@cuylabs/agent-core 0.4.0 → 0.6.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 (66) hide show
  1. package/README.md +81 -323
  2. package/dist/builder-BKkipazh.d.ts +34 -0
  3. package/dist/capabilities/index.d.ts +97 -0
  4. package/dist/capabilities/index.js +46 -0
  5. package/dist/chunk-3C4VKG4P.js +2149 -0
  6. package/dist/chunk-6TDTQJ4P.js +116 -0
  7. package/dist/chunk-7MUFEN4K.js +559 -0
  8. package/dist/chunk-BDBZ3SLK.js +745 -0
  9. package/dist/chunk-DWYX7ASF.js +26 -0
  10. package/dist/chunk-FG4MD5MU.js +54 -0
  11. package/dist/chunk-IVUJDISU.js +556 -0
  12. package/dist/chunk-LRHOS4ZN.js +584 -0
  13. package/dist/chunk-O2ZCFQL6.js +764 -0
  14. package/dist/chunk-P6YF7USR.js +182 -0
  15. package/dist/chunk-QAQADS4X.js +258 -0
  16. package/dist/chunk-QWFMX226.js +879 -0
  17. package/dist/{chunk-6VKLWNRE.js → chunk-SDSBEQXG.js} +1 -132
  18. package/dist/chunk-VBWWUHWI.js +724 -0
  19. package/dist/chunk-VEKUXUVF.js +41 -0
  20. package/dist/chunk-X635CM2F.js +305 -0
  21. package/dist/chunk-YUUJK53A.js +91 -0
  22. package/dist/chunk-ZXAKHMWH.js +283 -0
  23. package/dist/config-D2xeGEHK.d.ts +52 -0
  24. package/dist/context/index.d.ts +259 -0
  25. package/dist/context/index.js +26 -0
  26. package/dist/identifiers-BLUxFqV_.d.ts +12 -0
  27. package/dist/index-DZQJD_hp.d.ts +1067 -0
  28. package/dist/index-ipP3_ztp.d.ts +198 -0
  29. package/dist/index.d.ts +210 -5736
  30. package/dist/index.js +2132 -7767
  31. package/dist/mcp/index.d.ts +26 -0
  32. package/dist/mcp/index.js +14 -0
  33. package/dist/messages-BYWGn8TY.d.ts +110 -0
  34. package/dist/middleware/index.d.ts +8 -0
  35. package/dist/middleware/index.js +12 -0
  36. package/dist/models/index.d.ts +33 -0
  37. package/dist/models/index.js +12 -0
  38. package/dist/network-D76DS5ot.d.ts +5 -0
  39. package/dist/prompt/index.d.ts +225 -0
  40. package/dist/prompt/index.js +45 -0
  41. package/dist/reasoning/index.d.ts +71 -0
  42. package/dist/reasoning/index.js +47 -0
  43. package/dist/registry-CuRWWtcT.d.ts +164 -0
  44. package/dist/resolver-DOfZ-xuk.d.ts +254 -0
  45. package/dist/runner-G1wxEgac.d.ts +852 -0
  46. package/dist/runtime/index.d.ts +357 -0
  47. package/dist/runtime/index.js +64 -0
  48. package/dist/session-manager-Uawm2Le7.d.ts +274 -0
  49. package/dist/skill/index.d.ts +103 -0
  50. package/dist/skill/index.js +39 -0
  51. package/dist/storage/index.d.ts +167 -0
  52. package/dist/storage/index.js +50 -0
  53. package/dist/sub-agent/index.d.ts +14 -0
  54. package/dist/sub-agent/index.js +15 -0
  55. package/dist/tool/index.d.ts +174 -1
  56. package/dist/tool/index.js +12 -3
  57. package/dist/tool-DYp6-cC3.d.ts +239 -0
  58. package/dist/tool-pFAnJc5Y.d.ts +419 -0
  59. package/dist/tracker-DClqYqTj.d.ts +96 -0
  60. package/dist/tracking/index.d.ts +109 -0
  61. package/dist/tracking/index.js +20 -0
  62. package/dist/types-BWo810L_.d.ts +648 -0
  63. package/dist/types-CQaXbRsS.d.ts +47 -0
  64. package/dist/types-VQgymC1N.d.ts +156 -0
  65. package/package.json +89 -5
  66. package/dist/index-BlSTfS-W.d.ts +0 -470
