@canonmsg/backend-contracts 1.9.0 → 2.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.
Files changed (201) hide show
  1. package/dist/agentBehaviorPolicy.d.ts +45 -86
  2. package/dist/agentBehaviorPolicy.js +0 -53
  3. package/dist/cjs/agentBehaviorPolicy.js +1 -54
  4. package/dist/cjs/contactRequest.js +0 -30
  5. package/dist/cjs/diffRedaction.js +73 -0
  6. package/dist/cjs/index.js +1 -8
  7. package/dist/cjs/media.js +0 -13
  8. package/dist/cjs/message.js +44 -65
  9. package/dist/cjs/runtimeCardFields.js +1 -58
  10. package/dist/cjs/turnProtocol.js +1 -41
  11. package/dist/contactRequest.d.ts +23 -42
  12. package/dist/contactRequest.js +0 -29
  13. package/dist/diffRedaction.d.ts +6 -0
  14. package/dist/diffRedaction.js +68 -0
  15. package/dist/index.d.ts +1 -8
  16. package/dist/index.js +1 -8
  17. package/dist/media.d.ts +11 -24
  18. package/dist/media.js +0 -12
  19. package/dist/message.d.ts +79 -132
  20. package/dist/message.js +45 -65
  21. package/dist/runtimeCardFields.d.ts +39 -112
  22. package/dist/runtimeCardFields.js +0 -57
  23. package/dist/turnProtocol.d.ts +24 -91
  24. package/dist/turnProtocol.js +0 -40
  25. package/package.json +5 -8
  26. package/dist/bridgeLocal.d.ts +0 -1871
  27. package/dist/bridgeLocal.js +0 -744
  28. package/dist/cjs/bridgeLocal.js +0 -747
  29. package/dist/cjs/controlSignals.js +0 -44
  30. package/dist/cjs/endpointRegistry.js +0 -264
  31. package/dist/cjs/hitl.js +0 -171
  32. package/dist/cjs/inboundFrame.js +0 -92
  33. package/dist/cjs/restEndpoints.js +0 -237
  34. package/dist/cjs/sendContextual.js +0 -92
  35. package/dist/cjs/sseEvents.js +0 -281
  36. package/dist/controlSignals.d.ts +0 -55
  37. package/dist/controlSignals.js +0 -41
  38. package/dist/endpointRegistry.d.ts +0 -13
  39. package/dist/endpointRegistry.js +0 -261
  40. package/dist/hitl.d.ts +0 -303
  41. package/dist/hitl.js +0 -168
  42. package/dist/inboundFrame.d.ts +0 -229
  43. package/dist/inboundFrame.js +0 -89
  44. package/dist/restEndpoints.d.ts +0 -531
  45. package/dist/restEndpoints.js +0 -234
  46. package/dist/schemas/agent-behavior-settings-record.schema.json +0 -48
  47. package/dist/schemas/bridge-connection-state-notification.schema.json +0 -19
  48. package/dist/schemas/bridge-get-attachment-params.schema.json +0 -24
  49. package/dist/schemas/bridge-get-attachment-result.schema.json +0 -20
  50. package/dist/schemas/bridge-hello-params.schema.json +0 -42
  51. package/dist/schemas/bridge-hello-result.schema.json +0 -105
  52. package/dist/schemas/bridge-hitl-state.schema.json +0 -38
  53. package/dist/schemas/bridge-ok-result.schema.json +0 -15
  54. package/dist/schemas/bridge-publish-streaming-event-params.schema.json +0 -138
  55. package/dist/schemas/bridge-ready-notification.schema.json +0 -79
  56. package/dist/schemas/bridge-resync-reason.schema.json +0 -9
  57. package/dist/schemas/bridge-resync.schema.json +0 -18
  58. package/dist/schemas/bridge-rpc-error.schema.json +0 -19
  59. package/dist/schemas/bridge-rpc-id.schema.json +0 -12
  60. package/dist/schemas/bridge-rpc-notification.schema.json +0 -20
  61. package/dist/schemas/bridge-rpc-request.schema.json +0 -31
  62. package/dist/schemas/bridge-rpc-response.schema.json +0 -81
  63. package/dist/schemas/bridge-status-result.schema.json +0 -76
  64. package/dist/schemas/bridge-stream-clear-event.schema.json +0 -15
  65. package/dist/schemas/bridge-stream-event.schema.json +0 -112
  66. package/dist/schemas/bridge-stream-final-event.schema.json +0 -19
  67. package/dist/schemas/bridge-stream-text-event.schema.json +0 -31
  68. package/dist/schemas/bridge-stream-thinking-event.schema.json +0 -15
  69. package/dist/schemas/bridge-stream-tool-event.schema.json +0 -36
  70. package/dist/schemas/bridge-upload-media-params.schema.json +0 -28
  71. package/dist/schemas/bridge-upstream-state.schema.json +0 -10
  72. package/dist/schemas/contacts-response.schema.json +0 -52
  73. package/dist/schemas/control-channel-key.schema.json +0 -10
  74. package/dist/schemas/control-primitive-event.schema.json +0 -30
  75. package/dist/schemas/control-primitive-map.schema.json +0 -15
  76. package/dist/schemas/control-session-event.schema.json +0 -26
  77. package/dist/schemas/control-session-node.schema.json +0 -11
  78. package/dist/schemas/control-signal-event.schema.json +0 -35
  79. package/dist/schemas/control-signal-node.schema.json +0 -22
  80. package/dist/schemas/control-signal-type.schema.json +0 -10
  81. package/dist/schemas/conversations-response.schema.json +0 -167
  82. package/dist/schemas/create-contact-request-request.schema.json +0 -17
  83. package/dist/schemas/create-contact-request-response.schema.json +0 -51
  84. package/dist/schemas/create-conversation-request.schema.json +0 -82
  85. package/dist/schemas/create-conversation-response.schema.json +0 -29
  86. package/dist/schemas/delete-message-response.schema.json +0 -11
  87. package/dist/schemas/delivery-intent.schema.json +0 -11
  88. package/dist/schemas/forward-message-request.schema.json +0 -25
  89. package/dist/schemas/forward-message-response.schema.json +0 -35
  90. package/dist/schemas/forwarded-from.schema.json +0 -18
  91. package/dist/schemas/get-messages-query.schema.json +0 -17
  92. package/dist/schemas/hitl-approval-category.schema.json +0 -15
  93. package/dist/schemas/hitl-approval-detail.schema.json +0 -21
  94. package/dist/schemas/hitl-approval-outcome-record.schema.json +0 -33
  95. package/dist/schemas/hitl-approval-reply-record.schema.json +0 -57
  96. package/dist/schemas/hitl-approval-request-record.schema.json +0 -105
  97. package/dist/schemas/hitl-approval-risk.schema.json +0 -11
  98. package/dist/schemas/hitl-card-outcome-record.schema.json +0 -48
  99. package/dist/schemas/hitl-card-reply-record.schema.json +0 -46
  100. package/dist/schemas/hitl-card-request-record.schema.json +0 -73
  101. package/dist/schemas/hitl-input-answers.schema.json +0 -23
  102. package/dist/schemas/hitl-input-kind.schema.json +0 -10
  103. package/dist/schemas/hitl-input-outcome-record.schema.json +0 -46
  104. package/dist/schemas/hitl-input-question.schema.json +0 -54
  105. package/dist/schemas/hitl-input-reply-record.schema.json +0 -44
  106. package/dist/schemas/hitl-input-request-record.schema.json +0 -134
  107. package/dist/schemas/hitl-pending.schema.json +0 -31
  108. package/dist/schemas/hitl-request-accepted.schema.json +0 -18
  109. package/dist/schemas/hitl-request-kind.schema.json +0 -10
  110. package/dist/schemas/hitl-resolution-status.schema.json +0 -10
  111. package/dist/schemas/hitl-resolution.schema.json +0 -38
  112. package/dist/schemas/hitl-session-rule.schema.json +0 -32
  113. package/dist/schemas/inbound-disposition.schema.json +0 -13
  114. package/dist/schemas/inbound-frame-attachment-v1.schema.json +0 -94
  115. package/dist/schemas/inbound-frame-contact-card-v1.schema.json +0 -59
  116. package/dist/schemas/inbound-frame-group-context-v1.schema.json +0 -96
  117. package/dist/schemas/inbound-frame-reply-context-v1.schema.json +0 -261
  118. package/dist/schemas/inbound-frame-shape-v1.schema.json +0 -12
  119. package/dist/schemas/inbound-frame-v1.schema.json +0 -506
  120. package/dist/schemas/mark-read-response.schema.json +0 -11
  121. package/dist/schemas/media-attachment-kind.schema.json +0 -11
  122. package/dist/schemas/media-attachment.schema.json +0 -42
  123. package/dist/schemas/messages-page-response.schema.json +0 -290
  124. package/dist/schemas/participation-decision-input.schema.json +0 -44
  125. package/dist/schemas/participation-history-message.schema.json +0 -23
  126. package/dist/schemas/participation-history-snapshot.schema.json +0 -37
  127. package/dist/schemas/participation-style.schema.json +0 -13
  128. package/dist/schemas/react-request.schema.json +0 -22
  129. package/dist/schemas/react-response.schema.json +0 -35
  130. package/dist/schemas/resolve-admission-request.schema.json +0 -30
  131. package/dist/schemas/resolve-admission-response.schema.json +0 -129
  132. package/dist/schemas/resolved-agent-behavior-policy-record.schema.json +0 -81
  133. package/dist/schemas/rest-contact.schema.json +0 -40
  134. package/dist/schemas/rest-conversation-last-message.schema.json +0 -77
  135. package/dist/schemas/rest-conversation.schema.json +0 -155
  136. package/dist/schemas/rest-message.schema.json +0 -252
  137. package/dist/schemas/rest-ok-response.schema.json +0 -11
  138. package/dist/schemas/rest-session-selection.schema.json +0 -40
  139. package/dist/schemas/runtime-card-field-choice.schema.json +0 -23
  140. package/dist/schemas/runtime-card-field-type.schema.json +0 -17
  141. package/dist/schemas/runtime-card-field.schema.json +0 -180
  142. package/dist/schemas/runtime-card-line-item-column-type.schema.json +0 -12
  143. package/dist/schemas/runtime-card-line-item-column.schema.json +0 -74
  144. package/dist/schemas/send-contextual-deferred-response.schema.json +0 -39
  145. package/dist/schemas/send-contextual-messaged-response.schema.json +0 -42
  146. package/dist/schemas/send-contextual-request.schema.json +0 -103
  147. package/dist/schemas/send-contextual-response.schema.json +0 -105
  148. package/dist/schemas/send-contextual-self-context.schema.json +0 -19
  149. package/dist/schemas/send-contextual-state-response.schema.json +0 -24
  150. package/dist/schemas/send-message-request.schema.json +0 -106
  151. package/dist/schemas/send-message-response.schema.json +0 -14
  152. package/dist/schemas/sender-type.schema.json +0 -9
  153. package/dist/schemas/serialize-message-input.schema.json +0 -29
  154. package/dist/schemas/serialized-agent-client-type.schema.json +0 -12
  155. package/dist/schemas/serialized-contact-card.schema.json +0 -65
  156. package/dist/schemas/serialized-contact-request-status.schema.json +0 -11
  157. package/dist/schemas/serialized-contact-request.schema.json +0 -157
  158. package/dist/schemas/serialized-content-type.schema.json +0 -13
  159. package/dist/schemas/serialized-message.schema.json +0 -249
  160. package/dist/schemas/serialized-reactions.schema.json +0 -14
  161. package/dist/schemas/serialized-sender-type.schema.json +0 -9
  162. package/dist/schemas/set-streaming-request.schema.json +0 -67
  163. package/dist/schemas/set-typing-request.schema.json +0 -25
  164. package/dist/schemas/sse-access-policy.schema.json +0 -10
  165. package/dist/schemas/sse-agent-context-payload.schema.json +0 -57
  166. package/dist/schemas/sse-connected-payload.schema.json +0 -18
  167. package/dist/schemas/sse-contact-payload.schema.json +0 -40
  168. package/dist/schemas/sse-contact-removed-payload.schema.json +0 -14
  169. package/dist/schemas/sse-contact-request-payload.schema.json +0 -157
  170. package/dist/schemas/sse-conversation-updated-payload.schema.json +0 -48
  171. package/dist/schemas/sse-error-payload.schema.json +0 -23
  172. package/dist/schemas/sse-event-envelope.schema.json +0 -40
  173. package/dist/schemas/sse-event-family.schema.json +0 -12
  174. package/dist/schemas/sse-event-type.schema.json +0 -26
  175. package/dist/schemas/sse-heartbeat-payload.schema.json +0 -14
  176. package/dist/schemas/sse-membership-change.schema.json +0 -28
  177. package/dist/schemas/sse-message-created-payload.schema.json +0 -414
  178. package/dist/schemas/sse-message-deleted-payload.schema.json +0 -18
  179. package/dist/schemas/sse-message-updated-payload.schema.json +0 -46
  180. package/dist/schemas/sse-presence-payload.schema.json +0 -21
  181. package/dist/schemas/sse-provenance.schema.json +0 -64
  182. package/dist/schemas/sse-replay-expired-payload.schema.json +0 -21
  183. package/dist/schemas/sse-runtime-control-kind.schema.json +0 -13
  184. package/dist/schemas/sse-runtime-control-payload.schema.json +0 -44
  185. package/dist/schemas/sse-self-context.schema.json +0 -45
  186. package/dist/schemas/sse-turn-dispatch.schema.json +0 -29
  187. package/dist/schemas/sse-typing-payload.schema.json +0 -32
  188. package/dist/schemas/sse-voice-session-event-payload.schema.json +0 -170
  189. package/dist/schemas/sse-voice-session.schema.json +0 -157
  190. package/dist/schemas/trigger-decision.schema.json +0 -27
  191. package/dist/schemas/turn-lifecycle-state.schema.json +0 -14
  192. package/dist/schemas/turn-message-semantics.schema.json +0 -10
  193. package/dist/schemas/turn-metadata.schema.json +0 -56
  194. package/dist/schemas/turn-state-like.schema.json +0 -39
  195. package/dist/schemas/update-disposition-request.schema.json +0 -22
  196. package/dist/schemas/upload-media-request.schema.json +0 -25
  197. package/dist/schemas/upload-media-response.schema.json +0 -55
  198. package/dist/sendContextual.d.ts +0 -114
  199. package/dist/sendContextual.js +0 -89
  200. package/dist/sseEvents.d.ts +0 -474
  201. package/dist/sseEvents.js +0 -278
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WAITING_INPUT_STALE_THRESHOLD_MS = exports.ACTIVE_TURN_STALE_THRESHOLD_MS = exports.TurnStateLikeSchema = exports.TriggerDecisionSchema = exports.TurnMetadataSchema = exports.InboundDispositionSchema = exports.DeliveryIntentSchema = exports.TurnMessageSemanticsSchema = exports.TurnLifecycleStateSchema = exports.SenderTypeSchema = void 0;
3
+ exports.WAITING_INPUT_STALE_THRESHOLD_MS = exports.ACTIVE_TURN_STALE_THRESHOLD_MS = void 0;
4
4
  exports.normalizeTurnMetadata = normalizeTurnMetadata;
