simple-agents-wasm 0.3.0 → 0.3.3

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/index.d.ts CHANGED
@@ -100,10 +100,43 @@ export interface ClientConfig {
100
100
  headers?: Record<string, string>;
101
101
  }
102
102
 
103
+ /** Matches Rust `YamlWorkflowTelemetryConfig` JSON (snake_case). */
104
+ export interface WorkflowTelemetryConfig {
105
+ enabled?: boolean;
106
+ nerdstats?: boolean;
107
+ sample_rate?: number;
108
+ payload_mode?: "full_payload" | "redacted_payload";
109
+ retention_days?: number;
110
+ multi_tenant?: boolean;
111
+ tool_trace_mode?: "full" | "redacted" | "off";
112
+ }
113
+
114
+ export interface WorkflowTraceContext {
115
+ trace_id?: string;
116
+ span_id?: string;
117
+ parent_span_id?: string;
118
+ traceparent?: string;
119
+ tracestate?: string;
120
+ baggage?: Record<string, string>;
121
+ }
122
+
123
+ export interface WorkflowTraceTenant {
124
+ workspace_id?: string;
125
+ user_id?: string;
126
+ conversation_id?: string;
127
+ request_id?: string;
128
+ run_id?: string;
129
+ }
130
+
131
+ export interface WorkflowTraceConfig {
132
+ context?: WorkflowTraceContext;
133
+ tenant?: WorkflowTraceTenant;
134
+ }
135
+
103
136
  export interface WorkflowRunOptions {
104
- telemetry?: Record<string, unknown>;
105
- trace?: Record<string, unknown>;
106
137
  model?: string;
138
+ telemetry?: WorkflowTelemetryConfig;
139
+ trace?: WorkflowTraceConfig;
107
140
  onEvent?: (event: Record<string, unknown>) => void;
108
141
  functions?: Record<
109
142
  string,
@@ -114,6 +147,12 @@ export interface WorkflowRunOptions {
114
147
  >;
115
148
  }
116
149
 
150
+ /** Common workflow `input` fields; extra keys are allowed for workflow-specific payloads. */
151
+ export interface WorkflowInputFields {
152
+ email_text?: string;
153
+ [key: string]: unknown;
154
+ }
155
+
117
156
  export interface WorkflowRunEvent {
118
157
  stepId: string;
119
158
  stepType: string;
@@ -132,6 +171,7 @@ export interface WorkflowExecutionFlags {
132
171
  healing?: boolean;
133
172
  workflow_streaming?: boolean;
134
173
  node_llm_streaming?: boolean;
174
+ split_stream_deltas?: boolean;
135
175
  }
136
176
 
137
177
  export interface WorkflowExecutionRequest {
@@ -139,7 +179,7 @@ export interface WorkflowExecutionRequest {
139
179
  messages: MessageInput[];
140
180
  context?: Record<string, unknown>;
141
181
  media?: Record<string, unknown>;
142
- input?: Record<string, unknown>;
182
+ input?: WorkflowInputFields;
143
183
  execution?: WorkflowExecutionFlags;
144
184
  workflow_options?: WorkflowRunOptions;
145
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-agents-wasm",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "description": "Browser-compatible SimpleAgents client for OpenAI-compatible providers",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -16,12 +16,26 @@
16
16
  "files": [
17
17
  "index.js",
18
18
  "index.d.ts",
19
+ "workflow_stream_printer.mjs",
20
+ "workflow_stream_printer.d.ts",
19
21
  "runtime",
20
22
  "README.md",
21
23
  "pkg",
22
24
  "rust/Cargo.toml",
23
25
  "rust/src"
24
26
  ],
27
+ "exports": {
28
+ ".": {
29
+ "types": "./index.d.ts",
30
+ "import": "./index.js",
31
+ "default": "./index.js"
32
+ },
33
+ "./workflow_stream_printer": {
34
+ "types": "./workflow_stream_printer.d.ts",
35
+ "import": "./workflow_stream_printer.mjs",
36
+ "default": "./workflow_stream_printer.mjs"
37
+ }
38
+ },
25
39
  "engines": {
26
40
  "node": ">=18"
27
41
  },
@@ -8,6 +8,17 @@ export class WasmClient {
8
8
  constructor(provider: string, config: any);
9
9
  runWorkflowYaml(workflow_path: string, _workflow_input: any): any;
10
10
  runWorkflowYamlString(yaml_text: string, workflow_input: any, workflow_options?: any | null): Promise<any>;
11
+ /**
12
+ * Run a YAML workflow from a YAML text string (new unified API alias).
13
+ *
14
+ * This is an alias for `runWorkflowYamlString` using the new naming convention.
15
+ * WASM cannot use file paths; pass the YAML document text directly.
16
+ *
17
+ * ```js
18
+ * const result = await client.runYamlString(yamlText, messages);
19
+ * ```
20
+ */
21
+ runYamlString(yaml_text: string, messages: any, options?: any | null): Promise<any>;
11
22
  streamEvents(model: string, prompt_or_messages: any, on_event: Function, options?: any | null): Promise<any>;
12
23
  }
13
24
 
@@ -26,9 +37,10 @@ export interface InitOutput {
26
37
  readonly wasmclient_new: (a: number, b: number, c: any) => [number, number, number];
27
38
  readonly wasmclient_runWorkflowYaml: (a: number, b: number, c: number, d: any) => [number, number, number];
28
39
  readonly wasmclient_runWorkflowYamlString: (a: number, b: number, c: number, d: any, e: number) => any;
40
+ readonly wasmclient_runYamlString: (a: number, b: number, c: number, d: any, e: number) => any;
29
41
  readonly wasmclient_streamEvents: (a: number, b: number, c: number, d: any, e: any, f: number) => any;
30
- readonly wasm_bindgen__convert__closures_____invoke__h327a4c82efcf6931: (a: number, b: number, c: any) => [number, number];
31
- readonly wasm_bindgen__convert__closures_____invoke__h67e61867e7d8792e: (a: number, b: number, c: any, d: any) => void;
42
+ readonly wasm_bindgen__convert__closures_____invoke__h9f53f643b01d7c8e: (a: number, b: number, c: any) => [number, number];
43
+ readonly wasm_bindgen__convert__closures_____invoke__h05acb8c479b21d4b: (a: number, b: number, c: any, d: any) => void;
32
44
  readonly __wbindgen_malloc: (a: number, b: number) => number;
33
45
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
34
46
  readonly __wbindgen_exn_store: (a: number) => void;
@@ -64,6 +64,26 @@ export class WasmClient {
64
64
  const ret = wasm.wasmclient_runWorkflowYamlString(this.__wbg_ptr, ptr0, len0, workflow_input, isLikeNone(workflow_options) ? 0 : addToExternrefTable0(workflow_options));
65
65
  return ret;
66
66
  }
67
+ /**
68
+ * Run a YAML workflow from a YAML text string (new unified API alias).
69
+ *
70
+ * This is an alias for `runWorkflowYamlString` using the new naming convention.
71
+ * WASM cannot use file paths; pass the YAML document text directly.
72
+ *
73
+ * ```js
74
+ * const result = await client.runYamlString(yamlText, messages);
75
+ * ```
76
+ * @param {string} yaml_text
77
+ * @param {any} messages
78
+ * @param {any | null} [options]
79
+ * @returns {Promise<any>}
80
+ */
81
+ runYamlString(yaml_text, messages, options) {
82
+ const ptr0 = passStringToWasm0(yaml_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ret = wasm.wasmclient_runYamlString(this.__wbg_ptr, ptr0, len0, messages, isLikeNone(options) ? 0 : addToExternrefTable0(options));
85
+ return ret;
86
+ }
67
87
  /**
68
88
  * @param {string} model
69
89
  * @param {any} prompt_or_messages
@@ -267,6 +287,10 @@ function __wbg_get_imports() {
267
287
  const ret = result;
268
288
  return ret;
269
289
  },
290
+ __wbg_isArray_4daec0bfe3d60230: function(arg0) {
291
+ const ret = Array.isArray(arg0);
292
+ return ret;
293
+ },
270
294
  __wbg_isArray_db61795ad004c139: function(arg0) {
271
295
  const ret = Array.isArray(arg0);
272
296
  return ret;
@@ -314,7 +338,7 @@ function __wbg_get_imports() {
314
338
  const a = state0.a;
315
339
  state0.a = 0;
316
340
  try {
317
- return wasm_bindgen__convert__closures_____invoke__h67e61867e7d8792e(a, state0.b, arg0, arg1);
341
+ return wasm_bindgen__convert__closures_____invoke__h05acb8c479b21d4b(a, state0.b, arg0, arg1);
318
342
  } finally {
319
343
  state0.a = a;
320
344
  }
@@ -394,8 +418,8 @@ function __wbg_get_imports() {
394
418
  return ret;
395
419
  },
396
420
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
397
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 147, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
398
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h327a4c82efcf6931);
421
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 151, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
422
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h9f53f643b01d7c8e);
399
423
  return ret;
400
424
  },
401
425
  __wbindgen_cast_0000000000000002: function(arg0) {
@@ -434,15 +458,15 @@ function __wbg_get_imports() {
434
458
  };
435
459
  }
436
460
 
437
- function wasm_bindgen__convert__closures_____invoke__h327a4c82efcf6931(arg0, arg1, arg2) {
438
- const ret = wasm.wasm_bindgen__convert__closures_____invoke__h327a4c82efcf6931(arg0, arg1, arg2);
461
+ function wasm_bindgen__convert__closures_____invoke__h9f53f643b01d7c8e(arg0, arg1, arg2) {
462
+ const ret = wasm.wasm_bindgen__convert__closures_____invoke__h9f53f643b01d7c8e(arg0, arg1, arg2);
439
463
  if (ret[1]) {
440
464
  throw takeFromExternrefTable0(ret[0]);
441
465
  }
442
466
  }
443
467
 
444
- function wasm_bindgen__convert__closures_____invoke__h67e61867e7d8792e(arg0, arg1, arg2, arg3) {
445
- wasm.wasm_bindgen__convert__closures_____invoke__h67e61867e7d8792e(arg0, arg1, arg2, arg3);
468
+ function wasm_bindgen__convert__closures_____invoke__h05acb8c479b21d4b(arg0, arg1, arg2, arg3) {
469
+ wasm.wasm_bindgen__convert__closures_____invoke__h05acb8c479b21d4b(arg0, arg1, arg2, arg3);
446
470
  }
447
471
 
448
472
  const WasmClientFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -8,9 +8,10 @@ export const wasmclient_complete: (a: number, b: number, c: number, d: any, e: n
8
8
  export const wasmclient_new: (a: number, b: number, c: any) => [number, number, number];
9
9
  export const wasmclient_runWorkflowYaml: (a: number, b: number, c: number, d: any) => [number, number, number];
10
10
  export const wasmclient_runWorkflowYamlString: (a: number, b: number, c: number, d: any, e: number) => any;
11
+ export const wasmclient_runYamlString: (a: number, b: number, c: number, d: any, e: number) => any;
11
12
  export const wasmclient_streamEvents: (a: number, b: number, c: number, d: any, e: any, f: number) => any;
12
- export const wasm_bindgen__convert__closures_____invoke__h327a4c82efcf6931: (a: number, b: number, c: any) => [number, number];
13
- export const wasm_bindgen__convert__closures_____invoke__h67e61867e7d8792e: (a: number, b: number, c: any, d: any) => void;
13
+ export const wasm_bindgen__convert__closures_____invoke__h9f53f643b01d7c8e: (a: number, b: number, c: any) => [number, number];
14
+ export const wasm_bindgen__convert__closures_____invoke__h05acb8c479b21d4b: (a: number, b: number, c: any, d: any) => void;
14
15
  export const __wbindgen_malloc: (a: number, b: number) => number;
15
16
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
17
  export const __wbindgen_exn_store: (a: number) => void;
package/rust/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "simple-agents-wasm-rust"
3
- version = "0.3.0"
3
+ version = "0.3.3"
4
4
  edition = "2021"
5
5
  license = "MIT OR Apache-2.0"
6
6
 
package/rust/src/lib.rs CHANGED
@@ -2000,6 +2000,37 @@ impl WasmClient {
2000
2000
  "workflow file paths are not supported in browser runtime: {workflow_path}"
2001
2001
  )))
2002
2002
  }
2003
+
2004
+ /// Run a YAML workflow from a YAML text string (new unified API alias).
2005
+ ///
2006
+ /// This is an alias for `runWorkflowYamlString` using the new naming convention.
2007
+ /// WASM cannot use file paths; pass the YAML document text directly.
2008
+ ///
2009
+ /// ```js
2010
+ /// const result = await client.runYamlString(yamlText, messages);
2011
+ /// ```
2012
+ #[wasm_bindgen(js_name = runYamlString)]
2013
+ pub async fn run_yaml_string(
2014
+ &self,
2015
+ yaml_text: String,
2016
+ messages: JsValue,
2017
+ options: Option<JsValue>,
2018
+ ) -> Result<JsValue, JsValue> {
2019
+ // Build workflow input envelope from the messages arg
2020
+ let messages_value: serde_json::Value = if messages.is_array() || messages.is_object() {
2021
+ serde_wasm_bindgen::from_value(messages)
2022
+ .unwrap_or(serde_json::json!([]))
2023
+ } else if let Some(prompt) = messages.as_string() {
2024
+ serde_json::json!([{"role": "user", "content": prompt}])
2025
+ } else {
2026
+ serde_json::json!([])
2027
+ };
2028
+
2029
+ let input_js = serde_wasm_bindgen::to_value(&serde_json::json!({ "messages": messages_value }))
2030
+ .map_err(|_| js_error("failed to serialize messages input"))?;
2031
+
2032
+ self.run_workflow_yaml_string(yaml_text, input_js, options).await
2033
+ }
2003
2034
  }
2004
2035
 
2005
2036
  #[wasm_bindgen(js_name = supportsRustWasm)]
@@ -0,0 +1,12 @@
1
+ export interface WorkflowStreamPrinterOptions {
2
+ /** When true, print thinking vs output deltas instead of merged `node_stream_delta`. */
3
+ splitThinking?: boolean;
4
+ }
5
+
6
+ /**
7
+ * Build a default `onEvent` callback for {@link Client.streamWorkflow} (Node-friendly streaming;
8
+ * in browsers without `process.stdout`, falls back to `console.log` per chunk).
9
+ */
10
+ export function createWorkflowStreamPrinter(
11
+ options?: WorkflowStreamPrinterOptions,
12
+ ): (event: Record<string, unknown>) => void;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @typedef {Object} WorkflowStreamPrinterOptions
3
+ * @property {boolean} [splitThinking] When true, print `node_stream_thinking_delta` and
4
+ * `node_stream_output_delta`; otherwise print `node_stream_delta`.
5
+ */
6
+
7
+ /**
8
+ * Default `onEvent` handler for {@link Client.streamWorkflow} that prints stream tokens to stdout.
9
+ * @param {WorkflowStreamPrinterOptions} [options]
10
+ * @returns {(event: Record<string, unknown>) => void}
11
+ */
12
+ function writeChunk(chunk) {
13
+ if (typeof process !== "undefined" && process.stdout?.write) {
14
+ process.stdout.write(chunk);
15
+ } else if (typeof chunk === "string" && chunk.length > 0) {
16
+ console.log(chunk);
17
+ }
18
+ }
19
+
20
+ function writeLine() {
21
+ if (typeof process !== "undefined" && process.stdout?.write) {
22
+ process.stdout.write("\n");
23
+ } else {
24
+ console.log();
25
+ }
26
+ }
27
+
28
+ export function createWorkflowStreamPrinter(options = {}) {
29
+ const splitThinking = options.splitThinking === true;
30
+ /** @type {{ currentNode: string | null, lineOpen: boolean, lastTokenLabel: string | null }} */
31
+ const state = { currentNode: null, lineOpen: false, lastTokenLabel: null };
32
+
33
+ return (event) => {
34
+ const eventType = event?.event_type;
35
+ if (typeof eventType !== "string") return;
36
+
37
+ let isStream = eventType === "node_stream_delta";
38
+ if (splitThinking) {
39
+ isStream =
40
+ eventType === "node_stream_thinking_delta" ||
41
+ eventType === "node_stream_output_delta";
42
+ }
43
+
44
+ const delta = typeof event.delta === "string" ? event.delta : "";
45
+ if (isStream && delta !== "") {
46
+ let displayId =
47
+ typeof event.node_id === "string"
48
+ ? event.node_id
49
+ : typeof event.step_id === "string"
50
+ ? event.step_id
51
+ : "?";
52
+
53
+ if (state.currentNode !== displayId) {
54
+ if (state.lineOpen) writeLine();
55
+ writeChunk(`\nStep: ${displayId}\nStreaming: `);
56
+ state.currentNode = displayId;
57
+ state.lineOpen = true;
58
+ state.lastTokenLabel = null;
59
+ }
60
+
61
+ if (splitThinking) {
62
+ const parts = [];
63
+ if (typeof event.token_kind === "string" && event.token_kind.trim()) {
64
+ parts.push(event.token_kind.trim());
65
+ }
66
+ if (event.is_terminal_node_token === true) {
67
+ parts.push("terminal");
68
+ }
69
+ const tokenLabel = parts.length ? `[${parts.join(" ")}] ` : "";
70
+ if (tokenLabel && tokenLabel !== state.lastTokenLabel) {
71
+ if (state.lineOpen) writeLine();
72
+ writeChunk(`${tokenLabel}${displayId}: `);
73
+ state.lastTokenLabel = tokenLabel;
74
+ state.lineOpen = true;
75
+ }
76
+ writeChunk(delta);
77
+ } else {
78
+ writeChunk(delta);
79
+ }
80
+ return;
81
+ }
82
+
83
+ if (eventType === "workflow_started" || eventType === "workflow_completed") {
84
+ return;
85
+ }
86
+ };
87
+ }