@openlimiter/core 0.4.0 → 1.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.
Files changed (68) hide show
  1. package/dist/acquire/antigravity-probe.d.ts +139 -0
  2. package/dist/acquire/antigravity-probe.d.ts.map +1 -0
  3. package/dist/acquire/antigravity-probe.js +599 -0
  4. package/dist/acquire/antigravity-probe.js.map +1 -0
  5. package/dist/acquire/cadence.d.ts +74 -0
  6. package/dist/acquire/cadence.d.ts.map +1 -0
  7. package/dist/acquire/cadence.js +171 -0
  8. package/dist/acquire/cadence.js.map +1 -0
  9. package/dist/acquire/coordination.d.ts +157 -0
  10. package/dist/acquire/coordination.d.ts.map +1 -0
  11. package/dist/acquire/coordination.js +292 -0
  12. package/dist/acquire/coordination.js.map +1 -0
  13. package/dist/acquire/credentials.d.ts +113 -0
  14. package/dist/acquire/credentials.d.ts.map +1 -0
  15. package/dist/acquire/credentials.js +316 -0
  16. package/dist/acquire/credentials.js.map +1 -0
  17. package/dist/acquire/identity.d.ts +20 -0
  18. package/dist/acquire/identity.d.ts.map +1 -0
  19. package/dist/acquire/identity.js +20 -0
  20. package/dist/acquire/identity.js.map +1 -0
  21. package/dist/acquire/index.d.ts +10 -0
  22. package/dist/acquire/index.d.ts.map +1 -0
  23. package/dist/acquire/index.js +10 -0
  24. package/dist/acquire/index.js.map +1 -0
  25. package/dist/acquire/providers.d.ts +86 -0
  26. package/dist/acquire/providers.d.ts.map +1 -0
  27. package/dist/acquire/providers.js +175 -0
  28. package/dist/acquire/providers.js.map +1 -0
  29. package/dist/acquire/runner.d.ts +146 -0
  30. package/dist/acquire/runner.d.ts.map +1 -0
  31. package/dist/acquire/runner.js +345 -0
  32. package/dist/acquire/runner.js.map +1 -0
  33. package/dist/acquire/transport.d.ts +194 -0
  34. package/dist/acquire/transport.d.ts.map +1 -0
  35. package/dist/acquire/transport.js +434 -0
  36. package/dist/acquire/transport.js.map +1 -0
  37. package/dist/acquire/windows-credential.d.ts +74 -0
  38. package/dist/acquire/windows-credential.d.ts.map +1 -0
  39. package/dist/acquire/windows-credential.js +124 -0
  40. package/dist/acquire/windows-credential.js.map +1 -0
  41. package/dist/cache.d.ts +28 -0
  42. package/dist/cache.d.ts.map +1 -1
  43. package/dist/cache.js +179 -25
  44. package/dist/cache.js.map +1 -1
  45. package/dist/connection-state.d.ts +53 -2
  46. package/dist/connection-state.d.ts.map +1 -1
  47. package/dist/connection-state.js +98 -9
  48. package/dist/connection-state.js.map +1 -1
  49. package/dist/failures.d.ts +2 -1
  50. package/dist/failures.d.ts.map +1 -1
  51. package/dist/failures.js +7 -3
  52. package/dist/failures.js.map +1 -1
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +1 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/merge.d.ts.map +1 -1
  58. package/dist/merge.js +17 -1
  59. package/dist/merge.js.map +1 -1
  60. package/dist/normalizer.d.ts +2 -0
  61. package/dist/normalizer.d.ts.map +1 -1
  62. package/dist/normalizer.js +39 -4
  63. package/dist/normalizer.js.map +1 -1
  64. package/dist/types.d.ts +63 -1
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/types.js +22 -0
  67. package/dist/types.js.map +1 -1
  68. package/package.json +3 -2
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The Antigravity loopback probe.
3
+ *
4
+ * Antigravity quota is served live by a running agy process on a loopback port.
5
+ * It speaks Connect protocol (POST with Connect-Protocol-Version: 1) and
6
+ * answers RetrieveUserQuotaSummary over loopback HTTPS with a self-signed
7
+ * certificate. When an agy process is alive on this machine, probing this
8
+ * loopback endpoint gives an honest, authoritative reading with zero cloud
9
+ * impersonation.
10
+ *
11
+ * When no agy process is running, this probe reports that fact plainly and
12
+ * never attempts to spawn agy.
13
+ */
14
+ import type { ConnectorLabels, RawMeter } from "../types.js";
15
+ import type { CredentialCommandRunner } from "./windows-credential.js";
16
+ import type { CredentialLookupOptions } from "./credentials.js";
17
+ export declare const AGY_QUOTA_PATH = "/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary";
18
+ export declare const AGY_NOT_RUNNING_SENTENCE = "Open Antigravity once to refresh";
19
+ export declare const AGY_PROBE_TIMEOUT_MILLISECONDS = 3000;
20
+ export declare const MAX_AGY_RESPONSE_BYTES: number;
21
+ export declare const TOTAL_AGY_PROBE_DEADLINE_MS = 5000;
22
+ export declare const ANTIGRAVITY_PROBE_LABELS: ConnectorLabels;
23
+ export interface AgyBucketPayload {
24
+ readonly bucketId?: string;
25
+ readonly displayName?: string;
26
+ readonly window?: string;
27
+ readonly remainingFraction?: number;
28
+ readonly resetTime?: string;
29
+ }
30
+ export interface AgyGroupPayload {
31
+ readonly buckets?: readonly AgyBucketPayload[];
32
+ }
33
+ export interface AgyQuotaSummaryPayload {
34
+ readonly response?: {
35
+ readonly groups?: readonly AgyGroupPayload[];
36
+ };
37
+ readonly groups?: readonly AgyGroupPayload[];
38
+ }
39
+ export interface AntigravityProbeSuccess {
40
+ readonly ok: true;
41
+ readonly meters: readonly RawMeter[];
42
+ }
43
+ export interface AntigravityProbeFailure {
44
+ readonly ok: false;
45
+ readonly reason: "not_running" | "unreachable" | "invalid_response";
46
+ }
47
+ export type AntigravityProbeResult = AntigravityProbeSuccess | AntigravityProbeFailure;
48
+ export interface AntigravityProbeOptions {
49
+ readonly now?: string;
50
+ readonly lookup?: CredentialLookupOptions;
51
+ readonly runCommand?: CredentialCommandRunner;
52
+ readonly resolveExecutablePath?: (pid: string) => Promise<string | null>;
53
+ readonly enumeratePorts?: () => Promise<readonly number[]>;
54
+ readonly probePort?: (port: number) => Promise<unknown | null>;
55
+ readonly totalDeadlineMs?: number;
56
+ }
57
+ export interface EnumerateAgyPortsOptions {
58
+ readonly platform?: NodeJS.Platform;
59
+ readonly runCommand?: CredentialCommandRunner;
60
+ readonly resolveExecutablePath?: (pid: string) => Promise<string | null>;
61
+ readonly env?: NodeJS.ProcessEnv;
62
+ }
63
+ /**
64
+ * Parse the Connect protocol RetrieveUserQuotaSummary response.
65
+ *
66
+ * Maps gemini-5h to FIVE_HOUR (18,000s) and gemini-weekly to SEVEN_DAY (604,800s).
67
+ * Percentage is rounded to 1 decimal place: (1 - remainingFraction) * 100.
68
+ */
69
+ export declare function parseAgyQuotaSummary(payload: unknown, now: string): readonly RawMeter[] | null;
70
+ /**
71
+ * Resolve a pid to the absolute path of the executable running it, the one
72
+ * piece of proof `isTrustedAgyExecutable` actually checks.
73
+ *
74
+ * Windows' own `tasklist` names a process but never its path, so a caller
75
+ * stuck on that fallback (CIM itself already carries a path, see
76
+ * `enumerateAgyListeningPorts`) has nothing to verify a candidate against but
77
+ * the bare string "agy.exe", which is exactly the name an impostor process
78
+ * picks for itself. This asks Windows the same question CIM already answers,
79
+ * for one pid at a time; POSIX reads `/proc/<pid>/exe`'s own symlink on
80
+ * Linux, where the kernel itself is the source of truth, and asks `ps` on
81
+ * every other POSIX platform. A pid whose executable cannot be read this way
82
+ * answers null, which every caller here treats as "cannot be trusted", never
83
+ * as "trust it anyway".
84
+ */
85
+ export declare function resolveAgyExecutablePath(pid: string, platform?: NodeJS.Platform, runCommand?: (executable: string, args: readonly string[], timeout: number) => Promise<{
86
+ ok: true;
87
+ stdout: string;
88
+ } | {
89
+ ok: false;
90
+ }>): Promise<string | null>;
91
+ /**
92
+ * Extract loopback port from an address string (e.g. "127.0.0.1:57737" or "[::1]:57737").
93
+ */
94
+ export declare function parseLoopbackPort(address: string): number | null;
95
+ /**
96
+ * Language-agnostic Windows netstat parser.
97
+ *
98
+ * Windows netstat lines have 5 whitespace-delimited tokens:
99
+ * Protocol, Local Address, Foreign Address, State, PID.
100
+ * A listening socket always has a wildcard foreign address (0.0.0.0:0, [::]:0, *:*).
101
+ * Matching this wildcard avoids relying on English "LISTENING" or "TCP".
102
+ */
103
+ export declare function parseNetstatPorts(report: string, pids: ReadonlySet<string> | readonly string[]): readonly number[];
104
+ /**
105
+ * Parse output from lsof, handling both standard tabular output and "-F pn" output.
106
+ */
107
+ export declare function parseLsofOutput(output: string): Array<{
108
+ pid: string;
109
+ port: number;
110
+ }>;
111
+ /**
112
+ * Valid install roots where legitimate software binaries are located.
113
+ */
114
+ export declare function getAgyInstallRoots(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): readonly string[];
115
+ /**
116
+ * Validate that an executable path is trusted:
117
+ * 1. Absolute path, no parent traversal ("..")
118
+ * 2. Named agy.exe (Windows) or agy (non-Windows)
119
+ * 3. Resides under one of the legitimate install roots
120
+ */
121
+ export declare function isTrustedAgyExecutable(executablePath: string, platform?: NodeJS.Platform, roots?: readonly string[]): boolean;
122
+ /**
123
+ * Enumerate listening loopback ports belonging to running agy processes.
124
+ */
125
+ export declare function enumerateAgyListeningPorts(options?: EnumerateAgyPortsOptions): Promise<readonly number[]>;
126
+ /**
127
+ * Probe an agy loopback port for quota summary.
128
+ * Attempts HTTPS with self-signed certificate acceptance first, then plain HTTP.
129
+ */
130
+ export declare function probeAgyLoopback(port: number, timeoutMs?: number, signal?: AbortSignal): Promise<unknown | null>;
131
+ /**
132
+ * Run the Antigravity probe:
133
+ * 1. Discover listening ports for running agy processes.
134
+ * 2. If no processes found, report "not_running".
135
+ * 3. Probe loopback ports and parse quota summary.
136
+ * Enforces a hard total deadline across all ports probed.
137
+ */
138
+ export declare function probeAntigravity(options?: AntigravityProbeOptions): Promise<AntigravityProbeResult>;
139
+ //# sourceMappingURL=antigravity-probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"antigravity-probe.d.ts","sourceRoot":"","sources":["../../src/acquire/antigravity-probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE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