@superbuilders/primer-tives 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ bun add @superbuilders/primer-tives
19
19
 
20
20
  ## Version
21
21
 
22
- The current SDK version is `5.0.0`.
22
+ The current SDK version is `5.0.2`.
23
23
 
24
24
  ## Entrypoints
25
25
 
@@ -898,6 +898,8 @@ Fatal sentinels:
898
898
  | Sentinel | Meaning |
899
899
  | --- | --- |
900
900
  | `ErrBadRequest` | Primer rejected the runtime request as invalid for the SDK contract. |
901
+ | `ErrCurriculumInstructionalUndeliverable` | The active curriculum instructional has no deliverable frame content. |
902
+ | `ErrNoRoutableContent` | The catalog has no routable bootstrap content for the learner's scope. |
901
903
  | `ErrInvalidAccessToken` | The learner token was rejected. |
902
904
  | `ErrTokenExpired` | The learner token expired. |
903
905
  | `ErrForbidden` | The learner is not allowed to continue in this runtime scope. |
@@ -1275,18 +1277,23 @@ import {
1275
1277
  ErrAuthUnavailable,
1276
1278
  ErrBadRequest,
1277
1279
  ErrConflict,
1280
+ ErrCurriculumInstructionalUndeliverable,
1278
1281
  ErrForbidden,
1282
+ ErrFrameAlreadyAnswered,
1279
1283
  ErrInvalidAccessToken,
1280
1284
  ErrInvalidSubmission,
1281
1285
  ErrJsonParse,
1282
1286
  ErrMalformedAccessToken,
1283
1287
  ErrNetwork,
1288
+ ErrNoActiveFrame,
1289
+ ErrNoRoutableContent,
1284
1290
  ErrNotFound,
1285
1291
  ErrNotSerializable,
1286
1292
  ErrRateLimited,
1287
1293
  ErrSdkUpgradeRequired,
1288
1294
  ErrServerError,
1289
1295
  ErrServiceUnavailable,
1296
+ ErrSessionStateConflict,
1290
1297
  ErrTimeout,
1291
1298
  ErrTokenExpired,
1292
1299
  ErrUnsupportedPci
@@ -1319,9 +1326,14 @@ Runtime errors are represented as `ErroredState` or `FatalState`.
1319
1326
  | `ErrServiceUnavailable` | `ErroredState` | yes | Primer is temporarily unavailable. |
1320
1327
  | `ErrRateLimited` | `ErroredState` | yes | Runtime work is temporarily rate limited. |
1321
1328
  | `ErrConflict` | `ErroredState` | yes | The learner intent conflicts with another in-flight or current runtime action. |
1329
+ | `ErrNoActiveFrame` | `ResyncableErroredState` | no | Primer has no open frame for the submitted intent; call `resync()` to realign. |
1330
+ | `ErrFrameAlreadyAnswered` | `ResyncableErroredState` | no | The targeted frame was already answered; call `resync()` to realign. |
1331
+ | `ErrSessionStateConflict` | `ResyncableErroredState` | no | The learner intent does not match the active frame type; call `resync()` to realign. |
1322
1332
  | `ErrJsonParse` | `ErroredState` | yes | Runtime data could not be interpreted as the SDK contract. |
1323
1333
  | `ErrInvalidSubmission` | `ErroredState` | no | Renderer submitted a value that is invalid for the active interaction. |
1324
1334
  | `ErrBadRequest` | `FatalState` | no | Runtime request violates the SDK contract. |
1335
+ | `ErrCurriculumInstructionalUndeliverable` | `FatalState` | no | Curriculum routing reached an instructional with no deliverable frame content. |
1336
+ | `ErrNoRoutableContent` | `FatalState` | no | Catalog bootstrap has no routable content for the learner scope. |
1325
1337
  | `ErrInvalidAccessToken` | `FatalState` | no | Learner token is invalid. |
1326
1338
  | `ErrTokenExpired` | `FatalState` | no | Learner token expired. |
1327
1339
  | `ErrForbidden` | `FatalState` | no | Learner cannot continue in this runtime scope. |
@@ -1389,6 +1401,10 @@ if (state.phase === "fatal") {
1389
1401
  renderSdkUpgradeMessage()
1390
1402
  return
1391
1403
  }
1404
+ if (errors.is(state.error, ErrCurriculumInstructionalUndeliverable)) {
1405
+ renderContentUnavailableMessage()
1406
+ return
1407
+ }
1392
1408
  logger.error({ error: state.error }, "primer fatal state")
1393
1409
  throw state.error
1394
1410
  }
