@canonmsg/backend-contracts 3.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 +41 -0
- package/dist/canon-verbs.schema.json +1 -1
- package/dist/cjs/environment.js +0 -5
- package/dist/cjs/verbContract.js +3 -2
- package/dist/cjs/verbSchemas.js +1 -1
- package/dist/environment.d.ts +0 -5
- package/dist/environment.js +0 -5
- package/dist/verbContract.d.ts +3 -2
- package/dist/verbContract.js +3 -2
- package/dist/verbSchemas.js +1 -1
- package/package.json +2 -2
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
|
|
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": {
|
package/dist/cjs/environment.js
CHANGED
|
@@ -13,11 +13,6 @@ exports.CANON_ENVIRONMENT_CONTRACTS = Object.freeze({
|
|
|
13
13
|
projectId: 'canonmail-prod',
|
|
14
14
|
region: 'europe-west1',
|
|
15
15
|
}),
|
|
16
|
-
'canon-legacy-v1': Object.freeze({
|
|
17
|
-
name: 'legacy',
|
|
18
|
-
projectId: 'project-007a8e71-ba01-49e6-8aa',
|
|
19
|
-
region: 'us-central1',
|
|
20
|
-
}),
|
|
21
16
|
});
|
|
22
17
|
function getCanonEnvironmentContract(value) {
|
|
23
18
|
const environmentId = value.trim();
|
package/dist/cjs/verbContract.js
CHANGED
|
@@ -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.
|
|
27
|
-
*
|
|
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
|
package/dist/cjs/verbSchemas.js
CHANGED
|
@@ -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
|
|
128
|
+
+ '(forwarding has its own verb — use forward, not send_to).',
|
|
129
129
|
additionalProperties: false,
|
|
130
130
|
properties: {
|
|
131
131
|
messageId: REF('messageId'),
|
package/dist/environment.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ export declare const CANON_ENVIRONMENT_CONTRACTS: Readonly<{
|
|
|
9
9
|
projectId: "canonmail-prod";
|
|
10
10
|
region: "europe-west1";
|
|
11
11
|
}>;
|
|
12
|
-
readonly 'canon-legacy-v1': Readonly<{
|
|
13
|
-
name: "legacy";
|
|
14
|
-
projectId: "project-007a8e71-ba01-49e6-8aa";
|
|
15
|
-
region: "us-central1";
|
|
16
|
-
}>;
|
|
17
12
|
}>;
|
|
18
13
|
export type CanonEnvironmentId = keyof typeof CANON_ENVIRONMENT_CONTRACTS;
|
|
19
14
|
export type CanonEnvironmentName = (typeof CANON_ENVIRONMENT_CONTRACTS)[CanonEnvironmentId]['name'];
|
package/dist/environment.js
CHANGED
|
@@ -9,11 +9,6 @@ export const CANON_ENVIRONMENT_CONTRACTS = Object.freeze({
|
|
|
9
9
|
projectId: 'canonmail-prod',
|
|
10
10
|
region: 'europe-west1',
|
|
11
11
|
}),
|
|
12
|
-
'canon-legacy-v1': Object.freeze({
|
|
13
|
-
name: 'legacy',
|
|
14
|
-
projectId: 'project-007a8e71-ba01-49e6-8aa',
|
|
15
|
-
region: 'us-central1',
|
|
16
|
-
}),
|
|
17
12
|
});
|
|
18
13
|
export function getCanonEnvironmentContract(value) {
|
|
19
14
|
const environmentId = value.trim();
|
package/dist/verbContract.d.ts
CHANGED
|
@@ -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.
|
|
26
|
-
*
|
|
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
|
package/dist/verbContract.js
CHANGED
|
@@ -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.
|
|
26
|
-
*
|
|
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
|
package/dist/verbSchemas.js
CHANGED
|
@@ -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
|
|
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": "
|
|
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.
|
|
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",
|