@pi-oxide/pi-host-web 0.4.0 → 0.5.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/sdk/index.js DELETED
@@ -1,111 +0,0 @@
1
- /**
2
- * High-level JS SDK for @pi-oxide/pi-host-web.
3
- *
4
- * Hides WASM loading and numeric handles.
5
- * Supports streaming LLM responses and full agent lifecycle.
6
- *
7
- * Import from the package root:
8
- * import { ensureInit, toolResult } from "@pi-oxide/pi-host-web";
9
- */
10
-
11
- import {
12
- default as init,
13
- initSync,
14
- createHostAgent,
15
- destroyHostAgent,
16
- startTurn,
17
- hostFeedLlmChunk,
18
- hostLlmDone,
19
- hostToolDone,
20
- hostAcceptCompaction,
21
- hostContinueTurn,
22
- getHostStatePersistData,
23
- restoreHostState,
24
- restoreHostStateFromJson,
25
- hostReadArtifact,
26
- hostSearchArtifacts,
27
- hostToolCancelled,
28
- hostAbort,
29
- getHostAgentPersistData,
30
- restoreHostAgent,
31
- createHostState,
32
- destroyHostState,
33
- hostSteer,
34
- hostReset,
35
- estimateTokens,
36
- estimateTokensForText,
37
- setLogLevel,
38
- } from "../pi_host_web.js";
39
-
40
- export {
41
- createHostState,
42
- destroyHostState,
43
- createHostAgent,
44
- destroyHostAgent,
45
- startTurn,
46
- hostFeedLlmChunk,
47
- hostLlmDone,
48
- hostToolDone,
49
- hostAcceptCompaction,
50
- hostContinueTurn,
51
- getHostStatePersistData,
52
- restoreHostState,
53
- restoreHostStateFromJson,
54
- hostReadArtifact,
55
- hostSearchArtifacts,
56
- hostToolCancelled,
57
- hostAbort,
58
- getHostAgentPersistData,
59
- restoreHostAgent,
60
- hostSteer,
61
- hostReset,
62
- estimateTokens,
63
- estimateTokensForText,
64
- setLogLevel,
65
- };
66
-
67
- let initialized = false;
68
-
69
- /** Ensure the WASM module is loaded. Safe to call multiple times. */
70
- export async function ensureInit() {
71
- if (initialized) return;
72
- if (typeof process !== "undefined" && process.versions?.node) {
73
- const { readFileSync } = await import("node:fs");
74
- const bytes = readFileSync(
75
- new URL("../pi_host_web_bg.wasm", import.meta.url),
76
- );
77
- initSync({ module: bytes });
78
- } else {
79
- await init();
80
- }
81
- initialized = true;
82
- }
83
-
84
- export class HostError extends Error {
85
- constructor(code, message) {
86
- super(message);
87
- this.code = code;
88
- this.name = "HostError";
89
- }
90
- }
91
-
92
- export function unwrap(result) {
93
- if (!result.ok) {
94
- throw new HostError(result.error.code, result.error.message);
95
- }
96
- return result.data;
97
- }
98
-
99
- /** Build a successful tool result payload. */
100
- export function toolResult(text, opts = {}) {
101
- const payload = {
102
- content: [{ type: "text", text }],
103
- };
104
- if (opts.terminate) {
105
- payload.terminate = true;
106
- }
107
- if (opts.details) {
108
- payload.details = opts.details;
109
- }
110
- return payload;
111
- }
package/sdk/index.ts DELETED
@@ -1,53 +0,0 @@
1
- // Public SDK exports — the only surface normal apps should import.
2
- // Internal engine details are hidden in sdk/internal/.
3
-
4
- export { ensureInit, HostError, unwrap, toolResult } from "./init.ts";
5
-
6
- // SDK exports
7
- export { Agent } from "./agent.ts";
8
- export { defineModel } from "./model.ts";
9
- export { anthropic } from "./internal/providers/anthropic.ts";
10
- export { openai, openaiCompatible } from "./internal/providers/openai.ts";
11
- export { defineTools, tool } from "./tools.ts";
12
- export { browserTools } from "./internal/tools/browser.ts";
13
- export { artifactTools } from "./internal/tools/artifact.ts";
14
- export { indexedDbStore, memoryStore, localStorageStore, httpStore } from "./stores.ts";
15
- export { useAgent } from "./react/index.ts";
16
-
17
- export type {
18
- AgentArtifact,
19
- AgentArtifactRef,
20
- ArtifactPolicy,
21
- ArtifactSearchQuery,
22
- ArtifactSearchResult,
23
- } from "./artifacts.ts";
24
-
25
- export type {
26
- AgentConfig,
27
- AgentInput,
28
- AgentRunOptions,
29
- AgentRunResult,
30
- AgentEventName,
31
- AgentEventHandler,
32
- AgentMessage,
33
- AgentContentBlock,
34
- AgentToolRun,
35
- AgentStatus,
36
- AgentModel,
37
- ModelRequest,
38
- ModelResponse,
39
- ModelEvent,
40
- AgentTools,
41
- AgentToolDefinition,
42
- AgentStore,
43
- AgentSnapshot,
44
- AgentContextPolicy,
45
- AgentSummarizer,
46
- AgentTelemetry,
47
- AgentError,
48
- Unsubscribe,
49
- TokenUsage,
50
- UseAgentResult,
51
- } from "./types.ts";
52
-
53
- export { createAgentError } from "./errors.ts";
package/sdk/init.ts DELETED
@@ -1,58 +0,0 @@
1
- // WASM initialization and low-level helpers.
2
- // Kept separate from index.ts to avoid circular imports with internal modules.
3
-
4
- import {
5
- default as init,
6
- initSync,
7
- } from "../pi_host_web.js";
8
-
9
- let initialized = false;
10
-
11
- /** Ensure the WASM module is loaded. Safe to call multiple times. */
12
- export async function ensureInit() {
13
- if (initialized) return;
14
- if (typeof process !== "undefined" && process.versions?.node) {
15
- const { readFileSync } = await import("node:fs");
16
- const bytes = readFileSync(
17
- new URL("../pi_host_web_bg.wasm", import.meta.url),
18
- );
19
- initSync({ module: bytes });
20
- } else {
21
- await init();
22
- }
23
- initialized = true;
24
- }
25
-
26
- export class HostError extends Error {
27
- code: string;
28
- constructor(code: string, message: string) {
29
- super(message);
30
- this.code = code;
31
- this.name = "HostError";
32
- }
33
- }
34
-
35
- export function unwrap(result: { ok: boolean; data?: unknown; error?: { code: string; message: string } }): unknown {
36
- if (!result.ok) {
37
- throw new HostError(result.error!.code, result.error!.message);
38
- }
39
- return result.data;
40
- }
41
-
42
- /** Build a successful tool result payload. */
43
- export function toolResult(text: string, opts: { terminate?: boolean; details?: object } = {}) {
44
- const payload: {
45
- content: Array<{ type: "text"; text: string }>;
46
- terminate?: boolean;
47
- details?: object;
48
- } = {
49
- content: [{ type: "text", text }],
50
- };
51
- if (opts.terminate) {
52
- payload.terminate = true;
53
- }
54
- if (opts.details) {
55
- payload.details = opts.details;
56
- }
57
- return payload;
58
- }