agentel 0.2.5 → 0.2.6
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 +35 -22
- package/docs/code-reference.md +19 -10
- package/docs/history-source-handling.md +116 -52
- package/docs/release.md +1 -1
- package/package.json +1 -1
- package/src/archive.js +1 -1
- package/src/canonical-events.js +74 -25
- package/src/cli.js +760 -93
- package/src/doctor.js +2 -0
- package/src/importers/claude.js +309 -11
- package/src/importers/providers.js +22 -0
- package/src/importers.js +403 -14
- package/src/parser-versions.js +1 -0
- package/src/search.js +1 -0
- package/src/sources.js +1 -0
- package/src/web-export-instructions.js +77 -0
package/src/canonical-events.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const crypto = require("crypto");
|
|
4
4
|
const { parserVersionForSource } = require("./parser-versions");
|
|
5
5
|
|
|
6
|
-
const CANONICAL_EVENT_SCHEMA_VERSION = "agentlog.events.
|
|
6
|
+
const CANONICAL_EVENT_SCHEMA_VERSION = "agentlog.events.v2";
|
|
7
7
|
|
|
8
8
|
const EVENT_KINDS = {
|
|
9
9
|
SESSION_STARTED: "session.started",
|
|
@@ -93,6 +93,10 @@ const TOOL_CATEGORY_DEFINITIONS = [
|
|
|
93
93
|
|
|
94
94
|
function normalizeSessionEvents(session, messages, options = {}) {
|
|
95
95
|
const parserVersion = options.parserVersion ?? session.parserVersion ?? parserVersionForSource(session.sourceType);
|
|
96
|
+
const state = {
|
|
97
|
+
toolCallEventIdsByKey: new Map(),
|
|
98
|
+
unmatchedToolCallEventIds: []
|
|
99
|
+
};
|
|
96
100
|
const events = [
|
|
97
101
|
baseEvent(session, {
|
|
98
102
|
messageIndex: -1,
|
|
@@ -114,7 +118,7 @@ function normalizeSessionEvents(session, messages, options = {}) {
|
|
|
114
118
|
})
|
|
115
119
|
];
|
|
116
120
|
for (let index = 0; index < messages.length; index++) {
|
|
117
|
-
events.push(...messageToCanonicalEvents(messages[index], session, { ...options, parserVersion, messageIndex: index }));
|
|
121
|
+
events.push(...messageToCanonicalEvents(messages[index], session, { ...options, parserVersion, messageIndex: index, state }));
|
|
118
122
|
}
|
|
119
123
|
return events;
|
|
120
124
|
}
|
|
@@ -174,31 +178,32 @@ function messageToCanonicalEvents(message, session, options = {}) {
|
|
|
174
178
|
const toolCall = normalizeToolCall(toolCalls[index], metadata.provider || session.provider);
|
|
175
179
|
if (!toolCall) continue;
|
|
176
180
|
const rendered = renderToolCallText(toolCall);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
);
|
|
181
|
+
const event = baseEvent(session, {
|
|
182
|
+
messageIndex,
|
|
183
|
+
ordinal: index + 1,
|
|
184
|
+
kind: EVENT_KINDS.TOOL_CALLED,
|
|
185
|
+
occurredAt,
|
|
186
|
+
parserVersion,
|
|
187
|
+
role: "assistant",
|
|
188
|
+
parentEventId: responseEventId,
|
|
189
|
+
indexed: {
|
|
190
|
+
title: toolCall.title || toolCall.displayName || titleCaseToolName(toolCall.name || "tool"),
|
|
191
|
+
summary: summarize(rendered || toolCall.rawInputSummary || toolCall.argument || ""),
|
|
192
|
+
toolName: toolCall.name || toolCall.displayName || "",
|
|
193
|
+
toolCategory: toolCall.category || "",
|
|
194
|
+
toolIcon: toolCall.icon || "",
|
|
195
|
+
target: toolCall.target || "",
|
|
196
|
+
status: toolCall.status || "tool_call"
|
|
197
|
+
},
|
|
198
|
+
body: { text: rendered, toolCall, toolResult: null }
|
|
199
|
+
});
|
|
200
|
+
rememberToolCallEvent(options.state, toolCall, event.eventId);
|
|
201
|
+
events.push(event);
|
|
198
202
|
}
|
|
199
203
|
|
|
200
204
|
const toolResult = metadata.toolResult ? normalizeToolResult(metadata.toolResult, metadata.provider || session.provider) : role === "tool" ? normalizeToolResult(content, metadata.provider || session.provider) : null;
|
|
201
205
|
if (toolResult) {
|
|
206
|
+
const parentEventId = consumeToolCallEventId(options.state, toolResult);
|
|
202
207
|
events.push(
|
|
203
208
|
baseEvent(session, {
|
|
204
209
|
messageIndex,
|
|
@@ -210,11 +215,12 @@ function messageToCanonicalEvents(message, session, options = {}) {
|
|
|
210
215
|
indexed: {
|
|
211
216
|
title: toolResult.title || toolResult.kind || "Tool result",
|
|
212
217
|
summary: summarize(toolResult.summary || toolResult.output || content),
|
|
213
|
-
toolName: toolResult.kind || "",
|
|
218
|
+
toolName: toolResult.name || toolResult.kind || "",
|
|
214
219
|
toolCategory: toolResult.category || "",
|
|
215
220
|
toolIcon: toolResult.icon || "",
|
|
216
221
|
status: toolResult.status || "completed"
|
|
217
222
|
},
|
|
223
|
+
parentEventId,
|
|
218
224
|
body: { text: toolResult.output || content, toolCall: null, toolResult }
|
|
219
225
|
})
|
|
220
226
|
);
|
|
@@ -223,6 +229,46 @@ function messageToCanonicalEvents(message, session, options = {}) {
|
|
|
223
229
|
return events;
|
|
224
230
|
}
|
|
225
231
|
|
|
232
|
+
function rememberToolCallEvent(state, toolCall, eventId) {
|
|
233
|
+
if (!state || !eventId) return;
|
|
234
|
+
for (const key of toolPairKeys(toolCall)) {
|
|
235
|
+
if (!state.toolCallEventIdsByKey.has(key)) state.toolCallEventIdsByKey.set(key, []);
|
|
236
|
+
state.toolCallEventIdsByKey.get(key).push(eventId);
|
|
237
|
+
}
|
|
238
|
+
state.unmatchedToolCallEventIds.push(eventId);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function consumeToolCallEventId(state, toolResult) {
|
|
242
|
+
if (!state) return "";
|
|
243
|
+
for (const key of toolPairKeys(toolResult)) {
|
|
244
|
+
const values = state.toolCallEventIdsByKey.get(key);
|
|
245
|
+
while (values && values.length) {
|
|
246
|
+
const eventId = values.shift();
|
|
247
|
+
if (consumeUnmatchedToolEventId(state, eventId)) return eventId;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return state.unmatchedToolCallEventIds.shift() || "";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function consumeUnmatchedToolEventId(state, eventId) {
|
|
254
|
+
const index = state.unmatchedToolCallEventIds.indexOf(eventId);
|
|
255
|
+
if (index < 0) return false;
|
|
256
|
+
state.unmatchedToolCallEventIds.splice(index, 1);
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function toolPairKeys(tool) {
|
|
261
|
+
const keys = new Set();
|
|
262
|
+
for (const value of [tool?.id, tool?.callId, tool?.toolCallId, tool?.tool_call_id]) {
|
|
263
|
+
if (value) keys.add(`id:${String(value).trim()}`);
|
|
264
|
+
}
|
|
265
|
+
for (const value of [tool?.name, tool?.toolName, tool?.displayName, tool?.kind]) {
|
|
266
|
+
const key = normalizeToolKey(value);
|
|
267
|
+
if (key) keys.add(`name:${key}`);
|
|
268
|
+
}
|
|
269
|
+
return [...keys];
|
|
270
|
+
}
|
|
271
|
+
|
|
226
272
|
function baseEvent(session, options) {
|
|
227
273
|
const body = options.body || {};
|
|
228
274
|
const indexed = {
|
|
@@ -371,7 +417,7 @@ function normalizeToolCall(raw, provider = "") {
|
|
|
371
417
|
const target = firstString(raw.target, targetFromArguments(parsedArguments));
|
|
372
418
|
return {
|
|
373
419
|
provider: firstString(raw.provider, provider),
|
|
374
|
-
id: firstString(raw.id, raw.callId, raw.tool_call_id) || undefined,
|
|
420
|
+
id: firstString(raw.id, raw.callId, raw.call_id, raw.toolCallId, raw.tool_call_id, raw.toolUseId, raw.tool_use_id) || undefined,
|
|
375
421
|
name,
|
|
376
422
|
displayName,
|
|
377
423
|
rawCategory: rawCategory || undefined,
|
|
@@ -423,6 +469,7 @@ function normalizeToolResult(raw, provider = "") {
|
|
|
423
469
|
const classification = classifyTool("tool_output");
|
|
424
470
|
return {
|
|
425
471
|
provider,
|
|
472
|
+
id: undefined,
|
|
426
473
|
kind: "Tool output",
|
|
427
474
|
title: "Tool result",
|
|
428
475
|
category: classification.category,
|
|
@@ -443,6 +490,8 @@ function normalizeToolResult(raw, provider = "") {
|
|
|
443
490
|
const classification = classifyTool(firstString(raw.toolName, raw.name, kind), rawCategory);
|
|
444
491
|
return {
|
|
445
492
|
provider: firstString(raw.provider, provider),
|
|
493
|
+
id: firstString(raw.id, raw.callId, raw.call_id, raw.toolCallId, raw.tool_call_id, raw.toolUseId, raw.tool_use_id) || undefined,
|
|
494
|
+
name: firstString(raw.name, raw.toolName, raw.tool_name) || undefined,
|
|
446
495
|
kind,
|
|
447
496
|
title: firstString(raw.title, raw.kind, "Tool result"),
|
|
448
497
|
rawCategory: rawCategory || undefined,
|