@memizy/protocol 1.0.0-rc.5 → 1.0.0-rc.7

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.
@@ -1,11 +1,13 @@
1
1
  import { OQSEAnyItem, OQSEMeta, ProgressRecord } from '@memizy/oqse';
2
- import { HostAs, PluginView } from './pluginRuntime';
3
- /** Address of an instance: a player ID, `"board"`; `"server"` is reserved. */
2
+ import { HostAs, PluginView } from './pluginRuntime.js';
3
+ /** Address of an instance: a player ID, `"board"`, `"settings"` (`SETTINGS_ADDRESS`); `"server"` is reserved. */
4
4
  export type Address = string;
5
5
  /** Address of the presenter's board. */
6
6
  export declare const BOARD_ADDRESS = "board";
7
7
  /** Reserved for a future server-side authority (SPEC 3.1). */
8
8
  export declare const SERVER_ADDRESS = "server";
9
+ /** Address of the plugin's own settings screen in the lobby (view `settings`). */
10
+ export declare const SETTINGS_ADDRESS = "settings";
9
11
  export type SessionMode = 'solo' | 'multiplayer';
10
12
  export interface Player {
11
13
  id: string;
@@ -39,7 +41,8 @@ export interface Handshake {
39
41
  };
40
42
  features: string[];
41
43
  }
42
- export interface Theme {
44
+ /** Language and theme of the app (`InitPayload.config`, `configChanged`). */
45
+ export interface HostConfig {
43
46
  locale: string;
44
47
  theme: 'light' | 'dark';
45
48
  }
@@ -68,34 +71,38 @@ export interface InitPayload {
68
71
  };
69
72
  /** Values for every declared setting (defaults applied). */
70
73
  settings: Record<string, unknown>;
71
- config: Theme;
74
+ config: HostConfig;
72
75
  /** The session clock and its pauses (see {@link SessionClock}). */
73
76
  clock: SessionClock;
74
- /**
75
- * RC4: Memizy services this host offers to the plugin (declared in its manifest and
76
- * available here); call them with `service()`. Absent on older hosts.
77
- */
78
- services?: string[];
77
+ /** Memizy services this host offers to the plugin (declared in its manifest and available here); call them with `service()`. */
78
+ services: string[];
79
79
  /** Learning progress of `self` (empty for board/settings). */
80
80
  progress: Record<string, ProgressRecord>;
81
81
  /** Plugin data of `self` (`null` values for board/settings). */
82
82
  data: PluginData;
83
83
  /** Last saved snapshot, only for the authority (resume). */
84
84
  snapshot: unknown | null;
85
+ /**
86
+ * Only for the authority: the secret seed of the game's random numbers (at least 128 bits,
87
+ * e.g. 32 hex digits). Other instances never get it (SPEC 4.2).
88
+ */
89
+ seed?: string;
85
90
  }
86
91
  /**
87
- * The session clock. `Date.now() + offsetMs` is the session time. RC4 adds pauses: the
92
+ * The session clock. `Date.now() + offsetMs` is the session time. Pauses: the
88
93
  * game time is `(pausedAt ?? sessionTime) - pausedMs` – it stands still while the host
89
94
  * has paused the game (`pausedAt` = session time of the pause) and continues afterwards
90
95
  * without the paused time (`pausedMs` = total of finished pauses).
91
96
  */
92
97
  export interface SessionClock {
93
98
  offsetMs: number;
94
- pausedMs?: number;
95
- pausedAt?: number | null;
99
+ /** Total length of finished pauses (ms). */
100
+ pausedMs: number;
101
+ /** Session time when the current pause started, or `null` while the game runs. */
102
+ pausedAt: number | null;
96
103
  }
