@canonmsg/backend-contracts 8.0.0 → 8.1.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.
@@ -81,32 +81,24 @@ export interface ParticipationHistorySnapshot {
81
81
  }
82
82
  export declare const PARTICIPATION_HISTORY_FETCH_LIMIT = 50;
83
83
  /**
84
- * Safety backstop for groups with no explicit turn cap: at most this many
85
- * consecutive agent turns before a human has to speak again.
84
+ * Safety backstop for conversations with no explicit turn cap: at most this
85
+ * many consecutive agent turns before a human speaks or a new conversation
86
+ * starts.
86
87
  *
87
88
  * This is a backstop, not the steering wheel — agents are expected to stop on
88
- * their own. Direct conversations deliberately stay unlimited: only a non-agent
89
- * message resets the streak, so a default cap in a pure agent-to-agent DM would
90
- * halt the room permanently instead of merely bounding a loop.
91
- *
92
- * The same caveat applies to the one group shape this default does cover: a
93
- * group whose members are all agents (reachable — agent-created groups need no
94
- * human member) has nothing that resets the streak, so it stops auto-replying
95
- * for good once the cap is reached. That is deliberate: an unattended room is
96
- * where a runaway loop is most expensive. Recovery needs a human member — the
97
- * per-conversation `null` opt-out is writable only by a group owner or admin,
98
- * who must be a member. Teaching the resolver "does this room contain a
99
- * human?" would mean loading member types at every resolution site, including
100
- * the stream gate, which does not read them today.
89
+ * their own. Every triggerable agent message counts in both direct and group
90
+ * conversations. An explicit `null` remains the deployer opt-out for trusted,
91
+ * intentionally long-running collaboration.
101
92
  */
102
93
  export declare const DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS = 4;
94
+ export declare const DEFAULT_DIRECT_MAX_CONSECUTIVE_AGENT_TURNS = 4;
103
95
  export declare function parseAgentBehaviorSettings(raw: unknown): AgentBehaviorSettingsRecord;
104
96
  export declare function normalizeStoredAgentBehaviorPolicy(raw: Record<string, unknown> | undefined): AgentBehaviorSettingsRecord | null;
105
97
  export declare function normalizeAgentBehaviorInstructions(value: string | null | undefined): string | null;
106
98
  /**
107
99
  * The scope-independent participation defaults. `maxConsecutiveAgentTurns` is
108
- * `null` here because the turn cap is scope-dependent — a group with no stored
109
- * setting resolves to {@link DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS}. Use
100
+ * `null` here because the turn cap is scope-dependent — a conversation with no
101
+ * stored setting resolves to its direct or group safety default. Use
110
102
  * {@link resolveAgentBehaviorPolicy} with a `conversationType` to learn what a
111
103
  * given conversation actually enforces.
112
104
  */
@@ -114,9 +106,9 @@ export declare function getDefaultParticipationPolicy(): ParticipationPolicy;
114
106
  /**
115
107
  * Coalesce agent defaults and a conversation override into the resolved record
116
108
  * every runtime reads. `conversationType` selects the Canon-wide fallbacks that
117
- * differ per scope — today only the turn cap, which defaults to
118
- * {@link DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS} in groups and to unlimited
119
- * everywhere else. Omit it when resolving for the agent scope (no conversation);
109
+ * differ per scope — today only the turn cap, which defaults to 4 in direct and
110
+ * group conversations and to unlimited elsewhere. Omit it when resolving for
111
+ * the agent scope (no conversation);
120
112
  * an absent or unknown type always resolves to the unlimited default, so a call
121
113
  * site that forgets to thread it can never invent a cap.
122
114
  */
@@ -1,29 +1,25 @@
1
1
  import { shouldTriggerAgentTurn } from './turnProtocol.js';
2
2
  export const PARTICIPATION_HISTORY_FETCH_LIMIT = 50;
