@openclaw/proxyline 0.2.0 → 0.3.1

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/src/shared.ts ADDED
@@ -0,0 +1,42 @@
1
+ import fs from "node:fs";
2
+
3
+ export type ProxylineTlsOptions = Readonly<{
4
+ ca?: string;
5
+ caFile?: string;
6
+ }>;
7
+
8
+ export class ProxylineError extends Error {
9
+ public readonly code: string;
10
+
11
+ public constructor(code: string, message: string) {
12
+ super(message);
13
+ this.name = "ProxylineError";
14
+ this.code = code;
15
+ }
16
+ }
17
+
18
+ export function resolveProxyTlsCa(options: ProxylineTlsOptions | undefined): string | undefined {
19
+ if (!options) {
20
+ return undefined;
21
+ }
22
+ if (options.ca !== undefined) {
23
+ return options.ca;
24
+ }
25
+ if (options.caFile !== undefined) {
26
+ return fs.readFileSync(options.caFile, "utf8");
27
+ }
28
+ return undefined;
29
+ }
30
+
31
+ export function formatUrl(value: string | URL): string {
32
+ return value instanceof URL ? value.href : new URL(value).href;
33
+ }
34
+
35
+ export function redactProxyUrl(value: string | URL): string {
36
+ const url = value instanceof URL ? new URL(value.href) : new URL(value);
37
+ url.username = "";
38
+ url.password = "";
39
+ url.search = "";
40
+ url.hash = "";
41
+ return url.href;
42
+ }
package/src/types.ts ADDED
@@ -0,0 +1,98 @@
1
+ import type { Agent as HttpAgent } from "node:http";
2
+ import type { Dispatcher } from "undici";
3
+ import type { ProxylineTlsOptions } from "./shared.js";
4
+
5
+ export type ProxylineMode = "managed" | "ambient";
6
+
7
+ export type ProxylineSurface =
8
+ | "node-http"
9
+ | "node-https"
10
+ | "undici"
11
+ | "websocket"
12
+ | "connect"
13
+ | "unknown";
14
+
15
+ export type ProxylineOptions = Readonly<{
16
+ mode: ProxylineMode;
17
+ proxyUrl?: string | URL;
18
+ proxyTls?: ProxylineTlsOptions;
19
+ bypassPolicy?: ProxylineBypassPolicy;
20
+ ifActive?: "error" | "reuse-compatible" | "replace";
21
+ onEvent?: (event: ProxylineEvent) => void;
22
+ undici?: ProxylineUndiciOptions;
23
+ }>;
24
+
25
+ export type ProxylineDecision = Readonly<{
26
+ kind: "proxied" | "direct" | "blocked";
27
+ reason: string;
28
+ surface: ProxylineSurface;
29
+ url: string;
30
+ proxyUrl?: string;
31
+ }>;
32
+
33
+ export type ProxylineBypassRequest = Readonly<{
34
+ surface: ProxylineSurface;
35
+ url: string;
36
+ }>;
37
+
38
+ export type ProxylineBypassPolicy = (request: ProxylineBypassRequest) => boolean;
39
+
40
+ export type ProxylineEvent =
41
+ | Readonly<{
42
+ type: "runtime.installed";
43
+ mode: ProxylineMode;
44
+ active: boolean;
45
+ proxyUrl?: string;
46
+ }>
47
+ | Readonly<{
48
+ type: "runtime.stopped";
49
+ mode: ProxylineMode;
50
+ }>
51
+ | Readonly<{
52
+ type: "decision";
53
+ decision: ProxylineDecision;
54
+ }>
55
+ | Readonly<{
56
+ type: "warning";
57
+ code: string;
58
+ message: string;
59
+ }>;
60
+
61
+ export type ExplainOptions = Readonly<{
62
+ surface?: ProxylineSurface;
63
+ }>;
64
+
65
+ export type ProxylineBypassRegistration = Readonly<{
66
+ surface?: ProxylineSurface;
67
+ url: string | URL;
68
+ }>;
69
+
70
+ export type ProxylineUndiciOptions = Readonly<{
71
+ allowH2?: boolean;
72
+ bodyTimeout?: number;
73
+ headersTimeout?: number;
74
+ connect?: Readonly<{
75
+ autoSelectFamily?: boolean;
76
+ autoSelectFamilyAttemptTimeout?: number;
77
+ }>;
78
+ }>;
79
+
80
+ export type ProxylineHandle = Readonly<{
81
+ mode: ProxylineMode;
82
+ active: boolean;
83
+ proxyUrl?: string;
84
+ createNodeAgent: () => HttpAgent;
85
+ createUndiciDispatcher: () => Dispatcher;
86
+ createWebSocketAgent: () => HttpAgent;
87
+ explain: (url: string | URL, options?: ExplainOptions) => ProxylineDecision;
88
+ registerBypass: (registration: ProxylineBypassRegistration) => () => void;
89
+ stop: () => void;
90
+ withBypass: <T>(registration: ProxylineBypassRegistration, run: () => T) => T;
91
+ }>;
92
+
93
+ export type ProxyResolver = Readonly<{
94
+ active: boolean;
95
+ describeProxy: () => string | undefined;
96
+ explain: (url: string | URL, surface: ProxylineSurface) => ProxylineDecision;
97
+ getProxyForUrl: (url: string, surface?: ProxylineSurface) => string;
98
+ }>;
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "rootDir": "src"
6
+ },
7
+ "include": ["src/**/*.ts"]
8
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationMap": true,
5
+ "esModuleInterop": true,
6
+ "exactOptionalPropertyTypes": true,
7
+ "lib": ["ES2022"],
8
+ "module": "NodeNext",
9
+ "moduleResolution": "NodeNext",
10
+ "noEmit": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "noImplicitOverride": true,
13
+ "noImplicitReturns": true,
14
+ "noUncheckedIndexedAccess": true,
15
+ "outDir": "dist",
16
+ "rootDir": ".",
17
+ "skipLibCheck": true,
18
+ "strict": true,
19
+ "target": "ES2022"
20
+ },
21
+ "include": ["src/**/*.ts", "test/**/*.ts"]
22
+ }