@mcp-abap-adt/llm-agent-libs 33.1.0 → 35.0.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/README.md +72 -22
- package/dist/adapters/llm-adapter.d.ts +2 -2
- package/dist/adapters/llm-adapter.d.ts.map +1 -1
- package/dist/adapters/llm-adapter.js +51 -34
- package/dist/adapters/llm-adapter.js.map +1 -1
- package/dist/adapters/llm-provider-bridge.d.ts.map +1 -1
- package/dist/adapters/llm-provider-bridge.js +13 -20
- package/dist/adapters/llm-provider-bridge.js.map +1 -1
- package/dist/adapters/normalize-finish-reason.d.ts +3 -0
- package/dist/adapters/normalize-finish-reason.d.ts.map +1 -0
- package/dist/adapters/normalize-finish-reason.js +17 -0
- package/dist/adapters/normalize-finish-reason.js.map +1 -0
- package/dist/agent/rag-helpers.d.ts +4 -6
- package/dist/agent/rag-helpers.d.ts.map +1 -1
- package/dist/agent/rag-helpers.js +3 -43
- package/dist/agent/rag-helpers.js.map +1 -1
- package/dist/agent/rag-orchestrator-types.d.ts +3 -0
- package/dist/agent/rag-orchestrator-types.d.ts.map +1 -1
- package/dist/agent/rag-orchestrator.d.ts +0 -1
- package/dist/agent/rag-orchestrator.d.ts.map +1 -1
- package/dist/agent/rag-orchestrator.js +9 -29
- package/dist/agent/rag-orchestrator.js.map +1 -1
- package/dist/agent.d.ts +12 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +178 -245
- package/dist/agent.js.map +1 -1
- package/dist/builder-types.d.ts +1 -1
- package/dist/builder-types.d.ts.map +1 -1
- package/dist/builder.d.ts +7 -7
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +16 -26
- package/dist/builder.js.map +1 -1
- package/dist/config/config-watcher.d.ts +3 -0
- package/dist/config/config-watcher.d.ts.map +1 -1
- package/dist/config/config-watcher.js +1 -0
- package/dist/config/config-watcher.js.map +1 -1
- package/dist/context/context-assembler.d.ts.map +1 -1
- package/dist/context/context-assembler.js +23 -23
- package/dist/context/context-assembler.js.map +1 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.d.ts +2 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.d.ts.map +1 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.js +46 -22
- package/dist/coordinator/adaptive/adaptive-interpreter.js.map +1 -1
- package/dist/coordinator/adaptive/compose-step-input.d.ts +1 -5
- package/dist/coordinator/adaptive/compose-step-input.d.ts.map +1 -1
- package/dist/coordinator/adaptive/compose-step-input.js +6 -17
- package/dist/coordinator/adaptive/compose-step-input.js.map +1 -1
- package/dist/coordinator/adaptive/index.d.ts +2 -2
- package/dist/coordinator/adaptive/index.d.ts.map +1 -1
- package/dist/coordinator/adaptive/index.js +2 -2
- package/dist/coordinator/adaptive/index.js.map +1 -1
- package/dist/coordinator/adaptive/llm-adaptive-controller.d.ts.map +1 -1
- package/dist/coordinator/adaptive/llm-adaptive-controller.js +14 -20
- package/dist/coordinator/adaptive/llm-adaptive-controller.js.map +1 -1
- package/dist/coordinator/adaptive/parse-plan.d.ts +0 -2
- package/dist/coordinator/adaptive/parse-plan.d.ts.map +1 -1
- package/dist/coordinator/adaptive/parse-plan.js +4 -6
- package/dist/coordinator/adaptive/parse-plan.js.map +1 -1
- package/dist/coordinator/dag/dag-plan-interpreter.d.ts.map +1 -1
- package/dist/coordinator/dag/dag-plan-interpreter.js +7 -1
- package/dist/coordinator/dag/dag-plan-interpreter.js.map +1 -1
- package/dist/coordinator/dag/llm-finalizer.d.ts.map +1 -1
- package/dist/coordinator/dag/llm-finalizer.js +5 -2
- package/dist/coordinator/dag/llm-finalizer.js.map +1 -1
- package/dist/coordinator/dialogue/dialogue-session.d.ts +2 -3
- package/dist/coordinator/dialogue/dialogue-session.d.ts.map +1 -1
- package/dist/coordinator/dialogue/dialogue-session.js +103 -64
- package/dist/coordinator/dialogue/dialogue-session.js.map +1 -1
- package/dist/coordinator/dialogue/index.d.ts +2 -2
- package/dist/coordinator/dialogue/index.d.ts.map +1 -1
- package/dist/coordinator/dialogue/index.js +2 -2
- package/dist/coordinator/dialogue/index.js.map +1 -1
- package/dist/coordinator/dialogue/planner-context-builder.d.ts +2 -3
- package/dist/coordinator/dialogue/planner-context-builder.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-context-builder.js +13 -73
- package/dist/coordinator/dialogue/planner-context-builder.js.map +1 -1
- package/dist/coordinator/dialogue/planner-retrieval.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-retrieval.js +13 -4
- package/dist/coordinator/dialogue/planner-retrieval.js.map +1 -1
- package/dist/coordinator/dialogue/planner-scope.d.ts +4 -1
- package/dist/coordinator/dialogue/planner-scope.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-scope.js.map +1 -1
- package/dist/coordinator/dialogue/planner-tools-client.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-tools-client.js +47 -26
- package/dist/coordinator/dialogue/planner-tools-client.js.map +1 -1
- package/dist/coordinator/dialogue/profile-plan-author.d.ts.map +1 -1
- package/dist/coordinator/dialogue/profile-plan-author.js +5 -5
- package/dist/coordinator/dialogue/profile-plan-author.js.map +1 -1
- package/dist/coordinator/dialogue/profile-resolver.d.ts.map +1 -1
- package/dist/coordinator/dialogue/profile-resolver.js +8 -0
- package/dist/coordinator/dialogue/profile-resolver.js.map +1 -1
- package/dist/coordinator/dialogue/structured-plan.d.ts +1 -1
- package/dist/coordinator/dialogue/structured-plan.d.ts.map +1 -1
- package/dist/coordinator/dialogue/structured-plan.js +6 -7
- package/dist/coordinator/dialogue/structured-plan.js.map +1 -1
- package/dist/coordinator/dialogue/submit-report-tool.d.ts +1 -1
- package/dist/coordinator/dialogue/submit-report-tool.d.ts.map +1 -1
- package/dist/coordinator/dialogue/submit-report-tool.js +4 -17
- package/dist/coordinator/dialogue/submit-report-tool.js.map +1 -1
- package/dist/coordinator/dialogue/task-board.d.ts +11 -3
- package/dist/coordinator/dialogue/task-board.d.ts.map +1 -1
- package/dist/coordinator/dialogue/task-board.js +42 -12
- package/dist/coordinator/dialogue/task-board.js.map +1 -1
- package/dist/coordinator/dialogue/task-reference.d.ts +1 -3
- package/dist/coordinator/dialogue/task-reference.d.ts.map +1 -1
- package/dist/coordinator/dialogue/task-reference.js +3 -10
- package/dist/coordinator/dialogue/task-reference.js.map +1 -1
- package/dist/coordinator/dialogue/tool-trace-render.d.ts.map +1 -1
- package/dist/coordinator/dialogue/tool-trace-render.js +9 -29
- package/dist/coordinator/dialogue/tool-trace-render.js.map +1 -1
- package/dist/coordinator/dispatch/self.d.ts.map +1 -1
- package/dist/coordinator/dispatch/self.js +41 -26
- package/dist/coordinator/dispatch/self.js.map +1 -1
- package/dist/coordinator/dispatch/subagent.d.ts.map +1 -1
- package/dist/coordinator/dispatch/subagent.js +3 -0
- package/dist/coordinator/dispatch/subagent.js.map +1 -1
- package/dist/coordinator/llm-output-truncation.d.ts +3 -0
- package/dist/coordinator/llm-output-truncation.d.ts.map +1 -0
- package/dist/coordinator/llm-output-truncation.js +6 -0
- package/dist/coordinator/llm-output-truncation.js.map +1 -0
- package/dist/coordinator/planning/one-shot.d.ts.map +1 -1
- package/dist/coordinator/planning/one-shot.js +4 -0
- package/dist/coordinator/planning/one-shot.js.map +1 -1
- package/dist/coordinator/planning/replan-on-error.d.ts.map +1 -1
- package/dist/coordinator/planning/replan-on-error.js +5 -1
- package/dist/coordinator/planning/replan-on-error.js.map +1 -1
- package/dist/coordinator/stepper/cyclic-react-executor.d.ts.map +1 -1
- package/dist/coordinator/stepper/cyclic-react-executor.js +51 -37
- package/dist/coordinator/stepper/cyclic-react-executor.js.map +1 -1
- package/dist/coordinator/stepper/llm-evaluator.d.ts.map +1 -1
- package/dist/coordinator/stepper/llm-evaluator.js +12 -4
- package/dist/coordinator/stepper/llm-evaluator.js.map +1 -1
- package/dist/coordinator/stepper/llm-stepper-planner.d.ts.map +1 -1
- package/dist/coordinator/stepper/llm-stepper-planner.js +16 -5
- package/dist/coordinator/stepper/llm-stepper-planner.js.map +1 -1
- package/dist/coordinator/stepper/llm-task-formalizer.d.ts +2 -3
- package/dist/coordinator/stepper/llm-task-formalizer.d.ts.map +1 -1
- package/dist/coordinator/stepper/llm-task-formalizer.js +14 -8
- package/dist/coordinator/stepper/llm-task-formalizer.js.map +1 -1
- package/dist/coordinator/stepper/need-resolver.d.ts.map +1 -1
- package/dist/coordinator/stepper/need-resolver.js +10 -1
- package/dist/coordinator/stepper/need-resolver.js.map +1 -1
- package/dist/coordinator/stepper/root-finalizer.d.ts.map +1 -1
- package/dist/coordinator/stepper/root-finalizer.js +8 -3
- package/dist/coordinator/stepper/root-finalizer.js.map +1 -1
- package/dist/coordinator/stepper/stepper-interpreter.d.ts.map +1 -1
- package/dist/coordinator/stepper/stepper-interpreter.js +8 -19
- package/dist/coordinator/stepper/stepper-interpreter.js.map +1 -1
- package/dist/history/history-memory.d.ts +1 -0
- package/dist/history/history-memory.d.ts.map +1 -1
- package/dist/history/history-memory.js +5 -1
- package/dist/history/history-memory.js.map +1 -1
- package/dist/history/history-summarizer.js +1 -1
- package/dist/history/history-summarizer.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/pipeline.d.ts +1 -1
- package/dist/interfaces/pipeline.d.ts.map +1 -1
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.d.ts +1 -1
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.d.ts.map +1 -1
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.js +6 -3
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.js.map +1 -1
- package/dist/pipeline/context/tool-loop-control-history.d.ts +15 -0
- package/dist/pipeline/context/tool-loop-control-history.d.ts.map +1 -0
- package/dist/pipeline/context/tool-loop-control-history.js +72 -0
- package/dist/pipeline/context/tool-loop-control-history.js.map +1 -0
- package/dist/pipeline/context.d.ts +5 -2
- package/dist/pipeline/context.d.ts.map +1 -1
- package/dist/pipeline/default-pipeline.d.ts +2 -2
- package/dist/pipeline/default-pipeline.d.ts.map +1 -1
- package/dist/pipeline/default-pipeline.js +7 -7
- package/dist/pipeline/default-pipeline.js.map +1 -1
- package/dist/pipeline/executor.d.ts.map +1 -1
- package/dist/pipeline/executor.js +6 -0
- package/dist/pipeline/executor.js.map +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.d.ts +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.js +42 -46
- package/dist/pipeline/handlers/adaptive-coordinator.js.map +1 -1
- package/dist/pipeline/handlers/assemble.d.ts +0 -9
- package/dist/pipeline/handlers/assemble.d.ts.map +1 -1
- package/dist/pipeline/handlers/assemble.js +7 -11
- package/dist/pipeline/handlers/assemble.js.map +1 -1
- package/dist/pipeline/handlers/coordinator.d.ts +1 -0
- package/dist/pipeline/handlers/coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/coordinator.js +39 -7
- package/dist/pipeline/handlers/coordinator.js.map +1 -1
- package/dist/pipeline/handlers/dag-coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/dag-coordinator.js +17 -13
- package/dist/pipeline/handlers/dag-coordinator.js.map +1 -1
- package/dist/pipeline/handlers/history-upsert.d.ts +2 -0
- package/dist/pipeline/handlers/history-upsert.d.ts.map +1 -1
- package/dist/pipeline/handlers/history-upsert.js +6 -1
- package/dist/pipeline/handlers/history-upsert.js.map +1 -1
- package/dist/pipeline/handlers/pass-through.d.ts +5 -3
- package/dist/pipeline/handlers/pass-through.d.ts.map +1 -1
- package/dist/pipeline/handlers/pass-through.js +165 -91
- package/dist/pipeline/handlers/pass-through.js.map +1 -1
- package/dist/pipeline/handlers/subagent.d.ts.map +1 -1
- package/dist/pipeline/handlers/subagent.js +4 -1
- package/dist/pipeline/handlers/subagent.js.map +1 -1
- package/dist/pipeline/handlers/summarize.d.ts +2 -12
- package/dist/pipeline/handlers/summarize.d.ts.map +1 -1
- package/dist/pipeline/handlers/summarize.js +2 -54
- package/dist/pipeline/handlers/summarize.js.map +1 -1
- package/dist/pipeline/handlers/tool-loop-core.d.ts +15 -9
- package/dist/pipeline/handlers/tool-loop-core.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-loop-core.js +128 -59
- package/dist/pipeline/handlers/tool-loop-core.js.map +1 -1
- package/dist/pipeline/handlers/tool-loop.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-loop.js +120 -298
- package/dist/pipeline/handlers/tool-loop.js.map +1 -1
- package/dist/pipeline/handlers/tool-response-round.d.ts +48 -0
- package/dist/pipeline/handlers/tool-response-round.d.ts.map +1 -0
- package/dist/pipeline/handlers/tool-response-round.js +104 -0
- package/dist/pipeline/handlers/tool-response-round.js.map +1 -0
- package/dist/pipeline/handlers/tool-select.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-select.js +5 -1
- package/dist/pipeline/handlers/tool-select.js.map +1 -1
- package/dist/pipeline/pipeline-to-stream.d.ts.map +1 -1
- package/dist/pipeline/pipeline-to-stream.js +13 -6
- package/dist/pipeline/pipeline-to-stream.js.map +1 -1
- package/dist/policy/caller-identity.d.ts +29 -0
- package/dist/policy/caller-identity.d.ts.map +1 -0
- package/dist/policy/caller-identity.js +79 -0
- package/dist/policy/caller-identity.js.map +1 -0
- package/dist/policy/mixed-tool-call-handler.d.ts +9 -3
- package/dist/policy/mixed-tool-call-handler.d.ts.map +1 -1
- package/dist/policy/mixed-tool-call-handler.js +29 -7
- package/dist/policy/mixed-tool-call-handler.js.map +1 -1
- package/dist/policy/pending-tool-results-registry.d.ts +46 -4
- package/dist/policy/pending-tool-results-registry.d.ts.map +1 -1
- package/dist/policy/pending-tool-results-registry.js +203 -18
- package/dist/policy/pending-tool-results-registry.js.map +1 -1
- package/dist/policy/tool-availability-registry.d.ts +6 -5
- package/dist/policy/tool-availability-registry.d.ts.map +1 -1
- package/dist/policy/tool-availability-registry.js +13 -2
- package/dist/policy/tool-availability-registry.js.map +1 -1
- package/dist/resilience/retry-llm.d.ts +7 -5
- package/dist/resilience/retry-llm.d.ts.map +1 -1
- package/dist/resilience/retry-llm.js +93 -58
- package/dist/resilience/retry-llm.js.map +1 -1
- package/dist/subagent/default-context-builder.d.ts.map +1 -1
- package/dist/subagent/default-context-builder.js +9 -2
- package/dist/subagent/default-context-builder.js.map +1 -1
- package/dist/subagent/direct-llm-subagent.d.ts +1 -1
- package/dist/subagent/direct-llm-subagent.d.ts.map +1 -1
- package/dist/subagent/direct-llm-subagent.js +12 -3
- package/dist/subagent/direct-llm-subagent.js.map +1 -1
- package/dist/subagent/smart-agent-subagent.d.ts.map +1 -1
- package/dist/subagent/smart-agent-subagent.js +8 -5
- package/dist/subagent/smart-agent-subagent.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { addTokenUsage, scopedUsage, } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
import { addTokenUsage, scopedUsage, terminalRunError, } from '@mcp-abap-adt/llm-agent';
|
|
3
3
|
import { DIALOGUE_COORDINATOR_SYSTEM } from './coordinator-prompt.js';
|
|
4
4
|
import { createMemorySignalBus } from './memory-signal-bus.js';
|
|
5
|
-
import { appendRequestMessage,
|
|
5
|
+
import { appendRequestMessage, DefaultPlannerContextBuilder, renderPlannerRetrieval, } from './planner-context-builder.js';
|
|
6
6
|
import { PlannerMemoryWriter } from './planner-memory.js';
|
|
7
7
|
import { composePlannerPrompt, DIALOGUE_PLANNER_SYSTEM, } from './planner-prompt.js';
|
|
8
8
|
import { retrievePlannerContext, validateRetrievalOptions, } from './planner-retrieval.js';
|
|
@@ -10,13 +10,13 @@ import { runInPlannerScope } from './planner-scope.js';
|
|
|
10
10
|
import { PlannerToolsClient } from './planner-tools-client.js';
|
|
11
11
|
import { formatRequestTime, validateTimeZone } from './request-time.js';
|
|
12
12
|
import { applyTaskEvent, checkSourcesCurrent, currentAttemptIds, deliveryChecksPassed, planView, readySteps, recomputePlanStatus, resetStaleCheck, restoreLegacyStep, restoreSuccessfulWork, resultKind, } from './structured-plan.js';
|
|
13
|
-
import { TaskBoard } from './task-board.js';
|
|
14
|
-
import {
|
|
15
|
-
export const DIALOGUE_HISTORY_LIMIT = 200;
|
|
13
|
+
import { TaskBoard, TerminalDialogueError, } from './task-board.js';
|
|
14
|
+
import { taskNotice } from './task-reference.js';
|
|
16
15
|
export class DialogueSession {
|
|
17
16
|
opts;
|
|
18
17
|
board;
|
|
19
18
|
signals;
|
|
19
|
+
plannerCall;
|
|
20
20
|
turnActive = false;
|
|
21
21
|
externalCoordinator = false;
|
|
22
22
|
// Outcomes deferred while no coordinator turn runs accompany the next user.
|
|
@@ -118,6 +118,15 @@ export class DialogueSession {
|
|
|
118
118
|
]),
|
|
119
119
|
];
|
|
120
120
|
}
|
|
121
|
+
requestFailure(request) {
|
|
122
|
+
if (!request)
|
|
123
|
+
return undefined;
|
|
124
|
+
if (request.terminalError) {
|
|
125
|
+
const { message, code } = request.terminalError;
|
|
126
|
+
return new TerminalDialogueError(message, code);
|
|
127
|
+
}
|
|
128
|
+
return this.board.findTerminalError((id) => this.taskRequests.get(id) === request.id);
|
|
129
|
+
}
|
|
121
130
|
beginRequest(text, user) {
|
|
122
131
|
let open = this.openRequest;
|
|
123
132
|
const automatic = user &&
|
|
@@ -131,12 +140,12 @@ export class DialogueSession {
|
|
|
131
140
|
!this.board
|
|
132
141
|
.list()
|
|
133
142
|
.some((task) => task.state === 'queued' || task.state === 'running');
|
|
134
|
-
|
|
143
|
+
const restartAfterFailure = user && this.requestFailure(open) !== undefined;
|
|
144
|
+
if (open && (automatic || restartAfterFailure)) {
|
|
135
145
|
this.updateRequestPlan();
|
|
136
146
|
open.closedAt = this.now();
|
|
137
|
-
delete open.transcript;
|
|
138
147
|
// Preserve the notes sent with raw conversation history.
|
|
139
|
-
if (this.opts.plannerContext !== 'conversation')
|
|
148
|
+
if (restartAfterFailure || this.opts.plannerContext !== 'conversation')
|
|
140
149
|
this.plan = undefined;
|
|
141
150
|
open = undefined;
|
|
142
151
|
}
|
|
@@ -144,27 +153,13 @@ export class DialogueSession {
|
|
|
144
153
|
open = {
|
|
145
154
|
id: `r${++this.requestSeq}`,
|
|
146
155
|
openedAt: this.now(),
|
|
147
|
-
text
|
|
156
|
+
text,
|
|
148
157
|
transcript: [],
|
|
149
158
|
};
|
|
150
159
|
this.requests.push(open);
|
|
151
160
|
}
|
|
152
|
-
this.retainRequests();
|
|
153
161
|
return open;
|
|
154
162
|
}
|
|
155
|
-
retainRequests() {
|
|
156
|
-
for (const record of this.requests) {
|
|
157
|
-
record.text = record.text.slice(0, 20_000);
|
|
158
|
-
if (record.closedAt !== undefined)
|
|
159
|
-
delete record.transcript;
|
|
160
|
-
}
|
|
161
|
-
while (this.requests.length > 200) {
|
|
162
|
-
const index = this.requests.findIndex((record) => record.closedAt !== undefined);
|
|
163
|
-
if (index < 0)
|
|
164
|
-
break;
|
|
165
|
-
this.requests.splice(index, 1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
163
|
indexReply(message, request, memoryText = message.text) {
|
|
169
164
|
if (message.text.trim() === 'NO_MESSAGE')
|
|
170
165
|
return;
|
|
@@ -371,6 +366,11 @@ export class DialogueSession {
|
|
|
371
366
|
if (owner === this.openRequest?.id) {
|
|
372
367
|
applyTaskEvent(this.plan, event, this.taskSteps);
|
|
373
368
|
}
|
|
369
|
+
const plannerCall = this.plannerCall;
|
|
370
|
+
if (plannerCall &&
|
|
371
|
+
plannerCall.requestId === owner &&
|
|
372
|
+
event.task.terminalErrorCode !== undefined)
|
|
373
|
+
plannerCall.stop.abort();
|
|
374
374
|
recomputePlanStatus(this.plan);
|
|
375
375
|
this.changed();
|
|
376
376
|
// Only outcomes wake the planner; a start is visible via list_tasks.
|
|
@@ -386,10 +386,9 @@ export class DialogueSession {
|
|
|
386
386
|
const session = new DialogueSession(opts);
|
|
387
387
|
const state = await opts.store?.load(opts.id);
|
|
388
388
|
if (state) {
|
|
389
|
-
session.conversation = structuredClone(state.conversation
|
|
390
|
-
const offset = state.conversation.length - session.conversation.length;
|
|
389
|
+
session.conversation = structuredClone(state.conversation);
|
|
391
390
|
session.conversation.forEach((message, index) => {
|
|
392
|
-
if (state.conversationLeadingActions?.includes(index
|
|
391
|
+
if (state.conversationLeadingActions?.includes(index))
|
|
393
392
|
session.leadingActions.add(message);
|
|
394
393
|
});
|
|
395
394
|
session.conversation = session.conversation.reduce((messages, message) => {
|
|
@@ -400,7 +399,6 @@ export class DialogueSession {
|
|
|
400
399
|
messages.push(message);
|
|
401
400
|
return messages;
|
|
402
401
|
}, []);
|
|
403
|
-
session.trim();
|
|
404
402
|
session.plan =
|
|
405
403
|
typeof state.plan === 'string'
|
|
406
404
|
? {
|
|
@@ -419,9 +417,8 @@ export class DialogueSession {
|
|
|
419
417
|
{
|
|
420
418
|
id: 'r1',
|
|
421
419
|
openedAt: state.savedAt,
|
|
422
|
-
text: state.conversation
|
|
423
|
-
|
|
424
|
-
?.content?.slice(0, 20_000) ?? '',
|
|
420
|
+
text: state.conversation.find((message) => message.role === 'user')
|
|
421
|
+
?.content ?? '',
|
|
425
422
|
transcript: [],
|
|
426
423
|
legacy: true,
|
|
427
424
|
lastTurnOk: true,
|
|
@@ -429,16 +426,18 @@ export class DialogueSession {
|
|
|
429
426
|
]).map((record) => ({
|
|
430
427
|
id: record.id,
|
|
431
428
|
openedAt: record.openedAt,
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
text: record.text.slice(0, 20_000),
|
|
429
|
+
transcript: structuredClone(record.transcript ?? []),
|
|
430
|
+
...(record.closedAt === undefined ? {} : { closedAt: record.closedAt }),
|
|
431
|
+
text: record.text,
|
|
436
432
|
...(Object.hasOwn(record, 'plan')
|
|
437
433
|
? { plan: structuredClone(record.plan) }
|
|
438
434
|
: {}),
|
|
439
435
|
...(Object.hasOwn(record, 'lastTurnOk')
|
|
440
436
|
? { lastTurnOk: record.lastTurnOk }
|
|
441
437
|
: {}),
|
|
438
|
+
...(record.terminalError
|
|
439
|
+
? { terminalError: { ...record.terminalError } }
|
|
440
|
+
: {}),
|
|
442
441
|
...(Object.hasOwn(record, 'resolvedFailures')
|
|
443
442
|
? { resolvedFailures: structuredClone(record.resolvedFailures) }
|
|
444
443
|
: {}),
|
|
@@ -452,12 +451,10 @@ export class DialogueSession {
|
|
|
452
451
|
for (const message of state.conversation)
|
|
453
452
|
appendRequestMessage(legacy, message);
|
|
454
453
|
}
|
|
454
|
+
session.requestSeq = state.requestSeq ?? 0;
|
|
455
455
|
for (const record of session.requests) {
|
|
456
|
-
|
|
457
|
-
boundRequestTranscript(record);
|
|
456
|
+
session.requestSeq = Math.max(session.requestSeq, Number(record.id.slice(1)) || 0);
|
|
458
457
|
}
|
|
459
|
-
session.requestSeq = Math.max(state.requestSeq ?? 0, ...session.requests.map((record) => Number(record.id.slice(1)) || 0));
|
|
460
|
-
session.retainRequests();
|
|
461
458
|
session.savedAt = state.savedAt;
|
|
462
459
|
for (const [id, owner] of Object.entries(state.taskRequests ?? {}))
|
|
463
460
|
session.taskRequests.set(id, owner);
|
|
@@ -527,6 +524,11 @@ export class DialogueSession {
|
|
|
527
524
|
}
|
|
528
525
|
createPlannerScope(request, options = {}) {
|
|
529
526
|
this.validateCaller(options);
|
|
527
|
+
const assertRequestCanContinue = () => {
|
|
528
|
+
const terminal = this.requestFailure(request ?? this.openRequest);
|
|
529
|
+
if (terminal)
|
|
530
|
+
throw terminal;
|
|
531
|
+
};
|
|
530
532
|
return {
|
|
531
533
|
planAuthor: this.opts.planAuthor,
|
|
532
534
|
toolTrust: this.opts.toolTrust,
|
|
@@ -549,6 +551,13 @@ export class DialogueSession {
|
|
|
549
551
|
this.taskRequests.set(id, owner.id);
|
|
550
552
|
},
|
|
551
553
|
recordAction: () => this.changed(),
|
|
554
|
+
beforeTool: (name) => {
|
|
555
|
+
if (name === 'plan_create' ||
|
|
556
|
+
name === 'plan_revise' ||
|
|
557
|
+
name === 'plan_update')
|
|
558
|
+
assertRequestCanContinue();
|
|
559
|
+
},
|
|
560
|
+
beforeDelegate: assertRequestCanContinue,
|
|
552
561
|
board: this.board,
|
|
553
562
|
signal: options.signal,
|
|
554
563
|
requestStartedAt: request?.openedAt,
|
|
@@ -641,6 +650,10 @@ export class DialogueSession {
|
|
|
641
650
|
const events = this.liveEvents(user ? this.deferredEvents.splice(0) : this.events.splice(0));
|
|
642
651
|
if (!user && !events.length)
|
|
643
652
|
continue;
|
|
653
|
+
if (!user && this.openRequest?.terminalError) {
|
|
654
|
+
await this.persist();
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
644
657
|
const notes = this.eventNotes(events);
|
|
645
658
|
const text = user ? [user.text, notes].filter(Boolean).join('\n') : notes;
|
|
646
659
|
const trigger = user ? 'user' : 'event';
|
|
@@ -679,7 +692,9 @@ export class DialogueSession {
|
|
|
679
692
|
const previousRequest = this.openRequest;
|
|
680
693
|
const previousPlan = this.plan;
|
|
681
694
|
const waitingAtEntry = this.plan?.status === 'waiting_user';
|
|
682
|
-
let request = this.beginRequest(user?.text ?? text, user !== undefined &&
|
|
695
|
+
let request = this.beginRequest(user?.text ?? text, user !== undefined &&
|
|
696
|
+
(consumed.length === 0 ||
|
|
697
|
+
this.requestFailure(previousRequest) !== undefined));
|
|
683
698
|
const entryTurnOk = request.lastTurnOk;
|
|
684
699
|
request.lastTurnOk = false;
|
|
685
700
|
const turnStartedAt = this.now();
|
|
@@ -713,14 +728,20 @@ export class DialogueSession {
|
|
|
713
728
|
}
|
|
714
729
|
else
|
|
715
730
|
this.appendInput(text, 'events');
|
|
716
|
-
this.trim();
|
|
717
731
|
try {
|
|
732
|
+
const assertRequestCanContinue = () => {
|
|
733
|
+
const terminal = this.requestFailure(request);
|
|
734
|
+
if (terminal)
|
|
735
|
+
throw terminal;
|
|
736
|
+
};
|
|
737
|
+
assertRequestCanContinue();
|
|
718
738
|
const projected = new DefaultPlannerContextBuilder().build({
|
|
719
739
|
open: request,
|
|
720
740
|
memory: [],
|
|
721
741
|
knowledge: [],
|
|
722
742
|
notes: [],
|
|
723
743
|
});
|
|
744
|
+
// Legacy persisted conversations can still contain the old markers.
|
|
724
745
|
const elided = projected.some((message) => /\[(?:elided|cut:|stored cut:|dropped) /.test(message.content ?? ''));
|
|
725
746
|
let retrieved = await retrievePlannerContext(this.opts, this.opts.id, request.id, user
|
|
726
747
|
? text
|
|
@@ -743,6 +764,7 @@ export class DialogueSession {
|
|
|
743
764
|
let didRestart = false;
|
|
744
765
|
for (let correction = 0;; correction++) {
|
|
745
766
|
const callStop = new AbortController();
|
|
767
|
+
let toolFailure;
|
|
746
768
|
let restarting = false;
|
|
747
769
|
let delivered = false;
|
|
748
770
|
let toolCount = 0;
|
|
@@ -759,7 +781,6 @@ export class DialogueSession {
|
|
|
759
781
|
this.updateRequestPlan();
|
|
760
782
|
this.resolveFailures(request);
|
|
761
783
|
request.closedAt = this.now();
|
|
762
|
-
delete request.transcript;
|
|
763
784
|
request.lastTurnOk = entryTurnOk;
|
|
764
785
|
this.memoryWriter?.enqueue('planner-plan', request.id, request.id, this.plan?.steps
|
|
765
786
|
.map((step) => `${step.goal} — ${step.state} — ${step.note ?? ''}`)
|
|
@@ -784,7 +805,6 @@ export class DialogueSession {
|
|
|
784
805
|
didRestart = true;
|
|
785
806
|
restarting = true;
|
|
786
807
|
callStop.abort();
|
|
787
|
-
this.retainRequests();
|
|
788
808
|
this.changed();
|
|
789
809
|
};
|
|
790
810
|
let planner = this.opts.planner;
|
|
@@ -849,12 +869,21 @@ export class DialogueSession {
|
|
|
849
869
|
let lastIterationText = '';
|
|
850
870
|
let lastIterationPartials = [];
|
|
851
871
|
let finalIteration = false;
|
|
872
|
+
assertRequestCanContinue();
|
|
873
|
+
this.plannerCall = { requestId: request.id, stop: callStop };
|
|
852
874
|
const result = await runInPlannerScope({
|
|
853
875
|
...this.createPlannerScope(request, {
|
|
854
876
|
...user?.opts,
|
|
855
877
|
usage: this.turnUsage,
|
|
856
878
|
}),
|
|
879
|
+
onTerminalError: (error) => {
|
|
880
|
+
toolFailure ??= error;
|
|
881
|
+
callStop.abort();
|
|
882
|
+
},
|
|
857
883
|
beforeTool: (name) => {
|
|
884
|
+
if (toolFailure)
|
|
885
|
+
throw toolFailure;
|
|
886
|
+
assertRequestCanContinue();
|
|
858
887
|
if ((reserved || restarting) &&
|
|
859
888
|
(name !== 'new_request' || !reserved || restartDelivered))
|
|
860
889
|
throw new Error('new request started; continue in the next call');
|
|
@@ -911,6 +940,9 @@ export class DialogueSession {
|
|
|
911
940
|
output = result.value;
|
|
912
941
|
}
|
|
913
942
|
catch (error) {
|
|
943
|
+
const terminal = terminalRunError(error);
|
|
944
|
+
if (terminal)
|
|
945
|
+
throw terminal;
|
|
914
946
|
throw new Error(`task ${id} storage read failed: ${String(error)}`);
|
|
915
947
|
}
|
|
916
948
|
}
|
|
@@ -1017,6 +1049,12 @@ export class DialogueSession {
|
|
|
1017
1049
|
user?.opts.onPartial?.(chunk);
|
|
1018
1050
|
},
|
|
1019
1051
|
})).catch((error) => {
|
|
1052
|
+
if (toolFailure)
|
|
1053
|
+
throw toolFailure;
|
|
1054
|
+
assertRequestCanContinue();
|
|
1055
|
+
const terminal = terminalRunError(error);
|
|
1056
|
+
if (terminal)
|
|
1057
|
+
throw terminal;
|
|
1020
1058
|
if ((!waitStop.signal.aborted && !restarting) ||
|
|
1021
1059
|
user?.opts.signal?.aborted)
|
|
1022
1060
|
throw error;
|
|
@@ -1032,6 +1070,15 @@ export class DialogueSession {
|
|
|
1032
1070
|
},
|
|
1033
1071
|
};
|
|
1034
1072
|
});
|
|
1073
|
+
this.plannerCall = undefined;
|
|
1074
|
+
if (toolFailure)
|
|
1075
|
+
throw toolFailure;
|
|
1076
|
+
assertRequestCanContinue();
|
|
1077
|
+
if (!result.ok) {
|
|
1078
|
+
const terminal = terminalRunError(result.error);
|
|
1079
|
+
if (terminal)
|
|
1080
|
+
throw terminal;
|
|
1081
|
+
}
|
|
1035
1082
|
callIndex++;
|
|
1036
1083
|
if (result.ok)
|
|
1037
1084
|
plannerUsage = addTokenUsage(plannerUsage, result.value.usage);
|
|
@@ -1079,7 +1126,6 @@ export class DialogueSession {
|
|
|
1079
1126
|
};
|
|
1080
1127
|
this.leadingActions.add(actionMessage);
|
|
1081
1128
|
this.conversation.push(actionMessage);
|
|
1082
|
-
this.trim();
|
|
1083
1129
|
recomputePlanStatus(this.plan);
|
|
1084
1130
|
this.changed();
|
|
1085
1131
|
const ready = readySteps(this.plan);
|
|
@@ -1114,7 +1160,7 @@ export class DialogueSession {
|
|
|
1114
1160
|
this.changed();
|
|
1115
1161
|
const checks = [];
|
|
1116
1162
|
if (idle && ready.length)
|
|
1117
|
-
checks.push(`Steps ${ready.map((s) => `${s.id}: ${s.goal
|
|
1163
|
+
checks.push(`Steps ${ready.map((s) => `${s.id}: ${s.goal}`).join(', ')} are ready (all dependencies done) and nothing runs. Delegate them or set status waiting_user with your question; skipping or narrowing requires user consent.`);
|
|
1118
1164
|
if (idle)
|
|
1119
1165
|
for (const step of stalled)
|
|
1120
1166
|
checks.push(`Step ${step.id} is running and nothing runs: its task finished; review get_task and continue`);
|
|
@@ -1172,7 +1218,19 @@ export class DialogueSession {
|
|
|
1172
1218
|
}
|
|
1173
1219
|
return message;
|
|
1174
1220
|
}
|
|
1221
|
+
catch (error) {
|
|
1222
|
+
const terminal = terminalRunError(error);
|
|
1223
|
+
if (terminal) {
|
|
1224
|
+
request.terminalError ??= {
|
|
1225
|
+
code: terminal.code,
|
|
1226
|
+
message: terminal.message,
|
|
1227
|
+
};
|
|
1228
|
+
throw terminal;
|
|
1229
|
+
}
|
|
1230
|
+
throw error;
|
|
1231
|
+
}
|
|
1175
1232
|
finally {
|
|
1233
|
+
this.plannerCall = undefined;
|
|
1176
1234
|
if (user)
|
|
1177
1235
|
this.memoryWriter?.enqueue('planner-input', request.id, randomUUID(), text, { usage: this.turnUsage });
|
|
1178
1236
|
if (!this.closing)
|
|
@@ -1199,7 +1257,7 @@ export class DialogueSession {
|
|
|
1199
1257
|
const owner = this.taskSteps.get(task.id);
|
|
1200
1258
|
const removed = owner !== undefined &&
|
|
1201
1259
|
!this.plan?.steps.some((step) => step.id === owner);
|
|
1202
|
-
return `${label !== '[task events]' ? label : removed && task.state !== 'failed' && task.state !== 'interrupted' && task.error === undefined ? '[actions]' : '[task events]'} task ${task.id}${owner ? ` for ${owner}` : ''} (${task.worker}) ${kind}: ${
|
|
1260
|
+
return `${label !== '[task events]' ? label : removed && task.state !== 'failed' && task.state !== 'interrupted' && task.error === undefined ? '[actions]' : '[task events]'} task ${task.id}${owner ? ` for ${owner}` : ''} (${task.worker}) ${kind}: ${task.goal} — ${taskNotice(task)}`;
|
|
1203
1261
|
})
|
|
1204
1262
|
.join('\n');
|
|
1205
1263
|
}
|
|
@@ -1232,25 +1290,6 @@ export class DialogueSession {
|
|
|
1232
1290
|
last.content = `${last.content}\n${text}`;
|
|
1233
1291
|
else
|
|
1234
1292
|
this.conversation.push({ role: 'user', content: text });
|
|
1235
|
-
this.trim();
|
|
1236
|
-
}
|
|
1237
|
-
trim() {
|
|
1238
|
-
// Remove complete reply/note pairs, never leave an orphaned actions note.
|
|
1239
|
-
while (this.conversation.length > DIALOGUE_HISTORY_LIMIT)
|
|
1240
|
-
this.conversation.splice(0, 2);
|
|
1241
|
-
if (this.conversation[0]?.role === 'assistant')
|
|
1242
|
-
this.conversation.shift();
|
|
1243
|
-
const first = this.conversation[0];
|
|
1244
|
-
if (first && this.leadingActions.has(first)) {
|
|
1245
|
-
const content = first.content ?? '';
|
|
1246
|
-
const newline = content.indexOf('\n');
|
|
1247
|
-
if (newline < 0)
|
|
1248
|
-
this.conversation.shift();
|
|
1249
|
-
else {
|
|
1250
|
-
first.content = content.slice(newline + 1);
|
|
1251
|
-
this.leadingActions.delete(first);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
1293
|
}
|
|
1255
1294
|
now() {
|
|
1256
1295
|
return (this.opts.now ?? Date.now)();
|