@marimo-team/islands 0.23.14-dev19 → 0.23.14-dev21

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.
@@ -6,13 +6,13 @@ import { _ as Logger, c as Objects, g as cn, l as useEventListener, t as Button
6
6
  import { t as require_react } from "./react-DA-nE2FX.js";
7
7
  import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
8
8
  import { r as toast } from "./copy-COam1EG7.js";
9
- import { C as AccordionContent, D as ChatBubbleIcon, Et as createVariableInfoElement, G as cellErrorsAtom, Hn as CircleX, In as Info, Jt as getTableType, Kt as allTablesAtom, Ln as FileText, Lt as jotaiJsonStorage, Mt as generateUUID, On as Wrench, P as base64ToDataURL, Pn as LoaderCircle, Rt as variablesAtom, S as Accordion, Sn as Anchor2, T as AccordionTrigger, V as renderHTML, Vt as PluralWord, X as notebookAtom, Xt as getRequestClient, _ as Boosts, an as ZodLocalStorage, b as AIContextProvider, bn as atomWithStorage, c as Popover, d as PopoverTrigger, en as singleFacet, f as isOutputEmpty, h as DatasourceContextProvider, kn as Trash2, kt as moveToEndOfEditor, n as Spinner, qt as dataSourceConnectionsAtom, r as MarkdownRenderer, t as toPng, u as PopoverContent, un as CellOutputId, v as Sections, w as AccordionItem, x as AIContextRegistry, y as contextToXml, yt as displayCellName, zn as ExternalLink } from "./html-to-image-DBHfshED.js";
9
+ import { An as Wrench, Bt as variablesAtom, C as Accordion, E as AccordionTrigger, F as base64ToDataURL, H as renderHTML, In as LoaderCircle, Jt as allTablesAtom, O as ChatBubbleIcon, Ot as createVariableInfoElement, Pt as generateUUID, Qt as getRequestClient, Rn as Info, S as AIContextRegistry, Sn as atomWithStorage, T as AccordionItem, Ut as PluralWord, Vn as ExternalLink, Wn as CircleX, X as notebookAtom, Xt as getTableType, Yt as dataSourceConnectionsAtom, at as parseHtmlContent, b as contextToXml, c as Popover, d as PopoverTrigger, f as isOutputEmpty, fn as CellOutputId, g as formatDatasourceContextForCell, gt as isTracebackMime, h as DatasourceContextProvider, ht as isMarimoErrorsMime, jn as Trash2, jt as moveToEndOfEditor, mt as isErrorMime, n as Spinner, nn as singleFacet, r as MarkdownRenderer, sn as ZodLocalStorage, t as toPng, u as PopoverContent, v as Boosts, w as AccordionContent, wn as Anchor2, x as AIContextProvider, xt as displayCellName, y as Sections, zn as FileText, zt as jotaiJsonStorage } from "./html-to-image-DLSOS-bE.js";
10
10
  import "./chunk-5FQGJX7Z-BbqSm5gU.js";
11
11
  import { u as createLucideIcon } from "./dist--2Bqjvs0.js";
12
12
  import { C as logNever, I as X, R as ChevronDown, t as Strings } from "./strings-Dq_j3Rxw.js";
13
13
  import { C as DropdownMenuTrigger, a as NumberField, f as DropdownMenu, h as DropdownMenuItem, p as DropdownMenuContent, r as Input } from "./input-BSdZp5Ng.js";
14
14
  import { p as isUrl, v as CircleQuestionMark } from "./toDate-D1Z7ZXWh.js";
15
- import { a as MarimoIncomingMessageEvent, d as Square, f as File$1, n as blobToString, t as processOutput, u as deserializeBlob } from "./process-output-Dw6We6B6.js";
15
+ import { a as MarimoIncomingMessageEvent, d as Square, f as File$1, n as blobToString, t as processOutput, u as deserializeBlob } from "./process-output-B9ysqk1y.js";
16
16
  import "./react-dom-BTJzcVJ9.js";
17
17
  import { t as require_jsx_runtime } from "./jsx-runtime-DebpN0FN.js";
18
18
  import { A as looseObject, B as union, C as any, D as discriminatedUnion, E as custom, H as safeParseAsync, I as record, L as strictObject, M as never, N as number, O as lazy, P as object$1, R as string, S as _null, T as boolean, V as unknown, W as toJSONSchema, b as _enum, k as literal, w as array$1, x as _instanceof } from "./zod-CijjQh4u.js";
@@ -6046,9 +6046,84 @@ function getCellContextData(e18, h, g) {
6046
6046
  consoleOutputs: S
6047
6047
  };
6048
6048
  }
