@inneranimalmedia/agentsam-sdk 2.6.9 → 2.6.11
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 +21 -0
- package/TRADEMARKS.md +22 -0
- package/apps/README.md +3 -0
- package/apps/cad-creator/LICENSE +21 -0
- package/apps/cad-creator/README.md +4 -1
- package/apps/cad-creator/shared/cad/package.json +1 -1
- package/apps/client-cms-editor/LICENSE +21 -0
- package/apps/client-cms-editor/README.md +3 -0
- package/apps/client-cms-editor/backend/package.json +3 -3
- package/apps/client-cms-editor/frontend/package.json +4 -4
- package/apps/client-cms-editor/package-lock.json +43 -43
- package/apps/client-cms-editor/package.json +3 -3
- package/apps/client-cms-editor/reference/harvest/HARVEST_RECEIPT.json +1 -1
- package/apps/client-cms-editor/reference/harvest/README.md +1 -1
- package/apps/client-cms-editor/reference/harvest/plans/ARCHIVE-INTAKE.md +1 -1
- package/apps/client-cms-editor/reference/harvest/plans/HARVEST-INDEX.md +1 -1
- package/apps/client-cms-editor/reference/harvest/plans/TOOLING-LAB.md +1 -1
- package/apps/client-cms-editor/shared/cms/package.json +2 -2
- package/docs/MINI.md +4 -2
- package/docs/REPO_FILE_MAP.txt +0 -1
- package/docs/SOURCE_ARCHITECTURE.md +1 -1
- package/docs/architecture/DUAL_ANALYTICS_PRODUCT.md +140 -0
- package/docs/architecture/HOOKS-MODELS-SELF-HOSTING-PLAN.md +199 -0
- package/docs/content-studio/REVISION_GATE_2026-09-27.md +1 -1
- package/docs/engineering/go-portability/01-product-project-deployment-authority.md +69 -0
- package/docs/engineering/provider-internal-renames/01-lane-initialization.md +20 -0
- package/docs/engineering/provider-internal-renames/01a-runtime-environment-contract.md +115 -0
- package/docs/engineering/provider-internal-renames/02-cfoa.md +57 -0
- package/docs/engineering/provider-internal-renames/03-gclioa.md +32 -0
- package/docs/engineering/provider-internal-renames/04-goaude.md +50 -0
- package/docs/engineering/provider-internal-renames/05-gdrv.md +33 -0
- package/docs/engineering/provider-internal-renames/06-verification.md +103 -0
- package/docs/engineering/provider-internal-renames/README.md +77 -0
- package/docs/engineering/provider-internal-renames/runtime-environment-contract.json +220 -0
- package/docs/engineering/test-diagnostics/go-cli-test-hang-20261003.md +49 -0
- package/docs/engineering/test-diagnostics/go-skip-deploy-docker-fix.md +90 -0
- package/docs/knowledge-service-verification.md +3 -3
- package/docs/plans/AGENTSAM-SUSPEND-QUEUE-KNOWLEDGE-RDP-2026-10-03.md +870 -0
- package/docs/plans/LOCAL-STUDIO-GRADUATION-2026-09-26.md +9 -9
- package/docs/plans/MACHINE-FIRST-APPS-TUI-2026-09-24.md +11 -11
- package/docs/plans/RECONCILIATION-2026-09-19.md +6 -6
- package/docs/plans/SAM_WORK_PROTOCOL.md +667 -0
- package/docs/plans/TOMORROW-EXTENSIVE-TODO-2026-09-26.md +2 -2
- package/docs/plans/UNIVERSAL-INGEST-MACHINE-FIRST-2026-09-24.md +3 -3
- package/examples/hyperspace-demo/index.html +16 -0
- package/examples/hyperspace-demo/package.json +21 -0
- package/examples/hyperspace-demo/src/main.tsx +277 -0
- package/examples/hyperspace-demo/tsconfig.json +9 -0
- package/examples/hyperspace-demo/vite.config.ts +24 -0
- package/migrations/d1/0020_agentsam_receipt_catalog.sql +35 -0
- package/migrations/runtime/0005_agentsam_hooks.sql +87 -0
- package/migrations/runtime/0006_agent_run_suspend_activity.sql +53 -0
- package/migrations/runtime/0007_queue_control.sql +40 -0
- package/migrations/runtime/0008_agent_run_dependencies.sql +24 -0
- package/migrations/runtime/0008_analytics_legacy_bootstrap.sql +43 -0
- package/migrations/runtime/0009_analytics_authority.sql +108 -0
- package/package.json +45 -14
- package/packages/agentsam-brand/README.md +3 -0
- package/packages/agentsam-brand/package.json +2 -2
- package/packages/agentsam-brand/src/core/v2/compile.js +1 -1
- package/packages/agentsam-brand/src/core/v2/schema.js +1 -1
- package/packages/agentsam-contracts/dist/adapter.d.ts +22 -0
- package/packages/agentsam-contracts/dist/adapter.js +0 -0
- package/packages/agentsam-contracts/dist/agent.d.ts +66 -0
- package/packages/agentsam-contracts/dist/agent.js +15 -0
- package/packages/agentsam-contracts/dist/artifacts.d.ts +70 -0
- package/packages/agentsam-contracts/dist/artifacts.js +0 -0
- package/packages/agentsam-contracts/dist/authority.d.ts +21 -0
- package/packages/agentsam-contracts/dist/authority.js +0 -0
- package/packages/agentsam-contracts/dist/context.d.ts +14 -0
- package/packages/agentsam-contracts/dist/context.js +0 -0
- package/packages/agentsam-contracts/dist/errors.d.ts +121 -0
- package/packages/agentsam-contracts/dist/errors.js +5 -0
- package/packages/agentsam-contracts/dist/events.d.ts +53 -0
- package/packages/agentsam-contracts/dist/events.js +0 -0
- package/packages/agentsam-contracts/dist/execution.d.ts +38 -0
- package/packages/agentsam-contracts/dist/execution.js +0 -0
- package/packages/agentsam-contracts/dist/hooks.d.ts +31 -0
- package/packages/agentsam-contracts/dist/hooks.js +0 -0
- package/packages/agentsam-contracts/dist/identity.d.ts +15 -0
- package/packages/agentsam-contracts/dist/identity.js +0 -0
- package/packages/agentsam-contracts/dist/index.d.ts +16 -0
- package/packages/agentsam-contracts/dist/index.js +164 -0
- package/packages/agentsam-contracts/dist/models.d.ts +9 -0
- package/packages/agentsam-contracts/dist/models.js +0 -0
- package/packages/agentsam-contracts/dist/providers.d.ts +27 -0
- package/packages/agentsam-contracts/dist/providers.js +0 -0
- package/packages/agentsam-contracts/dist/repository.d.ts +56 -0
- package/packages/agentsam-contracts/dist/repository.js +15 -0
- package/packages/agentsam-contracts/dist/run.d.ts +113 -0
- package/packages/agentsam-contracts/dist/run.js +132 -0
- package/packages/agentsam-contracts/dist/tools.d.ts +82 -0
- package/packages/agentsam-contracts/dist/tools.js +0 -0
- package/packages/agentsam-contracts/dist/widgets.d.ts +38 -0
- package/packages/agentsam-contracts/dist/widgets.js +0 -0
- package/packages/agentsam-contracts/package.json +9 -1
- package/packages/agentsam-contracts/scripts/build.mjs +1 -1
- package/packages/agentsam-contracts/src/agent.ts +78 -3
- package/packages/agentsam-contracts/src/errors.ts +19 -10
- package/packages/agentsam-contracts/src/index.ts +2 -0
- package/packages/agentsam-contracts/src/run.ts +320 -0
- package/packages/agentsam-contracts/src/widgets.ts +58 -0
- package/packages/agentsam-contracts/test/contracts.test.mjs +1 -1
- package/packages/agentsam-contracts/test/run-contract.test.mjs +94 -0
- package/packages/agentsam-errors/package.json +11 -3
- package/packages/agentsam-errors/protocol/agentsam.error.v2.schema.json +821 -0
- package/packages/agentsam-errors/protocol/error-catalog.json +3512 -0
- package/packages/agentsam-errors/src/envelope.js +63 -11
- package/packages/agentsam-errors/src/error.js +6 -0
- package/packages/agentsam-errors/src/fingerprint.js +9 -1
- package/packages/agentsam-errors/src/normalize.js +51 -6
- package/packages/agentsam-errors/src/recovery.js +9 -35
- package/packages/agentsam-errors/src/transport.js +6 -1
- package/packages/agentsam-errors/src/vocabulary.js +515 -126
- package/packages/agentsam-errors/test/catalog-v2.test.mjs +106 -0
- package/packages/agentsam-errors/types/index.d.ts +157 -0
- package/packages/agentsam-goap/README.md +3 -0
- package/packages/agentsam-goap/package.json +2 -2
- package/packages/agentsam-hooks/README.md +206 -0
- package/packages/agentsam-hooks/bin/agentsam-hooks.mjs +64 -0
- package/packages/agentsam-hooks/bindings/go/command.go +55 -0
- package/packages/agentsam-hooks/bindings/go/errors_generated.go +402 -0
- package/packages/agentsam-hooks/bindings/go/go.mod +3 -0
- package/packages/agentsam-hooks/bindings/go/hooks.go +285 -0
- package/packages/agentsam-hooks/bindings/go/hooks_test.go +48 -0
- package/packages/agentsam-hooks/bindings/rust/Cargo.toml +11 -0
- package/packages/agentsam-hooks/bindings/rust/src/errors_generated.rs +396 -0
- package/packages/agentsam-hooks/bindings/rust/src/lib.rs +397 -0
- package/packages/agentsam-hooks/package.json +69 -0
- package/packages/agentsam-hooks/schema/manifest.json +54 -0
- package/packages/agentsam-hooks/scripts/clean-protocol.mjs +17 -0
- package/packages/agentsam-hooks/scripts/sync-protocol.mjs +27 -0
- package/packages/agentsam-hooks/src/adapters/agents.js +108 -0
- package/packages/agentsam-hooks/src/adapters/callback.js +4 -0
- package/packages/agentsam-hooks/src/adapters/capability.js +122 -0
- package/packages/agentsam-hooks/src/adapters/command.js +104 -0
- package/packages/agentsam-hooks/src/adapters/composite.js +31 -0
- package/packages/agentsam-hooks/src/adapters/http.js +58 -0
- package/packages/agentsam-hooks/src/adapters/lsp.js +116 -0
- package/packages/agentsam-hooks/src/adapters/mcp.js +76 -0
- package/packages/agentsam-hooks/src/adapters/provider.js +129 -0
- package/packages/agentsam-hooks/src/config.js +143 -0
- package/packages/agentsam-hooks/src/contracts.js +284 -0
- package/packages/agentsam-hooks/src/errors-generated.js +2732 -0
- package/packages/agentsam-hooks/src/index.d.ts +209 -0
- package/packages/agentsam-hooks/src/index.js +14 -0
- package/packages/agentsam-hooks/src/policy.js +34 -0
- package/packages/agentsam-hooks/src/runtime.js +312 -0
- package/packages/agentsam-hooks/src/store.js +264 -0
- package/packages/agentsam-hooks/test/adapters.test.mjs +216 -0
- package/packages/agentsam-hooks/test/runtime.test.mjs +258 -0
- package/packages/agentsam-knowledge/package.json +1 -1
- package/packages/agentsam-knowledge/src/backends/index.js +1 -1
- package/packages/agentsam-merch/README.md +62 -0
- package/packages/agentsam-merch/bin/agentsam-merch.mjs +16 -0
- package/packages/agentsam-merch/package.json +65 -0
- package/packages/agentsam-merch/profiles/completeful/dtg-back-large.json +42 -0
- package/packages/agentsam-merch/profiles/completeful/laser-engraving.json +39 -0
- package/packages/agentsam-merch/profiles/generic/embroidery-digitization.json +22 -0
- package/packages/agentsam-merch/schemas/collection-candidate.schema.json +66 -0
- package/packages/agentsam-merch/schemas/manufacturing-profile.schema.json +221 -0
- package/packages/agentsam-merch/src/adapters-completeful.js +50 -0
- package/packages/agentsam-merch/src/cli.js +93 -0
- package/packages/agentsam-merch/src/collection-lab.js +60 -0
- package/packages/agentsam-merch/src/compatibility.js +501 -0
- package/packages/agentsam-merch/src/derivatives.js +112 -0
- package/packages/agentsam-merch/src/index.d.ts +316 -0
- package/packages/agentsam-merch/src/index.js +46 -0
- package/packages/agentsam-merch/src/node/index.d.ts +58 -0
- package/packages/agentsam-merch/src/node/index.js +6 -0
- package/packages/agentsam-merch/src/node/raster.js +142 -0
- package/packages/agentsam-merch/src/node/vector.js +239 -0
- package/packages/agentsam-merch/src/product-concepts.js +118 -0
- package/packages/agentsam-merch/src/profile-registry.js +104 -0
- package/packages/agentsam-merch/src/profile.js +158 -0
- package/packages/agentsam-merch/src/transforms.js +215 -0
- package/packages/agentsam-merch/test/merch.test.mjs +332 -0
- package/packages/agentsam-merch/test/node-transforms.test.mjs +149 -0
- package/packages/agentsam-nav/dist/Nav.d.ts +43 -0
- package/packages/agentsam-nav/dist/NavCollapsible.d.ts +10 -0
- package/packages/agentsam-nav/dist/NavContent.d.ts +2 -0
- package/packages/agentsam-nav/dist/NavFooter.d.ts +2 -0
- package/packages/agentsam-nav/dist/NavGroup.d.ts +3 -0
- package/packages/agentsam-nav/dist/NavHeader.d.ts +2 -0
- package/packages/agentsam-nav/dist/NavMenu.d.ts +22 -0
- package/packages/agentsam-nav/dist/NavProvider.d.ts +35 -0
- package/packages/agentsam-nav/dist/NavTrigger.d.ts +2 -0
- package/packages/agentsam-nav/dist/Surfaces.d.ts +41 -0
- package/packages/agentsam-nav/dist/browser.d.ts +11 -0
- package/packages/agentsam-nav/dist/browser.global.js +172 -0
- package/packages/agentsam-nav/dist/browser.js +9688 -0
- package/packages/agentsam-nav/dist/contracts.d.ts +76 -0
- package/packages/agentsam-nav/dist/index.d.ts +11 -0
- package/packages/agentsam-nav/dist/index.js +9689 -0
- package/packages/agentsam-nav/dist/legacy.css +83 -0
- package/packages/agentsam-nav/dist/shell.css +113 -0
- package/packages/agentsam-nav/dist/theme.css +113 -0
- package/packages/agentsam-nav/dist/utils.d.ts +1 -0
- package/packages/agentsam-nav/package.json +1 -1
- package/packages/agentsam-queue-control/README.md +4 -1
- package/packages/agentsam-queue-control/package.json +4 -3
- package/packages/agentsam-queue-control/schemas/job-envelope.schema.json +111 -11
- package/packages/agentsam-queue-control/src/adapters/cloudflare.js +34 -6
- package/packages/agentsam-queue-control/src/adapters/memory.js +11 -2
- package/packages/agentsam-queue-control/src/adapters/sqlite.js +259 -0
- package/packages/agentsam-queue-control/src/contracts.js +207 -3
- package/packages/agentsam-queue-control/src/control-plane.js +62 -2
- package/packages/agentsam-queue-control/src/index.js +1 -0
- package/packages/agentsam-queue-control/test/queue-control.test.mjs +310 -0
- package/packages/agentsam-queue-control/test/sqlite-adapter.test.mjs +91 -0
- package/packages/agentsam-rapid-rust/README.md +3 -0
- package/packages/agentsam-repository/README.md +3 -0
- package/packages/agentsam-repository/package.json +1 -1
- package/packages/agentsam-vault/package.json +1 -1
- package/packages/agentsam-workbench/README.md +43 -0
- package/packages/agentsam-workbench/package.json +14 -4
- package/packages/agentsam-workbench/src/agent/AgentConversationSurface.tsx +108 -0
- package/packages/agentsam-workbench/src/agent/AgentPanel.tsx +25 -8
- package/packages/agentsam-workbench/src/agent/AgentRuntimeField.tsx +152 -0
- package/packages/agentsam-workbench/src/agent/Composer.tsx +10 -1
- package/packages/agentsam-workbench/src/agent/RunMode.ts +26 -0
- package/packages/agentsam-workbench/src/agent/Thread.tsx +18 -3
- package/packages/agentsam-workbench/src/agent/index.ts +3 -0
- package/packages/agentsam-workbench/src/index.ts +4 -0
- package/packages/agentsam-workbench/src/manufacturing/PreflightIndicator.tsx +203 -0
- package/packages/agentsam-workbench/src/manufacturing/index.ts +2 -0
- package/packages/agentsam-workbench/src/manufacturing/loading.ts +147 -0
- package/packages/agentsam-workbench/src/widgets/BuiltinWidget.tsx +22 -0
- package/packages/agentsam-workbench/src/widgets/CountdownWidget.tsx +68 -0
- package/packages/agentsam-workbench/src/widgets/WidgetFrame.tsx +56 -0
- package/packages/agentsam-workbench/src/widgets/countdown.ts +25 -0
- package/packages/agentsam-workbench/src/widgets/index.ts +6 -0
- package/packages/agentsam-workbench/src/widgets/registry.ts +13 -0
- package/packages/agentsam-workbench/src/widgets/useCountdown.ts +128 -0
- package/packages/agentsam-workbench/src/widgets/widgets.css +102 -0
- package/packages/connectors/{cloudflare → cfoa}/package.json +3 -3
- package/packages/heuristic-theme/package.json +1 -1
- package/packages/identity/README.md +3 -0
- package/packages/identity/backend/README.md +3 -0
- package/packages/identity/package.json +2 -2
- package/packages/identity/src/frontend/auth-portal/README.md +3 -0
- package/packages/identity/src/index.js +1 -1
- package/packages/identity/src/oauth/README.md +4 -1
- package/packages/identity/src/oauth/credentials.js +1 -1
- package/packages/identity/src/server/worker-router.js +1 -1
- package/packages/identity/tests/google-desktop-identity-login.test.mjs +1 -1
- package/packages/identity/tests/lane1-packed-consumer.test.mjs +1 -1
- package/packages/identity/tests/oauth-presets-accounts-ssot.test.mjs +1 -1
- package/packages/providers/completeful/package.json +1 -1
- package/packages/theme-church-site/package.json +2 -2
- package/packages/theme-companions-site/package.json +2 -2
- package/packages/theme-floors-site/package.json +2 -2
- package/packages/theme-fuelnfree-site/package.json +2 -2
- package/packages/theme-handyman-site/package.json +2 -2
- package/packages/theme-insurance-site/package.json +2 -2
- package/packages/theme-scenes/package.json +1 -1
- package/packages/theme-shinshu-site/package.json +2 -2
- package/packages/work-graph/package.json +1 -1
- package/protocol/apps/agentsam.app.v1.schema.json +1 -1
- package/protocol/apps/agentsam.host-install.v1.schema.json +1 -1
- package/protocol/assets/asset-record.v1.schema.json +1 -1
- package/protocol/brand/brandpack.v1.schema.json +1 -1
- package/protocol/capabilities/capability-manifest.schema.json +1 -1
- package/protocol/capabilities/knowledge-search-input.schema.json +1 -0
- package/protocol/credentials/issue.v1.schema.json +1 -1
- package/protocol/database/agentsam.schema-pack.v1.schema.json +1 -1
- package/protocol/database/connection.v1.schema.json +1 -1
- package/protocol/embeddings/embedding-profile.v1.schema.json +1 -1
- package/protocol/errors/README.md +36 -0
- package/protocol/errors/agentsam.error.v2.schema.json +821 -0
- package/protocol/errors/error-catalog.json +3506 -158
- package/protocol/errors/error-envelope.schema.json +195 -52
- package/protocol/errors/recovery.v1.schema.json +1 -1
- package/protocol/features/agentsam.feature.v1.schema.json +1 -1
- package/protocol/hooks/README.md +18 -0
- package/protocol/hooks/agentsam.hook.output.v1.schema.json +27 -0
- package/protocol/hooks/agentsam.hook.receipt.v1.schema.json +61 -0
- package/protocol/hooks/agentsam.hook.v1.schema.json +35 -0
- package/protocol/hooks/agentsam.hooks.config.v1.schema.json +78 -0
- package/protocol/local-engine/benchmark.v1.schema.json +1 -1
- package/protocol/local-engine/engine.v1.schema.json +1 -1
- package/protocol/models/README.md +3 -0
- package/protocol/models/model-inventory-v2.schema.json +1 -1
- package/protocol/models/provider-model-snapshot.v1.schema.json +22 -0
- package/protocol/receipts/agentsam.receipt.v1.json +95 -0
- package/protocol/rpc/v1/errors.proto +1 -0
- package/protocol/runtime/agentsam.runtime.v1.schema.json +1 -1
- package/protocol/runtime/workspace-fs.v1.schema.json +1 -1
- package/protocol/sam/activity.v1.schema.json +1 -1
- package/protocol/sam/answer.v1.schema.json +1 -1
- package/protocol/sam/calibration.v1.schema.json +1 -1
- package/protocol/sam/decision-receipt.v1.schema.json +1 -1
- package/protocol/sam/evaluation.v1.schema.json +1 -1
- package/protocol/sam/operation.schema.json +1 -1
- package/protocol/sam/outcome.v1.schema.json +1 -1
- package/protocol/sam/question.v1.schema.json +1 -1
- package/protocol/sam/result.schema.json +1 -1
- package/protocol/sam/state.v1.schema.json +1 -1
- package/protocol/scoring/scorecard.v1.schema.json +1 -1
- package/protocol/skills/agentsam.interaction.v1.schema.json +1 -1
- package/protocol/skills/agentsam.skill.v1.schema.json +1 -1
- package/protocol/theme-refinery/product-metadata.schema.json +1 -1
- package/protocol/theme-refinery/receipts/products-registry-batch-20260924.json +6 -6
- package/protocol/theme-refinery/receipts/theme-harvest-20260924.json +6 -6
- package/protocol/theme-refinery/reconciliation-receipt.schema.json +1 -1
- package/protocol/ui/icon.v1.schema.json +1 -1
- package/python/README.md +20 -0
- package/python/agentsam_sdk/errors/__init__.py +4 -0
- package/python/agentsam_sdk/errors/vocabulary.py +2730 -0
- package/python/agentsam_sdk/hooks/__init__.py +32 -0
- package/python/agentsam_sdk/hooks/adapters.py +132 -0
- package/python/agentsam_sdk/hooks/contracts.py +121 -0
- package/python/agentsam_sdk/hooks/runtime.py +253 -0
- package/python/tests/test_hooks.py +115 -0
- package/skills/README.md +3 -0
- package/src/acp/agent-executor.js +106 -0
- package/src/acp/client.js +316 -0
- package/src/acp/dependencies.js +426 -0
- package/src/acp/http.js +207 -0
- package/src/acp/index.js +22 -0
- package/src/acp/runs.js +125 -0
- package/src/acp/runtime-selection.js +180 -0
- package/src/agent/responses-runner.js +145 -1
- package/src/cli/command-catalog.js +4 -0
- package/src/cli.js +33 -0
- package/src/commands/cheat-sheet.js +1 -0
- package/src/commands/cloudflare-login.js +1 -1
- package/src/commands/cloudflare.js +2 -2
- package/src/commands/connections.js +1 -1
- package/src/commands/go.js +76 -6
- package/src/commands/hooks.js +260 -0
- package/src/commands/merch.js +5 -0
- package/src/commands/mini.js +1 -1
- package/src/commands/models.js +1 -1
- package/src/commands/receipts.js +140 -0
- package/src/commands/run.js +253 -0
- package/src/commands/shell.js +114 -9
- package/src/errors/diagnostic.js +9 -9
- package/src/go/container.js +1 -1
- package/src/go/contract.js +61 -18
- package/src/go/discover.js +0 -4
- package/src/go/index.js +13 -1
- package/src/go/probe.js +109 -0
- package/src/go/{cloudflare.js → providers/cloudflare.js} +36 -136
- package/src/go/verify.js +1 -1
- package/src/index.js +32 -0
- package/src/indexing/ingest/inventory.js +1 -1
- package/src/knowledge/service/grpc-codec.js +2 -0
- package/src/lib/deploy/local-studio.js +2 -2
- package/src/lib/mini/scaffold.js +1 -1
- package/src/lib/slash-commands.js +1 -0
- package/src/lib/whoami-capabilities.js +1 -1
- package/src/local/runtime-store.js +54 -0
- package/src/mcp/cloudflare-bundles.js +1 -1
- package/src/models/catalog.js +0 -49
- package/src/models/inventory-core.js +69 -0
- package/src/plugins/index.js +9 -1
- package/src/plugins/registry.js +115 -6
- package/src/receipts/contract.js +68 -0
- package/src/receipts/index.js +20 -0
- package/src/receipts/prune.js +64 -0
- package/src/receipts/sinks.js +285 -0
- package/src/rpc/generated/errors_pb.js +49 -1
- package/src/tools/runtime.js +13 -5
- package/templates/mini/gadget/app.js +15 -40
- package/templates/mini/gadget/index.html +7 -7
- package/templates/mini/shared/style.css +1 -1
- /package/packages/connectors/{cloudflare → cfoa}/OAUTH_STORAGE_AUDIT.md +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/api-client.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/capabilities.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/credential.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/brand-protection.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/keyless.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/pages.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/scanner.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/snippets.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/tag-gateway.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/tags.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/token-validation.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/vectorize.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/families/workflows.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/index.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/oauth-persist.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/owner.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/permission-options.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/routes.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/scope-catalog.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/src/vault.js +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/tests/capabilities.test.mjs +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/tests/connector.test.mjs +0 -0
- /package/packages/connectors/{cloudflare → cfoa}/tests/oauth-persist.test.mjs +0 -0
- /package/packages/identity/src/oauth/{google-desktop-exchange.js → goaude.js} +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ensureHookRuntime } from '../runtime.js';
|
|
2
|
+
|
|
3
|
+
function normalizeAgent(value) {
|
|
4
|
+
const source = typeof value === 'string' ? { id: value } : value;
|
|
5
|
+
const id = String(source?.id || source?.name || '').trim();
|
|
6
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/.test(id)) throw new Error(`invalid_agent_id:${id || '<missing>'}`);
|
|
7
|
+
return Object.freeze({
|
|
8
|
+
id,
|
|
9
|
+
description: String(source.description || `Delegate bounded work to the ${id} agent.`),
|
|
10
|
+
metadata: source.metadata && typeof source.metadata === 'object' ? structuredClone(source.metadata) : {},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function runWithSubagentHooks(options = {}) {
|
|
15
|
+
if (typeof options.run !== 'function') throw new TypeError('subagent_run_required');
|
|
16
|
+
const agentId = String(options.agentId || options.agent_id || '').trim();
|
|
17
|
+
if (!agentId) throw new TypeError('subagent_agent_id_required');
|
|
18
|
+
const task = String(options.task || '').trim();
|
|
19
|
+
if (!task) throw new TypeError('subagent_task_required');
|
|
20
|
+
|
|
21
|
+
const hooks = ensureHookRuntime(options.hooks || options.hookRuntime);
|
|
22
|
+
const context = options.context && typeof options.context === 'object' ? options.context : {};
|
|
23
|
+
const invocation = {
|
|
24
|
+
...(options.invocation || {}),
|
|
25
|
+
agent_id: agentId,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await hooks.dispatch('subagent_start', {
|
|
29
|
+
agent_id: agentId,
|
|
30
|
+
task,
|
|
31
|
+
context,
|
|
32
|
+
}, invocation, { cwd: options.cwd });
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const result = await options.run({ task, context, invocation });
|
|
36
|
+
await hooks.dispatch('subagent_stop', {
|
|
37
|
+
agent_id: agentId,
|
|
38
|
+
task,
|
|
39
|
+
status: 'completed',
|
|
40
|
+
result,
|
|
41
|
+
}, invocation, { cwd: options.cwd });
|
|
42
|
+
return result;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
await hooks.dispatch('subagent_stop', {
|
|
45
|
+
agent_id: agentId,
|
|
46
|
+
task,
|
|
47
|
+
status: 'failed',
|
|
48
|
+
error: { code: error?.code || null, message: String(error?.message || error) },
|
|
49
|
+
}, invocation, { cwd: options.cwd });
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createAgentCapabilityAdapter(options = {}) {
|
|
55
|
+
if (typeof options.runAgent !== 'function') throw new TypeError('run_agent_adapter_required');
|
|
56
|
+
const agents = (options.agents || []).map(normalizeAgent);
|
|
57
|
+
const hooks = ensureHookRuntime(options.hooks || options.hookRuntime);
|
|
58
|
+
const byCapability = new Map(agents.map((agent) => [`agent.delegate.${agent.id}`, agent]));
|
|
59
|
+
const parentInvocation = options.invocation || {};
|
|
60
|
+
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
toolDescriptors() {
|
|
63
|
+
return [...byCapability].map(([name, agent]) => Object.freeze({
|
|
64
|
+
name,
|
|
65
|
+
description: agent.description,
|
|
66
|
+
category: 'agents',
|
|
67
|
+
risk: 'write',
|
|
68
|
+
strict: false,
|
|
69
|
+
input_schema: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
task: { type: 'string', minLength: 1, description: 'Bounded objective delegated to the sub-agent.' },
|
|
73
|
+
context: { type: 'object', description: 'Portable context references or structured evidence for the task.' },
|
|
74
|
+
},
|
|
75
|
+
required: ['task'],
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
},
|
|
80
|
+
canInvoke(id) { return byCapability.has(String(id)); },
|
|
81
|
+
async invoke(id, input = {}, context = {}) {
|
|
82
|
+
const agent = byCapability.get(String(id));
|
|
83
|
+
if (!agent) throw new Error(`agent_capability_unavailable:${id}`);
|
|
84
|
+
const task = String(input.task || '').trim();
|
|
85
|
+
if (!task) throw new TypeError('subagent_task_required');
|
|
86
|
+
const agentInvocation = {
|
|
87
|
+
...parentInvocation,
|
|
88
|
+
parent_agent_id: parentInvocation.agent_id || null,
|
|
89
|
+
agent_id: agent.id,
|
|
90
|
+
};
|
|
91
|
+
return runWithSubagentHooks({
|
|
92
|
+
hookRuntime: hooks,
|
|
93
|
+
agentId: agent.id,
|
|
94
|
+
task,
|
|
95
|
+
context: input.context || {},
|
|
96
|
+
invocation: agentInvocation,
|
|
97
|
+
cwd: context.cwd || options.cwd,
|
|
98
|
+
run: () => options.runAgent({
|
|
99
|
+
agent,
|
|
100
|
+
task,
|
|
101
|
+
context: input.context || {},
|
|
102
|
+
parent: context,
|
|
103
|
+
invocation: agentInvocation,
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ensureHookRuntime } from '../runtime.js';
|
|
2
|
+
import { resolveHookPermission } from '../policy.js';
|
|
3
|
+
|
|
4
|
+
const HOOKED_CAPABILITY_ADAPTER = Symbol.for('agentsam.hooks.capability-adapter');
|
|
5
|
+
|
|
6
|
+
function serializedError(error) {
|
|
7
|
+
return Object.freeze({
|
|
8
|
+
name: error?.name || 'Error',
|
|
9
|
+
code: error?.code || null,
|
|
10
|
+
message: String(error?.message || error),
|
|
11
|
+
status: Number.isFinite(Number(error?.status)) ? Number(error.status) : null,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createHookedCapabilityAdapter(baseAdapter, options = {}) {
|
|
16
|
+
if (!baseAdapter?.toolDescriptors || !baseAdapter?.invoke) throw new TypeError('base_capability_adapter_required');
|
|
17
|
+
if (baseAdapter[HOOKED_CAPABILITY_ADAPTER]) return baseAdapter;
|
|
18
|
+
const hooks = ensureHookRuntime(options.hooks || options.hookRuntime);
|
|
19
|
+
const invocation = options.invocation || {};
|
|
20
|
+
const cwd = options.cwd;
|
|
21
|
+
const maxRetries = Number.isInteger(options.maxRetries) ? Math.max(0, Math.min(options.maxRetries, 10)) : 3;
|
|
22
|
+
|
|
23
|
+
const adapter = {
|
|
24
|
+
...baseAdapter,
|
|
25
|
+
[HOOKED_CAPABILITY_ADAPTER]: true,
|
|
26
|
+
toolDescriptors(descriptorOptions = {}) { return baseAdapter.toolDescriptors(descriptorOptions); },
|
|
27
|
+
canInvoke(id) { return typeof baseAdapter.canInvoke === 'function' ? baseAdapter.canInvoke(id) : true; },
|
|
28
|
+
describe(id) { return typeof baseAdapter.describe === 'function' ? baseAdapter.describe(id) : undefined; },
|
|
29
|
+
list(listOptions = {}) { return typeof baseAdapter.list === 'function' ? baseAdapter.list(listOptions) : this.toolDescriptors(listOptions); },
|
|
30
|
+
async invoke(id, input = {}, context = {}) {
|
|
31
|
+
const toolName = String(id);
|
|
32
|
+
const pre = await hooks.dispatch('pre_tool_use', {
|
|
33
|
+
tool_name: toolName,
|
|
34
|
+
tool_args: input,
|
|
35
|
+
cwd: cwd || context.cwd,
|
|
36
|
+
}, invocation, { cwd: cwd || context.cwd });
|
|
37
|
+
await resolveHookPermission({
|
|
38
|
+
output: pre.output,
|
|
39
|
+
kind: 'tool',
|
|
40
|
+
name: toolName,
|
|
41
|
+
requestPermission: options.requestPermission,
|
|
42
|
+
envelope: pre,
|
|
43
|
+
});
|
|
44
|
+
const args = pre.input.tool_args;
|
|
45
|
+
const hookContext = pre.output.additional_context;
|
|
46
|
+
let retriesRemaining = maxRetries;
|
|
47
|
+
|
|
48
|
+
let value;
|
|
49
|
+
while (true) {
|
|
50
|
+
try {
|
|
51
|
+
value = await baseAdapter.invoke(toolName, args, {
|
|
52
|
+
...context,
|
|
53
|
+
...(hookContext ? { hook_context: hookContext } : {}),
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const failed = await hooks.dispatch('post_tool_use_failure', {
|
|
58
|
+
tool_name: toolName,
|
|
59
|
+
tool_args: args,
|
|
60
|
+
error: serializedError(error),
|
|
61
|
+
cwd: cwd || context.cwd,
|
|
62
|
+
}, invocation, { cwd: cwd || context.cwd });
|
|
63
|
+
if (failed.output.additional_context) error.hook_context = failed.output.additional_context;
|
|
64
|
+
const occurred = await hooks.dispatch('error_occurred', {
|
|
65
|
+
error: String(error?.message || error),
|
|
66
|
+
error_context: 'tool_execution',
|
|
67
|
+
recoverable: error?.recoverable !== false,
|
|
68
|
+
tool_name: toolName,
|
|
69
|
+
cwd: cwd || context.cwd,
|
|
70
|
+
}, invocation, { cwd: cwd || context.cwd });
|
|
71
|
+
const handling = occurred.output.error_handling;
|
|
72
|
+
const requestedRetries = Math.min(Number(occurred.output.retry_count || 1), maxRetries);
|
|
73
|
+
if (handling === 'retry' && retriesRemaining > 0 && requestedRetries > 0) {
|
|
74
|
+
retriesRemaining -= 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (handling === 'skip') {
|
|
78
|
+
return Object.freeze({
|
|
79
|
+
schema: 'agentsam.hook.skipped.v1',
|
|
80
|
+
skipped: true,
|
|
81
|
+
kind: 'tool_error',
|
|
82
|
+
tool_name: toolName,
|
|
83
|
+
error: serializedError(error),
|
|
84
|
+
notification: occurred.output.user_notification || null,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (occurred.output.additional_context) error.hook_context = [error.hook_context, occurred.output.additional_context].filter(Boolean).join('\n\n');
|
|
88
|
+
if (occurred.output.user_notification) error.user_notification = occurred.output.user_notification;
|
|
89
|
+
if (occurred.output.suppress_output === true) error.suppress_output = true;
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Post-hook failures happen after the tool may have produced side effects.
|
|
95
|
+
// Never feed those failures into the tool retry policy.
|
|
96
|
+
const post = await hooks.dispatch('post_tool_use', {
|
|
97
|
+
tool_name: toolName,
|
|
98
|
+
tool_args: args,
|
|
99
|
+
tool_result: value,
|
|
100
|
+
cwd: cwd || context.cwd,
|
|
101
|
+
}, invocation, { cwd: cwd || context.cwd });
|
|
102
|
+
if (post.output.suppress_output === true) {
|
|
103
|
+
return Object.freeze({
|
|
104
|
+
schema: 'agentsam.hook.suppressed.v1',
|
|
105
|
+
suppressed: true,
|
|
106
|
+
kind: 'tool_result',
|
|
107
|
+
tool_name: toolName,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const contexts = [hookContext, post.output.additional_context].filter(Boolean);
|
|
111
|
+
if (contexts.length) {
|
|
112
|
+
return Object.freeze({
|
|
113
|
+
schema: 'agentsam.hook.contextualized-tool-result.v1',
|
|
114
|
+
result: post.input.tool_result,
|
|
115
|
+
additional_context: contexts.join('\n\n'),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return post.input.tool_result;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
return Object.freeze(adapter);
|
|
122
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
const PORTABLE_ENV_KEYS = Object.freeze([
|
|
4
|
+
'PATH', 'Path', 'PATHEXT', 'SYSTEMROOT', 'WINDIR',
|
|
5
|
+
'HOME', 'USERPROFILE', 'TMPDIR', 'TMP', 'TEMP', 'LANG', 'LC_ALL',
|
|
6
|
+
]);
|
|
7
|
+
|
|
8
|
+
function clean(value) {
|
|
9
|
+
return value == null ? '' : String(value).trim();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function portableEnvironment(extra = {}, inheritEnvironment = false) {
|
|
13
|
+
const environment = {};
|
|
14
|
+
const source = typeof process === 'undefined' ? {} : process.env;
|
|
15
|
+
if (inheritEnvironment) Object.assign(environment, source);
|
|
16
|
+
else for (const key of PORTABLE_ENV_KEYS) if (source[key] != null) environment[key] = source[key];
|
|
17
|
+
for (const [key, value] of Object.entries(extra || {})) {
|
|
18
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`invalid_hook_environment_key:${key}`);
|
|
19
|
+
if (value != null) environment[key] = String(value);
|
|
20
|
+
}
|
|
21
|
+
return environment;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function parseOutput(stdout, command) {
|
|
25
|
+
const text = stdout.trim();
|
|
26
|
+
if (!text) return null;
|
|
27
|
+
const lines = text.split(/\r?\n/).filter(Boolean);
|
|
28
|
+
try { return JSON.parse(lines.at(-1)); }
|
|
29
|
+
catch (error) {
|
|
30
|
+
const failure = new Error(`hook_command_invalid_json:${command}:${error.message}`);
|
|
31
|
+
failure.code = 'AGENTSAM_HOOK_INVALID_OUTPUT';
|
|
32
|
+
failure.adapter = 'command';
|
|
33
|
+
failure.protocol = 'agentsam.hook.v1';
|
|
34
|
+
failure.transport = 'process';
|
|
35
|
+
throw failure;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createCommandHookAdapter(options = {}) {
|
|
40
|
+
const command = clean(options.command);
|
|
41
|
+
if (!command) throw new TypeError('hook_command_required');
|
|
42
|
+
const args = Array.isArray(options.args) ? options.args.map(String) : [];
|
|
43
|
+
const timeoutMs = Number(options.timeout_ms ?? options.timeoutMs ?? 10_000);
|
|
44
|
+
const maxOutputBytes = Number(options.max_output_bytes ?? options.maxOutputBytes ?? 1_048_576);
|
|
45
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 600_000) throw new RangeError('invalid_hook_command_timeout');
|
|
46
|
+
if (!Number.isInteger(maxOutputBytes) || maxOutputBytes < 1 || maxOutputBytes > 16_777_216) throw new RangeError('invalid_hook_command_output_limit');
|
|
47
|
+
|
|
48
|
+
return (envelope) => new Promise((resolve, reject) => {
|
|
49
|
+
const child = spawn(command, args, {
|
|
50
|
+
cwd: options.cwd || envelope.cwd,
|
|
51
|
+
env: portableEnvironment(options.env, options.inherit_environment === true || options.inheritEnvironment === true),
|
|
52
|
+
shell: false,
|
|
53
|
+
windowsHide: true,
|
|
54
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
55
|
+
});
|
|
56
|
+
let stdout = '';
|
|
57
|
+
let stderr = '';
|
|
58
|
+
let outputBytes = 0;
|
|
59
|
+
let settled = false;
|
|
60
|
+
const finish = (callback, value) => {
|
|
61
|
+
if (settled) return;
|
|
62
|
+
settled = true;
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
callback(value);
|
|
65
|
+
};
|
|
66
|
+
const fail = (message, code = 'AGENTSAM_HOOK_COMMAND_FAILED') => {
|
|
67
|
+
const error = new Error(message);
|
|
68
|
+
error.code = code;
|
|
69
|
+
error.adapter = 'command';
|
|
70
|
+
error.protocol = 'agentsam.hook.v1';
|
|
71
|
+
error.transport = 'process';
|
|
72
|
+
finish(reject, error);
|
|
73
|
+
};
|
|
74
|
+
const append = (target, chunk) => {
|
|
75
|
+
outputBytes += chunk.length;
|
|
76
|
+
if (outputBytes > maxOutputBytes) {
|
|
77
|
+
child.kill('SIGKILL');
|
|
78
|
+
fail(`hook_command_output_limit_exceeded:${command}:${maxOutputBytes}`, 'AGENTSAM_HOOK_OUTPUT_LIMIT');
|
|
79
|
+
return target;
|
|
80
|
+
}
|
|
81
|
+
return target + chunk.toString('utf8');
|
|
82
|
+
};
|
|
83
|
+
child.stdout.on('data', (chunk) => { stdout = append(stdout, chunk); });
|
|
84
|
+
child.stderr.on('data', (chunk) => { stderr = append(stderr, chunk); });
|
|
85
|
+
child.on('error', (error) => fail(`hook_command_spawn_failed:${command}:${error.message}`));
|
|
86
|
+
child.on('close', (code, signal) => {
|
|
87
|
+
if (settled) return;
|
|
88
|
+
if (code !== 0) {
|
|
89
|
+
fail(`hook_command_failed:${command}:exit=${code ?? 'null'}:signal=${signal || 'none'}:${stderr.trim().slice(0, 512)}`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try { finish(resolve, parseOutput(stdout, command)); }
|
|
93
|
+
catch (error) { finish(reject, error); }
|
|
94
|
+
});
|
|
95
|
+
const timer = setTimeout(() => {
|
|
96
|
+
child.kill('SIGTERM');
|
|
97
|
+
const killTimer = setTimeout(() => child.kill('SIGKILL'), 250);
|
|
98
|
+
killTimer.unref?.();
|
|
99
|
+
fail(`hook_command_timeout:${command}:${timeoutMs}`, 'AGENTSAM_HOOK_TIMEOUT');
|
|
100
|
+
}, timeoutMs);
|
|
101
|
+
timer.unref?.();
|
|
102
|
+
child.stdin.end(`${JSON.stringify(envelope)}\n`);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function createCompositeCapabilityAdapter(adapters = []) {
|
|
2
|
+
const active = adapters.filter(Boolean);
|
|
3
|
+
if (!active.length || active.some((adapter) => !adapter?.toolDescriptors || !adapter?.invoke)) {
|
|
4
|
+
throw new TypeError('composite_capability_adapters_required');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function catalog(options = {}) {
|
|
8
|
+
const byName = new Map();
|
|
9
|
+
for (const adapter of active) {
|
|
10
|
+
for (const descriptor of adapter.toolDescriptors(options)) {
|
|
11
|
+
if (byName.has(descriptor.name)) throw new Error(`duplicate_capability_descriptor:${descriptor.name}`);
|
|
12
|
+
byName.set(descriptor.name, { descriptor, adapter });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return byName;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
toolDescriptors(options = {}) { return [...catalog(options).values()].map((row) => row.descriptor); },
|
|
20
|
+
canInvoke(id) {
|
|
21
|
+
return active.some((adapter) => typeof adapter.canInvoke === 'function'
|
|
22
|
+
? adapter.canInvoke(id)
|
|
23
|
+
: adapter.toolDescriptors().some((row) => row.name === id));
|
|
24
|
+
},
|
|
25
|
+
async invoke(id, input = {}, context = {}) {
|
|
26
|
+
const row = catalog().get(String(id));
|
|
27
|
+
if (!row) throw new Error(`capability_handler_unavailable:${id}`);
|
|
28
|
+
return row.adapter.invoke(id, input, context);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function clean(value) {
|
|
2
|
+
return value == null ? '' : String(value).trim();
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function safeUrl(value) {
|
|
6
|
+
const url = new URL(value);
|
|
7
|
+
if (!['http:', 'https:'].includes(url.protocol)) throw new Error(`unsupported_hook_http_protocol:${url.protocol}`);
|
|
8
|
+
if (url.username || url.password) throw new Error('hook_http_url_must_not_contain_credentials');
|
|
9
|
+
return url;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createHttpHookAdapter(options = {}) {
|
|
13
|
+
const url = safeUrl(clean(options.url));
|
|
14
|
+
const fetchImpl = options.fetchImpl || globalThis.fetch;
|
|
15
|
+
if (typeof fetchImpl !== 'function') throw new TypeError('hook_http_fetch_required');
|
|
16
|
+
const timeoutMs = Number(options.timeout_ms ?? options.timeoutMs ?? 10_000);
|
|
17
|
+
const maxResponseBytes = Number(options.max_response_bytes ?? options.maxResponseBytes ?? 1_048_576);
|
|
18
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 600_000) throw new RangeError('invalid_hook_http_timeout');
|
|
19
|
+
if (!Number.isInteger(maxResponseBytes) || maxResponseBytes < 1 || maxResponseBytes > 16_777_216) throw new RangeError('invalid_hook_http_response_limit');
|
|
20
|
+
const configuredHeaders = Object.fromEntries(Object.entries(options.headers || {}).map(([key, value]) => [key, String(value)]));
|
|
21
|
+
|
|
22
|
+
return async (envelope) => {
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const timer = setTimeout(() => controller.abort(new Error(`hook_http_timeout:${timeoutMs}`)), timeoutMs);
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetchImpl(url, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: { accept: 'application/json', 'content-type': 'application/json', ...configuredHeaders },
|
|
29
|
+
body: JSON.stringify(envelope),
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
});
|
|
32
|
+
const length = Number(response.headers?.get?.('content-length') || 0);
|
|
33
|
+
if (length > maxResponseBytes) throw new Error(`hook_http_response_limit_exceeded:${maxResponseBytes}`);
|
|
34
|
+
const text = await response.text();
|
|
35
|
+
if (new TextEncoder().encode(text).byteLength > maxResponseBytes) throw new Error(`hook_http_response_limit_exceeded:${maxResponseBytes}`);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const error = new Error(`hook_http_failed:${response.status}:${text.slice(0, 512)}`);
|
|
38
|
+
error.status = response.status;
|
|
39
|
+
error.code = 'AGENTSAM_HOOK_HTTP_FAILED';
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (!text.trim()) return null;
|
|
43
|
+
try { return JSON.parse(text); }
|
|
44
|
+
catch (error) {
|
|
45
|
+
const invalid = new Error(`hook_http_invalid_json:${error.message}`);
|
|
46
|
+
invalid.code = 'AGENTSAM_HOOK_INVALID_OUTPUT';
|
|
47
|
+
throw invalid;
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
error.adapter = 'http';
|
|
51
|
+
error.protocol = 'http';
|
|
52
|
+
error.transport = url.protocol.slice(0, -1);
|
|
53
|
+
throw error;
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const LSP_TOOLS = Object.freeze([
|
|
2
|
+
{
|
|
3
|
+
name: 'lsp.hover',
|
|
4
|
+
method: 'textDocument/hover',
|
|
5
|
+
description: 'Read type, symbol, and documentation information at a source position.',
|
|
6
|
+
required: ['document_uri', 'line', 'character'],
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'lsp.definition',
|
|
10
|
+
method: 'textDocument/definition',
|
|
11
|
+
description: 'Find the definition locations for a symbol at a source position.',
|
|
12
|
+
required: ['document_uri', 'line', 'character'],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'lsp.references',
|
|
16
|
+
method: 'textDocument/references',
|
|
17
|
+
description: 'Find source references for a symbol at a source position.',
|
|
18
|
+
required: ['document_uri', 'line', 'character'],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'lsp.symbols',
|
|
22
|
+
method: 'textDocument/documentSymbol',
|
|
23
|
+
description: 'List the structural symbols in a source document.',
|
|
24
|
+
required: ['document_uri'],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'lsp.diagnostics',
|
|
28
|
+
method: 'textDocument/diagnostic',
|
|
29
|
+
description: 'Request current diagnostics for a source document.',
|
|
30
|
+
required: ['document_uri'],
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
function descriptor(tool, languages) {
|
|
35
|
+
const properties = {
|
|
36
|
+
language: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'Configured language-server key.',
|
|
39
|
+
...(languages.length ? { enum: languages } : {}),
|
|
40
|
+
},
|
|
41
|
+
document_uri: { type: 'string', description: 'Absolute file URI for the source document.' },
|
|
42
|
+
line: { type: 'integer', minimum: 0 },
|
|
43
|
+
character: { type: 'integer', minimum: 0 },
|
|
44
|
+
include_declaration: { type: 'boolean' },
|
|
45
|
+
previous_result_id: { type: 'string' },
|
|
46
|
+
};
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
name: tool.name,
|
|
49
|
+
description: tool.description,
|
|
50
|
+
category: 'lsp',
|
|
51
|
+
risk: 'read',
|
|
52
|
+
strict: true,
|
|
53
|
+
protocol: 'lsp',
|
|
54
|
+
input_schema: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties,
|
|
57
|
+
required: ['language', ...tool.required],
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function paramsFor(tool, input) {
|
|
64
|
+
const textDocument = { uri: input.document_uri };
|
|
65
|
+
if (tool.method === 'textDocument/documentSymbol') return { textDocument };
|
|
66
|
+
if (tool.method === 'textDocument/diagnostic') return { textDocument, ...(input.previous_result_id ? { previousResultId: input.previous_result_id } : {}) };
|
|
67
|
+
const position = { line: input.line, character: input.character };
|
|
68
|
+
if (tool.method === 'textDocument/references') {
|
|
69
|
+
return { textDocument, position, context: { includeDeclaration: input.include_declaration !== false } };
|
|
70
|
+
}
|
|
71
|
+
return { textDocument, position };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function annotateLspFailure(value, server) {
|
|
75
|
+
const error = value && typeof value === 'object' ? value : new Error(String(value || 'LSP request failed'));
|
|
76
|
+
const message = String(error?.message || error || '').toLowerCase();
|
|
77
|
+
if (!error.reason) {
|
|
78
|
+
error.reason = /timeout|timed out|deadline/.test(message)
|
|
79
|
+
? 'lsp_timeout'
|
|
80
|
+
: /unavailable|not running|econnrefused|enoent/.test(message)
|
|
81
|
+
? 'lsp_server_unavailable'
|
|
82
|
+
: /connection|transport|socket|stdio/.test(message)
|
|
83
|
+
? 'lsp_transport_failed'
|
|
84
|
+
: 'lsp_request_failed';
|
|
85
|
+
}
|
|
86
|
+
error.adapter = error.adapter || 'lsp';
|
|
87
|
+
error.protocol = error.protocol || 'lsp';
|
|
88
|
+
error.transport = error.transport || server?.transport || (server?.command ? 'stdio' : null);
|
|
89
|
+
return error;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function createLspCapabilityAdapter(options = {}) {
|
|
93
|
+
if (typeof options.request !== 'function') throw new TypeError('lsp_request_adapter_required');
|
|
94
|
+
const languages = Object.keys(options.languages || {}).sort();
|
|
95
|
+
const byName = new Map(LSP_TOOLS.map((tool) => [tool.name, tool]));
|
|
96
|
+
return Object.freeze({
|
|
97
|
+
toolDescriptors() { return LSP_TOOLS.map((tool) => descriptor(tool, languages)); },
|
|
98
|
+
canInvoke(id) { return byName.has(String(id)); },
|
|
99
|
+
async invoke(id, input = {}, context = {}) {
|
|
100
|
+
const tool = byName.get(String(id));
|
|
101
|
+
if (!tool) throw new Error(`lsp_capability_unavailable:${id}`);
|
|
102
|
+
const language = String(input.language || '').trim();
|
|
103
|
+
if (!language) throw new TypeError('lsp_language_required');
|
|
104
|
+
if (languages.length && !Object.hasOwn(options.languages, language)) throw new Error(`lsp_language_not_configured:${language}`);
|
|
105
|
+
const server = options.languages?.[language] || null;
|
|
106
|
+
try {
|
|
107
|
+
return await options.request(language, tool.method, paramsFor(tool, input), {
|
|
108
|
+
...context,
|
|
109
|
+
server,
|
|
110
|
+
});
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw annotateLspFailure(error, server);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function cleanName(value, label) {
|
|
2
|
+
const normalized = String(value || '').trim();
|
|
3
|
+
if (!normalized || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(normalized)) throw new Error(`invalid_${label}:${normalized || '<missing>'}`);
|
|
4
|
+
return normalized;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function toolRows(value) {
|
|
8
|
+
return Array.isArray(value) ? value : Array.isArray(value?.tools) ? value.tools : [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function annotateMcpFailure(value, server) {
|
|
12
|
+
const error = value && typeof value === 'object' ? value : new Error(String(value || 'MCP call failed'));
|
|
13
|
+
const message = String(error?.message || error || '').toLowerCase();
|
|
14
|
+
if (!error.reason) {
|
|
15
|
+
error.reason = /timeout|timed out|deadline/.test(message)
|
|
16
|
+
? 'mcp_timeout'
|
|
17
|
+
: /unavailable|not running|econnrefused|enoent/.test(message)
|
|
18
|
+
? 'mcp_server_unavailable'
|
|
19
|
+
: /connection|transport|socket|stdio|http|sse/.test(message)
|
|
20
|
+
? 'mcp_transport_failed'
|
|
21
|
+
: 'mcp_call_failed';
|
|
22
|
+
}
|
|
23
|
+
error.adapter = error.adapter || 'mcp';
|
|
24
|
+
error.protocol = error.protocol || 'mcp';
|
|
25
|
+
error.transport = error.transport || server?.transport || null;
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function createMcpCapabilityAdapter(options = {}) {
|
|
30
|
+
const servers = options.servers || {};
|
|
31
|
+
const listTools = options.listTools;
|
|
32
|
+
const callTool = options.callTool;
|
|
33
|
+
if (typeof callTool !== 'function') throw new TypeError('mcp_call_tool_adapter_required');
|
|
34
|
+
const tools = new Map();
|
|
35
|
+
|
|
36
|
+
for (const [rawServerName, configValue] of Object.entries(servers)) {
|
|
37
|
+
const serverName = cleanName(rawServerName, 'mcp_server_name');
|
|
38
|
+
const config = configValue || {};
|
|
39
|
+
const discovered = config.tools || (typeof listTools === 'function' ? await listTools(serverName, config) : []);
|
|
40
|
+
for (const tool of toolRows(discovered)) {
|
|
41
|
+
const toolName = cleanName(tool.name, 'mcp_tool_name');
|
|
42
|
+
const capabilityId = `mcp.${serverName}.${toolName}`;
|
|
43
|
+
if (tools.has(capabilityId)) throw new Error(`duplicate_mcp_capability:${capabilityId}`);
|
|
44
|
+
tools.set(capabilityId, Object.freeze({
|
|
45
|
+
server_name: serverName,
|
|
46
|
+
tool_name: toolName,
|
|
47
|
+
server_config: config,
|
|
48
|
+
descriptor: Object.freeze({
|
|
49
|
+
name: capabilityId,
|
|
50
|
+
description: String(tool.description || `Call ${toolName} on MCP server ${serverName}`),
|
|
51
|
+
category: 'mcp',
|
|
52
|
+
risk: tool.annotations?.readOnlyHint === true ? 'read' : (tool.risk || 'write'),
|
|
53
|
+
input_schema: tool.inputSchema || tool.input_schema || { type: 'object', properties: {}, additionalProperties: true },
|
|
54
|
+
strict: false,
|
|
55
|
+
protocol: 'mcp',
|
|
56
|
+
remote_name: toolName,
|
|
57
|
+
server_name: serverName,
|
|
58
|
+
}),
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
toolDescriptors() { return [...tools.values()].map((row) => row.descriptor); },
|
|
65
|
+
canInvoke(id) { return tools.has(String(id)); },
|
|
66
|
+
async invoke(id, input = {}, context = {}) {
|
|
67
|
+
const row = tools.get(String(id));
|
|
68
|
+
if (!row) throw new Error(`mcp_capability_unavailable:${id}`);
|
|
69
|
+
try {
|
|
70
|
+
return await callTool(row.server_name, row.tool_name, input, { ...context, server: row.server_config });
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw annotateMcpFailure(error, row.server_config);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|