@lota-sdk/core 0.1.46 → 0.1.48
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_workstream.surql +0 -1
- package/package.json +2 -2
- package/src/runtime/agent-runtime-policy.ts +0 -2
- package/src/runtime/agent-stream-helpers.ts +26 -9
- package/src/runtime/context-compaction-runtime.ts +2 -3
- package/src/runtime/context-compaction.ts +48 -590
- package/src/runtime/execution-plan.ts +7 -1
- package/src/runtime/index.ts +0 -12
- package/src/runtime/post-turn-side-effects.ts +0 -3
- package/src/runtime/runtime-extensions.ts +0 -1
- package/src/runtime/workstream-chat-helpers.ts +1 -8
- package/src/services/context-compaction.service.ts +5 -21
- package/src/services/workstream-turn-preparation.service.ts +54 -51
- package/src/system-agents/context-compaction.agent.ts +4 -10
- package/src/system-agents/workstream-router.agent.ts +84 -2
- package/src/runtime/workstream-state.ts +0 -274
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
const DecisionConfidenceSchema = z.enum(['high', 'medium', 'low'])
|
|
4
|
-
const StateSourceSchema = z.enum(['user', 'agent'])
|
|
5
|
-
|
|
6
|
-
const WorkstreamPlanSchema = z.object({
|
|
7
|
-
id: z.string(),
|
|
8
|
-
text: z.string(),
|
|
9
|
-
source: StateSourceSchema,
|
|
10
|
-
approved: z.boolean(),
|
|
11
|
-
timestamp: z.number(),
|
|
12
|
-
sourceMessageIds: z.array(z.string()).default([]),
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const WorkstreamConstraintSchema = z.object({
|
|
16
|
-
id: z.string(),
|
|
17
|
-
text: z.string(),
|
|
18
|
-
source: StateSourceSchema,
|
|
19
|
-
approved: z.boolean(),
|
|
20
|
-
timestamp: z.number(),
|
|
21
|
-
sourceMessageIds: z.array(z.string()).default([]),
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const WorkstreamDecisionSchema = z.object({
|
|
25
|
-
id: z.string(),
|
|
26
|
-
decision: z.string(),
|
|
27
|
-
rationale: z.string(),
|
|
28
|
-
agent: z.string(),
|
|
29
|
-
sourceMessageIds: z.array(z.string()).default([]),
|
|
30
|
-
confidence: DecisionConfidenceSchema,
|
|
31
|
-
timestamp: z.number(),
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const WorkstreamTaskSchema = z.object({
|
|
35
|
-
id: z.string(),
|
|
36
|
-
title: z.string(),
|
|
37
|
-
status: z.enum(['open', 'in-progress', 'done', 'blocked']),
|
|
38
|
-
owner: z.string(),
|
|
39
|
-
externalId: z.string().optional(),
|
|
40
|
-
source: StateSourceSchema,
|
|
41
|
-
timestamp: z.number(),
|
|
42
|
-
sourceMessageIds: z.array(z.string()).default([]),
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const WorkstreamQuestionSchema = z.object({
|
|
46
|
-
id: z.string(),
|
|
47
|
-
text: z.string(),
|
|
48
|
-
source: StateSourceSchema,
|
|
49
|
-
timestamp: z.number(),
|
|
50
|
-
sourceMessageIds: z.array(z.string()).default([]),
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const WorkstreamArtifactSchema = z.object({
|
|
54
|
-
id: z.string(),
|
|
55
|
-
name: z.string(),
|
|
56
|
-
type: z.string(),
|
|
57
|
-
pointer: z.string(),
|
|
58
|
-
timestamp: z.number(),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const WorkstreamAgentNoteSchema = z.object({
|
|
62
|
-
id: z.string(),
|
|
63
|
-
agent: z.string(),
|
|
64
|
-
summary: z.string(),
|
|
65
|
-
timestamp: z.number(),
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
export const WorkstreamStateSchema = z.object({
|
|
69
|
-
currentPlan: WorkstreamPlanSchema.nullable(),
|
|
70
|
-
activeConstraints: z.array(WorkstreamConstraintSchema),
|
|
71
|
-
keyDecisions: z.array(WorkstreamDecisionSchema),
|
|
72
|
-
tasks: z.array(WorkstreamTaskSchema),
|
|
73
|
-
openQuestions: z.array(WorkstreamQuestionSchema),
|
|
74
|
-
risks: z.array(z.string()),
|
|
75
|
-
artifacts: z.array(WorkstreamArtifactSchema),
|
|
76
|
-
agentContributions: z.array(WorkstreamAgentNoteSchema),
|
|
77
|
-
approvedBy: z.string().optional(),
|
|
78
|
-
approvedAt: z.number().int().optional(),
|
|
79
|
-
approvalMessageId: z.string().optional(),
|
|
80
|
-
approvalNote: z.string().optional(),
|
|
81
|
-
lastUpdated: z.number(),
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
export type WorkstreamState = z.infer<typeof WorkstreamStateSchema>
|
|
85
|
-
|
|
86
|
-
export const WorkstreamStateDeltaSchema = z.object({
|
|
87
|
-
currentPlan: z.string().nullable().optional(),
|
|
88
|
-
newDecisions: z
|
|
89
|
-
.array(
|
|
90
|
-
z.object({
|
|
91
|
-
decision: z.string(),
|
|
92
|
-
rationale: z.string(),
|
|
93
|
-
agent: z.string(),
|
|
94
|
-
sourceMessageIds: z.array(z.string()),
|
|
95
|
-
confidence: DecisionConfidenceSchema,
|
|
96
|
-
}),
|
|
97
|
-
)
|
|
98
|
-
.optional(),
|
|
99
|
-
resolvedQuestions: z.array(z.string()).optional(),
|
|
100
|
-
newQuestions: z.array(z.string()).optional(),
|
|
101
|
-
newConstraints: z.array(z.string()).optional(),
|
|
102
|
-
newRisks: z.array(z.string()).optional(),
|
|
103
|
-
taskUpdates: z
|
|
104
|
-
.array(
|
|
105
|
-
z.object({
|
|
106
|
-
title: z.string(),
|
|
107
|
-
status: WorkstreamTaskSchema.shape.status,
|
|
108
|
-
owner: z.string(),
|
|
109
|
-
externalId: z.string().nullable(),
|
|
110
|
-
sourceMessageIds: z.array(z.string()),
|
|
111
|
-
}),
|
|
112
|
-
)
|
|
113
|
-
.optional(),
|
|
114
|
-
artifacts: z.array(z.object({ name: z.string(), type: z.string(), pointer: z.string() })).optional(),
|
|
115
|
-
agentNote: z.object({ agent: z.string(), summary: z.string() }).optional(),
|
|
116
|
-
conflicts: z
|
|
117
|
-
.array(z.object({ newFact: z.string(), conflictsWith: z.string(), recommendation: z.string() }))
|
|
118
|
-
.optional(),
|
|
119
|
-
approvedBy: z.string().nullable().optional(),
|
|
120
|
-
approvedAt: z.number().int().nullable().optional(),
|
|
121
|
-
approvalMessageId: z.string().nullable().optional(),
|
|
122
|
-
approvalNote: z.string().nullable().optional(),
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
export type WorkstreamStateDelta = z.infer<typeof WorkstreamStateDeltaSchema>
|
|
126
|
-
|
|
127
|
-
const StructuredWorkstreamPlanDeltaSchema = z.object({
|
|
128
|
-
action: z.enum(['unchanged', 'clear', 'set']),
|
|
129
|
-
text: z.string().nullable(),
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
const StructuredWorkstreamDecisionDeltaSchema = z.object({
|
|
133
|
-
decision: z.string(),
|
|
134
|
-
rationale: z.string(),
|
|
135
|
-
agent: z.string(),
|
|
136
|
-
sourceMessageIds: z.array(z.string()),
|
|
137
|
-
confidence: DecisionConfidenceSchema,
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
const StructuredWorkstreamTaskDeltaSchema = z.object({
|
|
141
|
-
title: z.string(),
|
|
142
|
-
status: WorkstreamTaskSchema.shape.status,
|
|
143
|
-
owner: z.string(),
|
|
144
|
-
externalId: z.string().nullable(),
|
|
145
|
-
sourceMessageIds: z.array(z.string()),
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
const StructuredWorkstreamArtifactDeltaSchema = z.object({ name: z.string(), type: z.string(), pointer: z.string() })
|
|
149
|
-
|
|
150
|
-
const StructuredWorkstreamAgentNoteDeltaSchema = z.object({ agent: z.string(), summary: z.string() })
|
|
151
|
-
|
|
152
|
-
const StructuredWorkstreamConflictDeltaSchema = z.object({
|
|
153
|
-
newFact: z.string(),
|
|
154
|
-
conflictsWith: z.string(),
|
|
155
|
-
recommendation: z.string(),
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
export const StructuredWorkstreamStateDeltaSchema = z.object({
|
|
159
|
-
currentPlan: StructuredWorkstreamPlanDeltaSchema,
|
|
160
|
-
newDecisions: z.array(StructuredWorkstreamDecisionDeltaSchema),
|
|
161
|
-
resolvedQuestions: z.array(z.string()),
|
|
162
|
-
newQuestions: z.array(z.string()),
|
|
163
|
-
newConstraints: z.array(z.string()),
|
|
164
|
-
newRisks: z.array(z.string()),
|
|
165
|
-
taskUpdates: z.array(StructuredWorkstreamTaskDeltaSchema),
|
|
166
|
-
artifacts: z.array(StructuredWorkstreamArtifactDeltaSchema),
|
|
167
|
-
agentNote: StructuredWorkstreamAgentNoteDeltaSchema.nullable(),
|
|
168
|
-
conflicts: z.array(StructuredWorkstreamConflictDeltaSchema),
|
|
169
|
-
approvedBy: z.string().nullable(),
|
|
170
|
-
approvedAt: z.number().int().nullable(),
|
|
171
|
-
approvalMessageId: z.string().nullable(),
|
|
172
|
-
approvalNote: z.string().nullable(),
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
export type StructuredWorkstreamStateDelta = z.infer<typeof StructuredWorkstreamStateDeltaSchema>
|
|
176
|
-
|
|
177
|
-
export function createEmptyStructuredWorkstreamStateDelta(): StructuredWorkstreamStateDelta {
|
|
178
|
-
return {
|
|
179
|
-
currentPlan: { action: 'unchanged', text: null },
|
|
180
|
-
newDecisions: [],
|
|
181
|
-
resolvedQuestions: [],
|
|
182
|
-
newQuestions: [],
|
|
183
|
-
newConstraints: [],
|
|
184
|
-
newRisks: [],
|
|
185
|
-
taskUpdates: [],
|
|
186
|
-
artifacts: [],
|
|
187
|
-
agentNote: null,
|
|
188
|
-
conflicts: [],
|
|
189
|
-
approvedBy: null,
|
|
190
|
-
approvedAt: null,
|
|
191
|
-
approvalMessageId: null,
|
|
192
|
-
approvalNote: null,
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function parseStructuredWorkstreamStateDelta(value: unknown): WorkstreamStateDelta {
|
|
197
|
-
const inputRecord = typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : null
|
|
198
|
-
const parsed = StructuredWorkstreamStateDeltaSchema.parse(value)
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
...(parsed.currentPlan.action === 'clear'
|
|
202
|
-
? { currentPlan: null }
|
|
203
|
-
: parsed.currentPlan.action === 'set' && typeof parsed.currentPlan.text === 'string'
|
|
204
|
-
? { currentPlan: parsed.currentPlan.text }
|
|
205
|
-
: {}),
|
|
206
|
-
...(parsed.newDecisions.length > 0 ? { newDecisions: parsed.newDecisions } : {}),
|
|
207
|
-
...(parsed.resolvedQuestions.length > 0 ? { resolvedQuestions: parsed.resolvedQuestions } : {}),
|
|
208
|
-
...(parsed.newQuestions.length > 0 ? { newQuestions: parsed.newQuestions } : {}),
|
|
209
|
-
...(parsed.newConstraints.length > 0 ? { newConstraints: parsed.newConstraints } : {}),
|
|
210
|
-
...(parsed.newRisks.length > 0 ? { newRisks: parsed.newRisks } : {}),
|
|
211
|
-
...(parsed.taskUpdates.length > 0
|
|
212
|
-
? {
|
|
213
|
-
taskUpdates: parsed.taskUpdates.map((taskUpdate) => ({
|
|
214
|
-
title: taskUpdate.title,
|
|
215
|
-
status: taskUpdate.status,
|
|
216
|
-
owner: taskUpdate.owner,
|
|
217
|
-
externalId: taskUpdate.externalId,
|
|
218
|
-
sourceMessageIds: taskUpdate.sourceMessageIds,
|
|
219
|
-
})),
|
|
220
|
-
}
|
|
221
|
-
: {}),
|
|
222
|
-
...(parsed.artifacts.length > 0 ? { artifacts: parsed.artifacts } : {}),
|
|
223
|
-
...(parsed.agentNote ? { agentNote: parsed.agentNote } : {}),
|
|
224
|
-
...(parsed.conflicts.length > 0 ? { conflicts: parsed.conflicts } : {}),
|
|
225
|
-
...(inputRecord && Object.hasOwn(inputRecord, 'approvedBy') ? { approvedBy: parsed.approvedBy } : {}),
|
|
226
|
-
...(inputRecord && Object.hasOwn(inputRecord, 'approvedAt') ? { approvedAt: parsed.approvedAt } : {}),
|
|
227
|
-
...(inputRecord && Object.hasOwn(inputRecord, 'approvalMessageId')
|
|
228
|
-
? { approvalMessageId: parsed.approvalMessageId }
|
|
229
|
-
: {}),
|
|
230
|
-
...(inputRecord && Object.hasOwn(inputRecord, 'approvalNote') ? { approvalNote: parsed.approvalNote } : {}),
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export const StructuredCompactionOutputSchema = z.object({
|
|
235
|
-
summary: z.string(),
|
|
236
|
-
stateDelta: StructuredWorkstreamStateDeltaSchema,
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
export interface CompactionOutput {
|
|
240
|
-
summary: string
|
|
241
|
-
stateDelta: WorkstreamStateDelta
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const WORKSTREAM_STATE_MAX_KEY_DECISIONS = 8
|
|
245
|
-
const WORKSTREAM_STATE_MAX_ACTIVE_CONSTRAINTS = 6
|
|
246
|
-
const WORKSTREAM_STATE_MAX_TASKS = 10
|
|
247
|
-
const WORKSTREAM_STATE_MAX_OPEN_QUESTIONS = 5
|
|
248
|
-
const WORKSTREAM_STATE_MAX_RISKS = 5
|
|
249
|
-
const WORKSTREAM_STATE_MAX_ARTIFACTS = 10
|
|
250
|
-
const WORKSTREAM_STATE_MAX_AGENT_CONTRIBUTIONS = 6
|
|
251
|
-
|
|
252
|
-
export function applyWorkstreamStateCaps(state: WorkstreamState): void {
|
|
253
|
-
state.keyDecisions = state.keyDecisions.slice(-WORKSTREAM_STATE_MAX_KEY_DECISIONS)
|
|
254
|
-
state.activeConstraints = state.activeConstraints.slice(-WORKSTREAM_STATE_MAX_ACTIVE_CONSTRAINTS)
|
|
255
|
-
state.tasks = state.tasks.slice(-WORKSTREAM_STATE_MAX_TASKS)
|
|
256
|
-
state.openQuestions = state.openQuestions.slice(-WORKSTREAM_STATE_MAX_OPEN_QUESTIONS)
|
|
257
|
-
state.risks = state.risks.slice(-WORKSTREAM_STATE_MAX_RISKS)
|
|
258
|
-
state.artifacts = state.artifacts.slice(-WORKSTREAM_STATE_MAX_ARTIFACTS)
|
|
259
|
-
state.agentContributions = state.agentContributions.slice(-WORKSTREAM_STATE_MAX_AGENT_CONTRIBUTIONS)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export function createEmptyWorkstreamState(now = Date.now()): WorkstreamState {
|
|
263
|
-
return {
|
|
264
|
-
currentPlan: null,
|
|
265
|
-
activeConstraints: [],
|
|
266
|
-
keyDecisions: [],
|
|
267
|
-
tasks: [],
|
|
268
|
-
openQuestions: [],
|
|
269
|
-
risks: [],
|
|
270
|
-
artifacts: [],
|
|
271
|
-
agentContributions: [],
|
|
272
|
-
lastUpdated: now,
|
|
273
|
-
}
|
|
274
|
-
}
|