@cuylabs/agent-core 0.9.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 (116) 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-EKR6PKXU.js → chunk-6HZBHFOL.js} +3 -3
  7. package/dist/chunk-CJI7PVS2.js +58 -0
  8. package/dist/{chunk-WKHDSSXG.js → chunk-CMYN2RCB.js} +146 -46
  9. package/dist/chunk-FII65CN7.js +117 -0
  10. package/dist/{chunk-UHCJEM2E.js → chunk-ICZ66572.js} +13 -6
  11. package/dist/chunk-KYLPMBHD.js +316 -0
  12. package/dist/chunk-MXAP4UG6.js +2956 -0
  13. package/dist/{chunk-4QFNWPIF.js → chunk-N3VX7FEE.js} +35 -2
  14. package/dist/{chunk-MAZ5DY5B.js → chunk-NDZWXCBZ.js} +213 -78
  15. package/dist/{chunk-MHKK374K.js → chunk-Q742PSH3.js} +11 -27
  16. package/dist/{chunk-WGZAPU6N.js → chunk-QAL3OMI3.js} +15 -1
  17. package/dist/{chunk-UDCZ673N.js → chunk-RN6WZEUF.js} +27 -23
  18. package/dist/{chunk-ZXAKHMWH.js → chunk-ROTGCYDW.js} +22 -84
  19. package/dist/chunk-SPBFQXOT.js +0 -0
  20. package/dist/chunk-SSFBF3US.js +602 -0
  21. package/dist/chunk-SZ2XBPTW.js +8 -0
  22. package/dist/chunk-T4UIX5D7.js +115 -0
  23. package/dist/{chunk-IYWQOJMQ.js → chunk-TIHPYVAJ.js} +34 -34
  24. package/dist/{chunk-RKEW5WXI.js → chunk-TOTDGK3P.js} +1 -1
  25. package/dist/chunk-V4RFNEET.js +563 -0
  26. package/dist/chunk-VOUEJSW6.js +0 -0
  27. package/dist/{chunk-J4QDGZIA.js → chunk-WBPOZ7CL.js} +659 -275
  28. package/dist/chunk-X4VN4GIJ.js +185 -0
  29. package/dist/dispatch/index.d.ts +93 -0
  30. package/dist/dispatch/index.js +37 -0
  31. package/dist/events/index.d.ts +93 -0
  32. package/dist/events/index.js +6 -0
  33. package/dist/{runtime → execution}/index.d.ts +120 -35
  34. package/dist/{runtime → execution}/index.js +17 -11
  35. package/dist/index.d.ts +489 -115
  36. package/dist/index.js +1665 -462
  37. package/dist/inference/errors/index.js +1 -1
  38. package/dist/inference/index.d.ts +13 -21
  39. package/dist/inference/index.js +15 -12
  40. package/dist/instance-BqV2D5pc.d.ts +5723 -0
  41. package/dist/logger/index.d.ts +50 -0
  42. package/dist/logger/index.js +11 -0
  43. package/dist/mcp/index.d.ts +5 -9
  44. package/dist/mcp/index.js +2 -3
  45. package/dist/middleware/index.d.ts +10 -150
  46. package/dist/middleware/index.js +10 -2
  47. package/dist/model-messages-B4nK9D1-.d.ts +13 -0
  48. package/dist/models/index.d.ts +5 -2
  49. package/dist/models/index.js +2 -1
  50. package/dist/models/reasoning/index.js +2 -1
  51. package/dist/plugin/index.d.ts +55 -11
  52. package/dist/plugin/index.js +1 -1
  53. package/dist/profiles/index.d.ts +55 -0
  54. package/dist/{presets → profiles}/index.js +10 -10
  55. package/dist/prompt/index.d.ts +8 -13
  56. package/dist/safety/index.d.ts +109 -14
  57. package/dist/safety/index.js +59 -3
  58. package/dist/sandbox/index.d.ts +81 -0
  59. package/dist/sandbox/index.js +1 -0
  60. package/dist/skill/index.d.ts +10 -8
  61. package/dist/skill/index.js +2 -2
  62. package/dist/storage/index.d.ts +12 -4
  63. package/dist/storage/index.js +1 -1
  64. package/dist/subagents/index.d.ts +177 -0
  65. package/dist/subagents/index.js +78 -0
  66. package/dist/team/index.d.ts +544 -0
  67. package/dist/team/index.js +41 -0
  68. package/dist/tool/host/index.d.ts +41 -0
  69. package/dist/tool/host/index.js +10 -0
  70. package/dist/tool/index.d.ts +111 -21
  71. package/dist/tool/index.js +20 -13
  72. package/dist/{types-VQgymC1N.d.ts → types-Bj_J8u_W.d.ts} +44 -64
  73. package/dist/{types-CHiPh8U2.d.ts → types-C_LCeYNg.d.ts} +7 -7
  74. package/dist/types-RSCv7nQ4.d.ts +59 -0
  75. package/package.json +46 -47
  76. package/dist/builder-BgZ_j4Vs.d.ts +0 -35
  77. package/dist/chunk-5ARZJWD2.js +0 -259
  78. package/dist/chunk-DXFBQMXP.js +0 -53
  79. package/dist/chunk-H3FUYU52.js +0 -81
  80. package/dist/chunk-JLXG2SH7.js +0 -905
  81. package/dist/chunk-N7P4PN3O.js +0 -84
  82. package/dist/chunk-OFDKHNCX.js +0 -727
  83. package/dist/chunk-SDSBEQXG.js +0 -157
  84. package/dist/chunk-VEKUXUVF.js +0 -41
  85. package/dist/chunk-VNQBHPCT.js +0 -398
  86. package/dist/chunk-WWYYNWEW.js +0 -259
  87. package/dist/context/index.d.ts +0 -259
  88. package/dist/context/index.js +0 -26
  89. package/dist/events-CE72w8W4.d.ts +0 -149
  90. package/dist/host/index.d.ts +0 -45
  91. package/dist/host/index.js +0 -8
  92. package/dist/index-DQuTZ8xL.d.ts +0 -1335
  93. package/dist/messages-BYWGn8TY.d.ts +0 -110
  94. package/dist/presets/index.d.ts +0 -53
  95. package/dist/registry-DwYqsQkX.d.ts +0 -164
  96. package/dist/runner-CI-XeR16.d.ts +0 -91
  97. package/dist/scope/index.d.ts +0 -10
  98. package/dist/scope/index.js +0 -14
  99. package/dist/session-manager-KbYt2WUh.d.ts +0 -282
  100. package/dist/signal/index.d.ts +0 -28
  101. package/dist/signal/index.js +0 -6
  102. package/dist/sub-agent/index.d.ts +0 -24
  103. package/dist/sub-agent/index.js +0 -32
  104. package/dist/tool-CZWN3KbO.d.ts +0 -141
  105. package/dist/tool-DkhSCV2Y.d.ts +0 -145
  106. package/dist/tracker-DClqYqTj.d.ts +0 -96
  107. package/dist/tracking/index.d.ts +0 -111
  108. package/dist/tracking/index.js +0 -20
  109. package/dist/types-BfNpU8NS.d.ts +0 -270
  110. package/dist/types-BlOKk-Bb.d.ts +0 -330
  111. package/dist/types-BlZwmnuW.d.ts +0 -50
  112. package/dist/types-CQL-SvTn.d.ts +0 -29
  113. package/dist/types-CWm-7rvB.d.ts +0 -55
  114. package/dist/types-DTSkxakL.d.ts +0 -651
  115. package/dist/types-DmDwi2zI.d.ts +0 -339
  116. package/dist/types-YuWV4ag7.d.ts +0 -72
