@openpond/evals 0.7.1 → 0.7.2
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/learning/authoring-service.js +49 -0
- package/dist/learning/authoring.js +37 -0
- package/dist/learning/index.js +1 -0
- package/dist/learning/operations.js +7 -3
- package/dist/learning/repository.js +2 -0
- package/dist/learning/service.js +12 -0
- package/dist/types/learning/authoring-service.d.ts +25 -0
- package/dist/types/learning/authoring-service.d.ts.map +1 -0
- package/dist/types/learning/authoring.d.ts +672 -0
- package/dist/types/learning/authoring.d.ts.map +1 -0
- package/dist/types/learning/index.d.ts +1 -0
- package/dist/types/learning/index.d.ts.map +1 -1
- package/dist/types/learning/operations.d.ts +557 -1
- package/dist/types/learning/operations.d.ts.map +1 -1
- package/dist/types/learning/repository.d.ts +192 -0
- package/dist/types/learning/repository.d.ts.map +1 -1
- package/dist/types/learning/service.d.ts.map +1 -1
- package/dist/types/learning/transport.d.ts +471 -2
- package/dist/types/learning/transport.d.ts.map +1 -1
- package/package.json +1 -1
- package/schemas/learning/v1/command-request.schema.json +757 -366
- package/schemas/learning/v1/draft.schema.json +562 -0
- package/schemas/learning/v1/read-request.schema.json +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { assertBoundedTaskJson } from "../task-schema.js";
|
|
2
|
+
import { AuthoringDraftSchema } from "./authoring.js";
|
|
3
|
+
import { LearningDomainError } from "./errors.js";
|
|
4
|
+
import { learningRef, sameLearningRef, sealLearningContent } from "./contracts.js";
|
|
5
|
+
import { requireLearningRelease } from "./repository.js";
|
|
6
|
+
export async function saveAuthoringDraft(tx, input, now) {
|
|
7
|
+
// A 100-record page remains below the common 16 MiB response limit.
|
|
8
|
+
assertBoundedTaskJson(input.draft, 131_072);
|
|
9
|
+
const previous = await tx.get("draft", input.draft.id);
|
|
10
|
+
if (previous && (previous.status !== "draft" || previous.targetId !== input.draft.targetId || previous.targetKind !== input.draft.targetKind || (previous.baseRelease === null ? input.draft.baseRelease !== null : input.draft.baseRelease === null || !sameLearningRef(previous.baseRelease, input.draft.baseRelease))))
|
|
11
|
+
throw new LearningDomainError("authoring_draft_identity_conflict", 409);
|
|
12
|
+
if (input.draft.baseRelease) {
|
|
13
|
+
if (input.draft.baseRelease.id !== input.draft.targetId)
|
|
14
|
+
throw new LearningDomainError("authoring_draft_base_mismatch", 422);
|
|
15
|
+
await requireLearningRelease(tx, input.draft.targetKind, input.draft.baseRelease);
|
|
16
|
+
}
|
|
17
|
+
const draft = AuthoringDraftSchema.parse(sealLearningContent({ ...input.draft, schemaVersion: "openpond.authoringDraft.v1", revision: input.expectedRevision + 1, status: "draft", publishedRelease: null, createdAt: previous?.createdAt ?? now, updatedAt: now }));
|
|
18
|
+
await tx.put("draft", draft, input.expectedRevision, { parentId: draft.targetKind, status: draft.status });
|
|
19
|
+
return { kind: "draft", id: draft.id, revision: draft.revision };
|
|
20
|
+
}
|
|
21
|
+
export async function archiveAuthoringDraft(tx, ref, now) {
|
|
22
|
+
const draft = await currentDraft(tx, ref);
|
|
23
|
+
const { contentHash: _hash, ...content } = draft;
|
|
24
|
+
const archived = AuthoringDraftSchema.parse(sealLearningContent({ ...content, revision: draft.revision + 1, status: "archived", updatedAt: now }));
|
|
25
|
+
await tx.put("draft", archived, draft.revision, { parentId: draft.targetKind, status: archived.status });
|
|
26
|
+
return { kind: "draft", id: archived.id, revision: archived.revision };
|
|
27
|
+
}
|
|
28
|
+
export async function finalizeAuthoringDraft(tx, input, published, now) {
|
|
29
|
+
const finalization = input.finalizeDraft;
|
|
30
|
+
if (!finalization)
|
|
31
|
+
return null;
|
|
32
|
+
const draft = await currentDraft(tx, finalization.draft);
|
|
33
|
+
if (draft.targetKind !== finalization.targetKind || draft.targetId !== finalization.release.id || finalization.release.revision !== (draft.baseRelease?.revision ?? 0) + 1 || !published.some(value => value.kind === finalization.targetKind && value.id === finalization.release.id && value.revision === finalization.release.revision))
|
|
34
|
+
throw new LearningDomainError("authoring_draft_publication_mismatch", 422);
|
|
35
|
+
await requireLearningRelease(tx, finalization.targetKind, finalization.release);
|
|
36
|
+
const { contentHash: _hash, ...content } = draft;
|
|
37
|
+
const completed = AuthoringDraftSchema.parse(sealLearningContent({ ...content, revision: draft.revision + 1, status: "published", publishedRelease: finalization.release, updatedAt: now }));
|
|
38
|
+
await tx.put("draft", completed, draft.revision, { parentId: draft.targetKind, status: completed.status });
|
|
39
|
+
return { kind: "draft", id: completed.id, revision: completed.revision };
|
|
40
|
+
}
|
|
41
|
+
async function currentDraft(tx, ref) {
|
|
42
|
+
const draft = await requireLearningRelease(tx, "draft", ref);
|
|
43
|
+
const current = await tx.get("draft", ref.id);
|
|
44
|
+
if (!current || !sameLearningRef(learningRef(current), ref))
|
|
45
|
+
throw new LearningDomainError("authoring_draft_revision_stale", 409);
|
|
46
|
+
if (draft.status !== "draft")
|
|
47
|
+
throw new LearningDomainError("authoring_draft_closed", 409);
|
|
48
|
+
return draft;
|
|
49
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ReleaseHashSchema, ReleaseIdSchema, ReleaseTimestampSchema } from "@openpond/harness";
|
|
3
|
+
import { RewardBindingSourceSchema, RewardReleaseRefSchema } from "../rewards.js";
|
|
4
|
+
import { LearningRevisionRefSchema } from "./contracts.js";
|
|
5
|
+
/** Strings intentionally preserve incomplete JSON/code until explicit publication. */
|
|
6
|
+
export const RewardAuthoringFieldsSchema = z.object({
|
|
7
|
+
name: z.string().max(500), description: z.string().max(10_000),
|
|
8
|
+
kind: z.enum(["custom_verifier", "state", "content", "schema", "artifact", "runtime_event", "model_judge", "learned_model", "human"]),
|
|
9
|
+
fields: z.string(), outputField: z.string(), expectedField: z.string(), expectedValue: z.string(),
|
|
10
|
+
schema: z.string(), reference: z.string(), events: z.string(), code: z.string(), exportName: z.string(), timeout: z.string(),
|
|
11
|
+
rubric: z.string(), providerId: z.string(), modelId: z.string(), modelRevision: z.string(), temperature: z.string(),
|
|
12
|
+
reviewerRole: z.string(), learnedId: z.string(), learnedHash: z.string(), inputContract: z.string(), minimum: z.string(), maximum: z.string(),
|
|
13
|
+
}).strict();
|
|
14
|
+
export const TaskFormatAuthoringFieldsSchema = z.object({
|
|
15
|
+
name: z.string().max(500), description: z.string().max(10_000), instructions: z.string().max(20_000),
|
|
16
|
+
input: z.string(), output: z.string(), familyNamespace: z.string(),
|
|
17
|
+
sources: z.array(RewardBindingSourceSchema).max(100), recipeRef: RewardReleaseRefSchema.optional(),
|
|
18
|
+
}).strict();
|
|
19
|
+
export const CombinedRewardAuthoringFieldsSchema = z.object({
|
|
20
|
+
name: z.string().max(500), description: z.string().max(10_000), sources: z.array(RewardBindingSourceSchema).max(100),
|
|
21
|
+
}).strict();
|
|
22
|
+
export const AuthoringTargetKindSchema = z.enum(["definition", "reward", "binding"]);
|
|
23
|
+
const base = z.object({ id: ReleaseIdSchema, targetId: ReleaseIdSchema, baseRelease: LearningRevisionRefSchema.nullable(), editorVersion: z.literal("openpond.modelsEditor.v1") });
|
|
24
|
+
export const AuthoringDraftInputSchema = z.discriminatedUnion("targetKind", [
|
|
25
|
+
base.extend({ targetKind: z.literal("definition"), fields: TaskFormatAuthoringFieldsSchema }).strict(),
|
|
26
|
+
base.extend({ targetKind: z.literal("reward"), fields: RewardAuthoringFieldsSchema }).strict(),
|
|
27
|
+
base.extend({ targetKind: z.literal("binding"), fields: CombinedRewardAuthoringFieldsSchema }).strict(),
|
|
28
|
+
]);
|
|
29
|
+
const history = {
|
|
30
|
+
schemaVersion: z.literal("openpond.authoringDraft.v1"), revision: z.number().int().positive(),
|
|
31
|
+
status: z.enum(["draft", "archived", "published"]), publishedRelease: LearningRevisionRefSchema.nullable(),
|
|
32
|
+
createdAt: ReleaseTimestampSchema, updatedAt: ReleaseTimestampSchema,
|
|
33
|
+
};
|
|
34
|
+
export const AuthoringDraftContentSchema = z.discriminatedUnion("targetKind", [AuthoringDraftInputSchema.options[0].extend(history).strict(), AuthoringDraftInputSchema.options[1].extend(history).strict(), AuthoringDraftInputSchema.options[2].extend(history).strict()]);
|
|
35
|
+
export const AuthoringDraftSchema = z.discriminatedUnion("targetKind", [AuthoringDraftContentSchema.options[0].extend({ contentHash: ReleaseHashSchema }).strict(), AuthoringDraftContentSchema.options[1].extend({ contentHash: ReleaseHashSchema }).strict(), AuthoringDraftContentSchema.options[2].extend({ contentHash: ReleaseHashSchema }).strict()]);
|
|
36
|
+
/** Exact draft and resulting release are finalized in the publication transaction. */
|
|
37
|
+
export const AuthoringDraftFinalizationSchema = z.object({ draft: LearningRevisionRefSchema, targetKind: AuthoringTargetKindSchema, release: LearningRevisionRefSchema }).strict();
|
package/dist/learning/index.js
CHANGED
|
@@ -2,9 +2,10 @@ import { z } from "zod";
|
|
|
2
2
|
import { ReleaseIdSchema } from "@openpond/harness";
|
|
3
3
|
import { LearningJsonObjectSchema, LearningRevisionRefSchema, LearningSourceContentSchema, TaskDefinitionContentSchema, TaskExampleSubmissionSchema, TaskFeedbackSubmissionSchema, LearningPolicyContentSchema } from "./contracts.js";
|
|
4
4
|
import { RewardBindingContentSchema, RewardReleaseContentSchema } from "../rewards.js";
|
|
5
|
+
import { AuthoringDraftInputSchema, AuthoringDraftFinalizationSchema } from "./authoring.js";
|
|
5
6
|
import { LearningTextAssetContentSchema } from "./assets.js";
|
|
6
7
|
const command = z.object({ operationId: ReleaseIdSchema });
|
|
7
|
-
const publish = command.extend({ action: z.literal("publish"), expectedRevision: z.number().int().nonnegative() });
|
|
8
|
+
const publish = command.extend({ action: z.literal("publish"), expectedRevision: z.number().int().nonnegative(), finalizeDraft: AuthoringDraftFinalizationSchema.optional() });
|
|
8
9
|
export const PublishLearningResourceCommandSchema = z.discriminatedUnion("kind", [
|
|
9
10
|
publish.extend({ kind: z.literal("asset"), content: LearningTextAssetContentSchema }).strict(),
|
|
10
11
|
publish.extend({ kind: z.literal("definition"), content: TaskDefinitionContentSchema }).strict(),
|
|
@@ -15,7 +16,8 @@ export const PublishLearningResourceCommandSchema = z.discriminatedUnion("kind",
|
|
|
15
16
|
]);
|
|
16
17
|
export const PublishLearningResourcesCommandSchema = command.extend({
|
|
17
18
|
action: z.literal("publish_resources"),
|
|
18
|
-
|
|
19
|
+
finalizeDraft: AuthoringDraftFinalizationSchema.optional(),
|
|
20
|
+
resources: z.array(z.union(PublishLearningResourceCommandSchema.options.map((schema) => schema.omit({ operationId: true, action: true, finalizeDraft: true })))).min(1).max(20),
|
|
19
21
|
}).strict();
|
|
20
22
|
export const SubmitTaskExampleCommandSchema = command.extend({ action: z.literal("submit_example"), example: TaskExampleSubmissionSchema }).strict();
|
|
21
23
|
export const SubmitTaskFeedbackCommandSchema = command.extend({ action: z.literal("submit_feedback"), feedback: TaskFeedbackSubmissionSchema }).strict();
|
|
@@ -30,4 +32,6 @@ export const ReviewTaskEvidenceCommandSchema = command.extend({
|
|
|
30
32
|
}).strict();
|
|
31
33
|
export const SealTaskBatchCommandSchema = command.extend({ action: z.literal("seal_batch"), batchId: ReleaseIdSchema, taskDefinition: LearningRevisionRefSchema, purpose: z.enum(["supervised_training", "reward_training", "evaluation"]), evidence: z.array(LearningRevisionRefSchema).min(1).max(10_000), decisions: z.array(LearningRevisionRefSchema).min(1).max(10_000) }).strict();
|
|
32
34
|
export const CancelTaskGradeCommandSchema = command.extend({ action: z.literal("cancel_grade"), gradeId: ReleaseIdSchema, expectedRevision: z.number().int().positive() }).strict();
|
|
33
|
-
export const
|
|
35
|
+
export const SaveAuthoringDraftCommandSchema = command.extend({ action: z.literal("save_draft"), expectedRevision: z.number().int().nonnegative(), draft: AuthoringDraftInputSchema }).strict();
|
|
36
|
+
export const ArchiveAuthoringDraftCommandSchema = command.extend({ action: z.literal("archive_draft"), draft: LearningRevisionRefSchema }).strict();
|
|
37
|
+
export const LearningCommandSchema = z.union([SaveAuthoringDraftCommandSchema, ArchiveAuthoringDraftCommandSchema, PublishLearningResourceCommandSchema, PublishLearningResourcesCommandSchema, SubmitTaskExampleCommandSchema, SubmitTaskFeedbackCommandSchema, ApplyTaskCorrectionCommandSchema, ResolveTaskFeedbackCommandSchema, QueueTaskGradeCommandSchema, ReviewTaskEvidenceCommandSchema, SealTaskBatchCommandSchema, CancelTaskGradeCommandSchema]);
|
|
@@ -4,8 +4,10 @@ import { assertLearningContentHash, LearningSourceSchema, TaskAdmissionDecisionS
|
|
|
4
4
|
import { RewardBindingSchema, RewardReleaseSchema } from "../rewards.js";
|
|
5
5
|
import { TasksetReleaseSchema } from "../tasksets.js";
|
|
6
6
|
import { LearningDomainError } from "./errors.js";
|
|
7
|
+
import { AuthoringDraftSchema } from "./authoring.js";
|
|
7
8
|
import { LearningTextAssetSchema } from "./assets.js";
|
|
8
9
|
export const learningResourceSchemas = {
|
|
10
|
+
draft: AuthoringDraftSchema,
|
|
9
11
|
asset: LearningTextAssetSchema,
|
|
10
12
|
definition: TaskDefinitionSchema, reward: RewardReleaseSchema, binding: RewardBindingSchema,
|
|
11
13
|
source: LearningSourceSchema, evidence: TaskEvidenceSchema, feedback: TaskFeedbackSchema,
|
package/dist/learning/service.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { saveAuthoringDraft, archiveAuthoringDraft, finalizeAuthoringDraft } from "./authoring-service.js";
|
|
1
2
|
import { LearningDomainError } from "./errors.js";
|
|
2
3
|
import { contentHash } from "@openpond/harness";
|
|
3
4
|
import { createRewardBinding, createRewardRelease, resolveBoundRewards } from "../rewards.js";
|
|
@@ -27,6 +28,12 @@ export function createLearningService(repository, options = {}) {
|
|
|
27
28
|
}
|
|
28
29
|
let pointers;
|
|
29
30
|
switch (input.action) {
|
|
31
|
+
case "save_draft":
|
|
32
|
+
pointers = [await saveAuthoringDraft(transaction, input, now())];
|
|
33
|
+
break;
|
|
34
|
+
case "archive_draft":
|
|
35
|
+
pointers = [await archiveAuthoringDraft(transaction, input.draft, now())];
|
|
36
|
+
break;
|
|
30
37
|
case "publish":
|
|
31
38
|
pointers = [await publish(transaction, input)];
|
|
32
39
|
break;
|
|
@@ -61,6 +68,11 @@ export function createLearningService(repository, options = {}) {
|
|
|
61
68
|
pointers = await seal(transaction, input, context.actor.id);
|
|
62
69
|
break;
|
|
63
70
|
}
|
|
71
|
+
if (input.action === "publish" || input.action === "publish_resources") {
|
|
72
|
+
const finalized = await finalizeAuthoringDraft(transaction, input, pointers, now());
|
|
73
|
+
if (finalized)
|
|
74
|
+
pointers.push(finalized);
|
|
75
|
+
}
|
|
64
76
|
await transaction.saveOperation(operationId, { requestHash, resources: pointers });
|
|
65
77
|
return { operationId: input.operationId, resources: await Promise.all(pointers.map((pointer) => requireLearningResource(transaction, pointer.kind, pointer.id, pointer.revision))) };
|
|
66
78
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type AuthoringDraftInput } from "./authoring.js";
|
|
2
|
+
import { type LearningRevisionRef } from "./contracts.js";
|
|
3
|
+
import { type LearningResourcePointer, type LearningTransaction } from "./repository.js";
|
|
4
|
+
import type { LearningCommand } from "./operations.js";
|
|
5
|
+
export declare function saveAuthoringDraft(tx: LearningTransaction, input: {
|
|
6
|
+
draft: AuthoringDraftInput;
|
|
7
|
+
expectedRevision: number;
|
|
8
|
+
}, now: string): Promise<{
|
|
9
|
+
kind: "draft";
|
|
10
|
+
id: string;
|
|
11
|
+
revision: number;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function archiveAuthoringDraft(tx: LearningTransaction, ref: LearningRevisionRef, now: string): Promise<{
|
|
14
|
+
kind: "draft";
|
|
15
|
+
id: string;
|
|
16
|
+
revision: number;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function finalizeAuthoringDraft(tx: LearningTransaction, input: Extract<LearningCommand, {
|
|
19
|
+
action: "publish" | "publish_resources";
|
|
20
|
+
}>, published: LearningResourcePointer[], now: string): Promise<{
|
|
21
|
+
kind: "draft";
|
|
22
|
+
id: string;
|
|
23
|
+
revision: number;
|
|
24
|
+
} | null>;
|
|
25
|
+
//# sourceMappingURL=authoring-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring-service.d.ts","sourceRoot":"","sources":["../../../../../src/learning/authoring-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,EAAqD,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC7G,OAAO,EAA0B,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACjH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,mBAAmB,EAAE,KAAK,EAAE;IAAE,KAAK,EAAE,mBAAmB,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,EAAE,MAAM;;;;GAY7I;AAED,wBAAsB,qBAAqB,CAAC,EAAE,EAAE,mBAAmB,EAAE,GAAG,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM;;;;GAMzG;AAED,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,mBAAmB,EAAE,KAAK,EAAE,OAAO,CAAC,eAAe,EAAE;IAAE,MAAM,EAAE,SAAS,GAAG,mBAAmB,CAAA;CAAE,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,EAAE,GAAG,EAAE,MAAM;;;;UAUpM"}
|