@beeos-ai/device-agent 0.7.1 → 0.8.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/dist/agent-runtime/skills/sqlite-store.d.ts +60 -0
- package/dist/agent-runtime/skills/sqlite-store.js +234 -0
- package/dist/agent-runtime/skills/sqlite-store.js.map +1 -0
- package/dist/app/in-flight-turn.d.ts +39 -0
- package/dist/app/in-flight-turn.js.map +1 -1
- package/dist/app/jsonl-store.js +20 -7
- package/dist/app/jsonl-store.js.map +1 -1
- package/dist/app/plugin-commands/screenshot-command.d.ts +11 -10
- package/dist/app/plugin-commands/screenshot-command.js +19 -18
- package/dist/app/plugin-commands/screenshot-command.js.map +1 -1
- package/dist/app/plugin-commands/types.d.ts +50 -11
- package/dist/app/plugin-commands/types.js +5 -2
- package/dist/app/plugin-commands/types.js.map +1 -1
- package/dist/app/session-manager.d.ts +20 -11
- package/dist/app/session-manager.js +83 -14
- package/dist/app/session-manager.js.map +1 -1
- package/dist/bootstrap.js +11 -0
- package/dist/bootstrap.js.map +1 -1
- package/dist/config/loader.d.ts +4 -0
- package/dist/config/loader.js +18 -2
- package/dist/config/loader.js.map +1 -1
- package/dist/config/schema.d.ts +5 -0
- package/dist/config/schema.js +42 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/inbound/cli/main.js +12 -0
- package/dist/inbound/cli/main.js.map +1 -1
- package/dist/messaging/token-provider.d.ts +43 -0
- package/dist/messaging/token-provider.js +65 -0
- package/dist/messaging/token-provider.js.map +1 -0
- package/dist/plugins/acp/index.js +1 -1
- package/dist/plugins/acp/index.js.map +1 -1
- package/dist/plugins/message-bus/busy-reply.d.ts +39 -0
- package/dist/plugins/message-bus/busy-reply.js +30 -0
- package/dist/plugins/message-bus/busy-reply.js.map +1 -0
- package/dist/plugins/message-bus/inbound.d.ts +55 -0
- package/dist/plugins/message-bus/inbound.js +123 -0
- package/dist/plugins/message-bus/inbound.js.map +1 -0
- package/dist/plugins/message-bus/index.d.ts +147 -0
- package/dist/plugins/message-bus/index.js +392 -0
- package/dist/plugins/message-bus/index.js.map +1 -0
- package/dist/plugins/message-bus/outbound.d.ts +43 -0
- package/dist/plugins/message-bus/outbound.js +149 -0
- package/dist/plugins/message-bus/outbound.js.map +1 -0
- package/dist/plugins/message-bus/turn-context.d.ts +57 -0
- package/dist/plugins/message-bus/turn-context.js +53 -0
- package/dist/plugins/message-bus/turn-context.js.map +1 -0
- package/dist/test-lan-autoglm.d.ts +7 -0
- package/dist/test-lan-autoglm.js +46 -0
- package/dist/test-lan-autoglm.js.map +1 -0
- package/dist/test-mem-breakdown.d.ts +1 -0
- package/dist/test-mem-breakdown.js +103 -0
- package/dist/test-mem-breakdown.js.map +1 -0
- package/dist/test-mem.d.ts +1 -0
- package/dist/test-mem.js +60 -0
- package/dist/test-mem.js.map +1 -0
- package/dist/test-mobile-use.d.ts +1 -0
- package/dist/test-mobile-use.js +18 -0
- package/dist/test-mobile-use.js.map +1 -0
- package/dist/test-screenshot-loop.d.ts +1 -0
- package/dist/test-screenshot-loop.js +43 -0
- package/dist/test-screenshot-loop.js.map +1 -0
- package/dist/test-screenshot.d.ts +1 -0
- package/dist/test-screenshot.js +10 -0
- package/dist/test-screenshot.js.map +1 -0
- package/dist/test-ui-xml-dump.d.ts +15 -0
- package/dist/test-ui-xml-dump.js +49 -0
- package/dist/test-ui-xml-dump.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin — message-bus.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes the device-agent to the BeeOS Message Service so it can
|
|
5
|
+
* receive `chat_message` envelopes from L0 / A2A / MCP / OpenAPI
|
|
6
|
+
* invocations and reply over `ch:{channelId}` with `agent_reply` /
|
|
7
|
+
* `agent_reply_delta` (in_reply_to = original message_id).
|
|
8
|
+
*
|
|
9
|
+
* Disabled by default — opt in by setting `BEEOS_MESSAGE_BUS_ENABLED=true`
|
|
10
|
+
* (or `--message-bus`) AND providing both `--agent-gateway-url` and
|
|
11
|
+
* an Ed25519 identity. Without those the plugin logs a one-line warning
|
|
12
|
+
* during `start()` and stays disabled — the rest of the agent (Bridge
|
|
13
|
+
* ACP, HTTP debug) still runs.
|
|
14
|
+
*
|
|
15
|
+
* Lifecycle:
|
|
16
|
+
* - `init` — read config, decide enabled / disabled.
|
|
17
|
+
* - `start` — kick off the connect loop. Returns IMMEDIATELY (does
|
|
18
|
+
* not block bootstrap on the network). The first connect attempt
|
|
19
|
+
* and any subsequent retries run in the background.
|
|
20
|
+
* - `stop` — cancel any pending retry, disconnect SDK, unsubscribe
|
|
21
|
+
* outbound listener, drop in-flight register.
|
|
22
|
+
*
|
|
23
|
+
* Failure mode: if `tokenProvider()` rejects (e.g. the device instance
|
|
24
|
+
* has not been provisioned with `agentPublicKey` yet), the plugin
|
|
25
|
+
* schedules a retry with exponential backoff (30s → 60s → 120s → 240s,
|
|
26
|
+
* capped at 300s) and keeps trying forever until either `connect`
|
|
27
|
+
* succeeds or `stop()` cancels the loop. This mirrors beeos-claw's
|
|
28
|
+
* `localServer.onceAgentMappingReady(...)` deferred-connect pattern —
|
|
29
|
+
* see `[index.ts:484-498](agents/beeos-claw/src/index.ts)`.
|
|
30
|
+
*/
|
|
31
|
+
import { MessageSDK, type TokenProvider } from "@beeos-ai/message-sdk";
|
|
32
|
+
import type { Logger } from "../../logger/index.js";
|
|
33
|
+
import type { AgentPlugin, PluginContext } from "../../ports/plugin.js";
|
|
34
|
+
/**
|
|
35
|
+
* Backoff schedule for token / connect failures (milliseconds). Each
|
|
36
|
+
* entry is the delay BEFORE the next retry. The last entry caps the
|
|
37
|
+
* delay; once we hit the cap we keep retrying forever at that interval.
|
|
38
|
+
*
|
|
39
|
+
* Tunable via `MessageBusPluginOptions.retrySchedule` — tests pin a
|
|
40
|
+
* tighter schedule (e.g. `[5, 5, 5]`) to keep `vi.useFakeTimers()`
|
|
41
|
+
* runs cheap.
|
|
42
|
+
*/
|
|
43
|
+
export declare const DEFAULT_RETRY_SCHEDULE_MS: readonly number[];
|
|
44
|
+
export interface MessageBusPluginOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Ed25519 keypair used to sign `POST /api/v1/messaging/token`. When
|
|
47
|
+
* absent the plugin self-disables.
|
|
48
|
+
*/
|
|
49
|
+
keypair?: {
|
|
50
|
+
publicKey: Uint8Array;
|
|
51
|
+
privateKey: Uint8Array;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Override the SDK constructor — used by tests to inject a fake
|
|
55
|
+
* MessageSDK whose `connect` / `onMessage` / `sendToChannel` are
|
|
56
|
+
* spies. Production code leaves this `undefined`.
|
|
57
|
+
*/
|
|
58
|
+
sdkFactory?: (logger: Logger) => MessageSDK;
|
|
59
|
+
/**
|
|
60
|
+
* Override the token provider builder — used by tests to skip the
|
|
61
|
+
* real Agent Gateway round-trip.
|
|
62
|
+
*/
|
|
63
|
+
tokenProviderFactory?: (opts: {
|
|
64
|
+
agentGatewayUrl: string;
|
|
65
|
+
keypair: {
|
|
66
|
+
publicKey: Uint8Array;
|
|
67
|
+
privateKey: Uint8Array;
|
|
68
|
+
};
|
|
69
|
+
}) => TokenProvider;
|
|
70
|
+
/**
|
|
71
|
+
* Local agent identity surfaced into `extractChatPrompt` for
|
|
72
|
+
* sessionKey prefixing. Defaults to the empty string — fine for the
|
|
73
|
+
* single-session-multiplex topology.
|
|
74
|
+
*/
|
|
75
|
+
localAgentId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Override the retry backoff schedule (ms). Defaults to
|
|
78
|
+
* `DEFAULT_RETRY_SCHEDULE_MS`. Tests pass small numbers; production
|
|
79
|
+
* leaves it `undefined`.
|
|
80
|
+
*/
|
|
81
|
+
retrySchedule?: readonly number[];
|
|
82
|
+
/**
|
|
83
|
+
* Test seam — `setTimeout` / `clearTimeout` shim. Defaults to
|
|
84
|
+
* the global `setTimeout` family. Tests inject a deterministic
|
|
85
|
+
* scheduler so they don't need real timers.
|
|
86
|
+
*/
|
|
87
|
+
scheduler?: {
|
|
88
|
+
setTimeout: (cb: () => void, ms: number) => unknown;
|
|
89
|
+
clearTimeout: (handle: unknown) => void;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export declare class MessageBusPlugin implements AgentPlugin {
|
|
93
|
+
private readonly opts;
|
|
94
|
+
readonly name = "message-bus";
|
|
95
|
+
private ctx?;
|
|
96
|
+
private sdk;
|
|
97
|
+
private register;
|
|
98
|
+
private unsubscribeOutbound;
|
|
99
|
+
private resolvedPrincipalId;
|
|
100
|
+
private stopped;
|
|
101
|
+
private retryHandle;
|
|
102
|
+
private retryResolve;
|
|
103
|
+
private connectAttempt;
|
|
104
|
+
private legacyDeprecationLogged;
|
|
105
|
+
private connectSettled;
|
|
106
|
+
private resolveConnectSettled;
|
|
107
|
+
constructor(opts?: MessageBusPluginOptions);
|
|
108
|
+
init(ctx: PluginContext): Promise<void>;
|
|
109
|
+
start(): Promise<void>;
|
|
110
|
+
stop(): Promise<void>;
|
|
111
|
+
get principalId(): string;
|
|
112
|
+
/**
|
|
113
|
+
* Test helper — resolves once `start()`'s connect loop has either
|
|
114
|
+
* successfully connected or `stop()` was called. Production code
|
|
115
|
+
* never needs this.
|
|
116
|
+
*/
|
|
117
|
+
whenSettled(): Promise<void>;
|
|
118
|
+
private runConnectLoop;
|
|
119
|
+
/**
|
|
120
|
+
* Single connect attempt. Returns `true` on success (sdk connected,
|
|
121
|
+
* handlers + listener installed) and `false` on any failure (caller
|
|
122
|
+
* should schedule a retry).
|
|
123
|
+
*
|
|
124
|
+
* Each attempt builds a FRESH `MessageSDK` instance — re-using one
|
|
125
|
+
* across reconnects would carry stale handlers and confuse the
|
|
126
|
+
* centrifuge-js internal state. The SDK has its own internal
|
|
127
|
+
* reconnect once `.connect()` succeeds; this loop is for the OPENING
|
|
128
|
+
* handshake only.
|
|
129
|
+
*/
|
|
130
|
+
private tryConnectOnce;
|
|
131
|
+
private nextDelayMs;
|
|
132
|
+
/**
|
|
133
|
+
* Log an attempt failure with attenuated severity — first attempt
|
|
134
|
+
* + a few well-spaced retries get a `warn`, the rest are `debug` to
|
|
135
|
+
* avoid log spam when an instance has never been provisioned.
|
|
136
|
+
*/
|
|
137
|
+
private logAttemptFailure;
|
|
138
|
+
private logRetryScheduled;
|
|
139
|
+
/**
|
|
140
|
+
* Sleep `ms` milliseconds. Returns `true` when stop() cancels the
|
|
141
|
+
* timer mid-flight (so the caller breaks out of its loop), or
|
|
142
|
+
* `false` once the timer fires normally.
|
|
143
|
+
*/
|
|
144
|
+
private sleep;
|
|
145
|
+
private cancelPendingRetry;
|
|
146
|
+
private scheduler;
|
|
147
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin — message-bus.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes the device-agent to the BeeOS Message Service so it can
|
|
5
|
+
* receive `chat_message` envelopes from L0 / A2A / MCP / OpenAPI
|
|
6
|
+
* invocations and reply over `ch:{channelId}` with `agent_reply` /
|
|
7
|
+
* `agent_reply_delta` (in_reply_to = original message_id).
|
|
8
|
+
*
|
|
9
|
+
* Disabled by default — opt in by setting `BEEOS_MESSAGE_BUS_ENABLED=true`
|
|
10
|
+
* (or `--message-bus`) AND providing both `--agent-gateway-url` and
|
|
11
|
+
* an Ed25519 identity. Without those the plugin logs a one-line warning
|
|
12
|
+
* during `start()` and stays disabled — the rest of the agent (Bridge
|
|
13
|
+
* ACP, HTTP debug) still runs.
|
|
14
|
+
*
|
|
15
|
+
* Lifecycle:
|
|
16
|
+
* - `init` — read config, decide enabled / disabled.
|
|
17
|
+
* - `start` — kick off the connect loop. Returns IMMEDIATELY (does
|
|
18
|
+
* not block bootstrap on the network). The first connect attempt
|
|
19
|
+
* and any subsequent retries run in the background.
|
|
20
|
+
* - `stop` — cancel any pending retry, disconnect SDK, unsubscribe
|
|
21
|
+
* outbound listener, drop in-flight register.
|
|
22
|
+
*
|
|
23
|
+
* Failure mode: if `tokenProvider()` rejects (e.g. the device instance
|
|
24
|
+
* has not been provisioned with `agentPublicKey` yet), the plugin
|
|
25
|
+
* schedules a retry with exponential backoff (30s → 60s → 120s → 240s,
|
|
26
|
+
* capped at 300s) and keeps trying forever until either `connect`
|
|
27
|
+
* succeeds or `stop()` cancels the loop. This mirrors beeos-claw's
|
|
28
|
+
* `localServer.onceAgentMappingReady(...)` deferred-connect pattern —
|
|
29
|
+
* see `[index.ts:484-498](agents/beeos-claw/src/index.ts)`.
|
|
30
|
+
*/
|
|
31
|
+
import { MessageSDK } from "@beeos-ai/message-sdk";
|
|
32
|
+
import { createDeviceMessagingTokenProvider } from "../../messaging/token-provider.js";
|
|
33
|
+
import { MessageSdkBusyReplyHandler } from "./busy-reply.js";
|
|
34
|
+
import { buildMessageBusInboundHandler } from "./inbound.js";
|
|
35
|
+
import { installMessageBusOutbound } from "./outbound.js";
|
|
36
|
+
import { TurnContextRegister } from "./turn-context.js";
|
|
37
|
+
/**
|
|
38
|
+
* Backoff schedule for token / connect failures (milliseconds). Each
|
|
39
|
+
* entry is the delay BEFORE the next retry. The last entry caps the
|
|
40
|
+
* delay; once we hit the cap we keep retrying forever at that interval.
|
|
41
|
+
*
|
|
42
|
+
* Tunable via `MessageBusPluginOptions.retrySchedule` — tests pin a
|
|
43
|
+
* tighter schedule (e.g. `[5, 5, 5]`) to keep `vi.useFakeTimers()`
|
|
44
|
+
* runs cheap.
|
|
45
|
+
*/
|
|
46
|
+
export const DEFAULT_RETRY_SCHEDULE_MS = Object.freeze([
|
|
47
|
+
30_000,
|
|
48
|
+
60_000,
|
|
49
|
+
120_000,
|
|
50
|
+
240_000,
|
|
51
|
+
300_000,
|
|
52
|
+
]);
|
|
53
|
+
/** Attempt indices (1-based) where a `warn` log is preferred over `debug`. */
|
|
54
|
+
const WARN_ATTEMPT_INDICES = new Set([1, 3, 5, 10]);
|
|
55
|
+
export class MessageBusPlugin {
|
|
56
|
+
opts;
|
|
57
|
+
name = "message-bus";
|
|
58
|
+
ctx;
|
|
59
|
+
sdk = null;
|
|
60
|
+
register = null;
|
|
61
|
+
unsubscribeOutbound = null;
|
|
62
|
+
resolvedPrincipalId = "";
|
|
63
|
+
// Connect-loop state.
|
|
64
|
+
stopped = false;
|
|
65
|
+
retryHandle = null;
|
|
66
|
+
// When the loop is sleeping in `sleep(ms)`, this resolver lets
|
|
67
|
+
// `stop()` (or any other test-level cancel) wake it up early with
|
|
68
|
+
// `cancelled = true`. Always cleared back to `null` once the resolver
|
|
69
|
+
// fires.
|
|
70
|
+
retryResolve = null;
|
|
71
|
+
connectAttempt = 0;
|
|
72
|
+
legacyDeprecationLogged = false;
|
|
73
|
+
// Resolves once the plugin has either successfully connected OR is
|
|
74
|
+
// permanently disabled. Tests await this to avoid racing the
|
|
75
|
+
// background loop. Production callers ignore it.
|
|
76
|
+
connectSettled = Promise.resolve();
|
|
77
|
+
resolveConnectSettled = () => undefined;
|
|
78
|
+
constructor(opts = {}) {
|
|
79
|
+
this.opts = opts;
|
|
80
|
+
}
|
|
81
|
+
async init(ctx) {
|
|
82
|
+
this.ctx = ctx;
|
|
83
|
+
if (!ctx.config.messageBus?.enabled) {
|
|
84
|
+
ctx.log.info("message-bus: disabled (set BEEOS_MESSAGE_BUS_ENABLED=true or --message-bus to enable)");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!this.opts.keypair) {
|
|
88
|
+
ctx.log.warn("message-bus: enabled but no Ed25519 identity available — stays disabled");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!ctx.config.agentGatewayUrl) {
|
|
92
|
+
ctx.log.warn("message-bus: enabled but no agentGatewayUrl configured — stays disabled");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async start() {
|
|
97
|
+
const ctx = this.ctx;
|
|
98
|
+
if (!ctx)
|
|
99
|
+
return;
|
|
100
|
+
if (!ctx.config.messageBus?.enabled)
|
|
101
|
+
return;
|
|
102
|
+
if (!this.opts.keypair)
|
|
103
|
+
return;
|
|
104
|
+
if (!ctx.config.agentGatewayUrl)
|
|
105
|
+
return;
|
|
106
|
+
this.connectSettled = new Promise((resolve) => {
|
|
107
|
+
this.resolveConnectSettled = resolve;
|
|
108
|
+
});
|
|
109
|
+
// Kick off the loop. Do NOT await — the bootstrap should not block
|
|
110
|
+
// on a remote handshake. The loop reschedules itself via setTimeout
|
|
111
|
+
// until either `tryConnectOnce` returns true or `stop()` is called.
|
|
112
|
+
void this.runConnectLoop();
|
|
113
|
+
}
|
|
114
|
+
async stop() {
|
|
115
|
+
this.stopped = true;
|
|
116
|
+
this.cancelPendingRetry();
|
|
117
|
+
// Resolve any outstanding waiter so test code that awaits
|
|
118
|
+
// `whenSettled()` does not hang past stop().
|
|
119
|
+
this.resolveConnectSettled();
|
|
120
|
+
if (this.unsubscribeOutbound) {
|
|
121
|
+
try {
|
|
122
|
+
this.unsubscribeOutbound();
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
/* ignore */
|
|
126
|
+
}
|
|
127
|
+
this.unsubscribeOutbound = null;
|
|
128
|
+
}
|
|
129
|
+
if (this.sdk) {
|
|
130
|
+
try {
|
|
131
|
+
await this.sdk.disconnect();
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
this.ctx?.log.warn({ err: err instanceof Error ? err.message : String(err) }, "message-bus: disconnect failed");
|
|
135
|
+
}
|
|
136
|
+
this.sdk = null;
|
|
137
|
+
}
|
|
138
|
+
if (this.register) {
|
|
139
|
+
this.register.reset();
|
|
140
|
+
this.register = null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Test seam — exposes the resolved principal so integration tests can
|
|
144
|
+
// assert what the plugin actually subscribed to without poking at
|
|
145
|
+
// private state.
|
|
146
|
+
get principalId() {
|
|
147
|
+
return this.resolvedPrincipalId;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Test helper — resolves once `start()`'s connect loop has either
|
|
151
|
+
* successfully connected or `stop()` was called. Production code
|
|
152
|
+
* never needs this.
|
|
153
|
+
*/
|
|
154
|
+
whenSettled() {
|
|
155
|
+
return this.connectSettled;
|
|
156
|
+
}
|
|
157
|
+
// ── Internals ──────────────────────────────────────────────────────────
|
|
158
|
+
async runConnectLoop() {
|
|
159
|
+
const ctx = this.ctx;
|
|
160
|
+
const log = ctx.log;
|
|
161
|
+
while (!this.stopped) {
|
|
162
|
+
this.connectAttempt += 1;
|
|
163
|
+
const ok = await this.tryConnectOnce(this.connectAttempt);
|
|
164
|
+
if (ok) {
|
|
165
|
+
this.resolveConnectSettled();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (this.stopped) {
|
|
169
|
+
this.resolveConnectSettled();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const delayMs = this.nextDelayMs(this.connectAttempt);
|
|
173
|
+
this.logRetryScheduled(this.connectAttempt, delayMs, log);
|
|
174
|
+
const cancelled = await this.sleep(delayMs);
|
|
175
|
+
if (cancelled) {
|
|
176
|
+
this.resolveConnectSettled();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
this.resolveConnectSettled();
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Single connect attempt. Returns `true` on success (sdk connected,
|
|
184
|
+
* handlers + listener installed) and `false` on any failure (caller
|
|
185
|
+
* should schedule a retry).
|
|
186
|
+
*
|
|
187
|
+
* Each attempt builds a FRESH `MessageSDK` instance — re-using one
|
|
188
|
+
* across reconnects would carry stale handlers and confuse the
|
|
189
|
+
* centrifuge-js internal state. The SDK has its own internal
|
|
190
|
+
* reconnect once `.connect()` succeeds; this loop is for the OPENING
|
|
191
|
+
* handshake only.
|
|
192
|
+
*/
|
|
193
|
+
async tryConnectOnce(attempt) {
|
|
194
|
+
const ctx = this.ctx;
|
|
195
|
+
const log = ctx.log;
|
|
196
|
+
const keypair = this.opts.keypair;
|
|
197
|
+
const agentGatewayUrl = ctx.config.agentGatewayUrl;
|
|
198
|
+
const tokenProvider = this.opts.tokenProviderFactory?.({ agentGatewayUrl, keypair }) ??
|
|
199
|
+
createDeviceMessagingTokenProvider({ agentGatewayUrl, keypair });
|
|
200
|
+
const sdk = this.opts.sdkFactory?.(log) ??
|
|
201
|
+
new MessageSDK({
|
|
202
|
+
// No serviceUrl — agents talk to MS only via Agent Gateway
|
|
203
|
+
// proxy + Centrifugo (P6 boundary).
|
|
204
|
+
centrifugoUrl: ctx.config.messageBus.centrifugoUrl || undefined,
|
|
205
|
+
}, wrapLoggerForSdk(log));
|
|
206
|
+
let tok;
|
|
207
|
+
try {
|
|
208
|
+
tok = await tokenProvider(ctx.config.messageBus.principalIdOverride ?? "");
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
this.logAttemptFailure(attempt, "messaging-token fetch failed", err, log);
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const principalId = tok.principal_id;
|
|
215
|
+
if (!principalId) {
|
|
216
|
+
this.logAttemptFailure(attempt, "gateway returned empty principal_id", null, log);
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
const register = new TurnContextRegister();
|
|
220
|
+
const busyReply = new MessageSdkBusyReplyHandler({ sdk });
|
|
221
|
+
const chatHandler = buildMessageBusInboundHandler({
|
|
222
|
+
host: ctx.host,
|
|
223
|
+
register,
|
|
224
|
+
busyReply,
|
|
225
|
+
logger: log,
|
|
226
|
+
localAgentId: this.opts.localAgentId,
|
|
227
|
+
source: "chat_message",
|
|
228
|
+
});
|
|
229
|
+
const legacyHandler = buildMessageBusInboundHandler({
|
|
230
|
+
host: ctx.host,
|
|
231
|
+
register,
|
|
232
|
+
busyReply,
|
|
233
|
+
logger: log,
|
|
234
|
+
localAgentId: this.opts.localAgentId,
|
|
235
|
+
source: "agent_request",
|
|
236
|
+
});
|
|
237
|
+
sdk.onMessage("chat_message", async (env) => chatHandler(env));
|
|
238
|
+
// Gap F — fire a one-shot deprecation warn the FIRST time a legacy
|
|
239
|
+
// `agent_request` envelope arrives. Mirrors beeos-claw
|
|
240
|
+
// [`index.ts:551-557`](agents/beeos-claw/src/index.ts).
|
|
241
|
+
sdk.onMessage("agent_request", async (env) => {
|
|
242
|
+
if (!this.legacyDeprecationLogged) {
|
|
243
|
+
this.legacyDeprecationLogged = true;
|
|
244
|
+
log.warn({}, "message-bus: received legacy 'agent_request' envelope — this path is deprecated; please migrate upstream callers to 'chat_message' (L0 AgentInvocationService)");
|
|
245
|
+
}
|
|
246
|
+
await legacyHandler(env);
|
|
247
|
+
});
|
|
248
|
+
const unsubscribe = installMessageBusOutbound({
|
|
249
|
+
host: ctx.host,
|
|
250
|
+
sdk,
|
|
251
|
+
register,
|
|
252
|
+
logger: log,
|
|
253
|
+
});
|
|
254
|
+
sdk.onceConnected(() => {
|
|
255
|
+
log.info({
|
|
256
|
+
principalId,
|
|
257
|
+
centrifugoUrl: tok.centrifugo_url,
|
|
258
|
+
channels: tok.channels,
|
|
259
|
+
attempt,
|
|
260
|
+
}, "message-bus: connected");
|
|
261
|
+
});
|
|
262
|
+
try {
|
|
263
|
+
await sdk.connect(principalId, {
|
|
264
|
+
centrifugoUrl: tok.centrifugo_url,
|
|
265
|
+
tokenProvider,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
// Roll back the listener so we don't double-subscribe on the
|
|
270
|
+
// next retry, and disconnect the half-opened SDK.
|
|
271
|
+
try {
|
|
272
|
+
unsubscribe();
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
/* ignore */
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
await sdk.disconnect();
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
/* ignore */
|
|
282
|
+
}
|
|
283
|
+
this.logAttemptFailure(attempt, "Centrifugo connect failed", err, log);
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
this.sdk = sdk;
|
|
287
|
+
this.register = register;
|
|
288
|
+
this.unsubscribeOutbound = unsubscribe;
|
|
289
|
+
this.resolvedPrincipalId = principalId;
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
nextDelayMs(attempt) {
|
|
293
|
+
const schedule = this.opts.retrySchedule ?? DEFAULT_RETRY_SCHEDULE_MS;
|
|
294
|
+
const idx = Math.min(attempt - 1, schedule.length - 1);
|
|
295
|
+
return schedule[idx];
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Log an attempt failure with attenuated severity — first attempt
|
|
299
|
+
* + a few well-spaced retries get a `warn`, the rest are `debug` to
|
|
300
|
+
* avoid log spam when an instance has never been provisioned.
|
|
301
|
+
*/
|
|
302
|
+
logAttemptFailure(attempt, summary, err, log) {
|
|
303
|
+
const errStr = err == null
|
|
304
|
+
? null
|
|
305
|
+
: err instanceof Error
|
|
306
|
+
? err.message
|
|
307
|
+
: String(err);
|
|
308
|
+
const fields = { attempt };
|
|
309
|
+
if (errStr)
|
|
310
|
+
fields.err = errStr;
|
|
311
|
+
if (WARN_ATTEMPT_INDICES.has(attempt)) {
|
|
312
|
+
log.warn(fields, `message-bus: ${summary} — will retry`);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
log.debug(fields, `message-bus: ${summary} — will retry`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
logRetryScheduled(attempt, delayMs, log) {
|
|
319
|
+
if (WARN_ATTEMPT_INDICES.has(attempt)) {
|
|
320
|
+
log.warn({ attempt, retryInMs: delayMs }, "message-bus: scheduled connect retry");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Sleep `ms` milliseconds. Returns `true` when stop() cancels the
|
|
325
|
+
* timer mid-flight (so the caller breaks out of its loop), or
|
|
326
|
+
* `false` once the timer fires normally.
|
|
327
|
+
*/
|
|
328
|
+
sleep(ms) {
|
|
329
|
+
const sched = this.scheduler();
|
|
330
|
+
return new Promise((resolve) => {
|
|
331
|
+
this.retryResolve = resolve;
|
|
332
|
+
this.retryHandle = sched.setTimeout(() => {
|
|
333
|
+
this.retryHandle = null;
|
|
334
|
+
this.retryResolve = null;
|
|
335
|
+
resolve(false);
|
|
336
|
+
}, ms);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
cancelPendingRetry() {
|
|
340
|
+
if (this.retryHandle == null)
|
|
341
|
+
return;
|
|
342
|
+
const sched = this.scheduler();
|
|
343
|
+
try {
|
|
344
|
+
sched.clearTimeout(this.retryHandle);
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
/* ignore */
|
|
348
|
+
}
|
|
349
|
+
this.retryHandle = null;
|
|
350
|
+
const resolve = this.retryResolve;
|
|
351
|
+
this.retryResolve = null;
|
|
352
|
+
if (resolve)
|
|
353
|
+
resolve(true);
|
|
354
|
+
}
|
|
355
|
+
scheduler() {
|
|
356
|
+
return (this.opts.scheduler ?? {
|
|
357
|
+
setTimeout: (cb, t) => setTimeout(cb, t),
|
|
358
|
+
clearTimeout: (h) => clearTimeout(h),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Adapt the device-agent pino logger to the MessageSDKLogger shape the
|
|
364
|
+
* shared SDK expects. The SDK calls `info(msg)` / `warn(msg, fields?)`
|
|
365
|
+
* with positional args; pino's signature is `(obj, msg)` so we coerce
|
|
366
|
+
* to a stringly form that prints sanely either way.
|
|
367
|
+
*/
|
|
368
|
+
function wrapLoggerForSdk(log) {
|
|
369
|
+
return {
|
|
370
|
+
info: (...args) => log.info(formatSdkArgs(args)),
|
|
371
|
+
warn: (...args) => log.warn(formatSdkArgs(args)),
|
|
372
|
+
error: (...args) => log.error(formatSdkArgs(args)),
|
|
373
|
+
debug: (...args) => log.debug(formatSdkArgs(args)),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function formatSdkArgs(args) {
|
|
377
|
+
return args
|
|
378
|
+
.map((a) => {
|
|
379
|
+
if (typeof a === "string")
|
|
380
|
+
return a;
|
|
381
|
+
if (a instanceof Error)
|
|
382
|
+
return a.message;
|
|
383
|
+
try {
|
|
384
|
+
return JSON.stringify(a);
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
return String(a);
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
.join(" ");
|
|
391
|
+
}
|
|
392
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/message-bus/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,UAAU,EAAsB,MAAM,uBAAuB,CAAC;AAEvE,OAAO,EAAE,kCAAkC,EAAE,MAAM,mCAAmC,CAAC;AAIvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACxE,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;CACR,CAAC,CAAC;AAEH,8EAA8E;AAC9E,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AA6CpD,MAAM,OAAO,gBAAgB;IAwBE;IAvBpB,IAAI,GAAG,aAAa,CAAC;IACtB,GAAG,CAAiB;IACpB,GAAG,GAAsB,IAAI,CAAC;IAC9B,QAAQ,GAA+B,IAAI,CAAC;IAC5C,mBAAmB,GAAwB,IAAI,CAAC;IAChD,mBAAmB,GAAG,E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AE,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,YAAY,KAAK;YAAE,OAAO,CAAC,CAAC,OAAO,CAAC;QACzC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbound — bridge AgentHost events back to the MS IM channel.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to `AgentHost.on(listener)` ONCE at plugin start, then
|
|
5
|
+
* publishes Centrifugo `ch:{channelId}` envelopes whose shape matches
|
|
6
|
+
* the contract the rest of the BeeOS platform expects:
|
|
7
|
+
*
|
|
8
|
+
* - `agent_reply_delta` — streaming chunks. Carries an inner
|
|
9
|
+
* `update.sessionUpdate` field that callers (A2A / OpenAPI) demux
|
|
10
|
+
* on. Only `agent_message_chunk` is treated as user-visible
|
|
11
|
+
* reply text by `backend/pkg/convmsg/extract.go::extractNestedDelta`;
|
|
12
|
+
* `agent_thought_chunk` is intentionally filtered out so reasoning
|
|
13
|
+
* never leaks into status text.
|
|
14
|
+
*
|
|
15
|
+
* - `agent_reply` — terminal reply on `task:end`. `payload.text` for
|
|
16
|
+
* success, `payload.error` for failure. Matches
|
|
17
|
+
* `chatinvoke/invoker.go::extractReplyFinal`.
|
|
18
|
+
*
|
|
19
|
+
* Each envelope carries `in_reply_to` set to the original request's
|
|
20
|
+
* `message_id`, which is what the L0 `/channels/{id}/wait` endpoint
|
|
21
|
+
* matches on.
|
|
22
|
+
*
|
|
23
|
+
* The listener filters by taskId via the in-flight register — events
|
|
24
|
+
* for tasks NOT submitted through the message-bus inbound (e.g. ACP
|
|
25
|
+
* `session/prompt` traffic) are ignored, so the two surfaces never
|
|
26
|
+
* collide.
|
|
27
|
+
*/
|
|
28
|
+
import type { MessageSDK } from "@beeos-ai/message-sdk";
|
|
29
|
+
import type { AgentHost } from "../../ports/agent-host.js";
|
|
30
|
+
import type { Logger } from "../../logger/index.js";
|
|
31
|
+
import type { TurnContextRegister } from "./turn-context.js";
|
|
32
|
+
export interface MessageBusOutboundOptions {
|
|
33
|
+
host: AgentHost;
|
|
34
|
+
sdk: MessageSDK;
|
|
35
|
+
register: TurnContextRegister;
|
|
36
|
+
logger: Logger;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Install the outbound listener on the host. Returns an `unsubscribe`
|
|
40
|
+
* function — call it from the plugin's `stop()` so we don't keep
|
|
41
|
+
* publishing after the SDK has been disconnected.
|
|
42
|
+
*/
|
|
43
|
+
export declare function installMessageBusOutbound(opts: MessageBusOutboundOptions): () => void;
|