electric-ax 0.1.18 → 0.2.1
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/completions.d.cts +1 -1
- package/dist/completions.d.ts +1 -1
- package/dist/entity-api-Cvo55yZx.cjs +28 -0
- package/dist/entity-api-DWMhkYbl.js +15 -0
- package/dist/{entity-stream-db-BRwzIuHl.d.ts → entity-stream-db-BV4N31MR.d.cts} +2 -1
- package/dist/{entity-stream-db-C2C3t_hD.d.cts → entity-stream-db-Bl6AT5hR.d.ts} +2 -1
- package/dist/{entity-stream-db-CGP2xVeJ.js → entity-stream-db-CDOlZYc2.js} +10 -4
- package/dist/{entity-stream-db-Djo-7a11.cjs → entity-stream-db-CIv6uC2d.cjs} +9 -3
- package/dist/entity-stream-db.cjs +2 -1
- package/dist/entity-stream-db.d.cts +1 -1
- package/dist/entity-stream-db.d.ts +1 -1
- package/dist/entity-stream-db.js +2 -1
- package/dist/{index-B2MsxFCW.d.cts → index-BSHO_Rei.d.ts} +6 -5
- package/dist/{index-BDO8dHhT.d.ts → index-cwCTPq6Y.d.cts} +6 -5
- package/dist/index.cjs +31 -7
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +31 -7
- package/dist/observe-ui.cjs +21 -11
- package/dist/observe-ui.d.cts +4 -1
- package/dist/observe-ui.d.ts +4 -1
- package/dist/observe-ui.js +21 -11
- package/dist/start.cjs +78 -28
- package/dist/start.d.cts +2 -2
- package/dist/start.d.ts +2 -2
- package/dist/start.js +77 -27
- package/docker-compose.full.yml +1 -1
- package/package.json +5 -5
- /package/dist/{env-BXUgom_C.cjs → env-CFKgT8o2.cjs} +0 -0
- /package/dist/{env-LZtIfFz1.js → env-DIhTv987.js} +0 -0
package/dist/completions.d.cts
CHANGED
package/dist/completions.d.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
3
|
+
const __electric_ax_agents_runtime = require_chunk.__toESM(require("@electric-ax/agents-runtime"));
|
|
4
|
+
|
|
5
|
+
//#region src/entity-api.ts
|
|
6
|
+
function withLeadingSlash(path) {
|
|
7
|
+
return path.startsWith(`/`) ? path : `/${path}`;
|
|
8
|
+
}
|
|
9
|
+
function entityApiPath(entityUrl, suffix = ``) {
|
|
10
|
+
return `/_electric/entities${withLeadingSlash(entityUrl)}${suffix}`;
|
|
11
|
+
}
|
|
12
|
+
function entityApiUrl(baseUrl, entityUrl, suffix = ``) {
|
|
13
|
+
return (0, __electric_ax_agents_runtime.appendPathToUrl)(baseUrl, entityApiPath(entityUrl, suffix));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
Object.defineProperty(exports, 'entityApiPath', {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return entityApiPath;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, 'entityApiUrl', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return entityApiUrl;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { appendPathToUrl } from "@electric-ax/agents-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/entity-api.ts
|
|
4
|
+
function withLeadingSlash(path) {
|
|
5
|
+
return path.startsWith(`/`) ? path : `/${path}`;
|
|
6
|
+
}
|
|
7
|
+
function entityApiPath(entityUrl, suffix = ``) {
|
|
8
|
+
return `/_electric/entities${withLeadingSlash(entityUrl)}${suffix}`;
|
|
9
|
+
}
|
|
10
|
+
function entityApiUrl(baseUrl, entityUrl, suffix = ``) {
|
|
11
|
+
return appendPathToUrl(baseUrl, entityApiPath(entityUrl, suffix));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { entityApiPath, entityApiUrl };
|
|
@@ -6,8 +6,9 @@ declare function createEntityStreamDB(opts: {
|
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
entityUrl: string;
|
|
8
8
|
initialOffset?: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
9
10
|
}): Promise<{
|
|
10
11
|
db: EntityStreamDB;
|
|
11
12
|
close: () => void;
|
|
12
13
|
}>; //#endregion
|
|
13
|
-
export { EntityStreamDB$1 as EntityStreamDB, createEntityStreamDB
|
|
14
|
+
export { EntityStreamDB$1 as EntityStreamDB, createEntityStreamDB };
|
|
@@ -6,8 +6,9 @@ declare function createEntityStreamDB(opts: {
|
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
entityUrl: string;
|
|
8
8
|
initialOffset?: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
9
10
|
}): Promise<{
|
|
10
11
|
db: EntityStreamDB;
|
|
11
12
|
close: () => void;
|
|
12
13
|
}>; //#endregion
|
|
13
|
-
export { EntityStreamDB$1 as EntityStreamDB, createEntityStreamDB };
|
|
14
|
+
export { EntityStreamDB$1 as EntityStreamDB, createEntityStreamDB as createEntityStreamDB$1 };
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
+
import { entityApiUrl } from "./entity-api-DWMhkYbl.js";
|
|
1
2
|
import { createStreamDB } from "@durable-streams/state";
|
|
2
|
-
import { entityStateSchema } from "@electric-ax/agents-runtime";
|
|
3
|
+
import { appendPathToUrl, entityStateSchema } from "@electric-ax/agents-runtime";
|
|
3
4
|
|
|
4
5
|
//#region src/entity-stream-db.ts
|
|
5
6
|
function getMainStreamPath(entityUrl, entity) {
|
|
6
7
|
return entity.streams?.main ?? `${entityUrl}/main`;
|
|
7
8
|
}
|
|
8
9
|
async function createEntityStreamDB(opts) {
|
|
9
|
-
const { baseUrl, entityUrl, initialOffset } = opts;
|
|
10
|
+
const { baseUrl, entityUrl, initialOffset, headers: serverHeaders } = opts;
|
|
10
11
|
console.log(`[createEntityStreamDB] Creating entity stream DB for ${baseUrl}${entityUrl}`);
|
|
12
|
+
const requestHeaders = {
|
|
13
|
+
"content-type": `application/json`,
|
|
14
|
+
...serverHeaders
|
|
15
|
+
};
|
|
11
16
|
let res;
|
|
12
17
|
try {
|
|
13
|
-
res = await fetch(
|
|
18
|
+
res = await fetch(entityApiUrl(baseUrl, entityUrl), { headers: requestHeaders });
|
|
14
19
|
} catch (err) {
|
|
15
20
|
throw new Error(`Could not connect to the Electric Agents server at ${baseUrl} — is it running?\n ${err instanceof Error ? err.message : String(err)}`);
|
|
16
21
|
}
|
|
17
22
|
if (!res.ok) throw new Error(`Failed to fetch entity at ${entityUrl}: ${res.statusText}`);
|
|
18
23
|
const entity = await res.json();
|
|
19
24
|
const streamPath = getMainStreamPath(entityUrl, entity);
|
|
20
|
-
const streamUrl =
|
|
25
|
+
const streamUrl = appendPathToUrl(baseUrl, streamPath);
|
|
21
26
|
const db = createStreamDB({
|
|
22
27
|
streamOptions: {
|
|
23
28
|
url: streamUrl,
|
|
29
|
+
headers: requestHeaders,
|
|
24
30
|
contentType: `application/json`,
|
|
25
31
|
...initialOffset ? { offset: initialOffset } : {}
|
|
26
32
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
3
|
+
const require_entity_api = require('./entity-api-Cvo55yZx.cjs');
|
|
3
4
|
const __durable_streams_state = require_chunk.__toESM(require("@durable-streams/state"));
|
|
4
5
|
const __electric_ax_agents_runtime = require_chunk.__toESM(require("@electric-ax/agents-runtime"));
|
|
5
6
|
|
|
@@ -8,21 +9,26 @@ function getMainStreamPath(entityUrl, entity) {
|
|
|
8
9
|
return entity.streams?.main ?? `${entityUrl}/main`;
|
|
9
10
|
}
|
|
10
11
|
async function createEntityStreamDB(opts) {
|
|
11
|
-
const { baseUrl, entityUrl, initialOffset } = opts;
|
|
12
|
+
const { baseUrl, entityUrl, initialOffset, headers: serverHeaders } = opts;
|
|
12
13
|
console.log(`[createEntityStreamDB] Creating entity stream DB for ${baseUrl}${entityUrl}`);
|
|
14
|
+
const requestHeaders = {
|
|
15
|
+
"content-type": `application/json`,
|
|
16
|
+
...serverHeaders
|
|
17
|
+
};
|
|
13
18
|
let res;
|
|
14
19
|
try {
|
|
15
|
-
res = await fetch(
|
|
20
|
+
res = await fetch(require_entity_api.entityApiUrl(baseUrl, entityUrl), { headers: requestHeaders });
|
|
16
21
|
} catch (err) {
|
|
17
22
|
throw new Error(`Could not connect to the Electric Agents server at ${baseUrl} — is it running?\n ${err instanceof Error ? err.message : String(err)}`);
|
|
18
23
|
}
|
|
19
24
|
if (!res.ok) throw new Error(`Failed to fetch entity at ${entityUrl}: ${res.statusText}`);
|
|
20
25
|
const entity = await res.json();
|
|
21
26
|
const streamPath = getMainStreamPath(entityUrl, entity);
|
|
22
|
-
const streamUrl =
|
|
27
|
+
const streamUrl = (0, __electric_ax_agents_runtime.appendPathToUrl)(baseUrl, streamPath);
|
|
23
28
|
const db = (0, __durable_streams_state.createStreamDB)({
|
|
24
29
|
streamOptions: {
|
|
25
30
|
url: streamUrl,
|
|
31
|
+
headers: requestHeaders,
|
|
26
32
|
contentType: `application/json`,
|
|
27
33
|
...initialOffset ? { offset: initialOffset } : {}
|
|
28
34
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require('./entity-api-Cvo55yZx.cjs');
|
|
2
|
+
const require_entity_stream_db = require('./entity-stream-db-CIv6uC2d.cjs');
|
|
2
3
|
|
|
3
4
|
exports.createEntityStreamDB = require_entity_stream_db.createEntityStreamDB
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntityStreamDB, createEntityStreamDB } from "./entity-stream-db-
|
|
1
|
+
import { EntityStreamDB, createEntityStreamDB } from "./entity-stream-db-BV4N31MR.cjs";
|
|
2
2
|
export { EntityStreamDB, createEntityStreamDB };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntityStreamDB, createEntityStreamDB$1 as createEntityStreamDB } from "./entity-stream-db-
|
|
1
|
+
import { EntityStreamDB, createEntityStreamDB$1 as createEntityStreamDB } from "./entity-stream-db-Bl6AT5hR.js";
|
|
2
2
|
export { EntityStreamDB, createEntityStreamDB };
|
package/dist/entity-stream-db.js
CHANGED
|
@@ -19,22 +19,22 @@ interface StoppedDevEnvironment {
|
|
|
19
19
|
removedVolumes: boolean;
|
|
20
20
|
}
|
|
21
21
|
interface StartedBuiltinAgentsEnvironment {
|
|
22
|
-
|
|
22
|
+
runnerId: string;
|
|
23
23
|
url: string;
|
|
24
|
-
registeredBaseUrl: string;
|
|
25
24
|
agentServerUrl: string;
|
|
26
25
|
}
|
|
27
26
|
interface WaitForServerOptions {
|
|
28
27
|
fetchImpl?: typeof globalThis.fetch;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
29
|
timeoutMs?: number;
|
|
30
30
|
intervalMs?: number;
|
|
31
31
|
}
|
|
32
|
-
declare function resolveBuiltinAgentsPort(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): number;
|
|
33
|
-
declare function resolveBuiltinAgentsHost(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
|
|
34
32
|
declare function resolveElectricAgentsPort(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): number;
|
|
35
33
|
declare function getStartedEnvironmentMessage(started: StartedDevEnvironment): string;
|
|
36
34
|
declare function getStoppedEnvironmentMessage(stopped: StoppedDevEnvironment): string;
|
|
37
35
|
declare function getStartedBuiltinAgentsMessage(started: StartedBuiltinAgentsEnvironment): string;
|
|
36
|
+
declare function resolvePullWakeRunnerId(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
|
|
37
|
+
declare function resolvePullWakeOwnerId(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>;
|
|
@@ -52,6 +52,7 @@ declare const DEFAULT_ELECTRIC_AGENTS_URL = "http://localhost:4437";
|
|
|
52
52
|
interface ElectricCliEnv {
|
|
53
53
|
electricAgentsUrl: string;
|
|
54
54
|
electricAgentsIdentity: string;
|
|
55
|
+
electricAgentsHeaders?: Record<string, string>;
|
|
55
56
|
}
|
|
56
57
|
interface SpawnCommandOptions {
|
|
57
58
|
args?: string;
|
|
@@ -124,4 +125,4 @@ declare function createElectricProgram({
|
|
|
124
125
|
declare function run(argv?: Array<string>): Promise<void>;
|
|
125
126
|
|
|
126
127
|
//#endregion
|
|
127
|
-
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,
|
|
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 };
|
|
@@ -19,22 +19,22 @@ interface StoppedDevEnvironment {
|
|
|
19
19
|
removedVolumes: boolean;
|
|
20
20
|
}
|
|
21
21
|
interface StartedBuiltinAgentsEnvironment {
|
|
22
|
-
|
|
22
|
+
runnerId: string;
|
|
23
23
|
url: string;
|
|
24
|
-
registeredBaseUrl: string;
|
|
25
24
|
agentServerUrl: string;
|
|
26
25
|
}
|
|
27
26
|
interface WaitForServerOptions {
|
|
28
27
|
fetchImpl?: typeof globalThis.fetch;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
29
|
timeoutMs?: number;
|
|
30
30
|
intervalMs?: number;
|
|
31
31
|
}
|
|
32
|
-
declare function resolveBuiltinAgentsPort(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): number;
|
|
33
|
-
declare function resolveBuiltinAgentsHost(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
|
|
34
32
|
declare function resolveElectricAgentsPort(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): number;
|
|
35
33
|
declare function getStartedEnvironmentMessage(started: StartedDevEnvironment): string;
|
|
36
34
|
declare function getStoppedEnvironmentMessage(stopped: StoppedDevEnvironment): string;
|
|
37
35
|
declare function getStartedBuiltinAgentsMessage(started: StartedBuiltinAgentsEnvironment): string;
|
|
36
|
+
declare function resolvePullWakeRunnerId(env?: NodeJS.ProcessEnv, fileEnv?: Record<string, string>): string;
|
|
37
|
+
declare function resolvePullWakeOwnerId(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>;
|
|
@@ -52,6 +52,7 @@ declare const DEFAULT_ELECTRIC_AGENTS_URL = "http://localhost:4437";
|
|
|
52
52
|
interface ElectricCliEnv {
|
|
53
53
|
electricAgentsUrl: string;
|
|
54
54
|
electricAgentsIdentity: string;
|
|
55
|
+
electricAgentsHeaders?: Record<string, string>;
|
|
55
56
|
}
|
|
56
57
|
interface SpawnCommandOptions {
|
|
57
58
|
args?: string;
|
|
@@ -124,4 +125,4 @@ declare function createElectricProgram({
|
|
|
124
125
|
declare function run(argv?: Array<string>): Promise<void>;
|
|
125
126
|
|
|
126
127
|
//#endregion
|
|
127
|
-
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,
|
|
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 };
|
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
4
4
|
const require_completions = require('./completions-Bj4D5DRa.cjs');
|
|
5
|
-
const
|
|
5
|
+
const require_entity_api = require('./entity-api-Cvo55yZx.cjs');
|
|
6
|
+
const require_env = require('./env-CFKgT8o2.cjs');
|
|
7
|
+
const __electric_ax_agents_runtime = require_chunk.__toESM(require("@electric-ax/agents-runtime"));
|
|
6
8
|
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
7
9
|
const node_os = require_chunk.__toESM(require("node:os"));
|
|
8
10
|
const node_path = require_chunk.__toESM(require("node:path"));
|
|
@@ -140,10 +142,30 @@ var CliError = class extends Error {};
|
|
|
140
142
|
function getDefaultElectricAgentsIdentity() {
|
|
141
143
|
return `${(0, node_os.userInfo)().username}@${(0, node_os.hostname)()}`;
|
|
142
144
|
}
|
|
145
|
+
function parseElectricAgentsHeaders(raw) {
|
|
146
|
+
const trimmed = raw?.trim();
|
|
147
|
+
if (!trimmed) return void 0;
|
|
148
|
+
let parsed;
|
|
149
|
+
try {
|
|
150
|
+
parsed = JSON.parse(trimmed);
|
|
151
|
+
} catch {
|
|
152
|
+
fail(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected JSON`);
|
|
153
|
+
}
|
|
154
|
+
if (!parsed || typeof parsed !== `object` || Array.isArray(parsed)) fail(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected a JSON object`);
|
|
155
|
+
const headers = new Headers();
|
|
156
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
157
|
+
if (typeof value !== `string`) fail(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: header "${name}" must be a string`);
|
|
158
|
+
headers.set(name, value);
|
|
159
|
+
}
|
|
160
|
+
const normalized = Object.fromEntries(headers.entries());
|
|
161
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
162
|
+
}
|
|
143
163
|
function getElectricCliEnv(env = process.env) {
|
|
164
|
+
const explicitIdentity = env.ELECTRIC_AGENTS_IDENTITY?.trim();
|
|
144
165
|
return {
|
|
145
166
|
electricAgentsUrl: env.ELECTRIC_AGENTS_URL || DEFAULT_ELECTRIC_AGENTS_URL,
|
|
146
|
-
electricAgentsIdentity:
|
|
167
|
+
electricAgentsIdentity: explicitIdentity || getDefaultElectricAgentsIdentity(),
|
|
168
|
+
electricAgentsHeaders: parseElectricAgentsHeaders(env.ELECTRIC_AGENTS_SERVER_HEADERS)
|
|
147
169
|
};
|
|
148
170
|
}
|
|
149
171
|
function getErrorMessage(error) {
|
|
@@ -270,10 +292,11 @@ function resolveCommandPrefix(argv, env = process.env) {
|
|
|
270
292
|
}
|
|
271
293
|
async function electricAgentsFetch(env, path, opts = {}) {
|
|
272
294
|
try {
|
|
273
|
-
return await fetch(
|
|
295
|
+
return await fetch((0, __electric_ax_agents_runtime.appendPathToUrl)(env.electricAgentsUrl, path), {
|
|
274
296
|
...opts,
|
|
275
297
|
headers: {
|
|
276
298
|
"content-type": `application/json`,
|
|
299
|
+
...env.electricAgentsHeaders,
|
|
277
300
|
...opts.headers
|
|
278
301
|
}
|
|
279
302
|
});
|
|
@@ -348,7 +371,7 @@ async function spawnEntity(env, urlPath, options) {
|
|
|
348
371
|
} catch (error) {
|
|
349
372
|
fail(`--args must be valid JSON: ${getErrorMessage(error)}`);
|
|
350
373
|
}
|
|
351
|
-
const res = await electricAgentsFetch(env, urlPath, {
|
|
374
|
+
const res = await electricAgentsFetch(env, require_entity_api.entityApiPath(urlPath), {
|
|
352
375
|
method: `PUT`,
|
|
353
376
|
body: JSON.stringify({ args: spawnArgs })
|
|
354
377
|
});
|
|
@@ -365,7 +388,7 @@ async function sendMessage(env, url, message, options) {
|
|
|
365
388
|
payload
|
|
366
389
|
};
|
|
367
390
|
if (options.type) body.type = options.type;
|
|
368
|
-
const res = await electricAgentsFetch(env,
|
|
391
|
+
const res = await electricAgentsFetch(env, require_entity_api.entityApiPath(url, `/send`), {
|
|
369
392
|
method: `POST`,
|
|
370
393
|
body: JSON.stringify(body)
|
|
371
394
|
});
|
|
@@ -382,11 +405,12 @@ async function observeEntity(env, url, options) {
|
|
|
382
405
|
entityUrl: url,
|
|
383
406
|
baseUrl: env.electricAgentsUrl,
|
|
384
407
|
identity: env.electricAgentsIdentity,
|
|
408
|
+
headers: env.electricAgentsHeaders,
|
|
385
409
|
initialOffset: options.from
|
|
386
410
|
});
|
|
387
411
|
}
|
|
388
412
|
async function inspectEntity(env, url) {
|
|
389
|
-
const res = await electricAgentsFetch(env, url);
|
|
413
|
+
const res = await electricAgentsFetch(env, require_entity_api.entityApiPath(url));
|
|
390
414
|
const data = await parseJsonResponse(res);
|
|
391
415
|
if (!res.ok) failFromResponse(data, res);
|
|
392
416
|
console.log(JSON.stringify(data, null, 2));
|
|
@@ -411,7 +435,7 @@ async function listEntities(env, options) {
|
|
|
411
435
|
}
|
|
412
436
|
}
|
|
413
437
|
async function killEntity(env, url) {
|
|
414
|
-
const res = await electricAgentsFetch(env, url, { method: `DELETE` });
|
|
438
|
+
const res = await electricAgentsFetch(env, require_entity_api.entityApiPath(url), { method: `DELETE` });
|
|
415
439
|
if (!res.ok) {
|
|
416
440
|
const data = await parseJsonResponse(res);
|
|
417
441
|
failFromResponse(data, res);
|
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-
|
|
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";
|
|
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-
|
|
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";
|
|
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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { installCompletions, setupCompletions } from "./completions-B-Lf28Wy.js";
|
|
3
|
-
import {
|
|
3
|
+
import { entityApiPath } from "./entity-api-DWMhkYbl.js";
|
|
4
|
+
import { resolveAnthropicApiKey$1 as resolveAnthropicApiKey } from "./env-DIhTv987.js";
|
|
5
|
+
import { appendPathToUrl } from "@electric-ax/agents-runtime";
|
|
4
6
|
import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
7
|
import { hostname, userInfo } from "node:os";
|
|
6
8
|
import { basename, resolve } from "node:path";
|
|
@@ -138,10 +140,30 @@ var CliError = class extends Error {};
|
|
|
138
140
|
function getDefaultElectricAgentsIdentity() {
|
|
139
141
|
return `${userInfo().username}@${hostname()}`;
|
|
140
142
|
}
|
|
143
|
+
function parseElectricAgentsHeaders(raw) {
|
|
144
|
+
const trimmed = raw?.trim();
|
|
145
|
+
if (!trimmed) return void 0;
|
|
146
|
+
let parsed;
|
|
147
|
+
try {
|
|
148
|
+
parsed = JSON.parse(trimmed);
|
|
149
|
+
} catch {
|
|
150
|
+
fail(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected JSON`);
|
|
151
|
+
}
|
|
152
|
+
if (!parsed || typeof parsed !== `object` || Array.isArray(parsed)) fail(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected a JSON object`);
|
|
153
|
+
const headers = new Headers();
|
|
154
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
155
|
+
if (typeof value !== `string`) fail(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: header "${name}" must be a string`);
|
|
156
|
+
headers.set(name, value);
|
|
157
|
+
}
|
|
158
|
+
const normalized = Object.fromEntries(headers.entries());
|
|
159
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
160
|
+
}
|
|
141
161
|
function getElectricCliEnv(env = process.env) {
|
|
162
|
+
const explicitIdentity = env.ELECTRIC_AGENTS_IDENTITY?.trim();
|
|
142
163
|
return {
|
|
143
164
|
electricAgentsUrl: env.ELECTRIC_AGENTS_URL || DEFAULT_ELECTRIC_AGENTS_URL,
|
|
144
|
-
electricAgentsIdentity:
|
|
165
|
+
electricAgentsIdentity: explicitIdentity || getDefaultElectricAgentsIdentity(),
|
|
166
|
+
electricAgentsHeaders: parseElectricAgentsHeaders(env.ELECTRIC_AGENTS_SERVER_HEADERS)
|
|
145
167
|
};
|
|
146
168
|
}
|
|
147
169
|
function getErrorMessage(error) {
|
|
@@ -268,10 +290,11 @@ function resolveCommandPrefix(argv, env = process.env) {
|
|
|
268
290
|
}
|
|
269
291
|
async function electricAgentsFetch(env, path$1, opts = {}) {
|
|
270
292
|
try {
|
|
271
|
-
return await fetch(
|
|
293
|
+
return await fetch(appendPathToUrl(env.electricAgentsUrl, path$1), {
|
|
272
294
|
...opts,
|
|
273
295
|
headers: {
|
|
274
296
|
"content-type": `application/json`,
|
|
297
|
+
...env.electricAgentsHeaders,
|
|
275
298
|
...opts.headers
|
|
276
299
|
}
|
|
277
300
|
});
|
|
@@ -346,7 +369,7 @@ async function spawnEntity(env, urlPath, options) {
|
|
|
346
369
|
} catch (error) {
|
|
347
370
|
fail(`--args must be valid JSON: ${getErrorMessage(error)}`);
|
|
348
371
|
}
|
|
349
|
-
const res = await electricAgentsFetch(env, urlPath, {
|
|
372
|
+
const res = await electricAgentsFetch(env, entityApiPath(urlPath), {
|
|
350
373
|
method: `PUT`,
|
|
351
374
|
body: JSON.stringify({ args: spawnArgs })
|
|
352
375
|
});
|
|
@@ -363,7 +386,7 @@ async function sendMessage(env, url, message, options) {
|
|
|
363
386
|
payload
|
|
364
387
|
};
|
|
365
388
|
if (options.type) body.type = options.type;
|
|
366
|
-
const res = await electricAgentsFetch(env,
|
|
389
|
+
const res = await electricAgentsFetch(env, entityApiPath(url, `/send`), {
|
|
367
390
|
method: `POST`,
|
|
368
391
|
body: JSON.stringify(body)
|
|
369
392
|
});
|
|
@@ -380,11 +403,12 @@ async function observeEntity(env, url, options) {
|
|
|
380
403
|
entityUrl: url,
|
|
381
404
|
baseUrl: env.electricAgentsUrl,
|
|
382
405
|
identity: env.electricAgentsIdentity,
|
|
406
|
+
headers: env.electricAgentsHeaders,
|
|
383
407
|
initialOffset: options.from
|
|
384
408
|
});
|
|
385
409
|
}
|
|
386
410
|
async function inspectEntity(env, url) {
|
|
387
|
-
const res = await electricAgentsFetch(env, url);
|
|
411
|
+
const res = await electricAgentsFetch(env, entityApiPath(url));
|
|
388
412
|
const data = await parseJsonResponse(res);
|
|
389
413
|
if (!res.ok) failFromResponse(data, res);
|
|
390
414
|
console.log(JSON.stringify(data, null, 2));
|
|
@@ -409,7 +433,7 @@ async function listEntities(env, options) {
|
|
|
409
433
|
}
|
|
410
434
|
}
|
|
411
435
|
async function killEntity(env, url) {
|
|
412
|
-
const res = await electricAgentsFetch(env, url, { method: `DELETE` });
|
|
436
|
+
const res = await electricAgentsFetch(env, entityApiPath(url), { method: `DELETE` });
|
|
413
437
|
if (!res.ok) {
|
|
414
438
|
const data = await parseJsonResponse(res);
|
|
415
439
|
failFromResponse(data, res);
|
package/dist/observe-ui.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
3
|
-
const
|
|
3
|
+
const require_entity_api = require('./entity-api-Cvo55yZx.cjs');
|
|
4
|
+
const require_entity_stream_db = require('./entity-stream-db-CIv6uC2d.cjs');
|
|
4
5
|
const __durable_streams_state = require_chunk.__toESM(require("@durable-streams/state"));
|
|
5
6
|
const __electric_ax_agents_runtime = require_chunk.__toESM(require("@electric-ax/agents-runtime"));
|
|
6
7
|
const react = require_chunk.__toESM(require("react"));
|
|
@@ -118,7 +119,7 @@ function ToolResultView({ result }) {
|
|
|
118
119
|
}) : null]
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
|
-
function MessageInput({ db, baseUrl, entityUrl, identity, disabled }) {
|
|
122
|
+
function MessageInput({ db, baseUrl, entityUrl, identity, headers, disabled }) {
|
|
122
123
|
const [value, setValue] = (0, react.useState)(``);
|
|
123
124
|
const [error, setError] = (0, react.useState)(null);
|
|
124
125
|
const sendAction = (0, react.useMemo)(() => (0, __durable_streams_state.createOptimisticAction)({
|
|
@@ -131,9 +132,12 @@ function MessageInput({ db, baseUrl, entityUrl, identity, disabled }) {
|
|
|
131
132
|
});
|
|
132
133
|
},
|
|
133
134
|
mutationFn: async ({ text }) => {
|
|
134
|
-
const res = await fetch(
|
|
135
|
+
const res = await fetch(require_entity_api.entityApiUrl(baseUrl, entityUrl, `/send`), {
|
|
135
136
|
method: `POST`,
|
|
136
|
-
headers: {
|
|
137
|
+
headers: {
|
|
138
|
+
"content-type": `application/json`,
|
|
139
|
+
...headers
|
|
140
|
+
},
|
|
137
141
|
body: JSON.stringify({
|
|
138
142
|
from: identity,
|
|
139
143
|
payload: { text }
|
|
@@ -157,7 +161,8 @@ function MessageInput({ db, baseUrl, entityUrl, identity, disabled }) {
|
|
|
157
161
|
db,
|
|
158
162
|
baseUrl,
|
|
159
163
|
entityUrl,
|
|
160
|
-
identity
|
|
164
|
+
identity,
|
|
165
|
+
headers
|
|
161
166
|
]);
|
|
162
167
|
(0, ink.useInput)((input, key) => {
|
|
163
168
|
if (disabled) return;
|
|
@@ -256,7 +261,7 @@ function WakeView({ section }) {
|
|
|
256
261
|
})]
|
|
257
262
|
});
|
|
258
263
|
}
|
|
259
|
-
function ObserveView({ db, entityUrl, baseUrl, identity }) {
|
|
264
|
+
function ObserveView({ db, entityUrl, baseUrl, identity, headers }) {
|
|
260
265
|
const timelineQuery = (0, react.useMemo)(() => (0, __electric_ax_agents_runtime.createEntityIncludesQuery)(db), [db]);
|
|
261
266
|
const { data: timelineRows = [] } = (0, __tanstack_react_db.useLiveQuery)(timelineQuery, [timelineQuery]);
|
|
262
267
|
const timelineData = (0, __electric_ax_agents_runtime.normalizeEntityTimelineData)(timelineRows[0] ?? {
|
|
@@ -329,12 +334,13 @@ function ObserveView({ db, entityUrl, baseUrl, identity }) {
|
|
|
329
334
|
baseUrl,
|
|
330
335
|
entityUrl,
|
|
331
336
|
identity,
|
|
337
|
+
headers,
|
|
332
338
|
disabled: closed
|
|
333
339
|
})
|
|
334
340
|
]
|
|
335
341
|
});
|
|
336
342
|
}
|
|
337
|
-
function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
343
|
+
function ObserveApp({ entityUrl, baseUrl, identity, headers, initialOffset }) {
|
|
338
344
|
const [db, setDb] = (0, react.useState)(null);
|
|
339
345
|
const [error, setError] = (0, react.useState)(null);
|
|
340
346
|
const closeRef = (0, react.useRef)(null);
|
|
@@ -343,7 +349,8 @@ function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
|
343
349
|
require_entity_stream_db.createEntityStreamDB({
|
|
344
350
|
baseUrl,
|
|
345
351
|
entityUrl,
|
|
346
|
-
initialOffset
|
|
352
|
+
initialOffset,
|
|
353
|
+
headers
|
|
347
354
|
}).then((result) => {
|
|
348
355
|
if (cancelled) {
|
|
349
356
|
result.close();
|
|
@@ -361,7 +368,8 @@ function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
|
361
368
|
}, [
|
|
362
369
|
baseUrl,
|
|
363
370
|
entityUrl,
|
|
364
|
-
initialOffset
|
|
371
|
+
initialOffset,
|
|
372
|
+
headers
|
|
365
373
|
]);
|
|
366
374
|
if (error) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ink.Box, {
|
|
367
375
|
flexDirection: "column",
|
|
@@ -378,15 +386,17 @@ function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
|
378
386
|
db,
|
|
379
387
|
entityUrl,
|
|
380
388
|
baseUrl,
|
|
381
|
-
identity
|
|
389
|
+
identity,
|
|
390
|
+
headers
|
|
382
391
|
});
|
|
383
392
|
}
|
|
384
393
|
function renderObserve(opts) {
|
|
385
|
-
const { entityUrl, baseUrl, identity, initialOffset } = opts;
|
|
394
|
+
const { entityUrl, baseUrl, identity, headers, initialOffset } = opts;
|
|
386
395
|
const app = (0, ink.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ObserveApp, {
|
|
387
396
|
entityUrl,
|
|
388
397
|
baseUrl,
|
|
389
398
|
identity,
|
|
399
|
+
headers,
|
|
390
400
|
initialOffset
|
|
391
401
|
}));
|
|
392
402
|
process.on(`SIGINT`, () => {
|
package/dist/observe-ui.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityStreamDB } from "./entity-stream-db-
|
|
1
|
+
import { EntityStreamDB } from "./entity-stream-db-BV4N31MR.cjs";
|
|
2
2
|
import { EntityTimelineContentItem, MessageReceived } from "@electric-ax/agents-runtime";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
@@ -40,18 +40,21 @@ declare function MessageInput({
|
|
|
40
40
|
baseUrl,
|
|
41
41
|
entityUrl,
|
|
42
42
|
identity,
|
|
43
|
+
headers,
|
|
43
44
|
disabled
|
|
44
45
|
}: {
|
|
45
46
|
db: EntityStreamDB;
|
|
46
47
|
baseUrl: string;
|
|
47
48
|
entityUrl: string;
|
|
48
49
|
identity: string;
|
|
50
|
+
headers?: Record<string, string>;
|
|
49
51
|
disabled: boolean;
|
|
50
52
|
}): React.ReactElement;
|
|
51
53
|
declare function renderObserve(opts: {
|
|
52
54
|
entityUrl: string;
|
|
53
55
|
baseUrl: string;
|
|
54
56
|
identity: string;
|
|
57
|
+
headers?: Record<string, string>;
|
|
55
58
|
initialOffset?: string;
|
|
56
59
|
}): void;
|
|
57
60
|
|
package/dist/observe-ui.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityStreamDB } from "./entity-stream-db-
|
|
1
|
+
import { EntityStreamDB } from "./entity-stream-db-Bl6AT5hR.js";
|
|
2
2
|
import { EntityTimelineContentItem, MessageReceived } from "@electric-ax/agents-runtime";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
@@ -40,18 +40,21 @@ declare function MessageInput({
|
|
|
40
40
|
baseUrl,
|
|
41
41
|
entityUrl,
|
|
42
42
|
identity,
|
|
43
|
+
headers,
|
|
43
44
|
disabled
|
|
44
45
|
}: {
|
|
45
46
|
db: EntityStreamDB;
|
|
46
47
|
baseUrl: string;
|
|
47
48
|
entityUrl: string;
|
|
48
49
|
identity: string;
|
|
50
|
+
headers?: Record<string, string>;
|
|
49
51
|
disabled: boolean;
|
|
50
52
|
}): React.ReactElement;
|
|
51
53
|
declare function renderObserve(opts: {
|
|
52
54
|
entityUrl: string;
|
|
53
55
|
baseUrl: string;
|
|
54
56
|
identity: string;
|
|
57
|
+
headers?: Record<string, string>;
|
|
55
58
|
initialOffset?: string;
|
|
56
59
|
}): void;
|
|
57
60
|
|
package/dist/observe-ui.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { entityApiUrl } from "./entity-api-DWMhkYbl.js";
|
|
2
|
+
import { createEntityStreamDB } from "./entity-stream-db-CDOlZYc2.js";
|
|
2
3
|
import { createOptimisticAction } from "@durable-streams/state";
|
|
3
4
|
import { buildSections, createEntityIncludesQuery, normalizeEntityTimelineData } from "@electric-ax/agents-runtime";
|
|
4
5
|
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -116,7 +117,7 @@ function ToolResultView({ result }) {
|
|
|
116
117
|
}) : null]
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
|
-
function MessageInput({ db, baseUrl, entityUrl, identity, disabled }) {
|
|
120
|
+
function MessageInput({ db, baseUrl, entityUrl, identity, headers, disabled }) {
|
|
120
121
|
const [value, setValue] = useState(``);
|
|
121
122
|
const [error, setError] = useState(null);
|
|
122
123
|
const sendAction = useMemo(() => createOptimisticAction({
|
|
@@ -129,9 +130,12 @@ function MessageInput({ db, baseUrl, entityUrl, identity, disabled }) {
|
|
|
129
130
|
});
|
|
130
131
|
},
|
|
131
132
|
mutationFn: async ({ text }) => {
|
|
132
|
-
const res = await fetch(
|
|
133
|
+
const res = await fetch(entityApiUrl(baseUrl, entityUrl, `/send`), {
|
|
133
134
|
method: `POST`,
|
|
134
|
-
headers: {
|
|
135
|
+
headers: {
|
|
136
|
+
"content-type": `application/json`,
|
|
137
|
+
...headers
|
|
138
|
+
},
|
|
135
139
|
body: JSON.stringify({
|
|
136
140
|
from: identity,
|
|
137
141
|
payload: { text }
|
|
@@ -155,7 +159,8 @@ function MessageInput({ db, baseUrl, entityUrl, identity, disabled }) {
|
|
|
155
159
|
db,
|
|
156
160
|
baseUrl,
|
|
157
161
|
entityUrl,
|
|
158
|
-
identity
|
|
162
|
+
identity,
|
|
163
|
+
headers
|
|
159
164
|
]);
|
|
160
165
|
useInput((input, key) => {
|
|
161
166
|
if (disabled) return;
|
|
@@ -254,7 +259,7 @@ function WakeView({ section }) {
|
|
|
254
259
|
})]
|
|
255
260
|
});
|
|
256
261
|
}
|
|
257
|
-
function ObserveView({ db, entityUrl, baseUrl, identity }) {
|
|
262
|
+
function ObserveView({ db, entityUrl, baseUrl, identity, headers }) {
|
|
258
263
|
const timelineQuery = useMemo(() => createEntityIncludesQuery(db), [db]);
|
|
259
264
|
const { data: timelineRows = [] } = useLiveQuery(timelineQuery, [timelineQuery]);
|
|
260
265
|
const timelineData = normalizeEntityTimelineData(timelineRows[0] ?? {
|
|
@@ -327,12 +332,13 @@ function ObserveView({ db, entityUrl, baseUrl, identity }) {
|
|
|
327
332
|
baseUrl,
|
|
328
333
|
entityUrl,
|
|
329
334
|
identity,
|
|
335
|
+
headers,
|
|
330
336
|
disabled: closed
|
|
331
337
|
})
|
|
332
338
|
]
|
|
333
339
|
});
|
|
334
340
|
}
|
|
335
|
-
function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
341
|
+
function ObserveApp({ entityUrl, baseUrl, identity, headers, initialOffset }) {
|
|
336
342
|
const [db, setDb] = useState(null);
|
|
337
343
|
const [error, setError] = useState(null);
|
|
338
344
|
const closeRef = useRef(null);
|
|
@@ -341,7 +347,8 @@ function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
|
341
347
|
createEntityStreamDB({
|
|
342
348
|
baseUrl,
|
|
343
349
|
entityUrl,
|
|
344
|
-
initialOffset
|
|
350
|
+
initialOffset,
|
|
351
|
+
headers
|
|
345
352
|
}).then((result) => {
|
|
346
353
|
if (cancelled) {
|
|
347
354
|
result.close();
|
|
@@ -359,7 +366,8 @@ function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
|
359
366
|
}, [
|
|
360
367
|
baseUrl,
|
|
361
368
|
entityUrl,
|
|
362
|
-
initialOffset
|
|
369
|
+
initialOffset,
|
|
370
|
+
headers
|
|
363
371
|
]);
|
|
364
372
|
if (error) return /* @__PURE__ */ jsx(Box, {
|
|
365
373
|
flexDirection: "column",
|
|
@@ -376,15 +384,17 @@ function ObserveApp({ entityUrl, baseUrl, identity, initialOffset }) {
|
|
|
376
384
|
db,
|
|
377
385
|
entityUrl,
|
|
378
386
|
baseUrl,
|
|
379
|
-
identity
|
|
387
|
+
identity,
|
|
388
|
+
headers
|
|
380
389
|
});
|
|
381
390
|
}
|
|
382
391
|
function renderObserve(opts) {
|
|
383
|
-
const { entityUrl, baseUrl, identity, initialOffset } = opts;
|
|
392
|
+
const { entityUrl, baseUrl, identity, headers, initialOffset } = opts;
|
|
384
393
|
const app = render(/* @__PURE__ */ jsx(ObserveApp, {
|
|
385
394
|
entityUrl,
|
|
386
395
|
baseUrl,
|
|
387
396
|
identity,
|
|
397
|
+
headers,
|
|
388
398
|
initialOffset
|
|
389
399
|
}));
|
|
390
400
|
process.on(`SIGINT`, () => {
|
package/dist/start.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
3
|
-
const require_env = require('./env-
|
|
3
|
+
const require_env = require('./env-CFKgT8o2.cjs');
|
|
4
|
+
const __electric_ax_agents_runtime = require_chunk.__toESM(require("@electric-ax/agents-runtime"));
|
|
4
5
|
const node_url = require_chunk.__toESM(require("node:url"));
|
|
5
6
|
const node_child_process = require_chunk.__toESM(require("node:child_process"));
|
|
6
7
|
const __electric_ax_agents = require_chunk.__toESM(require("@electric-ax/agents"));
|
|
@@ -19,19 +20,10 @@ const ELECTRIC_AGENTS_SERVER_IMAGE_TAG = `latest`;
|
|
|
19
20
|
//#endregion
|
|
20
21
|
//#region src/start.ts
|
|
21
22
|
const DEFAULT_ELECTRIC_AGENTS_PORT = 4437;
|
|
22
|
-
const DEFAULT_BUILTIN_AGENTS_PORT = 4448;
|
|
23
|
-
const DEFAULT_BUILTIN_AGENTS_HOST = `0.0.0.0`;
|
|
24
23
|
const DEFAULT_COMPOSE_PROJECT_NAME = `electric-agents`;
|
|
24
|
+
const DEFAULT_PULL_WAKE_RUNNER_ID = `builtin-agents`;
|
|
25
|
+
const DEFAULT_PULL_WAKE_OWNER_ID = `builtin-agents`;
|
|
25
26
|
const DOCKER_COMPOSE_FILE = (0, node_url.fileURLToPath)(new URL(`../docker-compose.full.yml`, require("url").pathToFileURL(__filename).href));
|
|
26
|
-
function resolveBuiltinAgentsPort(env = process.env, fileEnv = require_env.readDotEnvFile()) {
|
|
27
|
-
const raw = env.ELECTRIC_AGENTS_BUILTIN_PORT?.trim() || fileEnv.ELECTRIC_AGENTS_BUILTIN_PORT?.trim();
|
|
28
|
-
const parsed = raw ? Number(raw) : DEFAULT_BUILTIN_AGENTS_PORT;
|
|
29
|
-
if (!Number.isInteger(parsed) || parsed <= 0) throw new Error(`ELECTRIC_AGENTS_BUILTIN_PORT must be a positive integer`);
|
|
30
|
-
return parsed;
|
|
31
|
-
}
|
|
32
|
-
function resolveBuiltinAgentsHost(env = process.env, fileEnv = require_env.readDotEnvFile()) {
|
|
33
|
-
return env.ELECTRIC_AGENTS_BUILTIN_HOST?.trim() || fileEnv.ELECTRIC_AGENTS_BUILTIN_HOST?.trim() || DEFAULT_BUILTIN_AGENTS_HOST;
|
|
34
|
-
}
|
|
35
27
|
function resolveElectricAgentsPort(env = process.env, fileEnv = require_env.readDotEnvFile()) {
|
|
36
28
|
const raw = env.ELECTRIC_AGENTS_PORT?.trim() || fileEnv.ELECTRIC_AGENTS_PORT?.trim();
|
|
37
29
|
const parsed = raw ? Number(raw) : DEFAULT_ELECTRIC_AGENTS_PORT;
|
|
@@ -54,12 +46,61 @@ function getStoppedEnvironmentMessage(stopped) {
|
|
|
54
46
|
}
|
|
55
47
|
function getStartedBuiltinAgentsMessage(started) {
|
|
56
48
|
return [
|
|
57
|
-
`Builtin
|
|
58
|
-
`
|
|
49
|
+
`Builtin agents pull-wake runner is up.`,
|
|
50
|
+
`Runner: ${started.runnerId}`,
|
|
51
|
+
`Runtime: ${started.url}`,
|
|
59
52
|
`Registers with: ${started.agentServerUrl}`,
|
|
60
53
|
`Press Ctrl-C to stop.`
|
|
61
54
|
].join(`\n`);
|
|
62
55
|
}
|
|
56
|
+
function readConfigValue(env, fileEnv, names) {
|
|
57
|
+
for (const name of names) {
|
|
58
|
+
const value = env[name]?.trim() || fileEnv[name]?.trim();
|
|
59
|
+
if (value) return value;
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
function runnerIdFromIdentity(identity) {
|
|
64
|
+
if (!identity) return DEFAULT_PULL_WAKE_RUNNER_ID;
|
|
65
|
+
const slug = identity.toLowerCase().replace(/[^a-z0-9._-]+/g, `-`).replace(/^-+|-+$/g, ``);
|
|
66
|
+
return slug ? `builtin-${slug}` : DEFAULT_PULL_WAKE_RUNNER_ID;
|
|
67
|
+
}
|
|
68
|
+
function resolvePullWakeRunnerId(env = process.env, fileEnv = require_env.readDotEnvFile()) {
|
|
69
|
+
return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PULL_WAKE_RUNNER_ID`, `PULL_WAKE_RUNNER_ID`]) ?? runnerIdFromIdentity(readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]));
|
|
70
|
+
}
|
|
71
|
+
function resolvePullWakeOwnerId(env = process.env, fileEnv = require_env.readDotEnvFile()) {
|
|
72
|
+
return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]) ?? DEFAULT_PULL_WAKE_OWNER_ID;
|
|
73
|
+
}
|
|
74
|
+
function parseAdditionalServerHeaders(env, fileEnv) {
|
|
75
|
+
const raw = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_SERVER_HEADERS`]);
|
|
76
|
+
if (!raw) return void 0;
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(raw);
|
|
80
|
+
} catch {
|
|
81
|
+
throw new Error(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected JSON`);
|
|
82
|
+
}
|
|
83
|
+
if (!parsed || typeof parsed !== `object` || Array.isArray(parsed)) throw new Error(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected a JSON object`);
|
|
84
|
+
const headers = new Headers();
|
|
85
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
86
|
+
if (typeof value !== `string`) throw new Error(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: header "${name}" must be a string`);
|
|
87
|
+
headers.set(name, value);
|
|
88
|
+
}
|
|
89
|
+
const normalized = Object.fromEntries(headers.entries());
|
|
90
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
91
|
+
}
|
|
92
|
+
function mergeHeaders(...sources) {
|
|
93
|
+
const headers = new Headers();
|
|
94
|
+
for (const source of sources) {
|
|
95
|
+
if (!source) continue;
|
|
96
|
+
new Headers(source).forEach((value, key) => headers.set(key, value));
|
|
97
|
+
}
|
|
98
|
+
const merged = Object.fromEntries(headers.entries());
|
|
99
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
100
|
+
}
|
|
101
|
+
function hasHeader(headers, name) {
|
|
102
|
+
return headers ? new Headers(headers).has(name) : false;
|
|
103
|
+
}
|
|
63
104
|
function resolveComposeProjectName(_cwd = process.cwd(), env = process.env) {
|
|
64
105
|
const explicit = env.ELECTRIC_AGENTS_COMPOSE_PROJECT?.trim();
|
|
65
106
|
if (explicit) return explicit;
|
|
@@ -94,11 +135,14 @@ async function waitForElectricAgentsServer(baseUrl, options = {}) {
|
|
|
94
135
|
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
95
136
|
const intervalMs = options.intervalMs ?? 1e3;
|
|
96
137
|
const deadline = Date.now() + timeoutMs;
|
|
97
|
-
const healthUrl =
|
|
138
|
+
const healthUrl = (0, __electric_ax_agents_runtime.appendPathToUrl)(baseUrl, `/_electric/health`);
|
|
98
139
|
let lastError = null;
|
|
99
140
|
while (Date.now() < deadline) {
|
|
100
141
|
try {
|
|
101
|
-
const response = await fetchImpl(healthUrl, {
|
|
142
|
+
const response = await fetchImpl(healthUrl, {
|
|
143
|
+
headers: options.headers,
|
|
144
|
+
signal: AbortSignal.timeout(5e3)
|
|
145
|
+
});
|
|
102
146
|
if (response.ok) return;
|
|
103
147
|
lastError = `healthcheck returned ${response.status}`;
|
|
104
148
|
} catch (error) {
|
|
@@ -181,23 +225,29 @@ async function startBuiltinAgentsServer(options, params = {}) {
|
|
|
181
225
|
const cwd = params.cwd ?? process.cwd();
|
|
182
226
|
const fileEnv = require_env.readDotEnvFile(cwd);
|
|
183
227
|
const anthropicApiKey = require_env.resolveAnthropicApiKey(options, env, fileEnv);
|
|
184
|
-
const
|
|
185
|
-
const
|
|
228
|
+
const runnerId = resolvePullWakeRunnerId(env, fileEnv);
|
|
229
|
+
const ownerUserId = resolvePullWakeOwnerId(env, fileEnv);
|
|
230
|
+
const serverHeaders = mergeHeaders(parseAdditionalServerHeaders(env, fileEnv));
|
|
186
231
|
const agentServerUrl = params.agentServerUrl ?? env.ELECTRIC_AGENTS_URL?.trim() ?? `http://localhost:${resolveElectricAgentsPort(env, fileEnv)}`;
|
|
187
232
|
process.env.ANTHROPIC_API_KEY = anthropicApiKey;
|
|
188
|
-
await waitForElectricAgentsServer(agentServerUrl);
|
|
233
|
+
await waitForElectricAgentsServer(agentServerUrl, { headers: serverHeaders });
|
|
189
234
|
const server = new __electric_ax_agents.BuiltinAgentsServer({
|
|
190
235
|
agentServerUrl,
|
|
191
|
-
host,
|
|
192
|
-
port,
|
|
193
236
|
workingDirectory: cwd,
|
|
194
|
-
loadProjectMcpConfig: true
|
|
237
|
+
loadProjectMcpConfig: true,
|
|
238
|
+
pullWake: {
|
|
239
|
+
runnerId,
|
|
240
|
+
ownerUserId,
|
|
241
|
+
registerRunner: true,
|
|
242
|
+
headers: serverHeaders,
|
|
243
|
+
claimHeaders: serverHeaders,
|
|
244
|
+
claimTokenHeader: hasHeader(serverHeaders, `authorization`) ? `electric-claim-token` : void 0
|
|
245
|
+
}
|
|
195
246
|
});
|
|
196
|
-
await server.start();
|
|
247
|
+
const url = await server.start();
|
|
197
248
|
const started = {
|
|
198
|
-
|
|
199
|
-
url
|
|
200
|
-
registeredBaseUrl: server.registeredBaseUrl,
|
|
249
|
+
runnerId,
|
|
250
|
+
url,
|
|
201
251
|
agentServerUrl
|
|
202
252
|
};
|
|
203
253
|
if (params.printStartedMessage ?? true) console.log(getStartedBuiltinAgentsMessage(started));
|
|
@@ -211,10 +261,10 @@ exports.getStartedEnvironmentMessage = getStartedEnvironmentMessage
|
|
|
211
261
|
exports.getStoppedEnvironmentMessage = getStoppedEnvironmentMessage
|
|
212
262
|
exports.readDotEnvFile = require_env.readDotEnvFile
|
|
213
263
|
exports.resolveAnthropicApiKey = require_env.resolveAnthropicApiKey
|
|
214
|
-
exports.resolveBuiltinAgentsHost = resolveBuiltinAgentsHost
|
|
215
|
-
exports.resolveBuiltinAgentsPort = resolveBuiltinAgentsPort
|
|
216
264
|
exports.resolveComposeProjectName = resolveComposeProjectName
|
|
217
265
|
exports.resolveElectricAgentsPort = resolveElectricAgentsPort
|
|
266
|
+
exports.resolvePullWakeOwnerId = resolvePullWakeOwnerId
|
|
267
|
+
exports.resolvePullWakeRunnerId = resolvePullWakeRunnerId
|
|
218
268
|
exports.startBuiltinAgentsServer = startBuiltinAgentsServer
|
|
219
269
|
exports.startElectricAgentsDevEnvironment = startElectricAgentsDevEnvironment
|
|
220
270
|
exports.stopElectricAgentsDevEnvironment = stopElectricAgentsDevEnvironment
|
package/dist/start.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey,
|
|
2
|
-
export { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey,
|
|
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 };
|
package/dist/start.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey,
|
|
2
|
-
export { StartedBuiltinAgentsEnvironment, StartedDevEnvironment, StoppedDevEnvironment, getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey,
|
|
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 };
|
package/dist/start.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readDotEnvFile$1 as readDotEnvFile, resolveAnthropicApiKey$1 as resolveAnthropicApiKey } from "./env-
|
|
1
|
+
import { readDotEnvFile$1 as readDotEnvFile, resolveAnthropicApiKey$1 as resolveAnthropicApiKey } from "./env-DIhTv987.js";
|
|
2
|
+
import { appendPathToUrl } from "@electric-ax/agents-runtime";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { spawn } from "node:child_process";
|
|
4
5
|
import { BuiltinAgentsServer } from "@electric-ax/agents";
|
|
@@ -17,19 +18,10 @@ const ELECTRIC_AGENTS_SERVER_IMAGE_TAG = `latest`;
|
|
|
17
18
|
//#endregion
|
|
18
19
|
//#region src/start.ts
|
|
19
20
|
const DEFAULT_ELECTRIC_AGENTS_PORT = 4437;
|
|
20
|
-
const DEFAULT_BUILTIN_AGENTS_PORT = 4448;
|
|
21
|
-
const DEFAULT_BUILTIN_AGENTS_HOST = `0.0.0.0`;
|
|
22
21
|
const DEFAULT_COMPOSE_PROJECT_NAME = `electric-agents`;
|
|
22
|
+
const DEFAULT_PULL_WAKE_RUNNER_ID = `builtin-agents`;
|
|
23
|
+
const DEFAULT_PULL_WAKE_OWNER_ID = `builtin-agents`;
|
|
23
24
|
const DOCKER_COMPOSE_FILE = fileURLToPath(new URL(`../docker-compose.full.yml`, import.meta.url));
|
|
24
|
-
function resolveBuiltinAgentsPort(env = process.env, fileEnv = readDotEnvFile()) {
|
|
25
|
-
const raw = env.ELECTRIC_AGENTS_BUILTIN_PORT?.trim() || fileEnv.ELECTRIC_AGENTS_BUILTIN_PORT?.trim();
|
|
26
|
-
const parsed = raw ? Number(raw) : DEFAULT_BUILTIN_AGENTS_PORT;
|
|
27
|
-
if (!Number.isInteger(parsed) || parsed <= 0) throw new Error(`ELECTRIC_AGENTS_BUILTIN_PORT must be a positive integer`);
|
|
28
|
-
return parsed;
|
|
29
|
-
}
|
|
30
|
-
function resolveBuiltinAgentsHost(env = process.env, fileEnv = readDotEnvFile()) {
|
|
31
|
-
return env.ELECTRIC_AGENTS_BUILTIN_HOST?.trim() || fileEnv.ELECTRIC_AGENTS_BUILTIN_HOST?.trim() || DEFAULT_BUILTIN_AGENTS_HOST;
|
|
32
|
-
}
|
|
33
25
|
function resolveElectricAgentsPort(env = process.env, fileEnv = readDotEnvFile()) {
|
|
34
26
|
const raw = env.ELECTRIC_AGENTS_PORT?.trim() || fileEnv.ELECTRIC_AGENTS_PORT?.trim();
|
|
35
27
|
const parsed = raw ? Number(raw) : DEFAULT_ELECTRIC_AGENTS_PORT;
|
|
@@ -52,12 +44,61 @@ function getStoppedEnvironmentMessage(stopped) {
|
|
|
52
44
|
}
|
|
53
45
|
function getStartedBuiltinAgentsMessage(started) {
|
|
54
46
|
return [
|
|
55
|
-
`Builtin
|
|
56
|
-
`
|
|
47
|
+
`Builtin agents pull-wake runner is up.`,
|
|
48
|
+
`Runner: ${started.runnerId}`,
|
|
49
|
+
`Runtime: ${started.url}`,
|
|
57
50
|
`Registers with: ${started.agentServerUrl}`,
|
|
58
51
|
`Press Ctrl-C to stop.`
|
|
59
52
|
].join(`\n`);
|
|
60
53
|
}
|
|
54
|
+
function readConfigValue(env, fileEnv, names) {
|
|
55
|
+
for (const name of names) {
|
|
56
|
+
const value = env[name]?.trim() || fileEnv[name]?.trim();
|
|
57
|
+
if (value) return value;
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
function runnerIdFromIdentity(identity) {
|
|
62
|
+
if (!identity) return DEFAULT_PULL_WAKE_RUNNER_ID;
|
|
63
|
+
const slug = identity.toLowerCase().replace(/[^a-z0-9._-]+/g, `-`).replace(/^-+|-+$/g, ``);
|
|
64
|
+
return slug ? `builtin-${slug}` : DEFAULT_PULL_WAKE_RUNNER_ID;
|
|
65
|
+
}
|
|
66
|
+
function resolvePullWakeRunnerId(env = process.env, fileEnv = readDotEnvFile()) {
|
|
67
|
+
return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_PULL_WAKE_RUNNER_ID`, `PULL_WAKE_RUNNER_ID`]) ?? runnerIdFromIdentity(readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]));
|
|
68
|
+
}
|
|
69
|
+
function resolvePullWakeOwnerId(env = process.env, fileEnv = readDotEnvFile()) {
|
|
70
|
+
return readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_IDENTITY`]) ?? DEFAULT_PULL_WAKE_OWNER_ID;
|
|
71
|
+
}
|
|
72
|
+
function parseAdditionalServerHeaders(env, fileEnv) {
|
|
73
|
+
const raw = readConfigValue(env, fileEnv, [`ELECTRIC_AGENTS_SERVER_HEADERS`]);
|
|
74
|
+
if (!raw) return void 0;
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = JSON.parse(raw);
|
|
78
|
+
} catch {
|
|
79
|
+
throw new Error(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected JSON`);
|
|
80
|
+
}
|
|
81
|
+
if (!parsed || typeof parsed !== `object` || Array.isArray(parsed)) throw new Error(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: expected a JSON object`);
|
|
82
|
+
const headers = new Headers();
|
|
83
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
84
|
+
if (typeof value !== `string`) throw new Error(`Invalid ELECTRIC_AGENTS_SERVER_HEADERS: header "${name}" must be a string`);
|
|
85
|
+
headers.set(name, value);
|
|
86
|
+
}
|
|
87
|
+
const normalized = Object.fromEntries(headers.entries());
|
|
88
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
89
|
+
}
|
|
90
|
+
function mergeHeaders(...sources) {
|
|
91
|
+
const headers = new Headers();
|
|
92
|
+
for (const source of sources) {
|
|
93
|
+
if (!source) continue;
|
|
94
|
+
new Headers(source).forEach((value, key) => headers.set(key, value));
|
|
95
|
+
}
|
|
96
|
+
const merged = Object.fromEntries(headers.entries());
|
|
97
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
98
|
+
}
|
|
99
|
+
function hasHeader(headers, name) {
|
|
100
|
+
return headers ? new Headers(headers).has(name) : false;
|
|
101
|
+
}
|
|
61
102
|
function resolveComposeProjectName(_cwd = process.cwd(), env = process.env) {
|
|
62
103
|
const explicit = env.ELECTRIC_AGENTS_COMPOSE_PROJECT?.trim();
|
|
63
104
|
if (explicit) return explicit;
|
|
@@ -92,11 +133,14 @@ async function waitForElectricAgentsServer(baseUrl, options = {}) {
|
|
|
92
133
|
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
93
134
|
const intervalMs = options.intervalMs ?? 1e3;
|
|
94
135
|
const deadline = Date.now() + timeoutMs;
|
|
95
|
-
const healthUrl =
|
|
136
|
+
const healthUrl = appendPathToUrl(baseUrl, `/_electric/health`);
|
|
96
137
|
let lastError = null;
|
|
97
138
|
while (Date.now() < deadline) {
|
|
98
139
|
try {
|
|
99
|
-
const response = await fetchImpl(healthUrl, {
|
|
140
|
+
const response = await fetchImpl(healthUrl, {
|
|
141
|
+
headers: options.headers,
|
|
142
|
+
signal: AbortSignal.timeout(5e3)
|
|
143
|
+
});
|
|
100
144
|
if (response.ok) return;
|
|
101
145
|
lastError = `healthcheck returned ${response.status}`;
|
|
102
146
|
} catch (error) {
|
|
@@ -179,23 +223,29 @@ async function startBuiltinAgentsServer(options, params = {}) {
|
|
|
179
223
|
const cwd = params.cwd ?? process.cwd();
|
|
180
224
|
const fileEnv = readDotEnvFile(cwd);
|
|
181
225
|
const anthropicApiKey = resolveAnthropicApiKey(options, env, fileEnv);
|
|
182
|
-
const
|
|
183
|
-
const
|
|
226
|
+
const runnerId = resolvePullWakeRunnerId(env, fileEnv);
|
|
227
|
+
const ownerUserId = resolvePullWakeOwnerId(env, fileEnv);
|
|
228
|
+
const serverHeaders = mergeHeaders(parseAdditionalServerHeaders(env, fileEnv));
|
|
184
229
|
const agentServerUrl = params.agentServerUrl ?? env.ELECTRIC_AGENTS_URL?.trim() ?? `http://localhost:${resolveElectricAgentsPort(env, fileEnv)}`;
|
|
185
230
|
process.env.ANTHROPIC_API_KEY = anthropicApiKey;
|
|
186
|
-
await waitForElectricAgentsServer(agentServerUrl);
|
|
231
|
+
await waitForElectricAgentsServer(agentServerUrl, { headers: serverHeaders });
|
|
187
232
|
const server = new BuiltinAgentsServer({
|
|
188
233
|
agentServerUrl,
|
|
189
|
-
host,
|
|
190
|
-
port,
|
|
191
234
|
workingDirectory: cwd,
|
|
192
|
-
loadProjectMcpConfig: true
|
|
235
|
+
loadProjectMcpConfig: true,
|
|
236
|
+
pullWake: {
|
|
237
|
+
runnerId,
|
|
238
|
+
ownerUserId,
|
|
239
|
+
registerRunner: true,
|
|
240
|
+
headers: serverHeaders,
|
|
241
|
+
claimHeaders: serverHeaders,
|
|
242
|
+
claimTokenHeader: hasHeader(serverHeaders, `authorization`) ? `electric-claim-token` : void 0
|
|
243
|
+
}
|
|
193
244
|
});
|
|
194
|
-
await server.start();
|
|
245
|
+
const url = await server.start();
|
|
195
246
|
const started = {
|
|
196
|
-
|
|
197
|
-
url
|
|
198
|
-
registeredBaseUrl: server.registeredBaseUrl,
|
|
247
|
+
runnerId,
|
|
248
|
+
url,
|
|
199
249
|
agentServerUrl
|
|
200
250
|
};
|
|
201
251
|
if (params.printStartedMessage ?? true) console.log(getStartedBuiltinAgentsMessage(started));
|
|
@@ -204,4 +254,4 @@ async function startBuiltinAgentsServer(options, params = {}) {
|
|
|
204
254
|
}
|
|
205
255
|
|
|
206
256
|
//#endregion
|
|
207
|
-
export { getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey,
|
|
257
|
+
export { getStartedBuiltinAgentsMessage, getStartedEnvironmentMessage, getStoppedEnvironmentMessage, readDotEnvFile, resolveAnthropicApiKey, resolveComposeProjectName, resolveElectricAgentsPort, resolvePullWakeOwnerId, resolvePullWakeRunnerId, startBuiltinAgentsServer, startElectricAgentsDevEnvironment, stopElectricAgentsDevEnvironment, waitForElectricAgentsServer };
|
package/docker-compose.full.yml
CHANGED
|
@@ -38,7 +38,7 @@ services:
|
|
|
38
38
|
|
|
39
39
|
electric-agents:
|
|
40
40
|
image: electricax/agents-server:${ELECTRIC_AGENTS_SERVER_IMAGE_TAG:-latest}
|
|
41
|
-
pull_policy:
|
|
41
|
+
pull_policy: ${ELECTRIC_AGENTS_SERVER_PULL_POLICY:-missing}
|
|
42
42
|
restart: unless-stopped
|
|
43
43
|
extra_hosts:
|
|
44
44
|
- 'host.docker.internal:host-gateway'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electric-ax",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "CLI for Electric Agents",
|
|
5
5
|
"author": "ElectricSQL team and contributors",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@durable-streams/client": "
|
|
41
|
-
"@durable-streams/state": "
|
|
40
|
+
"@durable-streams/client": "https://pkg.pr.new/durable-streams/durable-streams/@durable-streams/client@350",
|
|
41
|
+
"@durable-streams/state": "https://pkg.pr.new/durable-streams/durable-streams/@durable-streams/state@350",
|
|
42
42
|
"@electric-sql/client": "^1.5.17",
|
|
43
43
|
"@tanstack/db": "^0.6.4",
|
|
44
44
|
"@tanstack/react-db": "^0.1.82",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"ink": "^6.8.0",
|
|
47
47
|
"omelette": "^0.4.17",
|
|
48
48
|
"react": "^19.2.0",
|
|
49
|
-
"@electric-ax/agents": "0.
|
|
50
|
-
"@electric-ax/agents-runtime": "0.1
|
|
49
|
+
"@electric-ax/agents": "0.4.1",
|
|
50
|
+
"@electric-ax/agents-runtime": "0.2.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@vitest/coverage-v8": "^4.1.0",
|
|
File without changes
|
|
File without changes
|