@heyputer/puter.js 2.1.2 → 2.1.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/index.d.ts CHANGED
@@ -9,7 +9,7 @@ declare global {
9
9
  declare class Puter {
10
10
  // Properties
11
11
  appID: string;
12
- env: 'app' | 'web' | 'gui';
12
+ env: 'app' | 'web' | 'gui' | 'nodejs' | 'service-worker';
13
13
 
14
14
  // Utility methods
15
15
  print(text: string, options?: { code?: boolean }): void;
@@ -47,15 +47,27 @@ interface AI {
47
47
  chat(messages: ChatMessage[], testMode?: boolean, options?: NonStreamingChatOptions): Promise<ChatResponse>;
48
48
 
49
49
  img2txt(image: string | File | Blob, testMode?: boolean): Promise<string>;
50
+ img2txt(image: string | File | Blob, options?: Img2TxtOptions): Promise<string>;
51
+ img2txt(image: string | File | Blob, testMode?: boolean, options?: Img2TxtOptions): Promise<string>;
52
+ img2txt(options: Img2TxtOptions): Promise<string>;
50
53
 
51
54
  txt2img(prompt: string, testMode?: boolean): Promise<HTMLImageElement>;
52
55
  txt2img(prompt: string, options?: Txt2ImgOptions): Promise<HTMLImageElement>;
53
56
 
57
+ txt2vid(prompt: string, testMode?: boolean): Promise<HTMLVideoElement>;
58
+ txt2vid(prompt: string, options?: Txt2VidOptions): Promise<HTMLVideoElement>;
59
+
54
60
  txt2speech(text: string): Promise<HTMLAudioElement>;
55
61
  txt2speech(text: string, options?: Txt2SpeechOptions): Promise<HTMLAudioElement>;
56
62
  txt2speech(text: string, language?: string): Promise<HTMLAudioElement>;
57
63
  txt2speech(text: string, language?: string, voice?: string): Promise<HTMLAudioElement>;
58
64
  txt2speech(text: string, language?: string, voice?: string, engine?: string): Promise<HTMLAudioElement>;
65
+
66
+ speech2txt(source: string | File | Blob): Promise<string | Speech2TxtResult>;
67
+ speech2txt(source: string | File | Blob, options?: Speech2TxtOptions): Promise<string | Speech2TxtResult>;
68
+ speech2txt(options: Speech2TxtOptions): Promise<string | Speech2TxtResult>;
69
+ speech2txt(source: string | File | Blob, testMode?: boolean): Promise<string | Speech2TxtResult>;
70
+ speech2txt(source: Speech2TxtOptions, testMode?: boolean): Promise<string | Speech2TxtResult>;
59
71
  }
60
72
 
61
73
  type StreamingChatOptions = Omit<ChatOptions, "stream"> & { stream: true };
@@ -66,6 +78,16 @@ interface ChatOptions {
66
78
  stream?: boolean;
67
79
  max_tokens?: number;
68
80
  temperature?: number;
81
+ reasoning?: {
82
+ effort?: 'none' | 'low' | 'medium' | 'high' | 'minimal';
83
+ [key: string]: unknown;
84
+ };
85
+ reasoning_effort?: 'none' | 'low' | 'medium' | 'high' | 'minimal';
86
+ text?: {
87
+ verbosity?: 'low' | 'medium' | 'high';
88
+ [key: string]: unknown;
89
+ };
90
+ verbosity?: 'low' | 'medium' | 'high';
69
91
  tools?: ToolDefinition[];
70
92
  }
71
93
 
@@ -108,16 +130,83 @@ interface ToolCall {
108
130
  }
109
131
 
110
132
  interface Txt2ImgOptions {
111
- model?: 'gpt-image-1' | 'gemini-2.5-flash-image-preview' | 'dall-e-3';
133
+ model?: 'gpt-image-1' | 'gpt-image-1-mini' | 'gemini-2.5-flash-image-preview' | 'dall-e-3';
112
134
  quality?: 'high' | 'medium' | 'low' | 'hd' | 'standard';
113
135
  input_image?: string;
114
136
  input_image_mime_type?: string;
115
137
  }
116
138
 
139
+ interface Txt2VidOptions {
140
+ prompt?: string;
141
+ model?: string;
142
+ duration?: number;
143
+ seconds?: number;
144
+ size?: string;
145
+ resolution?: string;
146
+ width?: number;
147
+ height?: number;
148
+ fps?: number;
149
+ steps?: number;
150
+ guidance_scale?: number;
151
+ seed?: number;
152
+ output_format?: string;
153
+ output_quality?: number;
154
+ negative_prompt?: string;
155
+ reference_images?: string[];
156
+ frame_images?: Array<Record<string, unknown>>;
157
+ metadata?: Record<string, unknown>;
158
+ provider?: string;
159
+ service?: string;
160
+ driver?: string;
161
+ test_mode?: boolean;
162
+ }
163
+
164
+ interface Img2TxtOptions {
165
+ source?: string | File | Blob;
166
+ provider?: 'aws-textract' | 'mistral';
167
+ model?: string;
168
+ pages?: number[];
169
+ includeImageBase64?: boolean;
170
+ imageLimit?: number;
171
+ imageMinSize?: number;
172
+ bboxAnnotationFormat?: Record<string, unknown>;
173
+ documentAnnotationFormat?: Record<string, unknown>;
174
+ testMode?: boolean;
175
+ }
176
+
117
177
  interface Txt2SpeechOptions {
118
178
  language?: string;
119
179
  voice?: string;
120
- engine?: 'standard' | 'neural' | 'generative';
180
+ engine?: 'standard' | 'neural' | 'long-form' | 'generative' | string;
181
+ provider?: 'aws-polly' | 'openai' | string;
182
+ model?: 'gpt-4o-mini-tts' | 'tts-1' | 'tts-1-hd' | string;
183
+ response_format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm' | string;
184
+ instructions?: string;
185
+ }
186
+
187
+ interface Speech2TxtOptions {
188
+ file?: string | File | Blob;
189
+ audio?: string | File | Blob;
190
+ model?: 'gpt-4o-mini-transcribe' | 'gpt-4o-transcribe' | 'gpt-4o-transcribe-diarize' | 'whisper-1' | string;
191
+ response_format?: 'json' | 'text' | 'diarized_json' | 'srt' | 'verbose_json' | 'vtt' | string;
192
+ language?: string;
193
+ prompt?: string;
194
+ temperature?: number;
195
+ logprobs?: boolean;
196
+ timestamp_granularities?: string[];
197
+ translate?: boolean;
198
+ stream?: boolean;
199
+ chunking_strategy?: string;
200
+ known_speaker_names?: string[];
201
+ known_speaker_references?: string[];
202
+ extra_body?: Record<string, unknown>;
203
+ }
204
+
205
+ interface Speech2TxtResult {
206
+ text?: string;
207
+ language?: string;
208
+ segments?: Array<Record<string, unknown>>;
209
+ [key: string]: any;
121
210
  }
122
211
 
123
212
  interface ChatResponseChunk {
@@ -146,6 +235,7 @@ interface CreateAppOptions {
146
235
  icon?: string;
147
236
  maximizeOnStart?: boolean;
148
237
  filetypeAssociations?: string[];
238
+ dedupeName?: boolean;
149
239
  }
150
240
 
151
241
  interface GetAppOptions {
@@ -188,6 +278,8 @@ interface Auth {
188
278
  signOut(): void;
189
279
  isSignedIn(): boolean;
190
280
  getUser(): Promise<User>;
281
+ getMonthlyUsage(): Promise<MonthlyUsage>;
282
+ getDetailedAppUsage(appId: string): Promise<DetailedAppUsage>;
191
283
  }
192
284
 
193
285
  interface User {
@@ -196,6 +288,33 @@ interface User {
196
288
  email_confirmed: boolean;
197
289
  }
198
290
 
291
+ interface AllowanceInfo {
292
+ monthUsageAllowance: number;
293
+ remaining: number;
294
+ }
295
+
296
+ interface AppUsage {
297
+ count: number;
298
+ total: number;
299
+ }
300
+
301
+ interface APIUsage {
302
+ cost: number;
303
+ count: number;
304
+ units: number;
305
+ }
306
+
307
+ interface MonthlyUsage {
308
+ allowanceInfo: AllowanceInfo;
309
+ appTotals: Record<string, AppUsage>;
310
+ usage: Record<string, APIUsage>;
311
+ }
312
+
313
+ interface DetailedAppUsage {
314
+ total: number;
315
+ [key: string]: APIUsage;
316
+ }
317
+
199
318
  // Drivers Module
200
319
  interface Drivers {
201
320
  call(interface: string, driver: string, method: string, args?: object): Promise<any>;
@@ -214,7 +333,7 @@ interface FileSystem {
214
333
  rename(path: string, newName: string): Promise<FSItem>;
215
334
  space(): Promise<SpaceInfo>;
216
335
  stat(path: string): Promise<FSItem>;
217
- upload(items: FileList | File[] | Blob[], dirPath?: string, options?: object): Promise<FSItem[]>;
336
+ upload(items: FileList | File[] | Blob[], dirPath?: string, options?: UploadOptions): Promise<FSItem[]>;
218
337
  write(path: string, data?: string | File | Blob, options?: WriteOptions): Promise<FSItem>;
219
338
  }
220
339
 
@@ -255,6 +374,12 @@ interface WriteOptions {
255
374
  createMissingParents?: boolean;
256
375
  }
257
376
 
377
+ interface UploadOptions {
378
+ overwrite?: boolean;
379
+ dedupeName?: boolean;
380
+ name?: string;
381
+ }
382
+
258
383
  interface SpaceInfo {
259
384
  capacity: number;
260
385
  used: number;
@@ -511,4 +636,3 @@ export {
511
636
  WorkerExecOptions,
512
637
  WorkerInfo, Workers, WriteOptions
513
638
  };
514
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyputer/puter.js",
3
- "version": "2.1.2",
3
+ "version": "2.1.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",
package/src/index.js CHANGED
@@ -785,6 +785,43 @@ export const puter = puterInit();
785
785
  export default puter;
786
786
  globalThis.puter = puter;
787
787
 
788
+ puter.tools = [];
789
+ /**
790
+ * @type {{messageTarget: Window}}
791
+ */
792
+ const puterParent = puter.ui.parentApp();
793
+ globalThis.puterParent = puterParent;
794
+ if (puterParent) {
795
+ console.log("I have a parent, registering tools")
796
+ puterParent.on('message', async (event) => {
797
+ console.log("Got tool req ", event)
798
+ if (event.$ === "requestTools") {
799
+ console.log("Responding with tools")
800
+ puterParent.postMessage({
801
+ $: "providedTools",
802
+ tools: JSON.parse(JSON.stringify(puter.tools))
803
+ });
804
+ }
805
+
806
+ if (event.$ === "executeTool") {
807
+ console.log("xecuting tools")
808
+ /**
809
+ * Puter tools format
810
+ * @type {[{exec: Function, function: {description: string, name: string, parameters: {properties: any, required: Array<string>}, type: string}}]}
811
+ */
812
+ const [tool] = puter.tools.filter(e=>e.function.name === event.toolName);
813
+
814
+ const response = await tool.exec(event.parameters);
815
+ puterParent.postMessage({
816
+ $: "toolResponse",
817
+ response,
818
+ tag: event.tag,
819
+ });
820
+ }
821
+ });
822
+ puterParent.postMessage({$: "ready"});
823
+ }
824
+
788
825
  globalThis.addEventListener && globalThis.addEventListener('message', async (event) => {
789
826
  // if the message is not from Puter, then ignore it
790
827
  if ( event.origin !== puter.defaultGUIOrigin ) return;