@masons/agent-network 0.4.26 → 0.5.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.
@@ -1,15 +1,18 @@
1
1
  /**
2
- * MASONS Platform API client.
2
+ * MASONS runtime API client.
3
3
  *
4
- * Pure HTTP functions wrapping the setup and connection API endpoints.
4
+ * Pure HTTP functions wrapping `/runtime/v1/*` endpoints on the connector.
5
5
  * Zero platform dependencies — only global fetch.
6
6
  *
7
- * Used by:
8
- * - cli-setup.ts (CLI path: configureInteractive)
9
- * - tools.ts (LLM path: tool execute functions)
7
+ * Used by `tools.ts` (LLM path: tool execute functions).
8
+ *
9
+ * The pre-0.5.0 setup-flow functions (`initSetup`, `pollSetup`, `listAgents`,
10
+ * `onboard`, `reconnect`) were deleted in this version: onboarding moves to
11
+ * the OAuth Device Authorization Grant flow served by Better Auth at the IdP
12
+ * (#1253), not via bespoke MASONS endpoints on the runtime API.
10
13
  */
11
14
  /** Default API host. */
12
- export declare const DEFAULT_API_HOST = "preview-platform.masons.ai";
15
+ export declare const DEFAULT_API_HOST = "preview-connectorapi.masons.ai";
13
16
  export interface PlatformClientConfig {
14
17
  apiHost: string;
15
18
  }
@@ -18,46 +21,6 @@ export declare class PlatformApiError extends Error {
18
21
  readonly code: string;
19
22
  constructor(status: number, code: string, message: string);
20
23
  }
