stitchkit 0.123.2 → 0.123.4

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 (36) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/agent-runtime/sandbox-broker.d.ts.map +1 -1
  3. package/dist/entrypoints/agent-runtime/sandbox.js +16 -4
  4. package/dist/entrypoints/files.d.ts +1 -0
  5. package/dist/entrypoints/files.d.ts.map +1 -1
  6. package/dist/entrypoints/files.js +4 -0
  7. package/dist/entrypoints/server.js +33 -20
  8. package/dist/entrypoints/telegram/voice.d.ts +2 -0
  9. package/dist/entrypoints/telegram/voice.d.ts.map +1 -0
  10. package/dist/entrypoints/telegram/voice.js +18 -0
  11. package/dist/entrypoints/telegram.d.ts +1 -0
  12. package/dist/entrypoints/telegram.d.ts.map +1 -1
  13. package/dist/entrypoints/telegram.js +43 -0
  14. package/dist/entrypoints/tracking/performance.js +3 -3
  15. package/dist/index-0jdempdr.js +69 -0
  16. package/dist/index-drcjjhy1.js +40 -0
  17. package/dist/internal/unix-socket.d.ts +28 -0
  18. package/dist/internal/unix-socket.d.ts.map +1 -0
  19. package/dist/server/bun.d.ts +5 -4
  20. package/dist/server/bun.d.ts.map +1 -1
  21. package/dist/telegram/voice-waveform-pcm.d.ts +21 -0
  22. package/dist/telegram/voice-waveform-pcm.d.ts.map +1 -0
  23. package/dist/telegram/voice-waveform.d.ts +67 -0
  24. package/dist/telegram/voice-waveform.d.ts.map +1 -0
  25. package/llms/files.txt +1 -0
  26. package/llms/process.2.txt +133 -0
  27. package/llms/process.txt +37 -133
  28. package/llms/server.5.txt +1 -1
  29. package/llms/server.txt +8 -5
  30. package/llms/stitchkit.txt +3 -1
  31. package/llms/telegram-voice.txt +29 -0
  32. package/llms/telegram.2.txt +71 -0
  33. package/llms/telegram.txt +51 -59
  34. package/llms-full.txt +115 -7
  35. package/llms.txt +7 -6
  36. package/package.json +5 -1
package/CHANGELOG.md CHANGED
@@ -15,6 +15,50 @@ additive**; the first breaking change landed in 0.10.0. Grep the file for
15
15
 
16
16
  ## [Unreleased]
17
17
 
18
+ ## [0.123.4] - 2026-11-12
19
+
20
+ ### Added
21
+
22
+ - `stitchkit/files` — **`bindUnixSocket({ path, mode }, bind)`: a unix socket that exists only
23
+ with its mode.** `bind(2)` takes a socket's rights from the umask and accepts no mode, so `chmod`
24
+ after `listen` leaves `0755` on disk until it runs, and a process watching the path sees it even
25
+ with `chmodSync` on the next line. The function narrows the umask to exactly `mode` for the one
26
+ synchronous `bind(path)` — `Bun.serve({ unix: path })` or a `node:http`/`node:net`
27
+ `listen(path)` — and restores it in `finally`. The path must be free beforehand and a socket with
28
+ exactly `mode` afterwards: a failed or late bind and a directory whose default ACL overrides the
29
+ umask are refused, a socket born with other rights is removed first. Services that each kept
30
+ their own "narrow the umask around `Bun.serve`" copy take this one; the `stitchkit/files` budget
31
+ grows by the function and `UnixSocketBinding`.
32
+
33
+ ### Fixed
34
+
35
+ - `stitchkit/server`, `stitchkit/agent-runtime/sandbox` — **a unix socket with `mode` is born with
36
+ it instead of being narrowed after it exists.** `createServer({ unix: { path, mode } })` listened
37
+ under the process umask and called `chmodSync` next: an observer in another process saw the socket
38
+ `0755` in 9 of 30 starts under umask `022`, and a readiness check that met it in that window
39
+ refused the service. The sandbox HTTP gateway did the same with `await chmod(…, 0o600)`. Both now
40
+ bind through `bindUnixSocket`; the stale-socket probe still runs before the bind, under the
41
+ normal umask. A socket the filesystem would give other rights than `mode` now fails the start
42
+ instead of being published wider.
43
+ **Affects:** `stitchkit/server` createServer(unix); `stitchkit/agent-runtime/sandbox` createBubblewrapSandboxBackend(behaviour)
44
+
45
+ ## [0.123.3] - 2026-11-12
46
+
47
+ ### Added
48
+
49
+ - `stitchkit/telegram/voice`, `stitchkit/telegram` — **the waveform of a voice message, one format
50
+ for every bot.** `readTelegramVoiceWaveform(pcmPath, { signal })` reads a mono 16-bit PCM side
51
+ copy of a recording in chunks and returns the packed waveform `sendVoice` takes on a local Bot
52
+ API server that accepts one; `readTelegramVoiceWaveformSupport(await bot.api.getMe())` says
53
+ whether the server does (`supports_voice_waveform`, `voice_waveform_version` 1). The levels are
54
+ scaled the way Telegram Desktop scales them — 1.8 × the mean peak, never below a floor — so
55
+ silence stays zero and a quiet recording is not stretched to look loud. The new browser-safe
56
+ entrypoint `stitchkit/telegram/voice` holds the format itself: `packTelegramVoiceWaveform(peaks)`,
57
+ `unpackTelegramVoiceWaveform(waveform)` for a page drawing the bars, and
58
+ `TelegramVoiceWaveformError` with its reasons. Bots that each packed 5-bit levels, read `getMe`
59
+ and scaled the bars their own way now share one implementation; the `stitchkit/telegram`
60
+ budget grows by these two names, and `stitchkit/telegram/voice` starts evolving at nine.
61
+
18
62
  ## [0.123.2] - 2026-11-12
