@marimo-team/islands 0.20.3-dev96 → 0.20.3-dev98

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/main.js CHANGED
@@ -11720,7 +11720,7 @@ ${d.join("\n")}`;
11720
11720
  return r.length === 0 ? null : r;
11721
11721
  }
11722
11722
  const filenameAtom = atom(getFilenameFromDOM());
11723
- atom(void 0);
11723
+ atom(null), atom(void 0);
11724
11724
  var InMemoryStorage = class {
11725
11725
  constructor() {
11726
11726
  __publicField(this, "store", /* @__PURE__ */ new Map());
@@ -70358,7 +70358,7 @@ Image URL: ${r.imageUrl}`)), contextToXml({
70358
70358
  return Logger.warn("Failed to get version from mount config"), null;
70359
70359
  }
70360
70360
  }
70361
- const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.20.3-dev96"), showCodeInRunModeAtom = atom(true);
70361
+ const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.20.3-dev98"), showCodeInRunModeAtom = atom(true);
70362
70362
  atom(null);
70363
70363
  var import_compiler_runtime$88 = require_compiler_runtime();
70364
70364
  function useKeydownOnElement(e, r) {
@@ -95286,7 +95286,9 @@ ${c}
95286
95286
  }
95287
95287
  }, importKatex = once(async () => (await import("./katex-pyO_klYC.js")).default), importMhChem = once(async () => {
95288
95288
  await import("./mhchem-DckvwtV8.js");
95289
- }), macros = {};
95289
+ }), macros = {
95290
+ "\\mbox": "\\text{#1}"
95291
+ };
95290
95292
  async function renderLatex(e, r) {
95291
95293
  let [c] = await Promise.all([
95292
95294
  importKatex(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.20.3-dev96",
3
+ "version": "0.20.3-dev98",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -60,11 +60,11 @@ import {
60
60
  import { toast } from "@/components/ui/use-toast";
61
61
  import { DelayMount } from "@/components/utils/delay-mount";
62
62
  import { useRequestClient } from "@/core/network/requests";
63
- import { filenameAtom } from "@/core/saving/file-state";
63
+ import { cwdAtom, filenameAtom } from "@/core/saving/file-state";
64
64
  import { store } from "@/core/state/jotai";
65
65
  import { ErrorBanner } from "@/plugins/impl/common/error-banner";
66
66
  import { Functions } from "@/utils/functions";
67
- import { Paths } from "@/utils/paths";
67
+ import { PathBuilder, Paths } from "@/utils/paths";
68
68
  import {
69
69
  AddContextButton,
70
70
  AttachFileButton,
@@ -614,7 +614,11 @@ ChatContent.displayName = "ChatContent";
614
614
 
615
615
  const NO_WS_SET = "_skip_auto_connect_";
616
616
 
617
- function getCwd() {
617
+ function getCwd(): string {
618
+ const cwd = store.get(cwdAtom);
619
+ if (cwd) {
620
+ return cwd;
621
+ }
618
622
  const filename = store.get(filenameAtom);
619
623
  if (!filename) {
620
624
  throw new Error(
@@ -624,6 +628,21 @@ function getCwd() {
624
628
  return Paths.dirname(filename);
625
629
  }
626
630
 
631
+ function getAbsoluteFilename(): string {
632
+ const filename = store.get(filenameAtom);
633
+ if (!filename) {
634
+ throw new Error(
635
+ "Please save the notebook and refresh the browser to use the agent",
636
+ );
637
+ }
638
+ const cwd = store.get(cwdAtom);
639
+ if (cwd) {
640
+ const builder = PathBuilder.guessDeliminator(cwd);
641
+ return builder.join(cwd, String(Paths.basename(filename)));
642
+ }
643
+ return filename;
644
+ }
645
+
627
646
  const AgentPanel: React.FC = () => {
628
647
  const [isLoading, setIsLoading] = useState(false);
629
648
  const [error, setError] = useState<Error | string | null>(null);
@@ -862,8 +881,10 @@ const AgentPanel: React.FC = () => {
862
881
  setSessionState((prev) => updateSessionTitle(prev, prompt));
863
882
  }
864
883
 
865
- const filename = store.get(filenameAtom);
866
- if (!filename) {
884
+ let absoluteFilename: string;
885
+ try {
886
+ absoluteFilename = getAbsoluteFilename();
887
+ } catch {
867
888
  toast({
868
889
  title: "Notebook must be named",
869
890
  description: "Please name the notebook to use the agent",
@@ -894,16 +915,16 @@ const AgentPanel: React.FC = () => {
894
915
  promptBlocks.push(
895
916
  {
896
917
  type: "resource_link",
897
- uri: filename,
918
+ uri: absoluteFilename,
898
919
  mimeType: "text/x-python",
899
- name: filename,
920
+ name: absoluteFilename,
900
921
  },
901
922
  {
902
923
  type: "resource",
903
924
  resource: {
904
925
  uri: "marimo_rules.md",
905
926
  mimeType: "text/plain",
906
- text: getAgentPrompt(filename),
927
+ text: getAgentPrompt(absoluteFilename),
907
928
  },
908
929
  },
909
930
  );
@@ -9,6 +9,13 @@ import { getFilenameFromDOM } from "../dom/htmlUtils";
9
9
  */
10
10
  export const filenameAtom = atom<string | null>(getFilenameFromDOM());
11
11
 
12
+ /**
13
+ * Atom for storing the notebook's working directory (absolute path).
14
+ * In directory mode, filenameAtom may be a relative display path;
15
+ * this atom holds the absolute directory containing the notebook.
16
+ */
17
+ export const cwdAtom = atom<string | null>(null);
18
+
12
19
  /**
13
20
  * Set for static notebooks.
14
21
  */
package/src/mount.tsx CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  DEFAULT_RUNTIME_CONFIG,
37
37
  runtimeConfigAtom,
38
38
  } from "./core/runtime/config";
39
- import { codeAtom, filenameAtom } from "./core/saving/file-state";
39
+ import { codeAtom, cwdAtom, filenameAtom } from "./core/saving/file-state";
40
40
  import { store } from "./core/state/jotai";
41
41
  import { patchFetch, patchVegaLoader } from "./core/static/files";
42
42
  import {
@@ -146,6 +146,10 @@ const mountOptionsSchema = z.object({
146
146
  Logger.warn("No filename provided, using fallback");
147
147
  return getFilenameFromDOM();
148
148
  }),
149
+ /**
150
+ * absolute working directory of the notebook
151
+ */
152
+ cwd: z.string().nullish().default(null),
149
153
  /**
150
154
  * notebook code
151
155
  */
@@ -282,6 +286,7 @@ function initStore(options: unknown) {
282
286
 
283
287
  // Files
284
288
  store.set(filenameAtom, parsedOptions.data.filename);
289
+ store.set(cwdAtom, parsedOptions.data.cwd ?? null);
285
290
  store.set(codeAtom, parsedOptions.data.code);
286
291
  store.set(initialModeAtom, mode);
287
292
 
@@ -39,7 +39,10 @@ const importMhChem = once(async () => {
39
39
  });
40
40
 
41
41
  // Required, even if empty. (see https://github.com/KaTeX/KaTeX/issues/2513)
42
- const macros = {};
42
+ const macros = {
43
+ // KaTeX doesn't support \mbox; map it to the equivalent \text
44
+ "\\mbox": "\\text{#1}",
45
+ };
43
46
 
44
47
  async function renderLatex(mount: HTMLElement, tex: string): Promise<void> {
45
48
  const [katex] = await Promise.all([importKatex(), importMhChem()]);