@cuylabs/agent-core 0.6.0 → 0.8.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 +5 -1
- package/dist/{builder-BKkipazh.d.ts → builder-UpOWQMW3.d.ts} +2 -2
- package/dist/{chunk-3C4VKG4P.js → chunk-4BDA7DQY.js} +273 -807
- package/dist/chunk-7VKQ4WPB.js +73 -0
- package/dist/chunk-BFM2YHNM.js +222 -0
- package/dist/chunk-CAA7FHIH.js +280 -0
- package/dist/chunk-KUVSERLJ.js +50 -0
- package/dist/chunk-N6HWIEEA.js +423 -0
- package/dist/chunk-N7P4PN3O.js +84 -0
- package/dist/{chunk-QWFMX226.js → chunk-RFEKJKTO.js} +252 -13
- package/dist/chunk-RZITT45F.js +202 -0
- package/dist/{chunk-X635CM2F.js → chunk-SQU2AJHO.js} +1 -1
- package/dist/chunk-VNQBHPCT.js +398 -0
- package/dist/{chunk-QAQADS4X.js → chunk-WWYYNWEW.js} +2 -1
- package/dist/{chunk-O2ZCFQL6.js → chunk-YSLSEQ6B.js} +105 -220
- package/dist/context/index.js +1 -1
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +16 -0
- package/dist/events-CE72w8W4.d.ts +149 -0
- package/dist/host/index.d.ts +45 -0
- package/dist/host/index.js +8 -0
- package/dist/{index-DZQJD_hp.d.ts → index-CWSchSql.d.ts} +42 -51
- package/dist/index.d.ts +98 -190
- package/dist/index.js +476 -939
- package/dist/inference/index.d.ts +62 -0
- package/dist/inference/index.js +27 -0
- package/dist/llm-error-D93FNNLY.d.ts +32 -0
- package/dist/middleware/index.d.ts +246 -5
- package/dist/middleware/index.js +7 -3
- package/dist/models/index.d.ts +226 -3
- package/dist/models/index.js +41 -3
- package/dist/presets/index.d.ts +53 -0
- package/dist/presets/index.js +28 -0
- package/dist/prompt/index.d.ts +12 -7
- package/dist/reasoning/index.d.ts +53 -8
- package/dist/reasoning/index.js +2 -7
- package/dist/{registry-CuRWWtcT.d.ts → registry-DwYqsQkX.d.ts} +1 -1
- package/dist/{runner-G1wxEgac.d.ts → runner-e2YRcUoX.d.ts} +82 -148
- package/dist/runtime/index.d.ts +44 -7
- package/dist/runtime/index.js +16 -5
- package/dist/safety/index.d.ts +38 -0
- package/dist/safety/index.js +12 -0
- package/dist/scope/index.d.ts +10 -0
- package/dist/scope/index.js +14 -0
- package/dist/{session-manager-Uawm2Le7.d.ts → session-manager-B_CWGTsl.d.ts} +1 -1
- package/dist/signal/index.d.ts +28 -0
- package/dist/signal/index.js +6 -0
- package/dist/skill/index.d.ts +8 -5
- package/dist/storage/index.d.ts +2 -2
- package/dist/sub-agent/index.d.ts +17 -8
- package/dist/tool/index.d.ts +9 -4
- package/dist/tool/index.js +4 -3
- package/dist/tool-BHbyUAy3.d.ts +150 -0
- package/dist/{tool-DYp6-cC3.d.ts → tool-DLXAR9Ce.d.ts} +5 -99
- package/dist/tracking/index.d.ts +3 -1
- package/dist/{tool-pFAnJc5Y.d.ts → types-BfNpU8NS.d.ts} +1 -150
- package/dist/types-BnpEOYV-.d.ts +50 -0
- package/dist/types-CHiPh8U2.d.ts +100 -0
- package/dist/types-CQL-SvTn.d.ts +29 -0
- package/dist/types-CWm-7rvB.d.ts +55 -0
- package/dist/types-KKDrdU9Y.d.ts +325 -0
- package/dist/{resolver-DOfZ-xuk.d.ts → types-QA4WhEfz.d.ts} +1 -117
- package/dist/types-QKHHQLLq.d.ts +336 -0
- package/dist/types-YuWV4ag7.d.ts +72 -0
- package/package.json +74 -8
- package/dist/capabilities/index.d.ts +0 -97
- package/dist/capabilities/index.js +0 -46
- package/dist/chunk-6TDTQJ4P.js +0 -116
- package/dist/chunk-FG4MD5MU.js +0 -54
- package/dist/config-D2xeGEHK.d.ts +0 -52
- package/dist/identifiers-BLUxFqV_.d.ts +0 -12
- package/dist/index-ipP3_ztp.d.ts +0 -198
- package/dist/network-D76DS5ot.d.ts +0 -5
- package/dist/types-BWo810L_.d.ts +0 -648
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { LanguageModel, TelemetrySettings, ModelMessage, ToolSet } from 'ai';
|
|
2
|
+
import { T as Tool } from './tool-BHbyUAy3.js';
|
|
3
|
+
import { T as ToolHost } from './types-CHiPh8U2.js';
|
|
4
|
+
import { d as StreamProvider, M as MiddlewareRunner } from './runner-e2YRcUoX.js';
|
|
5
|
+
import { g as InterventionController, T as ToolExecutionMode, I as InferenceStreamInput } from './types-KKDrdU9Y.js';
|
|
6
|
+
import { R as ReasoningLevel } from './types-CQaXbRsS.js';
|
|
7
|
+
import { N as NormalizedToolReplayPolicy, d as TurnTrackerContext } from './tool-DLXAR9Ce.js';
|
|
8
|
+
import { T as TokenUsage, M as Message } from './messages-BYWGn8TY.js';
|
|
9
|
+
import { S as StepProcessingResult, A as AgentEvent, b as AgentTurnBoundaryKind } from './events-CE72w8W4.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Doom-loop handling contracts for repeated tool invocations.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Response from a doom-loop handler.
|
|
16
|
+
*/
|
|
17
|
+
type DoomLoopAction = "allow" | "deny" | "remember";
|
|
18
|
+
/**
|
|
19
|
+
* Doom-loop detection request.
|
|
20
|
+
*/
|
|
21
|
+
interface DoomLoopRequest {
|
|
22
|
+
/** The tool being called repeatedly */
|
|
23
|
+
tool: string;
|
|
24
|
+
/** How many times it has been called with the same input */
|
|
25
|
+
repeatCount: number;
|
|
26
|
+
/** The repeated input */
|
|
27
|
+
input: unknown;
|
|
28
|
+
/** Session ID */
|
|
29
|
+
sessionId: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handler for doom-loop situations.
|
|
33
|
+
*/
|
|
34
|
+
type DoomLoopHandler = (request: DoomLoopRequest) => Promise<DoomLoopAction>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Options for processing a streamed model result.
|
|
38
|
+
*/
|
|
39
|
+
interface StepProcessingOptions {
|
|
40
|
+
/** Session ID (optional - for tracking purposes) */
|
|
41
|
+
sessionID?: string;
|
|
42
|
+
/** Abort signal */
|
|
43
|
+
abort: AbortSignal;
|
|
44
|
+
/** Event callback */
|
|
45
|
+
onEvent: (event: AgentEvent) => void | Promise<void>;
|
|
46
|
+
/** Doom loop threshold (default: 3) */
|
|
47
|
+
doomLoopThreshold?: number;
|
|
48
|
+
/** Enforce doom loop (throw error vs warn) when no handler is provided */
|
|
49
|
+
enforceDoomLoop?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Handler for doom loop detection.
|
|
52
|
+
* Allows user choice: allow, deny, or remember.
|
|
53
|
+
*/
|
|
54
|
+
onDoomLoop?: DoomLoopHandler;
|
|
55
|
+
/** Tools that are "remembered" (allowed without asking) */
|
|
56
|
+
rememberedDoomLoopTools?: Set<string>;
|
|
57
|
+
/** Token limit for context overflow detection */
|
|
58
|
+
contextTokenLimit?: number;
|
|
59
|
+
/** Callback for context overflow */
|
|
60
|
+
onContextOverflow?: (tokens: number, limit: number) => void | Promise<void>;
|
|
61
|
+
/** Current step number */
|
|
62
|
+
currentStep?: number;
|
|
63
|
+
/** Max steps */
|
|
64
|
+
maxSteps?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Result of stream processing.
|
|
68
|
+
*/
|
|
69
|
+
interface StepProcessingOutput {
|
|
70
|
+
/** Processing result */
|
|
71
|
+
result: StepProcessingResult;
|
|
72
|
+
/** Accumulated text */
|
|
73
|
+
text: string;
|
|
74
|
+
/** Tool results */
|
|
75
|
+
toolResults: Array<{
|
|
76
|
+
toolName: string;
|
|
77
|
+
toolCallId: string;
|
|
78
|
+
result: unknown;
|
|
79
|
+
}>;
|
|
80
|
+
/** Final usage */
|
|
81
|
+
usage?: TokenUsage;
|
|
82
|
+
/** Finish reason reported by the most recent completed step */
|
|
83
|
+
finishReason?: string;
|
|
84
|
+
/** Error if any */
|
|
85
|
+
error?: Error;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated Use `StepProcessingOptions`.
|
|
89
|
+
*/
|
|
90
|
+
type ProcessorOptions = StepProcessingOptions;
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated Use `StepProcessingOutput`.
|
|
93
|
+
*/
|
|
94
|
+
type ProcessorOutput = StepProcessingOutput;
|
|
95
|
+
|
|
96
|
+
interface AgentTurnEngineOptions {
|
|
97
|
+
sessionId: string;
|
|
98
|
+
startedAt: string;
|
|
99
|
+
getToolReplayPolicy?: (toolName: string) => NormalizedToolReplayPolicy | undefined;
|
|
100
|
+
}
|
|
101
|
+
interface AgentTurnBoundaryMetadata {
|
|
102
|
+
step?: number;
|
|
103
|
+
messageRole?: Message["role"];
|
|
104
|
+
pendingToolCallCount?: number;
|
|
105
|
+
}
|
|
106
|
+
interface AgentTurnStepCommitToolCall {
|
|
107
|
+
toolCallId: string;
|
|
108
|
+
toolName: string;
|
|
109
|
+
args: unknown;
|
|
110
|
+
replayPolicy?: NormalizedToolReplayPolicy;
|
|
111
|
+
}
|
|
112
|
+
interface AgentTurnStepCommitToolResult {
|
|
113
|
+
toolCallId: string;
|
|
114
|
+
toolName: string;
|
|
115
|
+
result: unknown;
|
|
116
|
+
replayPolicy?: NormalizedToolReplayPolicy;
|
|
117
|
+
}
|
|
118
|
+
interface AgentTurnStepCommitSnapshot {
|
|
119
|
+
toolCalls: AgentTurnStepCommitToolCall[];
|
|
120
|
+
toolResults: AgentTurnStepCommitToolResult[];
|
|
121
|
+
}
|
|
122
|
+
interface CreateAgentTurnStepCommitBatchOptions {
|
|
123
|
+
assistantMessageId?: string;
|
|
124
|
+
toolMessageIds?: Record<string, string>;
|
|
125
|
+
createdAt?: Date;
|
|
126
|
+
}
|
|
127
|
+
interface AgentTurnCommitBatch {
|
|
128
|
+
startBoundary: AgentEvent & {
|
|
129
|
+
type: "turn-boundary";
|
|
130
|
+
};
|
|
131
|
+
finishBoundary: AgentEvent & {
|
|
132
|
+
type: "turn-boundary";
|
|
133
|
+
};
|
|
134
|
+
messages: Message[];
|
|
135
|
+
}
|
|
136
|
+
interface AgentTurnOutputCommitOptions {
|
|
137
|
+
text: string;
|
|
138
|
+
usage?: TokenUsage;
|
|
139
|
+
createdAt?: Date;
|
|
140
|
+
id?: string;
|
|
141
|
+
}
|
|
142
|
+
type AgentTurnBoundaryEvent = AgentEvent & {
|
|
143
|
+
type: "turn-boundary";
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
type AgentTurnPhase = "initializing" | "committing-input" | "running-model" | "running-tools" | "committing-step" | "committing-output" | "completed" | "failed";
|
|
147
|
+
interface AgentTurnBoundarySnapshot {
|
|
148
|
+
kind: AgentTurnBoundaryKind;
|
|
149
|
+
createdAt: string;
|
|
150
|
+
step?: number;
|
|
151
|
+
messageRole?: "system" | "user" | "assistant" | "tool";
|
|
152
|
+
pendingToolCallCount?: number;
|
|
153
|
+
}
|
|
154
|
+
interface AgentTurnActiveToolCall {
|
|
155
|
+
toolCallId: string;
|
|
156
|
+
toolName: string;
|
|
157
|
+
input: unknown;
|
|
158
|
+
startedAt: string;
|
|
159
|
+
replayPolicy?: NormalizedToolReplayPolicy;
|
|
160
|
+
}
|
|
161
|
+
interface AgentTurnResolvedToolCall {
|
|
162
|
+
toolCallId: string;
|
|
163
|
+
toolName: string;
|
|
164
|
+
outcome: "result" | "error";
|
|
165
|
+
value: unknown;
|
|
166
|
+
resolvedAt: string;
|
|
167
|
+
replayPolicy?: NormalizedToolReplayPolicy;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Neutral state model for a single in-flight agent turn.
|
|
171
|
+
*
|
|
172
|
+
* This is intentionally infrastructure-agnostic. Runtime adapters can persist
|
|
173
|
+
* or inspect it without coupling `agent-core` to Dapr, queues, or workflow
|
|
174
|
+
* engines. The current shape is suitable for durable tracking and forms the
|
|
175
|
+
* basis for future workflow-level resume support.
|
|
176
|
+
*/
|
|
177
|
+
interface AgentTurnState {
|
|
178
|
+
sessionId: string;
|
|
179
|
+
phase: AgentTurnPhase;
|
|
180
|
+
step: number;
|
|
181
|
+
maxSteps?: number;
|
|
182
|
+
response: string;
|
|
183
|
+
usage: TokenUsage;
|
|
184
|
+
eventCount: number;
|
|
185
|
+
activeToolCalls: AgentTurnActiveToolCall[];
|
|
186
|
+
resolvedToolCalls: AgentTurnResolvedToolCall[];
|
|
187
|
+
lastFinishReason?: string;
|
|
188
|
+
lastBoundary?: AgentTurnBoundarySnapshot;
|
|
189
|
+
lastEvent?: AgentEvent;
|
|
190
|
+
error?: string;
|
|
191
|
+
startedAt: string;
|
|
192
|
+
updatedAt: string;
|
|
193
|
+
}
|
|
194
|
+
interface CreateAgentTurnStateOptions {
|
|
195
|
+
sessionId: string;
|
|
196
|
+
startedAt: string;
|
|
197
|
+
}
|
|
198
|
+
interface AgentTurnStateAdvanceOptions {
|
|
199
|
+
toolReplayPolicy?: NormalizedToolReplayPolicy;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Create the initial neutral state for a single agent turn.
|
|
203
|
+
*/
|
|
204
|
+
declare function createAgentTurnState(options: CreateAgentTurnStateOptions): AgentTurnState;
|
|
205
|
+
/**
|
|
206
|
+
* Advance neutral turn state from a streamed `AgentEvent`.
|
|
207
|
+
*
|
|
208
|
+
* This reducer deliberately models coarse but deterministic boundaries:
|
|
209
|
+
* step start, tool activity, step finish, completion, and failure. Runtime
|
|
210
|
+
* adapters can persist the resulting state now, and future resume-capable
|
|
211
|
+
* engines can build on the same state transitions.
|
|
212
|
+
*/
|
|
213
|
+
declare function advanceAgentTurnState(state: AgentTurnState, event: AgentEvent, updatedAt: string, options?: AgentTurnStateAdvanceOptions): AgentTurnState;
|
|
214
|
+
/**
|
|
215
|
+
* Mark the turn as failed when execution aborts without a terminal `error`
|
|
216
|
+
* event. This covers exceptions thrown by the stream itself or runtime
|
|
217
|
+
* wrappers around the loop.
|
|
218
|
+
*/
|
|
219
|
+
declare function failAgentTurnState(state: AgentTurnState, error: Error, updatedAt: string): AgentTurnState;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Neutral internal turn engine for one in-flight agent turn.
|
|
223
|
+
*/
|
|
224
|
+
declare class AgentTurnEngine {
|
|
225
|
+
private turnState;
|
|
226
|
+
private readonly pendingToolCalls;
|
|
227
|
+
private readonly pendingToolResults;
|
|
228
|
+
private readonly getToolReplayPolicy?;
|
|
229
|
+
constructor(options: AgentTurnEngineOptions);
|
|
230
|
+
getState(): AgentTurnState;
|
|
231
|
+
hasPendingToolCalls(): boolean;
|
|
232
|
+
createStepCommitSnapshot(): AgentTurnStepCommitSnapshot | undefined;
|
|
233
|
+
recordEvent(event: AgentEvent, updatedAt: string): AgentTurnState;
|
|
234
|
+
createBoundaryEvent(boundary: AgentTurnBoundaryKind, metadata?: AgentTurnBoundaryMetadata): AgentTurnBoundaryEvent;
|
|
235
|
+
createInputCommit(options: {
|
|
236
|
+
content: string;
|
|
237
|
+
system?: string;
|
|
238
|
+
createdAt?: Date;
|
|
239
|
+
id?: string;
|
|
240
|
+
}): AgentTurnCommitBatch;
|
|
241
|
+
createInterventionCommit(options: {
|
|
242
|
+
id: string;
|
|
243
|
+
content: string;
|
|
244
|
+
createdAt?: Date;
|
|
245
|
+
}): AgentTurnCommitBatch;
|
|
246
|
+
consumeStepCommit(step: number): AgentTurnCommitBatch | undefined;
|
|
247
|
+
createOutputCommit(options: AgentTurnOutputCommitOptions): AgentTurnCommitBatch | undefined;
|
|
248
|
+
}
|
|
249
|
+
declare function createAgentTurnEngine(options: AgentTurnEngineOptions): AgentTurnEngine;
|
|
250
|
+
|
|
251
|
+
interface AgentTurnCommitOptions {
|
|
252
|
+
emitMessages?: boolean;
|
|
253
|
+
}
|
|
254
|
+
type AgentTurnCommitApplier = (batch: AgentTurnCommitBatch, options?: AgentTurnCommitOptions) => AsyncGenerator<AgentEvent>;
|
|
255
|
+
interface AgentTurnStepRuntimeConfig {
|
|
256
|
+
model: LanguageModel;
|
|
257
|
+
cwd: string;
|
|
258
|
+
temperature?: number;
|
|
259
|
+
topP?: number;
|
|
260
|
+
maxOutputTokens?: number;
|
|
261
|
+
maxSteps: number;
|
|
262
|
+
doomLoopThreshold?: number;
|
|
263
|
+
enforceDoomLoop?: boolean;
|
|
264
|
+
onDoomLoop?: DoomLoopHandler;
|
|
265
|
+
contextWindow?: number;
|
|
266
|
+
streamProvider?: StreamProvider;
|
|
267
|
+
telemetry?: TelemetrySettings;
|
|
268
|
+
}
|
|
269
|
+
interface PrepareModelStepOptions {
|
|
270
|
+
sessionId: string;
|
|
271
|
+
step: number;
|
|
272
|
+
systemPrompts: string[];
|
|
273
|
+
messages: Message[];
|
|
274
|
+
toModelMessages: (messages: Message[]) => ModelMessage[];
|
|
275
|
+
abort: AbortSignal;
|
|
276
|
+
tools: Record<string, Tool.Info>;
|
|
277
|
+
mcpTools?: ToolSet;
|
|
278
|
+
config: AgentTurnStepRuntimeConfig;
|
|
279
|
+
host?: ToolHost;
|
|
280
|
+
turnTracker?: TurnTrackerContext;
|
|
281
|
+
intervention?: InterventionController;
|
|
282
|
+
middleware?: MiddlewareRunner;
|
|
283
|
+
reasoningLevel?: ReasoningLevel;
|
|
284
|
+
toolExecutionMode?: ToolExecutionMode;
|
|
285
|
+
}
|
|
286
|
+
interface PreparedAgentModelStep {
|
|
287
|
+
step: number;
|
|
288
|
+
messages: Message[];
|
|
289
|
+
modelMessages: ModelMessage[];
|
|
290
|
+
inferenceInput: InferenceStreamInput;
|
|
291
|
+
stepProcessing: {
|
|
292
|
+
maxSteps: number;
|
|
293
|
+
doomLoopThreshold?: number;
|
|
294
|
+
enforceDoomLoop?: boolean;
|
|
295
|
+
onDoomLoop?: DoomLoopHandler;
|
|
296
|
+
contextTokenLimit?: number;
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
interface RunModelStepOptions {
|
|
300
|
+
preparedStep: PreparedAgentModelStep;
|
|
301
|
+
turnEngine: AgentTurnEngine;
|
|
302
|
+
applyCommitBatch: AgentTurnCommitApplier;
|
|
303
|
+
rememberedDoomLoopTools?: Set<string>;
|
|
304
|
+
}
|
|
305
|
+
interface CommitStepOptions {
|
|
306
|
+
step: number;
|
|
307
|
+
finishReason?: string;
|
|
308
|
+
turnEngine: AgentTurnEngine;
|
|
309
|
+
applyCommitBatch: AgentTurnCommitApplier;
|
|
310
|
+
}
|
|
311
|
+
interface CommitOutputOptions {
|
|
312
|
+
text: string;
|
|
313
|
+
usage?: StepProcessingOutput["usage"];
|
|
314
|
+
turnEngine: AgentTurnEngine;
|
|
315
|
+
applyCommitBatch: AgentTurnCommitApplier;
|
|
316
|
+
}
|
|
317
|
+
interface RunToolBatchOptions {
|
|
318
|
+
sessionId: string;
|
|
319
|
+
snapshot: AgentTurnStepCommitSnapshot;
|
|
320
|
+
tools: Record<string, Tool.Info>;
|
|
321
|
+
cwd: string;
|
|
322
|
+
abort: AbortSignal;
|
|
323
|
+
host?: ToolHost;
|
|
324
|
+
turnTracker?: TurnTrackerContext;
|
|
325
|
+
middleware?: MiddlewareRunner;
|
|
326
|
+
turnState?: AgentTurnState;
|
|
327
|
+
}
|
|
328
|
+
interface RunToolBatchResult {
|
|
329
|
+
snapshot: AgentTurnStepCommitSnapshot;
|
|
330
|
+
turnState?: AgentTurnState;
|
|
331
|
+
events: Array<Extract<AgentEvent, {
|
|
332
|
+
type: "tool-result" | "tool-error";
|
|
333
|
+
}>>;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export { type AgentTurnActiveToolCall as A, advanceAgentTurnState as B, type CommitOutputOptions as C, type DoomLoopAction as D, createAgentTurnEngine as E, createAgentTurnState as F, failAgentTurnState as G, type PrepareModelStepOptions as P, type RunModelStepOptions as R, type StepProcessingOptions as S, type AgentTurnBoundaryMetadata as a, type AgentTurnBoundarySnapshot as b, type AgentTurnCommitApplier as c, type AgentTurnCommitBatch as d, type AgentTurnCommitOptions as e, AgentTurnEngine as f, type AgentTurnEngineOptions as g, type AgentTurnPhase as h, type AgentTurnResolvedToolCall as i, type AgentTurnState as j, type AgentTurnStateAdvanceOptions as k, type AgentTurnStepCommitSnapshot as l, type AgentTurnStepCommitToolCall as m, type AgentTurnStepCommitToolResult as n, type AgentTurnStepRuntimeConfig as o, type CommitStepOptions as p, type CreateAgentTurnStateOptions as q, type CreateAgentTurnStepCommitBatchOptions as r, type DoomLoopHandler as s, type DoomLoopRequest as t, type PreparedAgentModelStep as u, type ProcessorOptions as v, type ProcessorOutput as w, type RunToolBatchOptions as x, type RunToolBatchResult as y, type StepProcessingOutput as z };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { A as AgentEvent } from './events-CE72w8W4.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent Signal — typed event dispatch interface.
|
|
5
|
+
*
|
|
6
|
+
* Defines how consumers subscribe to {@link AgentEvent}s without being
|
|
7
|
+
* part of the middleware stack. Each Agent owns a signal; events are
|
|
8
|
+
* scoped to that agent instance.
|
|
9
|
+
*
|
|
10
|
+
* The default implementation (`LocalSignal`) dispatches in-process via
|
|
11
|
+
* plain function calls. A distributed runtime can supply its own
|
|
12
|
+
* implementation that bridges to external infrastructure.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extract a single variant from the AgentEvent union by its `type` tag.
|
|
17
|
+
*/
|
|
18
|
+
type EventOf<T extends AgentEvent["type"]> = Extract<AgentEvent, {
|
|
19
|
+
type: T;
|
|
20
|
+
}>;
|
|
21
|
+
/** Handler for a specific event type. */
|
|
22
|
+
type TypedHandler<T extends AgentEvent["type"]> = (event: EventOf<T>) => void;
|
|
23
|
+
/** Handler that receives every event regardless of type. */
|
|
24
|
+
type WildcardHandler = (event: AgentEvent) => void;
|
|
25
|
+
/** Call to remove a previously registered handler. */
|
|
26
|
+
type Unsubscribe = () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Typed, multi-consumer event dispatch.
|
|
29
|
+
*
|
|
30
|
+
* Subscribe to agent events from anywhere — SSE routes, TUI renderers,
|
|
31
|
+
* plugins, tests. The interface is deliberately minimal so that backend
|
|
32
|
+
* implementations (in-process, Dapr, Redis, …) have a small contract to
|
|
33
|
+
* fulfil.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // Subscribe to a specific event
|
|
38
|
+
* const off = agent.signal.on("text-delta", (e) => process.stdout.write(e.text));
|
|
39
|
+
*
|
|
40
|
+
* // Subscribe to everything
|
|
41
|
+
* const off2 = agent.signal.onAny((e) => logger.info(e.type));
|
|
42
|
+
*
|
|
43
|
+
* // Clean up
|
|
44
|
+
* off();
|
|
45
|
+
* off2();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
interface AgentSignal {
|
|
49
|
+
/**
|
|
50
|
+
* Subscribe to a specific event type.
|
|
51
|
+
*
|
|
52
|
+
* @returns An unsubscribe function.
|
|
53
|
+
*/
|
|
54
|
+
on<T extends AgentEvent["type"]>(type: T, handler: TypedHandler<T>): Unsubscribe;
|
|
55
|
+
/**
|
|
56
|
+
* Subscribe to all events.
|
|
57
|
+
*
|
|
58
|
+
* @returns An unsubscribe function.
|
|
59
|
+
*/
|
|
60
|
+
onAny(handler: WildcardHandler): Unsubscribe;
|
|
61
|
+
/**
|
|
62
|
+
* Dispatch an event to every matching handler.
|
|
63
|
+
*
|
|
64
|
+
* Called internally by the Agent — but nothing prevents external code
|
|
65
|
+
* from injecting a synthetic event (useful for testing or bridging).
|
|
66
|
+
*/
|
|
67
|
+
emit(event: AgentEvent): void;
|
|
68
|
+
/** Remove all handlers. Called during agent disposal. */
|
|
69
|
+
clear(): void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type { AgentSignal as A, EventOf as E, TypedHandler as T, Unsubscribe as U, WildcardHandler as W };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/agent-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Embeddable AI agent infrastructure — execution, sessions, tools, skills, sub-agents, tracing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"import": "./dist/runtime/index.js",
|
|
22
22
|
"default": "./dist/runtime/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./inference": {
|
|
25
|
+
"types": "./dist/inference/index.d.ts",
|
|
26
|
+
"import": "./dist/inference/index.js",
|
|
27
|
+
"default": "./dist/inference/index.js"
|
|
28
|
+
},
|
|
24
29
|
"./tracking": {
|
|
25
30
|
"types": "./dist/tracking/index.d.ts",
|
|
26
31
|
"import": "./dist/tracking/index.js",
|
|
@@ -61,11 +66,6 @@
|
|
|
61
66
|
"import": "./dist/reasoning/index.js",
|
|
62
67
|
"default": "./dist/reasoning/index.js"
|
|
63
68
|
},
|
|
64
|
-
"./capabilities": {
|
|
65
|
-
"types": "./dist/capabilities/index.d.ts",
|
|
66
|
-
"import": "./dist/capabilities/index.js",
|
|
67
|
-
"default": "./dist/capabilities/index.js"
|
|
68
|
-
},
|
|
69
69
|
"./models": {
|
|
70
70
|
"types": "./dist/models/index.d.ts",
|
|
71
71
|
"import": "./dist/models/index.js",
|
|
@@ -75,6 +75,36 @@
|
|
|
75
75
|
"types": "./dist/mcp/index.d.ts",
|
|
76
76
|
"import": "./dist/mcp/index.js",
|
|
77
77
|
"default": "./dist/mcp/index.js"
|
|
78
|
+
},
|
|
79
|
+
"./host": {
|
|
80
|
+
"types": "./dist/host/index.d.ts",
|
|
81
|
+
"import": "./dist/host/index.js",
|
|
82
|
+
"default": "./dist/host/index.js"
|
|
83
|
+
},
|
|
84
|
+
"./scope": {
|
|
85
|
+
"types": "./dist/scope/index.d.ts",
|
|
86
|
+
"import": "./dist/scope/index.js",
|
|
87
|
+
"default": "./dist/scope/index.js"
|
|
88
|
+
},
|
|
89
|
+
"./signal": {
|
|
90
|
+
"types": "./dist/signal/index.d.ts",
|
|
91
|
+
"import": "./dist/signal/index.js",
|
|
92
|
+
"default": "./dist/signal/index.js"
|
|
93
|
+
},
|
|
94
|
+
"./errors": {
|
|
95
|
+
"types": "./dist/errors/index.d.ts",
|
|
96
|
+
"import": "./dist/errors/index.js",
|
|
97
|
+
"default": "./dist/errors/index.js"
|
|
98
|
+
},
|
|
99
|
+
"./presets": {
|
|
100
|
+
"types": "./dist/presets/index.d.ts",
|
|
101
|
+
"import": "./dist/presets/index.js",
|
|
102
|
+
"default": "./dist/presets/index.js"
|
|
103
|
+
},
|
|
104
|
+
"./safety": {
|
|
105
|
+
"types": "./dist/safety/index.d.ts",
|
|
106
|
+
"import": "./dist/safety/index.js",
|
|
107
|
+
"default": "./dist/safety/index.js"
|
|
78
108
|
}
|
|
79
109
|
},
|
|
80
110
|
"files": [
|
|
@@ -87,12 +117,19 @@
|
|
|
87
117
|
"zod": "^3.25.76 || ^4.1.8"
|
|
88
118
|
},
|
|
89
119
|
"peerDependencies": {
|
|
120
|
+
"@ai-sdk/amazon-bedrock": "^4.0.0",
|
|
90
121
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
122
|
+
"@ai-sdk/azure": "^3.0.0",
|
|
91
123
|
"@ai-sdk/google": "^3.0.0",
|
|
124
|
+
"@ai-sdk/google-vertex": "^4.0.0",
|
|
125
|
+
"@ai-sdk/groq": "^3.0.0",
|
|
92
126
|
"@ai-sdk/mcp": "^1.0.0",
|
|
127
|
+
"@ai-sdk/mistral": "^3.0.0",
|
|
93
128
|
"@ai-sdk/openai": "^3.0.0",
|
|
94
129
|
"@ai-sdk/openai-compatible": "^2.0.0",
|
|
130
|
+
"@ai-sdk/xai": "^3.0.0",
|
|
95
131
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
132
|
+
"@openrouter/ai-sdk-provider": "^1.0.0",
|
|
96
133
|
"@opentelemetry/api": "^1.9.0",
|
|
97
134
|
"@opentelemetry/resources": "^2.0.0",
|
|
98
135
|
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
@@ -100,9 +137,15 @@
|
|
|
100
137
|
"dockerode": "^4.0.9"
|
|
101
138
|
},
|
|
102
139
|
"peerDependenciesMeta": {
|
|
140
|
+
"@ai-sdk/amazon-bedrock": {
|
|
141
|
+
"optional": true
|
|
142
|
+
},
|
|
103
143
|
"@ai-sdk/anthropic": {
|
|
104
144
|
"optional": true
|
|
105
145
|
},
|
|
146
|
+
"@ai-sdk/azure": {
|
|
147
|
+
"optional": true
|
|
148
|
+
},
|
|
106
149
|
"@ai-sdk/openai": {
|
|
107
150
|
"optional": true
|
|
108
151
|
},
|
|
@@ -112,12 +155,27 @@
|
|
|
112
155
|
"@ai-sdk/google": {
|
|
113
156
|
"optional": true
|
|
114
157
|
},
|
|
158
|
+
"@ai-sdk/google-vertex": {
|
|
159
|
+
"optional": true
|
|
160
|
+
},
|
|
161
|
+
"@ai-sdk/groq": {
|
|
162
|
+
"optional": true
|
|
163
|
+
},
|
|
115
164
|
"@ai-sdk/mcp": {
|
|
116
165
|
"optional": true
|
|
117
166
|
},
|
|
167
|
+
"@ai-sdk/mistral": {
|
|
168
|
+
"optional": true
|
|
169
|
+
},
|
|
170
|
+
"@ai-sdk/xai": {
|
|
171
|
+
"optional": true
|
|
172
|
+
},
|
|
118
173
|
"@modelcontextprotocol/sdk": {
|
|
119
174
|
"optional": true
|
|
120
175
|
},
|
|
176
|
+
"@openrouter/ai-sdk-provider": {
|
|
177
|
+
"optional": true
|
|
178
|
+
},
|
|
121
179
|
"dockerode": {
|
|
122
180
|
"optional": true
|
|
123
181
|
},
|
|
@@ -135,14 +193,21 @@
|
|
|
135
193
|
}
|
|
136
194
|
},
|
|
137
195
|
"devDependencies": {
|
|
196
|
+
"@ai-sdk/amazon-bedrock": "^4.0.77",
|
|
138
197
|
"@ai-sdk/anthropic": "^3.0.35",
|
|
198
|
+
"@ai-sdk/azure": "^3.0.42",
|
|
139
199
|
"@ai-sdk/google": "^3.0.30",
|
|
200
|
+
"@ai-sdk/google-vertex": "^4.0.80",
|
|
201
|
+
"@ai-sdk/groq": "^3.0.29",
|
|
140
202
|
"@ai-sdk/mcp": "^1.0.19",
|
|
203
|
+
"@ai-sdk/mistral": "^3.0.24",
|
|
141
204
|
"@ai-sdk/openai": "^3.0.25",
|
|
142
205
|
"@ai-sdk/openai-compatible": "^2.0.30",
|
|
143
206
|
"@ai-sdk/provider-utils": "^4.0.15",
|
|
207
|
+
"@ai-sdk/xai": "^3.0.67",
|
|
144
208
|
"@arizeai/openinference-vercel": "^2.7.1",
|
|
145
209
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
210
|
+
"@openrouter/ai-sdk-provider": "^1.0.0",
|
|
146
211
|
"@opentelemetry/api": "^1.9.0",
|
|
147
212
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.213.0",
|
|
148
213
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
@@ -179,10 +244,11 @@
|
|
|
179
244
|
"access": "public"
|
|
180
245
|
},
|
|
181
246
|
"scripts": {
|
|
182
|
-
"build": "tsup src/index.ts src/tool/index.ts src/runtime/index.ts src/tracking/index.ts src/middleware/index.ts src/prompt/index.ts src/skill/index.ts src/sub-agent/index.ts src/storage/index.ts src/context/index.ts src/reasoning/index.ts src/
|
|
183
|
-
"dev": "tsup src/index.ts src/tool/index.ts src/runtime/index.ts src/tracking/index.ts src/middleware/index.ts src/prompt/index.ts src/skill/index.ts src/sub-agent/index.ts src/storage/index.ts src/context/index.ts src/reasoning/index.ts src/
|
|
247
|
+
"build": "tsup src/index.ts src/tool/index.ts src/runtime/index.ts src/inference/index.ts src/tracking/index.ts src/middleware/index.ts src/prompt/index.ts src/skill/index.ts src/sub-agent/index.ts src/storage/index.ts src/context/index.ts src/reasoning/index.ts src/models/index.ts src/mcp/index.ts src/host/index.ts src/scope/index.ts src/signal/index.ts src/errors/index.ts src/presets/index.ts src/safety/index.ts --format esm --dts --clean",
|
|
248
|
+
"dev": "tsup src/index.ts src/tool/index.ts src/runtime/index.ts src/inference/index.ts src/tracking/index.ts src/middleware/index.ts src/prompt/index.ts src/skill/index.ts src/sub-agent/index.ts src/storage/index.ts src/context/index.ts src/reasoning/index.ts src/models/index.ts src/mcp/index.ts src/host/index.ts src/scope/index.ts src/signal/index.ts src/errors/index.ts src/presets/index.ts src/safety/index.ts --format esm --dts --watch",
|
|
184
249
|
"test": "vitest run",
|
|
185
250
|
"test:watch": "vitest",
|
|
251
|
+
"lint": "eslint src/",
|
|
186
252
|
"typecheck": "tsc --noEmit",
|
|
187
253
|
"clean": "rm -rf dist"
|
|
188
254
|
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { C as CapabilitySource, S as SourcePriority, b as SourceResult, P as ProviderCompatibility, R as ResolverOptions, M as ModelEntry, c as ModelCapabilities } from '../resolver-DOfZ-xuk.js';
|
|
2
|
-
export { D as DEFAULT_RESOLVER_OPTIONS, I as InputModality, d as ModelCapabilityResolver, N as NetworkStatus, O as OutputModality, f as ResolutionResult, g as configureResolver, e as extractModelId, a as extractProvider, h as getDefaultResolver } from '../resolver-DOfZ-xuk.js';
|
|
3
|
-
export { g as getModelId, a as getProviderId } from '../identifiers-BLUxFqV_.js';
|
|
4
|
-
export { g as getNetworkStatus } from '../network-D76DS5ot.js';
|
|
5
|
-
import 'ai';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Pattern-Based Capability Detection for @cuylabs/agent-core
|
|
9
|
-
*
|
|
10
|
-
* Static pattern matching for model capabilities when no external data is available.
|
|
11
|
-
* This is the fallback layer - always works offline.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Infer provider from model ID
|
|
16
|
-
*/
|
|
17
|
-
declare function inferProvider(modelId: string): string | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* Pattern-based capability source
|
|
20
|
-
* Always available, uses heuristics to detect capabilities
|
|
21
|
-
*/
|
|
22
|
-
declare class PatternCapabilitySource implements CapabilitySource {
|
|
23
|
-
readonly priority = SourcePriority.PatternMatch;
|
|
24
|
-
readonly name = "Pattern Matching";
|
|
25
|
-
lookup(modelId: string, providerHint?: string): Promise<SourceResult>;
|
|
26
|
-
isAvailable(): Promise<boolean>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Quick check if a model ID likely supports reasoning
|
|
30
|
-
*/
|
|
31
|
-
declare function likelySupportsReasoning(modelId: string): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Get provider compatibility for a model
|
|
34
|
-
*/
|
|
35
|
-
declare function getProviderCompatibility(modelId: string, provider?: string): ProviderCompatibility | undefined;
|
|
36
|
-
|
|
37
|
-
type CapabilityOverrides = ResolverOptions["modelOverrides"];
|
|
38
|
-
type OverrideLookup = {
|
|
39
|
-
override?: Partial<ModelCapabilities>;
|
|
40
|
-
matchedKey?: string;
|
|
41
|
-
};
|
|
42
|
-
declare function findCapabilityOverride(overrides: CapabilityOverrides, modelId: string, provider?: string): OverrideLookup;
|
|
43
|
-
declare function applyCapabilityOverride(entry: ModelEntry, override?: Partial<ModelCapabilities>): ModelEntry;
|
|
44
|
-
|
|
45
|
-
declare class CapabilityCache {
|
|
46
|
-
private adapter;
|
|
47
|
-
private memoryCache;
|
|
48
|
-
private ttlMs;
|
|
49
|
-
private loaded;
|
|
50
|
-
constructor(options?: Partial<ResolverOptions>);
|
|
51
|
-
private load;
|
|
52
|
-
get(modelId: string, provider?: string): Promise<ModelEntry | undefined>;
|
|
53
|
-
set(entry: ModelEntry): Promise<void>;
|
|
54
|
-
setMany(entries: ModelEntry[]): Promise<void>;
|
|
55
|
-
persist(): Promise<void>;
|
|
56
|
-
clear(): Promise<void>;
|
|
57
|
-
stats(): {
|
|
58
|
-
size: number;
|
|
59
|
-
loaded: boolean;
|
|
60
|
-
};
|
|
61
|
-
getAll(): Promise<ModelEntry[]>;
|
|
62
|
-
getAllByProvider(): Promise<Record<string, ModelEntry[]>>;
|
|
63
|
-
}
|
|
64
|
-
declare class CacheCapabilitySource implements CapabilitySource {
|
|
65
|
-
private cache;
|
|
66
|
-
readonly priority = SourcePriority.LocalCache;
|
|
67
|
-
readonly name = "Local Cache";
|
|
68
|
-
constructor(cache: CapabilityCache);
|
|
69
|
-
lookup(modelId: string, provider?: string): Promise<SourceResult>;
|
|
70
|
-
isAvailable(): Promise<boolean>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
declare class RemoteCapabilityFetcher {
|
|
74
|
-
private apiUrl;
|
|
75
|
-
private timeoutMs;
|
|
76
|
-
private cache;
|
|
77
|
-
private lastFetchTime;
|
|
78
|
-
private minFetchInterval;
|
|
79
|
-
constructor(cache: CapabilityCache, options?: Partial<ResolverOptions>);
|
|
80
|
-
fetchAll(): Promise<ModelEntry[]>;
|
|
81
|
-
ping(): Promise<boolean>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
declare class RemoteCapabilitySource implements CapabilitySource {
|
|
85
|
-
readonly priority = SourcePriority.RemoteAPI;
|
|
86
|
-
readonly name = "Remote API (models.dev)";
|
|
87
|
-
private fetcher;
|
|
88
|
-
private cache;
|
|
89
|
-
private fetchPromise;
|
|
90
|
-
private enabled;
|
|
91
|
-
constructor(cache: CapabilityCache, options?: Partial<ResolverOptions>);
|
|
92
|
-
lookup(modelId: string, provider?: string): Promise<SourceResult>;
|
|
93
|
-
isAvailable(): Promise<boolean>;
|
|
94
|
-
refresh(): Promise<void>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export { CacheCapabilitySource, CapabilityCache, type CapabilityOverrides, CapabilitySource, ModelCapabilities, ModelEntry, PatternCapabilitySource, ProviderCompatibility, RemoteCapabilityFetcher, RemoteCapabilitySource, ResolverOptions, SourcePriority, SourceResult, applyCapabilityOverride, findCapabilityOverride, getProviderCompatibility, inferProvider, likelySupportsReasoning };
|