@agimon-ai/po-approval 0.0.0-alpha.100

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.
@@ -0,0 +1,719 @@
1
+ import { defineActivityGroup, defineChannelFile, defineFill, defineGlobalStore, defineNativePlugin, defineSessionStore, defineToolRenderer, defineWebLifecycle, parsePoApprovalPrompt } from "@agimon-ai/po-core/native";
2
+ import { ArrowRightIcon, Button, ListRow, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, SectionLabel, ShieldIcon, fontOf, toolTone } from "@agimon-ai/po-native-components";
3
+ import { createElement, useCallback, useMemo, useSyncExternalStore } from "react";
4
+ import { View } from "react-native-unistyles/components/native/View";
5
+ import { Text } from "react-native-unistyles/components/native/Text";
6
+ import { StyleSheet } from "react-native-unistyles";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/types/approvalActivity.ts
9
+ /** The session channel the Activity card reads. */
10
+ const approvalActivityChannelType = "approval_activity";
11
+ /** The session methods the card answers through. */
12
+ const approvalMethodService = "approval";
13
+ //#endregion
14
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/approvalActivityModel.ts
15
+ const REASON_LIMIT = 600;
16
+ const NAME_LIMIT = 200;
17
+ function parseCard(input, parsePrompt) {
18
+ const prompt = parsePrompt(input);
19
+ if (prompt === void 0) return null;
20
+ const { revision, state, reason, sessionGone, sessionName, workspaceName } = input;
21
+ if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 1) return null;
22
+ if (state !== "pending" && state !== "approved" && state !== "running" && state !== "interrupted") return null;
23
+ return {
24
+ ...prompt,
25
+ revision,
26
+ state,
27
+ ...(state === "pending" || state === "approved") && sessionGone === true ? { sessionGone: true } : {},
28
+ ...typeof reason === "string" ? { reason: reason.slice(0, REASON_LIMIT) } : {},
29
+ ...typeof sessionName === "string" && sessionName !== "" ? { sessionName: sessionName.slice(0, NAME_LIMIT) } : {},
30
+ ...typeof workspaceName === "string" && workspaceName !== "" ? { workspaceName: workspaceName.slice(0, NAME_LIMIT) } : {}
31
+ };
32
+ }
33
+ /** The channel payload; malformed items are dropped, a malformed payload is refused. */
34
+ function parseApprovalActivity(input, parsePrompt) {
35
+ const approvals = input?.approvals;
36
+ if (!Array.isArray(approvals)) return null;
37
+ return { approvals: approvals.map((item) => parseCard(item, parsePrompt)).filter((card) => card !== null) };
38
+ }
39
+ /** A method reply; anything malformed reads as a failure with a plain sentence. */
40
+ function decisionFailure(reply) {
41
+ const value = reply;
42
+ if (value?.ok === true) return void 0;
43
+ return typeof value?.message === "string" && value.message !== "" ? value.message : "Po could not record that answer. The card shows where things stand now.";
44
+ }
45
+ /** Same state labels in the cockpit and phone. */
46
+ function approvalStateLabel(state) {
47
+ return {
48
+ pending: "Your approval",
49
+ approved: "Approved",
50
+ running: "Running…",
51
+ interrupted: "Outcome uncertain"
52
+ }[state];
53
+ }
54
+ /** The section's lead line: calm, whatever the count. */
55
+ function approvalSummary(approvals) {
56
+ const current = approvals.filter((card) => card.sessionGone !== true);
57
+ const pending = current.filter((card) => card.state === "pending").length;
58
+ if (approvals.length > 0 && current.length === 0) return "This session is gone. Nothing will run.";
59
+ if (pending === 0 && current.some((card) => card.state === "interrupted")) return "Outcome uncertain. Check before retrying.";
60
+ if (pending === 0 && current.some((card) => card.state === "running")) return "Po is running an approved call.";
61
+ if (pending === 0) return current.length === 1 ? "Approved. It runs when the session can." : "Approved. They run when the session can.";
62
+ if (pending === 1) return "One thing would like your eye, whenever you are ready.";
63
+ return `${pending} things would like your eye, whenever you are ready.`;
64
+ }
65
+ /** Where a Home card came from: its session and workspace, for example "Weekly report · agiflow". */
66
+ function approvalOrigin(card) {
67
+ return [card.sessionName ?? "A session", card.workspaceName].filter(Boolean).join(" · ");
68
+ }
69
+ /** Every session's open cards for Home, oldest first within a session, each keeping the session that answers it. */
70
+ function homeApprovals(state) {
71
+ return Object.entries(state).flatMap(([sessionId, activity]) => activity === void 0 ? [] : activity.approvals.map((card) => ({
72
+ sessionId,
73
+ card,
74
+ busy: activity.busy.includes(card.id),
75
+ ...activity.error === void 0 ? {} : { error: activity.error }
76
+ })));
77
+ }
78
+ //#endregion
79
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/approvalActivityStore.native.ts
80
+ /**
81
+ * The Activity card's view of this session's open approvals, and the person's answers.
82
+ *
83
+ * DESIGN PATTERNS:
84
+ * - Session store fed by the live channel and paginated global snapshots for dormant sessions.
85
+ * - Answers are typed global methods, not channel frames, so a refusal reaches the card that asked.
86
+ * - The method caller lives in a store rather than a module variable, because a web plugin keeps no
87
+ * mutable module state and the page may reconnect.
88
+ */
89
+ const approvalActivity = defineSessionStore({
90
+ approvals: [],
91
+ busy: []
92
+ });
93
+ function useApprovalActivity(sessionId) {
94
+ const subscribe = useCallback((listener) => {
95
+ const subscription = approvalActivity.store.subscribe(listener);
96
+ return () => subscription.unsubscribe();
97
+ }, []);
98
+ return useSyncExternalStore(subscribe, () => approvalActivity.select(approvalActivity.store.state, sessionId));
99
+ }
100
+ /** The group shows only while this session itself waits; gone sessions are answered from Home. */
101
+ const approvalActivitySource = {
102
+ subscribe(listener) {
103
+ const subscription = approvalActivity.store.subscribe(listener);
104
+ return () => subscription.unsubscribe();
105
+ },
106
+ isActive(sessionId) {
107
+ return approvalActivity.select(approvalActivity.store.state, sessionId).approvals.length > 0;
108
+ }
109
+ };
110
+ /** Every session's open cards, for Home. */
111
+ function useHomeApprovals() {
112
+ const read = () => approvalActivity.store.state;
113
+ const state = useSyncExternalStore(approvalActivitySource.subscribe, read, read);
114
+ return useMemo(() => homeApprovals(state), [state]);
115
+ }
116
+ const approvalActivityChannel = approvalActivity.channel({
117
+ channel: approvalActivityChannelType,
118
+ parse: (input) => parseApprovalActivity(input, parsePoApprovalPrompt),
119
+ reduce: (current, { approvals }) => ({
120
+ ...current,
121
+ approvals
122
+ })
123
+ });
124
+ const approvalHosts = defineGlobalStore([]);
125
+ const SNAPSHOT_INTERVAL_MS = 5e3;
126
+ /** Whether a host-qualified session id belongs to this runtime's computer. */
127
+ function owns(runtime, sessionId) {
128
+ try {
129
+ runtime.localSessionId?.(sessionId);
130
+ return true;
131
+ } catch {
132
+ return false;
133
+ }
134
+ }
135
+ /** Hydrates persisted cards even when their session plugin is not mounted. Never wakes a session. */
136
+ function startApprovalRuntime(runtime) {
137
+ const invoke = (call) => runtime.invokeServerMethod(call);
138
+ let stopped = false;
139
+ let refreshing;
140
+ let requested = false;
141
+ const refresh = () => {
142
+ requested = true;
143
+ if (refreshing !== void 0) return refreshing;
144
+ refreshing = (async () => {
145
+ while (requested && !stopped) {
146
+ requested = false;
147
+ try {
148
+ const cards = /* @__PURE__ */ new Map();
149
+ let offset = 0;
150
+ while (offset !== null && !stopped) {
151
+ const reply = await invoke({
152
+ mount: { scope: "global" },
153
+ service: approvalMethodService,
154
+ method: "snapshot",
155
+ input: { offset }
156
+ });
157
+ if (!Array.isArray(reply.cards) || reply.nextOffset !== null && (!Number.isSafeInteger(reply.nextOffset) || reply.nextOffset <= offset)) throw new Error("Invalid approval snapshot.");
158
+ for (const card of reply.cards) {
159
+ if (typeof card.sessionId !== "string") continue;
160
+ const parsed = parseApprovalActivity({ approvals: [card] }, parsePoApprovalPrompt)?.approvals[0];
161
+ if (parsed === void 0) continue;
162
+ const sessionId = runtime.qualifySessionId?.(card.sessionId) ?? card.sessionId;
163
+ const sessionCards = cards.get(sessionId) ?? [];
164
+ sessionCards.push(parsed);
165
+ cards.set(sessionId, sessionCards);
166
+ }
167
+ offset = reply.nextOffset;
168
+ }
169
+ if (stopped) return;
170
+ const known = Object.keys(approvalActivity.store.state).filter((sessionId) => owns(runtime, sessionId));
171
+ for (const sessionId of /* @__PURE__ */ new Set([...known, ...cards.keys()])) approvalActivity.update(sessionId, (current) => ({
172
+ ...current,
173
+ approvals: cards.get(sessionId) ?? [],
174
+ snapshotError: void 0
175
+ }));
176
+ } catch (error) {
177
+ if (stopped) return;
178
+ for (const sessionId of Object.keys(approvalActivity.store.state).filter((id) => owns(runtime, id))) approvalActivity.update(sessionId, (current) => ({
179
+ ...current,
180
+ snapshotError: error instanceof Error ? error.message : String(error)
181
+ }));
182
+ }
183
+ }
184
+ })().finally(() => {
185
+ refreshing = void 0;
186
+ });
187
+ return refreshing;
188
+ };
189
+ const entry = {
190
+ runtime,
191
+ refresh
192
+ };
193
+ approvalHosts.update((current) => [...current, entry]);
194
+ const disconnect = runtime.onHubConnected(() => void refresh());
195
+ const timer = setInterval(() => void refresh(), SNAPSHOT_INTERVAL_MS);
196
+ refresh();
197
+ return () => {
198
+ stopped = true;
199
+ clearInterval(timer);
200
+ disconnect();
201
+ approvalHosts.update((current) => current.filter((item) => item !== entry));
202
+ };
203
+ }
204
+ /**
205
+ * Sends one answer, holding the card's buttons until it lands. Undefined on success, otherwise the
206
+ * sentence the card shows. Refreshes persisted state after both accepted and refused answers.
207
+ */
208
+ async function answerApproval(sessionId, id, method, input) {
209
+ approvalActivity.update(sessionId, (current) => ({
210
+ ...current,
211
+ busy: [...current.busy, id],
212
+ error: void 0
213
+ }));
214
+ let reply;
215
+ try {
216
+ const hosts = approvalHosts.store.state;
217
+ const runtime = hosts.find((item) => owns(item.runtime, sessionId))?.runtime;
218
+ if (!runtime) throw new Error(hosts.length === 0 ? "Approvals are not connected yet." : "The computer this request came from is not connected right now.");
219
+ reply = await runtime.invokeServerMethod({
220
+ mount: { scope: "global" },
221
+ service: approvalMethodService,
222
+ method,
223
+ input: {
224
+ ...input,
225
+ sessionId: runtime.localSessionId?.(sessionId) ?? sessionId,
226
+ id
227
+ }
228
+ });
229
+ } catch (error) {
230
+ reply = {
231
+ ok: false,
232
+ message: error instanceof Error ? error.message : String(error)
233
+ };
234
+ }
235
+ const error = decisionFailure(reply);
236
+ approvalActivity.update(sessionId, (current) => ({
237
+ ...current,
238
+ busy: current.busy.filter((busy) => busy !== id),
239
+ ...error === void 0 ? {} : { error }
240
+ }));
241
+ await approvalHosts.store.state.find((item) => owns(item.runtime, sessionId))?.refresh();
242
+ return error;
243
+ }
244
+ //#endregion
245
+ //#region src/extensions/(frontend)/activity-group/approval.native.ts
246
+ var approval_native_default = defineActivityGroup({
247
+ keys: "g a",
248
+ icon: () => createElement(ShieldIcon),
249
+ activeSource: approvalActivitySource,
250
+ marksBackgroundWork: false,
251
+ hideWhenEmpty: true,
252
+ order: 5
253
+ });
254
+ //#endregion
255
+ //#region src/types/voiceHint.ts
256
+ function parseApprovalVoiceHintSource(input) {
257
+ const source = input;
258
+ return typeof source?.subscribe === "function" && typeof source.isActive === "function" ? source : null;
259
+ }
260
+ /** Voice fills this while installed; the hint shows only for `ask` approvals and only while a source is active. */
261
+ const approvalVoiceHintSlot = {
262
+ slot: "approval.voice-hint",
263
+ parse: parseApprovalVoiceHintSource
264
+ };
265
+ //#endregion
266
+ //#region src/extensions/workspaces/sessions/(frontend)/_components/ApprovalActivitySection.native.tsx
267
+ /**
268
+ * The Approval group's body in the phone's Activity sheet: one card per request this session is
269
+ * waiting on, the same states and copy as the cockpit.
270
+ */
271
+ function ApprovalActivitySection({ approvals, busy = [], error, voiceHint, onDecide, onDismiss }) {
272
+ if (approvals.length === 0) return /* @__PURE__ */ jsx(Text, {
273
+ style: styles$2.meta,
274
+ children: "Nothing is waiting for your approval."
275
+ });
276
+ const first = approvals.find((card) => card.state === "pending" && card.sessionGone !== true)?.id;
277
+ return /* @__PURE__ */ jsxs(View, {
278
+ style: styles$2.section,
279
+ children: [
280
+ /* @__PURE__ */ jsx(Text, {
281
+ style: styles$2.meta,
282
+ children: approvalSummary(approvals)
283
+ }),
284
+ error ? /* @__PURE__ */ jsx(Text, {
285
+ accessibilityRole: "alert",
286
+ style: styles$2.error,
287
+ children: error
288
+ }) : null,
289
+ approvals.map((card) => /* @__PURE__ */ jsx(ApprovalCard, {
290
+ card,
291
+ primary: card.id === first,
292
+ busy: busy.includes(card.id),
293
+ voiceHint: typeof voiceHint === "string" ? voiceHint : void 0,
294
+ onDecide,
295
+ onDismiss
296
+ }, card.id))
297
+ ]
298
+ });
299
+ }
300
+ function ApprovalCard({ card, primary, busy, voiceHint, origin, onOpenSession, onDecide, onDismiss }) {
301
+ const gone = card.sessionGone === true && (card.state === "pending" || card.state === "approved");
302
+ const pending = card.state === "pending" && !gone;
303
+ const note = gone ? "Nothing will run. Dismiss this request to clear it." : pending ? card.requirement === "human" ? "Only you can approve this in the app." : voiceHint ?? "Po keeps working while it waits." : card.reason ?? (card.state === "running" ? "Po is running this approved call." : card.state === "interrupted" ? "Check what happened before retrying. This will not run again automatically." : "It runs when the session can.");
304
+ return /* @__PURE__ */ jsxs(View, {
305
+ style: styles$2.card,
306
+ accessibilityLabel: card.title,
307
+ accessibilityState: { busy: busy || card.state === "running" },
308
+ children: [
309
+ /* @__PURE__ */ jsx(Text, {
310
+ style: [
311
+ styles$2.label,
312
+ !pending && styles$2.decidedLabel,
313
+ (gone || card.state === "interrupted") && styles$2.uncertainLabel
314
+ ],
315
+ children: gone ? "This session is gone" : approvalStateLabel(card.state)
316
+ }),
317
+ /* @__PURE__ */ jsx(Text, {
318
+ accessibilityRole: "header",
319
+ style: styles$2.title,
320
+ children: card.title
321
+ }),
322
+ card.summary ? /* @__PURE__ */ jsx(Text, {
323
+ style: styles$2.summary,
324
+ children: card.summary
325
+ }) : null,
326
+ card.details && card.details.length > 0 ? /* @__PURE__ */ jsx(View, {
327
+ style: styles$2.details,
328
+ children: card.details.map(({ label, value }) => /* @__PURE__ */ jsxs(View, { children: [/* @__PURE__ */ jsx(Text, {
329
+ style: styles$2.meta,
330
+ children: label
331
+ }), /* @__PURE__ */ jsx(Text, {
332
+ selectable: true,
333
+ style: styles$2.value,
334
+ children: value
335
+ })] }, label))
336
+ }) : null,
337
+ /* @__PURE__ */ jsx(Text, {
338
+ style: styles$2.meta,
339
+ children: note
340
+ }),
341
+ origin ? /* @__PURE__ */ jsx(Text, {
342
+ style: styles$2.meta,
343
+ children: origin
344
+ }) : null,
345
+ /* @__PURE__ */ jsx(View, {
346
+ style: styles$2.actions,
347
+ children: pending ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
348
+ variant: primary ? "primary" : "outline",
349
+ style: styles$2.action,
350
+ disabled: busy,
351
+ onPress: () => onDecide(card, "approve"),
352
+ children: "Approve"
353
+ }), /* @__PURE__ */ jsx(Button, {
354
+ variant: "ghost",
355
+ style: styles$2.action,
356
+ disabled: busy,
357
+ onPress: () => onDecide(card, "deny"),
358
+ children: "Deny"
359
+ })] }) : gone ? /* @__PURE__ */ jsx(Button, {
360
+ variant: "ghost",
361
+ style: styles$2.action,
362
+ disabled: busy,
363
+ onPress: () => onDismiss(card),
364
+ children: "Dismiss"
365
+ }) : null
366
+ }),
367
+ onOpenSession ? /* @__PURE__ */ jsx(View, {
368
+ style: styles$2.openRow,
369
+ children: /* @__PURE__ */ jsx(ListRow, {
370
+ leading: /* @__PURE__ */ jsx(ArrowRightIcon, {
371
+ size: 18,
372
+ color: "dim"
373
+ }),
374
+ title: "Open session",
375
+ onPress: onOpenSession,
376
+ disclosure: true,
377
+ accessibilityLabel: `Open the session for ${card.title}`
378
+ })
379
+ }) : null
380
+ ]
381
+ });
382
+ }
383
+ const styles$2 = StyleSheet.create((theme) => ({
384
+ section: {
385
+ gap: theme.spacing(2),
386
+ uni__dependencies: [0]
387
+ },
388
+ card: {
389
+ gap: theme.spacing(2),
390
+ padding: theme.spacing(3),
391
+ borderWidth: 1,
392
+ borderColor: theme.colors.border,
393
+ borderRadius: theme.borderRadius.md,
394
+ backgroundColor: theme.colors.panel,
395
+ uni__dependencies: [0]
396
+ },
397
+ decidedLabel: {
398
+ color: theme.colors.green,
399
+ uni__dependencies: [0]
400
+ },
401
+ uncertainLabel: {
402
+ color: theme.colors.dim,
403
+ uni__dependencies: [0]
404
+ },
405
+ label: {
406
+ fontFamily: fontOf(theme.fontFamily.sans),
407
+ fontSize: theme.fontSize.sm,
408
+ color: theme.colors.magenta,
409
+ fontWeight: theme.fontWeight.medium,
410
+ uni__dependencies: [0]
411
+ },
412
+ title: {
413
+ fontFamily: fontOf(theme.fontFamily.sans),
414
+ fontSize: theme.fontSize.base,
415
+ lineHeight: theme.lineHeight.base,
416
+ color: theme.colors.hi,
417
+ fontWeight: theme.fontWeight.semibold,
418
+ uni__dependencies: [0]
419
+ },
420
+ summary: {
421
+ fontFamily: fontOf(theme.fontFamily.sans),
422
+ fontSize: theme.fontSize.base,
423
+ lineHeight: theme.lineHeightRelaxed.base,
424
+ color: theme.colors.text,
425
+ uni__dependencies: [0]
426
+ },
427
+ details: {
428
+ gap: theme.spacing(2),
429
+ uni__dependencies: [0]
430
+ },
431
+ meta: {
432
+ fontFamily: fontOf(theme.fontFamily.sans),
433
+ fontSize: theme.fontSize.sm,
434
+ lineHeight: theme.lineHeightRelaxed.sm,
435
+ color: theme.colors.dim,
436
+ uni__dependencies: [0]
437
+ },
438
+ error: {
439
+ fontFamily: fontOf(theme.fontFamily.sans),
440
+ fontSize: theme.fontSize.sm,
441
+ lineHeight: theme.lineHeightRelaxed.sm,
442
+ color: theme.colors.red,
443
+ uni__dependencies: [0]
444
+ },
445
+ value: {
446
+ fontFamily: fontOf(theme.fontFamily.sans),
447
+ fontSize: theme.fontSize.sm,
448
+ lineHeight: theme.lineHeightRelaxed.sm,
449
+ color: theme.colors.hi,
450
+ uni__dependencies: [0]
451
+ },
452
+ actions: {
453
+ flexDirection: "row",
454
+ gap: theme.spacing(2),
455
+ uni__dependencies: [0]
456
+ },
457
+ action: {
458
+ minHeight: theme.spacing(11),
459
+ flex: 1,
460
+ uni__dependencies: [0]
461
+ },
462
+ openRow: {
463
+ borderTopWidth: 1,
464
+ borderTopColor: theme.colors.border,
465
+ marginHorizontal: -theme.spacing(3),
466
+ uni__dependencies: [0]
467
+ }
468
+ }));
469
+ //#endregion
470
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/_components/ApprovalActivityFill.native.tsx
471
+ const VOICE_HINT = "Or say “approve” or “deny”.";
472
+ const NO_SOURCES = () => () => void 0;
473
+ /** Whether any installed voice surface can take a spoken answer for this session right now. */
474
+ function useVoiceActive(sources, sessionId) {
475
+ const subscribe = sources.length === 0 ? NO_SOURCES : (listener) => {
476
+ const stops = sources.map((source) => source.subscribe(listener));
477
+ return () => {
478
+ for (const stop of stops) stop();
479
+ };
480
+ };
481
+ const read = () => sources.some((source) => source.isActive(sessionId));
482
+ return useSyncExternalStore(subscribe, read, read);
483
+ }
484
+ /** This session's own requests only; a gone session's cards are dismissed from Home. */
485
+ function ApprovalActivityFill({ sessionId, slotData }) {
486
+ const activity = useApprovalActivity(sessionId);
487
+ const voice = useVoiceActive(slotData(approvalVoiceHintSlot).map((fill) => fill.data), sessionId);
488
+ return /* @__PURE__ */ jsx(ApprovalActivitySection, {
489
+ approvals: activity.approvals,
490
+ busy: activity.busy,
491
+ error: activity.error ?? activity.snapshotError,
492
+ ...voice && !activity.approvals.some((card) => card.sessionGone === true) ? { voiceHint: VOICE_HINT } : {},
493
+ onDecide: (card, decision) => sessionId && card.sessionGone !== true && void answerApproval(sessionId, card.id, "decide", {
494
+ id: card.id,
495
+ revision: card.revision,
496
+ decision
497
+ }),
498
+ onDismiss: (card) => sessionId && void answerApproval(sessionId, card.id, "dismiss", {
499
+ id: card.id,
500
+ revision: card.revision
501
+ })
502
+ });
503
+ }
504
+ //#endregion
505
+ //#region src/extensions/(frontend)/fill/Approval.activity.approval.native.tsx
506
+ var Approval_activity_approval_native_default = defineFill({ component: ApprovalActivityFill });
507
+ //#endregion
508
+ //#region src/extensions/workspaces/sessions/(frontend)/_components/HomeApprovals.native.tsx
509
+ /** Home's section for every session's open approvals, above "Needs your eye"; nothing while nothing waits. */
510
+ function HomeApprovals({ approvals, onDecide, onDismiss, onOpenSession }) {
511
+ if (approvals.length === 0) return null;
512
+ const first = approvals.find(({ card }) => card.state === "pending" && card.sessionGone !== true);
513
+ const error = approvals.find((approval) => approval.error !== void 0)?.error;
514
+ return /* @__PURE__ */ jsxs(View, {
515
+ style: styles$1.section,
516
+ accessibilityLabel: "Your approval",
517
+ children: [
518
+ /* @__PURE__ */ jsx(SectionLabel, { children: "Your approval" }),
519
+ error ? /* @__PURE__ */ jsx(Text, {
520
+ accessibilityRole: "alert",
521
+ style: styles$1.error,
522
+ children: error
523
+ }) : null,
524
+ approvals.map((approval) => /* @__PURE__ */ jsx(ApprovalCard, {
525
+ card: approval.card,
526
+ primary: approval === first,
527
+ busy: approval.busy,
528
+ origin: approvalOrigin(approval.card),
529
+ ...onOpenSession && approval.card.sessionGone !== true ? { onOpenSession: () => onOpenSession(approval.sessionId) } : {},
530
+ onDecide: (_, decision) => onDecide(approval, decision),
531
+ onDismiss: () => onDismiss(approval)
532
+ }, `${approval.sessionId}:${approval.card.id}`))
533
+ ]
534
+ });
535
+ }
536
+ const styles$1 = StyleSheet.create((theme) => ({
537
+ section: {
538
+ gap: theme.spacing(2),
539
+ uni__dependencies: [0]
540
+ },
541
+ error: {
542
+ fontFamily: fontOf(theme.fontFamily.sans),
543
+ fontSize: theme.fontSize.sm,
544
+ lineHeight: theme.lineHeightRelaxed.sm,
545
+ color: theme.colors.red,
546
+ uni__dependencies: [0]
547
+ }
548
+ }));
549
+ //#endregion
550
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/_components/HomeApprovalsFill.native.tsx
551
+ /** Every session's open approvals on Home; each answer goes to the session that asked. */
552
+ function HomeApprovalsFill({ openSession }) {
553
+ return /* @__PURE__ */ jsx(HomeApprovals, {
554
+ approvals: useHomeApprovals(),
555
+ onDecide: ({ sessionId, card }, decision) => void answerApproval(sessionId, card.id, "decide", {
556
+ id: card.id,
557
+ revision: card.revision,
558
+ decision
559
+ }),
560
+ onDismiss: ({ sessionId, card }) => void answerApproval(sessionId, card.id, "dismiss", {
561
+ id: card.id,
562
+ revision: card.revision
563
+ }),
564
+ ...openSession ? { onOpenSession: openSession } : {}
565
+ });
566
+ }
567
+ //#endregion
568
+ //#region src/extensions/(frontend)/fill/Approval.home-attention.native.tsx
569
+ var Approval_home_attention_native_default = defineFill({ component: HomeApprovalsFill });
570
+ //#endregion
571
+ //#region src/extensions/(frontend)/lifecycle/start.native.ts
572
+ var start_native_default = defineWebLifecycle(startApprovalRuntime);
573
+ //#endregion
574
+ //#region src/extensions/workspaces/sessions/(frontend)/channel/approval-activity.native.ts
575
+ var approval_activity_native_default = defineChannelFile(approvalActivityChannel);
576
+ //#endregion
577
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/approvalWithdrawView.ts
578
+ /** What the approval_withdraw card shows, read from its arguments and result details. */
579
+ function approvalWithdrawView(args, result, output) {
580
+ const approvalId = typeof args.id === "string" ? args.id : "";
581
+ const details = typeof result?.details === "object" && result.details !== null ? result.details : {};
582
+ return {
583
+ approvalId,
584
+ outcome: typeof details.withdrawn === "boolean" ? details.withdrawn ? "withdrawn" : "not pending" : void 0,
585
+ message: result === null ? output : result.content.flatMap((block) => {
586
+ const record = typeof block === "object" && block !== null ? block : {};
587
+ return record.type === "text" && typeof record.text === "string" ? [record.text] : [];
588
+ }).join("\n")
589
+ };
590
+ }
591
+ //#endregion
592
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/ApprovalWithdrawToolMessage.native.tsx
593
+ /** The approval_withdraw tool's timeline item on native, as the web's: id and outcome, then the tool's sentence. */
594
+ function ApprovalWithdrawToolMessage({ args, result, output, running, isError }) {
595
+ const view = approvalWithdrawView(args, result, output);
596
+ return /* @__PURE__ */ jsx(MessageItem, {
597
+ tone: toolTone({
598
+ running,
599
+ isError
600
+ }),
601
+ expandable: true,
602
+ children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
603
+ title: "approval_withdraw",
604
+ children: /* @__PURE__ */ jsxs(View, {
605
+ testID: "tool-call-approval_withdraw",
606
+ style: styles.summary,
607
+ children: [/* @__PURE__ */ jsx(Text, {
608
+ numberOfLines: 1,
609
+ ellipsizeMode: "middle",
610
+ style: styles.id,
611
+ children: view.approvalId
612
+ }), view.outcome !== void 0 ? /* @__PURE__ */ jsxs(Text, {
613
+ numberOfLines: 1,
614
+ style: [styles.sans, styles.detail],
615
+ children: ["· ", view.outcome]
616
+ }) : null]
617
+ })
618
+ }), !expanded ? null : isError ? /* @__PURE__ */ jsx(MessageItemBody, {
619
+ testID: "tool-result-approval_withdraw",
620
+ children: /* @__PURE__ */ jsx(Text, {
621
+ selectable: true,
622
+ style: [styles.sans, styles.error],
623
+ children: view.message
624
+ })
625
+ }) : result === null ? running ? /* @__PURE__ */ jsx(MessageItemBody, {
626
+ testID: "tool-result-approval_withdraw",
627
+ children: /* @__PURE__ */ jsx(MessageItemStatus, {
628
+ tone: "running",
629
+ children: "running"
630
+ })
631
+ }) : null : view.message.length === 0 ? null : /* @__PURE__ */ jsx(MessageItemBody, {
632
+ testID: "tool-result-approval_withdraw",
633
+ children: /* @__PURE__ */ jsx(Text, {
634
+ selectable: true,
635
+ style: [styles.sans, styles.message],
636
+ children: view.message
637
+ })
638
+ })] })
639
+ });
640
+ }
641
+ const styles = StyleSheet.create((theme) => ({
642
+ summary: {
643
+ flex: 1,
644
+ flexDirection: "row",
645
+ flexWrap: "wrap",
646
+ alignItems: "center",
647
+ columnGap: theme.spacing(2),
648
+ minWidth: 0,
649
+ uni__dependencies: [0]
650
+ },
651
+ sans: {
652
+ fontFamily: fontOf(theme.fontFamily.sans),
653
+ fontSize: theme.fontSize.base,
654
+ lineHeight: theme.lineHeight.base,
655
+ uni__dependencies: [0]
656
+ },
657
+ id: {
658
+ flexShrink: 1,
659
+ maxWidth: "100%",
660
+ fontFamily: fontOf(theme.fontFamily.mono),
661
+ fontSize: theme.fontSize.sm,
662
+ color: theme.colors.text,
663
+ uni__dependencies: [0]
664
+ },
665
+ detail: {
666
+ flexShrink: 0,
667
+ color: theme.colors.faint,
668
+ uni__dependencies: [0]
669
+ },
670
+ message: {
671
+ color: theme.colors.text,
672
+ uni__dependencies: [0]
673
+ },
674
+ error: {
675
+ color: theme.colors.red,
676
+ uni__dependencies: [0]
677
+ }
678
+ }));
679
+ //#endregion
680
+ //#region src/extensions/workspaces/sessions/(frontend)/tool/approval-withdraw.native.tsx
681
+ var approval_withdraw_native_default = defineToolRenderer({ message: ApprovalWithdrawToolMessage });
682
+ //#endregion
683
+ //#region generated/native.ts
684
+ const via = (identity, value) => value === void 0 ? void 0 : {
685
+ ...identity,
686
+ ...value
687
+ };
688
+ const nativePlugin = defineNativePlugin({
689
+ id: "approval",
690
+ global: {
691
+ get activityGroups() {
692
+ return [via({ name: "approval" }, approval_native_default)];
693
+ },
694
+ get fills() {
695
+ return [via({
696
+ slot: "activity.approval",
697
+ id: "approval"
698
+ }, Approval_activity_approval_native_default), via({
699
+ slot: "home-attention",
700
+ id: "approval"
701
+ }, Approval_home_attention_native_default)];
702
+ },
703
+ get start() {
704
+ return start_native_default;
705
+ }
706
+ },
707
+ session: {
708
+ get channels() {
709
+ return [via({ channel: "approval_activity" }, approval_activity_native_default)];
710
+ },
711
+ get toolRenderers() {
712
+ return [via({ tools: ["approval_withdraw"] }, approval_withdraw_native_default)];
713
+ }
714
+ }
715
+ });
716
+ //#endregion
717
+ export { nativePlugin };
718
+
719
+ //# sourceMappingURL=native.mjs.map