@openpond/evals 0.10.1 → 0.10.3

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.
Files changed (52) hide show
  1. package/LEARNING.md +83 -0
  2. package/dist/learning/batch-service.js +44 -0
  3. package/dist/learning/contracts.js +2 -1
  4. package/dist/learning/index.js +4 -0
  5. package/dist/learning/iteration-candidate-decision.js +51 -0
  6. package/dist/learning/iteration-dispatch-commands.js +31 -0
  7. package/dist/learning/iteration-dispatch-contracts.js +73 -0
  8. package/dist/learning/iteration-dispatch-worker.js +178 -0
  9. package/dist/learning/iteration-eligibility.js +76 -0
  10. package/dist/learning/iteration-reservation-cancellation.js +31 -0
  11. package/dist/learning/iteration-reservation-contracts.js +57 -0
  12. package/dist/learning/iteration-reservation-service.js +106 -0
  13. package/dist/learning/operations.js +6 -1
  14. package/dist/learning/repository.js +4 -0
  15. package/dist/learning/service.js +19 -43
  16. package/dist/types/learning/batch-service.d.ts +8 -0
  17. package/dist/types/learning/batch-service.d.ts.map +1 -0
  18. package/dist/types/learning/contracts.d.ts +16 -0
  19. package/dist/types/learning/contracts.d.ts.map +1 -1
  20. package/dist/types/learning/index.d.ts +4 -0
  21. package/dist/types/learning/index.d.ts.map +1 -1
  22. package/dist/types/learning/iteration-candidate-decision.d.ts +94 -0
  23. package/dist/types/learning/iteration-candidate-decision.d.ts.map +1 -0
  24. package/dist/types/learning/iteration-dispatch-commands.d.ts +8 -0
  25. package/dist/types/learning/iteration-dispatch-commands.d.ts.map +1 -0
  26. package/dist/types/learning/iteration-dispatch-contracts.d.ts +93 -0
  27. package/dist/types/learning/iteration-dispatch-contracts.d.ts.map +1 -0
  28. package/dist/types/learning/iteration-dispatch-worker.d.ts +35 -0
  29. package/dist/types/learning/iteration-dispatch-worker.d.ts.map +1 -0
  30. package/dist/types/learning/iteration-eligibility.d.ts +18 -0
  31. package/dist/types/learning/iteration-eligibility.d.ts.map +1 -0
  32. package/dist/types/learning/iteration-reservation-cancellation.d.ts +8 -0
  33. package/dist/types/learning/iteration-reservation-cancellation.d.ts.map +1 -0
  34. package/dist/types/learning/iteration-reservation-contracts.d.ts +90 -0
  35. package/dist/types/learning/iteration-reservation-contracts.d.ts.map +1 -0
  36. package/dist/types/learning/iteration-reservation-service.d.ts +9 -0
  37. package/dist/types/learning/iteration-reservation-service.d.ts.map +1 -0
  38. package/dist/types/learning/operations.d.ts +64 -0
  39. package/dist/types/learning/operations.d.ts.map +1 -1
  40. package/dist/types/learning/repository.d.ts +126 -0
  41. package/dist/types/learning/repository.d.ts.map +1 -1
  42. package/dist/types/learning/service.d.ts.map +1 -1
  43. package/dist/types/learning/transport.d.ts +156 -0
  44. package/dist/types/learning/transport.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/schemas/learning/v1/chain.schema.json +72 -0
  47. package/schemas/learning/v1/command-request.schema.json +374 -233
  48. package/schemas/learning/v1/consumption.schema.json +77 -0
  49. package/schemas/learning/v1/dispatch.schema.json +338 -0
  50. package/schemas/learning/v1/iteration.schema.json +15 -1
  51. package/schemas/learning/v1/read-request.schema.json +4 -0
  52. package/schemas/learning/v1/reservation.schema.json +201 -0
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ import { ReleaseHashSchema, ReleaseIdSchema, ReleaseTimestampSchema } from "@openpond/harness";
3
+ import { LearningRevisionRefSchema } from "./contracts.js";
4
+ export const LearningIterationTriggerSchema = z.discriminatedUnion("kind", [
5
+ z.object({ kind: z.literal("manual"), identity: ReleaseIdSchema }).strict(),
6
+ z.object({ kind: z.literal("schedule"), scheduledAt: ReleaseTimestampSchema }).strict(),
7
+ ]);
8
+ /** Stable across policy edits: a Model owns one learning chain in its scope. */
9
+ export const LearningChainSchema = z.object({
10
+ schemaVersion: z.literal("openpond.learningChain.v1"),
11
+ id: ReleaseIdSchema,
12
+ revision: z.number().int().positive(),
13
+ modelProjectId: ReleaseIdSchema,
14
+ activeIterationId: ReleaseIdSchema.nullable(),
15
+ latestIterationId: ReleaseIdSchema,
16
+ lastReservedAt: ReleaseTimestampSchema.nullable(),
17
+ updatedAt: ReleaseTimestampSchema,
18
+ }).strict();
19
+ export const LearningEligibilityCountsSchema = z.object({
20
+ eligible: z.number().int().nonnegative(),
21
+ awaitingReview: z.number().int().nonnegative(),
22
+ excluded: z.number().int().nonnegative(),
23
+ consumed: z.number().int().nonnegative(),
24
+ }).strict();
25
+ /** Immutable evidence consumption survives rejection and policy revision changes.
26
+ * A corrected evidence revision is new data; reapproving the same revision isn't. */
27
+ export const LearningConsumptionSchema = z.object({
28
+ schemaVersion: z.literal("openpond.learningConsumption.v1"),
29
+ id: ReleaseIdSchema,
30
+ revision: z.literal(1),
31
+ chainId: ReleaseIdSchema,
32
+ iterationId: ReleaseIdSchema,
33
+ evidence: LearningRevisionRefSchema,
34
+ decision: LearningRevisionRefSchema,
35
+ reservedAt: ReleaseTimestampSchema,
36
+ }).strict();
37
+ /** Dispatch must reconcile this reservation, never reserve a second batch on retry. */
38
+ export const LearningIterationReservationSchema = z.object({
39
+ schemaVersion: z.literal("openpond.learningIterationReservation.v1"),
40
+ id: ReleaseIdSchema,
41
+ revision: z.number().int().positive(),
42
+ chainId: ReleaseIdSchema,
43
+ iterationId: ReleaseIdSchema,
44
+ policy: LearningRevisionRefSchema,
45
+ trigger: LearningIterationTriggerSchema,
46
+ requestHash: ReleaseHashSchema,
47
+ outcome: z.enum(["reserved", "waiting_for_data", "waiting_for_review"]),
48
+ counts: LearningEligibilityCountsSchema,
49
+ budget: z.object({
50
+ maximumSpendUsd: z.number().nonnegative(),
51
+ reservedSpendUsd: z.number().nonnegative(),
52
+ settledSpendUsd: z.number().nonnegative(),
53
+ settledAt: ReleaseTimestampSchema.nullable(),
54
+ }).strict(),
55
+ createdAt: ReleaseTimestampSchema,
56
+ updatedAt: ReleaseTimestampSchema,
57
+ }).strict();
@@ -0,0 +1,106 @@
1
+ import { contentHash } from "@openpond/harness";
2
+ import { sealLearningBatch } from "./batch-service.js";
3
+ import { LearningIterationSchema, learningRef, sameLearningRef } from "./contracts.js";
4
+ import { LearningDomainError } from "./errors.js";
5
+ import { inspectIterationEligibility, learningChainId, learningConsumptionId } from "./iteration-eligibility.js";
6
+ import { LearningChainSchema, LearningConsumptionSchema, LearningIterationReservationSchema } from "./iteration-reservation-contracts.js";
7
+ import { requireLearningRelease, requireLearningResource } from "./repository.js";
8
+ /** The caller owns one scope-serialized transaction. This never submits a Job. */
9
+ export async function reserveLearningIteration(transaction, input, actorId, now) {
10
+ const policy = await requireLearningRelease(transaction, "policy", input.policy);
11
+ const chainId = learningChainId(policy.modelProjectId);
12
+ const trigger = input.trigger.kind === "schedule" ? { ...input.trigger, scheduledAt: new Date(input.trigger.scheduledAt).toISOString() } : input.trigger;
13
+ const triggerIdentity = contentHash([input.policy.id, trigger]);
14
+ const id = `iteration-${contentHash([chainId, triggerIdentity])}`;
15
+ const requestHash = contentHash({ policy: input.policy, trigger });
16
+ const previous = await transaction.get("reservation", id);
17
+ if (previous) {
18
+ if (previous.requestHash !== requestHash)
19
+ throw new LearningDomainError("learning_trigger_identity_conflict", 409);
20
+ // Fire identity is independent of actor and transport operation identity.
21
+ return [{ kind: "iteration", id, revision: (await requireLearningResource(transaction, "iteration", id)).revision }, { kind: "reservation", id, revision: previous.revision }];
22
+ }
23
+ const current = await requireLearningResource(transaction, "policy", policy.id);
24
+ if (!sameLearningRef(learningRef(current), input.policy))
25
+ throw new LearningDomainError("learning_policy_revision_stale", 409);
26
+ if (!policy.enabled)
27
+ throw new LearningDomainError("learning_policy_paused", 409);
28
+ if (policy.automation.accept || policy.automation.serve)
29
+ throw new LearningDomainError("learning_automatic_acceptance_not_available", 422);
30
+ if (input.trigger.kind === "schedule") {
31
+ if (policy.trigger.kind !== "schedule" || !policy.automation.train)
32
+ throw new LearningDomainError("learning_schedule_not_enabled", 409);
33
+ if (Date.parse(input.trigger.scheduledAt) > Date.parse(now))
34
+ throw new LearningDomainError("learning_schedule_not_due", 409);
35
+ }
36
+ const chain = await transaction.get("chain", chainId);
37
+ if (chain?.activeIterationId)
38
+ throw new LearningDomainError("learning_iteration_active", 409, chain.activeIterationId);
39
+ if (chain?.lastReservedAt && Date.parse(now) - Date.parse(chain.lastReservedAt) < policy.limits.cooldownSeconds * 1_000) {
40
+ throw new LearningDomainError("learning_iteration_cooldown", 409);
41
+ }
42
+ const eligibility = await inspectIterationEligibility(transaction, policy);
43
+ const ready = eligibility.counts.eligible >= policy.admission.minimumApprovedExamples;
44
+ const status = ready ? "ready" : eligibility.counts.awaitingReview > 0 ? "waiting_for_review" : "waiting_for_data";
45
+ const pointers = [];
46
+ let batch = null;
47
+ if (ready) {
48
+ await assertAvailableBudget(transaction, chainId, now, policy.limits.maxIterationSpendUsd, policy.limits.maxDailySpendUsd);
49
+ const sealed = await sealLearningBatch(transaction, {
50
+ action: "seal_batch", operationId: input.operationId, batchId: `batch-${contentHash(id)}`,
51
+ taskDefinition: policy.taskDefinition, purpose: eligibility.purpose,
52
+ evidence: eligibility.selected.map((item) => learningRef(item.evidence)),
53
+ decisions: eligibility.selected.map((item) => learningRef(item.decision)),
54
+ }, actorId, now);
55
+ pointers.push(...sealed);
56
+ batch = learningRef(await requireLearningResource(transaction, "batch", sealed[0].id));
57
+ for (const item of eligibility.selected) {
58
+ const consumption = LearningConsumptionSchema.parse({
59
+ schemaVersion: "openpond.learningConsumption.v1", id: learningConsumptionId(chainId, item.evidence), revision: 1,
60
+ chainId, iterationId: id, evidence: learningRef(item.evidence), decision: learningRef(item.decision), reservedAt: now,
61
+ });
62
+ await transaction.put("consumption", consumption, 0, { parentId: chainId });
63
+ }
64
+ }
65
+ const iteration = LearningIterationSchema.parse({
66
+ schemaVersion: "openpond.learningIteration.v1", id, revision: 1, policy: input.policy, status,
67
+ triggerIdentity, batch,
68
+ // Existing evidence has no ordered ingress sequence. Consumption records,
69
+ // not a count or lexicographic ID cursor, decide whether an example is new.
70
+ sourceWatermarks: {}, trainingParent: policy.trainingParent, teacher: policy.teacher, upstreamEvent: null,
71
+ trainingJob: null, evaluationJob: null, candidateVersion: null, dispatchId: `dispatch-${contentHash(id)}`,
72
+ retryCount: 0, spendUsd: 0, failure: null, createdAt: now, updatedAt: now,
73
+ });
74
+ const reservation = LearningIterationReservationSchema.parse({
75
+ schemaVersion: "openpond.learningIterationReservation.v1", id, revision: 1, chainId, iterationId: id,
76
+ policy: input.policy, trigger, requestHash, outcome: ready ? "reserved" : status,
77
+ counts: eligibility.counts,
78
+ budget: { maximumSpendUsd: ready ? policy.limits.maxIterationSpendUsd : 0, reservedSpendUsd: ready ? policy.limits.maxIterationSpendUsd : 0, settledSpendUsd: 0, settledAt: ready ? null : now },
79
+ createdAt: now, updatedAt: now,
80
+ });
81
+ const updatedChain = LearningChainSchema.parse({
82
+ schemaVersion: "openpond.learningChain.v1", id: chainId, revision: (chain?.revision ?? 0) + 1,
83
+ modelProjectId: policy.modelProjectId, activeIterationId: ready ? id : null, latestIterationId: id,
84
+ lastReservedAt: ready ? now : chain?.lastReservedAt ?? null, updatedAt: now,
85
+ });
86
+ await transaction.put("iteration", iteration, 0, { parentId: chainId, status });
87
+ await transaction.put("reservation", reservation, 0, { parentId: chainId, status: reservation.outcome });
88
+ await transaction.put("chain", updatedChain, chain?.revision ?? 0, { parentId: policy.modelProjectId });
89
+ return [{ kind: "iteration", id, revision: 1 }, { kind: "reservation", id, revision: 1 }, ...pointers];
90
+ }
91
+ async function assertAvailableBudget(transaction, chainId, now, requested, maximum) {
92
+ let committed = 0;
93
+ let afterId;
94
+ do {
95
+ const page = await transaction.list("reservation", { parentId: chainId, limit: 100, ...(afterId ? { afterId } : {}) });
96
+ for (const { budget } of page.items) {
97
+ // Unsettled reservations carry across midnight and worker restarts.
98
+ committed += budget.reservedSpendUsd;
99
+ if (budget.settledAt && new Date(budget.settledAt).toISOString().slice(0, 10) === new Date(now).toISOString().slice(0, 10))
100
+ committed += budget.settledSpendUsd;
101
+ }
102
+ afterId = page.nextCursor ?? undefined;
103
+ } while (afterId);
104
+ if (committed + requested > maximum)
105
+ throw new LearningDomainError("learning_daily_budget_exhausted", 409);
106
+ }
@@ -1,3 +1,4 @@
1
+ import { LearningIterationTriggerSchema } from "./iteration-reservation-contracts.js";
1
2
  import { z } from "zod";
