@lobehub/cli 0.0.103 → 0.0.104
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 +284 -281
- package/dist/index.js +660 -39
- package/man/man1/lh.1 +7 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7900,6 +7900,8 @@ var init_workingDir = __esmMin((() => {
|
|
|
7900
7900
|
"success",
|
|
7901
7901
|
"unknown"
|
|
7902
7902
|
]).optional(),
|
|
7903
|
+
headRefName: string().optional(),
|
|
7904
|
+
headRepoFullName: string().optional(),
|
|
7903
7905
|
isDraft: boolean().optional(),
|
|
7904
7906
|
mergeable: string().optional(),
|
|
7905
7907
|
mergeStateStatus: string().optional(),
|
|
@@ -7928,6 +7930,7 @@ var init_workingDir = __esmMin((() => {
|
|
|
7928
7930
|
]).optional()
|
|
7929
7931
|
}).optional(),
|
|
7930
7932
|
isWorktree: boolean().optional(),
|
|
7933
|
+
ownBranch: string().optional(),
|
|
7931
7934
|
ownerNonce: string().max(64).optional(),
|
|
7932
7935
|
ownerToken: string().max(128).optional(),
|
|
7933
7936
|
upstream: object$1({
|
|
@@ -12123,12 +12126,18 @@ var init_connector = __esmMin((() => {}));
|
|
|
12123
12126
|
|
|
12124
12127
|
//#endregion
|
|
12125
12128
|
//#region ../../packages/types/src/inboundWebhook.ts
|
|
12126
|
-
var GENERIC_WEBHOOK_TOPIC_MODES, McpEventsWebhookConfigSchema, McpEventsWebhookStateSchema, McpEventsWebhookVerificationSchema, GenericWebhookConfigSchema, GenericWebhookStateSchema, GenericWebhookVerificationSchema, InboundWebhookDataSchema;
|
|
12129
|
+
var GENERIC_WEBHOOK_TOPIC_MODES, GENERIC_WEBHOOK_IDENTIFIER_PATTERN, InboundWebhookChannelDeliverySchema, McpEventsWebhookConfigSchema, McpEventsWebhookStateSchema, McpEventsWebhookVerificationSchema, GenericWebhookConfigSchema, GenericWebhookStateSchema, GenericWebhookVerificationSchema, InboundWebhookDataSchema;
|
|
12127
12130
|
var init_inboundWebhook = __esmMin((() => {
|
|
12128
12131
|
init_zod$1();
|
|
12129
12132
|
GENERIC_WEBHOOK_TOPIC_MODES = ["new", "reuse"];
|
|
12133
|
+
GENERIC_WEBHOOK_IDENTIFIER_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,46}[a-z0-9])?$/;
|
|
12134
|
+
InboundWebhookChannelDeliverySchema = object$1({
|
|
12135
|
+
channelId: string().min(1),
|
|
12136
|
+
threadId: string().min(1).optional()
|
|
12137
|
+
}).strict();
|
|
12130
12138
|
McpEventsWebhookConfigSchema = object$1({
|
|
12131
12139
|
arguments: record(string(), unknown()),
|
|
12140
|
+
delivery: InboundWebhookChannelDeliverySchema.optional(),
|
|
12132
12141
|
eventName: string().min(1),
|
|
12133
12142
|
linkId: string().min(1).optional()
|
|
12134
12143
|
}).strict();
|
|
@@ -12149,6 +12158,8 @@ var init_inboundWebhook = __esmMin((() => {
|
|
|
12149
12158
|
McpEventsWebhookVerificationSchema = object$1({ scheme: literal("standard_webhooks") }).strict();
|
|
12150
12159
|
GenericWebhookConfigSchema = object$1({
|
|
12151
12160
|
autoApprove: boolean(),
|
|
12161
|
+
delivery: InboundWebhookChannelDeliverySchema.optional(),
|
|
12162
|
+
identifier: string().regex(GENERIC_WEBHOOK_IDENTIFIER_PATTERN).optional(),
|
|
12152
12163
|
topicMode: _enum(GENERIC_WEBHOOK_TOPIC_MODES),
|
|
12153
12164
|
topicId: string().min(1).optional()
|
|
12154
12165
|
}).strict();
|
|
@@ -16682,7 +16693,7 @@ const noopLogger$2 = {
|
|
|
16682
16693
|
info: () => {},
|
|
16683
16694
|
warn: () => {}
|
|
16684
16695
|
};
|
|
16685
|
-
const describeError$
|
|
16696
|
+
const describeError$2 = (error) => {
|
|
16686
16697
|
if (error && typeof error === "object") {
|
|
16687
16698
|
const { cause, code, message } = error;
|
|
16688
16699
|
const causeCode = cause && typeof cause === "object" ? cause.code : void 0;
|
|
@@ -16806,7 +16817,7 @@ var DeviceTunnelHost = class {
|
|
|
16806
16817
|
};
|
|
16807
16818
|
this.connections.set(connId, conn);
|
|
16808
16819
|
this.serve(conn, head, target).catch((error) => {
|
|
16809
|
-
this.logger.warn(`[tunnel] ${connId} failed: ${describeError$
|
|
16820
|
+
this.logger.warn(`[tunnel] ${connId} failed: ${describeError$2(error)}`);
|
|
16810
16821
|
});
|
|
16811
16822
|
}
|
|
16812
16823
|
async serve(conn, head, target) {
|
|
@@ -16878,7 +16889,7 @@ var DeviceTunnelHost = class {
|
|
|
16878
16889
|
this.dropConnection(conn.connId);
|
|
16879
16890
|
} catch (error) {
|
|
16880
16891
|
if (conn.closed) return;
|
|
16881
|
-
const reason = describeError$
|
|
16892
|
+
const reason = describeError$2(error);
|
|
16882
16893
|
if (!conn.headSent) this.loopback.forget(target.port);
|
|
16883
16894
|
if (conn.headSent) this.send({
|
|
16884
16895
|
connId: conn.connId,
|
|
@@ -56705,7 +56716,7 @@ const isUnknownCommitOutcome = (error) => {
|
|
|
56705
56716
|
};
|
|
56706
56717
|
/** Market's answer when a reused key carries a different request. */
|
|
56707
56718
|
const isIdempotencyConflict = (error) => error instanceof Error && error.message.includes("Idempotency key was already used");
|
|
56708
|
-
const fail$
|
|
56719
|
+
const fail$4 = (message) => {
|
|
56709
56720
|
log$15.error(message);
|
|
56710
56721
|
process.exit(1);
|
|
56711
56722
|
};
|
|
@@ -56717,7 +56728,7 @@ function registerArtifactCommand(program) {
|
|
|
56717
56728
|
const artifact = program.command("artifact").description("Publish local pages as artifacts");
|
|
56718
56729
|
artifact.command("guide <type>").description("Read the generation guide for an artifact type (canvas)").action(async (type) => {
|
|
56719
56730
|
if (type !== "canvas") {
|
|
56720
|
-
fail$
|
|
56731
|
+
fail$4("The supported guide type is canvas.");
|
|
56721
56732
|
return;
|
|
56722
56733
|
}
|
|
56723
56734
|
const { output } = await (await getTrpcClient()).canvas.runAgentTool.mutate({
|
|
@@ -56725,7 +56736,7 @@ function registerArtifactCommand(program) {
|
|
|
56725
56736
|
args: {}
|
|
56726
56737
|
});
|
|
56727
56738
|
if (!output.success) {
|
|
56728
|
-
fail$
|
|
56739
|
+
fail$4(String(output.content));
|
|
56729
56740
|
return;
|
|
56730
56741
|
}
|
|
56731
56742
|
console.log(output.content);
|
|
@@ -56734,35 +56745,35 @@ function registerArtifactCommand(program) {
|
|
|
56734
56745
|
const entryPath = path.resolve(file);
|
|
56735
56746
|
const rootDirectory = path.resolve(options.root ?? process.cwd());
|
|
56736
56747
|
if (!entryPath.startsWith(`${rootDirectory}${path.sep}`) && entryPath !== rootDirectory) {
|
|
56737
|
-
fail$
|
|
56748
|
+
fail$4(`${file} is outside ${rootDirectory}. Pass --root to widen the published directory.`);
|
|
56738
56749
|
return;
|
|
56739
56750
|
}
|
|
56740
56751
|
const entry = await readLocalHtmlAsset(entryPath);
|
|
56741
56752
|
if (!entry.ok || entry.text === void 0) {
|
|
56742
|
-
fail$
|
|
56753
|
+
fail$4(`Cannot read ${file}`);
|
|
56743
56754
|
return;
|
|
56744
56755
|
}
|
|
56745
56756
|
const manifest = resolveManifest(entryPath, rootDirectory);
|
|
56746
56757
|
const binding = readBinding(manifest);
|
|
56747
56758
|
const type = options.type ?? binding.pendingType ?? binding.type ?? "html";
|
|
56748
56759
|
if (type !== "html" && type !== "canvas") {
|
|
56749
|
-
fail$
|
|
56760
|
+
fail$4("Artifact type must be html or canvas.");
|
|
56750
56761
|
return;
|
|
56751
56762
|
}
|
|
56752
56763
|
if (options.new && options.deployment) {
|
|
56753
|
-
fail$
|
|
56764
|
+
fail$4("--new and --deployment cannot be combined.");
|
|
56754
56765
|
return;
|
|
56755
56766
|
}
|
|
56756
56767
|
if (binding.pendingType && binding.pendingType !== type) {
|
|
56757
|
-
fail$
|
|
56768
|
+
fail$4("Complete the pending publication before changing its type.");
|
|
56758
56769
|
return;
|
|
56759
56770
|
}
|
|
56760
56771
|
if (type === "canvas" && binding.pendingCreateKey && !binding.pendingCanvas) {
|
|
56761
|
-
fail$
|
|
56772
|
+
fail$4("Complete the pending HTML publication before changing its type.");
|
|
56762
56773
|
return;
|
|
56763
56774
|
}
|
|
56764
56775
|
if (!options.new && options.type && options.type !== (binding.pendingType ?? binding.type ?? "html") && (binding.deploymentId || binding.canvasId || binding.pendingCreateKey)) {
|
|
56765
|
-
fail$
|
|
56776
|
+
fail$4("Changing a bound artifact type requires --new.");
|
|
56766
56777
|
return;
|
|
56767
56778
|
}
|
|
56768
56779
|
if (type === "canvas") {
|
|
@@ -56790,7 +56801,7 @@ function registerArtifactCommand(program) {
|
|
|
56790
56801
|
error: formatError(error),
|
|
56791
56802
|
success: false
|
|
56792
56803
|
});
|
|
56793
|
-
fail$
|
|
56804
|
+
fail$4(pending ? `${formatError(error)}. ${pending.rejectedPublication ? "Correct the rejected slug and retry with the same content and target." : "Retry the same command with the original input to resume publication."}` : formatError(error));
|
|
56794
56805
|
}
|
|
56795
56806
|
return;
|
|
56796
56807
|
}
|
|
@@ -56801,11 +56812,11 @@ function registerArtifactCommand(program) {
|
|
|
56801
56812
|
workingDirectory: rootDirectory
|
|
56802
56813
|
});
|
|
56803
56814
|
if (gathered.blocked === "too-many") {
|
|
56804
|
-
fail$
|
|
56815
|
+
fail$4("This page references too many local files to publish (limit is 64).");
|
|
56805
56816
|
return;
|
|
56806
56817
|
}
|
|
56807
56818
|
if (gathered.blocked === "too-large") {
|
|
56808
|
-
fail$
|
|
56819
|
+
fail$4(`This page is too large to publish (${gathered.totalBytes} bytes, limit is 50MB).`);
|
|
56809
56820
|
return;
|
|
56810
56821
|
}
|
|
56811
56822
|
const packed = packWorkspaceHtmlDocument({
|
|
@@ -56813,7 +56824,7 @@ function registerArtifactCommand(program) {
|
|
|
56813
56824
|
files: gathered.files
|
|
56814
56825
|
});
|
|
56815
56826
|
if (packed.unresolvedHrefs.length > 0) {
|
|
56816
|
-
fail$
|
|
56827
|
+
fail$4(`Could not resolve local references: ${packed.unresolvedHrefs.join(", ")}`);
|
|
56817
56828
|
return;
|
|
56818
56829
|
}
|
|
56819
56830
|
warnList("Referenced files not found (widen with --root?)", gathered.missing);
|
|
@@ -56862,7 +56873,7 @@ function registerArtifactCommand(program) {
|
|
|
56862
56873
|
for (const uploadTarget of prepared.data.files) {
|
|
56863
56874
|
const source = entries.find((item) => item.path === uploadTarget.path);
|
|
56864
56875
|
if (!source) {
|
|
56865
|
-
fail$
|
|
56876
|
+
fail$4(`Server asked for an unknown file: ${uploadTarget.path}`);
|
|
56866
56877
|
return;
|
|
56867
56878
|
}
|
|
56868
56879
|
const response = await fetch(uploadTarget.uploadUrl, {
|
|
@@ -56871,7 +56882,7 @@ function registerArtifactCommand(program) {
|
|
|
56871
56882
|
method: "PUT"
|
|
56872
56883
|
});
|
|
56873
56884
|
if (!response.ok) {
|
|
56874
|
-
fail$
|
|
56885
|
+
fail$4(`Upload failed for ${uploadTarget.path}: ${response.status} ${response.statusText}`);
|
|
56875
56886
|
return;
|
|
56876
56887
|
}
|
|
56877
56888
|
}
|
|
@@ -56882,14 +56893,14 @@ function registerArtifactCommand(program) {
|
|
|
56882
56893
|
if (persistsBinding && isIdempotencyConflict(error)) {
|
|
56883
56894
|
const { pendingCreateFingerprint: _fingerprint, pendingCreateKey: _key, pendingType: _type, ...rest } = readBinding(manifest);
|
|
56884
56895
|
writeBinding(manifest, rest);
|
|
56885
|
-
fail$
|
|
56896
|
+
fail$4("An earlier unconfirmed publish of this file already went live with different content, so this version was not published. Run the command again to publish it.");
|
|
56886
56897
|
return;
|
|
56887
56898
|
}
|
|
56888
56899
|
if (!isUnknownCommitOutcome(error)) {
|
|
56889
|
-
fail$
|
|
56900
|
+
fail$4(formatError(error));
|
|
56890
56901
|
return;
|
|
56891
56902
|
}
|
|
56892
|
-
fail$
|
|
56903
|
+
fail$4(`${formatError(error).replace(/\.$/, "")}. Run the same command again to finish publishing; it will not create a second site.`);
|
|
56893
56904
|
return;
|
|
56894
56905
|
}
|
|
56895
56906
|
if (persistsBinding && result.data.id) writeBinding(manifest, { deploymentId: result.data.id });
|
|
@@ -56911,12 +56922,12 @@ function registerArtifactCommand(program) {
|
|
|
56911
56922
|
let deploymentId = options.deployment;
|
|
56912
56923
|
if (!deploymentId) {
|
|
56913
56924
|
if (!file) {
|
|
56914
|
-
fail$
|
|
56925
|
+
fail$4("Pass the published file, or --deployment <id>.");
|
|
56915
56926
|
return;
|
|
56916
56927
|
}
|
|
56917
56928
|
deploymentId = readBinding(resolveManifest(path.resolve(file), process.cwd())).deploymentId;
|
|
56918
56929
|
if (!deploymentId) {
|
|
56919
|
-
fail$
|
|
56930
|
+
fail$4(`${file} is not bound to a deployment. Pass --deployment <id> to unpublish one.`);
|
|
56920
56931
|
return;
|
|
56921
56932
|
}
|
|
56922
56933
|
}
|
|
@@ -56929,7 +56940,7 @@ function registerArtifactCommand(program) {
|
|
|
56929
56940
|
error: formatError(error),
|
|
56930
56941
|
success: false
|
|
56931
56942
|
});
|
|
56932
|
-
fail$
|
|
56943
|
+
fail$4(formatError(error));
|
|
56933
56944
|
return;
|
|
56934
56945
|
}
|
|
56935
56946
|
if (options.json !== void 0) {
|
|
@@ -56941,6 +56952,241 @@ function registerArtifactCommand(program) {
|
|
|
56941
56952
|
});
|
|
56942
56953
|
}
|
|
56943
56954
|
|
|
56955
|
+
//#endregion
|
|
56956
|
+
//#region src/commands/webhook/shared.ts
|
|
56957
|
+
const jsonFields = (options) => typeof options.json === "string" ? options.json : void 0;
|
|
56958
|
+
function fail$3(error) {
|
|
56959
|
+
log$15.error(error?.message ?? String(error));
|
|
56960
|
+
process.exit(1);
|
|
56961
|
+
}
|
|
56962
|
+
/** Run an action, turning a local or TRPC error into a CLI error and exit code 1. */
|
|
56963
|
+
const guarded = (fn) => async (...args) => {
|
|
56964
|
+
try {
|
|
56965
|
+
await fn(...args);
|
|
56966
|
+
} catch (error) {
|
|
56967
|
+
fail$3(error);
|
|
56968
|
+
}
|
|
56969
|
+
};
|
|
56970
|
+
const UUID_RE$2 = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
56971
|
+
const NOUN = {
|
|
56972
|
+
automation: "an automation",
|
|
56973
|
+
webhook: "a webhook"
|
|
56974
|
+
};
|
|
56975
|
+
/** Ids are uuids; anything else would come back as an unreadable validation error. */
|
|
56976
|
+
function assertInboundWebhookId(id, group) {
|
|
56977
|
+
if (!UUID_RE$2.test(id)) throw new Error(`"${id}" is not ${NOUN[group]} id. Find the id with: lh ${group} list`);
|
|
56978
|
+
}
|
|
56979
|
+
async function getInboundWebhook(client, id, group) {
|
|
56980
|
+
assertInboundWebhookId(id, group);
|
|
56981
|
+
return client.inboundWebhook.get.query({ id });
|
|
56982
|
+
}
|
|
56983
|
+
/** The `lh automation` command that does what `lh webhook <command>` was asked to. */
|
|
56984
|
+
const AUTOMATION_COMMAND = {
|
|
56985
|
+
delete: "delete",
|
|
56986
|
+
edit: "rename",
|
|
56987
|
+
view: "view"
|
|
56988
|
+
};
|
|
56989
|
+
/** The `lh webhook` command that does what `lh automation <command>` was asked to. */
|
|
56990
|
+
const WEBHOOK_COMMAND = {
|
|
56991
|
+
check: "test",
|
|
56992
|
+
delete: "delete",
|
|
56993
|
+
rename: "edit",
|
|
56994
|
+
view: "view"
|
|
56995
|
+
};
|
|
56996
|
+
/** A custom webhook's source; an MCP Events subscription is refused with `lh automation`. */
|
|
56997
|
+
function requireGeneric(item, command) {
|
|
56998
|
+
if (item.source.kind === "generic") return item.source;
|
|
56999
|
+
const instead = AUTOMATION_COMMAND[command] ?? "view";
|
|
57000
|
+
const usage = instead === "rename" ? `lh automation rename ${item.id} <name>` : `lh automation ${instead} ${item.id}`;
|
|
57001
|
+
throw new Error(`${item.id} is an automation (MCP Events subscription), not a custom webhook: use lh automation for it, e.g. ${usage}`);
|
|
57002
|
+
}
|
|
57003
|
+
/** An MCP Events subscription's source; a custom webhook is refused with `lh webhook`. */
|
|
57004
|
+
function requireMcpEvents(item, command) {
|
|
57005
|
+
if (item.source.kind === "mcp_events") return item.source;
|
|
57006
|
+
const instead = WEBHOOK_COMMAND[command] ?? "view";
|
|
57007
|
+
const usage = instead === "edit" ? `lh webhook edit ${item.id} --name <name>` : `lh webhook ${instead} ${item.id}`;
|
|
57008
|
+
throw new Error(`${item.id} is a custom webhook, not an automation (MCP Events subscription): use lh webhook for it, e.g. ${usage}`);
|
|
57009
|
+
}
|
|
57010
|
+
/** What each `lastError` means, in the words the Web uses. */
|
|
57011
|
+
const ERROR_TEXT = {
|
|
57012
|
+
access_revoked: "Access was revoked; the subscription ended. Delete it and ask the agent to resubscribe.",
|
|
57013
|
+
auth: "The connector's authorization has expired. Reconnect the connector.",
|
|
57014
|
+
challenge_failed: "The connector could not verify LobeHub's callback address.",
|
|
57015
|
+
channel_unavailable: "Run results could not be posted to the Channel: the agent or the creator left it, the agent is muted, or the Channel was archived or deleted.",
|
|
57016
|
+
connection_refused: "The connector could not connect to LobeHub to deliver events.",
|
|
57017
|
+
delivery_suspended: "The connector had paused delivery after repeated failures and was asked to resume. This clears when the next event arrives.",
|
|
57018
|
+
event_unavailable: "The connector no longer offers this event, so the subscription ended.",
|
|
57019
|
+
http_4xx: "LobeHub rejected the connector's deliveries.",
|
|
57020
|
+
http_5xx: "LobeHub failed while receiving the connector's deliveries.",
|
|
57021
|
+
insufficient_budget: "Not enough credits to run the agent. Later calls run once you top up.",
|
|
57022
|
+
server_unreachable: "Could not reach the connector's server.",
|
|
57023
|
+
timeout: "The connector timed out delivering events to LobeHub.",
|
|
57024
|
+
tls_error: "The connector could not open a secure connection to LobeHub.",
|
|
57025
|
+
unknown: "An error was reported without details.",
|
|
57026
|
+
wake_cap: "Calls arrived too often, so some runs in the last 10 minutes were skipped."
|
|
57027
|
+
};
|
|
57028
|
+
const describeError$1 = (error) => `${ERROR_TEXT[error] ?? "An error was reported."} (${error})`;
|
|
57029
|
+
const statusText = (status) => {
|
|
57030
|
+
switch (status) {
|
|
57031
|
+
case "active": return import_picocolors.default.green(status);
|
|
57032
|
+
case "paused": return import_picocolors.default.yellow(status);
|
|
57033
|
+
case "error": return import_picocolors.default.red(status);
|
|
57034
|
+
default: return import_picocolors.default.dim(status);
|
|
57035
|
+
}
|
|
57036
|
+
};
|
|
57037
|
+
const agentOf = (item) => item.agent ? item.agent.title || item.agent.id : "-";
|
|
57038
|
+
/** Where results go: "Channel X · Thread Y" when posted to a Channel, else the Topic. */
|
|
57039
|
+
const targetOf = (item) => {
|
|
57040
|
+
const delivery = item.source.delivery;
|
|
57041
|
+
if (delivery) {
|
|
57042
|
+
const channel = item.channel?.title || delivery.channelId;
|
|
57043
|
+
const threadId = item.channel?.threadId ?? delivery.threadId;
|
|
57044
|
+
if (!threadId) return `Channel ${channel}`;
|
|
57045
|
+
return `Channel ${channel} · Thread ${item.channel?.threadTitle || threadId}`;
|
|
57046
|
+
}
|
|
57047
|
+
if (item.source.kind === "generic") {
|
|
57048
|
+
if (item.source.topicMode === "new") return "New topic per call";
|
|
57049
|
+
const topic = item.topic?.title || item.source.topicId;
|
|
57050
|
+
return topic ? `One shared topic (${topic})` : "One shared topic";
|
|
57051
|
+
}
|
|
57052
|
+
return item.topic ? `Topic ${item.topic.title || item.topic.id}` : "-";
|
|
57053
|
+
};
|
|
57054
|
+
const lastDeliveryOf = (item) => item.lastDeliveryAt ? timeAgo(item.lastDeliveryAt) : "never";
|
|
57055
|
+
/** One `Label value` line of a details view. */
|
|
57056
|
+
const detailLine = (label, value) => console.log(`${import_picocolors.default.dim(label.padEnd(14))}${value}`);
|
|
57057
|
+
|
|
57058
|
+
//#endregion
|
|
57059
|
+
//#region src/commands/automation/format.ts
|
|
57060
|
+
/** An automation's display name; without one, the event it follows. */
|
|
57061
|
+
const titleOf$1 = (item) => item.name || item.identifier;
|
|
57062
|
+
const connectorOf = (item) => item.connector ? item.connector.name : "-";
|
|
57063
|
+
const filterOf = (source) => Object.keys(source.arguments).length > 0 ? JSON.stringify(source.arguments) : "";
|
|
57064
|
+
function printAutomationTable(items) {
|
|
57065
|
+
printTable(items.map((item) => [
|
|
57066
|
+
item.id,
|
|
57067
|
+
truncate$2(titleOf$1(item), 32),
|
|
57068
|
+
truncate$2(connectorOf(item), 20),
|
|
57069
|
+
truncate$2(item.identifier, 28),
|
|
57070
|
+
truncate$2(agentOf(item), 24),
|
|
57071
|
+
statusText(item.status),
|
|
57072
|
+
truncate$2(targetOf(item), 36),
|
|
57073
|
+
lastDeliveryOf(item)
|
|
57074
|
+
]), [
|
|
57075
|
+
"ID",
|
|
57076
|
+
"NAME",
|
|
57077
|
+
"CONNECTOR",
|
|
57078
|
+
"EVENT",
|
|
57079
|
+
"AGENT",
|
|
57080
|
+
"STATUS",
|
|
57081
|
+
"RESULTS TO",
|
|
57082
|
+
"LAST EVENT"
|
|
57083
|
+
]);
|
|
57084
|
+
}
|
|
57085
|
+
/** `source` is the item's own, already narrowed to a subscription by `requireMcpEvents`. */
|
|
57086
|
+
function printAutomationDetails(item, source) {
|
|
57087
|
+
console.log(import_picocolors.default.bold(titleOf$1(item)));
|
|
57088
|
+
detailLine("ID", item.id);
|
|
57089
|
+
detailLine("Name", item.name || import_picocolors.default.dim("(none: shows the event)"));
|
|
57090
|
+
detailLine("Event", `${item.identifier} ${import_picocolors.default.dim("(how the agent knows it; fixed)")}`);
|
|
57091
|
+
detailLine("Connector", item.connector ? `${item.connector.name} (${item.connector.identifier})` : import_picocolors.default.dim("(removed)"));
|
|
57092
|
+
detailLine("Filter", filterOf(source) || import_picocolors.default.dim("(none: every event)"));
|
|
57093
|
+
detailLine("Status", statusText(item.status));
|
|
57094
|
+
if (item.lastError) detailLine("Last error", import_picocolors.default.red(describeError$1(item.lastError)));
|
|
57095
|
+
detailLine("Agent", item.agent ? `${item.agent.title || "-"} (${item.agent.id})` : "-");
|
|
57096
|
+
if (source.delivery) {
|
|
57097
|
+
detailLine("Posts to", targetOf(item));
|
|
57098
|
+
if (!item.channel) detailLine("", import_picocolors.default.dim("(you cannot see this Channel)"));
|
|
57099
|
+
if (item.topic) detailLine("Runs in", `Topic ${item.topic.title || "-"} (${item.topic.id})`);
|
|
57100
|
+
} else detailLine("Results in", item.topic ? `Topic ${item.topic.title || "-"} (${item.topic.id})` : "-");
|
|
57101
|
+
detailLine("Expires", item.expiresAt ? timeUntil(item.expiresAt) : "never");
|
|
57102
|
+
detailLine("Last event", item.lastDeliveryAt ? formatTimestamp(item.lastDeliveryAt) : "never");
|
|
57103
|
+
detailLine("Created", formatTimestamp(item.createdAt));
|
|
57104
|
+
if (!item.canManage) detailLine("Access", import_picocolors.default.dim("view only"));
|
|
57105
|
+
}
|
|
57106
|
+
|
|
57107
|
+
//#endregion
|
|
57108
|
+
//#region src/commands/automation.ts
|
|
57109
|
+
/** Longest display name the server accepts. */
|
|
57110
|
+
const NAME_MAX = 100;
|
|
57111
|
+
/**
|
|
57112
|
+
* An automation: an MCP Events subscription. The same table holds custom webhooks; those are
|
|
57113
|
+
* refused here with the `lh webhook` command that handles them.
|
|
57114
|
+
*/
|
|
57115
|
+
async function getAutomation(client, id, command) {
|
|
57116
|
+
const item = await getInboundWebhook(client, id, "automation");
|
|
57117
|
+
return {
|
|
57118
|
+
item,
|
|
57119
|
+
source: requireMcpEvents(item, command)
|
|
57120
|
+
};
|
|
57121
|
+
}
|
|
57122
|
+
/** The new display name, or `null` to clear it so the event shows. */
|
|
57123
|
+
function nameInput(name, clear) {
|
|
57124
|
+
if (clear) {
|
|
57125
|
+
if (name !== void 0) throw new Error("Pass a new name or --clear, not both.");
|
|
57126
|
+
return null;
|
|
57127
|
+
}
|
|
57128
|
+
const trimmed = name?.trim();
|
|
57129
|
+
if (!trimmed) throw new Error("Pass the new name, or --clear to drop it and show the event. See: lh automation rename --help");
|
|
57130
|
+
if (trimmed.length > NAME_MAX) throw new Error(`The name is too long: at most ${NAME_MAX} characters.`);
|
|
57131
|
+
return trimmed;
|
|
57132
|
+
}
|
|
57133
|
+
function registerAutomationCommand(program) {
|
|
57134
|
+
const automation = program.command("automation").alias("automations").description("Manage automations: MCP Events subscriptions that run an agent on a connector event (an agent creates them in a conversation)");
|
|
57135
|
+
automation.command("list").description("List automations (MCP Events subscriptions)").option("--agent <agentId>", "Only this agent").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (options) => {
|
|
57136
|
+
const items = await (await getTrpcClient()).inboundWebhook.list.query({
|
|
57137
|
+
kind: "mcp_events",
|
|
57138
|
+
...options.agent && { agentId: options.agent }
|
|
57139
|
+
});
|
|
57140
|
+
if (options.json !== void 0) return outputJson(items, jsonFields(options));
|
|
57141
|
+
if (items.length === 0) {
|
|
57142
|
+
console.log("No automations found. To make one, ask an agent in a conversation to subscribe to a connector event.");
|
|
57143
|
+
return;
|
|
57144
|
+
}
|
|
57145
|
+
printAutomationTable(items);
|
|
57146
|
+
}));
|
|
57147
|
+
automation.command("view <id>").description("Show an automation: name, event, connector, filter, status, where results go, expiry").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, options) => {
|
|
57148
|
+
const { item, source } = await getAutomation(await getTrpcClient(), id, "view");
|
|
57149
|
+
if (options.json !== void 0) return outputJson(item, jsonFields(options));
|
|
57150
|
+
printAutomationDetails(item, source);
|
|
57151
|
+
}));
|
|
57152
|
+
automation.command("rename <id> [name]").description("Rename an automation for people; the event the agent knows it by stays. --clear shows the event again").option("--clear", "Drop the name; the automation shows its event").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, name, options) => {
|
|
57153
|
+
const nextName = nameInput(name, options.clear);
|
|
57154
|
+
const client = await getTrpcClient();
|
|
57155
|
+
await getAutomation(client, id, "rename");
|
|
57156
|
+
const item = await client.inboundWebhook.update.mutate({
|
|
57157
|
+
id,
|
|
57158
|
+
name: nextName
|
|
57159
|
+
});
|
|
57160
|
+
if (options.json !== void 0) return outputJson(item, jsonFields(options));
|
|
57161
|
+
console.log(nextName === null ? `${import_picocolors.default.green("✓")} Cleared the name: it shows as its event ${import_picocolors.default.bold(item.identifier)}` : `${import_picocolors.default.green("✓")} Renamed to ${import_picocolors.default.bold(titleOf$1(item))} ${import_picocolors.default.dim(`(event ${item.identifier}, unchanged)`)}`);
|
|
57162
|
+
}));
|
|
57163
|
+
automation.command("check <id>").description("Check an automation with its MCP server now, renewing or recovering it").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, options) => {
|
|
57164
|
+
const client = await getTrpcClient();
|
|
57165
|
+
await getAutomation(client, id, "check");
|
|
57166
|
+
const item = await client.inboundWebhook.check.mutate({ id });
|
|
57167
|
+
if (options.json !== void 0) return outputJson(item, jsonFields(options));
|
|
57168
|
+
if (item.status === "active" && !item.lastError) {
|
|
57169
|
+
console.log(`${import_picocolors.default.green("✓")} ${titleOf$1(item)}: the subscription is working.`);
|
|
57170
|
+
return;
|
|
57171
|
+
}
|
|
57172
|
+
console.log(`${import_picocolors.default.yellow("!")} ${titleOf$1(item)}: ${item.status}`);
|
|
57173
|
+
if (item.lastError) console.log(describeError$1(item.lastError));
|
|
57174
|
+
}));
|
|
57175
|
+
automation.command("delete <id>").description("Delete an automation; this also ends the subscription on its MCP server").option("--yes", "Skip confirmation prompt").action(guarded(async (id, options) => {
|
|
57176
|
+
const client = await getTrpcClient();
|
|
57177
|
+
const { item: current } = await getAutomation(client, id, "delete");
|
|
57178
|
+
const agent = current.agent?.title || "the agent";
|
|
57179
|
+
if (!options.yes) {
|
|
57180
|
+
if (!await confirm(`Delete the automation ${titleOf$1(current)}? This also ends it on the MCP server, so ${agent} no longer runs on these events. To get them again, ask the agent to subscribe in a conversation.`)) {
|
|
57181
|
+
console.log("Cancelled.");
|
|
57182
|
+
return;
|
|
57183
|
+
}
|
|
57184
|
+
}
|
|
57185
|
+
await client.inboundWebhook.delete.mutate({ id });
|
|
57186
|
+
console.log(`${import_picocolors.default.green("✓")} Deleted ${import_picocolors.default.bold(titleOf$1(current))} and ended the subscription on its MCP server`);
|
|
57187
|
+
}));
|
|
57188
|
+
}
|
|
57189
|
+
|
|
56944
57190
|
//#endregion
|
|
56945
57191
|
//#region src/commands/botMessage.ts
|
|
56946
57192
|
const inferMimeFromUrl = (path) => {
|
|
@@ -263593,6 +263839,36 @@ const getDefaultRemote = async (dirPath) => {
|
|
|
263593
263839
|
if (remotes.includes("origin")) return "origin";
|
|
263594
263840
|
return remotes[0];
|
|
263595
263841
|
};
|
|
263842
|
+
/**
|
|
263843
|
+
* git remote URL forms that name a GitHub repository: https (with or without
|
|
263844
|
+
* credentials), ssh://, and scp-like `git@github.com:owner/repo.git`.
|
|
263845
|
+
*/
|
|
263846
|
+
const GITHUB_REMOTE_RE = /^(?:https?:\/\/(?:[^@/\s]+@)?github\.com\/|ssh:\/\/(?:[^@/\s]+@)?github\.com(?::\d+)?\/|(?:[^@/\s]+@)?github\.com:)([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/i;
|
|
263847
|
+
/**
|
|
263848
|
+
* The remote a branch PUSHES to when it differs from where it pulls: a
|
|
263849
|
+
* triangular workflow tracks `origin` but publishes to a fork. Git resolves it
|
|
263850
|
+
* from `branch.<name>.pushRemote`, then `remote.pushDefault`; undefined when
|
|
263851
|
+
* neither is set (the upstream remote is then the push remote too).
|
|
263852
|
+
*/
|
|
263853
|
+
const getPushRemote = async (dirPath, branch) => {
|
|
263854
|
+
const read = async (key) => (await runGit([
|
|
263855
|
+
"config",
|
|
263856
|
+
"--get",
|
|
263857
|
+
key
|
|
263858
|
+
], dirPath))?.trim() || void 0;
|
|
263859
|
+
return (branch ? await read(`branch.${branch}.pushRemote`) : void 0) ?? read("remote.pushDefault");
|
|
263860
|
+
};
|
|
263861
|
+
/** `owner/repo` of a remote's GitHub push URL; undefined for any other host. */
|
|
263862
|
+
const getRemoteGithubRepo = async (dirPath, remote) => {
|
|
263863
|
+
const url = (await runGit([
|
|
263864
|
+
"remote",
|
|
263865
|
+
"get-url",
|
|
263866
|
+
"--push",
|
|
263867
|
+
remote
|
|
263868
|
+
], dirPath))?.trim();
|
|
263869
|
+
const match = url ? GITHUB_REMOTE_RE.exec(url) : null;
|
|
263870
|
+
return match ? `${match[1]}/${match[2]}` : void 0;
|
|
263871
|
+
};
|
|
263596
263872
|
/** Exit-status-only probe — `runGit` cannot tell success-with-no-output from failure. */
|
|
263597
263873
|
const gitSucceeds = async (args, cwd) => {
|
|
263598
263874
|
try {
|
|
@@ -263637,7 +263913,7 @@ const isCommitSafeForPullRequestLookup = async (dirPath, sha) => {
|
|
|
263637
263913
|
//#region ../../packages/local-file-shell/src/git/info.ts
|
|
263638
263914
|
const log$4 = createLogger("local-file-shell:git");
|
|
263639
263915
|
const execFileAsync$10 = promisify(execFile);
|
|
263640
|
-
const GITHUB_PULL_REQUEST_FIELDS = "number,url,title,state,isDraft,mergeable,mergeStateStatus,mergedAt,reviewDecision,statusCheckRollup,headRefName";
|
|
263916
|
+
const GITHUB_PULL_REQUEST_FIELDS = "number,url,title,state,isDraft,mergeable,mergeStateStatus,mergedAt,reviewDecision,statusCheckRollup,headRefName,headRepository,headRepositoryOwner";
|
|
263641
263917
|
const failureConclusions$1 = new Set([
|
|
263642
263918
|
"action_required",
|
|
263643
263919
|
"cancelled",
|
|
@@ -263684,8 +263960,14 @@ const normalizeGithubPullRequest = (pr) => {
|
|
|
263684
263960
|
const mergeable = compactString(pr.mergeable);
|
|
263685
263961
|
const mergeStateStatus = compactString(pr.mergeStateStatus);
|
|
263686
263962
|
const reviewDecision = compactString(pr.reviewDecision);
|
|
263963
|
+
const headRefName = compactString(pr.headRefName);
|
|
263964
|
+
const headOwner = pr.headRepositoryOwner?.login;
|
|
263965
|
+
const headName = pr.headRepository?.name;
|
|
263966
|
+
const headRepoFullName = headOwner && headName ? `${headOwner}/${headName}` : void 0;
|
|
263687
263967
|
return {
|
|
263688
263968
|
...ciStatus ? { ciStatus } : {},
|
|
263969
|
+
...headRefName ? { headRefName } : {},
|
|
263970
|
+
...headRepoFullName ? { headRepoFullName } : {},
|
|
263689
263971
|
...pr.isDraft === void 0 ? {} : { isDraft: pr.isDraft },
|
|
263690
263972
|
...mergeable ? { mergeable } : {},
|
|
263691
263973
|
...mergeStateStatus ? { mergeStateStatus } : {},
|
|
@@ -263788,7 +264070,7 @@ const toUpstreamRef = async (dirPath, branch, fallback) => {
|
|
|
263788
264070
|
* Returns `status: 'gh-missing'` when `gh` is unavailable / not authed.
|
|
263789
264071
|
*/
|
|
263790
264072
|
const getLinkedPullRequest = async (payload) => {
|
|
263791
|
-
const { path: dirPath, branch, pullRequestNumber } = payload;
|
|
264073
|
+
const { path: dirPath, branch, pullRequestNumber, state = "all" } = payload;
|
|
263792
264074
|
if (!branch && pullRequestNumber === void 0) return {
|
|
263793
264075
|
pullRequest: null,
|
|
263794
264076
|
status: "ok"
|
|
@@ -263811,14 +264093,20 @@ const getLinkedPullRequest = async (payload) => {
|
|
|
263811
264093
|
sha: void 0,
|
|
263812
264094
|
upstream: void 0
|
|
263813
264095
|
};
|
|
264096
|
+
const remote = await getPushRemote(dirPath, branch || void 0) ?? localUpstream?.remote ?? await getDefaultRemote(dirPath);
|
|
264097
|
+
const remoteRepoFullName = remote ? await getRemoteGithubRepo(dirPath, remote) : void 0;
|
|
264098
|
+
const answer = (result) => remoteRepoFullName ? {
|
|
264099
|
+
...result,
|
|
264100
|
+
remoteRepoFullName
|
|
264101
|
+
} : result;
|
|
263814
264102
|
if (pullRequestNumber !== void 0) {
|
|
263815
264103
|
const parsed = await viewPullRequest(pullRequestNumber);
|
|
263816
264104
|
const upstream = await toUpstreamRef(dirPath, parsed.headRefName, localUpstream);
|
|
263817
|
-
return {
|
|
264105
|
+
return answer({
|
|
263818
264106
|
pullRequest: normalizeGithubPullRequest(parsed),
|
|
263819
264107
|
status: "ok",
|
|
263820
264108
|
...upstream ? { upstream } : {}
|
|
263821
|
-
};
|
|
264109
|
+
});
|
|
263822
264110
|
}
|
|
263823
264111
|
const { stdout } = await execFileAsync$10("gh", [
|
|
263824
264112
|
"pr",
|
|
@@ -263826,7 +264114,7 @@ const getLinkedPullRequest = async (payload) => {
|
|
|
263826
264114
|
"--head",
|
|
263827
264115
|
localUpstream?.branch ?? branch,
|
|
263828
264116
|
"--state",
|
|
263829
|
-
|
|
264117
|
+
state,
|
|
263830
264118
|
"--limit",
|
|
263831
264119
|
"5",
|
|
263832
264120
|
"--json",
|
|
@@ -263839,29 +264127,29 @@ const getLinkedPullRequest = async (payload) => {
|
|
|
263839
264127
|
if (parsed.length > 0) {
|
|
263840
264128
|
const [primaryRaw, ...rest] = parsed;
|
|
263841
264129
|
const upstream = await toUpstreamRef(dirPath, primaryRaw.headRefName, localUpstream);
|
|
263842
|
-
return {
|
|
264130
|
+
return answer({
|
|
263843
264131
|
extraCount: rest.length,
|
|
263844
264132
|
pullRequest: normalizeGithubPullRequest(primaryRaw),
|
|
263845
264133
|
status: "ok",
|
|
263846
264134
|
...upstream ? { upstream } : {}
|
|
263847
|
-
};
|
|
264135
|
+
});
|
|
263848
264136
|
}
|
|
263849
264137
|
if (!localUpstream && sha && await isCommitSafeForPullRequestLookup(dirPath, sha)) {
|
|
263850
264138
|
const recovered = await findPullRequestByCommit(dirPath, sha);
|
|
263851
264139
|
if (recovered) {
|
|
263852
264140
|
const upstream = await toUpstreamRef(dirPath, recovered.headRefName);
|
|
263853
|
-
return {
|
|
264141
|
+
return answer({
|
|
263854
264142
|
pullRequest: normalizeGithubPullRequest(await viewPullRequest(recovered.number)),
|
|
263855
264143
|
status: "ok",
|
|
263856
264144
|
...upstream ? { upstream } : {}
|
|
263857
|
-
};
|
|
264145
|
+
});
|
|
263858
264146
|
}
|
|
263859
264147
|
}
|
|
263860
|
-
return {
|
|
264148
|
+
return answer({
|
|
263861
264149
|
pullRequest: null,
|
|
263862
264150
|
status: "ok",
|
|
263863
264151
|
...localUpstream ? { upstream: localUpstream } : {}
|
|
263864
|
-
};
|
|
264152
|
+
});
|
|
263865
264153
|
} catch (error) {
|
|
263866
264154
|
const code = error?.code;
|
|
263867
264155
|
const stderr = error?.stderr ?? "";
|
|
@@ -556112,7 +556400,7 @@ function deriveIdentifier(options) {
|
|
|
556112
556400
|
* token goes in `credentials`, custom headers in `metadata.customHeaders`, and
|
|
556113
556401
|
* OAuth2 writes no credentials (the OAuth callback stores the tokens).
|
|
556114
556402
|
*/
|
|
556115
|
-
function buildCreateInput(options) {
|
|
556403
|
+
function buildCreateInput$1(options) {
|
|
556116
556404
|
if (options.url && options.stdioCmd) throw new Error("Use either --url or --stdio-cmd, not both.");
|
|
556117
556405
|
if (!options.url && !options.stdioCmd) throw new Error("Provide --url <mcp url> or --stdio-cmd <command>.");
|
|
556118
556406
|
const authType = options.auth ?? (options.token ? "bearer" : "none");
|
|
@@ -556325,7 +556613,7 @@ function registerConnectorCommand(program) {
|
|
|
556325
556613
|
connector.command("add").description("Add a custom MCP connector and sync its tools").option("--url <url>", "MCP server URL (streamable HTTP / SSE)").option("--name <name>", "Display name (defaults to the identifier)").option("--identifier <id>", "Connector identifier (derived from --name or --url if omitted)").option("--auth <type>", "Auth type: none, bearer or oauth2").option("--token <token>", "Bearer token (with --auth bearer)").option("--header <key:value>", "Custom request header (repeatable)", collect$1, []).option("--stdio-cmd <command>", "stdio MCP server command").option("--stdio-arg <arg>", "stdio MCP server argument (repeatable)", collect$1, []).option("--force", "Overwrite an existing connector with the same identifier").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(async (options) => {
|
|
556326
556614
|
let built;
|
|
556327
556615
|
try {
|
|
556328
|
-
built = buildCreateInput(options);
|
|
556616
|
+
built = buildCreateInput$1(options);
|
|
556329
556617
|
} catch (error) {
|
|
556330
556618
|
fail$2(error);
|
|
556331
556619
|
}
|
|
@@ -590370,6 +590658,337 @@ function registerUserCommand(program) {
|
|
|
590370
590658
|
});
|
|
590371
590659
|
}
|
|
590372
590660
|
|
|
590661
|
+
//#endregion
|
|
590662
|
+
//#region src/commands/webhook/format.ts
|
|
590663
|
+
const DELIVERY_REASON_TEXT = {
|
|
590664
|
+
agent_start_failed: "The agent couldn't start; it will be retried",
|
|
590665
|
+
feature_disabled: "Webhooks are turned off for this account",
|
|
590666
|
+
insufficient_budget: "Not enough credits to run the agent",
|
|
590667
|
+
target_removed: "The agent was removed",
|
|
590668
|
+
topic_busy: "Waiting for the topic to finish its current run",
|
|
590669
|
+
wake_cap: "Skipped: over 30 runs in 10 minutes",
|
|
590670
|
+
webhook_paused: "Skipped: the webhook was paused",
|
|
590671
|
+
webhook_removed: "The webhook was deleted"
|
|
590672
|
+
};
|
|
590673
|
+
const DELIVERY_STATUS_TEXT = {
|
|
590674
|
+
failed: "Failed",
|
|
590675
|
+
ignored: "Skipped",
|
|
590676
|
+
pending: "Waiting",
|
|
590677
|
+
processed: "Ran"
|
|
590678
|
+
};
|
|
590679
|
+
/** A custom webhook's display name; without one, the identifier the agent knows it by. */
|
|
590680
|
+
const titleOf = (item) => item.name || item.identifier;
|
|
590681
|
+
function printWebhookTable(items) {
|
|
590682
|
+
printTable(items.map((item) => [
|
|
590683
|
+
item.id,
|
|
590684
|
+
truncate$2(titleOf(item), 32),
|
|
590685
|
+
truncate$2(item.identifier, 28),
|
|
590686
|
+
truncate$2(agentOf(item), 24),
|
|
590687
|
+
statusText(item.status),
|
|
590688
|
+
truncate$2(targetOf(item), 40),
|
|
590689
|
+
lastDeliveryOf(item)
|
|
590690
|
+
]), [
|
|
590691
|
+
"ID",
|
|
590692
|
+
"NAME",
|
|
590693
|
+
"IDENTIFIER",
|
|
590694
|
+
"AGENT",
|
|
590695
|
+
"STATUS",
|
|
590696
|
+
"TARGET",
|
|
590697
|
+
"LAST CALL"
|
|
590698
|
+
]);
|
|
590699
|
+
}
|
|
590700
|
+
/** How a system calls a custom webhook; `<key>` stands in for the key, which is never stored here. */
|
|
590701
|
+
const curlUsage = (endpoint) => [
|
|
590702
|
+
`curl -X POST ${endpoint} \\`,
|
|
590703
|
+
` -H "Authorization: Bearer <key>" \\`,
|
|
590704
|
+
` -H 'content-type: application/json' \\`,
|
|
590705
|
+
` -d '{"text":"Build #42 failed on main"}'`
|
|
590706
|
+
].join("\n");
|
|
590707
|
+
const USAGE_NOTES = [
|
|
590708
|
+
"Any body works (JSON, a form or plain text, up to 256 KB).",
|
|
590709
|
+
"Append ?thread=<key> to the URL (or send an X-Thread-Key header) to keep related calls in one topic.",
|
|
590710
|
+
"Send an Idempotency-Key header so a retried call runs once."
|
|
590711
|
+
];
|
|
590712
|
+
/** `source` is the item's own, already narrowed to a custom webhook by `requireGeneric`. */
|
|
590713
|
+
function printWebhookDetails(item, source) {
|
|
590714
|
+
console.log(import_picocolors.default.bold(titleOf(item)));
|
|
590715
|
+
detailLine("ID", item.id);
|
|
590716
|
+
detailLine("Name", item.name || import_picocolors.default.dim("(none: shows the identifier)"));
|
|
590717
|
+
detailLine("Identifier", `${item.identifier} ${import_picocolors.default.dim("(how the agent knows it; fixed)")}`);
|
|
590718
|
+
detailLine("Status", statusText(item.status));
|
|
590719
|
+
detailLine("Agent", item.agent ? `${item.agent.title || "-"} (${item.agent.id})` : "-");
|
|
590720
|
+
detailLine("Topic mode", source.topicMode === "new" ? "New topic per call" : "One shared topic");
|
|
590721
|
+
if (source.topicMode === "reuse") detailLine("Shared topic", item.topic?.title || source.topicId || "(made on the first call)");
|
|
590722
|
+
detailLine("Auto-approve", source.autoApprove ? "on: tools run without waiting for approval" : "off");
|
|
590723
|
+
if (source.delivery) {
|
|
590724
|
+
detailLine("Posts to", targetOf(item));
|
|
590725
|
+
if (!item.channel) detailLine("", import_picocolors.default.dim("(you cannot see this Channel)"));
|
|
590726
|
+
}
|
|
590727
|
+
if (item.instructions) detailLine("Instructions", item.instructions);
|
|
590728
|
+
detailLine("Last call", item.lastDeliveryAt ? formatTimestamp(item.lastDeliveryAt) : "never");
|
|
590729
|
+
if (item.lastError) detailLine("Last error", import_picocolors.default.red(describeError$1(item.lastError)));
|
|
590730
|
+
detailLine("Created", formatTimestamp(item.createdAt));
|
|
590731
|
+
if (!item.canManage) detailLine("Access", import_picocolors.default.dim("view only"));
|
|
590732
|
+
else if (!item.canConfigure) detailLine("Access", import_picocolors.default.dim("pause, resume or delete only: only its creator changes what it runs"));
|
|
590733
|
+
console.log();
|
|
590734
|
+
if (!item.endpoint) {
|
|
590735
|
+
detailLine("URL", import_picocolors.default.dim("(hidden: you cannot see this agent)"));
|
|
590736
|
+
return;
|
|
590737
|
+
}
|
|
590738
|
+
detailLine("URL", item.endpoint);
|
|
590739
|
+
console.log();
|
|
590740
|
+
console.log(import_picocolors.default.bold("Call it"));
|
|
590741
|
+
console.log(curlUsage(item.endpoint));
|
|
590742
|
+
for (const note of USAGE_NOTES) console.log(import_picocolors.default.dim(`- ${note}`));
|
|
590743
|
+
console.log(import_picocolors.default.dim(`- The key is shown only when the webhook is created or given a new key. Lost it? Run: lh webhook rotate-key ${item.id}`));
|
|
590744
|
+
}
|
|
590745
|
+
function printDeliveryTable(items) {
|
|
590746
|
+
printTable(items.map((call) => {
|
|
590747
|
+
const result = DELIVERY_STATUS_TEXT[call.status] ?? call.status;
|
|
590748
|
+
const reason = call.reason ? DELIVERY_REASON_TEXT[call.reason] || call.reason : "";
|
|
590749
|
+
const request = call.payloadPurged ? import_picocolors.default.dim("(content expired)") : call.preview || "";
|
|
590750
|
+
return [
|
|
590751
|
+
formatTimestamp(call.receivedAt),
|
|
590752
|
+
call.test ? `${result} ${import_picocolors.default.dim("(test)")}` : result,
|
|
590753
|
+
truncate$2(reason, 40),
|
|
590754
|
+
truncate$2(call.topic ? call.topic.title || call.topic.id : "-", 28),
|
|
590755
|
+
truncate$2(call.threadKey ? `[${call.threadKey}] ${request}` : request, 60)
|
|
590756
|
+
];
|
|
590757
|
+
}), [
|
|
590758
|
+
"RECEIVED",
|
|
590759
|
+
"RESULT",
|
|
590760
|
+
"REASON",
|
|
590761
|
+
"TOPIC",
|
|
590762
|
+
"REQUEST"
|
|
590763
|
+
]);
|
|
590764
|
+
}
|
|
590765
|
+
|
|
590766
|
+
//#endregion
|
|
590767
|
+
//#region src/commands/webhook/input.ts
|
|
590768
|
+
const TOPIC_MODES = ["new", "reuse"];
|
|
590769
|
+
const AUTO_APPROVE_REQUIRED = "Posting to a Channel needs --auto-approve: nobody can approve a tool call in a Channel, so those runs use tools without waiting for approval. Add --auto-approve to accept that.";
|
|
590770
|
+
function topicModeOf(value) {
|
|
590771
|
+
if (value === void 0) return void 0;
|
|
590772
|
+
if (!TOPIC_MODES.includes(value)) throw new Error(`Invalid --topic-mode "${value}". Expected one of: ${TOPIC_MODES.join(", ")}.`);
|
|
590773
|
+
return value;
|
|
590774
|
+
}
|
|
590775
|
+
function deliveryOf(channelId, threadId) {
|
|
590776
|
+
if (channelId.startsWith("cht_")) throw new Error(`${channelId} is a Thread id. Pass its Channel as --channel <chn_id> and the Thread as --thread ${channelId}.`);
|
|
590777
|
+
if (threadId?.startsWith("chn_")) throw new Error(`${threadId} is a Channel id. Pass it as --channel, and a Thread as --thread.`);
|
|
590778
|
+
return threadId ? {
|
|
590779
|
+
channelId,
|
|
590780
|
+
threadId
|
|
590781
|
+
} : { channelId };
|
|
590782
|
+
}
|
|
590783
|
+
/**
|
|
590784
|
+
* The Topic flags: `--topic` pins a shared Topic, so it implies `--topic-mode reuse`; asking for
|
|
590785
|
+
* a new Topic per call while pinning one is a contradiction the server would silently drop.
|
|
590786
|
+
*/
|
|
590787
|
+
function topicSettings(options, currentMode) {
|
|
590788
|
+
let topicMode = topicModeOf(options.topicMode);
|
|
590789
|
+
if (typeof options.topic === "string") {
|
|
590790
|
+
if (topicMode === "new") throw new Error("--topic picks the one shared topic, so it needs --topic-mode reuse.");
|
|
590791
|
+
if (!topicMode && currentMode !== "reuse") topicMode = "reuse";
|
|
590792
|
+
}
|
|
590793
|
+
return {
|
|
590794
|
+
...topicMode && { topicMode },
|
|
590795
|
+
...options.topic !== void 0 && { topicId: options.topic || null }
|
|
590796
|
+
};
|
|
590797
|
+
}
|
|
590798
|
+
/** Turn `lh webhook create` flags into a `inboundWebhook.create` input. */
|
|
590799
|
+
function buildCreateInput(agentId, options) {
|
|
590800
|
+
if (options.thread && !options.channel) throw new Error("--thread needs the Channel it belongs to: pass --channel <chn_id> too.");
|
|
590801
|
+
const delivery = options.channel ? deliveryOf(options.channel, options.thread) : void 0;
|
|
590802
|
+
if (delivery && !options.autoApprove) throw new Error(AUTO_APPROVE_REQUIRED);
|
|
590803
|
+
return {
|
|
590804
|
+
agentId,
|
|
590805
|
+
...options.name && { name: options.name },
|
|
590806
|
+
...options.instructions && { instructions: options.instructions },
|
|
590807
|
+
...topicSettings(options),
|
|
590808
|
+
...options.autoApprove && { autoApprove: true },
|
|
590809
|
+
...delivery && { delivery }
|
|
590810
|
+
};
|
|
590811
|
+
}
|
|
590812
|
+
/**
|
|
590813
|
+
* Turn `lh webhook edit` flags into the settings part of an `inboundWebhook.update` input. Only
|
|
590814
|
+
* the flags given change; `--no-name`, `--no-instructions`, `--no-topic` and `--no-channel` clear.
|
|
590815
|
+
* The current settings settle what the flags leave open: a `--thread` alone stays in the current
|
|
590816
|
+
* Channel, and auto-approval is checked against the delivery the webhook will have afterwards.
|
|
590817
|
+
* Renaming never changes the identifier the agent knows the webhook by.
|
|
590818
|
+
*/
|
|
590819
|
+
function buildUpdateInput(current, options) {
|
|
590820
|
+
let delivery;
|
|
590821
|
+
if (options.channel === false) {
|
|
590822
|
+
if (options.thread) throw new Error("--thread cannot be combined with --no-channel.");
|
|
590823
|
+
delivery = null;
|
|
590824
|
+
} else if (options.channel) delivery = deliveryOf(options.channel, options.thread);
|
|
590825
|
+
else if (options.thread) {
|
|
590826
|
+
if (!current.delivery) throw new Error("This webhook does not post to a Channel yet: pass --channel <chn_id> with --thread.");
|
|
590827
|
+
delivery = deliveryOf(current.delivery.channelId, options.thread);
|
|
590828
|
+
}
|
|
590829
|
+
const posts = delivery === void 0 ? !!current.delivery : !!delivery;
|
|
590830
|
+
const autoApprove = options.autoApprove ?? current.autoApprove;
|
|
590831
|
+
if (posts && !autoApprove) throw new Error(delivery ? AUTO_APPROVE_REQUIRED : "This webhook posts to a Channel, where nobody can approve a tool call, so it must keep auto-approval. Stop posting with --no-channel to turn auto-approval off.");
|
|
590832
|
+
const input = {
|
|
590833
|
+
...options.name !== void 0 && { name: options.name || null },
|
|
590834
|
+
...options.instructions !== void 0 && { instructions: options.instructions || null },
|
|
590835
|
+
...topicSettings(options, current.topicMode),
|
|
590836
|
+
...options.autoApprove !== void 0 && { autoApprove: options.autoApprove },
|
|
590837
|
+
...delivery !== void 0 && { delivery }
|
|
590838
|
+
};
|
|
590839
|
+
if (Object.keys(input).length === 0) throw new Error("Nothing to change. Pass at least one option; see: lh webhook edit --help");
|
|
590840
|
+
return input;
|
|
590841
|
+
}
|
|
590842
|
+
|
|
590843
|
+
//#endregion
|
|
590844
|
+
//#region src/commands/webhook.ts
|
|
590845
|
+
/**
|
|
590846
|
+
* A custom webhook. The same table holds MCP Events subscriptions, which are automations: those
|
|
590847
|
+
* are refused here with the `lh automation` command that handles them.
|
|
590848
|
+
*/
|
|
590849
|
+
async function getWebhook(client, id, command) {
|
|
590850
|
+
const item = await getInboundWebhook(client, id, "webhook");
|
|
590851
|
+
return {
|
|
590852
|
+
item,
|
|
590853
|
+
source: requireGeneric(item, command)
|
|
590854
|
+
};
|
|
590855
|
+
}
|
|
590856
|
+
function printKey(item, secret) {
|
|
590857
|
+
if (item.endpoint) console.log(`${import_picocolors.default.dim("URL".padEnd(6))}${item.endpoint}`);
|
|
590858
|
+
console.log(`${import_picocolors.default.dim("Key".padEnd(6))}${secret}`);
|
|
590859
|
+
console.log(import_picocolors.default.yellow("Store this key now: it won't be shown again. Callers send it as \"Authorization: Bearer <key>\"."));
|
|
590860
|
+
}
|
|
590861
|
+
function addSettingsOptions(command) {
|
|
590862
|
+
return command.option("--name <name>", "Display name; the identifier the agent knows the webhook by is made from it on create and never changes").option("--instructions <text>", "What the agent should do with each call").option("--topic-mode <mode>", "new: each run starts a new topic; reuse: every call continues one shared topic").option("--topic <topicId>", "The shared topic to continue (one of yours; implies reuse)").option("--auto-approve", "Run tools without waiting for approval").option("--channel <channelId>", "Post each run's answer to this Channel (chn_...); needs --auto-approve").option("--thread <threadId>", "Post to this Thread (cht_...) of the Channel instead");
|
|
590863
|
+
}
|
|
590864
|
+
function registerWebhookCommand(program) {
|
|
590865
|
+
const webhook = program.command("webhook").alias("webhooks").description("Manage custom webhooks: URLs any system calls to wake an agent (MCP Events subscriptions are under lh automation)");
|
|
590866
|
+
webhook.command("list").description("List custom webhooks").option("--agent <agentId>", "Only this agent").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (options) => {
|
|
590867
|
+
const items = await (await getTrpcClient()).inboundWebhook.list.query({
|
|
590868
|
+
kind: "generic",
|
|
590869
|
+
...options.agent && { agentId: options.agent }
|
|
590870
|
+
});
|
|
590871
|
+
if (options.json !== void 0) return outputJson(items, jsonFields(options));
|
|
590872
|
+
if (items.length === 0) {
|
|
590873
|
+
console.log("No webhooks found.");
|
|
590874
|
+
return;
|
|
590875
|
+
}
|
|
590876
|
+
printWebhookTable(items);
|
|
590877
|
+
}));
|
|
590878
|
+
webhook.command("view <id>").description("Show a custom webhook: name, identifier, settings, URL, how to call it, last error").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, options) => {
|
|
590879
|
+
const { item, source } = await getWebhook(await getTrpcClient(), id, "view");
|
|
590880
|
+
if (options.json !== void 0) return outputJson(item, jsonFields(options));
|
|
590881
|
+
printWebhookDetails(item, source);
|
|
590882
|
+
}));
|
|
590883
|
+
addSettingsOptions(webhook.command("create").description("Create a custom webhook for an agent and print its key (shown once)").requiredOption("--agent <agentId>", "Agent the webhook wakes")).option("--json [fields]", "Output JSON (includes the key as \"secret\")").action(guarded(async (options) => {
|
|
590884
|
+
const input = buildCreateInput(options.agent, options);
|
|
590885
|
+
const { item, secret } = await (await getTrpcClient()).inboundWebhook.create.mutate(input);
|
|
590886
|
+
if (options.json !== void 0) return outputJson({
|
|
590887
|
+
...item,
|
|
590888
|
+
secret
|
|
590889
|
+
}, jsonFields(options));
|
|
590890
|
+
console.log(`${import_picocolors.default.green("✓")} Created webhook ${import_picocolors.default.bold(titleOf(item))} ${import_picocolors.default.dim(`(${item.id})`)}`);
|
|
590891
|
+
console.log(`${import_picocolors.default.dim("Identifier".padEnd(12))}${item.identifier} ${import_picocolors.default.dim("(how the agent knows it; fixed)")}`);
|
|
590892
|
+
printKey(item, secret);
|
|
590893
|
+
if (item.source.delivery) console.log(`Each run's answer is posted to ${targetOf(item)}.`);
|
|
590894
|
+
if (item.endpoint) {
|
|
590895
|
+
console.log();
|
|
590896
|
+
console.log(curlUsage(item.endpoint));
|
|
590897
|
+
}
|
|
590898
|
+
console.log(import_picocolors.default.dim(`Details and calling options: lh webhook view ${item.id}`));
|
|
590899
|
+
}));
|
|
590900
|
+
addSettingsOptions(webhook.command("edit <id>").description("Change a custom webhook: its name (the identifier stays), what it runs and where results go")).option("--no-name", "Clear the name (the webhook then shows its identifier)").option("--no-instructions", "Clear the instructions").option("--no-topic", "Forget the picked shared topic (the webhook uses its own)").option("--no-auto-approve", "Wait for approval as your tool settings say").option("--no-channel", "Stop posting to a Channel").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, options) => {
|
|
590901
|
+
const client = await getTrpcClient();
|
|
590902
|
+
const { source } = await getWebhook(client, id, "edit");
|
|
590903
|
+
const changes = buildUpdateInput(source, options);
|
|
590904
|
+
const item = await client.inboundWebhook.update.mutate({
|
|
590905
|
+
id,
|
|
590906
|
+
...changes
|
|
590907
|
+
});
|
|
590908
|
+
if (options.json !== void 0) return outputJson(item, jsonFields(options));
|
|
590909
|
+
console.log(`${import_picocolors.default.green("✓")} Updated webhook ${import_picocolors.default.bold(titleOf(item))}`);
|
|
590910
|
+
console.log(`${import_picocolors.default.dim("Identifier".padEnd(12))}${item.identifier} ${import_picocolors.default.dim("(unchanged)")}`);
|
|
590911
|
+
console.log(`${import_picocolors.default.dim("Target".padEnd(12))}${targetOf(item)}`);
|
|
590912
|
+
}));
|
|
590913
|
+
const setPaused = (paused) => guarded(async (id, options) => {
|
|
590914
|
+
const client = await getTrpcClient();
|
|
590915
|
+
await getWebhook(client, id, paused ? "pause" : "resume");
|
|
590916
|
+
const item = await client.inboundWebhook.update.mutate({
|
|
590917
|
+
id,
|
|
590918
|
+
paused
|
|
590919
|
+
});
|
|
590920
|
+
if (options.json !== void 0) return outputJson(item, jsonFields(options));
|
|
590921
|
+
console.log(paused ? `${import_picocolors.default.green("✓")} Paused ${import_picocolors.default.bold(titleOf(item))}. Calls are refused until you resume it: lh webhook resume ${id}` : `${import_picocolors.default.green("✓")} Resumed ${import_picocolors.default.bold(titleOf(item))}. Calls wake the agent again.`);
|
|
590922
|
+
});
|
|
590923
|
+
webhook.command("pause <id>").description("Pause a custom webhook: calls are refused until it is resumed").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(setPaused(true));
|
|
590924
|
+
webhook.command("resume <id>").description("Resume a paused custom webhook").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(setPaused(false));
|
|
590925
|
+
webhook.command("rotate-key <id>").description("Issue a new key for a custom webhook; the old key stops working at once").option("--yes", "Skip confirmation prompt").option("--json [fields]", "Output JSON (includes the new key as \"secret\")").action(guarded(async (id, options) => {
|
|
590926
|
+
const client = await getTrpcClient();
|
|
590927
|
+
const { item: current } = await getWebhook(client, id, "rotate-key");
|
|
590928
|
+
if (!options.yes) {
|
|
590929
|
+
if (!await confirm(`Generate a new key for ${titleOf(current)}? The current key stops working right away; the URL stays the same, so every caller needs the new key.`)) {
|
|
590930
|
+
console.log("Cancelled.");
|
|
590931
|
+
return;
|
|
590932
|
+
}
|
|
590933
|
+
}
|
|
590934
|
+
const { item, secret } = await client.inboundWebhook.rotateToken.mutate({ id });
|
|
590935
|
+
if (options.json !== void 0) return outputJson({
|
|
590936
|
+
...item,
|
|
590937
|
+
secret
|
|
590938
|
+
}, jsonFields(options));
|
|
590939
|
+
console.log(`${import_picocolors.default.green("✓")} New key for ${import_picocolors.default.bold(titleOf(item))}`);
|
|
590940
|
+
printKey(item, secret);
|
|
590941
|
+
}));
|
|
590942
|
+
webhook.command("test <id>").description("Send a sample call to a custom webhook; the agent runs as it would for a caller").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, options) => {
|
|
590943
|
+
const client = await getTrpcClient();
|
|
590944
|
+
const { item: current } = await getWebhook(client, id, "test");
|
|
590945
|
+
if (current.status === "paused") throw new Error(`The webhook is paused. Resume it first: lh webhook resume ${id}`);
|
|
590946
|
+
const result = await client.inboundWebhook.sendTest.mutate({ id });
|
|
590947
|
+
if (options.json !== void 0) return outputJson(result, jsonFields(options));
|
|
590948
|
+
if (!result.accepted) throw new Error(`The test call was refused (HTTP ${result.status})${result.error ? `: ${result.error}` : ""}.`);
|
|
590949
|
+
console.log(`${import_picocolors.default.green("✓")} Test sent (HTTP ${result.status}). The agent will run shortly; follow it with: lh webhook calls ${id}`);
|
|
590950
|
+
}));
|
|
590951
|
+
webhook.command("calls <id>").description("List the calls a custom webhook received, newest first").option("-L, --limit <n>", "Maximum number of calls", "20").option("--all", "List every recorded call").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(guarded(async (id, options) => {
|
|
590952
|
+
const limit = options.all ? Infinity : Number.parseInt(options.limit, 10);
|
|
590953
|
+
if (!options.all && (!Number.isInteger(limit) || limit < 1)) throw new Error(`Invalid --limit "${options.limit}". Expected a positive number.`);
|
|
590954
|
+
const client = await getTrpcClient();
|
|
590955
|
+
await getWebhook(client, id, "calls");
|
|
590956
|
+
const calls = [];
|
|
590957
|
+
let cursor;
|
|
590958
|
+
let more = false;
|
|
590959
|
+
do {
|
|
590960
|
+
const page = await client.inboundWebhook.listDeliveries.query({
|
|
590961
|
+
id,
|
|
590962
|
+
...cursor && { cursor }
|
|
590963
|
+
});
|
|
590964
|
+
calls.push(...page.items);
|
|
590965
|
+
cursor = page.nextCursor;
|
|
590966
|
+
more = !!cursor || calls.length > limit;
|
|
590967
|
+
} while (cursor && calls.length < limit);
|
|
590968
|
+
const shown = calls.slice(0, limit);
|
|
590969
|
+
if (options.json !== void 0) return outputJson(shown, jsonFields(options));
|
|
590970
|
+
if (shown.length === 0) {
|
|
590971
|
+
console.log("No calls yet.");
|
|
590972
|
+
return;
|
|
590973
|
+
}
|
|
590974
|
+
printDeliveryTable(shown);
|
|
590975
|
+
if (more) console.log(import_picocolors.default.dim(`Showing the latest ${shown.length}. See more with --limit <n> or --all.`));
|
|
590976
|
+
}));
|
|
590977
|
+
webhook.command("delete <id>").description("Delete a custom webhook: its URL stops working at once").option("--yes", "Skip confirmation prompt").action(guarded(async (id, options) => {
|
|
590978
|
+
const client = await getTrpcClient();
|
|
590979
|
+
const { item: current } = await getWebhook(client, id, "delete");
|
|
590980
|
+
const agent = current.agent?.title || "the agent";
|
|
590981
|
+
if (!options.yes) {
|
|
590982
|
+
if (!await confirm(`Delete webhook ${titleOf(current)}? Its URL stops working at once and calls no longer wake ${agent}. This cannot be undone.`)) {
|
|
590983
|
+
console.log("Cancelled.");
|
|
590984
|
+
return;
|
|
590985
|
+
}
|
|
590986
|
+
}
|
|
590987
|
+
await client.inboundWebhook.delete.mutate({ id });
|
|
590988
|
+
console.log(`${import_picocolors.default.green("✓")} Deleted webhook ${import_picocolors.default.bold(titleOf(current))}`);
|
|
590989
|
+
}));
|
|
590990
|
+
}
|
|
590991
|
+
|
|
590373
590992
|
//#endregion
|
|
590374
590993
|
//#region src/commands/widget.ts
|
|
590375
590994
|
init_src$2();
|
|
@@ -591073,6 +591692,8 @@ function createProgram() {
|
|
|
591073
591692
|
registerWidgetCommand(program);
|
|
591074
591693
|
registerLegacyPluginCommand(program);
|
|
591075
591694
|
registerConnectorCommand(program);
|
|
591695
|
+
registerWebhookCommand(program);
|
|
591696
|
+
registerAutomationCommand(program);
|
|
591076
591697
|
registerWorkspaceCommand(program);
|
|
591077
591698
|
registerUserCommand(program);
|
|
591078
591699
|
registerVerifyCommand(program);
|