@@ -1,110 +0,0 @@
1
- /**
2
- * Message and token types for @cuylabs/agent-core
3
- *
4
- * Defines the message model used across conversations,
5
- * including all role variants and token usage tracking.
6
- */
7
- /**
8
- * Message roles
9
- */
10
- type MessageRole = "user" | "assistant" | "tool" | "system";
11
- /**
12
- * Base message interface
13
- */
14
- interface MessageBase {
15
- id: string;
16
- role: MessageRole;
17
- createdAt: Date;
18
- }
19
- /**
20
- * User message
21
- */
22
- interface UserMessage extends MessageBase {
23
- role: "user";
24
- content: string;
25
- /** Optional custom system prompt for this message */
26
- system?: string;
27
- }
28
- /**
29
- * Assistant message
30
- */
31
- interface AssistantMessage extends MessageBase {
32
- role: "assistant";
33
- content: string;
34
- /** Finish reason */
35
- finish?: "stop" | "length" | "tool-calls" | "content-filter" | "error" | "unknown";
36
- /** Token usage for this response */
37
- tokens?: TokenUsage;
38
- /** Cost in USD */
39
- cost?: number;
40
- /** Error if any */
41
- error?: MessageError;
42
- /** Tool calls made by the assistant (when finish === "tool-calls") */
43
- toolCalls?: Array<{
44
- toolCallId: string;
45
- toolName: string;
46
- args: unknown;
47
- }>;
48
- }
49
- /**
50
- * Tool result message
51
- */
52
- interface ToolMessage extends MessageBase {
53
- role: "tool";
54
- content: string;
55
- toolCallId: string;
56
- toolName: string;
57
- result: unknown;
58
- /**
59
- * Timestamp when this tool result was compacted/pruned.
60
- * Once set, this message won't be pruned again.
61
- */
62
- compactedAt?: number;
63
- }
64
- /**
65
- * System message
66
- */
67
- interface SystemMessage extends MessageBase {
68
- role: "system";
69
- content: string;
70
- }
71
- /**
72
- * Union of all message types
73
- */
74
- type Message = UserMessage | AssistantMessage | ToolMessage | SystemMessage;
75
- /**
76
- * Error in a message
77
- */
78
- interface MessageError {
79
- name: string;
80
- message: string;
81
- code?: string;
82
- status?: number;
83
- }
84
- /**
85
- * Token usage statistics
86
- */
87
- interface TokenUsage {
88
- inputTokens?: number;
89
- outputTokens?: number;
90
- totalTokens?: number;
91
- /** Cache read tokens (if supported) */
92
- cacheReadTokens?: number;
93
- /** Cache write tokens (if supported) */
94
- cacheWriteTokens?: number;
95
- }
96
- /**
97
- * Session state
98
- */
99
- interface Session {
100
- id: string;
101
- messages: Message[];
102
- createdAt: Date;
103
- updatedAt: Date;
104
- /** Optional title */
105
- title?: string;
106
- /** Parent session ID for forking */
107
- parentID?: string;
108
- }
109
-
110
- export type { AssistantMessage as A, Message as M, Session as S, TokenUsage as T, UserMessage as U, MessageBase as a, MessageError as b, MessageRole as c, SystemMessage as d, ToolMessage as e };
@@ -1,53 +0,0 @@
1
- import { P as Preset, A as AppliedPreset } from '../types-BlZwmnuW.js';
2
- import { T as Tool } from '../tool-CZWN3KbO.js';
3
- import 'ai';
4
- import '../types-CQaXbRsS.js';
5
- import 'zod';
6
- import '../tool-DkhSCV2Y.js';
7
- import '../types-CHiPh8U2.js';
8
- import '../types-CQL-SvTn.js';
9
-
10
- /**
11
- * Filter tools using preset allow/deny patterns.
12
- *
13
- * Explicit allow matches win over deny matches. This lets presets define a
14
- * broad deny rule like `"*"` and then carve out a safe allow-list.
15
- */
16
- declare function filterTools(tools: Tool.AnyInfo[], options: {
17
- allow?: string[];
18
- deny?: string[];
19
- }): Tool.AnyInfo[];
20
-
21
- /**
22
- * Apply a preset to available tools and a parent system prompt.
23
- */
24
- declare function applyPreset(preset: Preset, availableTools: Tool.AnyInfo[], baseSystemPrompt?: string): AppliedPreset;
25
- /**
26
- * Merge multiple presets. Later presets override earlier scalar values.
27
- */
28
- declare function mergePresets(...presets: Preset[]): Preset;
29
- /**
30
- * Create a custom preset with sensible defaults.
31
- */
32
- declare function createPreset(options: Partial<Preset> & {
33
- name: string;
34
- }): Preset;
35
-
36
- declare const explore: Preset;
37
- declare const plan: Preset;
38
- declare const review: Preset;
39
- declare const quick: Preset;
40
- declare const careful: Preset;
41
- declare const code: Preset;
42
- declare const watch: Preset;
43
- declare const Presets: {
44
- readonly explore: Preset;
45
- readonly plan: Preset;
46
- readonly review: Preset;
47
- readonly quick: Preset;
48
- readonly careful: Preset;
49
- readonly code: Preset;
50
- readonly watch: Preset;
51
- };
52
-
53
- export { AppliedPreset, Preset, Presets, applyPreset, careful, code, createPreset, explore, filterTools, mergePresets, plan, quick, review, watch };
@@ -1,164 +0,0 @@
1
- import { S as SkillDiscoveryResult, a as SkillMetadata, b as SkillContent, c as SkillResource, d as SkillConfig } from './types-BfNpU8NS.js';
2
-
3
- /**
4
- * Skill Registry — in-memory store for discovered skills
5
- *
6
- * The registry is the central coordination point for the skill system.
7
- * It holds discovered metadata (L1), handles on-demand content loading
8
- * (L2/L3), provides the prompt summary for injection, and manages
9
- * the lifecycle of skill state.
10
- *
11
- * ```
12
- * discoverSkills() → SkillRegistry → promptSummary (L1 → system prompt)
13
- * → loadSkill() (L2 → tool response)
14
- * → loadResource (L3 → tool response)
15
- * ```
16
- *
17
- * The registry is designed to be created once per agent and shared
18
- * across the agent's lifetime, including across forked sub-agents.
19
- *
20
- * @example
21
- * ```typescript
22
- * const registry = await createSkillRegistry("/path/to/project", {
23
- * externalDirs: [".agents", ".claude"],
24
- * });
25
- *
26
- * // L1: summary goes into system prompt
27
- * const summary = registry.formatSummary();
28
- *
29
- * // L2: agent calls skill tool → full content loaded
30
- * const content = await registry.loadContent("testing");
31
- *
32
- * // L3: agent reads a bundled reference
33
- * const ref = await registry.loadResource("testing", "references/patterns.md");
34
- * ```
35
- */
36
-
37
- /**
38
- * In-memory registry of discovered skills with lazy content loading.
39
- *
40
- * Holds L1 metadata for all skills. Content (L2) and resources (L3)
41
- * are loaded on demand and cached for the registry's lifetime.
42
- */
43
- declare class SkillRegistry {
44
- /** All discovered skill metadata indexed by name */
45
- private readonly skills;
46
- /** Cached full content for skills that have been loaded */
47
- private readonly contentCache;
48
- /** Discovery metadata */
49
- readonly discoveryResult: SkillDiscoveryResult;
50
- constructor(discoveryResult: SkillDiscoveryResult);
51
- /** Get a skill's metadata by name. Returns undefined if not found. */
52
- get(name: string): SkillMetadata | undefined;
53
- /** Check if a skill exists by name. */
54
- has(name: string): boolean;
55
- /** Get all skill metadata entries. */
56
- list(): SkillMetadata[];
57
- /** Number of registered skills. */
58
- get size(): number;
59
- /** Skill names as an array. */
60
- get names(): string[];
61
- /**
62
- * Load a skill's full content (L2: body + resource listing).
63
- *
64
- * Results are cached — subsequent calls return the cached content
65
- * without re-reading the filesystem.
66
- *
67
- * @param name Skill name
68
- * @returns Full skill content, or null if the skill doesn't exist
69
- */
70
- loadContent(name: string): Promise<SkillContent | null>;
71
- /**
72
- * Load a specific bundled resource from a skill (L3).
73
- *
74
- * The skill's content must be loaded first (via `loadContent`)
75
- * so the resource listing is available.
76
- *
77
- * @param skillName Skill name
78
- * @param relativePath Relative path to the resource within the skill dir
79
- * @returns Resource file content as UTF-8 string
80
- * @throws If the skill or resource doesn't exist
81
- */
82
- loadResource(skillName: string, relativePath: string): Promise<string>;
83
- /**
84
- * Get the list of resources for a loaded skill.
85
- *
86
- * @param name Skill name
87
- * @returns Resource list, or empty array if skill isn't loaded yet
88
- */
89
- getResources(name: string): SkillResource[];
90
- /**
91
- * Format a summary of all available skills for injection into the system prompt.
92
- *
93
- * This is the L1 layer — the agent sees names and descriptions of all
94
- * available skills, enabling it to decide which to activate via tool calls.
95
- *
96
- * The output format uses XML tags (consistent with the instruction format
97
- * in `formatInstructions`) for clear delineation in the prompt.
98
- *
99
- * Returns empty string if no skills are available.
100
- *
101
- * @example Output:
102
- * ```xml
103
- * <available-skills>
104
- *
105
- * You have access to the following skills. To activate a skill and load its
106
- * full instructions, call the `skill` tool with the skill's name.
107
- *
108
- * <skill name="testing" scope="project">
109
- * Write comprehensive test suites with vitest, covering unit, integration,
110
- * and snapshot testing patterns.
111
- * </skill>
112
- *
113
- * <skill name="frontend-design" scope="user">
114
- * Create distinctive, production-grade frontend interfaces with high design quality.
115
- * </skill>
116
- *
117
- * </available-skills>
118
- * ```
119
- */
120
- formatSummary(): string;
121
- /**
122
- * Format the full content of a loaded skill for a tool response.
123
- *
124
- * Wraps the skill body in XML with metadata, and lists bundled resources
125
- * so the agent knows what's available at L3.
126
- *
127
- * @param content Previously loaded skill content
128
- * @returns Formatted string for tool response
129
- */
130
- formatContent(content: SkillContent): string;
131
- /** Clear the content cache, forcing reloads on next access. */
132
- clearContentCache(): void;
133
- /** Check if a skill's content has been loaded and cached. */
134
- isContentLoaded(name: string): boolean;
135
- }
136
- /**
137
- * Create a skill registry by discovering all available skills.
138
- *
139
- * This is the recommended way to initialize the skill system.
140
- * It runs discovery, deduplicates by scope priority, and returns
141
- * a ready-to-use registry.
142
- *
143
- * @param cwd Current working directory
144
- * @param config Skill configuration
145
- * @returns A populated SkillRegistry
146
- *
147
- * @example
148
- * ```typescript
149
- * const registry = await createSkillRegistry("/path/to/project", {
150
- * externalDirs: [".agents", ".claude"],
151
- * roots: ["./company-skills"],
152
- * });
153
- *
154
- * console.log(`Found ${registry.size} skills`);
155
- * console.log(registry.formatSummary());
156
- * ```
157
- */
158
- declare function createSkillRegistry(cwd: string, config?: SkillConfig): Promise<SkillRegistry>;
159
- /**
160
- * Create an empty skill registry (for agents that don't use skills).
161
- */
162
- declare function emptySkillRegistry(): SkillRegistry;
163
-
164
- export { SkillRegistry as S, createSkillRegistry as c, emptySkillRegistry as e };
@@ -1,91 +0,0 @@
1
- import { A as AgentMiddleware, M as ModelCallInput, a as ModelCallContext, B as BlockedModelCall, S as StreamChunk, b as ModelCallOutput, T as ToolCallDecision, P as PromptBuildContext, c as PromptSection } from './types-DTSkxakL.js';
2
- import { A as AgentEvent } from './events-CE72w8W4.js';
3
- import { T as TokenUsage } from './messages-BYWGn8TY.js';
4
- import { T as ToolContext } from './tool-DkhSCV2Y.js';
5
- import { T as Tool } from './tool-CZWN3KbO.js';
6
-
7
- /**
8
- * Middleware Runner
9
- *
10
- * Executes middleware hooks in the correct order with proper
11
- * error handling and short-circuit semantics.
12
- *
13
- * This is the internal engine — consumers never see it.
14
- * They interact with middleware through AgentConfig.middleware.
15
- */
16
-
17
- /**
18
- * Middleware runner — holds an ordered list of middleware and
19
- * exposes methods to run each hook type with correct semantics.
20
- *
21
- * Immutable after construction. Fork creates a new runner
22
- * (with inherited + additional middleware).
23
- */
24
- declare class MiddlewareRunner {
25
- private readonly stack;
26
- constructor(middleware?: AgentMiddleware[]);
27
- /** Number of registered middleware */
28
- get count(): number;
29
- /** Whether any middleware is registered */
30
- get hasMiddleware(): boolean;
31
- /** Get the middleware list (for fork inheritance) */
32
- getMiddleware(): readonly AgentMiddleware[];
33
- runModelInput(input: ModelCallInput, ctx: ModelCallContext): Promise<ModelCallInput | BlockedModelCall>;
34
- runModelChunk(chunk: StreamChunk, ctx: ModelCallContext): Promise<StreamChunk | undefined>;
35
- runModelOutput(output: ModelCallOutput, ctx: ModelCallContext): Promise<ModelCallOutput>;
36
- /**
37
- * Run all `beforeToolCall` hooks in order.
38
- *
39
- * Returns `{ action: "allow" }` if all middleware allow (or have no hook).
40
- * Returns `{ action: "deny", reason }` on first denial — remaining
41
- * middleware are skipped.
42
- */
43
- runBeforeToolCall(tool: string, args: unknown, ctx: ToolContext): Promise<ToolCallDecision>;
44
- /**
45
- * Run all `afterToolCall` hooks in reverse order.
46
- *
47
- * Each hook receives the result from the previous hook (or the
48
- * original tool result for the first hook). Errors are caught
49
- * and logged — the original result passes through.
50
- */
51
- runAfterToolCall(tool: string, args: unknown, result: Tool.ExecuteResult, ctx: ToolContext): Promise<Tool.ExecuteResult>;
52
- /**
53
- * Collect prompt sections from all middleware.
54
- *
55
- * Returns a flat array of sections. Each middleware can return a single
56
- * section, an array of sections, or undefined/empty.
57
- */
58
- collectPromptSections(ctx: PromptBuildContext): PromptSection[];
59
- /**
60
- * Broadcast an event to all middleware observers.
61
- *
62
- * Non-blocking — errors are caught and logged. This never
63
- * slows down the streaming pipeline.
64
- */
65
- emitEvent(event: AgentEvent): void;
66
- /**
67
- * Get the OTel context for a session from the telemetry middleware.
68
- * Returns undefined if no telemetry middleware is registered.
69
- */
70
- getOtelContext(sessionId: string): unknown | undefined;
71
- /**
72
- * Run all `onChatStart` hooks in order.
73
- *
74
- * Errors are caught and logged — a broken logger should not
75
- * prevent the chat from starting.
76
- */
77
- runChatStart(sessionId: string, message: string): Promise<void>;
78
- /**
79
- * Run all `onChatEnd` hooks in order.
80
- *
81
- * Always called, even when the stream errored. Errors in handlers
82
- * are caught and logged.
83
- */
84
- runChatEnd(sessionId: string, result: {
85
- usage?: TokenUsage;
86
- error?: Error;
87
- output?: string;
88
- }): Promise<void>;
89
- }
90
-
91
- export { MiddlewareRunner as M };
@@ -1,10 +0,0 @@
1
- import { e as ScopeOptions, a as Scope, S as ScopeSnapshot } from '../types-CQL-SvTn.js';
2
- export { b as ScopeAttributeValue, c as ScopeAttributes, d as ScopeKind } from '../types-CQL-SvTn.js';
3
-
4
- declare function currentScope(): Scope | undefined;
5
- declare function snapshotScope(scope?: Scope | undefined): ScopeSnapshot | undefined;
6
- declare function createScope(options: ScopeOptions): Scope;
7
- declare function withinScope<T>(options: ScopeOptions, fn: () => T | Promise<T>): Promise<T>;
8
- declare function restoreScope<T>(snapshot: ScopeSnapshot | undefined, fn: () => T | Promise<T>): Promise<T>;
9
-
10
- export { Scope, ScopeOptions, ScopeSnapshot, createScope, currentScope, restoreScope, snapshotScope, withinScope };
@@ -1,14 +0,0 @@
1
- import {
2
- createScope,
3
- currentScope,
4
- restoreScope,
5
- snapshotScope,
6
- withinScope
7
- } from "../chunk-N7P4PN3O.js";
8
- export {
9
- createScope,
10
- currentScope,
11
- restoreScope,
12
- snapshotScope,
13
- withinScope
14
- };