@beeos-ai/device-agent 0.7.2 → 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/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/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
package/dist/inbound/cli/main.js
CHANGED
|
@@ -223,6 +223,15 @@ export function parseArgs(argv) {
|
|
|
223
223
|
case "--vlm-config-file":
|
|
224
224
|
out.configFile = next();
|
|
225
225
|
break;
|
|
226
|
+
case "--message-bus":
|
|
227
|
+
out.messageBus = true;
|
|
228
|
+
break;
|
|
229
|
+
case "--no-message-bus":
|
|
230
|
+
out.messageBus = false;
|
|
231
|
+
break;
|
|
232
|
+
case "--centrifugo-url":
|
|
233
|
+
out.centrifugoUrl = next();
|
|
234
|
+
break;
|
|
226
235
|
default:
|
|
227
236
|
if (a.startsWith("--")) {
|
|
228
237
|
// Unknown flags are intentionally tolerated (not thrown) so that
|
|
@@ -293,6 +302,9 @@ Options:
|
|
|
293
302
|
--http-host <host> HTTP host (default: 127.0.0.1 — local only)
|
|
294
303
|
--http-port <port> HTTP port (default: 9090)
|
|
295
304
|
--http-cors-origins <list> Comma-separated allowed CORS origins (or '*')
|
|
305
|
+
--message-bus Enable BeeOS Message Service plugin (chat_message inbound + agent_reply outbound)
|
|
306
|
+
--no-message-bus Force-disable the Message Service plugin (overrides BEEOS_MESSAGE_BUS_ENABLED)
|
|
307
|
+
--centrifugo-url <url> Override Centrifugo WebSocket URL (defaults to gateway-issued)
|
|
296
308
|
--log-level <lvl> Log level (default: info)
|
|
297
309
|
--config <path> Config file path (default: ~/.beeos/config.json)
|
|
298
310
|
--vlm-config-file <p> Alias for --config (per-instance ~/.beeos/<id>.config.json)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/inbound/cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,OAAiB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,wEAAwE;IACxE,yEAAyE;IACzE,2EAA2E;IAC3E,6DAA6D;IAC7D,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;QACtB,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACzB,OAAO,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;I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CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter — Ed25519 messaging-token provider for device-agent.
|
|
3
|
+
*
|
|
4
|
+
* Bridges device-agent's `IDeviceIdentity` (which exposes a `KeyPair`
|
|
5
|
+
* with raw 32-byte private/public Ed25519 keys) to the
|
|
6
|
+
* `MessagingIdentity` interface consumed by `@beeos-ai/message-sdk`'s
|
|
7
|
+
* `createMessagingTokenProvider`.
|
|
8
|
+
*
|
|
9
|
+
* The actual Ed25519 signing reuses the same `sign()` helper from
|
|
10
|
+
* `@beeos-ai/bridge-client` that powers `agent-gateway-client.ts` —
|
|
11
|
+
* keeping a single signing path means the wire format cannot drift
|
|
12
|
+
* between the bridge handshake, file presign, and messaging-token
|
|
13
|
+
* endpoints.
|
|
14
|
+
*/
|
|
15
|
+
import { type MessagingIdentity, type TokenProvider } from "@beeos-ai/message-sdk";
|
|
16
|
+
import type { KeyPair } from "../ports/identity.js";
|
|
17
|
+
export interface DeviceMessagingTokenProviderOptions {
|
|
18
|
+
/** Agent Gateway base URL (e.g. `https://agent-gw.beeos.ai`). */
|
|
19
|
+
agentGatewayUrl: string;
|
|
20
|
+
keypair: KeyPair;
|
|
21
|
+
/** Test seam — defaults to `globalThis.fetch`. */
|
|
22
|
+
fetchImpl?: typeof fetch;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Wrap a raw Ed25519 keypair into the `MessagingIdentity` shape expected
|
|
26
|
+
* by the shared `@beeos-ai/message-sdk` token provider.
|
|
27
|
+
*
|
|
28
|
+
* Exported separately from `createDeviceMessagingTokenProvider` so unit
|
|
29
|
+
* tests can verify the produced signature with `crypto.verify`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function keypairToMessagingIdentity(keypair: KeyPair): MessagingIdentity;
|
|
32
|
+
/**
|
|
33
|
+
* Build a ready-to-use `TokenProvider` for `MessageSDK.connect`.
|
|
34
|
+
* The provider POSTs to `${agentGatewayUrl}/api/v1/messaging/token`
|
|
35
|
+
* with Ed25519 headers and returns the canonical Centrifugo token
|
|
36
|
+
* payload (token / centrifugo_url / principal_id / expires_at).
|
|
37
|
+
*
|
|
38
|
+
* The Agent Gateway derives the principal from the request's Ed25519
|
|
39
|
+
* public key (pod-is-principal), so the `principalId` argument passed
|
|
40
|
+
* to the returned function is ignored on the wire — callers should
|
|
41
|
+
* still re-read `tok.principal_id` after the first call.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createDeviceMessagingTokenProvider(opts: DeviceMessagingTokenProviderOptions): TokenProvider;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter — Ed25519 messaging-token provider for device-agent.
|
|
3
|
+
*
|
|
4
|
+
* Bridges device-agent's `IDeviceIdentity` (which exposes a `KeyPair`
|
|
5
|
+
* with raw 32-byte private/public Ed25519 keys) to the
|
|
6
|
+
* `MessagingIdentity` interface consumed by `@beeos-ai/message-sdk`'s
|
|
7
|
+
* `createMessagingTokenProvider`.
|
|
8
|
+
*
|
|
9
|
+
* The actual Ed25519 signing reuses the same `sign()` helper from
|
|
10
|
+
* `@beeos-ai/bridge-client` that powers `agent-gateway-client.ts` —
|
|
11
|
+
* keeping a single signing path means the wire format cannot drift
|
|
12
|
+
* between the bridge handshake, file presign, and messaging-token
|
|
13
|
+
* endpoints.
|
|
14
|
+
*/
|
|
15
|
+
import * as crypto from "node:crypto";
|
|
16
|
+
import { createMessagingTokenProvider, } from "@beeos-ai/message-sdk";
|
|
17
|
+
// PKCS8 prefix that wraps a raw 32-byte Ed25519 seed so node:crypto's
|
|
18
|
+
// createPrivateKey can ingest it. Identical to the prefix used by
|
|
19
|
+
// @beeos-ai/bridge-client and beeos-claw's agent-auth.
|
|
20
|
+
const ED25519_PKCS8_PREFIX = Buffer.from("302e020100300506032b657004220420", "hex");
|
|
21
|
+
/**
|
|
22
|
+
* Wrap a raw Ed25519 keypair into the `MessagingIdentity` shape expected
|
|
23
|
+
* by the shared `@beeos-ai/message-sdk` token provider.
|
|
24
|
+
*
|
|
25
|
+
* Exported separately from `createDeviceMessagingTokenProvider` so unit
|
|
26
|
+
* tests can verify the produced signature with `crypto.verify`.
|
|
27
|
+
*/
|
|
28
|
+
export function keypairToMessagingIdentity(keypair) {
|
|
29
|
+
return {
|
|
30
|
+
publicKeyBase64: () => Buffer.from(keypair.publicKey).toString("base64"),
|
|
31
|
+
sign: (bytes) => {
|
|
32
|
+
const wrapped = keypair.privateKey.length === 32
|
|
33
|
+
? Buffer.concat([
|
|
34
|
+
ED25519_PKCS8_PREFIX,
|
|
35
|
+
Buffer.from(keypair.privateKey),
|
|
36
|
+
])
|
|
37
|
+
: Buffer.from(keypair.privateKey);
|
|
38
|
+
const keyObj = crypto.createPrivateKey({
|
|
39
|
+
key: wrapped,
|
|
40
|
+
format: "der",
|
|
41
|
+
type: "pkcs8",
|
|
42
|
+
});
|
|
43
|
+
return new Uint8Array(crypto.sign(null, Buffer.from(bytes), keyObj));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build a ready-to-use `TokenProvider` for `MessageSDK.connect`.
|
|
49
|
+
* The provider POSTs to `${agentGatewayUrl}/api/v1/messaging/token`
|
|
50
|
+
* with Ed25519 headers and returns the canonical Centrifugo token
|
|
51
|
+
* payload (token / centrifugo_url / principal_id / expires_at).
|
|
52
|
+
*
|
|
53
|
+
* The Agent Gateway derives the principal from the request's Ed25519
|
|
54
|
+
* public key (pod-is-principal), so the `principalId` argument passed
|
|
55
|
+
* to the returned function is ignored on the wire — callers should
|
|
56
|
+
* still re-read `tok.principal_id` after the first call.
|
|
57
|
+
*/
|
|
58
|
+
export function createDeviceMessagingTokenProvider(opts) {
|
|
59
|
+
return createMessagingTokenProvider({
|
|
60
|
+
agentGatewayUrl: opts.agentGatewayUrl,
|
|
61
|
+
identity: keypairToMessagingIdentity(opts.keypair),
|
|
62
|
+
fetchImpl: opts.fetchImpl,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=token-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-provider.js","sourceRoot":"","sources":["../../src/messaging/token-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EACL,4BAA4B,GAG7B,MAAM,uBAAuB,CAAC;AAI/B,sEAAsE;AACtE,kEAAkE;AAClE,uDAAuD;AACvD,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CACtC,kCAAkC,EAClC,KAAK,CACN,CAAC;AAUF;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAgB;IAEhB,OAAO;QACL,eAAe,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACxE,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACd,MAAM,OAAO,GACX,OAAO,CAAC,UAAU,CAAC,MAAM,KAAK,EAAE;gBAC9B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;oBACZ,oBAAoB;oBACpB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;iBAChC,CAAC;gBACJ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC;gBACrC,GAAG,EAAE,OAAO;gBACZ,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;YACH,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kCAAkC,CAChD,IAAyC;IAEzC,OAAO,4BAA4B,CAAC;QAClC,eAAe,EAAE,IAAI,CAAC,eAAe;QACrC,QAAQ,EAAE,0BAA0B,CAAC,IAAI,CAAC,OAAO,CAAC;QAClD,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Busy-reply path — emits a terminal `agent_reply` with `error: agent_busy`
|
|
3
|
+
* back to the caller's IM channel when a second `chat_message` arrives
|
|
4
|
+
* while a turn is already in flight.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the SessionManager's "one turn per session" contract that the
|
|
7
|
+
* ACP handlers enforce — concurrent prompts on the same session are
|
|
8
|
+
* rejected, not queued. The MS path keeps the same semantics so callers
|
|
9
|
+
* (L0 / A2A / MCP / OpenAPI) get a deterministic refusal instead of a
|
|
10
|
+
* `/wait` timeout.
|
|
11
|
+
*
|
|
12
|
+
* Type/payload alignment: uses the same `agent_reply` type that the
|
|
13
|
+
* outbound listener emits, with a `{ error }` body that matches
|
|
14
|
+
* `backend/pkg/chatinvoke/invoker.go::extractReplyFinal` (which reads
|
|
15
|
+
* `payload.error` first, falling back to `payload.text`).
|
|
16
|
+
*/
|
|
17
|
+
import type { MessageSDK } from "@beeos-ai/message-sdk";
|
|
18
|
+
export interface BusyReplyRequest {
|
|
19
|
+
channelId: string;
|
|
20
|
+
inboundMessageId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Session key derived from the rejected envelope (via
|
|
23
|
+
* `extractChatPrompt(envelope).sessionKey`). Always set so the busy
|
|
24
|
+
* reply payload has the same `{ session_key, error }` shape as a
|
|
25
|
+
* regular `agent_reply`.
|
|
26
|
+
*/
|
|
27
|
+
sessionKey: string;
|
|
28
|
+
}
|
|
29
|
+
export interface BusyReplyHandler {
|
|
30
|
+
replyBusy(req: BusyReplyRequest): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface BusyReplyHandlerOptions {
|
|
33
|
+
sdk: MessageSDK;
|
|
34
|
+
}
|
|
35
|
+
export declare class MessageSdkBusyReplyHandler implements BusyReplyHandler {
|
|
36
|
+
private readonly opts;
|
|
37
|
+
constructor(opts: BusyReplyHandlerOptions);
|
|
38
|
+
replyBusy(req: BusyReplyRequest): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Busy-reply path — emits a terminal `agent_reply` with `error: agent_busy`
|
|
3
|
+
* back to the caller's IM channel when a second `chat_message` arrives
|
|
4
|
+
* while a turn is already in flight.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the SessionManager's "one turn per session" contract that the
|
|
7
|
+
* ACP handlers enforce — concurrent prompts on the same session are
|
|
8
|
+
* rejected, not queued. The MS path keeps the same semantics so callers
|
|
9
|
+
* (L0 / A2A / MCP / OpenAPI) get a deterministic refusal instead of a
|
|
10
|
+
* `/wait` timeout.
|
|
11
|
+
*
|
|
12
|
+
* Type/payload alignment: uses the same `agent_reply` type that the
|
|
13
|
+
* outbound listener emits, with a `{ error }` body that matches
|
|
14
|
+
* `backend/pkg/chatinvoke/invoker.go::extractReplyFinal` (which reads
|
|
15
|
+
* `payload.error` first, falling back to `payload.text`).
|
|
16
|
+
*/
|
|
17
|
+
export class MessageSdkBusyReplyHandler {
|
|
18
|
+
opts;
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
this.opts = opts;
|
|
21
|
+
}
|
|
22
|
+
async replyBusy(req) {
|
|
23
|
+
await this.opts.sdk.sendToChannel(req.channelId, "agent_reply", {
|
|
24
|
+
session_key: req.sessionKey,
|
|
25
|
+
error: "agent_busy",
|
|
26
|
+
text: "device-agent is processing another request — please retry once it completes.",
|
|
27
|
+
}, { inReplyTo: req.inboundMessageId });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=busy-reply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"busy-reply.js","sourceRoot":"","sources":["../../../src/plugins/message-bus/busy-reply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAwBH,MAAM,OAAO,0BAA0B;IACR;IAA7B,YAA6B,IAA6B;QAA7B,SAAI,GAAJ,IAAI,CAAyB;IAAG,CAAC;IAE9D,KAAK,CAAC,SAAS,CAAC,GAAqB;QACnC,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAC/B,GAAG,CAAC,SAAS,EACb,aAAa,EACb;YACE,WAAW,EAAE,GAAG,CAAC,UAAU;YAC3B,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,8EAA8E;SACrF,EACD,EAAE,SAAS,EAAE,GAAG,CAAC,gBAAgB,EAAE,CACpC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound — `chat_message` / `agent_request` envelope handler.
|
|
3
|
+
*
|
|
4
|
+
* Wires `MessageSDK.onMessage(...)` to `AgentHost.submitTask(...)`,
|
|
5
|
+
* extracting the prompt + IM correlators via the shared
|
|
6
|
+
* `extractChatPrompt` helper from `@beeos-ai/message-sdk`.
|
|
7
|
+
*
|
|
8
|
+
* Flow per inbound envelope:
|
|
9
|
+
*
|
|
10
|
+
* 1. Extract `{ message, channelId, messageId, contextId }` from the
|
|
11
|
+
* payload (returns null on malformed envelopes — silently dropped).
|
|
12
|
+
* 2. Reject if no `channelId` or no `messageId` — replies must round
|
|
13
|
+
* trip through `ch:{channelId}` with `in_reply_to=messageId`, so
|
|
14
|
+
* neither is optional for our outbound bridge.
|
|
15
|
+
* 3. Try to claim the in-flight turn register. If busy → busy-reply
|
|
16
|
+
* path (handled by the caller); otherwise submit to the host.
|
|
17
|
+
* 4. The submitted `taskId` gets stored in the register so the
|
|
18
|
+
* outbound listener can correlate AgentEvents back to the right
|
|
19
|
+
* MS channel.
|
|
20
|
+
*
|
|
21
|
+
* The inbound handler intentionally does NOT subscribe to the host
|
|
22
|
+
* event stream — that's `outbound.ts`'s job, registered ONCE at plugin
|
|
23
|
+
* start. Keeping the two sides decoupled means we never accidentally
|
|
24
|
+
* double-publish for the same turn.
|
|
25
|
+
*/
|
|
26
|
+
import { type MessageEnvelope } from "@beeos-ai/message-sdk";
|
|
27
|
+
import type { AgentHost } from "../../ports/agent-host.js";
|
|
28
|
+
import type { Logger } from "../../logger/index.js";
|
|
29
|
+
import type { TurnContextRegister } from "./turn-context.js";
|
|
30
|
+
import type { BusyReplyHandler } from "./busy-reply.js";
|
|
31
|
+
export interface MessageBusInboundOptions {
|
|
32
|
+
host: AgentHost;
|
|
33
|
+
register: TurnContextRegister;
|
|
34
|
+
busyReply: BusyReplyHandler;
|
|
35
|
+
logger: Logger;
|
|
36
|
+
/**
|
|
37
|
+
* Local agent identity surfaced to `extractChatPrompt`. Used only for
|
|
38
|
+
* sessionKey prefixing; safe to leave empty in standalone-style
|
|
39
|
+
* tests.
|
|
40
|
+
*/
|
|
41
|
+
localAgentId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Source tag passed to `extractChatPrompt`. Identifies which Centrifugo
|
|
44
|
+
* envelope type triggered the call — `chat_message` is the primary L0
|
|
45
|
+
* path, `agent_request` is the legacy A2A SendTask shim.
|
|
46
|
+
*/
|
|
47
|
+
source: "chat_message" | "agent_request";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the per-envelope handler. The returned function is what gets
|
|
51
|
+
* registered with `sdk.onMessage(type, handler)` — keeping the factory
|
|
52
|
+
* shape lets unit tests instantiate the closure with mock collaborators
|
|
53
|
+
* and feed envelopes synchronously.
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildMessageBusInboundHandler(opts: MessageBusInboundOptions): (envelope: MessageEnvelope) => Promise<void>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound — `chat_message` / `agent_request` envelope handler.
|
|
3
|
+
*
|
|
4
|
+
* Wires `MessageSDK.onMessage(...)` to `AgentHost.submitTask(...)`,
|
|
5
|
+
* extracting the prompt + IM correlators via the shared
|
|
6
|
+
* `extractChatPrompt` helper from `@beeos-ai/message-sdk`.
|
|
7
|
+
*
|
|
8
|
+
* Flow per inbound envelope:
|
|
9
|
+
*
|
|
10
|
+
* 1. Extract `{ message, channelId, messageId, contextId }` from the
|
|
11
|
+
* payload (returns null on malformed envelopes — silently dropped).
|
|
12
|
+
* 2. Reject if no `channelId` or no `messageId` — replies must round
|
|
13
|
+
* trip through `ch:{channelId}` with `in_reply_to=messageId`, so
|
|
14
|
+
* neither is optional for our outbound bridge.
|
|
15
|
+
* 3. Try to claim the in-flight turn register. If busy → busy-reply
|
|
16
|
+
* path (handled by the caller); otherwise submit to the host.
|
|
17
|
+
* 4. The submitted `taskId` gets stored in the register so the
|
|
18
|
+
* outbound listener can correlate AgentEvents back to the right
|
|
19
|
+
* MS channel.
|
|
20
|
+
*
|
|
21
|
+
* The inbound handler intentionally does NOT subscribe to the host
|
|
22
|
+
* event stream — that's `outbound.ts`'s job, registered ONCE at plugin
|
|
23
|
+
* start. Keeping the two sides decoupled means we never accidentally
|
|
24
|
+
* double-publish for the same turn.
|
|
25
|
+
*/
|
|
26
|
+
import { extractChatPrompt, } from "@beeos-ai/message-sdk";
|
|
27
|
+
/**
|
|
28
|
+
* Build the per-envelope handler. The returned function is what gets
|
|
29
|
+
* registered with `sdk.onMessage(type, handler)` — keeping the factory
|
|
30
|
+
* shape lets unit tests instantiate the closure with mock collaborators
|
|
31
|
+
* and feed envelopes synchronously.
|
|
32
|
+
*/
|
|
33
|
+
export function buildMessageBusInboundHandler(opts) {
|
|
34
|
+
return async (envelope) => {
|
|
35
|
+
const prompt = extractChatPrompt(envelope, {
|
|
36
|
+
source: opts.source,
|
|
37
|
+
localAgentId: opts.localAgentId ?? "",
|
|
38
|
+
});
|
|
39
|
+
if (!prompt) {
|
|
40
|
+
opts.logger.warn({ type: envelope.type, message_id: envelope.message_id }, "message-bus: dropped envelope (no prompt could be extracted)");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!prompt.channelId || !prompt.messageId) {
|
|
44
|
+
opts.logger.warn({
|
|
45
|
+
type: envelope.type,
|
|
46
|
+
hasChannelId: !!prompt.channelId,
|
|
47
|
+
hasMessageId: !!prompt.messageId,
|
|
48
|
+
}, "message-bus: dropped envelope (missing channelId or messageId — cannot correlate reply)");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (opts.register.isBusy()) {
|
|
52
|
+
opts.logger.warn({
|
|
53
|
+
incomingMessageId: prompt.messageId,
|
|
54
|
+
incomingChannelId: prompt.channelId,
|
|
55
|
+
activeTurn: opts.register.current_()?.taskId,
|
|
56
|
+
}, "message-bus: agent busy — sending agent_busy reply");
|
|
57
|
+
await opts.busyReply.replyBusy({
|
|
58
|
+
channelId: prompt.channelId,
|
|
59
|
+
inboundMessageId: prompt.messageId,
|
|
60
|
+
sessionKey: prompt.sessionKey,
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Gap E: forward `prompt.files` URLs into the prompt text so the
|
|
65
|
+
// agent at least sees them. beeos-claw's localServer.agentSend takes
|
|
66
|
+
// files as a separate argument; device-agent's host.submitTask only
|
|
67
|
+
// accepts a single string today. Append a minimal `[attachments]`
|
|
68
|
+
// block — deeper resource-resolver integration is out of scope here.
|
|
69
|
+
const promptText = appendAttachments(prompt.message, prompt.files);
|
|
70
|
+
const submitted = opts.host.submitTask(promptText, {
|
|
71
|
+
correlationTag: `ms:${prompt.channelId}`,
|
|
72
|
+
});
|
|
73
|
+
const claimed = opts.register.claim({
|
|
74
|
+
taskId: submitted.taskId,
|
|
75
|
+
channelId: prompt.channelId,
|
|
76
|
+
inboundMessageId: prompt.messageId,
|
|
77
|
+
sessionKey: prompt.sessionKey,
|
|
78
|
+
contextId: prompt.contextId,
|
|
79
|
+
});
|
|
80
|
+
if (!claimed) {
|
|
81
|
+
// Race between two near-simultaneous publications — undo the
|
|
82
|
+
// submit and treat the second one as busy. host.cancel returns
|
|
83
|
+
// `false` if the task already finished, which is fine.
|
|
84
|
+
opts.host.cancel(submitted.taskId);
|
|
85
|
+
opts.logger.warn({ messageId: prompt.messageId }, "message-bus: turn-context race — cancelling and replying busy");
|
|
86
|
+
await opts.busyReply.replyBusy({
|
|
87
|
+
channelId: prompt.channelId,
|
|
88
|
+
inboundMessageId: prompt.messageId,
|
|
89
|
+
sessionKey: prompt.sessionKey,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
opts.logger.info({
|
|
94
|
+
taskId: submitted.taskId,
|
|
95
|
+
channelId: prompt.channelId,
|
|
96
|
+
inboundMessageId: prompt.messageId,
|
|
97
|
+
contextId: prompt.contextId,
|
|
98
|
+
sessionKey: prompt.sessionKey,
|
|
99
|
+
}, "message-bus: turn started");
|
|
100
|
+
// Surface late submission failures into the outbound stream so the
|
|
101
|
+
// caller's /wait does not hang. The outbound listener already
|
|
102
|
+
// emits an agent_reply on `task:end (error)`; we do NOT await
|
|
103
|
+
// `submitted.done` here because the listener handles all terminal
|
|
104
|
+
// events.
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Append a markdown-style `[attachments]` block listing file URLs to
|
|
109
|
+
* the prompt text. KISS: today the device-agent agent-core only takes
|
|
110
|
+
* a single string prompt, so the only way to surface attachments is
|
|
111
|
+
* inline. Empty `files` returns the message unchanged.
|
|
112
|
+
*
|
|
113
|
+
* Deeper integration (downloading via the resource-resolution layer,
|
|
114
|
+
* uploading to the device sandbox) is intentionally out of scope —
|
|
115
|
+
* see plan §E.
|
|
116
|
+
*/
|
|
117
|
+
function appendAttachments(message, files) {
|
|
118
|
+
if (!files || files.length === 0)
|
|
119
|
+
return message;
|
|
120
|
+
const list = files.map((u) => `- ${u}`).join("\n");
|
|
121
|
+
return `${message}\n\n[attachments]\n${list}`;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=inbound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound.js","sourceRoot":"","sources":["../../../src/plugins/message-bus/inbound.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,iBAAiB,GAElB,MAAM,uBAAuB,CAAC;AA2B/B;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAA8B;IAE9B,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,EAAE;YACzC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,EAAE;SACtC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,EACxD,8DAA8D,CAC/D,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CACd;gBACE,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS;gBAChC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS;aACjC,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,CAAC,MAAM,CAAC,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,EAC/B,+DAA+D,CAChE,CAAC;YACF,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;gBAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,gBAAgB,EAAE,MAAM,CAAC,SAAS;gBAClC,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CACd;YACE,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,gBAAgB,EAAE,MAAM,CAAC,SAAS;YAClC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,EACD,2BAA2B,CAC5B,CAAC;QAEF,mEAAmE;QACnE,8DAA8D;QAC9D,8DAA8D;QAC9D,kEAAkE;QAClE,UAAU;IACZ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,iBAAiB,CAAC,OAAe,EAAE,KAAwB;IAClE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACjD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,GAAG,OAAO,sBAAsB,IAAI,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -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
|
+
}
|