@ateam-ai-mobile/core 0.1.32 → 0.1.33
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/index.d.mts +77 -3
- package/dist/index.d.ts +77 -3
- package/dist/index.js +121 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/attachments.ts +139 -0
- package/src/chat/store.ts +18 -4
- package/src/chat/types.ts +2 -0
- package/src/config.ts +4 -1
- package/src/index.ts +6 -0
- package/src/storage/types.ts +57 -2
package/dist/index.d.mts
CHANGED
|
@@ -4,11 +4,63 @@ import * as zustand from 'zustand';
|
|
|
4
4
|
* Storage adapter contracts. The core is platform-agnostic (no Expo, no
|
|
5
5
|
* AsyncStorage imports) — hosts or @ateam-ai-mobile/ui plug in concrete implementations.
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
7
|
+
/** The most Core stores for one file (Core's MAX_ARTIFACT_BYTES, 90 MiB: Cloudflare allows 100 MB a request). */
|
|
8
|
+
declare const MAX_ATTACHMENT_BYTES: number;
|
|
9
|
+
/**
|
|
10
|
+
* What the old base64-in-JSON path may carry in ONE chat message, in raw bytes (all inline attachments together). Core's
|
|
11
|
+
* express.json limit is 10 MB for the WHOLE /api/chat body and base64 adds a third (7 MiB becomes ~9.3 MiB), which leaves
|
|
12
|
+
* headroom for the text and the rest of the JSON.
|
|
13
|
+
*/
|
|
14
|
+
declare const MAX_INLINE_ATTACHMENT_BYTES: number;
|
|
15
|
+
/**
|
|
16
|
+
* An attachment the user staged, as handed to `sendMessage`.
|
|
17
|
+
*
|
|
18
|
+
* A file on the phone is given by `uri` (+ `size`): it is uploaded as the raw request body to `POST /api/artifacts`, and
|
|
19
|
+
* `/api/chat` then names it by hash, so a 90 MB file never rides inside JSON. `data` (base64) is the older shape, kept for
|
|
20
|
+
* small inline attachments and as the fallback when the server is too old to take a raw upload (it answers 400).
|
|
21
|
+
*/
|
|
8
22
|
interface OutgoingAttachment {
|
|
9
|
-
data: string;
|
|
10
23
|
mimeType: string;
|
|
11
24
|
name: string;
|
|
25
|
+
/** Base64 payload (inline path). Absent when the file is given by `uri`. */
|
|
26
|
+
data?: string;
|
|
27
|
+
/** Local file URI the host's `fileUploader` can read (e.g. a file:// path). */
|
|
28
|
+
uri?: string;
|
|
29
|
+
/** Size in bytes of the file at `uri`; used to refuse an oversize file early and to decide the old-server fallback. */
|
|
30
|
+
size?: number;
|
|
31
|
+
}
|
|
32
|
+
/** What `POST /api/artifacts` answers for a stored file. */
|
|
33
|
+
interface UploadedArtifact {
|
|
34
|
+
hash: string;
|
|
35
|
+
size: number;
|
|
36
|
+
mimeType: string;
|
|
37
|
+
}
|
|
38
|
+
/** One raw upload the host's `FileUploader` performs. The SDK builds the URL and the headers; the host only moves the bytes. */
|
|
39
|
+
interface FileUploadRequest {
|
|
40
|
+
/** Absolute `POST` URL, query included. */
|
|
41
|
+
url: string;
|
|
42
|
+
/** Headers to send as given (bearer + `Content-Type: application/octet-stream`). */
|
|
43
|
+
headers: Record<string, string>;
|
|
44
|
+
/** The local file to send as the request BODY (not multipart). */
|
|
45
|
+
uri: string;
|
|
46
|
+
/** 0..1 as the bytes go out. */
|
|
47
|
+
onProgress?: (fraction: number) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The host's file I/O for attachments: streaming a local file as a request body and reading a small one as base64. Core has
|
|
51
|
+
* no filesystem or native imports, so `@ateam-ai-mobile/expo` supplies the Expo implementation (`expoFileUploader`).
|
|
52
|
+
*/
|
|
53
|
+
interface FileUploader {
|
|
54
|
+
/** Send the file at `req.uri` as the raw body; resolve with the HTTP status and body text (any status). Reject only on a transport failure. */
|
|
55
|
+
upload(req: FileUploadRequest): Promise<{
|
|
56
|
+
status: number;
|
|
57
|
+
body: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** Read a local file as base64 (the old-server fallback, files within MAX_INLINE_ATTACHMENT_BYTES). */
|
|
60
|
+
readBase64(uri: string): Promise<string>;
|
|
61
|
+
/** Size in bytes of a local file, or undefined when it cannot be told. Used only when an attachment came without `size`,
|
|
62
|
+
* before any fallback read: without it a file of unknown size is refused rather than read whole. */
|
|
63
|
+
fileSize?(uri: string): Promise<number | undefined>;
|
|
12
64
|
}
|
|
13
65
|
/** Attachment as rendered in a message bubble (local or remote preview URI). */
|
|
14
66
|
interface AttachmentPreview {
|
|
@@ -23,6 +75,7 @@ interface AttachmentPreview {
|
|
|
23
75
|
interface AttachmentCache {
|
|
24
76
|
/** Resolve once the index is loaded — get() before this may return undefined. */
|
|
25
77
|
ready(): Promise<void>;
|
|
78
|
+
/** Keep a preview of each attachment (the bytes come from `data` or are copied from `uri`). */
|
|
26
79
|
save(jobId: string, attachments: OutgoingAttachment[]): Promise<void>;
|
|
27
80
|
get(jobId: string): AttachmentPreview[] | undefined;
|
|
28
81
|
}
|
|
@@ -96,6 +149,9 @@ interface AdasConfig {
|
|
|
96
149
|
* survive app restarts. No-op when omitted (previews live in memory for
|
|
97
150
|
* the session only). @ateam-ai-mobile/ui ships an Expo/RN implementation. */
|
|
98
151
|
attachmentCache?: AttachmentCache;
|
|
152
|
+
/** Moves an attachment's bytes for `sendMessage` (raw upload of a file `uri`). Required to attach a file by `uri`;
|
|
153
|
+
* without it only base64 `data` attachments can be sent. `@ateam-ai-mobile/expo` ships `expoFileUploader`. */
|
|
154
|
+
fileUploader?: FileUploader;
|
|
99
155
|
/** Called by `switchTenant()` with the freshly-minted session for the
|
|
100
156
|
* target tenant. The host MUST persist it here (store the new JWT so
|
|
101
157
|
* tokenProvider.getToken() returns it, and update the active tenant) —
|
|
@@ -782,6 +838,8 @@ interface Message {
|
|
|
782
838
|
skillSlug?: string;
|
|
783
839
|
/** Attached images/files */
|
|
784
840
|
attachments?: MessageAttachment[];
|
|
841
|
+
/** 0..1 while this message's files are still uploading; absent once they are stored and the message is posted. */
|
|
842
|
+
uploadProgress?: number;
|
|
785
843
|
/** UI Action chips beneath assistant bubbles */
|
|
786
844
|
actions?: UIAction[];
|
|
787
845
|
/** Chain id from /api/conversation — used to attach live progress to the
|
|
@@ -847,6 +905,22 @@ declare function setClientDeclarationProvider(fn: (() => ClientDeclaration | nul
|
|
|
847
905
|
/** Tear down the live connection (env/auth switch, SDK unmount). */
|
|
848
906
|
declare function closeChatStream(): void;
|
|
849
907
|
|
|
908
|
+
/** One attachment as `/api/chat` takes it: a stored file by hash, or small inline base64. */
|
|
909
|
+
type WireAttachment = {
|
|
910
|
+
hash: string;
|
|
911
|
+
name: string;
|
|
912
|
+
mimeType: string;
|
|
913
|
+
} | {
|
|
914
|
+
data: string;
|
|
915
|
+
mimeType: string;
|
|
916
|
+
name: string;
|
|
917
|
+
};
|
|
918
|
+
/**
|
|
919
|
+
* Upload what needs uploading and return the attachments as `/api/chat` takes them, in order.
|
|
920
|
+
* `onProgress` is the overall fraction 0..1 across all attachments.
|
|
921
|
+
*/
|
|
922
|
+
declare function prepareAttachments(attachments: OutgoingAttachment[], onProgress?: (fraction: number) => void): Promise<WireAttachment[]>;
|
|
923
|
+
|
|
850
924
|
/**
|
|
851
925
|
* Lightweight event emitter bridging the chat job stream → plugin bridges
|
|
852
926
|
* (React Native has no Node 'events' module).
|
|
@@ -1284,4 +1358,4 @@ interface AcsKvStorage {
|
|
|
1284
1358
|
}
|
|
1285
1359
|
declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
|
|
1286
1360
|
|
|
1287
|
-
export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasGateFlags, type AdasPhase, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type AuthSession, type AuthSessionDeps, type AuthSessionState, type BufferedCommand, type ChannelPrefs, type ConsumerCapabilityConfig, type ConsumerProviderConfig, type ConsumerSignInResult, type DeleteResult, type DevModeState, type DevicePlatform, type DispatchRow, type HandoffExchangeResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type InvitePreview, type JobProgress, type Message, type MessageAttachment, type NotifChannel, type NotifPrefs, type OtpStartResult, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type PushBackend, type PushRegistration, type QuietHoursPrefs, type RefreshOutcome, type RegisterDeviceResponse, type Session, type SessionEnv, type SessionPersistence, type SessionStatus, type SessionUser, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TelegramBotInfo, type TenantMembership, type TenantRow, type TokenProvider, type ToolCall, type UIAction, type WorkspaceCapabilities, type WorkspaceSnapshot, type WorkspaceState, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, capabilityEnabled, closeChatStream, colors, connectAcsWs, connectorCall, createAuthSession, createPushRegistration, deleteArtifact, devModeFromCatalog, disconnectAcsWs, exchangeHandoff, fetchConsumerConfig, focusPlugin, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getPrefs as getNotifPrefs, getTelegramBotInfo as getNotifTelegramBotInfo, getSession, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, isDevHost, joinWithApple, joinWithGoogle, linkChannelStart, linkChannelVerify, linkTelegram as linkNotifTelegram, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, nestByMaster, notifyAcsWsForeground, notifyAppForeground, onAppForeground, openJoinWithApple, openJoinWithGoogle, parseDeepLinkParam, parseHandoffCode, parseInviteCode, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, previewInvite, readDevMode, recentDispatches as recentNotifDispatches, recordEvent, refreshToken, registerHostIntent, registerDevice as registerPushDevice, resolveAdasPhase, setAcsCacheStorage, setAcsReachabilityReporter, setClientDeclarationProvider, setDevMode, setHomeActionOrder, setPrefs as setNotifPrefs, setOrder, signInWithApple, signInWithGoogle, spacing, switchTenant, tenantFromToken, unlinkChannel as unlinkNotifChannel, unregisterDevice as unregisterPushDevice, unwrapMcpResult, useCapability, useChatStore, useHomeActionsStore, useWidgetsStore, useWorkspaceStore, userFromJwt };
|
|
1361
|
+
export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasGateFlags, type AdasPhase, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type AuthSession, type AuthSessionDeps, type AuthSessionState, type BufferedCommand, type ChannelPrefs, type ConsumerCapabilityConfig, type ConsumerProviderConfig, type ConsumerSignInResult, type DeleteResult, type DevModeState, type DevicePlatform, type DispatchRow, type FileUploadRequest, type FileUploader, type HandoffExchangeResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type InvitePreview, type JobProgress, MAX_ATTACHMENT_BYTES, MAX_INLINE_ATTACHMENT_BYTES, type Message, type MessageAttachment, type NotifChannel, type NotifPrefs, type OtpStartResult, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type PushBackend, type PushRegistration, type QuietHoursPrefs, type RefreshOutcome, type RegisterDeviceResponse, type Session, type SessionEnv, type SessionPersistence, type SessionStatus, type SessionUser, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TelegramBotInfo, type TenantMembership, type TenantRow, type TokenProvider, type ToolCall, type UIAction, type UploadedArtifact, type WireAttachment, type WorkspaceCapabilities, type WorkspaceSnapshot, type WorkspaceState, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, capabilityEnabled, closeChatStream, colors, connectAcsWs, connectorCall, createAuthSession, createPushRegistration, deleteArtifact, devModeFromCatalog, disconnectAcsWs, exchangeHandoff, fetchConsumerConfig, focusPlugin, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getPrefs as getNotifPrefs, getTelegramBotInfo as getNotifTelegramBotInfo, getSession, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, isDevHost, joinWithApple, joinWithGoogle, linkChannelStart, linkChannelVerify, linkTelegram as linkNotifTelegram, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, nestByMaster, notifyAcsWsForeground, notifyAppForeground, onAppForeground, openJoinWithApple, openJoinWithGoogle, parseDeepLinkParam, parseHandoffCode, parseInviteCode, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, prepareAttachments, previewInvite, readDevMode, recentDispatches as recentNotifDispatches, recordEvent, refreshToken, registerHostIntent, registerDevice as registerPushDevice, resolveAdasPhase, setAcsCacheStorage, setAcsReachabilityReporter, setClientDeclarationProvider, setDevMode, setHomeActionOrder, setPrefs as setNotifPrefs, setOrder, signInWithApple, signInWithGoogle, spacing, switchTenant, tenantFromToken, unlinkChannel as unlinkNotifChannel, unregisterDevice as unregisterPushDevice, unwrapMcpResult, useCapability, useChatStore, useHomeActionsStore, useWidgetsStore, useWorkspaceStore, userFromJwt };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,63 @@ import * as zustand from 'zustand';
|
|
|
4
4
|
* Storage adapter contracts. The core is platform-agnostic (no Expo, no
|
|
5
5
|
* AsyncStorage imports) — hosts or @ateam-ai-mobile/ui plug in concrete implementations.
|
|
6
6
|
*/
|
|
7
|
-
/**
|
|
7
|
+
/** The most Core stores for one file (Core's MAX_ARTIFACT_BYTES, 90 MiB: Cloudflare allows 100 MB a request). */
|
|
8
|
+
declare const MAX_ATTACHMENT_BYTES: number;
|
|
9
|
+
/**
|
|
10
|
+
* What the old base64-in-JSON path may carry in ONE chat message, in raw bytes (all inline attachments together). Core's
|
|
11
|
+
* express.json limit is 10 MB for the WHOLE /api/chat body and base64 adds a third (7 MiB becomes ~9.3 MiB), which leaves
|
|
12
|
+
* headroom for the text and the rest of the JSON.
|
|
13
|
+
*/
|
|
14
|
+
declare const MAX_INLINE_ATTACHMENT_BYTES: number;
|
|
15
|
+
/**
|
|
16
|
+
* An attachment the user staged, as handed to `sendMessage`.
|
|
17
|
+
*
|
|
18
|
+
* A file on the phone is given by `uri` (+ `size`): it is uploaded as the raw request body to `POST /api/artifacts`, and
|
|
19
|
+
* `/api/chat` then names it by hash, so a 90 MB file never rides inside JSON. `data` (base64) is the older shape, kept for
|
|
20
|
+
* small inline attachments and as the fallback when the server is too old to take a raw upload (it answers 400).
|
|
21
|
+
*/
|
|
8
22
|
interface OutgoingAttachment {
|
|
9
|
-
data: string;
|
|
10
23
|
mimeType: string;
|
|
11
24
|
name: string;
|
|
25
|
+
/** Base64 payload (inline path). Absent when the file is given by `uri`. */
|
|
26
|
+
data?: string;
|
|
27
|
+
/** Local file URI the host's `fileUploader` can read (e.g. a file:// path). */
|
|
28
|
+
uri?: string;
|
|
29
|
+
/** Size in bytes of the file at `uri`; used to refuse an oversize file early and to decide the old-server fallback. */
|
|
30
|
+
size?: number;
|
|
31
|
+
}
|
|
32
|
+
/** What `POST /api/artifacts` answers for a stored file. */
|
|
33
|
+
interface UploadedArtifact {
|
|
34
|
+
hash: string;
|
|
35
|
+
size: number;
|
|
36
|
+
mimeType: string;
|
|
37
|
+
}
|
|
38
|
+
/** One raw upload the host's `FileUploader` performs. The SDK builds the URL and the headers; the host only moves the bytes. */
|
|
39
|
+
interface FileUploadRequest {
|
|
40
|
+
/** Absolute `POST` URL, query included. */
|
|
41
|
+
url: string;
|
|
42
|
+
/** Headers to send as given (bearer + `Content-Type: application/octet-stream`). */
|
|
43
|
+
headers: Record<string, string>;
|
|
44
|
+
/** The local file to send as the request BODY (not multipart). */
|
|
45
|
+
uri: string;
|
|
46
|
+
/** 0..1 as the bytes go out. */
|
|
47
|
+
onProgress?: (fraction: number) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The host's file I/O for attachments: streaming a local file as a request body and reading a small one as base64. Core has
|
|
51
|
+
* no filesystem or native imports, so `@ateam-ai-mobile/expo` supplies the Expo implementation (`expoFileUploader`).
|
|
52
|
+
*/
|
|
53
|
+
interface FileUploader {
|
|
54
|
+
/** Send the file at `req.uri` as the raw body; resolve with the HTTP status and body text (any status). Reject only on a transport failure. */
|
|
55
|
+
upload(req: FileUploadRequest): Promise<{
|
|
56
|
+
status: number;
|
|
57
|
+
body: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** Read a local file as base64 (the old-server fallback, files within MAX_INLINE_ATTACHMENT_BYTES). */
|
|
60
|
+
readBase64(uri: string): Promise<string>;
|
|
61
|
+
/** Size in bytes of a local file, or undefined when it cannot be told. Used only when an attachment came without `size`,
|
|
62
|
+
* before any fallback read: without it a file of unknown size is refused rather than read whole. */
|
|
63
|
+
fileSize?(uri: string): Promise<number | undefined>;
|
|
12
64
|
}
|
|
13
65
|
/** Attachment as rendered in a message bubble (local or remote preview URI). */
|
|
14
66
|
interface AttachmentPreview {
|
|
@@ -23,6 +75,7 @@ interface AttachmentPreview {
|
|
|
23
75
|
interface AttachmentCache {
|
|
24
76
|
/** Resolve once the index is loaded — get() before this may return undefined. */
|
|
25
77
|
ready(): Promise<void>;
|
|
78
|
+
/** Keep a preview of each attachment (the bytes come from `data` or are copied from `uri`). */
|
|
26
79
|
save(jobId: string, attachments: OutgoingAttachment[]): Promise<void>;
|
|
27
80
|
get(jobId: string): AttachmentPreview[] | undefined;
|
|
28
81
|
}
|
|
@@ -96,6 +149,9 @@ interface AdasConfig {
|
|
|
96
149
|
* survive app restarts. No-op when omitted (previews live in memory for
|
|
97
150
|
* the session only). @ateam-ai-mobile/ui ships an Expo/RN implementation. */
|
|
98
151
|
attachmentCache?: AttachmentCache;
|
|
152
|
+
/** Moves an attachment's bytes for `sendMessage` (raw upload of a file `uri`). Required to attach a file by `uri`;
|
|
153
|
+
* without it only base64 `data` attachments can be sent. `@ateam-ai-mobile/expo` ships `expoFileUploader`. */
|
|
154
|
+
fileUploader?: FileUploader;
|
|
99
155
|
/** Called by `switchTenant()` with the freshly-minted session for the
|
|
100
156
|
* target tenant. The host MUST persist it here (store the new JWT so
|
|
101
157
|
* tokenProvider.getToken() returns it, and update the active tenant) —
|
|
@@ -782,6 +838,8 @@ interface Message {
|
|
|
782
838
|
skillSlug?: string;
|
|
783
839
|
/** Attached images/files */
|
|
784
840
|
attachments?: MessageAttachment[];
|
|
841
|
+
/** 0..1 while this message's files are still uploading; absent once they are stored and the message is posted. */
|
|
842
|
+
uploadProgress?: number;
|
|
785
843
|
/** UI Action chips beneath assistant bubbles */
|
|
786
844
|
actions?: UIAction[];
|
|
787
845
|
/** Chain id from /api/conversation — used to attach live progress to the
|
|
@@ -847,6 +905,22 @@ declare function setClientDeclarationProvider(fn: (() => ClientDeclaration | nul
|
|
|
847
905
|
/** Tear down the live connection (env/auth switch, SDK unmount). */
|
|
848
906
|
declare function closeChatStream(): void;
|
|
849
907
|
|
|
908
|
+
/** One attachment as `/api/chat` takes it: a stored file by hash, or small inline base64. */
|
|
909
|
+
type WireAttachment = {
|
|
910
|
+
hash: string;
|
|
911
|
+
name: string;
|
|
912
|
+
mimeType: string;
|
|
913
|
+
} | {
|
|
914
|
+
data: string;
|
|
915
|
+
mimeType: string;
|
|
916
|
+
name: string;
|
|
917
|
+
};
|
|
918
|
+
/**
|
|
919
|
+
* Upload what needs uploading and return the attachments as `/api/chat` takes them, in order.
|
|
920
|
+
* `onProgress` is the overall fraction 0..1 across all attachments.
|
|
921
|
+
*/
|
|
922
|
+
declare function prepareAttachments(attachments: OutgoingAttachment[], onProgress?: (fraction: number) => void): Promise<WireAttachment[]>;
|
|
923
|
+
|
|
850
924
|
/**
|
|
851
925
|
* Lightweight event emitter bridging the chat job stream → plugin bridges
|
|
852
926
|
* (React Native has no Node 'events' module).
|
|
@@ -1284,4 +1358,4 @@ interface AcsKvStorage {
|
|
|
1284
1358
|
}
|
|
1285
1359
|
declare function setAcsCacheStorage(kv: AcsKvStorage | null): void;
|
|
1286
1360
|
|
|
1287
|
-
export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasGateFlags, type AdasPhase, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type AuthSession, type AuthSessionDeps, type AuthSessionState, type BufferedCommand, type ChannelPrefs, type ConsumerCapabilityConfig, type ConsumerProviderConfig, type ConsumerSignInResult, type DeleteResult, type DevModeState, type DevicePlatform, type DispatchRow, type HandoffExchangeResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type InvitePreview, type JobProgress, type Message, type MessageAttachment, type NotifChannel, type NotifPrefs, type OtpStartResult, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type PushBackend, type PushRegistration, type QuietHoursPrefs, type RefreshOutcome, type RegisterDeviceResponse, type Session, type SessionEnv, type SessionPersistence, type SessionStatus, type SessionUser, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TelegramBotInfo, type TenantMembership, type TenantRow, type TokenProvider, type ToolCall, type UIAction, type WorkspaceCapabilities, type WorkspaceSnapshot, type WorkspaceState, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, capabilityEnabled, closeChatStream, colors, connectAcsWs, connectorCall, createAuthSession, createPushRegistration, deleteArtifact, devModeFromCatalog, disconnectAcsWs, exchangeHandoff, fetchConsumerConfig, focusPlugin, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getPrefs as getNotifPrefs, getTelegramBotInfo as getNotifTelegramBotInfo, getSession, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, isDevHost, joinWithApple, joinWithGoogle, linkChannelStart, linkChannelVerify, linkTelegram as linkNotifTelegram, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, nestByMaster, notifyAcsWsForeground, notifyAppForeground, onAppForeground, openJoinWithApple, openJoinWithGoogle, parseDeepLinkParam, parseHandoffCode, parseInviteCode, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, previewInvite, readDevMode, recentDispatches as recentNotifDispatches, recordEvent, refreshToken, registerHostIntent, registerDevice as registerPushDevice, resolveAdasPhase, setAcsCacheStorage, setAcsReachabilityReporter, setClientDeclarationProvider, setDevMode, setHomeActionOrder, setPrefs as setNotifPrefs, setOrder, signInWithApple, signInWithGoogle, spacing, switchTenant, tenantFromToken, unlinkChannel as unlinkNotifChannel, unregisterDevice as unregisterPushDevice, unwrapMcpResult, useCapability, useChatStore, useHomeActionsStore, useWidgetsStore, useWorkspaceStore, userFromJwt };
|
|
1361
|
+
export { type AcsArtifact, type AcsDeleteReason, type AcsEvent, type AcsKvStorage, type AcsPatchReason, type AcsReachabilityReporter, type AcsSurface, type AdasConfig, type AdasGateFlags, type AdasPhase, type AdasSession, type AdasUser, type AttachmentCache, type AttachmentPreview, type AuthSession, type AuthSessionDeps, type AuthSessionState, type BufferedCommand, type ChannelPrefs, type ConsumerCapabilityConfig, type ConsumerProviderConfig, type ConsumerSignInResult, type DeleteResult, type DevModeState, type DevicePlatform, type DispatchRow, type FileUploadRequest, type FileUploader, type HandoffExchangeResult, type HomeAction, type HomeActionLeaf, type HomeActionReason, type InvitePreview, type JobProgress, MAX_ATTACHMENT_BYTES, MAX_INLINE_ATTACHMENT_BYTES, type Message, type MessageAttachment, type NotifChannel, type NotifPrefs, type OtpStartResult, type OutgoingAttachment, type PatchResult, PluginCommandEmitter, type PushBackend, type PushRegistration, type QuietHoursPrefs, type RefreshOutcome, type RegisterDeviceResponse, type Session, type SessionEnv, type SessionPersistence, type SessionStatus, type SessionUser, TABLE_BLOCK_CLOSE, TABLE_BLOCK_OPEN, type TelegramBotInfo, type TenantMembership, type TenantRow, type TokenProvider, type ToolCall, type UIAction, type UploadedArtifact, type WireAttachment, type WorkspaceCapabilities, type WorkspaceSnapshot, type WorkspaceState, ada, apiFetch, apiFetchRaw, blocksToText, borderRadius, capabilityEnabled, closeChatStream, colors, connectAcsWs, connectorCall, createAuthSession, createPushRegistration, deleteArtifact, devModeFromCatalog, disconnectAcsWs, exchangeHandoff, fetchConsumerConfig, focusPlugin, fontSize, getConfig, getConsumerAuthApiUrl, getCoreApiUrl, getCoreWsUrl, getPrefs as getNotifPrefs, getTelegramBotInfo as getNotifTelegramBotInfo, getSession, getTenant, getToken, getUser, getVoiceApiUrl, initAdas, isAdasInitialized, isDevHost, joinWithApple, joinWithGoogle, linkChannelStart, linkChannelVerify, linkTelegram as linkNotifTelegram, listHomeActions, listMadeForYou, listMyTenants, listSurface, mcpFetch, mcpToolCall, nestByMaster, notifyAcsWsForeground, notifyAppForeground, onAppForeground, openJoinWithApple, openJoinWithGoogle, parseDeepLinkParam, parseHandoffCode, parseInviteCode, patchArtifact, patchHomeAction, pluginCommandEmitter, postCommandResult, prepareAttachments, previewInvite, readDevMode, recentDispatches as recentNotifDispatches, recordEvent, refreshToken, registerHostIntent, registerDevice as registerPushDevice, resolveAdasPhase, setAcsCacheStorage, setAcsReachabilityReporter, setClientDeclarationProvider, setDevMode, setHomeActionOrder, setPrefs as setNotifPrefs, setOrder, signInWithApple, signInWithGoogle, spacing, switchTenant, tenantFromToken, unlinkChannel as unlinkNotifChannel, unregisterDevice as unregisterPushDevice, unwrapMcpResult, useCapability, useChatStore, useHomeActionsStore, useWidgetsStore, useWorkspaceStore, userFromJwt };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
MAX_ATTACHMENT_BYTES: () => MAX_ATTACHMENT_BYTES,
|
|
24
|
+
MAX_INLINE_ATTACHMENT_BYTES: () => MAX_INLINE_ATTACHMENT_BYTES,
|
|
23
25
|
PluginCommandEmitter: () => PluginCommandEmitter,
|
|
24
26
|
TABLE_BLOCK_CLOSE: () => TABLE_BLOCK_CLOSE,
|
|
25
27
|
TABLE_BLOCK_OPEN: () => TABLE_BLOCK_OPEN,
|
|
@@ -80,6 +82,7 @@ __export(index_exports, {
|
|
|
80
82
|
patchHomeAction: () => patchHomeAction,
|
|
81
83
|
pluginCommandEmitter: () => pluginCommandEmitter,
|
|
82
84
|
postCommandResult: () => postCommandResult,
|
|
85
|
+
prepareAttachments: () => prepareAttachments,
|
|
83
86
|
previewInvite: () => previewInvite,
|
|
84
87
|
readDevMode: () => readDevMode,
|
|
85
88
|
recentNotifDispatches: () => recentDispatches,
|
|
@@ -1461,6 +1464,106 @@ function focusPlugin(pluginId, props) {
|
|
|
1461
1464
|
pluginCommandEmitter.emit("focus-plugin", { pluginId, props });
|
|
1462
1465
|
}
|
|
1463
1466
|
|
|
1467
|
+
// src/storage/types.ts
|
|
1468
|
+
var MAX_ATTACHMENT_BYTES = 90 * 1024 * 1024;
|
|
1469
|
+
var MAX_INLINE_ATTACHMENT_BYTES = 7 * 1024 * 1024;
|
|
1470
|
+
|
|
1471
|
+
// src/chat/attachments.ts
|
|
1472
|
+
var mb = (bytes) => Math.round(bytes / 1024 / 1024);
|
|
1473
|
+
var base64Length = (bytes) => Math.ceil(bytes / 3) * 4;
|
|
1474
|
+
var MAX_INLINE_CHARS = base64Length(MAX_INLINE_ATTACHMENT_BYTES);
|
|
1475
|
+
function tooLarge(name) {
|
|
1476
|
+
return new Error(`"${name}" is too large (max ${mb(MAX_ATTACHMENT_BYTES)} MB)`);
|
|
1477
|
+
}
|
|
1478
|
+
function errorFrom(status, body, name) {
|
|
1479
|
+
let message = "";
|
|
1480
|
+
try {
|
|
1481
|
+
message = String(JSON.parse(body)?.error || "");
|
|
1482
|
+
} catch {
|
|
1483
|
+
}
|
|
1484
|
+
if (status === 413) {
|
|
1485
|
+
return new Error(message || `This server can't take files this big yet ("${name}")`);
|
|
1486
|
+
}
|
|
1487
|
+
if (status === 429) return new Error(message || "Too many uploads: wait a moment and try again");
|
|
1488
|
+
return new Error(message || `The upload of "${name}" failed (${status})`);
|
|
1489
|
+
}
|
|
1490
|
+
async function sendRaw(uploader, att, onProgress) {
|
|
1491
|
+
const query = new URLSearchParams({ mimeType: att.mimeType || "application/octet-stream", name: att.name || "upload" });
|
|
1492
|
+
const url = `${getCoreApiUrl()}/api/artifacts?${query.toString()}`;
|
|
1493
|
+
const attempt = () => {
|
|
1494
|
+
const token = getToken();
|
|
1495
|
+
return uploader.upload({
|
|
1496
|
+
url,
|
|
1497
|
+
uri: att.uri,
|
|
1498
|
+
headers: {
|
|
1499
|
+
"Content-Type": "application/octet-stream",
|
|
1500
|
+
...token ? { Authorization: `Bearer ${token}` } : {}
|
|
1501
|
+
},
|
|
1502
|
+
onProgress
|
|
1503
|
+
});
|
|
1504
|
+
};
|
|
1505
|
+
let res = await attempt();
|
|
1506
|
+
if (res.status === 401 && getToken()) {
|
|
1507
|
+
const outcome = await refreshToken();
|
|
1508
|
+
if (outcome.ok === "ok") {
|
|
1509
|
+
res = await attempt();
|
|
1510
|
+
if (res.status === 401 || res.status === 403) {
|
|
1511
|
+
notifyAuthFailure();
|
|
1512
|
+
throw new Error("Session expired: sign in again to upload this file");
|
|
1513
|
+
}
|
|
1514
|
+
} else if (outcome.ok === "auth_failed") {
|
|
1515
|
+
notifyAuthFailure();
|
|
1516
|
+
throw new Error("Session expired: sign in again to upload this file");
|
|
1517
|
+
} else {
|
|
1518
|
+
throw new Error("Could not reach the server to refresh your sign-in: check your connection and try again");
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
return res;
|
|
1522
|
+
}
|
|
1523
|
+
async function uploadOne(att, onProgress, budget) {
|
|
1524
|
+
const name = att.name || "attachment";
|
|
1525
|
+
if (att.data !== void 0) return { data: att.data, mimeType: att.mimeType, name: att.name };
|
|
1526
|
+
if (!att.uri) throw new Error(`The attachment "${name}" has no file to send`);
|
|
1527
|
+
if (att.size !== void 0 && att.size > MAX_ATTACHMENT_BYTES) throw tooLarge(name);
|
|
1528
|
+
const uploader = getConfig().fileUploader;
|
|
1529
|
+
if (!uploader) throw new Error("This app cannot upload files yet: initAdas needs a fileUploader");
|
|
1530
|
+
const res = await sendRaw(uploader, att, onProgress);
|
|
1531
|
+
if (res.status >= 200 && res.status < 300) {
|
|
1532
|
+
let parsed = null;
|
|
1533
|
+
try {
|
|
1534
|
+
parsed = JSON.parse(res.body);
|
|
1535
|
+
} catch {
|
|
1536
|
+
}
|
|
1537
|
+
if (parsed?.ok && typeof parsed.hash === "string") {
|
|
1538
|
+
onProgress(1);
|
|
1539
|
+
return { hash: parsed.hash, name: att.name, mimeType: parsed.mimeType || att.mimeType };
|
|
1540
|
+
}
|
|
1541
|
+
throw errorFrom(res.status, res.body, name);
|
|
1542
|
+
}
|
|
1543
|
+
if (res.status === 400) {
|
|
1544
|
+
const size = att.size !== void 0 ? att.size : await uploader.fileSize?.(att.uri);
|
|
1545
|
+
if (size === void 0) {
|
|
1546
|
+
throw new Error(`Cannot tell how big "${name}" is, and this server cannot take large files yet`);
|
|
1547
|
+
}
|
|
1548
|
+
if (base64Length(size) > budget.chars) {
|
|
1549
|
+
throw new Error(`"${name}" is too big for this server, which cannot take more than ${mb(MAX_INLINE_ATTACHMENT_BYTES)} MB of files in one message yet`);
|
|
1550
|
+
}
|
|
1551
|
+
const data = await uploader.readBase64(att.uri);
|
|
1552
|
+
budget.chars -= data.length;
|
|
1553
|
+
onProgress(1);
|
|
1554
|
+
return { data, mimeType: att.mimeType, name: att.name };
|
|
1555
|
+
}
|
|
1556
|
+
throw errorFrom(res.status, res.body, name);
|
|
1557
|
+
}
|
|
1558
|
+
async function prepareAttachments(attachments, onProgress) {
|
|
1559
|
+
const budget = { chars: MAX_INLINE_CHARS - attachments.reduce((n, a) => n + (a.data !== void 0 ? a.data.length : 0), 0) };
|
|
1560
|
+
const out = [];
|
|
1561
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
1562
|
+
out.push(await uploadOne(attachments[i], (f) => onProgress?.((i + f) / attachments.length), budget));
|
|
1563
|
+
}
|
|
1564
|
+
return out;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1464
1567
|
// src/chat/store.ts
|
|
1465
1568
|
function coreHeaders() {
|
|
1466
1569
|
const token = getToken();
|
|
@@ -1795,8 +1898,11 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
|
|
|
1795
1898
|
attachments: attachments.map((a) => ({
|
|
1796
1899
|
mimeType: a.mimeType,
|
|
1797
1900
|
name: a.name,
|
|
1798
|
-
|
|
1799
|
-
|
|
1901
|
+
// An image on the phone previews from its own file; an inline one from its base64.
|
|
1902
|
+
previewUri: !a.mimeType.startsWith("image/") ? void 0 : a.data !== void 0 ? `data:${a.mimeType};base64,${a.data}` : a.uri
|
|
1903
|
+
})),
|
|
1904
|
+
// A file on the phone is uploaded before the message is posted: the bubble shows how far along it is.
|
|
1905
|
+
...attachments.some((a) => a.uri && a.data === void 0) ? { uploadProgress: 0 } : {}
|
|
1800
1906
|
} : {}
|
|
1801
1907
|
};
|
|
1802
1908
|
set((s) => ({ messages: [...s.messages, userMsg], loading: true, error: null }));
|
|
@@ -1813,7 +1919,15 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
|
|
|
1813
1919
|
}
|
|
1814
1920
|
};
|
|
1815
1921
|
if (skillSlug) body.skillSlug = skillSlug;
|
|
1816
|
-
if (attachments?.length)
|
|
1922
|
+
if (attachments?.length) {
|
|
1923
|
+
let shown = 0;
|
|
1924
|
+
body.attachments = await prepareAttachments(attachments, (f) => {
|
|
1925
|
+
if (f - shown < 0.01 && f < 1) return;
|
|
1926
|
+
shown = f;
|
|
1927
|
+
set((s) => ({ messages: s.messages.map((m) => m.id === userMsg.id && m.uploadProgress !== void 0 ? { ...m, uploadProgress: f } : m) }));
|
|
1928
|
+
});
|
|
1929
|
+
set((s) => ({ messages: s.messages.map((m) => m.id === userMsg.id ? { ...m, uploadProgress: void 0 } : m) }));
|
|
1930
|
+
}
|
|
1817
1931
|
const res = await fetch(`${getCoreApiUrl()}/api/chat`, {
|
|
1818
1932
|
method: "POST",
|
|
1819
1933
|
headers: coreHeaders(),
|
|
@@ -1880,7 +1994,7 @@ var useChatStore = (0, import_zustand4.create)((set, get) => ({
|
|
|
1880
1994
|
streamJob(jobId, getTenant(), getToken());
|
|
1881
1995
|
} catch (err) {
|
|
1882
1996
|
set((s) => ({
|
|
1883
|
-
messages: [...s.messages, {
|
|
1997
|
+
messages: [...s.messages.map((m) => m.id === userMsg.id && m.uploadProgress !== void 0 ? { ...m, uploadProgress: void 0 } : m), {
|
|
1884
1998
|
id: `error-${Date.now()}`,
|
|
1885
1999
|
role: "system",
|
|
1886
2000
|
content: `Error: ${err.message}`,
|
|
@@ -2338,6 +2452,8 @@ var borderRadius = {
|
|
|
2338
2452
|
};
|
|
2339
2453
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2340
2454
|
0 && (module.exports = {
|
|
2455
|
+
MAX_ATTACHMENT_BYTES,
|
|
2456
|
+
MAX_INLINE_ATTACHMENT_BYTES,
|
|
2341
2457
|
PluginCommandEmitter,
|
|
2342
2458
|
TABLE_BLOCK_CLOSE,
|
|
2343
2459
|
TABLE_BLOCK_OPEN,
|
|
@@ -2398,6 +2514,7 @@ var borderRadius = {
|
|
|
2398
2514
|
patchHomeAction,
|
|
2399
2515
|
pluginCommandEmitter,
|
|
2400
2516
|
postCommandResult,
|
|
2517
|
+
prepareAttachments,
|
|
2401
2518
|
previewInvite,
|
|
2402
2519
|
readDevMode,
|
|
2403
2520
|
recentNotifDispatches,
|