@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.
- package/README.md +27 -3
- package/dist/chunks/contract-0d78mgf1.js +52 -0
- package/dist/chunks/contract-20jd153t.js +2089 -0
- package/dist/chunks/contract-2h09qg7t.js +62 -0
- package/dist/chunks/contract-5f99ddep.js +149 -0
- package/dist/chunks/contract-6mptkzbc.js +0 -0
- package/dist/chunks/contract-6mq2wh8y.js +33 -0
- package/dist/chunks/contract-6r38tsk5.js +0 -0
- package/dist/chunks/contract-6sr7f8yw.js +92 -0
- package/dist/chunks/contract-850x4mfy.js +948 -0
- package/dist/chunks/contract-8s2anffy.js +11 -0
- package/dist/chunks/contract-96mz1w8q.js +104 -0
- package/dist/chunks/contract-9rqn6x4v.js +16 -0
- package/dist/chunks/contract-d9s8wkgw.js +2082 -0
- package/dist/chunks/contract-mn9bt8t4.js +4 -0
- package/dist/chunks/contract-mwrzahmf.js +38 -0
- package/dist/chunks/contract-n4yq1n4a.js +111 -0
- package/dist/chunks/contract-nwcpakzx.js +12 -0
- package/dist/chunks/contract-qav6mfdz.js +0 -0
- package/dist/chunks/contract-qtt7zwr0.js +30 -0
- package/dist/chunks/contract-rhrawkx2.js +49 -0
- package/dist/chunks/contract-rrraq56y.js +67 -0
- package/dist/chunks/contract-sxt88q69.js +12 -0
- package/dist/chunks/contract-t5nrycbt.js +39 -0
- package/dist/chunks/contract-vyas3vgt.js +0 -0
- package/dist/chunks/contract-xgnj2w4v.js +20 -0
- package/dist/chunks/contract-y2etg5bs.js +9 -0
- package/dist/chunks/contract-ydhz1zrh.js +238 -0
- package/dist/chunks/contract-ztxd8xjp.js +81 -0
- package/dist/contract.d.ts +1 -0
- package/dist/contract.js +14 -0
- package/dist/effect/api/api.d.ts +3744 -0
- package/dist/effect/api/api.js +0 -0
- package/dist/effect/api.d.ts +5 -0
- package/dist/effect/api.js +0 -0
- package/dist/effect/client.d.ts +3129 -0
- package/dist/effect/client.js +15 -0
- package/dist/effect/generated/client-error.d.ts +7 -0
- package/dist/effect/generated/client-error.js +6 -0
- package/dist/effect/generated/client.d.ts +3158 -0
- package/dist/effect/generated/client.js +8 -0
- package/dist/effect/generated/index.d.ts +2 -0
- package/dist/effect/generated/index.js +12 -0
- package/dist/effect/index.d.ts +35 -0
- package/dist/effect/index.js +75 -0
- package/dist/effect/rpc.d.ts +20 -0
- package/dist/effect/rpc.js +11 -0
- package/dist/effect/service.d.ts +90 -0
- package/dist/effect/service.js +187 -0
- package/dist/mcp.d.ts +44 -0
- package/dist/mcp.js +110 -0
- package/dist/promise/api.d.ts +25 -0
- package/dist/promise/api.js +0 -0
- package/dist/promise/client.d.ts +414 -0
- package/dist/promise/client.js +14 -0
- package/dist/promise/generated/client-error.d.ts +8 -0
- package/dist/promise/generated/client-error.js +6 -0
- package/dist/promise/generated/client.d.ts +456 -0
- package/dist/promise/generated/client.js +7 -0
- package/dist/promise/generated/index.d.ts +3 -0
- package/dist/promise/generated/index.js +105 -0
- package/dist/promise/generated/types.d.ts +6642 -0
- package/dist/promise/generated/types.js +96 -0
- package/dist/promise/index.d.ts +8 -0
- package/dist/promise/index.js +115 -0
- package/dist/promise/media.d.ts +424 -0
- package/dist/promise/media.js +8 -0
- package/dist/promise/rpc.d.ts +32 -0
- package/dist/promise/rpc.js +7 -0
- package/dist/promise/service.d.ts +24 -0
- package/dist/promise/service.js +188 -0
- package/dist/pty-handoff.d.ts +12 -0
- package/dist/pty-handoff.js +17 -0
- package/dist/rpc-runtime.d.ts +20 -0
- package/dist/rpc-runtime.js +14 -0
- package/dist/service-contender.d.ts +37 -0
- package/dist/service-contender.js +10 -0
- package/dist/service-probe.d.ts +74 -0
- package/dist/service-probe.js +16 -0
- package/dist/service-timing.d.ts +12 -0
- package/dist/service-timing.js +10 -0
- package/dist/service-version.d.ts +2 -0
- package/dist/service-version.js +6 -0
- package/dist/service.d.ts +52 -0
- package/dist/service.js +1 -0
- package/dist/shared-events.d.ts +16 -0
- package/dist/shared-events.js +8 -0
- package/dist/solid/connection.d.ts +37 -0
- package/dist/solid/connection.js +10 -0
- package/dist/solid/data.d.ts +238 -0
- package/dist/solid/data.js +19 -0
- package/dist/solid/index.d.ts +5 -0
- package/dist/solid/index.js +45 -0
- package/dist/solid/pty.d.ts +80 -0
- package/dist/solid/pty.js +12 -0
- package/dist/solid/retention.d.ts +10 -0
- package/dist/solid/retention.js +6 -0
- package/dist/solid/usage.d.ts +9 -0
- package/dist/solid/usage.js +6 -0
- package/package.json +89 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// src/contract.ts
|
|
2
|
+
import { ClientApi as ClientApi2, clientNamespace as clientNamespace2, effectOmitEndpoints as effectOmitEndpoints2, groupNames as groupNames2, promiseOmitEndpoints as promiseOmitEndpoints2 } from "@radheim/protocol/client";
|
|
3
|
+
|
|
4
|
+
export { ClientApi2, clientNamespace2, effectOmitEndpoints2, groupNames2, promiseOmitEndpoints2 };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/promise/media.ts
|
|
2
|
+
var MEDIA_URI_CAPABILITY = "experimental-media-uri";
|
|
3
|
+
var CAPABILITIES_HEADER = "X-OpenCode-Capabilities";
|
|
4
|
+
var MEDIA_REF = /^media:([0-9a-f]{64})$/;
|
|
5
|
+
function mediaHashFromUri2(uri) {
|
|
6
|
+
if (!uri)
|
|
7
|
+
return;
|
|
8
|
+
return MEDIA_REF.exec(uri)?.[1];
|
|
9
|
+
}
|
|
10
|
+
function withMediaRefs2(api) {
|
|
11
|
+
return {
|
|
12
|
+
...api,
|
|
13
|
+
message: {
|
|
14
|
+
...api.message,
|
|
15
|
+
list: (input, options) => api.message.list(input, mediaRefOptions(options))
|
|
16
|
+
},
|
|
17
|
+
session: {
|
|
18
|
+
...api.session,
|
|
19
|
+
message: {
|
|
20
|
+
...api.session.message,
|
|
21
|
+
get: (input, options) => api.session.message.get(input, mediaRefOptions(options))
|
|
22
|
+
},
|
|
23
|
+
inbox: {
|
|
24
|
+
...api.session.inbox,
|
|
25
|
+
list: (input, options) => api.session.inbox.list(input, mediaRefOptions(options))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function mediaRefOptions(options) {
|
|
31
|
+
if (options?.mediaRefs === false)
|
|
32
|
+
return options;
|
|
33
|
+
const headers = new Headers(options?.headers);
|
|
34
|
+
headers.set(CAPABILITIES_HEADER, MEDIA_URI_CAPABILITY);
|
|
35
|
+
return { ...options, headers };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { mediaHashFromUri2, withMediaRefs2 };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
headers2
|
|
3
|
+
} from "./contract-6sr7f8yw.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 { Radhe } = await import("../promise/index.js");
|
|
23
|
+
const client = Radhe.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 };
|
|
@@ -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,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
make7
|
|
3
|
+
} from "./contract-5f99ddep.js";
|
|
4
|
+
import {
|
|
5
|
+
make6
|
|
6
|
+
} from "./contract-d9s8wkgw.js";
|
|
7
|
+
import {
|
|
8
|
+
makeRpc2
|
|
9
|
+
} from "./contract-ztxd8xjp.js";
|
|
10
|
+
import {
|
|
11
|
+
__export
|
|
12
|
+
} from "./contract-9rqn6x4v.js";
|
|
13
|
+
|
|
14
|
+
// src/promise/client.ts
|
|
15
|
+
var exports_client3 = {};
|
|
16
|
+
__export(exports_client3, {
|
|
17
|
+
Radhe: () => exports_client3,
|
|
18
|
+
make: () => make5
|
|
19
|
+
});
|
|
20
|
+
function make5(options) {
|
|
21
|
+
const raw = make6(options);
|
|
22
|
+
const events = make7((signal, onActivity) => raw.event.subscribe(undefined, { signal, onActivity }));
|
|
23
|
+
return {
|
|
24
|
+
...raw,
|
|
25
|
+
rpc: Object.assign(makeRpc2(raw, events), raw.rpc),
|
|
26
|
+
event: events
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { make5, exports_client3 };
|
|
@@ -0,0 +1,49 @@
|
|
|
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 isPluginNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PluginNotFoundError";
|
|
8
|
+
var isInvalidCursorError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "InvalidCursorError";
|
|
9
|
+
var isSessionNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SessionNotFoundError";
|
|
10
|
+
var isMessageNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "MessageNotFoundError";
|
|
11
|
+
var isConflictError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ConflictError";
|
|
12
|
+
var isSkillLoadError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SkillLoadError";
|
|
13
|
+
var isCommandNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "CommandNotFoundError";
|
|
14
|
+
var isCommandExecutionError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "CommandExecutionError";
|
|
15
|
+
var isSessionBusyError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SessionBusyError";
|
|
16
|
+
var isUnknownError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "UnknownError";
|
|
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 isSkillNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SkillNotFoundError";
|
|
21
|
+
var isInstructionEntryValueTooLargeError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "InstructionEntryValueTooLargeError";
|
|
22
|
+
var isProviderNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProviderNotFoundError";
|
|
23
|
+
var isModelNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ModelNotFoundError";
|
|
24
|
+
var isUnsupportedModelError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "UnsupportedModelError";
|
|
25
|
+
var isProviderRequestError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProviderRequestError";
|
|
26
|
+
var isVideoNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "VideoNotFoundError";
|
|
27
|
+
var isIntegrationNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationNotFoundError";
|
|
28
|
+
var isIntegrationAttemptNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationAttemptNotFoundError";
|
|
29
|
+
var isIntegrationMethodNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationMethodNotFoundError";
|
|
30
|
+
var isMcpServerNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "McpServerNotFoundError";
|
|
31
|
+
var isForbiddenError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ForbiddenError";
|
|
32
|
+
var isProjectNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProjectNotFoundError";
|
|
33
|
+
var isPermissionSavedNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PermissionSavedNotFoundError";
|
|
34
|
+
var isPermissionNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PermissionNotFoundError";
|
|
35
|
+
var isFileNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FileNotFoundError";
|
|
36
|
+
var isRpcError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "RpcError";
|
|
37
|
+
var isRpcInternalError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "RpcInternalError";
|
|
38
|
+
var isPtyNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PtyNotFoundError";
|
|
39
|
+
var isPtyFeatureUnsupportedError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PtyFeatureUnsupportedError";
|
|
40
|
+
var isBlobNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "BlobNotFoundError";
|
|
41
|
+
var isAutomationNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "AutomationNotFoundError";
|
|
42
|
+
var isArtifactNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ArtifactNotFoundError";
|
|
43
|
+
var isMachineNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "MachineNotFoundError";
|
|
44
|
+
var isPushDeviceNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PushDeviceNotFoundError";
|
|
45
|
+
var isShellNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ShellNotFoundError";
|
|
46
|
+
var isWorktreeError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "WorktreeError";
|
|
47
|
+
var isVcsInitNotSupportedError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "VcsInitNotSupportedError";
|
|
48
|
+
|
|
49
|
+
export { isInvalidRequestError2, isUnauthorizedError2, isLocationNotFoundError2, isServiceUnavailableError2, isAgentNotFoundError2, isPluginNotFoundError2, isInvalidCursorError2, isSessionNotFoundError2, isMessageNotFoundError2, isConflictError2, isSkillLoadError2, isCommandNotFoundError2, isCommandExecutionError2, isSessionBusyError2, isUnknownError2, isFormNotFoundError2, isFormInvalidAnswerError2, isFormAlreadySettledError2, isSkillNotFoundError2, isInstructionEntryValueTooLargeError2, isProviderNotFoundError2, isModelNotFoundError2, isUnsupportedModelError2, isProviderRequestError2, isVideoNotFoundError2, isIntegrationNotFoundError2, isIntegrationAttemptNotFoundError2, isIntegrationMethodNotFoundError2, isMcpServerNotFoundError2, isForbiddenError2, isProjectNotFoundError2, isPermissionSavedNotFoundError2, isPermissionNotFoundError2, isFileNotFoundError2, isRpcError2, isRpcInternalError2, isPtyNotFoundError2, isPtyFeatureUnsupportedError2, isBlobNotFoundError2, isAutomationNotFoundError2, isArtifactNotFoundError2, isMachineNotFoundError2, isPushDeviceNotFoundError2, isShellNotFoundError2, isWorktreeError2, isVcsInitNotSupportedError2 };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/solid/pty.ts
|
|
2
|
+
import { PersistentPty } from "@radheim/schema/persistent-pty";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
var PersistentPtyMessage2 = Schema.Union([
|
|
5
|
+
Schema.Struct({
|
|
6
|
+
type: Schema.Literal("attached"),
|
|
7
|
+
inputProtocol: Schema.optional(Schema.Number),
|
|
8
|
+
info: Schema.Struct({ size: PersistentPty.Info.fields.size }),
|
|
9
|
+
role: Schema.optional(Schema.Literals(["controller", "observer"]))
|
|
10
|
+
}),
|
|
11
|
+
Schema.Struct({ type: Schema.Literal("replay_complete") }),
|
|
12
|
+
Schema.Struct({
|
|
13
|
+
type: Schema.Literal("resized"),
|
|
14
|
+
cols: Schema.Number,
|
|
15
|
+
rows: Schema.Number,
|
|
16
|
+
checkpoint: Schema.String
|
|
17
|
+
}),
|
|
18
|
+
Schema.Struct({
|
|
19
|
+
type: Schema.Literal("controller_changed"),
|
|
20
|
+
attachmentID: Schema.optional(Schema.NullOr(Schema.String))
|
|
21
|
+
}),
|
|
22
|
+
Schema.Struct({
|
|
23
|
+
type: Schema.Literal("exited"),
|
|
24
|
+
exitCode: Schema.optional(Schema.NullOr(Schema.Number))
|
|
25
|
+
}),
|
|
26
|
+
Schema.Struct({ type: Schema.Literal("title_changed"), title: Schema.String }),
|
|
27
|
+
Schema.Struct({ type: Schema.Literal("foreground_process_changed"), process: Schema.NullOr(Schema.String) })
|
|
28
|
+
]);
|
|
29
|
+
var decodeMessage = Schema.decodeUnknownOption(Schema.fromJsonString(PersistentPtyMessage2));
|
|
30
|
+
function decodePersistentPtyMessage2(text) {
|
|
31
|
+
return decodeMessage(text);
|
|
32
|
+
}
|
|
33
|
+
function persistentPtyFrame2(size, data) {
|
|
34
|
+
const frame = new Uint8Array(5 + (data?.byteLength ?? 0));
|
|
35
|
+
const view = new DataView(frame.buffer);
|
|
36
|
+
frame[0] = data ? 1 : 0;
|
|
37
|
+
view.setUint16(1, size.cols);
|
|
38
|
+
view.setUint16(3, size.rows);
|
|
39
|
+
if (data)
|
|
40
|
+
frame.set(data, 5);
|
|
41
|
+
return frame;
|
|
42
|
+
}
|
|
43
|
+
function createPersistentPtyClient2(api, options) {
|
|
44
|
+
return {
|
|
45
|
+
async connect(input) {
|
|
46
|
+
const token = await api.experimental.persistentPty.connectToken({
|
|
47
|
+
ptyID: input.ptyID,
|
|
48
|
+
"x-opencode-ticket": "1"
|
|
49
|
+
});
|
|
50
|
+
const baseUrl = new URL(options.url);
|
|
51
|
+
if (!baseUrl.pathname.endsWith("/"))
|
|
52
|
+
baseUrl.pathname += "/";
|
|
53
|
+
const url = new URL(`api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect`, baseUrl);
|
|
54
|
+
url.searchParams.set("ticket", token.ticket);
|
|
55
|
+
url.searchParams.set("cursor", String(input.cursor));
|
|
56
|
+
url.searchParams.set("attachment_id", input.attachmentID);
|
|
57
|
+
url.searchParams.set("takeover", String(input.takeover ?? false));
|
|
58
|
+
url.searchParams.set("input_protocol", "1");
|
|
59
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
60
|
+
const socket = options.openSocket?.(url) ?? new WebSocket(url);
|
|
61
|
+
socket.binaryType = "arraybuffer";
|
|
62
|
+
return socket;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { PersistentPtyMessage2, decodePersistentPtyMessage2, persistentPtyFrame2, createPersistentPtyClient2 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/service-version.ts
|
|
2
|
+
function matchesVersion2(version, options) {
|
|
3
|
+
if (options.version === undefined)
|
|
4
|
+
return true;
|
|
5
|
+
if (version === undefined)
|
|
6
|
+
return false;
|
|
7
|
+
if (typeof options.version === "function")
|
|
8
|
+
return options.version(version);
|
|
9
|
+
return version === options.version;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { matchesVersion2 };
|
|
@@ -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 "@radheim/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.fnUntraced(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 };
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/service-timing.ts
|
|
2
|
+
var timings = new WeakMap;
|
|
3
|
+
var defaultEnsureTiming2 = {
|
|
4
|
+
pollInterval: 25,
|
|
5
|
+
requestTimeout: 2000,
|
|
6
|
+
spawnDelay: 5000,
|
|
7
|
+
maxSpawnDelay: 30000,
|
|
8
|
+
promiseTimeout: 120000,
|
|
9
|
+
stopPollInterval: 50,
|
|
10
|
+
stopPollAttempts: 100
|
|
11
|
+
};
|
|
12
|
+
function ensureTiming2(options) {
|
|
13
|
+
return timings.get(options) ?? defaultEnsureTiming2;
|
|
14
|
+
}
|
|
15
|
+
function withEnsureTiming2(options, overrides) {
|
|
16
|
+
timings.set(options, { ...defaultEnsureTiming2, ...overrides });
|
|
17
|
+
return options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { defaultEnsureTiming2, ensureTiming2, withEnsureTiming2 };
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// src/solid/connection.ts
|
|
2
|
+
import { batch, onCleanup } from "solid-js";
|
|
3
|
+
import { createStore } from "solid-js/store";
|
|
4
|
+
var connectTimeout = 2000;
|
|
5
|
+
var reconnectDelay = 1000;
|
|
6
|
+
var connectionHistoryLimit = 50;
|
|
7
|
+
var defaultIdleTimeout2 = 45000;
|
|
8
|
+
var foregroundIdleThreshold2 = 20000;
|
|
9
|
+
function createClientConnection2(initialApi, options) {
|
|
10
|
+
const abort = new AbortController;
|
|
11
|
+
const history = [];
|
|
12
|
+
const idleTimeout = options.idleTimeout ?? defaultIdleTimeout2;
|
|
13
|
+
const [connection, setConnection] = createStore({ status: "connecting", attempt: 0 });
|
|
14
|
+
let api = initialApi;
|
|
15
|
+
let pending = [];
|
|
16
|
+
let flushTimer;
|
|
17
|
+
let stream;
|
|
18
|
+
let current;
|
|
19
|
+
let run;
|
|
20
|
+
let started = false;
|
|
21
|
+
let generation = 0;
|
|
22
|
+
let lastActivity = 0;
|
|
23
|
+
let forced = false;
|
|
24
|
+
function record(status, attempt, error) {
|
|
25
|
+
history.push({ type: "client.connection", created: Date.now(), data: { status, attempt, error } });
|
|
26
|
+
if (history.length > connectionHistoryLimit)
|
|
27
|
+
history.shift();
|
|
28
|
+
}
|
|
29
|
+
function publish(event) {
|
|
30
|
+
pending.push(event);
|
|
31
|
+
if (flushTimer)
|
|
32
|
+
return;
|
|
33
|
+
flushTimer = setTimeout(() => {
|
|
34
|
+
flushTimer = undefined;
|
|
35
|
+
const events = pending;
|
|
36
|
+
pending = [];
|
|
37
|
+
batch(() => events.forEach(options.onEvent));
|
|
38
|
+
}, options.flushInterval ?? 10);
|
|
39
|
+
}
|
|
40
|
+
async function connect(signal, attempt) {
|
|
41
|
+
let connectedAt;
|
|
42
|
+
const request = new AbortController;
|
|
43
|
+
current = request;
|
|
44
|
+
const cancel = () => request.abort(signal.reason);
|
|
45
|
+
const timeout = setTimeout(() => request.abort(new Error("Timed out connecting to server")), connectTimeout);
|
|
46
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
47
|
+
let watchdog;
|
|
48
|
+
const touch = () => {
|
|
49
|
+
lastActivity = Date.now();
|
|
50
|
+
if (connectedAt === undefined)
|
|
51
|
+
return;
|
|
52
|
+
clearTimeout(watchdog);
|
|
53
|
+
watchdog = setTimeout(() => request.abort(new Error("Event stream stalled")), idleTimeout);
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
record(attempt === 0 ? "connecting" : "reconnecting", attempt);
|
|
57
|
+
options.log?.info?.("event stream connecting", { attempt });
|
|
58
|
+
const iterator = api.event.subscribe({ signal: request.signal, onActivity: touch })[Symbol.asyncIterator]();
|
|
59
|
+
const first = await iterator.next();
|
|
60
|
+
if (signal.aborted)
|
|
61
|
+
return { error: undefined, connectedAt };
|
|
62
|
+
if (first.done)
|
|
63
|
+
return {
|
|
64
|
+
error: request.signal.reason instanceof Error ? request.signal.reason : new Error("Event stream disconnected"),
|
|
65
|
+
connectedAt
|
|
66
|
+
};
|
|
67
|
+
if (first.value.type !== "server.connected")
|
|
68
|
+
return { error: new Error("Event stream did not start with server.connected"), connectedAt };
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
record("connected", attempt);
|
|
71
|
+
connectedAt = Date.now();
|
|
72
|
+
touch();
|
|
73
|
+
options.log?.info?.("event stream connected");
|
|
74
|
+
publish(first.value);
|
|
75
|
+
setConnection({ status: "connected", attempt: 0, error: undefined });
|
|
76
|
+
while (!signal.aborted) {
|
|
77
|
+
const event = await iterator.next();
|
|
78
|
+
if (signal.aborted)
|
|
79
|
+
return { error: undefined, connectedAt };
|
|
80
|
+
if (event.done)
|
|
81
|
+
return {
|
|
82
|
+
error: request.signal.reason instanceof Error ? request.signal.reason : new Error("Event stream disconnected"),
|
|
83
|
+
connectedAt
|
|
84
|
+
};
|
|
85
|
+
touch();
|
|
86
|
+
if ("durable" in event.value && event.value.durable)
|
|
87
|
+
options.log?.debug?.("event", {
|
|
88
|
+
type: event.value.type,
|
|
89
|
+
aggregateID: event.value.durable.aggregateID,
|
|
90
|
+
seq: event.value.durable.seq
|
|
91
|
+
});
|
|
92
|
+
publish(event.value);
|
|
93
|
+
}
|
|
94
|
+
return { error: undefined, connectedAt };
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return { error, connectedAt };
|
|
97
|
+
} finally {
|
|
98
|
+
request.abort();
|
|
99
|
+
if (current === request)
|
|
100
|
+
current = undefined;
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
clearTimeout(watchdog);
|
|
103
|
+
signal.removeEventListener("abort", cancel);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function runStream(active) {
|
|
107
|
+
let attempt = 0;
|
|
108
|
+
while (!abort.signal.aborted && started && generation === active) {
|
|
109
|
+
setConnection({ status: attempt === 0 ? "connecting" : "reconnecting", attempt });
|
|
110
|
+
const controller = new AbortController;
|
|
111
|
+
stream = controller;
|
|
112
|
+
const cancel = () => controller.abort(abort.signal.reason);
|
|
113
|
+
abort.signal.addEventListener("abort", cancel);
|
|
114
|
+
const result = await connect(controller.signal, attempt);
|
|
115
|
+
abort.signal.removeEventListener("abort", cancel);
|
|
116
|
+
if (abort.signal.aborted || !started || generation !== active)
|
|
117
|
+
return;
|
|
118
|
+
if (result.connectedAt !== undefined && Date.now() - result.connectedAt >= reconnectDelay)
|
|
119
|
+
attempt = 0;
|
|
120
|
+
attempt += 1;
|
|
121
|
+
const message = errorMessage(result.error);
|
|
122
|
+
record("disconnected", attempt, message);
|
|
123
|
+
options.log?.info?.("event stream disconnected", { attempt, error: message });
|
|
124
|
+
setConnection({ status: "reconnecting", attempt, error: message });
|
|
125
|
+
if (options.reconnect) {
|
|
126
|
+
const next = await options.reconnect(controller.signal).catch((error) => {
|
|
127
|
+
if (!controller.signal.aborted)
|
|
128
|
+
options.log?.info?.("server resolution failed", { attempt, error: errorMessage(error) });
|
|
129
|
+
});
|
|
130
|
+
if (abort.signal.aborted || controller.signal.aborted || !started || generation !== active)
|
|
131
|
+
return;
|
|
132
|
+
if (next) {
|
|
133
|
+
api = next;
|
|
134
|
+
if (attempt === 1)
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (forced) {
|
|
139
|
+
forced = false;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
await wait(reconnectDelay, controller.signal);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function start() {
|
|
146
|
+
if (started)
|
|
147
|
+
return run;
|
|
148
|
+
started = true;
|
|
149
|
+
forced = false;
|
|
150
|
+
const active = ++generation;
|
|
151
|
+
const previous = run;
|
|
152
|
+
const current = (async () => {
|
|
153
|
+
if (previous)
|
|
154
|
+
await previous;
|
|
155
|
+
await runStream(active);
|
|
156
|
+
})().finally(() => {
|
|
157
|
+
if (run !== current)
|
|
158
|
+
return;
|
|
159
|
+
run = undefined;
|
|
160
|
+
});
|
|
161
|
+
run = current;
|
|
162
|
+
return run;
|
|
163
|
+
}
|
|
164
|
+
function stop() {
|
|
165
|
+
if (!started)
|
|
166
|
+
return;
|
|
167
|
+
started = false;
|
|
168
|
+
generation += 1;
|
|
169
|
+
stream?.abort();
|
|
170
|
+
setConnection({ status: "connecting", attempt: 0, error: undefined });
|
|
171
|
+
}
|
|
172
|
+
function resync(reason) {
|
|
173
|
+
if (!started || connection.status !== "connected")
|
|
174
|
+
return;
|
|
175
|
+
options.log?.info?.("event stream resync", { reason, idle: Date.now() - lastActivity });
|
|
176
|
+
forced = true;
|
|
177
|
+
current?.abort(new Error(reason));
|
|
178
|
+
}
|
|
179
|
+
if (options.pageLifecycle) {
|
|
180
|
+
const pagehide = () => stop();
|
|
181
|
+
const pageshow = () => void start();
|
|
182
|
+
const visibility = () => {
|
|
183
|
+
if (document.visibilityState !== "visible")
|
|
184
|
+
return;
|
|
185
|
+
if (Date.now() - lastActivity < foregroundIdleThreshold2)
|
|
186
|
+
return;
|
|
187
|
+
resync("Page returned to the foreground after the event stream went quiet");
|
|
188
|
+
};
|
|
189
|
+
const online = () => resync("Network connection restored");
|
|
190
|
+
window.addEventListener("pagehide", pagehide);
|
|
191
|
+
window.addEventListener("pageshow", pageshow);
|
|
192
|
+
window.addEventListener("online", online);
|
|
193
|
+
document.addEventListener("visibilitychange", visibility);
|
|
194
|
+
onCleanup(() => {
|
|
195
|
+
window.removeEventListener("pagehide", pagehide);
|
|
196
|
+
window.removeEventListener("pageshow", pageshow);
|
|
197
|
+
window.removeEventListener("online", online);
|
|
198
|
+
document.removeEventListener("visibilitychange", visibility);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
start();
|
|
202
|
+
onCleanup(() => {
|
|
203
|
+
stop();
|
|
204
|
+
abort.abort();
|
|
205
|
+
if (flushTimer)
|
|
206
|
+
clearTimeout(flushTimer);
|
|
207
|
+
pending = [];
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
status: () => connection.status,
|
|
211
|
+
attempt: () => connection.attempt,
|
|
212
|
+
error: () => connection.error,
|
|
213
|
+
internal: {
|
|
214
|
+
history: () => history.slice(),
|
|
215
|
+
resync
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function errorMessage(error) {
|
|
220
|
+
if (error === undefined)
|
|
221
|
+
return;
|
|
222
|
+
if (error instanceof Error)
|
|
223
|
+
return error.message;
|
|
224
|
+
return String(error);
|
|
225
|
+
}
|
|
226
|
+
function wait(delay, signal) {
|
|
227
|
+
return new Promise((resolve) => {
|
|
228
|
+
const timer = setTimeout(done, delay);
|
|
229
|
+
signal.addEventListener("abort", done, { once: true });
|
|
230
|
+
function done() {
|
|
231
|
+
clearTimeout(timer);
|
|
232
|
+
signal.removeEventListener("abort", done);
|
|
233
|
+
resolve();
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { defaultIdleTimeout2, foregroundIdleThreshold2, createClientConnection2 };
|