@alivault/pico 0.10.1 → 0.10.3

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.
@@ -2,13 +2,13 @@ import { i as __toESM } from "../_runtime.mjs";
2
2
  import { $ as require_react, Q as require_jsx_runtime } from "../_libs/@base-ui/react+[...].mjs";
3
3
  import { a as createRouter, c as createRootRoute, n as Scripts, r as HeadContent, s as createFileRoute } from "../_libs/@tanstack/react-router+[...].mjs";
4
4
  import { I as CircleCheck, S as Info, _ as OctagonX, a as TriangleAlert } from "../_libs/lucide-react.mjs";
5
- import { A as TooltipProvider, B as extractMessageImages, F as buildItemsFromSync, G as mergeAssistantBlocksForStreaming, H as extractToolText, L as createCompactionSummaryItem, P as assistantBlocksFromMessage, S as Spinner, St as toolCategoryFromTool, V as extractMessageText$1, n as APPLIED_THEME_STORAGE_KEY, t as APPLIED_THEME_CLASSES, v as Route$54 } from "./routes-DbGwM-bj.mjs";
5
+ import { B as createCompactionSummaryItem, G as extractToolText, I as appliedThemeClassColorMode, J as mergeAssistantBlocksForStreaming, L as assistantBlocksFromMessage, M as TooltipProvider, R as buildItemsFromSync, T as Spinner, U as extractMessageImages, W as extractMessageText$1, f as PICO_SHIKI_VARIABLE_DEFAULTS, kt as toolCategoryFromTool, n as APPLIED_THEME_STORAGE_KEY, t as APPLIED_THEME_CLASSES, u as PICO_CODE_SHIKI_THEME, x as Route$54 } from "./routes-DMdIR42g.mjs";
6
6
  import { t as QueryClient } from "../_libs/tanstack__query-core.mjs";
7
7
  import { t as setupRouterSsrQueryIntegration } from "../_libs/@tanstack/react-router-ssr-query+[...].mjs";
8
8
  import { n as HotkeysProvider } from "../_libs/tanstack__react-hotkeys.mjs";
9
9
  import { n as z, t as J } from "../_libs/next-themes.mjs";
10
10
  import { t as Toaster } from "../_libs/sonner.mjs";
11
- import { a as rust_exports, i as python_exports, n as go_exports, o as css_exports, r as c_exports, s as highlight, t as java_exports } from "../_libs/sugar-high.mjs";
11
+ import { c as bundledLanguages, l as bundledLanguagesAlias, s as codeToHtml, u as createCssVariablesTheme } from "../_libs/@pierre/diffs+[...].mjs";
12
12
  import { t as createTwoFilesPatch } from "../_libs/diff.mjs";
13
13
  import { n as Debouncer } from "../_libs/tanstack__pacer.mjs";
14
14
  import { createHash, randomUUID } from "node:crypto";
@@ -20,13 +20,17 @@ import os, { homedir } from "node:os";
20
20
  import { performance } from "node:perf_hooks";
21
21
  import { isMainThread } from "node:worker_threads";
22
22
  import { execSync, spawn } from "node:child_process";
23
- //#region node_modules/.nitro/vite/services/ssr/assets/router-DhVJ7gcL.js
23
+ //#region node_modules/.nitro/vite/services/ssr/assets/router-qUSM3V8V.js
24
24
  var import_react = /* @__PURE__ */ __toESM(require_react());
25
25
  var import_jsx_runtime = require_jsx_runtime();
