@cotal-ai/connector-opencode 0.11.2 → 0.11.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/dist/index.js +604 -2
- package/dist/plugin.bundle.js +398 -98
- package/dist/plugin.d.ts.map +1 -1
- package/dist/serve.js +145 -208
- package/dist/tools.d.ts +2 -3
- package/dist/tools.d.ts.map +1 -1
- package/package.json +5 -7
- package/dist/extension.js +0 -231
- package/dist/extension.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plugin.js +0 -501
- package/dist/plugin.js.map +0 -1
- package/dist/serve.js.map +0 -1
- package/dist/tools.js +0 -42
- package/dist/tools.js.map +0 -1
- package/dist/transcript.js +0 -107
- package/dist/transcript.js.map +0 -1
package/dist/transcript.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const MAX_PREVIEW = 700; // tool results — enough to see what happened
|
|
2
|
-
const MAX_CHUNK = 6000; // chars per published message
|
|
3
|
-
function truncate(s, max) {
|
|
4
|
-
return s.length > max ? `${s.slice(0, max - 1)}…` : s;
|
|
5
|
-
}
|
|
6
|
-
/** A tool call's most salient input — mirrors the Claude connector's `salient`. */
|
|
7
|
-
function salient(input) {
|
|
8
|
-
const i = (input ?? {});
|
|
9
|
-
const v = i.command ?? i.filePath ?? i.file_path ?? i.path ?? i.url ?? i.pattern ?? i.description;
|
|
10
|
-
const s = typeof v === "string" ? v : Object.keys(i).length ? JSON.stringify(i) : "";
|
|
11
|
-
return s ? `: ${truncate(s, 300)}` : "";
|
|
12
|
-
}
|
|
13
|
-
/** One OpenCode message Part → the line(s) worth mirroring (empty for reasoning/file/step/etc). */
|
|
14
|
-
function condensePart(part) {
|
|
15
|
-
switch (part?.type) {
|
|
16
|
-
case "text":
|
|
17
|
-
if (part.synthetic || part.ignored || !part.text?.trim())
|
|
18
|
-
return [];
|
|
19
|
-
return [part.text.trim()]; // assistant text in FULL — chunkLines splits it across messages
|
|
20
|
-
case "tool": {
|
|
21
|
-
const head = `⚒ ${part.tool}${salient(part.state?.input)}`;
|
|
22
|
-
const status = part.state?.status;
|
|
23
|
-
if (status === "completed")
|
|
24
|
-
return [head, `→ ${truncate(String(part.state.output ?? ""), MAX_PREVIEW) || "(no output)"}`];
|
|
25
|
-
if (status === "error")
|
|
26
|
-
return [head, `→ ERROR: ${truncate(String(part.state.error ?? ""), MAX_PREVIEW)}`];
|
|
27
|
-
return [head];
|
|
28
|
-
}
|
|
29
|
-
default:
|
|
30
|
-
return []; // reasoning (thinking) omitted; file/step/snapshot/patch skipped
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/** Batch lines into wire-sized chunks, splitting on line boundaries — and hard-splitting any single
|
|
34
|
-
* line longer than `max` (e.g. a long assistant answer/code block) so full text is preserved across
|
|
35
|
-
* messages rather than truncated. */
|
|
36
|
-
function chunkLines(lines, max) {
|
|
37
|
-
const chunks = [];
|
|
38
|
-
let cur = "";
|
|
39
|
-
for (const ln of lines) {
|
|
40
|
-
if (ln.length > max) {
|
|
41
|
-
if (cur) {
|
|
42
|
-
chunks.push(cur);
|
|
43
|
-
cur = "";
|
|
44
|
-
}
|
|
45
|
-
for (let i = 0; i < ln.length; i += max)
|
|
46
|
-
chunks.push(ln.slice(i, i + max));
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (cur && cur.length + ln.length + 1 > max) {
|
|
50
|
-
chunks.push(cur);
|
|
51
|
-
cur = "";
|
|
52
|
-
}
|
|
53
|
-
cur = cur ? `${cur}\n${ln}` : ln;
|
|
54
|
-
}
|
|
55
|
-
if (cur)
|
|
56
|
-
chunks.push(cur);
|
|
57
|
-
return chunks;
|
|
58
|
-
}
|
|
59
|
-
/** An event-driven mirror to `channel`, fed from the plugin's OpenCode event hook. */
|
|
60
|
-
export function createTranscriptMirror(agent, channel) {
|
|
61
|
-
// One turn's worth, cleared every flush. `condensed` keeps each part's already-condensed lines (not
|
|
62
|
-
// the raw part) — tool results truncated to a preview, assistant text kept in full — so noisy tool
|
|
63
|
-
// output never sits in memory at full size. Map insertion order preserves emission order (a later
|
|
64
|
-
// .updated replaces the value, keeping its slot).
|
|
65
|
-
const assistantMsgs = new Set(); // messageIDs whose role is "assistant"
|
|
66
|
-
// Keyed by `${messageID}:${partID}` (NOT partID alone): OpenCode part ids are message-scoped, so a
|
|
67
|
-
// multi-message turn could otherwise collide two parts on the same id and drop output.
|
|
68
|
-
const condensed = new Map();
|
|
69
|
-
const clear = () => {
|
|
70
|
-
condensed.clear();
|
|
71
|
-
assistantMsgs.clear();
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
record(message) {
|
|
75
|
-
const info = message?.info ?? message;
|
|
76
|
-
if (info?.role === "assistant" && typeof info.id === "string")
|
|
77
|
-
assistantMsgs.add(info.id);
|
|
78
|
-
},
|
|
79
|
-
observe(part) {
|
|
80
|
-
if (!part?.id || typeof part.messageID !== "string")
|
|
81
|
-
return;
|
|
82
|
-
const key = `${part.messageID}:${part.id}`;
|
|
83
|
-
const lines = condensePart(part); // condense NOW (tool results truncated) → assistant text kept full
|
|
84
|
-
if (lines.length)
|
|
85
|
-
condensed.set(key, { messageID: part.messageID, lines });
|
|
86
|
-
else
|
|
87
|
-
condensed.delete(key); // a part that condensed to nothing (e.g. reasoning) holds no slot
|
|
88
|
-
},
|
|
89
|
-
async flush() {
|
|
90
|
-
// Collect this turn's assistant lines and clear — each turn's output is published ONCE, then
|
|
91
|
-
// forgotten. Snapshot-then-clear before the await means a duplicate/late session.idle finds an
|
|
92
|
-
// empty buffer and can't republish. Delivery reliability is the CHANNEL's job (NATS/JetStream),
|
|
93
|
-
// not a hand-rolled retry buffer here.
|
|
94
|
-
const lines = [];
|
|
95
|
-
for (const { messageID, lines: ls } of condensed.values())
|
|
96
|
-
if (assistantMsgs.has(messageID))
|
|
97
|
-
lines.push(...ls); // the agent's OWN output, not injected turns
|
|
98
|
-
clear();
|
|
99
|
-
for (const chunk of chunkLines(lines, MAX_CHUNK))
|
|
100
|
-
await agent.send(chunk, channel);
|
|
101
|
-
},
|
|
102
|
-
reset() {
|
|
103
|
-
clear();
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=transcript.js.map
|
package/dist/transcript.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,GAAG,GAAG,CAAC,CAAC,6CAA6C;AACtE,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,8BAA8B;AAEtD,SAAS,QAAQ,CAAC,CAAS,EAAE,GAAW;IACtC,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,mFAAmF;AACnF,SAAS,OAAO,CAAC,KAAc;IAC7B,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAA4B,CAAC;IACnD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,WAAW,CAAC;IAClG,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACrF,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CA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