@elie-laloum/outpost 7.0.0 → 8.0.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/CHANGELOG.md +15 -0
- package/README.md +2 -0
- package/dist/adapters/agents/antigravity-adapter.js +3 -0
- package/dist/adapters/agents/antigravity-adapter.js.map +1 -1
- package/dist/adapters/agents/claude-adapter.js +3 -0
- package/dist/adapters/agents/claude-adapter.js.map +1 -1
- package/dist/adapters/agents/claude-events.js +25 -1
- package/dist/adapters/agents/claude-events.js.map +1 -1
- package/dist/adapters/agents/codex-adapter.js +3 -0
- package/dist/adapters/agents/codex-adapter.js.map +1 -1
- package/dist/adapters/agents/copilot-adapter.js +3 -0
- package/dist/adapters/agents/copilot-adapter.js.map +1 -1
- package/dist/adapters/agents/copilot-events.js +7 -3
- package/dist/adapters/agents/copilot-events.js.map +1 -1
- package/dist/adapters/agents/kimi-adapter.js +3 -0
- package/dist/adapters/agents/kimi-adapter.js.map +1 -1
- package/dist/adapters/agents/quota.constants.d.ts +7 -0
- package/dist/adapters/agents/quota.constants.js +31 -0
- package/dist/adapters/agents/quota.constants.js.map +1 -0
- package/dist/adapters/agents/quota.d.ts +1 -0
- package/dist/adapters/agents/quota.js +4 -0
- package/dist/adapters/agents/quota.js.map +1 -0
- package/dist/adapters/models/http-provider.js +8 -2
- package/dist/adapters/models/http-provider.js.map +1 -1
- package/dist/adapters/models/model.constants.d.ts +2 -0
- package/dist/adapters/models/model.constants.js +6 -0
- package/dist/adapters/models/model.constants.js.map +1 -1
- package/dist/adapters/models/stream-events.js +11 -7
- package/dist/adapters/models/stream-events.js.map +1 -1
- package/dist/application/agent-output.js +10 -1
- package/dist/application/agent-output.js.map +1 -1
- package/dist/application/agent-quota.d.ts +7 -0
- package/dist/application/agent-quota.js +33 -0
- package/dist/application/agent-quota.js.map +1 -0
- package/dist/application/agent-turn.js +25 -9
- package/dist/application/agent-turn.js.map +1 -1
- package/dist/application/dispatch-observation.js +10 -1
- package/dist/application/dispatch-observation.js.map +1 -1
- package/dist/application/execution.types.d.ts +2 -0
- package/dist/application/execution.types.js.map +1 -1
- package/dist/application/interactive-task-execution.d.ts +3 -0
- package/dist/application/interactive-task-execution.js +76 -0
- package/dist/application/interactive-task-execution.js.map +1 -0
- package/dist/application/interactive-task-protocol.d.ts +4 -0
- package/dist/application/interactive-task-protocol.js +56 -0
- package/dist/application/interactive-task-protocol.js.map +1 -0
- package/dist/application/interactive-task.constants.d.ts +4 -0
- package/dist/application/interactive-task.constants.js +7 -0
- package/dist/application/interactive-task.constants.js.map +1 -0
- package/dist/application/interactive-task.d.ts +3 -0
- package/dist/application/interactive-task.js +84 -0
- package/dist/application/interactive-task.js.map +1 -0
- package/dist/application/interactive-task.types.d.ts +44 -0
- package/dist/application/interactive-task.types.js +2 -0
- package/dist/application/interactive-task.types.js.map +1 -0
- package/dist/application/queue-worker.js +19 -1
- package/dist/application/queue-worker.js.map +1 -1
- package/dist/application/queued-task.js +17 -2
- package/dist/application/queued-task.js.map +1 -1
- package/dist/application/quota-resume.constants.d.ts +1 -0
- package/dist/application/quota-resume.constants.js +2 -0
- package/dist/application/quota-resume.constants.js.map +1 -0
- package/dist/application/quota-resume.d.ts +9 -0
- package/dist/application/quota-resume.js +34 -0
- package/dist/application/quota-resume.js.map +1 -0
- package/dist/application/quota-resume.types.d.ts +1 -0
- package/dist/application/quota-resume.types.js +2 -0
- package/dist/application/quota-resume.types.js.map +1 -0
- package/dist/application/recovery-retention-policy.js +1 -1
- package/dist/application/recovery-retention-policy.js.map +1 -1
- package/dist/application/recovery-retention.js +3 -3
- package/dist/application/recovery-retention.js.map +1 -1
- package/dist/application/recovery-retention.types.d.ts +1 -1
- package/dist/application/recovery-retention.types.js.map +1 -1
- package/dist/application/remote-workspace.js +2 -1
- package/dist/application/remote-workspace.js.map +1 -1
- package/dist/application/replay-recording.d.ts +2 -0
- package/dist/application/replay-recording.js +22 -0
- package/dist/application/replay-recording.js.map +1 -0
- package/dist/application/replay-turn.d.ts +4 -0
- package/dist/application/replay-turn.js +47 -0
- package/dist/application/replay-turn.js.map +1 -0
- package/dist/application/replay-workspace.d.ts +4 -0
- package/dist/application/replay-workspace.js +71 -0
- package/dist/application/replay-workspace.js.map +1 -0
- package/dist/application/replay-workspace.types.d.ts +6 -0
- package/dist/application/replay-workspace.types.js +2 -0
- package/dist/application/replay-workspace.types.js.map +1 -0
- package/dist/application/repository-fingerprint.d.ts +1 -0
- package/dist/application/repository-fingerprint.js +18 -0
- package/dist/application/repository-fingerprint.js.map +1 -0
- package/dist/application/sandbox-dispatch.js +2 -0
- package/dist/application/sandbox-dispatch.js.map +1 -1
- package/dist/application/speculation-checkpoint.js +19 -2
- package/dist/application/speculation-checkpoint.js.map +1 -1
- package/dist/application/speculation-checkpoint.types.d.ts +1 -1
- package/dist/application/speculation-checkpoint.types.js.map +1 -1
- package/dist/application/speculation-resume.js +21 -0
- package/dist/application/speculation-resume.js.map +1 -1
- package/dist/application/speculation-run.js +18 -1
- package/dist/application/speculation-run.js.map +1 -1
- package/dist/application/speculation.types.d.ts +7 -2
- package/dist/application/speculation.types.js.map +1 -1
- package/dist/application/tasks.d.ts +2 -2
- package/dist/application/tasks.js +11 -4
- package/dist/application/tasks.js.map +1 -1
- package/dist/application/tasks.types.d.ts +5 -0
- package/dist/application/tasks.types.js.map +1 -1
- package/dist/application/transport-inspection.constants.js +1 -0
- package/dist/application/transport-inspection.constants.js.map +1 -1
- package/dist/application/transport-retention.js +33 -1
- package/dist/application/transport-retention.js.map +1 -1
- package/dist/domain/agent-observation.js +1 -0
- package/dist/domain/agent-observation.js.map +1 -1
- package/dist/domain/agent.types.d.ts +8 -1
- package/dist/domain/agent.types.js.map +1 -1
- package/dist/domain/errors.types.d.ts +1 -1
- package/dist/domain/errors.types.js.map +1 -1
- package/dist/domain/observation.types.d.ts +6 -1
- package/dist/domain/observation.types.js.map +1 -1
- package/dist/domain/quota.constants.d.ts +1 -0
- package/dist/domain/quota.constants.js +2 -0
- package/dist/domain/quota.constants.js.map +1 -0
- package/dist/domain/quota.d.ts +4 -0
- package/dist/domain/quota.js +28 -0
- package/dist/domain/quota.js.map +1 -0
- package/dist/domain/quota.types.d.ts +7 -0
- package/dist/domain/quota.types.js +2 -0
- package/dist/domain/quota.types.js.map +1 -0
- package/dist/domain/replay.constants.d.ts +11 -0
- package/dist/domain/replay.constants.js +42 -0
- package/dist/domain/replay.constants.js.map +1 -0
- package/dist/domain/replay.d.ts +11 -0
- package/dist/domain/replay.js +231 -0
- package/dist/domain/replay.js.map +1 -0
- package/dist/domain/replay.types.d.ts +84 -0
- package/dist/domain/replay.types.js +2 -0
- package/dist/domain/replay.types.js.map +1 -0
- package/dist/domain/task-queue.js +18 -0
- package/dist/domain/task-queue.js.map +1 -1
- package/dist/domain/task-queue.types.d.ts +9 -0
- package/dist/domain/task-queue.types.js.map +1 -1
- package/dist/domain/workflow/checkpoint-validation.js +14 -1
- package/dist/domain/workflow/checkpoint-validation.js.map +1 -1
- package/dist/domain/workflow/checkpoint.js +13 -2
- package/dist/domain/workflow/checkpoint.js.map +1 -1
- package/dist/domain/workflow/gate-validation.js +2 -1
- package/dist/domain/workflow/gate-validation.js.map +1 -1
- package/dist/domain/workflow/input-validation.d.ts +7 -0
- package/dist/domain/workflow/input-validation.js +82 -0
- package/dist/domain/workflow/input-validation.js.map +1 -0
- package/dist/domain/workflow/input.d.ts +10 -0
- package/dist/domain/workflow/input.js +93 -0
- package/dist/domain/workflow/input.js.map +1 -0
- package/dist/domain/workflow/input.types.d.ts +37 -0
- package/dist/domain/workflow/input.types.js +2 -0
- package/dist/domain/workflow/input.types.js.map +1 -0
- package/dist/domain/workflow/loop-runner.d.ts +3 -0
- package/dist/domain/workflow/loop-runner.js +91 -0
- package/dist/domain/workflow/loop-runner.js.map +1 -0
- package/dist/domain/workflow/loop-task.d.ts +10 -0
- package/dist/domain/workflow/loop-task.js +39 -0
- package/dist/domain/workflow/loop-task.js.map +1 -0
- package/dist/domain/workflow/loop-task.types.d.ts +28 -0
- package/dist/domain/workflow/loop-task.types.js +2 -0
- package/dist/domain/workflow/loop-task.types.js.map +1 -0
- package/dist/domain/workflow/loop-validation.d.ts +4 -0
- package/dist/domain/workflow/loop-validation.js +62 -0
- package/dist/domain/workflow/loop-validation.js.map +1 -0
- package/dist/domain/workflow/quota-pause.d.ts +7 -0
- package/dist/domain/workflow/quota-pause.js +83 -0
- package/dist/domain/workflow/quota-pause.js.map +1 -0
- package/dist/domain/workflow/quota-pause.types.d.ts +14 -0
- package/dist/domain/workflow/quota-pause.types.js +2 -0
- package/dist/domain/workflow/quota-pause.types.js.map +1 -0
- package/dist/domain/workflow/quota-validation.d.ts +2 -0
- package/dist/domain/workflow/quota-validation.js +30 -0
- package/dist/domain/workflow/quota-validation.js.map +1 -0
- package/dist/domain/workflow/task-cache-entry.d.ts +3 -0
- package/dist/domain/workflow/task-cache-entry.js +57 -0
- package/dist/domain/workflow/task-cache-entry.js.map +1 -0
- package/dist/domain/workflow/task-cache.constants.d.ts +3 -0
- package/dist/domain/workflow/task-cache.constants.js +3 -0
- package/dist/domain/workflow/task-cache.constants.js.map +1 -0
- package/dist/domain/workflow/task-cache.d.ts +6 -0
- package/dist/domain/workflow/task-cache.js +92 -0
- package/dist/domain/workflow/task-cache.js.map +1 -0
- package/dist/domain/workflow/task-cache.types.d.ts +35 -0
- package/dist/domain/workflow/task-cache.types.js +2 -0
- package/dist/domain/workflow/task-cache.types.js.map +1 -0
- package/dist/domain/workflow/task-runner.js +100 -34
- package/dist/domain/workflow/task-runner.js.map +1 -1
- package/dist/domain/workflow/task.js +21 -0
- package/dist/domain/workflow/task.js.map +1 -1
- package/dist/domain/workflow/validation.js +13 -2
- package/dist/domain/workflow/validation.js.map +1 -1
- package/dist/domain/workflow/workflow-scheduler.js +27 -2
- package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
- package/dist/domain/workflow/workflow-state.js +20 -3
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +26 -3
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/git/command.d.ts +2 -1
- package/dist/infrastructure/git/command.js +2 -2
- package/dist/infrastructure/git/command.js.map +1 -1
- package/dist/infrastructure/git/replay-commits.constants.d.ts +5 -0
- package/dist/infrastructure/git/replay-commits.constants.js +6 -0
- package/dist/infrastructure/git/replay-commits.constants.js.map +1 -0
- package/dist/infrastructure/git/replay-commits.d.ts +2 -0
- package/dist/infrastructure/git/replay-commits.js +92 -0
- package/dist/infrastructure/git/replay-commits.js.map +1 -0
- package/dist/infrastructure/journal.types.d.ts +1 -0
- package/dist/infrastructure/journal.types.js.map +1 -1
- package/dist/infrastructure/reporter.js +3 -0
- package/dist/infrastructure/reporter.js.map +1 -1
- package/dist/infrastructure/storage-inventory.types.d.ts +1 -1
- package/dist/infrastructure/storage-inventory.types.js.map +1 -1
- package/dist/infrastructure/transport-task-cache.constants.d.ts +2 -0
- package/dist/infrastructure/transport-task-cache.constants.js +3 -0
- package/dist/infrastructure/transport-task-cache.constants.js.map +1 -0
- package/dist/infrastructure/transport-task-cache.d.ts +3 -0
- package/dist/infrastructure/transport-task-cache.js +56 -0
- package/dist/infrastructure/transport-task-cache.js.map +1 -0
- package/dist/infrastructure/transport-task-cache.types.d.ts +4 -0
- package/dist/infrastructure/transport-task-cache.types.js +2 -0
- package/dist/infrastructure/transport-task-cache.types.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
This major release adds required workflow result fields, extends public status, event, fault and speculation unions, and reclassifies model-provider rate limits. Result producers and test doubles must provide `WorkflowResult.inputRequests`; update exhaustive handling of `TaskStatus`, `WorkflowResult.status`, `WorkflowEvent.type`, `FaultCode`, `ObservationEvent`, `Agent`, `StorageCategoryName` and speculation statuses, and handlers that matched `provider` for HTTP 429. Existing entry points remain available. Live limit campaigns and authenticated model campaigns for these additions remain outstanding.
|
|
6
|
+
|
|
7
|
+
- Add opt-in task result caching with `task({ cache: { store, version, key, maxAgeMs, mode } })`, `taskCacheStore({ transporter })` and `repositoryFingerprint()`. A hit restores the stored lossless JSON result without an attempt, usage or replayed side effects; `loopTask` accepts `cache`, while gates, interactions, `agentTask` and `isolatedTask` reject it. Store errors and invalid entries degrade to a miss without changing the task outcome. `TaskRecord` gains `cacheHit`, `WorkflowEvent` gains the `cache` type with `cache` and `error`, `StorageCategoryName` gains `task-cache` and retention policies accept the `task-cache` scope; update exhaustive consumers. Entries are not authenticated.
|
|
8
|
+
- Add opt-in quota pauses with `workflow.start({ onQuota: { action: "pause", maxWaitMs } })`. A quota error pauses the task durably instead of retrying or failing it; a known reset within `maxWaitMs` is awaited in process, otherwise a later start with the same checkpoint resumes it. `TaskRecord` gains `quota` and `WorkflowEvent` gains the `quota` type and `resetAt`; update exhaustive consumers. Human-readable reset times are not parsed, and reruns start a new agent dispatch.
|
|
9
|
+
- Continue the conversation interrupted by a quota pause: `TaskContext.quota` exposes the captured conversation and retained branch to the first attempt after the pause. `agentTask` and `isolatedTask` resume it with a short instruction unless `quotaResume: "restart"`, integrated isolated workspaces start from the interrupted branch, and interactive tasks continue the interrupted turn. Agents without resume or capture start a new conversation.
|
|
10
|
+
- Carry quota failures across queues: `QueueResult.quota` reports the handler's limit and `queuedTask` rejects with code `quota`. The first attempt after a pause publishes a new job, `<key>:quota:<attempt>`, and `QueueRequest.idempotencyKey` keeps the handler's effect key stable.
|
|
11
|
+
- Report candidates stopped by a limit with speculation status `quota` and `SpeculationResult.quota`; `SpeculativeCandidateResult.status` and `SpeculationResult.status` gain `quota`, so update exhaustive consumers. A durable race finished on quota reruns only those candidates as new attempts from the baseline, without continuing their conversation.
|
|
12
|
+
- Add the `quota` fault code, the `quota` agent event, `AgentAdapter.quota` and `quotaFault()`. Claude Code, Codex, Copilot, Kimi and Antigravity limit signals reclassify failed turns from `process` to `quota`, with the reset time when Claude reports it. HTTP 429 and quota stream errors from OpenAI and Anthropic model providers now use code `quota` instead of `provider`, keep `retryAfterMs` and add `resetAt`; update handlers that matched `provider` for rate limits. Classification is based on recorded protocol formats, not live limit campaigns.
|
|
13
|
+
- Add `replayAgent()` to replay a dispatch journal without calling a model: it re-emits the recorded events and usage turn by turn, rebuilds the recorded commits inside the sandbox with their original identities, rethrows recorded turn failures and reports prompt, baseline, tree, exhausted and unrecorded differences through `ReplayDivergence` (or warnings with `divergence: "warn"`). `logging.replayable` records each sandbox dispatch's linear commits as verified binary patches; journals then contain repository content. `Agent` gains the `ReplayAgent` variant, `FaultCode` gains `replay`, `ObservationEvent` gains `workspace-commits` and `dispatch-finished` gains an optional `error`; update exhaustive consumers.
|
|
14
|
+
- Add `interactiveAgentTask()` with durable question/answer turns for the Outpost harness and portable CLI conversations, preserved worktrees, actor validation, cumulative usage and explicit interrupted-turn replay. Antigravity and disabled capture are rejected. Pending questions release the sandbox; in-tool suspension, signed answers and question expiry remain future work.
|
|
15
|
+
- Extend `TaskStatus` and `WorkflowResult.status` with `waiting-input`, and `WorkflowEvent.type` with `input-request`/`input-answer`. Result producers must now provide `inputRequests`; consumers with exhaustive status handling must account for these additions.
|
|
16
|
+
- Add `loopTask` for bounded attempt/check cycles with feedback, durable phase recovery, cumulative budgets, phase-specific idempotency keys and `LoopTaskExhausted`. `WorkflowEvent.type` gains `loop`; update exhaustive consumers. Callback errors require explicit resume; loop checkpoints require JSON outputs.
|
|
17
|
+
|
|
3
18
|
## 7.0.0
|
|
4
19
|
|
|
5
20
|
This major release extends public event and conversation unions and adds required context fields. Update exhaustive handling of `AgentEvent`, `WorkflowEvent.type`, `ModelStreamEvent`, `ConversationFormat` and `StoredConversationFormat`; custom context producers and test doubles must provide `TaskContext.idempotencyKey` and `QueueHandlerContext.idempotencyKey`. Existing entry points remain available. Redis queues now require `maxmemory-policy=noeviction`, and token-only workflow budgets reject incomplete usage. Firecracker and speculation remain experimental; 7.0.0 does not complete every roadmap direction.
|
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Outpost is a TypeScript library for running coding agents in reusable sandboxes, managing their Git workspaces and composing typed workflows. Claude Code, Codex, Antigravity, GitHub Copilot CLI and Kimi Code adapters work with Docker, Podman, Vercel, Daytona or explicit host execution. Each harness authenticates explicitly with your account login or an API key. Claude Code, Codex and Kimi support native capture, resume and fork. Copilot supports capture and resume; Antigravity resumes conversations only while their sandbox remains open. These continuation additions are available in 7.0.0.
|
|
6
6
|
|
|
7
|
+
Version 8.0.0 adds verification loops, interactive agent tasks, dispatch record and replay, task result caching and quota pauses that resume interrupted conversations. It extends public status, event and fault unions and reclassifies model-provider rate limits as `quota`: see the [changelog](CHANGELOG.md#800) for migration notes.
|
|
8
|
+
|
|
7
9
|
Version 7.0.0 stabilizes the built-in harness and adds bounded subagents, unified observation, native CLI continuation, signed workflow decisions and recoverable speculation. It extends public TypeScript unions and context contracts: see the [changelog](CHANGELOG.md#700) for migration notes. Firecracker and speculation remain experimental; the [roadmap](https://elie-laloum.github.io/outpost/project/roadmap/) records remaining validation and planned work.
|
|
8
10
|
|
|
9
11
|
## Get started
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { quotaMatcher } from "./quota.js";
|
|
2
|
+
import { antigravityQuotaPatterns } from "./quota.constants.js";
|
|
1
3
|
import { antigravityCredentials } from "./antigravity-authentication.js";
|
|
2
4
|
import { antigravityVariables } from "./antigravity.constants.js";
|
|
3
5
|
import { antigravityEvents } from "./antigravity-events.js";
|
|
@@ -22,6 +24,7 @@ function bindAntigravity(settings) {
|
|
|
22
24
|
}),
|
|
23
25
|
request: (input) => antigravityRequest(settings, input),
|
|
24
26
|
events: antigravityEvents,
|
|
27
|
+
quota: quotaMatcher(antigravityQuotaPatterns),
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
export function antigravityHarness(settings = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"antigravity-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/antigravity-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"antigravity-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/antigravity-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGnE,SAAS,eAAe,CAAC,QAAoC;IAC3D,YAAY,CAAC,uBAAuB,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,iBAAiB,CACnC,aAAa,EACb,sBAAsB,EACtB,QAAQ,CAAC,cAAc,EACvB,QAAQ,CAAC,KAAK,CACf,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,aAAa;QACnB,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,SAAS,EAAE,aAAa;QACxB,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,KAAK;QACd,qBAAqB,EAAE,IAAI;QAC3B,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;YACvB,GAAG,oBAAoB;YACvB,GAAG,QAAQ,CAAC,SAAS;SACtB,CAAC;QACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC;QACvD,MAAM,EAAE,iBAAiB;QACzB,KAAK,EAAE,YAAY,CAAC,wBAAwB,CAAC;KACvB,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,WAAgC,EAAE;IAElC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;QACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,eAAe,CAAC;YACd,GAAG,UAAU;YACb,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SAC1C,CAAC;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { quotaMatcher } from \"./quota.ts\";\nimport { antigravityQuotaPatterns } from \"./quota.constants.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { antigravityCredentials } from \"./antigravity-authentication.ts\";\nimport { antigravityVariables } from \"./antigravity.constants.ts\";\nimport { antigravityEvents } from \"./antigravity-events.ts\";\nimport { antigravityRequest } from \"./antigravity-request.ts\";\nimport type { AntigravitySettings } from \"./antigravity.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { antigravityModelSupport } from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound } from \"./settings.types.ts\";\n\nfunction bindAntigravity(settings: Bound<AntigravitySettings>): AgentAdapter {\n supportModel(antigravityModelSupport, settings.model);\n const credentials = credentialPlanner(\n \"Antigravity\",\n antigravityCredentials,\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"antigravity\",\n ...(credentials ? { credentials } : {}),\n bootstrap: \"antigravity\",\n resumable: true,\n forkable: false,\n capture: false,\n requiresFinishedEvent: true,\n variables: Object.freeze({\n ...antigravityVariables,\n ...settings.variables,\n }),\n request: (input) => antigravityRequest(settings, input),\n events: antigravityEvents,\n quota: quotaMatcher(antigravityQuotaPatterns),\n } satisfies AgentAdapter);\n}\n\nexport function antigravityHarness(\n settings: AntigravitySettings = {},\n): CliHarness {\n harnessSettings(settings);\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindAntigravity({\n ...configured,\n ...(model === undefined ? {} : { model }),\n }),\n });\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { quotaMatcher } from "./quota.js";
|
|
2
|
+
import { claudeQuotaPatterns } from "./quota.constants.js";
|
|
1
3
|
import { invariant } from "../../domain/errors.js";
|
|
2
4
|
import { credentialPlanner } from "./authentication.js";
|
|
3
5
|
import { claudeCredentials } from "./claude-authentication.js";
|
|
@@ -25,6 +27,7 @@ function bindClaude(settings) {
|
|
|
25
27
|
}),
|
|
26
28
|
request: (input) => claudeRequest(settings, input),
|
|
27
29
|
events: claudeEvents,
|
|
30
|
+
quota: quotaMatcher(claudeQuotaPatterns),
|
|
28
31
|
transcriptUsage: claudeTranscriptUsage,
|
|
29
32
|
});
|
|
30
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/claude-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,E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AAC,0BAA0B,CAAC,EAAE,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC;SAC/D,CAAC;QACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC;QAClD,MAAM,EAAE,YAAY;QACpB,eAAe,EAAE,qBAAqB;KAChB,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAA2B,EAAE;IACzD,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;QACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,UAAU,CAAC;YACT,GAAG,UAAU;YACb,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SAC1C,CAAC;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { invariant } from \"../../domain/errors.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { claudeCredentials } from \"./claude-authentication.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport { claudeEvents, claudeTranscriptUsage } from \"./claude-events.ts\";\nimport { claudeRequest } from \"./claude-request.ts\";\nimport {\n CLAUDE_MAX_OUTPUT_VARIABLE,\n claudeModelSupport,\n} from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound, ClaudeSettings } from \"./settings.types.ts\";\n\nfunction bindClaude(settings: Bound<ClaudeSettings>): AgentAdapter {\n supportModel(claudeModelSupport, settings.model);\n const maxOutputTokens = settings.model?.maxOutputTokens;\n invariant(\n maxOutputTokens === undefined ||\n !Object.hasOwn(settings.variables ?? {}, CLAUDE_MAX_OUTPUT_VARIABLE),\n `Set maxOutputTokens on the agent model or ${CLAUDE_MAX_OUTPUT_VARIABLE}, not both`,\n );\n const credentials = credentialPlanner(\n \"Claude Code\",\n claudeCredentials,\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"claude\",\n ...(credentials ? { credentials } : {}),\n conversations: \"claude\",\n resumable: true,\n capture: settings.saveConversations ?? true,\n variables: Object.freeze({\n ...settings.variables,\n ...(maxOutputTokens === undefined\n ? {}\n : { [CLAUDE_MAX_OUTPUT_VARIABLE]: String(maxOutputTokens) }),\n }),\n request: (input) => claudeRequest(settings, input),\n events: claudeEvents,\n transcriptUsage: claudeTranscriptUsage,\n } satisfies AgentAdapter);\n}\n\nexport function claudeHarness(settings: ClaudeSettings = {}): CliHarness {\n harnessSettings(settings);\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindClaude({\n ...configured,\n ...(model === undefined ? {} : { model }),\n }),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"claude-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/claude-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;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AqB;KAChB,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAA2B,EAAE;IACzD,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;QACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,UAAU,CAAC;YACT,GAAG,UAAU;YACb,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SAC1C,CAAC;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { quotaMatcher } from \"./quota.ts\";\nimport { claudeQuotaPatterns } from \"./quota.constants.ts\";\nimport { invariant } from \"../../domain/errors.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { claudeCredentials } from \"./claude-authentication.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport { claudeEvents, claudeTranscriptUsage } from \"./claude-events.ts\";\nimport { claudeRequest } from \"./claude-request.ts\";\nimport {\n CLAUDE_MAX_OUTPUT_VARIABLE,\n claudeModelSupport,\n} from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound, ClaudeSettings } from \"./settings.types.ts\";\n\nfunction bindClaude(settings: Bound<ClaudeSettings>): AgentAdapter {\n supportModel(claudeModelSupport, settings.model);\n const maxOutputTokens = settings.model?.maxOutputTokens;\n invariant(\n maxOutputTokens === undefined ||\n !Object.hasOwn(settings.variables ?? {}, CLAUDE_MAX_OUTPUT_VARIABLE),\n `Set maxOutputTokens on the agent model or ${CLAUDE_MAX_OUTPUT_VARIABLE}, not both`,\n );\n const credentials = credentialPlanner(\n \"Claude Code\",\n claudeCredentials,\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"claude\",\n ...(credentials ? { credentials } : {}),\n conversations: \"claude\",\n resumable: true,\n capture: settings.saveConversations ?? true,\n variables: Object.freeze({\n ...settings.variables,\n ...(maxOutputTokens === undefined\n ? {}\n : { [CLAUDE_MAX_OUTPUT_VARIABLE]: String(maxOutputTokens) }),\n }),\n request: (input) => claudeRequest(settings, input),\n events: claudeEvents,\n quota: quotaMatcher(claudeQuotaPatterns),\n transcriptUsage: claudeTranscriptUsage,\n } satisfies AgentAdapter);\n}\n\nexport function claudeHarness(settings: ClaudeSettings = {}): CliHarness {\n harnessSettings(settings);\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindClaude({\n ...configured,\n ...(model === undefined ? {} : { model }),\n }),\n });\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { toolResult } from "./tool-result.js";
|
|
2
2
|
import { decodeEvent, decodeLine } from "./event-decoder.js";
|
|
3
3
|
import { asRecord, decodeRecord, numberOrZero } from "./protocol.js";
|
|
4
|
+
import { claudeQuotaErrors } from "./quota.constants.js";
|
|
4
5
|
function tokens(value) {
|
|
5
6
|
const usage = asRecord(value);
|
|
6
7
|
return {
|
|
@@ -15,11 +16,32 @@ function system(event) {
|
|
|
15
16
|
? [{ kind: "conversation", id: event.session_id }]
|
|
16
17
|
: [];
|
|
17
18
|
}
|
|
19
|
+
function rateLimit(event) {
|
|
20
|
+
const info = asRecord(event.rate_limit_info);
|
|
21
|
+
if (info.status !== "rejected")
|
|
22
|
+
return [];
|
|
23
|
+
const reset = typeof info.resetsAt === "number" && Number.isSafeInteger(info.resetsAt)
|
|
24
|
+
? new Date(info.resetsAt * 1000)
|
|
25
|
+
: undefined;
|
|
26
|
+
const limit = typeof info.rateLimitType === "string" ? info.rateLimitType : "usage";
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
kind: "quota",
|
|
30
|
+
message: `Claude Code ${limit} limit reached`,
|
|
31
|
+
...(reset && Number.isFinite(reset.getTime())
|
|
32
|
+
? { resetAt: reset.toISOString() }
|
|
33
|
+
: {}),
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
}
|
|
18
37
|
function assistant(event) {
|
|
38
|
+
const quota = typeof event.error === "string" && claudeQuotaErrors.has(event.error)
|
|
39
|
+
? [{ kind: "quota", message: `Claude Code reported ${event.error}` }]
|
|
40
|
+
: [];
|
|
19
41
|
const message = asRecord(event.message);
|
|
20
42
|
const content = message.content;
|
|
21
43
|
if (!Array.isArray(content))
|
|
22
|
-
return
|
|
44
|
+
return quota;
|
|
23
45
|
const usage = message.usage
|
|
24
46
|
? [
|
|
25
47
|
{
|
|
@@ -33,6 +55,7 @@ function assistant(event) {
|
|
|
33
55
|
]
|
|
34
56
|
: [];
|
|
35
57
|
return [
|
|
58
|
+
...quota,
|
|
36
59
|
...usage,
|
|
37
60
|
...content.flatMap((part) => decodeEvent(asRecord(part), {
|
|
38
61
|
text: (block) => typeof block.text === "string"
|
|
@@ -89,6 +112,7 @@ export function claudeEvents(line) {
|
|
|
89
112
|
return [];
|
|
90
113
|
},
|
|
91
114
|
result,
|
|
115
|
+
rate_limit_event: rateLimit,
|
|
92
116
|
});
|
|
93
117
|
}
|
|
94
118
|
export function claudeTranscriptUsage(text) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-events.js","sourceRoot":"","sources":["../../../src/adapters/agents/claude-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY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AAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;YACpD,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAC/D,OAAO,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACpD,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ;gBACvE,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM;KACiB,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,IAAI,KAAwB,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,EAAE,IAAI,KAAK,WAAW;YAAE,SAAS;QAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,OAAO,CAAC,KAAK;YAAE,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { toolResult } from \"./tool-result.ts\";\nimport type { AgentEvent, Usage } from \"../../domain/agent.types.ts\";\nimport { decodeEvent, decodeLine } from \"./event-decoder.ts\";\nimport { asRecord, decodeRecord, numberOrZero } from \"./protocol.ts\";\nimport type { EventDecoders, ProtocolRecord } from \"./protocol.types.ts\";\n\nfunction tokens(value: unknown): Usage {\n const usage = asRecord(value);\n return {\n input: numberOrZero(usage.input_tokens),\n cacheCreated: numberOrZero(usage.cache_creation_input_tokens),\n cached: numberOrZero(usage.cache_read_input_tokens),\n output: numberOrZero(usage.output_tokens),\n };\n}\n\nfunction system(event: ProtocolRecord): AgentEvent[] {\n return typeof event.session_id === \"string\"\n ? [{ kind: \"conversation\", id: event.session_id }]\n : [];\n}\n\nfunction assistant(event: ProtocolRecord): AgentEvent[] {\n const message = asRecord(event.message);\n const content = message.content;\n if (!Array.isArray(content)) return [];\n const usage: AgentEvent[] = message.usage\n ? [\n {\n kind: \"message-usage\",\n tokens: tokens(message.usage),\n ...(typeof message.id === \"string\" ? { messageId: message.id } : {}),\n ...(typeof event.parent_tool_use_id === \"string\"\n ? { parentCallId: event.parent_tool_use_id }\n : {}),\n },\n ]\n : [];\n return [\n ...usage,\n ...content.flatMap((part) =>\n decodeEvent(asRecord(part), {\n text: (block) =>\n typeof block.text === \"string\"\n ? [{ kind: \"text\", text: block.text }]\n : [],\n thinking: (block) =>\n typeof block.thinking === \"string\"\n ? [{ kind: \"reasoning\", text: block.thinking }]\n : [],\n tool_result: (block) =>\n toolResult(\n block.tool_use_id,\n undefined,\n block.content,\n block.is_error === true,\n ).map((value) => ({\n ...value,\n ...(typeof event.parent_tool_use_id === \"string\"\n ? { parentCallId: event.parent_tool_use_id }\n : {}),\n })),\n tool_use: (block) => [\n {\n kind: \"tool\",\n name: String(block.name),\n input: block.input,\n ...(typeof block.id === \"string\" ? { callId: block.id } : {}),\n ...(typeof event.parent_tool_use_id === \"string\"\n ? { parentCallId: event.parent_tool_use_id }\n : {}),\n },\n ],\n }),\n ),\n ];\n}\n\nfunction result(event: ProtocolRecord): AgentEvent[] {\n const events: AgentEvent[] = [];\n if (!event.is_error && typeof event.result === \"string\")\n events.push({ kind: \"result\", text: event.result });\n if (event.usage) events.push({ kind: \"usage\", tokens: tokens(event.usage) });\n events.push(\n event.is_error\n ? {\n kind: \"failure\",\n message: String(\n event.result ?? JSON.stringify(event.errors) ?? \"Agent failed\",\n ),\n }\n : { kind: \"finished\" },\n );\n return events;\n}\n\nexport function claudeEvents(line: string): AgentEvent[] {\n return decodeLine(line, {\n system,\n assistant,\n user: assistant,\n stream_event: (event) => {\n const delta = asRecord(asRecord(event.event).delta);\n if (delta.type === \"text_delta\" && typeof delta.text === \"string\")\n return [{ kind: \"text-delta\", text: delta.text }];\n if (delta.type === \"thinking_delta\" && typeof delta.thinking === \"string\")\n return [{ kind: \"reasoning\", text: delta.thinking }];\n return [];\n },\n result,\n } satisfies EventDecoders);\n}\n\nexport function claudeTranscriptUsage(text: string): Usage | undefined {\n let usage: Usage | undefined;\n for (const line of text.split(/\\r?\\n/)) {\n const event = decodeRecord(line);\n if (event?.type !== \"assistant\") continue;\n const message = asRecord(event.message);\n if (message.usage) usage = tokens(message.usage);\n }\n return usage;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"claude-events.js","sourceRoot":"","sources":["../../../src/adapters/agents/claude-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,SAAS,MAAM,CAAC,KAAc;IAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO;QACL,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC;QACvC,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,2BAA2B,CAAC;QAC7D,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,uBAAuB,CAAC;QACnD,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,KAAqB;IACnC,OAAO,OAAO,K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Y;IAChD,IAAI,KAAwB,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,EAAE,IAAI,KAAK,WAAW;YAAE,SAAS;QAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,OAAO,CAAC,KAAK;YAAE,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { toolResult } from \"./tool-result.ts\";\nimport type { AgentEvent, Usage } from \"../../domain/agent.types.ts\";\nimport { decodeEvent, decodeLine } from \"./event-decoder.ts\";\nimport { asRecord, decodeRecord, numberOrZero } from \"./protocol.ts\";\nimport type { EventDecoders, ProtocolRecord } from \"./protocol.types.ts\";\nimport { claudeQuotaErrors } from \"./quota.constants.ts\";\n\nfunction tokens(value: unknown): Usage {\n const usage = asRecord(value);\n return {\n input: numberOrZero(usage.input_tokens),\n cacheCreated: numberOrZero(usage.cache_creation_input_tokens),\n cached: numberOrZero(usage.cache_read_input_tokens),\n output: numberOrZero(usage.output_tokens),\n };\n}\n\nfunction system(event: ProtocolRecord): AgentEvent[] {\n return typeof event.session_id === \"string\"\n ? [{ kind: \"conversation\", id: event.session_id }]\n : [];\n}\n\nfunction rateLimit(event: ProtocolRecord): AgentEvent[] {\n const info = asRecord(event.rate_limit_info);\n if (info.status !== \"rejected\") return [];\n const reset =\n typeof info.resetsAt === \"number\" && Number.isSafeInteger(info.resetsAt)\n ? new Date(info.resetsAt * 1000)\n : undefined;\n const limit =\n typeof info.rateLimitType === \"string\" ? info.rateLimitType : \"usage\";\n return [\n {\n kind: \"quota\",\n message: `Claude Code ${limit} limit reached`,\n ...(reset && Number.isFinite(reset.getTime())\n ? { resetAt: reset.toISOString() }\n : {}),\n },\n ];\n}\n\nfunction assistant(event: ProtocolRecord): AgentEvent[] {\n const quota: AgentEvent[] =\n typeof event.error === \"string\" && claudeQuotaErrors.has(event.error)\n ? [{ kind: \"quota\", message: `Claude Code reported ${event.error}` }]\n : [];\n const message = asRecord(event.message);\n const content = message.content;\n if (!Array.isArray(content)) return quota;\n const usage: AgentEvent[] = message.usage\n ? [\n {\n kind: \"message-usage\",\n tokens: tokens(message.usage),\n ...(typeof message.id === \"string\" ? { messageId: message.id } : {}),\n ...(typeof event.parent_tool_use_id === \"string\"\n ? { parentCallId: event.parent_tool_use_id }\n : {}),\n },\n ]\n : [];\n return [\n ...quota,\n ...usage,\n ...content.flatMap((part) =>\n decodeEvent(asRecord(part), {\n text: (block) =>\n typeof block.text === \"string\"\n ? [{ kind: \"text\", text: block.text }]\n : [],\n thinking: (block) =>\n typeof block.thinking === \"string\"\n ? [{ kind: \"reasoning\", text: block.thinking }]\n : [],\n tool_result: (block) =>\n toolResult(\n block.tool_use_id,\n undefined,\n block.content,\n block.is_error === true,\n ).map((value) => ({\n ...value,\n ...(typeof event.parent_tool_use_id === \"string\"\n ? { parentCallId: event.parent_tool_use_id }\n : {}),\n })),\n tool_use: (block) => [\n {\n kind: \"tool\",\n name: String(block.name),\n input: block.input,\n ...(typeof block.id === \"string\" ? { callId: block.id } : {}),\n ...(typeof event.parent_tool_use_id === \"string\"\n ? { parentCallId: event.parent_tool_use_id }\n : {}),\n },\n ],\n }),\n ),\n ];\n}\n\nfunction result(event: ProtocolRecord): AgentEvent[] {\n const events: AgentEvent[] = [];\n if (!event.is_error && typeof event.result === \"string\")\n events.push({ kind: \"result\", text: event.result });\n if (event.usage) events.push({ kind: \"usage\", tokens: tokens(event.usage) });\n events.push(\n event.is_error\n ? {\n kind: \"failure\",\n message: String(\n event.result ?? JSON.stringify(event.errors) ?? \"Agent failed\",\n ),\n }\n : { kind: \"finished\" },\n );\n return events;\n}\n\nexport function claudeEvents(line: string): AgentEvent[] {\n return decodeLine(line, {\n system,\n assistant,\n user: assistant,\n stream_event: (event) => {\n const delta = asRecord(asRecord(event.event).delta);\n if (delta.type === \"text_delta\" && typeof delta.text === \"string\")\n return [{ kind: \"text-delta\", text: delta.text }];\n if (delta.type === \"thinking_delta\" && typeof delta.thinking === \"string\")\n return [{ kind: \"reasoning\", text: delta.thinking }];\n return [];\n },\n result,\n rate_limit_event: rateLimit,\n } satisfies EventDecoders);\n}\n\nexport function claudeTranscriptUsage(text: string): Usage | undefined {\n let usage: Usage | undefined;\n for (const line of text.split(/\\r?\\n/)) {\n const event = decodeRecord(line);\n if (event?.type !== \"assistant\") continue;\n const message = asRecord(event.message);\n if (message.usage) usage = tokens(message.usage);\n }\n return usage;\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { quotaMatcher } from "./quota.js";
|
|
2
|
+
import { codexQuotaPatterns } from "./quota.constants.js";
|
|
1
3
|
import { credentialPlanner } from "./authentication.js";
|
|
2
4
|
import { codexCredentials } from "./codex-authentication.js";
|
|
3
5
|
import { codexProvider } from "./codex-provider.js";
|
|
@@ -18,6 +20,7 @@ function bindCodex(settings) {
|
|
|
18
20
|
variables: Object.freeze({ ...settings.variables }),
|
|
19
21
|
request: (input) => codexRequest(settings, input),
|
|
20
22
|
events: codexEvents,
|
|
23
|
+
quota: quotaMatcher(codexQuotaPatterns),
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
export function codexHarness(settings = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/codex-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/codex-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAA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Q,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;QACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,SAAS,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;KAC1E,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { quotaMatcher } from \"./quota.ts\";\nimport { codexQuotaPatterns } from \"./quota.constants.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { codexCredentials } from \"./codex-authentication.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport { codexProvider } from \"./codex-provider.ts\";\nimport { codexEvents } from \"./codex-events.ts\";\nimport { codexRequest } from \"./codex-request.ts\";\nimport { codexModelSupport } from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound, CodexSettings } from \"./settings.types.ts\";\n\nfunction bindCodex(settings: Bound<CodexSettings>): AgentAdapter {\n supportModel(codexModelSupport, settings.model);\n codexProvider(settings);\n const credentials = credentialPlanner(\n \"Codex\",\n codexCredentials(settings.modelProvider),\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"codex\",\n ...(credentials ? { credentials } : {}),\n conversations: \"codex\",\n resumable: true,\n capture: settings.saveConversations ?? true,\n variables: Object.freeze({ ...settings.variables }),\n request: (input) => codexRequest(settings, input),\n events: codexEvents,\n quota: quotaMatcher(codexQuotaPatterns),\n } satisfies AgentAdapter);\n}\n\nexport function codexHarness(settings: CodexSettings = {}): CliHarness {\n harnessSettings(settings);\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindCodex({ ...configured, ...(model === undefined ? {} : { model }) }),\n });\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { quotaMatcher } from "./quota.js";
|
|
2
|
+
import { copilotQuotaPatterns } from "./quota.constants.js";
|
|
1
3
|
import { copilotUsage } from "./copilot-usage.js";
|
|
2
4
|
import { sessionUsageCommand, sessionUsageResult } from "./session-usage.js";
|
|
3
5
|
import { credentialPlanner } from "./authentication.js";
|
|
@@ -23,6 +25,7 @@ function bindCopilot(settings) {
|
|
|
23
25
|
}),
|
|
24
26
|
request: (input) => copilotRequest(settings, input),
|
|
25
27
|
events: copilotEvents,
|
|
28
|
+
quota: quotaMatcher(copilotQuotaPatterns),
|
|
26
29
|
usage: "session",
|
|
27
30
|
usageCommand: (conversation) => sessionUsageCommand("copilot", conversation),
|
|
28
31
|
usageResult: (text) => sessionUsageResult(text, copilotUsage),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/copilot-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,eAAe,E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IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,WAAW,CAAC;YACV,GAAG,UAAU;YACb,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SAC1C,CAAC;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { copilotUsage } from \"./copilot-usage.ts\";\nimport { sessionUsageCommand, sessionUsageResult } from \"./session-usage.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { copilotCredentials } from \"./copilot-authentication.ts\";\nimport { copilotEvents } from \"./copilot-events.ts\";\nimport { copilotRequest } from \"./copilot-request.ts\";\nimport type { CopilotSettings } from \"./copilot.types.ts\";\nimport { copilotModelSupport } from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound } from \"./settings.types.ts\";\n\nfunction bindCopilot(settings: Bound<CopilotSettings>): AgentAdapter {\n supportModel(copilotModelSupport, settings.model);\n const credentials = credentialPlanner(\n \"GitHub Copilot CLI\",\n copilotCredentials,\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"copilot\",\n ...(credentials ? { credentials } : {}),\n bootstrap: \"copilot\",\n resumable: true,\n forkable: false,\n conversations: \"copilot\",\n requiresFinishedEvent: true,\n variables: Object.freeze({\n COPILOT_AUTO_UPDATE: \"false\",\n ...settings.variables,\n }),\n request: (input) => copilotRequest(settings, input),\n events: copilotEvents,\n usage: \"session\",\n usageCommand: (conversation) =>\n sessionUsageCommand(\"copilot\", conversation),\n usageResult: (text) => sessionUsageResult(text, copilotUsage),\n } satisfies AgentAdapter);\n}\n\nexport function copilotHarness(settings: CopilotSettings = {}): CliHarness {\n harnessSettings(settings);\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindCopilot({\n ...configured,\n ...(model === undefined ? {} : { model }),\n }),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"copilot-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/copilot-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGnE,SAAS,WAAW,CAAC,QAAgC;IACnD,YAAY,CAAC,mBAAmB,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,iBAAiB,CACnC,oBAAoB,EACpB,kBAAkB,EAClB,QAAQ,CAAC,cAAc,EACvB,QAAQ,CAAC,KAAK,CACf,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,SAAS;QACf,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,KAAK;QACf,aAAa,EAAE,SAAS;QACxB,qBAAqB,EAAE,IAAI;QAC3B,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;YACvB,mBAAmB,EAAE,OAAO;YAC5B,GAAG,QAAQ,CAAC,SAAS;SACtB,CAAC;QACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC;QACnD,MAAM,EAAE,aAAa;QACrB,KAAK,EAAE,YAAY,CAAC,oBAAoB,CAAC;QACzC,KAAK,EAAE,SAAS;QAChB,YAAY,EAAE,CAAC,YAAY,EAAE,EAAE,CAC7B,mBAAmB,CAAC,SAAS,EAAE,YAAY,CAAC;QAC9C,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,YAAY,CAAC;KACvC,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,WAA4B,EAAE;IAC3D,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;QACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,WAAW,CAAC;YACV,GAAG,UAAU;YACb,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;SAC1C,CAAC;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { quotaMatcher } from \"./quota.ts\";\nimport { copilotQuotaPatterns } from \"./quota.constants.ts\";\nimport { copilotUsage } from \"./copilot-usage.ts\";\nimport { sessionUsageCommand, sessionUsageResult } from \"./session-usage.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { copilotCredentials } from \"./copilot-authentication.ts\";\nimport { copilotEvents } from \"./copilot-events.ts\";\nimport { copilotRequest } from \"./copilot-request.ts\";\nimport type { CopilotSettings } from \"./copilot.types.ts\";\nimport { copilotModelSupport } from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound } from \"./settings.types.ts\";\n\nfunction bindCopilot(settings: Bound<CopilotSettings>): AgentAdapter {\n supportModel(copilotModelSupport, settings.model);\n const credentials = credentialPlanner(\n \"GitHub Copilot CLI\",\n copilotCredentials,\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"copilot\",\n ...(credentials ? { credentials } : {}),\n bootstrap: \"copilot\",\n resumable: true,\n forkable: false,\n conversations: \"copilot\",\n requiresFinishedEvent: true,\n variables: Object.freeze({\n COPILOT_AUTO_UPDATE: \"false\",\n ...settings.variables,\n }),\n request: (input) => copilotRequest(settings, input),\n events: copilotEvents,\n quota: quotaMatcher(copilotQuotaPatterns),\n usage: \"session\",\n usageCommand: (conversation) =>\n sessionUsageCommand(\"copilot\", conversation),\n usageResult: (text) => sessionUsageResult(text, copilotUsage),\n } satisfies AgentAdapter);\n}\n\nexport function copilotHarness(settings: CopilotSettings = {}): CliHarness {\n harnessSettings(settings);\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindCopilot({\n ...configured,\n ...(model === undefined ? {} : { model }),\n }),\n });\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { copilotShutdown, copilotUsage } from "./copilot-usage.js";
|
|
|
2
2
|
import { toolResult } from "./tool-result.js";
|
|
3
3
|
import { decodeLine } from "./event-decoder.js";
|
|
4
4
|
import { asRecord } from "./protocol.js";
|
|
5
|
+
import { copilotQuotaErrors } from "./quota.constants.js";
|
|
5
6
|
function message(event) {
|
|
6
7
|
const data = asRecord(event.data);
|
|
7
8
|
const requests = Array.isArray(data.toolRequests) ? data.toolRequests : [];
|
|
@@ -56,9 +57,12 @@ export function copilotEvents(line) {
|
|
|
56
57
|
},
|
|
57
58
|
"session.error": (event) => {
|
|
58
59
|
const data = asRecord(event.data);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
if (typeof data.message !== "string")
|
|
61
|
+
return [];
|
|
62
|
+
return typeof data.errorType === "string" &&
|
|
63
|
+
copilotQuotaErrors.has(data.errorType)
|
|
64
|
+
? [{ kind: "quota", message: data.message }]
|
|
65
|
+
: [{ kind: "warning", message: data.message }];
|
|
62
66
|
},
|
|
63
67
|
result,
|
|
64
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot-events.js","sourceRoot":"","sources":["../../../src/adapters/agents/copilot-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"copilot-events.js","sourceRoot":"","sources":["../../../src/adapters/agents/copilot-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,SAAS,OAAO,CAAC,KAAqB;IACpC,MA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AClC,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;YAChD,OAAO,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ;gBACvC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;gBACtC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC5C,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,MAAM;KACP,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { copilotShutdown, copilotUsage } from \"./copilot-usage.ts\";\nimport { toolResult } from \"./tool-result.ts\";\nimport type { AgentEvent } from \"../../domain/agent.types.ts\";\nimport { decodeLine } from \"./event-decoder.ts\";\nimport { asRecord } from \"./protocol.ts\";\nimport type { ProtocolRecord } from \"./protocol.types.ts\";\nimport { copilotQuotaErrors } from \"./quota.constants.ts\";\n\nfunction message(event: ProtocolRecord): AgentEvent[] {\n const data = asRecord(event.data);\n const requests = Array.isArray(data.toolRequests) ? data.toolRequests : [];\n const tools = requests.map(asRecord).flatMap((request): AgentEvent[] =>\n typeof request.name === \"string\"\n ? [\n {\n kind: \"tool\",\n name: request.name,\n input: request.arguments,\n ...(typeof request.toolCallId === \"string\"\n ? { callId: request.toolCallId }\n : {}),\n },\n ]\n : [],\n );\n return typeof data.content === \"string\" && data.content\n ? [{ kind: \"text\", text: data.content }, ...tools]\n : tools;\n}\n\nfunction result(event: ProtocolRecord): AgentEvent[] {\n const conversation: AgentEvent[] =\n typeof event.sessionId === \"string\"\n ? [{ kind: \"conversation\", id: event.sessionId }]\n : [];\n if (event.exitCode === 0 && event.outcome !== \"blocked\")\n return [...conversation, { kind: \"finished\" }];\n return [\n ...conversation,\n {\n kind: \"failure\",\n message:\n event.outcome === \"blocked\"\n ? \"GitHub Copilot CLI was blocked before completing the prompt\"\n : `GitHub Copilot CLI ended with exit code ${String(event.exitCode ?? \"unknown\")}`,\n },\n ];\n}\n\nexport function copilotEvents(line: string): AgentEvent[] {\n return decodeLine(line, {\n \"assistant.message\": message,\n \"assistant.usage\": (event) => [\n { kind: \"usage\", tokens: copilotUsage(event.data) },\n ],\n \"session.shutdown\": copilotShutdown,\n \"assistant.reasoning\": (event) => {\n const data = asRecord(event.data);\n return typeof data.content === \"string\"\n ? [{ kind: \"reasoning\", text: data.content }]\n : [];\n },\n \"tool.execution_complete\": (event) => {\n const data = asRecord(event.data);\n return toolResult(\n data.toolCallId,\n undefined,\n data.result ?? data.error,\n data.success === false,\n );\n },\n \"session.error\": (event) => {\n const data = asRecord(event.data);\n if (typeof data.message !== \"string\") return [];\n return typeof data.errorType === \"string\" &&\n copilotQuotaErrors.has(data.errorType)\n ? [{ kind: \"quota\", message: data.message }]\n : [{ kind: \"warning\", message: data.message }];\n },\n result,\n });\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { quotaMatcher } from "./quota.js";
|
|
2
|
+
import { kimiQuotaPatterns } from "./quota.constants.js";
|
|
1
3
|
import { kimiUsage } from "./kimi-usage.js";
|
|
2
4
|
import { sessionUsageCommand, sessionUsageResult } from "./session-usage.js";
|
|
3
5
|
import { forkKimi } from "./kimi-fork.js";
|
|
@@ -27,6 +29,7 @@ function bindKimi(settings) {
|
|
|
27
29
|
}),
|
|
28
30
|
request: (input) => kimiRequest(settings, input),
|
|
29
31
|
events: kimiEvents,
|
|
32
|
+
quota: quotaMatcher(kimiQuotaPatterns),
|
|
30
33
|
usage: "session",
|
|
31
34
|
usageCommand: (conversation) => sessionUsageCommand("kimi", conversation),
|
|
32
35
|
usageResult: (text) => sessionUsageResult(text, kimiUsage),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kimi-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/kimi-adapter.ts"],"names":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AAC,EAAE,CAAC;KACzE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { kimiUsage } from \"./kimi-usage.ts\";\nimport { sessionUsageCommand, sessionUsageResult } from \"./session-usage.ts\";\nimport { forkKimi } from \"./kimi-fork.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport { invariant } from \"../../domain/errors.ts\";\nimport { authenticationForm } from \"../../domain/authentication.ts\";\nimport { kimiRegions } from \"./kimi.constants.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { kimiCredentials } from \"./kimi-authentication.ts\";\nimport { kimiEvents } from \"./kimi-events.ts\";\nimport { kimiRequest } from \"./kimi-request.ts\";\nimport type { KimiSettings } from \"./kimi.types.ts\";\nimport { kimiModelSupport } from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound } from \"./settings.types.ts\";\n\nfunction bindKimi(settings: Bound<KimiSettings>): AgentAdapter {\n supportModel(kimiModelSupport, settings.model);\n const credentials = credentialPlanner(\n \"Kimi Code\",\n kimiCredentials(settings.region),\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"kimi\",\n ...(credentials ? { credentials } : {}),\n bootstrap: \"kimi\",\n resumable: true,\n forkable: true,\n fork: forkKimi,\n conversations: \"kimi\",\n variables: Object.freeze({\n KIMI_CODE_NO_AUTO_UPDATE: \"1\",\n ...settings.variables,\n }),\n request: (input) => kimiRequest(settings, input),\n events: kimiEvents,\n usage: \"session\",\n usageCommand: (conversation) => sessionUsageCommand(\"kimi\", conversation),\n usageResult: (text) => sessionUsageResult(text, kimiUsage),\n } satisfies AgentAdapter);\n}\n\nexport function kimiHarness(settings: KimiSettings = {}): CliHarness {\n harnessSettings(settings);\n invariant(\n settings.region === undefined ||\n Object.hasOwn(kimiRegions, settings.region),\n 'Kimi region must be \"mainland-cn\" or \"global\"',\n );\n invariant(\n settings.region === undefined ||\n settings.authentication === undefined ||\n !authenticationForm(settings.authentication).form.startsWith(\"usage\"),\n \"Kimi region selects account authentication; configure the API endpoint through variables for usage authentication\",\n );\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindKimi({ ...configured, ...(model === undefined ? {} : { model }) }),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"kimi-adapter.js","sourceRoot":"","sources":["../../../src/adapters/agents/kimi-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGnE,SAAS,QAAQ,CAAC,QAA6B;IAC7C,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,iBAAiB,CACnC,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C,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EACvE,mHAAmH,CACpH,CAAC;IACF,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC/B,GAAG,QAAQ;QACX,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,CAAC,KAAkB,EAAE,EAAE,CAC3B,QAAQ,CAAC,EAAE,GAAG,UAAU,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;KACzE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { quotaMatcher } from \"./quota.ts\";\nimport { kimiQuotaPatterns } from \"./quota.constants.ts\";\nimport { kimiUsage } from \"./kimi-usage.ts\";\nimport { sessionUsageCommand, sessionUsageResult } from \"./session-usage.ts\";\nimport { forkKimi } from \"./kimi-fork.ts\";\nimport type { AgentAdapter, CliHarness } from \"../../domain/agent.types.ts\";\nimport { invariant } from \"../../domain/errors.ts\";\nimport { authenticationForm } from \"../../domain/authentication.ts\";\nimport { kimiRegions } from \"./kimi.constants.ts\";\nimport type { AgentModel } from \"../../domain/model.types.ts\";\nimport { credentialPlanner } from \"./authentication.ts\";\nimport { kimiCredentials } from \"./kimi-authentication.ts\";\nimport { kimiEvents } from \"./kimi-events.ts\";\nimport { kimiRequest } from \"./kimi-request.ts\";\nimport type { KimiSettings } from \"./kimi.types.ts\";\nimport { kimiModelSupport } from \"./model-support.constants.ts\";\nimport { harnessSettings, supportModel } from \"./model-support.ts\";\nimport type { Bound } from \"./settings.types.ts\";\n\nfunction bindKimi(settings: Bound<KimiSettings>): AgentAdapter {\n supportModel(kimiModelSupport, settings.model);\n const credentials = credentialPlanner(\n \"Kimi Code\",\n kimiCredentials(settings.region),\n settings.authentication,\n settings.model,\n );\n return Object.freeze({\n name: \"kimi\",\n ...(credentials ? { credentials } : {}),\n bootstrap: \"kimi\",\n resumable: true,\n forkable: true,\n fork: forkKimi,\n conversations: \"kimi\",\n variables: Object.freeze({\n KIMI_CODE_NO_AUTO_UPDATE: \"1\",\n ...settings.variables,\n }),\n request: (input) => kimiRequest(settings, input),\n events: kimiEvents,\n quota: quotaMatcher(kimiQuotaPatterns),\n usage: \"session\",\n usageCommand: (conversation) => sessionUsageCommand(\"kimi\", conversation),\n usageResult: (text) => sessionUsageResult(text, kimiUsage),\n } satisfies AgentAdapter);\n}\n\nexport function kimiHarness(settings: KimiSettings = {}): CliHarness {\n harnessSettings(settings);\n invariant(\n settings.region === undefined ||\n Object.hasOwn(kimiRegions, settings.region),\n 'Kimi region must be \"mainland-cn\" or \"global\"',\n );\n invariant(\n settings.region === undefined ||\n settings.authentication === undefined ||\n !authenticationForm(settings.authentication).form.startsWith(\"usage\"),\n \"Kimi region selects account authentication; configure the API endpoint through variables for usage authentication\",\n );\n const configured = Object.freeze({\n ...settings,\n variables: Object.freeze({ ...settings.variables }),\n });\n return Object.freeze({\n kind: \"cli\",\n bind: (model?: AgentModel) =>\n bindKimi({ ...configured, ...(model === undefined ? {} : { model }) }),\n });\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const claudeQuotaPatterns: readonly RegExp[];
|
|
2
|
+
export declare const codexQuotaPatterns: readonly RegExp[];
|
|
3
|
+
export declare const copilotQuotaPatterns: readonly RegExp[];
|
|
4
|
+
export declare const kimiQuotaPatterns: readonly RegExp[];
|
|
5
|
+
export declare const antigravityQuotaPatterns: readonly RegExp[];
|
|
6
|
+
export declare const claudeQuotaErrors: Set<string>;
|
|
7
|
+
export declare const copilotQuotaErrors: Set<string>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const claudeQuotaPatterns = Object.freeze([
|
|
2
|
+
/You['’]ve hit your (?:session |weekly |Opus |Sonnet |usage credit )?limit/i,
|
|
3
|
+
/usage limit reached/i,
|
|
4
|
+
/Request rejected \(429\)/i,
|
|
5
|
+
]);
|
|
6
|
+
export const codexQuotaPatterns = Object.freeze([
|
|
7
|
+
/You['’]ve hit your usage limit/i,
|
|
8
|
+
/Usage limit reached/i,
|
|
9
|
+
/Quota exceeded/i,
|
|
10
|
+
/exceeded retry limit, last status: 429/i,
|
|
11
|
+
]);
|
|
12
|
+
export const copilotQuotaPatterns = Object.freeze([
|
|
13
|
+
/You['’]ve (?:hit|reached) (?:your |the )?(?:session |weekly )?rate limit/i,
|
|
14
|
+
/run out of your included AI credits/i,
|
|
15
|
+
/reached the spending limit/i,
|
|
16
|
+
/wait for your limit to reset/i,
|
|
17
|
+
]);
|
|
18
|
+
export const kimiQuotaPatterns = Object.freeze([
|
|
19
|
+
/exceeded_current_quota_error/i,
|
|
20
|
+
/insufficient_quota/i,
|
|
21
|
+
/exceeded your current (?:token )?quota/i,
|
|
22
|
+
/check your account balance|insufficient balance/i,
|
|
23
|
+
/provider\.rate_limit/i,
|
|
24
|
+
]);
|
|
25
|
+
export const antigravityQuotaPatterns = Object.freeze([
|
|
26
|
+
/exhausted your quota/i,
|
|
27
|
+
/RESOURCE_EXHAUSTED/,
|
|
28
|
+
]);
|
|
29
|
+
export const claudeQuotaErrors = new Set(["rate_limit", "billing_error"]);
|
|
30
|
+
export const copilotQuotaErrors = new Set(["quota", "rate_limit"]);
|
|
31
|
+
//# sourceMappingURL=quota.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.constants.js","sourceRoot":"","sources":["../../../src/adapters/agents/quota.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,4EAA4E;IAC5E,sBAAsB;IACtB,2BAA2B;CAC5B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,iCAAiC;IACjC,sBAAsB;IACtB,iBAAiB;IACjB,yCAAyC;CAC1C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,2EAA2E;IAC3E,sCAAsC;IACtC,6BAA6B;IAC7B,+BAA+B;CAChC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,+BAA+B;IAC/B,qBAAqB;IACrB,yCAAyC;IACzC,kDAAkD;IAClD,uBAAuB;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,uBAAuB;IACvB,oBAAoB;CACrB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC","sourcesContent":["export const claudeQuotaPatterns = Object.freeze([\n /You['’]ve hit your (?:session |weekly |Opus |Sonnet |usage credit )?limit/i,\n /usage limit reached/i,\n /Request rejected \\(429\\)/i,\n]);\n\nexport const codexQuotaPatterns = Object.freeze([\n /You['’]ve hit your usage limit/i,\n /Usage limit reached/i,\n /Quota exceeded/i,\n /exceeded retry limit, last status: 429/i,\n]);\n\nexport const copilotQuotaPatterns = Object.freeze([\n /You['’]ve (?:hit|reached) (?:your |the )?(?:session |weekly )?rate limit/i,\n /run out of your included AI credits/i,\n /reached the spending limit/i,\n /wait for your limit to reset/i,\n]);\n\nexport const kimiQuotaPatterns = Object.freeze([\n /exceeded_current_quota_error/i,\n /insufficient_quota/i,\n /exceeded your current (?:token )?quota/i,\n /check your account balance|insufficient balance/i,\n /provider\\.rate_limit/i,\n]);\n\nexport const antigravityQuotaPatterns = Object.freeze([\n /exhausted your quota/i,\n /RESOURCE_EXHAUSTED/,\n]);\n\nexport const claudeQuotaErrors = new Set([\"rate_limit\", \"billing_error\"]);\nexport const copilotQuotaErrors = new Set([\"quota\", \"rate_limit\"]);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function quotaMatcher(patterns: readonly RegExp[]): (text: string) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota.js","sourceRoot":"","sources":["../../../src/adapters/agents/quota.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAC1B,QAA2B;IAE3B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAClE,CAAC","sourcesContent":["export function quotaMatcher(\n patterns: readonly RegExp[],\n): (text: string) => boolean {\n return (text) => patterns.some((pattern) => pattern.test(text));\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { invariant, OutpostError, positive } from "../../domain/errors.js";
|
|
2
2
|
import { serverSentEvents } from "../../infrastructure/sse.js";
|
|
3
|
-
import { MODEL_MAX_TIMEOUT_MS, MODEL_RESPONSE_BYTES, MODEL_TIMEOUT_MS, } from "./model.constants.js";
|
|
3
|
+
import { MODEL_MAX_TIMEOUT_MS, MODEL_QUOTA_STATUS, MODEL_RESPONSE_BYTES, MODEL_TIMEOUT_MS, } from "./model.constants.js";
|
|
4
4
|
import { validateModelRequest } from "./model-request.js";
|
|
5
5
|
import { retryAfterMs } from "./retry-after.js";
|
|
6
|
+
import { resetTimestamp } from "../../domain/quota.js";
|
|
6
7
|
import { modelJson } from "./model-http.js";
|
|
7
8
|
export function httpModelProvider(options, protocol, name, headers) {
|
|
8
9
|
let base;
|
|
@@ -39,9 +40,14 @@ export function httpModelProvider(options, protocol, name, headers) {
|
|
|
39
40
|
return response;
|
|
40
41
|
const retryAfter = retryAfterMs(response.headers.get("Retry-After"));
|
|
41
42
|
await response.body?.cancel();
|
|
42
|
-
|
|
43
|
+
const quota = response.status === MODEL_QUOTA_STATUS;
|
|
44
|
+
const resetAt = quota && retryAfter !== undefined
|
|
45
|
+
? resetTimestamp(retryAfter)
|
|
46
|
+
: undefined;
|
|
47
|
+
throw new OutpostError(quota ? "quota" : "provider", `Model request failed with HTTP ${response.status}`, {
|
|
43
48
|
status: response.status,
|
|
44
49
|
...(retryAfter === undefined ? {} : { retryAfterMs: retryAfter }),
|
|
50
|
+
...(resetAt === undefined ? {} : { resetAt }),
|
|
45
51
|
});
|
|
46
52
|
};
|
|
47
53
|
const failure = (error, signal, deadline, request) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-provider.js","sourceRoot":"","sources":["../../../src/adapters/models/http-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAM3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAK/D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,UAAU,iBAAiB,CAC/B,OAAyB,EACzB,QAAuB,EACvB,IAAY,EACZ,OAAyC;IAEzC,IAAI,IAAS,CAAC;IACd,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,YAAY,CACpB,eAAe,EACf,+CAA+C,CAChD,CAAC;IACJ,CAAC;IACD,SAAS,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AC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;YAC5D,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;gBACtE,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAClD,MAAM,CAAC,cAAc,EAAE,CAAC;gBACxB,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACzD,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { invariant, OutpostError, positive } from \"../../domain/errors.ts\";\nimport type {\n ModelProvider,\n ModelRequest,\n ModelStreamEvent,\n} from \"../../domain/model.types.ts\";\nimport { serverSentEvents } from \"../../infrastructure/sse.ts\";\nimport type {\n HttpModelOptions,\n ModelProtocol,\n} from \"./model-protocol.types.ts\";\nimport {\n MODEL_MAX_TIMEOUT_MS,\n MODEL_RESPONSE_BYTES,\n MODEL_TIMEOUT_MS,\n} from \"./model.constants.ts\";\nimport { validateModelRequest } from \"./model-request.ts\";\nimport { retryAfterMs } from \"./retry-after.ts\";\nimport { modelJson } from \"./model-http.ts\";\n\nexport function httpModelProvider(\n options: HttpModelOptions,\n protocol: ModelProtocol,\n name: string,\n headers: Readonly<Record<string, string>>,\n): ModelProvider {\n let base: URL;\n try {\n base = new URL(options.baseUrl);\n } catch {\n throw new OutpostError(\n \"configuration\",\n \"Model baseUrl must be an absolute HTTP(S) URL\",\n );\n }\n invariant(\n [\"http:\", \"https:\"].includes(base.protocol) &&\n !base.username &&\n !base.password &&\n !base.search &&\n !base.hash,\n \"Model baseUrl must use HTTP(S) without credentials, query or fragment\",\n );\n invariant(\n options.apiKey === false ||\n (typeof options.apiKey === \"string\" &&\n options.apiKey.trim() &&\n !/[\\r\\n]/.test(options.apiKey)),\n \"Model apiKey must be a nonempty key or false for unauthenticated endpoints\",\n );\n const endpoint = `${base.href.replace(/\\/+$/, \"\")}/${protocol.path}`;\n const timeoutMs = positive(\n options.timeoutMs ?? MODEL_TIMEOUT_MS,\n \"Model timeoutMs\",\n );\n invariant(\n timeoutMs <= MODEL_MAX_TIMEOUT_MS,\n \"Model timeoutMs exceeds the supported timer range\",\n );\n const maxBytes = positive(\n options.maxResponseBytes ?? MODEL_RESPONSE_BYTES,\n \"Model maxResponseBytes\",\n );\n const identity = `${name}:${protocol.path}:${base.origin}${base.pathname.replace(/\\/+$/, \"\")}`;\n const post = async (body: unknown, signal: AbortSignal) => {\n signal.throwIfAborted();\n const response = await fetch(endpoint, {\n method: \"POST\",\n redirect: \"error\",\n headers: { \"Content-Type\": \"application/json\", ...headers },\n body: JSON.stringify(body),\n signal,\n });\n if (response.ok) return response;\n const retryAfter = retryAfterMs(response.headers.get(\"Retry-After\"));\n await response.body?.cancel();\n throw new OutpostError(\n \"provider\",\n `Model request failed with HTTP ${response.status}`,\n {\n status: response.status,\n ...(retryAfter === undefined ? {} : { retryAfterMs: retryAfter }),\n },\n );\n };\n const failure = (\n error: unknown,\n signal: AbortSignal,\n deadline: AbortSignal,\n request: ModelRequest,\n ): OutpostError => {\n if (signal.aborted) {\n const timedOut = deadline.aborted && !request.signal?.aborted;\n return new OutpostError(\n timedOut ? \"timeout\" : \"aborted\",\n timedOut ? \"Model request timed out\" : \"Model request was cancelled\",\n );\n }\n if (error instanceof OutpostError) return error;\n return new OutpostError(\n \"provider\",\n \"Model request failed during HTTP transport\",\n );\n };\n async function* stream(\n request: ModelRequest,\n ): AsyncGenerator<ModelStreamEvent> {\n validateModelRequest(request);\n const streaming = protocol.stream!;\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n let timer = setTimeout(() => deadline.abort(), timeoutMs);\n const refresh = () => {\n clearTimeout(timer);\n timer = setTimeout(() => deadline.abort(), timeoutMs);\n };\n try {\n const response = await post(\n { ...protocol.build(request, context), ...streaming.body },\n signal,\n );\n if (!response.body)\n throw new OutpostError(\"response\", \"Model response has no body\");\n const decoder = streaming.decoder();\n for await (const event of serverSentEvents(\n response.body,\n maxBytes,\n refresh,\n )) {\n signal.throwIfAborted();\n const text = decoder.push(event);\n if (text) yield { type: \"text-delta\", text };\n }\n signal.throwIfAborted();\n yield { type: \"result\", result: protocol.read(decoder.final(), context) };\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n }\n return Object.freeze({\n name,\n identity,\n ...(protocol.validate ? { validate: protocol.validate } : {}),\n ...(protocol.stream ? { stream } : {}),\n async request(request: ModelRequest) {\n validateModelRequest(request);\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n const timer = setTimeout(() => deadline.abort(), timeoutMs);\n try {\n const response = await post(protocol.build(request, context), signal);\n const value = await modelJson(response, maxBytes);\n signal.throwIfAborted();\n return protocol.read(value, context);\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"http-provider.js","sourceRoot":"","sources":["../../../src/adapters/models/http-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAM3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAK/D,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sB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C;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACzD,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { invariant, OutpostError, positive } from \"../../domain/errors.ts\";\nimport type {\n ModelProvider,\n ModelRequest,\n ModelStreamEvent,\n} from \"../../domain/model.types.ts\";\nimport { serverSentEvents } from \"../../infrastructure/sse.ts\";\nimport type {\n HttpModelOptions,\n ModelProtocol,\n} from \"./model-protocol.types.ts\";\nimport {\n MODEL_MAX_TIMEOUT_MS,\n MODEL_QUOTA_STATUS,\n MODEL_RESPONSE_BYTES,\n MODEL_TIMEOUT_MS,\n} from \"./model.constants.ts\";\nimport { validateModelRequest } from \"./model-request.ts\";\nimport { retryAfterMs } from \"./retry-after.ts\";\nimport { resetTimestamp } from \"../../domain/quota.ts\";\nimport { modelJson } from \"./model-http.ts\";\n\nexport function httpModelProvider(\n options: HttpModelOptions,\n protocol: ModelProtocol,\n name: string,\n headers: Readonly<Record<string, string>>,\n): ModelProvider {\n let base: URL;\n try {\n base = new URL(options.baseUrl);\n } catch {\n throw new OutpostError(\n \"configuration\",\n \"Model baseUrl must be an absolute HTTP(S) URL\",\n );\n }\n invariant(\n [\"http:\", \"https:\"].includes(base.protocol) &&\n !base.username &&\n !base.password &&\n !base.search &&\n !base.hash,\n \"Model baseUrl must use HTTP(S) without credentials, query or fragment\",\n );\n invariant(\n options.apiKey === false ||\n (typeof options.apiKey === \"string\" &&\n options.apiKey.trim() &&\n !/[\\r\\n]/.test(options.apiKey)),\n \"Model apiKey must be a nonempty key or false for unauthenticated endpoints\",\n );\n const endpoint = `${base.href.replace(/\\/+$/, \"\")}/${protocol.path}`;\n const timeoutMs = positive(\n options.timeoutMs ?? MODEL_TIMEOUT_MS,\n \"Model timeoutMs\",\n );\n invariant(\n timeoutMs <= MODEL_MAX_TIMEOUT_MS,\n \"Model timeoutMs exceeds the supported timer range\",\n );\n const maxBytes = positive(\n options.maxResponseBytes ?? MODEL_RESPONSE_BYTES,\n \"Model maxResponseBytes\",\n );\n const identity = `${name}:${protocol.path}:${base.origin}${base.pathname.replace(/\\/+$/, \"\")}`;\n const post = async (body: unknown, signal: AbortSignal) => {\n signal.throwIfAborted();\n const response = await fetch(endpoint, {\n method: \"POST\",\n redirect: \"error\",\n headers: { \"Content-Type\": \"application/json\", ...headers },\n body: JSON.stringify(body),\n signal,\n });\n if (response.ok) return response;\n const retryAfter = retryAfterMs(response.headers.get(\"Retry-After\"));\n await response.body?.cancel();\n const quota = response.status === MODEL_QUOTA_STATUS;\n const resetAt =\n quota && retryAfter !== undefined\n ? resetTimestamp(retryAfter)\n : undefined;\n throw new OutpostError(\n quota ? \"quota\" : \"provider\",\n `Model request failed with HTTP ${response.status}`,\n {\n status: response.status,\n ...(retryAfter === undefined ? {} : { retryAfterMs: retryAfter }),\n ...(resetAt === undefined ? {} : { resetAt }),\n },\n );\n };\n const failure = (\n error: unknown,\n signal: AbortSignal,\n deadline: AbortSignal,\n request: ModelRequest,\n ): OutpostError => {\n if (signal.aborted) {\n const timedOut = deadline.aborted && !request.signal?.aborted;\n return new OutpostError(\n timedOut ? \"timeout\" : \"aborted\",\n timedOut ? \"Model request timed out\" : \"Model request was cancelled\",\n );\n }\n if (error instanceof OutpostError) return error;\n return new OutpostError(\n \"provider\",\n \"Model request failed during HTTP transport\",\n );\n };\n async function* stream(\n request: ModelRequest,\n ): AsyncGenerator<ModelStreamEvent> {\n validateModelRequest(request);\n const streaming = protocol.stream!;\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n let timer = setTimeout(() => deadline.abort(), timeoutMs);\n const refresh = () => {\n clearTimeout(timer);\n timer = setTimeout(() => deadline.abort(), timeoutMs);\n };\n try {\n const response = await post(\n { ...protocol.build(request, context), ...streaming.body },\n signal,\n );\n if (!response.body)\n throw new OutpostError(\"response\", \"Model response has no body\");\n const decoder = streaming.decoder();\n for await (const event of serverSentEvents(\n response.body,\n maxBytes,\n refresh,\n )) {\n signal.throwIfAborted();\n const text = decoder.push(event);\n if (text) yield { type: \"text-delta\", text };\n }\n signal.throwIfAborted();\n yield { type: \"result\", result: protocol.read(decoder.final(), context) };\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n }\n return Object.freeze({\n name,\n identity,\n ...(protocol.validate ? { validate: protocol.validate } : {}),\n ...(protocol.stream ? { stream } : {}),\n async request(request: ModelRequest) {\n validateModelRequest(request);\n const context = { identity, model: request.model };\n const deadline = new AbortController();\n const signal = request.signal\n ? AbortSignal.any([request.signal, deadline.signal])\n : deadline.signal;\n const timer = setTimeout(() => deadline.abort(), timeoutMs);\n try {\n const response = await post(protocol.build(request, context), signal);\n const value = await modelJson(response, maxBytes);\n signal.throwIfAborted();\n return protocol.read(value, context);\n } catch (error) {\n throw failure(error, signal, deadline.signal, request);\n } finally {\n clearTimeout(timer);\n }\n },\n });\n}\n"]}
|
|
@@ -2,3 +2,5 @@ export declare const MODEL_TIMEOUT_MS = 120000;
|
|
|
2
2
|
export declare const MODEL_RESPONSE_BYTES: number;
|
|
3
3
|
export declare const MODEL_MAX_TIMEOUT_MS = 2147483647;
|
|
4
4
|
export declare const MODEL_REQUEST_FIELDS: Set<string>;
|
|
5
|
+
export declare const MODEL_QUOTA_STATUS = 429;
|
|
6
|
+
export declare const MODEL_QUOTA_ERRORS: Set<string>;
|
|
@@ -12,4 +12,10 @@ export const MODEL_REQUEST_FIELDS = new Set([
|
|
|
12
12
|
"reasoning",
|
|
13
13
|
"signal",
|
|
14
14
|
]);
|
|
15
|
+
export const MODEL_QUOTA_STATUS = 429;
|
|
16
|
+
export const MODEL_QUOTA_ERRORS = new Set([
|
|
17
|
+
"rate_limit_error",
|
|
18
|
+
"rate_limit_exceeded",
|
|
19
|
+
"insufficient_quota",
|
|
20
|
+
]);
|
|
15
21
|
//# sourceMappingURL=model.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.constants.js","sourceRoot":"","sources":["../../../src/adapters/models/model.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACxC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IAC1C,OAAO;IACP,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,QAAQ;CACT,CAAC,CAAC","sourcesContent":["export const MODEL_TIMEOUT_MS = 120_000;\nexport const MODEL_RESPONSE_BYTES = 8 * 1024 * 1024;\nexport const MODEL_MAX_TIMEOUT_MS = 2_147_483_647;\nexport const MODEL_REQUEST_FIELDS = new Set([\n \"model\",\n \"prompt\",\n \"messages\",\n \"system\",\n \"tools\",\n \"cache\",\n \"maxOutputTokens\",\n \"reasoning\",\n \"signal\",\n]);\n"]}
|
|
1
|
+
{"version":3,"file":"model.constants.js","sourceRoot":"","sources":["../../../src/adapters/models/model.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACxC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IAC1C,OAAO;IACP,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,WAAW;IACX,QAAQ;CACT,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACxC,kBAAkB;IAClB,qBAAqB;IACrB,oBAAoB;CACrB,CAAC,CAAC","sourcesContent":["export const MODEL_TIMEOUT_MS = 120_000;\nexport const MODEL_RESPONSE_BYTES = 8 * 1024 * 1024;\nexport const MODEL_MAX_TIMEOUT_MS = 2_147_483_647;\nexport const MODEL_REQUEST_FIELDS = new Set([\n \"model\",\n \"prompt\",\n \"messages\",\n \"system\",\n \"tools\",\n \"cache\",\n \"maxOutputTokens\",\n \"reasoning\",\n \"signal\",\n]);\nexport const MODEL_QUOTA_STATUS = 429;\nexport const MODEL_QUOTA_ERRORS = new Set([\n \"rate_limit_error\",\n \"rate_limit_exceeded\",\n \"insufficient_quota\",\n]);\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OutpostError } from "../../domain/errors.js";
|
|
2
2
|
import { object } from "./model-response.js";
|
|
3
|
+
import { MODEL_QUOTA_ERRORS } from "./model.constants.js";
|
|
3
4
|
export function eventData(event) {
|
|
4
5
|
let value;
|
|
5
6
|
try {
|
|
@@ -11,12 +12,15 @@ export function eventData(event) {
|
|
|
11
12
|
return object(value);
|
|
12
13
|
}
|
|
13
14
|
export function streamFailure(data) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const record = (value) => value !== null && typeof value === "object"
|
|
16
|
+
? value
|
|
17
|
+
: {};
|
|
18
|
+
const error = record(data.error ?? record(data.response).error);
|
|
19
|
+
const type = "type" in error ? String(error.type) : undefined;
|
|
20
|
+
const code = typeof error.code === "string" ? error.code : undefined;
|
|
21
|
+
const quota = [type, code].some((value) => value !== undefined && MODEL_QUOTA_ERRORS.has(value));
|
|
22
|
+
throw new OutpostError(quota ? "quota" : "provider", quota
|
|
23
|
+
? "Model stream reported a usage or rate limit"
|
|
24
|
+
: "Model stream reported an error", { ...(type ? { type } : {}), ...(quota && code ? { code } : {}) });
|
|
21
25
|
}
|
|
22
26
|
//# sourceMappingURL=stream-events.js.map
|