Skip to content

Commit eabdde1

Browse files
committed
get rid of task state step I
1 parent 47978be commit eabdde1

File tree

5 files changed

+15
-32
lines changed

5 files changed

+15
-32
lines changed

src/components/taskyon/TaskWidget.vue

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
<div class="row items-end q-gutter-xs">
77
<!--task icon-->
88
<div
9-
v-if="
10-
task.state === 'Error' ||
11-
(task.result && task.result instanceof Object && 'error' in task.result)
12-
"
9+
v-if="task.result && task.result instanceof Object && 'error' in task.result"
1310
class="col-auto self-center"
1411
>
1512
<q-icon :name="matWarning" color="negative" size="sm"
@@ -27,8 +24,7 @@
2724
<q-expansion-item
2825
dense
2926
:header-class="
30-
task.state === 'Error' ||
31-
(task.result && task.result instanceof Object && 'error' in task.result)
27+
task.result && task.result instanceof Object && 'error' in task.result
3228
? 'text-negative'
3329
: isWorking
3430
? 'text-info'
@@ -283,7 +279,6 @@ async function taskDraftFromTask(taskId: string) {
283279
const jsonTask = JSON.stringify(await (await tystate.getTaskManager()).getTask(taskId))
284280
const task = TaskNode.partial().parse(JSON.parse(jsonTask))
285281
task.debugging = {}
286-
task.state = 'Open'
287282
state.llmSettings.taskDraft = partialTaskDraft.parse(task)
288283
return task
289284
}

src/modules/taskyon/rxdb.ts

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const taskNodeSchemaLiteral = {
4747
content: {
4848
type: 'string',
4949
},
50+
// TODO: also get rid of this
5051
state: {
5152
type: 'string',
5253
enum: ['Open', 'Queued', 'In Progress', 'Completed', 'Error', 'Cancelled'],
@@ -70,6 +71,7 @@ const taskNodeSchemaLiteral = {
7071
debugging: {
7172
type: 'string', // Storing debugging as a JSON string
7273
},
74+
// TODO: also get rid of this
7375
result: {
7476
type: 'string', // Storing result as a JSON string
7577
},
@@ -288,6 +290,8 @@ export function transformTaskNodeToDocType(taskNode: TaskNode): TaskNodeDocType
288290
debugging: JSON.stringify(taskNode.debugging),
289291
}),
290292
...(taskNode.result !== undefined && { result: JSON.stringify(taskNode.result) }),
293+
// TODO: remove this state here...
294+
state: 'Completed' as 'Open' | 'Queued' | 'In Progress' | 'Completed' | 'Error',
291295
}
292296

293297
return convertedTask

src/modules/taskyon/taskManager.ts

-4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export const initAddTask2Tree =
139139
role: task.role,
140140
priorID,
141141
content: task.content,
142-
state: task.state || 'Open',
143142
debugging: task.debugging || {},
144143
id: uuid,
145144
created_at: Date.now(),
@@ -164,11 +163,9 @@ export const initAddTask2Tree =
164163
if (execute) {
165164
// we need processTasksQueue as an argument here!!!
166165
processTasksQueue.push(newTask.id)
167-
newTask.state = 'Queued'
168166
await taskManager.setTask(newTask, false)
169167
} else {
170168
// in the case of a task which is not processed, we can save it :)
171-
newTask.state = 'Completed'
172169
await taskManager.setTask(newTask, true)
173170
}
174171

