electric-ax 0.2.1 → 0.2.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.
@@ -1,4 +1,4 @@
1
- import { ElectricCliEnv } from "./index-cwCTPq6Y.cjs";
1
+ import { ElectricCliEnv } from "./index-OgX1QS9Q.cjs";
2
2
 
3
3
  //#region src/completions.d.ts
4
4
  declare function fetchEntityTypeNames(env: ElectricCliEnv): Promise<Array<string>>;
@@ -1,4 +1,4 @@
1
- import { ElectricCliEnv } from "./index-BSHO_Rei.js";
1
+ import { ElectricCliEnv } from "./index-CwRI9tWl.js";
2
2
 
3
3
  //#region src/completions.d.ts
4
4
  declare function fetchEntityTypeNames(env: ElectricCliEnv): Promise<Array<string>>;
@@ -34,7 +34,7 @@ declare function getStartedEnvironmentMessage(started: StartedDevEnvironment): s
34
34
  declare function getStoppedEnvironmentMessage(stopped: StoppedDevEnvironment): string;
35
35
  declare function getStartedBuiltinAgentsMessage(started: StartedBuiltinAgentsEnvironment): string;
36
36
  declare function resolvePullWakeRunnerId(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
37
- declare function resolvePullWakeOwnerId(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
37
+ declare function resolvePullWakeOwnerPrincipal(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
38
38
  declare function resolveComposeProjectName(_cwd?: string, env?: NodeJS.ProcessEnv): string;
39
39
  declare function waitForElectricAgentsServer(baseUrl: string, options?: WaitForServerOptions): Promise<void>;
40
40
  declare function startElectricAgentsDevEnvironment(_options?: StartCommandOptions, env?: NodeJS.ProcessEnv, cwd?: string): Promise<StartedDevEnvironment>;
@@ -125,4 +125,4 @@ declare function createElectricProgram({
125
125
  declare function run(argv?: Array<string>): Promise<void>;
126
126
 
127
127
  //#endregion
128
- export { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveCommandPrefix, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, run, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
128
+ export { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveCommandPrefix, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, run, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
@@ -34,7 +34,7 @@ declare function getStartedEnvironmentMessage(started: StartedDevEnvironment): s
34
34
  declare function getStoppedEnvironmentMessage(stopped: StoppedDevEnvironment): string;
35
35
  declare function getStartedBuiltinAgentsMessage(started: StartedBuiltinAgentsEnvironment): string;
36
36
  declare function resolvePullWakeRunnerId(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
37
- declare function resolvePullWakeOwnerId(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
37
+ declare function resolvePullWakeOwnerPrincipal(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
38
38
  declare function resolveComposeProjectName(_cwd?: string, env?: NodeJS.ProcessEnv): string;
39
39
  declare function waitForElectricAgentsServer(baseUrl: string, options?: WaitForServerOptions): Promise<void>;
40
40
  declare function startElectricAgentsDevEnvironment(_options?: StartCommandOptions, env?: NodeJS.ProcessEnv, cwd?: string): Promise<StartedDevEnvironment>;
@@ -125,4 +125,4 @@ declare function createElectricProgram({
125
125
  declare function run(argv?: Array<string>): Promise<void>;
126
126
 
127
127
  //#endregion
128
- export { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveCommandPrefix, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, run, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
128
+ export { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveCommandPrefix, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, run, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
package/dist/index.cjs CHANGED
@@ -11,6 +11,7 @@ const node_path = require_chunk.__toESM(require("node:path"));
11
11
  const node_url = require_chunk.__toESM(require("node:url"));
12
12
  const commander = require_chunk.__toESM(require("commander"));
13
13
  const node_readline_promises = require_chunk.__toESM(require("node:readline/promises"));
14
+ const __electric_ax_agents_server_headers = require_chunk.__toESM(require("@electric-ax/agents/server-headers"));
14
15
 
15
16
  //#region src/prompt-api-key.ts
16
17
  const FRIENDLY_INTRO = `\n${[
@@ -162,17 +163,20 @@ function parseElectricAgentsHeaders(raw) {
162
163
  }
163
164
  function getElectricCliEnv(env = process.env) {
164
165
  const explicitIdentity = env.ELECTRIC_AGENTS_IDENTITY?.trim();
166
+ const headers = parseElectricAgentsHeaders(env.ELECTRIC_AGENTS_SERVER_HEADERS);
165
167
  return {
166
168
  electricAgentsUrl: env.ELECTRIC_AGENTS_URL || DEFAULT_ELECTRIC_AGENTS_URL,
167
169
  electricAgentsIdentity: explicitIdentity || getDefaultElectricAgentsIdentity(),
168
- electricAgentsHeaders: parseElectricAgentsHeaders(env.ELECTRIC_AGENTS_SERVER_HEADERS)
170
+ electricAgentsHeaders: (0, __electric_ax_agents_server_headers.mergeElectricPrincipalHeader)(headers, env.ELECTRIC_AGENTS_PRINCIPAL)
169
171
  };
170
172
  }
171
173
  function getErrorMessage(error) {
172
- return error instanceof Error ? error.message : String(error);
174
+ if (error instanceof Error) return error.message || error.name || `Unknown error`;
175
+ const message = String(error);
176
+ return message || `Unknown error`;
173
177
  }
174
178
  function fail(message) {
175
- throw new CliError(message);
179
+ throw new CliError(message || `Unknown error`);
176
180
  }
177
181
  function relativeTime(epochMs) {
178
182
  const seconds = Math.floor((Date.now() - epochMs) / 1e3);
@@ -310,17 +314,36 @@ async function parseJsonResponse(res) {
310
314
  return JSON.parse(text);
311
315
  } catch (error) {
312
316
  if (!(error instanceof SyntaxError)) throw error;
313
- return { error: { message: text || res.statusText } };
317
+ return { error: { message: text || fallbackResponseMessage(res) } };
314
318
  }
315
319
  }
320
+ function fallbackResponseMessage(res) {
321
+ const status = res.status ? `HTTP ${res.status}` : `HTTP error`;
322
+ return res.statusText ? `${status}: ${res.statusText}` : status;
323
+ }
324
+ function stringMessage(value) {
325
+ if (typeof value !== `string`) return void 0;
326
+ const trimmed = value.trim();
327
+ if (trimmed.length === 0) return void 0;
328
+ return trimmed;
329
+ }
330
+ function errorMessageFromValue(value) {
331
+ const direct = stringMessage(value);
332
+ if (direct) return direct;
333
+ if (!value || typeof value !== `object` || Array.isArray(value)) return void 0;
334
+ const record = value;
335
+ return errorMessageFromValue(record.message) ?? errorMessageFromValue(record.error) ?? errorMessageFromValue(record.reason) ?? errorMessageFromValue(record.detail);
336
+ }
337
+ function responseErrorMessage(data, res) {
338
+ return errorMessageFromValue(data) ?? fallbackResponseMessage(res);
339
+ }
316
340
  function failFromResponse(data, res) {
317
- const err = data.error;
318
- fail(String(err?.message ?? res.statusText));
341
+ fail(responseErrorMessage(data, res));
319
342
  }
320
343
  async function fetchEntityTypes(env) {
321
344
  const res = await electricAgentsFetch(env, `/_electric/entity-types`);
322
- const data = await res.json();
323
- if (!res.ok) fail(typeof data === `object` && data !== null ? String(data.error?.message ?? res.statusText) : res.statusText);
345
+ const data = await parseJsonResponse(res);
346
+ if (!res.ok) failFromResponse(data, res);
324
347
  if (!Array.isArray(data)) fail(`Unexpected response from server when listing entity types`);
325
348
  return data;
326
349
  }
@@ -345,8 +368,8 @@ async function fetchEntities(env, options = {}) {
345
368
  if (options.parent) searchParams.set(`parent`, options.parent);
346
369
  const suffix = searchParams.size > 0 ? `?${searchParams.toString()}` : ``;
347
370
  const res = await electricAgentsFetch(env, `/_electric/entities${suffix}`);
348
- const data = await res.json();
349
- if (!res.ok) fail(typeof data === `object` && data !== null ? String(data.error?.message ?? res.statusText) : res.statusText);
371
+ const data = await parseJsonResponse(res);
372
+ if (!res.ok) failFromResponse(data, res);
350
373
  if (!Array.isArray(data)) fail(`Unexpected response from server when listing entities`);
351
374
  return data;
352
375
  }
@@ -525,6 +548,8 @@ function getHelpText(commandName) {
525
548
  Environment:
526
549
  ELECTRIC_AGENTS_URL Base URL of the server (default: ${DEFAULT_ELECTRIC_AGENTS_URL})
527
550
  ELECTRIC_AGENTS_IDENTITY Sender identity for messages (default: ${getDefaultElectricAgentsIdentity()})
551
+ ELECTRIC_AGENTS_PRINCIPAL Optional principal key sent as the Electric-Principal header
552
+ ELECTRIC_AGENTS_SERVER_HEADERS Optional JSON object of additional server headers
528
553
  ANTHROPIC_API_KEY Required for '${agentsCommand} start-builtin' and '${agentsCommand} quickstart'
529
554
 
530
555
  Examples:
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, resolveCommandPrefix, run } from "./index-cwCTPq6Y.cjs";
2
+ import { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, resolveCommandPrefix, run } from "./index-OgX1QS9Q.cjs";
3
3
  export { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, resolveCommandPrefix, run };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, resolveCommandPrefix, run } from "./index-BSHO_Rei.js";
2
+ import { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, resolveCommandPrefix, run } from "./index-CwRI9tWl.js";
3
3
  export { DEFAULT_ELECTRIC_AGENTS_URL, ElectricCliEnv, ElectricCliHandlers, ObserveCommandOptions, PsCommandOptions, SendCommandOptions, SpawnCommandOptions, StartBuiltinCommandOptions, StartCommandOptions, StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StopCommandOptions, StoppedDevEnvironment, createElectricCliHandlers, createElectricProgram, formatQuickstartBackendStartedMessage, getElectricCliEnv, resolveCommandPrefix, run };
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import { basename, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { Command } from "commander";
11
11
  import { createInterface } from "node:readline/promises";
12
+ import { mergeElectricPrincipalHeader } from "@electric-ax/agents/server-headers";
12
13
 
13
14
  //#region src/prompt-api-key.ts
14
15
  const FRIENDLY_INTRO = `\n${[
@@ -160,17 +161,20 @@ function parseElectricAgentsHeaders(raw) {
160
161
  }
161
162
  function getElectricCliEnv(env = process.env) {
162
163
  const explicitIdentity = env.ELECTRIC_AGENTS_IDENTITY?.trim();
164
+ const headers = parseElectricAgentsHeaders(env.ELECTRIC_AGENTS_SERVER_HEADERS);
163
165
  return {
164
166
  electricAgentsUrl: env.ELECTRIC_AGENTS_URL || DEFAULT_ELECTRIC_AGENTS_URL,
165
167
  electricAgentsIdentity: explicitIdentity || getDefaultElectricAgentsIdentity(),
166
- electricAgentsHeaders: parseElectricAgentsHeaders(env.ELECTRIC_AGENTS_SERVER_HEADERS)
168
+ electricAgentsHeaders: mergeElectricPrincipalHeader(headers, env.ELECTRIC_AGENTS_PRINCIPAL)
167
169
  };
168
170
  }
169
171
  function getErrorMessage(error) {
170
- return error instanceof Error ? error.message : String(error);
172
+ if (error instanceof Error) return error.message || error.name || `Unknown error`;
173
+ const message = String(error);
174
+ return message || `Unknown error`;
171
175
  }
172
176
  function fail(message) {
173
- throw new CliError(message);
177
+ throw new CliError(message || `Unknown error`);
174
178
  }
175
179
  function relativeTime(epochMs) {
176
180
  const seconds = Math.floor((Date.now() - epochMs) / 1e3);
@@ -308,17 +312,36 @@ async function parseJsonResponse(res) {
308
312
  return JSON.parse(text);
309
313
  } catch (error) {
310
314
  if (!(error instanceof SyntaxError)) throw error;
311
- return { error: { message: text || res.statusText } };
315
+ return { error: { message: text || fallbackResponseMessage(res) } };
312
316
  }
313
317
  }
318
+ function fallbackResponseMessage(res) {
319
+ const status = res.status ? `HTTP ${res.status}` : `HTTP error`;
320
+ return res.statusText ? `${status}: ${res.statusText}` : status;
321
+ }
322
+ function stringMessage(value) {
323
+ if (typeof value !== `string`) return void 0;
324
+ const trimmed = value.trim();
325
+ if (trimmed.length === 0) return void 0;
326
+ return trimmed;
327
+ }
328
+ function errorMessageFromValue(value) {
329
+ const direct = stringMessage(value);
330
+ if (direct) return direct;
331
+ if (!value || typeof value !== `object` || Array.isArray(value)) return void 0;
332
+ const record = value;
333
+ return errorMessageFromValue(record.message) ?? errorMessageFromValue(record.error) ?? errorMessageFromValue(record.reason) ?? errorMessageFromValue(record.detail);
334
+ }
335
+ function responseErrorMessage(data, res) {
336
+ return errorMessageFromValue(data) ?? fallbackResponseMessage(res);
337
+ }
314
338
  function failFromResponse(data, res) {
315
- const err = data.error;
316
- fail(String(err?.message ?? res.statusText));
339
+ fail(responseErrorMessage(data, res));
317
340
  }
318
341
  async function fetchEntityTypes(env) {
319
342
  const res = await electricAgentsFetch(env, `/_electric/entity-types`);
320
- const data = await res.json();
321
- if (!res.ok) fail(typeof data === `object` && data !== null ? String(data.error?.message ?? res.statusText) : res.statusText);
343
+ const data = await parseJsonResponse(res);
344
+ if (!res.ok) failFromResponse(data, res);
322
345
  if (!Array.isArray(data)) fail(`Unexpected response from server when listing entity types`);
323
346
  return data;
324
347
  }
@@ -343,8 +366,8 @@ async function fetchEntities(env, options = {}) {
343
366
  if (options.parent) searchParams.set(`parent`, options.parent);
344
367
  const suffix = searchParams.size > 0 ? `?${searchParams.toString()}` : ``;
345
368
  const res = await electricAgentsFetch(env, `/_electric/entities${suffix}`);
346
- const data = await res.json();
347
- if (!res.ok) fail(typeof data === `object` && data !== null ? String(data.error?.message ?? res.statusText) : res.statusText);
369
+ const data = await parseJsonResponse(res);
370
+ if (!res.ok) failFromResponse(data, res);
348
371
  if (!Array.isArray(data)) fail(`Unexpected response from server when listing entities`);
349
372
  return data;
350
373
  }
@@ -523,6 +546,8 @@ function getHelpText(commandName) {
523
546
  Environment:
524
547
  ELECTRIC_AGENTS_URL Base URL of the server (default: ${DEFAULT_ELECTRIC_AGENTS_URL})
525
548
  ELECTRIC_AGENTS_IDENTITY Sender identity for messages (default: ${getDefaultElectricAgentsIdentity()})
549
+ ELECTRIC_AGENTS_PRINCIPAL Optional principal key sent as the Electric-Principal header
550
+ ELECTRIC_AGENTS_SERVER_HEADERS Optional JSON object of additional server headers
526
551
  ANTHROPIC_API_KEY Required for '${agentsCommand} start-builtin' and '${agentsCommand} quickstart'
527
552
 
528
553
  Examples:
package/dist/start.cjs CHANGED
@@ -3,6 +3,7 @@ const require_chunk = require('./chunk-BCwAaXi7.cjs');
3
3
  const require_env = require('./env-CFKgT8o2.cjs');
4
4
  const __electric_ax_agents_runtime = require_chunk.__toESM(require("@electric-ax/agents-runtime"));
5
5
  const node_url = require_chunk.__toESM(require("node:url"));
6
+ const __electric_ax_agents_server_headers = require_chunk.__toESM(require("@electric-ax/agents/server-headers"));
6
7
  const node_child_process = require_chunk.__toESM(require("node:child_process"));
7
8
  const __electric_ax_agents = require_chunk.__toESM(require("@electric-ax/agents"));
8
9
 
@@ -22,7 +23,8 @@ const ELECTRIC_AGENTS_SERVER_IMAGE_TAG = `latest`;
22
23
  const DEFAULT_ELECTRIC_AGENTS_PORT = 4437;
23
24
  const DEFAULT_COMPOSE_PROJECT_NAME = `electric-agents`;
24
25
  const DEFAULT_PULL_WAKE_RUNNER_ID = `builtin-agents`;
25
- const DEFAULT_PULL_WAKE_OWNER_ID = `builtin-agents`;
26
+ const DEFAULT_PULL_WAKE_OWNER_PRINCIPAL = `/principal/system%3Abuiltin-agents`;
27
+ const PRINCIPAL_URL_PREFIX = `/principal/`;
26
28
  const DOCKER_COMPOSE_FILE = (0, node_url.fileURLToPath)(new URL(`../docker-compose.full.yml`, require("url").pathToFileURL(__filename).href));
27
29
  function resolveElectricAgentsPort(env = process.env, fileEnv = require_env.readDotEnvFile()) {
28
30
  const raw = env.ELECTRIC_AGENTS_PORT?.trim() || fileEnv.ELECTRIC_AGENTS_PORT?.trim();
@@ -65,11 +67,18 @@ function runnerIdFromIdentity(identity) {
65
67
  const slug = identity.toLowerCase().replace(/[^a-z0-9._-]+/g, `-`).replace(/^-+|-+$/g, ``);
66
68
  return slug ? `builtin-${slug}` : DEFAULT_PULL_WAKE_RUNNER_ID;
67
69
  }
70
+ function principalUrlFromConfig(value) {
71
+ return value.startsWith(PRINCIPAL_URL_PREFIX) ? value : `${PRINCIPAL_URL_PREFIX}${encodeURIComponent(value)}`;
72
+ }
68
73
  function resolvePullWakeRunnerId(env = process.env, fileEnv = require_env.readDotEnvFile()) {
69
74
  return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PULL_WAKE_RUNNER_ID`, `PULL_WAKE_RUNNER_ID`]) ?? runnerIdFromIdentity(readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]));
70
75
  }
71
- function resolvePullWakeOwnerId(env = process.env, fileEnv = require_env.readDotEnvFile()) {
72
- return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]) ?? DEFAULT_PULL_WAKE_OWNER_ID;
76
+ function resolvePullWakeOwnerPrincipal(env = process.env, fileEnv = require_env.readDotEnvFile()) {
77
+ const principal = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PRINCIPAL`]);
78
+ if (principal) return principalUrlFromConfig(principal);
79
+ const identity = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]);
80
+ if (identity) return principalUrlFromConfig(identity);
81
+ return DEFAULT_PULL_WAKE_OWNER_PRINCIPAL;
73
82
  }
74
83
  function parseAdditionalServerHeaders(env, fileEnv) {
75
84
  const raw = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_SERVER_HEADERS`]);
@@ -89,6 +98,9 @@ function parseAdditionalServerHeaders(env, fileEnv) {
89
98
  const normalized = Object.fromEntries(headers.entries());
90
99
  return Object.keys(normalized).length > 0 ? normalized : void 0;
91
100
  }
101
+ function resolveServerHeaders(env, fileEnv) {
102
+ return (0, __electric_ax_agents_server_headers.mergeElectricPrincipalHeader)(parseAdditionalServerHeaders(env, fileEnv), readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PRINCIPAL`]));
103
+ }
92
104
  function mergeHeaders(...sources) {
93
105
  const headers = new Headers();
94
106
  for (const source of sources) {
@@ -226,8 +238,8 @@ async function startBuiltinAgentsServer(options, params = {}) {
226
238
  const fileEnv = require_env.readDotEnvFile(cwd);
227
239
  const anthropicApiKey = require_env.resolveAnthropicApiKey(options, env, fileEnv);
228
240
  const runnerId = resolvePullWakeRunnerId(env, fileEnv);
229
- const ownerUserId = resolvePullWakeOwnerId(env, fileEnv);
230
- const serverHeaders = mergeHeaders(parseAdditionalServerHeaders(env, fileEnv));
241
+ const ownerPrincipal = resolvePullWakeOwnerPrincipal(env, fileEnv);
242
+ const serverHeaders = mergeHeaders(resolveServerHeaders(env, fileEnv));
231
243
  const agentServerUrl = params.agentServerUrl ?? env.ELECTRIC_AGENTS_URL?.trim() ?? `http://localhost:${resolveElectricAgentsPort(env, fileEnv)}`;
232
244
  process.env.ANTHROPIC_API_KEY = anthropicApiKey;
233
245
  await waitForElectricAgentsServer(agentServerUrl, { headers: serverHeaders });
@@ -237,7 +249,7 @@ async function startBuiltinAgentsServer(options, params = {}) {
237
249
  loadProjectMcpConfig: true,
238
250
  pullWake: {
239
251
  runnerId,
240
- ownerUserId,
252
+ ownerPrincipal,
241
253
  registerRunner: true,
242
254
  headers: serverHeaders,
243
255
  claimHeaders: serverHeaders,
@@ -263,7 +275,7 @@ exports.readDotEnvFile = require_env.readDotEnvFile
263
275
  exports.resolveAnthropicApiKey = require_env.resolveAnthropicApiKey
264
276
  exports.resolveComposeProjectName = resolveComposeProjectName
265
277
  exports.resolveElectricAgentsPort = resolveElectricAgentsPort
266
- exports.resolvePullWakeOwnerId = resolvePullWakeOwnerId
278
+ exports.resolvePullWakeOwnerPrincipal = resolvePullWakeOwnerPrincipal
267
279
  exports.resolvePullWakeRunnerId = resolvePullWakeRunnerId
268
280
  exports.startBuiltinAgentsServer = startBuiltinAgentsServer
269
281
  exports.startElectricAgentsDevEnvironment = startElectricAgentsDevEnvironment
package/dist/start.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer } from "./index-cwCTPq6Y.cjs";
2
- export { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
1
+ import { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer } from "./index-OgX1QS9Q.cjs";
2
+ export { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
package/dist/start.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer } from "./index-BSHO_Rei.js";
2
- export { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
1
+ import { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer } from "./index-CwRI9tWl.js";
2
+ export { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
package/dist/start.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readDotEnvFile$1 as readDotEnvFile, resolveAnthropicApiKey$1 as resolveAnthropicApiKey } from "./env-DIhTv987.js";
2
2
  import { appendPathToUrl } from "@electric-ax/agents-runtime";
3
3
  import { fileURLToPath } from "node:url";
4
+ import { mergeElectricPrincipalHeader } from "@electric-ax/agents/server-headers";
4
5
  import { spawn } from "node:child_process";
5
6
  import { BuiltinAgentsServer } from "@electric-ax/agents";
6
7
 
@@ -20,7 +21,8 @@ const ELECTRIC_AGENTS_SERVER_IMAGE_TAG = `latest`;
20
21
  const DEFAULT_ELECTRIC_AGENTS_PORT = 4437;
21
22
  const DEFAULT_COMPOSE_PROJECT_NAME = `electric-agents`;
22
23
  const DEFAULT_PULL_WAKE_RUNNER_ID = `builtin-agents`;
23
- const DEFAULT_PULL_WAKE_OWNER_ID = `builtin-agents`;
24
+ const DEFAULT_PULL_WAKE_OWNER_PRINCIPAL = `/principal/system%3Abuiltin-agents`;
25
+ const PRINCIPAL_URL_PREFIX = `/principal/`;
24
26
  const DOCKER_COMPOSE_FILE = fileURLToPath(new URL(`../docker-compose.full.yml`, import.meta.url));
25
27
  function resolveElectricAgentsPort(env = process.env, fileEnv = readDotEnvFile()) {
26
28
  const raw = env.ELECTRIC_AGENTS_PORT?.trim() || fileEnv.ELECTRIC_AGENTS_PORT?.trim();
@@ -63,11 +65,18 @@ function runnerIdFromIdentity(identity) {
63
65
  const slug = identity.toLowerCase().replace(/[^a-z0-9._-]+/g, `-`).replace(/^-+|-+$/g, ``);
64
66
  return slug ? `builtin-${slug}` : DEFAULT_PULL_WAKE_RUNNER_ID;
65
67
  }
68
+ function principalUrlFromConfig(value) {
69
+ return value.startsWith(PRINCIPAL_URL_PREFIX) ? value : `${PRINCIPAL_URL_PREFIX}${encodeURIComponent(value)}`;
70
+ }
66
71
  function resolvePullWakeRunnerId(env = process.env, fileEnv = readDotEnvFile()) {
67
72
  return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PULL_WAKE_RUNNER_ID`, `PULL_WAKE_RUNNER_ID`]) ?? runnerIdFromIdentity(readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]));
68
73
  }
69
- function resolvePullWakeOwnerId(env = process.env, fileEnv = readDotEnvFile()) {
70
- return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]) ?? DEFAULT_PULL_WAKE_OWNER_ID;
74
+ function resolvePullWakeOwnerPrincipal(env = process.env, fileEnv = readDotEnvFile()) {
75
+ const principal = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PRINCIPAL`]);
76
+ if (principal) return principalUrlFromConfig(principal);
77
+ const identity = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]);
78
+ if (identity) return principalUrlFromConfig(identity);
79
+ return DEFAULT_PULL_WAKE_OWNER_PRINCIPAL;
71
80
  }
72
81
  function parseAdditionalServerHeaders(env, fileEnv) {
73
82
  const raw = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_SERVER_HEADERS`]);
@@ -87,6 +96,9 @@ function parseAdditionalServerHeaders(env, fileEnv) {
87
96
  const normalized = Object.fromEntries(headers.entries());
88
97
  return Object.keys(normalized).length > 0 ? normalized : void 0;
89
98
  }
99
+ function resolveServerHeaders(env, fileEnv) {
100
+ return mergeElectricPrincipalHeader(parseAdditionalServerHeaders(env, fileEnv), readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PRINCIPAL`]));
101
+ }
90
102
  function mergeHeaders(...sources) {
91
103
  const headers = new Headers();
92
104
  for (const source of sources) {
@@ -224,8 +236,8 @@ async function startBuiltinAgentsServer(options, params = {}) {
224
236
  const fileEnv = readDotEnvFile(cwd);
225
237
  const anthropicApiKey = resolveAnthropicApiKey(options, env, fileEnv);
226
238
  const runnerId = resolvePullWakeRunnerId(env, fileEnv);
227
- const ownerUserId = resolvePullWakeOwnerId(env, fileEnv);
228
- const serverHeaders = mergeHeaders(parseAdditionalServerHeaders(env, fileEnv));
239
+ const ownerPrincipal = resolvePullWakeOwnerPrincipal(env, fileEnv);
240
+ const serverHeaders = mergeHeaders(resolveServerHeaders(env, fileEnv));
229
241
  const agentServerUrl = params.agentServerUrl ?? env.ELECTRIC_AGENTS_URL?.trim() ?? `http://localhost:${resolveElectricAgentsPort(env, fileEnv)}`;
230
242
  process.env.ANTHROPIC_API_KEY = anthropicApiKey;
231
243
  await waitForElectricAgentsServer(agentServerUrl, { headers: serverHeaders });
@@ -235,7 +247,7 @@ async function startBuiltinAgentsServer(options, params = {}) {
235
247
  loadProjectMcpConfig: true,
236
248
  pullWake: {
237
249
  runnerId,
238
- ownerUserId,
250
+ ownerPrincipal,
239
251
  registerRunner: true,
240
252
  headers: serverHeaders,
241
253
  claimHeaders: serverHeaders,
@@ -254,4 +266,4 @@ async function startBuiltinAgentsServer(options, params = {}) {
254
266
  }
255
267
 
256
268
  //#endregion
257
- export { getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
269
+ export { getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerPrincipal, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electric-ax",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "CLI for Electric Agents",
5
5
  "author": "ElectricSQL team and contributors",
6
6
  "license": "Apache-2.0",
@@ -39,15 +39,15 @@
39
39
  "dependencies": {
40
40
  "@durable-streams/client": "https://pkg.pr.new/durable-streams/durable-streams/@durable-streams/client@350",
41
41
  "@durable-streams/state": "https://pkg.pr.new/durable-streams/durable-streams/@durable-streams/state@350",
42
- "@electric-sql/client": "^1.5.17",
42
+ "@electric-sql/client": "^1.5.18",
43
43
  "@tanstack/db": "^0.6.4",
44
44
  "@tanstack/react-db": "^0.1.82",
45
45
  "commander": "^13.1.0",
46
46
  "ink": "^6.8.0",
47
47
  "omelette": "^0.4.17",
48
48
  "react": "^19.2.0",
49
- "@electric-ax/agents": "0.4.1",
50
- "@electric-ax/agents-runtime": "0.2.1"
49
+ "@electric-ax/agents": "0.4.3",
50
+ "@electric-ax/agents-runtime": "0.2.2"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@vitest/coverage-v8": "^4.1.0",