acp-kernel 0.0.75 → 0.0.76-pr.325.190
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/dist/compress-tools.d.ts +191 -0
- package/dist/compress-tools.d.ts.map +1 -1
- package/dist/compress.d.ts.map +1 -1
- package/dist/index.js +164 -44
- package/dist/index.js.map +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/turn-integrity.d.ts +28 -0
- package/dist/turn-integrity.d.ts.map +1 -1
- package/dist/wire/bili-message.d.ts +10 -0
- package/dist/wire/bili-message.d.ts.map +1 -1
- package/dist/wire/formats.d.ts +1 -1
- package/dist/wire/formats.d.ts.map +1 -1
- package/dist/wire/google.d.ts +96 -0
- package/dist/wire/google.d.ts.map +1 -0
- package/dist/wire/index.d.ts +1 -0
- package/dist/wire/index.d.ts.map +1 -1
- package/dist/wire/index.js +310 -1
- package/dist/wire/index.js.map +1 -1
- package/dist/wire/strip-images.d.ts +1 -1
- package/dist/wire/strip-images.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/recommend.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../src/recommend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,MAAM,EACN,aAAa,EACb,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"recommend.d.ts","sourceRoot":"","sources":["../src/recommend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,MAAM,EACN,aAAa,EACb,WAAW,EAEZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAiBnD,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAE3D;AAgBD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,WAAW,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA2B,GACzD,GAAG,CAAC,MAAM,CAAC,CAwDb;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,MAAM,EACd,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAC/B,WAAW,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAA2B,GACzD,aAAa,CAyKf;AAkCD;;;;;;;;;;gFAUgF;AAChF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,iBAAiB,EAAE,EAC3B,QAAQ,EAAE,MAAM,GACf,iBAAiB,EAAE,CAmBrB"}
|
package/dist/turn-integrity.d.ts
CHANGED
|
@@ -20,4 +20,32 @@ import type { CoreMessage } from "./types.js";
|
|
|
20
20
|
* @returns disjoint member-id arrays; a message appears in at most one group.
|
|
21
21
|
*/
|
|
22
22
|
export declare function computeTurnGroups(messages: CoreMessage[]): string[][];
|
|
23
|
+
/** Which folded ids the rebuild cannot keep folded, and how many turns and
|
|
24
|
+
* call/result pairs that covers. */
|
|
25
|
+
export interface IntegrityWithdrawals {
|
|
26
|
+
withdrawn: Set<string>;
|
|
27
|
+
splitTurnCount: number;
|
|
28
|
+
splitPairCount: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fold-integrity gate (#684): given the ids a fold removes from the visible
|
|
32
|
+
* stream, return the ids that must stay visible instead.
|
|
33
|
+
*
|
|
34
|
+
* - INV1 — a kept assistant tool-call must keep its reasoning run, so a turn
|
|
35
|
+
* whose reasoning folds while a call of the same turn stays visible is
|
|
36
|
+
* withdrawn wholesale (all members stay visible).
|
|
37
|
+
* - INV2 — a tool-call and its tool-result are one exchange: a pair the fold
|
|
38
|
+
* would split is withdrawn together.
|
|
39
|
+
*
|
|
40
|
+
* The two invariants feed each other. Withdrawing a call for INV2 leaves a turn
|
|
41
|
+
* whose reasoning still folds while its call now stays visible — exactly the
|
|
42
|
+
* INV1 split — and withdrawing a turn for INV1 can strand a result whose call
|
|
43
|
+
* survived outside the turn. One pass in a fixed order misses both, so the gate
|
|
44
|
+
* repeats until nothing changes; a turn or pair is acted on once and reported
|
|
45
|
+
* once.
|
|
46
|
+
*
|
|
47
|
+
* The reverse direction stays allowed (#564): reasoning and text may stay
|
|
48
|
+
* visible while the call and its result fold, since that leaves a valid stream.
|
|
49
|
+
*/
|
|
50
|
+
export declare function computeIntegrityWithdrawals(messages: CoreMessage[], foldedIds: ReadonlySet<string>): IntegrityWithdrawals;
|
|
23
51
|
//# sourceMappingURL=turn-integrity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-integrity.d.ts","sourceRoot":"","sources":["../src/turn-integrity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,EAAE,CA2ErE"}
|
|
1
|
+
{"version":3,"file":"turn-integrity.d.ts","sourceRoot":"","sources":["../src/turn-integrity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,EAAE,CA2ErE;AAED;qCACqC;AACrC,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,WAAW,EAAE,EACvB,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,GAC7B,oBAAoB,CAuEtB"}
|
|
@@ -32,10 +32,20 @@ export interface BiliMessage extends CoreMessage {
|
|
|
32
32
|
/** Responses API: the original input item (for input_image, or a raw
|
|
33
33
|
* function_call / function_call_output we pass through). */
|
|
34
34
|
rawResponsesItem?: unknown;
|
|
35
|
+
/** Google/Gemini: the original content parts of this message, in wire
|
|
36
|
+
* order (inlineData/fileData, executableCode, functionCall/Response ids,
|
|
37
|
+
* thought parts and unknown future part types). coreToGoogle rebuilds
|
|
38
|
+
* the content from these when present, so parts the core does not model
|
|
39
|
+
* survive a round-trip. */
|
|
40
|
+
rawGoogleParts?: unknown[];
|
|
35
41
|
/** Anthropic thinking signature. Anthropic verifies thinking+signature
|
|
36
42
|
* pairs; without it the request is rejected. Stored alongside the
|
|
37
43
|
* reasoning text so coreToAnthropic can reattach it. */
|
|
38
44
|
thinkingSignature?: string;
|
|
45
|
+
/** Google/Gemini thought signature (thoughtSignature). Gemini 3 validates
|
|
46
|
+
* the signature of every replayed thought part, so a reasoning core
|
|
47
|
+
* carries it here for coreToGoogle to reattach. */
|
|
48
|
+
googleThoughtSignature?: string;
|
|
39
49
|
/** OpenAI reasoning_content (chain-of-thought from DeepSeek-R1, GLM-4.6
|
|
40
50
|
* thinking, Qwen-QwQ). These models require reasoning_content be echoed
|
|
41
51
|
* back on subsequent requests or the API returns HTTP 400; stored so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bili-message.d.ts","sourceRoot":"","sources":["../../src/wire/bili-message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CA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,CAAC,EAAE,OAAO,CAAC;IAC3B;iEAC6D;IAC7D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;gCAI4B;IAC5B,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC;IAC3B;;6DAEyD;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;wDAEoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;wCAGoC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;kDAK8C;IAC9C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;+EAC2E;IAC3E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;2EACuE;IACvE,YAAY,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;IACtC;;+CAE2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;6DACyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;yDAKqD;IACrD,qBAAqB,CAAC,EAAE,OAAO,EAAE,CAAC;CACrC;AAED;+EAC+E;AAC/E,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAEjE;AAED;;8DAE8D;AAC9D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAI3F"}
|
package/dist/wire/formats.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const WIRE_FORMATS: readonly ["anthropic", "openai", "responses"];
|
|
1
|
+
export declare const WIRE_FORMATS: readonly ["anthropic", "openai", "responses", "google"];
|
|
2
2
|
export type WireFormat = (typeof WIRE_FORMATS)[number];
|
|
3
3
|
export declare function isWireFormat(value: unknown): value is WireFormat;
|
|
4
4
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/wire/formats.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/wire/formats.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,yDAA0D,CAAC;AACpF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAKhE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAkCzE"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { BiliMessage } from "./bili-message.js";
|
|
2
|
+
export type GooglePart = {
|
|
3
|
+
text?: string;
|
|
4
|
+
thought?: boolean;
|
|
5
|
+
thoughtSignature?: string;
|
|
6
|
+
functionCall?: {
|
|
7
|
+
name: string;
|
|
8
|
+
args?: unknown;
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
11
|
+
functionResponse?: {
|
|
12
|
+
name: string;
|
|
13
|
+
response?: unknown;
|
|
14
|
+
id?: string;
|
|
15
|
+
parts?: GooglePart[];
|
|
16
|
+
};
|
|
17
|
+
inlineData?: {
|
|
18
|
+
mimeType: string;
|
|
19
|
+
data: string;
|
|
20
|
+
};
|
|
21
|
+
fileData?: {
|
|
22
|
+
fileUri: string;
|
|
23
|
+
mimeType?: string;
|
|
24
|
+
};
|
|
25
|
+
[k: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
export type GoogleContent = {
|
|
28
|
+
role?: string;
|
|
29
|
+
parts: GooglePart[];
|
|
30
|
+
};
|
|
31
|
+
export type GoogleFunctionDeclaration = {
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
parameters?: unknown;
|
|
35
|
+
parametersJsonSchema?: unknown;
|
|
36
|
+
response?: unknown;
|
|
37
|
+
[k: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
export type GoogleTool = {
|
|
40
|
+
functionDeclarations?: GoogleFunctionDeclaration[];
|
|
41
|
+
[k: string]: unknown;
|
|
42
|
+
};
|
|
43
|
+
export type GoogleSystemInstruction = {
|
|
44
|
+
parts?: GooglePart[];
|
|
45
|
+
role?: string;
|
|
46
|
+
};
|
|
47
|
+
export type GoogleRequestBody = {
|
|
48
|
+
contents: GoogleContent[];
|
|
49
|
+
systemInstruction?: GoogleSystemInstruction;
|
|
50
|
+
tools?: GoogleTool[];
|
|
51
|
+
toolConfig?: unknown;
|
|
52
|
+
generationConfig?: Record<string, unknown>;
|
|
53
|
+
cachedContent?: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
export type GoogleFlat = {
|
|
57
|
+
msgs: BiliMessage[];
|
|
58
|
+
systemText: string;
|
|
59
|
+
};
|
|
60
|
+
/** Hoist the system dimension out of the fold space. `systemInstruction` is
|
|
61
|
+
* host runtime state exactly like the openai codec's leading system prefix
|
|
62
|
+
* (see openaiToCore): its content varies across restarts, so keeping it
|
|
63
|
+
* inside the id space made every downstream fingerprint spanning it
|
|
64
|
+
* unstable, and a compress range that covered it deleted the model's system
|
|
65
|
+
* prompt from the rebuilt wire. The adapter re-injects it as
|
|
66
|
+
* `systemInstruction` at egress. */
|
|
67
|
+
export declare function googleSystemText(body: GoogleRequestBody): string;
|
|
68
|
+
/** Map a Gemini request body onto the kernel's message space. Mirrors
|
|
69
|
+
* openaiToCore's role handling: `content.role === "model"` is the assistant
|
|
70
|
+
* side, everything else the user side. A user content's functionResponse
|
|
71
|
+
* parts expand into `role:"tool"` cores emitted BEFORE that content's own
|
|
72
|
+
* user core — the client appends a second functionResponse to the previous
|
|
73
|
+
* user content instead of opening a new one, so those parts belong to the
|
|
74
|
+
* tool pair, not to the user text they sit next to. */
|
|
75
|
+
export declare function googleToCore(body: GoogleRequestBody): GoogleFlat;
|
|
76
|
+
/** Rebuild Gemini `contents` from kernel messages. Runs of same-side cores
|
|
77
|
+
* are merged into ONE content (Gemini rejects non-alternating roles): an
|
|
78
|
+
* assistant run becomes a single `{"role":"model"}` content whose parts are
|
|
79
|
+
* ordered reasoning, text, tool-call; a user-side run (user + tool-result)
|
|
80
|
+
* becomes a single `{"role":"user"}` content whose functionResponse parts
|
|
81
|
+
* lead. Mid-conversation system cores (host-synthetic; Gemini has no system
|
|
82
|
+
* role inside contents) ride on the user side as a text part. */
|
|
83
|
+
export declare function coreToGoogle(messages: BiliMessage[]): GoogleContent[];
|
|
84
|
+
/** Text-protocol/fallback system injection. `contents` has no top-level
|
|
85
|
+
* system slot, so the prompt becomes the first part of the leading user
|
|
86
|
+
* content, or a new leading user content when none is there. The adapter and
|
|
87
|
+
* the server inject the real system via `systemInstruction` instead (see the
|
|
88
|
+
* proxy's createGoogleAdapter) — this exists for the path where no system
|
|
89
|
+
* channel is wanted. */
|
|
90
|
+
export declare function injectGoogleSystem(contents: GoogleContent[], parts: string[]): GoogleContent[];
|
|
91
|
+
/** Extract the conversation dimension for Gemini: a client-provided session
|
|
92
|
+
* header if present (omp sends none for this protocol), else a content
|
|
93
|
+
* fingerprint of the first user content. See conversationSignalAnthropic for
|
|
94
|
+
* the full rationale. */
|
|
95
|
+
export declare function conversationSignalGoogle(body: GoogleRequestBody, headerValue?: string): string;
|
|
96
|
+
//# sourceMappingURL=google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/wire/google.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYrD,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CA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,aAAa,EAAE,CAAC;IAC1B,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE;;;;;;qCAMqC;AACrC,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAShE;AAED;;;;;;wDAMwD;AACxD,wBAAgB,YAAY,CAAC,IAAI,EAAE,iBAAiB,GAAG,UAAU,CA8HhE;AAED;;;;;;kEAMkE;AAClE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,aAAa,EAAE,CAsCrE;AAED;;;;;yBAKyB;AACzB,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EAAE,EACzB,KAAK,EAAE,MAAM,EAAE,GACd,aAAa,EAAE,CAUjB;AAED;;;0BAG0B;AAC1B,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,iBAAiB,EACvB,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAUR"}
|
package/dist/wire/index.d.ts
CHANGED
package/dist/wire/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wire/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wire/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
|
package/dist/wire/index.js
CHANGED
|
@@ -793,14 +793,290 @@ function subagentNamespace(identityValue, instructions) {
|
|
|
793
793
|
return defaultNamespaces.namespaceFor(identityValue, instructions);
|
|
794
794
|
}
|
|
795
795
|
|
|
796
|
+
// src/wire/google.ts
|
|
797
|
+
function googleSystemText(body) {
|
|
798
|
+
const parts = body.systemInstruction?.parts;
|
|
799
|
+
if (!Array.isArray(parts)) return "";
|
|
800
|
+
const texts = [];
|
|
801
|
+
for (const part of parts) {
|
|
802
|
+
if (typeof part.text === "string" && part.text.length > 0)
|
|
803
|
+
texts.push(part.text);
|
|
804
|
+
}
|
|
805
|
+
return texts.join("\n\n");
|
|
806
|
+
}
|
|
807
|
+
function googleToCore(body) {
|
|
808
|
+
const msgs = [];
|
|
809
|
+
const clusters = new ClusterCounter();
|
|
810
|
+
const unmatchedCalls = /* @__PURE__ */ new Map();
|
|
811
|
+
const contents = Array.isArray(body.contents) ? body.contents : [];
|
|
812
|
+
for (const content of contents) {
|
|
813
|
+
const parts = Array.isArray(content.parts) ? content.parts : [];
|
|
814
|
+
const isModel = content.role === "model";
|
|
815
|
+
for (const part of parts) {
|
|
816
|
+
const fr = part.functionResponse;
|
|
817
|
+
if (!fr || typeof fr.name !== "string") continue;
|
|
818
|
+
const text = jsonText(fr.response ?? {});
|
|
819
|
+
const wireId = typeof fr.id === "string" ? fr.id : void 0;
|
|
820
|
+
const queue = unmatchedCalls.get(fr.name);
|
|
821
|
+
let paired;
|
|
822
|
+
if (wireId) {
|
|
823
|
+
const i = queue ? queue.indexOf(wireId) : -1;
|
|
824
|
+
if (queue && i >= 0) queue.splice(i, 1);
|
|
825
|
+
} else if (queue && queue.length > 0) {
|
|
826
|
+
paired = queue.shift();
|
|
827
|
+
}
|
|
828
|
+
const base = deriveMessageId("tool", "tool-result", text, {
|
|
829
|
+
toolCallId: wireId ?? paired ?? "",
|
|
830
|
+
toolName: fr.name
|
|
831
|
+
});
|
|
832
|
+
const id = clusters.next(base);
|
|
833
|
+
msgs.push({
|
|
834
|
+
id,
|
|
835
|
+
role: "tool",
|
|
836
|
+
contentType: "tool-result",
|
|
837
|
+
toolName: fr.name,
|
|
838
|
+
// No wire id and nothing to pair with: the core's own id
|
|
839
|
+
// stands in, so the response is still identifiable and stable.
|
|
840
|
+
toolCallId: wireId ?? paired ?? id,
|
|
841
|
+
text,
|
|
842
|
+
rawGoogleParts: [part]
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
for (const part of parts) {
|
|
846
|
+
if (part.thought !== true || typeof part.text !== "string") continue;
|
|
847
|
+
const base = deriveMessageId("assistant", "reasoning", part.text);
|
|
848
|
+
msgs.push({
|
|
849
|
+
id: clusters.next(base),
|
|
850
|
+
role: "assistant",
|
|
851
|
+
contentType: "reasoning",
|
|
852
|
+
text: part.text,
|
|
853
|
+
rawGoogleParts: [part],
|
|
854
|
+
...signatureField("googleThoughtSignature", part.thoughtSignature)
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
const rest = parts.filter(isContentPart);
|
|
858
|
+
if (rest.length > 0) {
|
|
859
|
+
const text = textPartsOf(rest).map((p) => p.text ?? "").join("\n");
|
|
860
|
+
const inline = inlineDataOf(rest);
|
|
861
|
+
const base = deriveMessageId(
|
|
862
|
+
isModel ? "assistant" : "user",
|
|
863
|
+
"text",
|
|
864
|
+
text
|
|
865
|
+
);
|
|
866
|
+
msgs.push({
|
|
867
|
+
id: clusters.next(base),
|
|
868
|
+
role: isModel ? "assistant" : "user",
|
|
869
|
+
contentType: "text",
|
|
870
|
+
text,
|
|
871
|
+
...inline ? { imageMediaType: inline.mimeType, imageBase64: inline.data } : {},
|
|
872
|
+
rawGoogleParts: rest,
|
|
873
|
+
...signatureField(
|
|
874
|
+
"googleThoughtSignature",
|
|
875
|
+
textPartsOf(rest).find((p) => typeof p.thoughtSignature === "string")?.thoughtSignature
|
|
876
|
+
)
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
for (const part of parts) {
|
|
880
|
+
const fc = part.functionCall;
|
|
881
|
+
if (!fc || typeof fc.name !== "string") continue;
|
|
882
|
+
const text = jsonText(fc.args ?? {});
|
|
883
|
+
const wireId = typeof fc.id === "string" ? fc.id : void 0;
|
|
884
|
+
const base = deriveMessageId("assistant", "tool-call", text, {
|
|
885
|
+
toolCallId: wireId ?? "",
|
|
886
|
+
toolName: fc.name
|
|
887
|
+
});
|
|
888
|
+
const id = clusters.next(base);
|
|
889
|
+
const toolCallId = wireId ?? id;
|
|
890
|
+
const queue = unmatchedCalls.get(fc.name);
|
|
891
|
+
if (queue) queue.push(toolCallId);
|
|
892
|
+
else unmatchedCalls.set(fc.name, [toolCallId]);
|
|
893
|
+
msgs.push({
|
|
894
|
+
id,
|
|
895
|
+
role: "assistant",
|
|
896
|
+
contentType: "tool-call",
|
|
897
|
+
toolName: fc.name,
|
|
898
|
+
toolCallId,
|
|
899
|
+
text,
|
|
900
|
+
rawGoogleParts: [part],
|
|
901
|
+
...signatureField("googleThoughtSignature", part.thoughtSignature)
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return { msgs, systemText: googleSystemText(body) };
|
|
906
|
+
}
|
|
907
|
+
function coreToGoogle(messages) {
|
|
908
|
+
const out = [];
|
|
909
|
+
let model = null;
|
|
910
|
+
let user = null;
|
|
911
|
+
const flushModel = () => {
|
|
912
|
+
if (!model) return;
|
|
913
|
+
const parts = [...model.reasoning, ...model.text, ...model.calls];
|
|
914
|
+
model = null;
|
|
915
|
+
if (parts.length > 0) out.push({ role: "model", parts });
|
|
916
|
+
};
|
|
917
|
+
const flushUser = () => {
|
|
918
|
+
if (!user) return;
|
|
919
|
+
const parts = [...user.responses, ...user.content];
|
|
920
|
+
user = null;
|
|
921
|
+
if (parts.length > 0) out.push({ role: "user", parts });
|
|
922
|
+
};
|
|
923
|
+
for (const m of messages) {
|
|
924
|
+
if (m.role === "assistant") {
|
|
925
|
+
flushUser();
|
|
926
|
+
if (!model) model = { reasoning: [], text: [], calls: [] };
|
|
927
|
+
if (m.contentType === "reasoning") model.reasoning.push(reasoningPart(m));
|
|
928
|
+
else if (m.contentType === "tool-call") model.calls.push(toolCallPart(m));
|
|
929
|
+
else model.text.push(...contentParts(m));
|
|
930
|
+
} else {
|
|
931
|
+
flushModel();
|
|
932
|
+
if (!user) user = { responses: [], content: [] };
|
|
933
|
+
if (m.role === "tool" || m.contentType === "tool-result")
|
|
934
|
+
user.responses.push(...toolResultParts(m));
|
|
935
|
+
else user.content.push(...contentParts(m));
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
flushModel();
|
|
939
|
+
flushUser();
|
|
940
|
+
return out;
|
|
941
|
+
}
|
|
942
|
+
function injectGoogleSystem(contents, parts) {
|
|
943
|
+
if (parts.length === 0) return contents;
|
|
944
|
+
const extra = parts.join("\n\n");
|
|
945
|
+
const head = contents[0];
|
|
946
|
+
if (head && head.role === "user")
|
|
947
|
+
return [
|
|
948
|
+
{ ...head, parts: [{ text: extra }, ...head.parts] },
|
|
949
|
+
...contents.slice(1)
|
|
950
|
+
];
|
|
951
|
+
return [{ role: "user", parts: [{ text: extra }] }, ...contents];
|
|
952
|
+
}
|
|
953
|
+
function conversationSignalGoogle(body, headerValue) {
|
|
954
|
+
if (headerValue && headerValue.trim()) return headerValue.trim();
|
|
955
|
+
const contents = Array.isArray(body.contents) ? body.contents : [];
|
|
956
|
+
const firstUser = contents.find((c) => c.role !== "model");
|
|
957
|
+
const parts = firstUser && Array.isArray(firstUser.parts) ? firstUser.parts : [];
|
|
958
|
+
const seed = firstUser ? parts.map((p) => typeof p.text === "string" ? p.text : "").join("\n") : "default";
|
|
959
|
+
return hashId(seed);
|
|
960
|
+
}
|
|
961
|
+
function reasoningPart(m) {
|
|
962
|
+
const text = m.text ?? "";
|
|
963
|
+
const head = rawParts(m)[0];
|
|
964
|
+
if (head) return { ...head, text, thought: true };
|
|
965
|
+
return {
|
|
966
|
+
text,
|
|
967
|
+
thought: true,
|
|
968
|
+
...signatureField("thoughtSignature", m.googleThoughtSignature)
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
function toolCallPart(m) {
|
|
972
|
+
const head = rawParts(m)[0];
|
|
973
|
+
if (head && head.functionCall) return head;
|
|
974
|
+
return {
|
|
975
|
+
functionCall: {
|
|
976
|
+
name: m.toolName ?? "unknown",
|
|
977
|
+
args: jsonValue(m.text),
|
|
978
|
+
...m.toolCallId ? { id: m.toolCallId } : {}
|
|
979
|
+
},
|
|
980
|
+
...signatureField("thoughtSignature", m.googleThoughtSignature)
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
function toolResultParts(m) {
|
|
984
|
+
const raw = rawParts(m);
|
|
985
|
+
if (raw.length > 0 && raw.every((p) => p.functionResponse)) return raw;
|
|
986
|
+
return [
|
|
987
|
+
{
|
|
988
|
+
functionResponse: {
|
|
989
|
+
name: m.toolName ?? "unknown",
|
|
990
|
+
response: jsonValue(m.text),
|
|
991
|
+
...m.toolCallId ? { id: m.toolCallId } : {}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
];
|
|
995
|
+
}
|
|
996
|
+
function contentParts(m) {
|
|
997
|
+
const text = m.text ?? "";
|
|
998
|
+
const raw = rawParts(m);
|
|
999
|
+
if (raw.length === 0) {
|
|
1000
|
+
const parts2 = text ? [
|
|
1001
|
+
{
|
|
1002
|
+
text,
|
|
1003
|
+
...signatureField("thoughtSignature", m.googleThoughtSignature)
|
|
1004
|
+
}
|
|
1005
|
+
] : [];
|
|
1006
|
+
if (m.imageBase64 && m.imageMediaType)
|
|
1007
|
+
parts2.push({
|
|
1008
|
+
inlineData: { mimeType: m.imageMediaType, data: m.imageBase64 }
|
|
1009
|
+
});
|
|
1010
|
+
return parts2;
|
|
1011
|
+
}
|
|
1012
|
+
const rawTexts = textPartsOf(raw);
|
|
1013
|
+
if (rawTexts.map((p) => p.text ?? "").join("\n") === text) return raw;
|
|
1014
|
+
const parts = text ? [
|
|
1015
|
+
{
|
|
1016
|
+
text,
|
|
1017
|
+
...signatureField("thoughtSignature", m.googleThoughtSignature)
|
|
1018
|
+
}
|
|
1019
|
+
] : [];
|
|
1020
|
+
for (const part of raw) {
|
|
1021
|
+
if (!rawTexts.includes(part)) parts.push(part);
|
|
1022
|
+
}
|
|
1023
|
+
return parts;
|
|
1024
|
+
}
|
|
1025
|
+
function rawParts(m) {
|
|
1026
|
+
const raw = m.rawGoogleParts;
|
|
1027
|
+
if (!Array.isArray(raw)) return [];
|
|
1028
|
+
const out = [];
|
|
1029
|
+
for (const item of raw) {
|
|
1030
|
+
if (typeof item === "object" && item !== null) out.push(item);
|
|
1031
|
+
}
|
|
1032
|
+
return out;
|
|
1033
|
+
}
|
|
1034
|
+
function textPartsOf(parts) {
|
|
1035
|
+
return parts.filter((p) => typeof p.text === "string" && p.thought !== true);
|
|
1036
|
+
}
|
|
1037
|
+
function isContentPart(part) {
|
|
1038
|
+
if (part.functionCall !== void 0 || part.functionResponse !== void 0)
|
|
1039
|
+
return false;
|
|
1040
|
+
if (part.thought === true && typeof part.text === "string") return false;
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
function inlineDataOf(parts) {
|
|
1044
|
+
for (const part of parts) {
|
|
1045
|
+
const data = part.inlineData;
|
|
1046
|
+
if (data && typeof data.mimeType === "string" && typeof data.data === "string")
|
|
1047
|
+
return data;
|
|
1048
|
+
}
|
|
1049
|
+
return void 0;
|
|
1050
|
+
}
|
|
1051
|
+
function signatureField(key, signature) {
|
|
1052
|
+
return typeof signature === "string" ? { [key]: signature } : {};
|
|
1053
|
+
}
|
|
1054
|
+
function jsonText(value) {
|
|
1055
|
+
try {
|
|
1056
|
+
return JSON.stringify(value) ?? "";
|
|
1057
|
+
} catch {
|
|
1058
|
+
return "";
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function jsonValue(text) {
|
|
1062
|
+
if (!text) return {};
|
|
1063
|
+
try {
|
|
1064
|
+
const value = JSON.parse(text);
|
|
1065
|
+
return value === null ? {} : value;
|
|
1066
|
+
} catch {
|
|
1067
|
+
return { output: text };
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
|
|
796
1071
|
// src/wire/formats.ts
|
|
797
|
-
var WIRE_FORMATS = ["anthropic", "openai", "responses"];
|
|
1072
|
+
var WIRE_FORMATS = ["anthropic", "openai", "responses", "google"];
|
|
798
1073
|
function isWireFormat(value) {
|
|
799
1074
|
return typeof value === "string" && WIRE_FORMATS.includes(value);
|
|
800
1075
|
}
|
|
801
1076
|
function detectWireFormat(payload) {
|
|
802
1077
|
if (payload === null || typeof payload !== "object") return void 0;
|
|
803
1078
|
const p = payload;
|
|
1079
|
+
if (Array.isArray(p.contents)) return "google";
|
|
804
1080
|
if (Array.isArray(p.input)) return "responses";
|
|
805
1081
|
const messages = p.messages;
|
|
806
1082
|
if (!Array.isArray(messages)) return void 0;
|
|
@@ -1148,9 +1424,12 @@ function isImagePart(protocol, part) {
|
|
|
1148
1424
|
if (!isObj(part)) return false;
|
|
1149
1425
|
if (protocol === "responses") return part.type === "input_image";
|
|
1150
1426
|
if (protocol === "openai") return part.type === "image_url";
|
|
1427
|
+
if (protocol === "google")
|
|
1428
|
+
return isObj(part.inlineData) || isObj(part.fileData);
|
|
1151
1429
|
return part.type === "image";
|
|
1152
1430
|
}
|
|
1153
1431
|
function placeholderContent(protocol) {
|
|
1432
|
+
if (protocol === "google") return [{ text: IMAGE_PLACEHOLDER }];
|
|
1154
1433
|
const type = protocol === "responses" ? "input_text" : "text";
|
|
1155
1434
|
return [{ type, text: IMAGE_PLACEHOLDER }];
|
|
1156
1435
|
}
|
|
@@ -1182,6 +1461,31 @@ function stripHistoricalImages(body, protocol, keepRecent) {
|
|
|
1182
1461
|
if (!touched2) return { body, removed: 0 };
|
|
1183
1462
|
return { body: { ...body, input: nextInput }, removed: removed2 };
|
|
1184
1463
|
}
|
|
1464
|
+
if (protocol === "google") {
|
|
1465
|
+
const contents = body.contents;
|
|
1466
|
+
if (!Array.isArray(contents)) return { body, removed: 0 };
|
|
1467
|
+
const cutoff2 = contents.length - recentCount;
|
|
1468
|
+
let removed2 = 0;
|
|
1469
|
+
let touched2 = false;
|
|
1470
|
+
const nextContents = contents.map((c, i) => {
|
|
1471
|
+
if (i < cutoff2 && isObj(c) && Array.isArray(c.parts)) {
|
|
1472
|
+
const parts = c.parts;
|
|
1473
|
+
const imgs = parts.filter((p) => isImagePart("google", p)).length;
|
|
1474
|
+
if (imgs > 0) {
|
|
1475
|
+
removed2 += imgs;
|
|
1476
|
+
touched2 = true;
|
|
1477
|
+
const kept = parts.filter((p) => !isImagePart("google", p));
|
|
1478
|
+
return {
|
|
1479
|
+
...c,
|
|
1480
|
+
parts: kept.length > 0 ? kept : placeholderContent("google")
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return c;
|
|
1485
|
+
});
|
|
1486
|
+
if (!touched2) return { body, removed: 0 };
|
|
1487
|
+
return { body: { ...body, contents: nextContents }, removed: removed2 };
|
|
1488
|
+
}
|
|
1185
1489
|
const messages = body.messages;
|
|
1186
1490
|
if (!Array.isArray(messages)) return { body, removed: 0 };
|
|
1187
1491
|
const cutoff = messages.length - recentCount;
|
|
@@ -1216,10 +1520,12 @@ export {
|
|
|
1216
1520
|
compressToolArgs,
|
|
1217
1521
|
conversationIdentityResponses,
|
|
1218
1522
|
conversationSignalAnthropic,
|
|
1523
|
+
conversationSignalGoogle,
|
|
1219
1524
|
conversationSignalOpenai,
|
|
1220
1525
|
conversationSignalResponses,
|
|
1221
1526
|
corePieceKey,
|
|
1222
1527
|
coreToAnthropic,
|
|
1528
|
+
coreToGoogle,
|
|
1223
1529
|
coreToOpenai,
|
|
1224
1530
|
coreToResponses,
|
|
1225
1531
|
createSubagentNamespaces,
|
|
@@ -1227,7 +1533,10 @@ export {
|
|
|
1227
1533
|
detectWireFormat,
|
|
1228
1534
|
extractSystem,
|
|
1229
1535
|
findCompressCallsCore,
|
|
1536
|
+
googleSystemText,
|
|
1537
|
+
googleToCore,
|
|
1230
1538
|
hashId,
|
|
1539
|
+
injectGoogleSystem,
|
|
1231
1540
|
injectOpenaiSystem,
|
|
1232
1541
|
injectResponsesDeveloperMessage,
|
|
1233
1542
|
isWireFormat,
|