@veryfront/ext-llm-openai 0.1.1260-rc.19874 → 0.1.1260

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.
@@ -155,7 +155,7 @@ export async function* streamOpenAICompatibleParts(stream, context = {}) {
155
155
  let sawDone = false;
156
156
  const toolArgumentBudget = {
157
157
  bytes: 0,
158
- fragments: 0,
158
+ emptyFragments: 0,
159
159
  };
160
160
  function* processEvent(event) {
161
161
  if (event === "[DONE]") {
@@ -144,7 +144,7 @@ export async function* streamOpenAIResponsesParts(stream, context = {}) {
144
144
  context.webSearchToolName !== undefined;
145
145
  const toolArgumentBudget = {
146
146
  bytes: 0,
147
- fragments: 0,
147
+ emptyFragments: 0,
148
148
  };
149
149
  let finishReason = null;
150
150
  let usage;
@@ -1,9 +1,15 @@
1
+ import { type StreamRetentionBudget } from "veryfront/provider/shared";
1
2
  export declare const MAX_OPENAI_STREAM_TOOL_ARGUMENT_BYTES = 1048576;
3
+ /** Zero-byte argument fragments accepted per tool call; see {@link appendOpenAIStreamToolArgument}. */
2
4
  export declare const MAX_OPENAI_STREAM_TOOL_ARGUMENT_FRAGMENTS = 4096;
3
- export type OpenAIStreamToolArgumentBudget = {
4
- bytes: number;
5
- fragments: number;
6
- };
5
+ export type OpenAIStreamToolArgumentBudget = StreamRetentionBudget;
6
+ /**
7
+ * Retain one streamed tool-argument fragment.
8
+ *
9
+ * Fragment count is chosen by the provider's tokenizer rather than by the
10
+ * caller, so arguments are bounded by UTF-8 bytes. Only zero-byte fragments,
11
+ * which never advance the byte budget, count against the fragment limit.
12
+ */
7
13
  export declare function appendOpenAIStreamToolArgument(budget: OpenAIStreamToolArgumentBudget, chunks: string[], fragment: string): "bytes" | "fragments" | undefined;
8
14
  export declare function joinOpenAIStreamToolArguments(chunks: readonly string[]): string;
9
15
  export declare function isJsonObjectText(value: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"openai-tool-input.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-openai/src/openai-tool-input.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qCAAqC,UAAY,CAAC;AAC/D,eAAO,MAAM,yCAAyC,OAAQ,CAAC;AAE/D,MAAM,MAAM,8BAA8B,GAAG;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,8BAA8B,EACtC,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,GAAG,WAAW,GAAG,SAAS,CA+BnC;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAE/E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOvD"}
1
+ {"version":3,"file":"openai-tool-input.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-openai/src/openai-tool-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,qCAAqC,UAAY,CAAC;AAC/D,uGAAuG;AACvG,eAAO,MAAM,yCAAyC,OAAQ,CAAC;AAE/D,MAAM,MAAM,8BAA8B,GAAG,qBAAqB,CAAC;AAOnE;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,8BAA8B,EACtC,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,GAAG,WAAW,GAAG,SAAS,CAMnC;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAE/E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOvD"}
@@ -1,33 +1,26 @@
1
+ import { reserveStreamRetention, } from "veryfront/provider/shared";
1
2
  export const MAX_OPENAI_STREAM_TOOL_ARGUMENT_BYTES = 1_048_576;
3
+ /** Zero-byte argument fragments accepted per tool call; see {@link appendOpenAIStreamToolArgument}. */
2
4
  export const MAX_OPENAI_STREAM_TOOL_ARGUMENT_FRAGMENTS = 4_096;
3
- const TOOL_ARGUMENT_ENCODER = new TextEncoder();
5
+ const TOOL_ARGUMENT_LIMITS = {
6
+ maxBytes: MAX_OPENAI_STREAM_TOOL_ARGUMENT_BYTES,
7
+ maxEmptyFragments: MAX_OPENAI_STREAM_TOOL_ARGUMENT_FRAGMENTS,
8
+ };
9
+ /**
10
+ * Retain one streamed tool-argument fragment.
11
+ *
12
+ * Fragment count is chosen by the provider's tokenizer rather than by the
13
+ * caller, so arguments are bounded by UTF-8 bytes. Only zero-byte fragments,
14
+ * which never advance the byte budget, count against the fragment limit.
15
+ */
4
16
  export function appendOpenAIStreamToolArgument(budget, chunks, fragment) {
5
- const fragmentBytes = TOOL_ARGUMENT_ENCODER.encode(fragment).byteLength;
6
- // Zero-byte fragments never advance the byte budget, so they are the only
7
- // ones that can arrive without bound -- and they are what the fragment cap
8
- // exists to stop. Both provider streams exercise it exactly that way, by
9
- // flooding empty deltas.
10
- //
11
- // Counting non-empty fragments here too made the cap bind long before the
12
- // byte budget: at typical delta sizes, 4096 fragments is roughly 2-8% of the
13
- // 1 MiB a tool call is nominally allowed, which left the byte limit
14
- // unreachable. Fragment count is chosen by the provider's tokenizer rather
15
- // than by the caller, so the same tool call passed or failed depending on how
16
- // the stream happened to be chunked.
17
- if (fragmentBytes === 0) {
18
- if (budget.fragments >= MAX_OPENAI_STREAM_TOOL_ARGUMENT_FRAGMENTS) {
19
- return "fragments";
20
- }
21
- budget.fragments++;
22
- return undefined;
23
- }
24
- if (fragmentBytes > MAX_OPENAI_STREAM_TOOL_ARGUMENT_BYTES - budget.bytes) {
17
+ const overflow = reserveStreamRetention(budget, fragment, TOOL_ARGUMENT_LIMITS);
18
+ if (overflow === "empty-fragments")
19
+ return "fragments";
20
+ if (overflow === "bytes")
25
21
  return "bytes";
26
- }
27
- // Content is bounded by bytes: every fragment kept here is at least one byte,
28
- // so the array cannot outgrow the byte budget.
29
- budget.bytes += fragmentBytes;
30
- chunks.push(fragment);
22
+ if (fragment.length > 0)
23
+ chunks.push(fragment);
31
24
  return undefined;
32
25
  }
33
26
  export function joinOpenAIStreamToolArguments(chunks) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veryfront/ext-llm-openai",
3
- "version": "0.1.1260-rc.19874",
3
+ "version": "0.1.1260",
4
4
  "description": "Veryfront first-party extension package for ext-llm-openai",
5
5
  "keywords": [
6
6
  "veryfront",
@@ -45,7 +45,7 @@
45
45
  "capabilities": []
46
46
  },
47
47
  "peerDependencies": {
48
- "veryfront": "^0.1.1260-rc.19874"
48
+ "veryfront": "^0.1.1260"
49
49
  },
50
50
  "type": "module",
51
51
  "types": "./esm/extensions/ext-llm-openai/src/index.d.ts",
@@ -55,5 +55,5 @@
55
55
  "NOTICE",
56
56
  "README.md"
57
57
  ],
58
- "gitHead": "526feaa862e0e890ce7c265d292ade059562b2f0"
58
+ "gitHead": "f9a278ca0498b52b524523e79c2af0deb42699c5"
59
59
  }