@opengeni/sdk 1.0.1 → 2.2.0-canary.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 (92) hide show
  1. package/README.md +117 -2
  2. package/dist/artifacts.js +5 -5
  3. package/dist/automations-client.d.ts +17 -0
  4. package/dist/automations.d.ts +3 -0
  5. package/dist/automations.js +78 -0
  6. package/dist/automations.js.map +1 -0
  7. package/dist/{chunk-A5DC5WEM.js → chunk-C2H7HBNP.js} +22 -2
  8. package/dist/chunk-C2H7HBNP.js.map +1 -0
  9. package/dist/{chunk-GU6JF75T.js → chunk-C4DJPZRU.js} +1 -1
  10. package/dist/{chunk-GU6JF75T.js.map → chunk-C4DJPZRU.js.map} +1 -1
  11. package/dist/{chunk-TYZ4JL4J.js → chunk-G6LBVWKT.js} +2 -2
  12. package/dist/{chunk-4DV37UUA.js → chunk-GLDV5QY7.js} +16 -2
  13. package/dist/chunk-GLDV5QY7.js.map +1 -0
  14. package/dist/{chunk-ST5DDKJP.js → chunk-GW3EJ2GP.js} +52 -1
  15. package/dist/chunk-GW3EJ2GP.js.map +1 -0
  16. package/dist/{chunk-VWE2QIVO.js → chunk-XNG7YGR3.js} +23 -6
  17. package/dist/chunk-XNG7YGR3.js.map +1 -0
  18. package/dist/{chunk-YGH5P47G.js → chunk-YBQTKNTL.js} +696 -57
  19. package/dist/chunk-YBQTKNTL.js.map +1 -0
  20. package/dist/client.d.ts +151 -26
  21. package/dist/codex-realtime-controller.d.ts +1 -0
  22. package/dist/codex-realtime-controller.js +2 -2
  23. package/dist/company-brain.d.ts +32 -0
  24. package/dist/company-profile.d.ts +1 -1
  25. package/dist/core.js +4 -4
  26. package/dist/editable-artifacts/browser-session.d.ts +7 -3
  27. package/dist/editable-artifacts/controller.d.ts +4 -1
  28. package/dist/editable-artifacts/errors.d.ts +1 -1
  29. package/dist/editable-artifacts/http-live-transport.d.ts +6 -2
  30. package/dist/editable-artifacts/index.d.ts +2 -0
  31. package/dist/editable-artifacts/open-failure.d.ts +9 -0
  32. package/dist/editable-artifacts/types.d.ts +4 -3
  33. package/dist/editable-artifacts/worker/kernel-adapter.d.ts +1 -1
  34. package/dist/editable-artifacts-worker.js +44 -17
  35. package/dist/editable-artifacts-worker.js.map +1 -1
  36. package/dist/editable-artifacts.js +222 -119
  37. package/dist/editable-artifacts.js.map +1 -1
  38. package/dist/errors.d.ts +1 -1
  39. package/dist/index.d.ts +7 -4
  40. package/dist/index.js +61 -12
  41. package/dist/index.js.map +1 -1
  42. package/dist/interaction.d.ts +23 -0
  43. package/dist/interaction.js +4 -1
  44. package/dist/organization-private-session-settings.d.ts +6 -0
  45. package/dist/organization-private-session-settings.js +22 -0
  46. package/dist/organization-private-session-settings.js.map +1 -0
  47. package/dist/pr-review-client.d.ts +15 -0
  48. package/dist/pr-review.d.ts +4 -0
  49. package/dist/pr-review.js +56 -0
  50. package/dist/pr-review.js.map +1 -0
  51. package/dist/preference-registry.d.ts +8 -0
  52. package/dist/realtime.js +2 -2
  53. package/dist/retained-artifacts.d.ts +5 -1
  54. package/dist/types.d.ts +961 -13
  55. package/dist/workspace-instruction-policies.d.ts +22 -0
  56. package/dist/workspace-learning.d.ts +124 -0
  57. package/package.json +14 -2
  58. package/src/automations-client.ts +118 -0
  59. package/src/automations.ts +15 -0
  60. package/src/client.ts +974 -71
  61. package/src/codex-realtime-controller.ts +21 -0
  62. package/src/company-brain.ts +99 -0
  63. package/src/company-profile.ts +4 -1
  64. package/src/editable-artifacts/browser-session.ts +36 -22
  65. package/src/editable-artifacts/controller.ts +66 -45
  66. package/src/editable-artifacts/errors.ts +2 -0
  67. package/src/editable-artifacts/http-live-transport.ts +62 -37
  68. package/src/editable-artifacts/index.ts +6 -0
  69. package/src/editable-artifacts/open-failure.ts +79 -0
  70. package/src/editable-artifacts/storage.ts +31 -40
  71. package/src/editable-artifacts/types.ts +4 -3
  72. package/src/editable-artifacts/worker/kernel-adapter.ts +23 -7
  73. package/src/editable-artifacts/worker/runtime.ts +26 -13
  74. package/src/editable-artifacts/worker/wire-codec.ts +23 -5
  75. package/src/errors.ts +1 -1
  76. package/src/index.ts +131 -0
  77. package/src/interaction.ts +95 -0
  78. package/src/organization-private-session-settings.ts +33 -0
  79. package/src/pr-review-client.ts +84 -0
  80. package/src/pr-review.ts +15 -0
  81. package/src/preference-registry.ts +9 -0
  82. package/src/retained-artifacts.ts +101 -0
  83. package/src/stream.ts +13 -2
  84. package/src/types.ts +1101 -12
  85. package/src/workspace-instruction-policies.ts +24 -0
  86. package/src/workspace-learning.ts +138 -0
  87. package/dist/chunk-4DV37UUA.js.map +0 -1
  88. package/dist/chunk-A5DC5WEM.js.map +0 -1
  89. package/dist/chunk-ST5DDKJP.js.map +0 -1
  90. package/dist/chunk-VWE2QIVO.js.map +0 -1
  91. package/dist/chunk-YGH5P47G.js.map +0 -1
  92. /package/dist/{chunk-TYZ4JL4J.js.map → chunk-G6LBVWKT.js.map} +0 -0
