@jini-ai/agent-runtime 0.7.3-next.3 → 0.7.4
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 +7 -0
- package/dist/agent-protocol/acp/session-results.d.ts +1 -1
- package/dist/agent-protocol/acp/session-results.js +14 -5
- package/dist/agent-protocol/acp/session-usage.d.ts +12 -0
- package/dist/agent-protocol/acp/session-usage.js +29 -0
- package/dist/agent-protocol/acp/session.d.ts +1 -1
- package/dist/agent-protocol/acp/session.js +7 -2
- package/dist/agent-protocol/pi-rpc/events.js +1 -1
- package/dist/claude-stream-frames.js +1 -1
- package/dist/providers/anthropic-messages.js +3 -2
- package/dist/providers/connection-guard.js +1 -1
- package/dist/providers/google-messages.js +1 -1
- package/dist/providers/openai-chat-request.js +1 -1
- package/dist/providers/tool-loop-verdict.d.ts +1 -0
- package/dist/providers/tool-loop-verdict.js +4 -1
- package/dist/providers/tool-turn.js +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## 0.7.4
|
|
2
|
+
|
|
3
|
+
### Changes
|
|
4
|
+
|
|
5
|
+
- Move vendor configuration and staging behind runtime strategy ports, including Claude, Codex, and OpenCode adapters.
|
|
6
|
+
- Refuse inline Codex MCP configuration that breaks isolation and fit prompt variants at the actual command-line boundary.
|
|
7
|
+
|
|
1
8
|
## 0.7.2
|
|
2
9
|
|
|
3
10
|
### Patch Changes
|
|
@@ -14,7 +14,7 @@ export declare function handleRpcError({ state, effects, obj, error, rpcErr, }:
|
|
|
14
14
|
error: UnknownRecord | null;
|
|
15
15
|
rpcErr: string;
|
|
16
16
|
}, _optional?: Record<string, never>): void;
|
|
17
|
-
/** Handles the `initialize` ack:
|
|
17
|
+
/** Handles the `initialize` ack: restores an advertised session or creates a fresh one. */
|
|
18
18
|
export declare function handleInitializeAck({ state, effects, result }: {
|
|
19
19
|
state: AcpSessionState;
|
|
20
20
|
effects: AcpSessionEffects;
|
|
@@ -64,26 +64,35 @@ function failWithRpcError({ effects, obj, rpcErr, }) {
|
|
|
64
64
|
...(retryable === undefined ? {} : { retryable }),
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
67
|
+
/** Prefer no-replay resume when advertised; older peers still use load. */
|
|
68
|
+
function sessionRestoreMethod({ result }) {
|
|
69
|
+
const capabilities = asObject({ value: result.agentCapabilities });
|
|
70
|
+
const sessions = asObject({ value: capabilities?.sessionCapabilities });
|
|
71
|
+
if (asObject({ value: sessions?.resume }))
|
|
72
|
+
return 'session/resume';
|
|
73
|
+
return capabilities?.loadSession === true ? 'session/load' : null;
|
|
74
|
+
}
|
|
75
|
+
/** Handles the `initialize` ack: restores an advertised session or creates a fresh one. */
|
|
68
76
|
export function handleInitializeAck({ state, effects, result }, _optional = {}) {
|
|
69
77
|
const message = unsupportedAcpProtocolVersionMessage({ protocolVersion: result.protocolVersion });
|
|
70
78
|
if (message) {
|
|
71
79
|
effects.fail(message);
|
|
72
80
|
return;
|
|
73
81
|
}
|
|
74
|
-
|
|
82
|
+
const restoreMethod = sessionRestoreMethod({ result });
|
|
83
|
+
if (effects.resumeSessionId && !restoreMethod) {
|
|
75
84
|
effects.fail('This agent cannot reopen a saved conversation (it does not offer session/load); a new conversation is needed.', { details: { reason: 'load_session_unsupported' } });
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
87
|
state.expectedId = state.nextId;
|
|
79
|
-
if (effects.resumeSessionId) {
|
|
88
|
+
if (effects.resumeSessionId && restoreMethod) {
|
|
80
89
|
// Resume the prior upstream session instead of creating a fresh one.
|
|
81
|
-
effects.writeRpc(state.nextId,
|
|
90
|
+
effects.writeRpc(state.nextId, restoreMethod, {
|
|
82
91
|
...buildAcpSessionNewParams({ cwd: effects.effectiveCwd }, effects.mcpServers
|
|
83
92
|
? { mcpServers: effects.mcpServers, envFormat: effects.envFormat }
|
|
84
93
|
: { envFormat: effects.envFormat }),
|
|
85
94
|
sessionId: effects.resumeSessionId,
|
|
86
|
-
},
|
|
95
|
+
}, restoreMethod);
|
|
87
96
|
}
|
|
88
97
|
else {
|
|
89
98
|
effects.writeRpc(state.nextId, 'session/new', buildAcpSessionNewParams({ cwd: effects.effectiveCwd }, effects.mcpServers ? { mcpServers: effects.mcpServers, envFormat: effects.envFormat } : { envFormat: effects.envFormat }), 'session/new');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AcpSessionEffects, AcpSessionState } from './session-types.js';
|
|
2
|
+
import type { UnknownRecord } from './types.js';
|
|
3
|
+
/** Preserve session snapshots without charging them again as per-turn usage.
|
|
4
|
+
* ACP used/size describe the current context, not billable input/output tokens;
|
|
5
|
+
* cost is cumulative and its unit is not necessarily USD. O(1), no retained state.
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleUsageUpdate({ state, effects, update }: {
|
|
8
|
+
state: Pick<AcpSessionState, 'durableSessionId' | 'sessionId'>;
|
|
9
|
+
effects: Pick<AcpSessionEffects, 'send'>;
|
|
10
|
+
update: UnknownRecord;
|
|
11
|
+
}): void;
|
|
12
|
+
//# sourceMappingURL=session-usage.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { asObject } from './json.js';
|
|
2
|
+
function isTokenCount({ value }) {
|
|
3
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
4
|
+
}
|
|
5
|
+
function sessionCost({ value }) {
|
|
6
|
+
const cost = asObject({ value });
|
|
7
|
+
if (!cost || typeof cost.amount !== 'number' || !Number.isFinite(cost.amount) || cost.amount < 0)
|
|
8
|
+
return null;
|
|
9
|
+
if (typeof cost.currency !== 'string' || !cost.currency.trim())
|
|
10
|
+
return null;
|
|
11
|
+
return { amount: cost.amount, currency: cost.currency };
|
|
12
|
+
}
|
|
13
|
+
/** Preserve session snapshots without charging them again as per-turn usage.
|
|
14
|
+
* ACP used/size describe the current context, not billable input/output tokens;
|
|
15
|
+
* cost is cumulative and its unit is not necessarily USD. O(1), no retained state.
|
|
16
|
+
*/
|
|
17
|
+
export function handleUsageUpdate({ state, effects, update }) {
|
|
18
|
+
if (!isTokenCount({ value: update.used }) || !isTokenCount({ value: update.size }))
|
|
19
|
+
return;
|
|
20
|
+
const cost = sessionCost({ value: update.cost });
|
|
21
|
+
const sessionId = state.durableSessionId ?? state.sessionId;
|
|
22
|
+
effects.send({ event: 'agent', payload: {
|
|
23
|
+
type: 'usage', usage: null,
|
|
24
|
+
contextWindow: { used: update.used, size: update.size },
|
|
25
|
+
...(cost ? { sessionCost: cost } : {}),
|
|
26
|
+
...(cost?.currency === 'USD' && sessionId ? { cumulativeCostUsd: cost.amount, costSessionId: sessionId } : {}),
|
|
27
|
+
} });
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=session-usage.js.map
|
|
@@ -17,7 +17,7 @@ export declare function handleSessionUpdate({ state, effects, update, }: {
|
|
|
17
17
|
*
|
|
18
18
|
* Sequence:
|
|
19
19
|
* 1. Sends `initialize` to confirm the protocol version.
|
|
20
|
-
* 2. Sends `session/new` (or `session/load`
|
|
20
|
+
* 2. Sends `session/new` (or advertised `session/resume`/`session/load` for a saved session).
|
|
21
21
|
* 3. Optionally sends `session/set_model` when a non-default model is requested.
|
|
22
22
|
* 4. Sends `session/prompt` with the user's prompt and any image attachments.
|
|
23
23
|
* 5. Streams `session/update` events to the `send` callback, translating:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @module agent-protocol/acp/session
|
|
2
2
|
* ACP session orchestrator: performs the full initialize → session/new (or
|
|
3
|
-
* session/load) → session/prompt handshake with an already-spawned ACP
|
|
3
|
+
* session/resume or session/load) → session/prompt handshake with an already-spawned ACP
|
|
4
4
|
* subprocess, streams updates to the daemon event bus, handles permission
|
|
5
5
|
* replies, artifact-write mirroring, DSML text suppression, and clean abort.
|
|
6
6
|
* Depends on every other acp/ file and the core JSON-line stream. Consumed by
|
|
@@ -27,6 +27,7 @@ import {} from './session-types.js';
|
|
|
27
27
|
import { handleThoughtChunkUpdate, handleMessageChunkUpdate } from './session-text-updates.js';
|
|
28
28
|
import { handleToolCallUpdate } from './session-tool-updates.js';
|
|
29
29
|
import { handleRpcError, routeResultById } from './session-results.js';
|
|
30
|
+
import { handleUsageUpdate } from './session-usage.js';
|
|
30
31
|
/** Promotes an AMR retry-status `session/update` into a structured account-failure error, if the classifier matches. Returns `true` when it did (and thus failed the session). */
|
|
31
32
|
export function tryPromoteAmrRetryStatus({ effects, update, }, _optional = {}) {
|
|
32
33
|
const promotedPayload = promotedAmrRetryStatusPayload({ update }, { classifier: effects.accountFailureClassifier });
|
|
@@ -67,6 +68,10 @@ function currentModelUpdateId(update) {
|
|
|
67
68
|
}
|
|
68
69
|
/** Routes a `session/update` to its streaming-kind handler (thought, message, tool call). */
|
|
69
70
|
function routeSessionUpdateKind({ state, effects, update, }) {
|
|
71
|
+
if (update.sessionUpdate === 'usage_update') {
|
|
72
|
+
handleUsageUpdate({ state, effects, update });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
70
75
|
if (update.sessionUpdate === 'agent_thought_chunk') {
|
|
71
76
|
handleThoughtChunkUpdate({ state, effects, update });
|
|
72
77
|
return;
|
|
@@ -96,7 +101,7 @@ function resolveAcpSessionOptionDefaults(options) {
|
|
|
96
101
|
*
|
|
97
102
|
* Sequence:
|
|
98
103
|
* 1. Sends `initialize` to confirm the protocol version.
|
|
99
|
-
* 2. Sends `session/new` (or `session/load`
|
|
104
|
+
* 2. Sends `session/new` (or advertised `session/resume`/`session/load` for a saved session).
|
|
100
105
|
* 3. Optionally sends `session/set_model` when a non-default model is requested.
|
|
101
106
|
* 4. Sends `session/prompt` with the user's prompt and any image attachments.
|
|
102
107
|
* 5. Streams `session/update` events to the `send` callback, translating:
|
|
@@ -201,7 +201,7 @@ export function mapPiRpcEvent({ raw, send, ctx }, _optional = {}) {
|
|
|
201
201
|
if (message?.role === 'assistant' && typeof message.model === 'string' && typeof message.provider === 'string') {
|
|
202
202
|
send({ event: 'agent', payload: { type: 'status', label: 'model', model: `${message.provider}/${message.model}` } });
|
|
203
203
|
}
|
|
204
|
-
const handler = typeof raw.type === 'string' ? PI_RPC_EVENT_HANDLERS[raw.type] : undefined;
|
|
204
|
+
const handler = typeof raw.type === 'string' && Object.hasOwn(PI_RPC_EVENT_HANDLERS, raw.type) ? PI_RPC_EVENT_HANDLERS[raw.type] : undefined;
|
|
205
205
|
return handler ? handler(raw, send, ctx) : null;
|
|
206
206
|
}
|
|
207
207
|
//# sourceMappingURL=events.js.map
|
|
@@ -37,7 +37,7 @@ const TASK_STATUS_ALIASES = {
|
|
|
37
37
|
export function normalizeTaskStatus({ value }, _optional = {}) {
|
|
38
38
|
if (typeof value !== 'string')
|
|
39
39
|
return 'pending';
|
|
40
|
-
return TASK_STATUS_ALIASES[value]
|
|
40
|
+
return Object.hasOwn(TASK_STATUS_ALIASES, value) ? TASK_STATUS_ALIASES[value] : 'pending';
|
|
41
41
|
}
|
|
42
42
|
function nextGeneratedRuntimeTaskId(counter) {
|
|
43
43
|
// Coverage-driven refactor (2026-07-18, no behavior change): the
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { redactSecrets } from '@jini-ai/core';
|
|
1
|
+
import { redactSecrets } from '@jini-ai/core/redaction';
|
|
2
2
|
/**
|
|
3
3
|
* @module providers/anthropic-messages
|
|
4
4
|
*
|
|
@@ -394,7 +394,8 @@ async function runSingleAnthropicRequest(options, messages, emitEnd, retry) {
|
|
|
394
394
|
const data = parseAnthropicSseData({ raw: frame.data });
|
|
395
395
|
if (!data)
|
|
396
396
|
return null; // malformed/empty keep-alive frame, or a non-object payload
|
|
397
|
-
const
|
|
397
|
+
const kind = anthropicFrameKind({ data: data, frameEvent: frame.event });
|
|
398
|
+
const handler = Object.hasOwn(ANTHROPIC_FRAME_HANDLERS, kind) ? ANTHROPIC_FRAME_HANDLERS[kind] : undefined;
|
|
398
399
|
if (!handler)
|
|
399
400
|
return null; // `message_stop`, `ping`, or a future event type — nothing to do
|
|
400
401
|
return handler(state, data, onEvent, options.apiKey);
|
|
@@ -45,7 +45,7 @@ import { readProviderResponseText, MAX_PROVIDER_ERROR_BYTES } from './response-t
|
|
|
45
45
|
* that actually matters, the UI accepts one this guard would have refused.
|
|
46
46
|
*/
|
|
47
47
|
import { isLoopbackApiHost, isBlockedExternalApiHostname } from '@jini-ai/core/net';
|
|
48
|
-
import { isIpLiteralHostname } from '@jini-ai/core';
|
|
48
|
+
import { isIpLiteralHostname } from '@jini-ai/core/origin-validation';
|
|
49
49
|
import { trimCharsEnd } from '@jini-ai/core/text';
|
|
50
50
|
/**
|
|
51
51
|
* Synchronous base-URL check: scheme allow-list + literal-hostname block-list.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { redactSecrets } from '@jini-ai/core';
|
|
1
|
+
import { redactSecrets } from '@jini-ai/core/redaction';
|
|
2
2
|
import { createRoleMarkerGuard } from '../role-marker-guard.js';
|
|
3
3
|
import { extractProviderErrorDetail } from './response-text.js';
|
|
4
4
|
import { pinnedFetch } from './connection-guard.js';
|
|
@@ -13,6 +13,7 @@ export interface ToolLoopVerdict<R extends string> {
|
|
|
13
13
|
* own exit reason stops it, and so does a missing executor: pending tool calls were already emitted
|
|
14
14
|
* as `tool_use` events, so with nothing to run them the turn ends with `'stop'` rather than
|
|
15
15
|
* silently retrying forever. `exitReason` is only consulted for a turn that has not ended.
|
|
16
|
+
* A tool-turn limit only applies when tools can actually execute; provider errors still win.
|
|
16
17
|
*/
|
|
17
18
|
export declare function toolLoopVerdict<R extends string>({ ended, hasExecutor, exitReason }: {
|
|
18
19
|
ended: boolean;
|
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
* own exit reason stops it, and so does a missing executor: pending tool calls were already emitted
|
|
8
8
|
* as `tool_use` events, so with nothing to run them the turn ends with `'stop'` rather than
|
|
9
9
|
* silently retrying forever. `exitReason` is only consulted for a turn that has not ended.
|
|
10
|
+
* A tool-turn limit only applies when tools can actually execute; provider errors still win.
|
|
10
11
|
*/
|
|
11
12
|
export function toolLoopVerdict({ ended, hasExecutor, exitReason }, _optional = {}) {
|
|
12
13
|
if (ended)
|
|
13
14
|
return { stop: true, emit: null };
|
|
14
|
-
const
|
|
15
|
+
const reason = exitReason();
|
|
16
|
+
// Preserve the pre-extraction missing-executor precedence without hiding Google's empty-turn errors.
|
|
17
|
+
const emit = !hasExecutor && (reason === null || reason === 'max_tool_turns') ? 'stop' : reason;
|
|
15
18
|
return { stop: emit !== null, emit };
|
|
16
19
|
}
|
|
17
20
|
//# sourceMappingURL=tool-loop-verdict.js.map
|
|
@@ -3,7 +3,7 @@ import { runAzureToolTurn } from './azure-chat.js';
|
|
|
3
3
|
import { runGoogleToolTurn } from './google-messages.js';
|
|
4
4
|
import { runOpenAiToolTurn } from './openai-chat.js';
|
|
5
5
|
import {} from './openai-chat-types.js';
|
|
6
|
-
import { createToolNameMap } from '@jini-ai/core';
|
|
6
|
+
import { createToolNameMap } from '@jini-ai/core/tool-exposure';
|
|
7
7
|
import { compileOperationSchema } from './operation-schema.js';
|
|
8
8
|
export { compileOperationSchema } from './operation-schema.js';
|
|
9
9
|
export { googleParametersOf, sanitizeGoogleSchema, findNumericEnumPaths, coerceNumericEnumStringsToNumbers } from './google-schema.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/agent-runtime",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
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": {
|
|
@@ -164,17 +164,17 @@
|
|
|
164
164
|
},
|
|
165
165
|
"devDependencies": {
|
|
166
166
|
"@vitest/coverage-v8": "^3.2.6",
|
|
167
|
-
"@jini-ai/integrations": "^0.7.
|
|
168
|
-
"@jini-ai/platform": "^0.7.
|
|
169
|
-
"@jini-ai/core": "^0.7.
|
|
167
|
+
"@jini-ai/integrations": "^0.7.4",
|
|
168
|
+
"@jini-ai/platform": "^0.7.4",
|
|
169
|
+
"@jini-ai/core": "^0.7.4"
|
|
170
170
|
},
|
|
171
171
|
"dependencies": {
|
|
172
172
|
"smol-toml": "1.9.1",
|
|
173
|
-
"@jini-ai/
|
|
174
|
-
"@jini-ai/
|
|
175
|
-
"@jini-ai/
|
|
176
|
-
"@jini-ai/
|
|
177
|
-
"@jini-ai/platform": "^0.7.
|
|
173
|
+
"@jini-ai/oauth": "^0.7.4",
|
|
174
|
+
"@jini-ai/protocol": "^0.7.4",
|
|
175
|
+
"@jini-ai/integrations": "^0.7.4",
|
|
176
|
+
"@jini-ai/core": "^0.7.4",
|
|
177
|
+
"@jini-ai/platform": "^0.7.4"
|
|
178
178
|
},
|
|
179
179
|
"scripts": {
|
|
180
180
|
"build": "tsc -p tsconfig.json",
|