@linxiraos/pi-utils 1.0.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 +449 -0
- package/README.md +36 -0
- package/dist/types/abortable.d.ts +32 -0
- package/dist/types/acp/connection.d.ts +118 -0
- package/dist/types/acp/protocol.d.ts +526 -0
- package/dist/types/acp/schema.d.ts +41 -0
- package/dist/types/acp/stream.d.ts +8 -0
- package/dist/types/acp/transport.d.ts +81 -0
- package/dist/types/acp.d.ts +6 -0
- package/dist/types/async.d.ts +20 -0
- package/dist/types/binary.d.ts +17 -0
- package/dist/types/browsers.d.ts +68 -0
- package/dist/types/chalk.d.ts +125 -0
- package/dist/types/cli.d.ts +134 -0
- package/dist/types/color.d.ts +102 -0
- package/dist/types/dates.d.ts +7 -0
- package/dist/types/dirs.d.ts +282 -0
- package/dist/types/docx/converter.d.ts +46 -0
- package/dist/types/docx/xml.d.ts +26 -0
- package/dist/types/docx/zip.d.ts +6 -0
- package/dist/types/docx.d.ts +11 -0
- package/dist/types/dom/core.d.ts +431 -0
- package/dist/types/dom/parser.d.ts +7 -0
- package/dist/types/dom/selector.d.ts +5 -0
- package/dist/types/dom.d.ts +5 -0
- package/dist/types/env.d.ts +124 -0
- package/dist/types/fetch-retry.d.ts +96 -0
- package/dist/types/file-lock.d.ts +23 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +46 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/headers.d.ts +34 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/json-parse.d.ts +74 -0
- package/dist/types/json.d.ts +14 -0
- package/dist/types/logger/rotating-file.d.ts +18 -0
- package/dist/types/logger.d.ts +96 -0
- package/dist/types/loop-phase.d.ts +10 -0
- package/dist/types/lru.d.ts +46 -0
- package/dist/types/marked/core.d.ts +445 -0
- package/dist/types/marked.d.ts +2 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/module-timer.d.ts +1 -0
- package/dist/types/path-tree.d.ts +76 -0
- package/dist/types/path.d.ts +2 -0
- package/dist/types/peek-file.d.ts +29 -0
- package/dist/types/postmortem.d.ts +104 -0
- package/dist/types/process-name.d.ts +7 -0
- package/dist/types/procmgr.d.ts +74 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +110 -0
- package/dist/types/readability/readability.d.ts +9 -0
- package/dist/types/readability/readerable.d.ts +10 -0
- package/dist/types/readability/types.d.ts +70 -0
- package/dist/types/readability.d.ts +4 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/runtime-install.d.ts +78 -0
- package/dist/types/sanitize-text.d.ts +29 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stderr-guard.d.ts +22 -0
- package/dist/types/stream.d.ts +67 -0
- package/dist/types/tab-spacing.d.ts +24 -0
- package/dist/types/temp.d.ts +17 -0
- package/dist/types/template.d.ts +62 -0
- package/dist/types/timing-buffer.d.ts +22 -0
- package/dist/types/tls-fetch.d.ts +37 -0
- package/dist/types/turndown/gfm.d.ts +11 -0
- package/dist/types/turndown/html.d.ts +5 -0
- package/dist/types/turndown/service.d.ts +21 -0
- package/dist/types/turndown/types.d.ts +70 -0
- package/dist/types/turndown.d.ts +4 -0
- package/dist/types/type-guards.d.ts +5 -0
- package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
- package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
- package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
- package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
- package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
- package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
- package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
- package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
- package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
- package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
- package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
- package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
- package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
- package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
- package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
- package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
- package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
- package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
- package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
- package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
- package/dist/types/version.d.ts +18 -0
- package/dist/types/vterm/buffer.d.ts +99 -0
- package/dist/types/vterm/terminal.d.ts +44 -0
- package/dist/types/vterm.d.ts +8 -0
- package/dist/types/which.d.ts +37 -0
- package/dist/types/worker-host.d.ts +51 -0
- package/dist/types/xml.d.ts +31 -0
- package/package.json +59 -0
- package/src/abortable.ts +109 -0
- package/src/acp/connection.ts +344 -0
- package/src/acp/protocol.ts +466 -0
- package/src/acp/schema.ts +160 -0
- package/src/acp/stream.ts +82 -0
- package/src/acp/transport.ts +213 -0
- package/src/acp.ts +6 -0
- package/src/async.ts +91 -0
- package/src/binary.ts +50 -0
- package/src/browsers.ts +501 -0
- package/src/chalk.ts +312 -0
- package/src/cli.ts +529 -0
- package/src/color.ts +302 -0
- package/src/dates.ts +194 -0
- package/src/dirs.ts +1026 -0
- package/src/docx/converter.ts +681 -0
- package/src/docx/xml.ts +166 -0
- package/src/docx/zip.ts +87 -0
- package/src/docx.ts +20 -0
- package/src/dom/core.ts +1254 -0
- package/src/dom/parser.ts +370 -0
- package/src/dom/selector.ts +290 -0
- package/src/dom.ts +33 -0
- package/src/env.ts +400 -0
- package/src/fetch-retry.ts +379 -0
- package/src/file-lock.ts +69 -0
- package/src/format.ts +113 -0
- package/src/frontmatter.ts +205 -0
- package/src/fs-error.ts +56 -0
- package/src/glob.ts +189 -0
- package/src/headers.ts +167 -0
- package/src/index.ts +59 -0
- package/src/json-parse.ts +821 -0
- package/src/json.ts +23 -0
- package/src/logger/rotating-file.ts +149 -0
- package/src/logger.ts +798 -0
- package/src/loop-phase.ts +49 -0
- package/src/lru.ts +185 -0
- package/src/marked/core.ts +1576 -0
- package/src/marked.ts +2 -0
- package/src/mermaid-ascii.ts +31 -0
- package/src/mime.ts +159 -0
- package/src/module-timer.ts +148 -0
- package/src/path-tree.ts +147 -0
- package/src/path.ts +28 -0
- package/src/peek-file.ts +188 -0
- package/src/postmortem.ts +433 -0
- package/src/process-name.ts +57 -0
- package/src/procmgr.ts +247 -0
- package/src/prompt.ts +545 -0
- package/src/ptree.ts +412 -0
- package/src/readability/readability.ts +533 -0
- package/src/readability/readerable.ts +51 -0
- package/src/readability/types.ts +72 -0
- package/src/readability.ts +11 -0
- package/src/ring.ts +169 -0
- package/src/runtime-install.ts +393 -0
- package/src/sanitize-text.ts +96 -0
- package/src/snowflake.ts +121 -0
- package/src/stderr-guard.ts +155 -0
- package/src/stream.ts +454 -0
- package/src/tab-spacing.ts +336 -0
- package/src/temp.ts +134 -0
- package/src/template.ts +586 -0
- package/src/timing-buffer.ts +47 -0
- package/src/tls-fetch.ts +178 -0
- package/src/turndown/gfm.ts +106 -0
- package/src/turndown/html.ts +257 -0
- package/src/turndown/service.ts +334 -0
- package/src/turndown/types.ts +81 -0
- package/src/turndown.ts +5 -0
- package/src/type-guards.ts +17 -0
- package/src/vendor/mermaid-ascii/NOTICE +33 -0
- package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
- package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
- package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
- package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
- package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
- package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
- package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
- package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
- package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
- package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
- package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
- package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +277 -0
- package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
- package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
- package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
- package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
- package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
- package/src/vendor/mermaid-ascii/class/types.ts +121 -0
- package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
- package/src/vendor/mermaid-ascii/er/types.ts +91 -0
- package/src/vendor/mermaid-ascii/index.ts +14 -0
- package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
- package/src/vendor/mermaid-ascii/parser.ts +645 -0
- package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
- package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
- package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
- package/src/vendor/mermaid-ascii/types.ts +164 -0
- package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
- package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
- package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
- package/src/version.ts +99 -0
- package/src/vterm/buffer.ts +218 -0
- package/src/vterm/terminal.ts +773 -0
- package/src/vterm.ts +8 -0
- package/src/which.ts +234 -0
- package/src/worker-host.ts +100 -0
- package/src/xml.ts +313 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/** Behavior-compatible reimplementation of linkedom's used surface. */
|
|
2
|
+
/** DOM node type constants. */
|
|
3
|
+
export declare const enum NodeType {
|
|
4
|
+
ELEMENT = 1,
|
|
5
|
+
ATTRIBUTE = 2,
|
|
6
|
+
TEXT = 3,
|
|
7
|
+
COMMENT = 8,
|
|
8
|
+
DOCUMENT = 9,
|
|
9
|
+
DOCUMENT_FRAGMENT = 11
|
|
10
|
+
}
|
|
11
|
+
interface EventInit {
|
|
12
|
+
bubbles?: boolean;
|
|
13
|
+
cancelable?: boolean;
|
|
14
|
+
composed?: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface CustomEventInit<T> extends EventInit {
|
|
17
|
+
detail?: T;
|
|
18
|
+
}
|
|
19
|
+
interface ElementCreationOptions {
|
|
20
|
+
is?: string;
|
|
21
|
+
}
|
|
22
|
+
type FrameRequestCallback = (time: number) => void;
|
|
23
|
+
/** Minimal browser event implementation. */
|
|
24
|
+
export declare class Event {
|
|
25
|
+
#private;
|
|
26
|
+
type: string;
|
|
27
|
+
bubbles: boolean;
|
|
28
|
+
cancelable: boolean;
|
|
29
|
+
target: EventTarget | null;
|
|
30
|
+
currentTarget: EventTarget | null;
|
|
31
|
+
defaultPrevented: boolean;
|
|
32
|
+
constructor(type: string, init?: EventInit);
|
|
33
|
+
/** Initialize an event created through Document.createEvent. */
|
|
34
|
+
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
|
35
|
+
/** Cancel this event when it is cancelable. */
|
|
36
|
+
preventDefault(): void;
|
|
37
|
+
/** Stop bubbling this event. */
|
|
38
|
+
stopPropagation(): void;
|
|
39
|
+
/** Whether propagation has been stopped. */
|
|
40
|
+
get propagationStopped(): boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Browser custom event carrying a detail value. */
|
|
43
|
+
export declare class CustomEvent<T = unknown> extends Event {
|
|
44
|
+
readonly detail: T | undefined;
|
|
45
|
+
constructor(type: string, init?: CustomEventInit<T>);
|
|
46
|
+
}
|
|
47
|
+
type EventListener = ((event: Event) => void) | {
|
|
48
|
+
handleEvent(event: Event): void;
|
|
49
|
+
};
|
|
50
|
+
/** Minimal event-target implementation used by DOM nodes and window. */
|
|
51
|
+
export declare class EventTarget {
|
|
52
|
+
#private;
|
|
53
|
+
/** Register an event listener. */
|
|
54
|
+
addEventListener(type: string, listener: EventListener | null): void;
|
|
55
|
+
/** Remove an event listener. */
|
|
56
|
+
removeEventListener(type: string, listener: EventListener | null): void;
|
|
57
|
+
/** Dispatch an event to listeners and optionally through node ancestors. */
|
|
58
|
+
dispatchEvent(event: Event): boolean;
|
|
59
|
+
}
|
|
60
|
+
/** Base class for the implemented DOM tree. */
|
|
61
|
+
export declare class Node extends EventTarget {
|
|
62
|
+
static readonly ELEMENT_NODE = NodeType.ELEMENT;
|
|
63
|
+
static readonly ATTRIBUTE_NODE = NodeType.ATTRIBUTE;
|
|
64
|
+
static readonly TEXT_NODE = NodeType.TEXT;
|
|
65
|
+
static readonly COMMENT_NODE = NodeType.COMMENT;
|
|
66
|
+
static readonly DOCUMENT_NODE = NodeType.DOCUMENT;
|
|
67
|
+
static readonly DOCUMENT_FRAGMENT_NODE = NodeType.DOCUMENT_FRAGMENT;
|
|
68
|
+
readonly nodeType: number;
|
|
69
|
+
readonly nodeName: string;
|
|
70
|
+
parentNode: Node | null;
|
|
71
|
+
ownerDocument: Document | null;
|
|
72
|
+
childNodes: Node[];
|
|
73
|
+
constructor(nodeType: number, nodeName: string, ownerDocument?: Document | null);
|
|
74
|
+
/** First child node, if present. */
|
|
75
|
+
get firstChild(): Node | null;
|
|
76
|
+
/** Last child node, if present. */
|
|
77
|
+
get lastChild(): Node | null;
|
|
78
|
+
/** Previous node with the same parent. */
|
|
79
|
+
get previousSibling(): Node | null;
|
|
80
|
+
/** Next node with the same parent. */
|
|
81
|
+
get nextSibling(): Node | null;
|
|
82
|
+
/** Connectedness to a document. */
|
|
83
|
+
get isConnected(): boolean;
|
|
84
|
+
/** Node value for character-data nodes. */
|
|
85
|
+
get nodeValue(): string | null;
|
|
86
|
+
set nodeValue(_value: string | null);
|
|
87
|
+
/** Text contained by this node. */
|
|
88
|
+
get textContent(): string | null;
|
|
89
|
+
set textContent(value: string | null);
|
|
90
|
+
/** Parent element, excluding document and fragments. */
|
|
91
|
+
get parentElement(): Element | null;
|
|
92
|
+
/** Append a node, moving it from its old parent. */
|
|
93
|
+
appendChild<T extends Node>(child: T): T;
|
|
94
|
+
/** Insert a node before a current child, or append for null. */
|
|
95
|
+
insertBefore<T extends Node>(child: T, reference: Node | null): T;
|
|
96
|
+
/** Replace a current child with another node. */
|
|
97
|
+
replaceChild<T extends Node>(child: Node, previous: T): T;
|
|
98
|
+
/** Remove a current child. */
|
|
99
|
+
removeChild<T extends Node>(child: T): T;
|
|
100
|
+
/** Replace all children with nodes or strings. */
|
|
101
|
+
replaceChildren(...children: Array<Node | string>): void;
|
|
102
|
+
/** Append nodes or strings. */
|
|
103
|
+
append(...children: Array<Node | string>): void;
|
|
104
|
+
/** Prepend nodes or strings. */
|
|
105
|
+
prepend(...children: Array<Node | string>): void;
|
|
106
|
+
/** Remove this node from its parent. */
|
|
107
|
+
remove(): void;
|
|
108
|
+
/** Replace this node in its parent. */
|
|
109
|
+
replaceWith(...nodes: Array<Node | string>): void;
|
|
110
|
+
/** Whether this node contains another node. */
|
|
111
|
+
contains(other: Node | null): boolean;
|
|
112
|
+
/** Clone this node, optionally including descendants. */
|
|
113
|
+
cloneNode(deep?: boolean): Node;
|
|
114
|
+
/** Compare tree position sufficiently for document-order consumers. */
|
|
115
|
+
compareDocumentPosition(other: Node): number;
|
|
116
|
+
setOwnerDocument(document: Document): void;
|
|
117
|
+
documentForCreation(): Document;
|
|
118
|
+
}
|
|
119
|
+
/** Text node. */
|
|
120
|
+
export declare class Text extends Node {
|
|
121
|
+
data: string;
|
|
122
|
+
serializeRaw: boolean;
|
|
123
|
+
constructor(data: string, ownerDocument?: Document | null, serializeRaw?: boolean);
|
|
124
|
+
/** Number of UTF-16 code units. */
|
|
125
|
+
get length(): number;
|
|
126
|
+
get nodeValue(): string;
|
|
127
|
+
set nodeValue(value: string | null);
|
|
128
|
+
get textContent(): string;
|
|
129
|
+
set textContent(value: string | null);
|
|
130
|
+
/** Split this text node at an offset. */
|
|
131
|
+
splitText(offset: number): Text;
|
|
132
|
+
cloneNode(): Text;
|
|
133
|
+
}
|
|
134
|
+
/** Comment node. */
|
|
135
|
+
export declare class Comment extends Text {
|
|
136
|
+
constructor(data: string, ownerDocument?: Document | null);
|
|
137
|
+
cloneNode(): Comment;
|
|
138
|
+
}
|
|
139
|
+
/** DOM attribute value object. */
|
|
140
|
+
export declare class Attr extends Node {
|
|
141
|
+
readonly name: string;
|
|
142
|
+
value: string;
|
|
143
|
+
readonly namespaceURI: string | null;
|
|
144
|
+
constructor(name: string, value: string, ownerDocument?: Document | null, namespaceURI?: string | null);
|
|
145
|
+
get nodeValue(): string;
|
|
146
|
+
set nodeValue(value: string | null);
|
|
147
|
+
get textContent(): string;
|
|
148
|
+
set textContent(value: string | null);
|
|
149
|
+
cloneNode(): Attr;
|
|
150
|
+
}
|
|
151
|
+
/** Array-like attribute collection. */
|
|
152
|
+
export declare class NamedNodeMap extends Array<Attr> {
|
|
153
|
+
/** Find an attribute case-insensitively. */
|
|
154
|
+
getNamedItem(name: string): Attr | null;
|
|
155
|
+
/** Set an attribute object and return the prior one. */
|
|
156
|
+
setNamedItem(attr: Attr): Attr | null;
|
|
157
|
+
/** Remove and return a named attribute. */
|
|
158
|
+
removeNamedItem(name: string): Attr;
|
|
159
|
+
}
|
|
160
|
+
/** Token-list view over an element class attribute. */
|
|
161
|
+
export declare class DOMTokenList implements Iterable<string> {
|
|
162
|
+
#private;
|
|
163
|
+
constructor(element: Element);
|
|
164
|
+
/** Token count. */
|
|
165
|
+
get length(): number;
|
|
166
|
+
/** String representation. */
|
|
167
|
+
get value(): string;
|
|
168
|
+
set value(value: string);
|
|
169
|
+
/** Add class tokens. */
|
|
170
|
+
add(...tokens: string[]): void;
|
|
171
|
+
/** Remove class tokens. */
|
|
172
|
+
remove(...tokens: string[]): void;
|
|
173
|
+
/** Whether a class token exists. */
|
|
174
|
+
contains(token: string): boolean;
|
|
175
|
+
/** Toggle a class token. */
|
|
176
|
+
toggle(token: string, force?: boolean): boolean;
|
|
177
|
+
/** Replace one class token with another. */
|
|
178
|
+
replace(previous: string, next: string): boolean;
|
|
179
|
+
/** Token at an index. */
|
|
180
|
+
item(index: number): string | null;
|
|
181
|
+
[Symbol.iterator](): Iterator<string>;
|
|
182
|
+
toString(): string;
|
|
183
|
+
}
|
|
184
|
+
/** Mutable inline style declaration. */
|
|
185
|
+
export declare class CSSStyleDeclaration {
|
|
186
|
+
#private;
|
|
187
|
+
/** Serialized declarations. */
|
|
188
|
+
get cssText(): string;
|
|
189
|
+
set cssText(value: string);
|
|
190
|
+
/** Read a CSS property. */
|
|
191
|
+
getPropertyValue(name: string): string;
|
|
192
|
+
/** Set a CSS property. */
|
|
193
|
+
setProperty(name: string, value: string | null, _priority?: string): void;
|
|
194
|
+
/** Remove and return a CSS property. */
|
|
195
|
+
removeProperty(name: string): string;
|
|
196
|
+
}
|
|
197
|
+
/** DOM element with attributes, selectors, and HTML serialization. */
|
|
198
|
+
export declare class Element extends Node {
|
|
199
|
+
readonly localName: string;
|
|
200
|
+
readonly tagName: string;
|
|
201
|
+
readonly namespaceURI: string | null;
|
|
202
|
+
readonly qualifiedName: string;
|
|
203
|
+
readonly attributes: NamedNodeMap;
|
|
204
|
+
readonly classList: DOMTokenList;
|
|
205
|
+
readonly style: CSSStyleDeclaration;
|
|
206
|
+
constructor(tagName: string, ownerDocument?: Document | null, namespaceURI?: string | null);
|
|
207
|
+
/** Element children. */
|
|
208
|
+
get children(): Element[];
|
|
209
|
+
/** First element child. */
|
|
210
|
+
get firstElementChild(): Element | null;
|
|
211
|
+
/** Last element child. */
|
|
212
|
+
get lastElementChild(): Element | null;
|
|
213
|
+
/** Previous sibling that is an element. */
|
|
214
|
+
get previousElementSibling(): Element | null;
|
|
215
|
+
/** Next sibling that is an element. */
|
|
216
|
+
get nextElementSibling(): Element | null;
|
|
217
|
+
/** Attribute-backed element id. */
|
|
218
|
+
get id(): string;
|
|
219
|
+
set id(value: string);
|
|
220
|
+
/** Attribute-backed class string. */
|
|
221
|
+
get className(): string;
|
|
222
|
+
set className(value: string);
|
|
223
|
+
/** Data attributes exposed as camel-cased properties. */
|
|
224
|
+
get dataset(): Record<string, string>;
|
|
225
|
+
/** Linkedom-compatible legacy text property (only specialized elements define a value). */
|
|
226
|
+
get text(): string | undefined;
|
|
227
|
+
/** HTML contained inside this element. */
|
|
228
|
+
get innerHTML(): string;
|
|
229
|
+
set innerHTML(value: string);
|
|
230
|
+
/** Serialized element and descendants. */
|
|
231
|
+
get outerHTML(): string;
|
|
232
|
+
set outerHTML(value: string);
|
|
233
|
+
/** Read an attribute. */
|
|
234
|
+
getAttribute(name: string): string | null;
|
|
235
|
+
/** Read an attribute object. */
|
|
236
|
+
getAttributeNode(name: string): Attr | null;
|
|
237
|
+
/** Whether an attribute exists. */
|
|
238
|
+
hasAttribute(name: string): boolean;
|
|
239
|
+
/** Set an attribute. */
|
|
240
|
+
setAttribute(name: string, value: string): void;
|
|
241
|
+
/** Set a namespaced attribute. */
|
|
242
|
+
setAttributeNS(_namespace: string | null, name: string, value: string): void;
|
|
243
|
+
/** Remove an attribute. */
|
|
244
|
+
removeAttribute(name: string): void;
|
|
245
|
+
/** Find the first descendant matching a selector. */
|
|
246
|
+
querySelector(selector: string): Element | null;
|
|
247
|
+
/** Find all descendants matching a selector. */
|
|
248
|
+
querySelectorAll(selector: string): Element[];
|
|
249
|
+
/** Whether this element matches a selector. */
|
|
250
|
+
matches(selector: string): boolean;
|
|
251
|
+
/** Find the nearest matching ancestor including this element. */
|
|
252
|
+
closest(selector: string): Element | null;
|
|
253
|
+
/** Descendant elements with a tag name. */
|
|
254
|
+
getElementsByTagName(tagName: string): Element[];
|
|
255
|
+
/** Descendant elements containing all requested class tokens. */
|
|
256
|
+
getElementsByClassName(classNames: string): Element[];
|
|
257
|
+
/**
|
|
258
|
+
* Return a zero-sized rectangle because this parser DOM has no layout.
|
|
259
|
+
* Browser-side scripts only use this method's standard shape.
|
|
260
|
+
*/
|
|
261
|
+
getBoundingClientRect(): {
|
|
262
|
+
x: number;
|
|
263
|
+
y: number;
|
|
264
|
+
bottom: number;
|
|
265
|
+
height: number;
|
|
266
|
+
left: number;
|
|
267
|
+
right: number;
|
|
268
|
+
top: number;
|
|
269
|
+
width: number;
|
|
270
|
+
};
|
|
271
|
+
/** Focus this element in its owner document. */
|
|
272
|
+
focus(): void;
|
|
273
|
+
/** Clear focus from this element. */
|
|
274
|
+
blur(): void;
|
|
275
|
+
/** Trigger a synthetic click event. */
|
|
276
|
+
click(): void;
|
|
277
|
+
cloneNode(deep?: boolean): Element;
|
|
278
|
+
}
|
|
279
|
+
/** HTML element implementation. */
|
|
280
|
+
export declare class HTMLElement extends Element {
|
|
281
|
+
value: string;
|
|
282
|
+
checked: boolean;
|
|
283
|
+
selected: boolean;
|
|
284
|
+
disabled: boolean;
|
|
285
|
+
multiple: boolean;
|
|
286
|
+
defaultValue: string;
|
|
287
|
+
defaultChecked: boolean;
|
|
288
|
+
/** Reflected title attribute. */
|
|
289
|
+
get title(): string;
|
|
290
|
+
set title(value: string);
|
|
291
|
+
/** Reflected href attribute. */
|
|
292
|
+
get href(): string;
|
|
293
|
+
set href(value: string);
|
|
294
|
+
/** Reflected input type. */
|
|
295
|
+
get type(): string;
|
|
296
|
+
set type(value: string);
|
|
297
|
+
/** Reflected name. */
|
|
298
|
+
get name(): string;
|
|
299
|
+
set name(value: string);
|
|
300
|
+
}
|
|
301
|
+
/** HTML meta element with a reflected content attribute. */
|
|
302
|
+
export declare class HTMLMetaElement extends HTMLElement {
|
|
303
|
+
/** Reflected metadata content. */
|
|
304
|
+
get content(): string;
|
|
305
|
+
set content(value: string);
|
|
306
|
+
}
|
|
307
|
+
/** SVG element marker used by React feature checks. */
|
|
308
|
+
export declare class SVGElement extends Element {
|
|
309
|
+
}
|
|
310
|
+
/** Iframe element marker used by React selection restoration. */
|
|
311
|
+
export declare class HTMLIFrameElement extends HTMLElement {
|
|
312
|
+
}
|
|
313
|
+
/** Document fragment. */
|
|
314
|
+
export declare class DocumentFragment extends Node {
|
|
315
|
+
constructor(ownerDocument?: Document | null);
|
|
316
|
+
/** Element children. */
|
|
317
|
+
get children(): Element[];
|
|
318
|
+
/** First element child. */
|
|
319
|
+
get firstElementChild(): Element | null;
|
|
320
|
+
/** Last element child. */
|
|
321
|
+
get lastElementChild(): Element | null;
|
|
322
|
+
/** First matching descendant. */
|
|
323
|
+
querySelector(selector: string): Element | null;
|
|
324
|
+
/** All matching descendants. */
|
|
325
|
+
querySelectorAll(selector: string): Element[];
|
|
326
|
+
cloneNode(deep?: boolean): DocumentFragment;
|
|
327
|
+
}
|
|
328
|
+
/** HTML template whose parsed descendants live in a document fragment. */
|
|
329
|
+
export declare class HTMLTemplateElement extends HTMLElement {
|
|
330
|
+
readonly content: DocumentFragment;
|
|
331
|
+
constructor(tagName: string, ownerDocument?: Document | null, namespaceURI?: string | null);
|
|
332
|
+
get innerHTML(): string;
|
|
333
|
+
set innerHTML(value: string);
|
|
334
|
+
get textContent(): string;
|
|
335
|
+
set textContent(value: string | null);
|
|
336
|
+
appendChild<T extends Node>(child: T): T;
|
|
337
|
+
insertBefore<T extends Node>(child: T, reference: Node | null): T;
|
|
338
|
+
replaceChild<T extends Node>(child: Node, previous: T): T;
|
|
339
|
+
removeChild<T extends Node>(child: T): T;
|
|
340
|
+
cloneNode(deep?: boolean): HTMLTemplateElement;
|
|
341
|
+
}
|
|
342
|
+
/** Minimal HTML document. */
|
|
343
|
+
export declare class Document extends Node {
|
|
344
|
+
defaultView: DOMWindow | null;
|
|
345
|
+
URL: string;
|
|
346
|
+
activeElement: Element | null;
|
|
347
|
+
constructor();
|
|
348
|
+
/** Root element of the document. */
|
|
349
|
+
get documentElement(): Element | null;
|
|
350
|
+
/** Element children. */
|
|
351
|
+
get children(): Element[];
|
|
352
|
+
/** HTML body, or a detached empty body when absent like linkedom. */
|
|
353
|
+
get body(): HTMLElement;
|
|
354
|
+
/** HTML head, or a detached empty head when absent. */
|
|
355
|
+
get head(): HTMLElement;
|
|
356
|
+
/** Document title text. */
|
|
357
|
+
get title(): string;
|
|
358
|
+
set title(value: string);
|
|
359
|
+
get textContent(): null;
|
|
360
|
+
set textContent(_value: string | null);
|
|
361
|
+
/** Create an HTML element. */
|
|
362
|
+
createElement(tagName: string, _options?: ElementCreationOptions): HTMLElement;
|
|
363
|
+
/** Create a namespaced element. */
|
|
364
|
+
createElementNS(namespace: string | null, tagName: string): Element;
|
|
365
|
+
/** Create a text node. */
|
|
366
|
+
createTextNode(data: string): Text;
|
|
367
|
+
/** Create a comment. */
|
|
368
|
+
createComment(data: string): Comment;
|
|
369
|
+
/** Create an attribute. */
|
|
370
|
+
createAttribute(name: string): Attr;
|
|
371
|
+
/** Create a document fragment. */
|
|
372
|
+
createDocumentFragment(): DocumentFragment;
|
|
373
|
+
/** Find the first element by id. */
|
|
374
|
+
getElementById(id: string): HTMLElement | null;
|
|
375
|
+
/** Find the first matching descendant. */
|
|
376
|
+
querySelector(selector: string): Element | null;
|
|
377
|
+
/** Find all matching descendants. */
|
|
378
|
+
querySelectorAll(selector: string): Element[];
|
|
379
|
+
/** Descendant elements with a tag name. */
|
|
380
|
+
getElementsByTagName(tagName: string): Element[];
|
|
381
|
+
/** Descendant elements containing all class tokens. */
|
|
382
|
+
getElementsByClassName(classNames: string): Element[];
|
|
383
|
+
/** Adopt a node into this document. */
|
|
384
|
+
adoptNode<T extends Node>(node: T): T;
|
|
385
|
+
/** Import a cloned node into this document. */
|
|
386
|
+
importNode<T extends Node>(node: T, deep?: boolean): T;
|
|
387
|
+
/** Legacy event factory used by libraries. */
|
|
388
|
+
createEvent(_kind: string): Event;
|
|
389
|
+
cloneNode(deep?: boolean): Document;
|
|
390
|
+
}
|
|
391
|
+
/** Window shape returned by parseHTML. */
|
|
392
|
+
export declare class DOMWindow extends EventTarget {
|
|
393
|
+
readonly document: Document;
|
|
394
|
+
readonly Node: typeof Node;
|
|
395
|
+
readonly Element: typeof Element;
|
|
396
|
+
readonly HTMLElement: typeof HTMLElement;
|
|
397
|
+
readonly HTMLIFrameElement: typeof HTMLIFrameElement;
|
|
398
|
+
readonly SVGElement: typeof SVGElement;
|
|
399
|
+
readonly Text: typeof Text;
|
|
400
|
+
readonly Comment: typeof Comment;
|
|
401
|
+
readonly Document: typeof Document;
|
|
402
|
+
readonly DocumentFragment: typeof DocumentFragment;
|
|
403
|
+
readonly Event: typeof Event;
|
|
404
|
+
readonly CustomEvent: typeof CustomEvent;
|
|
405
|
+
readonly navigator: {
|
|
406
|
+
userAgent: string;
|
|
407
|
+
platform: string;
|
|
408
|
+
};
|
|
409
|
+
readonly location: {
|
|
410
|
+
href: string;
|
|
411
|
+
};
|
|
412
|
+
readonly window: DOMWindow;
|
|
413
|
+
readonly self: DOMWindow;
|
|
414
|
+
readonly top: DOMWindow;
|
|
415
|
+
readonly parent: DOMWindow;
|
|
416
|
+
constructor(document: Document);
|
|
417
|
+
/** Browser-compatible computed style placeholder. */
|
|
418
|
+
getComputedStyle(element: Element): CSSStyleDeclaration;
|
|
419
|
+
/** Schedule an animation callback. */
|
|
420
|
+
requestAnimationFrame(callback: FrameRequestCallback): number;
|
|
421
|
+
/** Cancel an animation callback. */
|
|
422
|
+
cancelAnimationFrame(handle: number): void;
|
|
423
|
+
/** Empty selection object. */
|
|
424
|
+
getSelection(): {
|
|
425
|
+
rangeCount: number;
|
|
426
|
+
removeAllRanges(): void;
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
/** Serialize a DOM node as HTML. */
|
|
430
|
+
export declare function serializeNode(node: Node): string;
|
|
431
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Document, type DocumentFragment } from "./core.js";
|
|
2
|
+
/** Decode common named entities and all valid numeric character references. */
|
|
3
|
+
export declare function decodeEntities(value: string): string;
|
|
4
|
+
/** Parse markup into a document fragment. */
|
|
5
|
+
export declare function parseFragment(html: string, document: Document, contextTag?: string): DocumentFragment;
|
|
6
|
+
/** Parse markup directly into a document. */
|
|
7
|
+
export declare function parseDocument(html: string): Document;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Document, type DocumentFragment, Element } from "./core.js";
|
|
2
|
+
/** Whether an element matches a CSS selector list. */
|
|
3
|
+
export declare function matchesSelector(element: Element, selector: string): boolean;
|
|
4
|
+
/** Query descendants of a node in document order. */
|
|
5
|
+
export declare function querySelectorAllFrom(root: Document | DocumentFragment | Element, selector: string, includeRoot: boolean): Element[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Behavior-compatible reimplementation of linkedom's used surface. */
|
|
2
|
+
import { DOMWindow } from "./dom/core.js";
|
|
3
|
+
export { Attr, Comment, CSSStyleDeclaration, CustomEvent, DOMTokenList, DOMWindow, Document, DocumentFragment, Element, Event, EventTarget, HTMLElement, HTMLIFrameElement, HTMLMetaElement, HTMLTemplateElement, NamedNodeMap, Node, NodeType, SVGElement, serializeNode, Text, } from "./dom/core.js";
|
|
4
|
+
/** Parse HTML or XML-like markup into a lightweight window and document. */
|
|
5
|
+
export declare function parseHTML(html: string): DOMWindow;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export * from "./worker-host.js";
|
|
2
|
+
/**
|
|
3
|
+
* Strict shell-identifier shape. Used for dotenv keys we accept into
|
|
4
|
+
* `Bun.env` — those should be referenceable as `$NAME` from POSIX shells,
|
|
5
|
+
* so we reject anything outside `[A-Za-z_][A-Za-z0-9_]*`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidEnvName(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The only names that are genuinely unsafe to forward to a native `execve`
|
|
10
|
+
* spawn: empty, containing `=` (would corrupt the `KEY=VALUE` framing) or
|
|
11
|
+
* NUL (terminates the C string mid-entry). Windows ships standard variables
|
|
12
|
+
* whose names contain parentheses (e.g. `ProgramFiles(x86)`, `CommonProgramFiles(x86)`)
|
|
13
|
+
* — those MUST survive the scrub so downstream resolvers (Git Bash discovery
|
|
14
|
+
* in `procmgr.ts`, etc.) can still read them.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isSafeEnvName(name: string): boolean;
|
|
17
|
+
export declare function isSafeEnvValue(value: string): boolean;
|
|
18
|
+
export declare function isMacosMallocStackLoggingEnvName(name: string): boolean;
|
|
19
|
+
export declare function filterProcessEnv(env: Record<string, string | undefined>): Record<string, string>;
|
|
20
|
+
/** Filters process env for child shells without launch-cwd dotenv values. */
|
|
21
|
+
export declare function filterChildShellEnv(env: Record<string, string | undefined>, cwd?: string): Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Parses a .env file synchronously into key-value string pairs using
|
|
24
|
+
* {@link parseEnvLine} for Bun-compatible line semantics, then mirrors valid
|
|
25
|
+
* `OMP_` variables to their `PI_` aliases.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseEnvFile(filePath: string): Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Intentional re-export of Bun.env.
|
|
30
|
+
*
|
|
31
|
+
* All users should import this env module (import { $env } from "@linxiraos/pi-utils")
|
|
32
|
+
* before using environment variables. This ensures that .env files have been loaded and
|
|
33
|
+
* overrides (project, home) have been applied, so $env always reflects the correct values.
|
|
34
|
+
*/
|
|
35
|
+
export declare const $env: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the first environment variable value from the given keys.
|
|
38
|
+
* @param keys - The keys to resolve.
|
|
39
|
+
* @returns The first environment variable value, or undefined if no value is found.
|
|
40
|
+
*/
|
|
41
|
+
export declare function $pickenv(...keys: string[]): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Read an environment variable by its EXACT, case-sensitive name.
|
|
44
|
+
*
|
|
45
|
+
* `process.env` / `Bun.env` lookups are case-insensitive on Windows (Node backs
|
|
46
|
+
* them with `uv_os_getenv`, Bun with a `CaseInsensitiveASCIIStringArrayHashMap`),
|
|
47
|
+
* so a lowercase literal like `public` silently resolves to a differently-cased
|
|
48
|
+
* system variable — Windows ships `PUBLIC=C:\Users\Public`. Enumerated keys are
|
|
49
|
+
* the only signal that preserves the real casing, so this trusts the lookup only
|
|
50
|
+
* when a key with identical casing is actually present. On POSIX (case-sensitive
|
|
51
|
+
* env) it is equivalent to a direct lookup.
|
|
52
|
+
*
|
|
53
|
+
* Use this instead of `process.env[name] ?? literal` wherever `name` may be a
|
|
54
|
+
* user-supplied literal (e.g. a stored API key) rather than a genuine env-var
|
|
55
|
+
* reference — otherwise the literal gets hijacked by a same-named system var.
|
|
56
|
+
*
|
|
57
|
+
* @param name - Environment variable name to look up.
|
|
58
|
+
* @param env - Environment source; defaults to `process.env`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function $envExact(name: string, env?: Record<string, string | undefined>): string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Parses a positive decimal integer from `$env[name]`.
|
|
63
|
+
* Empty, invalid, NaN, zero, or negative values return `defaultValue`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function $envpos(name: string, defaultValue: number): number;
|
|
66
|
+
/** True when the process is an explicitly marked test child or Bun is running a test entrypoint. */
|
|
67
|
+
export declare function isBunTestRuntime(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* True when real-terminal side effects must be suppressed: stdout escape/frame
|
|
70
|
+
* writes, stdin raw-mode + resume, CSI/OSC capability probes, SIGWINCH, window
|
|
71
|
+
* title changes, and emergency restore. Defaults to {@link isBunTestRuntime} so
|
|
72
|
+
* `bun test` launched inside a real TTY never paints the TUI, leaks probe
|
|
73
|
+
* queries, or hijacks the developer's stdin; production runtimes stay
|
|
74
|
+
* interactive.
|
|
75
|
+
*
|
|
76
|
+
* Terminal-contract tests that must exercise the real I/O path opt out with
|
|
77
|
+
* `setTerminalHeadless(false)` and restore it afterwards.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isTerminalHeadless(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Override the {@link isTerminalHeadless} default and return the previous value
|
|
82
|
+
* so callers can restore exact prior state (`const prev = setTerminalHeadless(false); … setTerminalHeadless(prev);`).
|
|
83
|
+
*/
|
|
84
|
+
export declare function setTerminalHeadless(headless: boolean): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* True when this process runs an interactive coding-agent host — the only
|
|
87
|
+
* context where the operator can browse the Agent Hub and focus a live
|
|
88
|
+
* subagent's session (`SessionFocusController`), so a subagent's session title
|
|
89
|
+
* can become operator-visible. Off by default (print/RPC/ACP/eval/SDK/`bun
|
|
90
|
+
* test` never render a focusable session tree); the interactive entrypoint
|
|
91
|
+
* flips it on with {@link setInteractiveHost}.
|
|
92
|
+
*/
|
|
93
|
+
export declare function isInteractiveHost(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Set the interactive-host flag and return the previous value so callers can
|
|
96
|
+
* restore exact prior state. See {@link isInteractiveHost}.
|
|
97
|
+
*/
|
|
98
|
+
export declare function setInteractiveHost(interactive: boolean): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* SQLite `busy_timeout` for the session-critical databases (agent.db,
|
|
101
|
+
* history.db, stats.db).
|
|
102
|
+
*
|
|
103
|
+
* Interactive hosts tolerate a longer synchronous wait on lock contention
|
|
104
|
+
* (SQLITE_BUSY during WAL recovery/checkpoint — see oh-my-pi#2421): the
|
|
105
|
+
* operator sees a brief freeze and the statement eventually completes.
|
|
106
|
+
* Headless hosts (print/RPC/ACP/eval/SDK) run a protocol on the same thread —
|
|
107
|
+
* a multi-second synchronous busy-wait freezes their event loop and stalls
|
|
108
|
+
* every in-flight frame with no liveness signal, so they use a short timeout
|
|
109
|
+
* and rely on the existing asynchronous open/retry paths to recover from
|
|
110
|
+
* contention instead of blocking.
|
|
111
|
+
*/
|
|
112
|
+
export declare function getDbBusyTimeoutMs(): number;
|
|
113
|
+
/**
|
|
114
|
+
* True when this code is running inside a `bun build --compile` standalone
|
|
115
|
+
* binary. Detects via the embedded virtual-filesystem path markers
|
|
116
|
+
* (`$bunfs`, `~BUN`, or its URL-encoded form `%7EBUN`) in `import.meta.url`,
|
|
117
|
+
* which Bun rewrites for every module bundled into the executable. The
|
|
118
|
+
* `PI_COMPILED` env var (set by the build script's `--define`) is checked
|
|
119
|
+
* first for cheap fast-path detection.
|
|
120
|
+
*/
|
|
121
|
+
export declare function isCompiledBinary(): boolean;
|
|
122
|
+
/** Parse a boolean-ish env value ("1", "yes", "on", …); `def` when unset/empty. */
|
|
123
|
+
export declare function parseFlag(value: string | undefined, def?: boolean): boolean;
|
|
124
|
+
export declare function $flag(name: string, def?: boolean): boolean;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-suggested retry delay extraction. Merges the patterns historically used
|
|
3
|
+
* by the OpenAI Codex and Google Gemini retry helpers.
|
|
4
|
+
*
|
|
5
|
+
* Header sources (checked in order):
|
|
6
|
+
* - `retry-after-ms` (milliseconds)
|
|
7
|
+
* - `Retry-After` (numeric seconds, or HTTP date)
|
|
8
|
+
* - `x-ratelimit-reset-ms` (delta ms, or Unix epoch ms/s for large values)
|
|
9
|
+
* - `x-ratelimit-reset` (Unix epoch seconds)
|
|
10
|
+
* - `x-ratelimit-reset-after` (seconds)
|
|
11
|
+
*
|
|
12
|
+
* Body patterns:
|
|
13
|
+
* - `Your quota will reset after 18h31m10s` / `10m15s` / `39s`
|
|
14
|
+
* - `Please retry in 250ms` / `Please retry in 12s`
|
|
15
|
+
* - `"retryDelay": "34.074824224s"` (JSON error detail field)
|
|
16
|
+
* - `try again in 250ms` / `try again in 12s` / `try again in 5 min` / `try again in ~158 min`
|
|
17
|
+
*
|
|
18
|
+
* Returns `undefined` if no signal is found.
|
|
19
|
+
*/
|
|
20
|
+
export declare function extractRetryHint(source: Response | Headers | null | undefined, body?: string): number | undefined;
|
|
21
|
+
export interface FetchWithRetryOptions extends RequestInit {
|
|
22
|
+
/** Total fetch attempts (initial + retries). Default `5`. */
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Per-delay cap. Server-provided `Retry-After` hints exceeding this return
|
|
26
|
+
* the current response immediately — caller deals with the `!response.ok`.
|
|
27
|
+
* Default `60_000`.
|
|
28
|
+
*/
|
|
29
|
+
maxDelayMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Fallback delay schedule when no server hint is present. Number, array
|
|
32
|
+
* (indexed by attempt, clamped to last), or function. Default exponential
|
|
33
|
+
* `500ms * 2 ** attempt` capped at `maxDelayMs`.
|
|
34
|
+
*/
|
|
35
|
+
defaultDelayMs?: number | readonly number[] | ((attempt: number) => number);
|
|
36
|
+
/**
|
|
37
|
+
* Optional per-attempt overlay merged into the base `RequestInit` each try.
|
|
38
|
+
* Headers from the overlay shallow-merge over the base. Useful for auth
|
|
39
|
+
* token refresh or user-agent rotation.
|
|
40
|
+
*/
|
|
41
|
+
prepareInit?: (attempt: number) => RequestInit | Promise<RequestInit>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional `fetch` implementation override. Defaults to `globalThis.fetch`.
|
|
44
|
+
* Useful for routing requests through a proxy, instrumented transport, or
|
|
45
|
+
* mock during tests.
|
|
46
|
+
*/
|
|
47
|
+
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional retry gate for HTTP responses whose status is retryable. Receives a
|
|
50
|
+
* cloned body string so callers can fail fast on deterministic provider
|
|
51
|
+
* failures that happen to use a 5xx status.
|
|
52
|
+
*/
|
|
53
|
+
shouldRetryResponse?: (response: Response, bodyText: string, attempt: number) => boolean | Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Bun extension forwarded verbatim to the underlying `fetch` call. `false`
|
|
56
|
+
* disables Bun's native ~300s pre-response timeout (callers that own a
|
|
57
|
+
* configurable first-event/idle watchdog or an external `AbortSignal`
|
|
58
|
+
* supply this so the runtime ceiling cannot pre-empt them); a positive
|
|
59
|
+
* number sets a custom ceiling in ms. Bare browser/Node fetch ignores it.
|
|
60
|
+
*/
|
|
61
|
+
timeout?: number | false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fetch with bounded retries and sensible defaults. Retries on any
|
|
65
|
+
* `isRetryableStatus` (5xx, 408, 429) and on transient network errors. Server
|
|
66
|
+
* `Retry-After`/quota hints are honoured up to `maxDelayMs`; a hint that exceeds
|
|
67
|
+
* the cap returns the current response so the caller can fail fast. Aborts on
|
|
68
|
+
* `init.signal` propagate as `"Request was aborted"`.
|
|
69
|
+
*
|
|
70
|
+
* The caller is responsible for inspecting `!response.ok` once the call returns.
|
|
71
|
+
*/
|
|
72
|
+
export declare function fetchWithRetry(url: string | URL | ((attempt: number) => string | URL), options?: FetchWithRetryOptions): Promise<Response>;
|
|
73
|
+
/**
|
|
74
|
+
* Inspect an arbitrary error value (or its `cause` chain, up to depth 2) for an
|
|
75
|
+
* HTTP status code. Reads `status`, `statusCode`, and `response.status` fields,
|
|
76
|
+
* coerces string values, and falls back to scanning the error message for
|
|
77
|
+
* common patterns like `Error: 401`, `error (429)`, or `HTTP 503`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function extractHttpStatusFromError(error: unknown): number | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* `true` if the given HTTP status code is one we treat as transient: 408
|
|
82
|
+
* (Request Timeout), 429 (Too Many Requests), or any 5xx (server error).
|
|
83
|
+
*/
|
|
84
|
+
export declare function isRetryableStatus(status: number): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* `true` if the message describes an unexpected socket closure — Bun and some
|
|
87
|
+
* proxies surface these for any HTTP/2 stream reset.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isUnexpectedSocketCloseMessage(message: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Identify errors that should be retried: aborts/timeouts in the error name or
|
|
92
|
+
* message, retryable HTTP statuses (see `isRetryableStatus`), unexpected socket
|
|
93
|
+
* closes, and the standard transient phrases. 4xx statuses other than 408/429
|
|
94
|
+
* and validation-shaped messages short-circuit to `false`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function isRetryableError(error: unknown): boolean;
|