@yielded/agent-storage-memory 0.1.0-beta.185 → 0.1.0-beta.187
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/MemoryMessageDeliveryStore.d.mts +2 -2
- package/dist/MemoryMessageDeliveryStore.mjs +6 -2
- package/dist/MemoryMessageDeliveryStore.mjs.map +1 -1
- package/dist/MemoryScheduleStore.d.mts +1 -1
- package/dist/MemoryScheduleStore.mjs +5 -1
- package/dist/MemoryScheduleStore.mjs.map +1 -1
- package/dist/MemorySemanticIndex.d.mts +2 -1
- package/dist/MemorySemanticIndex.mjs +6 -2
- package/dist/MemorySemanticIndex.mjs.map +1 -1
- package/dist/MemorySubmissionLedger.d.mts +5 -2
- package/dist/MemorySubmissionLedger.mjs +16 -2
- package/dist/MemorySubmissionLedger.mjs.map +1 -1
- package/dist/MemorySubscriptionStore.d.mts +1 -1
- package/dist/MemorySubscriptionStore.mjs +6 -1
- package/dist/MemorySubscriptionStore.mjs.map +1 -1
- package/dist/MemoryThreadStore.d.mts +3 -2
- package/dist/MemoryThreadStore.mjs +13 -3
- package/dist/MemoryThreadStore.mjs.map +1 -1
- package/dist/{MemoryThreadStoreKernel-h_k2t46J.d.mts → MemoryThreadStoreKernel-C2TdTwEU.d.mts} +4 -2
- package/dist/{WorkSelection-CmqTuws3.mjs → WorkSelection-CiJrnfOf.mjs} +2 -2
- package/dist/WorkSelection-CiJrnfOf.mjs.map +1 -0
- package/package.json +1 -1
- package/src/MemoryMessageDeliveryStore.ts +5 -1
- package/src/MemoryScheduleStore.ts +5 -1
- package/src/MemorySemanticIndex.ts +6 -2
- package/src/MemorySubmissionLedger.ts +15 -17
- package/src/MemorySubscriptionStore.ts +6 -1
- package/src/MemoryThreadStore.ts +12 -14
- package/src/internal/MemoryThreadStoreKernel.ts +3 -1
- package/dist/WorkSelection-CmqTuws3.mjs.map +0 -1
package/dist/{MemoryThreadStoreKernel-h_k2t46J.d.mts → MemoryThreadStoreKernel-C2TdTwEU.d.mts}
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
2
|
import { RunId, SubmissionId, ThreadId, ToolCallId } from "@yielded/agent/identifiers";
|
|
3
3
|
import { SubmissionSnapshot, WorkerLedgerState } from "@yielded/agent/submission-ledger";
|
|
4
4
|
import { PreparedImportPage, ThreadDeliveryImportReader, ThreadImportReader, ThreadImportRejected } from "@yielded/agent/thread-import";
|
|
5
5
|
import { AppendRequest, AppendResult, ThreadAdmission, ThreadExportSnapshot, ThreadStoreError, ThreadStoreFailure, ThreadTail } from "@yielded/agent/thread-store";
|
|
6
6
|
import { ThreadWorkEntry, WorkThreadsPage, WorkThreadsRequest } from "@yielded/agent/thread-work";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
7
8
|
import { RecordEnvelope, RecordId } from "@yielded/agent/records";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
8
10
|
import { StorageOwner } from "@yielded/agent/run-storage";
|
|
9
11
|
import { TransferFacts, TransferSection } from "@yielded/agent/thread-transfer";
|
|
10
12
|
import { IdempotencyKey } from "@yielded/agent/receipt";
|
|
@@ -82,4 +84,4 @@ declare const MemoryThreadStoreKernel_base: Context.ServiceClass<MemoryThreadSto
|
|
|
82
84
|
declare class MemoryThreadStoreKernel extends MemoryThreadStoreKernel_base {}
|
|
83
85
|
//#endregion
|
|
84
86
|
export { MemoryThreadStoreKernel as t };
|
|
85
|
-
//# sourceMappingURL=MemoryThreadStoreKernel-
|
|
87
|
+
//# sourceMappingURL=MemoryThreadStoreKernel-C2TdTwEU.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
2
|
//#region src/internal/MemoryThreadStoreKernel.ts
|
|
3
3
|
/** One journal's private mutation boundary, shared with its paired ledger and delivery store. */
|
|
4
4
|
var MemoryThreadStoreKernel = class extends Context.Service()("@effect-agent/storage-memory/internal/MemoryThreadStoreKernel") {};
|
|
@@ -28,4 +28,4 @@ const boundedWorkSelection = (limit, key, after) => {
|
|
|
28
28
|
//#endregion
|
|
29
29
|
export { MemoryThreadStoreKernel as n, boundedWorkSelection as t };
|
|
30
30
|
|
|
31
|
-
//# sourceMappingURL=WorkSelection-
|
|
31
|
+
//# sourceMappingURL=WorkSelection-CiJrnfOf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkSelection-CiJrnfOf.mjs","names":[],"sources":["../src/internal/MemoryThreadStoreKernel.ts","../src/internal/WorkSelection.ts"],"sourcesContent":["import type { RunId, SubmissionId, ThreadId, ToolCallId } from \"@yielded/agent/identifiers\";\nimport type { IdempotencyKey } from \"@yielded/agent/receipt\";\nimport type { RecordEnvelope, RecordId } from \"@yielded/agent/records\";\nimport type { StorageOwner } from \"@yielded/agent/run-storage\";\nimport type { SubmissionSnapshot, WorkerLedgerState } from \"@yielded/agent/submission-ledger\";\nimport type {\n PreparedImportPage,\n ThreadImportReader,\n ThreadDeliveryImportReader,\n ThreadImportRejected,\n} from \"@yielded/agent/thread-import\";\nimport type {\n AppendResult,\n AppendRequest,\n ThreadStoreFailure,\n ThreadTail,\n ThreadAdmission,\n ThreadStoreError,\n ThreadExportSnapshot,\n} from \"@yielded/agent/thread-store\";\nimport type { TransferFacts, TransferSection } from \"@yielded/agent/thread-transfer\";\nimport type {\n ThreadWorkEntry,\n WorkThreadsRequest,\n WorkThreadsPage,\n} from \"@yielded/agent/thread-work\";\nimport * as Context from \"effect/Context\";\nimport type * as Effect from \"effect/Effect\";\nimport type * as Stream from \"effect/Stream\";\n\nexport interface PreparedMemoryAppend {\n readonly request: AppendRequest;\n readonly batchJson: string;\n}\n\n/** Private storage, not a whole-Thread preparation value. Publication callbacks never yield. */\nexport interface MemoryLedgerImport {\n readonly reader: Pick<ThreadImportReader[\"Service\"], \"admission\" | \"runOwner\" | \"commands\">;\n readonly stage: (\n page: PreparedImportPage,\n ) => Effect.Effect<void, ThreadImportRejected | ThreadStoreError>;\n readonly prepareCommit: (\n workerSeal?: Pick<WorkerLedgerState, \"terminal\">,\n ) => Effect.Effect<() => void, ThreadImportRejected | ThreadStoreError, ThreadImportReader>;\n}\n\nexport interface MemoryLedgerTransfer {\n readonly snapshot: (threadId: ThreadId) => Effect.Effect<\n Omit<typeof ThreadExportSnapshot.Type, \"deliveries\"> & {\n readonly idle: boolean;\n readonly workerSeal?: Pick<WorkerLedgerState, \"terminal\">;\n },\n ThreadStoreError\n >;\n readonly facts: (\n threadId: ThreadId,\n section: Exclude<TransferSection, \"deliveries\">,\n after: string | undefined,\n ) => Effect.Effect<{ readonly facts: TransferFacts; readonly after: string }, ThreadStoreError>;\n readonly startImport: (\n threadId: ThreadId,\n ) => Effect.Effect<MemoryLedgerImport, ThreadImportRejected | ThreadStoreError>;\n readonly submissions: (threadId: ThreadId) => Stream.Stream<SubmissionSnapshot, ThreadStoreError>;\n readonly admission: (\n threadId: ThreadId,\n submissionId: SubmissionId,\n ) => Effect.Effect<ThreadAdmission | undefined, ThreadStoreError>;\n readonly commands: ThreadImportReader[\"Service\"][\"commands\"];\n}\n\nexport interface MemoryDeliveryImport {\n readonly record: ThreadImportReader[\"Service\"][\"delivery\"];\n readonly stage: (\n page: PreparedImportPage,\n ) => Effect.Effect<void, ThreadImportRejected | ThreadStoreError>;\n readonly has: (messageId: IdempotencyKey) => boolean;\n readonly prepareCommit: () => Effect.Effect<\n () => void,\n ThreadImportRejected | ThreadStoreError,\n ThreadDeliveryImportReader\n >;\n}\n\nexport interface MemoryDeliveryTransfer {\n readonly record: (\n threadId: ThreadId,\n messageId: IdempotencyKey,\n ) => ReturnType<ThreadImportReader[\"Service\"][\"delivery\"]>;\n readonly snapshot: (threadId: ThreadId) => {\n readonly idle: boolean;\n readonly deliveries: number;\n };\n readonly facts: (\n threadId: ThreadId,\n after: string | undefined,\n ) => Effect.Effect<{ readonly facts: TransferFacts; readonly after: string }, ThreadStoreError>;\n readonly startImport: (\n threadId: ThreadId,\n ) => Effect.Effect<MemoryDeliveryImport, ThreadImportRejected | ThreadStoreError>;\n readonly peerCount: (threadId: ThreadId, nowMillis: number, limit: number) => number;\n}\n\n/** Native control metadata only; callers already hold the journal's shared gate. */\nexport interface MemoryWorkOwner {\n readonly page: (\n threadId: ThreadId,\n after: string | undefined,\n limit: number,\n ) => Effect.Effect<\n {\n readonly entries: ReadonlyArray<ThreadWorkEntry>;\n readonly after?: string;\n },\n ThreadStoreError\n >;\n readonly threads: (\n request: WorkThreadsRequest,\n ) => Effect.Effect<WorkThreadsPage, ThreadStoreError>;\n}\n\n/** One journal's private mutation boundary, shared with its paired ledger and delivery store. */\nexport class MemoryThreadStoreKernel extends Context.Service<\n MemoryThreadStoreKernel,\n {\n readonly owner: StorageOwner[\"Service\"];\n readonly withMutation: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;\n readonly registerWorkOwner: (\n kind: \"admissions\" | \"deliveries\",\n owner: MemoryWorkOwner,\n ) => Effect.Effect<void>;\n readonly registerDeliveryLookup: (\n exists: (threadId: ThreadId, messageId: IdempotencyKey) => boolean,\n ) => Effect.Effect<void>;\n /** Synchronous publication with the authoritative retained row, including replay membership. */\n readonly checkThreadCapacity: (threadId: ThreadId) => Effect.Effect<void, ThreadStoreError>;\n readonly initializeWork: (threadId: ThreadId) => void;\n readonly retainDelivery: (threadId: ThreadId, messageId: IdempotencyKey) => void;\n readonly registerLedgerTransfer: (transfer: MemoryLedgerTransfer) => Effect.Effect<void>;\n readonly registerDeliveryTransfer: (transfer: MemoryDeliveryTransfer) => Effect.Effect<void>;\n readonly prepareAppend: (\n request: AppendRequest,\n ) => Effect.Effect<PreparedMemoryAppend, ThreadStoreFailure>;\n readonly appendPrepared: (\n prepared: PreparedMemoryAppend,\n ) => Effect.Effect<AppendResult, ThreadStoreFailure>;\n readonly record: (\n threadId: ThreadId,\n recordId: RecordId,\n ) => Effect.Effect<RecordEnvelope | undefined>;\n /** Bounded canonical outcomes for one call; caller holds the shared mutation gate. */\n readonly toolCallResults: (\n threadId: ThreadId,\n runId: RunId,\n toolCallId: ToolCallId,\n ) => Effect.Effect<ReadonlyArray<RecordEnvelope>>;\n readonly tail: (threadId: ThreadId) => Effect.Effect<ThreadTail, ThreadStoreFailure>;\n }\n>()(\"@effect-agent/storage-memory/internal/MemoryThreadStoreKernel\") {}\n","/** Keep only the lowest distinct metadata keys after a cursor while scanning resident indexes. */\nexport const boundedWorkSelection = <A>(\n limit: number,\n key: (value: A) => string,\n after?: string,\n) => {\n const values: Array<A> = [];\n\n return {\n values,\n add: (value: A) => {\n const candidate = key(value);\n\n if (after !== undefined && candidate <= after) return;\n let low = 0;\n let high = values.length;\n\n while (low < high) {\n const middle = Math.floor((low + high) / 2);\n\n if (key(values[middle]) < candidate) low = middle + 1;\n else high = middle;\n }\n if (low >= limit || (low < values.length && key(values[low]) === candidate)) return;\n if (values.length === limit) values.pop();\n values.splice(low, 0, value);\n },\n };\n};\n"],"mappings":";;;AAyHA,IAAa,0BAAb,cAA6C,QAAQ,QAoCnD,CAAC,CAAC,+DAA+D,CAAC,CAAC,CAAC;;;;AC5JtE,MAAa,wBACX,OACA,KACA,UACG;CACH,MAAM,SAAmB,CAAC;CAE1B,OAAO;EACL;EACA,MAAM,UAAa;GACjB,MAAM,YAAY,IAAI,KAAK;GAE3B,IAAI,UAAU,KAAA,KAAa,aAAa,OAAO;GAC/C,IAAI,MAAM;GACV,IAAI,OAAO,OAAO;GAElB,OAAO,MAAM,MAAM;IACjB,MAAM,SAAS,KAAK,OAAO,MAAM,QAAQ,CAAC;IAE1C,IAAI,IAAI,OAAO,OAAO,IAAI,WAAW,MAAM,SAAS;SAC/C,OAAO;GACd;GACA,IAAI,OAAO,SAAU,MAAM,OAAO,UAAU,IAAI,OAAO,IAAI,MAAM,WAAY;GAC7E,IAAI,OAAO,WAAW,OAAO,OAAO,IAAI;GACxC,OAAO,OAAO,KAAK,GAAG,KAAK;EAC7B;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@yielded/agent-storage-memory","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@yielded/agent-storage-memory","version":"0.1.0-beta.187","dependencies":{"@yielded/agent":"0.1.0-beta.187"},"devDependencies":{"@effect/platform-node":"4.0.5","@effect/vitest":"4.0.5","effect":"4.0.5","typescript":"7.0.2","vite":"npm:@voidzero-dev/vite-plus-core@1.1.0","vite-plus":"1.1.0","vitest":"5.0.3"},"peerDependencies":{"effect":"^4.0.3"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./memory-message-delivery-store":{"types":"./dist/MemoryMessageDeliveryStore.d.mts","default":"./dist/MemoryMessageDeliveryStore.mjs"},"./memory-schedule-store":{"types":"./dist/MemoryScheduleStore.d.mts","default":"./dist/MemoryScheduleStore.mjs"},"./memory-semantic-index":{"types":"./dist/MemorySemanticIndex.d.mts","default":"./dist/MemorySemanticIndex.mjs"},"./memory-submission-ledger":{"types":"./dist/MemorySubmissionLedger.d.mts","default":"./dist/MemorySubmissionLedger.mjs"},"./memory-subscription-store":{"types":"./dist/MemorySubscriptionStore.d.mts","default":"./dist/MemorySubscriptionStore.mjs"},"./memory-thread-store":{"types":"./dist/MemoryThreadStore.d.mts","default":"./dist/MemoryThreadStore.mjs"}},"description":"In-memory Thread store and submission ledger reference adapters for Effect Agent tests and conformance suites.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/agent.git","directory":"packages/storage-memory"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
|
|
@@ -35,7 +35,11 @@ import {
|
|
|
35
35
|
} from "@yielded/agent/thread-import";
|
|
36
36
|
import { ThreadStoreError, makeTransferFactCheck } from "@yielded/agent/thread-store";
|
|
37
37
|
import { workId, type ThreadWorkEntry } from "@yielded/agent/thread-work";
|
|
38
|
-
import
|
|
38
|
+
import * as Effect from "effect/Effect";
|
|
39
|
+
import * as Layer from "effect/Layer";
|
|
40
|
+
import * as MutableRef from "effect/MutableRef";
|
|
41
|
+
import * as Ref from "effect/Ref";
|
|
42
|
+
import * as Schema from "effect/Schema";
|
|
39
43
|
|
|
40
44
|
import { MemoryThreadStoreKernel } from "./internal/MemoryThreadStoreKernel.ts";
|
|
41
45
|
import { boundedWorkSelection } from "./internal/WorkSelection.ts";
|
|
@@ -23,7 +23,11 @@ import {
|
|
|
23
23
|
scheduleKeyOf,
|
|
24
24
|
scheduleOwnerKey,
|
|
25
25
|
} from "@yielded/agent/schedule-transition";
|
|
26
|
-
import
|
|
26
|
+
import * as Effect from "effect/Effect";
|
|
27
|
+
import * as Layer from "effect/Layer";
|
|
28
|
+
import * as Ref from "effect/Ref";
|
|
29
|
+
import * as Result from "effect/Result";
|
|
30
|
+
import * as Schema from "effect/Schema";
|
|
27
31
|
|
|
28
32
|
interface MemoryScheduleState {
|
|
29
33
|
readonly records: ReadonlyMap<string, string>;
|
|
@@ -10,8 +10,12 @@ import {
|
|
|
10
10
|
SemanticMemoryIndex,
|
|
11
11
|
SemanticMemoryProfile,
|
|
12
12
|
} from "@yielded/agent/semantic-memory-index";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
13
|
+
import * as Clock from "effect/Clock";
|
|
14
|
+
import * as Effect from "effect/Effect";
|
|
15
|
+
import * as Hex from "effect/encoding/Hex";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
import * as Ref from "effect/Ref";
|
|
18
|
+
import * as Schema from "effect/Schema";
|
|
15
19
|
|
|
16
20
|
const PositiveCapacity = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65_536 }));
|
|
17
21
|
const MaxStoredVectorComponents = 16_777_216;
|
|
@@ -120,23 +120,21 @@ import {
|
|
|
120
120
|
transferPageFits,
|
|
121
121
|
} from "@yielded/agent/thread-store";
|
|
122
122
|
import { admissionWork } from "@yielded/agent/thread-work";
|
|
123
|
-
import
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
Stream,
|
|
139
|
-
} from "effect";
|
|
123
|
+
import * as Cause from "effect/Cause";
|
|
124
|
+
import * as Clock from "effect/Clock";
|
|
125
|
+
import * as Context from "effect/Context";
|
|
126
|
+
import * as Crypto from "effect/Crypto";
|
|
127
|
+
import * as DateTime from "effect/DateTime";
|
|
128
|
+
import * as Effect from "effect/Effect";
|
|
129
|
+
import * as Exit from "effect/Exit";
|
|
130
|
+
import * as Fiber from "effect/Fiber";
|
|
131
|
+
import * as Layer from "effect/Layer";
|
|
132
|
+
import * as MutableRef from "effect/MutableRef";
|
|
133
|
+
import * as Option from "effect/Option";
|
|
134
|
+
import * as Ref from "effect/Ref";
|
|
135
|
+
import * as Result from "effect/Result";
|
|
136
|
+
import * as Schema from "effect/Schema";
|
|
137
|
+
import * as Stream from "effect/Stream";
|
|
140
138
|
|
|
141
139
|
import { MemoryThreadStoreKernel } from "./internal/MemoryThreadStoreKernel.ts";
|
|
142
140
|
import { boundedWorkSelection } from "./internal/WorkSelection.ts";
|
|
@@ -30,7 +30,12 @@ import {
|
|
|
30
30
|
subscriptionUsesCapacity,
|
|
31
31
|
subscriptionDeliveryUsesCapacity,
|
|
32
32
|
} from "@yielded/agent/subscription-transition";
|
|
33
|
-
import
|
|
33
|
+
import * as Clock from "effect/Clock";
|
|
34
|
+
import * as Effect from "effect/Effect";
|
|
35
|
+
import * as Layer from "effect/Layer";
|
|
36
|
+
import * as Ref from "effect/Ref";
|
|
37
|
+
import * as Result from "effect/Result";
|
|
38
|
+
import * as Schema from "effect/Schema";
|
|
34
39
|
|
|
35
40
|
interface RegistrationCapacity {
|
|
36
41
|
readonly registrationExpiries: ReadonlyArray<number>;
|
package/src/MemoryThreadStore.ts
CHANGED
|
@@ -130,20 +130,18 @@ import {
|
|
|
130
130
|
type WorkerReportingMode,
|
|
131
131
|
type ThreadWorkStorage,
|
|
132
132
|
} from "@yielded/agent/thread-work";
|
|
133
|
-
import
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} from "effect";
|
|
146
|
-
import { Base64 } from "effect/encoding";
|
|
133
|
+
import * as Context from "effect/Context";
|
|
134
|
+
import * as Crypto from "effect/Crypto";
|
|
135
|
+
import * as Effect from "effect/Effect";
|
|
136
|
+
import * as Base64 from "effect/encoding/Base64";
|
|
137
|
+
import * as Layer from "effect/Layer";
|
|
138
|
+
import * as MutableRef from "effect/MutableRef";
|
|
139
|
+
import * as Option from "effect/Option";
|
|
140
|
+
import * as PubSub from "effect/PubSub";
|
|
141
|
+
import * as Ref from "effect/Ref";
|
|
142
|
+
import * as Schema from "effect/Schema";
|
|
143
|
+
import * as Semaphore from "effect/Semaphore";
|
|
144
|
+
import * as Stream from "effect/Stream";
|
|
147
145
|
|
|
148
146
|
import {
|
|
149
147
|
MemoryThreadStoreKernel,
|
|
@@ -24,7 +24,9 @@ import type {
|
|
|
24
24
|
WorkThreadsRequest,
|
|
25
25
|
WorkThreadsPage,
|
|
26
26
|
} from "@yielded/agent/thread-work";
|
|
27
|
-
import
|
|
27
|
+
import * as Context from "effect/Context";
|
|
28
|
+
import type * as Effect from "effect/Effect";
|
|
29
|
+
import type * as Stream from "effect/Stream";
|
|
28
30
|
|
|
29
31
|
export interface PreparedMemoryAppend {
|
|
30
32
|
readonly request: AppendRequest;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WorkSelection-CmqTuws3.mjs","names":[],"sources":["../src/internal/MemoryThreadStoreKernel.ts","../src/internal/WorkSelection.ts"],"sourcesContent":["import type { RunId, SubmissionId, ThreadId, ToolCallId } from \"@yielded/agent/identifiers\";\nimport type { IdempotencyKey } from \"@yielded/agent/receipt\";\nimport type { RecordEnvelope, RecordId } from \"@yielded/agent/records\";\nimport type { StorageOwner } from \"@yielded/agent/run-storage\";\nimport type { SubmissionSnapshot, WorkerLedgerState } from \"@yielded/agent/submission-ledger\";\nimport type {\n PreparedImportPage,\n ThreadImportReader,\n ThreadDeliveryImportReader,\n ThreadImportRejected,\n} from \"@yielded/agent/thread-import\";\nimport type {\n AppendResult,\n AppendRequest,\n ThreadStoreFailure,\n ThreadTail,\n ThreadAdmission,\n ThreadStoreError,\n ThreadExportSnapshot,\n} from \"@yielded/agent/thread-store\";\nimport type { TransferFacts, TransferSection } from \"@yielded/agent/thread-transfer\";\nimport type {\n ThreadWorkEntry,\n WorkThreadsRequest,\n WorkThreadsPage,\n} from \"@yielded/agent/thread-work\";\nimport { Context, type Effect, type Stream } from \"effect\";\n\nexport interface PreparedMemoryAppend {\n readonly request: AppendRequest;\n readonly batchJson: string;\n}\n\n/** Private storage, not a whole-Thread preparation value. Publication callbacks never yield. */\nexport interface MemoryLedgerImport {\n readonly reader: Pick<ThreadImportReader[\"Service\"], \"admission\" | \"runOwner\" | \"commands\">;\n readonly stage: (\n page: PreparedImportPage,\n ) => Effect.Effect<void, ThreadImportRejected | ThreadStoreError>;\n readonly prepareCommit: (\n workerSeal?: Pick<WorkerLedgerState, \"terminal\">,\n ) => Effect.Effect<() => void, ThreadImportRejected | ThreadStoreError, ThreadImportReader>;\n}\n\nexport interface MemoryLedgerTransfer {\n readonly snapshot: (threadId: ThreadId) => Effect.Effect<\n Omit<typeof ThreadExportSnapshot.Type, \"deliveries\"> & {\n readonly idle: boolean;\n readonly workerSeal?: Pick<WorkerLedgerState, \"terminal\">;\n },\n ThreadStoreError\n >;\n readonly facts: (\n threadId: ThreadId,\n section: Exclude<TransferSection, \"deliveries\">,\n after: string | undefined,\n ) => Effect.Effect<{ readonly facts: TransferFacts; readonly after: string }, ThreadStoreError>;\n readonly startImport: (\n threadId: ThreadId,\n ) => Effect.Effect<MemoryLedgerImport, ThreadImportRejected | ThreadStoreError>;\n readonly submissions: (threadId: ThreadId) => Stream.Stream<SubmissionSnapshot, ThreadStoreError>;\n readonly admission: (\n threadId: ThreadId,\n submissionId: SubmissionId,\n ) => Effect.Effect<ThreadAdmission | undefined, ThreadStoreError>;\n readonly commands: ThreadImportReader[\"Service\"][\"commands\"];\n}\n\nexport interface MemoryDeliveryImport {\n readonly record: ThreadImportReader[\"Service\"][\"delivery\"];\n readonly stage: (\n page: PreparedImportPage,\n ) => Effect.Effect<void, ThreadImportRejected | ThreadStoreError>;\n readonly has: (messageId: IdempotencyKey) => boolean;\n readonly prepareCommit: () => Effect.Effect<\n () => void,\n ThreadImportRejected | ThreadStoreError,\n ThreadDeliveryImportReader\n >;\n}\n\nexport interface MemoryDeliveryTransfer {\n readonly record: (\n threadId: ThreadId,\n messageId: IdempotencyKey,\n ) => ReturnType<ThreadImportReader[\"Service\"][\"delivery\"]>;\n readonly snapshot: (threadId: ThreadId) => {\n readonly idle: boolean;\n readonly deliveries: number;\n };\n readonly facts: (\n threadId: ThreadId,\n after: string | undefined,\n ) => Effect.Effect<{ readonly facts: TransferFacts; readonly after: string }, ThreadStoreError>;\n readonly startImport: (\n threadId: ThreadId,\n ) => Effect.Effect<MemoryDeliveryImport, ThreadImportRejected | ThreadStoreError>;\n readonly peerCount: (threadId: ThreadId, nowMillis: number, limit: number) => number;\n}\n\n/** Native control metadata only; callers already hold the journal's shared gate. */\nexport interface MemoryWorkOwner {\n readonly page: (\n threadId: ThreadId,\n after: string | undefined,\n limit: number,\n ) => Effect.Effect<\n {\n readonly entries: ReadonlyArray<ThreadWorkEntry>;\n readonly after?: string;\n },\n ThreadStoreError\n >;\n readonly threads: (\n request: WorkThreadsRequest,\n ) => Effect.Effect<WorkThreadsPage, ThreadStoreError>;\n}\n\n/** One journal's private mutation boundary, shared with its paired ledger and delivery store. */\nexport class MemoryThreadStoreKernel extends Context.Service<\n MemoryThreadStoreKernel,\n {\n readonly owner: StorageOwner[\"Service\"];\n readonly withMutation: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;\n readonly registerWorkOwner: (\n kind: \"admissions\" | \"deliveries\",\n owner: MemoryWorkOwner,\n ) => Effect.Effect<void>;\n readonly registerDeliveryLookup: (\n exists: (threadId: ThreadId, messageId: IdempotencyKey) => boolean,\n ) => Effect.Effect<void>;\n /** Synchronous publication with the authoritative retained row, including replay membership. */\n readonly checkThreadCapacity: (threadId: ThreadId) => Effect.Effect<void, ThreadStoreError>;\n readonly initializeWork: (threadId: ThreadId) => void;\n readonly retainDelivery: (threadId: ThreadId, messageId: IdempotencyKey) => void;\n readonly registerLedgerTransfer: (transfer: MemoryLedgerTransfer) => Effect.Effect<void>;\n readonly registerDeliveryTransfer: (transfer: MemoryDeliveryTransfer) => Effect.Effect<void>;\n readonly prepareAppend: (\n request: AppendRequest,\n ) => Effect.Effect<PreparedMemoryAppend, ThreadStoreFailure>;\n readonly appendPrepared: (\n prepared: PreparedMemoryAppend,\n ) => Effect.Effect<AppendResult, ThreadStoreFailure>;\n readonly record: (\n threadId: ThreadId,\n recordId: RecordId,\n ) => Effect.Effect<RecordEnvelope | undefined>;\n /** Bounded canonical outcomes for one call; caller holds the shared mutation gate. */\n readonly toolCallResults: (\n threadId: ThreadId,\n runId: RunId,\n toolCallId: ToolCallId,\n ) => Effect.Effect<ReadonlyArray<RecordEnvelope>>;\n readonly tail: (threadId: ThreadId) => Effect.Effect<ThreadTail, ThreadStoreFailure>;\n }\n>()(\"@effect-agent/storage-memory/internal/MemoryThreadStoreKernel\") {}\n","/** Keep only the lowest distinct metadata keys after a cursor while scanning resident indexes. */\nexport const boundedWorkSelection = <A>(\n limit: number,\n key: (value: A) => string,\n after?: string,\n) => {\n const values: Array<A> = [];\n\n return {\n values,\n add: (value: A) => {\n const candidate = key(value);\n\n if (after !== undefined && candidate <= after) return;\n let low = 0;\n let high = values.length;\n\n while (low < high) {\n const middle = Math.floor((low + high) / 2);\n\n if (key(values[middle]) < candidate) low = middle + 1;\n else high = middle;\n }\n if (low >= limit || (low < values.length && key(values[low]) === candidate)) return;\n if (values.length === limit) values.pop();\n values.splice(low, 0, value);\n },\n };\n};\n"],"mappings":";;;AAuHA,IAAa,0BAAb,cAA6C,QAAQ,QAoCnD,CAAC,CAAC,+DAA+D,CAAC,CAAC,CAAC;;;;AC1JtE,MAAa,wBACX,OACA,KACA,UACG;CACH,MAAM,SAAmB,CAAC;CAE1B,OAAO;EACL;EACA,MAAM,UAAa;GACjB,MAAM,YAAY,IAAI,KAAK;GAE3B,IAAI,UAAU,KAAA,KAAa,aAAa,OAAO;GAC/C,IAAI,MAAM;GACV,IAAI,OAAO,OAAO;GAElB,OAAO,MAAM,MAAM;IACjB,MAAM,SAAS,KAAK,OAAO,MAAM,QAAQ,CAAC;IAE1C,IAAI,IAAI,OAAO,OAAO,IAAI,WAAW,MAAM,SAAS;SAC/C,OAAO;GACd;GACA,IAAI,OAAO,SAAU,MAAM,OAAO,UAAU,IAAI,OAAO,IAAI,MAAM,WAAY;GAC7E,IAAI,OAAO,WAAW,OAAO,OAAO,IAAI;GACxC,OAAO,OAAO,KAAK,GAAG,KAAK;EAC7B;CACF;AACF"}
|