@heyputer/puter.js 1.0.1 → 2.0.1
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 +14 -43
- package/index.d.ts +479 -0
- package/package.json +13 -3
- package/APACHE_LICENSE.txt +0 -201
- package/doc/devlog.md +0 -49
- package/src/bg.png +0 -0
- package/src/bg.webp +0 -0
- package/src/lib/APICallLogger.js +0 -110
- package/src/lib/EventListener.js +0 -51
- package/src/lib/RequestError.js +0 -6
- package/src/lib/filesystem/APIFS.js +0 -73
- package/src/lib/filesystem/CacheFS.js +0 -243
- package/src/lib/filesystem/PostMessageFS.js +0 -40
- package/src/lib/filesystem/definitions.js +0 -39
- package/src/lib/path.js +0 -509
- package/src/lib/polyfills/localStorage.js +0 -92
- package/src/lib/polyfills/xhrshim.js +0 -233
- package/src/lib/socket.io/socket.io.esm.min.js +0 -7
- package/src/lib/socket.io/socket.io.esm.min.js.map +0 -1
- package/src/lib/socket.io/socket.io.js +0 -4385
- package/src/lib/socket.io/socket.io.js.map +0 -1
- package/src/lib/socket.io/socket.io.min.js +0 -7
- package/src/lib/socket.io/socket.io.min.js.map +0 -1
- package/src/lib/socket.io/socket.io.msgpack.min.js +0 -7
- package/src/lib/socket.io/socket.io.msgpack.min.js.map +0 -1
- package/src/lib/utils.js +0 -620
- package/src/lib/xdrpc.js +0 -104
- package/src/modules/AI.js +0 -680
- package/src/modules/Apps.js +0 -215
- package/src/modules/Auth.js +0 -171
- package/src/modules/Debug.js +0 -39
- package/src/modules/Drivers.js +0 -278
- package/src/modules/FSItem.js +0 -139
- package/src/modules/FileSystem/index.js +0 -187
- package/src/modules/FileSystem/operations/copy.js +0 -64
- package/src/modules/FileSystem/operations/deleteFSEntry.js +0 -59
- package/src/modules/FileSystem/operations/getReadUrl.js +0 -42
- package/src/modules/FileSystem/operations/mkdir.js +0 -62
- package/src/modules/FileSystem/operations/move.js +0 -75
- package/src/modules/FileSystem/operations/read.js +0 -46
- package/src/modules/FileSystem/operations/readdir.js +0 -102
- package/src/modules/FileSystem/operations/rename.js +0 -58
- package/src/modules/FileSystem/operations/sign.js +0 -103
- package/src/modules/FileSystem/operations/space.js +0 -40
- package/src/modules/FileSystem/operations/stat.js +0 -95
- package/src/modules/FileSystem/operations/symlink.js +0 -55
- package/src/modules/FileSystem/operations/upload.js +0 -440
- package/src/modules/FileSystem/operations/write.js +0 -65
- package/src/modules/FileSystem/utils/getAbsolutePathForApp.js +0 -21
- package/src/modules/Hosting.js +0 -138
- package/src/modules/KV.js +0 -301
- package/src/modules/OS.js +0 -95
- package/src/modules/Perms.js +0 -109
- package/src/modules/PuterDialog.js +0 -481
- package/src/modules/Threads.js +0 -75
- package/src/modules/UI.js +0 -1555
- package/src/modules/Util.js +0 -38
- package/src/modules/Workers.js +0 -120
- package/src/modules/networking/PSocket.js +0 -87
- package/src/modules/networking/PTLS.js +0 -100
- package/src/modules/networking/PWispHandler.js +0 -89
- package/src/modules/networking/parsers.js +0 -157
- package/src/modules/networking/requests.js +0 -282
- package/src/services/APIAccess.js +0 -46
- package/src/services/FSRelay.js +0 -20
- package/src/services/Filesystem.js +0 -122
- package/src/services/NoPuterYet.js +0 -20
- package/src/services/XDIncoming.js +0 -44
- package/test/ai.test.js +0 -214
- package/test/fs.test.js +0 -798
- package/test/index.html +0 -1183
- package/test/kv.test.js +0 -548
- package/test/txt2speech.test.js +0 -178
- package/webpack.config.js +0 -25
package/test/ai.test.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// TODO: Make these more compatible with eslint
|
|
3
|
-
|
|
4
|
-
// Define models to test
|
|
5
|
-
const TEST_MODELS = [
|
|
6
|
-
"openrouter:openai/gpt-4.1-mini",
|
|
7
|
-
"openrouter:anthropic/claude-3.5-sonnet-20240620",
|
|
8
|
-
"gpt-4o-mini",
|
|
9
|
-
"openai/gpt-4.1-nano",
|
|
10
|
-
"claude-sonnet-4-latest",
|
|
11
|
-
// Add more models as needed
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
// Core test functions that can be reused across models
|
|
15
|
-
const testChatBasicPromptCore = async function(model) {
|
|
16
|
-
// Test basic string prompt with test mode enabled
|
|
17
|
-
const result = await puter.ai.chat("Hello, how are you?", { model: model });
|
|
18
|
-
|
|
19
|
-
// Check that result is an object and not null
|
|
20
|
-
assert(typeof result === 'object', "chat should return an object");
|
|
21
|
-
assert(result !== null, "chat should not return null");
|
|
22
|
-
|
|
23
|
-
// Check response structure
|
|
24
|
-
assert(typeof result.message === 'object', "result should have message object");
|
|
25
|
-
assert(typeof result.finish_reason === 'string', "result should have finish_reason string");
|
|
26
|
-
assert(typeof result.via_ai_chat_service === 'boolean', "result should have via_ai_chat_service boolean");
|
|
27
|
-
|
|
28
|
-
// Check message structure
|
|
29
|
-
assert(typeof result.message.role === 'string', "message should have role string");
|
|
30
|
-
assert(result.message.role === 'assistant', "message role should be 'assistant'");
|
|
31
|
-
assert(typeof result.message.content === 'string' || Array.isArray(result.message.content), "message should have content string or an array");
|
|
32
|
-
|
|
33
|
-
// Check that toString() and valueOf() methods exist and work
|
|
34
|
-
assert(typeof result.toString === 'function', "result should have toString method");
|
|
35
|
-
assert(typeof result.valueOf === 'function', "result should have valueOf method");
|
|
36
|
-
|
|
37
|
-
// Check that toString() and valueOf() return the message content
|
|
38
|
-
assert(result.toString() === result.message.content, "toString() should return message content");
|
|
39
|
-
assert(result.valueOf() === result.message.content, "valueOf() should return message content");
|
|
40
|
-
|
|
41
|
-
// Content should not be empty
|
|
42
|
-
assert(result.message.content.length > 0, "message content should not be empty");
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const testChatWithParametersCore = async function(model) {
|
|
46
|
-
// Test chat with parameters object
|
|
47
|
-
const result = await puter.ai.chat("What is 2+2?", {
|
|
48
|
-
model: model,
|
|
49
|
-
temperature: 0.7,
|
|
50
|
-
max_tokens: 50
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Check basic result structure
|
|
54
|
-
assert(typeof result === 'object', "chat should return an object");
|
|
55
|
-
assert(result !== null, "chat should not return null");
|
|
56
|
-
assert(typeof result.message === 'object', "result should have message object");
|
|
57
|
-
assert(typeof result.message.content === 'string' || Array.isArray(result.message.content), "result.message should have content string or an array");
|
|
58
|
-
|
|
59
|
-
// Check that the methods work
|
|
60
|
-
assert(typeof result.toString === 'function', "result should have toString method");
|
|
61
|
-
assert(typeof result.valueOf === 'function', "result should have valueOf method");
|
|
62
|
-
|
|
63
|
-
// Check that finish_reason is present and valid
|
|
64
|
-
const validFinishReasons = ['stop', 'length', 'function_call', 'content_filter', 'tool_calls'];
|
|
65
|
-
assert(validFinishReasons.includes(result.finish_reason),
|
|
66
|
-
`finish_reason should be one of: ${validFinishReasons.join(', ')}`);
|
|
67
|
-
|
|
68
|
-
// Check that via_ai_chat_service is true
|
|
69
|
-
assert(result.via_ai_chat_service === true, "via_ai_chat_service should be true");
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const testChatWithMessageArrayCore = async function(model) {
|
|
73
|
-
// Test chat with message array format
|
|
74
|
-
const messages = [
|
|
75
|
-
{ role: "system", content: "You are a helpful assistant." },
|
|
76
|
-
{ role: "user", content: "Hello!" }
|
|
77
|
-
];
|
|
78
|
-
const result = await puter.ai.chat(messages, { model: model });
|
|
79
|
-
|
|
80
|
-
// Check basic structure
|
|
81
|
-
assert(typeof result === 'object', "chat should return an object");
|
|
82
|
-
assert(typeof result.message === 'object', "result should have message object");
|
|
83
|
-
assert(result.message.role === 'assistant', "response should be from assistant");
|
|
84
|
-
|
|
85
|
-
// Check that content is present and not empty
|
|
86
|
-
assert(result.message.content.length > 0, "message content should not be empty");
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const testChatStreamingCore = async function(model) {
|
|
90
|
-
// Test chat with streaming enabled
|
|
91
|
-
const result = await puter.ai.chat("Count from 1 to 5", {
|
|
92
|
-
model: model,
|
|
93
|
-
stream: true,
|
|
94
|
-
max_tokens: 100
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Check that result is an object and not null
|
|
98
|
-
assert(typeof result === 'object', "streaming chat should return an object");
|
|
99
|
-
assert(result !== null, "streaming chat should not return null");
|
|
100
|
-
|
|
101
|
-
// For streaming, we need to check if it's an async iterator or has a different structure
|
|
102
|
-
// The exact structure depends on the implementation, but we should verify it's consumable
|
|
103
|
-
if (result[Symbol.asyncIterator]) {
|
|
104
|
-
// If it's an async iterator, test that we can consume it
|
|
105
|
-
let chunks = [];
|
|
106
|
-
let chunkCount = 0;
|
|
107
|
-
const maxChunks = 10; // Limit to prevent infinite loops in tests
|
|
108
|
-
|
|
109
|
-
for await (const chunk of result) {
|
|
110
|
-
chunks.push(chunk);
|
|
111
|
-
chunkCount++;
|
|
112
|
-
|
|
113
|
-
// Verify each chunk has expected structure
|
|
114
|
-
assert(typeof chunk === 'object', "each streaming chunk should be an object");
|
|
115
|
-
|
|
116
|
-
// Break after reasonable number of chunks for testing
|
|
117
|
-
if (chunkCount >= maxChunks) break;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
assert(chunks.length > 0, "streaming should produce at least one chunk");
|
|
121
|
-
|
|
122
|
-
} else {
|
|
123
|
-
// If not an async iterator, it might be a different streaming implementation
|
|
124
|
-
// Check for common streaming response patterns
|
|
125
|
-
|
|
126
|
-
// Check basic result structure (similar to non-streaming but may have different properties)
|
|
127
|
-
assert(typeof result.message === 'object' || typeof result.content === 'string',
|
|
128
|
-
"streaming result should have message object or content string");
|
|
129
|
-
|
|
130
|
-
// Check that it has streaming-specific properties
|
|
131
|
-
assert(typeof result.stream === 'boolean' || result.stream === true,
|
|
132
|
-
"streaming result should indicate it's a stream");
|
|
133
|
-
|
|
134
|
-
// Check that toString() and valueOf() methods exist and work
|
|
135
|
-
assert(typeof result.toString === 'function', "streaming result should have toString method");
|
|
136
|
-
assert(typeof result.valueOf === 'function', "streaming result should have valueOf method");
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// Function to generate test functions for a specific model
|
|
141
|
-
const generateTestsForModel = function(model) {
|
|
142
|
-
const modelName = model.replace(/[^a-zA-Z0-9]/g, '_'); // Sanitize model name for function names
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
[`testChatBasicPrompt_${modelName}`]: {
|
|
146
|
-
name: `testChatBasicPrompt_${modelName}`,
|
|
147
|
-
description: `Test basic AI chat prompt with ${model} model and verify response structure`,
|
|
148
|
-
test: async function() {
|
|
149
|
-
try {
|
|
150
|
-
await testChatBasicPromptCore(model);
|
|
151
|
-
pass(`testChatBasicPrompt_${modelName} passed`);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
fail(`testChatBasicPrompt_${modelName} failed:`, error);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
[`testChatWithParameters_${modelName}`]: {
|
|
159
|
-
name: `testChatWithParameters_${modelName}`,
|
|
160
|
-
description: `Test AI chat with parameters (temperature, max_tokens) using ${model} model`,
|
|
161
|
-
test: async function() {
|
|
162
|
-
try {
|
|
163
|
-
await testChatWithParametersCore(model);
|
|
164
|
-
pass(`testChatWithParameters_${modelName} passed`);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
fail(`testChatWithParameters_${modelName} failed:`, error);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
[`testChatWithMessageArray_${modelName}`]: {
|
|
172
|
-
name: `testChatWithMessageArray_${modelName}`,
|
|
173
|
-
description: `Test AI chat with message array format using ${model} model`,
|
|
174
|
-
test: async function() {
|
|
175
|
-
try {
|
|
176
|
-
await testChatWithMessageArrayCore(model);
|
|
177
|
-
pass(`testChatWithMessageArray_${modelName} passed`);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
fail(`testChatWithMessageArray_${modelName} failed:`, error);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
[`testChatStreaming_${modelName}`]: {
|
|
185
|
-
name: `testChatStreaming_${modelName}`,
|
|
186
|
-
description: `Test AI chat with streaming enabled using ${model} model`,
|
|
187
|
-
test: async function() {
|
|
188
|
-
try {
|
|
189
|
-
await testChatStreamingCore(model);
|
|
190
|
-
pass(`testChatStreaming_${modelName} passed`);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
fail(`testChatStreaming_${modelName} failed:`, error);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
// Generate all test functions for all models
|
|
200
|
-
const generateAllTests = function() {
|
|
201
|
-
const allTests = [];
|
|
202
|
-
|
|
203
|
-
TEST_MODELS.forEach(model => {
|
|
204
|
-
const modelTests = generateTestsForModel(model);
|
|
205
|
-
Object.values(modelTests).forEach(test => {
|
|
206
|
-
allTests.push(test);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
return allTests;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
// Export the generated tests
|
|
214
|
-
window.aiTests = generateAllTests();
|