@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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +58 -0
  3. package/README.md +290 -2
  4. package/README.zh.md +290 -0
  5. package/UPSTREAM.json +66 -0
  6. package/lib/index.js +140 -0
  7. package/lib/inline-image-DuX6vSEI.js +20 -0
  8. package/lib/read-receipts.js +413 -0
  9. package/lib/read-state-CnUZKCuY.js +1868 -0
  10. package/lib/runtime-Bm6iSEpv.js +10939 -0
  11. package/lib/tools.js +2 -0
  12. package/lib/types/account-placement.d.ts +22 -0
  13. package/lib/types/admission-annotations.d.ts +40 -0
  14. package/lib/types/agent-coordinator.d.ts +129 -0
  15. package/lib/types/agent-media.d.ts +46 -0
  16. package/lib/types/agent-prompt.d.ts +24 -0
  17. package/lib/types/checkpoint-recovery.d.ts +32 -0
  18. package/lib/types/checkpoint.d.ts +127 -0
  19. package/lib/types/consumer-chat-links.d.ts +59 -0
  20. package/lib/types/delivery-schema.d.ts +176 -0
  21. package/lib/types/delivery-sqlite.d.ts +387 -0
  22. package/lib/types/delivery-types.d.ts +744 -0
  23. package/lib/types/delivery.d.ts +114 -0
  24. package/lib/types/errors.d.ts +8 -0
  25. package/lib/types/evaluation-accounts.d.ts +86 -0
  26. package/lib/types/index.d.ts +51 -0
  27. package/lib/types/inline-image.d.ts +7 -0
  28. package/lib/types/input-drain.d.ts +73 -0
  29. package/lib/types/knowledge-image.d.ts +64 -0
  30. package/lib/types/media-lifetime.d.ts +22 -0
  31. package/lib/types/media.d.ts +32 -0
  32. package/lib/types/message-preview.d.ts +4 -0
  33. package/lib/types/message-upload.d.ts +55 -0
  34. package/lib/types/nas-host-lease.d.ts +33 -0
  35. package/lib/types/placement-slice.d.ts +30 -0
  36. package/lib/types/policies.d.ts +63 -0
  37. package/lib/types/preset-model.d.ts +50 -0
  38. package/lib/types/read-context.d.ts +27 -0
  39. package/lib/types/read-receipts.d.ts +10 -0
  40. package/lib/types/read-records.d.ts +30 -0
  41. package/lib/types/read-state.d.ts +18 -0
  42. package/lib/types/read-types.d.ts +28 -0
  43. package/lib/types/restart-recovery.d.ts +38 -0
  44. package/lib/types/route-resolve.d.ts +10 -0
  45. package/lib/types/runtime.d.ts +668 -0
  46. package/lib/types/schema.d.ts +61 -0
  47. package/lib/types/script-clock.d.ts +14 -0
  48. package/lib/types/sdk.d.ts +108 -0
  49. package/lib/types/service-types.d.ts +366 -0
  50. package/lib/types/session-events.d.ts +28 -0
  51. package/lib/types/simulation-batch.d.ts +40 -0
  52. package/lib/types/simulation-controller.d.ts +77 -0
  53. package/lib/types/simulation-operator.d.ts +19 -0
  54. package/lib/types/simulation-tools.d.ts +14 -0
  55. package/lib/types/sqlite-connection.d.ts +27 -0
  56. package/lib/types/time.d.ts +13 -0
  57. package/lib/types/tools.d.ts +17 -0
  58. package/lib/types/transport.d.ts +202 -0
  59. package/lib/types/transports.d.ts +48 -0
  60. package/lib/types/types.d.ts +521 -0
  61. package/lib/types/typing.d.ts +33 -0
  62. package/lib/types/upload-types.d.ts +121 -0
  63. package/lib/types.js +2 -0
  64. package/locale/en.json +6 -0
  65. package/locale/zh.json +6 -0
  66. package/package.json +125 -3
