firedrill-run 2.2.5 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -22
- package/bin/firedrill.mjs +29 -5
- package/dist/assembly.json +13 -0
- package/dist/cli/runtime/candidate_copy.py +395 -0
- package/dist/cli/runtime/source_snapshot.py +391 -0
- package/dist/cli/src/administration.js +295 -0
- package/dist/cli/src/agent-changes.js +496 -0
- package/dist/cli/src/assessment-requests.js +67 -0
- package/dist/cli/src/auth.js +506 -0
- package/dist/cli/src/billing-commerce-contracts.js +1 -0
- package/dist/cli/src/billing-usage.js +227 -0
- package/dist/cli/src/billing-wallet-contracts.js +1 -0
- package/dist/cli/src/billing.js +170 -0
- package/dist/cli/src/bootstrap-process-lock.js +136 -0
- package/dist/cli/src/browser-links.js +14 -0
- package/dist/cli/src/campaign-controls.js +122 -0
- package/dist/cli/src/campaign-diagnoses.js +118 -0
- package/dist/cli/src/campaign-reports.js +1215 -0
- package/dist/cli/src/campaign-world.js +156 -0
- package/dist/cli/src/candidate-copy.js +376 -0
- package/dist/cli/src/catalog-contracts.js +1 -0
- package/dist/cli/src/ci-access-contracts.js +1 -0
- package/dist/cli/src/ci-configuration-contracts.js +1 -0
- package/dist/cli/src/ci-coverage.js +64 -0
- package/dist/cli/src/ci-delivery-contracts.js +1 -0
- package/dist/cli/src/ci-result-contracts.js +1 -0
- package/dist/cli/src/ci-run-contracts.js +1 -0
- package/dist/cli/src/ci-setup-proposals.js +52 -0
- package/dist/cli/src/company-policies.js +229 -0
- package/dist/cli/src/completion.js +79 -0
- package/dist/cli/src/configuration-intents.js +277 -0
- package/dist/cli/src/configuration.js +369 -0
- package/dist/cli/src/continuous-simulation.js +277 -0
- package/dist/cli/src/coordinated-checkpoints.js +133 -0
- package/dist/cli/src/credential-mode.js +139 -0
- package/dist/cli/src/credentials.js +331 -0
- package/dist/cli/src/credit-format.js +8 -0
- package/dist/cli/src/dataset-contracts.js +1 -0
- package/dist/cli/src/dataset-export.js +154 -0
- package/dist/cli/src/dataset-reads.js +37 -0
- package/dist/cli/src/dependency-preparation.js +239 -0
- package/dist/cli/src/director-tool-setup.js +104 -0
- package/dist/cli/src/driver-review.js +225 -0
- package/dist/cli/src/evaluation-authoring.js +315 -0
- package/dist/cli/src/evidence-bundles.js +367 -0
- package/dist/cli/src/execution-proposals.js +36 -0
- package/dist/cli/src/http.js +302 -0
- package/dist/cli/src/local-container-boundary.js +38 -0
- package/dist/cli/src/local-container-policy.js +201 -0
- package/dist/cli/src/local-execution-setup.js +81 -0
- package/dist/cli/src/local-source-basis.js +73 -0
- package/dist/cli/src/local-source.js +66 -0
- package/dist/cli/src/local-value-store.js +91 -0
- package/dist/cli/src/local-values.js +163 -0
- package/dist/cli/src/login-organizations.js +70 -0
- package/dist/cli/src/main.js +1627 -0
- package/dist/cli/src/mcp-connection.js +109 -0
- package/dist/cli/src/native/bindings.js +137 -0
- package/dist/cli/src/native/canonical.js +370 -0
- package/dist/cli/src/native/cloud-resources.js +942 -0
- package/dist/cli/src/native/companion-channel.js +421 -0
- package/dist/cli/src/native/companion-ipc.js +473 -0
- package/dist/cli/src/native/contracts.js +218 -0
- package/dist/cli/src/native/control-plane.js +1354 -0
- package/dist/cli/src/native/credit-approval.js +15 -0
- package/dist/cli/src/native/dependency-proxy.js +1006 -0
- package/dist/cli/src/native/drill-cleanup.js +115 -0
- package/dist/cli/src/native/drill-runner.js +1562 -0
- package/dist/cli/src/native/drivers/action-trace.js +210 -0
- package/dist/cli/src/native/drivers/function-wrapper.js +152 -0
- package/dist/cli/src/native/drivers/http.js +442 -0
- package/dist/cli/src/native/drivers/index.js +47 -0
- package/dist/cli/src/native/drivers/jsonl-process.js +538 -0
- package/dist/cli/src/native/drivers/playwright.js +600 -0
- package/dist/cli/src/native/drivers/signed-event.js +244 -0
- package/dist/cli/src/native/drivers/types.js +578 -0
- package/dist/cli/src/native/evidence-filter.js +255 -0
- package/dist/cli/src/native/isolated-access.js +241 -0
- package/dist/cli/src/native/library-sharing.js +220 -0
- package/dist/cli/src/native/local-run.js +667 -0
- package/dist/cli/src/native/local-secrets.js +19 -0
- package/dist/cli/src/native/mcp-config.js +123 -0
- package/dist/cli/src/native/metadata-requests.js +120 -0
- package/dist/cli/src/native/observations.js +1159 -0
- package/dist/cli/src/native/owned-groups.js +46 -0
- package/dist/cli/src/native/plan.js +594 -0
- package/dist/cli/src/native/png.js +159 -0
- package/dist/cli/src/native/ports.js +43 -0
- package/dist/cli/src/native/readiness.js +139 -0
- package/dist/cli/src/native/reassessments.js +206 -0
- package/dist/cli/src/native/redaction.js +235 -0
- package/dist/cli/src/native/registration.js +155 -0
- package/dist/cli/src/native/roots.js +110 -0
- package/dist/cli/src/native/run-cleanup.js +199 -0
- package/dist/cli/src/native/scratch.js +117 -0
- package/dist/cli/src/native/screenshots.js +60 -0
- package/dist/cli/src/native/session.js +556 -0
- package/dist/cli/src/native/standalone-proxy.js +580 -0
- package/dist/cli/src/native/standalone-renewals.js +183 -0
- package/dist/cli/src/native/standalone-state.js +193 -0
- package/dist/cli/src/native/standalone-tools.js +187 -0
- package/dist/cli/src/native/supervisor.js +831 -0
- package/dist/cli/src/native/target-auth.js +161 -0
- package/dist/cli/src/native/target-state.js +330 -0
- package/dist/cli/src/native/tool-reuse.js +364 -0
- package/dist/cli/src/native/tool-setups.js +336 -0
- package/dist/cli/src/native/world-reuse.js +288 -0
- package/dist/cli/src/onboarding.js +23 -0
- package/dist/cli/src/priority-requests.js +70 -0
- package/dist/cli/src/priority.js +223 -0
- package/dist/cli/src/prompts.js +184 -0
- package/dist/cli/src/real-operations.js +221 -0
- package/dist/cli/src/recipe-intents.js +58 -0
- package/dist/cli/src/recorded-context-intents.js +59 -0
- package/dist/cli/src/recorded-context.js +248 -0
- package/dist/cli/src/recordings.js +69 -0
- package/dist/cli/src/registration-guide.js +39 -0
- package/dist/cli/src/report-exports.js +213 -0
- package/dist/cli/src/request-input.js +47 -0
- package/dist/cli/src/resource-lifecycle.js +141 -0
- package/dist/cli/src/revision-requests.js +55 -0
- package/dist/cli/src/runner-abandon.js +53 -0
- package/dist/cli/src/runner-campaign-controls.js +262 -0
- package/dist/cli/src/runner-claim-reads.js +36 -0
- package/dist/cli/src/runner-completion.js +65 -0
- package/dist/cli/src/runner-configuration.js +546 -0
- package/dist/cli/src/runner-container.js +794 -0
- package/dist/cli/src/runner-evidence-erasure.js +351 -0
- package/dist/cli/src/runner-evidence-privacy.js +37 -0
- package/dist/cli/src/runner-evidence-retention.js +161 -0
- package/dist/cli/src/runner-evidence.js +326 -0
- package/dist/cli/src/runner-execute.js +92 -0
- package/dist/cli/src/runner-execution-deadline.js +25 -0
- package/dist/cli/src/runner-grants.js +307 -0
- package/dist/cli/src/runner-identity.js +615 -0
- package/dist/cli/src/runner-inputs.js +308 -0
- package/dist/cli/src/runner-jobs.js +49 -0
- package/dist/cli/src/runner-model-transport.js +392 -0
- package/dist/cli/src/runner-ownership.js +332 -0
- package/dist/cli/src/runner-process-lock.js +175 -0
- package/dist/cli/src/runner-runtime.js +396 -0
- package/dist/cli/src/runner-session-channel.js +377 -0
- package/dist/cli/src/runner-trial-completion.js +34 -0
- package/dist/cli/src/runner-trial-journal.js +358 -0
- package/dist/cli/src/runner-trial-live.js +393 -0
- package/dist/cli/src/runner-trial-protocol.js +289 -0
- package/dist/cli/src/runner-trial-sync.js +110 -0
- package/dist/cli/src/runner-trial-transfer.js +107 -0
- package/dist/cli/src/runner-voice.js +40 -0
- package/dist/cli/src/runner-world-claim.js +21 -0
- package/dist/cli/src/runner-world-collector.js +159 -0
- package/dist/cli/src/runner-world-command-evidence.js +487 -0
- package/dist/cli/src/runner-world-commands.js +268 -0
- package/dist/cli/src/runner-world-completion.js +76 -0
- package/dist/cli/src/runner-world-erasure.js +95 -0
- package/dist/cli/src/runner-world-evidence-sync.js +91 -0
- package/dist/cli/src/runner-world-journal.js +510 -0
- package/dist/cli/src/runner-world-native-filters.js +134 -0
- package/dist/cli/src/runner-world-observations.js +50 -0
- package/dist/cli/src/runner-world-session-protocol.js +134 -0
- package/dist/cli/src/saved-records.js +40 -0
- package/dist/cli/src/scenario-authoring.js +212 -0
- package/dist/cli/src/scenario-discovery.js +216 -0
- package/dist/cli/src/scenario-paths.js +68 -0
- package/dist/cli/src/scenario-requests.js +4 -0
- package/dist/cli/src/service-receipts.js +105 -0
- package/dist/cli/src/simple/authoring.js +270 -0
- package/dist/cli/src/simple/credit-approval.js +16 -0
- package/dist/cli/src/simple/help.js +98 -0
- package/dist/cli/src/simple/init.js +96 -0
- package/dist/cli/src/simple/library-sharing.js +414 -0
- package/dist/cli/src/simple/metadata-requests.js +46 -0
- package/dist/cli/src/simple/native-report.js +841 -0
- package/dist/cli/src/simple/native-tools.js +780 -0
- package/dist/cli/src/simple/plan-apply.js +506 -0
- package/dist/cli/src/simple/reassessment.js +323 -0
- package/dist/cli/src/simple/register.js +123 -0
- package/dist/cli/src/simple/run.js +122 -0
- package/dist/cli/src/simple/status.js +49 -0
- package/dist/cli/src/simple/tool-renewal.js +308 -0
- package/dist/cli/src/simple/tool-reuse.js +526 -0
- package/dist/cli/src/simple/tool-start-catalog.js +100 -0
- package/dist/cli/src/simple/tool-state.js +426 -0
- package/dist/cli/src/simple/tools-author.js +222 -0
- package/dist/cli/src/simple/watch.js +28 -0
- package/dist/cli/src/simple/world-reuse.js +586 -0
- package/dist/cli/src/simulation-intents.js +406 -0
- package/dist/cli/src/simulation-run.js +1058 -0
- package/dist/cli/src/source-batch.js +322 -0
- package/dist/cli/src/source-connection.js +451 -0
- package/dist/cli/src/source-runtime.js +346 -0
- package/dist/cli/src/source-selection-intents.js +75 -0
- package/dist/cli/src/source-sets.js +214 -0
- package/dist/cli/src/target-models.js +109 -0
- package/dist/cli/src/tool-catalog.js +224 -0
- package/dist/cli/src/tool-command-contracts.js +1 -0
- package/dist/cli/src/tool-command-export.js +245 -0
- package/dist/cli/src/tool-connection-contracts.js +1 -0
- package/dist/cli/src/tool-connection-reads.js +23 -0
- package/dist/cli/src/tool-contributions.js +58 -0
- package/dist/cli/src/tool-data.js +116 -0
- package/dist/cli/src/tool-datasets.js +176 -0
- package/dist/cli/src/tool-group-contracts.js +1 -0
- package/dist/cli/src/tool-group-reads.js +26 -0
- package/dist/cli/src/tool-group-state.js +147 -0
- package/dist/cli/src/tool-groups.js +311 -0
- package/dist/cli/src/tool-instances.js +186 -0
- package/dist/cli/src/tool-lifecycle-contracts.js +1 -0
- package/dist/cli/src/tool-lifecycle-reads.js +30 -0
- package/dist/cli/src/tool-lifecycle.js +323 -0
- package/dist/cli/src/tool-package-contracts.js +1 -0
- package/dist/cli/src/tool-package-reads.js +41 -0
- package/dist/cli/src/tool-records.js +53 -0
- package/dist/cli/src/tool-runtime.js +96 -0
- package/dist/cli/src/tool-state-contracts.js +1 -0
- package/dist/cli/src/tool-state-reads.js +31 -0
- package/dist/cli/src/tools.js +306 -0
- package/dist/cli/src/trial-actions.js +93 -0
- package/dist/cli/src/trial-checkpoints.js +133 -0
- package/dist/cli/src/trial-checks.js +70 -0
- package/dist/cli/src/trial-state.js +197 -0
- package/dist/cli/src/vault.js +266 -0
- package/dist/cli/src/workspace-registration.js +383 -0
- package/dist/cli/src/workspace-team-contracts.js +1 -0
- package/dist/cli/src/world-access.js +231 -0
- package/dist/cli/src/world-agent.js +4 -0
- package/dist/cli/src/world-checkpoint-scopes.js +15 -0
- package/dist/cli/src/world-contracts.js +6 -0
- package/dist/cli/src/world-creation.js +201 -0
- package/dist/cli/src/world-datasets.js +207 -0
- package/dist/cli/src/world-inspection.js +257 -0
- package/dist/cli/src/world-recipes.js +103 -0
- package/dist/cli/src/world-requests.js +241 -0
- package/dist/cli/src/world-session-checkpoints.js +196 -0
- package/dist/cli/src/world-session-lifecycle.js +207 -0
- package/dist/cli/src/world-session-requests.js +215 -0
- package/dist/cli/src/world-session-state.js +145 -0
- package/dist/cli/src/world-session-voice.js +66 -0
- package/dist/cli/src/world-sessions.js +288 -0
- package/dist/cli/src/world-stream.js +99 -0
- package/dist/cli/src/world-time-report.js +58 -0
- package/dist/contracts/agent-change-contracts.js +75 -0
- package/dist/contracts/agent-execution-contracts.js +38 -0
- package/dist/contracts/application-state-contracts.js +26 -0
- package/dist/contracts/assessment-aggregate-contracts.js +15 -0
- package/dist/contracts/assessment-contracts.js +74 -0
- package/dist/contracts/billing-commerce-contracts.js +107 -0
- package/dist/contracts/billing-wallet-contracts.js +43 -0
- package/dist/contracts/campaign-lifecycle.js +1 -0
- package/dist/contracts/campaign-world-contracts.js +80 -0
- package/dist/contracts/catalog-contracts.js +73 -0
- package/dist/contracts/ci-access-contracts.js +68 -0
- package/dist/contracts/ci-configuration-contracts.js +88 -0
- package/dist/contracts/ci-coverage-contracts.js +65 -0
- package/dist/contracts/ci-coverage-labels.js +25 -0
- package/dist/contracts/ci-delivery-contracts.js +61 -0
- package/dist/contracts/ci-result-contracts.js +103 -0
- package/dist/contracts/ci-run-contracts.js +51 -0
- package/dist/contracts/ci-setup-contracts.js +88 -0
- package/dist/contracts/clip-contracts.js +32 -0
- package/dist/contracts/comparison-contracts.js +53 -0
- package/dist/contracts/composite-contracts.js +34 -0
- package/dist/contracts/context-contracts.js +76 -0
- package/dist/contracts/continuation-report-contracts.js +1 -0
- package/dist/contracts/continuity-requirements.js +8 -0
- package/dist/contracts/coordinated-checkpoint-contracts.js +34 -0
- package/dist/contracts/dataset-contracts.js +88 -0
- package/dist/contracts/dependency-decision-contracts.js +36 -0
- package/dist/contracts/dependency-protocol-contracts.js +43 -0
- package/dist/contracts/director-execution.js +51 -0
- package/dist/contracts/driver-review-contracts.js +99 -0
- package/dist/contracts/evidence-contracts.js +65 -0
- package/dist/contracts/evidence-coverage-contracts.js +10 -0
- package/dist/contracts/export-contracts.js +44 -0
- package/dist/contracts/github-directory-contracts.js +96 -0
- package/dist/contracts/insight-contracts.js +11 -0
- package/dist/contracts/inspection-contracts.js +1 -0
- package/dist/contracts/local-claim-contracts.js +39 -0
- package/dist/contracts/local-configuration-contracts.js +7 -0
- package/dist/contracts/local-evidence-contracts.js +32 -0
- package/dist/contracts/local-grant-contracts.js +83 -0
- package/dist/contracts/local-input-contracts.js +19 -0
- package/dist/contracts/local-runner-contracts.js +42 -0
- package/dist/contracts/local-trial-live-contracts.js +16 -0
- package/dist/contracts/local-value-source-contracts.js +92 -0
- package/dist/contracts/local-world-native-contracts.js +8 -0
- package/dist/contracts/mcp-contracts.js +42 -0
- package/dist/contracts/media-contracts.js +28 -0
- package/dist/contracts/native-check-contracts.js +31 -0
- package/dist/contracts/native-identity-contracts.js +52 -0
- package/dist/contracts/onboarding-contracts.js +32 -0
- package/dist/contracts/performance-contracts.js +85 -0
- package/dist/contracts/planning-contracts.js +81 -0
- package/dist/contracts/real-operation-contracts.js +30 -0
- package/dist/contracts/recommendation-contracts.js +54 -0
- package/dist/contracts/report-contracts.js +1 -0
- package/dist/contracts/resource-lifecycle-contracts.js +57 -0
- package/dist/contracts/revision-contracts.js +12 -0
- package/dist/contracts/revision-request-contracts.js +39 -0
- package/dist/contracts/saved-record-contracts.js +76 -0
- package/dist/contracts/scenario-draft-comparison.js +91 -0
- package/dist/contracts/scenario-world-contracts.js +14 -0
- package/dist/contracts/service-contracts.js +1 -0
- package/dist/contracts/session-command-contracts.js +56 -0
- package/dist/contracts/session-contracts.js +65 -0
- package/dist/contracts/session-state-contracts.js +67 -0
- package/dist/contracts/session-voice-contracts.js +45 -0
- package/dist/contracts/source-set-contracts.js +26 -0
- package/dist/contracts/source-upload-contracts.js +22 -0
- package/dist/contracts/tool-command-contracts.js +57 -0
- package/dist/contracts/tool-connection-contracts.js +87 -0
- package/dist/contracts/tool-contribution-contracts.js +35 -0
- package/dist/contracts/tool-group-contracts.js +53 -0
- package/dist/contracts/tool-group-state-contracts.js +63 -0
- package/dist/contracts/tool-lifecycle-contracts.js +94 -0
- package/dist/contracts/tool-package-contracts.js +91 -0
- package/dist/contracts/tool-protocol-contracts.js +71 -0
- package/dist/contracts/tool-runtime-billing-contracts.js +28 -0
- package/dist/contracts/tool-setup-proposal.js +59 -0
- package/dist/contracts/tool-state-contracts.js +79 -0
- package/dist/contracts/trial-state-contracts.js +30 -0
- package/dist/contracts/typescript/agent-change.js +1 -0
- package/dist/contracts/typescript/assessment-aggregate.js +1 -0
- package/dist/contracts/typescript/assessment.js +1 -0
- package/dist/contracts/typescript/billing-commerce.js +1 -0
- package/dist/contracts/typescript/campaigns.js +1 -0
- package/dist/contracts/typescript/catalog.js +1 -0
- package/dist/contracts/typescript/ci-access.js +1 -0
- package/dist/contracts/typescript/ci-configuration.js +1 -0
- package/dist/contracts/typescript/ci-delivery.js +1 -0
- package/dist/contracts/typescript/ci-result.js +1 -0
- package/dist/contracts/typescript/ci-runs.js +1 -0
- package/dist/contracts/typescript/clips.js +1 -0
- package/dist/contracts/typescript/comparison.js +1 -0
- package/dist/contracts/typescript/composite.js +1 -0
- package/dist/contracts/typescript/connections.js +1 -0
- package/dist/contracts/typescript/context.js +1 -0
- package/dist/contracts/typescript/datasets.js +1 -0
- package/dist/contracts/typescript/evidence-coverage.js +1 -0
- package/dist/contracts/typescript/export.js +1 -0
- package/dist/contracts/typescript/github-directory.js +1 -0
- package/dist/contracts/typescript/insight.js +1 -0
- package/dist/contracts/typescript/inspection.js +1 -0
- package/dist/contracts/typescript/intake.js +1 -0
- package/dist/contracts/typescript/local-claim.js +1 -0
- package/dist/contracts/typescript/local-configuration.js +1 -0
- package/dist/contracts/typescript/local-evidence.js +1 -0
- package/dist/contracts/typescript/local-grant.js +1 -0
- package/dist/contracts/typescript/local-input.js +1 -0
- package/dist/contracts/typescript/local-runner.js +1 -0
- package/dist/contracts/typescript/local-trial-live.js +1 -0
- package/dist/contracts/typescript/local-value-source.js +1 -0
- package/dist/contracts/typescript/local-world-native.js +1 -0
- package/dist/contracts/typescript/mcp.js +1 -0
- package/dist/contracts/typescript/media.js +1 -0
- package/dist/contracts/typescript/native-check.js +1 -0
- package/dist/contracts/typescript/native-identity.js +1 -0
- package/dist/contracts/typescript/onboarding.js +1 -0
- package/dist/contracts/typescript/performance.js +1 -0
- package/dist/contracts/typescript/planning.js +1 -0
- package/dist/contracts/typescript/preparation.js +1 -0
- package/dist/contracts/typescript/real-operation.js +1 -0
- package/dist/contracts/typescript/recommendation.js +1 -0
- package/dist/contracts/typescript/reports.js +1 -0
- package/dist/contracts/typescript/resource-lifecycle.js +1 -0
- package/dist/contracts/typescript/saved-record.js +1 -0
- package/dist/contracts/typescript/scenarios.js +1 -0
- package/dist/contracts/typescript/services.js +1 -0
- package/dist/contracts/typescript/session-command.js +1 -0
- package/dist/contracts/typescript/session-state.js +1 -0
- package/dist/contracts/typescript/session-voice.js +1 -0
- package/dist/contracts/typescript/session.js +1 -0
- package/dist/contracts/typescript/tool-command.js +1 -0
- package/dist/contracts/typescript/tool-connection.js +1 -0
- package/dist/contracts/typescript/tool-contribution.js +1 -0
- package/dist/contracts/typescript/tool-groups.js +1 -0
- package/dist/contracts/typescript/tool-lifecycle.js +1 -0
- package/dist/contracts/typescript/tool-package.js +1 -0
- package/dist/contracts/typescript/tool-state.js +1 -0
- package/dist/contracts/typescript/trial-state.js +1 -0
- package/dist/contracts/typescript/vault.js +1 -0
- package/dist/contracts/typescript/workspace-team.js +1 -0
- package/dist/contracts/typescript/world-stream.js +1 -0
- package/dist/contracts/workspace-team-contracts.js +55 -0
- package/dist/contracts/world-command.js +65 -0
- package/dist/contracts/world-lifetime-contracts.js +74 -0
- package/dist/contracts/world-recipe-contracts.js +27 -0
- package/dist/contracts/world-stream-contracts.js +27 -0
- package/dist/package.json +1 -0
- package/package.json +16 -16
- package/LICENSE.md +0 -23
- package/PACKAGING.json +0 -50
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lookup } from 'node:dns/promises';
|
|
3
|
+
import { request } from 'node:https';
|
|
4
|
+
import { BlockList, isIP } from 'node:net';
|
|
5
|
+
import { checkServerIdentity } from 'node:tls';
|
|
6
|
+
import { API_ORIGIN, CliError } from './http.js';
|
|
7
|
+
import { identifier } from './world-contracts.js';
|
|
8
|
+
import { voiceChannels, voiceOperations } from './runner-voice.js';
|
|
9
|
+
import { localExecutionTimeout } from './runner-execution-deadline.js';
|
|
10
|
+
const SCHEMA = 'firedrill.local-runtime-frame.v2', FRAME_MAX = 65536, CHUNK = 16384;
|
|
11
|
+
const REQUEST_MAX = 2 * 1024 ** 2, RESPONSE_MAX = 32 * 1024 ** 2;
|
|
12
|
+
const SPEECH_REQUEST_MAX = 36 * 1024 ** 2, REQUEST_BUFFER_MAX = 128 * 1024 ** 2;
|
|
13
|
+
const speechTypes = new Set(['audio/pcm', 'audio/wav', 'audio/mpeg', 'audio/flac', 'audio/ogg', 'audio/aac']);
|
|
14
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
15
|
+
const failure = () => new CliError('local_runtime_transport_failed', 'The private execution connection did not finish. No operation was retried.');
|
|
16
|
+
const excluded4 = new BlockList();
|
|
17
|
+
for (const [address, prefix] of [['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
|
|
18
|
+
['169.254.0.0', 16], ['172.16.0.0', 12], ['192.0.0.0', 24], ['192.0.2.0', 24], ['192.88.99.0', 24],
|
|
19
|
+
['192.168.0.0', 16], ['198.18.0.0', 15], ['198.51.100.0', 24], ['203.0.113.0', 24], ['224.0.0.0', 3]])
|
|
20
|
+
excluded4.addSubnet(address, prefix, 'ipv4');
|
|
21
|
+
const global6 = new BlockList(), excluded6 = new BlockList();
|
|
22
|
+
global6.addSubnet('2000::', 3, 'ipv6');
|
|
23
|
+
for (const [address, prefix] of [['2001::', 23], ['2001:db8::', 32], ['2002::', 16], ['3fff::', 20]])
|
|
24
|
+
excluded6.addSubnet(address, prefix, 'ipv6');
|
|
25
|
+
function publicAddress(address) {
|
|
26
|
+
const family = isIP(address);
|
|
27
|
+
return family === 4 ? !excluded4.check(address, 'ipv4') : family === 6 && global6.check(address, 'ipv6') && !excluded6.check(address, 'ipv6');
|
|
28
|
+
}
|
|
29
|
+
function exact(frame, fields) {
|
|
30
|
+
if (Object.keys(frame).sort().join(',') !== ['schema', 'kind', 'id', ...fields].sort().join(','))
|
|
31
|
+
throw failure();
|
|
32
|
+
}
|
|
33
|
+
export function encodeModelFrame(frame) {
|
|
34
|
+
const body = Buffer.from(JSON.stringify(frame));
|
|
35
|
+
if (!body.length || body.length > FRAME_MAX)
|
|
36
|
+
throw failure();
|
|
37
|
+
const prefix = Buffer.alloc(4);
|
|
38
|
+
prefix.writeUInt32BE(body.length);
|
|
39
|
+
return Buffer.concat([prefix, body]);
|
|
40
|
+
}
|
|
41
|
+
/** Private child pipes only. No frame bodies, prompts or keys reach a console. */
|
|
42
|
+
export async function* readModelFrames(stream, signal) {
|
|
43
|
+
if (stream.isTTY)
|
|
44
|
+
throw failure();
|
|
45
|
+
let prefix = Buffer.alloc(4), prefixSize = 0, length = 0, parts = [], size = 0;
|
|
46
|
+
const aborted = () => stream.destroy(failure());
|
|
47
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
48
|
+
try {
|
|
49
|
+
signal.throwIfAborted();
|
|
50
|
+
for await (const input of stream) {
|
|
51
|
+
const chunk = Buffer.isBuffer(input) ? input : Buffer.from(input);
|
|
52
|
+
let offset = 0;
|
|
53
|
+
while (offset < chunk.length) {
|
|
54
|
+
if (!length) {
|
|
55
|
+
const count = Math.min(4 - prefixSize, chunk.length - offset);
|
|
56
|
+
chunk.copy(prefix, prefixSize, offset, offset + count);
|
|
57
|
+
prefixSize += count;
|
|
58
|
+
offset += count;
|
|
59
|
+
if (prefixSize !== 4)
|
|
60
|
+
continue;
|
|
61
|
+
length = prefix.readUInt32BE();
|
|
62
|
+
prefixSize = 0;
|
|
63
|
+
if (!length || length > FRAME_MAX)
|
|
64
|
+
throw failure();
|
|
65
|
+
}
|
|
66
|
+
const count = Math.min(length - size, chunk.length - offset);
|
|
67
|
+
parts.push(chunk.subarray(offset, offset + count));
|
|
68
|
+
size += count;
|
|
69
|
+
offset += count;
|
|
70
|
+
if (size === length) {
|
|
71
|
+
let value;
|
|
72
|
+
try {
|
|
73
|
+
value = JSON.parse(Buffer.concat(parts, size).toString('utf8'));
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw failure();
|
|
77
|
+
}
|
|
78
|
+
length = 0;
|
|
79
|
+
size = 0;
|
|
80
|
+
parts = [];
|
|
81
|
+
yield value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (prefixSize || length)
|
|
86
|
+
throw failure();
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
signal.removeEventListener('abort', aborted);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export function modelFrameWriter(stream, signal) {
|
|
93
|
+
if (stream.isTTY)
|
|
94
|
+
throw failure();
|
|
95
|
+
let writing = Promise.resolve();
|
|
96
|
+
const aborted = () => stream.destroy(failure());
|
|
97
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
98
|
+
stream.once('close', () => signal.removeEventListener('abort', aborted));
|
|
99
|
+
// Destroy errors must not become an uncaught stream exception. Callers also
|
|
100
|
+
// retain their child/process lifecycle and must handle its own exit signal.
|
|
101
|
+
stream.on('error', () => undefined);
|
|
102
|
+
return frame => {
|
|
103
|
+
const body = encodeModelFrame(frame);
|
|
104
|
+
const next = writing.then(async () => {
|
|
105
|
+
signal.throwIfAborted();
|
|
106
|
+
await new Promise((resolve, reject) => stream.write(body, error => error ? reject(failure()) : resolve()));
|
|
107
|
+
});
|
|
108
|
+
writing = next;
|
|
109
|
+
return next;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export class LocalModelRelay {
|
|
113
|
+
routes = new Map();
|
|
114
|
+
pending = new Map();
|
|
115
|
+
requestBytes = 0;
|
|
116
|
+
seen = new Set();
|
|
117
|
+
stopped = new AbortController();
|
|
118
|
+
signal;
|
|
119
|
+
emit;
|
|
120
|
+
constructor(configuration, emit, signal) {
|
|
121
|
+
this.emit = emit;
|
|
122
|
+
if (!Number.isSafeInteger(configuration.control.budget_seconds) || configuration.control.budget_seconds < 1)
|
|
123
|
+
throw failure();
|
|
124
|
+
this.signal = AbortSignal.any([signal, this.stopped.signal, AbortSignal.timeout(localExecutionTimeout(configuration))]);
|
|
125
|
+
for (const channel of configuration.model_channels) {
|
|
126
|
+
const url = new URL(channel.endpoint);
|
|
127
|
+
if (url.origin !== API_ORIGIN || url.username || url.password || url.search || url.hash
|
|
128
|
+
|| !/^\/api\/internal\/target-model\/[a-f0-9-]{36}$/.test(url.pathname)
|
|
129
|
+
|| !/^[A-Za-z0-9_-]{32,256}$/.test(channel.token) || this.routes.has('model:' + channel.binding_id))
|
|
130
|
+
throw failure();
|
|
131
|
+
identifier(channel.binding_id);
|
|
132
|
+
identifier(url.pathname.split('/').at(-1));
|
|
133
|
+
this.routes.set('model:' + channel.binding_id, { endpoint: channel.endpoint, token: channel.token, kind: 'model', provider: channel.provider });
|
|
134
|
+
}
|
|
135
|
+
if (configuration.control.purpose === 'simulation_trial' && ['conversation', 'browser_chat'].includes(configuration.control.invocation_mode)) {
|
|
136
|
+
const channel = configuration.participant_channel;
|
|
137
|
+
if (!channel || channel.role !== 'participant')
|
|
138
|
+
throw failure();
|
|
139
|
+
const url = new URL(channel.endpoint), id = url.pathname.split('/').at(-1);
|
|
140
|
+
if (url.origin !== API_ORIGIN || url.username || url.password || url.search || url.hash
|
|
141
|
+
|| !/^\/api\/internal\/model\/[a-f0-9-]{36}$/.test(url.pathname)
|
|
142
|
+
|| !/^[A-Za-z0-9_-]{32,256}$/.test(channel.token) || this.routes.has('model:' + id))
|
|
143
|
+
throw failure();
|
|
144
|
+
identifier(id);
|
|
145
|
+
this.routes.set('model:' + id, { endpoint: channel.endpoint, token: channel.token, kind: 'model', provider: 'anthropic' });
|
|
146
|
+
}
|
|
147
|
+
else if (configuration.participant_channel !== null)
|
|
148
|
+
throw failure();
|
|
149
|
+
voiceChannels(configuration.voice_channels, configuration.control.purpose === 'simulation_trial' && configuration.control.invocation_mode === 'voice');
|
|
150
|
+
for (const channel of configuration.voice_channels) {
|
|
151
|
+
const id = new URL(channel.endpoint).pathname.split('/').at(-1);
|
|
152
|
+
if (this.routes.has('model:' + id))
|
|
153
|
+
throw failure();
|
|
154
|
+
this.routes.set('model:' + id, { endpoint: channel.endpoint, token: channel.token, kind: 'model', provider: 'openai',
|
|
155
|
+
operation: voiceOperations[channel.role] });
|
|
156
|
+
}
|
|
157
|
+
for (const channel of configuration.real_channels) {
|
|
158
|
+
const url = new URL(channel.endpoint);
|
|
159
|
+
if (!(configuration.control.purpose === 'simulation_trial' || ['world_validation', 'world_inspection_session'].includes(configuration.control.purpose)
|
|
160
|
+
&& configuration.control.validation_scope === 'target_startup_only'
|
|
161
|
+
&& typeof configuration.control.startup_authorization_sha256 === 'string'
|
|
162
|
+
&& HASH.test(configuration.control.startup_authorization_sha256))
|
|
163
|
+
|| url.origin !== API_ORIGIN || url.username || url.password || url.search || url.hash
|
|
164
|
+
|| url.pathname !== '/api/internal/real-dependency/' + identifier(channel.id)
|
|
165
|
+
|| !/^[A-Za-z0-9_-]{32,256}$/.test(channel.token) || this.routes.has('real:' + channel.id))
|
|
166
|
+
throw failure();
|
|
167
|
+
this.routes.set('real:' + channel.id, { endpoint: channel.endpoint, token: channel.token, kind: 'real' });
|
|
168
|
+
}
|
|
169
|
+
this.signal.addEventListener('abort', () => this.close(), { once: true });
|
|
170
|
+
if (this.signal.aborted)
|
|
171
|
+
this.close();
|
|
172
|
+
}
|
|
173
|
+
async accept(value) {
|
|
174
|
+
if (this.signal.aborted || !value || typeof value !== 'object' || Array.isArray(value))
|
|
175
|
+
throw failure();
|
|
176
|
+
const frame = value;
|
|
177
|
+
if (frame.schema !== SCHEMA || typeof frame.kind !== 'string' || typeof frame.id !== 'string' || identifier(frame.id) !== frame.id)
|
|
178
|
+
throw failure();
|
|
179
|
+
if (frame.kind === 'request_start') {
|
|
180
|
+
exact(frame, ['binding_id', 'operation', 'connection_kind', 'length', 'sha256']);
|
|
181
|
+
const audio = frame.connection_kind === 'model' && (frame.operation === 'audio/transcriptions' || frame.operation === 'audio/speech');
|
|
182
|
+
if (this.pending.size >= 64 || this.seen.has(frame.id) || this.seen.size >= 1000000 || typeof frame.binding_id !== 'string'
|
|
183
|
+
|| typeof frame.connection_kind !== 'string' || !['model', 'real'].includes(frame.connection_kind)
|
|
184
|
+
|| !this.routes.has(frame.connection_kind + ':' + frame.binding_id)
|
|
185
|
+
|| frame.connection_kind === 'model' && this.routes.get('model:' + frame.binding_id)?.operation !== undefined
|
|
186
|
+
&& this.routes.get('model:' + frame.binding_id).operation !== frame.operation
|
|
187
|
+
|| typeof frame.operation !== 'string' || !(frame.connection_kind === 'real' ? ['dispatch', 'acknowledge']
|
|
188
|
+
: this.routes.get('model:' + frame.binding_id)?.provider === 'openai' ? ['chat/completions', 'responses', 'audio/transcriptions', 'audio/speech'] : ['messages', 'messages/count_tokens']).includes(frame.operation)
|
|
189
|
+
|| !Number.isSafeInteger(frame.length) || Number(frame.length) < 1 || Number(frame.length) > (audio ? SPEECH_REQUEST_MAX : REQUEST_MAX)
|
|
190
|
+
|| this.requestBytes + Number(frame.length) > REQUEST_BUFFER_MAX
|
|
191
|
+
|| typeof frame.sha256 !== 'string' || !HASH.test(frame.sha256))
|
|
192
|
+
throw failure();
|
|
193
|
+
const state = { id: frame.id, binding: frame.binding_id, connectionKind: frame.connection_kind,
|
|
194
|
+
operation: frame.operation, expectedSize: Number(frame.length),
|
|
195
|
+
expectedHash: frame.sha256, chunks: [], size: 0, sequence: 0, sent: false, controller: new AbortController() };
|
|
196
|
+
state.timer = setTimeout(() => { void this.failed(state); }, 30000);
|
|
197
|
+
this.seen.add(frame.id);
|
|
198
|
+
this.pending.set(frame.id, state);
|
|
199
|
+
this.requestBytes += state.expectedSize;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const state = this.pending.get(frame.id);
|
|
203
|
+
if (!state) {
|
|
204
|
+
if (frame.kind === 'cancel' && this.seen.has(frame.id)) {
|
|
205
|
+
exact(frame, []);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
throw failure();
|
|
209
|
+
}
|
|
210
|
+
if (frame.kind === 'cancel') {
|
|
211
|
+
exact(frame, []);
|
|
212
|
+
this.finish(state);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (frame.kind === 'response_ack') {
|
|
216
|
+
exact(frame, ['sequence']);
|
|
217
|
+
if (!Number.isSafeInteger(frame.sequence) || !state.ack || state.ack.sequence !== frame.sequence)
|
|
218
|
+
throw failure();
|
|
219
|
+
state.ack.resolve();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (state.sent)
|
|
223
|
+
throw failure();
|
|
224
|
+
if (frame.kind === 'request_chunk') {
|
|
225
|
+
exact(frame, ['sequence', 'data']);
|
|
226
|
+
if (frame.sequence !== state.sequence || !Number.isSafeInteger(frame.sequence) || typeof frame.data !== 'string'
|
|
227
|
+
|| !frame.data.length || frame.data.length > 4 * Math.ceil(CHUNK / 3))
|
|
228
|
+
throw failure();
|
|
229
|
+
const body = Buffer.from(frame.data, 'base64');
|
|
230
|
+
if (!body.length || body.length > CHUNK || body.toString('base64') !== frame.data || state.size + body.length > state.expectedSize)
|
|
231
|
+
throw failure();
|
|
232
|
+
state.chunks.push(body);
|
|
233
|
+
state.size += body.length;
|
|
234
|
+
state.sequence += 1;
|
|
235
|
+
if (state.timer)
|
|
236
|
+
clearTimeout(state.timer);
|
|
237
|
+
state.timer = setTimeout(() => { void this.failed(state); }, 30000);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (frame.kind !== 'request_end')
|
|
241
|
+
throw failure();
|
|
242
|
+
exact(frame, ['sequence']);
|
|
243
|
+
if (frame.sequence !== state.sequence || state.size !== state.expectedSize)
|
|
244
|
+
throw failure();
|
|
245
|
+
const body = Buffer.concat(state.chunks, state.size);
|
|
246
|
+
if (createHash('sha256').update(body).digest('hex') !== state.expectedHash)
|
|
247
|
+
throw failure();
|
|
248
|
+
state.sent = true;
|
|
249
|
+
state.chunks = [];
|
|
250
|
+
if (state.timer)
|
|
251
|
+
clearTimeout(state.timer);
|
|
252
|
+
// Do not await the response here: the independent reader must keep accepting
|
|
253
|
+
// its chunk acknowledgments. This dispatch has no retry or reconnect loop.
|
|
254
|
+
void this.forward(state, body).catch(() => this.failed(state));
|
|
255
|
+
}
|
|
256
|
+
async chunk(state, sequence, body) {
|
|
257
|
+
await new Promise((resolve, reject) => {
|
|
258
|
+
let settled = false;
|
|
259
|
+
let timer;
|
|
260
|
+
const aborted = () => done(failure());
|
|
261
|
+
const done = (error) => {
|
|
262
|
+
if (settled)
|
|
263
|
+
return;
|
|
264
|
+
settled = true;
|
|
265
|
+
clearTimeout(timer);
|
|
266
|
+
state.controller.signal.removeEventListener('abort', aborted);
|
|
267
|
+
state.ack = undefined;
|
|
268
|
+
error ? reject(error) : resolve();
|
|
269
|
+
};
|
|
270
|
+
timer = setTimeout(() => done(failure()), 30000);
|
|
271
|
+
state.ack = { sequence, resolve: () => done(), reject: error => done(error) };
|
|
272
|
+
state.controller.signal.addEventListener('abort', aborted, { once: true });
|
|
273
|
+
if (state.controller.signal.aborted || this.signal.aborted) {
|
|
274
|
+
done(failure());
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
void this.emit({ schema: SCHEMA, kind: 'response_chunk', id: state.id, sequence, data: body.toString('base64') }).catch(() => done(failure()));
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
async forward(state, body) {
|
|
281
|
+
const channel = this.routes.get(state.connectionKind + ':' + state.binding);
|
|
282
|
+
if (!channel || channel.kind !== state.connectionKind || this.signal.aborted || state.controller.signal.aborted)
|
|
283
|
+
throw failure();
|
|
284
|
+
const url = new URL(channel.endpoint);
|
|
285
|
+
const answers = await lookup(url.hostname, { all: true, verbatim: true });
|
|
286
|
+
if (!answers.length || answers.some(item => !publicAddress(item.address)) || this.signal.aborted || state.controller.signal.aborted)
|
|
287
|
+
throw failure();
|
|
288
|
+
const address = answers.find(item => item.family === 4) ?? answers[0];
|
|
289
|
+
const path = channel.kind === 'real' ? url.pathname + (state.operation === 'acknowledge' ? '/acknowledge' : '')
|
|
290
|
+
: url.pathname + '/v1/' + state.operation;
|
|
291
|
+
const requestMs = channel.kind === 'real' ? 90000 : 900000;
|
|
292
|
+
// Literal checked address, original TLS identity/Host, no second DNS lookup,
|
|
293
|
+
// proxy environment, cookies, redirects, client certificate or ambient agent.
|
|
294
|
+
const response = await new Promise((resolve, reject) => {
|
|
295
|
+
const req = request({ protocol: 'https:', hostname: address.address, family: address.family, port: 443,
|
|
296
|
+
servername: url.hostname, path, method: 'POST', agent: false,
|
|
297
|
+
minVersion: 'TLSv1.3', rejectUnauthorized: true, checkServerIdentity: (_host, certificate) => checkServerIdentity(url.hostname, certificate),
|
|
298
|
+
signal: AbortSignal.any([this.signal, state.controller.signal, AbortSignal.timeout(requestMs)]),
|
|
299
|
+
headers: { Host: url.hostname, Authorization: 'Bearer ' + channel.token, 'Content-Type': 'application/json',
|
|
300
|
+
'Content-Length': String(body.length), 'Accept-Encoding': 'identity', Connection: 'close' } }, resolve);
|
|
301
|
+
state.request = req;
|
|
302
|
+
req.once('error', () => reject(failure()));
|
|
303
|
+
req.setTimeout(requestMs, () => req.destroy(failure()));
|
|
304
|
+
req.end(body);
|
|
305
|
+
});
|
|
306
|
+
state.response = response;
|
|
307
|
+
const status = response.statusCode ?? 503;
|
|
308
|
+
const type = String(response.headers['content-type'] ?? '');
|
|
309
|
+
if (status !== 200) {
|
|
310
|
+
await this.emit({ schema: SCHEMA, kind: 'response_start', id: state.id,
|
|
311
|
+
status: [400, 401, 403, 404, 413, 429, ...(channel.kind === 'real' ? [409] : [])].includes(status) ? status : 503, content_type: 'application/json' });
|
|
312
|
+
await this.emit({ schema: SCHEMA, kind: 'response_end', id: state.id, sequence: 0, length: 0, sha256: createHash('sha256').digest('hex') });
|
|
313
|
+
this.finish(state);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const media = type.split(';', 1)[0].trim().toLowerCase();
|
|
317
|
+
const contentType = media === 'application/json' ? 'application/json'
|
|
318
|
+
: channel.kind === 'model' && media === 'text/event-stream' ? 'text/event-stream'
|
|
319
|
+
: channel.kind === 'model' && state.operation === 'audio/speech' && speechTypes.has(media) ? media : null;
|
|
320
|
+
if (!contentType || response.headers['content-encoding'] && response.headers['content-encoding'] !== 'identity')
|
|
321
|
+
throw failure();
|
|
322
|
+
await this.emit({ schema: SCHEMA, kind: 'response_start', id: state.id, status: 200, content_type: contentType });
|
|
323
|
+
let sequence = 0, length = 0;
|
|
324
|
+
const hash = createHash('sha256');
|
|
325
|
+
for await (const input of response) {
|
|
326
|
+
const bytes = Buffer.isBuffer(input) ? input : Buffer.from(input);
|
|
327
|
+
for (let offset = 0; offset < bytes.length; offset += CHUNK) {
|
|
328
|
+
const part = bytes.subarray(offset, offset + CHUNK);
|
|
329
|
+
length += part.length;
|
|
330
|
+
if (length > RESPONSE_MAX || this.signal.aborted || state.controller.signal.aborted)
|
|
331
|
+
throw failure();
|
|
332
|
+
hash.update(part);
|
|
333
|
+
await this.chunk(state, sequence++, part);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!response.complete)
|
|
337
|
+
throw failure();
|
|
338
|
+
await this.emit({ schema: SCHEMA, kind: 'response_end', id: state.id, sequence, length, sha256: hash.digest('hex') });
|
|
339
|
+
this.finish(state);
|
|
340
|
+
}
|
|
341
|
+
finish(state) {
|
|
342
|
+
if (!this.pending.delete(state.id))
|
|
343
|
+
return;
|
|
344
|
+
this.requestBytes -= state.expectedSize;
|
|
345
|
+
if (state.timer)
|
|
346
|
+
clearTimeout(state.timer);
|
|
347
|
+
state.ack?.reject(failure());
|
|
348
|
+
state.controller.abort();
|
|
349
|
+
state.request?.destroy();
|
|
350
|
+
state.response?.destroy();
|
|
351
|
+
state.chunks = [];
|
|
352
|
+
}
|
|
353
|
+
async failed(state) {
|
|
354
|
+
if (!this.pending.has(state.id))
|
|
355
|
+
return;
|
|
356
|
+
this.finish(state);
|
|
357
|
+
if (!this.signal.aborted) {
|
|
358
|
+
try {
|
|
359
|
+
await this.emit({ schema: SCHEMA, kind: 'response_error', id: state.id, code: 'local_model_transport_failed' });
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
this.close();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
close() {
|
|
367
|
+
if (!this.stopped.signal.aborted)
|
|
368
|
+
this.stopped.abort();
|
|
369
|
+
for (const state of this.pending.values())
|
|
370
|
+
this.finish(state);
|
|
371
|
+
this.routes.clear();
|
|
372
|
+
this.seen.clear();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/** One dedicated private child channel. EOF/return is not target completion. */
|
|
376
|
+
export async function serveLocalModelTransport(configuration, input, output, signal) {
|
|
377
|
+
if (!Number.isSafeInteger(configuration.control.budget_seconds) || configuration.control.budget_seconds < 1)
|
|
378
|
+
throw failure();
|
|
379
|
+
const stopped = new AbortController();
|
|
380
|
+
const combined = AbortSignal.any([signal, stopped.signal,
|
|
381
|
+
AbortSignal.timeout(localExecutionTimeout(configuration))]);
|
|
382
|
+
let relay;
|
|
383
|
+
try {
|
|
384
|
+
relay = new LocalModelRelay(configuration, modelFrameWriter(output, combined), combined);
|
|
385
|
+
for await (const frame of readModelFrames(input, combined))
|
|
386
|
+
await relay.accept(frame);
|
|
387
|
+
}
|
|
388
|
+
finally {
|
|
389
|
+
relay?.close();
|
|
390
|
+
stopped.abort();
|
|
391
|
+
}
|
|
392
|
+
}
|