@context-action/core 0.8.8 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/index.cjs +9 -224
- package/dist/index.d.cts +31 -110
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +31 -110
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -220
- package/dist/index.js.map +1 -1
- package/package.json +4 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,96 +1,20 @@
|
|
|
1
|
-
import { ZodObject, ZodRawShape, ZodType, z } from "zod";
|
|
2
|
-
//#region src/json-schema.d.ts
|
|
3
|
-
type JSONSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
|
|
4
|
-
interface JSONSchema {
|
|
5
|
-
type?: JSONSchemaType | JSONSchemaType[];
|
|
6
|
-
title?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
default?: unknown;
|
|
9
|
-
examples?: unknown[];
|
|
10
|
-
minLength?: number;
|
|
11
|
-
maxLength?: number;
|
|
12
|
-
pattern?: string;
|
|
13
|
-
format?: string;
|
|
14
|
-
minimum?: number;
|
|
15
|
-
maximum?: number;
|
|
16
|
-
exclusiveMinimum?: number;
|
|
17
|
-
exclusiveMaximum?: number;
|
|
18
|
-
multipleOf?: number;
|
|
19
|
-
items?: JSONSchema;
|
|
20
|
-
minItems?: number;
|
|
21
|
-
maxItems?: number;
|
|
22
|
-
uniqueItems?: boolean;
|
|
23
|
-
properties?: Record<string, JSONSchema>;
|
|
24
|
-
required?: string[];
|
|
25
|
-
additionalProperties?: boolean | JSONSchema;
|
|
26
|
-
enum?: unknown[];
|
|
27
|
-
const?: unknown;
|
|
28
|
-
allOf?: JSONSchema[];
|
|
29
|
-
anyOf?: JSONSchema[];
|
|
30
|
-
oneOf?: JSONSchema[];
|
|
31
|
-
not?: JSONSchema;
|
|
32
|
-
$ref?: string;
|
|
33
|
-
$defs?: Record<string, JSONSchema>;
|
|
34
|
-
[key: string]: unknown;
|
|
35
|
-
}
|
|
36
|
-
interface MCPToolDefinition {
|
|
37
|
-
name: string;
|
|
38
|
-
description?: string;
|
|
39
|
-
inputSchema: JSONSchema;
|
|
40
|
-
outputSchema?: JSONSchema;
|
|
41
|
-
}
|
|
42
|
-
interface OpenAIToolDefinition {
|
|
43
|
-
type: 'function';
|
|
44
|
-
function: {
|
|
45
|
-
name: string;
|
|
46
|
-
description?: string;
|
|
47
|
-
parameters: JSONSchema;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
interface AnthropicToolDefinition {
|
|
51
|
-
name: string;
|
|
52
|
-
description?: string;
|
|
53
|
-
input_schema: JSONSchema;
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/action-schema.d.ts
|
|
57
|
-
type ZodTypeAny = ZodType;
|
|
58
|
-
type SafeParseResult<T> = {
|
|
59
|
-
success: true;
|
|
60
|
-
data: T;
|
|
61
|
-
} | {
|
|
62
|
-
success: false;
|
|
63
|
-
error: z.ZodError;
|
|
64
|
-
};
|
|
65
|
-
interface DefineActionOptions<TSchema extends ZodRawShape> {
|
|
66
|
-
name: string;
|
|
67
|
-
description?: string;
|
|
68
|
-
parameters: ZodObject<TSchema>;
|
|
69
|
-
}
|
|
70
|
-
interface UnifiedAction<TPayload = unknown> {
|
|
71
|
-
readonly name: string;
|
|
72
|
-
readonly description?: string;
|
|
73
|
-
readonly zodSchema: ZodObject<ZodRawShape>;
|
|
74
|
-
readonly jsonSchema: JSONSchema;
|
|
75
|
-
validate: (payload: unknown) => TPayload;
|
|
76
|
-
safeParse: (payload: unknown) => SafeParseResult<TPayload>;
|
|
77
|
-
toJSONSchema: () => JSONSchema;
|
|
78
|
-
toMCP: () => MCPToolDefinition;
|
|
79
|
-
toOpenAI: () => OpenAIToolDefinition;
|
|
80
|
-
toAnthropic: () => AnthropicToolDefinition;
|
|
81
|
-
}
|
|
82
|
-
interface ActionSchemaMap {
|
|
83
|
-
[actionName: string]: UnifiedAction;
|
|
84
|
-
}
|
|
85
|
-
type InferActionPayloadMap<T extends ActionSchemaMap> = { [K in keyof T]: T[K] extends UnifiedAction<infer P> ? P : never; };
|
|
86
|
-
declare function zodToJsonSchema(schema: ZodTypeAny, zodModule: typeof z): JSONSchema;
|
|
87
|
-
declare function defineAction<TSchema extends ZodRawShape>(options: DefineActionOptions<TSchema>, zodModule: typeof z): UnifiedAction<z.infer<ZodObject<TSchema>>>;
|
|
88
|
-
declare function createActionSchema<T extends Record<string, UnifiedAction>>(actions: T): T & ActionSchemaMap;
|
|
89
|
-
declare function createActionFactory(zodModule: typeof z): <TSchema extends ZodRawShape>(options: DefineActionOptions<TSchema>) => UnifiedAction<z.infer<ZodObject<TSchema>>>;
|
|
90
|
-
//#endregion
|
|
91
1
|
//#region src/types.d.ts
|
|
92
2
|
type ActionPayloadMap = object;
|
|
93
|
-
interface
|
|
3
|
+
interface ActionSchemaLike {
|
|
4
|
+
safeParse(value: unknown): {
|
|
5
|
+
success: true;
|
|
6
|
+
data: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
success: false;
|
|
9
|
+
error: {
|
|
10
|
+
message: string;
|
|
11
|
+
issues: readonly {
|
|
12
|
+
message: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
interface PipelineController<T = unknown, R = void> {
|
|
94
18
|
readonly signal?: AbortSignal;
|
|
95
19
|
abort(reason?: string): void;
|
|
96
20
|
modifyPayload(modifier: (payload: T) => T): void;
|
|
@@ -101,7 +25,7 @@ interface PipelineController<T = any, R = void> {
|
|
|
101
25
|
getResults(): R[];
|
|
102
26
|
mergeResult(merger: (previousResults: R[], currentResult: R) => R): void;
|
|
103
27
|
}
|
|
104
|
-
type ActionHandler<T =
|
|
28
|
+
type ActionHandler<T = unknown, R = void> = (payload: T, controller: PipelineController<T, R>) => R | Promise<R> | void | Promise<void>;
|
|
105
29
|
interface HandlerConfig<T = unknown> {
|
|
106
30
|
priority?: number;
|
|
107
31
|
id?: string;
|
|
@@ -113,13 +37,13 @@ interface HandlerConfig<T = unknown> {
|
|
|
113
37
|
cleanup?: () => void;
|
|
114
38
|
condition?: (payload: T) => boolean;
|
|
115
39
|
}
|
|
116
|
-
interface HandlerRegistration<T =
|
|
40
|
+
interface HandlerRegistration<T = unknown, R = void> {
|
|
117
41
|
handler: ActionHandler<T, R>;
|
|
118
42
|
config: Required<HandlerConfig<T>>;
|
|
119
43
|
id: string;
|
|
120
44
|
}
|
|
121
45
|
type ExecutionMode = 'sequential' | 'parallel' | 'race';
|
|
122
|
-
interface PipelineContext<T =
|
|
46
|
+
interface PipelineContext<T = unknown, R = void> {
|
|
123
47
|
action: string;
|
|
124
48
|
payload: T;
|
|
125
49
|
handlers: HandlerRegistration<T, R>[];
|
|
@@ -127,6 +51,7 @@ interface PipelineContext<T = any, R = void> {
|
|
|
127
51
|
deferOnceCleanup?: boolean;
|
|
128
52
|
signal?: AbortSignal;
|
|
129
53
|
trackHandlerPromise?<V>(promise: Promise<V>): Promise<V>;
|
|
54
|
+
collectedErrors?: HandlerError[];
|
|
130
55
|
aborted: boolean;
|
|
131
56
|
abortReason: string | undefined;
|
|
132
57
|
currentIndex: number;
|
|
@@ -147,7 +72,7 @@ interface ActionRegisterConfig {
|
|
|
147
72
|
useConcurrencyQueue?: boolean;
|
|
148
73
|
maxHandlersPerAction?: number;
|
|
149
74
|
errorHandler?: (error: Error, context: unknown) => void | Promise<void>;
|
|
150
|
-
schema?:
|
|
75
|
+
schema?: Record<string, ActionSchemaLike>;
|
|
151
76
|
validateOnDispatch?: boolean;
|
|
152
77
|
validationMode?: 'strict' | 'warn' | 'silent';
|
|
153
78
|
};
|
|
@@ -217,7 +142,7 @@ interface ExecutionResult<R = void> {
|
|
|
217
142
|
duration: number | undefined;
|
|
218
143
|
result: R | undefined;
|
|
219
144
|
error: Error | undefined;
|
|
220
|
-
metadata: Record<string,
|
|
145
|
+
metadata: Record<string, unknown> | undefined;
|
|
221
146
|
}>;
|
|
222
147
|
errors: HandlerError[];
|
|
223
148
|
}
|
|
@@ -228,8 +153,8 @@ interface HandlerError {
|
|
|
228
153
|
severity: 'blocking' | 'non-blocking';
|
|
229
154
|
}
|
|
230
155
|
type UnregisterFunction = () => void;
|
|
231
|
-
type VoidActions<T extends ActionPayloadMap> = { [K in keyof T]: T[K] extends
|
|
232
|
-
type PayloadActions<T extends ActionPayloadMap> = { [K in keyof T]: T[K] extends
|
|
156
|
+
type VoidActions<T extends ActionPayloadMap> = { [K in keyof T]: T[K] extends undefined | undefined ? K : never; }[keyof T];
|
|
157
|
+
type PayloadActions<T extends ActionPayloadMap> = { [K in keyof T]: T[K] extends undefined | undefined ? never : K; }[keyof T];
|
|
233
158
|
interface ActionDispatcher<T extends ActionPayloadMap> {
|
|
234
159
|
<K extends VoidActions<T>>(action: K, options?: DispatchOptions): Promise<void>;
|
|
235
160
|
<K extends VoidActions<T>>(action: K, payload?: undefined, options?: DispatchOptions): Promise<void>;
|
|
@@ -270,10 +195,8 @@ declare class ActionRegister<T extends ActionPayloadMap = Record<string, unknown
|
|
|
270
195
|
private readonly isDebugMode;
|
|
271
196
|
private readonly maxHandlersPerAction;
|
|
272
197
|
private dispatchQueue?;
|
|
273
|
-
private filterCacheDisabled;
|
|
274
198
|
private handlerIdCounter;
|
|
275
199
|
private controllerPool;
|
|
276
|
-
private readonly maxControllerPoolSize;
|
|
277
200
|
private lifecycleState;
|
|
278
201
|
private readonly lifecycleController;
|
|
279
202
|
private readonly activeDispatches;
|
|
@@ -283,8 +206,8 @@ declare class ActionRegister<T extends ActionPayloadMap = Record<string, unknown
|
|
|
283
206
|
private _actionsProxy?;
|
|
284
207
|
private _actionsWithResultProxy?;
|
|
285
208
|
constructor(config?: ActionRegisterConfig);
|
|
286
|
-
get actions(): { [K in keyof T]: T[K] extends void ? (
|
|
287
|
-
get actionsWithResult(): { [K in keyof T]: T[K] extends void ? (
|
|
209
|
+
get actions(): { [K in keyof T]: T[K] extends void ? (payload?: undefined, options?: DispatchOptions) => Promise<void> : (payload: T[K], options?: DispatchOptions) => Promise<void>; };
|
|
210
|
+
get actionsWithResult(): { [K in keyof T]: T[K] extends void ? (payload?: undefined, options?: DispatchOptions) => Promise<ExecutionResult<any>> : (payload: T[K], options?: DispatchOptions) => Promise<ExecutionResult<any>>; };
|
|
288
211
|
register<K extends keyof T, R = void>(action: K, handler: ActionHandler<T[K], R>, config?: HandlerConfig<T[K]>): UnregisterFunction;
|
|
289
212
|
private log;
|
|
290
213
|
private assertAcceptingWork;
|
|
@@ -309,9 +232,7 @@ declare class ActionRegister<T extends ActionPayloadMap = Record<string, unknown
|
|
|
309
232
|
dispatchWithResult<K extends keyof T, R = void>(action: K, payload?: T[K], options?: DispatchOptions): Promise<ExecutionResult<R>>;
|
|
310
233
|
private _performDispatchWithResult;
|
|
311
234
|
private applyActionGuardControlsWithResult;
|
|
312
|
-
private generateFilterCacheKey;
|
|
313
235
|
private getControllerFromPool;
|
|
314
|
-
private returnControllerToPool;
|
|
315
236
|
private filterHandlers;
|
|
316
237
|
private processResults;
|
|
317
238
|
private executePipeline;
|
|
@@ -396,7 +317,7 @@ declare const ReactDevUtils: {
|
|
|
396
317
|
enableDebugMode(): void;
|
|
397
318
|
disableDebugMode(): void;
|
|
398
319
|
isDebugMode(): boolean;
|
|
399
|
-
log(component: string, action: string, message: string, data?:
|
|
320
|
+
log(component: string, action: string, message: string, data?: unknown): void;
|
|
400
321
|
getStats(registry: ActionRegister<any>): {
|
|
401
322
|
totalHandlers: number;
|
|
402
323
|
reactHandlers: number;
|
|
@@ -405,13 +326,13 @@ declare const ReactDevUtils: {
|
|
|
405
326
|
};
|
|
406
327
|
declare class ReactActionError extends Error {
|
|
407
328
|
readonly action: string;
|
|
408
|
-
readonly payload?:
|
|
329
|
+
readonly payload?: unknown;
|
|
409
330
|
readonly handlerId: string | undefined;
|
|
410
331
|
readonly timestamp: number;
|
|
411
|
-
constructor(message: string, action: string, payload?:
|
|
412
|
-
static fromActionError(originalError: Error, action: string, payload?:
|
|
332
|
+
constructor(message: string, action: string, payload?: unknown, handlerId?: string | undefined, originalError?: Error);
|
|
333
|
+
static fromActionError(originalError: Error, action: string, payload?: unknown, handlerId?: string): ReactActionError;
|
|
413
334
|
}
|
|
414
|
-
declare function isReactActionError(error:
|
|
335
|
+
declare function isReactActionError(error: unknown): error is ReactActionError;
|
|
415
336
|
//#endregion
|
|
416
337
|
//#region src/errors.d.ts
|
|
417
338
|
interface ZodIssueLike {
|
|
@@ -452,5 +373,5 @@ declare function isActionValidationError(error: unknown): error is ActionValidat
|
|
|
452
373
|
declare function isActionTimeoutError(error: unknown): error is ActionTimeoutError;
|
|
453
374
|
declare function isActionRegisterDestroyedError(error: unknown): error is ActionRegisterDestroyedError;
|
|
454
375
|
//#endregion
|
|
455
|
-
export { type ActionDispatcher, ActionGuard, type ActionHandler, type ActionPayloadMap, ActionRegister, type ActionRegisterConfig, ActionRegisterDestroyedError, type
|
|
376
|
+
export { type ActionDispatcher, ActionGuard, type ActionHandler, type ActionPayloadMap, ActionRegister, type ActionRegisterConfig, ActionRegisterDestroyedError, type ActionSchemaLike, ActionTimeoutError, ActionValidationError, type DispatchOptions, type ExecutionMode, type ExecutionResult, type HandlerConfig, type HandlerRegistration, type PipelineContext, type PipelineController, ReactActionError, ReactDevUtils, type UnregisterFunction, createActionHandler, executeParallel, executeRace, executeSequential, isActionRegisterDestroyedError, isActionTimeoutError, isActionValidationError, isReactActionError };
|
|
456
377
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/ActionRegister.ts","../src/action-guard.ts","../src/execution-modes.ts","../src/react-helpers.ts","../src/errors.ts"],"mappings":";KAmBY;UASK;EACf,UAAU;IACJ;IAAe;;IA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,kBAAkB,GAAG,UACzC,SAAS,gBAAgB,GAAG,IAC5B,mBAAmB,cAAc,oBAAoB,GAAG,IAAI,kBAAkB,mBAAmB,GAAG,KACnG;iBA8LmB,gBAAgB,GAAG,UACvC,SAAS,gBAAgB,GAAG,IAC5B,mBAAmB,cAAc,oBAAoB,GAAG,IAAI,kBAAkB,mBAAmB,GAAG,KACnG;iBA+HmB,YAAY,GAAG,UACnC,SAAS,gBAAgB,GAAG,IAC5B,mBAAmB,cAAc,oBAAoB,GAAG,IAAI,kBAAkB,mBAAmB,GAAG,KACnG;;;iBC7Sa,oBAAoB,UAAU,kBAAkB,gBAAgB,GAC9E,UAAU,eAAe,IACzB,QAAQ,GACR,SAAS,cAAc,EAAE,KACzB,SAAS,cAAc,EAAE;EAEzB,gBAAgB;EAChB;EACA;EACA,QAAQ,SAAS,cAAc,EAAE;;cAoEtB;;;;yBA8BU,gBAAgB,iBAAiB;qBASnC;IACjB;IACA;IACA,cAAc,WAAW;;;cAgChB,yBAAyB;WACpB;WACA;WACA;WACA;cAGd,iBACA,gBACA,mBACA,gCACA,gBAAgB;SAkBX,gBACL,eAAe,OACf,gBACA,mBACA,qBACC;;iBAiBW,mBAAmB,iBAAiB,SAAS;;;UCxR5C;EACf;EACA;EACA;;cAqCW,8BAA8B;EAEhC;WAGO;cAMJ,gBAAgB;WAiBZ;MAKZ,mBAAmB;MAenB;MAeA;MAeA;MAOA;EASJ;;;;;;;cAgBW,2BAA2B;WAIpB;WACA;EAJT;cAGS,gBACA;;cAQP,qCAAqC;WAI9B;WACA;EAJT;cAGS,sBACA;;iBAcJ,wBACd,iBACC,SAAS;iBAKI,qBACd,iBACC,SAAS;iBAKI,+BACd,iBACC,SAAS"}
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,6 @@ async function executeSequential(context, createController) {
|
|
|
103
103
|
}
|
|
104
104
|
i = jumpIndex;
|
|
105
105
|
context.jumpToPriority = void 0;
|
|
106
|
-
continue;
|
|
107
106
|
} else {
|
|
108
107
|
context.jumpToPriority = void 0;
|
|
109
108
|
i++;
|
|
@@ -984,55 +983,6 @@ function isActionRegisterDestroyedError(error) {
|
|
|
984
983
|
|
|
985
984
|
//#endregion
|
|
986
985
|
//#region src/ActionRegister.ts
|
|
987
|
-
const dispatchOptionKeys = /* @__PURE__ */ new Set([
|
|
988
|
-
"autoAbort",
|
|
989
|
-
"debounce",
|
|
990
|
-
"executionMode",
|
|
991
|
-
"filter",
|
|
992
|
-
"immediate",
|
|
993
|
-
"queuePriority",
|
|
994
|
-
"result",
|
|
995
|
-
"retryOnError",
|
|
996
|
-
"signal",
|
|
997
|
-
"throttle",
|
|
998
|
-
"timeout"
|
|
999
|
-
]);
|
|
1000
|
-
function isRecord(value) {
|
|
1001
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1002
|
-
}
|
|
1003
|
-
function isOptionalNumber(value) {
|
|
1004
|
-
return value === void 0 || typeof value === "number";
|
|
1005
|
-
}
|
|
1006
|
-
function isOptionalBoolean(value) {
|
|
1007
|
-
return value === void 0 || typeof value === "boolean";
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Recognize the deprecated options-first void-action proxy call.
|
|
1011
|
-
*
|
|
1012
|
-
* Every supplied field is validated so ordinary payloads that merely overlap
|
|
1013
|
-
* one option name are not silently reinterpreted as dispatch options.
|
|
1014
|
-
*/
|
|
1015
|
-
function isDispatchOptions(value) {
|
|
1016
|
-
if (!isRecord(value)) return false;
|
|
1017
|
-
const keys = Object.keys(value);
|
|
1018
|
-
if (keys.length === 0 || keys.some((key) => !dispatchOptionKeys.has(key))) return false;
|
|
1019
|
-
return keys.every((key) => {
|
|
1020
|
-
const optionValue = value[key];
|
|
1021
|
-
switch (key) {
|
|
1022
|
-
case "debounce":
|
|
1023
|
-
case "queuePriority":
|
|
1024
|
-
case "throttle":
|
|
1025
|
-
case "timeout": return isOptionalNumber(optionValue);
|
|
1026
|
-
case "immediate": return isOptionalBoolean(optionValue);
|
|
1027
|
-
case "executionMode": return optionValue === void 0 || optionValue === "sequential" || optionValue === "parallel" || optionValue === "race";
|
|
1028
|
-
case "signal": return optionValue === void 0 || isRecord(optionValue) && typeof optionValue.aborted === "boolean" && typeof optionValue.addEventListener === "function";
|
|
1029
|
-
case "retryOnError": return optionValue === void 0 || isRecord(optionValue) && typeof optionValue.maxAttempts === "number" && typeof optionValue.delay === "number";
|
|
1030
|
-
case "autoAbort": return optionValue === void 0 || isRecord(optionValue) && typeof optionValue.enabled === "boolean" && isOptionalBoolean(optionValue.allowHandlerAbort) && (optionValue.onControllerCreated === void 0 || typeof optionValue.onControllerCreated === "function");
|
|
1031
|
-
case "filter": return optionValue === void 0 || isRecord(optionValue) && (optionValue.handlerIds === void 0 || Array.isArray(optionValue.handlerIds) && optionValue.handlerIds.every((item) => typeof item === "string")) && (optionValue.excludeHandlerIds === void 0 || Array.isArray(optionValue.excludeHandlerIds) && optionValue.excludeHandlerIds.every((item) => typeof item === "string")) && (optionValue.priority === void 0 || isRecord(optionValue.priority)) && (optionValue.custom === void 0 || typeof optionValue.custom === "function");
|
|
1032
|
-
case "result": return optionValue === void 0 || isRecord(optionValue) && (optionValue.strategy === void 0 || optionValue.strategy === "first" || optionValue.strategy === "last" || optionValue.strategy === "all" || optionValue.strategy === "merge" || optionValue.strategy === "custom") && (optionValue.merger === void 0 || typeof optionValue.merger === "function") && isOptionalBoolean(optionValue.collect) && isOptionalNumber(optionValue.maxResults) && isOptionalBoolean(optionValue.includeErrors);
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
986
|
/**
|
|
1037
987
|
* Action Register for managing action handlers with priority-based execution
|
|
1038
988
|
*
|
|
@@ -1055,10 +1005,8 @@ var ActionRegister = class {
|
|
|
1055
1005
|
this.actionExecutionModes = /* @__PURE__ */ new Map();
|
|
1056
1006
|
this.unregisterFunctions = /* @__PURE__ */ new Map();
|
|
1057
1007
|
this.lastRegisteredTimestamps = /* @__PURE__ */ new Map();
|
|
1058
|
-
this.filterCacheDisabled = true;
|
|
1059
1008
|
this.handlerIdCounter = 0;
|
|
1060
1009
|
this.controllerPool = [];
|
|
1061
|
-
this.maxControllerPoolSize = 10;
|
|
1062
1010
|
this.lifecycleState = "active";
|
|
1063
1011
|
this.lifecycleController = new AbortController();
|
|
1064
1012
|
this.activeDispatches = /* @__PURE__ */ new Set();
|
|
@@ -1096,7 +1044,6 @@ var ActionRegister = class {
|
|
|
1096
1044
|
* // Function-based dispatching
|
|
1097
1045
|
* await registry.actions.userLogin({ userId: '123', email: 'test@example.com' });
|
|
1098
1046
|
* await registry.actions.resetApp();
|
|
1099
|
-
* await registry.actions.resetApp({ debounce: 100 }); // Legacy options-first form
|
|
1100
1047
|
* await registry.actions.resetApp(undefined, { debounce: 100 });
|
|
1101
1048
|
* ```
|
|
1102
1049
|
*
|
|
@@ -1105,9 +1052,8 @@ var ActionRegister = class {
|
|
|
1105
1052
|
get actions() {
|
|
1106
1053
|
if (!this._actionsProxy) this._actionsProxy = new Proxy({}, { get: (_target, prop) => {
|
|
1107
1054
|
const actionKey = prop;
|
|
1108
|
-
if (typeof prop === "string" && this.pipelines.has(actionKey)) return (
|
|
1109
|
-
|
|
1110
|
-
return this.dispatch(actionKey, payloadOrOptions, options);
|
|
1055
|
+
if (typeof prop === "string" && this.pipelines.has(actionKey)) return (payload, options) => {
|
|
1056
|
+
return this.dispatch(actionKey, payload, options);
|
|
1111
1057
|
};
|
|
1112
1058
|
} });
|
|
1113
1059
|
return this._actionsProxy;
|
|
@@ -1142,9 +1088,8 @@ var ActionRegister = class {
|
|
|
1142
1088
|
get actionsWithResult() {
|
|
1143
1089
|
if (!this._actionsWithResultProxy) this._actionsWithResultProxy = new Proxy({}, { get: (_target, prop) => {
|
|
1144
1090
|
const actionKey = prop;
|
|
1145
|
-
if (typeof prop === "string" && this.pipelines.has(actionKey)) return (
|
|
1146
|
-
|
|
1147
|
-
return this.dispatchWithResult(actionKey, payloadOrOptions, options);
|
|
1091
|
+
if (typeof prop === "string" && this.pipelines.has(actionKey)) return (payload, options) => {
|
|
1092
|
+
return this.dispatchWithResult(actionKey, payload, options);
|
|
1148
1093
|
};
|
|
1149
1094
|
} });
|
|
1150
1095
|
return this._actionsWithResultProxy;
|
|
@@ -1277,7 +1222,7 @@ var ActionRegister = class {
|
|
|
1277
1222
|
const existing = pipeline[existingIndex];
|
|
1278
1223
|
const existingUnregister = this.unregisterFunctions.get(handlerId);
|
|
1279
1224
|
if (registration.config.replaceExisting) {
|
|
1280
|
-
if (existing
|
|
1225
|
+
if (existing?.config.cleanup && typeof existing.config.cleanup === "function") try {
|
|
1281
1226
|
existing.config.cleanup();
|
|
1282
1227
|
} catch (cleanupError) {
|
|
1283
1228
|
this.log(`Cleanup error for replaced handler: ${String(action)}`, cleanupError, "warn");
|
|
@@ -1944,21 +1889,6 @@ var ActionRegister = class {
|
|
|
1944
1889
|
return null;
|
|
1945
1890
|
}
|
|
1946
1891
|
/**
|
|
1947
|
-
* 🔧 Generate optimized cache key for filter options
|
|
1948
|
-
*/
|
|
1949
|
-
generateFilterCacheKey(filterOptions) {
|
|
1950
|
-
if (!filterOptions) return "no-filter";
|
|
1951
|
-
const parts = [];
|
|
1952
|
-
if (filterOptions.handlerIds?.length) parts.push(`h:${filterOptions.handlerIds.slice().sort().join(",")}`);
|
|
1953
|
-
if (filterOptions.excludeHandlerIds?.length) parts.push(`e:${filterOptions.excludeHandlerIds.slice().sort().join(",")}`);
|
|
1954
|
-
if (filterOptions.priority) {
|
|
1955
|
-
const { min, max } = filterOptions.priority;
|
|
1956
|
-
if (min !== void 0 || max !== void 0) parts.push(`p:${min ?? "*"}-${max ?? "*"}`);
|
|
1957
|
-
}
|
|
1958
|
-
if (filterOptions.custom) return "custom-" + Date.now() + Math.random();
|
|
1959
|
-
return parts.length > 0 ? parts.join("|") : "no-filter";
|
|
1960
|
-
}
|
|
1961
|
-
/**
|
|
1962
1892
|
* 🔧 Create or reuse PipelineController from pool for better performance
|
|
1963
1893
|
*/
|
|
1964
1894
|
getControllerFromPool(context, autoAbortController, autoAbortOptions) {
|
|
@@ -1998,12 +1928,6 @@ var ActionRegister = class {
|
|
|
1998
1928
|
};
|
|
1999
1929
|
return controller;
|
|
2000
1930
|
}
|
|
2001
|
-
/**
|
|
2002
|
-
* 🔧 Return controller to pool for reuse
|
|
2003
|
-
*/
|
|
2004
|
-
returnControllerToPool(controller) {
|
|
2005
|
-
if (this.controllerPool.length < this.maxControllerPoolSize) this.controllerPool.push(controller);
|
|
2006
|
-
}
|
|
2007
1931
|
filterHandlers(handlers, filterOptions) {
|
|
2008
1932
|
if (!filterOptions) return handlers;
|
|
2009
1933
|
const handlerIdSet = filterOptions.handlerIds ? new Set(filterOptions.handlerIds) : null;
|
|
@@ -2011,7 +1935,7 @@ var ActionRegister = class {
|
|
|
2011
1935
|
return handlers.filter((registration) => {
|
|
2012
1936
|
const config = registration.config;
|
|
2013
1937
|
if (handlerIdSet && !handlerIdSet.has(config.id)) return false;
|
|
2014
|
-
if (excludeIdSet
|
|
1938
|
+
if (excludeIdSet?.has(config.id)) return false;
|
|
2015
1939
|
if (filterOptions.priority) {
|
|
2016
1940
|
const priority = config.priority;
|
|
2017
1941
|
if (filterOptions.priority.min !== void 0 && priority < filterOptions.priority.min) return false;
|
|
@@ -2294,7 +2218,7 @@ var ActionRegister = class {
|
|
|
2294
2218
|
removeRegistration(action, registration, runCleanup = true) {
|
|
2295
2219
|
const pipeline = this.pipelines.get(action);
|
|
2296
2220
|
if (!pipeline) return false;
|
|
2297
|
-
const index = pipeline.
|
|
2221
|
+
const index = pipeline.indexOf(registration);
|
|
2298
2222
|
if (index === -1) return false;
|
|
2299
2223
|
pipeline.splice(index, 1);
|
|
2300
2224
|
this.unregisterFunctions.delete(registration.id);
|
|
@@ -2587,7 +2511,7 @@ var ReactActionError = class ReactActionError extends Error {
|
|
|
2587
2511
|
this.payload = payload;
|
|
2588
2512
|
this.handlerId = handlerId;
|
|
2589
2513
|
this.timestamp = Date.now();
|
|
2590
|
-
if (originalError
|
|
2514
|
+
if (originalError?.stack) this.stack = originalError.stack;
|
|
2591
2515
|
}
|
|
2592
2516
|
/**
|
|
2593
2517
|
* Create a React Error Boundary compatible error
|
|
@@ -2607,140 +2531,5 @@ function isReactActionError(error) {
|
|
|
2607
2531
|
}
|
|
2608
2532
|
|
|
2609
2533
|
//#endregion
|
|
2610
|
-
|
|
2611
|
-
/**
|
|
2612
|
-
* Zod 스키마를 JSON Schema로 변환 (Zod 4 네이티브 API)
|
|
2613
|
-
*
|
|
2614
|
-
* @param schema - Zod 스키마
|
|
2615
|
-
* @returns JSON Schema (draft-7)
|
|
2616
|
-
*/
|
|
2617
|
-
function zodToJsonSchema(schema, zodModule) {
|
|
2618
|
-
return zodModule.toJSONSchema(schema, {
|
|
2619
|
-
target: "draft-7",
|
|
2620
|
-
metadata: zodModule.globalRegistry
|
|
2621
|
-
});
|
|
2622
|
-
}
|
|
2623
|
-
/**
|
|
2624
|
-
* Zod 스키마 기반 Action 정의
|
|
2625
|
-
*
|
|
2626
|
-
* defineTool 패턴을 기반으로 context-action에 맞게 구현:
|
|
2627
|
-
* - Single Source of Truth: Zod 스키마로 타입 + 검증 + 메타데이터 통합
|
|
2628
|
-
* - 런타임 검증: validate(), safeParse()
|
|
2629
|
-
* - Tool Chain 호환: toMCP(), toOpenAI(), toAnthropic()
|
|
2630
|
-
*
|
|
2631
|
-
* @param options - Action 정의 옵션
|
|
2632
|
-
* @param zodModule - Zod 모듈 (peerDependency로 주입)
|
|
2633
|
-
* @returns UnifiedAction 인스턴스
|
|
2634
|
-
*
|
|
2635
|
-
* @example
|
|
2636
|
-
* ```typescript
|
|
2637
|
-
* import { z } from 'zod';
|
|
2638
|
-
* import { defineAction } from '@context-action/core';
|
|
2639
|
-
*
|
|
2640
|
-
* const updateUserAction = defineAction({
|
|
2641
|
-
* name: 'updateUser',
|
|
2642
|
-
* description: 'Update user profile',
|
|
2643
|
-
* parameters: z.object({
|
|
2644
|
-
* id: z.string().min(1).meta({ description: 'User ID' }),
|
|
2645
|
-
* name: z.string().min(2).max(50).meta({ description: 'User name' }),
|
|
2646
|
-
* email: z.string().email().optional(),
|
|
2647
|
-
* }),
|
|
2648
|
-
* }, z);
|
|
2649
|
-
*
|
|
2650
|
-
* // 검증
|
|
2651
|
-
* const validated = updateUserAction.validate({ id: '123', name: 'John' });
|
|
2652
|
-
*
|
|
2653
|
-
* // Tool chain 변환
|
|
2654
|
-
* const mcpTool = updateUserAction.toMCP();
|
|
2655
|
-
* ```
|
|
2656
|
-
*/
|
|
2657
|
-
function defineAction(options, zodModule) {
|
|
2658
|
-
const { name, description, parameters } = options;
|
|
2659
|
-
const jsonSchema = zodToJsonSchema(parameters, zodModule);
|
|
2660
|
-
return {
|
|
2661
|
-
name,
|
|
2662
|
-
description,
|
|
2663
|
-
zodSchema: parameters,
|
|
2664
|
-
jsonSchema,
|
|
2665
|
-
validate: (payload) => {
|
|
2666
|
-
return parameters.parse(payload);
|
|
2667
|
-
},
|
|
2668
|
-
safeParse: (payload) => {
|
|
2669
|
-
return parameters.safeParse(payload);
|
|
2670
|
-
},
|
|
2671
|
-
toJSONSchema: () => jsonSchema,
|
|
2672
|
-
toMCP: () => ({
|
|
2673
|
-
name,
|
|
2674
|
-
description,
|
|
2675
|
-
inputSchema: jsonSchema
|
|
2676
|
-
}),
|
|
2677
|
-
toOpenAI: () => ({
|
|
2678
|
-
type: "function",
|
|
2679
|
-
function: {
|
|
2680
|
-
name,
|
|
2681
|
-
description,
|
|
2682
|
-
parameters: {
|
|
2683
|
-
type: "object",
|
|
2684
|
-
properties: jsonSchema.properties ?? {},
|
|
2685
|
-
required: jsonSchema.required
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
}),
|
|
2689
|
-
toAnthropic: () => ({
|
|
2690
|
-
name,
|
|
2691
|
-
description,
|
|
2692
|
-
input_schema: jsonSchema
|
|
2693
|
-
})
|
|
2694
|
-
};
|
|
2695
|
-
}
|
|
2696
|
-
/**
|
|
2697
|
-
* 다중 Action 스키마 생성
|
|
2698
|
-
*
|
|
2699
|
-
* 여러 defineAction을 묶어서 ActionSchemaMap 생성
|
|
2700
|
-
*
|
|
2701
|
-
* @param actions - UnifiedAction 맵
|
|
2702
|
-
* @returns ActionSchemaMap
|
|
2703
|
-
*
|
|
2704
|
-
* @example
|
|
2705
|
-
* ```typescript
|
|
2706
|
-
* const userActionSchema = createActionSchema({
|
|
2707
|
-
* updateUser: defineAction({ ... }, z),
|
|
2708
|
-
* deleteUser: defineAction({ ... }, z),
|
|
2709
|
-
* });
|
|
2710
|
-
*
|
|
2711
|
-
* type UserActions = InferActionPayloadMap<typeof userActionSchema>;
|
|
2712
|
-
* ```
|
|
2713
|
-
*/
|
|
2714
|
-
function createActionSchema(actions) {
|
|
2715
|
-
return actions;
|
|
2716
|
-
}
|
|
2717
|
-
/**
|
|
2718
|
-
* Zod 모듈을 바인딩한 defineAction 팩토리 생성
|
|
2719
|
-
*
|
|
2720
|
-
* 매번 z 모듈을 전달하지 않아도 되도록 팩토리 패턴 제공
|
|
2721
|
-
*
|
|
2722
|
-
* @param zodModule - Zod 모듈
|
|
2723
|
-
* @returns defineAction 함수 (z 바인딩됨)
|
|
2724
|
-
*
|
|
2725
|
-
* @example
|
|
2726
|
-
* ```typescript
|
|
2727
|
-
* import { z } from 'zod';
|
|
2728
|
-
* import { createActionFactory } from '@context-action/core';
|
|
2729
|
-
*
|
|
2730
|
-
* const defineAction = createActionFactory(z);
|
|
2731
|
-
*
|
|
2732
|
-
* const updateUser = defineAction({
|
|
2733
|
-
* name: 'updateUser',
|
|
2734
|
-
* parameters: z.object({ id: z.string() }),
|
|
2735
|
-
* });
|
|
2736
|
-
* ```
|
|
2737
|
-
*/
|
|
2738
|
-
function createActionFactory(zodModule) {
|
|
2739
|
-
return (options) => {
|
|
2740
|
-
return defineAction(options, zodModule);
|
|
2741
|
-
};
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
//#endregion
|
|
2745
|
-
export { ActionGuard, ActionRegister, ActionRegisterDestroyedError, ActionTimeoutError, ActionValidationError, ReactActionError, ReactDevUtils, createActionFactory, createActionHandler, createActionSchema, defineAction, executeParallel, executeRace, executeSequential, isActionRegisterDestroyedError, isActionTimeoutError, isActionValidationError, isReactActionError, zodToJsonSchema };
|
|
2534
|
+
export { ActionGuard, ActionRegister, ActionRegisterDestroyedError, ActionTimeoutError, ActionValidationError, ReactActionError, ReactDevUtils, createActionHandler, executeParallel, executeRace, executeSequential, isActionRegisterDestroyedError, isActionTimeoutError, isActionValidationError, isReactActionError };
|
|
2746
2535
|
//# sourceMappingURL=index.js.map
|