dellweb3's picture
Close real-file skill lifecycle and improve readable logs and meeting layout
287e3a1 verified
Raw History Blame Contribute Delete
2.06 kB
"""Published workflow startup contracts and preflight, before any run or model call."""
import copy,json,re
from .models import RuntimeError
from .skill_contracts import validate,GatewayError as ContractError
ACCEPT=('.txt','.md','.docx','.pdf')
def contract(snapshot):
nodes=list(snapshot['compiled']['nodes'].values());fields=[]
for n in nodes:
if n['operation']['kind']=='start':fields=copy.deepcopy(n['config'].get('input_schema',[]))
for n in nodes:
if n['config'].get('program_code'):
for field in n['config'].get('input_schema',[]):
if not any(f['name']==field['name'] for f in fields):fields.append(copy.deepcopy(field))
if any(n['operation']['kind']=='meeting-read' for n in nodes):
from .materials import meeting_fields
fields+=meeting_fields()
return fields
def prepare(runtime,user,wid,snapshot,request,data):
fields=[f for f in contract(snapshot) if f['name'] not in ('meeting_material','meeting_date','lead_minutes')]
supplied=copy.deepcopy(data.get('workflow_inputs',{}))
if len(json.dumps(supplied,ensure_ascii=False))>65536:raise RuntimeError(413,'WORKFLOW_INPUTS_LIMIT','启动参数不能超过64KiB。')
if any(f['name']=='text' for f in fields):supplied.setdefault('text',request)
try:values=validate(supplied,fields,'启动参数',True)
except ContractError as exc:raise RuntimeError(422,'WORKFLOW_INPUT_REQUIRED' if exc.code=='SKILL_FIELD_REQUIRED' else exc.code,exc.message,{'input_schema':contract(snapshot)}) from exc
for f in fields:
if f.get('required') and isinstance(values.get(f['name']),str) and not values[f['name']].strip():raise RuntimeError(422,'WORKFLOW_INPUT_REQUIRED','请填写必填启动参数:'+f['name'])
result={'workflow_inputs':values}
if not any(f['type']=='file_or_text' for f in contract(snapshot)):return result
from .materials import prepare_material
result.update(prepare_material(runtime.workspace,user,wid,request,data.get('meeting_options',{})))
return result