6049
+ function parseCellErrorOutput(e18) {
6050
+ if (isMarimoErrorsMime(e18.mimetype)) {
6051
+ if (!Array.isArray(e18.data)) return null;
6052
+ let h = e18.data.filter((e19) => !e19.type.includes("ancestor"));
6053
+ return h.length === 0 ? null : { errorData: h };
6054
+ }
6055
+ return isTracebackMime(e18.mimetype) ? typeof e18.data != "string" || e18.data.length === 0 ? null : {
6056
+ errorData: [],
6057
+ tracebackHtml: e18.data
6058
+ } : null;
6059
+ }
6060
+ function errorDataHasTraceback(e18) {
6061
+ return e18.some((e19) => "traceback" in e19 && e19.traceback);
6062
+ }
6063
+ function getTracebackFromConsole(e18) {
6064
+ let h = e18 == null ? void 0 : e18.find((e19) => isTracebackMime(e19.mimetype));
6065
+ if (!(!h || typeof h.data != "string" || h.data.length === 0)) return h.data;
6066
+ }
6067
+ function resolveTracebackHtml(e18, h) {
6068
+ if (e18.tracebackHtml) return e18.tracebackHtml;
6069
+ if (!errorDataHasTraceback(e18.errorData)) return getTracebackFromConsole(h);
6070
+ }
6071
+ function getCellErrorEntries(e18) {
6072
+ let { cellIds: h, cellRuntime: g, cellData: _ } = e18.get(notebookAtom), v = [];
6073
+ for (let [e19, y] of h.inOrderIds.entries()) {
6074
+ let h2 = g[y], b = h2.output;
6075
+ if (!b || !isErrorMime(b.mimetype)) continue;
6076
+ let x = parseCellErrorOutput(b);
6077
+ if (!x) continue;
6078
+ let S = displayCellName(_[y].name, e19), C = _[y].lastCodeRun ?? _[y].code;
6079
+ v.push({
6080
+ cellId: y,
6081
+ cellName: S,
6082
+ cellCode: C,
6083
+ errorData: x.errorData,
6084
+ tracebackHtml: resolveTracebackHtml(x, h2.consoleOutputs)
6085
+ });
6086
+ }
6087
+ return v;
6088
+ }
6049
6089
  function describeError(e18) {
6050
6090
  return e18.type === "setup-refs" ? "The setup cell cannot have references" : e18.type === "cycle" ? "This cell is in a cycle" : e18.type === "multiple-defs" ? `The variable '${e18.name}' was defined by another cell` : e18.type === "import-star" || e18.type === "ancestor-stopped" || e18.type === "ancestor-prevented" || e18.type === "exception" || e18.type === "strict-exception" ? e18.msg : e18.type === "interruption" ? "This cell was interrupted and needs to be re-run" : e18.type === "syntax" || e18.type === "unknown" || e18.type === "sql-error" ? e18.msg : e18.type === "internal" ? e18.msg || "An internal error occurred" : (logNever(e18), "Unknown error");
6051
6091
  }
