@agentdocumentformat/cli 0.7.2

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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -0
  3. package/dist/adf.mjs +162 -0
  4. package/dist/chunks/APEv2Parser-2CNNHMXV.mjs +22 -0
  5. package/dist/chunks/AiffParser-7BR4RL6G.mjs +162 -0
  6. package/dist/chunks/App-L5L37JI5.mjs +16747 -0
  7. package/dist/chunks/AsfParser-VVRSLFOM.mjs +538 -0
  8. package/dist/chunks/DsdiffParser-CMD4AX7A.mjs +156 -0
  9. package/dist/chunks/DsfParser-UOGZDS2M.mjs +94 -0
  10. package/dist/chunks/FlacParser-HB3T3CD4.mjs +23 -0
  11. package/dist/chunks/MP4Parser-66HBRUSX.mjs +973 -0
  12. package/dist/chunks/MatroskaParser-J3HUIMEW.mjs +579 -0
  13. package/dist/chunks/MpegParser-YW6LIUEW.mjs +442 -0
  14. package/dist/chunks/MusepackParser-PAUSXP7D.mjs +252 -0
  15. package/dist/chunks/OggParser-NUBV3GWC.mjs +359 -0
  16. package/dist/chunks/WavPackParser-WQAGT7TC.mjs +171 -0
  17. package/dist/chunks/WaveParser-EWLQVDX4.mjs +238 -0
  18. package/dist/chunks/adf-schema-JRU2BTOG.mjs +62 -0
  19. package/dist/chunks/build-QF5W473T.mjs +60 -0
  20. package/dist/chunks/chatgpt-subscription-BQGWYZXE.mjs +23 -0
  21. package/dist/chunks/chunk-2DIECGFL.mjs +6 -0
  22. package/dist/chunks/chunk-2NAP2ZF7.mjs +60 -0
  23. package/dist/chunks/chunk-3AT7IIP7.mjs +25696 -0
  24. package/dist/chunks/chunk-3GNIDM53.mjs +35 -0
  25. package/dist/chunks/chunk-3M4ZPOA3.mjs +1477 -0
  26. package/dist/chunks/chunk-4MQPTCXY.mjs +510 -0
  27. package/dist/chunks/chunk-5PO5PKRV.mjs +366 -0
  28. package/dist/chunks/chunk-5QU5VY7N.mjs +52 -0
  29. package/dist/chunks/chunk-5W7KES6P.mjs +436 -0
  30. package/dist/chunks/chunk-62NE4LG4.mjs +61 -0
  31. package/dist/chunks/chunk-64OKE4X3.mjs +45 -0
  32. package/dist/chunks/chunk-6GJ4QHRI.mjs +1278 -0
  33. package/dist/chunks/chunk-6VQEXLE2.mjs +144 -0
  34. package/dist/chunks/chunk-6XUV6EK6.mjs +41 -0
  35. package/dist/chunks/chunk-776TSXEP.mjs +43 -0
  36. package/dist/chunks/chunk-7CV2SA3H.mjs +285 -0
  37. package/dist/chunks/chunk-7MTRVW2U.mjs +3103 -0
  38. package/dist/chunks/chunk-7N2R2VCG.mjs +1434 -0
  39. package/dist/chunks/chunk-7T2YMTWL.mjs +374 -0
  40. package/dist/chunks/chunk-7XYNI52E.mjs +149 -0
  41. package/dist/chunks/chunk-APHX6HSV.mjs +7731 -0
  42. package/dist/chunks/chunk-APRU6PHC.mjs +40 -0
  43. package/dist/chunks/chunk-AUYKRQPJ.mjs +499 -0
  44. package/dist/chunks/chunk-DXWDD5XJ.mjs +136 -0
  45. package/dist/chunks/chunk-EWL5FG4I.mjs +39 -0
  46. package/dist/chunks/chunk-EYX2YLJW.mjs +117 -0
  47. package/dist/chunks/chunk-F5ELW46V.mjs +27 -0
  48. package/dist/chunks/chunk-G426FACA.mjs +49 -0
  49. package/dist/chunks/chunk-GEKSJHIV.mjs +2472 -0
  50. package/dist/chunks/chunk-HBUENVQL.mjs +570 -0
  51. package/dist/chunks/chunk-HPVFJYXR.mjs +112 -0
  52. package/dist/chunks/chunk-HWLWPXQ7.mjs +721 -0
  53. package/dist/chunks/chunk-I2HJYHFT.mjs +665 -0
  54. package/dist/chunks/chunk-I3UYSITV.mjs +68 -0
  55. package/dist/chunks/chunk-IC4JDZCI.mjs +3864 -0
  56. package/dist/chunks/chunk-IHDDCZBS.mjs +112 -0
  57. package/dist/chunks/chunk-IIGMZHQQ.mjs +10416 -0
  58. package/dist/chunks/chunk-KWFOS5WC.mjs +41 -0
  59. package/dist/chunks/chunk-LAZIXV2F.mjs +5290 -0
  60. package/dist/chunks/chunk-LFMB4PAA.mjs +10814 -0
  61. package/dist/chunks/chunk-M2RX3S2T.mjs +49 -0
  62. package/dist/chunks/chunk-M3WPIJYM.mjs +65 -0
  63. package/dist/chunks/chunk-NBTUWMGP.mjs +263 -0
  64. package/dist/chunks/chunk-NGK6PVSF.mjs +2676 -0
  65. package/dist/chunks/chunk-NZ7JTHEO.mjs +85 -0
  66. package/dist/chunks/chunk-OQN33RGQ.mjs +52 -0
  67. package/dist/chunks/chunk-RIX34QHC.mjs +2935 -0
  68. package/dist/chunks/chunk-SGUTYISF.mjs +16 -0
  69. package/dist/chunks/chunk-SLJ5L7PY.mjs +1473 -0
  70. package/dist/chunks/chunk-SLUKGXKH.mjs +68 -0
  71. package/dist/chunks/chunk-TMT32MXT.mjs +419 -0
  72. package/dist/chunks/chunk-UYY5M2PB.mjs +151 -0
  73. package/dist/chunks/chunk-VAUOM3IN.mjs +298 -0
  74. package/dist/chunks/chunk-VMHTYDH4.mjs +172 -0
  75. package/dist/chunks/chunk-VZS54AA5.mjs +200 -0
  76. package/dist/chunks/chunk-WFQUVXML.mjs +295 -0
  77. package/dist/chunks/chunk-X34PDRUH.mjs +809 -0
  78. package/dist/chunks/chunk-XNPZBLYL.mjs +33 -0
  79. package/dist/chunks/chunk-XX7OSWTO.mjs +157 -0
  80. package/dist/chunks/chunk-XYTWGHFS.mjs +600 -0
  81. package/dist/chunks/chunk-XYV3VCIX.mjs +336 -0
  82. package/dist/chunks/chunk-Y5ZLKFLE.mjs +1469 -0
  83. package/dist/chunks/chunk-ZJKXHM4Q.mjs +230 -0
  84. package/dist/chunks/cli-TCMBNZF6.mjs +1030 -0
  85. package/dist/chunks/commands-DTEKM4ZL.mjs +20 -0
  86. package/dist/chunks/daemon-ZC3FZ2P4.mjs +112449 -0
  87. package/dist/chunks/daemon-control-WDX7PMTC.mjs +300 -0
  88. package/dist/chunks/daemon-token-WRSULP7G.mjs +23 -0
  89. package/dist/chunks/devtools-H7CI2ZVG.mjs +85 -0
  90. package/dist/chunks/discord-IWDQJA7A.mjs +70588 -0
  91. package/dist/chunks/dist-C57KYFS2.mjs +4952 -0
  92. package/dist/chunks/dist-I3XBAGDL.mjs +11 -0
  93. package/dist/chunks/email-V4Q4VJON.mjs +58679 -0
  94. package/dist/chunks/environment-NX277MQG.mjs +15 -0
  95. package/dist/chunks/grok-subscription-4PYX7TBF.mjs +19 -0
  96. package/dist/chunks/layout-EPJQNFAI.mjs +22 -0
  97. package/dist/chunks/lib-N7FCZWKH.mjs +4038 -0
  98. package/dist/chunks/open-OTQDGDH5.mjs +36 -0
  99. package/dist/chunks/parser-JVY2PWSM.mjs +19 -0
  100. package/dist/chunks/pipeline-executor-BHBSJX2K.mjs +19 -0
  101. package/dist/chunks/react-IUIDQ5LX.mjs +11 -0
  102. package/dist/chunks/screen-54BUTYCW.mjs +27 -0
  103. package/dist/chunks/slack-3L5QTDZX.mjs +8113 -0
  104. package/dist/chunks/store-WR7TZJZS.mjs +32 -0
  105. package/dist/chunks/telegram-5ISVFBV3.mjs +14918 -0
  106. package/dist/chunks/terminal-O5WO7C5U.mjs +48 -0
  107. package/dist/chunks/theme-NORU4J74.mjs +20 -0
  108. package/dist/chunks/themes-F2FKU7CP.mjs +23 -0
  109. package/dist/chunks/token-6G3HCMNX.mjs +54 -0
  110. package/dist/chunks/token-util-UXYSDQIW.mjs +12 -0
  111. package/dist/chunks/tui-ODVYUIMT.mjs +197 -0
  112. package/dist/chunks/welcome-XHXFV7SH.mjs +32 -0
  113. package/dist/chunks/whatsapp-XSAMNGPJ.mjs +85412 -0
  114. package/dist/chunks/xterm-headless-YF53XWXE.mjs +3353 -0
  115. package/package.json +53 -0
  116. package/resources/wasm/coreutils.LICENSE +18 -0
  117. package/resources/wasm/coreutils.wasm +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christian Balevski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @agentdocumentformat/cli
