@agimon-ai/po-template-advanced 0.0.0-alpha.74 → 0.0.0-alpha.75

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.
@@ -4,7 +4,7 @@ import { Text } from "react-native-unistyles/components/native/Text";
4
4
  import { SectionList } from "react-native-unistyles/components/native/SectionList";
5
5
  import { Pressable } from "react-native-unistyles/components/native/Pressable";
6
6
  import { ActivityIcon, AlertIcon, Badge, BranchIcon, Button, CheckIcon, CountBadge, EditIcon, EmptyState, FolderIcon, ForkIcon, HostTag, InfoStrip, Input, KebabIcon, Label, ListRow, LiveDuration, PlusIcon, Sheet, SheetBody, SheetContent, SheetHeader, SheetTitle, Spinner, Textarea, TrashIcon, UsersIcon, fontOf } from "@agimon-ai/po-native-components";
7
- import { useCallback, useEffect, useMemo, useState } from "react";
7
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
8
  import { StyleSheet } from "react-native-unistyles";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
10
  /** Every group some session uses, in rail order, with the other sessions in it. */
@@ -1351,8 +1351,9 @@ function sessionSections(workspaces, presentation, selectedHost = null) {
1351
1351
  return filter === null || owner === filter;
1352
1352
  });
1353
1353
  const sections = [];
