@byokit/openclaw 0.12.0 → 0.14.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/signin.js CHANGED
@@ -57,12 +57,14 @@ export function signIn(ctx, member, o, on) {
57
57
  };
58
58
  let server;
59
59
  let sessionId = '';
60
+ let native;
61
+ let nativeId;
60
62
  let starting;
61
63
  let releasing;
62
64
  let settleStart;
63
65
  const startingSettled = new Promise((resolve) => { settleStart = resolve; });
64
66
  let over = false;
65
- let activating = false;
67
+ let committed = false; // the commit point of the native and key drives: set just before setup.activate
66
68
  let recovering = false;
67
69
  let offDisconnect;
68
70
  let agentId;
@@ -127,6 +129,7 @@ export function signIn(ctx, member, o, on) {
127
129
  stopApproval();
128
130
  offDisconnect?.();
129
131
  o.signal?.removeEventListener('abort', cancel);
132
+ ctx.stopSignal?.removeEventListener('abort', cancel);
130
133
  owner.abort();
131
134
  returned = undefined;
132
135
  pasteIn = undefined;
@@ -142,8 +145,16 @@ export function signIn(ctx, member, o, on) {
142
145
  // session only as `openclaw.setup.auth.start` settles, so a cancel sent sooner is answered `wizard not found`
143
146
  // and leaves the person locked out of signing in. Waiting for that settlement is what frees the admission.
144
147
  await startingSettled;
145
- if (sessionId)
146
- await Promise.resolve().then(() => ctx.request('wizard.cancel', { sessionId }, { timeoutMs: CANCEL_MS })).catch(() => { });
148
+ if (nativeId)
149
+ await native?.cancel(nativeId).catch(() => { });
150
+ if (!sessionId)
151
+ return;
152
+ const answer = await Promise.resolve().then(() => ctx.request('wizard.cancel', { sessionId }, { timeoutMs: CANCEL_MS })).catch(() => undefined);
153
+ // The pin answers `cancelled` at once but frees the admission only once the cancelled runner and its setup-target
154
+ // lock settle, and answers wizard.status on that session only after that: done waits for it (CANCEL_MS at most).
155
+ // Not covered: a `running` answer (its commit under way) and a session the engine purged at the cancel.
156
+ if (answer?.status === 'cancelled')
157
+ await Promise.resolve().then(() => ctx.request('wizard.status', { sessionId }, { timeoutMs: CANCEL_MS })).catch(() => { });
147
158
  })();
148
159
  return releasing;
149
160
  };
