@clwnd/opencode 0.3.1 → 0.4.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/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/adiled/clwnd/main/clwnd.gif" alt="clwnd" />
3
+ </p>
4
+
1
5
  ```
2
6
  curl -fsSL https://raw.githubusercontent.com/adiled/clwnd/main/install | bash
3
7
  ```
package/dist/index.js CHANGED
@@ -357,6 +357,15 @@ function extractText(prompt) {
357
357
  }
358
358
  return "";
359
359
  }
360
+ async function getSessionPermissions(client, sessionId) {
361
+ if (!client) return [];
362
+ try {
363
+ const resp = await client.session.get({ path: { sessionID: sessionId } });
364
+ return resp.data?.permission ?? [];
365
+ } catch {
366
+ return [];
367
+ }
368
+ }
360
369
  function parseNDJSON(buffer, sessionId) {
361
370
  const messages = [];
362
371
  const lines = buffer.split("\n");
@@ -385,6 +394,7 @@ var ClwndModel = class {
385
394
  const text = extractText(opts.prompt);
386
395
  const warnings = [];
387
396
  const cwd = this.config.cwd ?? process.cwd();
397
+ const permissions = await getSessionPermissions(this.config.client, sid);
388
398
  let reasoning = "";
389
399
  let responseText = "";
390
400
  const toolCalls = [];
@@ -402,7 +412,8 @@ var ClwndModel = class {
402
412
  opencodeSessionId: sid,
403
413
  cwd,
404
414
  modelId: this.modelId,
405
- text
415
+ text,
416
+ permissions
406
417
  }).then(async (resp) => {
407
418
  if (!resp.body) {
408
419
  abort();
@@ -504,6 +515,7 @@ var ClwndModel = class {
504
515
  const cwd = this.config.cwd ?? process.cwd();
505
516
  const self = this;
506
517
  const toolInputAccum = /* @__PURE__ */ new Map();
518
+ const permissions = await getSessionPermissions(this.config.client, sid);
507
519
  const stream = new ReadableStream({
508
520
  async start(controller) {
509
521
  const textId = generateId();
@@ -542,7 +554,8 @@ var ClwndModel = class {
542
554
  opencodeSessionId: sid,
543
555
  cwd,
544
556
  modelId: self.modelId,
545
- text
557
+ text,
558
+ permissions
546
559
  });
547
560
  } catch (e) {
548
561
  emit({ type: "error", error: new Error(String(e)) });
@@ -643,13 +656,17 @@ var ClwndModel = class {
643
656
  emit({ type: "reasoning-end", id: reasoningId });
644
657
  }
645
658
  const u = msg.usage;
659
+ const cacheRead = u?.cache_read_input_tokens ?? 0;
660
+ const cacheWrite = u?.cache_creation_input_tokens ?? 0;
661
+ const inputBase = u?.input_tokens ?? u?.inputTokens ?? 0;
646
662
  emit({
647
663
  type: "finish",
648
664
  finishReason: msg.finishReason ?? "stop",
649
665
  usage: {
650
- inputTokens: u?.input_tokens ?? u?.inputTokens,
666
+ inputTokens: inputBase + cacheRead + cacheWrite,
651
667
  outputTokens: u?.output_tokens ?? u?.outputTokens,
652
- totalTokens: void 0
668
+ totalTokens: void 0,
669
+ cache: { read: cacheRead, write: cacheWrite }
653
670
  },
654
671
  providerMetadata: msg.providerMetadata ?? {}
655
672
  });
@@ -685,11 +702,14 @@ function createClwnd(config = {}) {
685
702
  }
686
703
 
687
704
  // index.ts
688
- var clwndPlugin = async () => ({
689
- models: {
690
- clwnd: createClwnd()
691
- }
692
- });
705
+ var clwndPlugin = async (input) => {
706
+ const provider = createClwnd({ client: input.client });
707
+ return {
708
+ models: {
709
+ clwnd: provider
710
+ }
711
+ };
712
+ };
693
713
  export {
694
714
  ClwndModel,
695
715
  clwndPlugin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clwnd/opencode",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "clwnd for opencode",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",