@jini-ai/agent-runtime 0.4.10 → 0.4.11

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 CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.4.11 — 2026-10-14
2
+
3
+ - Gemini: `applyGoogleUsage` adds `input_tokens` (`promptTokenCount`) and `output_tokens` (`candidatesTokenCount` + `thoughtsTokenCount`) next to the raw `usageMetadata` fields, so usage reducers show Gemini token counts (024fe7e8).
4
+ - Gemini: a first reply with no text and no tool calls (for example thinking consumed the whole `MAX_TOKENS` budget) now emits an error carrying the finish reason and ends with `error` instead of a blank successful `stop`. Partial text cut off by `MAX_TOKENS` and tool-only turns still succeed (a80066ae).
5
+
1
6
  ## 0.4.10 — 2026-10-13
2
7
 
3
8
  - ACP `session/request_permission` no longer fails the run. Without an injected `onPermissionRequest`, the session answers by the new `AttachAcpSessionOptions.permissionMode`: `bypass` selects `allow_once`; otherwise `reject_once`, falling back to `reject_always` or `cancelled`. It never picks an "always" approval. A handler that throws, rejects, or selects an unoffered option cancels the request. Each request emits one `status` event (`label: 'acp_permission'`) with only the tool kind and decision. `choosePermissionOutcome(options, { permissionMode })` follows the same policy.
@@ -247,6 +247,7 @@ export interface GoogleStreamState {
247
247
  finishReason: string | null;
248
248
  usage: Record<string, unknown> | null;
249
249
  }
