@lobehub/cli 0.0.223 → 0.0.225
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/acceptance-report.html +1 -1
- package/dist/index.js +92 -266
- package/man/man1/lh.1 +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -199,14 +199,27 @@ const firstEnvEntry = (names) => {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
const firstEnvValue = (names) => firstEnvEntry(names)?.value;
|
|
202
|
-
/**
|
|
203
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Whether this process runs inside a LobeHub agent run: the app stamps the run's ids into the
|
|
204
|
+
* environment of every agent it launches, and every shell that agent opens inherits them (Codex
|
|
205
|
+
* included, through `shell_environment_policy.set`).
|
|
206
|
+
*/
|
|
207
|
+
const isInsideAgentRun = (env = process.env) => !!(env.LOBEHUB_TOPIC_ID || env.LOBEHUB_OPERATION_ID);
|
|
208
|
+
/**
|
|
209
|
+
* API key from the environment, honouring every accepted variable name.
|
|
210
|
+
*
|
|
211
|
+
* Inside an agent run there is none: the run authenticates with its own sign-in
|
|
212
|
+
* (`LOBEHUB_JWT`), and a key the user exported in their shell belongs to this
|
|
213
|
+
* machine, not to the run — the same reason the stored login is not read there
|
|
214
|
+
* (`getValidToken`).
|
|
215
|
+
*/
|
|
216
|
+
const readCliApiKeyEnv = () => isInsideAgentRun() ? void 0 : firstEnvValue(CLI_API_KEY_ENV_NAMES);
|
|
204
217
|
/**
|
|
205
218
|
* Same lookup as {@link readCliApiKeyEnv}, but keeps the variable name that
|
|
206
219
|
* actually matched. `lh doctor` reports which env var a credential came from,
|
|
207
220
|
* and "LOBEHUB_CLI_API_KEY" is the wrong answer when an older alias won.
|
|
208
221
|
*/
|
|
209
|
-
const readCliApiKeyEnvSource = () => firstEnvEntry(CLI_API_KEY_ENV_NAMES);
|
|
222
|
+
const readCliApiKeyEnvSource = () => isInsideAgentRun() ? void 0 : firstEnvEntry(CLI_API_KEY_ENV_NAMES);
|
|
210
223
|
/** Config directory name, overridable per-install by the home env var. */
|
|
211
224
|
const resolveCliDirName = () => firstEnvValue(CLI_HOME_ENV_NAMES) ?? ".lobehub";
|
|
212
225
|
|
|
@@ -302,7 +315,7 @@ function clearCredentials() {
|
|
|
302
315
|
function resolveIdentityFingerprint() {
|
|
303
316
|
const envJwt = process.env.LOBEHUB_JWT;
|
|
304
317
|
if (envJwt) return userIdentity(envJwt);
|
|
305
|
-
if (readCliApiKeyEnv()) return void 0;
|
|
318
|
+
if (readCliApiKeyEnv() || isInsideAgentRun()) return void 0;
|
|
306
319
|
const stored = loadCredentials();
|
|
307
320
|
return stored?.accessToken ? userIdentity(stored.accessToken) : void 0;
|
|
308
321
|
}
|
|
@@ -18486,8 +18499,8 @@ const rw = (read, write) => ({
|
|
|
18486
18499
|
*/
|
|
18487
18500
|
const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
18488
18501
|
accountDeletion: "blocked",
|
|
18489
|
-
acceptance: "
|
|
18490
|
-
acceptanceComment: "
|
|
18502
|
+
acceptance: rw("acceptance:read", "acceptance:write"),
|
|
18503
|
+
acceptanceComment: rw("acceptance:read", "acceptance:write"),
|
|
18491
18504
|
agent: rw("agent:read", "agent:write"),
|
|
18492
18505
|
agentAccount: rw("agent:read", "agent:write"),
|
|
18493
18506
|
agentAvailability: rw("agent:read", null),
|
|
@@ -18504,7 +18517,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
|
18504
18517
|
agentSkills: rw("agent:read", "agent:write"),
|
|
18505
18518
|
agentSteerQueue: rw("agent:read", "agent:write"),
|
|
18506
18519
|
agentRunBoard: "blocked",
|
|
18507
|
-
agentTrace: "
|
|
18520
|
+
agentTrace: rw("trace:read", null),
|
|
18508
18521
|
aiAgent: rw("agent:read", "agent:write"),
|
|
18509
18522
|
aiChat: { any: "model:invoke" },
|
|
18510
18523
|
aiModel: rw("model:read", "model:write"),
|
|
@@ -18514,7 +18527,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
|
18514
18527
|
auth: "open",
|
|
18515
18528
|
artboard: "blocked",
|
|
18516
18529
|
artifactShare: rw("chat:read", null),
|
|
18517
|
-
botMessage: "
|
|
18530
|
+
botMessage: { any: "bot:message" },
|
|
18518
18531
|
brief: rw("chat:read", "chat:write"),
|
|
18519
18532
|
canvas: "blocked",
|
|
18520
18533
|
changelog: "open",
|
|
@@ -18526,7 +18539,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
|
18526
18539
|
config: "open",
|
|
18527
18540
|
connector: "blocked",
|
|
18528
18541
|
dashboard: rw("agent:read", null),
|
|
18529
|
-
device:
|
|
18542
|
+
device: rw(null, null),
|
|
18530
18543
|
deviceMetric: "blocked",
|
|
18531
18544
|
document: rw("knowledge:read", "knowledge:write"),
|
|
18532
18545
|
documentComment: rw("knowledge:read", "knowledge:write"),
|
|
@@ -18601,7 +18614,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
|
18601
18614
|
userMemories: rw("user:read", "user:write"),
|
|
18602
18615
|
userMemory: rw("user:read", "user:write"),
|
|
18603
18616
|
userSkill: rw("agent:read", "agent:write"),
|
|
18604
|
-
verify: "
|
|
18617
|
+
verify: rw("acceptance:read", "acceptance:write"),
|
|
18605
18618
|
video: { any: "model:invoke" },
|
|
18606
18619
|
waitlist: "blocked",
|
|
18607
18620
|
webBrowsing: { any: "model:invoke" },
|
|
@@ -26685,7 +26698,7 @@ const GOMS_KLM_TIMING_SECONDS = {
|
|
|
26685
26698
|
* @see https://trpc.io/docs/client/links#creating-a-custom-link
|
|
26686
26699
|
* @public
|
|
26687
26700
|
*/
|
|
26688
|
-
function observable
|
|
26701
|
+
function observable(subscribe) {
|
|
26689
26702
|
const self = {
|
|
26690
26703
|
subscribe(observer) {
|
|
26691
26704
|
let teardownRef = null;
|
|
@@ -26744,12 +26757,12 @@ function observable$1(subscribe) {
|
|
|
26744
26757
|
return { unsubscribe };
|
|
26745
26758
|
},
|
|
26746
26759
|
pipe(...operations) {
|
|
26747
|
-
return operations.reduce(pipeReducer
|
|
26760
|
+
return operations.reduce(pipeReducer, self);
|
|
26748
26761
|
}
|
|
26749
26762
|
};
|
|
26750
26763
|
return self;
|
|
26751
26764
|
}
|
|
26752
|
-
function pipeReducer
|
|
26765
|
+
function pipeReducer(prev, fn) {
|
|
26753
26766
|
return fn(prev);
|
|
26754
26767
|
}
|
|
26755
26768
|
/**
|
|
@@ -26965,7 +26978,7 @@ function share(_opts) {
|
|
|
26965
26978
|
function resetIfNeeded() {
|
|
26966
26979
|
if (refCount === 0 && subscription) resetSource();
|
|
26967
26980
|
}
|
|
26968
|
-
return observable
|
|
26981
|
+
return observable((subscriber) => {
|
|
26969
26982
|
refCount++;
|
|
26970
26983
|
const subscriberObservers = observers;
|
|
26971
26984
|
subscriberObservers.add(subscriber);
|
|
@@ -27007,7 +27020,7 @@ function behaviorSubject(initialValue) {
|
|
|
27007
27020
|
const removeObserver = (observer) => {
|
|
27008
27021
|
observerList.delete(observer);
|
|
27009
27022
|
};
|
|
27010
|
-
const obs = observable
|
|
27023
|
+
const obs = observable((observer) => {
|
|
27011
27024
|
addObserver(observer);
|
|
27012
27025
|
return () => {
|
|
27013
27026
|
removeObserver(observer);
|
|
@@ -27026,7 +27039,7 @@ function behaviorSubject(initialValue) {
|
|
|
27026
27039
|
//#region node_modules/.pnpm/@trpc+client@11.29.7_@trpc+server@11.29.7_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/splitLink-PFsRy7Mf.mjs
|
|
27027
27040
|
/** @internal */
|
|
27028
27041
|
function createChain(opts) {
|
|
27029
|
-
return observable
|
|
27042
|
+
return observable((observer) => {
|
|
27030
27043
|
function execute(index = 0, op = opts.op) {
|
|
27031
27044
|
const next = opts.links[index];
|
|
27032
27045
|
if (!next) throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
@@ -27630,7 +27643,7 @@ function httpLink(opts) {
|
|
|
27630
27643
|
return () => {
|
|
27631
27644
|
return (operationOpts) => {
|
|
27632
27645
|
const { op } = operationOpts;
|
|
27633
|
-
return observable
|
|
27646
|
+
return observable((observer) => {
|
|
27634
27647
|
const { path, input, type } = op;
|
|
27635
27648
|
/* istanbul ignore if -- @preserve */
|
|
27636
27649
|
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
@@ -27942,7 +27955,7 @@ var TRPCUntypedClient = class {
|
|
|
27942
27955
|
});
|
|
27943
27956
|
if (!hasCallbacks) {
|
|
27944
27957
|
var _opts$signal;
|
|
27945
|
-
const iterator = observableToAsyncIterable(observable
|
|
27958
|
+
const iterator = observableToAsyncIterable(observable((observer) => observable$.subscribe({
|
|
27946
27959
|
next(envelope) {
|
|
27947
27960
|
if (envelope.result.type === "data" || envelope.result.type === void 0) observer.next(envelope.result.data);
|
|
27948
27961
|
},
|
|
@@ -28958,6 +28971,7 @@ let refreshInFlight;
|
|
|
28958
28971
|
* Get a valid access token, refreshing if expired.
|
|
28959
28972
|
*/
|
|
28960
28973
|
async function getValidToken(bufferSeconds = 60) {
|
|
28974
|
+
if (isInsideAgentRun()) return { status: "agent-run" };
|
|
28961
28975
|
const credentials = loadCredentials();
|
|
28962
28976
|
if (!credentials) return { status: "no-login" };
|
|
28963
28977
|
if (credentials.expiresAt && Date.now() / 1e3 < credentials.expiresAt - bufferSeconds) return {
|
|
@@ -28989,22 +29003,16 @@ const refreshStoredToken = async (credentials) => {
|
|
|
28989
29003
|
};
|
|
28990
29004
|
};
|
|
28991
29005
|
/**
|
|
28992
|
-
*
|
|
28993
|
-
* environment of every agent it launches, and every shell that agent opens inherits them.
|
|
28994
|
-
*/
|
|
28995
|
-
const isInsideAgentRun = (env = process.env) => !!(env.LOBEHUB_TOPIC_ID || env.LOBEHUB_OPERATION_ID);
|
|
28996
|
-
/**
|
|
28997
|
-
* The missing-login report for a command run by an agent inside LobeHub.
|
|
29006
|
+
* The report for a command run by an agent inside LobeHub without the run's own sign-in.
|
|
28998
29007
|
*
|
|
28999
|
-
* Read by the agent, not by a person at a terminal
|
|
29000
|
-
*
|
|
29001
|
-
*
|
|
29002
|
-
*
|
|
29003
|
-
|
|
29004
|
-
|
|
29005
|
-
|
|
29006
|
-
|
|
29007
|
-
fix: `Ask the user to run '${"lh"} login' in a terminal on this machine and approve it in the browser, then retry. Do not run it yourself; restarting LobeHub does not fix this. Updating LobeHub Desktop lets local agents use the app's own sign-in.`
|
|
29008
|
+
* Read by the agent, not by a person at a terminal. Inside a run `lh` uses only the sign-in the
|
|
29009
|
+
* run passed it, never this machine's login or API key, so a bare "run `lh login`" would send the
|
|
29010
|
+
* agent after exactly the credential it must not use. Spell out the cause and the one fix that
|
|
29011
|
+
* works: a LobeHub that passes the run its sign-in.
|
|
29012
|
+
*/
|
|
29013
|
+
const agentRunNoSignInReport = () => ({
|
|
29014
|
+
detail: "This command runs inside a LobeHub agent run, but the run passed no LobeHub sign-in to the CLI. Inside an agent run the CLI uses only the run's own sign-in, never this machine's login or API key.",
|
|
29015
|
+
fix: `Tell the user that LobeHub (Desktop, or '${"lh"} connect' on this machine) needs updating so its runs carry their sign-in. Do not run '${"lh"} login', set an API key, or clear the run's environment to get around this.`
|
|
29008
29016
|
});
|
|
29009
29017
|
/**
|
|
29010
29018
|
* How to explain a lookup that produced no token, or `undefined` when there is nothing to
|
|
@@ -29012,7 +29020,7 @@ const agentRunMissingLoginReport = () => ({
|
|
|
29012
29020
|
*/
|
|
29013
29021
|
function describeTokenLookup(lookup) {
|
|
29014
29022
|
switch (lookup.status) {
|
|
29015
|
-
case "
|
|
29023
|
+
case "agent-run": return agentRunNoSignInReport();
|
|
29016
29024
|
case "spent": return {
|
|
29017
29025
|
detail: `The stored login is no longer valid (${lookup.detail}).`,
|
|
29018
29026
|
fix: `Run '${"lh"} login' again.`
|
|
@@ -29121,6 +29129,11 @@ function pickAuthSource(options = {}) {
|
|
|
29121
29129
|
token: apiKey.value,
|
|
29122
29130
|
tokenType: "apiKey"
|
|
29123
29131
|
};
|
|
29132
|
+
if (isInsideAgentRun()) return {
|
|
29133
|
+
kind: "stored",
|
|
29134
|
+
origin: "none: an agent run uses only its own sign-in",
|
|
29135
|
+
tokenType: "jwt"
|
|
29136
|
+
};
|
|
29124
29137
|
return {
|
|
29125
29138
|
kind: "stored",
|
|
29126
29139
|
origin: `stored login (${credentialsPath()})`,
|
|
@@ -29155,198 +29168,6 @@ const cliVersion = pkg.version;
|
|
|
29155
29168
|
/** The node range this build is published for, e.g. `>=22.15`. */
|
|
29156
29169
|
const cliNodeEngine = pkg.engines?.node;
|
|
29157
29170
|
|
|
29158
|
-
//#endregion
|
|
29159
|
-
//#region ../../node_modules/.pnpm/@trpc+server@11.29.7_@types+aws-lambda@8.10.164_@types+express@5.0.6_@types+ws@8.18.2_n_4a5bbc7e05a0f03e83d6e27192082686/node_modules/@trpc/server/dist/observable-CodTG6Sf.mjs
|
|
29160
|
-
/**
|
|
29161
|
-
* Creates an observable. `subscribe` runs for each subscriber, and can
|
|
29162
|
-
* return a function that cleans up when it unsubscribes.
|
|
29163
|
-
* @example
|
|
29164
|
-
* ```ts
|
|
29165
|
-
* const ticks = observable<number>((observer) => {
|
|
29166
|
-
* const timer = setInterval(() => observer.next(Date.now()), 1000);
|
|
29167
|
-
* return () => clearInterval(timer);
|
|
29168
|
-
* });
|
|
29169
|
-
* ```
|
|
29170
|
-
* @see https://trpc.io/docs/client/links#creating-a-custom-link
|
|
29171
|
-
* @public
|
|
29172
|
-
*/
|
|
29173
|
-
function observable(subscribe) {
|
|
29174
|
-
const self = {
|
|
29175
|
-
subscribe(observer) {
|
|
29176
|
-
let teardownRef = null;
|
|
29177
|
-
let isDone = false;
|
|
29178
|
-
let unsubscribed = false;
|
|
29179
|
-
let teardownImmediately = false;
|
|
29180
|
-
let subscribing = true;
|
|
29181
|
-
let thrownWhileSubscribing = null;
|
|
29182
|
-
function end(notify) {
|
|
29183
|
-
try {
|
|
29184
|
-
notify();
|
|
29185
|
-
} catch (cause) {
|
|
29186
|
-
var _thrownWhileSubscribi;
|
|
29187
|
-
if (!subscribing) throw cause;
|
|
29188
|
-
(_thrownWhileSubscribi = thrownWhileSubscribing) !== null && _thrownWhileSubscribi !== void 0 || (thrownWhileSubscribing = { cause });
|
|
29189
|
-
} finally {
|
|
29190
|
-
unsubscribe();
|
|
29191
|
-
}
|
|
29192
|
-
}
|
|
29193
|
-
function unsubscribe() {
|
|
29194
|
-
if (teardownRef === null) {
|
|
29195
|
-
teardownImmediately = true;
|
|
29196
|
-
return;
|
|
29197
|
-
}
|
|
29198
|
-
if (unsubscribed) return;
|
|
29199
|
-
unsubscribed = true;
|
|
29200
|
-
if (typeof teardownRef === "function") teardownRef();
|
|
29201
|
-
else if (teardownRef) teardownRef.unsubscribe();
|
|
29202
|
-
}
|
|
29203
|
-
teardownRef = subscribe({
|
|
29204
|
-
next(value) {
|
|
29205
|
-
var _observer$next;
|
|
29206
|
-
if (isDone) return;
|
|
29207
|
-
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
29208
|
-
},
|
|
29209
|
-
error(err) {
|
|
29210
|
-
if (isDone) return;
|
|
29211
|
-
isDone = true;
|
|
29212
|
-
end(() => {
|
|
29213
|
-
var _observer$error;
|
|
29214
|
-
return (_observer$error = observer.error) === null || _observer$error === void 0 ? void 0 : _observer$error.call(observer, err);
|
|
29215
|
-
});
|
|
29216
|
-
},
|
|
29217
|
-
complete() {
|
|
29218
|
-
if (isDone) return;
|
|
29219
|
-
isDone = true;
|
|
29220
|
-
end(() => {
|
|
29221
|
-
var _observer$complete;
|
|
29222
|
-
return (_observer$complete = observer.complete) === null || _observer$complete === void 0 ? void 0 : _observer$complete.call(observer);
|
|
29223
|
-
});
|
|
29224
|
-
}
|
|
29225
|
-
});
|
|
29226
|
-
subscribing = false;
|
|
29227
|
-
if (teardownImmediately) unsubscribe();
|
|
29228
|
-
if (thrownWhileSubscribing) throw thrownWhileSubscribing.cause;
|
|
29229
|
-
return { unsubscribe };
|
|
29230
|
-
},
|
|
29231
|
-
pipe(...operations) {
|
|
29232
|
-
return operations.reduce(pipeReducer, self);
|
|
29233
|
-
}
|
|
29234
|
-
};
|
|
29235
|
-
return self;
|
|
29236
|
-
}
|
|
29237
|
-
function pipeReducer(prev, fn) {
|
|
29238
|
-
return fn(prev);
|
|
29239
|
-
}
|
|
29240
|
-
|
|
29241
|
-
//#endregion
|
|
29242
|
-
//#region src/api/operationTokenFallback.ts
|
|
29243
|
-
/**
|
|
29244
|
-
* Device-dispatched runs (desktop gateway, `lh connect`) carry the run's narrow
|
|
29245
|
-
* `hetero-operation` token in `LOBEHUB_JWT`. It is accepted by the operation
|
|
29246
|
-
* endpoints (`heteroIngest`, `goal.*Operation`, …) and refused by every
|
|
29247
|
-
* user-scoped one, while it still outranks the machine's stored login. So an
|
|
29248
|
-
* agent's `lh doc` / `lh kb` / … failed until the agent itself cleared the
|
|
29249
|
-
* variable — an instruction the `lh` guide had to teach, and one an agent then
|
|
29250
|
-
* applied to errors it did not fit.
|
|
29251
|
-
*
|
|
29252
|
-
* The refusal is a fixed `oidcAuth` answer, so the client recognises exactly it
|
|
29253
|
-
* and re-sends that one request with the stored login — but only when that
|
|
29254
|
-
* login is the same account the operation token was minted for. A workspace
|
|
29255
|
-
* device is reachable by every member, so the machine's login can belong to
|
|
29256
|
-
* someone other than the member whose run this is; borrowing it would read and
|
|
29257
|
-
* write that person's data. Everything else is unchanged: operation endpoints
|
|
29258
|
-
* keep the operation token, and the workspace header stays the run's own scope
|
|
29259
|
-
* (`LOBEHUB_WORKSPACE_ID` or personal) — which the manual fallback did not do,
|
|
29260
|
-
* since an empty `LOBEHUB_JWT` re-enables the terminal's persisted
|
|
29261
|
-
* `lh workspace use` scope.
|
|
29262
|
-
*
|
|
29263
|
-
* Reads with an operation-authenticated route need neither: `lh topic view`
|
|
29264
|
-
* tries `topic.getTopicTranscriptOperation` first (`commands/topic/readTranscript`).
|
|
29265
|
-
*/
|
|
29266
|
-
/** `oidcAuth`'s message when an operation token reaches a user-scoped route. */
|
|
29267
|
-
const OPERATION_TOKEN_REFUSAL = "hetero-operation tokens are not accepted on this endpoint";
|
|
29268
|
-
/** Operation-context key carrying the stored login on the request the link re-sends. */
|
|
29269
|
-
const STORED_LOGIN = "storedLogin";
|
|
29270
|
-
const isOperationToken = (token) => !!token && parseJwtPayload(token)?.purpose === "hetero-operation";
|
|
29271
|
-
const subjectOf = (token) => {
|
|
29272
|
-
const sub = parseJwtPayload(token)?.sub;
|
|
29273
|
-
return typeof sub === "string" && sub ? sub : void 0;
|
|
29274
|
-
};
|
|
29275
|
-
const isOperationTokenRefusal = (error) => isTRPCClientError(error) && error.data?.code === "UNAUTHORIZED" && error.message === "hetero-operation tokens are not accepted on this endpoint";
|
|
29276
|
-
/** A library destination cannot be filed as run-scoped evidence. The refusal
|
|
29277
|
-
* happens before createFile writes, so it can use the same one-shot, same-owner
|
|
29278
|
-
* fallback as a user-scoped endpoint. Never retry a general permission denial.
|
|
29279
|
-
*/
|
|
29280
|
-
const isLibraryUploadRefusal = (op, error) => {
|
|
29281
|
-
if (op.path !== "file.createFile" || !isTRPCClientError(error) || error.data?.code !== "FORBIDDEN" || !["This run's token can only upload acceptance evidence", "This run's token can only upload acceptance evidence or tool-result images"].includes(error.message)) return false;
|
|
29282
|
-
const input = op.input;
|
|
29283
|
-
return [input?.knowledgeBaseId, input?.parentId].some((id) => typeof id === "string" && id.length > 0);
|
|
29284
|
-
};
|
|
29285
|
-
/**
|
|
29286
|
-
* The stored login, when it is usable and belongs to the operation token's own
|
|
29287
|
-
* account.
|
|
29288
|
-
*/
|
|
29289
|
-
const storedLoginFor = async (operationToken) => {
|
|
29290
|
-
const result = await getValidToken();
|
|
29291
|
-
if (result.status === "ok") {
|
|
29292
|
-
const owner = subjectOf(operationToken);
|
|
29293
|
-
const stored = result.credentials.accessToken;
|
|
29294
|
-
if (owner && subjectOf(stored) === owner) return { token: stored };
|
|
29295
|
-
}
|
|
29296
|
-
const report = result.status === "no-login" ? void 0 : describeTokenLookup(result);
|
|
29297
|
-
return { warning: report ? `${report.detail} ${report.fix}` : "LOBEHUB_JWT is this run's operation token, which this endpoint refuses, and this machine has no stored login of the same account to use instead." };
|
|
29298
|
-
};
|
|
29299
|
-
/**
|
|
29300
|
-
* Re-send a request whose operation token was refused, once, with the stored
|
|
29301
|
-
* login of the same account. Without one, say why instead of re-sending a
|
|
29302
|
-
* request that can only be refused again.
|
|
29303
|
-
*/
|
|
29304
|
-
const operationTokenFallbackLink = (operationToken) => () => ({ next, op }) => observable((observer) => {
|
|
29305
|
-
let closed = false;
|
|
29306
|
-
let subscription = next(op).subscribe({
|
|
29307
|
-
complete: () => observer.complete(),
|
|
29308
|
-
error: (error) => {
|
|
29309
|
-
if (op.context[STORED_LOGIN] || !isOperationTokenRefusal(error) && !isLibraryUploadRefusal(op, error)) {
|
|
29310
|
-
observer.error(error);
|
|
29311
|
-
return;
|
|
29312
|
-
}
|
|
29313
|
-
storedLoginFor(operationToken()).then((lookup) => {
|
|
29314
|
-
if (closed) return;
|
|
29315
|
-
if ("warning" in lookup) {
|
|
29316
|
-
log$15.warn(lookup.warning);
|
|
29317
|
-
observer.error(error);
|
|
29318
|
-
return;
|
|
29319
|
-
}
|
|
29320
|
-
log$15.debug(`${op.path}: operation token refused, retrying with the stored login`);
|
|
29321
|
-
subscription = next({
|
|
29322
|
-
...op,
|
|
29323
|
-
context: {
|
|
29324
|
-
...op.context,
|
|
29325
|
-
[STORED_LOGIN]: lookup.token
|
|
29326
|
-
}
|
|
29327
|
-
}).subscribe(observer);
|
|
29328
|
-
}).catch((lookupError) => {
|
|
29329
|
-
if (closed) return;
|
|
29330
|
-
log$15.warn(`Could not look up the stored login: ${lookupError instanceof Error ? lookupError.message : String(lookupError)}`);
|
|
29331
|
-
observer.error(error);
|
|
29332
|
-
});
|
|
29333
|
-
},
|
|
29334
|
-
next: (value) => observer.next(value)
|
|
29335
|
-
});
|
|
29336
|
-
return () => {
|
|
29337
|
-
closed = true;
|
|
29338
|
-
subscription.unsubscribe();
|
|
29339
|
-
};
|
|
29340
|
-
});
|
|
29341
|
-
/**
|
|
29342
|
-
* Auth headers for a client holding an operation token: the token itself, or
|
|
29343
|
-
* the stored login `operationTokenFallbackLink` attached to a re-sent request.
|
|
29344
|
-
*/
|
|
29345
|
-
const operationTokenHeaders = (operationToken) => (opts) => {
|
|
29346
|
-
const stored = opts?.op?.context[STORED_LOGIN];
|
|
29347
|
-
return { "Oidc-Auth": typeof stored === "string" ? stored : operationToken() };
|
|
29348
|
-
};
|
|
29349
|
-
|
|
29350
29171
|
//#endregion
|
|
29351
29172
|
//#region src/api/client.ts
|
|
29352
29173
|
const PERSONAL_KEY = "__personal__";
|
|
@@ -29357,11 +29178,6 @@ async function getAuthAndServer() {
|
|
|
29357
29178
|
if (source.kind === "env-jwt") {
|
|
29358
29179
|
const serverUrl = resolveServerUrl();
|
|
29359
29180
|
const envToken = () => process.env.LOBEHUB_JWT || source.token;
|
|
29360
|
-
if (isOperationToken(source.token)) return {
|
|
29361
|
-
headers: operationTokenHeaders(envToken),
|
|
29362
|
-
operationToken: envToken,
|
|
29363
|
-
serverUrl
|
|
29364
|
-
};
|
|
29365
29181
|
return {
|
|
29366
29182
|
headers: () => ({ "Oidc-Auth": envToken() }),
|
|
29367
29183
|
serverUrl
|
|
@@ -29394,9 +29210,9 @@ async function getTrpcClient(workspaceId) {
|
|
|
29394
29210
|
const cacheKey = wsId ?? PERSONAL_KEY;
|
|
29395
29211
|
const cached = _clients.get(cacheKey);
|
|
29396
29212
|
if (cached) return cached;
|
|
29397
|
-
const { headers,
|
|
29398
|
-
const client = createTRPCClient({ links: [
|
|
29399
|
-
headers: async (
|
|
29213
|
+
const { headers, serverUrl } = await getAuthAndServer();
|
|
29214
|
+
const client = createTRPCClient({ links: [httpLink({
|
|
29215
|
+
headers: async () => withWorkspaceHeader(await headers(), wsId),
|
|
29400
29216
|
transformer: SuperJSON,
|
|
29401
29217
|
url: `${serverUrl}/trpc/lambda`
|
|
29402
29218
|
})] });
|
|
@@ -29443,9 +29259,9 @@ async function getToolsTrpcClient(workspaceId) {
|
|
|
29443
29259
|
const cacheKey = wsId ?? PERSONAL_KEY;
|
|
29444
29260
|
const cached = _toolsClients.get(cacheKey);
|
|
29445
29261
|
if (cached) return cached;
|
|
29446
|
-
const { headers,
|
|
29447
|
-
const client = createTRPCClient({ links: [
|
|
29448
|
-
headers: async (
|
|
29262
|
+
const { headers, serverUrl } = await getAuthAndServer();
|
|
29263
|
+
const client = createTRPCClient({ links: [httpLink({
|
|
29264
|
+
headers: async () => withWorkspaceHeader(await headers(), wsId),
|
|
29449
29265
|
transformer: SuperJSON,
|
|
29450
29266
|
url: `${serverUrl}/trpc/tools`
|
|
29451
29267
|
})] });
|
|
@@ -41620,6 +41436,22 @@ function withEvidenceUploadOptions(cmd) {
|
|
|
41620
41436
|
return cmd.requiredOption("--check <checkResultId>", "Target check result id").requiredOption("--type <type>", "screenshot|gif|video|audio|text|markdown|dom_snapshot|transcript").option("--file <path>", "Local file to upload as the artifact").option("--file-id <id>", "Attach an already-uploaded file without uploading it again").option("--content <text>", "Inline text payload (instead of a file)").option("--metadata <json>", "Evidence metadata, preserved when retrying an attachment").option("--chapters <file>", "Video chapters JSON (steps, checks, flags on the timeline)").option("--by <capturedBy>", "agent-browser|cdp|cli|program|llm_judge", "cli").option("--desc <text>", "Human-readable caption").option("--json [fields]", "Output JSON");
|
|
41621
41437
|
}
|
|
41622
41438
|
|
|
41439
|
+
//#endregion
|
|
41440
|
+
//#region src/api/operationToken.ts
|
|
41441
|
+
/**
|
|
41442
|
+
* A device-dispatched run (desktop gateway, `lh connect`) authenticates with
|
|
41443
|
+
* the run's `hetero-operation` token in `LOBEHUB_JWT`. A server that mints it
|
|
41444
|
+
* with `caller:act` accepts it on user routes as the user who started the run;
|
|
41445
|
+
* an older server answers those routes with this refusal.
|
|
41446
|
+
*
|
|
41447
|
+
* `lh` never answers a refusal by switching to this machine's own login: on a
|
|
41448
|
+
* shared device that login can belong to someone else, and the server alone
|
|
41449
|
+
* decides what a run may do.
|
|
41450
|
+
*/
|
|
41451
|
+
const OPERATION_TOKEN_REFUSAL = "hetero-operation tokens are not accepted on this endpoint";
|
|
41452
|
+
const isOperationToken = (token) => !!token && parseJwtPayload(token)?.purpose === "hetero-operation";
|
|
41453
|
+
const isOperationTokenRefusal = (error) => isTRPCClientError(error) && error.data?.code === "UNAUTHORIZED" && error.message === "hetero-operation tokens are not accepted on this endpoint";
|
|
41454
|
+
|
|
41623
41455
|
//#endregion
|
|
41624
41456
|
//#region src/commands/acceptance/run/report.ts
|
|
41625
41457
|
/**
|
|
@@ -41629,9 +41461,8 @@ function withEvidenceUploadOptions(cmd) {
|
|
|
41629
41461
|
* round's verifier writes it, and `upsertReport` stays off the operation-token
|
|
41630
41462
|
* allowlist. A token without `acceptance:evidence` is refused one step earlier,
|
|
41631
41463
|
* on the language check's `user.getUserState`, and is no closer to writing it.
|
|
41632
|
-
* A
|
|
41633
|
-
*
|
|
41634
|
-
* 401 only got retried. The commands below take the run's own operation id,
|
|
41464
|
+
* A run never retries with the machine's stored login, so the refusal is
|
|
41465
|
+
* final. The commands below take the run's own operation id,
|
|
41635
41466
|
* which the token is bound to.
|
|
41636
41467
|
*/
|
|
41637
41468
|
const reportRefusalGuidance = (runId) => {
|
|
@@ -70220,16 +70051,12 @@ function registerCompletionCommand(program) {
|
|
|
70220
70051
|
//#region src/api/openapi.ts
|
|
70221
70052
|
/**
|
|
70222
70053
|
* The Bearer token for `/api/v1/*`. That API accepts OIDC JWTs and API keys
|
|
70223
|
-
* but refuses a run's `hetero-operation` token outright,
|
|
70224
|
-
* in
|
|
70225
|
-
* account, the same rule `operationTokenFallbackLink` applies to tRPC.
|
|
70054
|
+
* but refuses a run's `hetero-operation` token outright, and `lh` does not
|
|
70055
|
+
* swap in this machine's own login for it (see `operationToken`).
|
|
70226
70056
|
*/
|
|
70227
70057
|
const resolveBearerToken = async () => {
|
|
70228
|
-
|
|
70229
|
-
|
|
70230
|
-
const lookup = await storedLoginFor(envJwt);
|
|
70231
|
-
if ("token" in lookup) return lookup.token;
|
|
70232
|
-
log$15.error(lookup.warning);
|
|
70058
|
+
if (isOperationToken(process.env.LOBEHUB_JWT)) {
|
|
70059
|
+
log$15.error("This command is not available inside an agent run: its LobeHub API does not accept the run's sign-in. Ask the user to run it in a terminal.");
|
|
70233
70060
|
process.exit(1);
|
|
70234
70061
|
}
|
|
70235
70062
|
return (await getAgentStreamAuthInfo()).token;
|
|
@@ -72725,20 +72552,19 @@ const createCodexJwtFile = async (jwt) => {
|
|
|
72725
72552
|
*
|
|
72726
72553
|
* - **Credentials.** The cloud sandbox is handed a user-scoped JWT, and a
|
|
72727
72554
|
* desktop client-mode run is handed the app's own sign-in as
|
|
72728
|
-
* `LOBEHUB_JWT_FILE` (older desktops
|
|
72729
|
-
*
|
|
72730
|
-
*
|
|
72731
|
-
*
|
|
72732
|
-
*
|
|
72733
|
-
*
|
|
72734
|
-
*
|
|
72735
|
-
*
|
|
72736
|
-
*
|
|
72737
|
-
*
|
|
72738
|
-
* (`
|
|
72739
|
-
*
|
|
72740
|
-
*
|
|
72741
|
-
* did not fit.
|
|
72555
|
+
* `LOBEHUB_JWT_FILE` (older desktops passed none). The device-dispatch
|
|
72556
|
+
* paths (desktop gateway, `lh connect`) put the run's `hetero-operation`
|
|
72557
|
+
* token in `LOBEHUB_JWT`. Minted with `caller:act`, it acts as the user who
|
|
72558
|
+
* started the run, only in the run's workspace, only while the run lasts and
|
|
72559
|
+
* only within `HETERO_CALLER_SCOPES` (tasks, documents, files, acceptance,
|
|
72560
|
+
* bot messages, the device list, traces);
|
|
72561
|
+
* `oidcAuth` refuses a token without it there. `lh topic view` reads through
|
|
72562
|
+
* an operation route first, as the run's own principal, limited to this
|
|
72563
|
+
* conversation and the ones the user names in it
|
|
72564
|
+
* (`topic.getTopicTranscriptOperation`). Inside a run `lh` never uses the
|
|
72565
|
+
* machine's own login or API key (`getValidToken`, `readCliApiKeyEnv`): on a
|
|
72566
|
+
* shared workspace device they belong to whoever enrolled it. So the guide
|
|
72567
|
+
* does not teach the agent to clear the variable or log in.
|
|
72742
72568
|
* - **`LOBEHUB_AGENT_ID`.** Desktop client mode sets it through
|
|
72743
72569
|
* `buildLobeHubSessionEnv`. CLI/Desktop dispatch launchers, including
|
|
72744
72570
|
* OpenClaw/Hermes, clear inherited identity and inject the current dispatch's
|
|
@@ -563144,7 +562970,7 @@ const credentialSource = {
|
|
|
563144
562970
|
};
|
|
563145
562971
|
if (!source.token) {
|
|
563146
562972
|
if (isInsideAgentRun()) return {
|
|
563147
|
-
...
|
|
562973
|
+
...agentRunNoSignInReport(),
|
|
563148
562974
|
evidence,
|
|
563149
562975
|
status: "fail"
|
|
563150
562976
|
};
|
|
@@ -595823,9 +595649,9 @@ const isMissingProcedure = (error) => isTRPCClientError(error) && error.message.
|
|
|
595823
595649
|
* run's own principal, limited to its own conversation and the ones the user
|
|
595824
595650
|
* names in it. When that route cannot serve the read — a server without it, a
|
|
595825
595651
|
* topic outside that boundary, a run that already ended — the ordinary route is
|
|
595826
|
-
* tried, which
|
|
595827
|
-
*
|
|
595828
|
-
*
|
|
595652
|
+
* tried, which a server that accepts the run's token as its caller answers. If
|
|
595653
|
+
* the ordinary route only repeats the operation token refusal (an older server),
|
|
595654
|
+
* the operation route's own answer is the one worth showing.
|
|
595829
595655
|
*
|
|
595830
595656
|
* `--workspace` names a scope the run's token was not minted for, so it always
|
|
595831
595657
|
* takes the ordinary route.
|
package/man/man1/lh.1
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.\" Code generated by `npm run man:generate`; DO NOT EDIT.
|
|
2
2
|
.\" Manual command details come from the Commander command tree.
|
|
3
|
-
.TH LH 1 "" "@lobehub/cli 0.0.
|
|
3
|
+
.TH LH 1 "" "@lobehub/cli 0.0.225" "User Commands"
|
|
4
4
|
.SH NAME
|
|
5
5
|
lh \- LobeHub CLI \- manage and connect to LobeHub services
|
|
6
6
|
.SH SYNOPSIS
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.225",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/lobehub/lobehub",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"access": "public",
|
|
84
84
|
"registry": "https://registry.npmjs.org"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "3bf7170d71c83b5bec9adc6b1579e694f189c2cf"
|
|
87
87
|
}
|