@edugate/ai-agent 0.0.1

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.
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Closed contract of canvas-mutation operations the AI may emit and the client
3
+ * can apply. The legacy op set is verified 1:1 against BOTH the MCP server's
4
+ * emitted action names and the client's `applyAction` switch; item-level patch
5
+ * ops (insertItem/updateItem/deleteItem) extend it (Part C). Validating an op
6
+ * before apply lets the client surface a STRUCTURED reason for malformed or
7
+ * unknown ops instead of silently no-op'ing them (today an op with a missing
8
+ * field, or an op the client doesn't know, simply does nothing with no signal).
9
+ *
10
+ * This is the typed-op consumption seam (Phase 3b). Item-level patch ops
11
+ * (insertItem/updateItem, Part C) will extend this contract in a later slice.
12
+ */
13
+ /** Op name -> top-level data fields that must be present (non-null) to apply. */
14
+ declare const CANVAS_OP_REQUIRED: Record<string, string[]>;
15
+ declare const CANVAS_OP_NAMES: string[];
16
+ declare function isKnownCanvasOp(action: string): boolean;
17
+ type CanvasOpErrorCode = "UNKNOWN_OP" | "NOT_OBJECT" | "MISSING_FIELDS";
18
+ interface CanvasOpValidation {
19
+ ok: boolean;
20
+ code?: CanvasOpErrorCode;
21
+ errors?: string[];
22
+ }
23
+ declare function validateCanvasOp(action: string, data: unknown): CanvasOpValidation;
24
+ /**
25
+ * Pure, immutable application of an item-level patch op to a collection array.
26
+ * Used by the client to apply insertItem/updateItem/deleteItem against a block's
27
+ * collection (questions, cards, pairs, ...) by stable item id. Returns a NEW
28
+ * array; never mutates the input. Items are matched on `id`.
29
+ */
30
+ declare function applyItemPatch(items: unknown, op: "insertItem" | "updateItem" | "deleteItem", payload: {
31
+ item?: any;
32
+ itemId?: string;
33
+ at?: number;
34
+ }): any[];
35
+
36
+ /**
37
+ * Optimistic-concurrency conflict detection for canvas ops (Phase 7).
38
+ *
39
+ * The AI is a stateless suggester: it builds an op against the activity SNAPSHOT
40
+ * it was given, but the user may manually edit that same entity before the op is
41
+ * applied. Applying a stale mutating op would silently clobber the user's edit.
42
+ *
43
+ * Mechanism (base-signature / compare-and-set):
44
+ * 1. When an op is emitted, the server stamps it with the SIGNATURE of the
45
+ * entity it will mutate, computed from the snapshot the AI saw (`baseSignature`).
46
+ * 2. At apply time the client recomputes the CURRENT signature of that entity.
47
+ * If the base signature is non-null and the current one is missing or
48
+ * different, the entity changed underneath the AI -> conflict, skip + warn.
49
+ *
50
+ * Only MUTATING ops on an EXISTING entity are tracked. Additive ops (createScene,
51
+ * addBlock, addAction, insertItem, ...) and global ops (manageVariables,
52
+ * reorderScenes, ...) never conflict, so they carry no base signature.
53
+ *
54
+ * Pure + dependency-free: callable on the server (activityContext) and the client
55
+ * (live store) alike — both just pass their own `scenes` array.
56
+ */
57
+ type OpTargetKind = "block" | "item" | "untracked";
58
+ interface OpTarget {
59
+ kind: OpTargetKind;
60
+ blockId?: string;
61
+ collection?: string;
62
+ itemId?: string;
63
+ }
64
+ type ConflictVerdict = "apply" | "stale" | "missing";
65
+ /** Deterministic stringify (sorted keys) so signatures are stable regardless of
66
+ * property insertion order across server/client serialisation round-trips. */
67
+ declare function stableStringify(v: any): string;
68
+ /** Which canvas op mutates which existing entity. Anything not listed is
69
+ * additive or global and returns { kind: "untracked" } (never conflicts). */
70
+ declare function opTarget(action: string, data: any): OpTarget;
71
+ /**
72
+ * Signature of the entity an op targets, computed from a `scenes` array.
73
+ * Returns null when the target is untracked or the entity is absent (a missing
74
+ * entity is represented as null so the verdict can distinguish it from a change).
75
+ */
76
+ declare function entitySignature(scenes: any[], target: OpTarget): string | null;
77
+ /**
78
+ * Compare the base signature (what the AI saw) against the current signature
79
+ * (live state) to decide whether a mutating op is still safe to apply.
80
+ * - base null -> "apply" (untracked op, or target didn't exist at base)
81
+ * - current null -> "missing" (entity was deleted by the user)
82
+ * - differ -> "stale" (entity was modified by the user)
83
+ * - equal -> "apply"
84
+ */
85
+ declare function detectConflict(baseSignature: string | null | undefined, currentSignature: string | null | undefined): ConflictVerdict;
86
+ /** Convenience for the server: derive { target, baseSignature } for an op from
87
+ * the snapshot the AI operated on. baseSignature is null for untracked ops. */
88
+ declare function opConflictStamp(action: string, data: any, baseScenes: any[]): {
89
+ target: OpTarget;
90
+ baseSignature: string | null;
91
+ };
92
+
93
+ /**
94
+ * @-mention ("tag") resolution — turn the builder's `@[Name|UUID]` tags into an
95
+ * AUTHORITATIVE target the agents can actually consume.
96
+ *
97
+ * Root cause (see docs/ai-tag-context-and-quiz-styling-rootcause.md): the builder
98
+ * inserts a literal `@[Name|UUID]` into the message text, but NOTHING resolved it —
99
+ * the only structured target the agents received was `selectedBlockId` (the CLICKED
100
+ * block). Tagging ≠ selecting, so a tagged-but-not-selected block (e.g. a Quiz the
101
+ * user wants to style) was effectively ignored and mis-targeted.
102
+ *
103
+ * This module is PURE (no I/O): given the message text and the activity, it strips
104
+ * the tag noise to readable names and returns the entities that actually exist, so
105
+ * the route can promote them to the request target and surface them in [CONTEXT].
106
+ */
107
+ /** A `@[Name|UUID]` reference resolved against the activity. */
108
+ interface ResolvedEntity {
109
+ id: string;
110
+ name: string;
111
+ kind: "scene" | "block";
112
+ /** Present for blocks. */
113
+ blockType?: string;
114
+ /** The scene that contains the block (present for blocks). */
115
+ sceneId?: string;
116
+ }
117
+ interface MentionResolution {
118
+ /** The text with every `@[Name|UUID]` replaced by the bare `Name`. For display
119
+ * or any place where the literal name is wanted. */
120
+ cleanedText: string;
121
+ /**
122
+ * The text to send to the AGENT PIPELINE (router + specialists). Each mention is
123
+ * replaced by a NEUTRAL DEICTIC ("il blocco selezionato" / "la scena selezionata")
124
+ * instead of the entity name. Rationale: the small routing model keyword-matches
125
+ * intent, and a tagged block whose name happens to read as a command — e.g. the
126
+ * default "Nuovo blocco quiz vuoto" ("new empty quiz block") — was mis-parsed as
127
+ * an `add_block` intent, creating a phantom block. The authoritative name + ID
128
+ * still travel in [CONTEXT] (referencedEntities), so nothing is lost.
129
+ */
130
+ agentText: string;
131
+ /** De-duplicated entities that exist in the activity (unknown UUIDs dropped). */
132
+ entities: ResolvedEntity[];
133
+ }
134
+ /** Raw `{name,id}` pairs as written in the text (no validation). */
135
+ declare function parseMentions(text: string): {
136
+ name: string;
137
+ id: string;
138
+ }[];
139
+ /**
140
+ * Resolve mentions against an `activity` ({ scenes: [{ id, blocks: [{ id, type }] }] }).
141
+ * Strips every tag to its readable name; collects the ones whose UUID matches a real
142
+ * scene/block. Pure and deterministic.
143
+ */
144
+ declare function resolveMentions(text: string, activity: any): MentionResolution;
145
+
146
+ /**
147
+ * Human-readable Markdown reference of all block content schemas, suitable
148
+ * for injection into agent system prompts.
149
+ */
150
+ declare function generateBlockReference(): string;
151
+ declare function listBlockTypes(): string[];
152
+ /**
153
+ * Raw JSON Schema (draft-07) for a single block's content, for function/tool
154
+ * calling with an AI agent. Returns undefined for an unknown block type.
155
+ */
156
+ declare function getBlockJsonSchema(blockType: string): Record<string, unknown> | undefined;
157
+ /**
158
+ * Raw JSON Schema for every known block type, keyed by block type name.
159
+ */
160
+ declare function getAllBlockJsonSchemas(): Record<string, Record<string, unknown>>;
161
+
162
+ export { CANVAS_OP_NAMES, CANVAS_OP_REQUIRED, type CanvasOpErrorCode, type CanvasOpValidation, type ConflictVerdict, type MentionResolution, type OpTarget, type OpTargetKind, type ResolvedEntity, applyItemPatch, detectConflict, entitySignature, generateBlockReference, getAllBlockJsonSchemas, getBlockJsonSchema, isKnownCanvasOp, listBlockTypes, opConflictStamp, opTarget, parseMentions, resolveMentions, stableStringify, validateCanvasOp };
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Closed contract of canvas-mutation operations the AI may emit and the client
3
+ * can apply. The legacy op set is verified 1:1 against BOTH the MCP server's
4
+ * emitted action names and the client's `applyAction` switch; item-level patch
5
+ * ops (insertItem/updateItem/deleteItem) extend it (Part C). Validating an op
6
+ * before apply lets the client surface a STRUCTURED reason for malformed or
7
+ * unknown ops instead of silently no-op'ing them (today an op with a missing
8
+ * field, or an op the client doesn't know, simply does nothing with no signal).
9
+ *
10
+ * This is the typed-op consumption seam (Phase 3b). Item-level patch ops
11
+ * (insertItem/updateItem, Part C) will extend this contract in a later slice.
12
+ */
13
+ /** Op name -> top-level data fields that must be present (non-null) to apply. */
14
+ declare const CANVAS_OP_REQUIRED: Record<string, string[]>;
15
+ declare const CANVAS_OP_NAMES: string[];
16
+ declare function isKnownCanvasOp(action: string): boolean;
17
+ type CanvasOpErrorCode = "UNKNOWN_OP" | "NOT_OBJECT" | "MISSING_FIELDS";
18
+ interface CanvasOpValidation {
19
+ ok: boolean;
20
+ code?: CanvasOpErrorCode;
21
+ errors?: string[];
22
+ }
23
+ declare function validateCanvasOp(action: string, data: unknown): CanvasOpValidation;
24
+ /**
25
+ * Pure, immutable application of an item-level patch op to a collection array.
26
+ * Used by the client to apply insertItem/updateItem/deleteItem against a block's
27
+ * collection (questions, cards, pairs, ...) by stable item id. Returns a NEW
28
+ * array; never mutates the input. Items are matched on `id`.
29
+ */
30
+ declare function applyItemPatch(items: unknown, op: "insertItem" | "updateItem" | "deleteItem", payload: {
31
+ item?: any;
32
+ itemId?: string;
33
+ at?: number;
34
+ }): any[];
35
+
36
+ /**
37
+ * Optimistic-concurrency conflict detection for canvas ops (Phase 7).
38
+ *
39
+ * The AI is a stateless suggester: it builds an op against the activity SNAPSHOT
40
+ * it was given, but the user may manually edit that same entity before the op is
41
+ * applied. Applying a stale mutating op would silently clobber the user's edit.
42
+ *
43
+ * Mechanism (base-signature / compare-and-set):
44
+ * 1. When an op is emitted, the server stamps it with the SIGNATURE of the
45
+ * entity it will mutate, computed from the snapshot the AI saw (`baseSignature`).
46
+ * 2. At apply time the client recomputes the CURRENT signature of that entity.
47
+ * If the base signature is non-null and the current one is missing or
48
+ * different, the entity changed underneath the AI -> conflict, skip + warn.
49
+ *
50
+ * Only MUTATING ops on an EXISTING entity are tracked. Additive ops (createScene,
51
+ * addBlock, addAction, insertItem, ...) and global ops (manageVariables,
52
+ * reorderScenes, ...) never conflict, so they carry no base signature.
53
+ *
54
+ * Pure + dependency-free: callable on the server (activityContext) and the client
55
+ * (live store) alike — both just pass their own `scenes` array.
56
+ */
57
+ type OpTargetKind = "block" | "item" | "untracked";
58
+ interface OpTarget {
59
+ kind: OpTargetKind;
60
+ blockId?: string;
61
+ collection?: string;
62
+ itemId?: string;
63
+ }
64
+ type ConflictVerdict = "apply" | "stale" | "missing";
65
+ /** Deterministic stringify (sorted keys) so signatures are stable regardless of
66
+ * property insertion order across server/client serialisation round-trips. */
67
+ declare function stableStringify(v: any): string;
68
+ /** Which canvas op mutates which existing entity. Anything not listed is
69
+ * additive or global and returns { kind: "untracked" } (never conflicts). */
70
+ declare function opTarget(action: string, data: any): OpTarget;
71
+ /**
72
+ * Signature of the entity an op targets, computed from a `scenes` array.
73
+ * Returns null when the target is untracked or the entity is absent (a missing
74
+ * entity is represented as null so the verdict can distinguish it from a change).
75
+ */
76
+ declare function entitySignature(scenes: any[], target: OpTarget): string | null;
77
+ /**
78
+ * Compare the base signature (what the AI saw) against the current signature
79
+ * (live state) to decide whether a mutating op is still safe to apply.
80
+ * - base null -> "apply" (untracked op, or target didn't exist at base)
81
+ * - current null -> "missing" (entity was deleted by the user)
82
+ * - differ -> "stale" (entity was modified by the user)
83
+ * - equal -> "apply"
84
+ */
85
+ declare function detectConflict(baseSignature: string | null | undefined, currentSignature: string | null | undefined): ConflictVerdict;
86
+ /** Convenience for the server: derive { target, baseSignature } for an op from
87
+ * the snapshot the AI operated on. baseSignature is null for untracked ops. */
88
+ declare function opConflictStamp(action: string, data: any, baseScenes: any[]): {
89
+ target: OpTarget;
90
+ baseSignature: string | null;
91
+ };
92
+
93
+ /**
94
+ * @-mention ("tag") resolution — turn the builder's `@[Name|UUID]` tags into an
95
+ * AUTHORITATIVE target the agents can actually consume.
96
+ *
97
+ * Root cause (see docs/ai-tag-context-and-quiz-styling-rootcause.md): the builder
98
+ * inserts a literal `@[Name|UUID]` into the message text, but NOTHING resolved it —
99
+ * the only structured target the agents received was `selectedBlockId` (the CLICKED
100
+ * block). Tagging ≠ selecting, so a tagged-but-not-selected block (e.g. a Quiz the
101
+ * user wants to style) was effectively ignored and mis-targeted.
102
+ *
103
+ * This module is PURE (no I/O): given the message text and the activity, it strips
104
+ * the tag noise to readable names and returns the entities that actually exist, so
105
+ * the route can promote them to the request target and surface them in [CONTEXT].
106
+ */
107
+ /** A `@[Name|UUID]` reference resolved against the activity. */
108
+ interface ResolvedEntity {
109
+ id: string;
110
+ name: string;
111
+ kind: "scene" | "block";
112
+ /** Present for blocks. */
113
+ blockType?: string;
114
+ /** The scene that contains the block (present for blocks). */
115
+ sceneId?: string;
116
+ }
117
+ interface MentionResolution {
118
+ /** The text with every `@[Name|UUID]` replaced by the bare `Name`. For display
119
+ * or any place where the literal name is wanted. */
120
+ cleanedText: string;
121
+ /**
122
+ * The text to send to the AGENT PIPELINE (router + specialists). Each mention is
123
+ * replaced by a NEUTRAL DEICTIC ("il blocco selezionato" / "la scena selezionata")
124
+ * instead of the entity name. Rationale: the small routing model keyword-matches
125
+ * intent, and a tagged block whose name happens to read as a command — e.g. the
126
+ * default "Nuovo blocco quiz vuoto" ("new empty quiz block") — was mis-parsed as
127
+ * an `add_block` intent, creating a phantom block. The authoritative name + ID
128
+ * still travel in [CONTEXT] (referencedEntities), so nothing is lost.
129
+ */
130
+ agentText: string;
131
+ /** De-duplicated entities that exist in the activity (unknown UUIDs dropped). */
132
+ entities: ResolvedEntity[];
133
+ }
134
+ /** Raw `{name,id}` pairs as written in the text (no validation). */
135
+ declare function parseMentions(text: string): {
136
+ name: string;
137
+ id: string;
138
+ }[];
139
+ /**
140
+ * Resolve mentions against an `activity` ({ scenes: [{ id, blocks: [{ id, type }] }] }).
141
+ * Strips every tag to its readable name; collects the ones whose UUID matches a real
142
+ * scene/block. Pure and deterministic.
143
+ */
144
+ declare function resolveMentions(text: string, activity: any): MentionResolution;
145
+
146
+ /**
147
+ * Human-readable Markdown reference of all block content schemas, suitable
148
+ * for injection into agent system prompts.
149
+ */
150
+ declare function generateBlockReference(): string;
151
+ declare function listBlockTypes(): string[];
152
+ /**
153
+ * Raw JSON Schema (draft-07) for a single block's content, for function/tool
154
+ * calling with an AI agent. Returns undefined for an unknown block type.
155
+ */
156
+ declare function getBlockJsonSchema(blockType: string): Record<string, unknown> | undefined;
157
+ /**
158
+ * Raw JSON Schema for every known block type, keyed by block type name.
159
+ */
160
+ declare function getAllBlockJsonSchemas(): Record<string, Record<string, unknown>>;
161
+
162
+ export { CANVAS_OP_NAMES, CANVAS_OP_REQUIRED, type CanvasOpErrorCode, type CanvasOpValidation, type ConflictVerdict, type MentionResolution, type OpTarget, type OpTargetKind, type ResolvedEntity, applyItemPatch, detectConflict, entitySignature, generateBlockReference, getAllBlockJsonSchemas, getBlockJsonSchema, isKnownCanvasOp, listBlockTypes, opConflictStamp, opTarget, parseMentions, resolveMentions, stableStringify, validateCanvasOp };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var Pe=Object.create;var L=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var g=(t,n)=>()=>{try{return n||t((n={exports:{}}).exports,n),n.exports}catch(i){throw n=0,i}},Fe=(t,n)=>{for(var i in n)L(t,i,{get:n[i],enumerable:!0})},ie=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of De(n))!Re.call(t,a)&&a!==i&&L(t,a,{get:()=>n[a],enumerable:!(r=Ae(n,a))||r.enumerable});return t};var Qe=(t,n,i)=>(i=t!=null?Pe(qe(t)):{},ie(n||!t||!t.__esModule?L(i,"default",{value:t,enumerable:!0}):i,t)),Ee=t=>ie(L({},"__esModule",{value:!0}),t);var w=g(m=>{"use strict";Object.defineProperty(m,"__esModule",{value:!0});m.MediaRefSchema=m.MediaItemSchema=m.VideoSettingsSchema=m.CropDataSchema=m.MediaSourceSchema=m.MediaTypeSchema=m.GridSizeSchema=m.SizeSchema=m.PositionSchema=void 0;var c=require("zod");m.PositionSchema=c.z.object({x:c.z.number(),y:c.z.number(),z:c.z.number().optional()});m.SizeSchema=c.z.object({width:c.z.number().optional(),height:c.z.number().optional()});m.GridSizeSchema=c.z.object({rows:c.z.number(),cols:c.z.number()});m.MediaTypeSchema=c.z.enum(["image","color","gif","shape","illustration","video","audio"]);m.MediaSourceSchema=c.z.enum(["unsplash","pexels","upload","url","library","tenor"]);m.CropDataSchema=c.z.object({x:c.z.number(),y:c.z.number(),width:c.z.number(),height:c.z.number(),zoom:c.z.number().optional(),rotation:c.z.number().optional(),aspect:c.z.number().optional()});m.VideoSettingsSchema=c.z.object({autoplay:c.z.boolean().optional(),loop:c.z.boolean().optional(),muted:c.z.boolean().optional(),controls:c.z.boolean().optional(),poster:c.z.string().optional(),volume:c.z.number().optional()});m.MediaItemSchema=c.z.object({id:c.z.string().optional(),url:c.z.string().optional(),title:c.z.string().optional(),type:m.MediaTypeSchema,source:m.MediaSourceSchema.optional(),alt:c.z.string().optional(),width:c.z.number().optional(),height:c.z.number().optional(),format:c.z.enum(["cover","contain"]).optional(),color:c.z.string().optional(),cropData:m.CropDataSchema.optional(),duration:c.z.number().optional(),videoSettings:m.VideoSettingsSchema.optional()});m.MediaRefSchema=m.MediaItemSchema});var le=g(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});l.QuestionSchema=l.TextQuestionSchema=l.TrueFalseQuestionSchema=l.ChoiceQuestionSchema=l.QuestionOptionSchema=l.ImageSizeSchema=l.ImageAlignSchema=l.QuestionTypeSchema=void 0;var d=require("zod"),se=w();l.QuestionTypeSchema=d.z.enum(["single-choice","multiple-choice","true-false","short-answers","long-answers"]);l.ImageAlignSchema=d.z.enum(["left","right","center"]);l.ImageSizeSchema=d.z.object({width:d.z.number().optional(),height:d.z.number().optional()});l.QuestionOptionSchema=d.z.object({id:d.z.string(),text:d.z.string(),isCorrect:d.z.boolean(),image:se.MediaItemSchema.optional(),imageAlign:l.ImageAlignSchema.optional(),imageSize:l.ImageSizeSchema.optional()});var X={id:d.z.string(),text:d.z.string(),score:d.z.number().optional(),image:se.MediaItemSchema.optional(),imageAlign:l.ImageAlignSchema.optional(),imageSize:l.ImageSizeSchema.optional()};l.ChoiceQuestionSchema=d.z.object({...X,type:d.z.enum(["single-choice","multiple-choice"]),options:d.z.array(l.QuestionOptionSchema)});l.TrueFalseQuestionSchema=d.z.object({...X,type:d.z.literal("true-false"),correctAnswer:d.z.boolean()});l.TextQuestionSchema=d.z.object({...X,type:d.z.enum(["short-answers","long-answers"]),minCharacters:d.z.number().optional(),maxCharacters:d.z.number().optional()});l.QuestionSchema=d.z.discriminatedUnion("type",[l.ChoiceQuestionSchema,l.TrueFalseQuestionSchema,l.TextQuestionSchema])});var de=g(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.QuizContentSchema=k.QuizQuestionSchema=k.QuizOptionSchema=k.QuizQuestionTypeSchema=void 0;var u=require("zod"),me=w(),$=le();k.QuizQuestionTypeSchema=u.z.enum(["single-choice","multiple-choice","true-false","short-answers","long-answers"]);k.QuizOptionSchema=u.z.object({id:u.z.string().optional(),text:u.z.string(),isCorrect:u.z.boolean(),image:me.MediaItemSchema.optional().describe("Option image."),imageAlign:$.ImageAlignSchema.optional().describe("Option image alignment."),imageSize:$.ImageSizeSchema.optional().describe("Option image size.")});k.QuizQuestionSchema=u.z.object({id:u.z.string().optional().describe("Question ID. Auto-generated if omitted."),type:k.QuizQuestionTypeSchema,text:u.z.string().describe("The question text."),score:u.z.number().optional(),options:u.z.array(k.QuizOptionSchema).optional().describe("Required for single-choice and multiple-choice."),correctAnswer:u.z.boolean().optional().describe("Required for true-false."),image:me.MediaItemSchema.optional().describe("Question image."),imageAlign:$.ImageAlignSchema.optional().describe("Question image alignment."),imageSize:$.ImageSizeSchema.optional().describe("Question image size.")});k.QuizContentSchema=u.z.object({questions:u.z.array(k.QuizQuestionSchema).describe("Array of question objects."),showResults:u.z.boolean().optional(),allowRetry:u.z.boolean().optional(),maxRetry:u.z.string().optional(),required:u.z.boolean().optional(),submitText:u.z.string().optional().describe("Label for submit button."),timer:u.z.string().optional().describe("Timer duration in seconds as a string."),showQuestionCount:u.z.boolean().optional().describe("Show current/total questions count.")})});var ue=g(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.ClozeContentSchema=R.ClozeModeSchema=void 0;var Z=require("zod");R.ClozeModeSchema=Z.z.enum(["write","drag-drop"]);R.ClozeContentSchema=Z.z.object({templateText:Z.z.string().describe('Template text with blanks in [brackets]. E.g. "The capital of Italy is [Rome]."'),mode:R.ClozeModeSchema.optional().describe("Input mode. Default: write.")})});var he=g(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.AnagramContentSchema=T.WordSearchContentSchema=T.CrosswordContentSchema=T.CrosswordWordSchema=T.WordGameBlockTypeSchema=void 0;var y=require("zod"),pe=w();T.WordGameBlockTypeSchema=y.z.enum(["Crossword","WordSearch","Anagram"]);T.CrosswordWordSchema=y.z.object({answer:y.z.string(),clue:y.z.string(),image:pe.MediaItemSchema.optional().describe("Clue image.")});T.CrosswordContentSchema=y.z.object({words:y.z.array(T.CrosswordWordSchema)});T.WordSearchContentSchema=y.z.object({words:y.z.array(y.z.string()),gridSize:pe.GridSizeSchema.optional().describe("Grid dimensions."),difficulty:y.z.enum(["easy","medium","hard"]).optional()});T.AnagramContentSchema=y.z.object({correctWord:y.z.string().describe("The correct word."),letters:y.z.array(y.z.string()).optional(),clue:y.z.string().optional().describe("A hint.")})});var Se=g(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.PairGameContentSchema=B.PairSchema=B.MemoryPairTypeSchema=B.PairGameBlockTypeSchema=void 0;var _=require("zod"),ee=w();B.PairGameBlockTypeSchema=_.z.enum(["Memory","MatchPairs"]);B.MemoryPairTypeSchema=_.z.enum(["img-img","img-word","word-word"]);B.PairSchema=_.z.object({id:_.z.string().optional(),type:B.MemoryPairTypeSchema.optional().describe("For Memory: pair type."),content:_.z.array(_.z.string()).optional().describe("For Memory: [item1, item2]."),leftLabel:_.z.string().optional().describe("For MatchPairs: left side text."),rightLabel:_.z.string().optional().describe("For MatchPairs: right side text."),leftImage:ee.MediaItemSchema.optional().describe("For MatchPairs: left side image."),rightImage:ee.MediaItemSchema.optional().describe("For MatchPairs: right side image.")});B.PairGameContentSchema=_.z.object({pairs:_.z.array(B.PairSchema).describe("Array of pair objects."),gridSize:ee.GridSizeSchema.optional().describe("For Memory: grid dimensions."),instructions:_.z.string().optional().describe("For MatchPairs: instruction text.")})});var be=g(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.DeckContentSchema=C.CardSchema=C.CardFaceSchema=C.DeckBlockTypeSchema=void 0;var I=require("zod");C.DeckBlockTypeSchema=I.z.enum(["Flashcard","CardDeck"]);C.CardFaceSchema=I.z.object({type:I.z.enum(["text","image"]),content:I.z.any()});C.CardSchema=I.z.object({id:I.z.string().optional(),front:C.CardFaceSchema.optional().describe("For Flashcard: front side."),back:C.CardFaceSchema.optional().describe("For Flashcard: back side."),frontText:I.z.string().optional().describe("For CardDeck: front text."),frontImage:I.z.any().optional().describe("For CardDeck: front image.")});C.DeckContentSchema=I.z.object({cards:I.z.array(C.CardSchema).describe("Array of card objects."),backImage:I.z.any().optional().describe("For CardDeck: shared back image."),discardLogic:I.z.enum(["delete","return"]).optional().describe("For CardDeck.")})});var ze=g(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.DiceContentSchema=F.DieTypeSchema=void 0;var N=require("zod");F.DieTypeSchema=N.z.enum(["d4","d6","d8","d10","d12","d20"]);F.DiceContentSchema=N.z.object({diceType:F.DieTypeSchema.optional(),diceCount:N.z.number().int().min(1).max(10).optional(),color:N.z.string().optional().describe("CSS color for dice."),showNumber:N.z.boolean().optional(),persistent:N.z.boolean().optional().describe("Keep dice visible after roll.")})});var ge=g(E=>{"use strict";Object.defineProperty(E,"__esModule",{value:!0});E.SpinnerContentSchema=E.SpinnerSliceSchema=void 0;var Q=require("zod"),Ue=w();E.SpinnerSliceSchema=Q.z.object({id:Q.z.string().optional(),text:Q.z.string(),color:Q.z.string().optional().describe("CSS color for slice."),image:Ue.MediaItemSchema.optional().describe("Slice image.")});E.SpinnerContentSchema=Q.z.object({slices:Q.z.array(E.SpinnerSliceSchema).min(2).describe("Wheel slices (min 2)."),spinDuration:Q.z.number().optional().describe("Spin duration in seconds.")})});var ye=g(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.ShapeBlockThemeSchema=o.MatchPairsBlockThemeSchema=o.FlashcardBlockThemeSchema=o.CardDeckBlockThemeSchema=o.ClozeBlockThemeSchema=o.SpinningWheelBlockThemeSchema=o.MemoryBlockThemeSchema=o.WordSearchBlockThemeSchema=o.CrosswordBlockThemeSchema=o.DiceBlockThemeSchema=o.AnagramBlockThemeSchema=o.EditorBlockThemeSchema=o.DragAndDropBlockThemeSchema=o.QuizBlockThemeSchema=o.HotpointBlockThemeSchema=o.BlockThemeSchema=o.TextStylesSchema=o.BoxStylesSchema=o.RadiusSchema=o.BoxSideSchema=o.AnimationSchema=void 0;var e=require("zod"),oe=w();o.AnimationSchema=e.z.object({type:e.z.union([e.z.enum(["none","fade","direction","bounce","scale","rotate"]),e.z.string()]),duration:e.z.number().optional(),delay:e.z.number().optional(),phase:e.z.enum(["in","both","out"]).optional(),direction:e.z.enum(["up","right","down","left"]).optional()});o.BoxSideSchema=e.z.object({top:e.z.union([e.z.string(),e.z.number()]).optional(),right:e.z.union([e.z.string(),e.z.number()]).optional(),bottom:e.z.union([e.z.string(),e.z.number()]).optional(),left:e.z.union([e.z.string(),e.z.number()]).optional()});o.RadiusSchema=e.z.object({topLeft:e.z.union([e.z.string(),e.z.number()]).optional(),topRight:e.z.union([e.z.string(),e.z.number()]).optional(),bottomRight:e.z.union([e.z.string(),e.z.number()]).optional(),bottomLeft:e.z.union([e.z.string(),e.z.number()]).optional()});o.BoxStylesSchema=e.z.object({background:e.z.boolean().optional(),backgroundColor:e.z.string().optional(),backgroundOpacity:e.z.number().optional(),backgroundMedia:oe.MediaItemSchema.optional(),border:e.z.boolean().optional(),borderColor:e.z.string().optional(),borderWidth:o.BoxSideSchema.optional(),borderRadius:o.RadiusSchema.optional(),padding:e.z.union([e.z.string(),e.z.number(),o.BoxSideSchema]).optional()});o.TextStylesSchema=e.z.object({color:e.z.string().optional(),fontSize:e.z.number().optional(),fontFamily:e.z.string().optional(),fontStyle:e.z.string().optional(),fontWeight:e.z.union([e.z.string(),e.z.number()]).optional(),textAlign:e.z.enum(["left","center","right","justify"]).optional()});var O=o.BoxStylesSchema.merge(o.TextStylesSchema);o.BlockThemeSchema=e.z.object({spacing:e.z.enum(["no-spacing","small","medium","large"]).optional(),animation:o.AnimationSchema.optional(),styles:e.z.record(e.z.record(e.z.any())).optional()});o.HotpointBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({hotpoint:e.z.object({icon:e.z.string().optional(),iconPosition:e.z.enum(["left","right"]).optional(),iconSize:e.z.string().optional(),iconColor:e.z.string().optional(),image:oe.MediaItemSchema.optional(),imageFormat:e.z.enum(["circle","square","custom"]).optional(),border:e.z.boolean().optional(),borderColor:e.z.string().optional(),borderWidth:e.z.string().optional(),borderRadius:e.z.string().optional(),glow:e.z.boolean().optional(),glowColor:e.z.string().optional(),background:e.z.boolean().optional(),backgroundColor:e.z.string().optional(),fontSize:e.z.number().optional(),fontFamily:e.z.string().optional(),fontStyle:e.z.string().optional(),textColor:e.z.string().optional()}).optional()}).optional()});o.QuizBlockThemeSchema=o.BlockThemeSchema.extend({layout:e.z.enum(["horizontal","vertical","grid"]),gridColumns:e.z.number().optional(),preset:e.z.enum(["default","modern","trivia","custom"]),styles:e.z.object({general:O,question:O,answers:O.extend({customStyles:e.z.array(e.z.object({color:e.z.string().optional(),backgroundColor:e.z.string().optional(),targets:e.z.string().optional()})).optional(),hover:O.optional()}),button:O.extend({variant:e.z.enum(["default","outline","ghost"]).optional(),hover:O.optional()})}).optional()});o.DragAndDropBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),splitRatio:e.z.number().optional(),gridColumns:e.z.number().optional(),gridGap:e.z.number().optional().describe("Gap in pixels between auto-laid items (list/grid)."),pool:e.z.object({x:e.z.number().optional(),y:e.z.number().optional(),width:e.z.number().optional(),height:e.z.number().optional()}).optional().describe("Movable/resizable frame for the list/grid item pool (sandbox px)."),styles:e.z.object({title:o.TextStylesSchema.optional(),sandbox:o.BoxStylesSchema.optional(),item:O.optional(),group:o.BoxStylesSchema.optional(),container:o.BoxStylesSchema.extend({url:e.z.string().optional(),type:oe.MediaTypeSchema.optional()}).optional(),groups:O.optional(),feedback:e.z.object({correct:e.z.string().optional(),incorrect:e.z.string().optional(),active:e.z.string().optional()}).optional(),referenceSize:e.z.object({width:e.z.number(),height:e.z.number()}).optional()}).optional()});o.EditorBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({editor:o.BoxStylesSchema.optional()}).optional()});o.AnagramBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({letter:o.BoxStylesSchema.optional(),letterText:o.TextStylesSchema.optional(),slot:o.BoxStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.DiceBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({button:o.BoxStylesSchema.extend({hover:O.optional()}).optional(),buttonText:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.CrosswordBlockThemeSchema=o.BlockThemeSchema.extend({primaryColor:e.z.string().optional(),layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),splitRatio:e.z.number().optional(),styles:e.z.object({text:o.TextStylesSchema.optional(),cell:o.BoxStylesSchema.optional(),grid:o.BoxStylesSchema.optional(),clueContainer:o.BoxStylesSchema.optional(),clueText:o.TextStylesSchema.optional(),clueTitle:o.TextStylesSchema.optional()}).optional()});o.WordSearchBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),splitRatio:e.z.number().optional(),styles:e.z.object({wordSearch:e.z.object({primaryColor:e.z.string().optional(),highlightColor:e.z.string().optional(),fontSize:e.z.number().optional(),fontFamily:e.z.string().optional(),textColor:e.z.string().optional(),cellBackgroundColor:e.z.string().optional()}).optional(),text:o.TextStylesSchema.optional(),cell:o.BoxStylesSchema.optional(),grid:o.BoxStylesSchema.optional(),wordListContainer:o.BoxStylesSchema.optional(),wordListText:o.TextStylesSchema.optional(),wordListTitle:o.TextStylesSchema.optional()}).optional()});o.MemoryBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({text:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional(),infoContainer:o.BoxStylesSchema.optional(),infoText:o.TextStylesSchema.optional(),card:o.BoxStylesSchema.optional()}).optional()});o.SpinningWheelBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({wheelText:o.TextStylesSchema.optional()}).optional()});o.ClozeBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),styles:e.z.object({text:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional(),wordBank:o.BoxStylesSchema.optional(),word:o.BoxStylesSchema.optional(),blank:o.BoxStylesSchema.optional()}).optional()});o.CardDeckBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({card:o.BoxStylesSchema.optional(),cardText:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.FlashcardBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({cardFront:o.BoxStylesSchema.optional(),cardBack:o.BoxStylesSchema.optional(),frontText:o.TextStylesSchema.optional(),backText:o.TextStylesSchema.optional(),navigation:o.BoxStylesSchema.optional(),navigationText:o.TextStylesSchema.optional()}).optional()});o.MatchPairsBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),styles:e.z.object({text:o.TextStylesSchema.optional(),card:o.BoxStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.ShapeBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({shape:O.extend({fillColor:e.z.string().optional(),textColor:e.z.string().optional(),borderStyle:e.z.enum(["solid","dashed","dotted"]).optional(),padding:e.z.number().optional()}).optional()}).optional()})});var fe=g(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});v.DragAndDropContentSchema=v.DragGroupSchema=v.DragItemSchema=void 0;var s=require("zod"),J=w(),V=ye();v.DragItemSchema=s.z.object({id:s.z.string().optional(),text:s.z.string(),background:J.MediaItemSchema.optional().describe("Background image/color for item."),opacity:s.z.number().optional().describe("Opacity of the item (0-1)."),x:s.z.number().optional().describe("Manual x position in pixels (sandbox space, origin top-left; sandbox size = block.size)."),y:s.z.number().optional().describe("Manual y position in pixels (sandbox space, origin top-left)."),fx:s.z.number().optional().describe("Resize-invariant x as a fraction (0-1) of sandbox width. Preferred over x when present."),fy:s.z.number().optional().describe("Resize-invariant y as a fraction (0-1) of sandbox height. Preferred over y when present."),width:s.z.number().optional().describe("Manual width in pixels."),height:s.z.number().optional().describe("Manual height in pixels."),styles:V.BoxStylesSchema.optional().describe("Box custom styling styles."),textStyles:V.TextStylesSchema.optional().describe("Text custom styling styles.")});v.DragGroupSchema=s.z.object({id:s.z.string().optional(),name:s.z.string().describe("Group/dropzone name."),singleItem:s.z.boolean().optional().describe("Accept only one item inside."),background:J.MediaItemSchema.optional().describe("Background image/color for group."),x:s.z.number().optional().describe("Manual x position in pixels (sandbox space, origin top-left; sandbox size = block.size)."),y:s.z.number().optional().describe("Manual y position in pixels (sandbox space, origin top-left)."),fx:s.z.number().optional().describe("Resize-invariant x as a fraction (0-1) of sandbox width. Preferred over x when present."),fy:s.z.number().optional().describe("Resize-invariant y as a fraction (0-1) of sandbox height. Preferred over y when present."),width:s.z.number().optional().describe("Manual width in pixels."),height:s.z.number().optional().describe("Manual height in pixels."),opacity:s.z.number().optional().describe("Opacity of the group (0-1)."),styles:V.BoxStylesSchema.optional().describe("Box custom styling styles."),textStyles:V.TextStylesSchema.optional().describe("Text custom styling styles."),items:s.z.array(v.DragItemSchema).describe("Items that belong in this group.")});v.DragAndDropContentSchema=s.z.object({groups:s.z.array(v.DragGroupSchema).min(1).describe("Drag-and-drop groups."),layout:s.z.enum(["manual","split"]).optional().describe("Layout mode: manual placements or split areas."),itemArrangement:s.z.enum(["random","list","grid"]).optional().describe("Initial item arrangement inside sandbox."),showResults:s.z.boolean().optional().describe("Show result feedback immediately."),requireSubmit:s.z.boolean().optional().describe("Require an explicit 'Check' button to grade instead of auto-grading when all items are placed."),enableWrongAnswers:s.z.boolean().optional().describe("Allow placing items in incorrect groups."),groupBackground:J.MediaItemSchema.optional().describe("Shared background image/color for all groups."),itemBackground:J.MediaItemSchema.optional().describe("Shared background image/color for all items."),groupBackgroundOpacity:s.z.number().optional().describe("Shared group background opacity (0-1)."),itemBackgroundOpacity:s.z.number().optional().describe("Shared item background opacity (0-1)."),splitRatio:s.z.number().optional().describe("Proportion ratio for split layout.")})});var xe=g(P=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.ChartContentSchema=P.ChartConfigSchema=P.ChartTypeSchema=void 0;var f=require("zod");P.ChartTypeSchema=f.z.enum(["line","bar","pie","doughnut","radar","area","scatter"]);P.ChartConfigSchema=f.z.object({colors:f.z.array(f.z.string()).optional(),xAxisLabel:f.z.string().optional(),yAxisLabel:f.z.string().optional(),showLegend:f.z.boolean().optional(),showTooltip:f.z.boolean().optional(),stacked:f.z.boolean().optional(),seriesNames:f.z.record(f.z.string()).optional().describe("Dictionary mapping series keys to custom labels.")});P.ChartContentSchema=f.z.object({chartType:P.ChartTypeSchema.optional(),chartData:f.z.array(f.z.record(f.z.any())).optional().describe("Data array, e.g. [{name:'A', value:10}]."),chartConfig:P.ChartConfigSchema.optional()})});var ke=g(D=>{"use strict";Object.defineProperty(D,"__esModule",{value:!0});D.PuzzleContentSchema=D.PuzzleTypeSchema=D.PuzzleGameModeSchema=void 0;var A=require("zod"),Ye=w();D.PuzzleGameModeSchema=A.z.enum(["scattered","rotated","scattered_rotated"]);D.PuzzleTypeSchema=A.z.enum(["swap","slide"]);D.PuzzleContentSchema=A.z.object({image:A.z.union([A.z.string(),Ye.MediaItemSchema]).optional().describe("Image URL or MediaItem for puzzle."),pieces:A.z.number().int().optional().describe("Number of pieces (e.g. 9, 16, 25)."),gameMode:D.PuzzleGameModeSchema.optional(),puzzleType:D.PuzzleTypeSchema.optional(),showNumbers:A.z.union([A.z.boolean(),A.z.string()]).optional().describe("Show helper numbers on puzzle pieces."),seed:A.z.string().optional().describe("Deterministic seed for piece placement.")})});var Te=g(U=>{"use strict";Object.defineProperty(U,"__esModule",{value:!0});U.BasicContentSchema=void 0;var H=require("zod"),Xe=w();U.BasicContentSchema=H.z.object({content:H.z.any().optional().describe("For Editor: Plate JSON content array."),url:H.z.string().optional().describe("For Media or Embed: content URL."),text:H.z.string().optional().describe("For Shape: text inside shape."),mediaType:Xe.MediaTypeSchema.optional().describe("For Media: media type.")})});var Ce=g(b=>{"use strict";var Ze=b&&b.__createBinding||(Object.create?(function(t,n,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(n,i);(!a||("get"in a?!n.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return n[i]}}),Object.defineProperty(t,r,a)}):(function(t,n,i,r){r===void 0&&(r=i),t[r]=n[i]})),M=b&&b.__exportStar||function(t,n){for(var i in t)i!=="default"&&!Object.prototype.hasOwnProperty.call(n,i)&&Ze(n,t,i)};Object.defineProperty(b,"__esModule",{value:!0});M(de(),b);M(ue(),b);M(he(),b);M(Se(),b);M(be(),b);M(ze(),b);M(ge(),b);M(fe(),b);M(xe(),b);M(ke(),b);M(Te(),b)});var Be=g(j=>{"use strict";var eo=j&&j.__createBinding||(Object.create?(function(t,n,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(n,i);(!a||("get"in a?!n.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return n[i]}}),Object.defineProperty(t,r,a)}):(function(t,n,i,r){r===void 0&&(r=i),t[r]=n[i]})),oo=j&&j.__setModuleDefault||(Object.create?(function(t,n){Object.defineProperty(t,"default",{enumerable:!0,value:n})}):function(t,n){t.default=n}),to=j&&j.__importStar||(function(){var t=function(n){return t=Object.getOwnPropertyNames||function(i){var r=[];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(r[r.length]=a);return r},t(n)};return function(n){if(n&&n.__esModule)return n;var i={};if(n!=null)for(var r=t(n),a=0;a<r.length;a++)r[a]!=="default"&&eo(i,n,r[a]);return oo(i,n),i}})();Object.defineProperty(j,"__esModule",{value:!0});j.BLOCK_CONTENT_SCHEMAS=void 0;j.generateBlockReference=ro;var no=to(require("zod-to-json-schema")),io=no.zodToJsonSchema,p=Ce();j.BLOCK_CONTENT_SCHEMAS={Quiz:p.QuizContentSchema,Cloze:p.ClozeContentSchema,Crossword:p.CrosswordContentSchema,WordSearch:p.WordSearchContentSchema,Anagram:p.AnagramContentSchema,Memory:p.PairGameContentSchema,MatchPairs:p.PairGameContentSchema,Flashcard:p.DeckContentSchema,CardDeck:p.DeckContentSchema,Dice:p.DiceContentSchema,SpinningWheel:p.SpinnerContentSchema,DragAndDrop:p.DragAndDropContentSchema,Chart:p.ChartContentSchema,Puzzle:p.PuzzleContentSchema,Editor:p.BasicContentSchema,Media:p.BasicContentSchema,Embed:p.BasicContentSchema,Shape:p.BasicContentSchema};function ao(t,n,i,r){let a=i?"*required*":"optional",z=te(n),h=n.description?` \u2014 ${n.description}`:"";return`${r}- \`${t}\` (${z}, ${a})${h}`}function te(t){return t.enum?`enum: ${t.enum.map(n=>JSON.stringify(n)).join(" | ")}`:t.anyOf||t.oneOf?(t.anyOf||t.oneOf).map(te).join(" | "):Array.isArray(t.type)?t.type.join(" | "):t.type==="array"&&t.items?`array<${te(t.items)}>`:t.type==="object"?"object":t.type??"any"}function ne(t,n){let i=[],r=new Set(t.required??[]),a=t.properties??{};for(let[z,h]of Object.entries(a))i.push(ao(z,h,r.has(z),n)),h.type==="object"&&h.properties?i.push(ne(h,n+" ")):h.type==="array"&&h.items?.type==="object"&&i.push(ne(h.items,n+" "));return i.join(`
2
+ `)}function ro(){let t=[],n=new Map;for(let[i,r]of Object.entries(j.BLOCK_CONTENT_SCHEMAS)){let a=n.get(r)??[];a.push(i),n.set(r,a)}for(let[i,r]of n.entries()){let a=r.join(" / "),z=io(i,{target:"jsonSchema7"}),h=ne(z,"");t.push(`### ${a}
3
+ ${h||"_(no configurable fields)_"}`)}return t.join(`
4
+
5
+ `)}});var lo={};Fe(lo,{CANVAS_OP_NAMES:()=>Ne,CANVAS_OP_REQUIRED:()=>K,applyItemPatch:()=>We,detectConflict:()=>$e,entitySignature:()=>ce,generateBlockReference:()=>co,getAllBlockJsonSchemas:()=>so,getBlockJsonSchema:()=>_e,isKnownCanvasOp:()=>ae,listBlockTypes:()=>je,opConflictStamp:()=>Je,opTarget:()=>re,parseMentions:()=>Ve,resolveMentions:()=>He,stableStringify:()=>G,validateCanvasOp:()=>Ge});module.exports=Ee(lo);var K={createScene:[],deleteScene:["sceneId"],addBlock:["sceneId","block"],updateScene:["sceneId"],deleteBlock:["sceneId","blockId"],updateBlock:["sceneId","blockId","updates"],duplicateBlock:["sceneId","blockId"],groupBlocks:["blockIds"],updateBlockTheme:["sceneId","blockId","theme"],updateBlockElementStyle:["sceneId","blockId","elementId","customStyle"],addAction:["sceneId","blockId","action"],removeAction:["sceneId","blockId","actionId"],manageVariables:["operation","name"],configureTimer:[],reorderScenes:["sceneId","newIndex"],insertItem:["blockId","collection","item"],updateItem:["blockId","collection","itemId","item"],deleteItem:["blockId","collection","itemId"]},Ne=Object.keys(K);function ae(t){return Object.prototype.hasOwnProperty.call(K,t)}function Ge(t,n){if(!ae(t))return{ok:!1,code:"UNKNOWN_OP",errors:[`unknown op "${t}"`]};if(typeof n!="object"||n===null||Array.isArray(n))return{ok:!1,code:"NOT_OBJECT",errors:["op data must be an object"]};let i=n,r=K[t].filter(a=>i[a]===void 0||i[a]===null);return r.length>0?{ok:!1,code:"MISSING_FIELDS",errors:r.map(a=>`missing field: ${a}`)}:t==="groupBlocks"&&(!Array.isArray(i.blockIds)||i.blockIds.length<2)?{ok:!1,code:"MISSING_FIELDS",errors:["groupBlocks requires a blockIds array with >= 2 ids"]}:{ok:!0}}function We(t,n,i){let r=Array.isArray(t)?[...t]:[];if(n==="insertItem"){if(i.item===void 0||i.item===null)return r;let a=typeof i.at=="number"?i.at:r.length;return r.splice(Math.max(0,Math.min(a,r.length)),0,i.item),r}return n==="updateItem"?r.map(a=>a&&typeof a=="object"&&a.id===i.itemId?{...a,...i.item??{}}:a):r.filter(a=>!(a&&typeof a=="object"&&a.id===i.itemId))}var Le=new Set(["position","size","rotation","zIndex","z"]);function G(t){return t===null||typeof t!="object"?JSON.stringify(t)??"null":Array.isArray(t)?"["+t.map(G).join(",")+"]":"{"+Object.keys(t).sort().map(i=>JSON.stringify(i)+":"+G(t[i])).join(",")+"}"}function re(t,n){let i=n??{};switch(t){case"updateBlock":case"updateBlockTheme":case"updateBlockElementStyle":case"deleteBlock":case"duplicateBlock":case"removeAction":return i.blockId?{kind:"block",blockId:i.blockId}:{kind:"untracked"};case"updateItem":case"deleteItem":return i.blockId&&i.collection&&i.itemId?{kind:"item",blockId:i.blockId,collection:i.collection,itemId:i.itemId}:{kind:"untracked"};default:return{kind:"untracked"}}}function Ke(t,n){if(Array.isArray(t))for(let i of t){let r=i?.blocks?.find?.(a=>a&&a.id===n);if(r)return r}}function ce(t,n){if(n.kind==="untracked")return null;let i=n.blockId?Ke(t,n.blockId):void 0;if(!i)return null;if(n.kind==="block"){let z={};for(let h of Object.keys(i))Le.has(h)||(z[h]=i[h]);return G(z)}let r=i[n.collection];if(!Array.isArray(r))return null;let a=r.find(z=>z&&z.id===n.itemId);return a?G(a):null}function $e(t,n){return t==null?"apply":n==null?"missing":t===n?"apply":"stale"}function Je(t,n,i){let r=re(t,n);return{target:r,baseSignature:ce(i,r)}}var Y=/@\[([^\]|]+)\|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\]/g;function Ve(t){let n=[];for(let i of(t??"").matchAll(Y))n.push({name:i[1].trim(),id:i[2]});return n}function He(t,n){let i=new Map,r=new Map;for(let x of n?.scenes??[]){x?.id&&i.set(x.id,x);for(let S of x?.blocks??[])S?.id&&r.set(S.id,{block:S,sceneId:x.id})}let a=[],z=new Set,h=x=>r.has(x)?"il blocco selezionato":i.has(x)?"la scena selezionata":"l'elemento selezionato",Me=(x,S)=>{if(!z.has(S))if(r.has(S)){let{block:q,sceneId:ve}=r.get(S);a.push({id:S,name:x,kind:"block",blockType:q?.type,sceneId:ve}),z.add(S)}else i.has(S)&&(a.push({id:S,name:x,kind:"scene"}),z.add(S))},we=(t??"").replace(Y,(x,S,q)=>(Me(S.trim(),q),S.trim())),Oe=(t??"").replace(Y,(x,S,q)=>r.has(q)||i.has(q)?h(q):S.trim());return{cleanedText:we,agentText:Oe,entities:a}}var Ie=require("zod-to-json-schema"),W=Qe(Be());function co(){return(0,W.generateBlockReference)()}function je(){return Object.keys(W.BLOCK_CONTENT_SCHEMAS)}function _e(t){let n=W.BLOCK_CONTENT_SCHEMAS[t];if(n)return(0,Ie.zodToJsonSchema)(n,{target:"jsonSchema7"})}function so(){return Object.fromEntries(je().map(t=>[t,_e(t)]))}0&&(module.exports={CANVAS_OP_NAMES,CANVAS_OP_REQUIRED,applyItemPatch,detectConflict,entitySignature,generateBlockReference,getAllBlockJsonSchemas,getBlockJsonSchema,isKnownCanvasOp,listBlockTypes,opConflictStamp,opTarget,parseMentions,resolveMentions,stableStringify,validateCanvasOp});
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ var je=Object.create;var ie=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var y=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(n,i)=>(typeof require<"u"?require:n)[i]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var g=(t,n)=>()=>{try{return n||t((n={exports:{}}).exports,n),n.exports}catch(i){throw n=0,i}};var ve=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of Me(n))!Oe.call(t,a)&&a!==i&&ie(t,a,{get:()=>n[a],enumerable:!(r=_e(n,a))||r.enumerable});return t};var Pe=(t,n,i)=>(i=t!=null?je(we(t)):{},ve(n||!t||!t.__esModule?ie(i,"default",{value:t,enumerable:!0}):i,t));var O=g(m=>{"use strict";Object.defineProperty(m,"__esModule",{value:!0});m.MediaRefSchema=m.MediaItemSchema=m.VideoSettingsSchema=m.CropDataSchema=m.MediaSourceSchema=m.MediaTypeSchema=m.GridSizeSchema=m.SizeSchema=m.PositionSchema=void 0;var c=y("zod");m.PositionSchema=c.z.object({x:c.z.number(),y:c.z.number(),z:c.z.number().optional()});m.SizeSchema=c.z.object({width:c.z.number().optional(),height:c.z.number().optional()});m.GridSizeSchema=c.z.object({rows:c.z.number(),cols:c.z.number()});m.MediaTypeSchema=c.z.enum(["image","color","gif","shape","illustration","video","audio"]);m.MediaSourceSchema=c.z.enum(["unsplash","pexels","upload","url","library","tenor"]);m.CropDataSchema=c.z.object({x:c.z.number(),y:c.z.number(),width:c.z.number(),height:c.z.number(),zoom:c.z.number().optional(),rotation:c.z.number().optional(),aspect:c.z.number().optional()});m.VideoSettingsSchema=c.z.object({autoplay:c.z.boolean().optional(),loop:c.z.boolean().optional(),muted:c.z.boolean().optional(),controls:c.z.boolean().optional(),poster:c.z.string().optional(),volume:c.z.number().optional()});m.MediaItemSchema=c.z.object({id:c.z.string().optional(),url:c.z.string().optional(),title:c.z.string().optional(),type:m.MediaTypeSchema,source:m.MediaSourceSchema.optional(),alt:c.z.string().optional(),width:c.z.number().optional(),height:c.z.number().optional(),format:c.z.enum(["cover","contain"]).optional(),color:c.z.string().optional(),cropData:m.CropDataSchema.optional(),duration:c.z.number().optional(),videoSettings:m.VideoSettingsSchema.optional()});m.MediaRefSchema=m.MediaItemSchema});var re=g(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});l.QuestionSchema=l.TextQuestionSchema=l.TrueFalseQuestionSchema=l.ChoiceQuestionSchema=l.QuestionOptionSchema=l.ImageSizeSchema=l.ImageAlignSchema=l.QuestionTypeSchema=void 0;var d=y("zod"),ae=O();l.QuestionTypeSchema=d.z.enum(["single-choice","multiple-choice","true-false","short-answers","long-answers"]);l.ImageAlignSchema=d.z.enum(["left","right","center"]);l.ImageSizeSchema=d.z.object({width:d.z.number().optional(),height:d.z.number().optional()});l.QuestionOptionSchema=d.z.object({id:d.z.string(),text:d.z.string(),isCorrect:d.z.boolean(),image:ae.MediaItemSchema.optional(),imageAlign:l.ImageAlignSchema.optional(),imageSize:l.ImageSizeSchema.optional()});var X={id:d.z.string(),text:d.z.string(),score:d.z.number().optional(),image:ae.MediaItemSchema.optional(),imageAlign:l.ImageAlignSchema.optional(),imageSize:l.ImageSizeSchema.optional()};l.ChoiceQuestionSchema=d.z.object({...X,type:d.z.enum(["single-choice","multiple-choice"]),options:d.z.array(l.QuestionOptionSchema)});l.TrueFalseQuestionSchema=d.z.object({...X,type:d.z.literal("true-false"),correctAnswer:d.z.boolean()});l.TextQuestionSchema=d.z.object({...X,type:d.z.enum(["short-answers","long-answers"]),minCharacters:d.z.number().optional(),maxCharacters:d.z.number().optional()});l.QuestionSchema=d.z.discriminatedUnion("type",[l.ChoiceQuestionSchema,l.TrueFalseQuestionSchema,l.TextQuestionSchema])});var se=g(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.QuizContentSchema=T.QuizQuestionSchema=T.QuizOptionSchema=T.QuizQuestionTypeSchema=void 0;var u=y("zod"),ce=O(),K=re();T.QuizQuestionTypeSchema=u.z.enum(["single-choice","multiple-choice","true-false","short-answers","long-answers"]);T.QuizOptionSchema=u.z.object({id:u.z.string().optional(),text:u.z.string(),isCorrect:u.z.boolean(),image:ce.MediaItemSchema.optional().describe("Option image."),imageAlign:K.ImageAlignSchema.optional().describe("Option image alignment."),imageSize:K.ImageSizeSchema.optional().describe("Option image size.")});T.QuizQuestionSchema=u.z.object({id:u.z.string().optional().describe("Question ID. Auto-generated if omitted."),type:T.QuizQuestionTypeSchema,text:u.z.string().describe("The question text."),score:u.z.number().optional(),options:u.z.array(T.QuizOptionSchema).optional().describe("Required for single-choice and multiple-choice."),correctAnswer:u.z.boolean().optional().describe("Required for true-false."),image:ce.MediaItemSchema.optional().describe("Question image."),imageAlign:K.ImageAlignSchema.optional().describe("Question image alignment."),imageSize:K.ImageSizeSchema.optional().describe("Question image size.")});T.QuizContentSchema=u.z.object({questions:u.z.array(T.QuizQuestionSchema).describe("Array of question objects."),showResults:u.z.boolean().optional(),allowRetry:u.z.boolean().optional(),maxRetry:u.z.string().optional(),required:u.z.boolean().optional(),submitText:u.z.string().optional().describe("Label for submit button."),timer:u.z.string().optional().describe("Timer duration in seconds as a string."),showQuestionCount:u.z.boolean().optional().describe("Show current/total questions count.")})});var le=g(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.ClozeContentSchema=F.ClozeModeSchema=void 0;var Z=y("zod");F.ClozeModeSchema=Z.z.enum(["write","drag-drop"]);F.ClozeContentSchema=Z.z.object({templateText:Z.z.string().describe('Template text with blanks in [brackets]. E.g. "The capital of Italy is [Rome]."'),mode:F.ClozeModeSchema.optional().describe("Input mode. Default: write.")})});var de=g(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.AnagramContentSchema=C.WordSearchContentSchema=C.CrosswordContentSchema=C.CrosswordWordSchema=C.WordGameBlockTypeSchema=void 0;var f=y("zod"),me=O();C.WordGameBlockTypeSchema=f.z.enum(["Crossword","WordSearch","Anagram"]);C.CrosswordWordSchema=f.z.object({answer:f.z.string(),clue:f.z.string(),image:me.MediaItemSchema.optional().describe("Clue image.")});C.CrosswordContentSchema=f.z.object({words:f.z.array(C.CrosswordWordSchema)});C.WordSearchContentSchema=f.z.object({words:f.z.array(f.z.string()),gridSize:me.GridSizeSchema.optional().describe("Grid dimensions."),difficulty:f.z.enum(["easy","medium","hard"]).optional()});C.AnagramContentSchema=f.z.object({correctWord:f.z.string().describe("The correct word."),letters:f.z.array(f.z.string()).optional(),clue:f.z.string().optional().describe("A hint.")})});var ue=g(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.PairGameContentSchema=I.PairSchema=I.MemoryPairTypeSchema=I.PairGameBlockTypeSchema=void 0;var M=y("zod"),ee=O();I.PairGameBlockTypeSchema=M.z.enum(["Memory","MatchPairs"]);I.MemoryPairTypeSchema=M.z.enum(["img-img","img-word","word-word"]);I.PairSchema=M.z.object({id:M.z.string().optional(),type:I.MemoryPairTypeSchema.optional().describe("For Memory: pair type."),content:M.z.array(M.z.string()).optional().describe("For Memory: [item1, item2]."),leftLabel:M.z.string().optional().describe("For MatchPairs: left side text."),rightLabel:M.z.string().optional().describe("For MatchPairs: right side text."),leftImage:ee.MediaItemSchema.optional().describe("For MatchPairs: left side image."),rightImage:ee.MediaItemSchema.optional().describe("For MatchPairs: right side image.")});I.PairGameContentSchema=M.z.object({pairs:M.z.array(I.PairSchema).describe("Array of pair objects."),gridSize:ee.GridSizeSchema.optional().describe("For Memory: grid dimensions."),instructions:M.z.string().optional().describe("For MatchPairs: instruction text.")})});var pe=g(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.DeckContentSchema=B.CardSchema=B.CardFaceSchema=B.DeckBlockTypeSchema=void 0;var j=y("zod");B.DeckBlockTypeSchema=j.z.enum(["Flashcard","CardDeck"]);B.CardFaceSchema=j.z.object({type:j.z.enum(["text","image"]),content:j.z.any()});B.CardSchema=j.z.object({id:j.z.string().optional(),front:B.CardFaceSchema.optional().describe("For Flashcard: front side."),back:B.CardFaceSchema.optional().describe("For Flashcard: back side."),frontText:j.z.string().optional().describe("For CardDeck: front text."),frontImage:j.z.any().optional().describe("For CardDeck: front image.")});B.DeckContentSchema=j.z.object({cards:j.z.array(B.CardSchema).describe("Array of card objects."),backImage:j.z.any().optional().describe("For CardDeck: shared back image."),discardLogic:j.z.enum(["delete","return"]).optional().describe("For CardDeck.")})});var he=g(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.DiceContentSchema=Q.DieTypeSchema=void 0;var G=y("zod");Q.DieTypeSchema=G.z.enum(["d4","d6","d8","d10","d12","d20"]);Q.DiceContentSchema=G.z.object({diceType:Q.DieTypeSchema.optional(),diceCount:G.z.number().int().min(1).max(10).optional(),color:G.z.string().optional().describe("CSS color for dice."),showNumber:G.z.boolean().optional(),persistent:G.z.boolean().optional().describe("Keep dice visible after roll.")})});var Se=g(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.SpinnerContentSchema=N.SpinnerSliceSchema=void 0;var E=y("zod"),Qe=O();N.SpinnerSliceSchema=E.z.object({id:E.z.string().optional(),text:E.z.string(),color:E.z.string().optional().describe("CSS color for slice."),image:Qe.MediaItemSchema.optional().describe("Slice image.")});N.SpinnerContentSchema=E.z.object({slices:E.z.array(N.SpinnerSliceSchema).min(2).describe("Wheel slices (min 2)."),spinDuration:E.z.number().optional().describe("Spin duration in seconds.")})});var be=g(o=>{"use strict";Object.defineProperty(o,"__esModule",{value:!0});o.ShapeBlockThemeSchema=o.MatchPairsBlockThemeSchema=o.FlashcardBlockThemeSchema=o.CardDeckBlockThemeSchema=o.ClozeBlockThemeSchema=o.SpinningWheelBlockThemeSchema=o.MemoryBlockThemeSchema=o.WordSearchBlockThemeSchema=o.CrosswordBlockThemeSchema=o.DiceBlockThemeSchema=o.AnagramBlockThemeSchema=o.EditorBlockThemeSchema=o.DragAndDropBlockThemeSchema=o.QuizBlockThemeSchema=o.HotpointBlockThemeSchema=o.BlockThemeSchema=o.TextStylesSchema=o.BoxStylesSchema=o.RadiusSchema=o.BoxSideSchema=o.AnimationSchema=void 0;var e=y("zod"),oe=O();o.AnimationSchema=e.z.object({type:e.z.union([e.z.enum(["none","fade","direction","bounce","scale","rotate"]),e.z.string()]),duration:e.z.number().optional(),delay:e.z.number().optional(),phase:e.z.enum(["in","both","out"]).optional(),direction:e.z.enum(["up","right","down","left"]).optional()});o.BoxSideSchema=e.z.object({top:e.z.union([e.z.string(),e.z.number()]).optional(),right:e.z.union([e.z.string(),e.z.number()]).optional(),bottom:e.z.union([e.z.string(),e.z.number()]).optional(),left:e.z.union([e.z.string(),e.z.number()]).optional()});o.RadiusSchema=e.z.object({topLeft:e.z.union([e.z.string(),e.z.number()]).optional(),topRight:e.z.union([e.z.string(),e.z.number()]).optional(),bottomRight:e.z.union([e.z.string(),e.z.number()]).optional(),bottomLeft:e.z.union([e.z.string(),e.z.number()]).optional()});o.BoxStylesSchema=e.z.object({background:e.z.boolean().optional(),backgroundColor:e.z.string().optional(),backgroundOpacity:e.z.number().optional(),backgroundMedia:oe.MediaItemSchema.optional(),border:e.z.boolean().optional(),borderColor:e.z.string().optional(),borderWidth:o.BoxSideSchema.optional(),borderRadius:o.RadiusSchema.optional(),padding:e.z.union([e.z.string(),e.z.number(),o.BoxSideSchema]).optional()});o.TextStylesSchema=e.z.object({color:e.z.string().optional(),fontSize:e.z.number().optional(),fontFamily:e.z.string().optional(),fontStyle:e.z.string().optional(),fontWeight:e.z.union([e.z.string(),e.z.number()]).optional(),textAlign:e.z.enum(["left","center","right","justify"]).optional()});var v=o.BoxStylesSchema.merge(o.TextStylesSchema);o.BlockThemeSchema=e.z.object({spacing:e.z.enum(["no-spacing","small","medium","large"]).optional(),animation:o.AnimationSchema.optional(),styles:e.z.record(e.z.record(e.z.any())).optional()});o.HotpointBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({hotpoint:e.z.object({icon:e.z.string().optional(),iconPosition:e.z.enum(["left","right"]).optional(),iconSize:e.z.string().optional(),iconColor:e.z.string().optional(),image:oe.MediaItemSchema.optional(),imageFormat:e.z.enum(["circle","square","custom"]).optional(),border:e.z.boolean().optional(),borderColor:e.z.string().optional(),borderWidth:e.z.string().optional(),borderRadius:e.z.string().optional(),glow:e.z.boolean().optional(),glowColor:e.z.string().optional(),background:e.z.boolean().optional(),backgroundColor:e.z.string().optional(),fontSize:e.z.number().optional(),fontFamily:e.z.string().optional(),fontStyle:e.z.string().optional(),textColor:e.z.string().optional()}).optional()}).optional()});o.QuizBlockThemeSchema=o.BlockThemeSchema.extend({layout:e.z.enum(["horizontal","vertical","grid"]),gridColumns:e.z.number().optional(),preset:e.z.enum(["default","modern","trivia","custom"]),styles:e.z.object({general:v,question:v,answers:v.extend({customStyles:e.z.array(e.z.object({color:e.z.string().optional(),backgroundColor:e.z.string().optional(),targets:e.z.string().optional()})).optional(),hover:v.optional()}),button:v.extend({variant:e.z.enum(["default","outline","ghost"]).optional(),hover:v.optional()})}).optional()});o.DragAndDropBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),splitRatio:e.z.number().optional(),gridColumns:e.z.number().optional(),gridGap:e.z.number().optional().describe("Gap in pixels between auto-laid items (list/grid)."),pool:e.z.object({x:e.z.number().optional(),y:e.z.number().optional(),width:e.z.number().optional(),height:e.z.number().optional()}).optional().describe("Movable/resizable frame for the list/grid item pool (sandbox px)."),styles:e.z.object({title:o.TextStylesSchema.optional(),sandbox:o.BoxStylesSchema.optional(),item:v.optional(),group:o.BoxStylesSchema.optional(),container:o.BoxStylesSchema.extend({url:e.z.string().optional(),type:oe.MediaTypeSchema.optional()}).optional(),groups:v.optional(),feedback:e.z.object({correct:e.z.string().optional(),incorrect:e.z.string().optional(),active:e.z.string().optional()}).optional(),referenceSize:e.z.object({width:e.z.number(),height:e.z.number()}).optional()}).optional()});o.EditorBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({editor:o.BoxStylesSchema.optional()}).optional()});o.AnagramBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({letter:o.BoxStylesSchema.optional(),letterText:o.TextStylesSchema.optional(),slot:o.BoxStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.DiceBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({button:o.BoxStylesSchema.extend({hover:v.optional()}).optional(),buttonText:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.CrosswordBlockThemeSchema=o.BlockThemeSchema.extend({primaryColor:e.z.string().optional(),layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),splitRatio:e.z.number().optional(),styles:e.z.object({text:o.TextStylesSchema.optional(),cell:o.BoxStylesSchema.optional(),grid:o.BoxStylesSchema.optional(),clueContainer:o.BoxStylesSchema.optional(),clueText:o.TextStylesSchema.optional(),clueTitle:o.TextStylesSchema.optional()}).optional()});o.WordSearchBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),splitRatio:e.z.number().optional(),styles:e.z.object({wordSearch:e.z.object({primaryColor:e.z.string().optional(),highlightColor:e.z.string().optional(),fontSize:e.z.number().optional(),fontFamily:e.z.string().optional(),textColor:e.z.string().optional(),cellBackgroundColor:e.z.string().optional()}).optional(),text:o.TextStylesSchema.optional(),cell:o.BoxStylesSchema.optional(),grid:o.BoxStylesSchema.optional(),wordListContainer:o.BoxStylesSchema.optional(),wordListText:o.TextStylesSchema.optional(),wordListTitle:o.TextStylesSchema.optional()}).optional()});o.MemoryBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({text:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional(),infoContainer:o.BoxStylesSchema.optional(),infoText:o.TextStylesSchema.optional(),card:o.BoxStylesSchema.optional()}).optional()});o.SpinningWheelBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({wheelText:o.TextStylesSchema.optional()}).optional()});o.ClozeBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),styles:e.z.object({text:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional(),wordBank:o.BoxStylesSchema.optional(),word:o.BoxStylesSchema.optional(),blank:o.BoxStylesSchema.optional()}).optional()});o.CardDeckBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({card:o.BoxStylesSchema.optional(),cardText:o.TextStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.FlashcardBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({cardFront:o.BoxStylesSchema.optional(),cardBack:o.BoxStylesSchema.optional(),frontText:o.TextStylesSchema.optional(),backText:o.TextStylesSchema.optional(),navigation:o.BoxStylesSchema.optional(),navigationText:o.TextStylesSchema.optional()}).optional()});o.MatchPairsBlockThemeSchema=o.BlockThemeSchema.extend({layoutPosition:e.z.enum(["left","right","top","bottom"]).optional(),styles:e.z.object({text:o.TextStylesSchema.optional(),card:o.BoxStylesSchema.optional(),container:o.BoxStylesSchema.optional()}).optional()});o.ShapeBlockThemeSchema=o.BlockThemeSchema.extend({styles:e.z.object({shape:v.extend({fillColor:e.z.string().optional(),textColor:e.z.string().optional(),borderStyle:e.z.enum(["solid","dashed","dotted"]).optional(),padding:e.z.number().optional()}).optional()}).optional()})});var ze=g(P=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.DragAndDropContentSchema=P.DragGroupSchema=P.DragItemSchema=void 0;var s=y("zod"),$=O(),J=be();P.DragItemSchema=s.z.object({id:s.z.string().optional(),text:s.z.string(),background:$.MediaItemSchema.optional().describe("Background image/color for item."),opacity:s.z.number().optional().describe("Opacity of the item (0-1)."),x:s.z.number().optional().describe("Manual x position in pixels (sandbox space, origin top-left; sandbox size = block.size)."),y:s.z.number().optional().describe("Manual y position in pixels (sandbox space, origin top-left)."),fx:s.z.number().optional().describe("Resize-invariant x as a fraction (0-1) of sandbox width. Preferred over x when present."),fy:s.z.number().optional().describe("Resize-invariant y as a fraction (0-1) of sandbox height. Preferred over y when present."),width:s.z.number().optional().describe("Manual width in pixels."),height:s.z.number().optional().describe("Manual height in pixels."),styles:J.BoxStylesSchema.optional().describe("Box custom styling styles."),textStyles:J.TextStylesSchema.optional().describe("Text custom styling styles.")});P.DragGroupSchema=s.z.object({id:s.z.string().optional(),name:s.z.string().describe("Group/dropzone name."),singleItem:s.z.boolean().optional().describe("Accept only one item inside."),background:$.MediaItemSchema.optional().describe("Background image/color for group."),x:s.z.number().optional().describe("Manual x position in pixels (sandbox space, origin top-left; sandbox size = block.size)."),y:s.z.number().optional().describe("Manual y position in pixels (sandbox space, origin top-left)."),fx:s.z.number().optional().describe("Resize-invariant x as a fraction (0-1) of sandbox width. Preferred over x when present."),fy:s.z.number().optional().describe("Resize-invariant y as a fraction (0-1) of sandbox height. Preferred over y when present."),width:s.z.number().optional().describe("Manual width in pixels."),height:s.z.number().optional().describe("Manual height in pixels."),opacity:s.z.number().optional().describe("Opacity of the group (0-1)."),styles:J.BoxStylesSchema.optional().describe("Box custom styling styles."),textStyles:J.TextStylesSchema.optional().describe("Text custom styling styles."),items:s.z.array(P.DragItemSchema).describe("Items that belong in this group.")});P.DragAndDropContentSchema=s.z.object({groups:s.z.array(P.DragGroupSchema).min(1).describe("Drag-and-drop groups."),layout:s.z.enum(["manual","split"]).optional().describe("Layout mode: manual placements or split areas."),itemArrangement:s.z.enum(["random","list","grid"]).optional().describe("Initial item arrangement inside sandbox."),showResults:s.z.boolean().optional().describe("Show result feedback immediately."),requireSubmit:s.z.boolean().optional().describe("Require an explicit 'Check' button to grade instead of auto-grading when all items are placed."),enableWrongAnswers:s.z.boolean().optional().describe("Allow placing items in incorrect groups."),groupBackground:$.MediaItemSchema.optional().describe("Shared background image/color for all groups."),itemBackground:$.MediaItemSchema.optional().describe("Shared background image/color for all items."),groupBackgroundOpacity:s.z.number().optional().describe("Shared group background opacity (0-1)."),itemBackgroundOpacity:s.z.number().optional().describe("Shared item background opacity (0-1)."),splitRatio:s.z.number().optional().describe("Proportion ratio for split layout.")})});var ge=g(A=>{"use strict";Object.defineProperty(A,"__esModule",{value:!0});A.ChartContentSchema=A.ChartConfigSchema=A.ChartTypeSchema=void 0;var x=y("zod");A.ChartTypeSchema=x.z.enum(["line","bar","pie","doughnut","radar","area","scatter"]);A.ChartConfigSchema=x.z.object({colors:x.z.array(x.z.string()).optional(),xAxisLabel:x.z.string().optional(),yAxisLabel:x.z.string().optional(),showLegend:x.z.boolean().optional(),showTooltip:x.z.boolean().optional(),stacked:x.z.boolean().optional(),seriesNames:x.z.record(x.z.string()).optional().describe("Dictionary mapping series keys to custom labels.")});A.ChartContentSchema=x.z.object({chartType:A.ChartTypeSchema.optional(),chartData:x.z.array(x.z.record(x.z.any())).optional().describe("Data array, e.g. [{name:'A', value:10}]."),chartConfig:A.ChartConfigSchema.optional()})});var ye=g(q=>{"use strict";Object.defineProperty(q,"__esModule",{value:!0});q.PuzzleContentSchema=q.PuzzleTypeSchema=q.PuzzleGameModeSchema=void 0;var D=y("zod"),Ee=O();q.PuzzleGameModeSchema=D.z.enum(["scattered","rotated","scattered_rotated"]);q.PuzzleTypeSchema=D.z.enum(["swap","slide"]);q.PuzzleContentSchema=D.z.object({image:D.z.union([D.z.string(),Ee.MediaItemSchema]).optional().describe("Image URL or MediaItem for puzzle."),pieces:D.z.number().int().optional().describe("Number of pieces (e.g. 9, 16, 25)."),gameMode:q.PuzzleGameModeSchema.optional(),puzzleType:q.PuzzleTypeSchema.optional(),showNumbers:D.z.union([D.z.boolean(),D.z.string()]).optional().describe("Show helper numbers on puzzle pieces."),seed:D.z.string().optional().describe("Deterministic seed for piece placement.")})});var fe=g(H=>{"use strict";Object.defineProperty(H,"__esModule",{value:!0});H.BasicContentSchema=void 0;var V=y("zod"),Ne=O();H.BasicContentSchema=V.z.object({content:V.z.any().optional().describe("For Editor: Plate JSON content array."),url:V.z.string().optional().describe("For Media or Embed: content URL."),text:V.z.string().optional().describe("For Shape: text inside shape."),mediaType:Ne.MediaTypeSchema.optional().describe("For Media: media type.")})});var xe=g(b=>{"use strict";var Ge=b&&b.__createBinding||(Object.create?(function(t,n,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(n,i);(!a||("get"in a?!n.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return n[i]}}),Object.defineProperty(t,r,a)}):(function(t,n,i,r){r===void 0&&(r=i),t[r]=n[i]})),w=b&&b.__exportStar||function(t,n){for(var i in t)i!=="default"&&!Object.prototype.hasOwnProperty.call(n,i)&&Ge(n,t,i)};Object.defineProperty(b,"__esModule",{value:!0});w(se(),b);w(le(),b);w(de(),b);w(ue(),b);w(pe(),b);w(he(),b);w(Se(),b);w(ze(),b);w(ge(),b);w(ye(),b);w(fe(),b)});var ke=g(_=>{"use strict";var We=_&&_.__createBinding||(Object.create?(function(t,n,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(n,i);(!a||("get"in a?!n.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return n[i]}}),Object.defineProperty(t,r,a)}):(function(t,n,i,r){r===void 0&&(r=i),t[r]=n[i]})),Le=_&&_.__setModuleDefault||(Object.create?(function(t,n){Object.defineProperty(t,"default",{enumerable:!0,value:n})}):function(t,n){t.default=n}),Ke=_&&_.__importStar||(function(){var t=function(n){return t=Object.getOwnPropertyNames||function(i){var r=[];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(r[r.length]=a);return r},t(n)};return function(n){if(n&&n.__esModule)return n;var i={};if(n!=null)for(var r=t(n),a=0;a<r.length;a++)r[a]!=="default"&&We(i,n,r[a]);return Le(i,n),i}})();Object.defineProperty(_,"__esModule",{value:!0});_.BLOCK_CONTENT_SCHEMAS=void 0;_.generateBlockReference=He;var $e=Ke(y("zod-to-json-schema")),Je=$e.zodToJsonSchema,p=xe();_.BLOCK_CONTENT_SCHEMAS={Quiz:p.QuizContentSchema,Cloze:p.ClozeContentSchema,Crossword:p.CrosswordContentSchema,WordSearch:p.WordSearchContentSchema,Anagram:p.AnagramContentSchema,Memory:p.PairGameContentSchema,MatchPairs:p.PairGameContentSchema,Flashcard:p.DeckContentSchema,CardDeck:p.DeckContentSchema,Dice:p.DiceContentSchema,SpinningWheel:p.SpinnerContentSchema,DragAndDrop:p.DragAndDropContentSchema,Chart:p.ChartContentSchema,Puzzle:p.PuzzleContentSchema,Editor:p.BasicContentSchema,Media:p.BasicContentSchema,Embed:p.BasicContentSchema,Shape:p.BasicContentSchema};function Ve(t,n,i,r){let a=i?"*required*":"optional",z=te(n),h=n.description?` \u2014 ${n.description}`:"";return`${r}- \`${t}\` (${z}, ${a})${h}`}function te(t){return t.enum?`enum: ${t.enum.map(n=>JSON.stringify(n)).join(" | ")}`:t.anyOf||t.oneOf?(t.anyOf||t.oneOf).map(te).join(" | "):Array.isArray(t.type)?t.type.join(" | "):t.type==="array"&&t.items?`array<${te(t.items)}>`:t.type==="object"?"object":t.type??"any"}function ne(t,n){let i=[],r=new Set(t.required??[]),a=t.properties??{};for(let[z,h]of Object.entries(a))i.push(Ve(z,h,r.has(z),n)),h.type==="object"&&h.properties?i.push(ne(h,n+" ")):h.type==="array"&&h.items?.type==="object"&&i.push(ne(h.items,n+" "));return i.join(`
2
+ `)}function He(){let t=[],n=new Map;for(let[i,r]of Object.entries(_.BLOCK_CONTENT_SCHEMAS)){let a=n.get(r)??[];a.push(i),n.set(r,a)}for(let[i,r]of n.entries()){let a=r.join(" / "),z=Je(i,{target:"jsonSchema7"}),h=ne(z,"");t.push(`### ${a}
3
+ ${h||"_(no configurable fields)_"}`)}return t.join(`
4
+
5
+ `)}});var U={createScene:[],deleteScene:["sceneId"],addBlock:["sceneId","block"],updateScene:["sceneId"],deleteBlock:["sceneId","blockId"],updateBlock:["sceneId","blockId","updates"],duplicateBlock:["sceneId","blockId"],groupBlocks:["blockIds"],updateBlockTheme:["sceneId","blockId","theme"],updateBlockElementStyle:["sceneId","blockId","elementId","customStyle"],addAction:["sceneId","blockId","action"],removeAction:["sceneId","blockId","actionId"],manageVariables:["operation","name"],configureTimer:[],reorderScenes:["sceneId","newIndex"],insertItem:["blockId","collection","item"],updateItem:["blockId","collection","itemId","item"],deleteItem:["blockId","collection","itemId"]},eo=Object.keys(U);function Ae(t){return Object.prototype.hasOwnProperty.call(U,t)}function oo(t,n){if(!Ae(t))return{ok:!1,code:"UNKNOWN_OP",errors:[`unknown op "${t}"`]};if(typeof n!="object"||n===null||Array.isArray(n))return{ok:!1,code:"NOT_OBJECT",errors:["op data must be an object"]};let i=n,r=U[t].filter(a=>i[a]===void 0||i[a]===null);return r.length>0?{ok:!1,code:"MISSING_FIELDS",errors:r.map(a=>`missing field: ${a}`)}:t==="groupBlocks"&&(!Array.isArray(i.blockIds)||i.blockIds.length<2)?{ok:!1,code:"MISSING_FIELDS",errors:["groupBlocks requires a blockIds array with >= 2 ids"]}:{ok:!0}}function to(t,n,i){let r=Array.isArray(t)?[...t]:[];if(n==="insertItem"){if(i.item===void 0||i.item===null)return r;let a=typeof i.at=="number"?i.at:r.length;return r.splice(Math.max(0,Math.min(a,r.length)),0,i.item),r}return n==="updateItem"?r.map(a=>a&&typeof a=="object"&&a.id===i.itemId?{...a,...i.item??{}}:a):r.filter(a=>!(a&&typeof a=="object"&&a.id===i.itemId))}var De=new Set(["position","size","rotation","zIndex","z"]);function L(t){return t===null||typeof t!="object"?JSON.stringify(t)??"null":Array.isArray(t)?"["+t.map(L).join(",")+"]":"{"+Object.keys(t).sort().map(i=>JSON.stringify(i)+":"+L(t[i])).join(",")+"}"}function qe(t,n){let i=n??{};switch(t){case"updateBlock":case"updateBlockTheme":case"updateBlockElementStyle":case"deleteBlock":case"duplicateBlock":case"removeAction":return i.blockId?{kind:"block",blockId:i.blockId}:{kind:"untracked"};case"updateItem":case"deleteItem":return i.blockId&&i.collection&&i.itemId?{kind:"item",blockId:i.blockId,collection:i.collection,itemId:i.itemId}:{kind:"untracked"};default:return{kind:"untracked"}}}function Re(t,n){if(Array.isArray(t))for(let i of t){let r=i?.blocks?.find?.(a=>a&&a.id===n);if(r)return r}}function Fe(t,n){if(n.kind==="untracked")return null;let i=n.blockId?Re(t,n.blockId):void 0;if(!i)return null;if(n.kind==="block"){let z={};for(let h of Object.keys(i))De.has(h)||(z[h]=i[h]);return L(z)}let r=i[n.collection];if(!Array.isArray(r))return null;let a=r.find(z=>z&&z.id===n.itemId);return a?L(a):null}function io(t,n){return t==null?"apply":n==null?"missing":t===n?"apply":"stale"}function ao(t,n,i){let r=qe(t,n);return{target:r,baseSignature:Fe(i,r)}}var Y=/@\[([^\]|]+)\|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\]/g;function co(t){let n=[];for(let i of(t??"").matchAll(Y))n.push({name:i[1].trim(),id:i[2]});return n}function so(t,n){let i=new Map,r=new Map;for(let k of n?.scenes??[]){k?.id&&i.set(k.id,k);for(let S of k?.blocks??[])S?.id&&r.set(S.id,{block:S,sceneId:k.id})}let a=[],z=new Set,h=k=>r.has(k)?"il blocco selezionato":i.has(k)?"la scena selezionata":"l'elemento selezionato",Te=(k,S)=>{if(!z.has(S))if(r.has(S)){let{block:R,sceneId:Ie}=r.get(S);a.push({id:S,name:k,kind:"block",blockType:R?.type,sceneId:Ie}),z.add(S)}else i.has(S)&&(a.push({id:S,name:k,kind:"scene"}),z.add(S))},Ce=(t??"").replace(Y,(k,S,R)=>(Te(S.trim(),R),S.trim())),Be=(t??"").replace(Y,(k,S,R)=>r.has(R)||i.has(R)?h(R):S.trim());return{cleanedText:Ce,agentText:Be,entities:a}}var W=Pe(ke());import{zodToJsonSchema as Ue}from"zod-to-json-schema";function _o(){return(0,W.generateBlockReference)()}function Ye(){return Object.keys(W.BLOCK_CONTENT_SCHEMAS)}function Xe(t){let n=W.BLOCK_CONTENT_SCHEMAS[t];if(n)return Ue(n,{target:"jsonSchema7"})}function Mo(){return Object.fromEntries(Ye().map(t=>[t,Xe(t)]))}export{eo as CANVAS_OP_NAMES,U as CANVAS_OP_REQUIRED,to as applyItemPatch,io as detectConflict,Fe as entitySignature,_o as generateBlockReference,Mo as getAllBlockJsonSchemas,Xe as getBlockJsonSchema,Ae as isKnownCanvasOp,Ye as listBlockTypes,ao as opConflictStamp,qe as opTarget,co as parseMentions,so as resolveMentions,L as stableStringify,oo as validateCanvasOp};
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@edugate/ai-agent",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "source": "src/index.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.js"
15
+ }
16
+ },
17
+ "private": false,
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "dependencies": {
22
+ "zod": "^3.24.2",
23
+ "zod-to-json-schema": "^3.23.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^25.9.1",
27
+ "cross-env": "^10.1.0",
28
+ "tsup": "^8.5.1",
29
+ "vitest": "^4.1.8",
30
+ "@edugate/types": "0.0.0"
31
+ },
32
+ "scripts": {
33
+ "build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 tsup src/index.ts --format cjs,esm --dts --minify --tsconfig tsconfig.build.json",
34
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch --tsconfig tsconfig.build.json",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest"
37
+ }
38
+ }