1354
- for (const workspace of visible) {
1355
- const existing = presentation && presentation.hosts.length > 1 && !workspace.legacy ? sections.find((section) => !section.workspace.legacy && section.workspace.name === workspace.name) : void 0;
1354
+ for (const workspace of [...visible.filter((item) => item.kind === "session"), ...visible.filter((item) => item.kind !== "session")]) {
1355
+ if (workspace.kind === "session" && workspace.sessions.length === 0) continue;
1356
+ const existing = workspace.kind === "session" ? sections.find((section) => section.workspace.kind === "session") : presentation && presentation.hosts.length > 1 && !workspace.legacy ? sections.find((section) => section.workspace.kind !== "session" && !section.workspace.legacy && section.workspace.name === workspace.name) : void 0;
1356
1357
  if (existing) {
1357
1358
  existing.members.push(workspace);
1358
1359
  existing.data = [...existing.data, ...workspace.sessions];
@@ -1408,13 +1409,25 @@ function AdvancedSessions({ workspaces, openSession, actions, setHeaderAction, h
1408
1409
  }
1409
1410
  setAdding(true);
1410
1411
  }, [hosts]);
1411
- const titleAdd = canAdd && setHeaderAction !== void 0;
1412
+ const generalAction = useRef(actions.createGeneralSession);
1413
+ useEffect(() => {
1414
+ generalAction.current = actions.createGeneralSession;
1415
+ }, [actions.createGeneralSession]);
1416
+ const canGeneral = hosts.length > 0 ? hosts.some((host) => host.createGeneralSession !== void 0) : actions.createGeneralSession !== void 0;
1417
+ const beginGeneral = useCallback(() => {
1418
+ const host = hosts.find((host) => host.id === selected) ?? (hosts.length === 1 ? hosts[0] : void 0);
1419
+ if (host) {
1420
+ if (host.status === "connected") host.createGeneralSession?.();
1421
+ } else if (hosts.length > 1) setChoosing("general");
1422
+ else generalAction.current?.();
1423
+ }, [hosts, selected]);
1424
+ const titleAdd = (canGeneral || canAdd) && setHeaderAction !== void 0;
1412
1425
  useEffect(() => {
1413
1426
  if (!titleAdd) return;
1414
1427
  setHeaderAction(/* @__PURE__ */ jsx(IconButton, {
1415
- label: "Add workspace",
1416
- onPress: beginAdd,
1417
- disabled: hosts.length === 1 && hosts[0].status !== "connected",
1428
+ label: canGeneral ? "New session" : "Add workspace",
1429
+ onPress: canGeneral ? beginGeneral : beginAdd,
1430
+ disabled: canGeneral && selected !== null ? hosts.find((host) => host.id === selected)?.status !== "connected" : hosts.length === 1 && hosts[0].status !== "connected",
1418
1431
  children: /* @__PURE__ */ jsx(PlusIcon, {
1419
1432
  size: 18,
1420
1433
  color: "dim"
@@ -1425,7 +1438,10 @@ function AdvancedSessions({ workspaces, openSession, actions, setHeaderAction, h
1425
1438
  titleAdd,
1426
1439
  setHeaderAction,
1427
1440
  beginAdd,
1428
- hosts
1441
+ beginGeneral,
1442
+ canGeneral,
1443
+ hosts,
1444
+ selected
1429
1445
  ]);
1430
1446
  const sessions = workspaces.flatMap((workspace) => workspace.sessions).filter((session) => !stale(session.id));
1431
1447
  const { setSessionGroups, renameGroup, deleteGroup, removePendingSetup } = actions;
@@ -1445,7 +1461,7 @@ function AdvancedSessions({ workspaces, openSession, actions, setHeaderAction, h
1445
1461
  initialNumToRender: 12,
1446
1462
  maxToRenderPerBatch: 12,
1447
1463
  windowSize: 5,
1448
- renderSectionHeader: ({ section }) => /* @__PURE__ */ jsx(WorkspaceHeader, {
1464
+ renderSectionHeader: ({ section }) => section.workspace.kind === "session" ? null : /* @__PURE__ */ jsx(WorkspaceHeader, {
1449
1465
  workspace: section.workspace,
1450
1466
  actions,
1451
1467
  onWorkspaceMenu: (entry) => {
@@ -1483,23 +1499,28 @@ function AdvancedSessions({ workspaces, openSession, actions, setHeaderAction, h
1483
1499
  }),
1484
1500
  ListEmptyComponent: /* @__PURE__ */ jsx(EmptyState, {
1485
1501
  title: selected ? "No sessions on this computer." : "No sessions yet.",
1486
- description: "Add a workspace to start working with Po."
1502
+ description: canGeneral ? "Start a session to work with Po. No workspace needed." : "Add a workspace to start working with Po."
1487
1503
  }),
1488
1504
  ListHeaderComponent: /* @__PURE__ */ jsxs(View, {
1489
1505
  style: styles.listHeader,
1490
- children: [hosts.filter((host) => host.status !== "connected" && (selected === null || selected === host.id)).map((host) => /* @__PURE__ */ jsx(InfoStrip, {
1491
- message: host.status === "update_required" ? `${host.label} needs an app update. Sessions are read-only.` : `${host.label} is offline. Showing last known sessions.`,
1492
- actionLabel: "Retry",
1493
- onAction: host.onRetry
1494
- }, host.id)), canAdd && !titleAdd ? /* @__PURE__ */ jsxs(Button, {
1495
- variant: "ghost",
1496
- onPress: beginAdd,
1497
- disabled: hosts.length === 1 && hosts[0].status !== "connected",
1498
- children: [/* @__PURE__ */ jsx(PlusIcon, {
1499
- size: 18,
1500
- color: "dim"
1501
- }), "Add workspace"]
1502
- }) : null]
1506
+ children: [
1507
+ hosts.filter((host) => host.status !== "connected" && (selected === null || selected === host.id)).map((host) => /* @__PURE__ */ jsx(InfoStrip, {
1508
+ message: host.status === "update_required" ? `${host.label} needs an app update. Sessions are read-only.` : `${host.label} is offline. Showing last known sessions.`,
1509
+ actionLabel: "Retry",
1510
+ onAction: host.onRetry
1511
+ }, host.id)),
1512
+ canGeneral && !titleAdd ? /* @__PURE__ */ jsx(Button, {
1513
+ variant: "ghost",
1514
+ onPress: beginGeneral,
1515
+ children: "New session"
1516
+ }) : null,
1517
+ canAdd && (canGeneral || !titleAdd) ? /* @__PURE__ */ jsx(Button, {
1518
+ variant: "ghost",
1519
+ onPress: beginAdd,
1520
+ disabled: hosts.length === 1 && hosts[0].status !== "connected",
1521
+ children: "Add workspace"
1522
+ }) : null
1523
+ ]
1503
1524
  })
1504
1525
  }),
1505
1526
  /* @__PURE__ */ jsx(SessionMenuSheet, {
@@ -1537,7 +1558,15 @@ function AdvancedSessions({ workspaces, openSession, actions, setHeaderAction, h
1537
1558
  onOpenChange: (open) => {
1538
1559
  if (!open) setChoosing(null);
1539
1560
  },
1540
- children: /* @__PURE__ */ jsxs(SheetContent, { children: [/* @__PURE__ */ jsx(SheetHeader, { children: /* @__PURE__ */ jsx(SheetTitle, { children: "Which computer?" }) }), /* @__PURE__ */ jsx(SheetBody, { children: choosing === "add" ? hosts.map((host) => /* @__PURE__ */ jsxs(Button, {
1561
+ children: /* @__PURE__ */ jsxs(SheetContent, { children: [/* @__PURE__ */ jsx(SheetHeader, { children: /* @__PURE__ */ jsx(SheetTitle, { children: "Which computer?" }) }), /* @__PURE__ */ jsx(SheetBody, { children: choosing === "general" ? hosts.map((host) => /* @__PURE__ */ jsxs(Button, {
1562
+ variant: "ghost",
1563
+ disabled: host.status !== "connected" || !host.createGeneralSession,
1564
+ onPress: () => {
1565
+ setChoosing(null);
1566
+ host.createGeneralSession?.();
1567
+ },
1568
+ children: [host.label, host.status !== "connected" ? " · Unavailable" : ""]
1569
+ }, host.id)) : choosing === "add" ? hosts.map((host) => /* @__PURE__ */ jsxs(Button, {
1541
1570
  variant: "ghost",
1542
1571
  disabled: host.status !== "connected" || !host.addWorkspaceActions,
1543
1572
  onPress: () => {
@@ -1566,7 +1595,7 @@ function AdvancedSessions({ workspaces, openSession, actions, setHeaderAction, h
1566
1595
  }
1567
1596
  function sectionPath(sessionId, workspaces, sections) {
1568
1597
  const section = sections.find((entry) => entry.data.some(({ id }) => id === sessionId));
1569
- if (!section || new Set(section.members.map(({ root }) => root)).size < 2) return void 0;
1598
+ if (!section || section.workspace.kind === "session" || new Set(section.members.map(({ root }) => root)).size < 2) return void 0;
1570
1599
  return workspaces.find((workspace) => workspace.sessions.some(({ id }) => id === sessionId))?.root;
1571
1600
  }
1572
1601
  const styles = StyleSheet.create((theme) => {