19
63
 
20
64
  ### Added
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-broker.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/sandbox-broker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,6FAA6F;AAC7F,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,oBAAoB,EACrC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;;;GA2GlC"}
1
+ {"version":3,"file":"sandbox-broker.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/sandbox-broker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgB,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,6FAA6F;AAC7F,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,oBAAoB,EACrC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;;;GAoHlC"}
@@ -19,6 +19,9 @@ import {
19
19
  terminateOwnedGroup,
20
20
  startNativeCommand
21
21
  } from "../../index-gdqawggb.js";
22
+ import {
23
+ bindUnixSocket2
24
+ } from "../../index-drcjjhy1.js";
22
25
  import"../../index-kffm4r8w.js";
23
26
  import"../../index-fa53vygr.js";
24
27
  import"../../index-ww3gss55.js";
@@ -40,7 +43,7 @@ import { join as join2, posix as posix2 } from "node:path";
40
43
  import { z as z3 } from "zod";
41
44
 
42
45
  // src/agent-runtime/sandbox-broker.ts
43
- import { chmod, unlink } from "node:fs/promises";
46
+ import { unlink } from "node:fs/promises";
44
47
  import { createServer } from "node:http";
45
48
 
46
49
  // src/agent-runtime/sandbox-contract.ts
@@ -176,11 +179,20 @@ Connection: close\r
176
179
  `));
177
180
  server.requestTimeout = 30000;
178
181
  server.headersTimeout = 5000;
179
- await new Promise((resolve, reject) => {
182
+ const listening = new Promise((resolve, reject) => {
180
183
  server.once("error", reject);
181
- server.listen(socketPath, resolve);
184
+ server.once("listening", resolve);
182
185
  });
183
- await chmod(socketPath, 384);
186
+ try {
187
+ bindUnixSocket2({ path: socketPath, mode: 384 }, (path) => server.listen(path));
188
+ } catch (error) {
189
+ listening.catch(() => {
190
+ return;
191
+ });
192
+ server.close();
193
+ throw error;
194
+ }
195
+ await listening;
184
196
  return {
185
197
  abortRequests() {
186
198
  for (const controller of controllers)
@@ -5,5 +5,6 @@ export { CHUNK_SPOOL_ERROR_CODES, type ChunkSpool, type ChunkSpoolAssembly, type
5
5
  export { type WriteFileAtomicOptions, writeFileAtomic, writeFileAtomicSync, } from '../internal/atomic-file.js';
6
6
  export { AtomicFilePublicationError } from '../internal/atomic-publication.js';
7
7
  export { isAtomicStagingName, type SweepAtomicStagingOptions, sweepAtomicStaging, } from '../internal/atomic-staging.js';
8
+ export { bindUnixSocket, type UnixSocketBinding } from '../internal/unix-socket.js';
8
9
  export { type ExclusiveLock, ExclusiveLockError, type ExclusiveLockOptions, type ExclusiveLockOwner, withExclusiveLock, } from '../internal/with-exclusive-lock.js';
9
10
  //# sourceMappingURL=files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/entrypoints/files.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,sBAAsB,EAC3B,eAAe,EACf,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,iCAAiC,CAAC"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/entrypoints/files.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,GAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,sBAAsB,EAC3B,eAAe,EACf,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,iCAAiC,CAAC"}
@@ -5,6 +5,9 @@ import {
5
5
  import"../index-sqc6ezrb.js";
6
6
  import"../index-bqzgaj57.js";
7
7
  import"../index-chz7c830.js";
8
+ import {
9
+ bindUnixSocket2
10
+ } from "../index-drcjjhy1.js";
8
11
  import {
9
12
  ExclusiveLockError2,
10
13
  withExclusiveLock2
@@ -268,6 +271,7 @@ export {
268
271
  ManagedFileError2 as ManagedFileError,
269
272
  ManagedFilePathSchema2 as ManagedFilePathSchema,
270
273
  ManagedFileRefSchema2 as ManagedFileRefSchema,
274
+ bindUnixSocket2 as bindUnixSocket,
271
275
  createChunkSpool,
272
276
  createManagedFileBoundary2 as createManagedFileBoundary,
273
277
  isAtomicStagingName2 as isAtomicStagingName,
@@ -60,6 +60,9 @@ import {
60
60
  import {
61
61
  bindRealtimeServer2
62
62
  } from "../index-sqkttz7z.js";
63
+ import {
64
+ bindUnixSocket2
65
+ } from "../index-drcjjhy1.js";
63
66
  import"../index-73dappvg.js";
64
67
  import {
65
68
  withDeadline
@@ -72,6 +75,9 @@ import {
72
75
  signJwt2,
73
76
  verifyPkce2
74
77
  } from "../index-hkw233vx.js";
78
+ import {
79
+ deriveCodeChallenge2
80
+ } from "../index-ap3gqe56.js";
75
81
  import {
76
82
  defineMultipartStream2,
77
83
  createMultipartStream2,
@@ -79,9 +85,6 @@ import {
79
85
  createImplement2,
80
86
  createScopedImplement2
81
87
  } from "../index-eabx6qjh.js";
82
- import {
83
- deriveCodeChallenge2
84
- } from "../index-ap3gqe56.js";
85
88
  import"../index-9ypczvpj.js";
86
89
  import {
87
90
  DEFAULT_CORS_ALLOW_HEADERS2,
@@ -346,7 +349,7 @@ function bindSocketRegistry(server, options) {
346
349
  };
347
350
  }
348
351
  // src/server/bun.ts
349
- import { chmodSync, statSync, unlinkSync } from "node:fs";
352
+ import { statSync, unlinkSync } from "node:fs";
350
353
 
351
354
  // src/server/proxy-origin.ts
352
355
  import { z } from "zod";
@@ -437,6 +440,31 @@ function assertUnixListenConfig(config, unixPath) {
437
440
  throw new Error("[stitchkit] createServer: the Socket.IO lifecycle cannot listen on a unix socket — socket.io clients dial TCP only");
438
441
  }
439
442
  }
443
+ function listenOnUnixSocket(unix, { bunExtra, development, websocket, fetch }) {
444
+ reclaimStaleUnixSocket(unix.path);
445
+ const { reusePort, ipv6Only, http3, http2, http1, idleTimeout, ...unixExtra } = bunExtra ?? {};
446
+ const listen = (path) => websocket ? Bun.serve({
447
+ ...unixExtra,
448
+ ...development && { development },
449
+ unix: path,
450
+ websocket,
451
+ fetch
452
+ }) : Bun.serve({ ...unixExtra, ...development && { development }, unix: path, fetch });
453
+ if (unix.mode === undefined)
454
+ return listen(unix.path);
455
+ let started;
456
+ try {
457
+ return bindUnixSocket2({ path: unix.path, mode: unix.mode }, (path) => {
458
+ started = listen(path);
459
+ return started;
460
+ });
461
+ } catch (error) {
462
+ started?.stop(true).catch(() => {
463
+ return;
464
+ });
465
+ throw error;
466
+ }
467
+ }
440
468
  async function waitForRequestDrain(server) {
441
469
  while (server.pendingRequests > 0) {
442
470
  await new Promise((resolve) => setTimeout(resolve, 5));
@@ -568,22 +596,7 @@ function createServer(config) {
568
596
  return admittedFetch(normalized, server);
569
597
  };
570
598
  if (unixPath !== undefined) {
571
- reclaimStaleUnixSocket(unixPath);
572
- const { reusePort, ipv6Only, http3, http2, http1, idleTimeout, ...unixExtra } = bunExtra ?? {};
573
- runtime = trackedWebSocket ? Bun.serve({
574
- ...unixExtra,
575
- ...development && { development },
576
- unix: unixPath,
577
- websocket: trackedWebSocket,
578
- fetch
579
- }) : Bun.serve({
580
- ...unixExtra,
581
- ...development && { development },
582
- unix: unixPath,
583
- fetch
584
- });
585
- if (unixMode !== undefined)
586
- chmodSync(unixPath, unixMode);
599
+ runtime = listenOnUnixSocket({ path: unixPath, mode: unixMode }, { bunExtra, development, websocket: trackedWebSocket, fetch });
587
600
  } else {
588
601
  runtime = trackedWebSocket ? Bun.serve({
589
602
  ...bunExtra,
@@ -0,0 +1,2 @@
1
+ export { packTelegramVoiceWaveform, readTelegramVoiceWaveformSupport, TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL, TELEGRAM_VOICE_WAVEFORM_SAMPLES, TELEGRAM_VOICE_WAVEFORM_VERSION, TelegramVoiceWaveformError, type TelegramVoiceWaveformRefusal, type TelegramVoiceWaveformSupport, unpackTelegramVoiceWaveform, } from '../../telegram/voice-waveform.js';
2
+ //# sourceMappingURL=voice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/telegram/voice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,0BAA0B,EAC1B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,2BAA2B,GAC5B,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import {
2
+ TELEGRAM_VOICE_WAVEFORM_SAMPLES2,
3
+ TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL2,
4
+ TELEGRAM_VOICE_WAVEFORM_VERSION2,
5
+ TelegramVoiceWaveformError2,
6
+ packTelegramVoiceWaveform2,
7
+ unpackTelegramVoiceWaveform2,
8
+ readTelegramVoiceWaveformSupport2
9
+ } from "../../index-0jdempdr.js";
10
+ export {
11
+ TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL2 as TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL,
12
+ TELEGRAM_VOICE_WAVEFORM_SAMPLES2 as TELEGRAM_VOICE_WAVEFORM_SAMPLES,
13
+ TELEGRAM_VOICE_WAVEFORM_VERSION2 as TELEGRAM_VOICE_WAVEFORM_VERSION,
14
+ TelegramVoiceWaveformError2 as TelegramVoiceWaveformError,
15
+ packTelegramVoiceWaveform2 as packTelegramVoiceWaveform,
16
+ readTelegramVoiceWaveformSupport2 as readTelegramVoiceWaveformSupport,
17
+ unpackTelegramVoiceWaveform2 as unpackTelegramVoiceWaveform
18
+ };
@@ -15,5 +15,6 @@ export { checkTelegramUpdateStore } from '../telegram/update-store-check.js';
15
15
  export { type PostgresTelegramUpdateStoreConfig, postgresTelegramUpdateStore, postgresTelegramUpdateStoreSchema, type TelegramPostgresQuery, } from '../telegram/update-store-postgres.js';
16
16
  export { type SqliteTelegramUpdateStoreConfig, sqliteTelegramUpdateStore, type TelegramSqliteDatabase, } from '../telegram/update-store-sqlite.js';
17
17
  export { parseTelegramUser, type TelegramUser } from '../telegram/user.js';
18
+ export { type ReadTelegramVoiceWaveformOptions, readTelegramVoiceWaveform, } from '../telegram/voice-waveform-pcm.js';
18
19
  export { type ClaimTelegramWebhookConfig, checkTelegramWebhook, claimTelegramWebhook, type ReceiveTelegramWebhookOptions, receiveTelegramWebhook, TELEGRAM_WEBHOOK_NONE, type TelegramUpdateAcceptance, type TelegramWebhookClaim, TelegramWebhookClaimError, type TelegramWebhookConfig, type TelegramWebhookRefusal, type TelegramWebhookState, telegramWebhookUrl, } from '../telegram/webhook.js';
19
20
  //# sourceMappingURL=telegram.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/entrypoints/telegram.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,wBAAwB,EAC7B,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,EAC1B,KAAK,0BAA0B,GAChC,MAAM,4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,EAC/B,KAAK,2BAA2B,EAChC,gCAAgC,EAChC,KAAK,uBAAuB,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EACL,KAAK,iCAAiC,EACtC,2BAA2B,EAC3B,iCAAiC,EACjC,KAAK,qBAAqB,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,+BAA+B,EACpC,yBAAyB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EACL,KAAK,gCAAgC,EACrC,yBAAyB,GAC1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,KAAK,0BAA0B,EAC/B,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,6BAA6B,EAClC,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,yBAAyB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC"}
@@ -6,6 +6,11 @@ import"../index-bqzgaj57.js";
6
6
  import {
7
7
  attemptExclusiveLock
8
8
  } from "../index-chz7c830.js";
9
+ import {
10
+ TELEGRAM_VOICE_WAVEFORM_SAMPLES2,
11
+ TelegramVoiceWaveformError2,
12
+ packTelegramVoiceWaveform2
13
+ } from "../index-0jdempdr.js";
9
14
  import {
10
15
  TELEGRAM_SEND_FAILURE_REASONS2,
11
16
  classifyTelegramSendFailure2
@@ -2947,6 +2952,43 @@ function sqliteTelegramUpdateStore(config) {
2947
2952
  }
2948
2953
  };
2949
2954
  }
2955
+ // src/telegram/voice-waveform-pcm.ts
2956
+ import { open as open2 } from "node:fs/promises";
2957
+ var CHUNK_BYTES = 256 * 1024;
2958
+ var SAMPLE_BYTES = 2;
2959
+ async function readTelegramVoiceWaveform(pcmPath, options = {}) {
2960
+ const { signal } = options;
2961
+ signal?.throwIfAborted();
2962
+ const file = await open2(pcmPath, "r");
2963
+ try {
2964
+ const { size } = await file.stat();
2965
+ if (size === 0)
2966
+ throw new TelegramVoiceWaveformError2("empty-pcm");
2967
+ if (size % SAMPLE_BYTES !== 0)
2968
+ throw new TelegramVoiceWaveformError2("truncated-pcm");
2969
+ const samples = size / SAMPLE_BYTES;
2970
+ const peaks = new Uint16Array(TELEGRAM_VOICE_WAVEFORM_SAMPLES2);
2971
+ const buffer = new Uint8Array(Math.min(CHUNK_BYTES, size));
2972
+ const view = new DataView(buffer.buffer);
2973
+ for (let offset = 0;offset < size; ) {
2974
+ signal?.throwIfAborted();
2975
+ const { bytesRead } = await file.read(buffer, 0, Math.min(buffer.length, size - offset), offset);
2976
+ if (bytesRead === 0 || bytesRead % SAMPLE_BYTES !== 0)
2977
+ throw new TelegramVoiceWaveformError2("truncated-pcm");
2978
+ const first = offset / SAMPLE_BYTES;
2979
+ for (let index = 0;index < bytesRead; index += SAMPLE_BYTES) {
2980
+ const part = Math.floor((first + index / SAMPLE_BYTES) * TELEGRAM_VOICE_WAVEFORM_SAMPLES2 / samples);
2981
+ const peak = Math.abs(view.getInt16(index, true));
2982
+ if (peak > (peaks[part] ?? 0))
2983
+ peaks[part] = peak;
2984
+ }
2985
+ offset += bytesRead;
2986
+ }
2987
+ return packTelegramVoiceWaveform2(peaks);
2988
+ } finally {
2989
+ await file.close();
2990
+ }
2991
+ }
2950
2992
  // src/telegram/webhook.ts
2951
2993
  var OWNER_PARAMETER = "owner";
2952
2994
  var OWNER_CONTEXT = "stitchkit:telegram-webhook-owner";
@@ -3079,6 +3121,7 @@ export {
3079
3121
  parseTelegramUser,
3080
3122
  postgresTelegramUpdateStore,
3081
3123
  postgresTelegramUpdateStoreSchema,
3124
+ readTelegramVoiceWaveform,
3082
3125
  receiveTelegramWebhook,
3083
3126
  redactTelegramBotToken,
3084
3127
  runTelegramBroadcast,
@@ -1,10 +1,10 @@
1
- import {
2
- DEFAULT_BOT_USER_AGENT_PATTERN2
3
- } from "../../index-1f40z584.js";
4
1
  import {
5
2
  redactTrackingText2,
6
3
  sendUnloadBeacon2
7
4
  } from "../../index-8vzh5wpv.js";
5
+ import {
6
+ DEFAULT_BOT_USER_AGENT_PATTERN2
7
+ } from "../../index-1f40z584.js";
8
8
 
9
9
  // src/tracking/performance/collector.ts
10
10
  var DEFAULT_EARLY_DELAY_MS = 5000;
@@ -0,0 +1,69 @@
1
+ // src/telegram/voice-waveform.ts
2
+ var TELEGRAM_VOICE_WAVEFORM_SAMPLES2 = 100;
3
+ var TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL2 = 31;
4
+ var TELEGRAM_VOICE_WAVEFORM_VERSION2 = 1;
5
+ var BITS_PER_LEVEL = 5;
6
+ var PACKED_BYTES = Math.ceil(TELEGRAM_VOICE_WAVEFORM_SAMPLES2 * BITS_PER_LEVEL / 8);
7
+ var MEAN_PEAK_SCALE = 1.8;
8
+ var PEAK_FLOOR = 2500;
9
+ var PEAK_MAX = 32768;
10
+
11
+ class TelegramVoiceWaveformError2 extends Error {
12
+ reason;
13
+ constructor(reason) {
14
+ super(`Telegram voice waveform refused: ${reason}`);
15
+ this.name = "TelegramVoiceWaveformError";
16
+ this.reason = reason;
17
+ }
18
+ }
19
+ function packTelegramVoiceWaveform2(peaks) {
20
+ if (peaks.length !== TELEGRAM_VOICE_WAVEFORM_SAMPLES2)
21
+ throw new TelegramVoiceWaveformError2("peak-count");
22
+ const values = Array.from(peaks);
23
+ let sum = 0;
24
+ for (const peak of values) {
25
+ if (!Number.isInteger(peak) || peak < 0 || peak > PEAK_MAX)
26
+ throw new TelegramVoiceWaveformError2("peak-value");
27
+ sum += peak;
28
+ }
29
+ const ceiling = Math.max(Math.floor(sum * MEAN_PEAK_SCALE / TELEGRAM_VOICE_WAVEFORM_SAMPLES2), PEAK_FLOOR);
30
+ const packed = new Uint8Array(PACKED_BYTES);
31
+ for (const [index, peak] of values.entries()) {
32
+ const level = Math.floor(Math.min(peak, ceiling) * TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL2 / ceiling);
33
+ const bit = index * BITS_PER_LEVEL;
34
+ const byte = bit >> 3;
35
+ const shift = bit & 7;
36
+ packed[byte] = (packed[byte] ?? 0) | level << shift & 255;
37
+ if (shift > 8 - BITS_PER_LEVEL)
38
+ packed[byte + 1] = level >> 8 - shift;
39
+ }
40
+ return btoa(String.fromCharCode(...packed));
41
+ }
42
+ function unpackTelegramVoiceWaveform2(waveform) {
43
+ let text;
44
+ try {
45
+ text = atob(waveform);
46
+ } catch {
47
+ throw new TelegramVoiceWaveformError2("malformed");
48
+ }
49
+ const bytes = Uint8Array.from(text, (char) => char.charCodeAt(0));
50
+ const count = Math.floor(bytes.length * 8 / BITS_PER_LEVEL);
51
+ return Array.from({ length: count }, (_, index) => {
52
+ const bit = index * BITS_PER_LEVEL;
53
+ const byte = bit >> 3;
54
+ const pair = (bytes[byte] ?? 0) | (bytes[byte + 1] ?? 0) << 8;
55
+ return pair >> (bit & 7) & TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL2;
56
+ });
57
+ }
58
+ function readTelegramVoiceWaveformSupport2(me) {
59
+ const declared = typeof me === "object" && me !== null;
60
+ const flag = declared ? Reflect.get(me, "supports_voice_waveform") : undefined;
61
+ const raw = declared ? Reflect.get(me, "voice_waveform_version") : undefined;
62
+ const version = typeof raw === "number" && Number.isInteger(raw) ? raw : null;
63
+ return {
64
+ supported: flag === true && version === TELEGRAM_VOICE_WAVEFORM_VERSION2,
65
+ version
66
+ };
67
+ }
68
+
69
+ export { TELEGRAM_VOICE_WAVEFORM_SAMPLES2, TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL2, TELEGRAM_VOICE_WAVEFORM_VERSION2, TelegramVoiceWaveformError2, packTelegramVoiceWaveform2, unpackTelegramVoiceWaveform2, readTelegramVoiceWaveformSupport2 };
@@ -0,0 +1,40 @@
1
+ // src/internal/unix-socket.ts
2
+ import { lstatSync, unlinkSync } from "node:fs";
3
+ var PERMISSION_BITS = 511;
4
+ function octal(mode) {
5
+ return `0o${mode.toString(8).padStart(3, "0")}`;
6
+ }
7
+ function bindUnixSocket2(socket, bind) {
8
+ const { path, mode } = socket;
9
+ if (path.length === 0) {
10
+ throw new Error("[stitchkit] bindUnixSocket: `path` must be a non-empty socket path");
11
+ }
12
+ if (!Number.isInteger(mode) || mode < 0 || mode > PERMISSION_BITS) {
13
+ throw new Error(`[stitchkit] bindUnixSocket: \`mode\` must be permission bits 0o000–0o777, got ${String(mode)}`);
14
+ }
15
+ if (lstatSync(path, { throwIfNoEntry: false }) !== undefined) {
16
+ throw new Error(`[stitchkit] bindUnixSocket: "${path}" already exists — a socket is bound on a free path; remove a stale socket first`);
17
+ }
18
+ const previous = process.umask(~mode & PERMISSION_BITS);
19
+ let bound;
20
+ try {
21
+ bound = bind(path);
22
+ } finally {
23
+ process.umask(previous);
24
+ }
25
+ const stats = lstatSync(path, { throwIfNoEntry: false });
26
+ if (stats === undefined) {
27
+ throw new Error(`[stitchkit] bindUnixSocket: no socket at "${path}" when bind returned — the listen failed (its error arrives on the server's error event) or does not bind synchronously inside the call`);
28
+ }
29
+ if (!stats.isSocket()) {
30
+ throw new Error(`[stitchkit] bindUnixSocket: "${path}" is not a socket after bind — the bind must listen on this path`);
31
+ }
32
+ const born = stats.mode & PERMISSION_BITS;
33
+ if (born !== mode) {
34
+ unlinkSync(path);
35
+ throw new Error(`[stitchkit] bindUnixSocket: socket "${path}" was born ${octal(born)} instead of ${octal(mode)} — something other than the umask sets the rights in this directory (a default ACL?); the socket was removed`);
36
+ }
37
+ return bound;
38
+ }
39
+
40
+ export { bindUnixSocket2 };
@@ -0,0 +1,28 @@
1
+ /** Where a unix socket is bound and the exact permission bits it is born with. */
2
+ export interface UnixSocketBinding {
3
+ readonly path: string;
4
+ /** Permission bits `0o000`–`0o777`; `0o600` when access to the socket is the credential. */
5
+ readonly mode: number;
6
+ }
7
+ /**
8
+ * Bind a unix socket that exists only with `mode`, never with wider rights first.
9
+ *
10
+ * `bind(2)` takes a socket file's permissions from the process umask and accepts no mode, so a
11
+ * `chmod` after the bind leaves the umask rights on disk until it runs, and a process watching the
12
+ * path sees them even with `chmodSync` on the next line. The umask is narrowed to exactly
13
+ * `~mode` for the one synchronous `bind(path)` call and restored in `finally`, before any other
14
+ * JavaScript runs.
15
+ *
16
+ * The umask is process-wide. A file another thread creates during that call is born at most as
17
+ * permissive as the socket — narrower, never wider — and work that must keep the normal umask (a
18
+ * child process, a liveness probe) runs before the call, not inside `bind`.
19
+ *
20
+ * The path must be free before the call, so whatever stands there afterwards was created by it;
21
+ * a stale socket is the caller's to remove first. After `bind` the path must be a socket with
22
+ * exactly `mode`. A bind that failed — Node and Bun report a `listen` error asynchronously, on the
23
+ * server's `error` event — or completes later than the call, and a directory whose default ACL
24
+ * overrides the umask, all fail here; a socket that was born with other rights is unlinked first,
25
+ * so no client reaches it by path. The listener `bind` started is the caller's to stop.
26
+ */
27
+ export declare function bindUnixSocket<T>(socket: UnixSocketBinding, bind: (path: string) => T): T;
28
+ //# sourceMappingURL=unix-socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unix-socket.d.ts","sourceRoot":"","sources":["../../src/internal/unix-socket.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAQD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,CAyCzF"}
@@ -16,10 +16,11 @@ type BunDevelopmentOptions = BunServeOptions extends {
16
16
  } ? T : never;
