@anthropic-ai/foundry-sdk 0.4.4 → 0.4.6

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 (143) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +3 -3
  3. package/internal/builtin-types.d.mts.map +1 -1
  4. package/internal/builtin-types.d.ts.map +1 -1
  5. package/internal/builtin-types.js +0 -1
  6. package/internal/builtin-types.js.map +1 -1
  7. package/internal/builtin-types.mjs +0 -1
  8. package/internal/builtin-types.mjs.map +1 -1
  9. package/internal/errors.d.mts.map +1 -1
  10. package/internal/errors.d.ts.map +1 -1
  11. package/internal/errors.js +3 -2
  12. package/internal/errors.js.map +1 -1
  13. package/internal/errors.mjs +3 -2
  14. package/internal/errors.mjs.map +1 -1
  15. package/internal/file-store.d.mts.map +1 -1
  16. package/internal/file-store.d.ts.map +1 -1
  17. package/internal/file-store.js +23 -57
  18. package/internal/file-store.js.map +1 -1
  19. package/internal/file-store.mjs +5 -6
  20. package/internal/file-store.mjs.map +1 -1
  21. package/internal/headers.d.mts.map +1 -1
  22. package/internal/headers.d.ts.map +1 -1
  23. package/internal/headers.js +0 -1
  24. package/internal/headers.js.map +1 -1
  25. package/internal/headers.mjs +0 -1
  26. package/internal/headers.mjs.map +1 -1
  27. package/internal/node.browser.d.mts +9 -0
  28. package/internal/node.browser.d.mts.map +1 -0
  29. package/internal/node.browser.d.ts +9 -0
  30. package/internal/node.browser.d.ts.map +1 -0
  31. package/internal/node.browser.js +22 -0
  32. package/internal/node.browser.js.map +1 -0
  33. package/internal/node.browser.mjs +19 -0
  34. package/internal/node.browser.mjs.map +1 -0
  35. package/internal/node.d.mts +14 -0
  36. package/internal/node.d.mts.map +1 -0
  37. package/internal/node.d.ts +14 -0
  38. package/internal/node.d.ts.map +1 -0
  39. package/internal/node.js +56 -0
  40. package/internal/node.js.map +1 -0
  41. package/internal/node.mjs +14 -0
  42. package/internal/node.mjs.map +1 -0
  43. package/internal/parse.d.mts.map +1 -1
  44. package/internal/parse.d.ts.map +1 -1
  45. package/internal/parse.js +1 -2
  46. package/internal/parse.js.map +1 -1
  47. package/internal/parse.mjs +1 -2
  48. package/internal/parse.mjs.map +1 -1
  49. package/internal/request-options.d.mts +1 -1
  50. package/internal/request-options.d.mts.map +1 -1
  51. package/internal/request-options.d.ts +1 -1
  52. package/internal/request-options.d.ts.map +1 -1
  53. package/internal/request-options.js +0 -1
  54. package/internal/request-options.js.map +1 -1
  55. package/internal/request-options.mjs +0 -1
  56. package/internal/request-options.mjs.map +1 -1
  57. package/internal/shim-types.d.mts.map +1 -1
  58. package/internal/shim-types.d.ts.map +1 -1
  59. package/internal/shim-types.js +6 -1
  60. package/internal/shim-types.js.map +1 -1
  61. package/internal/shim-types.mjs +6 -1
  62. package/internal/shim-types.mjs.map +1 -1
  63. package/internal/shims.d.mts.map +1 -1
  64. package/internal/shims.d.ts.map +1 -1
  65. package/internal/shims.js +6 -1
  66. package/internal/shims.js.map +1 -1
  67. package/internal/shims.mjs +6 -1
  68. package/internal/shims.mjs.map +1 -1
  69. package/internal/types.d.mts.map +1 -1
  70. package/internal/types.d.ts.map +1 -1
  71. package/internal/types.js +0 -1
  72. package/internal/types.js.map +1 -1
  73. package/internal/types.mjs +0 -1
  74. package/internal/types.mjs.map +1 -1
  75. package/internal/uploads.js +10 -6
  76. package/internal/uploads.js.map +1 -1
  77. package/internal/uploads.mjs +10 -6
  78. package/internal/uploads.mjs.map +1 -1
  79. package/internal/utils/base64.d.mts.map +1 -1
  80. package/internal/utils/base64.d.ts.map +1 -1
  81. package/internal/utils/base64.js +0 -1
  82. package/internal/utils/base64.js.map +1 -1
  83. package/internal/utils/base64.mjs +0 -1
  84. package/internal/utils/base64.mjs.map +1 -1
  85. package/internal/utils/env.d.mts.map +1 -1
  86. package/internal/utils/env.d.ts.map +1 -1
  87. package/internal/utils/env.js +0 -1
  88. package/internal/utils/env.js.map +1 -1
  89. package/internal/utils/env.mjs +0 -1
  90. package/internal/utils/env.mjs.map +1 -1
  91. package/internal/utils/log.d.mts.map +1 -1
  92. package/internal/utils/log.d.ts.map +1 -1
  93. package/internal/utils/log.js +0 -1
  94. package/internal/utils/log.js.map +1 -1
  95. package/internal/utils/log.mjs +0 -1
  96. package/internal/utils/log.mjs.map +1 -1
  97. package/internal/utils/query.d.mts.map +1 -1
  98. package/internal/utils/query.d.ts.map +1 -1
  99. package/internal/utils/query.js +0 -1
  100. package/internal/utils/query.js.map +1 -1
  101. package/internal/utils/query.mjs +0 -1
  102. package/internal/utils/query.mjs.map +1 -1
  103. package/internal/utils/uuid.d.mts.map +1 -1
  104. package/internal/utils/uuid.d.ts.map +1 -1
  105. package/internal/utils/uuid.js +0 -1
  106. package/internal/utils/uuid.js.map +1 -1
  107. package/internal/utils/uuid.mjs +0 -1
  108. package/internal/utils/uuid.mjs.map +1 -1
  109. package/internal/utils/values.d.mts +6 -0
  110. package/internal/utils/values.d.mts.map +1 -1
  111. package/internal/utils/values.d.ts +6 -0
  112. package/internal/utils/values.d.ts.map +1 -1
  113. package/internal/utils/values.js +7 -1
  114. package/internal/utils/values.js.map +1 -1
  115. package/internal/utils/values.mjs +6 -1
  116. package/internal/utils/values.mjs.map +1 -1
  117. package/internal/utils.d.mts.map +1 -1
  118. package/internal/utils.d.ts.map +1 -1
  119. package/internal/utils.js +0 -1
  120. package/internal/utils.js.map +1 -1
  121. package/internal/utils.mjs +0 -1
  122. package/internal/utils.mjs.map +1 -1
  123. package/package.json +1 -11
  124. package/src/internal/builtin-types.ts +0 -2
  125. package/src/internal/detect-platform.ts +1 -3
  126. package/src/internal/errors.ts +3 -3
  127. package/src/internal/file-store.ts +11 -10
  128. package/src/internal/headers.ts +0 -2
  129. package/src/internal/node.browser.ts +22 -0
  130. package/src/internal/node.ts +14 -0
  131. package/src/internal/parse.ts +1 -3
  132. package/src/internal/request-options.ts +1 -3
  133. package/src/internal/shim-types.ts +0 -2
  134. package/src/internal/shims.ts +0 -2
  135. package/src/internal/types.ts +0 -2
  136. package/src/internal/uploads.ts +10 -7
  137. package/src/internal/utils/base64.ts +0 -2
  138. package/src/internal/utils/env.ts +0 -2
  139. package/src/internal/utils/log.ts +0 -2
  140. package/src/internal/utils/query.ts +0 -2
  141. package/src/internal/utils/uuid.ts +0 -2
  142. package/src/internal/utils/values.ts +7 -2
  143. package/src/internal/utils.ts +0 -2
