@lota-sdk/core 0.4.9 → 0.4.10
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/package.json +2 -2
- package/src/ai/embedding-cache.ts +3 -1
- package/src/ai-gateway/ai-gateway.ts +38 -10
- package/src/config/agent-defaults.ts +22 -9
- package/src/config/agent-types.ts +1 -1
- package/src/config/background-processing.ts +1 -1
- package/src/config/index.ts +0 -1
- package/src/config/logger.ts +20 -7
- package/src/config/thread-defaults.ts +12 -4
- package/src/create-runtime.ts +69 -656
- package/src/db/memory-query-builder.ts +2 -1
- package/src/db/memory-store.ts +29 -20
- package/src/db/memory.ts +188 -195
- package/src/db/service-normalization.ts +97 -64
- package/src/db/service.ts +706 -538
- package/src/db/startup.ts +30 -19
- package/src/effect/awaitable-effect.ts +46 -37
- package/src/effect/helpers.ts +30 -5
- package/src/effect/index.ts +7 -5
- package/src/effect/layers.ts +82 -72
- package/src/effect/runtime.ts +18 -3
- package/src/effect/services.ts +15 -11
- package/src/embeddings/provider.ts +65 -66
- package/src/index.ts +13 -11
- package/src/queues/autonomous-job.queue.ts +59 -71
- package/src/queues/context-compaction.queue.ts +6 -18
- package/src/queues/delayed-node-promotion.queue.ts +9 -17
- package/src/queues/organization-learning.queue.ts +17 -4
- package/src/queues/plan-agent-heartbeat.queue.ts +23 -20
- package/src/queues/plan-scheduler.queue.ts +6 -18
- package/src/queues/post-chat-memory.queue.ts +6 -18
- package/src/queues/queue-factory.ts +128 -50
- package/src/queues/title-generation.queue.ts +6 -17
- package/src/redis/connection.ts +181 -164
- package/src/redis/runtime-connection.ts +13 -3
- package/src/redis/stream-context.ts +17 -9
- package/src/runtime/agent-runtime-policy.ts +1 -1
- package/src/runtime/agent-stream-helpers.ts +15 -11
- package/src/runtime/chat-run-orchestration.ts +1 -1
- package/src/runtime/context-compaction/context-compaction-runtime.ts +1 -1
- package/src/runtime/context-compaction/context-compaction.ts +126 -82
- package/src/runtime/domain-layer.ts +192 -0
- package/src/runtime/graph-designer.ts +15 -7
- package/src/runtime/helper-model.ts +8 -4
- package/src/runtime/index.ts +0 -1
- package/src/runtime/memory/memory-block.ts +19 -9
- package/src/runtime/memory/memory-pipeline.ts +53 -66
- package/src/runtime/memory/memory-scope.ts +33 -29
- package/src/runtime/plugin-resolution.ts +33 -54
- package/src/runtime/post-turn-side-effects.ts +6 -26
- package/src/runtime/retrieval-adapters.ts +4 -4
- package/src/runtime/runtime-accessors.ts +92 -0
- package/src/runtime/runtime-config.ts +3 -3
- package/src/runtime/runtime-extensions.ts +20 -9
- package/src/runtime/runtime-lifecycle.ts +124 -0
- package/src/runtime/runtime-services.ts +386 -0
- package/src/runtime/runtime-token.ts +47 -0
- package/src/runtime/social-chat/social-chat-agent-runner.ts +7 -5
- package/src/runtime/social-chat/social-chat-history.ts +21 -12
- package/src/runtime/social-chat/social-chat.ts +401 -365
- package/src/runtime/team-consultation/team-consultation-orchestrator.ts +58 -52
- package/src/runtime/thread-turn-context.ts +21 -27
- package/src/services/agent-activity.service.ts +1 -1
- package/src/services/agent-executor.service.ts +179 -187
- package/src/services/artifact.service.ts +10 -5
- package/src/services/attachment.service.ts +35 -1
- package/src/services/autonomous-job.service.ts +58 -56
- package/src/services/background-work.service.ts +54 -0
- package/src/services/chat-run-registry.service.ts +3 -1
- package/src/services/context-compaction.service.ts +1 -1
- package/src/services/document-chunk.service.ts +8 -17
- package/src/services/execution-plan/execution-plan-graph.ts +74 -52
- package/src/services/execution-plan/execution-plan.service.ts +1 -1
- package/src/services/feedback-loop.service.ts +1 -1
- package/src/services/global-orchestrator.service.ts +33 -10
- package/src/services/graph-full-routing.ts +44 -33
- package/src/services/index.ts +1 -0
- package/src/services/institutional-memory.service.ts +8 -17
- package/src/services/learned-skill.service.ts +38 -35
- package/src/services/memory/memory-errors.ts +27 -0
- package/src/services/memory/memory-org-memory.ts +14 -3
- package/src/services/memory/memory-preseeded.ts +10 -4
- package/src/services/memory/memory-utils.ts +2 -1
- package/src/services/memory/memory.service.ts +26 -44
- package/src/services/memory/rerank.service.ts +3 -11
- package/src/services/monitoring-window.service.ts +1 -1
- package/src/services/mutating-approval.service.ts +1 -1
- package/src/services/node-workspace.service.ts +2 -2
- package/src/services/notification.service.ts +16 -4
- package/src/services/organization-member.service.ts +1 -1
- package/src/services/organization.service.ts +34 -51
- package/src/services/ownership-dispatcher.service.ts +132 -90
- package/src/services/plan/plan-agent-heartbeat.service.ts +1 -1
- package/src/services/plan/plan-agent-query.service.ts +1 -1
- package/src/services/plan/plan-approval.service.ts +52 -48
- package/src/services/plan/plan-artifact.service.ts +2 -2
- package/src/services/plan/plan-builder.service.ts +2 -2
- package/src/services/plan/plan-checkpoint.service.ts +1 -1
- package/src/services/plan/plan-compiler.service.ts +1 -1
- package/src/services/plan/plan-completion-side-effects.ts +18 -24
- package/src/services/plan/plan-coordination.service.ts +1 -1
- package/src/services/plan/plan-cycle.service.ts +171 -164
- package/src/services/plan/plan-deadline.service.ts +290 -304
- package/src/services/plan/plan-event-delivery.service.ts +44 -39
- package/src/services/plan/plan-executor-graph.ts +114 -67
- package/src/services/plan/plan-executor-helpers.ts +60 -75
- package/src/services/plan/plan-executor.service.ts +550 -467
- package/src/services/plan/plan-run.service.ts +12 -19
- package/src/services/plan/plan-scheduler.service.ts +27 -33
- package/src/services/plan/plan-template.service.ts +1 -1
- package/src/services/plan/plan-transaction-events.ts +8 -5
- package/src/services/plan/plan-validator.service.ts +1 -1
- package/src/services/plan/plan-workspace.service.ts +17 -11
- package/src/services/plugin-executor.service.ts +26 -21
- package/src/services/quality-metrics.service.ts +1 -1
- package/src/services/queue-job.service.ts +8 -17
- package/src/services/recent-activity-title.service.ts +17 -9
- package/src/services/recent-activity.service.ts +1 -1
- package/src/services/skill-resolver.service.ts +1 -1
- package/src/services/social-chat-history.service.ts +37 -20
- package/src/services/system-executor.service.ts +25 -20
- package/src/services/thread/thread-bootstrap.ts +26 -10
- package/src/services/thread/thread-listing.ts +2 -1
- package/src/services/thread/thread-memory-block.ts +18 -5
- package/src/services/thread/thread-message.service.ts +24 -8
- package/src/services/thread/thread-title.service.ts +1 -1
- package/src/services/thread/thread-turn-execution.ts +1 -1
- package/src/services/thread/thread-turn-preparation.service.ts +18 -16
- package/src/services/thread/thread-turn-streaming.ts +12 -11
- package/src/services/thread/thread-turn.ts +43 -10
- package/src/services/thread/thread.service.ts +11 -2
- package/src/services/user.service.ts +1 -1
- package/src/services/write-intent-validator.service.ts +1 -1
- package/src/storage/attachment-storage.service.ts +7 -4
- package/src/storage/generated-document-storage.service.ts +1 -1
- package/src/system-agents/context-compaction.agent.ts +1 -1
- package/src/system-agents/helper-agent-options.ts +1 -1
- 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/system-agents/regular-chat-memory-digest.agent.ts +1 -1
- package/src/system-agents/skill-extractor.agent.ts +1 -1
- package/src/system-agents/skill-manager.agent.ts +1 -1
- package/src/system-agents/title-generator.agent.ts +1 -1
- package/src/tools/execution-plan.tool.ts +28 -17
- package/src/tools/fetch-webpage.tool.ts +20 -13
- package/src/tools/firecrawl-client.ts +13 -3
- package/src/tools/plan-approval.tool.ts +9 -1
- package/src/tools/search-web.tool.ts +16 -9
- package/src/tools/team-think.tool.ts +2 -2
- package/src/utils/async.ts +15 -6
- package/src/utils/errors.ts +27 -15
- package/src/workers/bootstrap.ts +25 -48
- package/src/workers/organization-learning.worker.ts +1 -1
- package/src/workers/regular-chat-memory-digest.runner.ts +25 -15
- package/src/workers/worker-utils.ts +20 -2
- package/src/config/search.ts +0 -3
- package/src/runtime/agent-types.ts +0 -1
|
@@ -110,11 +110,15 @@ interface PlanCycleDeps {
|
|
|
110
110
|
export function makePlanCycleService(deps: PlanCycleDeps) {
|
|
111
111
|
const { db, planSchedulerService, planTemplateService } = deps
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
return db.findOne(
|
|
115
|
-
|
|
113
|
+
const getCycleEffect = Effect.fn('PlanCycle.getCycle')(function* (cycleId: RecordIdInput) {
|
|
114
|
+
return yield* db.findOne(
|
|
115
|
+
TABLES.PLAN_CYCLE,
|
|
116
|
+
{ id: ensureRecordId(cycleId, TABLES.PLAN_CYCLE) },
|
|
117
|
+
PlanCycleRecordSchema,
|
|
118
|
+
)
|
|
119
|
+
})
|
|
116
120
|
|
|
117
|
-
|
|
121
|
+
const createCycleEffect = Effect.fn('PlanCycle.createCycle')(function* (params: {
|
|
118
122
|
organizationId: RecordIdInput
|
|
119
123
|
threadId: RecordIdInput
|
|
120
124
|
templateId: RecordIdInput
|
|
@@ -123,10 +127,10 @@ export function makePlanCycleService(deps: PlanCycleDeps) {
|
|
|
123
127
|
carryForwardPolicy?: CarryForwardPolicy
|
|
124
128
|
leadAgentId: string
|
|
125
129
|
}) {
|
|
126
|
-
|
|
127
|
-
const now = nowDate()
|
|
130
|
+
const now = nowDate()
|
|
128
131
|
|
|
129
|
-
|
|
132
|
+
const cycle = yield* db
|
|
133
|
+
.create(
|
|
130
134
|
TABLES.PLAN_CYCLE,
|
|
131
135
|
{
|
|
132
136
|
organizationId: ensureRecordId(params.organizationId, TABLES.ORGANIZATION),
|
|
@@ -141,198 +145,194 @@ export function makePlanCycleService(deps: PlanCycleDeps) {
|
|
|
141
145
|
},
|
|
142
146
|
PlanCycleRecordSchema,
|
|
143
147
|
)
|
|
148
|
+
.pipe(Effect.withSpan('PlanCycle.persistCycle'))
|
|
144
149
|
|
|
145
|
-
|
|
150
|
+
const createResult = yield* planTemplateService
|
|
151
|
+
.instantiate({
|
|
146
152
|
templateId: params.templateId,
|
|
147
153
|
organizationId: params.organizationId,
|
|
148
154
|
threadId: params.threadId,
|
|
149
155
|
leadAgentId: params.leadAgentId,
|
|
150
156
|
})
|
|
157
|
+
.pipe(Effect.withSpan('PlanCycle.instantiateTemplate'))
|
|
151
158
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
const createdRunId = createResult.plan?.runId
|
|
160
|
+
const scheduleSpec = cycleScheduleToSpec(params.schedule)
|
|
161
|
+
const scheduleParams: {
|
|
162
|
+
organizationId: RecordIdInput
|
|
163
|
+
threadId: RecordIdInput
|
|
164
|
+
scheduleSpec: PlanScheduleSpec
|
|
165
|
+
runId?: RecordIdInput
|
|
166
|
+
} = { organizationId: params.organizationId, threadId: params.threadId, scheduleSpec }
|
|
167
|
+
if (createdRunId !== undefined) {
|
|
168
|
+
scheduleParams.runId = ensureRecordId(createdRunId, TABLES.PLAN_RUN)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const scheduleRecord = yield* planSchedulerService.createSchedule(scheduleParams)
|
|
172
|
+
|
|
173
|
+
const updatedPayload: { scheduleId: RecordIdInput; currentRunId?: RecordIdInput; currentIteration: number } = {
|
|
174
|
+
scheduleId: ensureRecordId(scheduleRecord.id, TABLES.PLAN_SCHEDULE),
|
|
175
|
+
currentIteration: 1,
|
|
176
|
+
}
|
|
177
|
+
if (createdRunId !== undefined) {
|
|
178
|
+
updatedPayload.currentRunId = ensureRecordId(createdRunId, TABLES.PLAN_RUN)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const updated = yield* db.update(
|
|
182
|
+
TABLES.PLAN_CYCLE,
|
|
183
|
+
ensureRecordId(cycle.id, TABLES.PLAN_CYCLE),
|
|
184
|
+
updatedPayload,
|
|
185
|
+
PlanCycleRecordSchema,
|
|
186
|
+
)
|
|
165
187
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
currentIteration: 1,
|
|
169
|
-
}
|
|
170
|
-
if (createdRunId !== undefined) {
|
|
171
|
-
updatedPayload.currentRunId = ensureRecordId(createdRunId, TABLES.PLAN_RUN)
|
|
172
|
-
}
|
|
188
|
+
return updated ?? cycle
|
|
189
|
+
})
|
|
173
190
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
const advanceCycleEffect = Effect.fn('PlanCycle.advanceCycle')(function* (cycleId: RecordIdInput) {
|
|
192
|
+
const cycle = yield* getCycleEffect(cycleId)
|
|
193
|
+
if (!cycle) {
|
|
194
|
+
return yield* new PlanCycleNotFoundError({
|
|
195
|
+
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
196
|
+
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (cycle.status !== 'active') {
|
|
201
|
+
return
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const currentRunId = cycle.currentRunId
|
|
205
|
+
if (currentRunId !== undefined) {
|
|
206
|
+
const runRecord = yield* db.findOne(
|
|
207
|
+
TABLES.PLAN_RUN,
|
|
208
|
+
{ id: ensureRecordId(currentRunId, TABLES.PLAN_RUN) },
|
|
209
|
+
PlanRunSchema,
|
|
179
210
|
)
|
|
180
|
-
|
|
181
|
-
return updated ?? cycle
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function advanceCycleEffect(cycleId: RecordIdInput) {
|
|
186
|
-
return Effect.gen(function* () {
|
|
187
|
-
const cycle = yield* getCycleEffect(cycleId)
|
|
188
|
-
if (!cycle) {
|
|
189
|
-
return yield* new PlanCycleNotFoundError({
|
|
190
|
-
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
191
|
-
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (cycle.status !== 'active') {
|
|
211
|
+
if (runRecord && !TERMINAL_RUN_STATUSES.has(runRecord.status)) {
|
|
196
212
|
return
|
|
197
213
|
}
|
|
214
|
+
}
|
|
198
215
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return yield* new PlanTemplateNotFoundForCycleError({
|
|
214
|
-
templateId: recordIdToString(cycle.templateId, TABLES.PLAN_TEMPLATE),
|
|
215
|
-
message: `Template not found for cycle: ${recordIdToString(cycle.templateId, TABLES.PLAN_TEMPLATE)}`,
|
|
216
|
+
const template = yield* planTemplateService.getTemplate(cycle.templateId)
|
|
217
|
+
if (!template) {
|
|
218
|
+
return yield* new PlanTemplateNotFoundForCycleError({
|
|
219
|
+
templateId: recordIdToString(cycle.templateId, TABLES.PLAN_TEMPLATE),
|
|
220
|
+
message: `Template not found for cycle: ${recordIdToString(cycle.templateId, TABLES.PLAN_TEMPLATE)}`,
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let previousRunArtifacts: PlanArtifactRecord[] = []
|
|
225
|
+
if (currentRunId !== undefined) {
|
|
226
|
+
previousRunArtifacts = yield* db
|
|
227
|
+
.findMany(TABLES.PLAN_ARTIFACT, { runId: ensureRecordId(currentRunId, TABLES.PLAN_RUN) }, PlanArtifactSchema, {
|
|
228
|
+
orderBy: 'createdAt',
|
|
229
|
+
orderDir: 'ASC',
|
|
216
230
|
})
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
let previousRunArtifacts: PlanArtifactRecord[] = []
|
|
220
|
-
if (currentRunId !== undefined) {
|
|
221
|
-
previousRunArtifacts = yield* db.findMany(
|
|
222
|
-
TABLES.PLAN_ARTIFACT,
|
|
223
|
-
{ runId: ensureRecordId(currentRunId, TABLES.PLAN_RUN) },
|
|
224
|
-
PlanArtifactSchema,
|
|
225
|
-
{ orderBy: 'createdAt', orderDir: 'ASC' },
|
|
226
|
-
)
|
|
227
|
-
}
|
|
231
|
+
.pipe(Effect.withSpan('PlanCycle.loadPreviousRunArtifacts'))
|
|
232
|
+
}
|
|
228
233
|
|
|
229
|
-
|
|
234
|
+
const draft = buildCarryForwardDraft({ template, previousRunArtifacts, policy: cycle.carryForwardPolicy })
|
|
230
235
|
|
|
231
|
-
|
|
236
|
+
const result = yield* planTemplateService
|
|
237
|
+
.instantiate({
|
|
232
238
|
templateId: cycle.templateId,
|
|
233
239
|
organizationId: cycle.organizationId,
|
|
234
240
|
threadId: cycle.threadId,
|
|
235
241
|
leadAgentId: 'system',
|
|
236
242
|
overrides: draft,
|
|
237
243
|
})
|
|
244
|
+
.pipe(Effect.withSpan('PlanCycle.instantiateTemplate'))
|
|
238
245
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
yield* db.update(
|
|
248
|
-
TABLES.PLAN_CYCLE,
|
|
249
|
-
ensureRecordId(cycleId, TABLES.PLAN_CYCLE),
|
|
250
|
-
updatePayload,
|
|
251
|
-
PlanCycleRecordSchema,
|
|
252
|
-
)
|
|
253
|
-
})
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function cancelCycleEffect(cycleId: RecordIdInput) {
|
|
257
|
-
return Effect.gen(function* () {
|
|
258
|
-
const cycle = yield* getCycleEffect(cycleId)
|
|
259
|
-
if (!cycle) {
|
|
260
|
-
return yield* new PlanCycleNotFoundError({
|
|
261
|
-
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
262
|
-
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
263
|
-
})
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const scheduleId = cycle.scheduleId
|
|
267
|
-
if (scheduleId !== undefined) {
|
|
268
|
-
yield* planSchedulerService.cancelSchedule(scheduleId)
|
|
269
|
-
}
|
|
246
|
+
const newRunId = result.plan?.runId
|
|
247
|
+
const updatePayload: { currentRunId?: RecordIdInput; currentIteration: number } = {
|
|
248
|
+
currentIteration: cycle.currentIteration + 1,
|
|
249
|
+
}
|
|
250
|
+
if (newRunId !== undefined) {
|
|
251
|
+
updatePayload.currentRunId = ensureRecordId(newRunId, TABLES.PLAN_RUN)
|
|
252
|
+
}
|
|
270
253
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
254
|
+
yield* db.update(
|
|
255
|
+
TABLES.PLAN_CYCLE,
|
|
256
|
+
ensureRecordId(cycleId, TABLES.PLAN_CYCLE),
|
|
257
|
+
updatePayload,
|
|
258
|
+
PlanCycleRecordSchema,
|
|
259
|
+
)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
const cancelCycleEffect = Effect.fn('PlanCycle.cancelCycle')(function* (cycleId: RecordIdInput) {
|
|
263
|
+
const cycle = yield* getCycleEffect(cycleId)
|
|
264
|
+
if (!cycle) {
|
|
265
|
+
return yield* new PlanCycleNotFoundError({
|
|
266
|
+
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
267
|
+
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
268
|
+
})
|
|
269
|
+
}
|
|
279
270
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return yield* new PlanCycleNotFoundError({
|
|
285
|
-
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
286
|
-
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
287
|
-
})
|
|
288
|
-
}
|
|
271
|
+
const scheduleId = cycle.scheduleId
|
|
272
|
+
if (scheduleId !== undefined) {
|
|
273
|
+
yield* planSchedulerService.cancelSchedule(scheduleId)
|
|
274
|
+
}
|
|
289
275
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
276
|
+
yield* db.update(
|
|
277
|
+
TABLES.PLAN_CYCLE,
|
|
278
|
+
ensureRecordId(cycleId, TABLES.PLAN_CYCLE),
|
|
279
|
+
{ status: 'cancelled' },
|
|
280
|
+
PlanCycleRecordSchema,
|
|
281
|
+
)
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
const pauseCycleEffect = Effect.fn('PlanCycle.pauseCycle')(function* (cycleId: RecordIdInput) {
|
|
285
|
+
const cycle = yield* getCycleEffect(cycleId)
|
|
286
|
+
if (!cycle) {
|
|
287
|
+
return yield* new PlanCycleNotFoundError({
|
|
288
|
+
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
289
|
+
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
290
|
+
})
|
|
291
|
+
}
|
|
294
292
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
PlanCycleRecordSchema,
|
|
300
|
-
)
|
|
301
|
-
})
|
|
302
|
-
}
|
|
293
|
+
const scheduleId = cycle.scheduleId
|
|
294
|
+
if (scheduleId !== undefined) {
|
|
295
|
+
yield* planSchedulerService.pauseSchedule(scheduleId)
|
|
296
|
+
}
|
|
303
297
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
298
|
+
yield* db.update(
|
|
299
|
+
TABLES.PLAN_CYCLE,
|
|
300
|
+
ensureRecordId(cycleId, TABLES.PLAN_CYCLE),
|
|
301
|
+
{ status: 'paused' },
|
|
302
|
+
PlanCycleRecordSchema,
|
|
303
|
+
)
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
const resumeCycleEffect = Effect.fn('PlanCycle.resumeCycle')(function* (cycleId: RecordIdInput) {
|
|
307
|
+
const cycle = yield* getCycleEffect(cycleId)
|
|
308
|
+
if (!cycle) {
|
|
309
|
+
return yield* new PlanCycleNotFoundError({
|
|
310
|
+
cycleId: recordIdToString(cycleId, TABLES.PLAN_CYCLE),
|
|
311
|
+
message: `Cycle not found: ${recordIdToString(cycleId, TABLES.PLAN_CYCLE)}`,
|
|
312
|
+
})
|
|
313
|
+
}
|
|
313
314
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
315
|
+
const scheduleId = cycle.scheduleId
|
|
316
|
+
if (scheduleId !== undefined) {
|
|
317
|
+
yield* planSchedulerService.resumeSchedule(scheduleId)
|
|
318
|
+
}
|
|
318
319
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
320
|
+
yield* db.update(
|
|
321
|
+
TABLES.PLAN_CYCLE,
|
|
322
|
+
ensureRecordId(cycleId, TABLES.PLAN_CYCLE),
|
|
323
|
+
{ status: 'active' },
|
|
324
|
+
PlanCycleRecordSchema,
|
|
325
|
+
)
|
|
326
|
+
})
|
|
327
327
|
|
|
328
|
-
|
|
329
|
-
return db.findMany(
|
|
328
|
+
const listCyclesEffect = Effect.fn('PlanCycle.listCycles')(function* (threadId: RecordIdInput) {
|
|
329
|
+
return yield* db.findMany(
|
|
330
330
|
TABLES.PLAN_CYCLE,
|
|
331
331
|
{ threadId: ensureRecordId(threadId, TABLES.THREAD) },
|
|
332
332
|
PlanCycleRecordSchema,
|
|
333
333
|
{ orderBy: 'createdAt', orderDir: 'ASC' },
|
|
334
334
|
)
|
|
335
|
-
}
|
|
335
|
+
})
|
|
336
336
|
|
|
337
337
|
return {
|
|
338
338
|
cycleScheduleToSpec,
|
|
@@ -347,10 +347,12 @@ export function makePlanCycleService(deps: PlanCycleDeps) {
|
|
|
347
347
|
}): Promise<PlanCycleRecord> {
|
|
348
348
|
return runPromise(createCycleEffect(params))
|
|
349
349
|
},
|
|
350
|
+
createCycleEffect,
|
|
350
351
|
|
|
351
352
|
advanceCycle(cycleId: RecordIdInput): Promise<void> {
|
|
352
353
|
return runPromise(advanceCycleEffect(cycleId))
|
|
353
354
|
},
|
|
355
|
+
advanceCycleEffect,
|
|
354
356
|
|
|
355
357
|
buildCarryForwardDraft(params: {
|
|
356
358
|
template: PlanTemplateRecord
|
|
@@ -363,29 +365,34 @@ export function makePlanCycleService(deps: PlanCycleDeps) {
|
|
|
363
365
|
cancelCycle(cycleId: RecordIdInput): Promise<void> {
|
|
364
366
|
return runPromise(cancelCycleEffect(cycleId))
|
|
365
367
|
},
|
|
368
|
+
cancelCycleEffect,
|
|
366
369
|
|
|
367
370
|
pauseCycle(cycleId: RecordIdInput): Promise<void> {
|
|
368
371
|
return runPromise(pauseCycleEffect(cycleId))
|
|
369
372
|
},
|
|
373
|
+
pauseCycleEffect,
|
|
370
374
|
|
|
371
375
|
resumeCycle(cycleId: RecordIdInput): Promise<void> {
|
|
372
376
|
return runPromise(resumeCycleEffect(cycleId))
|
|
373
377
|
},
|
|
378
|
+
resumeCycleEffect,
|
|
374
379
|
|
|
375
380
|
listCycles(threadId: RecordIdInput): Promise<PlanCycleRecord[]> {
|
|
376
381
|
return runPromise(listCyclesEffect(threadId))
|
|
377
382
|
},
|
|
383
|
+
listCyclesEffect,
|
|
378
384
|
|
|
379
385
|
getCycle(cycleId: RecordIdInput): Promise<PlanCycleRecord | null> {
|
|
380
386
|
return runPromise(getCycleEffect(cycleId))
|
|
381
387
|
},
|
|
388
|
+
getCycleEffect,
|
|
382
389
|
}
|
|
383
390
|
}
|
|
384
391
|
|
|
385
392
|
export class PlanCycleServiceTag extends Context.Service<
|
|
386
393
|
PlanCycleServiceTag,
|
|
387
394
|
ReturnType<typeof makePlanCycleService>
|
|
388
|
-
>()('PlanCycleService') {}
|
|
395
|
+
>()('@lota-sdk/core/PlanCycleService') {}
|
|
389
396
|
|
|
390
397
|
export const PlanCycleServiceLive = Layer.effect(
|
|
391
398
|
PlanCycleServiceTag,
|