6092
+ function formatSingleError(e18) {
6093
+ let h = describeError(e18);
6094
+ return "traceback" in e18 && e18.traceback && (h += `
6095
+
6096
+ Traceback:
6097
+ ${parseHtmlContent(e18.traceback)}`), h;
6098
+ }
6099
+ function formatCellErrorDetails(e18, h) {
6100
+ let g = [`Code:
6101
+ ${e18.cellCode}`];
6102
+ if (e18.tracebackHtml && g.push(`Traceback:
6103
+ ${parseHtmlContent(e18.tracebackHtml)}`), e18.errorData.length > 0 && g.push(e18.errorData.map((e19) => formatSingleError(e19)).join("\n\n")), e18.errorData.some((e19) => e19.type === "sql-error")) {
6104
+ let _ = formatDatasourceContextForCell(e18.cellId, h);
6105
+ _ && g.push(`Database schema:
6106
+ ${_}`);
6107
+ }
6108
+ return g.join("\n\n");
6109
+ }
6110
+ function formatCellErrorXml(e18, h) {
6111
+ return contextToXml({
6112
+ type: "error",
6113
+ data: {
6114
+ name: e18.cellName || `Cell ${e18.cellId}`,
6115
+ cellId: e18.cellId
6116
+ },
6117
+ details: formatCellErrorDetails(e18, h)
6118
+ });
6119
+ }
6120
+ function summarizeCellError(e18) {
6121
+ var _a;
6122
+ return e18.errorData.length === 1 ? describeError(e18.errorData[0]) : e18.errorData.length > 1 ? `${e18.errorData.length} errors` : e18.tracebackHtml ? ((_a = parseHtmlContent(e18.tracebackHtml).trim().split("\n").find((e19) => e19.trim())) == null ? void 0 : _a.trim()) || "traceback" : "error";
6123
+ }
6124
+ function errorContextName(e18) {
6125
+ return `Error: ${e18.cellName || `Cell ${e18.cellId}`}`;
6126
+ }
6052
6127
  var errorsTxt = new PluralWord("error", "errors"), ErrorContextProvider = class extends AIContextProvider {
6053
6128
  constructor(e18) {
6054
6129
  super();
@@ -6058,55 +6133,70 @@ var errorsTxt = new PluralWord("error", "errors"), ErrorContextProvider = class
6058
6133
  this.store = e18;
6059
6134
  }
6060
6135
  getItems() {
6061
- let e18 = this.store.get(cellErrorsAtom);
6062
- return e18.length === 0 ? [] : [{
6136
+ let e18 = getCellErrorEntries(this.store);
6137
+ if (e18.length === 0) return [];
6138
+ let h = [{
6063
6139
  uri: this.asURI("all"),
6064
6140
  name: "Errors",
6065
6141
  type: this.contextType,
6066
6142
  data: {
6067
6143
  type: "all-errors",
6068
- errors: e18.map((e19) => ({
6069
- cellId: e19.cellId,
6070
- cellName: e19.cellName,
6071
- errorData: e19.output.data
6072
- }))
6144
+ errors: e18
6073
6145
  },
6074
6146
  description: "All errors in the notebook"
6075
6147
  }];
6148
+ for (let g of e18) h.push({
6149
+ uri: this.asURI(g.cellId),
6150
+ name: errorContextName(g),
6151
+ type: this.contextType,
6152
+ data: {
6153
+ type: "cell-error",
6154
+ error: g
6155
+ },
6156
+ description: summarizeCellError(g)
6157
+ });
6158
+ return h;
6076
6159
  }
6077
6160
  formatCompletion(e18) {
6078
- return e18.data.type === "all-errors" ? {
6079
- label: "@Errors",
6080
- displayLabel: "Errors",
6081
- detail: `${e18.data.errors.length} ${errorsTxt.pluralize(e18.data.errors.length)}`,
6082
- type: "error",
6083
- apply: "@Errors",
6084
- section: Sections.ERROR,
6085
- info: () => {
6086
- let h = document.createElement("div");
6087
- h.classList.add("mo-cm-tooltip", "docs-documentation", "min-w-[200px]", "flex", "flex-col", "gap-1", "p-2");
6088
- let g = document.createElement("div");
6089
- g.classList.add("flex", "flex-col", "gap-1");
6090
- let _ = document.createElement("div");
6091
- _.classList.add("font-bold", "text-base"), _.textContent = "Errors", g.append(_);
6092
- let v = document.createElement("div");
6093
- return v.classList.add("text-sm", "text-muted-foreground"), v.textContent = `${e18.data.errors.length} ${errorsTxt.pluralize(e18.data.errors.length)}`, g.append(v), h.append(g), h;
6094
- }
6095
- } : {
6161
+ if (e18.data.type === "all-errors") {
6162
+ let h = e18.data.errors.length;
6163
+ return {
6164
+ label: "@Errors",
6165
+ displayLabel: "Errors",
6166
+ detail: `${h} ${errorsTxt.pluralize(h)}`,
6167
+ type: "error",
6168
+ apply: "@error://all",
6169
+ section: Sections.ERROR,
6170
+ info: () => {
6171
+ let e19 = document.createElement("div");
6172
+ e19.classList.add("mo-cm-tooltip", "docs-documentation", "min-w-[200px]", "flex", "flex-col", "gap-1", "p-2");
6173
+ let g = document.createElement("div");
6174
+ g.classList.add("flex", "flex-col", "gap-1");
6175
+ let _ = document.createElement("div");
6176
+ _.classList.add("font-bold", "text-base"), _.textContent = "Errors", g.append(_);
6177
+ let v = document.createElement("div");
6178
+ return v.classList.add("text-sm", "text-muted-foreground"), v.textContent = `${h} ${errorsTxt.pluralize(h)}`, g.append(v), e19.append(g), e19;
6179
+ }
6180
+ };
6181
+ }
6182
+ if (e18.data.type === "cell-error") {
6183
+ let { error: h } = e18.data;
6184
+ return {
6185
+ ...this.createBasicCompletion(e18, {
6186
+ detail: summarizeCellError(h),
6187
+ type: "error"
6188
+ }),
6189
+ section: Sections.ERROR
6190
+ };
6191
+ }
6192
+ return {
6096
6193
  label: "Error",
6097
6194
  displayLabel: "Error",
6098
6195
  section: Sections.ERROR
6099
6196
  };
6100
6197
  }
6101
6198
  formatContext(e18) {
6102
- let { data: h } = e18;
6103
- return h.errors.map((e19) => contextToXml({
6104
- type: this.contextType,
6105
- data: {
6106
- name: e19.cellName || `Cell ${e19.cellId}`,
6107
- description: e19.errorData.map((e20) => describeError(e20)).join("\n")
6108
- }
6109
- })).join("\n\n");
6199
+ return (e18.data.type === "all-errors" ? e18.data.errors : [e18.data.error]).map((e19) => formatCellErrorXml(e19, this.store)).join("\n\n");
6110
6200
  }
6111
6201
  };
6112
6202
  const contextCallbacks = singleFacet();
@@ -6515,22 +6605,22 @@ var import_compiler_runtime$8 = require_compiler_runtime();
6515
6605
  const ReasoningAccordion = (e18) => {
6516
6606
  let h = (0, import_compiler_runtime$8.c)(13), { reasoning: g, index: _, isStreaming: v } = e18, y = _ === void 0 ? 0 : _, b = v === void 0 ? false : v, [x, S] = import_react.useState("");
6517
6607
  if (!g && !b) return null;
6518
- let C = b ? "reasoning" : x, T;
6519
- h[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (T = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BotMessageSquare, { className: "h-3 w-3" }), h[0] = T) : T = h[0];
6520
- let E = b ? "Thinking" : "View reasoning", D = g.length > 0 && ` (${g.length} chars)`, O;
6521
- h[1] !== E || h[2] !== D ? (O = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionTrigger, {
6608
+ let C = b ? "reasoning" : x, w;
6609
+ h[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (w = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BotMessageSquare, { className: "h-3 w-3" }), h[0] = w) : w = h[0];
6610
+ let T = b ? "Thinking" : "View reasoning", O = g.length > 0 && ` (${g.length} chars)`, k;
6611
+ h[1] !== T || h[2] !== O ? (k = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionTrigger, {
6522
6612
  className: "text-xs text-muted-foreground hover:bg-muted/50 px-2 py-1 h-auto rounded-sm [&[data-state=open]>svg]:rotate-180",
6523
6613
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
6524
6614
  className: "flex items-center gap-2",
6525
6615
  children: [
6616
+ w,
6526
6617
  T,
6527
- E,
6528
- D
6618
+ O
6529
6619
  ]
6530
6620
  })
6531
- }), h[1] = E, h[2] = D, h[3] = O) : O = h[3];
6532
- let k;
6533
- h[4] === g ? k = h[5] : (k = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionContent, {
6621
+ }), h[1] = T, h[2] = O, h[3] = k) : k = h[3];
6622
+ let A;
6623
+ h[4] === g ? A = h[5] : (A = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionContent, {
6534
6624
  className: "pb-2 px-2",
6535
6625
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
6536
6626
  className: "bg-muted/30 border border-muted/50 rounded-md p-3 italic text-muted-foreground/90 relative",
@@ -6539,22 +6629,22 @@ const ReasoningAccordion = (e18) => {
6539
6629
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MarkdownRenderer, { content: g })
6540
6630
  })
6541
6631
  })
