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