26
+ function sonnerThemeFromAppliedTheme(theme) {
27
+ if (theme === "system") return "system";
28
+ return appliedThemeClassColorMode(theme) ?? "system";
29
+ }
26
30
  var Toaster$1 = ({ ...props }) => {
27
31
  const { theme = "system" } = z();
28
32
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toaster, {
29
- theme,
33
+ theme: sonnerThemeFromAppliedTheme(theme),
30
34
  className: "toaster group",
31
35
  icons: {
32
36
  success: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleCheck, { className: "size-4" }),
@@ -39,6 +43,18 @@ var Toaster$1 = ({ ...props }) => {
39
43
  "--normal-bg": "var(--popover)",
40
44
  "--normal-text": "var(--popover-foreground)",
41
45
  "--normal-border": "var(--border)",
46
+ "--success-bg": "color-mix(in oklab, var(--success) 14%, var(--popover))",
47
+ "--success-border": "color-mix(in oklab, var(--success) 35%, var(--border))",
48
+ "--success-text": "var(--success)",
49
+ "--info-bg": "color-mix(in oklab, var(--primary) 14%, var(--popover))",
50
+ "--info-border": "color-mix(in oklab, var(--primary) 35%, var(--border))",
51
+ "--info-text": "var(--primary)",
52
+ "--warning-bg": "color-mix(in oklab, var(--warning) 14%, var(--popover))",
53
+ "--warning-border": "color-mix(in oklab, var(--warning) 35%, var(--border))",
54
+ "--warning-text": "var(--warning)",
55
+ "--error-bg": "color-mix(in oklab, var(--danger) 14%, var(--popover))",
56
+ "--error-border": "color-mix(in oklab, var(--danger) 35%, var(--border))",
57
+ "--error-text": "var(--danger)",
42
58
  "--border-radius": "var(--radius)"
43
59
  },
44
60
  toastOptions: { classNames: { toast: "cn-toast" } },
@@ -71,7 +87,7 @@ function AppProviders({ children }) {
71
87
  })
72
88
  });
73
89
  }
74
- var styles_default = "/assets/styles-oRWMaOB0.css";
90
+ var styles_default = "/assets/styles-hk0oLlcJ.css";
75
91
  var TANSTACK_DEVTOOLS_SETTINGS_KEY = "tanstack_devtools_settings";
76
92
  var TANSTACK_DEVTOOLS_DEFAULTS_STORAGE_KEY = "pico-tanstack-devtools-defaults-v1";
