@clwnd/opencode 0.5.2 → 0.5.3
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 +30 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -289,6 +289,14 @@ try {
|
|
|
289
289
|
mkdirSync(LOG_DIR, { recursive: true });
|
|
290
290
|
} catch {
|
|
291
291
|
}
|
|
292
|
+
function trace(event, data) {
|
|
293
|
+
const parts = [(/* @__PURE__ */ new Date()).toISOString(), event];
|
|
294
|
+
if (data) for (const [k, v] of Object.entries(data)) parts.push(`${k}=${v}`);
|
|
295
|
+
try {
|
|
296
|
+
appendFileSync(LOG_FILE, parts.join(" ") + "\n");
|
|
297
|
+
} catch {
|
|
298
|
+
}
|
|
299
|
+
}
|
|
292
300
|
var MCP_PREFIX = "mcp__clwnd__";
|
|
293
301
|
var TOOL_NAME_MAP = {
|
|
294
302
|
WebFetch: "webfetch",
|
|
@@ -302,7 +310,7 @@ function mapToolName(name14) {
|
|
|
302
310
|
if (name14.startsWith(MCP_PREFIX)) return name14.slice(MCP_PREFIX.length);
|
|
303
311
|
return TOOL_NAME_MAP[name14] ?? name14;
|
|
304
312
|
}
|
|
305
|
-
var BROKERED_TOOLS = /* @__PURE__ */ new Set(["webfetch", "todowrite"]);
|
|
313
|
+
var BROKERED_TOOLS = /* @__PURE__ */ new Set(["webfetch", "websearch", "todowrite"]);
|
|
306
314
|
var INPUT_FIELD_MAP = {
|
|
307
315
|
read: { file_path: "filePath" },
|
|
308
316
|
edit: { file_path: "filePath", old_string: "oldString", new_string: "newString", replace_all: "replaceAll" },
|
|
@@ -378,6 +386,17 @@ function isAuxiliaryCall(opts) {
|
|
|
378
386
|
const hasTools = Array.isArray(opts.tools) && opts.tools.length > 0;
|
|
379
387
|
return !hasTools;
|
|
380
388
|
}
|
|
389
|
+
function isBrokeredToolReturn(prompt) {
|
|
390
|
+
if (prompt.length < 2) return false;
|
|
391
|
+
const last = prompt[prompt.length - 1];
|
|
392
|
+
if (last.role !== "tool" || !Array.isArray(last.content)) return false;
|
|
393
|
+
for (const part of last.content) {
|
|
394
|
+
if (part.type === "tool-result" && part.toolName && BROKERED_TOOLS.has(part.toolName)) {
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
381
400
|
var OC_TO_MCP = {
|
|
382
401
|
read: "read",
|
|
383
402
|
edit: "edit",
|
|
@@ -593,6 +612,16 @@ var ClwndModel = class {
|
|
|
593
612
|
const toolInputAccum = /* @__PURE__ */ new Map();
|
|
594
613
|
const permissions = isTitle ? [] : await getSessionPermissions(this.config.client, sid);
|
|
595
614
|
const allowedTools = isTitle ? [] : deriveAllowedTools(opts);
|
|
615
|
+
if (isBrokeredToolReturn(opts.prompt)) {
|
|
616
|
+
trace("brokered.return", { sid });
|
|
617
|
+
const stream2 = new ReadableStream({
|
|
618
|
+
start(controller) {
|
|
619
|
+
controller.enqueue({ type: "finish", finishReason: "stop", usage: { inputTokens: 0, outputTokens: 0, totalTokens: void 0 }, providerMetadata: {} });
|
|
620
|
+
controller.close();
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
return { stream: stream2, rawCall: { raw: {}, rawHeaders: {} }, warnings };
|
|
624
|
+
}
|
|
596
625
|
const stream = new ReadableStream({
|
|
597
626
|
async start(controller) {
|
|
598
627
|
const textId = generateId();
|