@pi-oxide/pi-host-web 0.3.0 → 0.4.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/pi_host_web.js CHANGED
@@ -1,21 +1,30 @@
1
1
  /* @ts-self-types="./pi_host_web.d.ts" */
2
2
 
3
3
  /**
4
- * @param {number} handle
5
- * @param {SessionEntry} entry
6
- * @returns {EmptyResult}
4
+ * @param {AgentOptions} options
5
+ * @param {ContextProjectionBudget} budget
6
+ * @returns {CreateHostAgentResult}
7
7
  */
8
- export function appendSessionEntry(handle, entry) {
9
- const ret = wasm.appendSessionEntry(handle, entry);
8
+ export function createHostAgent(options, budget) {
9
+ const ret = wasm.createHostAgent(options, budget);
10
10
  return ret;
11
11
  }
12
12
 
13
13
  /**
14
- * @param {AgentOptions} options
15
- * @returns {CreateAgentResult}
14
+ * @param {ContextProjectionBudget} _budget
15
+ * @returns {CreateHostStateResult}
16
+ */
17
+ export function createHostState(_budget) {
18
+ const ret = wasm.createHostState(_budget);
19
+ return ret;
20
+ }
21
+
22
+ /**
23
+ * @param {number} handle
24
+ * @returns {EmptyResult}
16
25
  */
17
- export function createAgent(options) {
18
- const ret = wasm.createAgent(options);
26
+ export function destroyHostAgent(handle) {
27
+ const ret = wasm.destroyHostAgent(handle);
19
28
  return ret;
20
29
  }
21
30
 
@@ -23,8 +32,8 @@ export function createAgent(options) {
23
32
  * @param {number} handle
24
33
  * @returns {EmptyResult}
25
34
  */
26
- export function destroyAgent(handle) {
27
- const ret = wasm.destroyAgent(handle);
35
+ export function destroyHostState(handle) {
36
+ const ret = wasm.destroyHostState(handle);
28
37
  return ret;
29
38
  }
30
39
 
@@ -49,193 +58,218 @@ export function estimateTokensForText(text) {
49
58
  }
50
59
 
51
60
  /**
52
- * @param {string} tool_name
53
- * @returns {ContextStrategy}
61
+ * @param {number} handle
62
+ * @returns {HostStatePersistDataResult}
54
63
  */
55
- export function fallbackStrategy(tool_name) {
56
- const ptr0 = passStringToWasm0(tool_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
57
- const len0 = WASM_VECTOR_LEN;
58
- const ret = wasm.fallbackStrategy(ptr0, len0);
64
+ export function getHostAgentPersistData(handle) {
65
+ const ret = wasm.getHostAgentPersistData(handle);
59
66
  return ret;
60
67
  }
61
68
 
62
69
  /**
63
70
  * @param {number} handle
64
- * @param {LlmChunk} chunk
65
- * @returns {EventsResult}
71
+ * @returns {HostStatePersistDataResult}
66
72
  */
67
- export function feedLlmChunk(handle, chunk) {
68
- const ret = wasm.feedLlmChunk(handle, chunk);
73
+ export function getHostStatePersistData(handle) {
74
+ const ret = wasm.getHostStatePersistData(handle);
69
75
  return ret;
70
76
  }
71
77
 
72
78
  /**
73
79
  * @param {number} handle
74
- * @param {AgentMessage} message
75
- * @returns {EmptyResult}
80
+ * @returns {TurnResultResult}
76
81
  */
77
- export function followUp(handle, message) {
78
- const ret = wasm.followUp(handle, message);
82
+ export function hostAbort(handle) {
83
+ const ret = wasm.hostAbort(handle);
79
84
  return ret;
80
85
  }
81
86
 
82
87
  /**
83
88
  * @param {number} handle
84
- * @returns {SessionBranchResult}
89
+ * @param {string} summary
90
+ * @param {string[]} _compacted_entry_ids
91
+ * @returns {TurnResultResult}
85
92
  */
86
- export function getSessionBranch(handle) {
87
- const ret = wasm.getSessionBranch(handle);
93
+ export function hostAcceptCompaction(handle, summary, _compacted_entry_ids) {
94
+ const ptr0 = passStringToWasm0(summary, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ const ptr1 = passArrayJsValueToWasm0(_compacted_entry_ids, wasm.__wbindgen_malloc);
97
+ const len1 = WASM_VECTOR_LEN;
98
+ const ret = wasm.hostAcceptCompaction(handle, ptr0, len0, ptr1, len1);
88
99
  return ret;
89
100
  }
90
101
 
91
102
  /**
92
103
  * @param {number} handle
93
- * @returns {SessionStateResult}
104
+ * @returns {TurnResultResult}
94
105
  */
95
- export function getSessionState(handle) {
96
- const ret = wasm.getSessionState(handle);
106
+ export function hostContinueTurn(handle) {
107
+ const ret = wasm.hostContinueTurn(handle);
97
108
  return ret;
98
109
  }
99
110
 
100
111
  /**
101
112
  * @param {number} handle
102
- * @param {string} target_id
103
- * @param {BranchSummary | null} [summary]
104
- * @returns {MoveToResult}
113
+ * @param {LlmChunk} chunk
114
+ * @returns {TurnResultResult}
105
115
  */
106
- export function moveTo(handle, target_id, summary) {
107
- const ptr0 = passStringToWasm0(target_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
108
- const len0 = WASM_VECTOR_LEN;
109
- const ret = wasm.moveTo(handle, ptr0, len0, isLikeNone(summary) ? 0 : addToExternrefTable0(summary));
116
+ export function hostFeedLlmChunk(handle, chunk) {
117
+ const ret = wasm.hostFeedLlmChunk(handle, chunk);
110
118
  return ret;
111
119
  }
112
120
 
113
121
  /**
114
122
  * @param {number} handle
115
123
  * @param {LlmResult} result
116
- * @returns {StepResult}
124
+ * @returns {TurnResultResult}
117
125
  */
118
- export function onLlmDone(handle, result) {
119
- const ret = wasm.onLlmDone(handle, result);
126
+ export function hostLlmDone(handle, result) {
127
+ const ret = wasm.hostLlmDone(handle, result);
120
128
  return ret;
121
129
  }
122
130
 
123
131
  /**
124
132
  * @param {number} handle
125
- * @param {string} tool_call_id
126
- * @param {CancelReason} reason
127
- * @returns {StepResult}
133
+ * @param {string} artifact_id
134
+ * @returns {string}
128
135
  */
129
- export function onToolCancelled(handle, tool_call_id, reason) {
130
- const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
131
- const len0 = WASM_VECTOR_LEN;
132
- const ret = wasm.onToolCancelled(handle, ptr0, len0, reason);
133
- return ret;
136
+ export function hostReadArtifact(handle, artifact_id) {
137
+ let deferred3_0;
138
+ let deferred3_1;
139
+ try {
140
+ const ptr0 = passStringToWasm0(artifact_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
141
+ const len0 = WASM_VECTOR_LEN;
142
+ const ret = wasm.hostReadArtifact(handle, ptr0, len0);
143
+ var ptr2 = ret[0];
144
+ var len2 = ret[1];
145
+ if (ret[3]) {
146
+ ptr2 = 0; len2 = 0;
147
+ throw takeFromExternrefTable0(ret[2]);
148
+ }
149
+ deferred3_0 = ptr2;
150
+ deferred3_1 = len2;
151
+ return getStringFromWasm0(ptr2, len2);
152
+ } finally {
153
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
154
+ }
134
155
  }
135
156
 
136
157
  /**
137
158
  * @param {number} handle
138
- * @param {string} tool_call_id
139
- * @param {ToolDonePayload} payload
140
- * @returns {StepResult}
159
+ * @returns {EmptyResult}
141
160
  */
142
- export function onToolDone(handle, tool_call_id, payload) {
143
- const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
144
- const len0 = WASM_VECTOR_LEN;
145
- const ret = wasm.onToolDone(handle, ptr0, len0, payload);
161
+ export function hostReset(handle) {
162
+ const ret = wasm.hostReset(handle);
146
163
  return ret;
147
164
  }
148
165
 
149
166
  /**
150
167
  * @param {number} handle
151
- * @param {string} tool_call_id
152
- * @returns {EventsResult}
168
+ * @param {string} query
169
+ * @returns {ArtifactSearchResults}
153
170
  */
154
- export function onToolStarted(handle, tool_call_id) {
155
- const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
171
+ export function hostSearchArtifacts(handle, query) {
172
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
156
173
  const len0 = WASM_VECTOR_LEN;
157
- const ret = wasm.onToolStarted(handle, ptr0, len0);
158
- return ret;
174
+ const ret = wasm.hostSearchArtifacts(handle, ptr0, len0);
175
+ if (ret[2]) {
176
+ throw takeFromExternrefTable0(ret[1]);
177
+ }
178
+ return takeFromExternrefTable0(ret[0]);
159
179
  }
160
180
 
161
181
  /**
162
182
  * @param {number} handle
163
- * @param {ToolExecutionUpdate} update
164
- * @returns {EventsResult}
183
+ * @param {AgentMessage} message
184
+ * @returns {TurnResultResult}
165
185
  */
166
- export function onToolUpdate(handle, update) {
167
- const ret = wasm.onToolUpdate(handle, update);
186
+ export function hostSteer(handle, message) {
187
+ const ret = wasm.hostSteer(handle, message);
168
188
  return ret;
169
189
  }
170
190
 
171
191
  /**
172
- * @param {ProjectionInput} input
173
- * @returns {ProjectionResult}
192
+ * @param {number} handle
193
+ * @param {string} tool_call_id
194
+ * @param {CancelReason} reason
195
+ * @returns {TurnResultResult}
174
196
  */
175
- export function projectContext(input) {
176
- const ret = wasm.projectContext(input);
197
+ export function hostToolCancelled(handle, tool_call_id, reason) {
198
+ const ptr0 = passStringToWasm0(tool_call_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
199
+ const len0 = WASM_VECTOR_LEN;
200
+ const ret = wasm.hostToolCancelled(handle, ptr0, len0, reason);
177
201
  return ret;
178
202
  }
179
203
 
180
204
  /**
181
205
  * @param {number} handle
182
- * @param {PromptRequest} prompt
183
- * @returns {StepResult}
206
+ * @param {ToolCallId} id
207
+ * @param {ToolResult} result
208
+ * @returns {TurnResultResult}
184
209
  */
185
- export function prompt(handle, prompt) {
186
- const ret = wasm.prompt(handle, prompt);
210
+ export function hostToolDone(handle, id, result) {
211
+ const ret = wasm.hostToolDone(handle, id, result);
187
212
  return ret;
188
213
  }
189
214
 
190
215
  /**
191
- * @param {number} handle
192
- * @returns {EmptyResult}
216
+ * @param {AgentOptions} options
217
+ * @param {PersistData} data
218
+ * @returns {CreateHostAgentResult}
193
219
  */
194
- export function reset(handle) {
195
- const ret = wasm.reset(handle);
220
+ export function restoreHostAgent(options, data) {
221
+ const ret = wasm.restoreHostAgent(options, data);
196
222
  return ret;
197
223
  }
198
224
 
199
225
  /**
200
- * @param {string} level
226
+ * @param {PersistData} data
227
+ * @returns {CreateHostStateResult}
201
228
  */
202
- export function setLogLevel(level) {
203
- const ptr0 = passStringToWasm0(level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
204
- const len0 = WASM_VECTOR_LEN;
205
- wasm.setLogLevel(ptr0, len0);
229
+ export function restoreHostState(data) {
230
+ const ret = wasm.restoreHostState(data);
231
+ return ret;
206
232
  }
207
233
 
208
234
  /**
209
- * @param {number} handle
210
- * @param {SessionState} state
211
- * @returns {EmptyResult}
235
+ * @param {string} json
236
+ * @returns {CreateHostStateResult}
212
237
  */
213
- export function setSessionState(handle, state) {
214
- const ret = wasm.setSessionState(handle, state);
238
+ export function restoreHostStateFromJson(json) {
239
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len0 = WASM_VECTOR_LEN;
241
+ const ret = wasm.restoreHostStateFromJson(ptr0, len0);
215
242
  return ret;
216
243
  }
217
244
 
218
245
  /**
219
- * @param {number} handle
220
- * @returns {StateResult}
246
+ * @param {string} level
221
247
  */
222
- export function state(handle) {
223
- const ret = wasm.state(handle);
224
- return ret;
248
+ export function setLogLevel(level) {
249
+ const ptr0 = passStringToWasm0(level, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
250
+ const len0 = WASM_VECTOR_LEN;
251
+ wasm.setLogLevel(ptr0, len0);
225
252
  }
226
253
 
227
254
  /**
228
255
  * @param {number} handle
229
- * @param {AgentMessage} message
230
- * @returns {EventsResult}
256
+ * @param {StartTurnInput} input
257
+ * @returns {TurnResultResult}
231
258
  */
232
- export function steer(handle, message) {
233
- const ret = wasm.steer(handle, message);
259
+ export function startTurn(handle, input) {
260
+ const ret = wasm.startTurn(handle, input);
234
261
  return ret;
235
262
  }
236
263
  function __wbg_get_imports() {
237
264
  const import0 = {
238
265
  __proto__: null,
266
+ __wbg___wbindgen_debug_string_0accd80f45e5faa2: function(arg0, arg1) {
267
+ const ret = debugString(arg1);
268
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
269
+ const len1 = WASM_VECTOR_LEN;
270
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
271
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
272
+ },
239
273
  __wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
240
274
  const ret = arg0 === undefined;
241
275
  return ret;
@@ -307,10 +341,17 @@ function __wbg_get_imports() {
307
341
  const ret = new Error();
308
342
  return ret;
309
343
  },
344
+ __wbg_new_ce1ab61c1c2b300d: function() {
345
+ const ret = new Object();
346
+ return ret;
347
+ },
310
348
  __wbg_parse_03863847d06c4e89: function() { return handleError(function (arg0, arg1) {
311
349
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
312
350
  return ret;
313
351
  }, arguments); },
352
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
353
+ arg0[arg1] = arg2;
354
+ },
314
355
  __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
315
356
  const ret = arg1.stack;
316
357
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -322,6 +363,11 @@ function __wbg_get_imports() {
322
363
  const ret = JSON.stringify(arg0);
323
364
  return ret;
324
365
  }, arguments); },
366
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
367
+ // Cast intrinsic for `Ref(String) -> Externref`.
368
+ const ret = getStringFromWasm0(arg0, arg1);
369
+ return ret;
370
+ },
325
371
  __wbindgen_init_externref_table: function() {
326
372
  const table = wasm.__wbindgen_externrefs;
327
373
  const offset = table.grow(4);
@@ -344,6 +390,71 @@ function addToExternrefTable0(obj) {
344
390
  return idx;
345
391
  }
346
392
 
393
+ function debugString(val) {
394
+ // primitive types
395
+ const type = typeof val;
396
+ if (type == 'number' || type == 'boolean' || val == null) {
397
+ return `${val}`;
398
+ }
399
+ if (type == 'string') {
400
+ return `"${val}"`;
401
+ }
402
+ if (type == 'symbol') {
403
+ const description = val.description;
404
+ if (description == null) {
405
+ return 'Symbol';
406
+ } else {
407
+ return `Symbol(${description})`;
408
+ }
409
+ }
410
+ if (type == 'function') {
411
+ const name = val.name;
412
+ if (typeof name == 'string' && name.length > 0) {
413
+ return `Function(${name})`;
414
+ } else {
415
+ return 'Function';
416
+ }
417
+ }
418
+ // objects
419
+ if (Array.isArray(val)) {
420
+ const length = val.length;
421
+ let debug = '[';
422
+ if (length > 0) {
423
+ debug += debugString(val[0]);
424
+ }
425
+ for(let i = 1; i < length; i++) {
426
+ debug += ', ' + debugString(val[i]);
427
+ }
428
+ debug += ']';
429
+ return debug;
430
+ }
431
+ // Test for built-in
432
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
433
+ let className;
434
+ if (builtInMatches && builtInMatches.length > 1) {
435
+ className = builtInMatches[1];
436
+ } else {
437
+ // Failed to match the standard '[object ClassName]'
438
+ return toString.call(val);
439
+ }
440
+ if (className == 'Object') {
441
+ // we're a user defined class or Object
442
+ // JSON.stringify avoids problems with cycles, and is generally much
443
+ // easier than looping through ownProperties of `val`.
444
+ try {
445
+ return 'Object(' + JSON.stringify(val) + ')';
446
+ } catch (_) {
447
+ return 'Object';
448
+ }
449
+ }
450
+ // errors
451
+ if (val instanceof Error) {
452
+ return `${val.name}: ${val.message}\n${val.stack}`;
453
+ }
454
+ // TODO we could test for more things here, like `Set`s and `Map`s.
455
+ return className;
456
+ }
457
+
347
458
  let cachedDataViewMemory0 = null;
348
459
  function getDataViewMemory0() {
349
460
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -377,6 +488,16 @@ function isLikeNone(x) {
377
488
  return x === undefined || x === null;
378
489
  }
379
490
 
491
+ function passArrayJsValueToWasm0(array, malloc) {
492
+ const ptr = malloc(array.length * 4, 4) >>> 0;
493
+ for (let i = 0; i < array.length; i++) {
494
+ const add = addToExternrefTable0(array[i]);
495
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
496
+ }
497
+ WASM_VECTOR_LEN = array.length;
498
+ return ptr;
499
+ }
500
+
380
501
  function passStringToWasm0(arg, malloc, realloc) {
381
502
  if (realloc === undefined) {
382
503
  const buf = cachedTextEncoder.encode(arg);
@@ -414,6 +535,12 @@ function passStringToWasm0(arg, malloc, realloc) {
414
535
  return ptr;
415
536
  }
416
537
 
538
+ function takeFromExternrefTable0(idx) {
539
+ const value = wasm.__wbindgen_externrefs.get(idx);
540
+ wasm.__externref_table_dealloc(idx);
541
+ return value;
542
+ }
543
+
417
544
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
418
545
  cachedTextDecoder.decode();
419
546
  const MAX_SAFARI_DECODE_BYTES = 2146435072;
Binary file