@rivus/runtime 0.16.6 → 0.18.0
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/LICENSE +674 -21
- package/README.md +21 -0
- package/dist/acp.d.ts +7 -92
- package/dist/acp.js +298 -249
- package/dist/chunks/agent-loop.d.ts +143 -95
- package/dist/chunks/agent-user-input.js +109 -0
- package/dist/chunks/rivus-runtime-tool.d.ts +104 -4
- package/dist/chunks/{tool-input-digest.js → tool-risk-policy.js} +7 -14
- package/dist/chunks/user-input-xml.js +224 -0
- package/dist/index.d.ts +107 -823
- package/dist/index.js +242 -705
- package/dist/pi.d.ts +62 -332
- package/dist/pi.js +547 -546
- package/package.json +12 -11
- package/dist/chunks/agent-loop.js +0 -164
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { a as createInvocationAuthority, i as InvalidInvocationAuthority, n as InvalidToolInput, o as resolveInvocationAuthority, r as createToolInputDigest, s as normalizeAgentInvocation, t as requiresToolApproval } from "./chunks/tool-risk-policy.js";
|
|
2
|
+
import { i as isAgentSteeringRequest, n as cloneAgentSteeringInput, o as projectUserInputText, r as cloneUserInput, t as ATTACHMENT_RECOVERY_COMMAND } from "./chunks/agent-user-input.js";
|
|
3
|
+
import { Deferred, Effect, Option, Queue, Semaphore, Stream } from "effect";
|
|
4
|
+
import { unwrapExit } from "@rivus/platform/effect";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
5
6
|
import { appendFile, chmod, lstat, mkdir, readFile, realpath, stat } from "node:fs/promises";
|
|
6
7
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
8
|
import { isPathWithin } from "@rivus/platform/filesystem";
|
|
@@ -13,7 +14,6 @@ import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
|
13
14
|
import { ROOT_CONTEXT, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
14
15
|
import { isRecord, readPersistenceFile } from "@rivus/platform/persistence";
|
|
15
16
|
import { createSerialExecutor } from "@rivus/platform/concurrency";
|
|
16
|
-
import { createSha256Digest } from "@rivus/platform/identity";
|
|
17
17
|
//#region src/core/application/agent-execution/contracts/agent-execution-errors.ts
|
|
18
18
|
var AgentHarnessBusy = class {
|
|
19
19
|
activeRun;
|
|
@@ -77,20 +77,6 @@ var AgentRunCancelled = class {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
//#endregion
|
|
80
|
-
//#region src/core/application/agent-execution/contracts/agent-domain-events.ts
|
|
81
|
-
function isAssistantTextDeltaEvent(event) {
|
|
82
|
-
return event.type === "assistant_text_delta";
|
|
83
|
-
}
|
|
84
|
-
function isAssistantThinkingDeltaEvent(event) {
|
|
85
|
-
return event.type === "assistant_thinking_delta";
|
|
86
|
-
}
|
|
87
|
-
function isAgentToolExecutionEvent(event) {
|
|
88
|
-
return event.type === "agent_tool_execution_started" || event.type === "agent_tool_execution_updated" || event.type === "agent_tool_execution_ended";
|
|
89
|
-
}
|
|
90
|
-
function isTerminalAgentDomainEvent(event) {
|
|
91
|
-
return event.type === "agent_run_completed" || event.type === "agent_run_failed" || event.type === "agent_run_cancelled";
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
80
|
//#region src/core/application/agent-execution/contracts/run-admission.ts
|
|
95
81
|
var ModelChangeBoundaryDeadlineError = class extends Error {
|
|
96
82
|
name = "ModelChangeBoundaryDeadlineError";
|
|
@@ -167,77 +153,13 @@ function assembleWorkspaceInstructions(input, digest) {
|
|
|
167
153
|
return Object.freeze(view);
|
|
168
154
|
}
|
|
169
155
|
//#endregion
|
|
170
|
-
//#region src/
|
|
171
|
-
var AgentContextBudgetExceeded = class extends Error {
|
|
172
|
-
name = "AgentContextBudgetExceeded";
|
|
173
|
-
};
|
|
174
|
-
function assembleAgentContext(input) {
|
|
175
|
-
const required = [
|
|
176
|
-
layer("host-safety", input.hostSafety),
|
|
177
|
-
layer("system-prompt", input.systemPrompt),
|
|
178
|
-
...input.managedInstructions ? [layer("managed-instructions", input.managedInstructions)] : [],
|
|
179
|
-
...input.toolSchemas.map((content) => layer("tool-schema", content)),
|
|
180
|
-
layer("current-input", input.currentInput)
|
|
181
|
-
];
|
|
182
|
-
let bytes = size(required);
|
|
183
|
-
if (bytes > input.maxBytes) throw new AgentContextBudgetExceeded("required context layers exceed byte budget");
|
|
184
|
-
const selected = [...required];
|
|
185
|
-
const optional = [
|
|
186
|
-
...(input.workspaceInstructions ?? []).map((content) => layer("workspace-instructions", content)),
|
|
187
|
-
...(input.skills ?? []).map((content) => layer("skill", content)),
|
|
188
|
-
...(input.memory ?? []).map((content) => layer("memory", content)),
|
|
189
|
-
...input.compaction ? [layer("compaction", input.compaction)] : [],
|
|
190
|
-
...(input.transcript ?? []).map((content) => layer("transcript", content))
|
|
191
|
-
];
|
|
192
|
-
const omitted = /* @__PURE__ */ new Set();
|
|
193
|
-
for (const candidate of optional) {
|
|
194
|
-
const candidateBytes = byteLength(candidate.content);
|
|
195
|
-
if (bytes + candidateBytes <= input.maxBytes) {
|
|
196
|
-
selected.push(candidate);
|
|
197
|
-
bytes += candidateBytes;
|
|
198
|
-
} else omitted.add(candidate.kind);
|
|
199
|
-
}
|
|
200
|
-
const order = [
|
|
201
|
-
"host-safety",
|
|
202
|
-
"system-prompt",
|
|
203
|
-
"managed-instructions",
|
|
204
|
-
"workspace-instructions",
|
|
205
|
-
"tool-schema",
|
|
206
|
-
"skill",
|
|
207
|
-
"memory",
|
|
208
|
-
"compaction",
|
|
209
|
-
"transcript",
|
|
210
|
-
"current-input"
|
|
211
|
-
];
|
|
212
|
-
selected.sort((a, b) => order.indexOf(a.kind) - order.indexOf(b.kind));
|
|
213
|
-
return Object.freeze({
|
|
214
|
-
bytes,
|
|
215
|
-
layers: Object.freeze(selected),
|
|
216
|
-
omittedKinds: Object.freeze(order.filter((kind) => omitted.has(kind)))
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
function layer(kind, content) {
|
|
220
|
-
return Object.freeze({
|
|
221
|
-
kind,
|
|
222
|
-
content
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
function size(layers) {
|
|
226
|
-
return layers.reduce((total, item) => total + byteLength(item.content), 0);
|
|
227
|
-
}
|
|
228
|
-
function byteLength(value) {
|
|
229
|
-
return new TextEncoder().encode(value).byteLength;
|
|
230
|
-
}
|
|
231
|
-
//#endregion
|
|
232
|
-
//#region src/adapters/agent/memory/agent-memory-access.ts
|
|
156
|
+
//#region src/adapters/agent/memory/rivus-memory-tool-contract.ts
|
|
233
157
|
const MEMORY_SCOPES = Object.freeze([
|
|
234
158
|
"conversation",
|
|
235
159
|
"agent-private",
|
|
236
160
|
"project",
|
|
237
161
|
"shared-user-profile"
|
|
238
162
|
]);
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/adapters/agent/memory/rivus-memory-tool-contract.ts
|
|
241
163
|
const RIVUS_MEMORY_TOOL_ID = "memory";
|
|
242
164
|
const RIVUS_MEMORY_TOOL_PLUGIN_ID = "rivus-core";
|
|
243
165
|
const RIVUS_MEMORY_TOOL_VERSION = "1.0.0";
|
|
@@ -334,7 +256,7 @@ function trimRequired(value) {
|
|
|
334
256
|
return typeof value === "string" ? value.trim() : "";
|
|
335
257
|
}
|
|
336
258
|
function trimOptional(value) {
|
|
337
|
-
if (value === void 0) return
|
|
259
|
+
if (value === void 0) return;
|
|
338
260
|
if (typeof value !== "string") return "";
|
|
339
261
|
return value.trim() || void 0;
|
|
340
262
|
}
|
|
@@ -575,7 +497,7 @@ function normalizeMemoryBinding(binding) {
|
|
|
575
497
|
tenantId
|
|
576
498
|
});
|
|
577
499
|
}
|
|
578
|
-
function createMemoryNamespace
|
|
500
|
+
function createMemoryNamespace(binding) {
|
|
579
501
|
const normalized = normalizeMemoryBinding(binding);
|
|
580
502
|
return {
|
|
581
503
|
conversation: [
|
|
@@ -653,7 +575,7 @@ function createMemoryService(options) {
|
|
|
653
575
|
return yield* options.repository.save(record.toSnapshot()).pipe(Effect.mapError(mapRepositoryConflict), Effect.map(snapshotRecord));
|
|
654
576
|
});
|
|
655
577
|
const handle = {
|
|
656
|
-
namespace: createMemoryNamespace
|
|
578
|
+
namespace: createMemoryNamespace(binding),
|
|
657
579
|
scope: binding.scope,
|
|
658
580
|
confirm: (input) => update(input.id, (current) => current.confirm({
|
|
659
581
|
expectedRevision: input.expectedRevision,
|
|
@@ -709,82 +631,105 @@ function toVisibleSnapshot(record) {
|
|
|
709
631
|
return record && isVisibleMemory(record) ? snapshotRecord(record) : void 0;
|
|
710
632
|
}
|
|
711
633
|
//#endregion
|
|
634
|
+
//#region src/core/application/tool-execution/contracts/rivus-tool.ts
|
|
635
|
+
var RivusToolInputRejected = class extends Error {
|
|
636
|
+
name = "RivusToolInputRejected";
|
|
637
|
+
};
|
|
638
|
+
//#endregion
|
|
712
639
|
//#region src/adapters/agent/memory/rivus-memory-tool.ts
|
|
713
640
|
function createRivusMemoryTool(memory) {
|
|
714
|
-
const handles =
|
|
641
|
+
const handles = "scope" in memory ? [memory] : [...memory];
|
|
715
642
|
if (handles.length === 0) throw new AgentMemoryError("rivus_memory requires at least one bound Memory scope");
|
|
716
643
|
const byScope = new Map(handles.map((handle) => [handle.scope, handle]));
|
|
717
|
-
const findStoredById =
|
|
644
|
+
const findStoredById = (id) => Effect.gen(function* () {
|
|
718
645
|
for (const handle of handles) {
|
|
719
|
-
const record =
|
|
646
|
+
const record = yield* handle.inspect(id);
|
|
720
647
|
if (record) return {
|
|
721
648
|
handle,
|
|
722
649
|
record
|
|
723
650
|
};
|
|
724
651
|
}
|
|
725
|
-
};
|
|
726
|
-
const execute =
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
"
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
"
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
"
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
for (const handle of handles) {
|
|
750
|
-
const record = await handle.read(id);
|
|
751
|
-
if (record) return record;
|
|
652
|
+
});
|
|
653
|
+
const execute = (value) => Effect.try({
|
|
654
|
+
catch: (error) => error,
|
|
655
|
+
try: () => {
|
|
656
|
+
const command = readCommand(value);
|
|
657
|
+
rejectUnknown(command, command.command === "search" ? [
|
|
658
|
+
"command",
|
|
659
|
+
"query",
|
|
660
|
+
"scope"
|
|
661
|
+
] : command.command === "propose" ? [
|
|
662
|
+
"command",
|
|
663
|
+
"input",
|
|
664
|
+
"scope"
|
|
665
|
+
] : command.command === "forget_request" ? [
|
|
666
|
+
"command",
|
|
667
|
+
"id",
|
|
668
|
+
"reason"
|
|
669
|
+
] : ["command", "id"]);
|
|
670
|
+
switch (command.command) {
|
|
671
|
+
case "search": {
|
|
672
|
+
const query = readSearchQuery(command.query);
|
|
673
|
+
const scope = readOptionalScope(command.scope);
|
|
674
|
+
const selected = scope ? [requireScope(byScope, scope)] : handles;
|
|
675
|
+
return Effect.all(selected.map((handle) => handle.search(query)), { concurrency: "unbounded" }).pipe(Effect.map((records) => records.flat()));
|
|
752
676
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
677
|
+
case "read": {
|
|
678
|
+
const id = readId(command.id);
|
|
679
|
+
return Effect.gen(function* () {
|
|
680
|
+
for (const handle of handles) {
|
|
681
|
+
const record = yield* handle.read(id);
|
|
682
|
+
if (record) return record;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
case "propose": {
|
|
687
|
+
const input = readProposeInput(command.input);
|
|
688
|
+
const scope = readOptionalScope(command.scope);
|
|
689
|
+
if (scope === "shared-user-profile") throw new AgentMemoryError("Shared User Profile changes require trusted confirmation");
|
|
690
|
+
const handle = scope ? requireScope(byScope, scope) : byScope.get("agent-private") ?? (handles.length === 1 ? handles[0] : void 0);
|
|
691
|
+
if (!handle) throw new AgentMemoryError("memory scope is required when multiple scopes are granted");
|
|
692
|
+
if (handle.scope === "shared-user-profile") throw new AgentMemoryError("Shared User Profile changes require trusted confirmation");
|
|
693
|
+
return handle.propose({ content: input.content });
|
|
694
|
+
}
|
|
695
|
+
case "forget_request": {
|
|
696
|
+
const id = readId(command.id);
|
|
697
|
+
const reason = command.reason === void 0 ? void 0 : readReason(command.reason);
|
|
698
|
+
return Effect.gen(function* () {
|
|
699
|
+
const stored = yield* findStoredById(id);
|
|
700
|
+
if (!stored) return yield* Effect.fail(new AgentMemoryError(`memory not found: ${id}`));
|
|
701
|
+
if (stored.handle.scope === "shared-user-profile" || stored.handle.scope === "project" || stored.record.state !== "proposed") return yield* Effect.fail(new AgentMemoryError("Only proposed private Memory can be forgotten by the model; confirmed or project-shared Memory requires trusted control"));
|
|
702
|
+
const record = yield* stored.handle.forgetRequest({
|
|
703
|
+
expectedRevision: stored.record.revision,
|
|
704
|
+
id,
|
|
705
|
+
...reason === void 0 ? {} : { reason }
|
|
706
|
+
});
|
|
707
|
+
return yield* Effect.try({
|
|
708
|
+
catch: (error) => error,
|
|
709
|
+
try: () => toTombstoneReceipt(record)
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
default: throw new AgentMemoryError(`unknown rivus_memory command: ${String(command.command)}`);
|
|
774
714
|
}
|
|
775
|
-
default: throw new AgentMemoryError(`unknown rivus_memory command: ${String(command.command)}`);
|
|
776
715
|
}
|
|
777
|
-
};
|
|
716
|
+
}).pipe(Effect.flatten);
|
|
778
717
|
return {
|
|
779
718
|
execute,
|
|
780
|
-
replayCompleted:
|
|
781
|
-
const input =
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (
|
|
719
|
+
replayCompleted: (command, completedResult) => Effect.gen(function* () {
|
|
720
|
+
const input = yield* Effect.try({
|
|
721
|
+
catch: (error) => error,
|
|
722
|
+
try: () => readCommand(command)
|
|
723
|
+
});
|
|
724
|
+
if (input.command === "search" || input.command === "read") return yield* execute(input);
|
|
725
|
+
const id = yield* Effect.try({
|
|
726
|
+
catch: (error) => error,
|
|
727
|
+
try: () => readCompletedMemoryId(completedResult)
|
|
728
|
+
});
|
|
729
|
+
const stored = yield* findStoredById(id);
|
|
730
|
+
if (!stored) return yield* Effect.fail(new AgentMemoryError(`completed Memory operation references missing Memory: ${id}`));
|
|
786
731
|
return stored.record.state === "tombstoned" ? toTombstoneReceipt(stored.record) : stored.record;
|
|
787
|
-
}
|
|
732
|
+
})
|
|
788
733
|
};
|
|
789
734
|
}
|
|
790
735
|
function createRivusMemoryToolDescriptor(options) {
|
|
@@ -812,7 +757,7 @@ function readId(value) {
|
|
|
812
757
|
return value;
|
|
813
758
|
}
|
|
814
759
|
function readOptionalScope(value) {
|
|
815
|
-
if (value === void 0) return
|
|
760
|
+
if (value === void 0) return;
|
|
816
761
|
if (typeof value !== "string" || !MEMORY_SCOPES.includes(value)) throw new AgentMemoryError("memory scope must be conversation, agent-private, project, or shared-user-profile");
|
|
817
762
|
return value;
|
|
818
763
|
}
|
|
@@ -868,35 +813,39 @@ function toTombstoneReceipt(record) {
|
|
|
868
813
|
state: record.state
|
|
869
814
|
};
|
|
870
815
|
}
|
|
871
|
-
|
|
872
|
-
try
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
throw error;
|
|
877
|
-
}
|
|
816
|
+
function asToolInputRejection(operation) {
|
|
817
|
+
return Effect.runPromiseExit(Effect.try({
|
|
818
|
+
catch: (error) => error,
|
|
819
|
+
try: operation
|
|
820
|
+
}).pipe(Effect.flatten, Effect.mapError((error) => error instanceof AgentMemoryError ? new RivusToolInputRejected(error.message) : error))).then(unwrapExit);
|
|
878
821
|
}
|
|
879
822
|
//#endregion
|
|
880
823
|
//#region src/adapters/agent/memory/project-memory-prompt-preparer.ts
|
|
881
|
-
const DEFAULT_MAX_BYTES =
|
|
824
|
+
const DEFAULT_MAX_BYTES = 8192;
|
|
882
825
|
const DEFAULT_MAX_RECORDS = 20;
|
|
883
826
|
function createProjectMemoryPromptPreparer(options) {
|
|
884
827
|
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
885
828
|
const maxRecords = options.maxRecords ?? DEFAULT_MAX_RECORDS;
|
|
886
829
|
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new Error("Project Memory maxBytes must be positive");
|
|
887
830
|
if (!Number.isSafeInteger(maxRecords) || maxRecords <= 0) throw new Error("Project Memory maxRecords must be positive");
|
|
888
|
-
return
|
|
889
|
-
const invocationIdentity = (
|
|
831
|
+
return (input) => Effect.gen(function* () {
|
|
832
|
+
const invocationIdentity = (yield* Effect.try({
|
|
833
|
+
catch: (error) => error,
|
|
834
|
+
try: () => input.invocation ? normalizeAgentInvocation(input.invocation) : void 0
|
|
835
|
+
}))?.memory;
|
|
890
836
|
if (invocationIdentity?.projectId && invocationIdentity.projectId !== options.projectId) return input.text;
|
|
891
837
|
const identity = invocationIdentity ?? options.identity;
|
|
892
838
|
if (!identity) return input.text;
|
|
893
|
-
const records = (
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
839
|
+
const records = (yield* (yield* Effect.try({
|
|
840
|
+
catch: (error) => error,
|
|
841
|
+
try: () => options.memory.bind({
|
|
842
|
+
agentId: options.agentId,
|
|
843
|
+
projectId: options.projectId,
|
|
844
|
+
scope: "project",
|
|
845
|
+
subjectId: identity.subjectId,
|
|
846
|
+
tenantId: identity.tenantId
|
|
847
|
+
})
|
|
848
|
+
})).search({ query: "" })).filter((record) => record.state === "confirmed").sort((left, right) => left.id.localeCompare(right.id)).slice(0, maxRecords);
|
|
900
849
|
const selected = [];
|
|
901
850
|
let usedBytes = 0;
|
|
902
851
|
for (const record of records) {
|
|
@@ -914,7 +863,7 @@ function createProjectMemoryPromptPreparer(options) {
|
|
|
914
863
|
"</rivus_project_memory>"
|
|
915
864
|
].join("\n");
|
|
916
865
|
return input.text.startsWith("/skill:") ? `${input.text} \n\n${context}` : `${input.text}\n\n${context}`;
|
|
917
|
-
};
|
|
866
|
+
});
|
|
918
867
|
}
|
|
919
868
|
//#endregion
|
|
920
869
|
//#region src/adapters/agent/workspace/node-workspace-root-registry.ts
|
|
@@ -986,7 +935,7 @@ async function readSource(rootPath, sourcePath, maxBytes) {
|
|
|
986
935
|
try {
|
|
987
936
|
metadata = await lstat(sourcePath);
|
|
988
937
|
} catch (error) {
|
|
989
|
-
if (isMissing(error)) return
|
|
938
|
+
if (isMissing(error)) return;
|
|
990
939
|
throw error;
|
|
991
940
|
}
|
|
992
941
|
const relativePath = toRelative(rootPath, sourcePath);
|
|
@@ -1036,14 +985,6 @@ function isMissing(error) {
|
|
|
1036
985
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
1037
986
|
}
|
|
1038
987
|
//#endregion
|
|
1039
|
-
//#region src/adapters/agent/memory/persisted-memory-record.ts
|
|
1040
|
-
function createPersistedMemoryRecord(input) {
|
|
1041
|
-
return createMemoryRecord(input);
|
|
1042
|
-
}
|
|
1043
|
-
function restorePersistedMemoryRecord(snapshot) {
|
|
1044
|
-
return restoreMemoryRecord(snapshot);
|
|
1045
|
-
}
|
|
1046
|
-
//#endregion
|
|
1047
988
|
//#region src/adapters/observability/content/telemetry-content-redactor.ts
|
|
1048
989
|
const REDACTED = "[REDACTED]";
|
|
1049
990
|
const TRUNCATED = "[TRUNCATED]";
|
|
@@ -1180,9 +1121,6 @@ const SPAN_NAMES = {
|
|
|
1180
1121
|
turn: "Agent 处理"
|
|
1181
1122
|
};
|
|
1182
1123
|
const MAX_TOOL_DISPLAY_NAME_LENGTH = 64;
|
|
1183
|
-
function createOpenTelemetryAgentEventSink(options) {
|
|
1184
|
-
return createOpenTelemetryAgentTelemetry(options).sink;
|
|
1185
|
-
}
|
|
1186
1124
|
function createOpenTelemetryAgentTelemetry(options) {
|
|
1187
1125
|
const runs = /* @__PURE__ */ new Map();
|
|
1188
1126
|
const pendingModelContent = /* @__PURE__ */ new Map();
|
|
@@ -1461,7 +1399,7 @@ function notifyProjectionError(callback, error, event) {
|
|
|
1461
1399
|
}
|
|
1462
1400
|
}
|
|
1463
1401
|
function redactEventContent(redactContent, callback, value, event) {
|
|
1464
|
-
if (!redactContent) return
|
|
1402
|
+
if (!redactContent) return;
|
|
1465
1403
|
try {
|
|
1466
1404
|
const redacted = redactContent(value);
|
|
1467
1405
|
if (typeof redacted !== "string") throw new TypeError("content redactor must return a string");
|
|
@@ -1488,7 +1426,7 @@ function resolveLangfuseTelemetryConfig(env) {
|
|
|
1488
1426
|
publicKey,
|
|
1489
1427
|
secretKey
|
|
1490
1428
|
].filter(Boolean).length;
|
|
1491
|
-
if (configured === 0) return
|
|
1429
|
+
if (configured === 0) return;
|
|
1492
1430
|
if (configured !== 3) throw new LangfuseTelemetryConfigError("LANGFUSE_BASE_URL, LANGFUSE_PUBLIC_KEY, and LANGFUSE_SECRET_KEY must be configured together");
|
|
1493
1431
|
let endpoint;
|
|
1494
1432
|
try {
|
|
@@ -1507,13 +1445,14 @@ function resolveLangfuseTelemetryConfig(env) {
|
|
|
1507
1445
|
};
|
|
1508
1446
|
}
|
|
1509
1447
|
function createLangfuseAgentTelemetry(config) {
|
|
1510
|
-
const
|
|
1448
|
+
const exporter = new OTLPTraceExporter({
|
|
1511
1449
|
headers: {
|
|
1512
1450
|
Authorization: `Basic ${Buffer$1.from(`${config.publicKey}:${config.secretKey}`).toString("base64")}`,
|
|
1513
1451
|
"x-langfuse-ingestion-version": "4"
|
|
1514
1452
|
},
|
|
1515
1453
|
url: config.endpoint
|
|
1516
|
-
})
|
|
1454
|
+
});
|
|
1455
|
+
const processor = new BatchSpanProcessor(exporter, {
|
|
1517
1456
|
scheduledDelayMillis: 1e3,
|
|
1518
1457
|
exportTimeoutMillis: 1e4,
|
|
1519
1458
|
maxExportBatchSize: 512,
|
|
@@ -1579,6 +1518,7 @@ function projectAgentRun(state, event) {
|
|
|
1579
1518
|
finalText: "",
|
|
1580
1519
|
phase: "accepted",
|
|
1581
1520
|
prompt: event.prompt,
|
|
1521
|
+
...event.userInput ? { userInput: event.userInput } : {},
|
|
1582
1522
|
runId: event.runId,
|
|
1583
1523
|
sessionKey: event.sessionKey,
|
|
1584
1524
|
thinkingText: "",
|
|
@@ -1761,6 +1701,7 @@ function updateRunSummary(current, event, state) {
|
|
|
1761
1701
|
case "agent_run_accepted":
|
|
1762
1702
|
next.acceptedAt = event.occurredAt;
|
|
1763
1703
|
next.prompt = event.prompt;
|
|
1704
|
+
if (event.userInput) next.userInput = event.userInput;
|
|
1764
1705
|
next.sessionKey = event.sessionKey;
|
|
1765
1706
|
break;
|
|
1766
1707
|
case "agent_turn_started":
|
|
@@ -1778,7 +1719,6 @@ function updateRunSummary(current, event, state) {
|
|
|
1778
1719
|
if (event.reason === void 0) delete next.cancellationReason;
|
|
1779
1720
|
else next.cancellationReason = event.reason;
|
|
1780
1721
|
next.cancelledAt = event.occurredAt;
|
|
1781
|
-
break;
|
|
1782
1722
|
}
|
|
1783
1723
|
return next;
|
|
1784
1724
|
}
|
|
@@ -1796,6 +1736,7 @@ function toRunSummary(summary) {
|
|
|
1796
1736
|
finalText: summary.finalText,
|
|
1797
1737
|
phase: summary.phase,
|
|
1798
1738
|
...summary.prompt ? { prompt: summary.prompt } : {},
|
|
1739
|
+
...summary.userInput ? { userInput: summary.userInput } : {},
|
|
1799
1740
|
runId: summary.runId,
|
|
1800
1741
|
...summary.sessionKey ? { sessionKey: summary.sessionKey } : {},
|
|
1801
1742
|
...summary.startedAt ? { startedAt: summary.startedAt } : {},
|
|
@@ -1859,14 +1800,16 @@ function createAgentTranscriptTurn(summary) {
|
|
|
1859
1800
|
thinkingText: summary.thinkingText,
|
|
1860
1801
|
toolExecutionCount: summary.toolExecutionCount,
|
|
1861
1802
|
updatedAt: summary.updatedAt,
|
|
1862
|
-
userText: summary.prompt ?? ""
|
|
1803
|
+
userText: summary.prompt ?? "",
|
|
1804
|
+
...summary.userInput ? { userInput: summary.userInput } : {}
|
|
1863
1805
|
};
|
|
1864
1806
|
}
|
|
1865
1807
|
function createAgentTranscriptMessages(transcript) {
|
|
1866
1808
|
return transcript.turns.flatMap((turn) => {
|
|
1867
1809
|
const messages = [{
|
|
1868
1810
|
content: turn.userText,
|
|
1869
|
-
role: "user"
|
|
1811
|
+
role: "user",
|
|
1812
|
+
...turn.userInput ? { userInput: turn.userInput } : {}
|
|
1870
1813
|
}];
|
|
1871
1814
|
if (turn.assistantText) messages.push({
|
|
1872
1815
|
content: turn.assistantText,
|
|
@@ -1878,7 +1821,8 @@ function createAgentTranscriptMessages(transcript) {
|
|
|
1878
1821
|
function createAgentConversationMessages(options) {
|
|
1879
1822
|
return [...options.transcript ? createAgentTranscriptMessages(options.transcript) : [], {
|
|
1880
1823
|
content: options.text,
|
|
1881
|
-
role: "user"
|
|
1824
|
+
role: "user",
|
|
1825
|
+
...options.userInput ? { userInput: options.userInput } : {}
|
|
1882
1826
|
}];
|
|
1883
1827
|
}
|
|
1884
1828
|
//#endregion
|
|
@@ -2079,10 +2023,10 @@ function createAgentRunStreams(runPrompt) {
|
|
|
2079
2023
|
};
|
|
2080
2024
|
}
|
|
2081
2025
|
function createProjectedRunStream(runPrompt, command, project) {
|
|
2082
|
-
return Stream.
|
|
2026
|
+
return Stream.callback((queue) => runPrompt(command, (event, state, previousState) => Option.match(project(event, state, previousState), {
|
|
2083
2027
|
onNone: () => Effect.void,
|
|
2084
|
-
onSome: (value) =>
|
|
2085
|
-
}), "stream interrupted").pipe(Effect.flatMap(() => Effect.
|
|
2028
|
+
onSome: (value) => Queue.offer(queue, value)
|
|
2029
|
+
}), "stream interrupted").pipe(Effect.flatMap(() => Queue.end(queue)), Effect.catchCause((cause) => Queue.failCause(queue, cause)), Effect.forkScoped, Effect.asVoid), { bufferSize: 16 });
|
|
2086
2030
|
}
|
|
2087
2031
|
//#endregion
|
|
2088
2032
|
//#region src/core/application/agent-execution/execution/agent-loop-event-mapper.ts
|
|
@@ -2196,16 +2140,36 @@ function toDomainEvent(runId, sessionKey, event, occurredAt) {
|
|
|
2196
2140
|
function createSteeringChannel() {
|
|
2197
2141
|
return Queue.unbounded().pipe(Effect.map((queue) => {
|
|
2198
2142
|
let closed = false;
|
|
2143
|
+
const toText = (input) => typeof input === "string" ? input : projectUserInputText(isAgentSteeringRequest(input) ? input.userInput : input);
|
|
2199
2144
|
return {
|
|
2200
|
-
next: () => Queue.take(queue),
|
|
2145
|
+
next: () => Queue.take(queue).pipe(Effect.map(toText)),
|
|
2146
|
+
nextInput: () => Queue.take(queue),
|
|
2201
2147
|
close: () => Effect.gen(function* () {
|
|
2202
2148
|
closed = true;
|
|
2203
|
-
return Array.from(yield* Queue.
|
|
2149
|
+
return Array.from(yield* Queue.clear(queue)).map(toText);
|
|
2204
2150
|
}),
|
|
2205
|
-
|
|
2151
|
+
closeInput: () => Effect.gen(function* () {
|
|
2152
|
+
closed = true;
|
|
2153
|
+
return Array.from(yield* Queue.clear(queue));
|
|
2154
|
+
}),
|
|
2155
|
+
push: (input) => Effect.sync(() => !closed && Queue.offerUnsafe(queue, input))
|
|
2206
2156
|
};
|
|
2207
2157
|
}));
|
|
2208
2158
|
}
|
|
2159
|
+
function bindAttachmentAccess(access, cancellation) {
|
|
2160
|
+
if (!access) return;
|
|
2161
|
+
const bound = access.bind?.(cancellation.attachmentBinding) ?? access;
|
|
2162
|
+
cancellation.attachmentAccesses.add(bound);
|
|
2163
|
+
return bound;
|
|
2164
|
+
}
|
|
2165
|
+
function bindAttachmentAccessInput(input, cancellation) {
|
|
2166
|
+
if (typeof input === "string" || !isAgentSteeringRequest(input) || !input.attachmentAccess) return input;
|
|
2167
|
+
const attachmentAccess = bindAttachmentAccess(input.attachmentAccess, cancellation);
|
|
2168
|
+
return attachmentAccess ? {
|
|
2169
|
+
...input,
|
|
2170
|
+
attachmentAccess
|
|
2171
|
+
} : input;
|
|
2172
|
+
}
|
|
2209
2173
|
function createAgentHarness(options) {
|
|
2210
2174
|
if (options.runTimeoutMs !== void 0 && (!Number.isSafeInteger(options.runTimeoutMs) || options.runTimeoutMs < 1)) throw new Error("Agent run timeout must be a positive integer");
|
|
2211
2175
|
let activeRun;
|
|
@@ -2240,6 +2204,10 @@ function createAgentHarness(options) {
|
|
|
2240
2204
|
};
|
|
2241
2205
|
};
|
|
2242
2206
|
const runPrompt = (command, emit, interruptionReason = "run interrupted") => Effect.gen(function* () {
|
|
2207
|
+
if (command.userInput) command = {
|
|
2208
|
+
...command,
|
|
2209
|
+
userInput: cloneUserInput(command.userInput)
|
|
2210
|
+
};
|
|
2243
2211
|
if (activeRun !== void 0) return yield* Effect.fail(new AgentHarnessBusy(activeRun, activeRunState));
|
|
2244
2212
|
const runId = yield* options.runIds.next;
|
|
2245
2213
|
activeRun = {
|
|
@@ -2248,8 +2216,16 @@ function createAgentHarness(options) {
|
|
|
2248
2216
|
};
|
|
2249
2217
|
const previousSessionState = queryStore.getSessionState(command.sessionKey);
|
|
2250
2218
|
const previousSessionTranscript = queryStore.getSessionTranscript(command.sessionKey);
|
|
2219
|
+
const abortController = new AbortController();
|
|
2251
2220
|
const cancellation = {
|
|
2252
|
-
abortController
|
|
2221
|
+
abortController,
|
|
2222
|
+
attachmentAccesses: /* @__PURE__ */ new Set(),
|
|
2223
|
+
attachmentBinding: {
|
|
2224
|
+
...options.generationId ? { generationId: options.generationId } : {},
|
|
2225
|
+
runId,
|
|
2226
|
+
sessionKey: command.sessionKey,
|
|
2227
|
+
signal: abortController.signal
|
|
2228
|
+
},
|
|
2253
2229
|
deferred: yield* Deferred.make(),
|
|
2254
2230
|
steering: yield* createSteeringChannel()
|
|
2255
2231
|
};
|
|
@@ -2257,12 +2233,13 @@ function createAgentHarness(options) {
|
|
|
2257
2233
|
const events = [];
|
|
2258
2234
|
const updates = [];
|
|
2259
2235
|
let settled = false;
|
|
2236
|
+
let boundAttachmentAccess;
|
|
2260
2237
|
let state = initialAgentRunState;
|
|
2261
2238
|
const project = (event) => Effect.gen(function* () {
|
|
2262
2239
|
for (const sink of options.eventSinks ?? []) yield* Effect.try({
|
|
2263
2240
|
try: () => sink.append(event),
|
|
2264
2241
|
catch: (error) => error
|
|
2265
|
-
}).pipe(Effect.flatMap((appendEffect) => appendEffect), Effect.
|
|
2242
|
+
}).pipe(Effect.flatMap((appendEffect) => appendEffect), Effect.catch((error) => Effect.fail(new AgentEventSinkFailed(event.runId, event.type, error))));
|
|
2266
2243
|
events.push(event);
|
|
2267
2244
|
const update = queryStore.project(event);
|
|
2268
2245
|
state = update.state;
|
|
@@ -2272,7 +2249,7 @@ function createAgentHarness(options) {
|
|
|
2272
2249
|
});
|
|
2273
2250
|
const record = (event) => Effect.gen(function* () {
|
|
2274
2251
|
const update = yield* project(event);
|
|
2275
|
-
yield* emit(update.event, update.state, update.previousState).pipe(Effect.
|
|
2252
|
+
yield* emit(update.event, update.state, update.previousState).pipe(Effect.catch((error) => Effect.fail(new AgentEventHandlerFailed(event.runId, event.type, error, state))));
|
|
2276
2253
|
});
|
|
2277
2254
|
const recordWithoutEmit = (event) => project(event).pipe(Effect.asVoid);
|
|
2278
2255
|
const recordInterruptedRun = Effect.gen(function* () {
|
|
@@ -2288,16 +2265,18 @@ function createAgentHarness(options) {
|
|
|
2288
2265
|
occurredAt: interruptedAt,
|
|
2289
2266
|
runId,
|
|
2290
2267
|
type: "agent_run_cancelled"
|
|
2291
|
-
}).pipe(Effect.
|
|
2268
|
+
}).pipe(Effect.catch(() => Effect.void));
|
|
2292
2269
|
settled = true;
|
|
2293
2270
|
});
|
|
2294
2271
|
return yield* Effect.gen(function* () {
|
|
2272
|
+
boundAttachmentAccess = bindAttachmentAccess(command.attachmentAccess, cancellation);
|
|
2295
2273
|
const acceptedAt = yield* options.clock.now;
|
|
2296
2274
|
yield* record({
|
|
2297
2275
|
occurredAt: acceptedAt,
|
|
2298
2276
|
prompt: command.text,
|
|
2299
2277
|
runId,
|
|
2300
2278
|
sessionKey: command.sessionKey,
|
|
2279
|
+
...command.userInput ? { userInput: command.userInput } : {},
|
|
2301
2280
|
type: "agent_run_accepted"
|
|
2302
2281
|
});
|
|
2303
2282
|
const startedAt = yield* options.clock.now;
|
|
@@ -2309,25 +2288,28 @@ function createAgentHarness(options) {
|
|
|
2309
2288
|
});
|
|
2310
2289
|
const loopInput = {
|
|
2311
2290
|
abortSignal: cancellation.abortController.signal,
|
|
2291
|
+
...boundAttachmentAccess ? { attachmentAccess: boundAttachmentAccess } : {},
|
|
2312
2292
|
...command.invocation ? { invocation: command.invocation } : {},
|
|
2313
2293
|
messages: createAgentConversationMessages({
|
|
2314
2294
|
text: command.text,
|
|
2315
|
-
transcript: previousSessionTranscript
|
|
2295
|
+
transcript: previousSessionTranscript,
|
|
2296
|
+
...command.userInput ? { userInput: command.userInput } : {}
|
|
2316
2297
|
}),
|
|
2317
2298
|
...previousSessionState ? { previousSessionState } : {},
|
|
2318
2299
|
...previousSessionTranscript.turnCount > 0 ? { previousSessionTranscript } : {},
|
|
2319
2300
|
runId,
|
|
2320
2301
|
sessionKey: command.sessionKey,
|
|
2321
2302
|
...options.loop.supportsSteering ? { steering: cancellation.steering } : {},
|
|
2322
|
-
text: command.text
|
|
2303
|
+
text: command.text,
|
|
2304
|
+
...command.userInput ? { userInput: command.userInput } : {}
|
|
2323
2305
|
};
|
|
2324
2306
|
const loop = Effect.try({
|
|
2325
2307
|
try: () => options.loop.run(loopInput),
|
|
2326
2308
|
catch: (error) => error
|
|
2327
|
-
}).pipe(Effect.flatMap((loopStream) => Stream.runForEach(loopStream.pipe(Stream.
|
|
2309
|
+
}).pipe(Effect.flatMap((loopStream) => Stream.runForEach(loopStream.pipe(Stream.interruptWhen(Deferred.await(cancellation.deferred))), (event) => Effect.gen(function* () {
|
|
2328
2310
|
const occurredAt = yield* options.clock.now;
|
|
2329
2311
|
yield* record(toDomainEvent(runId, command.sessionKey, event, occurredAt));
|
|
2330
|
-
}))), Effect.
|
|
2312
|
+
}))), Effect.catch((error) => {
|
|
2331
2313
|
if (error instanceof AgentEventSinkFailed || error instanceof AgentEventHandlerFailed) return Effect.fail(error);
|
|
2332
2314
|
return Effect.gen(function* () {
|
|
2333
2315
|
const occurredAt = yield* options.clock.now;
|
|
@@ -2342,16 +2324,16 @@ function createAgentHarness(options) {
|
|
|
2342
2324
|
return yield* Effect.fail(new AgentLoopFailed(runId, errorMessage, error, state));
|
|
2343
2325
|
});
|
|
2344
2326
|
}));
|
|
2345
|
-
yield* options.runTimeoutMs === void 0 ? loop : Effect.raceFirst(loop, Effect.sleep(options.runTimeoutMs).pipe(Effect.flatMap(() => {
|
|
2327
|
+
yield* options.runTimeoutMs === void 0 ? loop : Effect.raceFirst(loop, Effect.sleep(options.runTimeoutMs).pipe(Effect.flatMap(() => Effect.gen(function* () {
|
|
2346
2328
|
const request = {
|
|
2347
2329
|
reason: `run timed out after ${options.runTimeoutMs}ms`,
|
|
2348
2330
|
runId,
|
|
2349
2331
|
sessionKey: command.sessionKey
|
|
2350
2332
|
};
|
|
2351
2333
|
cancellation.requested = request;
|
|
2334
|
+
yield* Deferred.succeed(cancellation.deferred, request);
|
|
2352
2335
|
cancellation.abortController.abort(request);
|
|
2353
|
-
|
|
2354
|
-
}), Effect.asVoid));
|
|
2336
|
+
}).pipe(Effect.uninterruptible)), Effect.asVoid));
|
|
2355
2337
|
if (cancellation.requested) {
|
|
2356
2338
|
const cancelledAt = yield* options.clock.now;
|
|
2357
2339
|
yield* record({
|
|
@@ -2394,14 +2376,21 @@ function createAgentHarness(options) {
|
|
|
2394
2376
|
updates
|
|
2395
2377
|
};
|
|
2396
2378
|
}).pipe(Effect.onInterrupt(() => recordInterruptedRun), Effect.ensuring(Effect.sync(() => {
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2379
|
+
try {
|
|
2380
|
+
if (!settled && !cancellation.abortController.signal.aborted) cancellation.abortController.abort({
|
|
2381
|
+
reason: interruptionReason,
|
|
2382
|
+
runId,
|
|
2383
|
+
sessionKey: command.sessionKey
|
|
2384
|
+
});
|
|
2385
|
+
} finally {
|
|
2386
|
+
for (const access of cancellation.attachmentAccesses) try {
|
|
2387
|
+
access.revoke?.();
|
|
2388
|
+
} catch {}
|
|
2389
|
+
cancellation.attachmentAccesses.clear();
|
|
2390
|
+
activeRun = void 0;
|
|
2391
|
+
activeCancellation = void 0;
|
|
2392
|
+
activeRunState = void 0;
|
|
2393
|
+
}
|
|
2405
2394
|
})));
|
|
2406
2395
|
});
|
|
2407
2396
|
const requestCancellation = (runId, reason) => Effect.gen(function* () {
|
|
@@ -2411,17 +2400,18 @@ function createAgentHarness(options) {
|
|
|
2411
2400
|
runId: activeRun.runId,
|
|
2412
2401
|
sessionKey: activeRun.sessionKey
|
|
2413
2402
|
};
|
|
2414
|
-
const
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
return completed;
|
|
2403
|
+
const cancellation = activeCancellation;
|
|
2404
|
+
cancellation.requested = request;
|
|
2405
|
+
const requested = yield* Deferred.succeed(cancellation.deferred, request);
|
|
2406
|
+
cancellation.abortController.abort(request);
|
|
2407
|
+
return requested;
|
|
2420
2408
|
});
|
|
2421
|
-
const requestSteering = (runId, text) =>
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2409
|
+
const requestSteering = (runId, text) => requestSteeringInput(runId, text);
|
|
2410
|
+
const requestSteeringInput = (runId, input) => Effect.gen(function* () {
|
|
2411
|
+
const normalized = typeof input === "string" ? input.trim() : input;
|
|
2412
|
+
if (typeof normalized === "string" && !normalized || typeof normalized !== "string" && options.loop.supportsStructuredSteering !== true || !options.loop.supportsSteering || !activeRun || activeRun.runId !== runId || !activeCancellation || activeCancellation.requested) return false;
|
|
2413
|
+
const bound = bindAttachmentAccessInput(normalized, activeCancellation);
|
|
2414
|
+
return yield* activeCancellation.steering.push(cloneAgentSteeringInput(bound));
|
|
2425
2415
|
});
|
|
2426
2416
|
const requestSessionCancellation = (sessionKey, runId, reason) => {
|
|
2427
2417
|
if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
|
|
@@ -2431,6 +2421,10 @@ function createAgentHarness(options) {
|
|
|
2431
2421
|
if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
|
|
2432
2422
|
return requestSteering(runId, text);
|
|
2433
2423
|
};
|
|
2424
|
+
const requestSessionSteeringInput = (sessionKey, runId, input) => {
|
|
2425
|
+
if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
|
|
2426
|
+
return requestSteeringInput(runId, input);
|
|
2427
|
+
};
|
|
2434
2428
|
const requestSessionActiveCancellation = (sessionKey, reason) => {
|
|
2435
2429
|
if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
|
|
2436
2430
|
return requestCancellation(activeRun.runId, reason);
|
|
@@ -2446,10 +2440,12 @@ function createAgentHarness(options) {
|
|
|
2446
2440
|
}),
|
|
2447
2441
|
cancelRun: requestCancellation,
|
|
2448
2442
|
steerRun: requestSteering,
|
|
2443
|
+
steerRunInput: requestSteeringInput,
|
|
2449
2444
|
forSession: (sessionKey) => ({
|
|
2450
2445
|
cancelActiveRun: (reason) => requestSessionActiveCancellation(sessionKey, reason),
|
|
2451
2446
|
cancelRun: (runId, reason) => requestSessionCancellation(sessionKey, runId, reason),
|
|
2452
2447
|
steerRun: (runId, text) => requestSessionSteering(sessionKey, runId, text),
|
|
2448
|
+
steerRunInput: (runId, input) => requestSessionSteeringInput(sessionKey, runId, input),
|
|
2453
2449
|
getActiveRun: () => getSessionActiveRun(sessionKey),
|
|
2454
2450
|
getActiveRunState: () => getSessionActiveRunState(sessionKey),
|
|
2455
2451
|
getAvailability: () => getSessionAvailability(sessionKey),
|
|
@@ -2583,7 +2579,7 @@ function createRunAdmission(options) {
|
|
|
2583
2579
|
const remaining = input.deadlineAt === void 0 ? void 0 : remainingUntil(options.clock, input.deadlineAt);
|
|
2584
2580
|
if (remaining !== void 0 && remaining <= 0) return Effect.fail(new ModelChangeBoundaryDeadlineError("Run admission deadline has passed"));
|
|
2585
2581
|
if (open) return Effect.sync(createLease);
|
|
2586
|
-
const waiting = Effect.
|
|
2582
|
+
const waiting = Effect.callback((resume) => {
|
|
2587
2583
|
let settled = false;
|
|
2588
2584
|
let waiter;
|
|
2589
2585
|
let onAbort;
|
|
@@ -2611,9 +2607,9 @@ function createRunAdmission(options) {
|
|
|
2611
2607
|
if (onAbort && signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
2612
2608
|
return Effect.sync(cleanup);
|
|
2613
2609
|
});
|
|
2614
|
-
return remaining === void 0 ? waiting : waiting.pipe(Effect.
|
|
2610
|
+
return remaining === void 0 ? waiting : waiting.pipe(Effect.timeoutOrElse({
|
|
2615
2611
|
duration: Math.min(remaining, 2147483647),
|
|
2616
|
-
|
|
2612
|
+
orElse: () => Effect.fail(new ModelChangeBoundaryDeadlineError("Run admission deadline has passed"))
|
|
2617
2613
|
}));
|
|
2618
2614
|
});
|
|
2619
2615
|
const fence = () => {
|
|
@@ -2621,7 +2617,7 @@ function createRunAdmission(options) {
|
|
|
2621
2617
|
};
|
|
2622
2618
|
const whenDrained = () => Effect.suspend(() => {
|
|
2623
2619
|
if (active === 0) return Effect.void;
|
|
2624
|
-
return Effect.
|
|
2620
|
+
return Effect.callback((resume) => {
|
|
2625
2621
|
let settled = false;
|
|
2626
2622
|
let waiter;
|
|
2627
2623
|
const cleanup = () => {
|
|
@@ -2673,50 +2669,9 @@ function abortError(signal) {
|
|
|
2673
2669
|
return signal.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("Run admission aborted");
|
|
2674
2670
|
}
|
|
2675
2671
|
//#endregion
|
|
2676
|
-
//#region src/
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
};
|
|
2680
|
-
function createEffectCompactionService(options) {
|
|
2681
|
-
const candidates = /* @__PURE__ */ new Map();
|
|
2682
|
-
const committed = /* @__PURE__ */ new Map();
|
|
2683
|
-
const serial = Effect.unsafeMakeSemaphore(1);
|
|
2684
|
-
return {
|
|
2685
|
-
createCandidate: (input) => {
|
|
2686
|
-
const safeInput = Object.freeze({
|
|
2687
|
-
agentId: input.agentId,
|
|
2688
|
-
conversationId: input.conversationId,
|
|
2689
|
-
instanceId: input.instanceId,
|
|
2690
|
-
profileRevision: input.profileRevision,
|
|
2691
|
-
tenantId: input.tenantId,
|
|
2692
|
-
transcript: Object.freeze([...input.transcript]),
|
|
2693
|
-
watermark: input.watermark
|
|
2694
|
-
});
|
|
2695
|
-
return options.compactor.compact(safeInput).pipe(Effect.map((summary) => Object.freeze({
|
|
2696
|
-
agentId: input.agentId,
|
|
2697
|
-
conversationId: input.conversationId,
|
|
2698
|
-
id: `compaction:${options.identity.next()}`,
|
|
2699
|
-
instanceId: input.instanceId,
|
|
2700
|
-
profileRevision: input.profileRevision,
|
|
2701
|
-
summary,
|
|
2702
|
-
tenantId: input.tenantId,
|
|
2703
|
-
watermark: input.watermark
|
|
2704
|
-
})), Effect.tap((candidate) => Effect.sync(() => candidates.set(candidate.id, candidate))));
|
|
2705
|
-
},
|
|
2706
|
-
commit: (candidateId) => serial.withPermits(1)(Effect.suspend(() => {
|
|
2707
|
-
const candidate = candidates.get(candidateId);
|
|
2708
|
-
if (!candidate) return Effect.fail(new CompactionError(`unknown compaction candidate: ${candidateId}`));
|
|
2709
|
-
const key = `${candidate.instanceId}/${candidate.conversationId}`;
|
|
2710
|
-
const current = committed.get(key);
|
|
2711
|
-
if (current && current.watermark >= candidate.watermark) return Effect.fail(new CompactionError("compaction watermark conflict"));
|
|
2712
|
-
return Effect.sync(() => {
|
|
2713
|
-
committed.set(key, candidate);
|
|
2714
|
-
candidates.delete(candidateId);
|
|
2715
|
-
return candidate;
|
|
2716
|
-
});
|
|
2717
|
-
})),
|
|
2718
|
-
current: (instanceId, conversationId) => committed.get(`${instanceId}/${conversationId}`)
|
|
2719
|
-
};
|
|
2672
|
+
//#region src/adapters/agent/memory/persisted-memory-record.ts
|
|
2673
|
+
function restorePersistedMemoryRecord(snapshot) {
|
|
2674
|
+
return restoreMemoryRecord(snapshot);
|
|
2720
2675
|
}
|
|
2721
2676
|
//#endregion
|
|
2722
2677
|
//#region src/adapters/outbound/persistence/memory/agent-memory-repository-contract.ts
|
|
@@ -2730,9 +2685,6 @@ function resolveAgentMemoryUpdate(previous, next) {
|
|
|
2730
2685
|
if (!previous.validateTransitionTo(next)) throw new Error("memory revision or transition conflict");
|
|
2731
2686
|
return next;
|
|
2732
2687
|
}
|
|
2733
|
-
//#endregion
|
|
2734
|
-
//#region src/adapters/outbound/persistence/memory/agent-memory-snapshot-codec.ts
|
|
2735
|
-
const AGENT_MEMORY_JSONL_VERSION = 1;
|
|
2736
2688
|
function encodeAgentMemorySnapshot(snapshot) {
|
|
2737
2689
|
return JSON.stringify({
|
|
2738
2690
|
snapshot,
|
|
@@ -2756,7 +2708,7 @@ function decodeAgentMemorySnapshots(raw) {
|
|
|
2756
2708
|
} catch {
|
|
2757
2709
|
throw invalidSnapshot(index);
|
|
2758
2710
|
}
|
|
2759
|
-
const key = `${createMemoryNamespace
|
|
2711
|
+
const key = `${createMemoryNamespace(record.binding)}\u0000${record.id}`;
|
|
2760
2712
|
const previous = latest.get(key);
|
|
2761
2713
|
try {
|
|
2762
2714
|
if (previous) resolveAgentMemoryUpdate(previous, record);
|
|
@@ -2777,16 +2729,16 @@ function createInMemoryAgentMemoryRepository(options = {}) {
|
|
|
2777
2729
|
const records = /* @__PURE__ */ new Map();
|
|
2778
2730
|
for (const snapshot of options.initial ?? []) {
|
|
2779
2731
|
const restored = restorePersistedAgentMemoryRecord(snapshot);
|
|
2780
|
-
const namespace = createMemoryNamespace
|
|
2732
|
+
const namespace = createMemoryNamespace(restored.binding);
|
|
2781
2733
|
const bucket = records.get(namespace) ?? /* @__PURE__ */ new Map();
|
|
2782
2734
|
if (bucket.has(restored.id)) throw new AgentMemoryRepositoryConflict(`duplicate initial memory: ${restored.id}`);
|
|
2783
2735
|
bucket.set(restored.id, restored);
|
|
2784
2736
|
records.set(namespace, bucket);
|
|
2785
2737
|
}
|
|
2786
|
-
const serial =
|
|
2738
|
+
const serial = Semaphore.makeUnsafe(1);
|
|
2787
2739
|
return {
|
|
2788
|
-
get: (binding, id) => Effect.sync(() => records.get(createMemoryNamespace
|
|
2789
|
-
list: (binding) => Effect.sync(() => [...records.get(createMemoryNamespace
|
|
2740
|
+
get: (binding, id) => Effect.sync(() => records.get(createMemoryNamespace(binding))?.get(id)),
|
|
2741
|
+
list: (binding) => Effect.sync(() => [...records.get(createMemoryNamespace(binding))?.values() ?? []]),
|
|
2790
2742
|
save: (snapshotInput) => serial.withPermits(1)(Effect.uninterruptible(Effect.suspend(() => {
|
|
2791
2743
|
let record;
|
|
2792
2744
|
try {
|
|
@@ -2794,7 +2746,7 @@ function createInMemoryAgentMemoryRepository(options = {}) {
|
|
|
2794
2746
|
} catch {
|
|
2795
2747
|
return Effect.fail(new AgentMemoryRepositoryConflict("memory revision or transition conflict"));
|
|
2796
2748
|
}
|
|
2797
|
-
const namespace = createMemoryNamespace
|
|
2749
|
+
const namespace = createMemoryNamespace(record.binding);
|
|
2798
2750
|
const bucket = records.get(namespace) ?? /* @__PURE__ */ new Map();
|
|
2799
2751
|
const previous = bucket.get(record.id);
|
|
2800
2752
|
try {
|
|
@@ -3222,14 +3174,14 @@ function restoreToolOperation(snapshot) {
|
|
|
3222
3174
|
var ToolOperationLedgerError = class extends Error {
|
|
3223
3175
|
name = "ToolOperationLedgerError";
|
|
3224
3176
|
};
|
|
3225
|
-
function createToolOperationLedger
|
|
3177
|
+
function createToolOperationLedger(options = {}) {
|
|
3226
3178
|
const records = /* @__PURE__ */ new Map();
|
|
3227
3179
|
for (const snapshot of options.initial ?? []) {
|
|
3228
3180
|
const operation = restoreToolOperation(snapshot);
|
|
3229
3181
|
if (records.has(operation.operationId)) throw new ToolOperationLedgerError(`duplicate initial tool operation: ${operation.operationId}`);
|
|
3230
3182
|
records.set(operation.operationId, operation);
|
|
3231
3183
|
}
|
|
3232
|
-
const semaphore =
|
|
3184
|
+
const semaphore = Semaphore.makeUnsafe(1);
|
|
3233
3185
|
const exclusive = (effect) => semaphore.withPermits(1)(Effect.uninterruptible(effect));
|
|
3234
3186
|
const save = (operation) => {
|
|
3235
3187
|
const snapshot = operation.toSnapshot();
|
|
@@ -3330,7 +3282,7 @@ var ToolInvocationDenied = class extends Error {
|
|
|
3330
3282
|
name = "ToolInvocationDenied";
|
|
3331
3283
|
};
|
|
3332
3284
|
function createToolBroker(options) {
|
|
3333
|
-
const operations = options.operations ?? createToolOperationLedger
|
|
3285
|
+
const operations = options.operations ?? createToolOperationLedger();
|
|
3334
3286
|
const hostTools = new Map(options.hostTools?.map((tool) => [tool.id, tool]) ?? []);
|
|
3335
3287
|
if (hostTools.size !== (options.hostTools?.length ?? 0)) throw new ToolInvocationDenied("duplicate Host Tool id");
|
|
3336
3288
|
return { execute: (request) => Effect.gen(function* () {
|
|
@@ -3341,8 +3293,8 @@ function createToolBroker(options) {
|
|
|
3341
3293
|
const policy = yield* options.policy.current();
|
|
3342
3294
|
if (policy.revokedToolIds.includes(request.toolId)) return yield* Effect.fail(new ToolInvocationDenied(`tool has been revoked: ${request.toolId}`));
|
|
3343
3295
|
if (prepared.tool.idempotency === "required" && !request.operationId) return yield* Effect.fail(new ToolInvocationDenied(`tool requires a stable operation id: ${request.toolId}`));
|
|
3344
|
-
if (requiresToolApproval
|
|
3345
|
-
if (requiresToolApproval
|
|
3296
|
+
if (requiresToolApproval(prepared.tool.risk) && !request.operationId) return yield* Effect.fail(new ToolInvocationDenied(`tool approval requires a stable operation id: ${request.toolId}`));
|
|
3297
|
+
if (requiresToolApproval(prepared.tool.risk) && !request.approvalId) return yield* Effect.fail(new ToolInvocationDenied(`tool requires trusted approval: ${request.toolId}`));
|
|
3346
3298
|
const binding = yield* Effect.try({
|
|
3347
3299
|
catch: (error) => error,
|
|
3348
3300
|
try: () => createOperationBinding(prepared.authority, prepared.tool, request.input, options.digest)
|
|
@@ -3354,7 +3306,7 @@ function createToolBroker(options) {
|
|
|
3354
3306
|
if (inspected.status === "completed") return yield* replayCompleted(inspected.result);
|
|
3355
3307
|
if (inspected.status === "blocked") return yield* Effect.fail(new ToolInvocationDenied(`tool operation is fenced: ${inspected.reason}`));
|
|
3356
3308
|
}
|
|
3357
|
-
if (requiresToolApproval
|
|
3309
|
+
if (requiresToolApproval(prepared.tool.risk)) {
|
|
3358
3310
|
if (!(yield* options.approvals.consume({
|
|
3359
3311
|
agentId: prepared.authority.agentId,
|
|
3360
3312
|
approvalId: request.approvalId,
|
|
@@ -3385,9 +3337,9 @@ function createToolBroker(options) {
|
|
|
3385
3337
|
})).execute(request.input, context);
|
|
3386
3338
|
if (request.operationId) yield* operations.complete(request.operationId, binding, result);
|
|
3387
3339
|
return result;
|
|
3388
|
-
}).pipe(Effect.
|
|
3340
|
+
}).pipe(Effect.catch((error) => {
|
|
3389
3341
|
if (!request.operationId) return Effect.fail(error);
|
|
3390
|
-
return (prepared.tool.risk === "observe" || error instanceof ToolExecutorInputRejected ? operations.abort(request.operationId, binding) : operations.requireReconciliation(request.operationId, binding, error instanceof Error ? error.message : String(error))).pipe(Effect.
|
|
3342
|
+
return (prepared.tool.risk === "observe" || error instanceof ToolExecutorInputRejected ? operations.abort(request.operationId, binding) : operations.requireReconciliation(request.operationId, binding, error instanceof Error ? error.message : String(error))).pipe(Effect.andThen(Effect.fail(error)));
|
|
3391
3343
|
}));
|
|
3392
3344
|
}) };
|
|
3393
3345
|
}
|
|
@@ -3405,7 +3357,7 @@ function prepareInvocation(hostTools, catalog, request) {
|
|
|
3405
3357
|
function createOperationBinding(authority, tool, input, digest) {
|
|
3406
3358
|
let inputDigest;
|
|
3407
3359
|
try {
|
|
3408
|
-
inputDigest = createToolInputDigest
|
|
3360
|
+
inputDigest = createToolInputDigest(input, digest);
|
|
3409
3361
|
} catch (error) {
|
|
3410
3362
|
if (error instanceof InvalidToolInput) throw new ToolInvocationDenied(`tool input is not stable JSON: ${tool.id}`);
|
|
3411
3363
|
throw error;
|
|
@@ -3461,9 +3413,6 @@ const RIVUS_RUNTIME_TOOL_IDS = Object.freeze([
|
|
|
3461
3413
|
function isRivusRuntimeToolId(value) {
|
|
3462
3414
|
return RIVUS_RUNTIME_TOOL_IDS.includes(value);
|
|
3463
3415
|
}
|
|
3464
|
-
//#endregion
|
|
3465
|
-
//#region src/adapters/outbound/persistence/tool-operation/tool-operation-snapshot-codec.ts
|
|
3466
|
-
const TOOL_OPERATION_JSONL_VERSION = 1;
|
|
3467
3416
|
function encodeToolOperationSnapshot(record) {
|
|
3468
3417
|
return JSON.stringify({
|
|
3469
3418
|
record,
|
|
@@ -3503,7 +3452,7 @@ function openJsonlToolOperationLedger(options) {
|
|
|
3503
3452
|
if (recovered !== operation) yield* persist(options.filePath, recovered.toSnapshot());
|
|
3504
3453
|
initial.push(recovered.toSnapshot());
|
|
3505
3454
|
}
|
|
3506
|
-
return createToolOperationLedger
|
|
3455
|
+
return createToolOperationLedger({
|
|
3507
3456
|
initial,
|
|
3508
3457
|
persist: (record) => persist(options.filePath, record)
|
|
3509
3458
|
});
|
|
@@ -3748,417 +3697,5 @@ function readDate(value, field, lineNumber) {
|
|
|
3748
3697
|
return date;
|
|
3749
3698
|
}
|
|
3750
3699
|
//#endregion
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
return { now: Effect.succeed(now) };
|
|
3754
|
-
}
|
|
3755
|
-
function createTestClock(initial) {
|
|
3756
|
-
let now = initial;
|
|
3757
|
-
return {
|
|
3758
|
-
advance: (ms) => {
|
|
3759
|
-
now = new Date(now.getTime() + ms);
|
|
3760
|
-
},
|
|
3761
|
-
now: Effect.suspend(() => Effect.succeed(now))
|
|
3762
|
-
};
|
|
3763
|
-
}
|
|
3764
|
-
function createSequenceRunIds(runIds) {
|
|
3765
|
-
let index = 0;
|
|
3766
|
-
return { next: Effect.sync(() => {
|
|
3767
|
-
const runId = runIds[index];
|
|
3768
|
-
if (runId === void 0) throw new Error("No run ids left in test generator");
|
|
3769
|
-
index += 1;
|
|
3770
|
-
return runId;
|
|
3771
|
-
}) };
|
|
3772
|
-
}
|
|
3773
|
-
//#endregion
|
|
3774
|
-
//#region src/adapters/compatibility/agent-execution/loop/agent-loop-prompt-transformer.ts
|
|
3775
|
-
function createAgentLoopPromptTransformer(options) {
|
|
3776
|
-
return {
|
|
3777
|
-
run: (input) => Stream.unwrap(Effect.promise(() => Promise.resolve(options.transform(input))).pipe(Effect.map((text) => options.loop.run({
|
|
3778
|
-
...input,
|
|
3779
|
-
text
|
|
3780
|
-
})))),
|
|
3781
|
-
...options.loop.supportsSteering ? { supportsSteering: true } : {}
|
|
3782
|
-
};
|
|
3783
|
-
}
|
|
3784
|
-
//#endregion
|
|
3785
|
-
//#region src/adapters/compatibility/agent-execution/runtime/agent-harness.ts
|
|
3786
|
-
function createAgentHarness$1(options) {
|
|
3787
|
-
return createAgentHarness({
|
|
3788
|
-
...options,
|
|
3789
|
-
loop: toEffectAgentLoop(options.loop)
|
|
3790
|
-
});
|
|
3791
|
-
}
|
|
3792
|
-
//#endregion
|
|
3793
|
-
//#region src/adapters/compatibility/agent-execution/runtime/agent-callback-adapters.ts
|
|
3794
|
-
function createAgentDomainEventSinkFromCallback(append) {
|
|
3795
|
-
return createAgentDomainEventSink((event) => Effect.tryPromise({
|
|
3796
|
-
try: async () => {
|
|
3797
|
-
await append(event);
|
|
3798
|
-
},
|
|
3799
|
-
catch: (cause) => cause
|
|
3800
|
-
}));
|
|
3801
|
-
}
|
|
3802
|
-
function createAgentDomainEventHandler(handle) {
|
|
3803
|
-
return (event) => Effect.tryPromise({
|
|
3804
|
-
try: async () => {
|
|
3805
|
-
await handle(event);
|
|
3806
|
-
},
|
|
3807
|
-
catch: (cause) => cause
|
|
3808
|
-
});
|
|
3809
|
-
}
|
|
3810
|
-
function createAgentRunUpdateHandler(handle) {
|
|
3811
|
-
return (update) => Effect.tryPromise({
|
|
3812
|
-
try: async () => {
|
|
3813
|
-
await handle(update);
|
|
3814
|
-
},
|
|
3815
|
-
catch: (cause) => cause
|
|
3816
|
-
});
|
|
3817
|
-
}
|
|
3818
|
-
//#endregion
|
|
3819
|
-
//#region src/adapters/compatibility/agent-execution/runtime/agent-harness-client.ts
|
|
3820
|
-
function createAgentHarnessClient(harness) {
|
|
3821
|
-
return {
|
|
3822
|
-
cancelActiveRun: (reason) => Effect.runPromise(harness.cancelActiveRun(reason)),
|
|
3823
|
-
cancelRun: (runId, reason) => Effect.runPromise(harness.cancelRun(runId, reason)),
|
|
3824
|
-
forSession: (sessionKey) => createAgentSessionClient(harness.forSession(sessionKey)),
|
|
3825
|
-
getActiveRun: () => harness.getActiveRun(),
|
|
3826
|
-
getActiveRunId: () => harness.getActiveRunId(),
|
|
3827
|
-
getActiveRunState: () => harness.getActiveRunState(),
|
|
3828
|
-
getAvailability: () => harness.getAvailability(),
|
|
3829
|
-
getHistory: () => harness.getHistory(),
|
|
3830
|
-
getRunEvents: (runId) => harness.getRunEvents(runId),
|
|
3831
|
-
getRunSnapshot: (runId) => harness.getRunSnapshot(runId),
|
|
3832
|
-
getRunSummary: (runId) => harness.getRunSummary(runId),
|
|
3833
|
-
getRunState: (runId) => harness.getRunState(runId),
|
|
3834
|
-
getRunUpdates: (runId) => harness.getRunUpdates(runId),
|
|
3835
|
-
getSessionHistory: (sessionKey) => harness.getSessionHistory(sessionKey),
|
|
3836
|
-
getSessionLatestRunSnapshot: (sessionKey) => harness.getSessionLatestRunSnapshot(sessionKey),
|
|
3837
|
-
getSessionLatestRunSummary: (sessionKey) => harness.getSessionLatestRunSummary(sessionKey),
|
|
3838
|
-
getSessionRuns: (sessionKey) => harness.getSessionRuns(sessionKey),
|
|
3839
|
-
getSessionSnapshot: (sessionKey) => harness.getSessionSnapshot(sessionKey),
|
|
3840
|
-
getSessionSummary: (sessionKey) => harness.getSessionSummary(sessionKey),
|
|
3841
|
-
getSessionTranscript: (sessionKey) => harness.getSessionTranscript(sessionKey),
|
|
3842
|
-
getSessionState: (sessionKey) => harness.getSessionState(sessionKey),
|
|
3843
|
-
getState: () => harness.getState(),
|
|
3844
|
-
harness,
|
|
3845
|
-
prompt: (command) => Effect.runPromise(harness.prompt(command)),
|
|
3846
|
-
promptRunSnapshot: (command) => Effect.runPromise(harness.promptRunSnapshot(command)),
|
|
3847
|
-
promptSnapshot: (command) => Effect.runPromise(harness.promptSnapshot(command)),
|
|
3848
|
-
promptText: (command) => Effect.runPromise(harness.promptText(command)),
|
|
3849
|
-
promptTurn: (command) => Effect.runPromise(harness.promptTurn(command)),
|
|
3850
|
-
promptWithEvents: (command, onEvent) => Effect.runPromise(harness.promptWithEvents(command, createAgentDomainEventHandler(onEvent))),
|
|
3851
|
-
promptWithText: (command, onTextDelta) => Effect.runPromise(harness.promptWithEvents(command, createTextDeltaEventHandler(onTextDelta))),
|
|
3852
|
-
promptWithUpdates: (command, onUpdate) => Effect.runPromise(harness.promptWithUpdates(command, createAgentRunUpdateHandler(onUpdate))),
|
|
3853
|
-
stream: (command) => Stream.toAsyncIterable(harness.stream(command)),
|
|
3854
|
-
streamText: (command) => Stream.toAsyncIterable(harness.streamText(command)),
|
|
3855
|
-
streamUpdates: (command) => Stream.toAsyncIterable(harness.streamUpdates(command)),
|
|
3856
|
-
subscribe: (listener) => harness.subscribe(listener),
|
|
3857
|
-
subscribeRun: (runId, listener) => harness.subscribeRun(runId, listener),
|
|
3858
|
-
subscribeRunUpdates: (runId, listener) => harness.subscribeRunUpdates(runId, listener),
|
|
3859
|
-
subscribeUpdates: (listener) => harness.subscribeUpdates(listener),
|
|
3860
|
-
tryPrompt: (command) => runAttempt(harness.prompt(command)),
|
|
3861
|
-
tryPromptText: (command) => runAttempt(harness.promptText(command))
|
|
3862
|
-
};
|
|
3863
|
-
}
|
|
3864
|
-
function createAgentSessionClient(handle) {
|
|
3865
|
-
return {
|
|
3866
|
-
cancelActiveRun: (reason) => Effect.runPromise(handle.cancelActiveRun(reason)),
|
|
3867
|
-
cancelRun: (runId, reason) => Effect.runPromise(handle.cancelRun(runId, reason)),
|
|
3868
|
-
getActiveRun: () => handle.getActiveRun(),
|
|
3869
|
-
getActiveRunState: () => handle.getActiveRunState(),
|
|
3870
|
-
getAvailability: () => handle.getAvailability(),
|
|
3871
|
-
getHistory: () => handle.getHistory(),
|
|
3872
|
-
getLatestRunSnapshot: () => handle.getLatestRunSnapshot(),
|
|
3873
|
-
getLatestRunSummary: () => handle.getLatestRunSummary(),
|
|
3874
|
-
getRunEvents: (runId) => handle.getRunEvents(runId),
|
|
3875
|
-
getRunSnapshot: (runId) => handle.getRunSnapshot(runId),
|
|
3876
|
-
getRunSummary: (runId) => handle.getRunSummary(runId),
|
|
3877
|
-
getRuns: () => handle.getRuns(),
|
|
3878
|
-
getRunState: (runId) => handle.getRunState(runId),
|
|
3879
|
-
getRunUpdates: (runId) => handle.getRunUpdates(runId),
|
|
3880
|
-
getSnapshot: () => handle.getSnapshot(),
|
|
3881
|
-
getState: () => handle.getState(),
|
|
3882
|
-
getSummary: () => handle.getSummary(),
|
|
3883
|
-
getTranscript: () => handle.getTranscript(),
|
|
3884
|
-
handle,
|
|
3885
|
-
prompt: (text) => Effect.runPromise(handle.prompt(text)),
|
|
3886
|
-
promptRunSnapshot: (text) => Effect.runPromise(handle.promptRunSnapshot(text)),
|
|
3887
|
-
promptSnapshot: (text) => Effect.runPromise(handle.promptSnapshot(text)),
|
|
3888
|
-
promptText: (text) => Effect.runPromise(handle.promptText(text)),
|
|
3889
|
-
promptTurn: (text) => Effect.runPromise(handle.promptTurn(text)),
|
|
3890
|
-
promptWithEvents: (text, onEvent) => Effect.runPromise(handle.promptWithEvents(text, createAgentDomainEventHandler(onEvent))),
|
|
3891
|
-
promptWithText: (text, onTextDelta) => Effect.runPromise(handle.promptWithEvents(text, createTextDeltaEventHandler(onTextDelta))),
|
|
3892
|
-
promptWithUpdates: (text, onUpdate) => Effect.runPromise(handle.promptWithUpdates(text, createAgentRunUpdateHandler(onUpdate))),
|
|
3893
|
-
sessionKey: handle.sessionKey,
|
|
3894
|
-
stream: (text) => Stream.toAsyncIterable(handle.stream(text)),
|
|
3895
|
-
streamText: (text) => Stream.toAsyncIterable(handle.streamText(text)),
|
|
3896
|
-
streamUpdates: (text) => Stream.toAsyncIterable(handle.streamUpdates(text)),
|
|
3897
|
-
subscribe: (listener) => handle.subscribe(listener),
|
|
3898
|
-
subscribeRun: (runId, listener) => handle.subscribeRun(runId, listener),
|
|
3899
|
-
subscribeRunUpdates: (runId, listener) => handle.subscribeRunUpdates(runId, listener),
|
|
3900
|
-
subscribeUpdates: (listener) => handle.subscribeUpdates(listener),
|
|
3901
|
-
tryPrompt: (text) => runAttempt(handle.prompt(text)),
|
|
3902
|
-
tryPromptText: (text) => runAttempt(handle.promptText(text))
|
|
3903
|
-
};
|
|
3904
|
-
}
|
|
3905
|
-
function createTextDeltaEventHandler(onTextDelta) {
|
|
3906
|
-
return createAgentDomainEventHandler((event) => {
|
|
3907
|
-
if (!isAssistantTextDeltaEvent(event)) return;
|
|
3908
|
-
return onTextDelta(event.delta);
|
|
3909
|
-
});
|
|
3910
|
-
}
|
|
3911
|
-
async function runAttempt(effect) {
|
|
3912
|
-
const exit = await Effect.runPromiseExit(effect);
|
|
3913
|
-
if (Exit.isSuccess(exit)) return {
|
|
3914
|
-
ok: true,
|
|
3915
|
-
value: exit.value
|
|
3916
|
-
};
|
|
3917
|
-
const failure = Cause.failureOption(exit.cause);
|
|
3918
|
-
return {
|
|
3919
|
-
error: Option.isSome(failure) ? failure.value : exit.cause,
|
|
3920
|
-
ok: false
|
|
3921
|
-
};
|
|
3922
|
-
}
|
|
3923
|
-
//#endregion
|
|
3924
|
-
//#region src/adapters/compatibility/agent-execution/runtime/agent-runtime-primitives.ts
|
|
3925
|
-
const DEFAULT_MAIN_SESSION_KEY = "main";
|
|
3926
|
-
function createDefaultAgentHarness(options) {
|
|
3927
|
-
return createAgentHarness$1({
|
|
3928
|
-
...options,
|
|
3929
|
-
clock: options.clock ?? createSystemClock(),
|
|
3930
|
-
runIds: options.runIds ?? createUuidRunIds()
|
|
3931
|
-
});
|
|
3932
|
-
}
|
|
3933
|
-
function createDefaultAgentHarnessFromCallback(run, options = {}) {
|
|
3934
|
-
return createDefaultAgentHarness({
|
|
3935
|
-
...options,
|
|
3936
|
-
loop: createAgentLoopFromCallback(run)
|
|
3937
|
-
});
|
|
3938
|
-
}
|
|
3939
|
-
function createDefaultAgentHarnessFromTextCallback(generate, options = {}) {
|
|
3940
|
-
return createDefaultAgentHarness({
|
|
3941
|
-
...options,
|
|
3942
|
-
loop: createTextAgentLoopFromCallback(generate)
|
|
3943
|
-
});
|
|
3944
|
-
}
|
|
3945
|
-
function createDefaultAgentHarnessClient(options) {
|
|
3946
|
-
return createAgentHarnessClient(createDefaultAgentHarness(options));
|
|
3947
|
-
}
|
|
3948
|
-
function createDefaultAgentHarnessClientFromCallback(run, options = {}) {
|
|
3949
|
-
return createAgentHarnessClient(createDefaultAgentHarnessFromCallback(run, options));
|
|
3950
|
-
}
|
|
3951
|
-
function createDefaultAgentHarnessClientFromTextCallback(generate, options = {}) {
|
|
3952
|
-
return createAgentHarnessClient(createDefaultAgentHarnessFromTextCallback(generate, options));
|
|
3953
|
-
}
|
|
3954
|
-
function createDefaultAgentRuntime(options, runtimeOptions = {}) {
|
|
3955
|
-
return createAgentRuntime(createDefaultAgentHarness(options), runtimeOptions);
|
|
3956
|
-
}
|
|
3957
|
-
function createDefaultAgentRuntimeFromCallback(run, options = {}, runtimeOptions = {}) {
|
|
3958
|
-
return createAgentRuntime(createDefaultAgentHarnessFromCallback(run, options), runtimeOptions);
|
|
3959
|
-
}
|
|
3960
|
-
function createDefaultAgentRuntimeFromTextCallback(generate, options = {}, runtimeOptions = {}) {
|
|
3961
|
-
return createAgentRuntime(createDefaultAgentHarnessFromTextCallback(generate, options), runtimeOptions);
|
|
3962
|
-
}
|
|
3963
|
-
function createSystemClock() {
|
|
3964
|
-
return { now: Effect.sync(() => /* @__PURE__ */ new Date()) };
|
|
3965
|
-
}
|
|
3966
|
-
function createUuidRunIds() {
|
|
3967
|
-
return { next: Effect.sync(() => randomUUID()) };
|
|
3968
|
-
}
|
|
3969
|
-
function createAgentRuntime(harness, options = {}) {
|
|
3970
|
-
const mainSessionKey = options.mainSessionKey ?? DEFAULT_MAIN_SESSION_KEY;
|
|
3971
|
-
const client = createAgentHarnessClient(harness);
|
|
3972
|
-
const mainClient = client.forSession(mainSessionKey);
|
|
3973
|
-
return {
|
|
3974
|
-
client,
|
|
3975
|
-
forSession: (sessionKey) => harness.forSession(sessionKey),
|
|
3976
|
-
forSessionClient: (sessionKey) => client.forSession(sessionKey),
|
|
3977
|
-
harness,
|
|
3978
|
-
mainClient,
|
|
3979
|
-
mainSession: harness.forSession(mainSessionKey),
|
|
3980
|
-
mainSessionKey,
|
|
3981
|
-
prompt: (text) => mainClient.prompt(text),
|
|
3982
|
-
promptText: (text) => mainClient.promptText(text),
|
|
3983
|
-
promptTurn: (text) => mainClient.promptTurn(text),
|
|
3984
|
-
tryPrompt: (text) => mainClient.tryPrompt(text),
|
|
3985
|
-
tryPromptText: (text) => mainClient.tryPromptText(text)
|
|
3986
|
-
};
|
|
3987
|
-
}
|
|
3988
|
-
//#endregion
|
|
3989
|
-
//#region src/adapters/compatibility/memory/public-contract.ts
|
|
3990
|
-
function createMemoryNamespace(binding) {
|
|
3991
|
-
return {
|
|
3992
|
-
conversation: [
|
|
3993
|
-
binding.tenantId,
|
|
3994
|
-
binding.agentId,
|
|
3995
|
-
binding.subjectId,
|
|
3996
|
-
binding.conversationId ?? "",
|
|
3997
|
-
binding.scope
|
|
3998
|
-
],
|
|
3999
|
-
"agent-private": [
|
|
4000
|
-
binding.tenantId,
|
|
4001
|
-
binding.agentId,
|
|
4002
|
-
binding.subjectId,
|
|
4003
|
-
binding.scope
|
|
4004
|
-
],
|
|
4005
|
-
project: [
|
|
4006
|
-
binding.tenantId,
|
|
4007
|
-
binding.agentId,
|
|
4008
|
-
binding.projectId ?? "",
|
|
4009
|
-
binding.scope
|
|
4010
|
-
],
|
|
4011
|
-
"shared-user-profile": [
|
|
4012
|
-
binding.tenantId,
|
|
4013
|
-
binding.subjectId,
|
|
4014
|
-
binding.scope
|
|
4015
|
-
]
|
|
4016
|
-
}[binding.scope].map(encodeURIComponent).join("/");
|
|
4017
|
-
}
|
|
4018
|
-
function restrictMemoryScopesForAudience(scopes, audience) {
|
|
4019
|
-
return audience === "group" ? scopes.filter((scope) => scope === "conversation" || scope === "project") : [...scopes];
|
|
4020
|
-
}
|
|
4021
|
-
//#endregion
|
|
4022
|
-
//#region src/adapters/compatibility/memory/legacy-memory-adapter.ts
|
|
4023
|
-
function adaptLegacyMemoryService(service) {
|
|
4024
|
-
return { bind: (binding) => adaptLegacyMemoryHandle(service.bind(binding)) };
|
|
4025
|
-
}
|
|
4026
|
-
function adaptLegacyMemoryHandle(handle) {
|
|
4027
|
-
return Object.freeze({
|
|
4028
|
-
namespace: handle.namespace,
|
|
4029
|
-
scope: handle.scope,
|
|
4030
|
-
confirm: async (input) => toCanonicalRecord(await handle.confirm(input)),
|
|
4031
|
-
forgetRequest: async (input) => toCanonicalRecord(await handle.forgetRequest(input)),
|
|
4032
|
-
inspect: async (id) => toOptionalCanonicalRecord(await handle.inspect(id)),
|
|
4033
|
-
propose: async (input) => toCanonicalRecord(await handle.propose(input)),
|
|
4034
|
-
read: async (id) => toOptionalCanonicalRecord(await handle.read(id)),
|
|
4035
|
-
search: async (query) => (await handle.search(query)).map((record) => toCanonicalRecord(record))
|
|
4036
|
-
});
|
|
4037
|
-
}
|
|
4038
|
-
function toCanonicalRecord(record) {
|
|
4039
|
-
return { ...record };
|
|
4040
|
-
}
|
|
4041
|
-
function toOptionalCanonicalRecord(record) {
|
|
4042
|
-
return record === void 0 ? void 0 : toCanonicalRecord(record);
|
|
4043
|
-
}
|
|
4044
|
-
//#endregion
|
|
4045
|
-
//#region src/adapters/compatibility/memory/project-memory-prompt-preparer.ts
|
|
4046
|
-
function createLegacyProjectMemoryPromptPreparer(options) {
|
|
4047
|
-
const prepare = createProjectMemoryPromptPreparer({
|
|
4048
|
-
...options,
|
|
4049
|
-
memory: adaptLegacyMemoryService(options.memory)
|
|
4050
|
-
});
|
|
4051
|
-
return (input) => prepare(input);
|
|
4052
|
-
}
|
|
4053
|
-
//#endregion
|
|
4054
|
-
//#region src/adapters/compatibility/memory/rivus-memory-tool.ts
|
|
4055
|
-
function createLegacyRivusMemoryTool(memory) {
|
|
4056
|
-
const tool = createRivusMemoryTool(Array.isArray(memory) ? memory.map(adaptLegacyMemoryHandle) : [adaptLegacyMemoryHandle(memory)]);
|
|
4057
|
-
return {
|
|
4058
|
-
execute: async (command) => executeLegacyCommand(tool, command),
|
|
4059
|
-
replayCompleted: (command, completedResult) => tool.replayCompleted(command, completedResult)
|
|
4060
|
-
};
|
|
4061
|
-
}
|
|
4062
|
-
async function executeLegacyCommand(tool, command) {
|
|
4063
|
-
return tool.execute(command);
|
|
4064
|
-
}
|
|
4065
|
-
function createLegacyRivusMemoryToolDescriptor(options) {
|
|
4066
|
-
return createRivusMemoryToolDescriptor({ memory: adaptLegacyMemoryService(options.memory) });
|
|
4067
|
-
}
|
|
4068
|
-
//#endregion
|
|
4069
|
-
//#region src/adapters/compatibility/tool-execution/runtime/effect-runner.ts
|
|
4070
|
-
async function runToolExecutionEffect(effect) {
|
|
4071
|
-
const exit = await Effect.runPromiseExit(effect);
|
|
4072
|
-
if (Exit.isSuccess(exit)) return exit.value;
|
|
4073
|
-
throw failureOrCause(exit.cause);
|
|
4074
|
-
}
|
|
4075
|
-
function runToolExecutionEffectSync(effect) {
|
|
4076
|
-
const exit = Effect.runSyncExit(effect);
|
|
4077
|
-
if (Exit.isSuccess(exit)) return exit.value;
|
|
4078
|
-
throw failureOrCause(exit.cause);
|
|
4079
|
-
}
|
|
4080
|
-
function failureOrCause(cause) {
|
|
4081
|
-
const failure = Cause.failureOption(cause);
|
|
4082
|
-
return Option.isSome(failure) ? failure.value : Cause.squash(cause);
|
|
4083
|
-
}
|
|
4084
|
-
//#endregion
|
|
4085
|
-
//#region src/adapters/compatibility/memory/compaction/compaction-service.ts
|
|
4086
|
-
function createCompactionService(options) {
|
|
4087
|
-
const service = createEffectCompactionService({
|
|
4088
|
-
compactor: { compact: (input) => Effect.tryPromise({
|
|
4089
|
-
catch: (error) => error,
|
|
4090
|
-
try: () => options.compactor.compact(input)
|
|
4091
|
-
}) },
|
|
4092
|
-
identity: { next: () => randomUUID() }
|
|
4093
|
-
});
|
|
4094
|
-
return {
|
|
4095
|
-
createCandidate: (input) => runToolExecutionEffect(service.createCandidate(input)),
|
|
4096
|
-
commit: (candidateId) => runToolExecutionEffectSync(service.commit(candidateId)),
|
|
4097
|
-
current: (instanceId, conversationId) => service.current(instanceId, conversationId)
|
|
4098
|
-
};
|
|
4099
|
-
}
|
|
4100
|
-
//#endregion
|
|
4101
|
-
//#region src/adapters/compatibility/tool-execution/public-contract.ts
|
|
4102
|
-
function createInvocationAuthority$1(authority) {
|
|
4103
|
-
return createInvocationAuthority(authority);
|
|
4104
|
-
}
|
|
4105
|
-
function createToolInputDigest(input) {
|
|
4106
|
-
return createToolInputDigest$1(input, createSha256Digest);
|
|
4107
|
-
}
|
|
4108
|
-
function requiresToolApproval(risk) {
|
|
4109
|
-
return requiresToolApproval$1(risk);
|
|
4110
|
-
}
|
|
4111
|
-
//#endregion
|
|
4112
|
-
//#region src/adapters/compatibility/tool-execution/tool-operation-ledger.ts
|
|
4113
|
-
const effectLedger = Symbol("rivus.tool-execution.effect-ledger");
|
|
4114
|
-
function createToolOperationLedger(options = {}) {
|
|
4115
|
-
return adaptEffectToolOperationLedger(createToolOperationLedger$1({
|
|
4116
|
-
...options.initial ? { initial: options.initial } : {},
|
|
4117
|
-
...options.persist ? { persist: (record) => Effect.tryPromise({
|
|
4118
|
-
catch: (error) => error,
|
|
4119
|
-
try: () => options.persist(record)
|
|
4120
|
-
}) } : {}
|
|
4121
|
-
}));
|
|
4122
|
-
}
|
|
4123
|
-
function adaptEffectToolOperationLedger(ledger) {
|
|
4124
|
-
const facade = {
|
|
4125
|
-
abort: (operationId, binding) => runToolExecutionEffect(ledger.abort(operationId, binding)),
|
|
4126
|
-
begin: (operationId, binding) => runToolExecutionEffect(ledger.begin(operationId, binding)),
|
|
4127
|
-
complete: (operationId, binding, result) => runToolExecutionEffect(ledger.complete(operationId, binding, result)),
|
|
4128
|
-
inspect: (operationId, binding) => runToolExecutionEffect(ledger.inspect(operationId, binding)),
|
|
4129
|
-
reconciliationRequired: () => ledger.reconciliationRequired(),
|
|
4130
|
-
reconcile: async (input) => {
|
|
4131
|
-
const action = createRecoveryAction(input.action);
|
|
4132
|
-
return runToolExecutionEffect(ledger.reconcile({
|
|
4133
|
-
...input,
|
|
4134
|
-
action,
|
|
4135
|
-
outcome: input.outcome
|
|
4136
|
-
}));
|
|
4137
|
-
},
|
|
4138
|
-
requireReconciliation: (operationId, binding, reason) => runToolExecutionEffect(ledger.requireReconciliation(operationId, binding, reason)),
|
|
4139
|
-
unresolvedForSource: (sourceMessageId) => ledger.unresolvedForSource(sourceMessageId)
|
|
4140
|
-
};
|
|
4141
|
-
Object.defineProperty(facade, effectLedger, { value: ledger });
|
|
4142
|
-
return Object.freeze(facade);
|
|
4143
|
-
}
|
|
4144
|
-
function toEffectToolOperationLedger(ledger) {
|
|
4145
|
-
if (effectLedger in ledger) return ledger[effectLedger];
|
|
4146
|
-
return {
|
|
4147
|
-
abort: (operationId, binding) => fromPromise(() => ledger.abort(operationId, binding)),
|
|
4148
|
-
begin: (operationId, binding) => fromPromise(() => ledger.begin(operationId, binding)),
|
|
4149
|
-
complete: (operationId, binding, result) => fromPromise(() => ledger.complete(operationId, binding, result)),
|
|
4150
|
-
inspect: (operationId, binding) => fromPromise(() => ledger.inspect(operationId, binding)),
|
|
4151
|
-
reconciliationRequired: () => ledger.reconciliationRequired(),
|
|
4152
|
-
reconcile: (input) => fromPromise(() => ledger.reconcile(input)),
|
|
4153
|
-
requireReconciliation: (operationId, binding, reason) => fromPromise(() => ledger.requireReconciliation(operationId, binding, reason)),
|
|
4154
|
-
unresolvedForSource: (sourceMessageId) => ledger.unresolvedForSource(sourceMessageId)
|
|
4155
|
-
};
|
|
4156
|
-
}
|
|
4157
|
-
function fromPromise(operation) {
|
|
4158
|
-
return Effect.tryPromise({
|
|
4159
|
-
catch: (error) => error,
|
|
4160
|
-
try: operation
|
|
4161
|
-
});
|
|
4162
|
-
}
|
|
4163
|
-
//#endregion
|
|
4164
|
-
export { AGENT_MEMORY_JSONL_VERSION, AgentContextBudgetExceeded, AgentEventHandlerFailed, AgentEventLogStoreError, AgentEventSinkFailed, AgentHarnessBusy, AgentLoopFailed, AgentMemoryError, AgentMemoryRepositoryConflict, AgentRunCancelled, CompactionError, CompactionError as LegacyCompactionError, InvalidInvocationAuthority, InvalidInvocationAuthority as LegacyInvalidInvocationAuthority, InvalidRecoveryAction, InvalidStableJson, InvalidStableJson as LegacyInvalidStableJson, InvalidToolInput, InvalidToolInput as LegacyInvalidToolInput, InvalidWorkspaceRoot, LangfuseTelemetryConfigError, MEMORY_SCOPES, ModelChangeBoundaryDeadlineError, RIVUS_MEMORY_TOOL_ID, RIVUS_MEMORY_TOOL_PLUGIN_ID, RIVUS_MEMORY_TOOL_VERSION, RIVUS_RUNTIME_TOOL_IDS, RivusToolInputRejected, TOOL_OPERATION_JSONL_VERSION, ToolExecutorInputRejected, ToolInvocationDenied, ToolOperationLedgerError, WorkspaceInstructionsSourceError, adaptEffectToolOperationLedger as adaptLegacyEffectToolOperationLedger, assembleAgentContext, buildAgentSessionSnapshot, buildRunSnapshot, createAgentConversationMessages, createAgentDomainEventHandler, createAgentDomainEventSink, createAgentDomainEventSinkFromCallback, createAgentExecutionQueryStore, createAgentHarness, createAgentHarnessClient, createAgentLoopModelExecutionEnd, createAgentLoopModelExecutionStart, createAgentLoopSkillExecutionEnd, createAgentLoopSkillExecutionStart, createAgentLoopTextDelta, createAgentLoopThinkingDelta, createAgentLoopToolExecutionEnd, createAgentLoopToolExecutionStart, createAgentLoopToolExecutionUpdate, createAgentLoopTurnStart, createAgentRunStreams, createAgentRunUpdateHandler, createAgentRuntime, createAgentTranscriptMessages, createAgentTranscriptTurn, createAgentsMdInstructionsSource, createDefaultAgentHarness, createDefaultAgentHarnessClient, createDefaultAgentHarnessClientFromCallback, createDefaultAgentHarnessClientFromTextCallback, createDefaultAgentHarnessFromCallback, createDefaultAgentHarnessFromTextCallback, createDefaultAgentRuntime, createDefaultAgentRuntimeFromCallback, createDefaultAgentRuntimeFromTextCallback, createEffectCompactionService, createEventAgentLoop, createFixedClock, createInMemoryAgentMemoryRepository, createInvocationAuthority, createJsonlAgentEventLog, createLangfuseAgentTelemetry, createAgentHarness$1 as createLegacyAgentHarness, createAgentLoopFromCallback as createLegacyAgentLoopFromCallback, createAgentLoopPromptTransformer as createLegacyAgentLoopPromptTransformer, createAsyncIterableAgentLoop as createLegacyAsyncIterableAgentLoop, createCompactionService as createLegacyCompactionService, createEventAgentLoop$1 as createLegacyEventAgentLoop, createInvocationAuthority$1 as createLegacyInvocationAuthority, createMemoryNamespace as createLegacyMemoryNamespace, createLegacyProjectMemoryPromptPreparer, createLegacyRivusMemoryTool, createLegacyRivusMemoryToolDescriptor, createTextAgentLoop as createLegacyTextAgentLoop, createTextAgentLoopFromCallback as createLegacyTextAgentLoopFromCallback, createToolInputDigest as createLegacyToolInputDigest, createToolOperationLedger as createLegacyToolOperationLedger, createMemoryNamespace$1 as createMemoryNamespace, createMemoryService, createOpenTelemetryAgentEventSink, createOpenTelemetryAgentTelemetry, createPersistedMemoryRecord, createProjectMemoryPromptPreparer, createRecoveryAction, createRivusMemoryTool, createRivusMemoryToolContract, createRivusMemoryToolDescriptor, createRunAdmission, createSequenceRunIds, createSystemClock, createTelemetryContentRedactor, createTestClock, createTextAgentLoop$1 as createTextAgentLoop, createToolBroker, createToolInputDigest$1 as createToolInputDigest, createToolOperationLedger$1 as createToolOperationLedger, createUuidRunIds, createWorkspaceInstructionsResolver, createWorkspaceRootHandle, decodeAgentMemorySnapshots, decodeToolOperationSnapshots, describeLoopError, encodeAgentMemorySnapshot, encodeToolOperationSnapshot, evolveAgentRun, fromEffectAgentLoop as fromEffectLegacyAgentLoop, initialAgentRunState, isAgentToolExecutionEvent, isAssistantTextDeltaEvent, isAssistantThinkingDeltaEvent, isRivusRuntimeToolId, isTerminalAgentDomainEvent, isTerminalAgentRunPhase, normalizeAgentInvocation, normalizeAgentLoopEvent, normalizeStableJson as normalizeLegacyStableJson, normalizeStableJson, normalizeMemoryBinding, notifyListeners, notifyUpdateListeners, openJsonlAgentMemoryRepository, openJsonlToolOperationLedger, projectAgentSessionHistory, remainingUntil, replayAgentHistory, replayAgentTranscript, replayRunUpdates, requiresToolApproval as requiresLegacyToolApproval, requiresToolApproval$1 as requiresToolApproval, resolveInvocationAuthority, resolveLangfuseTelemetryConfig, resolveWorkspaceRootPath, restoreAgentHistory, restorePersistedMemoryRecord, restoreToolOperation as restorePersistedToolOperation, restrictMemoryScopesForAudience as restrictLegacyMemoryScopesForAudience, toDomainEvent, toEffectAgentLoop as toEffectLegacyAgentLoop, toEffectAgentLoopInput as toEffectLegacyAgentLoopInput, toEffectToolOperationLedger as toEffectLegacyToolOperationLedger, toCompatibilityAgentLoopInput as toLegacyAgentLoopInput, toRunUpdate };
|
|
3700
|
+
export { ATTACHMENT_RECOVERY_COMMAND, AgentEventHandlerFailed, AgentEventSinkFailed, AgentLoopFailed, AgentRunCancelled, InvalidInvocationAuthority, ModelChangeBoundaryDeadlineError, RIVUS_MEMORY_TOOL_ID, RIVUS_MEMORY_TOOL_PLUGIN_ID, RIVUS_MEMORY_TOOL_VERSION, RIVUS_RUNTIME_TOOL_IDS, RivusToolInputRejected, ToolExecutorInputRejected, ToolInvocationDenied, createAgentHarness, createAgentsMdInstructionsSource, createInvocationAuthority, createJsonlAgentEventLog, createLangfuseAgentTelemetry, createMemoryService, createProjectMemoryPromptPreparer, createRecoveryAction, createRivusMemoryToolContract, createRivusMemoryToolDescriptor, createRunAdmission, createTelemetryContentRedactor, createToolBroker, createToolInputDigest, createWorkspaceInstructionsResolver, createWorkspaceRootHandle, isRivusRuntimeToolId, normalizeAgentInvocation, openJsonlAgentMemoryRepository, openJsonlToolOperationLedger, remainingUntil, resolveInvocationAuthority, resolveLangfuseTelemetryConfig, restoreAgentHistory };
|
|
3701
|
+
|