@agentick/shared 0.0.1
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/LICENSE +21 -0
- package/README.md +322 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/.tsbuildinfo.build +1 -0
- package/dist/block-types.d.ts +85 -0
- package/dist/block-types.d.ts.map +1 -0
- package/dist/block-types.js +98 -0
- package/dist/block-types.js.map +1 -0
- package/dist/blocks.d.ts +396 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +209 -0
- package/dist/blocks.js.map +1 -0
- package/dist/devtools.d.ts +672 -0
- package/dist/devtools.d.ts.map +1 -0
- package/dist/devtools.js +445 -0
- package/dist/devtools.js.map +1 -0
- package/dist/errors.d.ts +335 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +529 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity.d.ts +99 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +116 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +55 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +83 -0
- package/dist/input.js.map +1 -0
- package/dist/messages.d.ts +98 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +81 -0
- package/dist/messages.js.map +1 -0
- package/dist/model-catalog.d.ts +144 -0
- package/dist/model-catalog.d.ts.map +1 -0
- package/dist/model-catalog.js +861 -0
- package/dist/model-catalog.js.map +1 -0
- package/dist/models.d.ts +173 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +10 -0
- package/dist/models.js.map +1 -0
- package/dist/protocol.d.ts +257 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +41 -0
- package/dist/protocol.js.map +1 -0
- package/dist/streaming.d.ts +635 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +134 -0
- package/dist/streaming.js.map +1 -0
- package/dist/testing/fixtures.d.ts +250 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +827 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/helpers.d.ts +95 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/helpers.js +271 -0
- package/dist/testing/helpers.js.map +1 -0
- package/dist/testing/index.d.ts +42 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +70 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/timeline.d.ts +59 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +11 -0
- package/dist/timeline.js.map +1 -0
- package/dist/tools.d.ts +220 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +63 -0
- package/dist/tools.js.map +1 -0
- package/dist/utils/entity-ids.d.ts +26 -0
- package/dist/utils/entity-ids.d.ts.map +1 -0
- package/dist/utils/entity-ids.js +44 -0
- package/dist/utils/entity-ids.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge-deep.d.ts +10 -0
- package/dist/utils/merge-deep.d.ts.map +1 -0
- package/dist/utils/merge-deep.js +33 -0
- package/dist/utils/merge-deep.js.map +1 -0
- package/package.json +84 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentick Error Hierarchy
|
|
3
|
+
*
|
|
4
|
+
* Structured error classes for consistent error handling across the framework.
|
|
5
|
+
* All errors extend AgentickError which provides:
|
|
6
|
+
* - Unique error codes for programmatic handling
|
|
7
|
+
* - Rich metadata for debugging
|
|
8
|
+
* - Serialization support for client/server communication
|
|
9
|
+
* - Type guards for catching specific error types
|
|
10
|
+
*
|
|
11
|
+
* @example Throwing errors
|
|
12
|
+
* ```typescript
|
|
13
|
+
* throw new NotFoundError('model', 'gpt-4', 'Model not found in registry');
|
|
14
|
+
* throw new ValidationError('messages', 'array', 'Messages must be an array');
|
|
15
|
+
* throw new AbortError('User cancelled operation');
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Catching specific errors
|
|
19
|
+
* ```typescript
|
|
20
|
+
* try {
|
|
21
|
+
* await engine.execute(input);
|
|
22
|
+
* } catch (error) {
|
|
23
|
+
* if (isAbortError(error)) {
|
|
24
|
+
* // Handle cancellation
|
|
25
|
+
* } else if (isNotFoundError(error)) {
|
|
26
|
+
* // Handle missing resource
|
|
27
|
+
* } else if (isAgentickError(error)) {
|
|
28
|
+
* // Handle any Agentick error
|
|
29
|
+
* console.log(error.code, error.toJSON());
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Base class for all Agentick errors.
|
|
36
|
+
* Provides consistent structure, serialization, and type identification.
|
|
37
|
+
*/
|
|
38
|
+
export class AgentickError extends Error {
|
|
39
|
+
/** Unique error code for programmatic handling */
|
|
40
|
+
code;
|
|
41
|
+
/** Additional error details */
|
|
42
|
+
details;
|
|
43
|
+
/** Original error that caused this error */
|
|
44
|
+
cause;
|
|
45
|
+
constructor(code, message, details = {}, cause) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "AgentickError";
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.details = details;
|
|
50
|
+
this.cause = cause;
|
|
51
|
+
// Maintain proper prototype chain
|
|
52
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
53
|
+
// Capture stack trace (V8 engines - Node.js specific)
|
|
54
|
+
const ErrorWithCapture = Error;
|
|
55
|
+
if (typeof ErrorWithCapture.captureStackTrace === "function") {
|
|
56
|
+
ErrorWithCapture.captureStackTrace(this, new.target);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Serialize error for transport (JSON-safe)
|
|
61
|
+
*/
|
|
62
|
+
toJSON() {
|
|
63
|
+
const serialized = {
|
|
64
|
+
name: this.name,
|
|
65
|
+
code: this.code,
|
|
66
|
+
message: this.message,
|
|
67
|
+
};
|
|
68
|
+
if (Object.keys(this.details).length > 0) {
|
|
69
|
+
serialized.details = this.details;
|
|
70
|
+
}
|
|
71
|
+
if (this.cause) {
|
|
72
|
+
if (this.cause instanceof AgentickError) {
|
|
73
|
+
serialized.cause = this.cause.toJSON();
|
|
74
|
+
}
|
|
75
|
+
else if (this.cause instanceof Error) {
|
|
76
|
+
serialized.cause = {
|
|
77
|
+
message: this.cause.message,
|
|
78
|
+
name: this.cause.name,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (this.stack) {
|
|
83
|
+
serialized.stack = this.stack;
|
|
84
|
+
}
|
|
85
|
+
return serialized;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create error from serialized format
|
|
89
|
+
*/
|
|
90
|
+
static fromJSON(json) {
|
|
91
|
+
const cause = json.cause
|
|
92
|
+
? json.cause.code
|
|
93
|
+
? AgentickError.fromJSON(json.cause)
|
|
94
|
+
: new Error(json.cause.message)
|
|
95
|
+
: undefined;
|
|
96
|
+
return new AgentickError(json.code, json.message, json.details, cause);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// =============================================================================
|
|
100
|
+
// Abort/Cancellation Errors
|
|
101
|
+
// =============================================================================
|
|
102
|
+
/**
|
|
103
|
+
* Error thrown when an operation is aborted or cancelled.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* throw new AbortError('User cancelled the operation');
|
|
108
|
+
* throw new AbortError('Operation timed out', 'ABORT_TIMEOUT', { timeoutMs: 30000 });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export class AbortError extends AgentickError {
|
|
112
|
+
constructor(message = "Operation aborted", code = "ABORT_CANCELLED", details = {}, cause) {
|
|
113
|
+
super(code, message, details, cause);
|
|
114
|
+
this.name = "AbortError";
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create from an AbortSignal's reason
|
|
118
|
+
*/
|
|
119
|
+
static fromSignal(signal) {
|
|
120
|
+
const reason = signal.reason;
|
|
121
|
+
if (reason instanceof AbortError) {
|
|
122
|
+
return reason;
|
|
123
|
+
}
|
|
124
|
+
const message = reason instanceof Error ? reason.message : String(reason || "Operation aborted");
|
|
125
|
+
return new AbortError(message, "ABORT_SIGNAL", {}, reason instanceof Error ? reason : undefined);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a timeout abort error
|
|
129
|
+
*/
|
|
130
|
+
static timeout(timeoutMs) {
|
|
131
|
+
return new AbortError(`Operation timed out after ${timeoutMs}ms`, "ABORT_TIMEOUT", {
|
|
132
|
+
timeoutMs,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Error thrown when a required resource cannot be found.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* throw new NotFoundError('model', 'gpt-4');
|
|
142
|
+
* throw new NotFoundError('tool', 'search', 'Tool not found in registry');
|
|
143
|
+
* throw new NotFoundError('execution', 'exec-123', 'Parent execution not found');
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export class NotFoundError extends AgentickError {
|
|
147
|
+
/** Type of resource that was not found */
|
|
148
|
+
resourceType;
|
|
149
|
+
/** Identifier of the resource */
|
|
150
|
+
resourceId;
|
|
151
|
+
constructor(resourceType, resourceId, message, cause) {
|
|
152
|
+
const codeMap = {
|
|
153
|
+
model: "NOT_FOUND_MODEL",
|
|
154
|
+
tool: "NOT_FOUND_TOOL",
|
|
155
|
+
agent: "NOT_FOUND_AGENT",
|
|
156
|
+
execution: "NOT_FOUND_EXECUTION",
|
|
157
|
+
channel: "NOT_FOUND_RESOURCE",
|
|
158
|
+
session: "NOT_FOUND_RESOURCE",
|
|
159
|
+
procedure: "NOT_FOUND_RESOURCE",
|
|
160
|
+
"mcp-client": "NOT_FOUND_RESOURCE",
|
|
161
|
+
scope: "NOT_FOUND_RESOURCE",
|
|
162
|
+
resource: "NOT_FOUND_RESOURCE",
|
|
163
|
+
};
|
|
164
|
+
super(codeMap[resourceType], message || `${resourceType} '${resourceId}' not found`, { resourceType, resourceId }, cause);
|
|
165
|
+
this.name = "NotFoundError";
|
|
166
|
+
this.resourceType = resourceType;
|
|
167
|
+
this.resourceId = resourceId;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// =============================================================================
|
|
171
|
+
// Validation Errors
|
|
172
|
+
// =============================================================================
|
|
173
|
+
/**
|
|
174
|
+
* Error thrown when input validation fails.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* throw new ValidationError('messages', 'Messages are required');
|
|
179
|
+
* throw new ValidationError('handler', 'Handler function required', { expected: 'function' });
|
|
180
|
+
* throw new ValidationError('input.model', 'Model identifier must be provided');
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export class ValidationError extends AgentickError {
|
|
184
|
+
/** Field or parameter that failed validation */
|
|
185
|
+
field;
|
|
186
|
+
/** Expected type or format (optional) */
|
|
187
|
+
expected;
|
|
188
|
+
/** Actual value received (optional) */
|
|
189
|
+
received;
|
|
190
|
+
constructor(field, message, options = {}, cause) {
|
|
191
|
+
const code = options.code || "VALIDATION_REQUIRED";
|
|
192
|
+
super(code, message, {
|
|
193
|
+
field,
|
|
194
|
+
...(options.expected && { expected: options.expected }),
|
|
195
|
+
...(options.received && { received: options.received }),
|
|
196
|
+
}, cause);
|
|
197
|
+
this.name = "ValidationError";
|
|
198
|
+
this.field = field;
|
|
199
|
+
this.expected = options.expected;
|
|
200
|
+
this.received = options.received;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Create a "required" validation error
|
|
204
|
+
*/
|
|
205
|
+
static required(field, message) {
|
|
206
|
+
return new ValidationError(field, message || `${field} is required`, {
|
|
207
|
+
code: "VALIDATION_REQUIRED",
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Create a "type mismatch" validation error
|
|
212
|
+
*/
|
|
213
|
+
static type(field, expected, received) {
|
|
214
|
+
const msg = received
|
|
215
|
+
? `${field} must be ${expected}, received ${received}`
|
|
216
|
+
: `${field} must be ${expected}`;
|
|
217
|
+
return new ValidationError(field, msg, {
|
|
218
|
+
expected,
|
|
219
|
+
received,
|
|
220
|
+
code: "VALIDATION_TYPE",
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// =============================================================================
|
|
225
|
+
// State/Lifecycle Errors
|
|
226
|
+
// =============================================================================
|
|
227
|
+
/**
|
|
228
|
+
* Error thrown when an operation is attempted in an invalid state.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* throw new StateError('streaming', 'completed', 'Cannot send message to completed execution');
|
|
233
|
+
* throw new StateError('initializing', 'ready', 'Engine is still initializing');
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export class StateError extends AgentickError {
|
|
237
|
+
/** Current state */
|
|
238
|
+
current;
|
|
239
|
+
/** Expected/required state (optional) */
|
|
240
|
+
expectedState;
|
|
241
|
+
constructor(current, expectedState, message, code = "STATE_INVALID", cause) {
|
|
242
|
+
super(code, message, { current, ...(expectedState && { expectedState }) }, cause);
|
|
243
|
+
this.name = "StateError";
|
|
244
|
+
this.current = current;
|
|
245
|
+
this.expectedState = expectedState;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Create error for "not ready" state
|
|
249
|
+
*/
|
|
250
|
+
static notReady(component, current) {
|
|
251
|
+
return new StateError(current, "ready", `${component} is not ready (current state: ${current})`, "STATE_NOT_READY");
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Create error for "already complete" state
|
|
255
|
+
*/
|
|
256
|
+
static alreadyComplete(operation) {
|
|
257
|
+
return new StateError("complete", undefined, `Cannot ${operation}: already complete`, "STATE_ALREADY_COMPLETE");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// =============================================================================
|
|
261
|
+
// Transport/Network Errors
|
|
262
|
+
// =============================================================================
|
|
263
|
+
/**
|
|
264
|
+
* Error thrown for network/transport failures.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* throw new TransportError('timeout', 'Request timed out after 30000ms');
|
|
269
|
+
* throw new TransportError('connection', 'SSE connection error');
|
|
270
|
+
* throw new TransportError('response', 'No response body');
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
export class TransportError extends AgentickError {
|
|
274
|
+
/** Type of transport error */
|
|
275
|
+
transportCode;
|
|
276
|
+
/** HTTP status code if applicable */
|
|
277
|
+
statusCode;
|
|
278
|
+
constructor(transportCode, message, options = {}, cause) {
|
|
279
|
+
const codeMap = {
|
|
280
|
+
timeout: "TRANSPORT_TIMEOUT",
|
|
281
|
+
connection: "TRANSPORT_CONNECTION",
|
|
282
|
+
response: "TRANSPORT_RESPONSE",
|
|
283
|
+
parse: "TRANSPORT_PARSE",
|
|
284
|
+
};
|
|
285
|
+
super(codeMap[transportCode], message, {
|
|
286
|
+
transportCode,
|
|
287
|
+
...(options.statusCode && { statusCode: options.statusCode }),
|
|
288
|
+
...(options.url && { url: options.url }),
|
|
289
|
+
...(options.method && { method: options.method }),
|
|
290
|
+
}, cause);
|
|
291
|
+
this.name = "TransportError";
|
|
292
|
+
this.transportCode = transportCode;
|
|
293
|
+
this.statusCode = options.statusCode;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Create a timeout error
|
|
297
|
+
*/
|
|
298
|
+
static timeout(timeoutMs, url) {
|
|
299
|
+
return new TransportError("timeout", `Request timeout after ${timeoutMs}ms`, { url });
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create a connection error
|
|
303
|
+
*/
|
|
304
|
+
static connection(message, url, cause) {
|
|
305
|
+
return new TransportError("connection", message, { url }, cause);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Create an HTTP error (non-2xx response)
|
|
309
|
+
*/
|
|
310
|
+
static http(statusCode, url, message) {
|
|
311
|
+
return new TransportError("response", message || `HTTP ${statusCode}`, {
|
|
312
|
+
statusCode,
|
|
313
|
+
url,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// =============================================================================
|
|
318
|
+
// Adapter/Provider Errors
|
|
319
|
+
// =============================================================================
|
|
320
|
+
/**
|
|
321
|
+
* Error thrown by model adapters for provider-specific errors.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* throw new AdapterError('openai', 'No message in response', 'ADAPTER_RESPONSE');
|
|
326
|
+
* throw new AdapterError('google', 'Rate limit exceeded', 'ADAPTER_RATE_LIMIT', { retryAfter: 60 });
|
|
327
|
+
* throw new AdapterError('anthropic', 'Content blocked', 'ADAPTER_CONTENT_FILTER');
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
export class AdapterError extends AgentickError {
|
|
331
|
+
/** Provider name (openai, google, anthropic, etc.) */
|
|
332
|
+
provider;
|
|
333
|
+
/** Provider-specific error code */
|
|
334
|
+
providerErrorCode;
|
|
335
|
+
constructor(provider, message, code = "ADAPTER_RESPONSE", details = {}, cause) {
|
|
336
|
+
super(code, message, { provider, ...details }, cause);
|
|
337
|
+
this.name = "AdapterError";
|
|
338
|
+
this.provider = provider;
|
|
339
|
+
this.providerErrorCode = details["providerErrorCode"];
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Create a rate limit error
|
|
343
|
+
*/
|
|
344
|
+
static rateLimit(provider, retryAfter) {
|
|
345
|
+
return new AdapterError(provider, retryAfter ? `Rate limit exceeded. Retry after ${retryAfter}s` : "Rate limit exceeded", "ADAPTER_RATE_LIMIT", { retryAfter });
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Create a content filter error
|
|
349
|
+
*/
|
|
350
|
+
static contentFiltered(provider, reason) {
|
|
351
|
+
return new AdapterError(provider, reason || "Content was filtered by provider", "ADAPTER_CONTENT_FILTER", { reason });
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Create a context length error
|
|
355
|
+
*/
|
|
356
|
+
static contextLength(provider, maxTokens, requestedTokens) {
|
|
357
|
+
return new AdapterError(provider, `Context length exceeded. Max: ${maxTokens}${requestedTokens ? `, Requested: ${requestedTokens}` : ""}`, "ADAPTER_CONTEXT_LENGTH", { maxTokens, requestedTokens });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// =============================================================================
|
|
361
|
+
// Context Errors
|
|
362
|
+
// =============================================================================
|
|
363
|
+
/**
|
|
364
|
+
* Error thrown when context is missing or invalid.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```typescript
|
|
368
|
+
* throw new ContextError('Context not found. Ensure you are running within Context.run()');
|
|
369
|
+
* throw new ContextError('Invalid context: missing required field', 'CONTEXT_INVALID');
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
export class ContextError extends AgentickError {
|
|
373
|
+
constructor(message, code = "CONTEXT_NOT_FOUND", details = {}, cause) {
|
|
374
|
+
super(code, message, details, cause);
|
|
375
|
+
this.name = "ContextError";
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Create "context not found" error with helpful message
|
|
379
|
+
*/
|
|
380
|
+
static notFound() {
|
|
381
|
+
return new ContextError("Context not found. Ensure you are running within a Context.run() block or using a Kernel Procedure.", "CONTEXT_NOT_FOUND");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
// =============================================================================
|
|
385
|
+
// Reactivity Errors
|
|
386
|
+
// =============================================================================
|
|
387
|
+
/**
|
|
388
|
+
* Error thrown for reactivity/signal system issues.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* throw new ReactivityError('Circular dependency detected in computed signal');
|
|
393
|
+
* throw new ReactivityError('Attempted to set disposed signal', 'REACTIVITY_DISPOSED');
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
export class ReactivityError extends AgentickError {
|
|
397
|
+
constructor(message, code = "REACTIVITY_CIRCULAR", details = {}, cause) {
|
|
398
|
+
super(code, message, details, cause);
|
|
399
|
+
this.name = "ReactivityError";
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Create circular dependency error
|
|
403
|
+
*/
|
|
404
|
+
static circular(signalName) {
|
|
405
|
+
return new ReactivityError(signalName
|
|
406
|
+
? `Circular dependency detected in computed signal '${signalName}'`
|
|
407
|
+
: "Circular dependency detected in computed signal", "REACTIVITY_CIRCULAR", { signalName });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
// =============================================================================
|
|
411
|
+
// Guard/Access Control Errors
|
|
412
|
+
// =============================================================================
|
|
413
|
+
/**
|
|
414
|
+
* Error thrown when a guard denies access to a procedure or resource.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* throw GuardError.role(['admin', 'moderator']);
|
|
419
|
+
* throw GuardError.denied('Insufficient permissions', { resource: 'settings' });
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
export class GuardError extends AgentickError {
|
|
423
|
+
/** Type of guard that denied access */
|
|
424
|
+
guardType;
|
|
425
|
+
constructor(message, guardType, details = {}, cause) {
|
|
426
|
+
super("GUARD_DENIED", message, { ...details, ...(guardType && { guardType }) }, cause);
|
|
427
|
+
this.name = "GuardError";
|
|
428
|
+
this.guardType = guardType;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Create a role-based guard error
|
|
432
|
+
*/
|
|
433
|
+
static role(roles) {
|
|
434
|
+
return new GuardError(`Requires one of roles [${roles.join(", ")}]`, "role", { roles });
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Create a custom guard denied error
|
|
438
|
+
*/
|
|
439
|
+
static denied(reason, details) {
|
|
440
|
+
return new GuardError(reason, "custom", details);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
// =============================================================================
|
|
444
|
+
// Type Guards
|
|
445
|
+
// =============================================================================
|
|
446
|
+
/**
|
|
447
|
+
* Check if error is any Agentick error
|
|
448
|
+
*/
|
|
449
|
+
export function isAgentickError(error) {
|
|
450
|
+
return error instanceof AgentickError;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Check if error is an AbortError
|
|
454
|
+
*/
|
|
455
|
+
export function isAbortError(error) {
|
|
456
|
+
return error instanceof AbortError;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Check if error is a NotFoundError
|
|
460
|
+
*/
|
|
461
|
+
export function isNotFoundError(error) {
|
|
462
|
+
return error instanceof NotFoundError;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Check if error is a ValidationError
|
|
466
|
+
*/
|
|
467
|
+
export function isValidationError(error) {
|
|
468
|
+
return error instanceof ValidationError;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Check if error is a StateError
|
|
472
|
+
*/
|
|
473
|
+
export function isStateError(error) {
|
|
474
|
+
return error instanceof StateError;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Check if error is a TransportError
|
|
478
|
+
*/
|
|
479
|
+
export function isTransportError(error) {
|
|
480
|
+
return error instanceof TransportError;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Check if error is an AdapterError
|
|
484
|
+
*/
|
|
485
|
+
export function isAdapterError(error) {
|
|
486
|
+
return error instanceof AdapterError;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Check if error is a ContextError
|
|
490
|
+
*/
|
|
491
|
+
export function isContextError(error) {
|
|
492
|
+
return error instanceof ContextError;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Check if error is a ReactivityError
|
|
496
|
+
*/
|
|
497
|
+
export function isReactivityError(error) {
|
|
498
|
+
return error instanceof ReactivityError;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Check if error is a GuardError
|
|
502
|
+
*/
|
|
503
|
+
export function isGuardError(error) {
|
|
504
|
+
return error instanceof GuardError;
|
|
505
|
+
}
|
|
506
|
+
// =============================================================================
|
|
507
|
+
// Utility Functions
|
|
508
|
+
// =============================================================================
|
|
509
|
+
/**
|
|
510
|
+
* Ensure a value is an Error, wrapping if necessary.
|
|
511
|
+
* Useful for catch blocks that might receive non-Error values.
|
|
512
|
+
*/
|
|
513
|
+
export function ensureError(value) {
|
|
514
|
+
if (value instanceof Error) {
|
|
515
|
+
return value;
|
|
516
|
+
}
|
|
517
|
+
return new Error(String(value));
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Wrap any error as an Agentick error if it isn't already.
|
|
521
|
+
*/
|
|
522
|
+
export function wrapAsAgentickError(error, defaultCode = "STATE_INVALID") {
|
|
523
|
+
if (error instanceof AgentickError) {
|
|
524
|
+
return error;
|
|
525
|
+
}
|
|
526
|
+
const err = ensureError(error);
|
|
527
|
+
return new AgentickError(defaultCode, err.message, {}, err);
|
|
528
|
+
}
|
|
529
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AA+DH;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,kDAAkD;IACzC,IAAI,CAAoB;IAEjC,+BAA+B;IACtB,OAAO,CAA0B;IAE1C,4CAA4C;IACnC,KAAK,CAAS;IAEvB,YACE,IAAuB,EACvB,OAAe,EACf,UAAmC,EAA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IAC9C,OAAO,KAAK,YAAY,eAAe,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC;AAED,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,cAAiC,eAAe;IAEhD,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,IAAI,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbol-based identity utilities for minification-safe type checking.
|
|
3
|
+
*
|
|
4
|
+
* Functions can be marked with symbols to identify them even after minification
|
|
5
|
+
* where function names are mangled.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Define a symbol for your component type
|
|
10
|
+
* const MY_COMPONENT_SYMBOL = Symbol.for('agentick.myComponent');
|
|
11
|
+
*
|
|
12
|
+
* // Mark the component
|
|
13
|
+
* export const MyComponent = markWithSymbol(MY_COMPONENT_SYMBOL, (props) => {
|
|
14
|
+
* return createElement(MyComponent, props);
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Check identity (minification-safe)
|
|
18
|
+
* if (hasSymbol(someFunction, MY_COMPONENT_SYMBOL)) {
|
|
19
|
+
* // It's a MyComponent
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Symbol used to mark host primitive components.
|
|
25
|
+
* These are structural primitives that should be handled by the renderer,
|
|
26
|
+
* not executed as functions.
|
|
27
|
+
*/
|
|
28
|
+
export declare const HOST_PRIMITIVE_SYMBOL: unique symbol;
|
|
29
|
+
/**
|
|
30
|
+
* Symbol used to mark semantic components.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SEMANTIC_COMPONENT_SYMBOL: unique symbol;
|
|
33
|
+
/**
|
|
34
|
+
* Symbol used to mark content components.
|
|
35
|
+
*/
|
|
36
|
+
export declare const CONTENT_COMPONENT_SYMBOL: unique symbol;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a value has a specific symbol marker.
|
|
39
|
+
*
|
|
40
|
+
* @param value - The value to check
|
|
41
|
+
* @param symbol - The symbol to look for
|
|
42
|
+
* @returns True if the value has the symbol marker
|
|
43
|
+
*/
|
|
44
|
+
export declare function hasSymbol(value: unknown, symbol: symbol): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Mark a function with a symbol for identity checking.
|
|
47
|
+
* Returns the same function with the symbol attached.
|
|
48
|
+
*
|
|
49
|
+
* @param symbol - The symbol to attach
|
|
50
|
+
* @param fn - The function to mark
|
|
51
|
+
* @returns The same function with the symbol attached
|
|
52
|
+
*/
|
|
53
|
+
export declare function markWithSymbol<T extends Function>(symbol: symbol, fn: T): T;
|
|
54
|
+
/**
|
|
55
|
+
* Mark a function as a host primitive.
|
|
56
|
+
* Host primitives are structural components that should be handled by the
|
|
57
|
+
* renderer directly, not executed as functions.
|
|
58
|
+
*
|
|
59
|
+
* @param fn - The function to mark as a host primitive
|
|
60
|
+
* @returns The same function marked as a host primitive
|
|
61
|
+
*/
|
|
62
|
+
export declare function markAsHostPrimitive<T extends Function>(fn: T): T;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a value is a host primitive component.
|
|
65
|
+
* Minification-safe - uses symbol identity, not function name.
|
|
66
|
+
*
|
|
67
|
+
* @param value - The value to check
|
|
68
|
+
* @returns True if it's a host primitive
|
|
69
|
+
*/
|
|
70
|
+
export declare function isHostPrimitive(value: unknown): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Mark a function as a semantic component.
|
|
73
|
+
*
|
|
74
|
+
* @param fn - The function to mark
|
|
75
|
+
* @returns The same function marked as a semantic component
|
|
76
|
+
*/
|
|
77
|
+
export declare function markAsSemanticComponent<T extends Function>(fn: T): T;
|
|
78
|
+
/**
|
|
79
|
+
* Check if a value is a semantic component.
|
|
80
|
+
*
|
|
81
|
+
* @param value - The value to check
|
|
82
|
+
* @returns True if it's a semantic component
|
|
83
|
+
*/
|
|
84
|
+
export declare function isSemanticComponent(value: unknown): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Mark a function as a content component.
|
|
87
|
+
*
|
|
88
|
+
* @param fn - The function to mark
|
|
89
|
+
* @returns The same function marked as a content component
|
|
90
|
+
*/
|
|
91
|
+
export declare function markAsContentComponent<T extends Function>(fn: T): T;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a value is a content component.
|
|
94
|
+
*
|
|
95
|
+
* @param value - The value to check
|
|
96
|
+
* @returns True if it's a content component
|
|
97
|
+
*/
|
|
98
|
+
export declare function isContentComponent(value: unknown): boolean;
|
|
99
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,eAAuC,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,eAA2C,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,wBAAwB,eAA0C,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAIjE;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAG3E;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE1D"}
|