@lota-sdk/core 0.1.15 → 0.1.17

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 (159) hide show
  1. package/infrastructure/schema/00_identity.surql +0 -2
  2. package/infrastructure/schema/01_memory.surql +1 -1
  3. package/infrastructure/schema/02_execution_plan.surql +62 -1
  4. package/infrastructure/schema/03_learned_skill.surql +1 -1
  5. package/infrastructure/schema/06_playbook.surql +25 -0
  6. package/infrastructure/schema/07_institutional_memory.surql +13 -0
  7. package/infrastructure/schema/08_quality_metrics.surql +17 -0
  8. package/package.json +12 -8
  9. package/src/ai/definitions.ts +81 -3
  10. package/src/ai/embedding-cache.ts +2 -4
  11. package/src/ai/index.ts +0 -2
  12. package/src/bifrost/bifrost.ts +2 -7
  13. package/src/bifrost/cache-headers.ts +8 -0
  14. package/src/bifrost/index.ts +1 -0
  15. package/src/config/agent-defaults.ts +31 -21
  16. package/src/config/agent-types.ts +11 -0
  17. package/src/config/constants.ts +2 -14
  18. package/src/config/debug-logger.ts +5 -1
  19. package/src/config/index.ts +3 -0
  20. package/src/config/model-constants.ts +16 -34
  21. package/src/config/search.ts +1 -15
  22. package/src/create-runtime.ts +269 -178
  23. package/src/db/cursor-pagination.ts +3 -6
  24. package/src/db/index.ts +2 -0
  25. package/src/db/memory-store.helpers.ts +1 -3
  26. package/src/db/memory-store.rows.ts +7 -7
  27. package/src/db/memory-store.ts +14 -18
  28. package/src/db/memory.ts +13 -13
  29. package/src/db/schema-fingerprint.ts +1 -3
  30. package/src/db/service.ts +153 -79
  31. package/src/db/startup.ts +6 -10
  32. package/src/db/surreal-mutation.ts +43 -0
  33. package/src/db/tables.ts +7 -0
  34. package/src/db/workstream-message-row.ts +15 -0
  35. package/src/embeddings/provider.ts +1 -1
  36. package/src/queues/context-compaction.queue.ts +15 -46
  37. package/src/queues/delayed-node-promotion.queue.ts +41 -0
  38. package/src/queues/document-processor.queue.ts +2 -4
  39. package/src/queues/index.ts +3 -0
  40. package/src/queues/memory-consolidation.queue.ts +16 -51
  41. package/src/queues/plan-scheduler.queue.ts +97 -0
  42. package/src/queues/post-chat-memory.queue.ts +20 -55
  43. package/src/queues/queue-factory.ts +100 -0
  44. package/src/queues/recent-activity-title-refinement.queue.ts +15 -50
  45. package/src/queues/regular-chat-memory-digest.queue.ts +16 -52
  46. package/src/queues/skill-extraction.queue.ts +15 -47
  47. package/src/queues/workstream-title-generation.queue.ts +15 -47
  48. package/src/redis/connection.ts +6 -0
  49. package/src/redis/index.ts +1 -1
  50. package/src/redis/redis-lease-lock.ts +1 -2
  51. package/src/redis/stream-context.ts +11 -0
  52. package/src/runtime/agent-runtime-policy.ts +109 -35
  53. package/src/runtime/approval-continuation.ts +12 -6
  54. package/src/runtime/context-compaction-runtime.ts +1 -1
  55. package/src/runtime/context-compaction.ts +24 -64
  56. package/src/runtime/execution-plan.ts +22 -18
  57. package/src/runtime/graph-designer.ts +15 -0
  58. package/src/runtime/helper-model.ts +9 -197
  59. package/src/runtime/index.ts +3 -1
  60. package/src/runtime/llm-content.ts +1 -1
  61. package/src/runtime/memory-block.ts +9 -11
  62. package/src/runtime/memory-pipeline.ts +6 -9
  63. package/src/runtime/plugin-resolution.ts +35 -0
  64. package/src/runtime/plugin-types.ts +72 -0
  65. package/src/runtime/retrieval-adapters.ts +1 -1
  66. package/src/runtime/runtime-config.ts +111 -14
  67. package/src/runtime/runtime-extensions.ts +2 -3
  68. package/src/runtime/runtime-worker-registry.ts +6 -0
  69. package/src/runtime/social-chat.ts +752 -0
  70. package/src/runtime/team-consultation-orchestrator.ts +45 -32
  71. package/src/runtime/team-consultation-prompts.ts +11 -2
  72. package/src/runtime/title-helpers.ts +2 -4
  73. package/src/runtime/workstream-chat-helpers.ts +1 -1
  74. package/src/services/adaptive-playbook.service.ts +152 -0
  75. package/src/services/agent-executor.service.ts +292 -0
  76. package/src/services/artifact-provenance.service.ts +172 -0
  77. package/src/services/attachment.service.ts +6 -11
  78. package/src/services/context-compaction.service.ts +72 -55
  79. package/src/services/context-enrichment.service.ts +33 -0
  80. package/src/services/coordination-registry.service.ts +117 -0
  81. package/src/services/document-chunk.service.ts +2 -4
  82. package/src/services/domain-agent-executor.service.ts +71 -0
  83. package/src/services/execution-plan.service.ts +269 -50
  84. package/src/services/feedback-loop.service.ts +96 -0
  85. package/src/services/global-orchestrator.service.ts +148 -0
  86. package/src/services/index.ts +27 -0
  87. package/src/services/institutional-memory.service.ts +145 -0
  88. package/src/services/learned-skill.service.ts +24 -5
  89. package/src/services/memory-assessment.service.ts +3 -2
  90. package/src/services/memory-utils.ts +3 -8
  91. package/src/services/memory.service.ts +49 -61
  92. package/src/services/monitoring-window.service.ts +86 -0
  93. package/src/services/mutating-approval.service.ts +1 -1
  94. package/src/services/node-workspace.service.ts +155 -0
  95. package/src/services/notification.service.ts +39 -0
  96. package/src/services/organization-member.service.ts +11 -4
  97. package/src/services/organization.service.ts +5 -5
  98. package/src/services/ownership-dispatcher.service.ts +403 -0
  99. package/src/services/plan-approval.service.ts +1 -1
  100. package/src/services/plan-builder.service.ts +1 -0
  101. package/src/services/plan-checkpoint.service.ts +30 -2
  102. package/src/services/plan-compiler.service.ts +5 -0
  103. package/src/services/plan-coordination.service.ts +152 -0
  104. package/src/services/plan-cycle.service.ts +284 -0
  105. package/src/services/plan-deadline.service.ts +287 -0
  106. package/src/services/plan-executor.service.ts +384 -40
  107. package/src/services/plan-run.service.ts +41 -7
  108. package/src/services/plan-scheduler.service.ts +240 -0
  109. package/src/services/plan-template.service.ts +117 -0
  110. package/src/services/plan-validator.service.ts +84 -2
  111. package/src/services/plan-workspace.service.ts +83 -0
  112. package/src/services/playbook-registry.service.ts +67 -0
  113. package/src/services/plugin-executor.service.ts +103 -0
  114. package/src/services/quality-metrics.service.ts +132 -0
  115. package/src/services/recent-activity.service.ts +28 -34
  116. package/src/services/skill-resolver.service.ts +19 -0
  117. package/src/services/social-chat-history.service.ts +197 -0
  118. package/src/services/system-executor.service.ts +105 -0
  119. package/src/services/workstream-message.service.ts +13 -37
  120. package/src/services/workstream-plan-registry.service.ts +22 -0
  121. package/src/services/workstream-title.service.ts +3 -1
  122. package/src/services/workstream-turn-preparation.service.ts +34 -89
  123. package/src/services/workstream.service.ts +33 -55
  124. package/src/services/workstream.types.ts +9 -9
  125. package/src/services/write-intent-validator.service.ts +81 -0
  126. package/src/storage/attachment-parser.ts +1 -1
  127. package/src/storage/attachment-utils.ts +1 -1
  128. package/src/storage/generated-document-storage.service.ts +3 -2
  129. package/src/system-agents/context-compaction.agent.ts +2 -0
  130. package/src/system-agents/delegated-agent-factory.ts +5 -0
  131. package/src/system-agents/memory-reranker.agent.ts +4 -2
  132. package/src/system-agents/memory.agent.ts +2 -0
  133. package/src/system-agents/recent-activity-title-refiner.agent.ts +2 -0
  134. package/src/system-agents/regular-chat-memory-digest.agent.ts +2 -0
  135. package/src/system-agents/skill-extractor.agent.ts +2 -0
  136. package/src/system-agents/skill-manager.agent.ts +2 -0
  137. package/src/system-agents/title-generator.agent.ts +2 -0
  138. package/src/tools/execution-plan.tool.ts +17 -23
  139. package/src/tools/index.ts +0 -1
  140. package/src/tools/research-topic.tool.ts +2 -0
  141. package/src/tools/team-think.tool.ts +5 -6
  142. package/src/utils/async.ts +2 -1
  143. package/src/utils/date-time.ts +4 -32
  144. package/src/utils/env.ts +8 -0
  145. package/src/utils/errors.ts +42 -10
  146. package/src/utils/index.ts +9 -0
  147. package/src/utils/string.ts +114 -1
  148. package/src/workers/index.ts +1 -0
  149. package/src/workers/regular-chat-memory-digest.helpers.ts +1 -1
  150. package/src/workers/regular-chat-memory-digest.runner.ts +45 -12
  151. package/src/workers/skill-extraction.runner.ts +26 -6
  152. package/src/workers/utils/file-section-chunker.ts +2 -1
  153. package/src/workers/utils/repo-structure-extractor.ts +2 -2
  154. package/src/workers/utils/repomix-file-sections.ts +2 -2
  155. package/src/workers/utils/sandbox-error.ts +11 -2
  156. package/src/workers/utils/workstream-message-query.ts +14 -25
  157. package/src/workers/worker-utils.ts +2 -2
  158. package/src/runtime/workstream-routing-policy.ts +0 -267
  159. package/src/tools/log-hello-world.tool.ts +0 -17
