@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,62 @@
1
+ import {
2
+ read2,
3
+ readError2,
4
+ event2,
5
+ eventType2
6
+ } from "./contract-t5nrycbt.js";
7
+ import {
8
+ __export
9
+ } from "./contract-9rqn6x4v.js";
10
+
11
+ // src/effect/rpc.ts
12
+ var exports_rpc = {};
13
+ __export(exports_rpc, {
14
+ RpcClientRuntime: () => exports_rpc,
15
+ aborted: () => aborted2,
16
+ make: () => make4
17
+ });
18
+ import { Effect, Stream } from "effect";
19
+ function make4(call, subscribe) {
20
+ return (definition) => {
21
+ const methods = Object.fromEntries(Object.entries(definition.methods).map(([name, method]) => [
22
+ name,
23
+ (input, options) => {
24
+ const result = Effect.gen(function* () {
25
+ const response = yield* call({
26
+ rpcID: definition.id,
27
+ method: name,
28
+ input,
29
+ location: options?.location
30
+ }, options);
31
+ return yield* read2(method.output, response.output);
32
+ }).pipe(Effect.catch((error) => readError2(method, error)));
33
+ const signal = options?.signal;
34
+ if (!signal)
35
+ return result;
36
+ return Effect.suspend(() => signal.aborted ? Effect.interrupt : Effect.raceFirst(result, Effect.andThen(aborted2(signal), Effect.interrupt)));
37
+ }
38
+ ]));
39
+ return Object.assign(methods, {
40
+ events: {
41
+ subscribe: (name) => {
42
+ const type = eventType2(definition, name);
43
+ if (!Object.hasOwn(definition.events, name))
44
+ return Stream.fail(new Error(`Unknown RPC event: ${type}`));
45
+ const schema = definition.events[name];
46
+ return subscribe().pipe(Stream.filter((event) => event.type === type), Stream.mapEffect((event) => event2(definition, name, schema, event)));
47
+ }
48
+ }
49
+ });
50
+ };
51
+ }
52
+ function aborted2(signal) {
53
+ return Effect.callback((resume) => {
54
+ if (signal.aborted)
55
+ return resume(Effect.void);
56
+ const abort = () => resume(Effect.void);
57
+ signal.addEventListener("abort", abort, { once: true });
58
+ return Effect.sync(() => signal.removeEventListener("abort", abort));
59
+ });
60
+ }
61
+
62
+ export { make4, aborted2, exports_rpc };
@@ -0,0 +1,149 @@
1
+ import {
2
+ __export
3
+ } from "./contract-9rqn6x4v.js";
4
+
5
+ // src/shared-events.ts
6
+ var exports_shared_events = {};
7
+ __export(exports_shared_events, {
8
+ SharedEvents: () => exports_shared_events,
9
+ make: () => make7
10
+ });
11
+ function make7(connect) {
12
+ let current;
13
+ const capacity = 4096;
14
+ function stop(connection) {
15
+ connection.connected = undefined;
16
+ connection.controller.abort();
17
+ if (current === connection)
18
+ current = undefined;
19
+ }
20
+ async function run(connection) {
21
+ let iterator;
22
+ let completion = {};
23
+ try {
24
+ if (connection.controller.signal.aborted)
25
+ return;
26
+ iterator = connect(connection.controller.signal, () => {
27
+ connection.subscribers.forEach((subscriber) => subscriber.activity?.());
28
+ })[Symbol.asyncIterator]();
29
+ while (!connection.controller.signal.aborted) {
30
+ const item = await iterator.next();
31
+ if (item.done || connection.controller.signal.aborted)
32
+ break;
33
+ if (item.value.type === "server.connected")
34
+ connection.connected = item.value;
35
+ connection.subscribers.forEach((subscriber) => subscriber.push(item.value));
36
+ }
37
+ } catch (error) {
38
+ completion = { error };
39
+ } finally {
40
+ stop(connection);
41
+ try {
42
+ await iterator?.return?.();
43
+ } catch (error) {
44
+ if (!("error" in completion))
45
+ completion = { error };
46
+ }
47
+ connection.subscribers.forEach((subscriber) => subscriber.finish(completion));
48
+ }
49
+ }
50
+ return {
51
+ subscribe(options) {
52
+ return {
53
+ [Symbol.asyncIterator]() {
54
+ const pending = [];
55
+ const queued = [];
56
+ let started = false;
57
+ let completion;
58
+ let connection;
59
+ const types = options?.types?.length ? new Set(options.types) : undefined;
60
+ const selected = (value) => !types || value.type === "server.connected" || types.has(value.type);
61
+ function finish(result, discard = true) {
62
+ completion = result;
63
+ if (discard)
64
+ queued.length = 0;
65
+ options?.signal?.removeEventListener("abort", abort);
66
+ if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
67
+ stop(connection);
68
+ pending.splice(0).forEach((request) => {
69
+ if ("error" in result)
70
+ request.reject(result.error);
71
+ else
72
+ request.resolve({ done: true, value: undefined });
73
+ });
74
+ }
75
+ function abort() {
76
+ finish({});
77
+ }
78
+ const subscriber = {
79
+ activity: options?.onActivity,
80
+ finish(result) {
81
+ finish(result, false);
82
+ },
83
+ push(value) {
84
+ if (completion)
85
+ return;
86
+ if (!selected(value))
87
+ return;
88
+ const request = pending.shift();
89
+ if (request) {
90
+ request.resolve({ done: false, value });
91
+ return;
92
+ }
93
+ if (queued.length === capacity) {
94
+ finish({ error: new Error(`Event subscriber exceeded its ${capacity}-event capacity`) });
95
+ return;
96
+ }
97
+ queued.push(value);
98
+ }
99
+ };
100
+ function start() {
101
+ if (completion)
102
+ return;
103
+ const fresh = !current;
104
+ connection = current ?? {
105
+ controller: new AbortController,
106
+ subscribers: new Set
107
+ };
108
+ current = connection;
109
+ connection.subscribers.add(subscriber);
110
+ if (connection.connected)
111
+ subscriber.push(connection.connected);
112
+ if (fresh)
113
+ run(connection);
114
+ }
115
+ return {
116
+ next() {
117
+ if (options?.signal?.aborted) {
118
+ abort();
119
+ return Promise.resolve({ done: true, value: undefined });
120
+ }
121
+ const value = queued.shift();
122
+ if (value)
123
+ return Promise.resolve({ done: false, value });
124
+ if (completion) {
125
+ if ("error" in completion)
126
+ return Promise.reject(completion.error);
127
+ return Promise.resolve({ done: true, value: undefined });
128
+ }
129
+ const request = Promise.withResolvers();
130
+ pending.push(request);
131
+ if (!started) {
132
+ started = true;
133
+ options?.signal?.addEventListener("abort", abort, { once: true });
134
+ start();
135
+ }
136
+ return request.promise;
137
+ },
138
+ return() {
139
+ finish({});
140
+ return Promise.resolve({ done: true, value: undefined });
141
+ }
142
+ };
143
+ }
144
+ };
145
+ }
146
+ };
147
+ }
148
+
149
+ export { make7, exports_shared_events };
File without changes
@@ -0,0 +1,33 @@
1
+ // src/solid/retention.ts
2
+ import { createEffect, untrack } from "solid-js";
3
+ function createSessionRetention2(input) {
4
+ let previous;
5
+ let recent = [];
6
+ let evicted = new Map;
7
+ createEffect(() => {
8
+ const viewed = input.current();
9
+ const current = viewed === undefined ? undefined : input.session.root(viewed);
10
+ const keep = new Set(input.keep().map((id) => input.session.root(id)));
11
+ recent = [
12
+ ...new Set([
13
+ ...viewed !== previous && current !== undefined ? [current] : [],
14
+ ...recent.map((id) => input.session.root(id))
15
+ ])
16
+ ];
17
+ previous = viewed;
18
+ const retained = new Set([...keep, ...recent.filter((id) => !keep.has(id)).slice(0, input.limit)]);
19
+ if (current !== undefined)
20
+ retained.add(current);
21
+ recent = recent.filter((id) => retained.has(id));
22
+ const count = (id) => untrack(() => input.session.message?.list(id).length ?? 0);
23
+ const excluded = new Map(input.session.list().flatMap((session) => {
24
+ const root = input.session.root(session.id);
25
+ return retained.has(root) ? [] : [[session.id, root]];
26
+ }));
27
+ const roots = new Set([...excluded].filter(([id, root]) => evicted.get(id) !== `${root}:${count(id)}`).map(([, root]) => root));
28
+ untrack(() => roots.forEach((root) => input.session.evict(root)));
29
+ evicted = new Map([...excluded].map(([id, root]) => [id, `${root}:${count(id)}`]));
30
+ });
31
+ }
32
+
33
+ export { createSessionRetention2 };
File without changes
@@ -0,0 +1,92 @@
1
+ import {
2
+ defaultEnsureTiming2
3
+ } from "./contract-xgnj2w4v.js";
4
+ import {
5
+ matchesVersion2
6
+ } from "./contract-sxt88q69.js";
7
+
8
+ // src/service-probe.ts
9
+ import { homedir } from "node:os";
10
+ import { join } from "node:path";
11
+ function decide2(service, options) {
12
+ if (!matchesVersion2(service.version, options))
13
+ return { _tag: "replace", pty: service.state === "ready" ? "handoff" : "clear" };
14
+ if (!service.compatible)
15
+ return fail("Background service uses an incompatible health protocol. Update this client or explicitly restart the service.");
16
+ if (service.state === "ready")
17
+ return { _tag: "reuse" };
18
+ if (service.state === "failed")
19
+ return fail("Background service failed to start");
20
+ return { _tag: "wait" };
21
+ }
22
+ function fail(message) {
23
+ return { _tag: "fail", error: new Error(message) };
24
+ }
25
+ function fallback2() {
26
+ return join(process.env["XDG_STATE_HOME"] || join(homedir(), ".local", "state"), "opencode", "service.json");
27
+ }
28
+ function same2(left, right) {
29
+ return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
30
+ }
31
+ async function probeResult2(info, timeout = defaultEnsureTiming2.requestTimeout) {
32
+ const endpoint = {
33
+ url: info.url,
34
+ auth: info.password === undefined ? undefined : { type: "basic", username: "opencode", password: info.password }
35
+ };
36
+ const signal = AbortSignal.timeout(timeout);
37
+ const result = await fetch(new URL("/api/info", info.url), { headers: headers2(endpoint), signal }).then(async (response) => ({
38
+ response,
39
+ body: response.status === 404 ? undefined : await response.json()
40
+ })).catch(() => {
41
+ return;
42
+ });
43
+ if (result === undefined)
44
+ return { service: undefined, timedOut: signal.aborted };
45
+ const response = result.response;
46
+ if (response.status === 404)
47
+ return {
48
+ service: {
49
+ info,
50
+ endpoint,
51
+ version: info.version,
52
+ state: "ready",
53
+ compatible: false
54
+ },
55
+ timedOut: false
56
+ };
57
+ const serverInfo = decodeInfo(result.body);
58
+ if (serverInfo === undefined)
59
+ return { service: undefined, timedOut: false };
60
+ if (serverInfo.pid !== info.pid)
61
+ return { service: undefined, timedOut: false };
62
+ if (info.version !== undefined && serverInfo.version !== info.version)
63
+ return { service: undefined, timedOut: false };
64
+ return {
65
+ service: {
66
+ info,
67
+ endpoint,
68
+ version: serverInfo.version,
69
+ state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
70
+ compatible: true
71
+ },
72
+ timedOut: false
73
+ };
74
+ }
75
+ function headers2(endpoint) {
76
+ if (endpoint.auth === undefined)
77
+ return;
78
+ return {
79
+ authorization: "Basic " + Buffer.from(endpoint.auth.username + ":" + endpoint.auth.password).toString("base64")
80
+ };
81
+ }
82
+ function decodeInfo(input) {
83
+ if (typeof input !== "object" || input === null)
84
+ return;
85
+ if (!("version" in input) || typeof input.version !== "string")
86
+ return;
87
+ if (!("pid" in input) || typeof input.pid !== "number" || !Number.isInteger(input.pid) || input.pid < 0)
88
+ return;
89
+ return { version: input.version, pid: input.pid };
90
+ }
91
+
92
+ export { decide2, fallback2, same2, probeResult2, headers2 };