@agent-relay/sdk 8.3.6 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -97
- package/bin/agent-relay-broker-darwin-arm64 +0 -0
- package/bin/agent-relay-broker-darwin-x64 +0 -0
- package/bin/agent-relay-broker-linux-arm64 +0 -0
- package/bin/agent-relay-broker-linux-x64 +0 -0
- package/bin/agent-relay-broker-win32-x64.exe +0 -0
- package/dist/agent-relay.d.ts +36 -6
- package/dist/agent-relay.d.ts.map +1 -1
- package/dist/agent-relay.js +52 -15
- package/dist/agent-relay.js.map +1 -1
- package/dist/facade.d.ts +19 -4
- package/dist/facade.d.ts.map +1 -1
- package/dist/facade.js +35 -20
- package/dist/facade.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/listeners.d.ts +120 -5
- package/dist/listeners.d.ts.map +1 -1
- package/dist/listeners.js +132 -15
- package/dist/listeners.js.map +1 -1
- package/dist/messaging/relaycast.d.ts +3 -0
- package/dist/messaging/relaycast.d.ts.map +1 -1
- package/dist/messaging/relaycast.js +4 -1
- package/dist/messaging/relaycast.js.map +1 -1
- package/dist/messaging/types.d.ts +6 -0
- package/dist/messaging/types.d.ts.map +1 -1
- package/dist/relaycast-errors.d.ts +8 -8
- package/dist/relaycast-errors.js +8 -8
- package/dist/relaycast-telemetry.d.ts +1 -1
- package/dist/relaycast-telemetry.d.ts.map +1 -1
- package/dist/relaycast-telemetry.js +19 -3
- package/dist/relaycast-telemetry.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ Core TypeScript SDK for Agent Relay communication. The SDK gives agents and appl
|
|
|
4
4
|
|
|
5
5
|
Use `@agent-relay/sdk` when your app, service, harness, or worker already owns its runtime and needs to participate in Agent Relay. Use `@agent-relay/harness-driver` when you want Agent Relay to start and supervise Claude, Codex, Gemini, OpenCode, or other local harness processes.
|
|
6
6
|
|
|
7
|
+
Full docs: [agentrelay.com/docs](https://agentrelay.com/docs/typescript-sdk) (markdown mirrors for agents and CLI tooling at [agentrelay.com/llms.txt](https://agentrelay.com/llms.txt)).
|
|
8
|
+
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
11
|
```bash
|
|
@@ -14,11 +16,13 @@ npm install @agent-relay/sdk zod
|
|
|
14
16
|
|
|
15
17
|
- **Messaging** is durable agent communication: identities, channels, DMs, group DMs, threads, reactions, inbox, read state, presence, search, and events.
|
|
16
18
|
- **Delivery** is runtime handoff: taking durable messages from Agent Relay and injecting them into a live agent process, service, app server, browser worker, or harness.
|
|
17
|
-
- **Actions** are typed capabilities: discoverable operations with Zod schemas,
|
|
19
|
+
- **Actions** are typed capabilities: discoverable operations with Zod schemas, fire-and-forget invocation, audit events, and `action.completed` results delivered to listeners.
|
|
18
20
|
- **Runtime** is optional managed execution. Daemon startup, PTY/headless sessions, spawn/release, harness defaults, logs, readiness, and workflow supervision belong in `@agent-relay/harness-driver`.
|
|
19
21
|
|
|
20
22
|
## Quick start
|
|
21
23
|
|
|
24
|
+
`relay.workspace.register(...)` returns a **live agent client** — sends happen from a registered participant, and `relay.addListener(...)` is the single event entry point.
|
|
25
|
+
|
|
22
26
|
```ts
|
|
23
27
|
import { AgentRelay } from '@agent-relay/sdk';
|
|
24
28
|
|
|
@@ -26,23 +30,21 @@ const relay = new AgentRelay({
|
|
|
26
30
|
workspaceKey: process.env.RELAY_WORKSPACE_KEY!,
|
|
27
31
|
});
|
|
28
32
|
|
|
29
|
-
const reviewer = await relay.
|
|
30
|
-
const agent = relay.as(reviewer);
|
|
33
|
+
const reviewer = await relay.workspace.register({ name: 'reviewer', type: 'agent' });
|
|
31
34
|
|
|
32
|
-
await
|
|
35
|
+
await reviewer.channels.join('reviews');
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
if (
|
|
37
|
+
relay.addListener('message.created', async ({ message, envelope }) => {
|
|
38
|
+
if (envelope.channel?.name !== 'reviews') return;
|
|
36
39
|
|
|
37
|
-
await
|
|
38
|
-
messageId:
|
|
40
|
+
await reviewer.reply({
|
|
41
|
+
messageId: message.messageId,
|
|
39
42
|
text: 'Received. I will review this thread.',
|
|
40
43
|
});
|
|
41
|
-
await agent.messages.markRead(event.message.id);
|
|
42
44
|
});
|
|
43
45
|
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
+
await reviewer.sendMessage({
|
|
47
|
+
to: '#reviews',
|
|
46
48
|
text: 'Reviewer is online.',
|
|
47
49
|
});
|
|
48
50
|
```
|
|
@@ -53,44 +55,92 @@ You can also create a new workspace directly:
|
|
|
53
55
|
const relay = await AgentRelay.createWorkspace({
|
|
54
56
|
name: 'review-workspace',
|
|
55
57
|
});
|
|
58
|
+
// persist relay.workspaceKey to reconnect later
|
|
56
59
|
```
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
Reconnect a registered agent in a fresh process with its persisted token:
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
```ts
|
|
64
|
+
const reviewer = await relay.workspace.reconnect({ apiToken: process.env.REVIEWER_TOKEN! });
|
|
65
|
+
```
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
- Join, list, create, update, mute, archive, and inspect channels.
|
|
64
|
-
- Send channel messages, direct messages, and group DMs.
|
|
65
|
-
- Reply in threads and fetch message history.
|
|
66
|
-
- Add and remove reactions.
|
|
67
|
-
- Search messages and inspect inbox state.
|
|
68
|
-
- Subscribe to events for messages, threads, DMs, reactions, channel changes, presence, files, webhooks, and action invocations.
|
|
67
|
+
## Messaging
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
The live agent client covers the communication surface agents need during a run: channels, DMs, group DMs, threads, reactions, inbox, and search.
|
|
71
70
|
|
|
72
71
|
```ts
|
|
73
|
-
const lead =
|
|
72
|
+
const lead = await relay.workspace.register({ name: 'lead', type: 'agent' });
|
|
74
73
|
|
|
75
74
|
await lead.channels.create({
|
|
76
75
|
name: 'release',
|
|
77
76
|
topic: 'Release readiness',
|
|
78
77
|
});
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
// `to` is '#channel', '@handle' (DM), or ['@a', '@b'] (group DM)
|
|
80
|
+
const { messageId } = await lead.sendMessage({
|
|
81
|
+
to: '#release',
|
|
82
82
|
text: 'Please review the migration guide.',
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
const
|
|
86
|
-
messageId
|
|
85
|
+
const reply = await lead.reply({
|
|
86
|
+
messageId,
|
|
87
87
|
text: 'Tracking docs feedback here.',
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
await lead.
|
|
91
|
-
messageId:
|
|
92
|
-
emoji: 'eyes',
|
|
90
|
+
await lead.react({
|
|
91
|
+
messageId: reply.messageId,
|
|
92
|
+
emoji: ':eyes:',
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const thread = await lead.threads.get(messageId, { limit: 50 });
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Actions
|
|
99
|
+
|
|
100
|
+
Actions are **fire-and-forget**: invoking returns an acknowledgement immediately, the handler runs in the SDK process that registered it, and the relay emits `action.completed` (or `action.failed`) to listeners — not inline to the invoking agent. Registered actions are exposed as typed MCP tools to agents automatically.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { z } from 'zod';
|
|
104
|
+
|
|
105
|
+
const handle = relay.registerAction({
|
|
106
|
+
name: 'github.open_pr',
|
|
107
|
+
description: 'Open a GitHub pull request for a prepared branch.',
|
|
108
|
+
input: z.object({
|
|
109
|
+
repository: z.string(),
|
|
110
|
+
branch: z.string(),
|
|
111
|
+
title: z.string(),
|
|
112
|
+
body: z.string().optional(),
|
|
113
|
+
}),
|
|
114
|
+
availableTo: [{ name: 'release-lead' }], // omit to allow everyone
|
|
115
|
+
handler: async ({ input, agent }) => {
|
|
116
|
+
const pr = await github.openPullRequest(input);
|
|
117
|
+
// The return value reaches listeners, not the caller — message the caller directly.
|
|
118
|
+
await coordinator.sendMessage({ to: `@${agent.handle}`, text: `Opened ${pr.url}` });
|
|
119
|
+
return { url: pr.url, number: pr.number }; // becomes the action.completed payload
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
relay.addListener(relay.action('github.open_pr').completed(), (event) => {
|
|
124
|
+
console.log(event.output);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Later, if this process should stop exposing the action:
|
|
128
|
+
handle.unregister();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Events
|
|
132
|
+
|
|
133
|
+
`relay.addListener(selector, handler)` accepts a dotted event name, a `*`/prefix wildcard, or a fluent predicate, and always hands the handler one discriminated event object. It returns an unsubscribe function.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const unsubscribe = relay.addListener('message.created', ({ message, envelope }) => {
|
|
137
|
+
console.log(`${envelope.from.handle}: ${message.text}`);
|
|
93
138
|
});
|
|
139
|
+
|
|
140
|
+
relay.addListener('action.*', (event) => console.log(event.type));
|
|
141
|
+
relay.addListener(reviewer.status.becomes('idle'), () => assignNextReview());
|
|
142
|
+
|
|
143
|
+
unsubscribe();
|
|
94
144
|
```
|
|
95
145
|
|
|
96
146
|
## Delivery
|
|
@@ -145,77 +195,29 @@ const session: AgentSession = {
|
|
|
145
195
|
};
|
|
146
196
|
|
|
147
197
|
await new DeliveryRunner({
|
|
148
|
-
messaging:
|
|
198
|
+
messaging: reviewer.messages, // messaging surface of the registered agent
|
|
149
199
|
delivery: session,
|
|
150
200
|
agentName: 'reviewer',
|
|
151
201
|
}).start();
|
|
152
202
|
```
|
|
153
203
|
|
|
154
|
-
##
|
|
155
|
-
|
|
156
|
-
Agent Relay actions are exposed through registration and invocation:
|
|
204
|
+
## Optional managed harnesses
|
|
157
205
|
|
|
158
|
-
|
|
159
|
-
- Validate inputs before handlers run and validate outputs before callers receive them.
|
|
160
|
-
- Attach policy hooks for allow/deny decisions.
|
|
161
|
-
- Emit audit events for invoked, completed, failed, and denied actions.
|
|
162
|
-
- Expose registered actions as MCP tools for agents that do not embed the SDK.
|
|
206
|
+
Install the harness packages for managed local execution:
|
|
163
207
|
|
|
164
|
-
|
|
208
|
+
```bash
|
|
209
|
+
npm install @agent-relay/harnesses @agent-relay/harness-driver
|
|
210
|
+
```
|
|
165
211
|
|
|
166
|
-
|
|
212
|
+
`create({ relay })` spawns the agent **and** self-registers it, returning the same live client shape as `relay.workspace.register(...)`:
|
|
167
213
|
|
|
168
214
|
```ts
|
|
169
|
-
import {
|
|
170
|
-
|
|
171
|
-
const OpenPullRequestInput = z.object({
|
|
172
|
-
repository: z.string(),
|
|
173
|
-
branch: z.string(),
|
|
174
|
-
title: z.string(),
|
|
175
|
-
body: z.string().optional(),
|
|
176
|
-
});
|
|
215
|
+
import { claude, codex } from '@agent-relay/harnesses';
|
|
177
216
|
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
number: z.number().int().positive(),
|
|
181
|
-
});
|
|
217
|
+
const planner = await claude.create({ relay, model: 'sonnet' });
|
|
218
|
+
const engineer = await codex.create({ relay, model: 'gpt-5.5' });
|
|
182
219
|
|
|
183
|
-
|
|
184
|
-
name: 'github.open_pr',
|
|
185
|
-
description: 'Open a GitHub pull request for a prepared branch.',
|
|
186
|
-
inputSchema: OpenPullRequestInput,
|
|
187
|
-
outputSchema: OpenPullRequestOutput,
|
|
188
|
-
policy: async (_input, ctx) => ({
|
|
189
|
-
allowed: ctx.caller.type === 'agent' && ctx.caller.name.startsWith('release-'),
|
|
190
|
-
reason: 'Only release agents can open PRs',
|
|
191
|
-
}),
|
|
192
|
-
handler: async (input, ctx) => {
|
|
193
|
-
const pr = await github.openPullRequest(input);
|
|
194
|
-
await ctx.messaging?.messages.direct({
|
|
195
|
-
to: ctx.caller.name,
|
|
196
|
-
text: `Opened ${pr.url}`,
|
|
197
|
-
});
|
|
198
|
-
return { url: pr.url, number: pr.number };
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
const pr = await relay.actions.invoke({
|
|
203
|
-
name: 'github.open_pr',
|
|
204
|
-
input: {
|
|
205
|
-
repository: 'AgentWorkforce/relay',
|
|
206
|
-
branch: 'codex/core-simplification',
|
|
207
|
-
title: 'Simplify Agent Relay core surfaces',
|
|
208
|
-
},
|
|
209
|
-
caller: { name: 'release-lead', type: 'agent' },
|
|
210
|
-
});
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## Optional managed harnesses
|
|
214
|
-
|
|
215
|
-
Install the harness driver package for managed local execution:
|
|
216
|
-
|
|
217
|
-
```bash
|
|
218
|
-
npm install @agent-relay/harness-driver
|
|
220
|
+
await planner.sendMessage({ to: '#reviews', text: `${engineer.handle} let's pair on the migration.` });
|
|
219
221
|
```
|
|
220
222
|
|
|
221
223
|
`@agent-relay/harness-driver` owns:
|
|
@@ -226,18 +228,19 @@ npm install @agent-relay/harness-driver
|
|
|
226
228
|
- Agent lifecycle hooks, session metadata, idle detection, managed release, and shutdown.
|
|
227
229
|
- Workflow and supervision helpers that coordinate multiple spawned harnesses.
|
|
228
230
|
|
|
229
|
-
Keep application-level messaging code on `@agent-relay/sdk`; add
|
|
231
|
+
Keep application-level messaging code on `@agent-relay/sdk`; add the harness packages only at the boundary that owns local agent processes.
|
|
230
232
|
|
|
231
|
-
## Migration from the pre-
|
|
233
|
+
## Migration from the pre-v8 SDK
|
|
232
234
|
|
|
233
|
-
| Previous SDK surface
|
|
234
|
-
|
|
|
235
|
-
|
|
|
236
|
-
|
|
|
237
|
-
|
|
|
238
|
-
|
|
|
235
|
+
| Previous SDK surface | Version 8 replacement |
|
|
236
|
+
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
|
|
237
|
+
| `relay.agents.register(...)` + `relay.as(agent)` token handoff | `relay.workspace.register(...)` returns the live client directly. |
|
|
238
|
+
| `relay.sendMessage(...)`, `relay.system()` | Send from a registered participant: `agent.sendMessage(...)`. |
|
|
239
|
+
| `agent.events.on(...)`, `relay.on(...)` | `relay.addListener(selector, handler)` — the single listener entry point. |
|
|
240
|
+
| `relay.actions.register(...)` / `relay.actions.invoke(...)` returning inline results | `relay.registerAction(...)`; results reach listeners via `action.completed`. |
|
|
241
|
+
| Spawn methods on `AgentRelay` (`spawnAgent()`, PTY/headless helpers) | `@agent-relay/harnesses` `create({ relay })` + `@agent-relay/harness-driver`. |
|
|
239
242
|
|
|
240
|
-
|
|
243
|
+
See the [migration guide](https://agentrelay.com/docs/migration) for details.
|
|
241
244
|
|
|
242
245
|
## Development
|
|
243
246
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/agent-relay.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { type AgentRelayActions
|
|
1
|
+
import { type AgentRelayActions } from './actions/index.js';
|
|
2
2
|
import { type RelaycastTelemetryOptions } from './relaycast-telemetry.js';
|
|
3
3
|
import { type RelayMessaging, type RelaycastMessagingOptions } from './messaging/index.js';
|
|
4
4
|
import { type EnrichedMessages, type RegisterActionInput, type RelayAgentClient, type RelayWorkspace } from './facade.js';
|
|
5
|
-
import { type AgentHandleInput, type ActionPredicate, type EnrichedEvents, type ListenerHandler, type ListenerPredicate, type RelayAgentHandle, type RelayEvent } from './listeners.js';
|
|
5
|
+
import { type AgentHandleInput, type ActionPredicate, type EnrichedEvents, type ListenerHandler, type ListenerPredicate, type RelayAgentHandle, type RelayErrorHook, type RelayEvent, type RelayEventMap, type TypedActionHandle } from './listeners.js';
|
|
6
6
|
import type { AgentSessionEvent } from './session/index.js';
|
|
7
7
|
export interface AgentRelayOptions extends RelaycastMessagingOptions {
|
|
8
8
|
messaging?: RelayMessaging;
|
|
9
9
|
actions?: AgentRelayActions;
|
|
10
10
|
/** Factory for agent-token-scoped messaging clients. Defaults to a Relaycast client. */
|
|
11
11
|
createAgentMessaging?: (token: string) => RelayMessaging;
|
|
12
|
+
/**
|
|
13
|
+
* Receives listener and action handler errors with a context identifying
|
|
14
|
+
* the listener selector or action name. When unset, errors are logged as
|
|
15
|
+
* console warnings.
|
|
16
|
+
*/
|
|
17
|
+
onError?: RelayErrorHook;
|
|
12
18
|
}
|
|
13
19
|
export interface AgentRelayCreateWorkspaceInput extends RelaycastTelemetryOptions {
|
|
14
20
|
name: string;
|
|
@@ -29,8 +35,14 @@ export interface AgentRelayAgent {
|
|
|
29
35
|
readonly webhooks: RelayMessaging['webhooks'];
|
|
30
36
|
readonly capabilities: RelayMessaging['commands'];
|
|
31
37
|
readonly workspace: RelayWorkspace;
|
|
32
|
-
registerAction<TInput, TOutput>(def: RegisterActionInput<TInput, TOutput>):
|
|
38
|
+
registerAction<TInput, TOutput>(def: RegisterActionInput<TInput, TOutput>): TypedActionHandle<TInput, TOutput>;
|
|
39
|
+
/** Subscribe with a typed predicate — the handler receives the predicate's event type. */
|
|
40
|
+
addListener<TEvent>(selector: ListenerPredicate<TEvent>, handler: ListenerHandler<TEvent>): () => void;
|
|
41
|
+
/** Subscribe by dotted event name, `'*'`/prefix wildcard, or a predicate. */
|
|
42
|
+
addListener<K extends keyof RelayEventMap>(selector: K, handler: ListenerHandler<RelayEventMap[K]>): () => void;
|
|
33
43
|
addListener(selector: string | ListenerPredicate, handler: ListenerHandler<RelayEvent>): () => void;
|
|
44
|
+
once<K extends keyof RelayEventMap>(selector: K, handler: ListenerHandler<RelayEventMap[K]>): () => void;
|
|
45
|
+
once(selector: string | ListenerPredicate, handler: ListenerHandler<RelayEvent>): () => void;
|
|
34
46
|
action(name: string): ActionPredicate;
|
|
35
47
|
agent(input: AgentHandleInput): RelayAgentHandle;
|
|
36
48
|
emitSessionEvent(agentId: string, event: AgentSessionEvent): void;
|
|
@@ -45,6 +57,7 @@ export declare class AgentRelay implements AgentRelayAgent {
|
|
|
45
57
|
private enrichedMessages?;
|
|
46
58
|
private workspaceFacade?;
|
|
47
59
|
private hub?;
|
|
60
|
+
private readonly errorHooks;
|
|
48
61
|
constructor(options?: AgentRelayOptions);
|
|
49
62
|
static createWorkspace(input: string | AgentRelayCreateWorkspaceInput): Promise<AgentRelay>;
|
|
50
63
|
get agents(): RelayMessaging['agents'];
|
|
@@ -63,16 +76,33 @@ export declare class AgentRelay implements AgentRelayAgent {
|
|
|
63
76
|
private buildAgentClient;
|
|
64
77
|
/** Rehydrate a live client from a persisted agent token, resolving identity from the relay. */
|
|
65
78
|
private reconnectAgent;
|
|
66
|
-
registerAction<TInput, TOutput>(def: RegisterActionInput<TInput, TOutput>):
|
|
79
|
+
registerAction<TInput, TOutput>(def: RegisterActionInput<TInput, TOutput>): TypedActionHandle<TInput, TOutput>;
|
|
80
|
+
/** Subscribe with a typed predicate — the handler receives the predicate's event type. */
|
|
81
|
+
addListener<TEvent>(selector: ListenerPredicate<TEvent>, handler: ListenerHandler<TEvent>): () => void;
|
|
67
82
|
/** Subscribe by dotted event name, `'*'`/prefix wildcard, or a predicate. */
|
|
83
|
+
addListener<K extends keyof RelayEventMap>(selector: K, handler: ListenerHandler<RelayEventMap[K]>): () => void;
|
|
68
84
|
addListener(selector: string | ListenerPredicate, handler: ListenerHandler<RelayEvent>): () => void;
|
|
85
|
+
/** Like `addListener`, but auto-unsubscribes after the first matching event. */
|
|
86
|
+
once<K extends keyof RelayEventMap>(selector: K, handler: ListenerHandler<RelayEventMap[K]>): () => void;
|
|
87
|
+
once(selector: string | ListenerPredicate, handler: ListenerHandler<RelayEvent>): () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Register a hook that receives listener and action handler errors. Returns
|
|
90
|
+
* an unsubscribe callback. When no hook is registered, errors are logged as
|
|
91
|
+
* console warnings.
|
|
92
|
+
*/
|
|
93
|
+
onError(hook: RelayErrorHook): () => void;
|
|
94
|
+
private reportError;
|
|
69
95
|
action(name: string): ActionPredicate;
|
|
70
96
|
agent(input: AgentHandleInput): RelayAgentHandle;
|
|
71
97
|
emitSessionEvent(agentId: string, event: AgentSessionEvent): void;
|
|
72
98
|
private messagingForToken;
|
|
73
99
|
private createMessagingResolver;
|
|
74
100
|
}
|
|
75
|
-
export
|
|
101
|
+
export interface AgentRelayAgentOptions {
|
|
102
|
+
/** Receives listener and action handler errors; defaults to console warnings. */
|
|
103
|
+
onError?: RelayErrorHook;
|
|
104
|
+
}
|
|
105
|
+
export declare function agentRelayAgent(messaging: RelayMessaging, actions: AgentRelayActions, handlerAgent?: string, options?: AgentRelayAgentOptions): AgentRelayAgent;
|
|
76
106
|
/**
|
|
77
107
|
* Assemble a live agent client: an agent-scoped messaging surface plus the
|
|
78
108
|
* agent's identity and status/tool predicate builders, with `reply`/`react`
|
|
@@ -83,5 +113,5 @@ export declare function assembleAgentClient(messaging: RelayMessaging, actions:
|
|
|
83
113
|
name: string;
|
|
84
114
|
handle?: string;
|
|
85
115
|
token: string;
|
|
86
|
-
}): RelayAgentClient;
|
|
116
|
+
}, options?: AgentRelayAgentOptions): RelayAgentClient;
|
|
87
117
|
//# sourceMappingURL=agent-relay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-relay.d.ts","sourceRoot":"","sources":["../src/agent-relay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"agent-relay.d.ts","sourceRoot":"","sources":["../src/agent-relay.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAGL,KAAK,yBAAyB,EAC/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAML,KAAK,gBAAgB,EAErB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EAEpB,KAAK,iBAAi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CAC7B,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,iBAAiB,EAC1B,YAAY,CAAC,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,eAAe,CA4BjB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EACtE,OAAO,CAAC,EAAE,sBAAsB,GAC/B,gBAAgB,CAUlB"}
|
package/dist/agent-relay.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RelayCast } from '@relaycast/sdk';
|
|
1
|
+
import { RelayCast, RelayError } from '@relaycast/sdk';
|
|
2
2
|
import { ActionRegistry } from './actions/index.js';
|
|
3
3
|
import { relaycastTelemetryOptions, relaycastWorkspaceTelemetryOptions, } from './relaycast-telemetry.js';
|
|
4
4
|
import { RelaycastMessagingClient, } from './messaging/index.js';
|
|
5
5
|
import { createEnrichedMessages, createWorkspaceFacade, registerFacadeAction, resolveAgentToken, } from './facade.js';
|
|
6
|
-
import { createAgentHandle, createListenerHub, } from './listeners.js';
|
|
6
|
+
import { createAgentHandle, createListenerHub, logRelayHandlerError, } from './listeners.js';
|
|
7
7
|
export class AgentRelay {
|
|
8
8
|
messaging;
|
|
9
9
|
actions;
|
|
@@ -14,8 +14,9 @@ export class AgentRelay {
|
|
|
14
14
|
enrichedMessages;
|
|
15
15
|
workspaceFacade;
|
|
16
16
|
hub;
|
|
17
|
+
errorHooks = new Set();
|
|
17
18
|
constructor(options = {}) {
|
|
18
|
-
const { messaging, actions, workspaceKey, createAgentMessaging, ...messagingOptions } = options;
|
|
19
|
+
const { messaging, actions, workspaceKey, createAgentMessaging, onError, ...messagingOptions } = options;
|
|
19
20
|
const resolvedWorkspaceKey = workspaceKey ?? messagingOptions.apiKey;
|
|
20
21
|
this.workspaceKey = resolvedWorkspaceKey;
|
|
21
22
|
this.messagingOptions = { ...messagingOptions, workspaceKey: resolvedWorkspaceKey };
|
|
@@ -24,6 +25,9 @@ export class AgentRelay {
|
|
|
24
25
|
this.createAgentMessaging =
|
|
25
26
|
createAgentMessaging ??
|
|
26
27
|
((token) => new RelaycastMessagingClient({ ...this.messagingOptions, agentToken: token }));
|
|
28
|
+
if (onError) {
|
|
29
|
+
this.errorHooks.add(onError);
|
|
30
|
+
}
|
|
27
31
|
}
|
|
28
32
|
static async createWorkspace(input) {
|
|
29
33
|
const options = typeof input === 'string' ? { name: input } : input;
|
|
@@ -34,7 +38,7 @@ export class AgentRelay {
|
|
|
34
38
|
}));
|
|
35
39
|
const workspaceKey = extractWorkspaceKey(workspace);
|
|
36
40
|
if (!workspaceKey) {
|
|
37
|
-
throw new
|
|
41
|
+
throw new RelayError('transport_error', 'Workspace created, but the response did not include a workspace key.', { retryable: false });
|
|
38
42
|
}
|
|
39
43
|
return new AgentRelay({
|
|
40
44
|
workspaceKey,
|
|
@@ -67,7 +71,9 @@ export class AgentRelay {
|
|
|
67
71
|
}
|
|
68
72
|
get listenerHub() {
|
|
69
73
|
if (!this.hub) {
|
|
70
|
-
this.hub = createListenerHub(this.messaging.events, this.actions
|
|
74
|
+
this.hub = createListenerHub(this.messaging.events, this.actions, {
|
|
75
|
+
onError: (error, context) => this.reportError(error, context),
|
|
76
|
+
});
|
|
71
77
|
}
|
|
72
78
|
return this.hub;
|
|
73
79
|
}
|
|
@@ -98,7 +104,7 @@ export class AgentRelay {
|
|
|
98
104
|
id: registration.id,
|
|
99
105
|
name: registration.name,
|
|
100
106
|
token: registration.token,
|
|
101
|
-
});
|
|
107
|
+
}, { onError: (error, context) => this.reportError(error, context) });
|
|
102
108
|
}
|
|
103
109
|
/** Rehydrate a live client from a persisted agent token, resolving identity from the relay. */
|
|
104
110
|
async reconnectAgent(apiToken) {
|
|
@@ -108,19 +114,49 @@ export class AgentRelay {
|
|
|
108
114
|
id: identity.id,
|
|
109
115
|
name: identity.name,
|
|
110
116
|
token: apiToken,
|
|
111
|
-
});
|
|
117
|
+
}, { onError: (error, context) => this.reportError(error, context) });
|
|
112
118
|
}
|
|
113
119
|
registerAction(def) {
|
|
114
120
|
// The workspace-scoped client has no single handler-agent identity or
|
|
115
121
|
// agent connection, so relay wiring is skipped and the action stays
|
|
116
122
|
// in-process. Use an agent client (workspace.register / reconnect) to
|
|
117
123
|
// register a relay-routed action.
|
|
118
|
-
return registerFacadeAction(this.actions, def, {
|
|
124
|
+
return registerFacadeAction(this.actions, def, {
|
|
125
|
+
messaging: this.messaging,
|
|
126
|
+
onError: (error, context) => this.reportError(error, context),
|
|
127
|
+
});
|
|
119
128
|
}
|
|
120
|
-
/** Subscribe by dotted event name, `'*'`/prefix wildcard, or a predicate. */
|
|
121
129
|
addListener(selector, handler) {
|
|
122
130
|
return this.listenerHub.addListener(selector, handler);
|
|
123
131
|
}
|
|
132
|
+
once(selector, handler) {
|
|
133
|
+
return this.listenerHub.once(selector, handler);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Register a hook that receives listener and action handler errors. Returns
|
|
137
|
+
* an unsubscribe callback. When no hook is registered, errors are logged as
|
|
138
|
+
* console warnings.
|
|
139
|
+
*/
|
|
140
|
+
onError(hook) {
|
|
141
|
+
this.errorHooks.add(hook);
|
|
142
|
+
return () => {
|
|
143
|
+
this.errorHooks.delete(hook);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
reportError(error, context) {
|
|
147
|
+
if (this.errorHooks.size === 0) {
|
|
148
|
+
logRelayHandlerError(error, context);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
for (const hook of this.errorHooks) {
|
|
152
|
+
try {
|
|
153
|
+
hook(error, context);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Error hooks must not throw into the event source.
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
124
160
|
action(name) {
|
|
125
161
|
return this.listenerHub.action(name);
|
|
126
162
|
}
|
|
@@ -157,11 +193,11 @@ function extractWorkspaceKey(payload) {
|
|
|
157
193
|
data.api_key;
|
|
158
194
|
return typeof value === 'string' && value.trim() ? value : undefined;
|
|
159
195
|
}
|
|
160
|
-
export function agentRelayAgent(messaging, actions, handlerAgent) {
|
|
196
|
+
export function agentRelayAgent(messaging, actions, handlerAgent, options) {
|
|
161
197
|
// An acting-as agent client sends through its own token; `from` overrides are
|
|
162
198
|
// best-effort and fall back to this client.
|
|
163
199
|
const messages = createEnrichedMessages(messaging.messages, () => messaging.messages);
|
|
164
|
-
const hub = createListenerHub(messaging.events, actions);
|
|
200
|
+
const hub = createListenerHub(messaging.events, actions, { onError: options?.onError });
|
|
165
201
|
return {
|
|
166
202
|
messaging,
|
|
167
203
|
agents: messaging.agents,
|
|
@@ -175,8 +211,9 @@ export function agentRelayAgent(messaging, actions, handlerAgent) {
|
|
|
175
211
|
webhooks: messaging.webhooks,
|
|
176
212
|
capabilities: messaging.commands,
|
|
177
213
|
workspace: createWorkspaceFacade(messaging),
|
|
178
|
-
registerAction: (def) => registerFacadeAction(actions, def, { messaging, handlerAgent }),
|
|
179
|
-
addListener: (selector, handler) => hub.addListener(selector, handler),
|
|
214
|
+
registerAction: (def) => registerFacadeAction(actions, def, { messaging, handlerAgent, onError: options?.onError }),
|
|
215
|
+
addListener: ((selector, handler) => hub.addListener(selector, handler)),
|
|
216
|
+
once: ((selector, handler) => hub.once(selector, handler)),
|
|
180
217
|
action: (name) => hub.action(name),
|
|
181
218
|
agent: (input) => hub.agent(input),
|
|
182
219
|
emitSessionEvent: (agentId, event) => hub.emitSessionEvent(agentId, event),
|
|
@@ -187,8 +224,8 @@ export function agentRelayAgent(messaging, actions, handlerAgent) {
|
|
|
187
224
|
* agent's identity and status/tool predicate builders, with `reply`/`react`
|
|
188
225
|
* convenience keyed on `messageId`.
|
|
189
226
|
*/
|
|
190
|
-
export function assembleAgentClient(messaging, actions, identity) {
|
|
191
|
-
const base = agentRelayAgent(messaging, actions, identity.name);
|
|
227
|
+
export function assembleAgentClient(messaging, actions, identity, options) {
|
|
228
|
+
const base = agentRelayAgent(messaging, actions, identity.name, options);
|
|
192
229
|
const handle = createAgentHandle(identity);
|
|
193
230
|
return {
|
|
194
231
|
...base,
|
package/dist/agent-relay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-relay.js","sourceRoot":"","sources":["../src/agent-relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-relay.js","sourceRoot":"","sources":["../src/agent-relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAA0B,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EACL,yBAAyB,EACzB,kCAAkC,GAEnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,GAIzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,GAOlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,GAarB,MAAM,gBAAgB,CAAC;AAsDxB,MAAM,OAAO,UAAU;IACZ,SAAS,CAAiB;IAClB,OAAO,CAAoB;IACnC,YAAY,CAAU;IAEd,gBAAgB,CAA4B;IAC5C,cAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;IACnD,oBAAoB,CAAoC;IACjE,gBAAgB,CAAoB;IACpC,eAAe,CAAkB;IACjC,GAAG,CAAe;IACT,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAExD,YAAY,UAA6B,EAAE;QACzC,MAAM,EAAE,SAA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AAM;QACT,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QACjD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;QAC5C,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC;KACpE,CAAC;AACJ,CAAC"}
|
package/dist/facade.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RelayMessaging, RelayMessage, RelayMessageReaction, RelayAgentRegistration, RelayAgentType, RelayMessageAttachmentInput, RelayMessageBlock, RelayMessageMode, RelaySendChannelMessageInput, RelayWorkspaceInfo } from './messaging/index.js';
|
|
2
|
-
import { type AgentRelayActions, type ActionContext, type
|
|
2
|
+
import { type AgentRelayActions, type ActionContext, type ActionPolicy, type ActionSchema } from './actions/index.js';
|
|
3
3
|
import type { DeliveryMode } from './delivery/index.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type RelayAgentHandle, type RelayErrorHook, type TypedActionHandle } from './listeners.js';
|
|
5
5
|
/**
|
|
6
6
|
* A reference to an agent accepted by the high-level facade APIs. Agents may be
|
|
7
7
|
* passed as a bare name/handle string, or as an object carrying any of
|
|
@@ -95,8 +95,21 @@ export interface WorkspaceFacadeDeps {
|
|
|
95
95
|
buildAgentClient(registration: RelayAgentRegistration): RelayAgentClient;
|
|
96
96
|
reconnectAgent(apiToken: string): Promise<RelayAgentClient>;
|
|
97
97
|
}
|
|
98
|
+
export interface RelayRegisterOptions {
|
|
99
|
+
/**
|
|
100
|
+
* Throw a `name_conflict` error when an agent with the same name already
|
|
101
|
+
* exists, instead of adopting the existing identity with a rotated token.
|
|
102
|
+
*/
|
|
103
|
+
strict?: boolean;
|
|
104
|
+
}
|
|
98
105
|
export interface RelayWorkspace {
|
|
99
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Register one or more agents. Idempotent by default: when an agent with
|
|
108
|
+
* the same name already exists, the existing identity is adopted and its
|
|
109
|
+
* token rotated. Pass `{ strict: true }` to fail on name conflicts instead.
|
|
110
|
+
* Token rotation invalidates any previously-issued token for that agent.
|
|
111
|
+
*/
|
|
112
|
+
register<T extends AgentLike | AgentLike[]>(agents: T, options?: RelayRegisterOptions): Promise<T extends AgentLike[] ? RelayAgentClient[] : RelayAgentClient>;
|
|
100
113
|
reconnect(input: {
|
|
101
114
|
apiToken: string;
|
|
102
115
|
}): Promise<RelayAgentClient>;
|
|
@@ -145,7 +158,9 @@ export interface ActionRelayWiring {
|
|
|
145
158
|
messaging: RelayMessaging;
|
|
146
159
|
/** The agent that owns and runs the handler (descriptor `handler_agent`). */
|
|
147
160
|
handlerAgent?: string;
|
|
161
|
+
/** Receives action wiring errors; defaults to console.error when unset. */
|
|
162
|
+
onError?: RelayErrorHook;
|
|
148
163
|
}
|
|
149
|
-
export declare function registerFacadeAction<TInput, TOutput>(actions: AgentRelayActions, def: RegisterActionInput<TInput, TOutput>, wiring?: ActionRelayWiring):
|
|
164
|
+
export declare function registerFacadeAction<TInput, TOutput>(actions: AgentRelayActions, def: RegisterActionInput<TInput, TOutput>, wiring?: ActionRelayWiring): TypedActionHandle<TInput, TOutput>;
|
|
150
165
|
export declare function createNotifyHandler(messages: EnrichedMessages, target: AgentLike, options: NotifyOptions): NotifyHandler;
|
|
151
166
|
//# sourceMappingURL=facade.d.ts.map
|