@rynx-ai/daemon 0.1.10 → 0.1.11-beta.2
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/bundled-plugins/.rynx-plugin/marketplace.json +10 -0
- package/bundled-plugins/plugins/lark/.rynx-plugin/plugin.json +37 -0
- package/bundled-plugins/plugins/lark/dist/cli-mirror/mirror-index.d.ts +48 -0
- package/bundled-plugins/plugins/lark/dist/cli-mirror/mirror-index.js +54 -0
- package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-mirror.d.ts +85 -0
- package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-mirror.js +333 -0
- package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-watcher.d.ts +109 -0
- package/bundled-plugins/plugins/lark/dist/cli-mirror/rollout-watcher.js +347 -0
- package/bundled-plugins/plugins/lark/dist/host-adapters.d.ts +95 -0
- package/bundled-plugins/plugins/lark/dist/host-adapters.js +504 -0
- package/bundled-plugins/plugins/lark/dist/index.d.ts +7 -0
- package/bundled-plugins/plugins/lark/dist/index.js +7 -0
- package/bundled-plugins/plugins/lark/dist/lark-card-stream.d.ts +363 -0
- package/bundled-plugins/plugins/lark/dist/lark-card-stream.js +1335 -0
- package/bundled-plugins/plugins/lark/dist/lark-config-store.d.ts +30 -0
- package/bundled-plugins/plugins/lark/dist/lark-config-store.js +135 -0
- package/bundled-plugins/plugins/lark/dist/lark-content.d.ts +30 -0
- package/bundled-plugins/plugins/lark/dist/lark-content.js +138 -0
- package/bundled-plugins/plugins/lark/dist/lark-conversation-directory.d.ts +65 -0
- package/bundled-plugins/plugins/lark/dist/lark-conversation-directory.js +106 -0
- package/bundled-plugins/plugins/lark/dist/lark-diff-card.d.ts +25 -0
- package/bundled-plugins/plugins/lark/dist/lark-diff-card.js +58 -0
- package/bundled-plugins/plugins/lark/dist/lark-fork-transcript.d.ts +16 -0
- package/bundled-plugins/plugins/lark/dist/lark-fork-transcript.js +141 -0
- package/bundled-plugins/plugins/lark/dist/lark-resume-card.d.ts +31 -0
- package/bundled-plugins/plugins/lark/dist/lark-resume-card.js +105 -0
- package/bundled-plugins/plugins/lark/dist/lark-runtime-state-store.d.ts +18 -0
- package/bundled-plugins/plugins/lark/dist/lark-runtime-state-store.js +95 -0
- package/bundled-plugins/plugins/lark/dist/lark-sdk/client.d.ts +8 -0
- package/bundled-plugins/plugins/lark/dist/lark-sdk/client.js +32 -0
- package/bundled-plugins/plugins/lark/dist/lark-sdk/index.d.ts +1 -0
- package/bundled-plugins/plugins/lark/dist/lark-sdk/index.js +1 -0
- package/bundled-plugins/plugins/lark/dist/lark-sender.d.ts +114 -0
- package/bundled-plugins/plugins/lark/dist/lark-sender.js +323 -0
- package/bundled-plugins/plugins/lark/dist/lark-session-store.d.ts +13 -0
- package/bundled-plugins/plugins/lark/dist/lark-session-store.js +14 -0
- package/bundled-plugins/plugins/lark/dist/lark-settings-card.d.ts +55 -0
- package/bundled-plugins/plugins/lark/dist/lark-settings-card.js +158 -0
- package/bundled-plugins/plugins/lark/dist/lark-setup.d.ts +39 -0
- package/bundled-plugins/plugins/lark/dist/lark-setup.js +103 -0
- package/bundled-plugins/plugins/lark/dist/lark.d.ts +507 -0
- package/bundled-plugins/plugins/lark/dist/lark.js +1977 -0
- package/bundled-plugins/plugins/lark/dist/runtime.d.ts +13 -0
- package/bundled-plugins/plugins/lark/dist/runtime.js +131316 -0
- package/bundled-plugins/plugins/lark/dist/settings.d.ts +7 -0
- package/bundled-plugins/plugins/lark/dist/settings.js +126958 -0
- package/bundled-plugins/plugins/lark/package.json +57 -0
- package/bundled-plugins/plugins/lark/ui/assets/index-B2dhMlMU.css +1 -0
- package/bundled-plugins/plugins/lark/ui/assets/index-D9N-AkLX.js +201 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/bundled-plugins/plugins/lark/ui/index.html +13 -0
- package/dist/bundled-plugins.d.ts +15 -0
- package/dist/bundled-plugins.js +134 -0
- package/dist/cli.js +26 -208
- package/dist/control-deps.js +2 -79
- package/dist/daemon-server.d.ts +4 -1
- package/dist/daemon-server.js +167 -57
- package/dist/db.js +145 -124
- package/dist/index-daemon.js +25 -4
- package/dist/migrations/cleanup-legacy-sessions.d.ts +1 -1
- package/dist/migrations/cleanup-legacy-sessions.js +33 -15
- package/dist/official-plugins.d.ts +2 -0
- package/dist/official-plugins.js +2 -0
- package/dist/plugin-cli.d.ts +1 -3
- package/dist/plugin-cli.js +56 -45
- package/dist/plugin-host-leases.d.ts +4 -0
- package/dist/plugin-host-leases.js +7 -0
- package/dist/plugin-host-rpc.d.ts +42 -4
- package/dist/plugin-host-rpc.js +144 -34
- package/dist/plugin-installer.d.ts +24 -55
- package/dist/plugin-installer.js +202 -415
- package/dist/plugin-management-service.d.ts +30 -23
- package/dist/plugin-management-service.js +290 -105
- package/dist/plugin-marketplace.d.ts +35 -0
- package/dist/plugin-marketplace.js +299 -0
- package/dist/plugin-package.d.ts +22 -24
- package/dist/plugin-package.js +520 -571
- package/dist/plugin-skill-context.d.ts +4 -0
- package/dist/plugin-skill-context.js +35 -0
- package/dist/plugin-store.d.ts +36 -37
- package/dist/plugin-store.js +140 -92
- package/dist/plugin-supervisor.d.ts +45 -125
- package/dist/plugin-supervisor.js +516 -1053
- package/dist/pm2.js +15 -10
- package/dist/runtime-project-store.d.ts +9 -0
- package/dist/runtime-project-store.js +83 -0
- package/dist/session-fallback-workspace.d.ts +22 -0
- package/dist/session-fallback-workspace.js +120 -0
- package/dist/session-fork-store.d.ts +41 -0
- package/dist/session-fork-store.js +288 -0
- package/dist/session-launch-operations.d.ts +14 -2
- package/dist/session-launch-operations.js +34 -2
- package/dist/session-meta-store.d.ts +7 -9
- package/dist/session-meta-store.js +28 -49
- package/dist/setup.js +26 -14
- package/package.json +14 -11
- package/dist/channel-store.d.ts +0 -22
- package/dist/channel-store.js +0 -65
- package/dist/instance-store.d.ts +0 -38
- package/dist/instance-store.js +0 -85
- package/dist/plugin-install-restart.d.ts +0 -13
- package/dist/plugin-install-restart.js +0 -24
- package/dist/plugin-runtime-control.d.ts +0 -2
- package/dist/plugin-runtime-control.js +0 -37
- package/dist/registry.d.ts +0 -10
- package/dist/registry.js +0 -52
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { AgentRuntimeError, } from "@rynx-ai/core";
|
|
4
|
+
import { FileLarkActiveSessionStore, } from "./lark-session-store.js";
|
|
5
|
+
/** Slow consumers fail the run instead of retaining an unbounded event stream. */
|
|
6
|
+
export const LARK_RUN_EVENT_QUEUE_MAX_ITEMS = 256;
|
|
7
|
+
export const LARK_RUN_EVENT_QUEUE_MAX_BYTES = 8 * 1024 * 1024;
|
|
8
|
+
/**
|
|
9
|
+
* ConversationRuntime-shaped adapter backed exclusively by capability-checked
|
|
10
|
+
* Host RPC. The plugin never receives the daemon's runtime, abort controller,
|
|
11
|
+
* steer controller, or session bus.
|
|
12
|
+
*/
|
|
13
|
+
export class HostConversationRuntime {
|
|
14
|
+
host;
|
|
15
|
+
constructor(host) {
|
|
16
|
+
this.host = host;
|
|
17
|
+
}
|
|
18
|
+
async runLive(input) {
|
|
19
|
+
if (!input.threadId) {
|
|
20
|
+
throw new AgentRuntimeError("a daemon-provisioned session id is required", 400, "session_required");
|
|
21
|
+
}
|
|
22
|
+
if (input.signal?.aborted) {
|
|
23
|
+
throw new AgentRuntimeError("conversation run was cancelled", 499, "codex_cancelled");
|
|
24
|
+
}
|
|
25
|
+
const queue = new AsyncEventQueue({
|
|
26
|
+
maxItems: LARK_RUN_EVENT_QUEUE_MAX_ITEMS,
|
|
27
|
+
maxBytes: LARK_RUN_EVENT_QUEUE_MAX_BYTES,
|
|
28
|
+
sizeOf: jsonByteLength,
|
|
29
|
+
overflowError: runEventQueueOverflowError,
|
|
30
|
+
});
|
|
31
|
+
let runId;
|
|
32
|
+
let terminal = false;
|
|
33
|
+
const earlyEvents = [];
|
|
34
|
+
let earlyEventBytes = 0;
|
|
35
|
+
let earlyOverflow = false;
|
|
36
|
+
let unsubscribeEvents = () => { };
|
|
37
|
+
const interrupt = () => {
|
|
38
|
+
if (!runId || terminal)
|
|
39
|
+
return;
|
|
40
|
+
void this.host.call("session.interrupt", { runId }).catch(() => undefined);
|
|
41
|
+
};
|
|
42
|
+
const accept = (event, payload) => {
|
|
43
|
+
if (!runId) {
|
|
44
|
+
if (earlyOverflow)
|
|
45
|
+
return;
|
|
46
|
+
const bytes = jsonByteLength({ event, payload });
|
|
47
|
+
if (earlyEvents.length >= LARK_RUN_EVENT_QUEUE_MAX_ITEMS
|
|
48
|
+
|| bytes > LARK_RUN_EVENT_QUEUE_MAX_BYTES - earlyEventBytes) {
|
|
49
|
+
earlyOverflow = true;
|
|
50
|
+
earlyEvents.length = 0;
|
|
51
|
+
earlyEventBytes = 0;
|
|
52
|
+
unsubscribeEvents();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
earlyEvents.push({ event, payload });
|
|
56
|
+
earlyEventBytes += bytes;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (event === "session.run.event") {
|
|
60
|
+
const value = runEventPayload(payload);
|
|
61
|
+
if (value?.runId === runId && queue.push(value.event) === "overflow") {
|
|
62
|
+
interrupt();
|
|
63
|
+
terminal = true;
|
|
64
|
+
unsubscribeEvents();
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (event === "session.run.completed") {
|
|
69
|
+
const value = runTerminalPayload(payload);
|
|
70
|
+
if (value?.runId === runId) {
|
|
71
|
+
terminal = true;
|
|
72
|
+
queue.end();
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (event === "session.run.failed") {
|
|
77
|
+
const value = runTerminalPayload(payload);
|
|
78
|
+
if (value?.runId === runId) {
|
|
79
|
+
terminal = true;
|
|
80
|
+
queue.fail(hostRunError(value));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
unsubscribeEvents = this.host.events.subscribe(({ event, payload }) => accept(event, payload));
|
|
85
|
+
if (earlyOverflow)
|
|
86
|
+
unsubscribeEvents();
|
|
87
|
+
let started;
|
|
88
|
+
try {
|
|
89
|
+
started = await this.host.call("session.run", {
|
|
90
|
+
sessionId: input.threadId,
|
|
91
|
+
message: input.message,
|
|
92
|
+
});
|
|
93
|
+
runId = started.runId;
|
|
94
|
+
if (earlyOverflow) {
|
|
95
|
+
queue.fail(runEventQueueOverflowError(), true);
|
|
96
|
+
interrupt();
|
|
97
|
+
terminal = true;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
for (const early of earlyEvents.splice(0))
|
|
101
|
+
accept(early.event, early.payload);
|
|
102
|
+
earlyEventBytes = 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
unsubscribeEvents();
|
|
107
|
+
throw toAgentRuntimeError(error);
|
|
108
|
+
}
|
|
109
|
+
const unsteer = input.steer?.subscribe((text) => {
|
|
110
|
+
if (!runId || terminal)
|
|
111
|
+
return;
|
|
112
|
+
void this.host.call("session.steer", { runId, text }).catch(() => undefined);
|
|
113
|
+
});
|
|
114
|
+
input.signal?.addEventListener("abort", interrupt, { once: true });
|
|
115
|
+
const generator = (async function* () {
|
|
116
|
+
try {
|
|
117
|
+
for await (const event of queue)
|
|
118
|
+
yield event;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
if (!terminal)
|
|
122
|
+
interrupt();
|
|
123
|
+
input.signal?.removeEventListener("abort", interrupt);
|
|
124
|
+
unsteer?.();
|
|
125
|
+
unsubscribeEvents();
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
return {
|
|
129
|
+
provider: started.provider,
|
|
130
|
+
threadId: started.sessionId,
|
|
131
|
+
model: started.model,
|
|
132
|
+
authSource: started.authSource,
|
|
133
|
+
generator,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Agent command adapter used by /models and /goal. Session fork is a Core RPC. */
|
|
138
|
+
export class HostAgentCapabilities {
|
|
139
|
+
host;
|
|
140
|
+
constructor(host) {
|
|
141
|
+
this.host = host;
|
|
142
|
+
}
|
|
143
|
+
listModels(runtime) {
|
|
144
|
+
return this.host.call("session.models", runtime ? { runtime } : {});
|
|
145
|
+
}
|
|
146
|
+
getGoal(sessionId) {
|
|
147
|
+
return this.host.call("session.goal.get", { sessionId });
|
|
148
|
+
}
|
|
149
|
+
setGoal(sessionId, objective) {
|
|
150
|
+
return this.host.call("session.goal.set", { sessionId, objective });
|
|
151
|
+
}
|
|
152
|
+
clearGoal(sessionId) {
|
|
153
|
+
return this.host.call("session.goal.clear", { sessionId });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Narrow agent catalog + first-turn execution resolver backed by Host RPC. */
|
|
157
|
+
export class HostAgentCatalog {
|
|
158
|
+
host;
|
|
159
|
+
constructor(host) {
|
|
160
|
+
this.host = host;
|
|
161
|
+
}
|
|
162
|
+
list() {
|
|
163
|
+
return this.host.call("agent.catalog.list", {});
|
|
164
|
+
}
|
|
165
|
+
get(id) {
|
|
166
|
+
return this.host.call("agent.catalog.get", { id });
|
|
167
|
+
}
|
|
168
|
+
resolveExecution(input) {
|
|
169
|
+
return this.host.call("agent.execution.resolve", input);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Daemon-owned session allocator. operationId must identify one allocation attempt durably. */
|
|
173
|
+
export class HostSessionProvisioner {
|
|
174
|
+
host;
|
|
175
|
+
instanceId;
|
|
176
|
+
resolvedExecutions = new Map();
|
|
177
|
+
constructor(host, instanceId) {
|
|
178
|
+
this.host = host;
|
|
179
|
+
this.instanceId = instanceId;
|
|
180
|
+
}
|
|
181
|
+
async provision(operationId, session = {}) {
|
|
182
|
+
const result = await this.host.call("session.ensure", {
|
|
183
|
+
scopeId: this.instanceId,
|
|
184
|
+
operationId,
|
|
185
|
+
session,
|
|
186
|
+
});
|
|
187
|
+
if (!result?.sessionId)
|
|
188
|
+
throw new Error("host did not return a provisioned session id");
|
|
189
|
+
this.resolvedExecutions.set(result.sessionId, {
|
|
190
|
+
runtime: result.execution.provider,
|
|
191
|
+
model: result.execution.model,
|
|
192
|
+
...(result.execution.reasoningEffort
|
|
193
|
+
? { reasoningEffort: result.execution.reasoningEffort }
|
|
194
|
+
: {}),
|
|
195
|
+
...(session.agent ? { agent: session.agent } : {}),
|
|
196
|
+
});
|
|
197
|
+
return result.sessionId;
|
|
198
|
+
}
|
|
199
|
+
takeExecution(sessionId) {
|
|
200
|
+
const execution = this.resolvedExecutions.get(sessionId);
|
|
201
|
+
this.resolvedExecutions.delete(sessionId);
|
|
202
|
+
return execution;
|
|
203
|
+
}
|
|
204
|
+
async existingExecution(sessionId) {
|
|
205
|
+
try {
|
|
206
|
+
const session = await this.host.call("session.meta.get", { sessionId });
|
|
207
|
+
return {
|
|
208
|
+
runtime: session.execution.provider,
|
|
209
|
+
model: session.execution.model,
|
|
210
|
+
...(session.execution.reasoningEffort
|
|
211
|
+
? { reasoningEffort: session.execution.reasoningEffort }
|
|
212
|
+
: {}),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (hostErrorCode(error) === "SESSION_NOT_FOUND")
|
|
217
|
+
return undefined;
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
allocationOperationId(sessionKey, previousSessionId) {
|
|
222
|
+
return stableOperationId("allocate", this.instanceId, sessionKey, previousSessionId ?? "initial");
|
|
223
|
+
}
|
|
224
|
+
forkOperationId(fromSessionId, newSessionKey) {
|
|
225
|
+
return stableOperationId("fork", this.instanceId, fromSessionId, newSessionKey);
|
|
226
|
+
}
|
|
227
|
+
async fork(operationId, sourceSessionId, title) {
|
|
228
|
+
const result = await this.host.call("session.fork", {
|
|
229
|
+
sourceSessionId,
|
|
230
|
+
operationId,
|
|
231
|
+
...(title ? { title } : {}),
|
|
232
|
+
});
|
|
233
|
+
if (!result?.sessionId)
|
|
234
|
+
throw new Error("host did not return a forked session id");
|
|
235
|
+
return result.sessionId;
|
|
236
|
+
}
|
|
237
|
+
async setTitle(sessionId, title) {
|
|
238
|
+
await this.host.call("session.meta.setTitle", { sessionId, title });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* File-backed Lark routing state whose every newly allocated machine session is
|
|
243
|
+
* minted by the daemon. Allocation operation ids are derived from the previous
|
|
244
|
+
* committed routing record, so a child crash between RPC and file commit replays
|
|
245
|
+
* the same host operation instead of creating a duplicate session.
|
|
246
|
+
*/
|
|
247
|
+
export class HostProvisionedLarkSessionStore extends FileLarkActiveSessionStore {
|
|
248
|
+
operation;
|
|
249
|
+
mutationTail = Promise.resolve();
|
|
250
|
+
instanceDefaultAgent;
|
|
251
|
+
constructor(options) {
|
|
252
|
+
const operation = new AsyncLocalStorage();
|
|
253
|
+
super({
|
|
254
|
+
filePath: options.filePath,
|
|
255
|
+
defaultAgent: options.defaultAgent,
|
|
256
|
+
now: options.now,
|
|
257
|
+
createSessionId: async () => {
|
|
258
|
+
const allocation = operation.getStore();
|
|
259
|
+
if (!allocation)
|
|
260
|
+
throw new Error("session allocation is missing its stable operation id");
|
|
261
|
+
return options.provisioner.provision(allocation.operationId, allocation.session);
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
this.operation = operation;
|
|
265
|
+
this.provisioner = options.provisioner;
|
|
266
|
+
this.instanceDefaultAgent = options.defaultAgent;
|
|
267
|
+
}
|
|
268
|
+
provisioner;
|
|
269
|
+
async ensure(sessionKey) {
|
|
270
|
+
return this.runMutation(async () => {
|
|
271
|
+
const current = await super.get(sessionKey);
|
|
272
|
+
const existingExecution = current
|
|
273
|
+
? await this.provisioner.existingExecution(current.sessionId)
|
|
274
|
+
: undefined;
|
|
275
|
+
if (current && existingExecution) {
|
|
276
|
+
const pinned = current.runtime
|
|
277
|
+
? current
|
|
278
|
+
: await super.freeze(sessionKey, existingExecution);
|
|
279
|
+
return { ...current, ...pinned, source: "existing" };
|
|
280
|
+
}
|
|
281
|
+
if (current) {
|
|
282
|
+
const replacement = await this.withAllocation(sessionKey, current.sessionId, launchMeta(current), () => super.rotate(sessionKey));
|
|
283
|
+
return {
|
|
284
|
+
...await this.pinResolvedExecution(sessionKey, replacement),
|
|
285
|
+
source: "new",
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const created = await this.withAllocation(sessionKey, undefined, this.instanceDefaultAgent ? { agent: this.instanceDefaultAgent } : {}, () => super.ensure(sessionKey));
|
|
289
|
+
return this.pinResolvedExecution(sessionKey, created);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
async set(sessionKey, sessionId, cwd) {
|
|
293
|
+
return this.runMutation(async () => this.pinResolvedExecution(sessionKey, await super.set(sessionKey, sessionId, cwd)));
|
|
294
|
+
}
|
|
295
|
+
async get(sessionKey) {
|
|
296
|
+
return this.runMutation(async () => {
|
|
297
|
+
const current = await super.get(sessionKey);
|
|
298
|
+
if (!current)
|
|
299
|
+
return current;
|
|
300
|
+
const existingExecution = await this.provisioner.existingExecution(current.sessionId);
|
|
301
|
+
if (existingExecution) {
|
|
302
|
+
return current.runtime ? current : super.freeze(sessionKey, existingExecution);
|
|
303
|
+
}
|
|
304
|
+
const replacement = await this.withAllocation(sessionKey, current.sessionId, launchMeta(current), () => super.rotate(sessionKey));
|
|
305
|
+
return this.pinResolvedExecution(sessionKey, replacement);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
async rotate(sessionKey) {
|
|
309
|
+
return this.runMutation(async () => {
|
|
310
|
+
const current = await super.get(sessionKey);
|
|
311
|
+
const rotated = await this.withAllocation(sessionKey, current?.sessionId, launchMeta(current), () => super.rotate(sessionKey));
|
|
312
|
+
return this.pinResolvedExecution(sessionKey, rotated);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
async bindCwd(sessionKey, cwd) {
|
|
316
|
+
void sessionKey;
|
|
317
|
+
void cwd;
|
|
318
|
+
throw new Error("working directory is managed by the Session Project snapshot");
|
|
319
|
+
}
|
|
320
|
+
async applySettings(sessionKey, settings) {
|
|
321
|
+
return this.runMutation(async () => {
|
|
322
|
+
if (!settings.rotate && (await super.get(sessionKey))) {
|
|
323
|
+
return super.applySettings(sessionKey, settings);
|
|
324
|
+
}
|
|
325
|
+
const current = await super.get(sessionKey);
|
|
326
|
+
const providerChanged = Boolean(settings.runtime && settings.runtime !== current?.runtime);
|
|
327
|
+
const updated = await this.withAllocation(sessionKey, current?.sessionId, launchMeta({
|
|
328
|
+
...(providerChanged
|
|
329
|
+
? { provider: settings.runtime }
|
|
330
|
+
: (current?.agent ?? this.instanceDefaultAgent)
|
|
331
|
+
? { agent: current?.agent ?? this.instanceDefaultAgent }
|
|
332
|
+
: settings.runtime
|
|
333
|
+
? { provider: settings.runtime }
|
|
334
|
+
: {}),
|
|
335
|
+
...(settings.model ? { model: settings.model } : {}),
|
|
336
|
+
...(settings.reasoningEffort ? { reasoningEffort: settings.reasoningEffort } : {}),
|
|
337
|
+
}), () => super.applySettings(sessionKey, settings));
|
|
338
|
+
return this.pinResolvedExecution(sessionKey, updated);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
async setAgent(sessionKey, agentName) {
|
|
342
|
+
return this.runMutation(async () => {
|
|
343
|
+
const current = await super.get(sessionKey);
|
|
344
|
+
const updated = await this.withAllocation(sessionKey, current?.sessionId, { agent: agentName }, () => super.setAgent(sessionKey, agentName));
|
|
345
|
+
return this.pinResolvedExecution(sessionKey, updated);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
async freeze(sessionKey, execution) {
|
|
349
|
+
return this.runMutation(async () => {
|
|
350
|
+
const current = await super.get(sessionKey);
|
|
351
|
+
if (current)
|
|
352
|
+
return super.freeze(sessionKey, execution);
|
|
353
|
+
const frozen = await this.withAllocation(sessionKey, undefined, launchMeta(execution), () => super.freeze(sessionKey, execution));
|
|
354
|
+
return this.pinResolvedExecution(sessionKey, frozen);
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
async pinResolvedExecution(sessionKey, record) {
|
|
358
|
+
const execution = this.provisioner.takeExecution(record.sessionId);
|
|
359
|
+
if (!execution)
|
|
360
|
+
return record;
|
|
361
|
+
const frozen = await super.freeze(sessionKey, execution);
|
|
362
|
+
return { ...record, ...frozen };
|
|
363
|
+
}
|
|
364
|
+
withAllocation(sessionKey, previousSessionId, session, run) {
|
|
365
|
+
return this.operation.run({
|
|
366
|
+
operationId: this.provisioner.allocationOperationId(sessionKey, previousSessionId),
|
|
367
|
+
session,
|
|
368
|
+
}, run);
|
|
369
|
+
}
|
|
370
|
+
async runMutation(run) {
|
|
371
|
+
const previous = this.mutationTail;
|
|
372
|
+
let release;
|
|
373
|
+
this.mutationTail = new Promise((resolve) => {
|
|
374
|
+
release = resolve;
|
|
375
|
+
});
|
|
376
|
+
await previous.catch(() => undefined);
|
|
377
|
+
try {
|
|
378
|
+
return await run();
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
release();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function launchMeta(input) {
|
|
386
|
+
if (!input)
|
|
387
|
+
return {};
|
|
388
|
+
return {
|
|
389
|
+
...(input.agent ? { agent: input.agent } : {}),
|
|
390
|
+
...(input.provider ? { provider: input.provider } : {}),
|
|
391
|
+
...(input.model ? { model: input.model } : {}),
|
|
392
|
+
...(input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {}),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function hostErrorCode(error) {
|
|
396
|
+
return error && typeof error === "object" && "code" in error &&
|
|
397
|
+
typeof error.code === "string"
|
|
398
|
+
? error.code
|
|
399
|
+
: undefined;
|
|
400
|
+
}
|
|
401
|
+
export function stableOperationId(kind, ...parts) {
|
|
402
|
+
const digest = createHash("sha256").update(parts.join("\0")).digest("hex");
|
|
403
|
+
return `${kind}-${digest}`;
|
|
404
|
+
}
|
|
405
|
+
class AsyncEventQueue {
|
|
406
|
+
options;
|
|
407
|
+
values = [];
|
|
408
|
+
waiters = [];
|
|
409
|
+
bufferedBytes = 0;
|
|
410
|
+
ended = false;
|
|
411
|
+
failure;
|
|
412
|
+
constructor(options) {
|
|
413
|
+
this.options = options;
|
|
414
|
+
}
|
|
415
|
+
push(value) {
|
|
416
|
+
if (this.ended || this.failure)
|
|
417
|
+
return "closed";
|
|
418
|
+
const waiter = this.waiters.shift();
|
|
419
|
+
if (waiter) {
|
|
420
|
+
waiter.resolve({ value, done: false });
|
|
421
|
+
return "accepted";
|
|
422
|
+
}
|
|
423
|
+
const bytes = this.options.sizeOf(value);
|
|
424
|
+
if (this.values.length >= this.options.maxItems
|
|
425
|
+
|| !Number.isSafeInteger(bytes)
|
|
426
|
+
|| bytes < 0
|
|
427
|
+
|| bytes > this.options.maxBytes - this.bufferedBytes) {
|
|
428
|
+
this.fail(this.options.overflowError(), true);
|
|
429
|
+
return "overflow";
|
|
430
|
+
}
|
|
431
|
+
this.values.push({ value, bytes });
|
|
432
|
+
this.bufferedBytes += bytes;
|
|
433
|
+
return "accepted";
|
|
434
|
+
}
|
|
435
|
+
end() {
|
|
436
|
+
if (this.ended || this.failure)
|
|
437
|
+
return;
|
|
438
|
+
this.ended = true;
|
|
439
|
+
for (const waiter of this.waiters.splice(0))
|
|
440
|
+
waiter.resolve({ value: undefined, done: true });
|
|
441
|
+
}
|
|
442
|
+
fail(error, discardBuffered = false) {
|
|
443
|
+
if (this.ended || this.failure)
|
|
444
|
+
return;
|
|
445
|
+
this.failure = error;
|
|
446
|
+
if (discardBuffered) {
|
|
447
|
+
this.values.length = 0;
|
|
448
|
+
this.bufferedBytes = 0;
|
|
449
|
+
}
|
|
450
|
+
for (const waiter of this.waiters.splice(0))
|
|
451
|
+
waiter.reject(error);
|
|
452
|
+
}
|
|
453
|
+
[Symbol.asyncIterator]() {
|
|
454
|
+
return {
|
|
455
|
+
next: () => {
|
|
456
|
+
const entry = this.values.shift();
|
|
457
|
+
if (entry) {
|
|
458
|
+
this.bufferedBytes -= entry.bytes;
|
|
459
|
+
return Promise.resolve({ value: entry.value, done: false });
|
|
460
|
+
}
|
|
461
|
+
if (this.failure)
|
|
462
|
+
return Promise.reject(this.failure);
|
|
463
|
+
if (this.ended)
|
|
464
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
465
|
+
return new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function jsonByteLength(value) {
|
|
471
|
+
try {
|
|
472
|
+
const encoded = JSON.stringify(value);
|
|
473
|
+
return encoded === undefined ? 0 : Buffer.byteLength(encoded, "utf8");
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
return Number.POSITIVE_INFINITY;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function runEventQueueOverflowError() {
|
|
480
|
+
return new AgentRuntimeError(`host run event queue exceeded ${LARK_RUN_EVENT_QUEUE_MAX_ITEMS} items or ${LARK_RUN_EVENT_QUEUE_MAX_BYTES} bytes; the run was interrupted`, 503, "plugin_event_queue_overflow");
|
|
481
|
+
}
|
|
482
|
+
function runEventPayload(value) {
|
|
483
|
+
if (!isRecord(value) || typeof value.runId !== "string" || !isRecord(value.event))
|
|
484
|
+
return undefined;
|
|
485
|
+
return value;
|
|
486
|
+
}
|
|
487
|
+
function runTerminalPayload(value) {
|
|
488
|
+
if (!isRecord(value) || typeof value.runId !== "string")
|
|
489
|
+
return undefined;
|
|
490
|
+
return value;
|
|
491
|
+
}
|
|
492
|
+
function hostRunError(payload) {
|
|
493
|
+
const code = payload.error?.code || "plugin_host_run_failed";
|
|
494
|
+
return new AgentRuntimeError(payload.error?.message || "host conversation run failed", code === "codex_cancelled" ? 499 : 500, code);
|
|
495
|
+
}
|
|
496
|
+
function toAgentRuntimeError(error) {
|
|
497
|
+
if (error instanceof AgentRuntimeError)
|
|
498
|
+
return error;
|
|
499
|
+
const code = isRecord(error) && typeof error.code === "string" ? error.code : "plugin_host_call_failed";
|
|
500
|
+
return new AgentRuntimeError(error instanceof Error ? error.message : String(error), 500, code);
|
|
501
|
+
}
|
|
502
|
+
function isRecord(value) {
|
|
503
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
504
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Public Lark plugin API. Rynx loads the manifest's self-contained runtime
|
|
2
|
+
* module; this package exports no in-process daemon Channel factory. */
|
|
3
|
+
export { LocalLarkBotRuntime } from "./lark.js";
|
|
4
|
+
export { authorizeLark, larkConfigSchema, LARK_BOT_SCOPES, LARK_BOT_EVENTS, type LarkAuthorizationMaterial, type LarkSetupField, } from "./lark-setup.js";
|
|
5
|
+
export { activate, createLarkPluginRuntime, LARK_CHANNEL_ID, type LarkPluginRuntimeOptions, } from "./runtime.js";
|
|
6
|
+
export { createLarkPluginSettings, type LarkPluginSettingsOptions, } from "./settings.js";
|
|
7
|
+
export { HostAgentCapabilities, HostAgentCatalog, HostConversationRuntime, HostProvisionedLarkSessionStore, HostSessionProvisioner, stableOperationId, } from "./host-adapters.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Public Lark plugin API. Rynx loads the manifest's self-contained runtime
|
|
2
|
+
* module; this package exports no in-process daemon Channel factory. */
|
|
3
|
+
export { LocalLarkBotRuntime } from "./lark.js";
|
|
4
|
+
export { authorizeLark, larkConfigSchema, LARK_BOT_SCOPES, LARK_BOT_EVENTS, } from "./lark-setup.js";
|
|
5
|
+
export { activate, createLarkPluginRuntime, LARK_CHANNEL_ID, } from "./runtime.js";
|
|
6
|
+
export { createLarkPluginSettings, } from "./settings.js";
|
|
7
|
+
export { HostAgentCapabilities, HostAgentCatalog, HostConversationRuntime, HostProvisionedLarkSessionStore, HostSessionProvisioner, stableOperationId, } from "./host-adapters.js";
|