6542
- }), h[4] = g, h[5] = k);
6543
- let A;
6544
- h[6] !== O || h[7] !== k ? (A = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AccordionItem, {
6632
+ }), h[4] = g, h[5] = A);
6633
+ let j;
6634
+ h[6] !== k || h[7] !== A ? (j = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AccordionItem, {
6545
6635
  value: "reasoning",
6546
6636
  className: "border-0",
6547
- children: [O, k]
6548
- }), h[6] = O, h[7] = k, h[8] = A) : A = h[8];
6549
- let j;
6550
- return h[9] !== y || h[10] !== C || h[11] !== A ? (j = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Accordion, {
6637
+ children: [k, A]
6638
+ }), h[6] = k, h[7] = A, h[8] = j) : j = h[8];
6639
+ let M;
6640
+ return h[9] !== y || h[10] !== C || h[11] !== j ? (M = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Accordion, {
6551
6641
  type: "single",
6552
6642
  collapsible: true,
6553
6643
  className: "w-full mb-2",
6554
6644
  value: C,
6555
6645
  onValueChange: S,
6556
- children: A
6557
- }, y), h[9] = y, h[10] = C, h[11] = A, h[12] = j) : j = h[12], j;
6646
+ children: j
6647
+ }, y), h[9] = y, h[10] = C, h[11] = j, h[12] = M) : M = h[12], M;
6558
6648
  };
6559
6649
  function formatToolName(e18) {
6560
6650
  return e18.replace("tool-", "");
@@ -6655,47 +6745,47 @@ const ToolErrorCard = (e18) => {
6655
6745
  }, E = [b], h[0] = b, h[1] = T, h[2] = E), import_react.useEffect(T, E);
6656
6746
  let D;
6657
6747
  h[3] === x ? D = h[4] : (D = cn("rounded-md border border-(--red-6) bg-(--red-2)", x), h[3] = x, h[4] = D);
6748
+ let O;
6749
+ h[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (O = () => C(_temp$2), h[5] = O) : O = h[5];
6658
6750
  let k;
6659
- h[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (k = () => C(_temp$2), h[5] = k) : k = h[5];
6751
+ h[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (k = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleX, { className: "h-3.5 w-3.5 shrink-0" }), h[6] = k) : k = h[6];
6660
6752
  let A;
6661
- h[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (A = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleX, { className: "h-3.5 w-3.5 shrink-0" }), h[6] = A) : A = h[6];
6662
- let j;
6663
- h[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (j = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
6753
+ h[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (A = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
6664
6754
  className: "font-semibold",
6665
6755
  children: "Failed:"
6666
- }), h[7] = j) : j = h[7];
6756
+ }), h[7] = A) : A = h[7];
6757
+ let j;
6758
+ h[8] === g ? j = h[9] : (j = formatToolName(g), h[8] = g, h[9] = j);
6667
6759
  let M;
6668
- h[8] === g ? M = h[9] : (M = formatToolName(g), h[8] = g, h[9] = M);
6669
- let N;
6670
- h[10] === M ? N = h[11] : (N = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
6760
+ h[10] === j ? M = h[11] : (M = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
6671
6761
  className: "flex-1 text-left",
6672
6762
  children: [
6673
- j,
6763
+ A,
6674
6764
  " ",
6675
6765
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
6676
6766
  className: "font-mono",
6677
- children: M
6767
+ children: j
6678
6768
  })
6679
6769
  ]
6680
- }), h[10] = M, h[11] = N);
6681
- let P = S && "rotate-180", F;
6682
- h[12] === P ? F = h[13] : (F = cn("h-3.5 w-3.5 shrink-0 transition-transform", P), h[12] = P, h[13] = F);
6770
+ }), h[10] = j, h[11] = M);
6771
+ let N = S && "rotate-180", P;
6772
+ h[12] === N ? P = h[13] : (P = cn("h-3.5 w-3.5 shrink-0 transition-transform", N), h[12] = N, h[13] = P);
6773
+ let F;
6774
+ h[14] === P ? F = h[15] : (F = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: P }), h[14] = P, h[15] = F);
6683
6775
  let I;
