@tangle-network/agent-knowledge 19.0.2 → 19.1.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/CHANGELOG.md +6 -0
- package/dist/{index-eDsIXWyM.d.ts → index-Bh9wLd0_.d.ts} +64 -3
- package/dist/index-Bh9wLd0_.d.ts.map +1 -0
- package/dist/index.d.ts +87 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +182 -2
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +2 -2
- package/dist/memory/index.js +2 -2
- package/dist/{memory-BYWNir2t.js → memory-PlYkyv8x.js} +430 -56
- package/dist/memory-PlYkyv8x.js.map +1 -0
- package/docs/hindsight-memory.md +126 -0
- package/docs/qmd-retrieval.md +60 -0
- package/package.json +1 -1
- package/dist/index-eDsIXWyM.d.ts.map +0 -1
- package/dist/memory-BYWNir2t.js.map +0 -1
package/dist/memory/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { At as AgentMemoryScope, Bt as RetrievalHoldoutSessionState, Dt as AgentMemoryContext, Et as AgentMemoryBranchIsolation, Ft as RetrievalHoldoutCallContext, It as RetrievalHoldoutConfig, Lt as RetrievalHoldoutEligibleItem, Mt as AgentMemoryWriteInput, Nt as AgentMemoryWriteResult, Ot as AgentMemoryHit, Pt as RetrievalHoldoutBypassReason, Rt as RetrievalHoldoutEvent, St as acquireAgentMemoryRunLease, Tt as AgentMemoryAdapter, bt as AgentMemoryRunLease, jt as AgentMemorySearchOptions, kt as AgentMemoryKind, vt as AgentMemoryAcquireRunLease, xt as OwnedAgentMemoryRunLease, yt as AgentMemoryControllerMode, zt as RetrievalHoldoutResult } from "../index-DZeFm-BP.js";
|
|
2
|
-
import { $ as
|
|
3
|
-
export { AgentMemoryAcquireRunLease, type AgentMemoryActivation, type AgentMemoryActivationDriver, AgentMemoryAdapter, type AgentMemoryAttemptEvent, AgentMemoryBranch, AgentMemoryBranchIsolation, AgentMemoryBranchLifetime, AgentMemoryBranchSnapshot, AgentMemoryContext, AgentMemoryControllerMode, type AgentMemoryDimensionComparison, type AgentMemoryEvidenceRef, type AgentMemoryExecutionContext, type AgentMemoryExecutionCostMeter, type AgentMemoryExecutionCostReceipt, type AgentMemoryExecutionPaidCallInput, type AgentMemoryExecutionPaidCallResult, type AgentMemoryExecutionStep, type AgentMemoryExperimentCandidate, type AgentMemoryExperimentCandidateRef, type AgentMemoryExperimentComparisonRef, type AgentMemoryExperimentRankingRow, type AgentMemoryExperimentRunLease, type AgentMemoryFinalEvaluation, type AgentMemoryFinalPair, type AgentMemoryForgettingComparison, AgentMemoryHit, AgentMemoryHitSchema, type AgentMemoryImprovementRunLease, AgentMemoryJournalEntry, AgentMemoryKind, AgentMemoryKindSchema, type AgentMemoryLearningArmOrder, type AgentMemoryLearningCandidateSummary, type AgentMemoryLearningCellComparison, type AgentMemoryLearningComparison, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, type AgentMemoryMode, type AgentMemoryPromotionDecision, AgentMemoryRunLease, AgentMemoryScope, AgentMemoryScopeSchema, AgentMemorySearchOptions, type AgentMemorySequence, type AgentMemorySequenceArtifact, type AgentMemorySequenceProbe, type AgentMemorySequenceProbeResult, type AgentMemorySequenceScenario, type AgentMemorySequenceStep, AgentMemorySharingPolicy, type AgentMemoryTransferCellComparison, type AgentMemoryTransferStepSummary, AgentMemoryVisibility, AgentMemoryWriteInput, AgentMemoryWriteInputSchema, AgentMemoryWriteResult, type BuildAgentMemorySequencesFromBenchmarkCasesOptions, type CompareAgentMemoryLearningOptions, CreateAgentMemoryBranchOptions, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, ForkAgentMemoryBranchSnapshotOptions, GraphitiMcpClientLike, GraphitiMemoryAdapterOptions, GraphitiToolNames, Mem0ClientMode, Mem0HostedClient, Mem0HostedMemoryAdapterOptions, Mem0MemoryAdapterOptions, Mem0OssClient, Mem0OssMemoryAdapterOptions, type MemoryConfigScenario, Neo4jAgentMemoryAdapterOptions, OwnedAgentMemoryRunLease, RetrievalHoldoutBypassReason, RetrievalHoldoutCallContext, RetrievalHoldoutConfig, RetrievalHoldoutEligibleItem, RetrievalHoldoutEvent, RetrievalHoldoutOffPolicyOptions, RetrievalHoldoutOffPolicyResult, RetrievalHoldoutResult, RetrievalHoldoutSessionState, RetrievalHoldoutSessionSummary, type RunAgentMemoryExperimentOptions, type RunAgentMemoryExperimentResult, type RunAgentMemoryImprovementOptions, type RunAgentMemoryImprovementResult, type RunAgentMemoryLearningExperimentOptions, type RunAgentMemoryLearningExperimentResult, acquireAgentMemoryRunLease, agentMemorySequenceJudge, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, compareAgentMemoryLearning, createAgentMemoryBranch, createGraphitiMemoryAdapter, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, defaultGetMemoryContext, deterministicRng, emitRetrievalHoldoutBypass, forkAgentMemoryBranchSnapshot, graphitiMemoryAdapterIdentity, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, renderMemoryContext, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, retrievalHoldoutConfigHash, runAgentMemoryExperiment, runAgentMemoryImprovement, runAgentMemoryLearningExperiment, runBoundedMemoryLifecycle, sleepForMemoryRecovery, toOffPolicyTrajectory };
|
|
2
|
+
import { $ as hindsightMemoryBankId, $t as forkAgentMemoryBranchSnapshot, A as AgentMemoryActivationDriver, At as AgentMemorySequence, B as RetrievalHoldoutOffPolicyResult, Bt as RunAgentMemoryExperimentOptions, C as createMemoryExecutionPool, Ct as AgentMemoryExperimentRunLease, D as sleepForMemoryRecovery, Dt as AgentMemoryLearningCellComparison, E as runBoundedMemoryLifecycle, Et as AgentMemoryLearningCandidateSummary, F as AgentMemoryPromotionDecision, Ft as AgentMemorySequenceStep, G as emitRetrievalHoldoutBypass, Gt as AgentMemoryBranchLifetime, H as applyRetrievalHoldout, Ht as RunAgentMemoryLearningExperimentOptions, I as MemoryConfigScenario, It as AgentMemoryTransferCellComparison, J as toOffPolicyTrajectory, Jt as AgentMemorySharingPolicy, K as resetRetrievalHoldoutRegistry, Kt as AgentMemoryBranchSnapshot, L as RunAgentMemoryImprovementOptions, Lt as AgentMemoryTransferStepSummary, M as AgentMemoryFinalEvaluation, Mt as AgentMemorySequenceProbe, N as AgentMemoryFinalPair, Nt as AgentMemorySequenceProbeResult, O as runAgentMemoryImprovement, Ot as AgentMemoryLearningComparison, P as AgentMemoryImprovementRunLease, Pt as AgentMemorySequenceScenario, Q as createHindsightMemoryAdapter, Qt as createAgentMemoryBranch, R as RunAgentMemoryImprovementResult, Rt as BuildAgentMemorySequencesFromBenchmarkCasesOptions, S as DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, St as AgentMemoryExperimentRankingRow, T as resolveMemoryCleanupTimeoutMs, Tt as AgentMemoryLearningArmOrder, U as applySessionStickyRetrievalHoldout, Ut as RunAgentMemoryLearningExperimentResult, V as RetrievalHoldoutSessionSummary, Vt as RunAgentMemoryExperimentResult, W as deterministicRng, Wt as AgentMemoryBranch, X as HindsightMemoryAdapterOptions, Xt as CreateAgentMemoryBranchOptions, Y as HindsightClientLike, Yt as AgentMemoryVisibility, Z as HindsightOperationUnknownError, Zt as ForkAgentMemoryBranchSnapshotOptions, _ as Mem0OssMemoryAdapterOptions, _t as AgentMemoryExecutionPaidCallResult, a as memoryWriteResultToSourceRecord, at as runAgentMemoryExperiment, b as AgentMemoryLifecycleTimeoutError, bt as AgentMemoryExperimentCandidateRef, c as AgentMemoryScopeSchema, ct as agentMemorySequenceJudge, d as createNeo4jAgentMemoryAdapter, dt as AgentMemoryAttemptEvent, en as defaultGetMemoryContext, et as GraphitiMcpClientLike, f as Mem0ClientMode, ft as AgentMemoryEvidenceRef, g as Mem0OssClient, gt as AgentMemoryExecutionPaidCallInput, h as Mem0MemoryAdapterOptions, ht as AgentMemoryExecutionCostReceipt, i as memoryHitToSourceRecord, it as graphitiMemoryAdapterIdentity, j as AgentMemoryDimensionComparison, jt as AgentMemorySequenceArtifact, k as AgentMemoryActivation, kt as AgentMemoryMode, l as AgentMemoryWriteInputSchema, lt as buildAgentMemorySequenceScenarios, m as Mem0HostedMemoryAdapterOptions, mt as AgentMemoryExecutionCostMeter, n as PlayMemoryRetrievalReceipt, nt as GraphitiToolNames, o as AgentMemoryHitSchema, ot as compareAgentMemoryLearning, p as Mem0HostedClient, pt as AgentMemoryExecutionContext, q as retrievalHoldoutConfigHash, qt as AgentMemoryJournalEntry, r as createPlayMemoryTools, rt as createGraphitiMemoryAdapter, s as AgentMemoryKindSchema, st as runAgentMemoryLearningExperiment, t as CreatePlayMemoryToolsOptions, tn as renderMemoryContext, tt as GraphitiMemoryAdapterOptions, u as Neo4jAgentMemoryAdapterOptions, ut as buildAgentMemorySequencesFromBenchmarkCases, v as createMem0MemoryAdapter, vt as AgentMemoryExecutionStep, w as memoryRecoveryDelayMs, wt as AgentMemoryForgettingComparison, x as AgentMemoryLifecycleUnsafeError, xt as AgentMemoryExperimentComparisonRef, y as mem0MemoryAdapterIdentity, yt as AgentMemoryExperimentCandidate, z as RetrievalHoldoutOffPolicyOptions, zt as CompareAgentMemoryLearningOptions } from "../index-Bh9wLd0_.js";
|
|
3
|
+
export { AgentMemoryAcquireRunLease, type AgentMemoryActivation, type AgentMemoryActivationDriver, AgentMemoryAdapter, type AgentMemoryAttemptEvent, AgentMemoryBranch, AgentMemoryBranchIsolation, AgentMemoryBranchLifetime, AgentMemoryBranchSnapshot, AgentMemoryContext, AgentMemoryControllerMode, type AgentMemoryDimensionComparison, type AgentMemoryEvidenceRef, type AgentMemoryExecutionContext, type AgentMemoryExecutionCostMeter, type AgentMemoryExecutionCostReceipt, type AgentMemoryExecutionPaidCallInput, type AgentMemoryExecutionPaidCallResult, type AgentMemoryExecutionStep, type AgentMemoryExperimentCandidate, type AgentMemoryExperimentCandidateRef, type AgentMemoryExperimentComparisonRef, type AgentMemoryExperimentRankingRow, type AgentMemoryExperimentRunLease, type AgentMemoryFinalEvaluation, type AgentMemoryFinalPair, type AgentMemoryForgettingComparison, AgentMemoryHit, AgentMemoryHitSchema, type AgentMemoryImprovementRunLease, AgentMemoryJournalEntry, AgentMemoryKind, AgentMemoryKindSchema, type AgentMemoryLearningArmOrder, type AgentMemoryLearningCandidateSummary, type AgentMemoryLearningCellComparison, type AgentMemoryLearningComparison, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, type AgentMemoryMode, type AgentMemoryPromotionDecision, AgentMemoryRunLease, AgentMemoryScope, AgentMemoryScopeSchema, AgentMemorySearchOptions, type AgentMemorySequence, type AgentMemorySequenceArtifact, type AgentMemorySequenceProbe, type AgentMemorySequenceProbeResult, type AgentMemorySequenceScenario, type AgentMemorySequenceStep, AgentMemorySharingPolicy, type AgentMemoryTransferCellComparison, type AgentMemoryTransferStepSummary, AgentMemoryVisibility, AgentMemoryWriteInput, AgentMemoryWriteInputSchema, AgentMemoryWriteResult, type BuildAgentMemorySequencesFromBenchmarkCasesOptions, type CompareAgentMemoryLearningOptions, CreateAgentMemoryBranchOptions, CreatePlayMemoryToolsOptions, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, ForkAgentMemoryBranchSnapshotOptions, GraphitiMcpClientLike, GraphitiMemoryAdapterOptions, GraphitiToolNames, HindsightClientLike, HindsightMemoryAdapterOptions, HindsightOperationUnknownError, Mem0ClientMode, Mem0HostedClient, Mem0HostedMemoryAdapterOptions, Mem0MemoryAdapterOptions, Mem0OssClient, Mem0OssMemoryAdapterOptions, type MemoryConfigScenario, Neo4jAgentMemoryAdapterOptions, OwnedAgentMemoryRunLease, PlayMemoryRetrievalReceipt, RetrievalHoldoutBypassReason, RetrievalHoldoutCallContext, RetrievalHoldoutConfig, RetrievalHoldoutEligibleItem, RetrievalHoldoutEvent, RetrievalHoldoutOffPolicyOptions, RetrievalHoldoutOffPolicyResult, RetrievalHoldoutResult, RetrievalHoldoutSessionState, RetrievalHoldoutSessionSummary, type RunAgentMemoryExperimentOptions, type RunAgentMemoryExperimentResult, type RunAgentMemoryImprovementOptions, type RunAgentMemoryImprovementResult, type RunAgentMemoryLearningExperimentOptions, type RunAgentMemoryLearningExperimentResult, acquireAgentMemoryRunLease, agentMemorySequenceJudge, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, compareAgentMemoryLearning, createAgentMemoryBranch, createGraphitiMemoryAdapter, createHindsightMemoryAdapter, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, createPlayMemoryTools, defaultGetMemoryContext, deterministicRng, emitRetrievalHoldoutBypass, forkAgentMemoryBranchSnapshot, graphitiMemoryAdapterIdentity, hindsightMemoryBankId, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, renderMemoryContext, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, retrievalHoldoutConfigHash, runAgentMemoryExperiment, runAgentMemoryImprovement, runAgentMemoryLearningExperiment, runBoundedMemoryLifecycle, sleepForMemoryRecovery, toOffPolicyTrajectory };
|
package/dist/memory/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as retrievalHoldoutConfigHash, C as defaultGetMemoryContext, D as deterministicRng, E as applySessionStickyRetrievalHoldout, O as emitRetrievalHoldoutBypass, S as forkAgentMemoryBranchSnapshot, T as applyRetrievalHoldout, _ as runAgentMemoryExperiment, a as runAgentMemoryImprovement, b as buildAgentMemorySequencesFromBenchmarkCases, c as hindsightMemoryBankId, d as AgentMemoryScopeSchema, f as AgentMemoryWriteInputSchema, g as runAgentMemoryLearningExperiment, h as compareAgentMemoryLearning, i as mem0MemoryAdapterIdentity, j as toOffPolicyTrajectory, k as resetRetrievalHoldoutRegistry, l as AgentMemoryHitSchema, m as graphitiMemoryAdapterIdentity, n as createNeo4jAgentMemoryAdapter, o as HindsightOperationUnknownError, p as createGraphitiMemoryAdapter, r as createMem0MemoryAdapter, s as createHindsightMemoryAdapter, t as createPlayMemoryTools, u as AgentMemoryKindSchema, v as agentMemorySequenceJudge, w as renderMemoryContext, x as createAgentMemoryBranch, y as buildAgentMemorySequenceScenarios } from "../memory-PlYkyv8x.js";
|
|
2
2
|
import { C as sleepForMemoryRecovery, S as runBoundedMemoryLifecycle, U as memoryHitToSourceRecord, W as memoryWriteResultToSourceRecord, b as memoryRecoveryDelayMs, f as acquireAgentMemoryRunLease, h as DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, m as AgentMemoryLifecycleUnsafeError, p as AgentMemoryLifecycleTimeoutError, x as resolveMemoryCleanupTimeoutMs, y as createMemoryExecutionPool } from "../benchmarks-B3kU-Yxz.js";
|
|
3
|
-
export { AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, AgentMemoryScopeSchema, AgentMemoryWriteInputSchema, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, acquireAgentMemoryRunLease, agentMemorySequenceJudge, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, compareAgentMemoryLearning, createAgentMemoryBranch, createGraphitiMemoryAdapter, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, defaultGetMemoryContext, deterministicRng, emitRetrievalHoldoutBypass, forkAgentMemoryBranchSnapshot, graphitiMemoryAdapterIdentity, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, renderMemoryContext, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, retrievalHoldoutConfigHash, runAgentMemoryExperiment, runAgentMemoryImprovement, runAgentMemoryLearningExperiment, runBoundedMemoryLifecycle, sleepForMemoryRecovery, toOffPolicyTrajectory };
|
|
3
|
+
export { AgentMemoryHitSchema, AgentMemoryKindSchema, AgentMemoryLifecycleTimeoutError, AgentMemoryLifecycleUnsafeError, AgentMemoryScopeSchema, AgentMemoryWriteInputSchema, DEFAULT_MEMORY_CLEANUP_TIMEOUT_MS, HindsightOperationUnknownError, acquireAgentMemoryRunLease, agentMemorySequenceJudge, applyRetrievalHoldout, applySessionStickyRetrievalHoldout, buildAgentMemorySequenceScenarios, buildAgentMemorySequencesFromBenchmarkCases, compareAgentMemoryLearning, createAgentMemoryBranch, createGraphitiMemoryAdapter, createHindsightMemoryAdapter, createMem0MemoryAdapter, createMemoryExecutionPool, createNeo4jAgentMemoryAdapter, createPlayMemoryTools, defaultGetMemoryContext, deterministicRng, emitRetrievalHoldoutBypass, forkAgentMemoryBranchSnapshot, graphitiMemoryAdapterIdentity, hindsightMemoryBankId, mem0MemoryAdapterIdentity, memoryHitToSourceRecord, memoryRecoveryDelayMs, memoryWriteResultToSourceRecord, renderMemoryContext, resetRetrievalHoldoutRegistry, resolveMemoryCleanupTimeoutMs, retrievalHoldoutConfigHash, runAgentMemoryExperiment, runAgentMemoryImprovement, runAgentMemoryLearningExperiment, runBoundedMemoryLifecycle, sleepForMemoryRecovery, toOffPolicyTrajectory };
|
|
@@ -6,6 +6,7 @@ import { canonicalJson, comparePairedArms, mulberry32 } from "@tangle-network/ag
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { assertCampaignSplitIdentity, canonicalDigest, compareOptimizationMethods, createRunCostLedger, fsCampaignStorage, heldoutSignificance, resolveRunDir, runCampaign, surfaceHash } from "@tangle-network/agent-eval/campaign";
|
|
8
8
|
import { pairArms } from "@tangle-network/agent-eval/experiment";
|
|
9
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
9
10
|
//#region src/immutable-ref.ts
|
|
10
11
|
const SHA256_REF = /^sha256:[a-f0-9]{64}$/;
|
|
11
12
|
const GIT_REF = /^git:[a-f0-9]{40}$/;
|
|
@@ -3537,6 +3538,337 @@ function graphitiMemoryAdapterIdentity(options) {
|
|
|
3537
3538
|
return `sha256:${sha256(canonicalJson(stripUndefined(options)))}`;
|
|
3538
3539
|
}
|
|
3539
3540
|
//#endregion
|
|
3541
|
+
//#region src/memory/json.ts
|
|
3542
|
+
/** Optional object properties are absent on the wire; other unsupported values still fail. */
|
|
3543
|
+
function canonicalMemoryJson(value) {
|
|
3544
|
+
return canonicalJson(omitUndefinedProperties(value));
|
|
3545
|
+
}
|
|
3546
|
+
function omitUndefinedProperties(value) {
|
|
3547
|
+
if (Array.isArray(value)) return value.map(omitUndefinedProperties);
|
|
3548
|
+
if (value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) return Object.fromEntries(Object.entries(value).filter(([, child]) => child !== void 0).map(([key, child]) => [key, omitUndefinedProperties(child)]));
|
|
3549
|
+
return value;
|
|
3550
|
+
}
|
|
3551
|
+
//#endregion
|
|
3552
|
+
//#region src/memory/schemas.ts
|
|
3553
|
+
const AgentMemoryKindSchema = z.enum([
|
|
3554
|
+
"message",
|
|
3555
|
+
"entity",
|
|
3556
|
+
"fact",
|
|
3557
|
+
"preference",
|
|
3558
|
+
"observation",
|
|
3559
|
+
"reasoning-trace"
|
|
3560
|
+
]);
|
|
3561
|
+
const AgentMemoryScopeSchema = z.object({
|
|
3562
|
+
tenantId: z.string().optional(),
|
|
3563
|
+
userId: z.string().optional(),
|
|
3564
|
+
agentId: z.string().optional(),
|
|
3565
|
+
teamId: z.string().optional(),
|
|
3566
|
+
runId: z.string().optional(),
|
|
3567
|
+
sessionId: z.string().optional(),
|
|
3568
|
+
namespace: z.string().optional(),
|
|
3569
|
+
tags: z.record(z.string(), z.string()).optional()
|
|
3570
|
+
});
|
|
3571
|
+
const AgentMemoryHitSchema = z.object({
|
|
3572
|
+
id: z.string().min(1),
|
|
3573
|
+
uri: z.string().min(1),
|
|
3574
|
+
kind: AgentMemoryKindSchema,
|
|
3575
|
+
text: z.string().min(1),
|
|
3576
|
+
title: z.string().optional(),
|
|
3577
|
+
score: z.number().optional(),
|
|
3578
|
+
normalizedScore: z.number().optional(),
|
|
3579
|
+
confidence: z.number().optional(),
|
|
3580
|
+
createdAt: z.string().optional(),
|
|
3581
|
+
validUntil: z.string().optional(),
|
|
3582
|
+
lastVerifiedAt: z.string().optional(),
|
|
3583
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
3584
|
+
});
|
|
3585
|
+
const AgentMemoryWriteInputSchema = z.object({
|
|
3586
|
+
kind: AgentMemoryKindSchema,
|
|
3587
|
+
text: z.string().min(1),
|
|
3588
|
+
id: z.string().optional(),
|
|
3589
|
+
title: z.string().optional(),
|
|
3590
|
+
role: z.enum([
|
|
3591
|
+
"system",
|
|
3592
|
+
"user",
|
|
3593
|
+
"assistant",
|
|
3594
|
+
"tool"
|
|
3595
|
+
]).optional(),
|
|
3596
|
+
entityName: z.string().optional(),
|
|
3597
|
+
entityType: z.string().optional(),
|
|
3598
|
+
category: z.string().optional(),
|
|
3599
|
+
predicate: z.string().optional(),
|
|
3600
|
+
subject: z.string().optional(),
|
|
3601
|
+
object: z.string().optional(),
|
|
3602
|
+
confidence: z.number().min(0).max(1).optional(),
|
|
3603
|
+
scope: AgentMemoryScopeSchema.optional(),
|
|
3604
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
3605
|
+
});
|
|
3606
|
+
//#endregion
|
|
3607
|
+
//#region src/memory/hindsight.ts
|
|
3608
|
+
var HindsightOperationUnknownError = class extends Error {
|
|
3609
|
+
bankId;
|
|
3610
|
+
operationId;
|
|
3611
|
+
documentId;
|
|
3612
|
+
constructor(bankId, operationId, documentId, options) {
|
|
3613
|
+
super("Hindsight retain is unresolved; retry the same write id and bytes to reconcile it before checkpointing", options);
|
|
3614
|
+
this.bankId = bankId;
|
|
3615
|
+
this.operationId = operationId;
|
|
3616
|
+
this.documentId = documentId;
|
|
3617
|
+
this.name = "HindsightOperationUnknownError";
|
|
3618
|
+
}
|
|
3619
|
+
};
|
|
3620
|
+
const operationSchema = z.object({
|
|
3621
|
+
operation_id: z.string(),
|
|
3622
|
+
status: z.enum([
|
|
3623
|
+
"pending",
|
|
3624
|
+
"processing",
|
|
3625
|
+
"completed",
|
|
3626
|
+
"failed",
|
|
3627
|
+
"cancelled",
|
|
3628
|
+
"not_found"
|
|
3629
|
+
])
|
|
3630
|
+
});
|
|
3631
|
+
const documentSchema = z.object({
|
|
3632
|
+
id: z.string(),
|
|
3633
|
+
bank_id: z.string(),
|
|
3634
|
+
original_text: z.string().nullable(),
|
|
3635
|
+
document_metadata: z.record(z.string(), z.unknown()).nullable().optional()
|
|
3636
|
+
});
|
|
3637
|
+
const recallSchema = z.object({
|
|
3638
|
+
results: z.array(z.object({
|
|
3639
|
+
id: z.string().min(1),
|
|
3640
|
+
text: z.string(),
|
|
3641
|
+
type: z.string().nullable().optional(),
|
|
3642
|
+
document_id: z.string().nullable().optional(),
|
|
3643
|
+
chunk_id: z.string().nullable().optional(),
|
|
3644
|
+
metadata: z.record(z.string(), z.string()).nullable().optional(),
|
|
3645
|
+
source_fact_ids: z.array(z.string()).nullable().optional(),
|
|
3646
|
+
scores: z.object({ final: z.number().nullable().optional() }).passthrough().nullable().optional()
|
|
3647
|
+
})),
|
|
3648
|
+
source_facts: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
3649
|
+
source_facts_truncated: z.boolean().nullable().optional()
|
|
3650
|
+
});
|
|
3651
|
+
/** Dedicated bank identity includes the entire logical scope, including the existing branch partition. */
|
|
3652
|
+
function hindsightMemoryBankId(input) {
|
|
3653
|
+
if (!input.backendRef.trim() || !input.branchId.trim()) throw new Error("Hindsight requires backendRef and branchId");
|
|
3654
|
+
if (!input.scope.namespace?.trim()) throw new Error("Hindsight memory requires an explicit stable play scope.namespace");
|
|
3655
|
+
if (input.scope.tags?.memoryBranchId !== input.branchId) throw new Error("Hindsight memory scope must belong to its bound AgentMemoryBranch");
|
|
3656
|
+
return `ak-${sha256(canonicalMemoryJson(input))}`;
|
|
3657
|
+
}
|
|
3658
|
+
/** Hindsight 0.10.2 adapter. Snapshots remain accepted-input journals, never provider database snapshots. */
|
|
3659
|
+
function createHindsightMemoryAdapter(options) {
|
|
3660
|
+
if (!options.backendRef?.trim() || !options.branchId?.trim()) throw new Error("Hindsight requires backendRef and branchId");
|
|
3661
|
+
const requestTimeoutMs = bounded(options.requestTimeoutMs ?? 15e3, 3e5, "requestTimeoutMs");
|
|
3662
|
+
const ingestionTimeoutMs = bounded(options.ingestionTimeoutMs ?? 12e4, 6e5, "ingestionTimeoutMs");
|
|
3663
|
+
const pollIntervalMs = bounded(options.pollIntervalMs ?? 1e3, 3e4, "pollIntervalMs");
|
|
3664
|
+
const maxTextChars = bounded(options.maxTextChars ?? 8e3, 1e5, "maxTextChars");
|
|
3665
|
+
const maxTokens = bounded(options.recallMaxTokens ?? 1e3, 16e3, "recallMaxTokens");
|
|
3666
|
+
const id = `hindsight-0.10.2:${sha256(options.backendRef)}`;
|
|
3667
|
+
const unresolved = /* @__PURE__ */ new Map();
|
|
3668
|
+
let version;
|
|
3669
|
+
async function request(method, path, body, timeoutMs = requestTimeoutMs) {
|
|
3670
|
+
const abortController = new AbortController();
|
|
3671
|
+
const response = await runBoundedMemoryLifecycle({
|
|
3672
|
+
operation: `Hindsight ${method} ${path}`,
|
|
3673
|
+
timeoutMs,
|
|
3674
|
+
resource: options.client,
|
|
3675
|
+
abortController,
|
|
3676
|
+
run: () => options.client.request({
|
|
3677
|
+
method,
|
|
3678
|
+
path,
|
|
3679
|
+
...body === void 0 ? {} : { body },
|
|
3680
|
+
signal: abortController.signal
|
|
3681
|
+
})
|
|
3682
|
+
});
|
|
3683
|
+
if (response.status !== 404 && (response.status < 200 || response.status >= 300)) throw new Error(`Hindsight ${method} failed with HTTP ${response.status}`);
|
|
3684
|
+
return response;
|
|
3685
|
+
}
|
|
3686
|
+
async function checkVersion() {
|
|
3687
|
+
version ??= (async () => {
|
|
3688
|
+
const response = await request("GET", "/version");
|
|
3689
|
+
const parsed = z.object({ api_version: z.literal("0.10.2") }).safeParse(response.body);
|
|
3690
|
+
if (response.status !== 200 || !parsed.success) throw new Error("Hindsight adapter requires the qualified 0.10.2 API");
|
|
3691
|
+
})();
|
|
3692
|
+
await version;
|
|
3693
|
+
}
|
|
3694
|
+
function bank(scope) {
|
|
3695
|
+
return hindsightMemoryBankId({
|
|
3696
|
+
backendRef: options.backendRef,
|
|
3697
|
+
branchId: options.branchId,
|
|
3698
|
+
scope: scope ?? {}
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3701
|
+
function path(bankId, suffix) {
|
|
3702
|
+
return `/v1/default/banks/${encodeURIComponent(bankId)}${suffix}`;
|
|
3703
|
+
}
|
|
3704
|
+
async function readDocument(bankId, documentId) {
|
|
3705
|
+
const response = await request("GET", path(bankId, `/documents/${encodeURIComponent(documentId)}`));
|
|
3706
|
+
return response.status === 404 ? null : documentSchema.parse(response.body);
|
|
3707
|
+
}
|
|
3708
|
+
async function readOperation(bankId, operationId, timeoutMs = requestTimeoutMs) {
|
|
3709
|
+
const response = await request("GET", path(bankId, `/operations/${operationId}`), void 0, timeoutMs);
|
|
3710
|
+
if (response.status === 404) return {
|
|
3711
|
+
operation_id: operationId,
|
|
3712
|
+
status: "not_found"
|
|
3713
|
+
};
|
|
3714
|
+
const operation = operationSchema.parse(response.body);
|
|
3715
|
+
if (operation.operation_id !== operationId) throw new Error("Hindsight returned another operation identity");
|
|
3716
|
+
return operation;
|
|
3717
|
+
}
|
|
3718
|
+
const adapter = {
|
|
3719
|
+
id,
|
|
3720
|
+
branchIsolation: {
|
|
3721
|
+
mode: "instance",
|
|
3722
|
+
branchId: options.branchId,
|
|
3723
|
+
supportsLogicalScopes: true
|
|
3724
|
+
},
|
|
3725
|
+
async search(query, searchOptions = {}) {
|
|
3726
|
+
const bankId = bank(searchOptions.scope);
|
|
3727
|
+
if (!query.trim()) throw new Error("Hindsight recall requires a nonempty query");
|
|
3728
|
+
const limit = searchOptions.limit ?? 10;
|
|
3729
|
+
if (!Number.isSafeInteger(limit) || limit < 0 || limit > 100) throw new Error("Hindsight recall limit must be between 0 and 100");
|
|
3730
|
+
if (searchOptions.minScore !== void 0 && !Number.isFinite(searchOptions.minScore)) throw new Error("Hindsight minScore must be finite");
|
|
3731
|
+
if (limit === 0) return [];
|
|
3732
|
+
await checkVersion();
|
|
3733
|
+
const response = await request("POST", path(bankId, "/memories/recall"), {
|
|
3734
|
+
query,
|
|
3735
|
+
budget: "low",
|
|
3736
|
+
max_tokens: maxTokens,
|
|
3737
|
+
include: {
|
|
3738
|
+
entities: null,
|
|
3739
|
+
source_facts: { max_tokens: maxTokens }
|
|
3740
|
+
}
|
|
3741
|
+
});
|
|
3742
|
+
if (response.status === 404) return [];
|
|
3743
|
+
const result = recallSchema.parse(response.body);
|
|
3744
|
+
return result.results.map((hit) => ({
|
|
3745
|
+
id: hit.id,
|
|
3746
|
+
uri: `hindsight://${bankId}/memories/${encodeURIComponent(hit.id)}`,
|
|
3747
|
+
kind: hit.type === "world" ? "fact" : "observation",
|
|
3748
|
+
text: hit.text,
|
|
3749
|
+
...hit.scores?.final == null ? {} : { score: hit.scores.final },
|
|
3750
|
+
metadata: {
|
|
3751
|
+
provider: "hindsight",
|
|
3752
|
+
backendRef: options.backendRef,
|
|
3753
|
+
bankId,
|
|
3754
|
+
branchId: options.branchId,
|
|
3755
|
+
providerFactType: hit.type ?? null,
|
|
3756
|
+
documentId: hit.document_id ?? null,
|
|
3757
|
+
chunkId: hit.chunk_id ?? null,
|
|
3758
|
+
provenance: hit.metadata ?? null,
|
|
3759
|
+
sourceFactIds: hit.source_fact_ids ?? [],
|
|
3760
|
+
sourceFacts: Object.fromEntries((hit.source_fact_ids ?? []).flatMap((key) => result.source_facts?.[key] === void 0 ? [] : [[key, result.source_facts[key]]])),
|
|
3761
|
+
sourceFactsTruncated: result.source_facts_truncated ?? null,
|
|
3762
|
+
evidenceStatus: "provider-derived; source attribution is not independent validation"
|
|
3763
|
+
}
|
|
3764
|
+
})).filter((hit) => (!searchOptions.kinds?.length || searchOptions.kinds.includes(hit.kind)) && (searchOptions.minScore === void 0 || hit.score !== void 0 && hit.score >= searchOptions.minScore)).slice(0, limit);
|
|
3765
|
+
},
|
|
3766
|
+
async getContext(query, searchOptions) {
|
|
3767
|
+
return defaultGetMemoryContext(adapter, query, searchOptions);
|
|
3768
|
+
},
|
|
3769
|
+
async write(raw) {
|
|
3770
|
+
const input = AgentMemoryWriteInputSchema.parse(raw);
|
|
3771
|
+
if (!input.id?.trim()) throw new Error("Hindsight writes require a stable caller id");
|
|
3772
|
+
if (input.text.length > maxTextChars) throw new Error(`Hindsight write exceeds ${maxTextChars} characters`);
|
|
3773
|
+
const bankId = bank(input.scope);
|
|
3774
|
+
const documentId = `ak-${sha256(input.id)}`;
|
|
3775
|
+
const operationId = operationUuid(`${bankId}:${documentId}`);
|
|
3776
|
+
const identity = `${bankId}:${operationId}`;
|
|
3777
|
+
const { scope, ...sourceInput } = input;
|
|
3778
|
+
const inputDigest = sha256(canonicalMemoryJson(sourceInput));
|
|
3779
|
+
const expectedMetadata = {
|
|
3780
|
+
ak_input_sha256: inputDigest,
|
|
3781
|
+
ak_scope_sha256: sha256(canonicalMemoryJson(scope)),
|
|
3782
|
+
ak_source: canonicalMemoryJson(sourceInput)
|
|
3783
|
+
};
|
|
3784
|
+
const verifyDocument = (document) => {
|
|
3785
|
+
if (!document || document.id !== documentId || document.bank_id !== bankId || document.original_text !== input.text || document.document_metadata?.ak_input_sha256 !== inputDigest || document.document_metadata?.ak_scope_sha256 !== expectedMetadata.ak_scope_sha256) throw new Error("Hindsight document identity or bytes differ from this stable write id");
|
|
3786
|
+
};
|
|
3787
|
+
await checkVersion();
|
|
3788
|
+
const prior = await readDocument(bankId, documentId);
|
|
3789
|
+
if (prior) verifyDocument(prior);
|
|
3790
|
+
let operation = await readOperation(bankId, operationId);
|
|
3791
|
+
if (prior && operation.status === "not_found") {
|
|
3792
|
+
const unknown = new HindsightOperationUnknownError(bankId, operationId, documentId);
|
|
3793
|
+
unresolved.set(identity, unknown);
|
|
3794
|
+
throw unknown;
|
|
3795
|
+
}
|
|
3796
|
+
const unknown = new HindsightOperationUnknownError(bankId, operationId, documentId);
|
|
3797
|
+
unresolved.set(identity, unknown);
|
|
3798
|
+
const deadline = Date.now() + ingestionTimeoutMs;
|
|
3799
|
+
try {
|
|
3800
|
+
if (operation.status === "not_found") {
|
|
3801
|
+
const submitted = await request("POST", path(bankId, "/memories"), {
|
|
3802
|
+
async: true,
|
|
3803
|
+
operation_id: operationId,
|
|
3804
|
+
items: [{
|
|
3805
|
+
content: input.text,
|
|
3806
|
+
document_id: documentId,
|
|
3807
|
+
metadata: expectedMetadata,
|
|
3808
|
+
tags: ["source:agent-knowledge"],
|
|
3809
|
+
observation_scopes: "shared",
|
|
3810
|
+
context: "Retained agent input. Claims of success or correctness remain attributed claims, not verified findings."
|
|
3811
|
+
}]
|
|
3812
|
+
});
|
|
3813
|
+
if (!z.object({
|
|
3814
|
+
success: z.literal(true),
|
|
3815
|
+
bank_id: z.literal(bankId),
|
|
3816
|
+
async: z.literal(true),
|
|
3817
|
+
operation_id: z.literal(operationId)
|
|
3818
|
+
}).parse(submitted.body).success) throw new Error("Hindsight rejected retain");
|
|
3819
|
+
}
|
|
3820
|
+
while (operation.status !== "completed") {
|
|
3821
|
+
const remaining = deadline - Date.now();
|
|
3822
|
+
if (remaining <= 0) throw unknown;
|
|
3823
|
+
operation = await readOperation(bankId, operationId, Math.min(requestTimeoutMs, remaining));
|
|
3824
|
+
if (operation.status === "failed" || operation.status === "cancelled") throw new Error(`Hindsight retain is ${operation.status}; possible partial provider state requires inspection`);
|
|
3825
|
+
if (operation.status !== "completed") await setTimeout$1(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
|
|
3826
|
+
}
|
|
3827
|
+
verifyDocument(await readDocument(bankId, documentId));
|
|
3828
|
+
unresolved.delete(identity);
|
|
3829
|
+
return accepted("completed");
|
|
3830
|
+
} catch (cause) {
|
|
3831
|
+
throw new HindsightOperationUnknownError(bankId, operationId, documentId, { cause });
|
|
3832
|
+
}
|
|
3833
|
+
function accepted(operationStatus) {
|
|
3834
|
+
unresolved.delete(identity);
|
|
3835
|
+
const result = {
|
|
3836
|
+
accepted: true,
|
|
3837
|
+
id: input.id,
|
|
3838
|
+
uri: `hindsight://${bankId}/documents/${documentId}`,
|
|
3839
|
+
kind: input.kind,
|
|
3840
|
+
metadata: {
|
|
3841
|
+
provider: "hindsight",
|
|
3842
|
+
bankId,
|
|
3843
|
+
branchId: options.branchId,
|
|
3844
|
+
operationId,
|
|
3845
|
+
documentId,
|
|
3846
|
+
inputDigest,
|
|
3847
|
+
operationStatus,
|
|
3848
|
+
cost: "unmeasured"
|
|
3849
|
+
}
|
|
3850
|
+
};
|
|
3851
|
+
return {
|
|
3852
|
+
...result,
|
|
3853
|
+
sourceRecord: memoryWriteResultToSourceRecord(result, input.text, { scope })
|
|
3854
|
+
};
|
|
3855
|
+
}
|
|
3856
|
+
},
|
|
3857
|
+
async flush() {
|
|
3858
|
+
if (unresolved.size) throw unresolved.values().next().value;
|
|
3859
|
+
}
|
|
3860
|
+
};
|
|
3861
|
+
return adapter;
|
|
3862
|
+
}
|
|
3863
|
+
function operationUuid(value) {
|
|
3864
|
+
const hex = sha256(value);
|
|
3865
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-8${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
3866
|
+
}
|
|
3867
|
+
function bounded(value, max, name) {
|
|
3868
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > max) throw new Error(`Hindsight ${name} must be an integer between 1 and ${max}`);
|
|
3869
|
+
return value;
|
|
3870
|
+
}
|
|
3871
|
+
//#endregion
|
|
3540
3872
|
//#region src/memory/improvement/candidate.ts
|
|
3541
3873
|
async function buildCandidate(options, config, hash) {
|
|
3542
3874
|
const id = `memory-config-${hash}`;
|
|
@@ -5344,61 +5676,103 @@ function stringMetadata(metadata, key) {
|
|
|
5344
5676
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
5345
5677
|
}
|
|
5346
5678
|
//#endregion
|
|
5347
|
-
//#region src/memory/
|
|
5348
|
-
const
|
|
5349
|
-
|
|
5350
|
-
"
|
|
5351
|
-
"
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
"
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
}
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5679
|
+
//#region src/memory/tools.ts
|
|
5680
|
+
const publications = /* @__PURE__ */ new WeakMap();
|
|
5681
|
+
function createPlayMemoryTools(options) {
|
|
5682
|
+
if (!options.actorId?.trim()) throw new Error("play memory tools require a trusted actorId");
|
|
5683
|
+
if (typeof options.onCheckpoint !== "function") throw new Error("play memory tools require durable checkpoint publication");
|
|
5684
|
+
const maxTextChars = options.maxTextChars ?? 8e3;
|
|
5685
|
+
const maxResults = options.maxResults ?? 20;
|
|
5686
|
+
if (!Number.isSafeInteger(maxTextChars) || maxTextChars < 1 || maxTextChars > 1e5 || !Number.isSafeInteger(maxResults) || maxResults < 1 || maxResults > 100) throw new Error("invalid play memory tool bounds");
|
|
5687
|
+
const prefix = options.namePrefix ?? "";
|
|
5688
|
+
if (!/^[a-zA-Z0-9_-]*$/.test(prefix)) throw new Error("invalid memory tool namePrefix");
|
|
5689
|
+
const recall = z.strictObject({
|
|
5690
|
+
question: z.string().trim().min(1).max(8e3),
|
|
5691
|
+
limit: z.int().min(1).max(maxResults).optional()
|
|
5692
|
+
});
|
|
5693
|
+
const record = z.strictObject({
|
|
5694
|
+
id: z.string().trim().min(1).max(256),
|
|
5695
|
+
kind: AgentMemoryKindSchema,
|
|
5696
|
+
text: z.string().min(1).max(maxTextChars),
|
|
5697
|
+
title: z.string().max(512).optional(),
|
|
5698
|
+
sourceRefs: z.array(z.string().min(1).max(2048)).max(50).optional()
|
|
5699
|
+
});
|
|
5700
|
+
return [tool(`${prefix}memory_recall`, "Recall memory visible to this play. Returned memories are attributed provider evidence, not independently verified findings.", recall, async (input) => {
|
|
5701
|
+
const context = await options.branch.getContext(input.question, { limit: input.limit ?? maxResults });
|
|
5702
|
+
const content = {
|
|
5703
|
+
branchId: options.branch.branchId,
|
|
5704
|
+
adapterId: options.branch.id,
|
|
5705
|
+
actorId: options.actorId,
|
|
5706
|
+
query: input.question,
|
|
5707
|
+
context
|
|
5708
|
+
};
|
|
5709
|
+
const receipt = {
|
|
5710
|
+
...content,
|
|
5711
|
+
receiptDigest: `sha256:${sha256(canonicalMemoryJson(content))}`
|
|
5712
|
+
};
|
|
5713
|
+
await options.recordRetrieval?.(receipt);
|
|
5714
|
+
return {
|
|
5715
|
+
...context,
|
|
5716
|
+
receipt
|
|
5717
|
+
};
|
|
5718
|
+
}), tool(`${prefix}memory_record`, "Retain a sourced observation in this play and checkpoint its accepted input. Reuse the same id and bytes after an ambiguous response.", record, async (input) => {
|
|
5719
|
+
const write = {
|
|
5720
|
+
id: input.id,
|
|
5721
|
+
kind: input.kind,
|
|
5722
|
+
text: input.text,
|
|
5723
|
+
...input.title === void 0 ? {} : { title: input.title },
|
|
5724
|
+
metadata: {
|
|
5725
|
+
actorId: options.actorId,
|
|
5726
|
+
sourceRefs: input.sourceRefs ?? []
|
|
5727
|
+
}
|
|
5728
|
+
};
|
|
5729
|
+
let state = publications.get(options.branch);
|
|
5730
|
+
if (!state) {
|
|
5731
|
+
state = { tail: Promise.resolve() };
|
|
5732
|
+
publications.set(options.branch, state);
|
|
5733
|
+
}
|
|
5734
|
+
const shared = state;
|
|
5735
|
+
const publication = shared.tail.catch(() => void 0).then(async () => {
|
|
5736
|
+
if (shared.pending && canonicalMemoryJson(shared.pending.input) !== canonicalMemoryJson(write)) throw new Error("reconcile the prior memory write with its same id, bytes, and actor before another write");
|
|
5737
|
+
if (!shared.pending) {
|
|
5738
|
+
const existing = (await options.branch.snapshot()).journal.find((entry) => entry.input.id === input.id);
|
|
5739
|
+
if (existing && canonicalMemoryJson(existing.input) !== canonicalMemoryJson(write)) throw new Error("memory write id already names different content or attribution");
|
|
5740
|
+
shared.pending = {
|
|
5741
|
+
input: write,
|
|
5742
|
+
...existing ? { result: existing.result } : {}
|
|
5743
|
+
};
|
|
5744
|
+
}
|
|
5745
|
+
const result = shared.pending.result ?? await options.branch.write(write);
|
|
5746
|
+
shared.pending.result = result;
|
|
5747
|
+
if (!result.accepted) {
|
|
5748
|
+
shared.pending = void 0;
|
|
5749
|
+
return {
|
|
5750
|
+
...result,
|
|
5751
|
+
checkpointDigest: null
|
|
5752
|
+
};
|
|
5753
|
+
}
|
|
5754
|
+
const snapshot = await options.branch.snapshot();
|
|
5755
|
+
await options.onCheckpoint(snapshot);
|
|
5756
|
+
shared.pending = void 0;
|
|
5757
|
+
return {
|
|
5758
|
+
...result,
|
|
5759
|
+
checkpointDigest: snapshot.digest
|
|
5760
|
+
};
|
|
5761
|
+
});
|
|
5762
|
+
shared.tail = publication;
|
|
5763
|
+
return publication;
|
|
5764
|
+
})];
|
|
5765
|
+
}
|
|
5766
|
+
function tool(name, description, inputSchema, handler) {
|
|
5767
|
+
return {
|
|
5768
|
+
name,
|
|
5769
|
+
description,
|
|
5770
|
+
inputSchema,
|
|
5771
|
+
inputSchemaJson: z.toJSONSchema(inputSchema),
|
|
5772
|
+
handler: async (input) => handler(inputSchema.parse(input))
|
|
5773
|
+
};
|
|
5774
|
+
}
|
|
5401
5775
|
//#endregion
|
|
5402
|
-
export {
|
|
5776
|
+
export { retrievalHoldoutConfigHash as A, defaultGetMemoryContext as C, deterministicRng as D, applySessionStickyRetrievalHoldout as E, scenarioContentFingerprint as F, assertImmutableRef as I, jsonCandidateCodec as M, jsonObjectCandidateCodec as N, emitRetrievalHoldoutBypass as O, runSerializedKnowledgeOptimization as P, forkAgentMemoryBranchSnapshot as S, applyRetrievalHoldout as T, runAgentMemoryExperiment as _, runAgentMemoryImprovement as a, buildAgentMemorySequencesFromBenchmarkCases as b, hindsightMemoryBankId as c, AgentMemoryScopeSchema as d, AgentMemoryWriteInputSchema as f, runAgentMemoryLearningExperiment as g, compareAgentMemoryLearning as h, mem0MemoryAdapterIdentity as i, toOffPolicyTrajectory as j, resetRetrievalHoldoutRegistry as k, AgentMemoryHitSchema as l, graphitiMemoryAdapterIdentity as m, createNeo4jAgentMemoryAdapter as n, HindsightOperationUnknownError as o, createGraphitiMemoryAdapter as p, createMem0MemoryAdapter as r, createHindsightMemoryAdapter as s, createPlayMemoryTools as t, AgentMemoryKindSchema as u, agentMemorySequenceJudge as v, renderMemoryContext as w, createAgentMemoryBranch as x, buildAgentMemorySequenceScenarios as y };
|
|
5403
5777
|
|
|
5404
|
-
//# sourceMappingURL=memory-
|
|
5778
|
+
//# sourceMappingURL=memory-PlYkyv8x.js.map
|