97
104
  export interface AnswerRecord {
98
- /** Default: self. The authority may record for any player. */
105
+ /** Default: self (the authority as a player); required when the board records. Only the authority records (SPEC 5). */
99
106
  playerId?: string;
100
107
  itemId: string;
101
108
  isCorrect: boolean;
@@ -104,12 +111,17 @@ export interface AnswerRecord {
104
111
  hintsUsed?: number;
105
112
  isSkipped?: boolean;
106
113
  /**
107
- * RC4: what the player answered, in the `checkAnswer` format of the item type
114
+ * Partial credit between 0 and 1 (e.g. 2 of 3 correct pairs = 0.67), for items that allow
115
+ * it (OQSE `pedagogy.partialCredit`). `isCorrect` stays the outcome used for repetition.
116
+ */
117
+ score?: number;
118
+ /**
119
+ * What the player answered, in the `checkAnswer` format of the item type
108
120
  * (choice IDs, text, numbers…). Lets teachers see which wrong answers were chosen.
109
121
  */
110
122
  answer?: unknown;
111
123
  /**
112
- * RC4: the item itself, required when `itemId` is not in the set (a generated item, e.g.
124
+ * The item itself, required when `itemId` is not in the set (a generated item, e.g.
113
125
  * from a service). It needs at least `id` (= `itemId`) and `type`; the answer fields may
114
126
  * be left out. Such answers count for statistics (`skills`, `tags`), not for repetition.
115
127
  */
@@ -130,9 +142,6 @@ export interface SettingsUpdate {
130
142
  valid: boolean;
131
143
  message?: string;
132
144
  }
133
- export interface ResizeRequest {
134
- height: number | 'auto';
135
- }
136
145
  export interface ErrorReport {
137
146
  code: string;
138
147
  message: string;
@@ -150,7 +159,7 @@ export interface IncomingMessage {
150
159
  /** Session clock (ms). */
151
160
  sentAt: number;
152
161
  }
153
- export type SessionEndReason = 'finished' | 'host_left' | 'kicked' | 'closed' | 'error';
162
+ export type SessionEndReason = 'finished' | 'host-left' | 'kicked' | 'closed' | 'error';
154
163
  /** Methods the host exposes to the plugin (plugin → host). SPEC section 5. */
155
164
  export interface HostApi {
156
165
  hello(handshake: Handshake): Promise<InitPayload>;
@@ -158,15 +167,12 @@ export interface HostApi {
158
167
  send(message: OutgoingMessage): Promise<void>;
159
168
  saveSnapshot(snapshot: unknown): Promise<void>;
160
169
  recordAnswer(answer: AnswerRecord): Promise<void>;
161
- saveProgress(records: Record<string, ProgressRecord>): Promise<void>;
162
170
  saveData(scope: DataScope, value: unknown): Promise<void>;
163
171
  updateSettings(update: SettingsUpdate): Promise<void>;
164
172
  getAsset(key: string, itemId?: string): Promise<Blob>;
165
173
  end(result: SessionResult): Promise<void>;
166
- resize(request: ResizeRequest): Promise<void>;
167
174
  reportError(error: ErrorReport): Promise<void>;
168
- exit(): Promise<void>;
169
- /** RC4: calls a Memizy service (one of `InitPayload.services`); returns its JSON result. */
175
+ /** Calls a Memizy service (one of `InitPayload.services`); returns its JSON result. */
170
176
  service(name: string, payload: unknown): Promise<unknown>;
171
177
  }
172
178
  /** Methods the plugin exposes to the host (host → plugin). SPEC section 7. */
@@ -177,14 +183,10 @@ export interface PluginApi {
177
183
  authorityChanged(status: {
178
184
  connected: boolean;
179
185
  }): Promise<void>;
180
- setChanged(set: {
181
- meta: OQSEMeta;
182
- items: OQSEAnyItem[];
183
- }): Promise<void>;
184
- configChanged(config: Theme): Promise<void>;
185
- /** The clock was corrected, or the game was paused / resumed (RC4). */
186
+ configChanged(config: HostConfig): Promise<void>;
187
+ /** The clock was corrected, or the game was paused / resumed. */
186
188
  clockChanged(clock: SessionClock): Promise<void>;
187
189
  sessionEnded(reason: SessionEndReason): Promise<void>;
188
190
  }
189
- export declare const HOST_API_METHODS: readonly ["hello", "ready", "send", "saveSnapshot", "recordAnswer", "saveProgress", "saveData", "updateSettings", "getAsset", "end", "resize", "reportError", "exit", "service"];
190
- export declare const PLUGIN_API_METHODS: readonly ["start", "deliver", "playersChanged", "authorityChanged", "setChanged", "configChanged", "clockChanged", "sessionEnded"];
191
+ export declare const HOST_API_METHODS: readonly ["hello", "ready", "send", "saveSnapshot", "recordAnswer", "saveData", "updateSettings", "getAsset", "end", "reportError", "service"];
192
+ export declare const PLUGIN_API_METHODS: readonly ["start", "deliver", "playersChanged", "authorityChanged", "configChanged", "clockChanged", "sessionEnded"];
package/dist/types.cjs CHANGED
@@ -1 +1 @@
1
- var e=`board`,t=`server`,n=[`hello`,`ready`,`send`,`saveSnapshot`,`recordAnswer`,`saveProgress`,`saveData`,`updateSettings`,`getAsset`,`end`,`resize`,`reportError`,`exit`,`service`],r=[`start`,`deliver`,`playersChanged`,`authorityChanged`,`setChanged`,`configChanged`,`clockChanged`,`sessionEnded`];exports.BOARD_ADDRESS=e,exports.HOST_API_METHODS=n,exports.PLUGIN_API_METHODS=r,exports.SERVER_ADDRESS=t;
1
+ var e=`board`,t=`server`,n=`settings`,r=[`hello`,`ready`,`send`,`saveSnapshot`,`recordAnswer`,`saveData`,`updateSettings`,`getAsset`,`end`,`reportError`,`service`],i=[`start`,`deliver`,`playersChanged`,`authorityChanged`,`configChanged`,`clockChanged`,`sessionEnded`];exports.BOARD_ADDRESS=e,exports.HOST_API_METHODS=r,exports.PLUGIN_API_METHODS=i,exports.SERVER_ADDRESS=t,exports.SETTINGS_ADDRESS=n;
package/dist/types.js CHANGED
@@ -1,28 +1,24 @@
1
1
  //#region src/types.ts
2
- var e = "board", t = "server", n = [
2
+ var e = "board", t = "server", n = "settings", r = [
3
3
  "hello",
4
4
  "ready",
5
5
  "send",
6
6
  "saveSnapshot",
7
7
  "recordAnswer",
8
- "saveProgress",
9
8
  "saveData",
10
9
  "updateSettings",
11
10
  "getAsset",
12
11
  "end",
13
- "resize",
14
12
  "reportError",
15
- "exit",
16
13
  "service"
17
- ], r = [
14
+ ], i = [
18
15
  "start",
19
16
  "deliver",
20
17
  "playersChanged",
21
18
  "authorityChanged",
22
- "setChanged",
23
19
  "configChanged",
24
20
  "clockChanged",
25
21
  "sessionEnded"
26
22
  ];
27
23
  //#endregion
28
- export { e as BOARD_ADDRESS, n as HOST_API_METHODS, r as PLUGIN_API_METHODS, t as SERVER_ADDRESS };
24
+ export { e as BOARD_ADDRESS, r as HOST_API_METHODS, i as PLUGIN_API_METHODS, t as SERVER_ADDRESS, n as SETTINGS_ADDRESS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memizy/protocol",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.7",
4
4
  "description": "Memizy Plugin Protocol: types, Zod schemas and helpers shared by @memizy/plugin-sdk and @memizy/host-sdk.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -12,21 +12,29 @@
12
12
  "types": "./dist/src/index.d.ts",
13
13
  "import": "./dist/index.js",
14
14
  "require": "./dist/index.cjs"
15
+ },
16
+ "./internal": {
17
+ "types": "./dist/src/internal.d.ts",
18
+ "import": "./dist/internal.js",
19
+ "require": "./dist/internal.cjs"
15
20
  }
16
21
  },
17
22
  "files": [
18
23
  "dist",
19
24
  "SPEC.md",
20
- "README.md"
25
+ "README.md",
26
+ "CHANGELOG.md",
27
+ "LICENSE"
21
28
  ],
22
29
  "scripts": {
23
- "build": "tsc --noEmit && vite build",
30
+ "build": "tsc --noEmit && vite build && node ../../scripts/dts-extensions.mjs dist",
24
31
  "test": "vitest run",
25
32
  "test:watch": "vitest",
26
- "typecheck": "tsc --noEmit"
33
+ "typecheck": "tsc --noEmit",
34
+ "prepublishOnly": "npm run build"
27
35
  },
28
36
  "dependencies": {
29
- "@memizy/oqse": "^1.0.0-rc.5",
37
+ "@memizy/oqse": "^1.0.0-rc.7",
30
38
  "zod": "^4.3.6"
31
39
  },
32
40
  "devDependencies": {