@anthropic-ai/foundry-sdk 0.2.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 (259) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +8 -0
  3. package/README.md +75 -0
  4. package/client.d.mts +58 -0
  5. package/client.d.mts.map +1 -0
  6. package/client.d.ts +58 -0
  7. package/client.d.ts.map +1 -0
  8. package/client.js +136 -0
  9. package/client.js.map +1 -0
  10. package/client.mjs +98 -0
  11. package/client.mjs.map +1 -0
  12. package/core/error.d.mts +2 -0
  13. package/core/error.d.mts.map +1 -0
  14. package/core/error.d.ts +2 -0
  15. package/core/error.d.ts.map +1 -0
  16. package/core/error.js +18 -0
  17. package/core/error.js.map +1 -0
  18. package/core/error.mjs +2 -0
  19. package/core/error.mjs.map +1 -0
  20. package/core/pagination.d.mts +2 -0
  21. package/core/pagination.d.mts.map +1 -0
  22. package/core/pagination.d.ts +2 -0
  23. package/core/pagination.d.ts.map +1 -0
  24. package/core/pagination.js +18 -0
  25. package/core/pagination.js.map +1 -0
  26. package/core/pagination.mjs +2 -0
  27. package/core/pagination.mjs.map +1 -0
  28. package/core/streaming.d.mts +2 -0
  29. package/core/streaming.d.mts.map +1 -0
  30. package/core/streaming.d.ts +2 -0
  31. package/core/streaming.d.ts.map +1 -0
  32. package/core/streaming.js +18 -0
  33. package/core/streaming.js.map +1 -0
  34. package/core/streaming.mjs +2 -0
  35. package/core/streaming.mjs.map +1 -0
  36. package/index.d.mts +4 -0
  37. package/index.d.mts.map +1 -0
  38. package/index.d.ts +4 -0
  39. package/index.d.ts.map +1 -0
  40. package/index.js +24 -0
  41. package/index.js.map +1 -0
  42. package/index.mjs +3 -0
  43. package/index.mjs.map +1 -0
  44. package/internal/builtin-types.d.mts +73 -0
  45. package/internal/builtin-types.d.mts.map +1 -0
  46. package/internal/builtin-types.d.ts +73 -0
  47. package/internal/builtin-types.d.ts.map +1 -0
  48. package/internal/builtin-types.js +4 -0
  49. package/internal/builtin-types.js.map +1 -0
  50. package/internal/builtin-types.mjs +3 -0
  51. package/internal/builtin-types.mjs.map +1 -0
  52. package/internal/constants.d.mts +5 -0
  53. package/internal/constants.d.mts.map +1 -0
  54. package/internal/constants.d.ts +5 -0
  55. package/internal/constants.d.ts.map +1 -0
  56. package/internal/constants.js +18 -0
  57. package/internal/constants.js.map +1 -0
  58. package/internal/constants.mjs +15 -0
  59. package/internal/constants.mjs.map +1 -0
  60. package/internal/decoders/jsonl.d.mts +10 -0
  61. package/internal/decoders/jsonl.d.mts.map +1 -0
  62. package/internal/decoders/jsonl.d.ts +10 -0
  63. package/internal/decoders/jsonl.d.ts.map +1 -0
  64. package/internal/decoders/jsonl.js +39 -0
  65. package/internal/decoders/jsonl.js.map +1 -0
  66. package/internal/decoders/jsonl.mjs +35 -0
  67. package/internal/decoders/jsonl.mjs.map +1 -0
  68. package/internal/decoders/line.d.mts +17 -0
  69. package/internal/decoders/line.d.mts.map +1 -0
  70. package/internal/decoders/line.d.ts +17 -0
  71. package/internal/decoders/line.d.ts.map +1 -0
  72. package/internal/decoders/line.js +123 -0
  73. package/internal/decoders/line.js.map +1 -0
  74. package/internal/decoders/line.mjs +118 -0
  75. package/internal/decoders/line.mjs.map +1 -0
  76. package/internal/errors.d.mts +3 -0
  77. package/internal/errors.d.mts.map +1 -0
  78. package/internal/errors.d.ts +3 -0
  79. package/internal/errors.d.ts.map +1 -0
  80. package/internal/errors.js +41 -0
  81. package/internal/errors.js.map +1 -0
  82. package/internal/errors.mjs +36 -0
  83. package/internal/errors.mjs.map +1 -0
  84. package/internal/headers.d.mts +22 -0
  85. package/internal/headers.d.mts.map +1 -0
  86. package/internal/headers.d.ts +22 -0
  87. package/internal/headers.d.ts.map +1 -0
  88. package/internal/headers.js +79 -0
  89. package/internal/headers.js.map +1 -0
  90. package/internal/headers.mjs +74 -0
  91. package/internal/headers.mjs.map +1 -0
  92. package/internal/parse.d.mts +17 -0
  93. package/internal/parse.d.mts.map +1 -0
  94. package/internal/parse.d.ts +17 -0
  95. package/internal/parse.d.ts.map +1 -0
  96. package/internal/parse.js +55 -0
  97. package/internal/parse.js.map +1 -0
  98. package/internal/parse.mjs +51 -0
  99. package/internal/parse.mjs.map +1 -0
  100. package/internal/request-options.d.mts +77 -0
  101. package/internal/request-options.d.mts.map +1 -0
  102. package/internal/request-options.d.ts +77 -0
  103. package/internal/request-options.d.ts.map +1 -0
  104. package/internal/request-options.js +14 -0
  105. package/internal/request-options.js.map +1 -0
  106. package/internal/request-options.mjs +10 -0
  107. package/internal/request-options.mjs.map +1 -0
  108. package/internal/shim-types.d.mts +17 -0
  109. package/internal/shim-types.d.mts.map +1 -0
  110. package/internal/shim-types.d.ts +17 -0
  111. package/internal/shim-types.d.ts.map +1 -0
  112. package/internal/shim-types.js +4 -0
  113. package/internal/shim-types.js.map +1 -0
  114. package/internal/shim-types.mjs +3 -0
  115. package/internal/shim-types.mjs.map +1 -0
  116. package/internal/shims.d.mts +20 -0
  117. package/internal/shims.d.mts.map +1 -0
  118. package/internal/shims.d.ts +20 -0
  119. package/internal/shims.d.ts.map +1 -0
  120. package/internal/shims.js +92 -0
  121. package/internal/shims.js.map +1 -0
  122. package/internal/shims.mjs +85 -0
  123. package/internal/shims.mjs.map +1 -0
  124. package/internal/stream-utils.d.mts +8 -0
  125. package/internal/stream-utils.d.mts.map +1 -0
  126. package/internal/stream-utils.d.ts +8 -0
  127. package/internal/stream-utils.d.ts.map +1 -0
  128. package/internal/stream-utils.js +38 -0
  129. package/internal/stream-utils.js.map +1 -0
  130. package/internal/stream-utils.mjs +35 -0
  131. package/internal/stream-utils.mjs.map +1 -0
  132. package/internal/to-file.d.mts +45 -0
  133. package/internal/to-file.d.mts.map +1 -0
  134. package/internal/to-file.d.ts +45 -0
  135. package/internal/to-file.d.ts.map +1 -0
  136. package/internal/to-file.js +96 -0
  137. package/internal/to-file.js.map +1 -0
  138. package/internal/to-file.mjs +93 -0
  139. package/internal/to-file.mjs.map +1 -0
  140. package/internal/types.d.mts +69 -0
  141. package/internal/types.d.mts.map +1 -0
  142. package/internal/types.d.ts +69 -0
  143. package/internal/types.d.ts.map +1 -0
  144. package/internal/types.js +4 -0
  145. package/internal/types.js.map +1 -0
  146. package/internal/types.mjs +3 -0
  147. package/internal/types.mjs.map +1 -0
  148. package/internal/uploads.d.mts +42 -0
  149. package/internal/uploads.d.mts.map +1 -0
  150. package/internal/uploads.d.ts +42 -0
  151. package/internal/uploads.d.ts.map +1 -0
  152. package/internal/uploads.js +146 -0
  153. package/internal/uploads.js.map +1 -0
  154. package/internal/uploads.mjs +136 -0
  155. package/internal/uploads.mjs.map +1 -0
  156. package/internal/utils/base64.d.mts +3 -0
  157. package/internal/utils/base64.d.mts.map +1 -0
  158. package/internal/utils/base64.d.ts +3 -0
  159. package/internal/utils/base64.d.ts.map +1 -0
  160. package/internal/utils/base64.js +38 -0
  161. package/internal/utils/base64.js.map +1 -0
  162. package/internal/utils/base64.mjs +33 -0
  163. package/internal/utils/base64.mjs.map +1 -0
  164. package/internal/utils/bytes.d.mts +4 -0
  165. package/internal/utils/bytes.d.mts.map +1 -0
  166. package/internal/utils/bytes.d.ts +4 -0
  167. package/internal/utils/bytes.d.ts.map +1 -0
  168. package/internal/utils/bytes.js +31 -0
  169. package/internal/utils/bytes.js.map +1 -0
  170. package/internal/utils/bytes.mjs +26 -0
  171. package/internal/utils/bytes.mjs.map +1 -0
  172. package/internal/utils/env.d.mts +9 -0
  173. package/internal/utils/env.d.mts.map +1 -0
  174. package/internal/utils/env.d.ts +9 -0
  175. package/internal/utils/env.d.ts.map +1 -0
  176. package/internal/utils/env.js +22 -0
  177. package/internal/utils/env.js.map +1 -0
  178. package/internal/utils/env.mjs +18 -0
  179. package/internal/utils/env.mjs.map +1 -0
  180. package/internal/utils/log.d.mts +37 -0
  181. package/internal/utils/log.d.mts.map +1 -0
  182. package/internal/utils/log.d.ts +37 -0
  183. package/internal/utils/log.d.ts.map +1 -0
  184. package/internal/utils/log.js +86 -0
  185. package/internal/utils/log.js.map +1 -0
  186. package/internal/utils/log.mjs +80 -0
  187. package/internal/utils/log.mjs.map +1 -0
  188. package/internal/utils/path.d.mts +15 -0
  189. package/internal/utils/path.d.mts.map +1 -0
  190. package/internal/utils/path.d.ts +15 -0
  191. package/internal/utils/path.d.ts.map +1 -0
  192. package/internal/utils/path.js +79 -0
  193. package/internal/utils/path.js.map +1 -0
  194. package/internal/utils/path.mjs +74 -0
  195. package/internal/utils/path.mjs.map +1 -0
  196. package/internal/utils/sleep.d.mts +2 -0
  197. package/internal/utils/sleep.d.mts.map +1 -0
  198. package/internal/utils/sleep.d.ts +2 -0
  199. package/internal/utils/sleep.d.ts.map +1 -0
  200. package/internal/utils/sleep.js +7 -0
  201. package/internal/utils/sleep.js.map +1 -0
  202. package/internal/utils/sleep.mjs +3 -0
  203. package/internal/utils/sleep.mjs.map +1 -0
  204. package/internal/utils/uuid.d.mts +5 -0
  205. package/internal/utils/uuid.d.mts.map +1 -0
  206. package/internal/utils/uuid.d.ts +5 -0
  207. package/internal/utils/uuid.d.ts.map +1 -0
  208. package/internal/utils/uuid.js +19 -0
  209. package/internal/utils/uuid.js.map +1 -0
  210. package/internal/utils/uuid.mjs +15 -0
  211. package/internal/utils/uuid.mjs.map +1 -0
  212. package/internal/utils/values.d.mts +19 -0
  213. package/internal/utils/values.d.mts.map +1 -0
  214. package/internal/utils/values.d.ts +19 -0
  215. package/internal/utils/values.d.ts.map +1 -0
  216. package/internal/utils/values.js +119 -0
  217. package/internal/utils/values.js.map +1 -0
  218. package/internal/utils/values.mjs +100 -0
  219. package/internal/utils/values.mjs.map +1 -0
  220. package/internal/utils.d.mts +7 -0
  221. package/internal/utils.d.mts.map +1 -0
  222. package/internal/utils.d.ts +7 -0
  223. package/internal/utils.d.ts.map +1 -0
  224. package/internal/utils.js +24 -0
  225. package/internal/utils.js.map +1 -0
  226. package/internal/utils.mjs +8 -0
  227. package/internal/utils.mjs.map +1 -0
  228. package/package.json +71 -0
  229. package/src/client.ts +166 -0
  230. package/src/core/error.ts +1 -0
  231. package/src/core/pagination.ts +1 -0
  232. package/src/core/streaming.ts +1 -0
  233. package/src/index.ts +3 -0
  234. package/src/internal/README.md +3 -0
  235. package/src/internal/builtin-types.ts +93 -0
  236. package/src/internal/constants.ts +15 -0
  237. package/src/internal/decoders/jsonl.ts +48 -0
  238. package/src/internal/decoders/line.ts +135 -0
  239. package/src/internal/detect-platform.ts +196 -0
  240. package/src/internal/errors.ts +33 -0
  241. package/src/internal/headers.ts +99 -0
  242. package/src/internal/parse.ts +84 -0
  243. package/src/internal/request-options.ts +93 -0
  244. package/src/internal/shim-types.ts +26 -0
  245. package/src/internal/shims.ts +107 -0
  246. package/src/internal/stream-utils.ts +32 -0
  247. package/src/internal/to-file.ts +159 -0
  248. package/src/internal/types.ts +95 -0
  249. package/src/internal/uploads.ts +193 -0
  250. package/src/internal/utils/base64.ts +40 -0
  251. package/src/internal/utils/bytes.ts +32 -0
  252. package/src/internal/utils/env.ts +18 -0
  253. package/src/internal/utils/log.ts +127 -0
  254. package/src/internal/utils/path.ts +88 -0
  255. package/src/internal/utils/sleep.ts +3 -0
  256. package/src/internal/utils/uuid.ts +17 -0
  257. package/src/internal/utils/values.ts +112 -0
  258. package/src/internal/utils.ts +8 -0
  259. package/src/tsconfig.json +11 -0
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.pop = exports.safeJSON = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.validatePositiveInteger = exports.ensurePresent = exports.isReadonlyArray = exports.isArray = exports.isAbsoluteURL = void 0;
5
+ exports.maybeObj = maybeObj;
6
+ exports.isEmptyObj = isEmptyObj;
7
+ exports.hasOwn = hasOwn;
8
+ exports.isObj = isObj;
9
+ const error_1 = require("../../core/error.js");
10
+ // https://url.spec.whatwg.org/#url-scheme-string
11
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
12
+ const isAbsoluteURL = (url) => {
13
+ return startsWithSchemeRegexp.test(url);
14
+ };
15
+ exports.isAbsoluteURL = isAbsoluteURL;
16
+ let isArray = (val) => ((exports.isArray = Array.isArray), (0, exports.isArray)(val));
17
+ exports.isArray = isArray;
18
+ exports.isReadonlyArray = exports.isArray;
19
+ /** Returns an object if the given value isn't an object, otherwise returns as-is */
20
+ function maybeObj(x) {
21
+ if (typeof x !== 'object') {
22
+ return {};
23
+ }
24
+ return x ?? {};
25
+ }
26
+ // https://stackoverflow.com/a/34491287
27
+ function isEmptyObj(obj) {
28
+ if (!obj)
29
+ return true;
30
+ for (const _k in obj)
31
+ return false;
32
+ return true;
33
+ }
34
+ // https://eslint.org/docs/latest/rules/no-prototype-builtins
35
+ function hasOwn(obj, key) {
36
+ return Object.prototype.hasOwnProperty.call(obj, key);
37
+ }
38
+ function isObj(obj) {
39
+ return obj != null && typeof obj === 'object' && !Array.isArray(obj);
40
+ }
41
+ const ensurePresent = (value) => {
42
+ if (value == null) {
43
+ throw new error_1.AnthropicError(`Expected a value to be given but received ${value} instead.`);
44
+ }
45
+ return value;
46
+ };
47
+ exports.ensurePresent = ensurePresent;
48
+ const validatePositiveInteger = (name, n) => {
49
+ if (typeof n !== 'number' || !Number.isInteger(n)) {
50
+ throw new error_1.AnthropicError(`${name} must be an integer`);
51
+ }
52
+ if (n < 0) {
53
+ throw new error_1.AnthropicError(`${name} must be a positive integer`);
54
+ }
55
+ return n;
56
+ };
57
+ exports.validatePositiveInteger = validatePositiveInteger;
58
+ const coerceInteger = (value) => {
59
+ if (typeof value === 'number')
60
+ return Math.round(value);
61
+ if (typeof value === 'string')
62
+ return parseInt(value, 10);
63
+ throw new error_1.AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
64
+ };
65
+ exports.coerceInteger = coerceInteger;
66
+ const coerceFloat = (value) => {
67
+ if (typeof value === 'number')
68
+ return value;
69
+ if (typeof value === 'string')
70
+ return parseFloat(value);
71
+ throw new error_1.AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
72
+ };
73
+ exports.coerceFloat = coerceFloat;
74
+ const coerceBoolean = (value) => {
75
+ if (typeof value === 'boolean')
76
+ return value;
77
+ if (typeof value === 'string')
78
+ return value === 'true';
79
+ return Boolean(value);
80
+ };
81
+ exports.coerceBoolean = coerceBoolean;
82
+ const maybeCoerceInteger = (value) => {
83
+ if (value == null) {
84
+ return undefined;
85
+ }
86
+ return (0, exports.coerceInteger)(value);
87
+ };
88
+ exports.maybeCoerceInteger = maybeCoerceInteger;
89
+ const maybeCoerceFloat = (value) => {
90
+ if (value == null) {
91
+ return undefined;
92
+ }
93
+ return (0, exports.coerceFloat)(value);
94
+ };
95
+ exports.maybeCoerceFloat = maybeCoerceFloat;
96
+ const maybeCoerceBoolean = (value) => {
97
+ if (value == null) {
98
+ return undefined;
99
+ }
100
+ return (0, exports.coerceBoolean)(value);
101
+ };
102
+ exports.maybeCoerceBoolean = maybeCoerceBoolean;
103
+ const safeJSON = (text) => {
104
+ try {
105
+ return JSON.parse(text);
106
+ }
107
+ catch (err) {
108
+ return undefined;
109
+ }
110
+ };
111
+ exports.safeJSON = safeJSON;
112
+ // Gets a value from an object, deletes the key, and returns the value (or undefined if not found)
113
+ const pop = (obj, key) => {
114
+ const value = obj[key];
115
+ delete obj[key];
116
+ return value;
117
+ };
118
+ exports.pop = pop;
119
+ //# sourceMappingURL=values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/internal/utils/values.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAetF,4BAMC;AAGD,gCAIC;AAGD,wBAEC;AAED,sBAEC;AAnCD,+CAAkD;AAElD,iDAAiD;AACjD,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAE/C,MAAM,aAAa,GAAG,CAAC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CAAC,GAAG,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAJW,QAAA,GAAG,OAId"}
@@ -0,0 +1,100 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ import { AnthropicError } from "../../core/error.mjs";
3
+ // https://url.spec.whatwg.org/#url-scheme-string
4
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
5
+ export const isAbsoluteURL = (url) => {
6
+ return startsWithSchemeRegexp.test(url);
7
+ };
8
+ export let isArray = (val) => ((isArray = Array.isArray), isArray(val));
9
+ export let isReadonlyArray = isArray;
10
+ /** Returns an object if the given value isn't an object, otherwise returns as-is */
11
+ export function maybeObj(x) {
12
+ if (typeof x !== 'object') {
13
+ return {};
14
+ }
15
+ return x ?? {};
16
+ }
17
+ // https://stackoverflow.com/a/34491287
18
+ export function isEmptyObj(obj) {
19
+ if (!obj)
20
+ return true;
21
+ for (const _k in obj)
22
+ return false;
23
+ return true;
24
+ }
25
+ // https://eslint.org/docs/latest/rules/no-prototype-builtins
26
+ export function hasOwn(obj, key) {
27
+ return Object.prototype.hasOwnProperty.call(obj, key);
28
+ }
29
+ export function isObj(obj) {
30
+ return obj != null && typeof obj === 'object' && !Array.isArray(obj);
31
+ }
32
+ export const ensurePresent = (value) => {
33
+ if (value == null) {
34
+ throw new AnthropicError(`Expected a value to be given but received ${value} instead.`);
35
+ }
36
+ return value;
37
+ };
38
+ export const validatePositiveInteger = (name, n) => {
39
+ if (typeof n !== 'number' || !Number.isInteger(n)) {
40
+ throw new AnthropicError(`${name} must be an integer`);
41
+ }
42
+ if (n < 0) {
43
+ throw new AnthropicError(`${name} must be a positive integer`);
44
+ }
45
+ return n;
46
+ };
47
+ export const coerceInteger = (value) => {
48
+ if (typeof value === 'number')
49
+ return Math.round(value);
50
+ if (typeof value === 'string')
51
+ return parseInt(value, 10);
52
+ throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
53
+ };
54
+ export const coerceFloat = (value) => {
55
+ if (typeof value === 'number')
56
+ return value;
57
+ if (typeof value === 'string')
58
+ return parseFloat(value);
59
+ throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
60
+ };
61
+ export const coerceBoolean = (value) => {
62
+ if (typeof value === 'boolean')
63
+ return value;
64
+ if (typeof value === 'string')
65
+ return value === 'true';
66
+ return Boolean(value);
67
+ };
68
+ export const maybeCoerceInteger = (value) => {
69
+ if (value == null) {
70
+ return undefined;
71
+ }
72
+ return coerceInteger(value);
73
+ };
74
+ export const maybeCoerceFloat = (value) => {
75
+ if (value == null) {
76
+ return undefined;
77
+ }
78
+ return coerceFloat(value);
79
+ };
80
+ export const maybeCoerceBoolean = (value) => {
81
+ if (value == null) {
82
+ return undefined;
83
+ }
84
+ return coerceBoolean(value);
85
+ };
86
+ export const safeJSON = (text) => {
87
+ try {
88
+ return JSON.parse(text);
89
+ }
90
+ catch (err) {
91
+ return undefined;
92
+ }
93
+ };
94
+ // Gets a value from an object, deletes the key, and returns the value (or undefined if not found)
95
+ export const pop = (obj, key) => {
96
+ const value = obj[key];
97
+ delete obj[key];
98
+ return value;
99
+ };
100
+ //# sourceMappingURL=values.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"values.mjs","sourceRoot":"","sources":["../../src/internal/utils/values.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,cAAc,EAAE;AAEzB,iDAAiD;AACjD,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAEtD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAW,EAAE;IACpD,OAAO,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,IAAI,OAAO,GAAG,CAAC,GAAY,EAAoB,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,C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AC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAsB,EAAE;IACrE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAuB,EAAE;IACxE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE;IACvC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF,kGAAkG;AAClG,MAAM,CAAC,MAAM,GAAG,GAAG,CAAkD,GAAM,EAAE,GAAM,EAAQ,EAAE;IAC3F,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./utils/values.mjs";
2
+ export * from "./utils/base64.mjs";
3
+ export * from "./utils/env.mjs";
4
+ export * from "./utils/log.mjs";
5
+ export * from "./utils/uuid.mjs";
6
+ export * from "./utils/sleep.mjs";
7
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/internal/utils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export * from "./utils/values.js";
2
+ export * from "./utils/base64.js";
3
+ export * from "./utils/env.js";
4
+ export * from "./utils/log.js";
5
+ export * from "./utils/uuid.js";
6
+ export * from "./utils/sleep.js";
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/internal/utils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./utils/values.js"), exports);
19
+ __exportStar(require("./utils/base64.js"), exports);
20
+ __exportStar(require("./utils/env.js"), exports);
21
+ __exportStar(require("./utils/log.js"), exports);
22
+ __exportStar(require("./utils/uuid.js"), exports);
23
+ __exportStar(require("./utils/sleep.js"), exports);
24
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/internal/utils.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;AAEtF,oDAA+B;AAC/B,oDAA+B;AAC/B,iDAA4B;AAC5B,iDAA4B;AAC5B,kDAA6B;AAC7B,mDAA8B"}
@@ -0,0 +1,8 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ export * from "./utils/values.mjs";
3
+ export * from "./utils/base64.mjs";
4
+ export * from "./utils/env.mjs";
5
+ export * from "./utils/log.mjs";
6
+ export * from "./utils/uuid.mjs";
7
+ export * from "./utils/sleep.mjs";
8
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/internal/utils.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@anthropic-ai/foundry-sdk",
3
+ "version": "0.2.0",
4
+ "description": "The official TypeScript library for the Anthropic Foundry API",
5
+ "author": "Anthropic <support@anthropic.com>",
6
+ "types": "./index.d.ts",
7
+ "main": "./index.js",
8
+ "type": "commonjs",
9
+ "repository": "github:anthropics/anthropic-sdk-typescript",
10
+ "license": "MIT",
11
+ "packageManager": "yarn@1.22.21",
12
+ "private": false,
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "test": "jest",
18
+ "build": "bash ./build",
19
+ "format": "prettier --write --cache --cache-strategy metadata . !dist",
20
+ "tsn": "ts-node -r tsconfig-paths/register",
21
+ "lint": "eslint --ext ts,js .",
22
+ "fix": "eslint --fix --ext ts,js ."
23
+ },
24
+ "dependencies": {
25
+ "@anthropic-ai/sdk": ">=0.50.3 <1"
26
+ },
27
+ "imports": {
28
+ "@anthropic-ai/foundry-sdk": ".",
29
+ "@anthropic-ai/foundry-sdk/*": "./src/*"
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "require": {
34
+ "types": "./index.d.ts",
35
+ "default": "./index.js"
36
+ },
37
+ "types": "./index.d.mts",
38
+ "default": "./index.mjs"
39
+ },
40
+ "./client": {
41
+ "import": "./client.mjs",
42
+ "require": "./client.js"
43
+ },
44
+ "./client.js": {
45
+ "default": "./client.js"
46
+ },
47
+ "./client.mjs": {
48
+ "default": "./client.mjs"
49
+ },
50
+ "./core/*.mjs": {
51
+ "default": "./core/*.mjs"
52
+ },
53
+ "./core/*.js": {
54
+ "default": "./core/*.js"
55
+ },
56
+ "./core/*": {
57
+ "import": "./core/*.mjs",
58
+ "require": "./core/*.js"
59
+ },
60
+ "./index": {
61
+ "import": "./index.mjs",
62
+ "require": "./index.js"
63
+ },
64
+ "./index.js": {
65
+ "default": "./index.js"
66
+ },
67
+ "./index.mjs": {
68
+ "default": "./index.mjs"
69
+ }
70
+ }
71
+ }
package/src/client.ts ADDED
@@ -0,0 +1,166 @@
1
+ import type { NullableHeaders } from './internal/headers';
2
+ import { buildHeaders } from './internal/headers';
3
+ import * as Errors from './core/error';
4
+ import { readEnv } from './internal/utils';
5
+ import { Anthropic, ClientOptions } from '@anthropic-ai/sdk/client';
6
+ export { BaseAnthropic } from '@anthropic-ai/sdk/client';
7
+ import * as Resources from '@anthropic-ai/sdk/resources/index';
8
+
9
+ /** API Client for interfacing with the Anthropic Foundry API. */
10
+ export interface FoundryClientOptions extends ClientOptions {
11
+ /**
12
+ * The name of your Foundry resource.
13
+ *
14
+ * For example, `https://{resource}.services.ai.azure.com/anthropic/v1/messages`.
15
+ */
16
+ resource?: string | undefined;
17
+
18
+ /**
19
+ * Defaults to process.env['ANTHROPIC_FOUNDRY_API_KEY'].
20
+ */
21
+ apiKey?: string | undefined;
22
+
23
+ /**
24
+ * A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),
25
+ * which will be invoked on every request.
26
+ */
27
+ azureADTokenProvider?: (() => Promise<string>) | undefined;
28
+ }
29
+
30
+ /** API Client for interfacing with the Anthropic Foundry API. */
31
+ export class AnthropicFoundry extends Anthropic {
32
+ resource: string | null = null;
33
+
34
+ // @ts-expect-error are using a different Messages type that omits batches
35
+ override messages: MessagesResource = makeMessagesResource(this);
36
+
37
+ // @ts-expect-error are using a different Beta type that omits batches
38
+ override beta: BetaResource = makeBetaResource(this);
39
+
40
+ // @ts-expect-error Anthropic Foundry does not support models endpoint
41
+ override models = undefined;
42
+ /**
43
+ * API Client for interfacing with the Anthropic Foundry API.
44
+ *
45
+ * @param {string | undefined} [opts.resource=process.env['ANTHROPIC_FOUNDRY_RESOURCE'] ?? undefined] - Your Foundry resource name
46
+ * @param {string | undefined} [opts.apiKey=process.env['ANTHROPIC_FOUNDRY_API_KEY'] ?? undefined]
47
+ * @param {string | null | undefined} [opts.organization=process.env['ANTHROPIC_ORG_ID'] ?? null]
48
+ * @param {string} [opts.baseURL=process.env['ANTHROPIC_FOUNDRY_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.anthropic.com/anthropic/`.
49
+ * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
50
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
51
+ * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
52
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
53
+ * @param {Headers} opts.defaultHeaders - Default headers to include with every request to the API.
54
+ * @param {DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
55
+ * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
56
+ */
57
+ constructor({
58
+ baseURL = readEnv('ANTHROPIC_FOUNDRY_BASE_URL'),
59
+ apiKey = readEnv('ANTHROPIC_FOUNDRY_API_KEY'),
60
+ resource = readEnv('ANTHROPIC_FOUNDRY_RESOURCE'),
61
+ azureADTokenProvider,
62
+ dangerouslyAllowBrowser,
63
+ ...opts
64
+ }: FoundryClientOptions = {}) {
65
+ if (typeof azureADTokenProvider === 'function') {
66
+ dangerouslyAllowBrowser = true;
67
+ }
68
+
69
+ if (!azureADTokenProvider && !apiKey) {
70
+ throw new Errors.AnthropicError(
71
+ 'Missing credentials. Please pass one of `apiKey` and `azureTokenProvider`, or set the `ANTHROPIC_FOUNDRY_API_KEY` environment variable.',
72
+ );
73
+ }
74
+
75
+ if (azureADTokenProvider && apiKey) {
76
+ throw new Errors.AnthropicError(
77
+ 'The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.',
78
+ );
79
+ }
80
+
81
+ if (!baseURL) {
82
+ if (!resource) {
83
+ throw new Errors.AnthropicError(
84
+ 'Must provide one of the `baseURL` or `resource` arguments, or the `ANTHROPIC_FOUNDRY_RESOURCE` environment variable',
85
+ );
86
+ }
87
+
88
+ baseURL = `https://${resource}.services.ai.azure.com/anthropic/`;
89
+ } else {
90
+ if (resource) {
91
+ throw new Errors.AnthropicError('baseURL and resource are mutually exclusive');
92
+ }
93
+ }
94
+
95
+ super({
96
+ apiKey: azureADTokenProvider ?? apiKey,
97
+ baseURL,
98
+ ...opts,
99
+ ...(dangerouslyAllowBrowser !== undefined ? { dangerouslyAllowBrowser } : {}),
100
+ });
101
+ }
102
+
103
+ protected override async authHeaders(): Promise<NullableHeaders | undefined> {
104
+ if (typeof this._options.apiKey === 'function') {
105
+ let token: unknown;
106
+ try {
107
+ token = await this._options.apiKey();
108
+ } catch (err: any) {
109
+ if (err instanceof Errors.AnthropicError) throw err;
110
+ throw new Errors.AnthropicError(
111
+ `Failed to get token from azureADTokenProvider: ${err.message}`,
112
+ // @ts-ignore
113
+ { cause: err },
114
+ );
115
+ }
116
+
117
+ if (typeof token !== 'string' || !token) {
118
+ throw new Errors.AnthropicError(
119
+ `Expected azureADTokenProvider function argument to return a string but it returned ${token}`,
120
+ );
121
+ }
122
+
123
+ return buildHeaders([{ Authorization: `Bearer ${token}` }]);
124
+ }
125
+
126
+ if (typeof this._options.apiKey === 'string') {
127
+ return buildHeaders([{ 'x-api-key': this.apiKey }]);
128
+ }
129
+
130
+ return undefined;
131
+ }
132
+
133
+ protected override validateHeaders(): void {
134
+ return;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * The Anthropic Foundry does not currently support the Batch API.
140
+ */
141
+ type MessagesResource = Omit<Resources.Messages, 'batches'>;
142
+
143
+ function makeMessagesResource(client: AnthropicFoundry): MessagesResource {
144
+ const resource = new Resources.Messages(client);
145
+
146
+ // @ts-expect-error we're deleting non-optional properties
147
+ delete resource.batches;
148
+
149
+ return resource;
150
+ }
151
+
152
+ /**
153
+ * The Anthropic Foundry does not currently support the Batch API.
154
+ */
155
+ type BetaResource = Omit<Resources.Beta, 'messages'> & {
156
+ messages: Omit<Resources.Beta['messages'], 'batches'>;
157
+ };
158
+
159
+ function makeBetaResource(client: AnthropicFoundry): BetaResource {
160
+ const resource = new Resources.Beta(client);
161
+
162
+ // @ts-expect-error we're deleting non-optional properties
163
+ delete resource.messages.batches;
164
+
165
+ return resource;
166
+ }
@@ -0,0 +1 @@
1
+ export * from '@anthropic-ai/sdk/core/error';
@@ -0,0 +1 @@
1
+ export * from '@anthropic-ai/sdk/core/pagination';
@@ -0,0 +1 @@
1
+ export * from '@anthropic-ai/sdk/core/streaming';
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './client';
2
+ export { AnthropicFoundry as default } from './client';
3
+ export type { FoundryClientOptions } from './client';
@@ -0,0 +1,3 @@
1
+ # `internal`
2
+
3
+ The modules in this directory are not importable outside this package and will change between releases.
@@ -0,0 +1,93 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
+
5
+ /**
6
+ * An alias to the builtin `RequestInit` type so we can
7
+ * easily alias it in import statements if there are name clashes.
8
+ *
9
+ * https://developer.mozilla.org/docs/Web/API/RequestInit
10
+ */
11
+ type _RequestInit = RequestInit;
12
+
13
+ /**
14
+ * An alias to the builtin `Response` type so we can
15
+ * easily alias it in import statements if there are name clashes.
16
+ *
17
+ * https://developer.mozilla.org/docs/Web/API/Response
18
+ */
19
+ type _Response = Response;
20
+
21
+ /**
22
+ * The type for the first argument to `fetch`.
23
+ *
24
+ * https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
25
+ */
26
+ type _RequestInfo = Request | URL | string;
27
+
28
+ /**
29
+ * The type for constructing `RequestInit` Headers.
30
+ *
31
+ * https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
32
+ */
33
+ type _HeadersInit = RequestInit['headers'];
34
+
35
+ /**
36
+ * The type for constructing `RequestInit` body.
37
+ *
38
+ * https://developer.mozilla.org/docs/Web/API/RequestInit#body
39
+ */
40
+ type _BodyInit = RequestInit['body'];
41
+
42
+ /**
43
+ * An alias to the builtin `Array<T>` type so we can
44
+ * easily alias it in import statements if there are name clashes.
45
+ */
46
+ type _Array<T> = Array<T>;
47
+
48
+ /**
49
+ * An alias to the builtin `Record<K, T>` type so we can
50
+ * easily alias it in import statements if there are name clashes.
51
+ */
52
+ type _Record<K extends keyof any, T> = Record<K, T>;
53
+
54
+ export type {
55
+ _Array as Array,
56
+ _BodyInit as BodyInit,
57
+ _HeadersInit as HeadersInit,
58
+ _Record as Record,
59
+ _RequestInfo as RequestInfo,
60
+ _RequestInit as RequestInit,
61
+ _Response as Response,
62
+ };
63
+
64
+ /**
65
+ * A copy of the builtin `EndingType` type as it isn't fully supported in certain
66
+ * environments and attempting to reference the global version will error.
67
+ *
68
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
69
+ */
70
+ type EndingType = 'native' | 'transparent';
71
+
72
+ /**
73
+ * A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
74
+ * environments and attempting to reference the global version will error.
75
+ *
76
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
77
+ * https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
78
+ */
79
+ export interface BlobPropertyBag {
80
+ endings?: EndingType;
81
+ type?: string;
82
+ }
83
+
84
+ /**
85
+ * A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
86
+ * environments and attempting to reference the global version will error.
87
+ *
88
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
89
+ * https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
90
+ */
91
+ export interface FilePropertyBag extends BlobPropertyBag {
92
+ lastModified?: number;
93
+ }
@@ -0,0 +1,15 @@
1
+ // File containing shared constants
2
+
3
+ /**
4
+ * Model-specific timeout constraints for non-streaming requests
5
+ */
6
+ export const MODEL_NONSTREAMING_TOKENS: Record<string, number> = {
7
+ 'claude-opus-4-20250514': 8192,
8
+ 'claude-opus-4-0': 8192,
9
+ 'claude-4-opus-20250514': 8192,
10
+ 'anthropic.claude-opus-4-20250514-v1:0': 8192,
11
+ 'claude-opus-4@20250514': 8192,
12
+ 'claude-opus-4-1-20250805': 8192,
13
+ 'anthropic.claude-opus-4-1-20250805-v1:0': 8192,
14
+ 'claude-opus-4-1@20250805': 8192,
15
+ };