@bizagent/dsh 0.0.0-stage → 1.0.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.
Files changed (181) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -2
  4. package/cordis.patch.yml +14 -0
  5. package/docs/README.md +23 -0
  6. package/docs/architecture.md +154 -0
  7. package/docs/concepts.md +192 -0
  8. package/docs/configuration.md +154 -0
  9. package/docs/quickstart.md +103 -0
  10. package/docs/quickstart.zh-CN.md +86 -0
  11. package/docs/tools.md +607 -0
  12. package/docs/user-guide.zh-CN.md +132 -0
  13. package/docs/verification.md +69 -0
  14. package/examples/README.md +64 -0
  15. package/examples/demo-runtime.mjs +71 -0
  16. package/examples/learning-lab.mjs +263 -0
  17. package/examples/scenarios.mjs +45 -0
  18. package/lib/agent-preset.d.ts +20 -0
  19. package/lib/agent-preset.js +46 -0
  20. package/lib/agent-session-address.d.ts +14 -0
  21. package/lib/agent-session-address.js +15 -0
  22. package/lib/agent-session-coordinator.d.ts +24 -0
  23. package/lib/agent-session-coordinator.js +101 -0
  24. package/lib/cli.d.ts +3 -0
  25. package/lib/cli.js +142 -0
  26. package/lib/client-types/agent-session-address.d.ts +13 -0
  27. package/lib/client-types/client/agent-mentions.d.ts +3 -0
  28. package/lib/client-types/client/api.d.ts +180 -0
  29. package/lib/client-types/client/components.d.ts +22 -0
  30. package/lib/client-types/client/controller.d.ts +23 -0
  31. package/lib/client-types/client/frame-participants.d.ts +5 -0
  32. package/lib/client-types/client/home-name.d.ts +9 -0
  33. package/lib/client-types/client/human-inbox.d.ts +8 -0
  34. package/lib/client-types/client/index.d.ts +13 -0
  35. package/lib/client-types/client/locales.d.ts +796 -0
  36. package/lib/client-types/client/markdown.d.ts +12 -0
  37. package/lib/client-types/client/project-artifact-link.d.ts +10 -0
  38. package/lib/client-types/client/project-outcome-review-inbox.d.ts +13 -0
  39. package/lib/client-types/client/projects.d.ts +11 -0
  40. package/lib/client-types/client/sample-guide.d.ts +9 -0
  41. package/lib/client-types/client/session-resource.d.ts +34 -0
  42. package/lib/client-types/client/session-surfaces.d.ts +24 -0
  43. package/lib/client-types/client/styles.d.ts +1 -0
  44. package/lib/client-types/config.d.ts +55 -0
  45. package/lib/client-types/cron.d.ts +8 -0
  46. package/lib/client-types/domain.d.ts +818 -0
  47. package/lib/client-types/frame-reference.d.ts +4 -0
  48. package/lib/client-types/home-directory.d.ts +5 -0
  49. package/lib/client-types/home-space.d.ts +49 -0
  50. package/lib/client-types/home-store.d.ts +125 -0
  51. package/lib/client-types/inbox-stalled-topic.d.ts +15 -0
  52. package/lib/client-types/inbox-wake-policy.d.ts +18 -0
  53. package/lib/client-types/known-format.d.ts +2 -0
  54. package/lib/client-types/learning-scheduler.d.ts +36 -0
  55. package/lib/client-types/learning-session-runner.d.ts +49 -0
  56. package/lib/client-types/learning-trigger.d.ts +17 -0
  57. package/lib/client-types/learning-usage.d.ts +17 -0
  58. package/lib/client-types/ledger.d.ts +190 -0
  59. package/lib/client-types/local-owner.d.ts +7 -0
  60. package/lib/client-types/message-source.d.ts +9 -0
  61. package/lib/client-types/organization-location.d.ts +19 -0
  62. package/lib/client-types/project-ledger.d.ts +182 -0
  63. package/lib/client-types/project-seat-context.d.ts +17 -0
  64. package/lib/client-types/safe-file.d.ts +23 -0
  65. package/lib/client-types/sample-organization.d.ts +9 -0
  66. package/lib/client-types/service.d.ts +596 -0
  67. package/lib/client-types/shared-knowledge.d.ts +116 -0
  68. package/lib/client-types/ui-contract.d.ts +276 -0
  69. package/lib/client-types/untrusted-text.d.ts +15 -0
  70. package/lib/client-types/work-ledger.d.ts +108 -0
  71. package/lib/client-types/work-output-eval.d.ts +15 -0
  72. package/lib/client-types/worklog-ledger.d.ts +88 -0
  73. package/lib/client-types/worklog-snapshot.d.ts +33 -0
  74. package/lib/client.js +5463 -0
  75. package/lib/config.d.ts +56 -0
  76. package/lib/config.js +115 -0
  77. package/lib/cron.d.ts +9 -0
  78. package/lib/cron.js +127 -0
  79. package/lib/domain.d.ts +819 -0
  80. package/lib/domain.js +662 -0
  81. package/lib/frame-admission.d.ts +6 -0
  82. package/lib/frame-admission.js +39 -0
  83. package/lib/frame-reference.d.ts +5 -0
  84. package/lib/frame-reference.js +12 -0
  85. package/lib/home-archive.d.ts +17 -0
  86. package/lib/home-archive.js +177 -0
  87. package/lib/home-directory.d.ts +6 -0
  88. package/lib/home-directory.js +38 -0
  89. package/lib/home-space.d.ts +50 -0
  90. package/lib/home-space.js +120 -0
  91. package/lib/home-store.d.ts +126 -0
  92. package/lib/home-store.js +837 -0
  93. package/lib/host.d.ts +22 -0
  94. package/lib/host.js +15 -0
  95. package/lib/human-inbox-transport.d.ts +23 -0
  96. package/lib/human-inbox-transport.js +105 -0
  97. package/lib/human-notification-runner.d.ts +83 -0
  98. package/lib/human-notification-runner.js +138 -0
  99. package/lib/human-notification-webhook.d.ts +18 -0
  100. package/lib/human-notification-webhook.js +102 -0
  101. package/lib/human-turn-completion.d.ts +61 -0
  102. package/lib/human-turn-completion.js +157 -0
  103. package/lib/inbox-return-notifier.d.ts +46 -0
  104. package/lib/inbox-return-notifier.js +279 -0
  105. package/lib/inbox-stalled-escalation-runner.d.ts +31 -0
  106. package/lib/inbox-stalled-escalation-runner.js +68 -0
  107. package/lib/inbox-stalled-topic.d.ts +16 -0
  108. package/lib/inbox-stalled-topic.js +44 -0
  109. package/lib/inbox-wake-policy.d.ts +19 -0
  110. package/lib/inbox-wake-policy.js +28 -0
  111. package/lib/inbox-wake-runner.d.ts +45 -0
  112. package/lib/inbox-wake-runner.js +481 -0
  113. package/lib/index.d.ts +29 -0
  114. package/lib/index.js +480 -0
  115. package/lib/known-format.d.ts +3 -0
  116. package/lib/known-format.js +8 -0
  117. package/lib/learning-scheduler.d.ts +37 -0
  118. package/lib/learning-scheduler.js +182 -0
  119. package/lib/learning-session-runner.d.ts +50 -0
  120. package/lib/learning-session-runner.js +435 -0
  121. package/lib/learning-trigger.d.ts +18 -0
  122. package/lib/learning-trigger.js +92 -0
  123. package/lib/learning-usage.d.ts +18 -0
  124. package/lib/learning-usage.js +49 -0
  125. package/lib/ledger.d.ts +191 -0
  126. package/lib/ledger.js +752 -0
  127. package/lib/local-human-host.d.ts +11 -0
  128. package/lib/local-human-host.js +191 -0
  129. package/lib/local-human-token.d.ts +9 -0
  130. package/lib/local-human-token.js +32 -0
  131. package/lib/local-owner.d.ts +8 -0
  132. package/lib/local-owner.js +26 -0
  133. package/lib/message-source.d.ts +10 -0
  134. package/lib/message-source.js +2 -0
  135. package/lib/organization-location.d.ts +20 -0
  136. package/lib/organization-location.js +80 -0
  137. package/lib/organization-workspace.d.ts +22 -0
  138. package/lib/organization-workspace.js +32 -0
  139. package/lib/project-ledger.d.ts +183 -0
  140. package/lib/project-ledger.js +189 -0
  141. package/lib/project-review-transport.d.ts +23 -0
  142. package/lib/project-review-transport.js +155 -0
  143. package/lib/project-seat-context.d.ts +18 -0
  144. package/lib/project-seat-context.js +34 -0
  145. package/lib/proposal-review-transport.d.ts +26 -0
  146. package/lib/proposal-review-transport.js +104 -0
  147. package/lib/route-guard.d.ts +31 -0
  148. package/lib/route-guard.js +80 -0
  149. package/lib/safe-file.d.ts +24 -0
  150. package/lib/safe-file.js +93 -0
  151. package/lib/sample-organization.d.ts +10 -0
  152. package/lib/sample-organization.js +46 -0
  153. package/lib/service.d.ts +597 -0
  154. package/lib/service.js +4076 -0
  155. package/lib/session-surface.d.ts +11 -0
  156. package/lib/session-surface.js +109 -0
  157. package/lib/shared-knowledge-review-transport.d.ts +28 -0
  158. package/lib/shared-knowledge-review-transport.js +85 -0
  159. package/lib/shared-knowledge.d.ts +117 -0
  160. package/lib/shared-knowledge.js +240 -0
  161. package/lib/tools.d.ts +7 -0
  162. package/lib/tools.js +955 -0
  163. package/lib/ui-contract.d.ts +277 -0
  164. package/lib/ui-contract.js +12 -0
  165. package/lib/ui-host.d.ts +24 -0
  166. package/lib/ui-host.js +471 -0
  167. package/lib/untrusted-text.d.ts +16 -0
  168. package/lib/untrusted-text.js +50 -0
  169. package/lib/work-ledger.d.ts +109 -0
  170. package/lib/work-ledger.js +107 -0
  171. package/lib/work-output-eval.d.ts +16 -0
  172. package/lib/work-output-eval.js +58 -0
  173. package/lib/work-runner.d.ts +47 -0
  174. package/lib/work-runner.js +352 -0
  175. package/lib/worklog-ledger.d.ts +89 -0
  176. package/lib/worklog-ledger.js +91 -0
  177. package/lib/worklog-snapshot.d.ts +34 -0
  178. package/lib/worklog-snapshot.js +100 -0
  179. package/lib/writer-guard.d.ts +11 -0
  180. package/lib/writer-guard.js +207 -0
  181. package/package.json +172 -4
