@agimon-ai/po-artifact 0.0.0-alpha.2 → 0.0.0-alpha.21

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.
Files changed (38) hide show
  1. package/LICENSE +149 -21
  2. package/README.md +1 -1
  3. package/dist/apiContracts.cjs +10 -2
  4. package/dist/apiContracts.cjs.map +1 -1
  5. package/dist/apiContracts.d.mts.map +1 -1
  6. package/dist/apiContracts.mjs +10 -2
  7. package/dist/apiContracts.mjs.map +1 -1
  8. package/dist/{artifactFiles-Bo5Mhwq0.cjs → artifactFiles-BmBU9Olm.cjs} +138 -76
  9. package/dist/artifactFiles-BmBU9Olm.cjs.map +1 -0
  10. package/dist/{artifactFiles-B8w_HQXv.mjs → artifactFiles-DyIkevXc.mjs} +119 -57
  11. package/dist/artifactFiles-DyIkevXc.mjs.map +1 -0
  12. package/dist/artifactFiles.cjs +7 -1
  13. package/dist/artifactFiles.d.mts +14 -1
  14. package/dist/artifactFiles.d.mts.map +1 -1
  15. package/dist/artifactFiles.mjs +3 -1
  16. package/dist/artifacts-Bhobz1nK.mjs +38 -0
  17. package/dist/artifacts-Bhobz1nK.mjs.map +1 -0
  18. package/dist/artifacts-DG_b7DZH.cjs +85 -0
  19. package/dist/artifacts-DG_b7DZH.cjs.map +1 -0
  20. package/dist/artifacts-sIj4Xaeu.d.mts +32 -0
  21. package/dist/artifacts-sIj4Xaeu.d.mts.map +1 -0
  22. package/dist/extensions/native.mjs +640 -32
  23. package/dist/extensions/native.mjs.map +1 -1
  24. package/dist/extensions/server.cjs +163 -44
  25. package/dist/extensions/server.cjs.map +1 -1
  26. package/dist/extensions/server.d.mts +2 -2
  27. package/dist/extensions/server.d.mts.map +1 -1
  28. package/dist/extensions/server.mjs +161 -42
  29. package/dist/extensions/server.mjs.map +1 -1
  30. package/dist/extensions/web.mjs +848 -136
  31. package/dist/extensions/web.mjs.map +1 -1
  32. package/dist/index.cjs +3 -0
  33. package/dist/index.d.mts +8 -19
  34. package/dist/index.d.mts.map +1 -1
  35. package/dist/index.mjs +1 -1
  36. package/package.json +20 -20
  37. package/dist/artifactFiles-B8w_HQXv.mjs.map +0 -1
  38. package/dist/artifactFiles-Bo5Mhwq0.cjs.map +0 -1
@@ -1,27 +1,30 @@
1
- import { createApiClient, defineActivityGroup, defineChannelFile, defineFill, defineNativePlugin, defineSessionStore, nativeApiTransport, sessionApiAddress } from "@agimon-ai/po-core/native";
1
+ import { createApiClient, defineActivityGroup, defineChannelFile, defineFill, defineGlobalStore, defineNativePlugin, defineSessionStore, nativeApiTransport, sessionApiAddress } from "@agimon-ai/po-core/native";
2
+ import { View } from "react-native-unistyles/components/native/View";
2
3
  import { Text } from "react-native-unistyles/components/native/Text";
3
- import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
4
- import { Button, CodeBlock, FolderIcon, Markdown, fontOf } from "@agimon-ai/po-native-components";
4
+ import { Image } from "react-native-unistyles/components/native/Image";
5
+ import { Button, ChevronDownIcon, ChevronRightIcon, CloseIcon, CodeBlock, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, FileIcon, FolderIcon, ImageIcon, Input, Markdown, SearchIcon, SegmentedControl, SlidersIcon, fontOf } from "@agimon-ai/po-native-components";
6
+ import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
5
7
  import { StyleSheet } from "react-native-unistyles";
