@gestaltrun/dsh-im-runtime 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tools.js ADDED
@@ -0,0 +1,2 @@
1
+ import { n as registerImAgentTools, r as registerSimulationTools } from "./runtime-C0-S-_CC.js";
2
+ export { registerImAgentTools, registerSimulationTools };
@@ -0,0 +1,84 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { ImDeliveryScope } from './delivery-types.ts';
3
+ import type { ImRuntime } from './runtime.ts';
4
+ /** Runtime-owned coordinator; one serialized driver and one timer exist per complete scope. */
5
+ export declare class ImAgentCoordinator {
6
+ private readonly ctx;
7
+ private readonly runtime;
8
+ private readonly tails;
9
+ private readonly timers;
10
+ private readonly handles;
11
+ private readonly toolDisposers;
12
+ private readonly closedScopes;
13
+ private readonly scopeClosures;
14
+ private readonly shutdown;
15
+ private readonly bundleLeases;
16
+ private readonly bundleLeaseDisposers;
17
+ private disposed;
18
+ private disposeCreated;
19
+ private disposeDisposed;
20
+ /** @param ctx - injected Agent, Workspace, preset, tools, Session, and persistence scope. @param runtime - IM authority. */
21
+ constructor(ctx: Context, runtime: ImRuntime);
22
+ /** Recover existing pending conversations and pending Session evidence. */
23
+ start(scopes: readonly ImDeliveryScope[]): void;
24
+ /** Queue one post-commit scope observation without inheriting an Agent initiator. */
25
+ notify(scope: ImDeliveryScope): void;
26
+ /** Close one simulation driver, cancel its Agent, and await only its derived work. */
27
+ stopScope(scope: ImDeliveryScope): Promise<void>;
28
+ /** Stop timers, drain admission drivers, and dispose every Agent this coordinator owns. */
29
+ dispose(): Promise<void>;
30
+ /** Evaluate current durable input and submit one eligible batch. */
31
+ private drive;
32
+ /** Continue one frozen admission after checking its Session log for an earlier append. */
33
+ private submitAdmission;
34
+ /** Pending pause and epoch changes revoke a batch, including during asynchronous policy or Agent setup. */
35
+ private admissionRevoked;
36
+ private discardAdmission;
37
+ /** Simulation admission uses its instance's frozen route, independent of live route edits. */
38
+ private admissionRoute;
39
+ /**
40
+ * Hold a bundled Workspace lease during Agent setup or one turn so template upgrade waits.
41
+ * @param workspaceId - task Workspace.
42
+ */
43
+ private acquireBundleLease;
44
+ /**
45
+ * Keep one bundle lease through this turn; turn/end releases it before the next prompt admission.
46
+ * @param agent - admitted Agent.
47
+ * @param release - disposer from {@link acquireBundleLease}.
48
+ */
49
+ private holdBundleLease;
50
+ /**
51
+ * Release one Agent's bundle lease. Idempotent.
52
+ * @param sessionId - Agent Session.
53
+ */
54
+ private dropBundleLease;
55
+ /** Resolve a route generation without storing it before a trigger admits input. */
56
+ private taskForCurrentBinding;
57
+ /** Persist a newly admitted route generation, or return its existing record. */
58
+ private persistTask;
59
+ /** Read task generations for one complete conversation identity in generation order. */
60
+ private tasksForScope;
61
+ /** Read one configured admission batch while excluding AI echoes. */
62
+ private pending;
63
+ /** Persist AI echoes without creating another Agent input. */
64
+ private discardNonAdmitted;
65
+ /** Reconcile only when the durable Session exists; persistence failures stop this driver. */
66
+ private reconcileTask;
67
+ /** Return every true member of the configured OR trigger. */
68
+ private triggerReasons;
69
+ /** Arm the persisted-message deadline; later messages never slide it. */
70
+ private scheduleInterval;
71
+ /** Store the exact batch and reasons before Agent lifecycle work starts. */
72
+ private freezeAdmission;
73
+ /** Reuse a live Agent or resume/create its frozen Session and scoped preset. */
74
+ private agentFor;
75
+ /** GUI resume uses preset-only setup; attach the frozen conversation tools then. */
76
+ private attachTools;
77
+ /** Build one identified Session message whose source reconstructs the whole batch. */
78
+ private admissionMessage;
79
+ /** Await the exact Session append and its persistence barrier before returning. */
80
+ private submit;
81
+ /** Remove only the pending batch whose identity was submitted. */
82
+ private clearAdmission;
83
+ private clearTimer;
84
+ }
@@ -0,0 +1,18 @@
1
+ /** Model-facing IM takeover labels and the scoped system-prompt section. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import type { ImDeliveryScope, ImInboundMessageView } from './delivery-types.ts';
4
+ import type { ImRuntime } from './runtime.ts';
5
+ /**
6
+ * Render one inbound row for Agent admission or history.
7
+ * @param message - stored inbound with classified sender evidence.
8
+ * @returns one labeled line; counterpart is platform-neutral. The role marker is `[role] body`, never `[role]: body`.
9
+ */
10
+ export declare function formatInbound(message: ImInboundMessageView): string;
11
+ /**
12
+ * Register the takeover standing rules on one Agent context.
13
+ * @param ctx - unpublished Agent context that owns the section.
14
+ * @param runtime - Host runtime that supplies frozen account and destination labels.
15
+ * @param scope - complete admitted conversation identity.
16
+ * @returns disposer for the section.
17
+ */
18
+ export declare function registerImTakeoverPrompt(ctx: Context, runtime: ImRuntime, scope: ImDeliveryScope): () => void;
@@ -0,0 +1,52 @@
1
+ import { type ZodType } from 'zod';
2
+ import type { ImAdmissionId, ImAgentTaskView, ImInboundOperationResult, ImDeliveryScope, ImInboundMessageInput, ImInboundMessageView, ImMessageId, ImOutboundView, ImScopeId, ImProviderCursorCommitResult, ImProviderCursorId, ImProviderCursorOwner, ImTriggerReason } from './delivery-types.ts';
3
+ export declare const imDeliveryScopeSchema: ZodType<ImDeliveryScope>;
4
+ /** Parser for provider and JSONL inbound records. */
5
+ export declare const imInboundMessageInputSchema: ZodType<ImInboundMessageInput>;
6
+ interface StoredDeliveryOperation {
7
+ readonly fingerprint: string;
8
+ readonly result: ImInboundOperationResult;
9
+ }
10
+ /** One durable record per complete conversation scope. */
11
+ export interface ImDeliveryAggregate {
12
+ readonly scope: ImDeliveryScope;
13
+ readonly scopeId: ImScopeId;
14
+ readonly nextMessageSequenceNumber: number;
15
+ readonly nextOutboundSequenceNumber: number;
16
+ readonly cursor: import('./delivery-types.ts').ImConversationCursor;
17
+ readonly presentation?: import('./delivery-types.ts').ImConversationPresentation;
18
+ readonly messages: Readonly<Record<string, ImInboundMessageView>>;
19
+ readonly messageIdsByExternalId: Readonly<Record<string, ImMessageId>>;
20
+ readonly operations: Readonly<Record<string, StoredDeliveryOperation>>;
21
+ readonly outbounds: Readonly<Record<string, ImOutboundView>>;
22
+ }
23
+ export declare const imDeliveryAggregateSchema: ZodType<ImDeliveryAggregate>;
24
+ /** One provider feed cursor plus queryable CAS receipts. */
25
+ export interface ImProviderCursorAggregate {
26
+ readonly id: ImProviderCursorId;
27
+ readonly owner: ImProviderCursorOwner;
28
+ readonly cursor: string | null;
29
+ readonly updatedAt: string;
30
+ readonly operations: Readonly<Record<string, {
31
+ readonly fingerprint: string;
32
+ readonly result: ImProviderCursorCommitResult;
33
+ }>>;
34
+ }
35
+ /** Parser for one provider-owned feed cursor plus its CAS receipts. */
36
+ export declare const imProviderCursorAggregateSchema: ZodType<ImProviderCursorAggregate>;
37
+ /** Batch frozen before Agent creation or steering begins. */
38
+ export interface ImPendingAdmission {
39
+ /** Customer pause generation frozen before asynchronous admission work. */
40
+ readonly handlingEpoch?: number;
41
+ readonly admissionId: ImAdmissionId;
42
+ readonly messageIds: readonly ImMessageId[];
43
+ readonly triggerReasons: readonly ImTriggerReason[];
44
+ readonly createdAt: string;
45
+ }
46
+ /** Durable execution assignment for one conversation scope. */
47
+ export interface ImExecutionAggregate extends ImAgentTaskView {
48
+ readonly pendingAdmission?: ImPendingAdmission;
49
+ }
50
+ /** Parser for one route-bound Agent task generation. */
51
+ export declare const imExecutionAggregateSchema: ZodType<ImExecutionAggregate>;
52
+ export {};
@@ -0,0 +1,187 @@
1
+ import { SessionId } from '@deepseek-ai/dsh-session';
2
+ import { type ImDeliveryAggregate, type ImExecutionAggregate, type ImProviderCursorAggregate } from './delivery-schema.ts';
3
+ import type { ImAgentTaskId, ImCustomerListPage, ImCustomerListRequest, ImCustomerReadAckRequest, ImDeliveryScope, ImHandlingControl, ImOutboundRequestId, ImOutboundView, ImProviderCursorId, ImScopeId, ImSetHandlingControlRequest } from './delivery-types.ts';
4
+ import type { ImAccountId } from './types.ts';
5
+ export declare const IM_DELIVERY_UNIT = "gestaltrun_im_delivery";
6
+ export declare const IM_DELIVERY_UNIT_VERSION = 1;
7
+ /** Monotonic physical layout version stored in `PRAGMA user_version`. */
8
+ export declare const IM_DELIVERY_SCHEMA_VERSION = 2;
9
+ /**
10
+ * Durable delivery records with key lookups and small parsed-document caches.
11
+ * Physical unit tables stay compatible with the sqlite KV layout already on disk.
12
+ */
13
+ export declare class ImDeliverySqlite {
14
+ /** Test-only: throw after this many scopes have been committed during 1→2 backfill. */
15
+ static injectBackfillCrashAfter: number | undefined;
16
+ /** Test-only: override the committed backfill batch size. */
17
+ static backfillBatchSize: number | undefined;
18
+ /** Test-only: fail the next customer-index write so putScope can prove rollback. */
19
+ static failNextCustomerIndexWrite: boolean;
20
+ private readonly db;
21
+ private readonly scopeSelect;
22
+ private readonly scopeUpsert;
23
+ private readonly cursorSelect;
24
+ private readonly cursorUpsert;
25
+ private readonly executionSelect;
26
+ private readonly executionUpsert;
27
+ private readonly scopeCache;
28
+ private readonly executionCache;
29
+ private closed;
30
+ private constructor();
31
+ /**
32
+ * Open or create the delivery database and ensure unit tables plus lookup indexes.
33
+ * @param path - sqlite file path, or `:memory:`.
34
+ * @returns the opened record store.
35
+ */
36
+ static open(path: string): Promise<ImDeliverySqlite>;
37
+ /**
38
+ * Read one conversation aggregate by scope id.
39
+ * @param id - complete conversation identity.
40
+ * @returns the stored aggregate, or absence.
41
+ */
42
+ getScope(id: ImScopeId): ImDeliveryAggregate | undefined;
43
+ /**
44
+ * Persist one conversation aggregate and refresh its lookup indexes.
45
+ * @param id - complete conversation identity.
46
+ * @param value - stored aggregate.
47
+ */
48
+ putScope(id: ImScopeId, value: ImDeliveryAggregate): Promise<void>;
49
+ /**
50
+ * Read one provider cursor by id.
51
+ * @param id - provider feed identity.
52
+ * @returns the stored cursor, or absence.
53
+ */
54
+ getCursor(id: ImProviderCursorId): ImProviderCursorAggregate | undefined;
55
+ /**
56
+ * Persist one provider cursor.
57
+ * @param id - provider feed identity.
58
+ * @param value - stored cursor.
59
+ */
60
+ putCursor(id: ImProviderCursorId, value: ImProviderCursorAggregate): Promise<void>;
61
+ /**
62
+ * Read one Agent task generation by id.
63
+ * @param id - durable task identity.
64
+ * @returns the stored generation, or absence.
65
+ */
66
+ getExecution(id: ImAgentTaskId): ImExecutionAggregate | undefined;
67
+ /**
68
+ * Persist one Agent task generation and refresh its lookup indexes.
69
+ * @param id - durable task identity.
70
+ * @param value - stored generation.
71
+ */
72
+ putExecution(id: ImAgentTaskId, value: ImExecutionAggregate): Promise<void>;
73
+ /**
74
+ * Apply one transform to a stored execution.
75
+ * @param id - durable task identity.
76
+ * @param fn - synchronous transform of the current record.
77
+ * @returns the stored next record.
78
+ */
79
+ updateExecution(id: ImAgentTaskId, fn: (current: ImExecutionAggregate) => ImExecutionAggregate): Promise<ImExecutionAggregate>;
80
+ /**
81
+ * List conversations that currently have pending live inbound.
82
+ * @returns scopes whose pendingCount is greater than zero.
83
+ */
84
+ pendingScopes(): ImDeliveryScope[];
85
+ /**
86
+ * List conversations with an interrupted platform send.
87
+ * @returns scope ids that currently have a dispatching outbound.
88
+ */
89
+ dispatchingScopeIds(): readonly ImScopeId[];
90
+ /**
91
+ * List conversations owned by one configured account.
92
+ * @param accountId - durable IM account.
93
+ * @returns stored scopes for that account.
94
+ */
95
+ scopesForAccount(accountId: ImAccountId): ImDeliveryScope[];
96
+ /**
97
+ * Resolve the newest execution bound to one Agent Session.
98
+ * @param sessionId - IM Agent Session.
99
+ * @returns that Session's newest task, or absence.
100
+ */
101
+ executionForSession(sessionId: SessionId): ImExecutionAggregate | undefined;
102
+ /**
103
+ * Resolve the newest execution for one conversation.
104
+ * @param scopeId - complete conversation identity.
105
+ * @returns the highest-generation task, or absence.
106
+ */
107
+ latestExecutionForScope(scopeId: ImScopeId): ImExecutionAggregate | undefined;
108
+ /**
109
+ * List task generations for one conversation in generation order.
110
+ * @param scopeId - complete conversation identity.
111
+ * @returns stored generations for that scope.
112
+ */
113
+ executionsForScope(scopeId: ImScopeId): ImExecutionAggregate[];
114
+ /**
115
+ * Record a provider actor id that belongs to one configured account.
116
+ * @param accountId - durable IM account.
117
+ * @param actorId - provider actor observed on a native-client or echo frame.
118
+ */
119
+ rememberNativeActor(accountId: ImAccountId, actorId: string): void;
120
+ /**
121
+ * Report whether one provider actor belongs to a configured account.
122
+ * @param accountId - durable IM account.
123
+ * @param actorId - provider actor id.
124
+ * @returns true when that actor was stored for the account.
125
+ */
126
+ isNativeActor(accountId: ImAccountId, actorId: string): boolean;
127
+ /**
128
+ * Locate the conversation that owns one outbound request.
129
+ * @param requestId - outbound identity.
130
+ * @returns that request's scope and stored outbound, or absence.
131
+ */
132
+ outboundOwner(requestId: ImOutboundRequestId): {
133
+ readonly scope: ImDeliveryScope;
134
+ readonly outbound: ImOutboundView;
135
+ } | undefined;
136
+ /**
137
+ * Report whether the delivery unit currently has no records.
138
+ * @returns true when scopes, cursors, and executions are empty.
139
+ */
140
+ empty(): boolean;
141
+ /**
142
+ * Delete every delivery record and lookup index.
143
+ */
144
+ deleteAll(): Promise<void>;
145
+ /** Release the sqlite connection. Idempotent. */
146
+ close(): void;
147
+ private backfillIndexes;
148
+ private backfillNativeActors;
149
+ private markLookupReady;
150
+ private markNativeReady;
151
+ private insertScopeIndexes;
152
+ private clearScopeIndexes;
153
+ private insertNativeActors;
154
+ private insertExecutionIndexes;
155
+ private clearExecutionIndexes;
156
+ private rememberScope;
157
+ private rememberExecution;
158
+ /**
159
+ * List customer rows for one account and source, grouped by customer key.
160
+ * @param request - account, real/simulation filter, optional substring, and reader.
161
+ */
162
+ listCustomers(request: ImCustomerListRequest): ImCustomerListPage;
163
+ /**
164
+ * Advance one reader's inbound watermark with max semantics.
165
+ * @param request - reader, scope, and observed arrival sequence.
166
+ */
167
+ ackCustomerRead(request: ImCustomerReadAckRequest): void;
168
+ /**
169
+ * Persist one scope's automatic-handling pause fact.
170
+ * @param request - scope and pause fields.
171
+ */
172
+ setHandlingControl(request: ImSetHandlingControlRequest): ImHandlingControl;
173
+ /**
174
+ * Read one scope's automatic-handling pause fact.
175
+ * @param scopeId - complete conversation identity.
176
+ */
177
+ getHandlingControl(scopeId: ImScopeId): ImHandlingControl | undefined;
178
+ private requireHandlingControl;
179
+ private customerMatches;
180
+ private likeMatch;
181
+ private customerRow;
182
+ private latestExecutionRow;
183
+ private updateSummaryExecution;
184
+ private changeWatermark;
185
+ private assertIndexReady;
186
+ private assertOpen;
187
+ }