21
- /** HTTP 428 — user hasn't authorized the setup code yet. Keep polling. */
22
- export declare class SetupPendingError extends PlatformApiError {
23
- constructor(message?: string);
24
- }
25
- /** HTTP 410 — setup token expired or not found. Must start over. */
26
- export declare class SetupExpiredError extends PlatformApiError {
27
- constructor(message?: string);
28
- }
29
- export interface InitSetupResponse {
30
- setup_code: string;
31
- setup_token: string;
32
- verification_uri: string;
33
- expires_in: number;
34
- interval: number;
35
- }
36
- export interface PollSetupResponse {
37
- status: "authorized";
38
- setup_token: string;
39
- expires_in: number;
40
- agent_id: string | null;
41
- }
42
- export interface AgentInfo {
43
- id: string;
44
- handle: string;
45
- address: string;
46
- deliveryMode: string;
47
- createdAt: string;
48
- }
49
- export interface ListAgentsResponse {
50
- agents: AgentInfo[];
51
- }
52
- export interface OnboardResponse {
53
- agentId: string;
54
- handle: string;
55
- address: string;
56
- connectorUrl: string;
57
- token: string;
58
- }
59
- /** Same shape as OnboardResponse. */
60
- export type ReconnectResponse = OnboardResponse;
61
24
  export interface RequestConnectionResponse {
62
25
  requestIds: string[];
63
26
  status: string;
@@ -124,45 +87,77 @@ export interface ConnectionStatusResponse {
124
87
  status: "connected" | "pending" | "not_connected";
125
88
  canCreateSession: boolean;
126
89
  }
90
+ /** Successful onboard — returned by all three branches. */
91
+ export interface OnboardSuccess {
92
+ apiKey: string;
93
+ connectorUrl: string;
94
+ agentId: string;
95
+ handle: string;
96
+ }
97
+ export interface OnboardAgentSummary {
98
+ id: string;
99
+ handle: string;
100
+ name: string;
101
+ }
127
102
  /**
128
- * `POST /setup/init`Start Device Code Flow.
129
- *
130
- * Public endpoint (no auth). Returns a setup code for the user to enter
131
- * in their browser, plus a setup token for subsequent API calls.
103
+ * 422 agent_requireduser owns multiple agents and didn't pick one.
104
+ * Plugin should prompter.select() from `agents` and re-call with `{agentId}`.
132
105
  */
133
- export declare function initSetup(cfg: PlatformClientConfig): Promise<InitSetupResponse>;
106
+ export interface OnboardAgentRequiredError {
107
+ status: 422;
108
+ code: "agent_required";
109
+ agents: OnboardAgentSummary[];
110
+ }
134
111
  /**
135
- * `POST /setup/poll`Poll for user authorization.
136
- *
137
- * Public endpoint. The setup token is sent in the request body (not header).
138
- *
139
- * @throws {SetupPendingError} 428 — user hasn't authorized yet
140
- * @throws {SetupExpiredError} 410 — token expired, start over
112
+ * 412 no_agentsuser owns zero agents. Plugin should prompt for handle
113
+ * and re-call with `{create: {handle}}`.
141
114
  */
142
- export declare function pollSetup(cfg: PlatformClientConfig, setupToken: string): Promise<PollSetupResponse>;
115
+ export interface OnboardNoAgentsError {
116
+ status: 412;
117
+ code: "no_agents";
118
+ message: string;
119
+ }
143
120
  /**
144
- * `GET /me/agents`List authenticated user's agents.
145
- *
146
- * Requires Setup Token in Authorization header.
121
+ * 409 handle_takenhandle conflict in create branch. Plugin should
122
+ * re-prompt for a different handle.
147
123
  */
148
- export declare function listAgents(cfg: PlatformClientConfig, setupToken: string): Promise<ListAgentsResponse>;
124
+ export interface OnboardHandleTakenError {
125
+ status: 409;
126
+ code: "handle_taken";
127
+ }
149
128
  /**
150
- * `POST /onboard`Create a new agent identity.
151
- *
152
- * Requires Setup Token in Authorization header.
153
- * Returns credentials for Gateway connection and API access.
129
+ * 422 invalid_handlehandle failed server-side validation. Plugin should
130
+ * surface the message and re-prompt.
154
131
  */
155
- export declare function onboard(cfg: PlatformClientConfig, setupToken: string, params: {
156
- handle: string;
157
- name?: string;
158
- }): Promise<OnboardResponse>;
132
+ export interface OnboardInvalidHandleError {
133
+ status: 422;
134
+ code: "invalid_handle";
135
+ message: string;
136
+ }
137
+ /** Body shape for the onboard endpoint. */
138
+ export type OnboardBody = Record<string, never> | {
139
+ agentId: string;
140
+ } | {
141
+ create: {
142
+ handle: string;
143
+ name?: string;
144
+ };
145
+ };
159
146
  /**
160
- * `POST /agents/{id}/reconnect` Rotate API key for an existing agent.
147
+ * Result discriminator. `kind: "ok"` carries the credentials; `kind: "error"`
148
+ * surfaces structured errors the plugin must handle in its CLI prompter loop
149
+ * (no-agents → prompt handle; agent-required → prompt picker; handle-taken
150
+ * → re-prompt; invalid-handle → re-prompt).
161
151
  *
162
- * Requires Setup Token in Authorization header.
163
- * Returns fresh credentials (same shape as onboard).
152
+ * Other failure shapes (401, 403, 404, 500) are thrown as `PlatformApiError`.
164
153
  */
165
- export declare function reconnect(cfg: PlatformClientConfig, setupToken: string, agentId: string): Promise<ReconnectResponse>;
154
+ export type OnboardResult = {
155
+ kind: "ok";
156
+ data: OnboardSuccess;
157
+ } | {
158
+ kind: "error";
159
+ data: OnboardAgentRequiredError | OnboardNoAgentsError | OnboardHandleTakenError | OnboardInvalidHandleError;
160
+ };
166
161
  /**
167
162
  * `POST /connections/requests` — Send a connection request.
168
163
  *
@@ -211,6 +206,21 @@ export declare function updateProfile(cfg: PlatformClientConfig, apiKey: string,
211
206
  * Returns name + MSTP address for each connected agent.
212
207
  */
213
208
  export declare function listConnections(cfg: PlatformClientConfig, apiKey: string): Promise<ListConnectionsResponse>;
209
+ /**
210
+ * `POST /onboard` — bind a device-class client to an agent.
211
+ *
212
+ * Three branches selected by body shape (#1264):
213
+ * - `{}` → list / auto-pick
214
+ * - `{agentId}` → select existing (rotates api_key)
215
+ * - `{create: {handle, name?}}` → mint new agent
216
+ *
217
+ * Auth: Bearer access_token from Better Auth's device-authorization plugin.
218
+ *
219
+ * Returns `{kind: "ok", data}` on 200. Returns `{kind: "error", data}` for
220
+ * the four structured errors the CLI prompter loop must handle. All other
221
+ * non-2xx responses throw `PlatformApiError`.
222
+ */
223
+ export declare function onboard(cfg: PlatformClientConfig, sessionToken: string, body: OnboardBody): Promise<OnboardResult>;
214
224
  /**
215
225
  * `GET /connections/status?target={handle}` — Check connection status.
216
226
  *
@@ -1 +1 @@
1
- {"version":3,"file":"platform-client.d.ts","sourceRoot":"","sources":["../src/platform-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,wBAAwB;AACxB,eAAO,MAAM,gBAAgB,+BAA+B,CAAC;AAE7D,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;AAED,0EAA0E;AAC1E,qBAAa,iBAAkB,SAAQ,gBAAgB;gBACzC,OAAO,SAA0B;CAI9C;AAED,oEAAoE;AACpE,qBAAa,iBAAkB,SAAQ,gBAAgB;gBACzC,OAAO,SAAwB;CAI5C;AAMD,MAAM,WAAW,i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GAKG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,oBAAoB,EACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,qBAAqB,CAAC,CAWhC;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,oBAAoB,EACzB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,uBAAuB,CAAC,CAMlC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAC3B,GAAG,EAAE,oBAAoB,EACzB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,aAAa,CAAC,CAyDxB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,oBAAoB,EACzB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAiB1C"}
@@ -1,18 +1,21 @@
1
1
  /**
2
- * MASONS Platform API client.
2
+ * MASONS runtime API client.
3
3
  *
4
- * Pure HTTP functions wrapping the setup and connection API endpoints.
4
+ * Pure HTTP functions wrapping `/runtime/v1/*` endpoints on the connector.
5
5
  * Zero platform dependencies — only global fetch.
6
6
  *
7
- * Used by:
8
- * - cli-setup.ts (CLI path: configureInteractive)
9
- * - tools.ts (LLM path: tool execute functions)
7
+ * Used by `tools.ts` (LLM path: tool execute functions).
8
+ *
9
+ * The pre-0.5.0 setup-flow functions (`initSetup`, `pollSetup`, `listAgents`,
10
+ * `onboard`, `reconnect`) were deleted in this version: onboarding moves to
11
+ * the OAuth Device Authorization Grant flow served by Better Auth at the IdP
12
+ * (#1253), not via bespoke MASONS endpoints on the runtime API.
10
13
  */
11
14
  // ---------------------------------------------------------------------------
12
15
  // Config
13
16
  // ---------------------------------------------------------------------------
14
17
  /** Default API host. */
15
- export const DEFAULT_API_HOST = "preview-platform.masons.ai";
18
+ export const DEFAULT_API_HOST = "preview-connectorapi.masons.ai";
16
19
  // ---------------------------------------------------------------------------
17
20
  // Error classes
18
21
  // ---------------------------------------------------------------------------
@@ -26,122 +29,24 @@ export class PlatformApiError extends Error {
26
29
  this.name = "PlatformApiError";
27
30
  }
28
31
  }
