@agent-relay/sdk 3.2.22 → 4.0.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.
Files changed (92) hide show
  1. package/README.md +10 -3
  2. package/bin/agent-relay-broker-darwin-arm64 +0 -0
  3. package/bin/agent-relay-broker-darwin-x64 +0 -0
  4. package/bin/agent-relay-broker-linux-arm64 +0 -0
  5. package/bin/agent-relay-broker-linux-x64 +0 -0
  6. package/dist/broker-path.d.ts +3 -2
  7. package/dist/broker-path.d.ts.map +1 -1
  8. package/dist/broker-path.js +119 -32
  9. package/dist/broker-path.js.map +1 -1
  10. package/dist/client.d.ts +119 -197
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +354 -823
  13. package/dist/client.js.map +1 -1
  14. package/dist/examples/example.js +2 -5
  15. package/dist/examples/example.js.map +1 -1
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +3 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/relay-adapter.d.ts +9 -26
  21. package/dist/relay-adapter.d.ts.map +1 -1
  22. package/dist/relay-adapter.js +75 -47
  23. package/dist/relay-adapter.js.map +1 -1
  24. package/dist/relay.d.ts +26 -6
  25. package/dist/relay.d.ts.map +1 -1
  26. package/dist/relay.js +213 -43
  27. package/dist/relay.js.map +1 -1
  28. package/dist/transport.d.ts +58 -0
  29. package/dist/transport.d.ts.map +1 -0
  30. package/dist/transport.js +184 -0
  31. package/dist/transport.js.map +1 -0
  32. package/dist/types.d.ts +69 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/dist/types.js +5 -0
  35. package/dist/types.js.map +1 -0
  36. package/dist/workflows/__tests__/channel-messenger.test.d.ts +2 -0
  37. package/dist/workflows/__tests__/channel-messenger.test.d.ts.map +1 -0
  38. package/dist/workflows/__tests__/channel-messenger.test.js +117 -0
  39. package/dist/workflows/__tests__/channel-messenger.test.js.map +1 -0
  40. package/dist/workflows/__tests__/run-summary-table.test.js +4 -3
  41. package/dist/workflows/__tests__/run-summary-table.test.js.map +1 -1
  42. package/dist/workflows/__tests__/step-executor.test.d.ts +2 -0
  43. package/dist/workflows/__tests__/step-executor.test.d.ts.map +1 -0
  44. package/dist/workflows/__tests__/step-executor.test.js +378 -0
  45. package/dist/workflows/__tests__/step-executor.test.js.map +1 -0
  46. package/dist/workflows/__tests__/template-resolver.test.d.ts +2 -0
  47. package/dist/workflows/__tests__/template-resolver.test.d.ts.map +1 -0
  48. package/dist/workflows/__tests__/template-resolver.test.js +145 -0
  49. package/dist/workflows/__tests__/template-resolver.test.js.map +1 -0
  50. package/dist/workflows/__tests__/verification.test.d.ts +2 -0
  51. package/dist/workflows/__tests__/verification.test.d.ts.map +1 -0
  52. package/dist/workflows/__tests__/verification.test.js +170 -0
  53. package/dist/workflows/__tests__/verification.test.js.map +1 -0
  54. package/dist/workflows/builder.d.ts +3 -2
  55. package/dist/workflows/builder.d.ts.map +1 -1
  56. package/dist/workflows/builder.js +1 -3
  57. package/dist/workflows/builder.js.map +1 -1
  58. package/dist/workflows/channel-messenger.d.ts +28 -0
  59. package/dist/workflows/channel-messenger.d.ts.map +1 -0
  60. package/dist/workflows/channel-messenger.js +255 -0
  61. package/dist/workflows/channel-messenger.js.map +1 -0
  62. package/dist/workflows/index.d.ts +7 -0
  63. package/dist/workflows/index.d.ts.map +1 -1
  64. package/dist/workflows/index.js +7 -0
  65. package/dist/workflows/index.js.map +1 -1
  66. package/dist/workflows/process-spawner.d.ts +35 -0
  67. package/dist/workflows/process-spawner.d.ts.map +1 -0
  68. package/dist/workflows/process-spawner.js +141 -0
  69. package/dist/workflows/process-spawner.js.map +1 -0
  70. package/dist/workflows/run.d.ts +2 -1
  71. package/dist/workflows/run.d.ts.map +1 -1
  72. package/dist/workflows/run.js.map +1 -1
  73. package/dist/workflows/runner.d.ts +6 -6
  74. package/dist/workflows/runner.d.ts.map +1 -1
  75. package/dist/workflows/runner.js +443 -719
  76. package/dist/workflows/runner.js.map +1 -1
  77. package/dist/workflows/step-executor.d.ts +95 -0
  78. package/dist/workflows/step-executor.d.ts.map +1 -0
  79. package/dist/workflows/step-executor.js +393 -0
  80. package/dist/workflows/step-executor.js.map +1 -0
  81. package/dist/workflows/template-resolver.d.ts +33 -0
  82. package/dist/workflows/template-resolver.d.ts.map +1 -0
  83. package/dist/workflows/template-resolver.js +144 -0
  84. package/dist/workflows/template-resolver.js.map +1 -0
  85. package/dist/workflows/validator.d.ts.map +1 -1
  86. package/dist/workflows/validator.js +17 -2
  87. package/dist/workflows/validator.js.map +1 -1
  88. package/dist/workflows/verification.d.ts +33 -0
  89. package/dist/workflows/verification.d.ts.map +1 -0
  90. package/dist/workflows/verification.js +122 -0
  91. package/dist/workflows/verification.js.map +1 -0
  92. package/package.json +2 -2
