@multiplayer-app/agent 0.1.9 → 0.1.11
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 +106 -0
- package/dist/agent/definition.d.ts +22 -0
- package/dist/agent/definition.d.ts.map +1 -0
- package/dist/agent/definition.js +3 -0
- package/dist/agent/definition.js.map +1 -0
- package/dist/agent/definition.test.d.ts +2 -0
- package/dist/agent/definition.test.d.ts.map +1 -0
- package/dist/agent/definition.test.js +40 -0
- package/dist/agent/definition.test.js.map +1 -0
- package/dist/agent/model-failure.d.ts +10 -0
- package/dist/agent/model-failure.d.ts.map +1 -0
- package/dist/agent/model-failure.js +50 -0
- package/dist/agent/model-failure.js.map +1 -0
- package/dist/agent/profiles/coding.d.ts +4 -0
- package/dist/agent/profiles/coding.d.ts.map +1 -0
- package/dist/agent/profiles/coding.js +17 -0
- package/dist/agent/profiles/coding.js.map +1 -0
- package/dist/agent/profiles/index.d.ts +4 -0
- package/dist/agent/profiles/index.d.ts.map +1 -0
- package/dist/agent/profiles/index.js +9 -0
- package/dist/agent/profiles/index.js.map +1 -0
- package/dist/agent/profiles/research.d.ts +4 -0
- package/dist/agent/profiles/research.d.ts.map +1 -0
- package/dist/agent/profiles/research.js +53 -0
- package/dist/agent/profiles/research.js.map +1 -0
- package/dist/agent/progress-reminder.test.d.ts +2 -0
- package/dist/agent/progress-reminder.test.d.ts.map +1 -0
- package/dist/agent/progress-reminder.test.js +20 -0
- package/dist/agent/progress-reminder.test.js.map +1 -0
- package/dist/agent/turn-runner.d.ts +54 -0
- package/dist/agent/turn-runner.d.ts.map +1 -0
- package/dist/agent/turn-runner.js +147 -0
- package/dist/agent/turn-runner.js.map +1 -0
- package/dist/agent/turn-runner.test.d.ts +2 -0
- package/dist/agent/turn-runner.test.d.ts.map +1 -0
- package/dist/agent/turn-runner.test.js +181 -0
- package/dist/agent/turn-runner.test.js.map +1 -0
- package/dist/context-pruning.d.ts +13 -0
- package/dist/context-pruning.d.ts.map +1 -0
- package/dist/context-pruning.js +61 -0
- package/dist/context-pruning.js.map +1 -0
- package/dist/context-pruning.test.d.ts +2 -0
- package/dist/context-pruning.test.d.ts.map +1 -0
- package/dist/context-pruning.test.js +48 -0
- package/dist/context-pruning.test.js.map +1 -0
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -10
- package/dist/index.js.map +1 -1
- package/dist/models/attribution.d.ts.map +1 -0
- package/dist/models/attribution.js.map +1 -0
- package/dist/{model.d.ts → models/resolve-model.d.ts} +2 -2
- package/dist/models/resolve-model.d.ts.map +1 -0
- package/dist/{model.js → models/resolve-model.js} +4 -2
- package/dist/models/resolve-model.js.map +1 -0
- package/dist/models/usage.d.ts +11 -0
- package/dist/models/usage.d.ts.map +1 -0
- package/dist/models/usage.js +19 -0
- package/dist/models/usage.js.map +1 -0
- package/dist/{git-sync.d.ts → persistence/git-sync.d.ts} +1 -1
- package/dist/persistence/git-sync.d.ts.map +1 -0
- package/dist/persistence/git-sync.js.map +1 -0
- package/dist/persistence/git-sync.test.d.ts.map +1 -0
- package/dist/{git-sync.test.js → persistence/git-sync.test.js} +2 -2
- package/dist/persistence/git-sync.test.js.map +1 -0
- package/dist/{session-storage-sync.d.ts → persistence/snapshot-sync.d.ts} +2 -2
- package/dist/persistence/snapshot-sync.d.ts.map +1 -0
- package/dist/{session-storage-sync.js → persistence/snapshot-sync.js} +1 -1
- package/dist/persistence/snapshot-sync.js.map +1 -0
- package/dist/persistence/snapshot-sync.test.d.ts +2 -0
- package/dist/persistence/snapshot-sync.test.d.ts.map +1 -0
- package/dist/{session-storage-sync.test.js → persistence/snapshot-sync.test.js} +3 -3
- package/dist/persistence/snapshot-sync.test.js.map +1 -0
- package/dist/persistence/workspace.d.ts +17 -0
- package/dist/persistence/workspace.d.ts.map +1 -0
- package/dist/persistence/workspace.js +26 -0
- package/dist/persistence/workspace.js.map +1 -0
- package/dist/persistence/workspace.test.d.ts +2 -0
- package/dist/persistence/workspace.test.d.ts.map +1 -0
- package/dist/persistence/workspace.test.js +38 -0
- package/dist/persistence/workspace.test.js.map +1 -0
- package/dist/research/extract-texts.d.ts +41 -0
- package/dist/research/extract-texts.d.ts.map +1 -0
- package/dist/research/extract-texts.js +239 -0
- package/dist/research/extract-texts.js.map +1 -0
- package/dist/research/extract-texts.test.d.ts +2 -0
- package/dist/research/extract-texts.test.d.ts.map +1 -0
- package/dist/research/extract-texts.test.js +120 -0
- package/dist/research/extract-texts.test.js.map +1 -0
- package/dist/research/extraction-tool.d.ts +6 -0
- package/dist/research/extraction-tool.d.ts.map +1 -0
- package/dist/research/extraction-tool.js +41 -0
- package/dist/research/extraction-tool.js.map +1 -0
- package/dist/research/extraction-tool.test.d.ts +2 -0
- package/dist/research/extraction-tool.test.d.ts.map +1 -0
- package/dist/research/extraction-tool.test.js +102 -0
- package/dist/research/extraction-tool.test.js.map +1 -0
- package/dist/research/filingramp/attachment-tools.d.ts +4 -0
- package/dist/research/filingramp/attachment-tools.d.ts.map +1 -0
- package/dist/research/filingramp/attachment-tools.js +198 -0
- package/dist/research/filingramp/attachment-tools.js.map +1 -0
- package/dist/research/filingramp/document-search-tool.d.ts +4 -0
- package/dist/research/filingramp/document-search-tool.d.ts.map +1 -0
- package/dist/research/filingramp/document-search-tool.js +231 -0
- package/dist/research/filingramp/document-search-tool.js.map +1 -0
- package/dist/research/filingramp/filing-detail-tool.d.ts +8 -0
- package/dist/research/filingramp/filing-detail-tool.d.ts.map +1 -0
- package/dist/research/filingramp/filing-detail-tool.js +161 -0
- package/dist/research/filingramp/filing-detail-tool.js.map +1 -0
- package/dist/research/filingramp/filing-search-tools.d.ts +4 -0
- package/dist/research/filingramp/filing-search-tools.d.ts.map +1 -0
- package/dist/research/filingramp/filing-search-tools.js +207 -0
- package/dist/research/filingramp/filing-search-tools.js.map +1 -0
- package/dist/research/filingramp/shared.d.ts +64 -0
- package/dist/research/filingramp/shared.d.ts.map +1 -0
- package/dist/research/filingramp/shared.js +130 -0
- package/dist/research/filingramp/shared.js.map +1 -0
- package/dist/research/filingramp-client.d.ts +1 -1
- package/dist/research/filingramp-client.d.ts.map +1 -1
- package/dist/research/filingramp-contract.d.ts.map +1 -1
- package/dist/research/filingramp-contract.js +8 -2
- package/dist/research/filingramp-contract.js.map +1 -1
- package/dist/research/filingramp-tools.d.ts +4 -8
- package/dist/research/filingramp-tools.d.ts.map +1 -1
- package/dist/research/filingramp-tools.js +19 -597
- package/dist/research/filingramp-tools.js.map +1 -1
- package/dist/research/filingramp-tools.test.js +138 -2
- package/dist/research/filingramp-tools.test.js.map +1 -1
- package/dist/research/prompt.d.ts +1 -1
- package/dist/research/prompt.d.ts.map +1 -1
- package/dist/research/prompt.js +16 -7
- package/dist/research/prompt.js.map +1 -1
- package/dist/research/scope.d.ts +1 -1
- package/dist/research/scope.d.ts.map +1 -1
- package/dist/runtime/cli.d.ts.map +1 -0
- package/dist/{cli.js → runtime/cli.js} +3 -3
- package/dist/runtime/cli.js.map +1 -0
- package/dist/{config.d.ts → runtime/config.d.ts} +1 -1
- package/dist/runtime/config.d.ts.map +1 -0
- package/dist/{config.js → runtime/config.js} +1 -1
- package/dist/runtime/config.js.map +1 -0
- package/dist/{runtime.d.ts → runtime/index.d.ts} +2 -2
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/{runtime.js → runtime/index.js} +7 -7
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/lambda-microvm.d.ts +3 -0
- package/dist/runtime/lambda-microvm.d.ts.map +1 -0
- package/dist/{lambda-microvm-entrypoint.js → runtime/lambda-microvm.js} +4 -4
- package/dist/runtime/lambda-microvm.js.map +1 -0
- package/dist/runtime/lifecycle.test.d.ts.map +1 -0
- package/dist/{lifecycle.test.js → runtime/lifecycle.test.js} +5 -5
- package/dist/runtime/lifecycle.test.js.map +1 -0
- package/dist/session/checkpoint-timer.test.d.ts.map +1 -0
- package/dist/{checkpoint-timer.test.js → session/checkpoint-timer.test.js} +8 -8
- package/dist/session/checkpoint-timer.test.js.map +1 -0
- package/dist/session/conversation.d.ts +15 -0
- package/dist/session/conversation.d.ts.map +1 -0
- package/dist/session/conversation.js +61 -0
- package/dist/session/conversation.js.map +1 -0
- package/dist/session/conversation.test.d.ts +2 -0
- package/dist/session/conversation.test.d.ts.map +1 -0
- package/dist/session/conversation.test.js +53 -0
- package/dist/session/conversation.test.js.map +1 -0
- package/dist/session/idle-checkpoint.test.d.ts.map +1 -0
- package/dist/{idle-checkpoint.test.js → session/idle-checkpoint.test.js} +8 -4
- package/dist/session/idle-checkpoint.test.js.map +1 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +16 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/runtime.d.ts +58 -0
- package/dist/session/runtime.d.ts.map +1 -0
- package/dist/session/runtime.js +292 -0
- package/dist/session/runtime.js.map +1 -0
- package/dist/session/runtime.test.d.ts +2 -0
- package/dist/session/runtime.test.d.ts.map +1 -0
- package/dist/session/runtime.test.js +201 -0
- package/dist/session/runtime.test.js.map +1 -0
- package/dist/session/tool-context.d.ts +12 -0
- package/dist/session/tool-context.d.ts.map +1 -0
- package/dist/session/tool-context.js +3 -0
- package/dist/session/tool-context.js.map +1 -0
- package/dist/session/tools.d.ts +6 -0
- package/dist/session/tools.d.ts.map +1 -0
- package/dist/session/tools.js +97 -0
- package/dist/session/tools.js.map +1 -0
- package/dist/session/tools.test.d.ts +2 -0
- package/dist/session/tools.test.d.ts.map +1 -0
- package/dist/session/tools.test.js +55 -0
- package/dist/session/tools.test.js.map +1 -0
- package/dist/task/loop.d.ts +6 -0
- package/dist/task/loop.d.ts.map +1 -0
- package/dist/{loop.js → task/loop.js} +6 -6
- package/dist/task/loop.js.map +1 -0
- package/dist/tool-call-repair.d.ts +11 -0
- package/dist/tool-call-repair.d.ts.map +1 -0
- package/dist/tool-call-repair.js +91 -0
- package/dist/tool-call-repair.js.map +1 -0
- package/dist/tool-call-repair.test.d.ts +2 -0
- package/dist/tool-call-repair.test.d.ts.map +1 -0
- package/dist/tool-call-repair.test.js +50 -0
- package/dist/tool-call-repair.test.js.map +1 -0
- package/dist/tools/exec-tools.d.ts +1 -0
- package/dist/tools/exec-tools.d.ts.map +1 -1
- package/dist/tools/exec-tools.js +23 -3
- package/dist/tools/exec-tools.js.map +1 -1
- package/dist/transport/link.d.ts.map +1 -0
- package/dist/transport/link.js.map +1 -0
- package/dist/{protocol.d.ts → transport/protocol.d.ts} +4 -0
- package/dist/transport/protocol.d.ts.map +1 -0
- package/dist/transport/protocol.js.map +1 -0
- package/dist/transport/protocol.test.d.ts.map +1 -0
- package/dist/transport/protocol.test.js.map +1 -0
- package/dist/{report.d.ts → transport/reporter.d.ts} +1 -1
- package/dist/transport/reporter.d.ts.map +1 -0
- package/dist/{report.js → transport/reporter.js} +1 -1
- package/dist/transport/reporter.js.map +1 -0
- package/package.json +11 -11
- package/dist/attribution.d.ts.map +0 -1
- package/dist/attribution.js.map +0 -1
- package/dist/checkpoint-timer.test.d.ts.map +0 -1
- package/dist/checkpoint-timer.test.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/git-sync.d.ts.map +0 -1
- package/dist/git-sync.js.map +0 -1
- package/dist/git-sync.test.d.ts.map +0 -1
- package/dist/git-sync.test.js.map +0 -1
- package/dist/idle-checkpoint.test.d.ts.map +0 -1
- package/dist/idle-checkpoint.test.js.map +0 -1
- package/dist/lambda-microvm-entrypoint.d.ts +0 -3
- package/dist/lambda-microvm-entrypoint.d.ts.map +0 -1
- package/dist/lambda-microvm-entrypoint.js.map +0 -1
- package/dist/lifecycle.test.d.ts.map +0 -1
- package/dist/lifecycle.test.js.map +0 -1
- package/dist/link.d.ts.map +0 -1
- package/dist/link.js.map +0 -1
- package/dist/loop.d.ts +0 -6
- package/dist/loop.d.ts.map +0 -1
- package/dist/loop.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js.map +0 -1
- package/dist/protocol.test.d.ts.map +0 -1
- package/dist/protocol.test.js.map +0 -1
- package/dist/report.d.ts.map +0 -1
- package/dist/report.js.map +0 -1
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/session-storage-sync.d.ts.map +0 -1
- package/dist/session-storage-sync.js.map +0 -1
- package/dist/session-storage-sync.test.d.ts +0 -2
- package/dist/session-storage-sync.test.d.ts.map +0 -1
- package/dist/session-storage-sync.test.js.map +0 -1
- package/dist/session.d.ts +0 -46
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -512
- package/dist/session.js.map +0 -1
- /package/dist/{attribution.d.ts → models/attribution.d.ts} +0 -0
- /package/dist/{attribution.js → models/attribution.js} +0 -0
- /package/dist/{git-sync.js → persistence/git-sync.js} +0 -0
- /package/dist/{git-sync.test.d.ts → persistence/git-sync.test.d.ts} +0 -0
- /package/dist/{cli.d.ts → runtime/cli.d.ts} +0 -0
- /package/dist/{lifecycle.test.d.ts → runtime/lifecycle.test.d.ts} +0 -0
- /package/dist/{checkpoint-timer.test.d.ts → session/checkpoint-timer.test.d.ts} +0 -0
- /package/dist/{idle-checkpoint.test.d.ts → session/idle-checkpoint.test.d.ts} +0 -0
- /package/dist/{link.d.ts → transport/link.d.ts} +0 -0
- /package/dist/{link.js → transport/link.js} +0 -0
- /package/dist/{protocol.js → transport/protocol.js} +0 -0
- /package/dist/{protocol.test.d.ts → transport/protocol.test.d.ts} +0 -0
- /package/dist/{protocol.test.js → transport/protocol.test.js} +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TurnRunner = void 0;
|
|
4
|
+
exports.stepsSinceProgress = stepsSinceProgress;
|
|
5
|
+
const ai_1 = require("ai");
|
|
6
|
+
const resolve_model_1 = require("../models/resolve-model");
|
|
7
|
+
const usage_1 = require("../models/usage");
|
|
8
|
+
const context_pruning_1 = require("../context-pruning");
|
|
9
|
+
const tool_call_repair_1 = require("../tool-call-repair");
|
|
10
|
+
const model_failure_1 = require("./model-failure");
|
|
11
|
+
/** Steps the budget wrap-up may take (write notes and findings, publish, summarize) before the turn stops. */
|
|
12
|
+
const WRAP_UP_STEPS = 4;
|
|
13
|
+
const WRAP_UP_TOOLS = ['write_files', 'read_file', 'run_command', 'publish_results'];
|
|
14
|
+
const WRAP_UP_INSTRUCTIONS = `(Automatic note, not from the user.) The token budget for this session is nearly used up. Stop researching now: no new searches, downloads or extraction. In the next few steps only:
|
|
15
|
+
1. Update research/notes.md: what is done, what is not, and the exact next step.
|
|
16
|
+
2. Write research/findings.md as a draft marked PARTIAL at the top, with what you found so far and its coverage (documents read vs not yet read).
|
|
17
|
+
3. Call publish_results with those files, then end with a short summary saying the findings are partial and the user can reply "continue".`;
|
|
18
|
+
/** Steps without a report_progress call after which the agent is reminded to update the checklist. */
|
|
19
|
+
const PROGRESS_REMINDER_STEPS = 6;
|
|
20
|
+
const PROGRESS_REMINDER = '(Automatic check, not from the user: the pinned "Research progress" checklist still shows the phases as you last reported them. If a phase has started or finished since, call report_progress with the full updated list now, alongside your next action. If nothing changed, ignore this note.)';
|
|
21
|
+
/** Steps since the agent last called report_progress in this turn (all of them when it never did). */
|
|
22
|
+
function stepsSinceProgress(steps) {
|
|
23
|
+
for (let index = steps.length - 1; index >= 0; index -= 1) {
|
|
24
|
+
if (steps[index].toolCalls.some((call) => call.toolName === 'report_progress'))
|
|
25
|
+
return steps.length - 1 - index;
|
|
26
|
+
}
|
|
27
|
+
return steps.length;
|
|
28
|
+
}
|
|
29
|
+
/** Executes one turn. It neither mutates conversation history nor checkpoints or schedules work. */
|
|
30
|
+
class TurnRunner {
|
|
31
|
+
constructor(definition) {
|
|
32
|
+
this.definition = definition;
|
|
33
|
+
}
|
|
34
|
+
async run(input) {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const { messageId, abortSignal, emit } = input;
|
|
37
|
+
let partialText = '';
|
|
38
|
+
let askedUser = false;
|
|
39
|
+
let wrapUpFrom;
|
|
40
|
+
let saved = false;
|
|
41
|
+
let responseMessages;
|
|
42
|
+
const recordUsage = (usage, model) => {
|
|
43
|
+
input.recordUsage(usage);
|
|
44
|
+
emit({ type: 'usage', messageId, usage: { ...usage, model } });
|
|
45
|
+
};
|
|
46
|
+
const context = {
|
|
47
|
+
workspaceDir: input.workspaceDir,
|
|
48
|
+
abortSignal,
|
|
49
|
+
recordUsage,
|
|
50
|
+
reportProgress: (steps, toolCallId) => emit({ type: 'progress', messageId, toolCallId, steps }),
|
|
51
|
+
publishFiles: (files) => emit({ type: 'files', messageId, files }),
|
|
52
|
+
requestClarification: (question, toolCallId) => {
|
|
53
|
+
askedUser = true;
|
|
54
|
+
emit({ type: 'question', messageId, toolCallId, question });
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
abortSignal.throwIfAborted();
|
|
59
|
+
const { model, maxSteps, profile } = this.definition;
|
|
60
|
+
const tools = this.definition.createTools(context);
|
|
61
|
+
// The wrap-up needs a research workspace to save into; the coding profile just stops at the budget.
|
|
62
|
+
const research = profile === 'research';
|
|
63
|
+
const wrapUpDone = ({ steps }) => wrapUpFrom !== undefined ? steps.length - wrapUpFrom >= WRAP_UP_STEPS : !research && input.budgetExceeded();
|
|
64
|
+
const result = (0, ai_1.streamText)({
|
|
65
|
+
model: (0, resolve_model_1.resolveLanguageModel)(model.provider, model.id, model.attribution),
|
|
66
|
+
system: input.instructions,
|
|
67
|
+
messages: input.messages,
|
|
68
|
+
tools,
|
|
69
|
+
abortSignal,
|
|
70
|
+
stopWhen: [(0, ai_1.stepCountIs)(maxSteps), () => askedUser, wrapUpDone],
|
|
71
|
+
experimental_repairToolCall: tool_call_repair_1.repairStringifiedToolInput,
|
|
72
|
+
prepareStep: ({ stepNumber, steps, messages }) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const pruned = (0, context_pruning_1.pruneToolResults)(messages);
|
|
75
|
+
if (wrapUpFrom === undefined && research && (input.wrapUpOnly || ((_a = input.nearBudget) === null || _a === void 0 ? void 0 : _a.call(input))))
|
|
76
|
+
wrapUpFrom = stepNumber;
|
|
77
|
+
if (wrapUpFrom === undefined) {
|
|
78
|
+
// The chat pins the checklist; a stale one tells the user nothing is moving. The note is
|
|
79
|
+
// appended for this step only, after the cached prefix, and is never saved. Once every
|
|
80
|
+
// PROGRESS_REMINDER_STEPS quiet steps, so an agent whose phase has not changed is not nagged.
|
|
81
|
+
const since = stepsSinceProgress(steps);
|
|
82
|
+
const stale = research && 'report_progress' in tools && since > 0 && since % PROGRESS_REMINDER_STEPS === 0;
|
|
83
|
+
return { messages: stale ? [...pruned, { role: 'user', content: PROGRESS_REMINDER }] : pruned };
|
|
84
|
+
}
|
|
85
|
+
// The instructions go last, as a note, rather than into the system prompt: the model acts on
|
|
86
|
+
// the newest message (in one run it ignored a system-only switch and ended on leftover
|
|
87
|
+
// text), and the cached prefix stays intact. A forced tool call (toolChoice "required") is
|
|
88
|
+
// not an option: Anthropic rejects it while extended thinking is on.
|
|
89
|
+
return {
|
|
90
|
+
messages: saved ? pruned : [...pruned, { role: 'user', content: WRAP_UP_INSTRUCTIONS }],
|
|
91
|
+
activeTools: WRAP_UP_TOOLS.filter((name) => name in tools),
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
for await (const part of result.fullStream) {
|
|
96
|
+
switch (part.type) {
|
|
97
|
+
case 'text-delta':
|
|
98
|
+
partialText += part.text;
|
|
99
|
+
emit({ type: 'text_delta', messageId, text: part.text });
|
|
100
|
+
break;
|
|
101
|
+
case 'reasoning-delta':
|
|
102
|
+
emit({ type: 'reasoning_delta', messageId, text: part.text });
|
|
103
|
+
break;
|
|
104
|
+
case 'tool-call':
|
|
105
|
+
if (wrapUpFrom !== undefined && (part.toolName === 'publish_results' || part.toolName === 'write_files'))
|
|
106
|
+
saved = true;
|
|
107
|
+
emit({ type: 'tool_call_start', messageId, toolCallId: part.toolCallId, toolName: part.toolName, input: part.input });
|
|
108
|
+
break;
|
|
109
|
+
case 'tool-result':
|
|
110
|
+
emit({ type: 'tool_call_result', messageId, toolCallId: part.toolCallId, output: part.output });
|
|
111
|
+
break;
|
|
112
|
+
case 'tool-error':
|
|
113
|
+
emit({
|
|
114
|
+
type: 'tool_call_result', messageId, toolCallId: part.toolCallId,
|
|
115
|
+
error: part.error instanceof Error ? part.error.message : String(part.error),
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
case 'finish-step': {
|
|
119
|
+
const usage = (0, usage_1.usageOf)(part);
|
|
120
|
+
if (usage)
|
|
121
|
+
recordUsage(usage, (_b = (_a = part.response) === null || _a === void 0 ? void 0 : _a.modelId) !== null && _b !== void 0 ? _b : model.id);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case 'error':
|
|
125
|
+
throw part.error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
abortSignal.throwIfAborted();
|
|
129
|
+
responseMessages = (await result.response).messages;
|
|
130
|
+
const text = await result.text;
|
|
131
|
+
return { status: 'completed', messages: responseMessages, text, partialText, askedUser, wrappedUp: wrapUpFrom !== undefined, saved };
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const aborted = abortSignal.aborted;
|
|
135
|
+
// A partial stream may end between a tool call and its result. Persist text only in that case.
|
|
136
|
+
const messages = responseMessages !== null && responseMessages !== void 0 ? responseMessages : [{
|
|
137
|
+
role: 'assistant', content: partialText || (aborted ? '(stopped by the user)' : '(turn failed)'),
|
|
138
|
+
}];
|
|
139
|
+
const output = { messages, partialText, askedUser, wrappedUp: wrapUpFrom !== undefined, saved };
|
|
140
|
+
return aborted
|
|
141
|
+
? { ...output, status: 'aborted' }
|
|
142
|
+
: { ...output, status: 'failed', error: (0, model_failure_1.describeModelFailure)(error), userMessage: (_c = (0, model_failure_1.userFacingModelFailure)(error)) !== null && _c !== void 0 ? _c : (0, model_failure_1.describeModelFailure)(error) };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.TurnRunner = TurnRunner;
|
|
147
|
+
//# sourceMappingURL=turn-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-runner.js","sourceRoot":"","sources":["../../src/agent/turn-runner.ts"],"names":[],"mappings":";;;AAwBA,gDAKC;AA7BD,2BAA8F;AAG9F,2DAA8D;AAE9D,2CAA0D;AAC1D,wDAAqD;AACrD,0DAAgE;AAChE,mDAA8E;AAE9E,8GAA8G;AAC9G,MAAM,aAAa,GAAG,CAAC,CAAA;AACvB,MAAM,aAAa,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAA;AACpF,MAAM,oBAAoB,GAAG;;;2IAG8G,CAAA;AAE3I,sGAAsG;AACtG,MAAM,uBAAuB,GAAG,CAAC,CAAA;AACjC,MAAM,iBAAiB,GACrB,mSAAmS,CAAA;AAErS,sGAAsG;AACtG,SAAgB,kBAAkB,CAAC,KAAwD;IACzF,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC1D,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,iBAAiB,CAAC;YAAE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAA;IACjH,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAA;AACrB,CAAC;AAmCD,oGAAoG;AACpG,MAAa,UAAU;IACrB,YAA6B,UAA2B;QAA3B,eAAU,GAAV,UAAU,CAAiB;IAAG,CAAC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OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,KAAK,SAAS,EAAE,KAAK,EAAE,CAAA;QACtI,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAA;YACnC,+FAA+F;YAC/F,MAAM,QAAQ,GAAmB,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,CAAC;oBACpD,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,eAAe,CAAC;iBACjG,CAAC,CAAA;YACF,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,KAAK,SAAS,EAAE,KAAK,EAAE,CAAA;YAC/F,OAAO,OAAO;gBACZ,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE;gBAClC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAA,oCAAoB,EAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAA,IAAA,sCAAsB,EAAC,KAAK,CAAC,mCAAI,IAAA,oCAAoB,EAAC,KAAK,CAAC,EAAE,CAAA;QACpJ,CAAC;IACH,CAAC;CACF;AAhHD,gCAgHC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-runner.test.d.ts","sourceRoot":"","sources":["../../src/agent/turn-runner.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
40
|
+
const node_test_1 = require("node:test");
|
|
41
|
+
const test_1 = require("ai/test");
|
|
42
|
+
const modelProvider = __importStar(require("../models/resolve-model"));
|
|
43
|
+
const profiles_1 = require("./profiles");
|
|
44
|
+
const turn_runner_1 = require("./turn-runner");
|
|
45
|
+
const config = {
|
|
46
|
+
sessionId: 'test', mode: 'session', profile: 'coding', workspaceDir: '/unused',
|
|
47
|
+
model: 'main-model', extractionModel: 'unused', provider: {}, mcpConnections: [],
|
|
48
|
+
};
|
|
49
|
+
const usage = {
|
|
50
|
+
inputTokens: { total: 10, noCache: 10, cacheRead: 0, cacheWrite: 0 },
|
|
51
|
+
outputTokens: { total: 5, text: 5, reasoning: 0 },
|
|
52
|
+
};
|
|
53
|
+
function input(messageId, events, abort = new AbortController()) {
|
|
54
|
+
return {
|
|
55
|
+
messageId,
|
|
56
|
+
messages: [{ role: 'user', content: 'Research this' }],
|
|
57
|
+
instructions: 'Test instructions',
|
|
58
|
+
workspaceDir: '/unused',
|
|
59
|
+
abortSignal: abort.signal,
|
|
60
|
+
budgetExceeded: () => false,
|
|
61
|
+
recordUsage() { },
|
|
62
|
+
emit: (event) => events.push(event),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
for (const stopReason of ['clarification', 'budget']) {
|
|
66
|
+
(0, node_test_1.it)(`stops after ${stopReason}, reports model usage, and returns history without mutating its input`, async (t) => {
|
|
67
|
+
const model = new test_1.MockLanguageModelV3({
|
|
68
|
+
modelId: 'main-model',
|
|
69
|
+
doStream: async () => ({
|
|
70
|
+
stream: new ReadableStream({
|
|
71
|
+
start(controller) {
|
|
72
|
+
controller.enqueue({ type: 'reasoning-start', id: 'reasoning' });
|
|
73
|
+
controller.enqueue({ type: 'reasoning-delta', id: 'reasoning', delta: 'Checking scope' });
|
|
74
|
+
controller.enqueue({ type: 'reasoning-end', id: 'reasoning' });
|
|
75
|
+
controller.enqueue({
|
|
76
|
+
type: 'tool-call', toolCallId: 'call',
|
|
77
|
+
toolName: stopReason === 'clarification' ? 'request_clarification' : 'report_progress',
|
|
78
|
+
input: JSON.stringify(stopReason === 'clarification'
|
|
79
|
+
? { question: 'Which state?', selectionMode: 'single', options: [{ id: 'tx', label: 'TX' }, { id: 'az', label: 'AZ' }] }
|
|
80
|
+
: { steps: [{ key: 'research', label: 'Research', status: 'active' }] }),
|
|
81
|
+
});
|
|
82
|
+
controller.enqueue({ type: 'finish', finishReason: { unified: 'tool-calls', raw: 'tool-calls' }, usage });
|
|
83
|
+
controller.close();
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
t.mock.method(modelProvider, 'resolveLanguageModel', () => model);
|
|
89
|
+
const events = [];
|
|
90
|
+
const request = input('turn', events);
|
|
91
|
+
const originalMessages = structuredClone(request.messages);
|
|
92
|
+
let used = 0;
|
|
93
|
+
request.recordUsage = (tokens) => {
|
|
94
|
+
used += tokens.totalTokens;
|
|
95
|
+
};
|
|
96
|
+
request.budgetExceeded = () => stopReason === 'budget' && used >= 15;
|
|
97
|
+
const runner = new turn_runner_1.TurnRunner((0, profiles_1.createAgentDefinition)(config, config.workspaceDir));
|
|
98
|
+
const result = await runner.run(request);
|
|
99
|
+
strict_1.default.equal(result.status, 'completed');
|
|
100
|
+
strict_1.default.equal(result.askedUser, stopReason === 'clarification');
|
|
101
|
+
strict_1.default.equal(model.doStreamCalls.length, 1);
|
|
102
|
+
strict_1.default.equal(used, 15);
|
|
103
|
+
strict_1.default.deepEqual(request.messages, originalMessages);
|
|
104
|
+
strict_1.default.deepEqual(result.messages.map((message) => message.role), ['assistant', 'tool']);
|
|
105
|
+
strict_1.default.ok(events.some((event) => event.type === 'reasoning_delta'));
|
|
106
|
+
strict_1.default.ok(events.some((event) => event.type === 'tool_call_start'));
|
|
107
|
+
strict_1.default.ok(events.some((event) => event.type === 'tool_call_result'));
|
|
108
|
+
strict_1.default.ok(events.some((event) => event.type === 'usage' && event.usage.model === 'main-model'));
|
|
109
|
+
strict_1.default.ok(events.every((event) => 'messageId' in event && event.messageId === 'turn'));
|
|
110
|
+
strict_1.default.ok(!events.some((event) => event.type === 'done' || event.type === 'checkpointed'));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
(0, node_test_1.it)('binds tool callbacks to their original turn even after another turn starts', async (t) => {
|
|
114
|
+
const model = new test_1.MockLanguageModelV3({
|
|
115
|
+
doStream: async () => ({
|
|
116
|
+
stream: new ReadableStream({
|
|
117
|
+
start(controller) {
|
|
118
|
+
controller.enqueue({ type: 'text-start', id: 'answer' });
|
|
119
|
+
controller.enqueue({ type: 'text-delta', id: 'answer', delta: 'Done' });
|
|
120
|
+
controller.enqueue({ type: 'text-end', id: 'answer' });
|
|
121
|
+
controller.enqueue({ type: 'finish', finishReason: { unified: 'stop', raw: 'stop' }, usage });
|
|
122
|
+
controller.close();
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
t.mock.method(modelProvider, 'resolveLanguageModel', () => model);
|
|
128
|
+
const contexts = [];
|
|
129
|
+
const definition = (0, profiles_1.createAgentDefinition)(config, config.workspaceDir);
|
|
130
|
+
const createTools = definition.createTools;
|
|
131
|
+
definition.createTools = (context) => {
|
|
132
|
+
contexts.push(context);
|
|
133
|
+
return createTools(context);
|
|
134
|
+
};
|
|
135
|
+
const runner = new turn_runner_1.TurnRunner(definition);
|
|
136
|
+
const firstEvents = [];
|
|
137
|
+
const secondEvents = [];
|
|
138
|
+
const firstAbort = new AbortController();
|
|
139
|
+
const secondAbort = new AbortController();
|
|
140
|
+
await runner.run(input('first', firstEvents, firstAbort));
|
|
141
|
+
await runner.run(input('second', secondEvents, secondAbort));
|
|
142
|
+
contexts[0].publishFiles([{ path: 'first.md', content: 'First result' }]);
|
|
143
|
+
contexts[1].requestClarification('Second question?', 'ask');
|
|
144
|
+
firstAbort.abort();
|
|
145
|
+
strict_1.default.equal(contexts[0].abortSignal.aborted, true);
|
|
146
|
+
strict_1.default.equal(contexts[1].abortSignal.aborted, false);
|
|
147
|
+
strict_1.default.deepEqual(firstEvents[firstEvents.length - 1], { type: 'files', messageId: 'first', files: [{ path: 'first.md', content: 'First result' }] });
|
|
148
|
+
strict_1.default.deepEqual(secondEvents[secondEvents.length - 1], { type: 'question', messageId: 'second', toolCallId: 'ask', question: 'Second question?' });
|
|
149
|
+
});
|
|
150
|
+
for (const interrupt of ['error', 'abort']) {
|
|
151
|
+
(0, node_test_1.it)(`returns safe partial text after a stream ${interrupt}`, async (t) => {
|
|
152
|
+
const abort = new AbortController();
|
|
153
|
+
const model = new test_1.MockLanguageModelV3({
|
|
154
|
+
doStream: async () => ({
|
|
155
|
+
stream: new ReadableStream({
|
|
156
|
+
start(controller) {
|
|
157
|
+
controller.enqueue({ type: 'text-start', id: 'answer' });
|
|
158
|
+
controller.enqueue({ type: 'text-delta', id: 'answer', delta: 'Partial findings' });
|
|
159
|
+
controller.enqueue({ type: 'tool-input-start', id: 'unfinished', toolName: 'report_progress' });
|
|
160
|
+
controller.enqueue({ type: 'error', error: new Error('provider interrupted') });
|
|
161
|
+
controller.close();
|
|
162
|
+
},
|
|
163
|
+
}),
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
t.mock.method(modelProvider, 'resolveLanguageModel', () => model);
|
|
167
|
+
const events = [];
|
|
168
|
+
const request = input('turn', events, abort);
|
|
169
|
+
request.emit = (event) => {
|
|
170
|
+
events.push(event);
|
|
171
|
+
if (interrupt === 'abort' && event.type === 'text_delta')
|
|
172
|
+
abort.abort();
|
|
173
|
+
};
|
|
174
|
+
const result = await new turn_runner_1.TurnRunner((0, profiles_1.createAgentDefinition)(config, config.workspaceDir)).run(request);
|
|
175
|
+
strict_1.default.equal(result.status, interrupt === 'abort' ? 'aborted' : 'failed');
|
|
176
|
+
strict_1.default.deepEqual(result.messages, [{ role: 'assistant', content: 'Partial findings' }]);
|
|
177
|
+
if (result.status === 'failed')
|
|
178
|
+
strict_1.default.equal(result.error, 'provider interrupted');
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=turn-runner.test.js.map
|
|
@@ -0,0 +1 @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AK,CAAC,CAAA;QAC5C,OAAO,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,EAAE;YACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAClB,IAAI,SAAS,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;gBAAE,KAAK,CAAC,KAAK,EAAE,CAAA;QACzE,CAAC,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,wBAAU,CAAC,IAAA,gCAAqB,EAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACpG,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;QACzE,gBAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAA;QACvF,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ;YAAE,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAA;IACpF,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ModelMessage } from 'ai';
|
|
2
|
+
export interface PruneOptions {
|
|
3
|
+
/** Messages at the end of the conversation that are never pruned (the steps the agent is working on). */
|
|
4
|
+
keepRecent: number;
|
|
5
|
+
/** Results smaller than this are kept: they cost little and often carry the answer. */
|
|
6
|
+
minChars: number;
|
|
7
|
+
/** Prune only once the prunable results together exceed this many characters. */
|
|
8
|
+
triggerChars: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_PRUNE_OPTIONS: PruneOptions;
|
|
11
|
+
/** Returns `messages` unchanged until old bulky tool results pass `triggerChars`, then a copy with them stubbed. */
|
|
12
|
+
export declare function pruneToolResults(messages: ModelMessage[], options?: PruneOptions): ModelMessage[];
|
|
13
|
+
//# sourceMappingURL=context-pruning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-pruning.d.ts","sourceRoot":"","sources":["../src/context-pruning.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAEtC,MAAM,WAAW,YAAY;IAC3B,yGAAyG;IACzG,UAAU,EAAE,MAAM,CAAA;IAClB,uFAAuF;IACvF,QAAQ,EAAE,MAAM,CAAA;IAChB,iFAAiF;IACjF,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,qBAAqB,EAAE,YAAwE,CAAA;AA6B5G,oHAAoH;AACpH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,OAAO,GAAE,YAAoC,GAAG,YAAY,EAAE,CAuBxH"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PRUNE_OPTIONS = void 0;
|
|
4
|
+
exports.pruneToolResults = pruneToolResults;
|
|
5
|
+
exports.DEFAULT_PRUNE_OPTIONS = { keepRecent: 6, minChars: 2000, triggerChars: 120000 };
|
|
6
|
+
const PATH_KEYS = ['path', 'textPath', 'saved', 'manifest', 'outputManifest', 'outputPath', 'saveHits'];
|
|
7
|
+
function isToolResult(part) {
|
|
8
|
+
return !!part && typeof part === 'object' && part.type === 'tool-result';
|
|
9
|
+
}
|
|
10
|
+
/** Workspace paths a tool result mentions at its top level (or one level down, e.g. `saved.path`). */
|
|
11
|
+
function mentionedPaths(output) {
|
|
12
|
+
const value = output && typeof output === 'object' && 'value' in output ? output.value : output;
|
|
13
|
+
if (!value || typeof value !== 'object')
|
|
14
|
+
return [];
|
|
15
|
+
const found = [];
|
|
16
|
+
for (const key of PATH_KEYS) {
|
|
17
|
+
const entry = value[key];
|
|
18
|
+
if (typeof entry === 'string')
|
|
19
|
+
found.push(entry);
|
|
20
|
+
else if (entry && typeof entry === 'object' && typeof entry.path === 'string')
|
|
21
|
+
found.push(entry.path);
|
|
22
|
+
}
|
|
23
|
+
return [...new Set(found)];
|
|
24
|
+
}
|
|
25
|
+
function stub(part, chars) {
|
|
26
|
+
const paths = mentionedPaths(part.output);
|
|
27
|
+
const where = paths.length ? ` Its data is on disk: ${paths.join(', ')}.` : ' Re-run the tool or read the workspace files if you need it again.';
|
|
28
|
+
return { ...part, output: { type: 'text', value: `[${part.toolName} result removed from the conversation to save tokens (${chars.toLocaleString()} chars).${where}]` } };
|
|
29
|
+
}
|
|
30
|
+
/** Returns `messages` unchanged until old bulky tool results pass `triggerChars`, then a copy with them stubbed. */
|
|
31
|
+
function pruneToolResults(messages, options = exports.DEFAULT_PRUNE_OPTIONS) {
|
|
32
|
+
const cutoff = Math.max(0, messages.length - options.keepRecent);
|
|
33
|
+
let prunable = 0;
|
|
34
|
+
for (const message of messages.slice(0, cutoff)) {
|
|
35
|
+
if (message.role !== 'tool')
|
|
36
|
+
continue;
|
|
37
|
+
for (const part of message.content) {
|
|
38
|
+
if (!isToolResult(part))
|
|
39
|
+
continue;
|
|
40
|
+
const chars = JSON.stringify(part.output).length;
|
|
41
|
+
if (chars >= options.minChars)
|
|
42
|
+
prunable += chars;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (prunable < options.triggerChars)
|
|
46
|
+
return messages;
|
|
47
|
+
return messages.map((message, index) => {
|
|
48
|
+
if (index >= cutoff || message.role !== 'tool')
|
|
49
|
+
return message;
|
|
50
|
+
return {
|
|
51
|
+
...message,
|
|
52
|
+
content: message.content.map((part) => {
|
|
53
|
+
if (!isToolResult(part))
|
|
54
|
+
return part;
|
|
55
|
+
const chars = JSON.stringify(part.output).length;
|
|
56
|
+
return chars >= options.minChars ? stub(part, chars) : part;
|
|
57
|
+
}),
|
|
58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AAI,QAAQ,GAAG,OAAO,CAAC,YAAY;QAAE,OAAO,QAAQ,CAAA;IACpD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QACrC,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO,OAAO,CAAA;QAC9D,OAAO;YACL,GAAG,OAAO;YACV,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACpC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAA;gBACpC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAA;gBAChD,OAAO,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC7D,CAAC,CAAC;SACa,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-pruning.test.d.ts","sourceRoot":"","sources":["../src/context-pruning.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const context_pruning_1 = require("./context-pruning");
|
|
9
|
+
function call(id) {
|
|
10
|
+
return { role: 'assistant', content: [{ type: 'tool-call', toolCallId: id, toolName: 'get_filing', input: {} }] };
|
|
11
|
+
}
|
|
12
|
+
function result(id, value) {
|
|
13
|
+
return { role: 'tool', content: [{ type: 'tool-result', toolCallId: id, toolName: 'get_filing', output: { type: 'json', value: value } }] };
|
|
14
|
+
}
|
|
15
|
+
const options = { keepRecent: 2, minChars: 100, triggerChars: 1000 };
|
|
16
|
+
(0, node_test_1.describe)('pruneToolResults', () => {
|
|
17
|
+
(0, node_test_1.it)('keeps everything while old bulky results stay under the trigger', () => {
|
|
18
|
+
const messages = [{ role: 'user', content: 'q' }, call('1'), result('1', { data: 'x'.repeat(500) }), call('2'), result('2', { ok: true })];
|
|
19
|
+
strict_1.default.equal((0, context_pruning_1.pruneToolResults)(messages, options), messages);
|
|
20
|
+
});
|
|
21
|
+
(0, node_test_1.it)('stubs old bulky results with the paths they pointed to, and keeps recent and small ones', () => {
|
|
22
|
+
const messages = [
|
|
23
|
+
{ role: 'user', content: 'q' },
|
|
24
|
+
call('1'),
|
|
25
|
+
result('1', { data: 'x'.repeat(1200), saved: { path: 'data/filings/T1.json', bytes: 9 }, manifest: { path: 'data/manifests/T1-attachments.jsonl' } }),
|
|
26
|
+
call('2'),
|
|
27
|
+
result('2', { ok: true }),
|
|
28
|
+
call('3'),
|
|
29
|
+
result('3', { data: 'y'.repeat(1200) }),
|
|
30
|
+
];
|
|
31
|
+
const pruned = (0, context_pruning_1.pruneToolResults)(messages, options);
|
|
32
|
+
const output = (index) => pruned[index].content[0].output;
|
|
33
|
+
strict_1.default.equal(output(2).type, 'text');
|
|
34
|
+
strict_1.default.match(String(output(2).value), /get_filing result removed.*data\/filings\/T1\.json, data\/manifests\/T1-attachments\.jsonl/);
|
|
35
|
+
strict_1.default.deepEqual(output(4), { type: 'json', value: { ok: true } });
|
|
36
|
+
strict_1.default.equal(output(6).type, 'json');
|
|
37
|
+
strict_1.default.equal(messages[2], messages[2], 'input is not mutated');
|
|
38
|
+
strict_1.default.equal(messages[2].content[0].output.type, 'json');
|
|
39
|
+
});
|
|
40
|
+
(0, node_test_1.it)('is monotonic: a result pruned at one step stays pruned when more steps follow', () => {
|
|
41
|
+
const base = [{ role: 'user', content: 'q' }, call('1'), result('1', { data: 'x'.repeat(1200) }), call('2'), result('2', { data: 'y'.repeat(150) })];
|
|
42
|
+
const later = [...base, call('3'), result('3', { data: 'z'.repeat(150) })];
|
|
43
|
+
const first = (0, context_pruning_1.pruneToolResults)(base, options);
|
|
44
|
+
const second = (0, context_pruning_1.pruneToolResults)(later, options);
|
|
45
|
+
strict_1.default.deepEqual(second.slice(0, 3), first.slice(0, 3));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=context-pruning.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-pruning.test.js","sourceRoot":"","sources":["../src/context-pruning.test.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AACvC,yCAAwC;AAExC,uDAAoD;AAEpD,SAAS,IAAI,CAAC,EAAU;IACtB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,CAAA;AACnH,CAAC;AAED,SAAS,MAAM,CAAC,EAAU,EAAE,KAA8B;IACxD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAc,EAAE,EAAE,CAAC,EAAE,CAAA;AACtJ,CAAC;AAED,MAAM,OAAO,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE,IAAK,EAAE,CAAA;AAErE,IAAA,oBAAQ,EAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAA,cAAE,EAAC,iEAAiE,EAAE,GAA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AAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;QAC1E,MAAM,KAAK,GAAG,IAAA,kCAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC7C,MAAM,MAAM,GAAG,IAAA,kCAAgB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC/C,gBAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
export { loadConfigFromEnv, type AgentRuntimeConfig, type AgentMode, type AgentProfile, type ResearchScope } from './config';
|
|
2
|
-
export { runAgentLoop } from './loop';
|
|
3
|
-
export { createReporter, type AgentEvent, type Reporter } from './
|
|
4
|
-
export { createSessionLink, type SessionLink } from './link';
|
|
1
|
+
export { loadConfigFromEnv, type AgentRuntimeConfig, type AgentMode, type AgentProfile, type ResearchScope } from './runtime/config';
|
|
2
|
+
export { runAgentLoop } from './task/loop';
|
|
3
|
+
export { createReporter, type AgentEvent, type Reporter } from './transport/reporter';
|
|
4
|
+
export { createSessionLink, type SessionLink } from './transport/link';
|
|
5
5
|
export { SessionAgent, runSessionAgent, limitConversation } from './session';
|
|
6
|
+
export { SessionRuntime, type SessionRuntimeDependencies } from './session/runtime';
|
|
7
|
+
export type { AgentDefinition, AgentModel } from './agent/definition';
|
|
8
|
+
export { createAgentDefinition } from './agent/profiles';
|
|
9
|
+
export { TurnRunner, type TurnInput, type TurnResult } from './agent/turn-runner';
|
|
10
|
+
export { createWorkspacePersistence, type WorkspacePersistence, type WorkspaceCheckpoint } from './persistence/workspace';
|
|
6
11
|
export { startAgent, type RunningAgent } from './runtime';
|
|
7
|
-
export { GitSync } from './git-sync';
|
|
8
|
-
export * from './protocol';
|
|
12
|
+
export { GitSync } from './persistence/git-sync';
|
|
13
|
+
export * from './transport/protocol';
|
|
9
14
|
export type { McpConnectionRecord, McpConnectionSummary, McpOAuthTokens, McpToolSummary } from './mcp/mcp-connection';
|
|
10
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACpI,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACrF,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,KAAK,0BAA0B,EAAE,MAAM,mBAAmB,CAAA;AACnF,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACjF,OAAO,EAAE,0BAA0B,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AACzH,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,cAAc,sBAAsB,CAAA;AACpC,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -14,22 +14,30 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.GitSync = exports.startAgent = exports.limitConversation = exports.runSessionAgent = exports.SessionAgent = exports.createSessionLink = exports.createReporter = exports.runAgentLoop = exports.loadConfigFromEnv = void 0;
|
|
18
|
-
var config_1 = require("./config");
|
|
17
|
+
exports.GitSync = exports.startAgent = exports.createWorkspacePersistence = exports.TurnRunner = exports.createAgentDefinition = exports.SessionRuntime = exports.limitConversation = exports.runSessionAgent = exports.SessionAgent = exports.createSessionLink = exports.createReporter = exports.runAgentLoop = exports.loadConfigFromEnv = void 0;
|
|
18
|
+
var config_1 = require("./runtime/config");
|
|
19
19
|
Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return config_1.loadConfigFromEnv; } });
|
|
20
|
-
var loop_1 = require("./loop");
|
|
20
|
+
var loop_1 = require("./task/loop");
|
|
21
21
|
Object.defineProperty(exports, "runAgentLoop", { enumerable: true, get: function () { return loop_1.runAgentLoop; } });
|
|
22
|
-
var
|
|
23
|
-
Object.defineProperty(exports, "createReporter", { enumerable: true, get: function () { return
|
|
24
|
-
var link_1 = require("./link");
|
|
22
|
+
var reporter_1 = require("./transport/reporter");
|
|
23
|
+
Object.defineProperty(exports, "createReporter", { enumerable: true, get: function () { return reporter_1.createReporter; } });
|
|
24
|
+
var link_1 = require("./transport/link");
|
|
25
25
|
Object.defineProperty(exports, "createSessionLink", { enumerable: true, get: function () { return link_1.createSessionLink; } });
|
|
26
26
|
var session_1 = require("./session");
|
|
27
27
|
Object.defineProperty(exports, "SessionAgent", { enumerable: true, get: function () { return session_1.SessionAgent; } });
|
|
28
28
|
Object.defineProperty(exports, "runSessionAgent", { enumerable: true, get: function () { return session_1.runSessionAgent; } });
|
|
29
29
|
Object.defineProperty(exports, "limitConversation", { enumerable: true, get: function () { return session_1.limitConversation; } });
|
|
30
|
-
var runtime_1 = require("./runtime");
|
|
31
|
-
Object.defineProperty(exports, "
|
|
32
|
-
var
|
|
30
|
+
var runtime_1 = require("./session/runtime");
|
|
31
|
+
Object.defineProperty(exports, "SessionRuntime", { enumerable: true, get: function () { return runtime_1.SessionRuntime; } });
|
|
32
|
+
var profiles_1 = require("./agent/profiles");
|
|
33
|
+
Object.defineProperty(exports, "createAgentDefinition", { enumerable: true, get: function () { return profiles_1.createAgentDefinition; } });
|
|
34
|
+
var turn_runner_1 = require("./agent/turn-runner");
|
|
35
|
+
Object.defineProperty(exports, "TurnRunner", { enumerable: true, get: function () { return turn_runner_1.TurnRunner; } });
|
|
36
|
+
var workspace_1 = require("./persistence/workspace");
|
|
37
|
+
Object.defineProperty(exports, "createWorkspacePersistence", { enumerable: true, get: function () { return workspace_1.createWorkspacePersistence; } });
|
|
38
|
+
var runtime_2 = require("./runtime");
|
|
39
|
+
Object.defineProperty(exports, "startAgent", { enumerable: true, get: function () { return runtime_2.startAgent; } });
|
|
40
|
+
var git_sync_1 = require("./persistence/git-sync");
|
|
33
41
|
Object.defineProperty(exports, "GitSync", { enumerable: true, get: function () { return git_sync_1.GitSync; } });
|
|
34
|
-
__exportStar(require("./protocol"), exports);
|
|
42
|
+
__exportStar(require("./transport/protocol"), exports);
|
|
35
43
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAoI;AAA3H,2GAAA,iBAAiB,OAAA;AAC1B,oCAA0C;AAAjC,oGAAA,YAAY,OAAA;AACrB,iDAAqF;AAA5E,0GAAA,cAAc,OAAA;AACvB,yCAAsE;AAA7D,yGAAA,iBAAiB,OAAA;AAC1B,qCAA4E;AAAnE,uGAAA,YAAY,OAAA;AAAE,0GAAA,eAAe,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AACzD,6CAAmF;AAA1E,yGAAA,cAAc,OAAA;AAEvB,6CAAwD;AAA/C,iHAAA,qBAAqB,OAAA;AAC9B,mDAAiF;AAAxE,yGAAA,UAAU,OAAA;AACnB,qDAAyH;AAAhH,uHAAA,0BAA0B,OAAA;AACnC,qCAAyD;AAAhD,qGAAA,UAAU,OAAA;AACnB,mDAAgD;AAAvC,mGAAA,OAAO,OAAA;AAChB,uDAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../../src/models/attribution.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,qBAAqB,mBAAmB,CAAA;AAErD,qFAAqF;AACrF,eAAO,MAAM,eAAe;IAC1B,kGAAkG;;IAElG,4CAA4C;;IAE5C,0CAA0C;;IAE1C,sCAAsC;;CAE9B,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAA;AAElF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAwB,GAAG,MAAM,CAMxF;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.js","sourceRoot":"","sources":["../../src/models/attribution.ts"],"names":[],"mappings":";AAAA,6FAA6F;AAC7F,uFAAuF;AACvF,EAAE;AACF,yFAAyF;AACzF,yFAAyF;AACzF,6FAA6F;AAC7F,yFAAyF;AACzF,4BAA4B;;;AAkB5B,oDAMC;AAGD,oDAEC;AA3BY,QAAA,qBAAqB,GAAG,gBAAgB,CAAA;AAErD,qFAAqF;AACxE,QAAA,eAAe,GAAG;IAC7B,kGAAkG;IAClG,YAAY,EAAE,cAAc;IAC5B,4CAA4C;IAC5C,aAAa,EAAE,eAAe;IAC9B,0CAA0C;IAC1C,aAAa,EAAE,eAAe;IAC9B,sCAAsC;IACtC,YAAY,EAAE,cAAc;CACpB,CAAA;AAIV,SAAgB,oBAAoB,CAAC,GAAW,EAAE,MAAM,GAAG,6BAAqB;IAC9E,MAAM,IAAI,GAAG,GAAG;SACb,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAC1B,OAAO,WAAW,IAAI,IAAI,MAAM,EAAE,CAAA;AACpC,CAAC;AAED,kFAAkF;AAClF,SAAgB,oBAAoB,CAAC,GAAW,EAAE,MAAM,GAAG,6BAAqB;IAC9E,OAAO,EAAE,cAAc,EAAE,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAA;AAC9E,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LanguageModel } from 'ai';
|
|
2
2
|
import { type OpenRouterApp } from './attribution';
|
|
3
|
-
import type { ModelProviderConfig } from '
|
|
3
|
+
import type { ModelProviderConfig } from '../runtime/config';
|
|
4
4
|
/** `app` names the workload on the OpenRouter dashboard; without it the calls show as "Unknown". */
|
|
5
5
|
export declare function resolveLanguageModel(provider: ModelProviderConfig, modelId: string, app: OpenRouterApp): LanguageModel;
|
|
6
|
-
//# sourceMappingURL=model.d.ts.map
|
|
6
|
+
//# sourceMappingURL=resolve-model.d.ts.map
|