@yielded/agent 0.1.0-beta.175 → 0.1.0-beta.176
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/{Admin-Qa3I1oA5.d.mts → Admin-DTDihBra.d.mts} +13 -7
- package/dist/{DurableAgentRuntime-CPlw5_7e.mjs → DurableAgentRuntime-BJbuIqQq.mjs} +84 -37
- package/dist/DurableAgentRuntime-BJbuIqQq.mjs.map +1 -0
- package/dist/{EventSource-BTu68yDW.d.mts → EventSource-Cc58uEso.d.mts} +2 -2
- package/dist/{MessageDelivery-DjAZJ4Fd.d.mts → MessageDelivery-ClHg7c0O.d.mts} +42 -42
- package/dist/{PreparedInputAdmission-wgY4JMZY.d.mts → PreparedInputAdmission-CjcX1OP0.d.mts} +3 -3
- package/dist/{RunContinuation-BiyKJK32.mjs → RunContinuation-CWHuciup.mjs} +3 -3
- package/dist/RunContinuation-CWHuciup.mjs.map +1 -0
- package/dist/{RunContinuation-3jB5pULC.d.mts → RunContinuation-DSnUTSSb.d.mts} +4 -4
- package/dist/{RunJournal-CPMKcfd0.mjs → RunJournal-DGblbFas.mjs} +5 -5
- package/dist/{RunJournal-CPMKcfd0.mjs.map → RunJournal-DGblbFas.mjs.map} +1 -1
- package/dist/{RunStorage-CzutHJBE.mjs → RunStorage-BF2YgWkg.mjs} +43 -33
- package/dist/RunStorage-BF2YgWkg.mjs.map +1 -0
- package/dist/{Subscription-DmIHlOJK.d.mts → Subscription-DuC_PcGx.d.mts} +2 -2
- package/dist/{SubscriptionInput-DgcQhvbe.d.mts → SubscriptionInput-B1IeAEDi.d.mts} +2 -2
- package/dist/{ThreadImport-DP-vOk2F.d.mts → ThreadImport-D_Biid6w.d.mts} +42 -42
- package/dist/{ThreadImport-CjlG57vH.mjs → ThreadImport-ZgWxf7bB.mjs} +5 -5
- package/dist/{ThreadImport-CjlG57vH.mjs.map → ThreadImport-ZgWxf7bB.mjs.map} +1 -1
- package/dist/{ThreadStore-EuUilthA.mjs → ThreadStore-BC4V-mY-.mjs} +39 -18
- package/dist/ThreadStore-BC4V-mY-.mjs.map +1 -0
- package/dist/{ThreadTransfer-DB_zsrtJ.mjs → ThreadTransfer-S7FnTRHt.mjs} +2 -2
- package/dist/{ThreadTransfer-DB_zsrtJ.mjs.map → ThreadTransfer-S7FnTRHt.mjs.map} +1 -1
- package/dist/{WorkerAdmission-eBeXt_mu.mjs → WorkerAdmission-C47Vy_cK.mjs} +3 -3
- package/dist/{WorkerAdmission-eBeXt_mu.mjs.map → WorkerAdmission-C47Vy_cK.mjs.map} +1 -1
- package/dist/durable/Admin.d.mts +1 -1
- package/dist/durable/AgentRegistration.d.mts +1 -1
- package/dist/durable/Certification.d.mts +1 -1
- package/dist/durable/CommittedActivity.d.mts +1 -1
- package/dist/durable/CommittedActivity.mjs +1 -1
- package/dist/durable/DurableAgentRuntime.d.mts +1 -1
- package/dist/durable/DurableAgentRuntime.mjs +2 -2
- package/dist/durable/EventSource.d.mts +1 -1
- package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
- package/dist/durable/LifecyclePublication.d.mts +1 -1
- package/dist/durable/LifecyclePublication.mjs +1 -1
- package/dist/durable/MessageDelivery.d.mts +1 -1
- package/dist/durable/MessageDeliveryStoreConformance.d.mts +2 -2
- package/dist/durable/PersistentHistory.d.mts +1 -1
- package/dist/durable/PersistentHistory.mjs +3 -3
- package/dist/durable/PreparedInputAdmission.d.mts +1 -1
- package/dist/durable/Recovery.d.mts +1 -1
- package/dist/durable/RunContinuation.d.mts +2 -2
- package/dist/durable/RunContinuation.mjs +2 -2
- package/dist/durable/RunJournal.d.mts +1 -1
- package/dist/durable/RunJournal.mjs +1 -1
- package/dist/durable/RunStorage.d.mts +1 -1
- package/dist/durable/RunStorage.mjs +1 -1
- package/dist/durable/Scheduling.d.mts +1 -1
- package/dist/durable/SettlementPublisher.d.mts +1 -1
- package/dist/durable/SettlementPublisher.mjs +2 -2
- package/dist/durable/SubmissionLedger.d.mts +1 -1
- package/dist/durable/SubmissionLedger.mjs.map +1 -1
- package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
- package/dist/durable/SubmissionLedgerConformance.mjs +3 -3
- package/dist/durable/SubmissionStatus.d.mts +1 -1
- package/dist/durable/Subscription.d.mts +1 -1
- package/dist/durable/SubscriptionInput.d.mts +1 -1
- package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
- package/dist/durable/SubscriptionTools.d.mts +2 -2
- package/dist/durable/SubscriptionTransition.d.mts +1 -1
- package/dist/durable/Subscriptions.d.mts +5 -5
- package/dist/durable/ThreadArchiveRange.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.d.mts +1 -1
- package/dist/durable/ThreadContextHistory.mjs +1 -1
- package/dist/durable/ThreadImport.d.mts +1 -1
- package/dist/durable/ThreadImport.mjs +1 -1
- package/dist/durable/ThreadInvariants.d.mts +3 -3
- package/dist/durable/ThreadInvariants.mjs +3 -3
- package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
- package/dist/durable/ThreadReader.d.mts +1 -1
- package/dist/durable/ThreadReader.mjs +1 -1
- package/dist/durable/ThreadStore.d.mts +1 -1
- package/dist/durable/ThreadStore.mjs +1 -1
- package/dist/durable/ThreadStoreConformance.d.mts +1 -1
- package/dist/durable/ThreadStoreConformance.mjs +3 -3
- package/dist/durable/ThreadTransfer.d.mts +1 -1
- package/dist/durable/ThreadTransfer.mjs +1 -1
- package/dist/durable/ThreadWork.d.mts +1 -1
- package/dist/durable/ThreadWork.mjs +3 -3
- package/dist/durable/WorkerAdmission.d.mts +68 -68
- package/dist/durable/WorkerAdmission.mjs +1 -1
- package/dist/durable/WorkerHost.d.mts +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +7 -7
- package/dist/{run-context-reader-DVhJZ1Qe.d.mts → run-context-reader-DvTEq2RC.d.mts} +2 -2
- package/package.json +1 -1
- package/src/durable/DurableAgentRuntime.ts +169 -55
- package/src/durable/RunContinuation.ts +2 -2
- package/src/durable/RunJournal.ts +9 -5
- package/src/durable/RunStorage.ts +83 -61
- package/src/durable/SubmissionLedger.ts +8 -0
- package/src/durable/ThreadStore.ts +39 -19
- package/src/durable/internal/initial-context.ts +17 -2
- package/src/durable/internal/prompt-history-cache.ts +13 -8
- package/dist/DurableAgentRuntime-CPlw5_7e.mjs.map +0 -1
- package/dist/RunContinuation-BiyKJK32.mjs.map +0 -1
- package/dist/RunStorage-CzutHJBE.mjs.map +0 -1
- package/dist/ThreadStore-EuUilthA.mjs.map +0 -1
|
@@ -343,19 +343,20 @@ export class AppendRequest extends Schema.Class<AppendRequest>(
|
|
|
343
343
|
expectedTailSequence: CanonicalSequence,
|
|
344
344
|
}) {}
|
|
345
345
|
|
|
346
|
+
const RecordCount = Schema.Array(Schema.Unknown).check(Schema.isMaxLength(256));
|
|
347
|
+
const ExecutionRecordCount = Schema.Array(Schema.Unknown).check(Schema.isMaxLength(8));
|
|
348
|
+
|
|
346
349
|
const AppendHeader = Schema.Struct({
|
|
347
350
|
threadId: ThreadId,
|
|
348
351
|
expectedTailSequence: CanonicalSequence,
|
|
349
352
|
batchId: BatchId,
|
|
350
353
|
producerId: ProducerId,
|
|
354
|
+
records: RecordCount,
|
|
355
|
+
executions: RecordCount,
|
|
351
356
|
});
|
|
352
357
|
|
|
353
358
|
const validateHeader = Schema.decodeUnknownSync(AppendHeader);
|
|
354
359
|
|
|
355
|
-
const validateRecordCount = Schema.decodeUnknownSync(
|
|
356
|
-
Schema.Array(Schema.Unknown).check(Schema.isMaxLength(256)),
|
|
357
|
-
);
|
|
358
|
-
|
|
359
360
|
const validateExecutionHeader = Schema.decodeUnknownSync(
|
|
360
361
|
Schema.Struct({
|
|
361
362
|
previousRevision: ExecutionUpdate.fields.previousRevision,
|
|
@@ -366,24 +367,36 @@ const validateExecutionHeader = Schema.decodeUnknownSync(
|
|
|
366
367
|
originalSequence: ExecutionCheckpoint.fields.originalSequence,
|
|
367
368
|
throughSequence: ExecutionCheckpoint.fields.throughSequence,
|
|
368
369
|
batchId: ExecutionCheckpoint.fields.batchId,
|
|
370
|
+
operational: ExecutionRecordCount,
|
|
369
371
|
}),
|
|
372
|
+
facts: ExecutionRecordCount,
|
|
370
373
|
}),
|
|
371
374
|
);
|
|
372
375
|
|
|
373
|
-
const validateExecutionRecordCount = Schema.decodeUnknownSync(
|
|
374
|
-
Schema.Array(Schema.Unknown).check(Schema.isMaxLength(8)),
|
|
375
|
-
);
|
|
376
|
-
|
|
377
376
|
/** Capture records once; wrapper fields retain their owning Schema's constraints. */
|
|
378
377
|
const captureExecution = (input: ExecutionUpdate) => {
|
|
379
|
-
const
|
|
380
|
-
const operationalInput =
|
|
378
|
+
const checkpointInput = input.checkpoint;
|
|
379
|
+
const operationalInput = checkpointInput.operational;
|
|
381
380
|
const factsInput = input.facts;
|
|
382
381
|
|
|
383
|
-
const
|
|
384
|
-
|
|
382
|
+
const header = validateExecutionHeader({
|
|
383
|
+
previousRevision: input.previousRevision,
|
|
384
|
+
retire: input.retire,
|
|
385
|
+
checkpoint: {
|
|
386
|
+
version: checkpointInput.version,
|
|
387
|
+
canonicalRecords: checkpointInput.canonicalRecords,
|
|
388
|
+
originalSequence: checkpointInput.originalSequence,
|
|
389
|
+
throughSequence: checkpointInput.throughSequence,
|
|
390
|
+
batchId: checkpointInput.batchId,
|
|
391
|
+
operational: operationalInput,
|
|
392
|
+
},
|
|
393
|
+
facts: factsInput,
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
const operationalLength = header.checkpoint.operational.length;
|
|
397
|
+
const factsLength = header.facts.length;
|
|
385
398
|
|
|
386
|
-
const progress = captureRecord(
|
|
399
|
+
const progress = captureRecord(checkpointInput.progressRecord);
|
|
387
400
|
|
|
388
401
|
if (Result.isFailure(progress)) return Result.fail(progress.failure);
|
|
389
402
|
const progressRecord = progress.success.canonical;
|
|
@@ -530,15 +543,19 @@ export const PreparedAppend = {
|
|
|
530
543
|
return Effect.try({
|
|
531
544
|
try: () =>
|
|
532
545
|
Result.gen(function* () {
|
|
546
|
+
const executions = input.executions ?? [];
|
|
547
|
+
const recordInputs = input.batch.records;
|
|
548
|
+
|
|
533
549
|
const header = validateHeader({
|
|
534
550
|
...input,
|
|
535
551
|
batchId: input.batch.batchId,
|
|
536
552
|
producerId: input.batch.producerId,
|
|
553
|
+
records: recordInputs,
|
|
554
|
+
executions,
|
|
537
555
|
});
|
|
538
556
|
|
|
539
|
-
|
|
540
|
-
const
|
|
541
|
-
const executionLength = validateRecordCount(executions).length;
|
|
557
|
+
const recordLength = header.records.length;
|
|
558
|
+
const executionLength = header.executions.length;
|
|
542
559
|
|
|
543
560
|
const executionWrites: Array<PreparedAppend["executionWrites"][number]> = [];
|
|
544
561
|
|
|
@@ -546,7 +563,7 @@ export const PreparedAppend = {
|
|
|
546
563
|
executionWrites.push(yield* captureExecution(executions[index]!));
|
|
547
564
|
Object.freeze(executionWrites);
|
|
548
565
|
|
|
549
|
-
if (
|
|
566
|
+
if (recordLength === 0 && executionWrites.length === 0)
|
|
550
567
|
return yield* Result.fail(
|
|
551
568
|
ThreadStoreError.make({
|
|
552
569
|
operation: "prepare durable commit",
|
|
@@ -560,8 +577,11 @@ export const PreparedAppend = {
|
|
|
560
577
|
message: "Active state exceeds its bounded transfer representation",
|
|
561
578
|
}),
|
|
562
579
|
);
|
|
563
|
-
// Visit
|
|
564
|
-
const encodings =
|
|
580
|
+
// Visit Schema-validated indexed slots, including sparse ones, never a caller's iterator.
|
|
581
|
+
const encodings = [];
|
|
582
|
+
|
|
583
|
+
for (let index = 0; index < recordLength; index++)
|
|
584
|
+
encodings.push(yield* captureRecord(recordInputs[index]!));
|
|
565
585
|
const prefix = `{"batchId":${JSON.stringify(header.batchId)},"producerId":${JSON.stringify(header.producerId)},"records":[`;
|
|
566
586
|
const batchJson = `${prefix}${encodings.map(({ json }) => json).join(",")}]}`;
|
|
567
587
|
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { Effect, Option, Schema, Stream } from "effect";
|
|
2
2
|
import { Prompt } from "effect/ai";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CanonicalSequence,
|
|
6
|
+
type CanonicalRecordEnvelope,
|
|
7
|
+
type RecordEnvelope,
|
|
8
|
+
type UserInputRecorded,
|
|
9
|
+
} from "../Records.ts";
|
|
5
10
|
import { RunJournalError, toolCallSettledRecordId } from "../RunJournal.ts";
|
|
6
11
|
import { submissionSettlementRecordId } from "../SubmissionLedger.ts";
|
|
7
12
|
import { getRecord, getRunInput, PROMPT_EVIDENCE_TAGS, ThreadReader } from "../ThreadStore.ts";
|
|
8
13
|
import type { JournalRecordEnvelope } from "./journal-metadata.ts";
|
|
9
14
|
|
|
15
|
+
/** A captured original input can prepare context before its atomic publication. It carries
|
|
16
|
+
* an expected position, never a committed observation cursor or dispatch authority. */
|
|
17
|
+
export type InitialContextInput =
|
|
18
|
+
| CanonicalRecordEnvelope
|
|
19
|
+
| {
|
|
20
|
+
readonly threadId: CanonicalRecordEnvelope["threadId"];
|
|
21
|
+
readonly sequence: CanonicalRecordEnvelope["sequence"];
|
|
22
|
+
readonly record: RecordEnvelope & { readonly payload: UserInputRecorded };
|
|
23
|
+
};
|
|
24
|
+
|
|
10
25
|
const invalid = (message: string) => RunJournalError.make({ message });
|
|
11
26
|
const promptTag = new Set<string>(PROMPT_EVIDENCE_TAGS);
|
|
12
27
|
|
|
13
28
|
/** Fresh admission trusts validated immutable history; recovery verifies its saved Prompt digest. */
|
|
14
|
-
export const initialContext = Effect.fnUntraced(function* (original:
|
|
29
|
+
export const initialContext = Effect.fnUntraced(function* (original: InitialContextInput) {
|
|
15
30
|
const reader = yield* ThreadReader;
|
|
16
31
|
const threadId = original.threadId;
|
|
17
32
|
const through = CanonicalSequence.make(original.sequence - 1);
|
|
@@ -6,9 +6,9 @@ import { boundedValueFootprint } from "../../engine/internal/bounded-value.ts";
|
|
|
6
6
|
import { canonicalJson, digestCanonicalJson, utf8ByteLength } from "../Digest.ts";
|
|
7
7
|
import {
|
|
8
8
|
CanonicalSequence,
|
|
9
|
+
type CanonicalRecordEnvelope,
|
|
9
10
|
CURRENT_RECORD_FORMAT,
|
|
10
11
|
PromptRecord,
|
|
11
|
-
type CanonicalRecordEnvelope,
|
|
12
12
|
type Digest,
|
|
13
13
|
type PromptRecordEnvelope,
|
|
14
14
|
type RecordEnvelope,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
ThreadStore,
|
|
24
24
|
ThreadTailRequest,
|
|
25
25
|
} from "../ThreadStore.ts";
|
|
26
|
+
import type { InitialContextInput } from "./initial-context.ts";
|
|
26
27
|
import type { JournalRecordEnvelope } from "./journal-metadata.ts";
|
|
27
28
|
import { promptJsonFootprint } from "./prompt-footprint.ts";
|
|
28
29
|
import { captureRecord } from "./record-encoding.ts";
|
|
@@ -149,12 +150,14 @@ const retainedBytes = (value: unknown, json: string, allowance: number) => {
|
|
|
149
150
|
return footprint === undefined ? undefined : encodedBytes + 2 * footprint;
|
|
150
151
|
};
|
|
151
152
|
|
|
152
|
-
const encodeHistory =
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const encodeHistory = (prompt: Prompt.Prompt, allowance: number) =>
|
|
154
|
+
Effect.suspend(() =>
|
|
155
|
+
Effect.mapEager(encodePrompt(prompt), (value) => {
|
|
156
|
+
const encoded = canonicalJson(value);
|
|
155
157
|
|
|
156
|
-
|
|
157
|
-
})
|
|
158
|
+
return { encoded, bytes: retainedBytes(value, encoded, allowance) };
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
158
161
|
|
|
159
162
|
// Finish parsing/decoding before suspending for suffix reads. Only the native prefix and its
|
|
160
163
|
// canonical string leave this Effect; it does not keep a second parsed root in the outer Run.
|
|
@@ -252,7 +255,9 @@ const suffixRecordFootprint = (entry: PromptRecordEnvelope, allowance: number) =
|
|
|
252
255
|
* acknowledged, consecutive appends. Never authority for writes or recovery; any uncertainty
|
|
253
256
|
* discards this derivative and completion rereads canonical history.
|
|
254
257
|
*/
|
|
255
|
-
export const makeCommittedPromptSuffix = (
|
|
258
|
+
export const makeCommittedPromptSuffix = (
|
|
259
|
+
original: Pick<CanonicalRecordEnvelope, "threadId" | "sequence" | "record">,
|
|
260
|
+
) => {
|
|
256
261
|
const records: Array<PromptRecordEnvelope> = [];
|
|
257
262
|
|
|
258
263
|
const runId =
|
|
@@ -558,7 +563,7 @@ export const makePromptHistoryCache = Effect.fnUntraced(function* () {
|
|
|
558
563
|
const complete = Effect.fnUntraced(
|
|
559
564
|
function* (
|
|
560
565
|
writer: WriterIdentity,
|
|
561
|
-
original:
|
|
566
|
+
original: InitialContextInput,
|
|
562
567
|
history: PromptHistory,
|
|
563
568
|
committed?: CommittedPromptSuffix,
|
|
564
569
|
) {
|