@pmate/chat-sdk 0.12.0-next.6 → 0.12.0-next.60
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/README.md +98 -3
- package/lib/runtime/batchedReadIndex.d.ts +16 -3
- package/lib/runtime/batchedReadIndex.js +50 -4
- package/lib/runtime/cachedMessage.d.ts +12 -0
- package/lib/runtime/cachedMessage.js +18 -0
- package/lib/runtime/chatClient.d.ts +1 -0
- package/lib/runtime/chatClient.js +1 -1
- package/lib/runtime/chatSession.d.ts +109 -12
- package/lib/runtime/chatSession.js +624 -40
- package/lib/runtime/connectivity.d.ts +4 -0
- package/lib/runtime/connectivity.js +8 -0
- package/lib/runtime/conversationRead.d.ts +13 -0
- package/lib/runtime/conversationRead.js +34 -0
- package/lib/runtime/conversationReading.d.ts +28 -0
- package/lib/runtime/conversationReading.js +47 -0
- package/lib/runtime/createChat.d.ts +5 -5
- package/lib/runtime/createChat.js +30 -17
- package/lib/runtime/durableSender.d.ts +97 -14
- package/lib/runtime/durableSender.js +786 -71
- package/lib/runtime/groupClient.d.ts +76 -0
- package/lib/runtime/groupClient.js +325 -0
- package/lib/runtime/index.d.ts +6 -0
- package/lib/runtime/index.js +5 -0
- package/lib/runtime/messageClient.d.ts +30 -8
- package/lib/runtime/messageClient.js +332 -66
- package/lib/runtime/messageControls.d.ts +19 -0
- package/lib/runtime/messageControls.js +44 -0
- package/lib/runtime/messageLaunch.d.ts +42 -0
- package/lib/runtime/messageLaunch.js +133 -0
- package/lib/runtime/messageQuotes.d.ts +3 -0
- package/lib/runtime/messageQuotes.js +17 -0
- package/lib/runtime/messageReaders.d.ts +12 -1
- package/lib/runtime/messageReaders.js +67 -3
- package/lib/runtime/messageStore.d.ts +38 -2
- package/lib/runtime/messageStore.js +215 -11
- package/lib/runtime/messageTimeline.d.ts +50 -0
- package/lib/runtime/messageTimeline.js +120 -0
- package/lib/runtime/outboxSchema.d.ts +5 -0
- package/lib/runtime/outboxSchema.js +59 -0
- package/lib/runtime/outgoingContent.d.ts +85 -0
- package/lib/runtime/outgoingContent.js +106 -0
- package/lib/runtime/readBatchJournal.d.ts +35 -0
- package/lib/runtime/readBatchJournal.js +210 -0
- package/lib/runtime/readCounts.d.ts +15 -1
- package/lib/runtime/readCounts.js +96 -8
- package/lib/runtime/readIndex.d.ts +68 -7
- package/lib/runtime/readIndex.js +460 -22
- package/lib/runtime/readSchema.d.ts +2 -0
- package/lib/runtime/readSchema.js +58 -0
- package/lib/runtime/readSync.d.ts +1 -0
- package/lib/runtime/readSync.js +25 -8
- package/lib/runtime/readingClient.d.ts +19 -0
- package/lib/runtime/readingClient.js +131 -19
- package/lib/runtime/readingContent.d.ts +5 -0
- package/lib/runtime/readingContent.js +23 -0
- package/lib/runtime/recordCache.d.ts +9 -0
- package/lib/runtime/recordCache.js +62 -5
- package/lib/runtime/responseCache.d.ts +57 -0
- package/lib/runtime/responseCache.js +230 -0
- package/lib/runtime/socialReadClient.d.ts +3 -1
- package/lib/runtime/socialReadClient.js +8 -4
- package/lib/runtime/voiceUpload.d.ts +2 -0
- package/lib/runtime/voiceUpload.js +27 -0
- package/package.json +6 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { Dexie } from "dexie";
|
|
2
|
+
import { WindowedTasks } from "./coalescer.js";
|
|
3
|
+
export function isResponseCacheAuthorityError(error) {
|
|
4
|
+
return /RESPONSE_CACHE_(ACCESS_REVOKED|SCOPE_CHANGED|INVALIDATED)/.test(String(error));
|
|
5
|
+
}
|
|
6
|
+
export async function assertResponseCacheAccess(access, expectedVersion) {
|
|
7
|
+
if (!access)
|
|
8
|
+
return undefined;
|
|
9
|
+
const current = await access();
|
|
10
|
+
if (!current.allowed)
|
|
11
|
+
throw new Error("RESPONSE_CACHE_ACCESS_REVOKED");
|
|
12
|
+
if (expectedVersion !== undefined && current.version !== expectedVersion)
|
|
13
|
+
throw new Error("RESPONSE_CACHE_SCOPE_CHANGED");
|
|
14
|
+
return current.version;
|
|
15
|
+
}
|
|
16
|
+
/** Small response windows, isolated by identity. Epochs fence late writes after
|
|
17
|
+
* access withdrawal. No localStorage or synchronous writes on the read path. */
|
|
18
|
+
export class IndexedDbResponseCache {
|
|
19
|
+
scope;
|
|
20
|
+
options;
|
|
21
|
+
db;
|
|
22
|
+
rows;
|
|
23
|
+
epochs;
|
|
24
|
+
pending = [];
|
|
25
|
+
tasks = new WindowedTasks(16, () => { });
|
|
26
|
+
running;
|
|
27
|
+
invalidations = new Set();
|
|
28
|
+
closed = false;
|
|
29
|
+
closing;
|
|
30
|
+
constructor(scope, options = {}) {
|
|
31
|
+
this.scope = scope;
|
|
32
|
+
this.options = options;
|
|
33
|
+
for (const [value, max] of [[options.recordBytes ?? 65536, 1048576], [options.entries ?? 256, 256], [options.batchRecords ?? 128, 128]])
|
|
34
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > max)
|
|
35
|
+
throw new Error("INVALID_RESPONSE_CACHE_LIMIT");
|
|
36
|
+
this.db = new Dexie(options.name ?? "pmate-chat-response-windows", { indexedDB: options.indexedDB ?? globalThis.indexedDB, IDBKeyRange: globalThis.IDBKeyRange });
|
|
37
|
+
this.db.version(1).stores({ windows: "[scope+key],scope", epochs: "scope" });
|
|
38
|
+
this.rows = this.db.table("windows");
|
|
39
|
+
this.epochs = this.db.table("epochs");
|
|
40
|
+
}
|
|
41
|
+
/** Resolve shared message-scope authority before opening our transaction.
|
|
42
|
+
* A newer authority version retires response windows exactly once; delayed
|
|
43
|
+
* callers can never roll the authority backwards or delete recovered data. */
|
|
44
|
+
async synchronizeAccess() {
|
|
45
|
+
if (!this.options.access)
|
|
46
|
+
return;
|
|
47
|
+
const access = await this.options.access();
|
|
48
|
+
const stored = await this.epochs.get(this.scope);
|
|
49
|
+
const storedVersion = stored?.accessVersion ?? 0;
|
|
50
|
+
if (access.version < storedVersion)
|
|
51
|
+
throw new Error("RESPONSE_CACHE_SCOPE_CHANGED");
|
|
52
|
+
// Ordinary cache reads must not take an IndexedDB write lock. Only an
|
|
53
|
+
// authority transition needs the atomic epoch bump and range deletion.
|
|
54
|
+
if (access.version > storedVersion)
|
|
55
|
+
await this.db.transaction("rw", this.rows, this.epochs, async () => {
|
|
56
|
+
const current = await this.epochs.get(this.scope);
|
|
57
|
+
const version = current?.accessVersion ?? 0;
|
|
58
|
+
if (access.version < version)
|
|
59
|
+
throw new Error("RESPONSE_CACHE_SCOPE_CHANGED");
|
|
60
|
+
if (access.version > version) {
|
|
61
|
+
await this.epochs.put({ scope: this.scope, epoch: (current?.epoch ?? 0) + 1, accessVersion: access.version });
|
|
62
|
+
await this.rows.where("scope").equals(this.scope).delete();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
if (!access.allowed)
|
|
66
|
+
throw new Error("RESPONSE_CACHE_ACCESS_REVOKED");
|
|
67
|
+
}
|
|
68
|
+
async read(key) {
|
|
69
|
+
if (this.closed)
|
|
70
|
+
throw new Error("RESPONSE_CACHE_CLOSED");
|
|
71
|
+
await this.synchronizeAccess();
|
|
72
|
+
return this.db.transaction("r", this.rows, this.epochs, async () => {
|
|
73
|
+
const epoch = (await this.epochs.get(this.scope))?.epoch ?? 0;
|
|
74
|
+
const row = await this.rows.get([this.scope, key]);
|
|
75
|
+
return { epoch, cached: row?.epoch === epoch ? { value: row.value, time: row.time } : undefined };
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Key-only callers can share one bounded metadata read transaction. */
|
|
79
|
+
async readMany(keys) {
|
|
80
|
+
if (this.closed)
|
|
81
|
+
throw new Error("RESPONSE_CACHE_CLOSED");
|
|
82
|
+
if (keys.length > 128)
|
|
83
|
+
throw new Error("RESPONSE_CACHE_SELECTION_TOO_LARGE");
|
|
84
|
+
await this.synchronizeAccess();
|
|
85
|
+
return this.db.transaction("r", this.rows, this.epochs, async () => {
|
|
86
|
+
const epoch = (await this.epochs.get(this.scope))?.epoch ?? 0, unique = [...new Set(keys)];
|
|
87
|
+
const rows = await this.rows.bulkGet(unique.map(key => [this.scope, key]));
|
|
88
|
+
return new Map(unique.map((key, index) => { const row = rows[index]; return [key, { epoch, cached: row?.epoch === epoch ? { value: row.value, time: row.time } : undefined }]; }));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
write(key, value, epoch, expectedRevision) {
|
|
92
|
+
if (this.closed)
|
|
93
|
+
return Promise.reject(new Error("RESPONSE_CACHE_CLOSED"));
|
|
94
|
+
if (expectedRevision !== undefined && !this.options.revision)
|
|
95
|
+
return Promise.reject(new Error("RESPONSE_CACHE_REVISION_UNAVAILABLE"));
|
|
96
|
+
const copy = structuredClone(value), bytes = new TextEncoder().encode(JSON.stringify(copy)).byteLength;
|
|
97
|
+
// Count in-flight data as well as queued data; requests cannot create an
|
|
98
|
+
// unbounded backlog while IndexedDB is blocked by another tab.
|
|
99
|
+
if (bytes > (this.options.recordBytes ?? 65536) || this.pending.length >= 128 || this.pending.reduce((n, w) => n + w.row.bytes, 0) + bytes > 1048576)
|
|
100
|
+
return Promise.reject(new Error("RESPONSE_CACHE_BACKPRESSURE"));
|
|
101
|
+
const promise = new Promise((resolve, reject) => this.pending.push({ row: { scope: this.scope, key, epoch, time: Date.now(), bytes, value: copy }, expectedRevision, resolve, reject }));
|
|
102
|
+
this.tasks.schedule("write", () => this.flush());
|
|
103
|
+
return promise;
|
|
104
|
+
}
|
|
105
|
+
/** Idempotent shared-scope retirement: an old cleanup cannot erase windows
|
|
106
|
+
* created after the same authority version was already recovered. */
|
|
107
|
+
retire(version) {
|
|
108
|
+
if (this.closed)
|
|
109
|
+
return Promise.reject(new Error("RESPONSE_CACHE_CLOSED"));
|
|
110
|
+
if (!Number.isSafeInteger(version) || version < 1)
|
|
111
|
+
return Promise.reject(new Error("INVALID_RESPONSE_SCOPE_VERSION"));
|
|
112
|
+
const task = this.db.transaction("rw", this.rows, this.epochs, async () => {
|
|
113
|
+
const current = await this.epochs.get(this.scope);
|
|
114
|
+
if ((current?.accessVersion ?? 0) >= version)
|
|
115
|
+
return;
|
|
116
|
+
await this.epochs.put({ scope: this.scope, epoch: (current?.epoch ?? 0) + 1, accessVersion: version });
|
|
117
|
+
await this.rows.where("scope").equals(this.scope).delete();
|
|
118
|
+
});
|
|
119
|
+
this.invalidations.add(task);
|
|
120
|
+
return task.finally(() => this.invalidations.delete(task));
|
|
121
|
+
}
|
|
122
|
+
invalidate() {
|
|
123
|
+
if (this.closed)
|
|
124
|
+
return Promise.reject(new Error("RESPONSE_CACHE_CLOSED"));
|
|
125
|
+
const task = (async () => {
|
|
126
|
+
await this.db.transaction("rw", this.rows, this.epochs, async () => {
|
|
127
|
+
const current = await this.epochs.get(this.scope);
|
|
128
|
+
const epoch = (current?.epoch ?? 0) + 1;
|
|
129
|
+
await this.epochs.put({ scope: this.scope, epoch, accessVersion: current?.accessVersion });
|
|
130
|
+
await this.rows.where("scope").equals(this.scope).delete();
|
|
131
|
+
});
|
|
132
|
+
})();
|
|
133
|
+
this.invalidations.add(task);
|
|
134
|
+
return task.finally(() => this.invalidations.delete(task));
|
|
135
|
+
}
|
|
136
|
+
async flush() {
|
|
137
|
+
if (this.running) {
|
|
138
|
+
await this.running;
|
|
139
|
+
if (this.pending.length)
|
|
140
|
+
return this.flush();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!this.pending.length)
|
|
144
|
+
return;
|
|
145
|
+
const task = (async () => {
|
|
146
|
+
let failed = false, failure;
|
|
147
|
+
// Each batch commits and resolves independently. A configured smaller
|
|
148
|
+
// batch still drains all accepted requests, including during close.
|
|
149
|
+
while (this.pending.length) {
|
|
150
|
+
const batch = this.pending.slice(0, this.options.batchRecords ?? 128);
|
|
151
|
+
try {
|
|
152
|
+
await this.synchronizeAccess();
|
|
153
|
+
const outcome = await this.db.transaction("rw", this.rows, this.epochs, async () => {
|
|
154
|
+
const epoch = (await this.epochs.get(this.scope))?.epoch ?? 0;
|
|
155
|
+
const valid = batch.filter(write => write.row.epoch === epoch);
|
|
156
|
+
const conditional = valid.filter(write => write.expectedRevision !== undefined);
|
|
157
|
+
const keys = [...new Set(conditional.map(write => write.row.key))];
|
|
158
|
+
const current = conditional.length ? await this.rows.bulkGet(keys.map(key => [this.scope, key])) : [];
|
|
159
|
+
const projected = new Map(keys.map((key, index) => [key, current[index]?.epoch === epoch ? current[index] : undefined]));
|
|
160
|
+
const accepted = new Set(), changed = new Set(), unique = new Map();
|
|
161
|
+
for (const write of valid) {
|
|
162
|
+
if (write.expectedRevision !== undefined) {
|
|
163
|
+
const previous = projected.get(write.row.key);
|
|
164
|
+
const revision = previous ? this.options.revision(previous.value) : null;
|
|
165
|
+
if (revision !== write.expectedRevision) {
|
|
166
|
+
// Another document may have already committed this exact
|
|
167
|
+
// revision; it is an idempotent success, never an overwrite.
|
|
168
|
+
if (revision === this.options.revision(write.row.value) && JSON.stringify(previous.value) === JSON.stringify(write.row.value))
|
|
169
|
+
accepted.add(write);
|
|
170
|
+
else
|
|
171
|
+
changed.add(write);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
unique.set(write.row.key, write.row);
|
|
176
|
+
projected.set(write.row.key, write.row);
|
|
177
|
+
accepted.add(write);
|
|
178
|
+
}
|
|
179
|
+
if (unique.size) {
|
|
180
|
+
await this.rows.bulkPut([...unique.values()]);
|
|
181
|
+
const stored = await this.rows.where("scope").equals(this.scope).toArray();
|
|
182
|
+
stored.sort((a, b) => b.time - a.time || a.key.localeCompare(b.key));
|
|
183
|
+
let bytes = 0;
|
|
184
|
+
const evicted = [];
|
|
185
|
+
stored.forEach((row, index) => { bytes += row.bytes; if (index >= (this.options.entries ?? 256) || bytes > 1048576)
|
|
186
|
+
evicted.push([this.scope, row.key]); });
|
|
187
|
+
if (evicted.length)
|
|
188
|
+
await this.rows.bulkDelete(evicted);
|
|
189
|
+
}
|
|
190
|
+
return { accepted, changed };
|
|
191
|
+
});
|
|
192
|
+
for (const write of batch) {
|
|
193
|
+
if (outcome.accepted.has(write))
|
|
194
|
+
write.resolve();
|
|
195
|
+
else
|
|
196
|
+
write.reject(new Error(outcome.changed.has(write) ? "RESPONSE_CACHE_CHANGED" : "RESPONSE_CACHE_INVALIDATED"));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
batch.forEach(write => write.reject(error));
|
|
201
|
+
if (!failed)
|
|
202
|
+
failure = error;
|
|
203
|
+
failed = true;
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
this.pending.splice(0, batch.length);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (failed)
|
|
210
|
+
throw failure;
|
|
211
|
+
})().finally(() => { if (this.running === task)
|
|
212
|
+
this.running = undefined; });
|
|
213
|
+
this.running = task;
|
|
214
|
+
return task;
|
|
215
|
+
}
|
|
216
|
+
close() {
|
|
217
|
+
if (this.closing)
|
|
218
|
+
return this.closing;
|
|
219
|
+
this.closed = true;
|
|
220
|
+
this.tasks.close();
|
|
221
|
+
return this.closing = (async () => {
|
|
222
|
+
try {
|
|
223
|
+
await Promise.all([this.flush(), ...this.invalidations]);
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
this.db.close();
|
|
227
|
+
}
|
|
228
|
+
})();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -22,6 +22,7 @@ export type SocialGroup = {
|
|
|
22
22
|
title: string;
|
|
23
23
|
avatar?: string | null;
|
|
24
24
|
revision: string;
|
|
25
|
+
versionNumber?: number;
|
|
25
26
|
};
|
|
26
27
|
export type SocialRelationship = {
|
|
27
28
|
appId: string;
|
|
@@ -57,11 +58,12 @@ export declare class SocialReadClient {
|
|
|
57
58
|
limit?: number;
|
|
58
59
|
before?: string;
|
|
59
60
|
after?: string;
|
|
61
|
+
messageId?: string;
|
|
60
62
|
}, signal?: AbortSignal): Promise<SocialMessagePage>;
|
|
61
63
|
group(input: {
|
|
62
64
|
groupId: string;
|
|
63
65
|
teamId?: string;
|
|
64
|
-
}): Promise<SocialGroup>;
|
|
66
|
+
}, signal?: AbortSignal): Promise<SocialGroup>;
|
|
65
67
|
relationship(input: {
|
|
66
68
|
peerId: string;
|
|
67
69
|
teamId?: string;
|
|
@@ -26,22 +26,26 @@ export class SocialReadClient {
|
|
|
26
26
|
}
|
|
27
27
|
async messagePage(input, signal) {
|
|
28
28
|
this.requireTeam(input.teamId);
|
|
29
|
-
const limit = input.limit ?? 100;
|
|
29
|
+
const limit = input.limit ?? (input.messageId === undefined ? 100 : 1);
|
|
30
30
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 500 || (input.before !== undefined && input.after !== undefined))
|
|
31
31
|
throw new SocialReadError(400, "INVALID_MESSAGE_PAGE");
|
|
32
|
+
if (input.messageId !== undefined && (!input.messageId || input.messageId.length > 256 || /[\u0000-\u001f\u007f]/.test(input.messageId) || limit !== 1 || input.before !== undefined || input.after !== undefined))
|
|
33
|
+
throw new SocialReadError(400, "INVALID_MESSAGE_LOOKUP");
|
|
32
34
|
const value = await this.request("messages", { threadId: input.threadId, ...this.teamQuery(input.teamId), limit: String(limit),
|
|
33
|
-
...(input.before === undefined ? {} : { before: input.before }), ...(input.after === undefined ? {} : { after: input.after }) }, signal);
|
|
35
|
+
...(input.before === undefined ? {} : { before: input.before }), ...(input.after === undefined ? {} : { after: input.after }), ...(input.messageId === undefined ? {} : { messageId: input.messageId }) }, signal);
|
|
34
36
|
const cursor = (token) => typeof token === "string" && /^mp1:\d+:[0-9a-f]{64}$/.test(token);
|
|
35
37
|
if (!value || !Array.isArray(value.messages) || value.messages.length > limit || !cursor(value.checkpoint)
|
|
36
38
|
|| (value.nextBefore !== null && !cursor(value.nextBefore)) || typeof value.hasMoreChanges !== "boolean" || typeof value.resetRequired !== "boolean"
|
|
37
39
|
|| value.messages.some(row => row.appId !== this.options.appId || row.threadId !== input.threadId || row.teamId !== input.teamId || !row.messageId || !Number.isFinite(row.serverCreatedAt))
|
|
38
40
|
|| (value.resetRequired && (value.messages.length || value.hasMoreChanges || value.nextBefore !== null)))
|
|
39
41
|
throw new SocialReadError(502, "INVALID_MESSAGE_PAGE_RESPONSE");
|
|
42
|
+
if (input.messageId !== undefined && (value.messages.some(row => row.messageId !== input.messageId) || value.nextBefore !== null || value.hasMoreChanges || value.resetRequired))
|
|
43
|
+
throw new SocialReadError(502, "INVALID_MESSAGE_LOOKUP_RESPONSE");
|
|
40
44
|
return value;
|
|
41
45
|
}
|
|
42
|
-
group(input) {
|
|
46
|
+
group(input, signal) {
|
|
43
47
|
this.requireTeam(input.teamId);
|
|
44
|
-
return this.request("group", { groupId: input.groupId, ...this.teamQuery(input.teamId) });
|
|
48
|
+
return this.request("group", { groupId: input.groupId, ...this.teamQuery(input.teamId) }, signal);
|
|
45
49
|
}
|
|
46
50
|
relationship(input) {
|
|
47
51
|
this.requireTeam(input.teamId);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isOffline } from "./connectivity.js";
|
|
2
|
+
/** The SDK owns upload I/O; hosts configure only their service endpoint. */
|
|
3
|
+
export function voiceUploader(profileId, endpoint = "https://upload-fc.pmate.chat", fetcher = globalThis.fetch) {
|
|
4
|
+
return async (blob, signal) => {
|
|
5
|
+
if (signal.aborted)
|
|
6
|
+
throw new DOMException("Upload aborted", "AbortError");
|
|
7
|
+
if (isOffline())
|
|
8
|
+
throw new Error("VOICE_UPLOAD_OFFLINE");
|
|
9
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
10
|
+
if (signal.aborted)
|
|
11
|
+
throw new DOMException("Upload aborted", "AbortError");
|
|
12
|
+
let binary = "";
|
|
13
|
+
for (let offset = 0; offset < bytes.length; offset += 32768)
|
|
14
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
|
|
15
|
+
const extension = blob.type.includes("mp4") ? "m4a" : blob.type.includes("mpeg") ? "mp3" : "webm";
|
|
16
|
+
const type = extension === "m4a" ? "audio/mp4" : extension === "mp3" ? "audio/mpeg" : "audio/webm";
|
|
17
|
+
if (isOffline())
|
|
18
|
+
throw new Error("VOICE_UPLOAD_OFFLINE");
|
|
19
|
+
const response = await fetcher(`${endpoint.replace(/\/+$/, "")}/file`, { method: "POST", signal, headers: { "Content-Type": "application/json", "x-file-content-type": type }, body: JSON.stringify({ user: profileId, base64: btoa(binary), filename: `voice-${Date.now()}.${extension}` }) });
|
|
20
|
+
if (!response.ok)
|
|
21
|
+
throw new Error("VOICE_UPLOAD_FAILED");
|
|
22
|
+
const result = await response.json();
|
|
23
|
+
if (typeof result.data !== "string" || !result.data)
|
|
24
|
+
throw new Error("VOICE_UPLOAD_FAILED");
|
|
25
|
+
return result.data;
|
|
26
|
+
};
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pmate/chat-sdk",
|
|
3
|
-
"version": "0.12.0-next.
|
|
3
|
+
"version": "0.12.0-next.60",
|
|
4
4
|
"description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./lib/index.js",
|
|
20
20
|
"default": "./lib/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./bootstrap": {
|
|
23
|
+
"types": "./lib/runtime/messageLaunch.d.ts",
|
|
24
|
+
"import": "./lib/runtime/messageLaunch.js",
|
|
25
|
+
"default": "./lib/runtime/messageLaunch.js"
|
|
26
|
+
},
|
|
22
27
|
"./runtime": {
|
|
23
28
|
"types": "./lib/runtime/index.d.ts",
|
|
24
29
|
"import": "./lib/runtime/index.js",
|