@anthropic-ai/sdk 0.93.0 → 0.95.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.
Files changed (247) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/bin/migration-config.json +185 -0
  3. package/client.d.mts +7 -4
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +7 -4
  6. package/client.d.ts.map +1 -1
  7. package/client.js +5 -4
  8. package/client.js.map +1 -1
  9. package/client.mjs +5 -4
  10. package/client.mjs.map +1 -1
  11. package/core/credentials.d.mts +20 -0
  12. package/core/credentials.d.mts.map +1 -1
  13. package/core/credentials.d.ts +20 -0
  14. package/core/credentials.d.ts.map +1 -1
  15. package/core/credentials.js +30 -11
  16. package/core/credentials.js.map +1 -1
  17. package/core/credentials.mjs +27 -9
  18. package/core/credentials.mjs.map +1 -1
  19. package/core/streaming.d.mts.map +1 -1
  20. package/core/streaming.d.ts.map +1 -1
  21. package/core/streaming.js +15 -1
  22. package/core/streaming.js.map +1 -1
  23. package/core/streaming.mjs +15 -1
  24. package/core/streaming.mjs.map +1 -1
  25. package/internal/qs/formats.d.mts +7 -0
  26. package/internal/qs/formats.d.mts.map +1 -0
  27. package/internal/qs/formats.d.ts +7 -0
  28. package/internal/qs/formats.d.ts.map +1 -0
  29. package/internal/qs/formats.js +13 -0
  30. package/internal/qs/formats.js.map +1 -0
  31. package/internal/qs/formats.mjs +9 -0
  32. package/internal/qs/formats.mjs.map +1 -0
  33. package/internal/qs/index.d.mts +10 -0
  34. package/internal/qs/index.d.mts.map +1 -0
  35. package/internal/qs/index.d.ts +10 -0
  36. package/internal/qs/index.d.ts.map +1 -0
  37. package/internal/qs/index.js +14 -0
  38. package/internal/qs/index.js.map +1 -0
  39. package/internal/qs/index.mjs +10 -0
  40. package/internal/qs/index.mjs.map +1 -0
  41. package/internal/qs/stringify.d.mts +3 -0
  42. package/internal/qs/stringify.d.mts.map +1 -0
  43. package/internal/qs/stringify.d.ts +3 -0
  44. package/internal/qs/stringify.d.ts.map +1 -0
  45. package/internal/qs/stringify.js +277 -0
  46. package/internal/qs/stringify.js.map +1 -0
  47. package/internal/qs/stringify.mjs +274 -0
  48. package/internal/qs/stringify.mjs.map +1 -0
  49. package/internal/qs/types.d.mts +57 -0
  50. package/internal/qs/types.d.mts.map +1 -0
  51. package/internal/qs/types.d.ts +57 -0
  52. package/internal/qs/types.d.ts.map +1 -0
  53. package/internal/qs/types.js +3 -0
  54. package/internal/qs/types.js.map +1 -0
  55. package/internal/qs/types.mjs +2 -0
  56. package/internal/qs/types.mjs.map +1 -0
  57. package/internal/qs/utils.d.mts +15 -0
  58. package/internal/qs/utils.d.mts.map +1 -0
  59. package/internal/qs/utils.d.ts +15 -0
  60. package/internal/qs/utils.d.ts.map +1 -0
  61. package/internal/qs/utils.js +230 -0
  62. package/internal/qs/utils.js.map +1 -0
  63. package/internal/qs/utils.mjs +217 -0
  64. package/internal/qs/utils.mjs.map +1 -0
  65. package/internal/utils/query.d.mts +0 -3
  66. package/internal/utils/query.d.mts.map +1 -1
  67. package/internal/utils/query.d.ts +0 -3
  68. package/internal/utils/query.d.ts.map +1 -1
  69. package/internal/utils/query.js +3 -16
  70. package/internal/utils/query.js.map +1 -1
  71. package/internal/utils/query.mjs +2 -16
  72. package/internal/utils/query.mjs.map +1 -1
  73. package/lib/credentials/credential-chain.d.mts.map +1 -1
  74. package/lib/credentials/credential-chain.d.ts.map +1 -1
  75. package/lib/credentials/credential-chain.js +18 -10
  76. package/lib/credentials/credential-chain.js.map +1 -1
  77. package/lib/credentials/credential-chain.mjs +19 -11
  78. package/lib/credentials/credential-chain.mjs.map +1 -1
  79. package/lib/credentials/oidc-federation.d.mts +12 -0
  80. package/lib/credentials/oidc-federation.d.mts.map +1 -1
  81. package/lib/credentials/oidc-federation.d.ts +12 -0
  82. package/lib/credentials/oidc-federation.d.ts.map +1 -1
  83. package/lib/credentials/oidc-federation.js +14 -1
  84. package/lib/credentials/oidc-federation.js.map +1 -1
  85. package/lib/credentials/oidc-federation.mjs +14 -1
  86. package/lib/credentials/oidc-federation.mjs.map +1 -1
  87. package/package.json +2 -1
  88. package/resources/beta/agents/agents.d.mts +60 -1
  89. package/resources/beta/agents/agents.d.mts.map +1 -1
  90. package/resources/beta/agents/agents.d.ts +60 -1
  91. package/resources/beta/agents/agents.d.ts.map +1 -1
  92. package/resources/beta/agents/agents.js.map +1 -1
  93. package/resources/beta/agents/agents.mjs.map +1 -1
  94. package/resources/beta/agents/index.d.mts +1 -1
  95. package/resources/beta/agents/index.d.mts.map +1 -1
  96. package/resources/beta/agents/index.d.ts +1 -1
  97. package/resources/beta/agents/index.d.ts.map +1 -1
  98. package/resources/beta/agents/index.js.map +1 -1
  99. package/resources/beta/agents/index.mjs.map +1 -1
  100. package/resources/beta/beta.d.mts +9 -5
  101. package/resources/beta/beta.d.mts.map +1 -1
  102. package/resources/beta/beta.d.ts +9 -5
  103. package/resources/beta/beta.d.ts.map +1 -1
  104. package/resources/beta/beta.js +4 -0
  105. package/resources/beta/beta.js.map +1 -1
  106. package/resources/beta/beta.mjs +4 -0
  107. package/resources/beta/beta.mjs.map +1 -1
  108. package/resources/beta/index.d.mts +3 -2
  109. package/resources/beta/index.d.mts.map +1 -1
  110. package/resources/beta/index.d.ts +3 -2
  111. package/resources/beta/index.d.ts.map +1 -1
  112. package/resources/beta/index.js +3 -1
  113. package/resources/beta/index.js.map +1 -1
  114. package/resources/beta/index.mjs +1 -0
  115. package/resources/beta/index.mjs.map +1 -1
  116. package/resources/beta/messages/messages.d.mts +88 -0
  117. package/resources/beta/messages/messages.d.mts.map +1 -1
  118. package/resources/beta/messages/messages.d.ts +88 -0
  119. package/resources/beta/messages/messages.d.ts.map +1 -1
  120. package/resources/beta/messages/messages.js.map +1 -1
  121. package/resources/beta/messages/messages.mjs.map +1 -1
  122. package/resources/beta/sessions/events.d.mts +436 -5
  123. package/resources/beta/sessions/events.d.mts.map +1 -1
  124. package/resources/beta/sessions/events.d.ts +436 -5
  125. package/resources/beta/sessions/events.d.ts.map +1 -1
  126. package/resources/beta/sessions/index.d.mts +3 -2
  127. package/resources/beta/sessions/index.d.mts.map +1 -1
  128. package/resources/beta/sessions/index.d.ts +3 -2
  129. package/resources/beta/sessions/index.d.ts.map +1 -1
  130. package/resources/beta/sessions/index.js +3 -1
  131. package/resources/beta/sessions/index.js.map +1 -1
  132. package/resources/beta/sessions/index.mjs +1 -0
  133. package/resources/beta/sessions/index.mjs.map +1 -1
  134. package/resources/beta/sessions/sessions.d.mts +99 -3
  135. package/resources/beta/sessions/sessions.d.mts.map +1 -1
  136. package/resources/beta/sessions/sessions.d.ts +99 -3
  137. package/resources/beta/sessions/sessions.d.ts.map +1 -1
  138. package/resources/beta/sessions/sessions.js +4 -0
  139. package/resources/beta/sessions/sessions.js.map +1 -1
  140. package/resources/beta/sessions/sessions.mjs +4 -0
  141. package/resources/beta/sessions/sessions.mjs.map +1 -1
  142. package/resources/beta/sessions/threads/events.d.mts +64 -0
  143. package/resources/beta/sessions/threads/events.d.mts.map +1 -0
  144. package/resources/beta/sessions/threads/events.d.ts +64 -0
  145. package/resources/beta/sessions/threads/events.d.ts.map +1 -0
  146. package/resources/beta/sessions/threads/events.js +60 -0
  147. package/resources/beta/sessions/threads/events.js.map +1 -0
  148. package/resources/beta/sessions/threads/events.mjs +56 -0
  149. package/resources/beta/sessions/threads/events.mjs.map +1 -0
  150. package/resources/beta/sessions/threads/index.d.mts +3 -0
  151. package/resources/beta/sessions/threads/index.d.mts.map +1 -0
  152. package/resources/beta/sessions/threads/index.d.ts +3 -0
  153. package/resources/beta/sessions/threads/index.d.ts.map +1 -0
  154. package/resources/beta/sessions/threads/index.js +9 -0
  155. package/resources/beta/sessions/threads/index.js.map +1 -0
  156. package/resources/beta/sessions/threads/index.mjs +4 -0
  157. package/resources/beta/sessions/threads/index.mjs.map +1 -0
  158. package/resources/beta/sessions/threads/threads.d.mts +203 -0
  159. package/resources/beta/sessions/threads/threads.d.mts.map +1 -0
  160. package/resources/beta/sessions/threads/threads.d.ts +203 -0
  161. package/resources/beta/sessions/threads/threads.d.ts.map +1 -0
  162. package/resources/beta/sessions/threads/threads.js +88 -0
  163. package/resources/beta/sessions/threads/threads.js.map +1 -0
  164. package/resources/beta/sessions/threads/threads.mjs +83 -0
  165. package/resources/beta/sessions/threads/threads.mjs.map +1 -0
  166. package/resources/beta/sessions/threads.d.mts +2 -0
  167. package/resources/beta/sessions/threads.d.mts.map +1 -0
  168. package/resources/beta/sessions/threads.d.ts +2 -0
  169. package/resources/beta/sessions/threads.d.ts.map +1 -0
  170. package/resources/beta/sessions/threads.js +6 -0
  171. package/resources/beta/sessions/threads.js.map +1 -0
  172. package/resources/beta/sessions/threads.mjs +3 -0
  173. package/resources/beta/sessions/threads.mjs.map +1 -0
  174. package/resources/beta/user-profiles.d.mts +36 -0
  175. package/resources/beta/user-profiles.d.mts.map +1 -1
  176. package/resources/beta/user-profiles.d.ts +36 -0
  177. package/resources/beta/user-profiles.d.ts.map +1 -1
  178. package/resources/beta/vaults/credentials.d.mts +109 -1
  179. package/resources/beta/vaults/credentials.d.mts.map +1 -1
  180. package/resources/beta/vaults/credentials.d.ts +109 -1
  181. package/resources/beta/vaults/credentials.d.ts.map +1 -1
  182. package/resources/beta/vaults/credentials.js +22 -0
  183. package/resources/beta/vaults/credentials.js.map +1 -1
  184. package/resources/beta/vaults/credentials.mjs +22 -0
  185. package/resources/beta/vaults/credentials.mjs.map +1 -1
  186. package/resources/beta/vaults/index.d.mts +1 -1
  187. package/resources/beta/vaults/index.d.mts.map +1 -1
  188. package/resources/beta/vaults/index.d.ts +1 -1
  189. package/resources/beta/vaults/index.d.ts.map +1 -1
  190. package/resources/beta/vaults/index.js.map +1 -1
  191. package/resources/beta/vaults/index.mjs.map +1 -1
  192. package/resources/beta/vaults/vaults.d.mts +2 -2
  193. package/resources/beta/vaults/vaults.d.mts.map +1 -1
  194. package/resources/beta/vaults/vaults.d.ts +2 -2
  195. package/resources/beta/vaults/vaults.d.ts.map +1 -1
  196. package/resources/beta/vaults/vaults.js.map +1 -1
  197. package/resources/beta/vaults/vaults.mjs.map +1 -1
  198. package/resources/beta/webhooks.d.mts +256 -0
  199. package/resources/beta/webhooks.d.mts.map +1 -0
  200. package/resources/beta/webhooks.d.ts +256 -0
  201. package/resources/beta/webhooks.d.ts.map +1 -0
  202. package/resources/beta/webhooks.js +20 -0
  203. package/resources/beta/webhooks.js.map +1 -0
  204. package/resources/beta/webhooks.mjs +16 -0
  205. package/resources/beta/webhooks.mjs.map +1 -0
  206. package/resources/messages/messages.d.mts +88 -0
  207. package/resources/messages/messages.d.mts.map +1 -1
  208. package/resources/messages/messages.d.ts +88 -0
  209. package/resources/messages/messages.d.ts.map +1 -1
  210. package/resources/messages/messages.js.map +1 -1
  211. package/resources/messages/messages.mjs.map +1 -1
  212. package/src/client.ts +17 -4
  213. package/src/core/credentials.ts +39 -9
  214. package/src/core/streaming.ts +15 -1
  215. package/src/internal/qs/LICENSE.md +13 -0
  216. package/src/internal/qs/README.md +3 -0
  217. package/src/internal/qs/formats.ts +10 -0
  218. package/src/internal/qs/index.ts +13 -0
  219. package/src/internal/qs/stringify.ts +385 -0
  220. package/src/internal/qs/types.ts +71 -0
  221. package/src/internal/qs/utils.ts +265 -0
  222. package/src/internal/utils/query.ts +2 -18
  223. package/src/lib/credentials/credential-chain.ts +19 -11
  224. package/src/lib/credentials/oidc-federation.ts +29 -1
  225. package/src/resources/beta/agents/agents.ts +74 -0
  226. package/src/resources/beta/agents/index.ts +4 -0
  227. package/src/resources/beta/beta.ts +80 -1
  228. package/src/resources/beta/index.ts +37 -0
  229. package/src/resources/beta/messages/messages.ts +88 -0
  230. package/src/resources/beta/sessions/events.ts +565 -3
  231. package/src/resources/beta/sessions/index.ts +34 -0
  232. package/src/resources/beta/sessions/sessions.ts +179 -0
  233. package/src/resources/beta/sessions/threads/events.ts +107 -0
  234. package/src/resources/beta/sessions/threads/index.ts +16 -0
  235. package/src/resources/beta/sessions/threads/threads.ts +344 -0
  236. package/src/resources/beta/sessions/threads.ts +3 -0
  237. package/src/resources/beta/user-profiles.ts +42 -0
  238. package/src/resources/beta/vaults/credentials.ts +150 -0
  239. package/src/resources/beta/vaults/index.ts +6 -0
  240. package/src/resources/beta/vaults/vaults.ts +12 -0
  241. package/src/resources/beta/webhooks.ts +417 -0
  242. package/src/resources/messages/messages.ts +88 -0
  243. package/src/version.ts +1 -1
  244. package/version.d.mts +1 -1
  245. package/version.d.ts +1 -1
  246. package/version.js +1 -1
  247. package/version.mjs +1 -1
