@cuylabs/agent-core 0.7.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/dist/{builder-BRvqCcIk.d.ts → builder-UpOWQMW3.d.ts} +2 -2
- package/dist/{chunk-3HNO5SVI.js → chunk-4BDA7DQY.js} +3 -3
- package/dist/chunk-BFM2YHNM.js +222 -0
- package/dist/chunk-CAA7FHIH.js +280 -0
- package/dist/chunk-DWYX7ASF.js +26 -0
- package/dist/chunk-KUVSERLJ.js +50 -0
- package/dist/{chunk-5K7AQVOU.js → chunk-N6HWIEEA.js} +8 -204
- package/dist/{chunk-QGOGIP7T.js → chunk-RFEKJKTO.js} +131 -25
- package/dist/chunk-RZITT45F.js +202 -0
- package/dist/{chunk-ZPMACVZK.js → chunk-SQU2AJHO.js} +1 -1
- package/dist/{chunk-BNSHUWCV.js → chunk-WWYYNWEW.js} +1 -1
- package/dist/{chunk-CDTV2UYU.js → chunk-YSLSEQ6B.js} +52 -252
- 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/{index-C33hlD6H.d.ts → index-CWSchSql.d.ts} +36 -50
- package/dist/index.d.ts +36 -109
- package/dist/index.js +213 -396
- package/dist/inference/index.d.ts +10 -7
- package/dist/inference/index.js +7 -5
- package/dist/llm-error-D93FNNLY.d.ts +32 -0
- package/dist/middleware/index.d.ts +245 -7
- package/dist/middleware/index.js +3 -1
- package/dist/models/index.d.ts +125 -4
- package/dist/models/index.js +7 -3
- package/dist/presets/index.d.ts +53 -0
- package/dist/presets/index.js +28 -0
- package/dist/prompt/index.d.ts +10 -8
- package/dist/reasoning/index.d.ts +1 -2
- package/dist/reasoning/index.js +3 -7
- package/dist/{registry-BDLIHOQB.d.ts → registry-DwYqsQkX.d.ts} +1 -1
- package/dist/{runner-DSKaEz3z.d.ts → runner-e2YRcUoX.d.ts} +58 -151
- package/dist/runtime/index.d.ts +11 -8
- package/dist/runtime/index.js +9 -7
- package/dist/safety/index.d.ts +38 -0
- package/dist/safety/index.js +12 -0
- package/dist/scope/index.d.ts +2 -2
- package/dist/signal/index.d.ts +28 -0
- package/dist/signal/index.js +6 -0
- package/dist/skill/index.d.ts +7 -6
- package/dist/sub-agent/index.d.ts +14 -9
- package/dist/tool/index.d.ts +7 -5
- package/dist/tool/index.js +2 -2
- package/dist/tool-BHbyUAy3.d.ts +150 -0
- package/dist/{tool-HUtkiVBx.d.ts → tool-DLXAR9Ce.d.ts} +1 -1
- package/dist/tracking/index.d.ts +2 -2
- package/dist/{tool-Db1Ue-1U.d.ts → types-BfNpU8NS.d.ts} +1 -150
- package/dist/types-BnpEOYV-.d.ts +50 -0
- package/dist/{types-9jGQUjqW.d.ts → types-CQL-SvTn.d.ts} +1 -1
- package/dist/types-CWm-7rvB.d.ts +55 -0
- package/dist/{types-FRpzzg_9.d.ts → types-KKDrdU9Y.d.ts} +5 -35
- package/dist/{capability-resolver-CgRGsWVX.d.ts → types-QA4WhEfz.d.ts} +1 -117
- package/dist/{types-CqDZTh4d.d.ts → types-QKHHQLLq.d.ts} +5 -4
- package/dist/types-YuWV4ag7.d.ts +72 -0
- package/package.json +58 -3
- package/dist/index-CfBGYrpd.d.ts +0 -317
- package/dist/{chunk-IEFIQENH.js → chunk-7VKQ4WPB.js} +4 -4
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { T as ToolMetadata, a as ToolReplayPolicy, b as ToolContext, F as FileOperationMeta, c as ToolResult } from './tool-HUtkiVBx.js';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Skill System Types
|
|
6
3
|
*
|
|
@@ -270,150 +267,4 @@ interface SkillDiscoveryError {
|
|
|
270
267
|
reason: string;
|
|
271
268
|
}
|
|
272
269
|
|
|
273
|
-
|
|
274
|
-
* Tool definition namespace for @cuylabs/agent-core
|
|
275
|
-
*
|
|
276
|
-
* Provides consistent tool creation via Tool.define.
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* A schema type compatible with both Zod 3 and Zod 4.
|
|
281
|
-
*
|
|
282
|
-
* Uses structural typing so that schemas from either Zod version satisfy
|
|
283
|
-
* the constraint. This avoids the problem where Zod 3's `ZodType` class
|
|
284
|
-
* and Zod 4's `ZodType` class have incompatible internal shapes, causing
|
|
285
|
-
* type errors when a library compiled against one version is consumed with
|
|
286
|
-
* the other.
|
|
287
|
-
*
|
|
288
|
-
* Both Zod 3 and Zod 4 (classic API) schemas have `parse()` and `_output`.
|
|
289
|
-
*/
|
|
290
|
-
interface CompatibleSchema<T = any> {
|
|
291
|
-
/** Parse and validate input data. Present in both Zod 3 and Zod 4. */
|
|
292
|
-
parse(data: unknown): T;
|
|
293
|
-
/**
|
|
294
|
-
* Type-level output marker used by both Zod versions:
|
|
295
|
-
* - Zod 3: `readonly _output!: T` (definite assignment assertion)
|
|
296
|
-
* - Zod 4 classic: `get _output(): T` (getter)
|
|
297
|
-
*/
|
|
298
|
-
readonly _output: T;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Infer the output type from a compatible schema.
|
|
302
|
-
* Equivalent to `z.infer<T>` but works with both Zod 3 and Zod 4 schemas.
|
|
303
|
-
*/
|
|
304
|
-
type InferSchemaOutput<T extends CompatibleSchema> = T["_output"];
|
|
305
|
-
/**
|
|
306
|
-
* Tool namespace - tool definition utilities
|
|
307
|
-
*/
|
|
308
|
-
declare namespace Tool {
|
|
309
|
-
/**
|
|
310
|
-
* Tool info interface - the shape of a defined tool
|
|
311
|
-
*/
|
|
312
|
-
interface Info<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
|
|
313
|
-
/** Unique tool identifier */
|
|
314
|
-
id: string;
|
|
315
|
-
/** Recovery semantics for resume-capable runtimes. */
|
|
316
|
-
replayPolicy?: ToolReplayPolicy;
|
|
317
|
-
/** Initialize the tool (can be async for dynamic descriptions) */
|
|
318
|
-
init: (ctx?: InitContext) => Promise<InitResult<TParams, TMeta>> | InitResult<TParams, TMeta>;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Any tool info - for use in arrays and collections where generic types vary
|
|
322
|
-
*/
|
|
323
|
-
type AnyInfo = Info<any, any>;
|
|
324
|
-
/**
|
|
325
|
-
* Context passed during tool initialization
|
|
326
|
-
*/
|
|
327
|
-
interface InitContext {
|
|
328
|
-
/** Working directory */
|
|
329
|
-
cwd?: string;
|
|
330
|
-
/** Agent name (if known) */
|
|
331
|
-
agent?: string;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Result of tool initialization
|
|
335
|
-
*/
|
|
336
|
-
interface InitResult<TParams extends CompatibleSchema = any, TMeta extends ToolMetadata = ToolMetadata> {
|
|
337
|
-
/** Tool description for the LLM */
|
|
338
|
-
description: string;
|
|
339
|
-
/** Zod schema for parameters */
|
|
340
|
-
parameters: TParams;
|
|
341
|
-
/** Execute the tool */
|
|
342
|
-
execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
|
|
343
|
-
/** Optional custom validation error formatter */
|
|
344
|
-
formatValidationError?: (error: z.ZodError) => string;
|
|
345
|
-
/**
|
|
346
|
-
* File operation metadata for automatic turn tracking.
|
|
347
|
-
* When set, the agent will automatically capture file baselines
|
|
348
|
-
* before tool execution for undo/diff capabilities.
|
|
349
|
-
*
|
|
350
|
-
* @example
|
|
351
|
-
* ```typescript
|
|
352
|
-
* // For a write tool
|
|
353
|
-
* fileOps: {
|
|
354
|
-
* pathArgs: ['path'],
|
|
355
|
-
* operationType: 'write'
|
|
356
|
-
* }
|
|
357
|
-
* ```
|
|
358
|
-
*/
|
|
359
|
-
fileOps?: FileOperationMeta;
|
|
360
|
-
/** Optional replay metadata for resume-capable runtimes. */
|
|
361
|
-
replayPolicy?: ToolReplayPolicy;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Result of tool execution
|
|
365
|
-
*/
|
|
366
|
-
interface ExecuteResult<TMeta extends ToolMetadata = ToolMetadata> {
|
|
367
|
-
/** Short title for display */
|
|
368
|
-
title: string;
|
|
369
|
-
/** Main output text */
|
|
370
|
-
output: string;
|
|
371
|
-
/** Metadata */
|
|
372
|
-
metadata: TMeta;
|
|
373
|
-
}
|
|
374
|
-
interface DefineOptions {
|
|
375
|
-
/** Static replay metadata exposed to higher-level runtimes. */
|
|
376
|
-
replayPolicy?: ToolReplayPolicy;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Define a tool with standard patterns
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
* ```typescript
|
|
383
|
-
* const myTool = Tool.define("my_tool", {
|
|
384
|
-
* description: "Does something useful",
|
|
385
|
-
* parameters: z.object({
|
|
386
|
-
* input: z.string().describe("The input to process"),
|
|
387
|
-
* }),
|
|
388
|
-
* execute: async (params, ctx) => ({
|
|
389
|
-
* title: "Processed",
|
|
390
|
-
* output: `Result: ${params.input}`,
|
|
391
|
-
* metadata: {},
|
|
392
|
-
* }),
|
|
393
|
-
* });
|
|
394
|
-
* ```
|
|
395
|
-
*/
|
|
396
|
-
function define<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, init: Info<TParams, TMeta>["init"] | Awaited<ReturnType<Info<TParams, TMeta>["init"]>>, options?: DefineOptions): Info<TParams, TMeta>;
|
|
397
|
-
/**
|
|
398
|
-
* Simple define for static tools (no async init)
|
|
399
|
-
*/
|
|
400
|
-
function defineSimple<TParams extends CompatibleSchema, TMeta extends ToolMetadata = ToolMetadata>(id: string, config: {
|
|
401
|
-
description: string;
|
|
402
|
-
parameters: TParams;
|
|
403
|
-
execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ExecuteResult<TMeta>>;
|
|
404
|
-
replayPolicy?: ToolReplayPolicy;
|
|
405
|
-
}): Info<TParams, TMeta>;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Legacy helper - wraps to Tool.Info format
|
|
409
|
-
*
|
|
410
|
-
* @deprecated Use Tool.define instead
|
|
411
|
-
*/
|
|
412
|
-
declare function defineTool<TParams extends CompatibleSchema>(definition: {
|
|
413
|
-
id: string;
|
|
414
|
-
description: string;
|
|
415
|
-
parameters: TParams;
|
|
416
|
-
execute: (params: InferSchemaOutput<TParams>, ctx: ToolContext) => Promise<ToolResult>;
|
|
417
|
-
}): Tool.Info<TParams>;
|
|
418
|
-
|
|
419
|
-
export { type CompatibleSchema as C, type InferSchemaOutput as I, type RemoteSkillEntry as R, type SkillDiscoveryResult as S, Tool as T, type SkillMetadata as a, type SkillContent as b, type SkillResource as c, type SkillConfig as d, type RemoteSkillIndex as e, type SkillDiscoveryError as f, type SkillResourceType as g, type SkillScope as h, type SkillSource as i, type SkillSourceType as j, defineTool as k };
|
|
270
|
+
export type { RemoteSkillEntry as R, SkillDiscoveryResult as S, SkillMetadata as a, SkillContent as b, SkillResource as c, SkillConfig as d, RemoteSkillIndex as e, SkillDiscoveryError as f, SkillResourceType as g, SkillScope as h, SkillSource as i, SkillSourceType as j };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { LanguageModel } from 'ai';
|
|
2
|
+
import { R as ReasoningLevel } from './types-CQaXbRsS.js';
|
|
3
|
+
import { T as Tool } from './tool-BHbyUAy3.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Agent preset - a reusable configuration profile.
|
|
7
|
+
*/
|
|
8
|
+
interface Preset {
|
|
9
|
+
/** Unique identifier for this preset */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Human-readable description */
|
|
12
|
+
description: string;
|
|
13
|
+
/**
|
|
14
|
+
* Tool allow patterns (glob-like).
|
|
15
|
+
* If provided, only tools matching these patterns are candidates.
|
|
16
|
+
*/
|
|
17
|
+
allowTools?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Tool deny patterns (glob-like).
|
|
20
|
+
* Deny patterns apply only after allow matching, so explicit allows win.
|
|
21
|
+
*/
|
|
22
|
+
denyTools?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Override system prompt.
|
|
25
|
+
* Use `{basePrompt}` to include the parent's system prompt.
|
|
26
|
+
*/
|
|
27
|
+
systemPrompt?: string;
|
|
28
|
+
/** Override temperature (0-1). */
|
|
29
|
+
temperature?: number;
|
|
30
|
+
/** Override max steps. */
|
|
31
|
+
maxSteps?: number;
|
|
32
|
+
/** Override reasoning level. */
|
|
33
|
+
reasoningLevel?: ReasoningLevel;
|
|
34
|
+
/** Override model. */
|
|
35
|
+
model?: LanguageModel;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result of applying a preset - ready for `fork()`.
|
|
39
|
+
*/
|
|
40
|
+
interface AppliedPreset {
|
|
41
|
+
name: string;
|
|
42
|
+
systemPrompt?: string;
|
|
43
|
+
tools?: Tool.AnyInfo[];
|
|
44
|
+
temperature?: number;
|
|
45
|
+
maxSteps?: number;
|
|
46
|
+
reasoningLevel?: ReasoningLevel;
|
|
47
|
+
model?: LanguageModel;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { AppliedPreset as A, Preset as P };
|
|
@@ -26,4 +26,4 @@ interface ScopeOptions {
|
|
|
26
26
|
attributes?: ScopeAttributes;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export type {
|
|
29
|
+
export type { ScopeSnapshot as S, Scope as a, ScopeAttributeValue as b, ScopeAttributes as c, ScopeKind as d, ScopeOptions as e };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk level for operations.
|
|
3
|
+
*/
|
|
4
|
+
type RiskLevel = "safe" | "moderate" | "dangerous";
|
|
5
|
+
/**
|
|
6
|
+
* User response to an approval request.
|
|
7
|
+
*/
|
|
8
|
+
type ApprovalAction = "allow" | "deny" | "remember";
|
|
9
|
+
/**
|
|
10
|
+
* Approval request sent to the UI/handler.
|
|
11
|
+
*/
|
|
12
|
+
interface ApprovalRequest {
|
|
13
|
+
/** Unique request ID */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Session ID */
|
|
16
|
+
sessionId: string;
|
|
17
|
+
/** Tool name */
|
|
18
|
+
tool: string;
|
|
19
|
+
/** Tool arguments */
|
|
20
|
+
args: unknown;
|
|
21
|
+
/** Human-readable description */
|
|
22
|
+
description: string;
|
|
23
|
+
/** Risk level */
|
|
24
|
+
risk: RiskLevel;
|
|
25
|
+
/** Patterns that would be remembered if "remember" is chosen */
|
|
26
|
+
patterns: string[];
|
|
27
|
+
/** Timestamp */
|
|
28
|
+
timestamp: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Rule for auto-approving/denying operations.
|
|
32
|
+
*/
|
|
33
|
+
interface ApprovalRule {
|
|
34
|
+
/** Pattern to match (glob-style) */
|
|
35
|
+
pattern: string;
|
|
36
|
+
/** Tool to match (`*` for all) */
|
|
37
|
+
tool: string;
|
|
38
|
+
/** Action to take */
|
|
39
|
+
action: "allow" | "deny";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configuration for the approval handler.
|
|
43
|
+
*/
|
|
44
|
+
interface ApprovalConfig {
|
|
45
|
+
/** Default action when no rule matches (default: "ask") */
|
|
46
|
+
defaultAction?: "allow" | "deny" | "ask";
|
|
47
|
+
/** Pre-configured rules */
|
|
48
|
+
rules?: ApprovalRule[];
|
|
49
|
+
/** Handler for approval requests */
|
|
50
|
+
onRequest?: (request: ApprovalRequest) => Promise<ApprovalAction>;
|
|
51
|
+
/** Timeout for approval requests in ms (default: 5 minutes) */
|
|
52
|
+
timeout?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type { ApprovalAction as A, RiskLevel as R, ApprovalConfig as a, ApprovalRequest as b, ApprovalRule as c };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { StreamTextResult, ToolSet, Output, LanguageModel, ModelMessage, TelemetrySettings } from 'ai';
|
|
2
|
-
import { T as Tool } from './tool-
|
|
2
|
+
import { T as Tool } from './tool-BHbyUAy3.js';
|
|
3
3
|
import { T as ToolHost } from './types-CHiPh8U2.js';
|
|
4
|
-
import { S as StreamChunk, d as StreamProvider, M as MiddlewareRunner, e as ModelCallInput } from './runner-
|
|
4
|
+
import { S as StreamChunk, d as StreamProvider, M as MiddlewareRunner, e as ModelCallInput } from './runner-e2YRcUoX.js';
|
|
5
5
|
import { R as ReasoningLevel } from './types-CQaXbRsS.js';
|
|
6
|
-
import { d as TurnTrackerContext } from './tool-
|
|
6
|
+
import { d as TurnTrackerContext } from './tool-DLXAR9Ce.js';
|
|
7
|
+
import { L as LLMError } from './llm-error-D93FNNLY.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Intervention Controller for @cuylabs/agent-core
|
|
@@ -128,37 +129,6 @@ declare class InterventionController {
|
|
|
128
129
|
resetCallbacks(): void;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
type ErrorCategory = "rate_limit" | "overloaded" | "auth" | "invalid_request" | "context_overflow" | "content_filter" | "network" | "timeout" | "cancelled" | "unknown";
|
|
132
|
-
interface ResponseHeaders {
|
|
133
|
-
"retry-after"?: string;
|
|
134
|
-
"retry-after-ms"?: string;
|
|
135
|
-
"x-ratelimit-remaining"?: string;
|
|
136
|
-
"x-ratelimit-reset"?: string;
|
|
137
|
-
[key: string]: string | undefined;
|
|
138
|
-
}
|
|
139
|
-
interface LLMErrorOptions {
|
|
140
|
-
message: string;
|
|
141
|
-
category?: ErrorCategory;
|
|
142
|
-
status?: number;
|
|
143
|
-
headers?: ResponseHeaders;
|
|
144
|
-
cause?: Error;
|
|
145
|
-
provider?: string;
|
|
146
|
-
model?: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
declare class LLMError extends Error {
|
|
150
|
-
readonly category: ErrorCategory;
|
|
151
|
-
readonly status?: number;
|
|
152
|
-
readonly headers?: ResponseHeaders;
|
|
153
|
-
readonly provider?: string;
|
|
154
|
-
readonly model?: string;
|
|
155
|
-
readonly isRetryable: boolean;
|
|
156
|
-
readonly retryDelayMs?: number;
|
|
157
|
-
constructor(options: LLMErrorOptions);
|
|
158
|
-
static from(error: unknown, context?: Partial<LLMErrorOptions>): LLMError;
|
|
159
|
-
get description(): string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
132
|
/**
|
|
163
133
|
* Retry logic with exponential backoff for @cuylabs/agent-core
|
|
164
134
|
*
|
|
@@ -352,4 +322,4 @@ type LLMStreamInput = InferenceStreamInput;
|
|
|
352
322
|
*/
|
|
353
323
|
type StepInfo = InferenceStepInfo;
|
|
354
324
|
|
|
355
|
-
export { type AnyInferenceResult as A, type CustomStreamProvider as C, DEFAULT_MAX_OUTPUT_TOKENS as D, type
|
|
325
|
+
export { type AnyInferenceResult as A, type CustomStreamProvider as C, DEFAULT_MAX_OUTPUT_TOKENS as D, type InferenceStreamInput as I, type LLMStreamInput as L, OUTPUT_TOKEN_MAX as O, type PendingIntervention as P, type RetryConfig as R, type StepInfo as S, type ToolExecutionMode as T, type AnyStreamResult as a, type CustomStreamResult as b, type InferenceCustomResult as c, type InferenceStepInfo as d, type InferenceStreamResult as e, type LLMStreamResult as f, InterventionController as g, DEFAULT_RETRY_CONFIG as h, type OnInterventionApplied as i, type RetryHandlerOptions as j, type RetryState as k, calculateDelay as l, createRetryHandler as m, createRetryState as n, sleep as o, shouldRetry as s, withRetry as w };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LanguageModel } from 'ai';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Model Capability Types for @cuylabs/agent-core
|
|
5
3
|
*
|
|
@@ -137,118 +135,4 @@ interface ResolverOptions {
|
|
|
137
135
|
*/
|
|
138
136
|
declare const DEFAULT_RESOLVER_OPTIONS: Required<ResolverOptions>;
|
|
139
137
|
|
|
140
|
-
|
|
141
|
-
online: boolean;
|
|
142
|
-
lastSuccess?: number;
|
|
143
|
-
lastError?: string;
|
|
144
|
-
failureCount: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Model Capability Resolver for @cuylabs/agent-core
|
|
149
|
-
*
|
|
150
|
-
* Main orchestrator that combines multiple capability sources:
|
|
151
|
-
* 1. User overrides (highest priority)
|
|
152
|
-
* 2. Local cache (fast, persisted)
|
|
153
|
-
* 3. Pattern matching (always available)
|
|
154
|
-
* 4. Remote API (optional, network-dependent)
|
|
155
|
-
*
|
|
156
|
-
* Designed for the Vercel AI SDK v6 ecosystem.
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Extract model ID from LanguageModel
|
|
161
|
-
*/
|
|
162
|
-
declare function extractModelId(model: LanguageModel): string;
|
|
163
|
-
/**
|
|
164
|
-
* Extract provider from LanguageModel
|
|
165
|
-
*/
|
|
166
|
-
declare function extractProvider(model: LanguageModel): string | undefined;
|
|
167
|
-
/**
|
|
168
|
-
* Resolution result with source information
|
|
169
|
-
*/
|
|
170
|
-
interface ResolutionResult {
|
|
171
|
-
/** The resolved model entry */
|
|
172
|
-
entry: ModelEntry;
|
|
173
|
-
/** Which source provided the primary result */
|
|
174
|
-
source: SourcePriority;
|
|
175
|
-
/** Whether this is a confident match */
|
|
176
|
-
confident: boolean;
|
|
177
|
-
/** Resolution timing in ms */
|
|
178
|
-
resolveTimeMs: number;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Model Capability Resolver
|
|
182
|
-
*
|
|
183
|
-
* Provides a unified API for querying model capabilities with
|
|
184
|
-
* automatic fallback through multiple sources.
|
|
185
|
-
*/
|
|
186
|
-
declare class ModelCapabilityResolver {
|
|
187
|
-
private options;
|
|
188
|
-
private cache;
|
|
189
|
-
private sources;
|
|
190
|
-
private initialized;
|
|
191
|
-
private initPromise;
|
|
192
|
-
constructor(options?: Partial<ResolverOptions>);
|
|
193
|
-
/**
|
|
194
|
-
* Initialize the resolver (load cache, optionally fetch remote)
|
|
195
|
-
*/
|
|
196
|
-
initialize(): Promise<void>;
|
|
197
|
-
/**
|
|
198
|
-
* Resolve capabilities for a model
|
|
199
|
-
*/
|
|
200
|
-
resolve(model: LanguageModel): Promise<ResolutionResult>;
|
|
201
|
-
/**
|
|
202
|
-
* Quick check if a model supports reasoning
|
|
203
|
-
* Uses cache/patterns only for speed
|
|
204
|
-
*/
|
|
205
|
-
supportsReasoning(model: LanguageModel): Promise<boolean>;
|
|
206
|
-
/**
|
|
207
|
-
* Get capabilities for a model
|
|
208
|
-
*/
|
|
209
|
-
getCapabilities(model: LanguageModel): Promise<ModelCapabilities>;
|
|
210
|
-
/**
|
|
211
|
-
* Get provider compatibility settings
|
|
212
|
-
*/
|
|
213
|
-
getCompatibility(model: LanguageModel): Promise<ProviderCompatibility | undefined>;
|
|
214
|
-
/**
|
|
215
|
-
* Force refresh from remote API
|
|
216
|
-
*/
|
|
217
|
-
refreshRemote(): Promise<void>;
|
|
218
|
-
/**
|
|
219
|
-
* Get current network status
|
|
220
|
-
*/
|
|
221
|
-
getNetworkStatus(): NetworkStatus;
|
|
222
|
-
/**
|
|
223
|
-
* Get resolver statistics
|
|
224
|
-
*/
|
|
225
|
-
getStats(): {
|
|
226
|
-
cacheSize: number;
|
|
227
|
-
cacheLoaded: boolean;
|
|
228
|
-
remoteFetchEnabled: boolean;
|
|
229
|
-
networkOnline: boolean;
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Clear all cached data
|
|
233
|
-
*/
|
|
234
|
-
clearCache(): Promise<void>;
|
|
235
|
-
/**
|
|
236
|
-
* List all available models
|
|
237
|
-
* Fetches from remote if cache is empty and remote is enabled
|
|
238
|
-
*/
|
|
239
|
-
listModels(): Promise<ModelEntry[]>;
|
|
240
|
-
/**
|
|
241
|
-
* List all available models grouped by provider
|
|
242
|
-
*/
|
|
243
|
-
listModelsByProvider(): Promise<Record<string, ModelEntry[]>>;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Get the default resolver instance
|
|
247
|
-
*/
|
|
248
|
-
declare function getDefaultResolver(): ModelCapabilityResolver;
|
|
249
|
-
/**
|
|
250
|
-
* Configure the default resolver with custom options
|
|
251
|
-
*/
|
|
252
|
-
declare function configureResolver(options: Partial<ResolverOptions>): void;
|
|
253
|
-
|
|
254
|
-
export { type CapabilitySource as C, DEFAULT_RESOLVER_OPTIONS as D, type InputModality as I, type ModelCapabilities as M, type NetworkStatus as N, type OutputModality as O, type ProviderCompatibility as P, type ResolutionResult as R, SourcePriority as S, ModelCapabilityResolver as a, type ModelEntry as b, type ResolverOptions as c, type SourceResult as d, configureResolver as e, extractModelId as f, extractProvider as g, getDefaultResolver as h };
|
|
138
|
+
export { type CapabilitySource as C, DEFAULT_RESOLVER_OPTIONS as D, type InputModality as I, type ModelCapabilities as M, type OutputModality as O, type ProviderCompatibility as P, type ResolverOptions as R, SourcePriority as S, type ModelEntry as a, type SourceResult as b };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { LanguageModel, TelemetrySettings, ModelMessage, ToolSet } from 'ai';
|
|
2
|
-
import { T as Tool } from './tool-
|
|
2
|
+
import { T as Tool } from './tool-BHbyUAy3.js';
|
|
3
3
|
import { T as ToolHost } from './types-CHiPh8U2.js';
|
|
4
|
-
import {
|
|
5
|
-
import { g as InterventionController, T as ToolExecutionMode, I as InferenceStreamInput } from './types-
|
|
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
6
|
import { R as ReasoningLevel } from './types-CQaXbRsS.js';
|
|
7
|
-
import { N as NormalizedToolReplayPolicy, d as TurnTrackerContext } from './tool-
|
|
7
|
+
import { N as NormalizedToolReplayPolicy, d as TurnTrackerContext } from './tool-DLXAR9Ce.js';
|
|
8
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';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Doom-loop handling contracts for repeated tool invocations.
|
|
@@ -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",
|
|
@@ -85,6 +85,26 @@
|
|
|
85
85
|
"types": "./dist/scope/index.d.ts",
|
|
86
86
|
"import": "./dist/scope/index.js",
|
|
87
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"
|
|
88
108
|
}
|
|
89
109
|
},
|
|
90
110
|
"files": [
|
|
@@ -97,12 +117,19 @@
|
|
|
97
117
|
"zod": "^3.25.76 || ^4.1.8"
|
|
98
118
|
},
|
|
99
119
|
"peerDependencies": {
|
|
120
|
+
"@ai-sdk/amazon-bedrock": "^4.0.0",
|
|
100
121
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
122
|
+
"@ai-sdk/azure": "^3.0.0",
|
|
101
123
|
"@ai-sdk/google": "^3.0.0",
|
|
124
|
+
"@ai-sdk/google-vertex": "^4.0.0",
|
|
125
|
+
"@ai-sdk/groq": "^3.0.0",
|
|
102
126
|
"@ai-sdk/mcp": "^1.0.0",
|
|
127
|
+
"@ai-sdk/mistral": "^3.0.0",
|
|
103
128
|
"@ai-sdk/openai": "^3.0.0",
|
|
104
129
|
"@ai-sdk/openai-compatible": "^2.0.0",
|
|
130
|
+
"@ai-sdk/xai": "^3.0.0",
|
|
105
131
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
132
|
+
"@openrouter/ai-sdk-provider": "^1.0.0",
|
|
106
133
|
"@opentelemetry/api": "^1.9.0",
|
|
107
134
|
"@opentelemetry/resources": "^2.0.0",
|
|
108
135
|
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
@@ -110,9 +137,15 @@
|
|
|
110
137
|
"dockerode": "^4.0.9"
|
|
111
138
|
},
|
|
112
139
|
"peerDependenciesMeta": {
|
|
140
|
+
"@ai-sdk/amazon-bedrock": {
|
|
141
|
+
"optional": true
|
|
142
|
+
},
|
|
113
143
|
"@ai-sdk/anthropic": {
|
|
114
144
|
"optional": true
|
|
115
145
|
},
|
|
146
|
+
"@ai-sdk/azure": {
|
|
147
|
+
"optional": true
|
|
148
|
+
},
|
|
116
149
|
"@ai-sdk/openai": {
|
|
117
150
|
"optional": true
|
|
118
151
|
},
|
|
@@ -122,12 +155,27 @@
|
|
|
122
155
|
"@ai-sdk/google": {
|
|
123
156
|
"optional": true
|
|
124
157
|
},
|
|
158
|
+
"@ai-sdk/google-vertex": {
|
|
159
|
+
"optional": true
|
|
160
|
+
},
|
|
161
|
+
"@ai-sdk/groq": {
|
|
162
|
+
"optional": true
|
|
163
|
+
},
|
|
125
164
|
"@ai-sdk/mcp": {
|
|
126
165
|
"optional": true
|
|
127
166
|
},
|
|
167
|
+
"@ai-sdk/mistral": {
|
|
168
|
+
"optional": true
|
|
169
|
+
},
|
|
170
|
+
"@ai-sdk/xai": {
|
|
171
|
+
"optional": true
|
|
172
|
+
},
|
|
128
173
|
"@modelcontextprotocol/sdk": {
|
|
129
174
|
"optional": true
|
|
130
175
|
},
|
|
176
|
+
"@openrouter/ai-sdk-provider": {
|
|
177
|
+
"optional": true
|
|
178
|
+
},
|
|
131
179
|
"dockerode": {
|
|
132
180
|
"optional": true
|
|
133
181
|
},
|
|
@@ -145,14 +193,21 @@
|
|
|
145
193
|
}
|
|
146
194
|
},
|
|
147
195
|
"devDependencies": {
|
|
196
|
+
"@ai-sdk/amazon-bedrock": "^4.0.77",
|
|
148
197
|
"@ai-sdk/anthropic": "^3.0.35",
|
|
198
|
+
"@ai-sdk/azure": "^3.0.42",
|
|
149
199
|
"@ai-sdk/google": "^3.0.30",
|
|
200
|
+
"@ai-sdk/google-vertex": "^4.0.80",
|
|
201
|
+
"@ai-sdk/groq": "^3.0.29",
|
|
150
202
|
"@ai-sdk/mcp": "^1.0.19",
|
|
203
|
+
"@ai-sdk/mistral": "^3.0.24",
|
|
151
204
|
"@ai-sdk/openai": "^3.0.25",
|
|
152
205
|
"@ai-sdk/openai-compatible": "^2.0.30",
|
|
153
206
|
"@ai-sdk/provider-utils": "^4.0.15",
|
|
207
|
+
"@ai-sdk/xai": "^3.0.67",
|
|
154
208
|
"@arizeai/openinference-vercel": "^2.7.1",
|
|
155
209
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
210
|
+
"@openrouter/ai-sdk-provider": "^1.0.0",
|
|
156
211
|
"@opentelemetry/api": "^1.9.0",
|
|
157
212
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.213.0",
|
|
158
213
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
@@ -189,8 +244,8 @@
|
|
|
189
244
|
"access": "public"
|
|
190
245
|
},
|
|
191
246
|
"scripts": {
|
|
192
|
-
"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 --format esm --dts --clean",
|
|
193
|
-
"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 --format esm --dts --watch",
|
|
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",
|
|
194
249
|
"test": "vitest run",
|
|
195
250
|
"test:watch": "vitest",
|
|
196
251
|
"lint": "eslint src/",
|