@radheim/client 0.0.0-stage → 2.4.3

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 (100) hide show
  1. package/README.md +27 -3
  2. package/dist/chunks/contract-0d78mgf1.js +52 -0
  3. package/dist/chunks/contract-20jd153t.js +2089 -0
  4. package/dist/chunks/contract-2h09qg7t.js +62 -0
  5. package/dist/chunks/contract-5f99ddep.js +149 -0
  6. package/dist/chunks/contract-6mptkzbc.js +0 -0
  7. package/dist/chunks/contract-6mq2wh8y.js +33 -0
  8. package/dist/chunks/contract-6r38tsk5.js +0 -0
  9. package/dist/chunks/contract-6sr7f8yw.js +92 -0
  10. package/dist/chunks/contract-850x4mfy.js +948 -0
  11. package/dist/chunks/contract-8s2anffy.js +11 -0
  12. package/dist/chunks/contract-96mz1w8q.js +104 -0
  13. package/dist/chunks/contract-9rqn6x4v.js +16 -0
  14. package/dist/chunks/contract-d9s8wkgw.js +2082 -0
  15. package/dist/chunks/contract-mn9bt8t4.js +4 -0
  16. package/dist/chunks/contract-mwrzahmf.js +38 -0
  17. package/dist/chunks/contract-n4yq1n4a.js +111 -0
  18. package/dist/chunks/contract-nwcpakzx.js +12 -0
  19. package/dist/chunks/contract-qav6mfdz.js +0 -0
  20. package/dist/chunks/contract-qtt7zwr0.js +30 -0
  21. package/dist/chunks/contract-rhrawkx2.js +49 -0
  22. package/dist/chunks/contract-rrraq56y.js +67 -0
  23. package/dist/chunks/contract-sxt88q69.js +12 -0
  24. package/dist/chunks/contract-t5nrycbt.js +39 -0
  25. package/dist/chunks/contract-vyas3vgt.js +0 -0
  26. package/dist/chunks/contract-xgnj2w4v.js +20 -0
  27. package/dist/chunks/contract-y2etg5bs.js +9 -0
  28. package/dist/chunks/contract-ydhz1zrh.js +238 -0
  29. package/dist/chunks/contract-ztxd8xjp.js +81 -0
  30. package/dist/contract.d.ts +1 -0
  31. package/dist/contract.js +14 -0
  32. package/dist/effect/api/api.d.ts +3744 -0
  33. package/dist/effect/api/api.js +0 -0
  34. package/dist/effect/api.d.ts +5 -0
  35. package/dist/effect/api.js +0 -0
  36. package/dist/effect/client.d.ts +3129 -0
  37. package/dist/effect/client.js +15 -0
  38. package/dist/effect/generated/client-error.d.ts +7 -0
  39. package/dist/effect/generated/client-error.js +6 -0
  40. package/dist/effect/generated/client.d.ts +3158 -0
  41. package/dist/effect/generated/client.js +8 -0
  42. package/dist/effect/generated/index.d.ts +2 -0
  43. package/dist/effect/generated/index.js +12 -0
  44. package/dist/effect/index.d.ts +35 -0
  45. package/dist/effect/index.js +75 -0
  46. package/dist/effect/rpc.d.ts +20 -0
  47. package/dist/effect/rpc.js +11 -0
  48. package/dist/effect/service.d.ts +90 -0
  49. package/dist/effect/service.js +187 -0
  50. package/dist/mcp.d.ts +44 -0
  51. package/dist/mcp.js +110 -0
  52. package/dist/promise/api.d.ts +25 -0
  53. package/dist/promise/api.js +0 -0
  54. package/dist/promise/client.d.ts +414 -0
  55. package/dist/promise/client.js +14 -0
  56. package/dist/promise/generated/client-error.d.ts +8 -0
  57. package/dist/promise/generated/client-error.js +6 -0
  58. package/dist/promise/generated/client.d.ts +456 -0
  59. package/dist/promise/generated/client.js +7 -0
  60. package/dist/promise/generated/index.d.ts +3 -0
  61. package/dist/promise/generated/index.js +105 -0
  62. package/dist/promise/generated/types.d.ts +6642 -0
  63. package/dist/promise/generated/types.js +96 -0
  64. package/dist/promise/index.d.ts +8 -0
  65. package/dist/promise/index.js +115 -0
  66. package/dist/promise/media.d.ts +424 -0
  67. package/dist/promise/media.js +8 -0
  68. package/dist/promise/rpc.d.ts +32 -0
  69. package/dist/promise/rpc.js +7 -0
  70. package/dist/promise/service.d.ts +24 -0
  71. package/dist/promise/service.js +188 -0
  72. package/dist/pty-handoff.d.ts +12 -0
  73. package/dist/pty-handoff.js +17 -0
  74. package/dist/rpc-runtime.d.ts +20 -0
  75. package/dist/rpc-runtime.js +14 -0
  76. package/dist/service-contender.d.ts +37 -0
  77. package/dist/service-contender.js +10 -0
  78. package/dist/service-probe.d.ts +74 -0
  79. package/dist/service-probe.js +16 -0
  80. package/dist/service-timing.d.ts +12 -0
  81. package/dist/service-timing.js +10 -0
  82. package/dist/service-version.d.ts +2 -0
  83. package/dist/service-version.js +6 -0
  84. package/dist/service.d.ts +52 -0
  85. package/dist/service.js +1 -0
  86. package/dist/shared-events.d.ts +16 -0
  87. package/dist/shared-events.js +8 -0
  88. package/dist/solid/connection.d.ts +37 -0
  89. package/dist/solid/connection.js +10 -0
  90. package/dist/solid/data.d.ts +238 -0
  91. package/dist/solid/data.js +19 -0
  92. package/dist/solid/index.d.ts +5 -0
  93. package/dist/solid/index.js +45 -0
  94. package/dist/solid/pty.d.ts +80 -0
  95. package/dist/solid/pty.js +12 -0
  96. package/dist/solid/retention.d.ts +10 -0
  97. package/dist/solid/retention.js +6 -0
  98. package/dist/solid/usage.d.ts +9 -0
  99. package/dist/solid/usage.js +6 -0
  100. package/package.json +89 -4