2
+
3
+ The ADF CLI: the ADF (Agent Document Format) daemon, command line and terminal app. An ADF agent is a single `.adf` file: config, memory, files and history in one document. This package runs your agents headless from a terminal, with no desktop app. For the desktop app (ADF Studio), see the [releases](https://github.com/christianbalevski/adf/releases).
4
+
5
+ ## Install
6
+
7
+ Requires Node.js 22 or newer.
8
+
9
+ ```bash
10
+ npm i -g @agentdocumentformat/cli
11
+ adf
12
+ ```
13
+
14
+ Native modules (SQLite, OS keychain) install from prebuilt binaries; no compiler is needed on Windows, macOS (arm64/x64) or Linux (x64/arm64, glibc).
15
+
16
+ ## Use
17
+
18
+ ```bash
19
+ adf # the terminal app; starts the daemon in the background if needed
20
+ adf agents # one-shot CLI commands; `adf help` lists them
21
+ adf daemon status # the background daemon: status | stop | restart | logs -f
22
+ adf daemon # or run the daemon in the foreground (http://127.0.0.1:7385)
23
+ adf --version
24
+ ```
25
+
26
+ The daemon keeps running after you quit the terminal app (`adf daemon stop` stops it gracefully). It is only started automatically for a daemon URL on this machine, never next to a running ADF Studio, and not with `--no-daemon` / `ADF_NO_AUTOSTART=1`. `adf --url http://127.0.0.1:7400` (or `ADF_DAEMON_URL`) targets, and if needed starts, a daemon on another port. Other daemon settings: `ADF_DAEMON_HOST`, `ADF_DAEMON_SETTINGS` (settings JSON path), `ADF_USER_DATA_DIR`, `ADF_DAEMON_TOKEN` (required off loopback).
27
+
28
+ The daemon shares its settings file with ADF Studio on the same machine by default, so providers and tracked directories you set up in Studio carry over.
29
+
30
+ ## Identity and sign-in
31
+
32
+ - `adf identity` shows the owner identity status; `adf identity create` / `adf identity restore` sets it up (the seed phrase is typed at a hidden prompt; the same phrase as Studio means the same owner). The phrase is kept in the OS keychain, or a passphrase-protected file where no keychain exists (`adf identity unlock`).
33
+ - `adf providers` lists model providers; `adf auth <provider>` signs in to subscription providers (ChatGPT, Grok) from the terminal.
34
+ - `adf new` creates an agent from a template, sealed with the owner identity.
35
+
36
+ ## Docs
37
+
38
+ - [Daemon getting started](https://github.com/christianbalevski/adf/blob/main/docs/daemon/getting-started.md)
39
+ - [CLI reference](https://github.com/christianbalevski/adf/blob/main/docs/daemon/cli.md)
40
+ - [Terminal app](https://github.com/christianbalevski/adf/blob/main/docs/daemon/tui.md)
41
+ - [HTTP API](https://github.com/christianbalevski/adf/blob/main/docs/daemon/http-api.md)
42
+
43
+ ## License
44
+
45
+ MIT
package/dist/adf.mjs ADDED
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __adfCreateRequire } from 'node:module';
3
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
4
+ import { dirname as __adfDirname } from 'node:path';
5
+ const require = __adfCreateRequire(import.meta.url);
6
+ const __filename = __adfFileURLToPath(import.meta.url);
7
+ const __dirname = __adfDirname(__filename);
8
+ import "./chunks/chunk-M2RX3S2T.mjs";
9
+
10
+ // src/main/cli/bin.ts
11
+ function version() {
12
+ return "0.7.2";
13
+ }
14
+ var DAEMON_HELP = `Usage: adf daemon [--port <n>] [--host <h>] [--settings <file>]
15
+ adf daemon start [--port <n>] [--force]
16
+ adf daemon status | stop | restart [--port <n>]
17
+ adf daemon logs [-f] [-n <lines>] [--port <n>]
18
+ adf daemon token
19
+
20
+ Without a subcommand the daemon runs in the foreground (Ctrl+C stops it).
21
+ start runs it in the background, like adf does on its own when it needs one;
22
+ the log goes to <data dir>/logs/adf-daemon.log. stop is graceful: agents are
23
+ unloaded and compute containers stopped.
24
+
25
+ Every request but GET /health needs the daemon's access token. adf reads it
26
+ on this machine by itself (<data dir>/daemon-token, created on first start);
27
+ token prints it for a client elsewhere (--token or ADF_DAEMON_TOKEN there).
28
+ ADF_DAEMON_TOKEN overrides the file, and is required with a non-loopback
29
+ --host (plus ADF_DAEMON_ALLOWED_HOSTS for host names clients use).
30
+
31
+ Environment: ADF_DAEMON_PORT, ADF_DAEMON_HOST, ADF_DAEMON_SETTINGS,
32
+ ADF_USER_DATA_DIR, ADF_DAEMON_PIDFILE, ADF_DAEMON_TOKEN,
33
+ ADF_DAEMON_ALLOWED_HOSTS`;
34
+ function applyDaemonArgs(args, env = process.env) {
35
+ for (let i = 0; i < args.length; i++) {
36
+ let arg = args[i], [flag, inline] = arg.startsWith("--") && arg.includes("=") ? [arg.slice(0, arg.indexOf("=")), arg.slice(arg.indexOf("=") + 1)] : [arg, void 0], value = () => {
37
+ let v = inline ?? args[++i];
38
+ if (v === void 0) throw new Error(`${flag} requires a value`);
39
+ return v;
40
+ };
41
+ if (flag === "--port" || flag === "-p") env.ADF_DAEMON_PORT = value();
42
+ else if (flag === "--host") env.ADF_DAEMON_HOST = value();
43
+ else if (flag === "--settings") env.ADF_DAEMON_SETTINGS = value();
44
+ else throw new Error(`Unknown daemon option: ${arg}
45
+
46
+ ${DAEMON_HELP}`);
47
+ }
48
+ }
49
+ var DAEMON_SUBCOMMANDS = /* @__PURE__ */ new Set(["start", "status", "stop", "restart", "logs", "token"]);
50
+ async function daemonSubcommand(sub, args) {
51
+ let control = await import("./chunks/daemon-control-WDX7PMTC.mjs"), out = (text) => {
52
+ process.stdout.write(text);
53
+ }, { url, rest } = control.daemonUrlFrom(args), target = control.daemonTarget(url), force = rest.includes("--force"), start = async () => {
54
+ if (await control.isHealthy(target.url))
55
+ return out(`The ADF daemon is already running at ${target.url}.
56
+ `), 0;
57
+ try {
58
+ return await control.startDaemon(target, { force }), 0;
59
+ } catch (err) {
60
+ let advice = err.advice;
61
+ return process.stderr.write(`${err instanceof Error ? err.message : String(err)}
62
+ ${advice ? `${advice}
63
+ ` : ""}`), 1;
64
+ }
65
+ };
66
+ switch (sub) {
67
+ case "start":
68
+ return await start();
69
+ case "status": {
70
+ let { running, lines } = await control.daemonStatus(target);
71
+ return out(`${lines.join(`
72
+ `)}
73
+ `), running ? 0 : 3;
74
+ }
75
+ case "stop": {
76
+ out(`Stopping the ADF daemon at ${target.url}\u2026
77
+ `);
78
+ let result = await control.stopDaemon(target);
79
+ return out(`${result.message}
80
+ `), result.stopped ? 0 : 1;
81
+ }
82
+ case "restart": {
83
+ if (await control.isHealthy(target.url)) {
84
+ out(`Stopping the ADF daemon at ${target.url}\u2026
85
+ `);
86
+ let result = await control.stopDaemon(target);
87
+ if (out(`${result.message}
88
+ `), !result.stopped) return 1;
89
+ }
90
+ return await start();
91
+ }
92
+ case "token": {
93
+ if (process.env.ADF_DAEMON_TOKEN)
94
+ return process.stderr.write(`(from ADF_DAEMON_TOKEN)
95
+ `), out(`${process.env.ADF_DAEMON_TOKEN}
96
+ `), 0;
97
+ let { ensureDaemonToken } = await import("./chunks/daemon-token-WRSULP7G.mjs"), { token, path } = ensureDaemonToken(control.daemonPaths(target.port).dataDir);
98
+ return process.stderr.write(`(${path})
99
+ `), out(`${token}
100
+ `), 0;
101
+ }
102
+ case "logs": {
103
+ let follow = rest.includes("-f") || rest.includes("--follow"), at = rest.findIndex((a) => a === "-n" || a === "--lines"), lines = at >= 0 && Number(rest[at + 1]) || 50, file = control.daemonPaths(target.port).logFile;
104
+ if (!follow) {
105
+ let tail = control.tailLines(file, lines);
106
+ return out(tail ? `${tail}
107
+ ` : `No log yet at ${file} (it is written by a daemon adf started in the background).
108
+ `), 0;
109
+ }
110
+ return out(`${file} (Ctrl+C stops following)
111
+ `), await control.followLog(file, { lines, follow: !0, write: out }), 0;
112
+ }
113
+ }
114
+ return 2;
115
+ }
116
+ async function main(argv) {
117
+ if (Number(process.versions.node.split(".")[0]) < 22)
118
+ return process.stderr.write(`adf needs Node.js 22 or newer (this is ${process.version}).
119
+ `), 1;
120
+ let noDaemon = argv.includes("--no-daemon");
121
+ noDaemon && (argv = argv.filter((a) => a !== "--no-daemon"));
122
+ let [command, ...rest] = argv;
123
+ if (command === "--version" || command === "-v" || command === "version")
124
+ return process.stdout.write(`${version()}
125
+ `), 0;
126
+ if (command === "daemon") {
127
+ if (rest.includes("--help") || rest.includes("-h"))
128
+ return process.stdout.write(`${DAEMON_HELP}
129
+ `), 0;
130
+ if (rest[0] && DAEMON_SUBCOMMANDS.has(rest[0])) return await daemonSubcommand(rest[0], rest.slice(1));
131
+ try {
132
+ applyDaemonArgs(rest);
133
+ } catch (err) {
134
+ return process.stderr.write(`${err instanceof Error ? err.message : String(err)}
135
+ `), 2;
136
+ }
137
+ if (!process.env.ADF_DAEMON_PIDFILE) {
138
+ let { daemonPaths } = await import("./chunks/daemon-control-WDX7PMTC.mjs");
139
+ process.env.ADF_DAEMON_PIDFILE = daemonPaths(Number(process.env.ADF_DAEMON_PORT ?? 7385)).pidFile;
140
+ }
141
+ return await import("./chunks/daemon-ZC3FZ2P4.mjs"), -1;
142
+ }
143
+ let [{ runCli, tuiInvocation }, control] = await Promise.all([import("./chunks/cli-TCMBNZF6.mjs"), import("./chunks/daemon-control-WDX7PMTC.mjs")]);
144
+ return tuiInvocation(argv) && process.env.NODE_ENV === void 0 && (process.env.NODE_ENV = "production", process.env.ADF_NODE_ENV_DEFAULTED = "1"), await runCli(argv, {
145
+ fetch: globalThis.fetch.bind(globalThis),
146
+ stdout: (text) => process.stdout.write(text),
147
+ stderr: (text) => process.stderr.write(text),
148
+ ensureDaemon: (url) => control.ensureDaemon(url, { disabled: noDaemon })
149
+ });
150
+ }
151
+ main(process.argv.slice(2)).then(
152
+ (code) => {
153
+ code >= 0 && (process.exitCode = code);
154
+ },
155
+ (err) => {
156
+ process.stderr.write(`${err instanceof Error ? err.stack ?? err.message : String(err)}
157
+ `), process.exitCode = 1;
158
+ }
159
+ );
160
+ export {
161
+ applyDaemonArgs
162
+ };
@@ -0,0 +1,22 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ APEv2Parser,
9
+ ApeContentError,
10
+ tryParseApeHeader
11
+ } from "./chunk-NBTUWMGP.mjs";
12
+ import "./chunk-XX7OSWTO.mjs";
13
+ import "./chunk-HBUENVQL.mjs";
14
+ import "./chunk-I2HJYHFT.mjs";
15
+ import "./chunk-AUYKRQPJ.mjs";
16
+ import "./chunk-NZ7JTHEO.mjs";
17
+ import "./chunk-M2RX3S2T.mjs";
18
+ export {
19
+ APEv2Parser,
20
+ ApeContentError,
21
+ tryParseApeHeader
22
+ };
@@ -0,0 +1,162 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ ID3v2Parser
9
+ } from "./chunk-XYTWGHFS.mjs";
10
+ import "./chunk-VAUOM3IN.mjs";
11
+ import "./chunk-DXWDD5XJ.mjs";
12
+ import {
13
+ FourCcToken
14
+ } from "./chunk-NBTUWMGP.mjs";
15
+ import "./chunk-XX7OSWTO.mjs";
16
+ import {
17
+ EndOfStreamError,
18
+ fromBuffer
19
+ } from "./chunk-HBUENVQL.mjs";
20
+ import {
21
+ BasicParser,
22
+ StringType,
23
+ UINT16_BE,
24
+ UINT32_BE,
25
+ UINT8,
26
+ Uint8ArrayType,
27
+ makeUnexpectedFileContentError
28
+ } from "./chunk-I2HJYHFT.mjs";
29
+ import {
30
+ require_src
31
+ } from "./chunk-AUYKRQPJ.mjs";
32
+ import "./chunk-NZ7JTHEO.mjs";
33
+ import {
34
+ __toESM
35
+ } from "./chunk-M2RX3S2T.mjs";
36
+
37
+ // node_modules/music-metadata/lib/aiff/AiffParser.js
38
+ var import_debug = __toESM(require_src(), 1);
39
+
40
+ // node_modules/music-metadata/lib/aiff/AiffToken.js
41
+ var compressionTypes = {
42
+ NONE: "not compressed PCM Apple Computer",
43
+ sowt: "PCM (byte swapped)",
44
+ fl32: "32-bit floating point IEEE 32-bit float",
45
+ fl64: "64-bit floating point IEEE 64-bit float Apple Computer",
46
+ alaw: "ALaw 2:1 8-bit ITU-T G.711 A-law",
47
+ ulaw: "\xB5Law 2:1 8-bit ITU-T G.711 \xB5-law Apple Computer",
48
+ ULAW: "CCITT G.711 u-law 8-bit ITU-T G.711 \xB5-law",
49
+ ALAW: "CCITT G.711 A-law 8-bit ITU-T G.711 A-law",
50
+ FL32: "Float 32 IEEE 32-bit float "
51
+ }, AiffContentError = class extends makeUnexpectedFileContentError("AIFF") {
52
+ }, Common = class {
53
+ constructor(header, isAifc) {
54
+ this.isAifc = isAifc;
55
+ let minimumChunkSize = isAifc ? 22 : 18;
56
+ if (header.chunkSize < minimumChunkSize)
57
+ throw new AiffContentError(`COMMON CHUNK size should always be at least ${minimumChunkSize}`);
58
+ this.len = header.chunkSize;
59
+ }
60
+ get(buf, off) {
61
+ let shift = UINT16_BE.get(buf, off + 8) - 16398, baseSampleRate = UINT16_BE.get(buf, off + 8 + 2), res = {
62
+ numChannels: UINT16_BE.get(buf, off),
63
+ numSampleFrames: UINT32_BE.get(buf, off + 2),
64
+ sampleSize: UINT16_BE.get(buf, off + 6),
65
+ sampleRate: shift < 0 ? baseSampleRate >> Math.abs(shift) : baseSampleRate << shift
66
+ };
67
+ if (this.isAifc) {
68
+ if (res.compressionType = FourCcToken.get(buf, off + 18), this.len > 22) {
69
+ let strLen = UINT8.get(buf, off + 22);
70
+ if (strLen > 0) {
71
+ let padding = (strLen + 1) % 2;
72
+ if (23 + strLen + padding === this.len)
73
+ res.compressionName = new StringType(strLen, "latin1").get(buf, off + 23);
74
+ else
75
+ throw new AiffContentError("Illegal pstring length");
76
+ } else
77
+ res.compressionName = void 0;
78
+ }
79
+ } else
80
+ res.compressionName = "PCM";
81
+ return res;
82
+ }
83
+ };
84
+
85
+ // node_modules/music-metadata/lib/iff/index.js
86
+ var Header = {
87
+ len: 8,
88
+ get: (buf, off) => ({
89
+ // Chunk type ID
90
+ chunkID: FourCcToken.get(buf, off),
91
+ // Chunk size
92
+ chunkSize: Number(BigInt(UINT32_BE.get(buf, off + 4)))
93
+ })
94
+ };
95
+
96
+ // node_modules/music-metadata/lib/aiff/AiffParser.js
97
+ var debug = (0, import_debug.default)("music-metadata:parser:aiff"), AIFFParser = class extends BasicParser {
98
+ constructor() {
99
+ super(...arguments), this.isCompressed = null;
100
+ }
101
+ async parse() {
102
+ if ((await this.tokenizer.readToken(Header)).chunkID !== "FORM")
103
+ throw new AiffContentError("Invalid Chunk-ID, expected 'FORM'");
104
+ let type = await this.tokenizer.readToken(FourCcToken);
105
+ switch (type) {
106
+ case "AIFF":
107
+ this.metadata.setFormat("container", type), this.isCompressed = !1;
108
+ break;
109
+ case "AIFC":
110
+ this.metadata.setFormat("container", "AIFF-C"), this.isCompressed = !0;
111
+ break;
112
+ default:
113
+ throw new AiffContentError(`Unsupported AIFF type: ${type}`);
114
+ }
115
+ this.metadata.setFormat("lossless", !this.isCompressed), this.metadata.setAudioOnly();
116
+ try {
117
+ for (; !this.tokenizer.fileInfo.size || this.tokenizer.fileInfo.size - this.tokenizer.position >= Header.len; ) {
118
+ debug(`Reading AIFF chunk at offset=${this.tokenizer.position}`);
119
+ let chunkHeader = await this.tokenizer.readToken(Header), nextChunk = 2 * Math.round(chunkHeader.chunkSize / 2), bytesRead = await this.readData(chunkHeader);
120
+ await this.tokenizer.ignore(nextChunk - bytesRead);
121
+ }
122
+ } catch (err) {
123
+ if (err instanceof EndOfStreamError)
124
+ debug("End-of-stream");
125
+ else
126
+ throw err;
127
+ }
128
+ }
129
+ async readData(header) {
130
+ switch (header.chunkID) {
131
+ case "COMM": {
132
+ if (this.isCompressed === null)
133
+ throw new AiffContentError("Failed to parse AIFF.COMM chunk when compression type is unknown");
134
+ let common = await this.tokenizer.readToken(new Common(header, this.isCompressed));
135
+ return this.metadata.setFormat("bitsPerSample", common.sampleSize), this.metadata.setFormat("sampleRate", common.sampleRate), this.metadata.setFormat("numberOfChannels", common.numChannels), this.metadata.setFormat("numberOfSamples", common.numSampleFrames), this.metadata.setFormat("duration", common.numSampleFrames / common.sampleRate), (common.compressionName || common.compressionType) && this.metadata.setFormat("codec", common.compressionName ?? compressionTypes[common.compressionType]), header.chunkSize;
136
+ }
137
+ case "ID3 ": {
138
+ let id3_data = await this.tokenizer.readToken(new Uint8ArrayType(header.chunkSize)), rst = fromBuffer(id3_data);
139
+ return await new ID3v2Parser().parse(this.metadata, rst, this.options), header.chunkSize;
140
+ }
141
+ case "SSND":
142
+ return this.metadata.format.duration && this.metadata.setFormat("bitrate", 8 * header.chunkSize / this.metadata.format.duration), 0;
143
+ case "NAME":
144
+ // Sample name chunk
145
+ case "AUTH":
146
+ // Author chunk
147
+ case "(c) ":
148
+ // Copyright chunk
149
+ case "ANNO":
150
+ return this.readTextChunk(header);
151
+ default:
152
+ return debug(`Ignore chunk id=${header.chunkID}, size=${header.chunkSize}`), 0;
153
+ }
154
+ }
155
+ async readTextChunk(header) {
156
+ let values = (await this.tokenizer.readToken(new StringType(header.chunkSize, "ascii"))).split("\0").map((v) => v.trim()).filter((v) => v?.length);
157
+ return await Promise.all(values.map((v) => this.metadata.addTag("AIFF", header.chunkID, v))), header.chunkSize;
158
+ }
159
+ };
160
+ export {
161
+ AIFFParser
162
+ };