simple-agents-wasm 0.2.28
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 +51 -0
- package/index.d.ts +155 -0
- package/index.js +734 -0
- package/package.json +28 -0
- package/pkg/simple_agents_wasm.d.ts +62 -0
- package/pkg/simple_agents_wasm.js +749 -0
- package/pkg/simple_agents_wasm_bg.wasm +0 -0
- package/pkg/simple_agents_wasm_bg.wasm.d.ts +21 -0
- package/rust/Cargo.toml +19 -0
- package/rust/src/lib.rs +1034 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# simple-agents-wasm
|
|
2
|
+
|
|
3
|
+
Browser-compatible SimpleAgents client for OpenAI-compatible providers.
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
7
|
+
This package now loads a Rust-compiled WASM core (`rust/src/lib.rs`) for
|
|
8
|
+
runtime execution when wasm artifacts are available. A JS fallback remains for
|
|
9
|
+
non-wasm environments and local Node tests.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i simple-agents-wasm
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Build wasm artifacts
|
|
18
|
+
|
|
19
|
+
Prerequisites:
|
|
20
|
+
|
|
21
|
+
- Rust target: `wasm32-unknown-unknown`
|
|
22
|
+
- `wasm-bindgen` CLI (matching `wasm-bindgen` crate version)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run build
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This compiles Rust to `wasm32-unknown-unknown` and generates browser bindings
|
|
29
|
+
under `pkg/` using `wasm-bindgen`.
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { Client } from "simple-agents-wasm";
|
|
35
|
+
|
|
36
|
+
const client = new Client("openai", {
|
|
37
|
+
apiKey: "<BYOK>",
|
|
38
|
+
baseUrl: "https://api.openai.com/v1"
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const result = await client.complete("gpt-4o-mini", "Say hi in one line.");
|
|
42
|
+
console.log(result.content);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Important notes
|
|
46
|
+
|
|
47
|
+
- Browser mode still depends on provider CORS support.
|
|
48
|
+
- `healed_json` and `schema` completion modes are not supported yet.
|
|
49
|
+
- `runWorkflowYaml(workflowPath, ...)` is not supported in browser runtime.
|
|
50
|
+
- `runWorkflowYamlString(...)` supports string-based workflow execution only.
|
|
51
|
+
- Use `hasRustBackend()` to check whether Rust wasm backend was loaded.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export interface CompleteOptions {
|
|
2
|
+
maxTokens?: number;
|
|
3
|
+
temperature?: number;
|
|
4
|
+
topP?: number;
|
|
5
|
+
stream?: boolean;
|
|
6
|
+
mode?: "standard" | "healed_json" | "schema";
|
|
7
|
+
schema?: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface MessageInput {
|
|
11
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
12
|
+
content: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
toolCallId?: string;
|
|
15
|
+
toolCalls?: Array<JsToolCall>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface JsToolCallFunction {
|
|
19
|
+
name: string;
|
|
20
|
+
arguments: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface JsToolCall {
|
|
24
|
+
id: string;
|
|
25
|
+
toolType: string;
|
|
26
|
+
function: JsToolCallFunction;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ToolCallResultFunction {
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ToolCallResult {
|
|
35
|
+
id: string;
|
|
36
|
+
toolType: string;
|
|
37
|
+
function: ToolCallResultFunction;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CompletionUsage {
|
|
41
|
+
promptTokens: number;
|
|
42
|
+
completionTokens: number;
|
|
43
|
+
totalTokens: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface HealingData {
|
|
47
|
+
value?: unknown;
|
|
48
|
+
flags: string[];
|
|
49
|
+
confidence: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface CompletionResult {
|
|
53
|
+
id: string;
|
|
54
|
+
model: string;
|
|
55
|
+
role: string;
|
|
56
|
+
content?: string;
|
|
57
|
+
toolCalls?: Array<ToolCallResult>;
|
|
58
|
+
finishReason?: string;
|
|
59
|
+
usage: CompletionUsage;
|
|
60
|
+
usageAvailable: boolean;
|
|
61
|
+
latencyMs: number;
|
|
62
|
+
raw?: string;
|
|
63
|
+
healed?: HealingData;
|
|
64
|
+
coerced?: HealingData;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface StreamChunk {
|
|
68
|
+
id: string;
|
|
69
|
+
model: string;
|
|
70
|
+
content?: string;
|
|
71
|
+
finishReason?: string;
|
|
72
|
+
error?: string;
|
|
73
|
+
raw?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface StreamDelta {
|
|
77
|
+
id: string;
|
|
78
|
+
model: string;
|
|
79
|
+
index: number;
|
|
80
|
+
role?: string;
|
|
81
|
+
content?: string;
|
|
82
|
+
finishReason?: string;
|
|
83
|
+
raw?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface StreamErrorEvent {
|
|
87
|
+
message: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface StreamEvent {
|
|
91
|
+
eventType: "delta" | "error" | "done";
|
|
92
|
+
delta?: StreamDelta;
|
|
93
|
+
error?: StreamErrorEvent;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ClientConfig {
|
|
97
|
+
baseUrl?: string;
|
|
98
|
+
apiKey: string;
|
|
99
|
+
fetchImpl?: typeof fetch;
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface WorkflowRunOptions {
|
|
104
|
+
telemetry?: Record<string, unknown>;
|
|
105
|
+
trace?: Record<string, unknown>;
|
|
106
|
+
functions?: Record<
|
|
107
|
+
string,
|
|
108
|
+
(args: Record<string, unknown>, context: Record<string, unknown>) => unknown
|
|
109
|
+
>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface WorkflowRunEvent {
|
|
113
|
+
stepId: string;
|
|
114
|
+
stepType: string;
|
|
115
|
+
status: "started" | "completed";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface WorkflowRunResult {
|
|
119
|
+
status: "ok";
|
|
120
|
+
context: Record<string, unknown>;
|
|
121
|
+
output?: unknown;
|
|
122
|
+
events: WorkflowRunEvent[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export declare class Client {
|
|
126
|
+
constructor(provider: string, config: ClientConfig);
|
|
127
|
+
complete(
|
|
128
|
+
model: string,
|
|
129
|
+
promptOrMessages: string | MessageInput[],
|
|
130
|
+
options?: CompleteOptions
|
|
131
|
+
): Promise<CompletionResult>;
|
|
132
|
+
stream(
|
|
133
|
+
model: string,
|
|
134
|
+
promptOrMessages: string | MessageInput[],
|
|
135
|
+
onChunk: (chunk: StreamChunk) => void,
|
|
136
|
+
options?: CompleteOptions
|
|
137
|
+
): Promise<CompletionResult>;
|
|
138
|
+
streamEvents(
|
|
139
|
+
model: string,
|
|
140
|
+
promptOrMessages: string | MessageInput[],
|
|
141
|
+
onEvent: (event: StreamEvent) => void,
|
|
142
|
+
options?: CompleteOptions
|
|
143
|
+
): Promise<CompletionResult>;
|
|
144
|
+
runWorkflowYamlString(
|
|
145
|
+
yamlText: string,
|
|
146
|
+
workflowInput: Record<string, unknown>,
|
|
147
|
+
workflowOptions?: WorkflowRunOptions
|
|
148
|
+
): Promise<WorkflowRunResult>;
|
|
149
|
+
runWorkflowYaml(
|
|
150
|
+
workflowPath: string,
|
|
151
|
+
workflowInput: Record<string, unknown>
|
|
152
|
+
): Promise<never>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export declare function hasRustBackend(): Promise<boolean>;
|