simple-agents-node 0.2.6 → 0.2.17

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 CHANGED
@@ -51,7 +51,7 @@ async function main() {
51
51
  console.log(response.usage);
52
52
  console.log(response.healed); // present when using healed_json/schema mode
53
53
 
54
- // Streaming
54
+ // Streaming (legacy chunk callback)
55
55
  const streamed = await client.stream(
56
56
  model,
57
57
  'Say hello in two words.',
@@ -63,6 +63,24 @@ async function main() {
63
63
  );
64
64
  console.log('streamed content:', streamed.content);
65
65
 
66
+ // Streaming (typed event callback)
67
+ await client.streamEvents(
68
+ model,
69
+ 'Say hello in two words.',
70
+ (event) => {
71
+ if (event.eventType === 'delta' && event.delta?.content) {
72
+ process.stdout.write(event.delta.content);
73
+ }
74
+ if (event.eventType === 'error') {
75
+ console.error('\nstream error:', event.error?.message);
76
+ }
77
+ if (event.eventType === 'done') {
78
+ console.log('\nstream done');
79
+ }
80
+ },
81
+ {},
82
+ );
83
+
66
84
  // Healed JSON
67
85
  const healed = await client.complete(
68
86
  'gpt-4',
@@ -81,7 +99,16 @@ main().catch((err) => {
81
99
  ## Notes
82
100
 
83
101
  - Canonical env contract for examples/tests is: `CUSTOM_API_BASE`, `CUSTOM_API_KEY`, `CUSTOM_API_MODEL`, `PROVIDER`.
102
+ - Canonical env contract for examples/tests is: `PROVIDER`, `CUSTOM_API_KEY`, `CUSTOM_API_BASE` (optional), `CUSTOM_API_MODEL`.
84
103
  - For OpenAI provider compatibility, map `CUSTOM_API_*` to `OPENAI_API_*` when needed (`OPENAI_API_KEY`, `OPENAI_API_BASE`, `OPENAI_MODEL`).
85
104
  - `max_tokens`, `temperature`, and `top_p` are optional. Use `mode: "healed_json"` for parsed JSON or `mode: "schema"` with a schema object to coerce/validate.
86
- - `complete` resolves with the first choice, usage metadata, and optional `healed`/`coerced` metadata. `stream` invokes a chunk callback and resolves with aggregated content (healing/schema not yet supported for streams).
105
+ - `complete` resolves with the first choice, usage metadata, and optional `healed`/`coerced` metadata.
106
+ - `stream` invokes a chunk callback and resolves with aggregated content (healing/schema not yet supported for streams).
107
+ - `streamEvents` is the canonical typed streaming callback API with `delta`, `error`, and `done` events.
87
108
  - Set `CUSTOM_API_BASE`, `CUSTOM_API_KEY`, `CUSTOM_API_MODEL`, and `PROVIDER` to run tests/examples consistently across bindings.
109
+
110
+ ## Test Layers
111
+
112
+ - `npm run test:unit` - runtime/export sanity checks
113
+ - `npm run test:contract` - shared fixture parity contract checks
114
+ - `npm run test:live` - provider-backed live checks (env-gated)
package/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export interface CompleteOptions {
13
13
  schema?: unknown
14
14
  }
15
15
  export interface MessageInput {
16
- role: string
16
+ role: 'system' | 'user' | 'assistant' | 'tool'
17
17
  content: string
18
18
  name?: string
19
19
  toolCallId?: string
@@ -23,6 +23,15 @@ export interface JsToolCallFunction {
23
23
  name: string
24
24
  arguments: string
25
25
  }
26
+ export interface ToolCallResultFunction {
27
+ name: string
28
+ arguments: string
29
+ }
30
+ export interface ToolCallResult {
31
+ id: string
32
+ toolType: string
33
+ function: ToolCallResultFunction
34
+ }
26
35
  export interface JsToolCall {
27
36
  id: string
28
37
  toolType: string
@@ -43,7 +52,7 @@ export interface CompletionResult {
43
52
  model: string
44
53
  role: string
45
54
  content?: string
46
- toolCalls?: Array<JsToolCall>
55
+ toolCalls?: Array<ToolCallResult>
47
56
  finishReason?: string
48
57
  usage: CompletionUsage
49
58
  usageAvailable: boolean
@@ -60,8 +69,33 @@ export interface StreamChunk {
60
69
  error?: string
61
70
  raw?: string
62
71
  }
72
+ export interface StreamDelta {
73
+ id: string
74
+ model: string
75
+ index: number
76
+ role?: string
77
+ content?: string
78
+ finishReason?: string
79
+ raw?: string
80
+ }
81
+ export interface StreamErrorEvent {
82
+ message: string
83
+ }
84
+ export interface StreamEvent {
85
+ eventType: string
86
+ delta?: StreamDelta
87
+ error?: StreamErrorEvent
88
+ }
63
89
  export declare class Client {
64
90
  constructor(provider: string)
65
91
  complete(model: string, promptOrMessages: string | MessageInput[], options?: CompleteOptions): Promise<unknown>
66
92
  stream(model: string, promptOrMessages: string | MessageInput[], onChunk: (chunk: StreamChunk) => void, options?: CompleteOptions): Promise<unknown>
93
+ streamEvents(model: string, promptOrMessages: string | MessageInput[], onEvent: (event: StreamEvent) => void, options?: CompleteOptions): Promise<unknown>
94
+ runEmailWorkflowYaml(workflowPath: string, emailText: string): any
95
+ runWorkflowYaml(workflowPath: string, workflowInput: { email_text?: string; messages?: MessageInput[]; [key: string]: unknown }): any
96
+ runWorkflowYamlWithEvents(workflowPath: string, workflowInput: { email_text?: string; messages?: MessageInput[]; [key: string]: unknown }, workflowOptions?: { telemetry?: Record<string, unknown>; trace?: Record<string, unknown> }): any
97
+ runEmailWorkflowYamlWithEvents(workflowPath: string, emailText: string, workflowOptions?: { telemetry?: Record<string, unknown>; trace?: Record<string, unknown> }): any
98
+ runWorkflowYamlStream(workflowPath: string, workflowInput: { email_text?: string; messages?: MessageInput[]; [key: string]: unknown }, onEvent: (eventJson: string) => void, workflowOptions?: { telemetry?: Record<string, unknown>; trace?: Record<string, unknown> }): Promise<any>
99
+ runEmailWorkflowYamlStream(workflowPath: string, emailText: string, onEvent: (eventJson: string) => void, workflowOptions?: { telemetry?: Record<string, unknown>; trace?: Record<string, unknown> }): Promise<any>
100
+ runWorkflowYamlWithOptions(workflowPath: string, workflowInput: { email_text?: string; messages?: MessageInput[]; [key: string]: unknown }, workflowOptions?: { telemetry?: Record<string, unknown>; trace?: Record<string, unknown> }): any
67
101
  }
package/index.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-agents-node",
3
- "version": "0.2.6",
3
+ "version": "0.2.17",
4
4
  "description": "Node.js bindings for SimpleAgents using napi-rs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -14,7 +14,10 @@
14
14
  "build": "napi build --release",
15
15
  "build:debug": "napi build",
16
16
  "pretest": "npm run build:debug",
17
- "test": "node --test test/*.test.js",
17
+ "test": "npm run test:unit && npm run test:contract",
18
+ "test:unit": "node --test test/unit.test.js",
19
+ "test:contract": "node --test test/contract.test.js",
20
+ "test:live": "node --test test/live.test.js",
18
21
  "prepublishOnly": "npm run build"
19
22
  },
20
23
  "engines": {