29
- /** HTTP 428 — user hasn't authorized the setup code yet. Keep polling. */
30
- export class SetupPendingError extends PlatformApiError {
31
- constructor(message = "Authorization pending") {
32
- super(428, "authorization_pending", message);
33
- this.name = "SetupPendingError";
34
- }
35
- }
36
- /** HTTP 410 — setup token expired or not found. Must start over. */
37
- export class SetupExpiredError extends PlatformApiError {
38
- constructor(message = "Setup token expired") {
39
- super(410, "expired_token", message);
40
- this.name = "SetupExpiredError";
41
- }
42
- }
43
32
  // ---------------------------------------------------------------------------
44
33
  // Internal helpers
45
34
  // ---------------------------------------------------------------------------
46
35
  function baseUrl(cfg) {
47
- return `https://${cfg.apiHost}/openclaw/v1`;
36
+ // `/runtime/v1/*` is the canonical prefix (renamed from legacy `/openclaw/v1/*`
37
+ // in connector PR #1248 — shared by OpenClaw plugin + Claude Code + any future
38
+ // device-class runtime). Atomic server-side change, no dual-serve.
39
+ return `https://${cfg.apiHost}/runtime/v1`;
48
40
  }
49
41
  async function handleError(res) {
50
42
  const body = (await res.json().catch(() => ({})));
51
43
  const code = typeof body.error === "string" ? body.error : "unknown";
52
44
  const message = typeof body.message === "string" ? body.message : res.statusText;
53
- if (res.status === 428)
54
- throw new SetupPendingError(message);
55
- if (res.status === 410)
56
- throw new SetupExpiredError(message);
57
45
  throw new PlatformApiError(res.status, code, message);
58
46
  }
59
47
  // ---------------------------------------------------------------------------
60
48
  // API functions
61
49
  // ---------------------------------------------------------------------------
