maestro-agent-sdk 0.1.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/LICENSE +21 -0
- package/NOTICE +24 -0
- package/README.md +133 -0
- package/dist/agents/contracts.d.ts +49 -0
- package/dist/agents/contracts.d.ts.map +1 -0
- package/dist/agents/contracts.js +2 -0
- package/dist/agents/contracts.js.map +1 -0
- package/dist/agents/rollout/shared.d.ts +24 -0
- package/dist/agents/rollout/shared.d.ts.map +1 -0
- package/dist/agents/rollout/shared.js +105 -0
- package/dist/agents/rollout/shared.js.map +1 -0
- package/dist/core/agent.d.ts +71 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +22 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/loop.d.ts +26 -0
- package/dist/core/loop.d.ts.map +1 -0
- package/dist/core/loop.js +317 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +79 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +176 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/pool-cache.d.ts +103 -0
- package/dist/mcp/pool-cache.d.ts.map +1 -0
- package/dist/mcp/pool-cache.js +249 -0
- package/dist/mcp/pool-cache.js.map +1 -0
- package/dist/mcp/pool.d.ts +65 -0
- package/dist/mcp/pool.d.ts.map +1 -0
- package/dist/mcp/pool.js +86 -0
- package/dist/mcp/pool.js.map +1 -0
- package/dist/media/file-events.d.ts +8 -0
- package/dist/media/file-events.d.ts.map +1 -0
- package/dist/media/file-events.js +15 -0
- package/dist/media/file-events.js.map +1 -0
- package/dist/memory/active-task-template.d.ts +34 -0
- package/dist/memory/active-task-template.d.ts.map +1 -0
- package/dist/memory/active-task-template.js +63 -0
- package/dist/memory/active-task-template.js.map +1 -0
- package/dist/memory/compressor.d.ts +87 -0
- package/dist/memory/compressor.d.ts.map +1 -0
- package/dist/memory/compressor.js +164 -0
- package/dist/memory/compressor.js.map +1 -0
- package/dist/memory/hash.d.ts +17 -0
- package/dist/memory/hash.d.ts.map +1 -0
- package/dist/memory/hash.js +20 -0
- package/dist/memory/hash.js.map +1 -0
- package/dist/memory/prune.d.ts +117 -0
- package/dist/memory/prune.d.ts.map +1 -0
- package/dist/memory/prune.js +416 -0
- package/dist/memory/prune.js.map +1 -0
- package/dist/memory/reminder.d.ts +57 -0
- package/dist/memory/reminder.d.ts.map +1 -0
- package/dist/memory/reminder.js +57 -0
- package/dist/memory/reminder.js.map +1 -0
- package/dist/memory/scrubber.d.ts +28 -0
- package/dist/memory/scrubber.d.ts.map +1 -0
- package/dist/memory/scrubber.js +147 -0
- package/dist/memory/scrubber.js.map +1 -0
- package/dist/memory/token-estimate.d.ts +10 -0
- package/dist/memory/token-estimate.d.ts.map +1 -0
- package/dist/memory/token-estimate.js +69 -0
- package/dist/memory/token-estimate.js.map +1 -0
- package/dist/platform/config.d.ts +12 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/config.js +54 -0
- package/dist/platform/config.js.map +1 -0
- package/dist/platform/jsonl.d.ts +15 -0
- package/dist/platform/jsonl.d.ts.map +1 -0
- package/dist/platform/jsonl.js +80 -0
- package/dist/platform/jsonl.js.map +1 -0
- package/dist/platform/lifecycle.d.ts +22 -0
- package/dist/platform/lifecycle.d.ts.map +1 -0
- package/dist/platform/lifecycle.js +60 -0
- package/dist/platform/lifecycle.js.map +1 -0
- package/dist/platform/logger.d.ts +26 -0
- package/dist/platform/logger.d.ts.map +1 -0
- package/dist/platform/logger.js +41 -0
- package/dist/platform/logger.js.map +1 -0
- package/dist/platform/mcp-config.d.ts +15 -0
- package/dist/platform/mcp-config.d.ts.map +1 -0
- package/dist/platform/mcp-config.js +8 -0
- package/dist/platform/mcp-config.js.map +1 -0
- package/dist/provider.d.ts +81 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +444 -0
- package/dist/provider.js.map +1 -0
- package/dist/providers/anthropic.d.ts +132 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +518 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +140 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +2 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/deepseek.d.ts +118 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +467 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/registry.d.ts +3 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +94 -0
- package/dist/registry.js.map +1 -0
- package/dist/session-store.d.ts +133 -0
- package/dist/session-store.d.ts.map +1 -0
- package/dist/session-store.js +277 -0
- package/dist/session-store.js.map +1 -0
- package/dist/skills/curator.d.ts +104 -0
- package/dist/skills/curator.d.ts.map +1 -0
- package/dist/skills/curator.js +162 -0
- package/dist/skills/curator.js.map +1 -0
- package/dist/skills/index-builder.d.ts +42 -0
- package/dist/skills/index-builder.d.ts.map +1 -0
- package/dist/skills/index-builder.js +94 -0
- package/dist/skills/index-builder.js.map +1 -0
- package/dist/skills/loader.d.ts +107 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +286 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/preprocess.d.ts +45 -0
- package/dist/skills/preprocess.d.ts.map +1 -0
- package/dist/skills/preprocess.js +126 -0
- package/dist/skills/preprocess.js.map +1 -0
- package/dist/skills/usage.d.ts +75 -0
- package/dist/skills/usage.d.ts.map +1 -0
- package/dist/skills/usage.js +147 -0
- package/dist/skills/usage.js.map +1 -0
- package/dist/state/todos.d.ts +95 -0
- package/dist/state/todos.d.ts.map +1 -0
- package/dist/state/todos.js +198 -0
- package/dist/state/todos.js.map +1 -0
- package/dist/storage/conversations.d.ts +28 -0
- package/dist/storage/conversations.d.ts.map +1 -0
- package/dist/storage/conversations.js +8 -0
- package/dist/storage/conversations.js.map +1 -0
- package/dist/sub-agent/runner.d.ts +78 -0
- package/dist/sub-agent/runner.d.ts.map +1 -0
- package/dist/sub-agent/runner.js +215 -0
- package/dist/sub-agent/runner.js.map +1 -0
- package/dist/tools/builtin/agent.d.ts +33 -0
- package/dist/tools/builtin/agent.d.ts.map +1 -0
- package/dist/tools/builtin/agent.js +76 -0
- package/dist/tools/builtin/agent.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts +11 -0
- package/dist/tools/builtin/bash.d.ts.map +1 -0
- package/dist/tools/builtin/bash.js +91 -0
- package/dist/tools/builtin/bash.js.map +1 -0
- package/dist/tools/builtin/edit.d.ts +21 -0
- package/dist/tools/builtin/edit.d.ts.map +1 -0
- package/dist/tools/builtin/edit.js +238 -0
- package/dist/tools/builtin/edit.js.map +1 -0
- package/dist/tools/builtin/read.d.ts +17 -0
- package/dist/tools/builtin/read.d.ts.map +1 -0
- package/dist/tools/builtin/read.js +139 -0
- package/dist/tools/builtin/read.js.map +1 -0
- package/dist/tools/builtin/sandbox.d.ts +16 -0
- package/dist/tools/builtin/sandbox.d.ts.map +1 -0
- package/dist/tools/builtin/sandbox.js +58 -0
- package/dist/tools/builtin/sandbox.js.map +1 -0
- package/dist/tools/builtin/skill_view.d.ts +37 -0
- package/dist/tools/builtin/skill_view.d.ts.map +1 -0
- package/dist/tools/builtin/skill_view.js +82 -0
- package/dist/tools/builtin/skill_view.js.map +1 -0
- package/dist/tools/builtin/todo_write.d.ts +29 -0
- package/dist/tools/builtin/todo_write.d.ts.map +1 -0
- package/dist/tools/builtin/todo_write.js +96 -0
- package/dist/tools/builtin/todo_write.js.map +1 -0
- package/dist/tools/builtin/web_fetch.d.ts +10 -0
- package/dist/tools/builtin/web_fetch.d.ts.map +1 -0
- package/dist/tools/builtin/web_fetch.js +150 -0
- package/dist/tools/builtin/web_fetch.js.map +1 -0
- package/dist/tools/builtin/write.d.ts +35 -0
- package/dist/tools/builtin/write.d.ts.map +1 -0
- package/dist/tools/builtin/write.js +70 -0
- package/dist/tools/builtin/write.js.map +1 -0
- package/dist/tools/file-state.d.ts +99 -0
- package/dist/tools/file-state.d.ts.map +1 -0
- package/dist/tools/file-state.js +133 -0
- package/dist/tools/file-state.js.map +1 -0
- package/dist/tools/hooks/sandbox-fs.d.ts +25 -0
- package/dist/tools/hooks/sandbox-fs.d.ts.map +1 -0
- package/dist/tools/hooks/sandbox-fs.js +48 -0
- package/dist/tools/hooks/sandbox-fs.js.map +1 -0
- package/dist/tools/registry.d.ts +102 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +93 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAuB,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;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AAC,aAAqB;IACpD,IAAI,aAAa,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC1C,OAAO,gBAAgB,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,iBAAiB,CAAC,OAAO,EAAE,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,CAAC,GAAG,GAAyC,CAAC;IACpD,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,CAAC,CAAC,IAAI,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IACzD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Provider, ProviderCompleteOptions, ProviderMessage, ProviderResponse, ProviderStreamChunk, ProviderToolSchema } from "../providers/base.js";
|
|
2
|
+
/** Anthropic cache-control marker. Wire-only — the rest of the Maestro
|
|
3
|
+
* pipeline uses pure `ProviderContentBlock` without this field. */
|
|
4
|
+
type CacheControl = {
|
|
5
|
+
type: "ephemeral";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Raw Anthropic Messages API adapter for the Maestro TS port.
|
|
9
|
+
*
|
|
10
|
+
* Uses fetch directly (no @anthropic-ai/sdk dependency) — keeps the dep
|
|
11
|
+
* surface minimal and avoids overlap with Clawgram's existing
|
|
12
|
+
* @anthropic-ai/claude-agent-sdk usage (which is a higher-level wrapper
|
|
13
|
+
* around a claude CLI subprocess).
|
|
14
|
+
*
|
|
15
|
+
* Auth: ANTHROPIC_API_KEY env var. This is independent from Clawgram's
|
|
16
|
+
* existing Claude provider, which uses OAuth via the claude CLI.
|
|
17
|
+
*/
|
|
18
|
+
export declare class AnthropicProvider implements Provider {
|
|
19
|
+
private readonly apiKey;
|
|
20
|
+
constructor(apiKey: string);
|
|
21
|
+
static fromEnv(): AnthropicProvider;
|
|
22
|
+
complete(opts: ProviderCompleteOptions): Promise<ProviderResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Streaming variant of `complete()`. Sends the same request body with
|
|
25
|
+
* `stream: true`, parses the resulting SSE event stream into the small
|
|
26
|
+
* set of chunks the agent loop consumes (text_delta, tool_use_start /
|
|
27
|
+
* input_delta / complete, message_complete).
|
|
28
|
+
*
|
|
29
|
+
* The model's network shape is Anthropic SSE — events like
|
|
30
|
+
* `message_start`, `content_block_start`, `content_block_delta`,
|
|
31
|
+
* `content_block_stop`, `message_delta`, `message_stop`, plus periodic
|
|
32
|
+
* `ping` keepalives. Most are housekeeping; the loop only needs the
|
|
33
|
+
* deltas + tool_use lifecycle + terminal stop_reason / usage. Everything
|
|
34
|
+
* else is consumed and dropped by this adapter.
|
|
35
|
+
*/
|
|
36
|
+
stream(opts: ProviderCompleteOptions): AsyncGenerator<ProviderStreamChunk>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Convert the user-supplied `system` (plain string) into the array shape
|
|
40
|
+
* Anthropic accepts when you need a cache_control marker. A string slot
|
|
41
|
+
* has no cache field, so we lift it into a single text block and tag it
|
|
42
|
+
* ephemeral. Returning the original string unchanged when it's empty keeps
|
|
43
|
+
* the request shape minimal for prompt-less calls.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildCacheableSystem(system: string): string | Array<{
|
|
46
|
+
type: "text";
|
|
47
|
+
text: string;
|
|
48
|
+
cache_control: CacheControl;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Tag the last tool with cache_control so the (usually large) tool schema
|
|
52
|
+
* block lands in the cache after the first turn. Other tools are passed
|
|
53
|
+
* through verbatim — Anthropic caches the entire tools array prefix up to
|
|
54
|
+
* the last marker, so one breakpoint covers every preceding entry.
|
|
55
|
+
*
|
|
56
|
+
* Returns a new array; the caller's `opts.tools` reference is untouched so
|
|
57
|
+
* subsequent calls don't accumulate markers.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildCacheableTools(tools: readonly ProviderToolSchema[]): Array<ProviderToolSchema & {
|
|
60
|
+
cache_control?: CacheControl;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Tag the last block of the last message with cache_control. This is the
|
|
64
|
+
* rolling breakpoint that moves forward each turn — the second-to-last
|
|
65
|
+
* marker (set on the previous call) ages out into a regular cache prefix,
|
|
66
|
+
* which Anthropic will hit on the new call's read.
|
|
67
|
+
*
|
|
68
|
+
* Three message-shape cases:
|
|
69
|
+
* - last message is `{role, content: string}` → lift to a single text
|
|
70
|
+
* block with cache_control.
|
|
71
|
+
* - last message has a block array → shallow-clone the array and replace
|
|
72
|
+
* just the final block with a copy carrying cache_control.
|
|
73
|
+
* - empty content (defensive) → leave unchanged, no marker.
|
|
74
|
+
*
|
|
75
|
+
* Anthropic allows max 4 cache_control markers per request. With system
|
|
76
|
+
* + tools + this rolling one we sit at 3, leaving headroom; we still cap
|
|
77
|
+
* defensively in case a future change adds another slot.
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildCacheableMessages(messages: readonly ProviderMessage[]): ProviderMessage[];
|
|
80
|
+
export declare const __cacheBreakpointCap = 4;
|
|
81
|
+
/**
|
|
82
|
+
* Patch `body` with the Anthropic extended-thinking payload when a budget is
|
|
83
|
+
* supplied. No-op when `budget` is undefined / 0 — the model emits no
|
|
84
|
+
* reasoning chain, same as claude/codex with effort omitted.
|
|
85
|
+
*
|
|
86
|
+
* Anthropic requires `max_tokens > thinking.budget_tokens`; if the caller's
|
|
87
|
+
* max_tokens is too small we lift it past `budget + 1024` so the API doesn't
|
|
88
|
+
* reject the request. Caller's explicit ceiling wins when it's already
|
|
89
|
+
* larger — we never SHRINK max_tokens.
|
|
90
|
+
*
|
|
91
|
+
* Thinking is only valid on Claude Sonnet 4 / Opus 4 / Haiku 4.5 (and later).
|
|
92
|
+
* maestroRegistry currently only ships sonnet, so we don't gate on model id
|
|
93
|
+
* here; if Phase 5 multi-provider lands an older model, the provider for
|
|
94
|
+
* that model just ignores `thinkingBudget` (this helper is Anthropic-only).
|
|
95
|
+
*/
|
|
96
|
+
export declare function applyThinkingBudget(body: Record<string, unknown>, budget: number | undefined): void;
|
|
97
|
+
/**
|
|
98
|
+
* Map Clawgram's shared `EffortLevel` to an Anthropic thinking budget in
|
|
99
|
+
* tokens. Maestro only accepts `low|medium|high|xhigh` (see
|
|
100
|
+
* `MAESTRO_EFFORT_VALUES`); other values return undefined so the caller skips
|
|
101
|
+
* thinking entirely. Budget scale is a deliberate match for the rough
|
|
102
|
+
* progression claude-agent-sdk uses internally (the SDK doesn't expose its
|
|
103
|
+
* mapping, so these are calibrated empirically against the latency / cost
|
|
104
|
+
* curve we see on sonnet-4-6).
|
|
105
|
+
*/
|
|
106
|
+
export declare function effortToThinkingBudget(e: string | undefined): number | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Map effort to a per-turn tool-iteration cap. Used as `AIAgent.maxIterations`
|
|
109
|
+
* AND surfaced to the model via the per-iteration system-reminder so it can
|
|
110
|
+
* self-pace (low → wrap up fast, max → take your time).
|
|
111
|
+
*
|
|
112
|
+
* Lives next to `effortToThinkingBudget` for grep affinity even though the
|
|
113
|
+
* cap is provider-agnostic (the maestro loop owns it, not the API request).
|
|
114
|
+
* The Anthropic SDK / DeepSeek API themselves don't see this value; only the
|
|
115
|
+
* model does, through the reminder.
|
|
116
|
+
*
|
|
117
|
+
* Scale rationale:
|
|
118
|
+
* - `low` (5) — single Read + answer territory. Forces the wrap-up
|
|
119
|
+
* tone almost immediately so the model stops tooling early.
|
|
120
|
+
* - `medium` (20) — "research one thing then answer" budget.
|
|
121
|
+
* - `high` (50) — multi-file edits, moderate debugging chains.
|
|
122
|
+
* - `xhigh` (90) — matches the previous hard-coded default; extended
|
|
123
|
+
* exploration runs without hitting the cap.
|
|
124
|
+
* - `max` (200) — large refactors / deep delegations; rarely should
|
|
125
|
+
* reach this many turns in practice but the headroom exists.
|
|
126
|
+
*
|
|
127
|
+
* Unknown effort falls back to 90 (= `xhigh`) — keeps the loop running
|
|
128
|
+
* with the historical default rather than silently strangling it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function effortToMaxIter(e: string | undefined): number;
|
|
131
|
+
export {};
|
|
132
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,uBAAuB,EAEvB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAO1B;oEACoE;AACpE,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAwB1C;;;;;;;;;;GAUG;AACH,qBAAa,iBAAkB,YAAW,QAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C,MAAM,CAAC,OAAO,IAAI,iBAAiB;IAQ7B,QAAQ,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqDxE;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,IAAI,EAAE,uBAAuB,GAAG,cAAc,CAAC,mBAAmB,CAAC;CA+LlF;AA6ED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,YAAY,CAAA;CAAE,CAAC,CAG7E;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,kBAAkB,EAAE,GACnC,KAAK,CAAC,kBAAkB,GAAG;IAAE,aAAa,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC,CAO9D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,eAAe,EAAE,CA6B9F;AAGD,eAAO,MAAM,oBAAoB,IAAwB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,IAAI,CAMN;AAOD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAehF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAe7D"}
|
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
const ANTHROPIC_API_URL = "https://api.anthropic.com/v1/messages";
|
|
2
|
+
const ANTHROPIC_VERSION = "2023-06-01";
|
|
3
|
+
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
4
|
+
/** Anthropic accepts at most 4 cache_control markers per request. We use 3
|
|
5
|
+
* (system, tools, last message) — leaves headroom if a future change wants
|
|
6
|
+
* one more without restructuring the breakpoint plan. */
|
|
7
|
+
const MAX_CACHE_BREAKPOINTS = 4;
|
|
8
|
+
/**
|
|
9
|
+
* Raw Anthropic Messages API adapter for the Maestro TS port.
|
|
10
|
+
*
|
|
11
|
+
* Uses fetch directly (no @anthropic-ai/sdk dependency) — keeps the dep
|
|
12
|
+
* surface minimal and avoids overlap with Clawgram's existing
|
|
13
|
+
* @anthropic-ai/claude-agent-sdk usage (which is a higher-level wrapper
|
|
14
|
+
* around a claude CLI subprocess).
|
|
15
|
+
*
|
|
16
|
+
* Auth: ANTHROPIC_API_KEY env var. This is independent from Clawgram's
|
|
17
|
+
* existing Claude provider, which uses OAuth via the claude CLI.
|
|
18
|
+
*/
|
|
19
|
+
export class AnthropicProvider {
|
|
20
|
+
apiKey;
|
|
21
|
+
constructor(apiKey) {
|
|
22
|
+
this.apiKey = apiKey;
|
|
23
|
+
}
|
|
24
|
+
static fromEnv() {
|
|
25
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
26
|
+
if (!apiKey) {
|
|
27
|
+
throw new Error("Maestro AnthropicProvider: ANTHROPIC_API_KEY env var is not set");
|
|
28
|
+
}
|
|
29
|
+
return new AnthropicProvider(apiKey);
|
|
30
|
+
}
|
|
31
|
+
async complete(opts) {
|
|
32
|
+
// Apply prompt-caching breakpoints to the three slots Anthropic's cache
|
|
33
|
+
// recognizes (system, tools, last message). claude/codex SDKs do this
|
|
34
|
+
// internally; since maestro hits the API raw, we own it here.
|
|
35
|
+
//
|
|
36
|
+
// Cache hits drop input-token cost roughly 10× and shave hundreds of ms
|
|
37
|
+
// off TTFT for long-running multi-turn sessions — the same conversation
|
|
38
|
+
// re-sends the same system + tool schemas every iteration, and most of
|
|
39
|
+
// the prior history is stable across the agent loop's tool-round cycle.
|
|
40
|
+
//
|
|
41
|
+
// We rebuild the body each turn rather than mutating opts.messages in
|
|
42
|
+
// place so the persisted history (read back from JSONL on the next
|
|
43
|
+
// resume) stays free of stale cache_control markers.
|
|
44
|
+
const body = {
|
|
45
|
+
model: opts.model,
|
|
46
|
+
max_tokens: opts.maxTokens ?? 4096,
|
|
47
|
+
system: buildCacheableSystem(opts.system),
|
|
48
|
+
messages: buildCacheableMessages(opts.messages),
|
|
49
|
+
};
|
|
50
|
+
if (opts.tools && opts.tools.length > 0) {
|
|
51
|
+
body.tools = buildCacheableTools(opts.tools);
|
|
52
|
+
}
|
|
53
|
+
applyThinkingBudget(body, opts.thinkingBudget);
|
|
54
|
+
const headers = {
|
|
55
|
+
"content-type": "application/json",
|
|
56
|
+
"x-api-key": this.apiKey,
|
|
57
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
58
|
+
};
|
|
59
|
+
applyThinkingHeaders(headers, opts.thinkingBudget);
|
|
60
|
+
const init = {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers,
|
|
63
|
+
body: JSON.stringify(body),
|
|
64
|
+
};
|
|
65
|
+
if (opts.abortSignal) {
|
|
66
|
+
init.signal = opts.abortSignal;
|
|
67
|
+
}
|
|
68
|
+
const response = await fetch(ANTHROPIC_API_URL, init);
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
const text = await response.text();
|
|
71
|
+
throw new Error(`Anthropic API ${response.status}: ${text}`);
|
|
72
|
+
}
|
|
73
|
+
const data = (await response.json());
|
|
74
|
+
return {
|
|
75
|
+
content: data.content,
|
|
76
|
+
stopReason: data.stop_reason,
|
|
77
|
+
usage: mapUsage(data.usage),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Streaming variant of `complete()`. Sends the same request body with
|
|
82
|
+
* `stream: true`, parses the resulting SSE event stream into the small
|
|
83
|
+
* set of chunks the agent loop consumes (text_delta, tool_use_start /
|
|
84
|
+
* input_delta / complete, message_complete).
|
|
85
|
+
*
|
|
86
|
+
* The model's network shape is Anthropic SSE — events like
|
|
87
|
+
* `message_start`, `content_block_start`, `content_block_delta`,
|
|
88
|
+
* `content_block_stop`, `message_delta`, `message_stop`, plus periodic
|
|
89
|
+
* `ping` keepalives. Most are housekeeping; the loop only needs the
|
|
90
|
+
* deltas + tool_use lifecycle + terminal stop_reason / usage. Everything
|
|
91
|
+
* else is consumed and dropped by this adapter.
|
|
92
|
+
*/
|
|
93
|
+
async *stream(opts) {
|
|
94
|
+
const body = {
|
|
95
|
+
model: opts.model,
|
|
96
|
+
max_tokens: opts.maxTokens ?? 4096,
|
|
97
|
+
system: buildCacheableSystem(opts.system),
|
|
98
|
+
messages: buildCacheableMessages(opts.messages),
|
|
99
|
+
stream: true,
|
|
100
|
+
};
|
|
101
|
+
if (opts.tools && opts.tools.length > 0) {
|
|
102
|
+
body.tools = buildCacheableTools(opts.tools);
|
|
103
|
+
}
|
|
104
|
+
applyThinkingBudget(body, opts.thinkingBudget);
|
|
105
|
+
const headers = {
|
|
106
|
+
"content-type": "application/json",
|
|
107
|
+
"x-api-key": this.apiKey,
|
|
108
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
109
|
+
accept: "text/event-stream",
|
|
110
|
+
};
|
|
111
|
+
applyThinkingHeaders(headers, opts.thinkingBudget);
|
|
112
|
+
const init = {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers,
|
|
115
|
+
body: JSON.stringify(body),
|
|
116
|
+
};
|
|
117
|
+
if (opts.abortSignal) {
|
|
118
|
+
init.signal = opts.abortSignal;
|
|
119
|
+
}
|
|
120
|
+
const response = await fetch(ANTHROPIC_API_URL, init);
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
const text = await response.text();
|
|
123
|
+
throw new Error(`Anthropic API ${response.status}: ${text}`);
|
|
124
|
+
}
|
|
125
|
+
if (!response.body) {
|
|
126
|
+
throw new Error("Anthropic API: streaming response missing body");
|
|
127
|
+
}
|
|
128
|
+
// Per-block scratch space. Anthropic indexes content blocks by position
|
|
129
|
+
// in the assistant message; we key on that index so concurrent tool_use
|
|
130
|
+
// blocks (Anthropic allows parallel tool_use in a single response) get
|
|
131
|
+
// their input_json_delta routed to the right accumulator.
|
|
132
|
+
const blockMeta = new Map();
|
|
133
|
+
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
134
|
+
let stopReason = "end_turn";
|
|
135
|
+
for await (const event of parseSseStream(response.body, opts.abortSignal)) {
|
|
136
|
+
switch (event.type) {
|
|
137
|
+
case "message_start": {
|
|
138
|
+
// Initial usage comes here (input tokens + cache stats). output
|
|
139
|
+
// tokens still 0 — they accumulate via message_delta.
|
|
140
|
+
const u = asRecord(event.message)?.usage;
|
|
141
|
+
if (u) {
|
|
142
|
+
usage.inputTokens = u.input_tokens ?? 0;
|
|
143
|
+
usage.outputTokens = u.output_tokens ?? 0;
|
|
144
|
+
if (u.cache_creation_input_tokens !== undefined) {
|
|
145
|
+
usage.cacheCreationInputTokens = u.cache_creation_input_tokens;
|
|
146
|
+
}
|
|
147
|
+
if (u.cache_read_input_tokens !== undefined) {
|
|
148
|
+
usage.cacheReadInputTokens = u.cache_read_input_tokens;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "content_block_start": {
|
|
154
|
+
const idx = event.index ?? 0;
|
|
155
|
+
const cb = asRecord(event.content_block);
|
|
156
|
+
if (cb?.type === "text") {
|
|
157
|
+
blockMeta.set(idx, { type: "text" });
|
|
158
|
+
}
|
|
159
|
+
else if (cb?.type === "tool_use") {
|
|
160
|
+
const id = typeof cb.id === "string" ? cb.id : "";
|
|
161
|
+
const name = typeof cb.name === "string" ? cb.name : "";
|
|
162
|
+
blockMeta.set(idx, { type: "tool_use", id, name });
|
|
163
|
+
yield { type: "tool_use_start", id, name };
|
|
164
|
+
}
|
|
165
|
+
else if (cb?.type === "thinking") {
|
|
166
|
+
const meta = {
|
|
167
|
+
type: "thinking",
|
|
168
|
+
thinking: typeof cb.thinking === "string" ? cb.thinking : "",
|
|
169
|
+
};
|
|
170
|
+
if (typeof cb.signature === "string")
|
|
171
|
+
meta.signature = cb.signature;
|
|
172
|
+
blockMeta.set(idx, meta);
|
|
173
|
+
}
|
|
174
|
+
else if (cb?.type === "redacted_thinking") {
|
|
175
|
+
blockMeta.set(idx, {
|
|
176
|
+
type: "redacted_thinking",
|
|
177
|
+
data: typeof cb.data === "string" ? cb.data : "",
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "content_block_delta": {
|
|
183
|
+
const idx = event.index ?? 0;
|
|
184
|
+
const meta = blockMeta.get(idx);
|
|
185
|
+
const delta = asRecord(event.delta);
|
|
186
|
+
if (!meta || !delta)
|
|
187
|
+
break;
|
|
188
|
+
if (meta.type === "text" && delta.type === "text_delta" && delta.text) {
|
|
189
|
+
yield { type: "text_delta", text: String(delta.text) };
|
|
190
|
+
}
|
|
191
|
+
else if (meta.type === "tool_use" &&
|
|
192
|
+
delta.type === "input_json_delta" &&
|
|
193
|
+
typeof delta.partial_json === "string") {
|
|
194
|
+
yield {
|
|
195
|
+
type: "tool_use_input_delta",
|
|
196
|
+
id: meta.id ?? "",
|
|
197
|
+
partial_json: delta.partial_json,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
else if (meta.type === "thinking" &&
|
|
201
|
+
delta.type === "thinking_delta" &&
|
|
202
|
+
typeof delta.thinking === "string") {
|
|
203
|
+
meta.thinking = `${meta.thinking ?? ""}${delta.thinking}`;
|
|
204
|
+
}
|
|
205
|
+
else if (meta.type === "thinking" &&
|
|
206
|
+
delta.type === "signature_delta" &&
|
|
207
|
+
typeof delta.signature === "string") {
|
|
208
|
+
meta.signature = `${meta.signature ?? ""}${delta.signature}`;
|
|
209
|
+
}
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case "content_block_stop": {
|
|
213
|
+
const idx = event.index ?? 0;
|
|
214
|
+
const meta = blockMeta.get(idx);
|
|
215
|
+
if (meta?.type === "tool_use") {
|
|
216
|
+
yield {
|
|
217
|
+
type: "tool_use_complete",
|
|
218
|
+
id: meta.id ?? "",
|
|
219
|
+
name: meta.name ?? "",
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
else if (meta?.type === "thinking") {
|
|
223
|
+
yield {
|
|
224
|
+
type: "thinking_complete",
|
|
225
|
+
block: {
|
|
226
|
+
type: "thinking",
|
|
227
|
+
thinking: meta.thinking ?? "",
|
|
228
|
+
...(meta.signature ? { signature: meta.signature } : {}),
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
else if (meta?.type === "redacted_thinking") {
|
|
233
|
+
yield {
|
|
234
|
+
type: "thinking_complete",
|
|
235
|
+
block: { type: "redacted_thinking", data: meta.data ?? "" },
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "message_delta": {
|
|
241
|
+
// Carries final stop_reason + cumulative output usage.
|
|
242
|
+
const delta = asRecord(event.delta);
|
|
243
|
+
if (typeof delta?.stop_reason === "string")
|
|
244
|
+
stopReason = delta.stop_reason;
|
|
245
|
+
const u = event.usage;
|
|
246
|
+
if (u?.output_tokens !== undefined)
|
|
247
|
+
usage.outputTokens = u.output_tokens;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case "message_stop": {
|
|
251
|
+
// Anthropic's "we're done" marker. Emit the terminal chunk.
|
|
252
|
+
yield { type: "message_complete", stopReason, usage };
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
case "error": {
|
|
256
|
+
const err = event.error;
|
|
257
|
+
throw new Error(`Anthropic stream error: ${err?.type ?? "unknown"} — ${err?.message ?? ""}`);
|
|
258
|
+
}
|
|
259
|
+
default:
|
|
260
|
+
// ping, etc. — ignore.
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Stream ended without an explicit message_stop (server hung up cleanly).
|
|
265
|
+
// Emit a terminal chunk anyway so the loop can finalize its turn.
|
|
266
|
+
yield { type: "message_complete", stopReason, usage };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function asRecord(value) {
|
|
270
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
271
|
+
? value
|
|
272
|
+
: null;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Parse Anthropic's `text/event-stream` response body into typed SSE events.
|
|
276
|
+
*
|
|
277
|
+
* Anthropic frames each event as
|
|
278
|
+
* event: <type>\ndata: <json>\n\n
|
|
279
|
+
* We buffer across chunk boundaries, split on the blank-line terminator,
|
|
280
|
+
* and JSON-parse the `data:` payload. The `event:` line is informational
|
|
281
|
+
* (Anthropic always also embeds the type inside the JSON), so we trust
|
|
282
|
+
* the `data` payload's `type` field as the authoritative event type —
|
|
283
|
+
* matches what the official SDKs do.
|
|
284
|
+
*
|
|
285
|
+
* The abort signal is honored by aborting the underlying ReadableStream
|
|
286
|
+
* reader, which propagates AbortError up into the caller.
|
|
287
|
+
*/
|
|
288
|
+
async function* parseSseStream(body, abortSignal) {
|
|
289
|
+
const reader = body.getReader();
|
|
290
|
+
const decoder = new TextDecoder("utf-8");
|
|
291
|
+
let buf = "";
|
|
292
|
+
const onAbort = () => {
|
|
293
|
+
reader.cancel("aborted").catch(() => { });
|
|
294
|
+
};
|
|
295
|
+
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
296
|
+
try {
|
|
297
|
+
while (true) {
|
|
298
|
+
const { value, done } = await reader.read();
|
|
299
|
+
if (done)
|
|
300
|
+
break;
|
|
301
|
+
buf += decoder.decode(value, { stream: true });
|
|
302
|
+
// Drain every complete event (terminated by a blank line).
|
|
303
|
+
let idx = buf.indexOf("\n\n");
|
|
304
|
+
while (idx >= 0) {
|
|
305
|
+
const raw = buf.slice(0, idx);
|
|
306
|
+
buf = buf.slice(idx + 2);
|
|
307
|
+
const dataLine = raw
|
|
308
|
+
.split("\n")
|
|
309
|
+
.find((l) => l.startsWith("data:"))
|
|
310
|
+
?.slice("data:".length)
|
|
311
|
+
.trim();
|
|
312
|
+
if (dataLine) {
|
|
313
|
+
try {
|
|
314
|
+
yield JSON.parse(dataLine);
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
// Malformed frame — skip rather than abort the stream; Anthropic
|
|
318
|
+
// shouldn't emit these but defensive parsing avoids one bad byte
|
|
319
|
+
// taking down a whole turn.
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
idx = buf.indexOf("\n\n");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
finally {
|
|
327
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
328
|
+
reader.releaseLock();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Convert the user-supplied `system` (plain string) into the array shape
|
|
333
|
+
* Anthropic accepts when you need a cache_control marker. A string slot
|
|
334
|
+
* has no cache field, so we lift it into a single text block and tag it
|
|
335
|
+
* ephemeral. Returning the original string unchanged when it's empty keeps
|
|
336
|
+
* the request shape minimal for prompt-less calls.
|
|
337
|
+
*/
|
|
338
|
+
export function buildCacheableSystem(system) {
|
|
339
|
+
if (!system || system.length === 0)
|
|
340
|
+
return system;
|
|
341
|
+
return [{ type: "text", text: system, cache_control: { type: "ephemeral" } }];
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Tag the last tool with cache_control so the (usually large) tool schema
|
|
345
|
+
* block lands in the cache after the first turn. Other tools are passed
|
|
346
|
+
* through verbatim — Anthropic caches the entire tools array prefix up to
|
|
347
|
+
* the last marker, so one breakpoint covers every preceding entry.
|
|
348
|
+
*
|
|
349
|
+
* Returns a new array; the caller's `opts.tools` reference is untouched so
|
|
350
|
+
* subsequent calls don't accumulate markers.
|
|
351
|
+
*/
|
|
352
|
+
export function buildCacheableTools(tools) {
|
|
353
|
+
if (tools.length === 0)
|
|
354
|
+
return [];
|
|
355
|
+
const out = tools.map((t) => ({
|
|
356
|
+
...t,
|
|
357
|
+
}));
|
|
358
|
+
out[out.length - 1] = { ...out[out.length - 1], cache_control: { type: "ephemeral" } };
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Tag the last block of the last message with cache_control. This is the
|
|
363
|
+
* rolling breakpoint that moves forward each turn — the second-to-last
|
|
364
|
+
* marker (set on the previous call) ages out into a regular cache prefix,
|
|
365
|
+
* which Anthropic will hit on the new call's read.
|
|
366
|
+
*
|
|
367
|
+
* Three message-shape cases:
|
|
368
|
+
* - last message is `{role, content: string}` → lift to a single text
|
|
369
|
+
* block with cache_control.
|
|
370
|
+
* - last message has a block array → shallow-clone the array and replace
|
|
371
|
+
* just the final block with a copy carrying cache_control.
|
|
372
|
+
* - empty content (defensive) → leave unchanged, no marker.
|
|
373
|
+
*
|
|
374
|
+
* Anthropic allows max 4 cache_control markers per request. With system
|
|
375
|
+
* + tools + this rolling one we sit at 3, leaving headroom; we still cap
|
|
376
|
+
* defensively in case a future change adds another slot.
|
|
377
|
+
*/
|
|
378
|
+
export function buildCacheableMessages(messages) {
|
|
379
|
+
if (messages.length === 0)
|
|
380
|
+
return [];
|
|
381
|
+
const out = messages.map((m) => m);
|
|
382
|
+
const lastIdx = out.length - 1;
|
|
383
|
+
const last = out[lastIdx];
|
|
384
|
+
if (typeof last.content === "string") {
|
|
385
|
+
if (last.content.length === 0)
|
|
386
|
+
return out;
|
|
387
|
+
out[lastIdx] = {
|
|
388
|
+
role: last.role,
|
|
389
|
+
content: [
|
|
390
|
+
{
|
|
391
|
+
type: "text",
|
|
392
|
+
text: last.content,
|
|
393
|
+
cache_control: { type: "ephemeral" },
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
};
|
|
397
|
+
return out;
|
|
398
|
+
}
|
|
399
|
+
if (Array.isArray(last.content) && last.content.length > 0) {
|
|
400
|
+
const blocks = [...last.content];
|
|
401
|
+
const tailIdx = blocks.length - 1;
|
|
402
|
+
blocks[tailIdx] = {
|
|
403
|
+
...blocks[tailIdx],
|
|
404
|
+
cache_control: { type: "ephemeral" },
|
|
405
|
+
};
|
|
406
|
+
out[lastIdx] = { role: last.role, content: blocks };
|
|
407
|
+
}
|
|
408
|
+
return out;
|
|
409
|
+
}
|
|
410
|
+
// Export the cap so tests can assert we don't drift past Anthropic's limit.
|
|
411
|
+
export const __cacheBreakpointCap = MAX_CACHE_BREAKPOINTS;
|
|
412
|
+
/**
|
|
413
|
+
* Patch `body` with the Anthropic extended-thinking payload when a budget is
|
|
414
|
+
* supplied. No-op when `budget` is undefined / 0 — the model emits no
|
|
415
|
+
* reasoning chain, same as claude/codex with effort omitted.
|
|
416
|
+
*
|
|
417
|
+
* Anthropic requires `max_tokens > thinking.budget_tokens`; if the caller's
|
|
418
|
+
* max_tokens is too small we lift it past `budget + 1024` so the API doesn't
|
|
419
|
+
* reject the request. Caller's explicit ceiling wins when it's already
|
|
420
|
+
* larger — we never SHRINK max_tokens.
|
|
421
|
+
*
|
|
422
|
+
* Thinking is only valid on Claude Sonnet 4 / Opus 4 / Haiku 4.5 (and later).
|
|
423
|
+
* maestroRegistry currently only ships sonnet, so we don't gate on model id
|
|
424
|
+
* here; if Phase 5 multi-provider lands an older model, the provider for
|
|
425
|
+
* that model just ignores `thinkingBudget` (this helper is Anthropic-only).
|
|
426
|
+
*/
|
|
427
|
+
export function applyThinkingBudget(body, budget) {
|
|
428
|
+
if (!budget || budget <= 0)
|
|
429
|
+
return;
|
|
430
|
+
body.thinking = { type: "enabled", budget_tokens: budget };
|
|
431
|
+
const minMax = budget + 1024;
|
|
432
|
+
const current = typeof body.max_tokens === "number" ? body.max_tokens : 0;
|
|
433
|
+
if (current < minMax)
|
|
434
|
+
body.max_tokens = minMax;
|
|
435
|
+
}
|
|
436
|
+
function applyThinkingHeaders(headers, budget) {
|
|
437
|
+
if (!budget || budget <= 0)
|
|
438
|
+
return;
|
|
439
|
+
headers["anthropic-beta"] = INTERLEAVED_THINKING_BETA;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Map Clawgram's shared `EffortLevel` to an Anthropic thinking budget in
|
|
443
|
+
* tokens. Maestro only accepts `low|medium|high|xhigh` (see
|
|
444
|
+
* `MAESTRO_EFFORT_VALUES`); other values return undefined so the caller skips
|
|
445
|
+
* thinking entirely. Budget scale is a deliberate match for the rough
|
|
446
|
+
* progression claude-agent-sdk uses internally (the SDK doesn't expose its
|
|
447
|
+
* mapping, so these are calibrated empirically against the latency / cost
|
|
448
|
+
* curve we see on sonnet-4-6).
|
|
449
|
+
*/
|
|
450
|
+
export function effortToThinkingBudget(e) {
|
|
451
|
+
switch (e) {
|
|
452
|
+
case "low":
|
|
453
|
+
return 2048;
|
|
454
|
+
case "medium":
|
|
455
|
+
return 8192;
|
|
456
|
+
case "high":
|
|
457
|
+
return 16384;
|
|
458
|
+
case "xhigh":
|
|
459
|
+
return 32768;
|
|
460
|
+
case "max":
|
|
461
|
+
return 65536;
|
|
462
|
+
default:
|
|
463
|
+
return undefined;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Map effort to a per-turn tool-iteration cap. Used as `AIAgent.maxIterations`
|
|
468
|
+
* AND surfaced to the model via the per-iteration system-reminder so it can
|
|
469
|
+
* self-pace (low → wrap up fast, max → take your time).
|
|
470
|
+
*
|
|
471
|
+
* Lives next to `effortToThinkingBudget` for grep affinity even though the
|
|
472
|
+
* cap is provider-agnostic (the maestro loop owns it, not the API request).
|
|
473
|
+
* The Anthropic SDK / DeepSeek API themselves don't see this value; only the
|
|
474
|
+
* model does, through the reminder.
|
|
475
|
+
*
|
|
476
|
+
* Scale rationale:
|
|
477
|
+
* - `low` (5) — single Read + answer territory. Forces the wrap-up
|
|
478
|
+
* tone almost immediately so the model stops tooling early.
|
|
479
|
+
* - `medium` (20) — "research one thing then answer" budget.
|
|
480
|
+
* - `high` (50) — multi-file edits, moderate debugging chains.
|
|
481
|
+
* - `xhigh` (90) — matches the previous hard-coded default; extended
|
|
482
|
+
* exploration runs without hitting the cap.
|
|
483
|
+
* - `max` (200) — large refactors / deep delegations; rarely should
|
|
484
|
+
* reach this many turns in practice but the headroom exists.
|
|
485
|
+
*
|
|
486
|
+
* Unknown effort falls back to 90 (= `xhigh`) — keeps the loop running
|
|
487
|
+
* with the historical default rather than silently strangling it.
|
|
488
|
+
*/
|
|
489
|
+
export function effortToMaxIter(e) {
|
|
490
|
+
switch (e) {
|
|
491
|
+
case "low":
|
|
492
|
+
return 5;
|
|
493
|
+
case "medium":
|
|
494
|
+
return 20;
|
|
495
|
+
case "high":
|
|
496
|
+
return 50;
|
|
497
|
+
case "xhigh":
|
|
498
|
+
return 90;
|
|
499
|
+
case "max":
|
|
500
|
+
return 200;
|
|
501
|
+
default:
|
|
502
|
+
return 90;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function mapUsage(u) {
|
|
506
|
+
const out = {
|
|
507
|
+
inputTokens: u.input_tokens,
|
|
508
|
+
outputTokens: u.output_tokens,
|
|
509
|
+
};
|
|
510
|
+
if (u.cache_creation_input_tokens !== undefined) {
|
|
511
|
+
out.cacheCreationInputTokens = u.cache_creation_input_tokens;
|
|
512
|
+
}
|
|
513
|
+
if (u.cache_read_input_tokens !== undefined) {
|
|
514
|
+
out.cacheReadInputTokens = u.cache_read_input_tokens;
|
|
515
|
+
}
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
//# sourceMappingURL=anthropic.js.map
|