@@ -0,0 +1,40 @@
1
+ import type { ImRuntimeService } from './service-types.ts';
2
+ import type { ImCreateSimulationInstanceRequest, ImSimulationInstanceView } from './types.ts';
3
+ /** Deployment limits for one batch controller. */
4
+ export interface ImSimulationBatchConfig {
5
+ /** Maximum simultaneous instances; defaults to 2. */
6
+ readonly maxConcurrency?: number;
7
+ }
8
+ /** A caller-owned simulated-user Session and its work against one paired instance. */
9
+ export interface ImSimulationBatchJob<T> {
10
+ readonly request: ImCreateSimulationInstanceRequest;
11
+ /** @param instance - Running pair owned by this batch. @param signal - Batch and caller cancellation. @returns Job result after all step work settles. */
12
+ execute(instance: ImSimulationInstanceView, signal: AbortSignal): Promise<T>;
13
+ }
14
+ /** Per-job result in input order; a failed job never discards completed siblings. */
15
+ export type ImSimulationBatchResult<T> = {
16
+ readonly status: 'fulfilled';
17
+ readonly value: T;
18
+ } | {
19
+ readonly status: 'rejected';
20
+ readonly error: unknown;
21
+ };
22
+ type Runtime = Pick<ImRuntimeService, 'createSimulationInstance' | 'beginStopSimulation' | 'waitSimulationStopped'>;
23
+ /** Batch owner; caller-owned simulated-user Sessions remain available after instance cleanup. */
24
+ export declare class ImSimulationBatch {
25
+ private readonly runtime;
26
+ private readonly concurrency;
27
+ private active;
28
+ /** @param runtime - Host instance lifecycle authority. @param config - Validated concurrency limit. */
29
+ constructor(runtime: Runtime, config?: ImSimulationBatchConfig);
30
+ /**
31
+ * Run one batch, retaining input order and stopping every created instance before resolving.
32
+ * @param jobs - Distinct live simulated-user Sessions; callbacks must settle on cancellation.
33
+ * @param signal - Optional caller cancellation; absent means only stop() can cancel the batch.
34
+ * @returns One result per job; cleanup failure cancels remaining jobs and retains both failures. Concurrent run calls reject.
35
+ */
36
+ run<T>(jobs: readonly ImSimulationBatchJob<T>[], signal?: AbortSignal): Promise<readonly ImSimulationBatchResult<T>[]>;
37
+ /** Cancel active work and queued creation, then await all callbacks and terminal cleanup. */
38
+ stop(): Promise<void>;
39
+ }
40
+ export {};
@@ -0,0 +1,77 @@
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 ImInjectSimulationOperatorRequest, type ImSimulationOperatorReceipt } from './simulation-operator.ts';
7
+ import type { ImCreateSimulationInstanceRequest, ImCreateManualSimulationInstanceRequest, ImInjectSimulationManagedHumanRequest, ImInjectSimulationMemberRequest, ImSimulationInstanceView, ImSimulationInjectionQuery } from './types.ts';
8
+ /** Runtime-owned controller; durable state is authoritative and live handles are only execution resources. */
9
+ export declare class ImSimulationController {
10
+ private readonly ctx;
11
+ private readonly runtime;
12
+ private readonly instances;
13
+ private readonly coordinator;
14
+ private readonly testedHandles;
15
+ private readonly toolDisposers;
16
+ private readonly tails;
17
+ private readonly creations;
18
+ private readonly stopping;
19
+ private readonly replyClosures;
20
+ private creationTail;
21
+ private readonly hostBuyers;
22
+ private disposed;
23
+ private disposeCreated?;
24
+ private disposeDisposed?;
25
+ /** @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. */
26
+ constructor(ctx: Context, runtime: ImRuntime, instances: KvTable<ImSimulationInstanceId, ImSimulationInstanceView>, coordinator: ImAgentCoordinator);
27
+ /** Recover incomplete lifecycles without resuming ordinary running Sessions. */
28
+ start(): Promise<void>;
29
+ /** Stop lifecycle work and release only handles and tool registrations owned here. */
30
+ dispose(): Promise<void>;
31
+ /** Re-evaluate tool availability after target or instance state changes. */
32
+ refreshAllTools(): void;
33
+ /** @param request - Live simulated-user Session and target conversation. @param formalOnly - Reject evaluation targets inside the serialized creation operation. @returns The durably published tested Session pair. */
34
+ create(request: ImCreateSimulationInstanceRequest, formalOnly: boolean): Promise<ImSimulationInstanceView>;
35
+ /** @param request - enabled all-direct route. @returns the empty, persisted tested Session. */
36
+ createManual(request: ImCreateManualSimulationInstanceRequest): Promise<ImSimulationInstanceView>;
37
+ /** Inject one allow-listed participant through the instance-local adapter. */
38
+ injectMember(request: ImInjectSimulationMemberRequest): Promise<ImInboundMessageView>;
39
+ /** Inject the frozen account owner locally as operator input, never as a member. */
40
+ injectManagedHuman(request: ImInjectSimulationManagedHumanRequest): Promise<ImInboundMessageView>;
41
+ /** @param request - Private operator text and retry identity. @returns Durable acceptance only in the running tested Session. */
42
+ injectOperator(request: ImInjectSimulationOperatorRequest): Promise<ImSimulationOperatorReceipt>;
43
+ /** @param request - original instance and request id. @returns persisted inbound receipt without executing input. */
44
+ queryInjection(request: ImSimulationInjectionQuery): ImInboundOperationQuery;
45
+ private validateInjection;
46
+ private inputOperationId;
47
+ private priorInjection;
48
+ /** Begin a deduplicated terminal stop and return after delivery closes durably. */
49
+ beginStop(instanceIdValue: ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
50
+ /** Await an already-begun stop until its persisted terminal state. */
51
+ waitStopped(instanceIdValue: ImSimulationInstanceId): Promise<ImSimulationInstanceView>;
52
+ /** Convert one locally settled tested-Agent reply into isolated inbound for its simulated-user Session. */
53
+ deliverTestedReply(scope: ImSimulationDeliveryScope, outbound: ImOutboundView): Promise<void>;
54
+ private createSerialized;
55
+ /** Creation includes conversation initialization; failure releases the tested handle and persists a failed instance. */
56
+ private completeCreation;
57
+ private recoverCreating;
58
+ private seedManualConversation;
59
+ private task;
60
+ private createTestedAgent;
61
+ private ingest;
62
+ private queueReplies;
63
+ /** @param id - Running pair driven by a deterministic Host role. @returns Disposer restoring automatic buyer delivery after its owner stops the case. */
64
+ holdBuyer(id: ImSimulationInstanceId): () => void;
65
+ /** @param id - Running pair held by a Host driver. @returns Number of AI and eligible staff replies durably delivered to the buyer; rejects if the buyer is not held or live. */
66
+ deliverBuyerReplies(id: ImSimulationInstanceId): Promise<number>;
67
+ private driveReplies;
68
+ private submit;
69
+ private scheduleStop;
70
+ private convergeStop;
71
+ private refreshTools;
72
+ private workspaceForSession;
73
+ private scope;
74
+ private requireRunning;
75
+ private closeReplies;
76
+ private enqueue;
77
+ }
@@ -0,0 +1,19 @@
1
+ import { type MessageId, type UserMessage } from '@deepseek-ai/dsh-llm';
2
+ import type { Session, SessionId } from '@deepseek-ai/dsh-session';
3
+ import type { ImDeliveryOperationId, ImSimulationInstanceId } from './delivery-types.ts';
4
+ /** Caller-owned identity and text for one private operator message. */
5
+ export interface ImInjectSimulationOperatorRequest {
6
+ readonly instanceId: ImSimulationInstanceId;
7
+ readonly requestId: ImDeliveryOperationId;
8
+ readonly text: string;
9
+ }
10
+ /** Durable inbox acceptance; it does not imply that the target has answered. */
11
+ export interface ImSimulationOperatorReceipt {
12
+ readonly sessionId: SessionId;
13
+ readonly messageId: MessageId;
14
+ readonly status: 'accepted';
15
+ }
16
+ /** @param request - Private message with a stable retry identity. @returns Immutable, unlabelled user input with the same identity on retries. */
17
+ export declare function simulationOperatorMessage(request: ImInjectSimulationOperatorRequest): UserMessage;
18
+ /** @param session - Target's persisted event view. @param message - Expected retry identity and content. @returns Whether the same message is already queued or consumed; conflicting reuse throws. */
19
+ export declare function hasSimulationOperatorMessage(session: Session, message: UserMessage): boolean;
@@ -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,27 @@
1
+ /** Connection-local SQLite locking and page-cache settings shared by product journals. */
2
+ import type { DatabaseSync } from 'node:sqlite';
3
+ /** SQLite locking policy; EXCLUSIVE requires sole ownership until connection close. */
4
+ export type SqliteLockingMode = 'NORMAL' | 'EXCLUSIVE';
5
+ /** Deployment settings; an absent cache budget keeps SQLite's default page cache. */
6
+ export interface SqliteConnectionConfig {
7
+ readonly lockingMode?: SqliteLockingMode | undefined;
8
+ readonly cacheSizeKiB?: number | undefined;
9
+ }
10
+ /** Validated connection settings; null preserves SQLite's default cache budget. */
11
+ export interface SqliteConnectionSpec {
12
+ readonly lockingMode: SqliteLockingMode;
13
+ readonly cacheSizeKiB: number | null;
14
+ }
15
+ /**
16
+ * Validate deployment settings before acquiring filesystem or database resources.
17
+ * @param config - Requested connection-local settings.
18
+ * @returns Explicit locking policy and optional page-cache budget in KiB.
19
+ */
20
+ export declare function resolveSqliteConnectionSpec(config: SqliteConnectionConfig): SqliteConnectionSpec;
21
+ /**
22
+ * Apply and verify connection-local settings before any reads or migrations; the caller closes on failure.
23
+ * EXCLUSIVE retains the file lock after a transaction, preventing other connections from reading or writing.
24
+ * @param db - Newly opened connection owned by the caller.
25
+ * @param spec - Validated deployment settings.
26
+ */
27
+ export declare function configureSqliteConnection(db: DatabaseSync, spec: SqliteConnectionSpec): void;
@@ -0,0 +1,13 @@
1
+ /** Minute-precision shop time for IM records and customer-service clock context. */
2
+ /**
3
+ * Format an absolute instant in a configured shop time zone.
4
+ * @param instant - ISO timestamp or milliseconds since the Unix epoch.
5
+ * @param timeZone - IANA time zone; invalid zones fail immediately.
6
+ * @returns Gregorian YYYY-MM-DD HH:mm with a 24-hour clock.
7
+ */
8
+ export declare function formatImTime(instant: string | number, timeZone: string): string;
9
+ /** Instance-owned running clock; the Host can jump forward between completed steps. */
10
+ export interface ImClockSource {
11
+ /** @returns Absolute Unix milliseconds. Throwing stops request preparation; there is no system-time fallback. */
12
+ now(): number;
13
+ }
@@ -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,202 @@
1
+ /** Provider-facing IM transport capability registered with the runtime. */
2
+ import type { CredentialRecord } from '@deepseek-ai/dsh-credentials';
3
+ import type { ImSdkProvider } from './sdk.ts';
4
+ import type { ImDeliveryOperationId, ImConversationPresentation, ImInboundPageResult, ImInboundSenderEvidence, ImMessageContent, ImProviderCursorCommitResult, ImProviderCursorOwner, ImProviderCursorView, ImRealDeliveryScope } from './delivery-types.ts';
5
+ import type { ImAccountCandidate, ImAccountIdentity, ImAccountSetupRequest, ImAccountView, ImAssignedActorCandidate, ImConversationCandidate, ImConversationCandidatePage, ImConversationKind, ImDirectRecipient, ImPlatform, ImPlatformLoginAttemptId, ImPlatformLoginStatus, ImRevision, ImRouteId, ImRouteTarget } from './types.ts';
6
+ export type { ImAccountSetupRequest, ImConversationCandidate, ImConversationCandidatePage, ImDingTalkAccountSetupRequest, ImWangwangAccountSetupRequest } from './types.ts';
7
+ /** Safe provider result plus an optional opaque credential record for durable storage. */
8
+ export interface ImPreparedAccount {
9
+ readonly displayName: string;
10
+ readonly identity: ImAccountIdentity;
11
+ readonly authorization: ImAccountView['authorization'];
12
+ readonly credentialRecord?: CredentialRecord;
13
+ }
14
+ /** Authorization facts observed by a provider without changing the configured identity. */
15
+ export interface ImTransportAccountInspection {
16
+ readonly authorization: ImAccountView['authorization'];
17
+ }
18
+ /** Provider message before the runtime classifies sender evidence. */
19
+ export interface ImTransportInboundMessage {
20
+ /** Provider facts for this message; absent fields stay unknown after persistence. */
21
+ readonly uploadIdentity?: import('./upload-types.ts').ImUploadIdentity;
22
+ readonly externalMessageId: string;
23
+ readonly senderEvidence: ImInboundSenderEvidence;
24
+ /** Provider-normalized safe presentation; raw credentials, headers, and connection settings are excluded. */
25
+ readonly content: ImMessageContent;
26
+ readonly occurredAt: string;
27
+ /** True only when the provider protocol identifies this configured account in its mention metadata. */
28
+ readonly mentionedConfiguredAccount?: boolean;
29
+ }
30
+ /** One conversation group within a provider-owned receive page. */
31
+ export interface ImTransportConversationPage {
32
+ readonly operationId: ImDeliveryOperationId;
33
+ readonly conversationId: string;
34
+ readonly conversationKind: ImConversationKind;
35
+ /** Provider-known group or peer labels; absent facts stay absent. */
36
+ readonly presentation?: ImConversationPresentation;
37
+ /** Platform-provided peer identity for direct sends; never the conversation id. */
38
+ readonly directRecipient?: ImDirectRecipient;
39
+ readonly messages: readonly ImTransportInboundMessage[];
40
+ }
41
+ /** One provider page that may span multiple conversations. */
42
+ export interface ImTransportInboundPage {
43
+ readonly operationId: ImDeliveryOperationId;
44
+ readonly owner: ImProviderCursorOwner;
45
+ readonly observedCursor: string | null;
46
+ readonly nextCursor: string | null;
47
+ readonly conversations: readonly ImTransportConversationPage[];
48
+ }
49
+ /** Durable per-conversation receipts followed by the provider-cursor result. */
50
+ export interface ImTransportInboundPageReceipt {
51
+ readonly conversations: readonly ImInboundPageResult[];
52
+ readonly cursor: ImProviderCursorCommitResult;
53
+ }
54
+ /** Enabled route facts needed to choose provider subscriptions and evidence feeds. */
55
+ export interface ImTransportRoutePlan {
56
+ readonly routeId: ImRouteId;
57
+ readonly routeRevision: ImRevision;
58
+ readonly conversationKind: ImConversationKind;
59
+ readonly target: ImRouteTarget;
60
+ readonly needsMentionEvidence: boolean;
61
+ /** Admission routes wake Agents; observe routes only retain history. Absence is admit. */
62
+ readonly mode?: 'admit' | 'observe';
63
+ }
64
+ /** Host observation that keeps history flowing without an enabled route. */
65
+ export interface ImTransportObservationPlan {
66
+ readonly conversationKind: ImConversationKind;
67
+ readonly target: ImRouteTarget;
68
+ }
69
+ /** Listener plan computed from enabled routes and optional observation leases. */
70
+ export interface ImTransportListenPlan {
71
+ readonly routes: readonly ImTransportRoutePlan[];
72
+ readonly observations?: readonly ImTransportObservationPlan[];
73
+ }
74
+ /** Provider listener lifetime returned only after the listener is ready. */
75
+ export interface ImTransportListener {
76
+ /** Settles after the listener ends; rejects with ImTransportListenerError when the provider can classify a failure. The runtime owns bounded retry scheduling. */
77
+ readonly done: Promise<void>;
78
+ /** Request an orderly stop. The `done` promise must settle after this request. @returns when provider stop has been requested. */
79
+ dispose(): Promise<void>;
80
+ }
81
+ /** One SDK message; the runtime resolves its buyer into an existing SaaS conversation. */
82
+ export interface ImRealtimeInboundRequest {
83
+ readonly account: ImAccountView;
84
+ readonly sdkGeneration: number;
85
+ readonly buyerUid: string;
86
+ readonly externalMessageId: string;
87
+ readonly content: ImMessageContent;
88
+ readonly occurredAt: string;
89
+ }
90
+ /** No deferred message is persisted; storage failures reject rather than returning duplicate. */
91
+ export type ImRealtimeInboundResult = {
92
+ readonly state: 'admitted' | 'duplicate';
93
+ readonly scope: ImRealDeliveryScope;
94
+ } | {
95
+ readonly state: 'deferred';
96
+ readonly reason: 'account-changed' | 'sdk-offline' | 'sdk-generation' | 'buyer-unknown' | 'buyer-ambiguous' | 'assignment-route' | 'route-unavailable' | 'native-sender';
97
+ };
98
+ /** Exact platform message lookup, optionally confined to one complete conversation identity. */
99
+ export type ImInboundContentQuery = {
100
+ readonly externalMessageId: string;
101
+ } & ({
102
+ readonly conversationId: string;
103
+ readonly conversationKind: ImConversationKind;
104
+ } | {
105
+ readonly conversationId?: never;
106
+ readonly conversationKind?: never;
107
+ });
108
+ /** Sink owned by the runtime while a provider listener is active. */
109
+ export interface ImTransportSink {
110
+ /**
111
+ * Persist every conversation group before advancing the provider-owned cursor.
112
+ * A partial failure leaves successful groups durable so a replay can deduplicate them.
113
+ * @param page - stable provider/page identities, cursor CAS, and normalized groups.
114
+ * @returns every durable group receipt and the final cursor result.
115
+ */
116
+ receivePage(page: ImTransportInboundPage): Promise<ImTransportInboundPageReceipt>;
117
+ /** @param request - SDK account generation, peer and normalized message. @param signal - optional caller cancellation while waiting for reception; absence uses the listener lifetime. @returns admission into an existing scope, a duplicate, or a deferred reason; never advances SaaS cursors. */
118
+ receiveRealtime(request: ImRealtimeInboundRequest, signal?: AbortSignal): Promise<ImRealtimeInboundResult>;
119
+ /** @param request - exact platform message id, optionally restricted to one conversation in this listener account. @returns stored content or absence; storage failures throw. */
120
+ findInboundContent(request: ImInboundContentQuery): ImMessageContent | undefined;
121
+ /** @param uid - SDK sender UID. @returns whether it names the configured merchant, main account or an observed native service account; storage failures throw. */
122
+ isNativeSender(uid: string): boolean;
123
+ /** @param owner - provider feed identity. @returns the durable merchant cursor, or a null cursor before the first listen. */
124
+ getProviderCursor(owner: ImProviderCursorOwner): ImProviderCursorView;
125
+ }
126
+ /** Send authority survives preparation only within the caller's customer handling epoch. */
127
+ export interface ImAutomaticSendAuthorization {
128
+ /** Cancellation during preparation; customer revocation stops affecting it after submission. */
129
+ readonly signal: AbortSignal;
130
+ /** Whether a provider has obtained permission to submit externally. */
131
+ readonly submitted: boolean;
132
+ /** @returns Current authorization. Providers call once, after asynchronous preparation and immediately before submission. */
133
+ authorizeSubmission(): boolean;
134
+ /** Release cancellation listeners after the provider settles. */
135
+ dispose(): void;
136
+ }
137
+ /** Provider outbound request. */
138
+ export interface ImTransportSendRequest {
139
+ readonly account: ImAccountView;
140
+ readonly conversationId: string;
141
+ readonly conversationKind: ImConversationKind;
142
+ readonly directRecipient?: ImDirectRecipient;
143
+ readonly requestId: string;
144
+ readonly text: string;
145
+ readonly aiTag?: boolean;
146
+ /** Required for automatic sends and handling-constrained manual sends. Providers authorize immediately before external submission. */
147
+ readonly submission?: ImAutomaticSendAuthorization;
148
+ }
149
+ /** Provider send outcome before or after receipt confirmation. */
150
+ export type ImTransportSendResult = {
151
+ readonly state: 'sent';
152
+ readonly externalMessageId: string;
153
+ readonly rawStatus?: string;
154
+ } | {
155
+ readonly state: 'failed';
156
+ readonly code: string;
157
+ readonly message: string;
158
+ } | {
159
+ readonly state: 'unknown';
160
+ readonly externalMessageId?: string;
161
+ };
162
+ /** Receipt lookup input for an uncertain outbound result. */
163
+ export interface ImTransportConfirmRequest {
164
+ readonly account: ImAccountView;
165
+ readonly requestId: string;
166
+ readonly externalMessageId?: string;
167
+ readonly conversationId?: string;
168
+ readonly conversationKind?: ImConversationKind;
169
+ readonly text?: string;
170
+ }
171
+ /** Complete provider capability registered under one platform. */
172
+ export interface ImTransport {
173
+ readonly platform: ImPlatform;
174
+ /** Optional secondary SDK connection. Wangwang text and media both require an online generation of this connection. */
175
+ readonly sdk?: ImSdkProvider | undefined;
176
+ /** Start or rejoin an interactive provider login. Implementations return only safe authorization instructions. */
177
+ startLogin?(signal: AbortSignal): Promise<ImPlatformLoginStatus>;
178
+ /** @param attemptId - provider-minted login identity. @returns its current safe state. */
179
+ loginStatus?(attemptId: ImPlatformLoginAttemptId): ImPlatformLoginStatus;
180
+ /** @param attemptId - provider-minted login identity. @returns the terminal cancelled state. */
181
+ cancelLogin?(attemptId: ImPlatformLoginAttemptId): Promise<ImPlatformLoginStatus>;
182
+ /** @param signal - caller lifetime. @returns installed or admitted identities safe for account selection. */
183
+ listAccountCandidates(signal: AbortSignal): Promise<readonly ImAccountCandidate[]>;
184
+ /** @param request - write-only setup input. @param signal - caller lifetime. @returns verified safe facts and credential payload. */
185
+ prepareAccount(request: ImAccountSetupRequest, signal: AbortSignal): Promise<ImPreparedAccount>;
186
+ /** @param account - configured safe identity. @param signal - caller lifetime. @returns current provider authorization facts. */
187
+ inspectAccount(account: ImAccountView, signal: AbortSignal): Promise<ImTransportAccountInspection>;
188
+ /** @param account - configured safe identity. @param signal - caller lifetime. @returns refreshed authorization facts. */
189
+ refreshAccount(account: ImAccountView, signal: AbortSignal): Promise<ImTransportAccountInspection>;
190
+ /** @param account - safe configured account. @param cursor - provider cursor. @param signal - caller lifetime. @returns one candidate page. */
191
+ discoverConversations(account: ImAccountView, cursor: string | undefined, signal: AbortSignal): Promise<ImConversationCandidatePage>;
192
+ /** @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. */
193
+ inspectConversation(account: ImAccountView, conversationId: string, conversationKind: ImConversationKind, signal: AbortSignal): Promise<ImConversationCandidate>;
194
+ /** @param account - safe configured account. @param signal - caller lifetime. @returns assigned service accounts when the platform exposes them. */
195
+ listAssignedActors?(account: ImAccountView, signal: AbortSignal): Promise<readonly ImAssignedActorCandidate[]>;
196
+ /** @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. */
197
+ listen(account: ImAccountView, plan: ImTransportListenPlan, sink: ImTransportSink, signal: AbortSignal): Promise<ImTransportListener>;
198
+ /** @param request - normalized outbound request. @param signal - caller lifetime. @returns provider result. */
199
+ send(request: ImTransportSendRequest, signal: AbortSignal): Promise<ImTransportSendResult>;
200
+ /** @param request - uncertain delivery to inspect. @param signal - caller lifetime. @returns current provider result. */
201
+ confirm(request: ImTransportConfirmRequest, signal: AbortSignal): Promise<ImTransportSendResult>;
202
+ }
@@ -0,0 +1,48 @@
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
+ /** Provider listener failure with a safe code and an explicit authorization disposition. */
14
+ export declare class ImTransportListenerError extends Error {
15
+ readonly code: string;
16
+ readonly authorization: boolean;
17
+ /** @param code - stable platform error code. @param authorization - whether credentials require operator action. @param cause - underlying provider failure, excluded from public state. */
18
+ constructor(code: string, authorization?: boolean, cause?: unknown);
19
+ }
20
+ declare module '@deepseek-ai/cordis' {
21
+ interface Context {
22
+ imTransports: ImTransports;
23
+ }
24
+ interface Events {
25
+ /**
26
+ * A platform transport became available or unavailable.
27
+ * @param platform - changed platform reservation.
28
+ * @mode emit
29
+ */
30
+ 'imTransports/changed'(platform: ImPlatform): void;
31
+ }
32
+ }
33
+ /** Registry whose entries live and die with their registering Cordis fiber. */
34
+ export declare class ImTransports extends Service {
35
+ private readonly providers;
36
+ /** @param ctx - owning Cordis context. */
37
+ constructor(ctx: Context);
38
+ /** @param provider - complete transport capability. @returns disposer that releases the platform reservation. */
39
+ register(provider: ImTransport): () => void;
40
+ /** @param platform - platform to resolve. @returns the registered provider. */
41
+ require(platform: ImPlatform): ImTransport;
42
+ /** @param platform - platform to inspect. @returns the transport, or absence while unloaded. */
43
+ get(platform: ImPlatform): ImTransport | undefined;
44
+ /** @returns currently registered transport platforms in stable display order. */
45
+ registeredPlatforms(): readonly ImPlatform[];
46
+ /** Notify post-registration observers without making their failure revoke the committed reservation. */
47
+ private publish;
48
+ }