@@ -1,17 +1,19 @@
1
+ import type { ToolSet } from 'ai'
1
2
  import { z } from 'zod'
2
3
 
3
4
  import type { CoreWorkstreamProfile } from '../config/agent-defaults'
5
+ import type { AgentFactory, AgentRuntimeConfigProvider, AgentToolBuilder } from '../config/agent-types'
4
6
  import type { LotaWorkstreamConfig, WorkstreamBootstrapWelcomeConfig } from '../config/workstream-defaults'
5
- import type { LotaPlugin } from './plugin-types'
7
+ import type { RecordIdRef } from '../db/record-id'
8
+ import type { NotificationService } from '../services/notification.service'
9
+ import { isRecord } from '../utils/string'
10
+ import type { GraphDesigner } from './graph-designer'
11
+ import type { LotaPlugin, SystemNodeExecutor } from './plugin-types'
6
12
  import type { LotaRuntimeAdapters, LotaRuntimeTurnHooks } from './runtime-extensions'
7
13
  import type { LotaRuntimeWorkerExtensions } from './runtime-worker-registry'
8
14
 
9
15
  const logLevelValues = ['trace', 'debug', 'info', 'warning', 'error', 'fatal'] as const
10
16
 
11
- type LotaAgentFactoryRegistry = Record<string, (...args: unknown[]) => unknown>
12
-
13
- const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null
14
-
15
17
  function isStringOrUrl(value: unknown): value is string | URL {
16
18
  return typeof value === 'string' || value instanceof URL
17
19
  }
