@masons/agent-network 0.6.21 → 0.6.22

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.
@@ -8,7 +8,6 @@ export interface ChannelSetupResult {
8
8
  status: "pending" | "completed" | "expired" | "failed";
9
9
  handoffUrl?: string;
10
10
  expiresAt?: number;
11
- agentHandle?: string;
12
11
  message?: string;
13
12
  }
14
13
  export declare function getDefaultChannelSetupOptions(): StartChannelSetupOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"channel-setup.d.ts","sourceRoot":"","sources":["../src/channel-setup.ts"],"names":[],"mappings":"AAiBA,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IAMnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuBD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAKD,wBAAgB,6BAA6B,IAAI,wBAAwB,CAKxE;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAqC7B;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,GAAG,IAAI,CAejE;AAED,wBAAgB,yBAAyB,IAAI,kBAAkB,GAAG,IAAI,CAMrE;AAmED,wBAAgB,4BAA4B,IAAI,IAAI,CAGnD;AAED,eAAO,MAAM,oBAAoB,QAAqB,CAAC"}
1
+ {"version":3,"file":"channel-setup.d.ts","sourceRoot":"","sources":["../src/channel-setup.ts"],"names":[],"mappings":"AAeA,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IAMnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA2BD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAOD,wBAAgB,6BAA6B,IAAI,wBAAwB,CAKxE;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAqC7B;AAED,wBAAgB,qBAAqB,IAAI,kBAAkB,GAAG,IAAI,CAcjE;AAED,wBAAgB,yBAAyB,IAAI,kBAAkB,GAAG,IAAI,CAMrE;AAmFD,wBAAgB,4BAA4B,IAAI,IAAI,CAGnD;AAED,eAAO,MAAM,oBAAoB,QAAqB,CAAC"}
@@ -1,8 +1,10 @@
1
- import { readExistingConnectorUrl, writeCredentials, } from "./config.js";
1
+ import createDebug from "debug";
2
+ import { readExistingConnectorUrl } from "./config.js";
2
3
  import { resolveConnectorUrlForSetup } from "./connector-url-boundary.js";
3
4
  import { beginBridgeHandoff, completeBridgeHandoff, DEFAULT_IDP_BASE_URL, HANDOFF_TIMEOUT_MS, SetupFlowError, } from "./handoff.js";
4
- import { assertHandoffDeadlineActive } from "./handoff-deadline.js";
5
+ import { acceptBridgeHandoff } from "./handoff-acceptance.js";
5
6
  import { DEFAULT_API_HOST } from "./platform-client.js";
7
+ const dbg = createDebug("agent-network:channel-setup");
6
8
  let pendingSetup = null;
7
9
  let lastSetupStatus = null;
