@gestaltrun/dsh-im-runtime 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.i18n.yaml +43 -0
- package/README.md +158 -2
- package/README.zh.md +158 -0
- package/UPSTREAM.json +66 -0
- package/lib/index.js +2 -0
- package/lib/runtime-C0-S-_CC.js +6758 -0
- package/lib/tools.js +2 -0
- package/lib/types/agent-coordinator.d.ts +84 -0
- package/lib/types/agent-prompt.d.ts +18 -0
- package/lib/types/delivery-schema.d.ts +52 -0
- package/lib/types/delivery-sqlite.d.ts +187 -0
- package/lib/types/delivery-types.d.ts +648 -0
- package/lib/types/delivery.d.ts +91 -0
- package/lib/types/errors.d.ts +8 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/policies.d.ts +53 -0
- package/lib/types/route-resolve.d.ts +10 -0
- package/lib/types/runtime.d.ts +360 -0
- package/lib/types/schema.d.ts +50 -0
- package/lib/types/service-types.d.ts +209 -0
- package/lib/types/session-events.d.ts +28 -0
- package/lib/types/simulation-controller.d.ts +64 -0
- package/lib/types/simulation-tools.d.ts +14 -0
- package/lib/types/tools.d.ts +17 -0
- package/lib/types/transport.d.ts +162 -0
- package/lib/types/transports.d.ts +41 -0
- package/lib/types/types.d.ts +504 -0
- package/lib/types.js +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +99 -3
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
/** Client-safe IM delivery, history, cursor, and outbox values. */
|
|
2
|
+
import type { Branded } from '@deepseek-ai/dsh-brand';
|
|
3
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
4
|
+
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types';
|
|
5
|
+
import type { ImAccountAuthorization, ImAccountConnectionIntent, ImAccountId, ImAccountIdentity, ImAccountListener, ImDirectRecipient, ImGroupTrigger, ImPlatform, ImRevision, ImRouteId } from './types.ts';
|
|
6
|
+
/** Collision-safe identifier of one real or simulated conversation scope. */
|
|
7
|
+
export type ImScopeId = Branded<'ImScopeId'>;
|
|
8
|
+
/** Stable identity of one inbound message. */
|
|
9
|
+
export type ImMessageId = Branded<'ImMessageId'>;
|
|
10
|
+
/** Caller-owned identity of one inbound page or JSONL import. */
|
|
11
|
+
export type ImDeliveryOperationId = Branded<'ImDeliveryOperationId'>;
|
|
12
|
+
/** Caller-owned idempotency identity of one outbound intent. */
|
|
13
|
+
export type ImOutboundRequestId = Branded<'ImOutboundRequestId'>;
|
|
14
|
+
/** Host-minted identity of the sole platform send attempt for an intent. */
|
|
15
|
+
export type ImOutboundAttemptId = Branded<'ImOutboundAttemptId'>;
|
|
16
|
+
/** Host-minted identity of a future local simulation instance. */
|
|
17
|
+
export type ImSimulationInstanceId = Branded<'ImSimulationInstanceId'>;
|
|
18
|
+
/** Stable identity of one provider-owned polling or stream cursor. */
|
|
19
|
+
export type ImProviderCursorId = Branded<'ImProviderCursorId'>;
|
|
20
|
+
/** Host-minted identity of one Agent admission batch. */
|
|
21
|
+
export type ImAdmissionId = Branded<'ImAdmissionId'>;
|
|
22
|
+
/** Stable identity of one route-bound Agent task generation. */
|
|
23
|
+
export type ImAgentTaskId = Branded<'ImAgentTaskId'>;
|
|
24
|
+
/** Complete identity of a real platform conversation. */
|
|
25
|
+
export interface ImRealDeliveryScope {
|
|
26
|
+
readonly kind: 'real';
|
|
27
|
+
readonly platform: ImPlatform;
|
|
28
|
+
readonly accountId: ImAccountId;
|
|
29
|
+
readonly conversationKind: 'direct' | 'group';
|
|
30
|
+
readonly conversationId: string;
|
|
31
|
+
}
|
|
32
|
+
/** Complete identity of a simulation conversation. */
|
|
33
|
+
export interface ImSimulationDeliveryScope {
|
|
34
|
+
readonly kind: 'simulation';
|
|
35
|
+
readonly instanceId: ImSimulationInstanceId;
|
|
36
|
+
readonly platform: ImPlatform;
|
|
37
|
+
readonly accountId: ImAccountId;
|
|
38
|
+
readonly conversationKind: 'direct' | 'group';
|
|
39
|
+
readonly conversationId: string;
|
|
40
|
+
}
|
|
41
|
+
/** Real and simulated conversations share the same history and outbox methods. */
|
|
42
|
+
export type ImDeliveryScope = ImRealDeliveryScope | ImSimulationDeliveryScope;
|
|
43
|
+
/** Provider evidence for an external participant. */
|
|
44
|
+
export interface ImExternalSenderAttribution {
|
|
45
|
+
readonly kind: 'external';
|
|
46
|
+
readonly senderId: string;
|
|
47
|
+
readonly senderDisplayName?: string;
|
|
48
|
+
readonly userId?: string;
|
|
49
|
+
readonly openDingTalkId?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Provider evidence that the configured account spoke in its native client. */
|
|
52
|
+
export interface ImHumanNativeSenderAttribution {
|
|
53
|
+
readonly kind: 'human-native';
|
|
54
|
+
readonly accountId: ImAccountId;
|
|
55
|
+
readonly providerActorId: string;
|
|
56
|
+
}
|
|
57
|
+
/** Durable outbox evidence that a human sent through DSH. */
|
|
58
|
+
export interface ImHumanDshSenderAttribution {
|
|
59
|
+
readonly kind: 'human-dsh';
|
|
60
|
+
readonly outboundRequestId: ImOutboundRequestId;
|
|
61
|
+
/** Host-derived managed account actor when the provider exposes one. */
|
|
62
|
+
readonly providerActorId?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Durable outbox evidence that an Agent reply was sent. */
|
|
65
|
+
export interface ImAiSenderAttribution {
|
|
66
|
+
readonly kind: 'ai';
|
|
67
|
+
readonly outboundRequestId: ImOutboundRequestId;
|
|
68
|
+
}
|
|
69
|
+
/** Honest fallback when provider facts cannot establish an actor. */
|
|
70
|
+
export interface ImUnknownSenderAttribution {
|
|
71
|
+
readonly kind: 'unknown';
|
|
72
|
+
readonly reason: 'insufficient-evidence' | 'unmatched-self' | 'unmatched-echo' | 'provider-unknown';
|
|
73
|
+
readonly observedSenderId?: string;
|
|
74
|
+
}
|
|
75
|
+
/** Evidence-bearing sender classification. Text equality never establishes a kind. */
|
|
76
|
+
export type ImSenderAttribution = ImExternalSenderAttribution | ImHumanNativeSenderAttribution | ImHumanDshSenderAttribution | ImAiSenderAttribution | ImUnknownSenderAttribution;
|
|
77
|
+
/** Provider facts admitted before the runtime assigns a sender category. */
|
|
78
|
+
export type ImInboundSenderEvidence = {
|
|
79
|
+
readonly kind: 'external-actor';
|
|
80
|
+
readonly senderId: string;
|
|
81
|
+
readonly senderDisplayName?: string;
|
|
82
|
+
readonly userId?: string;
|
|
83
|
+
readonly openDingTalkId?: string;
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: 'configured-native';
|
|
86
|
+
readonly providerActorId: string;
|
|
87
|
+
} | {
|
|
88
|
+
readonly kind: 'configured-echo';
|
|
89
|
+
readonly externalMessageId: string;
|
|
90
|
+
readonly observedSenderId?: string;
|
|
91
|
+
} | {
|
|
92
|
+
readonly kind: 'provider-unknown';
|
|
93
|
+
readonly observedSenderId?: string;
|
|
94
|
+
};
|
|
95
|
+
/** JSON value already reduced by a provider to display-safe message details. */
|
|
96
|
+
export type ImSafeJsonValue = null | boolean | number | string | readonly ImSafeJsonValue[] | {
|
|
97
|
+
readonly [key: string]: ImSafeJsonValue;
|
|
98
|
+
};
|
|
99
|
+
/** Provider quote context shown without resolving or rewriting another message. */
|
|
100
|
+
export interface ImMessageQuote {
|
|
101
|
+
readonly text: string;
|
|
102
|
+
readonly senderDisplayName?: string;
|
|
103
|
+
readonly externalMessageId?: string;
|
|
104
|
+
}
|
|
105
|
+
/** Text, image placeholder, or honest unsupported-message presentation. */
|
|
106
|
+
export type ImMessageContent = {
|
|
107
|
+
readonly text: string;
|
|
108
|
+
readonly format: 'text' | 'markdown';
|
|
109
|
+
readonly quote?: ImMessageQuote;
|
|
110
|
+
} | {
|
|
111
|
+
readonly text: string;
|
|
112
|
+
readonly format: 'image';
|
|
113
|
+
readonly quote?: ImMessageQuote;
|
|
114
|
+
} | {
|
|
115
|
+
readonly text: string;
|
|
116
|
+
readonly format: 'unsupported';
|
|
117
|
+
readonly messageType: string;
|
|
118
|
+
readonly details: ImSafeJsonValue;
|
|
119
|
+
readonly quote?: ImMessageQuote;
|
|
120
|
+
};
|
|
121
|
+
/** One normalized inbound provider message before persistence. */
|
|
122
|
+
export interface ImInboundMessageInput {
|
|
123
|
+
readonly externalMessageId: string;
|
|
124
|
+
readonly sender: ImSenderAttribution;
|
|
125
|
+
readonly content: ImMessageContent;
|
|
126
|
+
readonly occurredAt: string;
|
|
127
|
+
/** Provider-normalized evidence that this account was explicitly mentioned. */
|
|
128
|
+
readonly mentionedConfiguredAccount?: boolean;
|
|
129
|
+
}
|
|
130
|
+
/** Session attribution written with the existing durable `user/message` event. */
|
|
131
|
+
export interface ImMessageSource {
|
|
132
|
+
readonly kind: 'im';
|
|
133
|
+
readonly scopeId: ImScopeId;
|
|
134
|
+
readonly messageId: ImMessageId;
|
|
135
|
+
readonly sequenceNumber: number;
|
|
136
|
+
/** Present when one Agent steering item represents a durable message batch. */
|
|
137
|
+
readonly admission?: ImAgentAdmissionSource;
|
|
138
|
+
}
|
|
139
|
+
/** OR-combined reason that made one inbound batch eligible for Agent input. */
|
|
140
|
+
export type ImTriggerReason = 'direct' | 'mention' | 'every-n' | 'fixed-interval';
|
|
141
|
+
/** Sender and order evidence copied into the Session source for reconstruction. */
|
|
142
|
+
export interface ImAdmissionMessageSource {
|
|
143
|
+
readonly messageId: ImMessageId;
|
|
144
|
+
readonly sequenceNumber: number;
|
|
145
|
+
readonly externalMessageId: string;
|
|
146
|
+
readonly sender: ImSenderAttribution;
|
|
147
|
+
readonly occurredAt: string;
|
|
148
|
+
}
|
|
149
|
+
/** Frozen route and message evidence recorded with one Session user/message. */
|
|
150
|
+
export interface ImAgentAdmissionSource {
|
|
151
|
+
readonly admissionId: ImAdmissionId;
|
|
152
|
+
/** Customer pause generation at automatic input admission; absent legacy values mean zero. */
|
|
153
|
+
readonly handlingEpoch?: number;
|
|
154
|
+
readonly scope: ImDeliveryScope;
|
|
155
|
+
readonly messageIds: readonly ImMessageId[];
|
|
156
|
+
readonly messages: readonly ImAdmissionMessageSource[];
|
|
157
|
+
readonly triggerReasons: readonly ImTriggerReason[];
|
|
158
|
+
readonly routeId: ImRouteId;
|
|
159
|
+
readonly routeRevision: ImRevision;
|
|
160
|
+
readonly accountRevision: ImRevision;
|
|
161
|
+
readonly workspaceId: WorkspaceId;
|
|
162
|
+
}
|
|
163
|
+
/** Durable Agent task identity frozen when its first batch is admitted. */
|
|
164
|
+
export interface ImAgentTaskView {
|
|
165
|
+
readonly taskId: ImAgentTaskId;
|
|
166
|
+
readonly generation: number;
|
|
167
|
+
readonly scope: ImDeliveryScope;
|
|
168
|
+
readonly scopeId: ImScopeId;
|
|
169
|
+
readonly sessionId: SessionId;
|
|
170
|
+
readonly routeId: ImRouteId;
|
|
171
|
+
readonly routeRevision: ImRevision;
|
|
172
|
+
readonly accountRevision: ImRevision;
|
|
173
|
+
readonly workspaceId: WorkspaceId;
|
|
174
|
+
readonly agentPreset: string;
|
|
175
|
+
readonly controller?: string;
|
|
176
|
+
readonly groupTrigger?: ImGroupTrigger;
|
|
177
|
+
readonly directRecipient?: import('./types.ts').ImDirectRecipient;
|
|
178
|
+
readonly createdAt: string;
|
|
179
|
+
readonly updatedAt: string;
|
|
180
|
+
}
|
|
181
|
+
/** Durable inbound row safe for history UI and model tools. */
|
|
182
|
+
export interface ImInboundMessageView {
|
|
183
|
+
readonly messageId: ImMessageId;
|
|
184
|
+
readonly scopeId: ImScopeId;
|
|
185
|
+
readonly externalMessageId: string;
|
|
186
|
+
readonly sender: ImSenderAttribution;
|
|
187
|
+
readonly content: ImMessageContent;
|
|
188
|
+
readonly origin: 'live' | 'jsonl-import';
|
|
189
|
+
readonly stage: 'received' | 'submitted';
|
|
190
|
+
readonly sequenceNumber: number;
|
|
191
|
+
readonly occurredAt: string;
|
|
192
|
+
/** Provider-normalized evidence; message text is never parsed to infer a mention. */
|
|
193
|
+
readonly mentionedConfiguredAccount?: boolean;
|
|
194
|
+
readonly receivedAt: string;
|
|
195
|
+
readonly submission?: {
|
|
196
|
+
readonly sessionId: SessionId;
|
|
197
|
+
readonly submittedAt: string;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** Durable conversation progress. Imported history does not advance these live-delivery values. */
|
|
201
|
+
export interface ImConversationCursor {
|
|
202
|
+
readonly scopeId: ImScopeId;
|
|
203
|
+
readonly platformCursor: string | null;
|
|
204
|
+
readonly lastReceivedSequenceNumber: number;
|
|
205
|
+
readonly lastSubmittedSequenceNumber: number;
|
|
206
|
+
readonly pendingCount: number;
|
|
207
|
+
/**
|
|
208
|
+
* Highest live sequence a route policy refused to admit.
|
|
209
|
+
* Later allow does not replay these ids; only newer inbound is eligible.
|
|
210
|
+
*/
|
|
211
|
+
readonly lastSuppressedSequenceNumber?: number;
|
|
212
|
+
/** Last provider page admission; Agent submission does not change this value. */
|
|
213
|
+
readonly lastSyncedAt?: string;
|
|
214
|
+
readonly updatedAt: string;
|
|
215
|
+
}
|
|
216
|
+
/** Provider-known labels for one conversation. Missing fields remain unknown. */
|
|
217
|
+
export interface ImConversationPresentation {
|
|
218
|
+
readonly displayName?: string;
|
|
219
|
+
readonly memberCount?: number;
|
|
220
|
+
readonly assignedActorId?: string;
|
|
221
|
+
}
|
|
222
|
+
/** Atomic provider page admission request. */
|
|
223
|
+
export interface ImIngestInboundPageRequest {
|
|
224
|
+
readonly operationId: ImDeliveryOperationId;
|
|
225
|
+
readonly scope: ImDeliveryScope;
|
|
226
|
+
readonly observedCursor: string | null;
|
|
227
|
+
readonly nextCursor: string | null;
|
|
228
|
+
readonly presentation?: ImConversationPresentation;
|
|
229
|
+
readonly messages: readonly ImInboundMessageInput[];
|
|
230
|
+
}
|
|
231
|
+
/** Receipt stored with the conversation aggregate before a page call resolves. */
|
|
232
|
+
export interface ImInboundPageResult {
|
|
233
|
+
readonly kind: 'page';
|
|
234
|
+
readonly operationId: ImDeliveryOperationId;
|
|
235
|
+
readonly status: 'applied' | 'conflict';
|
|
236
|
+
readonly acceptedCount: number;
|
|
237
|
+
/** Existing rows whose explicit mention evidence advanced monotonically to true. */
|
|
238
|
+
readonly evidenceMergedCount?: number;
|
|
239
|
+
readonly duplicateCount: number;
|
|
240
|
+
readonly messages: readonly ImInboundMessageView[];
|
|
241
|
+
readonly cursor: ImConversationCursor;
|
|
242
|
+
}
|
|
243
|
+
/** Provider cursor ownership stays separate from conversation scopes. */
|
|
244
|
+
export interface ImProviderCursorOwner {
|
|
245
|
+
readonly platform: ImPlatform;
|
|
246
|
+
readonly accountId: ImAccountId;
|
|
247
|
+
/** Provider-defined feed identity, such as one admitted merchant inbox. */
|
|
248
|
+
readonly streamId: string;
|
|
249
|
+
}
|
|
250
|
+
/** One durable conversation-page receipt required before a provider cursor advances. */
|
|
251
|
+
export interface ImProviderCursorPageReceipt {
|
|
252
|
+
readonly scope: ImRealDeliveryScope;
|
|
253
|
+
readonly operationId: ImDeliveryOperationId;
|
|
254
|
+
}
|
|
255
|
+
/** Advance one provider cursor after every referenced conversation page is durable. */
|
|
256
|
+
export interface ImCommitProviderCursorRequest {
|
|
257
|
+
readonly operationId: ImDeliveryOperationId;
|
|
258
|
+
readonly owner: ImProviderCursorOwner;
|
|
259
|
+
readonly observedCursor: string | null;
|
|
260
|
+
readonly nextCursor: string | null;
|
|
261
|
+
readonly pages: readonly ImProviderCursorPageReceipt[];
|
|
262
|
+
}
|
|
263
|
+
/** Durable provider cursor and its last verified page set. */
|
|
264
|
+
export interface ImProviderCursorView {
|
|
265
|
+
readonly id: ImProviderCursorId;
|
|
266
|
+
readonly owner: ImProviderCursorOwner;
|
|
267
|
+
readonly cursor: string | null;
|
|
268
|
+
readonly updatedAt: string;
|
|
269
|
+
}
|
|
270
|
+
/** Cursor CAS result; rejected results identify incomplete durable page evidence. */
|
|
271
|
+
export interface ImProviderCursorCommitResult {
|
|
272
|
+
readonly operationId: ImDeliveryOperationId;
|
|
273
|
+
readonly status: 'applied' | 'unchanged' | 'conflict' | 'rejected';
|
|
274
|
+
readonly cursor: ImProviderCursorView;
|
|
275
|
+
readonly code?: 'IM_PROVIDER_PAGE_NOT_DURABLE';
|
|
276
|
+
readonly message?: string;
|
|
277
|
+
}
|
|
278
|
+
/** Lookup result for an uncertain provider-cursor response. */
|
|
279
|
+
export type ImProviderCursorOperationQuery = {
|
|
280
|
+
readonly state: 'not-found';
|
|
281
|
+
} | {
|
|
282
|
+
readonly state: 'known';
|
|
283
|
+
readonly result: ImProviderCursorCommitResult;
|
|
284
|
+
};
|
|
285
|
+
/** Query-only JSONL import request. Imported rows never enter pending delivery. */
|
|
286
|
+
export interface ImImportJsonlHistoryRequest {
|
|
287
|
+
readonly operationId: ImDeliveryOperationId;
|
|
288
|
+
readonly scope: ImDeliveryScope;
|
|
289
|
+
/** Display source; the Host persists its basename only. */
|
|
290
|
+
readonly fileName: string;
|
|
291
|
+
readonly jsonl: string;
|
|
292
|
+
}
|
|
293
|
+
/** Durable JSONL import receipt. */
|
|
294
|
+
export interface ImImportJsonlHistoryResult {
|
|
295
|
+
readonly kind: 'jsonl-import';
|
|
296
|
+
readonly operationId: ImDeliveryOperationId;
|
|
297
|
+
readonly status: 'applied';
|
|
298
|
+
readonly fileName: string;
|
|
299
|
+
readonly messageCount: number;
|
|
300
|
+
readonly importedCount: number;
|
|
301
|
+
readonly duplicateCount: number;
|
|
302
|
+
}
|
|
303
|
+
/** Durable inbound operation receipt. */
|
|
304
|
+
export type ImInboundOperationResult = ImInboundPageResult | ImImportJsonlHistoryResult;
|
|
305
|
+
/** Lookup result used after the caller loses an ingest or import response. */
|
|
306
|
+
export type ImInboundOperationQuery = {
|
|
307
|
+
readonly state: 'not-found';
|
|
308
|
+
} | {
|
|
309
|
+
readonly state: 'known';
|
|
310
|
+
readonly result: ImInboundOperationResult;
|
|
311
|
+
};
|
|
312
|
+
/** Cursor-based history request. `beforeSequenceNumber` is exclusive. */
|
|
313
|
+
export interface ImHistoryQueryRequest {
|
|
314
|
+
readonly scope: ImDeliveryScope;
|
|
315
|
+
readonly limit: number;
|
|
316
|
+
readonly beforeSequenceNumber?: number;
|
|
317
|
+
readonly origins?: readonly ImInboundMessageView['origin'][];
|
|
318
|
+
}
|
|
319
|
+
/** One ascending history page plus the cursor for an older page. */
|
|
320
|
+
export interface ImHistoryPage {
|
|
321
|
+
readonly items: readonly ImInboundMessageView[];
|
|
322
|
+
readonly hasMore: boolean;
|
|
323
|
+
readonly nextBeforeSequenceNumber?: number;
|
|
324
|
+
}
|
|
325
|
+
/** Pending live inbound request for the future Agent pump. */
|
|
326
|
+
export interface ImPendingInboundRequest {
|
|
327
|
+
readonly scope: ImDeliveryScope;
|
|
328
|
+
readonly limit: number;
|
|
329
|
+
}
|
|
330
|
+
/** Mark Session-appended messages submitted without claiming a cross-log transaction. */
|
|
331
|
+
export interface ImMarkSubmittedRequest {
|
|
332
|
+
readonly scope: ImDeliveryScope;
|
|
333
|
+
readonly messageIds: readonly ImMessageId[];
|
|
334
|
+
readonly sessionId: SessionId;
|
|
335
|
+
readonly submittedAt?: string;
|
|
336
|
+
}
|
|
337
|
+
/** Atomic submission result with current progress. */
|
|
338
|
+
export interface ImMarkSubmittedResult {
|
|
339
|
+
readonly messages: readonly ImInboundMessageView[];
|
|
340
|
+
readonly cursor: ImConversationCursor;
|
|
341
|
+
}
|
|
342
|
+
/** Outbound author and policy category. */
|
|
343
|
+
export type ImOutboundIntent = 'ai' | 'human-manual';
|
|
344
|
+
/** Durable state of one outbound intent. */
|
|
345
|
+
export type ImOutboundStatus = 'pending' | 'dispatching' | 'pre-send-failed' | 'sent' | 'result-unknown' | 'confirmed-failed';
|
|
346
|
+
/** Shared lifecycle terms used by recorded Session and delivery projections. */
|
|
347
|
+
export type ImMessageStage = 'received' | 'submitted' | 'sent';
|
|
348
|
+
/** Safe provider receipt facts. */
|
|
349
|
+
export interface ImOutboundReceipt {
|
|
350
|
+
readonly providerReceiptId?: string;
|
|
351
|
+
readonly providerStatus?: string;
|
|
352
|
+
readonly errorCode?: string;
|
|
353
|
+
readonly observedAt: string;
|
|
354
|
+
}
|
|
355
|
+
/** Frozen route identity for an automated real-platform reply. */
|
|
356
|
+
export interface ImOutboundRouteBinding {
|
|
357
|
+
readonly routeId: ImRouteId;
|
|
358
|
+
readonly routeRevision: ImRevision;
|
|
359
|
+
readonly workspaceId: WorkspaceId;
|
|
360
|
+
/** Account generation prevents paused automated work from flushing after resume. */
|
|
361
|
+
readonly accountRevision: ImRevision;
|
|
362
|
+
/** Customer pause generation that authorized this automatic reply. */
|
|
363
|
+
readonly handlingEpoch?: number;
|
|
364
|
+
}
|
|
365
|
+
/** Durable outbound intent and its sole send attempt. */
|
|
366
|
+
export interface ImOutboundView {
|
|
367
|
+
readonly requestId: ImOutboundRequestId;
|
|
368
|
+
readonly scopeId: ImScopeId;
|
|
369
|
+
readonly intent: ImOutboundIntent;
|
|
370
|
+
readonly content: ImMessageContent;
|
|
371
|
+
readonly status: ImOutboundStatus;
|
|
372
|
+
/** Scope-local admission order, independent of timestamps. */
|
|
373
|
+
readonly sequenceNumber: number;
|
|
374
|
+
/** Pause generation at registration; absence is the legacy zero generation. */
|
|
375
|
+
readonly handlingEpoch?: number;
|
|
376
|
+
readonly routeBinding?: ImOutboundRouteBinding;
|
|
377
|
+
readonly sender?: ImHumanDshSenderAttribution;
|
|
378
|
+
readonly manualBinding?: {
|
|
379
|
+
readonly sessionId: SessionId;
|
|
380
|
+
readonly taskId: ImAgentTaskId;
|
|
381
|
+
};
|
|
382
|
+
readonly retryOfRequestId?: ImOutboundRequestId;
|
|
383
|
+
readonly preSendFailureReason?: 'account-not-found' | 'platform-mismatch' | 'account-paused' | 'route-disabled' | 'route-unmatched' | 'route-changed' | 'cancelled';
|
|
384
|
+
readonly attempt?: {
|
|
385
|
+
readonly attemptId: ImOutboundAttemptId;
|
|
386
|
+
readonly startedAt: string;
|
|
387
|
+
};
|
|
388
|
+
readonly receipt?: ImOutboundReceipt;
|
|
389
|
+
readonly externalMessageId?: string;
|
|
390
|
+
readonly replyToExternalMessageId?: string;
|
|
391
|
+
readonly createdAt: string;
|
|
392
|
+
readonly updatedAt: string;
|
|
393
|
+
}
|
|
394
|
+
/** Persist an outbound intent before any platform call. */
|
|
395
|
+
export interface ImRegisterOutboundRequest {
|
|
396
|
+
readonly requestId: ImOutboundRequestId;
|
|
397
|
+
readonly scope: ImDeliveryScope;
|
|
398
|
+
readonly intent: ImOutboundIntent;
|
|
399
|
+
readonly content: ImMessageContent;
|
|
400
|
+
readonly sender?: ImHumanDshSenderAttribution;
|
|
401
|
+
readonly manualBinding?: {
|
|
402
|
+
readonly sessionId: SessionId;
|
|
403
|
+
readonly taskId: ImAgentTaskId;
|
|
404
|
+
};
|
|
405
|
+
readonly retryOfRequestId?: ImOutboundRequestId;
|
|
406
|
+
readonly replyToExternalMessageId?: string;
|
|
407
|
+
}
|
|
408
|
+
/** Durable real-Session assignment and safe identity confirmation for manual sends. */
|
|
409
|
+
export interface ImRealSessionBinding {
|
|
410
|
+
readonly sessionId: SessionId;
|
|
411
|
+
readonly scope: ImRealDeliveryScope;
|
|
412
|
+
readonly taskId: ImAgentTaskId;
|
|
413
|
+
readonly routeId: ImRouteId;
|
|
414
|
+
readonly routeRevision: ImRevision;
|
|
415
|
+
readonly accountRevision: ImRevision;
|
|
416
|
+
readonly workspaceId: WorkspaceId;
|
|
417
|
+
/** Workspace record title; falls back to {@link workspaceId} when the registry has no title. */
|
|
418
|
+
readonly workspaceTitle?: string;
|
|
419
|
+
readonly directRecipient?: ImDirectRecipient;
|
|
420
|
+
readonly senderIdentity: {
|
|
421
|
+
readonly accountId: ImAccountId;
|
|
422
|
+
readonly platform: ImPlatform;
|
|
423
|
+
readonly displayName: string;
|
|
424
|
+
readonly identity: ImAccountIdentity;
|
|
425
|
+
readonly providerActorId: string;
|
|
426
|
+
};
|
|
427
|
+
readonly accountState: {
|
|
428
|
+
readonly authorization: ImAccountAuthorization;
|
|
429
|
+
readonly connectionIntent: ImAccountConnectionIntent;
|
|
430
|
+
readonly listener: ImAccountListener;
|
|
431
|
+
readonly paused: boolean;
|
|
432
|
+
readonly manualSend: ImManualSendAvailability;
|
|
433
|
+
};
|
|
434
|
+
/** Whether the frozen route still admits automatic handling. */
|
|
435
|
+
readonly routeEnabled: boolean;
|
|
436
|
+
/** Customer-level pause recorded by the Host handling control. */
|
|
437
|
+
readonly automaticHandlingPaused: boolean;
|
|
438
|
+
readonly destination: {
|
|
439
|
+
readonly conversationKind: 'direct';
|
|
440
|
+
readonly conversationId: string;
|
|
441
|
+
readonly displayName?: string;
|
|
442
|
+
readonly directRecipient?: ImDirectRecipient;
|
|
443
|
+
} | {
|
|
444
|
+
readonly conversationKind: 'group';
|
|
445
|
+
readonly conversationId: string;
|
|
446
|
+
readonly displayName?: string;
|
|
447
|
+
readonly memberCount?: number;
|
|
448
|
+
};
|
|
449
|
+
readonly sync?: {
|
|
450
|
+
readonly lastSyncedAt: string;
|
|
451
|
+
readonly platformCursor: string | null;
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/** Current Host decision for a real Session's manual composer. */
|
|
455
|
+
export type ImManualSendAvailability = {
|
|
456
|
+
readonly state: 'available';
|
|
457
|
+
} | {
|
|
458
|
+
readonly state: 'unavailable';
|
|
459
|
+
readonly reason: 'disconnected' | 'authorization-required' | 'listener-unavailable';
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* GUI request for one idempotent real-platform manual message.
|
|
463
|
+
*
|
|
464
|
+
* Session-bound calls (an Agent task exists for {@link sessionId}) may send as
|
|
465
|
+
* any locally configured account that owns that task. Naming {@link scopeId}
|
|
466
|
+
* selects a stored real conversation when no task exists; Host then requires
|
|
467
|
+
* {@link accountId} and a conversation owned by that account. Unknown,
|
|
468
|
+
* other-account, and simulation scopes are rejected.
|
|
469
|
+
*/
|
|
470
|
+
export interface ImSendManualMessageRequest {
|
|
471
|
+
readonly sessionId: SessionId;
|
|
472
|
+
/** Wangwang conversation identity; used when {@link sessionId} has no Agent task. */
|
|
473
|
+
readonly scopeId?: ImScopeId;
|
|
474
|
+
/**
|
|
475
|
+
* Optional account constraint. Required together with {@link scopeId}.
|
|
476
|
+
* When present, the stored conversation must belong to this account.
|
|
477
|
+
* Session-bound callers that omit it may send as any locally configured
|
|
478
|
+
* account that owns the Session task.
|
|
479
|
+
*/
|
|
480
|
+
readonly accountId?: ImAccountId;
|
|
481
|
+
readonly requestId: ImOutboundRequestId;
|
|
482
|
+
readonly text: string;
|
|
483
|
+
}
|
|
484
|
+
/** Query or confirmation input for a manual message bound through its Session or scope. */
|
|
485
|
+
export interface ImManualMessageQueryRequest {
|
|
486
|
+
readonly sessionId: SessionId;
|
|
487
|
+
/** Wangwang conversation identity; used when {@link sessionId} has no Agent task. */
|
|
488
|
+
readonly scopeId?: ImScopeId;
|
|
489
|
+
/** Optional account constraint; required together with {@link scopeId}. */
|
|
490
|
+
readonly accountId?: ImAccountId;
|
|
491
|
+
readonly requestId: ImOutboundRequestId;
|
|
492
|
+
}
|
|
493
|
+
/** Explicit retry creates a distinct durable intent linked to an uncertain predecessor. */
|
|
494
|
+
export interface ImRetryManualMessageRequest {
|
|
495
|
+
readonly sessionId: SessionId;
|
|
496
|
+
/** Wangwang conversation identity; used when {@link sessionId} has no Agent task. */
|
|
497
|
+
readonly scopeId?: ImScopeId;
|
|
498
|
+
/** Optional account constraint; required together with {@link scopeId}. */
|
|
499
|
+
readonly accountId?: ImAccountId;
|
|
500
|
+
readonly requestId: ImOutboundRequestId;
|
|
501
|
+
readonly retryOfRequestId: ImOutboundRequestId;
|
|
502
|
+
}
|
|
503
|
+
/** Safe result for rendering identity, destination, source origin, and delivery state together. */
|
|
504
|
+
export interface ImManualMessageResult {
|
|
505
|
+
readonly binding: ImRealSessionBinding;
|
|
506
|
+
readonly sender: ImHumanDshSenderAttribution;
|
|
507
|
+
readonly outbound: ImOutboundView;
|
|
508
|
+
}
|
|
509
|
+
/** Durable lookup after an uncertain or lost manual-send response. */
|
|
510
|
+
export type ImManualMessageQuery = {
|
|
511
|
+
readonly state: 'not-found';
|
|
512
|
+
readonly binding: ImRealSessionBinding;
|
|
513
|
+
} | {
|
|
514
|
+
readonly state: 'known';
|
|
515
|
+
readonly result: ImManualMessageResult;
|
|
516
|
+
};
|
|
517
|
+
/** Start the sole provider attempt after a fresh route-policy check. */
|
|
518
|
+
export interface ImBeginOutboundAttemptRequest {
|
|
519
|
+
readonly scope: ImRealDeliveryScope;
|
|
520
|
+
readonly requestId: ImOutboundRequestId;
|
|
521
|
+
}
|
|
522
|
+
/** Provider dispatch instruction or a durable reason not to call the platform. */
|
|
523
|
+
export type ImBeginOutboundAttemptResult = {
|
|
524
|
+
readonly state: 'ready';
|
|
525
|
+
readonly attemptId: ImOutboundAttemptId;
|
|
526
|
+
readonly outbound: ImOutboundView;
|
|
527
|
+
} | {
|
|
528
|
+
readonly state: 'blocked' | 'result-unknown';
|
|
529
|
+
readonly outbound: ImOutboundView;
|
|
530
|
+
};
|
|
531
|
+
/** Final or uncertain outcome of one provider attempt. */
|
|
532
|
+
export interface ImSettleOutboundAttemptRequest {
|
|
533
|
+
readonly scope: ImRealDeliveryScope;
|
|
534
|
+
readonly requestId: ImOutboundRequestId;
|
|
535
|
+
readonly attemptId: ImOutboundAttemptId;
|
|
536
|
+
readonly status: 'sent' | 'result-unknown' | 'confirmed-failed';
|
|
537
|
+
readonly receipt?: ImOutboundReceipt;
|
|
538
|
+
readonly externalMessageId?: string;
|
|
539
|
+
}
|
|
540
|
+
/** Settle a simulation outbox locally without exposing a provider attempt. */
|
|
541
|
+
export interface ImSettleSimulationOutboundRequest {
|
|
542
|
+
readonly scope: ImSimulationDeliveryScope;
|
|
543
|
+
readonly requestId: ImOutboundRequestId;
|
|
544
|
+
}
|
|
545
|
+
/** Query one outbound intent with its full scope identity. */
|
|
546
|
+
export interface ImGetOutboundRequest {
|
|
547
|
+
readonly scope: ImDeliveryScope;
|
|
548
|
+
readonly requestId: ImOutboundRequestId;
|
|
549
|
+
}
|
|
550
|
+
/** Cursor-based outbound history request. */
|
|
551
|
+
export interface ImOutboundQueryRequest {
|
|
552
|
+
readonly scope: ImDeliveryScope;
|
|
553
|
+
readonly limit: number;
|
|
554
|
+
readonly beforeSequenceNumber?: number;
|
|
555
|
+
}
|
|
556
|
+
/** Ascending outbound page. */
|
|
557
|
+
export interface ImOutboundPage {
|
|
558
|
+
readonly items: readonly ImOutboundView[];
|
|
559
|
+
readonly hasMore: boolean;
|
|
560
|
+
readonly nextBeforeSequenceNumber?: number;
|
|
561
|
+
}
|
|
562
|
+
/** Result of comparing one durable Session log with pending IM submissions. */
|
|
563
|
+
export interface ImSessionReconciliationResult {
|
|
564
|
+
readonly sessionId: SessionId;
|
|
565
|
+
readonly submittedMessageIds: readonly ImMessageId[];
|
|
566
|
+
readonly ignoredEvidenceCount: number;
|
|
567
|
+
}
|
|
568
|
+
/** Explicitly discard still-pending automated sends without touching manual intents. */
|
|
569
|
+
export interface ImCancelPendingAiRequest {
|
|
570
|
+
readonly scope: ImDeliveryScope;
|
|
571
|
+
readonly reason: NonNullable<ImOutboundView['preSendFailureReason']>;
|
|
572
|
+
}
|
|
573
|
+
/** Post-commit delivery change for BFF feeds and provider pumps. */
|
|
574
|
+
export interface ImDeliveryChange {
|
|
575
|
+
readonly sequence: number;
|
|
576
|
+
readonly scope: ImDeliveryScope;
|
|
577
|
+
readonly scopeId: ImScopeId;
|
|
578
|
+
readonly kind: 'inbound' | 'submitted' | 'outbound' | 'handling';
|
|
579
|
+
readonly messageIds?: readonly ImMessageId[];
|
|
580
|
+
readonly requestId?: ImOutboundRequestId;
|
|
581
|
+
}
|
|
582
|
+
/** Reader identity for GUI-only inbound watermarks. One Host user shares one id. */
|
|
583
|
+
export type ImCustomerReaderId = Branded<'ImCustomerReaderId'>;
|
|
584
|
+
/** Customer-index list filter. Real and simulated rows are never mixed. */
|
|
585
|
+
export interface ImCustomerListRequest {
|
|
586
|
+
readonly accountId: ImAccountId;
|
|
587
|
+
readonly kind: 'real' | 'simulation';
|
|
588
|
+
readonly query?: string;
|
|
589
|
+
readonly limit: number;
|
|
590
|
+
readonly readerId: ImCustomerReaderId;
|
|
591
|
+
readonly after?: {
|
|
592
|
+
readonly lastActivity: string;
|
|
593
|
+
readonly customerKey: string;
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
/** One customer row projected from the rebuildable conversation index. */
|
|
597
|
+
export interface ImCustomerRow {
|
|
598
|
+
readonly customerKey: string;
|
|
599
|
+
readonly scopeId: ImScopeId;
|
|
600
|
+
readonly kind: 'real' | 'simulation';
|
|
601
|
+
readonly platform: ImPlatform;
|
|
602
|
+
readonly accountId: ImAccountId;
|
|
603
|
+
readonly conversationId: string;
|
|
604
|
+
readonly instanceId?: ImSimulationInstanceId;
|
|
605
|
+
readonly displayName?: string;
|
|
606
|
+
readonly lastActivity?: string;
|
|
607
|
+
readonly messagePreview?: string;
|
|
608
|
+
readonly unreadCount: number;
|
|
609
|
+
readonly latestSessionId?: SessionId;
|
|
610
|
+
readonly latestWorkspaceId?: WorkspaceId;
|
|
611
|
+
readonly latestGeneration?: number;
|
|
612
|
+
readonly unidentified: boolean;
|
|
613
|
+
readonly automaticHandlingPaused: boolean;
|
|
614
|
+
readonly pauseReason?: string;
|
|
615
|
+
}
|
|
616
|
+
/** Keyset page of customer rows plus the change watermark at query time. */
|
|
617
|
+
export interface ImCustomerListPage {
|
|
618
|
+
readonly items: readonly ImCustomerRow[];
|
|
619
|
+
readonly hasMore: boolean;
|
|
620
|
+
readonly nextAfter?: {
|
|
621
|
+
readonly lastActivity: string;
|
|
622
|
+
readonly customerKey: string;
|
|
623
|
+
};
|
|
624
|
+
readonly changeSeq: number;
|
|
625
|
+
}
|
|
626
|
+
/** GUI ack of the highest live inbound sequence the reader has rendered. */
|
|
627
|
+
export interface ImCustomerReadAckRequest {
|
|
628
|
+
readonly readerId: ImCustomerReaderId;
|
|
629
|
+
readonly scopeId: ImScopeId;
|
|
630
|
+
readonly sequenceNumber: number;
|
|
631
|
+
}
|
|
632
|
+
/** Customer-level automatic-handling pause fact. */
|
|
633
|
+
export interface ImHandlingControl {
|
|
634
|
+
readonly scopeId: ImScopeId;
|
|
635
|
+
readonly automaticHandlingPaused: boolean;
|
|
636
|
+
readonly reason?: string;
|
|
637
|
+
readonly revision: number;
|
|
638
|
+
readonly handlingEpoch: number;
|
|
639
|
+
readonly initiatingCallId?: string;
|
|
640
|
+
readonly updatedAt: string;
|
|
641
|
+
}
|
|
642
|
+
/** Persist or clear one scope's automatic-handling pause. */
|
|
643
|
+
export interface ImSetHandlingControlRequest {
|
|
644
|
+
readonly scopeId: ImScopeId;
|
|
645
|
+
readonly automaticHandlingPaused: boolean;
|
|
646
|
+
readonly reason?: string;
|
|
647
|
+
readonly initiatingCallId?: string;
|
|
648
|
+
}
|