6684
- h[14] === F ? I = h[15] : (I = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChevronDown, { className: F }), h[14] = F, h[15] = I);
6685
- let L;
6686
- h[16] !== S || h[17] !== I || h[18] !== N ? (L = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
6776
+ h[16] !== S || h[17] !== F || h[18] !== M ? (I = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
6687
6777
  type: "button",
6688
- onClick: k,
6778
+ onClick: O,
6689
6779
  className: "w-full flex items-center gap-2 px-3 py-2 text-xs text-(--red-11) hover:bg-(--red-3) rounded-md transition-colors",
6690
6780
  "aria-expanded": S,
6691
6781
  children: [
6692
- A,
6693
- N,
6694
- I
6782
+ k,
6783
+ M,
6784
+ F
6695
6785
  ]
6696
- }), h[16] = S, h[17] = I, h[18] = N, h[19] = L) : L = h[19];
6697
- let R;
6698
- h[20] !== y || h[21] !== _ || h[22] !== S ? (R = S && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
6786
+ }), h[16] = S, h[17] = F, h[18] = M, h[19] = I) : I = h[19];
6787
+ let L;
6788
+ h[20] !== y || h[21] !== _ || h[22] !== S ? (L = S && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
6699
6789
  className: "px-3 pb-3 space-y-3 border-t border-(--red-6)/40 pt-3",
6700
6790
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolArgsRenderer, { input: _ }), y && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
6701
6791
  className: "text-xs font-semibold text-(--red-11) mb-1",
@@ -6704,12 +6794,12 @@ const ToolErrorCard = (e18) => {
6704
6794
  className: "bg-(--red-2) border border-(--red-6) rounded p-2 text-xs text-(--red-11) leading-relaxed overflow-auto scrollbar-thin max-h-64 whitespace-pre-wrap",
6705
6795
  children: y
6706
6796
  })] })]
6707
- }), h[20] = y, h[21] = _, h[22] = S, h[23] = R) : R = h[23];
6708
- let z;
6709
- return h[24] !== L || h[25] !== R || h[26] !== D ? (z = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
6797
+ }), h[20] = y, h[21] = _, h[22] = S, h[23] = L) : L = h[23];
6798
+ let R;
6799
+ return h[24] !== I || h[25] !== L || h[26] !== D ? (R = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
6710
6800
  className: D,
6711
- children: [L, R]
6712
- }), h[24] = L, h[25] = R, h[26] = D, h[27] = z) : z = h[27], z;
6801
+ children: [I, L]
6802
+ }), h[24] = I, h[25] = L, h[26] = D, h[27] = R) : R = h[27], R;
6713
6803
  };
6714
6804
  function _temp$2(e18) {
6715
6805
  return !e18;
@@ -6854,41 +6944,41 @@ function getTriggerToneClass(e18) {
6854
6944
  }
6855
6945
  }
6856
6946
  const ToolHistoryRow = (e18) => {
6857
- let h = (0, import_compiler_runtime$3.c)(34), { toolName: g, state: _, input: y, result: b, approval: x, index: S, className: C, isActive: T } = e18, E = S === void 0 ? 0 : S, D = T === void 0 ? true : T, O;
6858
- h[0] !== D || h[1] !== _ ? (O = !D && PENDING_STATES.has(_), h[0] = D, h[1] = _, h[2] = O) : O = h[2];
6859
- let k = O, A = `tool-${E}`, j;
6860
- h[3] === C ? j = h[4] : (j = cn("w-full", C), h[3] = C, h[4] = j);
6861
- let M;
6862
- h[5] !== k || h[6] !== _ ? (M = cn("h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline", k ? "text-muted-foreground" : getTriggerToneClass(_)), h[5] = k, h[6] = _, h[7] = M) : M = h[7];
6947
+ let h = (0, import_compiler_runtime$3.c)(34), { toolName: g, state: _, input: y, result: b, approval: x, index: S, className: C, isActive: w } = e18, T = S === void 0 ? 0 : S, O = w === void 0 ? true : w, k;
6948
+ h[0] !== O || h[1] !== _ ? (k = !O && PENDING_STATES.has(_), h[0] = O, h[1] = _, h[2] = k) : k = h[2];
6949
+ let A = k, j = `tool-${T}`, M;
6950
+ h[3] === C ? M = h[4] : (M = cn("w-full", C), h[3] = C, h[4] = M);
6863
6951
  let N;
6864
- h[8] !== k || h[9] !== _ ? (N = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusIcon, {
6952
+ h[5] !== A || h[6] !== _ ? (N = cn("h-6 text-xs border-border shadow-none! ring-0! bg-muted/60 hover:bg-muted py-0 px-2 gap-1 rounded-sm [&[data-state=open]>svg]:rotate-180 hover:no-underline", A ? "text-muted-foreground" : getTriggerToneClass(_)), h[5] = A, h[6] = _, h[7] = N) : N = h[7];
6953
+ let P;
6954
+ h[8] !== A || h[9] !== _ ? (P = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusIcon, {
6865
6955
  state: _,
6866
- interrupted: k
6867
- }), h[8] = k, h[9] = _, h[10] = N) : N = h[10];
6868
- let P = k ? "Interrupted" : STATUS_LABEL[_], F;
6869
- h[11] === g ? F = h[12] : (F = formatToolName(g), h[11] = g, h[12] = F);
6870
- let I;
6871
- h[13] === F ? I = h[14] : (I = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
6872
- className: "font-mono text-xs",
6873
- children: F
6874
- }), h[13] = F, h[14] = I);
6956
+ interrupted: A
6957
+ }), h[8] = A, h[9] = _, h[10] = P) : P = h[10];
6958
+ let F = A ? "Interrupted" : STATUS_LABEL[_], I;
6959
+ h[11] === g ? I = h[12] : (I = formatToolName(g), h[11] = g, h[12] = I);
6875
6960
  let L;
