Spaces:
Sleeping
Sleeping
Download src/modules/tool_gateway/service.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/tool_gateway/service.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/modules/tool_gateway/service.py
-
curl -L -o service.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/modules/tool_gateway/service.py
2.25 kB
| """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)}) | |