opencode-ipynb 0.1.1 → 0.1.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.
@@ -1,7 +1,6 @@
1
1
  import type { CellRaw } from "../domain/cell.js";
2
2
  import { type OutputFormatOptions } from "./outputs.js";
3
3
  import type { ToolAttachment } from "@opencode-ai/plugin";
4
- import type { SavedAttachment } from "../utils/attachments.js";
5
4
  export interface MarkdownReadOptions {
6
5
  readonly includeOutputs: boolean;
7
6
  readonly includeErrors: boolean;
@@ -14,7 +13,6 @@ export interface MarkdownReadOptions {
14
13
  export interface FormattedCell {
15
14
  readonly rendered: string;
16
15
  readonly attachments: ReadonlyArray<ToolAttachment>;
17
- readonly savedAttachments: ReadonlyArray<SavedAttachment>;
18
16
  }
19
17
  export declare const formatCellMarkdown: (cell: CellRaw, index: number, optsInput?: Partial<MarkdownReadOptions>) => string;
20
18
  export declare const formatCellMarkdownDetailed: (cell: CellRaw, index: number, optsInput?: Partial<MarkdownReadOptions>) => Promise<FormattedCell>;
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/format/markdown.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAA4C,MAAM,mBAAmB,CAAA;AAC1F,OAAO,EAA8D,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAA;AACnH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAE9D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAA;IAC/B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,C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A;CAC9C;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAA;CACpD;AAkJD,eAAO,MAAM,kBAAkB,GAC7B,MAAM,OAAO,EACb,OAAO,MAAM,EACb,YAAW,OAAO,CAAC,mBAAmB,CAAM,KAC3C,MASF,CAAA;AAED,eAAO,MAAM,0BAA0B,GACrC,MAAM,OAAO,EACb,OAAO,MAAM,EACb,YAAW,OAAO,CAAC,mBAAmB,CAAM,KAC3C,OAAO,CAAC,aAAa,CAWvB,CAAA"}
@@ -1,4 +1,3 @@
1
- import { type SavedAttachment } from "../utils/attachments.js";
2
1
  import type { CellRaw } from "../domain/cell.js";
3
2
  import type { NotebookRaw } from "../domain/notebook.js";
4
3
  import type { ToolAttachment } from "@opencode-ai/plugin";
@@ -12,7 +11,6 @@ export interface OutputFormatOptions {
12
11
  export interface FormattedOutput {
13
12
  readonly rendered: string;
14
13
  readonly attachments: ReadonlyArray<ToolAttachment>;
15
- readonly savedAttachments: ReadonlyArray<SavedAttachment>;
16
14
  }
17
15
  export declare const formatOutputs: (cell: CellRaw, optsInput?: Partial<OutputFormatOptions>) => string;
18
16
  export declare const formatOutputsDetailed: (cell: CellRaw, optsInput?: Partial<OutputFormatOptions>) => Promise<FormattedOutput>;
@@ -1 +1 @@
1
- {"version":3,"file":"outputs.d.ts","sourceRoot":"","sources":["../../src/format/outputs.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,EAAE,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MAAM,CAAA;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACpD;AASD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAA;CACpD;AAwHD,eAAO,MAAM,aAAa,GACxB,MAAM,OAAO,EACb,YAAW,OAAO,CAAC,mBAAmB,CAAM,KAC3C,MA0DF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAChC,MAAM,OAAO,EACb,YAAW,OAAO,CAAC,mBAAmB,CAAM,KAC3C,OAAO,CAAC,eAAe,CA8DzB,CAAA;AAED,eAAO,MAAM,yBAAyB,GAAI,UAAU,WAAW,EAAE,UAAU,MAAM,KAAG,MA8BnF,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,EAAE,KAAK,MAAM,KAAG,MAAsC,CAAA"}
package/dist/index.js CHANGED
@@ -27834,10 +27834,6 @@ var CARRIAGE_RETURN_PATTERN = /\r/g;
27834
27834
  var stripAnsi = (text) => text.replace(ANSI_PATTERN, "").replace(CARRIAGE_RETURN_PATTERN, "");
27835
27835
 
27836
27836
  // src/utils/attachments.ts
27837
- import * as fs2 from "fs";
27838
- import * as os from "os";
27839
- import * as path4 from "path";
27840
- import { randomBytes } from "crypto";
27841
27837
  var EXTENSION_BY_MIME = {
27842
27838
  "image/png": "png",
27843
27839
  "image/jpeg": "jpg",
@@ -27850,24 +27846,13 @@ var EXTENSION_BY_MIME = {
27850
27846
  var pickExtensionForMime = (mime) => {
27851
27847
  return EXTENSION_BY_MIME[mime.toLowerCase()];
27852
27848
  };
27853
- var saveBase64Image = async (mime, base643, prefix = "img") => {
27854
- const ext = pickExtensionForMime(mime) ?? "bin";
27855
- const dir = path4.join(os.tmpdir(), "opencode-ipynb", `${prefix}-${process.pid}-${randomBytes(4).toString("hex")}`);
27856
- await fs2.promises.mkdir(dir, { recursive: true });
27857
- const buffer = Buffer.from(base643, "base64");
27858
- const filename = `${prefix}.${ext}`;
27859
- const filePath = path4.join(dir, filename);
27860
- await fs2.promises.writeFile(filePath, buffer);
27861
- return { path: filePath, mime, bytes: buffer.length, filename };
27862
- };
27863
- var formatAttachment = async (a) => {
27864
- const buffer = await fs2.promises.readFile(a.path);
27865
- const data = buffer.toString("base64");
27849
+ var formatAttachment = (mime, base643, filename) => {
27850
+ const ext = pickExtensionForMime(mime);
27866
27851
  return {
27867
27852
  type: "file",
27868
- mime: a.mime,
27869
- url: `data:${a.mime};base64,${data}`,
27870
- filename: a.filename
27853
+ mime,
27854
+ url: `data:${mime};base64,${base643}`,
27855
+ filename: filename ?? `image${ext ? `.${ext}` : ""}`
27871
27856
  };
27872
27857
  };
27873
27858
 
@@ -27970,11 +27955,9 @@ var formatDisplayWithAttachments = async (data, opts, optsInput, collector) => {
27970
27955
  if (isImageMime(mime)) {
27971
27956
  if (typeof value === "string") {
27972
27957
  if (shouldSaveImage(optsInput)) {
27973
- const saved = await saveBase64Image(mime, value);
27974
- const att = await formatAttachment(saved);
27958
+ const att = formatAttachment(mime, value);
27975
27959
  collector.attachments.push(att);
27976
- collector.saved.push(saved);
27977
- lines.push(`- ${mime}: (saved ${humanBytes(saved.bytes)} as image attachment)`);
27960
+ lines.push(`- ${mime}: (attached as image, ${humanBytes(Buffer.byteLength(value, "base64"))})`);
27978
27961
  } else {
27979
27962
  lines.push(`- ${imageNotice(mime, value)}`);
27980
27963
  }
@@ -28084,7 +28067,7 @@ ${e}`);
28084
28067
  var formatOutputsDetailed = async (cell, optsInput = {}) => {
28085
28068
  const opts = defaultOpts(optsInput);
28086
28069
  if (cell.cell_type !== "code") {
28087
- return { rendered: "", attachments: [], savedAttachments: [] };
28070
+ return { rendered: "", attachments: [] };
28088
28071
  }
28089
28072
  const sections = [];
28090
28073
  let stdout = "";
@@ -28092,7 +28075,7 @@ var formatOutputsDetailed = async (cell, optsInput = {}) => {
28092
28075
  const displaySections = [];
28093
28076
  const resultSections = [];
28094
28077
  const errorSections = [];
28095
- const collector = { attachments: [], saved: [] };
28078
+ const collector = { attachments: [] };
28096
28079
  for (const out of cell.outputs) {
28097
28080
  const kind = detectOutputKind(out);
28098
28081
  if (kind === "stream") {
@@ -28137,14 +28120,13 @@ ${r}`);
28137
28120
  ${e}`);
28138
28121
  }
28139
28122
  if (sections.length === 0) {
28140
- return { rendered: "(no output)", attachments: collector.attachments, savedAttachments: collector.saved };
28123
+ return { rendered: "(no output)", attachments: collector.attachments };
28141
28124
  }
28142
28125
  return {
28143
28126
  rendered: sections.join(`
28144
28127
 
28145
28128
  `),
28146
- attachments: collector.attachments,
28147
- savedAttachments: collector.saved
28129
+ attachments: collector.attachments
28148
28130
  };
28149
28131
  };
28150
28132
  var formatNotebookDiagnostics = (notebook, filePath) => {
@@ -28605,7 +28587,6 @@ ${JSON.stringify(cell.metadata, null, 2)}
28605
28587
  lines.push(formatted.rendered);
28606
28588
  }
28607
28589
  collector.attachments.push(...formatted.attachments);
28608
- collector.saved.push(...formatted.savedAttachments);
28609
28590
  } else if (opts.includeErrors) {
28610
28591
  const errOutputs = cell.outputs.filter((o) => o["output_type"] === "error");
28611
28592
  if (errOutputs.length > 0) {
@@ -28615,7 +28596,6 @@ ${JSON.stringify(cell.metadata, null, 2)}
28615
28596
  lines.push("");
28616
28597
  lines.push(formatted.rendered);
28617
28598
  collector.attachments.push(...formatted.attachments);
28618
- collector.saved.push(...formatted.savedAttachments);
28619
28599
  }
28620
28600
  }
28621
28601
  return lines.join(`
@@ -28657,15 +28637,15 @@ ${JSON.stringify(cell.metadata, null, 2)}
28657
28637
  };
28658
28638
  var formatCellMarkdownDetailed = async (cell, index, optsInput = {}) => {
28659
28639
  const opts = defaultReadOpts(optsInput);
28660
- const collector = { attachments: [], saved: [] };
28640
+ const collector = { attachments: [] };
28661
28641
  if (cell.cell_type === "code") {
28662
28642
  const rendered = await formatCodeCellDetailed(cell, index, opts, collector);
28663
- return { rendered, attachments: collector.attachments, savedAttachments: collector.saved };
28643
+ return { rendered, attachments: collector.attachments };
28664
28644
  }
28665
28645
  if (cell.cell_type === "markdown") {
28666
- return { rendered: formatMarkdownCell(cell, index, opts), attachments: [], savedAttachments: [] };
28646
+ return { rendered: formatMarkdownCell(cell, index, opts), attachments: [] };
28667
28647
  }
28668
- return { rendered: formatRawCell(cell, index, opts), attachments: [], savedAttachments: [] };
28648
+ return { rendered: formatRawCell(cell, index, opts), attachments: [] };
28669
28649
  };
28670
28650
 
28671
28651
  // src/services/NotebookReadService.ts
@@ -29422,7 +29402,7 @@ var makeOutputImpl = (pathSvc, fileSvc, permSvc) => {
29422
29402
 
29423
29403
  // src/services/NotebookExportService.ts
29424
29404
  import * as fsp2 from "fs/promises";
29425
- import * as path5 from "path";
29405
+ import * as path4 from "path";
29426
29406
 
29427
29407
  // src/format/diff.ts
29428
29408
  var renderCell = (cell, cellIndex, options) => {
@@ -29649,7 +29629,7 @@ ${rendered}`;
29649
29629
  });
29650
29630
  yield* exports_Effect.tryPromise({
29651
29631
  try: async () => {
29652
- await fsp2.mkdir(path5.dirname(outAbs), { recursive: true });
29632
+ await fsp2.mkdir(path4.dirname(outAbs), { recursive: true });
29653
29633
  await fsp2.writeFile(outAbs, finalRendered, "utf8");
29654
29634
  },
29655
29635
  catch: (err) => new NotebookWriteError({
@@ -30089,8 +30069,8 @@ var makeExecutionImpl = (pathSvc, fileSvc, permSvc, pythonSvc, execOpts) => {
30089
30069
  // src/services/PythonService.ts
30090
30070
  import { spawn as spawn2 } from "child_process";
30091
30071
  import { fileURLToPath } from "url";
30092
- import * as fs3 from "fs";
30093
- import * as path6 from "path";
30072
+ import * as fs2 from "fs";
30073
+ import * as path5 from "path";
30094
30074
  import * as readline from "readline";
30095
30075
  class PythonService extends exports_Context.Tag("@ipynb/PythonService")() {
30096
30076
  }
@@ -30162,13 +30142,13 @@ var findHelperWarned = false;
30162
30142
  var findHelper = (rel) => {
30163
30143
  const candidates = [];
30164
30144
  if (process.cwd())
30165
- candidates.push(path6.resolve(process.cwd(), rel));
30166
- const distDir = path6.dirname(__filename2);
30167
- candidates.push(path6.resolve(distDir, "..", "..", rel));
30168
- candidates.push(path6.resolve(distDir, "..", "..", "..", rel));
30169
- candidates.push(path6.resolve(distDir, "..", rel));
30145
+ candidates.push(path5.resolve(process.cwd(), rel));
30146
+ const distDir = path5.dirname(__filename2);
30147
+ candidates.push(path5.resolve(distDir, "..", "..", rel));
30148
+ candidates.push(path5.resolve(distDir, "..", "..", "..", rel));
30149
+ candidates.push(path5.resolve(distDir, "..", rel));
30170
30150
  for (const c of candidates) {
30171
- if (fs3.existsSync(c))
30151
+ if (fs2.existsSync(c))
30172
30152
  return c;
30173
30153
  }
30174
30154
  if (!findHelperWarned) {
@@ -1,11 +1,4 @@
1
1
  import type { ToolAttachment } from "@opencode-ai/plugin";
2
- export interface SavedAttachment {
3
- readonly path: string;
4
- readonly mime: string;
5
- readonly bytes: number;
6
- readonly filename: string;
7
- }
8
2
  export declare const pickExtensionForMime: (mime: string) => string | undefined;
9
- export declare const saveBase64Image: (mime: string, base64: string, prefix?: string) => Promise<SavedAttachment>;
10
- export declare const formatAttachment: (a: SavedAttachment) => Promise<ToolAttachment>;
3
+ export declare const formatAttachment: (mime: string, base64: string, filename?: string) => ToolAttachment;
11
4
  //# sourceMappingURL=attachments.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../../src/utils/attachments.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAYD,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAE5D,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,SAAQ,MAAc,KACrB,OAAO,CAAC,eAAe,CAazB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAU,GAAG,eAAe,KAAG,OAAO,CAAC,cAAc,CASjF,CAAA"}
1
+ {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../../src/utils/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAYzD,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAE5D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,WAAW,MAAM,KAChB,cAQF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-ipynb",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "OpenCode community plugin that adds robust .ipynb (Jupyter Notebook) support: inspect, read, edit, run, outputs, clean, export, reproducibility reports, and warm kernels.",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.3.13",