6
- import { useEffect, useRef, useState, useSyncExternalStore } from "react";
7
- import { View } from "react-native-unistyles/components/native/View";
8
+ import { FlatList } from "react-native-unistyles/components/native/FlatList";
8
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
9
11
  const api = createApiClient({
10
12
  list: {
11
13
  method: "GET",
12
14
  path: "/",
15
+ query: ["scope"],
13
16
  response: void 0
14
17
  },
15
18
  preview: {
16
19
  method: "GET",
17
20
  path: "/preview",
18
- query: ["path"],
21
+ query: ["path", "scope"],
19
22
  response: void 0
20
23
  },
21
24
  content: {
22
25
  method: "GET",
23
26
  path: "/content",
24
- query: ["path"],
27
+ query: ["path", "scope"],
25
28
  raw: true
26
29
  }
27
30
  }, {
@@ -31,10 +34,108 @@ const api = createApiClient({
31
34
  sessionAddress: sessionApiAddress
32
35
  });
33
36
  //#endregion
37
+ //#region src/constants/artifacts.ts
38
+ /** Autocompact mirrors compaction history here; the recent-artifacts card leaves it out. */
39
+ const COMPACTION_ARTIFACT_DIRECTORY = "compaction";
40
+ //#endregion
34
41
  //#region src/extensions/workspaces/sessions/(frontend)/_lib/artifactView.ts
42
+ function isArtifactLayout(value) {
43
+ return value === "tree" || value === "list" || value === "grid";
44
+ }
45
+ function artifactKind(path) {
46
+ if (/\.(?:md|markdown)$/iu.test(path)) return "Markdown";
47
+ if (/\.(?:png|jpe?g|gif|webp|avif|bmp|svg|ico|tiff?)$/iu.test(path)) return "Image";
48
+ if (/\.(?:jsonl?|csv|tsv|ya?ml|xml|toml|parquet|sqlite|db)$/iu.test(path)) return "Data";
49
+ if (/\.(?:[cm]?[jt]sx?|html?|css|scss|sass|less|py|sh|bash|go|rs|rb|java|c|cpp|cc|h|hpp|sql|swift|kt|kts|php|vue|svelte)$/iu.test(path)) return "Code";
50
+ if (/\.(?:pdf|txt|rtf|docx?|xlsx?|pptx?|odt|ods|odp)$/iu.test(path)) return "Document";
51
+ return "Other";
52
+ }
53
+ /** Time is supplied by the caller. Today starts at local midnight; day windows are inclusive. */
54
+ function filterArtifacts(items, filters, now) {
55
+ const query = (filters.query ?? "").trim().toLowerCase();
56
+ const modified = filters.modified ?? "any";
57
+ const day = 864e5;
58
+ const midnight = new Date(now);
59
+ midnight.setHours(0, 0, 0, 0);
60
+ const since = modified === "today" ? midnight.getTime() : now - (modified === "7days" ? 7 : 30) * day;
61
+ return items.filter((item) => item.path.toLowerCase().includes(query) && (!filters.type || filters.type === "any" || artifactKind(item.path) === filters.type) && (modified === "any" || item.modifiedAt >= since && item.modifiedAt <= now));
62
+ }
63
+ /** Sort a copy, with an ascending full-path tie breaker in either direction. */
64
+ function sortArtifacts(items, sort, direction) {
65
+ return [...items].sort((left, right) => {
66
+ return (sort === "name" ? comparePaths(left.name.toLowerCase(), right.name.toLowerCase()) : sort === "size" ? left.size - right.size : left.modifiedAt - right.modifiedAt) * (direction === "asc" ? 1 : -1) || comparePaths(left.path, right.path);
67
+ });
68
+ }
69
+ function comparePaths(left, right) {
70
+ return left < right ? -1 : left > right ? 1 : 0;
71
+ }
72
+ /** Derive folders from already filtered, sorted files. Folders precede files and compact single-child chains. */
73
+ function artifactTree(items, isOpen) {
74
+ const root = {
75
+ path: "",
76
+ dirs: /* @__PURE__ */ new Map(),
77
+ files: [],
78
+ count: 0
79
+ };
80
+ for (const item of items) {
81
+ let dir = root;
82
+ dir.count++;
83
+ for (const segment of item.path.split("/").slice(0, -1)) {
84
+ let next = dir.dirs.get(segment);
85
+ if (!next) {
86
+ next = {
87
+ path: dir.path ? `${dir.path}/${segment}` : segment,
88
+ dirs: /* @__PURE__ */ new Map(),
89
+ files: [],
90
+ count: 0
91
+ };
92
+ dir.dirs.set(segment, next);
93
+ }
94
+ dir = next;
95
+ dir.count++;
96
+ }
97
+ dir.files.push(item);
98
+ }
99
+ const rows = [];
100
+ const walk = (dir, depth) => {
101
+ for (const [segment, child] of [...dir.dirs].sort(([left], [right]) => comparePaths(left, right))) {
102
+ let name = segment;
103
+ let node = child;
104
+ while (node.files.length === 0 && node.dirs.size === 1) {
105
+ const [[nextName, next]] = [...node.dirs];
106
+ name = `${name}/${nextName}`;
107
+ node = next;
108
+ }
109
+ const open = isOpen(node.path);
110
+ rows.push({
111
+ kind: "dir",
112
+ path: node.path,
113
+ name,
114
+ depth,
115
+ open,
116
+ count: node.count
117
+ });
118
+ if (open) walk(node, depth + 1);
119
+ }
120
+ for (const item of dir.files) rows.push({
121
+ kind: "file",
122
+ item,
123
+ depth
124
+ });
125
+ };
126
+ walk(root, 0);
127
+ return rows;
128
+ }
129
+ function sizeLabel(size) {
130
+ return size < 1024 ? `${size} B` : size < 1048576 ? `${Math.ceil(size / 1024)} KB` : `${(size / 1048576).toFixed(1)} MB`;
131
+ }
35
132
  function sortedArtifacts(items) {
36
133
  return [...items].sort((left, right) => right.modifiedAt - left.modifiedAt || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
37
134
  }
135
+ /** The recent card shows the person's documents; compaction history stays in the full grid. */
136
+ function recentArtifacts(items) {
137
+ return sortedArtifacts(items.filter((item) => !item.path.startsWith(`${COMPACTION_ARTIFACT_DIRECTORY}/`))).slice(0, 3);
138
+ }
38
139
  function artifactTabId(sessionId, path) {
39
140
  return `artifact:${encodeURIComponent(sessionId)}:${encodeURIComponent(path)}`;
40
141
  }
@@ -75,22 +176,29 @@ function parseArtifactSnapshot(input) {
75
176
  }
76
177
  return {
77
178
  items: sortedArtifacts(items),
179
+ ..."temporaryRoot" in input && typeof input.temporaryRoot === "string" ? { temporaryRoot: input.temporaryRoot } : {},
78
180
  ..."error" in input && typeof input.error === "string" ? { error: input.error } : {}
79
181
  };
80
182
  }
81
183
  //#endregion
82
184
  //#region src/extensions/workspaces/sessions/(frontend)/_lib/artifactsApi.native.ts
83
185
  const MAX_MEDIA_BYTES = 5242880;
84
- async function fetchArtifacts(sessionId, signal) {
85
- const result = await api.session(sessionId).list({ signal });
186
+ async function fetchArtifacts(sessionId, signal, scope = "artifacts") {
187
+ const result = await api.session(sessionId).list({
188
+ ...scope === "temporary" ? { query: { scope } } : {},
189
+ signal
190
+ });
86
191
  if (!result.ok) throw new Error(result.error || "Artifacts could not be loaded.");
87
192
  const snapshot = parseArtifactSnapshot(result.data);
88
193
  if (!snapshot) throw new Error("The session returned an invalid artifact list.");
89
194
  return snapshot;
90
195
  }
91
- async function fetchArtifactPreview(sessionId, path, signal) {
196
+ async function fetchArtifactPreview(sessionId, path, signal, scope = "artifacts") {
92
197
  const result = await api.session(sessionId).preview({
93
- query: { path },
198
+ query: {
199
+ path,
200
+ ...scope === "temporary" ? { scope } : {}
201
+ },
94
202
  signal
95
203
  });
96
204
  if (!result.ok) throw new Error(result.error || "This artifact could not be read.");
@@ -116,9 +224,12 @@ function base64(bytes) {
116
224
  parts.push(chunk);
117
225
  return parts.join("");
118
226
  }
119
- async function fetchArtifactMedia(sessionId, path, signal) {
227
+ async function fetchArtifactMedia(sessionId, path, signal, scope = "artifacts") {
120
228
  const result = await api.session(sessionId).content({
121
- query: { path },
229
+ query: {
230
+ path,
231
+ ...scope === "temporary" ? { scope } : {}
232
+ },
122
233
  signal
123
234
  });
124
235
  if (!result.ok) throw new Error(result.error || "This media could not be loaded.");
@@ -136,11 +247,14 @@ async function fetchArtifactMedia(sessionId, path, signal) {
136
247
  };
137
248
  }
138
249
  /** The native host owns saving, with bounded version-checked reads supplied by this package. */
139
- async function prepareArtifactSave(sessionId, path, signal) {
250
+ async function prepareArtifactSave(sessionId, path, signal, scope = "artifacts") {
140
251
  const load = async (headers, signal) => {
141
252
  if (signal.aborted) throw new Error("Download cancelled.");
142
253
  const result = await api.session(sessionId).content({
143
- query: { path },
254
+ query: {
255
+ path,
256
+ ...scope === "temporary" ? { scope } : {}
257
+ },
144
258
  headers,
145
259
  signal
146
260
  });
@@ -183,6 +297,8 @@ async function prepareArtifactSave(sessionId, path, signal) {
183
297
  const artifactsChannelType = "artifacts";
184
298
  //#endregion
185
299
  //#region src/extensions/workspaces/sessions/(frontend)/_lib/artifactsStore.native.ts
300
+ /** Shared across browser mounts, in memory only until the native app restarts. */
301
+ const artifactLayout = defineGlobalStore("tree");
186
302
  const artifacts = defineSessionStore({
187
303
  items: [],
188
304
  loaded: false
@@ -233,7 +349,14 @@ function useArtifacts(sessionId, refreshOnMount = false) {
233
349
  //#endregion
234
350
  //#region src/extensions/workspaces/sessions/(frontend)/_components/ArtifactList.native.tsx
235
351
  /** Presentation only. The session store and guarded API belong to the containers. */
236
- function ArtifactList({ items, onOpen, loading, error, grid = false }) {
352
+ function ArtifactList({ items, onOpen, loading, error, grid = false, browser }) {
353
+ if (browser) return /* @__PURE__ */ jsx(ArtifactBrowser, {
354
+ items,
355
+ onOpen,
356
+ loading,
357
+ error,
358
+ browser
359
+ });
237
360
  return /* @__PURE__ */ jsxs(View, {
238
361
  testID: grid ? "artifacts-grid" : "artifacts-recent",
239
362
  style: styles$3.list,
@@ -284,7 +407,392 @@ function ArtifactList({ items, onOpen, loading, error, grid = false }) {
284
407
  ]
285
408
  });
286
409
  }
410
+ const LAYOUTS = [
411
+ {
412
+ value: "tree",
413
+ label: "Tree"
414
+ },
415
+ {
416
+ value: "list",
417
+ label: "List"
418
+ },
419
+ {
420
+ value: "grid",
421
+ label: "Grid"
422
+ }
423
+ ];
424
+ const TYPES = [
425
+ "any",
426
+ "Markdown",
427
+ "Image",
428
+ "Code",
429
+ "Data",
430
+ "Document",
431
+ "Other"
432
+ ];
433
+ const MODIFIED = [
434
+ {
435
+ value: "any",
436
+ label: "Any time"
437
+ },
438
+ {
439
+ value: "today",
440
+ label: "Today"
441
+ },
442
+ {
443
+ value: "7days",
444
+ label: "Last 7 days"
445
+ },
446
+ {
447
+ value: "30days",
448
+ label: "Last 30 days"
449
+ }
450
+ ];
451
+ const SORTS = [
452
+ {
453
+ value: "name",
454
+ label: "Name"
455
+ },
456
+ {
457
+ value: "modified",
458
+ label: "Modified"
459
+ },
460
+ {
461
+ value: "size",
462
+ label: "Size"
463
+ }
464
+ ];
465
+ const ROW_HEIGHT = 48;
466
+ const IMAGE_VIEWABILITY = { itemVisiblePercentThreshold: 1 };
467
+ function ArtifactBrowser({ items, onOpen, loading, error, browser: b }) {
468
+ const grid = b.layout === "grid";
469
+ const onViewableImagesChange = b.onViewableImagesChange;
470
+ const onViewableItemsChanged = useCallback(({ viewableItems }) => {
471
+ onViewableImagesChange?.(viewableItems.flatMap(({ item, isViewable }) => grid && isViewable && item.kind === "file" && artifactKind(item.item.path) === "Image" ? [item.item.path] : []));
472
+ }, [grid, onViewableImagesChange]);
473
+ const rows = b.layout === "tree" ? b.rows : items.map((item) => ({
474
+ kind: "file",
475
+ item,
476
+ depth: 0
477
+ }));
478
+ return /* @__PURE__ */ jsxs(View, {
479
+ style: styles$3.browser,
480
+ testID: "artifacts-browser",
481
+ children: [
482
+ /* @__PURE__ */ jsx(SegmentedControl, {
483
+ accessibilityLabel: "Artifact layout",
484
+ options: LAYOUTS,
485
+ value: b.layout,
486
+ onValueChange: (value) => {
487
+ if (isArtifactLayout(value)) b.onLayoutChange(value);
488
+ }
489
+ }),
490
+ /* @__PURE__ */ jsxs(View, {
491
+ style: styles$3.toolbar,
492
+ children: [/* @__PURE__ */ jsxs(View, {
493
+ style: styles$3.search,
494
+ children: [/* @__PURE__ */ jsx(SearchIcon, { size: 18 }), /* @__PURE__ */ jsx(Input, {
495
+ variant: "bare",
496
+ accessibilityLabel: "Search artifacts",
497
+ placeholder: "Search artifacts",
498
+ value: b.query,
499
+ onChangeText: b.onQueryChange,
500
+ style: styles$3.searchInput,
501
+ autoCapitalize: "none"
502
+ })]
503
+ }), /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsxs(DropdownMenuTrigger, {
504
+ variant: "outline",
505
+ accessibilityLabel: "Filters",
506
+ children: [/* @__PURE__ */ jsx(SlidersIcon, {}), "Filters"]
507
+ }), /* @__PURE__ */ jsxs(DropdownMenuContent, { children: [
508
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Type" }),
509
+ TYPES.map((type) => /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
510
+ checked: b.type === type,
511
+ onCheckedChange: () => b.onTypeChange(type),
512
+ children: type === "any" ? "All types" : type
513
+ }, type)),
514
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
515
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Modified" }),
516
+ MODIFIED.map(({ value, label }) => /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
517
+ checked: b.modified === value,
518
+ onCheckedChange: () => b.onModifiedChange(value),
519
+ children: label
520
+ }, value)),
521
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
522
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Sort" }),
523
+ SORTS.map(({ value, label }) => /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
524
+ checked: b.sort === value,
525
+ onCheckedChange: () => b.onSortChange(value),
526
+ children: label
527
+ }, value)),
528
+ /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
529
+ checked: b.direction === "asc",
530
+ onCheckedChange: () => b.onDirectionChange("asc"),
531
+ children: "Ascending"
532
+ }),
533
+ /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
534
+ checked: b.direction === "desc",
535
+ onCheckedChange: () => b.onDirectionChange("desc"),
536
+ children: "Descending"
537
+ })
538
+ ] })] })]
539
+ }),
540
+ /* @__PURE__ */ jsxs(View, {
541
+ style: styles$3.chips,
542
+ children: [
543
+ b.query ? /* @__PURE__ */ jsxs(Button, {
544
+ variant: "outline",
545
+ accessibilityLabel: "Remove search filter",
546
+ onPress: () => b.onQueryChange(""),
547
+ children: [
548
+ "Search: ",
549
+ b.query,
550
+ /* @__PURE__ */ jsx(CloseIcon, {})
551
+ ]
552
+ }) : null,
553
+ b.type !== "any" ? /* @__PURE__ */ jsxs(Button, {
554
+ variant: "outline",
555
+ accessibilityLabel: "Remove type filter",
556
+ onPress: () => b.onTypeChange("any"),
557
+ children: [b.type, /* @__PURE__ */ jsx(CloseIcon, {})]
558
+ }) : null,
559
+ b.modified !== "any" ? /* @__PURE__ */ jsxs(Button, {
560
+ variant: "outline",
561
+ accessibilityLabel: "Remove modified filter",
562
+ onPress: () => b.onModifiedChange("any"),
563
+ children: [MODIFIED.find((option) => option.value === b.modified)?.label, /* @__PURE__ */ jsx(CloseIcon, {})]
564
+ }) : null
565
+ ]
566
+ }),
567
+ error ? /* @__PURE__ */ jsx(Text, {
568
+ accessibilityRole: "alert",
569
+ style: styles$3.error,
570
+ children: error
571
+ }) : null,
572
+ loading ? /* @__PURE__ */ jsx(Text, {
573
+ style: styles$3.meta,
574
+ children: "Loading artifacts..."
575
+ }) : null,
576
+ /* @__PURE__ */ jsx(FlatList, {
577
+ onViewableItemsChanged,
578
+ viewabilityConfig: IMAGE_VIEWABILITY,
579
+ data: loading || error ? [] : rows,
580
+ style: styles$3.inventory,
581
+ numColumns: grid ? 2 : 1,
582
+ columnWrapperStyle: grid ? styles$3.columns : void 0,
583
+ keyExtractor: (row) => row.kind === "dir" ? `dir:${row.path}` : row.item.path,
584
+ ListEmptyComponent: !loading && !error ? /* @__PURE__ */ jsx(Text, {
585
+ style: styles$3.meta,
586
+ children: b.totalCount ? "No artifacts match these filters." : "Documents saved for this session will appear here."
587
+ }) : null,
588
+ renderItem: ({ item: row }) => {
589
+ if (row.kind === "dir") return /* @__PURE__ */ jsxs(Button, {
590
+ variant: "ghost",
591
+ style: [styles$3.row, { paddingLeft: row.depth * 16 }],
592
+ accessibilityLabel: `${row.open ? "Collapse" : "Expand"} ${row.path}`,
593
+ accessibilityState: { expanded: row.open },
594
+ onPress: () => b.onToggleDirectory(row.path),
595
+ children: [
596
+ row.open ? /* @__PURE__ */ jsx(ChevronDownIcon, {}) : /* @__PURE__ */ jsx(ChevronRightIcon, {}),
597
+ /* @__PURE__ */ jsx(FolderIcon, {}),
598
+ /* @__PURE__ */ jsx(Text, {
599
+ numberOfLines: 1,
600
+ style: [styles$3.name, styles$3.label],
601
+ children: row.name
602
+ }),
603
+ /* @__PURE__ */ jsx(Text, {
604
+ style: styles$3.meta,
605
+ children: row.count
606
+ })
607
+ ]
608
+ });
609
+ const item = row.item;
610
+ const image = artifactKind(item.path) === "Image";
611
+ const selected = b.selected?.path === item.path;
612
+ return /* @__PURE__ */ jsxs(Button, {
613
+ variant: "ghost",
614
+ size: "card",
615
+ testID: `artifact-${item.path}`,
616
+ accessibilityLabel: `Select ${item.path}`,
617
+ accessibilityState: { selected },
618
+ onPress: () => b.onSelect(item),
619
+ style: [
620
+ grid ? styles$3.tile : styles$3.row,
621
+ selected && styles$3.selected,
622
+ !grid && { paddingLeft: row.depth * 16 }
623
+ ],
624
+ children: [
625
+ b.layout === "tree" ? /* @__PURE__ */ jsx(View, {
626
+ accessible: false,
627
+ style: styles$3.chevronGutter
628
+ }) : null,
629
+ grid ? /* @__PURE__ */ jsx(View, {
630
+ style: styles$3.thumbnail,
631
+ children: image && b.renderImage ? b.renderImage(item) : image ? /* @__PURE__ */ jsx(ImageIcon, { size: 28 }) : /* @__PURE__ */ jsx(FileIcon, { size: 28 })
632
+ }) : image ? /* @__PURE__ */ jsx(ImageIcon, { size: 18 }) : /* @__PURE__ */ jsx(FileIcon, { size: 18 }),
633
+ /* @__PURE__ */ jsxs(View, {
634
+ style: styles$3.label,
635
+ children: [/* @__PURE__ */ jsx(Text, {
636
+ numberOfLines: 1,
637
+ style: styles$3.name,
638
+ children: item.name
639
+ }), /* @__PURE__ */ jsx(Text, {
640
+ numberOfLines: 1,
641
+ style: styles$3.path,
642
+ children: item.path
643
+ })]
644
+ }),
645
+ /* @__PURE__ */ jsx(Text, {
646
+ style: styles$3.meta,
647
+ children: sizeLabel(item.size)
648
+ })
649
+ ]
650
+ });
651
+ }
652
+ }, b.layout),
653
+ /* @__PURE__ */ jsxs(Text, {
654
+ style: styles$3.meta,
655
+ children: [
656
+ items.length,
657
+ " of ",
658
+ b.totalCount,
659
+ " artifacts"
660
+ ]
661
+ }),
662
+ b.selected ? /* @__PURE__ */ jsxs(View, {
663
+ style: styles$3.selection,
664
+ testID: "artifact-selection",
665
+ children: [
666
+ /* @__PURE__ */ jsx(Text, {
667
+ numberOfLines: 1,
668
+ style: styles$3.name,
669
+ children: b.selected.name
670
+ }),
671
+ /* @__PURE__ */ jsx(Text, {
672
+ numberOfLines: 2,
673
+ style: styles$3.path,
674
+ children: b.selected.path
675
+ }),
676
+ /* @__PURE__ */ jsxs(Text, {
677
+ style: styles$3.meta,
678
+ children: [
679
+ artifactKind(b.selected.path),
680
+ " · ",
681
+ sizeLabel(b.selected.size)
682
+ ]
683
+ }),
684
+ /* @__PURE__ */ jsxs(View, {
685
+ style: styles$3.actions,
686
+ children: [/* @__PURE__ */ jsx(Button, {
687
+ variant: "outline",
688
+ onPress: b.onCloseSelection,
689
+ children: "Close"
690
+ }), /* @__PURE__ */ jsx(Button, {
691
+ variant: "primary",
692
+ onPress: () => {
693
+ if (b.selected) onOpen(b.selected.path);
694
+ },
695
+ children: "Open"
696
+ })]
697
+ })
698
+ ]
699
+ }) : null
700
+ ]
701
+ });
702
+ }
287
703
  const styles$3 = StyleSheet.create((theme) => ({
704
+ browser: {
705
+ flex: 1,
706
+ gap: theme.spacing(3),
707
+ minHeight: 0,
708
+ uni__dependencies: [0]
709
+ },
710
+ toolbar: {
711
+ flexDirection: "row",
712
+ alignItems: "center",
713
+ gap: theme.spacing(2),
714
+ uni__dependencies: [0]
715
+ },
716
+ search: {
717
+ flex: 1,
718
+ minWidth: 0,
719
+ flexDirection: "row",
720
+ alignItems: "center",
721
+ gap: theme.spacing(2),
722
+ paddingHorizontal: theme.spacing(2),
723
+ borderWidth: 1,
724
+ borderColor: theme.colors.border,
725
+ borderRadius: theme.borderRadius.DEFAULT,
726
+ backgroundColor: theme.colors.deep,
727
+ uni__dependencies: [0]
728
+ },
729
+ searchInput: { flex: 1 },
730
+ chips: {
731
+ flexDirection: "row",
732
+ flexWrap: "wrap",
733
+ gap: theme.spacing(2),
734
+ uni__dependencies: [0]
735
+ },
736
+ inventory: { flex: 1 },
737
+ row: {
738
+ height: ROW_HEIGHT,
739
+ minHeight: ROW_HEIGHT,
740
+ flexDirection: "row",
741
+ alignItems: "center",
742
+ justifyContent: "flex-start",
743
+ gap: theme.spacing(2),
744
+ borderWidth: 1,
745
+ borderColor: theme.colors["border-soft"],
746
+ borderRadius: theme.borderRadius.DEFAULT,
747
+ paddingVertical: 0,
748
+ uni__dependencies: [0]
749
+ },
750
+ chevronGutter: { width: 16 },
751
+ columns: {
752
+ gap: theme.spacing(2),
753
+ uni__dependencies: [0]
754
+ },
755
+ tile: {
756
+ flex: 1,
757
+ maxWidth: "50%",
758
+ flexDirection: "column",
759
+ alignItems: "stretch",
760
+ gap: theme.spacing(2),
761
+ borderWidth: 1,
762
+ borderColor: theme.colors["border-soft"],
763
+ marginBottom: theme.spacing(2),
764
+ uni__dependencies: [0]
765
+ },
766
+ thumbnail: {
767
+ height: 96,
768
+ backgroundColor: theme.colors.deep,
769
+ borderRadius: theme.borderRadius.DEFAULT,
770
+ overflow: "hidden",
771
+ alignItems: "center",
772
+ justifyContent: "center",
773
+ uni__dependencies: [0]
774
+ },
775
+ selected: {
776
+ backgroundColor: theme.colors["tint-green"],
777
+ borderColor: theme.colors["edge-green"],
778
+ uni__dependencies: [0]
779
+ },
780
+ selection: {
781
+ flexShrink: 0,
782
+ padding: theme.spacing(3),
783
+ gap: theme.spacing(2),
784
+ borderWidth: 1,
785
+ borderColor: theme.colors.border,
786
+ borderRadius: theme.borderRadius.DEFAULT,
787
+ backgroundColor: theme.colors.panel,
788
+ uni__dependencies: [0]
789
+ },
790
+ actions: {
791
+ flexDirection: "row",
792
+ justifyContent: "flex-end",
793
+ gap: theme.spacing(2),
794
+ uni__dependencies: [0]
795
+ },
288
796
  list: {
289
797
  gap: theme.spacing(2),
290
798
  uni__dependencies: [0]
@@ -418,17 +926,17 @@ const styles$2 = StyleSheet.create((theme) => ({
418
926
  }));
419
927
  //#endregion
420
928
  //#region src/extensions/workspaces/sessions/(frontend)/_components/ArtifactPanel.native.tsx
421
- function ArtifactPanel({ path, ...props }) {
929
+ function ArtifactPanel({ path, scope = "artifacts", ...props }) {
422
930
  const item = useArtifacts(props.sessionId).items.find((item) => item.path === path);
423
931
  const version = `${item?.modifiedAt ?? ""}:${item?.size ?? ""}`;
424
- const downloadKey = `${props.sessionId}:${path}`;
932
+ const downloadKey = `${scope === "temporary" ? "temporary:" : ""}${props.sessionId}:${path}`;
425
933
  const key = `${downloadKey}:${version}`;
426
934
  const [loaded, setLoaded] = useState();
427
935
  useEffect(() => {
428
936
  if (props.sessionId === null) return;
429
937
  const sessionId = props.sessionId;
430
938
  const controller = new AbortController();
431
- fetchArtifactPreview(sessionId, path, controller.signal).then(async (preview) => {
939
+ fetchArtifactPreview(sessionId, path, controller.signal, scope).then(async (preview) => {
432
940
  if (controller.signal.aborted) return;
433
941
  setLoaded({
434
942
  key,
@@ -436,7 +944,7 @@ function ArtifactPanel({ path, ...props }) {
436
944
  });
437
945
  if (artifactPreviewMode(path) !== "media" || !props.renderMediaPreview) return;
438
946
  try {
439
- const media = await fetchArtifactMedia(sessionId, path, controller.signal);
947
+ const media = await fetchArtifactMedia(sessionId, path, controller.signal, scope);
440
948
  if (!controller.signal.aborted) setLoaded({
441
949
  key,
442
950
  preview,
@@ -460,7 +968,8 @@ function ArtifactPanel({ path, ...props }) {
460
968
  props.sessionId,
461
969
  path,
462
970
  key,
463
- props.renderMediaPreview
971
+ props.renderMediaPreview,
972
+ scope
464
973
  ]);
465
974
  const current = loaded?.key === key ? loaded : void 0;
466
975
  const downloadController = useRef(void 0);
@@ -468,7 +977,11 @@ function ArtifactPanel({ path, ...props }) {
468
977
  useEffect(() => () => {
469
978
  downloadController.current?.abort();
470
979
  downloadController.current = void 0;
471
- }, [props.sessionId, path]);
980
+ }, [
981
+ props.sessionId,
982
+ path,
983
+ scope
984
+ ]);
472
985
  const saving = download?.key === downloadKey && download.saving === true;
473
986
  const save = async () => {
474
987
  if (props.sessionId === null || !props.nativeSaveFile || downloadController.current) return;
@@ -479,7 +992,7 @@ function ArtifactPanel({ path, ...props }) {
479
992
  saving: true
480
993
  });
481
994
  try {
482
- const file = await prepareArtifactSave(props.sessionId, path, controller.signal);
995
+ const file = await prepareArtifactSave(props.sessionId, path, controller.signal, scope);
483
996
  if (controller.signal.aborted || downloadController.current !== controller) return;
484
997
  await props.nativeSaveFile(file);
485
998
  if (!controller.signal.aborted && downloadController.current === controller) setDownload({
@@ -547,7 +1060,7 @@ function ArtifactPanel({ path, ...props }) {
547
1060
  media: current.media,
548
1061
  mediaError: current.mediaError,
549
1062
  onOpen: (path) => {
550
- if (props.sessionId !== null) props.openTransientTab(artifactTab(props.sessionId, path));
1063
+ if (props.sessionId !== null) props.openTransientTab(artifactTab(props.sessionId, path, scope));
551
1064
  }
552
1065
  }) : /* @__PURE__ */ jsx(Text, {
553
1066
  style: styles$1.meta,
@@ -556,14 +1069,15 @@ function ArtifactPanel({ path, ...props }) {
556
1069
  ]
557
1070
  });
558
1071
  }
559
- function artifactTab(sessionId, path) {
1072
+ function artifactTab(sessionId, path, scope = "artifacts") {
560
1073
  return {
561
- id: artifactTabId(sessionId, path),
1074
+ id: `${scope === "temporary" ? "temporary:" : ""}${artifactTabId(sessionId, path)}`,
562
1075
  label: path.split("/").at(-1) ?? path,
563
1076
  panel: (props) => /* @__PURE__ */ jsx(ArtifactPanel, {
564
1077
  ...props,
565
1078
  sessionId,
566
- path
1079
+ path,
1080
+ scope
567
1081
  })
568
1082
  };
569
1083
  }
@@ -601,28 +1115,116 @@ const styles$1 = StyleSheet.create((theme) => ({
601
1115
  //#endregion
602
1116
  //#region src/extensions/workspaces/sessions/(frontend)/_components/ArtifactsPanel.native.tsx
603
1117
  function ArtifactsPanel(props) {
1118
+ return /* @__PURE__ */ jsx(SessionArtifactsPanel, { ...props }, props.sessionId);
1119
+ }
1120
+ function SessionArtifactsPanel(props) {
604
1121
  const snapshot = useArtifacts(props.sessionId, true);
605
- return /* @__PURE__ */ jsxs(ScrollView, {
606
- contentContainerStyle: styles.content,
1122
+ const layout = useSyncExternalStore((listener) => {
1123
+ const subscription = artifactLayout.store.subscribe(listener);
1124
+ return () => subscription.unsubscribe();
1125
+ }, () => artifactLayout.store.state);
1126
+ const [now, setNow] = useState(Date.now);
1127
+ useEffect(() => {
1128
+ const refreshClock = () => setNow(Date.now());
1129
+ const subscription = artifacts.store.subscribe(refreshClock);
1130
+ const timer = setInterval(refreshClock, 6e4);
1131
+ return () => {
1132
+ subscription.unsubscribe();
1133
+ clearInterval(timer);
1134
+ };
1135
+ }, []);
1136
+ const [query, setQuery] = useState("");
1137
+ const [type, setType] = useState("any");
1138
+ const [modified, setModified] = useState("any");
1139
+ const [sort, setSort] = useState("name");
1140
+ const [direction, setDirection] = useState("asc");
1141
+ const [expanded, setExpanded] = useState([]);
1142
+ const [selection, setSelection] = useState();
1143
+ const [viewable, setViewable] = useState([]);
1144
+ if (snapshot.loaded && selection && !snapshot.items.some((item) => item.path === selection)) setSelection(void 0);
1145
+ const hasFilters = query !== "" || type !== "any" || modified !== "any";
1146
+ const visible = sortArtifacts(filterArtifacts(snapshot.items, {
1147
+ query,
1148
+ type,
1149
+ modified
1150
+ }, now), sort, direction);
1151
+ return /* @__PURE__ */ jsxs(View, {
1152
+ style: styles.content,
607
1153
  children: [/* @__PURE__ */ jsx(Text, {
608
1154
  accessibilityRole: "header",
609
1155
  style: styles.heading,
610
1156
  children: "Artifacts"
611
1157
  }), /* @__PURE__ */ jsx(ArtifactList, {
612
- grid: true,
613
- items: snapshot.items,
1158
+ items: visible,
614
1159
  loading: !snapshot.loaded,
615
1160
  error: props.sessionId === null ? "The session is unavailable." : snapshot.error,
616
1161
  onOpen: (path) => {
617
1162
  if (props.sessionId !== null) props.openTransientTab(artifactTab(props.sessionId, path));
1163
+ },
1164
+ browser: {
1165
+ layout,
1166
+ onLayoutChange: (next) => {
1167
+ setViewable([]);
1168
+ artifactLayout.update(() => next);
1169
+ },
1170
+ query,
1171
+ onQueryChange: setQuery,
1172
+ type,
1173
+ onTypeChange: setType,
1174
+ modified,
1175
+ onModifiedChange: (value) => {
1176
+ setModified(value);
1177
+ setNow(Date.now());
1178
+ },
1179
+ sort,
1180
+ onSortChange: setSort,
1181
+ direction,
1182
+ onDirectionChange: setDirection,
1183
+ rows: artifactTree(visible, (path) => hasFilters || expanded.includes(path)),
1184
+ onToggleDirectory: (path) => setExpanded((paths) => paths.includes(path) ? paths.filter((value) => value !== path) : [...paths, path]),
1185
+ selected: snapshot.items.find((item) => item.path === selection),
1186
+ onSelect: (item) => setSelection(item.path),
1187
+ onCloseSelection: () => setSelection(void 0),
1188
+ totalCount: snapshot.items.length,
1189
+ onViewableImagesChange: setViewable,
1190
+ renderImage: (item) => /* @__PURE__ */ jsx(ArtifactThumbnail, {
1191
+ sessionId: props.sessionId,
1192
+ item,
1193
+ active: layout === "grid" && viewable.includes(item.path)
1194
+ }, `${props.sessionId}:${item.path}:${item.modifiedAt}:${item.size}`)
618
1195
  }
619
1196
  })]
620
1197
  });
621
1198
  }
1199
+ function ArtifactThumbnail({ sessionId, item, active }) {
1200
+ const [uri, setUri] = useState();
1201
+ useEffect(() => {
1202
+ if (!active || sessionId === null || item.size > 5242880) return;
1203
+ const controller = new AbortController();
1204
+ fetchArtifactMedia(sessionId, item.path, controller.signal).then((media) => {
1205
+ if (!controller.signal.aborted && media.mimeType.startsWith("image/")) setUri(`data:${media.mimeType};base64,${media.data}`);
1206
+ }).catch(() => {
1207
+ if (!controller.signal.aborted) setUri(void 0);
1208
+ });
1209
+ return () => controller.abort();
1210
+ }, [
1211
+ sessionId,
1212
+ item.path,
1213
+ item.size,
1214
+ item.modifiedAt,
1215
+ active
1216
+ ]);
1217
+ return active && uri ? /* @__PURE__ */ jsx(Image, {
1218
+ accessibilityLabel: item.name,
1219
+ source: { uri },
1220
+ resizeMode: "contain",
1221
+ style: styles.image
1222
+ }) : /* @__PURE__ */ jsx(ImageIcon, { size: 28 });
1223
+ }
622
1224
  function ArtifactsActivitySection(props) {
623
1225
  const snapshot = useArtifacts(props.sessionId);
624
1226
  return /* @__PURE__ */ jsx(ArtifactList, {
625
- items: snapshot.items.slice(0, 3),
1227
+ items: recentArtifacts(snapshot.items),
626
1228
  loading: !snapshot.loaded,
627
1229
  error: props.sessionId === null ? "The session is unavailable." : snapshot.error,
628
1230
  onOpen: (path) => {
@@ -638,7 +1240,13 @@ function artifactsTab() {
638
1240
  };
639
1241
  }
640
1242
  const styles = StyleSheet.create((theme) => ({
1243
+ image: {
1244
+ width: "100%",
1245
+ height: "100%"
1246
+ },
641
1247
  content: {
1248
+ flex: 1,
1249
+ minHeight: 0,
642
1250
  padding: theme.spacing(4),
643
1251
  gap: theme.spacing(4),
644
1252
  uni__dependencies: [0]