77
93
  var TANSTACK_DEVTOOLS_CONFIG = {
@@ -519,7 +535,7 @@ async function clearContextDraft(options) {
519
535
  await disposeDraftIfUnused(draftEntry);
520
536
  }
521
537
  async function resolveRequestedEntry(options) {
522
- const { url, context, getSessionEntryByKey, ensureSessionEntryById, getActiveEntry, isDraftEntry, getOrCreateDraftEntry, activateContextSession, notifyOnActivate = true, preferActiveDraft = false } = options;
538
+ const { url, context, getSessionEntryByKey, ensureSessionEntryById, getActiveEntry, isDraftEntry, getOrCreateDraftEntry, activateContextSession, notifyOnActivate = true, preferActiveDraft = false, preferActiveDraftOverRequestedSession = false } = options;
523
539
  const activateRequestedEntry = async (entry) => {
524
540
  await activateContextSession(context, entry, { notify: notifyOnActivate });
525
541
  return entry;
@@ -531,6 +547,10 @@ async function resolveRequestedEntry(options) {
531
547
  }
532
548
  const requestedSessionId = url.searchParams.get("session");
533
549
  if (requestedSessionId) {
550
+ if (preferActiveDraft && preferActiveDraftOverRequestedSession && context.draftKey && context.activeKey === context.draftKey) {
551
+ const activeDraftEntry = getSessionEntryByKey(context.draftKey);
552
+ if (activeDraftEntry && isDraftEntry(activeDraftEntry)) return await activateRequestedEntry(activeDraftEntry);
553
+ }
534
554
  const requestedEntry = await ensureSessionEntryById(requestedSessionId);
535
555
  if (requestedEntry) return await activateRequestedEntry(requestedEntry);
536
556
  }
@@ -542,26 +562,35 @@ async function resolveRequestedEntry(options) {
542
562
  if (activeEntry) return await activateRequestedEntry(activeEntry);
543
563
  return await getOrCreateDraftEntry(context);
544
564
  }
565
+ var SPECIAL_SHIKI_LANGUAGES = new Set([
566
+ "ansi",
567
+ "plain",
568
+ "plaintext",
569
+ "text"
570
+ ]);
571
+ var SUPPORTED_SHIKI_LANGUAGES = new Set([...Object.keys(bundledLanguages), ...Object.keys(bundledLanguagesAlias)]);
572
+ var picoCodeTheme = createCssVariablesTheme({
573
+ name: PICO_CODE_SHIKI_THEME,
574
+ variablePrefix: "--sh-",
575
+ variableDefaults: { ...PICO_SHIKI_VARIABLE_DEFAULTS },
576
+ fontStyle: false
577
+ });
545
578
  function normalizeHighlightLanguage(language) {
546
579
  const normalized = typeof language === "string" ? language.trim().toLowerCase().replace(/^language-/, "") : "";
547
580
  if (!normalized) return "";
548
581
  switch (normalized) {
549
- case "js":
550
582
  case "mjs":
551
583
  case "cjs": return "javascript";
552
- case "ts": return "typescript";
553
- case "py": return "python";
554
- case "rs": return "rust";
584
+ case "cts":
585
+ case "mts": return "typescript";
555
586
  case "golang": return "go";
556
587
  case "htm":
557
588
  case "xhtml": return "html";
558
- case "yml": return "yaml";
589
+ case "svg": return "xml";
559
590
  case "shell":
560
- case "shellscript":
561
- case "sh":
562
- case "zsh": return "bash";
591
+ case "shellscript": return "bash";
563
592
  case "plain":
564
- case "text": return "plaintext";
593
+ case "txt": return "text";
565
594
  case "h": return "c";
566
595
  default: return normalized;
567
596
  }
@@ -571,46 +600,34 @@ function countTextLines(text) {
571
600
  for (let index = 0; index < text.length; index += 1) if (text.charCodeAt(index) === 10) lines += 1;
572
601
  return lines;
573
602
  }
574
- function getSugarHighOptions(language) {
575
- switch (language) {
576
- case "javascript":
577
- case "jsx":
578
- case "typescript":
579
- case "tsx":
580
- case "json":
581
- case "jsonc":
582
- case "html":
583
- case "xml":
584
- case "svg":
585
- case "mdx": return null;
586
- case "css": return css_exports;
587
- case "python": return python_exports;
588
- case "rust": return rust_exports;
589
- case "c": return c_exports;
590
- case "go": return go_exports;
591
- case "java": return java_exports;
592
- default: return;
593
- }
594
- }
595
- function buildHighlightPayload(options) {
603
+ function isSupportedShikiLanguage(language) {
604
+ return SPECIAL_SHIKI_LANGUAGES.has(language) || SUPPORTED_SHIKI_LANGUAGES.has(language);
605
+ }
606
+ function shikiCodeInnerHtml(html) {
607
+ return /<pre\b[^>]*><code>([\s\S]*)<\/code><\/pre>/.exec(html)?.[1] ?? html;
608
+ }
609
+ async function buildHighlightPayload(options) {
596
610
  const text = typeof options.code === "string" ? options.code : "";
597
611
  const normalizedLanguage = normalizeHighlightLanguage(options.language);
598
612
  if (!text || !normalizedLanguage) return {
599
613
  skipped: true,
600
614
  language: normalizedLanguage || void 0
601
615
  };
602
- if (normalizedLanguage === "plaintext" || text.length > 1e5 || countTextLines(text) > 1500) return {
616
+ if (normalizedLanguage === "text" || normalizedLanguage === "plaintext" || text.length > 1e5 || countTextLines(text) > 1500) return {
603
617
  skipped: true,
604
618
  language: normalizedLanguage
605
619
  };
606
- const sugarOptions = getSugarHighOptions(normalizedLanguage);
607
- if (sugarOptions === void 0) return {
620
+ if (!isSupportedShikiLanguage(normalizedLanguage)) return {
608
621
  unsupported: true,
609
622
  language: normalizedLanguage
610
623
  };
611
624
  return {
612
625
  language: normalizedLanguage,
613
- html: highlight(text, sugarOptions ?? void 0)
626
+ html: shikiCodeInnerHtml(await codeToHtml(text, {
627
+ lang: normalizedLanguage,
628
+ theme: picoCodeTheme,
629
+ defaultColor: false
630
+ }))
614
631
  };
615
632
  }
616
633
  function messageItemIndex(item) {
@@ -4060,16 +4077,19 @@ var PicoRuntime = class {
4060
4077
  return mergeSessionListEntry(target, fallback);
4061
4078
  }
4062
4079
  async sessionFallbackInfo(entry) {
4063
- const firstMessage = this.getSessionFirstMessage(entry);
4080
+ const sessionName = entry.session.sessionName;
4081
+ const waitingForAutoName = Boolean(entry.sessionNaming.pendingGeneration && !cleanupSessionNameCandidate(sessionName));
4082
+ const firstMessage = waitingForAutoName ? "" : this.getSessionFirstMessage(entry);
4083
+ const listName = waitingForAutoName ? "New session" : sessionName;
4064
4084
  const lastMessage = getSessionLastCompleteMessageInfo(entry.session.messages);
4065
4085
  return {
4066
4086
  path: entry.session.sessionFile,
4067
4087
  id: entry.session.sessionId,
4068
4088
  cwd: entry.cwd,
4069
- name: entry.session.sessionName,
4089
+ name: listName,
4070
4090
  firstMessage,
4071
4091
  title: getSessionListTitle({
4072
- name: entry.session.sessionName,
4092
+ name: listName,
4073
4093
  firstMessage
4074
4094
  }),
4075
4095
  modified: await this.sessionEntryModified(entry),
@@ -4735,7 +4755,8 @@ var PicoRuntime = class {
4735
4755
  getOrCreateDraftEntry: async (activeContext) => await this.getOrCreateDraftEntry(activeContext),
4736
4756
  activateContextSession: async (activeContext, entry, activateOptions) => await this.activateContextSession(activeContext, entry, activateOptions),
4737
4757
  notifyOnActivate: options?.notifyOnActivate,
4738
- preferActiveDraft: options?.preferActiveDraft
4758
+ preferActiveDraft: options?.preferActiveDraft,
4759
+ preferActiveDraftOverRequestedSession: options?.preferActiveDraftOverRequestedSession
4739
4760
  });
4740
4761
  }
4741
4762
  async resolveRequest(request, options) {
@@ -4754,7 +4775,8 @@ var PicoRuntime = class {
4754
4775
  try {
4755
4776
  const activeEntry = await this.resolveRequestedEntry(url, context, {
4756
4777
  notifyOnActivate: options?.notifyOnActivate ?? false,
4757
- preferActiveDraft: options?.preferActiveDraft ?? true
4778
+ preferActiveDraft: options?.preferActiveDraft ?? true,
4779
+ preferActiveDraftOverRequestedSession: options?.preferActiveDraftOverRequestedSession ?? false
4758
4780
  });
4759
4781
  this.logSessionLoadDebug("request_resolve:done", {
4760
4782
  pathname: url.pathname,
@@ -5527,7 +5549,10 @@ var PicoRuntime = class {
5527
5549
  }
5528
5550
  }
5529
5551
  async prompt(request, body) {
5530
- const { context, activeEntry } = await this.resolveRequest(request, { preferActiveDraft: true });
5552
+ const { context, activeEntry } = await this.resolveRequest(request, {
5553
+ preferActiveDraft: true,
5554
+ preferActiveDraftOverRequestedSession: true
5555
+ });
5531
5556
  const message = typeof body.message === "string" ? body.message : "";
5532
5557
  const images = normalizePromptImages(body.images);
5533
5558
  if (!message.trim() && images.length === 0) throw new Error("message or image is required");
@@ -6478,7 +6503,7 @@ var PicoRuntime = class {
6478
6503
  async highlightCode(code, language) {
6479
6504
  const text = typeof code === "string" ? code : "";
6480
6505
  try {
6481
- const highlightInput = buildHighlightPayload({
6506
+ const highlightInput = await buildHighlightPayload({
6482
6507
  code,
6483
6508
  language
6484
6509
  });