6876
- h[15] !== I || h[16] !== N || h[17] !== P ? (L = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
6961
+ h[13] === I ? L = h[14] : (L = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
6962
+ className: "font-mono text-xs",
6963
+ children: I
6964
+ }), h[13] = I, h[14] = L);
6965
+ let R;
6966
+ h[15] !== L || h[16] !== P || h[17] !== F ? (R = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
6877
6967
  className: "flex items-center gap-1",
6878
6968
  children: [
6879
- N,
6880
6969
  P,
6970
+ F,
6881
6971
  ":",
6882
- I
6972
+ L
6883
6973
  ]
6884
- }), h[15] = I, h[16] = N, h[17] = P, h[18] = L) : L = h[18];
6885
- let R;
6886
- h[19] !== L || h[20] !== M ? (R = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionTrigger, {
6887
- className: M,
6888
- children: L
6889
- }), h[19] = L, h[20] = M, h[21] = R) : R = h[21];
6974
+ }), h[15] = L, h[16] = P, h[17] = F, h[18] = R) : R = h[18];
6890
6975
  let B;
6891
- h[22] !== x || h[23] !== y || h[24] !== b || h[25] !== _ ? (B = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionContent, {
6976
+ h[19] !== R || h[20] !== N ? (B = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionTrigger, {
6977
+ className: N,
6978
+ children: R
6979
+ }), h[19] = R, h[20] = N, h[21] = B) : B = h[21];
6980
+ let V;
6981
+ h[22] !== x || h[23] !== y || h[24] !== b || h[25] !== _ ? (V = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccordionContent, {
6892
6982
  className: "py-2 px-2",
6893
6983
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HistoryContent, {
6894
6984
  state: _,
@@ -6896,20 +6986,20 @@ const ToolHistoryRow = (e18) => {
6896
6986
  result: b,
6897
6987
  approval: x
6898
6988
  })
6899
- }), h[22] = x, h[23] = y, h[24] = b, h[25] = _, h[26] = B) : B = h[26];
6989
+ }), h[22] = x, h[23] = y, h[24] = b, h[25] = _, h[26] = V) : V = h[26];
6900
6990
  let H;
6901
- h[27] !== R || h[28] !== B ? (H = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AccordionItem, {
6991
+ h[27] !== B || h[28] !== V ? (H = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AccordionItem, {
6902
6992
  value: "tool-call",
6903
6993
  className: "border-0",
6904
- children: [R, B]
6905
- }), h[27] = R, h[28] = B, h[29] = H) : H = h[29];
6994
+ children: [B, V]
6995
+ }), h[27] = B, h[28] = V, h[29] = H) : H = h[29];
6906
6996
  let U;
6907
- return h[30] !== H || h[31] !== A || h[32] !== j ? (U = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Accordion, {
6997
+ return h[30] !== H || h[31] !== j || h[32] !== M ? (U = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Accordion, {
6908
6998
  type: "single",
6909
6999
  collapsible: true,
6910
- className: j,
7000
+ className: M,
6911
7001
  children: H
6912
- }, A), h[30] = H, h[31] = A, h[32] = j, h[33] = U) : U = h[33], U;
7002
+ }, j), h[30] = H, h[31] = j, h[32] = M, h[33] = U) : U = h[33], U;
6913
7003
  };
6914
7004
  var HistoryContent = (e18) => {
6915
7005
  let h = (0, import_compiler_runtime$3.c)(16), { state: g, input: _, result: v, approval: y } = e18;
@@ -7441,7 +7531,119 @@ const resourceInputFilter = EditorState.transactionFilter.of((e18) => {
7441
7531
  }];
7442
7532
  }
7443
7533
  return e18;
