@lota-sdk/core 0.2.3 → 0.3.1
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 +2 -2
- package/infrastructure/schema/00_thread.surql +73 -0
- package/infrastructure/schema/02_execution_plan.surql +10 -11
- package/infrastructure/schema/04_runtime_bootstrap.surql +1 -0
- package/infrastructure/schema/10_autonomous_job.surql +3 -3
- package/package.json +2 -2
- package/src/ai/definitions.ts +1 -1
- package/src/config/agent-defaults.ts +5 -5
- package/src/config/index.ts +1 -1
- package/src/config/thread-defaults.ts +72 -0
- package/src/create-runtime.ts +90 -94
- package/src/db/record-id.ts +21 -21
- package/src/db/service.ts +44 -40
- package/src/db/tables.ts +3 -3
- package/src/db/{workstream-message-row.ts → thread-message-row.ts} +3 -3
- package/src/queues/context-compaction.queue.ts +6 -6
- package/src/queues/plan-agent-heartbeat.queue.ts +3 -3
- package/src/queues/post-chat-memory.queue.ts +1 -1
- package/src/queues/title-generation.queue.ts +10 -13
- package/src/redis/index.ts +1 -1
- package/src/redis/stream-context.ts +1 -1
- package/src/runtime/agent-identity-overrides.ts +1 -1
- package/src/runtime/agent-runtime-policy.ts +19 -21
- package/src/runtime/chat-request-routing.ts +1 -1
- package/src/runtime/context-compaction-constants.ts +1 -1
- package/src/runtime/context-compaction.ts +1 -1
- package/src/runtime/execution-plan.ts +1 -1
- package/src/runtime/index.ts +1 -1
- package/src/runtime/memory-digest-policy.ts +1 -1
- package/src/runtime/plugin-types.ts +1 -1
- package/src/runtime/post-turn-side-effects.ts +35 -35
- package/src/runtime/runtime-config.ts +24 -21
- package/src/runtime/runtime-extensions.ts +11 -11
- package/src/runtime/social-chat-agent-runner.ts +3 -3
- package/src/runtime/social-chat-history.ts +1 -1
- package/src/runtime/social-chat.ts +6 -6
- package/src/runtime/team-consultation-orchestrator.ts +1 -1
- package/src/runtime/{workstream-chat-helpers.ts → thread-chat-helpers.ts} +7 -7
- package/src/runtime/{workstream-plan-turn.ts → thread-plan-turn.ts} +11 -17
- package/src/runtime/{workstream-turn-context.ts → thread-turn-context.ts} +10 -10
- package/src/services/agent-activity.service.ts +39 -44
- package/src/services/agent-executor.service.ts +17 -19
- package/src/services/attachment.service.ts +4 -8
- package/src/services/autonomous-job.service.ts +29 -28
- package/src/services/context-compaction.service.ts +19 -29
- package/src/services/execution-plan.service.ts +58 -70
- package/src/services/global-orchestrator.service.ts +5 -5
- package/src/services/index.ts +6 -6
- package/src/services/memory.service.ts +1 -1
- package/src/services/monitoring-window.service.ts +2 -2
- package/src/services/mutating-approval.service.ts +7 -10
- package/src/services/node-workspace.service.ts +8 -7
- package/src/services/notification.service.ts +1 -1
- package/src/services/organization.service.ts +9 -9
- package/src/services/ownership-dispatcher.service.ts +13 -19
- package/src/services/plan-agent-heartbeat.service.ts +13 -13
- package/src/services/plan-agent-query.service.ts +7 -7
- package/src/services/plan-artifact.service.ts +1 -2
- package/src/services/plan-coordination.service.ts +4 -4
- package/src/services/plan-cycle.service.ts +7 -7
- package/src/services/plan-deadline.service.ts +4 -4
- package/src/services/plan-event-delivery.service.ts +8 -12
- package/src/services/plan-executor.service.ts +25 -39
- package/src/services/plan-run-data.ts +27 -8
- package/src/services/plan-run.service.ts +7 -9
- package/src/services/plan-scheduler.service.ts +4 -4
- package/src/services/plan-template.service.ts +2 -2
- package/src/services/plan-validator.service.ts +0 -11
- package/src/services/plugin-executor.service.ts +1 -1
- package/src/services/queue-job.service.ts +1 -1
- package/src/services/recent-activity-title.service.ts +1 -1
- package/src/services/recent-activity.service.ts +4 -4
- package/src/services/system-executor.service.ts +2 -2
- package/src/services/{workstream-message.service.ts → thread-message.service.ts} +72 -76
- package/src/services/thread-plan-registry.service.ts +22 -0
- package/src/services/thread-title.service.ts +39 -0
- package/src/services/{workstream-turn-preparation.service.ts → thread-turn-preparation.service.ts} +148 -171
- package/src/services/{workstream-turn.ts → thread-turn.ts} +27 -31
- package/src/services/thread.service.ts +853 -0
- package/src/services/thread.types.ts +17 -0
- package/src/storage/attachment-storage.service.ts +4 -4
- package/src/system-agents/index.ts +1 -1
- package/src/system-agents/memory.agent.ts +1 -1
- package/src/system-agents/recent-activity-title-refiner.agent.ts +2 -2
- package/src/system-agents/regular-chat-memory-digest.agent.ts +1 -1
- package/src/system-agents/researcher.agent.ts +3 -3
- package/src/system-agents/{workstream-router.agent.ts → thread-router.agent.ts} +68 -135
- package/src/system-agents/title-generator.agent.ts +8 -8
- package/src/tools/execution-plan.tool.ts +39 -40
- package/src/tools/memory-block.tool.ts +4 -4
- package/src/tools/research-topic.tool.ts +1 -0
- package/src/tools/search-web.tool.ts +1 -1
- package/src/tools/search.tool.ts +4 -4
- package/src/tools/team-think.tool.ts +9 -9
- package/src/utils/async.ts +6 -7
- package/src/workers/regular-chat-memory-digest.helpers.ts +1 -1
- package/src/workers/regular-chat-memory-digest.runner.ts +43 -43
- package/src/workers/skill-extraction.runner.ts +9 -13
- package/src/workers/utils/{workstream-message-query.ts → thread-message-query.ts} +21 -21
- package/infrastructure/schema/00_workstream.surql +0 -64
- package/src/config/workstream-defaults.ts +0 -72
- package/src/services/workstream-plan-registry.service.ts +0 -22
- package/src/services/workstream-title.service.ts +0 -42
- package/src/services/workstream.service.ts +0 -803
- package/src/services/workstream.types.ts +0 -17
- /package/src/services/{workstream-constants.ts → thread-constants.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatMessage
|
|
1
|
+
import type { ChatMessage } from '@lota-sdk/shared'
|
|
2
2
|
import { createUIMessageStream } from 'ai'
|
|
3
3
|
|
|
4
4
|
import { lotaDebugLogger } from '../config/debug-logger'
|
|
@@ -9,24 +9,24 @@ import { shouldPlanNodeUseVisibleTurn } from '../runtime/execution-plan-visibili
|
|
|
9
9
|
import { wrapResponseWithKeepalive } from '../utils/sse-keepalive'
|
|
10
10
|
import { planExecutorService } from './plan-executor.service'
|
|
11
11
|
import { planRunService } from './plan-run.service'
|
|
12
|
-
import {
|
|
13
|
-
import { prepareWorkstreamRunCore } from './workstream-turn-preparation.service'
|
|
12
|
+
import { prepareThreadRunCore } from './thread-turn-preparation.service'
|
|
14
13
|
import type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from './
|
|
20
|
-
import {
|
|
14
|
+
PreparedThreadTurnResult,
|
|
15
|
+
ThreadApprovalContinuationParams,
|
|
16
|
+
ThreadPlanTurnParams,
|
|
17
|
+
ThreadTurnParams,
|
|
18
|
+
} from './thread-turn-preparation.service'
|
|
19
|
+
import { threadService } from './thread.service'
|
|
20
|
+
import { userService } from './user.service'
|
|
21
21
|
|
|
22
22
|
export { hasApprovalRespondedParts, isApprovalContinuationRequest }
|
|
23
23
|
export { wrapResponseWithKeepalive }
|
|
24
|
-
export type {
|
|
25
|
-
export type {
|
|
24
|
+
export type { PreparedThreadTurnResult }
|
|
25
|
+
export type { ThreadPlanTurnParams }
|
|
26
26
|
|
|
27
|
-
export async function
|
|
27
|
+
export async function createThreadApprovalContinuationStream(params: ThreadApprovalContinuationParams) {
|
|
28
28
|
const timer = lotaDebugLogger.timer('turn:approval-continuation')
|
|
29
|
-
const prepared = await
|
|
29
|
+
const prepared = await prepareThreadRunCore({ ...params, kind: 'approvalContinuation' })
|
|
30
30
|
timer.step('prepare')
|
|
31
31
|
|
|
32
32
|
return createUIMessageStream<ChatMessage>({
|
|
@@ -39,9 +39,9 @@ export async function createWorkstreamApprovalContinuationStream(params: Workstr
|
|
|
39
39
|
})
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export async function
|
|
42
|
+
export async function createThreadNativeToolApprovalStream(params: ThreadApprovalContinuationParams) {
|
|
43
43
|
const timer = lotaDebugLogger.timer('turn:native-tool-approval')
|
|
44
|
-
const prepared = await
|
|
44
|
+
const prepared = await prepareThreadRunCore({ ...params, kind: 'nativeToolApprovalTurn' })
|
|
45
45
|
timer.step('prepare')
|
|
46
46
|
|
|
47
47
|
return createUIMessageStream<ChatMessage>({
|
|
@@ -54,9 +54,9 @@ export async function createWorkstreamNativeToolApprovalStream(params: Workstrea
|
|
|
54
54
|
})
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export async function
|
|
57
|
+
export async function createThreadTurnStream(params: ThreadTurnParams) {
|
|
58
58
|
const timer = lotaDebugLogger.timer('turn:user-turn')
|
|
59
|
-
const prepared = await
|
|
59
|
+
const prepared = await prepareThreadRunCore({ ...params, kind: 'userTurn' })
|
|
60
60
|
timer.step('prepare')
|
|
61
61
|
|
|
62
62
|
return createUIMessageStream<ChatMessage>({
|
|
@@ -69,11 +69,9 @@ export async function createWorkstreamTurnStream(params: WorkstreamTurnParams) {
|
|
|
69
69
|
})
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export async function
|
|
73
|
-
params: WorkstreamTurnParams,
|
|
74
|
-
): Promise<PreparedWorkstreamTurnResult> {
|
|
72
|
+
export async function runThreadTurnInBackground(params: ThreadTurnParams): Promise<PreparedThreadTurnResult> {
|
|
75
73
|
const timer = lotaDebugLogger.timer('turn:background')
|
|
76
|
-
const prepared = await
|
|
74
|
+
const prepared = await prepareThreadRunCore({ ...params, kind: 'userTurn' })
|
|
77
75
|
timer.step('prepare')
|
|
78
76
|
const result = await prepared.run()
|
|
79
77
|
timer.step('run')
|
|
@@ -85,7 +83,7 @@ export async function triggerPlanNodeTurn(params: {
|
|
|
85
83
|
nodeId: string
|
|
86
84
|
abortSignal?: AbortSignal
|
|
87
85
|
streamId?: string
|
|
88
|
-
}): Promise<
|
|
86
|
+
}): Promise<PreparedThreadTurnResult> {
|
|
89
87
|
const timer = lotaDebugLogger.timer('turn:plan-turn')
|
|
90
88
|
let run = await planRunService.getRunById(params.runId)
|
|
91
89
|
const spec = await planRunService.getPlanSpecById(run.planSpecId)
|
|
@@ -106,8 +104,8 @@ export async function triggerPlanNodeTurn(params: {
|
|
|
106
104
|
return { assistantMessages: [], inputMessageId: undefined }
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
const
|
|
110
|
-
const userRef = ensureRecordId(
|
|
107
|
+
const thread = await threadService.getThread(run.threadId)
|
|
108
|
+
const userRef = ensureRecordId(thread.userId, TABLES.USER)
|
|
111
109
|
|
|
112
110
|
const [artifacts, nodeRuns, userName] = await Promise.all([
|
|
113
111
|
planRunService.listArtifacts(run.id),
|
|
@@ -122,8 +120,6 @@ export async function triggerPlanNodeTurn(params: {
|
|
|
122
120
|
.map((artifact) => ({
|
|
123
121
|
name: artifact.name,
|
|
124
122
|
kind: artifact.kind,
|
|
125
|
-
pointer: artifact.pointer,
|
|
126
|
-
...(artifact.schemaRef ? { schemaRef: artifact.schemaRef } : {}),
|
|
127
123
|
...(artifact.description ? { description: artifact.description } : {}),
|
|
128
124
|
...(artifact.payload !== undefined ? { payload: artifact.payload } : {}),
|
|
129
125
|
}))
|
|
@@ -134,20 +130,20 @@ export async function triggerPlanNodeTurn(params: {
|
|
|
134
130
|
]),
|
|
135
131
|
)
|
|
136
132
|
const upstreamHandoffs = nodeRuns
|
|
137
|
-
.filter((candidate) => nodeSpec.upstreamNodeIds.includes(candidate.nodeId) && candidate.
|
|
133
|
+
.filter((candidate) => nodeSpec.upstreamNodeIds.includes(candidate.nodeId) && candidate.latestNotes)
|
|
138
134
|
.map((candidate) => ({
|
|
139
135
|
nodeId: candidate.nodeId,
|
|
140
136
|
label: upstreamNodeSpecs.get(candidate.nodeId)?.label ?? candidate.nodeId,
|
|
141
137
|
ownerRef: upstreamNodeSpecs.get(candidate.nodeId)?.owner.ref ?? 'system',
|
|
142
138
|
ownerType: upstreamNodeSpecs.get(candidate.nodeId)?.owner.executorType ?? 'system',
|
|
143
|
-
|
|
139
|
+
summary: candidate.latestNotes ?? undefined,
|
|
144
140
|
}))
|
|
145
141
|
timer.step('load-plan-turn-context')
|
|
146
142
|
|
|
147
|
-
const prepared = await
|
|
143
|
+
const prepared = await prepareThreadRunCore({
|
|
148
144
|
kind: 'planTurn',
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
thread,
|
|
146
|
+
threadRef: ensureRecordId(run.threadId, TABLES.THREAD),
|
|
151
147
|
orgRef: ensureRecordId(run.organizationId, TABLES.ORGANIZATION),
|
|
152
148
|
userRef,
|
|
153
149
|
userName,
|