@@ -0,0 +1,4 @@
1
+ /** A selected composer reference; only user-authored, admitted messages are resolved. */
2
+ export declare function frameReference(address: string): string;
3
+ export declare function selectedFrameAddresses(text: string): string[];
4
+ export declare function removeFrameReferences(text: string): string;
@@ -0,0 +1,5 @@
1
+ import { type AgentHome, type HomeAddress } from './domain.js';
2
+ export type HomeDirectoryEntry = Pick<AgentHome, 'address' | 'type' | 'displayName'>;
3
+ export declare function visibleHomeDirectory(homes: readonly AgentHome[], primaryHome: HomeAddress): HomeDirectoryEntry[];
4
+ export declare function searchHomeDirectory(homes: readonly AgentHome[], primaryHome: HomeAddress, query?: string, limit?: number): HomeDirectoryEntry[];
5
+ export declare function resolveHomeDirectoryTarget(homes: readonly AgentHome[], primaryHome: HomeAddress, target: string): HomeAddress;
@@ -0,0 +1,49 @@
1
+ import { type AgentHome, type AssetStatus, type ContextBudget, type Organization, type StoredAsset } from './domain.js';
2
+ import type { InboxWakePolicy } from './inbox-wake-policy.js';
3
+ import type { AssetSearchInput, CreateAssetInput, CreateHomeInput, DoctorReport, HomeStore, UpdateAssetInput } from './home-store.js';
4
+ /**
5
+ * Every Home this host can see: the person's own Homes in the data root (the personal space), and
6
+ * the active organization's Homes under `<data root>/orgs/<id>`. Each Home stays in the folder of
7
+ * the store that holds it. When both hold the same address, the organization's Home wins and the
8
+ * personal one is reported by `doctor`.
9
+ */
10
+ export declare class HomeSpace {
11
+ readonly personal: HomeStore;
12
+ readonly organizationStore?: HomeStore | undefined;
13
+ constructor(personal: HomeStore, organizationStore?: HomeStore | undefined);
14
+ /** Where organization-wide records live: the organization root, or the personal space without one. */
15
+ get root(): string;
16
+ get personalRoot(): string;
17
+ get organizationRoot(): string | undefined;
18
+ initialize(): Promise<void>;
19
+ reload(): Promise<void>;
20
+ /** The same personal space with another organization (or none) beside it. */
21
+ withOrganization(organizationStore: HomeStore | undefined): HomeSpace;
22
+ /** The root of the store that holds this Home; its snapshots and records belong there. */
23
+ rootFor(address: string): string;
24
+ /** A Home from the personal space, outside any organization. */
25
+ isPersonalHome(address: string): boolean;
26
+ listHomes(): AgentHome[];
27
+ hasHome(address: string): boolean;
28
+ getHome(address: string): AgentHome;
29
+ findHome(address: string): AgentHome | undefined;
30
+ homeWorkspacePath(address: string): string;
31
+ readInboxWakePolicy(address: string): Promise<InboxWakePolicy>;
32
+ getIdentity(address: string): string;
33
+ /** The active organization; before organizations had their own folder it could sit in the data root itself. */
34
+ getOrganization(): Organization | undefined;
35
+ /** New Homes join the active organization unless the personal space is asked for. */
36
+ createHome(input: CreateHomeInput, target?: 'organization' | 'personal'): Promise<AgentHome>;
37
+ listAssets(address: string, status?: AssetStatus): StoredAsset[];
38
+ searchAssets(address: string, input?: AssetSearchInput): StoredAsset[];
39
+ readAsset(address: string, id: string): StoredAsset;
40
+ findAssetByProposalId(address: string, proposalId: string): StoredAsset | undefined;
41
+ createAsset(input: CreateAssetInput): Promise<StoredAsset>;
42
+ updateAsset(address: string, id: string, input: UpdateAssetInput): Promise<StoredAsset>;
43
+ contextFor(address: string, budget: ContextBudget, episodeCount?: number): string;
44
+ contextForFrame(address: string, budget: ContextBudget): string;
45
+ doctor(): Promise<DoctorReport>;
46
+ private findStore;
47
+ /** Throws the store's own unknown-Home error when no store holds the address. */
48
+ private storeFor;
49
+ }
@@ -0,0 +1,125 @@
1
+ import { type AgentHome, type AssetKind, type AssetStatus, type ContextBudget, type EvidenceRef, type HomeAddress, type Organization, type StoredAsset } from './domain.js';
2
+ import { type InboxWakePolicy } from './inbox-wake-policy.js';
3
+ export interface CreateHomeInput {
4
+ address: string;
5
+ displayName?: string;
6
+ owner?: string;
7
+ identity?: string;
8
+ }
9
+ export interface CreateOrganizationInput {
10
+ id: string;
11
+ name: string;
12
+ mission: string;
13
+ /** Person who owns every Home in the organization. Defaults to each member id (members as people). */
14
+ owner?: string;
15
+ members: Array<{
16
+ id: string;
17
+ displayName: string;
18
+ roleId: string;
19
+ roleName: string;
20
+ responsibility: string;
21
+ }>;
22
+ capabilities: Array<{
23
+ id: string;
24
+ displayName: string;
25
+ responsibility: string;
26
+ }>;
27
+ }
28
+ export interface CreateAssetInput {
29
+ id: string;
30
+ ownerAddress: HomeAddress;
31
+ kind: Exclude<AssetKind, 'identity'>;
32
+ title?: string;
33
+ description: string;
34
+ body: string;
35
+ tags?: string[];
36
+ sourceRefs: EvidenceRef[];
37
+ confidence?: number;
38
+ fitness?: number;
39
+ status?: AssetStatus;
40
+ proposalId?: string;
41
+ }
42
+ export interface UpdateAssetInput {
43
+ /** Checked inside the serialized mutation, before reading or writing a new revision. */
44
+ expectedRevision?: number;
45
+ description?: string;
46
+ body?: string;
47
+ tags?: string[];
48
+ sourceRefs?: EvidenceRef[];
49
+ status?: AssetStatus;
50
+ confidence?: number;
51
+ fitness?: number;
52
+ /** Internal recovery marker, persisted in the same file revision as a proposal replacement. */
53
+ appliedProposalId?: string;
54
+ }
55
+ export interface AssetSearchInput {
56
+ query?: string;
57
+ kind?: AssetKind;
58
+ status?: AssetStatus;
59
+ limit?: number;
60
+ }
61
+ export interface DoctorReport {
62
+ ok: boolean;
63
+ root: string;
64
+ homeCount: number;
65
+ assetCount: number;
66
+ issues: string[];
67
+ }
68
+ export declare class HomeStore {
69
+ readonly root: string;
70
+ readonly homesRoot: string;
71
+ readonly organizationFile: string;
72
+ private readonly homes;
73
+ private organization;
74
+ private organizationLoadError;
75
+ private integrityIssues;
76
+ private mutationTail;
77
+ constructor(root: string);
78
+ initialize(): Promise<void>;
79
+ reload(): Promise<void>;
80
+ listHomes(): AgentHome[];
81
+ hasHome(address: string): boolean;
82
+ getHome(address: string): AgentHome;
83
+ /** Any loaded Home, including an archived one, or undefined; never throws for an unknown address. */
84
+ findHome(address: string): AgentHome | undefined;
85
+ /** The Home's fixed DSH Workspace, shared by Principal, Project Main and Seats. */
86
+ homeWorkspacePath(address: string): string;
87
+ /** Home-local receipt policy. Missing or malformed files use the 15-minute batch default. */
88
+ readInboxWakePolicy(address: string): Promise<InboxWakePolicy>;
89
+ getIdentity(address: string): string;
90
+ getOrganization(): Organization | undefined;
91
+ createHome(input: CreateHomeInput): Promise<AgentHome>;
92
+ createOrganization(input: CreateOrganizationInput): Promise<Organization>;
93
+ listAssets(address: string, status?: AssetStatus): StoredAsset[];
94
+ searchAssets(address: string, input?: AssetSearchInput): StoredAsset[];
95
+ readAsset(address: string, id: string): StoredAsset;
96
+ findAssetByProposalId(address: string, proposalId: string): StoredAsset | undefined;
97
+ createAsset(input: CreateAssetInput): Promise<StoredAsset>;
98
+ updateAsset(address: string, id: string, input: UpdateAssetInput): Promise<StoredAsset>;
99
+ contextFor(address: string, budget: ContextBudget, episodeCount?: number): string;
100
+ contextForFrame(address: string, budget: ContextBudget): string;
101
+ private renderContext;
102
+ private relativePath;
103
+ /** Error text for issues, with absolute paths under the root shown relative to it. */
104
+ private relativeMessage;
105
+ doctor(): Promise<DoctorReport>;
106
+ /**
107
+ * Owners recorded in directory.yaml when this store last wrote it. The file sits at the store
108
+ * root, outside each Home's own Workspace directory, so an Agent working in its Home cannot
109
+ * change its owner by editing home.yaml alone.
110
+ */
111
+ private readRecordedOwners;
112
+ /** Refuse an owner change made in agent-writable home.yaml; keep the recorded owner and report it. */
113
+ private keepRecordedOwner;
114
+ private loadHome;
115
+ private loadOrganization;
116
+ private loadOrganizationFile;
117
+ private createHomeUnlocked;
118
+ private refreshHome;
119
+ private assetPath;
120
+ private requireHome;
121
+ private assertWithinRoot;
122
+ private writeDirectory;
123
+ private mutate;
124
+ }
125
+ export declare function pathExists(path: string): Promise<boolean>;
@@ -0,0 +1,15 @@
1
+ import { type HomeAddress, type ProjectSeatAddress, type InboxMessage } from './domain.js';
2
+ export declare const INBOX_STALE_ESCALATE_MS: number;
3
+ export interface StalledInboxTopic {
4
+ topicId: string;
5
+ ordinaryCount: number;
6
+ maxHop: number;
7
+ lastSentAt: string;
8
+ subject: string;
9
+ sourceMessageId: string;
10
+ returnAddress: HomeAddress | ProjectSeatAddress;
11
+ returnToSessionId?: string;
12
+ projectId?: string;
13
+ }
14
+ /** Scan immutable letters; Work notifications and closed topics do not consume the ordinary relay budget. */
15
+ export declare function stalledInboxTopics(messages: readonly InboxMessage[], now: number): StalledInboxTopic[];
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ export declare const InboxWakePolicySchema: z.ZodObject<{
3
+ policy: z.ZodEnum<{
4
+ immediate: "immediate";
5
+ batch: "batch";
6
+ scheduled: "scheduled";
7
+ carried: "carried";
8
+ }>;
9
+ batchMinutes: z.ZodOptional<z.ZodNumber>;
10
+ cron: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strip>;
12
+ export type InboxWakePolicy = z.infer<typeof InboxWakePolicySchema>;
13
+ export declare const DEFAULT_INBOX_WAKE_POLICY: InboxWakePolicy;
14
+ /** Freeze the effective recipient schedule at delivery time. */
15
+ export declare function inboxWakeSchedule(policy: InboxWakePolicy, priority: 'normal' | 'urgent', sentAt: string, timeZone?: string): {
16
+ wakePolicy: InboxWakePolicy['policy'];
17
+ wakeAt?: string;
18
+ };
@@ -0,0 +1,2 @@
1
+ /** Refuse files written by a newer BizAgent with a message that says so, instead of a schema error. */
2
+ export declare function assertKnownFormat(raw: unknown, latest: number, file: string): void;
@@ -0,0 +1,36 @@
1
+ import type { ResolvedConfig, ResolvedLearningSchedule } from './config.js';
2
+ import { type HomeAddress, type LearningLaunch, type LearningScheduleCursor, type LearningSchedulePolicy } from './domain.js';
3
+ import type { LearningSessionRunner } from './learning-session-runner.js';
4
+ import type { BizAgentService } from './service.js';
5
+ export interface LearningScheduleStatus {
6
+ homeAddress: HomeAddress;
7
+ hostEnabled: boolean;
8
+ configured: boolean;
9
+ timeZone: string;
10
+ maxDailyRuns?: number;
11
+ schedule?: ResolvedLearningSchedule;
12
+ policy?: LearningSchedulePolicy;
13
+ cursor?: LearningScheduleCursor;
14
+ nextDueAt?: number;
15
+ runsToday: number;
16
+ recentLaunches: LearningLaunch[];
17
+ }
18
+ /** Single-host, opt-in learning clock. Each due period is consumed at most once by its durable cursor. */
19
+ export declare class LearningScheduler {
20
+ private readonly service;
21
+ private readonly runner;
22
+ private readonly config;
23
+ private readonly clock;
24
+ private pass;
25
+ constructor(service: BizAgentService, runner: LearningSessionRunner, config: ResolvedConfig, clock?: () => number);
26
+ status(homeInput: string): LearningScheduleStatus;
27
+ configure(homeInput: string, input: {
28
+ expectedRevision: number;
29
+ enabled: boolean;
30
+ cron: string;
31
+ dailyRuns: number;
32
+ }): Promise<LearningScheduleStatus>;
33
+ runDue(): Promise<LearningScheduleCursor[]>;
34
+ private tick;
35
+ private runsToday;
36
+ }
@@ -0,0 +1,49 @@
1
+ import type { Agent, AgentRegistry } from '@deepseek-ai/dsh-agent';
2
+ import type { SessionQueryEngine } from '@deepseek-ai/dsh-session-query';
3
+ import type { ResolvedConfig } from './config.js';
4
+ import type { ResolvedLearningSchedule } from './config.js';
5
+ import { type HomeAddress } from './domain.js';
6
+ import type { BizAgentService } from './service.js';
7
+ type AgentFactory = Pick<AgentRegistry, 'get' | 'create' | 'resume'>;
8
+ type SessionCatalog = Pick<SessionQueryEngine, 'listSessions' | 'readSession'>;
9
+ /** Explicit, Home-bound launcher for dedicated learning Sessions. Unknown creation is never retried blindly. */
10
+ export declare class LearningSessionRunner {
11
+ private readonly agents;
12
+ private readonly sessions;
13
+ private readonly service;
14
+ private readonly config;
15
+ private readonly handles;
16
+ private readonly activating;
17
+ private readonly watching;
18
+ private readonly recoveryRetryAfter;
19
+ private closing;
20
+ constructor(agents: AgentFactory, sessions: SessionCatalog, service: BizAgentService, config: ResolvedConfig);
21
+ request(agent: Agent, idempotencyKey: string, model?: string): Promise<Record<string, unknown>>;
22
+ /** Trusted host scheduler entrypoint. The occurrence is part of the persistent launch identity. */
23
+ requestScheduled(schedule: ResolvedLearningSchedule, dueAt: number, scheduleFingerprint: string, requestedAt?: number, policyRevision?: number): Promise<Record<string, unknown>>;
24
+ private requestFor;
25
+ read(agent: Agent, id: string): Promise<Record<string, unknown>>;
26
+ abandon(agent: Agent, id: string, reason: string): Promise<Record<string, unknown>>;
27
+ /**
28
+ * Abandon launches that have needed review for longer than `maxAgeMs`, so one unresolved launch
29
+ * cannot block every later scheduled learning period. A live worker or an open batch keeps it.
30
+ */
31
+ retireStaleReviews(homeAddress: HomeAddress, now: number, maxAgeMs: number): Promise<string[]>;
32
+ /** On restart, only an already visible worker Session may be resumed. */
33
+ recoverBatch(limit?: number): Promise<{
34
+ recovered: string[];
35
+ needsReview: string[];
36
+ failed: Array<{
37
+ id: string;
38
+ error: unknown;
39
+ }>;
40
+ }>;
41
+ close(): Promise<void>;
42
+ private activateOnce;
43
+ private activate;
44
+ private watch;
45
+ private releaseWhenIdle;
46
+ private markNeedsReview;
47
+ private view;
48
+ }
49
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
2
+ import type { EvidenceRef } from './domain.js';
3
+ export interface LearningTriggerMatch {
4
+ reason: 'explicit-correction';
5
+ evidenceRef: Extract<EvidenceRef, {
6
+ type: 'session-events';
7
+ }>;
8
+ excerpt: string;
9
+ }
10
+ export interface LearningTrigger {
11
+ readonly name: string;
12
+ detect(events: readonly SessionEvent[], turn: number): LearningTriggerMatch | undefined;
13
+ }
14
+ export declare class ExplicitCorrectionTrigger implements LearningTrigger {
15
+ readonly name = "explicit-correction";
16
+ detect(events: readonly SessionEvent[], turn: number): LearningTriggerMatch | undefined;
17
+ }
@@ -0,0 +1,17 @@
1
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
2
+ /** A projection of the dedicated worker's durable model-call evidence. No price is inferred. */
3
+ export interface LearningUsage {
4
+ status: 'reported' | 'partial' | 'unavailable';
5
+ reported?: {
6
+ inputTokens: number;
7
+ outputTokens: number;
8
+ cacheReadTokens: number;
9
+ cacheWriteTokens: number;
10
+ reasoningTokens: number;
11
+ };
12
+ reportedSteps: number;
13
+ unreportedSteps: number;
14
+ lastEventSeq: number | null;
15
+ costUsd: null;
16
+ }
17
+ export declare function summarizeLearningUsage(events: readonly SessionEvent[]): LearningUsage;
@@ -0,0 +1,190 @@
1
+ import { type DomainFacility } from '@deepseek-ai/dsh-storage-domain';
2
+ import { type SharedKnowledgeProposal } from './shared-knowledge.js';
3
+ import { type AgentFrameState, type InboxDelivery, type InboxHumanNotification, type HumanNotificationPreference, type UserAddress, type InboxMessage, type InboxWakeOrigin, type InboxWakePlan, type InboxReturnRoute, type FitnessReceipt, type LearningCheckpoint, type LearningMaterialObservation, type LearningMaterialReview, type LearningBatchRun, type LearningLaunch, type LearningScheduleCursor, type LearningSchedulePolicy, type MemoryProposal, type ProjectTurnParticipation, type SessionBinding } from './domain.js';
4
+ export declare const BIZAGENT_DOMAIN: {
5
+ name: string;
6
+ version: number;
7
+ tables: {
8
+ bindings: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
9
+ sessionId: string;
10
+ homeAddress: string;
11
+ boundAt: string;
12
+ cwd?: string | undefined;
13
+ }>;
14
+ proposals: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
15
+ id: string;
16
+ fromAddress: string;
17
+ toAddress: string;
18
+ proposedKind: "memory" | "insight" | "knowledge" | "method" | "identity";
19
+ description: string;
20
+ body: string;
21
+ tags: string[];
22
+ sourceRefs: ({
23
+ type: "session-events";
24
+ sessionId: string;
25
+ fromSeq: number;
26
+ toSeq: number;
27
+ } | {
28
+ type: "worklog";
29
+ sessionId: string;
30
+ revisionId: string;
31
+ fingerprint: string;
32
+ } | {
33
+ type: "tool-result";
34
+ sessionId: string;
35
+ eventSeq: number;
36
+ toolCallId: string;
37
+ } | {
38
+ type: "artifact";
39
+ uri: string;
40
+ digest: string;
41
+ } | {
42
+ type: "document";
43
+ uri: string;
44
+ digest: string;
45
+ authority?: string | undefined;
46
+ } | {
47
+ type: "asset";
48
+ ownerAddress: string;
49
+ assetId: string;
50
+ revision: number;
51
+ } | {
52
+ type: "user-confirmation";
53
+ sessionId: string;
54
+ eventSeq: number;
55
+ })[];
56
+ status: "rejected" | "pending" | "accepted" | "withdrawn";
57
+ createdAt: string;
58
+ baseAsset?: {
59
+ id: string;
60
+ revision: number;
61
+ bodySha256: string;
62
+ } | undefined;
63
+ targetAssetId?: string | undefined;
64
+ appliedAssetRevision?: number | undefined;
65
+ appliedBodySha256?: string | undefined;
66
+ humanReview?: {
67
+ reviewerId: string;
68
+ authorityRef: string;
69
+ action: "accept" | "reject";
70
+ decision: string;
71
+ reviewedAt: string;
72
+ } | undefined;
73
+ decision?: string | undefined;
74
+ decidedAt?: string | undefined;
75
+ }>;
76
+ receipts: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
77
+ id: string;
78
+ assetId: string;
79
+ ownerAddress: string;
80
+ sessionId: string;
81
+ signal: "retrieved" | "applied" | "confirmed" | "contradicted" | "failed";
82
+ createdAt: string;
83
+ eventSeq?: number | undefined;
84
+ assetRevision?: number | undefined;
85
+ assetBodySha256?: string | undefined;
86
+ outcome?: string | undefined;
87
+ }>;
88
+ metadata: import("@deepseek-ai/dsh-storage-domain").DomainTableSpec<string, {
89
+ key: string;
90
+ value: string;
91
+ updatedAt: string;
92
+ }>;
93
+ };
94
+ };
95
+ export declare class LearningLedger {
96
+ private readonly domain;
97
+ private receiptTail;
98
+ private learningBatchTail;
99
+ private readonly materialReviewWrites;
100
+ private readonly frameMutationTail;
101
+ private inboxMutationTail;
102
+ private projectTurnTail;
103
+ private proposalTail;
104
+ private constructor();
105
+ static open(facility: DomainFacility): Promise<LearningLedger>;
106
+ getBinding(sessionId: string): SessionBinding | undefined;
107
+ putBinding(binding: SessionBinding): Promise<void>;
108
+ /** Roll back a pre-creation reservation only after the host has verified that no Session materialized. */
109
+ removeUnmaterializedBinding(binding: SessionBinding): Promise<boolean>;
110
+ /** Forget a binding the current rules no longer make, so its Session binds afresh on its next turn. */
111
+ releaseBinding(binding: SessionBinding): Promise<boolean>;
112
+ listBindings(homeAddress?: string): SessionBinding[];
113
+ listProjectTurns(projectId?: string): ProjectTurnParticipation[];
114
+ putProjectTurn(input: Omit<ProjectTurnParticipation, 'schemaVersion' | 'recordedAt'>): Promise<ProjectTurnParticipation>;
115
+ getFrameState(sessionId: string): AgentFrameState | undefined;
116
+ updateFrameState(sessionId: string, update: (current: AgentFrameState | undefined) => AgentFrameState): Promise<AgentFrameState>;
117
+ withInboxWrite<T>(update: () => Promise<T>): Promise<T>;
118
+ getInboxMessage(id: string): InboxMessage | undefined;
119
+ listInboxMessages(): InboxMessage[];
120
+ putInboxMessage(message: InboxMessage): Promise<void>;
121
+ getInboxDelivery(messageId: string, recipient: string): InboxDelivery | undefined;
122
+ putInboxDelivery(delivery: InboxDelivery): Promise<void>;
123
+ getInboxHumanNotification(messageId: string, recipient: string): InboxHumanNotification | undefined;
124
+ getHumanNotificationPreference(recipient: string): HumanNotificationPreference | undefined;
125
+ setHumanNotificationPreference(recipient: string, enabled: boolean, expectedRevision: number): Promise<HumanNotificationPreference>;
126
+ /** The external provider was never called; this terminal record survives later opt-in. */
127
+ suppressInboxHumanNotification(messageId: string, recipient: string, reason: string): Promise<InboxHumanNotification>;
128
+ private putSuppressedHumanNotification;
129
+ /** Persist an opt-out while holding the same lock as preference updates and channel reservations. */
130
+ suppressInboxHumanNotificationIfOptedOut(messageId: string, recipient: UserAddress): Promise<InboxHumanNotification | undefined>;
131
+ /** Reserve before calling the channel; a crash leaves unknown and never causes an automatic resend. */
132
+ reserveInboxHumanNotification(messageId: string, recipient: string): Promise<{
133
+ notification: InboxHumanNotification;
134
+ reserved: boolean;
135
+ }>;
136
+ settleInboxHumanNotification(messageId: string, recipient: string, outcome: {
137
+ status: 'sent';
138
+ providerReceipt: string;
139
+ } | {
140
+ status: 'rejected';
141
+ reason: string;
142
+ }): Promise<InboxHumanNotification>;
143
+ /** A definite rejection permits one explicit new attempt; unknown and sent never do. */
144
+ retryRejectedInboxHumanNotification(messageId: string, recipient: string): Promise<InboxHumanNotification>;
145
+ getInboxWakeOrigin(sessionId: string): InboxWakeOrigin | undefined;
146
+ putInboxWakeOrigin(origin: InboxWakeOrigin): Promise<InboxWakeOrigin>;
147
+ getInboxWakePlan(id: string): InboxWakePlan | undefined;
148
+ listInboxWakePlans(): InboxWakePlan[];
149
+ /** Caller holds withInboxWrite so plan selection and reservation share one local writer. */
150
+ putInboxWakePlan(plan: InboxWakePlan): Promise<InboxWakePlan>;
151
+ markInboxWakeDispatched(id: string, dispatchedAt: string, retiredReason?: string): Promise<InboxWakePlan>;
152
+ getInboxReturnRoute(messageId: string, recipient: string): InboxReturnRoute | undefined;
153
+ putInboxReturnRoute(route: InboxReturnRoute): Promise<InboxReturnRoute>;
154
+ getMaterialObservation(id: string): LearningMaterialObservation | undefined;
155
+ putMaterialObservation(observation: LearningMaterialObservation): Promise<LearningMaterialObservation>;
156
+ getMaterialReview(materialId: string): LearningMaterialReview | undefined;
157
+ putMaterialReview(review: LearningMaterialReview): Promise<LearningMaterialReview>;
158
+ withLearningBatchWrite<T>(update: () => Promise<T>): Promise<T>;
159
+ getLearningBatch(id: string): LearningBatchRun | undefined;
160
+ listLearningBatches(homeAddress: string): LearningBatchRun[];
161
+ putLearningBatch(run: LearningBatchRun): Promise<LearningBatchRun>;
162
+ getLearningLaunch(id: string): LearningLaunch | undefined;
163
+ listLearningLaunches(homeAddress?: string): LearningLaunch[];
164
+ putLearningLaunch(launch: LearningLaunch): Promise<LearningLaunch>;
165
+ getLearningScheduleCursor(homeAddress: string): LearningScheduleCursor | undefined;
166
+ putLearningScheduleCursor(cursor: LearningScheduleCursor): Promise<LearningScheduleCursor>;
167
+ getLearningSchedulePolicy(homeAddress: string): LearningSchedulePolicy | undefined;
168
+ /** Caller holds the learning batch write lock and checks the prior revision. */
169
+ putLearningSchedulePolicy(policy: LearningSchedulePolicy): Promise<LearningSchedulePolicy>;
170
+ getProposal(id: string): MemoryProposal | undefined;
171
+ putProposal(proposal: MemoryProposal): Promise<void>;
172
+ listProposals(options?: {
173
+ fromAddress?: string;
174
+ toAddress?: string;
175
+ status?: MemoryProposal['status'];
176
+ }): MemoryProposal[];
177
+ getSharedKnowledgeProposal(id: string): SharedKnowledgeProposal | undefined;
178
+ listSharedKnowledgeProposals(status?: SharedKnowledgeProposal['status']): SharedKnowledgeProposal[];
179
+ putSharedKnowledgeProposal(input: SharedKnowledgeProposal): Promise<SharedKnowledgeProposal>;
180
+ putReceipt(receipt: FitnessReceipt): Promise<boolean>;
181
+ listReceipts(assetId?: string): FitnessReceipt[];
182
+ getCheckpoint(id: string): LearningCheckpoint | undefined;
183
+ putCheckpoint(checkpoint: LearningCheckpoint): Promise<void>;
184
+ listCheckpoints(options?: {
185
+ sessionId?: string;
186
+ homeAddress?: string;
187
+ status?: LearningCheckpoint['status'];
188
+ }): LearningCheckpoint[];
189
+ close(): Promise<void>;
190
+ }
@@ -0,0 +1,7 @@
1
+ /** Whether a string can name a local human (Home owner or reviewer). */
2
+ export declare function isLocalUserId(value: string): boolean;
3
+ /**
4
+ * The person who owns Homes created by a local host: $BIZAGENT_LOCAL_HUMAN_ID when set,
5
+ * otherwise the operating system user name reduced to the allowed characters.
6
+ */
7
+ export declare function localOwnerId(env?: NodeJS.ProcessEnv): string;
@@ -0,0 +1,9 @@
1
+ import type { ContextFormed } from '@deepseek-ai/dsh-llm';
2
+ declare module '@deepseek-ai/dsh-llm' {
3
+ interface MessageSourceMap {
4
+ bizagent: {
5
+ kind: 'bizagent';
6
+ } & ContextFormed;
7
+ }
8
+ }
9
+ export declare const BIZAGENT_SOURCE_KIND = "bizagent";
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ export declare const ActiveOrganizationLocationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
+ schemaVersion: z.ZodLiteral<1>;
4
+ workspacePath: z.ZodString;
5
+ organizationId: z.ZodString;
6
+ organizationRoot: z.ZodString;
7
+ updatedAt: z.ZodString;
8
+ }, z.core.$strip>, z.ZodObject<{
9
+ schemaVersion: z.ZodLiteral<2>;
10
+ organizationId: z.ZodString;
11
+ organizationRoot: z.ZodString;
12
+ updatedAt: z.ZodString;
13
+ }, z.core.$strip>], "schemaVersion">;
14
+ export type ActiveOrganizationLocation = z.infer<typeof ActiveOrganizationLocationSchema>;
15
+ export declare function activeOrganizationLocationPath(registryRoot: string): string;
16
+ /** Where a new organization lives: `<data root>/orgs/<id>`. */
17
+ export declare function organizationLocation(registryRoot: string, organizationId: string): ActiveOrganizationLocation;
18
+ export declare function loadActiveOrganizationLocation(registryRoot: string): Promise<ActiveOrganizationLocation | undefined>;
19
+ export declare function saveActiveOrganizationLocation(registryRoot: string, location: ActiveOrganizationLocation): Promise<void>;