@cuylabs/agent-core 0.8.0 → 0.10.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 +33 -17
- package/dist/chunk-2O4MCSQS.js +780 -0
- package/dist/chunk-2TTOLHBT.js +198 -0
- package/dist/chunk-5FMSGQVX.js +281 -0
- package/dist/chunk-5NVVNXPQ.js +288 -0
- package/dist/{chunk-CAA7FHIH.js → chunk-6HZBHFOL.js} +3 -103
- package/dist/chunk-CJI7PVS2.js +58 -0
- package/dist/{chunk-N6HWIEEA.js → chunk-CMYN2RCB.js} +278 -61
- package/dist/chunk-FII65CN7.js +117 -0
- package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
- package/dist/chunk-I6PKJ7XQ.js +292 -0
- package/dist/{chunk-BDBZ3SLK.js → chunk-ICZ66572.js} +48 -4
- package/dist/chunk-KYLPMBHD.js +316 -0
- package/dist/chunk-MXAP4UG6.js +2956 -0
- package/dist/{chunk-RZITT45F.js → chunk-N3VX7FEE.js} +39 -6
- package/dist/{chunk-YSLSEQ6B.js → chunk-NDZWXCBZ.js} +218 -95
- package/dist/{chunk-P6YF7USR.js → chunk-Q742PSH3.js} +23 -38
- package/dist/chunk-QAL3OMI3.js +943 -0
- package/dist/{chunk-RFEKJKTO.js → chunk-RN6WZEUF.js} +330 -280
- package/dist/{chunk-ZXAKHMWH.js → chunk-ROTGCYDW.js} +22 -84
- package/dist/chunk-SPBFQXOT.js +0 -0
- package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
- package/dist/chunk-SSFBF3US.js +602 -0
- package/dist/chunk-SZ2XBPTW.js +8 -0
- package/dist/chunk-T4UIX5D7.js +115 -0
- package/dist/chunk-TIHPYVAJ.js +102 -0
- package/dist/{chunk-YUUJK53A.js → chunk-TOTDGK3P.js} +1 -1
- package/dist/chunk-V4RFNEET.js +563 -0
- package/dist/chunk-VOUEJSW6.js +0 -0
- package/dist/{chunk-4BDA7DQY.js → chunk-WBPOZ7CL.js} +673 -273
- package/dist/chunk-X4VN4GIJ.js +185 -0
- package/dist/dispatch/index.d.ts +93 -0
- package/dist/dispatch/index.js +37 -0
- package/dist/events/index.d.ts +93 -0
- package/dist/events/index.js +6 -0
- package/dist/{runtime → execution}/index.d.ts +120 -34
- package/dist/{runtime → execution}/index.js +18 -13
- package/dist/index-BCqEGzBj.d.ts +251 -0
- package/dist/index.d.ts +490 -122
- package/dist/index.js +2104 -615
- package/dist/{errors → inference/errors}/index.d.ts +2 -2
- package/dist/{errors → inference/errors}/index.js +1 -1
- package/dist/inference/index.d.ts +16 -23
- package/dist/inference/index.js +45 -16
- package/dist/instance-BqV2D5pc.d.ts +5723 -0
- package/dist/logger/index.d.ts +50 -0
- package/dist/logger/index.js +11 -0
- package/dist/mcp/index.d.ts +5 -9
- package/dist/mcp/index.js +2 -3
- package/dist/middleware/index.d.ts +10 -149
- package/dist/middleware/index.js +11 -3
- package/dist/model-messages-B4nK9D1-.d.ts +13 -0
- package/dist/models/index.d.ts +23 -18
- package/dist/models/index.js +48 -11
- package/dist/models/reasoning/index.d.ts +4 -0
- package/dist/{reasoning → models/reasoning}/index.js +3 -3
- package/dist/plugin/index.d.ts +458 -0
- package/dist/plugin/index.js +32 -0
- package/dist/profiles/index.d.ts +55 -0
- package/dist/profiles/index.js +30 -0
- package/dist/prompt/index.d.ts +8 -12
- package/dist/prompt/index.js +3 -2
- package/dist/safety/index.d.ts +109 -14
- package/dist/safety/index.js +59 -3
- package/dist/sandbox/index.d.ts +81 -0
- package/dist/sandbox/index.js +1 -0
- package/dist/skill/index.d.ts +10 -8
- package/dist/skill/index.js +3 -3
- package/dist/storage/index.d.ts +12 -4
- package/dist/storage/index.js +1 -1
- package/dist/subagents/index.d.ts +177 -0
- package/dist/subagents/index.js +78 -0
- package/dist/team/index.d.ts +544 -0
- package/dist/team/index.js +41 -0
- package/dist/tool/host/index.d.ts +41 -0
- package/dist/tool/host/index.js +10 -0
- package/dist/tool/index.d.ts +125 -21
- package/dist/tool/index.js +20 -13
- package/dist/{types-VQgymC1N.d.ts → types-Bj_J8u_W.d.ts} +44 -64
- package/dist/{types-CHiPh8U2.d.ts → types-C_LCeYNg.d.ts} +7 -7
- package/dist/types-RSCv7nQ4.d.ts +59 -0
- package/package.json +58 -53
- package/dist/builder-UpOWQMW3.d.ts +0 -34
- package/dist/chunk-7MUFEN4K.js +0 -559
- package/dist/chunk-7VKQ4WPB.js +0 -73
- package/dist/chunk-BFM2YHNM.js +0 -222
- package/dist/chunk-DWYX7ASF.js +0 -26
- package/dist/chunk-KUVSERLJ.js +0 -50
- package/dist/chunk-N7P4PN3O.js +0 -84
- package/dist/chunk-SDSBEQXG.js +0 -157
- package/dist/chunk-SQU2AJHO.js +0 -305
- package/dist/chunk-VBWWUHWI.js +0 -724
- package/dist/chunk-VEKUXUVF.js +0 -41
- package/dist/chunk-VNQBHPCT.js +0 -398
- package/dist/chunk-WWYYNWEW.js +0 -259
- package/dist/context/index.d.ts +0 -259
- package/dist/context/index.js +0 -26
- package/dist/events-CE72w8W4.d.ts +0 -149
- package/dist/host/index.d.ts +0 -45
- package/dist/host/index.js +0 -8
- package/dist/index-CWSchSql.d.ts +0 -1058
- package/dist/messages-BYWGn8TY.d.ts +0 -110
- package/dist/presets/index.d.ts +0 -53
- package/dist/presets/index.js +0 -28
- package/dist/reasoning/index.d.ts +0 -116
- package/dist/registry-DwYqsQkX.d.ts +0 -164
- package/dist/runner-e2YRcUoX.d.ts +0 -786
- package/dist/scope/index.d.ts +0 -10
- package/dist/scope/index.js +0 -14
- package/dist/session-manager-B_CWGTsl.d.ts +0 -274
- package/dist/signal/index.d.ts +0 -28
- package/dist/signal/index.js +0 -6
- package/dist/sub-agent/index.d.ts +0 -23
- package/dist/sub-agent/index.js +0 -15
- package/dist/tool-BHbyUAy3.d.ts +0 -150
- package/dist/tool-DLXAR9Ce.d.ts +0 -145
- package/dist/tracker-DClqYqTj.d.ts +0 -96
- package/dist/tracking/index.d.ts +0 -111
- package/dist/tracking/index.js +0 -20
- package/dist/types-BfNpU8NS.d.ts +0 -270
- package/dist/types-BnpEOYV-.d.ts +0 -50
- package/dist/types-CQL-SvTn.d.ts +0 -29
- package/dist/types-CWm-7rvB.d.ts +0 -55
- package/dist/types-KKDrdU9Y.d.ts +0 -325
- package/dist/types-QA4WhEfz.d.ts +0 -138
- package/dist/types-QKHHQLLq.d.ts +0 -336
- package/dist/types-YuWV4ag7.d.ts +0 -72
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatApprovalDeniedReason
|
|
3
|
+
} from "./chunk-V4RFNEET.js";
|
|
4
|
+
import {
|
|
5
|
+
requiresToolHost
|
|
6
|
+
} from "./chunk-FII65CN7.js";
|
|
7
|
+
|
|
8
|
+
// src/scope/store.ts
|
|
9
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
10
|
+
import { randomUUID } from "crypto";
|
|
11
|
+
var scopeStore = new AsyncLocalStorage();
|
|
12
|
+
function cloneAttributes(attributes) {
|
|
13
|
+
return { ...attributes };
|
|
14
|
+
}
|
|
15
|
+
function cloneScope(scope) {
|
|
16
|
+
return {
|
|
17
|
+
...scope,
|
|
18
|
+
attributes: cloneAttributes(scope.attributes)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function getStoredScope() {
|
|
22
|
+
return scopeStore.getStore();
|
|
23
|
+
}
|
|
24
|
+
function buildScope(options, current) {
|
|
25
|
+
const parent = options.parent === void 0 ? current : options.parent ?? void 0;
|
|
26
|
+
const id = options.id ?? randomUUID();
|
|
27
|
+
return {
|
|
28
|
+
id,
|
|
29
|
+
rootId: parent?.rootId ?? id,
|
|
30
|
+
kind: options.kind,
|
|
31
|
+
name: options.name,
|
|
32
|
+
parentId: parent?.id,
|
|
33
|
+
depth: (parent?.depth ?? -1) + 1,
|
|
34
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35
|
+
sessionId: options.sessionId ?? parent?.sessionId,
|
|
36
|
+
taskId: options.taskId ?? parent?.taskId,
|
|
37
|
+
step: options.step ?? parent?.step,
|
|
38
|
+
attributes: cloneAttributes(options.attributes ?? {})
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function runWithScope(scope, fn) {
|
|
42
|
+
return Promise.resolve(scopeStore.run(scope, fn));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/scope/run.ts
|
|
46
|
+
function currentScope() {
|
|
47
|
+
const scope = getStoredScope();
|
|
48
|
+
return scope ? cloneScope(scope) : void 0;
|
|
49
|
+
}
|
|
50
|
+
function snapshotScope(scope = getStoredScope()) {
|
|
51
|
+
return scope ? cloneScope(scope) : void 0;
|
|
52
|
+
}
|
|
53
|
+
function withinScope(options, fn) {
|
|
54
|
+
return runWithScope(buildScope(options, getStoredScope()), fn);
|
|
55
|
+
}
|
|
56
|
+
function restoreScope(snapshot, fn) {
|
|
57
|
+
if (!snapshot) {
|
|
58
|
+
return Promise.resolve(fn());
|
|
59
|
+
}
|
|
60
|
+
return runWithScope(cloneScope(snapshot), fn);
|
|
61
|
+
}
|
|
62
|
+
async function* streamWithinScope(options, iterable) {
|
|
63
|
+
const scope = buildScope(options, getStoredScope());
|
|
64
|
+
const iterator = await runWithScope(scope, () => iterable[Symbol.asyncIterator]());
|
|
65
|
+
try {
|
|
66
|
+
while (true) {
|
|
67
|
+
const next = await runWithScope(scope, () => iterator.next());
|
|
68
|
+
if (next.done) {
|
|
69
|
+
return next.value;
|
|
70
|
+
}
|
|
71
|
+
yield next.value;
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
const returnFn = iterator.return?.bind(iterator);
|
|
75
|
+
if (returnFn) {
|
|
76
|
+
await runWithScope(scope, () => returnFn(void 0));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/types/compaction.ts
|
|
82
|
+
var PRUNE_PROTECTED_TOOLS = ["skill"];
|
|
83
|
+
|
|
84
|
+
// src/tracking/file-tracking.ts
|
|
85
|
+
function extractFilePathsFromArgs(args, meta) {
|
|
86
|
+
if (!meta.pathArgs || meta.pathArgs.length === 0) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const paths = [];
|
|
90
|
+
for (const argName of meta.pathArgs) {
|
|
91
|
+
const value = args[argName];
|
|
92
|
+
if (typeof value === "string") {
|
|
93
|
+
paths.push(value);
|
|
94
|
+
} else if (Array.isArray(value)) {
|
|
95
|
+
for (const item of value) {
|
|
96
|
+
if (typeof item === "string") {
|
|
97
|
+
paths.push(item);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return paths;
|
|
103
|
+
}
|
|
104
|
+
function shouldCaptureBaseline(meta) {
|
|
105
|
+
return meta.operationType !== "read";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/types/messages.ts
|
|
109
|
+
function accumulateUsage(current, next) {
|
|
110
|
+
if (!next) return current;
|
|
111
|
+
if (!current) {
|
|
112
|
+
return {
|
|
113
|
+
inputTokens: next.inputTokens ?? 0,
|
|
114
|
+
outputTokens: next.outputTokens ?? 0,
|
|
115
|
+
totalTokens: next.totalTokens ?? 0,
|
|
116
|
+
cacheReadTokens: (next.cacheReadTokens ?? 0) || void 0,
|
|
117
|
+
cacheWriteTokens: (next.cacheWriteTokens ?? 0) || void 0
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const cacheRead = (current.cacheReadTokens ?? 0) + (next.cacheReadTokens ?? 0);
|
|
121
|
+
const cacheWrite = (current.cacheWriteTokens ?? 0) + (next.cacheWriteTokens ?? 0);
|
|
122
|
+
return {
|
|
123
|
+
inputTokens: (current.inputTokens ?? 0) + (next.inputTokens ?? 0),
|
|
124
|
+
outputTokens: (current.outputTokens ?? 0) + (next.outputTokens ?? 0),
|
|
125
|
+
totalTokens: (current.totalTokens ?? 0) + (next.totalTokens ?? 0),
|
|
126
|
+
cacheReadTokens: cacheRead || void 0,
|
|
127
|
+
cacheWriteTokens: cacheWrite || void 0
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/tool/executor.ts
|
|
132
|
+
import { z } from "zod";
|
|
133
|
+
function parseToolParams(toolName, initialized, params) {
|
|
134
|
+
try {
|
|
135
|
+
return initialized.parameters.parse(params);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error instanceof z.ZodError && initialized.formatValidationError) {
|
|
138
|
+
throw new Error(initialized.formatValidationError(error), {
|
|
139
|
+
cause: error
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
throw new Error(
|
|
143
|
+
`The ${toolName} tool was called with invalid arguments: ${error}.
|
|
144
|
+
Please rewrite the input so it satisfies the expected schema.`,
|
|
145
|
+
{ cause: error }
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function executeAgentToolCall(options) {
|
|
150
|
+
const toolCallId = options.toolCallId ?? options.messageID;
|
|
151
|
+
return withinScope(
|
|
152
|
+
{
|
|
153
|
+
kind: "tool",
|
|
154
|
+
name: "tool-call",
|
|
155
|
+
sessionId: options.sessionID,
|
|
156
|
+
attributes: {
|
|
157
|
+
toolName: options.toolName,
|
|
158
|
+
messageId: options.messageID,
|
|
159
|
+
toolCallId,
|
|
160
|
+
agent: options.agent ?? "default"
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
async () => {
|
|
164
|
+
const initialized = options.initialized ?? await options.tool.init({ cwd: options.cwd });
|
|
165
|
+
const ctx = {
|
|
166
|
+
cwd: options.cwd,
|
|
167
|
+
abort: options.abort,
|
|
168
|
+
sessionID: options.sessionID,
|
|
169
|
+
...options.turnID ? { turnID: options.turnID } : {},
|
|
170
|
+
messageID: options.messageID,
|
|
171
|
+
agent: options.agent ?? "default",
|
|
172
|
+
scope: snapshotScope(),
|
|
173
|
+
...options.host ? { host: options.host } : {},
|
|
174
|
+
...options.humanInputController ? { humanInputController: options.humanInputController } : {},
|
|
175
|
+
...options.turnTracker ? { turnTracker: options.turnTracker } : {},
|
|
176
|
+
...options.onEvent ? { emitEvent: options.onEvent } : {},
|
|
177
|
+
...initialized.capabilities ? { toolCapabilities: initialized.capabilities } : {},
|
|
178
|
+
...initialized.hostRequirements ? { hostRequirements: initialized.hostRequirements } : {},
|
|
179
|
+
...initialized.permissionPatterns ? { permissionPatterns: initialized.permissionPatterns } : {},
|
|
180
|
+
extra: {
|
|
181
|
+
toolCallId
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
if (requiresToolHost(initialized.hostRequirements) && !options.host) {
|
|
185
|
+
return {
|
|
186
|
+
output: `Tool "${options.toolName}" requires an execution host, but none was configured.`,
|
|
187
|
+
capabilities: initialized.capabilities
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const parsedParams = parseToolParams(
|
|
191
|
+
options.toolName,
|
|
192
|
+
initialized,
|
|
193
|
+
options.params
|
|
194
|
+
);
|
|
195
|
+
if (initialized.validate) {
|
|
196
|
+
const check = await initialized.validate(parsedParams, ctx);
|
|
197
|
+
if (!check.ok) {
|
|
198
|
+
return {
|
|
199
|
+
output: `Input validation failed for ${options.toolName}: ${check.reason}`,
|
|
200
|
+
capabilities: initialized.capabilities
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let effectiveParams = parsedParams;
|
|
205
|
+
if (options.middleware?.hasMiddleware) {
|
|
206
|
+
const decision = await options.middleware.runBeforeToolCall(
|
|
207
|
+
options.toolName,
|
|
208
|
+
parsedParams,
|
|
209
|
+
ctx
|
|
210
|
+
);
|
|
211
|
+
if (decision.action === "deny") {
|
|
212
|
+
return {
|
|
213
|
+
output: decision.reason ?? formatApprovalDeniedReason(options.toolName),
|
|
214
|
+
...decision.correction ? {
|
|
215
|
+
metadata: {
|
|
216
|
+
approvalCorrection: decision.correction
|
|
217
|
+
}
|
|
218
|
+
} : {},
|
|
219
|
+
capabilities: initialized.capabilities
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (decision.args !== void 0) {
|
|
223
|
+
effectiveParams = parseToolParams(
|
|
224
|
+
options.toolName,
|
|
225
|
+
initialized,
|
|
226
|
+
decision.args
|
|
227
|
+
);
|
|
228
|
+
if (initialized.validate) {
|
|
229
|
+
const check = await initialized.validate(effectiveParams, ctx);
|
|
230
|
+
if (!check.ok) {
|
|
231
|
+
return {
|
|
232
|
+
output: `Input validation failed for ${options.toolName}: ${check.reason}`,
|
|
233
|
+
capabilities: initialized.capabilities
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (options.turnTracker && initialized.fileOps && shouldCaptureBaseline(initialized.fileOps)) {
|
|
240
|
+
const paths = extractFilePathsFromArgs(
|
|
241
|
+
effectiveParams,
|
|
242
|
+
initialized.fileOps
|
|
243
|
+
);
|
|
244
|
+
for (const path of paths) {
|
|
245
|
+
await options.turnTracker.beforeWrite(path);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const result = await initialized.execute(effectiveParams, ctx);
|
|
249
|
+
const metadata = result.metadata ?? {};
|
|
250
|
+
if (options.middleware?.hasMiddleware) {
|
|
251
|
+
const transformed = await options.middleware.runAfterToolCall(
|
|
252
|
+
options.toolName,
|
|
253
|
+
effectiveParams,
|
|
254
|
+
{ ...result, metadata },
|
|
255
|
+
ctx
|
|
256
|
+
);
|
|
257
|
+
const finalOutput = transformed.supplement ? `${transformed.output}
|
|
258
|
+
|
|
259
|
+
${transformed.supplement}` : transformed.output;
|
|
260
|
+
return {
|
|
261
|
+
output: finalOutput,
|
|
262
|
+
title: transformed.title,
|
|
263
|
+
metadata: transformed.metadata ?? {},
|
|
264
|
+
capabilities: initialized.capabilities
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
output: result.output,
|
|
269
|
+
title: result.title,
|
|
270
|
+
metadata,
|
|
271
|
+
capabilities: initialized.capabilities
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export {
|
|
278
|
+
currentScope,
|
|
279
|
+
snapshotScope,
|
|
280
|
+
withinScope,
|
|
281
|
+
restoreScope,
|
|
282
|
+
streamWithinScope,
|
|
283
|
+
PRUNE_PROTECTED_TOOLS,
|
|
284
|
+
extractFilePathsFromArgs,
|
|
285
|
+
shouldCaptureBaseline,
|
|
286
|
+
accumulateUsage,
|
|
287
|
+
executeAgentToolCall
|
|
288
|
+
};
|
|
@@ -1,100 +1,4 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
function globToRegex(pattern) {
|
|
3
|
-
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
4
|
-
return new RegExp(`^${escaped}$`, "i");
|
|
5
|
-
}
|
|
6
|
-
function matchesPatterns(id, patterns) {
|
|
7
|
-
return patterns.some((pattern) => globToRegex(pattern).test(id));
|
|
8
|
-
}
|
|
9
|
-
function filterTools(tools, options) {
|
|
10
|
-
const allowPatterns = options.allow ?? [];
|
|
11
|
-
const denyPatterns = options.deny ?? [];
|
|
12
|
-
return tools.filter((tool) => {
|
|
13
|
-
const matchesAllow = allowPatterns.length === 0 || matchesPatterns(tool.id, allowPatterns);
|
|
14
|
-
if (!matchesAllow) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const matchesDeny = denyPatterns.length > 0 && matchesPatterns(tool.id, denyPatterns);
|
|
18
|
-
if (matchesDeny && allowPatterns.length === 0) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/presets/apply.ts
|
|
26
|
-
function applyPreset(preset, availableTools, baseSystemPrompt) {
|
|
27
|
-
const tools = filterTools(availableTools, {
|
|
28
|
-
allow: preset.allowTools,
|
|
29
|
-
deny: preset.denyTools
|
|
30
|
-
});
|
|
31
|
-
let systemPrompt = preset.systemPrompt;
|
|
32
|
-
if (systemPrompt && baseSystemPrompt) {
|
|
33
|
-
systemPrompt = systemPrompt.replace("{basePrompt}", baseSystemPrompt);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
name: preset.name,
|
|
37
|
-
systemPrompt,
|
|
38
|
-
tools: tools.length > 0 ? tools : void 0,
|
|
39
|
-
temperature: preset.temperature,
|
|
40
|
-
maxSteps: preset.maxSteps,
|
|
41
|
-
reasoningLevel: preset.reasoningLevel,
|
|
42
|
-
model: preset.model
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function mergePresets(...presets) {
|
|
46
|
-
if (presets.length === 0) {
|
|
47
|
-
throw new Error("mergePresets requires at least one preset");
|
|
48
|
-
}
|
|
49
|
-
if (presets.length === 1) {
|
|
50
|
-
return presets[0];
|
|
51
|
-
}
|
|
52
|
-
const [first, ...rest] = presets;
|
|
53
|
-
const allAllow = [];
|
|
54
|
-
const allDeny = [];
|
|
55
|
-
for (const preset of presets) {
|
|
56
|
-
if (preset.allowTools?.length) {
|
|
57
|
-
allAllow.push(preset.allowTools);
|
|
58
|
-
}
|
|
59
|
-
if (preset.denyTools?.length) {
|
|
60
|
-
allDeny.push(...preset.denyTools);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const combinedAllow = allAllow.length > 0 ? allAllow.reduce(
|
|
64
|
-
(left, right) => left.length <= right.length ? left : right
|
|
65
|
-
) : void 0;
|
|
66
|
-
return {
|
|
67
|
-
name: presets.map((preset) => preset.name).join("+"),
|
|
68
|
-
description: presets.map((preset) => preset.description).join(" | "),
|
|
69
|
-
allowTools: combinedAllow,
|
|
70
|
-
denyTools: allDeny.length > 0 ? [...new Set(allDeny)] : void 0,
|
|
71
|
-
systemPrompt: rest.reduce(
|
|
72
|
-
(value, preset) => preset.systemPrompt ?? value,
|
|
73
|
-
first.systemPrompt
|
|
74
|
-
),
|
|
75
|
-
temperature: rest.reduce(
|
|
76
|
-
(value, preset) => preset.temperature ?? value,
|
|
77
|
-
first.temperature
|
|
78
|
-
),
|
|
79
|
-
maxSteps: rest.reduce(
|
|
80
|
-
(value, preset) => preset.maxSteps ?? value,
|
|
81
|
-
first.maxSteps
|
|
82
|
-
),
|
|
83
|
-
reasoningLevel: rest.reduce(
|
|
84
|
-
(value, preset) => preset.reasoningLevel ?? value,
|
|
85
|
-
first.reasoningLevel
|
|
86
|
-
),
|
|
87
|
-
model: rest.reduce((value, preset) => preset.model ?? value, first.model)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function createPreset(options) {
|
|
91
|
-
return {
|
|
92
|
-
description: options.description ?? `Custom preset: ${options.name}`,
|
|
93
|
-
...options
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// src/presets/builtins.ts
|
|
1
|
+
// src/profiles/builtins.ts
|
|
98
2
|
var explore = {
|
|
99
3
|
name: "explore",
|
|
100
4
|
description: "Read-only exploration mode for understanding content",
|
|
@@ -254,7 +158,7 @@ Guidelines:
|
|
|
254
158
|
maxSteps: 10,
|
|
255
159
|
reasoningLevel: "low"
|
|
256
160
|
};
|
|
257
|
-
var
|
|
161
|
+
var Profiles = {
|
|
258
162
|
explore,
|
|
259
163
|
plan,
|
|
260
164
|
review,
|
|
@@ -265,10 +169,6 @@ var Presets = {
|
|
|
265
169
|
};
|
|
266
170
|
|
|
267
171
|
export {
|
|
268
|
-
filterTools,
|
|
269
|
-
applyPreset,
|
|
270
|
-
mergePresets,
|
|
271
|
-
createPreset,
|
|
272
172
|
explore,
|
|
273
173
|
plan,
|
|
274
174
|
review,
|
|
@@ -276,5 +176,5 @@ export {
|
|
|
276
176
|
careful,
|
|
277
177
|
code,
|
|
278
178
|
watch,
|
|
279
|
-
|
|
179
|
+
Profiles
|
|
280
180
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/middleware/types.ts
|
|
2
|
+
function isBlockedModelCall(value) {
|
|
3
|
+
return "block" in value && value.block === true;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/agent/defaults.ts
|
|
7
|
+
var DEFAULT_SYSTEM_PROMPT = `You are a capable AI assistant with access to tools.
|
|
8
|
+
|
|
9
|
+
Think step by step about what you need to do.
|
|
10
|
+
Use the available tools to accomplish tasks.
|
|
11
|
+
Verify your results after each action.
|
|
12
|
+
|
|
13
|
+
If a tool fails, try an alternative approach \u2014 do not give up after a single error.
|
|
14
|
+
Keep working until the task is fully resolved or you have exhausted all options.`;
|
|
15
|
+
var DEFAULT_AGENT_NAME = "agent";
|
|
16
|
+
var DEFAULT_MAX_STEPS = 50;
|
|
17
|
+
var DEFAULT_MAX_TOKENS = 32e3;
|
|
18
|
+
function resolveAgentDefaults(context, providers) {
|
|
19
|
+
let merged = {
|
|
20
|
+
systemPrompt: DEFAULT_SYSTEM_PROMPT,
|
|
21
|
+
maxSteps: DEFAULT_MAX_STEPS,
|
|
22
|
+
maxOutputTokens: DEFAULT_MAX_TOKENS
|
|
23
|
+
};
|
|
24
|
+
if (providers) {
|
|
25
|
+
for (const provider of providers) {
|
|
26
|
+
const overrides = provider(context);
|
|
27
|
+
if (overrides) {
|
|
28
|
+
merged = {
|
|
29
|
+
systemPrompt: overrides.systemPrompt ?? merged.systemPrompt,
|
|
30
|
+
maxSteps: overrides.maxSteps ?? merged.maxSteps,
|
|
31
|
+
maxOutputTokens: overrides.maxOutputTokens ?? merged.maxOutputTokens
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return merged;
|
|
37
|
+
}
|
|
38
|
+
function sandboxDefaultsProvider(context) {
|
|
39
|
+
const sandbox = context.sandbox;
|
|
40
|
+
if (!sandbox) {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
const managed = sandbox.metadata?.managed === true;
|
|
44
|
+
if (managed) {
|
|
45
|
+
return { maxSteps: 100 };
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
isBlockedModelCall,
|
|
52
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
53
|
+
DEFAULT_AGENT_NAME,
|
|
54
|
+
DEFAULT_MAX_STEPS,
|
|
55
|
+
DEFAULT_MAX_TOKENS,
|
|
56
|
+
resolveAgentDefaults,
|
|
57
|
+
sandboxDefaultsProvider
|
|
58
|
+
};
|