strands-darwin 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/dist/patches/{@strands-agents+sdk+1.16.0.patch → @strands-agents+sdk+1.18.0.patch} +320 -9
- package/dist/src/agent/compact.js +1 -1
- package/dist/src/agent/runtime.d.ts +17 -10
- package/dist/src/agent/runtime.js +36 -11
- package/dist/src/agent/runtime.js.map +1 -1
- package/dist/src/agent/system-prompt.d.ts +1 -1
- package/dist/src/agent/system-prompt.js +12 -0
- package/dist/src/agent/system-prompt.js.map +1 -1
- package/dist/src/agent/task-terminal-delivery.d.ts +25 -2
- package/dist/src/agent/task-terminal-delivery.js +80 -7
- package/dist/src/agent/task-terminal-delivery.js.map +1 -1
- package/dist/src/npm-package/patch-package-format.d.ts +5 -5
- package/dist/src/npm-package/patch-package-format.js +4 -4
- package/dist/src/sdk-patch-preflight.js +1 -1
- package/dist/src/skills/builtin/developer/SKILL.md +2 -0
- package/dist/src/skills/builtin/self-reflection/references/reflection-template.md +2 -1
- package/dist/src/tools/background-bash.d.ts +7 -1
- package/dist/src/tools/background-bash.js +10 -8
- package/dist/src/tools/background-bash.js.map +1 -1
- package/dist/src/trajectory/record.d.ts +50 -2
- package/dist/src/trajectory/record.js +32 -0
- package/dist/src/trajectory/record.js.map +1 -1
- package/dist/src/trajectory/replay.d.ts +12 -1
- package/dist/src/trajectory/replay.js +31 -2
- package/dist/src/trajectory/replay.js.map +1 -1
- package/dist/src/trajectory/writer.d.ts +14 -1
- package/dist/src/trajectory/writer.js +38 -0
- package/dist/src/trajectory/writer.js.map +1 -1
- package/dist/src/tui/InputBox.js +2 -1
- package/dist/src/tui/InputBox.js.map +1 -1
- package/dist/src/tui/prompt-editor.js +19 -9
- package/dist/src/tui/prompt-editor.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
<p>A terminal coding agent that improves by using each accepted revision to build the next one.</p>
|
|
4
4
|
<p><strong>English</strong> · <a href="README.zh-CN.md">简体中文</a></p>
|
|
5
5
|
<p>
|
|
6
|
-
<a href="https://nodejs.org/"><img alt="Node.js >=
|
|
6
|
+
<a href="https://nodejs.org/"><img alt="Node.js >=22.0.0" src="https://img.shields.io/badge/Node.js-%3E%3D22.0.0-339933?logo=nodedotjs&logoColor=white"></a>
|
|
7
7
|
<a href="https://www.typescriptlang.org/"><img alt="TypeScript 7.0.2" src="https://img.shields.io/badge/TypeScript-7.0.2-3178C6?logo=typescript&logoColor=white"></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/@strands-agents/sdk"><img alt="Strands Agents SDK 1.
|
|
8
|
+
<a href="https://www.npmjs.com/package/@strands-agents/sdk"><img alt="Strands Agents SDK 1.18.0" src="https://img.shields.io/badge/Strands_Agents_SDK-1.18.0-5E4AE3"></a>
|
|
9
9
|
<a href="https://spdx.org/licenses/ISC.html"><img alt="ISC License" src="https://img.shields.io/badge/License-ISC-blue.svg"></a>
|
|
10
10
|
</p>
|
|
11
11
|
<img src="docs/images/welcome.png" alt="darwin terminal welcome screen" width="100%">
|
|
@@ -51,7 +51,7 @@ The agent loop remains the Strands SDK loop. darwin assembles SDK models, interv
|
|
|
51
51
|
|
|
52
52
|
## Install and start
|
|
53
53
|
|
|
54
|
-
Requirements: Node.js
|
|
54
|
+
Requirements: Node.js 22.0+, npm, and credentials for your configured provider (AWS by default).
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
57
|
npm install -g strands-darwin
|
package/README.zh-CN.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
<p>一款在终端中运行的编程代理:每次通过验收的版本,都会成为开发下一版的工具。</p>
|
|
4
4
|
<p><a href="README.md">English</a> · <strong>简体中文</strong></p>
|
|
5
5
|
<p>
|
|
6
|
-
<a href="https://nodejs.org/"><img alt="Node.js >=
|
|
6
|
+
<a href="https://nodejs.org/"><img alt="Node.js >=22.0.0" src="https://img.shields.io/badge/Node.js-%3E%3D22.0.0-339933?logo=nodedotjs&logoColor=white"></a>
|
|
7
7
|
<a href="https://www.typescriptlang.org/"><img alt="TypeScript 7.0.2" src="https://img.shields.io/badge/TypeScript-7.0.2-3178C6?logo=typescript&logoColor=white"></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/@strands-agents/sdk"><img alt="Strands Agents SDK 1.
|
|
8
|
+
<a href="https://www.npmjs.com/package/@strands-agents/sdk"><img alt="Strands Agents SDK 1.18.0" src="https://img.shields.io/badge/Strands_Agents_SDK-1.18.0-5E4AE3"></a>
|
|
9
9
|
<a href="https://spdx.org/licenses/ISC.html"><img alt="ISC License" src="https://img.shields.io/badge/License-ISC-blue.svg"></a>
|
|
10
10
|
</p>
|
|
11
11
|
<img src="docs/images/welcome.png" alt="darwin 终端欢迎界面" width="100%">
|
|
@@ -51,7 +51,7 @@ darwin 不会另写一套代理循环。它沿用 Strands SDK 的循环,只负
|
|
|
51
51
|
|
|
52
52
|
## 安装与启动
|
|
53
53
|
|
|
54
|
-
需要 Node.js
|
|
54
|
+
需要 Node.js 22.0+、npm,以及所选模型供应商的凭证(默认使用 AWS)。
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
57
|
npm install -g strands-darwin
|
|
@@ -21,22 +21,22 @@ index 84e3d1bb0bcd499d3dd2cd07c08baa79807ca79c..7e1c407bb04714309226c40b5daa0082
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
diff --git a/node_modules/@strands-agents/sdk/dist/src/index.d.ts b/node_modules/@strands-agents/sdk/dist/src/index.d.ts
|
|
24
|
-
index
|
|
24
|
+
index 416fa4a6d2a29417506588e05f95562bc7f3aa79..62e02b408b78ef5ade04ecd24478031331b6b1e4 100644
|
|
25
25
|
--- a/node_modules/@strands-agents/sdk/dist/src/index.d.ts
|
|
26
26
|
+++ b/node_modules/@strands-agents/sdk/dist/src/index.d.ts
|
|
27
|
-
@@ -
|
|
27
|
+
@@ -64,6 +64,7 @@ export { ConversationManager, type ProactiveCompressionConfig, type Conversation
|
|
28
28
|
export { NullConversationManager } from './conversation-manager/null-conversation-manager.js';
|
|
29
29
|
export { SlidingWindowConversationManager, type SlidingWindowConversationManagerConfig, } from './conversation-manager/sliding-window-conversation-manager.js';
|
|
30
30
|
export { SummarizingConversationManager, type SummarizingConversationManagerConfig, } from './conversation-manager/summarizing-conversation-manager.js';
|
|
31
31
|
+export { DEFAULT_SUMMARIZATION_PROMPT } from './conversation-manager/compression/context-compression.js';
|
|
32
32
|
export { configureLogging } from './logging/logger.js';
|
|
33
33
|
export type { Logger } from './logging/types.js';
|
|
34
|
-
export { type McpClientOptions, type McpListToolsOptions, type McpToolFilterCallback, type McpToolFilters, type McpToolMatcher, type McpClientConfig, type McpClientCredentials, type McpTransport, type McpCallToolOptions, type TasksConfig, type McpConnectionState, type McpServerConfig, type SerializableMcpToolFilters, McpClient, } from './mcp/index.js';
|
|
34
|
+
export { type McpClientOptions, type McpListToolsOptions, type McpToolFilterCallback, type McpToolFilters, type McpToolMatcher, type McpClientConfig, type McpClientCredentials, type McpTransport, type McpCallToolOptions, type TasksConfig, type McpConnectionState, type McpLoadServersOptions, type McpServerConfig, type SerializableMcpToolFilters, McpClient, } from './mcp/index.js';
|
|
35
35
|
diff --git a/node_modules/@strands-agents/sdk/dist/src/index.js b/node_modules/@strands-agents/sdk/dist/src/index.js
|
|
36
|
-
index
|
|
36
|
+
index 1ffe683b6944318f8524c231674eabcf8428f89f..ea8dfa7ae5d5cfb3166a6e23afe3042d59b8973f 100644
|
|
37
37
|
--- a/node_modules/@strands-agents/sdk/dist/src/index.js
|
|
38
38
|
+++ b/node_modules/@strands-agents/sdk/dist/src/index.js
|
|
39
|
-
@@ -
|
|
39
|
+
@@ -53,6 +53,7 @@ export { ConversationManager, } from './conversation-manager/conversation-manage
|
|
40
40
|
export { NullConversationManager } from './conversation-manager/null-conversation-manager.js';
|
|
41
41
|
export { SlidingWindowConversationManager, } from './conversation-manager/sliding-window-conversation-manager.js';
|
|
42
42
|
export { SummarizingConversationManager, } from './conversation-manager/summarizing-conversation-manager.js';
|
|
@@ -44,6 +44,63 @@ index 3cb62b859eba690822bbd8fb1c2c9388cd151394..4a1febbd5752dc4bb0cbba24b0695c5c
|
|
|
44
44
|
// Logging
|
|
45
45
|
export { configureLogging } from './logging/logger.js';
|
|
46
46
|
// MCP Client types and implementations
|
|
47
|
+
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/anthropic.js b/node_modules/@strands-agents/sdk/dist/src/models/anthropic.js
|
|
48
|
+
index ffbbb3d5d8a29ac0e21ffd2409658e1f69850492..ff1f3cac332a260fef809d318c11062de78ce3d8 100644
|
|
49
|
+
--- a/node_modules/@strands-agents/sdk/dist/src/models/anthropic.js
|
|
50
|
+
+++ b/node_modules/@strands-agents/sdk/dist/src/models/anthropic.js
|
|
51
|
+
@@ -560,6 +560,11 @@ export class AnthropicModel extends Model {
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
case 'reasoningBlock':
|
|
55
|
+
+ // darwin patch (SER-101): Responses-origin reasoning carries a
|
|
56
|
+
+ // provenance tag, not an Anthropic signature; never send it.
|
|
57
|
+
+ if (typeof block.signature === 'string' && block.signature.startsWith('darwin-responses:')) {
|
|
58
|
+
+ return undefined;
|
|
59
|
+
+ }
|
|
60
|
+
if (block.signature) {
|
|
61
|
+
return {
|
|
62
|
+
type: 'thinking',
|
|
63
|
+
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/bedrock.js b/node_modules/@strands-agents/sdk/dist/src/models/bedrock.js
|
|
64
|
+
index e9efcc8ba832b878ec4b1ec0350e8ce6bf5b0e5b..0ff2da8f0256a9a6fa0a1153e868cfa53c9104a8 100644
|
|
65
|
+
--- a/node_modules/@strands-agents/sdk/dist/src/models/bedrock.js
|
|
66
|
+
+++ b/node_modules/@strands-agents/sdk/dist/src/models/bedrock.js
|
|
67
|
+
@@ -944,6 +944,19 @@ export class BedrockModel extends Model {
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
case 'reasoningBlock': {
|
|
71
|
+
+ // darwin patch (SER-101): Responses-origin reasoning (provenance tag in
|
|
72
|
+
+ // `signature`) is never sent to Converse, and a Claude model rejects a
|
|
73
|
+
+ // signature-less thinking block (`thinking.signature: Field required`),
|
|
74
|
+
+ // which is what another Converse model's reasoning (Kimi) carries.
|
|
75
|
+
+ if (typeof block.signature === 'string' && block.signature.startsWith('darwin-responses:')) {
|
|
76
|
+
+ return undefined;
|
|
77
|
+
+ }
|
|
78
|
+
+ if (block.signature === undefined &&
|
|
79
|
+
+ !block.redactedContent &&
|
|
80
|
+
+ /anthropic|claude/i.test(this._config.modelId ?? '')) {
|
|
81
|
+
+ logger.debug(`model_id=<${this._config.modelId}> | signature-less reasoning | dropping`);
|
|
82
|
+
+ return undefined;
|
|
83
|
+
+ }
|
|
84
|
+
if (block.text !== undefined || block.signature !== undefined) {
|
|
85
|
+
return {
|
|
86
|
+
reasoningContent: {
|
|
87
|
+
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/openai/chat-adapter.js b/node_modules/@strands-agents/sdk/dist/src/models/openai/chat-adapter.js
|
|
88
|
+
index fb16b465262638c7d97e874156058a856174752c..0ff778d68eaea576279c6850cf6a708386496261 100644
|
|
89
|
+
--- a/node_modules/@strands-agents/sdk/dist/src/models/openai/chat-adapter.js
|
|
90
|
+
+++ b/node_modules/@strands-agents/sdk/dist/src/models/openai/chat-adapter.js
|
|
91
|
+
@@ -242,6 +242,12 @@ function formatChatMessages(messages) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'reasoningBlock': {
|
|
95
|
+
+ // darwin patch (SER-101): Responses-origin reasoning is never
|
|
96
|
+
+ // sent to another model, not even as text.
|
|
97
|
+
+ if (typeof block.signature === 'string' && block.signature.startsWith('darwin-responses:')) {
|
|
98
|
+
+ logger.debug('block_type=<reasoningBlock> | responses-origin reasoning | dropping');
|
|
99
|
+
+ break;
|
|
100
|
+
+ }
|
|
101
|
+
if (block.text) {
|
|
102
|
+
logger.warn('block_type=<reasoningBlock> | reasoning blocks not supported by openai | converting to text');
|
|
103
|
+
textParts.push(block.text);
|
|
47
104
|
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/openai/errors.js b/node_modules/@strands-agents/sdk/dist/src/models/openai/errors.js
|
|
48
105
|
index 17a473fe3bcdcc02e17cd95283c832d9021634c1..6e5cda23f672684b3926450322459279e2355066 100644
|
|
49
106
|
--- a/node_modules/@strands-agents/sdk/dist/src/models/openai/errors.js
|
|
@@ -56,23 +113,202 @@ index 17a473fe3bcdcc02e17cd95283c832d9021634c1..6e5cda23f672684b3926450322459279
|
|
|
56
113
|
];
|
|
57
114
|
/**
|
|
58
115
|
* Error patterns that indicate rate limiting.
|
|
116
|
+
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/openai/model.js b/node_modules/@strands-agents/sdk/dist/src/models/openai/model.js
|
|
117
|
+
index e7db2ccc3d5d8cff7b27dbb5b5f46cdaf9a4de1b..d9881fb1d81a3cbd9e092591d8757023817ef6c7 100644
|
|
118
|
+
--- a/node_modules/@strands-agents/sdk/dist/src/models/openai/model.js
|
|
119
|
+
+++ b/node_modules/@strands-agents/sdk/dist/src/models/openai/model.js
|
|
120
|
+
@@ -196,7 +196,7 @@ export class OpenAIModel extends Model {
|
|
121
|
+
try {
|
|
122
|
+
const request = formatResponsesRequest(this._config, messages, options, this.stateful);
|
|
123
|
+
const stream = await this._client.responses.create(request, { signal: options?.cancelSignal });
|
|
124
|
+
- const state = createResponsesStreamState();
|
|
125
|
+
+ const state = createResponsesStreamState(request.model);
|
|
126
|
+
for await (const event of stream) {
|
|
127
|
+
for (const sdkEvent of mapResponsesEventToSDK(event, state, this.stateful, options?.modelState)) {
|
|
128
|
+
yield sdkEvent;
|
|
59
129
|
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.d.ts b/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.d.ts
|
|
60
|
-
index e17f00ac284c1e3357d55205c57b431061141b55..
|
|
130
|
+
index e17f00ac284c1e3357d55205c57b431061141b55..655e065df9823e8897759978a46cac8b2bee9d79 100644
|
|
61
131
|
--- a/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.d.ts
|
|
62
132
|
+++ b/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.d.ts
|
|
63
|
-
@@ -52,
|
|
133
|
+
@@ -52,15 +52,35 @@ export interface ResponsesStreamState {
|
|
64
134
|
outputTokens: number;
|
|
65
135
|
totalTokens: number;
|
|
66
136
|
cacheReadInputTokens?: number;
|
|
67
137
|
+ cacheWriteInputTokens?: number;
|
|
68
138
|
} | null;
|
|
69
139
|
stopReason: StopReason;
|
|
140
|
+
+ /** darwin patch (SER-101): request model id that tags captured reasoning. */
|
|
141
|
+
+ modelId?: string | undefined;
|
|
142
|
+
+ /** darwin patch (SER-101): what the open reasoning block streamed. */
|
|
143
|
+
+ reasoningKind?: 'text' | 'sum' | undefined;
|
|
70
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Creates fresh stream state for a new Responses API stream.
|
|
147
|
+
*
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
-export declare function createResponsesStreamState(): ResponsesStreamState;
|
|
151
|
+
+export declare function createResponsesStreamState(modelId?: string): ResponsesStreamState;
|
|
152
|
+
+/** darwin patch (SER-101): the provenance tag prefix carried in `ReasoningBlock.signature`. */
|
|
153
|
+
+export declare const RESPONSES_REASONING_TAG = "darwin-responses:v1:";
|
|
154
|
+
+/** darwin patch (SER-101): one tagged kind; `enc` carries the opaque `encrypted_content`. */
|
|
155
|
+
+export type ResponsesReasoningTag = {
|
|
156
|
+
+ modelId: string;
|
|
157
|
+
+ kind: 'text' | 'sum';
|
|
158
|
+
+} | {
|
|
159
|
+
+ modelId: string;
|
|
160
|
+
+ kind: 'enc';
|
|
161
|
+
+ encryptedContent: string;
|
|
162
|
+
+};
|
|
163
|
+
+/** @internal */
|
|
164
|
+
+export declare function encodeResponsesReasoningSignature(modelId: string, kind: 'text' | 'sum' | 'enc', encryptedContent?: string): string;
|
|
165
|
+
+/** @internal */
|
|
166
|
+
+export declare function parseResponsesReasoningSignature(signature: unknown): ResponsesReasoningTag | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Maps a single Responses API stream event to zero or more SDK events. Mutates
|
|
169
|
+
* `state` and, when `stateful` is `true`, writes `responseId` into `modelState`.
|
|
71
170
|
diff --git a/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.js b/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.js
|
|
72
|
-
index
|
|
171
|
+
index 9605eb256daa6aebf7dddea2f745d44bdf6f6970..76fb886e50ccbe1faa4bfb5208b82d64cbe84510 100644
|
|
73
172
|
--- a/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.js
|
|
74
173
|
+++ b/node_modules/@strands-agents/sdk/dist/src/models/openai/responses-adapter.js
|
|
75
|
-
@@ -
|
|
174
|
+
@@ -21,6 +21,72 @@ import { formatImageDataUrl, warnManagedParams as warnManagedParamsShared } from
|
|
175
|
+
import { applyCacheConfig } from './cache.js';
|
|
176
|
+
export const DEFAULT_RESPONSES_MODEL_ID = MODEL_DEFAULTS.openai.modelId;
|
|
177
|
+
const MANAGED_PARAMS = new Set(['model', 'input', 'stream', 'store']);
|
|
178
|
+
+/**
|
|
179
|
+
+ * darwin patch (SER-101): provenance of reasoning captured on the Responses path.
|
|
180
|
+
+ *
|
|
181
|
+
+ * `ReasoningBlock` has no provider-metadata field (harness-sdk#2014) and its
|
|
182
|
+
+ * `toJSON` persists only `text`/`signature`/`redactedContent`, so provenance
|
|
183
|
+
+ * rides inside `signature`:
|
|
184
|
+
+ * `darwin-responses:v1:<encodeURIComponent(modelId)>:<kind>[:<encrypted_content>]`.
|
|
185
|
+
+ * Kinds: `text` = raw reasoning text (replayed as `reasoning_text`), `enc` = one
|
|
186
|
+
+ * opaque `encrypted_content` item (replayed verbatim), `sum` = a summary kept for
|
|
187
|
+
+ * display only (never replayed). Replay is same-model and stateless only; every
|
|
188
|
+
+ * other formatter (Converse, Anthropic, Chat Completions) drops a tagged block.
|
|
189
|
+
+ * Drop these hunks on upgrade if upstream (harness-sdk#4598 / #3389) ships a
|
|
190
|
+
+ * provenance-aware round-trip.
|
|
191
|
+
+ */
|
|
192
|
+
+export const RESPONSES_REASONING_TAG = 'darwin-responses:v1:';
|
|
193
|
+
+const RESPONSES_REASONING_KINDS = new Set(['text', 'enc', 'sum']);
|
|
194
|
+
+/** @internal */
|
|
195
|
+
+export function encodeResponsesReasoningSignature(modelId, kind, encryptedContent) {
|
|
196
|
+
+ const tag = `${RESPONSES_REASONING_TAG}${encodeURIComponent(modelId)}:${kind}`;
|
|
197
|
+
+ return kind === 'enc' ? `${tag}:${encryptedContent}` : tag;
|
|
198
|
+
+}
|
|
199
|
+
+/** @internal Returns `undefined` for anything that is not a well-formed tag. */
|
|
200
|
+
+export function parseResponsesReasoningSignature(signature) {
|
|
201
|
+
+ if (typeof signature !== 'string' || !signature.startsWith(RESPONSES_REASONING_TAG))
|
|
202
|
+
+ return undefined;
|
|
203
|
+
+ const rest = signature.slice(RESPONSES_REASONING_TAG.length);
|
|
204
|
+
+ const modelEnd = rest.indexOf(':');
|
|
205
|
+
+ if (modelEnd <= 0)
|
|
206
|
+
+ return undefined;
|
|
207
|
+
+ let modelId;
|
|
208
|
+
+ try {
|
|
209
|
+
+ modelId = decodeURIComponent(rest.slice(0, modelEnd));
|
|
210
|
+
+ }
|
|
211
|
+
+ catch {
|
|
212
|
+
+ return undefined;
|
|
213
|
+
+ }
|
|
214
|
+
+ const tail = rest.slice(modelEnd + 1);
|
|
215
|
+
+ const kindEnd = tail.indexOf(':');
|
|
216
|
+
+ const kind = kindEnd < 0 ? tail : tail.slice(0, kindEnd);
|
|
217
|
+
+ if (!RESPONSES_REASONING_KINDS.has(kind))
|
|
218
|
+
+ return undefined;
|
|
219
|
+
+ if (kind === 'enc') {
|
|
220
|
+
+ const encryptedContent = kindEnd < 0 ? '' : tail.slice(kindEnd + 1);
|
|
221
|
+
+ return encryptedContent === '' ? undefined : { modelId, kind, encryptedContent };
|
|
222
|
+
+ }
|
|
223
|
+
+ return kindEnd < 0 ? { modelId, kind } : undefined;
|
|
224
|
+
+}
|
|
225
|
+
+/**
|
|
226
|
+
+ * The stateless `reasoning` input item for one assistant reasoning block, or
|
|
227
|
+
+ * `undefined` when it must be dropped: untagged, foreign model, display-only, or
|
|
228
|
+
+ * no replay model (stateful requests keep reasoning server-side).
|
|
229
|
+
+ */
|
|
230
|
+
+function formatResponsesReasoningInput(block, replayModelId) {
|
|
231
|
+
+ if (replayModelId === undefined)
|
|
232
|
+
+ return undefined;
|
|
233
|
+
+ const tag = parseResponsesReasoningSignature(block.signature);
|
|
234
|
+
+ if (tag === undefined || tag.modelId !== replayModelId)
|
|
235
|
+
+ return undefined;
|
|
236
|
+
+ if (tag.kind === 'enc') {
|
|
237
|
+
+ return { type: 'reasoning', summary: [], encrypted_content: tag.encryptedContent };
|
|
238
|
+
+ }
|
|
239
|
+
+ if (tag.kind === 'text' && typeof block.text === 'string' && block.text !== '') {
|
|
240
|
+
+ return { type: 'reasoning', summary: [], content: [{ type: 'reasoning_text', text: block.text }] };
|
|
241
|
+
+ }
|
|
242
|
+
+ return undefined;
|
|
243
|
+
+}
|
|
244
|
+
/**
|
|
245
|
+
* Logs a warning for each responses-managed key present in `params`.
|
|
246
|
+
*
|
|
247
|
+
@@ -35,7 +101,7 @@ export function warnManagedParams(params) {
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
export function formatResponsesRequest(config, messages, options, stateful) {
|
|
251
|
+
- const input = formatResponsesMessages(messages);
|
|
252
|
+
+ const input = formatResponsesMessages(messages, stateful ? undefined : (config.modelId ?? DEFAULT_RESPONSES_MODEL_ID));
|
|
253
|
+
// User `params` are spread first so provider-managed fields (asserted
|
|
254
|
+
// required by `ResponseCreateParamsStreaming` below) always win. The
|
|
255
|
+
// managed-params warning fires at config time to surface the collision.
|
|
256
|
+
@@ -111,11 +177,15 @@ export function formatResponsesRequest(config, messages, options, stateful) {
|
|
257
|
+
* - Text/media → grouped in `{ role, content: [...] }`
|
|
258
|
+
* - Tool calls → separate `{ type: 'function_call', ... }` items
|
|
259
|
+
* - Tool results → separate `{ type: 'function_call_output', ... }` items
|
|
260
|
+
+ * - Same-model tagged reasoning (darwin patch, SER-101) → stateless
|
|
261
|
+
+ * `{ type: 'reasoning', ... }` items with no `id`, before that message's
|
|
262
|
+
+ * text and `function_call` items
|
|
263
|
+
*/
|
|
264
|
+
-function formatResponsesMessages(messages) {
|
|
265
|
+
+function formatResponsesMessages(messages, replayModelId) {
|
|
266
|
+
const input = [];
|
|
267
|
+
for (const message of messages) {
|
|
268
|
+
const role = message.role === 'assistant' ? 'assistant' : 'user';
|
|
269
|
+
+ const reasoningItems = [];
|
|
270
|
+
const contentItems = [];
|
|
271
|
+
const toolCallItems = [];
|
|
272
|
+
const toolResultItems = [];
|
|
273
|
+
@@ -171,6 +241,11 @@ function formatResponsesMessages(messages) {
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 'reasoningBlock': {
|
|
277
|
+
+ const reasoning = role === 'assistant' ? formatResponsesReasoningInput(block, replayModelId) : undefined;
|
|
278
|
+
+ if (reasoning !== undefined) {
|
|
279
|
+
+ reasoningItems.push(reasoning);
|
|
280
|
+
+ break;
|
|
281
|
+
+ }
|
|
282
|
+
logger.warn('block_type=<reasoningBlock> | reasoning content is not yet supported in multi-turn conversations with the responses api');
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
@@ -179,6 +254,7 @@ function formatResponsesMessages(messages) {
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
+ input.push(...reasoningItems);
|
|
290
|
+
if (contentItems.length > 0) {
|
|
291
|
+
if (role === 'assistant') {
|
|
292
|
+
// Only the string EasyInputMessage form is a valid assistant *input* shape
|
|
293
|
+
@@ -303,12 +379,16 @@ function formatDocumentInput(docBlock) {
|
|
294
|
+
*
|
|
295
|
+
* @internal
|
|
296
|
+
*/
|
|
297
|
+
-export function createResponsesStreamState() {
|
|
298
|
+
+export function createResponsesStreamState(modelId) {
|
|
299
|
+
return {
|
|
300
|
+
dataType: null,
|
|
301
|
+
toolCalls: new Map(),
|
|
302
|
+
finalUsage: null,
|
|
303
|
+
stopReason: 'endTurn',
|
|
304
|
+
+ // darwin patch (SER-101): the request's model id tags captured reasoning;
|
|
305
|
+
+ // `reasoningKind` is what the open reasoning block streamed (`text`/`sum`).
|
|
306
|
+
+ modelId,
|
|
307
|
+
+ reasoningKind: undefined,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
@@ -328,9 +408,13 @@ function mapResponsesUsage(usage) {
|
|
76
312
|
totalTokens: usage.total_tokens,
|
|
77
313
|
};
|
|
78
314
|
const cached = usage.input_tokens_details?.cached_tokens;
|
|
@@ -87,6 +323,81 @@ index 25091ff4351eaa61dc370382a251285ed6f3a629..8d342dc7be28c63b7f609bd3c9cca00f
|
|
|
87
323
|
return mapped;
|
|
88
324
|
}
|
|
89
325
|
function createResponsesStreamError(message, code) {
|
|
326
|
+
@@ -359,22 +443,66 @@ export function mapResponsesEventToSDK(event, state, stateful, modelState) {
|
|
327
|
+
case 'response.output_text.delta': {
|
|
328
|
+
events.push(...switchContent('text', state.dataType));
|
|
329
|
+
state.dataType = 'text';
|
|
330
|
+
+ state.reasoningKind = undefined;
|
|
331
|
+
events.push({
|
|
332
|
+
type: 'modelContentBlockDeltaEvent',
|
|
333
|
+
delta: { type: 'textDelta', text: event.delta },
|
|
334
|
+
});
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
+ // darwin patch (SER-101): `response.reasoning.delta` is the Bedrock runtime
|
|
338
|
+
+ // endpoint's name for raw reasoning text (Kimi K3); same meaning as
|
|
339
|
+
+ // `response.reasoning_text.delta`. A block with any summary delta is `sum`.
|
|
340
|
+
+ case 'response.reasoning.delta':
|
|
341
|
+
case 'response.reasoning_text.delta':
|
|
342
|
+
case 'response.reasoning_summary_text.delta': {
|
|
343
|
+
+ if (state.dataType !== 'reasoning')
|
|
344
|
+
+ state.reasoningKind = undefined;
|
|
345
|
+
events.push(...switchContent('reasoning', state.dataType));
|
|
346
|
+
state.dataType = 'reasoning';
|
|
347
|
+
+ state.reasoningKind =
|
|
348
|
+
+ event.type === 'response.reasoning_summary_text.delta' || state.reasoningKind === 'sum' ? 'sum' : 'text';
|
|
349
|
+
events.push({
|
|
350
|
+
type: 'modelContentBlockDeltaEvent',
|
|
351
|
+
delta: { type: 'reasoningContentDelta', text: event.delta },
|
|
352
|
+
});
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
+ // darwin patch (SER-101): a finished reasoning item closes the open reasoning
|
|
356
|
+
+ // block with its provenance tag, and its `encrypted_content` (if any) becomes a
|
|
357
|
+
+ // block of its own, so several opaque items never collapse into one.
|
|
358
|
+
+ case 'response.output_item.done': {
|
|
359
|
+
+ const item = event.item;
|
|
360
|
+
+ if (item?.type !== 'reasoning')
|
|
361
|
+
+ break;
|
|
362
|
+
+ const encrypted = typeof item.encrypted_content === 'string' && item.encrypted_content !== '' ? item.encrypted_content : undefined;
|
|
363
|
+
+ if (state.dataType === 'reasoning') {
|
|
364
|
+
+ if (state.modelId !== undefined) {
|
|
365
|
+
+ const kind = encrypted !== undefined ? 'sum' : (state.reasoningKind ?? 'text');
|
|
366
|
+
+ events.push({
|
|
367
|
+
+ type: 'modelContentBlockDeltaEvent',
|
|
368
|
+
+ delta: { type: 'reasoningContentDelta', signature: encodeResponsesReasoningSignature(state.modelId, kind) },
|
|
369
|
+
+ });
|
|
370
|
+
+ }
|
|
371
|
+
+ events.push({ type: 'modelContentBlockStopEvent' });
|
|
372
|
+
+ state.dataType = null;
|
|
373
|
+
+ state.reasoningKind = undefined;
|
|
374
|
+
+ }
|
|
375
|
+
+ if (encrypted !== undefined && state.modelId !== undefined) {
|
|
376
|
+
+ events.push(...switchContent('reasoning', state.dataType));
|
|
377
|
+
+ events.push({
|
|
378
|
+
+ type: 'modelContentBlockDeltaEvent',
|
|
379
|
+
+ delta: {
|
|
380
|
+
+ type: 'reasoningContentDelta',
|
|
381
|
+
+ signature: encodeResponsesReasoningSignature(state.modelId, 'enc', encrypted),
|
|
382
|
+
+ },
|
|
383
|
+
+ });
|
|
384
|
+
+ events.push({ type: 'modelContentBlockStopEvent' });
|
|
385
|
+
+ state.dataType = null;
|
|
386
|
+
+ state.reasoningKind = undefined;
|
|
387
|
+
+ }
|
|
388
|
+
+ break;
|
|
389
|
+
+ }
|
|
390
|
+
case 'response.output_text.annotation.added': {
|
|
391
|
+
// The SDK types `event.annotation` as `unknown` and doesn't export a
|
|
392
|
+
// named annotation union, so we narrow structurally on the fields we use.
|
|
393
|
+
@@ -388,6 +516,7 @@ export function mapResponsesEventToSDK(event, state, stateful, modelState) {
|
|
394
|
+
// a fresh TextBlock.
|
|
395
|
+
events.push(...switchContent('citations', state.dataType));
|
|
396
|
+
state.dataType = 'citations';
|
|
397
|
+
+ state.reasoningKind = undefined;
|
|
398
|
+
events.push({
|
|
399
|
+
type: 'modelContentBlockDeltaEvent',
|
|
400
|
+
delta: {
|
|
90
401
|
diff --git a/node_modules/@strands-agents/sdk/dist/src/vended-plugins/context-offloader/plugin.d.ts b/node_modules/@strands-agents/sdk/dist/src/vended-plugins/context-offloader/plugin.d.ts
|
|
91
402
|
index b0223555c1f0410441546be860dbae824ac9857c..92ab47f4c8c1f5225c13dfd8a5e37324846bdfc2 100644
|
|
92
403
|
--- a/node_modules/@strands-agents/sdk/dist/src/vended-plugins/context-offloader/plugin.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// `DEFAULT_SUMMARIZATION_PROMPT` reaches the package root only through the pinned
|
|
2
|
-
// SDK patch (`patches/@strands-agents__sdk@1.
|
|
2
|
+
// SDK patch (`patches/@strands-agents__sdk@1.18.0.patch`, `dist/src/index.*`
|
|
3
3
|
// hunks): the SDK declares it in a module its `exports` map does not expose.
|
|
4
4
|
// Never copy the string here — a copy would drift from what the SDK sends when
|
|
5
5
|
// no focus is given.
|
|
@@ -333,6 +333,14 @@ export declare class AgentRuntime {
|
|
|
333
333
|
private readonly subagentDispatches;
|
|
334
334
|
/** Forwards background runs' `AfterToolCallEvent`s into `send()`'s stream (SER-064). */
|
|
335
335
|
private readonly backgroundDelegation;
|
|
336
|
+
/**
|
|
337
|
+
* Which background jobs' terminal states completed turns already carried to the
|
|
338
|
+
* model through `wait`/`status` results (SER-069): the interactive drain asks it
|
|
339
|
+
* before sending a wake, so a job the model already saw finish never starts a
|
|
340
|
+
* duplicate turn. Session-scoped like the anchor; a `/clear` successor starts empty.
|
|
341
|
+
* Built in `create()` because its pre-offload hook is installed on the Agent (SRF-036).
|
|
342
|
+
*/
|
|
343
|
+
private readonly terminalDelivery;
|
|
336
344
|
/** The parent Agent's own retry state; children keep theirs behind their installer (SER-066). */
|
|
337
345
|
private readonly modelRetry;
|
|
338
346
|
private readonly backgroundBash;
|
|
@@ -426,13 +434,6 @@ export declare class AgentRuntime {
|
|
|
426
434
|
private cacheMisses;
|
|
427
435
|
/** Latched on the first tracker failure — its own latch, so it cannot break the others. */
|
|
428
436
|
private cacheMissesBroken;
|
|
429
|
-
/**
|
|
430
|
-
* Which background jobs' terminal states completed turns already carried to the
|
|
431
|
-
* model through `wait`/`status` results (SER-069): the interactive drain asks it
|
|
432
|
-
* before sending a wake, so a job the model already saw finish never starts a
|
|
433
|
-
* duplicate turn. Session-scoped like the anchor; a `/clear` successor starts empty.
|
|
434
|
-
*/
|
|
435
|
-
private readonly terminalDelivery;
|
|
436
437
|
/** Serializes the bounded list/save/list critical section across concurrent callers. */
|
|
437
438
|
private rewindCaptureTail;
|
|
438
439
|
/**
|
|
@@ -732,9 +733,15 @@ export declare class AgentRuntime {
|
|
|
732
733
|
* instead of rebuilding the agent — which is the whole point: the history, the
|
|
733
734
|
* session file, the tools and the permission gate all survive. Both switch
|
|
734
735
|
* directions were measured to carry a conversation containing tool calls
|
|
735
|
-
* (`spike/probe-model-switch.ts`)
|
|
736
|
-
*
|
|
737
|
-
*
|
|
736
|
+
* (`spike/probe-model-switch.ts`). Reasoning crosses a switch only where it is
|
|
737
|
+
* provably the target's own (SER-101, the pinned SDK patch): the OpenAI Responses
|
|
738
|
+
* adapter tags what it captures with the producing model id and replays only a
|
|
739
|
+
* tag matching the live model; every foreign or untagged block — a Claude one, or
|
|
740
|
+
* another Responses model's — is still dropped with the SDK warning, which is why
|
|
741
|
+
* the TUI routes SDK warnings into notices. Converse, Anthropic and Chat
|
|
742
|
+
* Completions never send a tagged block, and Converse drops signature-less
|
|
743
|
+
* (Kimi) reasoning for a Claude id, which Claude would otherwise reject
|
|
744
|
+
* (`spike/verify-responses-reasoning-live.ts` measures every hand-off).
|
|
738
745
|
*
|
|
739
746
|
* The thinking and cache plans are recomputed rather than carried over: effort
|
|
740
747
|
* clamping is per-model and caching is per-provider, so the old plans would
|
|
@@ -137,6 +137,7 @@ export class AgentRuntime {
|
|
|
137
137
|
workflows;
|
|
138
138
|
subagentDispatches;
|
|
139
139
|
backgroundDelegation;
|
|
140
|
+
terminalDelivery;
|
|
140
141
|
modelRetry;
|
|
141
142
|
backgroundBash;
|
|
142
143
|
gate;
|
|
@@ -214,13 +215,6 @@ export class AgentRuntime {
|
|
|
214
215
|
cacheMisses;
|
|
215
216
|
/** Latched on the first tracker failure — its own latch, so it cannot break the others. */
|
|
216
217
|
cacheMissesBroken = false;
|
|
217
|
-
/**
|
|
218
|
-
* Which background jobs' terminal states completed turns already carried to the
|
|
219
|
-
* model through `wait`/`status` results (SER-069): the interactive drain asks it
|
|
220
|
-
* before sending a wake, so a job the model already saw finish never starts a
|
|
221
|
-
* duplicate turn. Session-scoped like the anchor; a `/clear` successor starts empty.
|
|
222
|
-
*/
|
|
223
|
-
terminalDelivery = new TerminalDeliveryLedger();
|
|
224
218
|
/** Serializes the bounded list/save/list critical section across concurrent callers. */
|
|
225
219
|
rewindCaptureTail = Promise.resolve();
|
|
226
220
|
/**
|
|
@@ -237,6 +231,14 @@ export class AgentRuntime {
|
|
|
237
231
|
mcp, skills, commands, subagents, workflows, subagentDispatches,
|
|
238
232
|
/** Forwards background runs' `AfterToolCallEvent`s into `send()`'s stream (SER-064). */
|
|
239
233
|
backgroundDelegation,
|
|
234
|
+
/**
|
|
235
|
+
* Which background jobs' terminal states completed turns already carried to the
|
|
236
|
+
* model through `wait`/`status` results (SER-069): the interactive drain asks it
|
|
237
|
+
* before sending a wake, so a job the model already saw finish never starts a
|
|
238
|
+
* duplicate turn. Session-scoped like the anchor; a `/clear` successor starts empty.
|
|
239
|
+
* Built in `create()` because its pre-offload hook is installed on the Agent (SRF-036).
|
|
240
|
+
*/
|
|
241
|
+
terminalDelivery,
|
|
240
242
|
/** The parent Agent's own retry state; children keep theirs behind their installer (SER-066). */
|
|
241
243
|
modelRetry, backgroundBash, gate,
|
|
242
244
|
/** Undefined when neither native lifecycle event is configured. */
|
|
@@ -272,6 +274,7 @@ export class AgentRuntime {
|
|
|
272
274
|
this.workflows = workflows;
|
|
273
275
|
this.subagentDispatches = subagentDispatches;
|
|
274
276
|
this.backgroundDelegation = backgroundDelegation;
|
|
277
|
+
this.terminalDelivery = terminalDelivery;
|
|
275
278
|
this.modelRetry = modelRetry;
|
|
276
279
|
this.backgroundBash = backgroundBash;
|
|
277
280
|
this.gate = gate;
|
|
@@ -552,6 +555,12 @@ export class AgentRuntime {
|
|
|
552
555
|
// have no AfterToolCallEvent. Never overwrite an original snapshot.
|
|
553
556
|
agent.addHook(ToolResultEvent, event => cloudMemory.uploadObserver?.fallback(event), { order: HookOrder.SDK_LAST });
|
|
554
557
|
}
|
|
558
|
+
// SRF-036: one read-only SDK_FIRST AfterToolCallEvent hook hands the ledger the
|
|
559
|
+
// original `bash` result before the ContextOffloader's default-order hook can
|
|
560
|
+
// replace it with a preview; `send()`'s stream-side `observe` resolves it.
|
|
561
|
+
// Parent only: children never construct a ledger.
|
|
562
|
+
const terminalDelivery = new TerminalDeliveryLedger();
|
|
563
|
+
terminalDelivery.install(agent);
|
|
555
564
|
toolForName = (name) => agent.tools.find((candidate) => candidate.name === name);
|
|
556
565
|
installMaxTokensRecovery(agent);
|
|
557
566
|
const modelRetry = installModelRetry(agent);
|
|
@@ -728,7 +737,7 @@ export class AgentRuntime {
|
|
|
728
737
|
});
|
|
729
738
|
trajectoryAudit = trajectory;
|
|
730
739
|
await trajectory?.open();
|
|
731
|
-
const runtime = new AgentRuntime(agent, model, options.projectRoot, mcp, skills, commands, subagents, workflows, subagentDispatches, backgroundDelegation, modelRetry, backgroundBash, gate, lifecycleHooks, policy.toolHookLayers, codexHooks, sessionManager, config.preserveRecentMessages, trajectory, diagnosticsLog, memoryController, cloudMemory, session.lease, {
|
|
740
|
+
const runtime = new AgentRuntime(agent, model, options.projectRoot, mcp, skills, commands, subagents, workflows, subagentDispatches, backgroundDelegation, terminalDelivery, modelRetry, backgroundBash, gate, lifecycleHooks, policy.toolHookLayers, codexHooks, sessionManager, config.preserveRecentMessages, trajectory, diagnosticsLog, memoryController, cloudMemory, session.lease, {
|
|
732
741
|
config,
|
|
733
742
|
projectRoot: options.projectRoot,
|
|
734
743
|
permissionMode,
|
|
@@ -1388,9 +1397,15 @@ export class AgentRuntime {
|
|
|
1388
1397
|
* instead of rebuilding the agent — which is the whole point: the history, the
|
|
1389
1398
|
* session file, the tools and the permission gate all survive. Both switch
|
|
1390
1399
|
* directions were measured to carry a conversation containing tool calls
|
|
1391
|
-
* (`spike/probe-model-switch.ts`)
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1400
|
+
* (`spike/probe-model-switch.ts`). Reasoning crosses a switch only where it is
|
|
1401
|
+
* provably the target's own (SER-101, the pinned SDK patch): the OpenAI Responses
|
|
1402
|
+
* adapter tags what it captures with the producing model id and replays only a
|
|
1403
|
+
* tag matching the live model; every foreign or untagged block — a Claude one, or
|
|
1404
|
+
* another Responses model's — is still dropped with the SDK warning, which is why
|
|
1405
|
+
* the TUI routes SDK warnings into notices. Converse, Anthropic and Chat
|
|
1406
|
+
* Completions never send a tagged block, and Converse drops signature-less
|
|
1407
|
+
* (Kimi) reasoning for a Claude id, which Claude would otherwise reject
|
|
1408
|
+
* (`spike/verify-responses-reasoning-live.ts` measures every hand-off).
|
|
1394
1409
|
*
|
|
1395
1410
|
* The thinking and cache plans are recomputed rather than carried over: effort
|
|
1396
1411
|
* clamping is per-model and caching is per-provider, so the old plans would
|
|
@@ -1415,6 +1430,7 @@ export class AgentRuntime {
|
|
|
1415
1430
|
if (promptCachePlan.parts.includes('system prompt') !== cacheUpdated) {
|
|
1416
1431
|
throw new Error('Could not update the final cache point on the assembled system prompt.');
|
|
1417
1432
|
}
|
|
1433
|
+
const from = { provider: this.liveConfig.provider, model: this.liveConfig.model };
|
|
1418
1434
|
this.agent.model = model;
|
|
1419
1435
|
this.model = model;
|
|
1420
1436
|
this.liveConfig = next;
|
|
@@ -1429,6 +1445,15 @@ export class AgentRuntime {
|
|
|
1429
1445
|
this.promptCachePlan = promptCachePlan;
|
|
1430
1446
|
// A different model keys a different cache: the next call re-reads uncached.
|
|
1431
1447
|
this.markCacheInvalidated('model');
|
|
1448
|
+
// SRF-038: the swap has happened, so the record says so — `runStarted` keeps
|
|
1449
|
+
// naming the startup model byte for byte. Observer-only (synchronous, no await,
|
|
1450
|
+
// non-throwing); a factory failure or a refused cache shape threw above and never
|
|
1451
|
+
// reaches here, and a failed config save is still a switch that ran.
|
|
1452
|
+
this.trajectory?.recordModelChanged({
|
|
1453
|
+
from,
|
|
1454
|
+
to: { provider: next.provider, model: next.model },
|
|
1455
|
+
thinkingEffort: thinkingPlan.effective,
|
|
1456
|
+
});
|
|
1432
1457
|
const choice = next.modelChoices.find((entry) => entry.index === target.index);
|
|
1433
1458
|
return {
|
|
1434
1459
|
choice,
|