5
5
  exports.isTurnOpen = isTurnOpen;
6
6
  exports.getTurnStateStaleThresholdMs = getTurnStateStaleThresholdMs;
@@ -9,46 +9,6 @@ exports.resolveTurnMessageSemantics = resolveTurnMessageSemantics;
9
9
  exports.shouldPromoteConversationMessage = shouldPromoteConversationMessage;
10
10
  exports.shouldTriggerAgentTurn = shouldTriggerAgentTurn;
11
11
  exports.normalizeRuntimeTurnState = normalizeRuntimeTurnState;
12
- const zod_1 = require("zod");
13
- exports.SenderTypeSchema = zod_1.z.enum(['human', 'ai_agent']);
14
- exports.TurnLifecycleStateSchema = zod_1.z.enum([
15
- 'idle',
16
- 'thinking',
17
- 'streaming',
18
- 'tool',
19
- 'waiting_input',
20
- 'completed',
21
- 'interrupted',
22
- ]);
23
- exports.TurnMessageSemanticsSchema = zod_1.z.enum(['progress', 'turn_complete', 'control']);
24
- exports.DeliveryIntentSchema = zod_1.z.enum(['queue', 'interrupt', 'interleave', 'stop']);
25
- exports.InboundDispositionSchema = zod_1.z.enum([
26
- 'queued',
27
- 'accepted_now',
28
- 'interleaved',
29
- 'trigger_suppressed',
30
- 'rejected',
31
- 'cancelled',
32
- ]);
33
- exports.TurnMetadataSchema = zod_1.z.object({
34
- turnId: zod_1.z.string().nullable().optional(),
35
- turnSemantics: exports.TurnMessageSemanticsSchema.optional(),
36
- deliveryIntent: exports.DeliveryIntentSchema.optional(),
37
- replyBehavior: zod_1.z.enum(['allow_auto_reply', 'suppress_auto_reply']).optional(),
38
- inboundDisposition: exports.InboundDispositionSchema.optional(),
39
- requestedTurnMode: zod_1.z.string().optional(),
40
- });
41
- exports.TriggerDecisionSchema = zod_1.z.object({
42
- allow: zod_1.z.boolean(),
43
- semantics: exports.TurnMessageSemanticsSchema,
44
- reason: zod_1.z.string(),
45
- });
46
- exports.TurnStateLikeSchema = zod_1.z.object({
47
- state: exports.TurnLifecycleStateSchema,
48
- openedAt: zod_1.z.number().optional(),
49
- updatedAt: zod_1.z.number().optional(),
50
- turnUpdatedAt: zod_1.z.number().nullable().optional(),
51
- });
52
12
  exports.ACTIVE_TURN_STALE_THRESHOLD_MS = 30 * 60 * 1000;
