@gestaltrun/dsh-im-runtime 0.0.0-stage → 0.1.5
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 +58 -0
- package/README.md +290 -2
- package/README.zh.md +290 -0
- package/UPSTREAM.json +66 -0
- package/lib/index.js +140 -0
- package/lib/inline-image-DuX6vSEI.js +20 -0
- package/lib/read-receipts.js +413 -0
- package/lib/read-state-CnUZKCuY.js +1868 -0
- package/lib/runtime-Bm6iSEpv.js +10939 -0
- package/lib/tools.js +2 -0
- package/lib/types/account-placement.d.ts +22 -0
- package/lib/types/admission-annotations.d.ts +40 -0
- package/lib/types/agent-coordinator.d.ts +129 -0
- package/lib/types/agent-media.d.ts +46 -0
- package/lib/types/agent-prompt.d.ts +24 -0
- package/lib/types/checkpoint-recovery.d.ts +32 -0
- package/lib/types/checkpoint.d.ts +127 -0
- package/lib/types/consumer-chat-links.d.ts +59 -0
- package/lib/types/delivery-schema.d.ts +176 -0
- package/lib/types/delivery-sqlite.d.ts +387 -0
- package/lib/types/delivery-types.d.ts +744 -0
- package/lib/types/delivery.d.ts +114 -0
- package/lib/types/errors.d.ts +8 -0
- package/lib/types/evaluation-accounts.d.ts +86 -0
- package/lib/types/index.d.ts +51 -0
- package/lib/types/inline-image.d.ts +7 -0
- package/lib/types/input-drain.d.ts +73 -0
- package/lib/types/knowledge-image.d.ts +64 -0
- package/lib/types/media-lifetime.d.ts +22 -0
- package/lib/types/media.d.ts +32 -0
- package/lib/types/message-preview.d.ts +4 -0
- package/lib/types/message-upload.d.ts +55 -0
- package/lib/types/nas-host-lease.d.ts +33 -0
- package/lib/types/placement-slice.d.ts +30 -0
- package/lib/types/policies.d.ts +63 -0
- package/lib/types/preset-model.d.ts +50 -0
- package/lib/types/read-context.d.ts +27 -0
- package/lib/types/read-receipts.d.ts +10 -0
- package/lib/types/read-records.d.ts +30 -0
- package/lib/types/read-state.d.ts +18 -0
- package/lib/types/read-types.d.ts +28 -0
- package/lib/types/restart-recovery.d.ts +38 -0
- package/lib/types/route-resolve.d.ts +10 -0
- package/lib/types/runtime.d.ts +668 -0
- package/lib/types/schema.d.ts +61 -0
- package/lib/types/script-clock.d.ts +14 -0
- package/lib/types/sdk.d.ts +108 -0
- package/lib/types/service-types.d.ts +366 -0
- package/lib/types/session-events.d.ts +28 -0
- package/lib/types/simulation-batch.d.ts +40 -0
- package/lib/types/simulation-controller.d.ts +77 -0
- package/lib/types/simulation-operator.d.ts +19 -0
- package/lib/types/simulation-tools.d.ts +14 -0
- package/lib/types/sqlite-connection.d.ts +27 -0
- package/lib/types/time.d.ts +13 -0
- package/lib/types/tools.d.ts +17 -0
- package/lib/types/transport.d.ts +202 -0
- package/lib/types/transports.d.ts +48 -0
- package/lib/types/types.d.ts +521 -0
- package/lib/types/typing.d.ts +33 -0
- package/lib/types/upload-types.d.ts +121 -0
- package/lib/types.js +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +125 -3
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { z, type ZodType } from 'zod';
|
|
2
|
+
import type { ImAdmissionId, ImAdmissionAnnotation, ImAdmissionAnnotationId, ImAdmissionAnnotatorId, ImAgentTaskView, ImInboundOperationResult, ImDeliveryScope, ImInboundMessageInput, ImInboundMessageView, ImMessageId, ImOutboundView, ImScopeId, ImProviderCursorCommitResult, ImProviderCursorId, ImProviderCursorOwner, ImTriggerReason } from './delivery-types.ts';
|
|
3
|
+
import type { ImUploadTarget, ImUploadObservation } from './upload-types.ts';
|
|
4
|
+
/** Captured platform identities; legacy observations omit the whole value. */
|
|
5
|
+
export declare const imUploadIdentitySchema: z.ZodObject<{
|
|
6
|
+
senderAccountId: z.ZodNullable<z.ZodString>;
|
|
7
|
+
senderDisplayName: z.ZodNullable<z.ZodString>;
|
|
8
|
+
senderDomain: z.ZodNullable<z.ZodString>;
|
|
9
|
+
assignedAccountId: z.ZodNullable<z.ZodString>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const imDeliveryScopeSchema: ZodType<ImDeliveryScope>;
|
|
12
|
+
/** Parser for provider and JSONL inbound records. */
|
|
13
|
+
export declare const imInboundMessageInputSchema: ZodType<ImInboundMessageInput>;
|
|
14
|
+
/** Server V2 control-result fields shared by the journal and queue parsers. */
|
|
15
|
+
export declare const imUploadConversationEventSchema: z.ZodObject<{
|
|
16
|
+
eventId: z.ZodString;
|
|
17
|
+
conversationKey: z.ZodString;
|
|
18
|
+
accountId: z.ZodString;
|
|
19
|
+
kind: z.ZodEnum<{
|
|
20
|
+
ai_to_human: "ai_to_human";
|
|
21
|
+
hosting_disabled: "hosting_disabled";
|
|
22
|
+
hosting_resumed: "hosting_resumed";
|
|
23
|
+
}>;
|
|
24
|
+
occurredAt: z.ZodISODateTime;
|
|
25
|
+
controlRevision: z.ZodString;
|
|
26
|
+
relatedMessageIds: z.ZodArray<z.ZodString>;
|
|
27
|
+
sourceOperationId: z.ZodString;
|
|
28
|
+
sourceKind: z.ZodLiteral<"dsh-control-result">;
|
|
29
|
+
payloadHash: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export declare const imUploadObservationSchema: z.ZodObject<{
|
|
32
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<import("./upload-types.ts").ImUploadObservationId, string>>;
|
|
33
|
+
target: z.ZodObject<{
|
|
34
|
+
serverOrigin: z.ZodURL;
|
|
35
|
+
tenantId: z.ZodPipe<z.ZodString, z.ZodTransform<import("@deepseek-ai/dsh-brand").Branded<"MerchantTenantId">, string>>;
|
|
36
|
+
shopAccountId: z.ZodString;
|
|
37
|
+
traffic: z.ZodEnum<{
|
|
38
|
+
formal: "formal";
|
|
39
|
+
test: "test";
|
|
40
|
+
simulation: "simulation";
|
|
41
|
+
}>;
|
|
42
|
+
testRunId: z.ZodNullable<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
scope: z.ZodType<ImDeliveryScope, unknown, z.core.$ZodTypeInternals<ImDeliveryScope, unknown>>;
|
|
45
|
+
observedAt: z.ZodISODateTime;
|
|
46
|
+
identity: z.ZodOptional<z.ZodObject<{
|
|
47
|
+
senderAccountId: z.ZodNullable<z.ZodString>;
|
|
48
|
+
senderDisplayName: z.ZodNullable<z.ZodString>;
|
|
49
|
+
senderDomain: z.ZodNullable<z.ZodString>;
|
|
50
|
+
assignedAccountId: z.ZodNullable<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
message: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
53
|
+
kind: z.ZodLiteral<"inbound">;
|
|
54
|
+
value: z.ZodType<ImInboundMessageView, unknown, z.core.$ZodTypeInternals<ImInboundMessageView, unknown>>;
|
|
55
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
56
|
+
kind: z.ZodLiteral<"outbound">;
|
|
57
|
+
value: z.ZodType<ImOutboundView, unknown, z.core.$ZodTypeInternals<ImOutboundView, unknown>>;
|
|
58
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
59
|
+
kind: z.ZodLiteral<"conversation-event">;
|
|
60
|
+
value: z.ZodObject<{
|
|
61
|
+
eventId: z.ZodString;
|
|
62
|
+
conversationKey: z.ZodString;
|
|
63
|
+
accountId: z.ZodString;
|
|
64
|
+
kind: z.ZodEnum<{
|
|
65
|
+
ai_to_human: "ai_to_human";
|
|
66
|
+
hosting_disabled: "hosting_disabled";
|
|
67
|
+
hosting_resumed: "hosting_resumed";
|
|
68
|
+
}>;
|
|
69
|
+
occurredAt: z.ZodISODateTime;
|
|
70
|
+
controlRevision: z.ZodString;
|
|
71
|
+
relatedMessageIds: z.ZodArray<z.ZodString>;
|
|
72
|
+
sourceOperationId: z.ZodString;
|
|
73
|
+
sourceKind: z.ZodLiteral<"dsh-control-result">;
|
|
74
|
+
payloadHash: z.ZodString;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
}, z.core.$strip>], "kind">;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
interface StoredDeliveryOperation {
|
|
79
|
+
readonly fingerprint: string;
|
|
80
|
+
readonly result: ImInboundOperationResult;
|
|
81
|
+
}
|
|
82
|
+
/** One durable record per complete conversation scope. */
|
|
83
|
+
export interface ImDeliveryAggregate {
|
|
84
|
+
readonly uploadIdentities?: Readonly<Record<string, import('./upload-types.ts').ImUploadIdentity>>;
|
|
85
|
+
readonly scope: ImDeliveryScope;
|
|
86
|
+
readonly scopeId: ImScopeId;
|
|
87
|
+
readonly uploadTargets?: Readonly<Record<string, ImUploadTarget>>;
|
|
88
|
+
readonly uploadPending?: readonly ImUploadObservation[];
|
|
89
|
+
readonly uploadObservedAt?: string;
|
|
90
|
+
readonly nextMessageSequenceNumber: number;
|
|
91
|
+
readonly nextOutboundSequenceNumber: number;
|
|
92
|
+
readonly cursor: import('./delivery-types.ts').ImConversationCursor;
|
|
93
|
+
readonly presentation?: import('./delivery-types.ts').ImConversationPresentation;
|
|
94
|
+
/** Latest platform-provided direct peer identity. Older records omit it. */
|
|
95
|
+
readonly directRecipient?: import('./types.ts').ImDirectRecipient;
|
|
96
|
+
readonly messages: Readonly<Record<string, ImInboundMessageView>>;
|
|
97
|
+
readonly messageIdsByExternalId: Readonly<Record<string, ImMessageId>>;
|
|
98
|
+
readonly operations: Readonly<Record<string, StoredDeliveryOperation>>;
|
|
99
|
+
readonly outbounds: Readonly<Record<string, ImOutboundView>>;
|
|
100
|
+
}
|
|
101
|
+
export declare const imDeliveryAggregateSchema: ZodType<ImDeliveryAggregate>;
|
|
102
|
+
/** One provider feed cursor plus queryable CAS receipts. */
|
|
103
|
+
export interface ImProviderCursorAggregate {
|
|
104
|
+
readonly id: ImProviderCursorId;
|
|
105
|
+
readonly owner: ImProviderCursorOwner;
|
|
106
|
+
readonly cursor: string | null;
|
|
107
|
+
readonly updatedAt: string;
|
|
108
|
+
readonly operations: Readonly<Record<string, {
|
|
109
|
+
readonly fingerprint: string;
|
|
110
|
+
readonly result: ImProviderCursorCommitResult;
|
|
111
|
+
}>>;
|
|
112
|
+
}
|
|
113
|
+
/** Parser for one provider-owned feed cursor plus its CAS receipts. */
|
|
114
|
+
export declare const imProviderCursorAggregateSchema: ZodType<ImProviderCursorAggregate>;
|
|
115
|
+
/** Batch frozen before Agent creation or steering begins. */
|
|
116
|
+
export interface ImPendingAdmission {
|
|
117
|
+
/** Analysis frozen for append/recovery; absence means it has not been attempted. */
|
|
118
|
+
readonly annotations?: readonly ImAdmissionAnnotation[];
|
|
119
|
+
/** Customer pause generation frozen before asynchronous admission work. */
|
|
120
|
+
readonly handlingEpoch?: number;
|
|
121
|
+
readonly admissionId: ImAdmissionId;
|
|
122
|
+
readonly messageIds: readonly ImMessageId[];
|
|
123
|
+
readonly triggerReasons: readonly ImTriggerReason[];
|
|
124
|
+
readonly createdAt: string;
|
|
125
|
+
}
|
|
126
|
+
/** Durable execution assignment for one conversation scope. */
|
|
127
|
+
export interface ImExecutionAggregate extends ImAgentTaskView {
|
|
128
|
+
readonly pendingAdmission?: ImPendingAdmission;
|
|
129
|
+
}
|
|
130
|
+
/** Frozen analysis parse path, shared by JSON records and compatibility fixtures. */
|
|
131
|
+
export declare const imAdmissionAnnotationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
132
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotationId, string>>;
|
|
133
|
+
annotatorId: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotatorId, string>>;
|
|
134
|
+
version: z.ZodString;
|
|
135
|
+
status: z.ZodLiteral<"success">;
|
|
136
|
+
text: z.ZodString;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotationId, string>>;
|
|
139
|
+
annotatorId: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotatorId, string>>;
|
|
140
|
+
version: z.ZodString;
|
|
141
|
+
status: z.ZodEnum<{
|
|
142
|
+
timeout: "timeout";
|
|
143
|
+
failed: "failed";
|
|
144
|
+
}>;
|
|
145
|
+
}, z.core.$strip>], "status">;
|
|
146
|
+
/** Parser for the frozen batch retained until its exact Session append commits. */
|
|
147
|
+
export declare const imPendingAdmissionSchema: z.ZodObject<{
|
|
148
|
+
annotations: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
149
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotationId, string>>;
|
|
150
|
+
annotatorId: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotatorId, string>>;
|
|
151
|
+
version: z.ZodString;
|
|
152
|
+
status: z.ZodLiteral<"success">;
|
|
153
|
+
text: z.ZodString;
|
|
154
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
155
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotationId, string>>;
|
|
156
|
+
annotatorId: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionAnnotatorId, string>>;
|
|
157
|
+
version: z.ZodString;
|
|
158
|
+
status: z.ZodEnum<{
|
|
159
|
+
timeout: "timeout";
|
|
160
|
+
failed: "failed";
|
|
161
|
+
}>;
|
|
162
|
+
}, z.core.$strip>], "status">>>;
|
|
163
|
+
handlingEpoch: z.ZodOptional<z.ZodNumber>;
|
|
164
|
+
admissionId: z.ZodPipe<z.ZodString, z.ZodTransform<ImAdmissionId, string>>;
|
|
165
|
+
messageIds: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<ImMessageId, string>>>;
|
|
166
|
+
triggerReasons: z.ZodArray<z.ZodEnum<{
|
|
167
|
+
direct: "direct";
|
|
168
|
+
mention: "mention";
|
|
169
|
+
"every-n": "every-n";
|
|
170
|
+
"fixed-interval": "fixed-interval";
|
|
171
|
+
}>>;
|
|
172
|
+
createdAt: z.ZodISODateTime;
|
|
173
|
+
}, z.core.$strip>;
|
|
174
|
+
/** Parser for one route-bound Agent task generation. */
|
|
175
|
+
export declare const imExecutionAggregateSchema: ZodType<ImExecutionAggregate>;
|
|
176
|
+
export {};
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/** Host-owned sqlite records for IM delivery. Opens one file and reads by key. */
|
|
2
|
+
import { type SqliteConnectionConfig } from './sqlite-connection.ts';
|
|
3
|
+
import type { NasHostLease, SqliteJournalMode } from './nas-host-lease.ts';
|
|
4
|
+
import type { ImUploadControlResult } from './upload-types.ts';
|
|
5
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
6
|
+
import { type ImDeliveryAggregate, type ImExecutionAggregate, type ImProviderCursorAggregate } from './delivery-schema.ts';
|
|
7
|
+
import type { ImAgentTaskId, ImCustomerSessionListRequest, ImCustomerSessionPage, ImCustomerListPage, ImCustomerListRequest, ImCustomerReadAckRequest, ImDeliveryScope, ImHandlingControl, ImOutboundRequestId, ImOutboundView, ImProviderCursorId, ImScopeId, ImSetHandlingControlRequest } from './delivery-types.ts';
|
|
8
|
+
import type { ImAccountId, ImPlatform } from './types.ts';
|
|
9
|
+
import type { ImInboundContentQuery } from './transport.ts';
|
|
10
|
+
import type { ImDeliveryAccountSlice } from './placement-slice.ts';
|
|
11
|
+
export declare const IM_DELIVERY_UNIT = "gestaltrun_im_delivery";
|
|
12
|
+
export declare const IM_DELIVERY_UNIT_VERSION = 1;
|
|
13
|
+
/** Monotonic physical layout version stored in `PRAGMA user_version`. */
|
|
14
|
+
export declare const IM_DELIVERY_SCHEMA_VERSION = 4;
|
|
15
|
+
/** 语句遇锁等待时长;node:sqlite 缺省为 0,任何持锁者都会让语句立即失败。NAS 交接窗口内旧实例的短暂事务通常在 2 秒内提交。 */
|
|
16
|
+
export declare const DEFAULT_DELIVERY_BUSY_TIMEOUT_MS = 2000;
|
|
17
|
+
/** 迁移单步遇锁重试的时间预算;超限抛 `IM_DELIVERY_SQLITE_BUSY`,由 supervisor 重启后再试,而不是无限期卡住启动。 */
|
|
18
|
+
export declare const DEFAULT_DELIVERY_MIGRATION_RETRY_BUDGET_MS = 30000;
|
|
19
|
+
/** Values one consumer derives from scope documents; created by `ImDeliverySqlite.projectScopes`. */
|
|
20
|
+
export interface ImScopeProjection<T> {
|
|
21
|
+
/**
|
|
22
|
+
* @param id - complete conversation identity.
|
|
23
|
+
* @returns the value derived from the stored document, or absence when none is stored; parses the document only when this projection has not derived it yet.
|
|
24
|
+
*/
|
|
25
|
+
get(id: ImScopeId): T | undefined;
|
|
26
|
+
/** Stop deriving and release the values. Idempotent; `get` throws afterwards. */
|
|
27
|
+
dispose(): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Durable delivery records with key lookups and small parsed-document caches.
|
|
31
|
+
* Scope descriptors and correlation identifiers derived from parsed or written documents stay in memory without a
|
|
32
|
+
* size bound, so account-wide listings and SDK matching do not re-read documents. Like the document caches, they
|
|
33
|
+
* require this connection to be the only writer.
|
|
34
|
+
* Physical unit tables stay compatible with the sqlite KV layout already on disk.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ImDeliverySqlite {
|
|
37
|
+
private readonly lease?;
|
|
38
|
+
private readonly releaseReservation?;
|
|
39
|
+
/** Test-only: throw after this many scopes have been committed during 1→2 backfill. */
|
|
40
|
+
static injectBackfillCrashAfter: number | undefined;
|
|
41
|
+
/** Test-only: override the committed backfill batch size. */
|
|
42
|
+
static backfillBatchSize: number | undefined;
|
|
43
|
+
/** Test-only: fail the next customer-index write so putScope can prove rollback. */
|
|
44
|
+
static failNextCustomerIndexWrite: boolean;
|
|
45
|
+
/** Test-only: fail the next cursor-account index write so putCursor can prove rollback. */
|
|
46
|
+
static failNextCursorIndexWrite: boolean;
|
|
47
|
+
private readonly db;
|
|
48
|
+
private readonly scopeSelect;
|
|
49
|
+
private readonly scopeUpsert;
|
|
50
|
+
private readonly cursorSelect;
|
|
51
|
+
private readonly cursorUpsert;
|
|
52
|
+
private readonly executionSelect;
|
|
53
|
+
private readonly executionUpsert;
|
|
54
|
+
private customerUnreadRevision;
|
|
55
|
+
private readonly customerUnreads;
|
|
56
|
+
private readonly scopeCache;
|
|
57
|
+
/**
|
|
58
|
+
* Descriptor of each stored scope seen since open or the last bulk removal. A scope id hashes its
|
|
59
|
+
* descriptor (`encodeImScopeId`), so an entry stays exact while that scope is stored.
|
|
60
|
+
*/
|
|
61
|
+
private readonly scopeDescriptors;
|
|
62
|
+
/** `correlationIdentifiers` of each parsed or written scope document, grouped by account; every write refreshes its entry. */
|
|
63
|
+
private readonly correlationByAccount;
|
|
64
|
+
/** Accounts whose every stored scope has a `correlationByAccount` entry; writes keep them complete until a bulk removal. */
|
|
65
|
+
private readonly correlationComplete;
|
|
66
|
+
private readonly projections;
|
|
67
|
+
private readonly executionCache;
|
|
68
|
+
private closed;
|
|
69
|
+
private readonly releaseFence;
|
|
70
|
+
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Open or create the delivery database and ensure unit tables plus lookup indexes.
|
|
73
|
+
* @param path - sqlite file path, or `:memory:`.
|
|
74
|
+
* @param options - 日志、连接锁和页缓存设置、锁等待与重试预算及可选云端租约;所有访问检查本地期限。
|
|
75
|
+
* @returns the opened record store.
|
|
76
|
+
*/
|
|
77
|
+
static open(path: string, options?: SqliteConnectionConfig & {
|
|
78
|
+
readonly journalMode?: SqliteJournalMode;
|
|
79
|
+
readonly lease?: NasHostLease;
|
|
80
|
+
readonly busyTimeoutMs?: number;
|
|
81
|
+
readonly migrationRetryBudgetMs?: number;
|
|
82
|
+
}): Promise<ImDeliverySqlite>;
|
|
83
|
+
/** @param requestId - outbox intent owning private staged bytes and SDK metadata. @returns stored JSON; the media owner validates before use. */
|
|
84
|
+
mediaPreparation(requestId: ImOutboundRequestId): unknown;
|
|
85
|
+
/** @param requestId - owning intent. @param value - media-owner validated private JSON, never included in history or Remote snapshots. */
|
|
86
|
+
saveMediaPreparation(requestId: ImOutboundRequestId, value: object): void;
|
|
87
|
+
/** @returns file intents whose external preparation started without committed metadata. */
|
|
88
|
+
unfinishedFilePreparationIds(): readonly ImOutboundRequestId[];
|
|
89
|
+
/** @param requestId - predecessor intent under retry consideration. @returns whether its external file preparation remains unconfirmed. */
|
|
90
|
+
hasUnfinishedFilePreparation(requestId: ImOutboundRequestId): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Read one conversation aggregate by scope id.
|
|
93
|
+
* @param id - complete conversation identity.
|
|
94
|
+
* @returns the stored aggregate, or absence.
|
|
95
|
+
*/
|
|
96
|
+
getScope(id: ImScopeId): ImDeliveryAggregate | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Persist one conversation aggregate and refresh its lookup indexes.
|
|
99
|
+
* @param id - complete conversation identity.
|
|
100
|
+
* @param value - stored aggregate.
|
|
101
|
+
*/
|
|
102
|
+
putScope(id: ImScopeId, value: ImDeliveryAggregate): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Read one provider cursor by id.
|
|
105
|
+
* @param id - provider feed identity.
|
|
106
|
+
* @returns the stored cursor, or absence.
|
|
107
|
+
*/
|
|
108
|
+
getCursor(id: ImProviderCursorId): ImProviderCursorAggregate | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Opaque provider cursors for one account.
|
|
111
|
+
* Stored operations stay in sqlite and are not returned.
|
|
112
|
+
* Cursor ids come from the derived account index and are ordered by id.
|
|
113
|
+
* @param accountId - cursor owner.
|
|
114
|
+
*/
|
|
115
|
+
checkpointCursors(accountId: ImAccountId): readonly {
|
|
116
|
+
readonly streamId: string;
|
|
117
|
+
readonly cursor: string;
|
|
118
|
+
}[];
|
|
119
|
+
/**
|
|
120
|
+
* Durable unsubmitted input, unsettled-send and unknown-send counts for one real account.
|
|
121
|
+
* Message rows are not copied out. Reads the derived per-scope counts maintained with each scope write.
|
|
122
|
+
* @param accountId - conversation owner.
|
|
123
|
+
*/
|
|
124
|
+
checkpointCounts(accountId: ImAccountId): {
|
|
125
|
+
readonly pendingCount: number;
|
|
126
|
+
readonly unknownSendCount: number;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Persist one provider cursor.
|
|
130
|
+
* @param id - provider feed identity.
|
|
131
|
+
* @param value - stored cursor.
|
|
132
|
+
*/
|
|
133
|
+
putCursor(id: ImProviderCursorId, value: ImProviderCursorAggregate): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Read one Agent task generation by id.
|
|
136
|
+
* @param id - durable task identity.
|
|
137
|
+
* @returns the stored generation, or absence.
|
|
138
|
+
*/
|
|
139
|
+
getExecution(id: ImAgentTaskId): ImExecutionAggregate | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Persist one Agent task generation and refresh its lookup indexes.
|
|
142
|
+
* @param id - durable task identity.
|
|
143
|
+
* @param value - stored generation.
|
|
144
|
+
*/
|
|
145
|
+
putExecution(id: ImAgentTaskId, value: ImExecutionAggregate): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Apply one transform to a stored execution.
|
|
148
|
+
* @param id - durable task identity.
|
|
149
|
+
* @param fn - synchronous transform of the current record.
|
|
150
|
+
* @returns the stored next record.
|
|
151
|
+
*/
|
|
152
|
+
updateExecution(id: ImAgentTaskId, fn: (current: ImExecutionAggregate) => ImExecutionAggregate): Promise<ImExecutionAggregate>;
|
|
153
|
+
/**
|
|
154
|
+
* List conversations that currently have pending live inbound.
|
|
155
|
+
* @returns scopes whose pendingCount is greater than zero.
|
|
156
|
+
*/
|
|
157
|
+
pendingScopes(): ImDeliveryScope[];
|
|
158
|
+
/**
|
|
159
|
+
* List conversations with an interrupted platform send.
|
|
160
|
+
* @returns scope ids that currently have a dispatching outbound.
|
|
161
|
+
*/
|
|
162
|
+
dispatchingScopeIds(): readonly ImScopeId[];
|
|
163
|
+
/**
|
|
164
|
+
* List conversations owned by one configured account.
|
|
165
|
+
* Membership comes from the account index; descriptors come from memory or the conversation summaries, not documents.
|
|
166
|
+
* @param accountId - durable IM account.
|
|
167
|
+
* @returns stored scopes for that account, in scope-id order.
|
|
168
|
+
*/
|
|
169
|
+
scopesForAccount(accountId: ImAccountId): ImDeliveryScope[];
|
|
170
|
+
/**
|
|
171
|
+
* Read one conversation's descriptor without parsing its document.
|
|
172
|
+
* @param id - complete conversation identity.
|
|
173
|
+
* @returns the stored scope, or absence when no document is stored under `id`.
|
|
174
|
+
*/
|
|
175
|
+
scopeDescriptor(id: ImScopeId): ImDeliveryScope | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Report whether one conversation holds received live inbound above its suppression watermark.
|
|
178
|
+
* Reads the pending index written with each document, which holds a scope exactly when its `cursor.pendingCount` is positive.
|
|
179
|
+
* @param id - complete conversation identity.
|
|
180
|
+
* @returns false for a scope without pending input or without a document.
|
|
181
|
+
*/
|
|
182
|
+
hasPendingInbound(id: ImScopeId): boolean;
|
|
183
|
+
/** @param accountId - account owning the conversations. @param platform - admitted platform. @param uid - unqualified buyer UID. @returns matching real direct scopes using summary rows; older empty conversations use their saved direct recipient. The lookup does not populate the aggregate cache. */
|
|
184
|
+
directScopesForPeer(accountId: ImAccountId, platform: ImPlatform, uid: string): ImDeliveryScope[];
|
|
185
|
+
/** @param accountId - listener account. @param platform - admitted platform. @param request - platform message identity and optional conversation restriction. @returns matching real scopes from message rows and summaries, without parsing aggregates. */
|
|
186
|
+
inboundScopes(accountId: ImAccountId, platform: ImPlatform, request: ImInboundContentQuery): ImDeliveryScope[];
|
|
187
|
+
/**
|
|
188
|
+
* Conversations of one account whose document holds one of `identifiers` as the external message id of a live
|
|
189
|
+
* external inbound, or as the request or external message id of a sent outbound.
|
|
190
|
+
* The first call for an account parses the documents not yet parsed since open or the last bulk removal; later calls read no rows.
|
|
191
|
+
* @param accountId - durable IM account.
|
|
192
|
+
* @param identifiers - exact provider message ids or outbound request ids.
|
|
193
|
+
* @returns matching stored scopes, in scope-id order.
|
|
194
|
+
*/
|
|
195
|
+
scopesWithCorrelationIdentifier(accountId: ImAccountId, identifiers: ReadonlySet<string>): ImDeliveryScope[];
|
|
196
|
+
/**
|
|
197
|
+
* Derive one value from every scope document parsed or written from now on. Each committed write refreshes the
|
|
198
|
+
* value and bulk removals clear it. A derivation failure during a write leaves that scope underived, and the next
|
|
199
|
+
* `get` derives it again and throws the failure to its caller; the committed write is unaffected.
|
|
200
|
+
* @param derive - pure function of one document; it must not keep the document.
|
|
201
|
+
* @returns accessor of the derived values.
|
|
202
|
+
*/
|
|
203
|
+
projectScopes<T extends object>(derive: (value: ImDeliveryAggregate) => T): ImScopeProjection<T>;
|
|
204
|
+
/** @returns scopes with durable observations not yet transferred to the external queue. Reads the derived upload-pending index. */
|
|
205
|
+
uploadScopeIds(): readonly ImScopeId[];
|
|
206
|
+
/**
|
|
207
|
+
* Resolve the newest execution bound to one Agent Session.
|
|
208
|
+
* @param sessionId - IM Agent Session.
|
|
209
|
+
* @returns that Session's newest task, or absence.
|
|
210
|
+
*/
|
|
211
|
+
executionForSession(sessionId: SessionId): ImExecutionAggregate | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* Resolve the newest execution for one conversation.
|
|
214
|
+
* @param scopeId - complete conversation identity.
|
|
215
|
+
* @returns the highest-generation task, or absence.
|
|
216
|
+
*/
|
|
217
|
+
latestExecutionForScope(scopeId: ImScopeId): ImExecutionAggregate | undefined;
|
|
218
|
+
/**
|
|
219
|
+
* List task generations for one conversation in generation order.
|
|
220
|
+
* @param scopeId - complete conversation identity.
|
|
221
|
+
* @returns stored generations for that scope.
|
|
222
|
+
*/
|
|
223
|
+
executionsForScope(scopeId: ImScopeId): ImExecutionAggregate[];
|
|
224
|
+
/**
|
|
225
|
+
* Newest execution per conversation, resolved with one indexed join per chunk of scope ids.
|
|
226
|
+
* Ties on generation resolve to the highest task id, the same row the per-scope
|
|
227
|
+
* `ORDER BY generation DESC LIMIT 1` query returns.
|
|
228
|
+
* @param scopeIds - complete conversation identities.
|
|
229
|
+
* @returns the highest-generation task of each scope that has one.
|
|
230
|
+
*/
|
|
231
|
+
latestExecutionsForScopes(scopeIds: readonly ImScopeId[]): Map<ImScopeId, ImExecutionAggregate>;
|
|
232
|
+
/**
|
|
233
|
+
* @param accountId - durable IM account.
|
|
234
|
+
* @returns ids the account index lists and the scope table stores, in scope-id order.
|
|
235
|
+
*/
|
|
236
|
+
private accountScopeIds;
|
|
237
|
+
/**
|
|
238
|
+
* Fill `scopeDescriptors` for stored ids from the conversation summaries written in the same transaction as each
|
|
239
|
+
* document, one statement per chunk. Ids whose summary is absent or invalid fall back to their documents.
|
|
240
|
+
* @param ids - ids whose documents are stored.
|
|
241
|
+
*/
|
|
242
|
+
private loadScopeDescriptors;
|
|
243
|
+
/** @param ids - scope ids. @returns known descriptors in the order of `ids`; unknown ids are absent. */
|
|
244
|
+
private descriptorsOf;
|
|
245
|
+
/**
|
|
246
|
+
* Stored scope documents for explicit ids, fetched with one join per chunk.
|
|
247
|
+
* Ids without a stored document are absent from the result.
|
|
248
|
+
* @param ids - complete conversation identities.
|
|
249
|
+
* @returns parsed aggregates keyed by scope id.
|
|
250
|
+
*/
|
|
251
|
+
private scopeDocuments;
|
|
252
|
+
/**
|
|
253
|
+
* Generations of every listed conversation in generation order, resolved with one
|
|
254
|
+
* indexed join per chunk. Scopes never overlap chunk boundaries, so per-scope order matches `executionsForScope`.
|
|
255
|
+
* @param scopeIds - complete conversation identities.
|
|
256
|
+
* @returns per-scope stored generations keyed by scope id.
|
|
257
|
+
*/
|
|
258
|
+
private executionsForScopes;
|
|
259
|
+
/**
|
|
260
|
+
* Export all durable real-conversation facts for one account, excluding simulations and derived indexes.
|
|
261
|
+
* Documents, generations, read positions and handling controls resolve in a fixed number of
|
|
262
|
+
* batched queries, not per scope.
|
|
263
|
+
* @param accountId - source account; the caller drains writers before taking a final snapshot.
|
|
264
|
+
* @returns independent account slice; it contains buyer data and must not be logged.
|
|
265
|
+
*/
|
|
266
|
+
exportAccountSlice(accountId: ImAccountId): ImDeliveryAccountSlice;
|
|
267
|
+
/**
|
|
268
|
+
* Read positions of one reader batch across scopes, grouped per scope.
|
|
269
|
+
* Reader order inside each group matches the per-scope point query (reader-id order).
|
|
270
|
+
* @param scopeIds - complete conversation identities.
|
|
271
|
+
* @returns acknowledged live-inbound positions keyed by scope id.
|
|
272
|
+
*/
|
|
273
|
+
private readPositionsForScopes;
|
|
274
|
+
/**
|
|
275
|
+
* Handling controls batch across scopes.
|
|
276
|
+
* @param scopeIds - complete conversation identities.
|
|
277
|
+
* @returns stored controls keyed by scope id; scopes without a control are absent.
|
|
278
|
+
*/
|
|
279
|
+
private handlingControlsForScopes;
|
|
280
|
+
/**
|
|
281
|
+
* Replace one account's real facts in one transaction, preserving other accounts, simulations and maximum reader positions.
|
|
282
|
+
* @param slice - wire-validated slice authorized for the target epoch; caller owns stopped listeners, drained queues and exclusive activation. Epoch receipts belong to the handoff journal.
|
|
283
|
+
* @throws ImPlacementSliceError for identities already owned by another account; transaction failures leave the prior slice intact unless the NAS fence closes the database, in which case the caller must remain stopped and reconcile.
|
|
284
|
+
*/
|
|
285
|
+
replaceAccountSlice(slice: ImDeliveryAccountSlice): void;
|
|
286
|
+
/**
|
|
287
|
+
* Record a provider actor id that belongs to one configured account.
|
|
288
|
+
* @param accountId - durable IM account.
|
|
289
|
+
* @param actorId - provider actor observed on a native-client or echo frame.
|
|
290
|
+
*/
|
|
291
|
+
rememberNativeActor(accountId: ImAccountId, actorId: string): void;
|
|
292
|
+
/**
|
|
293
|
+
* Report whether one provider actor belongs to a configured account.
|
|
294
|
+
* @param accountId - durable IM account.
|
|
295
|
+
* @param actorId - provider actor id.
|
|
296
|
+
* @returns true when that actor was stored for the account.
|
|
297
|
+
*/
|
|
298
|
+
isNativeActor(accountId: ImAccountId, actorId: string): boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Locate the conversation that owns one outbound request.
|
|
301
|
+
* @param requestId - outbound identity.
|
|
302
|
+
* @returns that request's scope and stored outbound, or absence.
|
|
303
|
+
*/
|
|
304
|
+
outboundOwner(requestId: ImOutboundRequestId): {
|
|
305
|
+
readonly scope: ImDeliveryScope;
|
|
306
|
+
readonly outbound: ImOutboundView;
|
|
307
|
+
} | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Report whether the delivery unit currently has no records.
|
|
310
|
+
* @returns true when scopes, cursors, and executions are empty.
|
|
311
|
+
*/
|
|
312
|
+
empty(): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Delete every delivery record and lookup index.
|
|
315
|
+
*/
|
|
316
|
+
deleteAll(): Promise<void>;
|
|
317
|
+
/** Release the sqlite connection. Idempotent. */
|
|
318
|
+
close(): void;
|
|
319
|
+
private backfillIndexes;
|
|
320
|
+
private backfillNativeActors;
|
|
321
|
+
private markLookupReady;
|
|
322
|
+
private markNativeReady;
|
|
323
|
+
private insertScopeIndexes;
|
|
324
|
+
private clearScopeIndexes;
|
|
325
|
+
private insertNativeActors;
|
|
326
|
+
private insertExecutionIndexes;
|
|
327
|
+
private clearExecutionIndexes;
|
|
328
|
+
private rememberScope;
|
|
329
|
+
/** Drop parsed scope documents and every projection derived from them after documents were removed or replaced in bulk. */
|
|
330
|
+
private forgetScopes;
|
|
331
|
+
private rememberExecution;
|
|
332
|
+
/**
|
|
333
|
+
* List customer rows for one account and source, grouped by customer key.
|
|
334
|
+
* @param request - account, real/simulation filter, optional substring, and reader.
|
|
335
|
+
*/
|
|
336
|
+
listCustomers(request: ImCustomerListRequest): ImCustomerListPage;
|
|
337
|
+
/**
|
|
338
|
+
* Read customer Session references without loading unread or handling state.
|
|
339
|
+
* @param request - account, source, search and keyset cursor.
|
|
340
|
+
* @returns Session references in the same order as the full customer list.
|
|
341
|
+
*/
|
|
342
|
+
listCustomerSessions(request: ImCustomerSessionListRequest): ImCustomerSessionPage;
|
|
343
|
+
private customerGroups;
|
|
344
|
+
/**
|
|
345
|
+
* Advance one reader's inbound watermark with max semantics.
|
|
346
|
+
* @param request - reader, scope, and observed arrival sequence.
|
|
347
|
+
*/
|
|
348
|
+
ackCustomerRead(request: ImCustomerReadAckRequest): void;
|
|
349
|
+
/**
|
|
350
|
+
* Persist one scope's automatic-handling pause fact.
|
|
351
|
+
* @param request - scope and pause fields.
|
|
352
|
+
* @param upload - successful product operation to journal atomically; absent for safety-only pauses.
|
|
353
|
+
* @returns committed control revision. Storage failure rolls back both control and observation.
|
|
354
|
+
*/
|
|
355
|
+
setHandlingControl(request: ImSetHandlingControlRequest, upload?: ImUploadControlResult): ImHandlingControl;
|
|
356
|
+
/**
|
|
357
|
+
* Read one scope's automatic-handling pause fact.
|
|
358
|
+
* @param scopeId - complete conversation identity.
|
|
359
|
+
*/
|
|
360
|
+
getHandlingControl(scopeId: ImScopeId): ImHandlingControl | undefined;
|
|
361
|
+
private requireHandlingControl;
|
|
362
|
+
private customerMatches;
|
|
363
|
+
private likeMatch;
|
|
364
|
+
/**
|
|
365
|
+
* One customer's acknowledged live-inbound watermarks, batched across scopes.
|
|
366
|
+
* @param readerId - reading customer-service reader.
|
|
367
|
+
* @param scopeIds - complete conversation identities of one page.
|
|
368
|
+
* @returns acknowledged sequence per scope; scopes without an ack read as 0.
|
|
369
|
+
*/
|
|
370
|
+
private readWatermarksForScopes;
|
|
371
|
+
/** Reuse per-reader counts for this delivery revision; acknowledgements invalidate their reader. */
|
|
372
|
+
private customerUnreadCounts;
|
|
373
|
+
/**
|
|
374
|
+
* Unread live-inbound counts for scopes with their per-scope watermark, one range count per
|
|
375
|
+
* scope through a values join over the message index. Scopes without unread messages are absent.
|
|
376
|
+
* @param scopeIds - every scope the counts must cover; scopes missing from `watermarks` read from 0.
|
|
377
|
+
* @param watermarks - acknowledged sequence per scope id.
|
|
378
|
+
* @returns unread count per scope id.
|
|
379
|
+
*/
|
|
380
|
+
private unreadCountsForScopes;
|
|
381
|
+
private customerRow;
|
|
382
|
+
private latestExecutionRow;
|
|
383
|
+
private updateSummaryExecution;
|
|
384
|
+
private changeWatermark;
|
|
385
|
+
private assertIndexReady;
|
|
386
|
+
private assertOpen;
|
|
387
|
+
}
|