@@ -2,7 +2,7 @@ import type { ArtifactWorkerInitializeInput } from "./wire-codec.js";
2
2
  import type { EditableArtifactModality } from "../types.js";
3
3
  export type ArtifactWorkerKernelSession = {
4
4
  readonly modality: EditableArtifactModality;
5
- /** Replays one exact whole canonical OGACO001 transaction. */
5
+ /** Replays one exact whole canonical OGACO002 transaction. */
6
6
  applyCommitted: (committedTransactionBytes: Uint8Array) => void;
7
7
  /** Authors and applies one exact OGATX001 intent over the current frontier. */
8
8
  applyPending: (intentBytes: Uint8Array) => void;
@@ -15,7 +15,7 @@ import {
15
15
  requireMatchingHash,
16
16
  sha256Hex,
17
17
  transferListForArtifactWorkerRpcMessage
18
- } from "./chunk-VWE2QIVO.js";
18
+ } from "./chunk-XNG7YGR3.js";
19
19
 
20
20
  // src/editable-artifacts/worker/kernel-adapter.ts
21
21
  import {
@@ -23,9 +23,18 @@ import {
23
23
  EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
24
24
  EDITABLE_ARTIFACT_INTENT_VERSION,
25
25
  EDITABLE_ARTIFACT_PRODUCT_MAX_SNAPSHOT_BYTES,
26
- SPREADSHEET_ARTIFACT_COMMAND_VERSION
26
+ SPREADSHEET_ARTIFACT_COMMAND_VERSION,
27
+ SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION
27
28
  } from "@opengeni/contracts/editable-artifacts";
28
- import { MAX_COMMITTED_TRANSACTION_BYTES } from "@opengeni/contracts/editable-artifact-committed-transaction";
29
+ import {
30
+ SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION,
31
+ SPREADSHEET_KERNEL_COMMAND_VERSION,
32
+ SPREADSHEET_KERNEL_SNAPSHOT_VERSION
33
+ } from "@opengeni/contracts/editable-artifact-versions";
34
+ import {
35
+ COMMITTED_TRANSACTION_PROTOCOL_VERSION,
36
+ MAX_COMMITTED_TRANSACTION_BYTES
37
+ } from "@opengeni/contracts/editable-artifact-committed-transaction";
29
38
  var ArtifactWorkerPendingProjectionError = class extends Error {
30
39
  code;
31
40
  constructor(code, message = "pending transaction cannot project over confirmed state") {
@@ -391,6 +400,7 @@ function decodeCapabilities(bytes) {
391
400
  "safeRust",
392
401
  "sessionForks",
393
402
  "spreadsheetCommandVersion",
403
+ "spreadsheetModelSchemaVersion",
394
404
  "statefulSessions",
395
405
  "textLayout",
396
406
  "textLayoutFontBundleVersion",
@@ -446,6 +456,10 @@ function decodeCapabilities(bytes) {
446
456
  value.spreadsheetCommandVersion,
447
457
  "spreadsheetCommandVersion"
448
458
  ),
459
+ spreadsheetModelSchemaVersion: positiveInteger(
460
+ value.spreadsheetModelSchemaVersion,
461
+ "spreadsheetModelSchemaVersion"
462
+ ),
449
463
  maxCellsPerBatch: positiveInteger(value.maxCellsPerBatch, "maxCellsPerBatch"),
450
464
  maxCommands: positiveInteger(value.maxCommands, "maxCommands"),
451
465
  maxSnapshotBytes: positiveInteger(value.maxSnapshotBytes, "maxSnapshotBytes"),
@@ -568,7 +582,7 @@ function decodeCapabilities(bytes) {
568
582
  "workbookMetadataQueries"
569
583
  )
570
584
  };
571
- if (normalized.abiVersion !== 1 || normalized.buildIdentityFormat !== "utf8" || normalized.canonicalStateHash !== "sha256:canonical-snapshot" || normalized.editableArtifactIntentVersion !== EDITABLE_ARTIFACT_INTENT_VERSION || normalized.spreadsheetCommandVersion !== SPREADSHEET_ARTIFACT_COMMAND_VERSION || normalized.collaborationSnapshotVersion !== 1 || normalized.commandSchemaVersion !== 1 || normalized.committedTransactionVersion !== 1 || normalized.documentCommandVersion !== 1 || normalized.documentQueryResponseVersion !== 1 || normalized.documentQueryVersion !== 1 || normalized.documentReceiptVersion !== 1 || normalized.documentSnapshotVersion !== 1 || normalized.documentStatefulSessions !== normalized.document || normalized.kernelSnapshotVersion !== 1 || normalized.maxCellsPerBatch !== WASM_MAX_CELLS_PER_BATCH || normalized.maxCommandBytes !== WASM_MAX_COMMAND_BYTES || normalized.maxSpreadsheetCommandBytes !== EDITABLE_ARTIFACT_COMMAND_MAX_BYTES || normalized.maxCommands !== 1e4 || normalized.maxIntentBytes !== EDITABLE_ARTIFACT_INTENT_MAX_BYTES || normalized.maxCommittedTransactionBytes !== MAX_COMMITTED_TRANSACTION_BYTES || normalized.maxDocumentCommandBytes !== WASM_MAX_COMMAND_BYTES || normalized.maxDocumentCommands !== 4096 || normalized.maxDocumentQueryBytes !== 256 || normalized.maxDocumentQueryResponseBytes !== 8 * 1024 * 1024 || normalized.maxDocumentSnapshotBytes !== WASM_MAX_SNAPSHOT_BYTES || normalized.maxMetadataScannedCells !== 4e6 || normalized.maxQueryBytes !== 68 || normalized.maxQueryResponseBytes !== 8 * 1024 * 1024 || normalized.maxViewportArea !== 1048576 || normalized.maxViewportCells !== 262144 || normalized.maxMetadataSheets !== 1e4 || normalized.maxPresentationCommandBytes !== 4 * 1024 * 1024 || normalized.maxPresentationQueryBytes !== 96 || normalized.maxPresentationResponseBytes !== 8 * 1024 * 1024 || normalized.maxPresentationSnapshotBytes !== WASM_MAX_SNAPSHOT_BYTES || normalized.maxTextLayoutFontBundleBytes !== 48 * 1024 * 1024 || normalized.maxTextLayoutRequestBytes !== 4 * 1024 * 1024 || normalized.maxTextLayoutResponseBytes !== 32 * 1024 * 1024 || normalized.maxSnapshotBytes !== WASM_MAX_SNAPSHOT_BYTES || normalized.queryResponseVersion !== 1 || normalized.queryVersion !== 1 || normalized.receiptSchemaVersion !== 1 || normalized.retainedRenderPatchVersion !== 1 || normalized.retainedRenderTileVersion !== 1 || normalized.presentationCommandVersion !== 1 || normalized.presentationQueryResponseVersion !== 1 || normalized.presentationQueryVersion !== 1 || normalized.presentationSnapshotVersion !== 1 || normalized.presentationStatefulSessions !== normalized.presentation || normalized.safeRust !== true || normalized.statefulSessions !== true || normalized.textLayoutFontBundleVersion !== 1 || normalized.textLayoutRequestVersion !== 1 || normalized.textLayoutResponseVersion !== 1 || normalized.textLayoutStatefulSessions !== normalized.textLayout || normalized.sessionForks !== true || normalized.transport !== "bounded-uint8array" || normalized.workbookMetadataQueries !== normalized.collaboration) {
585
+ if (normalized.abiVersion !== 1 || normalized.buildIdentityFormat !== "utf8" || normalized.canonicalStateHash !== "sha256:canonical-snapshot" || normalized.editableArtifactIntentVersion !== EDITABLE_ARTIFACT_INTENT_VERSION || normalized.spreadsheetCommandVersion !== SPREADSHEET_ARTIFACT_COMMAND_VERSION || normalized.spreadsheetModelSchemaVersion !== SPREADSHEET_ARTIFACT_MODEL_SCHEMA_VERSION || normalized.collaborationSnapshotVersion !== SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION || normalized.commandSchemaVersion !== SPREADSHEET_KERNEL_COMMAND_VERSION || normalized.committedTransactionVersion !== COMMITTED_TRANSACTION_PROTOCOL_VERSION || normalized.documentCommandVersion !== 1 || normalized.documentQueryResponseVersion !== 1 || normalized.documentQueryVersion !== 1 || normalized.documentReceiptVersion !== 1 || normalized.documentSnapshotVersion !== 1 || normalized.documentStatefulSessions !== normalized.document || normalized.kernelSnapshotVersion !== SPREADSHEET_KERNEL_SNAPSHOT_VERSION || normalized.maxCellsPerBatch !== WASM_MAX_CELLS_PER_BATCH || normalized.maxCommandBytes !== WASM_MAX_COMMAND_BYTES || normalized.maxSpreadsheetCommandBytes !== EDITABLE_ARTIFACT_COMMAND_MAX_BYTES || normalized.maxCommands !== 1e4 || normalized.maxIntentBytes !== EDITABLE_ARTIFACT_INTENT_MAX_BYTES || normalized.maxCommittedTransactionBytes !== MAX_COMMITTED_TRANSACTION_BYTES || normalized.maxDocumentCommandBytes !== WASM_MAX_COMMAND_BYTES || normalized.maxDocumentCommands !== 4096 || normalized.maxDocumentQueryBytes !== 256 || normalized.maxDocumentQueryResponseBytes !== 8 * 1024 * 1024 || normalized.maxDocumentSnapshotBytes !== WASM_MAX_SNAPSHOT_BYTES || normalized.maxMetadataScannedCells !== 4e6 || normalized.maxQueryBytes !== 68 || normalized.maxQueryResponseBytes !== 8 * 1024 * 1024 || normalized.maxViewportArea !== 1048576 || normalized.maxViewportCells !== 262144 || normalized.maxMetadataSheets !== 1e4 || normalized.maxPresentationCommandBytes !== 4 * 1024 * 1024 || normalized.maxPresentationQueryBytes !== 96 || normalized.maxPresentationResponseBytes !== 8 * 1024 * 1024 || normalized.maxPresentationSnapshotBytes !== WASM_MAX_SNAPSHOT_BYTES || normalized.maxTextLayoutFontBundleBytes !== 48 * 1024 * 1024 || normalized.maxTextLayoutRequestBytes !== 4 * 1024 * 1024 || normalized.maxTextLayoutResponseBytes !== 32 * 1024 * 1024 || normalized.maxSnapshotBytes !== WASM_MAX_SNAPSHOT_BYTES || normalized.queryResponseVersion !== 1 || normalized.queryVersion !== 1 || normalized.receiptSchemaVersion !== 1 || normalized.retainedRenderPatchVersion !== 1 || normalized.retainedRenderTileVersion !== 1 || normalized.presentationCommandVersion !== 1 || normalized.presentationQueryResponseVersion !== 1 || normalized.presentationQueryVersion !== 1 || normalized.presentationSnapshotVersion !== 1 || normalized.presentationStatefulSessions !== normalized.presentation || normalized.safeRust !== true || normalized.statefulSessions !== true || normalized.textLayoutFontBundleVersion !== 1 || normalized.textLayoutRequestVersion !== 1 || normalized.textLayoutResponseVersion !== 1 || normalized.textLayoutStatefulSessions !== normalized.textLayout || normalized.sessionForks !== true || normalized.transport !== "bounded-uint8array" || normalized.workbookMetadataQueries !== normalized.collaboration) {
572
586
  throw adapterError(
573
587
  "incompatible_wasm_build",
574
588
  "WASM capabilities do not match the SDK protocol"
@@ -612,7 +626,7 @@ function capabilityProfile(modality, capabilities) {
612
626
  );
613
627
  }
614
628
  return {
615
- modelSchemaVersion: capabilities.collaborationSnapshotVersion,
629
+ modelSchemaVersion: capabilities.spreadsheetModelSchemaVersion,
616
630
  commandVersion: capabilities.spreadsheetCommandVersion,
617
631
  maximumSnapshotBytes: capabilities.maxSnapshotBytes,
618
632
  maximumCommandBytes: capabilities.maxSpreadsheetCommandBytes,
@@ -755,9 +769,13 @@ import {
755
769
  decodeEditableArtifactMutationIntent,
756
770
  hashEditableArtifactMutationIntent
757
771
  } from "@opengeni/contracts/editable-artifacts";
758
- import { decodeCommittedTransactionSummary } from "@opengeni/contracts/editable-artifact-committed-transaction";
772
+ import {
773
+ COMMITTED_TRANSACTION_PROTOCOL_VERSION as COMMITTED_TRANSACTION_PROTOCOL_VERSION2,
774
+ decodeCommittedTransactionSummary
775
+ } from "@opengeni/contracts/editable-artifact-committed-transaction";
759
776
  import { editableArtifactCodecFor } from "@opengeni/contracts/editable-artifact-codec-registry";
760
777
  import { decodeEditableArtifactSerializedCommit } from "@opengeni/contracts/editable-artifact-serialized-commit";
778
+ import { SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION as SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION2 } from "@opengeni/contracts/editable-artifact-versions";
761
779
  var MAX_KNOWN_REQUESTS = 64;
762
780
  var MAX_QUEUED_REQUEST_BYTES = 192 * 1024 * 1024;
763
781
  var MAX_PENDING_AGGREGATE_BYTES = 64 * 1024 * 1024;
@@ -920,15 +938,17 @@ var ArtifactWorkerRuntime = class {
920
938
  "snapshot"
921
939
  );
922
940
  const snapshot = decodeSnapshotMetadata(frame.metadata, ownedBytes);
923
- if (snapshot.modality !== initialization.modality || snapshot.modality !== adapter.modality || snapshot.modality === "spreadsheet" && snapshot.protocolVersion !== adapter.protocolVersion || snapshot.kernelVersion !== adapter.kernelVersion || snapshot.modelSchemaVersion !== adapter.modelSchemaVersion) {
941
+ if (snapshot.modality !== initialization.modality || snapshot.modality !== adapter.modality || snapshot.modality === "spreadsheet" && (snapshot.operationProtocolVersion !== COMMITTED_TRANSACTION_PROTOCOL_VERSION2 || snapshot.snapshotVersion !== SPREADSHEET_COLLABORATION_SNAPSHOT_VERSION2) || snapshot.modelSchemaVersion !== adapter.modelSchemaVersion) {
924
942
  throw runtimeError(
925
943
  "unsupported_protocol",
926
- "snapshot protocol/kernel/schema is incompatible with the loaded collaboration kernel"
944
+ "snapshot protocol/schema is incompatible with the loaded collaboration kernel"
927
945
  );
928
946
  }
929
947
  const digest = await sha256Hex(ownedBytes);
930
948
  this.throwIfCancelled(frame.requestId);
931
- requireMatchingHash(digest, snapshot.digest, "snapshot digest");
949
+ if (digest !== snapshot.digest) {
950
+ throw runtimeError("byte_corruption", "snapshot digest does not match its bytes");
951
+ }
932
952
  const canonical = requireBytesWithin(
933
953
  adapter.canonicalizeSnapshot(ownedBytes),
934
954
  initialization.maximumSnapshotBytes,
@@ -946,7 +966,12 @@ var ArtifactWorkerRuntime = class {
946
966
  try {
947
967
  stateHash = await nextConfirmed.stateHash();
948
968
  this.throwIfCancelled(frame.requestId);
949
- requireMatchingHash(stateHash, snapshot.stateHash, "snapshot state");
969
+ if (stateHash !== snapshot.stateHash) {
970
+ throw runtimeError(
971
+ "authored_causal_mismatch",
972
+ "snapshot authored state does not match its state hash"
973
+ );
974
+ }
950
975
  if (snapshot.modality !== "spreadsheet" && nextConfirmed.nativeRevision() !== snapshot.nativeRevision) {
951
976
  throw runtimeError(
952
977
  "kernel_diverged",
@@ -968,7 +993,7 @@ var ArtifactWorkerRuntime = class {
968
993
  artifactId: snapshot.artifactId,
969
994
  modality: "spreadsheet",
970
995
  sequence: snapshot.sequence,
971
- protocolVersion: snapshot.protocolVersion,
996
+ protocolVersion: adapter.protocolVersion,
972
997
  kernelVersion: snapshot.kernelVersion,
973
998
  modelSchemaVersion: snapshot.modelSchemaVersion,
974
999
  stateHash,
@@ -1172,7 +1197,7 @@ var ArtifactWorkerRuntime = class {
1172
1197
  if (transaction.modality !== installed.modality) {
1173
1198
  throw runtimeError("modality_mismatch", "committed transaction modality is incompatible");
1174
1199
  }
1175
- if (transaction.modality === "spreadsheet" && transaction.protocolVersion !== installed.protocolVersion)
1200
+ if (transaction.modality === "spreadsheet" && transaction.operationProtocolVersion !== COMMITTED_TRANSACTION_PROTOCOL_VERSION2)
1176
1201
  throw runtimeError("unsupported_protocol", "committed transaction protocol is incompatible");
1177
1202
  if (transaction.startSequence !== installed.sequence + 1) {
1178
1203
  throw runtimeError("invalid_sequence", "committed transaction is not contiguous");
@@ -1559,14 +1584,14 @@ function assertCommittedEnvelopeMatchesOuter(transaction) {
1559
1584
  } catch (error) {
1560
1585
  throw new ArtifactWorkerProtocolError(
1561
1586
  "invalid_committed_transaction",
1562
- "committed transaction is not canonical OGACO001",
1587
+ "committed transaction is not canonical OGACO002",
1563
1588
  { cause: error }
1564
1589
  );
1565
1590
  }
1566
- if (summary.operationProtocolVersion !== transaction.protocolVersion || summary.transactionId !== transaction.transactionId || summary.priorStateHash !== transaction.priorStateHash || summary.stateHash !== transaction.stateHash || !frontiersEqual(summary.resultingCausalFrontier, transaction.causalFrontier)) {
1591
+ if (summary.operationProtocolVersion !== transaction.operationProtocolVersion || summary.transactionId !== transaction.transactionId || summary.priorStateHash !== transaction.priorStateHash || summary.stateHash !== transaction.stateHash || !frontiersEqual(summary.resultingCausalFrontier, transaction.causalFrontier)) {
1567
1592
  throw runtimeError(
1568
1593
  "committed_metadata_mismatch",
1569
- "outer committed metadata disagrees with its exact OGACO001 envelope"
1594
+ "outer committed metadata disagrees with its exact OGACO002 envelope"
1570
1595
  );
1571
1596
  }
1572
1597
  }
@@ -1638,8 +1663,9 @@ function asWorkerFailure(error) {
1638
1663
  };
1639
1664
  }
1640
1665
  if (error instanceof Error) {
1666
+ const rawCode = error.code;
1641
1667
  return {
1642
- code: "kernel_failed",
1668
+ code: typeof rawCode === "string" ? normalizeErrorCode(rawCode) : "kernel_failed",
1643
1669
  message: sanitizeErrorMessage(error.message || "artifact kernel failed"),
1644
1670
  retryable: false
1645
1671
  };
@@ -1655,7 +1681,8 @@ function asProtocolError(error) {
1655
1681
  );
1656
1682
  }
1657
1683
  function normalizeErrorCode(value) {
1658
- return /^[a-z][a-z0-9_]{0,127}$/.test(value) ? value : "kernel_failed";
1684
+ const normalized = value.toLowerCase();
1685
+ return /^[a-z][a-z0-9_]{0,127}$/.test(normalized) ? normalized : "kernel_failed";
1659
1686
  }
1660
1687
  function sanitizeErrorMessage(value) {
1661
1688
  let output = "";