@arbidocs/sdk 0.3.47 → 0.3.49
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/{browser-CtYFcHNd.d.cts → browser-BJdLTFSM.d.cts} +58 -15
- package/dist/{browser-CtYFcHNd.d.ts → browser-BJdLTFSM.d.ts} +58 -15
- package/dist/browser.cjs +130 -29
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +130 -30
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +130 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +130 -76
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-
|
|
2
|
-
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-
|
|
1
|
+
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-BJdLTFSM.cjs';
|
|
2
|
+
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-BJdLTFSM.cjs';
|
|
3
3
|
import { SessionStorageProvider, ArbiClient, components } from '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -168,8 +168,11 @@ interface UploadDirectoryOptions {
|
|
|
168
168
|
/**
|
|
169
169
|
* Upload a local file by path. Handles readFileSync + basename + Blob + uploadFile.
|
|
170
170
|
* Convenience wrapper for CLI/TUI consumers that work with file system paths.
|
|
171
|
+
*
|
|
172
|
+
* Workspace context is derived server-side from the open session (the caller's
|
|
173
|
+
* JWT + most recent ``/workspace/{id}/open`` call), so no workspace id is sent.
|
|
171
174
|
*/
|
|
172
|
-
declare function uploadLocalFile(auth: AuthHeaders,
|
|
175
|
+
declare function uploadLocalFile(auth: AuthHeaders, filePath: string, options?: UploadOptions): Promise<UploadResult & {
|
|
173
176
|
fileName: string;
|
|
174
177
|
}>;
|
|
175
178
|
/**
|
|
@@ -225,13 +228,13 @@ declare function uploadLocalArchiveDirect(arbi: ArbiClient, workspaceKey: Uint8A
|
|
|
225
228
|
* Files are grouped by their relative folder path, then each group is split
|
|
226
229
|
* into batches of UPLOAD_BATCH_SIZE to avoid overwhelming the backend.
|
|
227
230
|
*/
|
|
228
|
-
declare function uploadDirectory(auth: AuthHeaders,
|
|
231
|
+
declare function uploadDirectory(auth: AuthHeaders, dirPath: string, options?: UploadDirectoryOptions): Promise<UploadBatchResult>;
|
|
229
232
|
/**
|
|
230
233
|
* Upload files from a zip archive, preserving internal folder structure.
|
|
231
234
|
* Uses jszip via dynamic import so the dependency is optional at load time.
|
|
232
235
|
* Files are uploaded in batches of UPLOAD_BATCH_SIZE per folder.
|
|
233
236
|
*/
|
|
234
|
-
declare function uploadZip(auth: AuthHeaders,
|
|
237
|
+
declare function uploadZip(auth: AuthHeaders, zipPath: string, options?: UploadDirectoryOptions): Promise<UploadBatchResult>;
|
|
235
238
|
/**
|
|
236
239
|
* Terminal status for a single file after `uploadManifest` processes it.
|
|
237
240
|
*
|
|
@@ -328,7 +331,7 @@ interface UploadManifestResult {
|
|
|
328
331
|
* If the backend's response length disagrees with the survivor count, all
|
|
329
332
|
* survivors are emitted as `error` so the caller can retry.
|
|
330
333
|
*/
|
|
331
|
-
declare function uploadManifest(auth: AuthHeaders,
|
|
334
|
+
declare function uploadManifest(auth: AuthHeaders, paths: string[], options?: UploadManifestOptions): Promise<UploadManifestResult>;
|
|
332
335
|
/**
|
|
333
336
|
* Recursively walk a directory and return all absolute paths of files whose
|
|
334
337
|
* extension is in SUPPORTED_EXTENSIONS. Useful for turning a directory input
|
|
@@ -341,7 +344,7 @@ declare function walkSupportedFiles(dirPath: string): string[];
|
|
|
341
344
|
* to `uploadDirectory`. Requires p7zip / 7z to be installed on the system.
|
|
342
345
|
* Supports: .7z, .rar (anything `7z x` can handle).
|
|
343
346
|
*/
|
|
344
|
-
declare function uploadArchive(auth: AuthHeaders,
|
|
347
|
+
declare function uploadArchive(auth: AuthHeaders, archivePath: string, options?: UploadDirectoryOptions): Promise<UploadBatchResult>;
|
|
345
348
|
|
|
346
349
|
declare const documentsNode_ARCHIVE_EXTENSIONS: typeof ARCHIVE_EXTENSIONS;
|
|
347
350
|
type documentsNode_FileOutcome = FileOutcome;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-
|
|
2
|
-
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-
|
|
1
|
+
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, S as SkippedFile, U as UploadResult, A as AuthHeaders, d as UploadBatchResult, e as UploadOptions, f as UploadDirectOptions, g as UploadDirectResult, h as SUPPORTED_EXTENSIONS, D as DmCryptoContext } from './browser-BJdLTFSM.js';
|
|
2
|
+
export { i as AgentStepEvent, j as Arbi, k as ArbiApiError, l as ArbiError, m as ArbiOptions, n as ArtifactEvent, o as AuthContext, p as AuthenticatedClient, q as CitationSummary, r as ConnectOptions, s as DOC_TERMINAL_STATUSES, t as DocumentListFields, u as DocumentListOrder, v as DocumentWaiter, w as DocumentWaiterOptions, F as FormattedWsMessage, L as ListAllOptions, x as ListPaginatedOptions, M as MessageLevel, y as MessageMetadataPayload, z as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, B as ReconnectableWsConnection, E as ResolvedCitation, G as ResponseCompletedEvent, H as ResponseContentPartAddedEvent, I as ResponseCreatedEvent, J as ResponseFailedEvent, K as ResponseOutputItemAddedEvent, N as ResponseOutputItemDoneEvent, P as ResponseOutputTextDeltaEvent, T as ResponseOutputTextDoneEvent, V as ResponseUsage, W as SSEEvent, X as SSEStreamCallbacks, Y as SSEStreamResult, Z as SSEStreamStartData, _ as UserInfo, $ as UserInputRequestEvent, a0 as UserMessageEvent, a1 as WorkspaceContext, a2 as WsConnection, a3 as agentconfig, a4 as assistant, a5 as authenticatedFetch, a6 as buildRetrievalChunkTool, a7 as buildRetrievalFullContextTool, a8 as buildRetrievalTocTool, a9 as connectWebSocket, aa as connectWithReconnect, ab as consumeSSEStream, ac as contacts, ad as conversations, ae as countCitations, af as createAuthenticatedClient, ag as createDocumentWaiter, ah as dm, ai as doctags, aj as documents, ak as files, al as formatAgentStepLabel, am as formatFileSize, an as formatStreamSummary, ao as formatUserName, ap as formatWorkspaceChoices, aq as formatWsMessage, ar as generateEncryptedWorkspaceKey, as as generateNewWorkspaceKey, at as getErrorCode, au as getErrorMessage, av as getRawWorkspaceKey, aw as health, ax as parseSSEEvents, ay as performPasswordLogin, az as performSigningKeyLogin, aA as performSsoDeviceFlowLogin, aB as requireData, aC as requireOk, aD as resolveAuth, aE as resolveCitations, aF as resolveWorkspace, aG as responses, aH as selectWorkspace, aI as selectWorkspaceById, aJ as settings, aK as streamSSE, aL as stripCitationMarkdown, aM as summarizeCitations, aN as tags, aO as workspaces } from './browser-BJdLTFSM.js';
|
|
3
3
|
import { SessionStorageProvider, ArbiClient, components } from '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -168,8 +168,11 @@ interface UploadDirectoryOptions {
|
|
|
168
168
|
/**
|
|
169
169
|
* Upload a local file by path. Handles readFileSync + basename + Blob + uploadFile.
|
|
170
170
|
* Convenience wrapper for CLI/TUI consumers that work with file system paths.
|
|
171
|
+
*
|
|
172
|
+
* Workspace context is derived server-side from the open session (the caller's
|
|
173
|
+
* JWT + most recent ``/workspace/{id}/open`` call), so no workspace id is sent.
|
|
171
174
|
*/
|
|
172
|
-
declare function uploadLocalFile(auth: AuthHeaders,
|
|
175
|
+
declare function uploadLocalFile(auth: AuthHeaders, filePath: string, options?: UploadOptions): Promise<UploadResult & {
|
|
173
176
|
fileName: string;
|
|
174
177
|
}>;
|
|
175
178
|
/**
|
|
@@ -225,13 +228,13 @@ declare function uploadLocalArchiveDirect(arbi: ArbiClient, workspaceKey: Uint8A
|
|
|
225
228
|
* Files are grouped by their relative folder path, then each group is split
|
|
226
229
|
* into batches of UPLOAD_BATCH_SIZE to avoid overwhelming the backend.
|
|
227
230
|
*/
|
|
228
|
-
declare function uploadDirectory(auth: AuthHeaders,
|
|
231
|
+
declare function uploadDirectory(auth: AuthHeaders, dirPath: string, options?: UploadDirectoryOptions): Promise<UploadBatchResult>;
|
|
229
232
|
/**
|
|
230
233
|
* Upload files from a zip archive, preserving internal folder structure.
|
|
231
234
|
* Uses jszip via dynamic import so the dependency is optional at load time.
|
|
232
235
|
* Files are uploaded in batches of UPLOAD_BATCH_SIZE per folder.
|
|
233
236
|
*/
|
|
234
|
-
declare function uploadZip(auth: AuthHeaders,
|
|
237
|
+
declare function uploadZip(auth: AuthHeaders, zipPath: string, options?: UploadDirectoryOptions): Promise<UploadBatchResult>;
|
|
235
238
|
/**
|
|
236
239
|
* Terminal status for a single file after `uploadManifest` processes it.
|
|
237
240
|
*
|
|
@@ -328,7 +331,7 @@ interface UploadManifestResult {
|
|
|
328
331
|
* If the backend's response length disagrees with the survivor count, all
|
|
329
332
|
* survivors are emitted as `error` so the caller can retry.
|
|
330
333
|
*/
|
|
331
|
-
declare function uploadManifest(auth: AuthHeaders,
|
|
334
|
+
declare function uploadManifest(auth: AuthHeaders, paths: string[], options?: UploadManifestOptions): Promise<UploadManifestResult>;
|
|
332
335
|
/**
|
|
333
336
|
* Recursively walk a directory and return all absolute paths of files whose
|
|
334
337
|
* extension is in SUPPORTED_EXTENSIONS. Useful for turning a directory input
|
|
@@ -341,7 +344,7 @@ declare function walkSupportedFiles(dirPath: string): string[];
|
|
|
341
344
|
* to `uploadDirectory`. Requires p7zip / 7z to be installed on the system.
|
|
342
345
|
* Supports: .7z, .rar (anything `7z x` can handle).
|
|
343
346
|
*/
|
|
344
|
-
declare function uploadArchive(auth: AuthHeaders,
|
|
347
|
+
declare function uploadArchive(auth: AuthHeaders, archivePath: string, options?: UploadDirectoryOptions): Promise<UploadBatchResult>;
|
|
345
348
|
|
|
346
349
|
declare const documentsNode_ARCHIVE_EXTENSIONS: typeof ARCHIVE_EXTENSIONS;
|
|
347
350
|
type documentsNode_FileOutcome = FileOutcome;
|
package/dist/index.js
CHANGED
|
@@ -4442,7 +4442,8 @@ var DOC_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
4442
4442
|
"completed",
|
|
4443
4443
|
"failed",
|
|
4444
4444
|
"skipped",
|
|
4445
|
-
"empty"
|
|
4445
|
+
"empty",
|
|
4446
|
+
"low-content"
|
|
4446
4447
|
]);
|
|
4447
4448
|
function createDocumentWaiter(options) {
|
|
4448
4449
|
const { baseUrl, accessToken, onStatus } = options;
|
|
@@ -4646,6 +4647,7 @@ __export(documents_exports, {
|
|
|
4646
4647
|
listAll: () => listAll,
|
|
4647
4648
|
listDocuments: () => listDocuments,
|
|
4648
4649
|
listPaginated: () => listPaginated,
|
|
4650
|
+
mimeFromName: () => mimeFromName,
|
|
4649
4651
|
sanitizeFolderPath: () => sanitizeFolderPath,
|
|
4650
4652
|
updateDocuments: () => updateDocuments,
|
|
4651
4653
|
uploadDocumentsDirect: () => uploadDocumentsDirect,
|
|
@@ -4795,11 +4797,11 @@ async function updateDocuments(arbi, documents) {
|
|
|
4795
4797
|
"Failed to update documents"
|
|
4796
4798
|
);
|
|
4797
4799
|
}
|
|
4798
|
-
async function uploadUrl(arbi, urls,
|
|
4800
|
+
async function uploadUrl(arbi, urls, shared = false) {
|
|
4799
4801
|
return requireData(
|
|
4800
4802
|
await arbi.fetch.POST("/v1/document/upload-url", {
|
|
4801
4803
|
params: {
|
|
4802
|
-
query: { urls,
|
|
4804
|
+
query: { urls, shared }
|
|
4803
4805
|
}
|
|
4804
4806
|
}),
|
|
4805
4807
|
"Failed to upload from URLs"
|
|
@@ -4812,29 +4814,31 @@ async function getParsedContent(auth, docId, stage) {
|
|
|
4812
4814
|
});
|
|
4813
4815
|
return res.json();
|
|
4814
4816
|
}
|
|
4815
|
-
async function uploadFile(auth,
|
|
4817
|
+
async function uploadFile(auth, fileData, fileName, options) {
|
|
4816
4818
|
const formData = new FormData();
|
|
4817
4819
|
formData.append("files", fileData, fileName);
|
|
4818
|
-
const params = new URLSearchParams(
|
|
4820
|
+
const params = new URLSearchParams();
|
|
4819
4821
|
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
4820
4822
|
if (options?.configExtId) params.set("config_ext_id", options.configExtId);
|
|
4823
|
+
const qs = params.toString();
|
|
4821
4824
|
const res = await authenticatedFetch({
|
|
4822
4825
|
...auth,
|
|
4823
|
-
path: `/v1/document/upload?${
|
|
4826
|
+
path: qs ? `/v1/document/upload?${qs}` : `/v1/document/upload`,
|
|
4824
4827
|
method: "POST",
|
|
4825
4828
|
body: formData
|
|
4826
4829
|
});
|
|
4827
4830
|
return res.json();
|
|
4828
4831
|
}
|
|
4829
|
-
async function uploadFiles(auth,
|
|
4832
|
+
async function uploadFiles(auth, files, options) {
|
|
4830
4833
|
const formData = new FormData();
|
|
4831
4834
|
for (const f2 of files) formData.append("files", f2.data, f2.name);
|
|
4832
|
-
const params = new URLSearchParams(
|
|
4835
|
+
const params = new URLSearchParams();
|
|
4833
4836
|
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
4834
4837
|
if (options?.configExtId) params.set("config_ext_id", options.configExtId);
|
|
4838
|
+
const qs = params.toString();
|
|
4835
4839
|
const res = await authenticatedFetch({
|
|
4836
4840
|
...auth,
|
|
4837
|
-
path: `/v1/document/upload?${
|
|
4841
|
+
path: qs ? `/v1/document/upload?${qs}` : `/v1/document/upload`,
|
|
4838
4842
|
method: "POST",
|
|
4839
4843
|
body: formData
|
|
4840
4844
|
});
|
|
@@ -4846,6 +4850,68 @@ async function downloadDocument(auth, docId) {
|
|
|
4846
4850
|
path: `/v1/document/${docId}/download`
|
|
4847
4851
|
});
|
|
4848
4852
|
}
|
|
4853
|
+
function mimeFromName(name) {
|
|
4854
|
+
const dot = name.lastIndexOf(".");
|
|
4855
|
+
const ext = dot === -1 ? "" : name.slice(dot).toLowerCase();
|
|
4856
|
+
switch (ext) {
|
|
4857
|
+
case ".pdf":
|
|
4858
|
+
return "application/pdf";
|
|
4859
|
+
case ".txt":
|
|
4860
|
+
return "text/plain";
|
|
4861
|
+
case ".md":
|
|
4862
|
+
return "text/markdown";
|
|
4863
|
+
case ".html":
|
|
4864
|
+
case ".htm":
|
|
4865
|
+
return "text/html";
|
|
4866
|
+
case ".doc":
|
|
4867
|
+
return "application/msword";
|
|
4868
|
+
case ".docx":
|
|
4869
|
+
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
4870
|
+
case ".xls":
|
|
4871
|
+
return "application/vnd.ms-excel";
|
|
4872
|
+
case ".xlsx":
|
|
4873
|
+
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
4874
|
+
case ".ppt":
|
|
4875
|
+
return "application/vnd.ms-powerpoint";
|
|
4876
|
+
case ".pptx":
|
|
4877
|
+
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
4878
|
+
case ".eml":
|
|
4879
|
+
return "message/rfc822";
|
|
4880
|
+
default:
|
|
4881
|
+
return void 0;
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
async function presignedPut(url, body, onProgress) {
|
|
4885
|
+
const XhrGlobal = globalThis.XMLHttpRequest;
|
|
4886
|
+
if (XhrGlobal) {
|
|
4887
|
+
await new Promise((resolve2, reject) => {
|
|
4888
|
+
const xhr = new XhrGlobal();
|
|
4889
|
+
xhr.open("PUT", url);
|
|
4890
|
+
if (onProgress) {
|
|
4891
|
+
xhr.upload.addEventListener("progress", (e) => {
|
|
4892
|
+
if (e.lengthComputable) onProgress(e.loaded, e.total);
|
|
4893
|
+
});
|
|
4894
|
+
}
|
|
4895
|
+
xhr.addEventListener("load", () => {
|
|
4896
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
4897
|
+
resolve2();
|
|
4898
|
+
} else {
|
|
4899
|
+
const snippet = (xhr.responseText || "").slice(0, 200);
|
|
4900
|
+
reject(new Error(`Presigned PUT failed: ${xhr.status} ${snippet}`));
|
|
4901
|
+
}
|
|
4902
|
+
});
|
|
4903
|
+
xhr.addEventListener("error", () => reject(new Error("Presigned PUT network error")));
|
|
4904
|
+
xhr.addEventListener("abort", () => reject(new Error("Presigned PUT aborted")));
|
|
4905
|
+
xhr.send(body);
|
|
4906
|
+
});
|
|
4907
|
+
return;
|
|
4908
|
+
}
|
|
4909
|
+
const putRes = await fetch(url, { method: "PUT", body });
|
|
4910
|
+
if (!putRes.ok) {
|
|
4911
|
+
const snippet = await putRes.text().catch(() => "");
|
|
4912
|
+
throw new Error(`Presigned PUT failed: ${putRes.status} ${snippet.slice(0, 200)}`);
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4849
4915
|
async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
|
|
4850
4916
|
if (files.length === 0) return { doc_ext_ids: [], skipped: [] };
|
|
4851
4917
|
const SECRETBOX_ENVELOPE_OVERHEAD = 40;
|
|
@@ -4878,6 +4944,11 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
|
|
|
4878
4944
|
}
|
|
4879
4945
|
const skipped = [];
|
|
4880
4946
|
const toCommit = [];
|
|
4947
|
+
const indexByName = /* @__PURE__ */ new Map();
|
|
4948
|
+
files.forEach((f2, i2) => {
|
|
4949
|
+
if (!indexByName.has(f2.name)) indexByName.set(f2.name, []);
|
|
4950
|
+
indexByName.get(f2.name).push(i2);
|
|
4951
|
+
});
|
|
4881
4952
|
for (const item of items) {
|
|
4882
4953
|
if (item.status !== "uploading" || !item.upload_url || !item.doc_ext_id) {
|
|
4883
4954
|
skipped.push({
|
|
@@ -4887,21 +4958,34 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
|
|
|
4887
4958
|
continue;
|
|
4888
4959
|
}
|
|
4889
4960
|
const queue = bytesByName.get(item.file_name);
|
|
4890
|
-
|
|
4961
|
+
const idxQueue = indexByName.get(item.file_name);
|
|
4962
|
+
if (!queue || queue.length === 0 || !idxQueue || idxQueue.length === 0) {
|
|
4891
4963
|
throw new Error(`upload-init returned slot for unknown file: ${item.file_name}`);
|
|
4892
4964
|
}
|
|
4893
4965
|
const raw = queue.shift();
|
|
4966
|
+
const fileIndex = idxQueue.shift();
|
|
4894
4967
|
const ciphertext = encryptFile(raw, workspaceKey);
|
|
4895
|
-
const
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4968
|
+
const total = ciphertext.length;
|
|
4969
|
+
try {
|
|
4970
|
+
await presignedPut(item.upload_url, ciphertext, (loaded, putTotal) => {
|
|
4971
|
+
options?.onBytesProgress?.({
|
|
4972
|
+
fileIndex,
|
|
4973
|
+
fileName: item.file_name,
|
|
4974
|
+
loaded,
|
|
4975
|
+
total: putTotal
|
|
4976
|
+
});
|
|
4977
|
+
});
|
|
4978
|
+
} catch (err) {
|
|
4901
4979
|
throw new Error(
|
|
4902
|
-
`Presigned PUT for ${item.doc_ext_id} failed: ${
|
|
4980
|
+
`Presigned PUT for ${item.doc_ext_id} failed: ${err instanceof Error ? err.message : String(err)}`
|
|
4903
4981
|
);
|
|
4904
4982
|
}
|
|
4983
|
+
options?.onBytesProgress?.({
|
|
4984
|
+
fileIndex,
|
|
4985
|
+
fileName: item.file_name,
|
|
4986
|
+
loaded: total,
|
|
4987
|
+
total
|
|
4988
|
+
});
|
|
4905
4989
|
toCommit.push(item.doc_ext_id);
|
|
4906
4990
|
}
|
|
4907
4991
|
if (toCommit.length === 0) {
|
|
@@ -5757,19 +5841,19 @@ var Arbi = class {
|
|
|
5757
5841
|
get: (externalIds) => getDocuments(this.requireClient(), externalIds),
|
|
5758
5842
|
delete: (externalIds) => deleteDocuments(this.requireClient(), externalIds),
|
|
5759
5843
|
update: (documents) => updateDocuments(this.requireClient(), documents),
|
|
5760
|
-
uploadUrl: (urls, shared
|
|
5761
|
-
this.
|
|
5762
|
-
urls,
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5844
|
+
uploadUrl: (urls, shared) => {
|
|
5845
|
+
this.requireWorkspace();
|
|
5846
|
+
return uploadUrl(this.requireClient(), urls, shared);
|
|
5847
|
+
},
|
|
5848
|
+
uploadFile: (fileData, fileName, options) => {
|
|
5849
|
+
this.requireWorkspace();
|
|
5850
|
+
return uploadFile(
|
|
5851
|
+
this.getAuthHeaders(),
|
|
5852
|
+
fileData,
|
|
5853
|
+
fileName,
|
|
5854
|
+
options?.folder ? { folder: options.folder } : void 0
|
|
5855
|
+
);
|
|
5856
|
+
},
|
|
5773
5857
|
download: (docId) => downloadDocument(this.getAuthHeaders(), docId),
|
|
5774
5858
|
getParsedContent: (docId, stage) => getParsedContent(this.getAuthHeaders(), docId, stage)
|
|
5775
5859
|
};
|
|
@@ -5967,7 +6051,8 @@ function chunk(arr, size) {
|
|
|
5967
6051
|
}
|
|
5968
6052
|
return chunks;
|
|
5969
6053
|
}
|
|
5970
|
-
function readFileAsBlob(filePath, fileSize) {
|
|
6054
|
+
function readFileAsBlob(filePath, fileSize, fileName) {
|
|
6055
|
+
const type = fileName ? mimeFromName(fileName) ?? "" : "";
|
|
5971
6056
|
if (fileSize > NODE_BUFFER_LIMIT) {
|
|
5972
6057
|
const chunks = [];
|
|
5973
6058
|
const CHUNK = 256 * 1024 * 1024;
|
|
@@ -5981,15 +6066,15 @@ function readFileAsBlob(filePath, fileSize) {
|
|
|
5981
6066
|
pos += len;
|
|
5982
6067
|
}
|
|
5983
6068
|
fs2.closeSync(fd);
|
|
5984
|
-
return new Blob(chunks);
|
|
6069
|
+
return new Blob(chunks, { type });
|
|
5985
6070
|
}
|
|
5986
|
-
return new Blob([fs2.readFileSync(filePath)]);
|
|
6071
|
+
return new Blob([fs2.readFileSync(filePath)], { type });
|
|
5987
6072
|
}
|
|
5988
|
-
async function uploadLocalFile(auth,
|
|
6073
|
+
async function uploadLocalFile(auth, filePath, options) {
|
|
5989
6074
|
const stat = fs2.statSync(filePath);
|
|
5990
6075
|
const fileName = path2.basename(filePath);
|
|
5991
|
-
const blob = readFileAsBlob(filePath, stat.size);
|
|
5992
|
-
const result = await uploadFile(auth,
|
|
6076
|
+
const blob = readFileAsBlob(filePath, stat.size, fileName);
|
|
6077
|
+
const result = await uploadFile(auth, blob, fileName, options);
|
|
5993
6078
|
return { ...result, fileName };
|
|
5994
6079
|
}
|
|
5995
6080
|
async function uploadLocalFilesDirect(arbi, workspaceKey, filePaths, options) {
|
|
@@ -6148,37 +6233,7 @@ async function uploadLocalArchiveDirect(arbi, workspaceKey, archivePath, options
|
|
|
6148
6233
|
}
|
|
6149
6234
|
}
|
|
6150
6235
|
}
|
|
6151
|
-
function
|
|
6152
|
-
const ext = path2.extname(name).toLowerCase();
|
|
6153
|
-
switch (ext) {
|
|
6154
|
-
case ".pdf":
|
|
6155
|
-
return "application/pdf";
|
|
6156
|
-
case ".txt":
|
|
6157
|
-
return "text/plain";
|
|
6158
|
-
case ".md":
|
|
6159
|
-
return "text/markdown";
|
|
6160
|
-
case ".html":
|
|
6161
|
-
case ".htm":
|
|
6162
|
-
return "text/html";
|
|
6163
|
-
case ".doc":
|
|
6164
|
-
return "application/msword";
|
|
6165
|
-
case ".docx":
|
|
6166
|
-
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
6167
|
-
case ".xls":
|
|
6168
|
-
return "application/vnd.ms-excel";
|
|
6169
|
-
case ".xlsx":
|
|
6170
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
6171
|
-
case ".ppt":
|
|
6172
|
-
return "application/vnd.ms-powerpoint";
|
|
6173
|
-
case ".pptx":
|
|
6174
|
-
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
6175
|
-
case ".eml":
|
|
6176
|
-
return "message/rfc822";
|
|
6177
|
-
default:
|
|
6178
|
-
return void 0;
|
|
6179
|
-
}
|
|
6180
|
-
}
|
|
6181
|
-
async function uploadDirectory(auth, workspaceId, dirPath, options) {
|
|
6236
|
+
async function uploadDirectory(auth, dirPath, options) {
|
|
6182
6237
|
const resolvedDir = path2.resolve(dirPath);
|
|
6183
6238
|
const dirName = path2.basename(resolvedDir);
|
|
6184
6239
|
const entries = collectFiles(resolvedDir);
|
|
@@ -6234,7 +6289,7 @@ async function uploadDirectory(auth, workspaceId, dirPath, options) {
|
|
|
6234
6289
|
});
|
|
6235
6290
|
} else {
|
|
6236
6291
|
try {
|
|
6237
|
-
uploadable.push({ data: readFileAsBlob(f2.absolutePath, f2.size), name: f2.name });
|
|
6292
|
+
uploadable.push({ data: readFileAsBlob(f2.absolutePath, f2.size, f2.name), name: f2.name });
|
|
6238
6293
|
} catch (err) {
|
|
6239
6294
|
batchSkipped.push({
|
|
6240
6295
|
file_name: f2.name,
|
|
@@ -6245,7 +6300,7 @@ async function uploadDirectory(auth, workspaceId, dirPath, options) {
|
|
|
6245
6300
|
}
|
|
6246
6301
|
let result = { doc_ext_ids: [], skipped: [] };
|
|
6247
6302
|
if (uploadable.length > 0) {
|
|
6248
|
-
result = await uploadFiles(auth,
|
|
6303
|
+
result = await uploadFiles(auth, uploadable, {
|
|
6249
6304
|
folder,
|
|
6250
6305
|
configExtId: options?.configExtId
|
|
6251
6306
|
});
|
|
@@ -6270,7 +6325,7 @@ async function uploadDirectory(auth, workspaceId, dirPath, options) {
|
|
|
6270
6325
|
}
|
|
6271
6326
|
return { doc_ext_ids: allDocIds, skipped: allSkipped, folders };
|
|
6272
6327
|
}
|
|
6273
|
-
async function uploadZip(auth,
|
|
6328
|
+
async function uploadZip(auth, zipPath, options) {
|
|
6274
6329
|
const JSZip = (await import('jszip')).default;
|
|
6275
6330
|
const zipBuffer = fs2.readFileSync(zipPath);
|
|
6276
6331
|
const zip = await JSZip.loadAsync(zipBuffer);
|
|
@@ -6334,7 +6389,7 @@ async function uploadZip(auth, workspaceId, zipPath, options) {
|
|
|
6334
6389
|
data: new Blob([f2.data]),
|
|
6335
6390
|
name: f2.name
|
|
6336
6391
|
}));
|
|
6337
|
-
const result = await uploadFiles(auth,
|
|
6392
|
+
const result = await uploadFiles(auth, blobs, {
|
|
6338
6393
|
folder,
|
|
6339
6394
|
configExtId: options?.configExtId
|
|
6340
6395
|
});
|
|
@@ -6405,7 +6460,7 @@ function isTransientError(err) {
|
|
|
6405
6460
|
function sleep2(ms) {
|
|
6406
6461
|
return new Promise((r2) => setTimeout(r2, ms));
|
|
6407
6462
|
}
|
|
6408
|
-
async function uploadManifest(auth,
|
|
6463
|
+
async function uploadManifest(auth, paths, options) {
|
|
6409
6464
|
const maxRetries = Math.max(1, options?.maxRetries ?? 3);
|
|
6410
6465
|
const outcomes = [];
|
|
6411
6466
|
const summary = {
|
|
@@ -6526,7 +6581,7 @@ async function uploadManifest(auth, workspaceId, paths, options) {
|
|
|
6526
6581
|
const readable = [];
|
|
6527
6582
|
for (const f2 of batch) {
|
|
6528
6583
|
try {
|
|
6529
|
-
const blob = readFileAsBlob(f2.absolutePath, f2.size);
|
|
6584
|
+
const blob = readFileAsBlob(f2.absolutePath, f2.size, f2.basename);
|
|
6530
6585
|
readable.push({ f: f2, blob });
|
|
6531
6586
|
} catch (err) {
|
|
6532
6587
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -6554,7 +6609,6 @@ async function uploadManifest(auth, workspaceId, paths, options) {
|
|
|
6554
6609
|
try {
|
|
6555
6610
|
result = await uploadFiles(
|
|
6556
6611
|
auth,
|
|
6557
|
-
workspaceId,
|
|
6558
6612
|
readable.map((r2) => ({ data: r2.blob, name: r2.f.basename })),
|
|
6559
6613
|
{ folder, configExtId: options?.configExtId }
|
|
6560
6614
|
);
|
|
@@ -6668,7 +6722,7 @@ function walkSupportedFiles(dirPath) {
|
|
|
6668
6722
|
}
|
|
6669
6723
|
return out.sort();
|
|
6670
6724
|
}
|
|
6671
|
-
async function uploadArchive(auth,
|
|
6725
|
+
async function uploadArchive(auth, archivePath, options) {
|
|
6672
6726
|
try {
|
|
6673
6727
|
execSync("7z --help", { stdio: "ignore" });
|
|
6674
6728
|
} catch {
|
|
@@ -6687,7 +6741,7 @@ async function uploadArchive(auth, workspaceId, archivePath, options) {
|
|
|
6687
6741
|
fs2.renameSync(tmpDir, namedDir);
|
|
6688
6742
|
uploadDir = namedDir;
|
|
6689
6743
|
}
|
|
6690
|
-
return await uploadDirectory(auth,
|
|
6744
|
+
return await uploadDirectory(auth, uploadDir, options);
|
|
6691
6745
|
} finally {
|
|
6692
6746
|
fs2.rmSync(tmpDir, { recursive: true, force: true });
|
|
6693
6747
|
}
|