@jini-ai/agent-runtime 0.2.0 → 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 +8 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/agent-protocol/pi-rpc/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/agent-protocol/pi-rpc/events.ts"],"names":[],"mappings":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,EAAE,cAAc,GAAG,IAAI,CAEtF;AAMD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAQpH;AAaD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI,CAOlG;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAKvC;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAQpF;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAqBlF;AAMD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAOhF;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAGlF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAGjF;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAW9E;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,YAAY,GAChB,WAAW,GAAG,IAAI,CAGpB"}
|
|
@@ -1,4 +1,191 @@
|
|
|
1
1
|
import { getRecord } from './internal.js';
|
|
2
|
+
export function handleAgentStart(_raw, send) {
|
|
3
|
+
send('agent', { type: 'status', label: 'working' });
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
export function handleAgentEnd() {
|
|
7
|
+
return 'agent_end';
|
|
8
|
+
}
|
|
9
|
+
export function handleTurnStart(_raw, send) {
|
|
10
|
+
send('agent', { type: 'status', label: 'thinking' });
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
/** Extracts the subset of pi's `message.usage` fields the daemon reports as token usage. */
|
|
14
|
+
export function buildTokenUsage(u) {
|
|
15
|
+
const usage = {};
|
|
16
|
+
if (typeof u.input === 'number')
|
|
17
|
+
usage.input_tokens = u.input;
|
|
18
|
+
if (typeof u.output === 'number')
|
|
19
|
+
usage.output_tokens = u.output;
|
|
20
|
+
if (typeof u.cacheRead === 'number')
|
|
21
|
+
usage.cached_read_tokens = u.cacheRead;
|
|
22
|
+
if (typeof u.cacheWrite === 'number')
|
|
23
|
+
usage.cached_write_tokens = u.cacheWrite;
|
|
24
|
+
if (typeof u.totalTokens === 'number')
|
|
25
|
+
usage.total_tokens = u.totalTokens;
|
|
26
|
+
return usage;
|
|
27
|
+
}
|
|
28
|
+
export function emitTurnEndUsage(u, send, ctx) {
|
|
29
|
+
const usage = buildTokenUsage(u);
|
|
30
|
+
if (Object.keys(usage).length === 0)
|
|
31
|
+
return;
|
|
32
|
+
const cost = getRecord(u.cost);
|
|
33
|
+
send('agent', {
|
|
34
|
+
type: 'usage',
|
|
35
|
+
usage,
|
|
36
|
+
costUsd: cost?.total ?? cost?.totalCost ?? null,
|
|
37
|
+
durationMs: Date.now() - ctx.runStartedAt,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function emitTurnEndErrorIfPresent(message, raw, send) {
|
|
41
|
+
if (message?.stopReason !== 'error')
|
|
42
|
+
return;
|
|
43
|
+
const messageText = typeof message.errorMessage === 'string' && message.errorMessage.length > 0
|
|
44
|
+
? message.errorMessage
|
|
45
|
+
: 'Pi agent error';
|
|
46
|
+
send('agent', { type: 'error', message: messageText, raw });
|
|
47
|
+
}
|
|
48
|
+
export function handleTurnEnd(raw, send, ctx) {
|
|
49
|
+
const message = getRecord(raw.message);
|
|
50
|
+
const messageUsage = getRecord(message?.usage);
|
|
51
|
+
if (messageUsage)
|
|
52
|
+
emitTurnEndUsage(messageUsage, send, ctx);
|
|
53
|
+
emitTurnEndErrorIfPresent(message, raw, send);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
export function handleAssistantTextDelta(ev, send, ctx) {
|
|
57
|
+
if (typeof ev.delta !== 'string')
|
|
58
|
+
return;
|
|
59
|
+
if (!ctx.sentFirstToken.value) {
|
|
60
|
+
ctx.sentFirstToken.value = true;
|
|
61
|
+
send('agent', {
|
|
62
|
+
type: 'status',
|
|
63
|
+
label: 'streaming',
|
|
64
|
+
ttftMs: Date.now() - ctx.runStartedAt,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
send('agent', { type: 'text_delta', delta: ev.delta });
|
|
68
|
+
}
|
|
69
|
+
export function handleAssistantThinkingDelta(ev, send) {
|
|
70
|
+
if (typeof ev.delta !== 'string')
|
|
71
|
+
return;
|
|
72
|
+
send('agent', { type: 'thinking_delta', delta: ev.delta });
|
|
73
|
+
}
|
|
74
|
+
export function handleAssistantThinkingStart(_ev, send) {
|
|
75
|
+
send('agent', { type: 'thinking_start' });
|
|
76
|
+
}
|
|
77
|
+
export function handleAssistantThinkingEnd(_ev, send) {
|
|
78
|
+
send('agent', { type: 'thinking_end' });
|
|
79
|
+
}
|
|
80
|
+
// pi's RPC protocol emits a message_update with error delta when
|
|
81
|
+
// the model returns an error (e.g. aborted, context overflow).
|
|
82
|
+
// Surface it so sendAgentEvent's error-handling path sets
|
|
83
|
+
// agentStreamError and the run flips to `failed` on close.
|
|
84
|
+
export function handleAssistantError(ev, send, _ctx, raw) {
|
|
85
|
+
const message = typeof ev.reason === 'string' && ev.reason.length > 0
|
|
86
|
+
? ev.reason
|
|
87
|
+
: typeof ev.delta === 'string' && ev.delta.length > 0
|
|
88
|
+
? ev.delta
|
|
89
|
+
: 'Agent error';
|
|
90
|
+
send('agent', { type: 'error', message, raw });
|
|
91
|
+
}
|
|
92
|
+
const ASSISTANT_MESSAGE_EVENT_HANDLERS = {
|
|
93
|
+
text_delta: handleAssistantTextDelta,
|
|
94
|
+
thinking_delta: handleAssistantThinkingDelta,
|
|
95
|
+
thinking_start: handleAssistantThinkingStart,
|
|
96
|
+
thinking_end: handleAssistantThinkingEnd,
|
|
97
|
+
error: handleAssistantError,
|
|
98
|
+
};
|
|
99
|
+
export function handleMessageUpdate(raw, send, ctx) {
|
|
100
|
+
const assistantMessageEvent = getRecord(raw.assistantMessageEvent);
|
|
101
|
+
if (!assistantMessageEvent)
|
|
102
|
+
return null;
|
|
103
|
+
const ev = assistantMessageEvent;
|
|
104
|
+
const handler = typeof ev.type === 'string' ? ASSISTANT_MESSAGE_EVENT_HANDLERS[ev.type] : undefined;
|
|
105
|
+
handler?.(ev, send, ctx, raw);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
export function handleMessageEnd() {
|
|
109
|
+
// message_end carries usage (already emitted from turn_end) and
|
|
110
|
+
// tool call blocks (already emitted from tool_execution_start).
|
|
111
|
+
// Nothing to extract here.
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
export function handleToolExecutionStart(raw, send) {
|
|
115
|
+
send('agent', {
|
|
116
|
+
type: 'tool_use',
|
|
117
|
+
id: raw.toolCallId ?? null,
|
|
118
|
+
name: raw.toolName ?? null,
|
|
119
|
+
input: raw.args ?? null,
|
|
120
|
+
});
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
export function handleToolExecutionEnd(raw, send) {
|
|
124
|
+
const result = getRecord(raw.result);
|
|
125
|
+
const content = result?.content;
|
|
126
|
+
const text = Array.isArray(content)
|
|
127
|
+
? content
|
|
128
|
+
.map((c) => {
|
|
129
|
+
const item = getRecord(c);
|
|
130
|
+
return item?.type === 'text' ? String(item.text ?? '') : JSON.stringify(c);
|
|
131
|
+
})
|
|
132
|
+
.join('\n')
|
|
133
|
+
: typeof content === 'string'
|
|
134
|
+
? content
|
|
135
|
+
: '';
|
|
136
|
+
send('agent', {
|
|
137
|
+
type: 'tool_result',
|
|
138
|
+
toolUseId: raw.toolCallId ?? null,
|
|
139
|
+
content: text,
|
|
140
|
+
isError: raw.isError === true,
|
|
141
|
+
});
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
// pi's RPC protocol can emit `extension_error` when an extension
|
|
145
|
+
// throws during a tool call or event handler. Surface it so the
|
|
146
|
+
// daemon's error-handling path (sendAgentEvent → agentStreamError)
|
|
147
|
+
// can flip the run to `failed` and forward a visible SSE error.
|
|
148
|
+
export function handleExtensionError(raw, send) {
|
|
149
|
+
const message = typeof raw.error === 'string' && raw.error.length > 0
|
|
150
|
+
? raw.error
|
|
151
|
+
: 'Extension error';
|
|
152
|
+
send('agent', { type: 'error', message, raw });
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
export function handleCompactionStart(_raw, send) {
|
|
156
|
+
send('agent', { type: 'status', label: 'compacting' });
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
export function handleAutoRetryStart(_raw, send) {
|
|
160
|
+
send('agent', { type: 'status', label: 'retrying' });
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
export function handleAutoRetryEnd(raw, send) {
|
|
164
|
+
// Auto-retry exhausted — the agent is about to give up. Surface
|
|
165
|
+
// the final error so the daemon marks the run as failed rather
|
|
166
|
+
// than silently succeeding with empty output.
|
|
167
|
+
if (raw.success !== false)
|
|
168
|
+
return null;
|
|
169
|
+
const message = typeof raw.finalError === 'string' && raw.finalError.length > 0
|
|
170
|
+
? raw.finalError
|
|
171
|
+
: 'Auto-retry exhausted';
|
|
172
|
+
send('agent', { type: 'error', message, raw });
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const PI_RPC_EVENT_HANDLERS = {
|
|
176
|
+
agent_start: handleAgentStart,
|
|
177
|
+
agent_end: handleAgentEnd,
|
|
178
|
+
turn_start: handleTurnStart,
|
|
179
|
+
turn_end: handleTurnEnd,
|
|
180
|
+
message_update: handleMessageUpdate,
|
|
181
|
+
message_end: handleMessageEnd,
|
|
182
|
+
tool_execution_start: handleToolExecutionStart,
|
|
183
|
+
tool_execution_end: handleToolExecutionEnd,
|
|
184
|
+
extension_error: handleExtensionError,
|
|
185
|
+
compaction_start: handleCompactionStart,
|
|
186
|
+
auto_retry_start: handleAutoRetryStart,
|
|
187
|
+
auto_retry_end: handleAutoRetryEnd,
|
|
188
|
+
};
|
|
2
189
|
/**
|
|
3
190
|
* Maps a single raw pi RPC JSON object to zero or more daemon SSE events,
|
|
4
191
|
* dispatching each through `send`. Returns `'agent_end'` when pi signals the
|
|
@@ -10,158 +197,7 @@ import { getRecord } from './internal.js';
|
|
|
10
197
|
* @returns `'agent_end'` on run completion, `null` otherwise.
|
|
11
198
|
*/
|
|
12
199
|
export function mapPiRpcEvent(raw, send, ctx) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
if (raw.type === 'agent_end') {
|
|
18
|
-
return 'agent_end';
|
|
19
|
-
}
|
|
20
|
-
if (raw.type === 'turn_start') {
|
|
21
|
-
send('agent', { type: 'status', label: 'thinking' });
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
if (raw.type === 'turn_end') {
|
|
25
|
-
const message = getRecord(raw.message);
|
|
26
|
-
const messageUsage = getRecord(message?.usage);
|
|
27
|
-
if (messageUsage) {
|
|
28
|
-
const u = messageUsage;
|
|
29
|
-
const usage = {};
|
|
30
|
-
if (typeof u.input === 'number')
|
|
31
|
-
usage.input_tokens = u.input;
|
|
32
|
-
if (typeof u.output === 'number')
|
|
33
|
-
usage.output_tokens = u.output;
|
|
34
|
-
if (typeof u.cacheRead === 'number')
|
|
35
|
-
usage.cached_read_tokens = u.cacheRead;
|
|
36
|
-
if (typeof u.cacheWrite === 'number')
|
|
37
|
-
usage.cached_write_tokens = u.cacheWrite;
|
|
38
|
-
if (typeof u.totalTokens === 'number')
|
|
39
|
-
usage.total_tokens = u.totalTokens;
|
|
40
|
-
if (Object.keys(usage).length > 0) {
|
|
41
|
-
const cost = getRecord(u.cost);
|
|
42
|
-
send('agent', {
|
|
43
|
-
type: 'usage',
|
|
44
|
-
usage,
|
|
45
|
-
costUsd: cost?.total ?? cost?.totalCost ?? null,
|
|
46
|
-
durationMs: Date.now() - ctx.runStartedAt,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (message?.stopReason === 'error') {
|
|
51
|
-
const messageText = typeof message.errorMessage === 'string' && message.errorMessage.length > 0
|
|
52
|
-
? message.errorMessage
|
|
53
|
-
: 'Pi agent error';
|
|
54
|
-
send('agent', { type: 'error', message: messageText, raw });
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const assistantMessageEvent = getRecord(raw.assistantMessageEvent);
|
|
59
|
-
if (raw.type === 'message_update' && assistantMessageEvent) {
|
|
60
|
-
const ev = assistantMessageEvent;
|
|
61
|
-
if (ev.type === 'text_delta' && typeof ev.delta === 'string') {
|
|
62
|
-
if (!ctx.sentFirstToken.value) {
|
|
63
|
-
ctx.sentFirstToken.value = true;
|
|
64
|
-
send('agent', {
|
|
65
|
-
type: 'status',
|
|
66
|
-
label: 'streaming',
|
|
67
|
-
ttftMs: Date.now() - ctx.runStartedAt,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
send('agent', { type: 'text_delta', delta: ev.delta });
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
if (ev.type === 'thinking_delta' && typeof ev.delta === 'string') {
|
|
74
|
-
send('agent', { type: 'thinking_delta', delta: ev.delta });
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
if (ev.type === 'thinking_start') {
|
|
78
|
-
send('agent', { type: 'thinking_start' });
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
if (ev.type === 'thinking_end') {
|
|
82
|
-
send('agent', { type: 'thinking_end' });
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
// pi's RPC protocol emits a message_update with error delta when
|
|
86
|
-
// the model returns an error (e.g. aborted, context overflow).
|
|
87
|
-
// Surface it so sendAgentEvent's error-handling path sets
|
|
88
|
-
// agentStreamError and the run flips to `failed` on close.
|
|
89
|
-
if (ev.type === 'error') {
|
|
90
|
-
const message = typeof ev.reason === 'string' && ev.reason.length > 0
|
|
91
|
-
? ev.reason
|
|
92
|
-
: typeof ev.delta === 'string' && ev.delta.length > 0
|
|
93
|
-
? ev.delta
|
|
94
|
-
: 'Agent error';
|
|
95
|
-
send('agent', { type: 'error', message, raw });
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
if (raw.type === 'message_end') {
|
|
101
|
-
// message_end carries usage (already emitted from turn_end) and
|
|
102
|
-
// tool call blocks (already emitted from tool_execution_start).
|
|
103
|
-
// Nothing to extract here.
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
if (raw.type === 'tool_execution_start') {
|
|
107
|
-
send('agent', {
|
|
108
|
-
type: 'tool_use',
|
|
109
|
-
id: raw.toolCallId ?? null,
|
|
110
|
-
name: raw.toolName ?? null,
|
|
111
|
-
input: raw.args ?? null,
|
|
112
|
-
});
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
if (raw.type === 'tool_execution_end') {
|
|
116
|
-
const result = getRecord(raw.result);
|
|
117
|
-
const content = result?.content;
|
|
118
|
-
const text = Array.isArray(content)
|
|
119
|
-
? content
|
|
120
|
-
.map((c) => {
|
|
121
|
-
const item = getRecord(c);
|
|
122
|
-
return item?.type === 'text' ? String(item.text ?? '') : JSON.stringify(c);
|
|
123
|
-
})
|
|
124
|
-
.join('\n')
|
|
125
|
-
: typeof content === 'string'
|
|
126
|
-
? content
|
|
127
|
-
: '';
|
|
128
|
-
send('agent', {
|
|
129
|
-
type: 'tool_result',
|
|
130
|
-
toolUseId: raw.toolCallId ?? null,
|
|
131
|
-
content: text,
|
|
132
|
-
isError: raw.isError === true,
|
|
133
|
-
});
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
// pi's RPC protocol can emit `extension_error` when an extension
|
|
137
|
-
// throws during a tool call or event handler. Surface it so the
|
|
138
|
-
// daemon's error-handling path (sendAgentEvent → agentStreamError)
|
|
139
|
-
// can flip the run to `failed` and forward a visible SSE error.
|
|
140
|
-
if (raw.type === 'extension_error') {
|
|
141
|
-
const message = typeof raw.error === 'string' && raw.error.length > 0
|
|
142
|
-
? raw.error
|
|
143
|
-
: 'Extension error';
|
|
144
|
-
send('agent', { type: 'error', message, raw });
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
if (raw.type === 'compaction_start') {
|
|
148
|
-
send('agent', { type: 'status', label: 'compacting' });
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
if (raw.type === 'auto_retry_start') {
|
|
152
|
-
send('agent', { type: 'status', label: 'retrying' });
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
if (raw.type === 'auto_retry_end' && raw.success === false) {
|
|
156
|
-
// Auto-retry exhausted — the agent is about to give up. Surface
|
|
157
|
-
// the final error so the daemon marks the run as failed rather
|
|
158
|
-
// than silently succeeding with empty output.
|
|
159
|
-
const message = typeof raw.finalError === 'string' && raw.finalError.length > 0
|
|
160
|
-
? raw.finalError
|
|
161
|
-
: 'Auto-retry exhausted';
|
|
162
|
-
send('agent', { type: 'error', message, raw });
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
200
|
+
const handler = typeof raw.type === 'string' ? PI_RPC_EVENT_HANDLERS[raw.type] : undefined;
|
|
201
|
+
return handler ? handler(raw, send, ctx) : null;
|
|
166
202
|
}
|
|
167
203
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/agent-protocol/pi-rpc/events.ts"],"names":[],"mappings":"AAOA,OAAO,E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,GAAsC;IAC/D,WAAW,EAAE,gBAAgB;IAC7B,SAAS,EAAE,cAAc;IACzB,UAAU,EAAE,eAAe;IAC3B,QAAQ,EAAE,aAAa;IACvB,cAAc,EAAE,mBAAmB;IACnC,WAAW,EAAE,gBAAgB;IAC7B,oBAAoB,EAAE,wBAAwB;IAC9C,kBAAkB,EAAE,sBAAsB;IAC1C,eAAe,EAAE,oBAAoB;IACrC,gBAAgB,EAAE,qBAAqB;IACvC,gBAAgB,EAAE,oBAAoB;IACtC,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,GAAe,EACf,IAAoB,EACpB,GAAiB;IAEjB,MAAM,OAAO,GAAG,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3F,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC"}
|
|
@@ -43,6 +43,7 @@ export declare const FIRE_AND_FORGET_METHODS: Set<string>;
|
|
|
43
43
|
* @param writable - The child process stdin stream.
|
|
44
44
|
* @param raw - The parsed `extension_ui_request` RPC object from pi's stdout.
|
|
45
45
|
*/
|
|
46
|
+
export declare function firstDialogOptionResult(opts: unknown): Record<string, unknown>;
|
|
46
47
|
export declare function replyExtensionUi(writable: Writable, raw: JsonRecord): void;
|
|
47
48
|
/** Snapshot of `.pi/sessions/` file metadata taken before a prompt is sent. */
|
|
48
49
|
export type PiSessionFileSnapshot = Map<string, {
|
|
@@ -79,6 +80,44 @@ export declare function snapshotPiSessionFiles(cwd: string | undefined): PiSessi
|
|
|
79
80
|
* @returns Absolute path of the changed session file, or `null`.
|
|
80
81
|
*/
|
|
81
82
|
export declare function resolveSessionPathChangedSince(cwd: string | undefined, before: PiSessionFileSnapshot): string | null;
|
|
83
|
+
export declare function piImageMimeType(ext: string): string;
|
|
84
|
+
export declare function isPathUnderRoot(realPath: string, resolvedRoot: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Validates and reads one candidate image path for pi's `images` prompt
|
|
87
|
+
* field: resolves symlinks, re-verifies the resolved path is a regular file
|
|
88
|
+
* under `uploadRoot`, checks the extension allowlist, and enforces the
|
|
89
|
+
* remaining total-byte budget. Returns `null` for any rejection or read
|
|
90
|
+
* failure rather than throwing, so one bad image never fails the whole run.
|
|
91
|
+
*/
|
|
92
|
+
export declare function tryReadImagePayload(imgPath: unknown, uploadRoot: string | undefined, totalBytesSoFar: number): {
|
|
93
|
+
payload: PiImagePayload;
|
|
94
|
+
size: number;
|
|
95
|
+
} | null;
|
|
96
|
+
/**
|
|
97
|
+
* Builds pi's base64-encoded `images` prompt payload from `imagePaths`,
|
|
98
|
+
* subject to `MAX_IMAGE_COUNT` and `MAX_TOTAL_IMAGE_BYTES` budgets to
|
|
99
|
+
* prevent large synchronous base64 reads from blocking the event loop. The
|
|
100
|
+
* daemon's safeImages guard already validated that each path exists under
|
|
101
|
+
* UPLOAD_DIR; see {@link tryReadImagePayload} for the per-path re-checks.
|
|
102
|
+
*/
|
|
103
|
+
export declare function buildPiImagePayloads(imagePaths: string[] | undefined, uploadRoot: string | undefined): PiImagePayload[];
|
|
104
|
+
/**
|
|
105
|
+
* Routes one `response`-type frame from pi's RPC stdout: a rejected parent
|
|
106
|
+
* session fails the run immediately (a resumed turn must not continue
|
|
107
|
+
* without its prior context); an accepted parent session triggers the
|
|
108
|
+
* (previously withheld) prompt send; a rejected prompt fails the run;
|
|
109
|
+
* anything else (an accepted prompt, an unrelated response id) is a no-op.
|
|
110
|
+
* Exported as a free function — it only reads its explicit params and never
|
|
111
|
+
* touches `attachPiRpcSession`'s other session state — so it is directly
|
|
112
|
+
* testable without spinning up a session.
|
|
113
|
+
*/
|
|
114
|
+
export declare function handlePiResponseMessage({ raw, parentSessionRpcId, promptRpcId, fail, sendPromptCommand, }: {
|
|
115
|
+
raw: JsonRecord;
|
|
116
|
+
parentSessionRpcId: number | null;
|
|
117
|
+
promptRpcId: number | null;
|
|
118
|
+
fail: (message: string, code?: string) => void;
|
|
119
|
+
sendPromptCommand: () => void;
|
|
120
|
+
}): void;
|
|
82
121
|
/**
|
|
83
122
|
* Attaches the daemon's run lifecycle to an already-spawned `pi --mode rpc` child process.
|
|
84
123
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/agent-protocol/pi-rpc/session.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGhE,+DAA+D;AAC/D,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,yEAAyE;AACzE,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC;AACrC,wFAAwF;AACxF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,cAAc,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AACF,2FAA2F;AAC3F,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,IAAI,OAAO,CAAC;IACzB,KAAK,IAAI,IAAI,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