@wirecat/amo-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 +61 -0
- package/LICENSE +204 -0
- package/README.md +257 -2
- package/contracts/wirecat.json +1356 -0
- package/dist/amo/account.d.ts +18 -0
- package/dist/amo/account.d.ts.map +1 -0
- package/dist/amo/account.js +48 -0
- package/dist/amo/account.js.map +1 -0
- package/dist/amo/allow-list.d.ts +31 -0
- package/dist/amo/allow-list.d.ts.map +1 -0
- package/dist/amo/allow-list.js +106 -0
- package/dist/amo/allow-list.js.map +1 -0
- package/dist/amo/call.d.ts +24 -0
- package/dist/amo/call.d.ts.map +1 -0
- package/dist/amo/call.js +54 -0
- package/dist/amo/call.js.map +1 -0
- package/dist/amo/errors.d.ts +12 -0
- package/dist/amo/errors.d.ts.map +1 -0
- package/dist/amo/errors.js +72 -0
- package/dist/amo/errors.js.map +1 -0
- package/dist/amo/json.d.ts +3 -0
- package/dist/amo/json.d.ts.map +1 -0
- package/dist/amo/json.js +3 -0
- package/dist/amo/json.js.map +1 -0
- package/dist/amo/oauth.d.ts +55 -0
- package/dist/amo/oauth.d.ts.map +1 -0
- package/dist/amo/oauth.js +189 -0
- package/dist/amo/oauth.js.map +1 -0
- package/dist/amo/operation.d.ts +45 -0
- package/dist/amo/operation.d.ts.map +1 -0
- package/dist/amo/operation.js +119 -0
- package/dist/amo/operation.js.map +1 -0
- package/dist/amo/operations.d.ts +3 -0
- package/dist/amo/operations.d.ts.map +1 -0
- package/dist/amo/operations.js +1407 -0
- package/dist/amo/operations.js.map +1 -0
- package/dist/amo/routes.d.ts +67 -0
- package/dist/amo/routes.d.ts.map +1 -0
- package/dist/amo/routes.js +65 -0
- package/dist/amo/routes.js.map +1 -0
- package/dist/amo/transport.d.ts +62 -0
- package/dist/amo/transport.d.ts.map +1 -0
- package/dist/amo/transport.js +282 -0
- package/dist/amo/transport.js.map +1 -0
- package/dist/api-keys.d.ts +47 -0
- package/dist/api-keys.d.ts.map +1 -0
- package/dist/api-keys.js +224 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/bin/amo.d.ts +3 -0
- package/dist/bin/amo.d.ts.map +1 -0
- package/dist/bin/amo.js +40 -0
- package/dist/bin/amo.js.map +1 -0
- package/dist/bundle/all-profiles-3KQVWDV4.js +278 -0
- package/dist/bundle/amo.js +198 -0
- package/dist/bundle/anthropic-N5NOX7K7.js +90 -0
- package/dist/bundle/app-server-2MST5EZ5.js +245 -0
- package/dist/bundle/bun-4NHWOFX2.js +169 -0
- package/dist/bundle/bun-sqlite-DRSXPWPR.js +75 -0
- package/dist/bundle/chunk-2I5UVMLW.js +3232 -0
- package/dist/bundle/chunk-3IRJDH2U.js +731 -0
- package/dist/bundle/chunk-4ZAK773N.js +100 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5D4Z2B5B.js +334 -0
- package/dist/bundle/chunk-5E5R65CA.js +54 -0
- package/dist/bundle/chunk-5HGGG3QO.js +73 -0
- package/dist/bundle/chunk-5RLUHTK6.js +23 -0
- package/dist/bundle/chunk-5SBLU7D7.js +63 -0
- package/dist/bundle/chunk-5Z5PEEKP.js +206 -0
- package/dist/bundle/chunk-63F65DHU.js +29 -0
- package/dist/bundle/chunk-6RS7OYTD.js +64 -0
- package/dist/bundle/chunk-73CXFE36.js +88 -0
- package/dist/bundle/chunk-7GTUZY7M.js +170 -0
- package/dist/bundle/chunk-7PKFYX7V.js +189 -0
- package/dist/bundle/chunk-7U5HJEPZ.js +1400 -0
- package/dist/bundle/chunk-A33TIM5D.js +4172 -0
- package/dist/bundle/chunk-ADEWU4P4.js +38 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-AHJ4W2IL.js +106 -0
- package/dist/bundle/chunk-AUBB72VF.js +2572 -0
- package/dist/bundle/chunk-BVMNXI53.js +1266 -0
- package/dist/bundle/chunk-CDY2NJFE.js +136 -0
- package/dist/bundle/chunk-CHUKWON6.js +244 -0
- package/dist/bundle/chunk-CUZRHF34.js +230 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DAY6TSPF.js +786 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DJD7TBYG.js +2791 -0
- package/dist/bundle/chunk-DOSJONCX.js +1197 -0
- package/dist/bundle/chunk-DQV2IKCF.js +72 -0
- package/dist/bundle/chunk-DTA5YV5O.js +25 -0
- package/dist/bundle/chunk-DXGGCGRP.js +218 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EPOV5UIO.js +185 -0
- package/dist/bundle/chunk-EQ7A6NA6.js +53 -0
- package/dist/bundle/chunk-EQUKVVHX.js +353 -0
- package/dist/bundle/chunk-EROSAUNP.js +133 -0
- package/dist/bundle/chunk-ESZSMZKT.js +82 -0
- package/dist/bundle/chunk-FKR3M62D.js +407 -0
- package/dist/bundle/chunk-GNTJMB6X.js +142 -0
- package/dist/bundle/chunk-GQ7VFIYM.js +316 -0
- package/dist/bundle/chunk-JH3UOHRE.js +161 -0
- package/dist/bundle/chunk-JMDLPBXK.js +1068 -0
- package/dist/bundle/chunk-JR6TSMFX.js +9435 -0
- package/dist/bundle/chunk-K5UU3IOR.js +27955 -0
- package/dist/bundle/chunk-L6AFE73L.js +18 -0
- package/dist/bundle/chunk-LDEBZ3IX.js +238 -0
- package/dist/bundle/chunk-LGQXGOPJ.js +58 -0
- package/dist/bundle/chunk-LJQUYECN.js +6848 -0
- package/dist/bundle/chunk-LRBPT7LQ.js +95 -0
- package/dist/bundle/chunk-LSND5QYI.js +460 -0
- package/dist/bundle/chunk-NHXJYS4R.js +1334 -0
- package/dist/bundle/chunk-NJYAL3UW.js +92 -0
- package/dist/bundle/chunk-NTLSWCJ5.js +1718 -0
- package/dist/bundle/chunk-O2UCU52O.js +4065 -0
- package/dist/bundle/chunk-ODNQU7DH.js +1028 -0
- package/dist/bundle/chunk-P3WQRTYZ.js +24 -0
- package/dist/bundle/chunk-P5LYZRKW.js +63373 -0
- package/dist/bundle/chunk-PFO76YFP.js +2003 -0
- package/dist/bundle/chunk-PM77PRB6.js +12269 -0
- package/dist/bundle/chunk-Q2VNBY4Y.js +38109 -0
- package/dist/bundle/chunk-QDMXZZG4.js +604 -0
- package/dist/bundle/chunk-QRQYUHCZ.js +761 -0
- package/dist/bundle/chunk-RPWAJYI6.js +2336 -0
- package/dist/bundle/chunk-SMSTGO2G.js +58 -0
- package/dist/bundle/chunk-SZ2V62HB.js +72 -0
- package/dist/bundle/chunk-T2UDLX76.js +259 -0
- package/dist/bundle/chunk-TGEQNS6G.js +16 -0
- package/dist/bundle/chunk-TNUFLULO.js +2333 -0
- package/dist/bundle/chunk-U7RLVJ34.js +274 -0
- package/dist/bundle/chunk-UBRREVLJ.js +72 -0
- package/dist/bundle/chunk-ULXQ5MJM.js +76 -0
- package/dist/bundle/chunk-UMVRT7VQ.js +46 -0
- package/dist/bundle/chunk-V77XNPXG.js +360 -0
- package/dist/bundle/chunk-VVHRQ46X.js +193 -0
- package/dist/bundle/chunk-VX37MPTJ.js +7 -0
- package/dist/bundle/chunk-WCYCUTSK.js +362 -0
- package/dist/bundle/chunk-XEFAMLSD.js +288 -0
- package/dist/bundle/chunk-XQL7FEF4.js +721 -0
- package/dist/bundle/chunk-XRTD2GCU.js +627 -0
- package/dist/bundle/chunk-Y37A3232.js +804 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-ZM7I52EP.js +78 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/cli-KEGIR67U.js +1193 -0
- package/dist/bundle/command-contract-QBUQBXH7.js +39 -0
- package/dist/bundle/command-server-entry-5VL5U5EE.js +168 -0
- package/dist/bundle/decode-SQ5WGNDX.js +296 -0
- package/dist/bundle/dispatch-LA4DFXJD.js +411 -0
- package/dist/bundle/dist-XJGFOXYI.js +7577 -0
- package/dist/bundle/echarts-25Z3RINX.js +42501 -0
- package/dist/bundle/embed-BNOTNXMA.js +37 -0
- package/dist/bundle/embedder-BCUT7KKV.js +110 -0
- package/dist/bundle/failure-PKAC6XCT.js +24 -0
- package/dist/bundle/first-run-EO5K5GME.js +28 -0
- package/dist/bundle/first-screen-GMN3T6RW.js +39 -0
- package/dist/bundle/instructions-VLM3QAYB.js +11 -0
- package/dist/bundle/mcp-7ILNMJH5.js +167 -0
- package/dist/bundle/meeting-combined-LAMF7S2B.js +24 -0
- package/dist/bundle/meeting-model-GHMMUQ34.js +24 -0
- package/dist/bundle/meeting-semantic-BMP6323L.js +21 -0
- package/dist/bundle/node-CT3N3TNL.js +176 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-MELD2SBX.js +73 -0
- package/dist/bundle/oauth-YBH5OKC2.js +19 -0
- package/dist/bundle/open-WNSBWTAG.js +22 -0
- package/dist/bundle/openai-XSNMNLW6.js +237 -0
- package/dist/bundle/process-I2QKOMM7.js +91 -0
- package/dist/bundle/program-VQQTSSAF.js +4940 -0
- package/dist/bundle/prompt-SOG4AKPM.js +16 -0
- package/dist/bundle/recognize-WMQLWMXH.js +25 -0
- package/dist/bundle/remote-4BTFOLFY.js +30 -0
- package/dist/bundle/rerank-LJ3TWRNV.js +51 -0
- package/dist/bundle/serve-B6UANKXN.js +198 -0
- package/dist/bundle/server-S6XD6V6E.js +77 -0
- package/dist/bundle/server-YRH6GJ5Z.js +206 -0
- package/dist/bundle/source-DGFTA2TN.js +42 -0
- package/dist/bundle/sqlite-runtime-R7QFWFE7.js +19 -0
- package/dist/bundle/state-DIJ5YUOE.js +35 -0
- package/dist/bundle/store-6WFWW7EC.js +294 -0
- package/dist/bundle/store-BPNIM4BF.js +32 -0
- package/dist/bundle/store-MYTYDV6A.js +177 -0
- package/dist/bundle/store-maintenance-command-B5TMKFMG.js +68 -0
- package/dist/bundle/writer-GP7VIMAU.js +44 -0
- package/dist/commands/account.d.ts +3 -0
- package/dist/commands/account.d.ts.map +1 -0
- package/dist/commands/account.js +86 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +224 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.js.map +1 -0
- package/dist/commands/crm-shared.d.ts +8 -0
- package/dist/commands/crm-shared.d.ts.map +1 -0
- package/dist/commands/crm-shared.js +111 -0
- package/dist/commands/crm-shared.js.map +1 -0
- package/dist/commands/schedule.d.ts +3 -0
- package/dist/commands/schedule.d.ts.map +1 -0
- package/dist/commands/schedule.js +9 -0
- package/dist/commands/schedule.js.map +1 -0
- package/dist/commands/session.d.ts +18 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +265 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/write.d.ts +14 -0
- package/dist/commands/write.d.ts.map +1 -0
- package/dist/commands/write.js +36 -0
- package/dist/commands/write.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +29 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +62 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +97 -0
- package/dist/context.js.map +1 -0
- package/dist/crm/activities.d.ts +32 -0
- package/dist/crm/activities.d.ts.map +1 -0
- package/dist/crm/activities.js +196 -0
- package/dist/crm/activities.js.map +1 -0
- package/dist/crm/records.d.ts +20 -0
- package/dist/crm/records.d.ts.map +1 -0
- package/dist/crm/records.js +175 -0
- package/dist/crm/records.js.map +1 -0
- package/dist/crm/source.d.ts +41 -0
- package/dist/crm/source.d.ts.map +1 -0
- package/dist/crm/source.js +673 -0
- package/dist/crm/source.js.map +1 -0
- package/dist/crm/writer.d.ts +14 -0
- package/dist/crm/writer.d.ts.map +1 -0
- package/dist/crm/writer.js +247 -0
- package/dist/crm/writer.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +33 -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/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +91 -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 +35 -0
- package/dist/reasons.js.map +1 -0
- package/dist/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.js.map +1 -0
- package/dist/setup/flow.d.ts +2 -0
- package/dist/setup/flow.d.ts.map +1 -0
- package/dist/setup/flow.js +127 -0
- package/dist/setup/flow.js.map +1 -0
- package/dist/setup/texts.en.json +25 -0
- package/dist/setup/texts.es.json +25 -0
- package/dist/setup/texts.ru.json +25 -0
- package/dist/store.d.ts +15 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +16 -0
- package/dist/store.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/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/dist/whoami.d.ts +24 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +33 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +85 -4
- package/skills/amo-cli/SKILL.md +116 -0
- package/skills/amo-cli/references/mcp.md +38 -0
- package/skills/amo-cli/references/output.md +42 -0
- package/skills/amo-cli/references/reading.md +77 -0
- package/skills/amo-cli/references/setup.md +59 -0
- package/skills/amo-cli/references/writing.md +85 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
parseReference
|
|
5
|
+
} from "./chunk-QRQYUHCZ.js";
|
|
6
|
+
import {
|
|
7
|
+
__name
|
|
8
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
9
|
+
|
|
10
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/domain/links.js
|
|
11
|
+
var LINK_VERSION = "v1";
|
|
12
|
+
var DEFAULT_LINK_CONFIG = { base: "https://wirecat.dev/o", enabled: true };
|
|
13
|
+
var APP_PREFIX = "wirecat://open";
|
|
14
|
+
var MAX_PATH = 512;
|
|
15
|
+
var MAX_SEGMENTS = 6;
|
|
16
|
+
var TASK_FILTERS = ["overdue", "today", "tomorrow", "undated"];
|
|
17
|
+
var DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
18
|
+
var DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
19
|
+
var isMoment = /* @__PURE__ */ __name((text, pattern) => pattern.test(text) && !Number.isNaN(Date.parse(text)), "isMoment");
|
|
20
|
+
var partsOf = /* @__PURE__ */ __name((target) => {
|
|
21
|
+
switch (target.type) {
|
|
22
|
+
case "message":
|
|
23
|
+
return ["msg", target.provider, target.account, target.chat, target.message];
|
|
24
|
+
case "chat":
|
|
25
|
+
return ["chat", target.provider, target.account, target.chat];
|
|
26
|
+
case "task":
|
|
27
|
+
case "person":
|
|
28
|
+
case "project":
|
|
29
|
+
return [target.type, target.id];
|
|
30
|
+
case "tasks":
|
|
31
|
+
return target.filter === "new" ? ["tasks", "new", target.since] : ["tasks", target.filter];
|
|
32
|
+
case "proposal":
|
|
33
|
+
return ["proposal", target.id];
|
|
34
|
+
case "digest":
|
|
35
|
+
return ["digest", target.date];
|
|
36
|
+
case "sync":
|
|
37
|
+
return target.account === void 0 ? ["sync", target.tool] : ["sync", target.tool, target.account];
|
|
38
|
+
case "meeting":
|
|
39
|
+
return ["meeting", target.provider, target.account, target.meeting];
|
|
40
|
+
}
|
|
41
|
+
}, "partsOf");
|
|
42
|
+
var pathOf = /* @__PURE__ */ __name((target) => partsOf(target).map(encodeURIComponent).join("/"), "pathOf");
|
|
43
|
+
var targetOfParts = /* @__PURE__ */ __name((parts) => {
|
|
44
|
+
const [kind, ...rest] = parts;
|
|
45
|
+
const [a = "", b = "", c = "", d = ""] = rest;
|
|
46
|
+
switch (kind) {
|
|
47
|
+
case "msg":
|
|
48
|
+
return rest.length === 4 ? { type: "message", provider: a, account: b, chat: c, message: d } : null;
|
|
49
|
+
case "chat":
|
|
50
|
+
return rest.length === 3 ? { type: "chat", provider: a, account: b, chat: c } : null;
|
|
51
|
+
case "task":
|
|
52
|
+
case "person":
|
|
53
|
+
case "project":
|
|
54
|
+
return rest.length === 1 ? { type: kind, id: a } : null;
|
|
55
|
+
case "tasks":
|
|
56
|
+
if (rest.length === 1 && TASK_FILTERS.includes(a))
|
|
57
|
+
return { type: "tasks", filter: a };
|
|
58
|
+
return rest.length === 2 && a === "new" && (isMoment(b, DATE) || isMoment(b, DATE_TIME)) ? { type: "tasks", filter: "new", since: b } : null;
|
|
59
|
+
case "proposal":
|
|
60
|
+
return rest.length === 1 ? { type: "proposal", id: a } : null;
|
|
61
|
+
case "digest":
|
|
62
|
+
return rest.length === 1 && isMoment(a, DATE) ? { type: "digest", date: a } : null;
|
|
63
|
+
case "sync":
|
|
64
|
+
return rest.length === 1 || rest.length === 2 ? { type: "sync", tool: a, ...rest.length === 2 ? { account: b } : {} } : null;
|
|
65
|
+
case "meeting":
|
|
66
|
+
return rest.length === 3 ? { type: "meeting", provider: a, account: b, meeting: c } : null;
|
|
67
|
+
default:
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}, "targetOfParts");
|
|
71
|
+
var targetOfPath = /* @__PURE__ */ __name((path) => {
|
|
72
|
+
const raw = path.split("/");
|
|
73
|
+
if (raw.some((part) => part === ""))
|
|
74
|
+
return null;
|
|
75
|
+
try {
|
|
76
|
+
return targetOfParts(raw.map(decodeURIComponent));
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}, "targetOfPath");
|
|
81
|
+
var formatLink = /* @__PURE__ */ __name((target) => `/${LINK_VERSION}/${pathOf(target)}`, "formatLink");
|
|
82
|
+
var parseLink = /* @__PURE__ */ __name((text) => {
|
|
83
|
+
const link = text.trim();
|
|
84
|
+
const path = link.startsWith(`${APP_PREFIX}/`) ? link.slice(APP_PREFIX.length) : link.startsWith("https://") && link.includes("#") ? link.slice(link.indexOf("#") + 1) : link;
|
|
85
|
+
if (path.length > MAX_PATH || !path.startsWith(`/${LINK_VERSION}/`))
|
|
86
|
+
return null;
|
|
87
|
+
const rest = path.split("?")[0].slice(LINK_VERSION.length + 2);
|
|
88
|
+
if (rest.split("/").length + 1 > MAX_SEGMENTS)
|
|
89
|
+
return null;
|
|
90
|
+
return targetOfPath(rest);
|
|
91
|
+
}, "parseLink");
|
|
92
|
+
var LINK_ONLY = /* @__PURE__ */ new Set(["tasks", "proposal", "digest", "sync"]);
|
|
93
|
+
var FROM_REFERENCE = /* @__PURE__ */ new Set(["message", "chat", "task", "person", "project"]);
|
|
94
|
+
var ENTITY_KINDS = /* @__PURE__ */ new Set(["person", "project"]);
|
|
95
|
+
var refsForLink = /* @__PURE__ */ __name((refs) => [
|
|
96
|
+
...refs.filter((ref) => !ENTITY_KINDS.has(ref.slice(0, ref.indexOf(":")))),
|
|
97
|
+
...refs.filter((ref) => ENTITY_KINDS.has(ref.slice(0, ref.indexOf(":"))))
|
|
98
|
+
], "refsForLink");
|
|
99
|
+
var linkTargetOf = /* @__PURE__ */ __name((ref) => {
|
|
100
|
+
const text = ref.trim();
|
|
101
|
+
const colon = text.indexOf(":");
|
|
102
|
+
if (colon < 0)
|
|
103
|
+
return null;
|
|
104
|
+
const kind = text.slice(0, colon);
|
|
105
|
+
if (LINK_ONLY.has(kind))
|
|
106
|
+
return targetOfPath(`${kind}/${text.slice(colon + 1)}`);
|
|
107
|
+
try {
|
|
108
|
+
const reference = parseReference(text);
|
|
109
|
+
return FROM_REFERENCE.has(reference.type) ? reference : null;
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}, "linkTargetOf");
|
|
114
|
+
var linkConfigOf = /* @__PURE__ */ __name((section) => {
|
|
115
|
+
const value = section && typeof section === "object" ? section : {};
|
|
116
|
+
const base = typeof value.base === "string" && /^https:\/\/[^\s#?]+$/.test(value.base) ? value.base.replace(/\/+$/, "") : DEFAULT_LINK_CONFIG.base;
|
|
117
|
+
return { base, enabled: typeof value.enabled === "boolean" ? value.enabled : DEFAULT_LINK_CONFIG.enabled };
|
|
118
|
+
}, "linkConfigOf");
|
|
119
|
+
var linkFor = /* @__PURE__ */ __name((ref, { form, config = DEFAULT_LINK_CONFIG, env = process.env }) => {
|
|
120
|
+
if (!config.enabled || env.WIRECAT_LINKS === "off")
|
|
121
|
+
return null;
|
|
122
|
+
const target = typeof ref === "string" ? linkTargetOf(ref) : ref;
|
|
123
|
+
if (target === null)
|
|
124
|
+
return null;
|
|
125
|
+
const path = formatLink(target);
|
|
126
|
+
if (path.length > MAX_PATH || parseLink(path) === null)
|
|
127
|
+
return null;
|
|
128
|
+
return form === "app" ? `${APP_PREFIX}${path}` : `${config.base}#${path}`;
|
|
129
|
+
}, "linkFor");
|
|
130
|
+
|
|
131
|
+
export {
|
|
132
|
+
DEFAULT_LINK_CONFIG,
|
|
133
|
+
refsForLink,
|
|
134
|
+
linkConfigOf,
|
|
135
|
+
linkFor
|
|
136
|
+
};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
ENTITIES,
|
|
5
|
+
LOST,
|
|
6
|
+
WON
|
|
7
|
+
} from "./chunk-LDEBZ3IX.js";
|
|
8
|
+
import {
|
|
9
|
+
fieldNamed,
|
|
10
|
+
foldFieldName,
|
|
11
|
+
optionOf,
|
|
12
|
+
values_exports
|
|
13
|
+
} from "./chunk-2I5UVMLW.js";
|
|
14
|
+
import {
|
|
15
|
+
CliError,
|
|
16
|
+
isCliError
|
|
17
|
+
} from "./chunk-SZ2V62HB.js";
|
|
18
|
+
import {
|
|
19
|
+
__name
|
|
20
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
21
|
+
|
|
22
|
+
// dist/crm/writer.js
|
|
23
|
+
var AMO_WRITES = {
|
|
24
|
+
kinds: ["deal", "person", "organization"],
|
|
25
|
+
verbs: ["create", "update", "move", "close"],
|
|
26
|
+
idempotent: false
|
|
27
|
+
};
|
|
28
|
+
var STANDARD = new Set([
|
|
29
|
+
"id",
|
|
30
|
+
"name",
|
|
31
|
+
"first_name",
|
|
32
|
+
"last_name",
|
|
33
|
+
"price",
|
|
34
|
+
"status_id",
|
|
35
|
+
"pipeline_id",
|
|
36
|
+
"responsible_user_id",
|
|
37
|
+
"loss_reason_id",
|
|
38
|
+
"closed_at",
|
|
39
|
+
"created_by",
|
|
40
|
+
"updated_by",
|
|
41
|
+
"created_at",
|
|
42
|
+
"updated_at"
|
|
43
|
+
].map(foldFieldName));
|
|
44
|
+
var refused = /* @__PURE__ */ __name((message, param) => new CliError("validation_error", message, { reason: "crm.record-field", sent: false, ...param ? { param } : {} }), "refused");
|
|
45
|
+
var numericId = /* @__PURE__ */ __name((value, param) => {
|
|
46
|
+
if (!/^\d{1,20}$/.test(value))
|
|
47
|
+
throw refused(`${param} takes amoCRM's numeric id`, param);
|
|
48
|
+
return Number(value);
|
|
49
|
+
}, "numericId");
|
|
50
|
+
var customValuesOf = /* @__PURE__ */ __name((defined, custom) => Object.entries(custom).map(([name, value]) => {
|
|
51
|
+
const field = fieldNamed(defined, name, "--field");
|
|
52
|
+
if (field.holds)
|
|
53
|
+
throw refused(`${field.label ?? field.code} holds phones or e-mails; amo does not set them here`);
|
|
54
|
+
const one = /* @__PURE__ */ __name((given) => field.options ? { enum_id: Number(optionOf(field, given, "--field")) } : { value: given }, "one");
|
|
55
|
+
const values = value === null ? [] : (Array.isArray(value) ? value : [value]).map(one);
|
|
56
|
+
return { field_id: Number(field.code), values };
|
|
57
|
+
}), "customValuesOf");
|
|
58
|
+
var refuseStandard = /* @__PURE__ */ __name((custom) => {
|
|
59
|
+
for (const code of Object.keys(custom ?? {}))
|
|
60
|
+
if (STANDARD.has(foldFieldName(code)))
|
|
61
|
+
throw refused(`${code} is one of amoCRM's own fields; set it with its own option, not --field`, "--field");
|
|
62
|
+
}, "refuseStandard");
|
|
63
|
+
var amoCrmWriter = /* @__PURE__ */ __name((account, source) => {
|
|
64
|
+
const dealOf = /* @__PURE__ */ __name(async (given, create) => {
|
|
65
|
+
refuseStandard(given.custom);
|
|
66
|
+
if (given.people !== void 0)
|
|
67
|
+
throw refused("amo does not set the contacts on a deal yet");
|
|
68
|
+
if (given.owner === null)
|
|
69
|
+
throw refused("an amoCRM deal is always assigned to a user", "--owner");
|
|
70
|
+
if (given.closeDate !== void 0)
|
|
71
|
+
throw refused("amoCRM deals have no expected close date", "--close-date");
|
|
72
|
+
if (given.organization !== void 0 && (!create || given.organization === null))
|
|
73
|
+
throw refused("amo sets a deal's company only when it creates the deal", "--organization");
|
|
74
|
+
if (given.currency != null) {
|
|
75
|
+
const { currency } = await source.account();
|
|
76
|
+
if (given.currency !== currency)
|
|
77
|
+
throw refused(`amoCRM keeps every amount in the account's currency, ${currency ?? "none set"}`, "--currency");
|
|
78
|
+
}
|
|
79
|
+
const fields = {};
|
|
80
|
+
if (given.title !== void 0)
|
|
81
|
+
fields.name = given.title;
|
|
82
|
+
if (given.pipeline !== void 0)
|
|
83
|
+
fields.pipeline_id = numericId(given.pipeline, "--pipeline");
|
|
84
|
+
if (given.stage !== void 0)
|
|
85
|
+
fields.status_id = numericId(given.stage, "--stage");
|
|
86
|
+
if (given.amount !== void 0)
|
|
87
|
+
fields.price = given.amount === null ? 0 : Number(given.amount);
|
|
88
|
+
if (given.owner != null)
|
|
89
|
+
fields.responsible_user_id = numericId(given.owner, "--owner");
|
|
90
|
+
if (given.organization)
|
|
91
|
+
fields._embedded = { companies: [{ id: numericId(given.organization, "--organization") }] };
|
|
92
|
+
if (given.custom && Object.keys(given.custom).length)
|
|
93
|
+
fields.custom_fields_values = customValuesOf(await source.fields("deal"), given.custom);
|
|
94
|
+
return fields;
|
|
95
|
+
}, "dealOf");
|
|
96
|
+
const partsOf = /* @__PURE__ */ __name((current) => {
|
|
97
|
+
if (current?.firstName || current?.lastName)
|
|
98
|
+
return { first: current.firstName, last: current.lastName };
|
|
99
|
+
const [first, ...rest] = (current?.name ?? "").trim().split(/\s+/);
|
|
100
|
+
return { first: first || void 0, last: rest.join(" ") || void 0 };
|
|
101
|
+
}, "partsOf");
|
|
102
|
+
const personOf = /* @__PURE__ */ __name(async (given, externalId) => {
|
|
103
|
+
refuseStandard(given.custom);
|
|
104
|
+
if (given.owner === null)
|
|
105
|
+
throw refused("an amoCRM contact is always assigned to a user", "--owner");
|
|
106
|
+
if (given.position !== void 0)
|
|
107
|
+
throw refused("amoCRM keeps a job title in an account's own field; set it with --field", "--position");
|
|
108
|
+
const naming = given.name === void 0 && (given.firstName !== void 0 || given.lastName !== void 0);
|
|
109
|
+
const current = externalId !== void 0 && (naming || given.emails || given.phones) ? await source.get?.("person", externalId) : void 0;
|
|
110
|
+
const fields = {};
|
|
111
|
+
const stored = partsOf(current);
|
|
112
|
+
const name = given.name ?? (naming ? values_exports.fullName(given.firstName === void 0 ? stored.first : given.firstName, given.lastName === void 0 ? stored.last : given.lastName) : void 0);
|
|
113
|
+
if (name != null)
|
|
114
|
+
fields.name = name;
|
|
115
|
+
if (given.firstName !== void 0)
|
|
116
|
+
fields.first_name = given.firstName ?? "";
|
|
117
|
+
if (given.lastName !== void 0)
|
|
118
|
+
fields.last_name = given.lastName ?? "";
|
|
119
|
+
if (given.owner != null)
|
|
120
|
+
fields.responsible_user_id = numericId(given.owner, "--owner");
|
|
121
|
+
const values = await valuesOf("person", given, current?.contactTypes);
|
|
122
|
+
if (values.length)
|
|
123
|
+
fields.custom_fields_values = values;
|
|
124
|
+
return fields;
|
|
125
|
+
}, "personOf");
|
|
126
|
+
const valuesOf = /* @__PURE__ */ __name(async (kind, given, kinds = {}) => {
|
|
127
|
+
if (!given.emails && !given.phones && !(given.custom && Object.keys(given.custom).length))
|
|
128
|
+
return [];
|
|
129
|
+
const defined = await source.fields(kind);
|
|
130
|
+
const values = given.custom ? customValuesOf(defined, given.custom) : [];
|
|
131
|
+
for (const [holds, list] of [
|
|
132
|
+
["email", given.emails],
|
|
133
|
+
["phone", given.phones]
|
|
134
|
+
]) {
|
|
135
|
+
if (list === void 0)
|
|
136
|
+
continue;
|
|
137
|
+
const field = defined.find((one) => one.holds === holds);
|
|
138
|
+
if (!field)
|
|
139
|
+
throw refused(`this account has no ${holds} field on ${kind === "person" ? "contacts" : "companies"}`);
|
|
140
|
+
values.push({
|
|
141
|
+
field_id: Number(field.code),
|
|
142
|
+
values: list.map((value) => ({ value, enum_code: kinds[value] ?? "WORK" }))
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return values;
|
|
146
|
+
}, "valuesOf");
|
|
147
|
+
const organizationOf = /* @__PURE__ */ __name(async (given) => {
|
|
148
|
+
refuseStandard(given.custom);
|
|
149
|
+
if (given.owner === null)
|
|
150
|
+
throw refused("an amoCRM company is always assigned to a user", "--owner");
|
|
151
|
+
const fields = {};
|
|
152
|
+
if (given.name !== void 0)
|
|
153
|
+
fields.name = given.name;
|
|
154
|
+
if (given.owner != null)
|
|
155
|
+
fields.responsible_user_id = numericId(given.owner, "--owner");
|
|
156
|
+
const values = await valuesOf("organization", given);
|
|
157
|
+
if (values.length)
|
|
158
|
+
fields.custom_fields_values = values;
|
|
159
|
+
return fields;
|
|
160
|
+
}, "organizationOf");
|
|
161
|
+
const bodyOf = /* @__PURE__ */ __name((kind, given, create, externalId) => {
|
|
162
|
+
if (kind === "deal")
|
|
163
|
+
return dealOf(given, create);
|
|
164
|
+
if (kind === "person")
|
|
165
|
+
return personOf(given, create ? void 0 : externalId);
|
|
166
|
+
if (kind === "organization")
|
|
167
|
+
return organizationOf(given);
|
|
168
|
+
throw new CliError("validation_error", "amoCRM has no leads apart from its deals", {
|
|
169
|
+
reason: "crm.write-unsupported"
|
|
170
|
+
});
|
|
171
|
+
}, "bodyOf");
|
|
172
|
+
const readBack = /* @__PURE__ */ __name(async (kind, externalId, options) => {
|
|
173
|
+
try {
|
|
174
|
+
const found = kind === "deal" ? await source.item(externalId) : await source.get?.(kind, externalId);
|
|
175
|
+
if (!found)
|
|
176
|
+
throw new CliError("not_found", `amoCRM has no ${kind} ${externalId}`);
|
|
177
|
+
return found;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
throw new CliError("invalid_response", `amoCRM made the change to ${kind} ${externalId}, but reading it back failed${isCliError(error) ? ` (${error.code})` : ""}; run sync to store it \u2014 do not write it again`, { operation_id: options.operationId, external_id: externalId, sent: true });
|
|
180
|
+
}
|
|
181
|
+
}, "readBack");
|
|
182
|
+
const update = /* @__PURE__ */ __name(async (kind, externalId, fields, options) => {
|
|
183
|
+
if (Object.keys(fields).length === 0)
|
|
184
|
+
throw refused("nothing to change: name a field");
|
|
185
|
+
const entity = ENTITIES[kind];
|
|
186
|
+
await account().request({ route: entity.update, body: [{ id: Number(externalId), ...fields }] });
|
|
187
|
+
return readBack(kind, externalId, options);
|
|
188
|
+
}, "update");
|
|
189
|
+
const stageOf = /* @__PURE__ */ __name(async (externalId) => {
|
|
190
|
+
const current = await source.item(externalId);
|
|
191
|
+
return { current, pipeline: Number(current.pipeline) };
|
|
192
|
+
}, "stageOf");
|
|
193
|
+
return {
|
|
194
|
+
provider: "amocrm",
|
|
195
|
+
capabilities: AMO_WRITES,
|
|
196
|
+
async create(kind, draft, options) {
|
|
197
|
+
const fields = await bodyOf(kind, draft, true);
|
|
198
|
+
const entity = ENTITIES[kind];
|
|
199
|
+
const { body } = await account().request({ route: entity.create, body: [fields] });
|
|
200
|
+
const created = values_exports.rawsOf(values_exports.fieldOf(values_exports.fieldOf(body, "_embedded"), entity.name))[0];
|
|
201
|
+
const externalId = values_exports.id(created?.id);
|
|
202
|
+
if (externalId === null)
|
|
203
|
+
throw new CliError("invalid_response", `amoCRM answered the new ${kind} without its id; run sync before writing again`, {
|
|
204
|
+
operation_id: options.operationId,
|
|
205
|
+
sent: true
|
|
206
|
+
});
|
|
207
|
+
return readBack(kind, externalId, options);
|
|
208
|
+
},
|
|
209
|
+
async update(kind, externalId, patch, options) {
|
|
210
|
+
return update(kind, externalId, await bodyOf(kind, patch, false, externalId), options);
|
|
211
|
+
},
|
|
212
|
+
async move(_kind, externalId, stage, options) {
|
|
213
|
+
const { pipeline } = await stageOf(externalId);
|
|
214
|
+
return update("deal", externalId, { status_id: numericId(stage, "<stage>"), pipeline_id: pipeline }, options);
|
|
215
|
+
},
|
|
216
|
+
// 142 won and 143 lost in every pipeline (leads_pipelines); a lost one takes a loss reason by name (loss-reasons).
|
|
217
|
+
async close(_kind, externalId, outcome, options) {
|
|
218
|
+
const { pipeline } = await stageOf(externalId);
|
|
219
|
+
const fields = { status_id: Number(outcome === "won" ? WON : LOST), pipeline_id: pipeline };
|
|
220
|
+
if (options.reason !== void 0) {
|
|
221
|
+
if (outcome === "won")
|
|
222
|
+
throw refused("amoCRM keeps a reason only on a lost deal; leave out --reason", "--reason");
|
|
223
|
+
const reasons = await source.lossReasons();
|
|
224
|
+
const want = foldFieldName(options.reason);
|
|
225
|
+
const found = reasons.find((one) => one.id === options.reason || foldFieldName(one.name) === want);
|
|
226
|
+
if (!found)
|
|
227
|
+
throw refused(`amoCRM has no loss reason ${options.reason}; it has ${reasons.map((one) => one.name).join(", ") || "none"}`, "--reason");
|
|
228
|
+
fields.loss_reason_id = Number(found.id);
|
|
229
|
+
}
|
|
230
|
+
return update("deal", externalId, fields, options);
|
|
231
|
+
},
|
|
232
|
+
async remove() {
|
|
233
|
+
throw new CliError("validation_error", "amoCRM's API has no call that deletes a deal; delete it in amoCRM", {
|
|
234
|
+
reason: "crm.write-unsupported",
|
|
235
|
+
sent: false
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}, "amoCrmWriter");
|
|
240
|
+
|
|
241
|
+
export {
|
|
242
|
+
AMO_WRITES,
|
|
243
|
+
amoCrmWriter
|
|
244
|
+
};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
importFrom
|
|
5
|
+
} from "./chunk-Y5E2WNWB.js";
|
|
6
|
+
import {
|
|
7
|
+
CliError
|
|
8
|
+
} from "./chunk-SZ2V62HB.js";
|
|
9
|
+
import {
|
|
10
|
+
__name
|
|
11
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/speech/recognize.js
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
|
|
16
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/speech/ogg-limit.js
|
|
17
|
+
var invalid = /* @__PURE__ */ __name(() => new CliError("validation_error", "local transcription needs a complete mono or stereo Ogg Opus recording"), "invalid");
|
|
18
|
+
var checkOggDuration = /* @__PURE__ */ __name((bytes) => {
|
|
19
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
20
|
+
let offset = 0;
|
|
21
|
+
let serial;
|
|
22
|
+
let packet = 0;
|
|
23
|
+
let length = 0;
|
|
24
|
+
const prefix = [];
|
|
25
|
+
while (offset < bytes.length) {
|
|
26
|
+
if (offset + 27 > bytes.length || view.getUint32(offset, false) !== 1332176723 || bytes[offset + 4] !== 0)
|
|
27
|
+
throw invalid();
|
|
28
|
+
const stream = view.getUint32(offset + 14, true);
|
|
29
|
+
if (serial !== void 0 && serial !== stream)
|
|
30
|
+
throw invalid();
|
|
31
|
+
serial = stream;
|
|
32
|
+
const segments = bytes[offset + 26] ?? 0;
|
|
33
|
+
let data = offset + 27 + segments;
|
|
34
|
+
if (data > bytes.length || Boolean((bytes[offset + 5] ?? 0) & 1) !== length > 0)
|
|
35
|
+
throw invalid();
|
|
36
|
+
for (let index = 0; index < segments; index++) {
|
|
37
|
+
const size = bytes[offset + 27 + index] ?? 0;
|
|
38
|
+
if (data + size > bytes.length)
|
|
39
|
+
throw invalid();
|
|
40
|
+
const take = Math.min(size, 19 - prefix.length);
|
|
41
|
+
for (let i = 0; i < take; i++)
|
|
42
|
+
prefix.push(bytes[data + i] ?? 0);
|
|
43
|
+
length += size;
|
|
44
|
+
data += size;
|
|
45
|
+
if (size === 255)
|
|
46
|
+
continue;
|
|
47
|
+
if (packet === 0) {
|
|
48
|
+
if (length < 19 || String.fromCharCode(...prefix.slice(0, 8)) !== "OpusHead" || ![1, 2].includes(prefix[9] ?? 0) || prefix[18] !== 0)
|
|
49
|
+
throw invalid();
|
|
50
|
+
} else if (packet === 1) {
|
|
51
|
+
if (length < 8 || String.fromCharCode(...prefix.slice(0, 8)) !== "OpusTags")
|
|
52
|
+
throw invalid();
|
|
53
|
+
} else {
|
|
54
|
+
if (length < 1)
|
|
55
|
+
throw invalid();
|
|
56
|
+
const toc = prefix[0] ?? 0;
|
|
57
|
+
const config = toc >> 3;
|
|
58
|
+
const frame = config >= 16 ? 120 << (config & 3) : config >= 12 ? 480 << (config & 1) : (config & 3) === 3 ? 2880 : 480 << (config & 3);
|
|
59
|
+
const count = (toc & 3) === 0 ? 1 : (toc & 3) === 3 ? length >= 2 ? (prefix[1] ?? 0) & 63 : 0 : 2;
|
|
60
|
+
if (count < 1 || frame * count > 5760)
|
|
61
|
+
throw invalid();
|
|
62
|
+
}
|
|
63
|
+
packet++;
|
|
64
|
+
length = 0;
|
|
65
|
+
prefix.length = 0;
|
|
66
|
+
}
|
|
67
|
+
offset = data;
|
|
68
|
+
}
|
|
69
|
+
if (length !== 0 || packet < 3)
|
|
70
|
+
throw invalid();
|
|
71
|
+
}, "checkOggDuration");
|
|
72
|
+
|
|
73
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/speech/recognize.js
|
|
74
|
+
var SAMPLE_RATE = 16e3;
|
|
75
|
+
var LEAD = SAMPLE_RATE / 2;
|
|
76
|
+
var toModelRate = /* @__PURE__ */ __name((samples, rate) => {
|
|
77
|
+
const step = rate / SAMPLE_RATE;
|
|
78
|
+
const length = Math.floor(samples.length / step);
|
|
79
|
+
const pcm = new Float32Array(LEAD + length);
|
|
80
|
+
for (let i = 0; i < length; i++) {
|
|
81
|
+
const from = Math.floor(i * step);
|
|
82
|
+
const to = Math.max(from + 1, Math.floor((i + 1) * step));
|
|
83
|
+
let sum = 0;
|
|
84
|
+
for (let j = from; j < to; j++)
|
|
85
|
+
sum += samples[j] ?? 0;
|
|
86
|
+
pcm[LEAD + i] = sum / (to - from);
|
|
87
|
+
}
|
|
88
|
+
return pcm;
|
|
89
|
+
}, "toModelRate");
|
|
90
|
+
var decodeOgg = /* @__PURE__ */ __name(async (bytes) => {
|
|
91
|
+
checkOggDuration(bytes);
|
|
92
|
+
const { OggOpusDecoder } = await importFrom(new URL("speech/recognize.js", import.meta.resolve("@wirecat/cli-core")).href, "ogg-opus-decoder");
|
|
93
|
+
const decoder = new OggOpusDecoder();
|
|
94
|
+
await decoder.ready;
|
|
95
|
+
try {
|
|
96
|
+
const { channelData, sampleRate, samplesDecoded } = await decoder.decodeFile(bytes);
|
|
97
|
+
if (!channelData[0] || samplesDecoded === 0)
|
|
98
|
+
throw new Error("no Ogg Opus audio in it");
|
|
99
|
+
return channelData.map((samples) => ({ samples, rate: sampleRate }));
|
|
100
|
+
} finally {
|
|
101
|
+
decoder.free();
|
|
102
|
+
}
|
|
103
|
+
}, "decodeOgg");
|
|
104
|
+
var WINDOW = 512;
|
|
105
|
+
var detector = /* @__PURE__ */ __name((vadModel) => ({
|
|
106
|
+
sileroVad: {
|
|
107
|
+
model: vadModel,
|
|
108
|
+
// At the default 0.5 a quietly spoken stretch in the middle of a voice message never counted as
|
|
109
|
+
// speech and was lost; 0.3 keeps it for both models and changes nothing on clear speech (126508, 2026-09-30).
|
|
110
|
+
threshold: 0.3,
|
|
111
|
+
minSilenceDuration: 0.5,
|
|
112
|
+
minSpeechDuration: 0.25,
|
|
113
|
+
maxSpeechDuration: 20,
|
|
114
|
+
windowSize: WINDOW
|
|
115
|
+
},
|
|
116
|
+
sampleRate: SAMPLE_RATE,
|
|
117
|
+
numThreads: 1,
|
|
118
|
+
provider: "cpu",
|
|
119
|
+
debug: 0,
|
|
120
|
+
bufferSizeInSeconds: 30
|
|
121
|
+
}), "detector");
|
|
122
|
+
var cut = /* @__PURE__ */ __name((vad, pcm, each) => {
|
|
123
|
+
vad.reset();
|
|
124
|
+
const last = Math.max(0, pcm.length - LEAD);
|
|
125
|
+
const drain = /* @__PURE__ */ __name(() => {
|
|
126
|
+
for (; !vad.isEmpty(); vad.pop()) {
|
|
127
|
+
const { start, samples } = vad.front();
|
|
128
|
+
each({
|
|
129
|
+
start: Math.min(last, Math.max(0, start - LEAD)) / SAMPLE_RATE,
|
|
130
|
+
end: Math.min(last, Math.max(0, start + samples.length - LEAD)) / SAMPLE_RATE,
|
|
131
|
+
samples
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}, "drain");
|
|
135
|
+
for (let i = 0; i + WINDOW <= pcm.length; i += WINDOW) {
|
|
136
|
+
vad.acceptWaveform(pcm.subarray(i, i + WINDOW));
|
|
137
|
+
drain();
|
|
138
|
+
}
|
|
139
|
+
vad.flush();
|
|
140
|
+
drain();
|
|
141
|
+
}, "cut");
|
|
142
|
+
var openSpeechCutter = /* @__PURE__ */ __name((vadModel) => {
|
|
143
|
+
const vad = loadSherpa().createVad(detector(vadModel));
|
|
144
|
+
return {
|
|
145
|
+
cut: /* @__PURE__ */ __name((pcm) => {
|
|
146
|
+
const spans = [];
|
|
147
|
+
cut(vad, pcm, ({ start, end }) => spans.push({ start, end }));
|
|
148
|
+
return spans;
|
|
149
|
+
}, "cut"),
|
|
150
|
+
free: /* @__PURE__ */ __name(() => vad.free(), "free")
|
|
151
|
+
};
|
|
152
|
+
}, "openSpeechCutter");
|
|
153
|
+
var loaded;
|
|
154
|
+
var loadSherpa = /* @__PURE__ */ __name(() => {
|
|
155
|
+
if (loaded)
|
|
156
|
+
return loaded;
|
|
157
|
+
const load = createRequire(new URL("speech/recognize.js", import.meta.resolve("@wirecat/cli-core")).href);
|
|
158
|
+
const wasm = {};
|
|
159
|
+
load("sherpa-onnx/sherpa-onnx-wasm-nodejs.js")(wasm);
|
|
160
|
+
const stdout = wasm.FS?.getStream(1);
|
|
161
|
+
if (stdout)
|
|
162
|
+
stdout.nfd = 2;
|
|
163
|
+
const asr = load("sherpa-onnx/sherpa-onnx-asr.js");
|
|
164
|
+
const vad = load("sherpa-onnx/sherpa-onnx-vad.js");
|
|
165
|
+
loaded = {
|
|
166
|
+
createOfflineRecognizer: /* @__PURE__ */ __name((config) => new asr.OfflineRecognizer(config, wasm), "createOfflineRecognizer"),
|
|
167
|
+
createVad: /* @__PURE__ */ __name((config) => vad.createVad(wasm, config), "createVad")
|
|
168
|
+
};
|
|
169
|
+
return loaded;
|
|
170
|
+
}, "loadSherpa");
|
|
171
|
+
var openRecognizer = /* @__PURE__ */ __name((model, path, vadModel) => {
|
|
172
|
+
const sherpa = loadSherpa();
|
|
173
|
+
const engine = sherpa.createOfflineRecognizer({
|
|
174
|
+
featConfig: { sampleRate: SAMPLE_RATE, featureDim: model.featureDim },
|
|
175
|
+
modelConfig: { ...model.config(path), numThreads: 1, provider: "cpu", debug: 0 },
|
|
176
|
+
decodingMethod: "greedy_search"
|
|
177
|
+
});
|
|
178
|
+
const vad = sherpa.createVad(detector(vadModel));
|
|
179
|
+
const piece = /* @__PURE__ */ __name((samples) => {
|
|
180
|
+
const stream = engine.createStream();
|
|
181
|
+
try {
|
|
182
|
+
stream.acceptWaveform(SAMPLE_RATE, samples);
|
|
183
|
+
engine.decode(stream);
|
|
184
|
+
return engine.getResult(stream).text.trim();
|
|
185
|
+
} finally {
|
|
186
|
+
stream.free();
|
|
187
|
+
}
|
|
188
|
+
}, "piece");
|
|
189
|
+
const pieces = /* @__PURE__ */ __name((pcm) => {
|
|
190
|
+
const heard = [];
|
|
191
|
+
cut(vad, pcm, ({ start, end, samples }) => {
|
|
192
|
+
const text = piece(samples);
|
|
193
|
+
if (text)
|
|
194
|
+
heard.push({ start, end, text });
|
|
195
|
+
});
|
|
196
|
+
return heard;
|
|
197
|
+
}, "pieces");
|
|
198
|
+
const piecesUntil = /* @__PURE__ */ __name(async (pcm, signal) => {
|
|
199
|
+
const spans = [];
|
|
200
|
+
cut(vad, pcm, (span) => spans.push(span));
|
|
201
|
+
const heard = [];
|
|
202
|
+
for (const { start, end, samples } of spans) {
|
|
203
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
204
|
+
signal.throwIfAborted();
|
|
205
|
+
const text = piece(samples);
|
|
206
|
+
if (text)
|
|
207
|
+
heard.push({ start, end, text });
|
|
208
|
+
}
|
|
209
|
+
return heard;
|
|
210
|
+
}, "piecesUntil");
|
|
211
|
+
return {
|
|
212
|
+
recognize: /* @__PURE__ */ __name((pcm) => pieces(pcm).map(({ text }) => text).join(" "), "recognize"),
|
|
213
|
+
pieces,
|
|
214
|
+
piecesUntil,
|
|
215
|
+
free: /* @__PURE__ */ __name(() => {
|
|
216
|
+
vad.free();
|
|
217
|
+
engine.free();
|
|
218
|
+
}, "free")
|
|
219
|
+
};
|
|
220
|
+
}, "openRecognizer");
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
SAMPLE_RATE,
|
|
224
|
+
toModelRate,
|
|
225
|
+
decodeOgg,
|
|
226
|
+
detector,
|
|
227
|
+
openSpeechCutter,
|
|
228
|
+
loadSherpa,
|
|
229
|
+
openRecognizer
|
|
230
|
+
};
|