@@ -0,0 +1,188 @@
1
+ import {
2
+ spawnServiceContender2,
3
+ contenderPool2
4
+ } from "../chunks/contract-96mz1w8q.js";
5
+ import {
6
+ defaultEnsureTiming2,
7
+ ensureTiming2
8
+ } from "../chunks/contract-xgnj2w4v.js";
9
+ import {
10
+ matchesVersion2
11
+ } from "../chunks/contract-sxt88q69.js";
12
+ import {
13
+ decide2,
14
+ fallback2,
15
+ same2,
16
+ probeResult2,
17
+ headers2
18
+ } from "../chunks/contract-6sr7f8yw.js";
19
+ import {
20
+ prepare2,
21
+ environment2,
22
+ complete2,
23
+ clear2
24
+ } from "../chunks/contract-n4yq1n4a.js";
25
+ import"../chunks/contract-qav6mfdz.js";
26
+
27
+ // src/promise/service.ts
28
+ import { readFile, rm } from "node:fs/promises";
29
+ async function discover(options = {}) {
30
+ const found = (await registered(options.file)).service;
31
+ if (found?.state !== "ready")
32
+ return;
33
+ if (!found.compatible)
34
+ return;
35
+ if (!matchesVersion2(found.version, options))
36
+ return;
37
+ return found.endpoint;
38
+ }
39
+ async function ensure(options = {}) {
40
+ const timing = ensureTiming2(options);
41
+ const deadline = Date.now() + timing.promiseTimeout;
42
+ const pool = contenderPool2(timing);
43
+ let timeouts;
44
+ let announced = false;
45
+ const announce = (reason, previousVersion) => {
46
+ if (announced)
47
+ return;
48
+ announced = true;
49
+ options.onStart?.(reason, previousVersion);
50
+ };
51
+ const spawnContender = async () => {
52
+ const [command, ...args] = options.command ?? ["opencode", "serve", "--service"];
53
+ if (command === undefined)
54
+ throw new Error("Missing service command");
55
+ try {
56
+ return spawnServiceContender2(command, args, await environment2(options.file ?? fallback2(), options.env));
57
+ } catch (cause) {
58
+ throw new Error("Failed to start server", { cause });
59
+ }
60
+ };
61
+ try {
62
+ while (true) {
63
+ if (Date.now() >= deadline)
64
+ throw pool.failure() ?? new Error("Timed out waiting for the background service to start");
65
+ const registration = await registered(options.file, timing.requestTimeout);
66
+ if (registration.timedOut && registration.info !== undefined) {
67
+ timeouts = {
68
+ info: registration.info,
69
+ count: timeouts !== undefined && same2(timeouts.info, registration.info) ? timeouts.count + 1 : 1
70
+ };
71
+ if (timeouts.count >= 3) {
72
+ announce("missing");
73
+ console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
74
+ await clear2(options.file ?? fallback2());
75
+ await terminate(registration.info, options, timing);
76
+ pool.evict(registration.info.pid);
77
+ pool.recruitNow();
78
+ timeouts = undefined;
79
+ }
80
+ } else
81
+ timeouts = undefined;
82
+ if (registration.service !== undefined) {
83
+ pool.serviceAnswered();
84
+ const service2 = registration.service;
85
+ const decision = decide2(service2, options);
86
+ if (decision._tag === "fail")
87
+ throw decision.error;
88
+ if (decision._tag === "reuse") {
89
+ await complete2(options.file ?? fallback2(), service2.info);
90
+ return service2.endpoint;
91
+ }
92
+ if (decision._tag === "replace") {
93
+ announce("version-mismatch", service2.version);
94
+ if (service2.state !== "ready")
95
+ console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
96
+ await stop({ file: options.file, pty: decision.pty }).catch(() => {
97
+ return;
98
+ });
99
+ pool.evict(service2.info.pid);
100
+ }
101
+ } else {
102
+ const failed = pool.reap();
103
+ if (failed !== undefined)
104
+ throw failed;
105
+ if (pool.shouldRecruit(registration.info !== undefined)) {
106
+ announce("missing");
107
+ pool.add(await spawnContender());
108
+ }
109
+ }
110
+ await delay(timing.pollInterval);
111
+ }
112
+ } finally {
113
+ pool.releaseAll();
114
+ }
115
+ }
116
+ async function stop(options = {}) {
117
+ const info = await read(options.file);
118
+ await (options.pty === "handoff" && info !== undefined ? prepare2(options.file ?? fallback2(), info, defaultEnsureTiming2.requestTimeout) : clear2(options.file ?? fallback2())).catch((cause) => console.warn("Failed to prepare persistent terminals for replacement", cause));
119
+ if (info !== undefined)
120
+ await terminate(info, options, ensureTiming2(options));
121
+ }
122
+ async function read(file) {
123
+ const text = await readFile(file ?? fallback2(), "utf8").catch(() => {
124
+ return;
125
+ });
126
+ if (text === undefined)
127
+ return;
128
+ try {
129
+ return JSON.parse(text);
130
+ } catch {
131
+ return;
132
+ }
133
+ }
134
+ async function registered(file, timeout) {
135
+ const info = await read(file);
136
+ if (info === undefined)
137
+ return { info: undefined, service: undefined, timedOut: false };
138
+ return { info, ...await probeResult2(info, timeout) };
139
+ }
140
+ function signal(pid, name) {
141
+ try {
142
+ process.kill(pid, name);
143
+ } catch {}
144
+ }
145
+ function stopped(pid) {
146
+ try {
147
+ process.kill(pid, 0);
148
+ return false;
149
+ } catch {
150
+ return true;
151
+ }
152
+ }
153
+ async function waitUntilStopped(pid, timing) {
154
+ for (let attempt = 0;attempt <= timing.stopPollAttempts; attempt++) {
155
+ if (stopped(pid))
156
+ return true;
157
+ if (attempt < timing.stopPollAttempts)
158
+ await delay(timing.stopPollInterval);
159
+ }
160
+ return false;
161
+ }
162
+ async function terminate(info, options, timing) {
163
+ const current = await read(options.file);
164
+ if (current === undefined || !same2(current, info))
165
+ return;
166
+ signal(info.pid, "SIGTERM");
167
+ if (!await waitUntilStopped(info.pid, timing)) {
168
+ signal(info.pid, "SIGKILL");
169
+ if (!await waitUntilStopped(info.pid, timing))
170
+ throw new Error(`Server process ${info.pid} is still running`);
171
+ }
172
+ const latest = await read(options.file);
173
+ if (latest === undefined || !same2(latest, info))
174
+ return;
175
+ await rm(options.file ?? fallback2(), { force: true });
176
+ }
177
+ function delay(milliseconds) {
178
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
179
+ }
180
+ var Service = { discover, ensure, stop, headers: headers2 };
181
+ export {
182
+ Service,
183
+ discover,
184
+ ensure,
185
+ fallback2 as fallback,
186
+ headers2 as headers,
187
+ stop
188
+ };
@@ -0,0 +1,12 @@
1
+ export * as PtyHandoff from "./pty-handoff.js";
2
+ import type { Info } from "./service.js";
3
+ /**
4
+ * Publish the ticket before stopping its owner so every replacement contender can adopt it.
5
+ * Never throws: terminals are best-effort, so any failure replaces the service without a handoff.
6
+ */
7
+ export declare function prepare(file: string, info: Info, timeout: number): Promise<void>;
8
+ export declare function environment(file: string, env?: Readonly<Record<string, string>>): Promise<{
9
+ OPENCODE_PTY_HANDOFF: string | undefined;
10
+ }>;
11
+ export declare function complete(file: string, info: Info): Promise<void>;
12
+ export declare function clear(file: string): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import {
2
+ prepare2,
3
+ environment2,
4
+ complete2,
5
+ clear2,
6
+ exports_pty_handoff
7
+ } from "./chunks/contract-n4yq1n4a.js";
8
+ import"./chunks/contract-6sr7f8yw.js";
9
+ import"./chunks/contract-xgnj2w4v.js";
10
+ import"./chunks/contract-sxt88q69.js";
11
+ export {
12
+ exports_pty_handoff as PtyHandoff,
13
+ clear2 as clear,
14
+ complete2 as complete,
15
+ environment2 as environment,
16
+ prepare2 as prepare
17
+ };
@@ -0,0 +1,20 @@
1
+ export * as RpcRuntime from "./rpc-runtime.js";
2
+ import type { Rpc } from "@radheim/schema/rpc";
3
+ import { Effect, Schema } from "effect";
4
+ export declare function read(schema: Rpc.Method["output"], value: unknown): Effect.Effect<unknown, Schema.SchemaError, never>;
5
+ export declare function readError(method: Rpc.Method, error: unknown): Effect.Effect<never, unknown>;
6
+ export declare const event: <D extends Rpc.Definition, Name extends keyof D["events"] & string>(definition: D, name: Name, schema: Rpc.EventDefinition, event: {
7
+ readonly id: string & import("effect/Brand").Brand<"Event.ID">;
8
+ readonly created: number;
9
+ readonly metadata?: {
10
+ readonly [x: string]: unknown;
11
+ } | undefined;
12
+ readonly type: `rpc.${string}`;
13
+ readonly location: {
14
+ readonly directory: string & import("effect/Brand").Brand<"AbsolutePath">;
15
+ };
16
+ readonly data: {
17
+ readonly [x: string]: unknown;
18
+ };
19
+ }) => Effect.Effect<Rpc.EventPayload<D, Name>, unknown, never>;
20
+ export declare function eventType<const D extends Rpc.Definition, const Name extends keyof D["events"] & string>(definition: D, name: Name): `rpc.${D["id"]}.${Name}`;
@@ -0,0 +1,14 @@
1
+ import {
2
+ read2,
3
+ readError2,
4
+ event2,
5
+ eventType2,
6
+ exports_rpc_runtime
7
+ } from "./chunks/contract-t5nrycbt.js";
8
+ export {
9
+ exports_rpc_runtime as RpcRuntime,
10
+ event2 as event,
11
+ eventType2 as eventType,
12
+ read2 as read,
13
+ readError2 as readError
14
+ };
@@ -0,0 +1,37 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import type { EnsureTiming } from "./service-timing.js";
3
+ export type ServiceContender = {
4
+ readonly child: ChildProcess;
5
+ readonly error: () => Error | undefined;
6
+ readonly closed: () => boolean;
7
+ readonly stderr: () => string;
8
+ readonly release: () => void;
9
+ };
10
+ export declare function spawnServiceContender(command: string, args: ReadonlyArray<string>, env?: Readonly<Record<string, string | undefined>>): ServiceContender;
11
+ /**
12
+ * The startup attempts of one `ensure()` call. It keeps at most two attempts alive, remembers
13
+ * the first startup failure, and backs off when attempts exit cleanly because another one won.
14
+ */
15
+ export declare function contenderPool(timing: EnsureTiming): {
16
+ /** The first startup failure seen since the last eviction. */
17
+ failure: () => Error | undefined;
18
+ /** A registered service answered, so the next attempt waits the base delay again. */
19
+ serviceAnswered(): void;
20
+ /**
21
+ * The owner `pid` was replaced. Drop its attempt and any finished ones, forget their
22
+ * failure, and restart the spawn clock.
23
+ */
24
+ evict(pid: number): void;
25
+ /** Let the next attempt start without waiting a spawn delay. */
26
+ recruitNow(): void;
27
+ /** Collect finished attempts. Returns the startup failure once no attempt is left alive. */
28
+ reap(): Error | undefined;
29
+ /**
30
+ * Whether to start another attempt now. A registration that has not answered yet gets one
31
+ * spawn delay before an attempt competes with it.
32
+ */
33
+ shouldRecruit(registered: boolean): boolean;
34
+ add(contender: ServiceContender): void;
35
+ releaseAll(): void;
36
+ };
37
+ export declare function contenderFinished(contender: ServiceContender): boolean;
@@ -0,0 +1,10 @@
1
+ import {
2
+ spawnServiceContender2,
3
+ contenderPool2,
4
+ contenderFinished2
5
+ } from "./chunks/contract-96mz1w8q.js";
6
+ export {
7
+ contenderFinished2 as contenderFinished,
8
+ contenderPool2 as contenderPool,
9
+ spawnServiceContender2 as spawnServiceContender
10
+ };
@@ -0,0 +1,74 @@
1
+ import type { DiscoverOptions, Endpoint, Info } from "./service.js";
2
+ export type LocalService = {
3
+ readonly info: Info;
4
+ readonly endpoint: Endpoint;
5
+ readonly version?: string;
6
+ readonly state: "ready" | "waiting" | "failed";
7
+ readonly compatible: boolean;
8
+ };
9
+ /**
10
+ * What `ensure()` does with a registered service that answered: return it, keep polling while
11
+ * it starts, replace it because its version does not meet the requirement, or fail.
12
+ */
13
+ export declare function decide(service: LocalService, options: DiscoverOptions): {
14
+ readonly _tag: "replace";
15
+ readonly pty: "clear" | "handoff";
16
+ } | {
17
+ readonly pty?: undefined;
18
+ readonly _tag: "reuse";
19
+ } | {
20
+ readonly pty?: undefined;
21
+ readonly _tag: "wait";
22
+ } | {
23
+ _tag: "fail";
24
+ error: Error;
25
+ };
26
+ /**
27
+ * The default registration file. An empty `XDG_STATE_HOME` means unset, matching the XDG
28
+ * specification and `roots()` in `packages/util/src/global-roots.ts`, so the client and server
29
+ * always resolve the same registration path.
30
+ */
31
+ export declare function fallback(): string;
32
+ /** Whether two registrations describe the same service instance. */
33
+ export declare function same(left: Info, right: Info): boolean;
34
+ /** Ask a registered owner for its health and classify the answer. */
35
+ export declare function probeResult(info: Info, timeout?: number): Promise<{
36
+ service: undefined;
37
+ timedOut: boolean;
38
+ } | {
39
+ service: {
40
+ info: Info;
41
+ endpoint: {
42
+ url: string;
43
+ auth: {
44
+ type: "basic";
45
+ username: string;
46
+ password: string;
47
+ } | undefined;
48
+ };
49
+ version: string | undefined;
50
+ state: "ready";
51
+ compatible: false;
52
+ };
53
+ timedOut: boolean;
54
+ } | {
55
+ service: {
56
+ info: Info;
57
+ endpoint: {
58
+ url: string;
59
+ auth: {
60
+ type: "basic";
61
+ username: string;
62
+ password: string;
63
+ } | undefined;
64
+ };
65
+ version: string;
66
+ state: "failed" | "ready" | "waiting";
67
+ compatible: true;
68
+ };
69
+ timedOut: boolean;
70
+ }>;
71
+ /** Create HTTP authentication headers for a service endpoint. */
72
+ export declare function headers(endpoint: Endpoint): {
73
+ authorization: string;
74
+ } | undefined;
@@ -0,0 +1,16 @@
1
+ import {
2
+ decide2,
3
+ fallback2,
4
+ same2,
5
+ probeResult2,
6
+ headers2
7
+ } from "./chunks/contract-6sr7f8yw.js";
8
+ import"./chunks/contract-xgnj2w4v.js";
9
+ import"./chunks/contract-sxt88q69.js";
10
+ export {
11
+ decide2 as decide,
12
+ fallback2 as fallback,
13
+ headers2 as headers,
14
+ probeResult2 as probeResult,
15
+ same2 as same
16
+ };
@@ -0,0 +1,12 @@
1
+ export type EnsureTiming = {
2
+ readonly pollInterval: number;
3
+ readonly requestTimeout: number;
4
+ readonly spawnDelay: number;
5
+ readonly maxSpawnDelay: number;
6
+ readonly promiseTimeout: number;
7
+ readonly stopPollInterval: number;
8
+ readonly stopPollAttempts: number;
9
+ };
10
+ export declare const defaultEnsureTiming: EnsureTiming;
11
+ export declare function ensureTiming(options: object): EnsureTiming;
12
+ export declare function withEnsureTiming<A extends object>(options: A, overrides: Partial<EnsureTiming>): A;
@@ -0,0 +1,10 @@
1
+ import {
2
+ defaultEnsureTiming2,
3
+ ensureTiming2,
4
+ withEnsureTiming2
5
+ } from "./chunks/contract-xgnj2w4v.js";
6
+ export {
7
+ defaultEnsureTiming2 as defaultEnsureTiming,
8
+ ensureTiming2 as ensureTiming,
9
+ withEnsureTiming2 as withEnsureTiming
10
+ };
@@ -0,0 +1,2 @@
1
+ import type { DiscoverOptions } from "./service.js";
2
+ export declare function matchesVersion(version: string | undefined, options: DiscoverOptions): boolean;
@@ -0,0 +1,6 @@
1
+ import {
2
+ matchesVersion2
3
+ } from "./chunks/contract-sxt88q69.js";
4
+ export {
5
+ matchesVersion2 as matchesVersion
6
+ };
@@ -0,0 +1,52 @@
1
+ /** Connection details for a local OpenCode service. */
2
+ export type Endpoint = {
3
+ /** Base URL of the service. */
4
+ readonly url: string;
5
+ /** Authentication required by the service, when configured. */
6
+ readonly auth?: {
7
+ /** HTTP authentication scheme. */
8
+ readonly type: "basic";
9
+ /** Basic authentication username. */
10
+ readonly username: string;
11
+ /** Basic authentication password. */
12
+ readonly password: string;
13
+ };
14
+ };
15
+ /** Options used to discover the local OpenCode service. */
16
+ export type DiscoverOptions = {
17
+ /** Absolute registration file path. Defaults to the XDG state directory. */
18
+ readonly file?: string;
19
+ /** Required exact service version or compatibility predicate. */
20
+ readonly version?: string | ((version: string) => boolean);
21
+ };
22
+ /** Reason ensuring the service requires a new process. */
23
+ export type EnsureReason = "missing" | "version-mismatch";
24
+ /** Options used to ensure the local OpenCode service is running. */
25
+ export type EnsureOptions = DiscoverOptions & {
26
+ /** Service command and arguments. Defaults to `opencode serve --service`. */
27
+ readonly command?: ReadonlyArray<string>;
28
+ /** Environment variables added to the inherited service process environment. */
29
+ readonly env?: Readonly<Record<string, string>>;
30
+ /** Called once before spawning a new service process. */
31
+ readonly onStart?: (reason: EnsureReason, previousVersion?: string) => void;
32
+ };
33
+ /** Options used to stop the local OpenCode service. */
34
+ export type StopOptions = {
35
+ /** Absolute registration file path. Defaults to the XDG state directory. */
36
+ readonly file?: string;
37
+ /** How to handle persistent terminals before stopping the service. */
38
+ readonly pty?: "clear" | "handoff";
39
+ };
40
+ /** Contents of the local service registration file. */
41
+ export type Info = {
42
+ /** Unique service instance identifier. */
43
+ readonly id?: string;
44
+ /** OpenCode version served by the process. */
45
+ readonly version?: string;
46
+ /** Base URL advertised by the service. */
47
+ readonly url: string;
48
+ /** Operating system process identifier. */
49
+ readonly pid: number;
50
+ /** Private service password, when authentication is enabled. */
51
+ readonly password?: string;
52
+ };
@@ -0,0 +1 @@
1
+ import"./chunks/contract-qav6mfdz.js";
@@ -0,0 +1,16 @@
1
+ export * as SharedEvents from "./shared-events.js";
2
+ /** The members of event union `A` whose type matches one of `Type`, including `rpc.*` events. */
3
+ export type SelectedEvent<A extends {
4
+ readonly type: string;
5
+ }, Type extends string> = A extends unknown ? [Extract<Type, A["type"]>] extends [never] ? never : A : never;
6
+ export type SubscribeOptions<Type extends string = string> = {
7
+ readonly types?: ReadonlyArray<Type>;
8
+ readonly signal?: AbortSignal;
9
+ /** Reports transport activity on the shared stream, including keepalive frames that carry no event. */
10
+ readonly onActivity?: () => void;
11
+ };
12
+ export declare function make<A extends {
13
+ readonly type: string;
14
+ }>(connect: (signal: AbortSignal, onActivity: () => void) => AsyncIterable<A>): {
15
+ subscribe<Type extends Exclude<A["type"], "server.connected"> = Exclude<A["type"], "server.connected">>(options?: SubscribeOptions<Type>): AsyncIterable<SelectedEvent<A, Type | "server.connected">>;
16
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ make7,
3
+ exports_shared_events
4
+ } from "./chunks/contract-5f99ddep.js";
5
+ export {
6
+ exports_shared_events as SharedEvents,
7
+ make7 as make
8
+ };
@@ -0,0 +1,37 @@
1
+ import type { RadheClient, RadheEvent } from "../promise";
2
+ export type ClientConnectionStatus = "connected" | "connecting" | "reconnecting";
3
+ export type ClientConnectionEvent = {
4
+ readonly type: "client.connection";
5
+ readonly created: number;
6
+ readonly data: {
7
+ readonly status: "connecting" | "connected" | "disconnected" | "reconnecting";
8
+ readonly attempt: number;
9
+ readonly error?: string;
10
+ };
11
+ };
12
+ export type ClientConnectionOptions = {
13
+ readonly reconnect?: (signal: AbortSignal) => Promise<RadheClient>;
14
+ readonly onEvent: (event: RadheEvent) => void;
15
+ readonly flushInterval?: number;
16
+ readonly pageLifecycle?: boolean;
17
+ /**
18
+ * Abort and reconnect a stream that receives no bytes for this long. The server writes a keepalive
19
+ * comment every 15 seconds, so a quiet but healthy stream never trips this.
20
+ */
21
+ readonly idleTimeout?: number;
22
+ readonly log?: {
23
+ readonly debug?: (message: string, data?: Readonly<Record<string, unknown>>) => void;
24
+ readonly info?: (message: string, data?: Readonly<Record<string, unknown>>) => void;
25
+ };
26
+ };
27
+ export declare const defaultIdleTimeout = 45000;
28
+ export declare const foregroundIdleThreshold = 20000;
29
+ export declare function createClientConnection(initialApi: RadheClient, options: ClientConnectionOptions): {
30
+ status: () => ClientConnectionStatus;
31
+ attempt: () => number;
32
+ error: () => string | undefined;
33
+ internal: {
34
+ history: () => ClientConnectionEvent[];
35
+ resync: (reason: string) => void;
36
+ };
37
+ };
@@ -0,0 +1,10 @@
1
+ import {
2
+ defaultIdleTimeout2,
3
+ foregroundIdleThreshold2,
4
+ createClientConnection2
5
+ } from "../chunks/contract-ydhz1zrh.js";
6
+ export {
7
+ createClientConnection2 as createClientConnection,
8
+ defaultIdleTimeout2 as defaultIdleTimeout,
9
+ foregroundIdleThreshold2 as foregroundIdleThreshold
10
+ };