@heyputer/puter.js 2.1.7 → 2.1.9
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.cjs +1 -1
- package/index.d.ts +102 -624
- package/package.json +4 -3
- package/types/modules/ai.d.ts +124 -0
- package/types/modules/apps.d.ts +62 -0
- package/types/modules/auth.d.ts +48 -0
- package/types/modules/debug.d.ts +3 -0
- package/types/modules/drivers.d.ts +21 -0
- package/types/modules/filesystem.d.ts +104 -0
- package/types/modules/fs-item.d.ts +57 -0
- package/types/modules/hosting.d.ts +23 -0
- package/types/modules/kv.d.ts +34 -0
- package/types/modules/networking.d.ts +33 -0
- package/types/modules/os.d.ts +12 -0
- package/types/modules/perms.d.ts +23 -0
- package/types/modules/threads.d.ts +27 -0
- package/types/modules/ui.d.ts +146 -0
- package/types/modules/util.d.ts +12 -0
- package/types/modules/workers.d.ts +26 -0
- package/types/puter.d.ts +101 -0
- package/types/shared.d.ts +39 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { RequestCallbacks } from '../shared.d.ts';
|
|
2
|
+
import type { FSItem } from './fs-item.d.ts';
|
|
3
|
+
|
|
4
|
+
export interface AlertButton {
|
|
5
|
+
label: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
type?: 'primary' | 'success' | 'info' | 'warning' | 'danger';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ContextMenuItem {
|
|
11
|
+
label: string;
|
|
12
|
+
action?: () => void;
|
|
13
|
+
icon?: string;
|
|
14
|
+
icon_active?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
items?: (ContextMenuItem | '-')[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ContextMenuOptions {
|
|
20
|
+
items: (ContextMenuItem | '-')[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface WindowOptions {
|
|
24
|
+
center?: boolean;
|
|
25
|
+
content?: string;
|
|
26
|
+
disable_parent_window?: boolean;
|
|
27
|
+
has_head?: boolean;
|
|
28
|
+
height?: number;
|
|
29
|
+
is_resizable?: boolean;
|
|
30
|
+
show_in_taskbar?: boolean;
|
|
31
|
+
title?: string;
|
|
32
|
+
width?: number;
|
|
33
|
+
x?: number;
|
|
34
|
+
y?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface LaunchAppOptions {
|
|
38
|
+
name?: string;
|
|
39
|
+
args?: Record<string, unknown>;
|
|
40
|
+
appInstanceID?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ThemeData {
|
|
44
|
+
palette: {
|
|
45
|
+
primaryHue: number;
|
|
46
|
+
primarySaturation: string;
|
|
47
|
+
primaryLightness: string;
|
|
48
|
+
primaryAlpha: number;
|
|
49
|
+
primaryColor: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface MenubarOptions {
|
|
54
|
+
items: MenuItem[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface MenuItem {
|
|
58
|
+
label: string;
|
|
59
|
+
action?: () => void;
|
|
60
|
+
items?: MenuItem[];
|
|
61
|
+
icon?: string;
|
|
62
|
+
checked?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface FilePickerOptions {
|
|
66
|
+
multiple?: boolean;
|
|
67
|
+
accept?: string | string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface DirectoryPickerOptions {
|
|
71
|
+
multiple?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface AppConnectionCloseEvent {
|
|
75
|
+
appInstanceID: string;
|
|
76
|
+
statusCode?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type CancelAwarePromise<T> = Promise<T> & { undefinedOnCancel?: Promise<T | undefined> };
|
|
80
|
+
|
|
81
|
+
export class AppConnection {
|
|
82
|
+
readonly usesSDK: boolean;
|
|
83
|
+
readonly response?: Record<string, unknown>;
|
|
84
|
+
|
|
85
|
+
on (eventName: 'message', handler: (message: unknown) => void): void;
|
|
86
|
+
on (eventName: 'close', handler: (data: AppConnectionCloseEvent) => void): void;
|
|
87
|
+
off (eventName: string, handler: (...args: unknown[]) => void): void;
|
|
88
|
+
postMessage (message: unknown): void;
|
|
89
|
+
close (): void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class UI {
|
|
93
|
+
constructor (context: Record<string, unknown>, parameters: { appInstanceID?: string; parentInstanceID?: string });
|
|
94
|
+
|
|
95
|
+
alert (message?: string, buttons?: AlertButton[]): Promise<string>;
|
|
96
|
+
prompt (message?: string, defaultValue?: string): Promise<string | null>;
|
|
97
|
+
authenticateWithPuter (): Promise<unknown>;
|
|
98
|
+
contextMenu (options: ContextMenuOptions): void;
|
|
99
|
+
createWindow (options?: WindowOptions): void;
|
|
100
|
+
exit (statusCode?: number): void;
|
|
101
|
+
getLanguage (): Promise<string>;
|
|
102
|
+
hideSpinner (): void;
|
|
103
|
+
showSpinner (): void;
|
|
104
|
+
showColorPicker (defaultColor?: string | Record<string, unknown>): Promise<string>;
|
|
105
|
+
showDirectoryPicker (options?: DirectoryPickerOptions): Promise<FSItem | FSItem[]>;
|
|
106
|
+
showFontPicker (defaultFont?: string | Record<string, unknown>): Promise<{ fontFamily: string }>;
|
|
107
|
+
showOpenFilePicker (options?: FilePickerOptions): CancelAwarePromise<FSItem | FSItem[]>;
|
|
108
|
+
showSaveFilePicker (data?: unknown, defaultFileName?: string): CancelAwarePromise<FSItem>;
|
|
109
|
+
socialShare (url: string, message?: string, options?: { left?: number; top?: number }): void;
|
|
110
|
+
setMenubar (options: MenubarOptions): void;
|
|
111
|
+
setMenuItemIcon (itemId: string, icon: string): void;
|
|
112
|
+
setMenuItemIconActive (itemId: string, icon: string): void;
|
|
113
|
+
setMenuItemChecked (itemId: string, checked: boolean): void;
|
|
114
|
+
setWindowHeight (height: number): void;
|
|
115
|
+
setWindowPosition (x: number, y: number): void;
|
|
116
|
+
setWindowSize (width: number, height: number): void;
|
|
117
|
+
setWindowTitle (title: string): void;
|
|
118
|
+
setWindowWidth (width: number): void;
|
|
119
|
+
setWindowX (x: number): void;
|
|
120
|
+
setWindowY (y: number): void;
|
|
121
|
+
showColorPicker (options?: Record<string, unknown>): Promise<string>;
|
|
122
|
+
showSaveFilePicker (data?: unknown, defaultFileName?: string): Promise<FSItem>;
|
|
123
|
+
wasLaunchedWithItems (): boolean;
|
|
124
|
+
onItemsOpened (handler: (items: FSItem[]) => void): void;
|
|
125
|
+
onLaunchedWithItems (handler: (items: FSItem[]) => void): void;
|
|
126
|
+
onWindowClose (handler: () => void): void;
|
|
127
|
+
on (eventName: 'localeChanged', handler: (data: { language: string }) => void): void;
|
|
128
|
+
on (eventName: 'themeChanged', handler: (data: ThemeData) => void): void;
|
|
129
|
+
parentApp (): AppConnection | null;
|
|
130
|
+
launchApp (appName?: string, args?: Record<string, unknown>): Promise<AppConnection>;
|
|
131
|
+
launchApp (options: LaunchAppOptions): Promise<AppConnection>;
|
|
132
|
+
|
|
133
|
+
getEntriesFromDataTransferItems (dataTransferItems: DataTransferItemList, options?: { raw?: boolean }): Promise<Array<File | FileSystemEntry>>;
|
|
134
|
+
|
|
135
|
+
// Broadcast helpers are only partially typed because the payloads are app-defined.
|
|
136
|
+
broadcast (name: string, data: unknown): void;
|
|
137
|
+
listenForBroadcast (name: string, handler: (data: unknown) => void): void;
|
|
138
|
+
|
|
139
|
+
get FILE_SAVE_CANCELLED (): symbol;
|
|
140
|
+
get FILE_OPEN_CANCELLED (): symbol;
|
|
141
|
+
|
|
142
|
+
requestUpgrade (): Promise<unknown>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// NOTE: UI contains additional internal helpers that are not surfaced here because they are not
|
|
146
|
+
// part of the stable app-facing API.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class UtilRPC {
|
|
2
|
+
callbackManager: unknown;
|
|
3
|
+
getDehydrator (): { dehydrate(value: unknown): unknown };
|
|
4
|
+
getHydrator (config: { target: Window | Worker | MessagePort }): { hydrate(value: unknown): unknown };
|
|
5
|
+
registerCallback (resolve: (value: unknown) => void): string;
|
|
6
|
+
send (target: Window | Worker | MessagePort, id: string, ...args: unknown[]): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default class Util {
|
|
10
|
+
constructor ();
|
|
11
|
+
rpc: UtilRPC;
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface WorkerInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
url: string;
|
|
4
|
+
file_path?: string;
|
|
5
|
+
file_uid?: string;
|
|
6
|
+
created_at?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface WorkerDeployment {
|
|
11
|
+
success: boolean;
|
|
12
|
+
url: string;
|
|
13
|
+
errors?: unknown[];
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class WorkersHandler {
|
|
18
|
+
constructor (authToken?: string);
|
|
19
|
+
|
|
20
|
+
create (workerName: string, filePath: string, appName?: string): Promise<WorkerDeployment>;
|
|
21
|
+
delete (workerName: string): Promise<boolean>;
|
|
22
|
+
exec (request: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
23
|
+
get (workerName: string): Promise<WorkerInfo>;
|
|
24
|
+
list (): Promise<WorkerInfo[]>;
|
|
25
|
+
getLoggingHandle (workerName: string): Promise<EventTarget & { close: () => void }>;
|
|
26
|
+
}
|
package/types/puter.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { AI } from './modules/ai.d.ts';
|
|
2
|
+
import type { Apps } from './modules/apps.d.ts';
|
|
3
|
+
import type { Auth } from './modules/auth.d.ts';
|
|
4
|
+
import type { Debug } from './modules/debug.d.ts';
|
|
5
|
+
import type { Drivers } from './modules/drivers.d.ts';
|
|
6
|
+
import type { PuterJSFileSystemModule, SpaceInfo } from './modules/filesystem.d.ts';
|
|
7
|
+
import type { FSItem } from './modules/fs-item.d.ts';
|
|
8
|
+
import type { Hosting } from './modules/hosting.d.ts';
|
|
9
|
+
import type { KV } from './modules/kv.d.ts';
|
|
10
|
+
import type { Networking } from './modules/networking.d.ts';
|
|
11
|
+
import type { OS } from './modules/os.d.ts';
|
|
12
|
+
import type { Perms } from './modules/perms.d.ts';
|
|
13
|
+
import type Threads from './modules/threads.d.ts';
|
|
14
|
+
import type { UI } from './modules/ui.d.ts';
|
|
15
|
+
import type Util from './modules/util.d.ts';
|
|
16
|
+
import type { WorkersHandler } from './modules/workers.d.ts';
|
|
17
|
+
import type { APICallLogger, APILoggingConfig, PuterEnvironment, ToolSchema } from './shared.d.ts';
|
|
18
|
+
|
|
19
|
+
export interface NetAPI extends Networking {}
|
|
20
|
+
|
|
21
|
+
export interface PuterArgs {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PuterUser extends Record<string, unknown> {
|
|
26
|
+
username?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class Puter {
|
|
30
|
+
env: PuterEnvironment;
|
|
31
|
+
appID?: string;
|
|
32
|
+
appName?: string;
|
|
33
|
+
appDataPath?: string;
|
|
34
|
+
appInstanceID?: string;
|
|
35
|
+
parentInstanceID?: string;
|
|
36
|
+
args: PuterArgs;
|
|
37
|
+
onAuth?: (user: PuterUser) => void;
|
|
38
|
+
authToken?: string | null;
|
|
39
|
+
APIOrigin: string;
|
|
40
|
+
logger: unknown;
|
|
41
|
+
apiCallLogger?: APICallLogger;
|
|
42
|
+
puterAuthState: {
|
|
43
|
+
isPromptOpen: boolean;
|
|
44
|
+
authGranted: boolean | null;
|
|
45
|
+
resolver: { resolve: () => void; reject: (reason?: unknown) => void } | null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Core modules
|
|
49
|
+
util: Util;
|
|
50
|
+
ai: AI;
|
|
51
|
+
apps: Apps;
|
|
52
|
+
auth: Auth;
|
|
53
|
+
os: OS;
|
|
54
|
+
fs: PuterJSFileSystemModule;
|
|
55
|
+
ui: UI;
|
|
56
|
+
hosting: Hosting;
|
|
57
|
+
kv: KV;
|
|
58
|
+
threads: Threads;
|
|
59
|
+
perms: Perms;
|
|
60
|
+
drivers: Drivers;
|
|
61
|
+
debug: Debug;
|
|
62
|
+
path: {
|
|
63
|
+
join: (...parts: string[]) => string;
|
|
64
|
+
dirname: (p: string) => string;
|
|
65
|
+
basename: (p: string) => string;
|
|
66
|
+
normalize?: (p: string) => string;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
net: NetAPI;
|
|
71
|
+
workers: WorkersHandler;
|
|
72
|
+
|
|
73
|
+
static FSItem: typeof FSItem;
|
|
74
|
+
|
|
75
|
+
constructor();
|
|
76
|
+
|
|
77
|
+
setAuthToken(authToken: string): void;
|
|
78
|
+
resetAuthToken(): void;
|
|
79
|
+
setAPIOrigin(APIOrigin: string): void;
|
|
80
|
+
setAppID(appID: string): void;
|
|
81
|
+
|
|
82
|
+
get defaultAPIOrigin(): string;
|
|
83
|
+
set defaultAPIOrigin(value: string);
|
|
84
|
+
get defaultGUIOrigin(): string;
|
|
85
|
+
set defaultGUIOrigin(value: string);
|
|
86
|
+
|
|
87
|
+
print(text: string, options?: { code?: boolean; escapeHTML?: boolean }): void;
|
|
88
|
+
randName(separator?: string): string;
|
|
89
|
+
exit(statusCode?: number): void;
|
|
90
|
+
|
|
91
|
+
getUser(options?: { success?: (user: PuterUser) => void; error?: (reason: unknown) => void }): Promise<PuterUser>;
|
|
92
|
+
configureAPILogging(config?: APILoggingConfig): this;
|
|
93
|
+
enableAPILogging(config?: APILoggingConfig): this;
|
|
94
|
+
disableAPILogging(): this;
|
|
95
|
+
|
|
96
|
+
// Utilities for caches and network; exposed but not all internals are typed.
|
|
97
|
+
checkAndUpdateGUIFScache(): void;
|
|
98
|
+
initNetworkMonitoring(): void;
|
|
99
|
+
|
|
100
|
+
tools: ToolSchema[];
|
|
101
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type PuterEnvironment = 'app' | 'gui' | 'web' | 'web-worker' | 'service-worker' | 'nodejs';
|
|
2
|
+
|
|
3
|
+
export interface RequestCallbacks<T = unknown> {
|
|
4
|
+
success?: (value: T) => void;
|
|
5
|
+
error?: (reason: unknown) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface APILoggingConfig {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface APICallLogger {
|
|
14
|
+
isEnabled(): boolean;
|
|
15
|
+
logRequest(entry: Record<string, unknown>): void;
|
|
16
|
+
updateConfig(config: APILoggingConfig): void;
|
|
17
|
+
disable(): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PaginationOptions {
|
|
21
|
+
page?: number;
|
|
22
|
+
per_page?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PaginatedResult<T> {
|
|
26
|
+
data: T[];
|
|
27
|
+
page?: number;
|
|
28
|
+
pages?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ToolSchema {
|
|
32
|
+
function: {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
parameters: Record<string, unknown>;
|
|
36
|
+
strict?: boolean;
|
|
37
|
+
};
|
|
38
|
+
exec: (parameters: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
39
|
+
}
|