53
13
  exports.WAITING_INPUT_STALE_THRESHOLD_MS = 12 * 60 * 60 * 1000;
54
14
  const TURN_SEMANTICS = [
@@ -1,43 +1,24 @@
1
- import { z } from 'zod';
2
- export declare const SerializedContactRequestStatusSchema: z.ZodEnum<{
3
- rejected: "rejected";
4
- pending: "pending";
5
- approved: "approved";
6
- expired: "expired";
7
- }>;
8
- export type SerializedContactRequestStatus = z.infer<typeof SerializedContactRequestStatusSchema>;
9
- export declare const SerializedContactRequestSchema: z.ZodObject<{
10
- id: z.ZodString;
11
- requesterId: z.ZodString;
12
- requesterName: z.ZodString;
13
- requesterAvatarUrl: z.ZodNullable<z.ZodString>;
14
- targetId: z.ZodString;
15
- targetName: z.ZodString;
16
- targetAvatarUrl: z.ZodNullable<z.ZodString>;
17
- targetUserType: z.ZodEnum<{
18
- human: "human";
19
- ai_agent: "ai_agent";
20
- }>;
21
- targetOwnerId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
- approverId: z.ZodString;
23
- message: z.ZodNullable<z.ZodString>;
24
- status: z.ZodEnum<{
25
- rejected: "rejected";
26
- pending: "pending";
27
- approved: "approved";
28
- expired: "expired";
29
- }>;
30
- kind: z.ZodEnum<{
31
- dm: "dm";
32
- group_invite: "group_invite";
33
- }>;
34
- groupContext: z.ZodOptional<z.ZodObject<{
35
- conversationId: z.ZodString;
36
- groupName: z.ZodNullable<z.ZodString>;
37
- }, z.core.$strip>>;
38
- createdAt: z.ZodNullable<z.ZodString>;
39
- resolvedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
40
- expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
41
- }, z.core.$strip>;
42
- export type SerializedContactRequest = z.infer<typeof SerializedContactRequestSchema>;
1
+ export type SerializedContactRequestStatus = 'pending' | 'approved' | 'rejected' | 'expired';
2
+ export interface SerializedContactRequest {
3
+ id: string;
4
+ requesterId: string;
5
+ requesterName: string;
6
+ requesterAvatarUrl: string | null;
7
+ targetId: string;
8
+ targetName: string;
9
+ targetAvatarUrl: string | null;
10
+ targetUserType: 'human' | 'ai_agent';
11
+ targetOwnerId?: string | null;
12
+ approverId: string;
13
+ message: string | null;
14
+ status: SerializedContactRequestStatus;
15
+ kind: 'dm' | 'group_invite';
16
+ groupContext?: {
17
+ conversationId: string;
18
+ groupName: string | null;
19
+ };
20
+ createdAt: string | null;
21
+ resolvedAt?: string | null;
22
+ expiresAt?: string | null;
23
+ }
43
24
  export declare function serializeContactRequest(requestId: string, data: Record<string, unknown>): SerializedContactRequest | null;
@@ -1,32 +1,3 @@
1
- import { z } from 'zod';
2
- export const SerializedContactRequestStatusSchema = z.enum([
3
- 'pending',
4
- 'approved',
5
- 'rejected',
6
- 'expired',
7
- ]);
8
- export const SerializedContactRequestSchema = z.object({
9
- id: z.string(),
10
- requesterId: z.string(),
11
- requesterName: z.string(),
12
- requesterAvatarUrl: z.string().nullable(),
13
- targetId: z.string(),
14
- targetName: z.string(),
15
- targetAvatarUrl: z.string().nullable(),
16
- targetUserType: z.enum(['human', 'ai_agent']),
17
- targetOwnerId: z.string().nullable().optional(),
18
- approverId: z.string(),
19
- message: z.string().nullable(),
20
- status: SerializedContactRequestStatusSchema,
21
- kind: z.enum(['dm', 'group_invite']),
22
- groupContext: z.object({
23
- conversationId: z.string(),
24
- groupName: z.string().nullable(),
25
- }).optional(),
26
- createdAt: z.string().nullable(),
27
- resolvedAt: z.string().nullable().optional(),
28
- expiresAt: z.string().nullable().optional(),
29
- });
30
1
  function isRecord(value) {
31
2
  return typeof value === 'object' && value !== null && !Array.isArray(value);
32
3
  }
@@ -0,0 +1,6 @@
1
+ /** Matches the header line of a PEM private-key block. */
2
+ export declare const PRIVATE_KEY_BLOCK: RegExp;
3
+ /** True when a diff file path (or rename source) matches the sensitive list. */
4
+ export declare function isSensitiveDiffPath(path: string): boolean;
5
+ /** Replace high-confidence credential shapes inside hunk text with `[redacted]`. */
6
+ export declare function redactSecretTokens(text: string): string;
@@ -0,0 +1,68 @@
1
+ // Sensitive-content protection for approval diffs.
2
+ //
3
+ // Approval diffs include PRE-IMAGE context lines and ride on a message readable
4
+ // by every conversation member, so a secret-bearing file would leak existing
5
+ // secrets. The emitting host applies this before sending (it owns the file
6
+ // context); the server (@canonmsg/functions) mirrors the same suppression
7
+ // defensively. Single-sourced here in the zero-dependency backend-contracts
8
+ // leaf so @canonmsg/core (client-side sanitizer) and Functions (server mirror)
9
+ // share one implementation — Functions deliberately does not depend on core.
10
+ //
11
+ // Two deliberately narrow mechanisms so ordinary code diffs stay readable:
12
+ // 1. Path suppression — files whose path screams "secret store" lose their
13
+ // hunk text entirely; entry/status/counts survive.
14
+ // 2. High-confidence token redaction — prefix-anchored credential shapes
15
+ // (AWS/GitHub/Slack/Google/OpenAI-style keys, JWTs) are replaced with
16
+ // `[redacted]` inside remaining hunks. Private-key blocks suppress the
17
+ // whole file (redacting a PEM body line-by-line is fragile).
18
+ const SENSITIVE_DIFF_BASENAME_PATTERNS = [
19
+ /^\.env(\..+)?$/i,
20
+ /^\.npmrc$/i,
21
+ /^\.netrc$/i,
22
+ /^\.pgpass$/i,
23
+ /^\.git-credentials$/i,
24
+ /^\.htpasswd$/i,
25
+ /\.(pem|key|p12|pfx|keystore|jks|tfvars)$/i,
26
+ /^id_(rsa|dsa|ecdsa|ed25519)(\..+)?$/i,
27
+ // Word-bounded so "secrets.json" and "client_secret.yaml" match but
28
+ // "secretary.ts" does not.
29
+ /(^|[-_.])(credentials?|secrets?)([-_.]|$)/i,
30
+ /^serviceaccount.*\.json$/i,
31
+ /^kubeconfig(\..+)?$/i,
32
+ ];
33
+ // Directory components that mark everything beneath them sensitive
34
+ // (~/.ssh/config, .aws/credentials, infra/secrets/db.yaml, …).
35
+ const SENSITIVE_DIFF_SEGMENT_PATTERNS = [
36
+ /^\.ssh$/i,
37
+ /^\.aws$/i,
38
+ /^\.gnupg$/i,
39
+ /^\.kube$/i,
40
+ /^secrets?$/i,
41
+ /^credentials?$/i,
42
+ ];
43
+ const SECRET_TOKEN_PATTERNS = [
44
+ /AKIA[0-9A-Z]{16}/g,
45
+ /gh[pousr]_[A-Za-z0-9]{36,255}/g,
46
+ /github_pat_[A-Za-z0-9_]{22,255}/g,
47
+ /xox[baprs]-[A-Za-z0-9-]{10,250}/g,
48
+ /AIza[0-9A-Za-z_-]{35}/g,
49
+ /sk-[A-Za-z0-9_-]{20,250}/g,
50
+ /eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
51
+ ];
52
+ /** Matches the header line of a PEM private-key block. */
53
+ export const PRIVATE_KEY_BLOCK = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----/;
54
+ /** True when a diff file path (or rename source) matches the sensitive list. */
55
+ export function isSensitiveDiffPath(path) {
56
+ const segments = path.split('/').filter(Boolean);
57
+ const basename = segments.pop() ?? path;
58
+ return SENSITIVE_DIFF_BASENAME_PATTERNS.some((pattern) => pattern.test(basename))
59
+ || segments.some((segment) => SENSITIVE_DIFF_SEGMENT_PATTERNS.some((pattern) => pattern.test(segment)));
60
+ }
61
+ /** Replace high-confidence credential shapes inside hunk text with `[redacted]`. */
62
+ export function redactSecretTokens(text) {
63
+ let redacted = text;
64
+ for (const pattern of SECRET_TOKEN_PATTERNS) {
65
+ redacted = redacted.replace(pattern, '[redacted]');
66
+ }
67
+ return redacted;
68
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './diffRedaction.js';
1
2
  export * from './media.js';
2
3
  export * from './message.js';
3
4
  export * from './runtimeCardFields.js';
@@ -5,11 +6,3 @@ export * from './runtimeCardStorage.js';
5
6
  export * from './turnProtocol.js';
6
7
  export * from './agentBehaviorPolicy.js';
7
8
  export * from './contactRequest.js';
8
- export * from './sseEvents.js';
9
- export * from './controlSignals.js';
10
- export * from './hitl.js';
11
- export * from './inboundFrame.js';
12
- export * from './restEndpoints.js';
13
- export * from './sendContextual.js';
14
- export * from './bridgeLocal.js';
15
- export * from './endpointRegistry.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './diffRedaction.js';
1
2
  export * from './media.js';
2
3
  export * from './message.js';
3
4
  export * from './runtimeCardFields.js';
@@ -5,11 +6,3 @@ export * from './runtimeCardStorage.js';
5
6
  export * from './turnProtocol.js';
6
7
  export * from './agentBehaviorPolicy.js';
7
8
  export * from './contactRequest.js';
8
- export * from './sseEvents.js';
9
- export * from './controlSignals.js';
10
- export * from './hitl.js';
11
- export * from './inboundFrame.js';
12
- export * from './restEndpoints.js';
13
- export * from './sendContextual.js';
14
- export * from './bridgeLocal.js';
15
- export * from './endpointRegistry.js';
package/dist/media.d.ts CHANGED
@@ -1,27 +1,14 @@
1
- import { z } from 'zod';
2
- export declare const MediaAttachmentKindSchema: z.ZodEnum<{
3
- file: "file";
4
- image: "image";
5
- audio: "audio";
6
- video: "video";
7
- }>;
8
- export type MediaAttachmentKind = z.infer<typeof MediaAttachmentKindSchema>;
9
- export declare const MediaAttachmentSchema: z.ZodObject<{
10
- kind: z.ZodEnum<{
11
- file: "file";
12
- image: "image";
13
- audio: "audio";
14
- video: "video";
15
- }>;
16
- url: z.ZodString;
17
- mimeType: z.ZodOptional<z.ZodString>;
18
- fileName: z.ZodOptional<z.ZodString>;
19
- sizeBytes: z.ZodOptional<z.ZodNumber>;
20
- width: z.ZodOptional<z.ZodNumber>;
21
- height: z.ZodOptional<z.ZodNumber>;
22
- durationMs: z.ZodOptional<z.ZodNumber>;
23
- }, z.core.$strip>;
24
- export type MediaAttachment = z.infer<typeof MediaAttachmentSchema>;
1
+ export type MediaAttachmentKind = 'image' | 'audio' | 'video' | 'file';
2
+ export interface MediaAttachment {
3
+ kind: MediaAttachmentKind;
4
+ url: string;
5
+ mimeType?: string;
6
+ fileName?: string;
7
+ sizeBytes?: number;
8
+ width?: number;
9
+ height?: number;
10
+ durationMs?: number;
11
+ }
25
12
  export declare function inferMediaAttachmentKind(mimeType: string): MediaAttachmentKind;
26
13
  export declare function getStoredFileExtension(input: {
27
14
  mimeType?: string | null;
package/dist/media.js CHANGED
@@ -1,15 +1,3 @@
1
- import { z } from 'zod';
2
- export const MediaAttachmentKindSchema = z.enum(['image', 'audio', 'video', 'file']);
3
- export const MediaAttachmentSchema = z.object({
4
- kind: MediaAttachmentKindSchema,
5
- url: z.string(),
6
- mimeType: z.string().optional(),
7
- fileName: z.string().optional(),
8
- sizeBytes: z.number().optional(),
9
- width: z.number().optional(),
10
- height: z.number().optional(),
11
- durationMs: z.number().optional(),
12
- });
13
1
  export function inferMediaAttachmentKind(mimeType) {
14
2
  if (mimeType.startsWith('image/'))
15
3
  return 'image';
package/dist/message.d.ts CHANGED
@@ -1,134 +1,81 @@
1
- import { z } from 'zod';
2
- export declare const SerializedSenderTypeSchema: z.ZodEnum<{
3
- human: "human";
4
- ai_agent: "ai_agent";
5
- }>;
6
- export type SerializedSenderType = z.infer<typeof SerializedSenderTypeSchema>;
7
- export declare const SerializedAgentClientTypeSchema: z.ZodEnum<{
8
- "claude-code": "claude-code";
9
- openclaw: "openclaw";
10
- codex: "codex";
11
- hermes: "hermes";
12
- generic: "generic";
13
- }>;
14
- export type SerializedAgentClientType = z.infer<typeof SerializedAgentClientTypeSchema>;
15
- export declare const SerializedContentTypeSchema: z.ZodEnum<{
16
- file: "file";
17
- image: "image";
18
- audio: "audio";
19
- video: "video";
20
- text: "text";
21
- contact_card: "contact_card";
22
- }>;
23
- export type SerializedContentType = z.infer<typeof SerializedContentTypeSchema>;
24
- export declare const ForwardedFromSchema: z.ZodObject<{
25
- sourceConversationId: z.ZodString;
26
- messageId: z.ZodString;
27
- }, z.core.$strip>;
28
- export type ForwardedFrom = z.infer<typeof ForwardedFromSchema>;
29
- export declare const SerializedReactionsSchema: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
30
- export type SerializedReactions = z.infer<typeof SerializedReactionsSchema>;
31
- export declare const SerializedContactCardSchema: z.ZodObject<{
32
- userId: z.ZodString;
33
- canonContactId: z.ZodOptional<z.ZodString>;
34
- displayName: z.ZodString;
35
- avatarUrl: z.ZodNullable<z.ZodString>;
36
- userType: z.ZodEnum<{
37
- human: "human";
38
- ai_agent: "ai_agent";
39
- }>;
40
- clientType: z.ZodOptional<z.ZodEnum<{
41
- "claude-code": "claude-code";
42
- openclaw: "openclaw";
43
- codex: "codex";
44
- hermes: "hermes";
45
- generic: "generic";
46
- }>>;
47
- about: z.ZodOptional<z.ZodString>;
48
- isActive: z.ZodOptional<z.ZodBoolean>;
49
- ownerId: z.ZodOptional<z.ZodString>;
50
- ownerName: z.ZodOptional<z.ZodString>;
51
- lifecycleState: z.ZodOptional<z.ZodString>;
52
- }, z.core.$strip>;
53
- export type SerializedContactCard = z.infer<typeof SerializedContactCardSchema>;
54
- export declare const SerializedMessageSchema: z.ZodObject<{
55
- id: z.ZodString;
56
- senderId: z.ZodString;
57
- senderName: z.ZodOptional<z.ZodString>;
58
- senderType: z.ZodEnum<{
59
- human: "human";
60
- ai_agent: "ai_agent";
61
- }>;
62
- isOwner: z.ZodBoolean;
63
- contentType: z.ZodEnum<{
64
- file: "file";
65
- image: "image";
66
- audio: "audio";
67
- video: "video";
68
- text: "text";
69
- contact_card: "contact_card";
70
- }>;
71
- text: z.ZodNullable<z.ZodString>;
72
- attachments: z.ZodArray<z.ZodObject<{
73
- kind: z.ZodEnum<{
74
- file: "file";
75
- image: "image";
76
- audio: "audio";
77
- video: "video";
1
+ import { MediaAttachment } from './media.js';
2
+ export type SerializedSenderType = 'human' | 'ai_agent';
3
+ export type SerializedAgentClientType = 'claude-code' | 'openclaw' | 'codex' | 'hermes' | 'generic';
4
+ export type SerializedContentType = 'text' | 'image' | 'audio' | 'video' | 'file' | 'contact_card' | 'interaction';
5
+ export interface ForwardedFrom {
6
+ sourceConversationId: string;
7
+ messageId: string;
8
+ }
9
+ export type SerializedReactions = Record<string, string[]>;
10
+ export interface SerializedContactCard {
11
+ userId: string;
12
+ canonContactId?: string;
13
+ displayName: string;
14
+ avatarUrl: string | null;
15
+ userType: SerializedSenderType;
16
+ clientType?: SerializedAgentClientType;
17
+ about?: string;
18
+ isActive?: boolean;
19
+ ownerId?: string;
20
+ ownerName?: string;
21
+ lifecycleState?: string;
22
+ }
23
+ export interface SerializedMessage {
24
+ id: string;
25
+ senderId: string;
26
+ senderName?: string;
27
+ senderType: SerializedSenderType;
28
+ isOwner: boolean;
29
+ contentType: SerializedContentType;
30
+ text: string | null;
31
+ attachments: MediaAttachment[];
32
+ mentions: string[];
33
+ replyTo: string | null;
34
+ replyToPosition: number | null;
35
+ forwarded?: boolean;
36
+ forwardedFrom?: ForwardedFrom;
37
+ status: 'sent' | 'read';
38
+ createdAt: string;
39
+ metadata?: Record<string, unknown>;
40
+ contactCard?: SerializedContactCard;
41
+ /** Durable canon.card.v1 runtime card content, passed through opaquely. */
42
+ runtimeCard?: Record<string, unknown>;
43
+ /**
44
+ * Plaintext, server-authorized interaction envelope for `contentType:
45
+ * 'interaction'` messages (card / input / approval / plan / contact). The
46
+ * authorization contract (`response`) and preview live here; the opaque
47
+ * request payload rides in `body`.
48
+ */
49
+ interaction?: SerializedInteraction;
50
+ /** Opaque interaction payload (JSON string or ciphertext); never parsed here. */
51
+ body?: string;
52
+ reactions?: SerializedReactions;
53
+ }
54
+ export type SerializedInteractionKind = 'contact' | 'approval' | 'input' | 'plan' | 'card';
55
+ export interface SerializedInteraction {
56
+ kind: SerializedInteractionKind;
57
+ requestId: string;
58
+ interactive: boolean;
59
+ responseUserId?: string;
60
+ expiresAt?: string;
61
+ schemaVersion?: string;
62
+ preview?: {
63
+ title?: string;
64
+ blockKinds?: string[];
65
+ };
66
+ response?: {
67
+ actionIds?: string[];
68
+ actionFields?: Record<string, unknown>;
69
+ questions?: Array<{
70
+ id: string;
71
+ sensitive?: boolean;
78
72
  }>;
79
- url: z.ZodString;
80
- mimeType: z.ZodOptional<z.ZodString>;
81
- fileName: z.ZodOptional<z.ZodString>;
82
- sizeBytes: z.ZodOptional<z.ZodNumber>;
83
- width: z.ZodOptional<z.ZodNumber>;
84
- height: z.ZodOptional<z.ZodNumber>;
85
- durationMs: z.ZodOptional<z.ZodNumber>;
86
- }, z.core.$strip>>;
87
- mentions: z.ZodArray<z.ZodString>;
88
- replyTo: z.ZodNullable<z.ZodString>;
89
- replyToPosition: z.ZodNullable<z.ZodNumber>;
90
- forwarded: z.ZodOptional<z.ZodBoolean>;
91
- forwardedFrom: z.ZodOptional<z.ZodObject<{
92
- sourceConversationId: z.ZodString;
93
- messageId: z.ZodString;
94
- }, z.core.$strip>>;
95
- status: z.ZodEnum<{
96
- sent: "sent";
97
- read: "read";
98
- }>;
99
- createdAt: z.ZodString;
100
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
- contactCard: z.ZodOptional<z.ZodObject<{
102
- userId: z.ZodString;
103
- canonContactId: z.ZodOptional<z.ZodString>;
104
- displayName: z.ZodString;
105
- avatarUrl: z.ZodNullable<z.ZodString>;
106
- userType: z.ZodEnum<{
107
- human: "human";
108
- ai_agent: "ai_agent";
109
- }>;
110
- clientType: z.ZodOptional<z.ZodEnum<{
111
- "claude-code": "claude-code";
112
- openclaw: "openclaw";
113
- codex: "codex";
114
- hermes: "hermes";
115
- generic: "generic";
116
- }>>;
117
- about: z.ZodOptional<z.ZodString>;
118
- isActive: z.ZodOptional<z.ZodBoolean>;
119
- ownerId: z.ZodOptional<z.ZodString>;
120
- ownerName: z.ZodOptional<z.ZodString>;
121
- lifecycleState: z.ZodOptional<z.ZodString>;
122
- }, z.core.$strip>>;
123
- runtimeCard: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
124
- reactions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
125
- }, z.core.$strip>;
126
- export type SerializedMessage = z.infer<typeof SerializedMessageSchema>;
127
- export declare const SerializeMessageInputSchema: z.ZodObject<{
128
- id: z.ZodString;
129
- data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
130
- senderName: z.ZodOptional<z.ZodString>;
131
- isOwner: z.ZodBoolean;
132
- }, z.core.$strip>;
133
- export type SerializeMessageInput = z.infer<typeof SerializeMessageInputSchema>;
73
+ };
74
+ }
75
+ export interface SerializeMessageInput {
76
+ id: string;
77
+ data: Record<string, unknown>;
78
+ senderName?: string;
79
+ isOwner: boolean;
80
+ }
134
81
  export declare function serializeStoredMessage(input: SerializeMessageInput): SerializedMessage;