@clwnd/opencode 0.3.2 → 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 +51 -9
- 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,30 @@ 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
|
+
}
|
|
380
|
+
async function getSessionPermissions(client, sessionId) {
|
|
381
|
+
if (!client) return [];
|
|
382
|
+
try {
|
|
383
|
+
const resp = await client.session.get({ path: { sessionID: sessionId } });
|
|
384
|
+
return resp.data?.permission ?? [];
|
|
385
|
+
} catch {
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
360
389
|
function parseNDJSON(buffer, sessionId) {
|
|
361
390
|
const messages = [];
|
|
362
391
|
const lines = buffer.split("\n");
|
|
@@ -381,10 +410,13 @@ var ClwndModel = class {
|
|
|
381
410
|
provider = "clwnd";
|
|
382
411
|
supportedUrls = {};
|
|
383
412
|
async doGenerate(opts) {
|
|
384
|
-
const
|
|
413
|
+
const isTitle = isAuxiliaryCall(opts);
|
|
414
|
+
const sid = isTitle ? `title-${generateId()}` : opts.headers?.["x-opencode-session"] ?? generateId();
|
|
385
415
|
const text = extractText(opts.prompt);
|
|
416
|
+
const systemPrompt = extractSystemPrompt(opts.prompt);
|
|
386
417
|
const warnings = [];
|
|
387
418
|
const cwd = this.config.cwd ?? process.cwd();
|
|
419
|
+
const permissions = isTitle ? [] : await getSessionPermissions(this.config.client, sid);
|
|
388
420
|
let reasoning = "";
|
|
389
421
|
let responseText = "";
|
|
390
422
|
const toolCalls = [];
|
|
@@ -402,7 +434,9 @@ var ClwndModel = class {
|
|
|
402
434
|
opencodeSessionId: sid,
|
|
403
435
|
cwd,
|
|
404
436
|
modelId: this.modelId,
|
|
405
|
-
text
|
|
437
|
+
text,
|
|
438
|
+
systemPrompt,
|
|
439
|
+
permissions
|
|
406
440
|
}).then(async (resp) => {
|
|
407
441
|
if (!resp.body) {
|
|
408
442
|
abort();
|
|
@@ -498,12 +532,15 @@ var ClwndModel = class {
|
|
|
498
532
|
};
|
|
499
533
|
}
|
|
500
534
|
async doStream(opts) {
|
|
501
|
-
const
|
|
535
|
+
const isTitle = isAuxiliaryCall(opts);
|
|
536
|
+
const sid = isTitle ? `title-${generateId()}` : opts.headers?.["x-opencode-session"] ?? generateId();
|
|
502
537
|
const text = extractText(opts.prompt);
|
|
538
|
+
const systemPrompt = extractSystemPrompt(opts.prompt);
|
|
503
539
|
const warnings = [];
|
|
504
540
|
const cwd = this.config.cwd ?? process.cwd();
|
|
505
541
|
const self = this;
|
|
506
542
|
const toolInputAccum = /* @__PURE__ */ new Map();
|
|
543
|
+
const permissions = isTitle ? [] : await getSessionPermissions(this.config.client, sid);
|
|
507
544
|
const stream = new ReadableStream({
|
|
508
545
|
async start(controller) {
|
|
509
546
|
const textId = generateId();
|
|
@@ -542,7 +579,9 @@ var ClwndModel = class {
|
|
|
542
579
|
opencodeSessionId: sid,
|
|
543
580
|
cwd,
|
|
544
581
|
modelId: self.modelId,
|
|
545
|
-
text
|
|
582
|
+
text,
|
|
583
|
+
systemPrompt,
|
|
584
|
+
permissions
|
|
546
585
|
});
|
|
547
586
|
} catch (e) {
|
|
548
587
|
emit({ type: "error", error: new Error(String(e)) });
|
|
@@ -689,11 +728,14 @@ function createClwnd(config = {}) {
|
|
|
689
728
|
}
|
|
690
729
|
|
|
691
730
|
// index.ts
|
|
692
|
-
var clwndPlugin = async () =>
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
731
|
+
var clwndPlugin = async (input) => {
|
|
732
|
+
const provider = createClwnd({ client: input.client });
|
|
733
|
+
return {
|
|
734
|
+
models: {
|
|
735
|
+
clwnd: provider
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
};
|
|
697
739
|
export {
|
|
698
740
|
ClwndModel,
|
|
699
741
|
clwndPlugin,
|