@clwnd/opencode 0.4.0 → 0.4.2
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 +29 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -343,6 +343,10 @@ function streamCall(msg) {
|
|
|
343
343
|
unix: SOCK_PATH
|
|
344
344
|
});
|
|
345
345
|
}
|
|
346
|
+
function isAuxiliaryCall(opts) {
|
|
347
|
+
const hasTools = Array.isArray(opts.tools) && opts.tools.length > 0;
|
|
348
|
+
return !hasTools;
|
|
349
|
+
}
|
|
346
350
|
function extractText(prompt) {
|
|
347
351
|
for (let i = prompt.length - 1; i >= 0; i--) {
|
|
348
352
|
const m = prompt[i];
|
|
@@ -357,6 +361,21 @@ function extractText(prompt) {
|
|
|
357
361
|
}
|
|
358
362
|
return "";
|
|
359
363
|
}
|
|
364
|
+
function extractSystemPrompt(prompt) {
|
|
365
|
+
const parts = [];
|
|
366
|
+
for (const m of prompt) {
|
|
367
|
+
if (m.role === "system") {
|
|
368
|
+
if (typeof m.content === "string") {
|
|
369
|
+
parts.push(m.content);
|
|
370
|
+
} else if (Array.isArray(m.content)) {
|
|
371
|
+
for (const p of m.content) {
|
|
372
|
+
if (p.type === "text" && p.text) parts.push(p.text);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return parts.join("\n\n");
|
|
378
|
+
}
|
|
360
379
|
async function getSessionPermissions(client, sessionId) {
|
|
361
380
|
if (!client) return [];
|
|
362
381
|
try {
|
|
@@ -390,11 +409,13 @@ var ClwndModel = class {
|
|
|
390
409
|
provider = "clwnd";
|
|
391
410
|
supportedUrls = {};
|
|
392
411
|
async doGenerate(opts) {
|
|
393
|
-
const
|
|
412
|
+
const isTitle = isAuxiliaryCall(opts);
|
|
413
|
+
const sid = isTitle ? `title-${generateId()}` : opts.headers?.["x-opencode-session"] ?? generateId();
|
|
394
414
|
const text = extractText(opts.prompt);
|
|
415
|
+
const systemPrompt = extractSystemPrompt(opts.prompt);
|
|
395
416
|
const warnings = [];
|
|
396
417
|
const cwd = this.config.cwd ?? process.cwd();
|
|
397
|
-
const permissions = await getSessionPermissions(this.config.client, sid);
|
|
418
|
+
const permissions = isTitle ? [] : await getSessionPermissions(this.config.client, sid);
|
|
398
419
|
let reasoning = "";
|
|
399
420
|
let responseText = "";
|
|
400
421
|
const toolCalls = [];
|
|
@@ -413,6 +434,7 @@ var ClwndModel = class {
|
|
|
413
434
|
cwd,
|
|
414
435
|
modelId: this.modelId,
|
|
415
436
|
text,
|
|
437
|
+
systemPrompt,
|
|
416
438
|
permissions
|
|
417
439
|
}).then(async (resp) => {
|
|
418
440
|
if (!resp.body) {
|
|
@@ -509,13 +531,15 @@ var ClwndModel = class {
|
|
|
509
531
|
};
|
|
510
532
|
}
|
|
511
533
|
async doStream(opts) {
|
|
512
|
-
const
|
|
534
|
+
const isTitle = isAuxiliaryCall(opts);
|
|
535
|
+
const sid = isTitle ? `title-${generateId()}` : opts.headers?.["x-opencode-session"] ?? generateId();
|
|
513
536
|
const text = extractText(opts.prompt);
|
|
537
|
+
const systemPrompt = extractSystemPrompt(opts.prompt);
|
|
514
538
|
const warnings = [];
|
|
515
539
|
const cwd = this.config.cwd ?? process.cwd();
|
|
516
540
|
const self = this;
|
|
517
541
|
const toolInputAccum = /* @__PURE__ */ new Map();
|
|
518
|
-
const permissions = await getSessionPermissions(this.config.client, sid);
|
|
542
|
+
const permissions = isTitle ? [] : await getSessionPermissions(this.config.client, sid);
|
|
519
543
|
const stream = new ReadableStream({
|
|
520
544
|
async start(controller) {
|
|
521
545
|
const textId = generateId();
|
|
@@ -555,6 +579,7 @@ var ClwndModel = class {
|
|
|
555
579
|
cwd,
|
|
556
580
|
modelId: self.modelId,
|
|
557
581
|
text,
|
|
582
|
+
systemPrompt,
|
|
558
583
|
permissions
|
|
559
584
|
});
|
|
560
585
|
} catch (e) {
|