@raisindb/client 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{conversation-list-store-BaeGM2lx.d.mts → conversation-list-store-CHaqGtSi.d.mts} +737 -1
- package/dist/{conversation-list-store-BaeGM2lx.d.ts → conversation-list-store-CHaqGtSi.d.ts} +737 -1
- package/dist/{index-C4pX6FVI.d.mts → index-AobOnS4A.d.mts} +1 -1
- package/dist/{index-DCtNAWZ0.d.ts → index-DiL2gplR.d.ts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +551 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +546 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{svelte-sql-BhMxrqn_.d.mts → svelte-sql-BUrNcoHR.d.mts} +1 -1
- package/dist/{svelte-sql-DN3NpM4c.d.ts → svelte-sql-FQqis53r.d.ts} +1 -1
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -491,6 +491,15 @@ var RequestType = /* @__PURE__ */ ((RequestType2) => {
|
|
|
491
491
|
RequestType2["FlowCancel"] = "flow_cancel";
|
|
492
492
|
RequestType2["FlowSubscribeEvents"] = "flow_subscribe_events";
|
|
493
493
|
RequestType2["FlowUnsubscribeEvents"] = "flow_unsubscribe_events";
|
|
494
|
+
RequestType2["AgentRunCreate"] = "agent_run_create";
|
|
495
|
+
RequestType2["AgentRunGet"] = "agent_run_get";
|
|
496
|
+
RequestType2["AgentRunBySubject"] = "agent_run_by_subject";
|
|
497
|
+
RequestType2["AgentRunList"] = "agent_run_list";
|
|
498
|
+
RequestType2["AgentRunEvents"] = "agent_run_events";
|
|
499
|
+
RequestType2["AgentRunSubscribe"] = "agent_run_subscribe";
|
|
500
|
+
RequestType2["AgentRunUnsubscribe"] = "agent_run_unsubscribe";
|
|
501
|
+
RequestType2["AgentRunControl"] = "agent_run_control";
|
|
502
|
+
RequestType2["AgentRunChildren"] = "agent_run_children";
|
|
494
503
|
RequestType2["FunctionInvoke"] = "function_invoke";
|
|
495
504
|
RequestType2["FunctionInvokeSync"] = "function_invoke_sync";
|
|
496
505
|
RequestType2["ScheduledInvocationCreate"] = "scheduled_invocation_create";
|
|
@@ -2975,6 +2984,417 @@ function createAsyncQueue() {
|
|
|
2975
2984
|
};
|
|
2976
2985
|
}
|
|
2977
2986
|
|
|
2987
|
+
// src/agent-run-children.ts
|
|
2988
|
+
function spawnBody(o) {
|
|
2989
|
+
return {
|
|
2990
|
+
objective: o.objective,
|
|
2991
|
+
budgets: o.budgets,
|
|
2992
|
+
on_exceeded: o.onExceeded,
|
|
2993
|
+
spawn_key: o.spawnKey,
|
|
2994
|
+
subject: o.subject,
|
|
2995
|
+
as_agent: o.asAgent,
|
|
2996
|
+
agent_ref: o.agentRef,
|
|
2997
|
+
input: o.input ?? null,
|
|
2998
|
+
executor_config: o.executorConfig,
|
|
2999
|
+
reducer: o.reducer,
|
|
3000
|
+
inherit_reducer: o.inheritReducer ?? false
|
|
3001
|
+
};
|
|
3002
|
+
}
|
|
3003
|
+
function checkpointBody(o) {
|
|
3004
|
+
return {
|
|
3005
|
+
fence: o.fence,
|
|
3006
|
+
operation_id: o.operationId,
|
|
3007
|
+
reason: o.reason,
|
|
3008
|
+
summary: o.summary,
|
|
3009
|
+
transcript_cutoff: o.transcriptCutoff,
|
|
3010
|
+
state: o.state,
|
|
3011
|
+
large_refs: o.largeRefs ?? []
|
|
3012
|
+
};
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
// src/agent-runs.ts
|
|
3016
|
+
function createRunBody(options) {
|
|
3017
|
+
return {
|
|
3018
|
+
subject: options.subject,
|
|
3019
|
+
branch: options.branch,
|
|
3020
|
+
agent_ref: options.agentRef,
|
|
3021
|
+
create_key: options.createKey,
|
|
3022
|
+
budgets: options.budgets,
|
|
3023
|
+
input: options.input ?? null,
|
|
3024
|
+
reducer: options.reducer,
|
|
3025
|
+
executor_config: options.executorConfig,
|
|
3026
|
+
control_capability: options.controlCapability,
|
|
3027
|
+
as_agent: options.asAgent
|
|
3028
|
+
};
|
|
3029
|
+
}
|
|
3030
|
+
function subjectOf(subject) {
|
|
3031
|
+
if (typeof subject !== "string") return subject;
|
|
3032
|
+
const cut = subject.indexOf(":/");
|
|
3033
|
+
if (cut <= 0) throw new Error(`subject must be "workspace:/path", got "${subject}"`);
|
|
3034
|
+
return { workspace: subject.slice(0, cut), path: subject.slice(cut + 1) };
|
|
3035
|
+
}
|
|
3036
|
+
var controlCounter = 0;
|
|
3037
|
+
function newControlId(prefix = "ctl") {
|
|
3038
|
+
controlCounter += 1;
|
|
3039
|
+
const rand = Math.random().toString(36).slice(2, 10);
|
|
3040
|
+
return `${prefix}-${Date.now().toString(36)}-${controlCounter}-${rand}`;
|
|
3041
|
+
}
|
|
3042
|
+
var AgentRunsApi = class {
|
|
3043
|
+
constructor(repository, transport) {
|
|
3044
|
+
this.repository = repository;
|
|
3045
|
+
this.transport = transport;
|
|
3046
|
+
}
|
|
3047
|
+
base(runId, rest = "") {
|
|
3048
|
+
const repo = encodeURIComponent(this.repository);
|
|
3049
|
+
const run = runId ? `/${encodeURIComponent(runId)}` : "";
|
|
3050
|
+
return `/api/agent-runs/${repo}${run}${rest}`;
|
|
3051
|
+
}
|
|
3052
|
+
/** Create a run, or get back the subject's live run. */
|
|
3053
|
+
create(options) {
|
|
3054
|
+
return this.transport.request("POST", this.base(), createRunBody(options));
|
|
3055
|
+
}
|
|
3056
|
+
/** Every run about `subject` you may see, newest (the live one) first. */
|
|
3057
|
+
bySubject(subject, limit = 20) {
|
|
3058
|
+
const s = subjectOf(subject);
|
|
3059
|
+
const q = new URLSearchParams({ subject: `${s.workspace}:${s.path ?? ""}`, limit: String(limit) });
|
|
3060
|
+
if (s.node_id) q.set("subject_node_id", s.node_id);
|
|
3061
|
+
return this.transport.request("GET", `${this.base()}?${q.toString()}`);
|
|
3062
|
+
}
|
|
3063
|
+
/** Read a run (record + effective projection). */
|
|
3064
|
+
get(runId) {
|
|
3065
|
+
return this.transport.request("GET", this.base(runId));
|
|
3066
|
+
}
|
|
3067
|
+
/** Your runs in one status (default "running"). */
|
|
3068
|
+
list(status = "running", limit = 50) {
|
|
3069
|
+
return this.transport.request("GET", `${this.base()}?status=${status}&limit=${limit}`);
|
|
3070
|
+
}
|
|
3071
|
+
/** Durable events after `afterSeq` (gap-free; page with the last seq). */
|
|
3072
|
+
events(runId, afterSeq = 0, limit = 500) {
|
|
3073
|
+
return this.transport.request("GET", this.base(runId, `/events?after_seq=${afterSeq}&limit=${limit}`));
|
|
3074
|
+
}
|
|
3075
|
+
/** Any control. Retrying with the same `controlId` is a no-op. */
|
|
3076
|
+
control(runId, command, controlId = newControlId(command.command), capability) {
|
|
3077
|
+
return this.transport.request("POST", this.base(runId, "/control"), {
|
|
3078
|
+
control_id: controlId,
|
|
3079
|
+
command,
|
|
3080
|
+
capability
|
|
3081
|
+
});
|
|
3082
|
+
}
|
|
3083
|
+
stop(runId, reason, controlId) {
|
|
3084
|
+
return this.control(runId, { command: "stop", reason }, controlId);
|
|
3085
|
+
}
|
|
3086
|
+
pause(runId, controlId) {
|
|
3087
|
+
return this.control(runId, { command: "pause" }, controlId);
|
|
3088
|
+
}
|
|
3089
|
+
resume(runId, controlId) {
|
|
3090
|
+
return this.control(runId, { command: "resume" }, controlId);
|
|
3091
|
+
}
|
|
3092
|
+
/** Queue input for the run's next safe boundary. */
|
|
3093
|
+
steer(runId, input, controlId) {
|
|
3094
|
+
return this.control(runId, { command: "steer", input }, controlId);
|
|
3095
|
+
}
|
|
3096
|
+
/** Decide an approval request; the digest ties it to one changeset. */
|
|
3097
|
+
approve(runId, requestId, subjectDigest, reject, controlId) {
|
|
3098
|
+
const decision = reject ? { decision: "reject", reason: reject.reason } : { decision: "approve" };
|
|
3099
|
+
return this.control(
|
|
3100
|
+
runId,
|
|
3101
|
+
{ command: "approve", request_id: requestId, decision, subject_digest: subjectDigest },
|
|
3102
|
+
controlId
|
|
3103
|
+
);
|
|
3104
|
+
}
|
|
3105
|
+
/** Answer an input request. */
|
|
3106
|
+
answer(runId, requestId, value, controlId) {
|
|
3107
|
+
return this.control(runId, { command: "provide_input", request_id: requestId, value }, controlId);
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
3110
|
+
* Stream the run's events: replay after `afterSeq`, then live. Ends after
|
|
3111
|
+
* the run's terminal event. Resume after a disconnect with the last `seq`.
|
|
3112
|
+
*/
|
|
3113
|
+
async *stream(runId, afterSeq = 0, signal) {
|
|
3114
|
+
const response = await this.transport.fetch(
|
|
3115
|
+
this.transport.url(this.base(runId, `/stream?after_seq=${afterSeq}`)),
|
|
3116
|
+
{ headers: { ...this.transport.headers(), Accept: "text/event-stream" }, signal }
|
|
3117
|
+
);
|
|
3118
|
+
if (!response.ok || !response.body) {
|
|
3119
|
+
throw new Error(`agent run stream failed: ${response.status} ${await response.text()}`);
|
|
3120
|
+
}
|
|
3121
|
+
const reader = response.body.getReader();
|
|
3122
|
+
const decoder = new TextDecoder();
|
|
3123
|
+
let buffer = "";
|
|
3124
|
+
for (; ; ) {
|
|
3125
|
+
const { value, done } = await reader.read();
|
|
3126
|
+
if (done) return;
|
|
3127
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3128
|
+
let cut;
|
|
3129
|
+
while ((cut = buffer.indexOf("\n\n")) >= 0) {
|
|
3130
|
+
const block = buffer.slice(0, cut);
|
|
3131
|
+
buffer = buffer.slice(cut + 2);
|
|
3132
|
+
let event = "message";
|
|
3133
|
+
let data = "";
|
|
3134
|
+
for (const line of block.split("\n")) {
|
|
3135
|
+
if (line.startsWith("event:")) event = line.slice(6).trim();
|
|
3136
|
+
else if (line.startsWith("data:")) data += line.slice(5).trim();
|
|
3137
|
+
}
|
|
3138
|
+
if (event === "end") return;
|
|
3139
|
+
if (event === "error") throw new Error(`agent run stream error: ${data}`);
|
|
3140
|
+
if (event === "run-event" && data) yield JSON.parse(data);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
// ---- client-driven runs -------------------------------------------------
|
|
3145
|
+
/** Take the lease of a queued client-driven run. */
|
|
3146
|
+
acquire(runId) {
|
|
3147
|
+
return this.transport.request("POST", this.base(runId, "/lease/acquire"), {});
|
|
3148
|
+
}
|
|
3149
|
+
renew(runId, fence) {
|
|
3150
|
+
return this.transport.request("POST", this.base(runId, "/lease/renew"), { fence });
|
|
3151
|
+
}
|
|
3152
|
+
release(runId, fence) {
|
|
3153
|
+
return this.transport.request("POST", this.base(runId, "/lease/release"), { fence });
|
|
3154
|
+
}
|
|
3155
|
+
/** Begin an operation; returns the active operation (its `op_id`). */
|
|
3156
|
+
begin(runId, fence, op) {
|
|
3157
|
+
return this.transport.request("POST", this.base(runId, "/operations"), { fence, ...op });
|
|
3158
|
+
}
|
|
3159
|
+
/** Record an operation's result. */
|
|
3160
|
+
finish(runId, fence, opId, result) {
|
|
3161
|
+
return this.transport.request("POST", this.base(runId, "/operations/finish"), { fence, op_id: opId, ...result });
|
|
3162
|
+
}
|
|
3163
|
+
/** Open approval/input requests and wait (`kind: "approval" | "input"`). */
|
|
3164
|
+
wait(runId, fence, requests) {
|
|
3165
|
+
return this.transport.request("POST", this.base(runId, "/wait"), { fence, requests });
|
|
3166
|
+
}
|
|
3167
|
+
/** End a client-driven run. */
|
|
3168
|
+
complete(runId, fence, status, outcome) {
|
|
3169
|
+
return this.transport.request("POST", this.base(runId, "/complete"), { fence, status, outcome });
|
|
3170
|
+
}
|
|
3171
|
+
// ── Child runs, mailbox, checkpoints, usage ──────────────────────────────
|
|
3172
|
+
/** Spawn a child with a typed objective; its budgets come out of this run's. */
|
|
3173
|
+
spawnChild(runId, options) {
|
|
3174
|
+
const q = options.branch ? `?branch=${encodeURIComponent(options.branch)}` : "";
|
|
3175
|
+
return this.transport.request("POST", this.base(runId, `/children${q}`), spawnBody(options));
|
|
3176
|
+
}
|
|
3177
|
+
/** Every child of a run: the parent's link plus the child's live status. */
|
|
3178
|
+
children(runId) {
|
|
3179
|
+
return this.transport.request("GET", this.base(runId, "/children"));
|
|
3180
|
+
}
|
|
3181
|
+
/** Inspect one child: record, events after `afterSeq`, usage, checkpoint. */
|
|
3182
|
+
inspectChild(runId, childId, afterSeq = 0, limit = 200) {
|
|
3183
|
+
const rest = `/children/${encodeURIComponent(childId)}?after_seq=${afterSeq}&limit=${limit}`;
|
|
3184
|
+
return this.transport.request("GET", this.base(runId, rest));
|
|
3185
|
+
}
|
|
3186
|
+
/** Message, steer, interrupt or resume a child (idempotent per `controlId`). */
|
|
3187
|
+
controlChild(runId, childId, action, controlId = newControlId(action.action)) {
|
|
3188
|
+
const rest = `/children/${encodeURIComponent(childId)}/control`;
|
|
3189
|
+
return this.transport.request("POST", this.base(runId, rest), { control_id: controlId, ...action });
|
|
3190
|
+
}
|
|
3191
|
+
messageChild(runId, childId, message, controlId) {
|
|
3192
|
+
return this.controlChild(runId, childId, { action: "message", message }, controlId);
|
|
3193
|
+
}
|
|
3194
|
+
steerChild(runId, childId, input, controlId) {
|
|
3195
|
+
return this.controlChild(runId, childId, { action: "steer", input }, controlId);
|
|
3196
|
+
}
|
|
3197
|
+
interruptChild(runId, childId, reason, mode = "stop", controlId) {
|
|
3198
|
+
return this.controlChild(runId, childId, { action: "interrupt", mode, reason }, controlId);
|
|
3199
|
+
}
|
|
3200
|
+
/** A client-driven parent waits (under its lease) for a child's hand-back. */
|
|
3201
|
+
waitChild(runId, childId, fence, expiresAtMs) {
|
|
3202
|
+
const rest = `/children/${encodeURIComponent(childId)}/wait`;
|
|
3203
|
+
return this.transport.request("POST", this.base(runId, rest), { fence, expires_at_ms: expiresAtMs });
|
|
3204
|
+
}
|
|
3205
|
+
/** Unacknowledged mailbox items (hand-backs and child messages). */
|
|
3206
|
+
mailbox(runId) {
|
|
3207
|
+
return this.transport.request("GET", this.base(runId, "/mailbox"));
|
|
3208
|
+
}
|
|
3209
|
+
/** Acknowledge mailbox items up to `upTo`. */
|
|
3210
|
+
ackMailbox(runId, upTo) {
|
|
3211
|
+
return this.transport.request("POST", this.base(runId, "/mailbox/ack"), { up_to: upTo });
|
|
3212
|
+
}
|
|
3213
|
+
/** A child posts a message to its parent's mailbox (idempotent per id). */
|
|
3214
|
+
postToParent(runId, messageId, message) {
|
|
3215
|
+
return this.transport.request("POST", this.base(runId, "/post-to-parent"), { message_id: messageId, message });
|
|
3216
|
+
}
|
|
3217
|
+
/** Write a structured checkpoint (compaction keeps state, not prose). */
|
|
3218
|
+
checkpoint(runId, options) {
|
|
3219
|
+
return this.transport.request("POST", this.base(runId, "/checkpoints"), checkpointBody(options));
|
|
3220
|
+
}
|
|
3221
|
+
/** Read a checkpoint (default: latest) with its structured state. */
|
|
3222
|
+
readCheckpoint(runId, checkpointNo) {
|
|
3223
|
+
return this.transport.request("GET", this.base(runId, `/checkpoints/${checkpointNo ?? "latest"}`));
|
|
3224
|
+
}
|
|
3225
|
+
/** Usage accounting: own, children, reserved, spare. */
|
|
3226
|
+
usage(runId) {
|
|
3227
|
+
return this.transport.request("GET", this.base(runId, "/usage"));
|
|
3228
|
+
}
|
|
3229
|
+
};
|
|
3230
|
+
|
|
3231
|
+
// src/agent-runs-ws.ts
|
|
3232
|
+
var TERMINAL = ["completed", "failed", "stopped"];
|
|
3233
|
+
var AgentRunsWsApi = class {
|
|
3234
|
+
constructor(context, sendRequest, eventHandler) {
|
|
3235
|
+
this.context = context;
|
|
3236
|
+
this.sendRequest = sendRequest;
|
|
3237
|
+
this.eventHandler = eventHandler;
|
|
3238
|
+
}
|
|
3239
|
+
call(type, payload) {
|
|
3240
|
+
return this.sendRequest(payload, type, this.context);
|
|
3241
|
+
}
|
|
3242
|
+
/** Create a run, or get back the subject's live run. */
|
|
3243
|
+
create(options) {
|
|
3244
|
+
return this.call("agent_run_create" /* AgentRunCreate */, createRunBody(options));
|
|
3245
|
+
}
|
|
3246
|
+
/** Read a run (record + effective projection). */
|
|
3247
|
+
get(runId) {
|
|
3248
|
+
return this.call("agent_run_get" /* AgentRunGet */, { run_id: runId });
|
|
3249
|
+
}
|
|
3250
|
+
/**
|
|
3251
|
+
* Every run about `subject` (a conversation, a document) you may see,
|
|
3252
|
+
* newest first — the live run, if there is one, comes first.
|
|
3253
|
+
*/
|
|
3254
|
+
bySubject(subject, limit = 20) {
|
|
3255
|
+
return this.call("agent_run_by_subject" /* AgentRunBySubject */, { ...subjectOf(subject), limit });
|
|
3256
|
+
}
|
|
3257
|
+
/** The newest run of `subject`, or null. */
|
|
3258
|
+
async latest(subject) {
|
|
3259
|
+
const [first] = await this.bySubject(subject, 1);
|
|
3260
|
+
return first ?? null;
|
|
3261
|
+
}
|
|
3262
|
+
/** Your runs in one status (default "running"). */
|
|
3263
|
+
list(status = "running", limit = 50) {
|
|
3264
|
+
return this.call("agent_run_list" /* AgentRunList */, { status, limit });
|
|
3265
|
+
}
|
|
3266
|
+
/** Durable events after `afterSeq`. */
|
|
3267
|
+
events(runId, afterSeq = 0, limit = 500) {
|
|
3268
|
+
return this.call("agent_run_events" /* AgentRunEvents */, { run_id: runId, after_seq: afterSeq, limit });
|
|
3269
|
+
}
|
|
3270
|
+
/** The children a run spawned, with their current status. */
|
|
3271
|
+
children(runId) {
|
|
3272
|
+
return this.call("agent_run_children" /* AgentRunChildren */, { run_id: runId });
|
|
3273
|
+
}
|
|
3274
|
+
/** Any control. Retrying with the same `controlId` is a no-op. */
|
|
3275
|
+
control(runId, command, controlId = newControlId(command.command), capability) {
|
|
3276
|
+
return this.call("agent_run_control" /* AgentRunControl */, { run_id: runId, control_id: controlId, command, capability });
|
|
3277
|
+
}
|
|
3278
|
+
stop(runId, reason, controlId) {
|
|
3279
|
+
return this.control(runId, { command: "stop", reason }, controlId);
|
|
3280
|
+
}
|
|
3281
|
+
pause(runId, controlId) {
|
|
3282
|
+
return this.control(runId, { command: "pause" }, controlId);
|
|
3283
|
+
}
|
|
3284
|
+
resume(runId, controlId) {
|
|
3285
|
+
return this.control(runId, { command: "resume" }, controlId);
|
|
3286
|
+
}
|
|
3287
|
+
/** Queue input for the run's next safe boundary. */
|
|
3288
|
+
steer(runId, input, controlId) {
|
|
3289
|
+
return this.control(runId, { command: "steer", input }, controlId);
|
|
3290
|
+
}
|
|
3291
|
+
/** Decide an approval request; the digest ties it to one changeset. */
|
|
3292
|
+
approve(runId, requestId, subjectDigest, reject, controlId) {
|
|
3293
|
+
const decision = reject ? { decision: "reject", reason: reject.reason } : { decision: "approve" };
|
|
3294
|
+
return this.control(runId, { command: "approve", request_id: requestId, decision, subject_digest: subjectDigest }, controlId);
|
|
3295
|
+
}
|
|
3296
|
+
/** Answer an input request. */
|
|
3297
|
+
answer(runId, requestId, value, controlId) {
|
|
3298
|
+
return this.control(runId, { command: "provide_input", request_id: requestId, value }, controlId);
|
|
3299
|
+
}
|
|
3300
|
+
/**
|
|
3301
|
+
* Follow a run: replay after `afterSeq`, then live, until the run ends.
|
|
3302
|
+
*
|
|
3303
|
+
* Events that reach the socket before the subscription is known here are
|
|
3304
|
+
* not lost: the durable log is read once the listener is in place, live
|
|
3305
|
+
* events are held until that read is merged, and every seq is delivered
|
|
3306
|
+
* exactly once, in order.
|
|
3307
|
+
*/
|
|
3308
|
+
async subscribe(runId, options = {}) {
|
|
3309
|
+
let last = options.afterSeq ?? 0;
|
|
3310
|
+
let ready = false;
|
|
3311
|
+
let closed = false;
|
|
3312
|
+
const held = [];
|
|
3313
|
+
const buffer = [];
|
|
3314
|
+
const waiters = [];
|
|
3315
|
+
let resolveDone;
|
|
3316
|
+
const done = new Promise((r) => resolveDone = r);
|
|
3317
|
+
const close = (ended) => {
|
|
3318
|
+
if (closed) return;
|
|
3319
|
+
closed = true;
|
|
3320
|
+
if (ended) options.onEnd?.(last);
|
|
3321
|
+
for (const w of waiters.splice(0)) w({ value: void 0, done: true });
|
|
3322
|
+
resolveDone();
|
|
3323
|
+
};
|
|
3324
|
+
const deliver = (ev) => {
|
|
3325
|
+
if (closed || ev.seq <= last) return;
|
|
3326
|
+
last = ev.seq;
|
|
3327
|
+
options.onEvent?.(ev);
|
|
3328
|
+
const w = waiters.shift();
|
|
3329
|
+
if (w) w({ value: ev, done: false });
|
|
3330
|
+
else buffer.push(ev);
|
|
3331
|
+
};
|
|
3332
|
+
const listener = (message) => {
|
|
3333
|
+
if (message.event_type === "agent_run_end") {
|
|
3334
|
+
if (ready) close(true);
|
|
3335
|
+
else held.push({ seq: Number.MAX_SAFE_INTEGER });
|
|
3336
|
+
return;
|
|
3337
|
+
}
|
|
3338
|
+
const ev = message.payload;
|
|
3339
|
+
if (ready) deliver(ev);
|
|
3340
|
+
else held.push(ev);
|
|
3341
|
+
};
|
|
3342
|
+
const response = await this.call("agent_run_subscribe" /* AgentRunSubscribe */, {
|
|
3343
|
+
run_id: runId,
|
|
3344
|
+
after_seq: last
|
|
3345
|
+
});
|
|
3346
|
+
const subscriptionId = response.subscription_id;
|
|
3347
|
+
this.eventHandler.addFlowEventListener(subscriptionId, listener);
|
|
3348
|
+
const unsubscribe = async () => {
|
|
3349
|
+
this.eventHandler.removeFlowEventListener(subscriptionId);
|
|
3350
|
+
close(false);
|
|
3351
|
+
await this.call("agent_run_unsubscribe" /* AgentRunUnsubscribe */, { subscription_id: subscriptionId }).catch(() => void 0);
|
|
3352
|
+
};
|
|
3353
|
+
options.signal?.addEventListener("abort", () => void unsubscribe(), { once: true });
|
|
3354
|
+
for (; ; ) {
|
|
3355
|
+
const page = await this.events(runId, last, 500);
|
|
3356
|
+
page.forEach(deliver);
|
|
3357
|
+
if (page.length < 500) break;
|
|
3358
|
+
}
|
|
3359
|
+
ready = true;
|
|
3360
|
+
const endSeen = held.some((e) => e.seq === Number.MAX_SAFE_INTEGER);
|
|
3361
|
+
held.filter((e) => e.seq !== Number.MAX_SAFE_INTEGER).sort((a, b) => a.seq - b.seq).forEach(deliver);
|
|
3362
|
+
if (endSeen) close(true);
|
|
3363
|
+
else {
|
|
3364
|
+
const view = await this.get(runId).catch(() => null);
|
|
3365
|
+
const finalized = !view?.run?.domain || view.run.domain.finalized !== false;
|
|
3366
|
+
if (view && TERMINAL.includes(view.status) && finalized) {
|
|
3367
|
+
const tail = await this.events(runId, last, 500).catch(() => []);
|
|
3368
|
+
tail.forEach(deliver);
|
|
3369
|
+
this.eventHandler.removeFlowEventListener(subscriptionId);
|
|
3370
|
+
close(true);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
void done.then(() => this.eventHandler.removeFlowEventListener(subscriptionId));
|
|
3374
|
+
return {
|
|
3375
|
+
get lastSeq() {
|
|
3376
|
+
return last;
|
|
3377
|
+
},
|
|
3378
|
+
done,
|
|
3379
|
+
unsubscribe,
|
|
3380
|
+
[Symbol.asyncIterator]() {
|
|
3381
|
+
return {
|
|
3382
|
+
next: () => {
|
|
3383
|
+
const ev = buffer.shift();
|
|
3384
|
+
if (ev) return Promise.resolve({ value: ev, done: false });
|
|
3385
|
+
if (closed) return Promise.resolve({ value: void 0, done: true });
|
|
3386
|
+
return new Promise((r) => waiters.push(r));
|
|
3387
|
+
},
|
|
3388
|
+
return: async () => {
|
|
3389
|
+
await unsubscribe();
|
|
3390
|
+
return { value: void 0, done: true };
|
|
3391
|
+
}
|
|
3392
|
+
};
|
|
3393
|
+
}
|
|
3394
|
+
};
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
|
|
2978
3398
|
// src/functions-api.ts
|
|
2979
3399
|
var FunctionsApi = class {
|
|
2980
3400
|
constructor(repository, context, sendRequest) {
|
|
@@ -4280,6 +4700,16 @@ var Database = class _Database {
|
|
|
4280
4700
|
}
|
|
4281
4701
|
return this._flowsApi;
|
|
4282
4702
|
}
|
|
4703
|
+
/**
|
|
4704
|
+
* Durable agent runs over this WebSocket connection: find a subject's run,
|
|
4705
|
+
* follow it live (gap-free, resumable), control it, list its children.
|
|
4706
|
+
*/
|
|
4707
|
+
runs() {
|
|
4708
|
+
if (!this._runsApi) {
|
|
4709
|
+
this._runsApi = new AgentRunsWsApi(this._context, this.sendRequest, this.eventHandler);
|
|
4710
|
+
}
|
|
4711
|
+
return this._runsApi;
|
|
4712
|
+
}
|
|
4283
4713
|
/**
|
|
4284
4714
|
* Get FunctionsApi for invoking server-side functions via WebSocket
|
|
4285
4715
|
*/
|
|
@@ -6016,6 +6446,82 @@ function readTokensFromFragment(hashOrUrl) {
|
|
|
6016
6446
|
return { accessToken, refreshToken: params.get("refresh_token") };
|
|
6017
6447
|
}
|
|
6018
6448
|
|
|
6449
|
+
// src/node-dev.ts
|
|
6450
|
+
var NodeDevApi = class {
|
|
6451
|
+
constructor(repository, transport) {
|
|
6452
|
+
this.repository = repository;
|
|
6453
|
+
this.transport = transport;
|
|
6454
|
+
}
|
|
6455
|
+
/** Call any method by name (the typed helpers below all use this). */
|
|
6456
|
+
call(method, request) {
|
|
6457
|
+
const branch = typeof request.branch === "string" ? `?branch=${encodeURIComponent(request.branch)}` : "";
|
|
6458
|
+
return this.transport.request(
|
|
6459
|
+
"POST",
|
|
6460
|
+
`/api/node-dev/${encodeURIComponent(this.repository)}/${method}${branch}`,
|
|
6461
|
+
request
|
|
6462
|
+
);
|
|
6463
|
+
}
|
|
6464
|
+
changeset(o) {
|
|
6465
|
+
const { idempotencyKey, ...rest } = o;
|
|
6466
|
+
return { ...rest, idempotency_key: idempotencyKey };
|
|
6467
|
+
}
|
|
6468
|
+
stat(target, o = {}) {
|
|
6469
|
+
return this.call("stat", { ...o, target });
|
|
6470
|
+
}
|
|
6471
|
+
read(target, o = {}) {
|
|
6472
|
+
return this.call("read", { ...o, target });
|
|
6473
|
+
}
|
|
6474
|
+
list(target, o = {}) {
|
|
6475
|
+
return this.call("list", { ...o, target });
|
|
6476
|
+
}
|
|
6477
|
+
diff(target, from, to, o = {}) {
|
|
6478
|
+
return this.call("diff", { ...o, target, from, to });
|
|
6479
|
+
}
|
|
6480
|
+
/** Changes inside the roots after `since` (a cursor from a previous call). */
|
|
6481
|
+
watch(since, o = {}) {
|
|
6482
|
+
return this.call("watch", { ...o, since });
|
|
6483
|
+
}
|
|
6484
|
+
dryRun(o) {
|
|
6485
|
+
return this.call("dry_run", this.changeset(o));
|
|
6486
|
+
}
|
|
6487
|
+
propose(o) {
|
|
6488
|
+
return this.call(
|
|
6489
|
+
"propose",
|
|
6490
|
+
this.changeset(o)
|
|
6491
|
+
);
|
|
6492
|
+
}
|
|
6493
|
+
getChangeset(changesetId, o = {}) {
|
|
6494
|
+
return this.call("get_changeset", { ...o, changeset_id: changesetId });
|
|
6495
|
+
}
|
|
6496
|
+
listChangesets(o = {}) {
|
|
6497
|
+
return this.call("list_changesets", { ...o });
|
|
6498
|
+
}
|
|
6499
|
+
/** Commit; pass the reviewed digest to bind the commit to that approval. */
|
|
6500
|
+
commit(changesetId, expectedDigest, o = {}) {
|
|
6501
|
+
return this.call("commit", { ...o, changeset_id: changesetId, expected_digest: expectedDigest });
|
|
6502
|
+
}
|
|
6503
|
+
discard(changesetId, o = {}) {
|
|
6504
|
+
return this.call("discard", { ...o, changeset_id: changesetId });
|
|
6505
|
+
}
|
|
6506
|
+
/** Propose and commit in one call. */
|
|
6507
|
+
apply(o) {
|
|
6508
|
+
return this.call("apply", this.changeset(o));
|
|
6509
|
+
}
|
|
6510
|
+
forkBranch(name, o = {}) {
|
|
6511
|
+
return this.call("fork_branch", { ...o, name });
|
|
6512
|
+
}
|
|
6513
|
+
diffBranch(base = "main", o = {}) {
|
|
6514
|
+
return this.call("diff_branch", { ...o, base });
|
|
6515
|
+
}
|
|
6516
|
+
mergeBranch(target, o = {}) {
|
|
6517
|
+
const { dryRun, ...rest } = o;
|
|
6518
|
+
return this.call("merge_branch", { ...rest, target, dry_run: dryRun });
|
|
6519
|
+
}
|
|
6520
|
+
discardBranch(o = {}) {
|
|
6521
|
+
return this.call("discard_branch", { ...o });
|
|
6522
|
+
}
|
|
6523
|
+
};
|
|
6524
|
+
|
|
6019
6525
|
// src/http-client.ts
|
|
6020
6526
|
var RaisinHttpClient = class extends EventEmitter {
|
|
6021
6527
|
constructor(baseUrl, options = {}) {
|
|
@@ -6741,6 +7247,33 @@ var RaisinHttpClient = class extends EventEmitter {
|
|
|
6741
7247
|
* @param input - Input data passed to the function
|
|
6742
7248
|
* @returns Execution ID and job ID for tracking
|
|
6743
7249
|
*/
|
|
7250
|
+
/**
|
|
7251
|
+
* Durable agent runs of `repository`: create, read, control, stream, and
|
|
7252
|
+
* drive them directly (see {@link AgentRunsApi}).
|
|
7253
|
+
*/
|
|
7254
|
+
agentRuns(repository) {
|
|
7255
|
+
return new AgentRunsApi(repository, {
|
|
7256
|
+
request: async (method, path, body) => (await this.request({ method, path, body })).data,
|
|
7257
|
+
url: (path) => `${this.baseUrl}${path}`,
|
|
7258
|
+
headers: () => {
|
|
7259
|
+
const token = this.authManager.getAccessToken();
|
|
7260
|
+
const headers = {};
|
|
7261
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
7262
|
+
return headers;
|
|
7263
|
+
},
|
|
7264
|
+
fetch: this.fetchImpl
|
|
7265
|
+
});
|
|
7266
|
+
}
|
|
7267
|
+
/**
|
|
7268
|
+
* The node-development surface of `repository`: typed reads, atomic
|
|
7269
|
+
* changesets with review and idempotency, branch worktrees (see
|
|
7270
|
+
* {@link NodeDevApi}).
|
|
7271
|
+
*/
|
|
7272
|
+
nodeDev(repository) {
|
|
7273
|
+
return new NodeDevApi(repository, {
|
|
7274
|
+
request: async (method, path, body) => (await this.request({ method, path, body })).data
|
|
7275
|
+
});
|
|
7276
|
+
}
|
|
6744
7277
|
async invokeFunction(repository, functionName, input, options) {
|
|
6745
7278
|
const requestTimeoutMs = options?.requestTimeoutMs ?? this.options.requestTimeout;
|
|
6746
7279
|
let waitTimeoutMs = options?.waitTimeoutMs;
|
|
@@ -6944,6 +7477,14 @@ var HttpDatabase = class _HttpDatabase {
|
|
|
6944
7477
|
/**
|
|
6945
7478
|
* Get FunctionsApi for invoking server-side functions via HTTP
|
|
6946
7479
|
*/
|
|
7480
|
+
/** Durable agent runs of this repository. */
|
|
7481
|
+
agentRuns() {
|
|
7482
|
+
return this.client.agentRuns(this.repository);
|
|
7483
|
+
}
|
|
7484
|
+
/** The node-development surface of this repository. */
|
|
7485
|
+
nodeDev() {
|
|
7486
|
+
return this.client.nodeDev(this.repository);
|
|
7487
|
+
}
|
|
6947
7488
|
functions() {
|
|
6948
7489
|
return new HttpFunctionsApi(
|
|
6949
7490
|
this.repository,
|
|
@@ -9327,6 +9868,8 @@ function isFlowDefinitionContainer(node) {
|
|
|
9327
9868
|
return node.node_type === "raisin:FlowContainer";
|
|
9328
9869
|
}
|
|
9329
9870
|
export {
|
|
9871
|
+
AgentRunsApi,
|
|
9872
|
+
AgentRunsWsApi,
|
|
9330
9873
|
AllNodeEventTypes,
|
|
9331
9874
|
Archetypes,
|
|
9332
9875
|
AuthManager,
|
|
@@ -9367,6 +9910,7 @@ export {
|
|
|
9367
9910
|
McpClient,
|
|
9368
9911
|
MemoryTokenStorage,
|
|
9369
9912
|
NodeBuilder,
|
|
9913
|
+
NodeDevApi,
|
|
9370
9914
|
NodeEventType,
|
|
9371
9915
|
NodeFileSource,
|
|
9372
9916
|
NodeHelpers,
|
|
@@ -9434,12 +9978,14 @@ export {
|
|
|
9434
9978
|
isTerminalEvent,
|
|
9435
9979
|
isWebSocketClient,
|
|
9436
9980
|
logger,
|
|
9981
|
+
newControlId,
|
|
9437
9982
|
normalizeHomePath,
|
|
9438
9983
|
projectPlansFromMessages,
|
|
9439
9984
|
readTokensFromFragment,
|
|
9440
9985
|
rowsToObjects,
|
|
9441
9986
|
setLogLevel,
|
|
9442
9987
|
sleep,
|
|
9988
|
+
subjectOf,
|
|
9443
9989
|
useConversation,
|
|
9444
9990
|
useConversationList,
|
|
9445
9991
|
useFlow,
|