@canonmsg/backend-contracts 1.1.0 → 1.1.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.
package/dist/cjs/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./media.js"), exports);
18
18
  __exportStar(require("./message.js"), exports);
19
+ __exportStar(require("./runtimeCardStorage.js"), exports);
19
20
  __exportStar(require("./turnProtocol.js"), exports);
20
21
  __exportStar(require("./agentBehaviorPolicy.js"), exports);
21
22
  __exportStar(require("./contactRequest.js"), exports);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializeStoredMessage = serializeStoredMessage;
4
4
  const media_js_1 = require("./media.js");
5
+ const runtimeCardStorage_js_1 = require("./runtimeCardStorage.js");
5
6
  function isRecord(value) {
6
7
  return typeof value === 'object' && value !== null && !Array.isArray(value);
7
8
  }
@@ -132,8 +133,9 @@ function serializeStoredMessage(input) {
132
133
  if (contactCard) {
133
134
  result.contactCard = contactCard;
134
135
  }
135
- if (isRecord(data.runtimeCard)) {
136
- result.runtimeCard = data.runtimeCard;
136
+ const runtimeCard = (0, runtimeCardStorage_js_1.decodeStoredRuntimeCard)(data);
137
+ if (runtimeCard) {
138
+ result.runtimeCard = runtimeCard;
137
139
  }
138
140
  return result;
139
141
  }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeStoredRuntimeCard = decodeStoredRuntimeCard;
4
+ function isRecord(value) {
5
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
6
+ }
7
+ function decodeStoredRuntimeCard(input) {
8
+ if (isRecord(input.runtimeCard)) {
9
+ return input.runtimeCard;
10
+ }
11
+ if (typeof input.runtimeCardJson !== 'string' || !input.runtimeCardJson.trim()) {
12
+ return undefined;
13
+ }
14
+ try {
15
+ const parsed = JSON.parse(input.runtimeCardJson);
16
+ return isRecord(parsed) ? parsed : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './media.js';
2
2
  export * from './message.js';
3
+ export * from './runtimeCardStorage.js';
3
4
  export * from './turnProtocol.js';
4
5
  export * from './agentBehaviorPolicy.js';
5
6
  export * from './contactRequest.js';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './media.js';
2
2
  export * from './message.js';
3
+ export * from './runtimeCardStorage.js';
3
4
  export * from './turnProtocol.js';
4
5
  export * from './agentBehaviorPolicy.js';
5
6
  export * from './contactRequest.js';
package/dist/message.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { normalizeStoredAttachments } from './media.js';
2
+ import { decodeStoredRuntimeCard } from './runtimeCardStorage.js';
2
3
  function isRecord(value) {
3
4
  return typeof value === 'object' && value !== null && !Array.isArray(value);
4
5
  }
@@ -129,8 +130,9 @@ export function serializeStoredMessage(input) {
129
130
  if (contactCard) {
130
131
  result.contactCard = contactCard;
131
132
  }
132
- if (isRecord(data.runtimeCard)) {
133
- result.runtimeCard = data.runtimeCard;
133
+ const runtimeCard = decodeStoredRuntimeCard(data);
134
+ if (runtimeCard) {
135
+ result.runtimeCard = runtimeCard;
134
136
  }
135
137
  return result;
136
138
  }
@@ -0,0 +1,4 @@
1
+ export declare function decodeStoredRuntimeCard(input: {
2
+ runtimeCard?: unknown;
3
+ runtimeCardJson?: unknown;
4
+ }): Record<string, unknown> | undefined;
@@ -0,0 +1,18 @@
1
+ function isRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ export function decodeStoredRuntimeCard(input) {
5
+ if (isRecord(input.runtimeCard)) {
6
+ return input.runtimeCard;
7
+ }
8
+ if (typeof input.runtimeCardJson !== 'string' || !input.runtimeCardJson.trim()) {
9
+ return undefined;
10
+ }
11
+ try {
12
+ const parsed = JSON.parse(input.runtimeCardJson);
13
+ return isRecord(parsed) ? parsed : undefined;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/backend-contracts",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Canon backend contract helpers shared by Functions and stream-service",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",