@@ -7,14 +7,15 @@
7
7
  * scope.
8
8
  */
9
9
 
10
- import * as fsp from 'node:fs/promises';
11
- import * as path from 'node:path';
12
- import { constants as C } from 'node:fs';
13
10
  import type { BigIntStats, Dirent } from 'node:fs';
11
+ import type { FileHandle } from 'node:fs/promises';
14
12
  import type * as util from 'node:util';
15
- import { createHash, randomBytes } from 'node:crypto';
13
+ import { crypto, fs, path } from './node';
16
14
  import { encodeUTF8 } from './utils/bytes';
17
15
 
16
+ const fsp = fs.promises;
17
+ const C = fs.constants;
18
+
18
19
  // Owner-only regardless of umask: the store holds downloaded user/model content.
19
20
  const OWNER_ONLY_DIR_MODE = 0o700;
20
21
  const OWNER_ONLY_FILE_MODE = 0o600;
@@ -182,7 +183,7 @@ export class FileStore {
182
183
  /** The file's bytes; `null` when absent. */
183
184
  async get(relPath: string): Promise<Uint8Array | null> {
184
185
  const dest = this.resolveUnderRoot(relPath);
185
- let handle: fsp.FileHandle;
186
+ let handle: FileHandle;
186
187
  try {
187
188
  handle = await openRegularFile(relPath, dest);
188
189
  } catch (e) {
@@ -388,8 +389,8 @@ async function makeDirsBelowRoot(root: string, dir: string): Promise<void> {
388
389
 
389
390
  async function replaceViaTemp(dest: string, data: Uint8Array, isExecutable: boolean): Promise<void> {
390
391
  const mode = isExecutable ? OWNER_ONLY_EXEC_MODE : OWNER_ONLY_FILE_MODE;
391
- const tmp = path.join(path.dirname(dest), `.fs-${randomBytes(8).toString('hex')}.tmp`);
392
- let handle: fsp.FileHandle | undefined;
392
+ const tmp = path.join(path.dirname(dest), `.fs-${crypto.randomBytes(8).toString('hex')}.tmp`);
393
+ let handle: FileHandle | undefined;
393
394
  try {
394
395
  handle = await fsp.open(tmp, C.O_WRONLY | C.O_CREAT | C.O_EXCL | O_NOFOLLOW, mode);
395
396
  await handle.writeFile(data);
@@ -404,9 +405,9 @@ async function replaceViaTemp(dest: string, data: Uint8Array, isExecutable: bool
404
405
  }
405
406
  }
406
407
 
407
- async function openRegularFile(relPath: string, dest: string): Promise<fsp.FileHandle> {
408
+ async function openRegularFile(relPath: string, dest: string): Promise<FileHandle> {
408
409
  // O_NONBLOCK: a FIFO fails the fstat check below instead of blocking the open.
409
- let handle: fsp.FileHandle;
410
+ let handle: FileHandle;
410
411
  try {
411
412
  handle = await fsp.open(dest, C.O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
412
413
  } catch (e) {
@@ -429,7 +430,7 @@ async function openRegularFile(relPath: string, dest: string): Promise<fsp.FileH
429
430
 
430
431
  /** sha256 of a file's contents, streamed — constant memory on any file size. */
431
432
  async function hashFile(full: string): Promise<string> {
432
- const digest = createHash('sha256');
433
+ const digest = crypto.createHash('sha256');
433
434
  const handle = await openRegularFile(path.basename(full), full);
434
435
  const buf = new Uint8Array(1024 * 1024);
435
436
  try {
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { isReadonlyArray } from './utils/values';
4
2
 
5
3
  type HeaderValue = string | undefined | null;
@@ -0,0 +1,22 @@
1
+ import { AnthropicError } from '../core/error';
2
+ import type * as node from './node';
3
+
4
+ /** Substituted for `./node` by the package.json `browser` field; every property access throws. */
5
+ function unavailable<T extends object>(module: string): T {
6
+ return new Proxy({} as T, {
7
+ get(_target, property) {
8
+ if (typeof property === 'symbol') return undefined;
9
+ throw new AnthropicError(
10
+ `\`${module}.${property}\` is not available in this environment; it needs a Node.js-compatible runtime`,
11
+ );
12
+ },
13
+ });
14
+ }
15
+
16
+ export const child_process: typeof node.child_process = unavailable('child_process');
17
+ export const crypto: typeof node.crypto = unavailable('crypto');
18
+ export const fs: typeof node.fs = unavailable('fs');
19
+ export const os: typeof node.os = unavailable('os');
20
+ export const path: typeof node.path = unavailable('path');
21
+ export const stream: typeof node.stream = unavailable('stream');
22
+ export const util: typeof node.util = unavailable('util');
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The one module under `src/` that may import Node built-ins (eslint enforces this).
3
+ * The package.json `browser` field swaps it for `./node.browser`, so only touch its
4
+ * exports on code paths that run on Node-compatible runtimes.
5
+ */
6
+ import * as child_process from 'node:child_process';
7
+ import * as crypto from 'node:crypto';
8
+ import * as fs from 'node:fs';
9
+ import * as os from 'node:os';
10
+ import * as path from 'node:path';
11
+ import * as stream from 'node:stream';
12
+ import * as util from 'node:util';
13
+
14
+ export { child_process, crypto, fs, os, path, stream, util };
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import type { FinalRequestOptions } from './request-options';
4
2
  import { Stream } from '../core/streaming';
5
3
  import { type BaseAnthropic } from '../client';
@@ -28,7 +26,7 @@ export async function defaultParseResponse<T>(
28
26
  // Note: there is an invariant here that isn't represented in the type system
29
27
  // that if you set `stream: true` the response type must also be `Stream<T>`
30
28
 
31
- return Stream.fromSSEResponse(response, props.controller) as any;
29
+ return Stream.fromSSEResponse(response, props.controller, client) as any;
32
30
  }
33
31
 
34
32
  // fetch refuses to read the body when the status code is 204.
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { NullableHeaders } from './headers';
4
2
 
5
3
  import type { BodyInit } from './builtin-types';
@@ -120,7 +118,7 @@ export interface RequestOptions {
120
118
  fallbackState?: BetaFallbackState;
121
119
 
122
120
  /**
123
- * A unique key for this request to enable idempotency.
121
+ * @deprecated This option has no effect and will be removed in a future major version.
124
122
  */
125
123
  idempotencyKey?: string;
126
124
 
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * Shims for types that we can't always rely on being available globally.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export type PromiseOrValue<T> = T | Promise<T>;
4
2
  export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
5
3
 
@@ -137,14 +137,11 @@ export const createForm = async <T = Record<string, unknown>>(
137
137
  return form;
138
138
  };
139
139
 
140
- // We check for Blob not File because Bun.File doesn't inherit from File,
141
- // but they both inherit from Blob and have a `name` property at runtime.
142
- const isNamedBlob = (value: unknown): value is Blob => value instanceof Blob && 'name' in value;
143
-
140
+ // Blob, not File: bare Blobs and Bun.file() results don't inherit from File.
144
141
  const isUploadable = (value: unknown) =>
145
142
  typeof value === 'object' &&
146
143
  value !== null &&
147
- (value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));
144
+ (value instanceof Response || isAsyncIterable(value) || value instanceof Blob);
148
145
 
149
146
  const hasUploadableValue = (value: unknown): boolean => {
150
147
  if (isUploadable(value)) return true;
@@ -186,10 +183,16 @@ const addFormValue = async (
186
183
  key,
187
184
  makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value, stripFilenames)),
188
185
  );
189
- } else if (isNamedBlob(value)) {
190
- form.append(key, makeFile([value], getName(value, stripFilenames), { type: value.type }));
186
+ } else if (value instanceof Blob) {
187
+ form.append(key, makeFile([value], getName(value, stripFilenames) || undefined, { type: value.type }));
191
188
  } else if (Array.isArray(value)) {
192
189
  await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry, stripFilenames)));
190
+ } else if (typeof (value as any).then === 'function') {
191
+ throw new TypeError(`Received a Promise for "${key}"; await it first, e.g. \`await toFile(...)\``);
192
+ } else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
193
+ throw new TypeError(
194
+ `Received ${value.constructor.name} for "${key}"; to upload raw bytes, wrap them with \`await toFile(bytes, 'filename')\``,
195
+ );
193
196
  } else if (typeof value === 'object') {
194
197
  await Promise.all(
195
198
  Object.entries(value).map(([name, prop]) =>
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { AnthropicError } from '../../core/error';
4
2
  import { encodeUTF8 } from './bytes';
5
3
 
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * Read an environment variable.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { hasOwn } from './values';
4
2
  import { readEnv } from './env';
5
3
  import { type BaseAnthropic } from '../../client';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import * as qs from '../qs/stringify';
4
2
 
5
3
  export function stringifyQuery(query: object | Record<string, unknown>) {
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * https://stackoverflow.com/a/2117523
5
3
  */
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { AnthropicError } from '../../core/error';
4
2
 
5
3
  // https://url.spec.whatwg.org/#url-scheme-string
@@ -110,3 +108,10 @@ export const pop = <T extends Record<string, any>, K extends string>(obj: T, key
110
108
  delete obj[key];
111
109
  return value;
112
110
  };
111
+
112
+ /**
113
+ * Compile-time exhaustiveness check: passing a value here only type-checks once every
114
+ * member of its union has been handled. Does nothing at runtime, so unknown values from a
115
+ * newer API version fall through instead of throwing.
116
+ */
117
+ export function checkNever(_value: never): void {}
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export * from './utils/values';
4
2
  export * from './utils/base64';
5
3
  export * from './utils/env';