@canonmsg/backend-contracts 7.0.0 → 8.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.
package/README.md CHANGED
@@ -32,9 +32,9 @@ The JSON Schemas are also emitted as files for non-JavaScript consumers: `@canon
32
32
 
33
33
  **Message and media serialization.** The canonical `SerializedContentType` union (`text | image | audio | video | file | contact_card | interaction`), attachment normalization, and the single runtime-card decoder that `@canonmsg/core` re-exports rather than reimplements.
34
34
 
35
- **Behavior policy and contact requests.** The participation evaluator the stream service runs before dispatching a turn, and the contact-request serializer both sides validate against.
35
+ **Behavior policy.** The participation evaluator the stream service runs before dispatching a turn.
36
36
 
37
- **Server-side normalizers.** `readCanonicalPolicy` resolves a stored `inboundPolicy` / `groupJoinPolicy` field to the access triplet's three values, defaulting to `approval-required` rather than widening to `open`. `serializeSelfContext` is the agent-facing projection of a stored self-context. `readModerationStatus` is the single definition of an ejected account. All take plain document-shaped data — the package still performs no I/O.
37
+ **Server-side normalizers.** `readCommunicationRule` resolves a stored communication-policy field to `open | approval-required | closed`, defaulting to `approval-required` rather than widening to `open`. `serializeSelfContext` is the agent-facing projection of a stored self-context. `readModerationStatus` is the single definition of an ejected account. All take plain document-shaped data — the package still performs no I/O.
38
38
 
39
39
  **Environments.** `CANON_ENVIRONMENT_CONTRACTS` binds `canon-dev-v1` and `canon-prod-v1` to their project and region; `getCanonEnvironmentContract` rejects anything else rather than defaulting.
40
40
 
@@ -31,7 +31,6 @@
31
31
  "remove_member",
32
32
  "leave_conversation",
33
33
  "list_contacts",
34
- "list_contact_requests",
35
34
  "list_conversations",
36
35
  "no_reply"
37
36
  ]
@@ -212,71 +211,6 @@
212
211
  }
213
212
  ]
214
213
  },
215
- "sessionConfig": {
216
- "oneOf": [
217
- {
218
- "type": "object",
219
- "description": "Typed setup policy for an agent target. Values are stable runtime-advertised option ids and are validated against the target descriptor before session creation; labels, prompts, workspace paths, and arbitrary fields are not permitted.",
220
- "additionalProperties": false,
221
- "properties": {
222
- "model": {
223
- "type": "string",
224
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
225
- "maxLength": 256
226
- },
227
- "permissionMode": {
228
- "type": "string",
229
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
230
- "maxLength": 256
231
- },
232
- "effort": {
233
- "type": "string",
234
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
235
- "maxLength": 256
236
- },
237
- "workspaceId": {
238
- "type": "string",
239
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:@+\\-]{0,255}$",
240
- "maxLength": 256
241
- },
242
- "executionMode": {
243
- "enum": [
244
- "worktree",
245
- "locked"
246
- ]
247
- },
248
- "runtimeControlValues": {
249
- "type": "object",
250
- "maxProperties": 24,
251
- "propertyNames": {
252
- "pattern": "^[A-Za-z0-9_-]{1,80}$",
253
- "not": {
254
- "enum": [
255
- "model",
256
- "workspace",
257
- "executionMode",
258
- "permissionMode",
259
- "effort",
260
- "interrupt",
261
- "runtimeControlValues",
262
- "updatedAt",
263
- "updatedBy"
264
- ]
265
- }
266
- },
267
- "additionalProperties": {
268
- "type": "string",
269
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
270
- "maxLength": 256
271
- }
272
- }
273
- }
274
- },
275
- {
276
- "type": "null"
277
- }
278
- ]
279
- },
280
214
  "idempotencyKey": {
281
215
  "type": "string",
282
216
  "pattern": "^[A-Za-z0-9_.:-]{1,160}$",
@@ -506,7 +440,6 @@
506
440
  "remove_member",
507
441
  "leave_conversation",
508
442
  "list_contacts",
509
- "list_contact_requests",
510
443
  "list_conversations",
511
444
  "no_reply"
512
445
  ]
@@ -38,8 +38,6 @@
38
38
  "nativeKeys": 24,
39
39
  "nativeValueChars": 256,
40
40
  "nativeHandles": 16,
41
- "sessionConfigValues": 24,
42
- "sessionConfigValueChars": 256,
43
41
  "minTimeoutMs": 1000,
44
42
  "maxTimeoutMs": 1800000,
45
43
  "maxApprovalTimeoutMs": 259200000,
@@ -61,10 +59,7 @@
61
59
  "sessionRuleToolPattern": "^[\\w.*:-]{1,128}$",
62
60
  "runtimeCorrelationValue": "^[A-Za-z0-9@_][A-Za-z0-9_.:@+\\-]{0,255}$",
63
61
  "runtimeMethod": "^[A-Za-z0-9_][A-Za-z0-9_./:\\-]{0,255}$",
64
- "runtimeOptionValue": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
65
- "workspaceOptionId": "^[A-Za-z0-9@_][A-Za-z0-9_.:@+\\-]{0,255}$",
66
62
  "runtimeHandleKey": "^[A-Za-z0-9_.:-]{1,80}$",
67
- "runtimeControlId": "^[A-Za-z0-9_-]{1,80}$",
68
63
  "resumableUploadId": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
69
64
  },
70
65
  "byteSemantics": {
@@ -13,23 +13,6 @@
13
13
  },
14
14
  "description": "Client idempotency key (<= 160 chars / 256 UTF-8 bytes; no slashes, control chars, '.', '..', __x__). Same id + identical payload replays idempotently; different payload -> 409 MESSAGE_ID_EXISTS."
15
15
  },
16
- "groupInviteRequirements": {
17
- "type": "object",
18
- "description": "Independent gates on a pending group invite. policyApproval is social consent; ownerSessionSetup means the agent owner must choose the runtime session configuration before membership is activated.",
19
- "required": [
20
- "policyApproval",
21
- "ownerSessionSetup"
22
- ],
23
- "additionalProperties": false,
24
- "properties": {
25
- "policyApproval": {
26
- "type": "boolean"
27
- },
28
- "ownerSessionSetup": {
29
- "type": "boolean"
30
- }
31
- }
32
- },
33
16
  "selfContext": {
34
17
  "type": "object",
35
18
  "description": "Private note-to-self attached to a cross-conversation send. Visible only to the sending agent (surfaced back as provenance.activeSelfContext); never shown to recipients. Enforced by functions/src/utils/selfContexts.ts.",
@@ -557,67 +540,9 @@
557
540
  }
558
541
  }
559
542
  },
560
- "sessionConfig": {
561
- "type": "object",
562
- "description": "Typed setup policy for an agent target. Values are stable runtime-advertised option ids and are validated against the target descriptor before session creation; labels, prompts, workspace paths, and arbitrary fields are not permitted.",
563
- "additionalProperties": false,
564
- "properties": {
565
- "model": {
566
- "type": "string",
567
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
568
- "maxLength": 256
569
- },
570
- "permissionMode": {
571
- "type": "string",
572
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
573
- "maxLength": 256
574
- },
575
- "effort": {
576
- "type": "string",
577
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
578
- "maxLength": 256
579
- },
580
- "workspaceId": {
581
- "type": "string",
582
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:@+\\-]{0,255}$",
583
- "maxLength": 256
584
- },
585
- "executionMode": {
586
- "enum": [
587
- "worktree",
588
- "locked"
589
- ]
590
- },
591
- "runtimeControlValues": {
592
- "type": "object",
593
- "maxProperties": 24,
594
- "propertyNames": {
595
- "pattern": "^[A-Za-z0-9_-]{1,80}$",
596
- "not": {
597
- "enum": [
598
- "model",
599
- "workspace",
600
- "executionMode",
601
- "permissionMode",
602
- "effort",
603
- "interrupt",
604
- "runtimeControlValues",
605
- "updatedAt",
606
- "updatedBy"
607
- ]
608
- }
609
- },
610
- "additionalProperties": {
611
- "type": "string",
612
- "pattern": "^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$",
613
- "maxLength": 256
614
- }
615
- }
616
- }
617
- },
618
543
  "send_to_input": {
619
544
  "type": "object",
620
- "description": "Message another conversation or user (admission-aware), optionally carrying a private self-context. Exactly one of targetConversationId / targetUserId / canonContactId. canonContactId is NOT a wire field: bindings resolve it via POST /admission/resolve to a targetUserId first. Projections: selfContext sends -> POST /messages/send-contextual (which requires sourceConversationId + selfContext); known-conversation sends without selfContext -> POST /messages/send; plain user sends -> admission resolve + create + send (the core reachOut composite). User targets resolve admission first: open targets get the message, approval-required targets get a contact request (send deferred and auto-fulfilled on approval), owner-only targets surface as status 'unavailable' with reason owner-only.",
545
+ "description": "Message another conversation or user (admission-aware), optionally carrying a private self-context. Exactly one of targetConversationId / targetUserId / canonContactId. canonContactId is NOT a wire field: bindings resolve it via POST /admission/resolve to a targetUserId first. Projections: selfContext sends -> POST /messages/send-contextual (which requires sourceConversationId + selfContext); known-conversation sends without selfContext -> POST /messages/send; plain user sends -> admission resolve + create + send (the core reachOut composite). User targets resolve admission first: open targets get the message, approval-required targets get a contact request (send deferred and auto-fulfilled on approval), closed targets surface as status 'unavailable' with reason closed.",
621
546
  "additionalProperties": false,
622
547
  "properties": {
623
548
  "targetConversationId": {
@@ -653,17 +578,6 @@
653
578
  "sessionSelection": {
654
579
  "$ref": "#/$defs/sessionSelection"
655
580
  },
656
- "sessionConfig": {
657
- "oneOf": [
658
- {
659
- "$ref": "#/$defs/sessionConfig"
660
- },
661
- {
662
- "type": "null"
663
- }
664
- ],
665
- "description": "Coding-agent session setup (model/permissionMode/effort/workspaceId/executionMode); only applied to agent targets, stripped for humans."
666
- },
667
581
  "messageOptions": {
668
582
  "$ref": "#/$defs/messageOptions"
669
583
  }
@@ -1511,7 +1425,7 @@
1511
1425
  },
1512
1426
  "create_group_input": {
1513
1427
  "type": "object",
1514
- "description": "Create a group conversation. Each target's groupJoinPolicy is enforced server-side with staged admission: directly-addable members join at creation, approval-required members become pending group_invite requests; agents needing explicit group-session setup become pending owner requests; hard-denied members are skipped (see the result). A creator-only group is valid when at least one requested member has a pending invite. A creator that itself requires setup cannot create groups (403 CREATE_GROUP_CREATOR_SETUP_REQUIRED). Under MLS, membership changes are Add/Remove proposals + Commit — a group operation is a cryptographic state change, not a codec swap.",
1428
+ "description": "Create a group conversation. Each target's groupJoinPolicy is enforced server-side with staged admission: directly-addable members join at creation, approval-required members become pending group_invite requests; hard-denied members are skipped (see the result). A creator-only group is valid when at least one requested member has a pending invite. Under MLS, membership changes are Add/Remove proposals + Commit — a group operation is a cryptographic state change, not a codec swap.",
1515
1429
  "required": [
1516
1430
  "name",
1517
1431
  "memberIds"
@@ -1537,7 +1451,7 @@
1537
1451
  },
1538
1452
  "create_group_result": {
1539
1453
  "type": "object",
1540
- "description": "Staged admission: the group exists with the directly-added members; `pending` lists group_invite requests awaiting policy approval, owner session setup, or both; `skipped` lists hard-denied targets.",
1454
+ "description": "Staged admission: the group exists with the directly-added members; `pending` lists group_invite requests awaiting policy approval; `skipped` lists hard-denied targets.",
1541
1455
  "required": [
1542
1456
  "status",
1543
1457
  "conversationId",
@@ -1565,8 +1479,7 @@
1565
1479
  "type": "object",
1566
1480
  "required": [
1567
1481
  "userId",
1568
- "requestId",
1569
- "requirements"
1482
+ "requestId"
1570
1483
  ],
1571
1484
  "additionalProperties": true,
1572
1485
  "properties": {
@@ -1575,9 +1488,6 @@
1575
1488
  },
1576
1489
  "requestId": {
1577
1490
  "type": "string"
1578
- },
1579
- "requirements": {
1580
- "$ref": "#/$defs/groupInviteRequirements"
1581
1491
  }
1582
1492
  }
1583
1493
  }
@@ -1605,7 +1515,7 @@
1605
1515
  },
1606
1516
  "add_member_input": {
1607
1517
  "type": "object",
1608
- "description": "A target needing policy approval and/or explicit owner session setup yields one pending group_invite. Under MLS an add is an Add proposal + Commit (new epoch), not a server-side membership write — the verb semantics are stable, the mechanism is not.",
1518
+ "description": "A target needing policy approval yields one pending group_invite. Under MLS an add is an Add proposal + Commit (new epoch), not a server-side membership write — the verb semantics are stable, the mechanism is not.",
1609
1519
  "required": [
1610
1520
  "conversationId",
1611
1521
  "userId"
@@ -1623,7 +1533,7 @@
1623
1533
  }
1624
1534
  },
1625
1535
  "add_member_result": {
1626
- "description": "Targets needing policy approval and/or owner session setup yield one pending group_invite routed to the target or agent owner.",
1536
+ "description": "Targets needing policy approval yield an exact pending group invite.",
1627
1537
  "oneOf": [
1628
1538
  {
1629
1539
  "type": "object",
@@ -1641,8 +1551,7 @@
1641
1551
  "type": "object",
1642
1552
  "required": [
1643
1553
  "status",
1644
- "requestId",
1645
- "requirements"
1554
+ "requestId"
1646
1555
  ],
1647
1556
  "additionalProperties": true,
1648
1557
  "properties": {
@@ -1651,9 +1560,6 @@
1651
1560
  },
1652
1561
  "requestId": {
1653
1562
  "type": "string"
1654
- },
1655
- "requirements": {
1656
- "$ref": "#/$defs/groupInviteRequirements"
1657
1563
  }
1658
1564
  }
1659
1565
  }
@@ -1764,81 +1670,6 @@
1764
1670
  }
1765
1671
  }
1766
1672
  },
1767
- "list_contact_requests_input": {
1768
- "type": "object",
1769
- "additionalProperties": false,
1770
- "properties": {}
1771
- },
1772
- "list_contact_requests_result": {
1773
- "type": "object",
1774
- "description": "Pending inbound requests, newest first, capped at 100. Items are SerializedContactRequest (backend-contracts contactRequest.ts). Read-only awareness: approval routes to the owner; agents cannot approve/reject.",
1775
- "required": [
1776
- "requests"
1777
- ],
1778
- "additionalProperties": true,
1779
- "properties": {
1780
- "requests": {
1781
- "type": "array",
1782
- "items": {
1783
- "type": "object",
1784
- "required": [
1785
- "id",
1786
- "requesterId",
1787
- "targetId",
1788
- "status",
1789
- "kind"
1790
- ],
1791
- "additionalProperties": true,
1792
- "properties": {
1793
- "id": {
1794
- "type": "string"
1795
- },
1796
- "requesterId": {
1797
- "type": "string"
1798
- },
1799
- "requesterName": {
1800
- "type": "string"
1801
- },
1802
- "targetId": {
1803
- "type": "string"
1804
- },
1805
- "status": {
1806
- "enum": [
1807
- "pending",
1808
- "approved",
1809
- "rejected",
1810
- "expired"
1811
- ]
1812
- },
1813
- "kind": {
1814
- "enum": [
1815
- "dm",
1816
- "group_invite"
1817
- ]
1818
- },
1819
- "message": {
1820
- "type": [
1821
- "string",
1822
- "null"
1823
- ]
1824
- },
1825
- "createdAt": {
1826
- "type": [
1827
- "string",
1828
- "null"
1829
- ]
1830
- },
1831
- "expiresAt": {
1832
- "type": [
1833
- "string",
1834
- "null"
1835
- ]
1836
- }
1837
- }
1838
- }
1839
- }
1840
- }
1841
- },
1842
1673
  "list_conversations_input": {
1843
1674
  "type": "object",
1844
1675
  "additionalProperties": false,
@@ -7,10 +7,6 @@ function readCommunicationRule(value) {
7
7
  if (value === 'open' || value === 'approval-required' || value === 'closed') {
8
8
  return value;
9
9
  }
10
- // Existing owner-only records have the same outsider-facing meaning as
11
- // closed; the agent owner bypass remains a separate server-side rule.
12
- if (value === 'owner-only')
13
- return 'closed';
14
10
  return 'approval-required';
15
11
  }
16
12
  function parseDirectConversationSelection(value) {
@@ -14,7 +14,7 @@ function normalizeStoredString(value) {
14
14
  /**
15
15
  * Firestore Timestamp-like -> ISO 8601, or null. Accepts only objects exposing
16
16
  * `toDate()`. A raw `Date` is deliberately NOT accepted: that matches both call
17
- * sites this replaced. `message.ts` and `contactRequest.ts` keep their own
17
+ * sites this replaced. `message.ts` keeps its own
18
18
  * Date-tolerant normalizers — a different contract, not this one.
19
19
  */
20
20
  function firestoreTimestampToISOString(value) {
package/dist/cjs/index.js CHANGED
@@ -24,13 +24,12 @@ __exportStar(require("./runtimeCardStorage.js"), exports);
24
24
  __exportStar(require("./turnProtocol.js"), exports);
25
25
  __exportStar(require("./agentBehaviorPolicy.js"), exports);
26
26
  __exportStar(require("./agentSearch.js"), exports);
27
- __exportStar(require("./contactRequest.js"), exports);
28
27
  __exportStar(require("./verbContract.js"), exports);
29
28
  __exportStar(require("./verbSchemas.js"), exports);
30
29
  __exportStar(require("./verbWire.js"), exports);
31
- __exportStar(require("./accessPolicy.js"), exports);
32
30
  __exportStar(require("./communication.js"), exports);
33
31
  __exportStar(require("./apiErrors.js"), exports);
34
32
  __exportStar(require("./firestoreValues.js"), exports);
35
33
  __exportStar(require("./moderation.js"), exports);
36
34
  __exportStar(require("./selfContext.js"), exports);
35
+ __exportStar(require("./replyAuthority.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -44,7 +44,7 @@
44
44
  * canon-verbs.limits.json) after schema validation.
45
45
  */
46
46
  Object.defineProperty(exports, "__esModule", { value: true });
47
- exports.CANON_VERB_LIMITS_ARTIFACT = exports.NO_REPLY_ACK_NOTE = exports.CREATE_GROUP_CREATOR_SETUP_REQUIRED_CODE = exports.CREATE_GROUP_NO_ADDABLE_MEMBERS_CODE = exports.VERB_NATIVE_METADATA_KEYS = exports.CANON_VERB_NAMES = exports.SELF_CONTEXT_TYPE = exports.VERB_RATE_LIMITS = exports.VERB_LIMITS = exports.VERB_ID_PATTERNS = exports.CANON_CARD_SCHEMA_ID = exports.CANON_VERB_NAMESPACE = exports.CANON_VERBS_SCHEMA_ID = exports.CANON_VERBS_SCHEMA_VERSION = void 0;
47
+ exports.CANON_VERB_LIMITS_ARTIFACT = exports.NO_REPLY_ACK_NOTE = exports.CREATE_GROUP_NO_ADDABLE_MEMBERS_CODE = exports.VERB_NATIVE_METADATA_KEYS = exports.CANON_VERB_NAMES = exports.SELF_CONTEXT_TYPE = exports.VERB_RATE_LIMITS = exports.VERB_LIMITS = exports.VERB_ID_PATTERNS = exports.CANON_CARD_SCHEMA_ID = exports.CANON_VERB_NAMESPACE = exports.CANON_VERBS_SCHEMA_ID = exports.CANON_VERBS_SCHEMA_VERSION = void 0;
48
48
  exports.normalizeVerbNativeMetadata = normalizeVerbNativeMetadata;
49
49
  exports.canonVerbToolName = canonVerbToolName;
50
50
  exports.findVerbByteLimitViolations = findVerbByteLimitViolations;
@@ -78,10 +78,7 @@ exports.VERB_ID_PATTERNS = {
78
78
  sessionRuleToolPattern: '^[\\w.*:-]{1,128}$',
79
79
  runtimeCorrelationValue: '^[A-Za-z0-9@_][A-Za-z0-9_.:@+\\-]{0,255}$',
80
80
  runtimeMethod: '^[A-Za-z0-9_][A-Za-z0-9_./:\\-]{0,255}$',
81
- runtimeOptionValue: '^[A-Za-z0-9@_][A-Za-z0-9_.:/@+\\-]{0,255}$',
82
- workspaceOptionId: '^[A-Za-z0-9@_][A-Za-z0-9_.:@+\\-]{0,255}$',
83
81
  runtimeHandleKey: '^[A-Za-z0-9_.:-]{1,80}$',
84
- runtimeControlId: '^[A-Za-z0-9_-]{1,80}$',
85
82
  /** UUID issued by Canon's resumable-media session endpoint. */
86
83
  resumableUploadId: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$',
87
84
  };
@@ -151,9 +148,6 @@ exports.VERB_LIMITS = {
151
148
  nativeKeys: 24,
152
149
  nativeValueChars: 256,
153
150
  nativeHandles: 16,
154
- /** Initial agent-session setup carried by send_to. */
155
- sessionConfigValues: 24,
156
- sessionConfigValueChars: 256,
157
151
  /** Deadlines (functions/src/utils/runtimeRequestHelpers.ts). */
158
152
  minTimeoutMs: 1000,
159
153
  /** input/card/plan ceiling (30 minutes). */
@@ -204,7 +198,6 @@ exports.CANON_VERB_NAMES = [
204
198
  'remove_member',
205
199
  'leave_conversation',
206
200
  'list_contacts',
207
- 'list_contact_requests',
208
201
  'list_conversations',
209
202
  'no_reply',
210
203
  ];
@@ -273,14 +266,6 @@ function normalizeVerbNativeMetadata(value) {
273
266
  * invite is allowed; the error detail carries the attempted partition.
274
267
  */
275
268
  exports.CREATE_GROUP_NO_ADDABLE_MEMBERS_CODE = 'CREATE_GROUP_NO_ADDABLE_MEMBERS';
276
- /**
277
- * Error code on the 403 a create_group receives when the CREATOR itself is
278
- * a coding agent requiring explicit session setup: the group helper prepares
279
- * session configs for every coding-agent member including the creator, and
280
- * only the agent's human owner may provide them (v1 scoping — the owner
281
- * creates the group from the app instead).
282
- */
283
- exports.CREATE_GROUP_CREATOR_SETUP_REQUIRED_CODE = 'CREATE_GROUP_CREATOR_SETUP_REQUIRED';
284
269
  /**
285
270
  * The `note` the server returns on a `no_reply` ack — the model's closure
286
271
  * sentence. It lives here, not in a host, because every binding surfaces the