@@ -0,0 +1,71 @@
1
+ export type Format = 'RFC1738' | 'RFC3986';
2
+
3
+ export type DefaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
4
+ export type DefaultDecoder = (str: string, decoder?: any, charset?: string) => string;
5
+
6
+ export type BooleanOptional = boolean | undefined;
7
+
8
+ export type StringifyBaseOptions = {
9
+ delimiter?: string;
10
+ allowDots?: boolean;
11
+ encodeDotInKeys?: boolean;
12
+ strictNullHandling?: boolean;
13
+ skipNulls?: boolean;
14
+ encode?: boolean;
15
+ encoder?: (
16
+ str: any,
17
+ defaultEncoder: DefaultEncoder,
18
+ charset: string,
19
+ type: 'key' | 'value',
20
+ format?: Format,
21
+ ) => string;
22
+ filter?: Array<PropertyKey> | ((prefix: PropertyKey, value: any) => any);
23
+ arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma';
24
+ indices?: boolean;
25
+ sort?: ((a: PropertyKey, b: PropertyKey) => number) | null;
26
+ serializeDate?: (d: Date) => string;
27
+ format?: 'RFC1738' | 'RFC3986';
28
+ formatter?: (str: PropertyKey) => string;
29
+ encodeValuesOnly?: boolean;
30
+ addQueryPrefix?: boolean;
31
+ charset?: 'utf-8' | 'iso-8859-1';
32
+ charsetSentinel?: boolean;
33
+ allowEmptyArrays?: boolean;
34
+ commaRoundTrip?: boolean;
35
+ };
36
+
37
+ export type StringifyOptions = StringifyBaseOptions;
38
+
39
+ export type ParseBaseOptions = {
40
+ comma?: boolean;
41
+ delimiter?: string | RegExp;
42
+ depth?: number | false;
43
+ decoder?: (str: string, defaultDecoder: DefaultDecoder, charset: string, type: 'key' | 'value') => any;
44
+ arrayLimit?: number;
45
+ parseArrays?: boolean;
46
+ plainObjects?: boolean;
47
+ allowPrototypes?: boolean;
48
+ allowSparse?: boolean;
49
+ parameterLimit?: number;
50
+ strictDepth?: boolean;
51
+ strictNullHandling?: boolean;
52
+ ignoreQueryPrefix?: boolean;
53
+ charset?: 'utf-8' | 'iso-8859-1';
54
+ charsetSentinel?: boolean;
55
+ interpretNumericEntities?: boolean;
56
+ allowEmptyArrays?: boolean;
57
+ duplicates?: 'combine' | 'first' | 'last';
58
+ allowDots?: boolean;
59
+ decodeDotInKeys?: boolean;
60
+ };
61
+
62
+ export type ParseOptions = ParseBaseOptions;
63
+
64
+ export type ParsedQs = {
65
+ [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
66
+ };
67
+
68
+ // Type to remove null or undefined union from each property
69
+ export type NonNullableProperties<T> = {
70
+ [K in keyof T]-?: Exclude<T[K], undefined | null>;
71
+ };
@@ -0,0 +1,265 @@
1
+ import { RFC1738 } from './formats';
2
+ import type { DefaultEncoder, Format } from './types';
3
+ import { isArray } from '../utils/values';
4
+
5
+ export let has = (obj: object, key: PropertyKey): boolean => (
6
+ (has = (Object as any).hasOwn ?? Function.prototype.call.bind(Object.prototype.hasOwnProperty)),
7
+ has(obj, key)
8
+ );
9
+
10
+ const hex_table = /* @__PURE__ */ (() => {
11
+ const array = [];
12
+ for (let i = 0; i < 256; ++i) {
13
+ array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
14
+ }
15
+
16
+ return array;
17
+ })();
18
+
19
+ function compact_queue<T extends Record<string, any>>(queue: Array<{ obj: T; prop: string }>) {
20
+ while (queue.length > 1) {
21
+ const item = queue.pop();
22
+ if (!item) continue;
23
+
24
+ const obj = item.obj[item.prop];
25
+
26
+ if (isArray(obj)) {
27
+ const compacted: unknown[] = [];
28
+
29
+ for (let j = 0; j < obj.length; ++j) {
30
+ if (typeof obj[j] !== 'undefined') {
31
+ compacted.push(obj[j]);
32
+ }
33
+ }
34
+
35
+ // @ts-ignore
36
+ item.obj[item.prop] = compacted;
37
+ }
38
+ }
39
+ }
40
+
41
+ function array_to_object(source: any[], options: { plainObjects: boolean }) {
42
+ const obj = options && options.plainObjects ? Object.create(null) : {};
43
+ for (let i = 0; i < source.length; ++i) {
44
+ if (typeof source[i] !== 'undefined') {
45
+ obj[i] = source[i];
46
+ }
47
+ }
48
+
49
+ return obj;
50
+ }
51
+
52
+ export function merge(
53
+ target: any,
54
+ source: any,
55
+ options: { plainObjects?: boolean; allowPrototypes?: boolean } = {},
56
+ ) {
57
+ if (!source) {
58
+ return target;
59
+ }
60
+
61
+ if (typeof source !== 'object') {
62
+ if (isArray(target)) {
63
+ target.push(source);
64
+ } else if (target && typeof target === 'object') {
65
+ if ((options && (options.plainObjects || options.allowPrototypes)) || !has(Object.prototype, source)) {
66
+ target[source] = true;
67
+ }
68
+ } else {
69
+ return [target, source];
70
+ }
71
+
72
+ return target;
73
+ }
74
+
75
+ if (!target || typeof target !== 'object') {
76
+ return [target].concat(source);
77
+ }
78
+
79
+ let mergeTarget = target;
80
+ if (isArray(target) && !isArray(source)) {
81
+ // @ts-ignore
82
+ mergeTarget = array_to_object(target, options);
83
+ }
84
+
85
+ if (isArray(target) && isArray(source)) {
86
+ source.forEach(function (item, i) {
87
+ if (has(target, i)) {
88
+ const targetItem = target[i];
89
+ if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
90
+ target[i] = merge(targetItem, item, options);
91
+ } else {
92
+ target.push(item);
93
+ }
94
+ } else {
95
+ target[i] = item;
96
+ }
97
+ });
98
+ return target;
99
+ }
100
+
101
+ return Object.keys(source).reduce(function (acc, key) {
102
+ const value = source[key];
103
+
104
+ if (has(acc, key)) {
105
+ acc[key] = merge(acc[key], value, options);
106
+ } else {
107
+ acc[key] = value;
108
+ }
109
+ return acc;
110
+ }, mergeTarget);
111
+ }
112
+
113
+ export function assign_single_source(target: any, source: any) {
114
+ return Object.keys(source).reduce(function (acc, key) {
115
+ acc[key] = source[key];
116
+ return acc;
117
+ }, target);
118
+ }
119
+
120
+ export function decode(str: string, _: any, charset: string) {
121
+ const strWithoutPlus = str.replace(/\+/g, ' ');
122
+ if (charset === 'iso-8859-1') {
123
+ // unescape never throws, no try...catch needed:
124
+ return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
125
+ }
126
+ // utf-8
127
+ try {
128
+ return decodeURIComponent(strWithoutPlus);
129
+ } catch (e) {
130
+ return strWithoutPlus;
131
+ }
132
+ }
133
+
134
+ const limit = 1024;
135
+
136
+ export const encode: (
137
+ str: any,
138
+ defaultEncoder: DefaultEncoder,
139
+ charset: string,
140
+ type: 'key' | 'value',
141
+ format: Format,
142
+ ) => string = (str, _defaultEncoder, charset, _kind, format: Format) => {
143
+ // This code was originally written by Brian White for the io.js core querystring library.
144
+ // It has been adapted here for stricter adherence to RFC 3986
145
+ if (str.length === 0) {
146
+ return str;
147
+ }
148
+
149
+ let string = str;
150
+ if (typeof str === 'symbol') {
151
+ string = Symbol.prototype.toString.call(str);
152
+ } else if (typeof str !== 'string') {
153
+ string = String(str);
154
+ }
155
+
156
+ if (charset === 'iso-8859-1') {
157
+ return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
158
+ return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
159
+ });
160
+ }
161
+
162
+ let out = '';
163
+ for (let j = 0; j < string.length; j += limit) {
164
+ const segment = string.length >= limit ? string.slice(j, j + limit) : string;
165
+ const arr = [];
166
+
167
+ for (let i = 0; i < segment.length; ++i) {
168
+ let c = segment.charCodeAt(i);
169
+ if (
170
+ c === 0x2d || // -
171
+ c === 0x2e || // .
172
+ c === 0x5f || // _
173
+ c === 0x7e || // ~
174
+ (c >= 0x30 && c <= 0x39) || // 0-9
175
+ (c >= 0x41 && c <= 0x5a) || // a-z
176
+ (c >= 0x61 && c <= 0x7a) || // A-Z
177
+ (format === RFC1738 && (c === 0x28 || c === 0x29)) // ( )
178
+ ) {
179
+ arr[arr.length] = segment.charAt(i);
180
+ continue;
181
+ }
182
+
183
+ if (c < 0x80) {
184
+ arr[arr.length] = hex_table[c];
185
+ continue;
186
+ }
187
+
188
+ if (c < 0x800) {
189
+ arr[arr.length] = hex_table[0xc0 | (c >> 6)]! + hex_table[0x80 | (c & 0x3f)];
190
+ continue;
191
+ }
192
+
193
+ if (c < 0xd800 || c >= 0xe000) {
194
+ arr[arr.length] =
195
+ hex_table[0xe0 | (c >> 12)]! + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)];
196
+ continue;
197
+ }
198
+
199
+ i += 1;
200
+ c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff));
201
+
202
+ arr[arr.length] =
203
+ hex_table[0xf0 | (c >> 18)]! +
204
+ hex_table[0x80 | ((c >> 12) & 0x3f)] +
205
+ hex_table[0x80 | ((c >> 6) & 0x3f)] +
206
+ hex_table[0x80 | (c & 0x3f)];
207
+ }
208
+
209
+ out += arr.join('');
210
+ }
211
+
212
+ return out;
213
+ };
214
+
215
+ export function compact(value: any) {
216
+ const queue = [{ obj: { o: value }, prop: 'o' }];
217
+ const refs = [];
218
+
219
+ for (let i = 0; i < queue.length; ++i) {
220
+ const item = queue[i];
221
+ // @ts-ignore
222
+ const obj = item.obj[item.prop];
223
+
224
+ const keys = Object.keys(obj);
225
+ for (let j = 0; j < keys.length; ++j) {
226
+ const key = keys[j]!;
227
+ const val = obj[key];
228
+ if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
229
+ queue.push({ obj: obj, prop: key });
230
+ refs.push(val);
231
+ }
232
+ }
233
+ }
234
+
235
+ compact_queue(queue);
236
+
237
+ return value;
238
+ }
239
+
240
+ export function is_regexp(obj: any) {
241
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
242
+ }
243
+
244
+ export function is_buffer(obj: any) {
245
+ if (!obj || typeof obj !== 'object') {
246
+ return false;
247
+ }
248
+
249
+ return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
250
+ }
251
+
252
+ export function combine(a: any, b: any) {
253
+ return [].concat(a, b);
254
+ }
255
+
256
+ export function maybe_map<T>(val: T[], fn: (v: T) => T) {
257
+ if (isArray(val)) {
258
+ const mapped = [];
259
+ for (let i = 0; i < val.length; i += 1) {
260
+ mapped.push(fn(val[i]!));
261
+ }
262
+ return mapped;
263
+ }
264
+ return fn(val);
265
+ }
@@ -1,23 +1,7 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { AnthropicError } from '../../core/error';
3
+ import * as qs from '../qs/stringify';
4
4
 