3
3
  /**
4
- * Safety backstop for groups with no explicit turn cap: at most this many
5
- * consecutive agent turns before a human has to speak again.
4
+ * Safety backstop for conversations with no explicit turn cap: at most this
5
+ * many consecutive agent turns before a human speaks or a new conversation
6
+ * starts.
6
7
  *
7
8
  * This is a backstop, not the steering wheel — agents are expected to stop on
8
- * their own. Direct conversations deliberately stay unlimited: only a non-agent
9
- * message resets the streak, so a default cap in a pure agent-to-agent DM would
10
- * halt the room permanently instead of merely bounding a loop.
11
- *
12
- * The same caveat applies to the one group shape this default does cover: a
13
- * group whose members are all agents (reachable — agent-created groups need no
14
- * human member) has nothing that resets the streak, so it stops auto-replying
15
- * for good once the cap is reached. That is deliberate: an unattended room is
16
- * where a runaway loop is most expensive. Recovery needs a human member — the
17
- * per-conversation `null` opt-out is writable only by a group owner or admin,
18
- * who must be a member. Teaching the resolver "does this room contain a
19
- * human?" would mean loading member types at every resolution site, including
20
- * the stream gate, which does not read them today.
9
+ * their own. Every triggerable agent message counts in both direct and group
10
+ * conversations. An explicit `null` remains the deployer opt-out for trusted,
11
+ * intentionally long-running collaboration.
21
12
  */
22
13
  export const DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS = 4;
14
+ export const DEFAULT_DIRECT_MAX_CONSECUTIVE_AGENT_TURNS = 4;
23
15
  function defaultMaxConsecutiveAgentTurns(conversationType) {
24
- return conversationType === 'group'
25
- ? DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS
26
- : null;
16
+ if (conversationType === 'group') {
17
+ return DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS;
18
+ }
19
+ if (conversationType === 'direct') {
20
+ return DEFAULT_DIRECT_MAX_CONSECUTIVE_AGENT_TURNS;
21
+ }
22
+ return null;
27
23
  }
