@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.
- package/CHANGELOG.md +12 -0
- package/README.md +3 -3
- package/internal/builtin-types.d.mts.map +1 -1
- package/internal/builtin-types.d.ts.map +1 -1
- package/internal/builtin-types.js +0 -1
- package/internal/builtin-types.js.map +1 -1
- package/internal/builtin-types.mjs +0 -1
- package/internal/builtin-types.mjs.map +1 -1
- package/internal/errors.d.mts.map +1 -1
- package/internal/errors.d.ts.map +1 -1
- package/internal/errors.js +3 -2
- package/internal/errors.js.map +1 -1
- package/internal/errors.mjs +3 -2
- package/internal/errors.mjs.map +1 -1
- package/internal/file-store.d.mts.map +1 -1
- package/internal/file-store.d.ts.map +1 -1
- package/internal/file-store.js +23 -57
- package/internal/file-store.js.map +1 -1
- package/internal/file-store.mjs +5 -6
- package/internal/file-store.mjs.map +1 -1
- package/internal/headers.d.mts.map +1 -1
- package/internal/headers.d.ts.map +1 -1
- package/internal/headers.js +0 -1
- package/internal/headers.js.map +1 -1
- package/internal/headers.mjs +0 -1
- package/internal/headers.mjs.map +1 -1
- package/internal/node.browser.d.mts +9 -0
- package/internal/node.browser.d.mts.map +1 -0
- package/internal/node.browser.d.ts +9 -0
- package/internal/node.browser.d.ts.map +1 -0
- package/internal/node.browser.js +22 -0
- package/internal/node.browser.js.map +1 -0
- package/internal/node.browser.mjs +19 -0
- package/internal/node.browser.mjs.map +1 -0
- package/internal/node.d.mts +14 -0
- package/internal/node.d.mts.map +1 -0
- package/internal/node.d.ts +14 -0
- package/internal/node.d.ts.map +1 -0
- package/internal/node.js +56 -0
- package/internal/node.js.map +1 -0
- package/internal/node.mjs +14 -0
- package/internal/node.mjs.map +1 -0
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +1 -2
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +1 -2
- package/internal/parse.mjs.map +1 -1
- package/internal/request-options.d.mts +1 -1
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +1 -1
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js +0 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs +0 -1
- package/internal/request-options.mjs.map +1 -1
- package/internal/shim-types.d.mts.map +1 -1
- package/internal/shim-types.d.ts.map +1 -1
- package/internal/shim-types.js +6 -1
- package/internal/shim-types.js.map +1 -1
- package/internal/shim-types.mjs +6 -1
- package/internal/shim-types.mjs.map +1 -1
- package/internal/shims.d.mts.map +1 -1
- package/internal/shims.d.ts.map +1 -1
- package/internal/shims.js +6 -1
- package/internal/shims.js.map +1 -1
- package/internal/shims.mjs +6 -1
- package/internal/shims.mjs.map +1 -1
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts.map +1 -1
- package/internal/types.js +0 -1
- package/internal/types.js.map +1 -1
- package/internal/types.mjs +0 -1
- package/internal/types.mjs.map +1 -1
- package/internal/uploads.js +10 -6
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +10 -6
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/base64.d.mts.map +1 -1
- package/internal/utils/base64.d.ts.map +1 -1
- package/internal/utils/base64.js +0 -1
- package/internal/utils/base64.js.map +1 -1
- package/internal/utils/base64.mjs +0 -1
- package/internal/utils/base64.mjs.map +1 -1
- package/internal/utils/env.d.mts.map +1 -1
- package/internal/utils/env.d.ts.map +1 -1
- package/internal/utils/env.js +0 -1
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +0 -1
- package/internal/utils/env.mjs.map +1 -1
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +0 -1
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +0 -1
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/query.d.mts.map +1 -1
- package/internal/utils/query.d.ts.map +1 -1
- package/internal/utils/query.js +0 -1
- package/internal/utils/query.js.map +1 -1
- package/internal/utils/query.mjs +0 -1
- package/internal/utils/query.mjs.map +1 -1
- package/internal/utils/uuid.d.mts.map +1 -1
- package/internal/utils/uuid.d.ts.map +1 -1
- package/internal/utils/uuid.js +0 -1
- package/internal/utils/uuid.js.map +1 -1
- package/internal/utils/uuid.mjs +0 -1
- package/internal/utils/uuid.mjs.map +1 -1
- package/internal/utils/values.d.mts +6 -0
- package/internal/utils/values.d.mts.map +1 -1
- package/internal/utils/values.d.ts +6 -0
- package/internal/utils/values.d.ts.map +1 -1
- package/internal/utils/values.js +7 -1
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +6 -1
- package/internal/utils/values.mjs.map +1 -1
- package/internal/utils.d.mts.map +1 -1
- package/internal/utils.d.ts.map +1 -1
- package/internal/utils.js +0 -1
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +0 -1
- package/internal/utils.mjs.map +1 -1
- package/package.json +1 -11
- package/src/internal/builtin-types.ts +0 -2
- package/src/internal/detect-platform.ts +1 -3
- package/src/internal/errors.ts +3 -3
- package/src/internal/file-store.ts +11 -10
- package/src/internal/headers.ts +0 -2
- package/src/internal/node.browser.ts +22 -0
- package/src/internal/node.ts +14 -0
- package/src/internal/parse.ts +1 -3
- package/src/internal/request-options.ts +1 -3
- package/src/internal/shim-types.ts +0 -2
- package/src/internal/shims.ts +0 -2
- package/src/internal/types.ts +0 -2
- package/src/internal/uploads.ts +10 -7
- package/src/internal/utils/base64.ts +0 -2
- package/src/internal/utils/env.ts +0 -2
- package/src/internal/utils/log.ts +0 -2
- package/src/internal/utils/query.ts +0 -2
- package/src/internal/utils/uuid.ts +0 -2
- package/src/internal/utils/values.ts +7 -2
- 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 {
|
|
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:
|
|
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:
|
|
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<
|
|
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:
|
|
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 {
|
package/src/internal/headers.ts
CHANGED
|
@@ -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 };
|
package/src/internal/parse.ts
CHANGED
|
@@ -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
|
-
*
|
|
121
|
+
* @deprecated This option has no effect and will be removed in a future major version.
|
|
124
122
|
*/
|
|
125
123
|
idempotencyKey?: string;
|
|
126
124
|
|
package/src/internal/shims.ts
CHANGED
package/src/internal/types.ts
CHANGED
package/src/internal/uploads.ts
CHANGED
|
@@ -137,14 +137,11 @@ export const createForm = async <T = Record<string, unknown>>(
|
|
|
137
137
|
return form;
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
//
|
|
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) ||
|
|
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 (
|
|
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
|
|
|
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 {}
|