5
- /**
6
- * Basic re-implementation of `qs.stringify` for primitive types.
7
- */
8
5
  export function stringifyQuery(query: object | Record<string, unknown>) {
9
- return Object.entries(query)
10
- .filter(([_, value]) => typeof value !== 'undefined')
11
- .map(([key, value]) => {
12
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
13
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
14
- }
15
- if (value === null) {
16
- return `${encodeURIComponent(key)}=`;
17
- }
18
- throw new AnthropicError(
19
- `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
20
- );
21
- })
22
- .join('&');
6
+ return qs.stringify(query, { arrayFormat: 'brackets' });
23
7
  }
@@ -2,7 +2,7 @@ import type { Fetch } from '../../internal/builtin-types';
2
2
  import { readEnv } from '../../internal/utils/env';
3
3
  import {
4
4
  CREDENTIALS_FILE_VERSION,
5
- loadConfig,
5
+ loadConfigWithSource,
6
6
  getCredentialsPath,
7
7
  type AnthropicConfig,
8
8
  } from '../../core/credentials';
@@ -47,9 +47,9 @@ export function resolveCredentialsFromConfig(
47
47
  const provider = buildProvider(config, credentialsPath, effectiveBaseURL, options);
48
48
 
49
49
  const extraHeaders: Record<string, string> = {};
50
- // Workspace scoping for oidc_federation is server-side (the federation rule
51
- // encodes the workspace and the minted token is workspace-scoped), so the
52
- // header is only meaningful for user_oauth.
50
+ // For federation profiles workspace_id is sent in the jwt-bearer exchange
51
+ // body, not as a request header (the minted token is already
52
+ // workspace-scoped, so the header would be ignored).
53
53
  if (config.workspace_id && config.authentication.type === 'user_oauth') {
54
54
  extraHeaders['anthropic-workspace-id'] = config.workspace_id;
55
55
  }
@@ -79,17 +79,24 @@ export async function defaultCredentials(
79
79
  options: ResolverOptions,
80
80
  profile?: string,
81
81
  ): Promise<CredentialResult | null> {
82
- const config = await loadConfig(profile);
83
- if (!config) {
82
+ const loaded = await loadConfigWithSource(profile);
83
+ if (!loaded) {
84
84
  return null;
85
85
  }
86
+ const { config, fromFile } = loaded;
86
87
 
87
- // For env/file-loaded configs, default credentials_path to the
88
- // per-profile location so user_oauth and federation caching work.
89
- // Shallow-clone first so callers that retain a reference to the loaded
90
- // config don't observe the patched-in default.
88
+ // For file-loaded configs, default credentials_path to the per-profile
89
+ // location so user_oauth and federation caching work. Shallow-clone first
90
+ // so callers that retain a reference to the loaded config don't observe the
91
+ // patched-in default.
92
+ //
93
+ // Env-only credentials (no profile file on disk) skip the disk cache —
94
+ // matching the other SDKs. A disk cache keyed by profile path would
95
+ // re-serve a stale token after a change to ANTHROPIC_WORKSPACE_ID (or
96
+ // ANTHROPIC_ORGANIZATION_ID / ANTHROPIC_FEDERATION_RULE_ID) until the
97
+ // cached token expired, so the env-only chain stays in-memory only.
91
98
  const withPath: AnthropicConfig =
92
- config.authentication.credentials_path ?
99
+ config.authentication.credentials_path || !fromFile ?
93
100
  config
94
101
  : {
95
102
  ...config,
@@ -134,6 +141,7 @@ function buildProvider(
134
141
  federationRuleId: auth.federation_rule_id,
135
142
  organizationId: config.organization_id,
136
143
  serviceAccountId: auth.service_account_id,
144
+ workspaceId: config.workspace_id,
137
145
  baseURL,
138
146
  fetch: options.fetch,
139
147
  userAgent: options.userAgent,
@@ -18,6 +18,18 @@ export type OIDCFederationConfig = {
18
18
  federationRuleId: string;
19
19
  organizationId: string;
20
20
  serviceAccountId?: string | undefined;
21
+ /**
22
+ * Optional `wrkspc_*` tagged ID, or the literal `"default"` to scope the
23
+ * token to the organization's default workspace. When omitted the server
24
+ * picks the rule's sole enabled workspace, else the org default if the rule
25
+ * covers it. Required when the rule enables more than one non-default
26
+ * workspace, or to target a specific workspace other than the one the
27
+ * server would pick. The minted token is workspace-scoped: per-request
28
+ * workspace selection (the `anthropic-workspace-id` header) is not supported
29
+ * for federation tokens — switching workspaces requires a new token exchange
30
+ * with a different `workspaceId`.
31
+ */
32
+ workspaceId?: string | undefined;
21
33
  baseURL: string;
22
34
  fetch: Fetch;
23
35
  /**
@@ -61,6 +73,9 @@ export function oidcFederationProvider(config: OIDCFederationConfig): AccessToke
61
73
  if (config.serviceAccountId) {
62
74
  body['service_account_id'] = config.serviceAccountId;
63
75
  }
76
+ if (config.workspaceId) {
77
+ body['workspace_id'] = config.workspaceId;
78
+ }
64
79
 
65
80
  const url = `${config.baseURL}${TOKEN_ENDPOINT}`;
66
81
  let resp: Response;
@@ -83,10 +98,23 @@ export function oidcFederationProvider(config: OIDCFederationConfig): AccessToke
83
98
  if (!resp.ok) {
84
99
  const text = await resp.text().catch(() => '');
85
100
  const redacted = redactSensitive(text);
101
+ // A 401 is hard to debug from the status code alone, so surface
102
+ // guidance: check the federation rule, optionally set a workspace ID
103
+ // (the most common fix when no workspaceId is configured), and point at
104
+ // the Workload identity page in Claude Console for the server-side
105
+ // authentication event log. Other statuses (5xx, 400, ...) get no hint.
106
+ let hint = '';
107
+ if (resp.status === 401) {
108
+ const hintMiddle =
109
+ config.workspaceId ? '' : (
110
+ "If your federation rule is scoped to multiple workspaces, set the ANTHROPIC_WORKSPACE_ID environment variable, the 'workspace_id' config key, or the `workspaceId` option. "
111
+ );
112
+ hint = ` Ensure your federation rule matches your identity token. ${hintMiddle}View your authentication events in the Workload identity page of Claude Console for more details.`;
113
+ }
86
114
  throw new WorkloadIdentityError(
87
115
  `Token exchange failed with status ${resp.status}${
88
116
  requestId ? ` (request-id ${requestId})` : ''
89
- }: ${redacted}`,
117
+ }: ${redacted}${hint}`,
90
118
  resp.status,
91
119
  redacted,
92
120
  requestId,
@@ -4,6 +4,7 @@ import { APIResource } from '../../../core/resource';
4
4
  import * as BetaAPI from '../beta';
5
5
  import * as VersionsAPI from './versions';
6
6
  import { VersionListParams, Versions } from './versions';
7
+ import * as SessionsAPI from '../sessions/sessions';
7
8
  import { APIPromise } from '../../../core/api-promise';
8
9
  import { PageCursor, type PageCursorParams, PagePromise } from '../../../core/pagination';
9
10
  import { buildHeaders } from '../../../internal/headers';
@@ -174,6 +175,11 @@ export interface BetaManagedAgentsAgent {
174
175
  */
175
176
  model: BetaManagedAgentsModelConfig;
176
177
 
178
+ /**
179
+ * Resolved coordinator topology with a concrete agent roster.
180
+ */
181
+ multiagent: SessionsAPI.BetaManagedAgentsMultiagent | null;
182
+
177
183
  name: string;
178
184
 
179
185
  skills: Array<BetaManagedAgentsAnthropicSkill | BetaManagedAgentsCustomSkill>;
@@ -198,6 +204,17 @@ export interface BetaManagedAgentsAgent {
198
204
  version: number;
199
205
  }
200
206
 
207
+ /**
208
+ * A resolved agent reference with a concrete version.
209
+ */
210
+ export interface BetaManagedAgentsAgentReference {
211
+ id: string;
212
+
213
+ type: 'agent';
214
+
215
+ version: number;
216
+ }
217
+
201
218
  /**
202
219
  * Configuration for a specific agent tool.
203
220
  */
@@ -589,6 +606,45 @@ export interface BetaManagedAgentsModelConfigParams {
589
606
  speed?: 'standard' | 'fast' | null;
590
607
  }
591
608
 
609
+ /**
610
+ * Resolved coordinator topology with a concrete agent roster.
611
+ */
612
+ export interface BetaManagedAgentsMultiagentCoordinator {
613
+ /**
614
+ * Agents the coordinator may spawn as session threads, each resolved to a specific
615
+ * version.
616
+ */
617
+ agents: Array<BetaManagedAgentsAgentReference>;
618
+
619
+ type: 'coordinator';
620
+ }
621
+
622
+ /**
623
+ * A coordinator topology: the session's primary thread orchestrates work by
624
+ * spawning session threads, each running an agent drawn from the `agents` roster.
625
+ */
626
+ export interface BetaManagedAgentsMultiagentCoordinatorParams {
627
+ /**
628
+ * Agents the coordinator may spawn as session threads. 1–20 entries. Each entry is
629
+ * an agent ID string, a versioned `{"type":"agent","id","version"}` reference, or
630
+ * `{"type":"self"}` to allow recursive self-invocation. Entries must reference
631
+ * distinct agents (after resolving `self` and string forms); at most one `self`.
632
+ * Referenced agents must exist, must not be archived, and must not themselves have
633
+ * `multiagent` set (depth limit 1).
634
+ */
635
+ agents: Array<SessionsAPI.BetaManagedAgentsMultiagentRosterEntryParams>;
636
+
637
+ type: 'coordinator';
638
+ }
639
+
640
+ /**
641
+ * Sentinel roster entry meaning "the agent that owns this configuration". Resolved
642
+ * server-side to a concrete agent reference.
643
+ */
644
+ export interface BetaManagedAgentsMultiagentSelfParams {
645
+ type: 'self';
646
+ }
647
+
592
648
  /**
593
649
  * Skill to load in the session container.
594
650
  */
@@ -645,6 +701,13 @@ export interface AgentCreateParams {
645
701
  */
646
702
  metadata?: { [key: string]: string };
647
703
 
704
+ /**
705
+ * Body param: A coordinator topology: the session's primary thread orchestrates
706
+ * work by spawning session threads, each running an agent drawn from the `agents`
707
+ * roster.
708
+ */
709
+ multiagent?: SessionsAPI.BetaManagedAgentsMultiagentParams | null;
710
+
648
711
  /**
649
712
  * Body param: Skills available to the agent. Maximum 20.
650
713
  */
@@ -719,6 +782,13 @@ export interface AgentUpdateParams {
719
782
  */
720
783
  model?: BetaManagedAgentsModel | BetaManagedAgentsModelConfigParams;
721
784
 
785
+ /**
786
+ * Body param: A coordinator topology: the session's primary thread orchestrates
787
+ * work by spawning session threads, each running an agent drawn from the `agents`
788
+ * roster.
789
+ */
790
+ multiagent?: SessionsAPI.BetaManagedAgentsMultiagentParams | null;
791
+
722
792
  /**
723
793
  * Body param: Human-readable name. 1-256 characters. Omit to preserve. Cannot be
724
794
  * cleared.
@@ -788,6 +858,7 @@ Agents.Versions = Versions;
788
858
  export declare namespace Agents {
789
859
  export {
790
860
  type BetaManagedAgentsAgent as BetaManagedAgentsAgent,
861
+ type BetaManagedAgentsAgentReference as BetaManagedAgentsAgentReference,
791
862
  type BetaManagedAgentsAgentToolConfig as BetaManagedAgentsAgentToolConfig,
792
863
  type BetaManagedAgentsAgentToolConfigParams as BetaManagedAgentsAgentToolConfigParams,
793
864
  type BetaManagedAgentsAgentToolsetDefaultConfig as BetaManagedAgentsAgentToolsetDefaultConfig,
@@ -813,6 +884,9 @@ export declare namespace Agents {
813
884
  type BetaManagedAgentsModel as BetaManagedAgentsModel,
814
885
  type BetaManagedAgentsModelConfig as BetaManagedAgentsModelConfig,
815
886
  type BetaManagedAgentsModelConfigParams as BetaManagedAgentsModelConfigParams,
887
+ type BetaManagedAgentsMultiagentCoordinator as BetaManagedAgentsMultiagentCoordinator,
888
+ type BetaManagedAgentsMultiagentCoordinatorParams as BetaManagedAgentsMultiagentCoordinatorParams,
889
+ type BetaManagedAgentsMultiagentSelfParams as BetaManagedAgentsMultiagentSelfParams,
816
890
  type BetaManagedAgentsSkillParams as BetaManagedAgentsSkillParams,
817
891
  type BetaManagedAgentsURLMCPServerParams as BetaManagedAgentsURLMCPServerParams,
818
892
  type BetaManagedAgentsAgentsPageCursor as BetaManagedAgentsAgentsPageCursor,
@@ -3,6 +3,7 @@
3
3
  export {
4
4
  Agents,
5
5
  type BetaManagedAgentsAgent,
6
+ type BetaManagedAgentsAgentReference,
6
7
  type BetaManagedAgentsAgentToolConfig,
7
8
  type BetaManagedAgentsAgentToolConfigParams,
8
9
  type BetaManagedAgentsAgentToolsetDefaultConfig,
@@ -28,6 +29,9 @@ export {
28
29
  type BetaManagedAgentsModel,
29
30
  type BetaManagedAgentsModelConfig,
30
31
  type BetaManagedAgentsModelConfigParams,
32
+ type BetaManagedAgentsMultiagentCoordinator,
33
+ type BetaManagedAgentsMultiagentCoordinatorParams,
34
+ type BetaManagedAgentsMultiagentSelfParams,
31
35
  type BetaManagedAgentsSkillParams,
32
36
  type BetaManagedAgentsURLMCPServerParams,
33
37
  type AgentCreateParams,