@pi-oxide/pi-host-web 0.1.0
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/LICENSE +21 -0
- package/package.json +24 -0
- package/pi_host_web.d.ts +412 -0
- package/pi_host_web.js +432 -0
- package/pi_host_web_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 pi-oxide contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-oxide/pi-host-web",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Irving Ou <irving@pi-oxide.dev>"
|
|
6
|
+
],
|
|
7
|
+
"description": "WASM host for pi-core. Browser FileSystem Access API, fetch(), JS event loop.",
|
|
8
|
+
"version": "0.1.0",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pi-oxide/pi-oxide"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"pi_host_web_bg.wasm",
|
|
16
|
+
"pi_host_web.js",
|
|
17
|
+
"pi_host_web.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"main": "pi_host_web.js",
|
|
20
|
+
"types": "pi_host_web.d.ts",
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"./snippets/*"
|
|
23
|
+
]
|
|
24
|
+
}
|
package/pi_host_web.d.ts
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export interface AgentContext {
|
|
4
|
+
system_prompt: string;
|
|
5
|
+
messages: AgentMessage[];
|
|
6
|
+
tools: ToolDefinition[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AgentOptions {
|
|
10
|
+
system_prompt: string;
|
|
11
|
+
model: Model;
|
|
12
|
+
thinking_level?: ThinkingLevel;
|
|
13
|
+
tools?: ToolDefinition[];
|
|
14
|
+
steering_mode?: QueueMode;
|
|
15
|
+
follow_up_mode?: QueueMode;
|
|
16
|
+
tool_execution_mode?: ToolExecutionMode;
|
|
17
|
+
session_id?: SessionId;
|
|
18
|
+
messages?: AgentMessage[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AgentState {
|
|
22
|
+
system_prompt: string;
|
|
23
|
+
model: Model;
|
|
24
|
+
thinking_level: ThinkingLevel;
|
|
25
|
+
tools: ToolDefinition[];
|
|
26
|
+
messages: AgentMessage[];
|
|
27
|
+
is_streaming: boolean;
|
|
28
|
+
streaming_message?: AgentMessage;
|
|
29
|
+
pending_tool_calls: string[];
|
|
30
|
+
error_message?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ApiUsageSnapshot {
|
|
34
|
+
estimated_tokens: number;
|
|
35
|
+
actual_input_tokens: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AssistantMessage {
|
|
39
|
+
content: Content[];
|
|
40
|
+
api: ApiName;
|
|
41
|
+
provider: ProviderName;
|
|
42
|
+
model: ModelId;
|
|
43
|
+
stop_reason: StopReason;
|
|
44
|
+
error_message?: string;
|
|
45
|
+
timestamp: number;
|
|
46
|
+
usage: TokenUsage;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface BackgroundJobRef {
|
|
50
|
+
job_id: string;
|
|
51
|
+
tool_call_id: ToolCallId;
|
|
52
|
+
command_label: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ContextProjectionBudget {
|
|
56
|
+
max_tool_result_chars: number;
|
|
57
|
+
max_context_tokens: number;
|
|
58
|
+
default_preview_chars: number;
|
|
59
|
+
microcompact_after_turns?: number;
|
|
60
|
+
compaction_threshold?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ContextProjectionReport {
|
|
64
|
+
estimated_tokens: number;
|
|
65
|
+
replacements: ContextReplacement[];
|
|
66
|
+
dropped_messages: number;
|
|
67
|
+
needs_compaction?: boolean;
|
|
68
|
+
cache_breakpoints?: number[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ContextProjectionState {
|
|
72
|
+
replacements: Record<string, ContextReplacement>;
|
|
73
|
+
last_api_usage?: ApiUsageSnapshot | null;
|
|
74
|
+
turns_since_compaction?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ContextReplacement {
|
|
78
|
+
tool_call_id: string;
|
|
79
|
+
tool_name: string;
|
|
80
|
+
artifact_id: string;
|
|
81
|
+
original_chars: number;
|
|
82
|
+
preview_chars: number;
|
|
83
|
+
strategy: ContextStrategy;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface CreateAgentOutput {
|
|
87
|
+
handle: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface CreateAgentResult {
|
|
91
|
+
ok: boolean;
|
|
92
|
+
data?: CreateAgentOutput;
|
|
93
|
+
error?: ErrorDto;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface EmptyResult {
|
|
97
|
+
ok: boolean;
|
|
98
|
+
data?: null;
|
|
99
|
+
error?: ErrorDto;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface ErrorDto {
|
|
103
|
+
code: string;
|
|
104
|
+
message: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface EventsOutput {
|
|
108
|
+
events: AgentEvent[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface EventsResult {
|
|
112
|
+
ok: boolean;
|
|
113
|
+
data?: EventsOutput;
|
|
114
|
+
error?: ErrorDto;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ImageContent {
|
|
118
|
+
media_type: string;
|
|
119
|
+
data: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface LlmContext {
|
|
123
|
+
system_prompt: string;
|
|
124
|
+
messages: AgentMessage[];
|
|
125
|
+
tools: ToolDefinition[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface LlmError {
|
|
129
|
+
code: string;
|
|
130
|
+
message: string;
|
|
131
|
+
details?: Value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface Model {
|
|
135
|
+
id: ModelId;
|
|
136
|
+
name: ModelName;
|
|
137
|
+
api: ApiName;
|
|
138
|
+
provider: ProviderName;
|
|
139
|
+
base_url?: string;
|
|
140
|
+
reasoning: boolean;
|
|
141
|
+
context_window: number;
|
|
142
|
+
max_tokens: number;
|
|
143
|
+
capabilities?: ModelCapabilities;
|
|
144
|
+
cost?: ModelCost;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ModelCapabilities {
|
|
148
|
+
vision: boolean;
|
|
149
|
+
json_mode: boolean;
|
|
150
|
+
function_calling: boolean;
|
|
151
|
+
streaming: boolean;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface ModelCost {
|
|
155
|
+
input: number;
|
|
156
|
+
output: number;
|
|
157
|
+
cache_read: number;
|
|
158
|
+
cache_write: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface ProjectionInput {
|
|
162
|
+
system_prompt: string;
|
|
163
|
+
messages: AgentMessage[];
|
|
164
|
+
budget: ContextProjectionBudget;
|
|
165
|
+
state: ContextProjectionState;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface ProjectionOutput {
|
|
169
|
+
projected_messages: AgentMessage[];
|
|
170
|
+
updated_state: ContextProjectionState;
|
|
171
|
+
report: ContextProjectionReport;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface ProjectionResult {
|
|
175
|
+
ok: boolean;
|
|
176
|
+
data?: ProjectionOutput;
|
|
177
|
+
error?: ErrorDto;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface StateOutput {
|
|
181
|
+
state: AgentState;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface StateResult {
|
|
185
|
+
ok: boolean;
|
|
186
|
+
data?: StateOutput;
|
|
187
|
+
error?: ErrorDto;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface StepOutput {
|
|
191
|
+
events: AgentEvent[];
|
|
192
|
+
actions: AgentAction[];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface StepResult {
|
|
196
|
+
ok: boolean;
|
|
197
|
+
data?: StepOutput;
|
|
198
|
+
error?: ErrorDto;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface TextContent {
|
|
202
|
+
text: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface TokenUsage {
|
|
206
|
+
input: number;
|
|
207
|
+
output: number;
|
|
208
|
+
cache_read: number;
|
|
209
|
+
cache_write: number;
|
|
210
|
+
total_tokens: number;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface ToolCall {
|
|
214
|
+
id: ToolCallId;
|
|
215
|
+
name: ToolName;
|
|
216
|
+
arguments: ToolArguments;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface ToolDefinition {
|
|
220
|
+
name: ToolName;
|
|
221
|
+
label: string;
|
|
222
|
+
description: string;
|
|
223
|
+
parameters: JsonSchema;
|
|
224
|
+
execution_mode?: ExecutionMode;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface ToolError {
|
|
228
|
+
code: string;
|
|
229
|
+
message: string;
|
|
230
|
+
details?: ToolDetails;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface ToolExecutionUpdate {
|
|
234
|
+
tool_call_id: ToolCallId;
|
|
235
|
+
stream: ToolOutputStream;
|
|
236
|
+
chunk: string;
|
|
237
|
+
sequence: number;
|
|
238
|
+
timestamp: number;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface ToolResult {
|
|
242
|
+
content: Content[];
|
|
243
|
+
details?: ToolDetails;
|
|
244
|
+
terminate?: boolean;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface ToolResultContext {
|
|
248
|
+
content_kind: ContentKind;
|
|
249
|
+
strategy: ContextStrategy;
|
|
250
|
+
original_chars: number;
|
|
251
|
+
truncated_by_tool: boolean;
|
|
252
|
+
path?: string;
|
|
253
|
+
exit_code?: number;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface ToolResultMessage {
|
|
257
|
+
tool_call_id: ToolCallId;
|
|
258
|
+
tool_name: ToolName;
|
|
259
|
+
content: Content[];
|
|
260
|
+
details?: ToolDetails;
|
|
261
|
+
is_error: boolean;
|
|
262
|
+
timestamp: number;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface UserMessage {
|
|
266
|
+
content: Content[];
|
|
267
|
+
timestamp: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type AgentAction = { type: "stream_llm"; context: LlmContext; session_id?: SessionId } | { type: "execute_tools"; calls: ToolCall[] } | { type: "cancel_tools"; tool_call_ids: ToolCallId[]; reason: CancelReason } | { type: "wait_for_input"; mode: WaitMode } | { type: "finished"; messages: AgentMessage[] };
|
|
271
|
+
|
|
272
|
+
export type AgentEvent = { type: "agent_start" } | { type: "agent_end"; messages: AgentMessage[] } | { type: "turn_start" } | { type: "turn_end"; message: AgentMessage; tool_results: ToolResultMessage[] } | { type: "message_start"; message: AgentMessage } | { type: "message_update"; message: AgentMessage; delta: ContentDelta } | { type: "message_end"; message: AgentMessage } | { type: "tool_execution_start"; tool_call_id: ToolCallId; tool_name: ToolName; args?: ToolArguments } | { type: "tool_execution_update"; tool_call_id: ToolCallId; stream: ToolOutputStream; chunk: string; sequence: number; timestamp: number } | { type: "tool_execution_end"; tool_call_id: ToolCallId; result: ToolResult; is_error: boolean } | { type: "tool_execution_cancelled"; tool_call_id: ToolCallId; reason: CancelReason } | { type: "queue_update"; steer: AgentMessage[]; follow_up: AgentMessage[] } | { type: "save_point"; had_pending_writes: boolean } | { type: "settled" };
|
|
273
|
+
|
|
274
|
+
export type AgentMessage = ({ role: "user" } & UserMessage) | ({ role: "assistant" } & AssistantMessage) | ({ role: "tool_result" } & ToolResultMessage);
|
|
275
|
+
|
|
276
|
+
export type ApiName = string;
|
|
277
|
+
|
|
278
|
+
export type CancelReason = { type: "user_requested" } | { type: "timeout" } | { type: "agent_aborted" } | { type: "dependency_failed"; cause_tool_call_id: ToolCallId };
|
|
279
|
+
|
|
280
|
+
export type Content = ({ type: "text" } & TextContent) | ({ type: "image" } & ImageContent) | ({ type: "tool_call" } & ToolCall);
|
|
281
|
+
|
|
282
|
+
export type ContentDelta = { kind: "text_start" } | { kind: "text_delta"; text: string } | { kind: "text_end" } | { kind: "thinking_start" } | { kind: "thinking_delta"; text: string } | { kind: "thinking_end" } | { kind: "tool_call_start"; tool_call: ToolCall } | { kind: "tool_call_delta"; tool_call_id: ToolCallId; delta: Value } | { kind: "tool_call_end"; tool_call_id: ToolCallId };
|
|
283
|
+
|
|
284
|
+
export type ContentKind = "file_read" | "command_output" | "diff" | "search_results" | "directory_listing" | "generic_text";
|
|
285
|
+
|
|
286
|
+
export type ContextStrategy = { type: "keep_full" } | { type: "head"; max_chars: number } | { type: "tail"; max_chars: number } | { type: "head_tail"; head_chars: number; tail_chars: number } | { type: "drop_if_old" } | { type: "microcompacted" };
|
|
287
|
+
|
|
288
|
+
export type ExecutionMode = "parallel" | "sequential";
|
|
289
|
+
|
|
290
|
+
export type JsonSchema = Value;
|
|
291
|
+
|
|
292
|
+
export type LlmChunk = ({ kind: "start" } & {} & AssistantMessage) | { kind: "text_delta"; text: string } | { kind: "thinking_delta"; text: string } | { kind: "tool_call_delta"; tool_call_id: ToolCallId; delta: Value } | { kind: "done" } | { kind: "error"; message: string };
|
|
293
|
+
|
|
294
|
+
export type LlmResult = { Ok: AssistantMessage } | { Err: { error: LlmError; aborted: boolean } };
|
|
295
|
+
|
|
296
|
+
export type ModelId = string;
|
|
297
|
+
|
|
298
|
+
export type ModelName = string;
|
|
299
|
+
|
|
300
|
+
export type ModelProvider = "open_ai" | "anthropic" | "google" | "ollama" | "custom";
|
|
301
|
+
|
|
302
|
+
export type Phase = "idle" | "streaming" | "executing_tools" | "wait_for_input";
|
|
303
|
+
|
|
304
|
+
export type PromptRequest = AgentMessage | { text: string };
|
|
305
|
+
|
|
306
|
+
export type ProviderName = string;
|
|
307
|
+
|
|
308
|
+
export type QueueMode = "one_at_a_time" | "all";
|
|
309
|
+
|
|
310
|
+
export type SessionId = string;
|
|
311
|
+
|
|
312
|
+
export type StopReason = "end_turn" | "max_tokens" | "tool_use" | "aborted" | "error";
|
|
313
|
+
|
|
314
|
+
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
315
|
+
|
|
316
|
+
export type ToolArguments = Value;
|
|
317
|
+
|
|
318
|
+
export type ToolCallId = string;
|
|
319
|
+
|
|
320
|
+
export type ToolDetails = Value;
|
|
321
|
+
|
|
322
|
+
export type ToolDonePayload = { error: ToolError } | { result: ToolResult } | ToolResult;
|
|
323
|
+
|
|
324
|
+
export type ToolExecutionMode = "parallel" | "sequential";
|
|
325
|
+
|
|
326
|
+
export type ToolName = string;
|
|
327
|
+
|
|
328
|
+
export type ToolOutputStream = "stdout" | "stderr" | "status";
|
|
329
|
+
|
|
330
|
+
export type WaitMode = "steering" | "follow_up" | "any";
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
export function createAgent(options: AgentOptions): CreateAgentResult;
|
|
334
|
+
|
|
335
|
+
export function destroyAgent(handle: number): EmptyResult;
|
|
336
|
+
|
|
337
|
+
export function drainTraceLog(): string[];
|
|
338
|
+
|
|
339
|
+
export function feedLlmChunk(handle: number, chunk: LlmChunk): EventsResult;
|
|
340
|
+
|
|
341
|
+
export function followUp(handle: number, message: AgentMessage): EmptyResult;
|
|
342
|
+
|
|
343
|
+
export function onLlmDone(handle: number, result: LlmResult): StepResult;
|
|
344
|
+
|
|
345
|
+
export function onToolCancelled(handle: number, tool_call_id: string, reason: CancelReason): StepResult;
|
|
346
|
+
|
|
347
|
+
export function onToolDone(handle: number, tool_call_id: string, payload: ToolDonePayload): StepResult;
|
|
348
|
+
|
|
349
|
+
export function onToolStarted(handle: number, tool_call_id: string): EventsResult;
|
|
350
|
+
|
|
351
|
+
export function onToolUpdate(handle: number, update: ToolExecutionUpdate): EventsResult;
|
|
352
|
+
|
|
353
|
+
export function projectContext(input: ProjectionInput): ProjectionResult;
|
|
354
|
+
|
|
355
|
+
export function prompt(handle: number, prompt: PromptRequest): StepResult;
|
|
356
|
+
|
|
357
|
+
export function reset(handle: number): EmptyResult;
|
|
358
|
+
|
|
359
|
+
export function state(handle: number): StateResult;
|
|
360
|
+
|
|
361
|
+
export function steer(handle: number, message: AgentMessage): EventsResult;
|
|
362
|
+
|
|
363
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
364
|
+
|
|
365
|
+
export interface InitOutput {
|
|
366
|
+
readonly memory: WebAssembly.Memory;
|
|
367
|
+
readonly createAgent: (a: any) => any;
|
|
368
|
+
readonly destroyAgent: (a: number) => any;
|
|
369
|
+
readonly drainTraceLog: () => [number, number];
|
|
370
|
+
readonly feedLlmChunk: (a: number, b: any) => any;
|
|
371
|
+
readonly followUp: (a: number, b: any) => any;
|
|
372
|
+
readonly onLlmDone: (a: number, b: any) => any;
|
|
373
|
+
readonly onToolCancelled: (a: number, b: number, c: number, d: any) => any;
|
|
374
|
+
readonly onToolDone: (a: number, b: number, c: number, d: any) => any;
|
|
375
|
+
readonly onToolStarted: (a: number, b: number, c: number) => any;
|
|
376
|
+
readonly onToolUpdate: (a: number, b: any) => any;
|
|
377
|
+
readonly projectContext: (a: any) => any;
|
|
378
|
+
readonly prompt: (a: number, b: any) => any;
|
|
379
|
+
readonly reset: (a: number) => any;
|
|
380
|
+
readonly state: (a: number) => any;
|
|
381
|
+
readonly steer: (a: number, b: any) => any;
|
|
382
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
383
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
384
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
385
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
386
|
+
readonly __externref_table_alloc: () => number;
|
|
387
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
388
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
389
|
+
readonly __wbindgen_start: () => void;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
396
|
+
* a precompiled `WebAssembly.Module`.
|
|
397
|
+
*
|
|
398
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
399
|
+
*
|
|
400
|
+
* @returns {InitOutput}
|
|
401
|
+
*/
|
|
402
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
406
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
407
|
+
*
|
|
408
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
409
|
+
*
|
|
410
|
+
* @returns {Promise<InitOutput>}
|
|
411
|
+
*/
|
|
412
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/pi_host_web.js
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/* @ts-self-types="./pi_host_web.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {AgentOptions} options
|
|
5
|
+
* @returns {CreateAgentResult}
|
|
6
|
+
*/
|
|
7
|
+
export function createAgent(options) {
|
|
8
|
+
const ret = wasm.createAgent(options);
|
|
9
|
+
return ret;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {number} handle
|
|
14
|
+
* @returns {EmptyResult}
|
|
15
|
+
*/
|
|
16
|
+
export function destroyAgent(handle) {
|
|
17
|
+
const ret = wasm.destroyAgent(handle);
|
|
18
|
+
return ret;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @returns {string[]}
|
|
23
|
+
*/
|
|
24
|
+
export function drainTraceLog() {
|
|
25
|
+
const ret = wasm.drainTraceLog();
|
|
26
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
27
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
28
|
+
return v1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {number} handle
|
|
33
|
+
* @param {LlmChunk} chunk
|
|
34
|
+
* @returns {EventsResult}
|
|
35
|
+
*/
|
|
36
|
+
export function feedLlmChunk(handle, chunk) {
|
|
37
|
+
const ret = wasm.feedLlmChunk(handle, chunk);
|
|
38
|
+
return ret;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {number} handle
|
|
43
|
+
* @param {AgentMessage} message
|
|
44
|
+
* @returns {EmptyResult}
|
|
45
|
+
*/
|
|
46
|
+
export function followUp(handle, message) {
|
|
47
|
+
const ret = wasm.followUp(handle, message);
|
|
48
|
+
return ret;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {number} handle
|
|
53
|
+
* @param {LlmResult} result
|
|
54
|
+
* @returns {StepResult}
|
|
55
|
+
*/
|
|
56
|
+
export function onLlmDone(handle, result) {
|
|
57
|
+
const ret = wasm.onLlmDone(handle, result);
|
|
58
|
+
return ret;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {number} handle
|
|
63
|
+
* @param {string} tool_call_id
|
|
64
|
+
* @param {CancelReason} reason
|
|
65
|
+
* @returns {StepResult}
|
|
66
|
+
*/
|
|
67
|
+
export function onToolCancelled(handle, tool_call_id, reason) {
|
|
68
|
+
const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
69
|
+
const len0 = WASM_VECTOR_LEN;
|
|
70
|
+
const ret = wasm.onToolCancelled(handle, ptr0, len0, reason);
|
|
71
|
+
return ret;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {number} handle
|
|
76
|
+
* @param {string} tool_call_id
|
|
77
|
+
* @param {ToolDonePayload} payload
|
|
78
|
+
* @returns {StepResult}
|
|
79
|
+
*/
|
|
80
|
+
export function onToolDone(handle, tool_call_id, payload) {
|
|
81
|
+
const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
82
|
+
const len0 = WASM_VECTOR_LEN;
|
|
83
|
+
const ret = wasm.onToolDone(handle, ptr0, len0, payload);
|
|
84
|
+
return ret;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {number} handle
|
|
89
|
+
* @param {string} tool_call_id
|
|
90
|
+
* @returns {EventsResult}
|
|
91
|
+
*/
|
|
92
|
+
export function onToolStarted(handle, tool_call_id) {
|
|
93
|
+
const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
94
|
+
const len0 = WASM_VECTOR_LEN;
|
|
95
|
+
const ret = wasm.onToolStarted(handle, ptr0, len0);
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {number} handle
|
|
101
|
+
* @param {ToolExecutionUpdate} update
|
|
102
|
+
* @returns {EventsResult}
|
|
103
|
+
*/
|
|
104
|
+
export function onToolUpdate(handle, update) {
|
|
105
|
+
const ret = wasm.onToolUpdate(handle, update);
|
|
106
|
+
return ret;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {ProjectionInput} input
|
|
111
|
+
* @returns {ProjectionResult}
|
|
112
|
+
*/
|
|
113
|
+
export function projectContext(input) {
|
|
114
|
+
const ret = wasm.projectContext(input);
|
|
115
|
+
return ret;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {number} handle
|
|
120
|
+
* @param {PromptRequest} prompt
|
|
121
|
+
* @returns {StepResult}
|
|
122
|
+
*/
|
|
123
|
+
export function prompt(handle, prompt) {
|
|
124
|
+
const ret = wasm.prompt(handle, prompt);
|
|
125
|
+
return ret;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {number} handle
|
|
130
|
+
* @returns {EmptyResult}
|
|
131
|
+
*/
|
|
132
|
+
export function reset(handle) {
|
|
133
|
+
const ret = wasm.reset(handle);
|
|
134
|
+
return ret;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {number} handle
|
|
139
|
+
* @returns {StateResult}
|
|
140
|
+
*/
|
|
141
|
+
export function state(handle) {
|
|
142
|
+
const ret = wasm.state(handle);
|
|
143
|
+
return ret;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @param {number} handle
|
|
148
|
+
* @param {AgentMessage} message
|
|
149
|
+
* @returns {EventsResult}
|
|
150
|
+
*/
|
|
151
|
+
export function steer(handle, message) {
|
|
152
|
+
const ret = wasm.steer(handle, message);
|
|
153
|
+
return ret;
|
|
154
|
+
}
|
|
155
|
+
function __wbg_get_imports() {
|
|
156
|
+
const import0 = {
|
|
157
|
+
__proto__: null,
|
|
158
|
+
__wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
|
|
159
|
+
const ret = arg0 === undefined;
|
|
160
|
+
return ret;
|
|
161
|
+
},
|
|
162
|
+
__wbg___wbindgen_string_get_72bdf95d3ae505b1: function(arg0, arg1) {
|
|
163
|
+
const obj = arg1;
|
|
164
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
165
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
166
|
+
var len1 = WASM_VECTOR_LEN;
|
|
167
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
168
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
169
|
+
},
|
|
170
|
+
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
171
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
172
|
+
},
|
|
173
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
174
|
+
let deferred0_0;
|
|
175
|
+
let deferred0_1;
|
|
176
|
+
try {
|
|
177
|
+
deferred0_0 = arg0;
|
|
178
|
+
deferred0_1 = arg1;
|
|
179
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
180
|
+
} finally {
|
|
181
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
185
|
+
const ret = new Error();
|
|
186
|
+
return ret;
|
|
187
|
+
},
|
|
188
|
+
__wbg_parse_03863847d06c4e89: function() { return handleError(function (arg0, arg1) {
|
|
189
|
+
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
190
|
+
return ret;
|
|
191
|
+
}, arguments); },
|
|
192
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
193
|
+
const ret = arg1.stack;
|
|
194
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
195
|
+
const len1 = WASM_VECTOR_LEN;
|
|
196
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
197
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
198
|
+
},
|
|
199
|
+
__wbg_stringify_8286df6dcc591521: function() { return handleError(function (arg0) {
|
|
200
|
+
const ret = JSON.stringify(arg0);
|
|
201
|
+
return ret;
|
|
202
|
+
}, arguments); },
|
|
203
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
204
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
205
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
206
|
+
return ret;
|
|
207
|
+
},
|
|
208
|
+
__wbindgen_init_externref_table: function() {
|
|
209
|
+
const table = wasm.__wbindgen_externrefs;
|
|
210
|
+
const offset = table.grow(4);
|
|
211
|
+
table.set(0, undefined);
|
|
212
|
+
table.set(offset + 0, undefined);
|
|
213
|
+
table.set(offset + 1, null);
|
|
214
|
+
table.set(offset + 2, true);
|
|
215
|
+
table.set(offset + 3, false);
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
__proto__: null,
|
|
220
|
+
"./pi_host_web_bg.js": import0,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function addToExternrefTable0(obj) {
|
|
225
|
+
const idx = wasm.__externref_table_alloc();
|
|
226
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
227
|
+
return idx;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
231
|
+
ptr = ptr >>> 0;
|
|
232
|
+
const mem = getDataViewMemory0();
|
|
233
|
+
const result = [];
|
|
234
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
235
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
236
|
+
}
|
|
237
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let cachedDataViewMemory0 = null;
|
|
242
|
+
function getDataViewMemory0() {
|
|
243
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
244
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
245
|
+
}
|
|
246
|
+
return cachedDataViewMemory0;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function getStringFromWasm0(ptr, len) {
|
|
250
|
+
return decodeText(ptr >>> 0, len);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
let cachedUint8ArrayMemory0 = null;
|
|
254
|
+
function getUint8ArrayMemory0() {
|
|
255
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
256
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
257
|
+
}
|
|
258
|
+
return cachedUint8ArrayMemory0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function handleError(f, args) {
|
|
262
|
+
try {
|
|
263
|
+
return f.apply(this, args);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
const idx = addToExternrefTable0(e);
|
|
266
|
+
wasm.__wbindgen_exn_store(idx);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isLikeNone(x) {
|
|
271
|
+
return x === undefined || x === null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
275
|
+
if (realloc === undefined) {
|
|
276
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
277
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
278
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
279
|
+
WASM_VECTOR_LEN = buf.length;
|
|
280
|
+
return ptr;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
let len = arg.length;
|
|
284
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
285
|
+
|
|
286
|
+
const mem = getUint8ArrayMemory0();
|
|
287
|
+
|
|
288
|
+
let offset = 0;
|
|
289
|
+
|
|
290
|
+
for (; offset < len; offset++) {
|
|
291
|
+
const code = arg.charCodeAt(offset);
|
|
292
|
+
if (code > 0x7F) break;
|
|
293
|
+
mem[ptr + offset] = code;
|
|
294
|
+
}
|
|
295
|
+
if (offset !== len) {
|
|
296
|
+
if (offset !== 0) {
|
|
297
|
+
arg = arg.slice(offset);
|
|
298
|
+
}
|
|
299
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
300
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
301
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
302
|
+
|
|
303
|
+
offset += ret.written;
|
|
304
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
WASM_VECTOR_LEN = offset;
|
|
308
|
+
return ptr;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
312
|
+
cachedTextDecoder.decode();
|
|
313
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
314
|
+
let numBytesDecoded = 0;
|
|
315
|
+
function decodeText(ptr, len) {
|
|
316
|
+
numBytesDecoded += len;
|
|
317
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
318
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
319
|
+
cachedTextDecoder.decode();
|
|
320
|
+
numBytesDecoded = len;
|
|
321
|
+
}
|
|
322
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const cachedTextEncoder = new TextEncoder();
|
|
326
|
+
|
|
327
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
328
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
329
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
330
|
+
view.set(buf);
|
|
331
|
+
return {
|
|
332
|
+
read: arg.length,
|
|
333
|
+
written: buf.length
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
let WASM_VECTOR_LEN = 0;
|
|
339
|
+
|
|
340
|
+
let wasmModule, wasmInstance, wasm;
|
|
341
|
+
function __wbg_finalize_init(instance, module) {
|
|
342
|
+
wasmInstance = instance;
|
|
343
|
+
wasm = instance.exports;
|
|
344
|
+
wasmModule = module;
|
|
345
|
+
cachedDataViewMemory0 = null;
|
|
346
|
+
cachedUint8ArrayMemory0 = null;
|
|
347
|
+
wasm.__wbindgen_start();
|
|
348
|
+
return wasm;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function __wbg_load(module, imports) {
|
|
352
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
353
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
354
|
+
try {
|
|
355
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
356
|
+
} catch (e) {
|
|
357
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
358
|
+
|
|
359
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
360
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
361
|
+
|
|
362
|
+
} else { throw e; }
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const bytes = await module.arrayBuffer();
|
|
367
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
368
|
+
} else {
|
|
369
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
370
|
+
|
|
371
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
372
|
+
return { instance, module };
|
|
373
|
+
} else {
|
|
374
|
+
return instance;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function expectedResponseType(type) {
|
|
379
|
+
switch (type) {
|
|
380
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function initSync(module) {
|
|
387
|
+
if (wasm !== undefined) return wasm;
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
if (module !== undefined) {
|
|
391
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
392
|
+
({module} = module)
|
|
393
|
+
} else {
|
|
394
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const imports = __wbg_get_imports();
|
|
399
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
400
|
+
module = new WebAssembly.Module(module);
|
|
401
|
+
}
|
|
402
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
403
|
+
return __wbg_finalize_init(instance, module);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async function __wbg_init(module_or_path) {
|
|
407
|
+
if (wasm !== undefined) return wasm;
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
if (module_or_path !== undefined) {
|
|
411
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
412
|
+
({module_or_path} = module_or_path)
|
|
413
|
+
} else {
|
|
414
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (module_or_path === undefined) {
|
|
419
|
+
module_or_path = new URL('pi_host_web_bg.wasm', import.meta.url);
|
|
420
|
+
}
|
|
421
|
+
const imports = __wbg_get_imports();
|
|
422
|
+
|
|
423
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
424
|
+
module_or_path = fetch(module_or_path);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
428
|
+
|
|
429
|
+
return __wbg_finalize_init(instance, module);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|