@@ -24,7 +26,7 @@ function isStringRecord(value: unknown): value is Record<string, string> {
24
26
  return isRecord(value) && Object.values(value).every((entry) => typeof entry === 'string')
25
27
  }
26
28
 
27
- function isAgentFactoryRegistry(value: unknown): value is LotaAgentFactoryRegistry {
29
+ function isAgentFactoryRegistry(value: unknown): value is AgentFactory {
28
30
  return isRecord(value) && Object.values(value).every((entry) => typeof entry === 'function')
29
31
  }
30
32
 
@@ -32,10 +34,22 @@ function isPluginRuntimeRecord(value: unknown): value is Record<string, LotaPlug
32
34
  return isRecord(value)
33
35
  }
34
36
 
37
+ function isSystemExecutorRecord(value: unknown): value is Record<string, SystemNodeExecutor> {
38
+ return isRecord(value)
39
+ }
40
+
35
41
  function isToolProviderRecord(value: unknown): value is Record<string, unknown> {
36
42
  return isRecord(value)
37
43
  }
38
44
 
45
+ function isNotificationService(value: unknown): value is NotificationService {
46
+ return isRecord(value) && isFunction(value.notify) && isFunction(value.remind) && isFunction(value.escalate)
47
+ }
48
+
49
+ function isGraphDesigner(value: unknown): value is GraphDesigner {
50
+ return isRecord(value) && isFunction(value.designGraph)
51
+ }
52
+
39
53
  function isWorkerExtensionRecord(value: unknown): value is LotaRuntimeWorkerExtensions {
40
54
  if (!isRecord(value)) return false
41
55
 
@@ -49,6 +63,87 @@ function isWorkerExtensionRecord(value: unknown): value is LotaRuntimeWorkerExte
49
63
  return true
50
64
  }
