@jini-ai/agent-runtime 0.2.1 → 0.3.0
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/README.md +2 -2
- package/dist/agent-protocol/acp/session.d.ts +206 -1
- package/dist/agent-protocol/acp/session.d.ts.map +1 -1
- package/dist/agent-protocol/acp/session.js +505 -350
- package/dist/agent-protocol/acp/session.js.map +1 -1
- package/dist/agent-protocol/core/json-line-stream.d.ts +53 -0
- package/dist/agent-protocol/core/json-line-stream.d.ts.map +1 -1
- package/dist/agent-protocol/core/json-line-stream.js +307 -255
- package/dist/agent-protocol/core/json-line-stream.js.map +1 -1
- package/dist/agent-protocol/pi-rpc/events.d.ts +22 -1
- package/dist/agent-protocol/pi-rpc/events.d.ts.map +1 -1
- package/dist/agent-protocol/pi-rpc/events.js +189 -153
- package/dist/agent-protocol/pi-rpc/events.js.map +1 -1
- package/dist/agent-protocol/pi-rpc/session.d.ts +39 -0
- package/dist/agent-protocol/pi-rpc/session.d.ts.map +1 -1
- package/dist/agent-protocol/pi-rpc/session.js +143 -107
- package/dist/agent-protocol/pi-rpc/session.js.map +1 -1
- package/dist/claude-stream.d.ts +64 -1
- package/dist/claude-stream.d.ts.map +1 -1
- package/dist/claude-stream.js +568 -441
- package/dist/claude-stream.js.map +1 -1
- package/dist/defs/aider.d.ts.map +1 -1
- package/dist/defs/aider.js +13 -1
- package/dist/defs/aider.js.map +1 -1
- package/dist/defs/amp.d.ts.map +1 -1
- package/dist/defs/amp.js +16 -1
- package/dist/defs/amp.js.map +1 -1
- package/dist/defs/amr.d.ts +2 -1
- package/dist/defs/amr.d.ts.map +1 -1
- package/dist/defs/amr.js +12 -1
- package/dist/defs/amr.js.map +1 -1
- package/dist/defs/antigravity.d.ts +41 -2
- package/dist/defs/antigravity.d.ts.map +1 -1
- package/dist/defs/antigravity.js +201 -22
- package/dist/defs/antigravity.js.map +1 -1
- package/dist/defs/claude.d.ts +2 -0
- package/dist/defs/claude.d.ts.map +1 -1
- package/dist/defs/claude.js +58 -3
- package/dist/defs/claude.js.map +1 -1
- package/dist/defs/codebuddy.d.ts.map +1 -1
- package/dist/defs/codebuddy.js +9 -1
- package/dist/defs/codebuddy.js.map +1 -1
- package/dist/defs/codex.d.ts +1 -0
- package/dist/defs/codex.d.ts.map +1 -1
- package/dist/defs/codex.js +34 -0
- package/dist/defs/codex.js.map +1 -1
- package/dist/defs/copilot.d.ts.map +1 -1
- package/dist/defs/copilot.js +15 -1
- package/dist/defs/copilot.js.map +1 -1
- package/dist/defs/cursor-agent.d.ts.map +1 -1
- package/dist/defs/cursor-agent.js +24 -2
- package/dist/defs/cursor-agent.js.map +1 -1
- package/dist/defs/deepseek.d.ts.map +1 -1
- package/dist/defs/deepseek.js +12 -0
- package/dist/defs/deepseek.js.map +1 -1
- package/dist/defs/devin.d.ts +2 -1
- package/dist/defs/devin.d.ts.map +1 -1
- package/dist/defs/devin.js +12 -7
- package/dist/defs/devin.js.map +1 -1
- package/dist/defs/grok-build.d.ts.map +1 -1
- package/dist/defs/grok-build.js +10 -0
- package/dist/defs/grok-build.js.map +1 -1
- package/dist/defs/hermes.d.ts +1 -0
- package/dist/defs/hermes.d.ts.map +1 -1
- package/dist/defs/hermes.js +3 -0
- package/dist/defs/hermes.js.map +1 -1
- package/dist/defs/kilo.d.ts +1 -0
- package/dist/defs/kilo.d.ts.map +1 -1
- package/dist/defs/kilo.js +3 -0
- package/dist/defs/kilo.js.map +1 -1
- package/dist/defs/kimi.d.ts +1 -0
- package/dist/defs/kimi.d.ts.map +1 -1
- package/dist/defs/kimi.js +3 -0
- package/dist/defs/kimi.js.map +1 -1
- package/dist/defs/kiro.d.ts +1 -0
- package/dist/defs/kiro.d.ts.map +1 -1
- package/dist/defs/kiro.js +3 -0
- package/dist/defs/kiro.js.map +1 -1
- package/dist/defs/pi.d.ts +1 -1
- package/dist/defs/pi.d.ts.map +1 -1
- package/dist/defs/pi.js +6 -1
- package/dist/defs/pi.js.map +1 -1
- package/dist/defs/qoder.d.ts +1 -0
- package/dist/defs/qoder.d.ts.map +1 -1
- package/dist/defs/qoder.js +15 -0
- package/dist/defs/qoder.js.map +1 -1
- package/dist/defs/qwen.d.ts.map +1 -1
- package/dist/defs/qwen.js +9 -0
- package/dist/defs/qwen.js.map +1 -1
- package/dist/defs/reasonix.d.ts +1 -0
- package/dist/defs/reasonix.d.ts.map +1 -1
- package/dist/defs/reasonix.js +3 -0
- package/dist/defs/reasonix.js.map +1 -1
- package/dist/defs/shared.d.ts +31 -1
- package/dist/defs/shared.d.ts.map +1 -1
- package/dist/defs/shared.js +35 -0
- package/dist/defs/shared.js.map +1 -1
- package/dist/defs/trae-cli.d.ts +1 -0
- package/dist/defs/trae-cli.d.ts.map +1 -1
- package/dist/defs/trae-cli.js +3 -0
- package/dist/defs/trae-cli.js.map +1 -1
- package/dist/defs/vibe.d.ts +1 -0
- package/dist/defs/vibe.d.ts.map +1 -1
- package/dist/defs/vibe.js +3 -0
- package/dist/defs/vibe.js.map +1 -1
- package/dist/detection.d.ts +1 -1
- package/dist/detection.d.ts.map +1 -1
- package/dist/detection.js +7 -2
- package/dist/detection.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/log-file.d.ts +23 -0
- package/dist/log-file.d.ts.map +1 -0
- package/dist/log-file.js +56 -0
- package/dist/log-file.js.map +1 -0
- package/dist/model-registry.d.ts +7 -45
- package/dist/model-registry.d.ts.map +1 -1
- package/dist/model-registry.js.map +1 -1
- package/dist/providers/anthropic-messages.d.ts +198 -6
- package/dist/providers/anthropic-messages.d.ts.map +1 -1
- package/dist/providers/anthropic-messages.js +317 -140
- package/dist/providers/anthropic-messages.js.map +1 -1
- package/dist/providers/azure-chat.d.ts +113 -3
- package/dist/providers/azure-chat.d.ts.map +1 -1
- package/dist/providers/azure-chat.js +114 -21
- package/dist/providers/azure-chat.js.map +1 -1
- package/dist/providers/connection-guard.d.ts +121 -1
- package/dist/providers/connection-guard.d.ts.map +1 -1
- package/dist/providers/connection-guard.js +205 -3
- package/dist/providers/connection-guard.js.map +1 -1
- package/dist/providers/connection-test.d.ts +62 -0
- package/dist/providers/connection-test.d.ts.map +1 -0
- package/dist/providers/connection-test.js +404 -0
- package/dist/providers/connection-test.js.map +1 -0
- package/dist/providers/elevenlabs.d.ts.map +1 -1
- package/dist/providers/elevenlabs.js +3 -2
- package/dist/providers/elevenlabs.js.map +1 -1
- package/dist/providers/google-messages.d.ts +208 -7
- package/dist/providers/google-messages.d.ts.map +1 -1
- package/dist/providers/google-messages.js +331 -105
- package/dist/providers/google-messages.js.map +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/model-catalog.d.ts.map +1 -1
- package/dist/providers/model-catalog.js +21 -0
- package/dist/providers/model-catalog.js.map +1 -1
- package/dist/providers/ollama-chat.d.ts +190 -1
- package/dist/providers/ollama-chat.d.ts.map +1 -1
- package/dist/providers/ollama-chat.js +319 -110
- package/dist/providers/ollama-chat.js.map +1 -1
- package/dist/providers/openai-chat.d.ts +222 -14
- package/dist/providers/openai-chat.d.ts.map +1 -1
- package/dist/providers/openai-chat.js +377 -128
- package/dist/providers/openai-chat.js.map +1 -1
- package/dist/providers/sse-decode.d.ts +2 -2
- package/dist/providers/sse-decode.js +2 -2
- package/dist/types.d.ts +169 -87
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -4
|
@@ -1,13 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module providers/google-messages
|
|
3
|
+
*
|
|
4
|
+
* Google Generative Language (Gemini) `streamGenerateContent` wire adapter +
|
|
5
|
+
* tool-loop turn-runner. Sibling of `anthropic-messages.ts`/`openai-chat.ts`
|
|
6
|
+
* — see those modules' headers for the shared design rationale (package
|
|
7
|
+
* placement, `extraHeaders` never carrying a hardcoded product-identity
|
|
8
|
+
* string, the `turn-end-guard.ts` fix for a duplicate-`end`-event class of
|
|
9
|
+
* bug). Reuses this package's existing `providers/google.ts` URL helpers
|
|
10
|
+
* (`googleStreamGenerateContentUrl`) rather than rebuilding URL-building
|
|
11
|
+
* logic — see that module's own doc.
|
|
12
|
+
*
|
|
13
|
+
* **Verified against Google's real, current public API docs** (per this
|
|
14
|
+
* repo's "verify against real API docs, don't guess from memory"
|
|
15
|
+
* convention — see `anthropic-messages.ts`'s header for the precedent).
|
|
16
|
+
* Two things worth flagging for a future maintainer:
|
|
17
|
+
*
|
|
18
|
+
* 1. **Two REST APIs coexist as of this writing.** Google's docs now lead
|
|
19
|
+
* with a newer `interactions` API (`POST /v1beta/interactions`,
|
|
20
|
+
* `input`/`previous_interaction_id`/`function_result` shaped) alongside
|
|
21
|
+
* the classic `generateContent`/`streamGenerateContent` API
|
|
22
|
+
* (`contents: [{role, parts}]`, `functionCall`/`functionResponse`
|
|
23
|
+
* parts). This adapter deliberately targets the **classic** API — it is
|
|
24
|
+
* what `providers/google.ts#googleStreamGenerateContentUrl` already
|
|
25
|
+
* builds a URL for, and what this task's spec calls for. Confirmed via
|
|
26
|
+
* `ai.google.dev/api/generate-content` (Content/Part/GenerateContent
|
|
27
|
+
* Request/Response field names) and a live web search returning a
|
|
28
|
+
* real-world function-calling exchange showing the exact
|
|
29
|
+
* `{ functionResponse: { name, response, id } }` shape sent back with
|
|
30
|
+
* `role: 'user'` (not `role: 'function'` — there is no `function` role
|
|
31
|
+
* in the classic Content schema; `role` is `'user' | 'model' | 'system'`
|
|
32
|
+
* only).
|
|
33
|
+
* 2. **No `finishReason` value means "the model wants a tool call."**
|
|
34
|
+
* Unlike Anthropic (`stop_reason: 'tool_use'`) and OpenAI
|
|
35
|
+
* (`finish_reason: 'tool_calls'`), Gemini's documented `finishReason`
|
|
36
|
+
* enum (`STOP`, `MAX_TOKENS`, `SAFETY`, `RECITATION`, `LANGUAGE`,
|
|
37
|
+
* `OTHER`) has no tool-call-specific member — a function call is simply
|
|
38
|
+
* a `functionCall` part inside an otherwise normal (often
|
|
39
|
+
* `finishReason: 'STOP'`) candidate. `runGoogleToolTurn`'s tool-loop
|
|
40
|
+
* continuation predicate is therefore `toolCalls.length > 0`, not a
|
|
41
|
+
* `finishReason` comparison — the one structural place this adapter
|
|
42
|
+
* cannot mirror `anthropic-messages.ts`/`openai-chat.ts` byte-for-byte.
|
|
43
|
+
*
|
|
44
|
+
* **Scope for this pass:** text + function-call parts, `inlineData` image
|
|
45
|
+
* parts, and the tool-execution loop. `fileData` parts (the Files-API
|
|
46
|
+
* reference form, for content too large to inline) and `promptFeedback`'s
|
|
47
|
+
* per-category safety ratings are still out of scope — a blocked prompt
|
|
48
|
+
* (`promptFeedback.blockReason` present, no candidates) is still surfaced as
|
|
49
|
+
* an `error` event rather than silently hanging, but the detailed
|
|
50
|
+
* safety-rating breakdown is not modeled.
|
|
51
|
+
*
|
|
52
|
+
* **Image support**: `inlineData: {mimeType, data}` (base64) — canonical
|
|
53
|
+
* proto3 JSON field names confirmed via `ai.google.dev/api/rest/v1beta/
|
|
54
|
+
* Content` (`inline_data`/`mime_type` also parse, per proto3's JSON mapping,
|
|
55
|
+
* but this module sends the camelCase canonical form to match every other
|
|
56
|
+
* field it already sends: `functionCall`, `functionResponse`,
|
|
57
|
+
* `usageMetadata`, etc.). Supported formats and the 20 MB total-inline-
|
|
58
|
+
* request budget (text + system instructions + inline bytes combined) per
|
|
59
|
+
* `ai.google.dev/gemini-api/docs/image-understanding` — see
|
|
60
|
+
* `MAX_INLINE_IMAGE_BASE64_CHARS`'s doc for how this module applies that
|
|
61
|
+
* budget per-image.
|
|
62
|
+
*
|
|
63
|
+
* **No documented way to attach an image to a `functionResponse` in this
|
|
64
|
+
* (classic) API.** Checked `ai.google.dev/api/rest/v1beta/Content` and
|
|
65
|
+
* `ai.google.dev/gemini-api/docs/image-understanding` directly for a
|
|
66
|
+
* `FunctionResponse.parts` field or similar — neither documents one; images
|
|
67
|
+
* are only documented as ordinary `Content` input. (A "multimodal function
|
|
68
|
+
* response" feature does exist under `ai.google.dev/gemini-api/docs/
|
|
69
|
+
* function-calling`, but confirmed to belong exclusively to the newer
|
|
70
|
+
* `interactions` API this module already deliberately excludes — see the
|
|
71
|
+
* "Two REST APIs coexist" note above; its `result`/`function_result` shape
|
|
72
|
+
* does not apply here.) So a tool result carrying an image keeps
|
|
73
|
+
* `functionResponse.response` as a plain string (same shape as before), and
|
|
74
|
+
* `runGoogleToolTurn` appends the image as ordinary `inlineData` parts in
|
|
75
|
+
* the *same* `role: 'user'` `Content` alongside the `functionResponse` parts
|
|
76
|
+
* — unlike `openai-chat.ts`, which is forced onto a separate follow-up
|
|
77
|
+
* message because OpenAI's wire `tool` role is hard-restricted to text.
|
|
78
|
+
* Gemini's `Content.parts` has no such restriction: it is just an ordered
|
|
79
|
+
* list of `Part` union members, so mixing `functionResponse` and
|
|
80
|
+
* `inlineData` parts in one `Content` is exactly the same pattern this
|
|
81
|
+
* module already uses for `modelParts` (text + `functionCall` together).
|
|
82
|
+
*
|
|
83
|
+
* **This is still a workaround for a real protocol limitation, not this module inventing
|
|
84
|
+
* structure** — Anthropic's `tool_result` content block can carry an image natively and needs no
|
|
85
|
+
* such fold (see `anthropic-messages.ts`). Both `openai-chat.ts`'s separate-message form and this
|
|
86
|
+
* module's same-`Content` form exist for the identical underlying reason: `FunctionResponse`/`tool`
|
|
87
|
+
* has no documented image slot, so the image has to travel some other way. Each `inlineData` part
|
|
88
|
+
* appended this way is preceded by a plain-text label naming the tool call it answers (name + id)
|
|
89
|
+
* — an unlabeled image is otherwise indistinguishable from a human-supplied one, which in a vision
|
|
90
|
+
* self-check loop risks the model treating its own tool's output as a new user turn. When a batch
|
|
91
|
+
* has parallel tool calls, ALL `functionResponse` parts for the batch are assembled first and every
|
|
92
|
+
* labeled image is appended after them, in one `Content` — never one `Content` per tool result —
|
|
93
|
+
* matching this module's existing single-continuation-turn shape (see `runGoogleToolTurn`'s
|
|
94
|
+
* tool-loop body and its test file's multi-tool-call image test).
|
|
95
|
+
*/
|
|
96
|
+
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
97
|
+
import { type DnsLookupFn, type PinnedFetch } from './connection-guard.js';
|
|
1
98
|
import { type TurnEndReason } from './turn-end-guard.js';
|
|
2
99
|
export interface GoogleTextPart {
|
|
3
100
|
readonly text: string;
|
|
4
101
|
}
|
|
102
|
+
/** Base64 inline image (or other binary) data. Canonical camelCase field names — see module doc's "Image support" section for the verified proto3 JSON mapping. */
|
|
103
|
+
export interface GoogleInlineDataPart {
|
|
104
|
+
readonly inlineData: {
|
|
105
|
+
readonly mimeType: string;
|
|
106
|
+
readonly data: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
5
109
|
export interface GoogleFunctionCallPart {
|
|
6
110
|
readonly functionCall: {
|
|
7
111
|
readonly name: string;
|
|
8
112
|
readonly args: unknown;
|
|
9
113
|
readonly id?: string;
|
|
10
114
|
};
|
|
115
|
+
/**
|
|
116
|
+
* An opaque, encrypted handle on the model's reasoning for this call. A SIBLING of `functionCall`
|
|
117
|
+
* on the same `Part`, not a field inside it — verified against a live response, not inferred:
|
|
118
|
+
*
|
|
119
|
+
* ```json
|
|
120
|
+
* { "functionCall": { "name": "render_preview", "args": {}, "id": "UgFzM3QW" },
|
|
121
|
+
* "thoughtSignature": "EukCCuYCARFNMg+HEX+iufpVJfgG..." }
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* **Required on the continuation request.** Omitting it makes every currently-served Gemini model
|
|
125
|
+
* reject the follow-up with HTTP 400:
|
|
126
|
+
*
|
|
127
|
+
* > Function call is missing a thought_signature in functionCall parts. This is required for
|
|
128
|
+
* > tools to work correctly … Additional data, function call `default_api:<name>`, position 2.
|
|
129
|
+
*
|
|
130
|
+
* so the whole tool loop fails before the model evaluates anything. Note the wire key is
|
|
131
|
+
* camelCase `thoughtSignature` even though the error message spells it `thought_signature`.
|
|
132
|
+
*
|
|
133
|
+
* Treated as **opaque and echoed back verbatim** — never parsed, normalized, or synthesized. It
|
|
134
|
+
* is encrypted model state; a value we invent is not a weaker signature, it is an invalid one.
|
|
135
|
+
* Optional because a model may return a `functionCall` without one (older models, and non-thinking
|
|
136
|
+
* paths), and in that case the correct continuation omits the field rather than sending an empty
|
|
137
|
+
* string.
|
|
138
|
+
*/
|
|
139
|
+
readonly thoughtSignature?: string;
|
|
11
140
|
}
|
|
12
141
|
export interface GoogleFunctionResponsePart {
|
|
13
142
|
readonly functionResponse: {
|
|
@@ -16,7 +145,9 @@ export interface GoogleFunctionResponsePart {
|
|
|
16
145
|
readonly id?: string;
|
|
17
146
|
};
|
|
18
147
|
}
|
|
19
|
-
export type GooglePart = GoogleTextPart | GoogleFunctionCallPart | GoogleFunctionResponsePart;
|
|
148
|
+
export type GooglePart = GoogleTextPart | GoogleInlineDataPart | GoogleFunctionCallPart | GoogleFunctionResponsePart;
|
|
149
|
+
/** The subset of `GooglePart` a tool result may legally carry — no `functionCall`/`functionResponse` part makes sense as a tool's own output. */
|
|
150
|
+
export type GoogleToolResultPart = GoogleTextPart | GoogleInlineDataPart;
|
|
20
151
|
export interface GoogleContent {
|
|
21
152
|
readonly role: 'user' | 'model';
|
|
22
153
|
readonly parts: readonly GooglePart[];
|
|
@@ -33,9 +164,13 @@ export interface GoogleToolCall {
|
|
|
33
164
|
readonly id: string;
|
|
34
165
|
readonly name: string;
|
|
35
166
|
readonly input: unknown;
|
|
167
|
+
/** Carried from the response `Part` to the continuation `Part` untouched — see
|
|
168
|
+
* `GoogleFunctionCallPart.thoughtSignature` for why omitting it breaks the whole tool loop. */
|
|
169
|
+
readonly thoughtSignature?: string;
|
|
36
170
|
}
|
|
171
|
+
/** `content` may include `GoogleInlineDataPart`s (e.g. a vision self-check's screenshot) — `runGoogleToolTurn` folds them into the continuation `Content`'s `parts` alongside the `functionResponse`; see module doc's "No documented way to attach an image to a functionResponse" section. */
|
|
37
172
|
export interface GoogleToolResult {
|
|
38
|
-
readonly content: string;
|
|
173
|
+
readonly content: string | readonly GoogleToolResultPart[];
|
|
39
174
|
readonly isError?: boolean;
|
|
40
175
|
}
|
|
41
176
|
/** Host-owned tool execution — same "the collaborator is always supplied" convention as `anthropic-messages.ts#AnthropicToolExecutor`. */
|
|
@@ -56,7 +191,7 @@ export type GoogleTurnEvent = {
|
|
|
56
191
|
} | {
|
|
57
192
|
readonly type: 'tool_result';
|
|
58
193
|
readonly toolUseId: string;
|
|
59
|
-
readonly content: string;
|
|
194
|
+
readonly content: string | readonly GoogleToolResultPart[];
|
|
60
195
|
readonly isError: boolean;
|
|
61
196
|
} | {
|
|
62
197
|
readonly type: 'usage';
|
|
@@ -90,19 +225,85 @@ export interface GoogleTurnOptions {
|
|
|
90
225
|
readonly signal?: AbortSignal;
|
|
91
226
|
/** Caller-supplied extra headers — see `anthropic-messages.ts#AnthropicTurnOptions.extraHeaders`'s doc for why this exists and what it fixes. */
|
|
92
227
|
readonly extraHeaders?: Record<string, string>;
|
|
228
|
+
/** Injectable HTTP transport, defaulting to {@link pinnedFetch} (SSRF-guarded, DNS-pinned). See `anthropic-messages.ts#AnthropicTurnOptions.fetchImpl`'s doc for the seam this exists for and why production wiring must never override it. */
|
|
229
|
+
readonly fetchImpl?: PinnedFetch;
|
|
230
|
+
/** Injectable DNS resolver for {@link validateBaseUrlResolved}'s DNS-pinning check, defaulting to {@link defaultDnsLookup}. Same test-only override rationale as `fetchImpl`. */
|
|
231
|
+
readonly dnsLookup?: DnsLookupFn;
|
|
93
232
|
}
|
|
94
233
|
export interface GoogleTurnResult {
|
|
95
234
|
readonly finishReason: string | null;
|
|
96
235
|
readonly toolTurns: number;
|
|
97
236
|
}
|
|
237
|
+
interface SingleRequestOutcome {
|
|
238
|
+
readonly finishReason: string | null;
|
|
239
|
+
readonly toolCalls: readonly GoogleToolCall[];
|
|
240
|
+
readonly text: string;
|
|
241
|
+
}
|
|
242
|
+
/** Mutable reduction state threaded through one streaming request's frame handlers (below). Grouped into one object so each handler takes a single parameter instead of several — same convention as `anthropic-messages.ts#AnthropicStreamState`/`openai-chat.ts#OpenAiStreamState`. Exported so a unit test can construct one directly without going through a full `runGoogleToolTurn` call. */
|
|
243
|
+
export interface GoogleStreamState {
|
|
244
|
+
readonly guard: ReturnType<typeof createRoleMarkerGuard>;
|
|
245
|
+
readonly toolCalls: GoogleToolCall[];
|
|
246
|
+
fullText: string;
|
|
247
|
+
finishReason: string | null;
|
|
248
|
+
usage: Record<string, unknown> | null;
|
|
249
|
+
}
|
|
250
|
+
export declare function applyGoogleUsage(state: GoogleStreamState, data: Record<string, unknown>, onEvent: (event: GoogleTurnEvent) => void): void;
|
|
251
|
+
/** Checks `data.promptFeedback` for a documented block reason and, if present, emits the `error` event for it (the caller emits `end` — see `processGoogleFrame`). Returns whether the frame loop should stop. */
|
|
252
|
+
export declare function handleGoogleBlockedPrompt(data: Record<string, unknown>, onEvent: (event: GoogleTurnEvent) => void): boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Feeds one text part through the role-marker guard and emits the safe portion. Returns `'break'`
|
|
255
|
+
* once the guard flags contamination (the caller ends the turn immediately), otherwise
|
|
256
|
+
* `'continue'` — same contract as `anthropic-messages.ts#handleAnthropicTextDelta`.
|
|
257
|
+
*/
|
|
258
|
+
export declare function handleGoogleTextPart(state: GoogleStreamState, text: string, onEvent: (event: GoogleTurnEvent) => void): 'continue' | 'break';
|
|
259
|
+
/** `rawPart.functionCall` must already be confirmed a record by the caller. Reads `thoughtSignature` off `rawPart` (a sibling of `functionCall`, not a member of it) — see `GoogleFunctionCallPart.thoughtSignature`'s doc for why only a non-empty string is carried. */
|
|
260
|
+
export declare function handleGoogleFunctionCallPart(state: GoogleStreamState, rawPart: Record<string, unknown>, onEvent: (event: GoogleTurnEvent) => void): void;
|
|
261
|
+
/** Dispatches one part between the text and function-call handlers above. Returns `'break'` once a text part contaminates the guard, else `'continue'`. */
|
|
262
|
+
export declare function processGoogleRawPart(state: GoogleStreamState, rawPart: unknown, onEvent: (event: GoogleTurnEvent) => void): 'continue' | 'break';
|
|
263
|
+
/** One frame's dispatch outcome — `'end'` carries the reason `runSingleGoogleRequest`'s loop passes to `emitEnd`, matching `anthropic-messages.ts#AnthropicFrameOutcome`'s identical split (the low-level handlers below only ever *report* why to stop; only the loop itself calls `emitEnd`, keeping that call in exactly one place). */
|
|
264
|
+
export type GoogleFrameOutcome = {
|
|
265
|
+
readonly action: 'continue';
|
|
266
|
+
} | {
|
|
267
|
+
readonly action: 'end';
|
|
268
|
+
readonly reason: GoogleTurnEndReason;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Reduces one already-parsed SSE frame payload into `state`, reporting whether the caller's frame
|
|
272
|
+
* loop should stop (`'end'`, on either a blocked prompt or guard contamination) or keep going
|
|
273
|
+
* (`'continue'`). Pulling this out of the loop body turns what was five sequential,
|
|
274
|
+
* nesting-penalized top-level `if`s into one function call plus one outcome check — see
|
|
275
|
+
* `runSingleGoogleRequest`'s loop below.
|
|
276
|
+
*/
|
|
277
|
+
export declare function processGoogleFrame(state: GoogleStreamState, data: Record<string, unknown>, onEvent: (event: GoogleTurnEvent) => void): GoogleFrameOutcome;
|
|
278
|
+
/**
|
|
279
|
+
* Decides why the tool loop should stop after one request, or returns `null` when it should
|
|
280
|
+
* instead proceed to execute the pending tool calls. Pure — no events, no I/O — mirrors
|
|
281
|
+
* `anthropic-messages.ts#anthropicLoopExitReason`'s decision/effect split. Deliberate structural
|
|
282
|
+
* difference from that sibling: the continuation predicate is `toolCalls.length > 0`, not a
|
|
283
|
+
* `finishReason` comparison (see module doc, point 2, for why Gemini's `finishReason` enum cannot
|
|
284
|
+
* be used here).
|
|
285
|
+
*/
|
|
286
|
+
export declare function googleLoopExitReason(outcome: SingleRequestOutcome, toolTurns: number, maxToolTurns: number): GoogleTurnEndReason | null;
|
|
287
|
+
/** Builds the `model`-role `Content`'s `parts` recording the pending tool calls — text (if any) followed by one `functionCall` part per call, each with its `thoughtSignature` spread back on as a sibling field, in the same shape the response delivered it and only when the response actually carried one (a `functionCall` part with no signature is legal; one with an empty-string signature is not). */
|
|
288
|
+
export declare function buildGoogleAssistantParts(text: string, toolCalls: readonly GoogleToolCall[]): GooglePart[];
|
|
289
|
+
export interface GoogleToolExecutionOutcome {
|
|
290
|
+
readonly functionResponseParts: GooglePart[];
|
|
291
|
+
readonly followUpParts: GooglePart[];
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Runs every pending tool call in order, reducing the results into the `functionResponse` parts
|
|
295
|
+
* for the batch plus any labeled `inlineData` image parts that ride alongside them in the same
|
|
296
|
+
* continuation `Content` — see module doc's "No documented way to attach an image to a
|
|
297
|
+
* functionResponse" section for why images travel this way instead of a separate follow-up
|
|
298
|
+
* message (unlike `openai-chat.ts`/`azure-chat.ts`).
|
|
299
|
+
*/
|
|
300
|
+
export declare function executeGoogleToolCalls(executeTool: GoogleToolExecutor, calls: readonly GoogleToolCall[], onEvent: (event: GoogleTurnEvent) => void): Promise<GoogleToolExecutionOutcome>;
|
|
98
301
|
/**
|
|
99
302
|
* Runs a full Gemini `streamGenerateContent` turn, including the
|
|
100
303
|
* tool-execution loop when `options.executeTool` is supplied and the model
|
|
101
304
|
* requests a function call. See `anthropic-messages.ts#runAnthropicToolTurn`'s
|
|
102
|
-
* doc for the shared event-stream/`ended`-flag contract this mirrors
|
|
103
|
-
* one deliberate structural difference: the loop-continuation predicate is
|
|
104
|
-
* `toolCalls.length > 0`, not a `finishReason` comparison (see module doc,
|
|
105
|
-
* point 2, for why Gemini's `finishReason` enum cannot be used here).
|
|
305
|
+
* doc for the shared event-stream/`ended`-flag contract this mirrors.
|
|
106
306
|
*/
|
|
107
307
|
export declare function runGoogleToolTurn(options: GoogleTurnOptions): Promise<GoogleTurnResult>;
|
|
308
|
+
export {};
|
|
108
309
|
//# sourceMappingURL=google-messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-messages.d.ts","sourceRoot":"","sources":["../../src/providers/google-messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-messages.d.ts","sourceRoot":"","sources":["../../src/providers/google-messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAyE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGlJ,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE7E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,mKAAmK;AACnK,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,YAAY,EAAE;QACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;QACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,gBAAgB,EAAE;QACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;QAC3B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,MAAM,MAAM,UAAU,GAAG,cAAc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