@oh-my-pi/pi-utils 18.1.8 → 18.1.10

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/README.md CHANGED
@@ -4,22 +4,22 @@ Shared utilities for [oh-my-pi](https://github.com/can1357/oh-my-pi) packages. Z
4
4
 
5
5
  ## Notable modules
6
6
 
7
- | Module | Purpose |
8
- | --- | --- |
9
- | `logger` | Centralized logger writing to `~/.omp/logs/` with rotation (TUI-safe — never stdout) |
10
- | `prompt` | Handlebars-based prompt templating and formatting helpers |
11
- | `dirs` | Path helpers for omp config directories (`~/.omp`, XDG-aware on Linux) |
12
- | `stream` | `readStream` / `readLines` helpers over `ReadableStream` |
13
- | `ptree` / `procmgr` | Process trees, `ChildProcess` wrapper, process lifecycle management |
14
- | `postmortem` | Cleanup callbacks on exit, signals, and fatal exceptions |
15
- | `which` | `$which()` binary lookup with caching |
16
- | `fetch-retry` | `fetch` with retry/backoff policies |
17
- | `fs-error` | Errno guards (`isEnoent` and friends) |
18
- | `env` / `worker-host` | Environment plumbing and side-effect-free worker-host entry contract (`workerHostEntry`) |
19
- | `abortable` / `async` | AbortSignal-aware stream/promise helpers |
20
- | `math-delimiters` | LaTeX span/block delimiter grammar (offsets only) shared by the TUI and collab-web renderers |
21
- | `peek-file` | Read the first N bytes of a file with pooled buffers |
22
- | `frontmatter`, `glob`, `mime`, `temp`, `format`, `color`, `snowflake`, `tab-spacing`, `path-tree`, `sanitize-text` | Smaller single-purpose helpers |
7
+ | Module | Purpose |
8
+ | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------- |
9
+ | `logger` | Centralized logger writing to `~/.omp/logs/` with rotation (TUI-safe — never stdout) |
10
+ | `prompt` | Handlebars-based prompt templating and formatting helpers |
11
+ | `dirs` | Path helpers for omp config directories (`~/.omp`, XDG-aware on Linux) |
12
+ | `stream` | `readStream` / `readLines` helpers over `ReadableStream` |
13
+ | `ptree` / `procmgr` | Process trees, `ChildProcess` wrapper, process lifecycle management |
14
+ | `postmortem` | Cleanup callbacks on exit, signals, and fatal exceptions |
15
+ | `which` | `$which()` binary lookup with caching |
16
+ | `fetch-retry` | `fetch` with retry/backoff policies |
17
+ | `fs-error` | Errno guards (`isEnoent` and friends) |
18
+ | `env` / `worker-host` | Environment plumbing and side-effect-free worker-host entry contract (`workerHostEntry`) |
19
+ | `abortable` / `async` | AbortSignal-aware stream/promise helpers |
20
+ | `math-delimiters` | LaTeX span/block delimiter grammar (offsets only) shared by the TUI and collab-web renderers |
21
+ | `peek-file` | Read the first N bytes of a file with pooled buffers |
22
+ | `frontmatter`, `glob`, `mime`, `temp`, `format`, `color`, `snowflake`, `tab-spacing`, `path-tree`, `sanitize-text` | Smaller single-purpose helpers |
23
23
 
24
24
  Import from the root barrel or per-module subpaths (`@oh-my-pi/pi-utils/<module>`).
25
25
 
@@ -16,8 +16,30 @@ export declare class ExtraCaError extends Error {
16
16
  cause?: unknown;
17
17
  });
18
18
  }
19
+ /**
20
+ * Returns the PEM bytes referenced by `NODE_EXTRA_CA_CERTS`, or `undefined`
21
+ * when the env var is unset/empty.
22
+ *
23
+ * Accepts the same shapes Node accepts plus an inline-PEM escape hatch:
24
+ * - Inline PEM (`-----BEGIN CERTIFICATE-----...`). Literal `\n` escapes in
25
+ * the env value are expanded so callers can ship single-line PEMs through
26
+ * shell exports.
27
+ * - File path. Anything that does not contain a PEM header is treated as a
28
+ * path, matching Node's "extensionless filename is still a path" contract.
29
+ * `ENOENT` becomes {@link ExtraCaError}; other I/O errors bubble.
30
+ */
31
+ export declare function resolveExtraCa(): string | undefined;
19
32
  /** Test seam: drop the cached PEM so a follow-up call re-reads the env. */
20
33
  export declare function __resetExtraCaCache(): void;
34
+ /**
35
+ * Merge `extraCa` into `init.tls.ca`. When the caller has not supplied a CA
36
+ * list, the system root store is included alongside the extra bundle —
37
+ * Bun's `tls.ca` replaces the default trust store, so omitting roots would
38
+ * break every public host. When the caller already curated a list (e.g.
39
+ * Anthropic Foundry's mTLS options, which already seed
40
+ * `tls.rootCertificates`), only the extra CA is appended.
41
+ */
42
+ export declare function withExtraCaInit(init: RequestInit | undefined, extraCa: string): RequestInit;
21
43
  /**
22
44
  * Wrap `fetchImpl` so every call honours `NODE_EXTRA_CA_CERTS`. Idempotent:
23
45
  * a fetch already wrapped is returned unchanged so repeated composition
@@ -26,12 +48,3 @@ export declare function __resetExtraCaCache(): void;
26
48
  * default deployments pay nothing.
27
49
  */
28
50
  export declare function wrapFetchForExtraCa(fetchImpl: FetchImpl): FetchImpl;
