@kilocode/client 0.0.0-stage → 0.0.0-v2-9

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 (94) hide show
  1. package/README.md +26 -2
  2. package/dist/chunks/contract-15p82y03.js +62 -0
  3. package/dist/chunks/contract-1x65x4hv.js +1701 -0
  4. package/dist/chunks/contract-5bf0yjkp.js +111 -0
  5. package/dist/chunks/contract-6mptkzbc.js +0 -0
  6. package/dist/chunks/contract-8bbb028w.js +145 -0
  7. package/dist/chunks/contract-8s2anffy.js +11 -0
  8. package/dist/chunks/contract-8ye1ye6f.js +92 -0
  9. package/dist/chunks/contract-9rqn6x4v.js +16 -0
  10. package/dist/chunks/contract-c46qzyff.js +37 -0
  11. package/dist/chunks/contract-gne7h7mq.js +50 -0
  12. package/dist/chunks/contract-hjez4bfs.js +52 -0
  13. package/dist/chunks/contract-m2eywc8w.js +0 -0
  14. package/dist/chunks/contract-nwcpakzx.js +12 -0
  15. package/dist/chunks/contract-qav6mfdz.js +0 -0
  16. package/dist/chunks/contract-ryy6kscr.js +39 -0
  17. package/dist/chunks/contract-s2hya144.js +1524 -0
  18. package/dist/chunks/contract-skhp7hxc.js +81 -0
  19. package/dist/chunks/contract-sxt88q69.js +12 -0
  20. package/dist/chunks/contract-ve4aws36.js +103 -0
  21. package/dist/chunks/contract-vmytr4q8.js +4 -0
  22. package/dist/chunks/contract-vwtmm97t.js +30 -0
  23. package/dist/chunks/contract-vyas3vgt.js +0 -0
  24. package/dist/chunks/contract-w10x3kfx.js +658 -0
  25. package/dist/chunks/contract-xgnj2w4v.js +20 -0
  26. package/dist/chunks/contract-y2etg5bs.js +9 -0
  27. package/dist/chunks/contract-ydhz1zrh.js +238 -0
  28. package/dist/contract.d.ts +1 -0
  29. package/dist/contract.js +12 -0
  30. package/dist/effect/api/api.d.ts +2927 -0
  31. package/dist/effect/api/api.js +0 -0
  32. package/dist/effect/api.d.ts +4 -0
  33. package/dist/effect/api.js +0 -0
  34. package/dist/effect/client.d.ts +2569 -0
  35. package/dist/effect/client.js +15 -0
  36. package/dist/effect/generated/client-error.d.ts +7 -0
  37. package/dist/effect/generated/client-error.js +6 -0
  38. package/dist/effect/generated/client.d.ts +2568 -0
  39. package/dist/effect/generated/client.js +8 -0
  40. package/dist/effect/generated/index.d.ts +2 -0
  41. package/dist/effect/generated/index.js +12 -0
  42. package/dist/effect/index.d.ts +35 -0
  43. package/dist/effect/index.js +75 -0
  44. package/dist/effect/rpc.d.ts +20 -0
  45. package/dist/effect/rpc.js +11 -0
  46. package/dist/effect/service.d.ts +90 -0
  47. package/dist/effect/service.js +187 -0
  48. package/dist/mcp.d.ts +44 -0
  49. package/dist/mcp.js +110 -0
  50. package/dist/promise/api.d.ts +21 -0
  51. package/dist/promise/api.js +0 -0
  52. package/dist/promise/client.d.ts +270 -0
  53. package/dist/promise/client.js +14 -0
  54. package/dist/promise/generated/client-error.d.ts +8 -0
  55. package/dist/promise/generated/client-error.js +6 -0
  56. package/dist/promise/generated/client.d.ts +277 -0
  57. package/dist/promise/generated/client.js +7 -0
  58. package/dist/promise/generated/index.d.ts +3 -0
  59. package/dist/promise/generated/index.js +81 -0
  60. package/dist/promise/generated/types.d.ts +7877 -0
  61. package/dist/promise/generated/types.js +72 -0
  62. package/dist/promise/index.d.ts +6 -0
  63. package/dist/promise/index.js +85 -0
  64. package/dist/promise/rpc.d.ts +32 -0
  65. package/dist/promise/rpc.js +7 -0
  66. package/dist/promise/service.d.ts +24 -0
  67. package/dist/promise/service.js +187 -0
  68. package/dist/pty-handoff.d.ts +12 -0
  69. package/dist/pty-handoff.js +17 -0
  70. package/dist/rpc-runtime.d.ts +20 -0
  71. package/dist/rpc-runtime.js +14 -0
  72. package/dist/service-contender.d.ts +37 -0
  73. package/dist/service-contender.js +10 -0
  74. package/dist/service-probe.d.ts +70 -0
  75. package/dist/service-probe.js +16 -0
  76. package/dist/service-timing.d.ts +12 -0
  77. package/dist/service-timing.js +10 -0
  78. package/dist/service-version.d.ts +2 -0
  79. package/dist/service-version.js +6 -0
  80. package/dist/service.d.ts +52 -0
  81. package/dist/service.js +1 -0
  82. package/dist/shared-events.d.ts +11 -0
  83. package/dist/shared-events.js +8 -0
  84. package/dist/solid/connection.d.ts +37 -0
  85. package/dist/solid/connection.js +10 -0
  86. package/dist/solid/data.d.ts +211 -0
  87. package/dist/solid/data.js +18 -0
  88. package/dist/solid/index.d.ts +4 -0
  89. package/dist/solid/index.js +36 -0
  90. package/dist/solid/pty.d.ts +22 -0
  91. package/dist/solid/pty.js +8 -0
  92. package/dist/solid/usage.d.ts +9 -0
  93. package/dist/solid/usage.js +6 -0
  94. package/package.json +88 -4
