@synadia-ai/agent-fabric 0.0.0-stage → 0.2.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.
@@ -0,0 +1,33 @@
1
+ // An agent may ask a question before it answers. onQuery answers it: here
2
+ // from the terminal, one line per question.
3
+ //
4
+ // NATS_URL=<the URL the console showed> NATS_CREDS=./my.creds node answer-questions.mjs writer "Write me a poem."
5
+ //
6
+ // Install first: npm install @synadia-ai/agent-fabric
7
+
8
+ import { createInterface } from "node:readline";
9
+ import { fabricCallerFromEnv } from "@synadia-ai/agent-fabric";
10
+
11
+ const [who, ...words] = process.argv.slice(2);
12
+ if (who === undefined || words.length === 0) {
13
+ console.error('usage: node answer-questions.mjs <address or kind> "<text>"');
14
+ process.exit(2);
15
+ }
16
+
17
+ // One line per answer, read as it comes: stdin may be a terminal or a pipe.
18
+ const terminal = createInterface({ input: process.stdin });
19
+ const lines = terminal[Symbol.asyncIterator]();
20
+ const caller = await fabricCallerFromEnv();
21
+ try {
22
+ const { text } = await caller.ask(who, words.join(" "), {
23
+ onQuery: async (query) => {
24
+ process.stderr.write(`${query.prompt}\n> `);
25
+ const next = await lines.next();
26
+ return next.done ? "" : next.value;
27
+ },
28
+ });
29
+ console.log(text);
30
+ } finally {
31
+ terminal.close();
32
+ await caller.close();
33
+ }
@@ -0,0 +1,22 @@
1
+ // A reply as a string, for a script: ask() waits for the whole reply and
2
+ // returns it with the task's root id.
3
+ //
4
+ // NATS_URL=<the URL the console showed> NATS_CREDS=./my.creds node ask.mjs writer "Name three rivers."
5
+ //
6
+ // Install first: npm install @synadia-ai/agent-fabric
7
+
8
+ import { fabricCallerFromEnv } from "@synadia-ai/agent-fabric";
9
+
10
+ const [who, ...words] = process.argv.slice(2);
11
+ if (who === undefined || words.length === 0) {
12
+ console.error('usage: node ask.mjs <address or kind> "<text>"');
13
+ process.exit(2);
14
+ }
15
+
16
+ const caller = await fabricCallerFromEnv();
17
+ try {
18
+ const { text, rootId } = await caller.ask(who, words.join(" "));
19
+ console.log(JSON.stringify({ root: rootId, words: text.split(/\s+/).length, text }));
20
+ } finally {
21
+ await caller.close();
22
+ }
@@ -0,0 +1,28 @@
1
+ // A list of topics, prompted one after another on an interval: each prompt
2
+ // a task of its own, its root id printed with the topic.
3
+ //
4
+ // NATS_URL=<the URL the console showed> NATS_CREDS=./my.creds node every.mjs writer 60 "the sea" "the moon"
5
+ //
6
+ // Install first: npm install @synadia-ai/agent-fabric
7
+
8
+ import { setTimeout as sleep } from "node:timers/promises";
9
+ import { fabricCallerFromEnv } from "@synadia-ai/agent-fabric";
10
+
11
+ const [who, seconds, ...topics] = process.argv.slice(2);
12
+ if (who === undefined || !(Number(seconds) > 0) || topics.length === 0) {
13
+ console.error('usage: node every.mjs <address or kind> <seconds> "<topic>" ...');
14
+ process.exit(2);
15
+ }
16
+
17
+ const caller = await fabricCallerFromEnv();
18
+ process.on("SIGINT", () => void caller.close().then(() => process.exit(0)));
19
+ for (let i = 0; ; i++) {
20
+ const topic = topics[i % topics.length];
21
+ try {
22
+ const { text, rootId } = await caller.ask(who, `Write two lines about ${topic}.`);
23
+ console.log(`[${topic}] root ${rootId}\n${text}\n`);
24
+ } catch (err) {
25
+ console.error(`[${topic}] no reply: ${err.message}`);
26
+ }
27
+ await sleep(Number(seconds) * 1000);
28
+ }
@@ -0,0 +1,21 @@
1
+ // The agents your creds file can reach: address, kind, and whether the
2
+ // agent's identity is verified.
3
+ //
4
+ // NATS_URL=<the URL the console showed> NATS_CREDS=./my.creds node list-agents.mjs
5
+ //
6
+ // Install first: npm install @synadia-ai/agent-fabric
7
+
8
+ import { fabricCallerFromEnv } from "@synadia-ai/agent-fabric";
9
+
10
+ const caller = await fabricCallerFromEnv();
11
+ try {
12
+ for (const agent of await caller.list()) {
13
+ const identity =
14
+ agent.identity === undefined ? "agent identity: none" : `agent ${agent.identity}`;
15
+ console.log(
16
+ `${agent.promptSubject}\t${agent.agent}\t${identity}${agent.idSigVerified ? ", verified" : ""}`,
17
+ );
18
+ }
19
+ } finally {
20
+ await caller.close();
21
+ }
@@ -0,0 +1,25 @@
1
+ // One prompt: the reply streamed as it comes, then the root id of the task
2
+ // it started, which is how the console finds that task.
3
+ //
4
+ // NATS_URL=<the URL the console showed> NATS_CREDS=./my.creds node prompt.mjs writer "Say hello."
5
+ //
6
+ // Install first: npm install @synadia-ai/agent-fabric
7
+
8
+ import { fabricCallerFromEnv } from "@synadia-ai/agent-fabric";
9
+
10
+ const [who, ...words] = process.argv.slice(2);
11
+ if (who === undefined || words.length === 0) {
12
+ console.error('usage: node prompt.mjs <address or kind> "<text>"');
13
+ process.exit(2);
14
+ }
15
+
16
+ const caller = await fabricCallerFromEnv();
17
+ try {
18
+ const { stream, rootId } = await caller.prompt(who, words.join(" "));
19
+ for await (const msg of stream) {
20
+ if (msg.type === "response") process.stdout.write(msg.text);
21
+ }
22
+ console.log(`\nroot ${await rootId}`);
23
+ } finally {
24
+ await caller.close();
25
+ }
package/package.json CHANGED
@@ -1,6 +1,89 @@
1
1
  {
2
2
  "name": "@synadia-ai/agent-fabric",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "The SDK for agents on the Synadia Agent Fabric — tracing and the agent tools' ScratchPad extension, on the hooks of the Synadia Agent Protocol SDK.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "agent-fabric": "./dist/cli.js"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "examples",
24
+ "README.md",
25
+ "CHANGELOG.md",
26
+ "LICENSE",
27
+ "THIRD_PARTY_NOTICES"
28
+ ],
29
+ "sideEffects": false,
30
+ "engines": {
31
+ "node": ">=20.0.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "typecheck": "tsc --noEmit",
36
+ "lint": "eslint .",
37
+ "lint:fix": "eslint . --fix",
38
+ "format": "prettier --write .",
39
+ "format:check": "prettier --check .",
40
+ "test": "vitest run",
41
+ "test:unit": "vitest run test/unit",
42
+ "test:integration": "vitest run test/integration",
43
+ "test:watch": "vitest",
44
+ "check": "npm run typecheck && npm run lint && npm run format:check && npm run test",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "keywords": [
48
+ "nats",
49
+ "ai",
50
+ "agents",
51
+ "agent-fabric",
52
+ "tracing",
53
+ "scratchpad",
54
+ "synadia",
55
+ "sdk"
56
+ ],
57
+ "license": "Apache-2.0",
58
+ "author": "Synadia Communications",
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "git+https://github.com/synadia-ai/agent-fabric-sdk.git",
62
+ "directory": "typescript"
63
+ },
64
+ "homepage": "https://github.com/synadia-ai/agent-fabric-sdk/tree/main/typescript",
65
+ "bugs": {
66
+ "url": "https://github.com/synadia-ai/agent-fabric-sdk/issues"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public"
70
+ },
71
+ "dependencies": {
72
+ "@nats-io/nats-core": "^3.4.0",
73
+ "@nats-io/transport-node": "^3.4.0",
74
+ "@synadia-ai/agent-service": "^0.6.0",
75
+ "@synadia-ai/agents": "^0.6.0"
76
+ },
77
+ "devDependencies": {
78
+ "@unicode/unicode-15.0.0": "2.0.7",
79
+ "@types/node": "^22.0.0",
80
+ "ajv": "^8.17.0",
81
+ "eslint": "^9.0.0",
82
+ "eslint-config-prettier": "^9.1.0",
83
+ "prettier": "3.9.5",
84
+ "tsup": "^8.3.0",
85
+ "typescript": "~5.6.0",
86
+ "typescript-eslint": "^8.10.0",
87
+ "vitest": "^3.2.0"
88
+ }
89
+ }