simple-agents-node 0.2.2

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 ADDED
@@ -0,0 +1,66 @@
1
+ # simple-agents-napi
2
+
3
+ Node.js bindings for SimpleAgents using napi-rs.
4
+
5
+ ## Build
6
+
7
+ ```sh
8
+ npm install
9
+ npm run build
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```javascript
15
+ const { Client } = require('./index.js');
16
+
17
+ const client = new Client('openai');
18
+
19
+ async function main() {
20
+ const response = await client.complete(
21
+ 'gpt-4',
22
+ [
23
+ { role: 'system', content: 'You are concise.' },
24
+ { role: 'user', content: 'Say hi from Node.' },
25
+ ],
26
+ { max_tokens: 64, temperature: 0.7 },
27
+ );
28
+
29
+ console.log(response.content);
30
+ console.log(response.usage);
31
+ console.log(response.healed); // present when using healed_json/schema mode
32
+
33
+ // Streaming
34
+ const streamed = await client.stream(
35
+ 'gpt-4',
36
+ 'Say hello in two words.',
37
+ {},
38
+ (chunk) => {
39
+ if (chunk.content) process.stdout.write(chunk.content);
40
+ if (chunk.finish_reason) console.log('\nfinish:', chunk.finish_reason);
41
+ },
42
+ );
43
+ console.log('streamed content:', streamed.content);
44
+
45
+ // Healed JSON
46
+ const healed = await client.complete(
47
+ 'gpt-4',
48
+ 'Respond with JSON: {"message": "hello"}',
49
+ { mode: 'healed_json' },
50
+ );
51
+ console.log('parsed JSON value:', healed.healed?.value);
52
+ }
53
+
54
+ main().catch((err) => {
55
+ console.error(err);
56
+ process.exit(1);
57
+ });
58
+ ```
59
+
60
+ ## Notes
61
+
62
+ - Canonical env contract for examples/tests is: `CUSTOM_API_BASE`, `CUSTOM_API_KEY`, `CUSTOM_API_MODEL`, `PROVIDER`.
63
+ - For OpenAI provider compatibility, map `CUSTOM_API_*` to `OPENAI_API_*` when needed (`OPENAI_API_KEY`, `OPENAI_API_BASE`, `OPENAI_MODEL`).
64
+ - `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.
65
+ - `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).
66
+ - Set `CUSTOM_API_BASE`, `CUSTOM_API_KEY`, `CUSTOM_API_MODEL`, and `PROVIDER` to run tests/examples consistently across bindings.
package/index.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export interface CompleteOptions {
7
+ maxTokens?: number
8
+ temperature?: number
9
+ topP?: number
10
+ stream?: boolean
11
+ /** "standard" | "healed_json" | "schema" */
12
+ mode?: string
13
+ schema?: Schema
14
+ }
15
+ export interface MessageInput {
16
+ role: string
17
+ content: string
18
+ name?: string
19
+ toolCallId?: string
20
+ toolCalls?: Array<JsToolCall>
21
+ }
22
+ export interface JsToolCallFunction {
23
+ name: string
24
+ arguments: string
25
+ }
26
+ export interface JsToolCall {
27
+ id: string
28
+ toolType: string
29
+ function: JsToolCallFunction
30
+ }
31
+ export interface CompletionUsage {
32
+ promptTokens: number
33
+ completionTokens: number
34
+ totalTokens: number
35
+ }
36
+ export interface HealingData {
37
+ value?: unknown
38
+ flags: Array<string>
39
+ confidence: number
40
+ }
41
+ export interface CompletionResult {
42
+ id: string
43
+ model: string
44
+ role: string
45
+ content?: string
46
+ toolCalls?: Array<JsToolCall>
47
+ finishReason?: string
48
+ usage: CompletionUsage
49
+ latencyMs: number
50
+ raw?: string
51
+ healed?: HealingData
52
+ coerced?: HealingData
53
+ }
54
+ export interface StreamChunk {
55
+ id: string
56
+ model: string
57
+ content?: string
58
+ finishReason?: string
59
+ error?: string
60
+ raw?: string
61
+ }
62
+ export declare class Client {
63
+ constructor(provider: string)
64
+ complete(model: string, promptOrMessages: string | MessageInput[], options?: CompleteOptions): Promise<unknown>
65
+ stream(model: string, promptOrMessages: string | MessageInput[], options?: CompleteOptions, onChunk: (chunk: StreamChunk) => void): Promise<unknown>
66
+ }
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ // Load the native addon built by napi-rs.
4
+ const native = require("./index.node");
5
+
6
+ module.exports = native;
7
+ module.exports.default = native;
package/index.node ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "simple-agents-node",
3
+ "version": "0.2.2",
4
+ "description": "Node.js bindings for SimpleAgents using napi-rs",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "index.js",
9
+ "index.d.ts",
10
+ "README.md",
11
+ "index.node"
12
+ ],
13
+ "scripts": {
14
+ "build": "napi build --release",
15
+ "build:debug": "napi build",
16
+ "pretest": "npm run build:debug",
17
+ "test": "node --test test/*.test.js",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "napi": {
24
+ "name": "index"
25
+ },
26
+ "devDependencies": {
27
+ "@napi-rs/cli": "^2.16.0",
28
+ "typescript": "^5.4.0"
29
+ }
30
+ }