@superbuilders/primer-tives 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +15 -6
  2. package/dist/client/choice-state.d.ts +2 -1
  3. package/dist/client/choice-state.d.ts.map +1 -1
  4. package/dist/client/create.d.ts +1 -1
  5. package/dist/client/create.d.ts.map +1 -1
  6. package/dist/client/extended-text-state.d.ts +2 -1
  7. package/dist/client/extended-text-state.d.ts.map +1 -1
  8. package/dist/client/feedback-state.d.ts +2 -2
  9. package/dist/client/feedback-state.d.ts.map +1 -1
  10. package/dist/client/index.js +140 -61
  11. package/dist/client/index.js.map +16 -15
  12. package/dist/client/match-state.d.ts +2 -1
  13. package/dist/client/match-state.d.ts.map +1 -1
  14. package/dist/client/observation-state.d.ts +2 -1
  15. package/dist/client/observation-state.d.ts.map +1 -1
  16. package/dist/client/order-state.d.ts +2 -1
  17. package/dist/client/order-state.d.ts.map +1 -1
  18. package/dist/client/pci-state.d.ts +2 -1
  19. package/dist/client/pci-state.d.ts.map +1 -1
  20. package/dist/client/session-context.d.ts +1 -1
  21. package/dist/client/session-context.d.ts.map +1 -1
  22. package/dist/client/session.d.ts +1 -1
  23. package/dist/client/session.d.ts.map +1 -1
  24. package/dist/client/text-entry-state.d.ts +2 -1
  25. package/dist/client/text-entry-state.d.ts.map +1 -1
  26. package/dist/client/transport.d.ts +9 -6
  27. package/dist/client/transport.d.ts.map +1 -1
  28. package/dist/client/types.d.ts +10 -1
  29. package/dist/client/types.d.ts.map +1 -1
  30. package/dist/contracts/index.d.ts +1 -1
  31. package/dist/contracts/index.d.ts.map +1 -1
  32. package/dist/contracts/types.d.ts +5 -9
  33. package/dist/contracts/types.d.ts.map +1 -1
  34. package/dist/errors.d.ts +2 -1
  35. package/dist/errors.d.ts.map +1 -1
  36. package/dist/errors.js +3 -1
  37. package/dist/errors.js.map +3 -3
  38. package/dist/server/index.js +2 -1
  39. package/dist/server/index.js.map +3 -3
  40. package/dist/version.d.ts +4 -0
  41. package/dist/version.d.ts.map +1 -0
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -155,6 +155,7 @@ const { studentId, accessToken, expiresInSeconds } = sessionResult.data
155
155
  ```ts
156
156
  import { create } from "@superbuilders/primer-tives/client"
157
157
  import type { PrimerState } from "@superbuilders/primer-tives/client"
158
+ import * as logger from "@superbuilders/slog"
158
159
 
159
160
  const client = create({
160
161
  accessToken,
@@ -163,7 +164,8 @@ const client = create({
163
164
  supportedPcis: [
164
165
  "urn:primer:pci:division-remainder",
165
166
  "urn:primer:pci:fraction-addition"
166
- ]
167
+ ],
168
+ logger
167
169
  })
168
170
 
169
171
  let state: PrimerState = await client.start()
@@ -171,7 +173,7 @@ let state: PrimerState = await client.start()
171
173
  while (state.phase !== "completed" && state.phase !== "fatal") {
172
174
  switch (state.phase) {
173
175
  case "observation":
174
- renderStimulus(state.stimulus)
176
+ renderFrame(state.body, state.stimulus)
175
177
  state = await state.advance()
176
178
  break
177
179
  case "interaction":
@@ -345,7 +347,7 @@ interface Config<Pcis extends PciId = PciId> {
345
347
  readonly subject: SubjectScope
346
348
  readonly fetch?: typeof globalThis.fetch
347
349
  readonly abort?: AbortController
348
- readonly logger?: PrimerLogger
350
+ readonly logger: PrimerLogger
349
351
  }
350
352
 
351
353
  interface Client<Pcis extends PciId = PciId> {
@@ -390,6 +392,7 @@ Every `InteractionState` shape also exposes `timeout(): Promise<PrimerState>`.
390
392
  ```ts