@@ -162,12 +173,17 @@ export function signIn(ctx, member, o, on) {
162
173
  if (signal.aborted)
163
174
  return;
164
175
  owner.abort();
165
- void (async () => { await release(); if (!activating)
176
+ void (async () => { await release(); if (!committed)
166
177
  await finish(cancelled()); })();
167
178
  };
168
179
  o.signal?.addEventListener('abort', cancel, { once: true });
169
180
  if (o.signal?.aborted)
170
181
  cancel();
182
+ // An engine shutdown before the commit point is this drive's decline too: without it a key paste would sit out
183
+ // its 15-minute paste wait after the engine is gone.
184
+ ctx.stopSignal?.addEventListener('abort', cancel, { once: true });
185
+ if (ctx.stopSignal?.aborted)
186
+ cancel();
171
187
  /** Hold 127.0.0.1:<callbackPort> for the sign-in's life; a taken port is why the sign-in cannot start. */
172
188
  const holdCallback = () => {
173
189
  let took = false;
@@ -219,9 +235,53 @@ export function signIn(ctx, member, o, on) {
219
235
  settleStart();
220
236
  let apiKey;
221
237
  if (o.authChoice === 'anthropic-cli') {
222
- const detected = await ctx.request('openclaw.setup.detect', { agentId }, { timeoutMs: STATUS_MS });
223
- if (!detected.candidates?.some((candidate) => candidate.kind === 'claude-cli' && candidate.credentials === true))
224
- return { state: 'failed', via, why: 'failed', error: 'Sign in with Claude Code on this machine in the kit’s isolated HOME, then try again. The login stays in Claude Code.' };
238
+ const detected = async () => {
239
+ const value = await ctx.request('openclaw.setup.detect', { agentId }, { timeoutMs: STATUS_MS, signal });
240
+ return value.candidates?.some(candidate => candidate.kind === 'claude-cli' && candidate.credentials === true);
241
+ };
242
+ native = ctx.nativeClaudeLogin?.();
243
+ if (!await detected()) {
244
+ if (!native)
245
+ return { state: 'failed', via, why: 'failed', error: 'Claude Code sign-in is not available on this engine.' };
246
+ let started = await native.start('claude', { signal });
247
+ let ready = false;
248
+ if (!started.ok && started.error === 'already') {
249
+ ready = Boolean(await detected());
250
+ if (!ready && ctx.resetNativeClaudeLogin) {
251
+ if (signal.aborted || native.signal.aborted)
252
+ return cancelled();
253
+ await ctx.resetNativeClaudeLogin();
254
+ started = await native.start('claude', { signal });
255
+ }
256
+ }
257
+ if (!ready) {
258
+ if (!started.ok)
259
+ return { state: 'failed', via, why: started.error === 'busy' ? 'busy' : started.error === 'cancelled' ? 'declined' : 'failed', error: started.words };
260
+ nativeId = started.signIn.id;
261
+ if (signal.aborted) {
262
+ await native.cancel(nativeId);
263
+ return cancelled();
264
+ }
265
+ let pasteFailed = false;
266
+ pasteIn = text => { void native.paste(nativeId, text).catch((error) => { if (error.remoteCliProblem === 'unknown')
267
+ return; pasteFailed = true; void native.cancel(nativeId).catch(() => { }); }); };
268
+ say({ url: started.signIn.verificationUri, prompt: 'Paste the code from the sign-in page' });
269
+ if (returned !== undefined) {
270
+ pasteIn(returned);
271
+ returned = undefined;
272
+ }
273
+ const result = await native.wait(nativeId);
274
+ pasteIn = undefined;
275
+ if (signal.aborted)
276
+ return cancelled();
277
+ if (pasteFailed)
278
+ return { state: 'failed', via, why: 'failed', error: 'The sign-in code could not be sent. Try again.' };
279
+ if (!result.ok)
280
+ return { state: 'failed', via, why: result.error === 'expired' ? 'expired' : result.error === 'cancelled' ? 'declined' : 'failed', error: result.words };
281
+ if (!await detected())
282
+ return { state: 'failed', via, why: 'failed', error: 'Claude Code is still signed out on this engine. Try again.' };
283
+ }
284
+ }
225
285
  }
226
286
  else {
227
287
  say({ prompt: keyRoute?.billing === 'api' ? 'API key (billed per use)' : 'Plan key' });
@@ -239,21 +299,19 @@ export function signIn(ctx, member, o, on) {
239
299
  return { state: 'failed', via, why: signal.aborted ? 'declined' : 'expired' };
240
300
  secret = apiKey.trim() || undefined;
241
301
  }
242
- if (signal.aborted)
243
- return { state: 'failed', via, why: 'declined' };
244
- // Done waits for the gateway restart an `auth` change causes (activation.ts); a run started before it runs on the
245
- // old config. A restart that runs late or is cancelled ends failed, and the account is cleaned up by the caller.
246
- activating = true;
247
- const result = await activate(ctx, {
248
- agentId, kind: apiKey === undefined ? 'claude-cli' : 'api-key',
249
- ...(apiKey === undefined ? {} : { authChoice: o.authChoice, apiKey }),
250
- }, { timeoutMs: PULL_MS, signal }).finally(() => { activating = false; });
302
+ // The commit point: a phone cancel or host shutdown that landed before it activates nothing. Done waits for the gateway restart an `auth` change causes (activation.ts).
303
+ // For Claude only host shutdown cuts that wait; a late restart has persisted the route and says saved. A key's cancel still declines its wait; a late key keeps the shared words.
304
+ if (signal.aborted || native?.signal.aborted)
305
+ return cancelled();
306
+ committed = true;
307
+ const result = await activate(ctx, { agentId, kind: apiKey === undefined ? 'claude-cli' : 'api-key', ...(apiKey === undefined ? {} : { authChoice: o.authChoice, apiKey }), }, { timeoutMs: PULL_MS, signal: apiKey === undefined ? native?.signal : signal });
308
+ if (apiKey !== undefined && signal.aborted)
309
+ return cancelled();
251
310
  if (result.late)
252
- return signal.aborted ? cancelled() : { state: 'failed', via, why: 'failed', error: LATE_RESTART };
311
+ return { state: 'failed', via, why: 'failed', error: apiKey === undefined ? words('signin.savedNotRestarted') : LATE_RESTART };
253
312
  if (!result.ok)
254
- return { state: 'failed', via, why: 'failed',
255
- error: apiKey === undefined ? clean(result.error ?? 'Claude Code activation failed') : keyFailed(result.status) };
256
- return signal.aborted ? cancelled() : { state: 'done', via };
313
+ return { state: 'failed', via, why: 'failed', error: apiKey === undefined ? clean(result.error ?? 'Claude Code activation failed') : keyFailed(result.status) };
314
+ return { state: 'done', via };
257
315
  }
258
316
  // The client chooses the wizard id; cancellation waits for the engine to register it.
259
317
  sessionId = `byokit-${randomUUID()}`;
@@ -441,11 +499,11 @@ export function signIn(ctx, member, o, on) {
441
499
  try {
442
500
  const driven = await Promise.race([drive(), disconnected]);
443
501
  view = driven ?? await recover();
444
- if (signal.aborted)
502
+ if (!committed && (signal.aborted || native?.signal.aborted))
445
503
  view = codeExpired ? expired() : cancelled();
446
504
  }
447
505
  catch (error) {
448
- if (signal.aborted)
506
+ if (!committed && (signal.aborted || native?.signal.aborted))
449
507
  view = codeExpired ? expired() : cancelled();
450
508
  else if (sawDeviceCode && /expired_token|code.*expired|device.*(?:expired|timed out)/i.test(cut(error)))
451
509
  view = expired();
@@ -38,6 +38,13 @@ export type FakeGateway = {
38
38
  provider: string;
39
39
  type: string;
40
40
  } & Record<string, unknown>): void;
41
+ /** A late engine refresh racing a removal (O14 S8): writes one profile of `provider` onto `agentId` whole, as the
42
+ * pin would under its store lock. With `order: false` it lands with no order entry; `expires` (default: valid)
43
+ * may name an expired credential. */
44
+ refresh(agentId: string, provider: string, o?: {
45
+ order?: boolean;
46
+ expires?: number;
47
+ }): void;
41
48
  } & {
42
49
  transport: GatewayTransport;
43
50
  };
@@ -385,6 +385,25 @@ export function fakeGateway(script, o) {
385
385
  models.delete(id);
386
386
  return { ok: true, agentId: id, removedBindings: 0 };
387
387
  },
388
+ // model: null clears the agent's primary (config.patch cannot delete a key); a string sets it.
389
+ 'agents.update': (p) => {
390
+ const id = String(p.agentId ?? '');
391
+ if (!id)
392
+ throw new Error('agents.update requires agentId');
393
+ if ('model' in p) {
394
+ const entries = configBox.config.agents?.entries;
395
+ if (p.model === null) {
396
+ models.delete(id);
397
+ if (entries?.[id] && 'model' in entries[id])
398
+ delete entries[id].model;
399
+ }
400
+ else if (typeof p.model === 'string')
401
+ setPrimaryOfId(id, p.model);
402
+ else
403
+ throw new Error('agents.update model must be a string or null');
404
+ }
405
+ return { ok: true, agentId: id };
406
+ },
388
407
  'agents.files.get': (p) => fileAnswer(String(p.agentId), String(p.name)),
389
408
  'agents.files.set': (p) => {
390
409
  filesOf(String(p.agentId)).files.set(String(p.name), String(p.content));
@@ -447,9 +466,11 @@ export function fakeGateway(script, o) {
447
466
  'byokit.keys': (p) => {
448
467
  const id = `byokit-key-${p.member}`;
449
468
  if (p.action === 'prepare' || p.action === 'clear') {
469
+ // As the shipped plugin: a clear of a lane that was never created has nothing to drop and reports absent.
470
+ const lane = keys.has(id) || agents.has(id);
450
471
  keys.delete(id);
451
472
  ensureAgent(id).providers = [];
452
- return { ok: true };
473
+ return lane ? { ok: true } : { ok: false, absent: true };
453
474
  }
454
475
  const key = keys.get(id);
455
476
  if (!key)
@@ -858,6 +879,19 @@ export function fakeGateway(script, o) {
858
879
  storeOf(agentId)[profileId] = profile;
859
880
  setPrimaryOfId(agentId, `${profile.provider}/default@${profileId}`);
860
881
  },
882
+ refresh: (agentId, provider, o) => {
883
+ const agent = ensureAgent(agentId);
884
+ if (!agent.providers.includes(provider))
885
+ agent.providers.push(provider);
886
+ const profileId = `${provider}:default`;
887
+ storeOf(agentId)[profileId] = { provider, type: 'oauth', status: 'ok', access: 'fake-access',
888
+ refresh: 'fake-refresh', expires: o?.expires ?? Date.now() + 30 * 86_400_000,
889
+ accountId: `fake-refresh-${agentId}` };
890
+ if (o?.order !== false)
891
+ orderOf(agentId)[provider] = [profileId];
892
+ else if (orderOf(agentId)[provider])
893
+ delete orderOf(agentId)[provider];
894
+ },
861
895
  transport: factory({ port: 0, token: 'test', identityPath: '', bridgeSock: '' }),
862
896
  };
863
897
  }
@@ -0,0 +1,16 @@
1
+ import type { ThinkingAsked, ThinkingReport, ThinkingUsed } from './types.ts';
2
+ export type CatalogModel = {
3
+ id?: string;
4
+ thinkingLevelMap?: Record<string, string | null | undefined>;
5
+ compat?: {
6
+ supportedReasoningEfforts?: readonly string[] | null;
7
+ };
8
+ };
9
+ /** Supported thinking level ids from one catalog model row, or undefined when the catalog names none. */
10
+ export declare function levelsOf(model: CatalogModel | undefined): ThinkingUsed[] | undefined;
11
+ /** Nearest supported level for `asked`. Empty/absent catalog levels leave `asked` unchanged. */
12
+ export declare function clampThinking(asked: ThinkingAsked, supported: readonly ThinkingUsed[] | undefined): ThinkingReport;
13
+ /** The catalog row for `provider`/`modelId` in a `config.get` models.providers map. */
14
+ export declare function catalogModelOf(providers: Record<string, {
15
+ models?: CatalogModel[];
16
+ }> | undefined, provider: string, modelId: string): CatalogModel | undefined;
@@ -0,0 +1,62 @@
1
+ const ORDER = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
2
+ /** Supported thinking level ids from one catalog model row, or undefined when the catalog names none. */
3
+ export function levelsOf(model) {
4
+ if (!model)
5
+ return undefined;
6
+ const efforts = model.compat?.supportedReasoningEfforts;
7
+ if (Array.isArray(efforts) && efforts.length > 0) {
8
+ const out = [];
9
+ const seen = new Set();
10
+ for (const raw of ['off', ...efforts]) {
11
+ const id = raw === 'none' ? 'off' : raw;
12
+ if (!ORDER.includes(id) || seen.has(id))
13
+ continue;
14
+ seen.add(id);
15
+ out.push(id);
16
+ }
17
+ return out.length ? out : undefined;
18
+ }
19
+ const map = model.thinkingLevelMap;
20
+ if (!map)
21
+ return undefined;
22
+ const out = ORDER.filter((level) => {
23
+ const mapped = map[level];
24
+ if (mapped === null)
25
+ return false;
26
+ if (level === 'xhigh' || level === 'max')
27
+ return mapped !== undefined;
28
+ return true;
29
+ });
30
+ return out.length ? out : undefined;
31
+ }
32
+ /** Nearest supported level for `asked`. Empty/absent catalog levels leave `asked` unchanged. */
33
+ export function clampThinking(asked, supported) {
34
+ if (!supported?.length)
35
+ return { asked, used: asked };
36
+ if (supported.includes(asked))
37
+ return { asked, used: asked };
38
+ const candidates = asked === 'off' ? supported : supported.filter((level) => level !== 'off');
39
+ const pool = candidates.length ? candidates : supported;
40
+ const at = ORDER.indexOf(asked);
41
+ if (at >= 0) {
42
+ for (let i = at; i < ORDER.length; i++) {
43
+ const level = ORDER[i];
44
+ if (pool.includes(level))
45
+ return { asked, used: level };
46
+ }
47
+ for (let i = at - 1; i >= 0; i--) {
48
+ const level = ORDER[i];
49
+ if (pool.includes(level))
50
+ return { asked, used: level };
51
+ }
52
+ }
53
+ return { asked, used: pool[0] };
54
+ }
55
+ /** The catalog row for `provider`/`modelId` in a `config.get` models.providers map. */
56
+ export function catalogModelOf(providers, provider, modelId) {
57
+ const rows = providers?.[provider]?.models;
58
+ if (!rows)
59
+ return undefined;
60
+ const needle = modelId.includes('/') ? modelId.slice(modelId.indexOf('/') + 1) : modelId;
61
+ return rows.find((row) => row.id === needle || row.id === modelId || row.id === `${provider}/${needle}`);
62
+ }
package/dist/types.d.ts CHANGED
@@ -102,6 +102,13 @@ export type PlanWindow = {
102
102
  resetAt?: number;
103
103
  }[];
104
104
  };
105
+ /** Thinking levels a run may ask for (`RunSpec.thinking`) and the level the kit actually sent. */
106
+ export type ThinkingAsked = 'off' | 'low' | 'medium' | 'high';
107
+ export type ThinkingUsed = ThinkingAsked | 'minimal' | 'xhigh' | 'max';
108
+ export type ThinkingReport = {
109
+ asked: ThinkingAsked;
110
+ used: ThinkingUsed;
111
+ };
105
112
  export type RunEnd<T = unknown> = {
106
113
  ok: true;
107
114
  text: string;
@@ -110,6 +117,7 @@ export type RunEnd<T = unknown> = {
110
117
  planWindow?: PlanWindow;
111
118
  account?: AccountId;
112
119
  model?: string;
120
+ thinking?: ThinkingReport;
113
121
  } | {
114
122
  ok: false;
115
123
  aborted: true;
package/dist/words.json CHANGED
@@ -21,6 +21,7 @@
21
21
  "signin.returned": "Thanks. Finishing the sign-in — you can go back to the app now.",
22
22
  "signin.busy": "Another sign-in is already in progress. Finish or cancel it, then try again.",
23
23
  "signin.cancelled": "Sign-in cancelled. You can start again whenever you are ready.",
24
+ "signin.savedNotRestarted": "Your Claude sign-in was saved, but the engine did not restart in time. Try again.",
24
25
  "signin.expired": "The sign-in took too long. Start it again.",
25
26
  "signin.title": "Sign in to {site}",
26
27
  "signin.takeover": "Take over to sign in",
@@ -81,6 +82,7 @@
81
82
  "auto.refillsNoTime": "All {provider} accounts are out of room. {name} refills first.",
82
83
  "auto.terms": "Auto may use either of a provider's accounts.",
83
84
  "auto.none": "No signed-in {provider} account.",
85
+ "auto.noneBound": "No account in this conversation is signed in.",
84
86
  "room.unknown": "Room left unknown",
85
87
  "room.session": "{left} left this session",
86
88
  "room.week": "{left} left this week",
@@ -110,10 +112,12 @@
110
112
  "account.another": "another account",
111
113
  "account.signOutFirst": "To add a different {provider} account, sign out of {provider} in your browser first.",
112
114
  "account.legacyMember": "This person needs a new profile before adding more accounts.",
115
+ "account.indexDamaged": "The account list for {member} couldn't be opened, so those accounts are paused. Add the account again to fix this.",
113
116
  "move.unsupported": "This conversation has not started yet, so there is nothing to move.",
114
117
  "move.busy": "Wait for this conversation to finish before moving it.",
115
118
  "move.notReady": "Sign in to {name} first.",
116
119
  "move.closeFailed": "This conversation now continues on {name}, but its earlier copy could not be removed.",
117
120
  "move.taken": "{name} already holds a conversation under this name, so nothing was moved.",
118
- "run.moved": "This conversation just moved to another account. Send it again to continue there."
121
+ "run.moved": "This conversation just moved to another account. Send it again to continue there.",
122
+ "run.thinkingClamped": "Thinking set to {used} because this model does not support {asked}."
119
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byokit/openclaw",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "The OpenClaw runtime kit: the pinned engine's full operator surface with plain-words helpers for members, sign-in, runs and approvals.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -60,6 +60,7 @@
60
60
  "prepack": "tsc -b && node ../../scripts/fix-words-dts.cjs"
61
61
  },
62
62
  "dependencies": {
63
+ "@byokit/accounts": "0.23.0",
63
64
  "@byokit/pair": "0.10.0",
64
65
  "@byokit/relay": "0.6.1",
65
66
  "@byokit/discover": "0.8.1",
package/plugin/keys.js CHANGED
@@ -19,8 +19,9 @@ export function registerKeys(api) {
19
19
  if (diagnostics) diagnostics.stage = 'config';
20
20
  const config = JSON.parse(await readFile(process.env.OPENCLAW_CONFIG_PATH, 'utf8'));
21
21
  const keyId = `byokit-key-${member}`;
22
- if (!config.agents?.entries?.[member] || !config.agents?.entries?.[keyId]) {
23
- reply({ ok: false });
22
+ // A clear for a lane that was never created (or whose entries are gone) has nothing left to drop and reports absent.
23
+ if (!config.agents?.entries?.[keyId] || (params.action !== 'clear' && !config.agents?.entries?.[member])) {
24
+ reply(params.action === 'clear' ? { ok: false, absent: true } : { ok: false });
24
25
  return;
25
26
  }
26
27
  const keyDir = resolveAgentDir(config, keyId);