@agimon-ai/po-session 0.0.0-alpha.145 → 0.0.0-alpha.147

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.
@@ -1,4 +1,4 @@
1
- import { defineFill, defineGlobalStore, defineNativePlugin, defineWebLifecycle } from "@agimon-ai/po-core/native";
1
+ import { defineFill, defineHostStore, defineNativePlugin, defineWebLifecycle } from "@agimon-ai/po-core/native";
2
2
  import { View } from "react-native-unistyles/components/native/View";
3
3
  import { Text } from "react-native-unistyles/components/native/Text";
4
4
  import { Button, Dot, Input, ListRow, SheetBody, SheetDescription, SheetFooter, fontOf } from "@agimon-ai/po-native-components";
@@ -65,7 +65,7 @@ async function deliverToSession(runtimes, input) {
65
65
  * po-core/native only. The phone has no menu-to-overlay handoff, so only the
66
66
  * runtime list and the send live here.
67
67
  */
68
- const runtimes = defineGlobalStore([]);
68
+ const runtimes = defineHostStore([]);
69
69
  function startSendToSessionRuntime(runtime) {
70
70
  runtimes.update((current) => [...current, runtime]);
71
71
  return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));
@@ -1 +1 @@
1
- {"version":3,"file":"native.mjs","names":["WebPluginSessionOption","WebPluginSlotProps","Button","Dot","fontOf","Input","ListRow","SheetBody","SheetDescription","SheetFooter","useEffect","useMemo","useRef","useState","StyleSheet","sendToSession","TONE","running","waiting","idle","const","SendToSessionPanel","sessionId","listSessions","takeComposerDraft","appendComposerDraft","sessions","to","setTo","busy","setBusy","error","setError","held","text","inFlight","live","giveBack","current","state","undefined","send","Promise","trim","refusal","from","SendToSessionViewProps","onPick","id","onSend","SendToSessionView","filter","setFilter","shown","query","toLowerCase","session","name","detail","includes","target","find","styles","alert","length","empty","rows","map","index","separator","row","create","theme","small","fontFamily","sans","fontSize","sm","lineHeight","borderTopWidth","hairlineWidth","borderBottomWidth","borderColor","colors","uni__dependencies","paddingHorizontal","spacing","height","backgroundColor","color","dim","paddingVertical","textAlign","red","fillSendToSession","lifecycleStart"],"sources":["../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionDelivery.ts","../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionRequest.native.ts","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionPanel.native.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.native.tsx","../../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.native.ts","../../generated/native.ts"],"sourcesContent":["import type { WebPluginRuntime } from '@agimon-ai/po-core/web';\n\n/**\n * Delivers one send through the started runtime that owns the sending session.\n *\n * DESIGN PATTERNS:\n * - Host-neutral and stateless: the web and native request files each keep\n * their own runtime list (from their own po-core entry) and pass it in.\n * The phone starts one runtime per computer; a send goes through the one\n * that owns the sending session, with that computer's local ids.\n *\n * AVOID:\n * - Value imports from a po-core entry here. Native plugins may not import\n * `po-core/web`, and web plugins may not import `po-core/native`.\n */\n\n/** The runtime that owns `from`, with both ids as its computer knows them; undefined when none does. */\nfunction route(runtimes: readonly WebPluginRuntime[], input: { from: string; to: string }) {\n const owners = runtimes.flatMap((runtime) => {\n try {\n const from = runtime.localSessionId?.(input.from) ?? input.from;\n const to = runtime.localSessionId?.(input.to) ?? input.to;\n // An unqualified id belongs to the computer that would leave it unqualified (the local hub).\n const owns = from !== input.from || (runtime.qualifySessionId?.(input.from) ?? input.from) === input.from;\n return owns ? [{ runtime, from, to }] : [];\n } catch {\n // localSessionId refuses an id of another computer: this runtime does not own the send.\n return [];\n }\n });\n return owners.at(-1);\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport async function deliverToSession(\n runtimes: readonly WebPluginRuntime[],\n input: { from: string; to: string; text: string },\n): Promise<string | undefined> {\n const owner = route(runtimes, input);\n if (!owner) return 'Po is not connected. Your text is kept; try again.';\n try {\n await owner.runtime.invokeServerMethod({\n mount: { scope: 'host' },\n service: 'sessions',\n method: 'sendToSession',\n input: { from: owner.from, to: owner.to, text: input.text },\n });\n return undefined;\n } catch (error) {\n return error instanceof Error && error.message !== '' ? error.message : 'The message was not delivered.';\n }\n}\n","import { defineGlobalStore, type WebPluginRuntime } from '@agimon-ai/po-core/native';\n\nimport { deliverToSession } from './sendToSessionDelivery';\n\n/**\n * The phone's started runtimes, one per computer, for the send-to-session panel.\n *\n * DESIGN PATTERNS:\n * - The native twin of sendToSessionRequest.ts: a native plugin may import\n * po-core/native only. The phone has no menu-to-overlay handoff, so only the\n * runtime list and the send live here.\n */\n\nconst runtimes = defineGlobalStore<readonly WebPluginRuntime[]>([]);\n\nexport function startSendToSessionRuntime(runtime: WebPluginRuntime): () => void {\n runtimes.update((current) => [...current, runtime]);\n return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport function sendToSession(input: { from: string; to: string; text: string }): Promise<string | undefined> {\n return deliverToSession(runtimes.store.state, input);\n}\n","import type { WebPluginSessionOption, WebPluginSlotProps } from '@agimon-ai/po-core/native';\nimport {\n Button,\n Dot,\n fontOf,\n Input,\n ListRow,\n SheetBody,\n SheetDescription,\n SheetFooter,\n} from '@agimon-ai/po-native-components';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { Text, View } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { sendToSession } from '../../_lib/sendToSessionRequest.native';\n\n/**\n * The phone's \"Send to session…\" page of the composer's Insert sheet: pick a\n * live session, then Send steers what the person typed into it.\n *\n * DESIGN PATTERNS:\n * - The draft is taken only at Send, so opening and leaving the page never\n * touches it. A refused send keeps the taken text for a retry and hands it\n * back to the composer when the page goes away.\n * - The sheet closes when the page appends to the draft; an empty append\n * closes it and leaves the draft alone.\n *\n * AVOID:\n * - Sending on a row tap. On a phone a mis-tap would send; Send is its own button.\n */\n\nconst TONE = { running: 'green', waiting: 'magenta', idle: 'neutral' } as const;\n\n/** The Insert sheet page: lists the computer's live sessions and steers the composer's text into one. */\nexport function SendToSessionPanel({\n sessionId,\n listSessions,\n takeComposerDraft,\n appendComposerDraft,\n}: WebPluginSlotProps) {\n const [sessions] = useState(() => listSessions?.() ?? []);\n const [to, setTo] = useState<string>();\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState('');\n // Text taken from the composer and not yet delivered; `live` is false once the page is gone.\n const held = useRef<{ text?: string; inFlight: boolean; live: boolean }>({ inFlight: false, live: true });\n const giveBack = useRef(appendComposerDraft);\n useEffect(() => {\n giveBack.current = appendComposerDraft;\n }, [appendComposerDraft]);\n useEffect(() => {\n const state = held.current;\n state.live = true;\n return () => {\n state.live = false;\n if (state.text !== undefined && !state.inFlight) giveBack.current(state.text);\n };\n }, []);\n\n const send = async (): Promise<void> => {\n if (to === undefined || sessionId === null) return;\n const state = held.current;\n const text = state.text ?? takeComposerDraft?.() ?? '';\n if (text.trim() === '') {\n setError('Write something to send.');\n return;\n }\n state.text = text;\n state.inFlight = true;\n setBusy(true);\n setError('');\n const refusal = await sendToSession({ from: sessionId, to, text: text.trim() });\n state.inFlight = false;\n if (refusal === undefined) state.text = undefined;\n if (!state.live) {\n if (state.text !== undefined) giveBack.current(state.text);\n return;\n }\n if (refusal === undefined) {\n giveBack.current('');\n return;\n }\n setBusy(false);\n setError(refusal);\n };\n\n return (\n <SendToSessionView\n sessions={sessions}\n to={to}\n busy={busy}\n error={error}\n onPick={setTo}\n onSend={() => void send()}\n />\n );\n}\n\nexport interface SendToSessionViewProps {\n sessions: readonly WebPluginSessionOption[];\n to: string | undefined;\n busy: boolean;\n /** The server's refusal, shown above the list; empty when there is none. */\n error: string;\n onPick: (id: string) => void;\n onSend: () => void;\n}\n\nexport function SendToSessionView({ sessions, to, busy, error, onPick, onSend }: SendToSessionViewProps) {\n const [filter, setFilter] = useState('');\n const shown = useMemo(() => {\n const query = filter.trim().toLowerCase();\n return query === ''\n ? sessions\n : sessions.filter((session) => `${session.name} ${session.detail}`.toLowerCase().includes(query));\n }, [filter, sessions]);\n const target = sessions.find((session) => session.id === to);\n\n return (\n <>\n <SheetBody>\n <SheetDescription>Send what you typed to another session. It arrives there from you.</SheetDescription>\n {error === '' ? null : (\n <Text accessibilityRole=\"alert\" style={styles.alert}>\n {error}\n </Text>\n )}\n {sessions.length === 0 ? (\n <Text style={styles.empty}>No other session is running. Open one, then send.</Text>\n ) : (\n <>\n <Input\n accessibilityLabel=\"Filter sessions\"\n placeholder=\"Filter sessions\"\n value={filter}\n onChangeText={setFilter}\n />\n {shown.length === 0 ? (\n <Text style={styles.empty}>Nothing matches that filter</Text>\n ) : (\n <View style={styles.rows}>\n {shown.map((session, index) => (\n <View key={session.id}>\n {index > 0 ? <View style={styles.separator} /> : null}\n <ListRow\n accessibilityLabel={`${session.name}, ${session.detail}`}\n selected={session.id === to}\n disabled={busy}\n onPress={() => onPick(session.id)}\n disclosure={false}\n style={styles.row}\n leading={<Dot tone={TONE[session.state]} size=\"md\" />}\n title={session.name}\n description={\n <Text numberOfLines={1} style={styles.detail}>\n {session.detail}\n </Text>\n }\n />\n </View>\n ))}\n </View>\n )}\n </>\n )}\n </SheetBody>\n <SheetFooter>\n <Button variant=\"primary\" disabled={busy || target === undefined} onPress={onSend}>\n {busy ? 'Sending…' : target === undefined ? 'Pick a session' : `Send to ${target.name}`}\n </Button>\n </SheetFooter>\n </>\n );\n}\n\nconst styles = StyleSheet.create((theme) => {\n const small = {\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n };\n return {\n rows: {\n borderTopWidth: StyleSheet.hairlineWidth,\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderColor: theme.colors['border-soft'],\n },\n row: { paddingHorizontal: theme.spacing(1) },\n separator: { height: StyleSheet.hairlineWidth, backgroundColor: theme.colors['border-soft'] },\n detail: { ...small, color: theme.colors.dim },\n empty: { ...small, paddingVertical: theme.spacing(6), textAlign: 'center', color: theme.colors.dim },\n alert: { ...small, color: theme.colors.red },\n };\n});\n","import { defineFill } from '@agimon-ai/po-core/native';\n\nimport { SendToSessionPanel } from './_components/SendToSessionPanel.native';\n\n/** The phone's Insert sheet draws `data` as the row and `component` as the page it opens. */\nexport default defineFill({\n data: { title: 'Send to session…', hint: 'Steer another session with what you typed' },\n component: SendToSessionPanel,\n});\n","import { defineWebLifecycle } from '@agimon-ai/po-core/native';\n\nimport { startSendToSessionRuntime } from '../_lib/sendToSessionRequest.native';\n\nexport default defineWebLifecycle(startSendToSessionRuntime);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineNativePlugin, type WebPluginContributions } from '@agimon-ai/po-core/native';\n\nimport fillSendToSession from '../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.native';\nimport lifecycleStart from '../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.native';\n\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const nativePlugin = defineNativePlugin({\n id: 'sessions',\n session: {\n get fills(): WebPluginContributions['fills'] { return [via({ slot: 'composer-menu', id: 'send-to-session' }, fillSendToSession)]; },\n get start(): WebPluginContributions['start'] { return lifecycleStart; },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAS,MAAM,UAAuC,OAAqC;CAazF,OAZe,SAAS,SAAS,YAAY;EAC3C,IAAI;GACF,MAAM,OAAO,QAAQ,iBAAiB,MAAM,IAAI,KAAK,MAAM;GAC3D,MAAM,KAAK,QAAQ,iBAAiB,MAAM,EAAE,KAAK,MAAM;GAGvD,OADa,SAAS,MAAM,SAAS,QAAQ,mBAAmB,MAAM,IAAI,KAAK,MAAM,UAAU,MAAM,OACvF,CAAC;IAAE;IAAS;IAAM;GAAG,CAAC,IAAI,CAAC;EAC3C,QAAQ;GAEN,OAAO,CAAC;EACV;CACF,CACY,CAAC,CAAC,GAAG,EAAE;AACrB;;AAGA,eAAsB,iBACpB,UACA,OAC6B;CAC7B,MAAM,QAAQ,MAAM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MAAM,OAAU,UAAmC,UAChD,UAAU,KAAA,IAAY,KAAA,IAAY;CAAE,GAAG;CAAU,GAAI;AAAiB;AAEzE,MAAa,eAAe,mBAAmB;CAC7C,IAAI;CACJ,SAAS;EACP,IAAI,QAAyC;GAAE,OAAO,CAAC,IAAI;IAAE,MAAM;IAAiB,IAAI;GAAkB,GAAGU,0CAAiB,CAAC;EAAG;EAClI,IAAI,QAAyC;GAAE,OAAOC;EAAgB;CACxE;AACF,CAAC"}
1
+ {"version":3,"file":"native.mjs","names":["WebPluginSessionOption","WebPluginSlotProps","Button","Dot","fontOf","Input","ListRow","SheetBody","SheetDescription","SheetFooter","useEffect","useMemo","useRef","useState","StyleSheet","sendToSession","TONE","running","waiting","idle","const","SendToSessionPanel","sessionId","listSessions","takeComposerDraft","appendComposerDraft","sessions","to","setTo","busy","setBusy","error","setError","held","text","inFlight","live","giveBack","current","state","undefined","send","Promise","trim","refusal","from","SendToSessionViewProps","onPick","id","onSend","SendToSessionView","filter","setFilter","shown","query","toLowerCase","session","name","detail","includes","target","find","styles","alert","length","empty","rows","map","index","separator","row","create","theme","small","fontFamily","sans","fontSize","sm","lineHeight","borderTopWidth","hairlineWidth","borderBottomWidth","borderColor","colors","uni__dependencies","paddingHorizontal","spacing","height","backgroundColor","color","dim","paddingVertical","textAlign","red","fillSendToSession","lifecycleStart"],"sources":["../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionDelivery.ts","../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionRequest.native.ts","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionPanel.native.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.native.tsx","../../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.native.ts","../../generated/native.ts"],"sourcesContent":["import type { WebPluginRuntime } from '@agimon-ai/po-core/web';\n\n/**\n * Delivers one send through the started runtime that owns the sending session.\n *\n * DESIGN PATTERNS:\n * - Host-neutral and stateless: the web and native request files each keep\n * their own runtime list (from their own po-core entry) and pass it in.\n * The phone starts one runtime per computer; a send goes through the one\n * that owns the sending session, with that computer's local ids.\n *\n * AVOID:\n * - Value imports from a po-core entry here. Native plugins may not import\n * `po-core/web`, and web plugins may not import `po-core/native`.\n */\n\n/** The runtime that owns `from`, with both ids as its computer knows them; undefined when none does. */\nfunction route(runtimes: readonly WebPluginRuntime[], input: { from: string; to: string }) {\n const owners = runtimes.flatMap((runtime) => {\n try {\n const from = runtime.localSessionId?.(input.from) ?? input.from;\n const to = runtime.localSessionId?.(input.to) ?? input.to;\n // An unqualified id belongs to the computer that would leave it unqualified (the local hub).\n const owns = from !== input.from || (runtime.qualifySessionId?.(input.from) ?? input.from) === input.from;\n return owns ? [{ runtime, from, to }] : [];\n } catch {\n // localSessionId refuses an id of another computer: this runtime does not own the send.\n return [];\n }\n });\n return owners.at(-1);\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport async function deliverToSession(\n runtimes: readonly WebPluginRuntime[],\n input: { from: string; to: string; text: string },\n): Promise<string | undefined> {\n const owner = route(runtimes, input);\n if (!owner) return 'Po is not connected. Your text is kept; try again.';\n try {\n await owner.runtime.invokeServerMethod({\n mount: { scope: 'host' },\n service: 'sessions',\n method: 'sendToSession',\n input: { from: owner.from, to: owner.to, text: input.text },\n });\n return undefined;\n } catch (error) {\n return error instanceof Error && error.message !== '' ? error.message : 'The message was not delivered.';\n }\n}\n","import { defineHostStore, type WebPluginRuntime } from '@agimon-ai/po-core/native';\n\nimport { deliverToSession } from './sendToSessionDelivery';\n\n/**\n * The phone's started runtimes, one per computer, for the send-to-session panel.\n *\n * DESIGN PATTERNS:\n * - The native twin of sendToSessionRequest.ts: a native plugin may import\n * po-core/native only. The phone has no menu-to-overlay handoff, so only the\n * runtime list and the send live here.\n */\n\nconst runtimes = defineHostStore<readonly WebPluginRuntime[]>([]);\n\nexport function startSendToSessionRuntime(runtime: WebPluginRuntime): () => void {\n runtimes.update((current) => [...current, runtime]);\n return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport function sendToSession(input: { from: string; to: string; text: string }): Promise<string | undefined> {\n return deliverToSession(runtimes.store.state, input);\n}\n","import type { WebPluginSessionOption, WebPluginSlotProps } from '@agimon-ai/po-core/native';\nimport {\n Button,\n Dot,\n fontOf,\n Input,\n ListRow,\n SheetBody,\n SheetDescription,\n SheetFooter,\n} from '@agimon-ai/po-native-components';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { Text, View } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { sendToSession } from '../../_lib/sendToSessionRequest.native';\n\n/**\n * The phone's \"Send to session…\" page of the composer's Insert sheet: pick a\n * live session, then Send steers what the person typed into it.\n *\n * DESIGN PATTERNS:\n * - The draft is taken only at Send, so opening and leaving the page never\n * touches it. A refused send keeps the taken text for a retry and hands it\n * back to the composer when the page goes away.\n * - The sheet closes when the page appends to the draft; an empty append\n * closes it and leaves the draft alone.\n *\n * AVOID:\n * - Sending on a row tap. On a phone a mis-tap would send; Send is its own button.\n */\n\nconst TONE = { running: 'green', waiting: 'magenta', idle: 'neutral' } as const;\n\n/** The Insert sheet page: lists the computer's live sessions and steers the composer's text into one. */\nexport function SendToSessionPanel({\n sessionId,\n listSessions,\n takeComposerDraft,\n appendComposerDraft,\n}: WebPluginSlotProps) {\n const [sessions] = useState(() => listSessions?.() ?? []);\n const [to, setTo] = useState<string>();\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState('');\n // Text taken from the composer and not yet delivered; `live` is false once the page is gone.\n const held = useRef<{ text?: string; inFlight: boolean; live: boolean }>({ inFlight: false, live: true });\n const giveBack = useRef(appendComposerDraft);\n useEffect(() => {\n giveBack.current = appendComposerDraft;\n }, [appendComposerDraft]);\n useEffect(() => {\n const state = held.current;\n state.live = true;\n return () => {\n state.live = false;\n if (state.text !== undefined && !state.inFlight) giveBack.current(state.text);\n };\n }, []);\n\n const send = async (): Promise<void> => {\n if (to === undefined || sessionId === null) return;\n const state = held.current;\n const text = state.text ?? takeComposerDraft?.() ?? '';\n if (text.trim() === '') {\n setError('Write something to send.');\n return;\n }\n state.text = text;\n state.inFlight = true;\n setBusy(true);\n setError('');\n const refusal = await sendToSession({ from: sessionId, to, text: text.trim() });\n state.inFlight = false;\n if (refusal === undefined) state.text = undefined;\n if (!state.live) {\n if (state.text !== undefined) giveBack.current(state.text);\n return;\n }\n if (refusal === undefined) {\n giveBack.current('');\n return;\n }\n setBusy(false);\n setError(refusal);\n };\n\n return (\n <SendToSessionView\n sessions={sessions}\n to={to}\n busy={busy}\n error={error}\n onPick={setTo}\n onSend={() => void send()}\n />\n );\n}\n\nexport interface SendToSessionViewProps {\n sessions: readonly WebPluginSessionOption[];\n to: string | undefined;\n busy: boolean;\n /** The server's refusal, shown above the list; empty when there is none. */\n error: string;\n onPick: (id: string) => void;\n onSend: () => void;\n}\n\nexport function SendToSessionView({ sessions, to, busy, error, onPick, onSend }: SendToSessionViewProps) {\n const [filter, setFilter] = useState('');\n const shown = useMemo(() => {\n const query = filter.trim().toLowerCase();\n return query === ''\n ? sessions\n : sessions.filter((session) => `${session.name} ${session.detail}`.toLowerCase().includes(query));\n }, [filter, sessions]);\n const target = sessions.find((session) => session.id === to);\n\n return (\n <>\n <SheetBody>\n <SheetDescription>Send what you typed to another session. It arrives there from you.</SheetDescription>\n {error === '' ? null : (\n <Text accessibilityRole=\"alert\" style={styles.alert}>\n {error}\n </Text>\n )}\n {sessions.length === 0 ? (\n <Text style={styles.empty}>No other session is running. Open one, then send.</Text>\n ) : (\n <>\n <Input\n accessibilityLabel=\"Filter sessions\"\n placeholder=\"Filter sessions\"\n value={filter}\n onChangeText={setFilter}\n />\n {shown.length === 0 ? (\n <Text style={styles.empty}>Nothing matches that filter</Text>\n ) : (\n <View style={styles.rows}>\n {shown.map((session, index) => (\n <View key={session.id}>\n {index > 0 ? <View style={styles.separator} /> : null}\n <ListRow\n accessibilityLabel={`${session.name}, ${session.detail}`}\n selected={session.id === to}\n disabled={busy}\n onPress={() => onPick(session.id)}\n disclosure={false}\n style={styles.row}\n leading={<Dot tone={TONE[session.state]} size=\"md\" />}\n title={session.name}\n description={\n <Text numberOfLines={1} style={styles.detail}>\n {session.detail}\n </Text>\n }\n />\n </View>\n ))}\n </View>\n )}\n </>\n )}\n </SheetBody>\n <SheetFooter>\n <Button variant=\"primary\" disabled={busy || target === undefined} onPress={onSend}>\n {busy ? 'Sending…' : target === undefined ? 'Pick a session' : `Send to ${target.name}`}\n </Button>\n </SheetFooter>\n </>\n );\n}\n\nconst styles = StyleSheet.create((theme) => {\n const small = {\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n };\n return {\n rows: {\n borderTopWidth: StyleSheet.hairlineWidth,\n borderBottomWidth: StyleSheet.hairlineWidth,\n borderColor: theme.colors['border-soft'],\n },\n row: { paddingHorizontal: theme.spacing(1) },\n separator: { height: StyleSheet.hairlineWidth, backgroundColor: theme.colors['border-soft'] },\n detail: { ...small, color: theme.colors.dim },\n empty: { ...small, paddingVertical: theme.spacing(6), textAlign: 'center', color: theme.colors.dim },\n alert: { ...small, color: theme.colors.red },\n };\n});\n","import { defineFill } from '@agimon-ai/po-core/native';\n\nimport { SendToSessionPanel } from './_components/SendToSessionPanel.native';\n\n/** The phone's Insert sheet draws `data` as the row and `component` as the page it opens. */\nexport default defineFill({\n data: { title: 'Send to session…', hint: 'Steer another session with what you typed' },\n component: SendToSessionPanel,\n});\n","import { defineWebLifecycle } from '@agimon-ai/po-core/native';\n\nimport { startSendToSessionRuntime } from '../_lib/sendToSessionRequest.native';\n\nexport default defineWebLifecycle(startSendToSessionRuntime);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineNativePlugin, type WebPluginContributions } from '@agimon-ai/po-core/native';\n\nimport fillSendToSession from '../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.native';\nimport lifecycleStart from '../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.native';\n\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const nativePlugin = defineNativePlugin({\n id: 'sessions',\n session: {\n get fills(): WebPluginContributions['fills'] { return [via({ slot: 'composer-menu', id: 'send-to-session' }, fillSendToSession)]; },\n get start(): WebPluginContributions['start'] { return lifecycleStart; },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAS,MAAM,UAAuC,OAAqC;CAazF,OAZe,SAAS,SAAS,YAAY;EAC3C,IAAI;GACF,MAAM,OAAO,QAAQ,iBAAiB,MAAM,IAAI,KAAK,MAAM;GAC3D,MAAM,KAAK,QAAQ,iBAAiB,MAAM,EAAE,KAAK,MAAM;GAGvD,OADa,SAAS,MAAM,SAAS,QAAQ,mBAAmB,MAAM,IAAI,KAAK,MAAM,UAAU,MAAM,OACvF,CAAC;IAAE;IAAS;IAAM;GAAG,CAAC,IAAI,CAAC;EAC3C,QAAQ;GAEN,OAAO,CAAC;EACV;CACF,CACY,CAAC,CAAC,GAAG,EAAE;AACrB;;AAGA,eAAsB,iBACpB,UACA,OAC6B;CAC7B,MAAM,QAAQ,MAAM,UAAU,KAAK;CACnC,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,MAAM,MAAM,QAAQ,mBAAmB;GACrC,OAAO,EAAE,OAAO,OAAO;GACvB,SAAS;GACT,QAAQ;GACR,OAAO;IAAE,MAAM,MAAM;IAAM,IAAI,MAAM;IAAI,MAAM,MAAM;GAAK;EAC5D,CAAC;EACD;CACF,SAAS,OAAO;EACd,OAAO,iBAAiB,SAAS,MAAM,YAAY,KAAK,MAAM,UAAU;CAC1E;AACF;;;;;;;;;;;ACtCA,MAAM,WAAW,gBAA6C,CAAC,CAAC;AAEhE,SAAgB,0BAA0B,SAAuC;CAC/E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HostStore, defineWebLifecycle, defineWebPlugin } from "@agimon-ai/po-core/web";
2
2
  import { Button, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Dot, OptionLabel, OptionRow, PickerList, SendIcon, Textarea } from "@agimon-ai/po-web-components";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { useEffect, useState } from "react";
@@ -54,8 +54,8 @@ async function deliverToSession(runtimes, input) {
54
54
  }
55
55
  //#endregion
56
56
  //#region src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionRequest.ts
57
- const request = defineGlobalStore(void 0);
58
- const runtimes = defineGlobalStore([]);
57
+ const request = defineHostStore(void 0);
58
+ const runtimes = defineHostStore([]);
59
59
  function startSendToSessionRuntime(runtime) {
60
60
  runtimes.update((current) => [...current, runtime]);
61
61
  return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));
@@ -1 +1 @@
1
- {"version":3,"file":"web.mjs","names":["fillSendToSession","fillSendToSessionDialog","lifecycleStart"],"sources":["../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionDelivery.ts","../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionRequest.ts","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionMenuItem.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.web.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionDialog.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionDialogHost.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/SendToSessionDialog.overlay.web.tsx","../../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.web.ts","../../generated/web.ts"],"sourcesContent":["import type { WebPluginRuntime } from '@agimon-ai/po-core/web';\n\n/**\n * Delivers one send through the started runtime that owns the sending session.\n *\n * DESIGN PATTERNS:\n * - Host-neutral and stateless: the web and native request files each keep\n * their own runtime list (from their own po-core entry) and pass it in.\n * The phone starts one runtime per computer; a send goes through the one\n * that owns the sending session, with that computer's local ids.\n *\n * AVOID:\n * - Value imports from a po-core entry here. Native plugins may not import\n * `po-core/web`, and web plugins may not import `po-core/native`.\n */\n\n/** The runtime that owns `from`, with both ids as its computer knows them; undefined when none does. */\nfunction route(runtimes: readonly WebPluginRuntime[], input: { from: string; to: string }) {\n const owners = runtimes.flatMap((runtime) => {\n try {\n const from = runtime.localSessionId?.(input.from) ?? input.from;\n const to = runtime.localSessionId?.(input.to) ?? input.to;\n // An unqualified id belongs to the computer that would leave it unqualified (the local hub).\n const owns = from !== input.from || (runtime.qualifySessionId?.(input.from) ?? input.from) === input.from;\n return owns ? [{ runtime, from, to }] : [];\n } catch {\n // localSessionId refuses an id of another computer: this runtime does not own the send.\n return [];\n }\n });\n return owners.at(-1);\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport async function deliverToSession(\n runtimes: readonly WebPluginRuntime[],\n input: { from: string; to: string; text: string },\n): Promise<string | undefined> {\n const owner = route(runtimes, input);\n if (!owner) return 'Po is not connected. Your text is kept; try again.';\n try {\n await owner.runtime.invokeServerMethod({\n mount: { scope: 'host' },\n service: 'sessions',\n method: 'sendToSession',\n input: { from: owner.from, to: owner.to, text: input.text },\n });\n return undefined;\n } catch (error) {\n return error instanceof Error && error.message !== '' ? error.message : 'The message was not delivered.';\n }\n}\n","import { defineGlobalStore, type WebPluginRuntime } from '@agimon-ai/po-core/web';\n\nimport { deliverToSession } from './sendToSessionDelivery';\n\n/**\n * Package-local handoff from the composer's '+' row to the dialog that sends,\n * plus the page runtime the dialog calls the server through.\n *\n * DESIGN PATTERNS:\n * - The menu row unmounts the moment the menu closes, so it publishes one\n * short-lived request carrying the draft it took; the overlay owns the dialog.\n * - The lifecycle keeps each started runtime here, because slot props carry no\n * server method call. sendToSessionDelivery picks the one that owns the send.\n * - sendToSessionRequest.native.ts is the phone's copy of the runtime list; it\n * imports po-core/native, which a native plugin may load and this file may not.\n *\n * AVOID:\n * - Persisting the taken draft. Cancel hands it back to the composer instead.\n */\n\n/** One ask to send; `text` is the draft the row took, possibly empty. */\nexport interface SendToSessionRequest {\n text: string;\n}\n\nconst request = defineGlobalStore<SendToSessionRequest | undefined>(undefined);\nconst runtimes = defineGlobalStore<readonly WebPluginRuntime[]>([]);\n\nexport function startSendToSessionRuntime(runtime: WebPluginRuntime): () => void {\n runtimes.update((current) => [...current, runtime]);\n return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));\n}\n\nexport function requestSendToSession(text: string): void {\n request.update(() => ({ text }));\n}\n\nexport function subscribeSendToSessionRequest(listener: (request: SendToSessionRequest) => void): () => void {\n const deliver = (): void => {\n const next = request.store.state;\n if (!next) return;\n request.reset();\n listener(next);\n };\n const subscription = request.store.subscribe(deliver);\n deliver();\n return () => subscription.unsubscribe();\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport function sendToSession(input: { from: string; to: string; text: string }): Promise<string | undefined> {\n return deliverToSession(runtimes.store.state, input);\n}\n","import type { WebPluginSlotProps } from '@agimon-ai/po-core/web';\nimport { OptionLabel, OptionRow, SendIcon } from '@agimon-ai/po-web-components';\n\nimport { requestSendToSession } from '../../_lib/sendToSessionRequest';\n\n/**\n * \"Send to session…\" in the composer's '+' menu.\n *\n * DESIGN PATTERNS:\n * - Stateless on purpose. The menu unmounts this on close, so the click takes\n * the draft and publishes it; the dialog lives in the overlay.\n * - Hidden in hosts that cannot list sessions or take the draft.\n */\nexport function SendToSessionMenuItem({ takeComposerDraft, listSessions }: WebPluginSlotProps) {\n if (!takeComposerDraft || !listSessions) return null;\n return (\n <OptionRow\n role=\"menuitem\"\n density=\"compact\"\n data-testid=\"composer-menu-send-to-session\"\n className=\"w-full text-po-text hover:bg-po-tint-blue\"\n onClick={() => requestSendToSession(takeComposerDraft())}\n >\n <SendIcon aria-hidden className=\"h-3 w-3 shrink-0\" />\n <OptionLabel density=\"compact\">Send to session…</OptionLabel>\n </OptionRow>\n );\n}\n","import { defineFill } from '@agimon-ai/po-core/web';\n\nimport { SendToSessionMenuItem } from './_components/SendToSessionMenuItem';\nexport default defineFill({ component: SendToSessionMenuItem });\n","import type { WebPluginSessionOption } from '@agimon-ai/po-core/web';\nimport {\n Button,\n Dialog,\n DialogBody,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Dot,\n PickerList,\n SendIcon,\n Textarea,\n} from '@agimon-ai/po-web-components';\n\n/** Running is Po at work (jade); waiting is a gentle ask of the person (rose). */\nconst TONE = { running: 'green', waiting: 'magenta', idle: 'neutral' } as const;\n\nexport interface SendToSessionDialogProps {\n open: boolean;\n sessions: readonly WebPluginSessionOption[];\n to: string | undefined;\n text: string;\n error: string;\n sending: boolean;\n onPick: (to: string) => void;\n onTextChange: (text: string) => void;\n onCancel: () => void;\n onSend: () => void;\n}\n\n/**\n * The \"Send to session\" dialog, drawn from the approved SessionMessagingDesign story.\n *\n * DESIGN PATTERNS:\n * - Controlled: the overlay host owns the text, pick and error, so a refusal\n * keeps what the person wrote.\n * - One jade primary action; red only for a real refusal.\n */\nexport function SendToSessionDialog({\n open,\n sessions,\n to,\n text,\n error,\n sending,\n onPick,\n onTextChange,\n onCancel,\n onSend,\n}: SendToSessionDialogProps) {\n const target = sessions.find((session) => session.id === to);\n return (\n <Dialog open={open} onOpenChange={(next) => (next ? undefined : onCancel())}>\n <DialogContent width=\"md\" data-testid=\"send-to-session-dialog\">\n <DialogHeader>\n <DialogTitle>Send to session</DialogTitle>\n </DialogHeader>\n <DialogBody className=\"flex flex-col gap-3\">\n <DialogDescription>\n It reaches that session right away, in its current turn, as a message from you.\n </DialogDescription>\n {sessions.length === 0 ? (\n <p className=\"text-sm text-po-dim\">No other session is running. Open one, then send.</p>\n ) : (\n <PickerList\n label=\"Sessions\"\n items={sessions.map((session) => ({\n value: session.id,\n title: session.name,\n subtitle: session.detail,\n lead: <Dot tone={TONE[session.state]} size=\"md\" />,\n }))}\n value={to === undefined ? [] : [to]}\n filterable\n filterPlaceholder=\"Search sessions\"\n onSelect={onPick}\n className=\"max-h-56 rounded-md border border-po-border\"\n />\n )}\n <Textarea\n aria-label=\"Message\"\n rows={3}\n value={text}\n data-testid=\"send-to-session-text\"\n onChange={(event) => onTextChange(event.currentTarget.value)}\n />\n {error === '' ? null : (\n <p role=\"alert\" className=\"text-sm text-po-red\">\n {error}\n </p>\n )}\n <DialogFooter>\n <Button variant=\"outline\" size=\"md\" onClick={onCancel}>\n Cancel\n </Button>\n <Button\n variant=\"primary\"\n size=\"md\"\n className=\"gap-1.5\"\n data-testid=\"send-to-session-send\"\n disabled={target === undefined || text.trim() === '' || sending}\n onClick={onSend}\n >\n <SendIcon aria-hidden className=\"size-3.5\" />\n {target === undefined ? 'Send' : `Send to ${target.name}`}\n </Button>\n </DialogFooter>\n </DialogBody>\n </DialogContent>\n </Dialog>\n );\n}\n","import type { WebPluginSessionOption, WebPluginSlotProps } from '@agimon-ai/po-core/web';\nimport { useEffect, useState } from 'react';\n\nimport { sendToSession, subscribeSendToSessionRequest } from '../../_lib/sendToSessionRequest';\nimport { SendToSessionDialog } from './SendToSessionDialog';\n\n/**\n * The send dialog's state. It fills an overlay, which stays mounted for the\n * page, because the '+' row that opens it unmounts when the menu closes.\n *\n * AVOID:\n * - Rendering anything while closed. This sits over the whole cockpit.\n */\nexport function SendToSessionDialogHost({ sessionId, listSessions, appendComposerDraft }: WebPluginSlotProps) {\n const [open, setOpen] = useState(false);\n const [sessions, setSessions] = useState<readonly WebPluginSessionOption[]>([]);\n const [to, setTo] = useState<string | undefined>(undefined);\n const [text, setText] = useState('');\n const [error, setError] = useState('');\n const [sending, setSending] = useState(false);\n\n useEffect(\n () =>\n subscribeSendToSessionRequest((request) => {\n setSessions(listSessions?.() ?? []);\n setTo(undefined);\n setText(request.text);\n setError('');\n setOpen(true);\n }),\n [listSessions],\n );\n\n if (!open || sessionId === null) return null;\n\n const cancel = (): void => {\n if (sending) return;\n // The text came out of the composer; a cancel puts it back.\n appendComposerDraft(text);\n setOpen(false);\n };\n\n const send = async (): Promise<void> => {\n if (to === undefined) return;\n setSending(true);\n const refusal = await sendToSession({ from: sessionId, to, text: text.trim() });\n setSending(false);\n if (refusal === undefined) setOpen(false);\n else setError(refusal);\n };\n\n return (\n <SendToSessionDialog\n open\n sessions={sessions}\n to={to}\n text={text}\n error={error}\n sending={sending}\n onPick={setTo}\n onTextChange={setText}\n onCancel={cancel}\n onSend={() => void send()}\n />\n );\n}\n","import { defineFill } from '@agimon-ai/po-core/web';\n\nimport { SendToSessionDialogHost } from './_components/SendToSessionDialogHost';\nexport default defineFill({ component: SendToSessionDialogHost });\n","import { defineWebLifecycle } from '@agimon-ai/po-core/web';\n\nimport { startSendToSessionRuntime } from '../_lib/sendToSessionRequest';\n\nexport default defineWebLifecycle(startSendToSessionRuntime);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineWebPlugin, type WebPluginContributions } from '@agimon-ai/po-core/web';\n\nimport fillSendToSession from '../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.web';\nimport fillSendToSessionDialog from '../src/extensions/workspaces/sessions/(frontend)/fill/SendToSessionDialog.overlay.web';\nimport lifecycleStart from '../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.web';\n\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const webPlugin = defineWebPlugin({\n id: 'sessions',\n session: {\n get fills(): WebPluginContributions['fills'] { return [via({ slot: 'composer-menu', id: 'send-to-session' }, fillSendToSession), via({ slot: 'overlay', id: 'send-to-session-dialog' }, fillSendToSessionDialog)]; },\n get start(): WebPluginContributions['start'] { return lifecycleStart; },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,SAAS,MAAM,UAAuC,OAAqC;CAazF,OAZe,SAAS,SAAS,YAAY;EAC3C,IAAI;GACF,MAAM,OAAO,QAAQ,iBAAiB,MAAM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;EACX,QAAQ,IAAI;CACd,CAAC,GACH,CAAC,YAAY,CACf;CAEA,IAAI,CAAC,QAAQ,cAAc,MAAM,OAAO;CAExC,MAAM,eAAqB;EACzB,IAAI,SAAS;EAEb,oBAAoB,IAAI;EACxB,QAAQ,KAAK;CACf;CAEA,MAAM,OAAO,YAA2B;EACtC,IAAI,OAAO,KAAA,GAAW;EACtB,WAAW,IAAI;EACf,MAAM,UAAU,MAAM,cAAc;GAAE,MAAM;GAAW;GAAI,MAAM,KAAK,KAAK;EAAE,CAAC;EAC9E,WAAW,KAAK;EAChB,IAAI,YAAY,KAAA,GAAW,QAAQ,KAAK;OACnC,SAAS,OAAO;CACvB;CAEA,OACE,oBAAC,qBAAD;EACE,MAAA;EACU;EACN;EACE;EACC;EACE;EACT,QAAQ;EACR,cAAc;EACd,UAAU;EACV,cAAc,KAAK,KAAK;CACzB,CAAA;AAEL;;;AC9DA,IAAA,0CAAe,WAAW,EAAE,WAAW,wBAAwB,CAAC;;;ACChE,IAAA,oBAAe,mBAAmB,yBAAyB;;;ACG3D,MAAM,OAAU,UAAmC,UAChD,UAAU,KAAA,IAAY,KAAA,IAAY;CAAE,GAAG;CAAU,GAAI;AAAiB;AAEzE,MAAa,YAAY,gBAAgB;CACvC,IAAI;CACJ,SAAS;EACP,IAAI,QAAyC;GAAE,OAAO,CAAC,IAAI;IAAE,MAAM;IAAiB,IAAI;GAAkB,GAAGA,uCAAiB,GAAG,IAAI;IAAE,MAAM;IAAW,IAAI;GAAyB,GAAGC,uCAAuB,CAAC;EAAG;EACnN,IAAI,QAAyC;GAAE,OAAOC;EAAgB;CACxE;AACF,CAAC"}
1
+ {"version":3,"file":"web.mjs","names":["fillSendToSession","fillSendToSessionDialog","lifecycleStart"],"sources":["../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionDelivery.ts","../../src/extensions/workspaces/sessions/(frontend)/_lib/sendToSessionRequest.ts","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionMenuItem.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.web.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionDialog.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/_components/SendToSessionDialogHost.tsx","../../src/extensions/workspaces/sessions/(frontend)/fill/SendToSessionDialog.overlay.web.tsx","../../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.web.ts","../../generated/web.ts"],"sourcesContent":["import type { WebPluginRuntime } from '@agimon-ai/po-core/web';\n\n/**\n * Delivers one send through the started runtime that owns the sending session.\n *\n * DESIGN PATTERNS:\n * - Host-neutral and stateless: the web and native request files each keep\n * their own runtime list (from their own po-core entry) and pass it in.\n * The phone starts one runtime per computer; a send goes through the one\n * that owns the sending session, with that computer's local ids.\n *\n * AVOID:\n * - Value imports from a po-core entry here. Native plugins may not import\n * `po-core/web`, and web plugins may not import `po-core/native`.\n */\n\n/** The runtime that owns `from`, with both ids as its computer knows them; undefined when none does. */\nfunction route(runtimes: readonly WebPluginRuntime[], input: { from: string; to: string }) {\n const owners = runtimes.flatMap((runtime) => {\n try {\n const from = runtime.localSessionId?.(input.from) ?? input.from;\n const to = runtime.localSessionId?.(input.to) ?? input.to;\n // An unqualified id belongs to the computer that would leave it unqualified (the local hub).\n const owns = from !== input.from || (runtime.qualifySessionId?.(input.from) ?? input.from) === input.from;\n return owns ? [{ runtime, from, to }] : [];\n } catch {\n // localSessionId refuses an id of another computer: this runtime does not own the send.\n return [];\n }\n });\n return owners.at(-1);\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport async function deliverToSession(\n runtimes: readonly WebPluginRuntime[],\n input: { from: string; to: string; text: string },\n): Promise<string | undefined> {\n const owner = route(runtimes, input);\n if (!owner) return 'Po is not connected. Your text is kept; try again.';\n try {\n await owner.runtime.invokeServerMethod({\n mount: { scope: 'host' },\n service: 'sessions',\n method: 'sendToSession',\n input: { from: owner.from, to: owner.to, text: input.text },\n });\n return undefined;\n } catch (error) {\n return error instanceof Error && error.message !== '' ? error.message : 'The message was not delivered.';\n }\n}\n","import { defineHostStore, type WebPluginRuntime } from '@agimon-ai/po-core/web';\n\nimport { deliverToSession } from './sendToSessionDelivery';\n\n/**\n * Package-local handoff from the composer's '+' row to the dialog that sends,\n * plus the page runtime the dialog calls the server through.\n *\n * DESIGN PATTERNS:\n * - The menu row unmounts the moment the menu closes, so it publishes one\n * short-lived request carrying the draft it took; the overlay owns the dialog.\n * - The lifecycle keeps each started runtime here, because slot props carry no\n * server method call. sendToSessionDelivery picks the one that owns the send.\n * - sendToSessionRequest.native.ts is the phone's copy of the runtime list; it\n * imports po-core/native, which a native plugin may load and this file may not.\n *\n * AVOID:\n * - Persisting the taken draft. Cancel hands it back to the composer instead.\n */\n\n/** One ask to send; `text` is the draft the row took, possibly empty. */\nexport interface SendToSessionRequest {\n text: string;\n}\n\nconst request = defineHostStore<SendToSessionRequest | undefined>(undefined);\nconst runtimes = defineHostStore<readonly WebPluginRuntime[]>([]);\n\nexport function startSendToSessionRuntime(runtime: WebPluginRuntime): () => void {\n runtimes.update((current) => [...current, runtime]);\n return () => runtimes.update((current) => current.filter((entry) => entry !== runtime));\n}\n\nexport function requestSendToSession(text: string): void {\n request.update(() => ({ text }));\n}\n\nexport function subscribeSendToSessionRequest(listener: (request: SendToSessionRequest) => void): () => void {\n const deliver = (): void => {\n const next = request.store.state;\n if (!next) return;\n request.reset();\n listener(next);\n };\n const subscription = request.store.subscribe(deliver);\n deliver();\n return () => subscription.unsubscribe();\n}\n\n/** Steers `text` into session `to`. Resolves to the reason shown when it was refused, or undefined once delivered. */\nexport function sendToSession(input: { from: string; to: string; text: string }): Promise<string | undefined> {\n return deliverToSession(runtimes.store.state, input);\n}\n","import type { WebPluginSlotProps } from '@agimon-ai/po-core/web';\nimport { OptionLabel, OptionRow, SendIcon } from '@agimon-ai/po-web-components';\n\nimport { requestSendToSession } from '../../_lib/sendToSessionRequest';\n\n/**\n * \"Send to session…\" in the composer's '+' menu.\n *\n * DESIGN PATTERNS:\n * - Stateless on purpose. The menu unmounts this on close, so the click takes\n * the draft and publishes it; the dialog lives in the overlay.\n * - Hidden in hosts that cannot list sessions or take the draft.\n */\nexport function SendToSessionMenuItem({ takeComposerDraft, listSessions }: WebPluginSlotProps) {\n if (!takeComposerDraft || !listSessions) return null;\n return (\n <OptionRow\n role=\"menuitem\"\n density=\"compact\"\n data-testid=\"composer-menu-send-to-session\"\n className=\"w-full text-po-text hover:bg-po-tint-blue\"\n onClick={() => requestSendToSession(takeComposerDraft())}\n >\n <SendIcon aria-hidden className=\"h-3 w-3 shrink-0\" />\n <OptionLabel density=\"compact\">Send to session…</OptionLabel>\n </OptionRow>\n );\n}\n","import { defineFill } from '@agimon-ai/po-core/web';\n\nimport { SendToSessionMenuItem } from './_components/SendToSessionMenuItem';\nexport default defineFill({ component: SendToSessionMenuItem });\n","import type { WebPluginSessionOption } from '@agimon-ai/po-core/web';\nimport {\n Button,\n Dialog,\n DialogBody,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Dot,\n PickerList,\n SendIcon,\n Textarea,\n} from '@agimon-ai/po-web-components';\n\n/** Running is Po at work (jade); waiting is a gentle ask of the person (rose). */\nconst TONE = { running: 'green', waiting: 'magenta', idle: 'neutral' } as const;\n\nexport interface SendToSessionDialogProps {\n open: boolean;\n sessions: readonly WebPluginSessionOption[];\n to: string | undefined;\n text: string;\n error: string;\n sending: boolean;\n onPick: (to: string) => void;\n onTextChange: (text: string) => void;\n onCancel: () => void;\n onSend: () => void;\n}\n\n/**\n * The \"Send to session\" dialog, drawn from the approved SessionMessagingDesign story.\n *\n * DESIGN PATTERNS:\n * - Controlled: the overlay host owns the text, pick and error, so a refusal\n * keeps what the person wrote.\n * - One jade primary action; red only for a real refusal.\n */\nexport function SendToSessionDialog({\n open,\n sessions,\n to,\n text,\n error,\n sending,\n onPick,\n onTextChange,\n onCancel,\n onSend,\n}: SendToSessionDialogProps) {\n const target = sessions.find((session) => session.id === to);\n return (\n <Dialog open={open} onOpenChange={(next) => (next ? undefined : onCancel())}>\n <DialogContent width=\"md\" data-testid=\"send-to-session-dialog\">\n <DialogHeader>\n <DialogTitle>Send to session</DialogTitle>\n </DialogHeader>\n <DialogBody className=\"flex flex-col gap-3\">\n <DialogDescription>\n It reaches that session right away, in its current turn, as a message from you.\n </DialogDescription>\n {sessions.length === 0 ? (\n <p className=\"text-sm text-po-dim\">No other session is running. Open one, then send.</p>\n ) : (\n <PickerList\n label=\"Sessions\"\n items={sessions.map((session) => ({\n value: session.id,\n title: session.name,\n subtitle: session.detail,\n lead: <Dot tone={TONE[session.state]} size=\"md\" />,\n }))}\n value={to === undefined ? [] : [to]}\n filterable\n filterPlaceholder=\"Search sessions\"\n onSelect={onPick}\n className=\"max-h-56 rounded-md border border-po-border\"\n />\n )}\n <Textarea\n aria-label=\"Message\"\n rows={3}\n value={text}\n data-testid=\"send-to-session-text\"\n onChange={(event) => onTextChange(event.currentTarget.value)}\n />\n {error === '' ? null : (\n <p role=\"alert\" className=\"text-sm text-po-red\">\n {error}\n </p>\n )}\n <DialogFooter>\n <Button variant=\"outline\" size=\"md\" onClick={onCancel}>\n Cancel\n </Button>\n <Button\n variant=\"primary\"\n size=\"md\"\n className=\"gap-1.5\"\n data-testid=\"send-to-session-send\"\n disabled={target === undefined || text.trim() === '' || sending}\n onClick={onSend}\n >\n <SendIcon aria-hidden className=\"size-3.5\" />\n {target === undefined ? 'Send' : `Send to ${target.name}`}\n </Button>\n </DialogFooter>\n </DialogBody>\n </DialogContent>\n </Dialog>\n );\n}\n","import type { WebPluginSessionOption, WebPluginSlotProps } from '@agimon-ai/po-core/web';\nimport { useEffect, useState } from 'react';\n\nimport { sendToSession, subscribeSendToSessionRequest } from '../../_lib/sendToSessionRequest';\nimport { SendToSessionDialog } from './SendToSessionDialog';\n\n/**\n * The send dialog's state. It fills an overlay, which stays mounted for the\n * page, because the '+' row that opens it unmounts when the menu closes.\n *\n * AVOID:\n * - Rendering anything while closed. This sits over the whole cockpit.\n */\nexport function SendToSessionDialogHost({ sessionId, listSessions, appendComposerDraft }: WebPluginSlotProps) {\n const [open, setOpen] = useState(false);\n const [sessions, setSessions] = useState<readonly WebPluginSessionOption[]>([]);\n const [to, setTo] = useState<string | undefined>(undefined);\n const [text, setText] = useState('');\n const [error, setError] = useState('');\n const [sending, setSending] = useState(false);\n\n useEffect(\n () =>\n subscribeSendToSessionRequest((request) => {\n setSessions(listSessions?.() ?? []);\n setTo(undefined);\n setText(request.text);\n setError('');\n setOpen(true);\n }),\n [listSessions],\n );\n\n if (!open || sessionId === null) return null;\n\n const cancel = (): void => {\n if (sending) return;\n // The text came out of the composer; a cancel puts it back.\n appendComposerDraft(text);\n setOpen(false);\n };\n\n const send = async (): Promise<void> => {\n if (to === undefined) return;\n setSending(true);\n const refusal = await sendToSession({ from: sessionId, to, text: text.trim() });\n setSending(false);\n if (refusal === undefined) setOpen(false);\n else setError(refusal);\n };\n\n return (\n <SendToSessionDialog\n open\n sessions={sessions}\n to={to}\n text={text}\n error={error}\n sending={sending}\n onPick={setTo}\n onTextChange={setText}\n onCancel={cancel}\n onSend={() => void send()}\n />\n );\n}\n","import { defineFill } from '@agimon-ai/po-core/web';\n\nimport { SendToSessionDialogHost } from './_components/SendToSessionDialogHost';\nexport default defineFill({ component: SendToSessionDialogHost });\n","import { defineWebLifecycle } from '@agimon-ai/po-core/web';\n\nimport { startSendToSessionRuntime } from '../_lib/sendToSessionRequest';\n\nexport default defineWebLifecycle(startSendToSessionRuntime);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineWebPlugin, type WebPluginContributions } from '@agimon-ai/po-core/web';\n\nimport fillSendToSession from '../src/extensions/workspaces/sessions/(frontend)/fill/SendToSession.composer-menu.web';\nimport fillSendToSessionDialog from '../src/extensions/workspaces/sessions/(frontend)/fill/SendToSessionDialog.overlay.web';\nimport lifecycleStart from '../src/extensions/workspaces/sessions/(frontend)/lifecycle/start.web';\n\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const webPlugin = defineWebPlugin({\n id: 'sessions',\n session: {\n get fills(): WebPluginContributions['fills'] { return [via({ slot: 'composer-menu', id: 'send-to-session' }, fillSendToSession), via({ slot: 'overlay', id: 'send-to-session-dialog' }, fillSendToSessionDialog)]; },\n get start(): WebPluginContributions['start'] { return lifecycleStart; },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,SAAS,MAAM,UAAuC,OAAqC;CAazF,OAZe,SAAS,SAAS,YAAY;EAC3C,IAAI;GACF,MAAM,OAAO,QAAQ,iBAAiB,MAAM,IAAI,KAAK,MAAM;GAC3D,MAAM,KAAK,QAAQ,iBAAiB,MAAM,EAAE,KAAK,MAAM;GAGvD,OADa,SAAS,MAAM,SAAS,QAAQ,mBAAmB,MAAM,IAAI,KAAK,MAAM,UAAU,MAAM,OACvF,CAAC;IAAE;IAAS;IAAM;GAAG,CAAC,IAAI,CAAC;EAC3C,QAAQ;GAEN,OAAO,CAAC;EACV;CACF,CACY,CAAC,CAAC,GAAG,EAAE;AACrB;;AAGA,eAAsB,iBACpB,UACA,OAC6B;CAC7B,MAAM,QAAQ,MAAM,UAAU,KAAK;CACnC,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI;EACF,MAAM,MAAM,QAAQ,mBAAmB;GACrC,OAAO,EAAE,OAAO,OAAO;GACvB,SAAS;GACT,QAAQ;GACR,OAAO;IAAE,MAAM,MAAM;IAAM,IAAI,MAAM;IAAI,MAAM,MAAM;GAAK;EAC5D,CAAC;EACD;CACF,SAAS,OAAO;EACd,OAAO,iBAAiB,SAAS,MAAM,YAAY,KAAK,MAAM,UAAU;CAC1E;AACF;;;AC1BA,MAAM,UAAU,gBAAkD,KAAA,CAAS;AAC3E,MAAM,WAAW,gBAA6C,CAAC,CAAC;AAEhE,SAAgB,0BAA0B,SAAuC;CAC/E,SA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ACJ,SAAS;EACP,IAAI,QAAyC;GAAE,OAAO,CAAC,IAAI;IAAE,MAAM;IAAiB,IAAI;GAAkB,GAAGA,uCAAiB,GAAG,IAAI;IAAE,MAAM;IAAW,IAAI;GAAyB,GAAGC,uCAAuB,CAAC;EAAG;EACnN,IAAI,QAAyC;GAAE,OAAOC;EAAgB;CACxE;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-session",
3
- "version": "0.0.0-alpha.145",
3
+ "version": "0.0.0-alpha.147",
4
4
  "description": "Shared session coordination services for Po.",
5
5
  "keywords": [
6
6
  "ai",
@@ -64,17 +64,17 @@
64
64
  "access": "public"
65
65
  },
66
66
  "dependencies": {
67
- "@agimon-ai/po-config": "0.0.0-alpha.145",
68
- "@agimon-ai/po-core": "0.0.0-alpha.145",
69
- "@agimon-ai/po-web-components": "0.0.0-alpha.145",
70
- "@agimon-ai/po-web-security": "0.0.0-alpha.145",
67
+ "@agimon-ai/po-config": "0.0.0-alpha.147",
68
+ "@agimon-ai/po-core": "0.0.0-alpha.147",
69
+ "@agimon-ai/po-web-components": "0.0.0-alpha.147",
70
+ "@agimon-ai/po-web-security": "0.0.0-alpha.147",
71
71
  "@deepseek-ai/cordis": "4.0.5",
72
72
  "typebox": "1.4.2"
73
73
  },
74
74
  "devDependencies": {
75
- "@agimon-ai/po-build": "0.0.0-alpha.145",
76
- "@agimon-ai/po-native-components": "0.0.0-alpha.145",
77
- "@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.145",
75
+ "@agimon-ai/po-build": "0.0.0-alpha.147",
76
+ "@agimon-ai/po-native-components": "0.0.0-alpha.147",
77
+ "@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.147",
78
78
  "@earendil-works/pi-coding-agent": "1.5.1",
79
79
  "@types/node": "26.6.5",
80
80
  "@types/react": "19.3.0",