@soulcraft/sdk 1.6.2 → 2.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 (176) hide show
  1. package/dist/client/create-client-sdk.d.ts +16 -2
  2. package/dist/client/create-client-sdk.d.ts.map +1 -1
  3. package/dist/client/create-client-sdk.js +2 -7
  4. package/dist/client/create-client-sdk.js.map +1 -1
  5. package/dist/client/index.d.ts +48 -37
  6. package/dist/client/index.d.ts.map +1 -1
  7. package/dist/client/index.js +61 -42
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/client/namespace-proxy.d.ts +108 -0
  10. package/dist/client/namespace-proxy.d.ts.map +1 -0
  11. package/dist/client/namespace-proxy.js +151 -0
  12. package/dist/client/namespace-proxy.js.map +1 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/modules/app-context/index.d.ts +214 -0
  17. package/dist/modules/app-context/index.d.ts.map +1 -0
  18. package/dist/modules/app-context/index.js +569 -0
  19. package/dist/modules/app-context/index.js.map +1 -0
  20. package/dist/modules/auth/products.d.ts +208 -0
  21. package/dist/modules/auth/products.d.ts.map +1 -0
  22. package/dist/modules/auth/products.js +165 -0
  23. package/dist/modules/auth/products.js.map +1 -0
  24. package/dist/namespaces.d.ts +2942 -0
  25. package/dist/namespaces.d.ts.map +1 -0
  26. package/dist/namespaces.js +37 -0
  27. package/dist/namespaces.js.map +1 -0
  28. package/dist/rpc.d.ts +156 -0
  29. package/dist/rpc.d.ts.map +1 -0
  30. package/dist/rpc.js +26 -0
  31. package/dist/rpc.js.map +1 -0
  32. package/dist/server/create-sdk.d.ts.map +1 -1
  33. package/dist/server/create-sdk.js +3 -13
  34. package/dist/server/create-sdk.js.map +1 -1
  35. package/dist/server/handlers/annotations.d.ts +52 -0
  36. package/dist/server/handlers/annotations.d.ts.map +1 -0
  37. package/dist/server/handlers/annotations.js +204 -0
  38. package/dist/server/handlers/annotations.js.map +1 -0
  39. package/dist/server/handlers/auth.d.ts +53 -0
  40. package/dist/server/handlers/auth.d.ts.map +1 -0
  41. package/dist/server/handlers/auth.js +66 -0
  42. package/dist/server/handlers/auth.js.map +1 -0
  43. package/dist/server/handlers/certification.d.ts +32 -0
  44. package/dist/server/handlers/certification.d.ts.map +1 -0
  45. package/dist/server/handlers/certification.js +253 -0
  46. package/dist/server/handlers/certification.js.map +1 -0
  47. package/dist/server/handlers/chat/conversations.d.ts +91 -0
  48. package/dist/server/handlers/chat/conversations.d.ts.map +1 -0
  49. package/dist/server/handlers/chat/conversations.js +314 -0
  50. package/dist/server/handlers/chat/conversations.js.map +1 -0
  51. package/dist/server/handlers/chat/delegator.d.ts +144 -0
  52. package/dist/server/handlers/chat/delegator.d.ts.map +1 -0
  53. package/dist/server/handlers/chat/delegator.js +431 -0
  54. package/dist/server/handlers/chat/delegator.js.map +1 -0
  55. package/dist/server/handlers/chat/engine.d.ts +81 -0
  56. package/dist/server/handlers/chat/engine.d.ts.map +1 -0
  57. package/dist/server/handlers/chat/engine.js +442 -0
  58. package/dist/server/handlers/chat/engine.js.map +1 -0
  59. package/dist/server/handlers/chat/executor.d.ts +65 -0
  60. package/dist/server/handlers/chat/executor.d.ts.map +1 -0
  61. package/dist/server/handlers/chat/executor.js +375 -0
  62. package/dist/server/handlers/chat/executor.js.map +1 -0
  63. package/dist/server/handlers/chat/index.d.ts +62 -0
  64. package/dist/server/handlers/chat/index.d.ts.map +1 -0
  65. package/dist/server/handlers/chat/index.js +182 -0
  66. package/dist/server/handlers/chat/index.js.map +1 -0
  67. package/dist/server/handlers/chat/memory.d.ts +91 -0
  68. package/dist/server/handlers/chat/memory.d.ts.map +1 -0
  69. package/dist/server/handlers/chat/memory.js +293 -0
  70. package/dist/server/handlers/chat/memory.js.map +1 -0
  71. package/dist/server/handlers/chat/models.d.ts +180 -0
  72. package/dist/server/handlers/chat/models.d.ts.map +1 -0
  73. package/dist/server/handlers/chat/models.js +304 -0
  74. package/dist/server/handlers/chat/models.js.map +1 -0
  75. package/dist/server/handlers/chat/planner.d.ts +116 -0
  76. package/dist/server/handlers/chat/planner.d.ts.map +1 -0
  77. package/dist/server/handlers/chat/planner.js +344 -0
  78. package/dist/server/handlers/chat/planner.js.map +1 -0
  79. package/dist/server/handlers/chat/types.d.ts +500 -0
  80. package/dist/server/handlers/chat/types.d.ts.map +1 -0
  81. package/dist/server/handlers/chat/types.js +11 -0
  82. package/dist/server/handlers/chat/types.js.map +1 -0
  83. package/dist/server/handlers/collections.d.ts +67 -0
  84. package/dist/server/handlers/collections.d.ts.map +1 -0
  85. package/dist/server/handlers/collections.js +484 -0
  86. package/dist/server/handlers/collections.js.map +1 -0
  87. package/dist/server/handlers/commerce.d.ts +106 -0
  88. package/dist/server/handlers/commerce.d.ts.map +1 -0
  89. package/dist/server/handlers/commerce.js +62 -0
  90. package/dist/server/handlers/commerce.js.map +1 -0
  91. package/dist/server/handlers/config.d.ts +112 -0
  92. package/dist/server/handlers/config.d.ts.map +1 -0
  93. package/dist/server/handlers/config.js +122 -0
  94. package/dist/server/handlers/config.js.map +1 -0
  95. package/dist/server/handlers/export.d.ts +72 -0
  96. package/dist/server/handlers/export.d.ts.map +1 -0
  97. package/dist/server/handlers/export.js +175 -0
  98. package/dist/server/handlers/export.js.map +1 -0
  99. package/dist/server/handlers/formats.d.ts +77 -0
  100. package/dist/server/handlers/formats.d.ts.map +1 -0
  101. package/dist/server/handlers/formats.js +65 -0
  102. package/dist/server/handlers/formats.js.map +1 -0
  103. package/dist/server/handlers/graph.d.ts +31 -0
  104. package/dist/server/handlers/graph.d.ts.map +1 -0
  105. package/dist/server/handlers/graph.js +490 -0
  106. package/dist/server/handlers/graph.js.map +1 -0
  107. package/dist/server/handlers/import.d.ts +96 -0
  108. package/dist/server/handlers/import.d.ts.map +1 -0
  109. package/dist/server/handlers/import.js +108 -0
  110. package/dist/server/handlers/import.js.map +1 -0
  111. package/dist/server/handlers/index.d.ts +68 -0
  112. package/dist/server/handlers/index.d.ts.map +1 -0
  113. package/dist/server/handlers/index.js +71 -0
  114. package/dist/server/handlers/index.js.map +1 -0
  115. package/dist/server/handlers/media.d.ts +76 -0
  116. package/dist/server/handlers/media.d.ts.map +1 -0
  117. package/dist/server/handlers/media.js +53 -0
  118. package/dist/server/handlers/media.js.map +1 -0
  119. package/dist/server/handlers/project.d.ts +45 -0
  120. package/dist/server/handlers/project.d.ts.map +1 -0
  121. package/dist/server/handlers/project.js +181 -0
  122. package/dist/server/handlers/project.js.map +1 -0
  123. package/dist/server/handlers/publish.d.ts +102 -0
  124. package/dist/server/handlers/publish.d.ts.map +1 -0
  125. package/dist/server/handlers/publish.js +130 -0
  126. package/dist/server/handlers/publish.js.map +1 -0
  127. package/dist/server/handlers/pulse.d.ts +39 -0
  128. package/dist/server/handlers/pulse.d.ts.map +1 -0
  129. package/dist/server/handlers/pulse.js +78 -0
  130. package/dist/server/handlers/pulse.js.map +1 -0
  131. package/dist/server/handlers/realtime.d.ts +55 -0
  132. package/dist/server/handlers/realtime.d.ts.map +1 -0
  133. package/dist/server/handlers/realtime.js +49 -0
  134. package/dist/server/handlers/realtime.js.map +1 -0
  135. package/dist/server/handlers/search.d.ts +21 -0
  136. package/dist/server/handlers/search.d.ts.map +1 -0
  137. package/dist/server/handlers/search.js +237 -0
  138. package/dist/server/handlers/search.js.map +1 -0
  139. package/dist/server/handlers/session.d.ts +47 -0
  140. package/dist/server/handlers/session.d.ts.map +1 -0
  141. package/dist/server/handlers/session.js +286 -0
  142. package/dist/server/handlers/session.js.map +1 -0
  143. package/dist/server/handlers/settings.d.ts +97 -0
  144. package/dist/server/handlers/settings.d.ts.map +1 -0
  145. package/dist/server/handlers/settings.js +131 -0
  146. package/dist/server/handlers/settings.js.map +1 -0
  147. package/dist/server/handlers/workspace.d.ts +78 -0
  148. package/dist/server/handlers/workspace.d.ts.map +1 -0
  149. package/dist/server/handlers/workspace.js +270 -0
  150. package/dist/server/handlers/workspace.js.map +1 -0
  151. package/dist/server/hono-router.d.ts +66 -0
  152. package/dist/server/hono-router.d.ts.map +1 -0
  153. package/dist/server/hono-router.js +203 -0
  154. package/dist/server/hono-router.js.map +1 -0
  155. package/dist/server/index.d.ts +29 -19
  156. package/dist/server/index.d.ts.map +1 -1
  157. package/dist/server/index.js +33 -19
  158. package/dist/server/index.js.map +1 -1
  159. package/dist/server/namespace-router.d.ts +204 -0
  160. package/dist/server/namespace-router.d.ts.map +1 -0
  161. package/dist/server/namespace-router.js +262 -0
  162. package/dist/server/namespace-router.js.map +1 -0
  163. package/dist/transports/http-namespace.d.ts +210 -0
  164. package/dist/transports/http-namespace.d.ts.map +1 -0
  165. package/dist/transports/http-namespace.js +514 -0
  166. package/dist/transports/http-namespace.js.map +1 -0
  167. package/dist/transports/workshop.d.ts +173 -0
  168. package/dist/transports/workshop.d.ts.map +1 -0
  169. package/dist/transports/workshop.js +307 -0
  170. package/dist/transports/workshop.js.map +1 -0
  171. package/dist/types.d.ts +65 -67
  172. package/dist/types.d.ts.map +1 -1
  173. package/dist/types.js +7 -3
  174. package/dist/types.js.map +1 -1
  175. package/docs/ADR-004-product-registry.md +108 -0
  176. package/package.json +1 -1