391
393
  interface FeedbackState extends NonSerializable {
392
394
  readonly phase: "feedback"
395
+ readonly body: ContentBlock[]
393
396
  readonly stimulus: RendererStimulus | null
394
397
  readonly interaction: RendererInteraction
395
398
  readonly submission: RendererSubmission
@@ -400,7 +403,13 @@ interface FeedbackState extends NonSerializable {
400
403
  }
401
404
  ```
402
405
 
403
- `RendererStimulus`, `RendererInteraction`, `RendererSubmission`, `ContentInline`, `InteractionReview` all come from `/contracts`.
406
+ Every state that carries frame content (`ObservationState`, every `InteractionState` variant, `FeedbackState`) exposes the frame as three independent fields:
407
+
408
+ - `body: ContentBlock[]` — the frame's prose, possibly empty.
409
+ - `stimulus: RendererStimulus | null` — a discriminated union over media kinds (currently `{ kind: "image", alt, src }`).
410
+ - `interaction: RendererInteraction | null` — the question, when present.
411
+
412
+ `RendererStimulus`, `RendererInteraction`, `RendererSubmission`, `ContentBlock`, `ContentInline`, `InteractionReview` all come from `/contracts`.
404
413
 
405
414
  ### `ErroredState`
406
415
 
@@ -487,7 +496,6 @@ import type {
487
496
  PciSubmission,
488
497
  // stimulus shapes
489
498
  RendererStimulus,
490
- BodyStimulus,
491
499
  ImageStimulus,
492
500
  // choice shapes
493
501
  RendererChoice,
@@ -654,6 +662,7 @@ import {
654
662
  | `ErrForbidden` | HTTP 403 |
655
663
  | `ErrNotFound` | HTTP 404 |
656
664
  | `ErrNeedsHints` | HTTP 412 — the student has no `gradeLevel` on record; backend must call `setStudentHints` and mint a fresh access token |
665
+ | `ErrSdkUpgradeRequired` | the SDK's version is older than the server's minimum-supported version; bump `@superbuilders/primer-tives` to the latest |
657
666
  | `ErrUnsupportedPci` | HTTP 422 or a frame asks for a PCI not in `supportedPcis` |
658
667
 
659
668
  ## Thrown directly by `create()`
@@ -714,7 +723,7 @@ interface PrimerLogger {
714
723
  }
715
724
  ```
716
725
 
717
- Required by `PrimerServerConfig`, optional on `Config` (the client config). `@superbuilders/slog` matches this shape directly — `import * as logger from "@superbuilders/slog"` and pass `logger`.
726
+ Required by both `PrimerServerConfig` and `Config` (the client config). The SDK never silently swallows operational events — every fatal, parse failure, transport error, and submission rejection goes through this logger. `@superbuilders/slog` matches this shape directly — `import * as logger from "@superbuilders/slog"` and pass `logger`.
718
727
 
719
728
  ---
720
729
 
@@ -1,8 +1,9 @@
1
+ import type { ContentBlock } from "../contracts/content";
1
2
  import type { SessionContext } from "./session-context";
2
3
  import type { PciId } from "../contracts/pci";
3
4
  import type { RendererChoice, RendererInteraction, RendererStimulus } from "../contracts/types";
4
5
  import type { PrimerState } from "./types";
5
- declare function choiceState<Pcis extends PciId>(ctx: SessionContext<Pcis>, stimulus: RendererStimulus | null, interaction: Extract<RendererInteraction<Pcis>, {
6
+ declare function choiceState<Pcis extends PciId>(ctx: SessionContext<Pcis>, body: ContentBlock[], stimulus: RendererStimulus | null, interaction: Extract<RendererInteraction<Pcis>, {
6
7
  type: "choice";
7
8
  }>, options: RendererChoice[], maxChoices: number, minChoices: number): PrimerState<Pcis>;
8
9
  export { choiceState };
@@ -1 +1 @@
1
- {"version":3,"file":"choice-state.d.ts","sourceRoot":"","sources":["../../src/client/choice-state.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAA;AACtE,OAAO,KAAK,EACX,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAG3E,iBAAS,WAAW,CAAC,IAAI,SAAS,KAAK,EACtC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,EACzB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,WAAW,EAAE,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,EACnE,OAAO,EAAE,cAAc,EAAE,EACzB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GAChB,WAAW,CAAC,IAAI,CAAC,CAqFnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
1
+ {"version":3,"file":"choice-state.d.ts","sourceRoot":"","sources":["../../src/client/choice-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAOjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAA;AACtE,OAAO,KAAK,EACX,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAG3E,iBAAS,WAAW,CAAC,IAAI,SAAS,KAAK,EACtC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,EACzB,IAAI,EAAE,YAAY,EAAE,EACpB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,WAAW,EAAE,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,EACnE,OAAO,EAAE,cAAc,EAAE,EACzB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GAChB,WAAW,CAAC,IAAI,CAAC,CAsFnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -9,7 +9,7 @@ interface Config<Pcis extends PciId = PciId> {
9
9
  readonly subject: SubjectScope;
10
10
  readonly fetch?: typeof globalThis.fetch;
11
11
  readonly abort?: AbortController;
12
- readonly logger?: PrimerLogger;
12
+ readonly logger: PrimerLogger;
13
13
  }
14
14
  interface Client<Pcis extends PciId = PciId> {
15
15
  start(): Promise<PrimerState<Pcis>>;
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/client/create.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAA;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAM3E,UAAU,MAAM,CAAC,IAAI,SAAS,KAAK,GAAG,KAAK;IAC1C,QAAQ,C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IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAA;IAChC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAC7B;AAED,UAAU,MAAM,CAAC,IAAI,SAAS,KAAK,GAAG,KAAK;IAC1C,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;CACnC;AAUD,iBAAS,MAAM,CAAC,KAAK,CAAC,IAAI,SAAS,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CA2C5E;AAED,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA"}
@@ -1,8 +1,9 @@
1
+ import type { ContentBlock } from "../contracts/content";
1
2
  import type { SessionContext } from "./session-context";
2
3
  import type { PciId } from "../contracts/pci";
3
4
  import type { RendererStimulus, StandardRendererInteraction } from "../contracts/types";
4
5
  import type { PrimerState } from "./types";
5
- declare function extendedTextState<Pcis extends PciId>(ctx: SessionContext<Pcis>, stimulus: RendererStimulus | null, interaction: Extract<StandardRendererInteraction, {
6
+ declare function extendedTextState<Pcis extends PciId>(ctx: SessionContext<Pcis>, body: ContentBlock[], stimulus: RendererStimulus | null, interaction: Extract<StandardRendererInteraction, {
6
7
  type: "extended-text";
7
8
  }>): PrimerState<Pcis>;
8
9
  export { extendedTextState };
@@ -1 +1 @@
1
- {"version":3,"file":"extended-text-state.d.ts","sourceRoot":"","sources":["../../src/client/extended-text-state.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAA;AACtE,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAG3E,iBAAS,iBAAiB,CAAC,IAAI,SAAS,KAAK,EAC5C,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,EACzB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,WAAW,EAAE,OAAO,CAAC,2BAA2B,EAAE;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC,GAC1E,WAAW,CAAC,IAAI,CAAC,CAqKnB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
1
+ {"version":3,"file":"extended-text-state.d.ts","sourceRoot":"","sources":["../../src/client/extended-text-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAOjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAA;AACtE,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAG3E,iBAAS,iBAAiB,CAAC,IAAI,SAAS,KAAK,EAC5C,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,EACzB,IAAI,EAAE,YAAY,EAAE,EACpB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,WAAW,EAAE,OAAO,CAAC,2BAA2B,EAAE;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC,GAC1E,WAAW,CAAC,IAAI,CAAC,CAuKnB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
@@ -1,9 +1,9 @@
1
- import type { ContentInline } from "../contracts/content";
1
+ import type { ContentBlock, ContentInline } from "../contracts/content";
2
2
  import type { SessionContext } from "./session-context";
3
3
  import type { PciId } from "../contracts/pci";
4
4
  import type { RendererInteraction, RendererStimulus, RendererSubmission } from "../contracts/types";
5
5
  import type { InteractionReview } from "../contracts/review";
6
6
  import type { PrimerState } from "./types";
7
- declare function feedbackState<Pcis extends PciId>(ctx: SessionContext<Pcis>, stimulus: RendererStimulus | null, interaction: RendererInteraction<Pcis>, submission: RendererSubmission<Pcis>, isCorrect: boolean, feedbackContent: ContentInline[], review: InteractionReview<Pcis> | null): PrimerState<Pcis>;
7
+ declare function feedbackState<Pcis extends PciId>(ctx: SessionContext<Pcis>, body: ContentBlock[], stimulus: RendererStimulus | null, interaction: RendererInteraction<Pcis>, submission: RendererSubmission<Pcis>, isCorrect: boolean, feedbackContent: ContentInline[], review: InteractionReview<Pcis> | null): PrimerState<Pcis>;
8
8
  export { feedbackState };
9
9
  //# sourceMappingURL=feedback-state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"feedback-state.d.ts","sourceRoot":"","sources":["../../src/client/feedback-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAA;AACtE,OAAO,KAAK,EACX,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAA;AAE3E,iBAAS,aAAa,CAAC,IAAI,SAAS,KAAK,EACxC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,EACzB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,WAAW,EAAE,mBAAmB,CAAC,IAAI,CAAC,EACtC,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC,EACpC,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,aAAa,EAAE,EAChC,MAAM,EAAE,iBAAiB,CAAC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