@winmatrix/protocol 1.0.5 → 1.0.6

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.
@@ -0,0 +1,548 @@
1
+ import { z } from 'zod';
2
+ export declare const ChatPresentationFinalKind = "final-response";
3
+ export declare const CONVERSATION_CHAT_ACCEPTED_SCHEMA_VERSION = 1;
4
+ /** 首条消息由服务端分配真实会话 ID 后的 WS 确认帧。 */
5
+ export declare const ConversationChatAcceptedSchema: z.ZodObject<{
6
+ type: z.ZodLiteral<"conversation:chat_accepted">;
7
+ schemaVersion: z.ZodLiteral<1>;
8
+ conversationId: z.ZodString;
9
+ }, "strip", z.ZodTypeAny, {
10
+ type: "conversation:chat_accepted";
11
+ schemaVersion: 1;
12
+ conversationId: string;
13
+ }, {
14
+ type: "conversation:chat_accepted";
15
+ schemaVersion: 1;
16
+ conversationId: string;
17
+ }>;
18
+ /**
19
+ * user 消息落库回执帧:前端 pending 区据落库 presentationOrder 转正归位。
20
+ * ack 丢失无补偿——由前端重叠窗口回读自愈(spec §4.2)。
21
+ */
22
+ export declare const MessageAckFrameSchema: z.ZodObject<{
23
+ type: z.ZodLiteral<"conversation:message_ack">;
24
+ conversationId: z.ZodString;
25
+ userMessageId: z.ZodString;
26
+ presentationOrder: z.ZodString;
27
+ turnKey: z.ZodString;
28
+ }, "strip", z.ZodTypeAny, {
29
+ type: "conversation:message_ack";
30
+ turnKey: string;
31
+ presentationOrder: string;
32
+ conversationId: string;
33
+ userMessageId: string;
34
+ }, {
35
+ type: "conversation:message_ack";
36
+ turnKey: string;
37
+ presentationOrder: string;
38
+ conversationId: string;
39
+ userMessageId: string;
40
+ }>;
41
+ export declare const ChatPresentationLifecycleSchema: z.ZodEnum<["open", "patch", "settled", "discarded"]>;
42
+ export declare const ChatPresentationAnchorSchema: z.ZodObject<{
43
+ afterMessageId: z.ZodString;
44
+ slot: z.ZodNumber;
45
+ tieBreaker: z.ZodString;
46
+ }, "strip", z.ZodTypeAny, {
47
+ afterMessageId: string;
48
+ slot: number;
49
+ tieBreaker: string;
50
+ }, {
51
+ afterMessageId: string;
52
+ slot: number;
53
+ tieBreaker: string;
54
+ }>;
55
+ export declare const EmployeePresentationAuthorSchema: z.ZodObject<{
56
+ kind: z.ZodLiteral<"employee">;
57
+ roleId: z.ZodString;
58
+ digitalEmployeeName: z.ZodString;
59
+ digitalEmployeeId: z.ZodOptional<z.ZodString>;
60
+ }, "strip", z.ZodTypeAny, {
61
+ roleId: string;
62
+ kind: "employee";
63
+ digitalEmployeeName: string;
64
+ digitalEmployeeId?: string | undefined;
65
+ }, {
66
+ roleId: string;
67
+ kind: "employee";
68
+ digitalEmployeeName: string;
69
+ digitalEmployeeId?: string | undefined;
70
+ }>;
71
+ export declare const SystemPresentationAuthorSchema: z.ZodObject<{
72
+ kind: z.ZodLiteral<"system">;
73
+ displayName: z.ZodString;
74
+ }, "strip", z.ZodTypeAny, {
75
+ kind: "system";
76
+ displayName: string;
77
+ }, {
78
+ kind: "system";
79
+ displayName: string;
80
+ }>;
81
+ export declare const UserPresentationAuthorSchema: z.ZodObject<{
82
+ kind: z.ZodLiteral<"user">;
83
+ displayName: z.ZodOptional<z.ZodString>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ kind: "user";
86
+ displayName?: string | undefined;
87
+ }, {
88
+ kind: "user";
89
+ displayName?: string | undefined;
90
+ }>;
91
+ export declare const ChatPresentationAuthorSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
92
+ kind: z.ZodLiteral<"user">;
93
+ displayName: z.ZodOptional<z.ZodString>;
94
+ }, "strip", z.ZodTypeAny, {
95
+ kind: "user";
96
+ displayName?: string | undefined;
97
+ }, {
98
+ kind: "user";
99
+ displayName?: string | undefined;
100
+ }>, z.ZodObject<{
101
+ kind: z.ZodLiteral<"employee">;
102
+ roleId: z.ZodString;
103
+ digitalEmployeeName: z.ZodString;
104
+ digitalEmployeeId: z.ZodOptional<z.ZodString>;
105
+ }, "strip", z.ZodTypeAny, {
106
+ roleId: string;
107
+ kind: "employee";
108
+ digitalEmployeeName: string;
109
+ digitalEmployeeId?: string | undefined;
110
+ }, {
111
+ roleId: string;
112
+ kind: "employee";
113
+ digitalEmployeeName: string;
114
+ digitalEmployeeId?: string | undefined;
115
+ }>, z.ZodObject<{
116
+ kind: z.ZodLiteral<"system">;
117
+ displayName: z.ZodString;
118
+ }, "strip", z.ZodTypeAny, {
119
+ kind: "system";
120
+ displayName: string;
121
+ }, {
122
+ kind: "system";
123
+ displayName: string;
124
+ }>]>;
125
+ export declare const ChatPresentationProducerSchema: z.ZodObject<{
126
+ module: z.ZodString;
127
+ runId: z.ZodOptional<z.ZodString>;
128
+ sourceId: z.ZodOptional<z.ZodString>;
129
+ }, "strip", z.ZodTypeAny, {
130
+ module: string;
131
+ runId?: string | undefined;
132
+ sourceId?: string | undefined;
133
+ }, {
134
+ module: string;
135
+ runId?: string | undefined;
136
+ sourceId?: string | undefined;
137
+ }>;
138
+ export declare const ChatPresentationEventSchema: z.ZodEffects<z.ZodObject<{
139
+ eventId: z.ZodString;
140
+ conversationId: z.ZodString;
141
+ turnId: z.ZodString;
142
+ presentationId: z.ZodString;
143
+ kind: z.ZodEnum<["final-response", "final-draft", "transient-thinking", "tool-execution", "orchestration", "execution-surface", "artifacts"]>;
144
+ lifecycle: z.ZodEnum<["open", "patch", "settled", "discarded"]>;
145
+ revision: z.ZodNumber;
146
+ /** 服务端发布时刻;仅用于当前页的同锚点因果排序,历史仍按 presentationOrder。 */
147
+ emittedAt: z.ZodNumber;
148
+ anchor: z.ZodObject<{
149
+ afterMessageId: z.ZodString;
150
+ slot: z.ZodNumber;
151
+ tieBreaker: z.ZodString;
152
+ }, "strip", z.ZodTypeAny, {
153
+ afterMessageId: string;
154
+ slot: number;
155
+ tieBreaker: string;
156
+ }, {
157
+ afterMessageId: string;
158
+ slot: number;
159
+ tieBreaker: string;
160
+ }>;
161
+ producer: z.ZodObject<{
162
+ module: z.ZodString;
163
+ runId: z.ZodOptional<z.ZodString>;
164
+ sourceId: z.ZodOptional<z.ZodString>;
165
+ }, "strip", z.ZodTypeAny, {
166
+ module: string;
167
+ runId?: string | undefined;
168
+ sourceId?: string | undefined;
169
+ }, {
170
+ module: string;
171
+ runId?: string | undefined;
172
+ sourceId?: string | undefined;
173
+ }>;
174
+ author: z.ZodOptional<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
175
+ kind: z.ZodLiteral<"user">;
176
+ displayName: z.ZodOptional<z.ZodString>;
177
+ }, "strip", z.ZodTypeAny, {
178
+ kind: "user";
179
+ displayName?: string | undefined;
180
+ }, {
181
+ kind: "user";
182
+ displayName?: string | undefined;
183
+ }>, z.ZodObject<{
184
+ kind: z.ZodLiteral<"employee">;
185
+ roleId: z.ZodString;
186
+ digitalEmployeeName: z.ZodString;
187
+ digitalEmployeeId: z.ZodOptional<z.ZodString>;
188
+ }, "strip", z.ZodTypeAny, {
189
+ roleId: string;
190
+ kind: "employee";
191
+ digitalEmployeeName: string;
192
+ digitalEmployeeId?: string | undefined;
193
+ }, {
194
+ roleId: string;
195
+ kind: "employee";
196
+ digitalEmployeeName: string;
197
+ digitalEmployeeId?: string | undefined;
198
+ }>, z.ZodObject<{
199
+ kind: z.ZodLiteral<"system">;
200
+ displayName: z.ZodString;
201
+ }, "strip", z.ZodTypeAny, {
202
+ kind: "system";
203
+ displayName: string;
204
+ }, {
205
+ kind: "system";
206
+ displayName: string;
207
+ }>]>>;
208
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
209
+ }, "strip", z.ZodTypeAny, {
210
+ payload: Record<string, unknown>;
211
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
212
+ anchor: {
213
+ afterMessageId: string;
214
+ slot: number;
215
+ tieBreaker: string;
216
+ };
217
+ conversationId: string;
218
+ eventId: string;
219
+ turnId: string;
220
+ presentationId: string;
221
+ lifecycle: "open" | "patch" | "settled" | "discarded";
222
+ revision: number;
223
+ emittedAt: number;
224
+ producer: {
225
+ module: string;
226
+ runId?: string | undefined;
227
+ sourceId?: string | undefined;
228
+ };
229
+ author?: {
230
+ roleId: string;
231
+ kind: "employee";
232
+ digitalEmployeeName: string;
233
+ digitalEmployeeId?: string | undefined;
234
+ } | {
235
+ kind: "system";
236
+ displayName: string;
237
+ } | {
238
+ kind: "user";
239
+ displayName?: string | undefined;
240
+ } | undefined;
241
+ }, {
242
+ payload: Record<string, unknown>;
243
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
244
+ anchor: {
245
+ afterMessageId: string;
246
+ slot: number;
247
+ tieBreaker: string;
248
+ };
249
+ conversationId: string;
250
+ eventId: string;
251
+ turnId: string;
252
+ presentationId: string;
253
+ lifecycle: "open" | "patch" | "settled" | "discarded";
254
+ revision: number;
255
+ emittedAt: number;
256
+ producer: {
257
+ module: string;
258
+ runId?: string | undefined;
259
+ sourceId?: string | undefined;
260
+ };
261
+ author?: {
262
+ roleId: string;
263
+ kind: "employee";
264
+ digitalEmployeeName: string;
265
+ digitalEmployeeId?: string | undefined;
266
+ } | {
267
+ kind: "system";
268
+ displayName: string;
269
+ } | {
270
+ kind: "user";
271
+ displayName?: string | undefined;
272
+ } | undefined;
273
+ }>, {
274
+ payload: Record<string, unknown>;
275
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
276
+ anchor: {
277
+ afterMessageId: string;
278
+ slot: number;
279
+ tieBreaker: string;
280
+ };
281
+ conversationId: string;
282
+ eventId: string;
283
+ turnId: string;
284
+ presentationId: string;
285
+ lifecycle: "open" | "patch" | "settled" | "discarded";
286
+ revision: number;
287
+ emittedAt: number;
288
+ producer: {
289
+ module: string;
290
+ runId?: string | undefined;
291
+ sourceId?: string | undefined;
292
+ };
293
+ author?: {
294
+ roleId: string;
295
+ kind: "employee";
296
+ digitalEmployeeName: string;
297
+ digitalEmployeeId?: string | undefined;
298
+ } | {
299
+ kind: "system";
300
+ displayName: string;
301
+ } | {
302
+ kind: "user";
303
+ displayName?: string | undefined;
304
+ } | undefined;
305
+ }, {
306
+ payload: Record<string, unknown>;
307
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
308
+ anchor: {
309
+ afterMessageId: string;
310
+ slot: number;
311
+ tieBreaker: string;
312
+ };
313
+ conversationId: string;
314
+ eventId: string;
315
+ turnId: string;
316
+ presentationId: string;
317
+ lifecycle: "open" | "patch" | "settled" | "discarded";
318
+ revision: number;
319
+ emittedAt: number;
320
+ producer: {
321
+ module: string;
322
+ runId?: string | undefined;
323
+ sourceId?: string | undefined;
324
+ };
325
+ author?: {
326
+ roleId: string;
327
+ kind: "employee";
328
+ digitalEmployeeName: string;
329
+ digitalEmployeeId?: string | undefined;
330
+ } | {
331
+ kind: "system";
332
+ displayName: string;
333
+ } | {
334
+ kind: "user";
335
+ displayName?: string | undefined;
336
+ } | undefined;
337
+ }>;
338
+ export declare const PresentationIntentSchema: z.ZodEffects<z.ZodObject<{
339
+ conversationId: z.ZodString;
340
+ turnId: z.ZodString;
341
+ presentationId: z.ZodOptional<z.ZodString>;
342
+ anchor: z.ZodOptional<z.ZodObject<{
343
+ afterMessageId: z.ZodString;
344
+ slot: z.ZodNumber;
345
+ tieBreaker: z.ZodString;
346
+ }, "strip", z.ZodTypeAny, {
347
+ afterMessageId: string;
348
+ slot: number;
349
+ tieBreaker: string;
350
+ }, {
351
+ afterMessageId: string;
352
+ slot: number;
353
+ tieBreaker: string;
354
+ }>>;
355
+ afterMessageId: z.ZodOptional<z.ZodString>;
356
+ tieBreaker: z.ZodOptional<z.ZodString>;
357
+ kind: z.ZodEnum<["final-response", "final-draft", "transient-thinking", "tool-execution", "orchestration", "execution-surface", "artifacts"]>;
358
+ lifecycle: z.ZodEnum<["open", "patch", "settled", "discarded"]>;
359
+ producer: z.ZodObject<{
360
+ module: z.ZodString;
361
+ runId: z.ZodOptional<z.ZodString>;
362
+ sourceId: z.ZodOptional<z.ZodString>;
363
+ }, "strip", z.ZodTypeAny, {
364
+ module: string;
365
+ runId?: string | undefined;
366
+ sourceId?: string | undefined;
367
+ }, {
368
+ module: string;
369
+ runId?: string | undefined;
370
+ sourceId?: string | undefined;
371
+ }>;
372
+ author: z.ZodOptional<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
373
+ kind: z.ZodLiteral<"user">;
374
+ displayName: z.ZodOptional<z.ZodString>;
375
+ }, "strip", z.ZodTypeAny, {
376
+ kind: "user";
377
+ displayName?: string | undefined;
378
+ }, {
379
+ kind: "user";
380
+ displayName?: string | undefined;
381
+ }>, z.ZodObject<{
382
+ kind: z.ZodLiteral<"employee">;
383
+ roleId: z.ZodString;
384
+ digitalEmployeeName: z.ZodString;
385
+ digitalEmployeeId: z.ZodOptional<z.ZodString>;
386
+ }, "strip", z.ZodTypeAny, {
387
+ roleId: string;
388
+ kind: "employee";
389
+ digitalEmployeeName: string;
390
+ digitalEmployeeId?: string | undefined;
391
+ }, {
392
+ roleId: string;
393
+ kind: "employee";
394
+ digitalEmployeeName: string;
395
+ digitalEmployeeId?: string | undefined;
396
+ }>, z.ZodObject<{
397
+ kind: z.ZodLiteral<"system">;
398
+ displayName: z.ZodString;
399
+ }, "strip", z.ZodTypeAny, {
400
+ kind: "system";
401
+ displayName: string;
402
+ }, {
403
+ kind: "system";
404
+ displayName: string;
405
+ }>]>>;
406
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
407
+ }, "strip", z.ZodTypeAny, {
408
+ payload: Record<string, unknown>;
409
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
410
+ conversationId: string;
411
+ turnId: string;
412
+ lifecycle: "open" | "patch" | "settled" | "discarded";
413
+ producer: {
414
+ module: string;
415
+ runId?: string | undefined;
416
+ sourceId?: string | undefined;
417
+ };
418
+ author?: {
419
+ roleId: string;
420
+ kind: "employee";
421
+ digitalEmployeeName: string;
422
+ digitalEmployeeId?: string | undefined;
423
+ } | {
424
+ kind: "system";
425
+ displayName: string;
426
+ } | {
427
+ kind: "user";
428
+ displayName?: string | undefined;
429
+ } | undefined;
430
+ afterMessageId?: string | undefined;
431
+ tieBreaker?: string | undefined;
432
+ anchor?: {
433
+ afterMessageId: string;
434
+ slot: number;
435
+ tieBreaker: string;
436
+ } | undefined;
437
+ presentationId?: string | undefined;
438
+ }, {
439
+ payload: Record<string, unknown>;
440
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
441
+ conversationId: string;
442
+ turnId: string;
443
+ lifecycle: "open" | "patch" | "settled" | "discarded";
444
+ producer: {
445
+ module: string;
446
+ runId?: string | undefined;
447
+ sourceId?: string | undefined;
448
+ };
449
+ author?: {
450
+ roleId: string;
451
+ kind: "employee";
452
+ digitalEmployeeName: string;
453
+ digitalEmployeeId?: string | undefined;
454
+ } | {
455
+ kind: "system";
456
+ displayName: string;
457
+ } | {
458
+ kind: "user";
459
+ displayName?: string | undefined;
460
+ } | undefined;
461
+ afterMessageId?: string | undefined;
462
+ tieBreaker?: string | undefined;
463
+ anchor?: {
464
+ afterMessageId: string;
465
+ slot: number;
466
+ tieBreaker: string;
467
+ } | undefined;
468
+ presentationId?: string | undefined;
469
+ }>, {
470
+ payload: Record<string, unknown>;
471
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
472
+ conversationId: string;
473
+ turnId: string;
474
+ lifecycle: "open" | "patch" | "settled" | "discarded";
475
+ producer: {
476
+ module: string;
477
+ runId?: string | undefined;
478
+ sourceId?: string | undefined;
479
+ };
480
+ author?: {
481
+ roleId: string;
482
+ kind: "employee";
483
+ digitalEmployeeName: string;
484
+ digitalEmployeeId?: string | undefined;
485
+ } | {
486
+ kind: "system";
487
+ displayName: string;
488
+ } | {
489
+ kind: "user";
490
+ displayName?: string | undefined;
491
+ } | undefined;
492
+ afterMessageId?: string | undefined;
493
+ tieBreaker?: string | undefined;
494
+ anchor?: {
495
+ afterMessageId: string;
496
+ slot: number;
497
+ tieBreaker: string;
498
+ } | undefined;
499
+ presentationId?: string | undefined;
500
+ }, {
501
+ payload: Record<string, unknown>;
502
+ kind: "artifacts" | "final-response" | "final-draft" | "transient-thinking" | "tool-execution" | "orchestration" | "execution-surface";
503
+ conversationId: string;
504
+ turnId: string;
505
+ lifecycle: "open" | "patch" | "settled" | "discarded";
506
+ producer: {
507
+ module: string;
508
+ runId?: string | undefined;
509
+ sourceId?: string | undefined;
510
+ };
511
+ author?: {
512
+ roleId: string;
513
+ kind: "employee";
514
+ digitalEmployeeName: string;
515
+ digitalEmployeeId?: string | undefined;
516
+ } | {
517
+ kind: "system";
518
+ displayName: string;
519
+ } | {
520
+ kind: "user";
521
+ displayName?: string | undefined;
522
+ } | undefined;
523
+ afterMessageId?: string | undefined;
524
+ tieBreaker?: string | undefined;
525
+ anchor?: {
526
+ afterMessageId: string;
527
+ slot: number;
528
+ tieBreaker: string;
529
+ } | undefined;
530
+ presentationId?: string | undefined;
531
+ }>;
532
+ export interface HistoryPresentationOrderEntry {
533
+ presentationOrder: bigint;
534
+ id: string;
535
+ }
536
+ export declare function compareHistoryPresentationOrder(left: HistoryPresentationOrderEntry, right: HistoryPresentationOrderEntry): number;
537
+ export declare function compareLivePresentationAnchor(left: ChatPresentationAnchor, right: ChatPresentationAnchor): number;
538
+ export type ChatPresentationLifecycle = z.infer<typeof ChatPresentationLifecycleSchema>;
539
+ export type ConversationChatAccepted = z.infer<typeof ConversationChatAcceptedSchema>;
540
+ export type MessageAckFrame = z.infer<typeof MessageAckFrameSchema>;
541
+ export type ChatPresentationAnchor = z.infer<typeof ChatPresentationAnchorSchema>;
542
+ export type EmployeePresentationAuthor = z.infer<typeof EmployeePresentationAuthorSchema>;
543
+ export type SystemPresentationAuthor = z.infer<typeof SystemPresentationAuthorSchema>;
544
+ export type ChatPresentationAuthor = z.infer<typeof ChatPresentationAuthorSchema>;
545
+ export type ChatPresentationProducer = z.infer<typeof ChatPresentationProducerSchema>;
546
+ export type ChatPresentationEvent = z.infer<typeof ChatPresentationEventSchema>;
547
+ export type PresentationIntent = z.infer<typeof PresentationIntentSchema>;
548
+ //# sourceMappingURL=chatPresentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatPresentation.d.ts","sourceRoot":"","sources":["../src/chatPresentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAC1D,eAAO,MAAM,yCAAyC,IAAI,CAAC;AAI3D,mCAAmC;AACnC,eAAO,MAAM,8BAA8B;;;;;;;;;;;;EAIzC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;EAMhC,CAAC;AAEH,eAAO,MAAM,+BAA+B,sDAK1C,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;EAIvC,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;EAK3C,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;;;;EAGzC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;EAGvC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;EAIzC,CAAC;AAkBH,eAAO,MAAM,2BAA2B;;;;;;;;IARtC,qDAAqD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;E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C;AACtF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { z } from 'zod';
2
+ import { MessageKindSchema } from './messageView.js';
3
+ export const ChatPresentationFinalKind = 'final-response';
4
+ export const CONVERSATION_CHAT_ACCEPTED_SCHEMA_VERSION = 1;
5
+ const PresentationOrderCursorSchema = z.string().regex(/^(0|[1-9]\d*)$/);
6
+ /** 首条消息由服务端分配真实会话 ID 后的 WS 确认帧。 */
7
+ export const ConversationChatAcceptedSchema = z.object({
8
+ type: z.literal('conversation:chat_accepted'),
9
+ schemaVersion: z.literal(CONVERSATION_CHAT_ACCEPTED_SCHEMA_VERSION),
10
+ conversationId: z.string().min(1).max(200),
11
+ });
12
+ /**
13
+ * user 消息落库回执帧:前端 pending 区据落库 presentationOrder 转正归位。
14
+ * ack 丢失无补偿——由前端重叠窗口回读自愈(spec §4.2)。
15
+ */
16
+ export const MessageAckFrameSchema = z.object({
17
+ type: z.literal('conversation:message_ack'),
18
+ conversationId: z.string().min(1).max(200),
19
+ userMessageId: z.string().min(1).max(200),
20
+ presentationOrder: PresentationOrderCursorSchema,
21
+ turnKey: z.string().min(1).max(300),
22
+ });
23
+ export const ChatPresentationLifecycleSchema = z.enum([
24
+ 'open',
25
+ 'patch',
26
+ 'settled',
27
+ 'discarded',
28
+ ]);
29
+ export const ChatPresentationAnchorSchema = z.object({
30
+ afterMessageId: z.string().min(1),
31
+ slot: z.number().int().nonnegative(),
32
+ tieBreaker: z.string().min(1),
33
+ });
34
+ export const EmployeePresentationAuthorSchema = z.object({
35
+ kind: z.literal('employee'),
36
+ roleId: z.string().min(1),
37
+ digitalEmployeeName: z.string().min(1),
38
+ digitalEmployeeId: z.string().min(1).optional(),
39
+ });
40
+ export const SystemPresentationAuthorSchema = z.object({
41
+ kind: z.literal('system'),
42
+ displayName: z.string().min(1),
43
+ });
44
+ export const UserPresentationAuthorSchema = z.object({
45
+ kind: z.literal('user'),
46
+ displayName: z.string().min(1).optional(),
47
+ });
48
+ export const ChatPresentationAuthorSchema = z.discriminatedUnion('kind', [
49
+ UserPresentationAuthorSchema,
50
+ EmployeePresentationAuthorSchema,
51
+ SystemPresentationAuthorSchema,
52
+ ]);
53
+ export const ChatPresentationProducerSchema = z.object({
54
+ module: z.string().min(1),
55
+ runId: z.string().min(1).optional(),
56
+ sourceId: z.string().min(1).optional(),
57
+ });
58
+ const ChatPresentationEventBaseSchema = z.object({
59
+ eventId: z.string().min(1),
60
+ conversationId: z.string().min(1),
61
+ turnId: z.string().min(1),
62
+ presentationId: z.string().min(1),
63
+ kind: MessageKindSchema,
64
+ lifecycle: ChatPresentationLifecycleSchema,
65
+ revision: z.number().int().nonnegative(),
66
+ /** 服务端发布时刻;仅用于当前页的同锚点因果排序,历史仍按 presentationOrder。 */
67
+ emittedAt: z.number().int().nonnegative(),
68
+ anchor: ChatPresentationAnchorSchema,
69
+ producer: ChatPresentationProducerSchema,
70
+ author: ChatPresentationAuthorSchema.optional(),
71
+ payload: z.record(z.string(), z.unknown()),
72
+ });
73
+ export const ChatPresentationEventSchema = ChatPresentationEventBaseSchema.superRefine((event, context) => {
74
+ if (event.kind === ChatPresentationFinalKind && !event.author) {
75
+ context.addIssue({
76
+ code: z.ZodIssueCode.custom,
77
+ message: 'final-response requires an explicit employee or system author',
78
+ path: ['author'],
79
+ });
80
+ }
81
+ });
82
+ const PresentationIntentBaseSchema = z.object({
83
+ conversationId: z.string().min(1),
84
+ turnId: z.string().min(1),
85
+ presentationId: z.string().min(1).optional(),
86
+ anchor: ChatPresentationAnchorSchema.optional(),
87
+ afterMessageId: z.string().min(1).optional(),
88
+ tieBreaker: z.string().min(1).optional(),
89
+ kind: MessageKindSchema,
90
+ lifecycle: ChatPresentationLifecycleSchema,
91
+ producer: ChatPresentationProducerSchema,
92
+ author: ChatPresentationAuthorSchema.optional(),
93
+ payload: z.record(z.string(), z.unknown()),
94
+ });
95
+ export const PresentationIntentSchema = PresentationIntentBaseSchema.superRefine((intent, context) => {
96
+ if (intent.kind === ChatPresentationFinalKind && !intent.author) {
97
+ context.addIssue({
98
+ code: z.ZodIssueCode.custom,
99
+ message: 'final-response requires an explicit employee or system author',
100
+ path: ['author'],
101
+ });
102
+ }
103
+ });
104
+ export function compareHistoryPresentationOrder(left, right) {
105
+ if (left.presentationOrder !== right.presentationOrder) {
106
+ return left.presentationOrder < right.presentationOrder ? -1 : 1;
107
+ }
108
+ return left.id.localeCompare(right.id);
109
+ }
110
+ export function compareLivePresentationAnchor(left, right) {
111
+ if (left.afterMessageId !== right.afterMessageId) {
112
+ return left.afterMessageId.localeCompare(right.afterMessageId);
113
+ }
114
+ if (left.slot !== right.slot)
115
+ return left.slot - right.slot;
116
+ return left.tieBreaker.localeCompare(right.tieBreaker);
117
+ }
118
+ //# sourceMappingURL=chatPresentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chatPresentation.js","sourceRoot":"","sources":["../src/chatPresentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;AAC1D,MAAM,CAAC,MAAM,yCAAyC,GAAG,CAAC,CAAC;AAE3D,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAEzE,mCAAmC;AACnC,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAAC;IACrD,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC;IAC7C,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,yCAAyC,CAAC;IACnE,cAAc,EAAE,CAAC,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AAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,IAA4B,EAC5B,KAA6B;IAE7B,IAAI,IAAI,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc,EAAE,CAAC;QACjD,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IAC5D,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AACzD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,4 +3,7 @@ export * from './agentEngine.js';
3
3
  export * from './constants.js';
4
4
  export * from './types.js';
5
5
  export * from './helpers.js';
6
+ export * from './chatPresentation.js';
7
+ export * from './messageView.js';
8
+ export * from './mcpUrl.js';
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}