@arbidocs/blocks 0.4.142 → 0.4.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/agents/index.cjs +438 -435
  2. package/dist/agents/index.js +10 -7
  3. package/dist/chat/index.cjs +139 -138
  4. package/dist/chat/index.js +4 -3
  5. package/dist/{chunk-S24XEVPS.cjs → chunk-464YPRAE.cjs} +33 -2
  6. package/dist/chunk-464YPRAE.cjs.map +1 -0
  7. package/dist/{chunk-7YLJHTDC.cjs → chunk-5A2QQAF5.cjs} +11 -11
  8. package/dist/{chunk-7YLJHTDC.cjs.map → chunk-5A2QQAF5.cjs.map} +1 -1
  9. package/dist/{chunk-ON3TKY5Y.js → chunk-5YHEHEJT.js} +242 -4
  10. package/dist/chunk-5YHEHEJT.js.map +1 -0
  11. package/dist/chunk-76L6LOP3.cjs +308 -0
  12. package/dist/chunk-76L6LOP3.cjs.map +1 -0
  13. package/dist/chunk-AOSUHWIL.js +98 -0
  14. package/dist/chunk-AOSUHWIL.js.map +1 -0
  15. package/dist/{chunk-PROK33G6.js → chunk-C44TDH54.js} +13 -1598
  16. package/dist/chunk-C44TDH54.js.map +1 -0
  17. package/dist/{chunk-YFY3TQ6Q.cjs → chunk-COCGRJLA.cjs} +7 -7
  18. package/dist/{chunk-YFY3TQ6Q.cjs.map → chunk-COCGRJLA.cjs.map} +1 -1
  19. package/dist/chunk-CQCC7LE7.js +210 -0
  20. package/dist/chunk-CQCC7LE7.js.map +1 -0
  21. package/dist/{chunk-UGCKUXRV.js → chunk-CSI2B2H5.js} +3 -3
  22. package/dist/{chunk-UGCKUXRV.js.map → chunk-CSI2B2H5.js.map} +1 -1
  23. package/dist/{chunk-R26BK7YL.cjs → chunk-DTROMMDX.cjs} +4 -4
  24. package/dist/{chunk-R26BK7YL.cjs.map → chunk-DTROMMDX.cjs.map} +1 -1
  25. package/dist/{chunk-65THHQVB.cjs → chunk-ECW2R2KF.cjs} +27 -27
  26. package/dist/{chunk-65THHQVB.cjs.map → chunk-ECW2R2KF.cjs.map} +1 -1
  27. package/dist/{chunk-RI6DZA5X.js → chunk-EF4ZLKRM.js} +3 -3
  28. package/dist/{chunk-RI6DZA5X.js.map → chunk-EF4ZLKRM.js.map} +1 -1
  29. package/dist/{chunk-WS5EX7DN.cjs → chunk-EYKISBDO.cjs} +5 -5
  30. package/dist/{chunk-WS5EX7DN.cjs.map → chunk-EYKISBDO.cjs.map} +1 -1
  31. package/dist/chunk-FJETR2AS.js +561 -0
  32. package/dist/chunk-FJETR2AS.js.map +1 -0
  33. package/dist/{chunk-JO3EMZ4X.js → chunk-GWSGIZQ5.js} +3 -3
  34. package/dist/{chunk-JO3EMZ4X.js.map → chunk-GWSGIZQ5.js.map} +1 -1
  35. package/dist/{chunk-I7WG3JRD.js → chunk-H4D7WKDY.js} +3 -3
  36. package/dist/{chunk-I7WG3JRD.js.map → chunk-H4D7WKDY.js.map} +1 -1
  37. package/dist/{chunk-GBS6QVGS.cjs → chunk-HAOKT4LC.cjs} +5 -5
  38. package/dist/{chunk-GBS6QVGS.cjs.map → chunk-HAOKT4LC.cjs.map} +1 -1
  39. package/dist/{chunk-N5X37J3D.js → chunk-IJST4EBM.js} +11 -8
  40. package/dist/chunk-IJST4EBM.js.map +1 -0
  41. package/dist/{chunk-3RJN2VTL.js → chunk-IXWJGOM2.js} +3 -3
  42. package/dist/{chunk-3RJN2VTL.js.map → chunk-IXWJGOM2.js.map} +1 -1
  43. package/dist/{chunk-CYNF5PZI.js → chunk-J5CWKFSC.js} +3 -3
  44. package/dist/{chunk-CYNF5PZI.js.map → chunk-J5CWKFSC.js.map} +1 -1
  45. package/dist/{chunk-OWCEQKAR.cjs → chunk-JSTKEZBS.cjs} +21 -318
  46. package/dist/chunk-JSTKEZBS.cjs.map +1 -0
  47. package/dist/{chunk-TP6PLDNM.cjs → chunk-KMZWKSKO.cjs} +8 -8
  48. package/dist/{chunk-TP6PLDNM.cjs.map → chunk-KMZWKSKO.cjs.map} +1 -1
  49. package/dist/{chunk-C4WSHRR6.cjs → chunk-KPZZ5FHE.cjs} +32 -12
  50. package/dist/chunk-KPZZ5FHE.cjs.map +1 -0
  51. package/dist/{chunk-CKCBBYTA.js → chunk-KSHKTOY2.js} +5 -205
  52. package/dist/chunk-KSHKTOY2.js.map +1 -0
  53. package/dist/chunk-LJJJ6CYH.cjs +62 -0
  54. package/dist/chunk-LJJJ6CYH.cjs.map +1 -0
  55. package/dist/chunk-LPYEUD2D.cjs +1627 -0
  56. package/dist/chunk-LPYEUD2D.cjs.map +1 -0
  57. package/dist/chunk-MHFF5N65.cjs +101 -0
  58. package/dist/chunk-MHFF5N65.cjs.map +1 -0
  59. package/dist/{chunk-GYAUJ4KT.js → chunk-MTSKK3BN.js} +32 -3
  60. package/dist/chunk-MTSKK3BN.js.map +1 -0
  61. package/dist/chunk-NHZK64TQ.js +75 -0
  62. package/dist/chunk-NHZK64TQ.js.map +1 -0
  63. package/dist/{chunk-BPBSSMRB.js → chunk-NRFAWUVD.js} +3 -3
  64. package/dist/{chunk-BPBSSMRB.js.map → chunk-NRFAWUVD.js.map} +1 -1
  65. package/dist/chunk-NWNVWO6L.cjs +80 -0
  66. package/dist/chunk-NWNVWO6L.cjs.map +1 -0
  67. package/dist/{chunk-HIJUXAWS.cjs → chunk-O2GW5IY6.cjs} +86 -83
  68. package/dist/chunk-O2GW5IY6.cjs.map +1 -0
  69. package/dist/{chunk-3BFGL2JL.cjs → chunk-ODRHHWHY.cjs} +4 -4
  70. package/dist/{chunk-3BFGL2JL.cjs.map → chunk-ODRHHWHY.cjs.map} +1 -1
  71. package/dist/{chunk-Y3KA6X7B.js → chunk-OVR3XMYL.js} +4 -4
  72. package/dist/{chunk-Y3KA6X7B.js.map → chunk-OVR3XMYL.js.map} +1 -1
  73. package/dist/{chunk-Y5KTM3V5.js → chunk-PDKM27DF.js} +17 -295
  74. package/dist/chunk-PDKM27DF.js.map +1 -0
  75. package/dist/{chunk-OAL3B2ZU.cjs → chunk-PLJ7PHWU.cjs} +5 -5
  76. package/dist/{chunk-OAL3B2ZU.cjs.map → chunk-PLJ7PHWU.cjs.map} +1 -1
  77. package/dist/{chunk-DPGFEMVT.cjs → chunk-RB7GX2VT.cjs} +57 -1665
  78. package/dist/chunk-RB7GX2VT.cjs.map +1 -0
  79. package/dist/chunk-RFIBUWLF.cjs +232 -0
  80. package/dist/chunk-RFIBUWLF.cjs.map +1 -0
  81. package/dist/{chunk-MIDXCYZB.cjs → chunk-RQ2Y7USX.cjs} +15 -235
  82. package/dist/chunk-RQ2Y7USX.cjs.map +1 -0
  83. package/dist/chunk-SV65E4QW.js +58 -0
  84. package/dist/chunk-SV65E4QW.js.map +1 -0
  85. package/dist/{chunk-LYUO3E6V.js → chunk-SZOFGU7W.js} +3 -3
  86. package/dist/{chunk-LYUO3E6V.js.map → chunk-SZOFGU7W.js.map} +1 -1
  87. package/dist/chunk-T5B7FM7S.js +1602 -0
  88. package/dist/chunk-T5B7FM7S.js.map +1 -0
  89. package/dist/{chunk-YNIBUKV5.js → chunk-TBEVGWY3.js} +32 -14
  90. package/dist/chunk-TBEVGWY3.js.map +1 -0
  91. package/dist/{chunk-MJCCBMM5.cjs → chunk-TC3RQNEX.cjs} +6 -80
  92. package/dist/chunk-TC3RQNEX.cjs.map +1 -0
  93. package/dist/chunk-TZGBRLPK.js +288 -0
  94. package/dist/chunk-TZGBRLPK.js.map +1 -0
  95. package/dist/chunk-U6YVZDOV.cjs +574 -0
  96. package/dist/chunk-U6YVZDOV.cjs.map +1 -0
  97. package/dist/{chunk-QIMVTGKS.cjs → chunk-U73KPFYH.cjs} +255 -2
  98. package/dist/chunk-U73KPFYH.cjs.map +1 -0
  99. package/dist/{chunk-HFGXA5CL.cjs → chunk-UTTTJSQU.cjs} +4 -4
  100. package/dist/{chunk-HFGXA5CL.cjs.map → chunk-UTTTJSQU.cjs.map} +1 -1
  101. package/dist/{chunk-DLBUFHLY.js → chunk-VTTZZ4FN.js} +4 -74
  102. package/dist/chunk-VTTZZ4FN.js.map +1 -0
  103. package/dist/{chunk-5FTIHRZH.cjs → chunk-XVUOMWMD.cjs} +4 -4
  104. package/dist/{chunk-5FTIHRZH.cjs.map → chunk-XVUOMWMD.cjs.map} +1 -1
  105. package/dist/{chunk-FXG7TFAG.js → chunk-Y4ATWQGV.js} +3 -3
  106. package/dist/{chunk-FXG7TFAG.js.map → chunk-Y4ATWQGV.js.map} +1 -1
  107. package/dist/{chunk-444XKG46.js → chunk-YKQ2DPIP.js} +3 -3
  108. package/dist/{chunk-444XKG46.js.map → chunk-YKQ2DPIP.js.map} +1 -1
  109. package/dist/{chunk-HEMU73OP.cjs → chunk-YSHIC4NJ.cjs} +4 -4
  110. package/dist/{chunk-HEMU73OP.cjs.map → chunk-YSHIC4NJ.cjs.map} +1 -1
  111. package/dist/{chunk-5BXEYYH6.js → chunk-ZM26YEOT.js} +3 -3
  112. package/dist/{chunk-5BXEYYH6.js.map → chunk-ZM26YEOT.js.map} +1 -1
  113. package/dist/citations/index.cjs +12 -12
  114. package/dist/citations/index.js +3 -3
  115. package/dist/connect/docx.cjs +36 -7
  116. package/dist/connect/docx.cjs.map +1 -1
  117. package/dist/connect/docx.d.ts +9 -2
  118. package/dist/connect/docx.js +30 -6
  119. package/dist/connect/docx.js.map +1 -1
  120. package/dist/connect/index.cjs +802 -628
  121. package/dist/connect/index.cjs.map +1 -1
  122. package/dist/connect/index.d.ts +2 -0
  123. package/dist/connect/index.js +636 -507
  124. package/dist/connect/index.js.map +1 -1
  125. package/dist/connection/ConnectedSettings.d.ts +3 -2
  126. package/dist/connection/docx/ConnectedNativeDocxComparison.d.ts +5 -0
  127. package/dist/connection/docx/ConnectedNativeDocxEditor.d.ts +16 -0
  128. package/dist/connection/{ConnectedStreamedWordArtifact.d.ts → docx/ConnectedStreamedWordArtifact.d.ts} +1 -1
  129. package/dist/connection/docx/support.d.ts +27 -0
  130. package/dist/connection/docx/useConnectedDocxReferences.d.ts +2 -0
  131. package/dist/connection/docx/useConnectedHouseTemplate.d.ts +2 -0
  132. package/dist/connection/settings-page/ConnectedAccountSettings.d.ts +35 -0
  133. package/dist/connection/settings-page/ConnectedMailSettings.d.ts +13 -0
  134. package/dist/connection/settings-page/ConnectedPremiumModels.d.ts +1 -0
  135. package/dist/connection/settings-page/ConnectedPrivacySettings.d.ts +12 -0
  136. package/dist/connection/settings-page/ConnectedSettingsPage.d.ts +29 -0
  137. package/dist/connection/settings-page/SessionStatusIcon.d.ts +7 -0
  138. package/dist/connection/settings-page/index.d.ts +6 -0
  139. package/dist/docx/index.cjs +17 -63
  140. package/dist/docx/index.cjs.map +1 -1
  141. package/dist/docx/index.d.ts +1 -0
  142. package/dist/docx/index.js +2 -64
  143. package/dist/docx/index.js.map +1 -1
  144. package/dist/docx/template/candidates.d.ts +16 -0
  145. package/dist/facts/index.cjs +3 -3
  146. package/dist/facts/index.js +2 -2
  147. package/dist/files/index.cjs +3 -3
  148. package/dist/files/index.js +2 -2
  149. package/dist/home/index.cjs +20 -20
  150. package/dist/home/index.js +4 -4
  151. package/dist/index.cjs +766 -741
  152. package/dist/index.cjs.map +1 -1
  153. package/dist/index.d.ts +2 -0
  154. package/dist/index.js +23 -18
  155. package/dist/index.js.map +1 -1
  156. package/dist/lib/deep-link.d.ts +46 -0
  157. package/dist/provider/BlocksProvider.d.ts +5 -1
  158. package/dist/provider/settings-section.d.ts +9 -0
  159. package/dist/retrieval/index.cjs +4 -4
  160. package/dist/retrieval/index.js +2 -2
  161. package/dist/settings/AppearanceSettings.d.ts +18 -0
  162. package/dist/settings/ServerConnectionControls.d.ts +16 -0
  163. package/dist/settings/SettingsPage.d.ts +31 -0
  164. package/dist/settings/index.cjs +188 -250
  165. package/dist/settings/index.cjs.map +1 -1
  166. package/dist/settings/index.d.ts +3 -1
  167. package/dist/settings/index.js +88 -199
  168. package/dist/settings/index.js.map +1 -1
  169. package/dist/shell/index.cjs +44 -44
  170. package/dist/shell/index.js +3 -3
  171. package/dist/site/index.cjs +74 -73
  172. package/dist/site/index.js +3 -2
  173. package/dist/studio/index.cjs +80 -78
  174. package/dist/studio/index.cjs.map +1 -1
  175. package/dist/studio/index.js +10 -8
  176. package/dist/studio/index.js.map +1 -1
  177. package/dist/workflow-canvas/index.cjs +62 -59
  178. package/dist/workflow-canvas/index.cjs.map +1 -1
  179. package/dist/workflow-canvas/index.js +10 -7
  180. package/dist/workflow-canvas/index.js.map +1 -1
  181. package/dist/workspaces/index.cjs +3 -3
  182. package/dist/workspaces/index.js +2 -2
  183. package/node_modules/@arbidocs/coedit/package.json +1 -1
  184. package/package.json +4 -4
  185. package/dist/chunk-4TR5QCCX.cjs +0 -43
  186. package/dist/chunk-4TR5QCCX.cjs.map +0 -1
  187. package/dist/chunk-7NDW4KF4.cjs +0 -112
  188. package/dist/chunk-7NDW4KF4.cjs.map +0 -1
  189. package/dist/chunk-C4WSHRR6.cjs.map +0 -1
  190. package/dist/chunk-CKCBBYTA.js.map +0 -1
  191. package/dist/chunk-DLBUFHLY.js.map +0 -1
  192. package/dist/chunk-DPGFEMVT.cjs.map +0 -1
  193. package/dist/chunk-ETXYVO6E.js +0 -109
  194. package/dist/chunk-ETXYVO6E.js.map +0 -1
  195. package/dist/chunk-GYAUJ4KT.js.map +0 -1
  196. package/dist/chunk-HIJUXAWS.cjs.map +0 -1
  197. package/dist/chunk-MCKOZACC.js +0 -41
  198. package/dist/chunk-MCKOZACC.js.map +0 -1
  199. package/dist/chunk-MIDXCYZB.cjs.map +0 -1
  200. package/dist/chunk-MJCCBMM5.cjs.map +0 -1
  201. package/dist/chunk-N5X37J3D.js.map +0 -1
  202. package/dist/chunk-ON3TKY5Y.js.map +0 -1
  203. package/dist/chunk-OWCEQKAR.cjs.map +0 -1
  204. package/dist/chunk-PROK33G6.js.map +0 -1
  205. package/dist/chunk-QIMVTGKS.cjs.map +0 -1
  206. package/dist/chunk-S24XEVPS.cjs.map +0 -1
  207. package/dist/chunk-Y5KTM3V5.js.map +0 -1
  208. package/dist/chunk-YNIBUKV5.js.map +0 -1
  209. package/dist/connection/ConnectedNativeDocxEditor.d.ts +0 -6
