@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.
Files changed (127) hide show
  1. package/README.md +33 -17
  2. package/dist/chunk-2O4MCSQS.js +780 -0
  3. package/dist/chunk-2TTOLHBT.js +198 -0
  4. package/dist/chunk-5FMSGQVX.js +281 -0
  5. package/dist/chunk-5NVVNXPQ.js +288 -0
  6. package/dist/{chunk-CAA7FHIH.js → chunk-6HZBHFOL.js} +3 -103
  7. package/dist/chunk-CJI7PVS2.js +58 -0
  8. package/dist/{chunk-N6HWIEEA.js → chunk-CMYN2RCB.js} +278 -61
  9. package/dist/chunk-FII65CN7.js +117 -0
  10. package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
  11. package/dist/chunk-I6PKJ7XQ.js +292 -0
  12. package/dist/{chunk-BDBZ3SLK.js → chunk-ICZ66572.js} +48 -4
  13. package/dist/chunk-KYLPMBHD.js +316 -0
  14. package/dist/chunk-MXAP4UG6.js +2956 -0
  15. package/dist/{chunk-RZITT45F.js → chunk-N3VX7FEE.js} +39 -6
  16. package/dist/{chunk-YSLSEQ6B.js → chunk-NDZWXCBZ.js} +218 -95
  17. package/dist/{chunk-P6YF7USR.js → chunk-Q742PSH3.js} +23 -38
  18. package/dist/chunk-QAL3OMI3.js +943 -0
  19. package/dist/{chunk-RFEKJKTO.js → chunk-RN6WZEUF.js} +330 -280
  20. package/dist/{chunk-ZXAKHMWH.js → chunk-ROTGCYDW.js} +22 -84
  21. package/dist/chunk-SPBFQXOT.js +0 -0
  22. package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
  23. package/dist/chunk-SSFBF3US.js +602 -0
  24. package/dist/chunk-SZ2XBPTW.js +8 -0
  25. package/dist/chunk-T4UIX5D7.js +115 -0
  26. package/dist/chunk-TIHPYVAJ.js +102 -0
  27. package/dist/{chunk-YUUJK53A.js → chunk-TOTDGK3P.js} +1 -1
  28. package/dist/chunk-V4RFNEET.js +563 -0
  29. package/dist/chunk-VOUEJSW6.js +0 -0
  30. package/dist/{chunk-4BDA7DQY.js → chunk-WBPOZ7CL.js} +673 -273
  31. package/dist/chunk-X4VN4GIJ.js +185 -0
  32. package/dist/dispatch/index.d.ts +93 -0
  33. package/dist/dispatch/index.js +37 -0
  34. package/dist/events/index.d.ts +93 -0
  35. package/dist/events/index.js +6 -0
  36. package/dist/{runtime → execution}/index.d.ts +120 -34
  37. package/dist/{runtime → execution}/index.js +18 -13
  38. package/dist/index-BCqEGzBj.d.ts +251 -0
  39. package/dist/index.d.ts +490 -122
  40. package/dist/index.js +2104 -615
  41. package/dist/{errors → inference/errors}/index.d.ts +2 -2
  42. package/dist/{errors → inference/errors}/index.js +1 -1
  43. package/dist/inference/index.d.ts +16 -23
  44. package/dist/inference/index.js +45 -16
  45. package/dist/instance-BqV2D5pc.d.ts +5723 -0
  46. package/dist/logger/index.d.ts +50 -0
  47. package/dist/logger/index.js +11 -0
  48. package/dist/mcp/index.d.ts +5 -9
  49. package/dist/mcp/index.js +2 -3
  50. package/dist/middleware/index.d.ts +10 -149
  51. package/dist/middleware/index.js +11 -3
  52. package/dist/model-messages-B4nK9D1-.d.ts +13 -0
  53. package/dist/models/index.d.ts +23 -18
  54. package/dist/models/index.js +48 -11
  55. package/dist/models/reasoning/index.d.ts +4 -0
  56. package/dist/{reasoning → models/reasoning}/index.js +3 -3
  57. package/dist/plugin/index.d.ts +458 -0
  58. package/dist/plugin/index.js +32 -0
  59. package/dist/profiles/index.d.ts +55 -0
  60. package/dist/profiles/index.js +30 -0
  61. package/dist/prompt/index.d.ts +8 -12
  62. package/dist/prompt/index.js +3 -2
  63. package/dist/safety/index.d.ts +109 -14
  64. package/dist/safety/index.js +59 -3
  65. package/dist/sandbox/index.d.ts +81 -0
  66. package/dist/sandbox/index.js +1 -0
  67. package/dist/skill/index.d.ts +10 -8
  68. package/dist/skill/index.js +3 -3
  69. package/dist/storage/index.d.ts +12 -4
  70. package/dist/storage/index.js +1 -1
  71. package/dist/subagents/index.d.ts +177 -0
  72. package/dist/subagents/index.js +78 -0
  73. package/dist/team/index.d.ts +544 -0
  74. package/dist/team/index.js +41 -0
  75. package/dist/tool/host/index.d.ts +41 -0
  76. package/dist/tool/host/index.js +10 -0
  77. package/dist/tool/index.d.ts +125 -21
  78. package/dist/tool/index.js +20 -13
  79. package/dist/{types-VQgymC1N.d.ts → types-Bj_J8u_W.d.ts} +44 -64
  80. package/dist/{types-CHiPh8U2.d.ts → types-C_LCeYNg.d.ts} +7 -7
  81. package/dist/types-RSCv7nQ4.d.ts +59 -0
  82. package/package.json +58 -53
  83. package/dist/builder-UpOWQMW3.d.ts +0 -34
  84. package/dist/chunk-7MUFEN4K.js +0 -559
  85. package/dist/chunk-7VKQ4WPB.js +0 -73
  86. package/dist/chunk-BFM2YHNM.js +0 -222
  87. package/dist/chunk-DWYX7ASF.js +0 -26
  88. package/dist/chunk-KUVSERLJ.js +0 -50
  89. package/dist/chunk-N7P4PN3O.js +0 -84
  90. package/dist/chunk-SDSBEQXG.js +0 -157
  91. package/dist/chunk-SQU2AJHO.js +0 -305
  92. package/dist/chunk-VBWWUHWI.js +0 -724
  93. package/dist/chunk-VEKUXUVF.js +0 -41
  94. package/dist/chunk-VNQBHPCT.js +0 -398
  95. package/dist/chunk-WWYYNWEW.js +0 -259
  96. package/dist/context/index.d.ts +0 -259
  97. package/dist/context/index.js +0 -26
  98. package/dist/events-CE72w8W4.d.ts +0 -149
  99. package/dist/host/index.d.ts +0 -45
  100. package/dist/host/index.js +0 -8
  101. package/dist/index-CWSchSql.d.ts +0 -1058
  102. package/dist/messages-BYWGn8TY.d.ts +0 -110
  103. package/dist/presets/index.d.ts +0 -53
  104. package/dist/presets/index.js +0 -28
  105. package/dist/reasoning/index.d.ts +0 -116
  106. package/dist/registry-DwYqsQkX.d.ts +0 -164
  107. package/dist/runner-e2YRcUoX.d.ts +0 -786
  108. package/dist/scope/index.d.ts +0 -10
  109. package/dist/scope/index.js +0 -14
  110. package/dist/session-manager-B_CWGTsl.d.ts +0 -274
  111. package/dist/signal/index.d.ts +0 -28
  112. package/dist/signal/index.js +0 -6
  113. package/dist/sub-agent/index.d.ts +0 -23
  114. package/dist/sub-agent/index.js +0 -15
  115. package/dist/tool-BHbyUAy3.d.ts +0 -150
  116. package/dist/tool-DLXAR9Ce.d.ts +0 -145
  117. package/dist/tracker-DClqYqTj.d.ts +0 -96
  118. package/dist/tracking/index.d.ts +0 -111
  119. package/dist/tracking/index.js +0 -20
  120. package/dist/types-BfNpU8NS.d.ts +0 -270
  121. package/dist/types-BnpEOYV-.d.ts +0 -50
  122. package/dist/types-CQL-SvTn.d.ts +0 -29
  123. package/dist/types-CWm-7rvB.d.ts +0 -55
  124. package/dist/types-KKDrdU9Y.d.ts +0 -325
  125. package/dist/types-QA4WhEfz.d.ts +0 -138
  126. package/dist/types-QKHHQLLq.d.ts +0 -336
  127. package/dist/types-YuWV4ag7.d.ts +0 -72
