@halonicjs/testing 0.0.0 → 0.1.0
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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +41 -1
- package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
- package/dist/adapters/http-kit/src/address-class.js +109 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
- package/dist/adapters/http-kit/src/ip-address.js +89 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
- package/dist/adapters/integration-kit/src/declaration.js +77 -0
- package/dist/adapters/integration-kit/src/host.d.ts +28 -0
- package/dist/adapters/integration-kit/src/host.js +30 -0
- package/dist/adapters/integration-kit/src/index.d.ts +14 -0
- package/dist/adapters/integration-kit/src/index.js +21 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
- package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
- package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
- package/dist/adapters/integration-kit/src/limited-http.js +182 -0
- package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
- package/dist/adapters/integration-kit/src/load-problem.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
- package/dist/adapters/integration-kit/src/loader.js +219 -0
- package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
- package/dist/adapters/integration-kit/src/local-address.js +25 -0
- package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
- package/dist/adapters/integration-kit/src/own-request.js +36 -0
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
- package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
- package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
- package/dist/adapters/integration-kit/src/policy.js +37 -0
- package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
- package/dist/adapters/integration-kit/src/request-body.js +68 -0
- package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
- package/dist/adapters/integration-kit/src/request-log.js +17 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
- package/dist/adapters/integration-kit/src/response-body.js +117 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
- package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
- package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
- package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
- package/dist/adapters/integration-kit/src/wait.js +35 -0
- package/dist/core/events/src/add-usage.d.ts +10 -0
- package/dist/core/events/src/add-usage.js +27 -0
- package/dist/core/events/src/agent-resume.d.ts +24 -0
- package/dist/core/events/src/agent-resume.js +1 -0
- package/dist/core/events/src/home-path.d.ts +13 -0
- package/dist/core/events/src/home-path.js +26 -0
- package/dist/core/events/src/index.d.ts +13 -0
- package/dist/core/events/src/index.js +7 -0
- package/dist/core/events/src/run-basics.d.ts +205 -0
- package/dist/core/events/src/run-basics.js +1 -0
- package/dist/core/events/src/run-event.d.ts +434 -0
- package/dist/core/events/src/run-event.js +1 -0
- package/dist/core/events/src/run-summary.d.ts +108 -0
- package/dist/core/events/src/run-summary.js +1 -0
- package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
- package/dist/core/events/src/sandbox-blocked.js +26 -0
- package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
- package/dist/core/events/src/sandbox-opened-read.js +63 -0
- package/dist/core/events/src/sandbox-opened.d.ts +94 -0
- package/dist/core/events/src/sandbox-opened.js +52 -0
- package/dist/core/events/src/summarize.d.ts +14 -0
- package/dist/core/events/src/summarize.js +188 -0
- package/dist/core/events/src/timeline-entry.d.ts +21 -0
- package/dist/core/events/src/timeline-entry.js +105 -0
- package/dist/core/events/src/upgrade.d.ts +23 -0
- package/dist/core/events/src/upgrade.js +49 -0
- package/dist/core/format/src/compact.d.ts +30 -0
- package/dist/core/format/src/compact.js +72 -0
- package/dist/core/format/src/index.d.ts +37 -0
- package/dist/core/format/src/index.js +23 -0
- package/dist/core/format/src/integration/index.d.ts +6 -0
- package/dist/core/format/src/integration/index.js +9 -0
- package/dist/core/format/src/json-schema.d.ts +26 -0
- package/dist/core/format/src/json-schema.js +48 -0
- package/dist/core/format/src/kind.d.ts +65 -0
- package/dist/core/format/src/kind.js +1 -0
- package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/agent/kind.js +10 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
- package/dist/core/format/src/kinds/agent/schema.js +107 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
- package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/collection/kind.js +14 -0
- package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
- package/dist/core/format/src/kinds/collection/schema.js +90 -0
- package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
- package/dist/core/format/src/kinds/connector/is-local.js +43 -0
- package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/connector/kind.js +119 -0
- package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
- package/dist/core/format/src/kinds/connector/schema.js +92 -0
- package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/deployments/kind.js +25 -0
- package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
- package/dist/core/format/src/kinds/deployments/schema.js +42 -0
- package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/hub/kind.js +10 -0
- package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
- package/dist/core/format/src/kinds/hub/schema.js +34 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
- package/dist/core/format/src/kinds/integration/kind.js +138 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
- package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
- package/dist/core/format/src/kinds/integration/policy.js +268 -0
- package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
- package/dist/core/format/src/kinds/integration/schema.js +233 -0
- package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
- package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
- package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
- package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/models/kind.js +10 -0
- package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
- package/dist/core/format/src/kinds/models/schema.js +38 -0
- package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
- package/dist/core/format/src/kinds/plugin/backend.js +31 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
- package/dist/core/format/src/kinds/plugin/checks.js +131 -0
- package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/kind.js +16 -0
- package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
- package/dist/core/format/src/kinds/plugin/problems.js +65 -0
- package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
- package/dist/core/format/src/kinds/plugin/schema.js +261 -0
- package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
- package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
- package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/provider/kind.js +24 -0
- package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/provider/schema.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/routine/kind.js +25 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
- package/dist/core/format/src/kinds/routine/schema.js +93 -0
- package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/runtime/kind.js +13 -0
- package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
- package/dist/core/format/src/kinds/runtime/schema.js +12 -0
- package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/skill/kind.js +10 -0
- package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/skill/schema.js +17 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
- package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/workflow/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
- package/dist/core/format/src/kinds/workflow/schema.js +106 -0
- package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
- package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
- package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workspace/kind.js +10 -0
- package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
- package/dist/core/format/src/kinds/workspace/schema.js +66 -0
- package/dist/core/format/src/parse-file.d.ts +69 -0
- package/dist/core/format/src/parse-file.js +105 -0
- package/dist/core/format/src/recording/format.d.ts +81 -0
- package/dist/core/format/src/recording/format.js +102 -0
- package/dist/core/format/src/recording/index.d.ts +1 -0
- package/dist/core/format/src/recording/index.js +3 -0
- package/dist/core/format/src/registry.d.ts +64 -0
- package/dist/core/format/src/registry.js +61 -0
- package/dist/core/format/src/reserved.d.ts +20 -0
- package/dist/core/format/src/reserved.js +30 -0
- package/dist/core/format/src/shared/fields.d.ts +37 -0
- package/dist/core/format/src/shared/fields.js +54 -0
- package/dist/core/format/src/shared/guard.d.ts +32 -0
- package/dist/core/format/src/shared/guard.js +16 -0
- package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
- package/dist/core/format/src/shared/key-in-value.js +82 -0
- package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
- package/dist/core/format/src/shared/legacy-keys.js +17 -0
- package/dist/core/format/src/shared/program-start.d.ts +60 -0
- package/dist/core/format/src/shared/program-start.js +99 -0
- package/dist/core/format/src/shared/relative-path.d.ts +29 -0
- package/dist/core/format/src/shared/relative-path.js +50 -0
- package/dist/core/format/src/shared/secret-name.d.ts +24 -0
- package/dist/core/format/src/shared/secret-name.js +107 -0
- package/dist/core/format/src/source.d.ts +16 -0
- package/dist/core/format/src/source.js +73 -0
- package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
- package/dist/core/ports/src/agent-placement-store.js +27 -0
- package/dist/core/ports/src/blob-store.d.ts +33 -0
- package/dist/core/ports/src/blob-store.js +2 -0
- package/dist/core/ports/src/cant-try-error.d.ts +35 -0
- package/dist/core/ports/src/cant-try-error.js +44 -0
- package/dist/core/ports/src/chat.d.ts +127 -0
- package/dist/core/ports/src/chat.js +1 -0
- package/dist/core/ports/src/clock.d.ts +7 -0
- package/dist/core/ports/src/clock.js +2 -0
- package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
- package/dist/core/ports/src/connection-settings-store.js +2 -0
- package/dist/core/ports/src/connector-client.d.ts +259 -0
- package/dist/core/ports/src/connector-client.js +2 -0
- package/dist/core/ports/src/coordination.d.ts +84 -0
- package/dist/core/ports/src/coordination.js +2 -0
- package/dist/core/ports/src/definition-store.d.ts +208 -0
- package/dist/core/ports/src/definition-store.js +122 -0
- package/dist/core/ports/src/digest.d.ts +14 -0
- package/dist/core/ports/src/digest.js +2 -0
- package/dist/core/ports/src/folder-reader.d.ts +89 -0
- package/dist/core/ports/src/folder-reader.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
- package/dist/core/ports/src/harness-bridge-server.js +37 -0
- package/dist/core/ports/src/harness.d.ts +250 -0
- package/dist/core/ports/src/harness.js +45 -0
- package/dist/core/ports/src/http-client.d.ts +27 -0
- package/dist/core/ports/src/http-client.js +2 -0
- package/dist/core/ports/src/id-generator.d.ts +14 -0
- package/dist/core/ports/src/id-generator.js +2 -0
- package/dist/core/ports/src/index.d.ts +37 -0
- package/dist/core/ports/src/index.js +36 -0
- package/dist/core/ports/src/integration.d.ts +178 -0
- package/dist/core/ports/src/integration.js +13 -0
- package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
- package/dist/core/ports/src/knowledge-provider.js +2 -0
- package/dist/core/ports/src/llm-cache.d.ts +13 -0
- package/dist/core/ports/src/llm-cache.js +2 -0
- package/dist/core/ports/src/llm-provider.d.ts +184 -0
- package/dist/core/ports/src/llm-provider.js +136 -0
- package/dist/core/ports/src/model-price.d.ts +34 -0
- package/dist/core/ports/src/model-price.js +25 -0
- package/dist/core/ports/src/password-hasher.d.ts +47 -0
- package/dist/core/ports/src/password-hasher.js +2 -0
- package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
- package/dist/core/ports/src/plugin-folder-writer.js +95 -0
- package/dist/core/ports/src/port-versions.d.ts +44 -0
- package/dist/core/ports/src/port-versions.js +74 -0
- package/dist/core/ports/src/program-probe.d.ts +46 -0
- package/dist/core/ports/src/program-probe.js +2 -0
- package/dist/core/ports/src/record-store.d.ts +62 -0
- package/dist/core/ports/src/record-store.js +38 -0
- package/dist/core/ports/src/resource-probe.d.ts +59 -0
- package/dist/core/ports/src/resource-probe.js +2 -0
- package/dist/core/ports/src/run-executor.d.ts +302 -0
- package/dist/core/ports/src/run-executor.js +2 -0
- package/dist/core/ports/src/run-failure-error.d.ts +49 -0
- package/dist/core/ports/src/run-failure-error.js +47 -0
- package/dist/core/ports/src/run-store.d.ts +194 -0
- package/dist/core/ports/src/run-store.js +131 -0
- package/dist/core/ports/src/sandbox.d.ts +247 -0
- package/dist/core/ports/src/sandbox.js +34 -0
- package/dist/core/ports/src/scheduler.d.ts +85 -0
- package/dist/core/ports/src/scheduler.js +2 -0
- package/dist/core/ports/src/secrets.d.ts +128 -0
- package/dist/core/ports/src/secrets.js +144 -0
- package/dist/core/ports/src/token-store.d.ts +19 -0
- package/dist/core/ports/src/token-store.js +2 -0
- package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
- package/dist/core/ports/src/tool-approval-store.js +57 -0
- package/dist/core/ports/src/trust-store.d.ts +72 -0
- package/dist/core/ports/src/trust-store.js +2 -0
- package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
- package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
- package/dist/core/ports/src/vcs.d.ts +394 -0
- package/dist/core/ports/src/vcs.js +48 -0
- package/dist/core/schema-kit/src/builders.d.ts +50 -0
- package/dist/core/schema-kit/src/builders.js +72 -0
- package/dist/core/schema-kit/src/depth.d.ts +15 -0
- package/dist/core/schema-kit/src/depth.js +37 -0
- package/dist/core/schema-kit/src/index.d.ts +6 -0
- package/dist/core/schema-kit/src/index.js +6 -0
- package/dist/core/schema-kit/src/issue.d.ts +22 -0
- package/dist/core/schema-kit/src/issue.js +23 -0
- package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
- package/dist/core/schema-kit/src/json-schema.js +22 -0
- package/dist/core/schema-kit/src/parse.d.ts +17 -0
- package/dist/core/schema-kit/src/parse.js +25 -0
- package/dist/core/schema-kit/src/schema.d.ts +12 -0
- package/dist/core/schema-kit/src/schema.js +1 -0
- package/dist/core/std/src/ascii-host.d.ts +18 -0
- package/dist/core/std/src/ascii-host.js +110 -0
- package/dist/core/std/src/assert.d.ts +39 -0
- package/dist/core/std/src/assert.js +59 -0
- package/dist/core/std/src/base64url.d.ts +23 -0
- package/dist/core/std/src/base64url.js +65 -0
- package/dist/core/std/src/canonical-json.d.ts +18 -0
- package/dist/core/std/src/canonical-json.js +56 -0
- package/dist/core/std/src/clock.d.ts +27 -0
- package/dist/core/std/src/clock.js +33 -0
- package/dist/core/std/src/constant-time.d.ts +16 -0
- package/dist/core/std/src/constant-time.js +26 -0
- package/dist/core/std/src/content-digest.d.ts +24 -0
- package/dist/core/std/src/content-digest.js +28 -0
- package/dist/core/std/src/deep-clone.d.ts +15 -0
- package/dist/core/std/src/deep-clone.js +59 -0
- package/dist/core/std/src/deep-equal.d.ts +23 -0
- package/dist/core/std/src/deep-equal.js +64 -0
- package/dist/core/std/src/emitter.d.ts +42 -0
- package/dist/core/std/src/emitter.js +74 -0
- package/dist/core/std/src/error-kind.d.ts +88 -0
- package/dist/core/std/src/error-kind.js +98 -0
- package/dist/core/std/src/hex.d.ts +10 -0
- package/dist/core/std/src/hex.js +16 -0
- package/dist/core/std/src/ids.d.ts +45 -0
- package/dist/core/std/src/ids.js +49 -0
- package/dist/core/std/src/index.d.ts +25 -0
- package/dist/core/std/src/index.js +26 -0
- package/dist/core/std/src/keyed-queue.d.ts +18 -0
- package/dist/core/std/src/keyed-queue.js +32 -0
- package/dist/core/std/src/line-diff.d.ts +83 -0
- package/dist/core/std/src/line-diff.js +179 -0
- package/dist/core/std/src/line-merge.d.ts +63 -0
- package/dist/core/std/src/line-merge.js +138 -0
- package/dist/core/std/src/plain-data.d.ts +32 -0
- package/dist/core/std/src/plain-data.js +57 -0
- package/dist/core/std/src/posix-path.d.ts +61 -0
- package/dist/core/std/src/posix-path.js +121 -0
- package/dist/core/std/src/result.d.ts +55 -0
- package/dist/core/std/src/result.js +52 -0
- package/dist/core/std/src/secret-scrubber.d.ts +54 -0
- package/dist/core/std/src/secret-scrubber.js +124 -0
- package/dist/core/std/src/secret-shape.d.ts +20 -0
- package/dist/core/std/src/secret-shape.js +53 -0
- package/dist/core/std/src/stop-signal.d.ts +44 -0
- package/dist/core/std/src/stop-signal.js +77 -0
- package/dist/core/std/src/text.d.ts +28 -0
- package/dist/core/std/src/text.js +54 -0
- package/dist/core/std/src/utf8.d.ts +23 -0
- package/dist/core/std/src/utf8.js +110 -0
- package/dist/core/std/src/version.d.ts +48 -0
- package/dist/core/std/src/version.js +103 -0
- package/dist/core/yaml/src/depth.d.ts +14 -0
- package/dist/core/yaml/src/depth.js +140 -0
- package/dist/core/yaml/src/edit-data.d.ts +47 -0
- package/dist/core/yaml/src/edit-data.js +286 -0
- package/dist/core/yaml/src/edit-text.d.ts +92 -0
- package/dist/core/yaml/src/edit-text.js +267 -0
- package/dist/core/yaml/src/edit.d.ts +47 -0
- package/dist/core/yaml/src/edit.js +198 -0
- package/dist/core/yaml/src/index.d.ts +5 -0
- package/dist/core/yaml/src/index.js +4 -0
- package/dist/core/yaml/src/problem.d.ts +20 -0
- package/dist/core/yaml/src/problem.js +1 -0
- package/dist/core/yaml/src/read.d.ts +47 -0
- package/dist/core/yaml/src/read.js +130 -0
- package/dist/core/yaml/src/splice-node.d.ts +47 -0
- package/dist/core/yaml/src/splice-node.js +333 -0
- package/dist/core/yaml/src/splice.d.ts +13 -0
- package/dist/core/yaml/src/splice.js +174 -0
- package/dist/core/yaml/src/unsupported.d.ts +26 -0
- package/dist/core/yaml/src/unsupported.js +70 -0
- package/dist/core/yaml/src/write.d.ts +35 -0
- package/dist/core/yaml/src/write.js +44 -0
- package/dist/testing/integration/src/canaries.d.ts +14 -0
- package/dist/testing/integration/src/canaries.js +17 -0
- package/dist/testing/integration/src/checks.d.ts +37 -0
- package/dist/testing/integration/src/checks.js +195 -0
- package/dist/testing/integration/src/describe.d.ts +35 -0
- package/dist/testing/integration/src/describe.js +74 -0
- package/dist/testing/integration/src/failure.d.ts +6 -0
- package/dist/testing/integration/src/failure.js +8 -0
- package/dist/testing/integration/src/fake-wait.d.ts +18 -0
- package/dist/testing/integration/src/fake-wait.js +21 -0
- package/dist/testing/integration/src/index.d.ts +10 -0
- package/dist/testing/integration/src/index.js +11 -0
- package/dist/testing/integration/src/load.d.ts +14 -0
- package/dist/testing/integration/src/load.js +45 -0
- package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
- package/dist/testing/integration/src/plugin-folder.js +59 -0
- package/dist/testing/integration/src/plugin.d.ts +32 -0
- package/dist/testing/integration/src/plugin.js +57 -0
- package/dist/testing/integration/src/recording.d.ts +84 -0
- package/dist/testing/integration/src/recording.js +164 -0
- package/dist/testing/integration/src/run.d.ts +60 -0
- package/dist/testing/integration/src/run.js +81 -0
- package/dist/testing/integration/src/source-scan.d.ts +16 -0
- package/dist/testing/integration/src/source-scan.js +40 -0
- package/package.json +34 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Infer } from "../../../../schema-kit/src/index.js";
|
|
2
|
+
/** The shared items a hub takes from its workspace, by kind. */
|
|
3
|
+
export declare const HubUses: import("zod").ZodObject<{
|
|
4
|
+
connectors: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
5
|
+
skills: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
6
|
+
knowledge: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
7
|
+
collections: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
8
|
+
}, import("zod/v4/core").$strict>;
|
|
9
|
+
/** `hubs/<id>/hub.yaml`: a hub's name, its defaults and the shared items it uses. */
|
|
10
|
+
export declare const Hub: import("zod").ZodObject<{
|
|
11
|
+
version: import("zod").ZodDefault<import("zod").ZodLiteral<1>>;
|
|
12
|
+
id: import("zod").ZodString;
|
|
13
|
+
name: import("zod").ZodString;
|
|
14
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
15
|
+
defaults: import("zod").ZodDefault<import("zod").ZodObject<{
|
|
16
|
+
runtime: import("zod").ZodOptional<import("zod").ZodString>;
|
|
17
|
+
model: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
|
+
}, import("zod/v4/core").$strict>>;
|
|
19
|
+
models: import("zod").ZodDefault<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
20
|
+
provider: import("zod").ZodString;
|
|
21
|
+
model: import("zod").ZodString;
|
|
22
|
+
params: import("zod").ZodDefault<import("zod").ZodObject<{
|
|
23
|
+
temperature: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
24
|
+
topP: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
25
|
+
maxTokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
26
|
+
stop: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
27
|
+
reasoningEffort: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
28
|
+
high: "high";
|
|
29
|
+
low: "low";
|
|
30
|
+
medium: "medium";
|
|
31
|
+
}>>;
|
|
32
|
+
extra: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
33
|
+
}, import("zod/v4/core").$strict>>;
|
|
34
|
+
price: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
35
|
+
input: import("zod").ZodNumber;
|
|
36
|
+
output: import("zod").ZodNumber;
|
|
37
|
+
cacheRead: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
38
|
+
cacheWrite: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
39
|
+
cacheWrite1h: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
40
|
+
}, import("zod/v4/core").$strict>>;
|
|
41
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
42
|
+
fallback: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
43
|
+
}, import("zod/v4/core").$strict>>>;
|
|
44
|
+
uses: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
45
|
+
connectors: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
46
|
+
skills: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
47
|
+
knowledge: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
48
|
+
collections: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
|
|
49
|
+
}, import("zod/v4/core").$strict>>;
|
|
50
|
+
}, import("zod/v4/core").$strict>;
|
|
51
|
+
/** A hub, with defaults filled in. */
|
|
52
|
+
export type Hub = Infer<typeof Hub>;
|
|
53
|
+
/** The shared items a hub lists in `uses`. */
|
|
54
|
+
export type HubUses = Infer<typeof HubUses>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { s } from "../../../../schema-kit/src/index.js";
|
|
2
|
+
import { collectionId, id, version } from "../../shared/fields.js";
|
|
3
|
+
import { ModelAlias } from "../models/schema.js";
|
|
4
|
+
/** The shared items a hub takes from its workspace, by kind. */
|
|
5
|
+
export const HubUses = s
|
|
6
|
+
.object({
|
|
7
|
+
connectors: s.array(id).default([]),
|
|
8
|
+
skills: s.array(id).default([]),
|
|
9
|
+
knowledge: s.array(id).default([]),
|
|
10
|
+
collections: s.array(collectionId).default([]),
|
|
11
|
+
})
|
|
12
|
+
.strict();
|
|
13
|
+
/** `hubs/<id>/hub.yaml`: a hub's name, its defaults and the shared items it uses. */
|
|
14
|
+
export const Hub = s
|
|
15
|
+
.object({
|
|
16
|
+
version,
|
|
17
|
+
id,
|
|
18
|
+
name: s.string().min(1),
|
|
19
|
+
description: s.string().optional(),
|
|
20
|
+
/** Overrides of the workspace defaults (runtime, model alias). */
|
|
21
|
+
defaults: s
|
|
22
|
+
.object({ runtime: s.string().optional(), model: s.string().optional() })
|
|
23
|
+
.strict()
|
|
24
|
+
.default({}),
|
|
25
|
+
/** Hub-level alias overrides, such as "smart" pointing at another model. */
|
|
26
|
+
models: s.record(s.string(), ModelAlias).default({}),
|
|
27
|
+
/**
|
|
28
|
+
* The shared items this hub may use. Without it every shared item is
|
|
29
|
+
* available; with it only the listed ones are, which keeps the hub
|
|
30
|
+
* self-contained.
|
|
31
|
+
*/
|
|
32
|
+
uses: HubUses.optional(),
|
|
33
|
+
})
|
|
34
|
+
.strict();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileKind, KindCheckProblem } from "../../kind.js";
|
|
2
|
+
import { IntegrationSheet } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* `integration.yaml`, next to an integration's code. It isn't a workspace
|
|
5
|
+
* file, so it has no place; the loader for integrations reads it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const integrationKind: FileKind<IntegrationSheet>;
|
|
8
|
+
/**
|
|
9
|
+
* The rules over several fields: no list names a thing twice, a secret goes
|
|
10
|
+
* only to hosts the sheet declares, a send tool has a noun, and the Google
|
|
11
|
+
* fields fit the sheet.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* checkIntegrationSheet(sheet); // [] for the weather example in the guide
|
|
15
|
+
*/
|
|
16
|
+
export declare function checkIntegrationSheet(sheet: IntegrationSheet): KindCheckProblem[];
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { GOOGLE_CHECK_URL_PATTERN, GOOGLE_SECRET, IntegrationSheet, } from "./schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* `integration.yaml`, next to an integration's code. It isn't a workspace
|
|
4
|
+
* file, so it has no place; the loader for integrations reads it.
|
|
5
|
+
*/
|
|
6
|
+
export const integrationKind = {
|
|
7
|
+
name: "integration",
|
|
8
|
+
about: "An integration's permission sheet: its hosts, secrets, tools and limits.",
|
|
9
|
+
syntax: "yaml",
|
|
10
|
+
schema: IntegrationSheet,
|
|
11
|
+
places: [],
|
|
12
|
+
idFromPlace: "none",
|
|
13
|
+
check: checkIntegrationSheet,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The rules over several fields: no list names a thing twice, a secret goes
|
|
17
|
+
* only to hosts the sheet declares, a send tool has a noun, and the Google
|
|
18
|
+
* fields fit the sheet.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* checkIntegrationSheet(sheet); // [] for the weather example in the guide
|
|
22
|
+
*/
|
|
23
|
+
export function checkIntegrationSheet(sheet) {
|
|
24
|
+
const problems = [];
|
|
25
|
+
const duplicates = (values, path, what) => {
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
values.forEach((value, index) => {
|
|
28
|
+
if (seen.has(value)) {
|
|
29
|
+
problems.push({
|
|
30
|
+
severity: "error",
|
|
31
|
+
code: "duplicate",
|
|
32
|
+
path: [...path, index],
|
|
33
|
+
message: `Integration "${sheet.id}": ${what} ${value} is listed twice`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
seen.add(value);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
duplicates(sheet.provides, ["provides"], "provides");
|
|
40
|
+
duplicates(sheet.hosts.map(hostKey), ["hosts"], "host");
|
|
41
|
+
duplicates(sheet.googleScopes?.map((entry) => entry.scope) ?? [], ["googleScopes"], "scope");
|
|
42
|
+
duplicates(sheet.googleApis?.map((entry) => entry.api) ?? [], ["googleApis"], "API");
|
|
43
|
+
duplicates(sheet.tokens.map((token) => token.name), ["tokens"], "token");
|
|
44
|
+
duplicates(sheet.tools.map((tool) => tool.name), ["tools"], "tool");
|
|
45
|
+
duplicates(sheet.needs, ["needs"], "need");
|
|
46
|
+
const recording = sheet.recording;
|
|
47
|
+
duplicates(recording?.userContent ?? [], ["recording", "userContent"], "path");
|
|
48
|
+
duplicates(recording?.secretFields ?? [], ["recording", "secretFields"], "field");
|
|
49
|
+
duplicates(recording?.allowContentTypes ?? [], ["recording", "allowContentTypes"], "type");
|
|
50
|
+
const declared = new Set(sheet.hosts.map(hostKey));
|
|
51
|
+
for (const [name, secret] of Object.entries(sheet.secrets)) {
|
|
52
|
+
duplicates(secret.hosts.map(hostKey), ["secrets", name, "hosts"], "host");
|
|
53
|
+
secret.hosts.forEach((host, index) => {
|
|
54
|
+
if (!declared.has(hostKey(host))) {
|
|
55
|
+
problems.push({
|
|
56
|
+
severity: "error",
|
|
57
|
+
code: "secret-host-not-declared",
|
|
58
|
+
path: ["secrets", name, "hosts", index],
|
|
59
|
+
message: `Integration "${sheet.id}": secret "${name}" may only go to hosts in hosts, and ${hostKey(host)} isn't one`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
problems.push(...checkSendNouns(sheet));
|
|
65
|
+
problems.push(...checkGoogleFields(sheet));
|
|
66
|
+
return problems;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A `send` tool says what it sends, so a run can say "Sent 1 email". A
|
|
70
|
+
* `read` or `write` tool may leave its noun out.
|
|
71
|
+
*/
|
|
72
|
+
function checkSendNouns(sheet) {
|
|
73
|
+
return sheet.tools.flatMap((tool, index) => tool.risk === "send" && tool.noun === undefined
|
|
74
|
+
? [
|
|
75
|
+
{
|
|
76
|
+
severity: "error",
|
|
77
|
+
code: "send-tool-without-noun",
|
|
78
|
+
path: ["tools", index],
|
|
79
|
+
message: `Integration "${sheet.id}": tool "${tool.name}" has risk send, so it needs a noun for what it sends, such as noun: { one: email, many: emails }, so a run can say "Sent 1 email"`,
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
: []);
|
|
83
|
+
}
|
|
84
|
+
/** The sheet fields that only an integration using the Google sign-in may have. */
|
|
85
|
+
const googleFields = ["googleScopes", "googleApis", "googleCheck"];
|
|
86
|
+
/**
|
|
87
|
+
* The Google fields belong to a sheet with the `google-account` secret. A
|
|
88
|
+
* sheet that asks for scopes names the APIs to switch on, and `googleCheck`
|
|
89
|
+
* carries the token, so it goes to a host of the sheet and of that secret.
|
|
90
|
+
* The same rules as the `google-sheet` check in halonic-com/integrations.
|
|
91
|
+
*/
|
|
92
|
+
function checkGoogleFields(sheet) {
|
|
93
|
+
const secret = Object.hasOwn(sheet.secrets, GOOGLE_SECRET)
|
|
94
|
+
? sheet.secrets[GOOGLE_SECRET]
|
|
95
|
+
: undefined;
|
|
96
|
+
if (secret === undefined) {
|
|
97
|
+
return googleFields
|
|
98
|
+
.filter((field) => sheet[field] !== undefined)
|
|
99
|
+
.map((field) => ({
|
|
100
|
+
severity: "error",
|
|
101
|
+
code: "google-field-without-sign-in",
|
|
102
|
+
path: [field],
|
|
103
|
+
message: `Integration "${sheet.id}": ${field} is only for an integration with the ${GOOGLE_SECRET} secret. Remove it, or add the secret`,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
const problems = [];
|
|
107
|
+
if (sheet.googleScopes !== undefined && (sheet.googleApis ?? []).length === 0) {
|
|
108
|
+
problems.push({
|
|
109
|
+
severity: "error",
|
|
110
|
+
code: "google-apis-missing",
|
|
111
|
+
path: ["googleScopes"],
|
|
112
|
+
message: `Integration "${sheet.id}": a sheet with googleScopes also lists googleApis, { api, name } for each API the user switches on, such as { api: gmail.googleapis.com, name: Gmail API }`,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const url = sheet.googleCheck?.url;
|
|
116
|
+
const host = url === undefined ? undefined : GOOGLE_CHECK_URL_PATTERN.exec(url)?.[1];
|
|
117
|
+
if (host !== undefined) {
|
|
118
|
+
const inSheet = sheet.hosts.some((declared) => declared === host);
|
|
119
|
+
const inSecret = secret.hosts.some((declared) => declared === host);
|
|
120
|
+
if (!inSheet || !inSecret) {
|
|
121
|
+
problems.push({
|
|
122
|
+
severity: "error",
|
|
123
|
+
code: "google-check-host-not-declared",
|
|
124
|
+
path: ["googleCheck", "url"],
|
|
125
|
+
message: `Integration "${sheet.id}": googleCheck carries the ${GOOGLE_SECRET} token, so ${host} must be in hosts and in that secret's hosts`,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return problems;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A host as one text, to compare: `api.example.com`, or `fromSetting url`.
|
|
133
|
+
* A secret names a `{ fromSetting }` host by its setting alone, so the class
|
|
134
|
+
* isn't part of it.
|
|
135
|
+
*/
|
|
136
|
+
function hostKey(host) {
|
|
137
|
+
return typeof host === "string" ? host : `fromSetting ${host.fromSetting}`;
|
|
138
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type IssueCode, type Path } from "../../../../schema-kit/src/index.js";
|
|
2
|
+
import { type Result } from "../../../../std/src/index.js";
|
|
3
|
+
import { IntegrationSheet } from "./schema.js";
|
|
4
|
+
/** Why a sheet was refused: a schema issue code, or the code of one of the sheet's own checks. */
|
|
5
|
+
export interface SheetProblem {
|
|
6
|
+
readonly code: IssueCode | string;
|
|
7
|
+
readonly path: Path;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Checks a permission sheet that is already data, such as the JSON the build
|
|
12
|
+
* writes next to an integration, with the same schema and checks as
|
|
13
|
+
* `parseFile`. For a loader that must not read YAML.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const sheet = parseIntegrationSheet(JSON.parse(text));
|
|
17
|
+
* if (!sheet.ok) refuse(sheet.error);
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseIntegrationSheet(value: unknown): Result<IntegrationSheet, SheetProblem[]>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { parse } from "../../../../schema-kit/src/index.js";
|
|
2
|
+
import { err, ok } from "../../../../std/src/index.js";
|
|
3
|
+
import { checkIntegrationSheet } from "./kind.js";
|
|
4
|
+
import { IntegrationSheet } from "./schema.js";
|
|
5
|
+
/**
|
|
6
|
+
* Checks a permission sheet that is already data, such as the JSON the build
|
|
7
|
+
* writes next to an integration, with the same schema and checks as
|
|
8
|
+
* `parseFile`. For a loader that must not read YAML.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const sheet = parseIntegrationSheet(JSON.parse(text));
|
|
12
|
+
* if (!sheet.ok) refuse(sheet.error);
|
|
13
|
+
*/
|
|
14
|
+
export function parseIntegrationSheet(value) {
|
|
15
|
+
const parsed = parse(IntegrationSheet, value);
|
|
16
|
+
if (!parsed.ok) {
|
|
17
|
+
return err(parsed.error.map(({ code, path, message }) => ({ code, path, message })));
|
|
18
|
+
}
|
|
19
|
+
const problems = checkIntegrationSheet(parsed.value).filter((problem) => problem.severity === "error");
|
|
20
|
+
if (problems.length > 0) {
|
|
21
|
+
return err(problems.map(({ code, path, message }) => ({ code, path, message })));
|
|
22
|
+
}
|
|
23
|
+
return ok(parsed.value);
|
|
24
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Path } from "../../../../schema-kit/src/index.js";
|
|
2
|
+
import { type Result } from "../../../../std/src/index.js";
|
|
3
|
+
import type { IntegrationSheet } from "./schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* What one integration may do, in the shape of the kit's `IntegrationPolicy`
|
|
6
|
+
* (`adapters/integration-kit`). The core can't import an adapter, so the
|
|
7
|
+
* shape is repeated here; the kit enforces it.
|
|
8
|
+
*/
|
|
9
|
+
export interface IntegrationPolicy {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** Hosts it may call over `https`: a host name, or `host:port` for a port other than 443. */
|
|
12
|
+
readonly hosts: readonly string[];
|
|
13
|
+
/** Hosts the user chose that it may call over plain `http`: on this machine or a private network. */
|
|
14
|
+
readonly localHosts?: readonly string[];
|
|
15
|
+
/** Each secret, the hosts it may go to, whether a request may go without it, and where it goes. */
|
|
16
|
+
readonly secrets: Readonly<Record<string, DeclaredSecret>>;
|
|
17
|
+
readonly tokens: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
/** One secret as the kit takes it. */
|
|
20
|
+
export interface DeclaredSecret {
|
|
21
|
+
readonly hosts: readonly string[];
|
|
22
|
+
readonly optional?: boolean;
|
|
23
|
+
/** Where the sheet puts it. The kit refuses any other placement. */
|
|
24
|
+
readonly placement: DeclaredPlacement;
|
|
25
|
+
}
|
|
26
|
+
/** Where the sheet puts a secret, as the kit's `DeclaredPlacement` says. */
|
|
27
|
+
export type DeclaredPlacement = {
|
|
28
|
+
readonly as: "bearer";
|
|
29
|
+
} | {
|
|
30
|
+
readonly as: "header";
|
|
31
|
+
readonly header: string;
|
|
32
|
+
readonly prefix?: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly as: "form";
|
|
35
|
+
readonly field: string;
|
|
36
|
+
};
|
|
37
|
+
/** The kit's request limits, as the sheet gives them. */
|
|
38
|
+
export type IntegrationLimits = NonNullable<IntegrationSheet["limits"]>;
|
|
39
|
+
/** What the kit needs to build an integration's host. */
|
|
40
|
+
export interface ResolvedIntegration {
|
|
41
|
+
readonly policy: IntegrationPolicy;
|
|
42
|
+
/** Left out when the sheet has none: the kit's defaults apply. */
|
|
43
|
+
readonly limits?: IntegrationLimits;
|
|
44
|
+
}
|
|
45
|
+
/** Why a `fromSetting` host can't be resolved. */
|
|
46
|
+
export interface PolicyProblem {
|
|
47
|
+
readonly code: "setting-missing" | "setting-not-a-url" | "setting-outside-class" | "plain-http-not-local" | "secret-over-plain-http";
|
|
48
|
+
/** Where the host sits in the sheet. */
|
|
49
|
+
readonly path: Path;
|
|
50
|
+
readonly message: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Turns a parsed sheet and the integration's settings into the policy the
|
|
54
|
+
* kit enforces. A `{ fromSetting }` host becomes the host of the URL in that
|
|
55
|
+
* setting, which must be in the class the sheet declares for it: a value
|
|
56
|
+
* outside it is refused as `setting-outside-class`. This is the only place
|
|
57
|
+
* plain `http` is allowed: to a `loopback` or `private` host, and a secret
|
|
58
|
+
* only to a `loopback` one, even when it's optional: the kit checks where a
|
|
59
|
+
* secret may go before it looks the key up, so it would refuse every request
|
|
60
|
+
* that names the secret there, set up or not.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // hosts: [{ fromSetting: url, class: loopback }]
|
|
64
|
+
* const resolved = integrationPolicy(sheet, { url: "http://localhost:8080/mcp" });
|
|
65
|
+
* if (resolved.ok) createIntegrationHost({ policy: resolved.value.policy, ...ports });
|
|
66
|
+
*/
|
|
67
|
+
export declare function integrationPolicy(sheet: IntegrationSheet, settings: Readonly<Record<string, unknown>>): Result<ResolvedIntegration, PolicyProblem[]>;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { err, ok } from "../../../../std/src/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Turns a parsed sheet and the integration's settings into the policy the
|
|
4
|
+
* kit enforces. A `{ fromSetting }` host becomes the host of the URL in that
|
|
5
|
+
* setting, which must be in the class the sheet declares for it: a value
|
|
6
|
+
* outside it is refused as `setting-outside-class`. This is the only place
|
|
7
|
+
* plain `http` is allowed: to a `loopback` or `private` host, and a secret
|
|
8
|
+
* only to a `loopback` one, even when it's optional: the kit checks where a
|
|
9
|
+
* secret may go before it looks the key up, so it would refuse every request
|
|
10
|
+
* that names the secret there, set up or not.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // hosts: [{ fromSetting: url, class: loopback }]
|
|
14
|
+
* const resolved = integrationPolicy(sheet, { url: "http://localhost:8080/mcp" });
|
|
15
|
+
* if (resolved.ok) createIntegrationHost({ policy: resolved.value.policy, ...ports });
|
|
16
|
+
*/
|
|
17
|
+
export function integrationPolicy(sheet, settings) {
|
|
18
|
+
const problems = [];
|
|
19
|
+
const classes = settingClasses(sheet);
|
|
20
|
+
const hosts = [];
|
|
21
|
+
const localHosts = [];
|
|
22
|
+
sheet.hosts.forEach((host, index) => {
|
|
23
|
+
const found = resolveHost(sheet, host, classes, settings, ["hosts", index], problems);
|
|
24
|
+
if (found !== undefined) {
|
|
25
|
+
(found.plain ? localHosts : hosts).push(found.host);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const secrets = {};
|
|
29
|
+
for (const [name, secret] of Object.entries(sheet.secrets)) {
|
|
30
|
+
const secretHosts = [];
|
|
31
|
+
secret.hosts.forEach((host, index) => {
|
|
32
|
+
const path = ["secrets", name, "hosts", index];
|
|
33
|
+
const found = resolveHost(sheet, host, classes, settings, path, problems);
|
|
34
|
+
if (found === undefined) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (found.plain && !isLoopback(found.hostname)) {
|
|
38
|
+
problems.push({
|
|
39
|
+
code: "secret-over-plain-http",
|
|
40
|
+
path,
|
|
41
|
+
message: `${sheet.id}: the secret "${name}" may go over plain http only to this machine, not to ${found.host}`,
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
secretHosts.push(found.host);
|
|
46
|
+
});
|
|
47
|
+
const resolved = unique(secretHosts);
|
|
48
|
+
const placement = placementOf(secret);
|
|
49
|
+
secrets[name] = secret.optional
|
|
50
|
+
? { hosts: resolved, optional: true, placement }
|
|
51
|
+
: { hosts: resolved, placement };
|
|
52
|
+
}
|
|
53
|
+
if (problems.length > 0) {
|
|
54
|
+
return err(problems);
|
|
55
|
+
}
|
|
56
|
+
const policy = {
|
|
57
|
+
name: sheet.id,
|
|
58
|
+
hosts: unique(hosts),
|
|
59
|
+
...(localHosts.length > 0 ? { localHosts: unique(localHosts) } : {}),
|
|
60
|
+
secrets,
|
|
61
|
+
tokens: sheet.tokens.map((token) => token.name),
|
|
62
|
+
};
|
|
63
|
+
return ok(sheet.limits === undefined ? { policy } : { policy, limits: sheet.limits });
|
|
64
|
+
}
|
|
65
|
+
/** The placement part of a sheet's secret, without its purpose and hosts. */
|
|
66
|
+
function placementOf(secret) {
|
|
67
|
+
switch (secret.as) {
|
|
68
|
+
case "bearer":
|
|
69
|
+
return { as: "bearer" };
|
|
70
|
+
case "header":
|
|
71
|
+
return secret.prefix === undefined
|
|
72
|
+
? { as: "header", header: secret.header }
|
|
73
|
+
: { as: "header", header: secret.header, prefix: secret.prefix };
|
|
74
|
+
case "form":
|
|
75
|
+
return { as: "form", field: secret.field };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** The class the sheet declares for each setting a `{ fromSetting }` host reads. */
|
|
79
|
+
function settingClasses(sheet) {
|
|
80
|
+
const classes = new Map();
|
|
81
|
+
for (const host of sheet.hosts) {
|
|
82
|
+
if (typeof host !== "string" && !classes.has(host.fromSetting)) {
|
|
83
|
+
classes.set(host.fromSetting, host.class);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return classes;
|
|
87
|
+
}
|
|
88
|
+
function resolveHost(sheet, host, classes, settings, path, problems) {
|
|
89
|
+
if (typeof host === "string") {
|
|
90
|
+
return { host, hostname: host, plain: false };
|
|
91
|
+
}
|
|
92
|
+
const setting = host.fromSetting;
|
|
93
|
+
// A secret's `{ fromSetting }` host that `hosts` leaves out has no class;
|
|
94
|
+
// the sheet's checks refuse it as `secret-host-not-declared`.
|
|
95
|
+
const declared = classes.get(setting);
|
|
96
|
+
const value = Object.hasOwn(settings, setting) ? settings[setting] : undefined;
|
|
97
|
+
if (typeof value !== "string" || value === "") {
|
|
98
|
+
problems.push({
|
|
99
|
+
code: "setting-missing",
|
|
100
|
+
path,
|
|
101
|
+
message: `${sheet.id}: the setting "${setting}" must hold the server's URL`,
|
|
102
|
+
});
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const found = parseUrlHost(value);
|
|
106
|
+
if (found === undefined) {
|
|
107
|
+
problems.push({
|
|
108
|
+
code: "setting-not-a-url",
|
|
109
|
+
path,
|
|
110
|
+
message: `${sheet.id}: the setting "${setting}" must be an http or https URL without a user name or password`,
|
|
111
|
+
});
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (found.plain && !isLocalAddress(found.hostname)) {
|
|
115
|
+
problems.push({
|
|
116
|
+
code: "plain-http-not-local",
|
|
117
|
+
path,
|
|
118
|
+
message: `${sheet.id}: plain http is allowed only to this machine or a private network address, not to ${found.host}; use https`,
|
|
119
|
+
});
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
if (declared === undefined || addressClassOf(found.hostname) !== declared) {
|
|
123
|
+
problems.push({
|
|
124
|
+
code: "setting-outside-class",
|
|
125
|
+
path,
|
|
126
|
+
message: `${sheet.id}: the setting "${setting}" must hold ${classWords(declared)}, not ${found.host}`,
|
|
127
|
+
});
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return found;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The class a URL's host is in, read from the literal text: a name can
|
|
134
|
+
* resolve anywhere, so only `localhost` and IP addresses count as this
|
|
135
|
+
* computer or the home network, and an IP address never counts as public.
|
|
136
|
+
* Undefined for an address in no class, such as link-local `169.254.0.0/16`,
|
|
137
|
+
* where cloud machines serve their credentials, or `[::]`.
|
|
138
|
+
*
|
|
139
|
+
* Checking the addresses a public name resolves to is the Node transport's
|
|
140
|
+
* job (I5 design 3.8), on every request.
|
|
141
|
+
*/
|
|
142
|
+
function addressClassOf(hostname) {
|
|
143
|
+
if (isLoopback(hostname)) {
|
|
144
|
+
return "loopback";
|
|
145
|
+
}
|
|
146
|
+
if (isLocalAddress(hostname)) {
|
|
147
|
+
return "private";
|
|
148
|
+
}
|
|
149
|
+
const literal = hostname.startsWith("[") || ipv4(hostname) !== undefined;
|
|
150
|
+
return literal || hostname.endsWith(".localhost") ? undefined : "public";
|
|
151
|
+
}
|
|
152
|
+
/** What a class allows, for a message. */
|
|
153
|
+
function classWords(declared) {
|
|
154
|
+
switch (declared) {
|
|
155
|
+
case "loopback":
|
|
156
|
+
return "a URL on this machine (localhost, 127.0.0.0/8 or [::1])";
|
|
157
|
+
case "private":
|
|
158
|
+
return "a URL with a private network address (10/8, 172.16/12, 192.168/16 or fc00::/7)";
|
|
159
|
+
case "public":
|
|
160
|
+
return "an https URL with a public host name";
|
|
161
|
+
case undefined:
|
|
162
|
+
return "a URL for a host in the sheet's hosts";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The scheme, host and port of an absolute `http` or `https` URL, as
|
|
167
|
+
* `URL.host` gives them. The core has no `URL` class (plan 4.1), so this
|
|
168
|
+
* reads it by hand and accepts only the plain forms `URL` leaves unchanged:
|
|
169
|
+
* a name or dotted IPv4 address in lower case or a bracketed IPv6 address
|
|
170
|
+
* as `URL` writes it. Anything else is refused, so the kit's own match never
|
|
171
|
+
* sees a host spelled two ways.
|
|
172
|
+
*/
|
|
173
|
+
function parseUrlHost(url) {
|
|
174
|
+
const parts = /^(https?):\/\/([^/?#]*)(?:[/?#]|$)/i.exec(url);
|
|
175
|
+
const scheme = parts?.[1]?.toLowerCase();
|
|
176
|
+
const authority = parts?.[2]?.toLowerCase() ?? "";
|
|
177
|
+
const hostAndPort = /^(\[[0-9a-f:]+\]|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*)(?::(\d{1,5}))?$/.exec(authority);
|
|
178
|
+
const hostname = hostAndPort?.[1];
|
|
179
|
+
if (scheme === undefined || hostname === undefined) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
if (hostname.startsWith("[") ? !canonicalIpv6(hostname) : !canonicalIpv4(hostname)) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const port = hostAndPort?.[2];
|
|
186
|
+
if (port !== undefined && (Number(port) > 65535 || port !== String(Number(port)))) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const defaultPort = scheme === "https" ? "443" : "80";
|
|
190
|
+
const host = port === undefined || port === defaultPort ? hostname : `${hostname}:${port}`;
|
|
191
|
+
return { host, hostname, plain: scheme === "http" };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* `URL` reads a name whose last part is a number as an IPv4 address, so such
|
|
195
|
+
* a name must be four parts of 0 to 255 without leading zeros, as `URL`
|
|
196
|
+
* writes it.
|
|
197
|
+
*/
|
|
198
|
+
function canonicalIpv4(hostname) {
|
|
199
|
+
if (!/(?:^|\.)\d+$/.test(hostname)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
const parts = hostname.split(".");
|
|
203
|
+
return (parts.length === 4 &&
|
|
204
|
+
parts.every((part) => /^(?:0|[1-9]\d{0,2})$/.test(part) && Number(part) <= 255));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* A bracketed IPv6 address as `URL` writes it: eight groups in lower-case hex
|
|
208
|
+
* without leading zeros, the longest run of two or more zero groups (the
|
|
209
|
+
* first, on a tie) written `::`, and no dotted IPv4 tail.
|
|
210
|
+
*/
|
|
211
|
+
function canonicalIpv6(bracketed) {
|
|
212
|
+
const address = bracketed.slice(1, -1);
|
|
213
|
+
const halves = address.split("::");
|
|
214
|
+
const groupsOf = (half) => (half === "" ? [] : half.split(":"));
|
|
215
|
+
const head = groupsOf(halves[0] ?? "");
|
|
216
|
+
const tail = groupsOf(halves[1] ?? "");
|
|
217
|
+
const zeros = 8 - head.length - tail.length;
|
|
218
|
+
if (halves.length > 2 || (halves.length === 2 ? zeros < 1 : zeros !== 0)) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
if (![...head, ...tail].every((group) => /^[0-9a-f]{1,4}$/.test(group))) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const groups = [...head, ...Array(zeros).fill("0"), ...tail].map((group) => Number.parseInt(group, 16).toString(16));
|
|
225
|
+
let start = -1;
|
|
226
|
+
let length = 0;
|
|
227
|
+
for (let i = 0; i < 8; i += 1) {
|
|
228
|
+
let end = i;
|
|
229
|
+
while (end < 8 && groups[end] === "0") {
|
|
230
|
+
end += 1;
|
|
231
|
+
}
|
|
232
|
+
if (end - i >= 2 && end - i > length) {
|
|
233
|
+
start = i;
|
|
234
|
+
length = end - i;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const written = start === -1
|
|
238
|
+
? groups.join(":")
|
|
239
|
+
: `${groups.slice(0, start).join(":")}::${groups.slice(start + length).join(":")}`;
|
|
240
|
+
return written === address;
|
|
241
|
+
}
|
|
242
|
+
// The same rules as the kit's `local-address.ts`, which checks again on every
|
|
243
|
+
// request: only literal addresses and `localhost` count, since a name can
|
|
244
|
+
// resolve anywhere. Link-local addresses (169.254/16) don't count.
|
|
245
|
+
/** `localhost`, `127.0.0.0/8` or `::1`: this machine. */
|
|
246
|
+
function isLoopback(hostname) {
|
|
247
|
+
return hostname === "localhost" || hostname === "[::1]" || ipv4(hostname)?.[0] === 127;
|
|
248
|
+
}
|
|
249
|
+
/** Loopback, or `10/8`, `172.16/12`, `192.168/16` or IPv6 `fc00::/7`. */
|
|
250
|
+
function isLocalAddress(hostname) {
|
|
251
|
+
if (isLoopback(hostname)) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
const v4 = ipv4(hostname);
|
|
255
|
+
if (v4 !== undefined) {
|
|
256
|
+
const [a = 0, b = 0] = v4;
|
|
257
|
+
return a === 10 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168);
|
|
258
|
+
}
|
|
259
|
+
return /^\[f[cd][0-9a-f]{2}:/.test(hostname);
|
|
260
|
+
}
|
|
261
|
+
/** The four numbers of a whole dotted IPv4 address, as the kit reads it. */
|
|
262
|
+
function ipv4(hostname) {
|
|
263
|
+
const parts = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(hostname);
|
|
264
|
+
return parts?.slice(1).map(Number);
|
|
265
|
+
}
|
|
266
|
+
function unique(values) {
|
|
267
|
+
return [...new Set(values)];
|
|
268
|
+
}
|