@anthropic-ai/sdk 0.117.1 → 0.119.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 +36 -0
- package/client.d.mts +8 -2
- package/client.d.mts.map +1 -1
- package/client.d.ts +8 -2
- package/client.d.ts.map +1 -1
- package/client.js +7 -1
- package/client.js.map +1 -1
- package/client.mjs +7 -1
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +1 -0
- package/core/api-promise.d.mts.map +1 -1
- package/core/api-promise.d.ts +1 -0
- package/core/api-promise.d.ts.map +1 -1
- package/core/api-promise.js +7 -2
- package/core/api-promise.js.map +1 -1
- package/core/api-promise.mjs +8 -3
- package/core/api-promise.mjs.map +1 -1
- package/core/error.d.mts +1 -0
- package/core/error.d.mts.map +1 -1
- package/core/error.d.ts +1 -0
- package/core/error.d.ts.map +1 -1
- package/core/error.js +1 -0
- package/core/error.js.map +1 -1
- package/core/error.mjs +1 -0
- package/core/error.mjs.map +1 -1
- package/core/middleware.js +1 -1
- package/core/middleware.js.map +1 -1
- package/core/middleware.mjs +2 -2
- package/core/middleware.mjs.map +1 -1
- package/helpers/beta/zod.d.mts.map +1 -1
- package/helpers/beta/zod.d.ts.map +1 -1
- package/helpers/beta/zod.js +1 -2
- package/helpers/beta/zod.js.map +1 -1
- package/helpers/beta/zod.mjs +1 -2
- package/helpers/beta/zod.mjs.map +1 -1
- package/helpers/zod.d.mts.map +1 -1
- package/helpers/zod.d.ts.map +1 -1
- package/helpers/zod.js +1 -2
- package/helpers/zod.js.map +1 -1
- package/helpers/zod.mjs +1 -2
- package/helpers/zod.mjs.map +1 -1
- package/internal/parse.d.mts +2 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts +2 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +6 -6
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +5 -5
- package/internal/parse.mjs.map +1 -1
- package/lib/BetaMessageStream.d.mts +2 -0
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts +2 -0
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +8 -2
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +8 -2
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.mts +2 -0
- package/lib/MessageStream.d.mts.map +1 -1
- package/lib/MessageStream.d.ts +2 -0
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +8 -2
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +8 -2
- package/lib/MessageStream.mjs.map +1 -1
- package/lib/environments/worker.d.mts +10 -6
- package/lib/environments/worker.d.mts.map +1 -1
- package/lib/environments/worker.d.ts +10 -6
- package/lib/environments/worker.d.ts.map +1 -1
- package/lib/environments/worker.js +22 -15
- package/lib/environments/worker.js.map +1 -1
- package/lib/environments/worker.mjs +22 -15
- package/lib/environments/worker.mjs.map +1 -1
- package/lib/tools/BetaRunnableTool.d.mts +21 -40
- package/lib/tools/BetaRunnableTool.d.mts.map +1 -1
- package/lib/tools/BetaRunnableTool.d.ts +21 -40
- package/lib/tools/BetaRunnableTool.d.ts.map +1 -1
- package/lib/tools/BetaRunnableTool.js +7 -16
- package/lib/tools/BetaRunnableTool.js.map +1 -1
- package/lib/tools/BetaRunnableTool.mjs +7 -16
- package/lib/tools/BetaRunnableTool.mjs.map +1 -1
- package/lib/tools/BetaToolRunner.d.mts.map +1 -1
- package/lib/tools/BetaToolRunner.d.ts.map +1 -1
- package/lib/tools/BetaToolRunner.js +3 -13
- package/lib/tools/BetaToolRunner.js.map +1 -1
- package/lib/tools/BetaToolRunner.mjs +3 -13
- package/lib/tools/BetaToolRunner.mjs.map +1 -1
- package/lib/tools/SessionToolRunner.d.mts +6 -0
- package/lib/tools/SessionToolRunner.d.mts.map +1 -1
- package/lib/tools/SessionToolRunner.d.ts +6 -0
- package/lib/tools/SessionToolRunner.d.ts.map +1 -1
- package/lib/tools/SessionToolRunner.js +37 -8
- package/lib/tools/SessionToolRunner.js.map +1 -1
- package/lib/tools/SessionToolRunner.mjs +38 -9
- package/lib/tools/SessionToolRunner.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +3 -3
- package/resources/beta/agents/agents.d.ts +3 -3
- package/resources/beta/agents/agents.js +1 -1
- package/resources/beta/agents/agents.mjs +1 -1
- package/resources/beta/beta.d.mts +5 -5
- package/resources/beta/beta.d.mts.map +1 -1
- package/resources/beta/beta.d.ts +5 -5
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/dreams.d.mts +2 -2
- package/resources/beta/dreams.d.ts +2 -2
- package/resources/beta/environments/environments.d.mts +4 -3
- package/resources/beta/environments/environments.d.mts.map +1 -1
- package/resources/beta/environments/environments.d.ts +4 -3
- package/resources/beta/environments/environments.d.ts.map +1 -1
- package/resources/beta/environments/environments.js.map +1 -1
- package/resources/beta/environments/environments.mjs.map +1 -1
- package/resources/beta/files.d.mts +22 -22
- package/resources/beta/files.d.mts.map +1 -1
- package/resources/beta/files.d.ts +22 -22
- package/resources/beta/files.d.ts.map +1 -1
- package/resources/beta/files.js +4 -4
- package/resources/beta/files.js.map +1 -1
- package/resources/beta/files.mjs +4 -4
- package/resources/beta/files.mjs.map +1 -1
- package/resources/beta/index.d.mts +2 -2
- package/resources/beta/index.d.mts.map +1 -1
- package/resources/beta/index.d.ts +2 -2
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/memory-stores/index.d.mts +1 -1
- package/resources/beta/memory-stores/index.d.mts.map +1 -1
- package/resources/beta/memory-stores/index.d.ts +1 -1
- package/resources/beta/memory-stores/index.d.ts.map +1 -1
- package/resources/beta/memory-stores/index.js.map +1 -1
- package/resources/beta/memory-stores/index.mjs.map +1 -1
- package/resources/beta/memory-stores/memory-stores.d.mts +2 -2
- package/resources/beta/memory-stores/memory-stores.d.mts.map +1 -1
- package/resources/beta/memory-stores/memory-stores.d.ts +2 -2
- package/resources/beta/memory-stores/memory-stores.d.ts.map +1 -1
- package/resources/beta/memory-stores/memory-stores.js.map +1 -1
- package/resources/beta/memory-stores/memory-stores.mjs.map +1 -1
- package/resources/beta/memory-stores/memory-versions.d.mts +17 -2
- package/resources/beta/memory-stores/memory-versions.d.mts.map +1 -1
- package/resources/beta/memory-stores/memory-versions.d.ts +17 -2
- package/resources/beta/memory-stores/memory-versions.d.ts.map +1 -1
- package/resources/beta/messages/batches.d.mts +1 -1
- package/resources/beta/messages/batches.d.ts +1 -1
- package/resources/beta/messages/batches.js +1 -1
- package/resources/beta/messages/batches.mjs +1 -1
- package/resources/beta/messages/index.d.mts +1 -1
- package/resources/beta/messages/index.d.mts.map +1 -1
- package/resources/beta/messages/index.d.ts +1 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +1204 -25
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +1204 -25
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +1 -1
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +1 -1
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/beta/sessions/sessions.d.mts +1 -1
- package/resources/beta/sessions/sessions.d.ts +1 -1
- package/resources/beta/user-profiles.d.mts +35 -9
- package/resources/beta/user-profiles.d.mts.map +1 -1
- package/resources/beta/user-profiles.d.ts +35 -9
- package/resources/beta/user-profiles.d.ts.map +1 -1
- package/resources/beta/user-profiles.js +5 -5
- package/resources/beta/user-profiles.mjs +5 -5
- package/resources/files.d.mts +105 -0
- package/resources/files.d.mts.map +1 -0
- package/resources/files.d.ts +105 -0
- package/resources/files.d.ts.map +1 -0
- package/resources/files.js +52 -0
- package/resources/files.js.map +1 -0
- package/resources/files.mjs +48 -0
- package/resources/files.mjs.map +1 -0
- package/resources/index.d.mts +3 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +3 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -0
- package/resources/index.mjs.map +1 -1
- package/resources/messages/batches.d.mts +1 -1
- package/resources/messages/batches.d.ts +1 -1
- package/resources/messages/batches.js +1 -1
- package/resources/messages/batches.mjs +1 -1
- package/resources/messages/index.d.mts +1 -1
- package/resources/messages/index.d.mts.map +1 -1
- package/resources/messages/index.d.ts +1 -1
- package/resources/messages/index.d.ts.map +1 -1
- package/resources/messages/index.js.map +1 -1
- package/resources/messages/index.mjs.map +1 -1
- package/resources/messages/messages.d.mts +1270 -28
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +1270 -28
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/skills/index.d.mts +3 -0
- package/resources/skills/index.d.mts.map +1 -0
- package/resources/skills/index.d.ts +3 -0
- package/resources/skills/index.d.ts.map +1 -0
- package/resources/skills/index.js +9 -0
- package/resources/skills/index.js.map +1 -0
- package/resources/skills/index.mjs +4 -0
- package/resources/skills/index.mjs.map +1 -0
- package/resources/skills/skills.d.mts +129 -0
- package/resources/skills/skills.d.mts.map +1 -0
- package/resources/skills/skills.d.ts +129 -0
- package/resources/skills/skills.d.ts.map +1 -0
- package/resources/skills/skills.js +44 -0
- package/resources/skills/skills.js.map +1 -0
- package/resources/skills/skills.mjs +39 -0
- package/resources/skills/skills.mjs.map +1 -0
- package/resources/skills/versions.d.mts +104 -0
- package/resources/skills/versions.d.mts.map +1 -0
- package/resources/skills/versions.d.ts +104 -0
- package/resources/skills/versions.d.ts.map +1 -0
- package/resources/skills/versions.js +41 -0
- package/resources/skills/versions.js.map +1 -0
- package/resources/skills/versions.mjs +37 -0
- package/resources/skills/versions.mjs.map +1 -0
- package/resources/skills.d.mts +2 -0
- package/resources/skills.d.mts.map +1 -0
- package/resources/skills.d.ts +2 -0
- package/resources/skills.d.ts.map +1 -0
- package/resources/skills.js +6 -0
- package/resources/skills.js.map +1 -0
- package/resources/skills.mjs +3 -0
- package/resources/skills.mjs.map +1 -0
- package/src/client.ts +173 -3
- package/src/core/api-promise.ts +14 -4
- package/src/core/error.ts +2 -0
- package/src/core/middleware.ts +2 -2
- package/src/helpers/beta/zod.ts +1 -3
- package/src/helpers/zod.ts +1 -3
- package/src/internal/parse.ts +6 -6
- package/src/lib/BetaMessageStream.ts +8 -0
- package/src/lib/MessageStream.ts +8 -0
- package/src/lib/environments/worker.ts +28 -14
- package/src/lib/tools/BetaRunnableTool.ts +26 -43
- package/src/lib/tools/BetaToolRunner.ts +6 -13
- package/src/lib/tools/SessionToolRunner.ts +39 -6
- package/src/resources/beta/agents/agents.ts +3 -3
- package/src/resources/beta/beta.ts +127 -8
- package/src/resources/beta/dreams.ts +2 -2
- package/src/resources/beta/environments/environments.ts +4 -3
- package/src/resources/beta/files.ts +27 -27
- package/src/resources/beta/index.ts +63 -4
- package/src/resources/beta/memory-stores/index.ts +1 -0
- package/src/resources/beta/memory-stores/memory-stores.ts +2 -0
- package/src/resources/beta/memory-stores/memory-versions.ts +21 -1
- package/src/resources/beta/messages/batches.ts +1 -1
- package/src/resources/beta/messages/index.ts +60 -1
- package/src/resources/beta/messages/messages.ts +1862 -435
- package/src/resources/beta/sessions/sessions.ts +1 -1
- package/src/resources/beta/user-profiles.ts +44 -15
- package/src/resources/files.ts +163 -0
- package/src/resources/index.ts +83 -1
- package/src/resources/messages/batches.ts +1 -1
- package/src/resources/messages/index.ts +66 -1
- package/src/resources/messages/messages.ts +1830 -320
- package/src/resources/skills/index.ts +21 -0
- package/src/resources/skills/skills.ts +194 -0
- package/src/resources/skills/versions.ts +160 -0
- package/src/resources/skills.ts +3 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -53,6 +53,14 @@ import {
|
|
|
53
53
|
CompletionCreateParamsStreaming,
|
|
54
54
|
Completions,
|
|
55
55
|
} from './resources/completions';
|
|
56
|
+
import {
|
|
57
|
+
DeletedFile,
|
|
58
|
+
FileListParams,
|
|
59
|
+
FileMetadata,
|
|
60
|
+
FileMetadataPageCursor,
|
|
61
|
+
FileUploadParams,
|
|
62
|
+
Files,
|
|
63
|
+
} from './resources/files';
|
|
56
64
|
import {
|
|
57
65
|
CapabilitySupport,
|
|
58
66
|
ContextManagementCapability,
|
|
@@ -95,6 +103,46 @@ import {
|
|
|
95
103
|
BashCodeExecutionToolResultError,
|
|
96
104
|
BashCodeExecutionToolResultErrorCode,
|
|
97
105
|
BashCodeExecutionToolResultErrorParam,
|
|
106
|
+
BrowserCloseTabConfig,
|
|
107
|
+
BrowserDoubleClickConfig,
|
|
108
|
+
BrowserFileUploadConfig,
|
|
109
|
+
BrowserFindConfig,
|
|
110
|
+
BrowserFormInputConfig,
|
|
111
|
+
BrowserGetPageTextConfig,
|
|
112
|
+
BrowserHoldKeyConfig,
|
|
113
|
+
BrowserHoverConfig,
|
|
114
|
+
BrowserJavascriptExecConfig,
|
|
115
|
+
BrowserKeyConfig,
|
|
116
|
+
BrowserLeftClickConfig,
|
|
117
|
+
BrowserLeftClickDragConfig,
|
|
118
|
+
BrowserLeftMouseDownConfig,
|
|
119
|
+
BrowserLeftMouseUpConfig,
|
|
120
|
+
BrowserListTabsConfig,
|
|
121
|
+
BrowserMiddleClickConfig,
|
|
122
|
+
BrowserMouseMoveConfig,
|
|
123
|
+
BrowserNavigateConfig,
|
|
124
|
+
BrowserNewTabConfig,
|
|
125
|
+
BrowserReadConsoleConfig,
|
|
126
|
+
BrowserReadNetworkConfig,
|
|
127
|
+
BrowserReadPageConfig,
|
|
128
|
+
BrowserRightClickConfig,
|
|
129
|
+
BrowserScreenshotConfig,
|
|
130
|
+
BrowserScrollConfig,
|
|
131
|
+
BrowserScrollToConfig,
|
|
132
|
+
BrowserStateBlockParam,
|
|
133
|
+
BrowserStateChange,
|
|
134
|
+
BrowserStateChangeDownloadCompleted,
|
|
135
|
+
BrowserStateChangeDownloadFailed,
|
|
136
|
+
BrowserStateChangeDownloadStarted,
|
|
137
|
+
BrowserStateChangeTabOpened,
|
|
138
|
+
BrowserStateTabEntry,
|
|
139
|
+
BrowserSwitchTabConfig,
|
|
140
|
+
BrowserToolset20260801,
|
|
141
|
+
BrowserToolsetConfigs,
|
|
142
|
+
BrowserTripleClickConfig,
|
|
143
|
+
BrowserTypeConfig,
|
|
144
|
+
BrowserWaitConfig,
|
|
145
|
+
BrowserZoomConfig,
|
|
98
146
|
CacheControlEphemeral,
|
|
99
147
|
CacheCreation,
|
|
100
148
|
CitationCharLocation,
|
|
@@ -125,7 +173,28 @@ import {
|
|
|
125
173
|
CodeExecutionToolResultError,
|
|
126
174
|
CodeExecutionToolResultErrorCode,
|
|
127
175
|
CodeExecutionToolResultErrorParam,
|
|
176
|
+
ComputerCursorPositionConfig,
|
|
177
|
+
ComputerDoubleClickConfig,
|
|
178
|
+
ComputerHoldKeyConfig,
|
|
179
|
+
ComputerKeyConfig,
|
|
180
|
+
ComputerLeftClickConfig,
|
|
181
|
+
ComputerLeftClickDragConfig,
|
|
182
|
+
ComputerLeftMouseDownConfig,
|
|
183
|
+
ComputerLeftMouseUpConfig,
|
|
184
|
+
ComputerMiddleClickConfig,
|
|
185
|
+
ComputerMouseMoveConfig,
|
|
186
|
+
ComputerRightClickConfig,
|
|
187
|
+
ComputerScreenshotConfig,
|
|
188
|
+
ComputerScrollConfig,
|
|
189
|
+
ComputerToolset20260801,
|
|
190
|
+
ComputerToolsetConfigs,
|
|
191
|
+
ComputerTripleClickConfig,
|
|
192
|
+
ComputerTypeConfig,
|
|
193
|
+
ComputerWaitConfig,
|
|
194
|
+
ComputerZoomConfig,
|
|
128
195
|
Container,
|
|
196
|
+
ContainerParams,
|
|
197
|
+
ContainerSkill,
|
|
129
198
|
ContainerUploadBlock,
|
|
130
199
|
ContainerUploadBlockParam,
|
|
131
200
|
ContentBlock,
|
|
@@ -140,7 +209,10 @@ import {
|
|
|
140
209
|
DocumentBlockParam,
|
|
141
210
|
EncryptedCodeExecutionResultBlock,
|
|
142
211
|
EncryptedCodeExecutionResultBlockParam,
|
|
212
|
+
FileDocumentSource,
|
|
213
|
+
FileImageSource,
|
|
143
214
|
ImageBlockParam,
|
|
215
|
+
ImageTransformationsParam,
|
|
144
216
|
InputJSONDelta,
|
|
145
217
|
JSONOutputFormat,
|
|
146
218
|
MemoryTool20250818,
|
|
@@ -149,6 +221,7 @@ import {
|
|
|
149
221
|
MessageCountTokensParams,
|
|
150
222
|
MessageCountTokensTool,
|
|
151
223
|
MessageCreateParams,
|
|
224
|
+
MessageCreateParamsContainer,
|
|
152
225
|
MessageCreateParamsNonStreaming,
|
|
153
226
|
MessageCreateParamsStreaming,
|
|
154
227
|
MessageDeltaEvent,
|
|
@@ -160,7 +233,6 @@ import {
|
|
|
160
233
|
MessageTokensCount,
|
|
161
234
|
Messages,
|
|
162
235
|
Metadata,
|
|
163
|
-
MidConversationSystemBlockParam,
|
|
164
236
|
Model,
|
|
165
237
|
OutputConfig,
|
|
166
238
|
OutputTokensDetails,
|
|
@@ -183,6 +255,7 @@ import {
|
|
|
183
255
|
ServerToolUseBlock,
|
|
184
256
|
ServerToolUseBlockParam,
|
|
185
257
|
SignatureDelta,
|
|
258
|
+
SkillParams,
|
|
186
259
|
StopReason,
|
|
187
260
|
TextBlock,
|
|
188
261
|
TextBlockParam,
|
|
@@ -260,6 +333,15 @@ import {
|
|
|
260
333
|
WebSearchToolResultError,
|
|
261
334
|
WebSearchToolResultErrorCode,
|
|
262
335
|
} from './resources/messages/messages';
|
|
336
|
+
import {
|
|
337
|
+
DeletedSkill,
|
|
338
|
+
Skill,
|
|
339
|
+
SkillCreateParams,
|
|
340
|
+
SkillListParams,
|
|
341
|
+
SkillSource,
|
|
342
|
+
Skills,
|
|
343
|
+
SkillsPageCursor,
|
|
344
|
+
} from './resources/skills/skills';
|
|
263
345
|
import { type Fetch } from './internal/builtin-types';
|
|
264
346
|
import { isRunningInBrowser } from './internal/detect-platform';
|
|
265
347
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
@@ -1136,7 +1218,7 @@ export class BaseAnthropic {
|
|
|
1136
1218
|
}
|
|
1137
1219
|
|
|
1138
1220
|
const specialHeaders = [...response.headers.entries()]
|
|
1139
|
-
.filter(([name]) => name === 'request-id')
|
|
1221
|
+
.filter(([name]) => name === 'request-id' || name === 'anthropic-workspace-id')
|
|
1140
1222
|
.map(([name, value]) => ', ' + name + ': ' + JSON.stringify(value))
|
|
1141
1223
|
.join('');
|
|
1142
1224
|
const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${
|
|
@@ -1596,12 +1678,16 @@ export class Anthropic extends BaseAnthropic {
|
|
|
1596
1678
|
completions: API.Completions = new API.Completions(this);
|
|
1597
1679
|
messages: API.Messages = new API.Messages(this);
|
|
1598
1680
|
models: API.Models = new API.Models(this);
|
|
1681
|
+
files: API.Files = new API.Files(this);
|
|
1682
|
+
skills: API.Skills = new API.Skills(this);
|
|
1599
1683
|
beta: API.Beta = new API.Beta(this);
|
|
1600
1684
|
}
|
|
1601
1685
|
|
|
1602
1686
|
Anthropic.Completions = Completions;
|
|
1603
1687
|
Anthropic.Messages = Messages;
|
|
1604
1688
|
Anthropic.Models = Models;
|
|
1689
|
+
Anthropic.Files = Files;
|
|
1690
|
+
Anthropic.Skills = Skills;
|
|
1605
1691
|
Anthropic.Beta = Beta;
|
|
1606
1692
|
|
|
1607
1693
|
export declare namespace Anthropic {
|
|
@@ -1646,6 +1732,46 @@ export declare namespace Anthropic {
|
|
|
1646
1732
|
type BashCodeExecutionToolResultError as BashCodeExecutionToolResultError,
|
|
1647
1733
|
type BashCodeExecutionToolResultErrorCode as BashCodeExecutionToolResultErrorCode,
|
|
1648
1734
|
type BashCodeExecutionToolResultErrorParam as BashCodeExecutionToolResultErrorParam,
|
|
1735
|
+
type BrowserCloseTabConfig as BrowserCloseTabConfig,
|
|
1736
|
+
type BrowserDoubleClickConfig as BrowserDoubleClickConfig,
|
|
1737
|
+
type BrowserFileUploadConfig as BrowserFileUploadConfig,
|
|
1738
|
+
type BrowserFindConfig as BrowserFindConfig,
|
|
1739
|
+
type BrowserFormInputConfig as BrowserFormInputConfig,
|
|
1740
|
+
type BrowserGetPageTextConfig as BrowserGetPageTextConfig,
|
|
1741
|
+
type BrowserHoldKeyConfig as BrowserHoldKeyConfig,
|
|
1742
|
+
type BrowserHoverConfig as BrowserHoverConfig,
|
|
1743
|
+
type BrowserJavascriptExecConfig as BrowserJavascriptExecConfig,
|
|
1744
|
+
type BrowserKeyConfig as BrowserKeyConfig,
|
|
1745
|
+
type BrowserLeftClickConfig as BrowserLeftClickConfig,
|
|
1746
|
+
type BrowserLeftClickDragConfig as BrowserLeftClickDragConfig,
|
|
1747
|
+
type BrowserLeftMouseDownConfig as BrowserLeftMouseDownConfig,
|
|
1748
|
+
type BrowserLeftMouseUpConfig as BrowserLeftMouseUpConfig,
|
|
1749
|
+
type BrowserListTabsConfig as BrowserListTabsConfig,
|
|
1750
|
+
type BrowserMiddleClickConfig as BrowserMiddleClickConfig,
|
|
1751
|
+
type BrowserMouseMoveConfig as BrowserMouseMoveConfig,
|
|
1752
|
+
type BrowserNavigateConfig as BrowserNavigateConfig,
|
|
1753
|
+
type BrowserNewTabConfig as BrowserNewTabConfig,
|
|
1754
|
+
type BrowserReadConsoleConfig as BrowserReadConsoleConfig,
|
|
1755
|
+
type BrowserReadNetworkConfig as BrowserReadNetworkConfig,
|
|
1756
|
+
type BrowserReadPageConfig as BrowserReadPageConfig,
|
|
1757
|
+
type BrowserRightClickConfig as BrowserRightClickConfig,
|
|
1758
|
+
type BrowserScreenshotConfig as BrowserScreenshotConfig,
|
|
1759
|
+
type BrowserScrollConfig as BrowserScrollConfig,
|
|
1760
|
+
type BrowserScrollToConfig as BrowserScrollToConfig,
|
|
1761
|
+
type BrowserStateBlockParam as BrowserStateBlockParam,
|
|
1762
|
+
type BrowserStateChange as BrowserStateChange,
|
|
1763
|
+
type BrowserStateChangeDownloadCompleted as BrowserStateChangeDownloadCompleted,
|
|
1764
|
+
type BrowserStateChangeDownloadFailed as BrowserStateChangeDownloadFailed,
|
|
1765
|
+
type BrowserStateChangeDownloadStarted as BrowserStateChangeDownloadStarted,
|
|
1766
|
+
type BrowserStateChangeTabOpened as BrowserStateChangeTabOpened,
|
|
1767
|
+
type BrowserStateTabEntry as BrowserStateTabEntry,
|
|
1768
|
+
type BrowserSwitchTabConfig as BrowserSwitchTabConfig,
|
|
1769
|
+
type BrowserToolset20260801 as BrowserToolset20260801,
|
|
1770
|
+
type BrowserToolsetConfigs as BrowserToolsetConfigs,
|
|
1771
|
+
type BrowserTripleClickConfig as BrowserTripleClickConfig,
|
|
1772
|
+
type BrowserTypeConfig as BrowserTypeConfig,
|
|
1773
|
+
type BrowserWaitConfig as BrowserWaitConfig,
|
|
1774
|
+
type BrowserZoomConfig as BrowserZoomConfig,
|
|
1649
1775
|
type CacheControlEphemeral as CacheControlEphemeral,
|
|
1650
1776
|
type CacheCreation as CacheCreation,
|
|
1651
1777
|
type CitationCharLocation as CitationCharLocation,
|
|
@@ -1676,7 +1802,28 @@ export declare namespace Anthropic {
|
|
|
1676
1802
|
type CodeExecutionToolResultError as CodeExecutionToolResultError,
|
|
1677
1803
|
type CodeExecutionToolResultErrorCode as CodeExecutionToolResultErrorCode,
|
|
1678
1804
|
type CodeExecutionToolResultErrorParam as CodeExecutionToolResultErrorParam,
|
|
1805
|
+
type ComputerCursorPositionConfig as ComputerCursorPositionConfig,
|
|
1806
|
+
type ComputerDoubleClickConfig as ComputerDoubleClickConfig,
|
|
1807
|
+
type ComputerHoldKeyConfig as ComputerHoldKeyConfig,
|
|
1808
|
+
type ComputerKeyConfig as ComputerKeyConfig,
|
|
1809
|
+
type ComputerLeftClickConfig as ComputerLeftClickConfig,
|
|
1810
|
+
type ComputerLeftClickDragConfig as ComputerLeftClickDragConfig,
|
|
1811
|
+
type ComputerLeftMouseDownConfig as ComputerLeftMouseDownConfig,
|
|
1812
|
+
type ComputerLeftMouseUpConfig as ComputerLeftMouseUpConfig,
|
|
1813
|
+
type ComputerMiddleClickConfig as ComputerMiddleClickConfig,
|
|
1814
|
+
type ComputerMouseMoveConfig as ComputerMouseMoveConfig,
|
|
1815
|
+
type ComputerRightClickConfig as ComputerRightClickConfig,
|
|
1816
|
+
type ComputerScreenshotConfig as ComputerScreenshotConfig,
|
|
1817
|
+
type ComputerScrollConfig as ComputerScrollConfig,
|
|
1818
|
+
type ComputerToolset20260801 as ComputerToolset20260801,
|
|
1819
|
+
type ComputerToolsetConfigs as ComputerToolsetConfigs,
|
|
1820
|
+
type ComputerTripleClickConfig as ComputerTripleClickConfig,
|
|
1821
|
+
type ComputerTypeConfig as ComputerTypeConfig,
|
|
1822
|
+
type ComputerWaitConfig as ComputerWaitConfig,
|
|
1823
|
+
type ComputerZoomConfig as ComputerZoomConfig,
|
|
1679
1824
|
type Container as Container,
|
|
1825
|
+
type ContainerParams as ContainerParams,
|
|
1826
|
+
type ContainerSkill as ContainerSkill,
|
|
1680
1827
|
type ContainerUploadBlock as ContainerUploadBlock,
|
|
1681
1828
|
type ContainerUploadBlockParam as ContainerUploadBlockParam,
|
|
1682
1829
|
type ContentBlock as ContentBlock,
|
|
@@ -1691,12 +1838,16 @@ export declare namespace Anthropic {
|
|
|
1691
1838
|
type DocumentBlockParam as DocumentBlockParam,
|
|
1692
1839
|
type EncryptedCodeExecutionResultBlock as EncryptedCodeExecutionResultBlock,
|
|
1693
1840
|
type EncryptedCodeExecutionResultBlockParam as EncryptedCodeExecutionResultBlockParam,
|
|
1841
|
+
type FileDocumentSource as FileDocumentSource,
|
|
1842
|
+
type FileImageSource as FileImageSource,
|
|
1694
1843
|
type ImageBlockParam as ImageBlockParam,
|
|
1844
|
+
type ImageTransformationsParam as ImageTransformationsParam,
|
|
1695
1845
|
type InputJSONDelta as InputJSONDelta,
|
|
1696
1846
|
type JSONOutputFormat as JSONOutputFormat,
|
|
1697
1847
|
type MemoryTool20250818 as MemoryTool20250818,
|
|
1698
1848
|
type Message as Message,
|
|
1699
1849
|
type MessageCountTokensTool as MessageCountTokensTool,
|
|
1850
|
+
type MessageCreateParamsContainer as MessageCreateParamsContainer,
|
|
1700
1851
|
type MessageDeltaEvent as MessageDeltaEvent,
|
|
1701
1852
|
type MessageDeltaUsage as MessageDeltaUsage,
|
|
1702
1853
|
type MessageParam as MessageParam,
|
|
@@ -1705,7 +1856,6 @@ export declare namespace Anthropic {
|
|
|
1705
1856
|
type MessageStreamEvent as MessageStreamEvent,
|
|
1706
1857
|
type MessageTokensCount as MessageTokensCount,
|
|
1707
1858
|
type Metadata as Metadata,
|
|
1708
|
-
type MidConversationSystemBlockParam as MidConversationSystemBlockParam,
|
|
1709
1859
|
type Model as Model,
|
|
1710
1860
|
type OutputConfig as OutputConfig,
|
|
1711
1861
|
type OutputTokensDetails as OutputTokensDetails,
|
|
@@ -1728,6 +1878,7 @@ export declare namespace Anthropic {
|
|
|
1728
1878
|
type ServerToolUseBlock as ServerToolUseBlock,
|
|
1729
1879
|
type ServerToolUseBlockParam as ServerToolUseBlockParam,
|
|
1730
1880
|
type SignatureDelta as SignatureDelta,
|
|
1881
|
+
type SkillParams as SkillParams,
|
|
1731
1882
|
type StopReason as StopReason,
|
|
1732
1883
|
type TextBlock as TextBlock,
|
|
1733
1884
|
type TextBlockParam as TextBlockParam,
|
|
@@ -1825,6 +1976,25 @@ export declare namespace Anthropic {
|
|
|
1825
1976
|
type ModelListParams as ModelListParams,
|
|
1826
1977
|
};
|
|
1827
1978
|
|
|
1979
|
+
export {
|
|
1980
|
+
Files as Files,
|
|
1981
|
+
type DeletedFile as DeletedFile,
|
|
1982
|
+
type FileMetadata as FileMetadata,
|
|
1983
|
+
type FileMetadataPageCursor as FileMetadataPageCursor,
|
|
1984
|
+
type FileListParams as FileListParams,
|
|
1985
|
+
type FileUploadParams as FileUploadParams,
|
|
1986
|
+
};
|
|
1987
|
+
|
|
1988
|
+
export {
|
|
1989
|
+
Skills as Skills,
|
|
1990
|
+
type DeletedSkill as DeletedSkill,
|
|
1991
|
+
type Skill as Skill,
|
|
1992
|
+
type SkillSource as SkillSource,
|
|
1993
|
+
type SkillsPageCursor as SkillsPageCursor,
|
|
1994
|
+
type SkillCreateParams as SkillCreateParams,
|
|
1995
|
+
type SkillListParams as SkillListParams,
|
|
1996
|
+
};
|
|
1997
|
+
|
|
1828
1998
|
export {
|
|
1829
1999
|
Beta as Beta,
|
|
1830
2000
|
type AnthropicBeta as AnthropicBeta,
|
package/src/core/api-promise.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type APIResponseProps,
|
|
8
8
|
type WithRequestID,
|
|
9
9
|
defaultParseResponse,
|
|
10
|
-
|
|
10
|
+
addResponseIDs,
|
|
11
11
|
} from '../internal/parse';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -37,7 +37,7 @@ export class APIPromise<T> extends Promise<WithRequestID<T>> {
|
|
|
37
37
|
|
|
38
38
|
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
|
|
39
39
|
return new APIPromise(this.#client, this.responsePromise, async (client, props) =>
|
|
40
|
-
|
|
40
|
+
addResponseIDs(transform(await this.parseResponse(client, props), props), props.response),
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -68,9 +68,19 @@ export class APIPromise<T> extends Promise<WithRequestID<T>> {
|
|
|
68
68
|
* Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
|
|
69
69
|
* to your `tsconfig.json`.
|
|
70
70
|
*/
|
|
71
|
-
async withResponse(): Promise<{
|
|
71
|
+
async withResponse(): Promise<{
|
|
72
|
+
data: T;
|
|
73
|
+
response: Response;
|
|
74
|
+
request_id: string | null | undefined;
|
|
75
|
+
workspace_id: string | null | undefined;
|
|
76
|
+
}> {
|
|
72
77
|
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
73
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
data,
|
|
80
|
+
response,
|
|
81
|
+
request_id: response.headers.get('request-id'),
|
|
82
|
+
workspace_id: response.headers.get('anthropic-workspace-id'),
|
|
83
|
+
};
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
private parse(): Promise<WithRequestID<T>> {
|
package/src/core/error.ts
CHANGED
|
@@ -18,6 +18,7 @@ export class APIError<
|
|
|
18
18
|
readonly error: TError;
|
|
19
19
|
|
|
20
20
|
readonly requestID: string | null | undefined;
|
|
21
|
+
readonly workspaceID: string | null | undefined;
|
|
21
22
|
|
|
22
23
|
/** The `error.type` from the API response body, e.g. `"rate_limit_error"` */
|
|
23
24
|
readonly type: ErrorType | null;
|
|
@@ -33,6 +34,7 @@ export class APIError<
|
|
|
33
34
|
this.status = status;
|
|
34
35
|
this.headers = headers;
|
|
35
36
|
this.requestID = headers?.get('request-id');
|
|
37
|
+
this.workspaceID = headers?.get('anthropic-workspace-id');
|
|
36
38
|
this.error = error;
|
|
37
39
|
this.type = type ?? null;
|
|
38
40
|
}
|
package/src/core/middleware.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BaseAnthropic } from '../client';
|
|
2
2
|
import type { Fetch } from '../internal/builtin-types';
|
|
3
3
|
import { castToError, isAbortError } from '../internal/errors';
|
|
4
|
-
import {
|
|
4
|
+
import { addResponseIDs } from '../internal/parse';
|
|
5
5
|
import type { FinalRequestOptions } from '../internal/request-options';
|
|
6
6
|
import { defaultLogger, loggerFor, type Logger } from '../internal/utils/log';
|
|
7
7
|
import type { APIRequest } from './api';
|
|
@@ -299,7 +299,7 @@ async function parseMiddlewareResponse(
|
|
|
299
299
|
// if there is no content we can't do anything
|
|
300
300
|
return undefined;
|
|
301
301
|
}
|
|
302
|
-
return
|
|
302
|
+
return addResponseIDs(await response.clone().json(), response);
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
return await response.clone().text();
|
package/src/helpers/beta/zod.ts
CHANGED
|
@@ -16,9 +16,7 @@ import { BetaToolResultContentBlockParam } from '../../resources/beta';
|
|
|
16
16
|
export function betaZodOutputFormat<ZodInput extends z.ZodType>(
|
|
17
17
|
zodObject: ZodInput,
|
|
18
18
|
): AutoParseableBetaOutputFormat<z.infer<ZodInput>> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
jsonSchema = transformJSONSchema(jsonSchema);
|
|
19
|
+
const jsonSchema = transformJSONSchema(z.toJSONSchema(zodObject, { reused: 'ref' }));
|
|
22
20
|
|
|
23
21
|
return {
|
|
24
22
|
type: 'json_schema',
|
package/src/helpers/zod.ts
CHANGED
|
@@ -15,9 +15,7 @@ import { AutoParseableOutputFormat } from '../lib/parser';
|
|
|
15
15
|
export function zodOutputFormat<ZodInput extends z.ZodType>(
|
|
16
16
|
zodObject: ZodInput,
|
|
17
17
|
): AutoParseableOutputFormat<z.infer<ZodInput>> {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
jsonSchema = transformJSONSchema(jsonSchema);
|
|
18
|
+
const jsonSchema = transformJSONSchema(z.toJSONSchema(zodObject, { reused: 'ref' }));
|
|
21
19
|
|
|
22
20
|
return {
|
|
23
21
|
type: 'json_schema',
|
package/src/internal/parse.ts
CHANGED
|
@@ -51,7 +51,7 @@ export async function defaultParseResponse<T>(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const json = await response.json();
|
|
54
|
-
return
|
|
54
|
+
return addResponseIDs(json as T, response);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const text = await response.text();
|
|
@@ -80,16 +80,16 @@ export async function defaultParseResponse<T>(
|
|
|
80
80
|
|
|
81
81
|
export type WithRequestID<T> =
|
|
82
82
|
T extends Array<any> | Response | AbstractPage<any> ? T
|
|
83
|
-
: T extends Record<string, any> ? T & { _request_id?: string | null }
|
|
83
|
+
: T extends Record<string, any> ? T & { _request_id?: string | null; _workspace_id?: string | null }
|
|
84
84
|
: T;
|
|
85
85
|
|
|
86
|
-
export function
|
|
86
|
+
export function addResponseIDs<T>(value: T, response: Response): WithRequestID<T> {
|
|
87
87
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
88
88
|
return value as WithRequestID<T>;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
return Object.
|
|
92
|
-
value: response.headers.get('request-id'),
|
|
93
|
-
enumerable: false,
|
|
91
|
+
return Object.defineProperties(value, {
|
|
92
|
+
_request_id: { value: response.headers.get('request-id'), enumerable: false },
|
|
93
|
+
_workspace_id: { value: response.headers.get('anthropic-workspace-id'), enumerable: false },
|
|
94
94
|
}) as WithRequestID<T>;
|
|
95
95
|
}
|
|
@@ -74,6 +74,7 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
|
|
|
74
74
|
#catchingPromiseCreated = false;
|
|
75
75
|
#response: Response | null | undefined;
|
|
76
76
|
#request_id: string | null | undefined;
|
|
77
|
+
#workspace_id: string | null | undefined;
|
|
77
78
|
#logger: Logger;
|
|
78
79
|
|
|
79
80
|
constructor(params: MessageCreateParamsBase | null, opts?: { logger?: Logger | undefined }) {
|
|
@@ -106,6 +107,10 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
|
|
|
106
107
|
return this.#request_id;
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
get workspace_id(): string | null | undefined {
|
|
111
|
+
return this.#workspace_id;
|
|
112
|
+
}
|
|
113
|
+
|
|
109
114
|
/**
|
|
110
115
|
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
|
111
116
|
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
|
@@ -120,6 +125,7 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
|
|
|
120
125
|
data: BetaMessageStream<ParsedT>;
|
|
121
126
|
response: Response;
|
|
122
127
|
request_id: string | null | undefined;
|
|
128
|
+
workspace_id: string | null | undefined;
|
|
123
129
|
}> {
|
|
124
130
|
this.#catchingPromiseCreated = true;
|
|
125
131
|
|
|
@@ -132,6 +138,7 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
|
|
|
132
138
|
data: this,
|
|
133
139
|
response,
|
|
134
140
|
request_id: response.headers.get('request-id'),
|
|
141
|
+
workspace_id: response.headers.get('anthropic-workspace-id'),
|
|
135
142
|
};
|
|
136
143
|
}
|
|
137
144
|
|
|
@@ -223,6 +230,7 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
|
|
|
223
230
|
if (this.ended) return;
|
|
224
231
|
this.#response = response;
|
|
225
232
|
this.#request_id = response?.headers.get('request-id');
|
|
233
|
+
this.#workspace_id = response?.headers.get('anthropic-workspace-id');
|
|
226
234
|
this.#resolveConnectedPromise(response);
|
|
227
235
|
this._emit('connect');
|
|
228
236
|
}
|
package/src/lib/MessageStream.ts
CHANGED
|
@@ -73,6 +73,7 @@ export class MessageStream<ParsedT = null> implements AsyncIterable<MessageStrea
|
|
|
73
73
|
#catchingPromiseCreated = false;
|
|
74
74
|
#response: Response | null | undefined;
|
|
75
75
|
#request_id: string | null | undefined;
|
|
76
|
+
#workspace_id: string | null | undefined;
|
|
76
77
|
#logger: Logger;
|
|
77
78
|
|
|
78
79
|
constructor(params: MessageCreateParamsBase | null, opts?: { logger?: Logger | undefined }) {
|
|
@@ -105,6 +106,10 @@ export class MessageStream<ParsedT = null> implements AsyncIterable<MessageStrea
|
|
|
105
106
|
return this.#request_id;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
get workspace_id(): string | null | undefined {
|
|
110
|
+
return this.#workspace_id;
|
|
111
|
+
}
|
|
112
|
+
|
|
108
113
|
/**
|
|
109
114
|
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
|
110
115
|
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
|
@@ -119,6 +124,7 @@ export class MessageStream<ParsedT = null> implements AsyncIterable<MessageStrea
|
|
|
119
124
|
data: MessageStream<ParsedT>;
|
|
120
125
|
response: Response;
|
|
121
126
|
request_id: string | null | undefined;
|
|
127
|
+
workspace_id: string | null | undefined;
|
|
122
128
|
}> {
|
|
123
129
|
this.#catchingPromiseCreated = true;
|
|
124
130
|
|
|
@@ -131,6 +137,7 @@ export class MessageStream<ParsedT = null> implements AsyncIterable<MessageStrea
|
|
|
131
137
|
data: this,
|
|
132
138
|
response,
|
|
133
139
|
request_id: response.headers.get('request-id'),
|
|
140
|
+
workspace_id: response.headers.get('anthropic-workspace-id'),
|
|
134
141
|
};
|
|
135
142
|
}
|
|
136
143
|
|
|
@@ -222,6 +229,7 @@ export class MessageStream<ParsedT = null> implements AsyncIterable<MessageStrea
|
|
|
222
229
|
if (this.ended) return;
|
|
223
230
|
this.#response = response;
|
|
224
231
|
this.#request_id = response?.headers.get('request-id');
|
|
232
|
+
this.#workspace_id = response?.headers.get('anthropic-workspace-id');
|
|
225
233
|
this.#resolveConnectedPromise(response);
|
|
226
234
|
this._emit('connect');
|
|
227
235
|
}
|
|
@@ -52,6 +52,10 @@ export interface EnvironmentWorkerOptions {
|
|
|
52
52
|
* Tools to expose to each claimed session. Defaults to
|
|
53
53
|
* `betaAgentToolset20260401(ctx)` (the standard `agent_toolset_20260401` set
|
|
54
54
|
* bound to the per-session {@link AgentToolContext}).
|
|
55
|
+
*
|
|
56
|
+
* A `run` that blocks the event loop synchronously also stalls the lease
|
|
57
|
+
* heartbeat, and the worker can lose the lease; keep tools non-blocking (see
|
|
58
|
+
* {@link BetaRunnableTool.run}).
|
|
55
59
|
*/
|
|
56
60
|
tools?: EnvironmentWorkerTools;
|
|
57
61
|
/** Base directory for the per-session {@link AgentToolContext}. Defaults to `process.cwd()`. */
|
|
@@ -110,10 +114,10 @@ type ClaimedWork = Pick<BetaSelfHostedWork, 'id' | 'environment_id' | 'data'>;
|
|
|
110
114
|
* For each claimed `session` work item it: builds the per-session
|
|
111
115
|
* {@link AgentToolContext}, downloads the session agent's skills
|
|
112
116
|
* (`setupSkills`), then runs a {@link SessionToolRunner} for the session
|
|
113
|
-
*
|
|
114
|
-
* the work item, cleans up the downloaded skills, and loops to the
|
|
115
|
-
* lease heartbeat reports `state === "stopping"` / a lost lease
|
|
116
|
-
* by aborting the session runner.
|
|
117
|
+
* while heartbeating the work-item lease on the same event loop; on exit it
|
|
118
|
+
* force-stops the work item, cleans up the downloaded skills, and loops to the
|
|
119
|
+
* next one. The lease heartbeat reports `state === "stopping"` / a lost lease
|
|
120
|
+
* back into the run by aborting the session runner.
|
|
117
121
|
*
|
|
118
122
|
* Use {@link EnvironmentWorker.handleItem} if you already hold a claimed work
|
|
119
123
|
* item (e.g. a `worker poll --on-work` script handed one to a fresh process) and
|
|
@@ -196,8 +200,8 @@ export class EnvironmentWorker {
|
|
|
196
200
|
* per-session {@link AgentToolContext} (workdir from this worker's options),
|
|
197
201
|
* download the session agent's skills (`setupSkills`), run a
|
|
198
202
|
* {@link SessionToolRunner} for the session while heartbeating the work-item
|
|
199
|
-
* lease
|
|
200
|
-
*
|
|
203
|
+
* lease, and force-stop the work item on exit (whether the runner finishes
|
|
204
|
+
* normally, throws, or the heartbeat loop signals shutdown).
|
|
201
205
|
*
|
|
202
206
|
* Use this when something else does the claiming — e.g. a `worker poll
|
|
203
207
|
* --on-work` script that hands an already-claimed item to a fresh process. The
|
|
@@ -293,19 +297,26 @@ export class EnvironmentWorker {
|
|
|
293
297
|
const ctrl = new AbortController();
|
|
294
298
|
const detachExternal = linkAbort(externalSignal, ctrl);
|
|
295
299
|
|
|
296
|
-
|
|
300
|
+
// Inert until iterated below.
|
|
301
|
+
const runner = new SessionToolRunner(sessionId, {
|
|
302
|
+
client: sessionClient,
|
|
303
|
+
tools,
|
|
304
|
+
...(this.maxIdleMs !== undefined ? { maxIdleMs: this.maxIdleMs } : {}),
|
|
305
|
+
...(this.requestOptions !== undefined ? { requestOptions: this.requestOptions } : {}),
|
|
306
|
+
signal: ctrl.signal,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Each heartbeat reports the lease TTL the server is enforcing; it becomes
|
|
310
|
+
// the runner's tool-result send retry window so a send keeps retrying
|
|
311
|
+
// exactly as long as the lease could still be live.
|
|
312
|
+
const heartbeatPromise = heartbeatLoop(sessionClient, work, ctrl, log, this.requestOptions, (ttlMs) =>
|
|
313
|
+
runner._setSendRetryWindow(ttlMs),
|
|
314
|
+
).catch((e) => {
|
|
297
315
|
if (!ctrl.signal.aborted) log.error('heartbeat loop failed', { work_id: work.id, error: String(e) });
|
|
298
316
|
ctrl.abort();
|
|
299
317
|
});
|
|
300
318
|
|
|
301
319
|
try {
|
|
302
|
-
const runner = new SessionToolRunner(sessionId, {
|
|
303
|
-
client: sessionClient,
|
|
304
|
-
tools,
|
|
305
|
-
...(this.maxIdleMs !== undefined ? { maxIdleMs: this.maxIdleMs } : {}),
|
|
306
|
-
...(this.requestOptions !== undefined ? { requestOptions: this.requestOptions } : {}),
|
|
307
|
-
signal: ctrl.signal,
|
|
308
|
-
});
|
|
309
320
|
for await (const _ of runner) {
|
|
310
321
|
// Drive the runner to completion; per-call observability is not part
|
|
311
322
|
// of this composition's surface — use `SessionToolRunner` directly
|
|
@@ -360,6 +371,8 @@ async function heartbeatLoop(
|
|
|
360
371
|
ctrl: AbortController,
|
|
361
372
|
logger: Logger,
|
|
362
373
|
requestOptions?: BetaToolRunnerRequestOptions,
|
|
374
|
+
/** Called with the server-reported lease TTL after every successful beat. */
|
|
375
|
+
onLeaseTtl?: (ttlMs: number) => void,
|
|
363
376
|
): Promise<void> {
|
|
364
377
|
let intervalMs = HEARTBEAT_DEFAULT_MS;
|
|
365
378
|
let ttlMs = HEARTBEAT_TTL_DEFAULT_MS;
|
|
@@ -382,6 +395,7 @@ async function heartbeatLoop(
|
|
|
382
395
|
if (resp.ttl_seconds > 0) {
|
|
383
396
|
ttlMs = resp.ttl_seconds * 1000;
|
|
384
397
|
intervalMs = Math.max(1_000, Math.min(ttlMs / 2, HEARTBEAT_DEFAULT_MS));
|
|
398
|
+
onLeaseTtl?.(ttlMs);
|
|
385
399
|
}
|
|
386
400
|
if (resp.state === 'stopping' || resp.state === 'stopped') {
|
|
387
401
|
logger.info('heartbeat signals shutdown', { work_id: work.id, state: resp.state });
|