@diskd-ai/sdk 5.1.2
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/LICENSE +190 -0
- package/README.md +1036 -0
- package/dist/agentHub/StreamProtocolFetcher.d.ts +55 -0
- package/dist/agentHub/StreamProtocolFetcher.d.ts.map +1 -0
- package/dist/agentHub/StreamProtocolFetcher.js +176 -0
- package/dist/agentHub/StreamProtocolFetcher.js.map +1 -0
- package/dist/agentHub/StreamProtocolHandler.d.ts +18 -0
- package/dist/agentHub/StreamProtocolHandler.d.ts.map +1 -0
- package/dist/agentHub/StreamProtocolHandler.js +63 -0
- package/dist/agentHub/StreamProtocolHandler.js.map +1 -0
- package/dist/agentHub/agentHub.d.ts +30 -0
- package/dist/agentHub/agentHub.d.ts.map +1 -0
- package/dist/agentHub/agentHub.js +200 -0
- package/dist/agentHub/agentHub.js.map +1 -0
- package/dist/agentHub/agentHubTypes.d.ts +110 -0
- package/dist/agentHub/agentHubTypes.d.ts.map +1 -0
- package/dist/agentHub/agentHubTypes.js +8 -0
- package/dist/agentHub/agentHubTypes.js.map +1 -0
- package/dist/agentHub/streamProtocolMap.d.ts +328 -0
- package/dist/agentHub/streamProtocolMap.d.ts.map +1 -0
- package/dist/agentHub/streamProtocolMap.js +8 -0
- package/dist/agentHub/streamProtocolMap.js.map +1 -0
- package/dist/auth/createApiKeyAuth.d.ts +11 -0
- package/dist/auth/createApiKeyAuth.d.ts.map +1 -0
- package/dist/auth/createApiKeyAuth.js +31 -0
- package/dist/auth/createApiKeyAuth.js.map +1 -0
- package/dist/auth/createAuth.d.ts +3 -0
- package/dist/auth/createAuth.d.ts.map +1 -0
- package/dist/auth/createAuth.js +128 -0
- package/dist/auth/createAuth.js.map +1 -0
- package/dist/auth/createAuthBrowser.d.ts +3 -0
- package/dist/auth/createAuthBrowser.d.ts.map +1 -0
- package/dist/auth/createAuthBrowser.js +104 -0
- package/dist/auth/createAuthBrowser.js.map +1 -0
- package/dist/auth/jwtClaims.d.ts +3 -0
- package/dist/auth/jwtClaims.d.ts.map +1 -0
- package/dist/auth/jwtClaims.js +23 -0
- package/dist/auth/jwtClaims.js.map +1 -0
- package/dist/auth/keyfile.d.ts +10 -0
- package/dist/auth/keyfile.d.ts.map +1 -0
- package/dist/auth/keyfile.js +28 -0
- package/dist/auth/keyfile.js.map +1 -0
- package/dist/auth/oidcDiscovery.d.ts +9 -0
- package/dist/auth/oidcDiscovery.d.ts.map +1 -0
- package/dist/auth/oidcDiscovery.js +27 -0
- package/dist/auth/oidcDiscovery.js.map +1 -0
- package/dist/auth/pkce.d.ts +4 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +43 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/sessionStorage.d.ts +8 -0
- package/dist/auth/sessionStorage.d.ts.map +1 -0
- package/dist/auth/sessionStorage.js +8 -0
- package/dist/auth/sessionStorage.js.map +1 -0
- package/dist/auth/tokenRequests.d.ts +15 -0
- package/dist/auth/tokenRequests.d.ts.map +1 -0
- package/dist/auth/tokenRequests.js +89 -0
- package/dist/auth/tokenRequests.js.map +1 -0
- package/dist/auth/types.d.ts +35 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/urlRuntime.d.ts +7 -0
- package/dist/auth/urlRuntime.d.ts.map +1 -0
- package/dist/auth/urlRuntime.js +17 -0
- package/dist/auth/urlRuntime.js.map +1 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +3 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/calendar/calendar.d.ts +21 -0
- package/dist/calendar/calendar.d.ts.map +1 -0
- package/dist/calendar/calendar.js +105 -0
- package/dist/calendar/calendar.js.map +1 -0
- package/dist/calendar/calendarTypes.d.ts +191 -0
- package/dist/calendar/calendarTypes.d.ts.map +1 -0
- package/dist/calendar/calendarTypes.js +4 -0
- package/dist/calendar/calendarTypes.js.map +1 -0
- package/dist/contacts/contacts.d.ts +10 -0
- package/dist/contacts/contacts.d.ts.map +1 -0
- package/dist/contacts/contacts.js +86 -0
- package/dist/contacts/contacts.js.map +1 -0
- package/dist/contacts/contactsTypes.d.ts +81 -0
- package/dist/contacts/contactsTypes.d.ts.map +1 -0
- package/dist/contacts/contactsTypes.js +4 -0
- package/dist/contacts/contactsTypes.js.map +1 -0
- package/dist/drive/DriveRepository.d.ts +88 -0
- package/dist/drive/DriveRepository.d.ts.map +1 -0
- package/dist/drive/DriveRepository.js +156 -0
- package/dist/drive/DriveRepository.js.map +1 -0
- package/dist/drive/crontab.d.ts +7 -0
- package/dist/drive/crontab.d.ts.map +1 -0
- package/dist/drive/crontab.js +374 -0
- package/dist/drive/crontab.js.map +1 -0
- package/dist/drive/crontabTypes.d.ts +136 -0
- package/dist/drive/crontabTypes.d.ts.map +1 -0
- package/dist/drive/crontabTypes.js +2 -0
- package/dist/drive/crontabTypes.js.map +1 -0
- package/dist/drive/drive.d.ts +8 -0
- package/dist/drive/drive.d.ts.map +1 -0
- package/dist/drive/drive.js +711 -0
- package/dist/drive/drive.js.map +1 -0
- package/dist/drive/driveDb.d.ts +6 -0
- package/dist/drive/driveDb.d.ts.map +1 -0
- package/dist/drive/driveDb.js +220 -0
- package/dist/drive/driveDb.js.map +1 -0
- package/dist/drive/driveDbTypes.d.ts +138 -0
- package/dist/drive/driveDbTypes.d.ts.map +1 -0
- package/dist/drive/driveDbTypes.js +5 -0
- package/dist/drive/driveDbTypes.js.map +1 -0
- package/dist/drive/driveTypes.d.ts +322 -0
- package/dist/drive/driveTypes.d.ts.map +1 -0
- package/dist/drive/driveTypes.js +5 -0
- package/dist/drive/driveTypes.js.map +1 -0
- package/dist/drive/rpc.d.ts +14 -0
- package/dist/drive/rpc.d.ts.map +1 -0
- package/dist/drive/rpc.js +48 -0
- package/dist/drive/rpc.js.map +1 -0
- package/dist/drive/session.d.ts +7 -0
- package/dist/drive/session.d.ts.map +1 -0
- package/dist/drive/session.js +450 -0
- package/dist/drive/session.js.map +1 -0
- package/dist/drive/sessionBuilder.d.ts +33 -0
- package/dist/drive/sessionBuilder.d.ts.map +1 -0
- package/dist/drive/sessionBuilder.js +77 -0
- package/dist/drive/sessionBuilder.js.map +1 -0
- package/dist/drive/sessionObject.d.ts +57 -0
- package/dist/drive/sessionObject.d.ts.map +1 -0
- package/dist/drive/sessionObject.js +191 -0
- package/dist/drive/sessionObject.js.map +1 -0
- package/dist/drive/sessionTypes.d.ts +182 -0
- package/dist/drive/sessionTypes.d.ts.map +1 -0
- package/dist/drive/sessionTypes.js +2 -0
- package/dist/drive/sessionTypes.js.map +1 -0
- package/dist/drive/typeorm/DriveDriver.d.ts +27 -0
- package/dist/drive/typeorm/DriveDriver.d.ts.map +1 -0
- package/dist/drive/typeorm/DriveDriver.js +86 -0
- package/dist/drive/typeorm/DriveDriver.js.map +1 -0
- package/dist/drive/typeorm/DriveQueryRunner.d.ts +15 -0
- package/dist/drive/typeorm/DriveQueryRunner.d.ts.map +1 -0
- package/dist/drive/typeorm/DriveQueryRunner.js +76 -0
- package/dist/drive/typeorm/DriveQueryRunner.js.map +1 -0
- package/dist/drive/typeorm/createDriveDataSource.d.ts +3 -0
- package/dist/drive/typeorm/createDriveDataSource.d.ts.map +1 -0
- package/dist/drive/typeorm/createDriveDataSource.js +36 -0
- package/dist/drive/typeorm/createDriveDataSource.js.map +1 -0
- package/dist/drive/typeorm/datasourceTypes.d.ts +56 -0
- package/dist/drive/typeorm/datasourceTypes.d.ts.map +1 -0
- package/dist/drive/typeorm/datasourceTypes.js +5 -0
- package/dist/drive/typeorm/datasourceTypes.js.map +1 -0
- package/dist/drive/types.d.ts +48 -0
- package/dist/drive/types.d.ts.map +1 -0
- package/dist/drive/types.js +2 -0
- package/dist/drive/types.js.map +1 -0
- package/dist/env/apiKey.d.ts +2 -0
- package/dist/env/apiKey.d.ts.map +1 -0
- package/dist/env/apiKey.js +11 -0
- package/dist/env/apiKey.js.map +1 -0
- package/dist/env/baseUrl.d.ts +3 -0
- package/dist/env/baseUrl.d.ts.map +1 -0
- package/dist/env/baseUrl.js +31 -0
- package/dist/env/baseUrl.js.map +1 -0
- package/dist/inbox/inboxTypes.d.ts +34 -0
- package/dist/inbox/inboxTypes.d.ts.map +1 -0
- package/dist/inbox/inboxTypes.js +5 -0
- package/dist/inbox/inboxTypes.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/llmRouter/llmRouter.d.ts +23 -0
- package/dist/llmRouter/llmRouter.d.ts.map +1 -0
- package/dist/llmRouter/llmRouter.js +566 -0
- package/dist/llmRouter/llmRouter.js.map +1 -0
- package/dist/llmRouter/llmRouterTypes.d.ts +350 -0
- package/dist/llmRouter/llmRouterTypes.d.ts.map +1 -0
- package/dist/llmRouter/llmRouterTypes.js +5 -0
- package/dist/llmRouter/llmRouterTypes.js.map +1 -0
- package/dist/mcpHub/mcpHub.d.ts +23 -0
- package/dist/mcpHub/mcpHub.d.ts.map +1 -0
- package/dist/mcpHub/mcpHub.js +223 -0
- package/dist/mcpHub/mcpHub.js.map +1 -0
- package/dist/mcpHub/mcpHubTypes.d.ts +228 -0
- package/dist/mcpHub/mcpHubTypes.d.ts.map +1 -0
- package/dist/mcpHub/mcpHubTypes.js +5 -0
- package/dist/mcpHub/mcpHubTypes.js.map +1 -0
- package/dist/mcpTools/mcpTools.d.ts +31 -0
- package/dist/mcpTools/mcpTools.d.ts.map +1 -0
- package/dist/mcpTools/mcpTools.js +144 -0
- package/dist/mcpTools/mcpTools.js.map +1 -0
- package/dist/mcpTools/mcpToolsTypes.d.ts +45 -0
- package/dist/mcpTools/mcpToolsTypes.d.ts.map +1 -0
- package/dist/mcpTools/mcpToolsTypes.js +5 -0
- package/dist/mcpTools/mcpToolsTypes.js.map +1 -0
- package/dist/messagesStore/messagesStore.d.ts +22 -0
- package/dist/messagesStore/messagesStore.d.ts.map +1 -0
- package/dist/messagesStore/messagesStore.js +402 -0
- package/dist/messagesStore/messagesStore.js.map +1 -0
- package/dist/messagesStore/messagesStoreTypes.d.ts +327 -0
- package/dist/messagesStore/messagesStoreTypes.d.ts.map +1 -0
- package/dist/messagesStore/messagesStoreTypes.js +11 -0
- package/dist/messagesStore/messagesStoreTypes.js.map +1 -0
- package/dist/node/fastDns.d.ts +2 -0
- package/dist/node/fastDns.d.ts.map +1 -0
- package/dist/node/fastDns.js +119 -0
- package/dist/node/fastDns.js.map +1 -0
- package/dist/operatives/operatives.d.ts +22 -0
- package/dist/operatives/operatives.d.ts.map +1 -0
- package/dist/operatives/operatives.js +199 -0
- package/dist/operatives/operatives.js.map +1 -0
- package/dist/operatives/operativesTypes.d.ts +141 -0
- package/dist/operatives/operativesTypes.d.ts.map +1 -0
- package/dist/operatives/operativesTypes.js +6 -0
- package/dist/operatives/operativesTypes.js.map +1 -0
- package/dist/platformEvents/platformEvents.d.ts +14 -0
- package/dist/platformEvents/platformEvents.d.ts.map +1 -0
- package/dist/platformEvents/platformEvents.js +70 -0
- package/dist/platformEvents/platformEvents.js.map +1 -0
- package/dist/platformEvents/platformEventsTypes.d.ts +31 -0
- package/dist/platformEvents/platformEventsTypes.d.ts.map +1 -0
- package/dist/platformEvents/platformEventsTypes.js +8 -0
- package/dist/platformEvents/platformEventsTypes.js.map +1 -0
- package/dist/projects/projects.d.ts +19 -0
- package/dist/projects/projects.d.ts.map +1 -0
- package/dist/projects/projects.js +52 -0
- package/dist/projects/projects.js.map +1 -0
- package/dist/projects/projectsTypes.d.ts +47 -0
- package/dist/projects/projectsTypes.d.ts.map +1 -0
- package/dist/projects/projectsTypes.js +4 -0
- package/dist/projects/projectsTypes.js.map +1 -0
- package/dist/routineRuns/routineRuns.d.ts +19 -0
- package/dist/routineRuns/routineRuns.d.ts.map +1 -0
- package/dist/routineRuns/routineRuns.js +47 -0
- package/dist/routineRuns/routineRuns.js.map +1 -0
- package/dist/routineRuns/routineRunsTypes.d.ts +39 -0
- package/dist/routineRuns/routineRunsTypes.d.ts.map +1 -0
- package/dist/routineRuns/routineRunsTypes.js +4 -0
- package/dist/routineRuns/routineRunsTypes.js.map +1 -0
- package/dist/routines/routines.d.ts +19 -0
- package/dist/routines/routines.d.ts.map +1 -0
- package/dist/routines/routines.js +77 -0
- package/dist/routines/routines.js.map +1 -0
- package/dist/routines/routinesTypes.d.ts +106 -0
- package/dist/routines/routinesTypes.d.ts.map +1 -0
- package/dist/routines/routinesTypes.js +4 -0
- package/dist/routines/routinesTypes.js.map +1 -0
- package/dist/sdk/diskd.d.ts +3 -0
- package/dist/sdk/diskd.d.ts.map +1 -0
- package/dist/sdk/diskd.js +126 -0
- package/dist/sdk/diskd.js.map +1 -0
- package/dist/sdk/http.d.ts +13 -0
- package/dist/sdk/http.d.ts.map +1 -0
- package/dist/sdk/http.js +80 -0
- package/dist/sdk/http.js.map +1 -0
- package/dist/sdk/types.d.ts +115 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +2 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/testing/auth.d.ts +8 -0
- package/dist/testing/auth.d.ts.map +1 -0
- package/dist/testing/auth.js +14 -0
- package/dist/testing/auth.js.map +1 -0
- package/dist/testing/fetchMock.d.ts +17 -0
- package/dist/testing/fetchMock.d.ts.map +1 -0
- package/dist/testing/fetchMock.js +46 -0
- package/dist/testing/fetchMock.js.map +1 -0
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/integration.d.ts +33 -0
- package/dist/testing/integration.d.ts.map +1 -0
- package/dist/testing/integration.js +32 -0
- package/dist/testing/integration.js.map +1 -0
- package/dist/testing/jsonRpc.d.ts +9 -0
- package/dist/testing/jsonRpc.d.ts.map +1 -0
- package/dist/testing/jsonRpc.js +24 -0
- package/dist/testing/jsonRpc.js.map +1 -0
- package/dist/testing/rpcMock.d.ts +16 -0
- package/dist/testing/rpcMock.d.ts.map +1 -0
- package/dist/testing/rpcMock.js +28 -0
- package/dist/testing/rpcMock.js.map +1 -0
- package/dist/tgUserbot/tgUserbot.d.ts +23 -0
- package/dist/tgUserbot/tgUserbot.d.ts.map +1 -0
- package/dist/tgUserbot/tgUserbot.js +314 -0
- package/dist/tgUserbot/tgUserbot.js.map +1 -0
- package/dist/tgUserbot/tgUserbotTypes.d.ts +124 -0
- package/dist/tgUserbot/tgUserbotTypes.d.ts.map +1 -0
- package/dist/tgUserbot/tgUserbotTypes.js +5 -0
- package/dist/tgUserbot/tgUserbotTypes.js.map +1 -0
- package/dist/webNavigator/webNavigator.d.ts +22 -0
- package/dist/webNavigator/webNavigator.d.ts.map +1 -0
- package/dist/webNavigator/webNavigator.js +46 -0
- package/dist/webNavigator/webNavigator.js.map +1 -0
- package/dist/webNavigator/webNavigatorTypes.d.ts +133 -0
- package/dist/webNavigator/webNavigatorTypes.d.ts.map +1 -0
- package/dist/webNavigator/webNavigatorTypes.js +5 -0
- package/dist/webNavigator/webNavigatorTypes.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import { resolveDiskdGatewayUrl } from '../env/baseUrl.js';
|
|
2
|
+
import { createDriveCrontabClient } from './crontab.js';
|
|
3
|
+
import { createDriveDbClient } from './driveDb.js';
|
|
4
|
+
import { jsonRpcCall } from './rpc.js';
|
|
5
|
+
import { createDriveSessionClient } from './session.js';
|
|
6
|
+
import { createDriveSessionManager } from './sessionObject.js';
|
|
7
|
+
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
8
|
+
const str = (obj, key) => {
|
|
9
|
+
const v = obj[key];
|
|
10
|
+
return typeof v === 'string' && v.length > 0 ? v : null;
|
|
11
|
+
};
|
|
12
|
+
const strRequired = (obj, key) => {
|
|
13
|
+
const v = str(obj, key);
|
|
14
|
+
if (!v)
|
|
15
|
+
throw new Error(`Invalid Drive response: '${key}' must be a non-empty string`);
|
|
16
|
+
return v;
|
|
17
|
+
};
|
|
18
|
+
const num = (obj, key) => {
|
|
19
|
+
const v = obj[key];
|
|
20
|
+
return typeof v === 'number' ? v : null;
|
|
21
|
+
};
|
|
22
|
+
const numRequired = (obj, key) => {
|
|
23
|
+
const v = num(obj, key);
|
|
24
|
+
if (v === null)
|
|
25
|
+
throw new Error(`Invalid Drive response: '${key}' must be a number`);
|
|
26
|
+
return v;
|
|
27
|
+
};
|
|
28
|
+
const bool = (obj, key, fallback) => {
|
|
29
|
+
const v = obj[key];
|
|
30
|
+
return typeof v === 'boolean' ? v : fallback;
|
|
31
|
+
};
|
|
32
|
+
const metadata = (obj, key) => {
|
|
33
|
+
const v = obj[key];
|
|
34
|
+
if (typeof v === 'object' && v !== null && !Array.isArray(v)) {
|
|
35
|
+
return v;
|
|
36
|
+
}
|
|
37
|
+
return {};
|
|
38
|
+
};
|
|
39
|
+
const attrs = (obj, key) => {
|
|
40
|
+
const v = obj[key];
|
|
41
|
+
return Array.isArray(v) ? v.filter((x) => typeof x === 'string') : [];
|
|
42
|
+
};
|
|
43
|
+
const items = (result) => {
|
|
44
|
+
if (!isObject(result))
|
|
45
|
+
throw new Error('Invalid Drive response: expected object');
|
|
46
|
+
const arr = result.items;
|
|
47
|
+
if (!Array.isArray(arr))
|
|
48
|
+
throw new Error('Invalid Drive response: items must be array');
|
|
49
|
+
return arr;
|
|
50
|
+
};
|
|
51
|
+
const raw = (result) => {
|
|
52
|
+
if (!isObject(result))
|
|
53
|
+
throw new Error('Invalid Drive response: expected object');
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
const isDrivePathType = (v) => v === 'file' ||
|
|
57
|
+
v === 'dir' ||
|
|
58
|
+
v === 'symlink' ||
|
|
59
|
+
v === 'index' ||
|
|
60
|
+
v === 'capsule' ||
|
|
61
|
+
v === 'note' ||
|
|
62
|
+
v === 'chat';
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Decoders
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
const decodePathEntry = (o) => {
|
|
67
|
+
const r = raw(o);
|
|
68
|
+
const t = r.type;
|
|
69
|
+
if (!isDrivePathType(t))
|
|
70
|
+
throw new Error('Invalid Drive item: type is invalid');
|
|
71
|
+
return {
|
|
72
|
+
id: strRequired(r, 'inode'),
|
|
73
|
+
name: strRequired(r, 'name'),
|
|
74
|
+
type: t,
|
|
75
|
+
parentId: str(r, 'parent_inode') ?? str(r, 'parentInode'),
|
|
76
|
+
mimeType: str(r, 'mime_type') ?? str(r, 'mimeType'),
|
|
77
|
+
fileId: str(r, 'file_id') ?? str(r, 'fileId'),
|
|
78
|
+
etag: str(r, 'etag'),
|
|
79
|
+
size: num(r, 'size'),
|
|
80
|
+
metadata: metadata(r, 'metadata'),
|
|
81
|
+
attributes: attrs(r, 'attributes'),
|
|
82
|
+
createdAt: num(r, 'created_at') ?? num(r, 'createdAt'),
|
|
83
|
+
updatedAt: num(r, 'updated_at') ?? num(r, 'updatedAt'),
|
|
84
|
+
indexingStatus: str(r, 'indexing_status') ?? str(r, 'indexingStatus'),
|
|
85
|
+
processingStatus: str(r, 'processing_status') ?? str(r, 'processingStatus'),
|
|
86
|
+
processingError: str(r, 'processing_error') ?? str(r, 'processingError'),
|
|
87
|
+
externalStatus: str(r, 'external_status') ?? str(r, 'externalStatus'),
|
|
88
|
+
externalError: str(r, 'external_error') ?? str(r, 'externalError'),
|
|
89
|
+
fullPath: str(r, 'full_path') ?? str(r, 'fullPath'),
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const decodeMutationResult = (o) => {
|
|
93
|
+
const r = raw(o);
|
|
94
|
+
const t = r.type;
|
|
95
|
+
if (!isDrivePathType(t))
|
|
96
|
+
throw new Error('Invalid Drive mutation result: type is invalid');
|
|
97
|
+
return {
|
|
98
|
+
id: strRequired(r, 'inode'),
|
|
99
|
+
parentId: str(r, 'parent_inode') ?? str(r, 'parentInode'),
|
|
100
|
+
name: strRequired(r, 'name'),
|
|
101
|
+
type: t,
|
|
102
|
+
fileId: str(r, 'file_id') ?? str(r, 'fileId'),
|
|
103
|
+
etag: str(r, 'etag'),
|
|
104
|
+
metadata: metadata(r, 'metadata'),
|
|
105
|
+
attributes: attrs(r, 'attributes'),
|
|
106
|
+
updatedAt: numRequired(r, 'updated_at'),
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const decodeDeleteResult = (o) => {
|
|
110
|
+
const r = raw(o);
|
|
111
|
+
return {
|
|
112
|
+
success: bool(r, 'success', false),
|
|
113
|
+
ids: Array.isArray(r.inodes) ? r.inodes.filter((x) => typeof x === 'string') : [],
|
|
114
|
+
size: numRequired(r, 'size'),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const decodeUploadStart = (o) => {
|
|
118
|
+
const r = raw(o);
|
|
119
|
+
return {
|
|
120
|
+
intentId: strRequired(r, 'intent_id'),
|
|
121
|
+
id: strRequired(r, 'inode'),
|
|
122
|
+
uploadUrl: strRequired(r, 'upload_url'),
|
|
123
|
+
expiresIn: numRequired(r, 'expires_in'),
|
|
124
|
+
multipart: bool(r, 'multipart', false),
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
const decodeUploadCommit = (o) => {
|
|
128
|
+
const r = raw(o);
|
|
129
|
+
return {
|
|
130
|
+
id: strRequired(r, 'inode'),
|
|
131
|
+
etag: strRequired(r, 'etag'),
|
|
132
|
+
version: numRequired(r, 'version'),
|
|
133
|
+
committedAt: strRequired(r, 'committed_at'),
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
const decodeFileMetadata = (o) => {
|
|
137
|
+
const r = raw(o);
|
|
138
|
+
return {
|
|
139
|
+
id: strRequired(r, 'inode'),
|
|
140
|
+
name: strRequired(r, 'name'),
|
|
141
|
+
size: numRequired(r, 'size'),
|
|
142
|
+
etag: str(r, 'etag'),
|
|
143
|
+
versions: numRequired(r, 'versions'),
|
|
144
|
+
createdAt: strRequired(r, 'created_at'),
|
|
145
|
+
updatedAt: strRequired(r, 'updated_at'),
|
|
146
|
+
metadata: metadata(r, 'metadata'),
|
|
147
|
+
attributes: attrs(r, 'attributes'),
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const decodeDownloadUrl = (o) => {
|
|
151
|
+
const r = raw(o);
|
|
152
|
+
return {
|
|
153
|
+
url: strRequired(r, 'url'),
|
|
154
|
+
expiresIn: numRequired(r, 'expires_in'),
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const decodeDiskUsage = (o) => {
|
|
158
|
+
const r = raw(o);
|
|
159
|
+
return { used: numRequired(r, 'used') };
|
|
160
|
+
};
|
|
161
|
+
const decodeReadFilePart = (o) => {
|
|
162
|
+
const r = raw(o);
|
|
163
|
+
const t = strRequired(r, 'type');
|
|
164
|
+
return {
|
|
165
|
+
type: t,
|
|
166
|
+
content: strRequired(r, 'content'),
|
|
167
|
+
title: str(r, 'title') ?? undefined,
|
|
168
|
+
pageNumber: num(r, 'page_number') ?? num(r, 'pageNumber') ?? undefined,
|
|
169
|
+
confidence: num(r, 'confidence') ?? undefined,
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
const decodeReadFileResult = (o) => {
|
|
173
|
+
const r = raw(o);
|
|
174
|
+
const arr = r.parts;
|
|
175
|
+
if (!Array.isArray(arr))
|
|
176
|
+
throw new Error('Invalid Drive response: parts must be array');
|
|
177
|
+
return { parts: arr.map(decodeReadFilePart) };
|
|
178
|
+
};
|
|
179
|
+
const decodeWriteResult = (o) => {
|
|
180
|
+
const r = raw(o);
|
|
181
|
+
return {
|
|
182
|
+
id: strRequired(r, 'inode'),
|
|
183
|
+
path: strRequired(r, 'path'),
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
// -- Typed tools decoders --
|
|
187
|
+
const decodeDocumentPart = (o) => {
|
|
188
|
+
const r = raw(o);
|
|
189
|
+
return {
|
|
190
|
+
type: strRequired(r, 'type'),
|
|
191
|
+
title: str(r, 'title'),
|
|
192
|
+
content: typeof r.content === 'string' ? r.content : '',
|
|
193
|
+
pageNumber: num(r, 'page_number') ?? num(r, 'pageNumber'),
|
|
194
|
+
originUrl: str(r, 'origin_url') ?? str(r, 'originUrl'),
|
|
195
|
+
author: str(r, 'author'),
|
|
196
|
+
timestamp: num(r, 'timestamp'),
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const decodeDocument = (o) => {
|
|
200
|
+
const r = raw(o);
|
|
201
|
+
const partsArr = r.parts;
|
|
202
|
+
return {
|
|
203
|
+
id: strRequired(r, 'id'),
|
|
204
|
+
parts: Array.isArray(partsArr) ? partsArr.map(decodeDocumentPart) : [],
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const isErrorResult = (o) => isObject(o) && 'error' in o;
|
|
208
|
+
const decodeLsResult = (o) => {
|
|
209
|
+
const r = raw(o);
|
|
210
|
+
const arr = r.items ?? r.entries;
|
|
211
|
+
if (!Array.isArray(arr))
|
|
212
|
+
return { entries: [] };
|
|
213
|
+
return { entries: arr.map(decodePathEntry) };
|
|
214
|
+
};
|
|
215
|
+
const decodeGlobResult = (o) => {
|
|
216
|
+
const r = raw(o);
|
|
217
|
+
const arr = r.items ?? r.entries;
|
|
218
|
+
if (!Array.isArray(arr))
|
|
219
|
+
return { entries: [] };
|
|
220
|
+
return { entries: arr.map(decodePathEntry) };
|
|
221
|
+
};
|
|
222
|
+
const decodeDocumentResults = (o) => {
|
|
223
|
+
const r = raw(o);
|
|
224
|
+
const arr = r.results ?? r.documents ?? r.items;
|
|
225
|
+
if (!Array.isArray(arr))
|
|
226
|
+
return [];
|
|
227
|
+
return arr.filter((item) => !isErrorResult(item)).map(decodeDocument);
|
|
228
|
+
};
|
|
229
|
+
const decodeGrepResult = (o) => ({
|
|
230
|
+
documents: decodeDocumentResults(o),
|
|
231
|
+
});
|
|
232
|
+
const decodeVsearchResult = (o) => ({
|
|
233
|
+
documents: decodeDocumentResults(o),
|
|
234
|
+
});
|
|
235
|
+
const decodeTableData = (o) => {
|
|
236
|
+
const r = raw(o);
|
|
237
|
+
const headers = Array.isArray(r.headers)
|
|
238
|
+
? r.headers.filter((h) => typeof h === 'string')
|
|
239
|
+
: [];
|
|
240
|
+
const rows = Array.isArray(r.rows)
|
|
241
|
+
? r.rows.map((row) => Array.isArray(row)
|
|
242
|
+
? row.map((cell) => {
|
|
243
|
+
if (typeof cell === 'string' || typeof cell === 'number' || typeof cell === 'boolean')
|
|
244
|
+
return cell;
|
|
245
|
+
return null;
|
|
246
|
+
})
|
|
247
|
+
: [])
|
|
248
|
+
: [];
|
|
249
|
+
return { headers, rows };
|
|
250
|
+
};
|
|
251
|
+
const isTableDataLike = (o) => isObject(o) && Array.isArray(o.headers) && Array.isArray(o.rows);
|
|
252
|
+
const decodeBiQueryResult = (o) => {
|
|
253
|
+
const r = raw(o);
|
|
254
|
+
const tablesRaw = r.tables;
|
|
255
|
+
if (!isObject(tablesRaw))
|
|
256
|
+
return { tables: {} };
|
|
257
|
+
const tables = {};
|
|
258
|
+
for (const [key, value] of Object.entries(tablesRaw)) {
|
|
259
|
+
if (isTableDataLike(value)) {
|
|
260
|
+
tables[key] = decodeTableData(value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return { tables };
|
|
264
|
+
};
|
|
265
|
+
const decodeInodesQueryResult = (o) => {
|
|
266
|
+
const r = raw(o);
|
|
267
|
+
const documents = decodeDocumentResults(o);
|
|
268
|
+
const tablesRaw = r.tables;
|
|
269
|
+
const tables = {};
|
|
270
|
+
if (isObject(tablesRaw)) {
|
|
271
|
+
for (const [key, value] of Object.entries(tablesRaw)) {
|
|
272
|
+
if (isTableDataLike(value)) {
|
|
273
|
+
tables[key] = decodeTableData(value);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return { documents, tables };
|
|
278
|
+
};
|
|
279
|
+
const decodeTgMessage = (o) => {
|
|
280
|
+
const r = raw(o);
|
|
281
|
+
return {
|
|
282
|
+
messageId: numRequired(r, 'message_id'),
|
|
283
|
+
text: typeof r.text === 'string' ? r.text : '',
|
|
284
|
+
senderName: typeof r.sender_name === 'string' ? r.sender_name : '',
|
|
285
|
+
date: typeof r.date === 'string' ? r.date : '',
|
|
286
|
+
timestamp: num(r, 'timestamp') ?? 0,
|
|
287
|
+
replyToMessageId: num(r, 'reply_to_message_id'),
|
|
288
|
+
isForward: bool(r, 'is_forward', false),
|
|
289
|
+
views: num(r, 'views'),
|
|
290
|
+
channelUsername: str(r, 'channel_username'),
|
|
291
|
+
originUrl: str(r, 'origin_url'),
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
const decodeTgTopic = (o) => {
|
|
295
|
+
const r = raw(o);
|
|
296
|
+
const dateRangeRaw = Array.isArray(r.date_range) ? r.date_range : [];
|
|
297
|
+
const sampleRaw = Array.isArray(r.sample_messages) ? r.sample_messages : [];
|
|
298
|
+
return {
|
|
299
|
+
topicId: typeof r.topic_id === 'string' ? r.topic_id : '',
|
|
300
|
+
title: typeof r.title === 'string' ? r.title : '',
|
|
301
|
+
summary: str(r, 'summary'),
|
|
302
|
+
messageCount: num(r, 'message_count') ?? 0,
|
|
303
|
+
dateRange: [
|
|
304
|
+
typeof dateRangeRaw[0] === 'string' ? dateRangeRaw[0] : '',
|
|
305
|
+
typeof dateRangeRaw[1] === 'string' ? dateRangeRaw[1] : '',
|
|
306
|
+
],
|
|
307
|
+
sampleMessages: sampleRaw.map(decodeTgMessage),
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
const decodeTgSearchResult = (o) => {
|
|
311
|
+
const r = raw(o);
|
|
312
|
+
const queryTypeRaw = r.query_type;
|
|
313
|
+
const queryType = queryTypeRaw === 'discovery' || queryTypeRaw === 'search' || queryTypeRaw === 'recent'
|
|
314
|
+
? queryTypeRaw
|
|
315
|
+
: 'search';
|
|
316
|
+
const topicsRaw = Array.isArray(r.topics) ? r.topics : null;
|
|
317
|
+
const topics = topicsRaw ? topicsRaw.map(decodeTgTopic) : null;
|
|
318
|
+
const messagesRaw = Array.isArray(r.messages) ? r.messages : null;
|
|
319
|
+
const messages = messagesRaw
|
|
320
|
+
? messagesRaw.map((item) => {
|
|
321
|
+
const entry = raw(item);
|
|
322
|
+
return {
|
|
323
|
+
message: decodeTgMessage(entry.message),
|
|
324
|
+
score: num(entry, 'score'),
|
|
325
|
+
replyContext: isObject(entry.reply_context) ? decodeTgMessage(entry.reply_context) : null,
|
|
326
|
+
};
|
|
327
|
+
})
|
|
328
|
+
: null;
|
|
329
|
+
const dateRangeRaw = Array.isArray(r.date_range_applied) ? r.date_range_applied : null;
|
|
330
|
+
const dateRangeApplied = dateRangeRaw
|
|
331
|
+
? [
|
|
332
|
+
typeof dateRangeRaw[0] === 'string' ? dateRangeRaw[0] : '',
|
|
333
|
+
typeof dateRangeRaw[1] === 'string' ? dateRangeRaw[1] : '',
|
|
334
|
+
]
|
|
335
|
+
: null;
|
|
336
|
+
return {
|
|
337
|
+
queryType,
|
|
338
|
+
topics,
|
|
339
|
+
messages,
|
|
340
|
+
totalFound: numRequired(r, 'total_found'),
|
|
341
|
+
dateRangeApplied,
|
|
342
|
+
databasePath: typeof r.database_path === 'string' ? r.database_path : '',
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
// ---------------------------------------------------------------------------
|
|
346
|
+
// Encode helpers (domain params -> wire snake_case)
|
|
347
|
+
// ---------------------------------------------------------------------------
|
|
348
|
+
const optional = (key, value) => value !== undefined ? { [key]: value } : {};
|
|
349
|
+
// ---------------------------------------------------------------------------
|
|
350
|
+
// SHA256 helper (Web Crypto -- works in Node 18+ and browsers)
|
|
351
|
+
// ---------------------------------------------------------------------------
|
|
352
|
+
const toArrayBuffer = (data) => data instanceof ArrayBuffer ? data : new Uint8Array(data).buffer;
|
|
353
|
+
const sha256hex = async (data) => {
|
|
354
|
+
const buf = await globalThis.crypto.subtle.digest('SHA-256', toArrayBuffer(data));
|
|
355
|
+
const bytes = new Uint8Array(buf);
|
|
356
|
+
let hex = '';
|
|
357
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
358
|
+
hex += bytes[i].toString(16).padStart(2, '0');
|
|
359
|
+
}
|
|
360
|
+
return hex;
|
|
361
|
+
};
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// Client factory
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
export const createDriveClient = (params) => {
|
|
366
|
+
const rpcUrl = params.url
|
|
367
|
+
? params.url.replace(/\/+$/, '')
|
|
368
|
+
: `${resolveDiskdGatewayUrl('os/drive')}/api/v1`;
|
|
369
|
+
let nextId = 1;
|
|
370
|
+
const call = async (method, rpcParams) => {
|
|
371
|
+
const id = nextId;
|
|
372
|
+
nextId += 1;
|
|
373
|
+
if (params.auth.getRequestHeaders) {
|
|
374
|
+
const headers = await params.auth.getRequestHeaders();
|
|
375
|
+
return jsonRpcCall({ url: rpcUrl, headers, method, rpcParams, id });
|
|
376
|
+
}
|
|
377
|
+
const bearerToken = await params.auth.getAccessToken();
|
|
378
|
+
return jsonRpcCall({ url: rpcUrl, bearerToken, method, rpcParams, id });
|
|
379
|
+
};
|
|
380
|
+
const db = createDriveDbClient({ call });
|
|
381
|
+
const crontab = createDriveCrontabClient({ call });
|
|
382
|
+
const sessionRpc = createDriveSessionClient({ call });
|
|
383
|
+
const session = createDriveSessionManager({ rpc: sessionRpc });
|
|
384
|
+
return {
|
|
385
|
+
// -- Init --
|
|
386
|
+
init: async () => {
|
|
387
|
+
await call('drive/init', {});
|
|
388
|
+
},
|
|
389
|
+
// -- Path operations --
|
|
390
|
+
list: async (listParams) => {
|
|
391
|
+
const result = await call('drive/paths/list', {
|
|
392
|
+
...optional('path', listParams?.path),
|
|
393
|
+
});
|
|
394
|
+
return items(result).map(decodePathEntry);
|
|
395
|
+
},
|
|
396
|
+
create: async (p) => {
|
|
397
|
+
const name = 'name' in p ? p.name : p.dirName;
|
|
398
|
+
const type = 'type' in p ? p.type : 'dir';
|
|
399
|
+
const result = await call('drive/paths/create', {
|
|
400
|
+
name,
|
|
401
|
+
dir_name: name,
|
|
402
|
+
type,
|
|
403
|
+
...optional('parent_path', p.parentPath),
|
|
404
|
+
...optional('metadata', p.metadata),
|
|
405
|
+
...optional('file_id', p.fileId),
|
|
406
|
+
});
|
|
407
|
+
return decodeMutationResult(result);
|
|
408
|
+
},
|
|
409
|
+
rename: async (p) => {
|
|
410
|
+
const result = await call('drive/paths/rename', {
|
|
411
|
+
path: p.path,
|
|
412
|
+
new_name: p.newName,
|
|
413
|
+
...optional('new_parent_path', p.newParentPath),
|
|
414
|
+
});
|
|
415
|
+
return decodeMutationResult(result);
|
|
416
|
+
},
|
|
417
|
+
delete: async (p) => {
|
|
418
|
+
const result = await call('drive/paths/delete', {
|
|
419
|
+
paths: [...p.paths],
|
|
420
|
+
...optional('recursive', p.recursive),
|
|
421
|
+
});
|
|
422
|
+
return decodeDeleteResult(result);
|
|
423
|
+
},
|
|
424
|
+
resolve: async (p) => {
|
|
425
|
+
const result = await call('drive/paths/resolve', {
|
|
426
|
+
paths: [...p.paths],
|
|
427
|
+
});
|
|
428
|
+
return items(result).map(decodePathEntry);
|
|
429
|
+
},
|
|
430
|
+
updateMetadata: async (p) => {
|
|
431
|
+
const result = await call('drive/paths/update-metadata', {
|
|
432
|
+
path: p.path,
|
|
433
|
+
metadata: { ...p.metadata },
|
|
434
|
+
});
|
|
435
|
+
return decodeMutationResult(result);
|
|
436
|
+
},
|
|
437
|
+
updateAttributes: async (p) => {
|
|
438
|
+
const result = await call('drive/paths/update-attributes', {
|
|
439
|
+
path: p.path,
|
|
440
|
+
attributes: [...p.attributes],
|
|
441
|
+
});
|
|
442
|
+
return decodeMutationResult(result);
|
|
443
|
+
},
|
|
444
|
+
// -- Upload --
|
|
445
|
+
upload: {
|
|
446
|
+
file: async (p) => {
|
|
447
|
+
// Resolve size, hash, and body based on input type (buffer vs stream)
|
|
448
|
+
const isStream = p.stream !== undefined;
|
|
449
|
+
const fileSize = isStream
|
|
450
|
+
? p.size
|
|
451
|
+
: p.data instanceof Uint8Array
|
|
452
|
+
? p.data.byteLength
|
|
453
|
+
: p.data.byteLength;
|
|
454
|
+
const hash = isStream ? p.sha256Root : await sha256hex(p.data);
|
|
455
|
+
const body = isStream
|
|
456
|
+
? p.stream
|
|
457
|
+
: toArrayBuffer(p.data instanceof Uint8Array ? p.data : new Uint8Array(p.data));
|
|
458
|
+
// 1. Start upload intent
|
|
459
|
+
const intent = await (async () => {
|
|
460
|
+
const result = await call('drive/upload/start', {
|
|
461
|
+
name: p.name,
|
|
462
|
+
size: fileSize,
|
|
463
|
+
sha256_root: hash,
|
|
464
|
+
...optional('parent_path', p.parentPath),
|
|
465
|
+
...optional('mime_type', p.mimeType),
|
|
466
|
+
...optional('force', p.force),
|
|
467
|
+
});
|
|
468
|
+
return decodeUploadStart(result);
|
|
469
|
+
})();
|
|
470
|
+
p.onProgress?.(0, fileSize);
|
|
471
|
+
// 2. PUT the file data to the upload proxy
|
|
472
|
+
const uploadUrl = rpcUrl.replace(/\/+$/, '').replace(/\/api\/v1$/, '') + intent.uploadUrl;
|
|
473
|
+
const authHeaders = params.auth.getRequestHeaders
|
|
474
|
+
? await params.auth.getRequestHeaders()
|
|
475
|
+
: { Authorization: `Bearer ${await params.auth.getAccessToken()}` };
|
|
476
|
+
const putResponse = await fetch(uploadUrl, {
|
|
477
|
+
method: 'PUT',
|
|
478
|
+
headers: {
|
|
479
|
+
...authHeaders,
|
|
480
|
+
'Content-Type': p.mimeType ?? 'application/octet-stream',
|
|
481
|
+
'X-Upload-Intent-Id': intent.intentId,
|
|
482
|
+
},
|
|
483
|
+
body,
|
|
484
|
+
...(isStream ? { duplex: 'half' } : {}),
|
|
485
|
+
});
|
|
486
|
+
if (!putResponse.ok) {
|
|
487
|
+
const text = await putResponse.text();
|
|
488
|
+
throw new Error(`Upload PUT failed (HTTP ${putResponse.status}): ${text.slice(0, 200)}`);
|
|
489
|
+
}
|
|
490
|
+
const putBody = (await putResponse.json());
|
|
491
|
+
const etag = putBody.etag ?? putResponse.headers.get('etag') ?? '';
|
|
492
|
+
if (!etag) {
|
|
493
|
+
throw new Error('Upload PUT response missing etag');
|
|
494
|
+
}
|
|
495
|
+
p.onProgress?.(fileSize, fileSize);
|
|
496
|
+
// 3. Commit
|
|
497
|
+
const commitResult = await (async () => {
|
|
498
|
+
const result = await call('drive/upload/commit', {
|
|
499
|
+
intent_id: intent.intentId,
|
|
500
|
+
etag,
|
|
501
|
+
});
|
|
502
|
+
return decodeUploadCommit(result);
|
|
503
|
+
})();
|
|
504
|
+
return {
|
|
505
|
+
id: commitResult.id,
|
|
506
|
+
etag: commitResult.etag,
|
|
507
|
+
version: commitResult.version,
|
|
508
|
+
committedAt: commitResult.committedAt,
|
|
509
|
+
intentId: intent.intentId,
|
|
510
|
+
};
|
|
511
|
+
},
|
|
512
|
+
start: async (p) => {
|
|
513
|
+
const result = await call('drive/upload/start', {
|
|
514
|
+
name: p.name,
|
|
515
|
+
size: p.size,
|
|
516
|
+
sha256_root: p.sha256Root,
|
|
517
|
+
...optional('parent_path', p.parentPath),
|
|
518
|
+
...optional('mime_type', p.mimeType),
|
|
519
|
+
...optional('force', p.force),
|
|
520
|
+
});
|
|
521
|
+
return decodeUploadStart(result);
|
|
522
|
+
},
|
|
523
|
+
commit: async (p) => {
|
|
524
|
+
const result = await call('drive/upload/commit', {
|
|
525
|
+
intent_id: p.intentId,
|
|
526
|
+
etag: p.etag,
|
|
527
|
+
});
|
|
528
|
+
return decodeUploadCommit(result);
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
// -- Download --
|
|
532
|
+
download: {
|
|
533
|
+
file: async (p) => {
|
|
534
|
+
// 1. Get signed download URL
|
|
535
|
+
const dlResult = await call('drive/files/download-url', {
|
|
536
|
+
path: p.path,
|
|
537
|
+
...optional('version', p.version),
|
|
538
|
+
});
|
|
539
|
+
const { url } = decodeDownloadUrl(dlResult);
|
|
540
|
+
// 2. Fetch the file -- stream body, do not buffer
|
|
541
|
+
const authHeaders = params.auth.getRequestHeaders
|
|
542
|
+
? await params.auth.getRequestHeaders()
|
|
543
|
+
: { Authorization: `Bearer ${await params.auth.getAccessToken()}` };
|
|
544
|
+
const response = await fetch(url, { headers: authHeaders });
|
|
545
|
+
if (!response.ok) {
|
|
546
|
+
const text = await response.text();
|
|
547
|
+
throw new Error(`Download failed (HTTP ${response.status}): ${text.slice(0, 200)}`);
|
|
548
|
+
}
|
|
549
|
+
const size = Number(response.headers.get('content-length') ?? '0');
|
|
550
|
+
const mimeType = response.headers.get('content-type');
|
|
551
|
+
const body = response.body;
|
|
552
|
+
if (!body)
|
|
553
|
+
throw new Error('Download response has no body');
|
|
554
|
+
// 3. Wrap stream with progress tracking if callback provided
|
|
555
|
+
const stream = p.onProgress
|
|
556
|
+
? (() => {
|
|
557
|
+
let downloaded = 0;
|
|
558
|
+
const reader = body.getReader();
|
|
559
|
+
p.onProgress?.(0, size);
|
|
560
|
+
return new ReadableStream({
|
|
561
|
+
async pull(controller) {
|
|
562
|
+
const { done, value } = await reader.read();
|
|
563
|
+
if (done) {
|
|
564
|
+
controller.close();
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
downloaded += value.byteLength;
|
|
568
|
+
p.onProgress?.(downloaded, size);
|
|
569
|
+
controller.enqueue(value);
|
|
570
|
+
},
|
|
571
|
+
cancel(reason) {
|
|
572
|
+
reader.cancel(reason);
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
})()
|
|
576
|
+
: body;
|
|
577
|
+
return { stream, size, mimeType };
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
// -- Files --
|
|
581
|
+
files: {
|
|
582
|
+
metadata: async (p) => {
|
|
583
|
+
const result = await call('drive/files/metadata', { path: p.path });
|
|
584
|
+
return decodeFileMetadata(result);
|
|
585
|
+
},
|
|
586
|
+
metadataBatch: async (p) => {
|
|
587
|
+
const result = await call('drive/files/metadata/batch', {
|
|
588
|
+
paths: [...p.paths],
|
|
589
|
+
});
|
|
590
|
+
return items(result).map(decodePathEntry);
|
|
591
|
+
},
|
|
592
|
+
downloadUrl: async (p) => {
|
|
593
|
+
const result = await call('drive/files/download-url', {
|
|
594
|
+
path: p.path,
|
|
595
|
+
...optional('version', p.version),
|
|
596
|
+
});
|
|
597
|
+
return decodeDownloadUrl(result);
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
// -- Disk usage --
|
|
601
|
+
diskUsage: async () => {
|
|
602
|
+
const result = await call('drive/disk-usage', {});
|
|
603
|
+
return decodeDiskUsage(result);
|
|
604
|
+
},
|
|
605
|
+
// -- Tools (path-based query operations) --
|
|
606
|
+
tools: {
|
|
607
|
+
ls: async (p) => {
|
|
608
|
+
const result = await call('paths/tools/ls', {
|
|
609
|
+
...optional('path', p?.path),
|
|
610
|
+
...optional('recursive', p?.recursive),
|
|
611
|
+
...optional('show_hidden', p?.showHidden),
|
|
612
|
+
...optional('show_system', p?.showSystem),
|
|
613
|
+
});
|
|
614
|
+
return decodeLsResult(result);
|
|
615
|
+
},
|
|
616
|
+
glob: async (p) => {
|
|
617
|
+
const result = await call('paths/tools/glob', {
|
|
618
|
+
pattern: p.pattern,
|
|
619
|
+
...optional('path', p.path),
|
|
620
|
+
...optional('show_hidden', p?.showHidden),
|
|
621
|
+
...optional('show_system', p?.showSystem),
|
|
622
|
+
});
|
|
623
|
+
return decodeGlobResult(result);
|
|
624
|
+
},
|
|
625
|
+
grep: async (p) => {
|
|
626
|
+
const result = await call('paths/tools/grep', {
|
|
627
|
+
query: p.query,
|
|
628
|
+
paths: [...p.paths],
|
|
629
|
+
});
|
|
630
|
+
return decodeGrepResult(result);
|
|
631
|
+
},
|
|
632
|
+
vsearch: async (p) => {
|
|
633
|
+
const result = await call('paths/tools/vsearch', {
|
|
634
|
+
query: p.query,
|
|
635
|
+
...optional('top_k', p.topK),
|
|
636
|
+
paths: [...p.paths],
|
|
637
|
+
});
|
|
638
|
+
return decodeVsearchResult(result);
|
|
639
|
+
},
|
|
640
|
+
readFile: async (p) => {
|
|
641
|
+
const result = await call('paths/tools/read', {
|
|
642
|
+
path: p.path,
|
|
643
|
+
...optional('parts_limit', p.partsLimit),
|
|
644
|
+
...optional('parts_offset', p.partsOffset),
|
|
645
|
+
});
|
|
646
|
+
return decodeReadFileResult(result);
|
|
647
|
+
},
|
|
648
|
+
writeFile: async (p) => {
|
|
649
|
+
const result = await call('paths/tools/write', {
|
|
650
|
+
path: p.path,
|
|
651
|
+
content: p.content,
|
|
652
|
+
});
|
|
653
|
+
return decodeWriteResult(result);
|
|
654
|
+
},
|
|
655
|
+
applyPatch: async (p) => {
|
|
656
|
+
const result = await call('paths/tools/apply-patch', {
|
|
657
|
+
path: p.path,
|
|
658
|
+
patch: p.patch,
|
|
659
|
+
});
|
|
660
|
+
return decodeWriteResult(result);
|
|
661
|
+
},
|
|
662
|
+
biQuery: async (p) => {
|
|
663
|
+
const result = await call('paths/tools/bi-query', {
|
|
664
|
+
query: p.query,
|
|
665
|
+
paths: [...p.paths],
|
|
666
|
+
});
|
|
667
|
+
return decodeBiQueryResult(result);
|
|
668
|
+
},
|
|
669
|
+
inodesQuery: async (p) => {
|
|
670
|
+
const result = await call('paths/tools/inodes-query', {
|
|
671
|
+
query: p.query,
|
|
672
|
+
paths: [...p.paths],
|
|
673
|
+
...optional('date_start', p.dateStart),
|
|
674
|
+
...optional('date_end', p.dateEnd),
|
|
675
|
+
...optional('order_by', p.orderBy),
|
|
676
|
+
...optional('limit', p.limit),
|
|
677
|
+
...optional('offset', p.offset),
|
|
678
|
+
});
|
|
679
|
+
return decodeInodesQueryResult(result);
|
|
680
|
+
},
|
|
681
|
+
tgSearch: async (p) => {
|
|
682
|
+
const result = await call('paths/tools/tg-search', {
|
|
683
|
+
database_path: p.databasePath,
|
|
684
|
+
...optional('query', p.query),
|
|
685
|
+
...optional('limit', p.limit),
|
|
686
|
+
...optional('offset', p.offset),
|
|
687
|
+
...optional('date_start', p.dateStart),
|
|
688
|
+
...optional('date_end', p.dateEnd),
|
|
689
|
+
...optional('order_by', p.orderBy),
|
|
690
|
+
});
|
|
691
|
+
return decodeTgSearchResult(result);
|
|
692
|
+
},
|
|
693
|
+
excelWrite: async (p) => {
|
|
694
|
+
const result = await call('paths/tools/excel-write', {
|
|
695
|
+
path: p.path,
|
|
696
|
+
headers: [...p.headers],
|
|
697
|
+
rows: p.rows.map((row) => [...row]),
|
|
698
|
+
...optional('sheet_name', p.sheetName),
|
|
699
|
+
});
|
|
700
|
+
return decodeWriteResult(result);
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
// -- Database --
|
|
704
|
+
db,
|
|
705
|
+
// -- Crontab --
|
|
706
|
+
crontab,
|
|
707
|
+
// -- Session --
|
|
708
|
+
session,
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
//# sourceMappingURL=drive.js.map
|