@@ -0,0 +1,561 @@
1
+ "use client";
2
+ import { useConnectedDocuments, useConnectedTags, useConnectedConversations } from './chunk-45LRMW54.js';
3
+ import { useConnectedWorkspace } from './chunk-US3S4DCB.js';
4
+ import { loadDocxFonts, isCandidate } from './chunk-MTSKK3BN.js';
5
+ import { NativeDocxEditor, contentPath, builtinHouseTemplate } from './chunk-2FL7QJKJ.js';
6
+ import { parseDeepLinkPath, buildDeepLinkUrl } from './chunk-SV65E4QW.js';
7
+ import { buildWorkflowScopeSource, documentScopeLabels, WorkflowDocumentsField, WorkflowLauncher, WorkflowsTable, workflowTriggerType } from './chunk-T5B7FM7S.js';
8
+ import { DocumentPicker } from './chunk-KSHKTOY2.js';
9
+ import { useRegisterOpenDocument } from './chunk-YBLIKTJK.js';
10
+ import { useBlocksEnvironment } from './chunk-TBEVGWY3.js';
11
+ import { fmtDate } from './chunk-OXF2IFXG.js';
12
+ import { createContext, useContext, useMemo, useRef, useState, useCallback, useEffect } from 'react';
13
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
+ import { useAgents, useArbi, useThumbnails, useWorkspaceUsers, useWorkflows, useUpdateWorkflow, useDeleteWorkflow, useRunWorkflow, arbiQueryKeys, useSetWorkspaceHouseTemplate, useWorkspaces, supportsHouseTemplates, workspaceHouseTemplateId, useHouseTemplateCandidates } from '@arbidocs/react';
15
+ import { useQueryClient } from '@tanstack/react-query';
16
+ import { useOptionalDocumentTools } from '@arbidocs/react/document-tools';
17
+
18
+ var NativeDocxSupportContext = createContext({});
19
+ function NativeDocxSupportProvider({
20
+ value,
21
+ children
22
+ }) {
23
+ return /* @__PURE__ */ jsx(NativeDocxSupportContext.Provider, { value, children });
24
+ }
25
+ function useNativeDocxSupport() {
26
+ return useContext(NativeDocxSupportContext);
27
+ }
28
+ var IMAGE_FILE_TYPES = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "bmp", "tiff", "webp"]);
29
+ function toWorkflowFieldDocument(doc) {
30
+ const isImage = IMAGE_FILE_TYPES.has((doc.file_type ?? "").toLowerCase());
31
+ return {
32
+ id: doc.external_id,
33
+ title: doc.doc_metadata?.title || doc.file_name || doc.external_id,
34
+ fileName: doc.file_name,
35
+ pages: isImage ? null : doc.n_pages ?? null,
36
+ tokens: isImage ? null : doc.tokens ?? null,
37
+ status: doc.status,
38
+ isImage
39
+ };
40
+ }
41
+ function useConnectedWorkflowScopeSource() {
42
+ const { data: docs } = useConnectedDocuments();
43
+ const { data: tags } = useConnectedTags();
44
+ return useMemo(() => buildWorkflowScopeSource(docs, documentScopeLabels(tags)), [docs, tags]);
45
+ }
46
+ function useConnectedAgentOptions() {
47
+ const { data: agents } = useAgents();
48
+ return useMemo(
49
+ () => (agents ?? []).map((a) => ({ id: a.external_id, label: a.given_name || a.email })),
50
+ [agents]
51
+ );
52
+ }
53
+ function ConnectedWorkflowDocumentsField({
54
+ field,
55
+ value,
56
+ onChange,
57
+ onAddFiles,
58
+ labels
59
+ }) {
60
+ const arbi = useArbi();
61
+ const { notify } = useBlocksEnvironment();
62
+ const { ensureWorkspaceOpen } = useConnectedWorkspace();
63
+ const { data: docs, loaded, refetch } = useConnectedDocuments();
64
+ const documents = useMemo(() => docs.map(toWorkflowFieldDocument), [docs]);
65
+ const chosen = value.documents ?? [];
66
+ const { data: thumbnails } = useThumbnails(chosen, { enabled: (field.max ?? 1) > 1 });
67
+ const input = useRef(null);
68
+ const [adding, setAdding] = useState(false);
69
+ const upload = useCallback(
70
+ async (files) => {
71
+ setAdding(true);
72
+ try {
73
+ await ensureWorkspaceOpen();
74
+ for (const file of files) await arbi.documents.uploadFile(file, file.name);
75
+ } catch (error) {
76
+ notify(error instanceof Error && error.message ? error.message : String(error), "error");
77
+ } finally {
78
+ setAdding(false);
79
+ await refetch?.();
80
+ }
81
+ },
82
+ [arbi, ensureWorkspaceOpen, notify, refetch]
83
+ );
84
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
85
+ !onAddFiles && /* @__PURE__ */ jsx(
86
+ "input",
87
+ {
88
+ ref: input,
89
+ type: "file",
90
+ multiple: true,
91
+ className: "hidden",
92
+ "aria-label": "Add files",
93
+ "data-testid": "workflow-add-files-input",
94
+ onChange: (e) => {
95
+ const files = Array.from(e.target.files ?? []);
96
+ e.target.value = "";
97
+ if (files.length) void upload(files);
98
+ }
99
+ }
100
+ ),
101
+ /* @__PURE__ */ jsx(
102
+ WorkflowDocumentsField,
103
+ {
104
+ field,
105
+ value,
106
+ onChange,
107
+ documents,
108
+ loaded,
109
+ thumbnailOf: (id) => thumbnails?.[id],
110
+ onAddFiles: onAddFiles ?? ((files) => files?.length ? void upload(files) : input.current?.click()),
111
+ adding,
112
+ labels
113
+ }
114
+ )
115
+ ] });
116
+ }
117
+ function ConnectedWorkflowLauncher({
118
+ onAddFiles,
119
+ ...props
120
+ }) {
121
+ const scopeSource = useConnectedWorkflowScopeSource();
122
+ const agents = useConnectedAgentOptions();
123
+ return /* @__PURE__ */ jsx(
124
+ WorkflowLauncher,
125
+ {
126
+ ...props,
127
+ scopeSource,
128
+ agents,
129
+ renderDocuments: (field, value, onChange) => /* @__PURE__ */ jsx(
130
+ ConnectedWorkflowDocumentsField,
131
+ {
132
+ field,
133
+ value,
134
+ onChange,
135
+ onAddFiles
136
+ }
137
+ )
138
+ }
139
+ );
140
+ }
141
+ function useConnectedWorkspaceRole() {
142
+ const { workspaceId, live, userId, ensureWorkspaceOpen } = useConnectedWorkspace();
143
+ const { data: members = [] } = useWorkspaceUsers(workspaceId ?? void 0, {
144
+ enabled: live && !!workspaceId,
145
+ beforeFetch: ensureWorkspaceOpen
146
+ });
147
+ const role = members.find((m) => m.user.external_id === userId)?.role;
148
+ return {
149
+ members,
150
+ role,
151
+ /** An owner or a collaborator edits, pauses, resumes and runs what is shared with the workspace. */
152
+ canEditShared: role === "owner" || role === "collaborator",
153
+ /** With an item's creator, the only one who deletes it. */
154
+ isWorkspaceOwner: role === "owner"
155
+ };
156
+ }
157
+ var DEFAULT_CONNECTED_WORKFLOWS_TABLE_LABELS = {
158
+ updateFailed: "Could not update the workflow",
159
+ deleteTitle: "Delete workflow",
160
+ deleteOne: (name) => `Delete \u201C${name}\u201D? Threads it already created stay.`,
161
+ deleteMany: (count) => `Delete ${count} workflows? Threads they already created stay.`,
162
+ runFailed: "The workflow failed. You can send an error report from its history.",
163
+ noThread: "The workflow did not create a thread.",
164
+ documentAction: (workflow) => workflow.action?.type === "email_documents" ? "Preparing your document email" : "Reviewing documents",
165
+ untitledTask: "Untitled thread"
166
+ };
167
+ var messageOf = (error) => error instanceof Error ? error.message : "";
168
+ function ConnectedWorkflowsTable({
169
+ filter,
170
+ describeTrigger = (w) => workflowTriggerType(w).replaceAll("_", " "),
171
+ formatDate = fmtDate,
172
+ onViewRuns,
173
+ connectedLabels,
174
+ ...tableProps
175
+ }) {
176
+ const l = { ...DEFAULT_CONNECTED_WORKFLOWS_TABLE_LABELS, ...connectedLabels };
177
+ const { notify, confirm, openConversation } = useBlocksEnvironment();
178
+ const { canEditShared, isWorkspaceOwner } = useConnectedWorkspaceRole();
179
+ const { data: saved = [], isLoading } = useWorkflows({ live: true });
180
+ const { data: conversations, refetch } = useConnectedConversations({ live: true });
181
+ const { data: agents = [] } = useAgents();
182
+ const update = useUpdateWorkflow();
183
+ const remove = useDeleteWorkflow();
184
+ const run = useRunWorkflow();
185
+ const [busyId, setBusyId] = useState(null);
186
+ const workflows = useMemo(() => filter ? saved.filter(filter) : saved, [saved, filter]);
187
+ const firingStamp = saved.map((w) => `${w.external_id}:${w.last_fired_at ?? ""}`).join("|");
188
+ useEffect(() => {
189
+ void refetch?.();
190
+ }, [firingStamp, refetch]);
191
+ const lastRuns = useMemo(() => {
192
+ const out = {};
193
+ for (const c of conversations) {
194
+ const id = c.workflow_ext_id;
195
+ if (id && (!out[id] || Date.parse(c.created_at) > Date.parse(out[id].at)))
196
+ out[id] = { conversationId: c.external_id, at: c.created_at, threadStatus: c.status };
197
+ }
198
+ return out;
199
+ }, [conversations]);
200
+ const agentNames = useMemo(
201
+ () => Object.fromEntries(agents.map((a) => [a.external_id, a.given_name || a.email])),
202
+ [agents]
203
+ );
204
+ const taskNames = useMemo(
205
+ () => Object.fromEntries(
206
+ conversations.filter((c) => c.status != null).map((c) => [c.external_id, c.title || l.untitledTask])
207
+ ),
208
+ [conversations, l.untitledTask]
209
+ );
210
+ const act = async (workflow, action) => {
211
+ setBusyId(workflow.external_id);
212
+ try {
213
+ await action();
214
+ } catch (error) {
215
+ notify(messageOf(error) || l.updateFailed, "error");
216
+ } finally {
217
+ setBusyId(null);
218
+ }
219
+ };
220
+ const setActive = (workflow, active) => act(workflow, () => update.mutateAsync({ workflowId: workflow.external_id, patch: { active } }));
221
+ const deleteAll = async (items) => {
222
+ if (!items.length) return;
223
+ const ok = await confirm({
224
+ title: l.deleteTitle,
225
+ message: items.length === 1 ? l.deleteOne(items[0].name) : l.deleteMany(items.length)
226
+ });
227
+ if (!ok) return;
228
+ for (const workflow of items)
229
+ await act(workflow, () => remove.mutateAsync(workflow.external_id));
230
+ };
231
+ return /* @__PURE__ */ jsx(
232
+ WorkflowsTable,
233
+ {
234
+ ...tableProps,
235
+ workflows,
236
+ isLoading,
237
+ busyId,
238
+ describeTrigger,
239
+ formatDate,
240
+ agentNames,
241
+ taskNames,
242
+ lastRuns,
243
+ canEditShared,
244
+ isWorkspaceOwner,
245
+ onOpenThread: (conversationId) => openConversation(conversationId),
246
+ onViewRuns,
247
+ onToggleActive: (workflow, active) => void setActive(workflow, active),
248
+ onToggleActiveMany: (items, active) => {
249
+ void (async () => {
250
+ for (const workflow of items) await setActive(workflow, active);
251
+ })();
252
+ },
253
+ onToggleShared: (workflow, shared) => void act(
254
+ workflow,
255
+ () => update.mutateAsync({ workflowId: workflow.external_id, patch: { shared } })
256
+ ),
257
+ onDelete: (workflow) => void deleteAll([workflow]),
258
+ onDeleteMany: (items) => void deleteAll(items),
259
+ onRun: (workflow) => void act(workflow, async () => {
260
+ const result = await run.mutateAsync(workflow.external_id);
261
+ if (result.conversation_ext_id) openConversation(result.conversation_ext_id);
262
+ if (result.error) {
263
+ onViewRuns?.(workflow);
264
+ notify(l.runFailed, "error");
265
+ return;
266
+ }
267
+ if (result.execution_id && !result.conversation_ext_id) {
268
+ onViewRuns?.(workflow);
269
+ notify(l.documentAction(workflow), "success");
270
+ return;
271
+ }
272
+ if (!result.conversation_ext_id) throw new Error(l.noThread);
273
+ })
274
+ }
275
+ );
276
+ }
277
+ var isTopLevel = (doc) => !doc.parent_ext_id;
278
+ function ReferencePicker({
279
+ documents,
280
+ selectedId,
281
+ onSelect
282
+ }) {
283
+ const groups = useMemo(() => {
284
+ const docs = documents.filter(isTopLevel).map(toWorkflowFieldDocument).sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase()));
285
+ return [{ id: "all", heading: "In this workspace", docs }];
286
+ }, [documents]);
287
+ const selected = groups[0].docs.find((d) => d.id === selectedId);
288
+ return /* @__PURE__ */ jsx(
289
+ DocumentPicker,
290
+ {
291
+ groups,
292
+ value: selectedId ?? "",
293
+ onValueChange: onSelect,
294
+ selected,
295
+ labels: { placeholder: "Search documents\u2026" }
296
+ }
297
+ );
298
+ }
299
+ function useConnectedDocxReferences() {
300
+ const arbi = useArbi();
301
+ const { workspaceId } = useConnectedWorkspace();
302
+ const { openDocument, runtimeConfig } = useBlocksEnvironment();
303
+ const { data: documents } = useConnectedDocuments();
304
+ const documentsRef = useRef(documents);
305
+ documentsRef.current = documents;
306
+ return useMemo(
307
+ () => ({
308
+ documents: async () => documentsRef.current.filter(isTopLevel).map((d) => ({ id: d.external_id, title: toWorkflowFieldDocument(d).title })),
309
+ passages: async (documentId) => {
310
+ const parsed = await arbi.documents.getParsedContent(documentId, "final");
311
+ return (parsed.chunks ?? []).flatMap(
312
+ (chunk) => chunk.metadata?.chunk_ext_id && chunk.content?.trim() ? [
313
+ {
314
+ chunkId: chunk.metadata.chunk_ext_id,
315
+ page: chunk.metadata.page_number ?? null,
316
+ text: chunk.content
317
+ }
318
+ ] : []
319
+ );
320
+ },
321
+ linkFor: ({ documentId, chunkId, page }) => {
322
+ const url = buildDeepLinkUrl(
323
+ { workspaceId: workspaceId ?? void 0, documentId, chunkId },
324
+ runtimeConfig.deploymentDomain
325
+ );
326
+ return page ? `${url}?page=${page}` : url;
327
+ },
328
+ targetOf: (href) => {
329
+ let url;
330
+ try {
331
+ url = new URL(href, window.location.origin);
332
+ } catch {
333
+ return null;
334
+ }
335
+ const { documentId, chunkId } = parseDeepLinkPath(url.pathname);
336
+ if (!documentId || !chunkId) return null;
337
+ const page = Number(url.searchParams.get("page")) || null;
338
+ return { documentId, chunkId, page };
339
+ },
340
+ open: ({ documentId, chunkId, page }) => openDocument(documentId, { passageId: chunkId, page: page ?? void 0 }),
341
+ renderDocumentPicker: (onSelect, selectedId) => /* @__PURE__ */ jsx(
342
+ ReferencePicker,
343
+ {
344
+ documents: documentsRef.current,
345
+ selectedId,
346
+ onSelect
347
+ }
348
+ )
349
+ }),
350
+ [arbi, workspaceId, openDocument, runtimeConfig.deploymentDomain]
351
+ );
352
+ }
353
+ function useConnectedHouseTemplate() {
354
+ const arbi = useArbi();
355
+ const { mutateAsync: setWorkspaceTemplate } = useSetWorkspaceHouseTemplate();
356
+ const { workspaceId, live, ensureWorkspaceOpen } = useConnectedWorkspace();
357
+ const { data: workspaces } = useWorkspaces({ enabled: live });
358
+ const workspace = workspaces?.find((w) => w.external_id === workspaceId);
359
+ const { isWorkspaceOwner } = useConnectedWorkspaceRole();
360
+ const supported = supportsHouseTemplates(workspace);
361
+ const templateId = workspaceHouseTemplateId(workspace);
362
+ const { data: candidates } = useHouseTemplateCandidates(
363
+ workspaceId,
364
+ supported && isWorkspaceOwner
365
+ );
366
+ return useMemo(
367
+ () => ({
368
+ load: async () => {
369
+ if (templateId) {
370
+ await ensureWorkspaceOpen();
371
+ const response = await arbi.editor.request(contentPath(templateId));
372
+ const [record] = await arbi.documents.get([templateId]).catch(() => []);
373
+ return {
374
+ bytes: new Uint8Array(await response.arrayBuffer()),
375
+ name: record?.file_name ?? "House template.docx",
376
+ source: "workspace",
377
+ documentId: templateId
378
+ };
379
+ }
380
+ if (supported) {
381
+ const deployment = await arbi.houseTemplates.deployment();
382
+ if (deployment) return { ...deployment, source: "deployment" };
383
+ }
384
+ return builtinHouseTemplate();
385
+ },
386
+ setFromDocument: supported && isWorkspaceOwner ? async (documentId) => {
387
+ await ensureWorkspaceOpen();
388
+ await setWorkspaceTemplate(documentId);
389
+ } : void 0,
390
+ isEligible: (documentId) => isCandidate(candidates, documentId)
391
+ }),
392
+ [
393
+ arbi,
394
+ setWorkspaceTemplate,
395
+ supported,
396
+ templateId,
397
+ isWorkspaceOwner,
398
+ candidates,
399
+ ensureWorkspaceOpen
400
+ ]
401
+ );
402
+ }
403
+ function ConnectedNativeDocxEditor({
404
+ fontBaseUrl = "/native-docx/fonts",
405
+ ...props
406
+ }) {
407
+ const adapter = useConnectedNativeDocxAdapter(fontBaseUrl);
408
+ const { workspaceId } = useConnectedWorkspace();
409
+ const { commentTarget } = useNativeDocxSupport();
410
+ const [openFailed, setOpenFailed] = useState(false);
411
+ const hasOpened = useRef(false);
412
+ const guardedAdapter = useMemo(
413
+ () => ({
414
+ ...adapter,
415
+ open: async (documentId) => {
416
+ try {
417
+ const session = await adapter.open(documentId);
418
+ hasOpened.current = true;
419
+ return session;
420
+ } catch (error) {
421
+ if (!hasOpened.current) setOpenFailed(true);
422
+ throw error;
423
+ }
424
+ }
425
+ }),
426
+ [adapter]
427
+ );
428
+ const live = !props.snapshot && !props.stream && !props.draftContent && !props.compact;
429
+ useRegisterOpenDocument({ documentId: live ? props.documentId : null, workspaceId });
430
+ const initialCommentId = props.initialCommentId ?? (commentTarget?.documentId === props.documentId ? commentTarget.commentId : void 0);
431
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [
432
+ openFailed && /* @__PURE__ */ jsx("p", { role: "status", className: "text-muted-foreground border-b px-3 py-2 text-xs", children: "Co-editing isn't available for this document right now, so this is a read-only copy of the last saved version." }),
433
+ /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ jsx(
434
+ NativeDocxEditor,
435
+ {
436
+ ...props,
437
+ snapshot: props.snapshot || openFailed,
438
+ initialCommentId,
439
+ adapter: guardedAdapter
440
+ }
441
+ ) })
442
+ ] });
443
+ }
444
+ function tokenChanges(arbi) {
445
+ return (listener) => {
446
+ if (!arbi.isLoggedIn) return () => {
447
+ };
448
+ const session = arbi.getClient().session;
449
+ let token = session.getState().accessToken;
450
+ return session.subscribe((state) => {
451
+ if (state.accessToken === token) return;
452
+ token = state.accessToken;
453
+ listener();
454
+ });
455
+ };
456
+ }
457
+ function useConnectedNativeDocxAdapter(fontBaseUrl = "/native-docx/fonts") {
458
+ const arbi = useArbi();
459
+ const { workspaceId, live, user, ensureWorkspaceOpen } = useConnectedWorkspace();
460
+ const queries = useQueryClient();
461
+ const { notify } = useBlocksEnvironment();
462
+ const tools = useOptionalDocumentTools();
463
+ const support = useNativeDocxSupport();
464
+ const references = useConnectedDocxReferences();
465
+ const houseTemplate = useConnectedHouseTemplate();
466
+ const { data: members } = useWorkspaceUsers(workspaceId ?? void 0, {
467
+ enabled: live && !!workspaceId,
468
+ beforeFetch: ensureWorkspaceOpen
469
+ });
470
+ const onDocumentsChanged = tools?.onDocumentsChanged;
471
+ const author = live && arbi.user.profile()?.givenName || user?.name || "You";
472
+ const adapter = useMemo(
473
+ () => ({
474
+ request: async (path, options) => {
475
+ await ensureWorkspaceOpen();
476
+ return arbi.editor.request(path, options);
477
+ },
478
+ open: async (id) => {
479
+ await ensureWorkspaceOpen();
480
+ return (await arbi.editor.request(`/${encodeURIComponent(id)}/session`, { method: "POST" })).json();
481
+ },
482
+ save: async (id, state) => (await arbi.editor.request(`/${encodeURIComponent(id)}/save`, {
483
+ method: "POST",
484
+ headers: { "Content-Type": "application/json" },
485
+ body: JSON.stringify({ state })
486
+ })).json(),
487
+ loadFonts: () => loadDocxFonts(fontBaseUrl),
488
+ baseUrl: arbi.getConnectionInfo()?.baseUrl || window.location.origin,
489
+ author,
490
+ subscribeTokenChanges: tokenChanges(arbi),
491
+ onDirtyChange: support.onDirtyChange,
492
+ onVersionSaved: async (id) => {
493
+ const hostRefresh = onDocumentsChanged?.([id], "version");
494
+ if (workspaceId) {
495
+ const key = arbiQueryKeys.documents(workspaceId);
496
+ try {
497
+ const documents = await arbi.documents.get([id]);
498
+ if (!documents.length) throw new Error("The saved version is not available yet.");
499
+ queries.setQueryData(
500
+ key,
501
+ (previous) => [
502
+ ...documents,
503
+ ...(previous || []).filter(
504
+ (doc) => !documents.some((saved) => saved.external_id === doc.external_id)
505
+ )
506
+ ]
507
+ );
508
+ } catch {
509
+ await queries.invalidateQueries({ queryKey: key });
510
+ }
511
+ }
512
+ await hostRefresh;
513
+ },
514
+ notify,
515
+ mentions: members?.map(({ user: member }) => ({
516
+ id: member.external_id,
517
+ name: [member.given_name, member.family_name].filter(Boolean).join(" "),
518
+ kind: member.external_id.startsWith("agt-") ? "agent" : "human"
519
+ })),
520
+ requestAgent: async (id, request) => {
521
+ const response = await arbi.editor.request(`/${encodeURIComponent(id)}/mentions`, {
522
+ method: "POST",
523
+ headers: { "Content-Type": "application/json" },
524
+ body: JSON.stringify({
525
+ comment_id: request.commentId,
526
+ instruction: request.instruction,
527
+ request_id: request.requestId,
528
+ recipient_ids: request.recipientIds
529
+ })
530
+ });
531
+ const delivery = await response.json();
532
+ notify("Mention delivered.", "success");
533
+ return { responseIds: delivery.response_ids || [] };
534
+ },
535
+ getAgentStatus: async (responseId) => (await arbi.assistant.getResponse(responseId)).status,
536
+ definitions: support.definitions,
537
+ references,
538
+ imageGeneration: support.imageGeneration,
539
+ houseTemplate
540
+ }),
541
+ [
542
+ arbi,
543
+ author,
544
+ members,
545
+ ensureWorkspaceOpen,
546
+ fontBaseUrl,
547
+ queries,
548
+ workspaceId,
549
+ notify,
550
+ onDocumentsChanged,
551
+ support,
552
+ references,
553
+ houseTemplate
554
+ ]
555
+ );
556
+ return adapter;
557
+ }
558
+
559
+ export { ConnectedNativeDocxEditor, ConnectedWorkflowDocumentsField, ConnectedWorkflowLauncher, ConnectedWorkflowsTable, DEFAULT_CONNECTED_WORKFLOWS_TABLE_LABELS, NativeDocxSupportProvider, toWorkflowFieldDocument, useConnectedAgentOptions, useConnectedNativeDocxAdapter, useConnectedWorkflowScopeSource, useConnectedWorkspaceRole, useNativeDocxSupport };
560
+ //# sourceMappingURL=chunk-FJETR2AS.js.map
561
+ //# sourceMappingURL=chunk-FJETR2AS.js.map