stitchkit 0.107.0 → 0.108.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 +99 -0
- package/README.md +2 -0
- package/darwin-native.cjs +1 -0
- package/dist/browser/stream.d.ts +38 -12
- package/dist/browser/stream.d.ts.map +1 -1
- package/dist/entrypoints/application/diagnostic-journal.js +2 -2
- package/dist/entrypoints/application/directory-inbox.js +4 -4
- package/dist/entrypoints/bin/upgrade-cli.d.ts +32 -0
- package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -1
- package/dist/entrypoints/bin/upgrade-cli.js +451 -8
- package/dist/entrypoints/cli/publish.js +3 -3
- package/dist/entrypoints/files/packaging.d.ts +3 -1
- package/dist/entrypoints/files/packaging.d.ts.map +1 -1
- package/dist/entrypoints/files/packaging.js +105 -41
- package/dist/entrypoints/files.js +3 -3
- package/dist/entrypoints/index.d.ts +1 -1
- package/dist/entrypoints/index.d.ts.map +1 -1
- package/dist/entrypoints/index.js +7 -1
- package/dist/entrypoints/process.js +1 -1
- package/dist/entrypoints/remote.js +1 -1
- package/dist/entrypoints/server.js +4 -4
- package/dist/entrypoints/telegram/screens.js +1 -1
- package/dist/entrypoints/telegram.d.ts +2 -0
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +337 -3
- package/dist/entrypoints/testing.d.ts +1 -0
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +131 -1
- package/dist/files/native-artifact.d.ts +14 -0
- package/dist/files/native-artifact.d.ts.map +1 -0
- package/dist/files/native-packaging-layout.d.ts +5 -0
- package/dist/files/native-packaging-layout.d.ts.map +1 -1
- package/dist/files/native-packaging-plugin.d.ts +53 -0
- package/dist/files/native-packaging-plugin.d.ts.map +1 -0
- package/dist/files/native-packaging.d.ts +1 -35
- package/dist/files/native-packaging.d.ts.map +1 -1
- package/dist/index-a5qr2rj6.js +26 -0
- package/dist/{index-7r74re56.js → index-bh2ht9y5.js} +12 -6
- package/dist/{index-mbf4h8kp.js → index-nx49x0tw.js} +1 -1
- package/dist/{index-zsqt5q98.js → index-p5kx5vqd.js} +209 -54
- package/dist/{index-bnf8s6v3.js → index-t2bsd0hm.js} +1 -1
- package/dist/{index-4f37d3bg.js → index-w9mqgnz9.js} +1 -1
- package/dist/{index-e05cjgtf.js → index-xvj9h8yh.js} +28 -1
- package/dist/internal/bounded-lines.d.ts +46 -2
- package/dist/internal/bounded-lines.d.ts.map +1 -1
- package/dist/internal/process-identity.d.ts.map +1 -1
- package/dist/internal/until-aborted.d.ts +9 -0
- package/dist/internal/until-aborted.d.ts.map +1 -0
- package/dist/internal/upgrade-affects.d.ts +58 -0
- package/dist/internal/upgrade-affects.d.ts.map +1 -0
- package/dist/internal/upgrade-plan.d.ts +20 -0
- package/dist/internal/upgrade-plan.d.ts.map +1 -1
- package/dist/internal/upgrade-usage.d.ts +61 -0
- package/dist/internal/upgrade-usage.d.ts.map +1 -0
- package/dist/telegram/bot-api.d.ts +10 -4
- package/dist/telegram/bot-api.d.ts.map +1 -1
- package/dist/telegram/broadcast.d.ts +2 -1
- package/dist/telegram/broadcast.d.ts.map +1 -1
- package/dist/telegram/not-dispatched.d.ts +26 -0
- package/dist/telegram/not-dispatched.d.ts.map +1 -0
- package/dist/telegram/operator-channel.d.ts +2 -1
- package/dist/telegram/operator-channel.d.ts.map +1 -1
- package/dist/telegram/send-failure.d.ts +4 -3
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/transport-connect.d.ts +38 -0
- package/dist/telegram/transport-connect.d.ts.map +1 -0
- package/dist/telegram/transport.d.ts +43 -0
- package/dist/telegram/transport.d.ts.map +1 -0
- package/dist/telegram/webhook.d.ts +2 -1
- package/dist/telegram/webhook.d.ts.map +1 -1
- package/dist/testing/manual-clock.d.ts +82 -0
- package/dist/testing/manual-clock.d.ts.map +1 -0
- package/llms/files-packaging.txt +4 -1
- package/llms/process.txt +19 -5
- package/llms/stitchkit.2.txt +211 -628
- package/llms/stitchkit.txt +635 -10
- package/llms/telegram.txt +36 -3
- package/llms/testing.txt +47 -0
- package/llms/{upgrading-0.98.0-0.107.0.txt → upgrading-0.100.0-0.108.0.txt} +59 -64
- package/llms/{upgrading-0.72.0-0.97.0.txt → upgrading-0.72.0-0.99.0.txt} +64 -3
- package/llms/upgrading.txt +34 -2
- package/llms-full.txt +246 -17
- package/llms.txt +8 -8
- package/package.json +1 -1
- package/llms/stitchkit.3.txt +0 -177
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { type NativePackagingPlugin } from './native-packaging-plugin.js';
|
|
2
3
|
declare const ArchitectureSchema: z.ZodEnum<{
|
|
3
4
|
arm64: "arm64";
|
|
4
5
|
x64: "x64";
|
|
@@ -111,41 +112,6 @@ export type NativePackagingAsset<Multiple extends boolean = false> = Multiple ex
|
|
|
111
112
|
* `sha256`, for qualification. The plugin hands Bun these bytes; there is nothing to write.
|
|
112
113
|
*/
|
|
113
114
|
export type NativePackagingEmbeddedAsset = z.infer<typeof EmbeddedAssetSchema>;
|
|
114
|
-
/**
|
|
115
|
-
* Structural Bun plugin protocol: declarations need no Bun runtime or ambient types.
|
|
116
|
-
*/
|
|
117
|
-
export type NativePackagingPlugin = {
|
|
118
|
-
name: string;
|
|
119
|
-
setup: (build: {
|
|
120
|
-
config: {
|
|
121
|
-
splitting?: boolean;
|
|
122
|
-
naming?: string | {
|
|
123
|
-
entry?: string;
|
|
124
|
-
};
|
|
125
|
-
entrypoints: string[];
|
|
126
|
-
};
|
|
127
|
-
onLoad: (options: {
|
|
128
|
-
filter: RegExp;
|
|
129
|
-
}, callback: (args: {
|
|
130
|
-
path: string;
|
|
131
|
-
}) => {
|
|
132
|
-
contents: string;
|
|
133
|
-
loader: 'js';
|
|
134
|
-
} | {
|
|
135
|
-
contents: Uint8Array;
|
|
136
|
-
loader: 'napi';
|
|
137
|
-
} | undefined) => unknown;
|
|
138
|
-
onResolve: (options: {
|
|
139
|
-
filter: RegExp;
|
|
140
|
-
}, callback: (args: {
|
|
141
|
-
path: string;
|
|
142
|
-
importer: string;
|
|
143
|
-
}) => {
|
|
144
|
-
path: string;
|
|
145
|
-
external: boolean;
|
|
146
|
-
} | undefined) => unknown;
|
|
147
|
-
}) => void;
|
|
148
|
-
};
|
|
149
115
|
/**
|
|
150
116
|
* `ready` with the verified assets to write and the Bun plugin to add, or a refusal naming an
|
|
151
117
|
* unsupported architecture, a missing asset or an asset whose bytes differ from the published
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-packaging.d.ts","sourceRoot":"","sources":["../../src/files/native-packaging.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"native-packaging.d.ts","sourceRoot":"","sources":["../../src/files/native-packaging.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,2BAA2B,CAAC;AAMnC,QAAA,MAAM,kBAAkB;;;EAA2B,CAAC;AACpD,mGAAmG;AACnG,QAAA,MAAM,cAAc;;EAAqB,CAAC;AAe1C,QAAA,MAAM,mBAAmB;;;;;;;;iBAKvB,CAAC;AACH;;;GAGG;AACH,QAAA,MAAM,qBAAqB;;;;;;kBAIzB,CAAC;AACH,QAAA,MAAM,qBAAqB;;;;;;;;iBAOzB,CAAC;AAwCH,QAAA,MAAM,mBAAmB;;;;iBAIvB,CAAC;AACH,QAAA,MAAM,WAAW;;;;;iBAAyD,CAAC;AAC3E,QAAA,MAAM,iBAAiB;;;;;;;;;iBAA2D,CAAC;AAKnF,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAuBjB,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,sBAAsB,CAAC,QAAQ,SAAS,OAAO,GAAG,KAAK,IAAI,QAAQ,SAAS,IAAI,GACxF,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GACrC,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACxC,mGAAmG;AACnG,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACnF;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,OAAO,GAAG,KAAK,IAAI,QAAQ,SAAS,IAAI,GACtF,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,GACjC,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAChC;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,OAAO,GAAG,KAAK,IAC9D,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAC7B;IACE,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;IACzC,YAAY,EAAE,QAAQ,SAAS,IAAI,GAC/B,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,EAAE,GACpC,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACzC,MAAM,EAAE,qBAAqB,CAAC;CAC/B,CAAC;AAEN;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GACrC,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAC7B;IACE,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;IACzC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,4BAA4B,EAAE,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC;CAC/B,CAAC;AAsLN;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,8BAA8B,GACtC,6BAA6B,CAAC;AACjC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,qBAAqB,CAAC;AAC9F,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,CAAC,IAAI,CAAC,GACpC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAC/B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACvC,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAClC,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,GAAG,8BAA8B,GACxE,qBAAqB,CAAC,OAAO,CAAC,GAAG,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/internal/until-aborted.ts
|
|
2
|
+
function abortReason(signal) {
|
|
3
|
+
return signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
4
|
+
}
|
|
5
|
+
function untilAborted(pending, signal) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const abort = () => reject(abortReason(signal));
|
|
8
|
+
if (signal.aborted) {
|
|
9
|
+
pending.catch(() => {
|
|
10
|
+
return;
|
|
11
|
+
});
|
|
12
|
+
abort();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
16
|
+
pending.then((value) => {
|
|
17
|
+
signal.removeEventListener("abort", abort);
|
|
18
|
+
resolve(value);
|
|
19
|
+
}, (error) => {
|
|
20
|
+
signal.removeEventListener("abort", abort);
|
|
21
|
+
reject(error);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { abortReason, untilAborted };
|
|
@@ -14,7 +14,6 @@ import { z } from "zod";
|
|
|
14
14
|
import { execFile } from "node:child_process";
|
|
15
15
|
import { readFile } from "node:fs/promises";
|
|
16
16
|
import { platform } from "node:os";
|
|
17
|
-
import { promisify } from "node:util";
|
|
18
17
|
var detectedIdentity;
|
|
19
18
|
async function firstReadableLine(paths) {
|
|
20
19
|
for (const path of paths) {
|
|
@@ -26,7 +25,16 @@ async function firstReadableLine(paths) {
|
|
|
26
25
|
}
|
|
27
26
|
return null;
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
function run(file, args, options) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
execFile(file, args, { ...options, encoding: "utf8" }, (error, stdout) => {
|
|
31
|
+
if (error)
|
|
32
|
+
reject(error);
|
|
33
|
+
else
|
|
34
|
+
resolve({ stdout });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
30
38
|
function parsePlatformUuid(dump) {
|
|
31
39
|
return /"IOPlatformUUID"\s*=\s*"([^"]+)"/.exec(dump)?.[1] ?? null;
|
|
32
40
|
}
|
|
@@ -34,8 +42,7 @@ async function readDarwinPlatformUuid(command = "ioreg") {
|
|
|
34
42
|
try {
|
|
35
43
|
const { stdout } = await run(command, ["-rd1", "-c", "IOPlatformExpertDevice"], {
|
|
36
44
|
timeout: 2000,
|
|
37
|
-
maxBuffer: 1 << 20
|
|
38
|
-
encoding: "utf8"
|
|
45
|
+
maxBuffer: 1 << 20
|
|
39
46
|
});
|
|
40
47
|
return parsePlatformUuid(stdout);
|
|
41
48
|
} catch {
|
|
@@ -67,8 +74,7 @@ async function isZombieProcess(pid, seam = {}) {
|
|
|
67
74
|
try {
|
|
68
75
|
const { stdout } = await run(psCommand, ["-o", "state=", "-p", String(pid)], {
|
|
69
76
|
timeout: 2000,
|
|
70
|
-
maxBuffer: 1 << 16
|
|
71
|
-
encoding: "utf8"
|
|
77
|
+
maxBuffer: 1 << 16
|
|
72
78
|
});
|
|
73
79
|
return stdout.trim().startsWith("Z");
|
|
74
80
|
} catch {
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
withUploadProgress,
|
|
15
15
|
parseApiErrorBody
|
|
16
16
|
} from "./index-7jvwrjqa.js";
|
|
17
|
+
import {
|
|
18
|
+
abortReason,
|
|
19
|
+
untilAborted
|
|
20
|
+
} from "./index-a5qr2rj6.js";
|
|
17
21
|
import {
|
|
18
22
|
inputIsQuery
|
|
19
23
|
} from "./index-xhzq2qvj.js";
|
|
@@ -32,108 +36,259 @@ import {
|
|
|
32
36
|
|
|
33
37
|
// src/internal/bounded-lines.ts
|
|
34
38
|
var DEFAULT_STREAM_LINE_BYTES = 1024 * 1024;
|
|
39
|
+
|
|
40
|
+
class StreamLineLimitError2 extends RangeError {
|
|
41
|
+
limitBytes;
|
|
42
|
+
lineBytes;
|
|
43
|
+
name = "StreamLineLimitError";
|
|
44
|
+
constructor(limitBytes, lineBytes) {
|
|
45
|
+
super(`Stream line exceeds the ${limitBytes} byte limit (${lineBytes} bytes so far)`);
|
|
46
|
+
this.limitBytes = limitBytes;
|
|
47
|
+
this.lineBytes = lineBytes;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class StreamTruncatedLineError2 extends SyntaxError {
|
|
52
|
+
lineBytes;
|
|
53
|
+
name = "StreamTruncatedLineError";
|
|
54
|
+
constructor(lineBytes) {
|
|
55
|
+
super(`Stream ended with an unterminated final line (${lineBytes} bytes)`);
|
|
56
|
+
this.lineBytes = lineBytes;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
35
59
|
function lineLimit(value) {
|
|
36
60
|
const resolved = value ?? DEFAULT_STREAM_LINE_BYTES;
|
|
37
61
|
assertPositiveSafeInteger("maxLineBytes", resolved);
|
|
38
62
|
return resolved;
|
|
39
63
|
}
|
|
40
|
-
function
|
|
41
|
-
if (left.byteLength === 0)
|
|
42
|
-
return right.slice();
|
|
43
|
-
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
44
|
-
result.set(left);
|
|
45
|
-
result.set(right, left.byteLength);
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
async function* readBoundedUtf8Lines(response, maxLineBytes, requireFinalNewline = false) {
|
|
49
|
-
const reader = response.body?.getReader();
|
|
50
|
-
if (!reader)
|
|
51
|
-
return;
|
|
64
|
+
function createLineSplitter(maxLineBytes, requireFinalNewline = false) {
|
|
52
65
|
const limit = lineLimit(maxLineBytes);
|
|
53
66
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
let parts = [];
|
|
68
|
+
let pendingBytes = 0;
|
|
69
|
+
let ended = false;
|
|
70
|
+
let failed = false;
|
|
71
|
+
const drop = () => {
|
|
72
|
+
parts = [];
|
|
73
|
+
pendingBytes = 0;
|
|
74
|
+
};
|
|
75
|
+
const retain = (bytes) => {
|
|
76
|
+
if (bytes.byteLength === 0)
|
|
77
|
+
return;
|
|
78
|
+
pendingBytes += bytes.byteLength;
|
|
79
|
+
if (pendingBytes > limit) {
|
|
80
|
+
const seen = pendingBytes;
|
|
81
|
+
drop();
|
|
82
|
+
throw new StreamLineLimitError2(limit, seen);
|
|
83
|
+
}
|
|
84
|
+
parts.push(new Uint8Array(bytes));
|
|
85
|
+
};
|
|
86
|
+
const take = () => {
|
|
87
|
+
const line = new Uint8Array(pendingBytes);
|
|
88
|
+
let at = 0;
|
|
89
|
+
for (const part of parts) {
|
|
90
|
+
line.set(part, at);
|
|
91
|
+
at += part.byteLength;
|
|
92
|
+
}
|
|
93
|
+
drop();
|
|
94
|
+
return decoder.decode(line);
|
|
95
|
+
};
|
|
96
|
+
function* lines(chunk) {
|
|
97
|
+
if (ended)
|
|
98
|
+
throw new Error("Line decoder received bytes after end()");
|
|
99
|
+
if (failed)
|
|
100
|
+
throw new Error("Line decoder stopped at an earlier error; read the source again");
|
|
101
|
+
try {
|
|
60
102
|
let start = 0;
|
|
61
|
-
for (let index =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const lineBytes = joinBytes(pending, chunk.value.slice(start, index));
|
|
65
|
-
if (lineBytes.byteLength > limit) {
|
|
66
|
-
throw new RangeError(`Stream line exceeds the ${limit} byte limit`);
|
|
67
|
-
}
|
|
68
|
-
yield decoder.decode(lineBytes);
|
|
69
|
-
pending = new Uint8Array;
|
|
103
|
+
for (let index = chunk.indexOf(10);index !== -1; index = chunk.indexOf(10, start)) {
|
|
104
|
+
retain(chunk.subarray(start, index));
|
|
105
|
+
yield take();
|
|
70
106
|
start = index + 1;
|
|
71
107
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
retain(chunk.subarray(start));
|
|
109
|
+
} catch (error) {
|
|
110
|
+
failed = true;
|
|
111
|
+
throw error;
|
|
76
112
|
}
|
|
77
|
-
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
lines,
|
|
116
|
+
push: (chunk) => [...lines(chunk)],
|
|
117
|
+
end() {
|
|
118
|
+
ended = true;
|
|
119
|
+
if (pendingBytes === 0)
|
|
120
|
+
return [];
|
|
78
121
|
if (requireFinalNewline) {
|
|
79
|
-
|
|
122
|
+
const seen = pendingBytes;
|
|
123
|
+
drop();
|
|
124
|
+
throw new StreamTruncatedLineError2(seen);
|
|
125
|
+
}
|
|
126
|
+
return [take()];
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function createBoundedLineDecoder(maxLineBytes, requireFinalNewline = false) {
|
|
131
|
+
const { push, end } = createLineSplitter(maxLineBytes, requireFinalNewline);
|
|
132
|
+
return { push, end };
|
|
133
|
+
}
|
|
134
|
+
async function* chunksOf(source, signal) {
|
|
135
|
+
signal?.throwIfAborted();
|
|
136
|
+
const stream = source instanceof Response ? source.body : source;
|
|
137
|
+
if (stream === null)
|
|
138
|
+
return;
|
|
139
|
+
if (stream instanceof ReadableStream) {
|
|
140
|
+
const reader = stream.getReader();
|
|
141
|
+
const abort = () => {
|
|
142
|
+
if (signal)
|
|
143
|
+
reader.cancel(abortReason(signal)).catch(() => {
|
|
144
|
+
return;
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
148
|
+
try {
|
|
149
|
+
for (;; ) {
|
|
150
|
+
const chunk = await reader.read();
|
|
151
|
+
signal?.throwIfAborted();
|
|
152
|
+
if (chunk.done)
|
|
153
|
+
return;
|
|
154
|
+
yield chunk.value;
|
|
155
|
+
}
|
|
156
|
+
} finally {
|
|
157
|
+
signal?.removeEventListener("abort", abort);
|
|
158
|
+
await reader.cancel().catch(() => {
|
|
159
|
+
return;
|
|
160
|
+
});
|
|
161
|
+
reader.releaseLock();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
165
|
+
let finished = false;
|
|
166
|
+
try {
|
|
167
|
+
for (;; ) {
|
|
168
|
+
const pending = iterator.next();
|
|
169
|
+
const next = await (signal ? untilAborted(pending, signal) : pending);
|
|
170
|
+
if (next.done) {
|
|
171
|
+
finished = true;
|
|
172
|
+
return;
|
|
80
173
|
}
|
|
81
|
-
yield
|
|
174
|
+
yield next.value;
|
|
82
175
|
}
|
|
83
176
|
} finally {
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
177
|
+
if (!finished && signal?.aborted)
|
|
178
|
+
iterator.return?.().catch(() => {
|
|
179
|
+
return;
|
|
180
|
+
});
|
|
181
|
+
else if (!finished)
|
|
182
|
+
await iterator.return?.().catch(() => {
|
|
183
|
+
return;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function* readBoundedUtf8Lines(source, maxLineBytes, requireFinalNewline = false, signal) {
|
|
188
|
+
const splitter = createLineSplitter(maxLineBytes, requireFinalNewline);
|
|
189
|
+
for await (const chunk of chunksOf(source, signal)) {
|
|
190
|
+
for (const line of splitter.lines(chunk)) {
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
yield line;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
for (const line of splitter.end()) {
|
|
196
|
+
signal?.throwIfAborted();
|
|
197
|
+
yield line;
|
|
88
198
|
}
|
|
89
199
|
}
|
|
90
200
|
|
|
91
201
|
// src/browser/stream.ts
|
|
202
|
+
function ndjsonLine(rawLine) {
|
|
203
|
+
return (rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine).trim();
|
|
204
|
+
}
|
|
92
205
|
function parseFailure(raw, error, onParseError) {
|
|
93
206
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
94
207
|
if (!onParseError)
|
|
95
208
|
throw failure;
|
|
96
209
|
onParseError(raw, failure);
|
|
97
210
|
}
|
|
98
|
-
async function* parseNDJSON2(
|
|
211
|
+
async function* parseNDJSON2(source, options) {
|
|
212
|
+
let reporting = false;
|
|
99
213
|
try {
|
|
100
|
-
for await (const rawLine of readBoundedUtf8Lines(
|
|
101
|
-
const line = (rawLine
|
|
214
|
+
for await (const rawLine of readBoundedUtf8Lines(source, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, options?.finalLine === "require-newline", options?.signal)) {
|
|
215
|
+
const line = ndjsonLine(rawLine);
|
|
102
216
|
if (line === "")
|
|
103
217
|
continue;
|
|
218
|
+
let value;
|
|
104
219
|
try {
|
|
105
|
-
|
|
220
|
+
value = JSON.parse(line);
|
|
106
221
|
} catch (error) {
|
|
222
|
+
reporting = true;
|
|
107
223
|
parseFailure(line, error, options?.onParseError);
|
|
224
|
+
reporting = false;
|
|
225
|
+
continue;
|
|
108
226
|
}
|
|
227
|
+
yield value;
|
|
109
228
|
}
|
|
110
229
|
} catch (error) {
|
|
230
|
+
if (reporting || options?.signal?.aborted)
|
|
231
|
+
throw error;
|
|
111
232
|
parseFailure("", error, options?.onParseError);
|
|
112
233
|
}
|
|
113
234
|
}
|
|
114
|
-
|
|
235
|
+
function createNDJSONDecoder2(options) {
|
|
236
|
+
const lines = createBoundedLineDecoder(options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, options?.finalLine === "require-newline");
|
|
237
|
+
let failed = false;
|
|
238
|
+
const values = (rawLines) => {
|
|
239
|
+
const parsed = [];
|
|
240
|
+
for (const rawLine of rawLines) {
|
|
241
|
+
const line = ndjsonLine(rawLine);
|
|
242
|
+
if (line === "")
|
|
243
|
+
continue;
|
|
244
|
+
try {
|
|
245
|
+
parsed.push(JSON.parse(line));
|
|
246
|
+
} catch (error) {
|
|
247
|
+
parseFailure(line, error, options?.onParseError);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return parsed;
|
|
251
|
+
};
|
|
252
|
+
const guarded = (step) => {
|
|
253
|
+
if (failed)
|
|
254
|
+
throw new Error("NDJSON decoder stopped at an earlier error; read the source again");
|
|
255
|
+
try {
|
|
256
|
+
return values(step());
|
|
257
|
+
} catch (error) {
|
|
258
|
+
failed = true;
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
push: (chunk) => guarded(() => lines.push(chunk)),
|
|
264
|
+
end: () => guarded(() => lines.end())
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
async function* parseSSE2(source, options) {
|
|
268
|
+
let reporting = false;
|
|
115
269
|
try {
|
|
116
|
-
for await (const rawLine of readBoundedUtf8Lines(
|
|
270
|
+
for await (const rawLine of readBoundedUtf8Lines(source, options?.maxLineBytes ?? DEFAULT_STREAM_LINE_BYTES, false, options?.signal)) {
|
|
117
271
|
const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
118
272
|
if (!line.startsWith("data:"))
|
|
119
273
|
continue;
|
|
120
274
|
const data = line.slice(5).replace(/^ /, "");
|
|
121
275
|
if (data === "[DONE]")
|
|
122
276
|
return;
|
|
277
|
+
let value;
|
|
123
278
|
try {
|
|
124
|
-
|
|
279
|
+
value = JSON.parse(data);
|
|
125
280
|
} catch (error) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
281
|
+
reporting = true;
|
|
282
|
+
parseFailure(data, error, options?.onParseError);
|
|
283
|
+
reporting = false;
|
|
284
|
+
continue;
|
|
130
285
|
}
|
|
286
|
+
yield value;
|
|
131
287
|
}
|
|
132
288
|
} catch (error) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
options.onParseError("", failure);
|
|
289
|
+
if (reporting || options?.signal?.aborted)
|
|
290
|
+
throw error;
|
|
291
|
+
parseFailure("", error, options?.onParseError);
|
|
137
292
|
}
|
|
138
293
|
}
|
|
139
294
|
|
|
@@ -797,4 +952,4 @@ function createScopedUrlBuilders2(contracts, source, scopeConfigs) {
|
|
|
797
952
|
return buildScopedRegistry(contracts, scopeConfigs, "URL builder", (contract, config) => createUrlBuilder2(contract, source, config));
|
|
798
953
|
}
|
|
799
954
|
|
|
800
|
-
export { endpointHasArguments, parseNDJSON2, parseSSE2, contractEndpointMatchers2, createClient2, createClients2, createScopedClients2, createUrlBuilder2, createUrlBuilders2, createScopedUrlBuilders2 };
|
|
955
|
+
export { endpointHasArguments, StreamLineLimitError2, StreamTruncatedLineError2, parseNDJSON2, createNDJSONDecoder2, parseSSE2, contractEndpointMatchers2, createClient2, createClients2, createScopedClients2, createUrlBuilder2, createUrlBuilders2, createScopedUrlBuilders2 };
|
|
@@ -2,6 +2,30 @@ import {
|
|
|
2
2
|
isRecord
|
|
3
3
|
} from "./index-9jfdm5tg.js";
|
|
4
4
|
|
|
5
|
+
// src/telegram/not-dispatched.ts
|
|
6
|
+
class TelegramNotDispatchedError2 extends Error {
|
|
7
|
+
stage;
|
|
8
|
+
name = "TelegramNotDispatchedError";
|
|
9
|
+
code = "TELEGRAM_NOT_DISPATCHED";
|
|
10
|
+
constructor(stage, message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.stage = stage;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isTelegramNotDispatchedError(error) {
|
|
16
|
+
return error instanceof TelegramNotDispatchedError2 || error instanceof Error && error.name === "TelegramNotDispatchedError" && Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED";
|
|
17
|
+
}
|
|
18
|
+
function isTelegramNotDispatched(error, depth = 0) {
|
|
19
|
+
if (error instanceof TelegramNotDispatchedError2)
|
|
20
|
+
return true;
|
|
21
|
+
if (typeof error !== "object" || error === null || depth > 4)
|
|
22
|
+
return false;
|
|
23
|
+
if (Reflect.get(error, "code") === "TELEGRAM_NOT_DISPATCHED")
|
|
24
|
+
return true;
|
|
25
|
+
const nested = Reflect.get(error, "cause") ?? Reflect.get(error, "error");
|
|
26
|
+
return nested !== error && isTelegramNotDispatched(nested, depth + 1);
|
|
27
|
+
}
|
|
28
|
+
|
|
5
29
|
// src/telegram/send-failure.ts
|
|
6
30
|
var BY_DESCRIPTION = [
|
|
7
31
|
[/bot was blocked by the user|bot was kicked/i, "blocked-by-user"],
|
|
@@ -22,6 +46,7 @@ var TRAITS = {
|
|
|
22
46
|
"rate-limited": { retryable: true, recipientUnreachable: false },
|
|
23
47
|
"message-invalid": { retryable: false, recipientUnreachable: false },
|
|
24
48
|
"server-error": { retryable: true, recipientUnreachable: false },
|
|
49
|
+
"not-dispatched": { retryable: true, recipientUnreachable: false },
|
|
25
50
|
unknown: { retryable: false, recipientUnreachable: false }
|
|
26
51
|
};
|
|
27
52
|
function isSendFailureReason(value) {
|
|
@@ -71,6 +96,8 @@ function descriptionOf(value, depth = 0) {
|
|
|
71
96
|
return [own, message, nested].filter(Boolean).join(" ");
|
|
72
97
|
}
|
|
73
98
|
function classifyTelegramSendFailure2(error) {
|
|
99
|
+
if (isTelegramNotDispatched(error))
|
|
100
|
+
return { reason: "not-dispatched", ...TRAITS["not-dispatched"], evidence: "transport" };
|
|
74
101
|
const status = statusOf(error);
|
|
75
102
|
const retryAfterSeconds = retryAfterOf(error);
|
|
76
103
|
const description = descriptionOf(error);
|
|
@@ -141,4 +168,4 @@ function classifyTelegramEditRefusal(error) {
|
|
|
141
168
|
return "other";
|
|
142
169
|
}
|
|
143
170
|
|
|
144
|
-
export { TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
|
|
171
|
+
export { TelegramNotDispatchedError2, isTelegramNotDispatchedError, TELEGRAM_SEND_FAILURE_REASONS2, classifyTelegramSendFailure2, classifyTelegramEditRefusal };
|
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
export declare const DEFAULT_STREAM_LINE_BYTES: number;
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A line grew past its byte limit. The reader throws as soon as the retained bytes cross the
|
|
4
|
+
* limit, so memory stays bounded by the limit plus the chunk being read.
|
|
5
|
+
*/
|
|
6
|
+
export declare class StreamLineLimitError extends RangeError {
|
|
7
|
+
/** The configured `maxLineBytes`. */
|
|
8
|
+
readonly limitBytes: number;
|
|
9
|
+
/** Bytes of the line seen when it crossed the limit; the line itself is longer still. */
|
|
10
|
+
readonly lineBytes: number;
|
|
11
|
+
readonly name = "StreamLineLimitError";
|
|
12
|
+
constructor(
|
|
13
|
+
/** The configured `maxLineBytes`. */
|
|
14
|
+
limitBytes: number,
|
|
15
|
+
/** Bytes of the line seen when it crossed the limit; the line itself is longer still. */
|
|
16
|
+
lineBytes: number);
|
|
17
|
+
}
|
|
18
|
+
/** The source ended inside a line while `finalLine: 'require-newline'` asked for a delimiter. */
|
|
19
|
+
export declare class StreamTruncatedLineError extends SyntaxError {
|
|
20
|
+
/** Bytes of the unterminated final line. */
|
|
21
|
+
readonly lineBytes: number;
|
|
22
|
+
readonly name = "StreamTruncatedLineError";
|
|
23
|
+
constructor(
|
|
24
|
+
/** Bytes of the unterminated final line. */
|
|
25
|
+
lineBytes: number);
|
|
26
|
+
}
|
|
27
|
+
/** Bytes a line reader accepts: a `Response` body, a web stream, or any async byte iterable. */
|
|
28
|
+
export type StreamByteSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
29
|
+
/**
|
|
30
|
+
* Push-driven bounded line splitter for sources that deliver bytes through a callback, such as
|
|
31
|
+
* a `Bun.listen`/`Bun.connect` socket's `data` handler. Lines are split on `\n` in bytes and
|
|
32
|
+
* decoded as fatal UTF-8 only once complete, so a character split across chunks is never torn.
|
|
33
|
+
* An error (a line past the limit, invalid UTF-8) fails the whole `push` and stops the decoder:
|
|
34
|
+
* the bytes after it belong to the failed line, so every later `push` throws.
|
|
35
|
+
*/
|
|
36
|
+
export interface BoundedLineDecoder {
|
|
37
|
+
/** Feed one chunk; returns the lines it completed, without their `\n`. */
|
|
38
|
+
push(chunk: Uint8Array): string[];
|
|
39
|
+
/**
|
|
40
|
+
* The source ended. Returns the unterminated final line, if any, as one more line, or throws
|
|
41
|
+
* `StreamTruncatedLineError` when a final newline is required.
|
|
42
|
+
*/
|
|
43
|
+
end(): string[];
|
|
44
|
+
}
|
|
45
|
+
export declare function createBoundedLineDecoder(maxLineBytes?: number, requireFinalNewline?: boolean): BoundedLineDecoder;
|
|
46
|
+
/** Bounded, fatal-UTF-8 line reader shared by the NDJSON and SSE parsers. */
|
|
47
|
+
export declare function readBoundedUtf8Lines(source: StreamByteSource, maxLineBytes?: number, requireFinalNewline?: boolean, signal?: AbortSignal): AsyncGenerator<string>;
|
|
4
48
|
//# sourceMappingURL=bounded-lines.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-lines.d.ts","sourceRoot":"","sources":["../../src/internal/bounded-lines.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bounded-lines.d.ts","sourceRoot":"","sources":["../../src/internal/bounded-lines.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,yBAAyB,QAAc,CAAC;AAErD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;IAGhD,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,MAAM;IAL5B,SAAkB,IAAI,0BAA0B;IAChD;IACE,qCAAqC;IAC5B,UAAU,EAAE,MAAM;IAC3B,yFAAyF;IAChF,SAAS,EAAE,MAAM,EAG3B;CACF;AAED,iGAAiG;AACjG,qBAAa,wBAAyB,SAAQ,WAAW;IAGrD,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,EAAE,MAAM;IAH5B,SAAkB,IAAI,8BAA8B;IACpD;IACE,4CAA4C;IACnC,SAAS,EAAE,MAAM,EAG3B;CACF;AAED,gGAAgG;AAChG,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,cAAc,CAAC,UAAU,CAAC,GAC1B,aAAa,CAAC,UAAU,CAAC,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,CAAC;IAClC;;;OAGG;IACH,GAAG,IAAI,MAAM,EAAE,CAAC;CACjB;AAiFD,wBAAgB,wBAAwB,CACtC,YAAY,CAAC,EAAE,MAAM,EACrB,mBAAmB,UAAQ,GAC1B,kBAAkB,CAGpB;AAkDD,6EAA6E;AAC7E,wBAAuB,oBAAoB,CACzC,MAAM,EAAE,gBAAgB,EACxB,YAAY,CAAC,EAAE,MAAM,EACrB,mBAAmB,UAAQ,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,MAAM,CAAC,CAcxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-identity.d.ts","sourceRoot":"","sources":["../../src/internal/process-identity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process-identity.d.ts","sourceRoot":"","sources":["../../src/internal/process-identity.ts"],"names":[],"mappings":"AA6DA;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE7D;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,SAAU,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBtF;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAW1F;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,KAAK,YAAY,MAAM,SAA4B,GAClD,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,CAY3B;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,OAAO,CAAC,CAsBlB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The signal's reason, or the `AbortError` a signal aborted without one stands for. */
|
|
2
|
+
export declare function abortReason(signal: AbortSignal): unknown;
|
|
3
|
+
/**
|
|
4
|
+
* `pending`, or the signal's reason as soon as it aborts. Each call owns its listener and removes
|
|
5
|
+
* it when `pending` settles: one promise shared by every call would retain each result for as long
|
|
6
|
+
* as the signal lives. `pending` itself is not cancelled, only no longer waited for.
|
|
7
|
+
*/
|
|
8
|
+
export declare function untilAborted<T>(pending: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
9
|
+
//# sourceMappingURL=until-aborted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"until-aborted.d.ts","sourceRoot":"","sources":["../../src/internal/until-aborted.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAExD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAoBpF"}
|