@wirecat/bitrix24-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/LICENSE +204 -0
- package/README.md +17 -2
- package/dist/api-keys.d.ts +21 -0
- package/dist/api-keys.d.ts.map +1 -0
- package/dist/api-keys.js +58 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/bin/b24.d.ts +3 -0
- package/dist/bin/b24.d.ts.map +1 -0
- package/dist/bin/b24.js +40 -0
- package/dist/bin/b24.js.map +1 -0
- package/dist/bitrix/errors.d.ts +22 -0
- package/dist/bitrix/errors.d.ts.map +1 -0
- package/dist/bitrix/errors.js +76 -0
- package/dist/bitrix/errors.js.map +1 -0
- package/dist/bitrix/methods.d.ts +13 -0
- package/dist/bitrix/methods.d.ts.map +1 -0
- package/dist/bitrix/methods.js +33 -0
- package/dist/bitrix/methods.js.map +1 -0
- package/dist/bitrix/transport.d.ts +50 -0
- package/dist/bitrix/transport.d.ts.map +1 -0
- package/dist/bitrix/transport.js +189 -0
- package/dist/bitrix/transport.js.map +1 -0
- package/dist/bitrix/webhook.d.ts +14 -0
- package/dist/bitrix/webhook.d.ts.map +1 -0
- package/dist/bitrix/webhook.js +29 -0
- package/dist/bitrix/webhook.js.map +1 -0
- package/dist/bundle/all-profiles-QJ444GSX.js +24 -0
- package/dist/bundle/anthropic-RHRAVHC2.js +70 -0
- package/dist/bundle/app-server-QIT6S7AZ.js +224 -0
- package/dist/bundle/b24.js +32 -0
- package/dist/bundle/bun-H6RSODZ3.js +169 -0
- package/dist/bundle/bun-sqlite-BO4LTQHX.js +69 -0
- package/dist/bundle/chunk-2KCZ7BKW.js +215 -0
- package/dist/bundle/chunk-2SNUMZ7S.js +1028 -0
- package/dist/bundle/chunk-45AKJVKV.js +24 -0
- package/dist/bundle/chunk-4PDYYS5K.js +2 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-6WY72XVQ.js +216 -0
- package/dist/bundle/chunk-7GRZAKBB.js +639 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-BCF7P4FZ.js +558 -0
- package/dist/bundle/chunk-CNNEA2M4.js +54 -0
- package/dist/bundle/chunk-CXL33BFL.js +570 -0
- package/dist/bundle/chunk-CZ23EVP4.js +1691 -0
- package/dist/bundle/chunk-D5S6QV6R.js +95 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DTXERR44.js +35 -0
- package/dist/bundle/chunk-EVYSBZ3I.js +153 -0
- package/dist/bundle/chunk-EXOOKUEA.js +82 -0
- package/dist/bundle/chunk-FLUEXJ4X.js +53 -0
- package/dist/bundle/chunk-FOTREPNS.js +366 -0
- package/dist/bundle/chunk-FZL7F5NR.js +2022 -0
- package/dist/bundle/chunk-H2ADPPSH.js +50910 -0
- package/dist/bundle/chunk-HAXNUIGQ.js +1245 -0
- package/dist/bundle/chunk-HGL63O5V.js +288 -0
- package/dist/bundle/chunk-INFYLWUA.js +929 -0
- package/dist/bundle/chunk-IRV2PCQ2.js +5213 -0
- package/dist/bundle/chunk-K3UIB6ZF.js +45 -0
- package/dist/bundle/chunk-LRGYKOCP.js +91 -0
- package/dist/bundle/chunk-LSPIOT6Z.js +459 -0
- package/dist/bundle/chunk-MBDK4YXG.js +34 -0
- package/dist/bundle/chunk-N6FLBXZS.js +73 -0
- package/dist/bundle/chunk-OTD2ZRXD.js +161 -0
- package/dist/bundle/chunk-P33NDCDI.js +78 -0
- package/dist/bundle/chunk-P364PLIK.js +257 -0
- package/dist/bundle/chunk-PH5FZX6E.js +193 -0
- package/dist/bundle/chunk-POC3V3AO.js +36616 -0
- package/dist/bundle/chunk-QC53QBNC.js +143 -0
- package/dist/bundle/chunk-QGMDQ2PM.js +122 -0
- package/dist/bundle/chunk-QIPTIUMJ.js +281 -0
- package/dist/bundle/chunk-QMPN6WKD.js +3512 -0
- package/dist/bundle/chunk-QQXH2OPB.js +594 -0
- package/dist/bundle/chunk-QSNROIJL.js +413 -0
- package/dist/bundle/chunk-RRJNNPR4.js +76 -0
- package/dist/bundle/chunk-SFRNX2TI.js +6848 -0
- package/dist/bundle/chunk-SGRYYE4X.js +266 -0
- package/dist/bundle/chunk-TE3FR6MI.js +884 -0
- package/dist/bundle/chunk-U5ACMCAQ.js +12049 -0
- package/dist/bundle/chunk-VEWWAGTD.js +2315 -0
- package/dist/bundle/chunk-VL6SPMZV.js +194 -0
- package/dist/bundle/chunk-WII44RXN.js +58 -0
- package/dist/bundle/chunk-WKRQ44EH.js +528 -0
- package/dist/bundle/chunk-WTPMJYMD.js +8308 -0
- package/dist/bundle/chunk-XD4FRDSL.js +565 -0
- package/dist/bundle/chunk-XJXONOB5.js +63 -0
- package/dist/bundle/chunk-XNHSPHUN.js +48 -0
- package/dist/bundle/chunk-XRFJWHY5.js +131 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YYO7D2MO.js +783 -0
- package/dist/bundle/chunk-YZ5LHE5Q.js +31 -0
- package/dist/bundle/chunk-ZDQQCXFG.js +392 -0
- package/dist/bundle/chunk-ZEW4P6AH.js +158 -0
- package/dist/bundle/chunk-ZGZT5S6B.js +3480 -0
- package/dist/bundle/chunk-ZIAQPTUS.js +82 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-OKQOE6G4.js +30 -0
- package/dist/bundle/decode-5ZPLTYV6.js +160 -0
- package/dist/bundle/dist-PII6Z6X3.js +7577 -0
- package/dist/bundle/echarts-J6LAPIX7.js +42501 -0
- package/dist/bundle/embed-YG5LDHME.js +35 -0
- package/dist/bundle/embedder-7FNUA5OZ.js +108 -0
- package/dist/bundle/first-run-JPZNWIJN.js +23 -0
- package/dist/bundle/first-screen-VQM4MTS7.js +28 -0
- package/dist/bundle/instructions-AXWTQHMR.js +11 -0
- package/dist/bundle/mcp-7F46P6AM.js +165 -0
- package/dist/bundle/mcp-J5R5A65I.js +87 -0
- package/dist/bundle/mcp-WALJM6QX.js +160 -0
- package/dist/bundle/node-CWKAIOEM.js +176 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-LSEKVRDA.js +67 -0
- package/dist/bundle/oauth-THYNLRLD.js +17 -0
- package/dist/bundle/open-E47QYKFC.js +20 -0
- package/dist/bundle/openai-EWSGC3BC.js +227 -0
- package/dist/bundle/process-WKTEA3WE.js +91 -0
- package/dist/bundle/program-GO3RVP2H.js +20847 -0
- package/dist/bundle/prompt-CAQ7QR3U.js +12 -0
- package/dist/bundle/recognize-6KGHNZC3.js +23 -0
- package/dist/bundle/remote-3UO2WDC3.js +26 -0
- package/dist/bundle/rerank-2JVDPZBX.js +49 -0
- package/dist/bundle/serve-ES7AG5IK.js +19 -0
- package/dist/bundle/server-5LE5LNUQ.js +45 -0
- package/dist/bundle/server-BU4VBM6S.js +58 -0
- package/dist/bundle/state-7NH5G4XJ.js +33 -0
- package/dist/bundle/store-7O4JQD2Z.js +127 -0
- package/dist/bundle/store-maintenance-command-UDVGEY2D.js +47 -0
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +130 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/crm-writes.d.ts +4 -0
- package/dist/commands/crm-writes.d.ts.map +1 -0
- package/dist/commands/crm-writes.js +182 -0
- package/dist/commands/crm-writes.js.map +1 -0
- package/dist/commands/crm.d.ts +3 -0
- package/dist/commands/crm.d.ts.map +1 -0
- package/dist/commands/crm.js +142 -0
- package/dist/commands/crm.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +74 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +97 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +101 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/write.d.ts +21 -0
- package/dist/commands/write.d.ts.map +1 -0
- package/dist/commands/write.js +47 -0
- package/dist/commands/write.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +17 -0
- package/dist/config.js.map +1 -0
- package/dist/crm/conditions.d.ts +25 -0
- package/dist/crm/conditions.d.ts.map +1 -0
- package/dist/crm/conditions.js +78 -0
- package/dist/crm/conditions.js.map +1 -0
- package/dist/crm/deal.d.ts +27 -0
- package/dist/crm/deal.d.ts.map +1 -0
- package/dist/crm/deal.js +76 -0
- package/dist/crm/deal.js.map +1 -0
- package/dist/crm/items.d.ts +30 -0
- package/dist/crm/items.d.ts.map +1 -0
- package/dist/crm/items.js +76 -0
- package/dist/crm/items.js.map +1 -0
- package/dist/crm/lead.d.ts +36 -0
- package/dist/crm/lead.d.ts.map +1 -0
- package/dist/crm/lead.js +86 -0
- package/dist/crm/lead.js.map +1 -0
- package/dist/crm/organization.d.ts +32 -0
- package/dist/crm/organization.d.ts.map +1 -0
- package/dist/crm/organization.js +68 -0
- package/dist/crm/organization.js.map +1 -0
- package/dist/crm/person.d.ts +31 -0
- package/dist/crm/person.d.ts.map +1 -0
- package/dist/crm/person.js +68 -0
- package/dist/crm/person.js.map +1 -0
- package/dist/crm/pipeline.d.ts +17 -0
- package/dist/crm/pipeline.d.ts.map +1 -0
- package/dist/crm/pipeline.js +42 -0
- package/dist/crm/pipeline.js.map +1 -0
- package/dist/crm/product.d.ts +43 -0
- package/dist/crm/product.d.ts.map +1 -0
- package/dist/crm/product.js +42 -0
- package/dist/crm/product.js.map +1 -0
- package/dist/crm/stage.d.ts +20 -0
- package/dist/crm/stage.d.ts.map +1 -0
- package/dist/crm/stage.js +65 -0
- package/dist/crm/stage.js.map +1 -0
- package/dist/crm/user.d.ts +39 -0
- package/dist/crm/user.d.ts.map +1 -0
- package/dist/crm/user.js +54 -0
- package/dist/crm/user.js.map +1 -0
- package/dist/crm/values.d.ts +30 -0
- package/dist/crm/values.d.ts.map +1 -0
- package/dist/crm/values.js +50 -0
- package/dist/crm/values.js.map +1 -0
- package/dist/crm/walk.d.ts +19 -0
- package/dist/crm/walk.d.ts.map +1 -0
- package/dist/crm/walk.js +22 -0
- package/dist/crm/walk.js.map +1 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +18 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +29 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +99 -0
- package/dist/mcp.js.map +1 -0
- package/dist/portal.d.ts +33 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +46 -0
- package/dist/portal.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +45 -0
- package/dist/program.js.map +1 -0
- package/dist/reasons.d.ts +10 -0
- package/dist/reasons.d.ts.map +1 -0
- package/dist/reasons.js +28 -0
- package/dist/reasons.js.map +1 -0
- package/dist/token.d.ts +12 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +41 -0
- package/dist/token.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/whoami.d.ts +8 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +9 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +83 -4
- package/skills/bitrix24-cli/SKILL.md +41 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { backoffMs, CliError, isCliError, realSleep, wallClock, } from "@wirecat/cli-base";
|
|
2
|
+
import { providerWaitMs, readJsonResponse } from "@wirecat/cli-base/http";
|
|
3
|
+
import { apiJson, currentAttempt, providerEvent, providerRequest } from "@wirecat/cli-core/cli";
|
|
4
|
+
import { bitrixError } from "./errors.js";
|
|
5
|
+
import { methodOf } from "./methods.js";
|
|
6
|
+
import { methodUrl } from "./webhook.js";
|
|
7
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
8
|
+
const LARGEST_ANSWER = 16 * 1024 * 1024;
|
|
9
|
+
const RETRY = { retries: 3, baseDelayMs: 1_000, maxDelayMs: 10_000, maxRetryAfterMs: 30_000 };
|
|
10
|
+
/** A pace wait longer than this ends the run instead of sitting in it, as cli-core's messenger pacing does. */
|
|
11
|
+
const LONGEST_PACE_WAIT_MS = 60_000;
|
|
12
|
+
/** A keyed write that never got an answer may have run: the caller repeats it with the same operation id. */
|
|
13
|
+
const lastOf = (method, error, reads) => reads || (error.code !== "timeout" && error.code !== "network_error")
|
|
14
|
+
? error
|
|
15
|
+
: new CliError("outcome_unknown", `${method} got no answer; repeat it with the same --operation-id, which Bitrix24 will not run twice`, { operation: method, retryable: true });
|
|
16
|
+
/**
|
|
17
|
+
* Bitrix24's REST API over an incoming webhook, method by method.
|
|
18
|
+
*
|
|
19
|
+
* ⚠ **The webhook's secret is part of every address** — `/rest/<user>/<secret>/<method>` — so the address never
|
|
20
|
+
* leaves this class: not in an error, not in a run record, and never by passing on a failed request's own error,
|
|
21
|
+
* whose text may hold it. Modelled on tg-cli's Bot API transport, which has the same problem.
|
|
22
|
+
*/
|
|
23
|
+
export class BitrixTransport {
|
|
24
|
+
#webhook;
|
|
25
|
+
#fetch;
|
|
26
|
+
#timeoutMs;
|
|
27
|
+
#signal;
|
|
28
|
+
#events;
|
|
29
|
+
#pacer;
|
|
30
|
+
#sleep;
|
|
31
|
+
#now;
|
|
32
|
+
#random;
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.#webhook = options.webhook;
|
|
35
|
+
this.#fetch = options.fetch ?? fetch;
|
|
36
|
+
this.#timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
37
|
+
this.#signal = options.signal;
|
|
38
|
+
this.#events = options.events;
|
|
39
|
+
this.#pacer = options.pacer;
|
|
40
|
+
this.#sleep = options.sleep ?? realSleep;
|
|
41
|
+
this.#now = options.now ?? Date.now;
|
|
42
|
+
this.#random = options.random ?? Math.random;
|
|
43
|
+
}
|
|
44
|
+
/** The employee the webhook acts as. */
|
|
45
|
+
get userId() {
|
|
46
|
+
return this.#webhook.userId;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reads are tried again on a refused rate or a lost answer. A write is tried again only on REST 3.0 with an
|
|
50
|
+
* `Idempotency-Key`, which Bitrix24 answers from its store instead of running twice; any other write that got no
|
|
51
|
+
* answer is `outcome_unknown`.
|
|
52
|
+
*/
|
|
53
|
+
async call(method, params = {}, options = {}) {
|
|
54
|
+
const known = methodOf(method);
|
|
55
|
+
const api = options.api ?? known.api;
|
|
56
|
+
const reads = known.effect === "read";
|
|
57
|
+
const key = api === 3 && !reads ? options.idempotencyKey : undefined;
|
|
58
|
+
const repeatable = reads || key !== undefined;
|
|
59
|
+
let waited;
|
|
60
|
+
for (let attempt = 1;; attempt++) {
|
|
61
|
+
try {
|
|
62
|
+
await this.#turn(method);
|
|
63
|
+
return await this.#once(method, params, { api, reads, key, attempt, waited });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (!isCliError(error) || !repeatable)
|
|
67
|
+
throw error;
|
|
68
|
+
const asked = error.details.retry_after_ms;
|
|
69
|
+
const wait = typeof asked === "number" ? asked : backoffMs(attempt, RETRY, this.#random);
|
|
70
|
+
const again = error.code === "rate_limited" || error.details.retryable === true;
|
|
71
|
+
if (!again || wait > RETRY.maxRetryAfterMs || attempt > RETRY.retries)
|
|
72
|
+
throw lastOf(method, error, reads);
|
|
73
|
+
if (error.code === "rate_limited")
|
|
74
|
+
await this.#pacer?.holdFor(wait);
|
|
75
|
+
await this.#wait(wait, method);
|
|
76
|
+
waited = wait;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async #turn(method) {
|
|
81
|
+
if (!this.#pacer)
|
|
82
|
+
return;
|
|
83
|
+
const at = await this.#pacer.reserve();
|
|
84
|
+
const wait = at - this.#now();
|
|
85
|
+
if (wait <= 0)
|
|
86
|
+
return;
|
|
87
|
+
if (wait > LONGEST_PACE_WAIT_MS)
|
|
88
|
+
throw new CliError("rate_limited", `this profile must wait ${Math.ceil(wait / 1000)} s before ${method}`, {
|
|
89
|
+
operation: method,
|
|
90
|
+
retry_after_ms: wait,
|
|
91
|
+
remembered: true,
|
|
92
|
+
});
|
|
93
|
+
await this.#wait(wait, method);
|
|
94
|
+
}
|
|
95
|
+
async #wait(ms, method) {
|
|
96
|
+
try {
|
|
97
|
+
await this.#sleep(ms, this.#signal, "retry");
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
throw new CliError("cancelled", `stopped while waiting to call ${method}`, { operation: method });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async #once(method, params, run) {
|
|
104
|
+
// Not AbortSignal.timeout: its timer holds the run's async context until the deadline (tg-cli, 2026-11-05).
|
|
105
|
+
const deadline = new AbortController();
|
|
106
|
+
const timer = setTimeout(() => deadline.abort(new DOMException(`${method} timed out`, "TimeoutError")), this.#timeoutMs);
|
|
107
|
+
timer.unref();
|
|
108
|
+
const end = providerRequest(method, this.#events ?? providerEvent, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
endpointTemplate: `/rest/${run.api === 3 ? "api/" : ""}:user/:token/${method}`,
|
|
111
|
+
transport: "http",
|
|
112
|
+
...(currentAttempt()
|
|
113
|
+
? {}
|
|
114
|
+
: { attempt: run.attempt, ...(run.waited === undefined ? {} : { waitMs: run.waited }) }),
|
|
115
|
+
});
|
|
116
|
+
const signal = AbortSignal.any([deadline.signal, ...(this.#signal ? [this.#signal] : [])]);
|
|
117
|
+
try {
|
|
118
|
+
let response;
|
|
119
|
+
try {
|
|
120
|
+
response = await this.#fetch(methodUrl(this.#webhook, run.api, method), {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: {
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
Accept: "application/json",
|
|
125
|
+
...(run.key ? { "Idempotency-Key": run.key } : {}),
|
|
126
|
+
},
|
|
127
|
+
body: apiJson(params),
|
|
128
|
+
// A redirect would carry the secret path to another host.
|
|
129
|
+
redirect: "error",
|
|
130
|
+
signal,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const failure = this.#unanswered(method, error, run.reads || run.key !== undefined);
|
|
135
|
+
end({ errorCode: failure.code });
|
|
136
|
+
throw failure;
|
|
137
|
+
}
|
|
138
|
+
let body;
|
|
139
|
+
try {
|
|
140
|
+
body = await readJsonResponse(response, { maxBytes: LARGEST_ANSWER, signal });
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (signal.aborted) {
|
|
144
|
+
const failure = this.#unanswered(method, error, run.reads || run.key !== undefined);
|
|
145
|
+
end({ status: response.status, errorCode: failure.code });
|
|
146
|
+
throw failure;
|
|
147
|
+
}
|
|
148
|
+
end({ status: response.status, errorCode: "invalid_response" });
|
|
149
|
+
if (!response.ok)
|
|
150
|
+
throw bitrixError(method, response.status, undefined);
|
|
151
|
+
throw new CliError("invalid_response", `Bitrix24 answered ${method} with something that is not JSON`, {
|
|
152
|
+
operation: method,
|
|
153
|
+
status: response.status,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const answer = (body ?? {});
|
|
157
|
+
if (!response.ok || answer.error !== undefined) {
|
|
158
|
+
const refusal = bitrixError(method, response.status, answer, {
|
|
159
|
+
now: this.#now(),
|
|
160
|
+
waitMs: providerWaitMs(response.headers, wallClock),
|
|
161
|
+
});
|
|
162
|
+
end({
|
|
163
|
+
status: response.status,
|
|
164
|
+
errorCode: refusal.code,
|
|
165
|
+
providerError: String(refusal.details.provider_error ?? ""),
|
|
166
|
+
});
|
|
167
|
+
throw refusal;
|
|
168
|
+
}
|
|
169
|
+
end({ status: response.status });
|
|
170
|
+
return {
|
|
171
|
+
result: answer.result,
|
|
172
|
+
...(typeof answer.total === "number" ? { total: answer.total } : {}),
|
|
173
|
+
...(typeof answer.next === "number" ? { next: answer.next } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
#unanswered(method, error, repeatable) {
|
|
181
|
+
if (this.#signal?.aborted && this.#signal.reason?.name !== "TimeoutError")
|
|
182
|
+
return new CliError("cancelled", `${method} was cancelled`, { operation: method });
|
|
183
|
+
if (!repeatable)
|
|
184
|
+
return new CliError("outcome_unknown", `${method} got no answer; Bitrix24 may or may not have carried it out — check before repeating it`, { operation: method, retryable: false });
|
|
185
|
+
const timedOut = error?.name === "TimeoutError";
|
|
186
|
+
return new CliError(timedOut ? "timeout" : "network_error", timedOut ? `${method} got no answer within ${this.#timeoutMs} ms` : `${method} could not reach Bitrix24`, { operation: method, retryable: true });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/bitrix/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,QAAQ,EACR,UAAU,EAEV,SAAS,EAET,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAkB,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE/G,OAAO,EAAsB,WAAW,EAAE,MAAM,aAAa,CAA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AI,KAAK,cAAc,CAAA;QACtE,OAAO,IAAI,QAAQ,CACjB,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,EACtC,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,yBAAyB,IAAI,CAAC,UAAU,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,2BAA2B,EACxG,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CACvC,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** An incoming webhook: the portal, the employee it acts as, and the secret that is the whole sign-in. */
|
|
2
|
+
export interface Webhook {
|
|
3
|
+
origin: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
secret: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Takes the address as Bitrix24 shows it, `https://<portal>/rest/<user>/<secret>/`, with or without a method or the
|
|
9
|
+
* REST 3.0 `api/` segment pasted after it. The text is never quoted back: the secret is part of it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const parseWebhook: (raw: string) => Webhook;
|
|
12
|
+
/** REST 2 lives at `/rest/`, REST 3.0 at `/rest/api/`; both take the same user and secret. */
|
|
13
|
+
export declare const methodUrl: (webhook: Webhook, api: 2 | 3, method: string) => string;
|
|
14
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/bitrix/webhook.ts"],"names":[],"mappings":"AAEA,0GAA0G;AAC1G,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAID;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,OAgB1C,CAAA;AAED,8FAA8F;AAC9F,eAAO,MAAM,SAAS,YAAa,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,MAAM,KAAG,MACyB,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
const PATH = /^\/rest\/(?:api\/)?(\d+)\/([A-Za-z0-9_-]+)(?:\/.*)?$/;
|
|
3
|
+
/**
|
|
4
|
+
* Takes the address as Bitrix24 shows it, `https://<portal>/rest/<user>/<secret>/`, with or without a method or the
|
|
5
|
+
* REST 3.0 `api/` segment pasted after it. The text is never quoted back: the secret is part of it.
|
|
6
|
+
*/
|
|
7
|
+
export const parseWebhook = (raw) => {
|
|
8
|
+
const refused = (why) => new CliError("validation_error", `that is not a Bitrix24 incoming webhook address: ${why}`, {
|
|
9
|
+
reason: "webhook.malformed",
|
|
10
|
+
});
|
|
11
|
+
let url;
|
|
12
|
+
try {
|
|
13
|
+
url = new URL(raw.trim());
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw refused("it is not a URL");
|
|
17
|
+
}
|
|
18
|
+
if (url.protocol !== "https:")
|
|
19
|
+
throw refused("it must start with https://");
|
|
20
|
+
if (url.username || url.password || url.search || url.hash)
|
|
21
|
+
throw refused("it carries more than the address");
|
|
22
|
+
const path = PATH.exec(url.pathname);
|
|
23
|
+
if (!path?.[1] || !path[2])
|
|
24
|
+
throw refused("its path is not /rest/<user id>/<secret>/");
|
|
25
|
+
return { origin: url.origin, userId: path[1], secret: path[2] };
|
|
26
|
+
};
|
|
27
|
+
/** REST 2 lives at `/rest/`, REST 3.0 at `/rest/api/`; both take the same user and secret. */
|
|
28
|
+
export const methodUrl = (webhook, api, method) => `${webhook.origin}/rest/${api === 3 ? "api/" : ""}${webhook.userId}/${webhook.secret}/${method}`;
|
|
29
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/bitrix/webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,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MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,IAAI,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CHILD_IDLE_MS,
|
|
5
|
+
allProfilesServer,
|
|
6
|
+
serveAllProfilesOverHttp,
|
|
7
|
+
serveAllProfilesOverStdio,
|
|
8
|
+
withProfile
|
|
9
|
+
} from "./chunk-QIPTIUMJ.js";
|
|
10
|
+
import "./chunk-RRJNNPR4.js";
|
|
11
|
+
import "./chunk-7GRZAKBB.js";
|
|
12
|
+
import "./chunk-FOTREPNS.js";
|
|
13
|
+
import "./chunk-5D4AEUVA.js";
|
|
14
|
+
import "./chunk-LRGYKOCP.js";
|
|
15
|
+
import "./chunk-IRV2PCQ2.js";
|
|
16
|
+
import "./chunk-Y5E2WNWB.js";
|
|
17
|
+
import "./chunk-ZVVMGPBJ.js";
|
|
18
|
+
export {
|
|
19
|
+
CHILD_IDLE_MS,
|
|
20
|
+
allProfilesServer,
|
|
21
|
+
serveAllProfilesOverHttp,
|
|
22
|
+
serveAllProfilesOverStdio,
|
|
23
|
+
withProfile
|
|
24
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
checkedOptions
|
|
5
|
+
} from "./chunk-YZ5LHE5Q.js";
|
|
6
|
+
import {
|
|
7
|
+
messagesFor,
|
|
8
|
+
systemFor
|
|
9
|
+
} from "./chunk-K3UIB6ZF.js";
|
|
10
|
+
import {
|
|
11
|
+
Anthropic
|
|
12
|
+
} from "./chunk-ADLS6FVG.js";
|
|
13
|
+
import {
|
|
14
|
+
array,
|
|
15
|
+
optional,
|
|
16
|
+
strictObject,
|
|
17
|
+
string
|
|
18
|
+
} from "./chunk-IRV2PCQ2.js";
|
|
19
|
+
import "./chunk-Y5E2WNWB.js";
|
|
20
|
+
import {
|
|
21
|
+
__name
|
|
22
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
23
|
+
|
|
24
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.586.0_@wirecat+cli-base@0.79.0_commander@15.0.0_esbuild@0.28.2_type_bdecddef0ae5a50ae90cab8b9e35c13b/node_modules/@wirecat/cli-core/dist/models/anthropic.js
|
|
25
|
+
var options = strictObject({
|
|
26
|
+
stop_sequences: optional(array(string()))
|
|
27
|
+
});
|
|
28
|
+
var anthropic = {
|
|
29
|
+
images: true,
|
|
30
|
+
baseUrl: "https://api.anthropic.com",
|
|
31
|
+
validate: /* @__PURE__ */ __name((given) => checkedOptions("anthropic", options, given), "validate"),
|
|
32
|
+
complete: /* @__PURE__ */ __name(async (target, request, checked, apiKey, fetcher) => {
|
|
33
|
+
const client = new Anthropic({
|
|
34
|
+
apiKey: apiKey ?? "",
|
|
35
|
+
authToken: null,
|
|
36
|
+
fetch: /* @__PURE__ */ __name((input, init) => fetcher(input, { ...init, redirect: "error" }), "fetch"),
|
|
37
|
+
baseURL: target.baseUrl,
|
|
38
|
+
maxRetries: 0,
|
|
39
|
+
logLevel: "off",
|
|
40
|
+
timeout: 12e4
|
|
41
|
+
});
|
|
42
|
+
const response = await client.messages.stream({
|
|
43
|
+
...checked,
|
|
44
|
+
model: target.model,
|
|
45
|
+
system: systemFor(request),
|
|
46
|
+
messages: [
|
|
47
|
+
...messagesFor(request),
|
|
48
|
+
...request.images === void 0 ? [] : [
|
|
49
|
+
{
|
|
50
|
+
role: "user",
|
|
51
|
+
content: request.images.map((image) => ({
|
|
52
|
+
type: "image",
|
|
53
|
+
source: { type: "base64", media_type: image.mimeType, data: image.data }
|
|
54
|
+
}))
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
],
|
|
58
|
+
max_tokens: request.maxTokens
|
|
59
|
+
}).finalMessage();
|
|
60
|
+
if (response.stop_reason !== "end_turn")
|
|
61
|
+
throw new Error("incomplete response");
|
|
62
|
+
return {
|
|
63
|
+
text: response.content.filter((block) => block.type === "text").map((block) => block.text).join(""),
|
|
64
|
+
tokens: response.usage.input_tokens + response.usage.output_tokens + (response.usage.cache_creation_input_tokens ?? 0) + (response.usage.cache_read_input_tokens ?? 0)
|
|
65
|
+
};
|
|
66
|
+
}, "complete")
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
anthropic
|
|
70
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
PER_RUN,
|
|
5
|
+
envelope
|
|
6
|
+
} from "./chunk-YYO7D2MO.js";
|
|
7
|
+
import "./chunk-HAXNUIGQ.js";
|
|
8
|
+
import {
|
|
9
|
+
mcpUrlOf
|
|
10
|
+
} from "./chunk-XNHSPHUN.js";
|
|
11
|
+
import {
|
|
12
|
+
answeredWire
|
|
13
|
+
} from "./chunk-RRJNNPR4.js";
|
|
14
|
+
import {
|
|
15
|
+
answered,
|
|
16
|
+
failed,
|
|
17
|
+
registerCommands,
|
|
18
|
+
runCommandForAgent,
|
|
19
|
+
toolsFromCommands
|
|
20
|
+
} from "./chunk-QMPN6WKD.js";
|
|
21
|
+
import {
|
|
22
|
+
agentJson,
|
|
23
|
+
skillResource
|
|
24
|
+
} from "./chunk-WKRQ44EH.js";
|
|
25
|
+
import {
|
|
26
|
+
StdioServerTransport,
|
|
27
|
+
serveStdio
|
|
28
|
+
} from "./chunk-7GRZAKBB.js";
|
|
29
|
+
import "./chunk-FZL7F5NR.js";
|
|
30
|
+
import "./chunk-POC3V3AO.js";
|
|
31
|
+
import "./chunk-ZDQQCXFG.js";
|
|
32
|
+
import "./chunk-XRFJWHY5.js";
|
|
33
|
+
import {
|
|
34
|
+
DEFAULT_OUTPUT_BYTES,
|
|
35
|
+
changesAuthorityAt,
|
|
36
|
+
describeProgram,
|
|
37
|
+
environmentOf,
|
|
38
|
+
judgedTargets,
|
|
39
|
+
readOnlyLockOf,
|
|
40
|
+
readsOverMcpAt,
|
|
41
|
+
rootOf2 as rootOf
|
|
42
|
+
} from "./chunk-U5ACMCAQ.js";
|
|
43
|
+
import "./chunk-FOTREPNS.js";
|
|
44
|
+
import "./chunk-EVYSBZ3I.js";
|
|
45
|
+
import "./chunk-CXL33BFL.js";
|
|
46
|
+
import "./chunk-CNNEA2M4.js";
|
|
47
|
+
import {
|
|
48
|
+
appInstructions
|
|
49
|
+
} from "./chunk-FLUEXJ4X.js";
|
|
50
|
+
import {
|
|
51
|
+
McpServer
|
|
52
|
+
} from "./chunk-5D4AEUVA.js";
|
|
53
|
+
import {
|
|
54
|
+
mcpHttpMarker
|
|
55
|
+
} from "./chunk-OTD2ZRXD.js";
|
|
56
|
+
import "./chunk-N6FLBXZS.js";
|
|
57
|
+
import "./chunk-XJXONOB5.js";
|
|
58
|
+
import "./chunk-QGMDQ2PM.js";
|
|
59
|
+
import "./chunk-2SNUMZ7S.js";
|
|
60
|
+
import "./chunk-SGRYYE4X.js";
|
|
61
|
+
import "./chunk-K3UIB6ZF.js";
|
|
62
|
+
import "./chunk-QSNROIJL.js";
|
|
63
|
+
import "./chunk-BCF7P4FZ.js";
|
|
64
|
+
import "./chunk-XD4FRDSL.js";
|
|
65
|
+
import "./chunk-EXOOKUEA.js";
|
|
66
|
+
import "./chunk-H2ADPPSH.js";
|
|
67
|
+
import "./chunk-P364PLIK.js";
|
|
68
|
+
import "./chunk-VEWWAGTD.js";
|
|
69
|
+
import "./chunk-TE3FR6MI.js";
|
|
70
|
+
import "./chunk-DTXERR44.js";
|
|
71
|
+
import "./chunk-QQXH2OPB.js";
|
|
72
|
+
import "./chunk-ZGZT5S6B.js";
|
|
73
|
+
import "./chunk-LRGYKOCP.js";
|
|
74
|
+
import "./chunk-D5S6QV6R.js";
|
|
75
|
+
import "./chunk-MBDK4YXG.js";
|
|
76
|
+
import {
|
|
77
|
+
CliError,
|
|
78
|
+
mcpErrorResult
|
|
79
|
+
} from "./chunk-IRV2PCQ2.js";
|
|
80
|
+
import "./chunk-Y5E2WNWB.js";
|
|
81
|
+
import "./chunk-SFRNX2TI.js";
|
|
82
|
+
import {
|
|
83
|
+
__name
|
|
84
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
85
|
+
|
|
86
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.586.0_@wirecat+cli-base@0.79.0_commander@15.0.0_esbuild@0.28.2_type_bdecddef0ae5a50ae90cab8b9e35c13b/node_modules/@wirecat/cli-core/dist/mcp/app-server.js
|
|
87
|
+
var EXCLUDED = [["mcp"]];
|
|
88
|
+
var createAppServer = /* @__PURE__ */ __name((command, context, options) => {
|
|
89
|
+
const { app } = options;
|
|
90
|
+
const root = rootOf(command);
|
|
91
|
+
const environment = environmentOf(command);
|
|
92
|
+
if (!environment.runCommand)
|
|
93
|
+
throw new Error("the MCP server runs inside run(), which hands it the program");
|
|
94
|
+
const program = { run: environment.runCommand, commands: describeProgram(root) };
|
|
95
|
+
const flags = command.optsWithGlobals();
|
|
96
|
+
const overrides = flags.permission ?? [];
|
|
97
|
+
const { settings } = context;
|
|
98
|
+
const levels = /* @__PURE__ */ __name(() => options.resolveSettings(flags, { env: context.env }).permissions, "levels");
|
|
99
|
+
const readOnly = /* @__PURE__ */ __name(() => readOnlyLockOf(app, context.env) !== void 0, "readOnly");
|
|
100
|
+
const authority = changesAuthorityAt(root);
|
|
101
|
+
const targets = judgedTargets(root);
|
|
102
|
+
const passed = Object.fromEntries(Object.entries(environment).filter(([key]) => !PER_RUN.has(key)));
|
|
103
|
+
const tools = toolsFromCommands(program.commands, {
|
|
104
|
+
includeUnavailable: true,
|
|
105
|
+
exclude: EXCLUDED,
|
|
106
|
+
levels: settings.permissions,
|
|
107
|
+
currentLevels: levels,
|
|
108
|
+
readOnly: readOnly(),
|
|
109
|
+
authority,
|
|
110
|
+
fetchOnly: readsOverMcpAt(root),
|
|
111
|
+
permissions: options.permissions
|
|
112
|
+
});
|
|
113
|
+
const availability = /* @__PURE__ */ __name((one) => () => {
|
|
114
|
+
const permitted = one.availability?.() ?? { available: true };
|
|
115
|
+
if (!permitted.available)
|
|
116
|
+
return permitted;
|
|
117
|
+
return options.availability?.(one.path, settings.profile) ?? permitted;
|
|
118
|
+
}, "availability");
|
|
119
|
+
const commands = Object.fromEntries(tools.map((one) => [
|
|
120
|
+
one.command,
|
|
121
|
+
{
|
|
122
|
+
title: one.title,
|
|
123
|
+
description: one.description,
|
|
124
|
+
writes: one.writes,
|
|
125
|
+
availability: availability(one),
|
|
126
|
+
input: one.input,
|
|
127
|
+
run: /* @__PURE__ */ __name(async (input, ctx) => {
|
|
128
|
+
const own = options.availability?.(one.path, settings.profile);
|
|
129
|
+
if (own && !own.available)
|
|
130
|
+
return failed(new CliError("permission_error", `${one.command}: ${own.reason ?? "unavailable for this profile"}`, {
|
|
131
|
+
...own.permission ? { permission: own.permission } : {}
|
|
132
|
+
}), app.errors);
|
|
133
|
+
const traceparent = ctx?.mcpReq?._meta?.traceparent;
|
|
134
|
+
const env = typeof traceparent === "string" ? { ...context.env, TRACEPARENT: traceparent } : context.env;
|
|
135
|
+
const answer = await runCommandForAgent(program, one.path, input, {
|
|
136
|
+
profile: settings.profile,
|
|
137
|
+
readOnly: readOnly(),
|
|
138
|
+
env,
|
|
139
|
+
levels,
|
|
140
|
+
overrides,
|
|
141
|
+
authority,
|
|
142
|
+
permissions: options.permissions,
|
|
143
|
+
environment: passed
|
|
144
|
+
});
|
|
145
|
+
if ("error" in answer)
|
|
146
|
+
return mcpErrorResult(JSON.parse(agentJson(answer.error)));
|
|
147
|
+
try {
|
|
148
|
+
return answered(envelope(one.command, answer.result), DEFAULT_OUTPUT_BYTES, targets);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return failed(error, app.errors);
|
|
151
|
+
}
|
|
152
|
+
}, "run")
|
|
153
|
+
}
|
|
154
|
+
]));
|
|
155
|
+
const skill = options.skill ? skillResource(app, options.skill) : void 0;
|
|
156
|
+
const build = /* @__PURE__ */ __name(() => {
|
|
157
|
+
const server = new McpServer({ name: app.command, version: app.version }, {
|
|
158
|
+
instructions: appInstructions({
|
|
159
|
+
command: app.command,
|
|
160
|
+
name: options.name,
|
|
161
|
+
profile: settings.profile,
|
|
162
|
+
untrusted: options.untrusted,
|
|
163
|
+
...skill ? { skill: skill.instruction } : {}
|
|
164
|
+
})
|
|
165
|
+
});
|
|
166
|
+
registerCommands(server, app.command, commands, app.errors, void 0, app.messenger);
|
|
167
|
+
if (skill) {
|
|
168
|
+
const { uri, name, title, description, mimeType, read } = skill;
|
|
169
|
+
server.registerResource(name, uri, { title, description, mimeType }, read);
|
|
170
|
+
}
|
|
171
|
+
return server;
|
|
172
|
+
}, "build");
|
|
173
|
+
return { build, offered: Object.keys(commands) };
|
|
174
|
+
}, "createAppServer");
|
|
175
|
+
var serveAppOverStdio = /* @__PURE__ */ __name(async (command, context, options) => {
|
|
176
|
+
const { build } = createAppServer(command, context, options);
|
|
177
|
+
const { stdin, stdout, signal } = environmentOf(command);
|
|
178
|
+
const own = stdin && stdout && stdin !== process.stdin;
|
|
179
|
+
const wire = answeredWire(own ? stdin : process.stdin, own ? stdout : process.stdout);
|
|
180
|
+
const handle = serveStdio(build, {
|
|
181
|
+
transport: new StdioServerTransport(wire.input, wire.output),
|
|
182
|
+
onerror: /* @__PURE__ */ __name((error) => context.renderer.note(`mcp: ${error.message}`), "onerror")
|
|
183
|
+
});
|
|
184
|
+
const ended = await new Promise((resolve) => {
|
|
185
|
+
wire.ended.then(() => resolve("input"));
|
|
186
|
+
if (own)
|
|
187
|
+
signal?.addEventListener("abort", () => resolve("stopped"), { once: true });
|
|
188
|
+
else {
|
|
189
|
+
process.once("SIGINT", () => resolve("stopped"));
|
|
190
|
+
process.once("SIGTERM", () => resolve("stopped"));
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
if (ended === "input")
|
|
194
|
+
await wire.answered();
|
|
195
|
+
wire.release();
|
|
196
|
+
await handle.close();
|
|
197
|
+
}, "serveAppOverStdio");
|
|
198
|
+
var serveAppOverHttp = /* @__PURE__ */ __name(async (command, context, options, http) => {
|
|
199
|
+
const { app } = options;
|
|
200
|
+
const { build } = createAppServer(command, context, options);
|
|
201
|
+
const { serveOverHttp } = await import("./serve-ES7AG5IK.js");
|
|
202
|
+
const listening = await serveOverHttp(build, {
|
|
203
|
+
...http,
|
|
204
|
+
appName: app.command,
|
|
205
|
+
reaches: `your ${options.name}`,
|
|
206
|
+
onCode: /* @__PURE__ */ __name((code, expires) => context.renderer.note(context.env[mcpHttpMarker(app.envPrefix)] === void 0 ? `login code for a new browser app: ${code} (until ${expires.toTimeString().slice(0, 5)}; a new one after each login)` : `a new login code for a browser app: \`${app.command} ${context.settings.profile} mcp server status\``), "onCode"),
|
|
207
|
+
onError: /* @__PURE__ */ __name((error) => context.renderer.note(`mcp: ${error.message}`), "onError")
|
|
208
|
+
}).catch((error) => {
|
|
209
|
+
if (error.code === "EADDRINUSE")
|
|
210
|
+
throw new CliError("configuration_error", `port ${http.port} is in use \u2014 pass another with --port`);
|
|
211
|
+
throw error;
|
|
212
|
+
});
|
|
213
|
+
context.renderer.note(`serving on ${listening.url.href} \u2014 point your tunnel at it; connectors use ${mcpUrlOf(http.publicUrl).href}`);
|
|
214
|
+
await new Promise((resolve) => {
|
|
215
|
+
process.once("SIGINT", resolve);
|
|
216
|
+
process.once("SIGTERM", resolve);
|
|
217
|
+
});
|
|
218
|
+
await listening.close();
|
|
219
|
+
}, "serveAppOverHttp");
|
|
220
|
+
export {
|
|
221
|
+
createAppServer,
|
|
222
|
+
serveAppOverHttp,
|
|
223
|
+
serveAppOverStdio
|
|
224
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
3
|
+
const require = __bundleRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
IDENTITY
|
|
6
|
+
} from "./chunk-CZ23EVP4.js";
|
|
7
|
+
import "./chunk-QSNROIJL.js";
|
|
8
|
+
import "./chunk-PH5FZX6E.js";
|
|
9
|
+
import "./chunk-BCF7P4FZ.js";
|
|
10
|
+
import "./chunk-INFYLWUA.js";
|
|
11
|
+
import "./chunk-XD4FRDSL.js";
|
|
12
|
+
import "./chunk-ZIAQPTUS.js";
|
|
13
|
+
import "./chunk-EXOOKUEA.js";
|
|
14
|
+
import "./chunk-QQXH2OPB.js";
|
|
15
|
+
import "./chunk-ZGZT5S6B.js";
|
|
16
|
+
import "./chunk-LRGYKOCP.js";
|
|
17
|
+
import {
|
|
18
|
+
catchCrashes
|
|
19
|
+
} from "./chunk-IRV2PCQ2.js";
|
|
20
|
+
import "./chunk-Y5E2WNWB.js";
|
|
21
|
+
import "./chunk-ZVVMGPBJ.js";
|
|
22
|
+
|
|
23
|
+
// dist/bin/b24.js
|
|
24
|
+
import { enableCompileCache } from "node:module";
|
|
25
|
+
enableCompileCache();
|
|
26
|
+
var stopCatching = catchCrashes({ cli: IDENTITY.command, interactive: process.stdout.isTTY === true });
|
|
27
|
+
var { run } = await import("./program-GO3RVP2H.js");
|
|
28
|
+
try {
|
|
29
|
+
process.exitCode = await run(process.argv.slice(2));
|
|
30
|
+
} finally {
|
|
31
|
+
stopCatching();
|
|
32
|
+
}
|