51
65
 
66
+ export interface LotaSocialChatSlackConfig {
67
+ botToken?: string
68
+ signingSecret?: string
69
+ userName?: string
70
+ dedupeTtlMs?: number
71
+ }
72
+
73
+ export interface LotaSocialChatResolveContextParams {
74
+ platform: 'slack'
75
+ channelId: string
76
+ threadId: string
77
+ messageId: string
78
+ text: string
79
+ authorId?: string
80
+ authorName?: string
81
+ }
82
+
83
+ export interface LotaSocialChatResolvedContext {
84
+ workspaceId: RecordIdRef
85
+ userId: RecordIdRef
86
+ userName?: string | null
87
+ }
88
+
89
+ export interface BuildSocialChatAgentToolsParams {
90
+ agentId: string
91
+ workspaceId: RecordIdRef
92
+ workspaceIdString: string
93
+ userId: RecordIdRef
94
+ userIdString: string
95
+ userName?: string | null
96
+ platform: 'slack'
97
+ channelId: string
98
+ threadId: string
99
+ incomingMessageId: string
100
+ incomingText: string
101
+ memoryBlock: string
102
+ onAppendMemoryBlock: (value: string) => void
103
+ context?: Record<string, unknown> | null
104
+ }
105
+
106
+ export interface LotaRuntimeSocialChatConfig {
107
+ agentId?: string
108
+ agentDisplayName?: string
109
+ slack?: LotaSocialChatSlackConfig
110
+ historyRedisKeyPrefix?: string
111
+ stateRedisKeyPrefix?: string
112
+ resolveContext: (
113
+ params: LotaSocialChatResolveContextParams,
114
+ ) => LotaSocialChatResolvedContext | Promise<LotaSocialChatResolvedContext>
115
+ buildAgentTools: (params: BuildSocialChatAgentToolsParams) => ToolSet | Promise<ToolSet>
116
+ getConsultParticipants?:
117
+ | ((params: {
118
+ workspaceId: RecordIdRef
119
+ workspaceIdString: string
120
+ platform: 'slack'
121
+ }) => string[] | Promise<string[]>)
122
+ | undefined
123
+ }
124
+
125
+ function isSlackSocialChatConfig(value: unknown): value is LotaSocialChatSlackConfig {
126
+ if (!isRecord(value)) return false
127
+ if (value.botToken !== undefined && typeof value.botToken !== 'string') return false
128
+ if (value.signingSecret !== undefined && typeof value.signingSecret !== 'string') return false
129
+ if (value.userName !== undefined && typeof value.userName !== 'string') return false
130
+ if (value.dedupeTtlMs !== undefined && typeof value.dedupeTtlMs !== 'number') return false
131
+ return true
132
+ }
133
+
134
+ function isSocialChatConfig(value: unknown): value is LotaRuntimeSocialChatConfig {
135
+ if (!isRecord(value)) return false
136
+ if (value.agentId !== undefined && typeof value.agentId !== 'string') return false
137
+ if (value.agentDisplayName !== undefined && typeof value.agentDisplayName !== 'string') return false
138
+ if (value.historyRedisKeyPrefix !== undefined && typeof value.historyRedisKeyPrefix !== 'string') return false
139
+ if (value.stateRedisKeyPrefix !== undefined && typeof value.stateRedisKeyPrefix !== 'string') return false
140
+ if (value.slack !== undefined && !isSlackSocialChatConfig(value.slack)) return false
141
+ if (!isFunction(value.resolveContext)) return false
142
+ if (!isFunction(value.buildAgentTools)) return false
143
+ if (value.getConsultParticipants !== undefined && !isFunction(value.getConsultParticipants)) return false
144
+ return true
145
+ }
146
+
52
147
  const workstreamBootstrapWelcomeConfigSchema = z.object({
53
148
  directAgentId: z.string().trim().min(1),
54
149
  buildMessageText: z.custom<WorkstreamBootstrapWelcomeConfig['buildMessageText']>(isFunction, {
@@ -85,15 +180,13 @@ const agentsConfigSchema = z
85
180
  })
86
181
  .optional(),
87
182
  createAgent: z
88
- .custom<LotaAgentFactoryRegistry>(isAgentFactoryRegistry, {
89
- error: 'agents.createAgent must be a function registry',
90
- })
183
+ .custom<AgentFactory>(isAgentFactoryRegistry, { error: 'agents.createAgent must be a function registry' })
91
184
  .optional(),
92
185
  buildAgentTools: z
93
- .custom<(...args: unknown[]) => unknown>(isFunction, { error: 'agents.buildAgentTools must be a function' })
186
+ .custom<AgentToolBuilder>(isFunction, { error: 'agents.buildAgentTools must be a function' })
94
187
  .optional(),
95
188
  getAgentRuntimeConfig: z
96
- .custom<(...args: unknown[]) => unknown>(isFunction, { error: 'agents.getAgentRuntimeConfig must be a function' })
189
+ .custom<AgentRuntimeConfigProvider>(isFunction, { error: 'agents.getAgentRuntimeConfig must be a function' })
97
190
  .optional(),
98
191
  })