@@ -1462,6 +1478,7 @@ The runtime exchange shape is not public SDK surface. Tests should assert SDK se
1462
1478
  | first runtime work fails recoverably | `start` resolves to `ErroredState` with `retriable: true` |
1463
1479
  | first runtime work fails terminally | `start` resolves to `FatalState` |
1464
1480
  | unsupported PCI is presented | `start` resolves to `FatalState` with `ErrUnsupportedPci` |
1481
+ | curriculum instructional has no deliverable content | transition resolves to `FatalState` with `ErrCurriculumInstructionalUndeliverable` |
1465
1482
  | standard submission is invalid | submit method resolves to `ErroredState` with `ErrInvalidSubmission` |
1466
1483
  | concurrent submit/timeout conflict occurs | transition resolves to `ErroredState` with `ErrConflict` |
1467
1484
  | state is serialized | serialization throws `ErrNotSerializable` |
@@ -1,4 +1,4 @@
1
1
  export type { PrimerOptions, PrimerOptionsWithAccessToken, PrimerOptionsWithManagedAuth } from "./start";
2
2
  export { start } from "./start";
3
- export type { AccessTokenStartState, AssessmentOutcome, AssessmentOutcomeValue, AuthConfigInvalidState, AuthUnavailableState, ChoiceState, CompletedState, ErroredState, ExtendedTextMultipleState, ExtendedTextSingleState, ExtendedTextState, FatalState, FeedbackKind, FeedbackState, InteractionFeedback, InteractionState, ManagedStartState, MatchState, NonRetriableErroredState, NonSerializable, ObservationState, OrderState, PciInteractionState, PciPendingRenderProps, PciRenderProps, PciSubmittedRenderProps, PrimerState, RetriableErroredState, RuntimeState, SignInFailedState, SignInRequiredState, SubmittedFeedbackState, TextEntryState, TimedOutFeedbackState } from "./types";
3
+ export type { AccessTokenStartState, AssessmentOutcome, AssessmentOutcomeValue, AuthConfigInvalidState, AuthUnavailableState, ChoiceState, CompletedState, ErroredState, ExtendedTextMultipleState, ExtendedTextSingleState, ExtendedTextState, FatalState, FeedbackKind, FeedbackState, InteractionFeedback, InteractionState, ManagedStartState, MatchState, NonRetriableErroredState, NonSerializable, ObservationState, OrderState, PciInteractionState, PciPendingRenderProps, PciRenderProps, PciSubmittedRenderProps, PrimerState, ResyncableErroredState, RetriableErroredState, RuntimeState, SignInFailedState, SignInRequiredState, SubmittedFeedbackState, TextEntryState, TimedOutFeedbackState } from "./types";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,aAAa,EACb,4BAA4B,EAC5B,4BAA4B,EAC5B,MAAM,0CAA0C,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,0CAA0C,CAAA;AAEhE,YAAY,EACX,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,MAAM,0CAA0C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,aAAa,EACb,4BAA4B,EAC5B,4BAA4B,EAC5B,MAAM,0CAA0C,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,0CAA0C,CAAA;AAEhE,YAAY,EACX,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,MAAM,0CAA0C,CAAA"}
@@ -6279,6 +6279,11 @@ var ErrAuthStateMismatch = errors.new("auth state mismatch");
6279
6279
  var ErrAuthPopupBlocked = errors.new("auth popup blocked");
6280
6280
  var ErrAuthCancelled = errors.new("auth cancelled");
6281
6281
  var ErrSdkUpgradeRequired = errors.new("sdk upgrade required");