17
17
  export type ServerPassthrough = Omit<BunServeOptions, 'fetch' | 'port' | 'hostname' | 'unix' | 'routes' | 'websocket' | 'development'>;
18
18
  /**
19
- * Unix domain socket listener. The plain-string form binds the path as-is;
20
- * the object form additionally tightens the socket file mode after listen —
21
- * `mode: 0o600` is the right choice when access to the socket IS the
22
- * credential (a local daemon whose only auth is filesystem permission).
19
+ * Unix domain socket listener. The plain-string form binds the path under the
20
+ * process umask; the object form binds it with exactly `mode` from birth
21
+ * (`bindUnixSocket` from `stitchkit/files`) — `mode: 0o600` is the right choice
22
+ * when access to the socket IS the credential (a local daemon whose only auth
23
+ * is filesystem permission).
23
24
  */
24
25
  export type UnixListenConfig = string | {
25
26
  path: string;
@@ -1 +1 @@
1
- {"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../src/server/bun.ts"],"names":[],"mappings":"AAGA,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,yEAAyE;AACzE,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC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C,eAAe,EACf,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAChF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,8EAA8E;AAC9E,MAAM,WAAW,eAAgB,SAAQ,gBAAgB,EAAE,mBAAmB;IAC5E;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,iGAAiG;IACjG,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAiJ7D,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CA6KrE"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The waveform of a recording from its decoded PCM: mono, 16-bit, little-endian
3
+ * (`ffmpeg -i <audio> -ac 1 -ar 8000 -f s16le <file>`).
4
+ *
5
+ * The file is read in chunks, so an hour of audio never sits in memory; the
6
+ * waveform needs the loudness of each part, not the bandwidth, and 8 kHz keeps
7
+ * six hours under 350 MB of PCM. The recording being sent is never this file:
8
+ * the PCM is a side copy, and what is uploaded stays byte for byte what it was.
9
+ */
10
+ export interface ReadTelegramVoiceWaveformOptions {
11
+ /** Stops the read between chunks with the signal's reason. */
12
+ readonly signal?: AbortSignal;
13
+ }
14
+ /**
15
+ * The packed waveform `sendVoice` takes, from a PCM file. A file with no
16
+ * sample is refused (`empty-pcm`), and so is one that ends inside a sample or
17
+ * shrinks while it is read (`truncated-pcm`): a waveform is never made up.
18
+ * The refusal names the reason, not the path.
19
+ */
20
+ export declare function readTelegramVoiceWaveform(pcmPath: string, options?: ReadTelegramVoiceWaveformOptions): Promise<string>;
21
+ //# sourceMappingURL=voice-waveform-pcm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice-waveform-pcm.d.ts","sourceRoot":"","sources":["../../src/telegram/voice-waveform-pcm.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,MAAM,WAAW,gCAAgC;IAC/C,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,gCAAqC,GAC7C,OAAO,CAAC,MAAM,CAAC,CAoCjB"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The waveform of a Telegram voice message: the bars a client draws under the
3
+ * play button.
4
+ *
5
+ * Telegram stores it as a run of 5-bit levels packed little-endian — a voice
6
+ * note sent by a Telegram client carries 100 of them, 63 bytes. The public Bot
7
+ * API has no field for it, and Telegram then draws its own; a local Bot API
8
+ * server can accept one in `sendVoice`, and such a server says so in `getMe`
9
+ * (`supports_voice_waveform`, `voice_waveform_version`).
10
+ *
11
+ * The levels follow Telegram Desktop: each of the 100 parts of the recording
12
+ * keeps its loudest sample, and the scale is 1.8 times the mean of those
13
+ * peaks, never below a floor — a loud recording does not flatten its quiet
14
+ * parts to nothing, and a quiet one is not stretched into a loud-looking one.
15
+ * Silence stays at zero.
16
+ *
17
+ * Nothing here touches a file or the network, so the server that packs a
18
+ * waveform and the page that draws it read one format.
19
+ */
20
+ /** Parts of the recording a waveform describes. */
21
+ export declare const TELEGRAM_VOICE_WAVEFORM_SAMPLES = 100;
22
+ /** The highest level of a bar: levels are 5 bits, `0`–`31`. */
23
+ export declare const TELEGRAM_VOICE_WAVEFORM_MAX_LEVEL = 31;
24
+ /** The version of the `sendVoice` waveform field a Bot API server declares in `getMe`. */
25
+ export declare const TELEGRAM_VOICE_WAVEFORM_VERSION = 1;
26
+ /**
27
+ * Why a waveform was not made or not read.
28
+ *
29
+ * - `peak-count` — `packTelegramVoiceWaveform` takes exactly 100 peaks.
30
+ * - `peak-value` — a peak is not an integer from `0` to `32768`.
31
+ * - `malformed` — the waveform text is not base64.
32
+ * - `empty-pcm` — the PCM has no sample: there is nothing to draw.
33
+ * - `truncated-pcm` — the PCM ends inside a sample, or ended before its size.
34
+ */
35
+ export type TelegramVoiceWaveformRefusal = 'peak-count' | 'peak-value' | 'malformed' | 'empty-pcm' | 'truncated-pcm';
36
+ export declare class TelegramVoiceWaveformError extends Error {
37
+ readonly reason: TelegramVoiceWaveformRefusal;
38
+ constructor(reason: TelegramVoiceWaveformRefusal);
39
+ }
40
+ /**
41
+ * The waveform `sendVoice` takes, from the loudest absolute sample of each of
42
+ * the 100 equal parts of a recording (16-bit PCM: `0`–`32768`): base64 of 63
43
+ * bytes. `readTelegramVoiceWaveform` from `stitchkit/telegram` finds the
44
+ * peaks in a PCM file and calls this.
45
+ */
46
+ export declare function packTelegramVoiceWaveform(peaks: ArrayLike<number>): string;
47
+ /**
48
+ * The levels of a waveform, each `0`–`31`, for drawing it: one per 5 bits, so
49
+ * the 63 bytes `packTelegramVoiceWaveform` makes give 100, and a waveform
50
+ * Telegram drew itself gives however many it holds. Text that is not base64
51
+ * is refused, never read as silence.
52
+ */
53
+ export declare function unpackTelegramVoiceWaveform(waveform: string): number[];
54
+ /** What a Bot API server said in `getMe` about the `sendVoice` waveform field. */
55
+ export interface TelegramVoiceWaveformSupport {
56
+ /** The server takes the waveform this module packs: it declares version 1. */
57
+ readonly supported: boolean;
58
+ /** The version it declares; `null` when it declares none (the public Bot API). */
59
+ readonly version: number | null;
60
+ }
61
+ /**
62
+ * Whether the server behind a `getMe` answer takes the waveform: the `result`
63
+ * of `getMe` as it came, any shape. A server that declares nothing, or another
64
+ * version, does not — and a voice sent there gets whatever Telegram draws.
65
+ */
66
+ export declare function readTelegramVoiceWaveformSupport(me: unknown): TelegramVoiceWaveformSupport;
67
+ //# sourceMappingURL=voice-waveform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice-waveform.d.ts","sourceRoot":"","sources":["../../src/telegram/voice-waveform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,mDAAmD;AACnD,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,+DAA+D;AAC/D,eAAO,MAAM,iCAAiC,KAAK,CAAC;AACpD,0FAA0F;AAC1F,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAWjD;;;;;;;;GAQG;AACH,MAAM,MAAM,4BAA4B,GACpC,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,WAAW,GACX,eAAe,CAAC;AAEpB,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,MAAM,EAAE,4BAA4B,CAAC;IAE9C,YAAY,MAAM,EAAE,4BAA4B,EAI/C;CACF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CA0B1E;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAetE;AAED,kFAAkF;AAClF,MAAM,WAAW,4BAA4B;IAC3C,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,OAAO,GAAG,4BAA4B,CAS1F"}
package/llms/files.txt CHANGED
@@ -34,6 +34,7 @@ available from `stitchkit/contract`.
34
34
  | `sweepAtomicStaging` / `SweepAtomicStagingOptions` | function / _type_ | remove abandoned staging files from one `directory`: only regular files matching `isAtomicStagingName` and older than the required `olderThanMs`, never following a symlink or entering a subdirectory; stops on `signal`; returns the removed names, `[]` for a `directory` that does not exist |
35
35
  | `withExclusiveLock` / `ExclusiveLockOptions` / `ExclusiveLock` / `ExclusiveLockOwner` | function / _type_ | run work under an exclusive lock between processes — a file recording its owner (pid, host, machine identity, time and nullable kernel process identity); waits up to `timeoutMs` (default 10 s) and stops on `signal`; a dead owner on this machine is taken over, a live, slow or foreign one never is; a lock recorded by this very process is held only while one of its descriptors is open on it, so the lock an earlier image of the same PID left (`bun --watch` restarts in place) is taken over at once; the lock is published with its owner already recorded (temporary file plus hard link), so a stalled holder is never displaced; a legacy empty lock file is taken by age only when `ownerlessGraceMs` is a number (default `null`: never; an abandoned empty reclaim guard is taken after 5 000 ms unless a value is set); exact `mode` is independent of umask; shared readers need a common group and traversable directories |
36
36
  | `ExclusiveLockError` | class | `LOCK_TIMEOUT` naming the resource and its holder, or `LOCK_ABORTED` with the signal's reason |
37
+ | `bindUnixSocket` / `UnixSocketBinding` | function / _type_ | bind a unix socket that exists only with `mode` (`0o000`–`0o777`), never wider first: the umask is narrowed for the one synchronous `bind(path)` (`Bun.serve({ unix })`, `node:http`/`node:net` `listen(path)`) and restored before any other JavaScript; the path must be free beforehand and a socket with exactly `mode` afterwards, else it refuses (a socket born with other rights is removed) — [guide](../guide/native-io.md#a-unix-socket-private-from-birth) |
37
38
  | `createChunkSpool` | function | the server half of a chunked upload: parts on disk under `owner` + client-minted `uploadId`, each with a size+sha256 receipt; idempotent `open` and `put`, the first writer of a part wins across processes, `assemble` in order once every part is in, `sweep` of untouched uploads — [guide](../guide/client.md#chunked-uploads) |
38
39
  | `ChunkSpool` / `ChunkSpoolConfig` / `ChunkSpoolKey` / `ChunkSpoolOpen` / `ChunkSpoolPart` / `ChunkSpoolAssembly` | _type_ | the spool, its directory, part size, file limit, meta schema and age; an upload's key; its declaration; one part; the assembled parts with a concatenating `stream()` |
39
40
  | `ChunkSpoolErrorCode` | _type_ | the `AppError` codes a spool refuses with, each with its 4xx status: `UPLOAD_INVALID`, `UPLOAD_TOO_LARGE`, `UPLOAD_NOT_FOUND`, `UPLOAD_CONFLICT`, `UPLOAD_CHUNK_OUT_OF_RANGE`, `UPLOAD_CHUNK_SIZE`, `UPLOAD_INCOMPLETE` |