@ateam-ai-mobile/core 0.1.32 → 0.1.35
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 +166 -22
- package/dist/index.d.ts +166 -22
- package/dist/index.js +297 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +285 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/attachments.ts +139 -0
- package/src/chat/blockText.ts +253 -0
- package/src/chat/store.ts +19 -74
- package/src/chat/types.ts +2 -0
- package/src/config.ts +4 -1
- package/src/index.ts +19 -1
- package/src/storage/types.ts +57 -2
package/src/storage/types.ts
CHANGED
|
@@ -3,11 +3,65 @@
|
|
|
3
3
|
* AsyncStorage imports) — hosts or @ateam-ai-mobile/ui plug in concrete implementations.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/** The most Core stores for one file (Core's MAX_ARTIFACT_BYTES, 90 MiB: Cloudflare allows 100 MB a request). */
|
|
7
|
+
export const MAX_ATTACHMENT_BYTES = 90 * 1024 * 1024;
|
|
8
|
+
|
|
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
|
+
export const MAX_INLINE_ATTACHMENT_BYTES = 7 * 1024 * 1024;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An attachment the user staged, as handed to `sendMessage`.
|
|
18
|
+
*
|
|
19
|
+
* A file on the phone is given by `uri` (+ `size`): it is uploaded as the raw request body to `POST /api/artifacts`, and
|
|
20
|
+
* `/api/chat` then names it by hash, so a 90 MB file never rides inside JSON. `data` (base64) is the older shape, kept for
|
|
21
|
+
* small inline attachments and as the fallback when the server is too old to take a raw upload (it answers 400).
|
|
22
|
+
*/
|
|
7
23
|
export interface OutgoingAttachment {
|
|
8
|
-
data: string;
|
|
9
24
|
mimeType: string;
|
|
10
25
|
name: string;
|
|
26
|
+
/** Base64 payload (inline path). Absent when the file is given by `uri`. */
|
|
27
|
+
data?: string;
|
|
28
|
+
/** Local file URI the host's `fileUploader` can read (e.g. a file:// path). */
|
|
29
|
+
uri?: string;
|
|
30
|
+
/** Size in bytes of the file at `uri`; used to refuse an oversize file early and to decide the old-server fallback. */
|
|
31
|
+
size?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What `POST /api/artifacts` answers for a stored file. */
|
|
35
|
+
export interface UploadedArtifact {
|
|
36
|
+
hash: string;
|
|
37
|
+
size: number;
|
|
38
|
+
mimeType: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** One raw upload the host's `FileUploader` performs. The SDK builds the URL and the headers; the host only moves the bytes. */
|
|
42
|
+
export interface FileUploadRequest {
|
|
43
|
+
/** Absolute `POST` URL, query included. */
|
|
44
|
+
url: string;
|
|
45
|
+
/** Headers to send as given (bearer + `Content-Type: application/octet-stream`). */
|
|
46
|
+
headers: Record<string, string>;
|
|
47
|
+
/** The local file to send as the request BODY (not multipart). */
|
|
48
|
+
uri: string;
|
|
49
|
+
/** 0..1 as the bytes go out. */
|
|
50
|
+
onProgress?: (fraction: number) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 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
|
|
55
|
+
* no filesystem or native imports, so `@ateam-ai-mobile/expo` supplies the Expo implementation (`expoFileUploader`).
|
|
56
|
+
*/
|
|
57
|
+
export interface FileUploader {
|
|
58
|
+
/** 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. */
|
|
59
|
+
upload(req: FileUploadRequest): Promise<{ status: number; body: string }>;
|
|
60
|
+
/** Read a local file as base64 (the old-server fallback, files within MAX_INLINE_ATTACHMENT_BYTES). */
|
|
61
|
+
readBase64(uri: string): Promise<string>;
|
|
62
|
+
/** Size in bytes of a local file, or undefined when it cannot be told. Used only when an attachment came without `size`,
|
|
63
|
+
* before any fallback read: without it a file of unknown size is refused rather than read whole. */
|
|
64
|
+
fileSize?(uri: string): Promise<number | undefined>;
|
|
11
65
|
}
|
|
12
66
|
|
|
13
67
|
/** Attachment as rendered in a message bubble (local or remote preview URI). */
|
|
@@ -24,6 +78,7 @@ export interface AttachmentPreview {
|
|
|
24
78
|
export interface AttachmentCache {
|
|
25
79
|
/** Resolve once the index is loaded — get() before this may return undefined. */
|
|
26
80
|
ready(): Promise<void>;
|
|
81
|
+
/** Keep a preview of each attachment (the bytes come from `data` or are copied from `uri`). */
|
|
27
82
|
save(jobId: string, attachments: OutgoingAttachment[]): Promise<void>;
|
|
28
83
|
get(jobId: string): AttachmentPreview[] | undefined;
|
|
29
84
|
}
|