@inneranimalmedia/agentsam-sdk 2.6.1 → 2.6.3
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/AGENTSAM.md +45 -1
- package/README.md +80 -0
- package/apps/README.md +34 -0
- package/apps/cad-creator/README.md +728 -0
- package/apps/cad-creator/shared/cad/package.json +19 -0
- package/apps/cad-creator/shared/cad/src/domain/operations.ts +7 -0
- package/apps/cad-creator/shared/cad/src/domain/project-contract.d.ts +3 -0
- package/apps/cad-creator/shared/cad/src/domain/project-contract.js +75 -0
- package/apps/cad-creator/shared/cad/src/domain/project-tools.d.ts +1 -0
- package/apps/cad-creator/shared/cad/src/domain/project-tools.js +24 -0
- package/apps/cad-creator/shared/cad/src/domain/validation.ts +191 -0
- package/apps/cad-creator/shared/cad/src/index.ts +4 -0
- package/apps/cad-creator/shared/cad/src/robotics/types.ts +232 -0
- package/apps/cad-creator/shared/cad/src/types.ts +507 -0
- package/apps/cad-creator/shared/cad/tsconfig.json +14 -0
- package/docs/AUTH_IDENTITY_CONTRACT.md +25 -27
- package/docs/AUTORAG.md +58 -0
- package/docs/BRAND_INTELLIGENCE.md +30 -0
- package/docs/CLI_SHELL.md +4 -2
- package/docs/CMS_CONTEXTUAL_COMPOSER.md +38 -0
- package/docs/MERKLE.md +4 -0
- package/docs/PROJECT_CONFIG.md +3 -0
- package/docs/REPOSITORY_KNOWLEDGE.md +2 -0
- package/docs/SDK_WORKER.md +4 -3
- package/docs/THEME_REFINERY.md +120 -0
- package/docs/architecture/PROVIDER-TOOLS-AND-COMPACTION.md +60 -0
- package/docs/architecture/STORAGE.md +87 -0
- package/docs/cad-project-tools.md +69 -0
- package/docs/cms-scaffolding-pattern-reference.md +73 -0
- package/docs/plans/AGENTSAM-INTERACTIVE-UI-REQUIREMENTS-codex-tui-20260919.md +113 -0
- package/docs/plans/AGENTSAM-INTERACTIVE-UI-REQUIREMENTS.md +85 -0
- package/docs/plans/AGENTSAM-MCP-CLIENT-2026-09-19.md +181 -0
- package/docs/plans/ASBD-PORTABLE-WORKGRAPH-UI-DEFERRED.md +34 -0
- package/docs/plans/ASTRA-BRIEF-2026-09-18.md +258 -0
- package/docs/plans/MULTI-AGENT-SPRINTS-2026-09-19.md +373 -0
- package/docs/plans/NEXT-AGENT-HANDOFF.md +167 -0
- package/docs/plans/RECONCILIATION-2026-09-19.md +178 -0
- package/docs/plugins.md +43 -0
- package/docs/tools/README.md +57 -0
- package/docs/tools/agent-and-orchestration.md +49 -0
- package/docs/tools/browser-and-research.md +46 -0
- package/docs/tools/cloudflare-platform.md +32 -0
- package/docs/tools/cms.md +25 -0
- package/docs/tools/communications.md +41 -0
- package/docs/tools/database-and-storage.md +62 -0
- package/docs/tools/design-and-media.md +64 -0
- package/docs/tools/filesystem-and-code.md +55 -0
- package/docs/tools/github.md +56 -0
- package/docs/tools/integrations-and-misc.md +16 -0
- package/docs/tools/memory.md +21 -0
- package/docs/tools/terminal-and-execution.md +29 -0
- package/docs/tools/tickets-and-platform.md +30 -0
- package/migrations/d1/0001_agentsam_plugin_runtime.sql +177 -0
- package/migrations/d1/0002_agentsam_ticket_ownership.sql +8 -0
- package/migrations/d1/0002_dynamic_model_policies.sql +23 -0
- package/migrations/d1/0003_expand_tool_handler_families.sql +18 -0
- package/migrations/d1/0004_project_aware_retrieval_lanes.sql +24 -0
- package/migrations/d1/0005_portable_knowledge_identity.sql +104 -0
- package/migrations/d1/0006_repair_ops_trail_account_scope.sql +14 -0
- package/migrations/d1/0007_repair_ops_trail_agent_run_account.sql +13 -0
- package/migrations/d1/0008_backfill_knowledge_run_legacy_tenant.sql +14 -0
- package/migrations/d1/0009_normalize_cloudflare_plugin_installations.sql +137 -0
- package/migrations/runtime/0001_cli_runtime.sql +67 -0
- package/migrations/runtime/0002_project_sessions.sql +15 -0
- package/migrations/runtime/0003_provider_continuations.sql +8 -0
- package/package.json +92 -12
- package/packages/agentsam-brand/README.md +21 -0
- package/packages/agentsam-brand/package.json +22 -0
- package/packages/agentsam-brand/src/contract.js +59 -0
- package/packages/agentsam-brand/src/extract.js +126 -0
- package/packages/agentsam-brand/src/goap-actions.js +73 -0
- package/packages/agentsam-brand/src/index.js +48 -0
- package/packages/agentsam-brand/src/plan.js +115 -0
- package/packages/agentsam-brand/src/resolve.js +139 -0
- package/packages/agentsam-brand/src/scan.js +250 -0
- package/packages/agentsam-brand/test/brand-scan.test.mjs +106 -0
- package/packages/agentsam-contracts/README.md +23 -0
- package/packages/agentsam-contracts/package.json +32 -0
- package/packages/agentsam-contracts/src/adapter.ts +25 -0
- package/packages/agentsam-contracts/src/agent.ts +35 -0
- package/packages/agentsam-contracts/src/artifacts.ts +33 -0
- package/packages/agentsam-contracts/src/authority.ts +29 -0
- package/packages/agentsam-contracts/src/context.ts +16 -0
- package/packages/agentsam-contracts/src/errors.ts +46 -0
- package/packages/agentsam-contracts/src/events.ts +47 -0
- package/packages/agentsam-contracts/src/execution.ts +50 -0
- package/packages/agentsam-contracts/src/hooks.ts +40 -0
- package/packages/agentsam-contracts/src/identity.ts +16 -0
- package/packages/agentsam-contracts/src/index.ts +14 -0
- package/packages/agentsam-contracts/src/models.ts +9 -0
- package/packages/agentsam-contracts/src/providers.ts +33 -0
- package/packages/agentsam-contracts/src/repository.ts +64 -0
- package/packages/agentsam-contracts/src/tools.ts +98 -0
- package/packages/agentsam-contracts/test/contracts.test.mjs +16 -0
- package/packages/agentsam-contracts/test/errors-catalog.test.mjs +25 -0
- package/packages/agentsam-contracts/test/repository.test.mjs +18 -0
- package/packages/agentsam-contracts/tsconfig.json +12 -0
- package/packages/agentsam-errors/package.json +17 -0
- package/packages/agentsam-errors/src/adapters/anthropic.js +15 -0
- package/packages/agentsam-errors/src/adapters/cad.js +109 -0
- package/packages/agentsam-errors/src/adapters/cloudflare.js +21 -0
- package/packages/agentsam-errors/src/adapters/cursor.js +4 -0
- package/packages/agentsam-errors/src/adapters/device.js +38 -0
- package/packages/agentsam-errors/src/adapters/docker.js +28 -0
- package/packages/agentsam-errors/src/adapters/gcp.js +14 -0
- package/packages/agentsam-errors/src/adapters/github.js +22 -0
- package/packages/agentsam-errors/src/adapters/google.js +17 -0
- package/packages/agentsam-errors/src/adapters/index.js +55 -0
- package/packages/agentsam-errors/src/adapters/internal.js +40 -0
- package/packages/agentsam-errors/src/adapters/oauth.js +24 -0
- package/packages/agentsam-errors/src/adapters/openai.js +17 -0
- package/packages/agentsam-errors/src/adapters/process.js +35 -0
- package/packages/agentsam-errors/src/adapters/provider.js +114 -0
- package/packages/agentsam-errors/src/envelope.js +186 -0
- package/packages/agentsam-errors/src/error.js +24 -0
- package/packages/agentsam-errors/src/fingerprint.js +35 -0
- package/packages/agentsam-errors/src/index.js +10 -0
- package/packages/agentsam-errors/src/normalize.js +30 -0
- package/packages/agentsam-errors/src/redaction.js +52 -0
- package/packages/agentsam-errors/src/render.js +16 -0
- package/packages/agentsam-errors/src/retry.js +10 -0
- package/packages/agentsam-errors/src/transport.js +52 -0
- package/packages/agentsam-errors/src/vocabulary.js +320 -0
- package/packages/agentsam-errors/test/envelope.test.mjs +70 -0
- package/packages/agentsam-errors/test/providers.test.mjs +99 -0
- package/packages/agentsam-errors/test/redaction.test.mjs +21 -0
- package/packages/agentsam-errors/test/runtime-cad-device.test.mjs +76 -0
- package/packages/agentsam-errors/test/transport.test.mjs +46 -0
- package/packages/agentsam-knowledge/package.json +15 -0
- package/packages/agentsam-knowledge/src/autorag/index.js +64 -0
- package/packages/agentsam-knowledge/src/backends/index.js +26 -0
- package/packages/agentsam-knowledge/src/index.js +3 -0
- package/packages/agentsam-knowledge/src/providers/index.js +95 -0
- package/packages/agentsam-knowledge/test/autorag.test.mjs +42 -0
- package/packages/agentsam-nav/README.md +40 -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 +132 -0
- package/packages/agentsam-nav/dist/browser.js +613 -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 +614 -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 +43 -0
- package/packages/agentsam-queue-control/README.md +107 -0
- package/packages/agentsam-queue-control/package.json +31 -0
- package/packages/agentsam-queue-control/schemas/job-envelope.schema.json +56 -0
- package/packages/agentsam-queue-control/src/adapters/cloudflare.js +152 -0
- package/packages/agentsam-queue-control/src/adapters/memory.js +38 -0
- package/packages/agentsam-queue-control/src/contracts.js +130 -0
- package/packages/agentsam-queue-control/src/control-plane.js +141 -0
- package/packages/agentsam-queue-control/src/dispatch.js +43 -0
- package/packages/agentsam-queue-control/src/index.js +7 -0
- package/packages/agentsam-queue-control/src/policy.js +88 -0
- package/packages/agentsam-queue-control/src/topology.js +66 -0
- package/packages/agentsam-queue-control/test/queue-control.test.mjs +100 -0
- package/packages/agentsam-repository/src/goap.js +718 -0
- package/packages/agentsam-repository/src/goap.js.bak-20260922011251 +670 -0
- package/packages/agentsam-repository/src/index.js +5 -0
- package/packages/agentsam-repository/src/merkle/cloudflare-persistence.js +2 -2
- package/packages/agentsam-repository/src/tickets.js +184 -0
- package/packages/agentsam-repository/src/work-tracking.js +199 -0
- package/packages/agentsam-repository/src/workspace-state.js +176 -0
- package/packages/agentsam-repository/test/goap-tickets-workspace-state.test.mjs +152 -0
- package/packages/connectors/cloudflare/src/index.js +297 -15
- package/packages/connectors/cloudflare/src/owner.js +43 -40
- package/packages/connectors/cloudflare/src/routes.js +167 -26
- package/packages/connectors/cloudflare/tests/connector.test.mjs +112 -2
- package/packages/heuristic-theme/README.md +11 -0
- package/packages/heuristic-theme/package.json +25 -0
- package/packages/heuristic-theme/src/index.js +2 -0
- package/packages/heuristic-theme/src/registry.js +36 -0
- package/packages/heuristic-theme/src/theme.js +41 -0
- package/packages/heuristic-theme/test/theme.test.mjs +26 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/agentsam.feature.json +64 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/providers.json +96 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/resources.json +47 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/routes.json +74 -0
- package/packages/identity/.agentsam/features/oauth-login-portal/ui.json +35 -0
- package/packages/identity/package.json +4 -3
- package/packages/identity/src/adapters/cloudflare-d1/ids.js +4 -0
- package/packages/identity/src/adapters/cloudflare-d1/index.js +39 -1
- package/packages/identity/src/contracts/auth-config.js +23 -40
- package/packages/identity/src/contracts/provider.js +3 -2
- package/packages/identity/src/frontend/auth-portal/pages/login.html +7 -0
- package/packages/identity/src/index.js +2 -0
- package/packages/identity/src/oauth/credentials.js +13 -0
- package/packages/identity/src/oauth/iam-platform.js +5 -5
- package/packages/identity/src/providers/cloudflare/index.js +19 -0
- package/packages/identity/src/providers/cloudflare/mapper.js +21 -0
- package/packages/identity/src/providers/cloudflare/oauth.js +48 -0
- package/packages/identity/src/providers/cloudflare/profile.js +28 -0
- package/packages/identity/src/providers/index.js +18 -2
- package/packages/identity/src/server/identity-service.js +13 -3
- package/packages/identity/src/server/worker-router.js +63 -8
- package/packages/identity/tests/auth-config.test.mjs +14 -23
- package/packages/identity/tests/identity-service.test.mjs +15 -0
- package/packages/providers/completeful/README.md +38 -0
- package/packages/providers/completeful/package.json +29 -0
- package/packages/providers/completeful/src/client.js +162 -0
- package/packages/providers/completeful/src/events.js +49 -0
- package/packages/providers/completeful/src/index.js +22 -0
- package/packages/providers/completeful/src/tools.js +579 -0
- package/packages/providers/completeful/src/webhooks.js +55 -0
- package/packages/providers/completeful/test/provider.test.mjs +196 -0
- package/packages/theme-church-site/README.md +10 -0
- package/packages/theme-church-site/package.json +30 -0
- package/packages/theme-church-site/src/harvest.json +14 -0
- package/packages/theme-church-site/src/index.js +84 -0
- package/packages/theme-church-site/test/theme.test.mjs +19 -0
- package/packages/theme-companions-site/README.md +10 -0
- package/packages/theme-companions-site/package.json +30 -0
- package/packages/theme-companions-site/src/harvest.json +12 -0
- package/packages/theme-companions-site/src/index.js +82 -0
- package/packages/theme-companions-site/test/theme.test.mjs +19 -0
- package/packages/theme-floors-site/README.md +10 -0
- package/packages/theme-floors-site/package.json +30 -0
- package/packages/theme-floors-site/src/harvest.json +14 -0
- package/packages/theme-floors-site/src/index.js +82 -0
- package/packages/theme-floors-site/test/theme.test.mjs +19 -0
- package/packages/theme-fuelnfree-site/README.md +10 -0
- package/packages/theme-fuelnfree-site/package.json +30 -0
- package/packages/theme-fuelnfree-site/src/harvest.json +13 -0
- package/packages/theme-fuelnfree-site/src/index.js +81 -0
- package/packages/theme-fuelnfree-site/test/theme.test.mjs +19 -0
- package/packages/theme-handyman-site/README.md +10 -0
- package/packages/theme-handyman-site/package.json +30 -0
- package/packages/theme-handyman-site/src/harvest.json +10 -0
- package/packages/theme-handyman-site/src/index.js +83 -0
- package/packages/theme-handyman-site/test/theme.test.mjs +19 -0
- package/packages/theme-insurance-site/README.md +10 -0
- package/packages/theme-insurance-site/package.json +30 -0
- package/packages/theme-insurance-site/src/harvest.json +10 -0
- package/packages/theme-insurance-site/src/index.js +83 -0
- package/packages/theme-insurance-site/test/theme.test.mjs +19 -0
- package/packages/theme-shinshu-site/README.md +10 -0
- package/packages/theme-shinshu-site/package.json +30 -0
- package/packages/theme-shinshu-site/src/harvest.json +12 -0
- package/packages/theme-shinshu-site/src/index.js +83 -0
- package/packages/theme-shinshu-site/test/theme.test.mjs +19 -0
- package/packages/work-graph/README.md +49 -0
- package/packages/work-graph/package.json +19 -0
- package/packages/work-graph/prototype/README.md +32 -0
- package/packages/work-graph/prototype/data/demo-workgraph.js +47 -0
- package/packages/work-graph/prototype/renderers/timeline-model.js +21 -0
- package/packages/work-graph/prototype/renderers/workgraph-runtime.js +38 -0
- package/packages/work-graph/prototype-gnantt.html +655 -0
- package/packages/work-graph/src/adapters/business/projects.js +23 -0
- package/packages/work-graph/src/adapters/engineering/git.js +22 -0
- package/packages/work-graph/src/adapters/engineering/mcp.js +22 -0
- package/packages/work-graph/src/index.js +76 -0
- package/packages/work-graph/src/renderers/gantt-model.js +11 -0
- package/packages/work-graph/src/renderers/timeline.js +16 -0
- package/packages/work-graph/test/work-graph.test.mjs +37 -0
- package/protocol/README.md +12 -0
- package/protocol/capabilities/cloudflare-cpu-audit-input.schema.json +30 -6
- package/protocol/capabilities/cloudflare-cpu-profile-input.schema.json +18 -4
- package/protocol/capabilities/cloudflare-wrangler-native-input.schema.json +59 -10
- package/protocol/capabilities/knowledge-search-input.schema.json +35 -0
- package/protocol/capabilities/manifest.json +163 -1
- package/protocol/capabilities/repository-audit-input.schema.json +39 -6
- package/protocol/capabilities/repository-snapshot-input.schema.json +15 -3
- package/protocol/capabilities/terminal-exec-input.schema.json +55 -0
- package/protocol/commerce/catalog.v1.json +50 -0
- package/protocol/errors/error-catalog.json +164 -0
- package/protocol/errors/error-envelope.schema.json +544 -0
- package/protocol/features/README.md +57 -0
- package/protocol/features/agentsam.feature.v1.schema.json +290 -0
- package/protocol/features/catalog.json +65 -0
- package/protocol/features/examples/provider-resend.feature.json +17 -0
- package/protocol/go/agentsam-go-runtime.v1.json +17 -0
- package/protocol/knowledge/LIFECYCLE.md +140 -0
- package/protocol/knowledge/README.md +4 -0
- package/protocol/presets/catalog.json +128 -19
- package/protocol/rpc/v1/errors.proto +24 -0
- package/protocol/theme-refinery/d1-reconciliation.md +48 -0
- package/protocol/theme-refinery/product-metadata.schema.json +27 -0
- package/protocol/theme-refinery/receipts/products-registry-batch-20260924.json +318 -0
- package/protocol/theme-refinery/receipts/theme-harvest-20260924.json +472 -0
- package/protocol/theme-refinery/reconciliation-receipt.schema.json +83 -0
- package/services/cad/server.py +249 -2
- package/src/agent/capability-adapter.js +15 -5
- package/src/agent/index.js +2 -1
- package/src/agent/model-turn.js +51 -0
- package/src/agent/responses-runner.js +304 -38
- package/src/capabilities/index.js +1 -0
- package/src/capabilities/terminal-exec.js +78 -0
- package/src/cli.js +129 -31
- package/src/cloudflare/index.js +6 -0
- package/src/cloudflare/runtime-status.js +393 -0
- package/src/cloudflare/wrangler.js +17 -1
- package/src/commands/account-auth.js +1 -1
- package/src/commands/app.js +106 -0
- package/src/commands/autorag.js +77 -0
- package/src/commands/brand.js +293 -0
- package/src/commands/cad.js +1 -0
- package/src/commands/connections.js +126 -29
- package/src/commands/context-economics.js +8 -0
- package/src/commands/db.js +7 -0
- package/src/commands/deploy.js +2 -2
- package/src/commands/env.js +5 -4
- package/src/commands/eval.js +209 -14
- package/src/commands/go.js +365 -0
- package/src/commands/goap.js +176 -0
- package/src/commands/identity-init.js +27 -3
- package/src/commands/identity-protocol.js +195 -0
- package/src/commands/knowledge.js +64 -5
- package/src/commands/mcp.js +341 -0
- package/src/commands/merkle-persist.js +3 -1
- package/src/commands/merkle.js +18 -3
- package/src/commands/models.js +109 -23
- package/src/commands/plugins.js +175 -0
- package/src/commands/preferences.js +28 -8
- package/src/commands/product.js +53 -10
- package/src/commands/providers.js +389 -0
- package/src/commands/resume.js +9 -5
- package/src/commands/runtime-status.js +154 -0
- package/src/commands/shell.js +469 -54
- package/src/commands/status.js +82 -7
- package/src/commands/tunnel.js +228 -195
- package/src/commands/whoami.js +115 -22
- package/src/context/budget.js +6 -0
- package/src/context/index.js +2 -1
- package/src/context/project-card.js +75 -0
- package/src/errors/contract.js +34 -211
- package/src/errors/diagnostic.js +95 -50
- package/src/errors/index.js +6 -13
- package/src/eval/index.js +6 -0
- package/src/eval/live.js +439 -0
- package/src/features/resolve.js +242 -0
- package/src/go/build.js +108 -0
- package/src/go/cloudflare.js +207 -0
- package/src/go/contract.js +139 -0
- package/src/go/discover.js +96 -0
- package/src/go/index.js +13 -0
- package/src/go/receipts.js +77 -0
- package/src/go/registry.js +223 -0
- package/src/go/verify.js +31 -0
- package/src/index.js +100 -1
- package/src/knowledge/config.js +13 -5
- package/src/knowledge/engine.js +23 -8
- package/src/knowledge/index.js +1 -0
- package/src/knowledge/lane-registry.js +46 -0
- package/src/knowledge/providers/gemini.js +48 -8
- package/src/knowledge/service/client.js +13 -1
- package/src/knowledge/service/grpc-codec.js +156 -53
- package/src/knowledge/service/job-engine.js +133 -11
- package/src/knowledge/service/job-worker.js +34 -5
- package/src/knowledge/service/server.js +10 -1
- package/src/knowledge/store-discovery.js +77 -0
- package/src/lib/account-session.js +100 -25
- package/src/lib/agent-instructions.js +3 -0
- package/src/lib/auth.js +318 -51
- package/src/lib/cad/blender.js +42 -3
- package/src/lib/cad/d1-project-store.js +43 -0
- package/src/lib/cad/discovery.js +616 -0
- package/src/lib/cad/docker-executor.js +352 -0
- package/src/lib/cad/freecad.js +253 -0
- package/src/lib/cad/index.js +40 -0
- package/src/lib/cad/openscad.js +198 -0
- package/src/lib/cad/project-cli.d.ts +2 -0
- package/src/lib/cad/project-cli.js +21 -0
- package/src/lib/cad/project-contract.d.ts +3 -0
- package/src/lib/cad/project-contract.js +1 -0
- package/src/lib/cad/project-recipe.js +30 -0
- package/src/lib/cad/project-runtime.d.ts +2 -0
- package/src/lib/cad/project-runtime.js +53 -0
- package/src/lib/cad/project-store.js +25 -0
- package/src/lib/cad/project-workflows.js +31 -0
- package/src/lib/cad-docker.js +21 -2
- package/src/lib/cli-preferences.js +17 -2
- package/src/lib/core-client.js +97 -33
- package/src/lib/deploy/local-studio.js +6 -5
- package/src/lib/detect-context.js +14 -16
- package/src/lib/dockerize.js +3 -0
- package/src/lib/execution-approvals.js +1 -0
- package/src/lib/identity-scaffold.js +4 -1
- package/src/lib/knowledge-docker.js +9 -1
- package/src/lib/local-sessions.js +124 -34
- package/src/lib/local-status.js +35 -14
- package/src/lib/project-config.js +9 -0
- package/src/lib/provider-credentials.js +233 -55
- package/src/lib/scaffold/resolve-cloudflare-account.js +37 -0
- package/src/lib/scaffold/wizards/cms.js +2 -8
- package/src/lib/scaffold/wizards/worker-api.js +2 -8
- package/src/lib/slash-commands.js +10 -2
- package/src/local/migrations.js +109 -1
- package/src/local/runtime-store.js +31 -5
- package/src/local/sqlite.js +36 -1
- package/src/mcp/authority.js +348 -0
- package/src/mcp/client-adapters.js +431 -0
- package/src/mcp/client.js +172 -0
- package/src/mcp/index.js +47 -0
- package/src/mcp/telemetry.js +103 -0
- package/src/models/catalog.js +329 -51
- package/src/models/discovery.js +59 -4
- package/src/models/index.js +2 -0
- package/src/models/inventory-core.js +182 -0
- package/src/models/policy.js +20 -0
- package/src/plugins/cloudflare.js +103 -0
- package/src/plugins/completeful.js +69 -0
- package/src/plugins/contracts.js +86 -0
- package/src/plugins/index.js +11 -0
- package/src/plugins/registry.js +207 -0
- package/src/plugins/resource-scope.js +45 -0
- package/src/plugins/runtime.js +118 -0
- package/src/plugins/vectorize.js +31 -0
- package/src/progression/engine.js +171 -0
- package/src/progression/index.js +1 -0
- package/src/providers/cloudflare-chat.js +1 -1
- package/src/providers/gemini-generate-content.js +2 -1
- package/src/providers/openai-responses.js +45 -16
- package/src/providers/tool-schema.js +85 -0
- package/src/repository/index.js +29 -0
- package/src/rpc/generated/errors_pb.js +961 -1
- package/src/security/local-vault.js +415 -0
- package/src/security/process.js +20 -4
- package/src/status/actions.js +192 -0
- package/src/tools/hydrate.js +5 -1
- package/src/tools/index.js +7 -0
- package/src/tools/redact.js +64 -0
- package/src/tools/registry.js +83 -0
- package/src/tools/runtime.js +257 -0
- package/src/tools/search.js +21 -8
- package/src/ui/ansi.js +117 -3
- package/src/ui/cli/activity.js +76 -7
- package/src/ui/cli/footer.js +110 -9
- package/src/ui/cli/help.js +14 -5
- package/src/ui/wireframes.js +166 -0
- package/test/account-session.test.mjs +76 -11
- package/test/apps-scaffold-contract.test.mjs +58 -0
- package/test/capabilities.test.mjs +1 -1
- package/test/cli/eval-live.test.mjs +219 -0
- package/test/cli/go.test.mjs +71 -0
- package/test/cli/local-vault-and-provider-setup.test.mjs +268 -0
- package/test/cli/mcp-client.test.mjs +245 -0
- package/test/cli/runtime-ui.test.mjs +69 -2
- package/test/cli/status-actions.test.mjs +88 -0
- package/test/cli/wireframes-go-registry.test.mjs +54 -0
- package/test/cloudflare-connector.test.mjs +3 -6
- package/test/cloudflare-runtime.test.mjs +8 -1
- package/test/context.test.mjs +15 -0
- package/test/error-diagnostics.test.mjs +9 -0
- package/test/fixtures/cad/courtyard-house.json +208 -0
- package/test/go/cloudflare-probe.test.mjs +53 -0
- package/test/integration/app-command.test.mjs +55 -0
- package/test/integration/cad-discovery.test.mjs +158 -0
- package/test/integration/cad-docker-executor.test.mjs +249 -0
- package/test/integration/cad-execution.test.mjs +184 -0
- package/test/integration/cad-project-app.test.mjs +31 -0
- package/test/integration/cad-project-d1.test.mjs +25 -0
- package/test/integration/cad-project-native.test.mjs +24 -0
- package/test/integration/cad-project-workflow.test.mjs +9 -0
- package/test/integration/cad-project.test.mjs +82 -0
- package/test/integration/cli-help.test.mjs +4 -0
- package/test/integration/cms-site-tenancy-contract.test.mjs +256 -0
- package/test/integration/core-client.integration.test.mjs +55 -0
- package/test/integration/error-runtime-rpc.test.mjs +71 -0
- package/test/integration/features-resolve.test.mjs +128 -0
- package/test/integration/install-script.test.mjs +107 -0
- package/test/integration/inventory-core.test.mjs +53 -0
- package/test/integration/plugins-cloudflare.integration.test.mjs +28 -0
- package/test/integration/provider-env-cli.test.mjs +1 -1
- package/test/integration/runtime-migrations.test.mjs +6 -1
- package/test/integration/runtime-status.integration.test.mjs +211 -0
- package/test/integration/scaffold-cloudflare.test.mjs +46 -0
- package/test/integration/storage-architecture.test.mjs +154 -0
- package/test/integration/store-discovery.test.mjs +44 -0
- package/test/integration/terminal-exec.integration.test.mjs +86 -0
- package/test/integration/tool-runtime.test.mjs +124 -0
- package/test/integration/tool-schema.test.mjs +59 -0
- package/test/knowledge-service.test.mjs +4 -0
- package/test/local-sessions.test.mjs +11 -2
- package/test/local-studio-deploy.test.mjs +1 -1
- package/test/model-catalog.test.mjs +28 -1
- package/test/models.test.mjs +159 -5
- package/test/openai-responses.test.mjs +60 -0
- package/test/provider-credentials.test.mjs +15 -5
- package/test/responses-runner.test.mjs +321 -6
- package/test/sdk-worker-contract.test.mjs +5 -1
- package/test/shell.test.mjs +149 -4
- package/test/smoke.mjs +4 -3
- package/test/tools-search.test.mjs +33 -0
- package/test/unit/website-assets-bindings.test.mjs +60 -0
- package/test/whoami-resume.test.mjs +87 -7
- package/examples/gorilla-shell/README.md +0 -15
- package/src/lib/gorilla-template.js +0 -54
- package/src/lib/prompt-byok.js +0 -57
- package/src/lib/save-sdk-token.js +0 -19
- package/templates/gorilla-shell/App.tsx +0 -639
- package/templates/gorilla-shell/README.md +0 -34
- package/templates/gorilla-shell/index.html +0 -15
- package/templates/gorilla-shell/main.jsx +0 -9
- package/templates/gorilla-shell/package.json +0 -19
- package/templates/gorilla-shell/vite.config.js +0 -21
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { classifyProviderFailure } from './provider.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
export function classifyGcpFailure(evidence = {}, context = {}) {
|
|
5
|
+
const statusName = String(evidence.status_name || evidence.type || evidence.code || '').toUpperCase();
|
|
6
|
+
const text = `${evidence.message || ''} ${evidence.error || ''}`.toLowerCase();
|
|
7
|
+
let reason = context.reason;
|
|
8
|
+
if (!reason && (evidence.project_state === 'missing' || /project.*(?:missing|not set|not specified)/.test(text))) reason = ERROR_REASON.GCP_PROJECT_MISSING;
|
|
9
|
+
else if (!reason && /api.*(?:disabled|not enabled)|has not been used.*before/.test(text)) reason = ERROR_REASON.GCP_API_DISABLED;
|
|
10
|
+
else if (!reason && (statusName === 'RESOURCE_EXHAUSTED' || /quota/.test(text))) reason = ERROR_REASON.GCP_QUOTA_EXHAUSTED;
|
|
11
|
+
else if (!reason && (statusName === 'NOT_FOUND' || Number(evidence.status) === 404) && (context.resource?.type === 'vm' || /instance|vm/.test(text))) reason = ERROR_REASON.GCP_VM_NOT_FOUND;
|
|
12
|
+
else if (!reason && (statusName === 'UNAVAILABLE' || Number(evidence.status) === 503)) reason = ERROR_REASON.GCP_VM_UNAVAILABLE;
|
|
13
|
+
return classifyProviderFailure('gcp', evidence, { ...context, reason, domain: context.domain || 'runtime', tool: context.tool || 'gcp' });
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { classifyProviderFailure } from './provider.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
function header(headers, name) {
|
|
5
|
+
if (!headers) return '';
|
|
6
|
+
if (typeof headers.get === 'function') return String(headers.get(name) || '');
|
|
7
|
+
const wanted = name.toLowerCase();
|
|
8
|
+
for (const [key, value] of Object.entries(headers)) if (String(key).toLowerCase() === wanted) return String(value || '');
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function classifyGitHubFailure(evidence = {}, context = {}) {
|
|
13
|
+
const status = Number(evidence.status || 0);
|
|
14
|
+
const text = `${evidence.code || ''} ${evidence.message || ''}`.toLowerCase();
|
|
15
|
+
let reason = context.reason;
|
|
16
|
+
if (!reason && evidence.installation_state === 'missing') reason = ERROR_REASON.GITHUB_INSTALLATION_MISSING;
|
|
17
|
+
else if (!reason && status === 403 && (header(evidence.headers, 'x-ratelimit-remaining') === '0' || /rate limit exceeded/.test(text))) reason = ERROR_REASON.GITHUB_RATE_LIMITED;
|
|
18
|
+
else if (!reason && status === 403 && /secondary rate limit|abuse detection/.test(text)) reason = ERROR_REASON.GITHUB_SECONDARY_RATE_LIMITED;
|
|
19
|
+
else if (!reason && status === 403) reason = ERROR_REASON.GITHUB_SCOPE_INSUFFICIENT;
|
|
20
|
+
else if (!reason && status === 404 && (context.resource?.type === 'repository' || /repository/.test(text))) reason = ERROR_REASON.GITHUB_REPOSITORY_NOT_FOUND;
|
|
21
|
+
return classifyProviderFailure('github', evidence, { ...context, reason, domain: context.domain || 'repository' });
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { classifyProviderFailure } from './provider.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
export function classifyGoogleAIFailure(evidence = {}, context = {}) {
|
|
5
|
+
const statusName = String(evidence.status_name || evidence.type || evidence.code || '').toUpperCase();
|
|
6
|
+
const message = String(evidence.message || '');
|
|
7
|
+
let reason = context.reason;
|
|
8
|
+
if (!reason && /API key not valid|invalid API key/i.test(message)) reason = ERROR_REASON.PROVIDER_CREDENTIAL_INVALID;
|
|
9
|
+
else if (!reason && statusName === 'UNAUTHENTICATED') reason = ERROR_REASON.PROVIDER_CREDENTIAL_INVALID;
|
|
10
|
+
else if (!reason && statusName === 'PERMISSION_DENIED') reason = ERROR_REASON.PROVIDER_SCOPE_INSUFFICIENT;
|
|
11
|
+
else if (!reason && statusName === 'RESOURCE_EXHAUSTED') reason = /billing|budget/i.test(message) ? ERROR_REASON.PROVIDER_BUDGET_EXHAUSTED : ERROR_REASON.PROVIDER_QUOTA_EXHAUSTED;
|
|
12
|
+
else if (!reason && statusName === 'UNAVAILABLE') reason = ERROR_REASON.PROVIDER_UNAVAILABLE;
|
|
13
|
+
else if (!reason && statusName === 'INVALID_ARGUMENT') reason = ERROR_REASON.PROVIDER_REQUEST_INVALID;
|
|
14
|
+
return classifyProviderFailure(context.provider || 'google_ai', evidence, { ...context, reason });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const classifyGeminiFailure = (evidence = {}, context = {}) => classifyGoogleAIFailure(evidence, { ...context, provider: 'gemini' });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export { classifyProviderFailure, reasonFromGenericEvidence } from './provider.js';
|
|
2
|
+
export { classifyOpenAIFailure } from './openai.js';
|
|
3
|
+
export { classifyAnthropicFailure } from './anthropic.js';
|
|
4
|
+
export { classifyGoogleAIFailure, classifyGeminiFailure } from './google.js';
|
|
5
|
+
export { classifyCursorFailure } from './cursor.js';
|
|
6
|
+
export { classifyGitHubFailure } from './github.js';
|
|
7
|
+
export { classifyCloudflareFailure } from './cloudflare.js';
|
|
8
|
+
export { classifyDockerFailure } from './docker.js';
|
|
9
|
+
export { classifyGcpFailure } from './gcp.js';
|
|
10
|
+
export { classifyProcessFailure } from './process.js';
|
|
11
|
+
export { classifyOAuthFailure } from './oauth.js';
|
|
12
|
+
export { classifyCadFailure, classifyFreeCadFailure, classifyOpenScadFailure, classifyBlenderFailure, classifyMeshyFailure } from './cad.js';
|
|
13
|
+
export { classifyDeviceFailure } from './device.js';
|
|
14
|
+
export { classifyInternalFailure } from './internal.js';
|
|
15
|
+
|
|
16
|
+
import { classifyOpenAIFailure } from './openai.js';
|
|
17
|
+
import { classifyAnthropicFailure } from './anthropic.js';
|
|
18
|
+
import { classifyGoogleAIFailure, classifyGeminiFailure } from './google.js';
|
|
19
|
+
import { classifyCursorFailure } from './cursor.js';
|
|
20
|
+
import { classifyGitHubFailure } from './github.js';
|
|
21
|
+
import { classifyCloudflareFailure } from './cloudflare.js';
|
|
22
|
+
import { classifyDockerFailure } from './docker.js';
|
|
23
|
+
import { classifyGcpFailure } from './gcp.js';
|
|
24
|
+
import { classifyCadFailure } from './cad.js';
|
|
25
|
+
import { classifyDeviceFailure } from './device.js';
|
|
26
|
+
import { classifyInternalFailure } from './internal.js';
|
|
27
|
+
import { classifyProviderFailure } from './provider.js';
|
|
28
|
+
|
|
29
|
+
export function classifyFailure(source, evidence = {}, context = {}) {
|
|
30
|
+
const key = String(source || '').toLowerCase();
|
|
31
|
+
switch (key) {
|
|
32
|
+
case 'openai': return classifyOpenAIFailure(evidence, context);
|
|
33
|
+
case 'anthropic': return classifyAnthropicFailure(evidence, context);
|
|
34
|
+
case 'google':
|
|
35
|
+
case 'google_ai': return classifyGoogleAIFailure(evidence, context);
|
|
36
|
+
case 'gemini': return classifyGeminiFailure(evidence, context);
|
|
37
|
+
case 'cursor': return classifyCursorFailure(evidence, context);
|
|
38
|
+
case 'github': return classifyGitHubFailure(evidence, context);
|
|
39
|
+
case 'cloudflare': return classifyCloudflareFailure(evidence, context);
|
|
40
|
+
case 'docker': return classifyDockerFailure(evidence, context);
|
|
41
|
+
case 'gcp':
|
|
42
|
+
case 'google_cloud': return classifyGcpFailure(evidence, context);
|
|
43
|
+
case 'freecad':
|
|
44
|
+
case 'openscad':
|
|
45
|
+
case 'blender':
|
|
46
|
+
case 'meshy': return classifyCadFailure(key, evidence, context);
|
|
47
|
+
case 'device':
|
|
48
|
+
case 'execos_device': return classifyDeviceFailure(evidence, context);
|
|
49
|
+
case 'agentsam':
|
|
50
|
+
case 'agentsam-sdk':
|
|
51
|
+
case 'inneranimalmedia':
|
|
52
|
+
case 'execos': return classifyInternalFailure(evidence, { ...context, system: key });
|
|
53
|
+
default: return classifyProviderFailure(key || 'provider', evidence, context);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createErrorEnvelope } from '../envelope.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
const INTERNAL_REASONS = new Set([
|
|
5
|
+
ERROR_REASON.INTERNAL,
|
|
6
|
+
ERROR_REASON.INTERNAL_INVARIANT_VIOLATION,
|
|
7
|
+
ERROR_REASON.INTERNAL_CONFIGURATION_INVALID,
|
|
8
|
+
ERROR_REASON.INTERNAL_CONTRACT_VIOLATION,
|
|
9
|
+
ERROR_REASON.INTERNAL_ADAPTER_FAILED,
|
|
10
|
+
ERROR_REASON.INTERNAL_DEPENDENCY_FAILED,
|
|
11
|
+
ERROR_REASON.IDENTITY_RESOLUTION_FAILED,
|
|
12
|
+
ERROR_REASON.IDENTITY_MISMATCH,
|
|
13
|
+
ERROR_REASON.PERSISTENCE_FAILED,
|
|
14
|
+
ERROR_REASON.DATA_CORRUPT,
|
|
15
|
+
ERROR_REASON.DATA_LOSS,
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export function classifyInternalFailure(evidence = {}, context = {}) {
|
|
19
|
+
const reason = context.reason && INTERNAL_REASONS.has(context.reason) ? context.reason : ERROR_REASON.INTERNAL;
|
|
20
|
+
return createErrorEnvelope({
|
|
21
|
+
reason,
|
|
22
|
+
message: context.message || evidence.message || 'AgentSam encountered an internal failure.',
|
|
23
|
+
source: context.source || { kind: 'agentsam', name: context.system || 'agentsam-sdk', service: context.service || null },
|
|
24
|
+
resolution_owner: 'agentsam',
|
|
25
|
+
severity: 'blocking_internal',
|
|
26
|
+
retryable: false,
|
|
27
|
+
remediation: { action: 'inspect_platform', message: context.remediation_message || 'AgentSam must inspect this platform failure.' },
|
|
28
|
+
domain: context.domain || 'runtime',
|
|
29
|
+
tool: context.tool || null,
|
|
30
|
+
stage: context.stage || 'execute',
|
|
31
|
+
resource: context.resource || null,
|
|
32
|
+
provider: context.provider || null,
|
|
33
|
+
provider_code: evidence.provider_code || evidence.code || null,
|
|
34
|
+
request_id: evidence.request_id || null,
|
|
35
|
+
trace_id: evidence.trace_id || context.trace_id || null,
|
|
36
|
+
native: { code: evidence.code, exception_type: evidence.exception_type || evidence.name, exit_code: evidence.exit_code, signal: evidence.signal, stderr: evidence.stderr, stdout: evidence.stdout, stack: evidence.stack },
|
|
37
|
+
environment: context.environment || null,
|
|
38
|
+
details: evidence.details || null,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createErrorEnvelope } from '../envelope.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
export function classifyOAuthFailure(error, context = {}) {
|
|
5
|
+
const code = String(error?.code || error || '').toLowerCase();
|
|
6
|
+
let reason = context.reason;
|
|
7
|
+
if (!reason && ['invalid_client','invalid_grant'].includes(code)) reason = ERROR_REASON.PROVIDER_CREDENTIAL_INVALID;
|
|
8
|
+
else if (!reason && ['unauthorized_client','access_denied'].includes(code)) reason = ERROR_REASON.USER_PERMISSION_DENIED;
|
|
9
|
+
else if (!reason && ['invalid_scope'].includes(code)) reason = ERROR_REASON.PROVIDER_SCOPE_INSUFFICIENT;
|
|
10
|
+
else if (!reason && ['invalid_request','unsupported_grant_type'].includes(code)) reason = ERROR_REASON.INPUT_INVALID;
|
|
11
|
+
else reason ||= ERROR_REASON.UNKNOWN;
|
|
12
|
+
return createErrorEnvelope({
|
|
13
|
+
reason,
|
|
14
|
+
message: context.message || error?.message || `OAuth failure: ${code || 'unknown'}`,
|
|
15
|
+
source: context.source || { kind: context.provider ? 'provider' : 'runtime', name: context.provider || 'oauth' },
|
|
16
|
+
domain: 'auth',
|
|
17
|
+
tool: context.provider || 'oauth',
|
|
18
|
+
stage: context.stage || 'oauth',
|
|
19
|
+
provider: context.provider || null,
|
|
20
|
+
provider_code: code || null,
|
|
21
|
+
native: { code },
|
|
22
|
+
details: error?.details || null,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { classifyProviderFailure } from './provider.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
const BUDGET_CODES = new Set(['credit_balance_exhausted','organization_spend_limit_exceeded','project_spend_limit_exceeded','organization_usage_limit_exceeded']);
|
|
5
|
+
|
|
6
|
+
export function classifyOpenAIFailure(evidence = {}, context = {}) {
|
|
7
|
+
const code = String(evidence.code || evidence.provider_code || '').toLowerCase();
|
|
8
|
+
const message = String(evidence.message || '');
|
|
9
|
+
let reason = context.reason;
|
|
10
|
+
if (!reason && BUDGET_CODES.has(code)) reason = ERROR_REASON.PROVIDER_BUDGET_EXHAUSTED;
|
|
11
|
+
else if (!reason && (code === 'insufficient_quota' || /quota/i.test(message))) reason = ERROR_REASON.PROVIDER_QUOTA_EXHAUSTED;
|
|
12
|
+
else if (!reason && code === 'previous_response_not_found') reason = ERROR_REASON.CONTINUATION_INVALID;
|
|
13
|
+
else if (!reason && code === 'websocket_connection_limit_reached') reason = ERROR_REASON.PROVIDER_CAPACITY_EXHAUSTED;
|
|
14
|
+
else if (!reason && (code === 'server_is_overloaded' || /overload/i.test(message))) reason = ERROR_REASON.PROVIDER_OVERLOADED;
|
|
15
|
+
else if (!reason && /service[_ -]?tier/i.test(message)) reason = ERROR_REASON.SERVICE_TIER_UNSUPPORTED;
|
|
16
|
+
return classifyProviderFailure('openai', evidence, { ...context, reason });
|
|
17
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createErrorEnvelope } from '../envelope.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
export function classifyProcessFailure(evidence = {}, context = {}) {
|
|
5
|
+
const code = String(evidence.code || '').toUpperCase();
|
|
6
|
+
let reason = context.reason;
|
|
7
|
+
if (!reason && (evidence.cancelled || code === 'ABORT_ERR' || code === 'PROCESS_CANCELLED')) reason = ERROR_REASON.CANCELLED;
|
|
8
|
+
else if (!reason && (evidence.timeout || code === 'ETIMEDOUT' || code === 'PROCESS_TIMEOUT')) reason = ERROR_REASON.EXECUTION_TIMEOUT;
|
|
9
|
+
else if (!reason && (evidence.output_limit || code === 'PROCESS_OUTPUT_LIMIT')) reason = ERROR_REASON.PROCESS_OUTPUT_LIMIT;
|
|
10
|
+
else if (!reason && (code === 'ENOENT' || code === 'EACCES' || evidence.spawn_failed)) reason = ERROR_REASON.PROCESS_SPAWN_FAILED;
|
|
11
|
+
else if (!reason && Number.isInteger(evidence.exit_code) && evidence.exit_code !== 0) reason = ERROR_REASON.PROCESS_CRASHED;
|
|
12
|
+
else reason ||= ERROR_REASON.EXECUTION_FAILED;
|
|
13
|
+
let severity = context.severity;
|
|
14
|
+
let remediation = context.remediation;
|
|
15
|
+
if (context.retryable === false && !severity && reason === ERROR_REASON.EXECUTION_TIMEOUT) {
|
|
16
|
+
severity = 'blocking_user_fixable';
|
|
17
|
+
remediation = remediation || { action: 'change_configuration', message: 'Increase process timeout or inspect execution.' };
|
|
18
|
+
}
|
|
19
|
+
return createErrorEnvelope({
|
|
20
|
+
reason,
|
|
21
|
+
message: context.message || evidence.message || 'Process failed',
|
|
22
|
+
source: context.source || { kind: 'runtime', name: context.tool || 'process' },
|
|
23
|
+
resolution_owner: context.resolution_owner,
|
|
24
|
+
severity,
|
|
25
|
+
remediation,
|
|
26
|
+
domain: context.domain || 'runtime',
|
|
27
|
+
tool: context.tool || null,
|
|
28
|
+
stage: context.stage || 'execute',
|
|
29
|
+
retryable: context.retryable,
|
|
30
|
+
resource: context.resource || null,
|
|
31
|
+
environment: context.environment || null,
|
|
32
|
+
native: { code: evidence.code, exception_type: evidence.exception_type, exit_code: evidence.exit_code, signal: evidence.signal, stderr: evidence.stderr, stdout: evidence.stdout, stack: evidence.stack },
|
|
33
|
+
details: evidence.details || null,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createErrorEnvelope } from '../envelope.js';
|
|
2
|
+
import { ERROR_REASON } from '../vocabulary.js';
|
|
3
|
+
|
|
4
|
+
function clean(value) { return value == null ? '' : String(value).trim(); }
|
|
5
|
+
function lower(...values) { return values.map(clean).join(' ').toLowerCase(); }
|
|
6
|
+
function header(headers, name) {
|
|
7
|
+
if (!headers) return '';
|
|
8
|
+
if (typeof headers.get === 'function') return clean(headers.get(name));
|
|
9
|
+
const wanted = name.toLowerCase();
|
|
10
|
+
for (const [key, value] of Object.entries(headers)) if (String(key).toLowerCase() === wanted) return clean(value);
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
function retryAfterMs(headers, explicit) {
|
|
14
|
+
if (Number.isFinite(explicit) && explicit >= 0) return Math.round(explicit);
|
|
15
|
+
const value = header(headers, 'retry-after');
|
|
16
|
+
if (!value) return null;
|
|
17
|
+
if (/^\d+(?:\.\d+)?$/.test(value)) return Math.max(0, Math.round(Number(value) * 1000));
|
|
18
|
+
const when = Date.parse(value);
|
|
19
|
+
return Number.isFinite(when) ? Math.max(0, when - Date.now()) : null;
|
|
20
|
+
}
|
|
21
|
+
function requestId(headers, explicit) {
|
|
22
|
+
return clean(explicit) || header(headers, 'x-request-id') || header(headers, 'request-id') || header(headers, 'cf-ray') || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function reasonFromGenericEvidence(evidence = {}) {
|
|
26
|
+
const status = Number(evidence.status || evidence.http_status || 0);
|
|
27
|
+
const code = clean(evidence.code || evidence.provider_code).toLowerCase();
|
|
28
|
+
const type = clean(evidence.type).toLowerCase();
|
|
29
|
+
const text = lower(code, type, evidence.message, evidence.error);
|
|
30
|
+
if (evidence.connected === false) return ERROR_REASON.PROVIDER_NOT_CONNECTED;
|
|
31
|
+
if (evidence.credential_state === 'missing') return ERROR_REASON.PROVIDER_CREDENTIAL_MISSING;
|
|
32
|
+
if (evidence.credential_state === 'expired') return ERROR_REASON.PROVIDER_CREDENTIAL_EXPIRED;
|
|
33
|
+
if (evidence.credential_state === 'invalid') return ERROR_REASON.PROVIDER_CREDENTIAL_INVALID;
|
|
34
|
+
if (/credit|billing|spend[_ -]?limit|budget|payment required/.test(text)) return ERROR_REASON.PROVIDER_BUDGET_EXHAUSTED;
|
|
35
|
+
if (/quota|resource[_ -]?exhausted|usage[_ -]?limit/.test(text)) return ERROR_REASON.PROVIDER_QUOTA_EXHAUSTED;
|
|
36
|
+
if (/context.{0,20}(too long|limit|window|length)|max(?:imum)?[_ -]?tokens|request too large/.test(text)) return ERROR_REASON.CONTEXT_WINDOW_EXCEEDED;
|
|
37
|
+
if (/service[_ -]?tier/.test(text) && /(unsupported|invalid|not available)/.test(text)) return ERROR_REASON.SERVICE_TIER_UNSUPPORTED;
|
|
38
|
+
if (/region|country|location/.test(text) && /(unsupported|not available|restricted)/.test(text)) return ERROR_REASON.PROVIDER_REGION_UNSUPPORTED;
|
|
39
|
+
if (/content[_ -]?(filter|policy|blocked)|safety|moderation/.test(text)) return ERROR_REASON.PROVIDER_CONTENT_BLOCKED;
|
|
40
|
+
if (/model/.test(text) && /(not found|unknown|does not exist|unsupported)/.test(text)) return ERROR_REASON.PROVIDER_MODEL_NOT_FOUND;
|
|
41
|
+
if (status === 401 || /invalid[_ -]?(api[_ -]?)?key|authentication_error|unauthenticated/.test(text)) return ERROR_REASON.PROVIDER_CREDENTIAL_INVALID;
|
|
42
|
+
if (status === 403 || /permission|forbidden|scope/.test(text)) return ERROR_REASON.PROVIDER_SCOPE_INSUFFICIENT;
|
|
43
|
+
if (status === 429 || /rate[_ -]?limit|too many requests|slow[_ -]?down/.test(text)) return ERROR_REASON.PROVIDER_RATE_LIMITED;
|
|
44
|
+
if (status === 529 || /overload|overloaded|capacity/.test(text)) return ERROR_REASON.PROVIDER_OVERLOADED;
|
|
45
|
+
if (status >= 500) return ERROR_REASON.PROVIDER_UNAVAILABLE;
|
|
46
|
+
if (status === 404) return ERROR_REASON.TARGET_NOT_FOUND;
|
|
47
|
+
if (status === 400 || status === 409 || status === 422) return ERROR_REASON.PROVIDER_REQUEST_INVALID;
|
|
48
|
+
return ERROR_REASON.UNKNOWN;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function classifyProviderFailure(provider, evidence = {}, context = {}) {
|
|
52
|
+
const name = clean(provider || context.provider || 'provider').toLowerCase();
|
|
53
|
+
const reason = context.reason || reasonFromGenericEvidence(evidence);
|
|
54
|
+
const providerCode = clean(evidence.code || evidence.provider_code || evidence.type) || null;
|
|
55
|
+
const requestOrigin = clean(context.request_origin || evidence.request_origin).toLowerCase();
|
|
56
|
+
const configuredOwner = clean(context.credential_owner || context.account_owner || context.configuration_owner).toLowerCase();
|
|
57
|
+
const internalRequestFailure = reason === ERROR_REASON.PROVIDER_REQUEST_INVALID && requestOrigin === 'agentsam';
|
|
58
|
+
const ownerSensitiveFailure = [
|
|
59
|
+
ERROR_REASON.PROVIDER_NOT_CONNECTED,
|
|
60
|
+
ERROR_REASON.PROVIDER_CREDENTIAL_MISSING,
|
|
61
|
+
ERROR_REASON.PROVIDER_CREDENTIAL_INVALID,
|
|
62
|
+
ERROR_REASON.PROVIDER_CREDENTIAL_EXPIRED,
|
|
63
|
+
ERROR_REASON.PROVIDER_SCOPE_INSUFFICIENT,
|
|
64
|
+
ERROR_REASON.PROVIDER_BUDGET_EXHAUSTED,
|
|
65
|
+
ERROR_REASON.PROVIDER_QUOTA_EXHAUSTED,
|
|
66
|
+
].includes(reason);
|
|
67
|
+
const platformOwnedFailure = ownerSensitiveFailure && ['agentsam','inneranimalmedia','platform'].includes(configuredOwner);
|
|
68
|
+
const organizationOwnedFailure = ownerSensitiveFailure && ['organization','organization_admin','org'].includes(configuredOwner);
|
|
69
|
+
const localConfigurationFailure = [ERROR_REASON.PROVIDER_NOT_CONNECTED, ERROR_REASON.PROVIDER_CREDENTIAL_MISSING].includes(reason);
|
|
70
|
+
const resolutionOwner = internalRequestFailure || platformOwnedFailure
|
|
71
|
+
? 'agentsam'
|
|
72
|
+
: organizationOwnedFailure
|
|
73
|
+
? 'organization_admin'
|
|
74
|
+
: context.resolution_owner;
|
|
75
|
+
const severity = internalRequestFailure || platformOwnedFailure ? 'blocking_internal' : context.severity;
|
|
76
|
+
const remediation = internalRequestFailure || platformOwnedFailure
|
|
77
|
+
? { action: 'inspect_platform', message: 'AgentSam must inspect its provider integration or platform-owned credential.' }
|
|
78
|
+
: organizationOwnedFailure
|
|
79
|
+
? { action: 'contact_organization_admin', message: 'An organization administrator must update this provider connection or account.' }
|
|
80
|
+
: context.remediation;
|
|
81
|
+
const source = context.source || (localConfigurationFailure
|
|
82
|
+
? platformOwnedFailure
|
|
83
|
+
? { kind: 'agentsam', name: 'inneranimalmedia', service: name }
|
|
84
|
+
: { kind: 'user', name: organizationOwnedFailure ? 'organization_configuration' : 'project_configuration', service: name }
|
|
85
|
+
: { kind: 'provider', name, service: clean(context.service || evidence.service) || null });
|
|
86
|
+
return createErrorEnvelope({
|
|
87
|
+
reason,
|
|
88
|
+
message: context.message || evidence.message || evidence.error || `${name} request failed`,
|
|
89
|
+
source,
|
|
90
|
+
resolution_owner: resolutionOwner,
|
|
91
|
+
severity,
|
|
92
|
+
remediation,
|
|
93
|
+
domain: context.domain || 'provider',
|
|
94
|
+
tool: context.tool || name,
|
|
95
|
+
stage: context.stage || 'request',
|
|
96
|
+
retryable: context.retryable,
|
|
97
|
+
retry_after_ms: retryAfterMs(evidence.headers, evidence.retry_after_ms),
|
|
98
|
+
http_status: Number(evidence.status || evidence.http_status || 0) || undefined,
|
|
99
|
+
provider: name,
|
|
100
|
+
provider_code: providerCode,
|
|
101
|
+
request_id: requestId(evidence.headers, evidence.request_id),
|
|
102
|
+
trace_id: evidence.trace_id || context.trace_id || null,
|
|
103
|
+
resource: context.resource || null,
|
|
104
|
+
environment: context.environment || null,
|
|
105
|
+
native: {
|
|
106
|
+
code: providerCode,
|
|
107
|
+
exception_type: evidence.type || evidence.exception_type || null,
|
|
108
|
+
stack: evidence.stack || null,
|
|
109
|
+
},
|
|
110
|
+
details: evidence.details ?? evidence.body ?? null,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { reasonFromGenericEvidence };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_HTTP_STATUS,
|
|
3
|
+
ERROR_CODE,
|
|
4
|
+
ERROR_DOMAIN,
|
|
5
|
+
ERROR_REASON_POLICY,
|
|
6
|
+
ERROR_RESOLUTION_OWNER,
|
|
7
|
+
ERROR_SCHEMA_VERSION,
|
|
8
|
+
ERROR_SEVERITY,
|
|
9
|
+
ERROR_SOURCE_KIND,
|
|
10
|
+
GRPC_STATUS,
|
|
11
|
+
REMEDIATION_ACTION,
|
|
12
|
+
} from './vocabulary.js';
|
|
13
|
+
import { fingerprintError } from './fingerprint.js';
|
|
14
|
+
import { redactErrorValue, redactString, sanitizeNativeEvidence } from './redaction.js';
|
|
15
|
+
|
|
16
|
+
const REASON_PATTERN = /^[a-z][a-z0-9_]{0,127}$/;
|
|
17
|
+
const VALUES = object => new Set(Object.values(object));
|
|
18
|
+
const CODE_VALUES = VALUES(ERROR_CODE);
|
|
19
|
+
const SEVERITY_VALUES = VALUES(ERROR_SEVERITY);
|
|
20
|
+
const SOURCE_VALUES = VALUES(ERROR_SOURCE_KIND);
|
|
21
|
+
const OWNER_VALUES = VALUES(ERROR_RESOLUTION_OWNER);
|
|
22
|
+
const DOMAIN_VALUES = VALUES(ERROR_DOMAIN);
|
|
23
|
+
const ACTION_VALUES = VALUES(REMEDIATION_ACTION);
|
|
24
|
+
const GRPC_CODE_BY_NUMBER = new Map(Object.entries(GRPC_STATUS).map(([name, value]) => [value, ERROR_CODE[name]]));
|
|
25
|
+
const HTTP_OVERRIDES = new Map([
|
|
26
|
+
[400, ERROR_CODE.INVALID_ARGUMENT], [401, ERROR_CODE.UNAUTHENTICATED], [403, ERROR_CODE.PERMISSION_DENIED],
|
|
27
|
+
[404, ERROR_CODE.NOT_FOUND], [408, ERROR_CODE.DEADLINE_EXCEEDED], [409, ERROR_CODE.ABORTED],
|
|
28
|
+
[412, ERROR_CODE.FAILED_PRECONDITION], [413, ERROR_CODE.RESOURCE_EXHAUSTED], [415, ERROR_CODE.INVALID_ARGUMENT],
|
|
29
|
+
[422, ERROR_CODE.INVALID_ARGUMENT], [429, ERROR_CODE.RESOURCE_EXHAUSTED], [499, ERROR_CODE.CANCELLED],
|
|
30
|
+
[500, ERROR_CODE.INTERNAL], [501, ERROR_CODE.UNIMPLEMENTED], [502, ERROR_CODE.UNAVAILABLE],
|
|
31
|
+
[503, ERROR_CODE.UNAVAILABLE], [504, ERROR_CODE.DEADLINE_EXCEEDED], [520, ERROR_CODE.UNAVAILABLE],
|
|
32
|
+
[521, ERROR_CODE.UNAVAILABLE], [522, ERROR_CODE.UNAVAILABLE], [523, ERROR_CODE.UNAVAILABLE],
|
|
33
|
+
[524, ERROR_CODE.DEADLINE_EXCEEDED], [525, ERROR_CODE.UNAVAILABLE], [526, ERROR_CODE.UNAVAILABLE],
|
|
34
|
+
[530, ERROR_CODE.UNAVAILABLE],
|
|
35
|
+
]);
|
|
36
|
+
const USER_ACTIONS = new Set([
|
|
37
|
+
REMEDIATION_ACTION.REAUTHENTICATE,
|
|
38
|
+
REMEDIATION_ACTION.CONNECT_PROVIDER,
|
|
39
|
+
REMEDIATION_ACTION.CONFIGURE_PROVIDER_CREDENTIAL,
|
|
40
|
+
REMEDIATION_ACTION.REFRESH_PROVIDER_CREDENTIAL,
|
|
41
|
+
REMEDIATION_ACTION.REQUEST_PERMISSION,
|
|
42
|
+
REMEDIATION_ACTION.REENROLL_DEVICE,
|
|
43
|
+
REMEDIATION_ACTION.INSTALL_DEPENDENCY,
|
|
44
|
+
REMEDIATION_ACTION.UPGRADE_DEPENDENCY,
|
|
45
|
+
REMEDIATION_ACTION.CONFIGURE_DEPENDENCY,
|
|
46
|
+
REMEDIATION_ACTION.CHANGE_CONFIGURATION,
|
|
47
|
+
REMEDIATION_ACTION.CHANGE_INPUT,
|
|
48
|
+
REMEDIATION_ACTION.REDUCE_SCOPE,
|
|
49
|
+
REMEDIATION_ACTION.INCREASE_QUOTA,
|
|
50
|
+
REMEDIATION_ACTION.ADD_BUDGET,
|
|
51
|
+
REMEDIATION_ACTION.SELECT_MODEL,
|
|
52
|
+
REMEDIATION_ACTION.CHANGE_REGION,
|
|
53
|
+
REMEDIATION_ACTION.RESTART_RUNTIME,
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
function clean(value) { return value == null ? '' : String(value).trim(); }
|
|
57
|
+
function optional(value, max = 512) { const text = clean(value); return text ? redactString(text, max) : null; }
|
|
58
|
+
function deepFreeze(value) {
|
|
59
|
+
if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
|
|
60
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
61
|
+
return Object.freeze(value);
|
|
62
|
+
}
|
|
63
|
+
function normalizeSource(source, fallbackName = 'agentsam-sdk') {
|
|
64
|
+
const input = source && typeof source === 'object' ? source : {};
|
|
65
|
+
const kind = clean(input.kind || ERROR_SOURCE_KIND.AGENTSAM);
|
|
66
|
+
if (!SOURCE_VALUES.has(kind)) throw new TypeError(`Unknown AgentSam error source kind: ${kind}`);
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
kind,
|
|
69
|
+
name: optional(input.name || fallbackName, 256) || fallbackName,
|
|
70
|
+
service: optional(input.service, 256),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function normalizeRemediation(remediation, policy) {
|
|
74
|
+
const input = remediation && typeof remediation === 'object' ? remediation : {};
|
|
75
|
+
const action = clean(input.action || policy.remediation_action || REMEDIATION_ACTION.NONE);
|
|
76
|
+
if (!ACTION_VALUES.has(action)) throw new TypeError(`Unknown AgentSam remediation action: ${action}`);
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
action,
|
|
79
|
+
message: optional(input.message, 2_000),
|
|
80
|
+
automatic: input.automatic === true,
|
|
81
|
+
command: optional(input.command, 1_000),
|
|
82
|
+
url: optional(input.url, 2_000),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function normalizeResource(resource) {
|
|
86
|
+
if (!resource || typeof resource !== 'object') return null;
|
|
87
|
+
const type = optional(resource.type, 128);
|
|
88
|
+
if (!type) return null;
|
|
89
|
+
return Object.freeze({ type, id: optional(resource.id, 512), name: optional(resource.name, 512) });
|
|
90
|
+
}
|
|
91
|
+
function normalizeEnvironment(environment) {
|
|
92
|
+
if (!environment || typeof environment !== 'object') return null;
|
|
93
|
+
return Object.freeze({
|
|
94
|
+
detected_version: optional(environment.detected_version, 512),
|
|
95
|
+
required_version: optional(environment.required_version, 512),
|
|
96
|
+
component: optional(environment.component, 512),
|
|
97
|
+
runtime: optional(environment.runtime, 512),
|
|
98
|
+
platform: optional(environment.platform, 512),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function canonicalCodeFromHttpStatus(status) {
|
|
103
|
+
const value = Number(status || 0);
|
|
104
|
+
return HTTP_OVERRIDES.get(value) || (value >= 500 ? ERROR_CODE.INTERNAL : ERROR_CODE.UNKNOWN);
|
|
105
|
+
}
|
|
106
|
+
export function canonicalCodeFromGrpcStatus(status) { return GRPC_CODE_BY_NUMBER.get(Number(status)) || ERROR_CODE.UNKNOWN; }
|
|
107
|
+
export function defaultHttpStatusForCode(code) { return DEFAULT_HTTP_STATUS[code] ?? 500; }
|
|
108
|
+
export function grpcStatusForCode(code) { return GRPC_STATUS[code] ?? GRPC_STATUS.UNKNOWN; }
|
|
109
|
+
|
|
110
|
+
export function createErrorEnvelope(input = {}) {
|
|
111
|
+
const reason = clean(input.reason || 'unknown');
|
|
112
|
+
if (!REASON_PATTERN.test(reason)) throw new TypeError(`Invalid AgentSam error reason: ${reason}`);
|
|
113
|
+
const policy = ERROR_REASON_POLICY[reason] || ERROR_REASON_POLICY.unknown;
|
|
114
|
+
const code = clean(input.code || policy.code);
|
|
115
|
+
if (!CODE_VALUES.has(code) || code === ERROR_CODE.OK) throw new TypeError(`Unknown AgentSam error code: ${code}`);
|
|
116
|
+
if (ERROR_REASON_POLICY[reason] && code !== policy.code) {
|
|
117
|
+
throw new TypeError(`AgentSam error reason ${reason} requires canonical code ${policy.code}, received ${code}`);
|
|
118
|
+
}
|
|
119
|
+
const severity = clean(input.severity || policy.severity);
|
|
120
|
+
if (!SEVERITY_VALUES.has(severity)) throw new TypeError(`Unknown AgentSam error severity: ${severity}`);
|
|
121
|
+
const retryable = input.retryable == null ? Boolean(policy.retryable) : Boolean(input.retryable);
|
|
122
|
+
const resolutionOwner = clean(input.resolution_owner || policy.resolution_owner);
|
|
123
|
+
if (!OWNER_VALUES.has(resolutionOwner)) throw new TypeError(`Unknown AgentSam error resolution owner: ${resolutionOwner}`);
|
|
124
|
+
const domain = clean(input.domain || ERROR_DOMAIN.RUNTIME);
|
|
125
|
+
if (!DOMAIN_VALUES.has(domain)) throw new TypeError(`Unknown AgentSam error domain: ${domain}`);
|
|
126
|
+
const remediation = normalizeRemediation(input.remediation, policy);
|
|
127
|
+
if (severity === ERROR_SEVERITY.TRANSIENT && !retryable) throw new TypeError('transient AgentSam errors must be retryable');
|
|
128
|
+
if ((remediation.action === REMEDIATION_ACTION.RETRY || remediation.action === REMEDIATION_ACTION.RETRY_LATER) && !retryable) {
|
|
129
|
+
throw new TypeError(`${remediation.action} remediation requires retryable=true`);
|
|
130
|
+
}
|
|
131
|
+
if (severity === ERROR_SEVERITY.BLOCKING_INTERNAL && USER_ACTIONS.has(remediation.action)) {
|
|
132
|
+
throw new TypeError(`blocking_internal errors cannot prescribe user remediation action ${remediation.action}`);
|
|
133
|
+
}
|
|
134
|
+
const source = normalizeSource(input.source);
|
|
135
|
+
const native = sanitizeNativeEvidence(input.native);
|
|
136
|
+
const environment = normalizeEnvironment(input.environment);
|
|
137
|
+
const envelope = {
|
|
138
|
+
ok: false,
|
|
139
|
+
schema_version: ERROR_SCHEMA_VERSION,
|
|
140
|
+
code,
|
|
141
|
+
reason,
|
|
142
|
+
severity,
|
|
143
|
+
source,
|
|
144
|
+
resolution_owner: resolutionOwner,
|
|
145
|
+
domain,
|
|
146
|
+
tool: optional(input.tool, 256),
|
|
147
|
+
stage: optional(input.stage, 256),
|
|
148
|
+
message: redactString(input.message || 'Operation failed', 4_000),
|
|
149
|
+
retryable,
|
|
150
|
+
retry_after_ms: input.retry_after_ms == null ? null : Math.max(0, Math.round(Number(input.retry_after_ms) || 0)),
|
|
151
|
+
remediation,
|
|
152
|
+
resource: normalizeResource(input.resource),
|
|
153
|
+
native,
|
|
154
|
+
environment,
|
|
155
|
+
http_status: input.http_status == null ? defaultHttpStatusForCode(code) : Number(input.http_status),
|
|
156
|
+
grpc_status: input.grpc_status == null ? grpcStatusForCode(code) : Number(input.grpc_status),
|
|
157
|
+
transport: optional(input.transport, 256),
|
|
158
|
+
provider: optional(input.provider, 256),
|
|
159
|
+
provider_code: optional(input.provider_code, 512),
|
|
160
|
+
request_id: optional(input.request_id, 512),
|
|
161
|
+
trace_id: optional(input.trace_id, 512),
|
|
162
|
+
fingerprint: '',
|
|
163
|
+
occurrence_count: Number.isInteger(input.occurrence_count) && input.occurrence_count > 0 ? input.occurrence_count : 1,
|
|
164
|
+
details: input.details == null ? null : redactErrorValue(input.details),
|
|
165
|
+
};
|
|
166
|
+
if (!Number.isInteger(envelope.http_status) || envelope.http_status < 100 || envelope.http_status > 599) envelope.http_status = null;
|
|
167
|
+
if (!Number.isInteger(envelope.grpc_status) || envelope.grpc_status < 0 || envelope.grpc_status > 16) envelope.grpc_status = null;
|
|
168
|
+
envelope.fingerprint = optional(input.fingerprint, 128) || fingerprintError(envelope);
|
|
169
|
+
return deepFreeze(envelope);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function isErrorEnvelope(value) {
|
|
173
|
+
return Boolean(value && typeof value === 'object' && value.ok === false && value.schema_version === ERROR_SCHEMA_VERSION && CODE_VALUES.has(value.code) && typeof value.reason === 'string');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function assertErrorEnvelope(value) {
|
|
177
|
+
if (!isErrorEnvelope(value)) throw new TypeError('Expected an AgentSam ErrorEnvelope');
|
|
178
|
+
return createErrorEnvelope(value);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function serializeError(value) { return JSON.stringify(assertErrorEnvelope(value)); }
|
|
182
|
+
export function parseError(value) {
|
|
183
|
+
const parsed = typeof value === 'string' ? JSON.parse(value) : value;
|
|
184
|
+
if (parsed?.schema_version !== ERROR_SCHEMA_VERSION) throw new TypeError(`Unsupported AgentSam error schema version: ${parsed?.schema_version ?? 'missing'}`);
|
|
185
|
+
return createErrorEnvelope(parsed);
|
|
186
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createErrorEnvelope, isErrorEnvelope } from './envelope.js';
|
|
2
|
+
|
|
3
|
+
export class AgentSamError extends Error {
|
|
4
|
+
constructor(envelope, options = {}) {
|
|
5
|
+
const normalized = isErrorEnvelope(envelope) ? envelope : createErrorEnvelope(envelope);
|
|
6
|
+
super(normalized.message, options.cause ? { cause: options.cause } : undefined);
|
|
7
|
+
this.name = 'AgentSamError';
|
|
8
|
+
this.envelope = normalized;
|
|
9
|
+
// Compatibility alias for pre-v1 callers. It points at the canonical
|
|
10
|
+
// envelope; it is not a second diagnostic vocabulary.
|
|
11
|
+
this.diagnostic = normalized;
|
|
12
|
+
this.code = normalized.code;
|
|
13
|
+
this.reason = normalized.reason;
|
|
14
|
+
this.severity = normalized.severity;
|
|
15
|
+
this.retryable = normalized.retryable;
|
|
16
|
+
this.status = normalized.http_status;
|
|
17
|
+
this.fingerprint = normalized.fingerprint;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function asAgentSamError(value, options = {}) {
|
|
22
|
+
if (value instanceof AgentSamError) return value;
|
|
23
|
+
return new AgentSamError(value, options);
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function clean(value) { return value == null ? '' : String(value).trim(); }
|
|
2
|
+
|
|
3
|
+
function stableFields(value = {}) {
|
|
4
|
+
return [
|
|
5
|
+
value.code,
|
|
6
|
+
value.reason,
|
|
7
|
+
value.severity,
|
|
8
|
+
value.source?.kind,
|
|
9
|
+
value.source?.name,
|
|
10
|
+
value.source?.service,
|
|
11
|
+
value.resolution_owner,
|
|
12
|
+
value.domain,
|
|
13
|
+
value.tool,
|
|
14
|
+
value.stage,
|
|
15
|
+
value.provider,
|
|
16
|
+
value.provider_code,
|
|
17
|
+
value.native?.code,
|
|
18
|
+
value.native?.exception_type,
|
|
19
|
+
value.environment?.component,
|
|
20
|
+
value.environment?.runtime,
|
|
21
|
+
].map(clean).join('\u001f');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// FNV-1a 64-bit: deterministic, dependency-free, Worker/Node safe. This is an
|
|
25
|
+
// operational grouping key, not a cryptographic integrity primitive.
|
|
26
|
+
export function fingerprintError(value = {}) {
|
|
27
|
+
const text = stableFields(value);
|
|
28
|
+
let hash = 0xcbf29ce484222325n;
|
|
29
|
+
const prime = 0x100000001b3n;
|
|
30
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
31
|
+
hash ^= BigInt(text.charCodeAt(i));
|
|
32
|
+
hash = BigInt.asUintN(64, hash * prime);
|
|
33
|
+
}
|
|
34
|
+
return `err_${hash.toString(16).padStart(16, '0')}`;
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './vocabulary.js';
|
|
2
|
+
export * from './envelope.js';
|
|
3
|
+
export * from './error.js';
|
|
4
|
+
export * from './normalize.js';
|
|
5
|
+
export * from './redaction.js';
|
|
6
|
+
export * from './fingerprint.js';
|
|
7
|
+
export * from './retry.js';
|
|
8
|
+
export * from './transport.js';
|
|
9
|
+
export * from './render.js';
|
|
10
|
+
export * from './adapters/index.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AgentSamError } from './error.js';
|
|
2
|
+
import { canonicalCodeFromHttpStatus, createErrorEnvelope, isErrorEnvelope } from './envelope.js';
|
|
3
|
+
import { ERROR_REASON } from './vocabulary.js';
|
|
4
|
+
|
|
5
|
+
function clean(value) { return value == null ? '' : String(value).trim(); }
|
|
6
|
+
|
|
7
|
+
export function normalizeError(error, context = {}) {
|
|
8
|
+
if (isErrorEnvelope(error)) return error;
|
|
9
|
+
if (error instanceof AgentSamError) return error.envelope;
|
|
10
|
+
if (isErrorEnvelope(error?.envelope)) return error.envelope;
|
|
11
|
+
if (isErrorEnvelope(error?.error)) return error.error;
|
|
12
|
+
const status = Number(error?.status || error?.http_status || context.http_status || 0) || null;
|
|
13
|
+
const canonical = clean(context.code) || (status ? canonicalCodeFromHttpStatus(status) : undefined);
|
|
14
|
+
return createErrorEnvelope({
|
|
15
|
+
...context,
|
|
16
|
+
code: canonical,
|
|
17
|
+
reason: context.reason || ERROR_REASON.INTERNAL,
|
|
18
|
+
message: context.message || error?.message || String(error || 'Unknown error'),
|
|
19
|
+
http_status: status,
|
|
20
|
+
native: context.native || {
|
|
21
|
+
code: error?.code || null,
|
|
22
|
+
exception_type: error?.name || null,
|
|
23
|
+
stack: error?.stack || null,
|
|
24
|
+
},
|
|
25
|
+
source: context.source || { kind: 'agentsam', name: 'agentsam-sdk' },
|
|
26
|
+
resolution_owner: context.resolution_owner || 'agentsam',
|
|
27
|
+
severity: context.severity || 'blocking_internal',
|
|
28
|
+
remediation: context.remediation || { action: 'inspect_platform' },
|
|
29
|
+
});
|
|
30
|
+
}
|