8
10
  export function getDefaultChannelSetupOptions() {
@@ -59,7 +61,6 @@ export function getChannelSetupStatus() {
59
61
  return null;
60
62
  return {
61
63
  status: lastSetupStatus.status,
62
- agentHandle: lastSetupStatus.agentHandle,
63
64
  message: lastSetupStatus.message,
64
65
  };
65
66
  }
@@ -88,20 +89,22 @@ async function completePendingSetup(record) {
88
89
  const handoff = await completeBridgeHandoff(record.session);
89
90
  if (pendingSetup !== record)
90
91
  return;
91
- const creds = {
92
+ const receipt = await acceptBridgeHandoff({
93
+ handoff,
94
+ apiHost: record.apiHost,
92
95
  connectorUrl: record.connectorUrl,
93
- token: handoff.token,
94
- };
95
- await writeCredentials(creds, record.apiHost, record.idpBaseUrl, record.invitedBy, () => assertHandoffDeadlineActive(record.session.expiresAt));
96
+ idpBaseUrl: record.idpBaseUrl,
97
+ pendingTarget: record.invitedBy,
98
+ expiresAt: record.session.expiresAt,
99
+ });
96
100
  lastSetupStatus = {
97
101
  status: "completed",
98
- agentHandle: handoff.agent.handle,
99
- message: `Setup completed for @${handoff.agent.handle}.`,
102
+ message: receipt,
100
103
  finishedAt: Date.now(),
101
104
  };
102
105
  }
103
106
  catch (err) {
104
- if (pendingSetup !== record)
107
+ if (pendingSetup !== record && !supersedesGenericExpiry(err))
105
108
  return;
106
109
  lastSetupStatus = {
107
110
  status: isExpiryError(err) ? "expired" : "failed",
@@ -115,6 +118,11 @@ async function completePendingSetup(record) {
115
118
  }
116
119
  }
117
120
  }
121
+ function supersedesGenericExpiry(err) {
122
+ return (err instanceof SetupFlowError &&
123
+ pendingSetup === null &&
124
+ lastSetupStatus?.status === "expired");
125
+ }
118
126
  function isExpiryError(err) {
119
127
  if (!(err instanceof SetupFlowError))
120
128
  return false;
@@ -123,9 +131,8 @@ function isExpiryError(err) {
123
131
  function safeSetupErrorMessage(err) {
124
132
  if (err instanceof SetupFlowError)
125
133
  return err.message;
126
- if (err instanceof Error)
127
- return `Setup failed (${err.message}). Re-run setup.`;
128
- return "Setup failed. Re-run setup.";
134
+ dbg("setup failed with an unexpected error: %O", err);
135
+ return "Setup failed for an unexpected reason; check debug logs.";
129
136
  }
130
137
  export function _resetChannelSetupForTesting() {
131
138
  pendingSetup = null;
@@ -1 +1 @@
1
- {"version":3,"file":"cli-setup.d.ts","sourceRoot":"","sources":["../src/cli-setup.ts"],"names":[],"mappings":"AA0FA,UAAU,eAAe;IACvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAOD,UAAU,gBAAgB;IACxB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAwFD,wBAAsB,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+EhE"}
1
+ {"version":3,"file":"cli-setup.d.ts","sourceRoot":"","sources":["../src/cli-setup.ts"],"names":[],"mappings":"AA8FA,UAAU,eAAe;IACvB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAOD,UAAU,gBAAgB;IACxB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAmFD,wBAAsB,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2EhE"}
package/dist/cli-setup.js CHANGED
@@ -1,13 +1,12 @@
1
- import { readExistingConnectorUrl, writeCredentials } from "./config.js";
1
+ import { readExistingConnectorUrl } from "./config.js";
2
2
  import { ConnectorUrlConfigurationError, resolveConnectorUrlForSetup, } from "./connector-url-boundary.js";
3
3
  import { beginBridgeHandoff, completeBridgeHandoff, DEFAULT_IDP_BASE_URL, SetupFlowError, } from "./handoff.js";
4
- import { assertHandoffDeadlineActive } from "./handoff-deadline.js";
4
+ import { acceptBridgeHandoff } from "./handoff-acceptance.js";
5
5
  import { DEFAULT_API_HOST, DEFAULT_CONNECTOR_URL, PlatformApiError, } from "./platform-client.js";
6
- async function serverBridgeHandoffFlow(apiHost, idpBaseUrl, runtime, channelInput) {
6
+ async function serverBridgeHandoffFlow(apiHost, idpBaseUrl, runtime) {
7
7
  const session = await beginBridgeHandoff({
8
8
  apiHost,
9
9
  idpBaseUrl,
10
- channelInput,
11
10
  });
12
11
  runtime.writeStdout([
13
12
  "",
@@ -29,7 +28,7 @@ export async function login(ctx) {
29
28
  : DEFAULT_IDP_BASE_URL;
30
29
  let completed;
31
30
  try {
32
- completed = await serverBridgeHandoffFlow(apiHost, idpBaseUrl, ctx.runtime, ctx.channelInput);
31
+ completed = await serverBridgeHandoffFlow(apiHost, idpBaseUrl, ctx.runtime);
33
32
  }
34
33
  catch (err) {
35
34
  if (err instanceof SetupFlowError) {
@@ -61,8 +60,15 @@ export async function login(ctx) {
61
60
  }
62
61
  throw err;
63
62
  }
63
+ let receipt;
64
64
  try {
65
- await writeCredentials({ connectorUrl, token: handoff.token }, apiHost, idpBaseUrl, undefined, () => assertHandoffDeadlineActive(completed.expiresAt));
65
+ receipt = await acceptBridgeHandoff({
66
+ handoff,
67
+ apiHost,
68
+ connectorUrl,
69
+ idpBaseUrl,
70
+ expiresAt: completed.expiresAt,
71
+ });
66
72
  }
67
73
  catch (err) {
68
74
  if (err instanceof SetupFlowError) {
@@ -71,5 +77,5 @@ export async function login(ctx) {
71
77
  }
72
78
  throw err;
73
79
  }
74
- ctx.runtime.log(`✓ Connected as @${handoff.agent.handle}`);
80
+ ctx.runtime.log(`✓ ${receipt}`);
75
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAoCjD,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAsBD,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAMhC;AAYD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAyCjE;AAuCD,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAWD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAeD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAOjE;AAQD,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAYD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAE1E;AASD,wBAAgB,wBAA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D,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAOzD;AAwCD,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAAC,CAsBf;AAQD,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4B1E;AAOD,MAAM,WAAW,YAAY;IAE3B,cAAc,EAAE,OAAO,CAAC;IAExB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B,YAAY,EAAE,OAAO,CAAC;CACvB;AASD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,YAAY,CAAC,CA2BhE;AAOD,wBAAgB,gBAAgB,IAAI,IAAI,CAWvC"}
package/dist/config.js CHANGED
@@ -161,7 +161,6 @@ export async function writeCredentials(creds, apiHost, idpBaseUrl, pendingTarget
161
161
  };
162
162
  if (apiHost) {
163
163
  section.apiHost = apiHost;
164
- platformConfig = { apiHost };
165
164
  }
166
165
  if (idpBaseUrl) {
167
166
  section.idpBaseUrl = idpBaseUrl;
@@ -171,6 +170,9 @@ export async function writeCredentials(creds, apiHost, idpBaseUrl, pendingTarget
171
170
  }
172
171
  await persistConfig(config, assertCanPersist);
173
172
  storedApiKey = creds.token;
173
+ if (apiHost) {
174
+ platformConfig = { apiHost };
175
+ }
174
176
  if (pendingTarget) {
175
177
  storedPendingTarget = pendingTarget;
176
178
  }
@@ -0,0 +1,11 @@
1
+ import type { BridgeHandoffResult } from "./handoff.js";
2
+ export interface AcceptBridgeHandoffOptions {
3
+ handoff: BridgeHandoffResult;
4
+ apiHost: string;
5
+ connectorUrl: string;
6
+ idpBaseUrl: string;
7
+ pendingTarget?: string;
8
+ expiresAt: number;
9
+ }
10
+ export declare function acceptBridgeHandoff(options: AcceptBridgeHandoffOptions): Promise<string>;
11
+ //# sourceMappingURL=handoff-acceptance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff-acceptance.d.ts","sourceRoot":"","sources":["../src/handoff-acceptance.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAiCxD,MAAM,WAAW,0BAA0B;IAEzC,OAAO,EAAE,mBAAmB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAOD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
@@ -0,0 +1,62 @@
1
+ import createDebug from "debug";
2
+ import { writeCredentials } from "./config.js";
3
+ import { assertHandoffDeadlineActive, SetupFlowError, } from "./handoff-deadline.js";
4
+ import { classifyIdentityError, formatCanonicalNode, } from "./identity-format.js";
5
+ import { getIdentity, PlatformApiError, PlatformNetworkError, } from "./platform-client.js";
6
+ const dbg = createDebug("agent-network:handoff-acceptance");
7
+ const ACTIVATION_ACTION = "Messaging under this credential activates when the OpenClaw Gateway next starts or restarts.";
8
+ const NOTHING_CHANGED = "Nothing changed — this runtime still uses the credential it had before.";
9
+ export async function acceptBridgeHandoff(options) {
10
+ const node = await refreshCanonicalNode(options);
11
+ const echoed = options.handoff.agent.handle;
12
+ const mismatch = node.handle === echoed
13
+ ? undefined
14
+ : `Note: the handoff payload claimed @${echoed}; the network says this credential represents ${node.handle ? `@${node.handle}` : node.mstpAddress}, which is the answer used here.`;
15
+ if (mismatch)
16
+ dbg(mismatch);
17
+ await writeCredentials({ connectorUrl: options.connectorUrl, token: options.handoff.token }, options.apiHost, options.idpBaseUrl, options.pendingTarget, () => assertHandoffDeadlineActive(options.expiresAt));
18
+ return formatAcceptanceReceipt(node, mismatch);
19
+ }
20
+ function formatAcceptanceReceipt(node, mismatch) {
21
+ const lines = [formatCanonicalNode("Accepted", node), ACTIVATION_ACTION];
22
+ if (mismatch)
23
+ lines.push(mismatch);
24
+ return lines.join("\n");
25
+ }
26
+ async function refreshCanonicalNode(options) {
27
+ let node;
28
+ try {
29
+ node = await getIdentity({ apiHost: options.apiHost }, options.handoff.token);
30
+ }
31
+ catch (err) {
32
+ throw acceptanceFailure(err, options.apiHost);
33
+ }
34
+ if (node === null) {
35
+ throw new SetupFlowError(`The delivered runtime key is valid, but the network reports no active Node for it to represent, so it was not accepted. ${NOTHING_CHANGED} Choose or create an Agent Node in the console, then re-run setup.`);
36
+ }
37
+ return node;
38
+ }
39
+ function acceptanceFailure(err, apiHost) {
40
+ switch (classifyIdentityError(err)) {
41
+ case "credential-refused":
42
+ return new SetupFlowError(`The network rejected the runtime key delivered by the browser${httpStatusSuffix(err)}, so it was not accepted. That is a credential-class refusal — retrying will not change it. ${NOTHING_CHANGED} Re-run setup to authorize a new runtime key.`);
43
+ case "entity-missing":
44
+ return new SetupFlowError(`The delivered runtime key authenticates, but the Node it represents has no backing entity on the network — it is missing or deleted — so it was not accepted. ${NOTHING_CHANGED} Choose or create an Agent Node in the console, then re-run setup.`);
45
+ case "endpoint-absent":
46
+ return new SetupFlowError(`This MASONS Services deployment does not serve the identity endpoint (HTTP 404 for GET /v1/me/identity at ${apiHost}), so the delivered runtime key could not be verified and was not accepted. That is a property of this host — an older or self-hosted apps/api — not an expired link. ${NOTHING_CHANGED} Point setup at a Services deployment that serves the identity endpoint, or upgrade this one, then re-run setup.`);
47
+ case "unavailable":
48
+ return new SetupFlowError(`The network could not confirm which Node the delivered runtime key represents (${unavailableDetail(err)}), so it was not accepted. ${NOTHING_CHANGED} Re-run setup to try again.`);
49
+ default:
50
+ return err;
51
+ }
52
+ }
53
+ function httpStatusSuffix(err) {
54
+ return err instanceof PlatformApiError ? ` (HTTP ${err.status})` : "";
55
+ }
56
+ function unavailableDetail(err) {
57
+ if (err instanceof PlatformApiError)
58
+ return `HTTP ${err.status} ${err.code}`;
59
+ if (err instanceof PlatformNetworkError)
60
+ return `${err.code}: ${err.detail}`;
61
+ return "no answer";
62
+ }
package/dist/handoff.d.ts CHANGED
@@ -20,7 +20,6 @@ export interface BridgeHandoffSession {
20
20
  export interface BeginBridgeHandoffOptions {
21
21
  apiHost: string;
22
22
  idpBaseUrl: string;
23
- channelInput?: string;
24
23
  }
25
24
  export declare function beginBridgeHandoff(options: BeginBridgeHandoffOptions): Promise<BridgeHandoffSession>;
26
25
  export declare function completeBridgeHandoff(session: BridgeHandoffSession): Promise<BridgeHandoffResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAavD,eAAO,MAAM,oBAAoB,8BAA8B,CAAC;AAiBhE,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AAejD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AAQD,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAOhB,UAAU,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAsD/B;AAKD,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAwC9B"}
1
+ {"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAavD,eAAO,MAAM,oBAAoB,8BAA8B,CAAC;AAWhE,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AA0BjD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AAQD,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAOhB,UAAU,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAkD/B;AAKD,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CA0C9B"}
package/dist/handoff.js CHANGED
@@ -3,9 +3,9 @@ import { assertHandoffDeadlineActive, SetupFlowError, } from "./handoff-deadline
3
3
  import { apiFetch, PlatformNetworkError } from "./platform-client.js";
4
4
  export { SetupFlowError } from "./handoff-deadline.js";
5
5
  export const DEFAULT_IDP_BASE_URL = "https://preview.masons.ai";
6
- const HANDLE_REGEX = /^[a-z][a-z0-9_-]{2,14}$/;
7
6
  export const HANDOFF_TIMEOUT_MS = 10 * 60 * 1000;
8
7
  const HANDOFF_POLL_INTERVAL_MS = 2000;
8
+ const RUNTIME_KEY_PATTERN = /^masons_rt_v1_[A-Za-z0-9_-]+$/;
9
9
  export async function beginBridgeHandoff(options) {
10
10
  const { publicKey, privateKey } = generateKeyPairSync("rsa", {
11
11
  modulusLength: 2048,
@@ -39,11 +39,7 @@ export async function beginBridgeHandoff(options) {
39
39
  const message = err instanceof Error ? err.message : "unknown error";
40
40
  throw new SetupFlowError(`Could not reach the setup service at ${apiBase} (${message}). Retry in a moment.`);
41
41
  }
42
- const handle = parseHandleFromInput(options.channelInput);
43
- const handoffPath = handle
44
- ? `/console/agents/${encodeURIComponent(handle)}/runtime-keys/handoff`
45
- : "/console/handoff";
46
- const handoffUrl = `${options.idpBaseUrl}${handoffPath}?session=${encodeURIComponent(sessionId)}`;
42
+ const handoffUrl = `${options.idpBaseUrl}/console/handoff?session=${encodeURIComponent(sessionId)}`;
47
43
  return {
48
44
  sessionId,
49
45
  handoffUrl,
@@ -64,10 +60,10 @@ export async function completeBridgeHandoff(session) {
64
60
  }
65
61
  assertHandoffDeadlineActive(session.expiresAt);
66
62
  if (typeof payload.token !== "string" ||
67
- !payload.token.startsWith("masons_rt_v1_") ||
63
+ !RUNTIME_KEY_PATTERN.test(payload.token) ||
68
64
  typeof payload.agent?.handle !== "string" ||
69
65
  typeof payload.agent?.agentId !== "string") {
70
- throw new SetupFlowError("Handoff payload is missing required fields. Re-run setup; if it keeps happening, this is a server-side bug worth reporting.");
66
+ throw new SetupFlowError("Handoff payload did not match the expected shape. Re-run setup; if it keeps happening, this is a server-side bug worth reporting.");
71
67
  }
72
68
  return {
73
69
  token: payload.token,
@@ -154,17 +150,6 @@ function normalizeHttpBase(apiHost) {
154
150
  return trimmed;
155
151
  return `https://${trimmed}`;
156
152
  }
157
- function parseHandleFromInput(input) {
158
- if (typeof input !== "string")
159
- return undefined;
160
- const trimmed = input.trim().toLowerCase();
161
- if (!trimmed.startsWith("@"))
162
- return undefined;
163
- const handle = trimmed.slice(1);
164
- if (!HANDLE_REGEX.test(handle))
165
- return undefined;
166
- return handle;
167
- }
168
153
  function sleep(ms) {
169
154
  return new Promise((resolve) => {
170
155
  setTimeout(resolve, ms);
@@ -0,0 +1,6 @@
1
+ import { type ConnectionNodeRef } from "./platform-client.js";
2
+ export declare function formatKindLabel(kind: string | undefined): string;
3
+ export declare function formatCanonicalNode(label: string, node: ConnectionNodeRef): string;
4
+ export type IdentityErrorClass = "credential-refused" | "entity-missing" | "endpoint-absent" | "unavailable";
5
+ export declare function classifyIdentityError(err: unknown): IdentityErrorClass | null;
6
+ //# sourceMappingURL=identity-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-format.d.ts","sourceRoot":"","sources":["../src/identity-format.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,KAAK,iBAAiB,EAGvB,MAAM,sBAAsB,CAAC;AAe9B,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAKhE;AAYD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAKR;AAgBD,MAAM,MAAM,kBAAkB,GAC1B,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,CAAC;AAOlB,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAU7E"}
@@ -0,0 +1,30 @@
1
+ import { PlatformApiError, PlatformNetworkError, } from "./platform-client.js";
2
+ export function formatKindLabel(kind) {
3
+ if (!kind)
4
+ return "";
5
+ if (kind === "user")
6
+ return "[Human Node] ";
7
+ if (kind === "agent")
8
+ return "[Agent Node] ";
9
+ return `[Node:${kind}] `;
10
+ }
11
+ export function formatCanonicalNode(label, node) {
12
+ const handlePart = node.handle ? `@${node.handle} — ` : "";
13
+ const canonical = `${label}: ${formatKindLabel(node.kind)}${handlePart}${node.mstpAddress}`;
14
+ if (!node.displayName)
15
+ return canonical;
16
+ return `${canonical}\nDisplay name (presentation supplied by the identity endpoint): ${node.displayName}`;
17
+ }
18
+ export function classifyIdentityError(err) {
19
+ if (err instanceof PlatformApiError) {
20
+ if (err.status === 401 || err.status === 403)
21
+ return "credential-refused";
22
+ if (err.status === 404) {
23
+ return err.code === "not_found" ? "entity-missing" : "endpoint-absent";
24
+ }
25
+ return "unavailable";
26
+ }
27
+ if (err instanceof PlatformNetworkError)
28
+ return "unavailable";
29
+ return null;
30
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"platform-client.d.ts","sourceRoot":"","sources":["../src/platform-client.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AASxD,eAAO,MAAM,qBAAqB,iDACc,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,MAAM;gBADZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAC5B,OAAO,EAAE,MAAM;CAKlB;AAiBD,qBAAa,oBAAqB,SAAQ,KAAK;aAE3B,IAAI,EAAE,SAAS,GAAG,SAAS;aAE3B,MAAM,EAAE,MAAM;gBAFd,IAAI,EAAE,SAAS,GAAG,SAAS,EAE3B,MAAM,EAAE,MAAM;CAKjC;AAMD,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAYD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC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iB,CACrC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,CAAA;CAAE,GACvE,OAAO,CAAC,yBAAyB,CAAC,CAWpC;AAQD,wBAAsB,YAAY,CAChC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC,oBAAoB,CAAC,CAc/B;AAOD,wBAAsB,aAAa,CACjC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,CAAC,CAUhC;AAOD,wBAAsB,cAAc,CAClC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,sBAAsB,CAAC,CAUjC;AAQD,wBAAsB,aAAa,CACjC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CAWhC;AAQD,wBAAsB,eAAe,CACnC,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uBAAuB,CAAC,CAMlC;AA4BD,wBAAsB,WAAW,CAC/B,GAAG,EAAE,oBAAoB,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAyBnC"}
@@ -154,5 +154,17 @@ export async function getIdentity(cfg, runtimeKey) {
154
154
  if (!body || body.node === undefined) {
155
155
  throw new PlatformApiError(res.status, "malformed_response", "identity response carried no `node` field");
156
156
  }
157
+ if (body.node === null)
158
+ return null;
159
+ if (!isNodeRef(body.node)) {
160
+ throw new PlatformApiError(res.status, "malformed_response", "identity response `node` carried no mstpAddress");
161
+ }
157
162
  return body.node;
158
163
  }
164
+ function isNodeRef(value) {
165
+ return (typeof value === "object" &&
166
+ value !== null &&
167
+ "mstpAddress" in value &&
168
+ typeof value.mstpAddress === "string" &&
169
+ value.mstpAddress.length > 0);
170
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AA2EA,UAAU,WAAW;IACnB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,UAAU,WAAW;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AAE3E,UAAU,OAAO;IACf,YAAY,CACV,IAAI,EAAE,cAAc,GAAG,WAAW,EAWlC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAC7D,IAAI,CAAC;CACT;AAoDD,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C;AAoZD,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAm5BhD"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AA+EA,UAAU,WAAW;IACnB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,UAAU,WAAW;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AAE3E,UAAU,OAAO;IACf,YAAY,CACV,IAAI,EAAE,cAAc,GAAG,WAAW,EAWlC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAC7D,IAAI,CAAC;CACT;AAoDD,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C;AA8WD,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAm5BhD"}
package/dist/tools.js CHANGED
@@ -3,6 +3,7 @@ import { getOwnerPassportAddress } from "./channel.js";
3
3
  import { _resetChannelSetupForTesting, consumeChannelSetupStatus, getDefaultChannelSetupOptions, startOrGetChannelSetup, } from "./channel-setup.js";
4
4
  import { clearTargetHandle, extractNetworkConfig, getConnectorClient, getDmScope, getPendingTarget, hasApiKey, isProfileNeeded, markProfileComplete, removeIdentityLinks, requireApiKey, requireConversationManager, requirePlatformConfig, writeIdentityLinks, } from "./config.js";
5
5
  import { getOwnerHandle } from "./environment-context.js";
6
+ import { classifyIdentityError, formatCanonicalNode, formatKindLabel, } from "./identity-format.js";
6
7
  import { ownerNotesQueue } from "./owner-notes.js";
7
8
  import { acceptRequest, declineRequest, getIdentity, listConnections, listRequests, PlatformApiError, PlatformNetworkError, requestConnection, updateProfile, } from "./platform-client.js";
8
9
  import { isServicesRetainedReplyContext } from "./services-retained-reply-context.js";
@@ -46,43 +47,27 @@ function maybeAppendUpdateNotice(result) {
46
47
  function withUpdateNotice(fn) {
47
48
  return async (id, params) => maybeAppendUpdateNotice(await fn(id, params));
48
49
  }
49
- function formatKindLabel(kind) {
50
- if (!kind)
51
- return "";
52
- if (kind === "user")
53
- return "[Human Node] ";
54
- if (kind === "agent")
55
- return "[Agent Node] ";
56
- return `[Node:${kind}] `;
57
- }
58
50
  function formatConnectionResult(requestIds, status) {
59
51
  if (requestIds.length === 0) {
60
52
  return "Already connected or request already pending — no new request needed.";
61
53
  }
62
54
  return `Connection request sent. Status: ${status}. The other agent's owner will be notified.`;
63
55
  }
64
- function formatIdentityNode(node) {
65
- const handlePart = node.handle ? `@${node.handle} — ` : "";
66
- const canonical = `Identity: ${formatKindLabel(node.kind)}${handlePart}${node.mstpAddress}`;
67
- if (!node.displayName)
68
- return canonical;
69
- return `${canonical}\nDisplay name (presentation supplied by the identity endpoint): ${node.displayName}`;
70
- }
71
56
  const IDENTITY_NO_FALLBACK = "This is not an answer — do not assume any locally-cached handle or name is this Runtime's identity.";
72
57
  function formatIdentityError(err) {
73
58
  if (err instanceof PlatformApiError) {
74
- if (err.status === 404) {
75
- return err.code === "not_found"
76
- ? "Identity: the Node's backing entity is missing or deleted."
77
- : `Identity: unavailable — the identity endpoint is not available at this host (HTTP 404). ${IDENTITY_NO_FALLBACK}`;
78
- }
79
- if (err.status === 401) {
80
- return "Identity: the runtime key is not valid — the network rejected it. The owner can re-authenticate via masons_setup.";
81
- }
82
- if (err.status === 403) {
83
- return "Identity: refused (HTTP 403) — this runtime key is not permitted to read this Runtime's identity. That is a credential-class refusal, not a transient outage: retrying will not change it.";
59
+ switch (classifyIdentityError(err)) {
60
+ case "entity-missing":
61
+ return "Identity: the Node's backing entity is missing or deleted.";
62
+ case "endpoint-absent":
63
+ return `Identity: unavailable — the identity endpoint is not available at this host (HTTP 404). ${IDENTITY_NO_FALLBACK}`;
64
+ case "credential-refused":
65
+ return err.status === 401
66
+ ? "Identity: the runtime key is not valid — the network rejected it. The owner can re-authenticate via masons_setup."
67
+ : "Identity: refused (HTTP 403) — this runtime key is not permitted to read this Runtime's identity. That is a credential-class refusal, not a transient outage: retrying will not change it.";
68
+ default:
69
+ return `Identity: unavailable right now (HTTP ${err.status}: ${err.code}). ${IDENTITY_NO_FALLBACK}`;
84
70
  }
85
- return `Identity: unavailable right now (HTTP ${err.status}: ${err.code}). ${IDENTITY_NO_FALLBACK}`;
86
71
  }
87
72
  if (err instanceof PlatformNetworkError) {
88
73
  return `Identity: unavailable right now. ${networkErrorText(err)} ${IDENTITY_NO_FALLBACK}`;
@@ -125,7 +110,7 @@ async function resolveIdentitySection() {
125
110
  if (node === null) {
126
111
  return "Identity: this Runtime's principal holds no active Node on the network.";
127
112
  }
128
- return formatIdentityNode(node);
113
+ return formatCanonicalNode("Identity", node);
129
114
  }
130
115
  catch (err) {
131
116
  return formatIdentityError(err);
@@ -231,11 +216,9 @@ function formatChannelSetupResult(result) {
231
216
  }
232
217
  if (result.status === "completed") {
233
218
  return [
234
- result.agentHandle
235
- ? `Agent Network setup completed for @${result.agentHandle}.`
236
- : "Agent Network setup completed.",
219
+ result.message ?? "Agent Network setup completed.",
237
220
  "",
238
- "Credentials are saved. Restart the OpenClaw Gateway now to activate realtime messaging; HTTP tools may work before the Gateway WebSocket is connected.",
221
+ "HTTP tools may work before the Gateway WebSocket is connected.",
239
222
  'If the gateway tool is available, call it with action "restart" and reason "Activate Agent Network after setup". If not, ask the user to run `openclaw gateway restart`.',
240
223
  ].join("\n");
241
224
  }
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const PLUGIN_VERSION = "0.6.21";
1
+ export declare const PLUGIN_VERSION = "0.6.22";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const PLUGIN_VERSION = "0.6.21";
1
+ export const PLUGIN_VERSION = "0.6.22";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@masons/agent-network",
3
- "version": "0.6.21",
3
+ "version": "0.6.22",
4
4
  "description": "MASONS Agent Network — OpenClaw channel plugin for connecting agent runtimes to the Agent Network over MSTP.",
5
5
  "license": "MIT",
6
6
  "author": "MASONS.ai <hello@masons.ai> (https://masons.ai)",