@lota-sdk/core 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/infrastructure/schema/00_identity.surql +0 -2
- package/infrastructure/schema/01_memory.surql +1 -1
- package/infrastructure/schema/02_execution_plan.surql +62 -1
- package/infrastructure/schema/03_learned_skill.surql +1 -1
- package/infrastructure/schema/06_playbook.surql +25 -0
- package/infrastructure/schema/07_institutional_memory.surql +13 -0
- package/infrastructure/schema/08_quality_metrics.surql +17 -0
- package/package.json +9 -8
- package/src/ai/definitions.ts +80 -2
- package/src/ai/embedding-cache.ts +7 -6
- package/src/ai/index.ts +0 -1
- package/src/bifrost/bifrost.ts +14 -14
- package/src/config/agent-defaults.ts +32 -22
- package/src/config/agent-types.ts +11 -0
- package/src/config/constants.ts +2 -14
- package/src/config/debug-logger.ts +5 -1
- package/src/config/index.ts +3 -0
- package/src/config/logger.ts +7 -9
- package/src/config/model-constants.ts +16 -34
- package/src/config/search.ts +1 -15
- package/src/create-runtime.ts +453 -0
- package/src/db/cursor-pagination.ts +3 -6
- package/src/db/index.ts +2 -0
- package/src/db/memory-store.rows.ts +7 -7
- package/src/db/memory-store.ts +24 -24
- package/src/db/memory.ts +18 -16
- package/src/db/schema-fingerprint.ts +1 -0
- package/src/db/service.ts +193 -122
- package/src/db/startup.ts +9 -13
- package/src/db/surreal-mutation.ts +43 -0
- package/src/db/tables.ts +7 -0
- package/src/db/workstream-message-row.ts +15 -0
- package/src/embeddings/provider.ts +1 -1
- package/src/index.ts +1 -1
- package/src/queues/context-compaction.queue.ts +17 -52
- package/src/queues/delayed-node-promotion.queue.ts +41 -0
- package/src/queues/document-processor.queue.ts +7 -7
- package/src/queues/index.ts +3 -0
- package/src/queues/memory-consolidation.queue.ts +18 -54
- package/src/queues/plan-scheduler.queue.ts +97 -0
- package/src/queues/post-chat-memory.queue.ts +15 -60
- package/src/queues/queue-factory.ts +100 -0
- package/src/queues/recent-activity-title-refinement.queue.ts +15 -54
- package/src/queues/regular-chat-memory-digest.queue.ts +16 -55
- package/src/queues/skill-extraction.queue.ts +15 -50
- package/src/queues/workstream-title-generation.queue.ts +15 -51
- package/src/redis/connection.ts +12 -3
- package/src/redis/index.ts +2 -1
- package/src/redis/org-memory-lock.ts +1 -1
- package/src/redis/redis-lease-lock.ts +41 -8
- package/src/redis/stream-context.ts +11 -0
- package/src/runtime/agent-runtime-policy.ts +106 -21
- package/src/runtime/agent-stream-helpers.ts +2 -1
- package/src/runtime/approval-continuation.ts +12 -6
- package/src/runtime/context-compaction-constants.ts +1 -1
- package/src/runtime/context-compaction-runtime.ts +7 -5
- package/src/runtime/context-compaction.ts +40 -97
- package/src/runtime/execution-plan.ts +23 -19
- package/src/runtime/graph-designer.ts +15 -0
- package/src/runtime/helper-model.ts +10 -196
- package/src/runtime/index.ts +14 -1
- package/src/runtime/llm-content.ts +1 -1
- package/src/runtime/memory-block.ts +11 -12
- package/src/runtime/memory-pipeline.ts +26 -10
- package/src/runtime/plugin-resolution.ts +35 -0
- package/src/runtime/plugin-types.ts +73 -1
- package/src/runtime/retrieval-adapters.ts +1 -1
- package/src/runtime/runtime-config.ts +25 -12
- package/src/runtime/runtime-extensions.ts +91 -15
- package/src/runtime/runtime-worker-registry.ts +6 -0
- package/src/runtime/team-consultation-orchestrator.ts +45 -28
- package/src/runtime/team-consultation-prompts.ts +11 -2
- package/src/runtime/title-helpers.ts +11 -4
- package/src/runtime/workstream-chat-helpers.ts +6 -7
- package/src/runtime/workstream-routing-policy.ts +0 -30
- package/src/runtime/workstream-state.ts +17 -7
- package/src/services/adaptive-playbook.service.ts +152 -0
- package/src/services/agent-executor.service.ts +293 -0
- package/src/services/artifact-provenance.service.ts +172 -0
- package/src/services/attachment.service.ts +7 -12
- package/src/services/context-compaction.service.ts +75 -58
- package/src/services/context-enrichment.service.ts +33 -0
- package/src/services/coordination-registry.service.ts +117 -0
- package/src/services/document-chunk.service.ts +38 -33
- package/src/services/domain-agent-executor.service.ts +71 -0
- package/src/services/execution-plan.service.ts +271 -50
- package/src/services/feedback-loop.service.ts +96 -0
- package/src/services/global-orchestrator.service.ts +148 -0
- package/src/services/index.ts +26 -0
- package/src/services/institutional-memory.service.ts +145 -0
- package/src/services/learned-skill.service.ts +30 -15
- package/src/services/memory-assessment.service.ts +3 -2
- package/src/services/{memory.utils.ts → memory-utils.ts} +4 -13
- package/src/services/memory.service.ts +55 -69
- package/src/services/monitoring-window.service.ts +86 -0
- package/src/services/mutating-approval.service.ts +1 -1
- package/src/services/node-workspace.service.ts +155 -0
- package/src/services/notification.service.ts +39 -0
- package/src/services/organization-member.service.ts +12 -5
- package/src/services/organization.service.ts +5 -5
- package/src/services/ownership-dispatcher.service.ts +403 -0
- package/src/services/plan-approval.service.ts +1 -1
- package/src/services/plan-artifact.service.ts +1 -0
- package/src/services/plan-builder.service.ts +1 -0
- package/src/services/plan-checkpoint.service.ts +30 -2
- package/src/services/plan-compiler.service.ts +5 -0
- package/src/services/plan-coordination.service.ts +152 -0
- package/src/services/plan-cycle.service.ts +284 -0
- package/src/services/plan-deadline.service.ts +287 -0
- package/src/services/plan-executor.service.ts +386 -58
- package/src/services/plan-helpers.ts +15 -0
- package/src/services/plan-run.service.ts +41 -7
- package/src/services/plan-scheduler.service.ts +240 -0
- package/src/services/plan-template.service.ts +117 -0
- package/src/services/plan-validator.service.ts +87 -20
- package/src/services/plan-workspace.service.ts +83 -0
- package/src/services/playbook-registry.service.ts +67 -0
- package/src/services/plugin-executor.service.ts +103 -0
- package/src/services/quality-metrics.service.ts +132 -0
- package/src/services/recent-activity-title.service.ts +3 -10
- package/src/services/recent-activity.service.ts +33 -43
- package/src/services/skill-resolver.service.ts +19 -0
- package/src/services/system-executor.service.ts +105 -0
- package/src/services/workstream-message.service.ts +29 -41
- package/src/services/workstream-plan-registry.service.ts +22 -0
- package/src/services/workstream-title.service.ts +3 -9
- package/src/services/{workstream-turn-preparation.ts → workstream-turn-preparation.service.ts} +428 -373
- package/src/services/workstream-turn.ts +2 -2
- package/src/services/workstream.service.ts +55 -65
- package/src/services/workstream.types.ts +10 -19
- package/src/services/write-intent-validator.service.ts +81 -0
- package/src/storage/attachment-parser.ts +1 -1
- package/src/storage/attachment-storage.service.ts +4 -4
- package/src/storage/{attachments.utils.ts → attachment-utils.ts} +2 -5
- package/src/storage/generated-document-storage.service.ts +3 -2
- package/src/storage/index.ts +2 -2
- package/src/system-agents/{context-compacter.agent.ts → context-compaction.agent.ts} +4 -4
- package/src/system-agents/delegated-agent-factory.ts +5 -2
- package/src/system-agents/index.ts +8 -0
- package/src/system-agents/memory-reranker.agent.ts +1 -1
- package/src/system-agents/memory.agent.ts +1 -1
- package/src/system-agents/recent-activity-title-refiner.agent.ts +1 -1
- package/src/tools/execution-plan.tool.ts +17 -19
- package/src/tools/fetch-webpage.tool.ts +20 -18
- package/src/tools/index.ts +2 -3
- package/src/tools/read-file-parts.tool.ts +1 -1
- package/src/tools/search-web.tool.ts +18 -15
- package/src/tools/{search-tools.ts → search.tool.ts} +1 -1
- package/src/tools/team-think.tool.ts +14 -8
- package/src/tools/{tool-contract.ts → tool-contracts.ts} +9 -2
- package/src/utils/async.ts +3 -2
- package/src/utils/date-time.ts +4 -32
- package/src/utils/env.ts +8 -0
- package/src/utils/errors.ts +47 -0
- package/src/utils/hono-error-handler.ts +1 -2
- package/src/utils/index.ts +19 -2
- package/src/utils/string.ts +128 -1
- package/src/workers/bootstrap.ts +2 -2
- package/src/workers/index.ts +1 -0
- package/src/workers/memory-consolidation.worker.ts +12 -12
- package/src/workers/regular-chat-memory-digest.helpers.ts +2 -7
- package/src/workers/regular-chat-memory-digest.runner.ts +11 -105
- package/src/workers/skill-extraction.runner.ts +8 -102
- package/src/workers/utils/file-section-chunker.ts +6 -3
- package/src/workers/utils/repomix-file-sections.ts +2 -2
- package/src/workers/utils/sandbox-error.ts +11 -2
- package/src/workers/utils/workstream-message-query.ts +97 -0
- package/src/workers/worker-utils.ts +6 -2
- package/src/runtime/retrieval-pipeline.ts +0 -3
- package/src/runtime.ts +0 -387
- package/src/tools/log-hello-world.tool.ts +0 -17
- package/src/utils/error.ts +0 -10
- /package/src/services/{context-compaction-runtime.ts → context-compaction-runtime.singleton.ts} +0 -0
- /package/src/storage/{attachments.types.ts → attachment-types.ts} +0 -0
package/src/runtime.ts
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { configureEmbeddingCache } from './ai/embedding-cache'
|
|
2
|
-
import { configureAgentFactory, configureAgents } from './config/agent-defaults'
|
|
3
|
-
import { configureBackgroundProcessing } from './config/background-processing'
|
|
4
|
-
import { configureLogger } from './config/logger'
|
|
5
|
-
import { configureWorkstreams } from './config/workstream-defaults'
|
|
6
|
-
import { ensureRecordId } from './db/record-id'
|
|
7
|
-
import { computeSchemaFingerprint } from './db/schema-fingerprint'
|
|
8
|
-
import { LOTA_SDK_DATABASE_NAME } from './db/sdk-database'
|
|
9
|
-
import type { SurrealDBService } from './db/service'
|
|
10
|
-
import { SurrealDBService as SurrealDBServiceClass, setDatabaseService } from './db/service'
|
|
11
|
-
import { publishDatabaseBootstrap } from './db/startup'
|
|
12
|
-
import { TABLES } from './db/tables'
|
|
13
|
-
import type { RedisConnectionManager } from './redis/connection'
|
|
14
|
-
import { createRedisConnectionManager } from './redis/connection'
|
|
15
|
-
import { setRedisConnectionManager } from './redis/index'
|
|
16
|
-
import type { isApprovalContinuationRequest } from './runtime/approval-continuation'
|
|
17
|
-
import { routeWorkstreamChatMessages } from './runtime/chat-request-routing'
|
|
18
|
-
import type { LotaPlugin } from './runtime/plugin-types'
|
|
19
|
-
import { configureRuntimeConfig, LOTA_RUNTIME_ENV_KEYS, parseLotaRuntimeConfig } from './runtime/runtime-config'
|
|
20
|
-
import type { LotaRuntimeConfig, ResolvedLotaRuntimeConfig } from './runtime/runtime-config'
|
|
21
|
-
import { configureRuntimeExtensions } from './runtime/runtime-extensions'
|
|
22
|
-
import type { LotaRuntimeWorkers } from './runtime/runtime-worker-registry'
|
|
23
|
-
import { buildRuntimeWorkerRegistry } from './runtime/runtime-worker-registry'
|
|
24
|
-
import type { attachmentService } from './services/attachment.service'
|
|
25
|
-
import { attachmentService as attachmentServiceSingleton } from './services/attachment.service'
|
|
26
|
-
import type { documentChunkService } from './services/document-chunk.service'
|
|
27
|
-
import { documentChunkService as documentChunkServiceSingleton } from './services/document-chunk.service'
|
|
28
|
-
import type { executionPlanService } from './services/execution-plan.service'
|
|
29
|
-
import { executionPlanService as executionPlanServiceSingleton } from './services/execution-plan.service'
|
|
30
|
-
import type { memoryService } from './services/memory.service'
|
|
31
|
-
import { memoryService as memoryServiceSingleton } from './services/memory.service'
|
|
32
|
-
import type { verifyMutatingApproval } from './services/mutating-approval.service'
|
|
33
|
-
import { verifyMutatingApproval as verifyMutatingApprovalSingleton } from './services/mutating-approval.service'
|
|
34
|
-
import type { organizationMemberService } from './services/organization-member.service'
|
|
35
|
-
import { organizationMemberService as organizationMemberServiceSingleton } from './services/organization-member.service'
|
|
36
|
-
import type { organizationService } from './services/organization.service'
|
|
37
|
-
import { organizationService as organizationServiceSingleton } from './services/organization.service'
|
|
38
|
-
import type { recentActivityTitleService } from './services/recent-activity-title.service'
|
|
39
|
-
import { recentActivityTitleService as recentActivityTitleServiceSingleton } from './services/recent-activity-title.service'
|
|
40
|
-
import type { recentActivityService } from './services/recent-activity.service'
|
|
41
|
-
import { recentActivityService as recentActivityServiceSingleton } from './services/recent-activity.service'
|
|
42
|
-
import type { userService } from './services/user.service'
|
|
43
|
-
import { userService as userServiceSingleton } from './services/user.service'
|
|
44
|
-
import type { workstreamMessageService } from './services/workstream-message.service'
|
|
45
|
-
import { workstreamMessageService as workstreamMessageServiceSingleton } from './services/workstream-message.service'
|
|
46
|
-
import type { workstreamTitleService } from './services/workstream-title.service'
|
|
47
|
-
import { workstreamTitleService as workstreamTitleServiceSingleton } from './services/workstream-title.service'
|
|
48
|
-
import type {
|
|
49
|
-
createWorkstreamApprovalContinuationStream,
|
|
50
|
-
createWorkstreamNativeToolApprovalStream,
|
|
51
|
-
createWorkstreamTurnStream,
|
|
52
|
-
runWorkstreamTurnInBackground,
|
|
53
|
-
} from './services/workstream-turn'
|
|
54
|
-
import {
|
|
55
|
-
createWorkstreamApprovalContinuationStream as createWorkstreamApprovalContinuationStreamSingleton,
|
|
56
|
-
createWorkstreamNativeToolApprovalStream as createWorkstreamNativeToolApprovalStreamSingleton,
|
|
57
|
-
createWorkstreamTurnStream as createWorkstreamTurnStreamSingleton,
|
|
58
|
-
isApprovalContinuationRequest as isApprovalContinuationRequestSingleton,
|
|
59
|
-
runWorkstreamTurnInBackground as runWorkstreamTurnInBackgroundSingleton,
|
|
60
|
-
} from './services/workstream-turn'
|
|
61
|
-
import type { workstreamService } from './services/workstream.service'
|
|
62
|
-
import { workstreamService as workstreamServiceSingleton } from './services/workstream.service'
|
|
63
|
-
import type { generatedDocumentStorageService } from './storage/generated-document-storage.service'
|
|
64
|
-
import { generatedDocumentStorageService as generatedDocumentStorageServiceSingleton } from './storage/generated-document-storage.service'
|
|
65
|
-
|
|
66
|
-
type ArchiveSdkWorkstream = (
|
|
67
|
-
workstreamId: Parameters<typeof workstreamServiceSingleton.updateStatus>[0],
|
|
68
|
-
status?: 'archived',
|
|
69
|
-
) => ReturnType<typeof workstreamServiceSingleton.updateStatus>
|
|
70
|
-
|
|
71
|
-
type UnarchiveSdkWorkstream = (
|
|
72
|
-
workstreamId: Parameters<typeof workstreamServiceSingleton.updateStatus>[0],
|
|
73
|
-
status?: 'regular',
|
|
74
|
-
) => ReturnType<typeof workstreamServiceSingleton.updateStatus>
|
|
75
|
-
|
|
76
|
-
export interface LotaRuntime {
|
|
77
|
-
services: {
|
|
78
|
-
database: SurrealDBService
|
|
79
|
-
databaseService: SurrealDBService
|
|
80
|
-
redis: RedisConnectionManager
|
|
81
|
-
closeRedisConnection: () => Promise<void>
|
|
82
|
-
attachmentService: typeof attachmentService
|
|
83
|
-
documentChunkService: typeof documentChunkService
|
|
84
|
-
generatedDocumentStorageService: typeof generatedDocumentStorageService
|
|
85
|
-
memoryService: typeof memoryService
|
|
86
|
-
verifyMutatingApproval: typeof verifyMutatingApproval
|
|
87
|
-
organizationService: typeof organizationService
|
|
88
|
-
organizationMemberService: typeof organizationMemberService
|
|
89
|
-
userService: typeof userService
|
|
90
|
-
recentActivityService: typeof recentActivityService
|
|
91
|
-
recentActivityTitleService: typeof recentActivityTitleService
|
|
92
|
-
executionPlanService: typeof executionPlanService
|
|
93
|
-
workstreamMessageService: typeof workstreamMessageService
|
|
94
|
-
workstreamService: typeof workstreamService
|
|
95
|
-
workstreamTitleService: typeof workstreamTitleService
|
|
96
|
-
createWorkstreamApprovalContinuationStream: typeof createWorkstreamApprovalContinuationStream
|
|
97
|
-
createWorkstreamNativeToolApprovalStream: typeof createWorkstreamNativeToolApprovalStream
|
|
98
|
-
createWorkstreamTurnStream: typeof createWorkstreamTurnStream
|
|
99
|
-
isApprovalContinuationRequest: typeof isApprovalContinuationRequest
|
|
100
|
-
runWorkstreamTurnInBackground: typeof runWorkstreamTurnInBackground
|
|
101
|
-
}
|
|
102
|
-
lota: {
|
|
103
|
-
organizations: {
|
|
104
|
-
create: typeof organizationServiceSingleton.createOrganization
|
|
105
|
-
upsert: typeof organizationServiceSingleton.upsertOrganization
|
|
106
|
-
get: typeof organizationServiceSingleton.getOrganization
|
|
107
|
-
list: typeof organizationServiceSingleton.listOrganizations
|
|
108
|
-
update: typeof organizationServiceSingleton.updateOrganization
|
|
109
|
-
delete: typeof organizationServiceSingleton.deleteOrganization
|
|
110
|
-
}
|
|
111
|
-
users: {
|
|
112
|
-
upsert: typeof userServiceSingleton.upsertUser
|
|
113
|
-
get: typeof userServiceSingleton.getUser
|
|
114
|
-
list: typeof userServiceSingleton.listUsers
|
|
115
|
-
update: typeof userServiceSingleton.updateUser
|
|
116
|
-
delete: typeof userServiceSingleton.deleteUser
|
|
117
|
-
}
|
|
118
|
-
memberships: {
|
|
119
|
-
add: typeof organizationMemberServiceSingleton.addMembership
|
|
120
|
-
listForOrganization: typeof organizationMemberServiceSingleton.listMembershipsForOrganization
|
|
121
|
-
listForUser: typeof organizationMemberServiceSingleton.listMembershipsForUser
|
|
122
|
-
remove: typeof organizationMemberServiceSingleton.removeMembership
|
|
123
|
-
isMember: typeof organizationMemberServiceSingleton.isMember
|
|
124
|
-
}
|
|
125
|
-
workstreams: {
|
|
126
|
-
create: typeof workstreamServiceSingleton.createWorkstream
|
|
127
|
-
list: typeof workstreamServiceSingleton.listWorkstreams
|
|
128
|
-
get: typeof workstreamServiceSingleton.getWorkstream
|
|
129
|
-
update: typeof workstreamServiceSingleton.updateTitle
|
|
130
|
-
archive: ArchiveSdkWorkstream
|
|
131
|
-
unarchive: UnarchiveSdkWorkstream
|
|
132
|
-
delete: typeof workstreamServiceSingleton.deleteWorkstream
|
|
133
|
-
stop: typeof workstreamServiceSingleton.stopActiveRun
|
|
134
|
-
listMessages: typeof workstreamMessageServiceSingleton.listMessageHistoryPage
|
|
135
|
-
getMessage: (params: { workstreamId: string; messageId: string }) => Promise<unknown>
|
|
136
|
-
sendMessage: (params: {
|
|
137
|
-
workstreamId: string
|
|
138
|
-
organizationId: string
|
|
139
|
-
userId: string
|
|
140
|
-
userName: string
|
|
141
|
-
messages: Parameters<typeof routeWorkstreamChatMessages>[0]
|
|
142
|
-
}) => Promise<Awaited<ReturnType<typeof createWorkstreamTurnStream>>>
|
|
143
|
-
continueApproval: (params: {
|
|
144
|
-
workstreamId: string
|
|
145
|
-
organizationId: string
|
|
146
|
-
userId: string
|
|
147
|
-
userName: string
|
|
148
|
-
messages: Parameters<typeof routeWorkstreamChatMessages>[0]
|
|
149
|
-
}) => Promise<Awaited<ReturnType<typeof createWorkstreamApprovalContinuationStream>>>
|
|
150
|
-
uploadAttachment: typeof attachmentServiceSingleton.uploadWorkstreamAttachment
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
redis: {
|
|
154
|
-
manager: RedisConnectionManager
|
|
155
|
-
getConnection: () => ReturnType<RedisConnectionManager['getConnection']>
|
|
156
|
-
getConnectionForBullMQ: () => ReturnType<RedisConnectionManager['getConnectionForBullMQ']>
|
|
157
|
-
closeConnection: () => Promise<void>
|
|
158
|
-
}
|
|
159
|
-
workers: LotaRuntimeWorkers
|
|
160
|
-
schemaFiles: Array<string | URL>
|
|
161
|
-
contributions: { envKeys: readonly string[]; schemaFiles: Array<string | URL> }
|
|
162
|
-
config: ResolvedLotaRuntimeConfig
|
|
163
|
-
plugins: Record<string, LotaPlugin>
|
|
164
|
-
connectPluginDatabases(): Promise<void>
|
|
165
|
-
connect(): Promise<void>
|
|
166
|
-
disconnect(): Promise<void>
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export async function createLotaRuntime(config: LotaRuntimeConfig): Promise<LotaRuntime> {
|
|
170
|
-
const resolvedConfig = parseLotaRuntimeConfig(config)
|
|
171
|
-
configureRuntimeConfig(resolvedConfig)
|
|
172
|
-
|
|
173
|
-
await configureLogger(resolvedConfig.logging.level)
|
|
174
|
-
|
|
175
|
-
const db = new SurrealDBServiceClass({
|
|
176
|
-
url: resolvedConfig.database.url,
|
|
177
|
-
namespace: resolvedConfig.database.namespace,
|
|
178
|
-
database: LOTA_SDK_DATABASE_NAME,
|
|
179
|
-
username: resolvedConfig.database.username,
|
|
180
|
-
password: resolvedConfig.database.password,
|
|
181
|
-
})
|
|
182
|
-
setDatabaseService(db)
|
|
183
|
-
|
|
184
|
-
const redisManager = createRedisConnectionManager({ url: resolvedConfig.redis.url })
|
|
185
|
-
setRedisConnectionManager(redisManager)
|
|
186
|
-
configureEmbeddingCache(redisManager.getConnection(), resolvedConfig.memory.embeddingCacheTtlSeconds)
|
|
187
|
-
configureBackgroundProcessing(resolvedConfig.backgroundProcessing)
|
|
188
|
-
|
|
189
|
-
configureAgents({
|
|
190
|
-
roster: resolvedConfig.agents.roster,
|
|
191
|
-
leadAgentId: resolvedConfig.agents.leadAgentId,
|
|
192
|
-
displayNames: resolvedConfig.agents.displayNames,
|
|
193
|
-
shortDisplayNames: resolvedConfig.agents.shortDisplayNames,
|
|
194
|
-
teamConsultParticipants: resolvedConfig.agents.teamConsultParticipants,
|
|
195
|
-
getCoreWorkstreamProfile: resolvedConfig.agents.getCoreWorkstreamProfile,
|
|
196
|
-
})
|
|
197
|
-
configureAgentFactory({
|
|
198
|
-
createAgent: resolvedConfig.agents.createAgent,
|
|
199
|
-
buildAgentTools: resolvedConfig.agents.buildAgentTools,
|
|
200
|
-
getAgentRuntimeConfig: resolvedConfig.agents.getAgentRuntimeConfig,
|
|
201
|
-
pluginRuntime: resolvedConfig.pluginRuntime,
|
|
202
|
-
})
|
|
203
|
-
configureWorkstreams({ agentRoster: resolvedConfig.agents.roster, config: resolvedConfig.workstreams })
|
|
204
|
-
configureRuntimeExtensions({
|
|
205
|
-
adapters: resolvedConfig.runtimeAdapters,
|
|
206
|
-
turnHooks: resolvedConfig.turnHooks,
|
|
207
|
-
toolProviders: (resolvedConfig.toolProviders ?? {}) as never,
|
|
208
|
-
extraWorkers: resolvedConfig.extraWorkers,
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
const pluginRuntime = resolvedConfig.pluginRuntime ?? {}
|
|
212
|
-
const pluginContributions = Object.values(pluginRuntime).map((plugin) => plugin.contributions)
|
|
213
|
-
const schemaFiles = [...getBuiltInSchemaFiles(), ...(resolvedConfig.extraSchemaFiles ?? [])]
|
|
214
|
-
const hostContributionSchemaFiles = pluginContributions.flatMap((plugin) => plugin.schemaFiles)
|
|
215
|
-
const contributionEnvKeys = [...LOTA_RUNTIME_ENV_KEYS, ...pluginContributions.flatMap((plugin) => plugin.envKeys)]
|
|
216
|
-
const connectPluginDatabases = createPluginDatabaseConnector(pluginRuntime)
|
|
217
|
-
const workers = buildRuntimeWorkerRegistry(resolvedConfig.extraWorkers)
|
|
218
|
-
|
|
219
|
-
const lota = {
|
|
220
|
-
organizations: {
|
|
221
|
-
create: organizationServiceSingleton.createOrganization.bind(organizationServiceSingleton),
|
|
222
|
-
upsert: organizationServiceSingleton.upsertOrganization.bind(organizationServiceSingleton),
|
|
223
|
-
get: organizationServiceSingleton.getOrganization.bind(organizationServiceSingleton),
|
|
224
|
-
list: organizationServiceSingleton.listOrganizations.bind(organizationServiceSingleton),
|
|
225
|
-
update: organizationServiceSingleton.updateOrganization.bind(organizationServiceSingleton),
|
|
226
|
-
delete: organizationServiceSingleton.deleteOrganization.bind(organizationServiceSingleton),
|
|
227
|
-
},
|
|
228
|
-
users: {
|
|
229
|
-
upsert: userServiceSingleton.upsertUser.bind(userServiceSingleton),
|
|
230
|
-
get: userServiceSingleton.getUser.bind(userServiceSingleton),
|
|
231
|
-
list: userServiceSingleton.listUsers.bind(userServiceSingleton),
|
|
232
|
-
update: userServiceSingleton.updateUser.bind(userServiceSingleton),
|
|
233
|
-
delete: userServiceSingleton.deleteUser.bind(userServiceSingleton),
|
|
234
|
-
},
|
|
235
|
-
memberships: {
|
|
236
|
-
add: organizationMemberServiceSingleton.addMembership.bind(organizationMemberServiceSingleton),
|
|
237
|
-
listForOrganization: organizationMemberServiceSingleton.listMembershipsForOrganization.bind(
|
|
238
|
-
organizationMemberServiceSingleton,
|
|
239
|
-
),
|
|
240
|
-
listForUser: organizationMemberServiceSingleton.listMembershipsForUser.bind(organizationMemberServiceSingleton),
|
|
241
|
-
remove: organizationMemberServiceSingleton.removeMembership.bind(organizationMemberServiceSingleton),
|
|
242
|
-
isMember: organizationMemberServiceSingleton.isMember.bind(organizationMemberServiceSingleton),
|
|
243
|
-
},
|
|
244
|
-
workstreams: {
|
|
245
|
-
create: workstreamServiceSingleton.createWorkstream.bind(workstreamServiceSingleton),
|
|
246
|
-
list: workstreamServiceSingleton.listWorkstreams.bind(workstreamServiceSingleton),
|
|
247
|
-
get: workstreamServiceSingleton.getWorkstream.bind(workstreamServiceSingleton),
|
|
248
|
-
update: workstreamServiceSingleton.updateTitle.bind(workstreamServiceSingleton),
|
|
249
|
-
archive: async (workstreamId, status = 'archived') =>
|
|
250
|
-
await workstreamServiceSingleton.updateStatus(workstreamId, status),
|
|
251
|
-
unarchive: async (workstreamId, status = 'regular') =>
|
|
252
|
-
await workstreamServiceSingleton.updateStatus(workstreamId, status),
|
|
253
|
-
delete: workstreamServiceSingleton.deleteWorkstream.bind(workstreamServiceSingleton),
|
|
254
|
-
stop: workstreamServiceSingleton.stopActiveRun.bind(workstreamServiceSingleton),
|
|
255
|
-
listMessages: workstreamMessageServiceSingleton.listMessageHistoryPage.bind(workstreamMessageServiceSingleton),
|
|
256
|
-
getMessage: async ({ workstreamId, messageId }) => {
|
|
257
|
-
const messages = await workstreamMessageServiceSingleton.listMessages(
|
|
258
|
-
ensureRecordId(workstreamId, TABLES.WORKSTREAM),
|
|
259
|
-
)
|
|
260
|
-
const message = messages.find((candidate) => candidate.id === messageId)
|
|
261
|
-
if (!message) {
|
|
262
|
-
throw new Error(`Workstream message not found: ${messageId}`)
|
|
263
|
-
}
|
|
264
|
-
return message
|
|
265
|
-
},
|
|
266
|
-
sendMessage: async ({ workstreamId, organizationId, userId, userName, messages }) => {
|
|
267
|
-
const workstreamRef = ensureRecordId(workstreamId, TABLES.WORKSTREAM)
|
|
268
|
-
const workstream = await workstreamServiceSingleton.getWorkstream(workstreamRef)
|
|
269
|
-
const routed = routeWorkstreamChatMessages(messages)
|
|
270
|
-
if (routed.kind !== 'turn') {
|
|
271
|
-
throw new Error(routed.kind === 'invalid' ? routed.message : 'Expected a user turn payload.')
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return await createWorkstreamTurnStreamSingleton({
|
|
275
|
-
workstream,
|
|
276
|
-
workstreamRef,
|
|
277
|
-
orgRef: ensureRecordId(organizationId, TABLES.ORGANIZATION),
|
|
278
|
-
userRef: ensureRecordId(userId, TABLES.USER),
|
|
279
|
-
userName,
|
|
280
|
-
inputMessage: routed.inputMessage,
|
|
281
|
-
})
|
|
282
|
-
},
|
|
283
|
-
continueApproval: async ({ workstreamId, organizationId, userId, userName, messages }) => {
|
|
284
|
-
const workstreamRef = ensureRecordId(workstreamId, TABLES.WORKSTREAM)
|
|
285
|
-
const workstream = await workstreamServiceSingleton.getWorkstream(workstreamRef)
|
|
286
|
-
const routed = routeWorkstreamChatMessages(messages)
|
|
287
|
-
if (routed.kind !== 'approval-continuation') {
|
|
288
|
-
throw new Error(
|
|
289
|
-
routed.kind === 'invalid' ? routed.message : 'Expected approval continuation messages payload.',
|
|
290
|
-
)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return await createWorkstreamApprovalContinuationStreamSingleton({
|
|
294
|
-
workstream,
|
|
295
|
-
workstreamRef,
|
|
296
|
-
orgRef: ensureRecordId(organizationId, TABLES.ORGANIZATION),
|
|
297
|
-
userRef: ensureRecordId(userId, TABLES.USER),
|
|
298
|
-
userName,
|
|
299
|
-
approvalMessages: routed.approvalMessages,
|
|
300
|
-
})
|
|
301
|
-
},
|
|
302
|
-
uploadAttachment: attachmentServiceSingleton.uploadWorkstreamAttachment.bind(attachmentServiceSingleton),
|
|
303
|
-
},
|
|
304
|
-
} satisfies LotaRuntime['lota']
|
|
305
|
-
|
|
306
|
-
return {
|
|
307
|
-
services: {
|
|
308
|
-
database: db,
|
|
309
|
-
databaseService: db,
|
|
310
|
-
redis: redisManager,
|
|
311
|
-
closeRedisConnection: async () => await redisManager.closeConnection(),
|
|
312
|
-
attachmentService: attachmentServiceSingleton,
|
|
313
|
-
documentChunkService: documentChunkServiceSingleton,
|
|
314
|
-
generatedDocumentStorageService: generatedDocumentStorageServiceSingleton,
|
|
315
|
-
memoryService: memoryServiceSingleton,
|
|
316
|
-
verifyMutatingApproval: verifyMutatingApprovalSingleton,
|
|
317
|
-
organizationService: organizationServiceSingleton,
|
|
318
|
-
organizationMemberService: organizationMemberServiceSingleton,
|
|
319
|
-
userService: userServiceSingleton,
|
|
320
|
-
recentActivityService: recentActivityServiceSingleton,
|
|
321
|
-
recentActivityTitleService: recentActivityTitleServiceSingleton,
|
|
322
|
-
executionPlanService: executionPlanServiceSingleton,
|
|
323
|
-
workstreamMessageService: workstreamMessageServiceSingleton,
|
|
324
|
-
workstreamService: workstreamServiceSingleton,
|
|
325
|
-
workstreamTitleService: workstreamTitleServiceSingleton,
|
|
326
|
-
createWorkstreamApprovalContinuationStream: createWorkstreamApprovalContinuationStreamSingleton,
|
|
327
|
-
createWorkstreamNativeToolApprovalStream: createWorkstreamNativeToolApprovalStreamSingleton,
|
|
328
|
-
createWorkstreamTurnStream: createWorkstreamTurnStreamSingleton,
|
|
329
|
-
isApprovalContinuationRequest: isApprovalContinuationRequestSingleton,
|
|
330
|
-
runWorkstreamTurnInBackground: runWorkstreamTurnInBackgroundSingleton,
|
|
331
|
-
},
|
|
332
|
-
lota,
|
|
333
|
-
redis: {
|
|
334
|
-
manager: redisManager,
|
|
335
|
-
getConnection: () => redisManager.getConnection(),
|
|
336
|
-
getConnectionForBullMQ: () => redisManager.getConnectionForBullMQ(),
|
|
337
|
-
closeConnection: async () => await redisManager.closeConnection(),
|
|
338
|
-
},
|
|
339
|
-
workers,
|
|
340
|
-
schemaFiles,
|
|
341
|
-
contributions: { envKeys: [...new Set(contributionEnvKeys)], schemaFiles: hostContributionSchemaFiles },
|
|
342
|
-
config: resolvedConfig,
|
|
343
|
-
plugins: pluginRuntime,
|
|
344
|
-
async connectPluginDatabases() {
|
|
345
|
-
await connectPluginDatabases()
|
|
346
|
-
},
|
|
347
|
-
async connect() {
|
|
348
|
-
await db.connect()
|
|
349
|
-
const bunFiles = schemaFiles.map((schemaFile) =>
|
|
350
|
-
schemaFile instanceof URL ? Bun.file(schemaFile.pathname) : Bun.file(schemaFile),
|
|
351
|
-
)
|
|
352
|
-
await db.applySchemaAndMigrations(bunFiles)
|
|
353
|
-
const schemaFingerprint = await computeSchemaFingerprint(schemaFiles)
|
|
354
|
-
await publishDatabaseBootstrap({ databaseService: db, schemaFingerprint })
|
|
355
|
-
},
|
|
356
|
-
async disconnect() {
|
|
357
|
-
await db.disconnect()
|
|
358
|
-
await redisManager.closeConnection()
|
|
359
|
-
},
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function getBuiltInSchemaFiles(): URL[] {
|
|
364
|
-
return [
|
|
365
|
-
new URL('../infrastructure/schema/00_identity.surql', import.meta.url),
|
|
366
|
-
new URL('../infrastructure/schema/00_workstream.surql', import.meta.url),
|
|
367
|
-
new URL('../infrastructure/schema/01_memory.surql', import.meta.url),
|
|
368
|
-
new URL('../infrastructure/schema/02_execution_plan.surql', import.meta.url),
|
|
369
|
-
new URL('../infrastructure/schema/03_learned_skill.surql', import.meta.url),
|
|
370
|
-
new URL('../infrastructure/schema/05_recent_activity.surql', import.meta.url),
|
|
371
|
-
new URL('../infrastructure/schema/04_runtime_bootstrap.surql', import.meta.url),
|
|
372
|
-
]
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function createPluginDatabaseConnector(pluginRuntime: Record<string, LotaPlugin>): () => Promise<void> {
|
|
376
|
-
return async () => {
|
|
377
|
-
for (const plugin of Object.values(pluginRuntime)) {
|
|
378
|
-
const services = plugin.services as Record<string, unknown>
|
|
379
|
-
const connectDatabase = services.connectDatabase
|
|
380
|
-
if (typeof connectDatabase !== 'function') {
|
|
381
|
-
continue
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
await Reflect.apply(connectDatabase, services, [])
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { tool } from 'ai'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
|
|
4
|
-
export function createLogHelloWorldTool() {
|
|
5
|
-
return tool({
|
|
6
|
-
description: 'Logs "Hello World" to the server console. Requires user approval before running.',
|
|
7
|
-
inputSchema: z.object({
|
|
8
|
-
message: z.string().optional().describe('Optional custom message to log alongside Hello World'),
|
|
9
|
-
}),
|
|
10
|
-
needsApproval: true,
|
|
11
|
-
execute: async ({ message }: { message?: string }) => {
|
|
12
|
-
const output = message ? `Hello World: ${message}` : 'Hello World'
|
|
13
|
-
console.log('[logHelloWorld]', output)
|
|
14
|
-
return { logged: output, timestamp: new Date().toISOString() }
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
}
|
package/src/utils/error.ts
DELETED
/package/src/services/{context-compaction-runtime.ts → context-compaction-runtime.singleton.ts}
RENAMED
|
File without changes
|
|
File without changes
|