@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,209 @@
1
+ /** Host service and event declarations kept out of the client-safe DTO entry. */
2
+ import type { ImAutomaticSendAuthorization } from './transport.ts';
3
+ import type { WorkspaceId } from '@deepseek-ai/dsh-workspace';
4
+ import type { UserMessage } from '@deepseek-ai/dsh-llm';
5
+ import type { SessionId } from '@deepseek-ai/dsh-session';
6
+ import type { ImBeginOutboundAttemptRequest, ImOutboundAttemptId, ImBeginOutboundAttemptResult, 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, ImOutboundView, ImPendingInboundRequest, ImProviderCursorCommitResult, ImProviderCursorOperationQuery, ImProviderCursorOwner, ImProviderCursorView, ImRealDeliveryScope, ImRealSessionBinding, ImRegisterOutboundRequest, ImRetryManualMessageRequest, ImSendManualMessageRequest, ImSetHandlingControlRequest, ImSettleOutboundAttemptRequest, ImSettleSimulationOutboundRequest, ImSessionReconciliationResult, ImSenderAttribution, ImScopeId } from './delivery-types.ts';
7
+ import type { ImAccountId, ImAccountCandidate, ImAccountSetupId, ImAccountSetupPreview, ImCancelAccountSetupResult, ImConfirmAccountSetupRequest, ImAccountLifecycleRequest, ImAccountMutationResult, ImAccountOperationQuery, ImAccountSetupRequest, ImAccountView, ImAssignedActorCandidate, ImConversationCandidate, ImConversationCandidatePage, ImConversationKind, ImCreateRouteRequest, ImDeleteRouteRequest, ImOperationId, ImPlatform, ImPlatformLoginAttemptId, ImPlatformLoginStatus, ImRebindRouteRequest, ImRemoveSimulationTargetRequest, ImRouteMutationResult, ImRouteOperationQuery, ImRouteResolution, ImRuntimeChange, ImRuntimeSnapshot, ImSaveRouteRequest, ImSaveSimulationTargetRequest, ImSetAccountPausedRequest, ImSimulationTargetMutationResult, ImSimulationTargetOperationQuery, ImCreateSimulationInstanceRequest, ImSimulationInjectionQuery, ImInjectSimulationManagedHumanRequest, ImInjectSimulationMemberRequest, ImImportSimulationHistoryRequest, ImImportSimulationHistoryResult, ImSimulationInstanceView, ImSimulationSessionScope } from './types.ts';
8
+ declare module '@deepseek-ai/cordis' {
9
+ interface Context {
10
+ imRuntime: ImRuntimeService;
11
+ }
12
+ interface Events {
13
+ /**
14
+ * IM configuration or process listener state changed. The emitted revision is newer than every prior event from this process.
15
+ * @param change - changed account, route, target, instance, transport, or listener and its process generation revision.
16
+ * @mode emit
17
+ */
18
+ 'imRuntime/changed'(change: ImRuntimeChange): void;
19
+ /**
20
+ * Durable inbound, submission, or outbox state changed.
21
+ * @param change - committed scope and affected message or request identities.
22
+ * @mode emit
23
+ */
24
+ 'imRuntime/delivery-changed'(change: ImDeliveryChange): void;
25
+ }
26
+ }
27
+ declare module '@deepseek-ai/dsh-llm' {
28
+ interface MessageSourceMap {
29
+ /** Stable IM identity used to reconcile a Session append with the delivery domain. */
30
+ im: ImMessageSource;
31
+ }
32
+ }
33
+ /** Read and mutation surface consumed by the product BFF. */
34
+ export interface ImRuntimeService {
35
+ /** @param platform - installed provider selected by the operator. @param signal - caller lifetime until safe instructions are available. @returns current safe interactive login state. */
36
+ startPlatformLogin(platform: ImPlatform, signal?: AbortSignal): Promise<ImPlatformLoginStatus>;
37
+ /** @param platform - owning provider. @param attemptId - login identity returned by start. @returns current safe login state. */
38
+ platformLoginStatus(platform: ImPlatform, attemptId: ImPlatformLoginAttemptId): ImPlatformLoginStatus;
39
+ /** @param platform - owning provider. @param attemptId - login identity returned by start. @returns cancelled or already-terminal state. */
40
+ cancelPlatformLogin(platform: ImPlatform, attemptId: ImPlatformLoginAttemptId): Promise<ImPlatformLoginStatus>;
41
+ /** @returns the current durable configuration projection. */
42
+ snapshot(): ImRuntimeSnapshot;
43
+ /** @param listener - post-commit change observer. @returns disposer for this subscription. */
44
+ subscribe(listener: (change: ImRuntimeChange) => void): () => void;
45
+ /** @param platform - provider whose installed or admitted identities are requested. @param signal - caller lifetime. @returns safe selectable candidates. */
46
+ listAccountCandidates(platform: ImPlatform, signal?: AbortSignal): Promise<readonly ImAccountCandidate[]>;
47
+ /** @param accountId - configured account whose provider conversations are listed. @param signal - caller lifetime. @returns provider-known titles with stable conversation ids. */
48
+ discoverConversations(accountId: ImAccountId, signal?: AbortSignal): Promise<ImConversationCandidatePage>;
49
+ /** @param accountId - configured account. @param conversationId - platform conversation identifier. @param conversationKind - provider category. @param signal - caller lifetime. @returns provider-known title, or the identifier when the title is unknown. */
50
+ inspectConversation(accountId: ImAccountId, conversationId: string, conversationKind: ImConversationKind, signal?: AbortSignal): Promise<ImConversationCandidate>;
51
+ /** @param accountId - configured account. @param signal - caller lifetime. @returns assigned service accounts when the platform exposes them. */
52
+ listAssignedActors(accountId: ImAccountId, signal?: AbortSignal): Promise<readonly ImAssignedActorCandidate[]>;
53
+ /** @param request - candidate-bound write-only setup input. @param signal - caller lifetime. @returns safe verified facts and a short-lived Host setup identifier. */
54
+ previewAccountSetup(request: ImAccountSetupRequest, signal?: AbortSignal): Promise<ImAccountSetupPreview>;
55
+ /** @param request - setup identifier and idempotency identifier. @returns the durable account-creation outcome. */
56
+ confirmAccountSetup(request: ImConfirmAccountSetupRequest): Promise<ImAccountMutationResult>;
57
+ /** @param setupId - unconfirmed setup to release. @returns whether it was released or had already advanced. */
58
+ cancelAccountSetup(setupId: ImAccountSetupId): ImCancelAccountSetupResult;
59
+ /** @param accountId - receiving account. @param conversationKind - provider category. @param conversationId - provider conversation. @returns precedence-ordered route resolution. */
60
+ resolveRoute(accountId: ImAccountId, conversationKind: ImConversationKind, conversationId: string, assignedActorId?: string): ImRouteResolution;
61
+ /** @param request - candidate-bound setup input for non-interactive Host consumers. @param signal - caller lifetime. @returns the persisted safe account. */
62
+ addAccount(request: ImAccountSetupRequest, signal?: AbortSignal): Promise<ImAccountView>;
63
+ /** @param request - guarded account pause mutation. @returns its durable outcome. */
64
+ setAccountPaused(request: ImSetAccountPausedRequest): Promise<ImAccountMutationResult>;
65
+ /** @param request - guarded persistent disconnect intent. @returns its durable outcome. */
66
+ disconnectAccount(request: ImAccountLifecycleRequest): Promise<ImAccountMutationResult>;
67
+ /** @param request - guarded persistent reconnect intent. @returns its durable outcome. */
68
+ reconnectAccount(request: ImAccountLifecycleRequest): Promise<ImAccountMutationResult>;
69
+ /** @param request - guarded account deletion. @returns its durable outcome; conversation history remains. */
70
+ deleteAccount(request: ImAccountLifecycleRequest): Promise<ImAccountMutationResult>;
71
+ /** @param request - guarded provider authorization refresh. @param signal - caller lifetime. @returns its durable outcome. */
72
+ refreshAccount(request: ImAccountLifecycleRequest, signal?: AbortSignal): Promise<ImAccountMutationResult>;
73
+ /** @param accountId - owning account. @param operationId - idempotency identifier. @returns stored result or an explicit miss. */
74
+ queryAccountOperation(accountId: ImAccountId, operationId: ImOperationId): ImAccountOperationQuery;
75
+ /** @param request - new route tuple and workspace owner. @returns its durable outcome. */
76
+ createRoute(request: ImCreateRouteRequest): Promise<ImRouteMutationResult>;
77
+ /** @param request - guarded non-ownership route edit. @returns its durable outcome. */
78
+ saveRoute(request: ImSaveRouteRequest): Promise<ImRouteMutationResult>;
79
+ /** @param request - guarded ownership transfer. @returns its durable outcome. */
80
+ rebindRoute(request: ImRebindRouteRequest): Promise<ImRouteMutationResult>;
81
+ /** @param request - guarded route deletion. @returns its durable outcome. */
82
+ deleteRoute(request: ImDeleteRouteRequest): Promise<ImRouteMutationResult>;
83
+ /** @param accountId - owning account. @param operationId - idempotency identifier. @returns stored result or an explicit miss. */
84
+ queryRouteOperation(accountId: ImAccountId, operationId: ImOperationId): ImRouteOperationQuery;
85
+ /**
86
+ * Keep history flowing for one account without an enabled admit route.
87
+ * @param accountId - connected account.
88
+ * @param observation - conversation kind and target to receive.
89
+ */
90
+ registerObservation(accountId: ImAccountId, observation: {
91
+ readonly conversationKind: ImConversationKind;
92
+ readonly target: import('./types.ts').ImRouteTarget;
93
+ }): () => void;
94
+ /** @param request - guarded simulation-target save. @returns its durable outcome. */
95
+ saveSimulationTarget(request: ImSaveSimulationTargetRequest): Promise<ImSimulationTargetMutationResult>;
96
+ /** @param request - guarded simulation-target removal. @returns its durable outcome. */
97
+ removeSimulationTarget(request: ImRemoveSimulationTargetRequest): Promise<ImSimulationTargetMutationResult>;
98
+ /** @param workspaceId - target-owning workspace. @param operationId - idempotency identifier. @returns stored result or an explicit miss. */
99
+ querySimulationTargetOperation(workspaceId: WorkspaceId, operationId: ImOperationId): ImSimulationTargetOperationQuery;
100
+ /** @param sessionId - durable real IM task Session. @returns its frozen target plus current safe account, listener, presentation, and sync facts. */
101
+ realScopeForSession(sessionId: SessionId): ImRealSessionBinding | undefined;
102
+ /** @param scopeId - complete conversation identity. @returns current safe account, listener, presentation, and sync facts, even before an Agent task exists. */
103
+ realBindingForScope(scopeId: ImScopeId): ImRealSessionBinding | undefined;
104
+ /**
105
+ * Send one human-manual message.
106
+ * Session-bound calls may use any locally configured account that owns the
107
+ * Agent task. Hosting-console callers name the selected {@link ImSendManualMessageRequest.accountId}
108
+ * and, when no task exists, {@link ImSendManualMessageRequest.scopeId}; unknown,
109
+ * other-account, and simulation scopes are rejected.
110
+ * @param request - Session- or scope-bound stable request and text.
111
+ * @param signal - caller lifetime.
112
+ * @returns durable manual delivery and identity facts when the account is available.
113
+ */
114
+ sendManualMessage(request: ImSendManualMessageRequest, signal?: AbortSignal): Promise<ImManualMessageResult>;
115
+ /** @param request - Session- or scope-bound stable request identity. @returns durable result without provider activity. */
116
+ queryManualMessage(request: ImManualMessageQueryRequest): ImManualMessageQuery;
117
+ /** @param request - Session- or scope-bound uncertain request. @param signal - caller lifetime. @returns provider-confirmed or still-unknown result without sending. */
118
+ confirmManualMessage(request: ImManualMessageQueryRequest, signal?: AbortSignal): Promise<ImManualMessageResult>;
119
+ /** @param request - new request linked to an uncertain predecessor. @param signal - caller lifetime. @returns explicit retry delivery result. */
120
+ retryManualMessage(request: ImRetryManualMessageRequest, signal?: AbortSignal): Promise<ImManualMessageResult>;
121
+ /** @returns all durable simulation instances in creation order. */
122
+ listSimulationInstances(): readonly ImSimulationInstanceView[];
123
+ /** @param instanceId - Host-minted instance identity. @returns its durable state or absence. */
124
+ getSimulationInstance(instanceId: import('./delivery-types.ts').ImSimulationInstanceId): ImSimulationInstanceView | undefined;
125
+ /** @param sessionId - either side of a simulation pair. @returns Host-authoritative role, peer, workspace, and delivery scope. */
126
+ scopeForSession(sessionId: SessionId): ImSimulationSessionScope | undefined;
127
+ /** @param request - live simulated-user Session and optional all-route conversation. @returns durable pair after tested Session flush. */
128
+ createSimulationInstance(request: ImCreateSimulationInstanceRequest): Promise<ImSimulationInstanceView>;
129
+ /** @param request - allow-listed member identity and text. @returns shared-path durable inbound message. */
130
+ injectSimulationMember(request: ImInjectSimulationMemberRequest): Promise<ImInboundMessageView>;
131
+ /** @param request - instance and text; Host derives the frozen account actor. @returns shared-path durable inbound message. */
132
+ injectSimulationManagedHuman(request: ImInjectSimulationManagedHumanRequest): Promise<ImInboundMessageView>;
133
+ /** @param request - original injection identity. @returns durable receipt; never resends. */
134
+ querySimulationInjection(request: ImSimulationInjectionQuery): ImInboundOperationQuery;
135
+ /** @param instanceId - instance to close. @returns durable stopping or terminal state without awaiting caller activity. */
136
+ beginStopSimulation(instanceId: import('./delivery-types.ts').ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
137
+ /** @param sessionId - trusted tool caller Session. @returns its instance's durable stopping or terminal state. */
138
+ beginStopSimulationForSession(sessionId: SessionId): Promise<ImSimulationInstanceView>;
139
+ /** @param instanceId - already-stopping instance. @returns terminal state after both sides and derived work quiesce. */
140
+ waitSimulationStopped(instanceId: import('./delivery-types.ts').ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
141
+ /** @param request - instance identity, stable operation, display filename, and local JSONL. @returns durable query-only source counts and updated instance. */
142
+ importSimulationHistory(request: ImImportSimulationHistoryRequest): Promise<ImImportSimulationHistoryResult>;
143
+ /** @param listener - post-commit delivery observer. @returns disposer for this subscription. */
144
+ subscribeDelivery(listener: (change: ImDeliveryChange) => void): () => void;
145
+ /** @param request - complete real scope, cursor CAS, and provider page. @returns durable page receipt. */
146
+ ingestInboundPage(request: ImIngestInboundPageRequest): Promise<ImInboundPageResult>;
147
+ /** @param scope - complete conversation identity. @param operationId - page or import operation. @returns durable receipt or explicit miss. */
148
+ queryInboundOperation(scope: ImDeliveryScope, operationId: ImDeliveryOperationId): ImInboundOperationQuery;
149
+ /** @param scope - complete conversation identity. @returns current live-delivery cursor. */
150
+ getConversationCursor(scope: ImDeliveryScope): ImConversationCursor;
151
+ /** @param owner - platform account and provider feed identity. @returns current feed cursor without claiming conversation ownership. */
152
+ getProviderCursor(owner: ImProviderCursorOwner): ImProviderCursorView;
153
+ /** @param request - feed cursor CAS and every durable conversation-page receipt. @returns stored cursor outcome. */
154
+ commitProviderCursor(request: ImCommitProviderCursorRequest): Promise<ImProviderCursorCommitResult>;
155
+ /** @param owner - provider feed identity. @param operationId - uncertain cursor operation. @returns durable receipt or explicit miss. */
156
+ queryProviderCursorOperation(owner: ImProviderCursorOwner, operationId: ImDeliveryOperationId): ImProviderCursorOperationQuery;
157
+ /** @param request - bounded history cursor and origin filter. @returns ascending message page. */
158
+ queryHistory(request: ImHistoryQueryRequest): ImHistoryPage;
159
+ /** @param request - account, real/simulation filter, optional substring, and reader. @returns a keyset page of customer rows. */
160
+ listCustomers(request: ImCustomerListRequest): ImCustomerListPage;
161
+ /** @param request - reader, scope, and observed arrival sequence. */
162
+ ackCustomerRead(request: ImCustomerReadAckRequest): void;
163
+ /** @param request - scope and pause fields. @returns the stored handling control. */
164
+ setHandlingControl(request: ImSetHandlingControlRequest): ImHandlingControl;
165
+ /** @param scopeId - Customer whose durable journal pause needs reconciliation. @param pending - Hold automatic processing until persistence and acknowledgement complete; caller disposal does not release it. */
166
+ setAutomaticHandlingPausePending(scopeId: ImScopeId, pending: boolean): void;
167
+ /** @param scopeId - Complete customer scope. @returns Pending journal or durable handling pause blocks automatic processing. */
168
+ isAutomaticHandlingBlocked(scopeId: ImScopeId): boolean;
169
+ /** @param scopeId - complete conversation identity. @returns the stored handling control, or absence. */
170
+ getHandlingControl(scopeId: ImScopeId): ImHandlingControl | undefined;
171
+ /** @param scopeId - complete conversation identity. @returns the stored scope, or absence. */
172
+ getDeliveryScope(scopeId: ImScopeId): ImDeliveryScope | undefined;
173
+ /** @param request - scope and maximum pending live messages. @returns oldest received rows. */
174
+ pendingInbound(request: ImPendingInboundRequest): readonly ImInboundMessageView[];
175
+ /** @param scope - complete conversation identity. @returns frozen Agent task assignment, or absence before admission. */
176
+ getAgentTask(scope: ImDeliveryScope): ImAgentTaskView | undefined;
177
+ /** @param scope - complete conversation identity. @param messageId - stored inbound identity. @returns source for an existing Session user/message event. */
178
+ messageSource(scope: ImDeliveryScope, messageId: ImMessageId): ImMessageSource;
179
+ /** @param scope - complete conversation identity. @param messageId - stored inbound identity. @returns identified Session user message with durable IM source. */
180
+ sessionUserMessage(scope: ImDeliveryScope, messageId: ImMessageId): UserMessage;
181
+ /** @param sessionId - durable Session log to compare with pending delivery rows. @returns matched submissions and ignored stale evidence. */
182
+ reconcileSession(sessionId: SessionId): Promise<ImSessionReconciliationResult>;
183
+ /** @param request - Session evidence for atomically submitted inbound rows. @returns committed rows and cursor. */
184
+ markSubmitted(request: ImMarkSubmittedRequest): Promise<ImMarkSubmittedResult>;
185
+ /** @param request - query-only JSONL history and idempotency identity. @returns durable import receipt. */
186
+ importJsonlHistory(request: ImImportJsonlHistoryRequest): Promise<ImImportJsonlHistoryResult>;
187
+ /** @param request - outbound intent persisted before any send. @returns durable safe outbox row. */
188
+ registerOutbound(request: ImRegisterOutboundRequest): Promise<ImOutboundView>;
189
+ /** @param request - Durable automatic dispatch attempt. @param signal - Tool cancellation. @returns Epoch-scoped authorization disposed after provider settlement. */
190
+ automaticSendAuthorization(request: ImBeginOutboundAttemptRequest & {
191
+ readonly attemptId: ImOutboundAttemptId;
192
+ }, signal: AbortSignal): ImAutomaticSendAuthorization;
193
+ /** @param request - real scope and pending request. @returns sole attempt or durable block. */
194
+ beginOutboundAttempt(request: ImBeginOutboundAttemptRequest): Promise<ImBeginOutboundAttemptResult>;
195
+ /** @param request - provider attempt and observed outcome. @returns settled outbox row. */
196
+ settleOutboundAttempt(request: ImSettleOutboundAttemptRequest): Promise<ImOutboundView>;
197
+ /** @param request - simulation scope and local request. @returns locally sent outbox row. */
198
+ settleSimulationOutbound(request: ImSettleSimulationOutboundRequest): Promise<ImOutboundView>;
199
+ /** @param request - complete scope and request identity. @returns outbox row or absence. */
200
+ getOutbound(request: ImGetOutboundRequest): ImOutboundView | undefined;
201
+ /** @param request - bounded outbox history cursor. @returns ascending outbox page. */
202
+ queryOutbound(request: ImOutboundQueryRequest): ImOutboundPage;
203
+ /** @param request - scope and terminal reason. @returns discarded automated rows. */
204
+ cancelPendingAi(request: ImCancelPendingAiRequest): Promise<readonly ImOutboundView[]>;
205
+ /** @param scope - complete real scope. @param externalMessageId - provider message identity. @returns matching sent outbox evidence. */
206
+ findSentOutbound(scope: ImRealDeliveryScope, externalMessageId: string): ImOutboundView | undefined;
207
+ /** @param scope - complete real conversation. @param evidence - provider actor or echo facts without message-text heuristics. @returns evidence-backed sender category, including human-native for remembered native-client actors. */
208
+ classifyInboundSender(scope: ImRealDeliveryScope, evidence: ImInboundSenderEvidence): ImSenderAttribution;
209
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Session log of one IM automatic-handling pause.
3
+ *
4
+ * Written when `setHandlingControl` pauses a scope that already has an Agent
5
+ * Session (live or persisted). When no Session log exists, the event is not
6
+ * written; SQLite handling control remains the source of truth.
7
+ * Required-on-read. Secrets stay out.
8
+ * @module @gestaltrun/dsh-im-runtime/session-events
9
+ */
10
+ import type { ImDeliveryScope } from './delivery-types.ts';
11
+ /** Payload recorded when automatic handling is paused for one conversation. */
12
+ export interface ImHandlingPausedEvent {
13
+ /** Frozen conversation identity. */
14
+ readonly scope: ImDeliveryScope;
15
+ /** Pause reason such as `operator-pause` or `forward-*`; never a secret. */
16
+ readonly reason: string;
17
+ /** Tool or GUI call identity that initiated the pause; empty when none. */
18
+ readonly callId: string;
19
+ }
20
+ declare module '@deepseek-ai/dsh-session/types' {
21
+ interface SessionEventMap {
22
+ /**
23
+ * Automatic handling was paused for one IM scope. Records the scope, pause
24
+ * reason, and initiating call id. Contains no secrets. Required-on-read.
25
+ */
26
+ 'im/handling-paused': ImHandlingPausedEvent;
27
+ }
28
+ }
@@ -0,0 +1,64 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { KvTable } from '@deepseek-ai/dsh-storage-domain';
3
+ import type { ImInboundMessageView, ImInboundOperationQuery, ImOutboundView, ImSimulationDeliveryScope, ImSimulationInstanceId } from './delivery-types.ts';
4
+ import type { ImAgentCoordinator } from './agent-coordinator.ts';
5
+ import type { ImRuntime } from './runtime.ts';
6
+ import type { ImCreateSimulationInstanceRequest, ImInjectSimulationManagedHumanRequest, ImInjectSimulationMemberRequest, ImSimulationInstanceView, ImSimulationInjectionQuery } from './types.ts';
7
+ /** Runtime-owned controller; durable state is authoritative and live handles are only execution resources. */
8
+ export declare class ImSimulationController {
9
+ private readonly ctx;
10
+ private readonly runtime;
11
+ private readonly instances;
12
+ private readonly coordinator;
13
+ private readonly testedHandles;
14
+ private readonly toolDisposers;
15
+ private readonly tails;
16
+ private readonly creations;
17
+ private readonly stopping;
18
+ private readonly replyClosures;
19
+ private creationTail;
20
+ private disposed;
21
+ private disposeCreated?;
22
+ private disposeDisposed?;
23
+ /** @param ctx - injected Agent, Session, persistence, preset, tool, and Workspace services. @param runtime - IM delivery authority. @param instances - durable instance records. @param coordinator - normal IM admission coordinator. */
24
+ constructor(ctx: Context, runtime: ImRuntime, instances: KvTable<ImSimulationInstanceId, ImSimulationInstanceView>, coordinator: ImAgentCoordinator);
25
+ /** Recover incomplete lifecycles without resuming ordinary running Sessions. */
26
+ start(): Promise<void>;
27
+ /** Stop lifecycle work and release only handles and tool registrations owned here. */
28
+ dispose(): Promise<void>;
29
+ /** Re-evaluate tool availability after target or instance state changes. */
30
+ refreshAllTools(): void;
31
+ /** Create and durably publish one tested Session paired with the live simulated-user Session. */
32
+ create(request: ImCreateSimulationInstanceRequest): Promise<ImSimulationInstanceView>;
33
+ /** Inject one allow-listed participant through the instance-local adapter. */
34
+ injectMember(request: ImInjectSimulationMemberRequest): Promise<ImInboundMessageView>;
35
+ /** Inject the frozen account owner locally as operator input, never as a member. */
36
+ injectManagedHuman(request: ImInjectSimulationManagedHumanRequest): Promise<ImInboundMessageView>;
37
+ /** @param request - original instance and request id. @returns persisted inbound receipt without executing input. */
38
+ queryInjection(request: ImSimulationInjectionQuery): ImInboundOperationQuery;
39
+ private validateInjection;
40
+ private inputOperationId;
41
+ private priorInjection;
42
+ /** Begin a deduplicated terminal stop and return after delivery closes durably. */
43
+ beginStop(instanceIdValue: ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
44
+ /** Await an already-begun stop until its persisted terminal state. */
45
+ waitStopped(instanceIdValue: ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
46
+ /** Convert one locally settled tested-Agent reply into isolated inbound for its simulated-user Session. */
47
+ deliverTestedReply(scope: ImSimulationDeliveryScope, outbound: ImOutboundView): Promise<void>;
48
+ private createSerialized;
49
+ private recoverCreating;
50
+ private task;
51
+ private createTestedAgent;
52
+ private ingest;
53
+ private queueReplies;
54
+ private driveReplies;
55
+ private submit;
56
+ private scheduleStop;
57
+ private convergeStop;
58
+ private refreshTools;
59
+ private workspaceForSession;
60
+ private scope;
61
+ private requireRunning;
62
+ private closeReplies;
63
+ private enqueue;
64
+ }
@@ -0,0 +1,14 @@
1
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import type { ImRuntime } from './runtime.ts';
4
+ import type { ImSimulationSessionScope } from './types.ts';
5
+ /**
6
+ * Register only the simulation operations available to one exact live Agent.
7
+ * @param ctx - Agent context that owns the registrations.
8
+ * @param runtime - Host simulation authority.
9
+ * @param agent - exact Agent whose Session is trusted by every operation.
10
+ * @param targetConfigured - whether this Agent's workspace can create a new instance.
11
+ * @param bound - existing instance role for this Session, when present.
12
+ * @returns disposer for every registered tool.
13
+ */
14
+ export declare function registerSimulationTools(ctx: Context, runtime: ImRuntime, agent: Agent, targetConfigured: boolean, bound: ImSimulationSessionScope | undefined): () => void;
@@ -0,0 +1,17 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { SessionId } from '@deepseek-ai/dsh-session';
3
+ import { type ImRuntime } from './runtime.ts';
4
+ import type { ImDeliveryScope, ImOutboundRouteBinding } from './delivery-types.ts';
5
+ import type { ImDirectRecipient } from './types.ts';
6
+ /**
7
+ * Register IM tools and the takeover system-prompt section on a trusted Agent context.
8
+ * @param ctx - unpublished Agent context that owns the registrations.
9
+ * @param runtime - Host runtime that owns history, policy checks, and transports.
10
+ * @param scope - complete admitted conversation identity hidden from model arguments.
11
+ * @param binding - route, workspace, and account generation frozen for this Agent.
12
+ * @param directRecipient - provider peer identity frozen for a direct conversation.
13
+ * @param sessionId - Agent Session whose pre-step authorizes one handling generation.
14
+ * @returns disposer for the prompt section and both tools.
15
+ */
16
+ export declare function registerImAgentTools(ctx: Context, runtime: ImRuntime, scope: ImDeliveryScope, binding: ImOutboundRouteBinding, directRecipient?: ImDirectRecipient, sessionId?: SessionId): () => void;
17
+ export { registerSimulationTools } from './simulation-tools.ts';
@@ -0,0 +1,162 @@
1
+ /** Provider-facing IM transport capability registered with the runtime. */
2
+ import type { CredentialRecord } from '@deepseek-ai/dsh-credentials';
3
+ import type { ImDeliveryOperationId, ImConversationPresentation, ImInboundPageResult, ImInboundSenderEvidence, ImMessageContent, ImProviderCursorCommitResult, ImProviderCursorOwner, ImProviderCursorView } from './delivery-types.ts';
4
+ import type { ImAccountCandidate, ImAccountIdentity, ImAccountSetupRequest, ImAccountView, ImAssignedActorCandidate, ImConversationCandidate, ImConversationCandidatePage, ImConversationKind, ImDirectRecipient, ImPlatform, ImPlatformLoginAttemptId, ImPlatformLoginStatus, ImRevision, ImRouteId, ImRouteTarget } from './types.ts';
5
+ export type { ImAccountSetupRequest, ImConversationCandidate, ImConversationCandidatePage, ImDingTalkAccountSetupRequest, ImWangwangAccountSetupRequest } from './types.ts';
6
+ /** Safe provider result plus an optional opaque credential record for durable storage. */
7
+ export interface ImPreparedAccount {
8
+ readonly displayName: string;
9
+ readonly identity: ImAccountIdentity;
10
+ readonly authorization: ImAccountView['authorization'];
11
+ readonly credentialRecord?: CredentialRecord;
12
+ }
13
+ /** Authorization facts observed by a provider without changing the configured identity. */
14
+ export interface ImTransportAccountInspection {
15
+ readonly authorization: ImAccountView['authorization'];
16
+ }
17
+ /** Provider message before the runtime classifies sender evidence. */
18
+ export interface ImTransportInboundMessage {
19
+ readonly externalMessageId: string;
20
+ readonly senderEvidence: ImInboundSenderEvidence;
21
+ /** Provider-normalized safe presentation; raw credentials, headers, and connection settings are excluded. */
22
+ readonly content: ImMessageContent;
23
+ readonly occurredAt: string;
24
+ /** True only when the provider protocol identifies this configured account in its mention metadata. */
25
+ readonly mentionedConfiguredAccount?: boolean;
26
+ }
27
+ /** One conversation group within a provider-owned receive page. */
28
+ export interface ImTransportConversationPage {
29
+ readonly operationId: ImDeliveryOperationId;
30
+ readonly conversationId: string;
31
+ readonly conversationKind: ImConversationKind;
32
+ /** Provider-known group or peer labels; absent facts stay absent. */
33
+ readonly presentation?: ImConversationPresentation;
34
+ readonly messages: readonly ImTransportInboundMessage[];
35
+ }
36
+ /** One provider page that may span multiple conversations. */
37
+ export interface ImTransportInboundPage {
38
+ readonly operationId: ImDeliveryOperationId;
39
+ readonly owner: ImProviderCursorOwner;
40
+ readonly observedCursor: string | null;
41
+ readonly nextCursor: string | null;
42
+ readonly conversations: readonly ImTransportConversationPage[];
43
+ }
44
+ /** Durable per-conversation receipts followed by the provider-cursor result. */
45
+ export interface ImTransportInboundPageReceipt {
46
+ readonly conversations: readonly ImInboundPageResult[];
47
+ readonly cursor: ImProviderCursorCommitResult;
48
+ }
49
+ /** Enabled route facts needed to choose provider subscriptions and evidence feeds. */
50
+ export interface ImTransportRoutePlan {
51
+ readonly routeId: ImRouteId;
52
+ readonly routeRevision: ImRevision;
53
+ readonly conversationKind: ImConversationKind;
54
+ readonly target: ImRouteTarget;
55
+ readonly needsMentionEvidence: boolean;
56
+ /** Admission routes wake Agents; observe routes only retain history. Absence is admit. */
57
+ readonly mode?: 'admit' | 'observe';
58
+ }
59
+ /** Host observation that keeps history flowing without an enabled route. */
60
+ export interface ImTransportObservationPlan {
61
+ readonly conversationKind: ImConversationKind;
62
+ readonly target: ImRouteTarget;
63
+ }
64
+ /** Listener plan computed from enabled routes and optional observation leases. */
65
+ export interface ImTransportListenPlan {
66
+ readonly routes: readonly ImTransportRoutePlan[];
67
+ readonly observations?: readonly ImTransportObservationPlan[];
68
+ }
69
+ /** Provider listener lifetime returned only after the listener is ready. */
70
+ export interface ImTransportListener {
71
+ /** Settles after the listener ends; rejects when an established listener fails. */
72
+ readonly done: Promise<void>;
73
+ /** Request an orderly stop. The `done` promise must settle after this request. @returns when provider stop has been requested. */
74
+ dispose(): Promise<void>;
75
+ }
76
+ /** Sink owned by the runtime while a provider listener is active. */
77
+ export interface ImTransportSink {
78
+ /**
79
+ * Persist every conversation group before advancing the provider-owned cursor.
80
+ * A partial failure leaves successful groups durable so a replay can deduplicate them.
81
+ * @param page - stable provider/page identities, cursor CAS, and normalized groups.
82
+ * @returns every durable group receipt and the final cursor result.
83
+ */
84
+ receivePage(page: ImTransportInboundPage): Promise<ImTransportInboundPageReceipt>;
85
+ /** @param owner - provider feed identity. @returns the durable merchant cursor, or a null cursor before the first listen. */
86
+ getProviderCursor(owner: ImProviderCursorOwner): ImProviderCursorView;
87
+ }
88
+ /** Automatic-send authority survives preparation only within its customer's handling epoch. */
89
+ export interface ImAutomaticSendAuthorization {
90
+ /** Cancellation during preparation; customer revocation stops affecting it after submission. */
91
+ readonly signal: AbortSignal;
92
+ /** Whether a provider has obtained permission to submit externally. */
93
+ readonly submitted: boolean;
94
+ /** @returns Current authorization. Providers call once, after asynchronous preparation and immediately before submission. */
95
+ authorizeSubmission(): boolean;
96
+ /** Release cancellation listeners after the provider settles. */
97
+ dispose(): void;
98
+ }
99
+ /** Provider outbound request. */
100
+ export interface ImTransportSendRequest {
101
+ readonly account: ImAccountView;
102
+ readonly conversationId: string;
103
+ readonly conversationKind: ImConversationKind;
104
+ readonly directRecipient?: ImDirectRecipient;
105
+ readonly requestId: string;
106
+ readonly text: string;
107
+ readonly aiTag?: boolean;
108
+ /** Required for automatic sends; absent for manual sends. Providers must authorize immediately before external submission. */
109
+ readonly submission?: ImAutomaticSendAuthorization;
110
+ }
111
+ /** Provider send outcome before or after receipt confirmation. */
112
+ export type ImTransportSendResult = {
113
+ readonly state: 'sent';
114
+ readonly externalMessageId: string;
115
+ readonly rawStatus?: string;
116
+ } | {
117
+ readonly state: 'failed';
118
+ readonly code: string;
119
+ readonly message: string;
120
+ } | {
121
+ readonly state: 'unknown';
122
+ readonly externalMessageId?: string;
123
+ };
124
+ /** Receipt lookup input for an uncertain outbound result. */
125
+ export interface ImTransportConfirmRequest {
126
+ readonly account: ImAccountView;
127
+ readonly requestId: string;
128
+ readonly externalMessageId?: string;
129
+ readonly conversationId?: string;
130
+ readonly conversationKind?: ImConversationKind;
131
+ readonly text?: string;
132
+ }
133
+ /** Complete provider capability registered under one platform. */
134
+ export interface ImTransport {
135
+ readonly platform: ImPlatform;
136
+ /** Start or rejoin an interactive provider login. Implementations return only safe authorization instructions. */
137
+ startLogin?(signal: AbortSignal): Promise<ImPlatformLoginStatus>;
138
+ /** @param attemptId - provider-minted login identity. @returns its current safe state. */
139
+ loginStatus?(attemptId: ImPlatformLoginAttemptId): ImPlatformLoginStatus;
140
+ /** @param attemptId - provider-minted login identity. @returns the terminal cancelled state. */
141
+ cancelLogin?(attemptId: ImPlatformLoginAttemptId): Promise<ImPlatformLoginStatus>;
142
+ /** @param signal - caller lifetime. @returns installed or admitted identities safe for account selection. */
143
+ listAccountCandidates(signal: AbortSignal): Promise<readonly ImAccountCandidate[]>;
144
+ /** @param request - write-only setup input. @param signal - caller lifetime. @returns verified safe facts and credential payload. */
145
+ prepareAccount(request: ImAccountSetupRequest, signal: AbortSignal): Promise<ImPreparedAccount>;
146
+ /** @param account - configured safe identity. @param signal - caller lifetime. @returns current provider authorization facts. */
147
+ inspectAccount(account: ImAccountView, signal: AbortSignal): Promise<ImTransportAccountInspection>;
148
+ /** @param account - configured safe identity. @param signal - caller lifetime. @returns refreshed authorization facts. */
149
+ refreshAccount(account: ImAccountView, signal: AbortSignal): Promise<ImTransportAccountInspection>;
150
+ /** @param account - safe configured account. @param cursor - provider cursor. @param signal - caller lifetime. @returns one candidate page. */
151
+ discoverConversations(account: ImAccountView, cursor: string | undefined, signal: AbortSignal): Promise<ImConversationCandidatePage>;
152
+ /** @param account - safe configured account. @param conversationId - platform conversation identifier. @param conversationKind - provider category. @param signal - caller lifetime. @returns provider-known title, or the identifier when the title is unknown. */
153
+ inspectConversation(account: ImAccountView, conversationId: string, conversationKind: ImConversationKind, signal: AbortSignal): Promise<ImConversationCandidate>;
154
+ /** @param account - safe configured account. @param signal - caller lifetime. @returns assigned service accounts when the platform exposes them. */
155
+ listAssignedActors?(account: ImAccountView, signal: AbortSignal): Promise<readonly ImAssignedActorCandidate[]>;
156
+ /** @param account - account to listen on. @param plan - enabled routes and required provider evidence. @param sink - runtime-owned durable sink. @param signal - listener lifetime. @returns lifetime handle only after the provider has established and verified the usable listener. */
157
+ listen(account: ImAccountView, plan: ImTransportListenPlan, sink: ImTransportSink, signal: AbortSignal): Promise<ImTransportListener>;
158
+ /** @param request - normalized outbound request. @param signal - caller lifetime. @returns provider result. */
159
+ send(request: ImTransportSendRequest, signal: AbortSignal): Promise<ImTransportSendResult>;
160
+ /** @param request - uncertain delivery to inspect. @param signal - caller lifetime. @returns current provider result. */
161
+ confirm(request: ImTransportConfirmRequest, signal: AbortSignal): Promise<ImTransportSendResult>;
162
+ }
@@ -0,0 +1,41 @@
1
+ /** Cordis registry for product IM transport providers. */
2
+ import { Context, Service } from '@deepseek-ai/cordis';
3
+ import type { ImPlatform } from './types.ts';
4
+ import type { ImTransport } from './transport.ts';
5
+ /** Stable transport registry failure codes. */
6
+ export type ImTransportErrorCode = 'IM_TRANSPORT_CONFLICT' | 'IM_TRANSPORT_UNAVAILABLE' | 'IM_TRANSPORT_AUTHORIZATION_REQUIRED';
7
+ /** Structured transport registry failure. */
8
+ export declare class ImTransportError extends Error {
9
+ readonly code: ImTransportErrorCode;
10
+ /** @param code - stable failure code. @param message - diagnostic detail. */
11
+ constructor(code: ImTransportErrorCode, message: string);
12
+ }
13
+ declare module '@deepseek-ai/cordis' {
14
+ interface Context {
15
+ imTransports: ImTransports;
16
+ }
17
+ interface Events {
18
+ /**
19
+ * A platform transport became available or unavailable.
20
+ * @param platform - changed platform reservation.
21
+ * @mode emit
22
+ */
23
+ 'imTransports/changed'(platform: ImPlatform): void;
24
+ }
25
+ }
26
+ /** Registry whose entries live and die with their registering Cordis fiber. */
27
+ export declare class ImTransports extends Service {
28
+ private readonly providers;
29
+ /** @param ctx - owning Cordis context. */
30
+ constructor(ctx: Context);
31
+ /** @param provider - complete transport capability. @returns disposer that releases the platform reservation. */
32
+ register(provider: ImTransport): () => void;
33
+ /** @param platform - platform to resolve. @returns the registered provider. */
34
+ require(platform: ImPlatform): ImTransport;
35
+ /** @param platform - platform to inspect. @returns the transport, or absence while unloaded. */
36
+ get(platform: ImPlatform): ImTransport | undefined;
37
+ /** @returns currently registered transport platforms in stable display order. */
38
+ registeredPlatforms(): readonly ImPlatform[];
39
+ /** Notify post-registration observers without making their failure revoke the committed reservation. */
40
+ private publish;
41
+ }