package/README.md CHANGED
@@ -80,11 +80,18 @@ For direct broker control:
80
80
  ```ts
81
81
  import { AgentRelayClient } from '@agent-relay/sdk';
82
82
 
83
- const client = await AgentRelayClient.start({
84
- binaryPath: '/path/to/agent-relay-broker', // optional, auto-detected
83
+ // Spawn a local broker and connect over HTTP/WS
84
+ const client = await AgentRelayClient.spawn({
85
+ cwd: '/my/project',
85
86
  channels: ['general'],
86
87
  });
87
88
 
89
+ // Or connect to an already-running broker (reads connection.json)
90
+ // const client = AgentRelayClient.connect({ cwd: '/my/project' });
91
+
92
+ // Or connect to a remote broker directly
93
+ // const client = new AgentRelayClient({ baseUrl: 'http://...', apiKey: 'br_...' });
94
+
88
95
  await client.spawnPty({
89
96
  name: 'Worker1',
90
97
  cli: 'claude',
@@ -104,7 +111,7 @@ Use provider-first spawn helpers and set `transport` when you want headless mode
104
111
  ```ts
105
112
  import { AgentRelayClient } from '@agent-relay/sdk';
106
113
 
107
- const client = await AgentRelayClient.start({
114
+ const client = await AgentRelayClient.spawn({
108
115
  channels: ['general'],
109
116
  });
110
117
 
Binary file
Binary file
Binary file
Binary file
@@ -9,9 +9,10 @@
9
9
  * Resolve the agent-relay-broker binary path.
10
10
  *
11
11
  * Search order:
12
- * 1. SDK's bin/ directory (resolved via createRequire or import.meta.url)
12
+ * 1. SDK's bin/ directory (resolved via CJS globals, createRequire, or import.meta.url)
13
13
  * 2. Platform-specific name (agent-relay-broker-{platform}-{arch}) in bin/
14
- * 3. PATH lookup via `which` / `where`
14
+ * 3. Common Cargo development paths (target/release and target/debug)
15
+ * 4. PATH lookup via `which` / `where`
15
16
  *
16
17
  * @returns Absolute path to the broker binary, or null if not found
17
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"broker-path.d.ts","sourceRoot":"","sources":["../src/broker-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CA+CnD"}
1
+ {"version":3,"file":"broker-path.d.ts","sourceRoot":"","sources":["../src/broker-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAuHH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,IAAI,CA2CnD"}
@@ -6,61 +6,148 @@
6
6
  * const binPath = getBrokerBinaryPath();
7
7
  */
8
8
  import { existsSync } from 'node:fs';
9
- import { join, dirname } from 'node:path';
10
- import { execSync } from 'node:child_process';
9
+ import { join, dirname, resolve } from 'node:path';
10
+ import { execFileSync } from 'node:child_process';
11
11
  import { createRequire } from 'node:module';
12
12
  import { fileURLToPath } from 'node:url';
13
13
  const BROKER_NAME = 'agent-relay-broker';
14
+ function addUniquePath(paths, candidate) {
15
+ if (!candidate || paths.includes(candidate)) {
16
+ return;
17
+ }
18
+ paths.push(candidate);
19
+ }
20
+ function getImportMetaUrl() {
21
+ try {
22
+ return import.meta.url;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ function getCurrentModuleDir() {
29
+ if (typeof __dirname === 'string' && __dirname) {
30
+ return __dirname;
31
+ }
32
+ if (typeof __filename === 'string' && __filename) {
33
+ return dirname(__filename);
34
+ }
35
+ const importMetaUrl = getImportMetaUrl();
36
+ if (!importMetaUrl) {
37
+ return null;
38
+ }
39
+ try {
40
+ return dirname(fileURLToPath(importMetaUrl));
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ }
46
+ function getCurrentModuleReference() {
47
+ if (typeof __filename === 'string' && __filename) {
48
+ return __filename;
49
+ }
50
+ if (typeof __dirname === 'string' && __dirname) {
51
+ return join(__dirname, 'broker-path.js');
52
+ }
53
+ return getImportMetaUrl();
54
+ }
55
+ function getSdkBinDirs() {
56
+ const binDirs = [];
57
+ const currentModuleDir = getCurrentModuleDir();
58
+ if (currentModuleDir) {
59
+ addUniquePath(binDirs, resolve(currentModuleDir, '..', 'bin'));
60
+ }
61
+ const currentModuleReference = getCurrentModuleReference();
62
+ if (currentModuleReference) {
63
+ try {
64
+ const sdkEntry = createRequire(currentModuleReference).resolve('@agent-relay/sdk');
65
+ addUniquePath(binDirs, resolve(dirname(sdkEntry), '..', 'bin'));
66
+ }
67
+ catch {
68
+ // Continue with other resolution strategies.
69
+ }
70
+ }
71
+ const importMetaUrl = getImportMetaUrl();
72
+ if (importMetaUrl) {
73
+ try {
74
+ addUniquePath(binDirs, resolve(dirname(fileURLToPath(importMetaUrl)), '..', 'bin'));
75
+ }
76
+ catch {
77
+ // Continue with other resolution strategies.
78
+ }
79
+ }
80
+ return binDirs;
81
+ }
82
+ function getDevelopmentBinaryPaths(ext, binDirs) {
83
+ const binaryPaths = [];
84
+ const repoRoots = new Set();
85
+ const addRepoRoot = (candidate) => {
86
+ if (!candidate) {
87
+ return;
88
+ }
89
+ const repoRoot = resolve(candidate);
90
+ if (repoRoots.has(repoRoot)) {
91
+ return;
92
+ }
93
+ repoRoots.add(repoRoot);
94
+ addUniquePath(binaryPaths, join(repoRoot, 'target', 'release', `${BROKER_NAME}${ext}`));
95
+ addUniquePath(binaryPaths, join(repoRoot, 'target', 'debug', `${BROKER_NAME}${ext}`));
96
+ };
97
+ addRepoRoot(process.cwd());
98
+ const currentModuleDir = getCurrentModuleDir();
99
+ if (currentModuleDir) {
100
+ addRepoRoot(resolve(currentModuleDir, '..', '..', '..'));
101
+ }
102
+ for (const binDir of binDirs) {
103
+ addRepoRoot(resolve(binDir, '..', '..', '..'));
104
+ }
105
+ return binaryPaths;
106
+ }
14
107
  /**
15
108
  * Resolve the agent-relay-broker binary path.
16
109
  *
17
110
  * Search order:
18
- * 1. SDK's bin/ directory (resolved via createRequire or import.meta.url)
111
+ * 1. SDK's bin/ directory (resolved via CJS globals, createRequire, or import.meta.url)
19
112
  * 2. Platform-specific name (agent-relay-broker-{platform}-{arch}) in bin/
20
- * 3. PATH lookup via `which` / `where`
113
+ * 3. Common Cargo development paths (target/release and target/debug)
114
+ * 4. PATH lookup via `which` / `where`
21
115
  *
22
116
  * @returns Absolute path to the broker binary, or null if not found
23
117
  */
24
118
  export function getBrokerBinaryPath() {
25
- let binDir = null;
26
- try {
27
- // Use createRequire for ESM-compatible require.resolve
28
- const esmRequire = createRequire(import.meta.url);
29
- const sdkEntry = esmRequire.resolve('@agent-relay/sdk');
30
- binDir = join(dirname(sdkEntry), '..', 'bin');
31
- }
32
- catch {
33
- try {
34
- // Fallback: derive from import.meta.url
35
- binDir = join(dirname(dirname(fileURLToPath(import.meta.url))), 'bin');
36
- }
37
- catch {
38
- // Neither method worked
39
- }
40
- }
41
- if (!binDir)
42
- return null;
43
119
  const ext = process.platform === 'win32' ? '.exe' : '';
120
+ const binDirs = getSdkBinDirs();
121
+ const platformSpecific = `${BROKER_NAME}-${process.platform}-${process.arch}${ext}`;
44
122
  // 1. Exact name in bin/
45
- const exactPath = join(binDir, `${BROKER_NAME}${ext}`);
46
- if (existsSync(exactPath)) {
47
- return exactPath;
123
+ for (const binDir of binDirs) {
124
+ const exactPath = join(binDir, `${BROKER_NAME}${ext}`);
125
+ if (existsSync(exactPath)) {
126
+ return exactPath;
127
+ }
48
128
  }
49
129
  // 2. Platform-specific name in bin/
50
- const platformSpecific = `${BROKER_NAME}-${process.platform}-${process.arch}${ext}`;
51
- const platformPath = join(binDir, platformSpecific);
52
- if (existsSync(platformPath)) {
53
- return platformPath;
130
+ for (const binDir of binDirs) {
131
+ const platformPath = join(binDir, platformSpecific);
132
+ if (existsSync(platformPath)) {
133
+ return platformPath;
134
+ }
135
+ }
136
+ // 3. Common development paths for local Cargo builds.
137
+ for (const developmentPath of getDevelopmentBinaryPaths(ext, binDirs)) {
138
+ if (existsSync(developmentPath)) {
139
+ return developmentPath;
140
+ }
54
141
  }
55
- // 3. PATH lookup
142
+ // 4. PATH lookup
56
143
  try {
57
144
  const cmd = process.platform === 'win32' ? 'where' : 'which';
58
- const result = execSync(`${cmd} ${BROKER_NAME}`, {
145
+ const result = execFileSync(cmd, [BROKER_NAME], {
59
146
  encoding: 'utf-8',
60
147
  stdio: ['pipe', 'pipe', 'pipe'],
61
148
  }).trim();
62
149
  if (result) {
63
- return result.split('\n')[0].trim();
150
+ return result.split(/\r?\n/u)[0].trim();
64
151
  }
65
152
  }
66
153
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"broker-path.js","sourceRoot":"","sources":["../src/broker-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB;IACjC,IAAI,MAAM,GAAkB,IAAI,CAAC;IACjC,IAAI,CAAC;QACH,uDAAuD;QACvD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,MAAM,QAAQ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zB,CAAC;IACH,CAAC;IAED,iBAAiB;IACjB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7D,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE;YAC9C,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;SAChC,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,oBAAoB;IACtB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/client.d.ts CHANGED
@@ -1,116 +1,100 @@
1
- import { type AgentRuntime, type BrokerEvent, type BrokerStats, type BrokerStatus, type CrashInsightsResponse, type HeadlessProvider, type ProtocolError, type RestartPolicy, type MessageInjectionMode } from './protocol.js';
1
+ /**
2
+ * AgentRelayClient — single client for communicating with an agent-relay broker
3
+ * over HTTP/WS. Works identically for local and remote brokers.
4
+ *
5
+ * Usage:
6
+ * // Remote broker (Daytona sandbox, cloud, etc.)
7
+ * const client = new AgentRelayClient({ baseUrl, apiKey });
8
+ *
9
+ * // Local broker (spawn and connect)
10
+ * const client = await AgentRelayClient.spawn({ cwd: '/my/project' });
11
+ */
12
+ import type { AgentRuntime, BrokerEvent, BrokerStats, BrokerStatus, CrashInsightsResponse, HeadlessProvider } from './protocol.js';
13
+ import type { SpawnPtyInput, SpawnProviderInput, SendMessageInput, ListAgent } from './types.js';
2
14
  export interface AgentRelayClientOptions {
15
+ baseUrl: string;
16
+ apiKey?: string;
17
+ /** Timeout in ms for HTTP requests. Default: 30000. */
18
+ requestTimeoutMs?: number;
19
+ }
20
+ export interface AgentRelayBrokerInitArgs {
21
+ /** Optional HTTP API port for dashboard proxy (0 = disabled). */
22
+ apiPort?: number;
23
+ /** Bind address for the HTTP API. Defaults to 127.0.0.1 in the broker. */
24
+ apiBind?: string;
25
+ /** Enable persistence for broker state under the working directory. */
26
+ persist?: boolean;
27
+ /** Override the directory used for broker state files. */
28
+ stateDir?: string;
29
+ }
30
+ export interface AgentRelaySpawnOptions {
31
+ /** Path to the agent-relay-broker binary. Auto-resolved if omitted. */
3
32
  binaryPath?: string;
4
- binaryArgs?: string[];
33
+ /** Structured options mapped to the broker's Rust `init` CLI flags. */
34
+ binaryArgs?: AgentRelayBrokerInitArgs;
35
+ /** Broker name. Defaults to cwd basename. */
5
36
  brokerName?: string;
37
+ /** Default channels for spawned agents. */
6
38
  channels?: string[];
39
+ /** Working directory for the broker process. */
7
40
  cwd?: string;
41
+ /** Environment variables for the broker process. */
8
42
  env?: NodeJS.ProcessEnv;
43
+ /** Forward broker stderr to this callback. */
44
+ onStderr?: (line: string) => void;
45
+ /** Timeout in ms to wait for broker to become ready. Default: 15000. */
46
+ startupTimeoutMs?: number;
47
+ /** Timeout in ms for HTTP requests to the broker. Default: 30000. */
9
48
  requestTimeoutMs?: number;
10
- shutdownTimeoutMs?: number;
11
- clientName?: string;
12
- clientVersion?: string;
13
49
  }
14
- export interface SpawnPtyInput {
15
- name: string;
16
- cli: string;
17
- args?: string[];
18
- channels?: string[];
19
- task?: string;
20
- model?: string;
21
- cwd?: string;
22
- team?: string;
23
- shadowOf?: string;
24
- shadowMode?: string;
25
- /** Silence duration in seconds before emitting agent_idle (0 = disabled, default: 30). */
26
- idleThresholdSecs?: number;
27
- /** Auto-restart policy for crashed agents. */
28
- restartPolicy?: RestartPolicy;
29
- /** Name of a previously released agent whose continuity context should be injected. */
30
- continueFrom?: string;
31
- /** When true, skip injecting the relay MCP configuration and protocol prompt into the spawned agent.
32
- * Useful for minor tasks where relay messaging is not needed, saving tokens. */
33
- skipRelayPrompt?: boolean;
34
- }
35
- export interface SpawnHeadlessInput {
36
- name: string;
37
- provider: HeadlessProvider;
38
- args?: string[];
39
- channels?: string[];
40
- task?: string;
41
- /** When true, skip injecting the relay MCP configuration and protocol prompt into the spawned agent.
42
- * Useful for minor tasks where relay messaging is not needed, saving tokens. */
43
- skipRelayPrompt?: boolean;
44
- }
45
- export type AgentTransport = 'pty' | 'headless';
46
- export interface SpawnProviderInput {
47
- name: string;
48
- provider: string;
49
- transport?: AgentTransport;
50
- args?: string[];
51
- channels?: string[];
52
- task?: string;
53
- model?: string;
54
- cwd?: string;
55
- team?: string;
56
- shadowOf?: string;
57
- shadowMode?: string;
58
- idleThresholdSecs?: number;
59
- restartPolicy?: RestartPolicy;
60
- continueFrom?: string;
61
- /** When true, skip injecting the relay MCP configuration and protocol prompt into the spawned agent.
62
- * Useful for minor tasks where relay messaging is not needed, saving tokens. */
63
- skipRelayPrompt?: boolean;
64
- }
65
- export interface SendMessageInput {
66
- to: string;
67
- text: string;
68
- from?: string;
69
- threadId?: string;
70
- workspaceId?: string;
71
- workspaceAlias?: string;
72
- priority?: number;
73
- data?: Record<string, unknown>;
74
- mode?: MessageInjectionMode;
75
- }
76
- export interface ListAgent {
77
- name: string;
78
- runtime: AgentRuntime;
79
- provider?: HeadlessProvider;
80
- cli?: string;
81
- model?: string;
82
- team?: string;
83
- channels: string[];
84
- parent?: string;
85
- pid?: number;
86
- }
87
- export declare class AgentRelayProtocolError extends Error {
88
- code: string;
89
- retryable: boolean;
90
- data?: unknown;
91
- constructor(payload: ProtocolError);
92
- }
93
- export declare class AgentRelayProcessError extends Error {
94
- constructor(message: string);
50
+ export interface SessionInfo {
51
+ broker_version: string;
52
+ protocol_version: number;
53
+ workspace_key?: string;
54
+ default_workspace_id?: string;
55
+ mode: string;
56
+ uptime_secs: number;
95
57
  }
96
58
  export declare class AgentRelayClient {
97
- private readonly options;
98
- private child?;
99
- private stdoutRl?;
100
- private stderrRl?;
101
- private lastStderrLine?;
102
- private requestSeq;
103
- private pending;
104
- private startingPromise?;
105
- private eventListeners;
106
- private stderrListeners;
107
- private eventBuffer;
108
- private maxBufferSize;
109
- private exitPromise?;
110
- /** The workspace key returned by the broker in its hello_ack response. */
59
+ private readonly transport;
60
+ /** Set after spawn() — the managed child process. */
61
+ private child;
62
+ /** Lease renewal timer (only for spawned brokers). */
63
+ private leaseTimer;
111
64
  workspaceKey?: string;
112
- constructor(options?: AgentRelayClientOptions);
113
- static start(options?: AgentRelayClientOptions): Promise<AgentRelayClient>;
65
+ constructor(options: AgentRelayClientOptions);
66
+ /**
67
+ * Connect to an already-running broker by reading its connection file.
68
+ *
69
+ * The broker writes `connection.json` to its data directory ({cwd}/.agent-relay/
70
+ * in persist mode). This method reads that file to get the URL and API key.
71
+ *
72
+ * @param cwd — project directory (default: process.cwd())
73
+ * @param connectionPath — explicit path to connection.json (overrides cwd)
74
+ */
75
+ static connect(options?: {
76
+ cwd?: string;
77
+ connectionPath?: string;
78
+ }): AgentRelayClient;
79
+ /**
80
+ * Spawn a local broker process and return a connected client.
81
+ *
82
+ * 1. Generates a random API key
83
+ * 2. Spawns the broker binary (attached)
84
+ * 3. Parses the API port from stdout
85
+ * 4. Connects HTTP/WS transport
86
+ * 5. Fetches session metadata
87
+ * 6. Starts event stream + lease renewal
88
+ */
89
+ static spawn(options?: AgentRelaySpawnOptions): Promise<AgentRelayClient>;
90
+ /** PID of the managed broker process, if spawned locally. */
91
+ get brokerPid(): number | undefined;
92
+ getSession(): Promise<SessionInfo>;
93
+ healthCheck(): Promise<{
94
+ service: string;
95
+ }>;
96
+ connectEvents(sinceSeq?: number): void;
97
+ disconnectEvents(): void;
114
98
  onEvent(listener: (event: BrokerEvent) => void): () => void;
115
99
  queryEvents(filter?: {
116
100
  kind?: string;
@@ -119,29 +103,22 @@ export declare class AgentRelayClient {
119
103
  limit?: number;
120
104
  }): BrokerEvent[];
121
105
  getLastEvent(kind: string, name?: string): BrokerEvent | undefined;
122
- onBrokerStderr(listener: (line: string) => void): () => void;
123
- get brokerPid(): number | undefined;
124
- start(): Promise<void>;
125
- /**
126
- * Pre-register a batch of agents with Relaycast before their steps execute.
127
- * The broker warms its token cache in parallel; subsequent spawn_agent calls
128
- * hit the cache rather than waiting on individual HTTP registrations.
129
- * Fire-and-forget from the caller's perspective — broker responds immediately
130
- * and registers in the background.
131
- */
132
- preflightAgents(agents: Array<{
133
- name: string;
134
- cli: string | AgentRuntime;
135
- }>): Promise<void>;
136
106
  spawnPty(input: SpawnPtyInput): Promise<{
137
107
  name: string;
138
108
  runtime: AgentRuntime;
139
109
  }>;
140
- spawnHeadless(input: SpawnHeadlessInput): Promise<{
110
+ spawnProvider(input: SpawnProviderInput): Promise<{
141
111
  name: string;
142
112
  runtime: AgentRuntime;
143
113
  }>;
144
- spawnProvider(input: SpawnProviderInput): Promise<{
114
+ spawnHeadless(input: {
115
+ name: string;
116
+ provider: HeadlessProvider;
117
+ args?: string[];
118
+ channels?: string[];
119
+ task?: string;
120
+ skipRelayPrompt?: boolean;
121
+ }): Promise<{
145
122
  name: string;
146
123
  runtime: AgentRuntime;
147
124
  }>;
@@ -156,17 +133,20 @@ export declare class AgentRelayClient {
156
133
  release(name: string, reason?: string): Promise<{
157
134
  name: string;
158
135
  }>;
136
+ listAgents(): Promise<ListAgent[]>;
159
137
  sendInput(name: string, data: string): Promise<{
160
138
  name: string;
161
139
  bytes_written: number;
162
140
  }>;
163
- subscribeChannels(name: string, channels: string[]): Promise<void>;
164
- unsubscribeChannels(name: string, channels: string[]): Promise<void>;
165
141
  resizePty(name: string, rows: number, cols: number): Promise<{
166
142
  name: string;
167
143
  rows: number;
168
144
  cols: number;
169
145
  }>;
146
+ sendMessage(input: SendMessageInput): Promise<{
147
+ event_id: string;
148
+ targets: string[];
149
+ }>;
170
150
  setModel(name: string, model: string, opts?: {
171
151
  timeoutMs?: number;
172
152
  }): Promise<{
@@ -174,6 +154,8 @@ export declare class AgentRelayClient {
174
154
  model: string;
175
155
  success: boolean;
176
156
  }>;
157
+ subscribeChannels(name: string, channels: string[]): Promise<void>;
158
+ unsubscribeChannels(name: string, channels: string[]): Promise<void>;
177
159
  getMetrics(agent?: string): Promise<{
178
160
  agents: Array<{
179
161
  name: string;
@@ -183,89 +165,29 @@ export declare class AgentRelayClient {
183
165
  }>;
184
166
  broker?: BrokerStats;
185
167
  }>;
168
+ getStatus(): Promise<BrokerStatus>;
186
169
  getCrashInsights(): Promise<CrashInsightsResponse>;
187
- sendMessage(input: SendMessageInput): Promise<{
188
- event_id: string;
189
- targets: string[];
170
+ preflight(agents: Array<{
171
+ name: string;
172
+ cli: string;
173
+ }>): Promise<{
174
+ queued: number;
175
+ }>;
176
+ renewLease(): Promise<{
177
+ renewed: boolean;
178
+ expires_in_secs: number;
190
179
  }>;
191
- listAgents(): Promise<ListAgent[]>;
192
- getStatus(): Promise<BrokerStatus>;
193
- shutdown(): Promise<void>;
194
- waitForExit(): Promise<void>;
195
- private startInternal;
196
- private disposeProcessHandles;
197
- private failAllPending;
198
- private handleStdoutLine;
199
- private requestHello;
200
- private requestOk;
201
- private sendRequest;
202
- }
203
- export interface HttpAgentRelayClientOptions {
204
- port: number;
205
- apiKey?: string;
206
- }
207
- export interface DiscoverAndConnectOptions {
208
- cwd?: string;
209
- apiKey?: string;
210
- /** Auto-start the broker if not running (default: false). */
211
- autoStart?: boolean;
212
- /**
213
- * Path to the broker binary for auto-start.
214
- * If not provided, the SDK resolves it automatically via standard install locations
215
- * (~/.agent-relay/bin, bundled platform binary, or Cargo release build).
216
- * Only used when `autoStart: true`.
217
- */
218
- brokerBinaryPath?: string;
219
- }
220
- export declare class HttpAgentRelayClient {
221
- private readonly port;
222
- private readonly apiKey?;
223
- constructor(options: HttpAgentRelayClientOptions);
224
- /**
225
- * Connect to an already-running broker on the given port.
226
- */
227
- static connectHttp(port: number, options?: {
228
- apiKey?: string;
229
- }): Promise<HttpAgentRelayClient>;
230
180
  /**
231
- * Discover a running broker for the current project and connect to it.
232
- * Reads the broker PID file, verifies the process is alive, scans ports
233
- * for the HTTP API, and returns a connected client.
181
+ * Shut down and clean up.
182
+ * - For spawned brokers (via .spawn()): sends POST /api/shutdown to kill the broker, waits for exit.
183
+ * - For connected brokers (via .connect() or constructor): just disconnects the transport.
184
+ * Does NOT kill the broker — the caller doesn't own it.
234
185
  */
235
- static discoverAndConnect(options?: DiscoverAndConnectOptions): Promise<HttpAgentRelayClient>;
236
- private static scanForBrokerPort;
237
- private request;
238
- private static extractErrorMessage;
239
- healthCheck(): Promise<{
240
- service: string;
241
- }>;
242
- /** No-op — broker is already running. */
243
- start(): Promise<void>;
244
- /** No-op — don't kill an externally-managed broker. */
245
186
  shutdown(): Promise<void>;
246
- spawnPty(input: SpawnPtyInput): Promise<{
247
- name: string;
248
- runtime: AgentRuntime;
249
- }>;
250
- sendMessage(input: SendMessageInput): Promise<{
251
- event_id: string;
252
- targets: string[];
253
- }>;
254
- listAgents(): Promise<ListAgent[]>;
255
- release(name: string, reason?: string): Promise<{
256
- name: string;
257
- }>;
258
- subscribeChannels(_name: string, _channels: string[]): Promise<void>;
259
- unsubscribeChannels(_name: string, _channels: string[]): Promise<void>;
260
- setModel(name: string, model: string, opts?: {
261
- timeoutMs?: number;
262
- }): Promise<{
263
- name: string;
264
- model: string;
265
- success: boolean;
266
- }>;
187
+ /** Disconnect without shutting down the broker. Alias for cases where the intent is clear. */
188
+ disconnect(): void;
267
189
  getConfig(): Promise<{
268
- workspace_key?: string;
190
+ workspaceKey?: string;
269
191
  }>;
270
192
  }
271
193
  //# sourceMappingURL=client.d.ts.map