28
24
  const VALID_PARTICIPATION_STYLES = new Set([
29
25
  'natural',
@@ -146,8 +142,8 @@ export function normalizeAgentBehaviorInstructions(value) {
146
142
  }
147
143
  /**
148
144
  * The scope-independent participation defaults. `maxConsecutiveAgentTurns` is
149
- * `null` here because the turn cap is scope-dependent — a group with no stored
150
- * setting resolves to {@link DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS}. Use
145
+ * `null` here because the turn cap is scope-dependent — a conversation with no
146
+ * stored setting resolves to its direct or group safety default. Use
151
147
  * {@link resolveAgentBehaviorPolicy} with a `conversationType` to learn what a
152
148
  * given conversation actually enforces.
153
149
  */
@@ -157,9 +153,9 @@ export function getDefaultParticipationPolicy() {
157
153
  /**
158
154
  * Coalesce agent defaults and a conversation override into the resolved record
159
155
  * every runtime reads. `conversationType` selects the Canon-wide fallbacks that
160
- * differ per scope — today only the turn cap, which defaults to
161
- * {@link DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS} in groups and to unlimited
162
- * everywhere else. Omit it when resolving for the agent scope (no conversation);
156
+ * differ per scope — today only the turn cap, which defaults to 4 in direct and
157
+ * group conversations and to unlimited elsewhere. Omit it when resolving for
158
+ * the agent scope (no conversation);
163
159
  * an absent or unknown type always resolves to the unlimited default, so a call
164
160
  * site that forgets to thread it can never invent a cap.
165
161
  */
@@ -0,0 +1,29 @@
1
+ import type { CommunicationRule } from './communication.js';
2
+ /** Shared paging bounds for Canon's discoverable-agent directory. */
3
+ export declare const DEFAULT_DISCOVER_AGENTS_LIMIT = 20;
4
+ export declare const MAX_DISCOVER_AGENTS_LIMIT = 25;
5
+ export declare const MAX_DISCOVER_AGENTS_QUERY_LENGTH = 64;
6
+ export interface DiscoverAgentsInput {
7
+ query?: string;
8
+ limit?: number;
9
+ cursor?: string | null;
10
+ }
11
+ /** Public, addressable identity returned to an authenticated agent caller. */
12
+ export interface CanonAgentDirectoryEntry {
13
+ principalId: string;
14
+ canonContactId?: string;
15
+ displayName?: string;
16
+ description?: string;
17
+ /** Human principal accountable for this agent. */
18
+ owner: {
19
+ principalId: string;
20
+ displayName?: string;
21
+ };
22
+ inboundPolicy?: CommunicationRule;
23
+ groupJoinPolicy?: CommunicationRule;
24
+ shareable: boolean;
25
+ }
26
+ export interface DiscoverAgentsResult {
27
+ agents: CanonAgentDirectoryEntry[];
28
+ nextCursor: string | null;
29
+ }
@@ -0,0 +1,4 @@
1
+ /** Shared paging bounds for Canon's discoverable-agent directory. */
2
+ export const DEFAULT_DISCOVER_AGENTS_LIMIT = 20;
3
+ export const MAX_DISCOVER_AGENTS_LIMIT = 25;
4
+ export const MAX_DISCOVER_AGENTS_QUERY_LENGTH = 64;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS = exports.PARTICIPATION_HISTORY_FETCH_LIMIT = void 0;
3
+ exports.DEFAULT_DIRECT_MAX_CONSECUTIVE_AGENT_TURNS = exports.DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS = exports.PARTICIPATION_HISTORY_FETCH_LIMIT = void 0;
4
4
  exports.parseAgentBehaviorSettings = parseAgentBehaviorSettings;
5
5
  exports.normalizeStoredAgentBehaviorPolicy = normalizeStoredAgentBehaviorPolicy;
6
6
  exports.normalizeAgentBehaviorInstructions = normalizeAgentBehaviorInstructions;
@@ -12,29 +12,25 @@ exports.evaluateParticipationPolicy = evaluateParticipationPolicy;
12
12
  const turnProtocol_js_1 = require("./turnProtocol.js");
13
13
  exports.PARTICIPATION_HISTORY_FETCH_LIMIT = 50;
14
14
  /**
15
- * Safety backstop for groups with no explicit turn cap: at most this many
16
- * consecutive agent turns before a human has to speak again.
15
+ * Safety backstop for conversations with no explicit turn cap: at most this
16
+ * many consecutive agent turns before a human speaks or a new conversation
17
+ * starts.
17
18
  *
18
19
  * This is a backstop, not the steering wheel — agents are expected to stop on
19
- * their own. Direct conversations deliberately stay unlimited: only a non-agent
20
- * message resets the streak, so a default cap in a pure agent-to-agent DM would
21
- * halt the room permanently instead of merely bounding a loop.
22
- *
23
- * The same caveat applies to the one group shape this default does cover: a
24
- * group whose members are all agents (reachable — agent-created groups need no
25
- * human member) has nothing that resets the streak, so it stops auto-replying
26
- * for good once the cap is reached. That is deliberate: an unattended room is
27
- * where a runaway loop is most expensive. Recovery needs a human member — the
28
- * per-conversation `null` opt-out is writable only by a group owner or admin,
29
- * who must be a member. Teaching the resolver "does this room contain a
30
- * human?" would mean loading member types at every resolution site, including
31
- * the stream gate, which does not read them today.
20
+ * their own. Every triggerable agent message counts in both direct and group
21
+ * conversations. An explicit `null` remains the deployer opt-out for trusted,
22
+ * intentionally long-running collaboration.
32
23
  */
33
24
  exports.DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS = 4;
25
+ exports.DEFAULT_DIRECT_MAX_CONSECUTIVE_AGENT_TURNS = 4;
34
26
  function defaultMaxConsecutiveAgentTurns(conversationType) {
35
- return conversationType === 'group'
36
- ? exports.DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS
37
- : null;
27
+ if (conversationType === 'group') {
28
+ return exports.DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS;
29
+ }
30
+ if (conversationType === 'direct') {
31
+ return exports.DEFAULT_DIRECT_MAX_CONSECUTIVE_AGENT_TURNS;
32
+ }
33
+ return null;
38
34
  }
39
35
  const VALID_PARTICIPATION_STYLES = new Set([
40
36
  'natural',
@@ -157,8 +153,8 @@ function normalizeAgentBehaviorInstructions(value) {
157
153
  }
158
154
  /**
159
155
  * The scope-independent participation defaults. `maxConsecutiveAgentTurns` is
160
- * `null` here because the turn cap is scope-dependent — a group with no stored
161
- * setting resolves to {@link DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS}. Use
156
+ * `null` here because the turn cap is scope-dependent — a conversation with no
157
+ * stored setting resolves to its direct or group safety default. Use
162
158
  * {@link resolveAgentBehaviorPolicy} with a `conversationType` to learn what a
163
159
  * given conversation actually enforces.
164
160
  */
@@ -168,9 +164,9 @@ function getDefaultParticipationPolicy() {
168
164
  /**
169
165
  * Coalesce agent defaults and a conversation override into the resolved record
170
166
  * every runtime reads. `conversationType` selects the Canon-wide fallbacks that
171
- * differ per scope — today only the turn cap, which defaults to
172
- * {@link DEFAULT_GROUP_MAX_CONSECUTIVE_AGENT_TURNS} in groups and to unlimited
173
- * everywhere else. Omit it when resolving for the agent scope (no conversation);
167
+ * differ per scope — today only the turn cap, which defaults to 4 in direct and
168
+ * group conversations and to unlimited elsewhere. Omit it when resolving for
169
+ * the agent scope (no conversation);
174
170
  * an absent or unknown type always resolves to the unlimited default, so a call
175
171
  * site that forgets to thread it can never invent a cap.
176
172
  */
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_DISCOVER_AGENTS_QUERY_LENGTH = exports.MAX_DISCOVER_AGENTS_LIMIT = exports.DEFAULT_DISCOVER_AGENTS_LIMIT = void 0;
4
+ /** Shared paging bounds for Canon's discoverable-agent directory. */
5
+ exports.DEFAULT_DISCOVER_AGENTS_LIMIT = 20;
6
+ exports.MAX_DISCOVER_AGENTS_LIMIT = 25;
7
+ exports.MAX_DISCOVER_AGENTS_QUERY_LENGTH = 64;
package/dist/cjs/index.js CHANGED
@@ -24,6 +24,7 @@ __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("./agentDirectory.js"), exports);
27
28
  __exportStar(require("./verbContract.js"), exports);
28
29
  __exportStar(require("./verbSchemas.js"), exports);
29
30
  __exportStar(require("./verbWire.js"), exports);
@@ -1,3 +1,4 @@
1
+ import type { DiscoverAgentsInput, DiscoverAgentsResult } from './agentDirectory.js';
1
2
  /** The deliberately small policy vocabulary for principal communication. */
2
3
  export type CommunicationRule = 'open' | 'approval-required' | 'closed';
3
4
  /** Missing or invalid policy never widens access. */
@@ -11,7 +12,9 @@ export type DirectConversationSelection = {
11
12
  mode: 'specific';
12
13
  conversationId: string;
13
14
  };
14
- export type CommunicateInput = {
15
+ export type CommunicateInput = ({
16
+ action: 'discover_agents';
17
+ } & DiscoverAgentsInput) | {
15
18
  action: 'message_existing';
16
19
  conversationId: string;
17
20
  text: string;
@@ -44,7 +47,9 @@ export type CommunicateInput = {
44
47
  userId: string;
45
48
  operation: 'add' | 'remove';
46
49
  };
47
- export type CommunicateResult = {
50
+ export type CommunicateResult = ({
51
+ status: 'discovered';
52
+ } & DiscoverAgentsResult) | {
48
53
  status: 'messaged';
49
54
  conversationId: string;
50
55
  messageId: string;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './runtimeCardStorage.js';
8
8
  export * from './turnProtocol.js';
9
9
  export * from './agentBehaviorPolicy.js';
10
10
  export * from './agentSearch.js';
11
+ export * from './agentDirectory.js';
11
12
  export * from './verbContract.js';
12
13
  export * from './verbSchemas.js';
13
14
  export * from './verbWire.js';
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './runtimeCardStorage.js';
8
8
  export * from './turnProtocol.js';
9
9
  export * from './agentBehaviorPolicy.js';
10
10
  export * from './agentSearch.js';
11
+ export * from './agentDirectory.js';
11
12
  export * from './verbContract.js';
12
13
  export * from './verbSchemas.js';
13
14
  export * from './verbWire.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/backend-contracts",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "Canon backend contract helpers shared by Functions and stream-service",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",