@@ -1,16 +1,23 @@
1
1
  import {
2
- executeAgentToolCall
3
- } from "./chunk-7VKQ4WPB.js";
4
- import {
5
- buildReasoningOptionsSync
6
- } from "./chunk-SQU2AJHO.js";
7
- import {
2
+ executeAgentToolCall,
8
3
  snapshotScope
9
- } from "./chunk-N7P4PN3O.js";
4
+ } from "./chunk-5NVVNXPQ.js";
10
5
  import {
11
6
  LLMError,
12
7
  isRetryable
13
- } from "./chunk-RZITT45F.js";
8
+ } from "./chunk-N3VX7FEE.js";
9
+ import {
10
+ buildReasoningOptionsSync,
11
+ supportsReasoningSync
12
+ } from "./chunk-RN6WZEUF.js";
13
+ import {
14
+ DEFAULT_MAX_STEPS,
15
+ DEFAULT_MAX_TOKENS,
16
+ isBlockedModelCall
17
+ } from "./chunk-CJI7PVS2.js";
18
+ import {
19
+ formatApprovalDeniedReason
20
+ } from "./chunk-V4RFNEET.js";
14
21
 
15
22
  // src/inference/toolset.ts
16
23
  import { tool, zodSchema } from "ai";
@@ -19,25 +26,58 @@ async function buildToolSet(options) {
19
26
  const executionMode = options.executionMode ?? "auto";
20
27
  for (const [id, info] of Object.entries(options.tools)) {
21
28
  const initialized = await info.init({ cwd: options.cwd });
22
- toolSet[id] = executionMode === "auto" ? tool({
23
- description: initialized.description,
24
- inputSchema: zodSchema(initialized.parameters),
25
- execute: async (params) => (await executeAgentToolCall({
26
- toolName: id,
27
- tool: info,
28
- params,
29
- cwd: options.cwd,
30
- abort: options.abort,
31
- sessionID: options.sessionID,
32
- messageID: options.messageID,
33
- ...options.host ? { host: options.host } : {},
34
- ...options.turnTracker ? { turnTracker: options.turnTracker } : {},
35
- ...options.middleware ? { middleware: options.middleware } : {}
36
- })).output
37
- }) : tool({
38
- description: initialized.description,
39
- inputSchema: zodSchema(initialized.parameters)
40
- });
29
+ const sdkPassthrough = {};
30
+ if (initialized.title !== void 0) sdkPassthrough.title = initialized.title;
31
+ if (initialized.strict !== void 0) sdkPassthrough.strict = initialized.strict;
32
+ if (initialized.inputExamples !== void 0) {
33
+ sdkPassthrough.inputExamples = initialized.inputExamples;
34
+ }
35
+ if (initialized.toModelOutput !== void 0) {
36
+ sdkPassthrough.toModelOutput = initialized.toModelOutput;
37
+ }
38
+ if (executionMode === "auto") {
39
+ toolSet[id] = tool({
40
+ description: initialized.description,
41
+ inputSchema: zodSchema(initialized.parameters),
42
+ ...sdkPassthrough,
43
+ execute: async (params, sdkOptions) => {
44
+ const executed = await executeAgentToolCall({
45
+ toolName: id,
46
+ tool: info,
47
+ initialized,
48
+ params,
49
+ cwd: options.cwd,
50
+ abort: options.abort,
51
+ sessionID: options.sessionID,
52
+ turnID: options.turnID,
53
+ messageID: options.messageID,
54
+ toolCallId: sdkOptions.toolCallId,
55
+ ...options.host ? { host: options.host } : {},
56
+ ...options.humanInputController ? { humanInputController: options.humanInputController } : {},
57
+ ...options.turnTracker ? { turnTracker: options.turnTracker } : {},
58
+ ...options.middleware ? { middleware: options.middleware } : {},
59
+ ...options.onEvent ? { onEvent: options.onEvent } : {}
60
+ });
61
+ if (!executed.metadata?.approvalCorrection) {
62
+ return executed.output;
63
+ }
64
+ const structured = {
65
+ __cuylabsAgentToolResult: true,
66
+ output: executed.output,
67
+ metadata: executed.metadata
68
+ };
69
+ return structured;
70
+ }
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ });
73
+ } else {
74
+ toolSet[id] = tool({
75
+ description: initialized.description,
76
+ inputSchema: zodSchema(initialized.parameters),
77
+ ...sdkPassthrough
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
+ });
80
+ }
41
81
  }
42
82
  return toolSet;
43
83
  }