@@ -955,7 +952,6 @@ export function useTyTaskManager(
955952
delete partialTask.debugging
956953
delete partialTask.result
957954
delete partialTask.id
958-
delete partialTask.state
959955
delete partialTask.created_at
960956
delete partialTask.priorID
961957
if (message) delete partialTask.content

src/modules/taskyon/taskWorker.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,12 @@ async function parseChatResponse2TaskDraft(message: string): Promise<Record<stri
201201

202202
// use helper function to make code more concise ;)
203203
const createTaskGenerator =
204-
(childCosts: object, finishedTask: TaskNode) =>
205-
async (execute: boolean, partialTask: partialTaskDraft) => {
204+
(childCosts: object, finishedTask: TaskNode) => async (partialTask: partialTaskDraft) => {
206205
partialTask.debugging = { ...partialTask.debugging, ...childCosts }
207206
const taskTemplate: Partial<TaskNode> = {
208207
configuration: finishedTask.configuration,
209208
}
210209
const newTask = deepMerge(taskTemplate, partialTask)
211-
newTask.state = execute ? 'Open' : 'Completed'
212210
return newTask
213211
}
214212

@@ -240,7 +238,7 @@ async function generateFollowupFromStructuredResponse(
240238

241239
if (useTool) {
242240
console.log('trying to get tool call from structured response')
243-
const newTask = await generateFollowUpTask(false, {
241+
const newTask = await generateFollowUpTask({
244242
role: 'assistant',
245243
content: { structuredResponse: choice.message.content || '' },
246244
})
@@ -257,7 +255,7 @@ async function generateFollowupFromStructuredResponse(
257255
const command = res.data
258256
return [
259257
newTask,
260-
await generateFollowUpTask(true, {
258+
await generateFollowUpTask({
261259
priorID: newTask.priorID,
262260
role: 'assistant',
263261
content: { functionCall: command },
@@ -266,7 +264,7 @@ async function generateFollowupFromStructuredResponse(
266264
} else {
267265
return [
268266
newTask,
269-
await generateFollowUpTask(true, {
267+
await generateFollowUpTask({
270268
priorID: newTask.priorID,
271269
role: 'system',
272270
content: {
@@ -280,7 +278,7 @@ async function generateFollowupFromStructuredResponse(
280278
// in the case that we don't call a tool, provide a "normal" answer :)
281279
// this time we declare it as "Open" and set execution to "true"
282280
return [
283-
await generateFollowUpTask(true, {
281+
await generateFollowUpTask({
284282
role: 'assistant',
285283
content: { structuredResponse: choice.message.content || '' },
286284
}),
@@ -335,7 +333,7 @@ async function generateFollowUpTasksFromResult(
335333
if (finishedTask.result) {
336334
if ('functionCall' in finishedTask.content) {
337335
return [
338-
await generateFollowUpTask(true, {
336+
await generateFollowUpTask({
339337
role: 'system',
340338
content: { toolResult: finishedTask.result },
341339
}),
@@ -354,7 +352,7 @@ async function generateFollowUpTasksFromResult(
354352
if (functionCall[0]) {
355353
// TODO: enable multiple parallel function calls
356354
return [
357-
await generateFollowUpTask(true, {
355+
await generateFollowUpTask({
358356
role: 'function',
359357
content: { functionCall: functionCall[0] },
360358
}),
@@ -379,7 +377,7 @@ async function generateFollowUpTasksFromResult(
379377
} else {
380378
// if 'message' in finishedTask.content && finishedTask.role === 'assistant'
381379
// this is the final response, so we simply add it to the chain without executing it
382-
const newTask = await generateFollowUpTask(false, {
380+
const newTask = await generateFollowUpTask({
383381
role: 'assistant',
384382
content: { message: choice.message.content },
385383
})
@@ -478,7 +476,6 @@ async function processTask(
478476
void taskManager.updateTask(
479477
{
480478
id: taskId,
481-
state: 'In Progress',
482479
},
483480
false,
484481
)
@@ -512,7 +509,6 @@ async function processTask(
512509
// get token usage for this task..
513510
await addTaskCostInformation(task, taskManager, llmSettings, apiKey)
514511

515-
task.state = 'Completed'
516512
return task
517513
}
518514

@@ -640,7 +636,7 @@ export async function runTaskWorker(
640636
// interrupt execution if interrupted flag is shown!
641637
// this makes sure that results are still saved, even if we stop any
642638
// further execution
643-
taskWorkerController.isInterrupted() ? false : t.state == 'Open' ? true : false,
639+
taskWorkerController.isInterrupted() ? false : true,
644640
)
645641
llmSettings.selectedTaskId = newTaskId
646642
}
@@ -658,10 +654,6 @@ export async function runTaskWorker(
658654
)
659655
}
660656

661-
if (task) {
662-
task.state = 'Error'
663-
}
664-
665657
const errorTask: partialTaskDraft = {
666658
role: 'system',
667659
configuration: task?.configuration,

src/modules/taskyon/types.ts

-4
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ export const TaskNode = z.object({
319319
For example this is, what an LLM would actually get to see. There are only a few different ways
320320
of how content can be structured. `,
321321
),
322-
// TODO: get rid of task state... the reason is that its stateful (as the nam suggests)
323-
// what we can do is this: move it into
324-
state: TaskState,
325322
label: z.array(z.string()).optional(),
326323
context: z.record(z.string(), z.string()).optional(),
327324
configuration: z
@@ -389,7 +386,6 @@ export const partialTaskDraft = TaskNode.pick({
389386
priorID: true,
390387
name: true,
391388
configuration: true,
392-
state: true,
393389
allowedTools: true,
394390
debugging: true,
395391
label: true,

0 commit comments

Comments
 (0)