@@ -0,0 +1,198 @@
1
+ import { h as AgentMiddleware } from './runner-G1wxEgac.js';
2
+ import { TelemetrySettings } from 'ai';
3
+
4
+ /**
5
+ * Risk level for operations.
6
+ */
7
+ type RiskLevel = "safe" | "moderate" | "dangerous";
8
+ /**
9
+ * User response to an approval request.
10
+ */
11
+ type ApprovalAction = "allow" | "deny" | "remember";
12
+ /**
13
+ * Approval request sent to the UI/handler.
14
+ */
15
+ interface ApprovalRequest {
16
+ /** Unique request ID */
17
+ id: string;
18
+ /** Session ID */
19
+ sessionId: string;
20
+ /** Tool name */
21
+ tool: string;
22
+ /** Tool arguments */
23
+ args: unknown;
24
+ /** Human-readable description */
25
+ description: string;
26
+ /** Risk level */
27
+ risk: RiskLevel;
28
+ /** Patterns that would be remembered if "remember" is chosen */
29
+ patterns: string[];
30
+ /** Timestamp */
31
+ timestamp: number;
32
+ }
33
+ /**
34
+ * Rule for auto-approving/denying operations.
35
+ */
36
+ interface ApprovalRule {
37
+ /** Pattern to match (glob-style) */
38
+ pattern: string;
39
+ /** Tool to match (`*` for all) */
40
+ tool: string;
41
+ /** Action to take */
42
+ action: "allow" | "deny";
43
+ }
44
+ /**
45
+ * Configuration for the approval handler.
46
+ */
47
+ interface ApprovalConfig {
48
+ /** Default action when no rule matches (default: "ask") */
49
+ defaultAction?: "allow" | "deny" | "ask";
50
+ /** Pre-configured rules */
51
+ rules?: ApprovalRule[];
52
+ /** Handler for approval requests */
53
+ onRequest?: (request: ApprovalRequest) => Promise<ApprovalAction>;
54
+ /** Timeout for approval requests in ms (default: 5 minutes) */
55
+ timeout?: number;
56
+ }
57
+
58
+ /**
59
+ * Approval Middleware
60
+ *
61
+ * Wraps the existing approval system as an AgentMiddleware.
62
+ * This is how approval finally gets wired into the tool execution
63
+ * pipeline — no more dead code.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import { createAgent, approvalMiddleware } from "@cuylabs/agent-core";
68
+ *
69
+ * const agent = createAgent({
70
+ * model: anthropic("claude-sonnet-4-20250514"),
71
+ * tools: [read, write, bash],
72
+ * middleware: [
73
+ * approvalMiddleware({
74
+ * rules: [
75
+ * { pattern: "src/*", tool: "read_file", action: "allow" },
76
+ * ],
77
+ * onRequest: async (req) => {
78
+ * // Prompt user in your UI
79
+ * return await askUser(req);
80
+ * },
81
+ * }),
82
+ * ],
83
+ * });
84
+ * ```
85
+ */
86
+
87
+ /**
88
+ * Configuration for the approval middleware.
89
+ *
90
+ * Extends the existing ApprovalConfig with middleware-specific options.
91
+ */
92
+ interface ApprovalMiddlewareConfig extends ApprovalConfig {
93
+ /**
94
+ * Custom risk classification for tools.
95
+ *
96
+ * Overrides the built-in risk map. Tools not listed here
97
+ * fall back to the default classification.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * customRisks: {
102
+ * "my_deploy_tool": "dangerous",
103
+ * "my_lint_tool": "safe",
104
+ * }
105
+ * ```
106
+ */
107
+ customRisks?: Record<string, RiskLevel>;
108
+ }
109
+ /**
110
+ * Create an approval middleware from an ApprovalConfig.
111
+ *
112
+ * This bridges the existing `createApprovalHandler` into the middleware
113
+ * system. The `beforeToolCall` hook checks rules, classifies risk,
114
+ * and calls the approval handler when needed.
115
+ *
116
+ * @param config - Approval configuration (rules, handler, timeout, etc.)
117
+ * @returns An AgentMiddleware that gates tool execution
118
+ */
119
+ declare function approvalMiddleware(config?: ApprovalMiddlewareConfig): AgentMiddleware;
120
+
121
+ /**
122
+ * Configuration for the OpenTelemetry middleware.
123
+ */
124
+ interface OtelMiddlewareConfig {
125
+ /**
126
+ * Whether to record tool call arguments as span attributes.
127
+ * Defaults to `true`.
128
+ */
129
+ recordInputs?: boolean;
130
+ /**
131
+ * Whether to record tool results as span attributes.
132
+ * Defaults to `true`.
133
+ */
134
+ recordOutputs?: boolean;
135
+ /**
136
+ * Agent name — used in the root span name and attributes.
137
+ * Falls back to `"agent"`.
138
+ */
139
+ agentName?: string;
140
+ /** Agent description — recorded as `gen_ai.agent.description`. */
141
+ agentDescription?: string;
142
+ /**
143
+ * Whether to emit `execute_tool` spans for tool calls.
144
+ * Defaults to `true`.
145
+ */
146
+ emitToolSpans?: boolean;
147
+ /**
148
+ * TTL in milliseconds for orphaned spans.
149
+ * Defaults to 5 minutes.
150
+ */
151
+ spanTimeoutMs?: number;
152
+ }
153
+ /**
154
+ * Configuration for `createTelemetryConfig()`.
155
+ */
156
+ interface TelemetryConfig {
157
+ /** Agent name — used in span names and `gen_ai.agent.name`. */
158
+ agentName: string;
159
+ /** Agent description — recorded as `gen_ai.agent.description`. */
160
+ agentDescription?: string;
161
+ /** Record tool arguments and LLM prompts in spans. Defaults to `true`. */
162
+ recordInputs?: boolean;
163
+ /** Record tool results and LLM responses in spans. Defaults to `true`. */
164
+ recordOutputs?: boolean;
165
+ /** Emit `execute_tool` spans from our middleware. Defaults to `true`. */
166
+ emitToolSpans?: boolean;
167
+ /** TTL in ms for orphaned spans. Defaults to 5 minutes. */
168
+ spanTimeoutMs?: number;
169
+ /**
170
+ * An OTel `SpanProcessor` to auto-create and register a `NodeTracerProvider`.
171
+ */
172
+ spanProcessor?: unknown;
173
+ /**
174
+ * OTel service name for the `NodeTracerProvider` resource.
175
+ * Defaults to `agentName`.
176
+ */
177
+ serviceName?: string;
178
+ }
179
+ /**
180
+ * Result of `createTelemetryConfig()`.
181
+ */
182
+ interface TelemetryConfigResult {
183
+ /** Agent-core middleware. */
184
+ middleware: AgentMiddleware;
185
+ /** AI SDK telemetry settings. */
186
+ telemetry: TelemetrySettings;
187
+ /**
188
+ * Flush and shut down the auto-created tracer provider.
189
+ * No-op when no provider was auto-created.
190
+ */
191
+ shutdown: () => Promise<void>;
192
+ }
193
+
194
+ declare function otelMiddleware(config?: OtelMiddlewareConfig): AgentMiddleware;
195
+
196
+ declare function createTelemetryConfig(config: TelemetryConfig): TelemetryConfigResult;
197
+
198
+ export { type ApprovalConfig as A, type OtelMiddlewareConfig as O, type RiskLevel as R, type TelemetryConfig as T, type ApprovalRule as a, type ApprovalAction as b, type ApprovalMiddlewareConfig as c, type ApprovalRequest as d, type TelemetryConfigResult as e, approvalMiddleware as f, createTelemetryConfig as g, otelMiddleware as o };