@acosmi/sdk-ts 2.19.2 → 2.19.4
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 +20 -0
- package/dist/browser/index.mjs +433 -351
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.mjs +433 -351
- package/dist/index.mjs.map +1 -1
- package/dist/node/adapters/anthropic.cjs +0 -7
- package/dist/node/adapters/anthropic.cjs.map +1 -1
- package/dist/node/adapters/anthropic.d.cts +1 -1
- package/dist/node/adapters/anthropic.d.ts +1 -1
- package/dist/node/adapters/anthropic.mjs +0 -7
- package/dist/node/adapters/anthropic.mjs.map +1 -1
- package/dist/node/adapters/openai.cjs +115 -25
- package/dist/node/adapters/openai.cjs.map +1 -1
- package/dist/node/adapters/openai.d.cts +2 -2
- package/dist/node/adapters/openai.d.ts +2 -2
- package/dist/node/adapters/openai.mjs +115 -25
- package/dist/node/adapters/openai.mjs.map +1 -1
- package/dist/node/{index-CqxPqbsl.d.cts → format-DWA12pVT.d.cts} +35 -27
- package/dist/node/{index-CqxPqbsl.d.ts → format-DWA12pVT.d.ts} +35 -27
- package/dist/node/index.cjs +434 -351
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +84 -10
- package/dist/node/index.d.ts +84 -10
- package/dist/node/index.mjs +433 -351
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/{openai-mkTSir6E.d.ts → openai-Cuu_DPxM.d.cts} +34 -4
- package/dist/node/{openai-Ce85qh14.d.cts → openai-DsbJUOOW.d.ts} +34 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## 2.19.4
|
|
2
|
+
|
|
3
|
+
- Stop dropping the OpenAI-line streaming usage tail frame. With `stream_options.include_usage: true` the upstream sends content frames, then the `finish_reason` frame, then `{"choices":[],"usage":{...}}`, then `data: [DONE]`. The stream converter discarded every frame without `choices`, and it had already emitted `message_delta` (without usage) and `message_stop` on the `finish_reason` frame, so no OpenAI-line turn streamed through `chatMessagesStream` ever carried usage and consumers counted it as zero. The converter now records the usage object of any frame, with or without `choices` (later frames override earlier ones), and puts it in the `message_delta` that immediately precedes the single `message_stop`.
|
|
4
|
+
- Content blocks are still closed on the `finish_reason` frame, but when no usage has been seen yet, `message_delta` and `message_stop` wait for the first of: a frame carrying usage, `data: [DONE]`, or the end of the body. The new `OpenAIStreamConverter.flush()` emits that deferred close at end of stream; `chatMessagesStream` calls it when the body ends without `[DONE]`, and code that drives the converter directly should do the same. `flush()` never fabricates a close for a stream that never delivered `finish_reason`, and no path emits `message_stop` twice.
|
|
5
|
+
- The streaming usage mapping is exactly the non-streaming one: `prompt_tokens` to `input_tokens` and `completion_tokens` to `output_tokens`. Cached-token and reasoning-token details are neither mapped nor netted out; normalizing usage semantics belongs to the gateway. A count that is missing or not a finite number is omitted rather than written as 0. `OpenAIStreamChunk.usage` is now typed as `OpenAIStreamUsage | null`, with optional counts and the detail objects.
|
|
6
|
+
- Fix the `@acosmi/sdk-ts/adapters/openai` and `@acosmi/sdk-ts/adapters/anthropic` subpath entries, which threw as soon as they were loaded: `OpenAIAdapter is not a constructor` / `AnthropicAdapter is not a constructor` under Node ESM and CJS, `undefined is not a constructor` under Bun. Both adapter implementations took `ProviderFormat` from the adapters barrel, and the barrel constructs both adapters at module top level. With a subpath as the entry, the adapter module was evaluated first and pulled in the barrel, whose top-level `new` then ran before the adapter class had been defined. The root entry `@acosmi/sdk-ts` loads the barrel first and was not affected; the published 2.19.3 package fails the same way. `ProviderFormat` and `ProviderAdapter` now live in a leaf module that imports no adapter implementation, and every entry exports the same names as before. `test:pack` now also loads every `exports` subpath that declares an `import` or `require` condition, each in a fresh Node process, with `import()` and `require()` respectively; before, it only type-checked from the consumer side and never loaded any entry at runtime.
|
|
7
|
+
- Tolerate a stream `choice` that carries no `delta`. Some compatible implementations send `{"choices":[{"index":0}]}` to say "channel 0 is still there" on a frame with no increment; the converter read `choice.delta.reasoning_content` straight away, and the resulting `TypeError` tore through the whole `for-await` chain and failed the turn. Such a choice is now treated as an empty delta: zero events, no error, the stream keeps running, and `finish_reason` / `usage` on the same frame are still handled. `OpenAIStreamChoice.delta` is now optional, matching what the wire actually sends.
|
|
8
|
+
- Stop throwing on a non-streaming response that carries no `choices`. Both `parseResponse` and `parseOpenAIResponseToAnthropic` read `oai.choices.length` without a guard, so the whole response died - including the `id`, `model` and `usage` that had in fact arrived. Missing `choices` is now treated as an empty array on both paths: no content blocks, no error, `stop_reason` left empty rather than invented, and every other field converted as before. `OpenAIChatResponse.choices` is now optional. This is the fourth known site of one recurring mistake - a wire type declaring a key required that the wire genuinely omits - after `OpenAIStreamChunk.choices`, `OpenAIStreamChoice.delta` and `OpenAIChatResponse.usage`.
|
|
9
|
+
- Stop throwing on a non-streaming response that carries no `usage`. Both `parseResponse` and `parseOpenAIResponseToAnthropic` read `oai.usage.prompt_tokens` without a guard, so a response whose content, `finish_reason` and `tool_calls` were all perfectly usable was killed outright just because the upstream does not meter. Missing usage now counts as 0 on both paths and everything else converts as before; `OpenAIChatResponse.usage` is now optional.
|
|
10
|
+
- Fix block indexes when text arrives before `reasoning_content`. The thinking branch neither closed an open text block nor advanced the block index, so both `content_block_start` events landed on index 0 while the `textStarted / else if thinking` close only ever reached the text block - the thinking block was never closed. The thinking branch now mirrors the text and `tool_calls` branches and closes an open text block first, so at most one non-tool block is open at a time. This is the other half of the invariant the `thinking` then `tool_calls` fix established.
|
|
11
|
+
- Add `WindowLimitStatus.fiveHourSoftContinuing?: boolean`, the gateway's server-synthesized flag meaning the window is used up but the user's "continue" switch is letting requests through. New gateways always send it and older gateways omit it, so absence does not mean `false`. Type only.
|
|
12
|
+
- Add `WindowLimitStatus.inflightHeldCredits?: number | null`, the micro-Credits in that window currently held by in-progress requests and not yet settled. `usedCredits` counts settled usage only, while admission counts settled usage plus in-flight holds; this field is the difference. Absent or `null` means unknown (an older gateway, or the lookup failed), not 0; `0` means nothing is in flight. Type only.
|
|
13
|
+
- Add `QuotaSummary.subscriptionPool?: QuotaSummarySubscriptionPool` (`quota`, `used`, `remaining`, optional `expiresAt`, `unit`), derived by the gateway from alive COMMERCIAL buckets. Amounts are in micro-Credits (divide by 1000 for Credits). The field is absent on older gateways and when there is no alive paid bucket; do not read absence as 0. Type only.
|
|
14
|
+
|
|
15
|
+
## 2.19.3
|
|
16
|
+
|
|
17
|
+
- Surface gateway stream failures on the OpenAI line instead of crashing on them. The gateway emits its structured error frame with `event: failed`, but the OpenAI branch of `chatMessagesStream` captured the SSE event name and never read it, so the error frame reached the OpenAI chunk converter and died on `chunk.choices.length` - replacing the real upstream cause with an unrelated TypeError. That branch now routes `failed` and `error` frames through the existing `parseStreamError`, exactly as `chatStreamWithUsage` already did.
|
|
18
|
+
- Guard the OpenAI stream converter against data frames that carry no `choices` (gateway error frames, usage-only tail frames from some compatible implementations), and mark `OpenAIStreamChunk.choices` optional - the type declared it required while the wire genuinely omits it, which is where the TypeError came from.
|
|
19
|
+
- No behavior change on the Anthropic line, and no change to request building.
|
|
20
|
+
|
|
1
21
|
## 2.19.2
|
|
2
22
|
|
|
3
23
|
- Preserve catalog-supported low, medium, xhigh, and max thinking levels through both chat adapters.
|