@flowy-agent-store/sdk 0.1.0-beta.2 → 0.1.0-beta.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/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ let node_readline = require("node:readline");
10
10
  let _flowy_agent_store_protocol = require("@flowy-agent-store/protocol");
11
11
  //#region src/bin.ts
12
12
  /**
13
- * Locate the `agent-store` runtime binary.
13
+ * Locate the `flowy-agent-store` runtime binary.
14
14
  *
15
15
  * Order (docs/agent-store/12 §6):
16
16
  * 1. explicit `bin` argument (skips every other lookup)
@@ -18,13 +18,13 @@ let _flowy_agent_store_protocol = require("@flowy-agent-store/protocol");
18
18
  * 3. platform runtime package (`@flowy-agent-store/runtime-<platform>-<arch>`,
19
19
  * an optionalDependency of `@flowy-agent-store/sdk`) resolved via
20
20
  * `createRequire(import.meta.url).resolve` — the binary ships inside the
21
- * package (`vendor/agent-store[.exe]`)
22
- * 4. `agent-store[.exe]` on `PATH`
21
+ * package (`vendor/flowy-agent-store[.exe]`)
22
+ * 4. `flowy-agent-store[.exe]` on `PATH`
23
23
  *
24
24
  * Anything else is a hard error — the SDK never downloads or guesses.
25
25
  */
26
26
  const VENDOR_DIR = "vendor";
27
- const BIN_NAMES = ["agent-store", "agent-store.exe"];
27
+ const BIN_NAMES = ["flowy-agent-store", "flowy-agent-store.exe"];
28
28
  function resolveAppServerBin(explicit) {
29
29
  if (explicit && (0, node_fs.existsSync)(explicit)) return explicit;
30
30
  const candidates = [];
@@ -38,7 +38,7 @@ function resolveAppServerBin(explicit) {
38
38
  if (found) candidates.push(found);
39
39
  }
40
40
  const hit = candidates.find((candidate) => (0, node_fs.existsSync)(candidate));
41
- if (!hit) throw new Error(`cannot find the agent-store runtime binary: pass \`bin\`, set AGENT_STORE_BIN, install @flowy-agent-store/runtime-${process.platform}-${process.arch} alongside @flowy-agent-store/sdk, or put agent-store[.exe] on PATH`);
41
+ if (!hit) throw new Error(`cannot find the flowy-agent-store runtime binary: pass \`bin\`, set AGENT_STORE_BIN, install @flowy-agent-store/runtime-${process.platform}-${process.arch} alongside @flowy-agent-store/sdk, or put flowy-agent-store[.exe] on PATH`);
42
42
  return hit;
43
43
  }
44
44
  /** Probe the platform runtime package for a vendored binary (optional dep). */
