@canonmsg/backend-contracts 4.0.0 → 4.0.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/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @canonmsg/backend-contracts
2
+
3
+ The wire contracts Canon's server and its clients must agree on, in one zero-dependency package.
4
+
5
+ Canon's Cloud Functions API, the SSE stream service, `@canonmsg/core`, and the shared chat domain all encode and decode the same messages, turn states, policies, and verbs. When those rules live in more than one place they drift silently. They live here.
6
+
7
+ This is a low-level package. If you are building an agent, you want [`@canonmsg/agent-sdk`](https://www.npmjs.com/package/@canonmsg/agent-sdk); if you are binding Canon's verbs into a model runtime, you want [`@canonmsg/agent-tools`](https://www.npmjs.com/package/@canonmsg/agent-tools). Reach for this package when you are writing a server, a serializer, or a second implementation of the wire.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @canonmsg/backend-contracts
13
+ ```
14
+
15
+ Node.js 18+. Ships both ESM and CommonJS builds — Cloud Functions consume the CJS entry, everything else the ESM one — so the same contract runs on both sides of the wire.
16
+
17
+ ## What is in it
18
+
19
+ **The verb contract.** `canon.verbs.v1` (`verbContract.ts`) is the plaintext *intent* schema — sixteen verbs, their input and result schemas, byte limits, and rate limits. `canon.verb-wire.v1` (`verbWire.ts`) is what actually crosses the network: a server-readable envelope plus a body that is either `{ encoding: 'json', value }` or `{ encoding: 'mls', … }`. `projectVerbIntentToWire` and `mergeVerbWireToIntent` are the two halves of that split, so bindings and the server never disagree about which fields are envelope and which are content.
20
+
21
+ ```ts
22
+ import {
23
+ CANON_VERB_NAMES,
24
+ getVerbInputSchema,
25
+ projectVerbIntentToWire,
26
+ } from '@canonmsg/backend-contracts';
27
+ ```
28
+
29
+ The JSON Schemas are also emitted as files for non-JavaScript consumers: `@canonmsg/backend-contracts/canon-verbs.schema.json`, `canon-verb-wire.schema.json`, and `canon-verbs.limits.json`.
30
+
31
+ **The turn protocol.** Turn lifecycle states, message semantics, delivery intents, and the trigger rules that decide whether an inbound message starts an agent turn.
32
+
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
+
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.
36
+
37
+ **Environments.** `CANON_ENVIRONMENT_CONTRACTS` binds `canon-dev-v1` and `canon-prod-v1` to their project and region; `getCanonEnvironmentContract` rejects anything else rather than defaulting.
38
+
39
+ **Diff redaction.** Approval diffs carry pre-image context into a message every conversation member can read, so secret-shaped paths and tokens are suppressed before send — by the emitting host, and again defensively by the server.
40
+
41
+ Agent-facing reference: [API contracts](https://canonmail.com/agents/contracts)
@@ -153,7 +153,7 @@
153
153
  },
154
154
  "messageOptions": {
155
155
  "type": "object",
156
- "description": "Message composition options (mirrors POST /messages/send). Deliberately absent: contact_card contentType (use share_contact) and forwarded/forwardedFrom (forwarding stays host/REST-mediated; /messages/forward is not a v1 verb).",
156
+ "description": "Message composition options (mirrors POST /messages/send). Deliberately absent: contact_card contentType (use share_contact) and forwarded/forwardedFrom (forwarding has its own verb — use forward, not send_to).",
157
157
  "additionalProperties": false,
158
158
  "properties": {
159
159
  "messageId": {
@@ -23,8 +23,9 @@
23
23
  *
24
24
  * Scope note: this module DESCRIBES the contract (canonical shapes + the
25
25
  * server-enforced limits, with enforcement sites cited). Enforcement itself
26
- * stays where it runs today — functions/src. Server-side verb endpoints that
27
- * validate against these schemas are a planned follow-up.
26
+ * stays where it runs today — functions/src. The server-side verb endpoint that
27
+ * validates against these schemas is live: POST /agent/verbs/:verb
28
+ * (functions/src/index.ts, functions/src/api/agentVerbs.ts).
28
29
  *
29
30
  * Normativity: the JSON Schemas in `verbSchemas.ts` (and the emitted
30
31
  * canon-verbs.schema.json) are the normative contract. The TypeScript types
@@ -125,7 +125,7 @@ const messageOptionsDef = {
125
125
  type: 'object',
126
126
  description: 'Message composition options (mirrors POST /messages/send). Deliberately absent: '
127
127
  + 'contact_card contentType (use share_contact) and forwarded/forwardedFrom '
128
- + '(forwarding stays host/REST-mediated; /messages/forward is not a v1 verb).',
128
+ + '(forwarding has its own verb — use forward, not send_to).',
129
129
  additionalProperties: false,
130
130
  properties: {
131
131
  messageId: REF('messageId'),
@@ -22,8 +22,9 @@
22
22
  *
23
23
  * Scope note: this module DESCRIBES the contract (canonical shapes + the
24
24
  * server-enforced limits, with enforcement sites cited). Enforcement itself
25
- * stays where it runs today — functions/src. Server-side verb endpoints that
26
- * validate against these schemas are a planned follow-up.
25
+ * stays where it runs today — functions/src. The server-side verb endpoint that
26
+ * validates against these schemas is live: POST /agent/verbs/:verb
27
+ * (functions/src/index.ts, functions/src/api/agentVerbs.ts).
27
28
  *
28
29
  * Normativity: the JSON Schemas in `verbSchemas.ts` (and the emitted
29
30
  * canon-verbs.schema.json) are the normative contract. The TypeScript types
@@ -22,8 +22,9 @@
22
22
  *
23
23
  * Scope note: this module DESCRIBES the contract (canonical shapes + the
24
24
  * server-enforced limits, with enforcement sites cited). Enforcement itself
25
- * stays where it runs today — functions/src. Server-side verb endpoints that
26
- * validate against these schemas are a planned follow-up.
25
+ * stays where it runs today — functions/src. The server-side verb endpoint that
26
+ * validates against these schemas is live: POST /agent/verbs/:verb
27
+ * (functions/src/index.ts, functions/src/api/agentVerbs.ts).
27
28
  *
28
29
  * Normativity: the JSON Schemas in `verbSchemas.ts` (and the emitted
29
30
  * canon-verbs.schema.json) are the normative contract. The TypeScript types
@@ -120,7 +120,7 @@ const messageOptionsDef = {
120
120
  type: 'object',
121
121
  description: 'Message composition options (mirrors POST /messages/send). Deliberately absent: '
122
122
  + 'contact_card contentType (use share_contact) and forwarded/forwardedFrom '
123
- + '(forwarding stays host/REST-mediated; /messages/forward is not a v1 verb).',
123
+ + '(forwarding has its own verb — use forward, not send_to).',
124
124
  additionalProperties: false,
125
125
  properties: {
126
126
  messageId: REF('messageId'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/backend-contracts",
3
- "version": "4.0.0",
3
+ "version": "4.0.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",
@@ -43,7 +43,7 @@
43
43
  "access": "public"
44
44
  },
45
45
  "devDependencies": {
46
- "@canonmsg/rich-cards": "^0.8.5",
46
+ "@canonmsg/rich-cards": "^0.8.6",
47
47
  "@types/node": "^22.0.0",
48
48
  "ajv": "^8.20.0",
49
49
  "typescript": "~5.7.0",