@clwnd/opencode 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/dist/index.js +72 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -282,6 +282,53 @@ var generateId = createIdGenerator();
|
|
|
282
282
|
var { btoa, atob } = globalThis;
|
|
283
283
|
|
|
284
284
|
// provider.ts
|
|
285
|
+
var MCP_PREFIX = "mcp__clwnd__";
|
|
286
|
+
function mapToolName(name14) {
|
|
287
|
+
if (name14.startsWith(MCP_PREFIX)) return name14.slice(MCP_PREFIX.length);
|
|
288
|
+
return name14;
|
|
289
|
+
}
|
|
290
|
+
var INPUT_FIELD_MAP = {
|
|
291
|
+
read: { file_path: "filePath" },
|
|
292
|
+
edit: { file_path: "filePath", old_string: "oldString", new_string: "newString", replace_all: "replaceAll" },
|
|
293
|
+
write: { file_path: "filePath" },
|
|
294
|
+
bash: {},
|
|
295
|
+
// command, description, timeout are already correct
|
|
296
|
+
glob: {},
|
|
297
|
+
// pattern, path are already correct
|
|
298
|
+
grep: {}
|
|
299
|
+
// pattern, path, include are already correct
|
|
300
|
+
};
|
|
301
|
+
function mapToolInput(toolName, input) {
|
|
302
|
+
const ocName = mapToolName(toolName);
|
|
303
|
+
const fieldMap = INPUT_FIELD_MAP[ocName];
|
|
304
|
+
if (!fieldMap || Object.keys(fieldMap).length === 0) return input;
|
|
305
|
+
try {
|
|
306
|
+
const parsed = JSON.parse(input);
|
|
307
|
+
const mapped = {};
|
|
308
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
309
|
+
mapped[fieldMap[k] ?? k] = v;
|
|
310
|
+
}
|
|
311
|
+
return JSON.stringify(mapped);
|
|
312
|
+
} catch {
|
|
313
|
+
return input;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function parseToolResult(resultText) {
|
|
317
|
+
const metaMatch = resultText.match(/<!--clwnd-meta:(.*?)-->/s);
|
|
318
|
+
let title = "";
|
|
319
|
+
let metadata = {};
|
|
320
|
+
let output = resultText;
|
|
321
|
+
if (metaMatch) {
|
|
322
|
+
output = resultText.replace(/\n?<!--clwnd-meta:.*?-->/s, "").trim();
|
|
323
|
+
try {
|
|
324
|
+
const parsed = JSON.parse(metaMatch[1]);
|
|
325
|
+
title = parsed.title ?? "";
|
|
326
|
+
metadata = parsed.metadata ?? {};
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return { output, title, metadata };
|
|
331
|
+
}
|
|
285
332
|
function defaultSocketPath() {
|
|
286
333
|
const runtime = process.env.XDG_RUNTIME_DIR;
|
|
287
334
|
if (runtime) return `${runtime}/clwnd/clwnd.sock`;
|
|
@@ -383,16 +430,17 @@ var ClwndModel = class {
|
|
|
383
430
|
}
|
|
384
431
|
if (ct === "tool_call" && msg.toolCallId && msg.toolName) {
|
|
385
432
|
const accumulated = toolInputAccum.get(msg.toolCallId) ?? "{}";
|
|
433
|
+
const mapped = mapToolInput(msg.toolName, accumulated);
|
|
386
434
|
let input = {};
|
|
387
435
|
try {
|
|
388
|
-
input = JSON.parse(
|
|
436
|
+
input = JSON.parse(mapped);
|
|
389
437
|
} catch {
|
|
390
438
|
input = {};
|
|
391
439
|
}
|
|
392
440
|
toolCalls.push({
|
|
393
441
|
type: "tool-call",
|
|
394
442
|
toolCallId: msg.toolCallId,
|
|
395
|
-
toolName: msg.toolName,
|
|
443
|
+
toolName: mapToolName(msg.toolName),
|
|
396
444
|
input
|
|
397
445
|
});
|
|
398
446
|
}
|
|
@@ -546,7 +594,7 @@ var ClwndModel = class {
|
|
|
546
594
|
}
|
|
547
595
|
if (ct === "tool_input_start" && msg.toolCallId && msg.toolName) {
|
|
548
596
|
toolInputAccum.set(msg.toolCallId, "");
|
|
549
|
-
emit({ type: "tool-input-start", id: msg.toolCallId, toolName: msg.toolName });
|
|
597
|
+
emit({ type: "tool-input-start", id: msg.toolCallId, toolName: mapToolName(msg.toolName) });
|
|
550
598
|
}
|
|
551
599
|
if (ct === "tool_input_delta" && msg.toolCallId && msg.partialJson) {
|
|
552
600
|
const prev = toolInputAccum.get(msg.toolCallId) ?? "";
|
|
@@ -554,20 +602,35 @@ var ClwndModel = class {
|
|
|
554
602
|
emit({ type: "tool-input-delta", id: msg.toolCallId, delta: msg.partialJson });
|
|
555
603
|
}
|
|
556
604
|
if (ct === "tool_call" && msg.toolCallId && msg.toolName) {
|
|
557
|
-
const
|
|
605
|
+
const ocToolName = mapToolName(msg.toolName);
|
|
606
|
+
if (!toolInputAccum.has(msg.toolCallId)) {
|
|
607
|
+
emit({ type: "tool-input-start", id: msg.toolCallId, toolName: ocToolName });
|
|
608
|
+
}
|
|
609
|
+
const accumulated = toolInputAccum.get(msg.toolCallId);
|
|
610
|
+
let rawInput;
|
|
611
|
+
if (accumulated) {
|
|
612
|
+
rawInput = mapToolInput(msg.toolName, accumulated);
|
|
613
|
+
} else if (msg.input && typeof msg.input === "object") {
|
|
614
|
+
rawInput = mapToolInput(msg.toolName, JSON.stringify(msg.input));
|
|
615
|
+
} else {
|
|
616
|
+
rawInput = "{}";
|
|
617
|
+
}
|
|
558
618
|
emit({
|
|
559
619
|
type: "tool-call",
|
|
560
620
|
toolCallId: msg.toolCallId,
|
|
561
|
-
toolName:
|
|
562
|
-
input:
|
|
621
|
+
toolName: ocToolName,
|
|
622
|
+
input: rawInput,
|
|
563
623
|
providerExecuted: true
|
|
564
624
|
});
|
|
565
625
|
}
|
|
566
|
-
if (ct === "tool_result" && msg.toolCallId) {
|
|
626
|
+
if (ct === "tool_result" && (msg.toolCallId || msg.toolUseId)) {
|
|
627
|
+
const callId = msg.toolCallId ?? msg.toolUseId;
|
|
628
|
+
const raw = msg.result ?? "";
|
|
629
|
+
const { output, title, metadata } = parseToolResult(typeof raw === "string" ? raw : JSON.stringify(raw));
|
|
567
630
|
emit({
|
|
568
631
|
type: "tool-result",
|
|
569
|
-
toolCallId:
|
|
570
|
-
result: { output
|
|
632
|
+
toolCallId: callId,
|
|
633
|
+
result: { output, title, metadata },
|
|
571
634
|
providerExecuted: true
|
|
572
635
|
});
|
|
573
636
|
}
|