@optima-chat/agentic-sdk 0.11.0 → 0.12.0
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/hooks/use-workspace-files.d.ts +18 -0
- package/dist/hooks/use-workspace-files.d.ts.map +1 -0
- package/dist/hooks/use-workspace-files.js +52 -0
- package/dist/hooks/use-workspace-files.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/workspace/default-provider.d.ts +21 -10
- package/dist/workspace/default-provider.d.ts.map +1 -1
- package/dist/workspace/default-provider.js +151 -26
- package/dist/workspace/default-provider.js.map +1 -1
- package/dist/workspace/errors.d.ts +12 -0
- package/dist/workspace/errors.d.ts.map +1 -0
- package/dist/workspace/errors.js +17 -0
- package/dist/workspace/errors.js.map +1 -0
- package/dist/workspace/types.d.ts +72 -5
- package/dist/workspace/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChatError, UploadResult } from '../types.js';
|
|
2
|
+
import type { DeleteOptions, UploadOptions, WorkspaceFile } from '../workspace/types.js';
|
|
3
|
+
export interface UseWorkspaceFilesOptions {
|
|
4
|
+
path?: string;
|
|
5
|
+
includeStats?: boolean;
|
|
6
|
+
/** Auto-fetch on mount and on path/includeStats change. Defaults to true. */
|
|
7
|
+
autoLoad?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface UseWorkspaceFilesResult {
|
|
10
|
+
files: WorkspaceFile[];
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: ChatError | null;
|
|
13
|
+
refresh: () => Promise<void>;
|
|
14
|
+
upload: (files: File[], options?: UploadOptions) => Promise<UploadResult[]>;
|
|
15
|
+
deleteFile: (path: string, options?: DeleteOptions) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare function useWorkspaceFiles(options?: UseWorkspaceFilesOptions): UseWorkspaceFilesResult;
|
|
18
|
+
//# sourceMappingURL=use-workspace-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-workspace-files.d.ts","sourceRoot":"","sources":["../../src/hooks/use-workspace-files.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5E,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAaD,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,wBAA6B,GACrC,uBAAuB,CAkDzB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { useChatContext } from '../provider/chat-context.js';
|
|
3
|
+
function toChatError(err) {
|
|
4
|
+
if (err && typeof err === 'object') {
|
|
5
|
+
const anyErr = err;
|
|
6
|
+
return {
|
|
7
|
+
code: anyErr.code ?? 'UNKNOWN',
|
|
8
|
+
message: anyErr.message ?? String(err),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return { code: 'UNKNOWN', message: String(err) };
|
|
12
|
+
}
|
|
13
|
+
export function useWorkspaceFiles(options = {}) {
|
|
14
|
+
const { workspaceProvider } = useChatContext();
|
|
15
|
+
if (!workspaceProvider) {
|
|
16
|
+
throw new Error('useWorkspaceFiles requires a workspaceProvider on <ChatProvider>');
|
|
17
|
+
}
|
|
18
|
+
const { path, includeStats, autoLoad = true } = options;
|
|
19
|
+
const [files, setFiles] = useState([]);
|
|
20
|
+
const [loading, setLoading] = useState(autoLoad);
|
|
21
|
+
const [error, setError] = useState(null);
|
|
22
|
+
const refresh = useCallback(async () => {
|
|
23
|
+
setLoading(true);
|
|
24
|
+
setError(null);
|
|
25
|
+
try {
|
|
26
|
+
const next = await workspaceProvider.listFiles({ path, includeStats });
|
|
27
|
+
setFiles(next);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
setError(toChatError(err));
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
setLoading(false);
|
|
34
|
+
}
|
|
35
|
+
}, [workspaceProvider, path, includeStats]);
|
|
36
|
+
const upload = useCallback(async (incoming, uploadOptions) => {
|
|
37
|
+
const results = await workspaceProvider.uploadFiles(incoming, uploadOptions);
|
|
38
|
+
await refresh();
|
|
39
|
+
return results;
|
|
40
|
+
}, [workspaceProvider, refresh]);
|
|
41
|
+
const deleteFile = useCallback(async (target, deleteOptions) => {
|
|
42
|
+
await workspaceProvider.deleteFile(target, deleteOptions);
|
|
43
|
+
await refresh();
|
|
44
|
+
}, [workspaceProvider, refresh]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!autoLoad)
|
|
47
|
+
return;
|
|
48
|
+
void refresh();
|
|
49
|
+
}, [autoLoad, refresh]);
|
|
50
|
+
return { files, loading, error, refresh, upload, deleteFile };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=use-workspace-files.js.map
|
|
@@ -0,0 +1 @@
|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ist/index.d.ts
CHANGED
|
@@ -7,8 +7,11 @@ export { useQuestion } from './hooks/use-question.js';
|
|
|
7
7
|
export { useApproval } from './hooks/use-approval.js';
|
|
8
8
|
export { useSwitchConfig } from './hooks/use-switch-config.js';
|
|
9
9
|
export { useProcessingConversations } from './hooks/use-processing-conversations.js';
|
|
10
|
+
export { useWorkspaceFiles } from './hooks/use-workspace-files.js';
|
|
11
|
+
export type { UseWorkspaceFilesOptions, UseWorkspaceFilesResult } from './hooks/use-workspace-files.js';
|
|
10
12
|
export type { ChatProviderProps, ConnectionState, MessageStatus, ToolCallStatus, ChatError, Conversation, ConversationLastMessageKind, Message, MessageAttachment, ToolCall, QuestionRequest, ApprovalRequestWithId, SendMessageOptions, UploadResult, } from './types.js';
|
|
11
|
-
export type { WorkspaceProvider } from './workspace/types.js';
|
|
12
|
-
export {
|
|
13
|
+
export type { WorkspaceProvider, WorkspaceFile, FilePreview, ShareLink, UploadProgress, AuthenticatedUploader, UploadOptions, ListOptions, DeleteOptions, } from './workspace/types.js';
|
|
14
|
+
export { WorkspaceFileError } from './workspace/errors.js';
|
|
15
|
+
export { createDefaultWorkspaceProvider, type DefaultWorkspaceProviderOptions, } from './workspace/default-provider.js';
|
|
13
16
|
export type { ServerEvent, ClientEvent, FinishInfo, Question, ApprovalRequest, ApprovalResponse, TokenProgress, BillingError, } from '@optima-chat/gateway-protocol';
|
|
14
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAA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MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,8BAA8B,EAC9B,KAAK,+BAA+B,GACrC,MAAM,iCAAiC,CAAC;AAGzC,YAAY,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,YAAY,GACb,MAAM,+BAA+B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,5 +9,7 @@ export { useQuestion } from './hooks/use-question.js';
|
|
|
9
9
|
export { useApproval } from './hooks/use-approval.js';
|
|
10
10
|
export { useSwitchConfig } from './hooks/use-switch-config.js';
|
|
11
11
|
export { useProcessingConversations } from './hooks/use-processing-conversations.js';
|
|
12
|
-
export {
|
|
12
|
+
export { useWorkspaceFiles } from './hooks/use-workspace-files.js';
|
|
13
|
+
export { WorkspaceFileError } from './workspace/errors.js';
|
|
14
|
+
export { createDefaultWorkspaceProvider, } from './workspace/default-provider.js';
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,QAAQ;AACR,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,QAAQ;AACR,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAiCnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,8BAA8B,GAE/B,MAAM,iCAAiC,CAAC"}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import type { WorkspaceProvider } from './types.js';
|
|
1
|
+
import type { AuthenticatedUploader, WorkspaceProvider } from './types.js';
|
|
2
|
+
export interface DefaultWorkspaceProviderOptions {
|
|
3
|
+
/** XHR-based uploader for progress events; falls back to `authenticatedFetch` if omitted. */
|
|
4
|
+
authenticatedUploader?: AuthenticatedUploader;
|
|
5
|
+
}
|
|
6
|
+
type AuthFetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
2
7
|
/**
|
|
3
|
-
* Default WorkspaceProvider backed by the gateway's
|
|
4
|
-
*
|
|
5
|
-
* - `uploadFiles` POSTs each file individually to `/api/workspace/upload` as
|
|
6
|
-
* FormData (field name `file`) and expects a JSON response with a `url`
|
|
7
|
-
* field.
|
|
8
|
-
* - `resolveFileUrl` returns a GET URL under `/api/workspace/files/<path>`.
|
|
9
|
-
*
|
|
8
|
+
* Default WorkspaceProvider backed by the gateway's `/api/user/files/*` family.
|
|
10
9
|
* Consumers with a different backend can pass their own WorkspaceProvider to
|
|
11
|
-
*
|
|
10
|
+
* `<ChatProvider>`.
|
|
11
|
+
*
|
|
12
|
+
* @param gatewayBaseUrl Gateway origin (e.g. `https://gateway.example.com`).
|
|
13
|
+
* Trailing slash tolerated.
|
|
14
|
+
* @param authenticatedFetch Bearer-token-attaching fetch (typically from
|
|
15
|
+
* `@optima-chat/agentic-auth`'s
|
|
16
|
+
* `createAuthenticatedFetch`).
|
|
17
|
+
* @param options Optional. Pass `authenticatedUploader` (from the
|
|
18
|
+
* auth package's `createAuthenticatedUploader`) to get
|
|
19
|
+
* per-file upload progress; otherwise upload falls
|
|
20
|
+
* back to plain `authenticatedFetch + FormData`
|
|
21
|
+
* (no progress events).
|
|
12
22
|
*/
|
|
13
|
-
export declare function createDefaultWorkspaceProvider(gatewayBaseUrl: string, authenticatedFetch:
|
|
23
|
+
export declare function createDefaultWorkspaceProvider(gatewayBaseUrl: string, authenticatedFetch: AuthFetch, options?: DefaultWorkspaceProviderOptions): WorkspaceProvider;
|
|
24
|
+
export {};
|
|
14
25
|
//# sourceMappingURL=default-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-provider.d.ts","sourceRoot":"","sources":["../../src/workspace/default-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"default-provider.d.ts","sourceRoot":"","sources":["../../src/workspace/default-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAOrB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,+BAA+B;IAC9C,6FAA6F;IAC7F,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AA+CxE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,8BAA8B,CAC5C,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,SAAS,EAC7B,OAAO,GAAE,+BAAoC,GAC5C,iBAAiB,CAsInB"}
|
|
@@ -1,45 +1,170 @@
|
|
|
1
|
+
import { WorkspaceFileError } from './errors.js';
|
|
2
|
+
function joinContainerPath(dir, name) {
|
|
3
|
+
return dir.endsWith('/') ? `${dir}${name}` : `${dir}/${name}`;
|
|
4
|
+
}
|
|
5
|
+
function toWorkspaceFile(parentPath, entry) {
|
|
6
|
+
return {
|
|
7
|
+
name: entry.name,
|
|
8
|
+
path: joinContainerPath(parentPath, entry.name),
|
|
9
|
+
size: entry.size ?? 0,
|
|
10
|
+
modifiedAt: entry.modified ?? '',
|
|
11
|
+
type: entry.type,
|
|
12
|
+
...(entry.permissions !== undefined && { permissions: entry.permissions }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async function asWorkspaceError(res, fallbackOp) {
|
|
16
|
+
let code = 'UNKNOWN';
|
|
17
|
+
let message = `${fallbackOp} failed: ${res.status}`;
|
|
18
|
+
try {
|
|
19
|
+
const body = (await res.json());
|
|
20
|
+
if (body.error?.code)
|
|
21
|
+
code = body.error.code;
|
|
22
|
+
if (body.error?.message)
|
|
23
|
+
message = body.error.message;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// body wasn't JSON — keep defaults
|
|
27
|
+
}
|
|
28
|
+
return new WorkspaceFileError(res.status, code, message);
|
|
29
|
+
}
|
|
1
30
|
/**
|
|
2
|
-
* Default WorkspaceProvider backed by the gateway's
|
|
3
|
-
*
|
|
4
|
-
* - `uploadFiles` POSTs each file individually to `/api/workspace/upload` as
|
|
5
|
-
* FormData (field name `file`) and expects a JSON response with a `url`
|
|
6
|
-
* field.
|
|
7
|
-
* - `resolveFileUrl` returns a GET URL under `/api/workspace/files/<path>`.
|
|
8
|
-
*
|
|
31
|
+
* Default WorkspaceProvider backed by the gateway's `/api/user/files/*` family.
|
|
9
32
|
* Consumers with a different backend can pass their own WorkspaceProvider to
|
|
10
|
-
*
|
|
33
|
+
* `<ChatProvider>`.
|
|
34
|
+
*
|
|
35
|
+
* @param gatewayBaseUrl Gateway origin (e.g. `https://gateway.example.com`).
|
|
36
|
+
* Trailing slash tolerated.
|
|
37
|
+
* @param authenticatedFetch Bearer-token-attaching fetch (typically from
|
|
38
|
+
* `@optima-chat/agentic-auth`'s
|
|
39
|
+
* `createAuthenticatedFetch`).
|
|
40
|
+
* @param options Optional. Pass `authenticatedUploader` (from the
|
|
41
|
+
* auth package's `createAuthenticatedUploader`) to get
|
|
42
|
+
* per-file upload progress; otherwise upload falls
|
|
43
|
+
* back to plain `authenticatedFetch + FormData`
|
|
44
|
+
* (no progress events).
|
|
11
45
|
*/
|
|
12
|
-
export function createDefaultWorkspaceProvider(gatewayBaseUrl, authenticatedFetch) {
|
|
13
|
-
const base = gatewayBaseUrl.endsWith('/')
|
|
14
|
-
|
|
15
|
-
|
|
46
|
+
export function createDefaultWorkspaceProvider(gatewayBaseUrl, authenticatedFetch, options = {}) {
|
|
47
|
+
const base = gatewayBaseUrl.endsWith('/') ? gatewayBaseUrl.slice(0, -1) : gatewayBaseUrl;
|
|
48
|
+
const uploader = options.authenticatedUploader;
|
|
49
|
+
function buildUrl(path, query) {
|
|
50
|
+
const qs = query
|
|
51
|
+
? Object.entries(query)
|
|
52
|
+
.filter(([, v]) => v !== undefined)
|
|
53
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
54
|
+
.join('&')
|
|
55
|
+
: '';
|
|
56
|
+
return qs ? `${base}${path}?${qs}` : `${base}${path}`;
|
|
57
|
+
}
|
|
16
58
|
return {
|
|
17
|
-
async uploadFiles(files) {
|
|
59
|
+
async uploadFiles(files, options = {}) {
|
|
60
|
+
const targetPath = options.path ?? '/home/aiuser';
|
|
61
|
+
const url = `${base}/api/user/files`;
|
|
18
62
|
const results = [];
|
|
19
63
|
for (const file of files) {
|
|
20
64
|
const formData = new FormData();
|
|
65
|
+
// path MUST come before file — gateway sets targetPath as it consumes parts in append order
|
|
66
|
+
formData.append('path', targetPath);
|
|
21
67
|
formData.append('file', file);
|
|
22
|
-
const res =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
68
|
+
const res = uploader
|
|
69
|
+
? await uploader(url, formData, options.onProgress
|
|
70
|
+
? (progress) => options.onProgress(file, progress)
|
|
71
|
+
: undefined)
|
|
72
|
+
: await authenticatedFetch(url, { method: 'POST', body: formData });
|
|
73
|
+
if (!res.ok)
|
|
74
|
+
throw await asWorkspaceError(res, 'upload');
|
|
75
|
+
const body = (await res.json());
|
|
76
|
+
const uploaded = body.uploaded[0];
|
|
77
|
+
if (!uploaded) {
|
|
78
|
+
throw new WorkspaceFileError(500, 'UNKNOWN', `Upload of ${file.name} returned no entries`);
|
|
32
79
|
}
|
|
33
80
|
results.push({
|
|
34
81
|
originalName: file.name,
|
|
35
|
-
url:
|
|
82
|
+
url: uploaded.path,
|
|
36
83
|
mediaType: file.type,
|
|
37
84
|
});
|
|
38
85
|
}
|
|
39
86
|
return results;
|
|
40
87
|
},
|
|
41
|
-
|
|
42
|
-
|
|
88
|
+
async listFiles(opts = {}) {
|
|
89
|
+
const url = buildUrl('/api/user/files', {
|
|
90
|
+
path: opts.path,
|
|
91
|
+
include_stats: opts.includeStats ? 'true' : undefined,
|
|
92
|
+
});
|
|
93
|
+
const res = await authenticatedFetch(url);
|
|
94
|
+
if (!res.ok)
|
|
95
|
+
throw await asWorkspaceError(res, 'list');
|
|
96
|
+
const body = (await res.json());
|
|
97
|
+
return body.files.map((entry) => toWorkspaceFile(body.path, entry));
|
|
98
|
+
},
|
|
99
|
+
async previewFile(path) {
|
|
100
|
+
const url = buildUrl('/api/user/files/preview', { path });
|
|
101
|
+
const res = await authenticatedFetch(url);
|
|
102
|
+
if (!res.ok)
|
|
103
|
+
throw await asWorkspaceError(res, 'preview');
|
|
104
|
+
const body = (await res.json());
|
|
105
|
+
return {
|
|
106
|
+
content: body.content,
|
|
107
|
+
mimeType: body.mimeType,
|
|
108
|
+
truncated: body.truncated ?? false,
|
|
109
|
+
...(body['X-Original-Size'] !== undefined && { originalSize: body['X-Original-Size'] }),
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
async downloadFile(path) {
|
|
113
|
+
const url = buildUrl('/api/user/files/download', { path });
|
|
114
|
+
const res = await authenticatedFetch(url);
|
|
115
|
+
if (!res.ok)
|
|
116
|
+
throw await asWorkspaceError(res, 'download');
|
|
117
|
+
return res.blob();
|
|
118
|
+
},
|
|
119
|
+
async deleteFile(path, opts = {}) {
|
|
120
|
+
const url = buildUrl('/api/user/files', {
|
|
121
|
+
path,
|
|
122
|
+
recursive: opts.recursive ? 'true' : undefined,
|
|
123
|
+
});
|
|
124
|
+
const res = await authenticatedFetch(url, { method: 'DELETE' });
|
|
125
|
+
if (!res.ok)
|
|
126
|
+
throw await asWorkspaceError(res, 'delete');
|
|
127
|
+
},
|
|
128
|
+
async renameFile(oldPath, newPath) {
|
|
129
|
+
const res = await authenticatedFetch(`${base}/api/user/files/rename`, {
|
|
130
|
+
method: 'PUT',
|
|
131
|
+
headers: { 'Content-Type': 'application/json' },
|
|
132
|
+
body: JSON.stringify({ oldPath, newPath }),
|
|
133
|
+
});
|
|
134
|
+
if (!res.ok)
|
|
135
|
+
throw await asWorkspaceError(res, 'rename');
|
|
136
|
+
},
|
|
137
|
+
async makeDirectory(path) {
|
|
138
|
+
const res = await authenticatedFetch(`${base}/api/user/files/mkdir`, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: { 'Content-Type': 'application/json' },
|
|
141
|
+
body: JSON.stringify({ path }),
|
|
142
|
+
});
|
|
143
|
+
if (!res.ok)
|
|
144
|
+
throw await asWorkspaceError(res, 'mkdir');
|
|
145
|
+
},
|
|
146
|
+
async statFile(path) {
|
|
147
|
+
const url = buildUrl('/api/user/files/stat', { path });
|
|
148
|
+
const res = await authenticatedFetch(url);
|
|
149
|
+
if (!res.ok)
|
|
150
|
+
throw await asWorkspaceError(res, 'stat');
|
|
151
|
+
const body = (await res.json());
|
|
152
|
+
// Gateway returns the basename in `name`; reconstruct full path from input.
|
|
153
|
+
return {
|
|
154
|
+
name: body.name,
|
|
155
|
+
path,
|
|
156
|
+
size: body.size ?? 0,
|
|
157
|
+
modifiedAt: body.modified ?? '',
|
|
158
|
+
type: body.type,
|
|
159
|
+
...(body.permissions !== undefined && { permissions: body.permissions }),
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
async shareFile(path) {
|
|
163
|
+
const url = buildUrl('/api/user/files/share', { path });
|
|
164
|
+
const res = await authenticatedFetch(url, { method: 'POST' });
|
|
165
|
+
if (!res.ok)
|
|
166
|
+
throw await asWorkspaceError(res, 'share');
|
|
167
|
+
return (await res.json());
|
|
43
168
|
},
|
|
44
169
|
};
|
|
45
170
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-provider.js","sourceRoot":"","sources":["../../src/workspace/default-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-provider.js","sourceRoot":"","sources":["../../src/workspace/default-provider.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AA0BjD,SAAS,iBAAiB,CAAC,GAAW,EAAE,IAAY;IAClD,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;AAChE,CAAC;AAED,SAAS,eAAe,CAAC,UA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QAAQ,CAAC,IAAY;YACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YACvD,MAAM,GAAG,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,MAAM,MAAM,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACvD,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAqB,CAAC;YACpD,4EAA4E;YAC5E,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI;gBACJ,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;gBACpB,UAAU,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE;gBAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;aACzE,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,IAAY;YAC1B,MAAM,GAAG,GAAG,QAAQ,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YACxD,MAAM,GAAG,GAAG,MAAM,kBAAkB,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAC9D,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,MAAM,MAAM,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACxD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAc,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error raised by the default WorkspaceProvider when the gateway returns a
|
|
3
|
+
* non-2xx response. Consumers can branch on `status` (e.g. 409 = directory
|
|
4
|
+
* non-empty, 503 = signed-URL not configured) and `code` (gateway's symbolic
|
|
5
|
+
* error code) without parsing message strings.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WorkspaceFileError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
constructor(status: number, code: string, message: string);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/workspace/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM1D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error raised by the default WorkspaceProvider when the gateway returns a
|
|
3
|
+
* non-2xx response. Consumers can branch on `status` (e.g. 409 = directory
|
|
4
|
+
* non-empty, 503 = signed-URL not configured) and `code` (gateway's symbolic
|
|
5
|
+
* error code) without parsing message strings.
|
|
6
|
+
*/
|
|
7
|
+
export class WorkspaceFileError extends Error {
|
|
8
|
+
status;
|
|
9
|
+
code;
|
|
10
|
+
constructor(status, code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'WorkspaceFileError';
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/workspace/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,MAAM,CAAS;IACf,IAAI,CAAS;IAEtB,YAAY,MAAc,EAAE,IAAY,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1,11 +1,78 @@
|
|
|
1
1
|
import type { UploadResult } from '../types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* A file or directory entry in the user's workspace.
|
|
4
|
+
*
|
|
5
|
+
* `path` is a container-style absolute path (e.g. `/home/aiuser/uploads/foo.txt`)
|
|
6
|
+
* — the same form the gateway accepts as `?path=`. `modifiedAt` is whatever the
|
|
7
|
+
* gateway returned in the `modified` field; consumers should treat it as opaque.
|
|
8
|
+
*/
|
|
9
|
+
export interface WorkspaceFile {
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
/** File size in bytes. For directories, this is whatever the gateway reports (typically 0 or the inode size). */
|
|
13
|
+
size: number;
|
|
14
|
+
modifiedAt: string;
|
|
15
|
+
type: 'file' | 'directory';
|
|
16
|
+
permissions?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface FilePreview {
|
|
19
|
+
content: string;
|
|
20
|
+
mimeType: string;
|
|
21
|
+
/** True when content was truncated at the gateway's 1MB cap. */
|
|
22
|
+
truncated: boolean;
|
|
23
|
+
/** Total bytes of the underlying file. Always present when `truncated` is true (gateway pairs the two). */
|
|
24
|
+
originalSize?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ShareLink {
|
|
27
|
+
url: string;
|
|
28
|
+
/** ISO-8601 string, mirrors gateway response. */
|
|
29
|
+
expiresAt: string;
|
|
30
|
+
fileName: string;
|
|
31
|
+
fileSize: number;
|
|
32
|
+
}
|
|
33
|
+
/** Per-file upload progress, mirrors `@optima-chat/agentic-auth`'s `UploadProgress`. */
|
|
34
|
+
export interface UploadProgress {
|
|
35
|
+
loaded: number;
|
|
36
|
+
total: number;
|
|
37
|
+
percentage: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Optional progress-capable uploader, structurally compatible with
|
|
41
|
+
* `createAuthenticatedUploader` from `@optima-chat/agentic-auth`. Keeping this
|
|
42
|
+
* as a structural type means the SDK does not depend on the auth package.
|
|
43
|
+
*/
|
|
44
|
+
export type AuthenticatedUploader = (url: string, formData: FormData, onProgress?: (progress: UploadProgress) => void) => Promise<Response>;
|
|
45
|
+
export interface UploadOptions {
|
|
46
|
+
/** Target directory (defaults to `/home/aiuser`). */
|
|
47
|
+
path?: string;
|
|
48
|
+
/** Per-file progress callback. Implementations that don't track progress may ignore this option. */
|
|
49
|
+
onProgress?: (file: File, progress: UploadProgress) => void;
|
|
50
|
+
}
|
|
51
|
+
export interface ListOptions {
|
|
52
|
+
/** Container path to list; defaults to workspace root. */
|
|
53
|
+
path?: string;
|
|
54
|
+
/** When true, populate `size`/`modifiedAt`/`permissions` on each entry. */
|
|
55
|
+
includeStats?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface DeleteOptions {
|
|
58
|
+
/** Required to delete a non-empty directory; otherwise gateway returns 409. */
|
|
59
|
+
recursive?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Consumer-supplied abstraction for workspace file operations. The default
|
|
63
|
+
* implementation (`createDefaultWorkspaceProvider`) targets the gateway's
|
|
64
|
+
* `/api/user/files/*` family. Consumers can swap in their own (e.g. signed-S3)
|
|
65
|
+
* provider as long as the contract holds.
|
|
6
66
|
*/
|
|
7
67
|
export interface WorkspaceProvider {
|
|
8
|
-
uploadFiles: (files: File[]) => Promise<UploadResult[]>;
|
|
9
|
-
|
|
68
|
+
uploadFiles: (files: File[], options?: UploadOptions) => Promise<UploadResult[]>;
|
|
69
|
+
listFiles: (options?: ListOptions) => Promise<WorkspaceFile[]>;
|
|
70
|
+
previewFile: (path: string) => Promise<FilePreview>;
|
|
71
|
+
downloadFile: (path: string) => Promise<Blob>;
|
|
72
|
+
deleteFile: (path: string, options?: DeleteOptions) => Promise<void>;
|
|
73
|
+
renameFile: (oldPath: string, newPath: string) => Promise<void>;
|
|
74
|
+
makeDirectory: (path: string) => Promise<void>;
|
|
75
|
+
statFile: (path: string) => Promise<WorkspaceFile>;
|
|
76
|
+
shareFile: (path: string) => Promise<ShareLink>;
|
|
10
77
|
}
|
|
11
78
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workspace/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workspace/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,iHAAiH;IACjH,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,SAAS,EAAE,OAAO,CAAC;IACnB,2GAA2G;IAC3G,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,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