@arbidocs/blocks 0.4.72 → 0.4.74
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.
- package/dist/agents/index.cjs +401 -262
- package/dist/agents/index.js +7 -4
- package/dist/agents/tasks/TaskActivityTimeline.d.ts +1 -1
- package/dist/agents/tasks/WorkflowThreadStrip.d.ts +58 -0
- package/dist/agents/tasks/index.d.ts +1 -0
- package/dist/agents/workflows/WorkflowRunner.d.ts +86 -0
- package/dist/agents/workflows/WorkflowStepBar.d.ts +23 -0
- package/dist/agents/workflows/index.d.ts +7 -1
- package/dist/agents/workflows/planSteps.d.ts +28 -0
- package/dist/agents/workflows/run.d.ts +98 -0
- package/dist/agents/workflows/skillMarkdown.d.ts +15 -0
- package/dist/agents/workflows/types.d.ts +111 -0
- package/dist/agents/workflows/useWorkflowPreview.d.ts +14 -0
- package/dist/agents/workflows/useWorkflowView.d.ts +54 -0
- package/dist/agents/workflows/workflow.d.ts +3 -1
- package/dist/chat/index.cjs +124 -124
- package/dist/chat/index.js +3 -3
- package/dist/{chunk-DH7C2UJO.cjs → chunk-5LP54CWR.cjs} +299 -526
- package/dist/chunk-5LP54CWR.cjs.map +1 -0
- package/dist/{chunk-3SFFTSOI.cjs → chunk-7CVF3DK2.cjs} +5 -5
- package/dist/{chunk-3SFFTSOI.cjs.map → chunk-7CVF3DK2.cjs.map} +1 -1
- package/dist/chunk-7D737FLE.cjs +43 -0
- package/dist/chunk-7D737FLE.cjs.map +1 -0
- package/dist/{chunk-V3L5DONY.cjs → chunk-B4SRYJLM.cjs} +31 -2
- package/dist/chunk-B4SRYJLM.cjs.map +1 -0
- package/dist/{chunk-LFGJAZ5H.js → chunk-DDF5GPIJ.js} +6 -36
- package/dist/chunk-DDF5GPIJ.js.map +1 -0
- package/dist/chunk-DETZZBG2.cjs +91 -0
- package/dist/chunk-DETZZBG2.cjs.map +1 -0
- package/dist/chunk-EVUEIBNU.js +89 -0
- package/dist/chunk-EVUEIBNU.js.map +1 -0
- package/dist/{chunk-G5QTGKDJ.cjs → chunk-HITAN7JF.cjs} +8 -8
- package/dist/{chunk-G5QTGKDJ.cjs.map → chunk-HITAN7JF.cjs.map} +1 -1
- package/dist/{chunk-3VQYJBOI.js → chunk-HOXKR26S.js} +31 -4
- package/dist/chunk-HOXKR26S.js.map +1 -0
- package/dist/{chunk-KJ3QEKOJ.cjs → chunk-IPGKTUF7.cjs} +7 -33
- package/dist/chunk-IPGKTUF7.cjs.map +1 -0
- package/dist/{chunk-IMC2Z32C.js → chunk-KOSGX3UK.js} +269 -485
- package/dist/chunk-KOSGX3UK.js.map +1 -0
- package/dist/{chunk-KOXUBCLL.js → chunk-MK6NJQGF.js} +4 -4
- package/dist/{chunk-KOXUBCLL.js.map → chunk-MK6NJQGF.js.map} +1 -1
- package/dist/{chunk-THO7DZNN.cjs → chunk-MUMH3Z6K.cjs} +20 -15
- package/dist/chunk-MUMH3Z6K.cjs.map +1 -0
- package/dist/{chunk-5HOAOKZL.js → chunk-OYMWV45N.js} +21 -16
- package/dist/chunk-OYMWV45N.js.map +1 -0
- package/dist/chunk-P2RBE3FD.cjs +1448 -0
- package/dist/chunk-P2RBE3FD.cjs.map +1 -0
- package/dist/{chunk-G5DP27DU.js → chunk-UIWLDSTF.js} +3 -29
- package/dist/chunk-UIWLDSTF.js.map +1 -0
- package/dist/{chunk-VRPRAU3J.js → chunk-WJEKRSPH.js} +3 -3
- package/dist/{chunk-VRPRAU3J.js.map → chunk-WJEKRSPH.js.map} +1 -1
- package/dist/chunk-XD2M6LIG.js +41 -0
- package/dist/chunk-XD2M6LIG.js.map +1 -0
- package/dist/chunk-YWYVIQ7T.js +1402 -0
- package/dist/chunk-YWYVIQ7T.js.map +1 -0
- package/dist/{chunk-WBDK4PIA.cjs → chunk-Z5VUZ6YD.cjs} +6 -37
- package/dist/chunk-Z5VUZ6YD.cjs.map +1 -0
- package/dist/connect/docx.cjs +2 -2
- package/dist/connect/docx.js +1 -1
- package/dist/connect/index.cjs +379 -27
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.d.ts +1 -0
- package/dist/connect/index.js +362 -11
- package/dist/connect/index.js.map +1 -1
- package/dist/connection/ConnectedWorkflowBuilder.d.ts +44 -0
- package/dist/connection/ConnectedWorkflowRunner.d.ts +31 -0
- package/dist/connection/useWorkflowThread.d.ts +38 -0
- package/dist/facts/index.cjs +1 -1
- package/dist/facts/index.js +1 -1
- package/dist/files/index.cjs +9 -83
- package/dist/files/index.cjs.map +1 -1
- package/dist/files/index.js +6 -83
- package/dist/files/index.js.map +1 -1
- package/dist/home/index.cjs +22 -21
- package/dist/home/index.cjs.map +1 -1
- package/dist/home/index.js +4 -3
- package/dist/home/index.js.map +1 -1
- package/dist/index.cjs +579 -440
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/shell/index.cjs +1 -1
- package/dist/shell/index.js +1 -1
- package/dist/studio/index.cjs +7 -7
- package/dist/studio/index.js +5 -5
- package/dist/workflow-canvas/StepInspector.d.ts +57 -0
- package/dist/workflow-canvas/TriggerInspector.d.ts +46 -0
- package/dist/workflow-canvas/WorkflowBuilder.d.ts +55 -0
- package/dist/workflow-canvas/WorkflowCanvas.d.ts +69 -0
- package/dist/workflow-canvas/edit.d.ts +54 -0
- package/dist/workflow-canvas/index.cjs +1719 -0
- package/dist/workflow-canvas/index.cjs.map +1 -0
- package/dist/workflow-canvas/index.d.ts +13 -0
- package/dist/workflow-canvas/index.js +1689 -0
- package/dist/workflow-canvas/index.js.map +1 -0
- package/dist/workflow-canvas/trigger.d.ts +51 -0
- package/dist/workflow-canvas/viewport.d.ts +47 -0
- package/package.json +25 -14
- package/src/workflow-canvas/canvas.css +113 -0
- package/dist/chunk-3VQYJBOI.js.map +0 -1
- package/dist/chunk-5HOAOKZL.js.map +0 -1
- package/dist/chunk-DH7C2UJO.cjs.map +0 -1
- package/dist/chunk-G5DP27DU.js.map +0 -1
- package/dist/chunk-IMC2Z32C.js.map +0 -1
- package/dist/chunk-KJ3QEKOJ.cjs.map +0 -1
- package/dist/chunk-LFGJAZ5H.js.map +0 -1
- package/dist/chunk-THO7DZNN.cjs.map +0 -1
- package/dist/chunk-V3L5DONY.cjs.map +0 -1
- package/dist/chunk-WBDK4PIA.cjs.map +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @arbidocs/blocks/workflow-canvas.css: the workflow builder's canvas. Import it once, next to
|
|
3
|
+
* `blocks.css`, where `@arbidocs/blocks/workflow-canvas` is used. The graph library's structural
|
|
4
|
+
* rules, its surfaces on the theme tokens, and one accent per kind of step (override the
|
|
5
|
+
* `--wf-*` variables to retheme them).
|
|
6
|
+
*/
|
|
7
|
+
@import '@xyflow/react/dist/base.css';
|
|
8
|
+
|
|
9
|
+
:root {
|
|
10
|
+
--wf-start: 262 83% 58%;
|
|
11
|
+
--wf-form: 217 91% 55%;
|
|
12
|
+
--wf-upload: 173 70% 38%;
|
|
13
|
+
--wf-agent: 280 70% 56%;
|
|
14
|
+
--wf-review: 32 95% 48%;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.dark {
|
|
18
|
+
--wf-start: 262 85% 72%;
|
|
19
|
+
--wf-form: 217 91% 68%;
|
|
20
|
+
--wf-upload: 173 60% 52%;
|
|
21
|
+
--wf-agent: 280 75% 72%;
|
|
22
|
+
--wf-review: 32 95% 62%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.react-flow {
|
|
26
|
+
--xy-edge-stroke-default: hsl(var(--muted-foreground) / 0.45);
|
|
27
|
+
--xy-edge-stroke-width-default: 1.5;
|
|
28
|
+
--xy-edge-stroke-selected-default: hsl(var(--primary));
|
|
29
|
+
--xy-connectionline-stroke-default: hsl(var(--primary));
|
|
30
|
+
--xy-background-pattern-dots-color-default: hsl(var(--muted-foreground) / 0.25);
|
|
31
|
+
--xy-controls-button-background-color-default: hsl(var(--card));
|
|
32
|
+
--xy-controls-button-background-color-hover-default: hsl(var(--muted));
|
|
33
|
+
--xy-controls-button-color-default: hsl(var(--foreground));
|
|
34
|
+
--xy-controls-button-border-color-default: hsl(var(--border));
|
|
35
|
+
--xy-minimap-background-color-default: hsl(var(--card));
|
|
36
|
+
--xy-minimap-mask-background-color-default: hsl(var(--muted) / 0.6);
|
|
37
|
+
--xy-minimap-node-background-color-default: hsl(var(--muted-foreground) / 0.35);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* A step's accent: its kind's colour. */
|
|
41
|
+
.wf-kind-start { --wf-accent: var(--wf-start); }
|
|
42
|
+
.wf-kind-form { --wf-accent: var(--wf-form); }
|
|
43
|
+
.wf-kind-upload { --wf-accent: var(--wf-upload); }
|
|
44
|
+
.wf-kind-agent { --wf-accent: var(--wf-agent); }
|
|
45
|
+
.wf-kind-review { --wf-accent: var(--wf-review); }
|
|
46
|
+
|
|
47
|
+
.wf-node {
|
|
48
|
+
position: relative;
|
|
49
|
+
border-radius: 0.75rem;
|
|
50
|
+
border: 1px solid hsl(var(--border));
|
|
51
|
+
background: hsl(var(--card));
|
|
52
|
+
box-shadow: 0 1px 2px hsl(var(--foreground) / 0.06), 0 4px 12px -4px hsl(var(--foreground) / 0.08);
|
|
53
|
+
transition: box-shadow 150ms, border-color 150ms, transform 150ms;
|
|
54
|
+
overflow: visible;
|
|
55
|
+
}
|
|
56
|
+
.wf-node::before {
|
|
57
|
+
content: '';
|
|
58
|
+
position: absolute;
|
|
59
|
+
inset: 0 auto 0 0;
|
|
60
|
+
width: 4px;
|
|
61
|
+
border-radius: 0.75rem 0 0 0.75rem;
|
|
62
|
+
background: hsl(var(--wf-accent));
|
|
63
|
+
}
|
|
64
|
+
.wf-node:hover {
|
|
65
|
+
box-shadow: 0 2px 4px hsl(var(--foreground) / 0.06), 0 10px 24px -8px hsl(var(--foreground) / 0.18);
|
|
66
|
+
}
|
|
67
|
+
.react-flow__node.selected .wf-node {
|
|
68
|
+
border-color: hsl(var(--wf-accent));
|
|
69
|
+
box-shadow: 0 0 0 3px hsl(var(--wf-accent) / 0.22), 0 10px 24px -8px hsl(var(--foreground) / 0.18);
|
|
70
|
+
}
|
|
71
|
+
.wf-badge {
|
|
72
|
+
color: hsl(var(--wf-accent));
|
|
73
|
+
background: hsl(var(--wf-accent) / 0.12);
|
|
74
|
+
}
|
|
75
|
+
.wf-kind-text { color: hsl(var(--wf-accent)); }
|
|
76
|
+
|
|
77
|
+
/* The start: a pill in its own colour. */
|
|
78
|
+
.wf-start {
|
|
79
|
+
border-radius: 9999px;
|
|
80
|
+
border: 1px solid hsl(var(--wf-start) / 0.5);
|
|
81
|
+
background: linear-gradient(135deg, hsl(var(--wf-start) / 0.16), hsl(var(--wf-start) / 0.06));
|
|
82
|
+
}
|
|
83
|
+
.react-flow__node.selected .wf-start {
|
|
84
|
+
box-shadow: 0 0 0 3px hsl(var(--wf-start) / 0.25);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* Handles: small, on the accent; the "+" sits beside the outgoing one. */
|
|
88
|
+
.wf-node .react-flow__handle,
|
|
89
|
+
.wf-start .react-flow__handle {
|
|
90
|
+
width: 10px;
|
|
91
|
+
height: 10px;
|
|
92
|
+
border: 2px solid hsl(var(--card));
|
|
93
|
+
background: hsl(var(--wf-accent));
|
|
94
|
+
}
|
|
95
|
+
.wf-add {
|
|
96
|
+
position: absolute;
|
|
97
|
+
top: 50%;
|
|
98
|
+
right: -38px;
|
|
99
|
+
transform: translateY(-50%);
|
|
100
|
+
opacity: 0;
|
|
101
|
+
transition: opacity 120ms;
|
|
102
|
+
}
|
|
103
|
+
.react-flow__node:hover .wf-add,
|
|
104
|
+
.react-flow__node.selected .wf-add,
|
|
105
|
+
.wf-add[data-state='open'] {
|
|
106
|
+
opacity: 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.wf-phase-running { border-color: hsl(var(--wf-accent)); }
|
|
110
|
+
.wf-phase-done { background: linear-gradient(0deg, hsl(var(--wf-accent) / 0.06), hsl(var(--wf-accent) / 0.06)), hsl(var(--card)); }
|
|
111
|
+
.wf-phase-failed { border-color: hsl(var(--destructive) / 0.6); }
|
|
112
|
+
.wf-phase-skipped,
|
|
113
|
+
.wf-phase-blocked { opacity: 0.6; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/chat/useMentionAutocomplete.ts"],"names":[],"mappings":";;;AA6CO,SAAS,sBAAA,CAAuB;AAAA,EACrC,KAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,EAA0D;AACxD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAwB,IAAI,CAAA;AAEtD,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAwB,IAAI,CAAA;AAIlE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,gBAAgB,IAAA,IAAQ,KAAA,CAAM,WAAW,CAAA,KAAM,GAAA,iBAAoB,IAAI,CAAA;AAAA,EAC7E,CAAA,EAAG,CAAC,KAAA,EAAO,WAAW,CAAC,CAAA;AAEvB,EAAA,MAAM,KAAA,GAAQ,QAAQ,MAAM;AAC1B,IAAA,IAAI,KAAA,KAAU,MAAM,OAAO,IAAA;AAC3B,IAAA,MAAM,KAAA,GAAQ,iBAAiB,KAAA,EAAO,IAAA,CAAK,IAAI,KAAA,EAAO,KAAA,CAAM,MAAM,CAAC,CAAA;AAEnE,IAAA,OAAO,KAAA,IAAS,UAAA,CAAW,IAAA,CAAK,CAAC,SAAA,KAAc,KAAA,CAAM,KAAA,KAAU,CAAA,EAAG,SAAA,CAAU,KAAK,CAAA,CAAA,CAAG,CAAA,GAChF,IAAA,GACA,KAAA;AAAA,EACN,CAAA,EAAG,CAAC,KAAA,EAAO,KAAA,EAAO,UAAU,CAAC,CAAA;AAC7B,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,MAAO,KAAA,GAAQ,uBAAA,CAAwB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AM,MAAA;AAAA,IACN,KAAA;AAAA,IACA,MAAA,EAAQ,IAAA;AAAA,IACR,SAAA,EAAW,MAAM,cAAA,CAAe,KAAA,EAAO,SAAS,IAAI,CAAA;AAAA,IACpD,UAAU,KAAA,EAAO;AAAA,GAClB,CAAA;AAED,EAAA,MAAM,iBAAA,GAAoB,WAAA;AAAA,IACxB,CAAC,IAAA,KAAiB;AAChB,MAAA,aAAA,CAAc,IAAI,CAAA;AAClB,MAAA,MAAM,KAAK,WAAA,CAAY,OAAA;AACvB,MAAA,QAAA,CAAS,EAAA,GAAK,EAAA,CAAG,cAAA,GAAiB,IAAA,CAAK,MAAM,CAAA;AAE7C,MAAA,IAAI,WAAA,KAAgB,SAAS,IAAA,CAAK,MAAA,GAAS,MAAM,MAAA,IAAU,IAAA,CAAK,WAAW,CAAA,KAAM,GAAA,CAAA,EAAM;AACrF,QAAA,cAAA,CAAe,IAAI,CAAA;AAAA,MACrB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,aAAA,EAAe,WAAA,EAAa,WAAA,EAAa,KAAK;AAAA,GACjD;AAEA,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,KAAA;AAAA,IACA,GAAA;AAAA,IACA,IAAA;AAAA,IACA,aAAA,EAAe,iBAAA;AAAA,IACf,aAAA,EAAe,EAAE,QAAA,EAAU,SAAA;AAAU,GACvC;AACF","file":"chunk-3VQYJBOI.js","sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useState,\n type RefObject,\n type SyntheticEvent,\n} from 'react'\nimport { useListKeyNav, type UseListKeyNav } from '../lib/useListKeyNav'\nimport {\n filterMentionCandidates,\n findMentionQuery,\n insertMention,\n type MentionCandidate,\n} from './mentions'\n\nexport interface UseMentionAutocompleteOptions {\n /** The draft. */\n value: string\n /** Writes the draft (the same setter the composer uses). */\n onValueChange: (next: string) => void\n /** Who can be mentioned: workspace members and the assistant. */\n candidates: ReadonlyArray<MentionCandidate>\n /** The composer textarea; read for the caret and refocused after a pick. */\n textareaRef: RefObject<HTMLTextAreaElement | null>\n}\n\nexport interface UseMentionAutocomplete {\n isOpen: boolean\n /** Filtered candidates for the `@query` at the caret. */\n items: MentionCandidate[]\n /** Keyboard navigation; call `nav.handleKeyDown` first in the textarea's `onKeyDown`. */\n nav: UseListKeyNav\n /** Insert a candidate in place of the `@query`. */\n pick: (candidate: MentionCandidate) => void\n /** Wrap the composer's `onValueChange` with this so the caret is tracked as the user types. */\n onValueChange: (next: string) => void\n /** Spread onto the textarea (via `textareaProps`): tracks caret moves (clicks, arrows). */\n textareaProps: { onSelect: (event: SyntheticEvent<HTMLTextAreaElement>) => void }\n}\n\n/**\n * Headless `@mention` autocomplete for a textarea: finds the `@query` at the caret, filters the\n * candidates, and on pick replaces the query with `@<label> `. Pair with {@link MentionMenu}.\n */\nexport function useMentionAutocomplete({\n value,\n onValueChange,\n candidates,\n textareaRef,\n}: UseMentionAutocompleteOptions): UseMentionAutocomplete {\n const [caret, setCaret] = useState<number | null>(null)\n // Escape dismisses the menu for the `@` it was opened at, until the user starts another one.\n const [dismissedAt, setDismissedAt] = useState<number | null>(null)\n\n // The draft can change from outside (cleared on send, restored on error): once the dismissed\n // `@` is gone, re-arm so the next `@` there opens the menu again.\n useEffect(() => {\n if (dismissedAt !== null && value[dismissedAt] !== '@') setDismissedAt(null)\n }, [value, dismissedAt])\n\n const match = useMemo(() => {\n if (caret === null) return null\n const query = findMentionQuery(value, Math.min(caret, value.length))\n // A completed recipient followed by a space is no longer an autocomplete query.\n return query && candidates.some((candidate) => query.query === `${candidate.label} `)\n ? null\n : query\n }, [value, caret, candidates])\n const items = useMemo(\n () => (match ? filterMentionCandidates(candidates, match.query) : []),\n [match, candidates]\n )\n const isOpen = !!match && items.length > 0 && dismissedAt !== match.start\n\n const readCaret = useCallback(() => {\n const ta = textareaRef.current\n setCaret(ta ? ta.selectionStart : null)\n }, [textareaRef])\n\n const pick = useCallback(\n (candidate: MentionCandidate) => {\n if (!match || caret === null) return\n const next = insertMention(value, match.start, Math.min(caret, value.length), candidate.label)\n onValueChange(next.text)\n setCaret(next.caret)\n // The inserted `@<label> ` is complete: keep the menu shut for this `@`.\n setDismissedAt(match.start)\n requestAnimationFrame(() => {\n const ta = textareaRef.current\n if (!ta) return\n ta.focus()\n ta.setSelectionRange(next.caret, next.caret)\n })\n },\n [match, caret, value, onValueChange, textareaRef]\n )\n\n const nav = useListKeyNav({\n open: isOpen,\n items,\n onPick: pick,\n onDismiss: () => setDismissedAt(match?.start ?? null),\n resetKey: match?.query,\n })\n\n const handleValueChange = useCallback(\n (next: string) => {\n onValueChange(next)\n const ta = textareaRef.current\n setCaret(ta ? ta.selectionStart : next.length)\n // Deleting text (or the `@` itself) re-arms the menu: the user is editing that mention.\n if (dismissedAt !== null && (next.length < value.length || next[dismissedAt] !== '@')) {\n setDismissedAt(null)\n }\n },\n [onValueChange, textareaRef, dismissedAt, value]\n )\n\n return {\n isOpen,\n items,\n nav,\n pick,\n onValueChange: handleValueChange,\n textareaProps: { onSelect: readCaret },\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/connection/ConnectionProvider.tsx"],"names":[],"mappings":";;;;;AA0DA,IAAM,iBAAA,GAAoB,cAAsC,IAAI,CAAA;AAQpE,IAAM,wBAAA,GAA2B,wBAAA;AACjC,IAAM,cAAA,GAAiB,CAAC,MAAA,KAAmB,CAAA,iBAAA,EAAoB,MAAM,CAAA,CAAA;AACrE,SAAS,mBAAA,CAAoB,QAAgB,KAAA,EAAsB;AACjE,EAAA,IAAI;AACF,IAAA,IAAI,KAAA,SAAc,YAAA,CAAa,OAAA,CAAQ,eAAe,MAAM,CAAA,EAAG,gBAAA,CAAiB,KAAK,CAAC,CAAA;AAAA,SACjF,MAAA,CAAO,YAAA,CAAa,UAAA,CAAW,cAAA,CAAe,MAAM,CAAC,CAAA;AAAA,EAC5D,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;AACA,IAAM,mBAAmB,CAAC,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AA,MACA,gBAAA;AAAA,MACA,MAAA,CAAO,MAAA;AAAA,MACP,IAAA;AAAA,MACA,MAAA,CAAO,eAAA;AAAA,MACP,MAAA,CAAO,WAAA;AAAA,MACP,KAAA;AAAA,MACA,KAAA;AAAA,MACA,SAAA;AAAA,MACA,MAAA;AAAA,MACA,YAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAA,uBAAO,GAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,OAAe,QAAA,EAAS,CAAA;AAC7D;AAEO,SAAS,aAAA,GAAiC;AAC/C,EAAA,MAAM,GAAA,GAAM,WAAW,iBAAiB,CAAA;AACxC,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAChF,EAAA,OAAO,GAAA;AACT;AAEO,IAAM,eAAA,GAAkB,CAAC,CAAA,KAAwB,CAAA,KAAM,UAAU,CAAA,KAAM","file":"chunk-5HOAOKZL.js","sourcesContent":["/**\n * The demo/live connection layer for a host app. Holds auth + workspace\n * selection state and exposes it via {@link useConnection}, so every surface\n * works identically whether it's talking to a live ARBI backend or the seeded\n * demo workspace. Host-specific values (backend URL, demo identity, default\n * workspace/assistant ids) arrive once through {@link ArbiConnectionConfig}.\n */\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from 'react'\nimport { useArbi, type LoginProfile } from '@arbidocs/react'\nimport type { ArbiMode, ArbiUser, ConnectionStatus, ArbiConnectionConfig } from './types'\n\ninterface ConnectionValue {\n mode: ArbiMode\n status: ConnectionStatus\n user: ArbiUser | null\n workspaceId: string | null\n apiConfigured: boolean\n apiUrl: string\n /**\n * The deployment domain the user's keys are derived for (`arbi.getDeploymentDomain()`), for the\n * document tools' e-signing. `undefined` in demo mode.\n */\n deploymentDomain: string | undefined\n error: string | null\n /** Default assistant config ext_id (for the AI hooks). */\n assistantConfig?: string\n /** Fallback workspace ext_id when none is actively selected. */\n fallbackWorkspaceId?: string\n /** Authenticate. Live login when a backend is configured, otherwise the demo workspace. */\n login: (email: string, password: string) => Promise<void>\n /** One-click demo entry (no backend required). */\n enterDemo: () => void\n logout: () => void\n /**\n * Affirmatively select a workspace: opens it on the server (via the SDK),\n * updates the app-wide state, and persists the choice so it survives future\n * logins. This is the single entry point for \"the user is now in workspace X\".\n */\n setWorkspace: (id: string) => Promise<void>\n /**\n * Re-assert the selected workspace on the server session (idempotent `/open`).\n * Call before a workspace-scoped write when the session may have lost its open\n * workspace (token re-login, backend restart, session expiry) — the server\n * resolves the workspace from the session, so a dropped `/open` yields\n * \"No active workspace\" until it's re-opened.\n */\n ensureWorkspaceOpen: () => Promise<void>\n}\n\nconst ConnectionContext = createContext<ConnectionValue | null>(null)\n\n/**\n * Persist the affirmatively-selected workspace per backend AND per signed-in user, so a returning\n * user lands back in the workspace they last chose, while the next person on a shared browser\n * never starts from someone else's workspace id. Namespaced by apiUrl so distinct deployments\n * (and the demo workspace) don't clobber each other. Cleared on logout.\n */\nconst WORKSPACE_STORAGE_PREFIX = 'arbi:selectedWorkspace'\nconst sessionUserKey = (apiUrl: string) => `arbi:sessionUser:${apiUrl}`\nfunction rememberSessionUser(apiUrl: string, email: string | null) {\n try {\n if (email) window.localStorage.setItem(sessionUserKey(apiUrl), normalizeUserKey(email))\n else window.localStorage.removeItem(sessionUserKey(apiUrl))\n } catch {\n /* Storage may be unavailable. */\n }\n}\nconst normalizeUserKey = (email: string) => email.trim().toLowerCase()\n\n/** Exported for tests. */\nexport const workspaceStorageKey = (apiUrl: string, userKey: string) =>\n `${WORKSPACE_STORAGE_PREFIX}:${apiUrl || 'demo'}:${normalizeUserKey(userKey)}`\n\n/** The pre-isolation key (apiUrl only). Never read: removed so it cannot leak across users. */\nconst legacyWorkspaceStorageKey = (apiUrl: string) =>\n `${WORKSPACE_STORAGE_PREFIX}:${apiUrl || 'demo'}`\n\nfunction readPersistedWorkspace(apiUrl: string, userKey: string | null): string | null {\n if (!userKey) return null\n try {\n return window.localStorage.getItem(workspaceStorageKey(apiUrl, userKey))\n } catch {\n return null\n }\n}\n\nfunction persistWorkspace(apiUrl: string, userKey: string | null, id: string | null): void {\n if (!userKey) return\n try {\n if (id) window.localStorage.setItem(workspaceStorageKey(apiUrl, userKey), id)\n else window.localStorage.removeItem(workspaceStorageKey(apiUrl, userKey))\n window.localStorage.removeItem(legacyWorkspaceStorageKey(apiUrl))\n } catch {\n // Storage unavailable (private mode, SSR) — selection stays in-memory only.\n }\n}\n\n/** Shown on the sign-in screen after the session could not be recovered. */\nexport const SESSION_EXPIRED_MESSAGE = 'Your session expired. Sign in again.'\n\n/** The connection user for a profile: its full name, falling back to the email local part. */\nfunction userFromProfile(profile: LoginProfile, externalId?: string): ArbiUser {\n const fullName = [profile.givenName, profile.familyName]\n .map((part) => part?.trim())\n .filter(Boolean)\n .join(' ')\n return {\n name: fullName || profile.email.split('@')[0],\n email: profile.email,\n externalId,\n picture: profile.picture,\n }\n}\n\nexport function ConnectionProvider({\n config,\n children,\n}: {\n config: ArbiConnectionConfig\n children: ReactNode\n}) {\n const arbi = useArbi()\n const isLiveConfigured = config.apiUrl.length > 0\n const demoWorkspaceId = config.demoWorkspaceId ?? 'demo-workspace'\n\n const [status, setStatus] = useState<ConnectionStatus>(\n isLiveConfigured ? 'connecting' : 'disconnected'\n )\n const [user, setUser] = useState<ArbiUser | null>(null)\n const [workspaceId, setWorkspaceId] = useState<string | null>(null)\n const [mode, setMode] = useState<ArbiMode>('demo')\n const [error, setError] = useState<string | null>(null)\n // Who the persisted workspace belongs to; set at sign-in, cleared at logout.\n const storageUserRef = useRef<string | null>(null)\n\n // The SDK could not recover the session (token refused, workspace not re-openable): drop to\n // 'disconnected' with a plain message, so the host's gate sends the user to sign in instead of\n // every call failing with a raw backend error. The remembered workspace is kept for next login.\n useEffect(\n () =>\n arbi.onSessionExpired?.(() => {\n rememberSessionUser(config.apiUrl, null)\n storageUserRef.current = null\n setUser(null)\n setWorkspaceId(null)\n setStatus('disconnected')\n setError(SESSION_EXPIRED_MESSAGE)\n }),\n [arbi, config.apiUrl]\n )\n\n // A saved name, picture or email reaches every surface reading `useConnection().user`.\n useEffect(\n () =>\n arbi.user.onProfileChange?.((profile) =>\n setUser((current) => (current ? userFromProfile(profile, current.externalId) : current))\n ),\n [arbi]\n )\n\n const enterDemo = useCallback(() => {\n setMode('demo')\n setStatus('demo')\n setError(null)\n setUser({ name: config.demoUser.name, email: config.demoUser.email })\n setWorkspaceId(demoWorkspaceId)\n }, [config.demoUser.name, config.demoUser.email, demoWorkspaceId])\n\n const login = useCallback(\n async (email: string, password: string, restoring = false) => {\n setError(null)\n // No backend configured → run the seeded demo workspace.\n if (!isLiveConfigured) {\n enterDemo()\n return\n }\n setStatus('connecting')\n setMode('live')\n try {\n if (restoring) {\n if (!(await arbi.restoreSession(email))) {\n rememberSessionUser(config.apiUrl, null)\n setStatus('disconnected')\n return\n }\n } else await arbi.login(email, password)\n storageUserRef.current = normalizeUserKey(email)\n const workspaces = await arbi.workspaces.list()\n if (workspaces?.length) {\n // Prefer the workspace the user last affirmatively selected (persisted),\n // then the configured workspace (there may be several — e.g. a\n // marketing/KM workspace), then whichever happens to be first. Ternary\n // (not `&&`) so an empty value can't leak `\"\"` into `target`.\n const persisted = readPersistedWorkspace(config.apiUrl, storageUserRef.current)\n const preferred = persisted ?? config.workspaceId\n const target =\n (preferred ? workspaces.find((w) => w.external_id === preferred) : undefined) ??\n workspaces[0]\n await arbi.selectWorkspace(target.external_id)\n setWorkspaceId(target.external_id)\n persistWorkspace(config.apiUrl, storageUserRef.current, target.external_id)\n }\n // The profile (name + avatar) comes with the login response. A session restored without\n // a login has none, so fall back to finding ourselves in the workspace roster; the email\n // local part is only the last resort, never the answer when a profile name exists.\n let resolved: ArbiUser = { name: email.split('@')[0], email }\n const me = arbi.user.identity()\n const profile = arbi.user.profile?.()\n if (profile) {\n resolved = userFromProfile(profile, me?.externalId)\n } else {\n try {\n const members = await arbi.workspaces.listUsers()\n const self = members.find((m) => m.user.external_id === me?.externalId)?.user\n if (self) {\n const fullName = [self.given_name, self.family_name].filter(Boolean).join(' ').trim()\n resolved = {\n name: fullName || email.split('@')[0],\n email: self.email || email,\n externalId: self.external_id,\n picture: self.picture ?? null,\n }\n } else if (me?.externalId) {\n resolved.externalId = me.externalId\n }\n } catch {\n // Roster not available (e.g. no workspace) — keep the fallback identity.\n }\n }\n setUser(resolved)\n rememberSessionUser(config.apiUrl, email)\n setStatus('authenticated')\n } catch (e) {\n // Surface the real error — no silent fallback to a fake session.\n setError(e instanceof Error ? e.message : 'Sign-in failed. Check your credentials.')\n setStatus('error')\n }\n },\n [arbi, enterDemo, isLiveConfigured, config.workspaceId, config.apiUrl]\n )\n\n // Run once even under StrictMode; passwords and signing keys are never stored here.\n const recoveryStarted = useRef(false)\n useEffect(() => {\n if (recoveryStarted.current || !isLiveConfigured) return\n recoveryStarted.current = true\n let email: string | null = null\n try {\n email = window.localStorage.getItem(sessionUserKey(config.apiUrl))\n } catch {\n /* unavailable */\n }\n if (email) void login(email, '', true)\n else setStatus('disconnected')\n }, [isLiveConfigured, config.apiUrl, login])\n\n const logout = useCallback(() => {\n rememberSessionUser(config.apiUrl, null)\n if (mode === 'live') {\n void arbi.logout?.()\n }\n setUser(null)\n setWorkspaceId(null)\n persistWorkspace(config.apiUrl, storageUserRef.current, null)\n storageUserRef.current = null\n setStatus('disconnected')\n setError(null)\n }, [arbi, mode, config.apiUrl])\n\n // Affirmative selection: open the workspace on the server (live), then remember\n // it in state + storage so every surface — and the next login — is in sync.\n const setWorkspace = useCallback(\n async (id: string) => {\n if (mode === 'live' && arbi.isLoggedIn) {\n await arbi.selectWorkspace(id)\n }\n setWorkspaceId(id)\n persistWorkspace(config.apiUrl, storageUserRef.current, id)\n },\n [arbi, mode, config.apiUrl]\n )\n\n // Re-open the selected workspace on the session if the server may have dropped\n // it. Idempotent: re-running `/open` for the already-selected workspace is safe.\n const ensureWorkspaceOpen = useCallback(async () => {\n if (mode !== 'live' || !arbi.isLoggedIn) return\n const id =\n workspaceId ??\n readPersistedWorkspace(config.apiUrl, storageUserRef.current) ??\n config.workspaceId\n if (id) await arbi.selectWorkspace(id)\n }, [arbi, mode, workspaceId, config.apiUrl, config.workspaceId])\n\n const value = useMemo<ConnectionValue>(\n () => ({\n mode,\n status,\n user,\n workspaceId,\n apiConfigured: isLiveConfigured,\n apiUrl: config.apiUrl,\n deploymentDomain: isLiveConfigured ? arbi.getDeploymentDomain() : undefined,\n error,\n assistantConfig: config.assistantConfig,\n fallbackWorkspaceId: config.workspaceId,\n login,\n enterDemo,\n logout,\n setWorkspace,\n ensureWorkspaceOpen,\n }),\n [\n mode,\n status,\n user,\n workspaceId,\n isLiveConfigured,\n config.apiUrl,\n arbi,\n config.assistantConfig,\n config.workspaceId,\n error,\n login,\n enterDemo,\n logout,\n setWorkspace,\n ensureWorkspaceOpen,\n ]\n )\n\n return <ConnectionContext.Provider value={value}>{children}</ConnectionContext.Provider>\n}\n\nexport function useConnection(): ConnectionValue {\n const ctx = useContext(ConnectionContext)\n if (!ctx) throw new Error('useConnection must be used within ConnectionProvider')\n return ctx\n}\n\nexport const isAuthenticated = (s: ConnectionStatus) => s === 'demo' || s === 'authenticated'\n"]}
|