Spaces:
Sleeping
Sleeping
File size: 2,056 Bytes
f578bd2 287e3a1 f578bd2 b27057a f578bd2 b27057a f578bd2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """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
|