@rivus/runtime 0.16.6 → 0.17.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/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { a as requiresToolApproval$1, c as resolveInvocationAuthority, i as normalizeStableJson, l as normalizeAgentInvocation, n as InvalidToolInput, o as InvalidInvocationAuthority, r as createToolInputDigest$1, s as createInvocationAuthority, t as InvalidStableJson, u as RivusToolInputRejected } from "./chunks/tool-input-digest.js";
2
- import { S as normalizeAgentLoopEvent, _ as createAgentLoopToolExecutionStart, a as createTextAgentLoopFromCallback, b as createEventAgentLoop, c as toEffectAgentLoop, d as createAgentLoopModelExecutionStart, f as createAgentLoopSkillExecutionEnd, g as createAgentLoopToolExecutionEnd, h as createAgentLoopThinkingDelta, i as createTextAgentLoop, l as toEffectAgentLoopInput, m as createAgentLoopTextDelta, n as createAsyncIterableAgentLoop, o as fromEffectAgentLoop, p as createAgentLoopSkillExecutionStart, r as createEventAgentLoop$1, s as toCompatibilityAgentLoopInput, t as createAgentLoopFromCallback, u as createAgentLoopModelExecutionEnd, v as createAgentLoopToolExecutionUpdate, x as createTextAgentLoop$1, y as createAgentLoopTurnStart } from "./chunks/agent-loop.js";
3
- import { Cause, Deferred, Effect, Exit, Option, Queue, Stream } from "effect";
4
- import { createHash, randomUUID } from "node:crypto";
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, 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/core/application/agent-execution/context/agent-context-assembler.ts
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 void 0;
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$1(binding) {
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$1(binding),
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 = Array.isArray(memory) ? [...memory] : [memory];
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 = async (id) => {
644
+ const findStoredById = (id) => Effect.gen(function* () {
718
645
  for (const handle of handles) {
719
- const record = await handle.inspect(id);
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 = async (command) => {
727
- rejectUnknown(command, command.command === "search" ? [
728
- "command",
729
- "query",
730
- "scope"
731
- ] : command.command === "propose" ? [
732
- "command",
733
- "input",
734
- "scope"
735
- ] : command.command === "forget_request" ? [
736
- "command",
737
- "id",
738
- "reason"
739
- ] : ["command", "id"]);
740
- switch (command.command) {
741
- case "search": {
742
- const query = readSearchQuery(command.query);
743
- const scope = readOptionalScope(command.scope);
744
- const selected = scope ? [requireScope(byScope, scope)] : handles;
745
- return (await Promise.all(selected.map((handle) => handle.search(query)))).flat();
746
- }
747
- case "read": {
748
- const id = readId(command.id);
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
- return;
754
- }
755
- case "propose": {
756
- const input = readProposeInput(command.input);
757
- const scope = readOptionalScope(command.scope);
758
- if (scope === "shared-user-profile") throw new AgentMemoryError("Shared User Profile changes require trusted confirmation");
759
- const handle = scope ? requireScope(byScope, scope) : byScope.get("agent-private") ?? (handles.length === 1 ? handles[0] : void 0);
760
- if (!handle) throw new AgentMemoryError("memory scope is required when multiple scopes are granted");
761
- if (handle.scope === "shared-user-profile") throw new AgentMemoryError("Shared User Profile changes require trusted confirmation");
762
- return handle.propose({ content: input.content });
763
- }
764
- case "forget_request": {
765
- const id = readId(command.id);
766
- const stored = await findStoredById(id);
767
- if (!stored) throw new AgentMemoryError(`memory not found: ${id}`);
768
- if (stored.handle.scope === "shared-user-profile" || stored.handle.scope === "project" || stored.record.state !== "proposed") throw new AgentMemoryError("Only proposed private Memory can be forgotten by the model; confirmed or project-shared Memory requires trusted control");
769
- return toTombstoneReceipt(await stored.handle.forgetRequest({
770
- expectedRevision: stored.record.revision,
771
- id,
772
- ...command.reason === void 0 ? {} : { reason: readReason(command.reason) }
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: async (command, completedResult) => {
781
- const input = readCommand(command);
782
- if (input.command === "search" || input.command === "read") return execute(input);
783
- const id = readCompletedMemoryId(completedResult);
784
- const stored = await findStoredById(id);
785
- if (!stored) throw new AgentMemoryError(`completed Memory operation references missing Memory: ${id}`);
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 void 0;
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
- async function asToolInputRejection(operation) {
872
- try {
873
- return await operation();
874
- } catch (error) {
875
- if (error instanceof AgentMemoryError) throw new RivusToolInputRejected(error.message);
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 = 8 * 1024;
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 async (input) => {
889
- const invocationIdentity = (input.invocation ? normalizeAgentInvocation(input.invocation) : void 0)?.memory;
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 = (await options.memory.bind({
894
- agentId: options.agentId,
895
- projectId: options.projectId,
896
- scope: "project",
897
- subjectId: identity.subjectId,
898
- tenantId: identity.tenantId
899
- }).search({ query: "" })).filter((record) => record.state === "confirmed").sort((left, right) => left.id.localeCompare(right.id)).slice(0, maxRecords);
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 void 0;
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 void 0;
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 void 0;
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 processor = new BatchSpanProcessor(new OTLPTraceExporter({
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
@@ -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* () {
2148
+ closed = true;
2149
+ return Array.from(yield* Queue.takeAll(queue)).map(toText);
2150
+ }),
2151
+ closeInput: () => Effect.gen(function* () {
2202
2152
  closed = true;
2203
2153
  return Array.from(yield* Queue.takeAll(queue));
2204
2154
  }),
2205
- push: (text) => Effect.sync(() => !closed && Queue.unsafeOffer(queue, text))
2155
+ push: (input) => Effect.sync(() => !closed && Queue.unsafeOffer(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: new 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,6 +2233,7 @@ 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({
@@ -2292,12 +2269,14 @@ function createAgentHarness(options) {
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,17 +2288,20 @@ 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),
@@ -2394,14 +2376,21 @@ function createAgentHarness(options) {
2394
2376
  updates
2395
2377
  };
2396
2378
  }).pipe(Effect.onInterrupt(() => recordInterruptedRun), Effect.ensuring(Effect.sync(() => {
2397
- if (!settled && !cancellation.abortController.signal.aborted) cancellation.abortController.abort({
2398
- reason: interruptionReason,
2399
- runId,
2400
- sessionKey: command.sessionKey
2401
- });
2402
- activeRun = void 0;
2403
- activeCancellation = void 0;
2404
- activeRunState = void 0;
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* () {
@@ -2418,10 +2407,12 @@ function createAgentHarness(options) {
2418
2407
  }
2419
2408
  return completed;
2420
2409
  });
2421
- const requestSteering = (runId, text) => Effect.gen(function* () {
2422
- const normalized = text.trim();
2423
- if (!normalized || !options.loop.supportsSteering || !activeRun || activeRun.runId !== runId || !activeCancellation || activeCancellation.requested) return false;
2424
- return yield* activeCancellation.steering.push(normalized);
2410
+ const requestSteering = (runId, text) => requestSteeringInput(runId, text);
2411
+ const requestSteeringInput = (runId, input) => Effect.gen(function* () {
2412
+ const normalized = typeof input === "string" ? input.trim() : input;
2413
+ if (typeof normalized === "string" && !normalized || typeof normalized !== "string" && options.loop.supportsStructuredSteering !== true || !options.loop.supportsSteering || !activeRun || activeRun.runId !== runId || !activeCancellation || activeCancellation.requested) return false;
2414
+ const bound = bindAttachmentAccessInput(normalized, activeCancellation);
2415
+ return yield* activeCancellation.steering.push(cloneAgentSteeringInput(bound));
2425
2416
  });
2426
2417
  const requestSessionCancellation = (sessionKey, runId, reason) => {
2427
2418
  if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
@@ -2431,6 +2422,10 @@ function createAgentHarness(options) {
2431
2422
  if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
2432
2423
  return requestSteering(runId, text);
2433
2424
  };
2425
+ const requestSessionSteeringInput = (sessionKey, runId, input) => {
2426
+ if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
2427
+ return requestSteeringInput(runId, input);
2428
+ };
2434
2429
  const requestSessionActiveCancellation = (sessionKey, reason) => {
2435
2430
  if (!activeRun || activeRun.sessionKey !== sessionKey) return Effect.succeed(false);
2436
2431
  return requestCancellation(activeRun.runId, reason);
@@ -2446,10 +2441,12 @@ function createAgentHarness(options) {
2446
2441
  }),
2447
2442
  cancelRun: requestCancellation,
2448
2443
  steerRun: requestSteering,
2444
+ steerRunInput: requestSteeringInput,
2449
2445
  forSession: (sessionKey) => ({
2450
2446
  cancelActiveRun: (reason) => requestSessionActiveCancellation(sessionKey, reason),
2451
2447
  cancelRun: (runId, reason) => requestSessionCancellation(sessionKey, runId, reason),
2452
2448
  steerRun: (runId, text) => requestSessionSteering(sessionKey, runId, text),
2449
+ steerRunInput: (runId, input) => requestSessionSteeringInput(sessionKey, runId, input),
2453
2450
  getActiveRun: () => getSessionActiveRun(sessionKey),
2454
2451
  getActiveRunState: () => getSessionActiveRunState(sessionKey),
2455
2452
  getAvailability: () => getSessionAvailability(sessionKey),
@@ -2673,50 +2670,9 @@ function abortError(signal) {
2673
2670
  return signal.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("Run admission aborted");
2674
2671
  }
2675
2672
  //#endregion
2676
- //#region src/core/application/memory/compaction/compaction-service.ts
2677
- var CompactionError = class extends Error {
2678
- name = "CompactionError";
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
- };
2673
+ //#region src/adapters/agent/memory/persisted-memory-record.ts
2674
+ function restorePersistedMemoryRecord(snapshot) {
2675
+ return restoreMemoryRecord(snapshot);
2720
2676
  }
2721
2677
  //#endregion
2722
2678
  //#region src/adapters/outbound/persistence/memory/agent-memory-repository-contract.ts
@@ -2730,9 +2686,6 @@ function resolveAgentMemoryUpdate(previous, next) {
2730
2686
  if (!previous.validateTransitionTo(next)) throw new Error("memory revision or transition conflict");
2731
2687
  return next;
2732
2688
  }
2733
- //#endregion
2734
- //#region src/adapters/outbound/persistence/memory/agent-memory-snapshot-codec.ts
2735
- const AGENT_MEMORY_JSONL_VERSION = 1;
2736
2689
  function encodeAgentMemorySnapshot(snapshot) {
2737
2690
  return JSON.stringify({
2738
2691
  snapshot,
@@ -2756,7 +2709,7 @@ function decodeAgentMemorySnapshots(raw) {
2756
2709
  } catch {
2757
2710
  throw invalidSnapshot(index);
2758
2711
  }
2759
- const key = `${createMemoryNamespace$1(record.binding)}\u0000${record.id}`;
2712
+ const key = `${createMemoryNamespace(record.binding)}\u0000${record.id}`;
2760
2713
  const previous = latest.get(key);
2761
2714
  try {
2762
2715
  if (previous) resolveAgentMemoryUpdate(previous, record);
@@ -2777,7 +2730,7 @@ function createInMemoryAgentMemoryRepository(options = {}) {
2777
2730
  const records = /* @__PURE__ */ new Map();
2778
2731
  for (const snapshot of options.initial ?? []) {
2779
2732
  const restored = restorePersistedAgentMemoryRecord(snapshot);
2780
- const namespace = createMemoryNamespace$1(restored.binding);
2733
+ const namespace = createMemoryNamespace(restored.binding);
2781
2734
  const bucket = records.get(namespace) ?? /* @__PURE__ */ new Map();
2782
2735
  if (bucket.has(restored.id)) throw new AgentMemoryRepositoryConflict(`duplicate initial memory: ${restored.id}`);
2783
2736
  bucket.set(restored.id, restored);
@@ -2785,8 +2738,8 @@ function createInMemoryAgentMemoryRepository(options = {}) {
2785
2738
  }
2786
2739
  const serial = Effect.unsafeMakeSemaphore(1);
2787
2740
  return {
2788
- get: (binding, id) => Effect.sync(() => records.get(createMemoryNamespace$1(binding))?.get(id)),
2789
- list: (binding) => Effect.sync(() => [...records.get(createMemoryNamespace$1(binding))?.values() ?? []]),
2741
+ get: (binding, id) => Effect.sync(() => records.get(createMemoryNamespace(binding))?.get(id)),
2742
+ list: (binding) => Effect.sync(() => [...records.get(createMemoryNamespace(binding))?.values() ?? []]),
2790
2743
  save: (snapshotInput) => serial.withPermits(1)(Effect.uninterruptible(Effect.suspend(() => {
2791
2744
  let record;
2792
2745
  try {
@@ -2794,7 +2747,7 @@ function createInMemoryAgentMemoryRepository(options = {}) {
2794
2747
  } catch {
2795
2748
  return Effect.fail(new AgentMemoryRepositoryConflict("memory revision or transition conflict"));
2796
2749
  }
2797
- const namespace = createMemoryNamespace$1(record.binding);
2750
+ const namespace = createMemoryNamespace(record.binding);
2798
2751
  const bucket = records.get(namespace) ?? /* @__PURE__ */ new Map();
2799
2752
  const previous = bucket.get(record.id);
2800
2753
  try {
@@ -3222,7 +3175,7 @@ function restoreToolOperation(snapshot) {
3222
3175
  var ToolOperationLedgerError = class extends Error {
3223
3176
  name = "ToolOperationLedgerError";
3224
3177
  };
3225
- function createToolOperationLedger$1(options = {}) {
3178
+ function createToolOperationLedger(options = {}) {
3226
3179
  const records = /* @__PURE__ */ new Map();
3227
3180
  for (const snapshot of options.initial ?? []) {
3228
3181
  const operation = restoreToolOperation(snapshot);
@@ -3330,7 +3283,7 @@ var ToolInvocationDenied = class extends Error {
3330
3283
  name = "ToolInvocationDenied";
3331
3284
  };
3332
3285
  function createToolBroker(options) {
3333
- const operations = options.operations ?? createToolOperationLedger$1();
3286
+ const operations = options.operations ?? createToolOperationLedger();
3334
3287
  const hostTools = new Map(options.hostTools?.map((tool) => [tool.id, tool]) ?? []);
3335
3288
  if (hostTools.size !== (options.hostTools?.length ?? 0)) throw new ToolInvocationDenied("duplicate Host Tool id");
3336
3289
  return { execute: (request) => Effect.gen(function* () {
@@ -3341,8 +3294,8 @@ function createToolBroker(options) {
3341
3294
  const policy = yield* options.policy.current();
3342
3295
  if (policy.revokedToolIds.includes(request.toolId)) return yield* Effect.fail(new ToolInvocationDenied(`tool has been revoked: ${request.toolId}`));
3343
3296
  if (prepared.tool.idempotency === "required" && !request.operationId) return yield* Effect.fail(new ToolInvocationDenied(`tool requires a stable operation id: ${request.toolId}`));
3344
- if (requiresToolApproval$1(prepared.tool.risk) && !request.operationId) return yield* Effect.fail(new ToolInvocationDenied(`tool approval requires a stable operation id: ${request.toolId}`));
3345
- if (requiresToolApproval$1(prepared.tool.risk) && !request.approvalId) return yield* Effect.fail(new ToolInvocationDenied(`tool requires trusted approval: ${request.toolId}`));
3297
+ if (requiresToolApproval(prepared.tool.risk) && !request.operationId) return yield* Effect.fail(new ToolInvocationDenied(`tool approval requires a stable operation id: ${request.toolId}`));
3298
+ if (requiresToolApproval(prepared.tool.risk) && !request.approvalId) return yield* Effect.fail(new ToolInvocationDenied(`tool requires trusted approval: ${request.toolId}`));
3346
3299
  const binding = yield* Effect.try({
3347
3300
  catch: (error) => error,
3348
3301
  try: () => createOperationBinding(prepared.authority, prepared.tool, request.input, options.digest)
@@ -3354,7 +3307,7 @@ function createToolBroker(options) {
3354
3307
  if (inspected.status === "completed") return yield* replayCompleted(inspected.result);
3355
3308
  if (inspected.status === "blocked") return yield* Effect.fail(new ToolInvocationDenied(`tool operation is fenced: ${inspected.reason}`));
3356
3309
  }
3357
- if (requiresToolApproval$1(prepared.tool.risk)) {
3310
+ if (requiresToolApproval(prepared.tool.risk)) {
3358
3311
  if (!(yield* options.approvals.consume({
3359
3312
  agentId: prepared.authority.agentId,
3360
3313
  approvalId: request.approvalId,
@@ -3405,7 +3358,7 @@ function prepareInvocation(hostTools, catalog, request) {
3405
3358
  function createOperationBinding(authority, tool, input, digest) {
3406
3359
  let inputDigest;
3407
3360
  try {
3408
- inputDigest = createToolInputDigest$1(input, digest);
3361
+ inputDigest = createToolInputDigest(input, digest);
3409
3362
  } catch (error) {
3410
3363
  if (error instanceof InvalidToolInput) throw new ToolInvocationDenied(`tool input is not stable JSON: ${tool.id}`);
3411
3364
  throw error;
@@ -3461,9 +3414,6 @@ const RIVUS_RUNTIME_TOOL_IDS = Object.freeze([
3461
3414
  function isRivusRuntimeToolId(value) {
3462
3415
  return RIVUS_RUNTIME_TOOL_IDS.includes(value);
3463
3416
  }
3464
- //#endregion
3465
- //#region src/adapters/outbound/persistence/tool-operation/tool-operation-snapshot-codec.ts
3466
- const TOOL_OPERATION_JSONL_VERSION = 1;
3467
3417
  function encodeToolOperationSnapshot(record) {
3468
3418
  return JSON.stringify({
3469
3419
  record,
@@ -3503,7 +3453,7 @@ function openJsonlToolOperationLedger(options) {
3503
3453
  if (recovered !== operation) yield* persist(options.filePath, recovered.toSnapshot());
3504
3454
  initial.push(recovered.toSnapshot());
3505
3455
  }
3506
- return createToolOperationLedger$1({
3456
+ return createToolOperationLedger({
3507
3457
  initial,
3508
3458
  persist: (record) => persist(options.filePath, record)
3509
3459
  });
@@ -3748,417 +3698,5 @@ function readDate(value, field, lineNumber) {
3748
3698
  return date;
3749
3699
  }
3750
3700
  //#endregion
3751
- //#region src/testing/fakes.ts
3752
- function createFixedClock(now) {
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 };
3701
+ 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 };
3702
+