diff --git a/.release-please-manifest.json b/.release-please-manifest.json index affd1ab3d..6c8775576 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "5.1.0" + ".": "5.1.1" } diff --git a/CHANGELOG.md b/CHANGELOG.md index ea12ff509..6acc4963f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 5.1.1 (2025-06-05) + +Full Changelog: [v5.1.0...v5.1.1](https://github.com/openai/openai-node/compare/v5.1.0...v5.1.1) + +### Bug Fixes + +* **assistants:** handle thread.run.incomplete while streaming ([8f5e7f3](https://github.com/openai/openai-node/commit/8f5e7f3ffaad7bdd0424743eb68a63f918dbabb8)) + + +### Chores + +* **docs:** use top-level-await in example snippets ([065d3b0](https://github.com/openai/openai-node/commit/065d3b08b29e10d7af58bb66816245f71f386833)) +* **internal:** fix readablestream types in node 20 ([771ae81](https://github.com/openai/openai-node/commit/771ae818c32d855778c3847d9005efb80b0a8cd5)) + ## 5.1.0 (2025-06-03) Full Changelog: [v5.0.2...v5.1.0](https://github.com/openai/openai-node/compare/v5.0.2...v5.1.0) diff --git a/README.md b/README.md index 0f4449006..77a98746c 100644 --- a/README.md +++ b/README.md @@ -132,22 +132,18 @@ a subclass of `APIError` will be thrown: ```ts -async function main() { - const job = await client.fineTuning.jobs - .create({ model: 'gpt-4o', training_file: 'file-abc123' }) - .catch(async (err) => { - if (err instanceof OpenAI.APIError) { - console.log(err.request_id); - console.log(err.status); // 400 - console.log(err.name); // BadRequestError - console.log(err.headers); // {server: 'nginx', ...} - } else { - throw err; - } - }); -} - -main(); +const job = await client.fineTuning.jobs + .create({ model: 'gpt-4o', training_file: 'file-abc123' }) + .catch(async (err) => { + if (err instanceof OpenAI.APIError) { + console.log(err.request_id); + console.log(err.status); // 400 + console.log(err.name); // BadRequestError + console.log(err.headers); // {server: 'nginx', ...} + } else { + throw err; + } + }); ``` Error codes are as follows: diff --git a/ecosystem-tests/cli.ts b/ecosystem-tests/cli.ts index 9781c2b03..4ca7a0e4e 100644 --- a/ecosystem-tests/cli.ts +++ b/ecosystem-tests/cli.ts @@ -562,11 +562,6 @@ async function withChdir(newDir: string, fn: () => Promise): Promise { } } -function checkNever(x: never, detail: any = x): never { - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - throw new Error(`checkNever: impossible to call: ${detail}`); -} - async function pathExists(path: string) { try { await fs.access(path); diff --git a/ecosystem-tests/proxy.ts b/ecosystem-tests/proxy.ts index ab05685a3..756a6c013 100644 --- a/ecosystem-tests/proxy.ts +++ b/ecosystem-tests/proxy.ts @@ -19,9 +19,9 @@ async function startProxy() { await new Promise((resolve) => proxy.listen(0, '127.0.0.1', resolve)); - console.log(proxy.address()!.toString()) + console.log(proxy.address()!.toString()); return () => { - proxy.close() - } + proxy.close(); + }; } diff --git a/eslint.config.mjs b/eslint.config.mjs index 33cb4be6f..f816a1613 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -10,7 +10,7 @@ export default tseslint.config( parserOptions: { sourceType: 'module' }, }, files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.js', '**/*.mjs', '**/*.cjs'], - ignores: ['dist/', 'ecosystem-tests/'], + ignores: ['dist/'], plugins: { '@typescript-eslint': tseslint.plugin, 'unused-imports': unusedImports, @@ -34,7 +34,7 @@ export default tseslint.config( }, }, { - files: ['tests/**', 'examples/**'], + files: ['tests/**', 'examples/**', 'ecosystem-tests/**'], rules: { 'no-restricted-imports': 'off', }, diff --git a/jsr.json b/jsr.json index 26b7bbd20..bd734c294 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@openai/openai", - "version": "5.1.0", + "version": "5.1.1", "exports": { ".": "./index.ts", "./helpers/zod": "./helpers/zod.ts", diff --git a/package.json b/package.json index 3c7181019..1e425a912 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openai", - "version": "5.1.0", + "version": "5.1.1", "description": "The official TypeScript library for the OpenAI API", "author": "OpenAI ", "types": "dist/index.d.ts", diff --git a/scripts/build b/scripts/build index d268d6627..beb4da8f7 100755 --- a/scripts/build +++ b/scripts/build @@ -37,8 +37,6 @@ npm exec tsc-multi # when building .mjs node scripts/utils/fix-index-exports.cjs cp tsconfig.dist-src.json dist/src/tsconfig.json -cp src/internal/shim-types.d.ts dist/internal/shim-types.d.ts -cp src/internal/shim-types.d.ts dist/internal/shim-types.d.mts node scripts/utils/postprocess-files.cjs diff --git a/scripts/lint b/scripts/lint index 3ffb78a64..97a3df83e 100755 --- a/scripts/lint +++ b/scripts/lint @@ -19,3 +19,5 @@ node scripts/utils/attw-report.cjs echo "==> Running publint" ./node_modules/.bin/publint dist +echo "==> Running jsr publish --dry-run" +(cd dist-deno && npx jsr publish --dry-run --allow-dirty) diff --git a/src/internal/shim-types.d.ts b/src/internal/shim-types.d.ts deleted file mode 100644 index fe48144fa..000000000 --- a/src/internal/shim-types.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -/** - * Shims for types that we can't always rely on being available globally. - * - * Note: these only exist at the type-level, there is no corresponding runtime - * version for any of these symbols. - */ - -/** - * In order to properly access the global `NodeJS` type, if it's available, we - * need to make use of declaration shadowing. Without this, any checks for the - * presence of `NodeJS.ReadableStream` will fail. - */ -declare namespace NodeJS { - interface ReadableStream {} -} - -type HasProperties = keyof T extends never ? false : true; - -// @ts-ignore -type _ReadableStream = - // @ts-ignore - HasProperties extends true ? NodeJS.ReadableStream : ReadableStream; - -// @ts-ignore -declare const _ReadableStream: unknown extends typeof ReadableStream ? never : typeof ReadableStream; -export { _ReadableStream as ReadableStream }; diff --git a/src/internal/shim-types.ts b/src/internal/shim-types.ts new file mode 100644 index 000000000..8ddf7b0ad --- /dev/null +++ b/src/internal/shim-types.ts @@ -0,0 +1,26 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +/** + * Shims for types that we can't always rely on being available globally. + * + * Note: these only exist at the type-level, there is no corresponding runtime + * version for any of these symbols. + */ + +type NeverToAny = T extends never ? any : T; + +/** @ts-ignore */ +type _DOMReadableStream = globalThis.ReadableStream; + +/** @ts-ignore */ +type _NodeReadableStream = import('stream/web').ReadableStream; + +type _ConditionalNodeReadableStream = + typeof globalThis extends { ReadableStream: any } ? never : _NodeReadableStream; + +type _ReadableStream = NeverToAny< + | ([0] extends [1 & _DOMReadableStream] ? never : _DOMReadableStream) + | ([0] extends [1 & _ConditionalNodeReadableStream] ? never : _ConditionalNodeReadableStream) +>; + +export type { _ReadableStream as ReadableStream }; diff --git a/src/internal/shims.ts b/src/internal/shims.ts index b1196d141..588ce43ab 100644 --- a/src/internal/shims.ts +++ b/src/internal/shims.ts @@ -7,8 +7,8 @@ * messages in cases where an environment isn't fully supported. */ -import { type Fetch } from './builtin-types'; -import { type ReadableStream } from './shim-types'; +import type { Fetch } from './builtin-types'; +import type { ReadableStream } from './shim-types'; export function getDefaultFetch(): Fetch { if (typeof fetch !== 'undefined') { diff --git a/src/lib/AssistantStream.ts b/src/lib/AssistantStream.ts index 7d6cb2d77..bb2a2b5b3 100644 --- a/src/lib/AssistantStream.ts +++ b/src/lib/AssistantStream.ts @@ -18,6 +18,7 @@ import { RunSubmitToolOutputsParamsBase, RunSubmitToolOutputsParamsStreaming, } from '../resources/beta/threads/runs/runs'; +import { type ReadableStream } from '../internal/shim-types'; import { Stream } from '../streaming'; import { APIUserAbortError, OpenAIError } from '../error'; import { @@ -718,6 +719,7 @@ export class AssistantStream #handleRun(this: AssistantStream, event: RunStreamEvent) { this.#currentRunSnapshot = event.data; + switch (event.event) { case 'thread.run.created': break; @@ -730,6 +732,7 @@ export class AssistantStream case 'thread.run.failed': case 'thread.run.completed': case 'thread.run.expired': + case 'thread.run.incomplete': this.#finalRun = event.data; if (this.#currentToolCall) { this._emit('toolCallDone', this.#currentToolCall); diff --git a/src/lib/ChatCompletionStream.ts b/src/lib/ChatCompletionStream.ts index 832fca4f3..5036d4f60 100644 --- a/src/lib/ChatCompletionStream.ts +++ b/src/lib/ChatCompletionStream.ts @@ -17,6 +17,7 @@ import { AbstractChatCompletionRunner, type AbstractChatCompletionRunnerEvents, } from './AbstractChatCompletionRunner'; +import { type ReadableStream } from '../internal/shim-types'; import { Stream } from '../streaming'; import OpenAI from '../index'; import { ParsedChatCompletion } from '../resources/chat/completions'; diff --git a/src/lib/ChatCompletionStreamingRunner.ts b/src/lib/ChatCompletionStreamingRunner.ts index 78637856e..eb8fcc357 100644 --- a/src/lib/ChatCompletionStreamingRunner.ts +++ b/src/lib/ChatCompletionStreamingRunner.ts @@ -3,6 +3,7 @@ import { type ChatCompletionCreateParamsStreaming, } from '../resources/chat/completions'; import { RunnerOptions, type AbstractChatCompletionRunnerEvents } from './AbstractChatCompletionRunner'; +import { type ReadableStream } from '../internal/shim-types'; import { RunnableTools, type BaseFunctionsArgs } from './RunnableFunction'; import { ChatCompletionSnapshot, ChatCompletionStream } from './ChatCompletionStream'; import OpenAI from '../index'; diff --git a/src/version.ts b/src/version.ts index 0d43855fe..08dfa7aba 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '5.1.0'; // x-release-please-version +export const VERSION = '5.1.1'; // x-release-please-version