@anthropic-ai/sdk 0.105.0 → 0.106.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 +19 -0
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +2 -1
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +2 -1
- package/core/streaming.mjs.map +1 -1
- package/helpers/beta/mcp.d.mts +1 -1
- package/helpers/beta/mcp.d.mts.map +1 -1
- package/helpers/beta/mcp.d.ts +1 -1
- package/helpers/beta/mcp.d.ts.map +1 -1
- package/helpers/beta/mcp.js +1 -1
- package/helpers/beta/mcp.js.map +1 -1
- package/helpers/beta/mcp.mjs +1 -1
- package/helpers/beta/mcp.mjs.map +1 -1
- package/internal/headers.d.mts +7 -0
- package/internal/headers.d.mts.map +1 -1
- package/internal/headers.d.ts +7 -0
- package/internal/headers.d.ts.map +1 -1
- package/internal/headers.js +45 -4
- package/internal/headers.js.map +1 -1
- package/internal/headers.mjs +43 -3
- package/internal/headers.mjs.map +1 -1
- package/internal/stainless-helper-header.d.mts +60 -0
- package/internal/stainless-helper-header.d.mts.map +1 -0
- package/internal/stainless-helper-header.d.ts +60 -0
- package/internal/stainless-helper-header.d.ts.map +1 -0
- package/{lib → internal}/stainless-helper-header.js +27 -6
- package/internal/stainless-helper-header.js.map +1 -0
- package/{lib → internal}/stainless-helper-header.mjs +25 -5
- package/internal/stainless-helper-header.mjs.map +1 -0
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +2 -1
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +2 -1
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.mts.map +1 -1
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +2 -1
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +2 -1
- package/lib/MessageStream.mjs.map +1 -1
- package/lib/helper-client.d.mts +2 -20
- package/lib/helper-client.d.mts.map +1 -1
- package/lib/helper-client.d.ts +2 -20
- package/lib/helper-client.d.ts.map +1 -1
- package/lib/helper-client.js +2 -1
- package/lib/helper-client.js.map +1 -1
- package/lib/helper-client.mjs +2 -1
- package/lib/helper-client.mjs.map +1 -1
- package/lib/middleware.d.mts.map +1 -1
- package/lib/middleware.d.ts.map +1 -1
- package/lib/middleware.js +7 -5
- package/lib/middleware.js.map +1 -1
- package/lib/middleware.mjs +7 -5
- package/lib/middleware.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 +11 -5
- package/lib/tools/BetaToolRunner.js.map +1 -1
- package/lib/tools/BetaToolRunner.mjs +11 -5
- package/lib/tools/BetaToolRunner.mjs.map +1 -1
- package/lib/tools/SessionToolRunner.d.mts.map +1 -1
- package/lib/tools/SessionToolRunner.d.ts.map +1 -1
- package/lib/tools/SessionToolRunner.js +2 -3
- package/lib/tools/SessionToolRunner.js.map +1 -1
- package/lib/tools/SessionToolRunner.mjs +2 -3
- package/lib/tools/SessionToolRunner.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/agents/agents.d.mts +7 -2
- package/resources/beta/agents/agents.d.mts.map +1 -1
- package/resources/beta/agents/agents.d.ts +7 -2
- package/resources/beta/agents/agents.d.ts.map +1 -1
- package/resources/beta/agents/agents.js.map +1 -1
- package/resources/beta/agents/agents.mjs.map +1 -1
- package/resources/beta/files.js +1 -1
- package/resources/beta/files.js.map +1 -1
- package/resources/beta/files.mjs +1 -1
- package/resources/beta/files.mjs.map +1 -1
- package/resources/beta/messages/batches.d.mts +8 -5
- package/resources/beta/messages/batches.d.mts.map +1 -1
- package/resources/beta/messages/batches.d.ts +8 -5
- package/resources/beta/messages/batches.d.ts.map +1 -1
- package/resources/beta/messages/batches.js +5 -2
- package/resources/beta/messages/batches.js.map +1 -1
- package/resources/beta/messages/batches.mjs +5 -2
- package/resources/beta/messages/batches.mjs.map +1 -1
- package/resources/beta/messages/messages.d.mts +11 -8
- package/resources/beta/messages/messages.d.mts.map +1 -1
- package/resources/beta/messages/messages.d.ts +11 -8
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js +6 -3
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs +6 -3
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/messages/batches.d.mts +11 -3
- package/resources/messages/batches.d.mts.map +1 -1
- package/resources/messages/batches.d.ts +11 -3
- package/resources/messages/batches.d.ts.map +1 -1
- package/resources/messages/batches.js +10 -2
- package/resources/messages/batches.js.map +1 -1
- package/resources/messages/batches.mjs +10 -2
- package/resources/messages/batches.mjs.map +1 -1
- package/resources/messages/messages.d.mts +38 -26
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +38 -26
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js +9 -4
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs +9 -4
- package/resources/messages/messages.mjs.map +1 -1
- package/src/core/streaming.ts +2 -1
- package/src/helpers/beta/mcp.ts +1 -1
- package/src/internal/headers.ts +47 -4
- package/src/internal/stainless-helper-header.ts +122 -0
- package/src/lib/BetaMessageStream.ts +2 -1
- package/src/lib/MessageStream.ts +2 -1
- package/src/lib/helper-client.ts +6 -9
- package/src/lib/middleware.ts +10 -4
- package/src/lib/tools/BetaToolRunner.ts +15 -6
- package/src/lib/tools/SessionToolRunner.ts +2 -4
- package/src/resources/beta/agents/agents.ts +7 -2
- package/src/resources/beta/files.ts +1 -1
- package/src/resources/beta/messages/batches.ts +14 -8
- package/src/resources/beta/messages/messages.ts +17 -11
- package/src/resources/messages/batches.ts +21 -4
- package/src/resources/messages/messages.ts +48 -31
- 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/lib/stainless-helper-header.d.mts +0 -34
- package/lib/stainless-helper-header.d.mts.map +0 -1
- package/lib/stainless-helper-header.d.ts +0 -34
- package/lib/stainless-helper-header.d.ts.map +0 -1
- package/lib/stainless-helper-header.js.map +0 -1
- package/lib/stainless-helper-header.mjs.map +0 -1
- package/src/lib/stainless-helper-header.ts +0 -80
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the `x-stainless-helper` telemetry header — the
|
|
3
|
+
* key, the closed value vocabulary, and per-object helper tagging. The
|
|
4
|
+
* append-don't-clobber merge for the header itself lives in
|
|
5
|
+
* {@link import('../internal/headers').buildHeaders} via `APPEND_HEADERS`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Telemetry header naming the SDK helper(s) a request came from. Always this
|
|
10
|
+
* lowercase form; `buildHeaders` matches it case-insensitively for its append
|
|
11
|
+
* semantics, but a single canonical casing keeps every call site greppable.
|
|
12
|
+
*/
|
|
13
|
+
export const STAINLESS_HELPER_HEADER = 'x-stainless-helper';
|
|
14
|
+
|
|
15
|
+
/** Telemetry header naming the SDK method (e.g. `stream`) in use. */
|
|
16
|
+
export const STAINLESS_HELPER_METHOD_HEADER = 'x-stainless-helper-method';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The closed set of helper telemetry tags, shared verbatim across SDKs. A
|
|
20
|
+
* typo at any call site is a type error rather than silently mistagged
|
|
21
|
+
* telemetry. Existing values keep their original spellings — telemetry
|
|
22
|
+
* consumers match on them, so renames lose history. New tags are hyphenated
|
|
23
|
+
* lowercase.
|
|
24
|
+
*/
|
|
25
|
+
export type StainlessHelperHeaderValue =
|
|
26
|
+
| 'BetaToolRunner'
|
|
27
|
+
| 'betaZodTool'
|
|
28
|
+
| 'compaction'
|
|
29
|
+
| 'environments-work-poller'
|
|
30
|
+
| 'environments-worker'
|
|
31
|
+
| 'fallback-refusal-middleware'
|
|
32
|
+
| 'mcpContent'
|
|
33
|
+
| 'mcpMessage'
|
|
34
|
+
| 'mcpResourceToContent'
|
|
35
|
+
| 'mcpResourceToFile'
|
|
36
|
+
| 'mcpTool'
|
|
37
|
+
| 'session-tool-runner';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The `{ 'x-stainless-helper': value }` header dict, for passing into
|
|
41
|
+
* `buildHeaders` (which comma-appends `x-stainless-helper` across sources)
|
|
42
|
+
* or as `defaultHeaders`/per-request `headers`.
|
|
43
|
+
*/
|
|
44
|
+
export function helperHeader(value: StainlessHelperHeaderValue): { [STAINLESS_HELPER_HEADER]: string } {
|
|
45
|
+
return { [STAINLESS_HELPER_HEADER]: value };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Symbol used to mark objects created by SDK helpers for tracking.
|
|
50
|
+
* The value is the helper name (e.g., 'mcpTool', 'betaZodTool').
|
|
51
|
+
*/
|
|
52
|
+
export const SDK_HELPER_SYMBOL = Symbol('anthropic.sdk.stainlessHelper');
|
|
53
|
+
|
|
54
|
+
type StainlessHelperObject = { [SDK_HELPER_SYMBOL]: string };
|
|
55
|
+
|
|
56
|
+
export function wasCreatedByStainlessHelper(value: unknown): value is StainlessHelperObject {
|
|
57
|
+
return typeof value === 'object' && value !== null && SDK_HELPER_SYMBOL in value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Collects helper names from tools and messages arrays.
|
|
62
|
+
* Returns a deduplicated array of helper names found.
|
|
63
|
+
*/
|
|
64
|
+
export function collectStainlessHelpers(
|
|
65
|
+
tools: readonly unknown[] | undefined,
|
|
66
|
+
messages: readonly unknown[] | undefined,
|
|
67
|
+
): string[] {
|
|
68
|
+
const helpers = new Set<string>();
|
|
69
|
+
|
|
70
|
+
// Collect from tools
|
|
71
|
+
if (tools) {
|
|
72
|
+
for (const tool of tools) {
|
|
73
|
+
if (wasCreatedByStainlessHelper(tool)) {
|
|
74
|
+
helpers.add(tool[SDK_HELPER_SYMBOL]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Collect from messages and their content blocks
|
|
80
|
+
if (messages) {
|
|
81
|
+
for (const message of messages) {
|
|
82
|
+
if (wasCreatedByStainlessHelper(message)) {
|
|
83
|
+
helpers.add(message[SDK_HELPER_SYMBOL]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const content = (message as { content?: unknown }).content;
|
|
87
|
+
if (Array.isArray(content)) {
|
|
88
|
+
for (const block of content) {
|
|
89
|
+
if (wasCreatedByStainlessHelper(block)) {
|
|
90
|
+
helpers.add(block[SDK_HELPER_SYMBOL]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return Array.from(helpers);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Builds x-stainless-helper header value from tools and messages.
|
|
102
|
+
* Returns an empty object if no helpers are found.
|
|
103
|
+
*/
|
|
104
|
+
export function stainlessHelperHeader(
|
|
105
|
+
tools: readonly unknown[] | undefined,
|
|
106
|
+
messages: readonly unknown[] | undefined,
|
|
107
|
+
): { 'x-stainless-helper'?: string } {
|
|
108
|
+
const helpers = collectStainlessHelpers(tools, messages);
|
|
109
|
+
if (helpers.length === 0) return {};
|
|
110
|
+
return { [STAINLESS_HELPER_HEADER]: helpers.join(', ') };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Builds x-stainless-helper header value from a file object.
|
|
115
|
+
* Returns an empty object if the file is not marked with a helper.
|
|
116
|
+
*/
|
|
117
|
+
export function stainlessHelperHeaderFromFile(file: unknown): { 'x-stainless-helper'?: string } {
|
|
118
|
+
if (wasCreatedByStainlessHelper(file)) {
|
|
119
|
+
return { [STAINLESS_HELPER_HEADER]: file[SDK_HELPER_SYMBOL] };
|
|
120
|
+
}
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STAINLESS_HELPER_METHOD_HEADER } from '../internal/stainless-helper-header';
|
|
1
2
|
import type { Logger } from '../client';
|
|
2
3
|
import { AnthropicError, APIUserAbortError } from '../error';
|
|
3
4
|
import { isAbortError } from '../internal/errors';
|
|
@@ -162,7 +163,7 @@ export class BetaMessageStream<ParsedT = null> implements AsyncIterable<BetaMess
|
|
|
162
163
|
runner._createMessage(
|
|
163
164
|
messages,
|
|
164
165
|
{ ...params, stream: true },
|
|
165
|
-
{ ...options, headers: { ...options?.headers,
|
|
166
|
+
{ ...options, headers: { ...options?.headers, [STAINLESS_HELPER_METHOD_HEADER]: 'stream' } },
|
|
166
167
|
),
|
|
167
168
|
);
|
|
168
169
|
return runner;
|
package/src/lib/MessageStream.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STAINLESS_HELPER_METHOD_HEADER } from '../internal/stainless-helper-header';
|
|
1
2
|
import { isAbortError } from '../internal/errors';
|
|
2
3
|
import { AnthropicError, APIUserAbortError } from '../error';
|
|
3
4
|
import {
|
|
@@ -161,7 +162,7 @@ export class MessageStream<ParsedT = null> implements AsyncIterable<MessageStrea
|
|
|
161
162
|
runner._createMessage(
|
|
162
163
|
messages,
|
|
163
164
|
{ ...params, stream: true },
|
|
164
|
-
{ ...options, headers: { ...options?.headers,
|
|
165
|
+
{ ...options, headers: { ...options?.headers, [STAINLESS_HELPER_METHOD_HEADER]: 'stream' } },
|
|
165
166
|
),
|
|
166
167
|
);
|
|
167
168
|
return runner;
|
package/src/lib/helper-client.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { AnthropicError } from '../core/error';
|
|
2
2
|
import type { Anthropic } from '../client';
|
|
3
3
|
import { buildHeaders, type HeadersLike, type NullableHeaders } from '../internal/headers';
|
|
4
|
+
import {
|
|
5
|
+
STAINLESS_HELPER_HEADER,
|
|
6
|
+
type StainlessHelperHeaderValue,
|
|
7
|
+
} from '../internal/stainless-helper-header';
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Shared util for building a runner-helper-bound sub-client.
|
|
@@ -16,13 +20,6 @@ import { buildHeaders, type HeadersLike, type NullableHeaders } from '../interna
|
|
|
16
20
|
* {@link copyClientForHelper} is the one shared construction.
|
|
17
21
|
*/
|
|
18
22
|
|
|
19
|
-
/**
|
|
20
|
-
* The closed set of `x-stainless-helper` telemetry tags the runner helpers
|
|
21
|
-
* stamp on outgoing requests. Constrained as a string union so a typo at any
|
|
22
|
-
* call site is a type error rather than silently mistagged telemetry.
|
|
23
|
-
*/
|
|
24
|
-
export type HelperTag = 'environments-work-poller' | 'environments-worker' | 'session-tool-runner';
|
|
25
|
-
|
|
26
23
|
interface ClientInternalAccess {
|
|
27
24
|
_options: { defaultHeaders?: HeadersLike };
|
|
28
25
|
_authState?: { extraHeaders?: Record<string, string> };
|
|
@@ -54,7 +51,7 @@ interface ClientInternalAccess {
|
|
|
54
51
|
*/
|
|
55
52
|
export function copyClientForHelper<T extends Anthropic>(
|
|
56
53
|
client: T,
|
|
57
|
-
{ authToken, helper }: { authToken: string; helper:
|
|
54
|
+
{ authToken, helper }: { authToken: string; helper: StainlessHelperHeaderValue },
|
|
58
55
|
): T {
|
|
59
56
|
if (!authToken) {
|
|
60
57
|
throw new AnthropicError(
|
|
@@ -77,7 +74,7 @@ export function copyClientForHelper<T extends Anthropic>(
|
|
|
77
74
|
const defaultHeaders: NullableHeaders = buildHeaders([
|
|
78
75
|
inheritedAuthExtraHeaders,
|
|
79
76
|
parentDefaults,
|
|
80
|
-
{
|
|
77
|
+
{ [STAINLESS_HELPER_HEADER]: helper },
|
|
81
78
|
]);
|
|
82
79
|
return client.withOptions({
|
|
83
80
|
apiKey: null,
|
package/src/lib/middleware.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { AnthropicError } from '../core/error';
|
|
|
3
3
|
import type { Middleware, MiddlewareContext, MiddlewareNext } from '../core/middleware';
|
|
4
4
|
import { Stream, type ServerSentEvent } from '../core/streaming';
|
|
5
5
|
import { isAbortError } from '../internal/errors';
|
|
6
|
+
import { appendHeaderValue } from '../internal/headers';
|
|
7
|
+
import { STAINLESS_HELPER_HEADER } from '../internal/stainless-helper-header';
|
|
6
8
|
import { safeJSON } from '../internal/utils/values';
|
|
7
9
|
import type { AnthropicBeta } from '../resources/beta/beta';
|
|
8
10
|
import type {
|
|
@@ -179,8 +181,9 @@ export function betaRefusalFallbackMiddleware(
|
|
|
179
181
|
((error: BetaRefusalFallbackError) =>
|
|
180
182
|
ctx.logger.error(`anthropic-sdk: betaRefusalFallbackMiddleware: ${error.message}`));
|
|
181
183
|
|
|
182
|
-
// Send the configured betas on this and every hop request derived from it
|
|
183
|
-
|
|
184
|
+
// Send the configured betas on this and every hop request derived from it,
|
|
185
|
+
// and tag this and every hop with the middleware's helper telemetry.
|
|
186
|
+
request = withMiddlewareHeaders(request, options.betas ?? DEFAULT_BETAS);
|
|
184
187
|
|
|
185
188
|
const body = stripFallbackBlocks(ctx.options.body as MessageCreateParams);
|
|
186
189
|
const state = ctx.options.fallbackState;
|
|
@@ -851,8 +854,7 @@ function toPrefillBlocks(responseBlocks: any[]): BetaContentBlockParam[] {
|
|
|
851
854
|
* A copy of `request` with `betas` appended to its `anthropic-beta` header,
|
|
852
855
|
* skipping values already present (set by the caller or another middleware).
|
|
853
856
|
*/
|
|
854
|
-
function
|
|
855
|
-
if (!betas.length) return request;
|
|
857
|
+
function withMiddlewareHeaders(request: APIRequest, betas: readonly AnthropicBeta[]): APIRequest {
|
|
856
858
|
const headers = new Headers(request.headers);
|
|
857
859
|
const existing = new Set(
|
|
858
860
|
headers
|
|
@@ -866,6 +868,10 @@ function appendBetas(request: APIRequest, betas: readonly AnthropicBeta[]): APIR
|
|
|
866
868
|
existing.add(beta);
|
|
867
869
|
}
|
|
868
870
|
}
|
|
871
|
+
headers.set(
|
|
872
|
+
STAINLESS_HELPER_HEADER,
|
|
873
|
+
appendHeaderValue(headers.get(STAINLESS_HELPER_HEADER), 'fallback-refusal-middleware'),
|
|
874
|
+
);
|
|
869
875
|
return { ...request, headers };
|
|
870
876
|
}
|
|
871
877
|
|
|
@@ -8,7 +8,11 @@ import { RequestOptions } from '../../internal/request-options';
|
|
|
8
8
|
import { buildHeaders } from '../../internal/headers';
|
|
9
9
|
import { promiseWithResolvers } from '../../internal/utils/promise';
|
|
10
10
|
import { CompactionControl, DEFAULT_SUMMARY_PROMPT, DEFAULT_TOKEN_THRESHOLD } from './CompactionControl';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
collectStainlessHelpers,
|
|
13
|
+
helperHeader,
|
|
14
|
+
STAINLESS_HELPER_HEADER,
|
|
15
|
+
} from '../../internal/stainless-helper-header';
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* A ToolRunner handles the automatic conversation loop between the assistant and tools.
|
|
@@ -52,12 +56,17 @@ export class BetaToolRunner<Stream extends boolean> {
|
|
|
52
56
|
},
|
|
53
57
|
};
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
// structuredClone drops symbol-keyed properties, so collect helper marks
|
|
60
|
+
// from the original params here — the create()-side collector won't see
|
|
61
|
+
// them on the cloned messages.
|
|
62
|
+
const collected = collectStainlessHelpers(params.tools, params.messages);
|
|
58
63
|
this.#options = {
|
|
59
64
|
...options,
|
|
60
|
-
headers: buildHeaders([
|
|
65
|
+
headers: buildHeaders([
|
|
66
|
+
helperHeader('BetaToolRunner'),
|
|
67
|
+
collected.length ? { [STAINLESS_HELPER_HEADER]: collected.join(', ') } : undefined,
|
|
68
|
+
options?.headers,
|
|
69
|
+
]),
|
|
61
70
|
};
|
|
62
71
|
this.#completion = promiseWithResolvers();
|
|
63
72
|
|
|
@@ -137,7 +146,7 @@ export class BetaToolRunner<Stream extends boolean> {
|
|
|
137
146
|
},
|
|
138
147
|
{
|
|
139
148
|
signal: this.#options.signal,
|
|
140
|
-
headers: buildHeaders([this.#options.headers,
|
|
149
|
+
headers: buildHeaders([this.#options.headers, helperHeader('compaction')]),
|
|
141
150
|
},
|
|
142
151
|
);
|
|
143
152
|
|
|
@@ -15,6 +15,7 @@ import { isFatal4xx } from '../../internal/utils/backoff';
|
|
|
15
15
|
import { linkAbort } from '../../internal/utils/abort';
|
|
16
16
|
import { AsyncQueue } from '../../internal/utils/async-queue';
|
|
17
17
|
import { buildHeaders } from '../../internal/headers';
|
|
18
|
+
import { helperHeader } from '../../internal/stainless-helper-header';
|
|
18
19
|
import type { RequestOptions } from '../../internal/request-options';
|
|
19
20
|
import { runRunnableTool, toolName, type BetaRunnableTool } from './BetaRunnableTool';
|
|
20
21
|
import type { BetaToolRunnerRequestOptions } from './BetaToolRunner';
|
|
@@ -22,9 +23,6 @@ import type { BetaToolRunnerRequestOptions } from './BetaToolRunner';
|
|
|
22
23
|
/** Beta header for the managed-agents API. */
|
|
23
24
|
export const MANAGED_AGENTS_BETA = 'managed-agents-2026-04-01';
|
|
24
25
|
|
|
25
|
-
/** `x-stainless-helper` value identifying this helper in SDK telemetry. */
|
|
26
|
-
const HELPER_NAME = 'SessionToolRunner';
|
|
27
|
-
|
|
28
26
|
const STREAM_BACKOFF_START_MS = 500;
|
|
29
27
|
const STREAM_BACKOFF_CAP_MS = 10_000;
|
|
30
28
|
const TOOL_TIMEOUT_MS = 120_000;
|
|
@@ -287,7 +285,7 @@ export class SessionToolRunner implements AsyncIterable<DispatchedToolCall> {
|
|
|
287
285
|
#requestOptions(): RequestOptions {
|
|
288
286
|
return {
|
|
289
287
|
...this.#requestOpts,
|
|
290
|
-
headers: buildHeaders([
|
|
288
|
+
headers: buildHeaders([helperHeader('session-tool-runner'), this.#requestOpts?.headers]),
|
|
291
289
|
signal: this.#controller.signal,
|
|
292
290
|
};
|
|
293
291
|
}
|
|
@@ -840,7 +840,9 @@ export interface AgentCreateParams {
|
|
|
840
840
|
|
|
841
841
|
/**
|
|
842
842
|
* Body param: MCP servers this agent connects to. Maximum 20. Names must be unique
|
|
843
|
-
* within the array.
|
|
843
|
+
* within the array. Every server must be referenced by an `mcp_toolset` in
|
|
844
|
+
* `tools`; unreferenced servers are rejected. See the
|
|
845
|
+
* [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
|
|
844
846
|
*/
|
|
845
847
|
mcp_servers?: Array<BetaManagedAgentsURLMCPServerParams>;
|
|
846
848
|
|
|
@@ -911,7 +913,10 @@ export interface AgentUpdateParams {
|
|
|
911
913
|
|
|
912
914
|
/**
|
|
913
915
|
* Body param: MCP servers. Full replacement. Omit to preserve; send empty array or
|
|
914
|
-
* null to clear. Names must be unique. Maximum 20.
|
|
916
|
+
* `null` to clear. Names must be unique. Maximum 20. Every server must be
|
|
917
|
+
* referenced by an `mcp_toolset` in the agent's resulting `tools`; unreferenced
|
|
918
|
+
* servers are rejected. See the
|
|
919
|
+
* [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
|
|
915
920
|
*/
|
|
916
921
|
mcp_servers?: Array<BetaManagedAgentsURLMCPServerParams> | null;
|
|
917
922
|
|
|
@@ -7,7 +7,7 @@ import { Page, type PageParams, PagePromise } from '../../core/pagination';
|
|
|
7
7
|
import { type Uploadable } from '../../core/uploads';
|
|
8
8
|
import { buildHeaders } from '../../internal/headers';
|
|
9
9
|
import { RequestOptions } from '../../internal/request-options';
|
|
10
|
-
import { stainlessHelperHeaderFromFile } from '../../
|
|
10
|
+
import { stainlessHelperHeaderFromFile } from '../../internal/stainless-helper-header';
|
|
11
11
|
import { multipartFormRequestOptions } from '../../internal/uploads';
|
|
12
12
|
import { path } from '../../internal/utils/path';
|
|
13
13
|
|
|
@@ -43,12 +43,15 @@ export class Batches extends APIResource {
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
create(params: BatchCreateParams, options?: RequestOptions): APIPromise<BetaMessageBatch> {
|
|
46
|
-
const { betas, ...body } = params;
|
|
46
|
+
const { betas, user_profile_id, ...body } = params;
|
|
47
47
|
return this._client.post('/v1/messages/batches?beta=true', {
|
|
48
48
|
body,
|
|
49
49
|
...options,
|
|
50
50
|
headers: buildHeaders([
|
|
51
|
-
{
|
|
51
|
+
{
|
|
52
|
+
'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
|
|
53
|
+
...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
|
|
54
|
+
},
|
|
52
55
|
options?.headers,
|
|
53
56
|
]),
|
|
54
57
|
});
|
|
@@ -424,6 +427,15 @@ export interface BatchCreateParams {
|
|
|
424
427
|
* Header param: Optional header to specify the beta version(s) you want to use.
|
|
425
428
|
*/
|
|
426
429
|
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Header param: The user profile ID to attribute the requests in this batch to.
|
|
433
|
+
* Use when acting on behalf of a party other than your organization. Requires the
|
|
434
|
+
* `user-profiles` beta header. Applies to every request in the batch; an
|
|
435
|
+
* individual request whose `user_profile_id` body field conflicts with this header
|
|
436
|
+
* is errored.
|
|
437
|
+
*/
|
|
438
|
+
user_profile_id?: string;
|
|
427
439
|
}
|
|
428
440
|
|
|
429
441
|
export namespace BatchCreateParams {
|
|
@@ -791,12 +803,6 @@ export namespace BatchCreateParams {
|
|
|
791
803
|
* other values will be rejected with a 400 error.
|
|
792
804
|
*/
|
|
793
805
|
top_p?: number;
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* The user profile ID to attribute this request to. Use when acting on behalf of a
|
|
797
|
-
* party other than your organization.
|
|
798
|
-
*/
|
|
799
|
-
user_profile_id?: string | null;
|
|
800
806
|
}
|
|
801
807
|
}
|
|
802
808
|
}
|
|
@@ -9,7 +9,7 @@ import { Stream } from '../../../core/streaming';
|
|
|
9
9
|
import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants';
|
|
10
10
|
import { buildHeaders } from '../../../internal/headers';
|
|
11
11
|
import { RequestOptions } from '../../../internal/request-options';
|
|
12
|
-
import { stainlessHelperHeader } from '../../../
|
|
12
|
+
import { stainlessHelperHeader } from '../../../internal/stainless-helper-header';
|
|
13
13
|
import {
|
|
14
14
|
parseBetaMessage,
|
|
15
15
|
type ExtractParsedContentFromBetaParams,
|
|
@@ -111,7 +111,7 @@ export class Messages extends APIResource {
|
|
|
111
111
|
// Transform deprecated output_format to output_config.format
|
|
112
112
|
const modifiedParams = transformOutputFormat(params);
|
|
113
113
|
|
|
114
|
-
const { betas, ...body } = modifiedParams;
|
|
114
|
+
const { betas, user_profile_id, ...body } = modifiedParams;
|
|
115
115
|
|
|
116
116
|
if (body.model in DEPRECATED_MODELS) {
|
|
117
117
|
console.warn(
|
|
@@ -145,7 +145,10 @@ export class Messages extends APIResource {
|
|
|
145
145
|
timeout: timeout ?? 600000,
|
|
146
146
|
...options,
|
|
147
147
|
headers: buildHeaders([
|
|
148
|
-
{
|
|
148
|
+
{
|
|
149
|
+
...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined),
|
|
150
|
+
...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined),
|
|
151
|
+
},
|
|
149
152
|
helperHeader,
|
|
150
153
|
options?.headers,
|
|
151
154
|
]),
|
|
@@ -588,7 +591,9 @@ export interface BetaCacheControlEphemeral {
|
|
|
588
591
|
* - `5m`: 5 minutes
|
|
589
592
|
* - `1h`: 1 hour
|
|
590
593
|
*
|
|
591
|
-
* Defaults to `5m`.
|
|
594
|
+
* Defaults to `5m`. See
|
|
595
|
+
* [prompt caching pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching)
|
|
596
|
+
* for details.
|
|
592
597
|
*/
|
|
593
598
|
ttl?: '5m' | '1h';
|
|
594
599
|
}
|
|
@@ -1732,7 +1737,7 @@ export interface BetaFallbackRefusalTrigger {
|
|
|
1732
1737
|
/**
|
|
1733
1738
|
* The policy category that triggered a refusal.
|
|
1734
1739
|
*/
|
|
1735
|
-
category: 'cyber' | 'bio' | 'frontier_llm' | 'reasoning_extraction' | null;
|
|
1740
|
+
category: 'cyber' | 'bio' | 'frontier_llm' | 'reasoning_extraction' | 'military_weapons' | null;
|
|
1736
1741
|
|
|
1737
1742
|
type: 'refusal';
|
|
1738
1743
|
}
|
|
@@ -2504,7 +2509,7 @@ export interface BetaRefusalStopDetails {
|
|
|
2504
2509
|
/**
|
|
2505
2510
|
* The policy category that triggered a refusal.
|
|
2506
2511
|
*/
|
|
2507
|
-
category: 'cyber' | 'bio' | 'frontier_llm' | 'reasoning_extraction' | null;
|
|
2512
|
+
category: 'cyber' | 'bio' | 'frontier_llm' | 'reasoning_extraction' | 'military_weapons' | null;
|
|
2508
2513
|
|
|
2509
2514
|
/**
|
|
2510
2515
|
* Human-readable explanation of the refusal.
|
|
@@ -4710,15 +4715,16 @@ export interface MessageCreateParamsBase {
|
|
|
4710
4715
|
top_p?: number;
|
|
4711
4716
|
|
|
4712
4717
|
/**
|
|
4713
|
-
*
|
|
4714
|
-
* behalf of a party other than your organization.
|
|
4718
|
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
|
4715
4719
|
*/
|
|
4716
|
-
|
|
4720
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
4717
4721
|
|
|
4718
4722
|
/**
|
|
4719
|
-
* Header param:
|
|
4723
|
+
* Header param: The user profile ID to attribute this request to. Use when acting
|
|
4724
|
+
* on behalf of a party other than your organization. Requires the `user-profiles`
|
|
4725
|
+
* beta header.
|
|
4720
4726
|
*/
|
|
4721
|
-
|
|
4727
|
+
user_profile_id?: string;
|
|
4722
4728
|
}
|
|
4723
4729
|
|
|
4724
4730
|
export namespace MessageCreateParams {
|
|
@@ -40,8 +40,16 @@ export class Batches extends APIResource {
|
|
|
40
40
|
* });
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
create(
|
|
44
|
-
|
|
43
|
+
create(params: BatchCreateParams, options?: RequestOptions): APIPromise<MessageBatch> {
|
|
44
|
+
const { user_profile_id, ...body } = params;
|
|
45
|
+
return this._client.post('/v1/messages/batches', {
|
|
46
|
+
body,
|
|
47
|
+
...options,
|
|
48
|
+
headers: buildHeaders([
|
|
49
|
+
{ ...(user_profile_id != null ? { 'anthropic-user-profile-id': user_profile_id } : undefined) },
|
|
50
|
+
options?.headers,
|
|
51
|
+
]),
|
|
52
|
+
});
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
/**
|
|
@@ -350,10 +358,19 @@ export interface MessageBatchSucceededResult {
|
|
|
350
358
|
|
|
351
359
|
export interface BatchCreateParams {
|
|
352
360
|
/**
|
|
353
|
-
* List of requests for prompt completion. Each is an individual
|
|
354
|
-
* a Message.
|
|
361
|
+
* Body param: List of requests for prompt completion. Each is an individual
|
|
362
|
+
* request to create a Message.
|
|
355
363
|
*/
|
|
356
364
|
requests: Array<BatchCreateParams.Request>;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Header param: The user profile ID to attribute the requests in this batch to.
|
|
368
|
+
* Use when acting on behalf of a party other than your organization. Requires the
|
|
369
|
+
* `user-profiles` beta header. Applies to every request in the batch; an
|
|
370
|
+
* individual request whose `user_profile_id` body field conflicts with this header
|
|
371
|
+
* is errored.
|
|
372
|
+
*/
|
|
373
|
+
user_profile_id?: string;
|
|
357
374
|
}
|
|
358
375
|
|
|
359
376
|
export namespace BatchCreateParams {
|