@@ -0,0 +1,500 @@
1
+ /**
2
+ * @module server/handlers/chat/types
3
+ * @description Shared types and dependency interfaces for the chat engine.
4
+ *
5
+ * Products inject implementations of these interfaces when creating the chat
6
+ * handler. The SDK provides the universal engine (streaming loop, conversation
7
+ * CRUD, memory, model routing, delegator, planner); products supply their
8
+ * own tools, system prompts, and billing checks.
9
+ */
10
+ import type { Brainy } from '@soulcraft/brainy';
11
+ import type { HandlerContext } from '../../namespace-router.js';
12
+ /**
13
+ * Abstraction over the Anthropic SDK `messages.create()` call.
14
+ *
15
+ * Products inject their own client (which may use a personal API key, a
16
+ * platform key, or a BYOK key). The chat engine calls `createStream()` and
17
+ * iterates over the events.
18
+ */
19
+ export interface ChatAIClient {
20
+ /**
21
+ * Create a streaming message completion.
22
+ *
23
+ * @param options - Anthropic-compatible request options.
24
+ * @returns An async iterable of raw Anthropic stream events.
25
+ */
26
+ createStream(options: {
27
+ model: string;
28
+ maxTokens: number;
29
+ system: Array<{
30
+ type: 'text';
31
+ text: string;
32
+ cache_control?: {
33
+ type: 'ephemeral';
34
+ };
35
+ }>;
36
+ messages: Array<{
37
+ role: string;
38
+ content: any;
39
+ }>;
40
+ tools?: ToolDefinition[];
41
+ thinking?: {
42
+ type: 'enabled';
43
+ budget_tokens: number;
44
+ };
45
+ }): Promise<AsyncIterable<AnthropicStreamEvent>>;
46
+ /**
47
+ * Create a non-streaming message completion.
48
+ *
49
+ * Used by the delegator for triage and synthesis (no streaming needed).
50
+ *
51
+ * @param options - Request options.
52
+ * @returns The completion response.
53
+ */
54
+ create(options: {
55
+ model: string;
56
+ maxTokens: number;
57
+ system: string;
58
+ messages: Array<{
59
+ role: string;
60
+ content: any;
61
+ }>;
62
+ tools?: ToolDefinition[];
63
+ }): Promise<{
64
+ content: Array<{
65
+ type: string;
66
+ text?: string;
67
+ id?: string;
68
+ name?: string;
69
+ input?: any;
70
+ }>;
71
+ usage: {
72
+ input_tokens: number;
73
+ output_tokens: number;
74
+ };
75
+ }>;
76
+ }
77
+ /**
78
+ * Raw Anthropic stream event — subset of the events the chat engine processes.
79
+ *
80
+ * The engine handles: content_block_start, content_block_delta,
81
+ * content_block_stop, message_start, message_delta, message_stop.
82
+ */
83
+ export interface AnthropicStreamEvent {
84
+ type: string;
85
+ content_block?: {
86
+ type: string;
87
+ id?: string;
88
+ name?: string;
89
+ };
90
+ delta?: {
91
+ type: string;
92
+ text?: string;
93
+ thinking?: string;
94
+ partial_json?: string;
95
+ };
96
+ message?: {
97
+ usage?: {
98
+ input_tokens?: number;
99
+ output_tokens?: number;
100
+ cache_creation_input_tokens?: number;
101
+ cache_read_input_tokens?: number;
102
+ };
103
+ };
104
+ usage?: {
105
+ output_tokens?: number;
106
+ };
107
+ }
108
+ /**
109
+ * Tool definition in Anthropic's format — passed to `messages.create()`.
110
+ *
111
+ * Products register their own tool sets. Workshop has 31 tools (entity CRUD,
112
+ * VFS, search, UI actions). Venue has different tools. Academy has tutor tools.
113
+ */
114
+ export interface ToolDefinition {
115
+ /** Tool name (e.g. 'advanced_search', 'create_entity'). */
116
+ name: string;
117
+ /** Human-readable description shown to Claude. */
118
+ description: string;
119
+ /** JSON Schema for the tool's input parameters. */
120
+ input_schema: Record<string, unknown>;
121
+ }
122
+ /**
123
+ * Tool executor — dispatches tool calls to product-specific implementations.
124
+ *
125
+ * The chat engine calls this when Claude invokes a tool. Products implement
126
+ * the actual logic (e.g. Workshop's `executeTool()` with 55-case switch).
127
+ */
128
+ export interface ToolExecutor {
129
+ /**
130
+ * Execute a tool call.
131
+ *
132
+ * @param name - Tool name from Claude's response.
133
+ * @param input - Tool input parameters.
134
+ * @param ctx - Execution context with brain, user, and conversation info.
135
+ * @returns Tool result (serialized as JSON for Claude's next turn).
136
+ */
137
+ execute(name: string, input: Record<string, unknown>, ctx: ToolExecutionContext): Promise<unknown>;
138
+ }
139
+ /**
140
+ * Context passed to tool execution.
141
+ *
142
+ * Provides the tool with everything it needs to operate — brain instance,
143
+ * conversation state, and product-specific context.
144
+ */
145
+ export interface ToolExecutionContext {
146
+ /** Brainy instance for the current workspace. */
147
+ brain: Brainy;
148
+ /** Conversation ID the tool is executing within. */
149
+ conversationId: string;
150
+ /** Message ID of the assistant message that triggered this tool call. */
151
+ assistantMessageId: string;
152
+ /** Handler context with user and workspace info. */
153
+ handlerCtx: HandlerContext;
154
+ /** Product-specific context (e.g. Workshop's ChatContext, kit config). */
155
+ productContext?: Record<string, unknown>;
156
+ }
157
+ /**
158
+ * System prompt builder — products provide their own prompt logic.
159
+ *
160
+ * Workshop builds a prompt with kit context, skills, memory, expertise.
161
+ * Venue uses the kit's AI persona. Academy uses a Socratic tutor prompt.
162
+ */
163
+ export interface SystemPromptBuilder {
164
+ /**
165
+ * Build the system prompt for a chat message.
166
+ *
167
+ * @param ctx - Context for prompt building.
168
+ * @returns Static part (cacheable) and dynamic part (per-request).
169
+ */
170
+ build(ctx: SystemPromptContext): Promise<{
171
+ staticPart: string;
172
+ dynamicPart: string;
173
+ }>;
174
+ }
175
+ /**
176
+ * Context provided to the system prompt builder.
177
+ */
178
+ export interface SystemPromptContext {
179
+ /** Brainy instance. */
180
+ brain: Brainy;
181
+ /** Handler context. */
182
+ handlerCtx: HandlerContext;
183
+ /** Conversation history for context. */
184
+ conversationHistory: Array<{
185
+ role: string;
186
+ content: string;
187
+ }>;
188
+ /** Retrieved memory items. */
189
+ memory: RetrievedMemory | null;
190
+ /** User expertise profile. */
191
+ expertise: UserExpertiseProfile | null;
192
+ /** Product-specific context passed through from send options. */
193
+ productContext?: Record<string, unknown>;
194
+ }
195
+ /**
196
+ * Model selector — chooses the right Claude model for each request.
197
+ *
198
+ * The default implementation provides tiered routing (Opus for planning,
199
+ * Sonnet for triage, Haiku for execution). Products can override for
200
+ * simpler routing or cost control.
201
+ */
202
+ export interface ModelSelector {
203
+ /**
204
+ * Select the routing strategy for a message.
205
+ *
206
+ * @param message - The user's message.
207
+ * @param options - Routing options.
208
+ * @returns The routing decision with model assignments.
209
+ */
210
+ selectRouting(message: string, options: {
211
+ planModeEnabled?: boolean;
212
+ forcedModel?: string;
213
+ }): TieredRouting;
214
+ }
215
+ /** Model role in the tiered strategy. */
216
+ export type ModelRole = 'planner' | 'triage' | 'executor' | 'fallback';
217
+ /**
218
+ * Tiered routing decision — which models to use for each phase.
219
+ */
220
+ export interface TieredRouting {
221
+ /** Whether plan mode is active. */
222
+ planModeEnabled: boolean;
223
+ /** Model for triage/planning phase. */
224
+ triageModel: string;
225
+ /** Model for task execution phase. */
226
+ executeModel: string;
227
+ /** Complexity score (0-10) from message analysis. */
228
+ complexityScore: number;
229
+ /** Whether the engine should recommend switching to plan mode. */
230
+ shouldRecommendPlan: boolean;
231
+ /** Human-readable routing reason. */
232
+ reason: string;
233
+ }
234
+ /**
235
+ * Billing check interface — products enforce their own limits.
236
+ *
237
+ * Called before streaming starts. If the check fails, the chat handler
238
+ * returns an error without calling Claude.
239
+ */
240
+ export interface ChatBillingCheck {
241
+ /**
242
+ * Check if the user can send a message.
243
+ *
244
+ * @param userId - The billing identity (email or hash).
245
+ * @param ctx - Handler context.
246
+ * @returns Whether the user can proceed, and tier info.
247
+ */
248
+ checkLimit(userId: string, ctx: HandlerContext): Promise<{
249
+ ok: boolean;
250
+ tier: 'free' | 'subscriber' | 'byok';
251
+ remaining: number;
252
+ useTopUp?: boolean;
253
+ }>;
254
+ /**
255
+ * Record token usage after a message completes. Fire-and-forget.
256
+ *
257
+ * @param userId - The billing identity.
258
+ * @param inputTokens - Input tokens consumed.
259
+ * @param outputTokens - Output tokens consumed.
260
+ * @param model - Model used.
261
+ */
262
+ recordUsage(userId: string, inputTokens: number, outputTokens: number, model: string): void;
263
+ }
264
+ /**
265
+ * Optional event emitter for real-time UI updates (data changes, activity feed).
266
+ */
267
+ export interface ChatEventEmitter {
268
+ /** Emit an event. */
269
+ emit(event: string, data: unknown): void;
270
+ }
271
+ /**
272
+ * Memory retrieved by the proactive memory system for context enrichment.
273
+ */
274
+ export interface RetrievedMemory {
275
+ /** Past conversation fragments relevant to the current message. */
276
+ conversations: Array<{
277
+ content: string;
278
+ timestamp: string;
279
+ }>;
280
+ /** User preferences learned from past interactions. */
281
+ preferences: Array<{
282
+ key: string;
283
+ value: string;
284
+ }>;
285
+ /** Entities in the knowledge graph related to the message. */
286
+ relatedEntities: Array<{
287
+ id: string;
288
+ name: string;
289
+ type: string;
290
+ }>;
291
+ /** Insights the AI has derived from past conversations. */
292
+ insights: Array<{
293
+ content: string;
294
+ confidence: number;
295
+ }>;
296
+ }
297
+ /**
298
+ * User expertise profile — accumulated over time from conversations.
299
+ *
300
+ * The AI adapts its communication style based on the user's demonstrated
301
+ * knowledge level in various domains.
302
+ */
303
+ export interface UserExpertiseProfile {
304
+ /** Domains where the user has demonstrated strong knowledge. */
305
+ strongAreas: string[];
306
+ /** Domains where the user is learning or has asked basic questions. */
307
+ growthAreas: string[];
308
+ /** Overall technical sophistication (1-5 scale). */
309
+ technicalLevel: number;
310
+ /** How much detail the user prefers (1-5 scale). */
311
+ preferredDetailLevel: number;
312
+ /** User's preferred communication style. */
313
+ communicationStyle: string;
314
+ /** Specific domain expertise entries. */
315
+ domainExpertise: Array<{
316
+ domain: string;
317
+ level: number;
318
+ lastSeen: string;
319
+ }>;
320
+ }
321
+ /** Routing decision from triage. */
322
+ export type RoutingDecisionType = 'direct' | 'delegate_tasks' | 'recommend_plan';
323
+ /** A task delegated by the triage model to the executor model. */
324
+ export interface DelegatedTask {
325
+ id: string;
326
+ description: string;
327
+ tool?: string;
328
+ input?: Record<string, unknown>;
329
+ purpose: string;
330
+ status: 'pending' | 'running' | 'completed' | 'failed';
331
+ result?: unknown;
332
+ error?: string;
333
+ }
334
+ /** Triage routing decision. */
335
+ export interface RoutingDecision {
336
+ decision: RoutingDecisionType;
337
+ reasoning: string;
338
+ tasks?: DelegatedTask[];
339
+ directResponse?: string;
340
+ recommendPlanReason?: string;
341
+ }
342
+ /** Result of the triage phase. */
343
+ export interface TriageResult {
344
+ decision: RoutingDecision;
345
+ inputTokens: number;
346
+ outputTokens: number;
347
+ }
348
+ /** Result of executing a single delegated task. */
349
+ export interface TaskExecutionResult {
350
+ taskId: string;
351
+ success: boolean;
352
+ result?: unknown;
353
+ error?: string;
354
+ model: string;
355
+ escalated: boolean;
356
+ inputTokens: number;
357
+ outputTokens: number;
358
+ }
359
+ /** Result of the full delegation flow. */
360
+ export interface DelegationResult {
361
+ success: boolean;
362
+ taskResults: TaskExecutionResult[];
363
+ synthesizedResponse?: string;
364
+ totalTokens: {
365
+ input: number;
366
+ output: number;
367
+ };
368
+ escalationCount: number;
369
+ }
370
+ /** A step in an AI-generated execution plan. */
371
+ export interface PlanStep {
372
+ id: string;
373
+ description: string;
374
+ activeDescription: string;
375
+ tools: string[];
376
+ dependencies: string[];
377
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
378
+ result?: unknown;
379
+ error?: string;
380
+ startedAt?: string;
381
+ completedAt?: string;
382
+ }
383
+ /** An AI-generated plan for complex multi-step operations. */
384
+ export interface AIPlan {
385
+ id: string;
386
+ conversationId: string;
387
+ userMessage: string;
388
+ status: 'draft' | 'pending' | 'approved' | 'executing' | 'completed' | 'failed' | 'cancelled';
389
+ analysis: string;
390
+ approach: string;
391
+ steps: PlanStep[];
392
+ executionContext: {
393
+ relevantFiles: string[];
394
+ entities: string[];
395
+ tools: string[];
396
+ skills: string[];
397
+ };
398
+ planModel: string;
399
+ executeModel: string;
400
+ createdAt: string;
401
+ approvedAt?: string;
402
+ startedAt?: string;
403
+ completedAt?: string;
404
+ estimatedCost: {
405
+ planTokens: number;
406
+ executeTokens: number;
407
+ totalUSD: number;
408
+ };
409
+ actualCost?: {
410
+ inputTokens: number;
411
+ outputTokens: number;
412
+ totalUSD: number;
413
+ };
414
+ }
415
+ /** Progress event emitted during plan execution. */
416
+ export interface StepProgress {
417
+ type: 'step_start' | 'step_complete' | 'step_error' | 'escalating';
418
+ stepId: string;
419
+ stepIndex: number;
420
+ totalSteps: number;
421
+ description: string;
422
+ model?: string;
423
+ result?: unknown;
424
+ error?: string;
425
+ }
426
+ /** Result of executing a plan. */
427
+ export interface PlanExecutionResult {
428
+ success: boolean;
429
+ stepResults: Array<{
430
+ stepId: string;
431
+ status: string;
432
+ result?: unknown;
433
+ error?: string;
434
+ model: string;
435
+ tokens: {
436
+ input: number;
437
+ output: number;
438
+ };
439
+ escalated: boolean;
440
+ }>;
441
+ totalTokens: {
442
+ input: number;
443
+ output: number;
444
+ };
445
+ actualCost: number;
446
+ escalationCount: number;
447
+ }
448
+ /**
449
+ * Options for {@link createChatHandler}.
450
+ *
451
+ * The AI client and tool executor are required — the chat engine can't
452
+ * function without them. All other dependencies have sensible defaults.
453
+ */
454
+ export interface ChatHandlerOptions {
455
+ /** AI client for calling Claude. Required. */
456
+ aiClient: ChatAIClient;
457
+ /** Tool definitions available to Claude. Required. */
458
+ tools: ToolDefinition[];
459
+ /** Tool executor for running tool calls. Required. */
460
+ toolExecutor: ToolExecutor;
461
+ /** System prompt builder. If omitted, uses a minimal default prompt. */
462
+ systemPromptBuilder?: SystemPromptBuilder;
463
+ /** Model selector for tiered routing. If omitted, uses default tiers. */
464
+ modelSelector?: ModelSelector;
465
+ /** Billing check. If omitted, all messages are allowed. */
466
+ billing?: ChatBillingCheck;
467
+ /** Event emitter for real-time updates. Optional. */
468
+ events?: ChatEventEmitter;
469
+ /**
470
+ * Maximum agentic loop iterations (tool use → Claude → tool use → ...).
471
+ * @default 100
472
+ */
473
+ maxIterations?: number;
474
+ /**
475
+ * Maximum agentic loop duration in milliseconds.
476
+ * @default 300000 (5 minutes)
477
+ */
478
+ maxDurationMs?: number;
479
+ /**
480
+ * Default model for non-tiered requests.
481
+ * @default 'claude-3-5-haiku-latest'
482
+ */
483
+ defaultModel?: string;
484
+ /**
485
+ * Free-tier model override. Used when billing reports `tier: 'free'`.
486
+ * @default 'claude-3-5-haiku-latest'
487
+ */
488
+ freeTierModel?: string;
489
+ /**
490
+ * Enable extended thinking for supported models.
491
+ * @default true
492
+ */
493
+ enableThinking?: boolean;
494
+ /**
495
+ * Thinking budget in tokens.
496
+ * @default 8000
497
+ */
498
+ thinkingBudget?: number;
499
+ }
500
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/server/handlers/chat/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAO/D;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,MAAM,CAAA;QACjB,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* @module server/handlers/chat/types
3
+ * @description Shared types and dependency interfaces for the chat engine.
4
+ *
5
+ * Products inject implementations of these interfaces when creating the chat
6
+ * handler. The SDK provides the universal engine (streaming loop, conversation
7
+ * CRUD, memory, model routing, delegator, planner); products supply their
8
+ * own tools, system prompts, and billing checks.
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/server/handlers/chat/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module server/handlers/collections
3
+ * @description Collections namespace handler — view collection CRUD, member
4
+ * management, and sample data seeding.
5
+ *
6
+ * Absorbs Workshop `routes/collections.ts`. Collections are Brainy entities
7
+ * of type `Collection` with `isViewCollection: true` metadata. Members are
8
+ * linked via `Contains` relationships. Virtual collections (Everything,
9
+ * Uncategorized) are computed dynamically.
10
+ *
11
+ * Methods:
12
+ * - `list` — List all view collections (real + virtual)
13
+ * - `get` — Get a single collection by ID
14
+ * - `create` — Create a new collection (optionally with sample data)
15
+ * - `update` — Update collection name/metadata
16
+ * - `delete` — Delete a collection (members are NOT deleted)
17
+ * - `getMembers` — Get entities belonging to a collection
18
+ * - `addMember` — Add an entity to a collection
19
+ * - `removeMember` — Remove an entity from a collection
20
+ * - `loadSampleData` — Seed sample data for a kit
21
+ * - `clearSampleData` — Remove all sample data entities
22
+ */
23
+ import type { NamespaceProvider } from '../namespace-router.js';
24
+ /**
25
+ * Sample data provider for seeding collections with demo content.
26
+ *
27
+ * Products inject their own sample data definitions — Workshop uses
28
+ * `VIEW_SAMPLE_DATA` keyed by view type; Venue might have different samples.
29
+ */
30
+ export interface SampleDataProvider {
31
+ /**
32
+ * Get sample data for a given key (view type or kit ID).
33
+ *
34
+ * @returns Entity and relationship definitions, or `null` if no sample data.
35
+ */
36
+ getSampleData(key: string): {
37
+ entities: Array<{
38
+ name: string;
39
+ type: string;
40
+ description?: string;
41
+ properties?: Record<string, unknown>;
42
+ }>;
43
+ relationships?: Array<{
44
+ from: string;
45
+ to: string;
46
+ type: string;
47
+ }>;
48
+ } | null;
49
+ }
50
+ /**
51
+ * Options for {@link createCollectionsHandler}.
52
+ */
53
+ export interface CollectionsHandlerOptions {
54
+ /**
55
+ * Sample data provider for the `loadSampleData` method.
56
+ * If not provided, sample data methods return no-ops.
57
+ */
58
+ sampleData?: SampleDataProvider;
59
+ }
60
+ /**
61
+ * Creates the `collections` namespace handler.
62
+ *
63
+ * @param options - Optional collections handler configuration.
64
+ * @returns A {@link NamespaceProvider} implementing {@link CollectionsNamespace}.
65
+ */
66
+ export declare function createCollectionsHandler(options?: CollectionsHandlerOptions): NamespaceProvider;
67
+ //# sourceMappingURL=collections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/collections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,wBAAwB,CAAA;AAO/E;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;QAC1B,QAAQ,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,CAAA;YACZ,IAAI,EAAE,MAAM,CAAA;YACZ,WAAW,CAAC,EAAE,MAAM,CAAA;YACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SACrC,CAAC,CAAA;QACF,aAAa,CAAC,EAAE,KAAK,CAAC;YACpB,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,MAAM,CAAA;YACV,IAAI,EAAE,MAAM,CAAA;SACb,CAAC,CAAA;KACH,GAAG,IAAI,CAAA;CACT;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAChC;AAsED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,iBAAiB,CAwc/F"}