@veryfront/ext-llm-google 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.
@@ -1 +1 @@
1
- {"version":3,"file":"google-stream.d.ts","sourceRoot":"","sources":["../src/google-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,YAAY,EAElB,MAAM,2BAA2B,CAAC;AAiBnC,eAAO,MAAM,0BAA0B,QAAkB,CAAC;AAC1D,eAAO,MAAM,gCAAgC,QAAkB,CAAC;AAChE,eAAO,MAAM,+BAA+B,QAAqC,CAAC;AAClF,eAAO,MAAM,+BAA+B,OAAQ,CAAC;AAgBrD,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,OAAO,GACX,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAgBlD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CA4B7E;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAQjG;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAY5F;AAED,KAAK,mBAAmB,GAAG;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AA8BF,wBAAuB,2BAA2B,CAChD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,OAAO,GAAE,mBAAwB,GAChC,aAAa,CAAC,OAAO,CAAC,CA2tBxB"}
1
+ {"version":3,"file":"google-stream.d.ts","sourceRoot":"","sources":["../src/google-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,YAAY,EAGlB,MAAM,2BAA2B,CAAC;AAiBnC,eAAO,MAAM,0BAA0B,QAAkB,CAAC;AAC1D,eAAO,MAAM,gCAAgC,QAAkB,CAAC;AAChE,eAAO,MAAM,+BAA+B,QAAqC,CAAC;AAClF,eAAO,MAAM,+BAA+B,OAAQ,CAAC;AAgBrD,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,OAAO,GACX,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAgBlD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CA4B7E;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAQjG;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAY5F;AAED,KAAK,mBAAmB,GAAG;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AA8BF,wBAAuB,2BAA2B,CAChD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,OAAO,GAAE,mBAAwB,GAChC,aAAa,CAAC,OAAO,CAAC,CAywBxB"}
@@ -1,4 +1,4 @@
1
- import { mergeUsage, parseFinalSseChunk, parseSseChunk, ProviderRequestError, readRecord, stringifyJsonValue, } from "veryfront/provider/shared";
1
+ import { mergeUsage, parseFinalSseChunk, parseSseChunk, ProviderRequestError, readRecord, StreamFragmentBuffer, stringifyJsonValue, } from "veryfront/provider/shared";
2
2
  import { createGoogleToolCallCorrelationRegistry, GOOGLE_CODE_EXECUTION_TOOL_NAME, googleCodeExecutionInput, googleCodeExecutionOutput, readGoogleCodeExecutionResult, readGoogleExecutableCode, readGooglePartDataField, } from "./google-content-parts.js";
3
3
  import { mergeGoogleGroundingMetadata } from "./google-grounding-metadata.js";
4
4
  import { createGoogleProviderMetadata, MAX_GOOGLE_PROVIDER_METADATA_BYTES, readGoogleThoughtSignature, } from "./google-thought-signatures.js";
@@ -107,6 +107,13 @@ export async function* streamGoogleCompatibleParts(stream, context = {}) {
107
107
  const pendingAnonymousCodeExecutions = [];
108
108
  const toolCallRegistry = createGoogleToolCallCorrelationRegistry();
109
109
  const rawAssistantParts = [];
110
+ // Original stream position of each retained part. Fallback tool-call IDs and
111
+ // replay derive from these, so merging text chunks never changes an ID.
112
+ const rawAssistantPartPositions = [];
113
+ let nextRawPartPosition = 0;
114
+ // Adjacent unsigned text chunks share one raw part, so replay state grows
115
+ // with content rather than with how finely Gemini chunked the stream.
116
+ const rawTextRuns = [];
110
117
  let retainedStateBytes = 0;
111
118
  let retainedStateItems = 0;
112
119
  let reasoningId = null;
@@ -142,8 +149,31 @@ export async function* streamGoogleCompatibleParts(stream, context = {}) {
142
149
  }
143
150
  reserveRetainedItem("raw candidate part");
144
151
  reserveRetainedBytes(serialized, "raw candidate part");
152
+ rawAssistantPartPositions.push(nextRawPartPosition++);
145
153
  return rawAssistantParts.push(part) - 1;
146
154
  };
155
+ const isMergeableTextPart = (part) => typeof part.text === "string" &&
156
+ Object.keys(part).every((key) => key === "text" || key === "thought");
157
+ const retainRawTextPart = (part, text) => {
158
+ const run = rawTextRuns.at(-1);
159
+ if (run !== undefined &&
160
+ run.index === rawAssistantParts.length - 1 &&
161
+ run.part.thought === part.thought &&
162
+ isMergeableTextPart(part)) {
163
+ // Empty chunks advance no byte budget, so they count as items.
164
+ if (text.length === 0)
165
+ reserveRetainedItem("empty candidate text part");
166
+ // Charge the escaped form, as retainRawAssistantPart does for a whole part.
167
+ reserveRetainedBytes(JSON.stringify(text).slice(1, -1), "raw candidate part");
168
+ run.text.append(text);
169
+ nextRawPartPosition++;
170
+ return;
171
+ }
172
+ const index = retainRawAssistantPart(part);
173
+ if (isMergeableTextPart(part)) {
174
+ rawTextRuns.push({ index, part, text: new StreamFragmentBuffer(text) });
175
+ }
176
+ };
147
177
  const reserveCorrelation = (issue, ...values) => {
148
178
  reserveRetainedItem(issue);
149
179
  for (const value of values)
@@ -289,8 +319,8 @@ export async function* streamGoogleCompatibleParts(stream, context = {}) {
289
319
  if (dataField === "text" && partText === undefined) {
290
320
  throw invalidGoogleStream(context, "candidate text part was malformed");
291
321
  }
292
- if (dataField === "text") {
293
- retainRawAssistantPart(part);
322
+ if (partText !== undefined) {
323
+ retainRawTextPart(part, partText);
294
324
  }
295
325
  if (partText !== undefined && part.thought === true) {
296
326
  if (reasoningId &&
@@ -382,7 +412,7 @@ export async function* streamGoogleCompatibleParts(stream, context = {}) {
382
412
  }
383
413
  let toolCallId;
384
414
  try {
385
- toolCallId = toolCallRegistry.registerFunctionCall(rawPartIndex, providerId);
415
+ toolCallId = toolCallRegistry.registerFunctionCall(nextRawPartPosition, providerId);
386
416
  }
387
417
  catch {
388
418
  throw invalidGoogleStream(context, "candidate tool call id was duplicated");
@@ -662,9 +692,13 @@ export async function* streamGoogleCompatibleParts(stream, context = {}) {
662
692
  ...(reasoningSignature !== undefined ? { signature: reasoningSignature } : {}),
663
693
  };
664
694
  }
695
+ for (const run of rawTextRuns) {
696
+ rawAssistantParts[run.index] = { ...run.part, text: run.text.toString() };
697
+ }
665
698
  let providerMetadata;
666
699
  try {
667
- providerMetadata = createGoogleProviderMetadata(rawAssistantParts, groundingMetadata);
700
+ const mergedTextChunks = rawAssistantPartPositions.some((position, index) => position !== index);
701
+ providerMetadata = createGoogleProviderMetadata(rawAssistantParts, groundingMetadata, mergedTextChunks ? rawAssistantPartPositions : undefined);
668
702
  }
669
703
  catch {
670
704
  // The stream accounts for retained raw parts and correlation state under
@@ -1 +1 @@
1
- {"version":3,"file":"google-thought-signatures.d.ts","sourceRoot":"","sources":["../src/google-thought-signatures.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,kCAAkC,QAAkB,CAAC;AA6OlE,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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AAS,CASpB;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,uBAAuB,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA2CrC;AAsGD,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAC1C,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACpD,wBAAwB,GAAG,SAAS,CAiCtC;AAED,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACpD,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,SAAS,CAEhD;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,mBAAmB,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAC3D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAqErC"}
@@ -4,6 +4,11 @@ const GOOGLE_METADATA_KEY = "google";
4
4
  const RAW_ASSISTANT_PARTS_KEY = "rawAssistantParts";
5
5
  const RAW_ASSISTANT_PART_INDEXES_KEY = "rawAssistantPartIndexes";
6
6
  const GROUNDING_METADATA_KEY = "groundingMetadata";
7
+ /**
8
+ * Maximum raw assistant parts retained for replay. Part indexes record each
9
+ * part's original stream position and are only required to increase: adjacent
10
+ * text chunks are merged into one part, so a position can exceed this count.
11
+ */
7
12
  const MAX_GOOGLE_RAW_ASSISTANT_PARTS = 4_096;
8
13
  export const MAX_GOOGLE_PROVIDER_METADATA_BYTES = 8 * 1024 * 1024;
9
14
  const GOOGLE_PROVIDER_METADATA_SNAPSHOT_OPTIONS = {
@@ -312,8 +317,7 @@ function validateGoogleRawAssistantPartIndexes(value, partCount) {
312
317
  if (typeof index !== "number" ||
313
318
  !Number.isSafeInteger(index) ||
314
319
  index <= previous ||
315
- index < 0 ||
316
- index >= MAX_GOOGLE_RAW_ASSISTANT_PARTS) {
320
+ index < 0) {
317
321
  throw new TypeError("Google raw assistant part indexes must be increasing safe integers");
318
322
  }
319
323
  previous = index;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veryfront/ext-llm-google",
3
- "version": "0.1.1260-rc.19874",
3
+ "version": "0.1.1260",
4
4
  "description": "Veryfront first-party extension package for ext-llm-google",
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/index.d.ts",
@@ -55,5 +55,5 @@
55
55
  "NOTICE",
56
56
  "README.md"
57
57
  ],
58
- "gitHead": "526feaa862e0e890ce7c265d292ade059562b2f0"
58
+ "gitHead": "f9a278ca0498b52b524523e79c2af0deb42699c5"
59
59
  }