@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.
@@ -0,0 +1,91 @@
1
+ import type { ImDeliverySqlite } from './delivery-sqlite.ts';
2
+ import type { ImBeginOutboundAttemptRequest, ImBeginOutboundAttemptResult, ImCancelPendingAiRequest, ImCommitProviderCursorRequest, ImConversationCursor, ImConversationPresentation, ImDeliveryOperationId, ImDeliveryScope, ImGetOutboundRequest, ImHistoryPage, ImHistoryQueryRequest, ImImportJsonlHistoryRequest, ImImportJsonlHistoryResult, ImInboundMessageView, ImInboundOperationQuery, ImInboundPageResult, ImIngestInboundPageRequest, ImMarkSubmittedRequest, ImMarkSubmittedResult, ImMessageId, ImMessageSource, ImOutboundAttemptId, ImOutboundPage, ImOutboundQueryRequest, ImOutboundRequestId, ImOutboundRouteBinding, ImOutboundView, ImPendingInboundRequest, ImProviderCursorCommitResult, ImProviderCursorId, ImProviderCursorOperationQuery, ImProviderCursorOwner, ImProviderCursorView, ImRealDeliveryScope, ImRegisterOutboundRequest, ImScopeId, ImSettleOutboundAttemptRequest, ImSettleSimulationOutboundRequest } from './delivery-types.ts';
3
+ import type { ImAccountId, ImPlatform, ImRouteResolution } from './types.ts';
4
+ interface ImDeliveryHost {
5
+ automaticHandlingBlocked(scopeId: ImScopeId): boolean;
6
+ inspectAccount(id: ImAccountId): {
7
+ readonly platform: ImPlatform;
8
+ readonly paused: boolean;
9
+ readonly revision: import('./types.ts').ImRevision;
10
+ } | undefined;
11
+ resolveRoute(scope: ImRealDeliveryScope): ImRouteResolution | undefined;
12
+ publish(change: {
13
+ readonly scope: ImDeliveryScope;
14
+ readonly scopeId: ImScopeId;
15
+ readonly kind: 'inbound' | 'submitted' | 'outbound';
16
+ readonly messageIds?: readonly ImMessageId[];
17
+ readonly requestId?: ImOutboundRequestId;
18
+ }): void;
19
+ }
20
+ /**
21
+ * Encode every scope component in an ordered JSON tuple before hashing.
22
+ * @param scope - complete real or simulation conversation identity.
23
+ * @returns stable scope identifier shared by history, Session sources, and outbox rows.
24
+ */
25
+ export declare function encodeImScopeId(scope: ImDeliveryScope): ImScopeId;
26
+ /**
27
+ * Encode the platform account and provider feed name that jointly own a cursor.
28
+ * @param owner - provider cursor owner.
29
+ * @returns stable provider cursor identifier.
30
+ */
31
+ export declare function encodeImProviderCursorId(owner: ImProviderCursorOwner): ImProviderCursorId;
32
+ /** One-record mutations for complete conversation scopes. */
33
+ export declare class ImDeliveryStore {
34
+ private readonly records;
35
+ private readonly host;
36
+ private readonly tails;
37
+ private readonly cursorTails;
38
+ /** @param records - sqlite delivery records. @param host - account policy and post-commit publisher. */
39
+ constructor(records: ImDeliverySqlite, host: ImDeliveryHost);
40
+ /** Mark interrupted platform calls uncertain before new work can claim them. */
41
+ recoverInterruptedAttempts(): Promise<void>;
42
+ ingestInboundPage(request: ImIngestInboundPageRequest): Promise<ImInboundPageResult>;
43
+ queryInboundOperation(scope: ImDeliveryScope, operationId: ImDeliveryOperationId): ImInboundOperationQuery;
44
+ getConversationCursor(scope: ImDeliveryScope): ImConversationCursor;
45
+ /** @param scope - durable conversation. @returns last admitted presentation, including the assigned service account when known. */
46
+ getConversationPresentation(scope: ImDeliveryScope): ImConversationPresentation | undefined;
47
+ getProviderCursor(owner: ImProviderCursorOwner): ImProviderCursorView;
48
+ commitProviderCursor(request: ImCommitProviderCursorRequest): Promise<ImProviderCursorCommitResult>;
49
+ queryProviderCursorOperation(owner: ImProviderCursorOwner, operationId: ImDeliveryOperationId): ImProviderCursorOperationQuery;
50
+ queryHistory(request: ImHistoryQueryRequest): ImHistoryPage;
51
+ pendingInbound(request: ImPendingInboundRequest): readonly ImInboundMessageView[];
52
+ /**
53
+ * Consume the current received live batch without an Agent turn.
54
+ * A later allow only admits newer sequence numbers.
55
+ * @param scope - conversation whose policy just refused admission.
56
+ */
57
+ suppressUnadmitted(scope: ImDeliveryScope): Promise<void>;
58
+ messageSource(scope: ImDeliveryScope, messageId: ImMessageId): ImMessageSource;
59
+ /** @param source - durable Session message source. @returns matched scope, or absence for stale or foreign evidence. */
60
+ matchMessageSource(source: ImMessageSource): {
61
+ readonly scope: ImDeliveryScope;
62
+ readonly messageId: ImMessageId;
63
+ } | undefined;
64
+ /** @param scope - complete scope. @param messageId - inbound identity. @returns stored row. */
65
+ getInbound(scope: ImDeliveryScope, messageId: ImMessageId): ImInboundMessageView;
66
+ markSubmitted(request: ImMarkSubmittedRequest): Promise<ImMarkSubmittedResult>;
67
+ importJsonlHistory(request: ImImportJsonlHistoryRequest): Promise<ImImportJsonlHistoryResult>;
68
+ registerOutbound(request: ImRegisterOutboundRequest, frozenBinding?: ImOutboundRouteBinding): Promise<ImOutboundView>;
69
+ beginOutboundAttempt(request: ImBeginOutboundAttemptRequest): Promise<ImBeginOutboundAttemptResult>;
70
+ /** @param request - Owning attempt. @returns Whether its frozen route and handling epoch still authorize an external submission. */
71
+ authorizeOutboundSubmission(request: ImBeginOutboundAttemptRequest & {
72
+ readonly attemptId: ImOutboundAttemptId;
73
+ }): boolean;
74
+ settleOutboundAttempt(request: ImSettleOutboundAttemptRequest): Promise<ImOutboundView>;
75
+ settleSimulationOutbound(request: ImSettleSimulationOutboundRequest): Promise<ImOutboundView>;
76
+ getOutbound(request: ImGetOutboundRequest): ImOutboundView | undefined;
77
+ queryOutbound(request: ImOutboundQueryRequest): ImOutboundPage;
78
+ cancelPendingAi(request: ImCancelPendingAiRequest): Promise<readonly ImOutboundView[]>;
79
+ findSentOutbound(scope: ImRealDeliveryScope, externalMessageId: string): ImOutboundView | undefined;
80
+ findUnknownOutbound(scope: ImRealDeliveryScope, text: string): ImOutboundView | undefined;
81
+ private registrationPolicy;
82
+ private handlingRevoked;
83
+ private dispatchFailure;
84
+ private assertRealScope;
85
+ private lookup;
86
+ private require;
87
+ private mutate;
88
+ private enqueue;
89
+ private enqueueCursor;
90
+ }
91
+ export {};
@@ -0,0 +1,8 @@
1
+ /** Stable IM runtime configuration failure codes. */
2
+ export type ImRuntimeErrorCode = 'IM_ACCOUNT_NOT_FOUND' | 'IM_ACCOUNT_EXISTS' | 'IM_ACCOUNT_SETUP_CONFIRMED' | 'IM_ACCOUNT_SETUP_NOT_FOUND' | 'IM_IDENTITY_MISMATCH' | 'IM_DELIVERY_OPERATION_REUSED' | 'IM_DELIVERY_SCOPE_INVALID' | 'IM_JSONL_INVALID' | 'IM_LOGIN_ATTEMPT_NOT_FOUND' | 'IM_LOGIN_UNAVAILABLE' | 'IM_MANUAL_ACCOUNT_UNAVAILABLE' | 'IM_MANUAL_MESSAGE_INVALID' | 'IM_MANUAL_RETRY_INVALID' | 'IM_MESSAGE_ALREADY_SUBMITTED' | 'IM_MESSAGE_NOT_FOUND' | 'IM_OPERATION_REUSED' | 'IM_OUTBOUND_ATTEMPT_MISMATCH' | 'IM_OUTBOUND_NOT_FOUND' | 'IM_OUTBOUND_REQUEST_REUSED' | 'IM_OUTBOUND_STATE_INVALID' | 'IM_ROUTE_INVALID' | 'IM_ROUTE_POLICY_DENIED' | 'IM_REAL_SESSION_NOT_FOUND' | 'IM_SESSION_PERSISTENCE_UNAVAILABLE' | 'IM_SIMULATION_INSTANCE_ACTIVE' | 'IM_SIMULATION_INSTANCE_NOT_FOUND' | 'IM_SIMULATION_INSTANCE_NOT_RUNNING' | 'IM_SIMULATION_SESSION_INVALID' | 'IM_SIMULATION_TARGET_INVALID';
3
+ /** Structured IM runtime failure for requests that cannot produce a durable receipt. */
4
+ export declare class ImRuntimeError extends Error {
5
+ readonly code: ImRuntimeErrorCode;
6
+ /** @param code - stable failure code. @param message - diagnostic detail. */
7
+ constructor(code: ImRuntimeErrorCode, message: string);
8
+ }
@@ -0,0 +1,19 @@
1
+ /** Product-owned IM Host runtime and transport registry. */
2
+ import './session-events.ts';
3
+ export type * from './types.ts';
4
+ export type * from './transport.ts';
5
+ export type { ImRuntimeService } from './service-types.ts';
6
+ export { ImRuntimeError } from './errors.ts';
7
+ export type { ImRuntimeErrorCode } from './errors.ts';
8
+ export { imRuntimeDomainSpec } from './schema.ts';
9
+ export { encodeImProviderCursorId, encodeImScopeId } from './delivery.ts';
10
+ export { IM_DELIVERY_SCHEMA_VERSION, ImDeliverySqlite } from './delivery-sqlite.ts';
11
+ export { ImTransportError, ImTransports } from './transports.ts';
12
+ export type { ImTransportErrorCode } from './transports.ts';
13
+ export { ImRoutePolicies } from './policies.ts';
14
+ export type { ImPolicyCheckKind, ImPolicyCheckRequest, ImPolicyDecision, ImRoutePolicy } from './policies.ts';
15
+ export type { ImRouteControllerId } from './types.ts';
16
+ export { resolveRouteAgentPreset } from './route-resolve.ts';
17
+ export { ImRuntime, ImRuntime as default } from './runtime.ts';
18
+ export type { Config as ImRuntimeConfig } from './runtime.ts';
19
+ export type { ImHandlingPausedEvent } from './session-events.ts';
@@ -0,0 +1,53 @@
1
+ /** Registry of product controllers that authorize IM admission and automated sends. */
2
+ import { Context, Service } from '@deepseek-ai/cordis';
3
+ import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types';
4
+ import type { ImDeliveryScope } from './delivery-types.ts';
5
+ import type { ImRouteControllerId, ImRouteId } from './types.ts';
6
+ export type { ImRouteControllerId };
7
+ /** Moments a declared route controller must authorize. */
8
+ export type ImPolicyCheckKind = 'admit' | 'send' | 'manual-send' | 'recover' | 'simulation-end';
9
+ /** One authorization request for a declared controller. */
10
+ export interface ImPolicyCheckRequest {
11
+ readonly kind: ImPolicyCheckKind;
12
+ readonly controller: ImRouteControllerId;
13
+ readonly scope: ImDeliveryScope;
14
+ readonly routeId: ImRouteId;
15
+ readonly workspaceId: WorkspaceId;
16
+ }
17
+ /** Allow, or refuse with a stable code. */
18
+ export type ImPolicyDecision = {
19
+ readonly allow: true;
20
+ } | {
21
+ readonly allow: false;
22
+ readonly code: string;
23
+ readonly message: string;
24
+ };
25
+ /** Product Provider that owns one controller identity. */
26
+ export interface ImRoutePolicy {
27
+ check(request: ImPolicyCheckRequest): ImPolicyDecision | Promise<ImPolicyDecision>;
28
+ }
29
+ declare module '@deepseek-ai/cordis' {
30
+ interface Context {
31
+ /** IM admission and automated-send policies keyed by route controller. */
32
+ imRoutePolicies: ImRoutePolicies;
33
+ }
34
+ }
35
+ /** Registry whose entries live and die with their registering Cordis fiber. */
36
+ export declare class ImRoutePolicies extends Service {
37
+ private readonly policies;
38
+ /** @param ctx - owning Cordis context. */
39
+ constructor(ctx: Context);
40
+ /**
41
+ * Register the policy for one controller identity.
42
+ * @param controller - product controller recorded on the route.
43
+ * @param policy - authorization Provider.
44
+ * @returns disposer that releases the registration.
45
+ */
46
+ register(controller: ImRouteControllerId, policy: ImRoutePolicy): () => void;
47
+ /**
48
+ * Authorize one admission or send for a declared controller.
49
+ * Missing Providers refuse; ordinary routes without a controller skip this registry.
50
+ * @param request - controller, scope, and check kind.
51
+ */
52
+ authorize(request: ImPolicyCheckRequest): Promise<ImPolicyDecision>;
53
+ }
@@ -0,0 +1,10 @@
1
+ /** Explicit Agent-preset resolution for an IM route. */
2
+ import type { ImRouteView } from './types.ts';
3
+ /**
4
+ * Resolve the Agent preset a route uses.
5
+ * A recorded preset is used as-is. Absence takes the runtime default.
6
+ * Callers must fail when a recorded preset cannot mount; they must not fall back.
7
+ * @param route - stored route fields.
8
+ * @param defaultId - AgentPresets default when the route omitted a preset.
9
+ */
10
+ export declare function resolveRouteAgentPreset(route: Pick<ImRouteView, 'agentPreset'>, defaultId: string): string;
@@ -0,0 +1,360 @@
1
+ import { Context, Service } from '@deepseek-ai/cordis';
2
+ import type { UserMessage } from '@deepseek-ai/dsh-llm';
3
+ import { type SessionId } from '@deepseek-ai/dsh-session';
4
+ import './session-events.ts';
5
+ import type { WorkspaceId } from '@deepseek-ai/dsh-workspace';
6
+ import { type ZodType } from 'zod';
7
+ import type { ImExecutionAggregate } from './delivery-schema.ts';
8
+ import { ImRoutePolicies } from './policies.ts';
9
+ import type { ImPolicyCheckKind, ImPolicyCheckRequest, ImPolicyDecision } from './policies.ts';
10
+ import { ImTransports } from './transports.ts';
11
+ import type { ImAutomaticSendAuthorization } from './transport.ts';
12
+ import type { ImBeginOutboundAttemptRequest, ImBeginOutboundAttemptResult, ImAgentTaskId, ImAgentTaskView, ImCancelPendingAiRequest, ImCommitProviderCursorRequest, ImConversationCursor, ImCustomerListPage, ImCustomerListRequest, ImCustomerReadAckRequest, ImDeliveryChange, ImDeliveryOperationId, ImDeliveryScope, ImGetOutboundRequest, ImHandlingControl, ImHistoryPage, ImHistoryQueryRequest, ImImportJsonlHistoryRequest, ImImportJsonlHistoryResult, ImInboundMessageView, ImInboundSenderEvidence, ImInboundOperationQuery, ImInboundPageResult, ImIngestInboundPageRequest, ImMarkSubmittedRequest, ImMarkSubmittedResult, ImManualMessageQuery, ImManualMessageQueryRequest, ImManualMessageResult, ImMessageId, ImMessageSource, ImOutboundPage, ImOutboundQueryRequest, ImOutboundAttemptId, ImOutboundRouteBinding, ImOutboundView, ImPendingInboundRequest, ImProviderCursorCommitResult, ImProviderCursorOperationQuery, ImProviderCursorOwner, ImProviderCursorView, ImRealDeliveryScope, ImRealSessionBinding, ImRegisterOutboundRequest, ImRetryManualMessageRequest, ImSendManualMessageRequest, ImSessionReconciliationResult, ImSenderAttribution, ImSetHandlingControlRequest, ImSettleOutboundAttemptRequest, ImSettleSimulationOutboundRequest, ImSimulationDeliveryScope, ImSimulationInstanceId, ImScopeId } from './delivery-types.ts';
13
+ import type { ImAccountId, ImAccountCandidate, ImAccountSetupId, ImAccountSetupPreview, ImCancelAccountSetupResult, ImConfirmAccountSetupRequest, ImAccountLifecycleRequest, ImAccountSetupRequest, ImAccountMutationResult, ImAccountOperationQuery, ImAccountView, ImAssignedActorCandidate, ImConversationCandidate, ImConversationCandidatePage, ImConversationKind, ImDirectRecipient, ImCreateRouteRequest, ImDeleteRouteRequest, ImOperationId, ImPlatform, ImPlatformLoginAttemptId, ImPlatformLoginStatus, ImRebindRouteRequest, ImRemoveSimulationTargetRequest, ImRouteMutationResult, ImRouteOperationQuery, ImRouteResolution, ImRouteTarget, ImRouteView, ImRuntimeChange, ImRuntimeSnapshot, ImSaveRouteRequest, ImSaveSimulationTargetRequest, ImSetAccountPausedRequest, ImSimulationTargetMutationResult, ImSimulationTargetOperationQuery, ImCreateSimulationInstanceRequest, ImSimulationInjectionQuery, ImInjectSimulationManagedHumanRequest, ImInjectSimulationMemberRequest, ImImportSimulationHistoryRequest, ImImportSimulationHistoryResult, ImSimulationInstanceView, ImSimulationSessionScope, ImSimulationTargetView } from './types.ts';
14
+ import type { ImRuntimeService } from './service-types.ts';
15
+ declare module '@deepseek-ai/cordis' {
16
+ interface Events {
17
+ /**
18
+ * Synchronous controller veto immediately before an automatic external submission.
19
+ * @param request - Current route controller and conversation.
20
+ * @returns A refusal to block submission, or void to delegate.
21
+ * @mode bail
22
+ */
23
+ 'imRuntime/authorize-submission'(request: ImPolicyCheckRequest): Extract<ImPolicyDecision, {
24
+ allow: false;
25
+ }> | void;
26
+ }
27
+ }
28
+ /** Stable Wangwang refusal when a direct send has no observed counterpart sender. */
29
+ export declare const WANGWANG_DIRECT_RECIPIENT_UNAVAILABLE = "WANGWANG_DIRECT_RECIPIENT_UNAVAILABLE";
30
+ /** Runtime limits applied to one durable Agent admission. */
31
+ export interface Config {
32
+ /** Maximum inbound messages copied into one Agent input. */
33
+ readonly admissionBatchSize?: number;
34
+ /** Time that unconfirmed provider setup material remains in Host memory. */
35
+ readonly accountSetupTtlMs?: number;
36
+ /** Sqlite file for conversation, cursor, and execution records. */
37
+ readonly deliverySqlitePath?: string | undefined;
38
+ }
39
+ interface ResolvedConfig {
40
+ readonly admissionBatchSize: number;
41
+ readonly accountSetupTtlMs: number;
42
+ readonly deliverySqlitePath?: string | undefined;
43
+ }
44
+ /** Host service implementing the durable configuration half of IM takeover. */
45
+ export declare class ImRuntime extends Service implements ImRuntimeService {
46
+ static inject: string[];
47
+ static Config: ZodType<Config>;
48
+ private accounts?;
49
+ private simulationTargets?;
50
+ private simulationInstances?;
51
+ private deliveryRecords?;
52
+ private delivery?;
53
+ private coordinator;
54
+ private simulationController;
55
+ private readonly pendingAutomaticPauses;
56
+ private readonly automaticSendEpochs;
57
+ private generation;
58
+ private deliveryGeneration;
59
+ private simulationTail;
60
+ private readonly activeListeners;
61
+ private readonly listenerStates;
62
+ private readonly listenerTails;
63
+ private readonly pendingAccountSetups;
64
+ private readonly observations;
65
+ readonly transports: ImTransports;
66
+ readonly policies: ImRoutePolicies;
67
+ readonly config: ResolvedConfig;
68
+ /** @param ctx - Cordis context carrying StorageDomain and Credentials. @param config - validated Agent admission limits. */
69
+ constructor(ctx: Context, config?: Config);
70
+ /** Open the authoritative configuration domain before publishing the service. */
71
+ protected [Service.init](): Promise<void>;
72
+ snapshot(): ImRuntimeSnapshot;
73
+ subscribe(listener: (change: ImRuntimeChange) => void): () => void;
74
+ startPlatformLogin(platform: ImPlatform, signal?: AbortSignal): Promise<ImPlatformLoginStatus>;
75
+ platformLoginStatus(platform: ImPlatform, attemptId: ImPlatformLoginAttemptId): ImPlatformLoginStatus;
76
+ cancelPlatformLogin(platform: ImPlatform, attemptId: ImPlatformLoginAttemptId): Promise<ImPlatformLoginStatus>;
77
+ listAccountCandidates(platform: ImPlatform, signal?: AbortSignal): Promise<readonly ImAccountCandidate[]>;
78
+ discoverConversations(accountId: ImAccountId, signal?: AbortSignal): Promise<ImConversationCandidatePage>;
79
+ inspectConversation(accountId: ImAccountId, conversationId: string, conversationKind: ImConversationKind, signal?: AbortSignal): Promise<ImConversationCandidate>;
80
+ /** @param accountId - configured account. @param signal - caller lifetime. @returns assigned service accounts when the platform exposes them. */
81
+ listAssignedActors(accountId: ImAccountId, signal?: AbortSignal): Promise<readonly ImAssignedActorCandidate[]>;
82
+ previewAccountSetup(request: ImAccountSetupRequest, signal?: AbortSignal): Promise<ImAccountSetupPreview>;
83
+ confirmAccountSetup(request: ImConfirmAccountSetupRequest): Promise<ImAccountMutationResult>;
84
+ cancelAccountSetup(setupId: ImAccountSetupId): ImCancelAccountSetupResult;
85
+ addAccount(request: ImAccountSetupRequest, signal?: AbortSignal): Promise<ImAccountView>;
86
+ setAccountPaused(request: ImSetAccountPausedRequest): Promise<ImAccountMutationResult>;
87
+ disconnectAccount(request: ImAccountLifecycleRequest): Promise<ImAccountMutationResult>;
88
+ reconnectAccount(request: ImAccountLifecycleRequest): Promise<ImAccountMutationResult>;
89
+ /**
90
+ * Delete one configured account after comparing its observed revision.
91
+ * @param request - account identity and revision observed before confirmation.
92
+ * @returns the durable deletion receipt.
93
+ */
94
+ deleteAccount(request: ImAccountLifecycleRequest): Promise<ImAccountMutationResult>;
95
+ refreshAccount(request: ImAccountLifecycleRequest, signal?: AbortSignal): Promise<ImAccountMutationResult>;
96
+ queryAccountOperation(accountId: ImAccountId, operationId: ImOperationId): ImAccountOperationQuery;
97
+ createRoute(request: ImCreateRouteRequest): Promise<ImRouteMutationResult>;
98
+ saveRoute(request: ImSaveRouteRequest): Promise<ImRouteMutationResult>;
99
+ rebindRoute(request: ImRebindRouteRequest): Promise<ImRouteMutationResult>;
100
+ deleteRoute(request: ImDeleteRouteRequest): Promise<ImRouteMutationResult>;
101
+ queryRouteOperation(account: ImAccountId, operationId: ImOperationId): ImRouteOperationQuery;
102
+ /**
103
+ * Keep history flowing for one account without an enabled admit route.
104
+ * @param accountId - connected account.
105
+ * @param observation - conversation kind and target to receive.
106
+ * @returns disposer that drops the lease and reconciles the listener.
107
+ */
108
+ registerObservation(accountId: ImAccountId, observation: {
109
+ readonly conversationKind: ImConversationKind;
110
+ readonly target: ImRouteTarget;
111
+ }): () => void;
112
+ /**
113
+ * Authorize one admission or automated send when the route declared a controller.
114
+ * Ordinary routes without a controller are allowed.
115
+ * @param kind - check moment.
116
+ * @param route - frozen route.
117
+ * @param scope - conversation identity.
118
+ */
119
+ authorizeRoutePolicy(kind: ImPolicyCheckKind, route: ImRouteView, scope: import('./delivery-types.ts').ImDeliveryScope): Promise<ImPolicyDecision>;
120
+ resolveRoute(account: ImAccountId, conversationKind: ImConversationKind, conversationId: string, assignedActorId?: string): ImRouteResolution;
121
+ /** Whether this real conversation currently admits automatic handling. */
122
+ private conversationAdmits;
123
+ /** @param scope - durable real conversation. @returns last admitted presentation, including the assigned service account when known. */
124
+ getConversationPresentation(scope: ImRealDeliveryScope): import('./delivery-types.ts').ImConversationPresentation | undefined;
125
+ saveSimulationTarget(request: ImSaveSimulationTargetRequest): Promise<ImSimulationTargetMutationResult>;
126
+ removeSimulationTarget(request: ImRemoveSimulationTargetRequest): Promise<ImSimulationTargetMutationResult>;
127
+ querySimulationTargetOperation(workspaceId: WorkspaceId, operationId: ImOperationId): ImSimulationTargetOperationQuery;
128
+ listSimulationInstances(): readonly ImSimulationInstanceView[];
129
+ getSimulationInstance(instanceId: ImSimulationInstanceId): ImSimulationInstanceView | undefined;
130
+ scopeForSession(sessionId: SessionId): ImSimulationSessionScope | undefined;
131
+ realScopeForSession(sessionId: SessionId): ImRealSessionBinding | undefined;
132
+ realBindingForScope(scopeId: ImScopeId): ImRealSessionBinding | undefined;
133
+ sendManualMessage(request: ImSendManualMessageRequest, signal?: AbortSignal): Promise<ImManualMessageResult>;
134
+ queryManualMessage(request: ImManualMessageQueryRequest): ImManualMessageQuery;
135
+ confirmManualMessage(request: ImManualMessageQueryRequest, signal?: AbortSignal): Promise<ImManualMessageResult>;
136
+ retryManualMessage(request: ImRetryManualMessageRequest, signal?: AbortSignal): Promise<ImManualMessageResult>;
137
+ createSimulationInstance(request: ImCreateSimulationInstanceRequest): Promise<ImSimulationInstanceView>;
138
+ injectSimulationMember(request: ImInjectSimulationMemberRequest): Promise<ImInboundMessageView>;
139
+ injectSimulationManagedHuman(request: ImInjectSimulationManagedHumanRequest): Promise<ImInboundMessageView>;
140
+ querySimulationInjection(request: ImSimulationInjectionQuery): ImInboundOperationQuery;
141
+ beginStopSimulation(instanceId: ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
142
+ beginStopSimulationForSession(sessionId: SessionId): Promise<ImSimulationInstanceView>;
143
+ waitSimulationStopped(instanceId: ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
144
+ subscribeDelivery(listener: (change: ImDeliveryChange) => void): () => void;
145
+ ingestInboundPage(request: ImIngestInboundPageRequest): Promise<ImInboundPageResult>;
146
+ queryInboundOperation(scope: ImDeliveryScope, operationId: ImDeliveryOperationId): ImInboundOperationQuery;
147
+ getConversationCursor(scope: ImDeliveryScope): ImConversationCursor;
148
+ getProviderCursor(owner: ImProviderCursorOwner): ImProviderCursorView;
149
+ commitProviderCursor(request: ImCommitProviderCursorRequest): Promise<ImProviderCursorCommitResult>;
150
+ queryProviderCursorOperation(owner: ImProviderCursorOwner, operationId: ImDeliveryOperationId): ImProviderCursorOperationQuery;
151
+ queryHistory(request: ImHistoryQueryRequest): ImHistoryPage;
152
+ /**
153
+ * List customer rows for one account and source from the rebuildable index.
154
+ * @param request - account, real/simulation filter, optional substring, and reader.
155
+ */
156
+ listCustomers(request: ImCustomerListRequest): ImCustomerListPage;
157
+ /**
158
+ * Advance one reader's live inbound watermark with max semantics.
159
+ * @param request - reader, scope, and observed arrival sequence.
160
+ */
161
+ ackCustomerRead(request: ImCustomerReadAckRequest): void;
162
+ /**
163
+ * Persist one scope's automatic-handling pause fact.
164
+ * @param request - scope and pause fields.
165
+ */
166
+ setHandlingControl(request: ImSetHandlingControlRequest): ImHandlingControl;
167
+ /**
168
+ * Read one scope's automatic-handling pause fact.
169
+ * @param scopeId - complete conversation identity.
170
+ */
171
+ getHandlingControl(scopeId: ImScopeId): ImHandlingControl | undefined;
172
+ /**
173
+ * Project an unresolved durable forward pause into automatic-processing authorization.
174
+ * @param scopeId - Customer whose journal pause is unresolved.
175
+ * @param pending - True before attempting persistence; false only after reconciling the durable pause and journal acknowledgement.
176
+ * Pending projections survive their caller's disposal until reconciliation or runtime shutdown; they do not change the persisted handling control.
177
+ */
178
+ setAutomaticHandlingPausePending(scopeId: ImScopeId, pending: boolean): void;
179
+ /** @param scopeId - Complete customer scope. @returns Whether a pending journal pause or durable handling control blocks automatic processing. */
180
+ isAutomaticHandlingBlocked(scopeId: ImScopeId): boolean;
181
+ private recordHandlingPaused;
182
+ /**
183
+ * Open a persisted Agent Session and append `im/handling-paused`.
184
+ * When no Session log exists, skip the event: handling control remains the
185
+ * SQLite row from `setHandlingControl`, which is the source of truth for
186
+ * pause/resume even if a later Agent Session is created.
187
+ */
188
+ private appendHandlingPausedToPersisted;
189
+ /**
190
+ * Resolve a stored conversation identity from its scope id.
191
+ * @param scopeId - complete conversation identity.
192
+ */
193
+ getDeliveryScope(scopeId: ImScopeId): ImDeliveryScope | undefined;
194
+ pendingInbound(request: ImPendingInboundRequest): readonly ImInboundMessageView[];
195
+ getAgentTask(scope: ImDeliveryScope): ImAgentTaskView | undefined;
196
+ /** @param scope - complete conversation identity. @param messageId - stored inbound identity. @returns stored message. */
197
+ getInboundMessage(scope: ImDeliveryScope, messageId: ImMessageId): ImInboundMessageView;
198
+ messageSource(scope: ImDeliveryScope, messageId: ImMessageId): ImMessageSource;
199
+ markSubmitted(request: ImMarkSubmittedRequest): Promise<ImMarkSubmittedResult>;
200
+ /** Consume live pending that a route policy just refused, without an Agent turn. */
201
+ suppressUnadmitted(scope: ImDeliveryScope): Promise<void>;
202
+ /** Advance watermarks of conversations this newly enabled route would now admit. */
203
+ private suppressUnadmittedMatchedBy;
204
+ sessionUserMessage(scope: ImDeliveryScope, messageId: ImMessageId): UserMessage;
205
+ reconcileSession(sessionId: SessionId): Promise<ImSessionReconciliationResult>;
206
+ importJsonlHistory(request: ImImportJsonlHistoryRequest): Promise<ImImportJsonlHistoryResult>;
207
+ importSimulationHistory(request: ImImportSimulationHistoryRequest): Promise<ImImportSimulationHistoryResult>;
208
+ registerOutbound(request: ImRegisterOutboundRequest): Promise<ImOutboundView>;
209
+ /** @param request - scope-fixed automated intent. @param binding - task generation recorded before Agent execution. @returns durable intent or a route-changed rejection. */
210
+ registerAgentOutbound(request: ImRegisterOutboundRequest, binding: ImOutboundRouteBinding): Promise<ImOutboundView>;
211
+ /**
212
+ * Bind automatic provider preparation to one scope's handling epoch and durable attempt.
213
+ * @param request - Owning dispatch attempt.
214
+ * @param signal - Tool cancellation, retained after external submission.
215
+ * @returns Provider authorization; dispose after settlement. Submission rechecks controller policy; customer pause revokes only unsubmitted preparation.
216
+ */
217
+ automaticSendAuthorization(request: ImBeginOutboundAttemptRequest & {
218
+ readonly attemptId: ImOutboundAttemptId;
219
+ }, signal: AbortSignal): ImAutomaticSendAuthorization;
220
+ beginOutboundAttempt(request: ImBeginOutboundAttemptRequest): Promise<ImBeginOutboundAttemptResult>;
221
+ settleOutboundAttempt(request: ImSettleOutboundAttemptRequest): Promise<ImOutboundView>;
222
+ settleSimulationOutbound(request: ImSettleSimulationOutboundRequest): Promise<ImOutboundView>;
223
+ getOutbound(request: ImGetOutboundRequest): ImOutboundView | undefined;
224
+ queryOutbound(request: ImOutboundQueryRequest): ImOutboundPage;
225
+ cancelPendingAi(request: ImCancelPendingAiRequest): Promise<readonly ImOutboundView[]>;
226
+ findSentOutbound(scope: ImRealDeliveryScope, externalMessageId: string): ImOutboundView | undefined;
227
+ private confirmUnknownOutbound;
228
+ private inboundSender;
229
+ classifyInboundSender(scope: ImRealDeliveryScope, evidence: ImInboundSenderEvidence): ImSenderAttribution;
230
+ private isNativeActor;
231
+ /** @param workspaceId - simulated-user Workspace. @returns its current target setting. */
232
+ simulationTargetForWorkspace(workspaceId: WorkspaceId): ImSimulationTargetView | undefined;
233
+ /** @param target - current workspace target setting. @returns its exact route when still present. */
234
+ routeForSimulationTarget(target: ImSimulationTargetView): ImRouteView | undefined;
235
+ /** @param target - current workspace target setting. @returns its exact safe account when still present. */
236
+ accountForSimulationTarget(target: ImSimulationTargetView): ImAccountView | undefined;
237
+ /** @param scope - claimed frozen simulation scope. @returns whether its exact instance accepts delivery. */
238
+ isSimulationScopeRunning(scope: ImSimulationDeliveryScope): boolean;
239
+ /** Emit a post-commit instance notification for BFF followers. @param instanceId - changed instance. */
240
+ publishSimulationInstanceChange(instanceId: ImSimulationInstanceId): void;
241
+ private requireRealSessionBinding;
242
+ private requireManualBinding;
243
+ private assertNamedManualAccount;
244
+ /**
245
+ * Hosting controllers shop-match human-manual send the same way they
246
+ * shop-match `requireOwnedScope`. Ordinary routes without a controller skip.
247
+ */
248
+ private authorizeManualSend;
249
+ private realBindingForScopeSeat;
250
+ private bindingFromTask;
251
+ /**
252
+ * Direct peer that a send may use.
253
+ * Wangwang accepts a stored id only when this scope has observed that external sender; otherwise it uses the latest observed sender. The conversation id is never a recipient. Other platforms keep a stored peer, then an observed sender.
254
+ * @param scope - conversation being sent or displayed.
255
+ * @param stored - recipient frozen on the task, when one exists.
256
+ * @returns usable peer, or absence when Wangwang has not observed a counterpart.
257
+ */
258
+ usableDirectRecipient(scope: ImDeliveryScope, stored?: ImDirectRecipient): ImDirectRecipient | undefined;
259
+ /**
260
+ * Store the Wangwang peer a send is allowed to use, including clearing one that no observed sender supports.
261
+ * @param sessionId - Agent Session that owns the task, when one exists.
262
+ * @param recipient - usable peer, or absence.
263
+ */
264
+ rememberDirectRecipient(sessionId: SessionId | undefined, recipient: ImDirectRecipient | undefined): Promise<void>;
265
+ private composeRealBinding;
266
+ private requireManualAccount;
267
+ private outboundOwner;
268
+ private assertManualRequestOwner;
269
+ private manualMessageResult;
270
+ private dispatchManualMessage;
271
+ private finishManualMessage;
272
+ /**
273
+ * Persist a DSH operator send as live inbound so Agent admission does not wait for a provider echo.
274
+ * @param scope - conversation that owns the outbound.
275
+ * @param outbound - settled human-manual intent.
276
+ */
277
+ private admitManualOutbound;
278
+ private settleManualResult;
279
+ private prepareVerifiedAccount;
280
+ private persistPreparedAccount;
281
+ private accountIdForSetup;
282
+ private expireAccountSetup;
283
+ private releaseAccountSetup;
284
+ private clearAccountSetups;
285
+ private accountTable;
286
+ private simulationTargetTable;
287
+ private simulationInstanceTable;
288
+ private requireSimulationController;
289
+ private simulationScope;
290
+ private deliveryStore;
291
+ private deliveryRecordsStore;
292
+ /**
293
+ * Insert one execution when its task id is absent.
294
+ * @param task - durable Agent task generation.
295
+ * @returns the stored record, which may already exist.
296
+ */
297
+ persistExecution(task: ImExecutionAggregate): Promise<ImExecutionAggregate>;
298
+ /**
299
+ * Overwrite one execution record.
300
+ * @param task - complete stored generation.
301
+ */
302
+ putExecution(task: ImExecutionAggregate): Promise<void>;
303
+ /**
304
+ * Read one execution by task id.
305
+ * @param id - durable task identity.
306
+ * @returns the stored generation, or absence.
307
+ */
308
+ getExecution(id: ImAgentTaskId): ImExecutionAggregate | undefined;
309
+ /**
310
+ * Apply one serialized transform to a stored execution.
311
+ * @param id - durable task identity.
312
+ * @param fn - synchronous transform of the current record.
313
+ * @returns the stored next record.
314
+ */
315
+ updateExecution(id: ImAgentTaskId, fn: (current: ImExecutionAggregate) => ImExecutionAggregate): Promise<ImExecutionAggregate>;
316
+ /**
317
+ * List task generations for one conversation in generation order.
318
+ * @param scopeId - complete conversation identity.
319
+ * @returns stored generations for that scope.
320
+ */
321
+ executionsForScope(scopeId: import('./delivery-types.ts').ImScopeId): readonly ImExecutionAggregate[];
322
+ /**
323
+ * Resolve the latest execution bound to one Agent Session.
324
+ * @param sessionId - IM Agent Session.
325
+ * @returns that Session's newest task, or absence.
326
+ */
327
+ executionForSession(sessionId: SessionId): ImExecutionAggregate | undefined;
328
+ private assertUnusedIdentity;
329
+ private requireAccount;
330
+ private accountError;
331
+ private updateAccountRoute;
332
+ private enqueueSimulation;
333
+ /** Persist a connection intent separately from pause and process listener state. */
334
+ private setConnectionIntent;
335
+ /** Store one provider authorization observation under the account revision CAS. */
336
+ private storeRefreshResult;
337
+ private publish;
338
+ private publishDelivery;
339
+ /** Serialize listener state changes for one configured account. */
340
+ private scheduleListener;
341
+ /** Start or stop the provider listener from durable account, route, and observation facts. */
342
+ private reconcileListener;
343
+ /** Stop one exact listener before publishing a later start for the same account. */
344
+ private stopListener;
345
+ /** Observe an established listener without turning completion into automatic retry. */
346
+ private observeListener;
347
+ /** Publish one exact listener generation's terminal state. */
348
+ private finishListener;
349
+ /** Stop one ready provider handle and consume its terminal signal without exposing provider errors. */
350
+ private closeListenerHandle;
351
+ /** Drain every provider listener owned by this runtime. */
352
+ private stopAllListeners;
353
+ /** Bind a provider page sink to one configured account and its platform. */
354
+ private transportSink;
355
+ /** Persist every conversation page before committing the provider-owned cursor. */
356
+ private receiveTransportPage;
357
+ /** Publish process listener facts without scheduling another reconciliation. */
358
+ private publishListener;
359
+ }
360
+ export default ImRuntime;
@@ -0,0 +1,50 @@
1
+ import { type ZodType } from 'zod';
2
+ import type { ImAccountId, ImAccountMutationResult, ImAccountView, ImRouteMutationResult, ImRouteView, ImSimulationTargetMutationResult, ImSimulationTargetView, ImSimulationInstanceId, ImSimulationInstanceView } from './types.ts';
3
+ /** Stored account fields; listener status is process state and is derived on read. */
4
+ export type ImAccountRecord = Omit<ImAccountView, 'listener'>;
5
+ export declare const imAccountRecordSchema: ZodType<ImAccountRecord>;
6
+ export declare const imRouteSchema: ZodType<ImRouteView>;
7
+ interface StoredRouteOperation {
8
+ readonly fingerprint: string;
9
+ readonly result: ImRouteMutationResult;
10
+ }
11
+ interface StoredAccountMutationResult extends Omit<ImAccountMutationResult, 'account'> {
12
+ readonly account: ImAccountRecord;
13
+ }
14
+ interface StoredAccountOperation {
15
+ readonly fingerprint: string;
16
+ readonly result: StoredAccountMutationResult;
17
+ }
18
+ /** One atomic account aggregate: safe account facts, routes, and queryable operation receipts. */
19
+ export interface ImAccountAggregate {
20
+ readonly account: ImAccountRecord;
21
+ readonly routes: Readonly<Record<string, ImRouteView>>;
22
+ readonly routeOperations: Readonly<Record<string, StoredRouteOperation>>;
23
+ readonly accountOperations: Readonly<Record<string, StoredAccountOperation>>;
24
+ }
25
+ export declare const imAccountAggregateSchema: ZodType<ImAccountAggregate>;
26
+ export declare const imSimulationTargetSchema: ZodType<ImSimulationTargetView>;
27
+ interface StoredSimulationTargetOperation {
28
+ readonly fingerprint: string;
29
+ readonly result: ImSimulationTargetMutationResult;
30
+ }
31
+ /** Workspace simulation-target aggregate retaining receipts after target removal. */
32
+ export interface ImSimulationTargetAggregate {
33
+ readonly workspaceId: import('@deepseek-ai/dsh-workspace').WorkspaceId;
34
+ readonly target?: ImSimulationTargetView;
35
+ readonly operations: Readonly<Record<string, StoredSimulationTargetOperation>>;
36
+ }
37
+ export declare const imSimulationTargetAggregateSchema: ZodType<ImSimulationTargetAggregate>;
38
+ /** Parser for one durable two-Session simulation lifecycle. */
39
+ export declare const imSimulationInstanceSchema: ZodType<ImSimulationInstanceView>;
40
+ /** IM configuration storage schema. Cross-account or cross-table transactions are not implied. */
41
+ export declare const imRuntimeDomainSpec: {
42
+ name: string;
43
+ version: number;
44
+ tables: {
45
+ accounts: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<ImAccountId, ImAccountAggregate>;
46
+ simulation_targets: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<import("@deepseek-ai/dsh-workspace/types").WorkspaceId, ImSimulationTargetAggregate>;
47
+ simulation_instances: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<ImSimulationInstanceId, ImSimulationInstanceView>;
48
+ };
49
+ };
50
+ export {};