@@ -0,0 +1,111 @@
1
+ import {
2
+ headers2
3
+ } from "./contract-8ye1ye6f.js";
4
+ import {
5
+ __export
6
+ } from "./contract-9rqn6x4v.js";
7
+
8
+ // src/pty-handoff.ts
9
+ var exports_pty_handoff = {};
10
+ __export(exports_pty_handoff, {
11
+ PtyHandoff: () => exports_pty_handoff,
12
+ clear: () => clear2,
13
+ complete: () => complete2,
14
+ environment: () => environment2,
15
+ prepare: () => prepare2
16
+ });
17
+ import { readFile, rename, rm, writeFile } from "node:fs/promises";
18
+ async function prepare2(file, info, timeout) {
19
+ const existing = await read(file);
20
+ if (existing !== undefined && existing.expiresAt > Date.now() && same(existing.source, info))
21
+ return;
22
+ const { OpenCode } = await import("../promise/index.js");
23
+ const client = OpenCode.make({
24
+ baseUrl: info.url,
25
+ headers: headers2({
26
+ url: info.url,
27
+ auth: info.password === undefined ? undefined : { type: "basic", username: "opencode", password: info.password }
28
+ })
29
+ });
30
+ const handoff = await client.experimental.persistentPty.handoff({ signal: AbortSignal.timeout(timeout) }).then(parse).catch(async (cause) => {
31
+ const concurrent = await read(file);
32
+ if (concurrent !== undefined && concurrent.expiresAt > Date.now() && same(concurrent.source, info))
33
+ return;
34
+ console.warn("Background service cannot hand off persistent terminals; shutting them down before replacement", cause);
35
+ await client.experimental.persistentPty.shutdown({ signal: AbortSignal.timeout(timeout) }).catch(() => {});
36
+ return null;
37
+ });
38
+ if (handoff === undefined)
39
+ return;
40
+ await publish(file, info, handoff).catch((cause) => console.warn("Failed to publish persistent terminal handoff", cause));
41
+ }
42
+ function parse(body) {
43
+ if (typeof body !== "object" || body === null || !("handoff" in body))
44
+ throw new Error("Invalid persistent terminal handoff response");
45
+ if (body.handoff === null)
46
+ return null;
47
+ if (!isHandoff(body.handoff) || body.handoff.expiresAt <= Date.now())
48
+ throw new Error("Invalid or expired persistent terminal handoff");
49
+ return body.handoff;
50
+ }
51
+ async function publish(file, info, handoff) {
52
+ const temporary = `${file}.pty-handoff.${crypto.randomUUID()}.tmp`;
53
+ await writeFile(temporary, JSON.stringify({
54
+ source: { id: info.id, pid: info.pid, url: info.url },
55
+ handoff,
56
+ expiresAt: handoff?.expiresAt ?? Date.now() + 30000
57
+ }), { mode: 384, flag: "wx" });
58
+ await rename(temporary, file + ".pty-handoff").finally(() => rm(temporary, { force: true }));
59
+ }
60
+ async function environment2(file, env) {
61
+ const record = await read(file);
62
+ const current = await readFile(file, "utf8").then((text) => JSON.parse(text)).catch(() => {
63
+ return;
64
+ });
65
+ const handoff = record !== undefined && record.expiresAt > Date.now() && (current === undefined || same(record.source, current)) ? record.handoff : undefined;
66
+ return { ...env, OPENCODE_PTY_HANDOFF: handoff == null ? undefined : JSON.stringify(handoff) };
67
+ }
68
+ async function complete2(file, info) {
69
+ const record = await read(file);
70
+ if (record !== undefined && !same(record.source, info))
71
+ await clear2(file);
72
+ }
73
+ async function clear2(file) {
74
+ await rm(file + ".pty-handoff", { force: true });
75
+ }
76
+ async function read(file) {
77
+ const value = await readFile(file + ".pty-handoff", "utf8").then((text) => JSON.parse(text)).catch(() => {
78
+ return;
79
+ });
80
+ if (typeof value !== "object" || value === null || !("source" in value) || !("handoff" in value))
81
+ return;
82
+ if (typeof value.source !== "object" || value.source === null)
83
+ return;
84
+ if (!("pid" in value.source) || typeof value.source.pid !== "number")
85
+ return;
86
+ if (!("url" in value.source) || typeof value.source.url !== "string")
87
+ return;
88
+ if ("id" in value.source && typeof value.source.id !== "string")
89
+ return;
90
+ if (value.handoff !== null && !isHandoff(value.handoff))
91
+ return;
92
+ if (!("expiresAt" in value) || typeof value.expiresAt !== "number" || !Number.isFinite(value.expiresAt))
93
+ return;
94
+ return {
95
+ source: {
96
+ id: "id" in value.source && typeof value.source.id === "string" ? value.source.id : undefined,
97
+ pid: value.source.pid,
98
+ url: value.source.url
99
+ },
100
+ handoff: value.handoff,
101
+ expiresAt: value.expiresAt
102
+ };
103
+ }
104
+ function same(left, right) {
105
+ return left.id === right.id && left.pid === right.pid && left.url === right.url;
106
+ }
107
+ function isHandoff(value) {
108
+ return typeof value === "object" && value !== null && "directory" in value && typeof value.directory === "string" && "instanceID" in value && typeof value.instanceID === "string" && "ticket" in value && typeof value.ticket === "string" && "expiresAt" in value && typeof value.expiresAt === "number" && Number.isFinite(value.expiresAt);
109
+ }
110
+
111
+ export { prepare2, environment2, complete2, clear2, exports_pty_handoff };
File without changes
@@ -0,0 +1,145 @@
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
+ function finish(result, discard = true) {
60
+ completion = result;
61
+ if (discard)
62
+ queued.length = 0;
63
+ options?.signal?.removeEventListener("abort", abort);
64
+ if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
65
+ stop(connection);
66
+ pending.splice(0).forEach((request) => {
67
+ if ("error" in result)
68
+ request.reject(result.error);
69
+ else
70
+ request.resolve({ done: true, value: undefined });
71
+ });
72
+ }
73
+ function abort() {
74
+ finish({});
75
+ }
76
+ const subscriber = {
77
+ activity: options?.onActivity,
78
+ finish(result) {
79
+ finish(result, false);
80
+ },
81
+ push(value) {
82
+ if (completion)
83
+ return;
84
+ const request = pending.shift();
85
+ if (request) {
86
+ request.resolve({ done: false, value });
87
+ return;
88
+ }
89
+ if (queued.length === capacity) {
90
+ finish({ error: new Error(`Event subscriber exceeded its ${capacity}-event capacity`) });
91
+ return;
92
+ }
93
+ queued.push(value);
94
+ }
95
+ };
96
+ function start() {
97
+ if (completion)
98
+ return;
99
+ const fresh = !current;
100
+ connection = current ?? {
101
+ controller: new AbortController,
102
+ subscribers: new Set
103
+ };
104
+ current = connection;
105
+ connection.subscribers.add(subscriber);
106
+ if (connection.connected)
107
+ subscriber.push(connection.connected);
108
+ if (fresh)
109
+ run(connection);
110
+ }
111
+ return {
112
+ next() {
113
+ const value = queued.shift();
114
+ if (value)
115
+ return Promise.resolve({ done: false, value });
116
+ if (completion) {
117
+ if ("error" in completion)
118
+ return Promise.reject(completion.error);
119
+ return Promise.resolve({ done: true, value: undefined });
120
+ }
121
+ if (options?.signal?.aborted) {
122
+ abort();
123
+ return Promise.resolve({ done: true, value: undefined });
124
+ }
125
+ const request = Promise.withResolvers();
126
+ pending.push(request);
127
+ if (!started) {
128
+ started = true;
129
+ options?.signal?.addEventListener("abort", abort, { once: true });
130
+ start();
131
+ }
132
+ return request.promise;
133
+ },
134
+ return() {
135
+ finish({});
136
+ return Promise.resolve({ done: true, value: undefined });
137
+ }
138
+ };
139
+ }
140
+ };
141
+ }
142
+ };
143
+ }
144
+
145
+ export { make7, exports_shared_events };
@@ -0,0 +1,11 @@
1
+ // src/solid/usage.ts
2
+ function lastAssistantWithUsage2(messages, boundary) {
3
+ const boundaryIndex = boundary ? messages.findIndex((message) => message.id === boundary) : -1;
4
+ if (boundary && boundaryIndex === -1)
5
+ return;
6
+ const end = boundaryIndex === -1 ? messages.length : boundaryIndex;
7
+ const compactionIndex = messages.findLastIndex((message, index) => message.type === "compaction" && message.status === "completed" && index < end);
8
+ return messages.findLast((message, index) => message.type === "assistant" && message.tokens !== undefined && index > compactionIndex && index < end);
9
+ }
10
+
11
+ export { lastAssistantWithUsage2 };
@@ -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 };
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+
16
+ export { __export };
@@ -0,0 +1,37 @@
1
+ // src/promise/generated/types.ts
2
+ var isInvalidRequestError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "InvalidRequestError";
3
+ var isUnauthorizedError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "UnauthorizedError";
4
+ var isLocationNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "LocationNotFoundError";
5
+ var isServiceUnavailableError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ServiceUnavailableError";
6
+ var isAgentNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "AgentNotFoundError";
7
+ var isInvalidCursorError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "InvalidCursorError";
8
+ var isSessionNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SessionNotFoundError";
9
+ var isConflictError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ConflictError";
10
+ var isUnknownError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "UnknownError";
11
+ var isMessageNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "MessageNotFoundError";
12
+ var isCommandNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "CommandNotFoundError";
13
+ var isCommandExecutionError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "CommandExecutionError";
14
+ var isSkillNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SkillNotFoundError";
15
+ var isSessionBusyError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SessionBusyError";
16
+ var isInstructionEntryValueTooLargeError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "InstructionEntryValueTooLargeError";
17
+ var isFormNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FormNotFoundError";
18
+ var isFormInvalidAnswerError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FormInvalidAnswerError";
19
+ var isFormAlreadySettledError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FormAlreadySettledError";
20
+ var isProviderNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProviderNotFoundError";
21
+ var isIntegrationNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationNotFoundError";
22
+ var isIntegrationAttemptNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationAttemptNotFoundError";
23
+ var isIntegrationMethodNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationMethodNotFoundError";
24
+ var isMcpServerNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "McpServerNotFoundError";
25
+ var isForbiddenError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ForbiddenError";
26
+ var isProjectNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProjectNotFoundError";
27
+ var isPermissionSavedNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PermissionSavedNotFoundError";
28
+ var isPermissionNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PermissionNotFoundError";
29
+ var isFileNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FileNotFoundError";
30
+ var isRpcError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "RpcError";
31
+ var isRpcInternalError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "RpcInternalError";
32
+ var isPtyNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PtyNotFoundError";
33
+ var isShellNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ShellNotFoundError";
34
+ var isWorktreeError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "WorktreeError";
35
+ var isVcsInitNotSupportedError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "VcsInitNotSupportedError";
36
+
37
+ export { isInvalidRequestError2, isUnauthorizedError2, isLocationNotFoundError2, isServiceUnavailableError2, isAgentNotFoundError2, isInvalidCursorError2, isSessionNotFoundError2, isConflictError2, isUnknownError2, isMessageNotFoundError2, isCommandNotFoundError2, isCommandExecutionError2, isSkillNotFoundError2, isSessionBusyError2, isInstructionEntryValueTooLargeError2, isFormNotFoundError2, isFormInvalidAnswerError2, isFormAlreadySettledError2, isProviderNotFoundError2, isIntegrationNotFoundError2, isIntegrationAttemptNotFoundError2, isIntegrationMethodNotFoundError2, isMcpServerNotFoundError2, isForbiddenError2, isProjectNotFoundError2, isPermissionSavedNotFoundError2, isPermissionNotFoundError2, isFileNotFoundError2, isRpcError2, isRpcInternalError2, isPtyNotFoundError2, isShellNotFoundError2, isWorktreeError2, isVcsInitNotSupportedError2 };
@@ -0,0 +1,50 @@
1
+ // src/solid/pty.ts
2
+ function createPtyClient2(api, options) {
3
+ return {
4
+ async connect(input) {
5
+ const result = await api.pty.connect.token({
6
+ ptyID: input.ptyID,
7
+ location: input.location,
8
+ "x-opencode-ticket": "1"
9
+ });
10
+ const baseUrl = new URL(options.url);
11
+ if (!baseUrl.pathname.endsWith("/"))
12
+ baseUrl.pathname += "/";
13
+ const url = new URL(`api/pty/${encodeURIComponent(input.ptyID)}/connect`, baseUrl);
14
+ if (input.location?.directory)
15
+ url.searchParams.set("location[directory]", input.location.directory);
16
+ if (input.cursor !== undefined)
17
+ url.searchParams.set("cursor", String(input.cursor));
18
+ url.searchParams.set("ticket", result.data.ticket);
19
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
20
+ const socket = options.openSocket?.(url) ?? new WebSocket(url);
21
+ socket.binaryType = "arraybuffer";
22
+ return socket;
23
+ }
24
+ };
25
+ }
26
+ function createPersistentPtyClient2(api, options) {
27
+ return {
28
+ async connect(input) {
29
+ const token = await api.experimental.persistentPty.connectToken({
30
+ ptyID: input.ptyID,
31
+ "x-opencode-ticket": "1"
32
+ });
33
+ const baseUrl = new URL(options.url);
34
+ if (!baseUrl.pathname.endsWith("/"))
35
+ baseUrl.pathname += "/";
36
+ const url = new URL(`api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect`, baseUrl);
37
+ url.searchParams.set("ticket", token.ticket);
38
+ url.searchParams.set("cursor", String(input.cursor));
39
+ url.searchParams.set("attachment_id", input.attachmentID);
40
+ url.searchParams.set("takeover", String(input.takeover ?? false));
41
+ url.searchParams.set("input_protocol", "1");
42
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
43
+ const socket = options.openSocket?.(url) ?? new WebSocket(url);
44
+ socket.binaryType = "arraybuffer";
45
+ return socket;
46
+ }
47
+ };
48
+ }
49
+
50
+ export { createPtyClient2, createPersistentPtyClient2 };
@@ -0,0 +1,52 @@
1
+ import {
2
+ make7
3
+ } from "./contract-8bbb028w.js";
4
+ import {
5
+ ClientError2
6
+ } from "./contract-y2etg5bs.js";
7
+ import {
8
+ make4
9
+ } from "./contract-w10x3kfx.js";
10
+ import {
11
+ make3,
12
+ aborted2
13
+ } from "./contract-15p82y03.js";
14
+ import {
15
+ __export
16
+ } from "./contract-9rqn6x4v.js";
17
+
18
+ // src/effect/client.ts
19
+ var exports_client = {};
20
+ __export(exports_client, {
21
+ OpenCode: () => exports_client,
22
+ make: () => make2
23
+ });
24
+ import { Cause, Context, Effect, Stream } from "effect";
25
+ import { HttpClient, HttpClientRequest } from "effect/http";
26
+ var CurrentHeaders = Context.Reference("@opencode/client/effect/rpc/headers", {
27
+ defaultValue: () => {
28
+ return;
29
+ }
30
+ });
31
+ var make2 = Effect.fn("OpenCode.make")(function* (options) {
32
+ const httpClient = yield* HttpClient.HttpClient;
33
+ const raw = yield* make4(options).pipe(Effect.provideService(HttpClient.HttpClient, HttpClient.mapRequestEffect(httpClient, (request) => Effect.map(CurrentHeaders, (headers) => headers ? HttpClientRequest.setHeaders(request, new Headers(headers)) : request))));
34
+ const context = yield* Effect.context();
35
+ const native = raw.event.subscribe();
36
+
37
+ class EventFailure {
38
+ cause;
39
+ constructor(cause) {
40
+ this.cause = cause;
41
+ }
42
+ }
43
+ const shared = make7((signal) => Stream.toAsyncIterableWith(native.pipe(Stream.interruptWhen(aborted2(signal)), Stream.catchCause((cause) => Stream.fail(new EventFailure(cause)))), context));
44
+ const subscribe = () => Stream.fromAsyncIterable(shared.subscribe(), (error) => error).pipe(Stream.catch((error) => Stream.failCause(error instanceof EventFailure ? error.cause : Cause.fail(new ClientError2({ cause: error })))));
45
+ return {
46
+ ...raw,
47
+ event: { ...raw.event, subscribe },
48
+ rpc: Object.assign(make3((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
49
+ };
50
+ });
51
+
52
+ export { make2, exports_client };
File without changes
@@ -0,0 +1,12 @@
1
+ // src/promise/generated/client-error.ts
2
+ class ClientError3 extends Error {
3
+ reason;
4
+ name = "ClientError";
5
+ constructor(reason, options) {
6
+ const detail = options?.detail ?? (options?.cause instanceof Error ? options.cause.message : undefined);
7
+ super(detail ? `${reason}: ${detail}` : reason, options);
8
+ this.reason = reason;
9
+ }
10
+ }
11
+
12
+ export { ClientError3 };
File without changes
@@ -0,0 +1,39 @@
1
+ import {
2
+ __export
3
+ } from "./contract-9rqn6x4v.js";
4
+
5
+ // src/rpc-runtime.ts
6
+ var exports_rpc_runtime = {};
7
+ __export(exports_rpc_runtime, {
8
+ RpcRuntime: () => exports_rpc_runtime,
9
+ event: () => event2,
10
+ eventType: () => eventType2,
11
+ read: () => read2,
12
+ readError: () => readError2
13
+ });
14
+ import { RpcError, RpcInternalError } from "@opencode/protocol/errors";
15
+ import { Effect, Schema } from "effect";
16
+ function read2(schema, value) {
17
+ return Schema.isSchema(schema) ? Schema.decodeUnknownEffect(schema)(value) : Effect.succeed(value);
18
+ }
19
+ function readError2(method, error) {
20
+ if (!(error instanceof RpcError) && !(error instanceof RpcInternalError))
21
+ return Effect.fail(error);
22
+ if (!method.errors || !Object.hasOwn(method.errors, error.type)) {
23
+ return Effect.fail(error.data === undefined ? { type: error.type, message: error.message } : { type: error.type, message: error.message, data: error.data });
24
+ }
25
+ return read2(method.errors[error.type], error.data).pipe(Effect.catch((cause) => Effect.die(cause)), Effect.flatMap((data) => Effect.fail(data === undefined ? { type: error.type, message: error.message } : { type: error.type, message: error.message, data })));
26
+ }
27
+ var event2 = Effect.fn("Client.Rpc.event")(function* (definition, name, schema, event) {
28
+ const data = yield* read2(schema.schema, event.data);
29
+ return {
30
+ ...event,
31
+ type: eventType2(definition, name),
32
+ data
33
+ };
34
+ });
35
+ function eventType2(definition, name) {
36
+ return `rpc.${definition.id}.${name}`;
37
+ }
38
+
39
+ export { read2, readError2, event2, eventType2, exports_rpc_runtime };