@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,63 @@
1
+ /** Registry of product controllers that authorize IM admission and automated sends. */
2
+ import { Context, Service } from '@deepseek-ai/cordis';
3
+ import type { WorkspaceId } from '@deepseek-ai/dsh-workspace/types';
4
+ import type { ImDeliveryScope } from './delivery-types.ts';
5
+ import type { ImRouteControllerId, ImRouteId } from './types.ts';
6
+ export type { ImRouteControllerId };
7
+ /** Moments a declared route controller must authorize. */
8
+ export type ImPolicyCheckKind = 'admit' | 'send' | 'manual-send' | 'recover' | 'simulation-end';
9
+ /** One authorization request for a declared controller. */
10
+ export interface ImPolicyCheckRequest {
11
+ readonly kind: ImPolicyCheckKind;
12
+ readonly controller: ImRouteControllerId;
13
+ readonly scope: ImDeliveryScope;
14
+ readonly routeId: ImRouteId;
15
+ readonly workspaceId: WorkspaceId;
16
+ }
17
+ /** Allow, or refuse with a stable code. */
18
+ export type ImPolicyDecision = {
19
+ readonly allow: true;
20
+ } | {
21
+ readonly allow: false;
22
+ readonly code: string;
23
+ readonly message: string;
24
+ };
25
+ /** Product Provider that owns one controller identity. */
26
+ export interface ImRoutePolicy {
27
+ check(request: ImPolicyCheckRequest): ImPolicyDecision | Promise<ImPolicyDecision>;
28
+ /** @param listener - 准入条件变化通知。 @returns 撤销本订阅。 */
29
+ subscribe?(listener: () => void): () => void;
30
+ }
31
+ declare module '@deepseek-ai/cordis' {
32
+ interface Events {
33
+ /**
34
+ * 控制器注册或准入状态变化;等待恢复的 Session 可以重新核对。
35
+ * @param controller - 发生变化的托管控制器。
36
+ * @mode emit
37
+ */
38
+ 'imRoutePolicies/changed'(controller: ImRouteControllerId): void;
39
+ }
40
+ interface Context {
41
+ /** IM admission and automated-send policies keyed by route controller. */
42
+ imRoutePolicies: ImRoutePolicies;
43
+ }
44
+ }
45
+ /** Registry whose entries live and die with their registering Cordis fiber. */
46
+ export declare class ImRoutePolicies extends Service {
47
+ private readonly policies;
48
+ /** @param ctx - owning Cordis context. */
49
+ constructor(ctx: Context);
50
+ /**
51
+ * Register the policy for one controller identity.
52
+ * @param controller - product controller recorded on the route.
53
+ * @param policy - authorization Provider.
54
+ * @returns disposer that releases the registration.
55
+ */
56
+ register(controller: ImRouteControllerId, policy: ImRoutePolicy): () => void;
57
+ /**
58
+ * Authorize one admission or send for a declared controller.
59
+ * Missing Providers refuse; ordinary routes without a controller skip this registry.
60
+ * @param request - controller, scope, and check kind.
61
+ */
62
+ authorize(request: ImPolicyCheckRequest): Promise<ImPolicyDecision>;
63
+ }
@@ -0,0 +1,50 @@
1
+ /** Optional pin that keeps one IM preset on a Host-owned model route. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ /** Preset id whose model must be the shop cloud route. Matches the cs-hosting preset. */
4
+ export declare const SHOP_CLOUD_PRESET_ID = "cs-hosting";
5
+ /** A pinned preset's model, or why the call must wait. No key and no message body. */
6
+ export type ImPresetModelDecision = {
7
+ readonly kind: 'ready';
8
+ readonly provider: string;
9
+ readonly model: string;
10
+ readonly models: readonly string[];
11
+ } | {
12
+ readonly kind: 'blocked';
13
+ readonly code: string;
14
+ };
15
+ /**
16
+ * Host gate for presets that must not use the member's own model.
17
+ * `warm` resolves the route before IM submits a batch. A blocked decision leaves that batch pending.
18
+ */
19
+ export interface ImPresetModelGate {
20
+ /** @param presetId - agent preset about to run. */
21
+ pins(presetId: string): boolean;
22
+ /** @param signal - cancels the admission read. */
23
+ warm(signal?: AbortSignal): Promise<ImPresetModelDecision>;
24
+ /** @param listener - runs when the admission changes. @returns its disposer. */
25
+ subscribe(listener: () => void): () => void;
26
+ }
27
+ declare module '@deepseek-ai/cordis' {
28
+ interface Context {
29
+ /** Present when a product preset pins its model. Absent presets keep the member default. */
30
+ imPresetModelGate?: ImPresetModelGate;
31
+ }
32
+ }
33
+ /** Model options for one new or resumed IM agent. */
34
+ export type PresetAgentSelection = {
35
+ readonly kind: 'default';
36
+ } | {
37
+ readonly kind: 'pinned';
38
+ readonly provider: string;
39
+ readonly model: string;
40
+ } | {
41
+ readonly kind: 'hold';
42
+ };
43
+ /**
44
+ * Resolve agent options for a preset.
45
+ * The shop-cloud preset fails when the gate is missing, and holds when the gate is blocked.
46
+ * @param ctx - Host context.
47
+ * @param presetId - recorded route preset.
48
+ * @param signal - cancels a pinned read.
49
+ */
50
+ export declare function resolvePresetAgentOptions(ctx: Context, presetId: string, signal?: AbortSignal): Promise<PresetAgentSelection>;
@@ -0,0 +1,27 @@
1
+ /** Durable buyer-read facts become context at the next accepted model step. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import { type UserMessage } from '@deepseek-ai/dsh-llm';
4
+ import type { Session } from '@deepseek-ai/dsh-session';
5
+ import type { KvTable } from '@deepseek-ai/dsh-storage-domain';
6
+ import type { ImRealDeliveryScope, ImScopeId, ImOutboundRequestId } from './delivery-types.ts';
7
+ import type { ImReadAssociation, ImReadRecord } from './read-records.ts';
8
+ declare module '@deepseek-ai/dsh-llm' {
9
+ interface MessageSourceMap {
10
+ /** Receipt attribution preserves its JSON metadata for readers without this projection.
11
+ * @persistenceAttribution
12
+ */
13
+ 'im-read': {
14
+ readonly kind: 'im-read';
15
+ readonly scopeId: ImScopeId;
16
+ readonly requestId: ImOutboundRequestId;
17
+ readonly form: 'notice';
18
+ readonly summary: string;
19
+ };
20
+ }
21
+ }
22
+ /** @param ctx - optional live Agent and persistence services. @param scope - verified outbound scope. @param row - confirmed buyer evidence. @returns after a live Session fact is durable; absent Agents receive it at their next pre-step. */
23
+ export declare function recordLiveRead(ctx: Context, scope: ImRealDeliveryScope, row: ImReadAssociation): Promise<void>;
24
+ /** @param session - recorded facts and previously admitted contexts. @param proposed - contexts already proposed for this step. @returns each previously unannounced read once; source facts reconstruct the notification after a restart. */
25
+ export declare function readContextMessages(session: Session, proposed?: readonly UserMessage[]): readonly UserMessage[];
26
+ /** @param ctx - registration owner. @param table - independent durable read evidence. @returns exact child disposer, joined before the table closes. Context reconstruction does not wake idle Agents. */
27
+ export declare function installReadContext(ctx: Context, table: KvTable<ImScopeId, ImReadRecord>): () => Promise<void>;
@@ -0,0 +1,10 @@
1
+ /** Single-chat read synchronization after durable, exact-identity correlation. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ /** Bounded admission for SDK messages waiting for their OpenAPI durable counterparts. */
4
+ export interface Config {
5
+ readonly pendingMessageLimit?: number;
6
+ }
7
+ /** Host services required before opening independent read storage. */
8
+ export declare const inject: string[];
9
+ /** @param ctx - durable runtime and storage owner. @param config - bounded unmatched-message admission. @returns after the read domain and optional SDK consumers are installed. */
10
+ export declare function apply(ctx: Context, config?: Config): Promise<void>;
@@ -0,0 +1,30 @@
1
+ import { SessionId } from '@deepseek-ai/dsh-session';
2
+ import type { ImOutboundRequestId, ImRealDeliveryScope, ImScopeId } from './delivery-types.ts';
3
+ import type { ImBuyerReadState } from './read-state.ts';
4
+ /** Exact platform association and monotonically confirmed buyer state. */
5
+ export interface ImReadAssociation {
6
+ readonly requestId: ImOutboundRequestId;
7
+ readonly platformMessageId: string;
8
+ readonly sdkConversationId: string;
9
+ readonly buyerUid: string;
10
+ readonly singleton: boolean;
11
+ readonly queried: boolean;
12
+ readonly state: ImBuyerReadState;
13
+ readonly observedAt: string;
14
+ readonly sessionId?: SessionId;
15
+ }
16
+ /** One independently versioned conversation read record. */
17
+ export interface ImReadRecord {
18
+ readonly schema: 'gestaltrun.im-reads.v1';
19
+ readonly scope: ImRealDeliveryScope;
20
+ readonly reported: Readonly<Record<string, true>>;
21
+ readonly outbounds: Readonly<Record<string, ImReadAssociation>>;
22
+ }
23
+ /** Product-owned read records; opening older IM configuration requires no migration. */
24
+ export declare const imReadsDomainSpec: {
25
+ name: string;
26
+ version: number;
27
+ tables: {
28
+ scopes: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<ImScopeId, ImReadRecord>;
29
+ };
30
+ };
@@ -0,0 +1,18 @@
1
+ import type { ImDirectRecipient } from './types.ts';
2
+ /** Consumer-read evidence; absence or ambiguity remains unknown. */
3
+ export type ImBuyerReadState = 'unknown' | 'unread' | 'read';
4
+ /** @param buyer - verified direct recipient. @returns its SDK user id when present, otherwise the platform actor id. */
5
+ export declare function buyerUid(buyer: ImDirectRecipient): string;
6
+ /** @param sender - SDK sender string or object; absent receipt senders remain absent. @returns the supplied sender UID, or absence. */
7
+ export declare function senderUid(sender: string | {
8
+ readonly uid: string;
9
+ } | undefined): string | undefined;
10
+ /** @param uid - SDK identity. @param buyer - verified OpenAPI buyer UID. @returns whether domain-qualified or unqualified SDK identity names this buyer. */
11
+ export declare function sameBuyer(uid: string, buyer: string): boolean;
12
+ /** @param data - raw 40103 counts. @param singleton - independently verified receiver set consists solely of the target buyer. @returns conservative buyer state. */
13
+ export declare function buyerReadState(data: Readonly<Record<string, unknown>>, singleton: boolean): ImBuyerReadState;
14
+ /** @param data - ListMessageReadStatus response body. @param buyer - independently verified buyer UID. @returns matched status and whether the response establishes a singleton receiver set. */
15
+ export declare function buyerReadQuery(data: unknown, buyer: string): {
16
+ readonly state: ImBuyerReadState;
17
+ readonly singleton: boolean;
18
+ };
@@ -0,0 +1,28 @@
1
+ /** Safe read-receipt projections and Host-only SDK correlation facts. */
2
+ import type { ImDeliveryScope, ImInboundMessageView, ImOutboundRequestId, ImOutboundView, ImRealDeliveryScope } from './delivery-types.ts';
3
+ import type { ImDirectRecipient } from './types.ts';
4
+ import type { ImBuyerReadState } from './read-state.ts';
5
+ /** Buyer status associated with one durable DSH outbound request. */
6
+ export interface ImReadReceipt {
7
+ readonly requestId: ImOutboundRequestId;
8
+ readonly state: ImBuyerReadState;
9
+ }
10
+ /** One exact identifier match in durable OpenAPI history; content equality is never evidence. */
11
+ export interface ImSdkMessageMatch {
12
+ readonly scope: ImRealDeliveryScope;
13
+ readonly buyer: ImDirectRecipient;
14
+ readonly inbound?: ImInboundMessageView;
15
+ readonly outbound?: ImOutboundView;
16
+ }
17
+ /** Safe read status provider, separate from transport send outcomes. */
18
+ export interface ImReads {
19
+ /** @param scope - complete conversation. @returns durable buyer status; unknown is omitted. */
20
+ snapshot(scope: ImDeliveryScope): readonly ImReadReceipt[];
21
+ /** @param listener - committed scope change. @returns disposer. */
22
+ subscribe(listener: (scope: ImRealDeliveryScope) => void): () => void;
23
+ }
24
+ declare module '@deepseek-ai/cordis' {
25
+ interface Context {
26
+ imReads: ImReads;
27
+ }
28
+ }
@@ -0,0 +1,38 @@
1
+ import type { SessionId } from '@deepseek-ai/dsh-session';
2
+ import type { UserMessage } from '@deepseek-ai/dsh-llm';
3
+ import type { SessionEvent, SessionSeq, SessionLogOffset } from '@deepseek-ai/dsh-session';
4
+ /** 一轮中断及已经登记的同一条跟进输入。 */
5
+ export interface RestartRecovery {
6
+ readonly turnStartSeq: SessionSeq;
7
+ readonly message?: UserMessage;
8
+ readonly consumed: boolean;
9
+ }
10
+ /**
11
+ * 仅从持久日志或 live Session 的初始 seed 识别中断,再用完整日志核对跟进收据。
12
+ * @param events - 路由登记 Session 的实际日志。
13
+ * @param firstLiveSeq - live Session 的公开 seed 结束位置;冷读省略,使用完整持久日志。
14
+ * @returns 未完成的重启恢复证据;无中断时为空。
15
+ */
16
+ export declare function restartRecovery(events: readonly SessionEvent[], firstLiveSeq?: SessionLogOffset): RestartRecovery | undefined;
17
+ /** 单个路由 Session 的公开读接口;读取期间可能由其他消费者恢复。 */
18
+ export interface RestartSessionSource {
19
+ /** @returns 当前已发布 Agent 的公开 seed 偏移;不存在时为空。 */
20
+ live(): {
21
+ readonly firstLiveSeq: SessionLogOffset;
22
+ } | undefined;
23
+ /** @param signal - Host 生命周期。 @returns 当前 live Session 的已提交事件已刷写;无 live Session 时不写入。 */
24
+ flush(signal: AbortSignal): Promise<void>;
25
+ /** @param signal - Host 生命周期。 @returns Session 是否已创建。 */
26
+ exists(signal: AbortSignal): Promise<boolean>;
27
+ /** @param signal - Host 生命周期。 @returns 调用者负责关闭的只读句柄。 */
28
+ open(signal: AbortSignal): Promise<Pick<import('@deepseek-ai/dsh-session-persistence').SessionHandle, 'read' | 'close'>>;
29
+ }
30
+ /**
31
+ * 读取单个登记 Session;未创建的 Session 留给普通准入恢复,冷读后重新观察 live 所有者。
32
+ * @param source - Session 的 live 与持久化读接口。
33
+ * @param signal - 取消读取并释放句柄;取消错误交给 Host 生命周期处理。
34
+ * @returns 中断与跟进日志证据,或无需恢复。
35
+ */
36
+ export declare function discoverRestartRecovery(source: RestartSessionSource, signal: AbortSignal): Promise<RestartRecovery | undefined>;
37
+ /** @param error - 公开恢复接口的原始错误。 @param sessionId - 本次恢复 Session。 @returns 同一个 Session 的写入所有权占用可以等待,其他失败必须报告。 */
38
+ export declare function restartFailureDisposition(error: unknown, sessionId: SessionId): 'ownership-wait' | 'failed';
@@ -0,0 +1,10 @@
1
+ /** Explicit Agent-preset resolution for an IM route. */
2
+ import type { ImRouteView } from './types.ts';
3
+ /**
4
+ * Resolve the Agent preset a route uses.
5
+ * A recorded preset is used as-is. Absence takes the runtime default.
6
+ * Callers must fail when a recorded preset cannot mount; they must not fall back.
7
+ * @param route - stored route fields.
8
+ * @param defaultId - AgentPresets default when the route omitted a preset.
9
+ */
10
+ export declare function resolveRouteAgentPreset(route: Pick<ImRouteView, 'agentPreset'>, defaultId: string): string;