@heyputer/puter.js 2.1.10 → 2.1.14
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 +1 -1
- package/dist/puter.cjs +2 -2
- package/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/modules/Perms.js +239 -0
- package/src/modules/UI.js +17 -12
- package/types/modules/ai.d.ts +143 -36
- package/types/modules/auth.d.ts +25 -11
- package/types/modules/filesystem.d.ts +83 -25
- package/types/modules/hosting.d.ts +8 -11
- package/types/modules/kv.d.ts +0 -5
- package/types/puter.d.ts +2 -2
package/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Apps, AppListOptions, AppRecord, CreateAppOptions, UpdateAppAttrib
|
|
|
4
4
|
import type { Auth, APIUsage, AllowanceInfo, AppUsage, AuthUser, DetailedAppUsage, MonthlyUsage } from './types/modules/auth.d.ts';
|
|
5
5
|
import type { Debug } from './types/modules/debug.d.ts';
|
|
6
6
|
import type { Driver, DriverDescriptor, Drivers } from './types/modules/drivers.d.ts';
|
|
7
|
-
import type {
|
|
7
|
+
import type { FS, CopyOptions, DeleteOptions, MkdirOptions, MoveOptions, ReadOptions, ReaddirOptions, SignResult, SpaceInfo, UploadOptions, WriteOptions } from './types/modules/filesystem.d.ts';
|
|
8
8
|
import type { FSItem, FileSignatureInfo, InternalFSProperties } from './types/modules/fs-item.d.ts';
|
|
9
9
|
import type { Hosting, Subdomain } from './types/modules/hosting.d.ts';
|
|
10
10
|
import type { KV, KVIncrementPath, KVPair } from './types/modules/kv.d.ts';
|
|
@@ -83,7 +83,7 @@ export type {
|
|
|
83
83
|
PTLSSocket,
|
|
84
84
|
Puter,
|
|
85
85
|
PuterEnvironment,
|
|
86
|
-
|
|
86
|
+
FS,
|
|
87
87
|
ReadOptions,
|
|
88
88
|
ReaddirOptions,
|
|
89
89
|
RequestCallbacks,
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -458,6 +458,7 @@ const puterInit = (function () {
|
|
|
458
458
|
|
|
459
459
|
registerModule (name, cls, parameters = {}) {
|
|
460
460
|
const instance = new cls(this.context, parameters);
|
|
461
|
+
instance.puter = this;
|
|
461
462
|
this.modules_.push(name);
|
|
462
463
|
this[name] = instance;
|
|
463
464
|
if ( instance._init ) instance._init({ puter: this });
|
package/src/modules/Perms.js
CHANGED
|
@@ -111,4 +111,243 @@ export default class Perms {
|
|
|
111
111
|
async listGroups () {
|
|
112
112
|
return await this.req_('/group/list');
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated use .request() instead
|
|
117
|
+
*/
|
|
118
|
+
requestPermission (...a) {
|
|
119
|
+
return this.request(...a);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Request a specific permission string to be granted. Note that some
|
|
124
|
+
* permission strings are not supported and will be denied silently.
|
|
125
|
+
* @param {string} permission - permission string to request
|
|
126
|
+
* @returns {boolean} true if permission was granted, false otherwise
|
|
127
|
+
*/
|
|
128
|
+
async request (permission) {
|
|
129
|
+
// note: we cannot move this fully from "puter.ui" without
|
|
130
|
+
// a significant refactor because the UI module contains
|
|
131
|
+
// all of the IPC communication logic.
|
|
132
|
+
return await this.puter.ui.requestPermission({ permission });
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// #region shorthand functions
|
|
136
|
+
/**
|
|
137
|
+
* Request to see a user's email. If the user has already granted this
|
|
138
|
+
* permission the user will not be prompted and their email address
|
|
139
|
+
* will be returned. If the user grants permission their email address will
|
|
140
|
+
* be returned. If the user does not allow access `undefined` will be
|
|
141
|
+
* returned. If the user does not have an email address, the value of their
|
|
142
|
+
* email address will be `null`.
|
|
143
|
+
*
|
|
144
|
+
* @return {string|null|undefined} An email address or undefined
|
|
145
|
+
*/
|
|
146
|
+
async requestEmail () {
|
|
147
|
+
let whoami;
|
|
148
|
+
whoami = await this.puter.auth.whoami();
|
|
149
|
+
if ( whoami.email !== undefined ) return whoami.email;
|
|
150
|
+
const granted = await this.puter.ui.requestPermission({
|
|
151
|
+
permission: `user:${whoami.uuid}:email:read`,
|
|
152
|
+
});
|
|
153
|
+
if ( granted ) {
|
|
154
|
+
whoami = await this.puter.auth.whoami();
|
|
155
|
+
}
|
|
156
|
+
return whoami.email;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Request read access to the user's Desktop folder. If the user has already
|
|
161
|
+
* granted this permission the user will not be prompted and the path will
|
|
162
|
+
* be returned. If the user grants permission the path will be returned.
|
|
163
|
+
* If the user does not allow access `undefined` will be returned.
|
|
164
|
+
*
|
|
165
|
+
* @return {string|undefined} The Desktop path or undefined
|
|
166
|
+
*/
|
|
167
|
+
async requestReadDesktop () {
|
|
168
|
+
return this.requestFolder_('Desktop', 'read');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Request write access to the user's Desktop folder. If the user has already
|
|
173
|
+
* granted this permission the user will not be prompted and the path will
|
|
174
|
+
* be returned. If the user grants permission the path will be returned.
|
|
175
|
+
* If the user does not allow access `undefined` will be returned.
|
|
176
|
+
*
|
|
177
|
+
* @return {string|undefined} The Desktop path or undefined
|
|
178
|
+
*/
|
|
179
|
+
async requestWriteDesktop () {
|
|
180
|
+
return this.requestFolder_('Desktop', 'write');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Request read access to the user's Documents folder. If the user has already
|
|
185
|
+
* granted this permission the user will not be prompted and the path will
|
|
186
|
+
* be returned. If the user grants permission the path will be returned.
|
|
187
|
+
* If the user does not allow access `undefined` will be returned.
|
|
188
|
+
*
|
|
189
|
+
* @return {string|undefined} The Documents path or undefined
|
|
190
|
+
*/
|
|
191
|
+
async requestReadDocuments () {
|
|
192
|
+
return this.requestFolder_('Documents', 'read');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Request write access to the user's Documents folder. If the user has already
|
|
197
|
+
* granted this permission the user will not be prompted and the path will
|
|
198
|
+
* be returned. If the user grants permission the path will be returned.
|
|
199
|
+
* If the user does not allow access `undefined` will be returned.
|
|
200
|
+
*
|
|
201
|
+
* @return {string|undefined} The Documents path or undefined
|
|
202
|
+
*/
|
|
203
|
+
async requestWriteDocuments () {
|
|
204
|
+
return this.requestFolder_('Documents', 'write');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Request read access to the user's Pictures folder. If the user has already
|
|
209
|
+
* granted this permission the user will not be prompted and the path will
|
|
210
|
+
* be returned. If the user grants permission the path will be returned.
|
|
211
|
+
* If the user does not allow access `undefined` will be returned.
|
|
212
|
+
*
|
|
213
|
+
* @return {string|undefined} The Pictures path or undefined
|
|
214
|
+
*/
|
|
215
|
+
async requestReadPictures () {
|
|
216
|
+
return this.requestFolder_('Pictures', 'read');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Request write access to the user's Pictures folder. If the user has already
|
|
221
|
+
* granted this permission the user will not be prompted and the path will
|
|
222
|
+
* be returned. If the user grants permission the path will be returned.
|
|
223
|
+
* If the user does not allow access `undefined` will be returned.
|
|
224
|
+
*
|
|
225
|
+
* @return {string|undefined} The Pictures path or undefined
|
|
226
|
+
*/
|
|
227
|
+
async requestWritePictures () {
|
|
228
|
+
return this.requestFolder_('Pictures', 'write');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Request read access to the user's Videos folder. If the user has already
|
|
233
|
+
* granted this permission the user will not be prompted and the path will
|
|
234
|
+
* be returned. If the user grants permission the path will be returned.
|
|
235
|
+
* If the user does not allow access `undefined` will be returned.
|
|
236
|
+
*
|
|
237
|
+
* @return {string|undefined} The Videos path or undefined
|
|
238
|
+
*/
|
|
239
|
+
async requestReadVideos () {
|
|
240
|
+
return this.requestFolder_('Videos', 'read');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Request write access to the user's Videos folder. If the user has already
|
|
245
|
+
* granted this permission the user will not be prompted and the path will
|
|
246
|
+
* be returned. If the user grants permission the path will be returned.
|
|
247
|
+
* If the user does not allow access `undefined` will be returned.
|
|
248
|
+
*
|
|
249
|
+
* @return {string|undefined} The Videos path or undefined
|
|
250
|
+
*/
|
|
251
|
+
async requestWriteVideos () {
|
|
252
|
+
return this.requestFolder_('Videos', 'write');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Request read access to the user's apps. If the user has already granted
|
|
257
|
+
* this permission the user will not be prompted and `true` will be returned.
|
|
258
|
+
* If the user grants permission `true` will be returned. If the user does
|
|
259
|
+
* not allow access `false` will be returned.
|
|
260
|
+
*
|
|
261
|
+
* @return {boolean} Whether read access to apps was granted
|
|
262
|
+
*/
|
|
263
|
+
async requestReadApps () {
|
|
264
|
+
const whoami = await this.puter.auth.whoami();
|
|
265
|
+
const granted = await this.puter.ui.requestPermission({
|
|
266
|
+
permission: `apps-of-user:${whoami.uuid}:read`,
|
|
267
|
+
});
|
|
268
|
+
return granted;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Request write (manage) access to the user's apps. If the user has already
|
|
273
|
+
* granted this permission the user will not be prompted and `true` will be
|
|
274
|
+
* returned. If the user grants permission `true` will be returned. If the
|
|
275
|
+
* user does not allow access `false` will be returned.
|
|
276
|
+
*
|
|
277
|
+
* @return {boolean} Whether manage access to apps was granted
|
|
278
|
+
*/
|
|
279
|
+
async requestManageApps () {
|
|
280
|
+
const whoami = await this.puter.auth.whoami();
|
|
281
|
+
const granted = await this.puter.ui.requestPermission({
|
|
282
|
+
permission: `apps-of-user:${whoami.uuid}:write`,
|
|
283
|
+
});
|
|
284
|
+
return granted;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Request read access to the user's subdomains. If the user has already
|
|
289
|
+
* granted this permission the user will not be prompted and `true` will be
|
|
290
|
+
* returned. If the user grants permission `true` will be returned. If the
|
|
291
|
+
* user does not allow access `false` will be returned.
|
|
292
|
+
*
|
|
293
|
+
* @return {boolean} Whether read access to subdomains was granted
|
|
294
|
+
*/
|
|
295
|
+
async requestReadSubdomains () {
|
|
296
|
+
const whoami = await this.puter.auth.whoami();
|
|
297
|
+
const granted = await this.puter.ui.requestPermission({
|
|
298
|
+
permission: `subdomains-of-user:${whoami.uuid}:read`,
|
|
299
|
+
});
|
|
300
|
+
return granted;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Request write (manage) access to the user's subdomains. If the user has
|
|
305
|
+
* already granted this permission the user will not be prompted and `true`
|
|
306
|
+
* will be returned. If the user grants permission `true` will be returned.
|
|
307
|
+
* If the user does not allow access `false` will be returned.
|
|
308
|
+
*
|
|
309
|
+
* @return {boolean} Whether manage access to subdomains was granted
|
|
310
|
+
*/
|
|
311
|
+
async requestManageSubdomains () {
|
|
312
|
+
const whoami = await this.puter.auth.whoami();
|
|
313
|
+
const granted = await this.puter.ui.requestPermission({
|
|
314
|
+
permission: `subdomains-of-user:${whoami.uuid}:write`,
|
|
315
|
+
});
|
|
316
|
+
return granted;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Internal helper to request access to a user's special folder.
|
|
321
|
+
* @private
|
|
322
|
+
* @param {string} folderName - The name of the folder (Desktop, Documents, Pictures, Videos)
|
|
323
|
+
* @param {string} accessLevel - The access level (read, write)
|
|
324
|
+
* @return {string|undefined} The folder path or undefined
|
|
325
|
+
*/
|
|
326
|
+
async requestFolder_ (folderName, accessLevel) {
|
|
327
|
+
const whoami = await this.puter.auth.whoami();
|
|
328
|
+
const folderPath = `/${whoami.username}/${folderName}`;
|
|
329
|
+
|
|
330
|
+
// Check if we already have access by trying to stat the folder
|
|
331
|
+
try {
|
|
332
|
+
await this.puter.fs.stat({ path: folderPath });
|
|
333
|
+
|
|
334
|
+
// If we can stat the folder, we have at least read access
|
|
335
|
+
if ( accessLevel !== 'write' ) {
|
|
336
|
+
return folderPath;
|
|
337
|
+
}
|
|
338
|
+
} catch (e) {
|
|
339
|
+
// No access yet, need to request permission
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const granted = await this.puter.ui.requestPermission({
|
|
343
|
+
permission: `fs:${folderPath}:${accessLevel}`,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
if ( granted ) {
|
|
347
|
+
return folderPath;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
// #endregion
|
|
114
353
|
}
|
package/src/modules/UI.js
CHANGED
|
@@ -182,7 +182,15 @@ class UI extends EventListener {
|
|
|
182
182
|
...args,
|
|
183
183
|
}, '*');
|
|
184
184
|
//register callback
|
|
185
|
-
this.#callbackFunctions[msg_id] =
|
|
185
|
+
this.#callbackFunctions[msg_id] = (...a) => {
|
|
186
|
+
resolve(...a);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#postMessageAsync (name, args = {}) {
|
|
191
|
+
return new Promise(resolve => {
|
|
192
|
+
this.#postMessageWithCallback(name, resolve, args);
|
|
193
|
+
});
|
|
186
194
|
}
|
|
187
195
|
|
|
188
196
|
#postMessageWithObject (name, value) {
|
|
@@ -974,17 +982,14 @@ class UI extends EventListener {
|
|
|
974
982
|
this.#postMessageWithObject('setMenubar', spec);
|
|
975
983
|
};
|
|
976
984
|
|
|
977
|
-
requestPermission (options) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
resolve(false);
|
|
986
|
-
}
|
|
987
|
-
});
|
|
985
|
+
async requestPermission (options) {
|
|
986
|
+
if ( this.env === 'app' ) {
|
|
987
|
+
const result = await this.#postMessageAsync('requestPermission', { options });
|
|
988
|
+
return result.granted;
|
|
989
|
+
} else {
|
|
990
|
+
// TODO: Implement for web
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
988
993
|
};
|
|
989
994
|
|
|
990
995
|
disableMenuItem (item_id) {
|
package/types/modules/ai.d.ts
CHANGED
|
@@ -3,34 +3,53 @@ export type AIMessageContent = string | { image_url?: { url: string } } | Record
|
|
|
3
3
|
export interface ChatMessage {
|
|
4
4
|
role?: string;
|
|
5
5
|
content: AIMessageContent | AIMessageContent[];
|
|
6
|
-
[
|
|
6
|
+
tool_calls?: ToolCall[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ToolCall {
|
|
10
|
+
id: string;
|
|
11
|
+
function: { name: string, arguments: string };
|
|
7
12
|
}
|
|
8
13
|
|
|
9
14
|
export interface ChatOptions {
|
|
10
15
|
model?: string;
|
|
11
16
|
temperature?: number;
|
|
12
17
|
max_tokens?: number;
|
|
13
|
-
stream?: boolean;
|
|
14
18
|
vision?: boolean;
|
|
15
|
-
|
|
19
|
+
driver?: string;
|
|
20
|
+
tools?: unknown;
|
|
21
|
+
response?: unknown;
|
|
22
|
+
reasoning?: unknown;
|
|
23
|
+
reasoning_effort?: string;
|
|
24
|
+
text?: unknown;
|
|
25
|
+
verbosity?: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface StreamingChatOptions extends ChatOptions {
|
|
29
|
+
stream: boolean;
|
|
16
30
|
}
|
|
17
31
|
|
|
18
32
|
export interface ChatResponse {
|
|
19
33
|
message?: ChatMessage;
|
|
20
34
|
choices?: unknown;
|
|
21
|
-
[key: string]: unknown;
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
export interface ChatResponseChunk {
|
|
25
38
|
text?: string;
|
|
26
|
-
|
|
39
|
+
reasoning?: string;
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
export interface Img2TxtOptions {
|
|
30
43
|
source?: string | File | Blob;
|
|
31
44
|
provider?: string;
|
|
32
45
|
testMode?: boolean;
|
|
33
|
-
|
|
46
|
+
model?: string;
|
|
47
|
+
pages?: number[];
|
|
48
|
+
includeImageBase64?: boolean;
|
|
49
|
+
imageLimit?: number;
|
|
50
|
+
imageMinSize?: number;
|
|
51
|
+
bboxAnnotationFormat?: string;
|
|
52
|
+
documentAnnotationFormat?: string;
|
|
34
53
|
}
|
|
35
54
|
|
|
36
55
|
export interface Txt2ImgOptions {
|
|
@@ -39,18 +58,52 @@ export interface Txt2ImgOptions {
|
|
|
39
58
|
quality?: string;
|
|
40
59
|
input_image?: string;
|
|
41
60
|
input_image_mime_type?: string;
|
|
42
|
-
|
|
61
|
+
driver?: string;
|
|
62
|
+
provider?: string;
|
|
63
|
+
service?: string;
|
|
64
|
+
ratio?: { w: number; h: number };
|
|
65
|
+
width?: number;
|
|
66
|
+
height?: number;
|
|
67
|
+
aspect_ratio?: string;
|
|
68
|
+
steps?: number;
|
|
69
|
+
seed?: number;
|
|
70
|
+
negative_prompt?: string;
|
|
71
|
+
n?: number;
|
|
72
|
+
image_url?: string;
|
|
73
|
+
image_base64?: string;
|
|
74
|
+
mask_image_url?: string;
|
|
75
|
+
mask_image_base64?: string;
|
|
76
|
+
prompt_strength?: number;
|
|
77
|
+
disable_safety_checker?: boolean;
|
|
78
|
+
response_format?: string;
|
|
79
|
+
test_mode?: boolean;
|
|
43
80
|
}
|
|
44
81
|
|
|
45
82
|
export interface Txt2VidOptions {
|
|
46
83
|
prompt?: string;
|
|
84
|
+
provider?: string;
|
|
47
85
|
model?: string;
|
|
48
|
-
|
|
86
|
+
seconds?: number;
|
|
87
|
+
test_mode?: boolean;
|
|
88
|
+
|
|
89
|
+
// OpenAI options
|
|
90
|
+
size?: string;
|
|
91
|
+
resolution?: string;
|
|
92
|
+
input_reference?: File;
|
|
93
|
+
|
|
94
|
+
// TogetherAI options
|
|
49
95
|
width?: number;
|
|
50
96
|
height?: number;
|
|
51
97
|
fps?: number;
|
|
52
98
|
steps?: number;
|
|
53
|
-
|
|
99
|
+
guidance_scale?: number;
|
|
100
|
+
seed?: number;
|
|
101
|
+
output_format?: string;
|
|
102
|
+
output_quality?: number;
|
|
103
|
+
negative_prompt?: string;
|
|
104
|
+
reference_images?: string[];
|
|
105
|
+
frame_images?: Array<{ input_image: string; frame: number }>;
|
|
106
|
+
metadata?: Record<string, unknown>;
|
|
54
107
|
}
|
|
55
108
|
|
|
56
109
|
export interface Txt2SpeechOptions {
|
|
@@ -61,26 +114,43 @@ export interface Txt2SpeechOptions {
|
|
|
61
114
|
provider?: string;
|
|
62
115
|
model?: string;
|
|
63
116
|
response_format?: string;
|
|
64
|
-
|
|
117
|
+
output_format?: string;
|
|
118
|
+
instructions?: string;
|
|
119
|
+
voice_settings?: Record<string, unknown>;
|
|
120
|
+
ssml?: boolean;
|
|
121
|
+
test_mode?: boolean;
|
|
65
122
|
}
|
|
66
123
|
|
|
67
|
-
export interface
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
listVoices: (options?: string | Record<string, unknown>) => Promise<unknown>;
|
|
124
|
+
export interface Speech2TxtResult {
|
|
125
|
+
text: string;
|
|
126
|
+
language: string;
|
|
127
|
+
segments?: Record<string, unknown>[];
|
|
72
128
|
}
|
|
73
129
|
|
|
74
|
-
|
|
130
|
+
interface BaseSpeech2TxtOptions {
|
|
75
131
|
file?: string | File | Blob;
|
|
76
132
|
audio?: string | File | Blob;
|
|
77
133
|
model?: string;
|
|
78
|
-
response_format?: string;
|
|
79
134
|
language?: string;
|
|
80
135
|
prompt?: string;
|
|
81
136
|
stream?: boolean;
|
|
82
137
|
translate?: boolean;
|
|
83
|
-
|
|
138
|
+
temperature?: number;
|
|
139
|
+
logprobs?: boolean;
|
|
140
|
+
timestamp_granularities?: string[];
|
|
141
|
+
chunking_strategy?: string;
|
|
142
|
+
known_speaker_names?: string[];
|
|
143
|
+
known_speaker_references?: string[];
|
|
144
|
+
extra_body?: Record<string, unknown>;
|
|
145
|
+
test_mode?: boolean;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface TextFormatSpeech2TxtOptions extends BaseSpeech2TxtOptions {
|
|
149
|
+
response_format: "text";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface Speech2TxtOptions extends BaseSpeech2TxtOptions {
|
|
153
|
+
response_format?: Exclude<string, "text">;
|
|
84
154
|
}
|
|
85
155
|
|
|
86
156
|
export interface Speech2SpeechOptions {
|
|
@@ -88,36 +158,73 @@ export interface Speech2SpeechOptions {
|
|
|
88
158
|
file?: string | File | Blob;
|
|
89
159
|
provider?: string;
|
|
90
160
|
model?: string;
|
|
161
|
+
modelId?: string;
|
|
162
|
+
model_id?: string;
|
|
91
163
|
voice?: string;
|
|
92
|
-
|
|
164
|
+
voiceId?: string;
|
|
165
|
+
voice_id?: string;
|
|
166
|
+
output_format?: string;
|
|
167
|
+
outputFormat?: string;
|
|
168
|
+
voice_settings?: Record<string, unknown>;
|
|
169
|
+
voiceSettings?: Record<string, unknown>;
|
|
170
|
+
seed?: number;
|
|
171
|
+
file_format?: string;
|
|
172
|
+
fileFormat?: string;
|
|
173
|
+
remove_background_noise?: boolean;
|
|
174
|
+
removeBackgroundNoise?: boolean;
|
|
175
|
+
optimize_streaming_latency?: number;
|
|
176
|
+
optimizeStreamingLatency?: number;
|
|
177
|
+
enable_logging?: boolean;
|
|
178
|
+
enableLogging?: boolean;
|
|
179
|
+
test_mode?: boolean;
|
|
93
180
|
}
|
|
94
181
|
|
|
95
182
|
export class AI {
|
|
96
|
-
constructor (context: { authToken?: string; APIOrigin: string; appID?: string });
|
|
97
|
-
|
|
98
|
-
setAuthToken (authToken: string): void;
|
|
99
|
-
setAPIOrigin (APIOrigin: string): void;
|
|
100
|
-
|
|
101
183
|
listModels (provider?: string): Promise<Record<string, unknown>[]>;
|
|
102
184
|
listModelProviders (): Promise<string[]>;
|
|
103
185
|
|
|
104
|
-
chat (prompt: string,
|
|
105
|
-
chat (prompt: string,
|
|
106
|
-
chat (
|
|
107
|
-
chat (prompt: string,
|
|
108
|
-
chat (prompt: string, imageURL: string | File, options: ChatOptions
|
|
109
|
-
chat (
|
|
110
|
-
|
|
186
|
+
chat (prompt: string, testMode?: boolean): Promise<ChatResponse>;
|
|
187
|
+
chat (prompt: string, options: ChatOptions, testMode?: boolean): Promise<ChatResponse>;
|
|
188
|
+
chat (prompt: string, imageURL: string | File, testMode?: boolean): Promise<ChatResponse>;
|
|
189
|
+
chat (prompt: string, imageURLArray: string[], testMode?: boolean): Promise<ChatResponse>;
|
|
190
|
+
chat (prompt: string, imageURL: string | File, options: ChatOptions, testMode?: boolean): Promise<ChatResponse>;
|
|
191
|
+
chat (prompt: string, imageURLArray: string[], options: ChatOptions, testMode?: boolean): Promise<ChatResponse>;
|
|
192
|
+
|
|
193
|
+
chat (prompt: string, options: StreamingChatOptions, testMode?: boolean): AsyncIterable<ChatResponseChunk>;
|
|
194
|
+
chat (prompt: string, imageURL: string | File, options: StreamingChatOptions, testMode?: boolean): AsyncIterable<ChatResponseChunk>;
|
|
195
|
+
chat (prompt: string, imageURLArray: string[], options: StreamingChatOptions, testMode?: boolean): AsyncIterable<ChatResponseChunk>;
|
|
196
|
+
|
|
197
|
+
chat (messages: ChatMessage[], testMode?: boolean): Promise<ChatResponse>;
|
|
198
|
+
chat (messages: ChatMessage[], options: ChatOptions, testMode?: boolean): Promise<ChatResponse>;
|
|
199
|
+
chat (messages: ChatMessage[], options: StreamingChatOptions, testMode?: boolean): AsyncIterable<ChatResponseChunk>;
|
|
200
|
+
|
|
201
|
+
img2txt (source: string | File | Blob, testMode?: boolean): Promise<string>;
|
|
202
|
+
img2txt (source: string | File | Blob, options: Img2TxtOptions, testMode?: boolean): Promise<string>;
|
|
203
|
+
img2txt (options: Img2TxtOptions, testMode?: boolean): Promise<string>;
|
|
111
204
|
|
|
112
|
-
img2txt (source: string | File | Blob | Img2TxtOptions, testMode?: boolean): Promise<string>;
|
|
113
205
|
txt2img (prompt: string, testMode?: boolean): Promise<HTMLImageElement>;
|
|
114
206
|
txt2img (prompt: string, options: Txt2ImgOptions): Promise<HTMLImageElement>;
|
|
207
|
+
txt2img (options: Txt2ImgOptions, testMode?: boolean): Promise<HTMLImageElement>;
|
|
208
|
+
|
|
115
209
|
txt2vid (prompt: string, testMode?: boolean): Promise<HTMLVideoElement>;
|
|
116
210
|
txt2vid (prompt: string, options: Txt2VidOptions): Promise<HTMLVideoElement>;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
211
|
+
txt2vid (options: Txt2VidOptions, testMode?: boolean): Promise<HTMLVideoElement>;
|
|
212
|
+
|
|
213
|
+
speech2txt (source: string | File | Blob, testMode?: boolean): Promise<string>;
|
|
214
|
+
speech2txt (source: string | File | Blob, options: TextFormatSpeech2TxtOptions, testMode?: boolean): Promise<string>;
|
|
215
|
+
speech2txt (source: string | File | Blob, options: Speech2TxtOptions, testMode?: boolean): Promise<Speech2TxtResult>;
|
|
216
|
+
speech2txt (options: TextFormatSpeech2TxtOptions, testMode?: boolean): Promise<string>;
|
|
217
|
+
speech2txt (options: Speech2TxtOptions, testMode?: boolean): Promise<Speech2TxtResult>;
|
|
218
|
+
|
|
219
|
+
speech2speech (source: string | File | Blob, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
220
|
+
speech2speech (source: string | File | Blob, options: Speech2SpeechOptions, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
221
|
+
speech2speech (options: Speech2SpeechOptions, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
222
|
+
|
|
223
|
+
txt2speech (text: string, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
224
|
+
txt2speech (text: string, options: Txt2SpeechOptions, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
225
|
+
txt2speech (text: string, language: string, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
226
|
+
txt2speech (text: string, language: string, voice: string, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
227
|
+
txt2speech (text: string, language: string, voice: string, engine: string, testMode?: boolean): Promise<HTMLAudioElement>;
|
|
121
228
|
}
|
|
122
229
|
|
|
123
230
|
// NOTE: AI responses contain provider-specific payloads that are not fully typed here because
|
package/types/modules/auth.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface User {
|
|
2
2
|
uuid: string;
|
|
3
3
|
username: string;
|
|
4
|
-
email_confirmed?: boolean;
|
|
5
|
-
|
|
4
|
+
email_confirmed?: boolean | number;
|
|
5
|
+
actual_free_storage?: number;
|
|
6
|
+
app_name?: string;
|
|
7
|
+
feature_flags?: Record<string, unknown>;
|
|
8
|
+
hasDevAccountAccess?: boolean;
|
|
9
|
+
is_temp?: boolean;
|
|
10
|
+
last_activity_ts?: number;
|
|
11
|
+
otp?: boolean;
|
|
12
|
+
paid_storage?: number;
|
|
13
|
+
referral_code?: string;
|
|
14
|
+
requires_email_confirmation?: boolean | number;
|
|
15
|
+
subscribed?: boolean;
|
|
6
16
|
}
|
|
7
17
|
|
|
8
18
|
export interface AllowanceInfo {
|
|
@@ -32,17 +42,21 @@ export interface DetailedAppUsage {
|
|
|
32
42
|
[key: string]: APIUsage;
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
export interface SignInResult {
|
|
46
|
+
success: boolean;
|
|
47
|
+
token: string;
|
|
48
|
+
app_uid: string;
|
|
49
|
+
username: string;
|
|
50
|
+
error?: string;
|
|
51
|
+
msg?: string;
|
|
52
|
+
}
|
|
40
53
|
|
|
41
|
-
|
|
54
|
+
export class Auth {
|
|
55
|
+
signIn (options?: { attempt_temp_user_creation?: boolean }): Promise<SignInResult>;
|
|
42
56
|
signOut (): void;
|
|
43
57
|
isSignedIn (): boolean;
|
|
44
|
-
getUser (): Promise<
|
|
45
|
-
whoami (): Promise<
|
|
58
|
+
getUser (): Promise<User>;
|
|
59
|
+
whoami (): Promise<User>;
|
|
46
60
|
getMonthlyUsage (): Promise<MonthlyUsage>;
|
|
47
61
|
getDetailedAppUsage (appId: string): Promise<DetailedAppUsage>;
|
|
48
62
|
}
|