@canonmsg/backend-contracts 1.1.1 → 1.3.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/dist/cjs/media.js +9 -0
- package/dist/cjs/message.js +17 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.js +9 -0
- package/dist/message.d.ts +3 -1
- package/dist/message.js +17 -0
- package/package.json +1 -1
package/dist/cjs/media.js
CHANGED
|
@@ -11,6 +11,8 @@ function inferMediaAttachmentKind(mimeType) {
|
|
|
11
11
|
return 'image';
|
|
12
12
|
if (mimeType.startsWith('audio/'))
|
|
13
13
|
return 'audio';
|
|
14
|
+
if (mimeType.startsWith('video/'))
|
|
15
|
+
return 'video';
|
|
14
16
|
return 'file';
|
|
15
17
|
}
|
|
16
18
|
function getStoredFileExtension(input) {
|
|
@@ -26,6 +28,10 @@ function getStoredFileExtension(input) {
|
|
|
26
28
|
'audio/mpeg': 'mp3',
|
|
27
29
|
'audio/webm': 'webm',
|
|
28
30
|
'audio/ogg': 'ogg',
|
|
31
|
+
'video/mp4': 'mp4',
|
|
32
|
+
'video/quicktime': 'mov',
|
|
33
|
+
'video/webm': 'webm',
|
|
34
|
+
'video/x-m4v': 'm4v',
|
|
29
35
|
'application/pdf': 'pdf',
|
|
30
36
|
'text/plain': 'txt',
|
|
31
37
|
'application/json': 'json',
|
|
@@ -63,6 +69,7 @@ function normalizeStoredAttachments(value) {
|
|
|
63
69
|
const candidate = item;
|
|
64
70
|
if (candidate.kind !== 'image'
|
|
65
71
|
&& candidate.kind !== 'audio'
|
|
72
|
+
&& candidate.kind !== 'video'
|
|
66
73
|
&& candidate.kind !== 'file') {
|
|
67
74
|
return null;
|
|
68
75
|
}
|
|
@@ -97,5 +104,7 @@ function describeAttachment(attachment) {
|
|
|
97
104
|
return '📷 Image';
|
|
98
105
|
if (attachment.kind === 'audio')
|
|
99
106
|
return '🎤 Voice message';
|
|
107
|
+
if (attachment.kind === 'video')
|
|
108
|
+
return '🎬 Video';
|
|
100
109
|
return attachment.fileName ? `📎 ${attachment.fileName}` : '📎 File';
|
|
101
110
|
}
|
package/dist/cjs/message.js
CHANGED
|
@@ -11,6 +11,18 @@ function normalizeStringArray(value) {
|
|
|
11
11
|
return [];
|
|
12
12
|
return value.filter((entry) => typeof entry === 'string');
|
|
13
13
|
}
|
|
14
|
+
function normalizeReactions(value) {
|
|
15
|
+
if (!isRecord(value))
|
|
16
|
+
return undefined;
|
|
17
|
+
const reactions = {};
|
|
18
|
+
for (const [reaction, userIds] of Object.entries(value)) {
|
|
19
|
+
const normalizedUserIds = normalizeStringArray(userIds);
|
|
20
|
+
if (reaction.length > 0 && normalizedUserIds.length > 0) {
|
|
21
|
+
reactions[reaction] = normalizedUserIds;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return Object.keys(reactions).length > 0 ? reactions : undefined;
|
|
25
|
+
}
|
|
14
26
|
function normalizeTimestamp(value) {
|
|
15
27
|
if (value instanceof Date)
|
|
16
28
|
return value;
|
|
@@ -47,6 +59,7 @@ function normalizeContentType(value) {
|
|
|
47
59
|
if (value === 'text'
|
|
48
60
|
|| value === 'image'
|
|
49
61
|
|| value === 'audio'
|
|
62
|
+
|| value === 'video'
|
|
50
63
|
|| value === 'file'
|
|
51
64
|
|| value === 'contact_card') {
|
|
52
65
|
return value;
|
|
@@ -137,5 +150,9 @@ function serializeStoredMessage(input) {
|
|
|
137
150
|
if (runtimeCard) {
|
|
138
151
|
result.runtimeCard = runtimeCard;
|
|
139
152
|
}
|
|
153
|
+
const reactions = normalizeReactions(data.reactions);
|
|
154
|
+
if (reactions) {
|
|
155
|
+
result.reactions = reactions;
|
|
156
|
+
}
|
|
140
157
|
return result;
|
|
141
158
|
}
|
package/dist/media.d.ts
CHANGED
package/dist/media.js
CHANGED
|
@@ -3,6 +3,8 @@ export function inferMediaAttachmentKind(mimeType) {
|
|
|
3
3
|
return 'image';
|
|
4
4
|
if (mimeType.startsWith('audio/'))
|
|
5
5
|
return 'audio';
|
|
6
|
+
if (mimeType.startsWith('video/'))
|
|
7
|
+
return 'video';
|
|
6
8
|
return 'file';
|
|
7
9
|
}
|
|
8
10
|
export function getStoredFileExtension(input) {
|
|
@@ -18,6 +20,10 @@ export function getStoredFileExtension(input) {
|
|
|
18
20
|
'audio/mpeg': 'mp3',
|
|
19
21
|
'audio/webm': 'webm',
|
|
20
22
|
'audio/ogg': 'ogg',
|
|
23
|
+
'video/mp4': 'mp4',
|
|
24
|
+
'video/quicktime': 'mov',
|
|
25
|
+
'video/webm': 'webm',
|
|
26
|
+
'video/x-m4v': 'm4v',
|
|
21
27
|
'application/pdf': 'pdf',
|
|
22
28
|
'text/plain': 'txt',
|
|
23
29
|
'application/json': 'json',
|
|
@@ -55,6 +61,7 @@ export function normalizeStoredAttachments(value) {
|
|
|
55
61
|
const candidate = item;
|
|
56
62
|
if (candidate.kind !== 'image'
|
|
57
63
|
&& candidate.kind !== 'audio'
|
|
64
|
+
&& candidate.kind !== 'video'
|
|
58
65
|
&& candidate.kind !== 'file') {
|
|
59
66
|
return null;
|
|
60
67
|
}
|
|
@@ -89,5 +96,7 @@ export function describeAttachment(attachment) {
|
|
|
89
96
|
return '📷 Image';
|
|
90
97
|
if (attachment.kind === 'audio')
|
|
91
98
|
return '🎤 Voice message';
|
|
99
|
+
if (attachment.kind === 'video')
|
|
100
|
+
return '🎬 Video';
|
|
92
101
|
return attachment.fileName ? `📎 ${attachment.fileName}` : '📎 File';
|
|
93
102
|
}
|
package/dist/message.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { MediaAttachment } from './media.js';
|
|
2
2
|
export type SerializedSenderType = 'human' | 'ai_agent';
|
|
3
3
|
export type SerializedAgentClientType = 'claude-code' | 'openclaw' | 'codex' | 'hermes' | 'generic';
|
|
4
|
-
export type SerializedContentType = 'text' | 'image' | 'audio' | 'file' | 'contact_card';
|
|
4
|
+
export type SerializedContentType = 'text' | 'image' | 'audio' | 'video' | 'file' | 'contact_card';
|
|
5
5
|
export interface ForwardedFrom {
|
|
6
6
|
sourceConversationId: string;
|
|
7
7
|
messageId: string;
|
|
8
8
|
}
|
|
9
|
+
export type SerializedReactions = Record<string, string[]>;
|
|
9
10
|
export interface SerializedContactCard {
|
|
10
11
|
userId: string;
|
|
11
12
|
displayName: string;
|
|
@@ -38,6 +39,7 @@ export interface SerializedMessage {
|
|
|
38
39
|
contactCard?: SerializedContactCard;
|
|
39
40
|
/** Durable canon.card.v1 runtime card content, passed through opaquely. */
|
|
40
41
|
runtimeCard?: Record<string, unknown>;
|
|
42
|
+
reactions?: SerializedReactions;
|
|
41
43
|
}
|
|
42
44
|
export interface SerializeMessageInput {
|
|
43
45
|
id: string;
|
package/dist/message.js
CHANGED
|
@@ -8,6 +8,18 @@ function normalizeStringArray(value) {
|
|
|
8
8
|
return [];
|
|
9
9
|
return value.filter((entry) => typeof entry === 'string');
|
|
10
10
|
}
|
|
11
|
+
function normalizeReactions(value) {
|
|
12
|
+
if (!isRecord(value))
|
|
13
|
+
return undefined;
|
|
14
|
+
const reactions = {};
|
|
15
|
+
for (const [reaction, userIds] of Object.entries(value)) {
|
|
16
|
+
const normalizedUserIds = normalizeStringArray(userIds);
|
|
17
|
+
if (reaction.length > 0 && normalizedUserIds.length > 0) {
|
|
18
|
+
reactions[reaction] = normalizedUserIds;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return Object.keys(reactions).length > 0 ? reactions : undefined;
|
|
22
|
+
}
|
|
11
23
|
function normalizeTimestamp(value) {
|
|
12
24
|
if (value instanceof Date)
|
|
13
25
|
return value;
|
|
@@ -44,6 +56,7 @@ function normalizeContentType(value) {
|
|
|
44
56
|
if (value === 'text'
|
|
45
57
|
|| value === 'image'
|
|
46
58
|
|| value === 'audio'
|
|
59
|
+
|| value === 'video'
|
|
47
60
|
|| value === 'file'
|
|
48
61
|
|| value === 'contact_card') {
|
|
49
62
|
return value;
|
|
@@ -134,5 +147,9 @@ export function serializeStoredMessage(input) {
|
|
|
134
147
|
if (runtimeCard) {
|
|
135
148
|
result.runtimeCard = runtimeCard;
|
|
136
149
|
}
|
|
150
|
+
const reactions = normalizeReactions(data.reactions);
|
|
151
|
+
if (reactions) {
|
|
152
|
+
result.reactions = reactions;
|
|
153
|
+
}
|
|
137
154
|
return result;
|
|
138
155
|
}
|