2
3
  import { ReleaseIdSchema } from "@openpond/harness";
3
4
  import { LearningJsonObjectSchema, LearningRevisionRefSchema, LearningSourceContentSchema, TaskDefinitionContentSchema, TaskExampleSubmissionSchema, TaskFeedbackSubmissionSchema, LearningPolicyContentSchema } from "./contracts.js";
@@ -36,4 +37,8 @@ export const SaveAuthoringDraftCommandSchema = command.extend({ action: z.litera
36
37
  export const ArchiveAuthoringDraftCommandSchema = command.extend({ action: z.literal("archive_draft"), draft: LearningRevisionRefSchema }).strict();
37
38
  export const QueueRewardCheckCommandSchema = command.extend({ action: z.literal("queue_reward_check"), draft: LearningRevisionRefSchema, timeoutMs: z.number().int().min(100).max(300_000).default(30_000), maximumSpendUsd: z.number().nonnegative().max(1_000).default(0) }).strict();
38
39
  export const CancelRewardCheckCommandSchema = command.extend({ action: z.literal("cancel_reward_check"), checkId: ReleaseIdSchema, expectedRevision: z.number().int().positive() }).strict();
39
- export const LearningCommandSchema = z.union([QueueRewardCheckCommandSchema, CancelRewardCheckCommandSchema, SaveAuthoringDraftCommandSchema, ArchiveAuthoringDraftCommandSchema, PublishLearningResourceCommandSchema, PublishLearningResourcesCommandSchema, SubmitTaskExampleCommandSchema, SubmitTaskFeedbackCommandSchema, ApplyTaskCorrectionCommandSchema, ResolveTaskFeedbackCommandSchema, QueueTaskGradeCommandSchema, ReviewTaskEvidenceCommandSchema, SealTaskBatchCommandSchema, CancelTaskGradeCommandSchema]);
40
+ export const ReserveLearningIterationCommandSchema = command.extend({ action: z.literal("reserve_iteration"), policy: LearningRevisionRefSchema, trigger: LearningIterationTriggerSchema }).strict();
41
+ export const CancelLearningIterationReservationCommandSchema = command.extend({ action: z.literal("cancel_iteration_reservation"), iterationId: ReleaseIdSchema, expectedRevision: z.number().int().positive() }).strict();
42
+ export const CancelLearningIterationCommandSchema = command.extend({ action: z.literal("cancel_iteration"), iterationId: ReleaseIdSchema, expectedRevision: z.number().int().positive() }).strict();
43
+ export const RetryLearningIterationDispatchCommandSchema = command.extend({ action: z.literal("retry_iteration_dispatch"), iterationId: ReleaseIdSchema, expectedRevision: z.number().int().positive() }).strict();
44
+ export const LearningCommandSchema = z.union([CancelLearningIterationCommandSchema, RetryLearningIterationDispatchCommandSchema, CancelLearningIterationReservationCommandSchema, ReserveLearningIterationCommandSchema, QueueRewardCheckCommandSchema, CancelRewardCheckCommandSchema, SaveAuthoringDraftCommandSchema, ArchiveAuthoringDraftCommandSchema, PublishLearningResourceCommandSchema, PublishLearningResourcesCommandSchema, SubmitTaskExampleCommandSchema, SubmitTaskFeedbackCommandSchema, ApplyTaskCorrectionCommandSchema, ResolveTaskFeedbackCommandSchema, QueueTaskGradeCommandSchema, ReviewTaskEvidenceCommandSchema, SealTaskBatchCommandSchema, CancelTaskGradeCommandSchema]);
@@ -1,3 +1,5 @@
1
+ import { LearningChainSchema, LearningConsumptionSchema, LearningIterationReservationSchema } from "./iteration-reservation-contracts.js";
2
+ import { LearningIterationDispatchSchema } from "./iteration-dispatch-contracts.js";
1
3
  import { z } from "zod";
2
4
  import { contentHash } from "@openpond/harness";
3
5
  import { assertLearningContentHash, LearningSourceSchema, TaskAdmissionDecisionSchema, TaskBatchSchema, TaskDefinitionSchema, TaskEvidenceSchema, TaskFeedbackSchema, TaskGradeRunSchema, LearningPolicySchema, LearningIterationSchema } from "./contracts.js";
@@ -14,6 +16,8 @@ export const learningResourceSchemas = {
14
16
  definition: TaskDefinitionSchema, reward: RewardReleaseSchema, binding: RewardBindingSchema,
15
17
  source: LearningSourceSchema, evidence: TaskEvidenceSchema, feedback: TaskFeedbackSchema,
16
18
  decision: TaskAdmissionDecisionSchema, batch: TaskBatchSchema, policy: LearningPolicySchema,
19
+ chain: LearningChainSchema, consumption: LearningConsumptionSchema, reservation: LearningIterationReservationSchema,
20
+ dispatch: LearningIterationDispatchSchema,
17
21
  iteration: LearningIterationSchema, grade: TaskGradeRunSchema, package: TasksetReleaseSchema,
18
22
  };
19
23
  export const LearningResourceKindSchema = z.enum(Object.keys(learningResourceSchemas));
@@ -1,10 +1,14 @@
1
+ import { cancelLearningIterationReservation } from "./iteration-reservation-cancellation.js";
2
+ import { commandLearningIterationDispatch } from "./iteration-dispatch-commands.js";
3
+ import { reserveLearningIteration } from "./iteration-reservation-service.js";
4
+ import { requireCurrentLearningEvidence as currentEvidence, sealLearningBatch } from "./batch-service.js";
1
5
  import { saveAuthoringDraft, archiveAuthoringDraft, finalizeAuthoringDraft } from "./authoring-service.js";
2
6
  import { queueRewardCheck, cancelRewardCheck } from "./reward-check-service.js";
3
7
  import { LearningDomainError } from "./errors.js";
4
8
  import { contentHash } from "@openpond/harness";
5
- import { createRewardBinding, createRewardRelease, resolveBoundRewards } from "../rewards.js";
9
+ import { createRewardBinding, createRewardRelease } from "../rewards.js";
6
10
  import { assertBoundedTaskJson, validateTaskValue } from "../task-schema.js";
7
- import { assertAdmissionDecision, assertGradeIdentity, compileTaskBatch, inspectTaskEvidence, sealTaskBatch, taskFamilyReservations } from "./admission.js";
11
+ import { assertAdmissionDecision, assertGradeIdentity, inspectTaskEvidence } from "./admission.js";
8
12
  import { learningRef, LearningSourceSchema, LearningPolicySchema, sameLearningRef, sealLearningContent, TaskAdmissionDecisionContentSchema, TaskAdmissionDecisionSchema, TaskDefinitionSchema, TaskEvidenceContentSchema, TaskEvidenceSchema, TaskFeedbackSchema, TaskGradeRunSchema } from "./contracts.js";
9
13
  import { LearningCommandSchema } from "./operations.js";
10
14
  import { LearningConflictError, learningEvidenceId, learningOperationId, requireLearningRelease, requireLearningResource } from "./repository.js";
@@ -29,6 +33,16 @@ export function createLearningService(repository, options = {}) {
29
33
  }
30
34
  let pointers;
31
35
  switch (input.action) {
36
+ case "cancel_iteration":
37
+ case "retry_iteration_dispatch":
38
+ pointers = await commandLearningIterationDispatch(transaction, input, now());
39
+ break;
40
+ case "cancel_iteration_reservation":
41
+ pointers = await cancelLearningIterationReservation(transaction, input, now());
42
+ break;
43
+ case "reserve_iteration":
44
+ pointers = await reserveLearningIteration(transaction, input, context.actor.id, now());
45
+ break;
32
46
  case "queue_reward_check":
33
47
  pointers = [await queueRewardCheck(transaction, input, operationId, now())];
34
48
  break;
@@ -72,7 +86,7 @@ export function createLearningService(repository, options = {}) {
72
86
  pointers = [await review(transaction, input, context.actor.id)];
73
87
  break;
74
88
  case "seal_batch":
75
- pointers = await seal(transaction, input, context.actor.id);
89
+ pointers = await sealLearningBatch(transaction, input, context.actor.id, now());
76
90
  break;
77
91
  }
78
92
  if (input.action === "publish" || input.action === "publish_resources") {
@@ -143,7 +157,7 @@ export function createLearningService(repository, options = {}) {
143
157
  break;
144
158
  }
145
159
  }
146
- await transaction.put(input.kind, resource, input.expectedRevision);
160
+ await transaction.put(input.kind, resource, input.expectedRevision, input.kind === "policy" ? { parentId: input.content.modelProjectId } : undefined);
147
161
  return pointer(input.kind, resource);
148
162
  }
149
163
  async function submit(transaction, input) {
@@ -308,37 +322,6 @@ export function createLearningService(repository, options = {}) {
308
322
  await transaction.put("decision", decision, input.expectedRevision, { parentId: evidence.id, status: decision.taskAdmissibility });
309
323
  return pointer("decision", decision);
310
324
  }
311
- async function seal(transaction, input, actorId) {
312
- const definition = await requireLearningRelease(transaction, "definition", input.taskDefinition);
313
- const binding = await requireLearningRelease(transaction, "binding", definition.rewardBinding);
314
- const rewards = await Promise.all(binding.sources.map((source) => requireLearningRelease(transaction, "reward", source.reward)));
315
- resolveBoundRewards(binding, rewards);
316
- const evidence = await Promise.all(input.evidence.map((ref) => currentEvidence(transaction, ref)));
317
- const decisions = await Promise.all(input.decisions.map(async (ref) => {
318
- const decision = await requireLearningRelease(transaction, "decision", ref);
319
- const current = await requireLearningResource(transaction, "decision", ref.id);
320
- if (!sameLearningRef(learningRef(current), ref))
321
- throw new LearningDomainError("task_admission_revision_stale", 409);
322
- return decision;
323
- }));
324
- const priorSplits = [];
325
- for (const item of evidence) {
326
- for (const reservation of taskFamilyReservations(item, definition)) {
327
- const split = await transaction.familySplit(reservation.namespace, reservation.kind, reservation.key);
328
- if (split !== null)
329
- priorSplits.push({ ...reservation, split: split });
330
- }
331
- }
332
- const batch = sealTaskBatch({ id: input.batchId, definition, binding, rewards, purpose: input.purpose, evidence, decisions, priorSplits, actorId, now: now() });
333
- const release = compileTaskBatch({ batch, definition, binding, rewards, evidence, decisions });
334
- for (const item of evidence) {
335
- for (const reservation of taskFamilyReservations(item, definition))
336
- await transaction.reserveFamilySplit(reservation.namespace, reservation.kind, reservation.key, reservation.split);
337
- }
338
- await transaction.put("batch", batch, 0, { parentId: definition.id });
339
- await transaction.put("package", release, 0, { parentId: batch.id });
340
- return [pointer("batch", batch), pointer("package", release)];
341
- }
342
325
  return {
343
326
  command,
344
327
  async inspectEvidence(context, reference) {
@@ -361,13 +344,6 @@ export function createLearningService(repository, options = {}) {
361
344
  },
362
345
  };
363
346
  }
364
- async function currentEvidence(transaction, ref) {
365
- const evidence = await requireLearningRelease(transaction, "evidence", ref);
366
- const current = await requireLearningResource(transaction, "evidence", ref.id);
367
- if (!sameLearningRef(learningRef(current), ref))
368
- throw new LearningDomainError("task_evidence_revision_stale", 409);
369
- return evidence;
370
- }
371
347
  async function gradeResult(transaction, id, evidence, target) {
372
348
  if (id === null)
373
349
  return null;
@@ -391,6 +367,6 @@ function authorize(context, input) {
391
367
  if (!sourceId || sourceId !== context.actor.sourceId)
392
368
  throw new LearningDomainError("learning_source_not_authorized", 403);
393
369
  }
394
- if (["review", "apply_correction", "resolve_feedback", "seal_batch"].includes(input.action) && context.actor.role !== "reviewer")
370
+ if (["review", "apply_correction", "resolve_feedback", "seal_batch", "reserve_iteration", "cancel_iteration_reservation", "cancel_iteration", "retry_iteration_dispatch"].includes(input.action) && context.actor.role !== "reviewer")
395
371
  throw new LearningDomainError("learning_review_not_authorized", 403);
396
372
  }
@@ -0,0 +1,8 @@
1
+ import { type LearningRevisionRef, type TaskEvidence } from "./contracts.js";
2
+ import type { LearningCommand } from "./operations.js";
3
+ import { type LearningResourcePointer, type LearningTransaction } from "./repository.js";
4
+ export declare function sealLearningBatch(transaction: LearningTransaction, input: Extract<LearningCommand, {
5
+ action: "seal_batch";
6
+ }>, actorId: string, timestamp: string): Promise<LearningResourcePointer[]>;
7
+ export declare function requireCurrentLearningEvidence(transaction: LearningTransaction, ref: LearningRevisionRef): Promise<TaskEvidence>;
8
+ //# sourceMappingURL=batch-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-service.d.ts","sourceRoot":"","sources":["../../../../../src/learning/batch-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAA8E,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAErK,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,mBAAmB,EAAE,KAAK,EAAE,OAAO,CAAC,eAAe,EAAE;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CA2B3M;AAED,wBAAsB,8BAA8B,CAAC,WAAW,EAAE,mBAAmB,EAAE,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAKtI"}
@@ -1183,10 +1183,12 @@ export declare const LearningIterationStatusSchema: z.ZodEnum<{
1183
1183
  waiting_for_data: "waiting_for_data";
1184
1184
  waiting_for_review: "waiting_for_review";
1185
1185
  ready: "ready";
1186
+ dispatching: "dispatching";
1186
1187
  evaluating: "evaluating";
1187
1188
  candidate_ready: "candidate_ready";
1188
1189
  paused: "paused";
1189
1190
  cancelling: "cancelling";
1191
+ completed_without_candidate: "completed_without_candidate";
1190
1192
  }>;
1191
1193
  export declare const LearningIterationSchema: z.ZodObject<{
1192
1194
  schemaVersion: z.ZodLiteral<"openpond.learningIteration.v1">;
@@ -1206,10 +1208,12 @@ export declare const LearningIterationSchema: z.ZodObject<{
1206
1208
  waiting_for_data: "waiting_for_data";
1207
1209
  waiting_for_review: "waiting_for_review";
1208
1210
  ready: "ready";
1211
+ dispatching: "dispatching";
1209
1212
  evaluating: "evaluating";
1210
1213
  candidate_ready: "candidate_ready";
1211
1214
  paused: "paused";
1212
1215
  cancelling: "cancelling";
1216
+ completed_without_candidate: "completed_without_candidate";
1213
1217
  }>;
1214
1218
  triggerIdentity: z.ZodString;
1215
1219
  batch: z.ZodNullable<z.ZodObject<{
@@ -1242,6 +1246,11 @@ export declare const LearningIterationSchema: z.ZodObject<{
1242
1246
  id: z.ZodString;
1243
1247
  contentHash: z.ZodString;
1244
1248
  }, z.core.$strict>>;
1249
+ candidateDecision: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1250
+ id: z.ZodString;
1251
+ contentHash: z.ZodString;
1252
+ revision: z.ZodNumber;
1253
+ }, z.core.$strict>>>;
1245
1254
  dispatchId: z.ZodString;
1246
1255
  retryCount: z.ZodNumber;
1247
1256
  spendUsd: z.ZodNumber;
@@ -2078,10 +2087,12 @@ export declare const LearningResourceSchema: z.ZodUnion<readonly [z.ZodObject<{
2078
2087
  waiting_for_data: "waiting_for_data";
2079
2088
  waiting_for_review: "waiting_for_review";
2080
2089
  ready: "ready";
2090
+ dispatching: "dispatching";
2081
2091
  evaluating: "evaluating";
2082
2092
  candidate_ready: "candidate_ready";
2083
2093
  paused: "paused";
2084
2094
  cancelling: "cancelling";
2095
+ completed_without_candidate: "completed_without_candidate";
2085
2096
  }>;
2086
2097
  triggerIdentity: z.ZodString;
2087
2098
  batch: z.ZodNullable<z.ZodObject<{
@@ -2114,6 +2125,11 @@ export declare const LearningResourceSchema: z.ZodUnion<readonly [z.ZodObject<{
2114
2125
  id: z.ZodString;
2115
2126
  contentHash: z.ZodString;
2116
2127
  }, z.core.$strict>>;
2128
+ candidateDecision: z.ZodDefault<z.ZodNullable<z.ZodObject<{
2129
+ id: z.ZodString;
2130
+ contentHash: z.ZodString;
2131
+ revision: z.ZodNumber;
2132
+ }, z.core.$strict>>>;
2117
2133
  dispatchId: z.ZodString;
2118
2134
  retryCount: z.ZodNumber;
2119
2135
  spendUsd: z.ZodNumber;
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../../../src/learning/contracts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,wBAAwB,2CAAiC,CAAC;AACvE,eAAO,MAAM,yBAAyB;;;;kBAAyB,CAAC;AAChE,eAAO,MAAM,yBAAyB,aAAiJ,CAAC;AAExL,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAsBtC,CAAC;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAsF,CAAC;AAExH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;kBAWzB,CAAC;AACZ;0EAC0E;AAC1E,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;kBAM5B,CAAC;AACZ,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgBtC,CAAC;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAsF,CAAC;AAExH,eAAO,MAA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C,CAAC;AAC9D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACtE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,wBAAgB,WAAW,CAAC,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,mBAAmB,CAEhH;AACD,wBAAgB,eAAe,CAAC,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAE9F;AACD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAG9G;AACD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAIjF"}
@@ -12,4 +12,8 @@ export * from "./reward-authoring.js";
12
12
  export * from "./reward-checks.js";
13
13
  export * from "./reward-check-worker.js";
14
14
  export * from "./reward-fixture-executor.js";
15
+ export * from "./iteration-reservation-contracts.js";
16
+ export * from "./iteration-dispatch-contracts.js";
17
+ export * from "./iteration-dispatch-worker.js";
18
+ export * from "./iteration-candidate-decision.js";
15
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/learning/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/learning/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ import { type LearningRepository } from "./repository.js";
3
+ export declare const LearningCandidateDecisionObservationSchema: z.ZodObject<{
4
+ scope: z.ZodString;
5
+ iterationId: z.ZodString;
6
+ decision: z.ZodObject<{
7
+ id: z.ZodString;
8
+ contentHash: z.ZodString;
9
+ revision: z.ZodNumber;
10
+ }, z.core.$strict>;
11
+ outcome: z.ZodEnum<{
12
+ rejected: "rejected";
13
+ accepted: "accepted";
14
+ }>;
15
+ execution: z.ZodObject<{
16
+ id: z.ZodString;
17
+ contentHash: z.ZodString;
18
+ }, z.core.$strict>;
19
+ candidate: z.ZodObject<{
20
+ id: z.ZodString;
21
+ contentHash: z.ZodString;
22
+ }, z.core.$strict>;
23
+ evaluation: z.ZodObject<{
24
+ id: z.ZodString;
25
+ contentHash: z.ZodString;
26
+ }, z.core.$strict>;
27
+ receipt: z.ZodObject<{
28
+ id: z.ZodString;
29
+ contentHash: z.ZodString;
30
+ }, z.core.$strict>;
31
+ }, z.core.$strict>;
32
+ export type LearningCandidateDecisionObservation = z.infer<typeof LearningCandidateDecisionObservationSchema>;
33
+ /** Trusted host boundary: verify the provider's immutable decision and ownership
34
+ * before calling. This reconciles retained evidence; it does not authorize a
35
+ * review, accept a model automatically, or activate serving. */
36
+ export declare function reconcileLearningCandidateDecision(repository: LearningRepository, value: LearningCandidateDecisionObservation, options?: {
37
+ now?: () => string;
38
+ }): Promise<{
39
+ schemaVersion: "openpond.learningIteration.v1";
40
+ id: string;
41
+ revision: number;
42
+ policy: {
43
+ id: string;
44
+ contentHash: string;
45
+ revision: number;
46
+ };
47
+ status: "failed" | "cancelled" | "rejected" | "accepted" | "training" | "waiting_for_data" | "waiting_for_review" | "ready" | "dispatching" | "evaluating" | "candidate_ready" | "paused" | "cancelling" | "completed_without_candidate";
48
+ triggerIdentity: string;
49
+ batch: {
50
+ id: string;
51
+ contentHash: string;
52
+ revision: number;
53
+ } | null;
54
+ sourceWatermarks: Record<string, number>;
55
+ trainingParent: {
56
+ id: string;
57
+ contentHash: string;
58
+ };
59
+ teacher: {
60
+ id: string;
61
+ contentHash: string;
62
+ } | null;
63
+ upstreamEvent: {
64
+ id: string;
65
+ contentHash: string;
66
+ } | null;
67
+ trainingJob: {
68
+ id: string;
69
+ contentHash: string;
70
+ } | null;
71
+ evaluationJob: {
72
+ id: string;
73
+ contentHash: string;
74
+ } | null;
75
+ candidateVersion: {
76
+ id: string;
77
+ contentHash: string;
78
+ } | null;
79
+ candidateDecision: {
80
+ id: string;
81
+ contentHash: string;
82
+ revision: number;
83
+ } | null;
84
+ dispatchId: string;
85
+ retryCount: number;
86
+ spendUsd: number;
87
+ failure: {
88
+ code: string;
89
+ message: string;
90
+ } | null;
91
+ createdAt: string;
92
+ updatedAt: string;
93
+ }>;
94
+ //# sourceMappingURL=iteration-candidate-decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iteration-candidate-decision.d.ts","sourceRoot":"","sources":["../../../../../src/learning/iteration-candidate-decision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAA2B,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEnF,eAAO,MAAM,0CAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAS5C,CAAC;AACZ,MAAM,MAAM,oCAAoC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0CAA0C,CAAC,CAAC;AAE9G;;gEAEgE;AAChE,wBAAsB,kCAAkC,CAAC,UAAU,EAAE,kBAAkB,EAAE,KAAK,EAAE,oCAAoC,EAClI,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BrC"}
@@ -0,0 +1,8 @@
1
+ import type { LearningCommand } from "./operations.js";
2
+ import { type LearningResourcePointer, type LearningTransaction } from "./repository.js";
3
+ type DispatchCommand = Extract<LearningCommand, {
4
+ action: "cancel_iteration" | "retry_iteration_dispatch";
5
+ }>;
6
+ export declare function commandLearningIterationDispatch(tx: LearningTransaction, input: DispatchCommand, now: string): Promise<LearningResourcePointer[]>;
7
+ export {};
8
+ //# sourceMappingURL=iteration-dispatch-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iteration-dispatch-commands.d.ts","sourceRoot":"","sources":["../../../../../src/learning/iteration-dispatch-commands.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAkD,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEzI,KAAK,eAAe,GAAG,OAAO,CAAC,eAAe,EAAE;IAAE,MAAM,EAAE,kBAAkB,GAAG,0BAA0B,CAAA;CAAE,CAAC,CAAC;AAE7G,wBAAsB,gCAAgC,CAAC,EAAE,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAoBvJ"}
@@ -0,0 +1,93 @@
1
+ import { z } from "zod";
2
+ /** The executor validates its protocol payload before returning this snapshot.
3
+ * Credentials and expiring transport URLs belong to the executor, not payload. */
4
+ export declare const LearningIterationSubmissionSchema: z.ZodObject<{
5
+ provider: z.ZodString;
6
+ protocol: z.ZodString;
7
+ payload: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
8
+ }, z.core.$strict>;
9
+ export declare const LearningIterationDispatchSchema: z.ZodObject<{
10
+ schemaVersion: z.ZodLiteral<"openpond.learningIterationDispatch.v1">;
11
+ id: z.ZodString;
12
+ revision: z.ZodNumber;
13
+ iterationId: z.ZodString;
14
+ chainId: z.ZodString;
15
+ policy: z.ZodObject<{
16
+ id: z.ZodString;
17
+ contentHash: z.ZodString;
18
+ revision: z.ZodNumber;
19
+ }, z.core.$strict>;
20
+ batch: z.ZodObject<{
21
+ id: z.ZodString;
22
+ contentHash: z.ZodString;
23
+ revision: z.ZodNumber;
24
+ }, z.core.$strict>;
25
+ state: z.ZodEnum<{
26
+ blocked: "blocked";
27
+ preparing: "preparing";
28
+ prepared: "prepared";
29
+ submitted: "submitted";
30
+ settled: "settled";
31
+ }>;
32
+ submission: z.ZodNullable<z.ZodObject<{
33
+ provider: z.ZodString;
34
+ protocol: z.ZodString;
35
+ payload: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
36
+ }, z.core.$strict>>;
37
+ submissionHash: z.ZodNullable<z.ZodString>;
38
+ submissionStartedAt: z.ZodNullable<z.ZodString>;
39
+ execution: z.ZodNullable<z.ZodObject<{
40
+ id: z.ZodString;
41
+ contentHash: z.ZodString;
42
+ }, z.core.$strict>>;
43
+ terminalReceipt: z.ZodNullable<z.ZodObject<{
44
+ id: z.ZodString;
45
+ contentHash: z.ZodString;
46
+ }, z.core.$strict>>;
47
+ cancelRequestedAt: z.ZodNullable<z.ZodString>;
48
+ leaseOwner: z.ZodNullable<z.ZodString>;
49
+ leaseGeneration: z.ZodNumber;
50
+ leaseExpiresAt: z.ZodNullable<z.ZodString>;
51
+ consecutiveFailures: z.ZodNumber;
52
+ nextAttemptAt: z.ZodNullable<z.ZodString>;
53
+ lastError: z.ZodNullable<z.ZodString>;
54
+ createdAt: z.ZodString;
55
+ updatedAt: z.ZodString;
56
+ }, z.core.$strict>;
57
+ /** Terminal cleanup includes fencing future submission under this dispatch ID.
58
+ * The execution adapter verifies its authoritative provider receipt. */
59
+ export declare const LearningIterationObservationSchema: z.ZodObject<{
60
+ scope: z.ZodString;
61
+ dispatchId: z.ZodString;
62
+ submissionHash: z.ZodString;
63
+ execution: z.ZodNullable<z.ZodObject<{
64
+ id: z.ZodString;
65
+ contentHash: z.ZodString;
66
+ }, z.core.$strict>>;
67
+ status: z.ZodEnum<{
68
+ failed: "failed";
69
+ cancelled: "cancelled";
70
+ running: "running";
71
+ evaluating: "evaluating";
72
+ succeeded: "succeeded";
73
+ }>;
74
+ spendUsd: z.ZodNumber;
75
+ cleanupComplete: z.ZodBoolean;
76
+ receipt: z.ZodNullable<z.ZodObject<{
77
+ id: z.ZodString;
78
+ contentHash: z.ZodString;
79
+ }, z.core.$strict>>;
80
+ evaluation: z.ZodNullable<z.ZodObject<{
81
+ id: z.ZodString;
82
+ contentHash: z.ZodString;
83
+ }, z.core.$strict>>;
84
+ candidate: z.ZodNullable<z.ZodObject<{
85
+ id: z.ZodString;
86
+ contentHash: z.ZodString;
87
+ }, z.core.$strict>>;
88
+ failure: z.ZodNullable<z.ZodString>;
89
+ }, z.core.$strict>;
90
+ export type LearningIterationSubmission = z.infer<typeof LearningIterationSubmissionSchema>;
91
+ export type LearningIterationDispatch = z.infer<typeof LearningIterationDispatchSchema>;
92
+ export type LearningIterationObservation = z.infer<typeof LearningIterationObservationSchema>;
93
+ //# sourceMappingURL=iteration-dispatch-contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iteration-dispatch-contracts.d.ts","sourceRoot":"","sources":["../../../../../src/learning/iteration-dispatch-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;kFACkF;AAClF,eAAO,MAAM,iCAAiC;;;;kBAInC,CAAC;AAEZ,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAiC1C,CAAC;AAEH;wEACwE;AACxE,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkB7C,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAC;AAC5F,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AACxF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kCAAkC,CAAC,CAAC"}