29
- /**
30
- * Convenience for options-bag composition (e.g. the stream-entry path in
31
- * `@oh-my-pi/pi-ai`'s `stream.ts`, which mirrors `withRequestDebugFetch` so
32
- * the proxy/debug/extra-CA wrappers compose uniformly). No-op when the env
33
- * var is unset.
34
- */
35
- export declare function withExtraCaFetch<T extends {
36
- fetch?: FetchImpl;
37
- } | undefined>(options: T): T;
package/package.json CHANGED
@@ -1,44 +1,24 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "@oh-my-pi/pi-utils",
4
- "version": "18.1.8",
3
+ "version": "18.1.10",
5
4
  "description": "Shared utilities for pi packages",
5
+ "keywords": [
6
+ "cli",
7
+ "logging",
8
+ "streams",
9
+ "utilities"
10
+ ],
6
11
  "homepage": "https://omp.sh",
7
- "author": "Stencil Labs, Inc.",
12
+ "bugs": {
13
+ "url": "https://github.com/can1357/oh-my-pi/issues"
14
+ },
8
15
  "license": "MIT",
16
+ "author": "Stencil Labs, Inc.",
9
17
  "repository": {
10
18
  "type": "git",
11
19
  "url": "git+https://github.com/can1357/oh-my-pi.git",
12
20
  "directory": "packages/utils"
13
21
  },
14
- "bugs": {
15
- "url": "https://github.com/can1357/oh-my-pi/issues"
16
- },
17
- "keywords": [
18
- "utilities",
19
- "cli",
20
- "logging",
21
- "streams"
22
- ],
23
- "main": "./src/index.ts",
24
- "types": "./dist/types/index.d.ts",
25
- "scripts": {
26
- "check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
27
- "check:types": "tsgo -p tsconfig.json --noEmit",
28
- "lint": "oxlint .",
29
- "test": "bun test --parallel",
30
- "fix": "oxlint --fix --fix-suggestions . && bun run fmt",
31
- "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
32
- },
33
- "dependencies": {
34
- "@oh-my-pi/pi-natives": "18.1.8"
35
- },
36
- "devDependencies": {
37
- "@types/bun": "^1.3.14"
38
- },
39
- "engines": {
40
- "bun": ">=1.3.14"
41
- },
42
22
  "files": [
43
23
  "src",
44
24
  "README.md",
@@ -47,6 +27,9 @@
47
27
  "THIRD-PARTY-NOTICES.txt",
48
28
  "dist/types"
49
29
  ],
30
+ "type": "module",
31
+ "main": "./src/index.ts",
32
+ "types": "./dist/types/index.d.ts",
50
33
  "exports": {
51
34
  ".": {
52
35
  "types": "./dist/types/index.d.ts",
@@ -61,5 +44,22 @@
61
44
  "import": "./src/*.ts"
62
45
  },
63
46
  "./*.js": "./src/*.ts"
47
+ },
48
+ "scripts": {
49
+ "check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
50
+ "check:types": "tsgo -p tsconfig.json --noEmit",
51
+ "lint": "oxlint .",
52
+ "test": "bun test --parallel",
53
+ "fix": "oxlint --fix --fix-suggestions . && bun run fmt",
54
+ "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
55
+ },
56
+ "dependencies": {
57
+ "@oh-my-pi/pi-natives": "18.1.10"
58
+ },
59
+ "devDependencies": {
60
+ "@types/bun": "^1.3.14"
61
+ },
62
+ "engines": {
63
+ "bun": ">=1.3.14"
64
64
  }
65
65
  }
package/src/tls-fetch.ts CHANGED
@@ -76,7 +76,7 @@ let cacheValue: string | undefined;
76
76
  * path, matching Node's "extensionless filename is still a path" contract.
77
77
  * `ENOENT` becomes {@link ExtraCaError}; other I/O errors bubble.
78
78
  */
79
- function resolveExtraCa(): string | undefined {
79
+ export function resolveExtraCa(): string | undefined {
80
80
  const raw = $env.NODE_EXTRA_CA_CERTS?.trim();
81
81
  if (!raw) return undefined;
82
82
 
@@ -122,7 +122,7 @@ export function __resetExtraCaCache(): void {
122
122
  * Anthropic Foundry's mTLS options, which already seed
123
123
  * `tls.rootCertificates`), only the extra CA is appended.
124
124
  */
125
- function withExtraCaInit(init: RequestInit | undefined, extraCa: string): RequestInit {
125
+ export function withExtraCaInit(init: RequestInit | undefined, extraCa: string): RequestInit {
126
126
  const existingTls = (init as BunTlsRequestInit | undefined)?.tls;
127
127
  const existingCa = existingTls?.ca;
128
128
  let mergedCa: string[];
@@ -162,17 +162,3 @@ export function wrapFetchForExtraCa(fetchImpl: FetchImpl): FetchImpl {
162
162
  );
163
163
  return wrapped;
164
164
  }
165
-
166
- /**
167
- * Convenience for options-bag composition (e.g. the stream-entry path in
168
- * `@oh-my-pi/pi-ai`'s `stream.ts`, which mirrors `withRequestDebugFetch` so
169
- * the proxy/debug/extra-CA wrappers compose uniformly). No-op when the env
170
- * var is unset.
171
- */
172
- export function withExtraCaFetch<T extends { fetch?: FetchImpl } | undefined>(options: T): T {
173
- if (!$env.NODE_EXTRA_CA_CERTS?.trim()) return options;
174
- const fetchImpl = options?.fetch ?? (globalThis.fetch as FetchImpl);
175
- const wrapped = wrapFetchForExtraCa(fetchImpl);
176
- if (wrapped === fetchImpl && options?.fetch !== undefined) return options;
177
- return { ...options, fetch: wrapped } as T;
178
- }