6282
+ var ErrCurriculumInstructionalUndeliverable = errors.new("curriculum instructional undeliverable");
6283
+ var ErrNoRoutableContent = errors.new("no routable content");
6284
+ var ErrNoActiveFrame = errors.new("no active frame");
6285
+ var ErrFrameAlreadyAnswered = errors.new("frame already answered");
6286
+ var ErrSessionStateConflict = errors.new("session state conflict");
6282
6287
  // src/contracts/content.ts
6283
6288
  function inlinesToPlainText(nodes) {
6284
6289
  const parts = [];
@@ -7751,13 +7756,24 @@ function textEntryState(ctx, body, stimulus, interaction, feedback) {
7751
7756
  // src/client/session.ts
7752
7757
  var FATAL_SENTINELS = [
7753
7758
  ErrBadRequest,
7759
+ ErrCurriculumInstructionalUndeliverable,
7754
7760
  ErrInvalidAccessToken,
7755
7761
  ErrTokenExpired,
7756
7762
  ErrForbidden,
7757
7763
  ErrNotFound,
7764
+ ErrNoRoutableContent,
7758
7765
  ErrSdkUpgradeRequired,
7759
7766
  ErrUnsupportedPci
7760
7767
  ];
7768
+ var SESSION_SYNC_SENTINELS = [ErrNoActiveFrame, ErrFrameAlreadyAnswered, ErrSessionStateConflict];
7769
+ function isSessionSyncError(err) {
7770
+ for (const sentinel of SESSION_SYNC_SENTINELS) {
7771
+ if (errors11.is(err, sentinel)) {
7772
+ return true;
7773
+ }
7774
+ }
7775
+ return false;
7776
+ }
7761
7777
  function isFatalError(err) {
7762
7778
  for (const sentinel of FATAL_SENTINELS) {
7763
7779
  if (errors11.is(err, sentinel)) {
@@ -7767,7 +7783,13 @@ function isFatalError(err) {
7767
7783
  return false;
7768
7784
  }
7769
7785
  function isRetriableError(err) {
7770
- return !errors11.is(err, ErrInvalidSubmission);
7786
+ if (errors11.is(err, ErrInvalidSubmission)) {
7787
+ return false;
7788
+ }
7789
+ if (isSessionSyncError(err)) {
7790
+ return false;
7791
+ }
7792
+ return true;
7771
7793
  }
7772
7794
  function makeSession(sc) {
7773
7795
  const logger = sc.logger;
@@ -7813,7 +7835,23 @@ function makeSession(sc) {
7813
7835
  }
7814
7836
  }
7815
7837
  function errored(error, failedPhase, intent) {
7816
- let pending;
7838
+ if (isSessionSyncError(error)) {
7839
+ let pending2;
7840
+ return {
7841
+ phase: "errored",
7842
+ error,
7843
+ retriable: false,
7844
+ resync: function resync() {
7845
+ if (pending2) {
7846
+ return pending2;
7847
+ }
7848
+ logger.debug({ failedPhase }, "resyncing session from errored state");
7849
+ pending2 = execute({ kind: "observation" }, "observation");
7850
+ return pending2;
7851
+ },
7852
+ toJSON: poisonToJSON
7853
+ };
7854
+ }
7817
7855
  const retriable = isRetriableError(error);
7818
7856
  if (!retriable) {
7819
7857
  return {
@@ -7823,6 +7861,7 @@ function makeSession(sc) {
7823
7861
  toJSON: poisonToJSON
7824
7862
  };
7825
7863
  }
7864
+ let pending;
7826
7865
  const state = {
7827
7866
  phase: "errored",
7828
7867
  error,
@@ -7946,7 +7985,7 @@ function makeSession(sc) {
7946
7985
  import * as errors12 from "@superbuilders/errors";
7947
7986
 
7948
7987
  // src/version.ts
7949
- var SDK_VERSION = "5.0.0";
7988
+ var SDK_VERSION = "5.0.2";
7950
7989
  var NPM_PACKAGE_URL = "https://www.npmjs.com/package/@superbuilders/primer-tives";
7951
7990
 
7952
7991
  // src/client/transport.ts
@@ -7998,37 +8037,61 @@ function parseAdvanceErrorBody(body) {
7998
8037
  }
7999
8038
  return result;
8000
8039
  }
8001
- function httpSentinel(status, body) {
8002
- if (status === 400) {
8003
- const parsed = parseAdvanceErrorBody(body);
8004
- if (parsed?.error === "sdk_upgrade_required") {
8005
- return ErrSdkUpgradeRequired;
8006
- }
8007
- return ErrBadRequest;
8008
- }
8009
- if (status === 401) {
8010
- const parsed = parseAdvanceErrorBody(body);
8011
- if (parsed?.detail === "token_expired") {
8012
- return ErrTokenExpired;
8040
+ var ADVANCE_400_ERRORS = {
8041
+ sdk_upgrade_required: ErrSdkUpgradeRequired,
8042
+ curriculum_instructional_undeliverable: ErrCurriculumInstructionalUndeliverable,
8043
+ no_routable_content: ErrNoRoutableContent
8044
+ };
8045
+ var ADVANCE_409_ERRORS = {
8046
+ no_active_frame: ErrNoActiveFrame,
8047
+ frame_already_answered: ErrFrameAlreadyAnswered,
8048
+ session_state_conflict: ErrSessionStateConflict
8049
+ };
8050
+ function advanceErrorSentinel(errorCode, mapping, fallback) {
8051
+ if (errorCode !== undefined) {
8052
+ const sentinel = mapping[errorCode];
8053
+ if (sentinel !== undefined) {
8054
+ return sentinel;
8013
8055
  }
8014
- return ErrInvalidAccessToken;
8015
8056
  }
8016
- if (status === 403) {
8017
- return ErrForbidden;
8018
- }
8019
- if (status === 404) {
8020
- return ErrNotFound;
8021
- }
8022
- if (status === 409) {
8023
- return ErrConflict;
8024
- }
8025
- if (status === 429) {
8026
- return ErrRateLimited;
8057
+ return fallback;
8058
+ }
8059
+ function badRequestSentinel(body) {
8060
+ const parsed = parseAdvanceErrorBody(body);
8061
+ return advanceErrorSentinel(parsed?.error, ADVANCE_400_ERRORS, ErrBadRequest);
8062
+ }
8063
+ function unauthorizedSentinel(body) {
8064
+ const parsed = parseAdvanceErrorBody(body);
8065
+ if (parsed?.detail === "token_expired") {
8066
+ return ErrTokenExpired;
8027
8067
  }
8028
- if (status === 502 || status === 503 || status === 504) {
8029
- return ErrServiceUnavailable;
8068
+ return ErrInvalidAccessToken;
8069
+ }
8070
+ function conflictSentinel(body) {
8071
+ const parsed = parseAdvanceErrorBody(body);
8072
+ return advanceErrorSentinel(parsed?.error, ADVANCE_409_ERRORS, ErrConflict);
8073
+ }
8074
+ function httpSentinel(status, body) {
8075
+ switch (status) {
8076
+ case 400:
8077
+ return badRequestSentinel(body);
8078
+ case 401:
8079
+ return unauthorizedSentinel(body);
8080
+ case 403:
8081
+ return ErrForbidden;
8082
+ case 404:
8083
+ return ErrNotFound;
8084
+ case 409:
8085
+ return conflictSentinel(body);
8086
+ case 429:
8087
+ return ErrRateLimited;
8088
+ case 502:
8089
+ case 503:
8090
+ case 504:
8091
+ return ErrServiceUnavailable;
8092
+ default:
8093
+ return ErrServerError;
8030
8094
  }
8031
- return ErrServerError;
8032
8095
  }
8033
8096
  function buildSdkUpgradeRequiredError(sentinel, text, logger) {
8034
8097
  const parsed = parseAdvanceErrorBody(text);
@@ -8269,4 +8332,4 @@ export {
8269
8332
  start
8270
8333
  };
8271
8334
 
8272
- //# debugId=9849F045A465657964756E2164756E21
8335
+ //# debugId=437ED91D306035DE64756E2164756E21