62
- /**
63
- * `POST /setup/init` — Start Device Code Flow.
64
- *
65
- * Public endpoint (no auth). Returns a setup code for the user to enter
66
- * in their browser, plus a setup token for subsequent API calls.
67
- */
68
- export async function initSetup(cfg) {
69
- const res = await fetch(`${baseUrl(cfg)}/setup/init`, {
70
- method: "POST",
71
- headers: { "Content-Type": "application/json" },
72
- });
73
- if (!res.ok)
74
- return handleError(res);
75
- return (await res.json());
76
- }
77
- /**
78
- * `POST /setup/poll` — Poll for user authorization.
79
- *
80
- * Public endpoint. The setup token is sent in the request body (not header).
81
- *
82
- * @throws {SetupPendingError} 428 — user hasn't authorized yet
83
- * @throws {SetupExpiredError} 410 — token expired, start over
84
- */
85
- export async function pollSetup(cfg, setupToken) {
86
- const res = await fetch(`${baseUrl(cfg)}/setup/poll`, {
87
- method: "POST",
88
- headers: { "Content-Type": "application/json" },
89
- body: JSON.stringify({ setup_token: setupToken }),
90
- });
91
- if (!res.ok)
92
- return handleError(res);
93
- return (await res.json());
94
- }
95
- /**
96
- * `GET /me/agents` — List authenticated user's agents.
97
- *
98
- * Requires Setup Token in Authorization header.
99
- */
100
- export async function listAgents(cfg, setupToken) {
101
- const res = await fetch(`${baseUrl(cfg)}/me/agents`, {
102
- headers: { Authorization: `Bearer ${setupToken}` },
103
- });
104
- if (!res.ok)
105
- return handleError(res);
106
- return (await res.json());
107
- }
108
- /**
109
- * `POST /onboard` — Create a new agent identity.
110
- *
111
- * Requires Setup Token in Authorization header.
112
- * Returns credentials for Gateway connection and API access.
113
- */
114
- export async function onboard(cfg, setupToken, params) {
115
- const res = await fetch(`${baseUrl(cfg)}/onboard`, {
116
- method: "POST",
117
- headers: {
118
- "Content-Type": "application/json",
119
- Authorization: `Bearer ${setupToken}`,
120
- },
121
- body: JSON.stringify(params),
122
- });
123
- if (!res.ok)
124
- return handleError(res);
125
- return (await res.json());
126
- }
127
- /**
128
- * `POST /agents/{id}/reconnect` — Rotate API key for an existing agent.
129
- *
130
- * Requires Setup Token in Authorization header.
131
- * Returns fresh credentials (same shape as onboard).
132
- */
133
- export async function reconnect(cfg, setupToken, agentId) {
134
- const res = await fetch(`${baseUrl(cfg)}/agents/${encodeURIComponent(agentId)}/reconnect`, {
135
- method: "POST",
136
- headers: {
137
- "Content-Type": "application/json",
138
- Authorization: `Bearer ${setupToken}`,
139
- },
140
- });
141
- if (!res.ok)
142
- return handleError(res);
143
- return (await res.json());
144
- }
145
50
  /**
146
51
  * `POST /connections/requests` — Send a connection request.
147
52
  *
@@ -247,6 +152,70 @@ export async function listConnections(cfg, apiKey) {
247
152
  return handleError(res);
248
153
  return (await res.json());
249
154
  }
155
+ /**
156
+ * `POST /onboard` — bind a device-class client to an agent.
157
+ *
158
+ * Three branches selected by body shape (#1264):
159
+ * - `{}` → list / auto-pick
160
+ * - `{agentId}` → select existing (rotates api_key)
161
+ * - `{create: {handle, name?}}` → mint new agent
162
+ *
163
+ * Auth: Bearer access_token from Better Auth's device-authorization plugin.
164
+ *
165
+ * Returns `{kind: "ok", data}` on 200. Returns `{kind: "error", data}` for
166
+ * the four structured errors the CLI prompter loop must handle. All other
167
+ * non-2xx responses throw `PlatformApiError`.
168
+ */
169
+ export async function onboard(cfg, sessionToken, body) {
170
+ const res = await fetch(`${baseUrl(cfg)}/onboard`, {
171
+ method: "POST",
172
+ headers: {
173
+ "Content-Type": "application/json",
174
+ Authorization: `Bearer ${sessionToken}`,
175
+ },
176
+ body: JSON.stringify(body),
177
+ });
178
+ if (res.ok) {
179
+ const data = (await res.json());
180
+ return { kind: "ok", data };
181
+ }
182
+ // Branch on the structured-error codes the prompter loop knows how to
183
+ // recover from. Anything else → throw PlatformApiError.
184
+ const raw = (await res.json().catch(() => ({})));
185
+ const code = typeof raw.error === "string" ? raw.error : "unknown";
186
+ const message = typeof raw.message === "string" ? raw.message : res.statusText;
187
+ if (res.status === 412 && code === "no_agents") {
188
+ return {
189
+ kind: "error",
190
+ data: { status: 412, code: "no_agents", message },
191
+ };
192
+ }
193
+ if (res.status === 422 && code === "agent_required") {
194
+ const agents = Array.isArray(raw.agents)
195
+ ? raw.agents
196
+ : [];
197
+ return {
198
+ kind: "error",
199
+ data: { status: 422, code: "agent_required", agents },
200
+ };
201
+ }
202
+ if (res.status === 422 && code === "invalid_handle") {
203
+ return {
204
+ kind: "error",
205
+ data: { status: 422, code: "invalid_handle", message },
206
+ };
207
+ }
208
+ if (res.status === 409 && code === "handle_taken") {
209
+ return {
210
+ kind: "error",
211
+ data: { status: 409, code: "handle_taken" },
212
+ };
213
+ }
214
+ // 401 unauthorized, 403 forbidden, 404 agent_not_found, 500 internal —
215
+ // these are programming errors at this stage, propagate via the standard
216
+ // throw path so the CLI prompter loop sees them as fatal.
217
+ throw new PlatformApiError(res.status, code, message);
218
+ }
250
219
  /**
251
220
  * `GET /connections/status?target={handle}` — Check connection status.
252
221
  *
package/dist/plugin.d.ts CHANGED
@@ -22,6 +22,11 @@ declare const plugin: {
22
22
  description: string;
23
23
  default: string;
24
24
  };
25
+ idpBaseUrl: {
26
+ type: string;
27
+ description: string;
28
+ default: string;
29
+ };
25
30
  updateCheck: {
26
31
  type: string;
27
32
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAiJA,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACnE;AAED,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;kBAaI,iBAAiB;CAkWhC,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAiJA,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACnE;AAED,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;kBAaI,iBAAiB;CAoXhC,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/plugin.js CHANGED
@@ -124,11 +124,19 @@ const plugin = {
124
124
  // Idempotent — Gateway may hot-reload, calling register() again.
125
125
  initPluginRuntime(api.runtime);
126
126
  // Register tools FIRST — they must be available even when the channel
127
- // has no credentials yet (setup flow needs these tools to GET credentials).
127
+ // has no credentials yet.
128
128
  registerTools(api);
129
129
  // Channel registration may fail if no credentials are configured yet.
130
- // This is expected on first run — the user will use the setup tools above
131
- // to obtain credentials, then restart to activate the channel.
130
+ // This is expected on first run — the user authorizes via the OAuth
131
+ // device flow run by `configureInteractive` (CLI command:
132
+ // `openclaw channels login --channel agent-network`). After credentials
133
+ // are persisted to openclaw.json, OpenClaw hot-reloads and re-runs
134
+ // register() — the channel then activates.
135
+ //
136
+ // `setup: { configureInteractive }` exposes the CLI hook to OpenClaw.
137
+ // Restored in #1264 after the legacy setup flow was deleted in
138
+ // fd5568e8 (#1253). The new implementation is RFC 8628 device flow
139
+ // against Better Auth at the IdP — no MASONS-specific bespoke endpoints.
132
140
  try {
133
141
  api.registerChannel({
134
142
  plugin: {
@@ -246,9 +254,19 @@ const plugin = {
246
254
  // --- Build dynamic context based on setup state ---
247
255
  let dynamicContext;
248
256
  if (!state.hasCredentials) {
249
- // Just installed, no credentials yet — guide to setup
257
+ // Just installed, no credentials yet — guide to CLI setup.
258
+ // The previous `masons_setup_init` LLM tool was removed in 0.5.0
259
+ // (#1253) and replaced by the OAuth device flow in cli-setup.ts.
260
+ // The LLM cannot run the device flow itself (it requires terminal
261
+ // I/O via OpenClaw's prompter), so its job here is to surface the
262
+ // command and wait for the user.
250
263
  dynamicContext =
251
- "[Context: Agent Network] You recently installed the agent network plugin. Your user wants to connect to the agent network. Call the masons_setup_init tool to begin the setup process.";
264
+ "[Context: Agent Network] You recently installed the agent network plugin " +
265
+ "but it is not yet authorized. Tell your user to run this in their terminal: " +
266
+ "`openclaw channels login --channel agent-network`. " +
267
+ "The command opens a browser to authorize the device, then prompts in the " +
268
+ "terminal to pick or create an agent. After it completes, OpenClaw will " +
269
+ "reload and the agent network tools will become available.";
252
270
  if (state.pendingTarget) {
253
271
  dynamicContext += ` After setup, send a connection request to ${state.pendingTarget} — they invited your user to join.`;
254
272
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAqDH,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,OAAO;IACf,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;AA0CD,uDAAuD;AACvD,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C;AAsFD;;;;;;;GAOG;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