99
192
  .superRefine((value, ctx) => {
@@ -151,9 +244,9 @@ export const LotaRuntimeConfigSchema = z.object({
151
244
  memory: z
152
245
  .object({
153
246
  searchK: z.coerce.number().int().positive().default(6),
154
- embeddingCacheTtlSeconds: z.coerce.number().int().positive().default(3600),
247
+ embeddingCacheTtlSeconds: z.coerce.number().int().positive().default(7200),
155
248
  })
156
- .default({ searchK: 6, embeddingCacheTtlSeconds: 3600 }),
249
+ .default({ searchK: 6, embeddingCacheTtlSeconds: 7200 }),
157
250
  workstreams: workstreamConfigSchema.default({}),
158
251
  backgroundProcessing: z
159
252
  .object({
@@ -173,8 +266,12 @@ export const LotaRuntimeConfigSchema = z.object({
173
266
  extraSchemaFiles: z.array(z.custom<string | URL>(isStringOrUrl)).optional(),
174
267
  extraWorkers: z.custom<LotaRuntimeWorkerExtensions>(isWorkerExtensionRecord).optional(),
175
268
  pluginRuntime: z.custom<Record<string, LotaPlugin>>(isPluginRuntimeRecord).optional(),
269
+ systemExecutors: z.custom<Record<string, SystemNodeExecutor>>(isSystemExecutorRecord).optional(),
270
+ notificationService: z.custom<NotificationService>(isNotificationService).optional(),
176
271
  runtimeAdapters: z.custom<LotaRuntimeAdapters>(isRecord).optional(),
177
272
  turnHooks: z.custom<LotaRuntimeTurnHooks>(isRecord).optional(),
273
+ graphDesigner: z.custom<GraphDesigner>(isGraphDesigner).optional(),
274
+ socialChat: z.custom<LotaRuntimeSocialChatConfig>(isSocialChatConfig).optional(),
178
275
  })
179
276
 
180
277
  export type LotaRuntimeConfig = z.input<typeof LotaRuntimeConfigSchema>
@@ -235,4 +332,4 @@ export function parseWorkerBootstrapEnv(env: Record<string, string | undefined>)
235
332
  return WORKER_BOOTSTRAP_ENV_SCHEMA.parse(env)
236
333
  }
237
334
 
238
- export type { LotaAgentFactoryRegistry, LotaWorkstreamConfig }
335
+ export type { LotaWorkstreamConfig }
@@ -123,7 +123,6 @@ export interface ResolveAgentParams {
123
123
  onboardingActive: boolean
124
124
  linearInstalled: boolean
125
125
  githubInstalled: boolean
126
- reasoningProfile: string
127
126
  skills?: string[]
128
127
  additionalInstructionSections?: string[]
129
128
  context: Record<string, unknown> | null
@@ -224,8 +223,8 @@ export function getConfiguredPluginDatabaseConnector(): (() => Promise<void>) |
224
223
  export async function withConfiguredWorkspaceMemoryLock<T>(workspaceId: string, fn: () => Promise<T>): Promise<T> {
225
224
  const adapter = runtimeExtensionsState.adapters.workers?.withWorkspaceMemoryLock
226
225
  if (!adapter) {
227
- return await fn()
226
+ return fn()
228
227
  }
229
228
 
230
- return await adapter(workspaceId, fn)
229
+ return adapter(workspaceId, fn)
231
230
  }
@@ -1,5 +1,7 @@
1
1
  import { startContextCompactionWorker } from '../queues/context-compaction.queue'
2
+ import { startDelayedNodePromotionWorker } from '../queues/delayed-node-promotion.queue'
2
3
  import { scheduleRecurringConsolidation, startMemoryConsolidationWorker } from '../queues/memory-consolidation.queue'
4
+ import { startPlanSchedulerWorker } from '../queues/plan-scheduler.queue'
3
5
  import { startPostChatMemoryWorker } from '../queues/post-chat-memory.queue'
4
6
  import { startRecentActivityTitleRefinementWorker } from '../queues/recent-activity-title-refinement.queue'
5
7
  import { startRegularChatMemoryDigestWorker } from '../queues/regular-chat-memory-digest.queue'
@@ -8,7 +10,9 @@ import { startWorkstreamTitleGenerationWorker } from '../queues/workstream-title
8
10
 
9
11
  export interface LotaRuntimeWorkerStartRegistry {
10
12
  contextCompaction: typeof startContextCompactionWorker
13
+ delayedNodePromotion: typeof startDelayedNodePromotionWorker
11
14
  memoryConsolidation: typeof startMemoryConsolidationWorker
15
+ planScheduler: typeof startPlanSchedulerWorker
12
16
  postChatMemory: typeof startPostChatMemoryWorker
13
17
  regularChatMemoryDigest: typeof startRegularChatMemoryDigestWorker
14
18
  skillExtraction: typeof startSkillExtractionWorker
@@ -34,7 +38,9 @@ export function buildRuntimeWorkerRegistry(extraWorkers?: LotaRuntimeWorkerExten
34
38
  return {
35
39
  start: {
36
40
  contextCompaction: startContextCompactionWorker,
41
+ delayedNodePromotion: startDelayedNodePromotionWorker,
37
42
  memoryConsolidation: startMemoryConsolidationWorker,
43
+ planScheduler: startPlanSchedulerWorker,
38
44
  postChatMemory: startPostChatMemoryWorker,
39
45
  regularChatMemoryDigest: startRegularChatMemoryDigestWorker,
40
46
  skillExtraction: startSkillExtractionWorker,