@johpaz/hive-sdk 0.1.3 → 0.1.5
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/CHANGELOG.md +97 -0
- package/README.md +78 -23
- package/bunfig.toml +4 -2
- package/docs/API-AGENTS.md +78 -27
- package/docs/API-CONTEXT-COMPILER.md +31 -34
- package/docs/API-TOOLS-SKILLS-CHANNELS.md +58 -22
- package/docs/HIVE-HARNESS.md +1 -1
- package/docs/INDEX.md +4 -4
- package/docs/TEMPLATE-HIVE-APP.md +10 -10
- package/package.json +9 -4
- package/packages/cli/package.json +2 -2
- package/packages/cli/src/commands/create-app.test.ts +36 -7
- package/packages/cli/src/commands/init.ts +3 -3
- package/packages/cli/src/commands/run.ts +1 -1
- package/packages/cli/src/commands/test.ts +37 -25
- package/packages/cli/src/commands/trace.ts +30 -28
- package/packages/cli/templates/hive-app/.env.example +10 -2
- package/packages/cli/templates/hive-app/README.md +103 -0
- package/packages/cli/templates/hive-app/hive.config.ts +9 -3
- package/packages/cli/templates/hive-app/src/agents/coordinator.ts +8 -1
- package/packages/cli/templates/hive-app/src/main.ts +12 -19
- package/packages/core/package.json +5 -4
- package/packages/core/src/agent/acceptance-checks.ts +166 -0
- package/packages/core/src/agent/agent-catalog.ts +348 -0
- package/packages/core/src/agent/agent-loop.ts +1373 -0
- package/packages/core/src/agent/capability-search.ts +186 -0
- package/packages/core/src/agent/catalog-selector.ts +103 -0
- package/packages/core/src/agent/{Compaction.ts → compaction.ts} +86 -63
- package/packages/core/src/agent/context-compiler.ts +689 -0
- package/packages/core/src/agent/conversation-store.ts +381 -0
- package/packages/core/src/agent/curator.ts +276 -0
- package/packages/core/src/agent/delegation-runtime.ts +241 -0
- package/packages/core/src/agent/goal-runner.ts +323 -0
- package/packages/core/src/agent/index.ts +17 -12
- package/packages/core/src/agent/llm-client.ts +266 -0
- package/packages/core/src/agent/llm-providers/anthropic.ts +264 -0
- package/packages/core/src/agent/llm-providers/deepseek.ts +8 -0
- package/packages/core/src/agent/{providers → llm-providers}/gemini.ts +98 -60
- package/packages/core/src/agent/llm-providers/groq.ts +5 -0
- package/packages/core/src/agent/llm-providers/hiveagents.ts +253 -0
- package/packages/core/src/agent/{providers → llm-providers}/interface.ts +73 -13
- package/packages/core/src/agent/llm-providers/kimi.ts +8 -0
- package/packages/core/src/agent/llm-providers/minimax.ts +13 -0
- package/packages/core/src/agent/llm-providers/mistral.ts +5 -0
- package/packages/core/src/agent/llm-providers/modelscope.ts +5 -0
- package/packages/core/src/agent/llm-providers/nvidia.ts +5 -0
- package/packages/core/src/agent/{providers → llm-providers}/ollama.ts +31 -5
- package/packages/core/src/agent/llm-providers/openai-compat-base.ts +418 -0
- package/packages/core/src/agent/llm-providers/openai.ts +5 -0
- package/packages/core/src/agent/llm-providers/opencode-go.ts +9 -0
- package/packages/core/src/agent/llm-providers/openrouter.ts +5 -0
- package/packages/core/src/agent/llm-providers/qwen.ts +5 -0
- package/packages/core/src/agent/llm-providers/z-ai.ts +5 -0
- package/packages/core/src/agent/minimal-loadout.ts +47 -0
- package/packages/core/src/agent/playbook-selector.ts +119 -0
- package/packages/core/src/agent/{PromptBuilder.ts → prompt-builder.ts} +21 -22
- package/packages/core/src/{harness → agent}/proof-packet.ts +16 -21
- package/packages/core/src/agent/providers/index.ts +35 -16
- package/packages/core/src/agent/reflector.ts +320 -0
- package/packages/core/src/agent/routing-intent.ts +22 -0
- package/packages/core/src/{harness → agent}/run-epoch.ts +4 -3
- package/packages/core/src/{harness → agent}/run-store.ts +142 -81
- package/packages/core/src/agent/{Service.ts → service.ts} +37 -26
- package/packages/core/src/agent/skill-selector.ts +374 -0
- package/packages/core/src/agent/stuck-loop.ts +209 -0
- package/packages/core/src/agent/{selectors/ToolSelector.ts → tool-selector.ts} +188 -178
- package/packages/core/src/{ace/Tracer.ts → agent/tracer.ts} +37 -27
- package/packages/core/src/api/createAgent.test.ts +139 -27
- package/packages/core/src/api/createAgent.ts +232 -44
- package/packages/core/src/artifacts/store.ts +162 -0
- package/packages/core/src/canvas/canvas-manager.ts +161 -0
- package/packages/core/src/canvas/canvas.test.ts +8 -4
- package/packages/core/src/canvas/emitter.ts +131 -80
- package/packages/core/src/canvas/index.ts +1 -3
- package/packages/core/src/channels/base.ts +9 -1
- package/packages/core/src/channels/discord.ts +5 -4
- package/packages/core/src/channels/manager.ts +122 -30
- package/packages/core/src/channels/slack.ts +5 -4
- package/packages/core/src/channels/telegram.ts +36 -6
- package/packages/core/src/channels/webchat.ts +11 -10
- package/packages/core/src/channels/whatsapp.ts +23 -7
- package/packages/core/src/config/index.ts +13 -2
- package/packages/core/src/config/loader.ts +71 -29
- package/packages/core/src/ethics/EthicsGuard.test.ts +90 -36
- package/packages/core/src/ethics/EthicsGuard.ts +51 -47
- package/packages/core/src/events/agent-bus.ts +44 -68
- package/packages/core/src/events/channel-narration.ts +150 -0
- package/packages/core/src/events/narration.ts +82 -0
- package/packages/core/src/events/tool-narration.ts +62 -0
- package/packages/core/src/gateway/delegation-groups.ts +258 -0
- package/packages/core/src/{harness → gateway}/durable-queue.ts +102 -42
- package/packages/core/src/{harness → gateway}/job-store.ts +85 -48
- package/packages/core/src/gateway/lane-queue.ts +173 -0
- package/packages/core/src/gateway/notification-inbox.ts +57 -0
- package/packages/core/src/gateway/server.ts +1 -1
- package/packages/core/src/harness/index.ts +46 -27
- package/packages/core/src/index.ts +33 -20
- package/packages/core/src/mcp/hot-reload.ts +32 -23
- package/packages/core/src/mcp/index.ts +6 -3
- package/packages/core/src/mcp/singleton.ts +1 -4
- package/packages/core/src/mcp/tool-sync.ts +138 -0
- package/packages/core/src/memory/Scratchpad.test.ts +39 -20
- package/packages/core/src/memory/Scratchpad.ts +27 -34
- package/packages/core/src/multimodal/vision-service.ts +44 -38
- package/packages/core/src/resilience/retry.ts +95 -0
- package/packages/core/src/scheduler/CronScheduler.ts +334 -287
- package/packages/core/src/scheduler/index.ts +9 -7
- package/packages/core/src/scheduler/integration.ts +46 -26
- package/packages/core/src/scheduler/scheduler.test.ts +9 -13
- package/packages/core/src/scheduler/types.ts +7 -2
- package/packages/core/src/security/Pairing.ts +1 -1
- package/packages/core/src/skills/bundled/a2ui/a2ui_dashboard/SKILL.md +176 -0
- package/packages/core/src/skills/bundled/a2ui/a2ui_form/SKILL.md +202 -0
- package/packages/core/src/skills/bundled/a2ui/a2ui_interactive/SKILL.md +206 -0
- package/packages/core/src/skills/bundled/agents/agent_spawner/SKILL.md +173 -0
- package/packages/core/src/skills/bundled/agents/memory_manager/SKILL.md +143 -0
- package/packages/core/src/skills/bundled/agents/research_and_remember/SKILL.md +139 -0
- package/packages/core/src/skills/bundled/agents/task_orchestrator/SKILL.md +98 -0
- package/packages/core/src/skills/bundled/api/api_client/SKILL.md +132 -0
- package/packages/core/src/skills/bundled/cli/cli_pipeline/SKILL.md +135 -0
- package/packages/core/src/skills/bundled/cli/cli_safe_exec/SKILL.md +125 -0
- package/packages/core/src/skills/bundled/cli/software_engineering/SKILL.md +23 -0
- package/packages/core/src/skills/bundled/cron_manager/SKILL.md +188 -0
- package/packages/core/src/skills/bundled/cron_reminder/SKILL.md +112 -0
- package/packages/core/src/skills/bundled/filesystem/file_manager/SKILL.md +118 -0
- package/packages/core/src/skills/bundled/filesystem/file_read_and_summarize/SKILL.md +109 -0
- package/packages/core/src/skills/bundled/filesystem/file_writer/SKILL.md +129 -0
- package/packages/core/src/skills/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
- package/packages/core/src/skills/bundled/office/office_document_manager/SKILL.md +262 -0
- package/packages/core/src/skills/bundled/search_knowledge/capability_discovery/SKILL.md +75 -0
- package/packages/core/src/skills/bundled/web/browser_automate/SKILL.md +120 -0
- package/packages/core/src/skills/bundled/web/browser_scrape/SKILL.md +109 -0
- package/packages/core/src/skills/bundled/web/web_monitor/SKILL.md +127 -0
- package/packages/core/src/skills/bundled/web/web_research/SKILL.md +119 -0
- package/packages/core/src/skills/bundled-data.generated.ts +731 -2678
- package/packages/core/src/skills/skills.test.ts +52 -11
- package/packages/core/src/{harness → storage}/boot-id.ts +5 -2
- package/packages/core/src/storage/bootstrap.ts +151 -0
- package/packages/core/src/storage/causal-events.ts +84 -0
- package/packages/core/src/storage/collections.ts +680 -0
- package/packages/core/src/storage/crypto.ts +205 -74
- package/packages/core/src/{harness/db-helpers.ts → storage/hive.ts} +63 -7
- package/packages/core/src/storage/hivedb.ts +61 -0
- package/packages/core/src/storage/index.ts +111 -17
- package/packages/core/src/storage/model-id.ts +53 -0
- package/packages/core/src/storage/onboarding.ts +540 -972
- package/packages/core/src/storage/reconcile.ts +238 -0
- package/packages/core/src/storage/seed.ts +572 -406
- package/packages/core/src/storage/usage.ts +285 -225
- package/packages/core/src/storage/user-email.ts +11 -0
- package/packages/core/src/swarm/AgentExecutor.ts +1 -1
- package/packages/core/src/swarm/EventBridge.ts +1 -1
- package/packages/core/src/swarm/index.ts +12 -9
- package/packages/core/src/tool-runtime/index.ts +146 -23
- package/packages/core/src/tool-runtime/tool-worker.ts +2 -2
- package/packages/core/src/tool-runtime/worker-tools.ts +27 -0
- package/packages/core/src/{canvas/a2ui-tools.ts → tools/a2ui/index.ts} +17 -8
- package/packages/core/src/tools/agents/get-available-models.ts +36 -54
- package/packages/core/src/tools/agents/index.ts +784 -292
- package/packages/core/src/tools/api/api-request.test.ts +164 -0
- package/packages/core/src/tools/api/api-request.ts +174 -0
- package/packages/core/src/tools/api/index.ts +16 -0
- package/packages/core/src/tools/cli/index.ts +4 -0
- package/packages/core/src/tools/core/index.ts +281 -112
- package/packages/core/src/tools/cron/index.ts +121 -124
- package/packages/core/src/tools/index.ts +63 -78
- package/packages/core/src/tools/office/office-escribir-xlsx.ts +3 -1
- package/packages/core/src/tools/types.ts +3 -1
- package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
- package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
- package/packages/core/src/tools/web/browser-service.ts +5 -0
- package/packages/core/src/tools/web/browser-type.ts +3 -8
- package/packages/core/src/tools/web/index.ts +4 -4
- package/packages/core/src/voice/index.ts +89 -63
- package/packages/core/src/workers/agent.worker.ts +2 -2
- package/packages/core/src/workers/workers.test.ts +3 -10
- package/scripts/bump-version.ts +248 -0
- package/scripts/generate-skill-bundle.ts +108 -0
- package/test/agent-loop-terminal-synthesis.test.ts +32 -0
- package/test/catalog-agents-stay-enabled.test.ts +117 -0
- package/test/causal-events.test.ts +117 -0
- package/test/compaction.test.ts +105 -0
- package/test/context-compiler.test.ts +269 -0
- package/test/curator.test.ts +130 -0
- package/test/durable-queue.test.ts +114 -0
- package/test/harness-barrel.test.ts +64 -0
- package/test/hive-helpers.test.ts +130 -0
- package/test/hivedb-search.test.ts +189 -0
- package/test/internal-turns.test.ts +166 -0
- package/test/job-idempotency.test.ts +68 -0
- package/test/job-retry-backoff.test.ts +184 -0
- package/test/job-store.test.ts +381 -0
- package/test/llm-retry.test.ts +97 -0
- package/test/memory-perf.test.ts +774 -0
- package/test/minimal-loadout.test.ts +78 -0
- package/test/model-catalog.test.ts +105 -0
- package/test/preload.ts +12 -0
- package/test/reflector.test.ts +320 -0
- package/test/retention-cap.test.ts +91 -0
- package/test/retired-capabilities-pruned.test.ts +192 -0
- package/test/run-store.test.ts +355 -0
- package/test/scratchpad.test.ts +74 -0
- package/test/secrets-durability.test.ts +119 -0
- package/test/seed-model-reseed.test.ts +155 -0
- package/test/setup-agent-seed.test.ts +264 -0
- package/test/tool-inventory.test.ts +65 -0
- package/test/tool-runtime.test.ts +258 -0
- package/test/toon.test.ts +429 -0
- package/tsconfig.json +2 -0
- package/packages/core/src/ace/Curator.ts +0 -158
- package/packages/core/src/ace/Reflector.ts +0 -200
- package/packages/core/src/ace/index.ts +0 -4
- package/packages/core/src/agent/AgentRunner.ts +0 -711
- package/packages/core/src/agent/ContextCompiler.ts +0 -567
- package/packages/core/src/agent/ContextGuard.ts +0 -91
- package/packages/core/src/agent/ConversationStore.ts +0 -254
- package/packages/core/src/agent/Hooks.ts +0 -166
- package/packages/core/src/agent/StuckLoop.ts +0 -133
- package/packages/core/src/agent/providers/LLMClient.ts +0 -149
- package/packages/core/src/agent/providers/anthropic.ts +0 -212
- package/packages/core/src/agent/providers/openai-compat.ts +0 -231
- package/packages/core/src/agent/selectors/PlaybookSelector.ts +0 -121
- package/packages/core/src/agent/selectors/SkillSelector.ts +0 -322
- package/packages/core/src/agent/selectors/index.ts +0 -6
- package/packages/core/src/auth/auth.ts +0 -121
- package/packages/core/src/auth/index.ts +0 -1
- package/packages/core/src/canvas/CanvasManager.ts +0 -390
- package/packages/core/src/canvas/canvas-tools.ts +0 -448
- package/packages/core/src/harness/collections.ts +0 -98
- package/packages/core/src/harness/goal-verifier.ts +0 -141
- package/packages/core/src/harness/harness.test.ts +0 -236
- package/packages/core/src/harness/reconcile.ts +0 -149
- package/packages/core/src/mcp/MCPToolAdapter.ts +0 -176
- package/packages/core/src/multimodal/VisionService.ts +0 -293
- package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
- package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
- package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
- package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
- package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
- package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
- package/packages/core/src/scheduler/dag/errors.ts +0 -37
- package/packages/core/src/scheduler/dag/index.ts +0 -26
- package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
- package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
- package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
- package/packages/core/src/storage/HiveDBStorage.ts +0 -64
- package/packages/core/src/storage/SQLiteStorage.ts +0 -414
- package/packages/core/src/storage/hiveSeed.ts +0 -308
- package/packages/core/src/storage/hiveStorage.test.ts +0 -38
- package/packages/core/src/storage/schema.ts +0 -689
- package/packages/core/src/storage/storage.test.ts +0 -37
- package/packages/core/src/swarm/AgentBus.ts +0 -460
- package/packages/core/src/swarm/EventBus.ts +0 -169
- package/packages/core/src/swarm/WorkerPool.ts +0 -236
- package/packages/core/src/tools/bridge-events.ts +0 -26
- package/packages/core/src/tools/canvas/index.ts +0 -375
- package/packages/core/src/tools/codebridge/index.ts +0 -342
- package/packages/core/src/tools/meeting/index.ts +0 -353
- package/packages/core/src/tools/projects/index.ts +0 -37
- package/packages/core/src/tools/projects/project-create.ts +0 -94
- package/packages/core/src/tools/projects/project-done.ts +0 -66
- package/packages/core/src/tools/projects/project-fail.ts +0 -66
- package/packages/core/src/tools/projects/project-list.ts +0 -96
- package/packages/core/src/tools/projects/project-update.ts +0 -72
- package/packages/core/src/tools/projects/task-create.ts +0 -68
- package/packages/core/src/tools/projects/task-evaluate.ts +0 -93
- package/packages/core/src/tools/projects/task-update.ts +0 -93
- package/packages/core/src/tools/voice/index.ts +0 -104
- package/packages/core/src/tools/web/api-request.test.ts +0 -170
- package/packages/core/src/tools/web/api-request.ts +0 -239
- package/test/setup-db.ts +0 -216
- /package/packages/core/src/agent/{NativeTools.ts → native-tools.ts} +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Projects Tools - 8 tools
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { Tool } from "../types.ts";
|
|
8
|
-
import { projectCreateTool } from "./project-create.ts";
|
|
9
|
-
import { projectListTool } from "./project-list.ts";
|
|
10
|
-
import { projectUpdateTool } from "./project-update.ts";
|
|
11
|
-
import { projectDoneTool } from "./project-done.ts";
|
|
12
|
-
import { projectFailTool } from "./project-fail.ts";
|
|
13
|
-
import { taskCreateTool } from "./task-create.ts";
|
|
14
|
-
import { taskUpdateTool } from "./task-update.ts";
|
|
15
|
-
import { taskEvaluateTool } from "./task-evaluate.ts";
|
|
16
|
-
|
|
17
|
-
export function createTools(): Tool[] {
|
|
18
|
-
return [
|
|
19
|
-
projectCreateTool,
|
|
20
|
-
projectListTool,
|
|
21
|
-
projectUpdateTool,
|
|
22
|
-
projectDoneTool,
|
|
23
|
-
projectFailTool,
|
|
24
|
-
taskCreateTool,
|
|
25
|
-
taskUpdateTool,
|
|
26
|
-
taskEvaluateTool,
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export * from "./project-create.ts";
|
|
31
|
-
export * from "./project-list.ts";
|
|
32
|
-
export * from "./project-update.ts";
|
|
33
|
-
export * from "./project-done.ts";
|
|
34
|
-
export * from "./project-fail.ts";
|
|
35
|
-
export * from "./task-create.ts";
|
|
36
|
-
export * from "./task-update.ts";
|
|
37
|
-
export * from "./task-evaluate.ts";
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* project_create - Create a new project with tasks in the database
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId project_create
|
|
6
|
-
* @spanish crear proyecto, nuevo proyecto, iniciar plan
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
import crypto from "crypto";
|
|
13
|
-
|
|
14
|
-
const log = logger.child("project-create");
|
|
15
|
-
|
|
16
|
-
export const projectCreateTool: Tool = {
|
|
17
|
-
name: "project_create",
|
|
18
|
-
description: "Create a new project with tasks in the database. Spanish: crear proyecto, nuevo proyecto, iniciar plan",
|
|
19
|
-
parameters: {
|
|
20
|
-
type: "object",
|
|
21
|
-
properties: {
|
|
22
|
-
name: {
|
|
23
|
-
type: "string",
|
|
24
|
-
description: "Nombre descriptivo del proyecto",
|
|
25
|
-
},
|
|
26
|
-
description: {
|
|
27
|
-
type: "string",
|
|
28
|
-
description: "Descripción detallada del objetivo del proyecto",
|
|
29
|
-
},
|
|
30
|
-
type: {
|
|
31
|
-
type: "string",
|
|
32
|
-
enum: ["general", "code", "research", "content", "data"],
|
|
33
|
-
description: "Tipo de proyecto",
|
|
34
|
-
},
|
|
35
|
-
tasks: {
|
|
36
|
-
type: "array",
|
|
37
|
-
description: "Lista de tareas atómicas que componen el proyecto",
|
|
38
|
-
items: {
|
|
39
|
-
type: "object",
|
|
40
|
-
properties: {
|
|
41
|
-
name: { type: "string", description: "Nombre corto de la tarea" },
|
|
42
|
-
description: { type: "string", description: "Qué debe hacer esta tarea" },
|
|
43
|
-
agent_id: { type: "string", description: "ID del agente asignado (opcional)" },
|
|
44
|
-
},
|
|
45
|
-
required: ["name"],
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
required: ["name", "type"],
|
|
50
|
-
},
|
|
51
|
-
execute: async (params: Record<string, unknown>, config?: any) => {
|
|
52
|
-
const db = getDb();
|
|
53
|
-
const name = params.name as string;
|
|
54
|
-
const description = (params.description as string) ?? "";
|
|
55
|
-
const type = (params.type as string) ?? "general";
|
|
56
|
-
const tasks = (params.tasks as any[]) ?? [];
|
|
57
|
-
const userId = config?.configurable?.user_id;
|
|
58
|
-
const agentId = config?.configurable?.agent_id;
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const projectId = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
|
|
62
|
-
|
|
63
|
-
log.info(`Creating project: ${name}`);
|
|
64
|
-
|
|
65
|
-
db.query(`
|
|
66
|
-
INSERT INTO projects (id, user_id, agent_id, name, description, type, task, status, created_at, updated_at)
|
|
67
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, 'active', unixepoch(), unixepoch())
|
|
68
|
-
`).run(projectId, userId, agentId, name, description, type, description);
|
|
69
|
-
|
|
70
|
-
const taskIds: number[] = [];
|
|
71
|
-
for (const t of tasks) {
|
|
72
|
-
const result = db.query(`
|
|
73
|
-
INSERT INTO tasks (project_id, agent_id, name, description, status, created_at, updated_at)
|
|
74
|
-
VALUES (?, ?, ?, ?, 'pending', unixepoch(), unixepoch())
|
|
75
|
-
`).run(projectId, t.agent_id ?? agentId, t.name, t.description ?? null);
|
|
76
|
-
|
|
77
|
-
taskIds.push(result.lastInsertRowid as number);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
ok: true,
|
|
82
|
-
projectId,
|
|
83
|
-
taskIds,
|
|
84
|
-
message: `Project "${name}" created with ${tasks.length} task(s).`,
|
|
85
|
-
};
|
|
86
|
-
} catch (error) {
|
|
87
|
-
log.error(`Failed to create project: ${(error as Error).message}`);
|
|
88
|
-
return {
|
|
89
|
-
ok: false,
|
|
90
|
-
error: `Failed to create project: ${(error as Error).message}`,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* project_done - Mark project as completed
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId project_done
|
|
6
|
-
* @spanish proyecto terminado, cerrar proyecto, completado
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("project-done");
|
|
14
|
-
|
|
15
|
-
export const projectDoneTool: Tool = {
|
|
16
|
-
name: "project_done",
|
|
17
|
-
description: "Mark project as completed and archive it. Spanish: proyecto terminado, cerrar proyecto, completado",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
projectId: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "ID del proyecto completado",
|
|
24
|
-
},
|
|
25
|
-
summary: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Resumen final de lo logrado",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
required: ["projectId"],
|
|
31
|
-
},
|
|
32
|
-
execute: async (params: Record<string, unknown>) => {
|
|
33
|
-
const db = getDb();
|
|
34
|
-
const projectId = params.projectId as string;
|
|
35
|
-
const summary = (params.summary as string) ?? "Tarea completada exitosamente.";
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
log.info(`Completing project ${projectId}`);
|
|
39
|
-
|
|
40
|
-
const result = db.query(`
|
|
41
|
-
UPDATE projects
|
|
42
|
-
SET status = 'done', progress = 100, updated_at = unixepoch(), completed_at = unixepoch(), context = ?
|
|
43
|
-
WHERE id = ?
|
|
44
|
-
`).run(summary, projectId);
|
|
45
|
-
|
|
46
|
-
if (result.changes === 0) {
|
|
47
|
-
return {
|
|
48
|
-
ok: false,
|
|
49
|
-
error: `Project not found: ${projectId}`,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
ok: true,
|
|
55
|
-
projectId,
|
|
56
|
-
message: "Project marked as completed.",
|
|
57
|
-
};
|
|
58
|
-
} catch (error) {
|
|
59
|
-
log.error(`Failed to complete project: ${(error as Error).message}`);
|
|
60
|
-
return {
|
|
61
|
-
ok: false,
|
|
62
|
-
error: `Failed to complete project: ${(error as Error).message}`,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* project_fail - Mark project as failed
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId project_fail
|
|
6
|
-
* @spanish proyecto fallido, marcar fracaso, error
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("project-fail");
|
|
14
|
-
|
|
15
|
-
export const projectFailTool: Tool = {
|
|
16
|
-
name: "project_fail",
|
|
17
|
-
description: "Mark project as failed and record reason. Spanish: proyecto fallido, marcar fracaso, error",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
projectId: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "ID del proyecto fallido",
|
|
24
|
-
},
|
|
25
|
-
reason: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Razón del fallo",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
required: ["projectId", "reason"],
|
|
31
|
-
},
|
|
32
|
-
execute: async (params: Record<string, unknown>) => {
|
|
33
|
-
const db = getDb();
|
|
34
|
-
const projectId = params.projectId as string;
|
|
35
|
-
const reason = params.reason as string;
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
log.error(`Project ${projectId} failed: ${reason}`);
|
|
39
|
-
|
|
40
|
-
const result = db.query(`
|
|
41
|
-
UPDATE projects
|
|
42
|
-
SET status = 'failed', updated_at = unixepoch(), context = ?
|
|
43
|
-
WHERE id = ?
|
|
44
|
-
`).run(reason, projectId);
|
|
45
|
-
|
|
46
|
-
if (result.changes === 0) {
|
|
47
|
-
return {
|
|
48
|
-
ok: false,
|
|
49
|
-
error: `Project not found: ${projectId}`,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
ok: true,
|
|
55
|
-
projectId,
|
|
56
|
-
message: "Project marked as failed.",
|
|
57
|
-
};
|
|
58
|
-
} catch (error) {
|
|
59
|
-
log.error(`Failed to mark project as failed: ${(error as Error).message}`);
|
|
60
|
-
return {
|
|
61
|
-
ok: false,
|
|
62
|
-
error: `Failed to mark project as failed: ${(error as Error).message}`,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* project_list - List all projects with their status
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId project_list
|
|
6
|
-
* @spanish listar proyectos, ver proyectos, historial
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("project-list");
|
|
14
|
-
|
|
15
|
-
export const projectListTool: Tool = {
|
|
16
|
-
name: "project_list",
|
|
17
|
-
description: "List all projects with their status. Spanish: listar proyectos, ver proyectos, historial",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
status: {
|
|
22
|
-
type: "string",
|
|
23
|
-
enum: ["active", "done", "failed", "all"],
|
|
24
|
-
description: "Filter by status (default: all)",
|
|
25
|
-
},
|
|
26
|
-
limit: {
|
|
27
|
-
type: "number",
|
|
28
|
-
description: "Maximum results (default: 20)",
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
execute: async (params: Record<string, unknown>, config?: any) => {
|
|
33
|
-
const db = getDb();
|
|
34
|
-
const userId = config?.configurable?.user_id;
|
|
35
|
-
const statusFilter = params.status as string | undefined;
|
|
36
|
-
const limit = (params.limit as number) ?? 20;
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
let query = `
|
|
40
|
-
SELECT id, name, description, type, status, progress, created_at, updated_at
|
|
41
|
-
FROM projects
|
|
42
|
-
WHERE user_id = ?
|
|
43
|
-
`;
|
|
44
|
-
const args: any[] = [userId];
|
|
45
|
-
|
|
46
|
-
if (statusFilter && statusFilter !== "all") {
|
|
47
|
-
query += ` AND status = ?`;
|
|
48
|
-
args.push(statusFilter);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
query += ` ORDER BY updated_at DESC LIMIT ?`;
|
|
52
|
-
args.push(limit);
|
|
53
|
-
|
|
54
|
-
const rows = db.query(query).all(...args) as any[];
|
|
55
|
-
|
|
56
|
-
const projects = rows.map((row) => {
|
|
57
|
-
const tasks = db.query(`
|
|
58
|
-
SELECT id, name, description, status, progress, agent_id, result
|
|
59
|
-
FROM tasks WHERE project_id = ? ORDER BY id ASC
|
|
60
|
-
`).all(row.id) as any[];
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
id: row.id,
|
|
64
|
-
name: row.name,
|
|
65
|
-
description: row.description,
|
|
66
|
-
type: row.type,
|
|
67
|
-
status: row.status,
|
|
68
|
-
progress: row.progress,
|
|
69
|
-
createdAt: new Date(row.created_at * 1000).toISOString(),
|
|
70
|
-
updatedAt: new Date(row.updated_at * 1000).toISOString(),
|
|
71
|
-
tasks: tasks.map((t) => ({
|
|
72
|
-
id: t.id,
|
|
73
|
-
name: t.name,
|
|
74
|
-
description: t.description,
|
|
75
|
-
status: t.status,
|
|
76
|
-
progress: t.progress,
|
|
77
|
-
agentId: t.agent_id,
|
|
78
|
-
result: t.result,
|
|
79
|
-
})),
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
ok: true,
|
|
85
|
-
projects,
|
|
86
|
-
count: projects.length,
|
|
87
|
-
};
|
|
88
|
-
} catch (error) {
|
|
89
|
-
log.error(`Failed to list projects: ${(error as Error).message}`);
|
|
90
|
-
return {
|
|
91
|
-
ok: false,
|
|
92
|
-
error: `Failed to list projects: ${(error as Error).message}`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* project_update - Update project progress or metadata
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId project_update
|
|
6
|
-
* @spanish actualizar proyecto, avance, porcentaje, estado
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("project-update");
|
|
14
|
-
|
|
15
|
-
export const projectUpdateTool: Tool = {
|
|
16
|
-
name: "project_update",
|
|
17
|
-
description: "Update project progress or metadata. Spanish: actualizar proyecto, avance, porcentaje, estado",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
projectId: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "ID del proyecto a actualizar",
|
|
24
|
-
},
|
|
25
|
-
progress: {
|
|
26
|
-
type: "number",
|
|
27
|
-
description: "Progreso actual (0-100)",
|
|
28
|
-
},
|
|
29
|
-
stepDescription: {
|
|
30
|
-
type: "string",
|
|
31
|
-
description: "Descripción del paso actual o siguiente",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
required: ["projectId", "progress", "stepDescription"],
|
|
35
|
-
},
|
|
36
|
-
execute: async (params: Record<string, unknown>) => {
|
|
37
|
-
const db = getDb();
|
|
38
|
-
const projectId = params.projectId as string;
|
|
39
|
-
const progress = params.progress as number;
|
|
40
|
-
const stepDescription = params.stepDescription as string;
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
log.info(`Updating project ${projectId}: ${progress}%`);
|
|
44
|
-
|
|
45
|
-
const result = db.query(`
|
|
46
|
-
UPDATE projects
|
|
47
|
-
SET progress = ?, context = ?, updated_at = unixepoch()
|
|
48
|
-
WHERE id = ?
|
|
49
|
-
`).run(progress, stepDescription, projectId);
|
|
50
|
-
|
|
51
|
-
if (result.changes === 0) {
|
|
52
|
-
return {
|
|
53
|
-
ok: false,
|
|
54
|
-
error: `Project not found: ${projectId}`,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
ok: true,
|
|
60
|
-
projectId,
|
|
61
|
-
progress,
|
|
62
|
-
message: `Project updated: ${progress}%`,
|
|
63
|
-
};
|
|
64
|
-
} catch (error) {
|
|
65
|
-
log.error(`Failed to update project: ${(error as Error).message}`);
|
|
66
|
-
return {
|
|
67
|
-
ok: false,
|
|
68
|
-
error: `Failed to update project: ${(error as Error).message}`,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* task_create - Add a task or subtask to an existing project
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId task_create
|
|
6
|
-
* @spanish crear tarea, agregar tarea, subtarea, pendiente
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("task-create");
|
|
14
|
-
|
|
15
|
-
export const taskCreateTool: Tool = {
|
|
16
|
-
name: "task_create",
|
|
17
|
-
description: "Add a task or subtask to an existing project. Spanish: crear tarea, agregar tarea, subtarea, pendiente",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
project_id: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "ID del proyecto al que pertenece la tarea",
|
|
24
|
-
},
|
|
25
|
-
name: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Nombre corto de la tarea",
|
|
28
|
-
},
|
|
29
|
-
description: {
|
|
30
|
-
type: "string",
|
|
31
|
-
description: "Qué debe realizar esta tarea",
|
|
32
|
-
},
|
|
33
|
-
agent_id: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "ID del agente responsable (opcional)",
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
required: ["project_id", "name"],
|
|
39
|
-
},
|
|
40
|
-
execute: async (params: Record<string, unknown>) => {
|
|
41
|
-
const db = getDb();
|
|
42
|
-
const projectId = params.project_id as string;
|
|
43
|
-
const name = params.name as string;
|
|
44
|
-
const description = (params.description as string) ?? null;
|
|
45
|
-
const agentId = (params.agent_id as string) ?? null;
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const result = db.query(`
|
|
49
|
-
INSERT INTO tasks (project_id, agent_id, name, description, status, created_at, updated_at)
|
|
50
|
-
VALUES (?, ?, ?, ?, 'pending', unixepoch(), unixepoch())
|
|
51
|
-
`).run(projectId, agentId, name, description);
|
|
52
|
-
|
|
53
|
-
const taskId = result.lastInsertRowid as number;
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
ok: true,
|
|
57
|
-
taskId,
|
|
58
|
-
message: `Task "${name}" created (ID: ${taskId}).`,
|
|
59
|
-
};
|
|
60
|
-
} catch (error) {
|
|
61
|
-
log.error(`Failed to create task: ${(error as Error).message}`);
|
|
62
|
-
return {
|
|
63
|
-
ok: false,
|
|
64
|
-
error: `Failed to create task: ${(error as Error).message}`,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* task_evaluate - Evaluate task result against acceptance criteria
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId task_evaluate
|
|
6
|
-
* @spanish evaluar tarea, validar resultado, criterios de aceptación
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("task-evaluate");
|
|
14
|
-
|
|
15
|
-
export const taskEvaluateTool: Tool = {
|
|
16
|
-
name: "task_evaluate",
|
|
17
|
-
description: "Evaluate task result against acceptance criteria. Spanish: evaluar tarea, validar resultado, criterios de aceptación",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
task_id: {
|
|
22
|
-
type: "number",
|
|
23
|
-
description: "ID numérico de la tarea a evaluar",
|
|
24
|
-
},
|
|
25
|
-
criteria: {
|
|
26
|
-
type: "array",
|
|
27
|
-
description: "Lista de criterios de aceptación",
|
|
28
|
-
items: { type: "string" },
|
|
29
|
-
},
|
|
30
|
-
auto_update: {
|
|
31
|
-
type: "boolean",
|
|
32
|
-
description: "Si pasa la evaluación, marca la tarea como completed (default: false)",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
required: ["task_id", "criteria"],
|
|
36
|
-
},
|
|
37
|
-
execute: async (params: Record<string, unknown>) => {
|
|
38
|
-
const db = getDb();
|
|
39
|
-
const taskId = params.task_id as number;
|
|
40
|
-
const criteria = params.criteria as string[];
|
|
41
|
-
const autoUpdate = (params.auto_update as boolean) ?? false;
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const task = db.query<any, [number]>(
|
|
45
|
-
"SELECT id, name, status, result FROM tasks WHERE id = ?"
|
|
46
|
-
).get(taskId);
|
|
47
|
-
|
|
48
|
-
if (!task) {
|
|
49
|
-
return {
|
|
50
|
-
ok: false,
|
|
51
|
-
error: `Task not found: ${taskId}`,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!task.result) {
|
|
56
|
-
return {
|
|
57
|
-
ok: false,
|
|
58
|
-
error: `Task has no result to evaluate.`,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const evaluations = criteria.map((criterion) => {
|
|
63
|
-
const passed = task.result.toLowerCase().includes(criterion.toLowerCase());
|
|
64
|
-
return { criterion, passed };
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const allPassed = evaluations.every((e) => e.passed);
|
|
68
|
-
const passedCount = evaluations.filter((e) => e.passed).length;
|
|
69
|
-
|
|
70
|
-
if (autoUpdate && allPassed) {
|
|
71
|
-
db.query(`
|
|
72
|
-
UPDATE tasks SET status = 'completed', completed_at = unixepoch() WHERE id = ?
|
|
73
|
-
`).run(taskId);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
ok: true,
|
|
78
|
-
taskId,
|
|
79
|
-
allPassed,
|
|
80
|
-
passedCount,
|
|
81
|
-
totalCriteria: criteria.length,
|
|
82
|
-
evaluations,
|
|
83
|
-
autoUpdated: autoUpdate && allPassed,
|
|
84
|
-
};
|
|
85
|
-
} catch (error) {
|
|
86
|
-
log.error(`Failed to evaluate task: ${(error as Error).message}`);
|
|
87
|
-
return {
|
|
88
|
-
ok: false,
|
|
89
|
-
error: `Failed to evaluate task: ${(error as Error).message}`,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* task_update - Update task status
|
|
3
|
-
*
|
|
4
|
-
* @category projects
|
|
5
|
-
* @seedId task_update
|
|
6
|
-
* @spanish actualizar tarea, marcar completa, en progreso
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Tool } from "../types.ts";
|
|
10
|
-
import { getDb } from "../../storage/SQLiteStorage.ts";
|
|
11
|
-
import { logger } from "../../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
const log = logger.child("task-update");
|
|
14
|
-
|
|
15
|
-
export const taskUpdateTool: Tool = {
|
|
16
|
-
name: "task_update",
|
|
17
|
-
description: "Update task status (pending, in_progress, done). Spanish: actualizar tarea, marcar completa, en progreso",
|
|
18
|
-
parameters: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: {
|
|
21
|
-
task_id: {
|
|
22
|
-
type: "number",
|
|
23
|
-
description: "ID numérico de la tarea",
|
|
24
|
-
},
|
|
25
|
-
status: {
|
|
26
|
-
type: "string",
|
|
27
|
-
enum: ["pending", "in_progress", "completed", "failed", "blocked"],
|
|
28
|
-
description: "Nuevo estado de la tarea",
|
|
29
|
-
},
|
|
30
|
-
progress: {
|
|
31
|
-
type: "number",
|
|
32
|
-
description: "Progreso de la tarea (0-100)",
|
|
33
|
-
},
|
|
34
|
-
result: {
|
|
35
|
-
type: "string",
|
|
36
|
-
description: "Resultado o output de la tarea",
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
required: ["task_id"],
|
|
40
|
-
},
|
|
41
|
-
execute: async (params: Record<string, unknown>) => {
|
|
42
|
-
const db = getDb();
|
|
43
|
-
const taskId = params.task_id as number;
|
|
44
|
-
const status = params.status as string | undefined;
|
|
45
|
-
const progress = params.progress as number | undefined;
|
|
46
|
-
const result = params.result as string | undefined;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
log.info(`Updating task ${taskId}`);
|
|
50
|
-
|
|
51
|
-
const updates: string[] = [];
|
|
52
|
-
const values: any[] = [];
|
|
53
|
-
|
|
54
|
-
if (status !== undefined) {
|
|
55
|
-
updates.push("status = ?");
|
|
56
|
-
values.push(status);
|
|
57
|
-
}
|
|
58
|
-
if (progress !== undefined) {
|
|
59
|
-
updates.push("progress = ?");
|
|
60
|
-
values.push(progress);
|
|
61
|
-
}
|
|
62
|
-
if (result !== undefined) {
|
|
63
|
-
updates.push("result = ?");
|
|
64
|
-
values.push(result);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
updates.push("updated_at = unixepoch()");
|
|
68
|
-
values.push(taskId);
|
|
69
|
-
|
|
70
|
-
const query = `UPDATE tasks SET ${updates.join(", ")} WHERE id = ?`;
|
|
71
|
-
const updateResult = db.query(query).run(...values);
|
|
72
|
-
|
|
73
|
-
if (updateResult.changes === 0) {
|
|
74
|
-
return {
|
|
75
|
-
ok: false,
|
|
76
|
-
error: `Task not found: ${taskId}`,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
ok: true,
|
|
82
|
-
taskId,
|
|
83
|
-
message: `Task ${taskId} updated.`,
|
|
84
|
-
};
|
|
85
|
-
} catch (error) {
|
|
86
|
-
log.error(`Failed to update task: ${(error as Error).message}`);
|
|
87
|
-
return {
|
|
88
|
-
ok: false,
|
|
89
|
-
error: `Failed to update task: ${(error as Error).message}`,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
};
|