@distlang/opencode-plugin 0.1.9 → 0.1.10
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/package.json +2 -2
- package/src/index.js +8 -0
- package/src/recorder.js +104 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distlang/opencode-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "OpenCode plugin for Distlang AI Debugger",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"check": "npm test",
|
|
19
19
|
"pack:check": "npm pack --dry-run",
|
|
20
20
|
"release": "npm test && npm run pack:check",
|
|
21
|
-
"publish": "npm publish --access public"
|
|
21
|
+
"publish:public": "npm publish --access public"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"distlang",
|
package/src/index.js
CHANGED
|
@@ -395,6 +395,14 @@ export const DistlangAIDebugger = async ({ project, directory, client }) => {
|
|
|
395
395
|
return;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
if (event.type === "message.part.updated") {
|
|
399
|
+
const observed = recorder.observeMessagePartUpdated(event);
|
|
400
|
+
if (observed) {
|
|
401
|
+
await debugLog("message.part.updated observed", observed);
|
|
402
|
+
}
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
398
406
|
if (event.type !== "message.updated") {
|
|
399
407
|
return;
|
|
400
408
|
}
|
package/src/recorder.js
CHANGED
|
@@ -63,6 +63,9 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
63
63
|
interactionCounter: 0,
|
|
64
64
|
stepCounter: 0,
|
|
65
65
|
assistantStates: new Map(),
|
|
66
|
+
messageRoles: new Map(),
|
|
67
|
+
messageTextParts: new Map(),
|
|
68
|
+
messageInteractions: new Map(),
|
|
66
69
|
toolStarts: new Map(),
|
|
67
70
|
seenUserMessages: new Set(),
|
|
68
71
|
};
|
|
@@ -103,6 +106,33 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
103
106
|
return createInteraction(recorder, configuredValue(prompt, recorder.initialPrompt), timestampMs);
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
function observeUserPrompt(recorder, messageID, prompt, timestampMs) {
|
|
110
|
+
const cleanPrompt = sanitizeDebuggerText(prompt);
|
|
111
|
+
const existingID = recorder.messageInteractions.get(messageID);
|
|
112
|
+
const existing = existingID ? findInteraction(recorder, existingID) : null;
|
|
113
|
+
if (existing) {
|
|
114
|
+
existing.prompt = cleanPrompt;
|
|
115
|
+
existing.summary = summarizePrompt(cleanPrompt, existing.summary || `Interaction ${existing.index}`);
|
|
116
|
+
return existing;
|
|
117
|
+
}
|
|
118
|
+
const current = findInteraction(recorder, recorder.currentInteractionID);
|
|
119
|
+
const currentHasMessage = Array.from(recorder.messageInteractions.values()).includes(current?.id);
|
|
120
|
+
if (current && isGenericInteractionLabel(current.prompt) && !currentHasMessage) {
|
|
121
|
+
current.prompt = cleanPrompt;
|
|
122
|
+
current.summary = summarizePrompt(cleanPrompt, `Interaction ${current.index}`);
|
|
123
|
+
recorder.messageInteractions.set(messageID, current.id);
|
|
124
|
+
recorder.seenUserMessages.add(messageID);
|
|
125
|
+
return current;
|
|
126
|
+
}
|
|
127
|
+
if (recorder.seenUserMessages.has(messageID)) {
|
|
128
|
+
return current || createInteraction(recorder, cleanPrompt, timestampMs);
|
|
129
|
+
}
|
|
130
|
+
recorder.seenUserMessages.add(messageID);
|
|
131
|
+
const interaction = createInteraction(recorder, cleanPrompt, timestampMs);
|
|
132
|
+
recorder.messageInteractions.set(messageID, interaction.id);
|
|
133
|
+
return interaction;
|
|
134
|
+
}
|
|
135
|
+
|
|
106
136
|
function addStep(recorder, interaction, step) {
|
|
107
137
|
recorder.stepCounter += 1;
|
|
108
138
|
const normalized = {
|
|
@@ -192,13 +222,35 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
192
222
|
}
|
|
193
223
|
const recorder = ensureSession(sessionID, Date.now());
|
|
194
224
|
const id = messageID(info) || `${sessionID}:user:${Date.now()}`;
|
|
195
|
-
|
|
196
|
-
|
|
225
|
+
recorder.messageRoles.set(id, "user");
|
|
226
|
+
const prompt = extractMessageText(info) || storedMessageText(recorder, id);
|
|
227
|
+
if (!prompt) {
|
|
228
|
+
return { sessionID, messageID: id, prompt: "" };
|
|
229
|
+
}
|
|
230
|
+
const interaction = observeUserPrompt(recorder, id, prompt, parseMessageTime(info, Date.now()));
|
|
231
|
+
return { sessionID, messageID: id, prompt: interaction.prompt };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function observeMessagePartUpdated(event) {
|
|
235
|
+
const part = extractMessagePart(event);
|
|
236
|
+
if (!part || part.type !== "text") {
|
|
197
237
|
return null;
|
|
198
238
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
239
|
+
const sessionID = configuredValue(part.sessionID, activeSessionID());
|
|
240
|
+
const messageID = configuredValue(part.messageID, "");
|
|
241
|
+
const partID = configuredValue(part.id, "");
|
|
242
|
+
const text = sanitizeDebuggerText(configuredValue(part.text, configuredValue(event?.properties?.delta, "")));
|
|
243
|
+
if (!sessionID || !messageID || !partID || !text) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const recorder = ensureSession(sessionID, Date.now());
|
|
247
|
+
storeMessageTextPart(recorder, messageID, partID, text);
|
|
248
|
+
const role = recorder.messageRoles.get(messageID);
|
|
249
|
+
if (role !== "user") {
|
|
250
|
+
return { sessionID, messageID, role: configuredValue(role, "unknown"), text };
|
|
251
|
+
}
|
|
252
|
+
const interaction = observeUserPrompt(recorder, messageID, storedMessageText(recorder, messageID), parsePartTime(part, Date.now()));
|
|
253
|
+
return { sessionID, messageID, role, text: interaction.prompt };
|
|
202
254
|
}
|
|
203
255
|
|
|
204
256
|
function observeAssistantMessage(event) {
|
|
@@ -212,6 +264,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
212
264
|
return null;
|
|
213
265
|
}
|
|
214
266
|
const recorder = ensureSession(sessionID, Date.now());
|
|
267
|
+
recorder.messageRoles.set(id, "assistant");
|
|
215
268
|
const interaction = ensureInteraction(recorder, Date.now());
|
|
216
269
|
const now = Date.now();
|
|
217
270
|
const existing = recorder.assistantStates.get(id) || {
|
|
@@ -232,10 +285,11 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
232
285
|
if (finalState.isFinal && !existing.finalized) {
|
|
233
286
|
existing.finalized = true;
|
|
234
287
|
const targetInteraction = findInteraction(recorder, existing.interactionID) || interaction;
|
|
288
|
+
const assistantText = extractMessageText(info) || storedMessageText(recorder, id);
|
|
235
289
|
addStep(recorder, targetInteraction, {
|
|
236
290
|
kind: "llm_call",
|
|
237
291
|
phase: targetInteraction.mode,
|
|
238
|
-
title: summarizePrompt(
|
|
292
|
+
title: summarizePrompt(assistantText, `Assistant response ${targetInteraction.index}`),
|
|
239
293
|
started_at: new Date(existing.firstSeenAt).toISOString(),
|
|
240
294
|
ended_at: new Date(now).toISOString(),
|
|
241
295
|
duration_ms: Math.max(0, now - existing.firstSeenAt),
|
|
@@ -350,6 +404,7 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
350
404
|
setSessionTitle,
|
|
351
405
|
observeFileEdited,
|
|
352
406
|
observeUserMessage,
|
|
407
|
+
observeMessagePartUpdated,
|
|
353
408
|
observeAssistantMessage,
|
|
354
409
|
observeToolBefore,
|
|
355
410
|
observeToolAfter,
|
|
@@ -358,6 +413,20 @@ export function createRecorder({ project, directory, initialPrompt = "" }) {
|
|
|
358
413
|
};
|
|
359
414
|
}
|
|
360
415
|
|
|
416
|
+
function storeMessageTextPart(recorder, messageID, partID, text) {
|
|
417
|
+
const parts = recorder.messageTextParts.get(messageID) || new Map();
|
|
418
|
+
parts.set(partID, sanitizeDebuggerText(text));
|
|
419
|
+
recorder.messageTextParts.set(messageID, parts);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function storedMessageText(recorder, messageID) {
|
|
423
|
+
const parts = recorder.messageTextParts.get(messageID);
|
|
424
|
+
if (!parts) {
|
|
425
|
+
return "";
|
|
426
|
+
}
|
|
427
|
+
return sanitizeDebuggerText(Array.from(parts.values()).filter(Boolean).join("\n"));
|
|
428
|
+
}
|
|
429
|
+
|
|
361
430
|
function buildSessionPayload(recorder) {
|
|
362
431
|
const sessionTitle = sanitizeDebuggerText(recorder.title);
|
|
363
432
|
const interactions = recorder.interactions.map((interaction) => buildInteractionPayload(interaction, sessionTitle));
|
|
@@ -485,6 +554,35 @@ function extractMessageInfo(event) {
|
|
|
485
554
|
return null;
|
|
486
555
|
}
|
|
487
556
|
|
|
557
|
+
function extractMessagePart(event) {
|
|
558
|
+
if (!event || typeof event !== "object") {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
if (event.part && typeof event.part === "object") {
|
|
562
|
+
return event.part;
|
|
563
|
+
}
|
|
564
|
+
if (event.properties && event.properties.part && typeof event.properties.part === "object") {
|
|
565
|
+
return event.properties.part;
|
|
566
|
+
}
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function parseMessageTime(info, fallback) {
|
|
571
|
+
const time = info && info.time;
|
|
572
|
+
if (time && typeof time === "object") {
|
|
573
|
+
return parseTimestamp(time.created, fallback);
|
|
574
|
+
}
|
|
575
|
+
return parseTimestamp(time, fallback);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function parsePartTime(part, fallback) {
|
|
579
|
+
const time = part && part.time;
|
|
580
|
+
if (time && typeof time === "object") {
|
|
581
|
+
return parseTimestamp(time.start ?? time.created, fallback);
|
|
582
|
+
}
|
|
583
|
+
return parseTimestamp(time, fallback);
|
|
584
|
+
}
|
|
585
|
+
|
|
488
586
|
function isAssistantMessage(info) {
|
|
489
587
|
if (!info || typeof info !== "object") {
|
|
490
588
|
return false;
|