Spaces:
Sleeping
Sleeping
File size: 2,247 Bytes
caf8059 115b94d caf8059 115b94d caf8059 115b94d caf8059 | 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 | """Fixed capability dispatch. No shell, URL, command or executable from model text."""
from src.modules.skill.domain.models import SkillError, digest
class ToolGateway:
def __init__(self, sandbox, harness,store=None):
self.sandbox, self.harness = sandbox, harness
self.store=store
def invoke(self, operation, run, payload, cancelled):
if operation not in {'AO08', 'AO09', 'AO10'}:
raise SkillError('TOOL_NOT_ALLOWED', '未批准的执行能力。', 403)
if cancelled():
raise SkillError('RUN_CANCELLED', '执行已取消。', 409)
if operation == 'AO08':
source = payload['source']
checked = self.harness.files({'files': source['files']}, run['snapshot']['framework'])
if checked['source_digest'] != source['source_digest']:
raise SkillError('SOURCE_DIGEST_MISMATCH', '执行输入摘要不符。', 409)
if self.store and run['request'].get('resource_limits'):
from src.modules.governance.resource_limits import serial_slot,require_time
require_time(self.store.get(run['id']),getattr(self.sandbox,'command_timeout',120))
with serial_slot(self.store.path.parent,'heavy',cancelled=cancelled,timeout=run['request']['resource_limits']['queue_seconds'],
on_wait=lambda:self.store.stage_event(run['id'],'resource_queue','waiting','等待实例重型构建/测试执行位,尚未启动环境。')) as waited:
self.store.stage_event(run['id'],'resource_queue','completed',f'构建/测试排队 {waited:.3f} 秒')
require_time(self.store.get(run['id']),getattr(self.sandbox,'command_timeout',120))
result=self.sandbox.build(run['id'],checked,cancelled)
else:result = self.sandbox.build(run['id'], checked, cancelled)
else:
result = self.sandbox.probe(run['id'], payload['candidate'],
'test' if operation == 'AO09' else 'preview', cancelled)
return dict(result, tool_receipt={'operation': operation, 'run_id': run['id'],
'input_digest': digest(payload), 'result_digest': digest(result)})
|