@bradygaster/squad-sdk 0.7.0 → 0.8.2-1.4
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 +3 -3
- package/dist/adapter/client.d.ts +246 -0
- package/dist/adapter/client.d.ts.map +1 -0
- package/dist/adapter/client.js +699 -0
- package/dist/adapter/client.js.map +1 -0
- package/dist/adapter/errors.d.ts +260 -0
- package/dist/adapter/errors.d.ts.map +1 -0
- package/dist/adapter/errors.js +362 -0
- package/dist/adapter/errors.js.map +1 -0
- package/dist/adapter/types.d.ts +817 -0
- package/dist/adapter/types.d.ts.map +1 -0
- package/dist/adapter/types.js +11 -0
- package/dist/adapter/types.js.map +1 -0
- package/dist/agents/charter-compiler.d.ts +106 -0
- package/dist/agents/charter-compiler.d.ts.map +1 -0
- package/dist/agents/charter-compiler.js +165 -0
- package/dist/agents/charter-compiler.js.map +1 -0
- package/dist/agents/history-shadow.d.ts +80 -0
- package/dist/agents/history-shadow.d.ts.map +1 -0
- package/dist/agents/history-shadow.js +239 -0
- package/dist/agents/history-shadow.js.map +1 -0
- package/dist/agents/index.d.ts +71 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +183 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/lifecycle.d.ts +138 -0
- package/dist/agents/lifecycle.d.ts.map +1 -0
- package/dist/agents/lifecycle.js +284 -0
- package/dist/agents/lifecycle.js.map +1 -0
- package/dist/agents/model-selector.d.ts +80 -0
- package/dist/agents/model-selector.d.ts.map +1 -0
- package/dist/agents/model-selector.js +171 -0
- package/dist/agents/model-selector.js.map +1 -0
- package/dist/agents/onboarding.d.ts +65 -0
- package/dist/agents/onboarding.d.ts.map +1 -0
- package/dist/agents/onboarding.js +373 -0
- package/dist/agents/onboarding.js.map +1 -0
- package/dist/build/bundle.d.ts +32 -0
- package/dist/build/bundle.d.ts.map +1 -0
- package/dist/build/bundle.js +97 -0
- package/dist/build/bundle.js.map +1 -0
- package/dist/build/ci-pipeline.d.ts +51 -0
- package/dist/build/ci-pipeline.d.ts.map +1 -0
- package/dist/build/ci-pipeline.js +180 -0
- package/dist/build/ci-pipeline.js.map +1 -0
- package/dist/build/github-dist.d.ts +37 -0
- package/dist/build/github-dist.d.ts.map +1 -0
- package/dist/build/github-dist.js +117 -0
- package/dist/build/github-dist.js.map +1 -0
- package/dist/build/index.d.ts +11 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +11 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/install-migration.d.ts +28 -0
- package/dist/build/install-migration.d.ts.map +1 -0
- package/dist/build/install-migration.js +103 -0
- package/dist/build/install-migration.js.map +1 -0
- package/dist/build/npm-package.d.ts +54 -0
- package/dist/build/npm-package.d.ts.map +1 -0
- package/dist/build/npm-package.js +128 -0
- package/dist/build/npm-package.js.map +1 -0
- package/dist/build/release.d.ts +108 -0
- package/dist/build/release.d.ts.map +1 -0
- package/dist/build/release.js +295 -0
- package/dist/build/release.js.map +1 -0
- package/dist/build/versioning.d.ts +38 -0
- package/dist/build/versioning.d.ts.map +1 -0
- package/dist/build/versioning.js +113 -0
- package/dist/build/versioning.js.map +1 -0
- package/dist/builders/index.d.ts +156 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +404 -0
- package/dist/builders/index.js.map +1 -0
- package/dist/builders/types.d.ts +187 -0
- package/dist/builders/types.d.ts.map +1 -0
- package/dist/builders/types.js +12 -0
- package/dist/builders/types.js.map +1 -0
- package/dist/casting/casting-engine.d.ts +60 -0
- package/dist/casting/casting-engine.d.ts.map +1 -0
- package/dist/casting/casting-engine.js +223 -0
- package/dist/casting/casting-engine.js.map +1 -0
- package/dist/casting/casting-history.d.ts +54 -0
- package/dist/casting/casting-history.d.ts.map +1 -0
- package/dist/casting/casting-history.js +63 -0
- package/dist/casting/casting-history.js.map +1 -0
- package/dist/casting/index.d.ts +46 -0
- package/dist/casting/index.d.ts.map +1 -0
- package/dist/casting/index.js +45 -0
- package/dist/casting/index.js.map +1 -0
- package/dist/client/event-bus.d.ts +29 -0
- package/dist/client/event-bus.d.ts.map +1 -0
- package/dist/client/event-bus.js +52 -0
- package/dist/client/event-bus.js.map +1 -0
- package/dist/client/index.d.ts +103 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +182 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/session-pool.d.ts +66 -0
- package/dist/client/session-pool.d.ts.map +1 -0
- package/dist/client/session-pool.js +145 -0
- package/dist/client/session-pool.js.map +1 -0
- package/dist/config/agent-doc.d.ts +43 -0
- package/dist/config/agent-doc.d.ts.map +1 -0
- package/dist/config/agent-doc.js +158 -0
- package/dist/config/agent-doc.js.map +1 -0
- package/dist/config/agent-source.d.ts +95 -0
- package/dist/config/agent-source.d.ts.map +1 -0
- package/dist/config/agent-source.js +274 -0
- package/dist/config/agent-source.js.map +1 -0
- package/dist/config/doc-sync.d.ts +66 -0
- package/dist/config/doc-sync.d.ts.map +1 -0
- package/dist/config/doc-sync.js +270 -0
- package/dist/config/doc-sync.js.map +1 -0
- package/dist/config/feature-audit.d.ts +49 -0
- package/dist/config/feature-audit.d.ts.map +1 -0
- package/dist/config/feature-audit.js +148 -0
- package/dist/config/feature-audit.js.map +1 -0
- package/dist/config/index.d.ts +15 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +15 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/init.d.ts +86 -0
- package/dist/config/init.d.ts.map +1 -0
- package/dist/config/init.js +807 -0
- package/dist/config/init.js.map +1 -0
- package/dist/config/legacy-fallback.d.ts +83 -0
- package/dist/config/legacy-fallback.d.ts.map +1 -0
- package/dist/config/legacy-fallback.js +212 -0
- package/dist/config/legacy-fallback.js.map +1 -0
- package/dist/config/markdown-migration.d.ts +157 -0
- package/dist/config/markdown-migration.d.ts.map +1 -0
- package/dist/config/markdown-migration.js +434 -0
- package/dist/config/markdown-migration.js.map +1 -0
- package/dist/config/migration.d.ts +123 -0
- package/dist/config/migration.d.ts.map +1 -0
- package/dist/config/migration.js +273 -0
- package/dist/config/migration.js.map +1 -0
- package/dist/config/migrations/index.d.ts +36 -0
- package/dist/config/migrations/index.d.ts.map +1 -0
- package/dist/config/migrations/index.js +216 -0
- package/dist/config/migrations/index.js.map +1 -0
- package/dist/config/models.d.ts +134 -0
- package/dist/config/models.d.ts.map +1 -0
- package/dist/config/models.js +354 -0
- package/dist/config/models.js.map +1 -0
- package/dist/config/routing.d.ts +118 -0
- package/dist/config/routing.d.ts.map +1 -0
- package/dist/config/routing.js +247 -0
- package/dist/config/routing.js.map +1 -0
- package/dist/config/schema.d.ts +72 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +63 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/coordinator/coordinator.d.ts +82 -0
- package/dist/coordinator/coordinator.d.ts.map +1 -0
- package/dist/coordinator/coordinator.js +192 -0
- package/dist/coordinator/coordinator.js.map +1 -0
- package/dist/coordinator/direct-response.d.ts +83 -0
- package/dist/coordinator/direct-response.d.ts.map +1 -0
- package/dist/coordinator/direct-response.js +187 -0
- package/dist/coordinator/direct-response.js.map +1 -0
- package/dist/coordinator/fan-out.d.ts +83 -0
- package/dist/coordinator/fan-out.d.ts.map +1 -0
- package/dist/coordinator/fan-out.js +161 -0
- package/dist/coordinator/fan-out.js.map +1 -0
- package/dist/coordinator/index.d.ts +62 -0
- package/dist/coordinator/index.d.ts.map +1 -0
- package/dist/coordinator/index.js +177 -0
- package/dist/coordinator/index.js.map +1 -0
- package/dist/coordinator/response-tiers.d.ts +49 -0
- package/dist/coordinator/response-tiers.d.ts.map +1 -0
- package/dist/coordinator/response-tiers.js +149 -0
- package/dist/coordinator/response-tiers.js.map +1 -0
- package/dist/hooks/index.d.ts +103 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +279 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/dist/marketplace/backend.d.ts +35 -0
- package/dist/marketplace/backend.d.ts.map +1 -0
- package/dist/marketplace/backend.js +99 -0
- package/dist/marketplace/backend.js.map +1 -0
- package/dist/marketplace/browser.d.ts +33 -0
- package/dist/marketplace/browser.d.ts.map +1 -0
- package/dist/marketplace/browser.js +97 -0
- package/dist/marketplace/browser.js.map +1 -0
- package/dist/marketplace/extension-adapter.d.ts +51 -0
- package/dist/marketplace/extension-adapter.d.ts.map +1 -0
- package/dist/marketplace/extension-adapter.js +81 -0
- package/dist/marketplace/extension-adapter.js.map +1 -0
- package/dist/marketplace/index.d.ts +51 -0
- package/dist/marketplace/index.d.ts.map +1 -0
- package/dist/marketplace/index.js +108 -0
- package/dist/marketplace/index.js.map +1 -0
- package/dist/marketplace/packaging.d.ts +25 -0
- package/dist/marketplace/packaging.d.ts.map +1 -0
- package/dist/marketplace/packaging.js +117 -0
- package/dist/marketplace/packaging.js.map +1 -0
- package/dist/marketplace/schema.d.ts +50 -0
- package/dist/marketplace/schema.d.ts.map +1 -0
- package/dist/marketplace/schema.js +120 -0
- package/dist/marketplace/schema.js.map +1 -0
- package/dist/marketplace/security.d.ts +26 -0
- package/dist/marketplace/security.d.ts.map +1 -0
- package/dist/marketplace/security.js +199 -0
- package/dist/marketplace/security.js.map +1 -0
- package/dist/multi-squad.d.ts +89 -0
- package/dist/multi-squad.d.ts.map +1 -0
- package/dist/multi-squad.js +233 -0
- package/dist/multi-squad.js.map +1 -0
- package/dist/parsers.d.ts +15 -0
- package/dist/parsers.d.ts.map +1 -0
- package/dist/parsers.js +15 -0
- package/dist/parsers.js.map +1 -0
- package/dist/ralph/index.d.ts +58 -0
- package/dist/ralph/index.d.ts.map +1 -0
- package/dist/ralph/index.js +128 -0
- package/dist/ralph/index.js.map +1 -0
- package/dist/ralph/triage.d.ts +48 -0
- package/dist/ralph/triage.d.ts.map +1 -0
- package/dist/ralph/triage.js +310 -0
- package/dist/ralph/triage.js.map +1 -0
- package/dist/remote/bridge.d.ts +79 -0
- package/dist/remote/bridge.d.ts.map +1 -0
- package/dist/remote/bridge.js +583 -0
- package/dist/remote/bridge.js.map +1 -0
- package/dist/remote/index.d.ts +7 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +6 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote/protocol.d.ts +130 -0
- package/dist/remote/protocol.d.ts.map +1 -0
- package/dist/remote/protocol.js +25 -0
- package/dist/remote/protocol.js.map +1 -0
- package/dist/remote/types.d.ts +34 -0
- package/dist/remote/types.d.ts.map +1 -0
- package/dist/remote/types.js +5 -0
- package/dist/remote/types.js.map +1 -0
- package/dist/resolution.d.ts +119 -0
- package/dist/resolution.d.ts.map +1 -0
- package/dist/resolution.js +259 -0
- package/dist/resolution.js.map +1 -0
- package/dist/runtime/benchmarks.d.ts +121 -0
- package/dist/runtime/benchmarks.d.ts.map +1 -0
- package/dist/runtime/benchmarks.js +251 -0
- package/dist/runtime/benchmarks.js.map +1 -0
- package/dist/runtime/config.d.ts +314 -0
- package/dist/runtime/config.d.ts.map +1 -0
- package/dist/runtime/config.js +467 -0
- package/dist/runtime/config.js.map +1 -0
- package/dist/runtime/constants.d.ts +37 -0
- package/dist/runtime/constants.d.ts.map +1 -0
- package/dist/runtime/constants.js +60 -0
- package/dist/runtime/constants.js.map +1 -0
- package/dist/runtime/cost-tracker.d.ts +73 -0
- package/dist/runtime/cost-tracker.d.ts.map +1 -0
- package/dist/runtime/cost-tracker.js +157 -0
- package/dist/runtime/cost-tracker.js.map +1 -0
- package/dist/runtime/event-bus-ws-bridge.d.ts +35 -0
- package/dist/runtime/event-bus-ws-bridge.d.ts.map +1 -0
- package/dist/runtime/event-bus-ws-bridge.js +55 -0
- package/dist/runtime/event-bus-ws-bridge.js.map +1 -0
- package/dist/runtime/event-bus.d.ts +190 -0
- package/dist/runtime/event-bus.d.ts.map +1 -0
- package/dist/runtime/event-bus.js +218 -0
- package/dist/runtime/event-bus.js.map +1 -0
- package/dist/runtime/event-payloads.d.ts +108 -0
- package/dist/runtime/event-payloads.d.ts.map +1 -0
- package/dist/runtime/event-payloads.js +28 -0
- package/dist/runtime/event-payloads.js.map +1 -0
- package/dist/runtime/health.d.ts +66 -0
- package/dist/runtime/health.d.ts.map +1 -0
- package/dist/runtime/health.js +112 -0
- package/dist/runtime/health.js.map +1 -0
- package/dist/runtime/i18n.d.ts +54 -0
- package/dist/runtime/i18n.d.ts.map +1 -0
- package/dist/runtime/i18n.js +126 -0
- package/dist/runtime/i18n.js.map +1 -0
- package/dist/runtime/offline.d.ts +64 -0
- package/dist/runtime/offline.d.ts.map +1 -0
- package/dist/runtime/offline.js +108 -0
- package/dist/runtime/offline.js.map +1 -0
- package/dist/runtime/otel-api.d.ts +38 -0
- package/dist/runtime/otel-api.d.ts.map +1 -0
- package/dist/runtime/otel-api.js +94 -0
- package/dist/runtime/otel-api.js.map +1 -0
- package/dist/runtime/otel-bridge.d.ts +52 -0
- package/dist/runtime/otel-bridge.d.ts.map +1 -0
- package/dist/runtime/otel-bridge.js +132 -0
- package/dist/runtime/otel-bridge.js.map +1 -0
- package/dist/runtime/otel-init.d.ts +84 -0
- package/dist/runtime/otel-init.d.ts.map +1 -0
- package/dist/runtime/otel-init.js +86 -0
- package/dist/runtime/otel-init.js.map +1 -0
- package/dist/runtime/otel-metrics.d.ts +42 -0
- package/dist/runtime/otel-metrics.d.ts.map +1 -0
- package/dist/runtime/otel-metrics.js +196 -0
- package/dist/runtime/otel-metrics.js.map +1 -0
- package/dist/runtime/otel.d.ts +55 -0
- package/dist/runtime/otel.d.ts.map +1 -0
- package/dist/runtime/otel.js +165 -0
- package/dist/runtime/otel.js.map +1 -0
- package/dist/runtime/squad-observer.d.ts +75 -0
- package/dist/runtime/squad-observer.d.ts.map +1 -0
- package/dist/runtime/squad-observer.js +190 -0
- package/dist/runtime/squad-observer.js.map +1 -0
- package/dist/runtime/streaming.d.ts +106 -0
- package/dist/runtime/streaming.d.ts.map +1 -0
- package/dist/runtime/streaming.js +192 -0
- package/dist/runtime/streaming.js.map +1 -0
- package/dist/runtime/telemetry.d.ts +82 -0
- package/dist/runtime/telemetry.d.ts.map +1 -0
- package/dist/runtime/telemetry.js +120 -0
- package/dist/runtime/telemetry.js.map +1 -0
- package/dist/sharing/agent-repo.d.ts +33 -0
- package/dist/sharing/agent-repo.d.ts.map +1 -0
- package/dist/sharing/agent-repo.js +79 -0
- package/dist/sharing/agent-repo.js.map +1 -0
- package/dist/sharing/cache.d.ts +36 -0
- package/dist/sharing/cache.d.ts.map +1 -0
- package/dist/sharing/cache.js +85 -0
- package/dist/sharing/cache.js.map +1 -0
- package/dist/sharing/conflicts.d.ts +32 -0
- package/dist/sharing/conflicts.d.ts.map +1 -0
- package/dist/sharing/conflicts.js +123 -0
- package/dist/sharing/conflicts.js.map +1 -0
- package/dist/sharing/consult.d.ts +226 -0
- package/dist/sharing/consult.d.ts.map +1 -0
- package/dist/sharing/consult.js +818 -0
- package/dist/sharing/consult.js.map +1 -0
- package/dist/sharing/export.d.ts +50 -0
- package/dist/sharing/export.d.ts.map +1 -0
- package/dist/sharing/export.js +156 -0
- package/dist/sharing/export.js.map +1 -0
- package/dist/sharing/history-split.d.ts +34 -0
- package/dist/sharing/history-split.d.ts.map +1 -0
- package/dist/sharing/history-split.js +101 -0
- package/dist/sharing/history-split.js.map +1 -0
- package/dist/sharing/import.d.ts +37 -0
- package/dist/sharing/import.d.ts.map +1 -0
- package/dist/sharing/import.js +138 -0
- package/dist/sharing/import.js.map +1 -0
- package/dist/sharing/index.d.ts +12 -0
- package/dist/sharing/index.d.ts.map +1 -0
- package/dist/sharing/index.js +12 -0
- package/dist/sharing/index.js.map +1 -0
- package/dist/sharing/versioning.d.ts +32 -0
- package/dist/sharing/versioning.d.ts.map +1 -0
- package/dist/sharing/versioning.js +64 -0
- package/dist/sharing/versioning.js.map +1 -0
- package/dist/skills/index.d.ts +49 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +85 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/skill-loader.d.ts +56 -0
- package/dist/skills/skill-loader.d.ts.map +1 -0
- package/dist/skills/skill-loader.js +106 -0
- package/dist/skills/skill-loader.js.map +1 -0
- package/dist/skills/skill-source.d.ts +63 -0
- package/dist/skills/skill-source.d.ts.map +1 -0
- package/dist/skills/skill-source.js +199 -0
- package/dist/skills/skill-source.js.map +1 -0
- package/dist/streams/filter.d.ts +33 -0
- package/dist/streams/filter.d.ts.map +1 -0
- package/dist/streams/filter.js +29 -0
- package/dist/streams/filter.js.map +1 -0
- package/dist/streams/index.d.ts +9 -0
- package/dist/streams/index.d.ts.map +1 -0
- package/dist/streams/index.js +9 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams/resolver.d.ts +40 -0
- package/dist/streams/resolver.d.ts.map +1 -0
- package/dist/streams/resolver.js +162 -0
- package/dist/streams/resolver.js.map +1 -0
- package/dist/streams/types.d.ts +44 -0
- package/dist/streams/types.d.ts.map +1 -0
- package/dist/streams/types.js +10 -0
- package/dist/streams/types.js.map +1 -0
- package/dist/tools/index.d.ts +95 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +475 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/upstream/index.d.ts +8 -0
- package/dist/upstream/index.d.ts.map +1 -0
- package/dist/upstream/index.js +7 -0
- package/dist/upstream/index.js.map +1 -0
- package/dist/upstream/resolver.d.ts +37 -0
- package/dist/upstream/resolver.d.ts.map +1 -0
- package/dist/upstream/resolver.js +234 -0
- package/dist/upstream/resolver.js.map +1 -0
- package/dist/upstream/types.d.ts +55 -0
- package/dist/upstream/types.d.ts.map +1 -0
- package/dist/upstream/types.js +11 -0
- package/dist/upstream/types.js.map +1 -0
- package/dist/utils/normalize-eol.d.ts +6 -0
- package/dist/utils/normalize-eol.d.ts.map +1 -0
- package/dist/utils/normalize-eol.js +8 -0
- package/dist/utils/normalize-eol.js.map +1 -0
- package/dist/utils/safe-timestamp.d.ts +6 -0
- package/dist/utils/safe-timestamp.d.ts.map +1 -0
- package/dist/utils/safe-timestamp.js +8 -0
- package/dist/utils/safe-timestamp.js.map +1 -0
- package/package.json +151 -6
- package/templates/casting-history.json +4 -0
- package/templates/casting-policy.json +35 -0
- package/templates/casting-registry.json +3 -0
- package/templates/ceremonies.md +41 -0
- package/templates/charter.md +53 -0
- package/templates/constraint-tracking.md +38 -0
- package/templates/copilot-instructions.md +46 -0
- package/templates/history.md +10 -0
- package/templates/identity/now.md +9 -0
- package/templates/identity/wisdom.md +15 -0
- package/templates/mcp-config.md +98 -0
- package/templates/multi-agent-format.md +28 -0
- package/templates/orchestration-log.md +27 -0
- package/templates/plugin-marketplace.md +49 -0
- package/templates/raw-agent-output.md +37 -0
- package/templates/roster.md +60 -0
- package/templates/routing.md +54 -0
- package/templates/run-output.md +50 -0
- package/templates/scribe-charter.md +119 -0
- package/templates/skill.md +24 -0
- package/templates/skills/project-conventions/SKILL.md +56 -0
- package/templates/squad.agent.md +1146 -0
- package/templates/workflows/squad-ci.yml +24 -0
- package/templates/workflows/squad-docs.yml +50 -0
- package/templates/workflows/squad-heartbeat.yml +316 -0
- package/templates/workflows/squad-insider-release.yml +61 -0
- package/templates/workflows/squad-issue-assign.yml +161 -0
- package/templates/workflows/squad-label-enforce.yml +181 -0
- package/templates/workflows/squad-preview.yml +55 -0
- package/templates/workflows/squad-promote.yml +120 -0
- package/templates/workflows/squad-release.yml +77 -0
- package/templates/workflows/squad-triage.yml +260 -0
- package/templates/workflows/sync-squad-labels.yml +169 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Squad SDK Client Adapter
|
|
3
|
+
*
|
|
4
|
+
* Wraps CopilotClient to provide connection lifecycle management, error recovery,
|
|
5
|
+
* automatic reconnection, and protocol version validation.
|
|
6
|
+
*
|
|
7
|
+
* @module adapter/client
|
|
8
|
+
*/
|
|
9
|
+
import { CopilotClient } from "@github/copilot-sdk";
|
|
10
|
+
import { trace, SpanStatusCode } from '../runtime/otel-api.js';
|
|
11
|
+
import { recordSessionCreated, recordSessionClosed, recordSessionError } from '../runtime/otel-metrics.js';
|
|
12
|
+
const tracer = trace.getTracer('squad-sdk');
|
|
13
|
+
/**
|
|
14
|
+
* Adapts @github/copilot-sdk CopilotSession to our SquadSession interface.
|
|
15
|
+
* Maps sendMessage() → send(), off() via unsubscribe tracking, close() → destroy().
|
|
16
|
+
*
|
|
17
|
+
* Bug reported by @spboyer (Shayne Boyer) — Codespace environment exposed
|
|
18
|
+
* the unsafe `as unknown as` cast that skipped runtime method mapping.
|
|
19
|
+
*/
|
|
20
|
+
class CopilotSessionAdapter {
|
|
21
|
+
/**
|
|
22
|
+
* Maps Squad short event names → @github/copilot-sdk dotted event names.
|
|
23
|
+
* SDK uses dotted-namespace prefixes (e.g., `assistant.message_delta`),
|
|
24
|
+
* while Squad uses short names (e.g., `message_delta`).
|
|
25
|
+
* Names already in dotted form pass through via the fallback.
|
|
26
|
+
*/
|
|
27
|
+
static EVENT_MAP = {
|
|
28
|
+
'message_delta': 'assistant.message_delta',
|
|
29
|
+
'message': 'assistant.message',
|
|
30
|
+
'usage': 'assistant.usage',
|
|
31
|
+
'reasoning_delta': 'assistant.reasoning_delta',
|
|
32
|
+
'reasoning': 'assistant.reasoning',
|
|
33
|
+
'turn_start': 'assistant.turn_start',
|
|
34
|
+
'turn_end': 'assistant.turn_end',
|
|
35
|
+
'intent': 'assistant.intent',
|
|
36
|
+
'idle': 'session.idle',
|
|
37
|
+
'error': 'session.error',
|
|
38
|
+
};
|
|
39
|
+
/** Reverse map: SDK dotted names → Squad short names. */
|
|
40
|
+
static REVERSE_EVENT_MAP = Object.fromEntries(Object.entries(CopilotSessionAdapter.EVENT_MAP).map(([k, v]) => [v, k]));
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
inner;
|
|
43
|
+
unsubscribers = new Map();
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
constructor(copilotSession) {
|
|
46
|
+
this.inner = copilotSession;
|
|
47
|
+
}
|
|
48
|
+
get sessionId() {
|
|
49
|
+
return this.inner.sessionId ?? 'unknown';
|
|
50
|
+
}
|
|
51
|
+
async sendMessage(options) {
|
|
52
|
+
await this.inner.send(options);
|
|
53
|
+
}
|
|
54
|
+
async sendAndWait(options, timeout) {
|
|
55
|
+
return await this.inner.sendAndWait(options, timeout);
|
|
56
|
+
}
|
|
57
|
+
async abort() {
|
|
58
|
+
await this.inner.abort();
|
|
59
|
+
}
|
|
60
|
+
async getMessages() {
|
|
61
|
+
return await this.inner.getMessages();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Normalizes an SDK event into a SquadSessionEvent.
|
|
65
|
+
* Maps the dotted type back to the Squad short name and
|
|
66
|
+
* flattens `event.data` onto the top-level object so callers
|
|
67
|
+
* can access fields directly (e.g., `event.inputTokens`).
|
|
68
|
+
*/
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
static normalizeEvent(sdkEvent) {
|
|
71
|
+
const squadType = CopilotSessionAdapter.REVERSE_EVENT_MAP[sdkEvent.type] ?? sdkEvent.type;
|
|
72
|
+
return {
|
|
73
|
+
type: squadType,
|
|
74
|
+
...(sdkEvent.data ?? {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
on(eventType, handler) {
|
|
78
|
+
const sdkType = CopilotSessionAdapter.EVENT_MAP[eventType] ?? eventType;
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const wrappedHandler = (sdkEvent) => {
|
|
81
|
+
handler(CopilotSessionAdapter.normalizeEvent(sdkEvent));
|
|
82
|
+
};
|
|
83
|
+
const unsubscribe = this.inner.on(sdkType, wrappedHandler);
|
|
84
|
+
if (!this.unsubscribers.has(handler)) {
|
|
85
|
+
this.unsubscribers.set(handler, new Map());
|
|
86
|
+
}
|
|
87
|
+
this.unsubscribers.get(handler).set(eventType, unsubscribe);
|
|
88
|
+
}
|
|
89
|
+
off(eventType, handler) {
|
|
90
|
+
const handlerMap = this.unsubscribers.get(handler);
|
|
91
|
+
if (handlerMap) {
|
|
92
|
+
const unsubscribe = handlerMap.get(eventType);
|
|
93
|
+
if (unsubscribe) {
|
|
94
|
+
unsubscribe();
|
|
95
|
+
handlerMap.delete(eventType);
|
|
96
|
+
}
|
|
97
|
+
if (handlerMap.size === 0) {
|
|
98
|
+
this.unsubscribers.delete(handler);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async close() {
|
|
103
|
+
await this.inner.destroy();
|
|
104
|
+
this.unsubscribers.clear();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* SquadClient wraps CopilotClient with enhanced lifecycle management.
|
|
109
|
+
*
|
|
110
|
+
* Features:
|
|
111
|
+
* - Connection state tracking
|
|
112
|
+
* - Automatic reconnection with exponential backoff
|
|
113
|
+
* - Protocol version validation
|
|
114
|
+
* - Error recovery
|
|
115
|
+
* - Session lifecycle event handling
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const client = new SquadClient();
|
|
120
|
+
* await client.connect();
|
|
121
|
+
*
|
|
122
|
+
* const session = await client.createSession({
|
|
123
|
+
* model: "claude-sonnet-4.5"
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* await client.disconnect();
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export class SquadClient {
|
|
130
|
+
client;
|
|
131
|
+
state = "disconnected";
|
|
132
|
+
connectPromise = null;
|
|
133
|
+
reconnectAttempts = 0;
|
|
134
|
+
reconnectTimer = null;
|
|
135
|
+
options;
|
|
136
|
+
manualDisconnect = false;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a new SquadClient instance.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Configuration options
|
|
141
|
+
* @throws Error if mutually exclusive options are provided
|
|
142
|
+
*/
|
|
143
|
+
constructor(options = {}) {
|
|
144
|
+
this.options = {
|
|
145
|
+
cliPath: options.cliPath,
|
|
146
|
+
cliArgs: options.cliArgs ?? [],
|
|
147
|
+
cwd: options.cwd ?? process.cwd(),
|
|
148
|
+
port: options.port ?? 0,
|
|
149
|
+
useStdio: options.useStdio ?? true,
|
|
150
|
+
cliUrl: options.cliUrl,
|
|
151
|
+
logLevel: options.logLevel ?? "debug",
|
|
152
|
+
autoStart: options.autoStart ?? true,
|
|
153
|
+
autoReconnect: options.autoReconnect ?? true,
|
|
154
|
+
env: options.env ?? process.env,
|
|
155
|
+
githubToken: options.githubToken,
|
|
156
|
+
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
|
|
157
|
+
maxReconnectAttempts: options.maxReconnectAttempts ?? 3,
|
|
158
|
+
reconnectDelayMs: options.reconnectDelayMs ?? 1000,
|
|
159
|
+
};
|
|
160
|
+
this.client = new CopilotClient({
|
|
161
|
+
cliPath: this.options.cliPath,
|
|
162
|
+
cliArgs: this.options.cliArgs,
|
|
163
|
+
cwd: this.options.cwd,
|
|
164
|
+
port: this.options.port,
|
|
165
|
+
useStdio: this.options.useStdio,
|
|
166
|
+
cliUrl: this.options.cliUrl,
|
|
167
|
+
logLevel: this.options.logLevel,
|
|
168
|
+
autoStart: false, // We manage connection lifecycle
|
|
169
|
+
autoRestart: false, // We handle reconnection ourselves
|
|
170
|
+
env: this.options.env,
|
|
171
|
+
githubToken: this.options.githubToken,
|
|
172
|
+
useLoggedInUser: this.options.useLoggedInUser,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get the current connection state.
|
|
177
|
+
*/
|
|
178
|
+
getState() {
|
|
179
|
+
return this.state;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Check if the client is connected.
|
|
183
|
+
*/
|
|
184
|
+
isConnected() {
|
|
185
|
+
return this.state === "connected";
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Establish connection to the Copilot CLI server.
|
|
189
|
+
*
|
|
190
|
+
* This method:
|
|
191
|
+
* 1. Spawns or connects to the CLI server
|
|
192
|
+
* 2. Validates protocol version compatibility
|
|
193
|
+
* 3. Sets up automatic reconnection handlers
|
|
194
|
+
*
|
|
195
|
+
* @returns Promise that resolves when connection is established
|
|
196
|
+
* @throws Error if connection fails or protocol version is incompatible
|
|
197
|
+
*/
|
|
198
|
+
async connect() {
|
|
199
|
+
if (this.state === "connected") {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Dedup: if a connection is already in progress, piggyback on it
|
|
203
|
+
if (this.state === "connecting" && this.connectPromise) {
|
|
204
|
+
return this.connectPromise;
|
|
205
|
+
}
|
|
206
|
+
const span = tracer.startSpan('squad.client.connect');
|
|
207
|
+
span.setAttribute('connection.transport', this.options.useStdio ? 'stdio' : 'tcp');
|
|
208
|
+
this.state = "connecting";
|
|
209
|
+
this.manualDisconnect = false;
|
|
210
|
+
this.connectPromise = (async () => {
|
|
211
|
+
const startTime = Date.now();
|
|
212
|
+
try {
|
|
213
|
+
await this.client.start();
|
|
214
|
+
const elapsed = Date.now() - startTime;
|
|
215
|
+
this.state = "connected";
|
|
216
|
+
this.reconnectAttempts = 0;
|
|
217
|
+
span.setAttribute('connection.duration_ms', elapsed);
|
|
218
|
+
if (elapsed > 2000) {
|
|
219
|
+
console.warn(`SquadClient connection took ${elapsed}ms (> 2s threshold)`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
this.state = "error";
|
|
224
|
+
const wrapped = new Error(`Failed to connect to Copilot CLI: ${error instanceof Error ? error.message : String(error)}`);
|
|
225
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: wrapped.message });
|
|
226
|
+
span.recordException(wrapped);
|
|
227
|
+
throw wrapped;
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
this.connectPromise = null;
|
|
231
|
+
span.end();
|
|
232
|
+
}
|
|
233
|
+
})();
|
|
234
|
+
return this.connectPromise;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Disconnect from the Copilot CLI server.
|
|
238
|
+
*
|
|
239
|
+
* Performs graceful cleanup:
|
|
240
|
+
* 1. Destroys all active sessions
|
|
241
|
+
* 2. Closes the connection
|
|
242
|
+
* 3. Terminates the CLI process (if spawned)
|
|
243
|
+
*
|
|
244
|
+
* @returns Promise that resolves with any errors encountered during cleanup
|
|
245
|
+
*/
|
|
246
|
+
async disconnect() {
|
|
247
|
+
const span = tracer.startSpan('squad.client.disconnect');
|
|
248
|
+
try {
|
|
249
|
+
this.manualDisconnect = true;
|
|
250
|
+
if (this.reconnectTimer) {
|
|
251
|
+
clearTimeout(this.reconnectTimer);
|
|
252
|
+
this.reconnectTimer = null;
|
|
253
|
+
}
|
|
254
|
+
const errors = await this.client.stop();
|
|
255
|
+
this.state = "disconnected";
|
|
256
|
+
this.reconnectAttempts = 0;
|
|
257
|
+
this.connectPromise = null;
|
|
258
|
+
return errors;
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
262
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
263
|
+
throw err;
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
span.end();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Force disconnect without graceful cleanup.
|
|
271
|
+
* Use only when disconnect() fails or hangs.
|
|
272
|
+
*/
|
|
273
|
+
async forceDisconnect() {
|
|
274
|
+
this.manualDisconnect = true;
|
|
275
|
+
if (this.reconnectTimer) {
|
|
276
|
+
clearTimeout(this.reconnectTimer);
|
|
277
|
+
this.reconnectTimer = null;
|
|
278
|
+
}
|
|
279
|
+
await this.client.forceStop();
|
|
280
|
+
this.state = "disconnected";
|
|
281
|
+
this.reconnectAttempts = 0;
|
|
282
|
+
this.connectPromise = null;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Create a new Squad session.
|
|
286
|
+
*
|
|
287
|
+
* If autoStart is enabled and the client is not connected, this will
|
|
288
|
+
* automatically establish the connection.
|
|
289
|
+
*
|
|
290
|
+
* @param config - Session configuration
|
|
291
|
+
* @returns Promise that resolves with the created session
|
|
292
|
+
*/
|
|
293
|
+
async createSession(config = {}) {
|
|
294
|
+
const span = tracer.startSpan('squad.session.create');
|
|
295
|
+
span.setAttribute('session.auto_start', this.options.autoStart);
|
|
296
|
+
try {
|
|
297
|
+
if (!this.isConnected() && this.options.autoStart) {
|
|
298
|
+
await this.connect();
|
|
299
|
+
}
|
|
300
|
+
if (!this.isConnected()) {
|
|
301
|
+
throw new Error("Client not connected. Call connect() first.");
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
// Cast config to handle SDK version differences in SessionConfig type
|
|
305
|
+
const session = await this.client.createSession(config);
|
|
306
|
+
const result = new CopilotSessionAdapter(session);
|
|
307
|
+
if (result.sessionId) {
|
|
308
|
+
span.setAttribute('session.id', result.sessionId);
|
|
309
|
+
}
|
|
310
|
+
recordSessionCreated();
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
315
|
+
if (msg.includes('onPermissionRequest')) {
|
|
316
|
+
throw new Error('Session creation failed: an onPermissionRequest handler is required. ' +
|
|
317
|
+
'Pass { onPermissionRequest: () => ({ kind: "approved" }) } in your session config ' +
|
|
318
|
+
'to approve all permissions, or provide a custom handler.');
|
|
319
|
+
}
|
|
320
|
+
recordSessionError();
|
|
321
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
322
|
+
await this.attemptReconnection();
|
|
323
|
+
return this.createSession(config);
|
|
324
|
+
}
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (err) {
|
|
329
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
330
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
331
|
+
throw err;
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
span.end();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Resume an existing Squad session by ID.
|
|
339
|
+
*
|
|
340
|
+
* @param sessionId - ID of the session to resume
|
|
341
|
+
* @param config - Optional configuration overrides
|
|
342
|
+
* @returns Promise that resolves with the resumed session
|
|
343
|
+
*/
|
|
344
|
+
async resumeSession(sessionId, config = {}) {
|
|
345
|
+
const span = tracer.startSpan('squad.session.resume');
|
|
346
|
+
span.setAttribute('session.id', sessionId);
|
|
347
|
+
try {
|
|
348
|
+
if (!this.isConnected() && this.options.autoStart) {
|
|
349
|
+
await this.connect();
|
|
350
|
+
}
|
|
351
|
+
if (!this.isConnected()) {
|
|
352
|
+
throw new Error("Client not connected. Call connect() first.");
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
// Cast config to handle SDK version differences in ResumeSessionConfig type
|
|
356
|
+
const session = await this.client.resumeSession(sessionId, config);
|
|
357
|
+
return new CopilotSessionAdapter(session);
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
361
|
+
await this.attemptReconnection();
|
|
362
|
+
return this.resumeSession(sessionId, config);
|
|
363
|
+
}
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
catch (err) {
|
|
368
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
369
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
370
|
+
throw err;
|
|
371
|
+
}
|
|
372
|
+
finally {
|
|
373
|
+
span.end();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* List all available sessions.
|
|
378
|
+
*/
|
|
379
|
+
async listSessions() {
|
|
380
|
+
const span = tracer.startSpan('squad.session.list');
|
|
381
|
+
try {
|
|
382
|
+
if (!this.isConnected()) {
|
|
383
|
+
throw new Error("Client not connected");
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
const sessions = await this.client.listSessions();
|
|
387
|
+
const result = sessions.map((s) => ({
|
|
388
|
+
sessionId: s.sessionId,
|
|
389
|
+
startTime: s.startTime,
|
|
390
|
+
modifiedTime: s.modifiedTime,
|
|
391
|
+
summary: s.summary,
|
|
392
|
+
isRemote: s.isRemote,
|
|
393
|
+
context: s.context,
|
|
394
|
+
}));
|
|
395
|
+
span.setAttribute('sessions.count', result.length);
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
400
|
+
await this.attemptReconnection();
|
|
401
|
+
return this.listSessions();
|
|
402
|
+
}
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
catch (err) {
|
|
407
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
408
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
409
|
+
throw err;
|
|
410
|
+
}
|
|
411
|
+
finally {
|
|
412
|
+
span.end();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Delete a session by ID.
|
|
417
|
+
*/
|
|
418
|
+
async deleteSession(sessionId) {
|
|
419
|
+
const span = tracer.startSpan('squad.session.delete');
|
|
420
|
+
span.setAttribute('session.id', sessionId);
|
|
421
|
+
try {
|
|
422
|
+
if (!this.isConnected()) {
|
|
423
|
+
throw new Error("Client not connected");
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
await this.client.deleteSession(sessionId);
|
|
427
|
+
recordSessionClosed();
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
recordSessionError();
|
|
431
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
432
|
+
await this.attemptReconnection();
|
|
433
|
+
return this.deleteSession(sessionId);
|
|
434
|
+
}
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
catch (err) {
|
|
439
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
440
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
441
|
+
throw err;
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
span.end();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get the ID of the last updated session.
|
|
449
|
+
*/
|
|
450
|
+
async getLastSessionId() {
|
|
451
|
+
if (!this.isConnected()) {
|
|
452
|
+
throw new Error("Client not connected");
|
|
453
|
+
}
|
|
454
|
+
try {
|
|
455
|
+
return await this.client.getLastSessionId();
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
459
|
+
await this.attemptReconnection();
|
|
460
|
+
return this.getLastSessionId();
|
|
461
|
+
}
|
|
462
|
+
throw error;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Send a ping to verify connectivity.
|
|
467
|
+
*/
|
|
468
|
+
async ping(message) {
|
|
469
|
+
if (!this.isConnected()) {
|
|
470
|
+
throw new Error("Client not connected");
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
return await this.client.ping(message);
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
477
|
+
await this.attemptReconnection();
|
|
478
|
+
return this.ping(message);
|
|
479
|
+
}
|
|
480
|
+
throw error;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Get CLI status information.
|
|
485
|
+
*/
|
|
486
|
+
async getStatus() {
|
|
487
|
+
if (!this.isConnected()) {
|
|
488
|
+
throw new Error("Client not connected");
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
const raw = await this.client.getStatus();
|
|
492
|
+
return {
|
|
493
|
+
version: raw.version,
|
|
494
|
+
protocolVersion: raw.protocolVersion,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
499
|
+
await this.attemptReconnection();
|
|
500
|
+
return this.getStatus();
|
|
501
|
+
}
|
|
502
|
+
throw error;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Get authentication status.
|
|
507
|
+
*/
|
|
508
|
+
async getAuthStatus() {
|
|
509
|
+
if (!this.isConnected()) {
|
|
510
|
+
throw new Error("Client not connected");
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
const raw = await this.client.getAuthStatus();
|
|
514
|
+
return {
|
|
515
|
+
isAuthenticated: raw.isAuthenticated,
|
|
516
|
+
authType: raw.authType,
|
|
517
|
+
host: raw.host,
|
|
518
|
+
login: raw.login,
|
|
519
|
+
statusMessage: raw.statusMessage,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
524
|
+
await this.attemptReconnection();
|
|
525
|
+
return this.getAuthStatus();
|
|
526
|
+
}
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* List available models.
|
|
532
|
+
*/
|
|
533
|
+
async listModels() {
|
|
534
|
+
if (!this.isConnected()) {
|
|
535
|
+
throw new Error("Client not connected");
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
const models = await this.client.listModels();
|
|
539
|
+
return models.map((m) => ({
|
|
540
|
+
id: m.id,
|
|
541
|
+
name: m.name,
|
|
542
|
+
capabilities: m.capabilities,
|
|
543
|
+
policy: m.policy,
|
|
544
|
+
billing: m.billing,
|
|
545
|
+
supportedReasoningEfforts: m.supportedReasoningEfforts,
|
|
546
|
+
defaultReasoningEffort: m.defaultReasoningEffort,
|
|
547
|
+
}));
|
|
548
|
+
}
|
|
549
|
+
catch (error) {
|
|
550
|
+
if (this.shouldAttemptReconnect(error)) {
|
|
551
|
+
await this.attemptReconnection();
|
|
552
|
+
return this.listModels();
|
|
553
|
+
}
|
|
554
|
+
throw error;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Send a message to a session, wrapped with OTel tracing.
|
|
559
|
+
*
|
|
560
|
+
* Creates a `squad.session.message` span for the full call and a
|
|
561
|
+
* child `squad.session.stream` span that tracks streaming duration
|
|
562
|
+
* with `first_token`, `last_token`, and `stream_error` events.
|
|
563
|
+
*
|
|
564
|
+
* @param session - The session to send the message to
|
|
565
|
+
* @param options - Message content and delivery options
|
|
566
|
+
* @returns Promise that resolves when the message is processed
|
|
567
|
+
*/
|
|
568
|
+
async sendMessage(session, options) {
|
|
569
|
+
const messageSpan = tracer.startSpan('squad.session.message');
|
|
570
|
+
messageSpan.setAttribute('session.id', session.sessionId);
|
|
571
|
+
messageSpan.setAttribute('prompt.length', options.prompt.length);
|
|
572
|
+
messageSpan.setAttribute('streaming', true);
|
|
573
|
+
const streamSpan = tracer.startSpan('squad.session.stream');
|
|
574
|
+
streamSpan.setAttribute('session.id', session.sessionId);
|
|
575
|
+
const messageStartMs = Date.now();
|
|
576
|
+
let firstTokenRecorded = false;
|
|
577
|
+
let outputTokens = 0;
|
|
578
|
+
let inputTokens = 0;
|
|
579
|
+
const origOn = session.on.bind(session);
|
|
580
|
+
// Wire temporary event listener for stream tracking
|
|
581
|
+
const streamListener = (event) => {
|
|
582
|
+
if (event.type === 'message_delta' && !firstTokenRecorded) {
|
|
583
|
+
firstTokenRecorded = true;
|
|
584
|
+
streamSpan.addEvent('first_token');
|
|
585
|
+
}
|
|
586
|
+
if (event.type === 'usage') {
|
|
587
|
+
inputTokens = typeof event['inputTokens'] === 'number' ? event['inputTokens'] : 0;
|
|
588
|
+
outputTokens = typeof event['outputTokens'] === 'number' ? event['outputTokens'] : 0;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
origOn('message_delta', streamListener);
|
|
592
|
+
origOn('usage', streamListener);
|
|
593
|
+
try {
|
|
594
|
+
await session.sendMessage(options);
|
|
595
|
+
const durationMs = Date.now() - messageStartMs;
|
|
596
|
+
streamSpan.addEvent('last_token');
|
|
597
|
+
streamSpan.setAttribute('tokens.input', inputTokens);
|
|
598
|
+
streamSpan.setAttribute('tokens.output', outputTokens);
|
|
599
|
+
streamSpan.setAttribute('duration_ms', durationMs);
|
|
600
|
+
}
|
|
601
|
+
catch (err) {
|
|
602
|
+
streamSpan.addEvent('stream_error');
|
|
603
|
+
streamSpan.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
604
|
+
streamSpan.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
605
|
+
messageSpan.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
606
|
+
messageSpan.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
607
|
+
throw err;
|
|
608
|
+
}
|
|
609
|
+
finally {
|
|
610
|
+
streamSpan.end();
|
|
611
|
+
messageSpan.end();
|
|
612
|
+
// Clean up listeners
|
|
613
|
+
try {
|
|
614
|
+
session.off('message_delta', streamListener);
|
|
615
|
+
session.off('usage', streamListener);
|
|
616
|
+
}
|
|
617
|
+
catch {
|
|
618
|
+
// session may not support off — ignore
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Close a session (alias for deleteSession with `squad.session.close` span).
|
|
624
|
+
*
|
|
625
|
+
* @param sessionId - ID of the session to close
|
|
626
|
+
*/
|
|
627
|
+
async closeSession(sessionId) {
|
|
628
|
+
const span = tracer.startSpan('squad.session.close');
|
|
629
|
+
span.setAttribute('session.id', sessionId);
|
|
630
|
+
try {
|
|
631
|
+
await this.deleteSession(sessionId);
|
|
632
|
+
}
|
|
633
|
+
catch (err) {
|
|
634
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
635
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
636
|
+
throw err;
|
|
637
|
+
}
|
|
638
|
+
finally {
|
|
639
|
+
span.end();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
on(eventTypeOrHandler, handler) {
|
|
643
|
+
if (typeof eventTypeOrHandler === "string" && handler) {
|
|
644
|
+
return this.client.on(eventTypeOrHandler, handler);
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
return this.client.on(eventTypeOrHandler);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Determine if an error is recoverable via reconnection.
|
|
652
|
+
*/
|
|
653
|
+
shouldAttemptReconnect(error) {
|
|
654
|
+
if (!this.options.autoReconnect) {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
if (this.manualDisconnect) {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
664
|
+
// Transient connection errors
|
|
665
|
+
if (message.includes("ECONNREFUSED") ||
|
|
666
|
+
message.includes("ECONNRESET") ||
|
|
667
|
+
message.includes("EPIPE") ||
|
|
668
|
+
message.includes("Client not connected") ||
|
|
669
|
+
message.includes("Connection closed")) {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Attempt to reconnect with exponential backoff.
|
|
676
|
+
*/
|
|
677
|
+
async attemptReconnection() {
|
|
678
|
+
if (this.state === "reconnecting") {
|
|
679
|
+
throw new Error("Reconnection already in progress");
|
|
680
|
+
}
|
|
681
|
+
this.state = "reconnecting";
|
|
682
|
+
this.reconnectAttempts++;
|
|
683
|
+
const delay = this.options.reconnectDelayMs * Math.pow(2, this.reconnectAttempts - 1);
|
|
684
|
+
await new Promise((resolve) => {
|
|
685
|
+
this.reconnectTimer = setTimeout(resolve, delay);
|
|
686
|
+
});
|
|
687
|
+
try {
|
|
688
|
+
await this.client.stop();
|
|
689
|
+
await this.client.start();
|
|
690
|
+
this.state = "connected";
|
|
691
|
+
this.reconnectAttempts = 0;
|
|
692
|
+
}
|
|
693
|
+
catch (error) {
|
|
694
|
+
this.state = "error";
|
|
695
|
+
throw new Error(`Reconnection attempt ${this.reconnectAttempts} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
//# sourceMappingURL=client.js.map
|