@ai-devkit/agent-manager 0.42.3 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AgentManager.d.ts +14 -5
- package/dist/AgentManager.d.ts.map +1 -1
- package/dist/AgentManager.js +32 -13
- package/dist/AgentManager.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/.swcrc +0 -27
- package/dist/__tests__/AgentManager.test.js +0 -1596
- package/dist/__tests__/AgentManager.test.js.map +0 -1
- package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js +0 -486
- package/dist/__tests__/adapters/IncrementalSessionRefresh.test.js.map +0 -1
- package/dist/__tests__/adapters/adapterProcessImports.test.js +0 -52
- package/dist/__tests__/adapters/adapterProcessImports.test.js.map +0 -1
- package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js +0 -247
- package/dist/__tests__/adapters/adapterSnapshotCandidates.test.js.map +0 -1
- package/dist/__tests__/capacity/anthropic.test.js +0 -115
- package/dist/__tests__/capacity/anthropic.test.js.map +0 -1
- package/dist/__tests__/capacity/boundaries.test.js +0 -45
- package/dist/__tests__/capacity/boundaries.test.js.map +0 -1
- package/dist/__tests__/capacity/claude.test.js +0 -485
- package/dist/__tests__/capacity/claude.test.js.map +0 -1
- package/dist/__tests__/capacity/codex.test.js +0 -339
- package/dist/__tests__/capacity/codex.test.js.map +0 -1
- package/dist/__tests__/capacity/devin.test.js +0 -239
- package/dist/__tests__/capacity/devin.test.js.map +0 -1
- package/dist/__tests__/capacity/index.test.js +0 -53
- package/dist/__tests__/capacity/index.test.js.map +0 -1
- package/dist/__tests__/capacity/openai.test.js +0 -687
- package/dist/__tests__/capacity/openai.test.js.map +0 -1
- package/dist/__tests__/capacity/wham.test.js +0 -159
- package/dist/__tests__/capacity/wham.test.js.map +0 -1
- package/dist/__tests__/capacity/zai.test.js +0 -212
- package/dist/__tests__/capacity/zai.test.js.map +0 -1
- package/dist/__tests__/fixtures.test.js +0 -218
- package/dist/__tests__/fixtures.test.js.map +0 -1
- package/dist/__tests__/harnesses/BoundedSummarySkip.test.js +0 -568
- package/dist/__tests__/harnesses/BoundedSummarySkip.test.js.map +0 -1
- package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js +0 -1089
- package/dist/__tests__/harnesses/SessionSummaryEquivalence.test.js.map +0 -1
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js +0 -143
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.js.map +0 -1
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js +0 -462
- package/dist/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/builtinAdapters.test.js +0 -33
- package/dist/__tests__/harnesses/builtinAdapters.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js +0 -79
- package/dist/__tests__/harnesses/claude/ClaudeAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js +0 -1881
- package/dist/__tests__/harnesses/claude/ClaudeCodeAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js +0 -425
- package/dist/__tests__/harnesses/claude/ClaudeSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js +0 -314
- package/dist/__tests__/harnesses/claude/ClaudeSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js +0 -49
- package/dist/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js +0 -76
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js +0 -173
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.js.map +0 -1
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js +0 -181
- package/dist/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexAdapter.test.js +0 -685
- package/dist/__tests__/harnesses/codex/CodexAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js +0 -463
- package/dist/__tests__/harnesses/codex/CodexSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js +0 -86
- package/dist/__tests__/harnesses/codex/CodexSessionMapping.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js +0 -254
- package/dist/__tests__/harnesses/codex/CodexSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js +0 -121
- package/dist/__tests__/harnesses/codex/durable/CodexCliProbe.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js +0 -84
- package/dist/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js +0 -128
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js +0 -246
- package/dist/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.js.map +0 -1
- package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js +0 -384
- package/dist/__tests__/harnesses/codex/durable/CodexPrintRunner.test.js.map +0 -1
- package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js +0 -659
- package/dist/__tests__/harnesses/copilot/CopilotAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js +0 -290
- package/dist/__tests__/harnesses/copilot/CopilotRefreshIO.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinAdapter.test.js +0 -597
- package/dist/__tests__/harnesses/devin/DevinAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +0 -99
- package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js +0 -192
- package/dist/__tests__/harnesses/devin/DevinSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js +0 -407
- package/dist/__tests__/harnesses/devin/DevinSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/devin/fixtures.js +0 -95
- package/dist/__tests__/harnesses/devin/fixtures.js.map +0 -1
- package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +0 -1454
- package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js +0 -491
- package/dist/__tests__/harnesses/gemini/GeminiSessionJsonl.test.js.map +0 -1
- package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js +0 -399
- package/dist/__tests__/harnesses/gemini/GeminiSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js +0 -56
- package/dist/__tests__/harnesses/grok/GrokAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js +0 -421
- package/dist/__tests__/harnesses/grok/GrokCliAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js +0 -167
- package/dist/__tests__/harnesses/grok/GrokIncrementalRefresh.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js +0 -133
- package/dist/__tests__/harnesses/grok/GrokSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js +0 -301
- package/dist/__tests__/harnesses/grok/GrokSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js +0 -662
- package/dist/__tests__/harnesses/kiro/KiroAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseAdapter.test.js +0 -247
- package/dist/__tests__/harnesses/muse/MuseAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js +0 -81
- package/dist/__tests__/harnesses/muse/MuseAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js +0 -185
- package/dist/__tests__/harnesses/muse/MuseSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js +0 -328
- package/dist/__tests__/harnesses/muse/MuseSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js +0 -213
- package/dist/__tests__/harnesses/opencode/OpenCodeAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +0 -108
- package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js +0 -94
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.js.map +0 -1
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js +0 -147
- package/dist/__tests__/harnesses/opencode/OpenCodeSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiAdapter.test.js +0 -367
- package/dist/__tests__/harnesses/pi/PiAdapter.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js +0 -382
- package/dist/__tests__/harnesses/pi/PiDiscoveryIO.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiSessionParser.test.js +0 -416
- package/dist/__tests__/harnesses/pi/PiSessionParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js +0 -108
- package/dist/__tests__/harnesses/pi/PiSessionTracker.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js +0 -70
- package/dist/__tests__/harnesses/pi/durable/PiCliProbe.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js +0 -43
- package/dist/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js +0 -192
- package/dist/__tests__/harnesses/pi/durable/PiPrintAgentService.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js +0 -119
- package/dist/__tests__/harnesses/pi/durable/PiPrintProtocol.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js +0 -382
- package/dist/__tests__/harnesses/pi/durable/PiPrintRunner.test.js.map +0 -1
- package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js +0 -34
- package/dist/__tests__/harnesses/pi/durable/PiStreamParser.test.js.map +0 -1
- package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js +0 -446
- package/dist/__tests__/harnesses/readiness/AgentReadiness.test.js.map +0 -1
- package/dist/__tests__/harnesses/runtimeProfiles.test.js +0 -101
- package/dist/__tests__/harnesses/runtimeProfiles.test.js.map +0 -1
- package/dist/__tests__/print/DurableAgent.test.js +0 -15
- package/dist/__tests__/print/DurableAgent.test.js.map +0 -1
- package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js +0 -186
- package/dist/__tests__/print/DurableAgentRepository.sqlite.test.js.map +0 -1
- package/dist/__tests__/print/DurableAgentRepository.test.js +0 -249
- package/dist/__tests__/print/DurableAgentRepository.test.js.map +0 -1
- package/dist/__tests__/readiness-fixtures.test.js +0 -54
- package/dist/__tests__/readiness-fixtures.test.js.map +0 -1
- package/dist/__tests__/runtime/AgentRuntime.test.js +0 -13
- package/dist/__tests__/runtime/AgentRuntime.test.js.map +0 -1
- package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js +0 -164
- package/dist/__tests__/runtime/HerdrAgentDiscovery.test.js.map +0 -1
- package/dist/__tests__/runtime/HerdrAgentRuntime.test.js +0 -488
- package/dist/__tests__/runtime/HerdrAgentRuntime.test.js.map +0 -1
- package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +0 -637
- package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +0 -1
- package/dist/__tests__/terminal/GhosttyBackend.test.js +0 -334
- package/dist/__tests__/terminal/GhosttyBackend.test.js.map +0 -1
- package/dist/__tests__/terminal/TerminalFocusManager.test.js +0 -253
- package/dist/__tests__/terminal/TerminalFocusManager.test.js.map +0 -1
- package/dist/__tests__/terminal/TmuxManager.test.js +0 -168
- package/dist/__tests__/terminal/TmuxManager.test.js.map +0 -1
- package/dist/__tests__/terminal/TtyWriter.test.js +0 -386
- package/dist/__tests__/terminal/TtyWriter.test.js.map +0 -1
- package/dist/__tests__/utils/AgentRegistry.test.js +0 -636
- package/dist/__tests__/utils/AgentRegistry.test.js.map +0 -1
- package/dist/__tests__/utils/IncrementalJsonlSummary.test.js +0 -650
- package/dist/__tests__/utils/IncrementalJsonlSummary.test.js.map +0 -1
- package/dist/__tests__/utils/agent-requests.test.js +0 -90
- package/dist/__tests__/utils/agent-requests.test.js.map +0 -1
- package/dist/__tests__/utils/conversationTail.bench.test.js +0 -258
- package/dist/__tests__/utils/conversationTail.bench.test.js.map +0 -1
- package/dist/__tests__/utils/conversationTailParity.test.js +0 -588
- package/dist/__tests__/utils/conversationTailParity.test.js.map +0 -1
- package/dist/__tests__/utils/jsonlTail.test.js +0 -360
- package/dist/__tests__/utils/jsonlTail.test.js.map +0 -1
- package/dist/__tests__/utils/matching.test.js +0 -324
- package/dist/__tests__/utils/matching.test.js.map +0 -1
- package/dist/__tests__/utils/matchingConstants.test.js +0 -35
- package/dist/__tests__/utils/matchingConstants.test.js.map +0 -1
- package/dist/__tests__/utils/process.test.js +0 -818
- package/dist/__tests__/utils/process.test.js.map +0 -1
- package/dist/__tests__/utils/session.test.js +0 -175
- package/dist/__tests__/utils/session.test.js.map +0 -1
- package/project.json +0 -29
- package/scripts/benchmark-cold-start.mjs +0 -350
- package/src/AgentManager.ts +0 -530
- package/src/__tests__/AgentManager.test.ts +0 -1483
- package/src/__tests__/adapters/IncrementalSessionRefresh.test.ts +0 -437
- package/src/__tests__/adapters/adapterProcessImports.test.ts +0 -58
- package/src/__tests__/adapters/adapterSnapshotCandidates.test.ts +0 -243
- package/src/__tests__/capacity/anthropic.test.ts +0 -105
- package/src/__tests__/capacity/boundaries.test.ts +0 -36
- package/src/__tests__/capacity/claude.test.ts +0 -462
- package/src/__tests__/capacity/codex.test.ts +0 -311
- package/src/__tests__/capacity/devin.test.ts +0 -210
- package/src/__tests__/capacity/fixtures/claude-credentials.json +0 -7
- package/src/__tests__/capacity/fixtures/claude-usage-malformed.json +0 -1
- package/src/__tests__/capacity/fixtures/claude-usage-partial.json +0 -15
- package/src/__tests__/capacity/fixtures/claude-usage.json +0 -63
- package/src/__tests__/capacity/fixtures/devin-config.json +0 -6
- package/src/__tests__/capacity/fixtures/devin-credentials.toml +0 -4
- package/src/__tests__/capacity/fixtures/devin-quota-nonplan.json +0 -5
- package/src/__tests__/capacity/fixtures/devin-quota.json +0 -10
- package/src/__tests__/capacity/fixtures/openai-auth.json +0 -6
- package/src/__tests__/capacity/fixtures/openai-codex-auth.json +0 -9
- package/src/__tests__/capacity/fixtures/openai-usage-completions.json +0 -67
- package/src/__tests__/capacity/fixtures/openai-usage-responses.json +0 -20
- package/src/__tests__/capacity/fixtures/wham-usage.json +0 -45
- package/src/__tests__/capacity/fixtures/zai-auth.json +0 -6
- package/src/__tests__/capacity/fixtures/zai-quota-invalid.json +0 -7
- package/src/__tests__/capacity/fixtures/zai-quota.json +0 -38
- package/src/__tests__/capacity/index.test.ts +0 -54
- package/src/__tests__/capacity/openai.test.ts +0 -571
- package/src/__tests__/capacity/wham.test.ts +0 -122
- package/src/__tests__/capacity/zai.test.ts +0 -151
- package/src/__tests__/fixtures.test.ts +0 -245
- package/src/__tests__/harnesses/BoundedSummarySkip.test.ts +0 -496
- package/src/__tests__/harnesses/SessionSummaryEquivalence.test.ts +0 -726
- package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.subprocess.test.ts +0 -133
- package/src/__tests__/harnesses/antigravity/AntigravityCliAdapter.test.ts +0 -396
- package/src/__tests__/harnesses/builtinAdapters.test.ts +0 -33
- package/src/__tests__/harnesses/claude/ClaudeAgentMapper.test.ts +0 -84
- package/src/__tests__/harnesses/claude/ClaudeCodeAdapter.test.ts +0 -1793
- package/src/__tests__/harnesses/claude/ClaudeSessionLocator.test.ts +0 -423
- package/src/__tests__/harnesses/claude/ClaudeSessionParser.test.ts +0 -300
- package/src/__tests__/harnesses/claude/durable/ClaudeCliProbe.test.ts +0 -34
- package/src/__tests__/harnesses/claude/durable/ClaudePrintAgent.integration.test.ts +0 -61
- package/src/__tests__/harnesses/claude/durable/ClaudePrintAgentService.test.ts +0 -129
- package/src/__tests__/harnesses/claude/durable/ClaudePrintRunner.test.ts +0 -152
- package/src/__tests__/harnesses/codex/CodexAdapter.test.ts +0 -652
- package/src/__tests__/harnesses/codex/CodexSessionLocator.test.ts +0 -419
- package/src/__tests__/harnesses/codex/CodexSessionMapping.test.ts +0 -63
- package/src/__tests__/harnesses/codex/CodexSessionParser.test.ts +0 -192
- package/src/__tests__/harnesses/codex/durable/CodexCliProbe.test.ts +0 -80
- package/src/__tests__/harnesses/codex/durable/CodexDurableAgentRepository.test.ts +0 -65
- package/src/__tests__/harnesses/codex/durable/CodexPrintAgent.integration.test.ts +0 -104
- package/src/__tests__/harnesses/codex/durable/CodexPrintAgentService.test.ts +0 -201
- package/src/__tests__/harnesses/codex/durable/CodexPrintRunner.test.ts +0 -299
- package/src/__tests__/harnesses/copilot/CopilotAdapter.test.ts +0 -614
- package/src/__tests__/harnesses/copilot/CopilotRefreshIO.test.ts +0 -270
- package/src/__tests__/harnesses/devin/DevinAdapter.test.ts +0 -290
- package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +0 -101
- package/src/__tests__/harnesses/devin/DevinSessionLocator.test.ts +0 -139
- package/src/__tests__/harnesses/devin/DevinSessionParser.test.ts +0 -212
- package/src/__tests__/harnesses/devin/fixtures.ts +0 -144
- package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +0 -1336
- package/src/__tests__/harnesses/gemini/GeminiSessionJsonl.test.ts +0 -402
- package/src/__tests__/harnesses/gemini/GeminiSessionLocator.test.ts +0 -396
- package/src/__tests__/harnesses/grok/GrokAgentMapper.test.ts +0 -57
- package/src/__tests__/harnesses/grok/GrokCliAdapter.test.ts +0 -376
- package/src/__tests__/harnesses/grok/GrokIncrementalRefresh.test.ts +0 -170
- package/src/__tests__/harnesses/grok/GrokSessionLocator.test.ts +0 -106
- package/src/__tests__/harnesses/grok/GrokSessionParser.test.ts +0 -230
- package/src/__tests__/harnesses/kiro/KiroAdapter.test.ts +0 -552
- package/src/__tests__/harnesses/muse/MuseAdapter.test.ts +0 -197
- package/src/__tests__/harnesses/muse/MuseAgentMapper.test.ts +0 -83
- package/src/__tests__/harnesses/muse/MuseSessionLocator.test.ts +0 -177
- package/src/__tests__/harnesses/muse/MuseSessionParser.test.ts +0 -279
- package/src/__tests__/harnesses/opencode/OpenCodeAdapter.test.ts +0 -215
- package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +0 -101
- package/src/__tests__/harnesses/opencode/OpenCodeSessionLocator.test.ts +0 -84
- package/src/__tests__/harnesses/opencode/OpenCodeSessionParser.test.ts +0 -149
- package/src/__tests__/harnesses/pi/PiAdapter.test.ts +0 -325
- package/src/__tests__/harnesses/pi/PiDiscoveryIO.test.ts +0 -337
- package/src/__tests__/harnesses/pi/PiSessionParser.test.ts +0 -280
- package/src/__tests__/harnesses/pi/PiSessionTracker.test.ts +0 -79
- package/src/__tests__/harnesses/pi/durable/PiCliProbe.test.ts +0 -50
- package/src/__tests__/harnesses/pi/durable/PiDurableAgentRepository.test.ts +0 -33
- package/src/__tests__/harnesses/pi/durable/PiPrintAgentService.test.ts +0 -138
- package/src/__tests__/harnesses/pi/durable/PiPrintProtocol.test.ts +0 -71
- package/src/__tests__/harnesses/pi/durable/PiPrintRunner.test.ts +0 -252
- package/src/__tests__/harnesses/pi/durable/PiStreamParser.test.ts +0 -26
- package/src/__tests__/harnesses/readiness/AgentReadiness.test.ts +0 -362
- package/src/__tests__/harnesses/runtimeProfiles.test.ts +0 -123
- package/src/__tests__/print/DurableAgent.test.ts +0 -15
- package/src/__tests__/print/DurableAgentRepository.sqlite.test.ts +0 -128
- package/src/__tests__/print/DurableAgentRepository.test.ts +0 -184
- package/src/__tests__/readiness-fixtures.test.ts +0 -79
- package/src/__tests__/runtime/AgentRuntime.test.ts +0 -8
- package/src/__tests__/runtime/HerdrAgentDiscovery.test.ts +0 -131
- package/src/__tests__/runtime/HerdrAgentRuntime.test.ts +0 -377
- package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +0 -590
- package/src/__tests__/terminal/GhosttyBackend.test.ts +0 -271
- package/src/__tests__/terminal/TerminalFocusManager.test.ts +0 -280
- package/src/__tests__/terminal/TmuxManager.test.ts +0 -185
- package/src/__tests__/terminal/TtyWriter.test.ts +0 -454
- package/src/__tests__/utils/AgentRegistry.test.ts +0 -532
- package/src/__tests__/utils/IncrementalJsonlSummary.test.ts +0 -414
- package/src/__tests__/utils/agent-requests.test.ts +0 -94
- package/src/__tests__/utils/conversationTail.bench.test.ts +0 -193
- package/src/__tests__/utils/conversationTailParity.test.ts +0 -365
- package/src/__tests__/utils/jsonlTail.test.ts +0 -317
- package/src/__tests__/utils/matching.test.ts +0 -234
- package/src/__tests__/utils/matchingConstants.test.ts +0 -40
- package/src/__tests__/utils/process.test.ts +0 -596
- package/src/__tests__/utils/session.test.ts +0 -158
- package/src/adapters/AgentAdapter.ts +0 -255
- package/src/capacity/index.ts +0 -127
- package/src/capacity/providers/anthropic.ts +0 -198
- package/src/capacity/providers/devin.ts +0 -121
- package/src/capacity/providers/openai-platform.ts +0 -150
- package/src/capacity/providers/openai-subscription.ts +0 -184
- package/src/capacity/providers/zai.ts +0 -155
- package/src/capacity/sources/claude.ts +0 -30
- package/src/capacity/sources/codex.ts +0 -251
- package/src/capacity/sources/devin.ts +0 -49
- package/src/capacity/sources/pi.ts +0 -131
- package/src/capacity/types.ts +0 -29
- package/src/database/connection.ts +0 -96
- package/src/database/index.ts +0 -7
- package/src/database/migrations/001_initial.sql +0 -12
- package/src/database/migrations/002_pins.sql +0 -1
- package/src/database/migrations/003_durable_agents.sql +0 -43
- package/src/database/migrations/004_codex_durable_sessions.sql +0 -1
- package/src/database/migrations/005_agent_runtime.sql +0 -2
- package/src/database/schema.ts +0 -64
- package/src/durable/DurableAgent.ts +0 -139
- package/src/durable/DurableAgentRepository.ts +0 -485
- package/src/durable/process.ts +0 -29
- package/src/durable/run.ts +0 -84
- package/src/durable/utils.ts +0 -66
- package/src/fixtures/bundle.ts +0 -130
- package/src/fixtures/capture.ts +0 -364
- package/src/harnesses/antigravity/AntigravityAgentMapper.ts +0 -34
- package/src/harnesses/antigravity/AntigravityCliAdapter.ts +0 -126
- package/src/harnesses/antigravity/AntigravitySessionLocator.ts +0 -75
- package/src/harnesses/antigravity/AntigravitySessionParser.ts +0 -252
- package/src/harnesses/claude/ClaudeAgentMapper.ts +0 -55
- package/src/harnesses/claude/ClaudeCodeAdapter.ts +0 -175
- package/src/harnesses/claude/ClaudeSessionLocator.ts +0 -358
- package/src/harnesses/claude/ClaudeSessionParser.ts +0 -524
- package/src/harnesses/claude/credentials.ts +0 -122
- package/src/harnesses/claude/durable/ClaudeCliProbe.ts +0 -57
- package/src/harnesses/claude/durable/ClaudePrintAgentService.ts +0 -79
- package/src/harnesses/claude/durable/ClaudePrintRunner.ts +0 -102
- package/src/harnesses/claude/durable/ClaudeStreamParser.ts +0 -108
- package/src/harnesses/claude/readiness.ts +0 -69
- package/src/harnesses/codex/CodexAdapter.ts +0 -337
- package/src/harnesses/codex/CodexAgentMapper.ts +0 -26
- package/src/harnesses/codex/CodexSessionLocator.ts +0 -509
- package/src/harnesses/codex/CodexSessionMapping.ts +0 -89
- package/src/harnesses/codex/CodexSessionParser.ts +0 -462
- package/src/harnesses/codex/credentials.ts +0 -81
- package/src/harnesses/codex/durable/CodexCliProbe.ts +0 -68
- package/src/harnesses/codex/durable/CodexPrintAgentService.ts +0 -79
- package/src/harnesses/codex/durable/CodexPrintRunner.ts +0 -104
- package/src/harnesses/codex/durable/CodexStreamParser.ts +0 -117
- package/src/harnesses/codex/readiness.ts +0 -72
- package/src/harnesses/copilot/CopilotAdapter.ts +0 -161
- package/src/harnesses/copilot/CopilotAgentMapper.ts +0 -27
- package/src/harnesses/copilot/CopilotSessionLocator.ts +0 -161
- package/src/harnesses/copilot/CopilotSessionParser.ts +0 -380
- package/src/harnesses/copilot/readiness.ts +0 -33
- package/src/harnesses/devin/DevinAdapter.ts +0 -212
- package/src/harnesses/devin/DevinAgentMapper.ts +0 -39
- package/src/harnesses/devin/DevinSessionLocator.ts +0 -230
- package/src/harnesses/devin/DevinSessionParser.ts +0 -227
- package/src/harnesses/devin/credentials.ts +0 -88
- package/src/harnesses/devin/readiness.ts +0 -36
- package/src/harnesses/gemini/GeminiAgentMapper.ts +0 -27
- package/src/harnesses/gemini/GeminiCliAdapter.ts +0 -272
- package/src/harnesses/gemini/GeminiSessionLocator.ts +0 -394
- package/src/harnesses/gemini/GeminiSessionParser.ts +0 -395
- package/src/harnesses/gemini/fileSignature.ts +0 -10
- package/src/harnesses/grok/GrokAgentMapper.ts +0 -32
- package/src/harnesses/grok/GrokCliAdapter.ts +0 -126
- package/src/harnesses/grok/GrokSessionLocator.ts +0 -179
- package/src/harnesses/grok/GrokSessionParser.ts +0 -251
- package/src/harnesses/index.ts +0 -32
- package/src/harnesses/kiro/KiroAdapter.ts +0 -143
- package/src/harnesses/kiro/KiroAgentMapper.ts +0 -34
- package/src/harnesses/kiro/KiroSessionLocator.ts +0 -143
- package/src/harnesses/kiro/KiroSessionParser.ts +0 -376
- package/src/harnesses/muse/MuseAdapter.ts +0 -157
- package/src/harnesses/muse/MuseAgentMapper.ts +0 -33
- package/src/harnesses/muse/MuseSessionLocator.ts +0 -286
- package/src/harnesses/muse/MuseSessionParser.ts +0 -435
- package/src/harnesses/muse/readiness.ts +0 -38
- package/src/harnesses/opencode/OpenCodeAdapter.ts +0 -110
- package/src/harnesses/opencode/OpenCodeAgentMapper.ts +0 -49
- package/src/harnesses/opencode/OpenCodeSessionLocator.ts +0 -151
- package/src/harnesses/opencode/OpenCodeSessionParser.ts +0 -146
- package/src/harnesses/opencode/readiness.ts +0 -48
- package/src/harnesses/pi/PiAdapter.ts +0 -197
- package/src/harnesses/pi/PiAgentMapper.ts +0 -27
- package/src/harnesses/pi/PiSessionLocator.ts +0 -288
- package/src/harnesses/pi/PiSessionParser.ts +0 -488
- package/src/harnesses/pi/PiSessionTracker.ts +0 -87
- package/src/harnesses/pi/credentials.ts +0 -129
- package/src/harnesses/pi/durable/PiCliProbe.ts +0 -56
- package/src/harnesses/pi/durable/PiPrintAgentService.ts +0 -77
- package/src/harnesses/pi/durable/PiPrintProtocol.ts +0 -41
- package/src/harnesses/pi/durable/PiPrintRunner.ts +0 -95
- package/src/harnesses/pi/durable/PiStreamParser.ts +0 -94
- package/src/harnesses/pi/readiness.ts +0 -104
- package/src/harnesses/readiness/AgentReadiness.ts +0 -91
- package/src/harnesses/readiness/checks.ts +0 -336
- package/src/harnesses/readiness/types.ts +0 -90
- package/src/harnesses/runtimeProfiles.ts +0 -105
- package/src/harnesses/shared.ts +0 -124
- package/src/index.ts +0 -70
- package/src/runtime/ManagedAgentRuntime.ts +0 -253
- package/src/runtime/RuntimeFactory.ts +0 -13
- package/src/runtime/errors.ts +0 -50
- package/src/runtime/herdr/HerdrAgentDiscovery.ts +0 -166
- package/src/runtime/herdr/HerdrAgentRuntime.ts +0 -216
- package/src/runtime/herdr/HerdrCliClient.ts +0 -78
- package/src/runtime/herdr/HerdrErrors.ts +0 -9
- package/src/runtime/herdr/HerdrResponseParsers.ts +0 -86
- package/src/runtime/herdr/HerdrRuntimeRef.ts +0 -41
- package/src/runtime/tmux/PidPolling.ts +0 -34
- package/src/runtime/tmux/TmuxAgentRuntime.ts +0 -113
- package/src/runtime/tmux/TmuxManager.ts +0 -102
- package/src/runtime/tmux/TmuxRuntimeRef.ts +0 -9
- package/src/runtime/types.ts +0 -56
- package/src/terminal/TerminalFocusManager.ts +0 -52
- package/src/terminal/TtyWriter.ts +0 -26
- package/src/terminal/backends/ghostty.ts +0 -180
- package/src/terminal/backends/index.ts +0 -23
- package/src/terminal/backends/iterm2.ts +0 -126
- package/src/terminal/backends/shared.ts +0 -47
- package/src/terminal/backends/terminal-app.ts +0 -122
- package/src/terminal/backends/tmux.ts +0 -62
- package/src/terminal/backends/wezterm.ts +0 -65
- package/src/terminal/types.ts +0 -23
- package/src/utils/AgentRegistry.ts +0 -351
- package/src/utils/IncrementalJsonlSummary.ts +0 -306
- package/src/utils/agent-requests.ts +0 -28
- package/src/utils/applescript.ts +0 -10
- package/src/utils/jsonlTail.ts +0 -349
- package/src/utils/matching.ts +0 -96
- package/src/utils/matchingConstants.ts +0 -15
- package/src/utils/process.ts +0 -604
- package/src/utils/session.ts +0 -144
- package/src/utils/sortAgents.ts +0 -54
- package/tsconfig.json +0 -11
- package/vitest.config.ts +0 -20
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import type { Availability, CapacityWindow, ProviderCapacitySnapshot } from "../types.js";
|
|
2
|
-
|
|
3
|
-
const SESSION_DURATION_MINUTES = 5 * 60;
|
|
4
|
-
const WEEK_DURATION_MINUTES = 7 * 24 * 60;
|
|
5
|
-
const ANTHROPIC_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
6
|
-
|
|
7
|
-
export type AnthropicCapacityRequestOptions = {
|
|
8
|
-
fetch?: typeof globalThis.fetch;
|
|
9
|
-
timeoutMs?: number;
|
|
10
|
-
now?: () => Date;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function record(value: unknown): Record<string, unknown> | null {
|
|
14
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
15
|
-
? (value as Record<string, unknown>)
|
|
16
|
-
: null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function percent(value: unknown): number | null {
|
|
20
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 100
|
|
21
|
-
? value
|
|
22
|
-
: null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function nonEmptyText(value: unknown): string | null {
|
|
26
|
-
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function resetTime(value: unknown): string | null {
|
|
30
|
-
if (typeof value !== "string") return null;
|
|
31
|
-
const milliseconds = Date.parse(value);
|
|
32
|
-
return Number.isNaN(milliseconds) ? null : new Date(milliseconds).toISOString();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function usageWindow(
|
|
36
|
-
value: unknown,
|
|
37
|
-
id: string,
|
|
38
|
-
label: string,
|
|
39
|
-
durationMinutes: number,
|
|
40
|
-
): CapacityWindow | null {
|
|
41
|
-
const input = record(value);
|
|
42
|
-
if (!input) return null;
|
|
43
|
-
return {
|
|
44
|
-
id,
|
|
45
|
-
label,
|
|
46
|
-
durationMinutes,
|
|
47
|
-
usedPercent: percent(input.utilization),
|
|
48
|
-
resetsAt: resetTime(input.resets_at),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function slug(value: string): string {
|
|
53
|
-
return value
|
|
54
|
-
.toLowerCase()
|
|
55
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
56
|
-
.replace(/^-|-$/g, "");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function scopedWindows(value: unknown): CapacityWindow[] {
|
|
60
|
-
if (!Array.isArray(value)) return [];
|
|
61
|
-
const seen = new Set<string>();
|
|
62
|
-
const windows: CapacityWindow[] = [];
|
|
63
|
-
for (const entry of value) {
|
|
64
|
-
const limit = record(entry);
|
|
65
|
-
const model = record(record(limit?.scope)?.model);
|
|
66
|
-
const name = nonEmptyText(model?.display_name);
|
|
67
|
-
const identity = nonEmptyText(model?.id) ?? name;
|
|
68
|
-
if (limit?.kind !== "weekly_scoped" || limit.group !== "weekly" || !name || !identity) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
const modelSlug = slug(identity);
|
|
72
|
-
if (!modelSlug || modelSlug === "all-models" || modelSlug.endsWith("-all-models")) continue;
|
|
73
|
-
const id = `claude:weekly:${modelSlug}`;
|
|
74
|
-
if (seen.has(id)) continue;
|
|
75
|
-
seen.add(id);
|
|
76
|
-
windows.push({
|
|
77
|
-
id,
|
|
78
|
-
label: `${name} weekly`,
|
|
79
|
-
durationMinutes: WEEK_DURATION_MINUTES,
|
|
80
|
-
usedPercent: percent(limit.percent),
|
|
81
|
-
resetsAt: resetTime(limit.resets_at),
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return windows;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function finiteNumber(value: unknown): number | null {
|
|
88
|
-
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function extraUsageWindow(value: unknown): CapacityWindow | null {
|
|
92
|
-
const extra = record(value);
|
|
93
|
-
if (!extra || extra.is_enabled !== true) return null;
|
|
94
|
-
const limitMinor = finiteNumber(extra.monthly_limit);
|
|
95
|
-
const usedMinor = finiteNumber(extra.used_credits);
|
|
96
|
-
if (limitMinor === null || usedMinor === null) return null;
|
|
97
|
-
const total = limitMinor / 100;
|
|
98
|
-
const current = usedMinor / 100;
|
|
99
|
-
const currency = nonEmptyText(extra.currency)?.toUpperCase() ?? "USD";
|
|
100
|
-
return {
|
|
101
|
-
id: "claude:extra-usage",
|
|
102
|
-
label: `Extra usage · ${currency}`,
|
|
103
|
-
limitType: "CREDIT_LIMIT",
|
|
104
|
-
durationMinutes: null,
|
|
105
|
-
usedPercent:
|
|
106
|
-
percent(extra.utilization) ??
|
|
107
|
-
(total > 0 ? Math.max(0, Math.min(100, (current / total) * 100)) : null),
|
|
108
|
-
resetsAt: null,
|
|
109
|
-
total,
|
|
110
|
-
current,
|
|
111
|
-
remaining: Math.max(0, total - current),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function availability(windows: CapacityWindow[]): Availability {
|
|
116
|
-
const known = windows.flatMap((window) =>
|
|
117
|
-
window.usedPercent === null ? [] : [window.usedPercent],
|
|
118
|
-
);
|
|
119
|
-
if (known.length === 0) return "unknown";
|
|
120
|
-
return known.some((used) => used < 100) ? "yes" : "no";
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function retryAfterTime(response: Response, now: Date): string | null {
|
|
124
|
-
const raw = response.headers.get("Retry-After")?.trim();
|
|
125
|
-
if (!raw) return null;
|
|
126
|
-
const seconds = Number(raw);
|
|
127
|
-
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
128
|
-
return new Date(now.getTime() + seconds * 1000).toISOString();
|
|
129
|
-
}
|
|
130
|
-
const milliseconds = Date.parse(raw);
|
|
131
|
-
return Number.isNaN(milliseconds) ? null : new Date(milliseconds).toISOString();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function parseAnthropicCapacity(raw: unknown): ProviderCapacitySnapshot {
|
|
135
|
-
const input = record(raw);
|
|
136
|
-
if (!input) throw new Error("Claude usage response is malformed");
|
|
137
|
-
const windows = [
|
|
138
|
-
usageWindow(input.five_hour, "session", "Session", SESSION_DURATION_MINUTES),
|
|
139
|
-
usageWindow(input.seven_day, "weekly", "Weekly", WEEK_DURATION_MINUTES),
|
|
140
|
-
usageWindow(
|
|
141
|
-
input.seven_day_sonnet,
|
|
142
|
-
"claude:sonnet:weekly",
|
|
143
|
-
"Sonnet weekly",
|
|
144
|
-
WEEK_DURATION_MINUTES,
|
|
145
|
-
),
|
|
146
|
-
usageWindow(input.seven_day_opus, "claude:opus:weekly", "Opus weekly", WEEK_DURATION_MINUTES),
|
|
147
|
-
...scopedWindows(input.limits),
|
|
148
|
-
extraUsageWindow(input.extra_usage),
|
|
149
|
-
].filter((window): window is CapacityWindow => window !== null);
|
|
150
|
-
return {
|
|
151
|
-
authenticated: true,
|
|
152
|
-
available: availability(windows),
|
|
153
|
-
windows,
|
|
154
|
-
creditsRemaining: null,
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export async function fetchAnthropicCapacity(
|
|
159
|
-
token: string,
|
|
160
|
-
options: AnthropicCapacityRequestOptions = {},
|
|
161
|
-
): Promise<ProviderCapacitySnapshot> {
|
|
162
|
-
let response: Response;
|
|
163
|
-
try {
|
|
164
|
-
response = await (options.fetch ?? globalThis.fetch)(ANTHROPIC_USAGE_URL, {
|
|
165
|
-
method: "GET",
|
|
166
|
-
headers: {
|
|
167
|
-
Accept: "application/json",
|
|
168
|
-
Authorization: `Bearer ${token}`,
|
|
169
|
-
"Content-Type": "application/json",
|
|
170
|
-
"User-Agent": "claude-code/2.1.0",
|
|
171
|
-
"anthropic-beta": "oauth-2025-04-20",
|
|
172
|
-
},
|
|
173
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
|
|
174
|
-
});
|
|
175
|
-
} catch {
|
|
176
|
-
throw new Error("Claude OAuth usage request failed");
|
|
177
|
-
}
|
|
178
|
-
if (response.status === 401) throw new Error("Claude OAuth request unauthorized (HTTP 401)");
|
|
179
|
-
if (response.status === 403) throw new Error("Claude OAuth request forbidden (HTTP 403)");
|
|
180
|
-
if (response.status === 429) {
|
|
181
|
-
const retryAt = retryAfterTime(response, options.now?.() ?? new Date());
|
|
182
|
-
throw new Error(
|
|
183
|
-
retryAt
|
|
184
|
-
? `Claude OAuth usage rate limited until ${retryAt}`
|
|
185
|
-
: "Claude OAuth usage rate limited (HTTP 429)",
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
if (!response.ok) {
|
|
189
|
-
throw new Error(`Claude OAuth usage request failed (HTTP ${response.status})`);
|
|
190
|
-
}
|
|
191
|
-
let raw: unknown;
|
|
192
|
-
try {
|
|
193
|
-
raw = await response.json();
|
|
194
|
-
} catch {
|
|
195
|
-
throw new Error("Claude usage response is malformed");
|
|
196
|
-
}
|
|
197
|
-
return parseAnthropicCapacity(raw);
|
|
198
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { Availability, CapacityWindow, ProviderCapacitySnapshot } from "../types.js";
|
|
2
|
-
import type { DevinCredential } from "../../harnesses/devin/credentials.js";
|
|
3
|
-
|
|
4
|
-
const DEVIN_WEBAPP_HOST = "https://app.devin.ai";
|
|
5
|
-
const DAY_MINUTES = 24 * 60;
|
|
6
|
-
const WEEK_MINUTES = 7 * 24 * 60;
|
|
7
|
-
|
|
8
|
-
type UnknownRecord = Record<string, unknown>;
|
|
9
|
-
|
|
10
|
-
export type DevinRequestOptions = {
|
|
11
|
-
fetch?: typeof globalThis.fetch;
|
|
12
|
-
timeoutMs?: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export class DevinHttpError extends Error {
|
|
16
|
-
constructor(
|
|
17
|
-
public readonly status: number,
|
|
18
|
-
message: string,
|
|
19
|
-
) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = "DevinHttpError";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function record(value: unknown): UnknownRecord | null {
|
|
26
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
27
|
-
? (value as UnknownRecord)
|
|
28
|
-
: null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function percent(value: unknown): number | null {
|
|
32
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
33
|
-
return Math.max(0, Math.min(100, value));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function timestamp(value: unknown): string | null {
|
|
37
|
-
if (typeof value !== "string" || !value) return null;
|
|
38
|
-
const ms = Date.parse(value);
|
|
39
|
-
return Number.isNaN(ms) ? null : new Date(ms).toISOString();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function finiteNumber(value: unknown): number | null {
|
|
43
|
-
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function availability(windows: CapacityWindow[]): Availability {
|
|
47
|
-
if (windows.length === 0) return "unknown";
|
|
48
|
-
return windows.some((window) => window.usedPercent !== null && window.usedPercent < 100)
|
|
49
|
-
? "yes"
|
|
50
|
-
: "no";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function parseDevinCapacity(raw: unknown): ProviderCapacitySnapshot {
|
|
54
|
-
const root = record(raw);
|
|
55
|
-
if (!root) throw new Error("Invalid Devin quota response");
|
|
56
|
-
|
|
57
|
-
if (root.is_quota_plan !== true || root.has_quota_allocation !== true) {
|
|
58
|
-
return {
|
|
59
|
-
authenticated: true,
|
|
60
|
-
available: "unknown",
|
|
61
|
-
windows: [],
|
|
62
|
-
creditsRemaining: null,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const windows: CapacityWindow[] = [];
|
|
67
|
-
if (root.hide_daily_quota !== true) {
|
|
68
|
-
windows.push({
|
|
69
|
-
id: "devin:daily",
|
|
70
|
-
label: "Daily",
|
|
71
|
-
durationMinutes: DAY_MINUTES,
|
|
72
|
-
usedPercent: percent(root.daily_percentage),
|
|
73
|
-
resetsAt: timestamp(root.daily_reset_at),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
windows.push({
|
|
77
|
-
id: "devin:weekly",
|
|
78
|
-
label: "Weekly",
|
|
79
|
-
durationMinutes: WEEK_MINUTES,
|
|
80
|
-
usedPercent: percent(root.weekly_percentage),
|
|
81
|
-
resetsAt: timestamp(root.weekly_reset_at),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
authenticated: true,
|
|
86
|
-
available: availability(windows),
|
|
87
|
-
windows,
|
|
88
|
-
creditsRemaining: finiteNumber(root.overage_balance),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function fetchDevinCapacity(
|
|
93
|
-
credential: DevinCredential,
|
|
94
|
-
options: DevinRequestOptions = {},
|
|
95
|
-
): Promise<ProviderCapacitySnapshot> {
|
|
96
|
-
const url = `${DEVIN_WEBAPP_HOST}/api/${encodeURIComponent(credential.orgId)}/billing/quota/usage`;
|
|
97
|
-
let response: Response;
|
|
98
|
-
try {
|
|
99
|
-
response = await (options.fetch ?? globalThis.fetch)(url, {
|
|
100
|
-
method: "GET",
|
|
101
|
-
headers: { Authorization: `Bearer ${credential.key}` },
|
|
102
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
|
|
103
|
-
});
|
|
104
|
-
} catch {
|
|
105
|
-
throw new Error("Devin quota request failed");
|
|
106
|
-
}
|
|
107
|
-
if (response.status !== 200) {
|
|
108
|
-
throw new DevinHttpError(
|
|
109
|
-
response.status,
|
|
110
|
-
`Devin quota request failed: HTTP ${response.status}`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
return parseDevinCapacity(await response.json());
|
|
115
|
-
} catch (error) {
|
|
116
|
-
if (error instanceof SyntaxError) {
|
|
117
|
-
throw new Error("Devin quota response is not valid JSON");
|
|
118
|
-
}
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import type { CapacityWindow, ProviderCapacitySnapshot } from "../types.js";
|
|
2
|
-
|
|
3
|
-
const OPENAI_USAGE_BASE_URL = "https://api.openai.com/v1/organization/usage";
|
|
4
|
-
const OPENAI_MODELS_URL = "https://api.openai.com/v1/models";
|
|
5
|
-
const OPENAI_USAGE_ENDPOINTS = ["completions", "responses"] as const;
|
|
6
|
-
const USAGE_WINDOW_DAYS = 7;
|
|
7
|
-
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
8
|
-
|
|
9
|
-
export type OpenAiUsageBucket = { startMs: number; tokens: number };
|
|
10
|
-
export type OpenAiPlatformCapacityOptions = {
|
|
11
|
-
checkedAt: string;
|
|
12
|
-
fetch?: typeof globalThis.fetch;
|
|
13
|
-
timeoutMs?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type UnknownRecord = Record<string, unknown>;
|
|
17
|
-
|
|
18
|
-
function record(value: unknown): UnknownRecord | null {
|
|
19
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
20
|
-
? (value as UnknownRecord)
|
|
21
|
-
: null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function finiteNumber(value: unknown): number | null {
|
|
25
|
-
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function bucketTokens(value: unknown): number {
|
|
29
|
-
const results = Array.isArray(value) ? value : [];
|
|
30
|
-
return results.reduce(
|
|
31
|
-
(total, entry) =>
|
|
32
|
-
total +
|
|
33
|
-
(finiteNumber(record(entry)?.input_tokens) ?? 0) +
|
|
34
|
-
(finiteNumber(record(entry)?.output_tokens) ?? 0),
|
|
35
|
-
0,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function parseOpenAiUsage(raw: unknown): OpenAiUsageBucket[] {
|
|
40
|
-
const data = record(raw)?.data;
|
|
41
|
-
if (!Array.isArray(data)) throw new Error("Invalid OpenAI usage response");
|
|
42
|
-
const buckets: OpenAiUsageBucket[] = [];
|
|
43
|
-
for (const entry of data) {
|
|
44
|
-
const seconds = finiteNumber(record(entry)?.aggregation_timestamp);
|
|
45
|
-
if (seconds === null) continue;
|
|
46
|
-
buckets.push({ startMs: seconds * 1000, tokens: bucketTokens(record(entry)?.results) });
|
|
47
|
-
}
|
|
48
|
-
return buckets;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function emptySnapshot(authenticated: boolean): ProviderCapacitySnapshot {
|
|
52
|
-
return {
|
|
53
|
-
authenticated,
|
|
54
|
-
available: "unknown",
|
|
55
|
-
windows: [],
|
|
56
|
-
creditsRemaining: null,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function buildOpenAiPlatformCapacity(
|
|
61
|
-
buckets: OpenAiUsageBucket[],
|
|
62
|
-
checkedAt: string,
|
|
63
|
-
): ProviderCapacitySnapshot {
|
|
64
|
-
const nowMs = Date.parse(checkedAt);
|
|
65
|
-
const todayStartMs = Math.floor(nowMs / DAY_MS) * DAY_MS;
|
|
66
|
-
const weekStartMs = todayStartMs - (USAGE_WINDOW_DAYS - 1) * DAY_MS;
|
|
67
|
-
let todayTokens = 0;
|
|
68
|
-
let weekTokens = 0;
|
|
69
|
-
for (const bucket of buckets) {
|
|
70
|
-
if (bucket.startMs === todayStartMs) todayTokens += bucket.tokens;
|
|
71
|
-
if (bucket.startMs >= weekStartMs) weekTokens += bucket.tokens;
|
|
72
|
-
}
|
|
73
|
-
const windows: CapacityWindow[] = [
|
|
74
|
-
{
|
|
75
|
-
id: "openai:tokens:today",
|
|
76
|
-
label: "Tokens · today (UTC)",
|
|
77
|
-
limitType: "TOKENS_LIMIT",
|
|
78
|
-
durationMinutes: 24 * 60,
|
|
79
|
-
usedPercent: null,
|
|
80
|
-
resetsAt: new Date(todayStartMs + DAY_MS).toISOString(),
|
|
81
|
-
total: null,
|
|
82
|
-
current: todayTokens,
|
|
83
|
-
remaining: null,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: "openai:tokens:week",
|
|
87
|
-
label: "Tokens · 7 days",
|
|
88
|
-
limitType: "TOKENS_LIMIT",
|
|
89
|
-
durationMinutes: USAGE_WINDOW_DAYS * 24 * 60,
|
|
90
|
-
usedPercent: null,
|
|
91
|
-
resetsAt: null,
|
|
92
|
-
total: null,
|
|
93
|
-
current: weekTokens,
|
|
94
|
-
remaining: null,
|
|
95
|
-
},
|
|
96
|
-
];
|
|
97
|
-
return {
|
|
98
|
-
authenticated: true,
|
|
99
|
-
available: "yes",
|
|
100
|
-
windows,
|
|
101
|
-
creditsRemaining: null,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function request(
|
|
106
|
-
url: string,
|
|
107
|
-
key: string,
|
|
108
|
-
options: OpenAiPlatformCapacityOptions,
|
|
109
|
-
): Promise<Response> {
|
|
110
|
-
try {
|
|
111
|
-
return await (options.fetch ?? globalThis.fetch)(url, {
|
|
112
|
-
method: "GET",
|
|
113
|
-
headers: { Authorization: `Bearer ${key}` },
|
|
114
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
|
|
115
|
-
});
|
|
116
|
-
} catch {
|
|
117
|
-
throw new Error("OpenAI usage request failed");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function verifyKey(key: string, options: OpenAiPlatformCapacityOptions): Promise<boolean> {
|
|
122
|
-
const response = await request(OPENAI_MODELS_URL, key, options);
|
|
123
|
-
return response.status !== 401;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function fetchOpenAiPlatformCapacity(
|
|
127
|
-
key: string,
|
|
128
|
-
options: OpenAiPlatformCapacityOptions,
|
|
129
|
-
): Promise<ProviderCapacitySnapshot> {
|
|
130
|
-
const endSeconds = Math.floor(Date.parse(options.checkedAt) / 1000);
|
|
131
|
-
const startSeconds = endSeconds - USAGE_WINDOW_DAYS * 24 * 60 * 60;
|
|
132
|
-
const query = `start_time=${startSeconds}&end_time=${endSeconds}`;
|
|
133
|
-
const payloads: unknown[] = [];
|
|
134
|
-
|
|
135
|
-
for (const endpoint of OPENAI_USAGE_ENDPOINTS) {
|
|
136
|
-
const response = await request(`${OPENAI_USAGE_BASE_URL}/${endpoint}?${query}`, key, options);
|
|
137
|
-
if (response.status === 401) return emptySnapshot(false);
|
|
138
|
-
if (response.status === 403) return emptySnapshot(await verifyKey(key, options));
|
|
139
|
-
if (response.status !== 200) {
|
|
140
|
-
throw new Error(`OpenAI usage request failed: HTTP ${response.status}`);
|
|
141
|
-
}
|
|
142
|
-
try {
|
|
143
|
-
payloads.push(await response.json());
|
|
144
|
-
} catch {
|
|
145
|
-
throw new Error("OpenAI usage response is not valid JSON");
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return buildOpenAiPlatformCapacity(payloads.flatMap(parseOpenAiUsage), options.checkedAt);
|
|
150
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import type { Availability, CapacityWindow, ProviderCapacitySnapshot } from "../types.js";
|
|
2
|
-
|
|
3
|
-
const WHAM_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
|
4
|
-
const OPENAI_WHOAMI_URL = "https://auth.openai.com/api/accounts/v1/user-auth-credential/whoami";
|
|
5
|
-
|
|
6
|
-
export type OpenAiSubscriptionCredential = {
|
|
7
|
-
access: string;
|
|
8
|
-
accountId: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type OpenAiSubscriptionCapacityOptions = {
|
|
12
|
-
fetch?: typeof globalThis.fetch;
|
|
13
|
-
timeoutMs?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type UnknownRecord = Record<string, unknown>;
|
|
17
|
-
|
|
18
|
-
function record(value: unknown): UnknownRecord | null {
|
|
19
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
20
|
-
? (value as UnknownRecord)
|
|
21
|
-
: null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function finiteNumber(value: unknown): number | null {
|
|
25
|
-
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function numericValue(value: unknown): number | null {
|
|
29
|
-
const direct = finiteNumber(value);
|
|
30
|
-
if (direct !== null) return direct;
|
|
31
|
-
if (typeof value !== "string" || value.trim().length === 0) return null;
|
|
32
|
-
const parsed = Number(value);
|
|
33
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function nonEmptyText(value: unknown): string | null {
|
|
37
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function resetTime(value: unknown): string | null {
|
|
41
|
-
const seconds = finiteNumber(value);
|
|
42
|
-
if (seconds !== null) return new Date(seconds * 1000).toISOString();
|
|
43
|
-
if (typeof value === "string" && !Number.isNaN(Date.parse(value))) {
|
|
44
|
-
return new Date(value).toISOString();
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function safeIdentifier(value: unknown): string | null {
|
|
50
|
-
const candidate = nonEmptyText(value);
|
|
51
|
-
if (!candidate || !/^[a-z][a-z0-9_-]{0,63}$/i.test(candidate)) return null;
|
|
52
|
-
if (/(?:account|token|secret|key)[_-]?\d{6,}/i.test(candidate)) return null;
|
|
53
|
-
return candidate;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function toRateWindow(value: unknown, id: string, label: string): CapacityWindow | null {
|
|
57
|
-
const input = record(value);
|
|
58
|
-
if (!input) return null;
|
|
59
|
-
const used = finiteNumber(input.used_percent);
|
|
60
|
-
const seconds = finiteNumber(input.limit_window_seconds);
|
|
61
|
-
return {
|
|
62
|
-
id,
|
|
63
|
-
label,
|
|
64
|
-
durationMinutes: seconds === null ? null : seconds / 60,
|
|
65
|
-
usedPercent: used,
|
|
66
|
-
resetsAt: resetTime(input.reset_at),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function extraWindows(value: unknown): CapacityWindow[] {
|
|
71
|
-
if (!Array.isArray(value)) return [];
|
|
72
|
-
return value.flatMap((entry, index) => {
|
|
73
|
-
const limit = record(entry);
|
|
74
|
-
if (!limit) return [];
|
|
75
|
-
const scope = safeIdentifier(limit.limit_name) ?? `extra-${index + 1}`;
|
|
76
|
-
const windows = record(limit.rate_limit) ?? limit;
|
|
77
|
-
return [
|
|
78
|
-
toRateWindow(windows.primary_window, `${scope}:primary`, `${scope} primary`),
|
|
79
|
-
toRateWindow(windows.secondary_window, `${scope}:secondary`, `${scope} secondary`),
|
|
80
|
-
].filter((window): window is CapacityWindow => window !== null);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function spendControlWindow(value: unknown): CapacityWindow | null {
|
|
85
|
-
const limit = record(record(value)?.individual_limit);
|
|
86
|
-
if (!limit) return null;
|
|
87
|
-
return {
|
|
88
|
-
id: "spend-control",
|
|
89
|
-
label: "Spend control",
|
|
90
|
-
durationMinutes: null,
|
|
91
|
-
usedPercent: finiteNumber(limit.used_percent),
|
|
92
|
-
resetsAt: resetTime(limit.reset_at),
|
|
93
|
-
limitType: "CREDIT_LIMIT",
|
|
94
|
-
total: numericValue(limit.limit),
|
|
95
|
-
current: numericValue(limit.used),
|
|
96
|
-
remaining: numericValue(limit.remaining),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function availability(windows: CapacityWindow[], spendControl: UnknownRecord | null): Availability {
|
|
101
|
-
if (spendControl?.reached === true) return "no";
|
|
102
|
-
return windows.some((window) => window.usedPercent !== null) ? "yes" : "unknown";
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function parseWhamUsage(raw: unknown): ProviderCapacitySnapshot {
|
|
106
|
-
const response = record(raw) ?? {};
|
|
107
|
-
const limits = record(response.rate_limit) ?? {};
|
|
108
|
-
const credits = record(response.credits) ?? {};
|
|
109
|
-
const spendControl = record(response.spend_control);
|
|
110
|
-
const windows = [
|
|
111
|
-
toRateWindow(limits.primary_window, "session", "Session"),
|
|
112
|
-
toRateWindow(limits.secondary_window, "weekly", "Weekly"),
|
|
113
|
-
...extraWindows(response.additional_rate_limits),
|
|
114
|
-
spendControlWindow(spendControl),
|
|
115
|
-
].filter((window): window is CapacityWindow => window !== null);
|
|
116
|
-
return {
|
|
117
|
-
authenticated: true,
|
|
118
|
-
available: availability(windows, spendControl),
|
|
119
|
-
windows,
|
|
120
|
-
creditsRemaining: finiteNumber(credits.balance),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export async function fetchOpenAiSubscriptionCapacity(
|
|
125
|
-
credential: OpenAiSubscriptionCredential,
|
|
126
|
-
options: OpenAiSubscriptionCapacityOptions = {},
|
|
127
|
-
): Promise<ProviderCapacitySnapshot> {
|
|
128
|
-
let response: Response;
|
|
129
|
-
try {
|
|
130
|
-
response = await (options.fetch ?? globalThis.fetch)(WHAM_USAGE_URL, {
|
|
131
|
-
method: "GET",
|
|
132
|
-
headers: {
|
|
133
|
-
Authorization: `Bearer ${credential.access}`,
|
|
134
|
-
"ChatGPT-Account-Id": credential.accountId,
|
|
135
|
-
},
|
|
136
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
|
|
137
|
-
});
|
|
138
|
-
} catch {
|
|
139
|
-
throw new Error("OpenAI usage request failed");
|
|
140
|
-
}
|
|
141
|
-
if (response.status === 401 || response.status === 403) {
|
|
142
|
-
return {
|
|
143
|
-
authenticated: false,
|
|
144
|
-
available: "unknown",
|
|
145
|
-
windows: [],
|
|
146
|
-
creditsRemaining: null,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
if (response.status !== 200) {
|
|
150
|
-
throw new Error(`OpenAI usage request failed: HTTP ${response.status}`);
|
|
151
|
-
}
|
|
152
|
-
let raw: unknown;
|
|
153
|
-
try {
|
|
154
|
-
raw = await response.json();
|
|
155
|
-
} catch {
|
|
156
|
-
throw new Error("OpenAI usage response is not valid JSON");
|
|
157
|
-
}
|
|
158
|
-
return parseWhamUsage(raw);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function fetchOpenAiPatAccountId(
|
|
162
|
-
token: string,
|
|
163
|
-
options: OpenAiSubscriptionCapacityOptions = {},
|
|
164
|
-
): Promise<string> {
|
|
165
|
-
let response: Response;
|
|
166
|
-
try {
|
|
167
|
-
response = await (options.fetch ?? globalThis.fetch)(OPENAI_WHOAMI_URL, {
|
|
168
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
169
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 5000),
|
|
170
|
-
});
|
|
171
|
-
} catch {
|
|
172
|
-
throw new Error("OpenAI account request failed");
|
|
173
|
-
}
|
|
174
|
-
if (!response.ok) throw new Error("OpenAI account request failed");
|
|
175
|
-
let raw: unknown;
|
|
176
|
-
try {
|
|
177
|
-
raw = await response.json();
|
|
178
|
-
} catch {
|
|
179
|
-
throw new Error("OpenAI account response is not valid JSON");
|
|
180
|
-
}
|
|
181
|
-
const accountId = nonEmptyText(record(raw)?.chatgpt_account_id);
|
|
182
|
-
if (!accountId) throw new Error("OpenAI account unavailable");
|
|
183
|
-
return accountId;
|
|
184
|
-
}
|