@arbidocs/react 0.4.69 → 0.4.71
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/README.md +10 -0
- package/dist/ProductionDialog-BRrZ5Lj5.d.cts +84 -0
- package/dist/ProductionDialog-DUC9BXWS.d.ts +84 -0
- package/dist/annotations/freeze/index.cjs +45 -1100
- package/dist/annotations/freeze/index.cjs.map +1 -1
- package/dist/annotations/freeze/index.d.cts +2 -85
- package/dist/annotations/freeze/index.d.ts +2 -85
- package/dist/annotations/freeze/index.js +4 -1084
- package/dist/annotations/freeze/index.js.map +1 -1
- package/dist/annotations/index.cjs +186 -2450
- package/dist/annotations/index.cjs.map +1 -1
- package/dist/annotations/index.d.cts +3 -81
- package/dist/annotations/index.d.ts +3 -81
- package/dist/annotations/index.js +4 -2411
- package/dist/annotations/index.js.map +1 -1
- package/dist/artifacts/index.cjs +91 -115
- package/dist/artifacts/index.cjs.map +1 -1
- package/dist/artifacts/index.js +13 -62
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/redline-core.cjs +8 -7
- package/dist/artifacts/redline-core.js +2 -1
- package/dist/bundle-BnCSbHy2.d.cts +85 -0
- package/dist/bundle-BnCSbHy2.d.ts +85 -0
- package/dist/bundle-N2JIJ2T6.js +4 -0
- package/dist/bundle-N2JIJ2T6.js.map +1 -0
- package/dist/bundle-T6BEVYHE.cjs +13 -0
- package/dist/bundle-T6BEVYHE.cjs.map +1 -0
- package/dist/{chunk-PATLJSAO.cjs → chunk-3AADNIOK.cjs} +9 -52
- package/dist/chunk-3AADNIOK.cjs.map +1 -0
- package/dist/chunk-3QF5DNAP.js +2413 -0
- package/dist/chunk-3QF5DNAP.js.map +1 -0
- package/dist/chunk-5DCRIWCA.cjs +243 -0
- package/dist/chunk-5DCRIWCA.cjs.map +1 -0
- package/dist/{chunk-NA3FOYSF.cjs → chunk-5SZ2J2WT.cjs} +5 -177
- package/dist/chunk-5SZ2J2WT.cjs.map +1 -0
- package/dist/{chunk-PFKLOVGQ.js → chunk-6ERJUIMQ.js} +4 -234
- package/dist/chunk-6ERJUIMQ.js.map +1 -0
- package/dist/{chunk-Z3RRZ3KV.cjs → chunk-6TFD5OS5.cjs} +25 -263
- package/dist/chunk-6TFD5OS5.cjs.map +1 -0
- package/dist/{chunk-43AKLNBC.js → chunk-74N436VK.js} +4 -40
- package/dist/chunk-74N436VK.js.map +1 -0
- package/dist/{chunk-BWVIAATD.cjs → chunk-BTRIS3HY.cjs} +4 -4
- package/dist/{chunk-BWVIAATD.cjs.map → chunk-BTRIS3HY.cjs.map} +1 -1
- package/dist/chunk-G6FHNURH.js +234 -0
- package/dist/chunk-G6FHNURH.js.map +1 -0
- package/dist/chunk-HKUD2NZN.js +61 -0
- package/dist/chunk-HKUD2NZN.js.map +1 -0
- package/dist/{chunk-ZMTLGO3K.cjs → chunk-IIT7DMQL.cjs} +6 -2
- package/dist/chunk-IIT7DMQL.cjs.map +1 -0
- package/dist/chunk-QJXFRP5R.cjs +1103 -0
- package/dist/chunk-QJXFRP5R.cjs.map +1 -0
- package/dist/chunk-QRCMKEE6.js +173 -0
- package/dist/chunk-QRCMKEE6.js.map +1 -0
- package/dist/chunk-T4IJHRRD.cjs +71 -0
- package/dist/chunk-T4IJHRRD.cjs.map +1 -0
- package/dist/chunk-ULU5LEWF.cjs +2460 -0
- package/dist/chunk-ULU5LEWF.cjs.map +1 -0
- package/dist/{chunk-TQ6FRVAH.js → chunk-V4CXOPLB.js} +3 -3
- package/dist/{chunk-TQ6FRVAH.js.map → chunk-V4CXOPLB.js.map} +1 -1
- package/dist/chunk-VOFNX4P6.cjs +50 -0
- package/dist/chunk-VOFNX4P6.cjs.map +1 -0
- package/dist/{chunk-J4MX2W4H.js → chunk-WBYNKFUO.js} +6 -3
- package/dist/chunk-WBYNKFUO.js.map +1 -0
- package/dist/chunk-WUTL62MC.js +42 -0
- package/dist/chunk-WUTL62MC.js.map +1 -0
- package/dist/{chunk-JPGV7NMY.js → chunk-YXSXGTYQ.js} +4 -173
- package/dist/chunk-YXSXGTYQ.js.map +1 -0
- package/dist/chunk-Z3LLUO32.cjs +177 -0
- package/dist/chunk-Z3LLUO32.cjs.map +1 -0
- package/dist/chunk-ZJMUNGOY.js +1088 -0
- package/dist/chunk-ZJMUNGOY.js.map +1 -0
- package/dist/document-tools/index.cjs +898 -0
- package/dist/document-tools/index.cjs.map +1 -0
- package/dist/document-tools/index.d.cts +522 -0
- package/dist/document-tools/index.d.ts +522 -0
- package/dist/document-tools/index.js +837 -0
- package/dist/document-tools/index.js.map +1 -0
- package/dist/index.cjs +365 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/ui/index.cjs +132 -131
- package/dist/ui/index.js +3 -2
- package/dist/viewers/index.cjs +2 -2
- package/dist/viewers/index.js +1 -1
- package/package.json +11 -3
- package/dist/chunk-43AKLNBC.js.map +0 -1
- package/dist/chunk-J4MX2W4H.js.map +0 -1
- package/dist/chunk-JPGV7NMY.js.map +0 -1
- package/dist/chunk-NA3FOYSF.cjs.map +0 -1
- package/dist/chunk-PATLJSAO.cjs.map +0 -1
- package/dist/chunk-PFKLOVGQ.js.map +0 -1
- package/dist/chunk-Z3RRZ3KV.cjs.map +0 -1
- package/dist/chunk-ZMTLGO3K.cjs.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var chunkZMTLGO3K_cjs = require('./chunk-ZMTLGO3K.cjs');
|
|
3
|
+
var chunkIIT7DMQL_cjs = require('./chunk-IIT7DMQL.cjs');
|
|
5
4
|
var react = require('react');
|
|
6
5
|
var reactQuery = require('@tanstack/react-query');
|
|
7
6
|
|
|
@@ -59,7 +58,7 @@ var arbiQueryKeys = {
|
|
|
59
58
|
userSettings: () => ["arbi", "userSettings"]
|
|
60
59
|
};
|
|
61
60
|
function useWorkspaceUsers(workspaceId, options) {
|
|
62
|
-
const arbi =
|
|
61
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
63
62
|
return reactQuery.useQuery({
|
|
64
63
|
queryKey: arbiQueryKeys.workspaceUsers(workspaceId ?? ""),
|
|
65
64
|
enabled: !!workspaceId && (options?.enabled ?? arbi.hasWorkspace),
|
|
@@ -72,7 +71,7 @@ function useWorkspaceUsers(workspaceId, options) {
|
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
73
|
function useWorkspaces(options) {
|
|
75
|
-
const arbi =
|
|
74
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
76
75
|
return reactQuery.useQuery({
|
|
77
76
|
queryKey: arbiQueryKeys.workspaces(),
|
|
78
77
|
queryFn: () => arbi.workspaces.list(),
|
|
@@ -80,7 +79,7 @@ function useWorkspaces(options) {
|
|
|
80
79
|
});
|
|
81
80
|
}
|
|
82
81
|
function useDocuments(workspaceId, options) {
|
|
83
|
-
const arbi =
|
|
82
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
84
83
|
return reactQuery.useQuery({
|
|
85
84
|
queryKey: arbiQueryKeys.documents(workspaceId ?? ""),
|
|
86
85
|
queryFn: () => arbi.documents.list(),
|
|
@@ -88,7 +87,7 @@ function useDocuments(workspaceId, options) {
|
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
89
|
function useDocumentVersionList(docId, options) {
|
|
91
|
-
const arbi =
|
|
90
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
92
91
|
return reactQuery.useQuery({
|
|
93
92
|
queryKey: arbiQueryKeys.documentVersions(docId ?? ""),
|
|
94
93
|
queryFn: () => arbi.documents.versions(docId),
|
|
@@ -96,7 +95,7 @@ function useDocumentVersionList(docId, options) {
|
|
|
96
95
|
});
|
|
97
96
|
}
|
|
98
97
|
function useConversations(workspaceId, options) {
|
|
99
|
-
const arbi =
|
|
98
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
100
99
|
return reactQuery.useQuery({
|
|
101
100
|
queryKey: arbiQueryKeys.conversations(workspaceId ?? ""),
|
|
102
101
|
queryFn: () => arbi.conversations.list(),
|
|
@@ -105,7 +104,7 @@ function useConversations(workspaceId, options) {
|
|
|
105
104
|
});
|
|
106
105
|
}
|
|
107
106
|
function useConversationThreads(workspaceId, conversationId, options) {
|
|
108
|
-
const arbi =
|
|
107
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
109
108
|
return reactQuery.useQuery({
|
|
110
109
|
queryKey: arbiQueryKeys.conversationThreads(workspaceId ?? "", conversationId ?? ""),
|
|
111
110
|
queryFn: () => arbi.conversations.getThreads(conversationId),
|
|
@@ -115,7 +114,7 @@ function useConversationThreads(workspaceId, conversationId, options) {
|
|
|
115
114
|
});
|
|
116
115
|
}
|
|
117
116
|
function useTags(workspaceId, options) {
|
|
118
|
-
const arbi =
|
|
117
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
119
118
|
return reactQuery.useQuery({
|
|
120
119
|
queryKey: arbiQueryKeys.tags(workspaceId ?? ""),
|
|
121
120
|
queryFn: () => arbi.tags.list(),
|
|
@@ -123,7 +122,7 @@ function useTags(workspaceId, options) {
|
|
|
123
122
|
});
|
|
124
123
|
}
|
|
125
124
|
function useThumbnails(docIds, options) {
|
|
126
|
-
const arbi =
|
|
125
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
127
126
|
return reactQuery.useQuery({
|
|
128
127
|
queryKey: arbiQueryKeys.thumbnails(docIds),
|
|
129
128
|
queryFn: () => arbi.documents.getThumbnails(docIds),
|
|
@@ -132,7 +131,7 @@ function useThumbnails(docIds, options) {
|
|
|
132
131
|
});
|
|
133
132
|
}
|
|
134
133
|
function useParsedDocument(docId, stage = "final", options) {
|
|
135
|
-
const arbi =
|
|
134
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
136
135
|
return reactQuery.useQuery({
|
|
137
136
|
queryKey: arbiQueryKeys.parsedDoc(docId ?? "", stage),
|
|
138
137
|
queryFn: () => arbi.documents.getParsedContent(docId, stage),
|
|
@@ -140,13 +139,13 @@ function useParsedDocument(docId, stage = "final", options) {
|
|
|
140
139
|
});
|
|
141
140
|
}
|
|
142
141
|
function useAssistantQuery() {
|
|
143
|
-
const arbi =
|
|
142
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
144
143
|
return reactQuery.useMutation({
|
|
145
144
|
mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options)
|
|
146
145
|
});
|
|
147
146
|
}
|
|
148
147
|
function useAgents(options) {
|
|
149
|
-
const arbi =
|
|
148
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
150
149
|
return reactQuery.useQuery({
|
|
151
150
|
queryKey: arbiQueryKeys.agents(),
|
|
152
151
|
queryFn: () => arbi.agents.list(),
|
|
@@ -154,7 +153,7 @@ function useAgents(options) {
|
|
|
154
153
|
});
|
|
155
154
|
}
|
|
156
155
|
function useDeleteAgents() {
|
|
157
|
-
const arbi =
|
|
156
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
158
157
|
const qc = reactQuery.useQueryClient();
|
|
159
158
|
return reactQuery.useMutation({
|
|
160
159
|
mutationFn: ({ agentExtIds }) => arbi.agents.delete(agentExtIds),
|
|
@@ -173,7 +172,7 @@ function useDeleteAgents() {
|
|
|
173
172
|
});
|
|
174
173
|
}
|
|
175
174
|
function useSessions(options) {
|
|
176
|
-
const arbi =
|
|
175
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
177
176
|
return reactQuery.useQuery({
|
|
178
177
|
queryKey: arbiQueryKeys.sessions(),
|
|
179
178
|
queryFn: () => arbi.sessions.list(),
|
|
@@ -181,7 +180,7 @@ function useSessions(options) {
|
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
182
|
function useHealth(options) {
|
|
184
|
-
const arbi =
|
|
183
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
185
184
|
return reactQuery.useQuery({
|
|
186
185
|
queryKey: arbiQueryKeys.health(),
|
|
187
186
|
queryFn: () => arbi.health.check(),
|
|
@@ -189,7 +188,7 @@ function useHealth(options) {
|
|
|
189
188
|
});
|
|
190
189
|
}
|
|
191
190
|
function useFacts(workspaceId, options) {
|
|
192
|
-
const arbi =
|
|
191
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
193
192
|
return reactQuery.useQuery({
|
|
194
193
|
queryKey: arbiQueryKeys.facts(workspaceId ?? ""),
|
|
195
194
|
queryFn: () => arbi.facts.list(),
|
|
@@ -197,7 +196,7 @@ function useFacts(workspaceId, options) {
|
|
|
197
196
|
});
|
|
198
197
|
}
|
|
199
198
|
function useConfigs(options) {
|
|
200
|
-
const arbi =
|
|
199
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
201
200
|
return reactQuery.useQuery({
|
|
202
201
|
queryKey: arbiQueryKeys.configs(),
|
|
203
202
|
queryFn: () => arbi.agentConfig.list(),
|
|
@@ -205,7 +204,7 @@ function useConfigs(options) {
|
|
|
205
204
|
});
|
|
206
205
|
}
|
|
207
206
|
function useActivity(options) {
|
|
208
|
-
const arbi =
|
|
207
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
209
208
|
return reactQuery.useQuery({
|
|
210
209
|
queryKey: arbiQueryKeys.activity(),
|
|
211
210
|
queryFn: () => arbi.dm.listActivity({ limit: options?.limit, offset: options?.offset }),
|
|
@@ -213,7 +212,7 @@ function useActivity(options) {
|
|
|
213
212
|
});
|
|
214
213
|
}
|
|
215
214
|
function useProjects(options) {
|
|
216
|
-
const arbi =
|
|
215
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
217
216
|
return reactQuery.useQuery({
|
|
218
217
|
queryKey: arbiQueryKeys.projects(),
|
|
219
218
|
queryFn: () => arbi.projects.list(),
|
|
@@ -221,7 +220,7 @@ function useProjects(options) {
|
|
|
221
220
|
});
|
|
222
221
|
}
|
|
223
222
|
function useProjectUsage(projectExtId, monthsBack = 0, options) {
|
|
224
|
-
const arbi =
|
|
223
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
225
224
|
const usage = reactQuery.useQuery({
|
|
226
225
|
queryKey: arbiQueryKeys.projectUsage(projectExtId ?? "", monthsBack),
|
|
227
226
|
queryFn: () => arbi.projects.usage(projectExtId, monthsBack),
|
|
@@ -233,7 +232,7 @@ function useProjectUsage(projectExtId, monthsBack = 0, options) {
|
|
|
233
232
|
return { ...usage, metered };
|
|
234
233
|
}
|
|
235
234
|
function useProjectsUsage(projectExtIds, monthsBack = 0, options) {
|
|
236
|
-
const arbi =
|
|
235
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
237
236
|
const enabled = (options?.enabled ?? true) && arbi.isLoggedIn;
|
|
238
237
|
const projects = useProjects({ enabled: enabled && projectExtIds.length > 0 });
|
|
239
238
|
const results = reactQuery.useQueries({
|
|
@@ -307,7 +306,7 @@ function useProjectsUsage(projectExtIds, monthsBack = 0, options) {
|
|
|
307
306
|
}, [signature]);
|
|
308
307
|
}
|
|
309
308
|
function useProjectInvoices(projectExtId, options) {
|
|
310
|
-
const arbi =
|
|
309
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
311
310
|
return reactQuery.useQuery({
|
|
312
311
|
queryKey: arbiQueryKeys.projectInvoices(projectExtId ?? ""),
|
|
313
312
|
queryFn: () => arbi.projects.invoices(projectExtId),
|
|
@@ -315,7 +314,7 @@ function useProjectInvoices(projectExtId, options) {
|
|
|
315
314
|
});
|
|
316
315
|
}
|
|
317
316
|
function useUserUsageToday(options) {
|
|
318
|
-
const arbi =
|
|
317
|
+
const arbi = chunkIIT7DMQL_cjs.useArbi();
|
|
319
318
|
return reactQuery.useQuery({
|
|
320
319
|
queryKey: arbiQueryKeys.userUsageToday(),
|
|
321
320
|
queryFn: () => arbi.user.usageToday(),
|
|
@@ -323,248 +322,11 @@ function useUserUsageToday(options) {
|
|
|
323
322
|
});
|
|
324
323
|
}
|
|
325
324
|
|
|
326
|
-
// src/ai/stored-markdown.ts
|
|
327
|
-
var FENCE = /^\s*(```|~~~)/;
|
|
328
|
-
function mapOutsideFences(text, fn) {
|
|
329
|
-
let inFence = false;
|
|
330
|
-
return text.split("\n").map((line) => {
|
|
331
|
-
if (FENCE.test(line)) {
|
|
332
|
-
inFence = !inFence;
|
|
333
|
-
return line;
|
|
334
|
-
}
|
|
335
|
-
return inFence ? line : fn(line);
|
|
336
|
-
}).join("\n");
|
|
337
|
-
}
|
|
338
|
-
var ESCAPED_PUNCTUATION = /\\([\\`*_{}[\]()#+\-.!|>~<])/g;
|
|
339
|
-
var ESCAPED_EMPHASIS = /\\([*_])/g;
|
|
340
|
-
var INLINE_CODE = /(`+)(?!`)(.+?)(?<!`)\1(?!`)/g;
|
|
341
|
-
function unescapeMarkdown(text) {
|
|
342
|
-
if (!text.includes("\\")) return text;
|
|
343
|
-
return mapOutsideFences(text, (line) => {
|
|
344
|
-
if (!line.includes("\\")) return line;
|
|
345
|
-
let out = "";
|
|
346
|
-
let last = 0;
|
|
347
|
-
for (const span of line.matchAll(INLINE_CODE)) {
|
|
348
|
-
const at = span.index ?? 0;
|
|
349
|
-
out += line.slice(last, at).replace(ESCAPED_PUNCTUATION, "$1") + span[0].replace(ESCAPED_EMPHASIS, "$1");
|
|
350
|
-
last = at + span[0].length;
|
|
351
|
-
}
|
|
352
|
-
return out + line.slice(last).replace(ESCAPED_PUNCTUATION, "$1");
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
function repairParsedTitle(text) {
|
|
356
|
-
const lines = text.split("\n");
|
|
357
|
-
const first = lines.findIndex((l) => l.trim());
|
|
358
|
-
if (first < 0) return text;
|
|
359
|
-
const doubled = /^#{1,6}\s+(#{1,6}\s+\S.*)$/.exec(lines[first]);
|
|
360
|
-
if (doubled) {
|
|
361
|
-
lines[first] = doubled[1];
|
|
362
|
-
return lines.join("\n");
|
|
363
|
-
}
|
|
364
|
-
if (/^\s*```\s*$/.test(lines[first]) && /^#{1,6}\s+\S/.test(lines[first + 1] ?? "")) {
|
|
365
|
-
if (/^\s*```\s*$/.test(lines[first + 2] ?? "")) lines.splice(first + 2, 1);
|
|
366
|
-
else return text;
|
|
367
|
-
lines.splice(first, 1);
|
|
368
|
-
return lines.join("\n");
|
|
369
|
-
}
|
|
370
|
-
return text;
|
|
371
|
-
}
|
|
372
|
-
var DOUBLED_HEADING = /^#{1,6}\s+(#{1,6}\s+\S.*)$/;
|
|
373
|
-
var LIST_HEADING = /^[-*+]\s+(#{1,6}\s+\S.*)$/;
|
|
374
|
-
var LIST_IN_LIST = /^[-*+]\s+[-*+]\s+(\S.*)$/;
|
|
375
|
-
var LIST_ORDINAL = /^[-*+]\s+(\d{1,9})([.)])\s+(\S.*)$/;
|
|
376
|
-
var LIST_ITEM_LINE = /^\s*(?:[-*+]|\d{1,9}[.)])\s/;
|
|
377
|
-
var TABLE_DELIMITER_CELL = /^:?-{1,}:?$/;
|
|
378
|
-
function splitRunOfOrdinals(first, delimiter, rest) {
|
|
379
|
-
const items = [];
|
|
380
|
-
let n = first;
|
|
381
|
-
let remaining = rest;
|
|
382
|
-
for (; ; ) {
|
|
383
|
-
const next = new RegExp(`^(.+?)\\s+${n + 1}\\${delimiter}\\s+(\\S.*)$`).exec(remaining);
|
|
384
|
-
if (!next) break;
|
|
385
|
-
items.push(`${n}${delimiter} ${next[1]}`);
|
|
386
|
-
n += 1;
|
|
387
|
-
remaining = next[2];
|
|
388
|
-
}
|
|
389
|
-
items.push(`${n}${delimiter} ${remaining}`);
|
|
390
|
-
return items;
|
|
391
|
-
}
|
|
392
|
-
function rebuildFlatTable(line) {
|
|
393
|
-
const trimmed = line.trim();
|
|
394
|
-
if (!trimmed.startsWith("|") || !trimmed.endsWith("|")) return null;
|
|
395
|
-
const cells = trimmed.slice(1, -1).split("|").map((c) => c.trim());
|
|
396
|
-
const firstRule = cells.findIndex((c) => TABLE_DELIMITER_CELL.test(c));
|
|
397
|
-
if (firstRule < 2 || cells[firstRule - 1] !== "") return null;
|
|
398
|
-
const columns = firstRule - 1;
|
|
399
|
-
const rows = [];
|
|
400
|
-
for (let at = 0; at < cells.length; at += columns + 1) {
|
|
401
|
-
const row = cells.slice(at, at + columns);
|
|
402
|
-
const gap = cells[at + columns];
|
|
403
|
-
if (row.length !== columns || gap !== void 0 && gap !== "") return null;
|
|
404
|
-
rows.push(row);
|
|
405
|
-
}
|
|
406
|
-
const [header, rule, ...body] = rows;
|
|
407
|
-
if (!rule.every((c) => TABLE_DELIMITER_CELL.test(c))) return null;
|
|
408
|
-
const fmt = (row) => `| ${row.join(" | ")} |`;
|
|
409
|
-
return [fmt(header), fmt(rule.map(() => "---")), ...body.map(fmt)];
|
|
410
|
-
}
|
|
411
|
-
function repairParsedStructure(text) {
|
|
412
|
-
const out = [];
|
|
413
|
-
let inFence = false;
|
|
414
|
-
for (const line of text.split("\n")) {
|
|
415
|
-
if (FENCE.test(line)) {
|
|
416
|
-
inFence = !inFence;
|
|
417
|
-
out.push(line);
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
if (inFence) {
|
|
421
|
-
out.push(line);
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
const table = rebuildFlatTable(line);
|
|
425
|
-
if (table) {
|
|
426
|
-
out.push(...table);
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
const heading = DOUBLED_HEADING.exec(line) ?? LIST_HEADING.exec(line);
|
|
430
|
-
if (heading) {
|
|
431
|
-
out.push(heading[1]);
|
|
432
|
-
continue;
|
|
433
|
-
}
|
|
434
|
-
const ordinal = LIST_ORDINAL.exec(line);
|
|
435
|
-
if (ordinal) {
|
|
436
|
-
out.push(...splitRunOfOrdinals(Number(ordinal[1]), ordinal[2], ordinal[3]));
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
const nested = LIST_IN_LIST.exec(line);
|
|
440
|
-
out.push(nested ? `- ${nested[1]}` : line);
|
|
441
|
-
}
|
|
442
|
-
return out.filter(
|
|
443
|
-
(line, i) => !(line === "" && LIST_ITEM_LINE.test(out[i - 1] ?? "") && LIST_ITEM_LINE.test(out[i + 1] ?? ""))
|
|
444
|
-
).join("\n");
|
|
445
|
-
}
|
|
446
|
-
var SOURCE_NOTE = /[ \t]*(?:\*+\(\s*Sources?\s*:[^)\n]*\)\*+|\(\s*\*{0,2}\s*Sources?\s*:[^)\n]*\))/gi;
|
|
447
|
-
var CITE_TOKEN = /^\]\(#cite-[\w-]+\)/;
|
|
448
|
-
function removeCitationLinks(line) {
|
|
449
|
-
if (!line.includes("](#cite-")) return line;
|
|
450
|
-
const drop = /* @__PURE__ */ new Set();
|
|
451
|
-
const open = [];
|
|
452
|
-
for (let i = 0; i < line.length; i++) {
|
|
453
|
-
const c = line[i];
|
|
454
|
-
if (c === "[") open.push(i);
|
|
455
|
-
else if (c === "]") {
|
|
456
|
-
const token = CITE_TOKEN.exec(line.slice(i, i + 40));
|
|
457
|
-
if (token) {
|
|
458
|
-
const opener = open.pop();
|
|
459
|
-
if (opener !== void 0) drop.add(opener);
|
|
460
|
-
for (let k = i; k < i + token[0].length; k++) drop.add(k);
|
|
461
|
-
i += token[0].length - 1;
|
|
462
|
-
} else open.pop();
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
let out = "";
|
|
466
|
-
for (let i = 0; i < line.length; i++) if (!drop.has(i)) out += line[i];
|
|
467
|
-
return out;
|
|
468
|
-
}
|
|
469
|
-
function balanceBold(line) {
|
|
470
|
-
if (/^\s*\*\*#{1,6}\s/.test(line)) return line.replace(/\*\*/g, "").trim();
|
|
471
|
-
if ((line.match(/\*\*/g)?.length ?? 0) % 2 === 0) return line;
|
|
472
|
-
if (/^#{1,6}\s/.test(line)) return line.replace(/\*\*/g, "");
|
|
473
|
-
return line.replace(/\*\*\s*$/, "").replace(/^(\s*(?:[-*]\s+)?)\*\*(?=\s)/, "$1");
|
|
474
|
-
}
|
|
475
|
-
function unwrapCitationLinks(text) {
|
|
476
|
-
const withoutNotes = mapOutsideFences(text, (line) => line.replace(SOURCE_NOTE, ""));
|
|
477
|
-
return mapOutsideFences(chunkNA3FOYSF_cjs.normalizeCitationMarkup(withoutNotes), (line) => {
|
|
478
|
-
const unlinked = removeCitationLinks(line);
|
|
479
|
-
return unlinked === line ? line : balanceBold(unlinked);
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
var HEADING = /^#{1,6}\s+\S/;
|
|
483
|
-
var HR_ONLY = /^\s*(?:-{3,}|\*{3,}|_{3,})\s*$/;
|
|
484
|
-
var BOLD_LINE = /^\*\*[^*#].*\*\*$/;
|
|
485
|
-
var MAX_PREAMBLE_CHARS = 900;
|
|
486
|
-
var MAX_PREAMBLE_PARAGRAPHS = 4;
|
|
487
|
-
var MAX_TITLE_CHARS = 100;
|
|
488
|
-
var NARRATION_OPENER = /^(?:I(?:['’](?:ll|ve|m|d))?\s|let me\b|here(?:['’]s| is| are)\b|below is\b|sure[,.! ]|certainly[,.! ]|of course[,.! ]|okay[,.! ]|based on (?:the|your|my)\b|per the (?:user|instructions?)|as requested\b|the workspace\b|no (?:relevant |workspace |matching )?documents?\b|there (?:are|is) no (?:relevant |workspace )?documents?\b|after (?:reviewing|reading|searching)\b)/i;
|
|
489
|
-
var STRUCTURED = /^\s*(?:[-*+>|]|\d{1,9}[.)]\s|#{1,6}\s|```|~~~)|\*\*|\]\(/m;
|
|
490
|
-
function stripAgentPreamble(text) {
|
|
491
|
-
const lines = text.split("\n");
|
|
492
|
-
const start = lines.findIndex((l) => HEADING.test(l));
|
|
493
|
-
if (start <= 0) return text;
|
|
494
|
-
const before = lines.slice(0, start).filter((l) => !HR_ONLY.test(l)).join("\n").trim();
|
|
495
|
-
if (!before) return lines.slice(start).join("\n");
|
|
496
|
-
const paragraphs = before.split(/\n\s*\n/).map((p) => p.trim());
|
|
497
|
-
const narration = before.length <= MAX_PREAMBLE_CHARS && paragraphs.length <= MAX_PREAMBLE_PARAGRAPHS && !STRUCTURED.test(before) && paragraphs.every((p) => NARRATION_OPENER.test(p));
|
|
498
|
-
return narration ? lines.slice(start).join("\n") : text;
|
|
499
|
-
}
|
|
500
|
-
function promoteBoldTitle(text) {
|
|
501
|
-
const lines = text.split("\n");
|
|
502
|
-
const first = lines.findIndex((l) => l.trim());
|
|
503
|
-
if (first < 0) return text;
|
|
504
|
-
const line = lines[first].trim();
|
|
505
|
-
if (!BOLD_LINE.test(line)) return text;
|
|
506
|
-
const title = line.replace(/\*\*/g, "").trim();
|
|
507
|
-
if (title.length === 0 || title.length > MAX_TITLE_CHARS || !/^[\p{Lu}\d]/u.test(title) || /[,;:]$/.test(title) || /[.!?]\s+\S/.test(title)) {
|
|
508
|
-
return text;
|
|
509
|
-
}
|
|
510
|
-
lines[first] = `# ${title}`;
|
|
511
|
-
return lines.join("\n");
|
|
512
|
-
}
|
|
513
|
-
function cleanHeadings(text) {
|
|
514
|
-
return mapOutsideFences(
|
|
515
|
-
text,
|
|
516
|
-
(line) => /^\s*#{1,6}\s/.test(line) ? line.replace(/\*\*/g, "").trim() : line
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
var MIN_RATIO = 0.7;
|
|
520
|
-
var countMatches = (text, re) => text.match(re)?.length ?? 0;
|
|
521
|
-
var LIST_NUMBER = /^\s*\d{1,9}[.)]\s/gm;
|
|
522
|
-
var HEADING_LINE = /^#{1,6}\s/gm;
|
|
523
|
-
var withoutCitationMarkup = (raw) => mapOutsideFences(raw.replace(SOURCE_NOTE, ""), removeCitationLinks).trim();
|
|
524
|
-
var tidy = (text) => text.replace(/\n{3,}/g, "\n\n").trim();
|
|
525
|
-
var isPrefixCut = (before, after) => before.trimEnd().endsWith(after.trim());
|
|
526
|
-
var keepsStructure = (candidate, reference) => countMatches(candidate, LIST_NUMBER) >= countMatches(reference, LIST_NUMBER) && countMatches(candidate, HEADING_LINE) >= countMatches(reference, HEADING_LINE);
|
|
527
|
-
var DEFAULT_CLEAN_STEPS = {
|
|
528
|
-
unwrap: unwrapCitationLinks,
|
|
529
|
-
strip: stripAgentPreamble,
|
|
530
|
-
promote: promoteBoldTitle
|
|
531
|
-
};
|
|
532
|
-
function cleanDraftWithReport(raw, steps = DEFAULT_CLEAN_STEPS) {
|
|
533
|
-
const floor = withoutCitationMarkup(raw);
|
|
534
|
-
const ratio = (t) => floor.length ? t.length / floor.length : 1;
|
|
535
|
-
const unwrapped = tidy(steps.unwrap(raw));
|
|
536
|
-
const stripped = tidy(steps.strip(unwrapped));
|
|
537
|
-
const titled = tidy(cleanHeadings(steps.promote(stripped)));
|
|
538
|
-
const changedBy = [];
|
|
539
|
-
if (unwrapped !== raw.trim()) changedBy.push("citations");
|
|
540
|
-
if (stripped !== unwrapped) changedBy.push("preamble");
|
|
541
|
-
if (titled !== stripped) changedBy.push("title");
|
|
542
|
-
const unwrappedOk = unwrapped.length >= MIN_RATIO * floor.length && keepsStructure(unwrapped, raw);
|
|
543
|
-
if (!unwrappedOk) return { text: raw, stage: "raw", ratio: 1, changedBy, guarded: true };
|
|
544
|
-
const strippedOk = stripped === unwrapped || isPrefixCut(unwrapped, stripped) && keepsStructure(stripped, unwrapped);
|
|
545
|
-
const titledOk = titled.length >= MIN_RATIO * stripped.length && keepsStructure(titled, stripped);
|
|
546
|
-
if (strippedOk && titledOk) {
|
|
547
|
-
return { text: titled, stage: "cleaned", ratio: ratio(titled), changedBy, guarded: false };
|
|
548
|
-
}
|
|
549
|
-
return { text: unwrapped, stage: "unwrapped", ratio: ratio(unwrapped), changedBy, guarded: true };
|
|
550
|
-
}
|
|
551
|
-
function cleanDraftMarkdown(raw) {
|
|
552
|
-
return cleanDraftWithReport(raw).text;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
325
|
exports.DEFAULT_USD_PER_CREDIT = DEFAULT_USD_PER_CREDIT;
|
|
556
326
|
exports.arbiQueryKeys = arbiQueryKeys;
|
|
557
|
-
exports.cleanDraftMarkdown = cleanDraftMarkdown;
|
|
558
|
-
exports.cleanDraftWithReport = cleanDraftWithReport;
|
|
559
327
|
exports.creditsToUsd = creditsToUsd;
|
|
560
328
|
exports.formatCredits = formatCredits;
|
|
561
329
|
exports.isUsageMetered = isUsageMetered;
|
|
562
|
-
exports.promoteBoldTitle = promoteBoldTitle;
|
|
563
|
-
exports.repairParsedStructure = repairParsedStructure;
|
|
564
|
-
exports.repairParsedTitle = repairParsedTitle;
|
|
565
|
-
exports.stripAgentPreamble = stripAgentPreamble;
|
|
566
|
-
exports.unescapeMarkdown = unescapeMarkdown;
|
|
567
|
-
exports.unwrapCitationLinks = unwrapCitationLinks;
|
|
568
330
|
exports.useActivity = useActivity;
|
|
569
331
|
exports.useAgents = useAgents;
|
|
570
332
|
exports.useAssistantQuery = useAssistantQuery;
|
|
@@ -587,5 +349,5 @@ exports.useThumbnails = useThumbnails;
|
|
|
587
349
|
exports.useUserUsageToday = useUserUsageToday;
|
|
588
350
|
exports.useWorkspaceUsers = useWorkspaceUsers;
|
|
589
351
|
exports.useWorkspaces = useWorkspaces;
|
|
590
|
-
//# sourceMappingURL=chunk-
|
|
591
|
-
//# sourceMappingURL=chunk-
|
|
352
|
+
//# sourceMappingURL=chunk-6TFD5OS5.cjs.map
|
|
353
|
+
//# sourceMappingURL=chunk-6TFD5OS5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/credits.ts","../src/hooks.ts"],"names":["useArbi","useQuery","useMutation","useQueryClient","useQueries","useMemo"],"mappings":";;;;;;;AAYO,IAAM,sBAAA,GAAyB;AAUtC,IAAM,kBAAA,GAAqB,GAAA;AAOpB,SAAS,aAAA,CAAc,OAAA,EAAiB,OAAA,GAAgC,EAAC,EAAW;AACzF,EAAA,MAAM,EAAE,IAAA,GAAO,IAAA,EAAM,MAAA,GAAS,SAAQ,GAAI,OAAA;AAC1C,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,QAAA,CAAS,OAAO,IAAI,OAAA,GAAU,CAAA;AAClD,EAAA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CAAc,eAAA,CAAgB,YAAA,IAAgB,EAAE,CAAA;AAAA,IAC1D,OAAA,EAAS,MAAM,IAAA,CAAK,QAAA,CAAS,SAAS,YAAsB,CAAA;AAAA,IAC5D,UAAU,OAAA,EAAS,OAAA,IAAW,SAAS,CAAC,CAAC,gBAAgB,IAAA,CAAK;AAAA,GAC/D,CAAA;AACH;AAGO,SAAS,kBAAkB,OAAA,EAAiC;AACjE,EAAA,MAAM,OAAOD,yBAAA,EAAQ;AACrB,EAAA,OAAOC,mBAAA,CAAS;AAAA,IACd,QAAA,EAAU,cAAc,cAAA,EAAe;AAAA,IACvC,OAAA,EAAS,MAAM,IAAA,CAAK,IAAA,CAAK,UAAA,EAAW;AAAA,IACpC,OAAA,EAAS,OAAA,EAAS,OAAA,IAAW,IAAA,CAAK;AAAA,GACnC,CAAA;AACH","file":"chunk-6TFD5OS5.cjs","sourcesContent":["/**\n * Credits: the unit the ARBI backend reports AI usage in.\n *\n * The usage endpoints (`/v1/user/projects/{id}/usage`, `/me/usage/today`) convert the metered USD\n * spend into credits at the API boundary (fractional, rounded to 2 decimals, because a small\n * deployment spends well under one credit a day): 1 credit = `CREDITS_TO_AI_USD`, which is $0.01 on\n * a default deployment. The fields are still named `spend` / `total_spend` in the schema, but they\n * hold CREDITS, never dollars. Label them as credits; use {@link creditsToUsd} only when a\n * dollar figure is genuinely wanted, with the deployment's own rate.\n */\n\n/** Dollars per credit on a default deployment (`CREDITS_TO_AI_USD`). */\nexport const DEFAULT_USD_PER_CREDIT = 0.01\n\nexport interface FormatCreditsOptions {\n /** Append the unit (\"12 credits\"). Default true; pass false inside a column headed \"Credits\". */\n unit?: boolean\n /** BCP 47 locale for the digit grouping. Default `en-US`. */\n locale?: string\n}\n\n/** Amounts at or above this show as whole credits; below it, up to 2 decimals. */\nconst WHOLE_CREDITS_FROM = 100\n\n/**\n * \"0.47 credits\" / \"1 credit\" / \"1.5 credits\" / \"1,235 credits\". The backend reports fractional\n * credits (2 decimals). Amounts under 100 keep up to 2 decimals with trailing zeros trimmed;\n * amounts of 100 and over round to whole credits. Only exactly 1 is singular.\n */\nexport function formatCredits(credits: number, options: FormatCreditsOptions = {}): string {\n const { unit = true, locale = 'en-US' } = options\n const safe = Number.isFinite(credits) ? credits : 0\n const rounded =\n Math.abs(safe) >= WHOLE_CREDITS_FROM ? Math.round(safe) : Math.round(safe * 100) / 100\n const digits = rounded.toLocaleString(locale, { maximumFractionDigits: 2 })\n return unit ? `${digits} ${rounded === 1 ? 'credit' : 'credits'}` : digits\n}\n\n/** The dollar value of an amount of credits. `usdPerCredit` defaults to {@link DEFAULT_USD_PER_CREDIT}. */\nexport function creditsToUsd(\n credits: number,\n usdPerCredit: number = DEFAULT_USD_PER_CREDIT\n): number {\n return credits * usdPerCredit\n}\n\n/** The slice of a usage response that tells whether anything was recorded. */\nexport interface UsageTotals {\n total_spend: number\n total_tokens: number\n total_requests: number\n}\n\n/**\n * Was this usage actually metered? A `dev`-plan project with an all-zero response (no spend, no\n * tokens, no requests) is treated as \"not metered\", so the UI shows a note instead of silent\n * zeros. Any recorded tokens or requests mean usage was metered, even when the spend rounds to 0\n * (the backend now records usage when billing is off, and a tiny spend can be 0.00 credits).\n */\nexport function isUsageMetered(\n usage: UsageTotals,\n subscription: string | null | undefined\n): boolean {\n const empty = usage.total_spend === 0 && usage.total_tokens === 0 && usage.total_requests === 0\n return !(empty && subscription === 'dev')\n}\n","/**\n * React Query hooks that use the Arbi instance from context.\n */\n\nimport { useMemo } from 'react'\nimport { useQuery, useQueries, useMutation, useQueryClient } from '@tanstack/react-query'\nimport type {\n SSEStreamResult,\n SSEStreamStartData,\n ResponseOutputItemDoneEvent,\n ArtifactEvent,\n UserMessageEvent,\n MessageMetadataPayload,\n QueryOptions,\n} from '@arbidocs/sdk/browser'\nimport { useArbi } from './useArbi'\nimport type { ParsedDocument } from './documents/parsed-types'\nimport { isUsageMetered } from './credits'\n\n// ── Query keys ──────────────────────────────────────────────────────────────\n\nexport const arbiQueryKeys = {\n workspaces: () => ['arbi', 'workspaces'] as const,\n workspaceUsers: (workspaceId: string) => ['arbi', 'workspaceUsers', workspaceId] as const,\n documents: (workspaceId: string) => ['arbi', 'documents', workspaceId] as const,\n /** Every version list: the prefix a new version invalidates. */\n allDocumentVersions: () => ['arbi', 'documentVersions'] as const,\n documentVersions: (docId: string) => ['arbi', 'documentVersions', docId] as const,\n conversations: (workspaceId: string) => ['arbi', 'conversations', workspaceId] as const,\n /** Every workspace's conversation list (and threads): the prefix a conversation write invalidates. */\n allConversations: () => ['arbi', 'conversations'] as const,\n conversationThreads: (workspaceId: string, conversationId: string) =>\n ['arbi', 'conversations', workspaceId, 'threads', conversationId] as const,\n tags: (workspaceId: string) => ['arbi', 'tags', workspaceId] as const,\n thumbnails: (docIds: string[]) => ['arbi', 'thumbnails', [...docIds].sort().join(',')] as const,\n parsedDoc: (docId: string, stage: string) => ['arbi', 'parsedDoc', docId, stage] as const,\n agents: () => ['arbi', 'agents'] as const,\n sessions: () => ['arbi', 'sessions'] as const,\n health: () => ['arbi', 'health'] as const,\n workflows: () => ['arbi', 'workflows'] as const,\n facts: (workspaceId: string) => ['arbi', 'facts', workspaceId] as const,\n configs: () => ['arbi', 'configs'] as const,\n activity: () => ['arbi', 'activity'] as const,\n projects: () => ['arbi', 'projects'] as const,\n projectUsage: (projectExtId: string, monthsBack: number) =>\n ['arbi', 'projectUsage', projectExtId, monthsBack] as const,\n projectInvoices: (projectExtId: string) => ['arbi', 'projectInvoices', projectExtId] as const,\n userUsageToday: () => ['arbi', 'userUsageToday'] as const,\n contacts: () => ['arbi', 'contacts'] as const,\n skills: () => ['arbi', 'skills'] as const,\n /** An agent's pinned config; `undefined` = the library default config. */\n agentConfig: (agentExtId?: string) => ['arbi', 'agentConfig', agentExtId ?? 'default'] as const,\n agentWorkspaces: (agentExtId: string) => ['arbi', 'agentWorkspaces', agentExtId] as const,\n models: () => ['arbi', 'models'] as const,\n /** The signed-in user's own profile (name, picture, email). */\n profile: () => ['arbi', 'profile'] as const,\n /** The signed-in user's settings record (notification preferences, flags). */\n userSettings: () => ['arbi', 'userSettings'] as const,\n}\n\n// ── Hooks ───────────────────────────────────────────────────────────────────\n\n/** Workspace people for mentions and ownership. */\nexport function useWorkspaceUsers(\n workspaceId: string | undefined,\n options?: {\n enabled?: boolean\n beforeFetch?: () => Promise<unknown>\n }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.workspaceUsers(workspaceId ?? ''),\n enabled: !!workspaceId && (options?.enabled ?? arbi.hasWorkspace),\n queryFn: async () => {\n await options?.beforeFetch?.()\n if (arbi.getWorkspaceId() !== workspaceId) throw new Error('The selected workspace changed.')\n return arbi.workspaces.listUsers()\n },\n refetchInterval: 30_000,\n })\n}\n\n/** List the logged-in user's workspaces. */\nexport function useWorkspaces(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.workspaces(),\n queryFn: () => arbi.workspaces.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/** List documents in a workspace. */\nexport function useDocuments(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.documents(workspaceId ?? ''),\n queryFn: () => arbi.documents.list(),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** Every version of the document `docId`, oldest first (`is_current` marks the current one). */\nexport function useDocumentVersionList(\n docId: string | null | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.documentVersions(docId ?? ''),\n queryFn: () => arbi.documents.versions(docId as string),\n enabled: (options?.enabled ?? true) && !!docId && arbi.hasWorkspace,\n })\n}\n\n/** List conversations in a workspace. */\nexport function useConversations(\n workspaceId: string | undefined,\n options?: { enabled?: boolean; live?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.conversations(workspaceId ?? ''),\n queryFn: () => arbi.conversations.list(),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n refetchInterval: options?.live\n ? (query) =>\n query.state.data?.some((conversation) => conversation.status === 'generating')\n ? 3000\n : 15000\n : false,\n })\n}\n\n/**\n * A conversation's stored threads (each with its message history, citations data included).\n * Always refetched on mount: a conversation that was open before may have new turns.\n */\nexport function useConversationThreads(\n workspaceId: string | undefined,\n conversationId: string | undefined,\n options?: { enabled?: boolean; live?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.conversationThreads(workspaceId ?? '', conversationId ?? ''),\n queryFn: () => arbi.conversations.getThreads(conversationId as string),\n enabled: (options?.enabled ?? true) && !!workspaceId && !!conversationId && arbi.hasWorkspace,\n gcTime: 0,\n refetchInterval: options?.live ? 3000 : false,\n })\n}\n\n/** List tags in a workspace. */\nexport function useTags(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.tags(workspaceId ?? ''),\n queryFn: () => arbi.tags.list(),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/**\n * Batch-fetch first-page thumbnails for a set of documents. Returns a map of\n * doc external id → `data:image/webp` URI (or `null` when no thumbnail exists).\n * Cached for a few minutes since thumbnails are effectively immutable per doc.\n */\nexport function useThumbnails(docIds: string[], options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.thumbnails(docIds),\n queryFn: () => arbi.documents.getThumbnails(docIds),\n enabled: (options?.enabled ?? true) && docIds.length > 0 && arbi.hasWorkspace,\n staleTime: 5 * 60_000,\n })\n}\n\n/**\n * Fetch a document's parsed content (chunks grouped by page) for the review\n * viewer. `stage` defaults to `final` (fully processed); `marker`/`subchunk`\n * expose earlier pipeline stages.\n */\nexport function useParsedDocument(\n docId: string | undefined,\n stage: string = 'final',\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.parsedDoc(docId ?? '', stage),\n queryFn: () =>\n arbi.documents.getParsedContent(docId as string, stage) as unknown as Promise<ParsedDocument>,\n enabled: (options?.enabled ?? true) && !!docId && arbi.hasWorkspace,\n })\n}\n\n/** Send a streaming query to the RAG assistant. Returns a mutation. */\nexport function useAssistantQuery() {\n const arbi = useArbi()\n\n return useMutation<\n SSEStreamResult,\n Error,\n {\n question: string\n agentId?: string\n workspaceId?: string\n activeArtifactExtId?: string\n docIds: string[]\n previousResponseId?: string | null\n conversationId?: string\n assistantMode?: QueryOptions['assistantMode']\n mentions?: QueryOptions['mentions']\n model?: string\n onToken?: (content: string) => void\n /** Aborts the request and the stream; the mutation then rejects with an `AbortError`. */\n signal?: AbortSignal\n onStreamStart?: (data: SSEStreamStartData) => void\n onUserMessage?: (data: UserMessageEvent) => void\n onMetadata?: (data: MessageMetadataPayload) => void\n onOutputItemDone?: (data: ResponseOutputItemDoneEvent) => void\n onArtifact?: (data: ArtifactEvent) => void\n onError?: (message: string) => void\n onComplete?: () => void\n }\n >({\n mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options),\n })\n}\n\n/** List agents owned by the current user. */\nexport function useAgents(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.agents(),\n queryFn: () => arbi.agents.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/**\n * Delete agents. Returns a mutation. Refreshes the agent list, the workflow list and the conversation list\n * (a deleted agent's workflows and work go with it), and drops the deleted agents' own config and workspace queries.\n */\nexport function useDeleteAgents() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation<unknown, Error, { agentExtIds: string[] }>({\n mutationFn: ({ agentExtIds }) => arbi.agents.delete(agentExtIds),\n onSuccess: (_result, { agentExtIds }) => {\n for (const id of agentExtIds) {\n qc.removeQueries({ queryKey: arbiQueryKeys.agentConfig(id) })\n qc.removeQueries({ queryKey: arbiQueryKeys.agentWorkspaces(id) })\n }\n return Promise.all([\n qc.invalidateQueries({ queryKey: arbiQueryKeys.agents() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.workflows() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.allConversations() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.configs() }),\n ])\n },\n })\n}\n\n/** List active sessions. */\nexport function useSessions(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.sessions(),\n queryFn: () => arbi.sessions.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/** Authorize a delegated session (generates claim code). Returns a mutation. */\n\n/** Check backend health. */\nexport function useHealth(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.health(),\n queryFn: () => arbi.health.check(),\n enabled: options?.enabled,\n })\n}\n\n// ── Workspace notes ──────────────────────────────────────────────────────────\n\n/** List the open workspace's facts. */\nexport function useFacts(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.facts(workspaceId ?? ''),\n queryFn: () => arbi.facts.list(),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n// ── Behaviour-template configs ───────────────────────────────────────────────\n\n/** List the caller's saved agent configurations (behaviour templates). */\nexport function useConfigs(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.configs(),\n queryFn: () => arbi.agentConfig.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n// ── Activity feed ─────────────────────────────────────────────────────────────\n\n/**\n * List the caller's durable activity feed, newest first.\n *\n * Activity entries are backend-originated, to-self log lines that are always\n * read — they are deliberately kept out of the normal notifications/DM feed and\n * never affect the unread badge, so this is a separate, opt-in query.\n */\nexport function useActivity(options?: { enabled?: boolean; limit?: number; offset?: number }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.activity(),\n queryFn: () => arbi.dm.listActivity({ limit: options?.limit, offset: options?.offset }),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n// ── Projects, usage & spend ───────────────────────────────────────────────────\n\n/** List the logged-in user's projects (billing accounts). */\nexport function useProjects(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.projects(),\n queryFn: () => arbi.projects.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/**\n * AI usage breakdown for a project's billing period. `monthsBack` selects the period (0 =\n * current, 1 = previous month, …).\n *\n * The response's `total_spend` / `spend` fields are CREDITS, not dollars (see `formatCredits`).\n * `metered` is `false` when the deployment does not record usage (a `dev`-plan project with all\n * zeros): show \"usage is not metered here\" instead of zeros. It is `undefined` until the usage\n * has loaded.\n */\nexport function useProjectUsage(\n projectExtId: string | undefined,\n monthsBack: number = 0,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n const usage = useQuery({\n queryKey: arbiQueryKeys.projectUsage(projectExtId ?? '', monthsBack),\n queryFn: () => arbi.projects.usage(projectExtId as string, monthsBack),\n enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn,\n })\n const projects = useProjects({ enabled: !!projectExtId && (options?.enabled ?? true) })\n const subscription = projects.data?.find((p) => p.external_id === projectExtId)?.subscription\n const metered = usage.data ? isUsageMetered(usage.data, subscription) : undefined\n return { ...usage, metered }\n}\n\n/** One day of aggregated usage across projects (for a spend/token trend). */\nexport interface AggregatedDailyUsage {\n date: string\n /** Credits used that day (not dollars). */\n credits: number\n totalTokens: number\n apiRequests: number\n}\n\n/** One model group's aggregated usage across projects (for a breakdown). */\nexport interface AggregatedModelGroupUsage {\n model: string\n /** Credits used by this model group (not dollars). */\n credits: number\n totalTokens: number\n promptTokens: number\n completionTokens: number\n successfulRequests: number\n}\n\n/** Aggregated AI usage + spend across several projects. */\nexport interface ProjectsUsageAggregate {\n /** Summed usage across the projects, in CREDITS (1 credit = $0.01 by default), not dollars. */\n totalCredits: number\n /** Summed token count across the projects. */\n totalTokens: number\n /** Summed API request count across the projects. */\n totalRequests: number\n /** Per-day totals merged across every project, oldest first. */\n daily: AggregatedDailyUsage[]\n /** Per-model-group totals merged across every project, most credits first. */\n modelGroups: AggregatedModelGroupUsage[]\n /**\n * False when none of the loaded projects records usage (billing is off on this deployment), so\n * zeros mean \"not metered\". True while anything real was recorded, or before data arrived.\n */\n metered: boolean\n /** True while any per-project query is still loading. */\n isLoading: boolean\n /** True if any per-project query errored. */\n isError: boolean\n}\n\n/**\n * Firm-wide AI usage + spend: aggregates {@link useProjectUsage} across several\n * projects (e.g. all of a firm's matters) in parallel and merges the real totals,\n * the daily trend, and the per-model breakdown. Shares the per-project query\n * cache, so it costs nothing extra where a project's usage is already loaded.\n * Numbers are genuine — zero projects (or zero billed work) yields zero totals;\n * callers render that honestly.\n */\nexport function useProjectsUsage(\n projectExtIds: string[],\n monthsBack: number = 0,\n options?: { enabled?: boolean }\n): ProjectsUsageAggregate {\n const arbi = useArbi()\n const enabled = (options?.enabled ?? true) && arbi.isLoggedIn\n const projects = useProjects({ enabled: enabled && projectExtIds.length > 0 })\n const results = useQueries({\n queries: projectExtIds.map((id) => ({\n queryKey: arbiQueryKeys.projectUsage(id, monthsBack),\n queryFn: () => arbi.projects.usage(id, monthsBack),\n enabled: enabled && !!id,\n })),\n })\n\n // Recompute only when a query's data actually changes (not on every parent\n // render — the dashboard re-renders often while a digest streams).\n const signature =\n results.map((r) => `${r.status}:${r.dataUpdatedAt ?? 0}`).join('|') +\n `#${projects.dataUpdatedAt}`\n\n return useMemo(() => {\n const dailyMap = new Map<string, AggregatedDailyUsage>()\n const modelMap = new Map<string, AggregatedModelGroupUsage>()\n let totalCredits = 0\n let anyData = false\n let anyMetered = false\n let totalTokens = 0\n let totalRequests = 0\n\n results.forEach((r, i) => {\n const d = r.data\n if (!d) return\n anyData = true\n const subscription = projects.data?.find(\n (p) => p.external_id === projectExtIds[i]\n )?.subscription\n if (isUsageMetered(d, subscription)) anyMetered = true\n totalCredits += d.total_spend ?? 0\n totalTokens += d.total_tokens ?? 0\n totalRequests += d.total_requests ?? 0\n\n for (const day of d.daily ?? []) {\n const cur = dailyMap.get(day.date) ?? {\n date: day.date,\n credits: 0,\n totalTokens: 0,\n apiRequests: 0,\n }\n cur.credits += day.spend ?? 0\n cur.totalTokens += day.total_tokens ?? 0\n cur.apiRequests += day.api_requests ?? 0\n dailyMap.set(day.date, cur)\n }\n\n for (const [model, mg] of Object.entries(d.model_groups ?? {})) {\n const cur = modelMap.get(model) ?? {\n model,\n credits: 0,\n totalTokens: 0,\n promptTokens: 0,\n completionTokens: 0,\n successfulRequests: 0,\n }\n cur.credits += mg.spend ?? 0\n cur.totalTokens += mg.total_tokens ?? 0\n cur.promptTokens += mg.prompt_tokens ?? 0\n cur.completionTokens += mg.completion_tokens ?? 0\n cur.successfulRequests += mg.successful_requests ?? 0\n modelMap.set(model, cur)\n }\n })\n\n return {\n totalCredits,\n totalTokens,\n totalRequests,\n daily: [...dailyMap.values()].sort((a, b) => a.date.localeCompare(b.date)),\n modelGroups: [...modelMap.values()].sort(\n (a, b) => b.credits - a.credits || b.totalTokens - a.totalTokens\n ),\n metered: !anyData || anyMetered,\n isLoading: results.some((r) => r.isLoading),\n isError: results.some((r) => r.isError),\n }\n }, [signature])\n}\n\n/** List the Stripe invoices for a project's subscription. */\nexport function useProjectInvoices(\n projectExtId: string | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.projectInvoices(projectExtId ?? ''),\n queryFn: () => arbi.projects.invoices(projectExtId as string),\n enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn,\n })\n}\n\n/** Today's deployment-wide credit use for the current user (`credits_used`, in credits). */\nexport function useUserUsageToday(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.userUsageToday(),\n queryFn: () => arbi.user.usageToday(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n"]}
|
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import remarkParse from 'remark-parse';
|
|
3
|
-
import remarkGfm from 'remark-gfm';
|
|
4
|
-
import remarkStringify from 'remark-stringify';
|
|
1
|
+
import { normalizeMarkdown } from './chunk-WUTL62MC.js';
|
|
5
2
|
import { diffLines, diffWords } from 'diff';
|
|
6
3
|
|
|
7
|
-
// src/artifacts/normalize-markdown.ts
|
|
8
|
-
var INTRAWORD_ESCAPED_UNDERSCORE = /(?<=[\p{L}\p{N}])\\_(?=[\p{L}\p{N}])/gu;
|
|
9
|
-
var processor = unified().use(remarkParse).use(remarkGfm, { tablePipeAlign: false }).use(remarkStringify, {
|
|
10
|
-
bullet: "-",
|
|
11
|
-
bulletOther: "*",
|
|
12
|
-
emphasis: "*",
|
|
13
|
-
strong: "*",
|
|
14
|
-
fence: "`",
|
|
15
|
-
fences: true,
|
|
16
|
-
rule: "-",
|
|
17
|
-
listItemIndent: "one",
|
|
18
|
-
incrementListMarker: true,
|
|
19
|
-
resourceLink: false,
|
|
20
|
-
handlers: {
|
|
21
|
-
text: (node, _parent, state, info) => state.safe(node.value, info).replace(INTRAWORD_ESCAPED_UNDERSCORE, "_")
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
var cache = /* @__PURE__ */ new Map();
|
|
25
|
-
var CACHE_LIMIT = 16;
|
|
26
|
-
function normalizeMarkdown(text) {
|
|
27
|
-
if (!text) return "";
|
|
28
|
-
const hit = cache.get(text);
|
|
29
|
-
if (hit !== void 0) return hit;
|
|
30
|
-
let out;
|
|
31
|
-
try {
|
|
32
|
-
out = String(processor.processSync(text.replace(/\r\n?/g, "\n"))).replace(/\n*$/, "\n");
|
|
33
|
-
} catch {
|
|
34
|
-
out = text.replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "");
|
|
35
|
-
}
|
|
36
|
-
if (cache.size >= CACHE_LIMIT) cache.delete(cache.keys().next().value);
|
|
37
|
-
cache.set(text, out);
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
4
|
var UNSAFE_LINE = /^(?:\s*(?:```|~~~).*|\s*\|.*\||\s*(?:[-=*_]\s*){3,})\s*$/;
|
|
41
5
|
var STRUCTURAL_PREFIX = /^(\s*(?:#{1,6}\s+|[-*+]\s+|\d+[.)]\s+|>\s*)+)/;
|
|
42
6
|
function escapeForHtmlTag(text) {
|
|
@@ -339,6 +303,6 @@ function revertRedlineRegion(rawBase, rawCompare, targetId) {
|
|
|
339
303
|
return matchTail(out.join(""), rawCompare);
|
|
340
304
|
}
|
|
341
305
|
|
|
342
|
-
export { buildHybridRedlineMarkdown, buildHybridRedlineWithRegions,
|
|
343
|
-
//# sourceMappingURL=chunk-
|
|
344
|
-
//# sourceMappingURL=chunk-
|
|
306
|
+
export { buildHybridRedlineMarkdown, buildHybridRedlineWithRegions, revertRedlineRegion };
|
|
307
|
+
//# sourceMappingURL=chunk-74N436VK.js.map
|
|
308
|
+
//# sourceMappingURL=chunk-74N436VK.js.map
|