@@ -112,7 +112,7 @@ async function spawnAppServer(options = {}) {
112
112
  const ownedDir = options.dataDir === void 0;
113
113
  const dataDir = ownedDir ? await (0, node_fs_promises.mkdtemp)((0, node_path.join)((0, node_os.tmpdir)(), "agent-store-sdk-")) : options.dataDir;
114
114
  const port = options.port ?? 0;
115
- const child = (0, node_child_process.spawn)(bin, [
115
+ const { child, exited } = spawnRuntimeChild(bin, [
116
116
  "--host",
117
117
  "127.0.0.1",
118
118
  "--port",
@@ -121,14 +121,7 @@ async function spawnAppServer(options = {}) {
121
121
  dataDir,
122
122
  "--no-open",
123
123
  ...options.extraArgs ?? []
124
- ], {
125
- stdio: [
126
- "ignore",
127
- "pipe",
128
- "pipe"
129
- ],
130
- windowsHide: true
131
- });
124
+ ], options);
132
125
  const stderrTail = [];
133
126
  child.stderr?.on("data", (chunk) => {
134
127
  for (const line of String(chunk).split(/\r?\n/)) {
@@ -168,6 +161,7 @@ async function spawnAppServer(options = {}) {
168
161
  return {
169
162
  readiness,
170
163
  dataDir,
164
+ exited,
171
165
  close: async () => {
172
166
  if (closed) return;
173
167
  closed = true;
@@ -187,31 +181,77 @@ async function spawnAppServer(options = {}) {
187
181
  throw error;
188
182
  }
189
183
  }
184
+ /**
185
+ * Spawn the runtime process and start tracking its exit.
186
+ *
187
+ * Internal (not part of the package entry): exported so the lifecycle and
188
+ * `env` / `cwd` passthrough contract can be exercised with a synthetic child,
189
+ * which is what the managed CLI args normally make impossible to inject.
190
+ */
191
+ function spawnRuntimeChild(bin, args, options = {}) {
192
+ const child = (0, node_child_process.spawn)(bin, args, {
193
+ stdio: [
194
+ "ignore",
195
+ "pipe",
196
+ "pipe"
197
+ ],
198
+ windowsHide: true,
199
+ ...options.env ? { env: {
200
+ ...process.env,
201
+ ...options.env
202
+ } } : {},
203
+ ...options.cwd ? { cwd: options.cwd } : {}
204
+ });
205
+ return {
206
+ child,
207
+ exited: new Promise((resolve) => {
208
+ child.once("exit", (code, signal) => {
209
+ const info = {
210
+ code,
211
+ signal
212
+ };
213
+ resolve(info);
214
+ try {
215
+ options.onExit?.(info);
216
+ } catch {}
217
+ });
218
+ })
219
+ };
220
+ }
221
+ /** Internal: exported for the stdout-backpressure regression test only. */
190
222
  function waitForReadiness(child, timeoutMs) {
191
223
  return new Promise((resolve, reject) => {
192
224
  if (!child.stdout) {
193
225
  reject(/* @__PURE__ */ new Error("spawned runtime has no stdout pipe"));
194
226
  return;
195
227
  }
196
- const lines = (0, node_readline.createInterface)({ input: child.stdout });
197
- const timer = setTimeout(() => {
228
+ const stdout = child.stdout;
229
+ const lines = (0, node_readline.createInterface)({ input: stdout });
230
+ let settled = false;
231
+ const fail = (error) => {
232
+ if (settled) return;
233
+ settled = true;
198
234
  lines.close();
199
- reject(/* @__PURE__ */ new Error(`timed out after ${timeoutMs}ms waiting for the runtime readiness line`));
200
- }, timeoutMs);
201
- const done = (fn) => {
202
- clearTimeout(timer);
203
- lines.close();
204
- fn();
235
+ reject(error);
205
236
  };
237
+ const timer = setTimeout(() => {
238
+ fail(/* @__PURE__ */ new Error(`timed out after ${timeoutMs}ms waiting for the runtime readiness line`));
239
+ }, timeoutMs);
206
240
  lines.on("line", (line) => {
241
+ if (settled) return;
207
242
  const readiness = parseReadinessLine(line);
208
- if (readiness) done(() => resolve(readiness));
243
+ if (!readiness) return;
244
+ settled = true;
245
+ clearTimeout(timer);
246
+ lines.close();
247
+ stdout.resume();
248
+ resolve(readiness);
209
249
  });
210
250
  child.once("error", (error) => {
211
- done(() => reject(/* @__PURE__ */ new Error(`failed to spawn the runtime: ${error.message}`)));
251
+ fail(/* @__PURE__ */ new Error(`failed to spawn the runtime: ${error.message}`));
212
252
  });
213
253
  child.once("exit", (code) => {
214
- done(() => reject(/* @__PURE__ */ new Error(`runtime exited before reporting readiness (code ${code})`)));
254
+ fail(/* @__PURE__ */ new Error(`runtime exited before reporting readiness (code ${code})`));
215
255
  });
216
256
  });
217
257
  }
@@ -262,6 +302,7 @@ async function launchClient(options) {
262
302
  }
263
303
  }
264
304
  //#endregion
305
+ exports.assertProtocolCompatible = assertProtocolCompatible;
265
306
  exports.launchClient = launchClient;
266
307
  exports.parseReadinessLine = parseReadinessLine;
267
308
  exports.resolveAppServerBin = resolveAppServerBin;
package/dist/index.d.cts CHANGED
@@ -23,6 +23,8 @@ interface ReadinessInfo {
23
23
  export declare function parseReadinessLine(line: string): ReadinessInfo | null;
24
24
  //#endregion
25
25
  //#region src/spawn.d.ts
26
+ /** Fail when the runtime speaks a different wire protocol (§7 acceptance). */
27
+ export declare function assertProtocolCompatible(runtimeVersion: string): void;
26
28
  interface SpawnOptions {
27
29
  /** Explicit binary path (overrides `AGENT_STORE_BIN` / `PATH`). */
28
30
  bin?: string;
@@ -34,10 +36,29 @@ interface SpawnOptions {
34
36
  extraArgs?: string[];
35
37
  /** How long to wait for the readiness line. Defaults to 120s (cold DB init). */
36
38
  readyTimeoutMs?: number;
39
+ /** Extra environment variables, merged over the parent's `process.env`. */
40
+ env?: Record<string, string | undefined>;
41
+ /** Working directory for the child. Defaults to the parent's cwd. */
42
+ cwd?: string;
43
+ /** Called once when the child exits, for any reason (crash included). */
44
+ onExit?: (info: SpawnExitInfo) => void;
45
+ }
46
+ /** How a spawned runtime process ended. */
47
+ interface SpawnExitInfo {
48
+ /** Exit code, or `null` when the process was terminated by a signal. */
49
+ code: number | null;
50
+ /** Terminating signal, or `null` on a normal exit. */
51
+ signal: string | null;
37
52
  }
38
53
  interface SpawnedServer {
39
54
  readonly readiness: ReadinessInfo;
40
55
  readonly dataDir: string;
56
+ /**
57
+ * Settles when the runtime process exits — including an unexpected crash,
58
+ * which is otherwise indistinguishable from "still starting up". Never
59
+ * rejects: inspect `code` / `signal`.
60
+ */
61
+ readonly exited: Promise<SpawnExitInfo>;
41
62
  /** Terminate the child and remove the data dir when it was auto-created. */
42
63
  close(): Promise<void>;
43
64
  }
@@ -64,4 +85,4 @@ export interface LaunchedClient {
64
85
  */
65
86
  export declare function launchClient(options: LaunchOptions): Promise<LaunchedClient>;
66
87
  //#endregion
67
- export type { ReadinessInfo, SpawnOptions, SpawnedServer };
88
+ export type { ReadinessInfo, SpawnExitInfo, SpawnOptions, SpawnedServer };
package/dist/index.d.mts CHANGED
@@ -23,6 +23,8 @@ interface ReadinessInfo {
23
23
  export declare function parseReadinessLine(line: string): ReadinessInfo | null;
24
24
  //#endregion
25
25
  //#region src/spawn.d.ts
26
+ /** Fail when the runtime speaks a different wire protocol (§7 acceptance). */
27
+ export declare function assertProtocolCompatible(runtimeVersion: string): void;
26
28
  interface SpawnOptions {
27
29
  /** Explicit binary path (overrides `AGENT_STORE_BIN` / `PATH`). */
28
30
  bin?: string;
@@ -34,10 +36,29 @@ interface SpawnOptions {
34
36
  extraArgs?: string[];
35
37
  /** How long to wait for the readiness line. Defaults to 120s (cold DB init). */
36
38
  readyTimeoutMs?: number;
39
+ /** Extra environment variables, merged over the parent's `process.env`. */
40
+ env?: Record<string, string | undefined>;
41
+ /** Working directory for the child. Defaults to the parent's cwd. */
42
+ cwd?: string;
43
+ /** Called once when the child exits, for any reason (crash included). */
44
+ onExit?: (info: SpawnExitInfo) => void;
45
+ }
46
+ /** How a spawned runtime process ended. */
47
+ interface SpawnExitInfo {
48
+ /** Exit code, or `null` when the process was terminated by a signal. */
49
+ code: number | null;
50
+ /** Terminating signal, or `null` on a normal exit. */
51
+ signal: string | null;
37
52
  }
38
53
  interface SpawnedServer {
39
54
  readonly readiness: ReadinessInfo;
40
55
  readonly dataDir: string;
56
+ /**
57
+ * Settles when the runtime process exits — including an unexpected crash,
58
+ * which is otherwise indistinguishable from "still starting up". Never
59
+ * rejects: inspect `code` / `signal`.
60
+ */
61
+ readonly exited: Promise<SpawnExitInfo>;
41
62
  /** Terminate the child and remove the data dir when it was auto-created. */
42
63
  close(): Promise<void>;
43
64
  }
@@ -64,4 +85,4 @@ export interface LaunchedClient {
64
85
  */
65
86
  export declare function launchClient(options: LaunchOptions): Promise<LaunchedClient>;
66
87
  //#endregion
67
- export type { ReadinessInfo, SpawnOptions, SpawnedServer };
88
+ export type { ReadinessInfo, SpawnExitInfo, SpawnOptions, SpawnedServer };
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import { createInterface } from "node:readline";
9
9
  import { APP_SERVER_PROTOCOL_VERSION } from "@flowy-agent-store/protocol";
10
10
  //#region src/bin.ts
11
11
  /**
12
- * Locate the `agent-store` runtime binary.
12
+ * Locate the `flowy-agent-store` runtime binary.
13
13
  *
14
14
  * Order (docs/agent-store/12 §6):
15
15
  * 1. explicit `bin` argument (skips every other lookup)
@@ -17,13 +17,13 @@ import { APP_SERVER_PROTOCOL_VERSION } from "@flowy-agent-store/protocol";
17
17
  * 3. platform runtime package (`@flowy-agent-store/runtime-<platform>-<arch>`,
18
18
  * an optionalDependency of `@flowy-agent-store/sdk`) resolved via
19
19
  * `createRequire(import.meta.url).resolve` — the binary ships inside the
20
- * package (`vendor/agent-store[.exe]`)
21
- * 4. `agent-store[.exe]` on `PATH`
20
+ * package (`vendor/flowy-agent-store[.exe]`)
21
+ * 4. `flowy-agent-store[.exe]` on `PATH`
22
22
  *
23
23
  * Anything else is a hard error — the SDK never downloads or guesses.
24
24
  */
25
25
  const VENDOR_DIR = "vendor";
26
- const BIN_NAMES = ["agent-store", "agent-store.exe"];
26
+ const BIN_NAMES = ["flowy-agent-store", "flowy-agent-store.exe"];
27
27
  function resolveAppServerBin(explicit) {
28
28
  if (explicit && existsSync(explicit)) return explicit;
29
29
  const candidates = [];
@@ -37,7 +37,7 @@ function resolveAppServerBin(explicit) {
37
37
  if (found) candidates.push(found);
38
38
  }
39
39
  const hit = candidates.find((candidate) => existsSync(candidate));
40
- if (!hit) throw new Error(`cannot find the agent-store runtime binary: pass \`bin\`, set AGENT_STORE_BIN, install @flowy-agent-store/runtime-${process.platform}-${process.arch} alongside @flowy-agent-store/sdk, or put agent-store[.exe] on PATH`);
40
+ if (!hit) throw new Error(`cannot find the flowy-agent-store runtime binary: pass \`bin\`, set AGENT_STORE_BIN, install @flowy-agent-store/runtime-${process.platform}-${process.arch} alongside @flowy-agent-store/sdk, or put flowy-agent-store[.exe] on PATH`);
41
41
  return hit;
42
42
  }
43
43
  /** Probe the platform runtime package for a vendored binary (optional dep). */
@@ -111,7 +111,7 @@ async function spawnAppServer(options = {}) {
111
111
  const ownedDir = options.dataDir === void 0;
112
112
  const dataDir = ownedDir ? await mkdtemp(join(tmpdir(), "agent-store-sdk-")) : options.dataDir;
113
113
  const port = options.port ?? 0;
114
- const child = spawn(bin, [
114
+ const { child, exited } = spawnRuntimeChild(bin, [
115
115
  "--host",
116
116
  "127.0.0.1",
117
117
  "--port",
@@ -120,14 +120,7 @@ async function spawnAppServer(options = {}) {
120
120
  dataDir,
121
121
  "--no-open",
122
122
  ...options.extraArgs ?? []
123
- ], {
124
- stdio: [
125
- "ignore",
126
- "pipe",
127
- "pipe"
128
- ],
129
- windowsHide: true
130
- });
123
+ ], options);
131
124
  const stderrTail = [];
132
125
  child.stderr?.on("data", (chunk) => {
133
126
  for (const line of String(chunk).split(/\r?\n/)) {
@@ -167,6 +160,7 @@ async function spawnAppServer(options = {}) {
167
160
  return {
168
161
  readiness,
169
162
  dataDir,
163
+ exited,
170
164
  close: async () => {
171
165
  if (closed) return;
172
166
  closed = true;
@@ -186,31 +180,77 @@ async function spawnAppServer(options = {}) {
186
180
  throw error;
187
181
  }
188
182
  }
183
+ /**
184
+ * Spawn the runtime process and start tracking its exit.
185
+ *
186
+ * Internal (not part of the package entry): exported so the lifecycle and
187
+ * `env` / `cwd` passthrough contract can be exercised with a synthetic child,
188
+ * which is what the managed CLI args normally make impossible to inject.
189
+ */
190
+ function spawnRuntimeChild(bin, args, options = {}) {
191
+ const child = spawn(bin, args, {
192
+ stdio: [
193
+ "ignore",
194
+ "pipe",
195
+ "pipe"
196
+ ],
197
+ windowsHide: true,
198
+ ...options.env ? { env: {
199
+ ...process.env,
200
+ ...options.env
201
+ } } : {},
202
+ ...options.cwd ? { cwd: options.cwd } : {}
203
+ });
204
+ return {
205
+ child,
206
+ exited: new Promise((resolve) => {
207
+ child.once("exit", (code, signal) => {
208
+ const info = {
209
+ code,
210
+ signal
211
+ };
212
+ resolve(info);
213
+ try {
214
+ options.onExit?.(info);
215
+ } catch {}
216
+ });
217
+ })
218
+ };
219
+ }
220
+ /** Internal: exported for the stdout-backpressure regression test only. */
189
221
  function waitForReadiness(child, timeoutMs) {
190
222
  return new Promise((resolve, reject) => {
191
223
  if (!child.stdout) {
192
224
  reject(/* @__PURE__ */ new Error("spawned runtime has no stdout pipe"));
193
225
  return;
194
226
  }
195
- const lines = createInterface({ input: child.stdout });
196
- const timer = setTimeout(() => {
227
+ const stdout = child.stdout;
228
+ const lines = createInterface({ input: stdout });
229
+ let settled = false;
230
+ const fail = (error) => {
231
+ if (settled) return;
232
+ settled = true;
197
233
  lines.close();
198
- reject(/* @__PURE__ */ new Error(`timed out after ${timeoutMs}ms waiting for the runtime readiness line`));
199
- }, timeoutMs);
200
- const done = (fn) => {
201
- clearTimeout(timer);
202
- lines.close();
203
- fn();
234
+ reject(error);
204
235
  };
236
+ const timer = setTimeout(() => {
237
+ fail(/* @__PURE__ */ new Error(`timed out after ${timeoutMs}ms waiting for the runtime readiness line`));
238
+ }, timeoutMs);
205
239
  lines.on("line", (line) => {
240
+ if (settled) return;
206
241
  const readiness = parseReadinessLine(line);
207
- if (readiness) done(() => resolve(readiness));
242
+ if (!readiness) return;
243
+ settled = true;
244
+ clearTimeout(timer);
245
+ lines.close();
246
+ stdout.resume();
247
+ resolve(readiness);
208
248
  });
209
249
  child.once("error", (error) => {
210
- done(() => reject(/* @__PURE__ */ new Error(`failed to spawn the runtime: ${error.message}`)));
250
+ fail(/* @__PURE__ */ new Error(`failed to spawn the runtime: ${error.message}`));
211
251
  });
212
252
  child.once("exit", (code) => {
213
- done(() => reject(/* @__PURE__ */ new Error(`runtime exited before reporting readiness (code ${code})`)));
253
+ fail(/* @__PURE__ */ new Error(`runtime exited before reporting readiness (code ${code})`));
214
254
  });
215
255
  });
216
256
  }
@@ -261,4 +301,4 @@ async function launchClient(options) {
261
301
  }
262
302
  }
263
303
  //#endregion
264
- export { launchClient, parseReadinessLine, resolveAppServerBin, spawnAppServer };
304
+ export { assertProtocolCompatible, launchClient, parseReadinessLine, resolveAppServerBin, spawnAppServer };
package/package.json CHANGED
@@ -1,40 +1,49 @@
1
- {
2
- "name": "@flowy-agent-store/sdk",
3
- "version": "0.1.0-beta.2",
4
- "description": "Node.js host for the Agent Store App Server: spawn the runtime binary and connect over loopback (docs/agent-store/12 P1-3)",
5
- "type": "module",
6
- "license": "Apache-2.0",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.mts",
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs"
12
- },
13
- "./package.json": "./package.json"
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "dependencies": {
19
- "@flowy-agent-store/client": "0.1.0-beta.2",
20
- "@flowy-agent-store/protocol": "0.1.0-beta.2"
21
- },
22
- "scripts": {
23
- "build": "tsdown",
24
- "prepack": "tsdown"
25
- },
26
- "publishConfig": {
27
- "access": "public",
28
- "registry": "https://registry.npmjs.org/"
29
- },
30
- "main": "./dist/index.cjs",
31
- "module": "./dist/index.mjs",
32
- "types": "./dist/index.d.mts",
33
- "optionalDependencies": {
34
- "@flowy-agent-store/runtime-win32-x64": "0.1.0-beta.2",
35
- "@flowy-agent-store/runtime-linux-x64": "0.1.0-beta.2",
36
- "@flowy-agent-store/runtime-linux-arm64": "0.1.0-beta.2",
37
- "@flowy-agent-store/runtime-darwin-x64": "0.1.0-beta.2",
38
- "@flowy-agent-store/runtime-darwin-arm64": "0.1.0-beta.2"
39
- }
40
- }
1
+ {
2
+ "name": "@flowy-agent-store/sdk",
3
+ "version": "0.1.0-beta.3",
4
+ "description": "Node.js host for the Agent Store App Server: spawn the runtime binary and connect over loopback (docs/agent-store/12 P1-3)",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "engines": {
8
+ "node": ">=22"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Michael-Lfx/allo.git",
13
+ "directory": "web/packages/sdk"
14
+ },
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "dependencies": {
28
+ "@flowy-agent-store/client": "0.1.0-beta.3",
29
+ "@flowy-agent-store/protocol": "0.1.0-beta.3"
30
+ },
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "prepack": "tsdown"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "registry": "https://registry.npmjs.org/"
38
+ },
39
+ "main": "./dist/index.cjs",
40
+ "module": "./dist/index.mjs",
41
+ "types": "./dist/index.d.mts",
42
+ "optionalDependencies": {
43
+ "@flowy-agent-store/runtime-win32-x64": "0.1.0-beta.3",
44
+ "@flowy-agent-store/runtime-linux-x64": "0.1.0-beta.3",
45
+ "@flowy-agent-store/runtime-linux-arm64": "0.1.0-beta.3",
46
+ "@flowy-agent-store/runtime-darwin-x64": "0.1.0-beta.3",
47
+ "@flowy-agent-store/runtime-darwin-arm64": "0.1.0-beta.3"
48
+ }
49
+ }