7444
- }), resourceTheme = EditorView.baseTheme({
7534
+ });
7535
+ var DEFAULT_DEBOUNCE_MS = 150;
7536
+ function getUnresolvedUris(e18, h) {
7537
+ let g = /* @__PURE__ */ new Set();
7538
+ for (let _ of matchAllURIs(e18)) {
7539
+ let e19 = _[0].slice(1);
7540
+ h.has(e19) || g.add(e19);
7541
+ }
7542
+ return [...g];
7543
+ }
7544
+ function unresolvedKey(e18) {
7545
+ return [...e18].sort().join("\n");
7546
+ }
7547
+ function hasResourceMention(e18) {
7548
+ return !matchAllURIs(e18).next().done;
7549
+ }
7550
+ function changedLineText(e18) {
7551
+ let h = [], g = [];
7552
+ return e18.changes.iterChanges((_, v, y, b) => {
7553
+ let x = e18.startState.doc.lineAt(_), S = e18.startState.doc.lineAt(v === _ ? _ : v - 1);
7554
+ h.push(e18.startState.doc.sliceString(x.from, S.to));
7555
+ let C = e18.state.doc.lineAt(y), w = e18.state.doc.lineAt(b === y ? y : b - 1);
7556
+ g.push(e18.state.doc.sliceString(C.from, w.to));
7557
+ }), {
7558
+ before: h.join("\n"),
7559
+ after: g.join("\n")
7560
+ };
7561
+ }
7562
+ function createResourceSyncPlugin(e18, h) {
7563
+ let g = h.debounceMs ?? DEFAULT_DEBOUNCE_MS, { logger: _, resolve: v } = h;
7564
+ return class {
7565
+ constructor(e19) {
7566
+ __publicField(this, "view");
7567
+ __publicField(this, "timer");
7568
+ __publicField(this, "running", false);
7569
+ __publicField(this, "rerun", false);
7570
+ __publicField(this, "lastKey", "");
7571
+ __publicField(this, "destroyed", false);
7572
+ this.view = e19, this.maybeSchedule(e19);
7573
+ }
7574
+ update(e19) {
7575
+ if (e19.docChanged) {
7576
+ let h2 = changedLineText(e19);
7577
+ if (hasResourceMention(h2.before)) {
7578
+ this.maybeSchedule(e19.view);
7579
+ return;
7580
+ }
7581
+ this.maybeSchedule(e19.view, h2.after);
7582
+ }
7583
+ }
7584
+ destroy() {
7585
+ this.destroyed = true, this.clearTimer();
7586
+ }
7587
+ maybeSchedule(e19, h2) {
7588
+ let _2 = h2 ?? e19.state.doc.toString();
7589
+ if (!hasResourceMention(_2)) {
7590
+ h2 === void 0 && (this.lastKey = "", this.clearTimer());
7591
+ return;
7592
+ }
7593
+ let v2 = unresolvedKey(getUnresolvedUris(_2, e19.state.field(resourcesField)));
7594
+ if (v2 === "") {
7595
+ h2 === void 0 && (this.lastKey = "", this.clearTimer());
7596
+ return;
7597
+ }
7598
+ if (v2 === this.lastKey) {
7599
+ this.clearTimer();
7600
+ return;
7601
+ }
7602
+ this.clearTimer(), this.timer = setTimeout(() => {
7603
+ this.timer = void 0, this.run(e19);
7604
+ }, g);
7605
+ }
7606
+ clearTimer() {
7607
+ this.timer !== void 0 && (clearTimeout(this.timer), this.timer = void 0);
7608
+ }
7609
+ async run(h2) {
7610
+ if (!this.destroyed) {
7611
+ if (this.running) {
7612
+ this.rerun = true;
7613
+ return;
7614
+ }
7615
+ this.running = true;
7616
+ try {
7617
+ do {
7618
+ this.rerun = false;
7619
+ let g2 = getUnresolvedUris(h2.state.doc.toString(), h2.state.field(resourcesField));
7620
+ if (g2.length === 0) {
7621
+ this.lastKey = "";
7622
+ break;
7623
+ }
7624
+ this.lastKey = unresolvedKey(g2);
7625
+ let _2 = v ? await v(g2) : await e18();
7626
+ if (this.destroyed) return;
7627
+ let y = new Set(g2), b = _2.filter((e19) => y.has(e19.uri));
7628
+ if (b.length === 0) {
7629
+ if (this.rerun) continue;
7630
+ break;
7631
+ }
7632
+ h2.dispatch({ effects: updateResources.of(new Map(b.map((e19) => [e19.uri, e19]))) }), this.rerun = true;
7633
+ } while (this.rerun);
7634
+ } catch (e19) {
7635
+ this.lastKey = "", _ == null ? void 0 : _.error("Failed to sync resources:", e19);
7636
+ } finally {
7637
+ this.running = false;
7638
+ }
7639
+ }
7640
+ }
7641
+ };
7642
+ }
7643
+ function resourceSync(e18, h = {}) {
7644
+ return ViewPlugin.fromClass(createResourceSyncPlugin(e18, h));
7645
+ }
7646
+ const resourceTheme = EditorView.baseTheme({
7445
7647
  ".cm-resource-widget": {
7446
7648
  background: "light-dark(rgba(86,156,214,0.08),rgba(86,156,214,0.18))",
7447
7649
  borderRadius: "4px",
@@ -7468,13 +7670,14 @@ var NONE_RESOURCE_TYPE = "_none_", NONE_RESOURCE = [{
7468
7670
  apply: () => {
7469
7671
  }
7470
7672
  };
7673
+ function getRegistryResources(e18) {
7674
+ let h = getAIContextRegistry(e18).getAllItems();
7675
+ return h.length === 0 ? NONE_RESOURCE : h;
7676
+ }
7471
7677
  function resourceExtension(e18) {
7472
- let { language: h, store: _, onAddFiles: v } = e18;
7678
+ let { language: h, store: _, onAddFiles: v } = e18, y = () => getRegistryResources(_);
7473
7679
  return [
7474
- h.data.of({ autocomplete: resourceCompletion(async () => {
7475
- let e19 = getAIContextRegistry(_).getAllItems();
7476
- return e19.length === 0 ? NONE_RESOURCE : e19;
7477
- }, (e19) => {
7680
+ h.data.of({ autocomplete: resourceCompletion(async () => y(), (e19) => {
7478
7681
  var _a;
7479
7682
  return e19.type === NONE_RESOURCE_TYPE ? NONE_RESOURCE_FORMAT_COMPLETION : ((_a = getAIContextRegistry(_).getProvider(e19.type)) == null ? void 0 : _a.formatCompletion(e19)) || {};
7480
7683
  }) }),
@@ -7487,19 +7690,20 @@ function resourceExtension(e18) {
7487
7690
  ...v ? [h.data.of({ autocomplete: getFileContextProvider().createCompletionSource() })] : [],
7488
7691
  resourceDecorations,
7489
7692
  resourceInputFilter,
7693
+ resourceSync(y, { logger: Logger }),
7490
7694
  resourcesField.init(() => {
7491
- let e19 = getAIContextRegistry(_).getAllItems();
7695
+ let e19 = getRegistryResources(_);
7492
7696
  return new Map(e19.map((e20) => [e20.uri, e20]));
7493
7697
  }),
7494
7698
  resourceTheme,
7495
7699
  hoverResource({ createTooltip: (e19) => {
7496
7700
  let h2 = getAIContextRegistry(_).getProvider(e19.type);
7497
7701
  if (!h2) return Logger.warn("No provider found for resource", e19), asDom(e19.description || e19.name);
7498
- let v2 = h2.formatCompletion(e19), y = e19.description || e19.name;
7499
- if (!(v2 == null ? void 0 : v2.info)) return asDom(y);
7702
+ let v2 = h2.formatCompletion(e19), y2 = e19.description || e19.name;
7703
+ if (!(v2 == null ? void 0 : v2.info)) return asDom(y2);
7500
7704
  if (typeof v2.info == "string") return asDom(v2.info);
7501
7705
  let b = v2.info(v2);
7502
- return b ? "dom" in b ? { dom: b.dom } : "then" in b ? (Logger.warn("info is a promise. This is not supported", b), asDom(y)) : { dom: b } : asDom(y);
7706
+ return b ? "dom" in b ? { dom: b.dom } : "then" in b ? (Logger.warn("info is a promise. This is not supported", b), asDom(y2)) : { dom: b } : asDom(y2);
7503
7707
  } })
7504
7708
  ];
7505
7709
  }
@@ -8022,8 +8226,8 @@ var configDescriptions = {
8022
8226
  h[0] === _ ? C = h[1] : (C = (e19) => {
8023
8227
  [...e19.matchAll(/{{(\w+)}}/g)].length > 0 ? (S(e19), y(true)) : _(e19);
8024
8228
  }, h[0] = _, h[1] = C);
8025
- let w = C, E;
8026
- h[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (E = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tooltip, {
8229
+ let w = C, T;
8230
+ h[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (T = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tooltip, {
8027
8231
  content: "Select a prompt",
8028
8232
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuTrigger, {
8029
8233
  asChild: true,
@@ -8034,43 +8238,43 @@ var configDescriptions = {
8034
8238
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ChatBubbleIcon, { className: "h-3 w-3" })
8035
8239
  })
8036
8240
  })
8037
- }), h[2] = E) : E = h[2];
8038
- let D;
8241
+ }), h[2] = T) : T = h[2];
8242
+ let E;
8039
8243
  if (h[3] !== w || h[4] !== g) {
8040
8244
  let e19;
8041
8245
  h[6] === w ? e19 = h[7] : (e19 = (e20, h2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuItem, {
8042
8246
  onSelect: () => w(e20),
8043
8247
  className: "whitespace-normal text-left",
8044
8248
  children: e20
8045
- }, h2), h[6] = w, h[7] = e19), D = g.map(e19), h[3] = w, h[4] = g, h[5] = D;
8046
- } else D = h[5];
8047
- let O;
8048
- h[8] === D ? O = h[9] : (O = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopoverAnchor, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { children: [E, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuContent, {
8249
+ }, h2), h[6] = w, h[7] = e19), E = g.map(e19), h[3] = w, h[4] = g, h[5] = E;
8250
+ } else E = h[5];
8251
+ let D;
8252
+ h[8] === E ? D = h[9] : (D = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopoverAnchor, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DropdownMenu, { children: [T, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropdownMenuContent, {
8049
8253
  side: "right",
8050
8254
  align: "end",
8051
8255
  onCloseAutoFocus: _temp,
8052
8256
  className: "w-64 max-h-96 overflow-y-auto",
8053
- children: D
8054
- })] }) }), h[8] = D, h[9] = O);
8257
+ children: E
8258
+ })] }) }), h[8] = E, h[9] = D);
8259
+ let O;
8260
+ h[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (O = () => y(false), h[10] = O) : O = h[10];
8055
8261
  let k;
8056
- h[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (k = () => y(false), h[10] = k) : k = h[10];
8057
- let A;
8058
- h[11] !== _ || h[12] !== x ? (A = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopoverContent, {
8262
+ h[11] !== _ || h[12] !== x ? (k = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopoverContent, {
8059
8263
  side: "right",
8060
8264
  align: "end",
8061
8265
  className: "min-w-80 px-2",
8062
8266
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PromptVariablesForm, {
8063
8267
  prompt: x,
8064
- onClose: k,
8268
+ onClose: O,
8065
8269
  onSelect: _
8066
8270
  })
8067
- }), h[11] = _, h[12] = x, h[13] = A) : A = h[13];
8068
- let j;
8069
- return h[14] !== v || h[15] !== O || h[16] !== A ? (j = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Popover, {
8271
+ }), h[11] = _, h[12] = x, h[13] = k) : k = h[13];
8272
+ let A;
8273
+ return h[14] !== v || h[15] !== D || h[16] !== k ? (A = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Popover, {
8070
8274
  open: v,
8071
8275
  onOpenChange: y,
8072
- children: [O, A]
8073
- }), h[14] = v, h[15] = O, h[16] = A, h[17] = j) : j = h[17], j;
8276
+ children: [D, k]
8277
+ }), h[14] = v, h[15] = D, h[16] = k, h[17] = A) : A = h[17], A;
8074
8278
  }, PromptVariablesForm = (e18) => {
8075
8279
  let h = (0, import_compiler_runtime.c)(32), { prompt: g, onClose: _, onSelect: v } = e18, y;
8076
8280
  h[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (y = {}, h[0] = y) : y = h[0];