proxylang 0.12.0 → 0.13.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/dist/index.d.ts CHANGED
@@ -1,12 +1,18 @@
1
1
  import { z } from "zod";
2
- //#region src/types.d.ts
3
- export type Network = "tcp" | "udp";
4
- export type NamedRuleSet = {
5
- readonly type: "ruleSet";
6
- readonly id: string;
7
- readonly when: Match;
2
+ //#region src/model/identity.d.ts
3
+ type Origin = {
4
+ readonly file: string;
5
+ readonly line: number;
6
+ readonly column: number;
7
+ };
8
+ declare const sdkIdentity: unique symbol;
9
+ type SDK<K extends string> = {
10
+ readonly [sdkIdentity]: K;
8
11
  };
9
- export type NativeRuleSet = {
12
+ //#endregion
13
+ //#region src/model/types.d.ts
14
+ type Network = "tcp" | "udp";
15
+ type NativeRuleSet = {
10
16
  readonly type: "nativeRuleSet";
11
17
  readonly id: string;
12
18
  readonly url: string;
@@ -27,7 +33,7 @@ export type NativeRuleSet = {
27
33
  readonly behavior: "domain" | "ipcidr" | "classical";
28
34
  readonly intervalSeconds: number;
29
35
  });
30
- export type Match = NamedRuleSet | NativeRuleSet | {
36
+ type Match = NativeRuleSet | {
31
37
  readonly type: "domain" | "domainSuffix";
32
38
  readonly includeSniffed?: boolean;
33
39
  readonly value: string;
@@ -52,85 +58,49 @@ export type Match = NamedRuleSet | NativeRuleSet | {
52
58
  readonly type: "not";
53
59
  readonly condition: Match;
54
60
  };
55
- export type Action = {
56
- readonly type: "direct" | "reject";
57
- } | {
58
- readonly type: "route";
59
- readonly to: string;
60
- };
61
- export type Slot<S extends string = string> = {
62
- readonly type: "slot";
63
- readonly name: S;
64
- };
65
- export type Rule<S extends string = string> = {
66
- readonly type: "rule";
67
- readonly id: string;
68
- readonly when: Match;
69
- readonly then: Action | Slot<S>;
70
- };
71
- export type Block<S extends string = string> = {
72
- readonly type: "block";
73
- readonly id: string;
74
- readonly rules: readonly Entry<S>[];
75
- readonly when?: Match;
76
- };
77
- export type Policy<S extends string = string> = {
78
- readonly type: "policy";
79
- readonly id: string;
80
- readonly exits: readonly S[];
81
- readonly rules: readonly Entry[];
82
- };
83
- export type Use<S extends string = string> = {
84
- readonly type: "use";
85
- readonly id: string;
86
- readonly policy: Policy;
87
- readonly bindings: Readonly<Record<string, Action | Slot<S>>>;
88
- };
89
- export type Entry<S extends string = string> = Rule<S> | Block<S> | Use<S>;
90
- export type Secret = {
61
+ type Secret = {
91
62
  readonly type: "env";
92
63
  readonly name: string;
93
64
  };
94
- export type ProxyBase = {
65
+ type ProxyBase = {
95
66
  readonly id: string;
96
67
  readonly server: string;
97
68
  readonly port: number;
98
69
  readonly via?: string;
99
70
  readonly tcpFastOpen?: boolean;
100
- readonly label?: string;
101
71
  };
102
- export type ProxyTLS = {
72
+ type ProxyTLS = {
103
73
  readonly serverName: string;
104
74
  readonly alpn?: readonly string[];
105
75
  readonly skipCertVerify?: boolean;
106
76
  };
107
- export type SurgeProxyOptions = {
77
+ type SurgeProxyOptions = {
108
78
  readonly udpRelay?: boolean;
109
79
  readonly blockQuic?: "auto" | "on" | "off";
110
80
  };
111
81
  type SurgeAutomaticUdpOptions = Omit<SurgeProxyOptions, "udpRelay"> & {
112
82
  readonly udpRelay?: true;
113
83
  };
114
- export type WebSocketTransport = {
84
+ type WebSocketTransport = {
115
85
  readonly type: "ws";
116
86
  readonly path: string;
117
87
  readonly host?: string;
118
88
  };
119
- export type TrojanNode = ProxyBase & {
89
+ type TrojanNode$1 = ProxyBase & {
120
90
  readonly type: "trojan";
121
91
  readonly password: Secret;
122
92
  readonly serverName?: string;
123
93
  readonly skipCertVerify?: boolean;
124
94
  readonly surge?: SurgeAutomaticUdpOptions;
125
95
  };
126
- export type AnyTLSNode = ProxyBase & {
96
+ type AnyTLSNode$1 = ProxyBase & {
127
97
  readonly type: "anytls";
128
98
  readonly password: Secret;
129
99
  readonly serverName?: string;
130
100
  readonly skipCertVerify?: boolean;
131
101
  readonly surge?: SurgeAutomaticUdpOptions;
132
102
  };
133
- export type Hysteria2Node = Omit<ProxyBase, "tcpFastOpen"> & {
103
+ type Hysteria2Node$1 = Omit<ProxyBase, "tcpFastOpen"> & {
134
104
  readonly type: "hysteria2";
135
105
  readonly tcpFastOpen?: never;
136
106
  readonly password: Secret;
@@ -139,26 +109,26 @@ export type Hysteria2Node = Omit<ProxyBase, "tcpFastOpen"> & {
139
109
  readonly portHopping?: string;
140
110
  readonly portHoppingInterval?: number;
141
111
  };
142
- export type HttpNode = ProxyBase & {
112
+ type HttpNode$1 = ProxyBase & {
143
113
  readonly type: "http";
144
114
  readonly serverName?: never;
145
115
  readonly password: Secret;
146
116
  readonly username?: Secret;
147
117
  };
148
- export type ShadowsocksNode = ProxyBase & {
118
+ type ShadowsocksNode$1 = ProxyBase & {
149
119
  readonly type: "shadowsocks";
150
120
  readonly method: "aes-128-gcm" | "aes-256-gcm" | "chacha20-ietf-poly1305";
151
121
  readonly password: Secret;
152
122
  readonly surge?: SurgeProxyOptions;
153
123
  };
154
- export type VMessNode = ProxyBase & {
124
+ type VMessNode$1 = ProxyBase & {
155
125
  readonly type: "vmess";
156
126
  readonly uuid: Secret;
157
127
  readonly tls?: ProxyTLS;
158
128
  readonly transport?: WebSocketTransport;
159
129
  readonly surge?: Pick<SurgeProxyOptions, "blockQuic">;
160
130
  };
161
- export type VLESSNode = ProxyBase & {
131
+ type VLESSNode$1 = ProxyBase & {
162
132
  readonly type: "vless";
163
133
  readonly uuid: Secret;
164
134
  readonly tls?: ProxyTLS;
@@ -171,8 +141,8 @@ export type VLESSNode = ProxyBase & {
171
141
  };
172
142
  readonly utlsFingerprint?: "chrome";
173
143
  };
174
- export type ProxyNode = TrojanNode | AnyTLSNode | Hysteria2Node | HttpNode | ShadowsocksNode | VMessNode | VLESSNode;
175
- export type TailscaleEndpoint = {
144
+ type ProxyNode$1 = TrojanNode$1 | AnyTLSNode$1 | Hysteria2Node$1 | HttpNode$1 | ShadowsocksNode$1 | VMessNode$1 | VLESSNode$1;
145
+ type TailscaleEndpoint = {
176
146
  readonly type: "sing-box-tailscale";
177
147
  readonly id: string;
178
148
  readonly hostname: string;
@@ -183,77 +153,23 @@ export type TailscaleEndpoint = {
183
153
  readonly exitNode?: string;
184
154
  readonly exitNodeAllowLanAccess?: boolean;
185
155
  };
186
- export type GroupAlgorithm = {
187
- readonly type: "select";
188
- } | {
189
- readonly type: "surge-smart";
190
- } | {
191
- readonly type: "urltest";
192
- readonly url: string;
193
- readonly intervalSeconds?: number;
194
- readonly toleranceMs?: number;
195
- };
196
- export type PortableAlgorithm = {
156
+ type GroupAlgorithm = {
197
157
  readonly type: "auto";
198
- } | Extract<GroupAlgorithm, {
199
- readonly type: "select" | "urltest";
200
- }>;
201
- export type StrategyImplementations = {
202
- readonly surge?: GroupAlgorithm;
203
- readonly "sing-box"?: GroupAlgorithm;
204
- readonly mihomo?: GroupAlgorithm;
205
- readonly stash?: GroupAlgorithm;
206
- };
207
- export type StrategyDefinition = {
208
- readonly id: string;
209
- readonly members: readonly string[];
210
- } & ({
211
- readonly algorithm: PortableAlgorithm;
212
- readonly implementations?: StrategyImplementations;
213
158
  } | {
214
- readonly algorithm?: never;
215
- readonly implementations: StrategyImplementations;
216
- });
217
- export type Strategy = StrategyDefinition & {
218
- readonly type: "strategy";
219
- };
220
- export type StrategySelection = {
221
- readonly id: string;
222
- readonly engine: Engine;
223
- readonly algorithm: GroupAlgorithm;
224
- readonly members: readonly string[];
225
- readonly requestedAlgorithm?: PortableAlgorithm;
226
- readonly implementationSource?: "default" | "override";
227
- };
228
- export type ConcreteGroup = {
229
- readonly id: string;
230
159
  readonly type: "select";
231
- readonly members: readonly string[];
232
- } | {
233
- readonly id: string;
234
- readonly type: "smart";
235
- readonly members: readonly string[];
236
160
  } | {
237
- readonly id: string;
238
161
  readonly type: "surge-smart";
239
- readonly members: readonly string[];
240
162
  } | {
241
- readonly id: string;
242
163
  readonly type: "urltest";
243
- readonly members: readonly string[];
244
164
  readonly url: string;
245
165
  readonly intervalSeconds?: number;
246
166
  readonly toleranceMs?: number;
247
167
  };
248
- export type Group = Exclude<ConcreteGroup, {
249
- readonly type: "surge-smart";
250
- }> | Strategy;
251
- export type Engine = "surge" | "sing-box" | "mihomo" | "stash";
252
- export type DnsRule = {
168
+ type DnsRule = {
253
169
  readonly pattern: string;
254
170
  readonly server: string;
255
171
  };
256
- export type Tun = {
172
+ type Tun = {
257
173
  readonly address: readonly string[];
258
174
  readonly stack: "system" | "gvisor" | "mixed";
259
175
  readonly autoRoute: boolean;
@@ -261,91 +177,85 @@ export type Tun = {
261
177
  readonly dnsMode: "disabled" | "native" | "hijack";
262
178
  readonly routeExcludeAddress?: readonly string[];
263
179
  };
264
- export type Program = {
265
- readonly domainMatching?: "prefer-sniffed";
266
- readonly serverAliases?: Readonly<Record<string, string>>;
267
- readonly cacheFile?: boolean;
268
- readonly unsupportedUdp?: "reject";
269
- readonly tun?: Tun;
270
- readonly dns?: readonly DnsRule[];
271
- readonly engine: Engine;
272
- readonly nodes: readonly ProxyNode[];
273
- readonly endpoints?: readonly TailscaleEndpoint[];
274
- readonly groups: readonly Group[];
275
- readonly routing: readonly Entry[];
276
- readonly fallback: Action;
277
- readonly listener?: {
278
- readonly port: number;
279
- readonly resolver: string;
280
- };
180
+ type Diagnostic = {
181
+ readonly profile?: string;
182
+ readonly origin?: Origin;
183
+ readonly severity: "error" | "warning";
184
+ readonly code: string;
185
+ readonly path: string;
186
+ readonly message: string;
187
+ readonly target?: string;
281
188
  };
282
- export type Target = {
283
- readonly id: string;
284
- readonly program: string;
285
- readonly engine: Engine;
286
- readonly platform: "macos" | "linux";
287
- readonly version: string;
288
- readonly mode?: "fragment" | "standalone";
189
+ type ProfileDiagnostic = Omit<Diagnostic, "target" | "profile"> & {
190
+ readonly profile: string;
289
191
  };
290
- export type Request = {
291
- readonly network: Network;
192
+ //#endregion
193
+ //#region src/model/routing-types.d.ts
194
+ type RouteRequest = {
195
+ readonly network?: "tcp" | "udp";
292
196
  readonly domain?: string;
293
- readonly tlsSni?: string;
294
- readonly httpHost?: string;
197
+ readonly sniffedDomain?: string;
295
198
  readonly ip?: string;
296
- readonly sourceIp?: string;
297
- readonly processName?: string;
199
+ readonly resolvedIp?: string;
200
+ readonly asn?: number;
298
201
  readonly port?: number;
202
+ readonly sourceIp?: string;
299
203
  readonly sourcePort?: number;
204
+ readonly processName?: string;
205
+ readonly macAddress?: string;
300
206
  };
301
- export type PolicyCase = {
302
- readonly id: string;
303
- readonly program: string;
304
- readonly request: Request;
305
- readonly expect: {
306
- readonly rule?: string;
307
- readonly action: Action;
308
- };
309
- };
310
- export type Config = {
311
- readonly outDir?: string;
312
- readonly programs: Readonly<Record<string, Program>>;
313
- readonly targets: readonly Target[];
314
- readonly cases?: readonly PolicyCase[];
315
- readonly warningsAsErrors?: boolean;
207
+ type Assumptions = {
208
+ readonly hit?: readonly RuleSet[];
209
+ readonly miss?: readonly RuleSet[];
316
210
  };
317
- export type Diagnostic = {
318
- readonly severity: "error" | "warning";
319
- readonly code: string;
320
- readonly path: string;
321
- readonly message: string;
322
- readonly target?: string;
211
+ type RouteCase = {
212
+ readonly name: string;
213
+ readonly request: RouteRequest;
214
+ readonly assume?: Assumptions;
215
+ readonly expect: Exit;
323
216
  };
324
- export type ExpandedRule = {
217
+ type Need = {
218
+ readonly kind: "ruleSet";
325
219
  readonly id: string;
326
- readonly when: Match;
327
- readonly then: Action;
328
- readonly origin: readonly string[];
329
- };
330
- export type ConditionTrace = {
331
- readonly type: Match["type"];
332
- readonly matched: boolean | null;
333
- readonly reason: string;
334
- readonly children?: readonly ConditionTrace[];
335
- };
336
- export type Explanation = {
337
- readonly mode: "static";
338
- readonly rule: string;
339
- readonly action: Action;
220
+ } | {
221
+ readonly kind: "dns";
222
+ } | {
223
+ readonly kind: "asn";
224
+ };
225
+ type Explanation = {
226
+ readonly outcome: "matched" | "fallback" | "indeterminate";
227
+ readonly exit?: string;
228
+ readonly route?: {
229
+ readonly index: number;
230
+ readonly origin?: Origin;
231
+ };
232
+ readonly needs?: Need;
340
233
  readonly trace: readonly {
341
- readonly id: string;
342
- readonly origin: readonly string[];
343
- readonly condition: ConditionTrace;
234
+ readonly index: number;
235
+ readonly matched: boolean | null;
236
+ readonly origin?: Origin;
344
237
  }[];
345
238
  };
239
+ type ExplainResult = {
240
+ readonly ok: true;
241
+ readonly explanation: Explanation;
242
+ } | {
243
+ readonly ok: false;
244
+ readonly diagnostics: readonly ProfileDiagnostic[];
245
+ };
246
+ type CaseResult = {
247
+ readonly name: string;
248
+ readonly profile: string;
249
+ readonly ok: boolean;
250
+ readonly outcome: Explanation["outcome"] | "skipped";
251
+ readonly expected: string;
252
+ readonly actual?: string;
253
+ readonly needs?: Need;
254
+ readonly route?: Explanation["route"];
255
+ };
346
256
  //#endregion
347
- //#region src/surge-profile.d.ts
348
- declare const policy$1: z.ZodUnion<readonly [z.ZodObject<{
257
+ //#region src/model/surge-schema.d.ts
258
+ declare const policy: z.ZodUnion<readonly [z.ZodObject<{
349
259
  ref: z.ZodString;
350
260
  }, z.core.$strict>, z.ZodObject<{
351
261
  builtin: z.ZodEnum<{
@@ -356,8 +266,12 @@ declare const policy$1: z.ZodUnion<readonly [z.ZodObject<{
356
266
  "REJECT-TINYGIF": "REJECT-TINYGIF";
357
267
  }>;
358
268
  }, z.core.$strict>]>;
359
- type SurgePolicy = z.infer<typeof policy$1>;
269
+ type SurgePolicy = z.infer<typeof policy>;
360
270
  declare const generalSchema: z.ZodObject<{
271
+ "udp-policy-not-supported-behaviour": z.ZodOptional<z.ZodEnum<{
272
+ DIRECT: "DIRECT";
273
+ REJECT: "REJECT";
274
+ }>>;
361
275
  loglevel: z.ZodOptional<z.ZodEnum<{
362
276
  info: "info";
363
277
  notify: "notify";
@@ -385,18 +299,12 @@ declare const generalSchema: z.ZodObject<{
385
299
  "bypass-tun": z.ZodOptional<z.ZodArray<z.ZodString>>;
386
300
  "always-real-ip": z.ZodOptional<z.ZodArray<z.ZodString>>;
387
301
  "http-api": z.ZodOptional<z.ZodObject<{
388
- password: z.ZodObject<{
389
- type: z.ZodLiteral<"env">;
390
- name: z.ZodString;
391
- }, z.core.$strict>;
302
+ password: z.ZodCustom<SecretRef, SecretRef>;
392
303
  listen: z.ZodString;
393
304
  }, z.core.$strict>>;
394
305
  "http-api-web-dashboard": z.ZodOptional<z.ZodBoolean>;
395
306
  "external-controller-access": z.ZodOptional<z.ZodObject<{
396
- password: z.ZodObject<{
397
- type: z.ZodLiteral<"env">;
398
- name: z.ZodString;
399
- }, z.core.$strict>;
307
+ password: z.ZodCustom<SecretRef, SecretRef>;
400
308
  listen: z.ZodString;
401
309
  }, z.core.$strict>>;
402
310
  "hijack-dns": z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -415,10 +323,7 @@ declare const tunnelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
415
323
  type: z.ZodLiteral<"tailscale">;
416
324
  id: z.ZodString;
417
325
  sectionName: z.ZodString;
418
- authKey: z.ZodObject<{
419
- type: z.ZodLiteral<"env">;
420
- name: z.ZodString;
421
- }, z.core.$strict>;
326
+ authKey: z.ZodCustom<SecretRef, SecretRef>;
422
327
  hostname: z.ZodString;
423
328
  dnsServer: z.ZodOptional<z.ZodArray<z.ZodString>>;
424
329
  autoAddMagicDnsRule: z.ZodOptional<z.ZodBoolean>;
@@ -427,10 +332,7 @@ declare const tunnelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
427
332
  type: z.ZodLiteral<"wireguard">;
428
333
  id: z.ZodString;
429
334
  sectionName: z.ZodString;
430
- privateKey: z.ZodObject<{
431
- type: z.ZodLiteral<"env">;
432
- name: z.ZodString;
433
- }, z.core.$strict>;
335
+ privateKey: z.ZodCustom<SecretRef, SecretRef>;
434
336
  selfIp: z.ZodString;
435
337
  dnsServer: z.ZodOptional<z.ZodArray<z.ZodString>>;
436
338
  mtu: z.ZodOptional<z.ZodNumber>;
@@ -438,14 +340,11 @@ declare const tunnelSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
438
340
  publicKey: z.ZodString;
439
341
  endpoint: z.ZodString;
440
342
  allowedIps: z.ZodArray<z.ZodString>;
441
- presharedKey: z.ZodOptional<z.ZodObject<{
442
- type: z.ZodLiteral<"env">;
443
- name: z.ZodString;
444
- }, z.core.$strict>>;
343
+ presharedKey: z.ZodOptional<z.ZodCustom<SecretRef, SecretRef>>;
445
344
  persistentKeepalive: z.ZodOptional<z.ZodNumber>;
446
345
  }, z.core.$strict>>;
447
346
  }, z.core.$strict>], "type">;
448
- type SurgeTunnel = z.infer<typeof tunnelSchema>;
347
+ type SurgeTunnel$1 = z.infer<typeof tunnelSchema>;
449
348
  declare const groupSchema: z.ZodObject<{
450
349
  id: z.ZodString;
451
350
  type: z.ZodEnum<{
@@ -510,10 +409,7 @@ type SurgeRule = {
510
409
  };
511
410
  declare const managedSchema: z.ZodObject<{
512
411
  url: z.ZodString;
513
- query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
514
- type: z.ZodLiteral<"env">;
515
- name: z.ZodString;
516
- }, z.core.$strict>]>>>;
412
+ query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodCustom<SecretRef, SecretRef>]>>>;
517
413
  intervalSeconds: z.ZodNumber;
518
414
  strict: z.ZodBoolean;
519
415
  }, z.core.$strict>;
@@ -526,265 +422,242 @@ type SurgeProfileInput = {
526
422
  readonly managed?: z.infer<typeof managedSchema>;
527
423
  readonly general?: SurgeGeneral;
528
424
  readonly hosts?: readonly SurgeHost[];
529
- readonly nodes: readonly ProxyNode[];
530
- readonly tunnels?: readonly SurgeTunnel[];
425
+ readonly nodes: readonly ProxyNode$1[];
426
+ readonly tunnels?: readonly SurgeTunnel$1[];
531
427
  readonly groups: readonly SurgeGroup[];
532
428
  readonly rules: readonly SurgeRule[];
533
429
  readonly fallback: SurgePolicy;
534
430
  readonly names?: Readonly<Record<string, string>>;
535
431
  };
536
- type SurgeProfileCompilation = {
537
- readonly ok: boolean;
538
- readonly artifactKind: "surge-profile";
539
- readonly diagnostics: readonly Diagnostic[];
540
- readonly bindings: readonly {
541
- readonly id: string;
542
- readonly nativeName: string;
543
- }[];
544
- };
545
- type SurgeProfileArtifact = {
546
- readonly artifactKind: "surge-profile";
547
- readonly content: string;
548
- };
549
- export declare function compileSurgeProfile(input: unknown): SurgeProfileCompilation;
550
- export declare function renderSurgeProfile(compilation: SurgeProfileCompilation, resolveSecret: (token: Secret) => string | undefined): SurgeProfileArtifact;
551
- export declare function renderSurgeProfiles(compilations: readonly SurgeProfileCompilation[], resolveSecret: (token: Secret) => string | undefined): readonly SurgeProfileArtifact[];
552
432
  //#endregion
553
- //#region src/targets.d.ts
554
- export declare const targetCatalog: readonly [{
555
- readonly engine: "sing-box";
556
- readonly version: "1.14.4";
557
- readonly autoGroup: "urltest";
558
- readonly platforms: readonly ["linux", "macos"];
559
- readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
560
- readonly endpoints: readonly ["sing-box-tailscale"];
561
- readonly groups: readonly ["select", "urltest"];
562
- readonly nativeRuleSets: readonly ["source", "binary"];
563
- readonly dns: "typed";
564
- }, {
565
- readonly engine: "sing-box";
566
- readonly version: "1.11.0";
567
- readonly autoGroup: "urltest";
568
- readonly platforms: readonly ["linux", "macos"];
569
- readonly protocols: readonly ["hysteria2", "trojan", "http", "shadowsocks", "vmess", "vless"];
570
- readonly endpoints: readonly [];
571
- readonly groups: readonly ["select", "urltest"];
572
- readonly nativeRuleSets: readonly ["source", "binary"];
573
- readonly dns: "legacy";
574
- }, {
575
- readonly engine: "sing-box";
576
- readonly version: "1.12.0";
577
- readonly autoGroup: "urltest";
578
- readonly platforms: readonly ["linux", "macos"];
579
- readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
580
- readonly endpoints: readonly ["sing-box-tailscale"];
581
- readonly groups: readonly ["select", "urltest"];
582
- readonly nativeRuleSets: readonly ["source", "binary"];
583
- readonly dns: "typed";
584
- }, {
433
+ //#region src/model/profile-types.d.ts
434
+ type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
435
+ type Fragments<T> = T | readonly Fragments<T>[];
436
+ type Target = {
437
+ readonly engine: "surge";
438
+ readonly platform: "ios";
439
+ readonly version: "5.21.0";
440
+ } | {
585
441
  readonly engine: "surge";
442
+ readonly platform: "macos";
586
443
  readonly version: "6.10.0";
587
- readonly autoGroup: "surge-smart";
588
- readonly platforms: readonly ["macos"];
589
- readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess"];
590
- readonly endpoints: readonly [];
591
- readonly groups: readonly ["select", "surge-smart"];
592
- readonly nativeRuleSets: readonly ["rule-set", "domain-set"];
593
- readonly dns: "general";
594
- }, {
444
+ } | {
445
+ readonly engine: "sing-box";
446
+ readonly platform: "macos" | "linux";
447
+ readonly version: "1.12.0" | "1.14.4";
448
+ } | {
595
449
  readonly engine: "mihomo";
450
+ readonly platform: "macos" | "linux";
596
451
  readonly version: "1.19.32";
597
- readonly autoGroup: "urltest";
598
- readonly platforms: readonly ["linux", "macos"];
599
- readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
600
- readonly endpoints: readonly [];
601
- readonly groups: readonly ["select", "urltest"];
602
- readonly nativeRuleSets: readonly ["yaml", "text"];
603
- readonly dns: "clash";
604
- }, {
452
+ } | {
605
453
  readonly engine: "stash";
454
+ readonly platform: "macos";
606
455
  readonly version: "4.2.1";
607
- readonly autoGroup: null;
608
- readonly platforms: readonly ["macos"];
609
- readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess"];
610
- readonly endpoints: readonly [];
611
- readonly groups: readonly ["select"];
612
- readonly nativeRuleSets: readonly [];
613
- readonly dns: "external";
614
- }];
615
- //#endregion
616
- //#region src/compiler.d.ts
617
- type TargetPlan = {
618
- readonly target: Target;
619
- readonly program: Omit<Program, "groups"> & {
620
- readonly groups: readonly ConcreteGroup[];
621
- };
622
- readonly nativeRuleSets: readonly NativeRuleSet[];
623
- readonly strategySelections: readonly StrategySelection[];
624
- readonly rules: readonly ExpandedRule[];
625
- readonly sourceMap: readonly {
626
- readonly rule: string;
627
- readonly nativeIndex: number;
628
- readonly origin: readonly string[];
629
- }[];
630
- readonly preconditions: readonly string[];
631
- readonly nativeValidation: "not-run";
632
456
  };
633
- type Compilation = {
634
- readonly ok: boolean;
635
- readonly diagnostics: readonly Diagnostic[];
636
- readonly plans: readonly TargetPlan[];
637
- readonly cases: readonly CaseResult[];
638
- };
639
- type CaseResult = {
457
+ type SecretRef = Secret & SDK<"secret">;
458
+ type Secrets<T extends string = string> = Readonly<Record<T, SecretRef>> & SDK<"secrets">;
459
+ type PublicSecrets<T> = T extends Secret ? SecretRef : T extends readonly (infer V)[] ? readonly PublicSecrets<V>[] : T extends object ? { readonly [K in keyof T]: PublicSecrets<T[K]>; } : T;
460
+ type NodeOf<N> = N extends ProxyNode$1 ? Omit<PublicSecrets<N>, "via" | "label"> & {
461
+ readonly via?: ProxyNode | ProxyGroup;
462
+ readonly name?: string;
463
+ } & SDK<"node"> : never;
464
+ type ProxyNode = NodeOf<ProxyNode$1>;
465
+ type ProxyGroup<A extends GroupAlgorithm = GroupAlgorithm> = {
466
+ readonly type: "proxy-group";
640
467
  readonly id: string;
641
- readonly passed: boolean;
642
- readonly actual: {
643
- readonly rule: string;
644
- readonly action: Action;
468
+ readonly name?: string;
469
+ readonly algorithm: A;
470
+ readonly members: readonly Exit[];
471
+ readonly surge?: {
472
+ readonly url: string;
473
+ readonly intervalSeconds?: number;
474
+ readonly timeoutSeconds?: number;
645
475
  };
646
- } | {
647
- readonly id: string;
648
- readonly passed: false;
649
- readonly code: "CASE_INDETERMINATE";
650
- };
651
- export declare function compile(input: unknown): Compilation;
652
- export declare function explain(compilation: Compilation, target: string, request: Request): Explanation;
653
- //#endregion
654
- //#region src/surge-definitions.d.ts
655
- interface ProxyGroupDefinition {
656
- readonly type: "proxy-group";
476
+ } & SDK<"group">;
477
+ type SurgeTunnel = PublicSecrets<SurgeTunnel$1> & {
478
+ readonly name?: string;
479
+ } & SDK<"tunnel">;
480
+ type SingBoxEndpoint = PublicSecrets<TailscaleEndpoint> & {
481
+ readonly name?: string;
482
+ } & SDK<"endpoint">;
483
+ type Builtin = {
484
+ readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
485
+ } & SDK<"builtin">;
486
+ type Exit = ProxyNode | ProxyGroup | SurgeTunnel | SingBoxEndpoint | Builtin;
487
+ type ProfileProxy = ProxyNode | SurgeTunnel | SingBoxEndpoint;
488
+ type ExternalRuleSet = {
489
+ readonly type: "ruleSetSource";
657
490
  readonly id: string;
658
- readonly name: string;
659
- readonly algorithm: GroupAlgorithm;
660
- readonly members: readonly ProfileDestination[];
661
- readonly url?: string;
662
- readonly intervalSeconds?: number;
663
- readonly timeoutSeconds?: number;
664
- }
665
- type RouteDefinition = {
666
- readonly type: "route";
667
- readonly when: ProfileCondition;
668
- readonly to: ProfileDestination;
669
- };
670
- export declare class ProfileDefinitionError extends Error {
671
- readonly code: string;
672
- readonly paths?: readonly string[];
673
- constructor(code: string, paths?: readonly string[]);
674
- }
675
- export declare const outbound: {
676
- direct: Readonly<{
677
- readonly builtin: "DIRECT";
678
- }>;
679
- reject: Readonly<{
680
- readonly builtin: "REJECT";
681
- }>;
682
- rejectDrop: Readonly<{
683
- readonly builtin: "REJECT-DROP";
684
- }>;
685
- rejectNoDrop: Readonly<{
686
- readonly builtin: "REJECT-NO-DROP";
687
- }>;
688
- rejectTinyGif: Readonly<{
689
- readonly builtin: "REJECT-TINYGIF";
690
- }>;
691
- };
692
- export declare function defineProxyGroup(input: Omit<ProxyGroupDefinition, "type">): ProxyGroupDefinition;
693
- export declare function defineRoute(input: Omit<RouteDefinition, "type">): RouteDefinition;
694
- export declare function defineRoutes(input: {
695
- readonly when: readonly ProfileCondition[];
696
- readonly to: ProfileDestination;
697
- }): RouteDefinition[];
698
- //#endregion
699
- //#region src/profile.d.ts
700
- type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
491
+ readonly surge?: {
492
+ readonly url: string;
493
+ readonly format?: "rule-set" | "domain-set";
494
+ readonly intervalSeconds?: number;
495
+ readonly noResolve?: boolean;
496
+ readonly includeSniffed?: boolean;
497
+ };
498
+ readonly singBox?: {
499
+ readonly url: string;
500
+ readonly format: "source" | "binary";
501
+ readonly intervalSeconds: number;
502
+ readonly resolve?: boolean;
503
+ };
504
+ readonly mihomo?: {
505
+ readonly url: string;
506
+ readonly format: "yaml" | "text";
507
+ readonly behavior: "domain" | "ipcidr" | "classical";
508
+ readonly intervalSeconds: number;
509
+ };
510
+ } & SDK<"ruleSet">;
511
+ type BuiltinRuleSet = {
512
+ readonly type: "ruleSet";
513
+ readonly id: "surge:lan" | "surge:system";
514
+ readonly format: "rule-set";
515
+ readonly builtin: "LAN" | "SYSTEM";
516
+ } & SDK<"ruleSet">;
517
+ type RuleSet = ExternalRuleSet | BuiltinRuleSet;
701
518
  type ProfileCondition = Exclude<Match | SurgeCondition, {
702
- type: "all" | "any" | "not";
703
- }> | {
519
+ type: "all" | "any" | "not" | "nativeRuleSet" | "ruleSet";
520
+ }> | RuleSet | {
704
521
  readonly type: "all" | "any";
705
522
  readonly conditions: readonly ProfileCondition[];
706
- readonly noResolve?: boolean;
707
523
  } | {
708
524
  readonly type: "not";
709
525
  readonly condition: ProfileCondition;
710
- readonly noResolve?: boolean;
711
- };
712
- type ProfileDestination = string | ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
713
- readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
714
526
  };
715
- type Fragments<T> = readonly (T | Fragments<T>)[];
716
- type ProfileProxy = ProxyNode | SurgeTunnel | TailscaleEndpoint;
717
- type SurgeConfig = DeepReadonly<Pick<SurgeProfileInput, "managed" | "names">> & {
718
- readonly general?: DeepReadonly<SurgeGeneral> | Fragments<DeepReadonly<SurgeGeneral>>;
527
+ type Condition = ProfileCondition;
528
+ type Route = {
529
+ readonly type: "route";
530
+ readonly when: Condition;
531
+ readonly to: Exit;
532
+ } & SDK<"route">;
533
+ type SurgeConfig = {
534
+ readonly general?: Fragments<DeepReadonly<SurgeGeneral>>;
719
535
  readonly hosts?: Fragments<DeepReadonly<SurgeHost>>;
536
+ readonly managed?: DeepReadonly<SurgeProfileInput["managed"]>;
720
537
  };
721
- type ProfileDefinition = {
722
- readonly dns?: Fragments<DnsRule>;
723
- readonly target: SurgeProfileInput["target"] | {
724
- readonly engine: "sing-box";
725
- readonly platform: "macos" | "linux";
726
- readonly version: string;
538
+ type SingBoxOptions = {
539
+ readonly mode?: "standalone" | "fragment";
540
+ readonly listener?: {
541
+ readonly port: number;
542
+ readonly resolver: string;
727
543
  };
544
+ readonly tun?: Tun;
545
+ readonly domainMatching?: "prefer-sniffed";
546
+ readonly serverAliases?: Readonly<Record<string, string>>;
547
+ readonly cacheFile?: boolean;
548
+ readonly unsupportedUdp?: "reject";
549
+ };
550
+ type Common = {
551
+ readonly cases?: Fragments<RouteCase>;
552
+ readonly dns?: Fragments<DnsRule>;
728
553
  readonly proxies: Fragments<ProfileProxy>;
729
- readonly groups: Fragments<ProxyGroupDefinition>;
730
- readonly routes: Fragments<RouteDefinition>;
731
- readonly fallback: ProfileDestination;
732
- readonly surge?: SurgeConfig;
733
- readonly singBox?: {
734
- readonly mode: "fragment" | "standalone";
735
- readonly tun?: Tun;
736
- readonly listener?: {
737
- readonly port: number;
738
- readonly resolver: string;
739
- };
740
- readonly domainMatching?: "prefer-sniffed";
741
- readonly serverAliases?: Readonly<Record<string, string>>;
742
- readonly cacheFile?: boolean;
743
- readonly unsupportedUdp?: "reject";
744
- };
554
+ readonly routes: Fragments<Route>;
555
+ readonly fallback: Exit;
745
556
  };
746
- type Profile = DeepReadonly<Omit<ProfileDefinition, "proxies" | "groups" | "routes" | "surge" | "dns"> & {
747
- readonly dns?: readonly DnsRule[];
748
- readonly proxies: readonly ProfileProxy[];
749
- readonly groups: readonly ProxyGroupDefinition[];
750
- readonly routes: readonly RouteDefinition[];
751
- readonly surge?: Pick<SurgeProfileInput, "managed" | "general" | "hosts" | "names">;
557
+ type Portable = Exclude<GroupAlgorithm, {
558
+ type: "surge-smart";
752
559
  }>;
753
- type ProfileCompilation = {
754
- readonly engine: "surge";
755
- readonly ok: boolean;
756
- readonly compilation: SurgeProfileCompilation;
560
+ type ProfileDefinition = Common & ({
561
+ readonly target: Extract<Target, {
562
+ engine: "surge";
563
+ }>;
564
+ readonly groups: Fragments<ProxyGroup>;
565
+ readonly surge?: SurgeConfig;
566
+ readonly singBox?: never;
567
+ readonly mihomo?: never;
757
568
  } | {
758
- readonly engine: "sing-box";
759
- readonly ok: boolean;
760
- readonly compilation: Compilation;
569
+ readonly target: Extract<Target, {
570
+ engine: "sing-box";
571
+ }>;
572
+ readonly groups: Fragments<ProxyGroup<Portable>>;
573
+ readonly singBox?: SingBoxOptions;
574
+ readonly surge?: never;
575
+ readonly mihomo?: never;
761
576
  } | {
762
- readonly engine: "invalid";
763
- readonly ok: false;
764
- readonly code: string;
765
- readonly paths?: readonly string[];
577
+ readonly target: Extract<Target, {
578
+ engine: "mihomo";
579
+ }>;
580
+ readonly groups: Fragments<ProxyGroup<Portable>>;
581
+ readonly mihomo?: Pick<SingBoxOptions, "mode" | "listener">;
582
+ readonly surge?: never;
583
+ readonly singBox?: never;
584
+ } | {
585
+ readonly target: Extract<Target, {
586
+ engine: "stash";
587
+ }>;
588
+ readonly groups: Fragments<ProxyGroup<Portable>>;
589
+ readonly surge?: never;
590
+ readonly singBox?: never;
591
+ readonly mihomo?: never;
592
+ });
593
+ type ResolvedSurge = {
594
+ readonly general?: DeepReadonly<SurgeGeneral>;
595
+ readonly hosts?: readonly DeepReadonly<SurgeHost>[];
596
+ readonly managed?: DeepReadonly<SurgeProfileInput["managed"]>;
766
597
  };
767
- declare function surgeConfig(input: SurgeConfig): SurgeConfig;
768
- export declare function defineProfile(input: ProfileDefinition | Profile): Profile;
769
- /** No secrets or I/O. All engine adaptations retain strict validation. */
770
- export declare function compileProfile(input: ProfileDefinition | Profile): ProfileCompilation;
598
+ type FlattenedProfile<D extends ProfileDefinition> = D extends ProfileDefinition ? Omit<D, "proxies" | "groups" | "routes" | "dns" | "cases" | "surge"> & {
599
+ readonly proxies: readonly ProfileProxy[];
600
+ readonly groups: readonly (D extends {
601
+ target: {
602
+ engine: "surge";
603
+ };
604
+ } ? ProxyGroup : ProxyGroup<Portable>)[];
605
+ readonly routes: readonly Route[];
606
+ readonly dns: readonly DnsRule[];
607
+ readonly cases: readonly RouteCase[];
608
+ readonly surge?: D extends {
609
+ target: {
610
+ engine: "surge";
611
+ };
612
+ } ? ResolvedSurge : never;
613
+ } : never;
614
+ type Profile<D extends ProfileDefinition = ProfileDefinition> = FlattenedProfile<D> & SDK<"profile">;
615
+ //#endregion
616
+ //#region src/authoring/profile.d.ts
617
+ export declare function defineProfile<const D extends ProfileDefinition>(input: D): Profile<D>;
618
+ //#endregion
619
+ //#region src/authoring/resources.d.ts
620
+ export declare const outbound: {
621
+ direct: {
622
+ builtin: "DIRECT";
623
+ } & SDK<"builtin">;
624
+ reject: {
625
+ builtin: "REJECT";
626
+ } & SDK<"builtin">;
627
+ rejectDrop: {
628
+ builtin: "REJECT-DROP";
629
+ } & SDK<"builtin">;
630
+ rejectNoDrop: {
631
+ builtin: "REJECT-NO-DROP";
632
+ } & SDK<"builtin">;
633
+ rejectTinyGif: {
634
+ builtin: "REJECT-TINYGIF";
635
+ } & SDK<"builtin">;
636
+ };
637
+ export declare function defineProxyGroup<const A extends GroupAlgorithm>(input: {
638
+ readonly id: string;
639
+ readonly name?: string;
640
+ readonly algorithm: A;
641
+ readonly members: Fragments<Exit>;
642
+ readonly surge?: ProxyGroup<A>["surge"];
643
+ }): ProxyGroup<A>;
644
+ export declare function defineRoutes(input: {
645
+ readonly when: Fragments<Condition>;
646
+ readonly to: Exit;
647
+ }): Route[];
771
648
  //#endregion
772
- //#region src/proxy-builder.d.ts
649
+ //#region src/authoring/proxy-builder.d.ts
773
650
  type ProxyBuilder<N extends ProxyNode> = {
774
- readonly via: (id: string) => ProxyBuilder<N>;
775
- readonly label: (text: string) => ProxyBuilder<N>;
651
+ readonly via: (exit: ProxyNode | ProxyGroup) => ProxyBuilder<N>;
652
+ readonly name: (text: string) => ProxyBuilder<N>;
776
653
  readonly tcpFastOpen: (enabled: boolean) => ProxyBuilder<N>;
777
654
  readonly build: () => N;
778
655
  };
779
- /** Fluent construction is separate from the plain-data node consumed by the compiler. */
780
- declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<Extract<ProxyNode, {
781
- type: N["type"];
782
- }>>;
656
+ declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<N>;
783
657
  //#endregion
784
- //#region src/dsl.d.ts
658
+ //#region src/authoring/constructors.d.ts
785
659
  export declare function dnsRule(pattern: string, server: string): DnsRule;
786
- export declare function dnsRule(patterns: readonly string[], server: string): DnsRule[];
787
- export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
660
+ export declare function dnsRule(pattern: readonly string[], server: string): DnsRule[];
788
661
  type DomainOptions = {
789
662
  readonly includeSniffed?: boolean;
790
663
  };
@@ -792,438 +665,575 @@ type IpOptions = {
792
665
  readonly noResolve?: boolean;
793
666
  };
794
667
  export declare const match: {
795
- processName: (value: string) => {
796
- readonly type: "processName";
797
- readonly value: string;
668
+ domain: {
669
+ (value: string, options?: DomainOptions | undefined): {
670
+ readonly type: "domain";
671
+ readonly value: string;
672
+ } & DomainOptions;
673
+ (value: readonly string[], options?: DomainOptions | undefined): ({
674
+ readonly type: "domain";
675
+ readonly value: string;
676
+ } & DomainOptions)[];
798
677
  };
799
- ruleSet: (set: NamedRuleSet) => NamedRuleSet;
800
- domain: (value: string, opts?: DomainOptions) => {
801
- includeSniffed?: boolean;
802
- type: "domain";
803
- value: string;
678
+ domainSuffix: {
679
+ (value: string, options?: DomainOptions | undefined): {
680
+ readonly type: "domainSuffix";
681
+ readonly value: string;
682
+ } & DomainOptions;
683
+ (value: readonly string[], options?: DomainOptions | undefined): ({
684
+ readonly type: "domainSuffix";
685
+ readonly value: string;
686
+ } & DomainOptions)[];
804
687
  };
805
- domainSuffix: (value: string, opts?: DomainOptions) => {
806
- includeSniffed?: boolean;
807
- type: "domainSuffix";
808
- value: string;
688
+ ipCidr: {
689
+ (value: string, options?: IpOptions | undefined): {
690
+ readonly type: "ipCidr";
691
+ readonly value: string;
692
+ } & IpOptions;
693
+ (value: readonly string[], options?: IpOptions | undefined): ({
694
+ readonly type: "ipCidr";
695
+ readonly value: string;
696
+ } & IpOptions)[];
809
697
  };
810
- ipCidr: (value: string, opts?: IpOptions) => {
811
- noResolve?: boolean;
812
- type: "ipCidr";
813
- value: string;
698
+ sourceIp: {
699
+ (value: string, options?: Record<string, never> | undefined): {
700
+ readonly type: "sourceIp";
701
+ readonly value: string;
702
+ } & Record<string, never>;
703
+ (value: readonly string[], options?: Record<string, never> | undefined): ({
704
+ readonly type: "sourceIp";
705
+ readonly value: string;
706
+ } & Record<string, never>)[];
814
707
  };
815
- sourceIp: (value: string) => {
816
- type: "sourceIp";
817
- value: string;
708
+ processName: {
709
+ (value: string, options?: Record<string, never> | undefined): {
710
+ readonly type: "processName";
711
+ readonly value: string;
712
+ } & Record<string, never>;
713
+ (value: readonly string[], options?: Record<string, never> | undefined): ({
714
+ readonly type: "processName";
715
+ readonly value: string;
716
+ } & Record<string, never>)[];
818
717
  };
819
- port: (from: number, to?: number) => {
820
- type: "port";
821
- from: number;
822
- to: number;
823
- };
824
- sourcePort: (from: number, to?: number) => {
825
- type: "sourcePort";
826
- from: number;
827
- to: number;
828
- };
829
- network: (value: Network) => {
718
+ port: (from: number, to?: number) => Extract<Condition, {
719
+ type: "port" | "sourcePort";
720
+ }>;
721
+ sourcePort: (from: number, to?: number) => Extract<Condition, {
722
+ type: "port" | "sourcePort";
723
+ }>;
724
+ network: (value: Network) => Extract<Condition, {
830
725
  type: "network";
831
- value: Network;
832
- };
833
- all: <const C extends readonly ProfileCondition[]>(...conditions: C) => {
834
- type: "all";
835
- conditions: C;
836
- };
837
- any: <const C extends readonly ProfileCondition[]>(...conditions: C) => {
838
- type: "any";
839
- conditions: C;
840
- };
841
- not: <const C extends ProfileCondition>(condition: C) => {
726
+ }>;
727
+ all: (...conditions: readonly Fragments<Condition>[]) => {
728
+ type: "all" | "any";
729
+ conditions: ProfileCondition[];
730
+ } & SDK<"condition">;
731
+ any: (...conditions: readonly Fragments<Condition>[]) => {
732
+ type: "all" | "any";
733
+ conditions: ProfileCondition[];
734
+ } & SDK<"condition">;
735
+ not: (condition: Condition) => {
842
736
  type: "not";
843
- condition: C;
844
- };
845
- };
846
- type NativeFor<E extends NativeRuleSet["engine"]> = Extract<NativeRuleSet, {
847
- engine: E;
848
- }>;
849
- type NativeInput<E extends NativeRuleSet["engine"]> = Omit<NativeFor<E>, "type" | "engine" | "id"> & {
850
- readonly id?: string;
737
+ condition: ProfileCondition;
738
+ } & SDK<"condition">;
851
739
  };
852
- type SurgeSetInput = Omit<NativeInput<"surge">, "format"> & {
853
- readonly format?: "rule-set" | "domain-set";
854
- };
855
- export declare const direct: () => Action;
856
- export declare const reject: () => Action;
857
- export declare const route: (to: string) => Action;
858
- /** An exit parameter declared by policy.exits and resolved by use.bindings. */
859
- export declare const slot: <const S extends string>(name: S) => Slot<S>;
860
- export declare const secret: (name: string) => Secret;
861
- export declare const rule: <const S extends string = never>(id: string, when: Match, then: Action | Slot<S>) => Rule<S>;
862
- export declare const block: <const S extends string = never>(id: string, rules: readonly Entry<S>[], when?: Match) => Block<S>;
863
- type CheckedEntries<S extends string, R extends readonly Entry[]> = R & (string extends (R[number] extends Entry<infer Used> ? Used : never) ? unknown : readonly Entry<S>[]);
864
- export declare const policy: <const S extends string, const R extends readonly Entry[] = readonly Entry<S>[]>(definition: Omit<Policy<S>, "type" | "rules"> & {
865
- readonly rules: CheckedEntries<NoInfer<S>, R>;
866
- }) => Policy<S>;
867
- export declare const use: <S extends string, const B extends Record<NoInfer<S>, Action | Slot>>(definition: Policy<S>, options: {
868
- id: string;
869
- bindings: B & Record<Exclude<keyof B, S>, never>;
870
- }) => Use<Extract<B[keyof B], Slot>["name"]>;
871
- export declare const sequence: <const S extends string = never>(...parts: readonly (Entry<S> | readonly Entry<S>[])[]) => Entry<S>[];
872
- export declare const defineConfig: <const T extends Config>(config: T & {
873
- readonly targets: readonly (Config["targets"][number] & {
874
- readonly program: string extends NoInfer<T>["targets"][number]["program"] ? string : keyof NoInfer<T>["programs"] & string;
875
- })[];
876
- readonly cases?: readonly (NonNullable<Config["cases"]>[number] & {
877
- readonly program: string extends NonNullable<NoInfer<T>["cases"]>[number]["program"] ? string : keyof NoInfer<T>["programs"] & string;
878
- })[];
879
- }) => T;
880
- /** A shared strategy declares an algorithm or explicitly selects native implementations. */
881
- export declare const strategy: (definition: StrategyDefinition) => Strategy;
740
+ export declare function ruleSet(input: Omit<ExternalRuleSet, "type" | keyof SDK<"ruleSet">>): RuleSet;
882
741
  export declare const group: {
883
742
  auto: () => {
884
- readonly type: "auto";
885
- };
886
- select: () => Extract<GroupAlgorithm, {
743
+ type: "auto";
744
+ } & SDK<"algorithm">;
745
+ select: () => {
887
746
  type: "select";
888
- }>;
889
- urltest: (options: Omit<Extract<GroupAlgorithm, {
747
+ } & SDK<"algorithm">;
748
+ urltest: (input: Omit<Extract<GroupAlgorithm, {
890
749
  type: "urltest";
891
- }>, "type">) => Extract<GroupAlgorithm, {
750
+ }>, "type">) => {
751
+ url: string;
752
+ intervalSeconds?: number;
753
+ toleranceMs?: number;
892
754
  type: "urltest";
893
- }>;
755
+ } & SDK<"algorithm">;
756
+ };
757
+ type Input<T extends object> = Omit<T, "type" | keyof SDK<string>>;
758
+ export declare const proxy: {
759
+ builder: typeof proxyBuilder;
760
+ http: (input: Input<Omit<{
761
+ readonly id: string;
762
+ readonly server: string;
763
+ readonly port: number;
764
+ readonly via?: string;
765
+ readonly tcpFastOpen?: boolean;
766
+ readonly type: "http";
767
+ readonly serverName?: never;
768
+ readonly password: SecretRef;
769
+ readonly username?: SecretRef | undefined;
770
+ }, "label" | "via"> & {
771
+ readonly via?: ProxyNode | ProxyGroup;
772
+ readonly name?: string;
773
+ } & SDK<"node">>) => Omit<{
774
+ readonly id: string;
775
+ readonly server: string;
776
+ readonly port: number;
777
+ readonly via?: string;
778
+ readonly tcpFastOpen?: boolean;
779
+ readonly type: "http";
780
+ readonly serverName?: never;
781
+ readonly password: SecretRef;
782
+ readonly username?: SecretRef | undefined;
783
+ }, "label" | "via"> & {
784
+ readonly via?: ProxyNode | ProxyGroup;
785
+ readonly name?: string;
786
+ } & SDK<"node">;
787
+ trojan: (input: Input<Omit<{
788
+ readonly id: string;
789
+ readonly server: string;
790
+ readonly port: number;
791
+ readonly via?: string;
792
+ readonly tcpFastOpen?: boolean;
793
+ readonly type: "trojan";
794
+ readonly password: SecretRef;
795
+ readonly serverName?: string;
796
+ readonly skipCertVerify?: boolean;
797
+ readonly surge?: {
798
+ readonly blockQuic?: "auto" | "on" | "off";
799
+ readonly udpRelay?: true;
800
+ } | undefined;
801
+ }, "label" | "via"> & {
802
+ readonly via?: ProxyNode | ProxyGroup;
803
+ readonly name?: string;
804
+ } & SDK<"node">>) => Omit<{
805
+ readonly id: string;
806
+ readonly server: string;
807
+ readonly port: number;
808
+ readonly via?: string;
809
+ readonly tcpFastOpen?: boolean;
810
+ readonly type: "trojan";
811
+ readonly password: SecretRef;
812
+ readonly serverName?: string;
813
+ readonly skipCertVerify?: boolean;
814
+ readonly surge?: {
815
+ readonly blockQuic?: "auto" | "on" | "off";
816
+ readonly udpRelay?: true;
817
+ } | undefined;
818
+ }, "label" | "via"> & {
819
+ readonly via?: ProxyNode | ProxyGroup;
820
+ readonly name?: string;
821
+ } & SDK<"node">;
822
+ anytls: (input: Input<Omit<{
823
+ readonly id: string;
824
+ readonly server: string;
825
+ readonly port: number;
826
+ readonly via?: string;
827
+ readonly tcpFastOpen?: boolean;
828
+ readonly type: "anytls";
829
+ readonly password: SecretRef;
830
+ readonly serverName?: string;
831
+ readonly skipCertVerify?: boolean;
832
+ readonly surge?: {
833
+ readonly blockQuic?: "auto" | "on" | "off";
834
+ readonly udpRelay?: true;
835
+ } | undefined;
836
+ }, "label" | "via"> & {
837
+ readonly via?: ProxyNode | ProxyGroup;
838
+ readonly name?: string;
839
+ } & SDK<"node">>) => Omit<{
840
+ readonly id: string;
841
+ readonly server: string;
842
+ readonly port: number;
843
+ readonly via?: string;
844
+ readonly tcpFastOpen?: boolean;
845
+ readonly type: "anytls";
846
+ readonly password: SecretRef;
847
+ readonly serverName?: string;
848
+ readonly skipCertVerify?: boolean;
849
+ readonly surge?: {
850
+ readonly blockQuic?: "auto" | "on" | "off";
851
+ readonly udpRelay?: true;
852
+ } | undefined;
853
+ }, "label" | "via"> & {
854
+ readonly via?: ProxyNode | ProxyGroup;
855
+ readonly name?: string;
856
+ } & SDK<"node">;
857
+ hysteria2: (input: Input<Omit<{
858
+ readonly id: string;
859
+ readonly server: string;
860
+ readonly port: number;
861
+ readonly via?: string;
862
+ readonly type: "hysteria2";
863
+ readonly tcpFastOpen?: never;
864
+ readonly password: SecretRef;
865
+ readonly serverName?: string;
866
+ readonly skipCertVerify?: boolean;
867
+ readonly portHopping?: string;
868
+ readonly portHoppingInterval?: number;
869
+ }, "label" | "via"> & {
870
+ readonly via?: ProxyNode | ProxyGroup;
871
+ readonly name?: string;
872
+ } & SDK<"node">>) => Omit<{
873
+ readonly id: string;
874
+ readonly server: string;
875
+ readonly port: number;
876
+ readonly via?: string;
877
+ readonly type: "hysteria2";
878
+ readonly tcpFastOpen?: never;
879
+ readonly password: SecretRef;
880
+ readonly serverName?: string;
881
+ readonly skipCertVerify?: boolean;
882
+ readonly portHopping?: string;
883
+ readonly portHoppingInterval?: number;
884
+ }, "label" | "via"> & {
885
+ readonly via?: ProxyNode | ProxyGroup;
886
+ readonly name?: string;
887
+ } & SDK<"node">;
888
+ shadowsocks: (input: Input<Omit<{
889
+ readonly id: string;
890
+ readonly server: string;
891
+ readonly port: number;
892
+ readonly via?: string;
893
+ readonly tcpFastOpen?: boolean;
894
+ readonly type: "shadowsocks";
895
+ readonly method: "aes-128-gcm" | "aes-256-gcm" | "chacha20-ietf-poly1305";
896
+ readonly password: SecretRef;
897
+ readonly surge?: {
898
+ readonly udpRelay?: boolean;
899
+ readonly blockQuic?: "auto" | "on" | "off";
900
+ } | undefined;
901
+ }, "label" | "via"> & {
902
+ readonly via?: ProxyNode | ProxyGroup;
903
+ readonly name?: string;
904
+ } & SDK<"node">>) => Omit<{
905
+ readonly id: string;
906
+ readonly server: string;
907
+ readonly port: number;
908
+ readonly via?: string;
909
+ readonly tcpFastOpen?: boolean;
910
+ readonly type: "shadowsocks";
911
+ readonly method: "aes-128-gcm" | "aes-256-gcm" | "chacha20-ietf-poly1305";
912
+ readonly password: SecretRef;
913
+ readonly surge?: {
914
+ readonly udpRelay?: boolean;
915
+ readonly blockQuic?: "auto" | "on" | "off";
916
+ } | undefined;
917
+ }, "label" | "via"> & {
918
+ readonly via?: ProxyNode | ProxyGroup;
919
+ readonly name?: string;
920
+ } & SDK<"node">;
921
+ vmess: (input: Input<Omit<{
922
+ readonly id: string;
923
+ readonly server: string;
924
+ readonly port: number;
925
+ readonly via?: string;
926
+ readonly tcpFastOpen?: boolean;
927
+ readonly type: "vmess";
928
+ readonly uuid: SecretRef;
929
+ readonly tls?: {
930
+ readonly serverName: string;
931
+ readonly alpn?: readonly string[] | undefined;
932
+ readonly skipCertVerify?: boolean;
933
+ } | undefined;
934
+ readonly transport?: {
935
+ readonly type: "ws";
936
+ readonly path: string;
937
+ readonly host?: string;
938
+ } | undefined;
939
+ readonly surge?: {
940
+ readonly blockQuic?: "auto" | "on" | "off";
941
+ } | undefined;
942
+ }, "label" | "via"> & {
943
+ readonly via?: ProxyNode | ProxyGroup;
944
+ readonly name?: string;
945
+ } & SDK<"node">>) => Omit<{
946
+ readonly id: string;
947
+ readonly server: string;
948
+ readonly port: number;
949
+ readonly via?: string;
950
+ readonly tcpFastOpen?: boolean;
951
+ readonly type: "vmess";
952
+ readonly uuid: SecretRef;
953
+ readonly tls?: {
954
+ readonly serverName: string;
955
+ readonly alpn?: readonly string[] | undefined;
956
+ readonly skipCertVerify?: boolean;
957
+ } | undefined;
958
+ readonly transport?: {
959
+ readonly type: "ws";
960
+ readonly path: string;
961
+ readonly host?: string;
962
+ } | undefined;
963
+ readonly surge?: {
964
+ readonly blockQuic?: "auto" | "on" | "off";
965
+ } | undefined;
966
+ }, "label" | "via"> & {
967
+ readonly via?: ProxyNode | ProxyGroup;
968
+ readonly name?: string;
969
+ } & SDK<"node">;
970
+ vless: (input: Input<Omit<{
971
+ readonly id: string;
972
+ readonly server: string;
973
+ readonly port: number;
974
+ readonly via?: string;
975
+ readonly tcpFastOpen?: boolean;
976
+ readonly type: "vless";
977
+ readonly uuid: SecretRef;
978
+ readonly tls?: {
979
+ readonly serverName: string;
980
+ readonly alpn?: readonly string[] | undefined;
981
+ readonly skipCertVerify?: boolean;
982
+ } | undefined;
983
+ readonly transport?: {
984
+ readonly type: "ws";
985
+ readonly path: string;
986
+ readonly host?: string;
987
+ } | undefined;
988
+ readonly flow?: "xtls-rprx-vision";
989
+ readonly packetEncoding?: "xudp" | "packetaddr";
990
+ readonly reality?: {
991
+ readonly publicKey: string;
992
+ readonly shortId: string;
993
+ } | undefined;
994
+ readonly utlsFingerprint?: "chrome";
995
+ }, "label" | "via"> & {
996
+ readonly via?: ProxyNode | ProxyGroup;
997
+ readonly name?: string;
998
+ } & SDK<"node">>) => Omit<{
999
+ readonly id: string;
1000
+ readonly server: string;
1001
+ readonly port: number;
1002
+ readonly via?: string;
1003
+ readonly tcpFastOpen?: boolean;
1004
+ readonly type: "vless";
1005
+ readonly uuid: SecretRef;
1006
+ readonly tls?: {
1007
+ readonly serverName: string;
1008
+ readonly alpn?: readonly string[] | undefined;
1009
+ readonly skipCertVerify?: boolean;
1010
+ } | undefined;
1011
+ readonly transport?: {
1012
+ readonly type: "ws";
1013
+ readonly path: string;
1014
+ readonly host?: string;
1015
+ } | undefined;
1016
+ readonly flow?: "xtls-rprx-vision";
1017
+ readonly packetEncoding?: "xudp" | "packetaddr";
1018
+ readonly reality?: {
1019
+ readonly publicKey: string;
1020
+ readonly shortId: string;
1021
+ } | undefined;
1022
+ readonly utlsFingerprint?: "chrome";
1023
+ }, "label" | "via"> & {
1024
+ readonly via?: ProxyNode | ProxyGroup;
1025
+ readonly name?: string;
1026
+ } & SDK<"node">;
894
1027
  };
895
1028
  export declare const surge: {
896
- config: typeof surgeConfig;
897
1029
  match: {
898
- domain: (value: string, options?: {
899
- readonly noResolve?: boolean;
900
- readonly includeSniffed?: boolean;
901
- } | undefined) => SurgeCondition;
902
- domainSuffix: (value: string, options?: {
903
- readonly noResolve?: boolean;
904
- readonly includeSniffed?: boolean;
905
- } | undefined) => SurgeCondition;
906
- ipCidr: (value: string, options?: {
907
- readonly noResolve?: boolean;
908
- readonly includeSniffed?: never;
909
- } | undefined) => SurgeCondition;
910
- ipCidr6: (value: string, options?: {
911
- readonly noResolve?: boolean;
912
- readonly includeSniffed?: never;
913
- } | undefined) => SurgeCondition;
914
1030
  ipAsn: (value: number, options?: {
915
1031
  readonly noResolve?: boolean;
916
1032
  readonly includeSniffed?: never;
917
- }) => SurgeCondition;
918
- sourceIp: (value: string, options?: {
919
- readonly noResolve?: boolean;
920
- readonly includeSniffed?: never;
921
- } | undefined) => SurgeCondition;
922
- processName: (value: string, options?: {
923
- readonly noResolve?: boolean;
924
- readonly includeSniffed?: never;
925
- } | undefined) => SurgeCondition;
926
- macAddress: (value: string, options?: {
927
- readonly noResolve?: boolean;
928
- readonly includeSniffed?: never;
929
- } | undefined) => SurgeCondition;
930
- network: (value: "tcp" | "udp", options?: {
931
- readonly noResolve?: boolean;
932
- readonly includeSniffed?: never;
933
- }) => SurgeCondition;
934
- port: (from: number, to?: number, options?: {
935
- readonly noResolve?: boolean;
936
- readonly includeSniffed?: never;
937
- }) => SurgeCondition;
938
- sourcePort: (from: number, to?: number, options?: {
939
- readonly noResolve?: boolean;
940
- readonly includeSniffed?: never;
941
- }) => SurgeCondition;
942
- all: (conditions: readonly SurgeCondition[], options?: {
943
- readonly noResolve?: boolean;
944
- readonly includeSniffed?: never;
945
- }) => SurgeCondition;
946
- any: (conditions: readonly SurgeCondition[], options?: {
1033
+ }) => {
1034
+ noResolve?: boolean;
1035
+ includeSniffed?: never;
1036
+ type: "ipAsn";
1037
+ value: number;
1038
+ };
1039
+ ipCidr6: (value: string, options?: {
947
1040
  readonly noResolve?: boolean;
948
1041
  readonly includeSniffed?: never;
949
- }) => SurgeCondition;
950
- not: (value: SurgeCondition, options?: {
1042
+ }) => {
1043
+ readonly type: "ipCidr6";
1044
+ readonly value: string;
951
1045
  readonly noResolve?: boolean;
952
- readonly includeSniffed?: never;
953
- }) => SurgeCondition;
954
- ruleSet: (options: Omit<Extract<SurgeCondition, {
955
- type: "ruleSet";
956
- }>, "type">) => SurgeCondition;
957
- };
958
- smart: () => Extract<GroupAlgorithm, {
959
- type: "surge-smart";
960
- }>;
961
- ruleSet: {
962
- (input: Omit<NativeInput<"surge">, "format"> & {
963
- readonly format?: "rule-set" | "domain-set";
964
- } & {
965
- readonly to: ProfileDestination;
966
- }): RouteDefinition;
967
- (input: SurgeSetInput): {
968
- readonly type: "nativeRuleSet";
969
- readonly id: string;
970
- readonly url: string;
971
- } & {
972
- readonly engine: "surge";
973
- readonly format: "rule-set" | "domain-set";
974
- readonly intervalSeconds?: number;
975
- readonly noResolve?: boolean;
976
- readonly includeSniffed?: boolean;
977
1046
  };
978
- };
979
- };
980
- export declare const mihomo: {
981
- ruleSet: {
982
- (input: Omit<{
983
- readonly type: "nativeRuleSet";
984
- readonly id: string;
985
- readonly url: string;
986
- } & {
987
- readonly engine: "mihomo";
988
- readonly format: "yaml" | "text";
989
- readonly behavior: "domain" | "ipcidr" | "classical";
990
- readonly intervalSeconds: number;
991
- }, "engine" | "id" | "type"> & {
992
- readonly id?: string;
993
- } & {
994
- readonly to: ProfileDestination;
995
- }): RouteDefinition;
996
- (input: NativeInput<"mihomo">): {
997
- readonly type: "nativeRuleSet";
998
- readonly id: string;
999
- readonly url: string;
1000
- } & {
1001
- readonly engine: "mihomo";
1002
- readonly format: "yaml" | "text";
1003
- readonly behavior: "domain" | "ipcidr" | "classical";
1004
- readonly intervalSeconds: number;
1047
+ macAddress: (value: string) => {
1048
+ readonly type: "macAddress";
1049
+ readonly value: string;
1050
+ readonly noResolve?: boolean;
1005
1051
  };
1006
1052
  };
1007
- ruleProvider: {
1008
- (input: Omit<{
1009
- readonly type: "nativeRuleSet";
1010
- readonly id: string;
1011
- readonly url: string;
1012
- } & {
1013
- readonly engine: "mihomo";
1014
- readonly format: "yaml" | "text";
1015
- readonly behavior: "domain" | "ipcidr" | "classical";
1016
- readonly intervalSeconds: number;
1017
- }, "engine" | "id" | "type"> & {
1018
- readonly id?: string;
1019
- } & {
1020
- readonly to: ProfileDestination;
1021
- }): RouteDefinition;
1022
- (input: NativeInput<"mihomo">): {
1023
- readonly type: "nativeRuleSet";
1024
- readonly id: string;
1025
- readonly url: string;
1026
- } & {
1027
- readonly engine: "mihomo";
1028
- readonly format: "yaml" | "text";
1029
- readonly behavior: "domain" | "ipcidr" | "classical";
1030
- readonly intervalSeconds: number;
1031
- };
1053
+ ruleSets: {
1054
+ lan: {
1055
+ type: "ruleSet";
1056
+ id: "surge:lan";
1057
+ format: "rule-set";
1058
+ builtin: "LAN";
1059
+ } & SDK<"ruleSet">;
1060
+ system: {
1061
+ type: "ruleSet";
1062
+ id: "surge:system";
1063
+ format: "rule-set";
1064
+ builtin: "SYSTEM";
1065
+ } & SDK<"ruleSet">;
1032
1066
  };
1033
- };
1034
- export declare const proxy: {
1035
- builder: typeof proxyBuilder;
1036
- http: (options: Omit<HttpNode, "type">) => HttpNode;
1037
- trojan: (options: Omit<TrojanNode, "type">) => TrojanNode;
1038
- anytls: (options: Omit<AnyTLSNode, "type">) => AnyTLSNode;
1039
- hysteria2: (options: Omit<Hysteria2Node, "type">) => Hysteria2Node;
1040
- shadowsocks: (options: Omit<ShadowsocksNode, "type">) => ShadowsocksNode;
1041
- vmess: (options: Omit<VMessNode, "type">) => VMessNode;
1042
- vless: (options: Omit<VLESSNode, "type">) => VLESSNode;
1067
+ smart: () => {
1068
+ type: "surge-smart";
1069
+ } & SDK<"algorithm">;
1070
+ tailscale: (input: Input<{
1071
+ readonly type: "tailscale";
1072
+ readonly id: string;
1073
+ readonly sectionName: string;
1074
+ readonly authKey: SecretRef;
1075
+ readonly hostname: string;
1076
+ readonly dnsServer?: readonly string[] | undefined;
1077
+ readonly autoAddMagicDnsRule?: boolean | undefined;
1078
+ readonly idleKeepalive?: number | undefined;
1079
+ } & {
1080
+ readonly name?: string;
1081
+ } & SDK<"tunnel">>) => {
1082
+ readonly type: "tailscale";
1083
+ readonly id: string;
1084
+ readonly sectionName: string;
1085
+ readonly authKey: SecretRef;
1086
+ readonly hostname: string;
1087
+ readonly dnsServer?: readonly string[] | undefined;
1088
+ readonly autoAddMagicDnsRule?: boolean | undefined;
1089
+ readonly idleKeepalive?: number | undefined;
1090
+ } & {
1091
+ readonly name?: string;
1092
+ } & SDK<"tunnel">;
1093
+ wireguard: (input: Input<{
1094
+ readonly type: "wireguard";
1095
+ readonly id: string;
1096
+ readonly sectionName: string;
1097
+ readonly privateKey: SecretRef;
1098
+ readonly selfIp: string;
1099
+ readonly dnsServer?: readonly string[] | undefined;
1100
+ readonly mtu?: number | undefined;
1101
+ readonly peers: readonly {
1102
+ readonly publicKey: string;
1103
+ readonly endpoint: string;
1104
+ readonly allowedIps: readonly string[];
1105
+ readonly presharedKey?: SecretRef | undefined;
1106
+ readonly persistentKeepalive?: number | undefined;
1107
+ }[];
1108
+ } & {
1109
+ readonly name?: string;
1110
+ } & SDK<"tunnel">>) => {
1111
+ readonly type: "wireguard";
1112
+ readonly id: string;
1113
+ readonly sectionName: string;
1114
+ readonly privateKey: SecretRef;
1115
+ readonly selfIp: string;
1116
+ readonly dnsServer?: readonly string[] | undefined;
1117
+ readonly mtu?: number | undefined;
1118
+ readonly peers: readonly {
1119
+ readonly publicKey: string;
1120
+ readonly endpoint: string;
1121
+ readonly allowedIps: readonly string[];
1122
+ readonly presharedKey?: SecretRef | undefined;
1123
+ readonly persistentKeepalive?: number | undefined;
1124
+ }[];
1125
+ } & {
1126
+ readonly name?: string;
1127
+ } & SDK<"tunnel">;
1043
1128
  };
1044
1129
  export declare const singbox: {
1045
- ruleSet: {
1046
- (input: Omit<{
1047
- readonly type: "nativeRuleSet";
1048
- readonly id: string;
1049
- readonly url: string;
1050
- } & {
1051
- readonly engine: "sing-box";
1052
- readonly format: "source" | "binary";
1053
- readonly intervalSeconds: number;
1054
- readonly resolve?: boolean;
1055
- }, "engine" | "id" | "type"> & {
1056
- readonly id?: string;
1057
- } & {
1058
- readonly to: ProfileDestination;
1059
- }): RouteDefinition;
1060
- (input: NativeInput<"sing-box">): {
1061
- readonly type: "nativeRuleSet";
1062
- readonly id: string;
1063
- readonly url: string;
1064
- } & {
1065
- readonly engine: "sing-box";
1066
- readonly format: "source" | "binary";
1067
- readonly intervalSeconds: number;
1068
- readonly resolve?: boolean;
1069
- };
1070
- };
1071
- tailscale: (options: Omit<TailscaleEndpoint, "type">) => TailscaleEndpoint;
1130
+ tailscale: (input: Input<SingBoxEndpoint>) => SingBoxEndpoint;
1072
1131
  };
1073
1132
  //#endregion
1074
- //#region src/proxies.d.ts
1075
- export declare class RenderError extends Error {
1076
- readonly code: string;
1077
- constructor(code: string);
1078
- }
1079
- //#endregion
1080
- //#region src/render.d.ts
1081
- type Artifact = {
1082
- readonly target: string;
1083
- readonly filename: string;
1084
- readonly content: string;
1133
+ //#region src/authoring/secret-inputs.d.ts
1134
+ type Source = ({
1135
+ readonly env: string;
1136
+ readonly value?: never;
1137
+ } | {
1138
+ readonly value: string;
1139
+ readonly env?: never;
1140
+ }) & {
1141
+ readonly validation?: string;
1085
1142
  };
1086
- /** Secret resolution is once per token per batch, including across providers. */
1087
- export declare function render(compilation: Compilation, resolveSecret: (token: Secret) => string | undefined): readonly Artifact[];
1143
+ export declare function defineSecrets<const T extends Record<string, Source>>(input: T): Secrets<Extract<keyof T, string>>;
1088
1144
  //#endregion
1089
- //#region src/secrets.d.ts
1090
- type SecretFailure = {
1091
- readonly secretName?: string;
1092
- readonly secretReason?: "MISSING" | "RESOLUTION_FAILED";
1093
- };
1145
+ //#region src/authoring/proxy-id.d.ts
1146
+ /** Stable identity independent of engine and mutable metadata. */
1147
+ export declare function proxyId(namespace: string, name: string): string;
1094
1148
  //#endregion
1095
- //#region src/host.d.ts
1096
- type BuildResult = SecretFailure & {
1097
- readonly published: boolean;
1098
- readonly exitCode: 0 | 1 | 2;
1099
- readonly code: string;
1100
- readonly paths?: readonly string[];
1101
- readonly active?: string;
1102
- readonly generation?: string;
1103
- readonly reason?: "ACCESS_DENIED" | "NO_SPACE" | "READ_ONLY" | "INVALID_DIRECTORY" | "IO_ERROR";
1104
- readonly hint?: string;
1105
- };
1106
- /** All targets publish together by one active.json rename. Config files never go to stdout. */
1107
- export declare function buildToDirectory(compilation: Compilation, output: string, resolveSecret?: (token: Secret) => string | undefined): Promise<BuildResult>;
1149
+ //#region src/model/build-types.d.ts
1150
+ type BuildDefinition = {
1151
+ readonly outDir?: string;
1152
+ readonly profiles: Readonly<Record<string, Profile>>;
1153
+ readonly secrets?: Secrets;
1154
+ } & SDK<"build">;
1108
1155
  //#endregion
1109
- //#region src/strategies.d.ts
1110
- type StrategyGroupInput = {
1111
- readonly target: {
1112
- readonly engine: Engine;
1113
- readonly platform: "macos" | "linux";
1114
- readonly version: string;
1115
- };
1116
- readonly nodes: readonly {
1117
- readonly id: string;
1118
- readonly nativeName: string;
1119
- }[];
1120
- readonly strategies: readonly Strategy[];
1121
- readonly names?: Readonly<Record<string, string>>;
1122
- };
1123
- type StrategyGroupCompilation = {
1124
- readonly ok: boolean;
1125
- readonly artifactKind: "strategy-groups";
1126
- readonly diagnostics: readonly Diagnostic[];
1127
- readonly selections: readonly StrategySelection[];
1128
- readonly content: string | null;
1129
- };
1130
- /** Only group topology/encoding is checked here; nodes, via, protocols and routes remain consumer-owned. */
1131
- export declare function compileStrategyGroups(input: unknown): StrategyGroupCompilation;
1156
+ //#region src/authoring/build.d.ts
1157
+ /** Capture the immutable batch before any secret source is invoked. */
1158
+ export declare function defineBuild(input: Omit<BuildDefinition, keyof SDK<"build">>): BuildDefinition;
1132
1159
  //#endregion
1133
- //#region src/rules.d.ts
1134
- export declare class StaticRuleSetUnknownError extends Error {
1135
- constructor();
1160
+ //#region src/model/definitions.d.ts
1161
+ export declare class ProfileDefinitionError extends Error {
1162
+ readonly code: string;
1163
+ readonly paths?: readonly string[];
1164
+ readonly origin?: Origin;
1165
+ constructor(code: string, paths?: readonly string[]);
1136
1166
  }
1137
1167
  //#endregion
1138
- //#region src/proxy-fragments.d.ts
1139
- type ProxyNodeInput = {
1140
- readonly target: {
1141
- readonly engine: "surge";
1142
- readonly platform: "macos";
1143
- readonly version: "6.10.0";
1144
- };
1145
- readonly nodes: readonly ProxyNode[];
1146
- readonly names?: Readonly<Record<string, string>>;
1147
- readonly externals?: readonly {
1148
- readonly id: string;
1149
- readonly nativeName: string;
1150
- readonly kind: "proxy" | "group";
1151
- }[];
1152
- };
1153
- type ProxyNodeCompilation = {
1154
- readonly ok: boolean;
1155
- readonly artifactKind: "proxy-nodes";
1156
- readonly diagnostics: readonly Diagnostic[];
1157
- readonly bindings: readonly {
1158
- readonly id: string;
1159
- readonly nativeName: string;
1160
- }[];
1161
- readonly requirements: readonly {
1162
- readonly id: string;
1163
- readonly nativeName: string;
1164
- readonly kind: "proxy" | "group";
1165
- readonly usedBy: readonly string[];
1166
- }[];
1167
- };
1168
- type ProxyNodeArtifact = {
1169
- readonly artifactKind: "proxy-nodes";
1170
- readonly content: string;
1171
- readonly entries: readonly {
1172
- readonly id: string;
1173
- readonly content: string;
1174
- }[];
1168
+ //#region src/authoring/index.d.ts
1169
+ export type HttpNode = Extract<ProxyNode, {
1170
+ type: "http";
1171
+ }>;
1172
+ export type TrojanNode = Extract<ProxyNode, {
1173
+ type: "trojan";
1174
+ }>;
1175
+ export type AnyTLSNode = Extract<ProxyNode, {
1176
+ type: "anytls";
1177
+ }>;
1178
+ export type Hysteria2Node = Extract<ProxyNode, {
1179
+ type: "hysteria2";
1180
+ }>;
1181
+ export type ShadowsocksNode = Extract<ProxyNode, {
1182
+ type: "shadowsocks";
1183
+ }>;
1184
+ export type VMessNode = Extract<ProxyNode, {
1185
+ type: "vmess";
1186
+ }>;
1187
+ export type VLESSNode = Extract<ProxyNode, {
1188
+ type: "vless";
1189
+ }>;
1190
+ //#endregion
1191
+ //#region src/model/inspect-profile.d.ts
1192
+ type Selection = {
1193
+ kind: "name";
1194
+ resource: string;
1195
+ nativeName: string;
1196
+ } | {
1197
+ kind: "algorithm";
1198
+ group: string;
1199
+ algorithm: "surge-smart" | "urltest";
1200
+ parameters?: object;
1201
+ } | {
1202
+ kind: "ruleSet";
1203
+ ruleSet: string;
1204
+ branch: "surge" | "singBox" | "mihomo";
1205
+ nativeName: string;
1175
1206
  };
1176
- export declare function compileProxyNodes(input: unknown): ProxyNodeCompilation;
1177
- export declare function renderProxyNodes(compilation: ProxyNodeCompilation, resolveSecret: (token: Secret) => string | undefined): ProxyNodeArtifact;
1178
1207
  //#endregion
1179
- //#region src/profile-build.d.ts
1180
- type ProfileCheckResult = {
1208
+ //#region src/build/explain.d.ts
1209
+ export declare function explainProfile(profile: Profile, request: RouteRequest, assume?: Assumptions): ExplainResult;
1210
+ //#endregion
1211
+ //#region src/build/index.d.ts
1212
+ type CheckResult = {
1181
1213
  readonly ok: boolean;
1182
- readonly code: string;
1183
- readonly profileCount: number;
1214
+ readonly code: "CHECKED" | "CHECK_FAILED" | "CASE_FAILED";
1184
1215
  readonly outputDirectoryChecked: boolean;
1185
1216
  readonly profiles: readonly {
1186
- readonly id: string;
1187
- readonly engine: "surge" | "sing-box" | "invalid";
1217
+ readonly key: string;
1218
+ readonly target: Target;
1188
1219
  readonly ok: boolean;
1189
- readonly code?: string;
1190
- readonly paths?: readonly string[];
1191
- readonly diagnostics: readonly Diagnostic[];
1220
+ readonly diagnostics: readonly ProfileDiagnostic[];
1221
+ readonly selections: readonly Selection[];
1192
1222
  }[];
1223
+ readonly cases: readonly CaseResult[];
1193
1224
  };
1194
- export declare function checkBuild(input: BuildDefinition): ProfileCheckResult;
1195
- type BuildContext = {
1196
- readonly validation: boolean;
1197
- };
1198
- type BuildDefinition = {
1199
- readonly outDir?: string;
1200
- readonly profiles: Readonly<Record<string, Profile | ProfileDefinition>>;
1201
- readonly preflight?: () => readonly string[];
1202
- readonly secrets?: (token: Secret, context: BuildContext) => string | undefined;
1203
- };
1204
- type ProfileBuildResult = BuildResult & {
1205
- readonly warnings: Readonly<Record<string, number>>;
1206
- readonly validation: boolean;
1207
- readonly profileCount: number;
1225
+ type BuildResult = {
1226
+ readonly published: boolean;
1227
+ readonly exitCode: 0 | 1 | 2;
1228
+ readonly code: string;
1229
+ readonly check: CheckResult;
1230
+ readonly active?: string;
1231
+ readonly hint?: string;
1232
+ readonly secretName?: string;
1208
1233
  };
1209
- /** Capture data and callback references before application preflight can change its source. */
1210
- export declare function defineBuild(input: BuildDefinition): BuildDefinition;
1211
- /** Pure orchestration result; the CLI owns stdout and process exit status. */
1212
- export declare function runBuild(input: BuildDefinition, output: string, options?: {
1234
+ export declare function checkBuild(definition: BuildDefinition): CheckResult;
1235
+ export declare function runBuild(definition: BuildDefinition, options?: {
1213
1236
  readonly validation?: boolean;
1214
- }): Promise<ProfileBuildResult>;
1215
- //#endregion
1216
- //#region src/proxy-id.d.ts
1217
- /** Stable identity independent of engine and mutable metadata. */
1218
- export declare function proxyId(namespace: string, label: string): string;
1219
- //#endregion
1220
- //#region src/secret-inputs.d.ts
1221
- type SecretsInput = {
1222
- readonly values?: Readonly<Record<string, string>>;
1223
- readonly env?: readonly string[];
1224
- readonly validation?: Readonly<Record<string, string>>;
1225
- };
1226
- /** Capture declarations now; read only referenced, allowed environment names at render time. */
1227
- export declare function secrets(input: SecretsInput, environment?: Readonly<Record<string, string | undefined>>): (token: Secret, context?: BuildContext) => string | undefined;
1237
+ }): Promise<BuildResult>;
1228
1238
  //#endregion
1229
- export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly, Fragments, Profile, ProfileBuildResult, ProfileCheckResult, ProfileCompilation, ProfileCondition, ProfileDefinition, ProfileDestination, ProfileProxy, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, SecretsInput, StrategyGroupCompilation, StrategyGroupInput, SurgeCondition, SurgeConfig, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };
1239
+ export type { Assumptions, BuildDefinition, BuildResult, CaseResult, CheckResult, Condition, ProfileDiagnostic as Diagnostic, DnsRule, Exit, ExplainResult, Explanation, Fragments, GroupAlgorithm, Need, Origin, Profile, ProfileDefinition, ProxyBuilder, ProxyGroup, ProxyNode, Route, RouteCase, RouteRequest, RuleSet, SecretRef, Secrets, Selection, SingBoxEndpoint, SurgeGeneral, SurgeHost, SurgeTunnel, Target };