@alook/daemon 0.1.49 → 0.1.51
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 +7 -5
- package/dist/cli/index.js +642 -166
- package/dist/index.js +642 -166
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7065,14 +7065,16 @@ class OpenCodeServiceLane {
|
|
|
7065
7065
|
if (!this.identity || this.identity.generation !== generation || this.isProcessClosed(this.identity.process)) {
|
|
7066
7066
|
if (/EADDRINUSE|address already in use/i.test(this.stderrBuffer))
|
|
7067
7067
|
throw new OpenCodePortBindError("OpenCode service port bind raced");
|
|
7068
|
-
|
|
7068
|
+
const process2 = this.identity?.process;
|
|
7069
|
+
const detail = scrubDriverErrorMessage(this.stderrBuffer.replaceAll(this.password, "[redacted]"), "no native stderr");
|
|
7070
|
+
throw new Error(`OpenCode service exited before readiness (code=${process2?.exitCode ?? "unknown"}, signal=${process2?.signalCode ?? "none"}): ${detail}`);
|
|
7069
7071
|
}
|
|
7070
7072
|
try {
|
|
7071
7073
|
const healthTimeoutMs = Math.max(1, Math.min(1000, deadline - Date.now(), this.options.requestTimeoutMs ?? REQUEST_TIMEOUT_MS));
|
|
7072
|
-
const { response, body } = await this.fetchJsonWithTimeout(
|
|
7074
|
+
const { response, body } = await this.fetchJsonWithTimeout(this.healthPath, { method: "GET" }, "health", healthTimeoutMs);
|
|
7073
7075
|
if (response.ok) {
|
|
7074
7076
|
const health = record4(body);
|
|
7075
|
-
if (health
|
|
7077
|
+
if (!this.acceptsHealth(health)) {
|
|
7076
7078
|
throw new OpenCodeIncompatibleError("Installed OpenCode service did not report healthy status");
|
|
7077
7079
|
}
|
|
7078
7080
|
await this.verifyOpenApi();
|
|
@@ -7089,12 +7091,27 @@ class OpenCodeServiceLane {
|
|
|
7089
7091
|
throw new Error("OpenCode service readiness timed out");
|
|
7090
7092
|
}
|
|
7091
7093
|
async verifyOpenApi() {
|
|
7092
|
-
const { response, body } = await this.fetchJsonWithTimeout(
|
|
7094
|
+
const { response, body } = await this.fetchJsonWithTimeout(this.openApiPath, { method: "GET" }, "OpenAPI");
|
|
7093
7095
|
if (!response.ok)
|
|
7094
7096
|
throw new OpenCodeIncompatibleError("Installed OpenCode service does not expose its OpenAPI document");
|
|
7095
7097
|
const document = record4(body);
|
|
7096
7098
|
const paths = record4(document?.paths);
|
|
7097
|
-
const required =
|
|
7099
|
+
const required = this.requiredApiPaths;
|
|
7100
|
+
if (!paths || required.some((path9) => !record4(paths[path9]))) {
|
|
7101
|
+
throw new OpenCodeIncompatibleError("Installed OpenCode service is missing required session capabilities");
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
get healthPath() {
|
|
7105
|
+
return "/global/health";
|
|
7106
|
+
}
|
|
7107
|
+
get openApiPath() {
|
|
7108
|
+
return "/doc";
|
|
7109
|
+
}
|
|
7110
|
+
acceptsHealth(health) {
|
|
7111
|
+
return health?.healthy === true;
|
|
7112
|
+
}
|
|
7113
|
+
get requiredApiPaths() {
|
|
7114
|
+
return [
|
|
7098
7115
|
"/api/session",
|
|
7099
7116
|
"/api/session/active",
|
|
7100
7117
|
"/api/session/{sessionID}/prompt",
|
|
@@ -7106,12 +7123,12 @@ class OpenCodeServiceLane {
|
|
|
7106
7123
|
"/api/session/{sessionID}/permission/{requestID}/reply",
|
|
7107
7124
|
"/api/event"
|
|
7108
7125
|
];
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7126
|
+
}
|
|
7127
|
+
get selectedModel() {
|
|
7128
|
+
return parseModelRef(resolveLaunchFieldsOrDefault(this.ctx.config.runtimeConfig).model);
|
|
7112
7129
|
}
|
|
7113
7130
|
async openSession(resumeId) {
|
|
7114
|
-
const model =
|
|
7131
|
+
const model = this.selectedModel;
|
|
7115
7132
|
if (resumeId) {
|
|
7116
7133
|
const { response: response2, body: body2 } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(resumeId)}`, { method: "GET" }, "session resume");
|
|
7117
7134
|
if (response2.status === 404) {
|
|
@@ -7454,7 +7471,7 @@ class OpenCodeServiceLane {
|
|
|
7454
7471
|
async handleLiveEvent(value) {
|
|
7455
7472
|
const event = record4(value);
|
|
7456
7473
|
const data = record4(event?.data);
|
|
7457
|
-
if (event?.type !==
|
|
7474
|
+
if (event?.type !== this.permissionEventType || data?.sessionID !== this.sessionId)
|
|
7458
7475
|
return;
|
|
7459
7476
|
if (typeof data.id !== "string" || !/^per/.test(data.id)) {
|
|
7460
7477
|
throw new OpenCodeProtocolError("OpenCode emitted a malformed permission request");
|
|
@@ -7477,13 +7494,19 @@ class OpenCodeServiceLane {
|
|
|
7477
7494
|
}
|
|
7478
7495
|
}
|
|
7479
7496
|
}
|
|
7497
|
+
get permissionEventType() {
|
|
7498
|
+
return "permission.v2.asked";
|
|
7499
|
+
}
|
|
7500
|
+
get permissionReply() {
|
|
7501
|
+
return { reply: "once" };
|
|
7502
|
+
}
|
|
7480
7503
|
async replyPermission(requestId) {
|
|
7481
7504
|
if (this.handledPermissions.has(requestId))
|
|
7482
7505
|
return;
|
|
7483
7506
|
const existing = this.permissionFlights.get(requestId);
|
|
7484
7507
|
if (existing)
|
|
7485
7508
|
return existing;
|
|
7486
|
-
const flight = this.requestNoContent(`/api/session/${encodeURIComponent(this.sessionId)}/permission/${encodeURIComponent(requestId)}/reply`, "POST",
|
|
7509
|
+
const flight = this.requestNoContent(`/api/session/${encodeURIComponent(this.sessionId)}/permission/${encodeURIComponent(requestId)}/reply`, "POST", this.permissionReply, "permission reply").catch((error) => {
|
|
7487
7510
|
if (!(error instanceof OpenCodeHttpError) || error.status !== 404)
|
|
7488
7511
|
throw error;
|
|
7489
7512
|
}).then(() => {
|
|
@@ -7860,6 +7883,28 @@ async function legacyOpenCodeApiEnvironment(environment, model) {
|
|
|
7860
7883
|
return credential?.type === "api" && typeof credential.key === "string" && credential.key.trim() ? { [name]: credential.key } : {};
|
|
7861
7884
|
}
|
|
7862
7885
|
|
|
7886
|
+
// agent-driver/dist/adapters/opencode/compatibility.js
|
|
7887
|
+
var OPEN_CODE_V1 = {
|
|
7888
|
+
major: 1,
|
|
7889
|
+
modelArgs: ["models", "--pure"],
|
|
7890
|
+
serviceArgs: ["serve", "--pure"],
|
|
7891
|
+
sessionListArgs: (maxCount) => ["session", "list", "--format", "json", "--max-count", String(maxCount), "--pure"]
|
|
7892
|
+
};
|
|
7893
|
+
var OPEN_CODE_V2 = {
|
|
7894
|
+
major: 2,
|
|
7895
|
+
modelArgs: ["models", "--standalone"],
|
|
7896
|
+
serviceArgs: ["serve"],
|
|
7897
|
+
sessionListArgs: (maxCount) => ["api", "--standalone", "GET", `/api/session?parentID=null&order=desc&limit=${maxCount}`]
|
|
7898
|
+
};
|
|
7899
|
+
function resolveOpenCodeCompatibility(version) {
|
|
7900
|
+
const match = version?.trim().match(/^(?:opencode\s+)?v?(\d+)\.\d+\.\d+(?:[-+][\w.-]+)?$/i);
|
|
7901
|
+
if (match?.[1] === "1")
|
|
7902
|
+
return OPEN_CODE_V1;
|
|
7903
|
+
if (match?.[1] === "2")
|
|
7904
|
+
return OPEN_CODE_V2;
|
|
7905
|
+
throw new Error("Installed OpenCode CLI version is unrecognized or has an unsupported major version");
|
|
7906
|
+
}
|
|
7907
|
+
|
|
7863
7908
|
// agent-driver/dist/adapters/opencode/recent-context.js
|
|
7864
7909
|
var OPENCODE_DISCOVERY_TIMEOUT_MS = 15000;
|
|
7865
7910
|
var OPENCODE_DISCOVERY_OUTPUT_MAX_BYTES = 4 * 1024 * 1024;
|
|
@@ -7893,6 +7938,7 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
7893
7938
|
const collector = new RecentContextCollector(request, "unavailable");
|
|
7894
7939
|
if (collector.satisfied)
|
|
7895
7940
|
return collector.result();
|
|
7941
|
+
const compatibility = dependencies.compatibility ?? OPEN_CODE_V1;
|
|
7896
7942
|
const startedAt = Date.now();
|
|
7897
7943
|
const timeoutMs = dependencies.timeoutMs ?? OPENCODE_DISCOVERY_TIMEOUT_MS;
|
|
7898
7944
|
let remainingOutputBytes = dependencies.outputMaxBytes ?? OPENCODE_DISCOVERY_OUTPUT_MAX_BYTES;
|
|
@@ -7901,7 +7947,7 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
7901
7947
|
const remainingTimeoutMs = timeoutMs - (Date.now() - startedAt);
|
|
7902
7948
|
if (remainingTimeoutMs <= 0)
|
|
7903
7949
|
throw new Error("OpenCode discovery timed out");
|
|
7904
|
-
const spec = resolveSpawnSpec("opencode", [
|
|
7950
|
+
const spec = resolveSpawnSpec("opencode", [...compatibility.sessionListArgs(maxCount)], request.command);
|
|
7905
7951
|
const commandOutput = await collectCommandOutput(spec.command, spec.args, spec.shell, dependencies, remainingTimeoutMs, remainingOutputBytes);
|
|
7906
7952
|
remainingOutputBytes -= commandOutput.outputBytes;
|
|
7907
7953
|
let parsed;
|
|
@@ -7910,14 +7956,17 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
7910
7956
|
} catch {
|
|
7911
7957
|
throw new Error("OpenCode session listing returned invalid JSON");
|
|
7912
7958
|
}
|
|
7959
|
+
if (compatibility.major === 2)
|
|
7960
|
+
parsed = asRecord(parsed)?.data;
|
|
7913
7961
|
if (!Array.isArray(parsed))
|
|
7914
7962
|
throw new Error("OpenCode session listing returned an invalid response");
|
|
7915
7963
|
for (const value of parsed) {
|
|
7916
7964
|
const session = asRecord(value);
|
|
7917
7965
|
if (!session)
|
|
7918
7966
|
continue;
|
|
7919
|
-
const modifiedAt = session.updated ?? session.updatedAt;
|
|
7920
|
-
|
|
7967
|
+
const modifiedAt = compatibility.major === 2 ? asRecord(session.time)?.updated : session.updated ?? session.updatedAt;
|
|
7968
|
+
const projectPath = compatibility.major === 2 ? asRecord(session.location)?.directory : session.directory;
|
|
7969
|
+
collector.add({ projectPath, modifiedAt });
|
|
7921
7970
|
}
|
|
7922
7971
|
if (collector.satisfied || parsed.length < maxCount)
|
|
7923
7972
|
break;
|
|
@@ -7929,6 +7978,419 @@ async function discoverOpenCodeRecentContext(request, dependencies = {}) {
|
|
|
7929
7978
|
return collector.result();
|
|
7930
7979
|
}
|
|
7931
7980
|
|
|
7981
|
+
// agent-driver/dist/adapters/opencode/v2-service-lane.js
|
|
7982
|
+
class OpenCodeV2ServiceLane extends OpenCodeServiceLane {
|
|
7983
|
+
root = null;
|
|
7984
|
+
v2AdmissionTail = Promise.resolve();
|
|
7985
|
+
v2EvaluationTimer;
|
|
7986
|
+
v2Evaluating = false;
|
|
7987
|
+
projectedMessages = new Set;
|
|
7988
|
+
liveTools = new Map;
|
|
7989
|
+
settledTools = new Set;
|
|
7990
|
+
usage = new SettledUsageProjector;
|
|
7991
|
+
get healthPath() {
|
|
7992
|
+
return "/api/info";
|
|
7993
|
+
}
|
|
7994
|
+
get openApiPath() {
|
|
7995
|
+
return "/openapi.json";
|
|
7996
|
+
}
|
|
7997
|
+
acceptsHealth(health) {
|
|
7998
|
+
if (typeof health?.version !== "string" || !Number.isInteger(health.pid) || Number(health.pid) < 1)
|
|
7999
|
+
return false;
|
|
8000
|
+
try {
|
|
8001
|
+
return resolveOpenCodeCompatibility(health.version).major === 2;
|
|
8002
|
+
} catch {
|
|
8003
|
+
return false;
|
|
8004
|
+
}
|
|
8005
|
+
}
|
|
8006
|
+
get requiredApiPaths() {
|
|
8007
|
+
return [
|
|
8008
|
+
"/api/session",
|
|
8009
|
+
"/api/session/active",
|
|
8010
|
+
"/api/session/{sessionID}",
|
|
8011
|
+
"/api/session/{sessionID}/prompt",
|
|
8012
|
+
"/api/session/{sessionID}/inbox",
|
|
8013
|
+
"/api/session/{sessionID}/message",
|
|
8014
|
+
"/api/session/{sessionID}/message/{messageID}",
|
|
8015
|
+
"/api/session/{sessionID}/interrupt",
|
|
8016
|
+
"/api/session/{sessionID}/model",
|
|
8017
|
+
"/api/session/{sessionID}/permission",
|
|
8018
|
+
"/api/session/{sessionID}/permission/{requestID}/reply",
|
|
8019
|
+
"/api/event"
|
|
8020
|
+
];
|
|
8021
|
+
}
|
|
8022
|
+
get selectedModel() {
|
|
8023
|
+
const model = super.selectedModel;
|
|
8024
|
+
if (typeof model?.id !== "string")
|
|
8025
|
+
return model;
|
|
8026
|
+
const hash = model.id.lastIndexOf("#");
|
|
8027
|
+
return hash > 0 && hash < model.id.length - 1 ? { ...model, id: model.id.slice(0, hash), variant: model.id.slice(hash + 1) } : model;
|
|
8028
|
+
}
|
|
8029
|
+
get permissionEventType() {
|
|
8030
|
+
return "permission.asked";
|
|
8031
|
+
}
|
|
8032
|
+
get permissionReply() {
|
|
8033
|
+
return { decision: "once" };
|
|
8034
|
+
}
|
|
8035
|
+
protocolFailure(message, cause) {
|
|
8036
|
+
super.protocolFailure(cause === undefined ? message : `${message}: ${scrubDriverErrorMessage(cause)}`);
|
|
8037
|
+
}
|
|
8038
|
+
async primeHistory() {}
|
|
8039
|
+
startStreams() {
|
|
8040
|
+
const identity = this.identity;
|
|
8041
|
+
this.liveTask = this.runLiveStream(identity).catch((error) => {
|
|
8042
|
+
if (!this.stopping)
|
|
8043
|
+
this.protocolFailure("OpenCode CLI v2 live stream failed", error);
|
|
8044
|
+
});
|
|
8045
|
+
}
|
|
8046
|
+
async recoverPendingPermissions() {
|
|
8047
|
+
await super.recoverPendingPermissions();
|
|
8048
|
+
const root = this.root;
|
|
8049
|
+
if (root)
|
|
8050
|
+
for (const message of await this.messagesAfter(root))
|
|
8051
|
+
this.projectTools(message);
|
|
8052
|
+
this.schedule();
|
|
8053
|
+
}
|
|
8054
|
+
async handleLiveEvent(value) {
|
|
8055
|
+
await super.handleLiveEvent(value);
|
|
8056
|
+
const event = record4(value);
|
|
8057
|
+
const data = record4(event?.data);
|
|
8058
|
+
if (data?.sessionID !== this.sessionId || !this.root)
|
|
8059
|
+
return;
|
|
8060
|
+
switch (event?.type) {
|
|
8061
|
+
case "session.step.started":
|
|
8062
|
+
this.events.emit("runtime_event", {
|
|
8063
|
+
kind: "internal_progress",
|
|
8064
|
+
source: "opencode.service",
|
|
8065
|
+
itemType: "step_started"
|
|
8066
|
+
});
|
|
8067
|
+
break;
|
|
8068
|
+
case "session.tool.input.started": {
|
|
8069
|
+
const key = this.toolKey(data.assistantMessageID, data.id);
|
|
8070
|
+
if (key && typeof data.name === "string" && !this.liveTools.has(key) && !this.settledTools.has(key)) {
|
|
8071
|
+
this.liveTools.set(key, { name: data.name, called: false });
|
|
8072
|
+
}
|
|
8073
|
+
break;
|
|
8074
|
+
}
|
|
8075
|
+
case "session.tool.called":
|
|
8076
|
+
this.projectTool(data);
|
|
8077
|
+
break;
|
|
8078
|
+
case "session.tool.success":
|
|
8079
|
+
case "session.tool.failed": {
|
|
8080
|
+
this.finishTool(this.toolKey(data.assistantMessageID, data.id));
|
|
8081
|
+
break;
|
|
8082
|
+
}
|
|
8083
|
+
case "session.compaction.started":
|
|
8084
|
+
this.events.emit("runtime_event", { kind: "compaction_started" });
|
|
8085
|
+
break;
|
|
8086
|
+
case "session.compaction.failed":
|
|
8087
|
+
case "session.compaction.ended":
|
|
8088
|
+
this.events.emit("runtime_event", { kind: "compaction_finished" });
|
|
8089
|
+
break;
|
|
8090
|
+
default:
|
|
8091
|
+
break;
|
|
8092
|
+
}
|
|
8093
|
+
this.schedule();
|
|
8094
|
+
}
|
|
8095
|
+
async send(input) {
|
|
8096
|
+
if (!this.ready || this.stopping || !this.sessionId || !this.identityMatches())
|
|
8097
|
+
return { ok: false, reason: "closed" };
|
|
8098
|
+
if (input.mode === "idle") {
|
|
8099
|
+
if (this.root)
|
|
8100
|
+
return { ok: false, reason: "runtime_busy" };
|
|
8101
|
+
return this.beginRoot(input);
|
|
8102
|
+
}
|
|
8103
|
+
const root = this.root;
|
|
8104
|
+
if (!root)
|
|
8105
|
+
return { ok: false, reason: "not_ready" };
|
|
8106
|
+
return this.admit(input.text, "steer", this.newMessageId(), root);
|
|
8107
|
+
}
|
|
8108
|
+
async beginRoot(input) {
|
|
8109
|
+
const page = await this.messagePage(undefined, 1);
|
|
8110
|
+
if (this.stopping || !this.identityMatches())
|
|
8111
|
+
return { ok: false, reason: "closed" };
|
|
8112
|
+
const receipt = input.terminalOwner?.startsWith("msg_") ? input.terminalOwner : this.newMessageId();
|
|
8113
|
+
const root = {
|
|
8114
|
+
receipt,
|
|
8115
|
+
baseline: typeof page.data[0]?.id === "string" ? page.data[0].id : null,
|
|
8116
|
+
inputs: new Set,
|
|
8117
|
+
generation: 0,
|
|
8118
|
+
pending: 0
|
|
8119
|
+
};
|
|
8120
|
+
this.root = root;
|
|
8121
|
+
return this.admit(input.text, "queue", receipt, root);
|
|
8122
|
+
}
|
|
8123
|
+
admit(text, delivery, id, root) {
|
|
8124
|
+
root.generation += 1;
|
|
8125
|
+
root.pending += 1;
|
|
8126
|
+
const run = this.v2AdmissionTail.then(async () => {
|
|
8127
|
+
await this.waitForLiveStream();
|
|
8128
|
+
if (this.root !== root || this.stopping || !this.identityMatches())
|
|
8129
|
+
return { ok: false, reason: "closed" };
|
|
8130
|
+
const { response, body } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/prompt`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id, text, delivery, resume: true }) }, "prompt admission");
|
|
8131
|
+
if (!response.ok)
|
|
8132
|
+
throw new OpenCodeHttpError(response.status, "prompt admission");
|
|
8133
|
+
const input = record4(record4(body)?.data);
|
|
8134
|
+
if (input?.id !== id || input.sessionID !== this.sessionId || input.type !== "user" || input.delivery !== delivery) {
|
|
8135
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid prompt receipt");
|
|
8136
|
+
}
|
|
8137
|
+
if (this.root !== root || this.stopping || !this.identityMatches())
|
|
8138
|
+
return { ok: false, reason: "closed" };
|
|
8139
|
+
root.inputs.add(id);
|
|
8140
|
+
return { ok: true, acceptedAs: delivery === "steer" ? "steer" : "prompt", receipt: id };
|
|
8141
|
+
}).catch((error) => {
|
|
8142
|
+
if (this.root === root && !this.stopping)
|
|
8143
|
+
this.protocolFailure("OpenCode CLI v2 prompt admission failed", error);
|
|
8144
|
+
throw error;
|
|
8145
|
+
}).finally(() => {
|
|
8146
|
+
root.pending -= 1;
|
|
8147
|
+
this.schedule();
|
|
8148
|
+
});
|
|
8149
|
+
this.v2AdmissionTail = run.then(() => {}, () => {});
|
|
8150
|
+
return run;
|
|
8151
|
+
}
|
|
8152
|
+
async messagePage(cursor, limit = 100) {
|
|
8153
|
+
const query = new URLSearchParams({ limit: String(limit), ...cursor ? { cursor } : { order: "desc" } });
|
|
8154
|
+
const { response, body } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/message?${query}`, { method: "GET" }, "message recovery");
|
|
8155
|
+
if (!response.ok)
|
|
8156
|
+
throw new OpenCodeHttpError(response.status, "message recovery");
|
|
8157
|
+
const page = record4(body);
|
|
8158
|
+
const cursors = record4(page?.cursor);
|
|
8159
|
+
if (!Array.isArray(page?.data) || !cursors || page.data.some((item) => typeof record4(item)?.id !== "string")) {
|
|
8160
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid message page");
|
|
8161
|
+
}
|
|
8162
|
+
if (cursors.next !== undefined && cursors.next !== null && typeof cursors.next !== "string")
|
|
8163
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid message cursor");
|
|
8164
|
+
return { data: page.data, next: typeof cursors.next === "string" ? cursors.next : undefined };
|
|
8165
|
+
}
|
|
8166
|
+
async messagesAfter(root) {
|
|
8167
|
+
const messages = [];
|
|
8168
|
+
const cursors = new Set;
|
|
8169
|
+
let cursor;
|
|
8170
|
+
for (;; ) {
|
|
8171
|
+
const page = await this.messagePage(cursor);
|
|
8172
|
+
if (this.root !== root || this.stopping)
|
|
8173
|
+
return [];
|
|
8174
|
+
for (const message of page.data) {
|
|
8175
|
+
if (message.id === root.baseline)
|
|
8176
|
+
return messages.reverse();
|
|
8177
|
+
messages.push(message);
|
|
8178
|
+
}
|
|
8179
|
+
if (!page.next) {
|
|
8180
|
+
if (root.baseline !== null)
|
|
8181
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 message recovery lost its root boundary");
|
|
8182
|
+
return messages.reverse();
|
|
8183
|
+
}
|
|
8184
|
+
if (cursors.has(page.next))
|
|
8185
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 message cursor did not advance");
|
|
8186
|
+
cursors.add(page.next);
|
|
8187
|
+
cursor = page.next;
|
|
8188
|
+
}
|
|
8189
|
+
}
|
|
8190
|
+
schedule() {
|
|
8191
|
+
if (!this.root || this.stopping || this.v2EvaluationTimer || this.v2Evaluating)
|
|
8192
|
+
return;
|
|
8193
|
+
this.v2EvaluationTimer = setTimeout(() => {
|
|
8194
|
+
this.v2EvaluationTimer = undefined;
|
|
8195
|
+
this.evaluate();
|
|
8196
|
+
}, this.options.activePollMs ?? 100);
|
|
8197
|
+
this.v2EvaluationTimer.unref?.();
|
|
8198
|
+
}
|
|
8199
|
+
async isActive() {
|
|
8200
|
+
const { response, body } = await this.fetchJsonWithTimeout("/api/session/active", { method: "GET" }, "active session query");
|
|
8201
|
+
if (!response.ok)
|
|
8202
|
+
throw new OpenCodeHttpError(response.status, "active session query");
|
|
8203
|
+
const active = record4(record4(body)?.data);
|
|
8204
|
+
if (!active)
|
|
8205
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned invalid active session data");
|
|
8206
|
+
return active[this.sessionId] !== undefined;
|
|
8207
|
+
}
|
|
8208
|
+
async evaluate() {
|
|
8209
|
+
const root = this.root;
|
|
8210
|
+
const identity = this.identity;
|
|
8211
|
+
if (!root || !identity || this.stopping || root.pending > 0 || root.inputs.size === 0 || this.v2Evaluating)
|
|
8212
|
+
return;
|
|
8213
|
+
this.v2Evaluating = true;
|
|
8214
|
+
const generation = root.generation;
|
|
8215
|
+
const current = () => this.root === root && root.generation === generation && root.pending === 0 && this.isIdentity(identity);
|
|
8216
|
+
try {
|
|
8217
|
+
if (await this.isActive())
|
|
8218
|
+
return;
|
|
8219
|
+
if (!current())
|
|
8220
|
+
return;
|
|
8221
|
+
const messages = await this.messagesAfter(root);
|
|
8222
|
+
if (!current())
|
|
8223
|
+
return;
|
|
8224
|
+
let lastInput = -1;
|
|
8225
|
+
const delivered = new Set;
|
|
8226
|
+
for (const [index, message] of messages.entries()) {
|
|
8227
|
+
if (message.type === "user" && typeof message.id === "string" && root.inputs.has(message.id)) {
|
|
8228
|
+
delivered.add(message.id);
|
|
8229
|
+
lastInput = index;
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
const idle = messages.slice(lastInput + 1).reverse().find((message) => message.type === "idle");
|
|
8233
|
+
if (delivered.size !== root.inputs.size) {
|
|
8234
|
+
const { response, body } = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/inbox`, { method: "GET" }, "pending input recovery");
|
|
8235
|
+
if (!response.ok)
|
|
8236
|
+
throw new OpenCodeHttpError(response.status, "pending input recovery");
|
|
8237
|
+
const pending = record4(body)?.data;
|
|
8238
|
+
if (!Array.isArray(pending))
|
|
8239
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned invalid inbox data");
|
|
8240
|
+
if (!current())
|
|
8241
|
+
return;
|
|
8242
|
+
const retained = new Set(pending.map((item) => record4(item)?.id));
|
|
8243
|
+
for (const id of root.inputs) {
|
|
8244
|
+
if (delivered.has(id) || retained.has(id))
|
|
8245
|
+
continue;
|
|
8246
|
+
const recovered = await this.fetchJsonWithTimeout(`/api/session/${encodeURIComponent(this.sessionId)}/message/${encodeURIComponent(id)}`, { method: "GET" }, "accepted input recovery");
|
|
8247
|
+
if (!current())
|
|
8248
|
+
return;
|
|
8249
|
+
if (recovered.response.status === 404)
|
|
8250
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 lost an accepted input from both inbox and messages");
|
|
8251
|
+
if (!recovered.response.ok)
|
|
8252
|
+
throw new OpenCodeHttpError(recovered.response.status, "accepted input recovery");
|
|
8253
|
+
const message = record4(record4(recovered.body)?.data);
|
|
8254
|
+
if (message?.id !== id || message.type !== "user")
|
|
8255
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid recovered input");
|
|
8256
|
+
}
|
|
8257
|
+
return;
|
|
8258
|
+
}
|
|
8259
|
+
for (const message of messages) {
|
|
8260
|
+
this.projectTools(message);
|
|
8261
|
+
this.projectMessage(message);
|
|
8262
|
+
}
|
|
8263
|
+
if (!idle || await this.isActive() || !current())
|
|
8264
|
+
return;
|
|
8265
|
+
if (!["succeeded", "failed", "interrupted"].includes(String(idle.outcome))) {
|
|
8266
|
+
throw new OpenCodeProtocolError("OpenCode CLI v2 returned an invalid idle outcome");
|
|
8267
|
+
}
|
|
8268
|
+
this.root = null;
|
|
8269
|
+
if (idle.outcome === "failed") {
|
|
8270
|
+
const error = record4(idle.error);
|
|
8271
|
+
this.events.emit("runtime_event", {
|
|
8272
|
+
kind: "error",
|
|
8273
|
+
code: "opencode.turn_failed",
|
|
8274
|
+
message: typeof error?.message === "string" ? error.message : "OpenCode CLI v2 execution failed"
|
|
8275
|
+
});
|
|
8276
|
+
}
|
|
8277
|
+
this.events.emit("runtime_event", {
|
|
8278
|
+
kind: "turn_end",
|
|
8279
|
+
sessionId: this.sessionId,
|
|
8280
|
+
turnOwner: root.receipt
|
|
8281
|
+
});
|
|
8282
|
+
} catch (error) {
|
|
8283
|
+
if (!current() || this.stopping)
|
|
8284
|
+
return;
|
|
8285
|
+
if (error instanceof OpenCodeProtocolError || error instanceof OpenCodeHttpError && error.status < 500) {
|
|
8286
|
+
this.protocolFailure("OpenCode CLI v2 durable message recovery failed", error);
|
|
8287
|
+
} else
|
|
8288
|
+
this.diagnostic("warning", "OpenCode CLI v2 message recovery temporarily unavailable; keeping the root active");
|
|
8289
|
+
} finally {
|
|
8290
|
+
this.v2Evaluating = false;
|
|
8291
|
+
this.schedule();
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
8294
|
+
toolKey(messageId, id) {
|
|
8295
|
+
return typeof messageId === "string" && typeof id === "string" ? `${messageId}:${id}` : undefined;
|
|
8296
|
+
}
|
|
8297
|
+
projectTool(data) {
|
|
8298
|
+
const key = this.toolKey(data.assistantMessageID, data.id);
|
|
8299
|
+
if (!key || this.settledTools.has(key))
|
|
8300
|
+
return;
|
|
8301
|
+
const tool = this.liveTools.get(key) ?? { name: typeof data.name === "string" ? data.name : "OpenCode tool", called: false };
|
|
8302
|
+
if (tool.called)
|
|
8303
|
+
return;
|
|
8304
|
+
tool.called = true;
|
|
8305
|
+
this.liveTools.set(key, tool);
|
|
8306
|
+
this.events.emit("runtime_event", { kind: "tool_call", callId: key, name: tool.name, input: data.input });
|
|
8307
|
+
}
|
|
8308
|
+
finishTool(key) {
|
|
8309
|
+
if (!key || this.settledTools.has(key))
|
|
8310
|
+
return;
|
|
8311
|
+
const tool = this.liveTools.get(key);
|
|
8312
|
+
if (!tool?.called)
|
|
8313
|
+
return;
|
|
8314
|
+
this.liveTools.delete(key);
|
|
8315
|
+
this.settledTools.add(key);
|
|
8316
|
+
this.events.emit("runtime_event", { kind: "tool_output", callId: key, name: tool.name });
|
|
8317
|
+
}
|
|
8318
|
+
projectTools(message) {
|
|
8319
|
+
if (message.type !== "assistant" || !Array.isArray(message.content) || !this.root || this.stopping)
|
|
8320
|
+
return;
|
|
8321
|
+
for (const value of message.content) {
|
|
8322
|
+
const tool = record4(value);
|
|
8323
|
+
const state = record4(tool?.state);
|
|
8324
|
+
if (tool?.type !== "tool" || !["running", "completed", "error"].includes(String(state?.status)))
|
|
8325
|
+
continue;
|
|
8326
|
+
this.projectTool({ assistantMessageID: message.id, id: tool.id, name: tool.name, input: state?.input });
|
|
8327
|
+
if (state?.status !== "running")
|
|
8328
|
+
this.finishTool(this.toolKey(message.id, tool.id));
|
|
8329
|
+
}
|
|
8330
|
+
}
|
|
8331
|
+
projectMessage(message) {
|
|
8332
|
+
if (message.type !== "assistant" || typeof message.id !== "string" || this.projectedMessages.has(message.id))
|
|
8333
|
+
return;
|
|
8334
|
+
const time = record4(message.time);
|
|
8335
|
+
if (time?.completed === undefined)
|
|
8336
|
+
return;
|
|
8337
|
+
this.projectedMessages.add(message.id);
|
|
8338
|
+
if (Array.isArray(message.content))
|
|
8339
|
+
for (const value of message.content) {
|
|
8340
|
+
const content = record4(value);
|
|
8341
|
+
if (typeof content?.text !== "string" || !content.text)
|
|
8342
|
+
continue;
|
|
8343
|
+
if (content.type === "text")
|
|
8344
|
+
this.events.emit("runtime_event", { kind: "assistant_message_completed", text: content.text });
|
|
8345
|
+
if (content.type === "reasoning")
|
|
8346
|
+
this.events.emit("runtime_event", { kind: "assistant_reasoning_completed", text: content.text });
|
|
8347
|
+
}
|
|
8348
|
+
const tokens = record4(message.tokens);
|
|
8349
|
+
if (!tokens || !this.sessionId)
|
|
8350
|
+
return;
|
|
8351
|
+
const cache = record4(tokens.cache);
|
|
8352
|
+
const identity = { runtime: "opencode", backendSessionId: this.sessionId, providerRecordId: message.id };
|
|
8353
|
+
const usage = this.usage.project({
|
|
8354
|
+
...identity,
|
|
8355
|
+
source: "opencode.v2",
|
|
8356
|
+
input: tokens.input,
|
|
8357
|
+
output: tokens.output,
|
|
8358
|
+
reasoning: tokens.reasoning,
|
|
8359
|
+
cacheRead: cache?.read,
|
|
8360
|
+
cacheWrite: cache?.write,
|
|
8361
|
+
inputIncludesCache: false,
|
|
8362
|
+
outputIncludesReasoning: false
|
|
8363
|
+
});
|
|
8364
|
+
if (usage)
|
|
8365
|
+
this.events.emit("runtime_event", usage);
|
|
8366
|
+
this.usage.release(identity);
|
|
8367
|
+
}
|
|
8368
|
+
async interrupt(_input) {
|
|
8369
|
+
const root = this.root;
|
|
8370
|
+
if (!root || !this.ready || this.stopping || !this.identityMatches())
|
|
8371
|
+
return false;
|
|
8372
|
+
root.generation += 1;
|
|
8373
|
+
root.pending += 1;
|
|
8374
|
+
try {
|
|
8375
|
+
await this.requestNoContent(`/api/session/${encodeURIComponent(this.sessionId)}/interrupt?resume=false`, "POST", undefined, "session interrupt");
|
|
8376
|
+
return true;
|
|
8377
|
+
} catch (error) {
|
|
8378
|
+
if (!this.stopping)
|
|
8379
|
+
this.stop({ reason: "interrupt_timeout", forceAfterMs: 0 });
|
|
8380
|
+
throw error;
|
|
8381
|
+
} finally {
|
|
8382
|
+
root.pending -= 1;
|
|
8383
|
+
this.schedule();
|
|
8384
|
+
}
|
|
8385
|
+
}
|
|
8386
|
+
stop(input = {}) {
|
|
8387
|
+
this.root = null;
|
|
8388
|
+
if (this.v2EvaluationTimer)
|
|
8389
|
+
clearTimeout(this.v2EvaluationTimer);
|
|
8390
|
+
return super.stop(input);
|
|
8391
|
+
}
|
|
8392
|
+
}
|
|
8393
|
+
|
|
7932
8394
|
// agent-driver/dist/adapters/opencode/index.js
|
|
7933
8395
|
function createOpenCodeMessageId() {
|
|
7934
8396
|
return `msg_${randomBytes4(16).toString("hex")}`;
|
|
@@ -7936,6 +8398,7 @@ function createOpenCodeMessageId() {
|
|
|
7936
8398
|
|
|
7937
8399
|
class OpenCodeDriver {
|
|
7938
8400
|
outputProbe;
|
|
8401
|
+
versionProbe;
|
|
7939
8402
|
id = "opencode";
|
|
7940
8403
|
instructionDelivery = { kind: "workspace_file", canonical: "AGENTS.md", aliases: ["CLAUDE.md"] };
|
|
7941
8404
|
execution = {
|
|
@@ -7944,17 +8407,29 @@ class OpenCodeDriver {
|
|
|
7944
8407
|
wakeStart: "immediate",
|
|
7945
8408
|
terminalOwnership: "transport_request"
|
|
7946
8409
|
};
|
|
7947
|
-
constructor(outputProbe = probeCommandOutput) {
|
|
8410
|
+
constructor(outputProbe = probeCommandOutput, versionProbe = probeCliRuntime) {
|
|
7948
8411
|
this.outputProbe = outputProbe;
|
|
8412
|
+
this.versionProbe = versionProbe;
|
|
7949
8413
|
}
|
|
7950
8414
|
discoverRecentContext(request) {
|
|
7951
|
-
|
|
8415
|
+
if (request.recentProjectsTopK === 0)
|
|
8416
|
+
return discoverOpenCodeRecentContext(request);
|
|
8417
|
+
const result = this.versionProbe("opencode", {}, request.command);
|
|
8418
|
+
if (result.status !== "healthy")
|
|
8419
|
+
throw new Error("Installed OpenCode CLI could not report its version");
|
|
8420
|
+
return discoverOpenCodeRecentContext(request, { compatibility: resolveOpenCodeCompatibility(result.version) });
|
|
7952
8421
|
}
|
|
7953
8422
|
probe(command) {
|
|
7954
|
-
const result =
|
|
8423
|
+
const result = this.versionProbe("opencode", {}, command);
|
|
7955
8424
|
if (result.status !== "healthy")
|
|
7956
8425
|
return result;
|
|
7957
|
-
|
|
8426
|
+
let compatibility;
|
|
8427
|
+
try {
|
|
8428
|
+
compatibility = resolveOpenCodeCompatibility(result.version);
|
|
8429
|
+
} catch {
|
|
8430
|
+
return { ...result, status: "unhealthy", lastError: "unsupported_opencode_cli_version" };
|
|
8431
|
+
}
|
|
8432
|
+
const spec = resolveSpawnSpec("opencode", [...compatibility.modelArgs], command);
|
|
7958
8433
|
const output = this.outputProbe(spec.command, spec.args);
|
|
7959
8434
|
return {
|
|
7960
8435
|
...result,
|
|
@@ -7965,20 +8440,29 @@ class OpenCodeDriver {
|
|
|
7965
8440
|
return createOpenCodeMessageId();
|
|
7966
8441
|
}
|
|
7967
8442
|
async openLane(ctx, options) {
|
|
7968
|
-
|
|
8443
|
+
const command = resolveLaunchFieldsOrDefault(ctx.config.runtimeConfig).command;
|
|
8444
|
+
const result = this.versionProbe("opencode", {}, command);
|
|
8445
|
+
if (result.status !== "healthy")
|
|
8446
|
+
throw new Error("Installed OpenCode CLI could not report its version");
|
|
8447
|
+
const compatibility = resolveOpenCodeCompatibility(result.version);
|
|
8448
|
+
const factory = {
|
|
8449
|
+
spawnService: (launch, port, password) => this.spawnService(launch, port, password, compatibility)
|
|
8450
|
+
};
|
|
8451
|
+
const Lane = compatibility.major === 1 ? OpenCodeServiceLane : OpenCodeV2ServiceLane;
|
|
8452
|
+
return new Lane(factory, ctx, {
|
|
7969
8453
|
onRawStdoutLine: options?.onRawStdoutLine
|
|
7970
8454
|
});
|
|
7971
8455
|
}
|
|
7972
|
-
async spawnService(ctx, port, password) {
|
|
8456
|
+
async spawnService(ctx, port, password, compatibility = OPEN_CODE_V1) {
|
|
7973
8457
|
const { spawnEnv } = await prepareCliTransport(ctx, {
|
|
7974
|
-
OPENCODE_SERVER_PASSWORD: password
|
|
8458
|
+
OPENCODE_SERVER_PASSWORD: password,
|
|
8459
|
+
...compatibility.major === 2 ? { OPENCODE_PASSWORD: password } : {}
|
|
7975
8460
|
});
|
|
7976
8461
|
const fields2 = resolveLaunchFieldsOrDefault(ctx.config.runtimeConfig);
|
|
7977
8462
|
Object.assign(spawnEnv, await legacyOpenCodeApiEnvironment(spawnEnv, fields2.model));
|
|
7978
8463
|
const override = fields2.command;
|
|
7979
8464
|
const args = [
|
|
7980
|
-
|
|
7981
|
-
"--pure",
|
|
8465
|
+
...compatibility.serviceArgs,
|
|
7982
8466
|
"--hostname",
|
|
7983
8467
|
"127.0.0.1",
|
|
7984
8468
|
"--port",
|
|
@@ -8173,15 +8657,14 @@ function createPiSessionDependencies(ctx, loadSdk = loadPiSdkModule) {
|
|
|
8173
8657
|
},
|
|
8174
8658
|
async createAgentSession(opts) {
|
|
8175
8659
|
const sdk = await loadSdk();
|
|
8176
|
-
const
|
|
8660
|
+
const modelRuntime = await sdk.ModelRuntime.create();
|
|
8177
8661
|
const runtimeConfig = ctx.config.runtimeConfig;
|
|
8178
8662
|
const provider = runtimeConfig && "provider" in runtimeConfig ? runtimeConfig.provider : undefined;
|
|
8179
8663
|
if (provider?.kind === "builtin") {
|
|
8180
|
-
|
|
8664
|
+
await modelRuntime.setRuntimeApiKey(provider.providerId, provider.apiKey);
|
|
8181
8665
|
}
|
|
8182
|
-
const modelRegistry = sdk.ModelRegistry.create(authStorage);
|
|
8183
8666
|
const parsed = parseModelString(opts.model);
|
|
8184
|
-
const model = parsed ?
|
|
8667
|
+
const model = parsed ? modelRuntime.getModel(parsed.provider, parsed.id) : undefined;
|
|
8185
8668
|
const cwd = opts.cwd;
|
|
8186
8669
|
const requestedSessionId = opts.sessionId;
|
|
8187
8670
|
let sessionManager;
|
|
@@ -8200,8 +8683,7 @@ function createPiSessionDependencies(ctx, loadSdk = loadPiSdkModule) {
|
|
|
8200
8683
|
cwd,
|
|
8201
8684
|
model,
|
|
8202
8685
|
thinkingLevel: opts.thinkingLevel,
|
|
8203
|
-
|
|
8204
|
-
modelRegistry,
|
|
8686
|
+
modelRuntime,
|
|
8205
8687
|
sessionManager,
|
|
8206
8688
|
customTools: [bashTool]
|
|
8207
8689
|
});
|
|
@@ -8436,9 +8918,8 @@ class PiDriver {
|
|
|
8436
8918
|
try {
|
|
8437
8919
|
const reasoning = await Promise.race([
|
|
8438
8920
|
this.loadSdk().then(async (sdk) => {
|
|
8439
|
-
const
|
|
8440
|
-
|
|
8441
|
-
return parsePiModelCatalog(await registry.getAvailable());
|
|
8921
|
+
const modelRuntime = await sdk.ModelRuntime.create();
|
|
8922
|
+
return parsePiModelCatalog(await modelRuntime.getAvailable());
|
|
8442
8923
|
}),
|
|
8443
8924
|
new Promise((resolve4) => {
|
|
8444
8925
|
timer = setTimeout(() => resolve4(undefined), PI_MODEL_PROBE_TIMEOUT_MS);
|
|
@@ -11565,10 +12046,31 @@ function reduceManager(state, event) {
|
|
|
11565
12046
|
return withAgent(state, event.agentId, (a) => a ?? freshAgent(event.agentId), []);
|
|
11566
12047
|
case "wake":
|
|
11567
12048
|
return onWake(state, event.agentId, event.message);
|
|
11568
|
-
case "spawned":
|
|
12049
|
+
case "spawned": {
|
|
12050
|
+
const existing = state.agents[event.agentId];
|
|
12051
|
+
if (!existing || existing.status !== "starting")
|
|
12052
|
+
return { state, effects: [] };
|
|
12053
|
+
const agent = clone(existing);
|
|
12054
|
+
enterStable(agent, "running");
|
|
12055
|
+
syncExecutionProjection(agent);
|
|
12056
|
+
const mode = leaseIsWorking(agent.execution.lease) || agent.pendingAdmissions.length > 0 ? "busy" : "idle";
|
|
12057
|
+
const messages = drainInbox(agent);
|
|
12058
|
+
return commit(state, agent, messages.map((message) => ({ type: "send", agentId: event.agentId, message, mode })));
|
|
12059
|
+
}
|
|
12060
|
+
case "queue_delivery":
|
|
11569
12061
|
return mutate(state, event.agentId, (a) => {
|
|
11570
|
-
|
|
12062
|
+
const queuedById = new Map(a.inbox.filter((message) => message.id).map((message) => [message.id, message]));
|
|
12063
|
+
const restoredIds = new Set;
|
|
12064
|
+
const messages = event.messages.filter((message) => {
|
|
12065
|
+
if (message.id && restoredIds.has(message.id))
|
|
12066
|
+
return false;
|
|
12067
|
+
if (message.id)
|
|
12068
|
+
restoredIds.add(message.id);
|
|
12069
|
+
return true;
|
|
12070
|
+
}).map((message) => message.id ? queuedById.get(message.id) ?? message : message);
|
|
12071
|
+
a.inbox = [...messages, ...a.inbox.filter((message) => !message.id || !restoredIds.has(message.id))];
|
|
11571
12072
|
syncExecutionProjection(a);
|
|
12073
|
+
a.idleSince = null;
|
|
11572
12074
|
});
|
|
11573
12075
|
case "backend_session":
|
|
11574
12076
|
return mutate(state, event.agentId, (a) => {
|
|
@@ -11909,14 +12411,14 @@ function onTurnCompleted(state, agentId, sessionInstanceId, nowMs, turnId, endRe
|
|
|
11909
12411
|
agent.stalledSessionId = null;
|
|
11910
12412
|
syncExecutionProjection(agent);
|
|
11911
12413
|
const clearEffects = clearedStallSessionId === null ? [] : [{ type: "clear_stall_recovery", agentId, sessionId: clearedStallSessionId }];
|
|
11912
|
-
if (agent.inbox.length > 0 && !agent.resetting) {
|
|
12414
|
+
if (agent.status === "running" && agent.inbox.length > 0 && !agent.resetting) {
|
|
11913
12415
|
const messages = drainInbox(agent);
|
|
11914
12416
|
return commit(state, agent, [
|
|
11915
12417
|
...clearEffects,
|
|
11916
12418
|
...messages.map((queued) => ({ type: "send", agentId, message: queued, mode: "idle" }))
|
|
11917
12419
|
]);
|
|
11918
12420
|
}
|
|
11919
|
-
agent.idleSince = nowMs;
|
|
12421
|
+
agent.idleSince = agent.status === "running" && !agent.resetting ? nowMs : null;
|
|
11920
12422
|
return commit(state, agent, clearEffects);
|
|
11921
12423
|
}
|
|
11922
12424
|
function onTurnToolLifecycle(state, event, lifecycle) {
|
|
@@ -13440,8 +13942,34 @@ class AgentProcessManager {
|
|
|
13440
13942
|
}
|
|
13441
13943
|
}
|
|
13442
13944
|
}
|
|
13443
|
-
|
|
13444
|
-
|
|
13945
|
+
const completed = new Set;
|
|
13946
|
+
const deferSends = (agentId) => {
|
|
13947
|
+
const remaining = effects.filter((candidate) => candidate.type === "send" && !completed.has(candidate) && (agentId === undefined || candidate.agentId === agentId));
|
|
13948
|
+
for (const id of new Set(remaining.map((candidate) => candidate.agentId))) {
|
|
13949
|
+
const batch = remaining.filter((candidate) => candidate.agentId === id);
|
|
13950
|
+
batch.forEach((candidate) => completed.add(candidate));
|
|
13951
|
+
this.dispatch({
|
|
13952
|
+
type: "queue_delivery",
|
|
13953
|
+
agentId: id,
|
|
13954
|
+
messages: batch.map((candidate) => candidate.message)
|
|
13955
|
+
});
|
|
13956
|
+
}
|
|
13957
|
+
};
|
|
13958
|
+
try {
|
|
13959
|
+
for (const effect of effects) {
|
|
13960
|
+
if (completed.has(effect))
|
|
13961
|
+
continue;
|
|
13962
|
+
if (effect.type === "send" && !this.canSend(effect.agentId)) {
|
|
13963
|
+
deferSends(effect.agentId);
|
|
13964
|
+
continue;
|
|
13965
|
+
}
|
|
13966
|
+
this.applyEffect(effect);
|
|
13967
|
+
completed.add(effect);
|
|
13968
|
+
}
|
|
13969
|
+
} catch (error) {
|
|
13970
|
+
deferSends();
|
|
13971
|
+
throw error;
|
|
13972
|
+
}
|
|
13445
13973
|
return effects;
|
|
13446
13974
|
}
|
|
13447
13975
|
deriveActivitySnapshot(state) {
|
|
@@ -13473,6 +14001,26 @@ ${this.opts.wakePromptFooter}` : text2;
|
|
|
13473
14001
|
stampNow(text2) {
|
|
13474
14002
|
return this.opts.stampWakePromptTime ? `[${nowLocalISO()}] ${text2}` : text2;
|
|
13475
14003
|
}
|
|
14004
|
+
prepareDelivery(message) {
|
|
14005
|
+
return {
|
|
14006
|
+
...message,
|
|
14007
|
+
preparedInput: message.preparedInput ?? {
|
|
14008
|
+
id: message.id,
|
|
14009
|
+
kind: "user",
|
|
14010
|
+
text: this.stampNow(this.withFooter(message.text)),
|
|
14011
|
+
sequence: message.seq
|
|
14012
|
+
}
|
|
14013
|
+
};
|
|
14014
|
+
}
|
|
14015
|
+
canSend(agentId) {
|
|
14016
|
+
const session = this.sessions.get(agentId);
|
|
14017
|
+
const owner = this.activeSpawnState.get(agentId);
|
|
14018
|
+
const agent = this.state.agents[agentId];
|
|
14019
|
+
if (!session || !owner || owner.session !== session || owner.torndown || owner.superseded || agent?.status !== "running" || agent.resetting || agent.execution.sessionInstanceId !== session.sessionInstanceId)
|
|
14020
|
+
return false;
|
|
14021
|
+
const driverState = session.snapshot().state;
|
|
14022
|
+
return driverState !== "stopping" && driverState !== "closed";
|
|
14023
|
+
}
|
|
13476
14024
|
beginPendingDelivery(owner, commandId, message, mode, span, requeueOnFailure = true) {
|
|
13477
14025
|
const sessionInstanceId = owner.sessionInstanceId;
|
|
13478
14026
|
if (!sessionInstanceId || owner.pendingDeliverySpans.has(commandId))
|
|
@@ -13532,18 +14080,15 @@ ${this.opts.wakePromptFooter}` : text2;
|
|
|
13532
14080
|
break;
|
|
13533
14081
|
case "send": {
|
|
13534
14082
|
const session = this.sessions.get(effect.agentId);
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
sequence: effect.message.seq
|
|
13540
|
-
};
|
|
13541
|
-
if (session) {
|
|
14083
|
+
if (session && this.canSend(effect.agentId)) {
|
|
14084
|
+
const message = this.prepareDelivery(effect.message);
|
|
14085
|
+
effect.message = message;
|
|
14086
|
+
const input = message.preparedInput;
|
|
13542
14087
|
const owner = this.activeSpawnState.get(effect.agentId);
|
|
13543
14088
|
const exactOwner = owner?.session === session ? owner : undefined;
|
|
13544
14089
|
const associatedSpan = exactOwner ? effect.mode === "idle" ? this.openTurn(exactOwner) : exactOwner.activeSpan : null;
|
|
13545
14090
|
if (exactOwner)
|
|
13546
|
-
this.beginPendingDelivery(exactOwner, input.id,
|
|
14091
|
+
this.beginPendingDelivery(exactOwner, input.id, message, effect.mode, associatedSpan);
|
|
13547
14092
|
let sent;
|
|
13548
14093
|
try {
|
|
13549
14094
|
sent = session.send(input);
|
|
@@ -13752,9 +14297,11 @@ ${this.opts.wakePromptFooter}` : text2;
|
|
|
13752
14297
|
this.log.info("agent session ended", { agentId, sessionId, reason });
|
|
13753
14298
|
}
|
|
13754
14299
|
doSpawn(agentId, messages, resumeSessionId) {
|
|
13755
|
-
const [
|
|
13756
|
-
if (!
|
|
14300
|
+
const [initial, ...pending] = messages;
|
|
14301
|
+
if (!initial)
|
|
13757
14302
|
throw new Error(`AgentProcessManager: spawn for ${agentId} has no command`);
|
|
14303
|
+
this.dispatch({ type: "queue_delivery", agentId, messages: pending });
|
|
14304
|
+
const first = this.prepareDelivery(initial);
|
|
13758
14305
|
const prompt = this.withFooter(first.text);
|
|
13759
14306
|
const driver = this.opts.driverFor(agentId, this.runtimeConfigs.get(agentId));
|
|
13760
14307
|
this.liveBackendIds.set(agentId, driver.id);
|
|
@@ -13958,12 +14505,7 @@ ${this.opts.wakePromptFooter}` : text2;
|
|
|
13958
14505
|
this.beginPendingDelivery(state, commandId, first, "idle", startedSpan, false);
|
|
13959
14506
|
let startResult;
|
|
13960
14507
|
try {
|
|
13961
|
-
startResult = session.start(
|
|
13962
|
-
id: commandId,
|
|
13963
|
-
kind: "user",
|
|
13964
|
-
text: this.stampNow(prompt),
|
|
13965
|
-
sequence: first.seq
|
|
13966
|
-
});
|
|
14508
|
+
startResult = session.start(first.preparedInput);
|
|
13967
14509
|
this.markPendingDeliveryObserved(state, commandId);
|
|
13968
14510
|
} catch (error) {
|
|
13969
14511
|
this.settlePendingDelivery(state, commandId);
|
|
@@ -13971,7 +14513,7 @@ ${this.opts.wakePromptFooter}` : text2;
|
|
|
13971
14513
|
throw error;
|
|
13972
14514
|
}
|
|
13973
14515
|
startResult.then((receipt) => {
|
|
13974
|
-
if (this.sessions.get(agentId) !== session || state.torndown)
|
|
14516
|
+
if (this.sessions.get(agentId) !== session || state.torndown || state.superseded || this.activeSpawnState.get(agentId) !== state)
|
|
13975
14517
|
return;
|
|
13976
14518
|
if (receipt?.status === "rejected") {
|
|
13977
14519
|
this.settlePendingDelivery(state, commandId);
|
|
@@ -13980,44 +14522,16 @@ ${this.opts.wakePromptFooter}` : text2;
|
|
|
13980
14522
|
session.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
13981
14523
|
return;
|
|
13982
14524
|
}
|
|
13983
|
-
|
|
13984
|
-
|
|
13985
|
-
|
|
13986
|
-
|
|
13987
|
-
|
|
13988
|
-
|
|
13989
|
-
|
|
13990
|
-
|
|
13991
|
-
|
|
13992
|
-
|
|
13993
|
-
id: message.id,
|
|
13994
|
-
kind: "user",
|
|
13995
|
-
text: this.stampNow(this.withFooter(message.text)),
|
|
13996
|
-
sequence: message.seq
|
|
13997
|
-
});
|
|
13998
|
-
this.markPendingDeliveryObserved(state, message.id);
|
|
13999
|
-
queuedReceipt = await queuedResult;
|
|
14000
|
-
} catch (error) {
|
|
14001
|
-
this.settlePendingDelivery(state, message.id);
|
|
14002
|
-
if (!state.torndown && this.sessions.get(agentId) === session && this.activeSpawnState.get(agentId) === state) {
|
|
14003
|
-
this.emitErrorAudit(agentId, "runtime", "send_failed", String(error));
|
|
14004
|
-
session.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
14005
|
-
}
|
|
14006
|
-
return;
|
|
14007
|
-
}
|
|
14008
|
-
if (state.torndown || this.sessions.get(agentId) !== session || this.activeSpawnState.get(agentId) !== state) {
|
|
14009
|
-
return;
|
|
14010
|
-
}
|
|
14011
|
-
if (queuedReceipt.status === "rejected") {
|
|
14012
|
-
if (!state.pendingDeliverySpans.has(message.id))
|
|
14013
|
-
return;
|
|
14014
|
-
this.settlePendingDelivery(state, message.id);
|
|
14015
|
-
this.emitErrorAudit(agentId, "runtime", queuedReceipt.error?.code ?? queuedReceipt.reason, queuedReceipt.error?.message ?? `Delivery rejected (${queuedReceipt.reason})`);
|
|
14016
|
-
session.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
14017
|
-
return;
|
|
14018
|
-
}
|
|
14019
|
-
}
|
|
14020
|
-
})().catch((error) => this.emitErrorAudit(agentId, "runtime", "send_failed", String(error)));
|
|
14525
|
+
const driverState = session.snapshot().state;
|
|
14526
|
+
if (this.state.agents[agentId]?.status !== "starting" || driverState === "stopping" || driverState === "closed")
|
|
14527
|
+
return;
|
|
14528
|
+
try {
|
|
14529
|
+
this.dispatch({ type: "spawned", agentId, nowMs: this.now() }, state);
|
|
14530
|
+
} catch (error) {
|
|
14531
|
+
this.emitErrorAudit(agentId, "runtime", "send_failed", String(error));
|
|
14532
|
+
session.stop({ reason: "shutdown", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
14533
|
+
return;
|
|
14534
|
+
}
|
|
14021
14535
|
if (state.hasEstablished || state.hasReportedSpawnFailure)
|
|
14022
14536
|
return;
|
|
14023
14537
|
state.handshakeTimer = setTimeout(() => {
|
|
@@ -33725,7 +34239,7 @@ __export(exports_community_machine_schema, {
|
|
|
33725
34239
|
DIAGNOSTIC_REPORT_FAILURE_CODES: () => DIAGNOSTIC_REPORT_FAILURE_CODES
|
|
33726
34240
|
});
|
|
33727
34241
|
|
|
33728
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34242
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/entity.js
|
|
33729
34243
|
var entityKind = Symbol.for("drizzle:entityKind");
|
|
33730
34244
|
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
33731
34245
|
function is(value, type) {
|
|
@@ -33750,7 +34264,7 @@ function is(value, type) {
|
|
|
33750
34264
|
return false;
|
|
33751
34265
|
}
|
|
33752
34266
|
|
|
33753
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34267
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/column.js
|
|
33754
34268
|
class Column {
|
|
33755
34269
|
constructor(table, config2) {
|
|
33756
34270
|
this.table = table;
|
|
@@ -33800,7 +34314,7 @@ class Column {
|
|
|
33800
34314
|
}
|
|
33801
34315
|
}
|
|
33802
34316
|
|
|
33803
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34317
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/column-builder.js
|
|
33804
34318
|
class ColumnBuilder {
|
|
33805
34319
|
static [entityKind] = "ColumnBuilder";
|
|
33806
34320
|
config;
|
|
@@ -33856,20 +34370,20 @@ class ColumnBuilder {
|
|
|
33856
34370
|
}
|
|
33857
34371
|
}
|
|
33858
34372
|
|
|
33859
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34373
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/table.utils.js
|
|
33860
34374
|
var TableName = Symbol.for("drizzle:Name");
|
|
33861
34375
|
|
|
33862
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34376
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/tracing-utils.js
|
|
33863
34377
|
function iife(fn, ...args) {
|
|
33864
34378
|
return fn(...args);
|
|
33865
34379
|
}
|
|
33866
34380
|
|
|
33867
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34381
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
33868
34382
|
function uniqueKeyName(table, columns) {
|
|
33869
34383
|
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
33870
34384
|
}
|
|
33871
34385
|
|
|
33872
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34386
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/pg-core/columns/common.js
|
|
33873
34387
|
class PgColumn extends Column {
|
|
33874
34388
|
constructor(table, config2) {
|
|
33875
34389
|
if (!config2.uniqueName) {
|
|
@@ -33918,7 +34432,7 @@ class ExtraConfigColumn extends PgColumn {
|
|
|
33918
34432
|
}
|
|
33919
34433
|
}
|
|
33920
34434
|
|
|
33921
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34435
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
33922
34436
|
class PgEnumObjectColumn extends PgColumn {
|
|
33923
34437
|
static [entityKind] = "PgEnumObjectColumn";
|
|
33924
34438
|
enum;
|
|
@@ -33948,7 +34462,7 @@ class PgEnumColumn extends PgColumn {
|
|
|
33948
34462
|
}
|
|
33949
34463
|
}
|
|
33950
34464
|
|
|
33951
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34465
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/subquery.js
|
|
33952
34466
|
class Subquery {
|
|
33953
34467
|
static [entityKind] = "Subquery";
|
|
33954
34468
|
constructor(sql, fields2, alias, isWith = false, usedTables = []) {
|
|
@@ -33963,10 +34477,10 @@ class Subquery {
|
|
|
33963
34477
|
}
|
|
33964
34478
|
}
|
|
33965
34479
|
|
|
33966
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
33967
|
-
var version2 = "0.45.
|
|
34480
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/version.js
|
|
34481
|
+
var version2 = "0.45.4";
|
|
33968
34482
|
|
|
33969
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34483
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/tracing.js
|
|
33970
34484
|
var otel;
|
|
33971
34485
|
var rawTracer;
|
|
33972
34486
|
var tracer = {
|
|
@@ -33993,10 +34507,10 @@ var tracer = {
|
|
|
33993
34507
|
}
|
|
33994
34508
|
};
|
|
33995
34509
|
|
|
33996
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34510
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/view-common.js
|
|
33997
34511
|
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
33998
34512
|
|
|
33999
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34513
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/table.js
|
|
34000
34514
|
var Schema = Symbol.for("drizzle:Schema");
|
|
34001
34515
|
var Columns = Symbol.for("drizzle:Columns");
|
|
34002
34516
|
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
@@ -34034,7 +34548,7 @@ class Table {
|
|
|
34034
34548
|
}
|
|
34035
34549
|
}
|
|
34036
34550
|
|
|
34037
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34551
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sql/sql.js
|
|
34038
34552
|
function isSQLWrapper(value) {
|
|
34039
34553
|
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
34040
34554
|
}
|
|
@@ -34397,7 +34911,7 @@ Subquery.prototype.getSQL = function() {
|
|
|
34397
34911
|
return new SQL([this]);
|
|
34398
34912
|
};
|
|
34399
34913
|
|
|
34400
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34914
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/alias.js
|
|
34401
34915
|
class ColumnAliasProxyHandler {
|
|
34402
34916
|
constructor(table) {
|
|
34403
34917
|
this.table = table;
|
|
@@ -34453,12 +34967,12 @@ class TableAliasProxyHandler {
|
|
|
34453
34967
|
}
|
|
34454
34968
|
}
|
|
34455
34969
|
|
|
34456
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34970
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/alias.js
|
|
34457
34971
|
function alias(table, alias2) {
|
|
34458
34972
|
return new Proxy(table, new TableAliasProxyHandler(alias2, false));
|
|
34459
34973
|
}
|
|
34460
34974
|
|
|
34461
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
34975
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/checks.js
|
|
34462
34976
|
class CheckBuilder {
|
|
34463
34977
|
constructor(name, value) {
|
|
34464
34978
|
this.name = name;
|
|
@@ -34485,7 +34999,7 @@ function check2(name, value) {
|
|
|
34485
34999
|
return new CheckBuilder(name, value);
|
|
34486
35000
|
}
|
|
34487
35001
|
|
|
34488
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35002
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/utils.js
|
|
34489
35003
|
function getColumnNameAndConfig(a, b) {
|
|
34490
35004
|
return {
|
|
34491
35005
|
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
@@ -34494,7 +35008,7 @@ function getColumnNameAndConfig(a, b) {
|
|
|
34494
35008
|
}
|
|
34495
35009
|
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
|
|
34496
35010
|
|
|
34497
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35011
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
34498
35012
|
class ForeignKeyBuilder {
|
|
34499
35013
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
34500
35014
|
reference;
|
|
@@ -34562,7 +35076,7 @@ function foreignKey(config2) {
|
|
|
34562
35076
|
return new ForeignKeyBuilder(mappedConfig);
|
|
34563
35077
|
}
|
|
34564
35078
|
|
|
34565
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35079
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
|
|
34566
35080
|
function uniqueKeyName2(table, columns) {
|
|
34567
35081
|
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
34568
35082
|
}
|
|
@@ -34607,7 +35121,7 @@ class UniqueConstraint {
|
|
|
34607
35121
|
}
|
|
34608
35122
|
}
|
|
34609
35123
|
|
|
34610
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35124
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/common.js
|
|
34611
35125
|
class SQLiteColumnBuilder extends ColumnBuilder {
|
|
34612
35126
|
static [entityKind] = "SQLiteColumnBuilder";
|
|
34613
35127
|
foreignKeyConfigs = [];
|
|
@@ -34658,7 +35172,7 @@ class SQLiteColumn extends Column {
|
|
|
34658
35172
|
static [entityKind] = "SQLiteColumn";
|
|
34659
35173
|
}
|
|
34660
35174
|
|
|
34661
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35175
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/blob.js
|
|
34662
35176
|
class SQLiteBigIntBuilder extends SQLiteColumnBuilder {
|
|
34663
35177
|
static [entityKind] = "SQLiteBigIntBuilder";
|
|
34664
35178
|
constructor(name) {
|
|
@@ -34746,7 +35260,7 @@ function blob(a, b) {
|
|
|
34746
35260
|
return new SQLiteBlobBufferBuilder(name);
|
|
34747
35261
|
}
|
|
34748
35262
|
|
|
34749
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35263
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/custom.js
|
|
34750
35264
|
class SQLiteCustomColumnBuilder extends SQLiteColumnBuilder {
|
|
34751
35265
|
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
34752
35266
|
constructor(name, fieldConfig, customTypeParams) {
|
|
@@ -34787,7 +35301,7 @@ function customType(customTypeParams) {
|
|
|
34787
35301
|
};
|
|
34788
35302
|
}
|
|
34789
35303
|
|
|
34790
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35304
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/integer.js
|
|
34791
35305
|
class SQLiteBaseIntegerBuilder extends SQLiteColumnBuilder {
|
|
34792
35306
|
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
34793
35307
|
constructor(name, dataType, columnType) {
|
|
@@ -34889,7 +35403,7 @@ function integer2(a, b) {
|
|
|
34889
35403
|
return new SQLiteIntegerBuilder(name);
|
|
34890
35404
|
}
|
|
34891
35405
|
|
|
34892
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35406
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
|
|
34893
35407
|
class SQLiteNumericBuilder extends SQLiteColumnBuilder {
|
|
34894
35408
|
static [entityKind] = "SQLiteNumericBuilder";
|
|
34895
35409
|
constructor(name) {
|
|
@@ -34959,7 +35473,7 @@ function numeric(a, b) {
|
|
|
34959
35473
|
return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
|
|
34960
35474
|
}
|
|
34961
35475
|
|
|
34962
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35476
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/real.js
|
|
34963
35477
|
class SQLiteRealBuilder extends SQLiteColumnBuilder {
|
|
34964
35478
|
static [entityKind] = "SQLiteRealBuilder";
|
|
34965
35479
|
constructor(name) {
|
|
@@ -34980,7 +35494,7 @@ function real(name) {
|
|
|
34980
35494
|
return new SQLiteRealBuilder(name ?? "");
|
|
34981
35495
|
}
|
|
34982
35496
|
|
|
34983
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35497
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/text.js
|
|
34984
35498
|
class SQLiteTextBuilder extends SQLiteColumnBuilder {
|
|
34985
35499
|
static [entityKind] = "SQLiteTextBuilder";
|
|
34986
35500
|
constructor(name, config2) {
|
|
@@ -35035,7 +35549,7 @@ function text2(a, b = {}) {
|
|
|
35035
35549
|
return new SQLiteTextBuilder(name, config2);
|
|
35036
35550
|
}
|
|
35037
35551
|
|
|
35038
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35552
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/columns/all.js
|
|
35039
35553
|
function getSQLiteColumnBuilders() {
|
|
35040
35554
|
return {
|
|
35041
35555
|
blob,
|
|
@@ -35047,7 +35561,7 @@ function getSQLiteColumnBuilders() {
|
|
|
35047
35561
|
};
|
|
35048
35562
|
}
|
|
35049
35563
|
|
|
35050
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35564
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/table.js
|
|
35051
35565
|
var InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
35052
35566
|
|
|
35053
35567
|
class SQLiteTable extends Table {
|
|
@@ -35081,7 +35595,7 @@ var sqliteTable = (name, columns, extraConfig) => {
|
|
|
35081
35595
|
return sqliteTableBase(name, columns, extraConfig);
|
|
35082
35596
|
};
|
|
35083
35597
|
|
|
35084
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35598
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
35085
35599
|
class IndexBuilderOn {
|
|
35086
35600
|
constructor(name, unique2) {
|
|
35087
35601
|
this.name = name;
|
|
@@ -35127,7 +35641,7 @@ function uniqueIndex(name) {
|
|
|
35127
35641
|
return new IndexBuilderOn(name, true);
|
|
35128
35642
|
}
|
|
35129
35643
|
|
|
35130
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35644
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sqlite-core/primary-keys.js
|
|
35131
35645
|
function primaryKey(...config2) {
|
|
35132
35646
|
if (config2[0].columns) {
|
|
35133
35647
|
return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
@@ -35162,7 +35676,7 @@ class PrimaryKey {
|
|
|
35162
35676
|
}
|
|
35163
35677
|
}
|
|
35164
35678
|
|
|
35165
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35679
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
35166
35680
|
function bindIfParam(value, column) {
|
|
35167
35681
|
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
35168
35682
|
return new Param(value, column);
|
|
@@ -35190,7 +35704,7 @@ function isNotNull(value) {
|
|
|
35190
35704
|
return sql`${value} is not null`;
|
|
35191
35705
|
}
|
|
35192
35706
|
|
|
35193
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.
|
|
35707
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261009.1_@opentelemetry+api@1.9.1_@typ_2c5bdbc2e285e95e03f6fc3b5df79b2b/node_modules/drizzle-orm/sql/expressions/select.js
|
|
35194
35708
|
function desc(column) {
|
|
35195
35709
|
return sql`${column} desc`;
|
|
35196
35710
|
}
|
|
@@ -40386,46 +40900,8 @@ var communityFunnelAnalyticsEvent = sqliteTable("community_funnel_analytics_even
|
|
|
40386
40900
|
index("idx_community_funnel_analytics_owner_claimed_created").on(t.ownerUserId, t.claimedAt, t.createdAt)
|
|
40387
40901
|
]);
|
|
40388
40902
|
|
|
40389
|
-
// ../shared/src/db/product-analytics-schema.ts
|
|
40390
|
-
var exports_product_analytics_schema = {};
|
|
40391
|
-
__export(exports_product_analytics_schema, {
|
|
40392
|
-
productAnalyticsEvent: () => productAnalyticsEvent,
|
|
40393
|
-
PRODUCT_ANALYTICS_EVENTS: () => PRODUCT_ANALYTICS_EVENTS
|
|
40394
|
-
});
|
|
40395
|
-
var PRODUCT_ANALYTICS_EVENTS = [
|
|
40396
|
-
"landing_cta_clicked",
|
|
40397
|
-
"login_page_view",
|
|
40398
|
-
"sign_up",
|
|
40399
|
-
"sign_in_success",
|
|
40400
|
-
"sign_in_failed",
|
|
40401
|
-
"onboarding_enter_clicked",
|
|
40402
|
-
"onboarding_first_message",
|
|
40403
|
-
"invitation_link_visit"
|
|
40404
|
-
];
|
|
40405
|
-
var productAnalyticsEvent = sqliteTable("product_analytics_event", {
|
|
40406
|
-
id: text2("id").primaryKey(),
|
|
40407
|
-
eventName: text2("event_name").notNull().$type(),
|
|
40408
|
-
actorUserId: text2("actor_user_id").references(() => user.id, { onDelete: "cascade" }),
|
|
40409
|
-
serverId: text2("server_id").references(() => communityServer.id, { onDelete: "cascade" }),
|
|
40410
|
-
sourceId: text2("source_id"),
|
|
40411
|
-
dedupeKey: text2("dedupe_key").notNull(),
|
|
40412
|
-
clientId: text2("client_id").notNull(),
|
|
40413
|
-
sessionId: text2("session_id").notNull(),
|
|
40414
|
-
method: text2("method"),
|
|
40415
|
-
accountKind: text2("account_kind").$type(),
|
|
40416
|
-
ctaName: text2("cta_name"),
|
|
40417
|
-
failureStage: text2("failure_stage").$type(),
|
|
40418
|
-
createdAt: text2("created_at").notNull(),
|
|
40419
|
-
deliveryStatus: text2("delivery_status").notNull().default("pending").$type(),
|
|
40420
|
-
deliveryReason: text2("delivery_reason"),
|
|
40421
|
-
attemptedAt: text2("attempted_at")
|
|
40422
|
-
}, (t) => [
|
|
40423
|
-
uniqueIndex("uq_product_analytics_dedupe").on(t.dedupeKey),
|
|
40424
|
-
index("idx_product_analytics_actor_server_event").on(t.actorUserId, t.serverId, t.eventName)
|
|
40425
|
-
]);
|
|
40426
|
-
|
|
40427
40903
|
// ../shared/src/db/index.ts
|
|
40428
|
-
var allSchema = { ...exports_schema, ...exports_community_schema, ...exports_community_machine_schema, ...exports_product_plan_schema, ...exports_billing_schema, ...exports_community_funnel_analytics_schema
|
|
40904
|
+
var allSchema = { ...exports_schema, ...exports_community_schema, ...exports_community_machine_schema, ...exports_product_plan_schema, ...exports_billing_schema, ...exports_community_funnel_analytics_schema };
|
|
40429
40905
|
// ../shared/src/community-server-rail.ts
|
|
40430
40906
|
var MAX_SERVER_RAIL_COMMANDS = 3;
|
|
40431
40907
|
var idSchema = exports_external.string().trim().min(1);
|