250
+ /** Adds the shared `input_tokens`/`output_tokens` fields (the only ones the chat usage reducers read) to raw Gemini `usageMetadata` and emits usage. */
250
251
  export declare function applyGoogleUsage({ state, data, onEvent }: {
251
252
  state: GoogleStreamState;
252
253
  data: Record<string, unknown>;
@@ -337,6 +338,8 @@ export declare function executeGoogleToolCalls({ executeTool, calls, onEvent }:
337
338
  * tool-execution loop when `options.executeTool` is supplied and the model
338
339
  * requests a function call. See `anthropic-messages.ts#runAnthropicToolTurn`'s
339
340
  * doc for the shared event-stream/`ended`-flag contract this mirrors.
341
+ * An initial response without text or calls emits an error with its provider finish reason,
342
+ * not a successful stop. Tool-only turns remain valid: the host may already have acted on them.
340
343
  */
341
344
  export declare function runGoogleToolTurn(requiredArgs: Pick<GoogleTurnOptions, "apiKey" | "model" | "contents" | "onEvent">, optionalArgs?: Omit<GoogleTurnOptions, "apiKey" | "model" | "contents" | "onEvent">): Promise<GoogleTurnResult>;
342
345
  export {};
@@ -151,10 +151,20 @@ function extractGoogleErrorDetail(rawText) {
151
151
  }
152
152
  return rawText.trim().slice(0, 500);
153
153
  }
154
+ /** Adds the shared `input_tokens`/`output_tokens` fields (the only ones the chat usage reducers read) to raw Gemini `usageMetadata` and emits usage. */
154
155
  export function applyGoogleUsage({ state, data, onEvent }) {
155
156
  if (!isRecord(data.usageMetadata))
156
157
  return;
157
- state.usage = data.usageMetadata;
158
+ const usage = data.usageMetadata;
159
+ const candidateTokens = typeof usage.candidatesTokenCount === 'number' ? usage.candidatesTokenCount : undefined;
160
+ const thoughtsTokens = typeof usage.thoughtsTokenCount === 'number' ? usage.thoughtsTokenCount : undefined;
161
+ state.usage = {
162
+ ...usage,
163
+ // Thoughts are reported separately from candidates; they count as output, as thinking/reasoning
164
+ // tokens already do inside Anthropic's `output_tokens` and OpenAI's `completion_tokens`.
165
+ ...(typeof usage.promptTokenCount === 'number' ? { input_tokens: usage.promptTokenCount } : {}),
166
+ ...(candidateTokens !== undefined || thoughtsTokens !== undefined ? { output_tokens: (candidateTokens ?? 0) + (thoughtsTokens ?? 0) } : {}),
167
+ };
158
168
  onEvent({ type: 'usage', usage: state.usage });
159
169
  }
160
170
  /** The frame's first candidate, unnarrowed — `processGoogleFrame` distinguishes "no candidate at all" (checks `promptFeedback` for a blocked-prompt error) from "a candidate that isn't a record" (silently skipped), so this deliberately does not collapse both into one `null`. */
@@ -468,6 +478,8 @@ export async function executeGoogleToolCalls({ executeTool, calls, onEvent }) {
468
478
  * tool-execution loop when `options.executeTool` is supplied and the model
469
479
  * requests a function call. See `anthropic-messages.ts#runAnthropicToolTurn`'s
470
480
  * doc for the shared event-stream/`ended`-flag contract this mirrors.
481
+ * An initial response without text or calls emits an error with its provider finish reason,
482
+ * not a successful stop. Tool-only turns remain valid: the host may already have acted on them.
471
483
  */
472
484
  export async function runGoogleToolTurn(requiredArgs, optionalArgs = {}) {
473
485
  const options = { ...optionalArgs, ...requiredArgs };
@@ -483,6 +495,15 @@ export async function runGoogleToolTurn(requiredArgs, optionalArgs = {}) {
483
495
  lastFinishReason = outcome.finishReason;
484
496
  if (endGuard.hasEnded())
485
497
  break;
498
+ if (toolTurns === 0 && outcome.toolCalls.length === 0 && !outcome.text.trim()) {
499
+ // Thinking can consume the entire output budget without producing any answer. Preserve
500
+ // the reason for operator diagnostics rather than turning a content-free response into stop.
501
+ options.onEvent({ type: 'error', message: redactSecrets({
502
+ input: `Google returned no text or tool calls (${outcome.finishReason ?? 'missing finish reason'})`,
503
+ }, { exactSecrets: [options.apiKey] }) });
504
+ emitEnd('error');
505
+ break;
506
+ }
486
507
  const exitReason = googleLoopExitReason({ outcome: outcome, toolTurns: toolTurns, maxToolTurns: maxToolTurns });
487
508
  if (exitReason) {
488
509
  emitEnd(exitReason);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/agent-runtime",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "Coding-agent runtime adapters: runtime registry, detection, launch, stream parsers, and the ACP/pi-rpc subprocess transport.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -99,13 +99,13 @@
99
99
  "devDependencies": {
100
100
  "@vitest/coverage-v8": "^2.1.9",
101
101
  "@jini-ai/core": "^0.4.0",
102
- "@jini-ai/platform": "^0.5.6",
103
102
  "@jini-ai/integrations": "^0.4.2",
103
+ "@jini-ai/platform": "^0.5.7",
104
104
  "@jini-ai/protocol": "^0.4.4"
105
105
  },
106
106
  "dependencies": {
107
107
  "@jini-ai/oauth": "^0.2.2",
108
- "@jini-ai/core": "^0.4.5"
108
+ "@jini-ai/core": "^0.4.6"
109
109
  },
110
110
  "peerDependencies": {
111
111
  "@jini-ai/integrations": "^0.4.2",
@@ -1,24 +0,0 @@
1
- export declare const geminiAgentDef: {
2
- id: string;
3
- name: string;
4
- bin: string;
5
- versionArgs: string[];
6
- versionProbeTimeoutMs: number;
7
- helpArgs: string[];
8
- capabilityFlags: {
9
- "--skip-trust": string;
10
- };
11
- fallbackModels: import("../types.js").RuntimeModelOption[];
12
- buildArgs: ({ prompt: _prompt, imagePaths: _imagePaths }: {
13
- prompt: string;
14
- imagePaths: string[];
15
- }, { extraAllowedDirs, options }?: {
16
- extraAllowedDirs?: string[];
17
- options?: import("../types.js").RuntimeBuildOptions;
18
- runtimeContext?: import("../types.js").RuntimeContext;
19
- } | undefined) => string[];
20
- promptViaStdin: true;
21
- streamFormat: string;
22
- eventParser: string;
23
- };
24
- //# sourceMappingURL=gemini.d.ts.map
@@ -1,81 +0,0 @@
1
- /**
2
- * @module defs/gemini
3
- *
4
- * Google's Gemini CLI (`gemini`, npm `@google/gemini-cli`). Checked against an installed
5
- * `gemini` 0.58.0 (`gemini --help` and the bundled headless code path) and the upstream headless
6
- * docs (<https://geminicli.com/docs/cli/headless>):
7
- *
8
- * - Headless mode starts whenever stdin is not a TTY; the whole piped stdin becomes the prompt
9
- * (`-p` is only needed to pass the prompt in argv, and would be "appended to input on stdin").
10
- * So the prompt goes over stdin, like the Qwen Code fork, which avoids Windows `spawn
11
- * ENAMETOOLONG` on large composed prompts.
12
- * - `--output-format stream-json` emits the JSONL `init` / `message` / `tool_use` /
13
- * `tool_result` / `error` / `result` events that `json-event-stream.ts`'s `gemini` parser
14
- * already reads.
15
- * - `--approval-mode yolo` auto-approves every tool (the `--yolo` alias does the same).
16
- * - Since folder trust landed, a headless run in an untrusted directory exits with "Gemini CLI
17
- * is not running in a trusted directory. To proceed, either use `--skip-trust`, …". The host
18
- * already chose the run's cwd, so the def trusts it for this session only. Older builds
19
- * reject unknown flags, so `--skip-trust` is gated on the `--help` capability probe.
20
- * - `--include-directories` (repeatable) widens the workspace to dirs outside the cwd.
21
- *
22
- * Auth: since 2026-06-18 Google no longer serves Gemini CLI's "Login with Google" for free /
23
- * Google AI Pro / Ultra individual accounts (the run dies with `IneligibleTierError: This client
24
- * is no longer supported for Gemini Code Assist for individuals`). A Gemini API key, Vertex AI,
25
- * or a Gemini Code Assist license still works. There is no side-effect-free auth-status
26
- * subcommand, so no `authProbe`; `auth.ts#classifyAgentAuthFailure` turns the failure text into
27
- * setup guidance instead.
28
- */
29
- import { DEFAULT_MODEL_OPTION } from './shared.js';
30
- import { agentCapabilities } from '../capabilities.js';
31
- const SKIP_TRUST_FLAG = '--skip-trust';
32
- export const geminiAgentDef = {
33
- id: 'gemini',
34
- name: 'Gemini CLI',
35
- bin: 'gemini',
36
- versionArgs: ['--version'],
37
- // A cold `gemini --version` took 4.7 s on the dev machine (warm ~2 s), past the 3 s default.
38
- versionProbeTimeoutMs: 10_000,
39
- helpArgs: ['--help'],
40
- capabilityFlags: {
41
- [SKIP_TRUST_FLAG]: 'skipTrust',
42
- },
43
- // No `models` subcommand. `auto` and the concrete ids below are the ones the installed
44
- // 0.58.0 bundle and the upstream model docs name; any other id can still be typed in.
45
- fallbackModels: [
46
- DEFAULT_MODEL_OPTION,
47
- { id: 'auto', label: 'auto' },
48
- { id: 'gemini-3.1-pro-preview', label: 'gemini-3.1-pro-preview' },
49
- { id: 'gemini-3.5-flash', label: 'gemini-3.5-flash' },
50
- { id: 'gemini-3-pro-preview', label: 'gemini-3-pro-preview' },
51
- { id: 'gemini-3-flash-preview', label: 'gemini-3-flash-preview' },
52
- { id: 'gemini-2.5-pro', label: 'gemini-2.5-pro' },
53
- { id: 'gemini-2.5-flash', label: 'gemini-2.5-flash' },
54
- ],
55
- buildArgs: ({ prompt: _prompt, imagePaths: _imagePaths }, { extraAllowedDirs = [], options = {} } = {}) => {
56
- const args = ['--output-format', 'stream-json'];
57
- if (agentCapabilities.get('gemini')?.skipTrust) {
58
- args.push(SKIP_TRUST_FLAG);
59
- }
60
- // See `RuntimeBuildOptions.permissionMode`'s doc: bypass is the default (unchanged
61
- // behavior) unless a caller explicitly opts into a restricted run.
62
- if (options.permissionMode !== 'restricted') {
63
- args.push('--approval-mode', 'yolo');
64
- }
65
- if (options.model && options.model !== 'default') {
66
- args.push('--model', options.model);
67
- }
68
- const dirs = (extraAllowedDirs || []).filter((d) => typeof d === 'string' && d.length > 0);
69
- for (const d of dirs)
70
- args.push('--include-directories', d);
71
- return args;
72
- },
73
- promptViaStdin: true,
74
- streamFormat: 'json-event-stream',
75
- eventParser: 'gemini',
76
- // No `externalMcpInjection` yet: Gemini CLI reads `mcpServers` from `settings.json` (user,
77
- // project `.gemini/settings.json`, or a system file named by
78
- // `GEMINI_CLI_SYSTEM_SETTINGS_PATH`), with no per-run `--mcp-config` flag. A run-scoped
79
- // system-settings file is the likely strategy, but it is not wired or verified live.
80
- };
81
- //# sourceMappingURL=gemini.js.map