@@ -48,7 +88,115 @@ import {
48
88
  streamText
49
89
  } from "ai";
50
90
 
51
- // src/retry.ts
91
+ // src/inference/middleware-support.ts
92
+ function isPlainObject(value) {
93
+ return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
94
+ }
95
+ function isAsyncIterable(value) {
96
+ return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
97
+ }
98
+ function stringifyToolOutput(output) {
99
+ if (typeof output === "string") {
100
+ return output;
101
+ }
102
+ try {
103
+ const serialized = JSON.stringify(output);
104
+ return serialized ?? String(output);
105
+ } catch {
106
+ return String(output);
107
+ }
108
+ }
109
+ async function runAfterToolCall(options) {
110
+ const { middleware, toolName, params, output, ctx } = options;
111
+ const transformed = await middleware.runAfterToolCall(
112
+ toolName,
113
+ params,
114
+ {
115
+ title: toolName,
116
+ output: stringifyToolOutput(output),
117
+ metadata: {}
118
+ },
119
+ ctx
120
+ );
121
+ return typeof output === "string" ? transformed.output : output;
122
+ }
123
+ function mergeProviderOptions(base, override) {
124
+ if (!base) return override;
125
+ if (!override) return base;
126
+ const merged = { ...base };
127
+ for (const [key, value] of Object.entries(override)) {
128
+ const current = merged[key];
129
+ merged[key] = isPlainObject(current) && isPlainObject(value) ? mergeProviderOptions(
130
+ current,
131
+ value
132
+ ) : value;
133
+ }
134
+ return merged;
135
+ }
136
+ function wrapMcpToolsForMiddleware(options) {
137
+ const { tools, middleware, cwd, sessionID, turnID, abort, agent } = options;
138
+ if (!middleware?.hasMiddleware) {
139
+ return tools;
140
+ }
141
+ const wrapped = {};
142
+ for (const [toolName, tool2] of Object.entries(tools)) {
143
+ if (!tool2.execute) {
144
+ wrapped[toolName] = tool2;
145
+ continue;
146
+ }
147
+ wrapped[toolName] = {
148
+ ...tool2,
149
+ execute: async (params, execOptions) => {
150
+ const ctx = {
151
+ cwd,
152
+ abort: execOptions.abortSignal ?? abort,
153
+ sessionID,
154
+ ...turnID ? { turnID } : {},
155
+ messageID: execOptions.toolCallId,
156
+ agent: agent ?? "default",
157
+ scope: snapshotScope(),
158
+ extra: {
159
+ toolCallId: execOptions.toolCallId,
160
+ messages: execOptions.messages,
161
+ experimentalContext: execOptions.experimental_context
162
+ }
163
+ };
164
+ const decision = await middleware.runBeforeToolCall(
165
+ toolName,
166
+ params,
167
+ ctx
168
+ );
169
+ if (decision.action === "deny") {
170
+ return decision.reason ?? formatApprovalDeniedReason(toolName);
171
+ }
172
+ const result = tool2.execute(params, execOptions);
173
+ if (isAsyncIterable(result)) {
174
+ let lastOutput;
175
+ for await (const chunk of result) {
176
+ lastOutput = chunk;
177
+ }
178
+ return await runAfterToolCall({
179
+ middleware,
180
+ toolName,
181
+ params,
182
+ output: lastOutput,
183
+ ctx
184
+ });
185
+ }
186
+ return await runAfterToolCall({
187
+ middleware,
188
+ toolName,
189
+ params,
190
+ output: await result,
191
+ ctx
192
+ });
193
+ }
194
+ };
195
+ }
196
+ return wrapped;
197
+ }
198
+
199
+ // src/inference/retry.ts
52
200
  var DEFAULT_RETRY_CONFIG = {
53
201
  maxAttempts: 3,
54
202
  initialDelayMs: 2e3,
@@ -139,14 +287,11 @@ function shouldRetry(error, attempt, maxAttempts = DEFAULT_RETRY_CONFIG.maxAttem
139
287
  return isRetryable(error);
140
288
  }
141
289
 
142
- // src/inference/types.ts
143
- var DEFAULT_MAX_OUTPUT_TOKENS = 32e3;
144
- var OUTPUT_TOKEN_MAX = DEFAULT_MAX_OUTPUT_TOKENS;
145
-
146
290
  // src/inference/stream.ts
147
291
  function buildModelCallContext(input) {
148
292
  return {
149
293
  sessionID: input.sessionID,
294
+ turnID: input.turnID,
150
295
  step: input.step ?? 1,
151
296
  cwd: input.cwd,
152
297
  abort: input.abort,
@@ -187,14 +332,6 @@ function applyModelCallInput(target, modelCall) {
187
332
  target.toolExecutionMode = modelCall.toolExecutionMode;
188
333
  target.activeModelCall = modelCall;
189
334
  }
190
- function mergeProviderOptions(base, override) {
191
- if (!base) return override;
192
- if (!override) return base;
193
- return { ...base, ...override };
194
- }
195
- function isBlockedModelCall(value) {
196
- return "block" in value && value.block === true;
197
- }
198
335
  async function resolveModelCallInput(input) {
199
336
  if (!input.middleware?.hasMiddleware) {
200
337
  const current = buildModelCallInput(input);
@@ -274,13 +411,20 @@ async function callStreamTextWithOtelContext(options) {
274
411
  system: systemParam,
275
412
  messages: input.messages,
276
413
  tools: allTools,
277
- stopWhen: stepCountIs(input.maxSteps ?? 50),
278
- maxOutputTokens: input.maxOutputTokens ?? DEFAULT_MAX_OUTPUT_TOKENS,
279
- temperature: input.temperature,
280
- topP: input.topP,
414
+ ...input.toolChoice ? { toolChoice: input.toolChoice } : {},
415
+ ...input.activeTools ? { activeTools: input.activeTools } : {},
416
+ stopWhen: stepCountIs(input.maxSteps ?? DEFAULT_MAX_STEPS),
417
+ maxOutputTokens: input.maxOutputTokens ?? DEFAULT_MAX_TOKENS,
418
+ ...input.temperature !== void 0 && !supportsReasoningSync(input.model) ? { temperature: input.temperature } : {},
419
+ ...input.topP !== void 0 && !supportsReasoningSync(input.model) ? { topP: input.topP } : {},
281
420
  abortSignal: input.abort,
282
421
  providerOptions: mergedProviderOptions,
283
422
  experimental_telemetry: input.telemetry,
423
+ // The AI SDK defaults to console.error(error) for stream failures.
424
+ // We normalize and surface these errors through our own runtime events,
425
+ // so suppress the duplicate raw dump here.
426
+ onError: () => {
427
+ },
284
428
  prepareStep: input.intervention ? async ({ messages }) => {
285
429
  const pending = input.intervention.drainImmediate();
286
430
  if (pending.length === 0) {
@@ -310,7 +454,10 @@ async function callStreamTextWithOtelContext(options) {
310
454
  });
311
455
  }
312
456
  });
313
- const otelCtx = input.middleware?.getOtelContext(input.sessionID);
457
+ const otelCtx = input.middleware?.getOtelContext(input.sessionID, {
458
+ sessionId: input.sessionID,
459
+ ...input.turnID ? { turnId: input.turnID } : {}
460
+ });
314
461
  if (!otelCtx) {
315
462
  return callStreamText();
316
463
  }
@@ -342,26 +489,40 @@ async function stream(input) {
342
489
  if (!input.retry || input.retry.maxAttempts === 0) {
343
490
  return wrapModelStream(await runCustomStream(), input);
344
491
  }
345
- return wrapModelStream(await withRetry(
346
- async () => await runCustomStream(),
347
- input.retry,
348
- input.abort
349
- ), input);
492
+ return wrapModelStream(
493
+ await withRetry(
494
+ async () => await runCustomStream(),
495
+ input.retry,
496
+ input.abort
497
+ ),
498
+ input
499
+ );
350
500
  }
351
501
  const toolSet = await buildToolSet({
352
502
  tools: input.tools,
353
503
  cwd: input.cwd,
354
504
  sessionID: input.sessionID,
505
+ turnID: input.turnID,
355
506
  messageID,
356
507
  abort: input.abort,
357
508
  turnTracker: input.turnTracker,
358
509
  host: input.host,
510
+ humanInputController: input.humanInputController,
359
511
  middleware: input.middleware,
512
+ onEvent: input.onEvent,
360
513
  executionMode: input.toolExecutionMode
361
514
  });
515
+ const mcpToolSet = wrapMcpToolsForMiddleware({
516
+ tools: input.mcpTools ?? {},
517
+ middleware: input.middleware,
518
+ cwd: input.cwd,
519
+ sessionID: input.sessionID,
520
+ turnID: input.turnID,
521
+ abort: input.abort
522
+ });
362
523
  const allTools = {
363
524
  ...toolSet,
364
- ...input.mcpTools ?? {}
525
+ ...mcpToolSet
365
526
  };
366
527
  const providerOptions = input.reasoningLevel ? buildReasoningOptionsSync(input.model, input.reasoningLevel) : void 0;
367
528
  const createStream = async () => {
@@ -379,11 +540,10 @@ async function stream(input) {
379
540
  if (!input.retry || input.retry.maxAttempts === 0) {
380
541
  return wrapModelStream(await createStream(), input);
381
542
  }
382
- return wrapModelStream(await withRetry(
383
- async () => await createStream(),
384
- input.retry,
385
- input.abort
386
- ), input);
543
+ return wrapModelStream(
544
+ await withRetry(async () => await createStream(), input.retry, input.abort),
545
+ input
546
+ );
387
547
  }
388
548
  async function streamOnce(input) {
389
549
  return await stream({ ...input, retry: void 0 });
@@ -395,16 +555,75 @@ async function streamStep(input) {
395
555
  });
396
556
  }
397
557
 
558
+ // src/inference/model-messages.ts
559
+ function buildApprovalCorrectionPrompt(correction) {
560
+ const lines = [
561
+ `Human approval denied the previous ${correction.tool} tool call.`,
562
+ `Treat this as corrective guidance and revise the plan before attempting another action.`,
563
+ `Reason: ${correction.reason}`
564
+ ];
565
+ if (correction.feedback) {
566
+ lines.push(`Feedback: ${correction.feedback}`);
567
+ }
568
+ return {
569
+ role: "system",
570
+ content: lines.join("\n")
571
+ };
572
+ }
573
+ function convertAgentMessagesToModelMessages(messages) {
574
+ return messages.flatMap((message) => {
575
+ switch (message.role) {
576
+ case "user":
577
+ return [{ role: "user", content: message.content }];
578
+ case "assistant": {
579
+ if (message.toolCalls && message.toolCalls.length > 0) {
580
+ const toolCallParts = message.toolCalls.map(
581
+ (toolCall) => ({
582
+ type: "tool-call",
583
+ toolCallId: toolCall.toolCallId,
584
+ toolName: toolCall.toolName,
585
+ input: toolCall.args
586
+ })
587
+ );
588
+ return [{ role: "assistant", content: toolCallParts }];
589
+ }
590
+ return [{ role: "assistant", content: message.content }];
591
+ }
592
+ case "tool":
593
+ return [
594
+ {
595
+ role: "tool",
596
+ content: [
597
+ {
598
+ type: "tool-result",
599
+ toolCallId: message.toolCallId ?? "",
600
+ toolName: message.toolName ?? "",
601
+ output: {
602
+ type: "text",
603
+ value: typeof message.result === "string" ? message.result : JSON.stringify(message.result)
604
+ }
605
+ }
606
+ ]
607
+ },
608
+ ...message.metadata?.approvalCorrection ? [buildApprovalCorrectionPrompt(message.metadata.approvalCorrection)] : []
609
+ ];
610
+ case "system":
611
+ return [{ role: "system", content: message.content }];
612
+ }
613
+ });
614
+ }
615
+
398
616
  // src/inference/index.ts
399
617
  var Inference = {
618
+ buildModelCallContext,
400
619
  buildToolSet,
401
620
  stream,
402
621
  streamOnce,
403
622
  streamStep
404
623
  };
405
- var LLM = Inference;
406
624
 
407
625
  export {
626
+ convertAgentMessagesToModelMessages,
408
627
  buildToolSet,
409
628
  DEFAULT_RETRY_CONFIG,
410
629
  createRetryState,
@@ -413,11 +632,9 @@ export {
413
632
  withRetry,
414
633
  createRetryHandler,
415
634
  shouldRetry,
416
- DEFAULT_MAX_OUTPUT_TOKENS,
417
- OUTPUT_TOKEN_MAX,
635
+ buildModelCallContext,
418
636
  stream,
419
637
  streamOnce,
420
638
  streamStep,
421
- Inference,
422
- LLM
639
+ Inference
423
640
  };
@@ -0,0 +1,117 @@
1
+ // src/safety/patterns.ts
2
+ function matchApprovalPattern(pattern, value) {
3
+ if (pattern.length > 500) return false;
4
+ const p = pattern.toLowerCase();
5
+ const v = value.toLowerCase();
6
+ let pi = 0;
7
+ let vi = 0;
8
+ let starPi = -1;
9
+ let starVi = -1;
10
+ while (vi < v.length) {
11
+ if (pi < p.length && (p[pi] === "?" || p[pi] === v[vi])) {
12
+ pi++;
13
+ vi++;
14
+ } else if (pi < p.length && p[pi] === "*") {
15
+ starPi = pi;
16
+ starVi = vi;
17
+ pi++;
18
+ } else if (starPi !== -1) {
19
+ pi = starPi + 1;
20
+ starVi++;
21
+ vi = starVi;
22
+ } else {
23
+ return false;
24
+ }
25
+ }
26
+ while (pi < p.length && p[pi] === "*") {
27
+ pi++;
28
+ }
29
+ return pi === p.length;
30
+ }
31
+ function extractApprovalPatterns(tool, args) {
32
+ if (!args || typeof args !== "object") {
33
+ return [tool];
34
+ }
35
+ const record = args;
36
+ if ("path" in record && typeof record.path === "string" || "filePath" in record && typeof record.filePath === "string") {
37
+ const path = record.path ?? record.filePath;
38
+ const dir = path.substring(0, path.lastIndexOf("/") + 1);
39
+ return [dir ? `${dir}*` : path];
40
+ }
41
+ if ("command" in record && typeof record.command === "string") {
42
+ const command = record.command.split(/\s+/)[0];
43
+ return [command];
44
+ }
45
+ if ("pattern" in record && typeof record.pattern === "string") {
46
+ return [record.pattern];
47
+ }
48
+ return [tool];
49
+ }
50
+ function describeApprovalOperation(tool, args) {
51
+ if (!args || typeof args !== "object") {
52
+ return `Execute ${tool}`;
53
+ }
54
+ const record = args;
55
+ switch (tool) {
56
+ case "read":
57
+ case "read_file":
58
+ return `Read file: ${record.path ?? record.filePath}`;
59
+ case "write":
60
+ case "write_file":
61
+ case "create_file":
62
+ return `Write file: ${record.path ?? record.filePath}`;
63
+ case "edit":
64
+ case "edit_file":
65
+ return `Edit file: ${record.path ?? record.filePath}`;
66
+ case "delete_file":
67
+ case "remove":
68
+ return `Delete: ${record.path}`;
69
+ case "bash":
70
+ case "shell": {
71
+ const command = String(record.command);
72
+ return `Run command: ${command.slice(0, 100)}${command.length > 100 ? "..." : ""}`;
73
+ }
74
+ case "grep":
75
+ return `Search for: ${record.pattern}`;
76
+ case "glob":
77
+ return `Find files: ${record.pattern}`;
78
+ default: {
79
+ const json = JSON.stringify(args);
80
+ const truncated = json.length > 50 ? `${json.slice(0, 50)}...` : json;
81
+ return `${tool}(${truncated})`;
82
+ }
83
+ }
84
+ }
85
+
86
+ // src/types/tool.ts
87
+ function requiresToolHost(requirements) {
88
+ if (!requirements) return false;
89
+ if (requirements.required !== void 0) {
90
+ return requirements.required;
91
+ }
92
+ return requirements.filesystem !== void 0 && requirements.filesystem !== "none" ? true : requirements.shell === true;
93
+ }
94
+ function getRequiredToolHost(ctx, options = {}) {
95
+ if (ctx.host) {
96
+ return ctx.host;
97
+ }
98
+ const target = options.toolName ? `Tool "${options.toolName}"` : "This tool";
99
+ const usageSuffix = options.usage ? ` (${options.usage})` : "";
100
+ throw new Error(
101
+ `${target} requires an execution host${usageSuffix}, but none was configured.`
102
+ );
103
+ }
104
+ function resolveCapability(cap, input, fallback) {
105
+ if (cap === void 0) return fallback;
106
+ if (typeof cap === "function") return cap(input);
107
+ return cap;
108
+ }
109
+
110
+ export {
111
+ matchApprovalPattern,
112
+ extractApprovalPatterns,
113
+ describeApprovalOperation,
114
+ requiresToolHost,
115
+ getRequiredToolHost,
116
+ resolveCapability
117
+ };
@@ -1,22 +1,13 @@
1
1
  import {
2
2
  createSkillRegistry,
3
3
  emptySkillRegistry
4
- } from "./chunk-LRHOS4ZN.js";
4
+ } from "./chunk-SPILYYDF.js";
5
+ import {
6
+ extractModelId,
7
+ extractProvider
8
+ } from "./chunk-I6PKJ7XQ.js";
5
9
 
6
10
  // src/prompt/templates.ts
7
- function extractModelId(model) {
8
- if (typeof model === "string") return model;
9
- if (typeof model === "object" && model !== null && "modelId" in model) {
10
- return String(model.modelId);
11
- }
12
- return void 0;
13
- }
14
- function extractProvider(model) {
15
- if (typeof model === "object" && model !== null && "provider" in model) {
16
- return String(model.provider);
17
- }
18
- return void 0;
19
- }
20
11
  function detectModelFamily(model) {
21
12
  const provider = extractProvider(model);
22
13
  const modelId = extractModelId(model);