@mastra/core 1.5.0 → 1.6.0
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 +386 -0
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/adapters/AIV5Adapter.d.ts.map +1 -1
- package/dist/agent/message-list/conversion/output-converter.d.ts.map +1 -1
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +7 -7
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +7 -7
- package/dist/agent/workflows/prepare-stream/schema.d.ts +11 -11
- package/dist/{chunk-CQ4Z6ZAV.cjs → chunk-3U3XFMGJ.cjs} +7 -7
- package/dist/{chunk-CQ4Z6ZAV.cjs.map → chunk-3U3XFMGJ.cjs.map} +1 -1
- package/dist/{chunk-D57U4II4.js → chunk-4WG5K4CK.js} +9 -8
- package/dist/chunk-4WG5K4CK.js.map +1 -0
- package/dist/{chunk-UZFGMMKU.js → chunk-5K45E5VE.js} +37 -3
- package/dist/chunk-5K45E5VE.js.map +1 -0
- package/dist/{chunk-OQ5LZ6OV.cjs → chunk-5VQPSWPG.cjs} +149 -61
- package/dist/chunk-5VQPSWPG.cjs.map +1 -0
- package/dist/{chunk-AIRMLZ43.js → chunk-7EXW4AAG.js} +4 -4
- package/dist/{chunk-AIRMLZ43.js.map → chunk-7EXW4AAG.js.map} +1 -1
- package/dist/{chunk-S4VVZI4E.cjs → chunk-AYHSPIT6.cjs} +326 -5
- package/dist/chunk-AYHSPIT6.cjs.map +1 -0
- package/dist/{chunk-YW54RH77.cjs → chunk-DB7U2C5B.cjs} +12 -5
- package/dist/chunk-DB7U2C5B.cjs.map +1 -0
- package/dist/{chunk-DST75PA4.js → chunk-DGS2KGDI.js} +4 -4
- package/dist/{chunk-DST75PA4.js.map → chunk-DGS2KGDI.js.map} +1 -1
- package/dist/{chunk-YIN5F7VO.js → chunk-EEU5NHHU.js} +4254 -3958
- package/dist/chunk-EEU5NHHU.js.map +1 -0
- package/dist/{chunk-A6EWCOGA.cjs → chunk-H5S4PS44.cjs} +197 -27
- package/dist/chunk-H5S4PS44.cjs.map +1 -0
- package/dist/{chunk-3YMDR4OL.cjs → chunk-HTAUP7ER.cjs} +4 -4
- package/dist/{chunk-3YMDR4OL.cjs.map → chunk-HTAUP7ER.cjs.map} +1 -1
- package/dist/{chunk-OHLVZVIK.js → chunk-IC5OUWKJ.js} +12 -5
- package/dist/chunk-IC5OUWKJ.js.map +1 -0
- package/dist/{chunk-MZIMV2BB.js → chunk-IHDE4CJV.js} +244 -213
- package/dist/chunk-IHDE4CJV.js.map +1 -0
- package/dist/{chunk-3KJW4EMO.js → chunk-IHEYJDJP.js} +3 -3
- package/dist/{chunk-3KJW4EMO.js.map → chunk-IHEYJDJP.js.map} +1 -1
- package/dist/{chunk-CXVMDV2B.js → chunk-IOY7Y5GV.js} +197 -27
- package/dist/chunk-IOY7Y5GV.js.map +1 -0
- package/dist/{chunk-MDC6VYA6.cjs → chunk-KAVAKMOQ.cjs} +4 -8
- package/dist/chunk-KAVAKMOQ.cjs.map +1 -0
- package/dist/{chunk-7WC7ALDW.cjs → chunk-LNKS4TJ6.cjs} +6 -6
- package/dist/{chunk-7WC7ALDW.cjs.map → chunk-LNKS4TJ6.cjs.map} +1 -1
- package/dist/{chunk-R3364RAL.js → chunk-MWGGSA5Q.js} +4 -4
- package/dist/{chunk-R3364RAL.js.map → chunk-MWGGSA5Q.js.map} +1 -1
- package/dist/{chunk-QSN5KQXZ.cjs → chunk-O7PZ4VOO.cjs} +11 -11
- package/dist/{chunk-QSN5KQXZ.cjs.map → chunk-O7PZ4VOO.cjs.map} +1 -1
- package/dist/chunk-OQDRPRKM.cjs +46 -0
- package/dist/chunk-OQDRPRKM.cjs.map +1 -0
- package/dist/{chunk-YV2YGQRY.js → chunk-RHKNKJNM.js} +101 -13
- package/dist/chunk-RHKNKJNM.js.map +1 -0
- package/dist/{chunk-TPDMP7OD.js → chunk-RHYZ6CQN.js} +4 -8
- package/dist/chunk-RHYZ6CQN.js.map +1 -0
- package/dist/{chunk-G5JVVFIG.cjs → chunk-RZNHRIM7.cjs} +9 -9
- package/dist/{chunk-G5JVVFIG.cjs.map → chunk-RZNHRIM7.cjs.map} +1 -1
- package/dist/{chunk-JZ6TH4HQ.cjs → chunk-TL2TTA4X.cjs} +4260 -3962
- package/dist/chunk-TL2TTA4X.cjs.map +1 -0
- package/dist/{chunk-KNXZ7KYL.cjs → chunk-TVPANHLE.cjs} +40 -2
- package/dist/chunk-TVPANHLE.cjs.map +1 -0
- package/dist/{chunk-7S6LA43E.cjs → chunk-VJWRJWSC.cjs} +278 -248
- package/dist/chunk-VJWRJWSC.cjs.map +1 -0
- package/dist/chunk-X2HAI3OX.js +39 -0
- package/dist/chunk-X2HAI3OX.js.map +1 -0
- package/dist/{chunk-FZ5DRHKE.js → chunk-XB3DA67Q.js} +325 -5
- package/dist/chunk-XB3DA67Q.js.map +1 -0
- package/dist/{chunk-NUV3BLRH.cjs → chunk-XWZAKKFT.cjs} +17 -16
- package/dist/chunk-XWZAKKFT.cjs.map +1 -0
- package/dist/{chunk-4GB2GS4S.js → chunk-YM6245EM.js} +5 -5
- package/dist/{chunk-4GB2GS4S.js.map → chunk-YM6245EM.js.map} +1 -1
- package/dist/datasets/index.cjs +17 -17
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +417 -391
- package/dist/docs/references/docs-memory-observational-memory.md +2 -0
- package/dist/docs/references/docs-streaming-tool-streaming.md +6 -0
- package/dist/docs/references/docs-workspace-filesystem.md +21 -1
- package/dist/docs/references/reference-harness-harness-class.md +645 -0
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +1 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +25 -0
- package/dist/docs/references/reference-workspace-workspace-class.md +1 -24
- package/dist/docs/references/reference.md +1 -0
- package/dist/editor/types.d.ts +20 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/events/index.cjs +6 -2
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/harness/harness.d.ts +105 -35
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +472 -64
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.d.ts +2 -1
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +468 -62
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/tools.d.ts +38 -0
- package/dist/harness/tools.d.ts.map +1 -1
- package/dist/harness/types.d.ts +64 -9
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +12 -12
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +6 -6
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +21 -21
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +14 -14
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +7 -7
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +21 -21
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +30 -30
- package/dist/loop/workflows/stream.d.ts +0 -13
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-6P4CM74H.js +3 -0
- package/dist/{models-dev-MDI5E2YA.js.map → models-dev-6P4CM74H.js.map} +1 -1
- package/dist/models-dev-CLLSNT5L.cjs +12 -0
- package/dist/{models-dev-BW2GAM3K.cjs.map → models-dev-CLLSNT5L.cjs.map} +1 -1
- package/dist/processor-provider/index.cjs +256 -0
- package/dist/processor-provider/index.cjs.map +1 -0
- package/dist/processor-provider/index.d.ts +5 -0
- package/dist/processor-provider/index.d.ts.map +1 -0
- package/dist/processor-provider/index.js +243 -0
- package/dist/processor-provider/index.js.map +1 -0
- package/dist/processor-provider/phase-filtered-processor.d.ts +22 -0
- package/dist/processor-provider/phase-filtered-processor.d.ts.map +1 -0
- package/dist/processor-provider/providers/index.d.ts +12 -0
- package/dist/processor-provider/providers/index.d.ts.map +1 -0
- package/dist/processor-provider/types.d.ts +65 -0
- package/dist/processor-provider/types.d.ts.map +1 -0
- package/dist/processors/index.cjs +41 -41
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/message-history.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +14 -14
- package/dist/provider-registry-HMTFO5FV.cjs +40 -0
- package/dist/{provider-registry-4PH2JPIA.cjs.map → provider-registry-HMTFO5FV.cjs.map} +1 -1
- package/dist/provider-registry-TTZ2WN2P.js +3 -0
- package/dist/{provider-registry-VEJ3PN4S.js.map → provider-registry-TTZ2WN2P.js.map} +1 -1
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/base.d.ts +2 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.cjs +68 -52
- package/dist/storage/constants.d.ts +6 -2
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/index.d.ts +1 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +4 -1
- package/dist/storage/domains/inmemory-db.d.ts.map +1 -1
- package/dist/storage/domains/mcp-servers/base.d.ts +47 -0
- package/dist/storage/domains/mcp-servers/base.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/index.d.ts +3 -0
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/inmemory.d.ts +31 -0
- package/dist/storage/domains/mcp-servers/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/types.d.ts +44 -44
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +178 -154
- package/dist/storage/index.js +2 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +220 -6
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +19 -0
- package/dist/stream/base/input.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +9 -9
- package/dist/vector/index.js +2 -2
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workspace/constants/index.d.ts +1 -0
- package/dist/workspace/constants/index.d.ts.map +1 -1
- package/dist/workspace/index.cjs +64 -64
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/tools/ast-edit.d.ts +97 -0
- package/dist/workspace/tools/ast-edit.d.ts.map +1 -0
- package/dist/workspace/tools/search.d.ts +1 -1
- package/dist/workspace/tools/tools.d.ts.map +1 -1
- package/package.json +12 -11
- package/processor-provider.d.ts +1 -0
- package/dist/chunk-4D4KB75Y.cjs +0 -9
- package/dist/chunk-4D4KB75Y.cjs.map +0 -1
- package/dist/chunk-7S6LA43E.cjs.map +0 -1
- package/dist/chunk-A6EWCOGA.cjs.map +0 -1
- package/dist/chunk-BVUMKER5.js +0 -7
- package/dist/chunk-BVUMKER5.js.map +0 -1
- package/dist/chunk-CXVMDV2B.js.map +0 -1
- package/dist/chunk-D57U4II4.js.map +0 -1
- package/dist/chunk-FZ5DRHKE.js.map +0 -1
- package/dist/chunk-JZ6TH4HQ.cjs.map +0 -1
- package/dist/chunk-KNXZ7KYL.cjs.map +0 -1
- package/dist/chunk-MDC6VYA6.cjs.map +0 -1
- package/dist/chunk-MZIMV2BB.js.map +0 -1
- package/dist/chunk-NUV3BLRH.cjs.map +0 -1
- package/dist/chunk-OHLVZVIK.js.map +0 -1
- package/dist/chunk-OQ5LZ6OV.cjs.map +0 -1
- package/dist/chunk-S4VVZI4E.cjs.map +0 -1
- package/dist/chunk-TPDMP7OD.js.map +0 -1
- package/dist/chunk-UZFGMMKU.js.map +0 -1
- package/dist/chunk-YIN5F7VO.js.map +0 -1
- package/dist/chunk-YV2YGQRY.js.map +0 -1
- package/dist/chunk-YW54RH77.cjs.map +0 -1
- package/dist/models-dev-BW2GAM3K.cjs +0 -12
- package/dist/models-dev-MDI5E2YA.js +0 -3
- package/dist/provider-registry-4PH2JPIA.cjs +0 -40
- package/dist/provider-registry-VEJ3PN4S.js +0 -3
package/dist/harness/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Agent } from '../chunk-
|
|
2
|
-
import { Workspace } from '../chunk-
|
|
1
|
+
import { Agent } from '../chunk-IHDE4CJV.js';
|
|
2
|
+
import { Workspace } from '../chunk-XB3DA67Q.js';
|
|
3
3
|
import { createTool } from '../chunk-BQHWJLXU.js';
|
|
4
4
|
import { RequestContext } from '../chunk-CCLV5CAA.js';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -36,9 +36,12 @@ var askUserTool = createTool({
|
|
|
36
36
|
}
|
|
37
37
|
const onAbort = () => reject(new DOMException("Aborted", "AbortError"));
|
|
38
38
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
39
|
-
harnessCtx.registerQuestion(
|
|
40
|
-
|
|
41
|
-
resolve(answer2)
|
|
39
|
+
harnessCtx.registerQuestion({
|
|
40
|
+
questionId,
|
|
41
|
+
resolve: (answer2) => {
|
|
42
|
+
signal?.removeEventListener("abort", onAbort);
|
|
43
|
+
resolve(answer2);
|
|
44
|
+
}
|
|
42
45
|
});
|
|
43
46
|
harnessCtx.emitEvent({
|
|
44
47
|
type: "ask_question",
|
|
@@ -83,9 +86,12 @@ ${plan}`,
|
|
|
83
86
|
}
|
|
84
87
|
const onAbort = () => reject(new DOMException("Aborted", "AbortError"));
|
|
85
88
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
86
|
-
harnessCtx.registerPlanApproval(
|
|
87
|
-
|
|
88
|
-
resolve(res)
|
|
89
|
+
harnessCtx.registerPlanApproval({
|
|
90
|
+
planId,
|
|
91
|
+
resolve: (res) => {
|
|
92
|
+
signal?.removeEventListener("abort", onAbort);
|
|
93
|
+
resolve(res);
|
|
94
|
+
}
|
|
89
95
|
});
|
|
90
96
|
harnessCtx.emitEvent({
|
|
91
97
|
type: "plan_approval_required",
|
|
@@ -115,6 +121,135 @@ Please revise the plan based on the feedback and submit again with submit_plan.`
|
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
});
|
|
124
|
+
var taskItemSchema = z.object({
|
|
125
|
+
content: z.string().min(1).describe("Task description in imperative form (e.g., 'Fix authentication bug')"),
|
|
126
|
+
status: z.enum(["pending", "in_progress", "completed"]).describe("Current task status"),
|
|
127
|
+
activeForm: z.string().min(1).describe("Present continuous form shown during execution (e.g., 'Fixing authentication bug')")
|
|
128
|
+
});
|
|
129
|
+
var taskWriteTool = createTool({
|
|
130
|
+
id: "task_write",
|
|
131
|
+
description: `Create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
132
|
+
|
|
133
|
+
Usage:
|
|
134
|
+
- Pass the FULL task list each time (replaces previous list)
|
|
135
|
+
- Each task has: content (imperative), status (pending|in_progress|completed), activeForm (present continuous)
|
|
136
|
+
- Mark tasks in_progress BEFORE starting work (only ONE at a time)
|
|
137
|
+
- Mark tasks completed IMMEDIATELY after finishing
|
|
138
|
+
- Use this for multi-step tasks requiring 3+ distinct actions
|
|
139
|
+
|
|
140
|
+
States:
|
|
141
|
+
- pending: Not yet started
|
|
142
|
+
- in_progress: Currently working on (limit to ONE)
|
|
143
|
+
- completed: Finished successfully`,
|
|
144
|
+
inputSchema: z.object({
|
|
145
|
+
tasks: z.array(taskItemSchema).describe("The complete updated task list")
|
|
146
|
+
}),
|
|
147
|
+
execute: async ({ tasks }, context) => {
|
|
148
|
+
try {
|
|
149
|
+
const harnessCtx = context?.requestContext?.get("harness");
|
|
150
|
+
if (harnessCtx) {
|
|
151
|
+
await harnessCtx.setState({ tasks });
|
|
152
|
+
harnessCtx.emitEvent?.({
|
|
153
|
+
type: "task_updated",
|
|
154
|
+
tasks
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const completed = tasks.filter((t) => t.status === "completed").length;
|
|
158
|
+
const inProgress = tasks.find((t) => t.status === "in_progress");
|
|
159
|
+
const total = tasks.length;
|
|
160
|
+
let summary = `Tasks updated: [${completed}/${total} completed]`;
|
|
161
|
+
if (inProgress) {
|
|
162
|
+
summary += `
|
|
163
|
+
Currently: ${inProgress.activeForm}`;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
content: summary,
|
|
167
|
+
isError: false
|
|
168
|
+
};
|
|
169
|
+
} catch (error) {
|
|
170
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
171
|
+
return {
|
|
172
|
+
content: `Failed to update tasks: ${msg}`,
|
|
173
|
+
isError: true
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
var taskCheckTool = createTool({
|
|
179
|
+
id: "task_check",
|
|
180
|
+
description: `Check the completion status of your current task list. Use this before deciding to end work on a task to ensure all tasks are completed.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
- Total number of tasks
|
|
184
|
+
- Number of completed, in progress, and pending tasks
|
|
185
|
+
- List of incomplete tasks (if any)
|
|
186
|
+
- Boolean indicating if all tasks are done`,
|
|
187
|
+
inputSchema: z.object({}),
|
|
188
|
+
// No input needed
|
|
189
|
+
execute: async ({}, context) => {
|
|
190
|
+
try {
|
|
191
|
+
const harnessCtx = context?.requestContext?.get("harness");
|
|
192
|
+
if (!harnessCtx) {
|
|
193
|
+
return {
|
|
194
|
+
content: "Unable to access task list (no harness context)",
|
|
195
|
+
isError: true
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const state = harnessCtx.getState ? harnessCtx.getState() : harnessCtx.state;
|
|
199
|
+
const typedState = state;
|
|
200
|
+
const tasks = typedState.tasks || [];
|
|
201
|
+
if (tasks.length === 0) {
|
|
202
|
+
return {
|
|
203
|
+
content: "No tasks found. Consider using task_write to create a task list for complex work.",
|
|
204
|
+
isError: false
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const completed = tasks.filter((t) => t.status === "completed");
|
|
208
|
+
const inProgress = tasks.filter((t) => t.status === "in_progress");
|
|
209
|
+
const pending = tasks.filter((t) => t.status === "pending");
|
|
210
|
+
const incomplete = [...inProgress, ...pending];
|
|
211
|
+
const allDone = incomplete.length === 0;
|
|
212
|
+
let response = `Task Status: [${completed.length}/${tasks.length} completed]
|
|
213
|
+
`;
|
|
214
|
+
response += `- Completed: ${completed.length}
|
|
215
|
+
`;
|
|
216
|
+
response += `- In Progress: ${inProgress.length}
|
|
217
|
+
`;
|
|
218
|
+
response += `- Pending: ${pending.length}
|
|
219
|
+
`;
|
|
220
|
+
response += `
|
|
221
|
+
All tasks completed: ${allDone ? "\u2713 YES" : "\u2717 NO"}`;
|
|
222
|
+
if (!allDone) {
|
|
223
|
+
response += "\n\nIncomplete tasks:";
|
|
224
|
+
if (inProgress.length > 0) {
|
|
225
|
+
response += "\n\nIn Progress:";
|
|
226
|
+
inProgress.forEach((t) => {
|
|
227
|
+
response += `
|
|
228
|
+
- ${t.content}`;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (pending.length > 0) {
|
|
232
|
+
response += "\n\nPending:";
|
|
233
|
+
pending.forEach((t) => {
|
|
234
|
+
response += `
|
|
235
|
+
- ${t.content}`;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
response += "\n\nContinue working on these tasks before ending.";
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
content: response,
|
|
242
|
+
isError: false
|
|
243
|
+
};
|
|
244
|
+
} catch (error) {
|
|
245
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
246
|
+
return {
|
|
247
|
+
content: `Failed to check tasks: ${msg}`,
|
|
248
|
+
isError: true
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
118
253
|
function createSubagentTool(opts) {
|
|
119
254
|
const { subagents, resolveModel, harnessTools, fallbackModelId } = opts;
|
|
120
255
|
const subagentIds = subagents.map((s) => s.id);
|
|
@@ -158,7 +293,7 @@ Use this tool when:
|
|
|
158
293
|
}
|
|
159
294
|
}
|
|
160
295
|
}
|
|
161
|
-
const harnessModelId = harnessCtx?.getSubagentModelId?.(agentType) ?? void 0;
|
|
296
|
+
const harnessModelId = harnessCtx?.getSubagentModelId?.({ agentType }) ?? void 0;
|
|
162
297
|
const resolvedModelId = modelId ?? harnessModelId ?? definition.defaultModelId ?? fallbackModelId;
|
|
163
298
|
if (!resolvedModelId) {
|
|
164
299
|
return { content: "No model ID available for subagent. Configure defaultModelId.", isError: true };
|
|
@@ -398,6 +533,7 @@ var Harness = class {
|
|
|
398
533
|
}
|
|
399
534
|
const sortedThreads = [...threads].sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
400
535
|
const mostRecent = sortedThreads[0];
|
|
536
|
+
this.config.threadLock?.acquire(mostRecent.id);
|
|
401
537
|
this.currentThreadId = mostRecent.id;
|
|
402
538
|
await this.loadThreadMetadata();
|
|
403
539
|
return mostRecent;
|
|
@@ -457,7 +593,7 @@ var Harness = class {
|
|
|
457
593
|
// ===========================================================================
|
|
458
594
|
// Mode Management
|
|
459
595
|
// ===========================================================================
|
|
460
|
-
|
|
596
|
+
listModes() {
|
|
461
597
|
return this.config.modes;
|
|
462
598
|
}
|
|
463
599
|
getCurrentModeId() {
|
|
@@ -474,7 +610,7 @@ var Harness = class {
|
|
|
474
610
|
* Switch to a different mode.
|
|
475
611
|
* Aborts any in-progress generation and switches to the mode's default model.
|
|
476
612
|
*/
|
|
477
|
-
async switchMode(modeId) {
|
|
613
|
+
async switchMode({ modeId }) {
|
|
478
614
|
const mode = this.config.modes.find((m) => m.id === modeId);
|
|
479
615
|
if (!mode) {
|
|
480
616
|
throw new Error(`Mode not found: ${modeId}`);
|
|
@@ -482,11 +618,11 @@ var Harness = class {
|
|
|
482
618
|
this.abort();
|
|
483
619
|
const currentModelId = this.getCurrentModelId();
|
|
484
620
|
if (currentModelId) {
|
|
485
|
-
await this.
|
|
621
|
+
await this.setThreadSetting({ key: `modeModelId_${this.currentModeId}`, value: currentModelId });
|
|
486
622
|
}
|
|
487
623
|
const previousModeId = this.currentModeId;
|
|
488
624
|
this.currentModeId = modeId;
|
|
489
|
-
await this.
|
|
625
|
+
await this.setThreadSetting({ key: "currentModeId", value: modeId });
|
|
490
626
|
const modeModelId = await this.loadModeModelId(modeId);
|
|
491
627
|
if (modeModelId) {
|
|
492
628
|
void this.setState({ currentModelId: modeModelId });
|
|
@@ -541,13 +677,17 @@ var Harness = class {
|
|
|
541
677
|
/**
|
|
542
678
|
* Switch to a different model at runtime.
|
|
543
679
|
*/
|
|
544
|
-
async switchModel(
|
|
680
|
+
async switchModel({
|
|
681
|
+
modelId,
|
|
682
|
+
scope = "thread",
|
|
683
|
+
modeId
|
|
684
|
+
}) {
|
|
545
685
|
const targetModeId = modeId ?? this.currentModeId;
|
|
546
686
|
if (targetModeId === this.currentModeId) {
|
|
547
687
|
void this.setState({ currentModelId: modelId });
|
|
548
688
|
}
|
|
549
689
|
if (scope === "thread") {
|
|
550
|
-
await this.
|
|
690
|
+
await this.setThreadSetting({ key: `modeModelId_${targetModeId}`, value: modelId });
|
|
551
691
|
}
|
|
552
692
|
this.emit({ type: "model_changed", modelId, scope, modeId: targetModeId });
|
|
553
693
|
}
|
|
@@ -575,7 +715,7 @@ var Harness = class {
|
|
|
575
715
|
}
|
|
576
716
|
}
|
|
577
717
|
try {
|
|
578
|
-
const { PROVIDER_REGISTRY } = await import('../provider-registry-
|
|
718
|
+
const { PROVIDER_REGISTRY } = await import('../provider-registry-TTZ2WN2P.js');
|
|
579
719
|
const registry = PROVIDER_REGISTRY;
|
|
580
720
|
const providerConfig = registry[provider];
|
|
581
721
|
const envVars = providerConfig?.apiKeyEnvVar;
|
|
@@ -592,9 +732,9 @@ var Harness = class {
|
|
|
592
732
|
* Get all available models from the provider registry with auth status.
|
|
593
733
|
* Uses the optional `modelAuthChecker` and `modelUseCountProvider` hooks.
|
|
594
734
|
*/
|
|
595
|
-
async
|
|
735
|
+
async listAvailableModels() {
|
|
596
736
|
try {
|
|
597
|
-
const { PROVIDER_REGISTRY } = await import('../provider-registry-
|
|
737
|
+
const { PROVIDER_REGISTRY } = await import('../provider-registry-TTZ2WN2P.js');
|
|
598
738
|
if (!PROVIDER_REGISTRY) return [];
|
|
599
739
|
const registry = PROVIDER_REGISTRY;
|
|
600
740
|
const providers = Object.keys(registry);
|
|
@@ -632,7 +772,7 @@ var Harness = class {
|
|
|
632
772
|
}
|
|
633
773
|
async getProviderApiKeyEnvVar(provider) {
|
|
634
774
|
try {
|
|
635
|
-
const { PROVIDER_REGISTRY } = await import('../provider-registry-
|
|
775
|
+
const { PROVIDER_REGISTRY } = await import('../provider-registry-TTZ2WN2P.js');
|
|
636
776
|
const registry = PROVIDER_REGISTRY;
|
|
637
777
|
const envVars = registry[provider]?.apiKeyEnvVar;
|
|
638
778
|
return Array.isArray(envVars) ? envVars[0] : envVars;
|
|
@@ -649,11 +789,11 @@ var Harness = class {
|
|
|
649
789
|
getResourceId() {
|
|
650
790
|
return this.resourceId;
|
|
651
791
|
}
|
|
652
|
-
setResourceId(resourceId) {
|
|
792
|
+
setResourceId({ resourceId }) {
|
|
653
793
|
this.resourceId = resourceId;
|
|
654
794
|
this.currentThreadId = null;
|
|
655
795
|
}
|
|
656
|
-
async createThread(title) {
|
|
796
|
+
async createThread({ title } = {}) {
|
|
657
797
|
const now = /* @__PURE__ */ new Date();
|
|
658
798
|
const thread = {
|
|
659
799
|
id: this.generateId(),
|
|
@@ -670,6 +810,10 @@ var Harness = class {
|
|
|
670
810
|
metadata.currentModelId = modelId;
|
|
671
811
|
metadata[`modeModelId_${this.currentModeId}`] = modelId;
|
|
672
812
|
}
|
|
813
|
+
const projectPath = this.state.projectPath;
|
|
814
|
+
if (projectPath) {
|
|
815
|
+
metadata.projectPath = projectPath;
|
|
816
|
+
}
|
|
673
817
|
if (this.config.storage) {
|
|
674
818
|
const memoryStorage = await this.getMemoryStorage();
|
|
675
819
|
await memoryStorage.saveThread({
|
|
@@ -683,6 +827,23 @@ var Harness = class {
|
|
|
683
827
|
}
|
|
684
828
|
});
|
|
685
829
|
}
|
|
830
|
+
const oldThreadId = this.currentThreadId;
|
|
831
|
+
if (this.config.threadLock) {
|
|
832
|
+
try {
|
|
833
|
+
this.config.threadLock.acquire(thread.id);
|
|
834
|
+
} catch (err) {
|
|
835
|
+
if (oldThreadId) {
|
|
836
|
+
try {
|
|
837
|
+
this.config.threadLock.acquire(oldThreadId);
|
|
838
|
+
} catch {
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
throw err;
|
|
842
|
+
}
|
|
843
|
+
if (oldThreadId) {
|
|
844
|
+
this.config.threadLock.release(oldThreadId);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
686
847
|
this.currentThreadId = thread.id;
|
|
687
848
|
if (modelId && !currentStateModel) {
|
|
688
849
|
void this.setState({ currentModelId: modelId });
|
|
@@ -691,7 +852,7 @@ var Harness = class {
|
|
|
691
852
|
this.emit({ type: "thread_created", thread });
|
|
692
853
|
return thread;
|
|
693
854
|
}
|
|
694
|
-
async renameThread(title) {
|
|
855
|
+
async renameThread({ title }) {
|
|
695
856
|
if (!this.currentThreadId || !this.config.storage) return;
|
|
696
857
|
const memoryStorage = await this.getMemoryStorage();
|
|
697
858
|
const thread = await memoryStorage.getThreadById({ threadId: this.currentThreadId });
|
|
@@ -701,7 +862,7 @@ var Harness = class {
|
|
|
701
862
|
});
|
|
702
863
|
}
|
|
703
864
|
}
|
|
704
|
-
async switchThread(threadId) {
|
|
865
|
+
async switchThread({ threadId }) {
|
|
705
866
|
this.abort();
|
|
706
867
|
if (this.config.storage) {
|
|
707
868
|
const memoryStorage = await this.getMemoryStorage();
|
|
@@ -710,7 +871,11 @@ var Harness = class {
|
|
|
710
871
|
throw new Error(`Thread not found: ${threadId}`);
|
|
711
872
|
}
|
|
712
873
|
}
|
|
874
|
+
this.config.threadLock?.acquire(threadId);
|
|
713
875
|
const previousThreadId = this.currentThreadId;
|
|
876
|
+
if (previousThreadId) {
|
|
877
|
+
this.config.threadLock?.release(previousThreadId);
|
|
878
|
+
}
|
|
714
879
|
this.currentThreadId = threadId;
|
|
715
880
|
await this.loadThreadMetadata();
|
|
716
881
|
this.emit({ type: "thread_changed", threadId, previousThreadId });
|
|
@@ -729,7 +894,7 @@ var Harness = class {
|
|
|
729
894
|
metadata: thread.metadata
|
|
730
895
|
}));
|
|
731
896
|
}
|
|
732
|
-
async
|
|
897
|
+
async setThreadSetting({ key, value }) {
|
|
733
898
|
if (!this.currentThreadId || !this.config.storage) return;
|
|
734
899
|
try {
|
|
735
900
|
const memoryStorage = await this.getMemoryStorage();
|
|
@@ -746,7 +911,7 @@ var Harness = class {
|
|
|
746
911
|
} catch {
|
|
747
912
|
}
|
|
748
913
|
}
|
|
749
|
-
async
|
|
914
|
+
async deleteThreadSetting({ key }) {
|
|
750
915
|
if (!this.currentThreadId || !this.config.storage) return;
|
|
751
916
|
try {
|
|
752
917
|
const memoryStorage = await this.getMemoryStorage();
|
|
@@ -957,10 +1122,26 @@ var Harness = class {
|
|
|
957
1122
|
if (!modelId || !this.config.resolveModel) return void 0;
|
|
958
1123
|
return this.config.resolveModel(modelId);
|
|
959
1124
|
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Switch the Observer model.
|
|
1127
|
+
*/
|
|
1128
|
+
async switchObserverModel({ modelId }) {
|
|
1129
|
+
void this.setState({ observerModelId: modelId });
|
|
1130
|
+
await this.setThreadSetting({ key: "observerModelId", value: modelId });
|
|
1131
|
+
this.emit({ type: "om_model_changed", role: "observer", modelId });
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Switch the Reflector model.
|
|
1135
|
+
*/
|
|
1136
|
+
async switchReflectorModel({ modelId }) {
|
|
1137
|
+
void this.setState({ reflectorModelId: modelId });
|
|
1138
|
+
await this.setThreadSetting({ key: "reflectorModelId", value: modelId });
|
|
1139
|
+
this.emit({ type: "om_model_changed", role: "reflector", modelId });
|
|
1140
|
+
}
|
|
960
1141
|
// ===========================================================================
|
|
961
1142
|
// Subagent Model Management
|
|
962
1143
|
// ===========================================================================
|
|
963
|
-
getSubagentModelId(agentType) {
|
|
1144
|
+
getSubagentModelId({ agentType } = {}) {
|
|
964
1145
|
const state = this.state;
|
|
965
1146
|
if (agentType) {
|
|
966
1147
|
const perType = state[`subagentModelId_${agentType}`];
|
|
@@ -969,19 +1150,19 @@ var Harness = class {
|
|
|
969
1150
|
const global = state.subagentModelId;
|
|
970
1151
|
return typeof global === "string" ? global : null;
|
|
971
1152
|
}
|
|
972
|
-
async setSubagentModelId(modelId, agentType) {
|
|
1153
|
+
async setSubagentModelId({ modelId, agentType }) {
|
|
973
1154
|
const key = agentType ? `subagentModelId_${agentType}` : "subagentModelId";
|
|
974
1155
|
void this.setState({ [key]: modelId });
|
|
975
|
-
await this.
|
|
1156
|
+
await this.setThreadSetting({ key, value: modelId });
|
|
976
1157
|
this.emit({ type: "subagent_model_changed", modelId, scope: "thread", agentType });
|
|
977
1158
|
}
|
|
978
1159
|
// ===========================================================================
|
|
979
1160
|
// Permissions
|
|
980
1161
|
// ===========================================================================
|
|
981
|
-
grantSessionCategory(category) {
|
|
1162
|
+
grantSessionCategory({ category }) {
|
|
982
1163
|
this.sessionGrantedCategories.add(category);
|
|
983
1164
|
}
|
|
984
|
-
grantSessionTool(toolName) {
|
|
1165
|
+
grantSessionTool({ toolName }) {
|
|
985
1166
|
this.sessionGrantedTools.add(toolName);
|
|
986
1167
|
}
|
|
987
1168
|
getSessionGrants() {
|
|
@@ -990,15 +1171,15 @@ var Harness = class {
|
|
|
990
1171
|
tools: [...this.sessionGrantedTools]
|
|
991
1172
|
};
|
|
992
1173
|
}
|
|
993
|
-
getToolCategory(toolName) {
|
|
1174
|
+
getToolCategory({ toolName }) {
|
|
994
1175
|
return this.config.toolCategoryResolver?.(toolName) ?? null;
|
|
995
1176
|
}
|
|
996
|
-
|
|
1177
|
+
setPermissionForCategory({ category, policy }) {
|
|
997
1178
|
const rules = this.getPermissionRules();
|
|
998
1179
|
rules.categories[category] = policy;
|
|
999
1180
|
void this.setState({ permissionRules: rules });
|
|
1000
1181
|
}
|
|
1001
|
-
|
|
1182
|
+
setPermissionForTool({ toolName, policy }) {
|
|
1002
1183
|
const rules = this.getPermissionRules();
|
|
1003
1184
|
rules.tools[toolName] = policy;
|
|
1004
1185
|
void this.setState({ permissionRules: rules });
|
|
@@ -1020,7 +1201,7 @@ var Harness = class {
|
|
|
1020
1201
|
const toolPolicy = rules.tools[toolName];
|
|
1021
1202
|
if (toolPolicy) return toolPolicy;
|
|
1022
1203
|
if (this.sessionGrantedTools.has(toolName)) return "allow";
|
|
1023
|
-
const category = this.getToolCategory(toolName);
|
|
1204
|
+
const category = this.getToolCategory({ toolName });
|
|
1024
1205
|
if (category) {
|
|
1025
1206
|
if (this.sessionGrantedCategories.has(category)) return "allow";
|
|
1026
1207
|
const categoryPolicy = rules.categories[category];
|
|
@@ -1035,7 +1216,10 @@ var Harness = class {
|
|
|
1035
1216
|
* Send a message to the current agent.
|
|
1036
1217
|
* Streams the response and emits events.
|
|
1037
1218
|
*/
|
|
1038
|
-
async sendMessage(
|
|
1219
|
+
async sendMessage({
|
|
1220
|
+
content,
|
|
1221
|
+
images
|
|
1222
|
+
}) {
|
|
1039
1223
|
if (!this.currentThreadId) {
|
|
1040
1224
|
const thread = await this.createThread();
|
|
1041
1225
|
this.currentThreadId = thread.id;
|
|
@@ -1057,12 +1241,16 @@ var Harness = class {
|
|
|
1057
1241
|
};
|
|
1058
1242
|
streamOptions.toolsets = await this.buildToolsets(requestContext);
|
|
1059
1243
|
let messageInput = content;
|
|
1060
|
-
if (
|
|
1244
|
+
if (images?.length) {
|
|
1061
1245
|
messageInput = {
|
|
1062
1246
|
role: "user",
|
|
1063
1247
|
content: [
|
|
1064
1248
|
{ type: "text", text: content },
|
|
1065
|
-
...
|
|
1249
|
+
...images.map((img) => ({
|
|
1250
|
+
type: "file",
|
|
1251
|
+
data: img.data,
|
|
1252
|
+
mediaType: img.mimeType
|
|
1253
|
+
}))
|
|
1066
1254
|
]
|
|
1067
1255
|
};
|
|
1068
1256
|
}
|
|
@@ -1099,18 +1287,17 @@ var Harness = class {
|
|
|
1099
1287
|
}
|
|
1100
1288
|
if (this.currentOperationId === operationId && this.followUpQueue.length > 0) {
|
|
1101
1289
|
const next = this.followUpQueue.shift();
|
|
1102
|
-
await this.sendMessage(next);
|
|
1290
|
+
await this.sendMessage({ content: next });
|
|
1103
1291
|
}
|
|
1104
1292
|
}
|
|
1105
1293
|
}
|
|
1106
|
-
async
|
|
1294
|
+
async listMessages(options) {
|
|
1107
1295
|
if (!this.currentThreadId) return [];
|
|
1108
|
-
return this.
|
|
1296
|
+
return this.listMessagesForThread({ threadId: this.currentThreadId, limit: options?.limit });
|
|
1109
1297
|
}
|
|
1110
|
-
async
|
|
1298
|
+
async listMessagesForThread({ threadId, limit }) {
|
|
1111
1299
|
if (!this.config.storage) return [];
|
|
1112
1300
|
const memoryStorage = await this.getMemoryStorage();
|
|
1113
|
-
const limit = options?.limit;
|
|
1114
1301
|
if (limit) {
|
|
1115
1302
|
const result2 = await memoryStorage.listMessages({
|
|
1116
1303
|
threadId,
|
|
@@ -1123,7 +1310,7 @@ var Harness = class {
|
|
|
1123
1310
|
const result = await memoryStorage.listMessages({ threadId, perPage: false });
|
|
1124
1311
|
return result.messages.map((msg) => this.convertToHarnessMessage(msg));
|
|
1125
1312
|
}
|
|
1126
|
-
async getFirstUserMessageForThread(threadId) {
|
|
1313
|
+
async getFirstUserMessageForThread({ threadId }) {
|
|
1127
1314
|
if (!this.config.storage) return null;
|
|
1128
1315
|
const memoryStorage = await this.getMemoryStorage();
|
|
1129
1316
|
const result = await memoryStorage.listMessages({
|
|
@@ -1182,6 +1369,39 @@ var Harness = class {
|
|
|
1182
1369
|
});
|
|
1183
1370
|
}
|
|
1184
1371
|
break;
|
|
1372
|
+
case "data-om-observation-start": {
|
|
1373
|
+
const data = part.data ?? {};
|
|
1374
|
+
content.push({
|
|
1375
|
+
type: "om_observation_start",
|
|
1376
|
+
tokensToObserve: data.tokensToObserve ?? 0,
|
|
1377
|
+
operationType: data.operationType ?? "observation"
|
|
1378
|
+
});
|
|
1379
|
+
break;
|
|
1380
|
+
}
|
|
1381
|
+
case "data-om-observation-end": {
|
|
1382
|
+
const data = part.data ?? {};
|
|
1383
|
+
content.push({
|
|
1384
|
+
type: "om_observation_end",
|
|
1385
|
+
tokensObserved: data.tokensObserved ?? 0,
|
|
1386
|
+
observationTokens: data.observationTokens ?? 0,
|
|
1387
|
+
durationMs: data.durationMs ?? 0,
|
|
1388
|
+
operationType: data.operationType ?? "observation",
|
|
1389
|
+
observations: data.observations ?? void 0,
|
|
1390
|
+
currentTask: data.currentTask ?? void 0,
|
|
1391
|
+
suggestedResponse: data.suggestedResponse ?? void 0
|
|
1392
|
+
});
|
|
1393
|
+
break;
|
|
1394
|
+
}
|
|
1395
|
+
case "data-om-observation-failed": {
|
|
1396
|
+
const data = part.data ?? {};
|
|
1397
|
+
content.push({
|
|
1398
|
+
type: "om_observation_failed",
|
|
1399
|
+
error: data.error ?? "Unknown error",
|
|
1400
|
+
tokensAttempted: data.tokensAttempted ?? 0,
|
|
1401
|
+
operationType: data.operationType ?? "observation"
|
|
1402
|
+
});
|
|
1403
|
+
break;
|
|
1404
|
+
}
|
|
1185
1405
|
}
|
|
1186
1406
|
}
|
|
1187
1407
|
return { id: msg.id, role: msg.role, content, createdAt: msg.createdAt };
|
|
@@ -1241,6 +1461,21 @@ var Harness = class {
|
|
|
1241
1461
|
}
|
|
1242
1462
|
break;
|
|
1243
1463
|
}
|
|
1464
|
+
case "tool-call-input-streaming-start": {
|
|
1465
|
+
const { toolCallId, toolName } = chunk.payload;
|
|
1466
|
+
this.emit({ type: "tool_input_start", toolCallId, toolName });
|
|
1467
|
+
break;
|
|
1468
|
+
}
|
|
1469
|
+
case "tool-call-delta": {
|
|
1470
|
+
const { toolCallId, argsTextDelta, toolName } = chunk.payload;
|
|
1471
|
+
this.emit({ type: "tool_input_delta", toolCallId, argsTextDelta, toolName });
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
case "tool-call-input-streaming-end": {
|
|
1475
|
+
const { toolCallId } = chunk.payload;
|
|
1476
|
+
this.emit({ type: "tool_input_end", toolCallId });
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1244
1479
|
case "tool-call": {
|
|
1245
1480
|
const toolCall = chunk.payload;
|
|
1246
1481
|
currentMessage.content.push({
|
|
@@ -1343,6 +1578,169 @@ var Harness = class {
|
|
|
1343
1578
|
}
|
|
1344
1579
|
break;
|
|
1345
1580
|
}
|
|
1581
|
+
// Observational Memory data parts
|
|
1582
|
+
// NOTE: OM data parts arrive as { type, data: { ... } } — NOT { type, payload }
|
|
1583
|
+
case "data-om-status": {
|
|
1584
|
+
const d = chunk.data;
|
|
1585
|
+
if (d?.windows) {
|
|
1586
|
+
const w = d.windows;
|
|
1587
|
+
const active = w.active ?? {};
|
|
1588
|
+
const msgs = active.messages ?? {};
|
|
1589
|
+
const obs = active.observations ?? {};
|
|
1590
|
+
const buffObs = w.buffered?.observations ?? {};
|
|
1591
|
+
const buffRef = w.buffered?.reflection ?? {};
|
|
1592
|
+
this.emit({
|
|
1593
|
+
type: "om_status",
|
|
1594
|
+
windows: {
|
|
1595
|
+
active: {
|
|
1596
|
+
messages: { tokens: msgs.tokens ?? 0, threshold: msgs.threshold ?? 0 },
|
|
1597
|
+
observations: { tokens: obs.tokens ?? 0, threshold: obs.threshold ?? 0 }
|
|
1598
|
+
},
|
|
1599
|
+
buffered: {
|
|
1600
|
+
observations: {
|
|
1601
|
+
status: buffObs.status ?? "idle",
|
|
1602
|
+
chunks: buffObs.chunks ?? 0,
|
|
1603
|
+
messageTokens: buffObs.messageTokens ?? 0,
|
|
1604
|
+
projectedMessageRemoval: buffObs.projectedMessageRemoval ?? 0,
|
|
1605
|
+
observationTokens: buffObs.observationTokens ?? 0
|
|
1606
|
+
},
|
|
1607
|
+
reflection: {
|
|
1608
|
+
status: buffRef.status ?? "idle",
|
|
1609
|
+
inputObservationTokens: buffRef.inputObservationTokens ?? 0,
|
|
1610
|
+
observationTokens: buffRef.observationTokens ?? 0
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
},
|
|
1614
|
+
recordId: d.recordId ?? "",
|
|
1615
|
+
threadId: d.threadId ?? "",
|
|
1616
|
+
stepNumber: d.stepNumber ?? 0,
|
|
1617
|
+
generationCount: d.generationCount ?? 0
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
break;
|
|
1621
|
+
}
|
|
1622
|
+
case "data-om-observation-start": {
|
|
1623
|
+
const payload = chunk.data;
|
|
1624
|
+
if (payload && payload.cycleId) {
|
|
1625
|
+
if (payload.operationType === "observation") {
|
|
1626
|
+
this.emit({
|
|
1627
|
+
type: "om_observation_start",
|
|
1628
|
+
cycleId: payload.cycleId,
|
|
1629
|
+
operationType: payload.operationType,
|
|
1630
|
+
tokensToObserve: payload.tokensToObserve ?? 0
|
|
1631
|
+
});
|
|
1632
|
+
} else if (payload.operationType === "reflection") {
|
|
1633
|
+
this.emit({
|
|
1634
|
+
type: "om_reflection_start",
|
|
1635
|
+
cycleId: payload.cycleId,
|
|
1636
|
+
tokensToReflect: payload.tokensToObserve ?? 0
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
case "data-om-observation-end": {
|
|
1643
|
+
const payload = chunk.data;
|
|
1644
|
+
if (payload && payload.cycleId) {
|
|
1645
|
+
if (payload.operationType === "reflection") {
|
|
1646
|
+
this.emit({
|
|
1647
|
+
type: "om_reflection_end",
|
|
1648
|
+
cycleId: payload.cycleId,
|
|
1649
|
+
durationMs: payload.durationMs ?? 0,
|
|
1650
|
+
compressedTokens: payload.observationTokens ?? 0,
|
|
1651
|
+
observations: payload.observations
|
|
1652
|
+
});
|
|
1653
|
+
} else {
|
|
1654
|
+
this.emit({
|
|
1655
|
+
type: "om_observation_end",
|
|
1656
|
+
cycleId: payload.cycleId,
|
|
1657
|
+
durationMs: payload.durationMs ?? 0,
|
|
1658
|
+
tokensObserved: payload.tokensObserved ?? 0,
|
|
1659
|
+
observationTokens: payload.observationTokens ?? 0,
|
|
1660
|
+
observations: payload.observations,
|
|
1661
|
+
currentTask: payload.currentTask,
|
|
1662
|
+
suggestedResponse: payload.suggestedResponse
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
break;
|
|
1667
|
+
}
|
|
1668
|
+
case "data-om-observation-failed": {
|
|
1669
|
+
const payload = chunk.data;
|
|
1670
|
+
if (payload) {
|
|
1671
|
+
if (payload.operationType === "reflection") {
|
|
1672
|
+
this.emit({
|
|
1673
|
+
type: "om_reflection_failed",
|
|
1674
|
+
cycleId: payload.cycleId ?? "unknown",
|
|
1675
|
+
error: payload.error ?? "Unknown error",
|
|
1676
|
+
durationMs: payload.durationMs ?? 0
|
|
1677
|
+
});
|
|
1678
|
+
} else {
|
|
1679
|
+
this.emit({
|
|
1680
|
+
type: "om_observation_failed",
|
|
1681
|
+
cycleId: payload.cycleId ?? "unknown",
|
|
1682
|
+
error: payload.error ?? "Unknown error",
|
|
1683
|
+
durationMs: payload.durationMs ?? 0
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
// Async buffering lifecycle
|
|
1690
|
+
case "data-om-buffering-start": {
|
|
1691
|
+
const payload = chunk.data;
|
|
1692
|
+
if (payload && payload.cycleId) {
|
|
1693
|
+
this.emit({
|
|
1694
|
+
type: "om_buffering_start",
|
|
1695
|
+
cycleId: payload.cycleId,
|
|
1696
|
+
operationType: payload.operationType ?? "observation",
|
|
1697
|
+
tokensToBuffer: payload.tokensToBuffer ?? 0
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
case "data-om-buffering-end": {
|
|
1703
|
+
const payload = chunk.data;
|
|
1704
|
+
if (payload && payload.cycleId) {
|
|
1705
|
+
this.emit({
|
|
1706
|
+
type: "om_buffering_end",
|
|
1707
|
+
cycleId: payload.cycleId,
|
|
1708
|
+
operationType: payload.operationType ?? "observation",
|
|
1709
|
+
tokensBuffered: payload.tokensBuffered ?? 0,
|
|
1710
|
+
bufferedTokens: payload.bufferedTokens ?? 0,
|
|
1711
|
+
observations: payload.observations
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
case "data-om-buffering-failed": {
|
|
1717
|
+
const payload = chunk.data;
|
|
1718
|
+
if (payload && payload.cycleId) {
|
|
1719
|
+
this.emit({
|
|
1720
|
+
type: "om_buffering_failed",
|
|
1721
|
+
cycleId: payload.cycleId,
|
|
1722
|
+
operationType: payload.operationType ?? "observation",
|
|
1723
|
+
error: payload.error ?? "Unknown error"
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
case "data-om-activation": {
|
|
1729
|
+
const payload = chunk.data;
|
|
1730
|
+
if (payload && payload.cycleId) {
|
|
1731
|
+
this.emit({
|
|
1732
|
+
type: "om_activation",
|
|
1733
|
+
cycleId: payload.cycleId,
|
|
1734
|
+
operationType: payload.operationType ?? "observation",
|
|
1735
|
+
chunksActivated: payload.chunksActivated ?? 0,
|
|
1736
|
+
tokensActivated: payload.tokensActivated ?? 0,
|
|
1737
|
+
observationTokens: payload.observationTokens ?? 0,
|
|
1738
|
+
messagesActivated: payload.messagesActivated ?? 0,
|
|
1739
|
+
generationCount: payload.generationCount ?? 0
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
break;
|
|
1743
|
+
}
|
|
1346
1744
|
}
|
|
1347
1745
|
}
|
|
1348
1746
|
this.emit({ type: "message_end", message: currentMessage });
|
|
@@ -1367,20 +1765,20 @@ var Harness = class {
|
|
|
1367
1765
|
/**
|
|
1368
1766
|
* Steer the agent mid-stream: aborts current run and sends a new message.
|
|
1369
1767
|
*/
|
|
1370
|
-
async steer(content) {
|
|
1768
|
+
async steer({ content }) {
|
|
1371
1769
|
this.abort();
|
|
1372
1770
|
this.followUpQueue = [];
|
|
1373
|
-
await this.sendMessage(content);
|
|
1771
|
+
await this.sendMessage({ content });
|
|
1374
1772
|
}
|
|
1375
1773
|
/**
|
|
1376
1774
|
* Queue a follow-up message to be processed after the current operation completes.
|
|
1377
1775
|
*/
|
|
1378
|
-
async followUp(content) {
|
|
1776
|
+
async followUp({ content }) {
|
|
1379
1777
|
if (this.isRunning()) {
|
|
1380
1778
|
this.followUpQueue.push(content);
|
|
1381
1779
|
this.emit({ type: "follow_up_queued", count: this.followUpQueue.length });
|
|
1382
1780
|
} else {
|
|
1383
|
-
await this.sendMessage(content);
|
|
1781
|
+
await this.sendMessage({ content });
|
|
1384
1782
|
}
|
|
1385
1783
|
}
|
|
1386
1784
|
getFollowUpCount() {
|
|
@@ -1396,14 +1794,14 @@ var Harness = class {
|
|
|
1396
1794
|
* Respond to a pending tool approval from the UI.
|
|
1397
1795
|
* "always_allow_category" grants the tool's category for the rest of the session, then approves.
|
|
1398
1796
|
*/
|
|
1399
|
-
|
|
1797
|
+
respondToToolApproval({ decision }) {
|
|
1400
1798
|
if (!this.pendingApprovalResolve) return;
|
|
1401
1799
|
if (decision === "always_allow_category") {
|
|
1402
1800
|
const tn = this.pendingApprovalToolName;
|
|
1403
1801
|
if (tn) {
|
|
1404
|
-
const category = this.getToolCategory(tn);
|
|
1802
|
+
const category = this.getToolCategory({ toolName: tn });
|
|
1405
1803
|
if (category) {
|
|
1406
|
-
this.grantSessionCategory(category);
|
|
1804
|
+
this.grantSessionCategory({ category });
|
|
1407
1805
|
}
|
|
1408
1806
|
}
|
|
1409
1807
|
this.pendingApprovalResolve("approve");
|
|
@@ -1419,14 +1817,14 @@ var Harness = class {
|
|
|
1419
1817
|
* Register a pending question resolver.
|
|
1420
1818
|
* Called by agent tools (e.g., ask_user) to pause execution until the UI responds.
|
|
1421
1819
|
*/
|
|
1422
|
-
registerQuestion(questionId, resolve) {
|
|
1820
|
+
registerQuestion({ questionId, resolve }) {
|
|
1423
1821
|
this.pendingQuestions.set(questionId, resolve);
|
|
1424
1822
|
}
|
|
1425
1823
|
/**
|
|
1426
1824
|
* Resolve a pending question with the user's answer.
|
|
1427
1825
|
* Called by the UI when the user responds to a question dialog.
|
|
1428
1826
|
*/
|
|
1429
|
-
respondToQuestion(questionId, answer) {
|
|
1827
|
+
respondToQuestion({ questionId, answer }) {
|
|
1430
1828
|
const resolve = this.pendingQuestions.get(questionId);
|
|
1431
1829
|
if (resolve) {
|
|
1432
1830
|
this.pendingQuestions.delete(questionId);
|
|
@@ -1437,7 +1835,10 @@ var Harness = class {
|
|
|
1437
1835
|
* Register a pending plan approval resolver.
|
|
1438
1836
|
* Called by agent tools (e.g., submit_plan) to pause execution until approval.
|
|
1439
1837
|
*/
|
|
1440
|
-
registerPlanApproval(
|
|
1838
|
+
registerPlanApproval({
|
|
1839
|
+
planId,
|
|
1840
|
+
resolve
|
|
1841
|
+
}) {
|
|
1441
1842
|
this.pendingPlanApprovals.set(planId, resolve);
|
|
1442
1843
|
}
|
|
1443
1844
|
/**
|
|
@@ -1445,13 +1846,16 @@ var Harness = class {
|
|
|
1445
1846
|
* On approval: switches to the default mode, then resolves the promise.
|
|
1446
1847
|
* On rejection: resolves with feedback (stays in current mode).
|
|
1447
1848
|
*/
|
|
1448
|
-
async respondToPlanApproval(
|
|
1849
|
+
async respondToPlanApproval({
|
|
1850
|
+
planId,
|
|
1851
|
+
response
|
|
1852
|
+
}) {
|
|
1449
1853
|
const resolve = this.pendingPlanApprovals.get(planId);
|
|
1450
1854
|
if (!resolve) return;
|
|
1451
1855
|
if (response.action === "approved") {
|
|
1452
1856
|
const defaultMode = this.config.modes.find((m) => m.default) ?? this.config.modes[0];
|
|
1453
1857
|
if (defaultMode && defaultMode.id !== this.currentModeId) {
|
|
1454
|
-
await this.switchMode(defaultMode.id);
|
|
1858
|
+
await this.switchMode({ modeId: defaultMode.id });
|
|
1455
1859
|
}
|
|
1456
1860
|
}
|
|
1457
1861
|
this.pendingPlanApprovals.delete(planId);
|
|
@@ -1535,7 +1939,9 @@ var Harness = class {
|
|
|
1535
1939
|
async buildToolsets(requestContext) {
|
|
1536
1940
|
const builtInTools = {
|
|
1537
1941
|
ask_user: askUserTool,
|
|
1538
|
-
submit_plan: submitPlanTool
|
|
1942
|
+
submit_plan: submitPlanTool,
|
|
1943
|
+
task_write: taskWriteTool,
|
|
1944
|
+
task_check: taskCheckTool
|
|
1539
1945
|
};
|
|
1540
1946
|
let resolvedHarnessTools = void 0;
|
|
1541
1947
|
if (this.config.tools) {
|
|
@@ -1574,9 +1980,9 @@ var Harness = class {
|
|
|
1574
1980
|
abortSignal: this.abortController?.signal,
|
|
1575
1981
|
workspace: this.workspace,
|
|
1576
1982
|
emitEvent: (event) => this.emit(event),
|
|
1577
|
-
registerQuestion: (
|
|
1578
|
-
registerPlanApproval: (
|
|
1579
|
-
getSubagentModelId: (
|
|
1983
|
+
registerQuestion: (params) => this.registerQuestion(params),
|
|
1984
|
+
registerPlanApproval: (params) => this.registerPlanApproval(params),
|
|
1985
|
+
getSubagentModelId: (params) => this.getSubagentModelId(params)
|
|
1580
1986
|
};
|
|
1581
1987
|
const requestContext = new RequestContext([["harness", harnessContext]]);
|
|
1582
1988
|
if (this.workspaceFn) {
|
|
@@ -1658,7 +2064,7 @@ var Harness = class {
|
|
|
1658
2064
|
}
|
|
1659
2065
|
}
|
|
1660
2066
|
registerHeartbeat(handler) {
|
|
1661
|
-
void this.removeHeartbeat(handler.id);
|
|
2067
|
+
void this.removeHeartbeat({ id: handler.id });
|
|
1662
2068
|
const run = async () => {
|
|
1663
2069
|
try {
|
|
1664
2070
|
await handler.handler();
|
|
@@ -1673,7 +2079,7 @@ var Harness = class {
|
|
|
1673
2079
|
timer.unref();
|
|
1674
2080
|
this.heartbeatTimers.set(handler.id, { timer, shutdown: handler.shutdown });
|
|
1675
2081
|
}
|
|
1676
|
-
async removeHeartbeat(id) {
|
|
2082
|
+
async removeHeartbeat({ id }) {
|
|
1677
2083
|
const entry = this.heartbeatTimers.get(id);
|
|
1678
2084
|
if (entry) {
|
|
1679
2085
|
clearInterval(entry.timer);
|
|
@@ -1718,6 +2124,6 @@ var Harness = class {
|
|
|
1718
2124
|
}
|
|
1719
2125
|
};
|
|
1720
2126
|
|
|
1721
|
-
export { Harness, askUserTool, parseSubagentMeta, submitPlanTool };
|
|
2127
|
+
export { Harness, askUserTool, parseSubagentMeta, submitPlanTool, taskCheckTool, taskWriteTool };
|
|
1722
2128
|
//# sourceMappingURL=index.js.map
|
|
1723
2129
|
//# sourceMappingURL=index.js.map
|