@heyputer/puter.js 2.0.4 → 2.0.6
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/puter.js +2 -2
- package/index.d.ts +496 -0
- package/package.json +3 -2
- package/src/modules/FileSystem/index.js +46 -29
- package/src/safeLoadPuter.cjs +2 -3
- package/src/services/Filesystem.js +43 -25
package/index.d.ts
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
// index.d.ts
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
puter: Puter;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare class Puter {
|
|
10
|
+
// Properties
|
|
11
|
+
appID: string;
|
|
12
|
+
env: 'app' | 'web' | 'gui';
|
|
13
|
+
|
|
14
|
+
// Utility methods
|
|
15
|
+
print(text: string, options?: { code?: boolean }): void;
|
|
16
|
+
randName(separator?: string): string;
|
|
17
|
+
exit(statusCode?: number): void;
|
|
18
|
+
|
|
19
|
+
// Sub-modules
|
|
20
|
+
ai: AI;
|
|
21
|
+
apps: Apps;
|
|
22
|
+
auth: Auth;
|
|
23
|
+
drivers: Drivers;
|
|
24
|
+
fs: FileSystem;
|
|
25
|
+
hosting: Hosting;
|
|
26
|
+
kv: KV;
|
|
27
|
+
net: Networking;
|
|
28
|
+
perms: Permissions;
|
|
29
|
+
ui: UI;
|
|
30
|
+
workers: Workers;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// AI Module
|
|
34
|
+
interface AI {
|
|
35
|
+
chat(prompt: string, options?: ChatOptions): Promise<ChatResponse>;
|
|
36
|
+
chat(prompt: string, testMode?: boolean, options?: ChatOptions): Promise<ChatResponse>;
|
|
37
|
+
chat(prompt: string, imageURL?: string, testMode?: boolean, options?: ChatOptions): Promise<ChatResponse>;
|
|
38
|
+
chat(prompt: string, imageURLArray?: string[], testMode?: boolean, options?: ChatOptions): Promise<ChatResponse>;
|
|
39
|
+
chat(messages: ChatMessage[], testMode?: boolean, options?: ChatOptions): Promise<ChatResponse>;
|
|
40
|
+
|
|
41
|
+
img2txt(image: string | File | Blob, testMode?: boolean): Promise<string>;
|
|
42
|
+
|
|
43
|
+
txt2img(prompt: string, testMode?: boolean): Promise<HTMLImageElement>;
|
|
44
|
+
txt2img(prompt: string, options?: Txt2ImgOptions): Promise<HTMLImageElement>;
|
|
45
|
+
|
|
46
|
+
txt2speech(text: string): Promise<HTMLAudioElement>;
|
|
47
|
+
txt2speech(text: string, options?: Txt2SpeechOptions): Promise<HTMLAudioElement>;
|
|
48
|
+
txt2speech(text: string, language?: string): Promise<HTMLAudioElement>;
|
|
49
|
+
txt2speech(text: string, language?: string, voice?: string): Promise<HTMLAudioElement>;
|
|
50
|
+
txt2speech(text: string, language?: string, voice?: string, engine?: string): Promise<HTMLAudioElement>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ChatOptions {
|
|
54
|
+
model?: string;
|
|
55
|
+
stream?: boolean;
|
|
56
|
+
max_tokens?: number;
|
|
57
|
+
temperature?: number;
|
|
58
|
+
tools?: ToolDefinition[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface ToolDefinition {
|
|
62
|
+
type: 'function';
|
|
63
|
+
function: {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
parameters: object;
|
|
67
|
+
strict?: boolean;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface ChatMessage {
|
|
72
|
+
role: 'system' | 'assistant' | 'user' | 'function' | 'tool';
|
|
73
|
+
content: string | ContentObject[];
|
|
74
|
+
tool_call_id?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface ContentObject {
|
|
78
|
+
type: 'text' | 'file';
|
|
79
|
+
text?: string;
|
|
80
|
+
puter_path?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface ChatResponse {
|
|
84
|
+
message: {
|
|
85
|
+
role: string;
|
|
86
|
+
content: string;
|
|
87
|
+
tool_calls?: ToolCall[];
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface ToolCall {
|
|
92
|
+
id: string;
|
|
93
|
+
function: {
|
|
94
|
+
name: string;
|
|
95
|
+
arguments: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface Txt2ImgOptions {
|
|
100
|
+
model?: 'gpt-image-1' | 'gemini-2.5-flash-image-preview' | 'dall-e-3';
|
|
101
|
+
quality?: 'high' | 'medium' | 'low' | 'hd' | 'standard';
|
|
102
|
+
input_image?: string;
|
|
103
|
+
input_image_mime_type?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface Txt2SpeechOptions {
|
|
107
|
+
language?: string;
|
|
108
|
+
voice?: string;
|
|
109
|
+
engine?: 'standard' | 'neural' | 'generative';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Apps Module
|
|
113
|
+
interface Apps {
|
|
114
|
+
create(name: string, indexURL: string): Promise<App>;
|
|
115
|
+
create(name: string, indexURL: string, title?: string): Promise<App>;
|
|
116
|
+
create(name: string, indexURL: string, title?: string, description?: string): Promise<App>;
|
|
117
|
+
create(options: CreateAppOptions): Promise<App>;
|
|
118
|
+
|
|
119
|
+
delete(name: string): Promise<App>;
|
|
120
|
+
get(name: string, options?: GetAppOptions): Promise<App>;
|
|
121
|
+
list(options?: ListAppOptions): Promise<App[]>;
|
|
122
|
+
update(name: string, attributes: UpdateAppAttributes): Promise<App>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface CreateAppOptions {
|
|
126
|
+
name: string;
|
|
127
|
+
indexURL: string;
|
|
128
|
+
title?: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
icon?: string;
|
|
131
|
+
maximizeOnStart?: boolean;
|
|
132
|
+
filetypeAssociations?: string[];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface GetAppOptions {
|
|
136
|
+
stats_period?: StatsPeriod;
|
|
137
|
+
icon_size?: null | 16 | 32 | 64 | 128 | 256 | 512;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface ListAppOptions extends GetAppOptions { }
|
|
141
|
+
|
|
142
|
+
interface UpdateAppAttributes {
|
|
143
|
+
name?: string;
|
|
144
|
+
indexURL?: string;
|
|
145
|
+
title?: string;
|
|
146
|
+
description?: string;
|
|
147
|
+
icon?: string;
|
|
148
|
+
maximizeOnStart?: boolean;
|
|
149
|
+
filetypeAssociations?: string[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type StatsPeriod = 'all' | 'today' | 'yesterday' | '7d' | '30d' | 'this_month' | 'last_month' | 'this_year' | 'last_year' | 'month_to_date' | 'year_to_date' | 'last_12_months';
|
|
153
|
+
|
|
154
|
+
interface App {
|
|
155
|
+
uid: string;
|
|
156
|
+
name: string;
|
|
157
|
+
icon: string;
|
|
158
|
+
description: string;
|
|
159
|
+
title: string;
|
|
160
|
+
maximize_on_start: boolean;
|
|
161
|
+
index_url: string;
|
|
162
|
+
created_at: string;
|
|
163
|
+
background: boolean;
|
|
164
|
+
filetype_associations: string[];
|
|
165
|
+
open_count: number;
|
|
166
|
+
user_count: number;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Auth Module
|
|
170
|
+
interface Auth {
|
|
171
|
+
signIn(options?: { attempt_temp_user_creation?: boolean }): Promise<boolean>;
|
|
172
|
+
signOut(): void;
|
|
173
|
+
isSignedIn(): boolean;
|
|
174
|
+
getUser(): Promise<User>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
interface User {
|
|
178
|
+
uuid: string;
|
|
179
|
+
username: string;
|
|
180
|
+
email_confirmed: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Drivers Module
|
|
184
|
+
interface Drivers {
|
|
185
|
+
call(interface: string, driver: string, method: string, args?: object): Promise<any>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// FileSystem Module
|
|
189
|
+
interface FileSystem {
|
|
190
|
+
copy(source: string, destination: string, options?: CopyOptions): Promise<FSItem>;
|
|
191
|
+
delete(path: string, options?: DeleteOptions): Promise<void>;
|
|
192
|
+
getReadURL(path: string, expiresIn?: number): Promise<string>;
|
|
193
|
+
mkdir(path: string, options?: MkdirOptions): Promise<FSItem>;
|
|
194
|
+
move(source: string, destination: string, options?: MoveOptions): Promise<FSItem>;
|
|
195
|
+
read(path: string, options?: ReadOptions): Promise<Blob>;
|
|
196
|
+
readdir(path: string, options?: ReaddirOptions): Promise<FSItem[]>;
|
|
197
|
+
readdir(options?: ReaddirOptions): Promise<FSItem[]>;
|
|
198
|
+
rename(path: string, newName: string): Promise<FSItem>;
|
|
199
|
+
space(): Promise<SpaceInfo>;
|
|
200
|
+
stat(path: string): Promise<FSItem>;
|
|
201
|
+
upload(items: FileList | File[] | Blob[], dirPath?: string, options?: object): Promise<FSItem[]>;
|
|
202
|
+
write(path: string, data?: string | File | Blob, options?: WriteOptions): Promise<FSItem>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface CopyOptions {
|
|
206
|
+
overwrite?: boolean;
|
|
207
|
+
dedupeName?: boolean;
|
|
208
|
+
newName?: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
interface DeleteOptions {
|
|
212
|
+
recursive?: boolean;
|
|
213
|
+
descendantsOnly?: boolean;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
interface MkdirOptions {
|
|
217
|
+
overwrite?: boolean;
|
|
218
|
+
dedupeName?: boolean;
|
|
219
|
+
createMissingParents?: boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
interface MoveOptions extends CopyOptions {
|
|
223
|
+
createMissingParents?: boolean;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface ReadOptions {
|
|
227
|
+
offset?: number;
|
|
228
|
+
byte_count?: number;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
interface ReaddirOptions {
|
|
232
|
+
path?: string;
|
|
233
|
+
uid?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface WriteOptions {
|
|
237
|
+
overwrite?: boolean;
|
|
238
|
+
dedupeName?: boolean;
|
|
239
|
+
createMissingParents?: boolean;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface SpaceInfo {
|
|
243
|
+
capacity: number;
|
|
244
|
+
used: number;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface FSItem {
|
|
248
|
+
id: string;
|
|
249
|
+
uid: string;
|
|
250
|
+
name: string;
|
|
251
|
+
path: string;
|
|
252
|
+
is_dir: boolean;
|
|
253
|
+
parent_id: string;
|
|
254
|
+
parent_uid: string;
|
|
255
|
+
created: number;
|
|
256
|
+
modified: number;
|
|
257
|
+
accessed: number;
|
|
258
|
+
size: number | null;
|
|
259
|
+
writable: boolean;
|
|
260
|
+
read(): Promise<Blob>;
|
|
261
|
+
readdir(): Promise<FSItem[]>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Hosting Module
|
|
265
|
+
interface Hosting {
|
|
266
|
+
create(subdomain: string, dirPath?: string): Promise<Subdomain>;
|
|
267
|
+
delete(subdomain: string): Promise<boolean>;
|
|
268
|
+
get(subdomain: string): Promise<Subdomain>;
|
|
269
|
+
list(): Promise<Subdomain[]>;
|
|
270
|
+
update(subdomain: string, dirPath?: string): Promise<Subdomain>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
interface Subdomain {
|
|
274
|
+
uid: string;
|
|
275
|
+
subdomain: string;
|
|
276
|
+
root_dir: FSItem;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Key-Value Store Module
|
|
280
|
+
interface KV {
|
|
281
|
+
set(key: string, value: string | number | boolean | object | any[]): Promise<boolean>;
|
|
282
|
+
get(key: string): Promise<any>;
|
|
283
|
+
del(key: string): Promise<boolean>;
|
|
284
|
+
incr(key: string, amount?: number): Promise<number>;
|
|
285
|
+
decr(key: string, amount?: number): Promise<number>;
|
|
286
|
+
list(pattern?: string, returnValues?: boolean): Promise<string[] | KVPair[]>;
|
|
287
|
+
list(returnValues?: boolean): Promise<string[] | KVPair[]>;
|
|
288
|
+
flush(): Promise<boolean>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
interface KVPair {
|
|
292
|
+
key: string;
|
|
293
|
+
value: any;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Networking Module
|
|
297
|
+
interface Networking {
|
|
298
|
+
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
299
|
+
Socket: typeof Socket;
|
|
300
|
+
tls: {
|
|
301
|
+
TLSSocket: typeof TLSSocket;
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
declare class Socket {
|
|
306
|
+
constructor(hostname: string, port: number);
|
|
307
|
+
write(data: ArrayBuffer | Uint8Array | string): void;
|
|
308
|
+
close(): void;
|
|
309
|
+
on(event: 'open', callback: () => void): void;
|
|
310
|
+
on(event: 'data', callback: (buffer: Uint8Array) => void): void;
|
|
311
|
+
on(event: 'error', callback: (reason: string) => void): void;
|
|
312
|
+
on(event: 'close', callback: (hadError: boolean) => void): void;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
declare class TLSSocket extends Socket {
|
|
316
|
+
constructor(hostname: string, port: number);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Permissions Module
|
|
320
|
+
interface Permissions {
|
|
321
|
+
grantApp(app_uid: string, permissionString: string): Promise<object>;
|
|
322
|
+
grantAppAnyUser(app_uid: string, permissionString: string): Promise<object>;
|
|
323
|
+
grantGroup(group_uid: string, permissionString: string): Promise<object>;
|
|
324
|
+
grantOrigin(origin: string, permissionString: string): Promise<object>;
|
|
325
|
+
grantUser(username: string, permissionString: string): Promise<object>;
|
|
326
|
+
revokeApp(app_uid: string, permissionString: string): Promise<object>;
|
|
327
|
+
revokeAppAnyUser(app_uid: string, permissionString: string): Promise<object>;
|
|
328
|
+
revokeGroup(group_uid: string, permissionString: string): Promise<object>;
|
|
329
|
+
revokeOrigin(origin: string, permissionString: string): Promise<object>;
|
|
330
|
+
revokeUser(username: string, permissionString: string): Promise<object>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// UI Module
|
|
334
|
+
interface UI {
|
|
335
|
+
alert(message?: string, buttons?: AlertButton[]): Promise<string>;
|
|
336
|
+
prompt(message?: string, defaultValue?: string): Promise<string | null>;
|
|
337
|
+
authenticateWithPuter(): Promise<boolean>;
|
|
338
|
+
contextMenu(options: ContextMenuOptions): void;
|
|
339
|
+
createWindow(options?: WindowOptions): void;
|
|
340
|
+
exit(statusCode?: number): void;
|
|
341
|
+
getLanguage(): Promise<string>;
|
|
342
|
+
hideSpinner(): void;
|
|
343
|
+
launchApp(appName?: string, args?: object): Promise<AppConnection>;
|
|
344
|
+
launchApp(options: LaunchAppOptions): Promise<AppConnection>;
|
|
345
|
+
on(eventName: 'localeChanged', handler: (data: { language: string }) => void): void;
|
|
346
|
+
on(eventName: 'themeChanged', handler: (data: ThemeData) => void): void;
|
|
347
|
+
onItemsOpened(handler: (items: FSItem[]) => void): void;
|
|
348
|
+
onLaunchedWithItems(handler: (items: FSItem[]) => void): void;
|
|
349
|
+
onWindowClose(handler: () => void): void;
|
|
350
|
+
parentApp(): AppConnection | null;
|
|
351
|
+
setMenubar(options: MenubarOptions): void;
|
|
352
|
+
setWindowHeight(height: number): void;
|
|
353
|
+
setWindowPosition(x: number, y: number): void;
|
|
354
|
+
setWindowSize(width: number, height: number): void;
|
|
355
|
+
setWindowTitle(title: string): void;
|
|
356
|
+
setWindowWidth(width: number): void;
|
|
357
|
+
setWindowX(x: number): void;
|
|
358
|
+
setWindowY(y: number): void;
|
|
359
|
+
showColorPicker(defaultColor?: string): Promise<string>;
|
|
360
|
+
showColorPicker(options?: object): Promise<string>;
|
|
361
|
+
showDirectoryPicker(options?: { multiple?: boolean }): Promise<FSItem | FSItem[]>;
|
|
362
|
+
showFontPicker(defaultFont?: string): Promise<{ fontFamily: string }>;
|
|
363
|
+
showFontPicker(options?: object): Promise<{ fontFamily: string }>;
|
|
364
|
+
showOpenFilePicker(options?: FilePickerOptions): Promise<FSItem | FSItem[]>;
|
|
365
|
+
showSaveFilePicker(data?: any, defaultFileName?: string): Promise<FSItem>;
|
|
366
|
+
showSpinner(): void;
|
|
367
|
+
socialShare(url: string, message?: string, options?: { left?: number; top?: number }): void;
|
|
368
|
+
wasLaunchedWithItems(): boolean;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
interface AlertButton {
|
|
372
|
+
label: string;
|
|
373
|
+
value?: string;
|
|
374
|
+
type?: 'primary' | 'success' | 'info' | 'warning' | 'danger';
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
interface ContextMenuOptions {
|
|
378
|
+
items: (ContextMenuItem | '-')[];
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
interface ContextMenuItem {
|
|
382
|
+
label: string;
|
|
383
|
+
action?: () => void;
|
|
384
|
+
icon?: string;
|
|
385
|
+
icon_active?: string;
|
|
386
|
+
disabled?: boolean;
|
|
387
|
+
items?: (ContextMenuItem | '-')[];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
interface WindowOptions {
|
|
391
|
+
center?: boolean;
|
|
392
|
+
content?: string;
|
|
393
|
+
disable_parent_window?: boolean;
|
|
394
|
+
has_head?: boolean;
|
|
395
|
+
height?: number;
|
|
396
|
+
is_resizable?: boolean;
|
|
397
|
+
show_in_taskbar?: boolean;
|
|
398
|
+
title?: string;
|
|
399
|
+
width?: number;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
interface LaunchAppOptions {
|
|
403
|
+
name?: string;
|
|
404
|
+
args?: object;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
interface ThemeData {
|
|
408
|
+
palette: {
|
|
409
|
+
primaryHue: number;
|
|
410
|
+
primarySaturation: string;
|
|
411
|
+
primaryLightness: string;
|
|
412
|
+
primaryAlpha: number;
|
|
413
|
+
primaryColor: string;
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
interface MenubarOptions {
|
|
418
|
+
items: MenuItem[];
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
interface MenuItem {
|
|
422
|
+
label: string;
|
|
423
|
+
action?: () => void;
|
|
424
|
+
items?: MenuItem[];
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
interface FilePickerOptions {
|
|
428
|
+
multiple?: boolean;
|
|
429
|
+
accept?: string | string[];
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
interface AppConnection {
|
|
433
|
+
usesSDK: boolean;
|
|
434
|
+
on(eventName: 'message', handler: (message: any) => void): void;
|
|
435
|
+
on(eventName: 'close', handler: (data: { appInstanceID: string }) => void): void;
|
|
436
|
+
off(eventName: string, handler: Function): void;
|
|
437
|
+
postMessage(message: any): void;
|
|
438
|
+
close(): void;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Workers Module
|
|
442
|
+
interface Workers {
|
|
443
|
+
create(workerName: string, filePath: string): Promise<WorkerDeployment>;
|
|
444
|
+
delete(workerName: string): Promise<boolean>;
|
|
445
|
+
exec(workerURL: string, options?: WorkerExecOptions): Promise<Response>;
|
|
446
|
+
get(workerName: string): Promise<WorkerInfo>;
|
|
447
|
+
list(): Promise<WorkerInfo[]>;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
interface WorkerDeployment {
|
|
451
|
+
success: boolean;
|
|
452
|
+
url: string;
|
|
453
|
+
errors: any[];
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
interface WorkerExecOptions extends RequestInit {
|
|
457
|
+
method?: string;
|
|
458
|
+
headers?: object;
|
|
459
|
+
body?: string | object;
|
|
460
|
+
cache?: RequestCache;
|
|
461
|
+
credentials?: RequestCredentials;
|
|
462
|
+
mode?: RequestMode;
|
|
463
|
+
redirect?: RequestRedirect;
|
|
464
|
+
referrer?: string;
|
|
465
|
+
signal?: AbortSignal;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
interface WorkerInfo {
|
|
469
|
+
name: string;
|
|
470
|
+
url: string;
|
|
471
|
+
file_path: string;
|
|
472
|
+
file_uid: string;
|
|
473
|
+
created_at: string;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Global puter instance
|
|
477
|
+
declare const puter: Puter;
|
|
478
|
+
|
|
479
|
+
// Export the Puter class as both default and named export
|
|
480
|
+
export default puter;
|
|
481
|
+
export { puter };
|
|
482
|
+
|
|
483
|
+
// Also export all the interfaces for users who want to use them
|
|
484
|
+
export {
|
|
485
|
+
AI, AlertButton, App, AppConnection, Apps,
|
|
486
|
+
Auth, ChatMessage, ChatOptions, ChatResponse, ContentObject, ContextMenuItem, ContextMenuOptions, CopyOptions, CreateAppOptions, DeleteOptions, Drivers, FilePickerOptions, FileSystem, FSItem, GetAppOptions, Hosting,
|
|
487
|
+
KV,
|
|
488
|
+
KVPair, LaunchAppOptions, MenubarOptions,
|
|
489
|
+
MenuItem, MkdirOptions,
|
|
490
|
+
MoveOptions, Networking,
|
|
491
|
+
Permissions, Puter, ReaddirOptions, ReadOptions, SpaceInfo, StatsPeriod, Subdomain, ThemeData, ToolCall, ToolDefinition, Txt2ImgOptions,
|
|
492
|
+
Txt2SpeechOptions, UI, UpdateAppAttributes, User, WindowOptions, WorkerDeployment,
|
|
493
|
+
WorkerExecOptions,
|
|
494
|
+
WorkerInfo, Workers, WriteOptions
|
|
495
|
+
};
|
|
496
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyputer/puter.js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Puter.js - A JavaScript library for interacting with Puter services.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/puter.js",
|
|
11
|
-
"src/"
|
|
11
|
+
"src/",
|
|
12
|
+
"index.d.ts"
|
|
12
13
|
],
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import io from '../../lib/socket.io/socket.io.esm.min.js';
|
|
2
2
|
|
|
3
3
|
// Operations
|
|
4
|
-
import
|
|
5
|
-
import mkdir from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import upload from "./operations/upload.js";
|
|
9
|
-
import read from "./operations/read.js";
|
|
10
|
-
import move from "./operations/move.js";
|
|
11
|
-
import write from "./operations/write.js";
|
|
12
|
-
import sign from "./operations/sign.js";
|
|
13
|
-
import symlink from './operations/symlink.js';
|
|
4
|
+
import copy from './operations/copy.js';
|
|
5
|
+
import mkdir from './operations/mkdir.js';
|
|
6
|
+
import move from './operations/move.js';
|
|
7
|
+
import read from './operations/read.js';
|
|
14
8
|
import readdir from './operations/readdir.js';
|
|
9
|
+
import rename from './operations/rename.js';
|
|
10
|
+
import sign from './operations/sign.js';
|
|
11
|
+
import space from './operations/space.js';
|
|
15
12
|
import stat from './operations/stat.js';
|
|
16
|
-
|
|
13
|
+
import symlink from './operations/symlink.js';
|
|
14
|
+
import upload from './operations/upload.js';
|
|
15
|
+
import write from './operations/write.js';
|
|
16
|
+
// Why is this called deleteFSEntry instead of just delete? because delete is
|
|
17
17
|
// a reserved keyword in javascript
|
|
18
|
-
import deleteFSEntry from "./operations/deleteFSEntry.js";
|
|
19
18
|
import { AdvancedBase } from '../../../../putility/index.js';
|
|
20
19
|
import FSItem from '../FSItem.js';
|
|
20
|
+
import deleteFSEntry from './operations/deleteFSEntry.js';
|
|
21
21
|
import getReadURL from './operations/getReadUrl.js';
|
|
22
22
|
|
|
23
23
|
export class PuterJSFileSystemModule extends AdvancedBase {
|
|
@@ -39,7 +39,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
39
39
|
readdir = readdir;
|
|
40
40
|
stat = stat;
|
|
41
41
|
|
|
42
|
-
FSItem = FSItem
|
|
42
|
+
FSItem = FSItem;
|
|
43
43
|
|
|
44
44
|
static NARI_METHODS = {
|
|
45
45
|
// stat: {
|
|
@@ -50,7 +50,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
50
50
|
// return svc_fs.filesystem.stat(parameters);
|
|
51
51
|
// }
|
|
52
52
|
// },
|
|
53
|
-
}
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Creates a new instance with the given authentication token, API origin, and app ID,
|
|
@@ -61,7 +61,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
61
61
|
* @param {string} APIOrigin - Origin of the API server. Used to build the API endpoint URLs.
|
|
62
62
|
* @param {string} appID - ID of the app to use.
|
|
63
63
|
*/
|
|
64
|
-
constructor
|
|
64
|
+
constructor(context) {
|
|
65
65
|
super();
|
|
66
66
|
this.authToken = context.authToken;
|
|
67
67
|
this.APIOrigin = context.APIOrigin;
|
|
@@ -81,7 +81,6 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
84
|
/**
|
|
86
85
|
* Initializes the socket connection to the server using the current API origin.
|
|
87
86
|
* If a socket connection already exists, it disconnects it before creating a new one.
|
|
@@ -92,17 +91,21 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
92
91
|
* @returns {void}
|
|
93
92
|
*/
|
|
94
93
|
initializeSocket() {
|
|
95
|
-
if (
|
|
94
|
+
if ( globalThis.puter.env === 'nodejs' ){
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if ( this.socket ) {
|
|
96
98
|
this.socket.disconnect();
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
this.socket = io(this.APIOrigin, {
|
|
100
102
|
auth: {
|
|
101
103
|
auth_token: this.authToken,
|
|
102
|
-
}
|
|
104
|
+
},
|
|
103
105
|
});
|
|
104
106
|
|
|
105
107
|
this.bindSocketEvents();
|
|
108
|
+
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
bindSocketEvents() {
|
|
@@ -117,16 +120,20 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
117
120
|
this.socket.on('item.moved', (item) => {
|
|
118
121
|
// todo: NAIVE PURGE
|
|
119
122
|
puter._cache.flushall();
|
|
120
|
-
});
|
|
123
|
+
});
|
|
121
124
|
|
|
122
125
|
this.socket.on('connect', () => {
|
|
123
|
-
if(puter.debugMode)
|
|
126
|
+
if ( puter.debugMode )
|
|
127
|
+
{
|
|
124
128
|
console.log('FileSystem Socket: Connected', this.socket.id);
|
|
129
|
+
}
|
|
125
130
|
});
|
|
126
131
|
|
|
127
132
|
this.socket.on('disconnect', () => {
|
|
128
|
-
if(puter.debugMode)
|
|
133
|
+
if ( puter.debugMode )
|
|
134
|
+
{
|
|
129
135
|
console.log('FileSystem Socket: Disconnected');
|
|
136
|
+
}
|
|
130
137
|
|
|
131
138
|
// todo: NAIVE PURGE
|
|
132
139
|
// purge cache on disconnect since we may have become out of sync
|
|
@@ -134,28 +141,38 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
134
141
|
});
|
|
135
142
|
|
|
136
143
|
this.socket.on('reconnect', (attempt) => {
|
|
137
|
-
if(puter.debugMode)
|
|
144
|
+
if ( puter.debugMode )
|
|
145
|
+
{
|
|
138
146
|
console.log('FileSystem Socket: Reconnected', this.socket.id);
|
|
147
|
+
}
|
|
139
148
|
});
|
|
140
149
|
|
|
141
150
|
this.socket.on('reconnect_attempt', (attempt) => {
|
|
142
|
-
if(puter.debugMode)
|
|
151
|
+
if ( puter.debugMode )
|
|
152
|
+
{
|
|
143
153
|
console.log('FileSystem Socket: Reconnection Attemps', attempt);
|
|
154
|
+
}
|
|
144
155
|
});
|
|
145
156
|
|
|
146
157
|
this.socket.on('reconnect_error', (error) => {
|
|
147
|
-
if(puter.debugMode)
|
|
158
|
+
if ( puter.debugMode )
|
|
159
|
+
{
|
|
148
160
|
console.log('FileSystem Socket: Reconnection Error', error);
|
|
161
|
+
}
|
|
149
162
|
});
|
|
150
163
|
|
|
151
164
|
this.socket.on('reconnect_failed', () => {
|
|
152
|
-
if(puter.debugMode)
|
|
165
|
+
if ( puter.debugMode )
|
|
166
|
+
{
|
|
153
167
|
console.log('FileSystem Socket: Reconnection Failed');
|
|
168
|
+
}
|
|
154
169
|
});
|
|
155
170
|
|
|
156
171
|
this.socket.on('error', (error) => {
|
|
157
|
-
if(puter.debugMode)
|
|
172
|
+
if ( puter.debugMode )
|
|
173
|
+
{
|
|
158
174
|
console.error('FileSystem Socket Error:', error);
|
|
175
|
+
}
|
|
159
176
|
});
|
|
160
177
|
}
|
|
161
178
|
|
|
@@ -166,7 +183,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
166
183
|
* @memberof [FileSystem]
|
|
167
184
|
* @returns {void}
|
|
168
185
|
*/
|
|
169
|
-
setAuthToken
|
|
186
|
+
setAuthToken(authToken) {
|
|
170
187
|
this.authToken = authToken;
|
|
171
188
|
// reset socket
|
|
172
189
|
this.initializeSocket();
|
|
@@ -174,12 +191,12 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
|
|
174
191
|
|
|
175
192
|
/**
|
|
176
193
|
* Sets the API origin and resets the socket connection with the updated API origin.
|
|
177
|
-
*
|
|
194
|
+
*
|
|
178
195
|
* @param {string} APIOrigin - The new API origin.
|
|
179
196
|
* @memberof [Apps]
|
|
180
197
|
* @returns {void}
|
|
181
198
|
*/
|
|
182
|
-
setAPIOrigin
|
|
199
|
+
setAPIOrigin(APIOrigin) {
|
|
183
200
|
this.APIOrigin = APIOrigin;
|
|
184
201
|
// reset socket
|
|
185
202
|
this.initializeSocket();
|