@holokai/sdk 0.1.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/LICENSE +21 -0
- package/README.md +396 -0
- package/dist/core/api/base.controller.d.ts +8 -0
- package/dist/core/api/base.controller.d.ts.map +1 -0
- package/dist/core/api/base.controller.js +41 -0
- package/dist/core/api/base.controller.js.map +1 -0
- package/dist/core/api/index.d.ts +3 -0
- package/dist/core/api/index.d.ts.map +1 -0
- package/dist/core/api/index.js +3 -0
- package/dist/core/api/index.js.map +1 -0
- package/dist/core/api/types.d.ts +19 -0
- package/dist/core/api/types.d.ts.map +1 -0
- package/dist/core/api/types.js +2 -0
- package/dist/core/api/types.js.map +1 -0
- package/dist/core/entities/analysisResult.d.ts +8 -0
- package/dist/core/entities/analysisResult.d.ts.map +1 -0
- package/dist/core/entities/analysisResult.js +2 -0
- package/dist/core/entities/analysisResult.js.map +1 -0
- package/dist/core/entities/application.d.ts +12 -0
- package/dist/core/entities/application.d.ts.map +1 -0
- package/dist/core/entities/application.js +2 -0
- package/dist/core/entities/application.js.map +1 -0
- package/dist/core/entities/base.d.ts +8 -0
- package/dist/core/entities/base.d.ts.map +1 -0
- package/dist/core/entities/base.js +2 -0
- package/dist/core/entities/base.js.map +1 -0
- package/dist/core/entities/evaluator.d.ts +13 -0
- package/dist/core/entities/evaluator.d.ts.map +1 -0
- package/dist/core/entities/evaluator.data.d.ts +9 -0
- package/dist/core/entities/evaluator.data.d.ts.map +1 -0
- package/dist/core/entities/evaluator.data.js +2 -0
- package/dist/core/entities/evaluator.data.js.map +1 -0
- package/dist/core/entities/evaluator.js +2 -0
- package/dist/core/entities/evaluator.js.map +1 -0
- package/dist/core/entities/index.d.ts +11 -0
- package/dist/core/entities/index.d.ts.map +1 -0
- package/dist/core/entities/index.js +3 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/llm.request.d.ts +19 -0
- package/dist/core/entities/llm.request.d.ts.map +1 -0
- package/dist/core/entities/llm.request.js +2 -0
- package/dist/core/entities/llm.request.js.map +1 -0
- package/dist/core/entities/llm.response.d.ts +24 -0
- package/dist/core/entities/llm.response.d.ts.map +1 -0
- package/dist/core/entities/llm.response.js +3 -0
- package/dist/core/entities/llm.response.js.map +1 -0
- package/dist/core/entities/llm.status.d.ts +9 -0
- package/dist/core/entities/llm.status.d.ts.map +1 -0
- package/dist/core/entities/llm.status.js +11 -0
- package/dist/core/entities/llm.status.js.map +1 -0
- package/dist/core/entities/model.d.ts +14 -0
- package/dist/core/entities/model.d.ts.map +1 -0
- package/dist/core/entities/model.js +2 -0
- package/dist/core/entities/model.js.map +1 -0
- package/dist/core/entities/provider.d.ts +12 -0
- package/dist/core/entities/provider.d.ts.map +1 -0
- package/dist/core/entities/provider.js +2 -0
- package/dist/core/entities/provider.js.map +1 -0
- package/dist/core/id/index.d.ts +2 -0
- package/dist/core/id/index.d.ts.map +1 -0
- package/dist/core/id/index.js +13 -0
- package/dist/core/id/index.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger/holo-logger-factory.d.ts +6 -0
- package/dist/core/logger/holo-logger-factory.d.ts.map +1 -0
- package/dist/core/logger/holo-logger-factory.js +16 -0
- package/dist/core/logger/holo-logger-factory.js.map +1 -0
- package/dist/core/logger/index.d.ts +4 -0
- package/dist/core/logger/index.d.ts.map +1 -0
- package/dist/core/logger/index.js +4 -0
- package/dist/core/logger/index.js.map +1 -0
- package/dist/core/logger/logger.d.ts +24 -0
- package/dist/core/logger/logger.d.ts.map +1 -0
- package/dist/core/logger/logger.js +16 -0
- package/dist/core/logger/logger.js.map +1 -0
- package/dist/core/logger/mixin.d.ts +29 -0
- package/dist/core/logger/mixin.d.ts.map +1 -0
- package/dist/core/logger/mixin.js +29 -0
- package/dist/core/logger/mixin.js.map +1 -0
- package/dist/core/mixins/constructor.d.ts +2 -0
- package/dist/core/mixins/constructor.d.ts.map +1 -0
- package/dist/core/mixins/constructor.js +2 -0
- package/dist/core/mixins/constructor.js.map +1 -0
- package/dist/core/mixins/index.d.ts +2 -0
- package/dist/core/mixins/index.d.ts.map +1 -0
- package/dist/core/mixins/index.js +2 -0
- package/dist/core/mixins/index.js.map +1 -0
- package/dist/core/parsers/find-last.d.ts +3 -0
- package/dist/core/parsers/find-last.d.ts.map +1 -0
- package/dist/core/parsers/find-last.js +22 -0
- package/dist/core/parsers/find-last.js.map +1 -0
- package/dist/core/parsers/index.d.ts +6 -0
- package/dist/core/parsers/index.d.ts.map +1 -0
- package/dist/core/parsers/index.js +6 -0
- package/dist/core/parsers/index.js.map +1 -0
- package/dist/core/parsers/parsers.d.ts +6 -0
- package/dist/core/parsers/parsers.d.ts.map +1 -0
- package/dist/core/parsers/parsers.js +32 -0
- package/dist/core/parsers/parsers.js.map +1 -0
- package/dist/core/parsers/pick-defined.d.ts +2 -0
- package/dist/core/parsers/pick-defined.d.ts.map +1 -0
- package/dist/core/parsers/pick-defined.js +4 -0
- package/dist/core/parsers/pick-defined.js.map +1 -0
- package/dist/core/parsers/pick-headers.d.ts +3 -0
- package/dist/core/parsers/pick-headers.d.ts.map +1 -0
- package/dist/core/parsers/pick-headers.js +41 -0
- package/dist/core/parsers/pick-headers.js.map +1 -0
- package/dist/core/parsers/safe-parse.d.ts +2 -0
- package/dist/core/parsers/safe-parse.d.ts.map +1 -0
- package/dist/core/parsers/safe-parse.js +12 -0
- package/dist/core/parsers/safe-parse.js.map +1 -0
- package/dist/core/routes.d.ts +19 -0
- package/dist/core/routes.d.ts.map +1 -0
- package/dist/core/routes.js +8 -0
- package/dist/core/routes.js.map +1 -0
- package/dist/core/worker/envelopes.d.ts +27 -0
- package/dist/core/worker/envelopes.d.ts.map +1 -0
- package/dist/core/worker/envelopes.js +2 -0
- package/dist/core/worker/envelopes.js.map +1 -0
- package/dist/core/worker/index.d.ts +5 -0
- package/dist/core/worker/index.d.ts.map +1 -0
- package/dist/core/worker/index.js +5 -0
- package/dist/core/worker/index.js.map +1 -0
- package/dist/core/worker/prompt.d.ts +9 -0
- package/dist/core/worker/prompt.d.ts.map +1 -0
- package/dist/core/worker/prompt.js +2 -0
- package/dist/core/worker/prompt.js.map +1 -0
- package/dist/core/worker/request.d.ts +33 -0
- package/dist/core/worker/request.d.ts.map +1 -0
- package/dist/core/worker/request.js +2 -0
- package/dist/core/worker/request.js.map +1 -0
- package/dist/core/worker/response.d.ts +18 -0
- package/dist/core/worker/response.d.ts.map +1 -0
- package/dist/core/worker/response.js +2 -0
- package/dist/core/worker/response.js.map +1 -0
- package/dist/holo/content.d.ts +14 -0
- package/dist/holo/content.d.ts.map +1 -0
- package/dist/holo/content.js +7 -0
- package/dist/holo/content.js.map +1 -0
- package/dist/holo/factories/index.d.ts +3 -0
- package/dist/holo/factories/index.d.ts.map +1 -0
- package/dist/holo/factories/index.js +3 -0
- package/dist/holo/factories/index.js.map +1 -0
- package/dist/holo/factories/request-factory.d.ts +3 -0
- package/dist/holo/factories/request-factory.d.ts.map +1 -0
- package/dist/holo/factories/request-factory.js +8 -0
- package/dist/holo/factories/request-factory.js.map +1 -0
- package/dist/holo/factories/response-factory.d.ts +7 -0
- package/dist/holo/factories/response-factory.d.ts.map +1 -0
- package/dist/holo/factories/response-factory.js +64 -0
- package/dist/holo/factories/response-factory.js.map +1 -0
- package/dist/holo/index.d.ts +17 -0
- package/dist/holo/index.d.ts.map +1 -0
- package/dist/holo/index.js +19 -0
- package/dist/holo/index.js.map +1 -0
- package/dist/holo/messages.d.ts +10 -0
- package/dist/holo/messages.d.ts.map +1 -0
- package/dist/holo/messages.js +2 -0
- package/dist/holo/messages.js.map +1 -0
- package/dist/holo/requests.d.ts +32 -0
- package/dist/holo/requests.d.ts.map +1 -0
- package/dist/holo/requests.js +7 -0
- package/dist/holo/requests.js.map +1 -0
- package/dist/holo/responses.d.ts +57 -0
- package/dist/holo/responses.d.ts.map +1 -0
- package/dist/holo/responses.js +2 -0
- package/dist/holo/responses.js.map +1 -0
- package/dist/holo/tools.d.ts +25 -0
- package/dist/holo/tools.d.ts.map +1 -0
- package/dist/holo/tools.js +2 -0
- package/dist/holo/tools.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/base.d.ts +109 -0
- package/dist/plugin/base.d.ts.map +1 -0
- package/dist/plugin/base.js +131 -0
- package/dist/plugin/base.js.map +1 -0
- package/dist/plugin/context.d.ts +21 -0
- package/dist/plugin/context.d.ts.map +1 -0
- package/dist/plugin/context.js +2 -0
- package/dist/plugin/context.js.map +1 -0
- package/dist/plugin/errors.d.ts +24 -0
- package/dist/plugin/errors.d.ts.map +1 -0
- package/dist/plugin/errors.js +31 -0
- package/dist/plugin/errors.js.map +1 -0
- package/dist/plugin/evaluator.d.ts +243 -0
- package/dist/plugin/evaluator.d.ts.map +1 -0
- package/dist/plugin/evaluator.js +2 -0
- package/dist/plugin/evaluator.js.map +1 -0
- package/dist/plugin/guard.d.ts +307 -0
- package/dist/plugin/guard.d.ts.map +1 -0
- package/dist/plugin/guard.js +46 -0
- package/dist/plugin/guard.js.map +1 -0
- package/dist/plugin/index.d.ts +14 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +14 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/manifest.d.ts +349 -0
- package/dist/plugin/manifest.d.ts.map +1 -0
- package/dist/plugin/manifest.js +6 -0
- package/dist/plugin/manifest.js.map +1 -0
- package/dist/plugin/provider.d.ts +55 -0
- package/dist/plugin/provider.d.ts.map +1 -0
- package/dist/plugin/provider.js +2 -0
- package/dist/plugin/provider.js.map +1 -0
- package/dist/plugin/registry.d.ts +7 -0
- package/dist/plugin/registry.d.ts.map +1 -0
- package/dist/plugin/registry.js +2 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/provider/auditor/base.d.ts +21 -0
- package/dist/provider/auditor/base.d.ts.map +1 -0
- package/dist/provider/auditor/base.js +58 -0
- package/dist/provider/auditor/base.js.map +1 -0
- package/dist/provider/auditor/index.d.ts +2 -0
- package/dist/provider/auditor/index.d.ts.map +1 -0
- package/dist/provider/auditor/index.js +2 -0
- package/dist/provider/auditor/index.js.map +1 -0
- package/dist/provider/base.d.ts +39 -0
- package/dist/provider/base.d.ts.map +1 -0
- package/dist/provider/base.js +169 -0
- package/dist/provider/base.js.map +1 -0
- package/dist/provider/index.d.ts +6 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +6 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/translator/base.d.ts +32 -0
- package/dist/provider/translator/base.d.ts.map +1 -0
- package/dist/provider/translator/base.js +33 -0
- package/dist/provider/translator/base.js.map +1 -0
- package/dist/provider/translator/index.d.ts +3 -0
- package/dist/provider/translator/index.d.ts.map +1 -0
- package/dist/provider/translator/index.js +3 -0
- package/dist/provider/translator/index.js.map +1 -0
- package/dist/provider/translator/stream.d.ts +24 -0
- package/dist/provider/translator/stream.d.ts.map +1 -0
- package/dist/provider/translator/stream.js +50 -0
- package/dist/provider/translator/stream.js.map +1 -0
- package/dist/provider/types.d.ts +107 -0
- package/dist/provider/types.d.ts.map +1 -0
- package/dist/provider/types.js +38 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/provider/wire/base.d.ts +50 -0
- package/dist/provider/wire/base.d.ts.map +1 -0
- package/dist/provider/wire/base.js +99 -0
- package/dist/provider/wire/base.js.map +1 -0
- package/dist/provider/wire/index.d.ts +2 -0
- package/dist/provider/wire/index.d.ts.map +1 -0
- package/dist/provider/wire/index.js +2 -0
- package/dist/provider/wire/index.js.map +1 -0
- package/package.json +97 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { PluginManifest } from "./manifest";
|
|
2
|
+
import { PluginContext } from "./context";
|
|
3
|
+
import { ClassLogger } from "../core";
|
|
4
|
+
export declare enum PluginState {
|
|
5
|
+
UNINITIALIZED = "uninitialized",
|
|
6
|
+
INITIALIZING = "initializing",
|
|
7
|
+
READY = "ready",
|
|
8
|
+
ERROR = "error",
|
|
9
|
+
DESTROYING = "destroying",
|
|
10
|
+
DESTROYED = "destroyed"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Base plugin interface that all plugin types must implement
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* class MyPlugin implements IPlugin {
|
|
18
|
+
* manifest = {
|
|
19
|
+
* name: '@myorg/my-plugin',
|
|
20
|
+
* version: '1.0.0',
|
|
21
|
+
* pluginType: 'provider' as const
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* async initialize(context: PluginContext): Promise<void> {
|
|
25
|
+
* // Setup plugin resources
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* async destroy(): Promise<void> {
|
|
29
|
+
* // Cleanup resources
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface IPlugin {
|
|
35
|
+
/** Plugin metadata and configuration */
|
|
36
|
+
readonly manifest: PluginManifest;
|
|
37
|
+
/** Current plugin state */
|
|
38
|
+
readonly state: PluginState;
|
|
39
|
+
readonly family: string;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the plugin with provided context
|
|
42
|
+
* @param context Runtime context including logger, config, and environment
|
|
43
|
+
* @throws {PluginError} If initialization fails
|
|
44
|
+
*/
|
|
45
|
+
initialize(context: PluginContext): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Destroy the plugin and cleanup resources
|
|
48
|
+
* @throws {PluginError} If cleanup fails
|
|
49
|
+
*/
|
|
50
|
+
destroy(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get current plugin state
|
|
53
|
+
* @returns Current state of the plugin
|
|
54
|
+
*/
|
|
55
|
+
getState(): PluginState;
|
|
56
|
+
/**
|
|
57
|
+
* Perform health check on the plugin
|
|
58
|
+
* @returns Health status and diagnostic information
|
|
59
|
+
*/
|
|
60
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Health check result for plugin status monitoring
|
|
64
|
+
*/
|
|
65
|
+
export interface HealthCheckResult {
|
|
66
|
+
healthy: boolean;
|
|
67
|
+
message?: string;
|
|
68
|
+
details?: Record<string, unknown>;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Base abstract class implementing common plugin functionality.
|
|
73
|
+
*
|
|
74
|
+
* Lifecycle:
|
|
75
|
+
* UNINITIALIZED → INITIALIZING → READY → DESTROYING → DESTROYED
|
|
76
|
+
* Any failure moves the plugin to ERROR.
|
|
77
|
+
*/
|
|
78
|
+
export declare abstract class BasePlugin extends ClassLogger implements IPlugin {
|
|
79
|
+
/**
|
|
80
|
+
* Static manifest per-plugin implementation.
|
|
81
|
+
* Implementations SHOULD treat this as immutable metadata.
|
|
82
|
+
*/
|
|
83
|
+
abstract readonly manifest: PluginManifest;
|
|
84
|
+
private _context;
|
|
85
|
+
protected _state: PluginState;
|
|
86
|
+
/**
|
|
87
|
+
* Current plugin state (read-only from outside).
|
|
88
|
+
*/
|
|
89
|
+
get state(): PluginState;
|
|
90
|
+
/**
|
|
91
|
+
* Strongly typed access to the plugin context.
|
|
92
|
+
* Throws if accessed before initialize() or after destroy().
|
|
93
|
+
*/
|
|
94
|
+
protected get pluginContext(): PluginContext;
|
|
95
|
+
/**
|
|
96
|
+
* Backwards-compatible state accessor.
|
|
97
|
+
*/
|
|
98
|
+
getState(): PluginState;
|
|
99
|
+
initialize(context: PluginContext): Promise<void>;
|
|
100
|
+
destroy(): Promise<void>;
|
|
101
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
102
|
+
protected abstract onInitialize(context: PluginContext): Promise<void>;
|
|
103
|
+
protected abstract onDestroy(): Promise<void>;
|
|
104
|
+
protected onHealthCheck(): Promise<HealthCheckResult | void>;
|
|
105
|
+
get name(): string;
|
|
106
|
+
get family(): string;
|
|
107
|
+
get version(): string;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/plugin/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AAExC,OAAO,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGpC,oBAAY,WAAW;IACnB,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,KAAK,UAAU;IACf,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,SAAS,cAAc;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,OAAO;IACpB,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAElC,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;OAGG;IACH,QAAQ,IAAI,WAAW,CAAC;IAExB;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export var PluginState;
|
|
4
|
+
(function (PluginState) {
|
|
5
|
+
PluginState["UNINITIALIZED"] = "uninitialized";
|
|
6
|
+
PluginState["INITIALIZING"] = "initializing";
|
|
7
|
+
PluginState["READY"] = "ready";
|
|
8
|
+
PluginState["ERROR"] = "error";
|
|
9
|
+
PluginState["DESTROYING"] = "destroying";
|
|
10
|
+
PluginState["DESTROYED"] = "destroyed";
|
|
11
|
+
})(PluginState || (PluginState = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Base abstract class implementing common plugin functionality.
|
|
14
|
+
*
|
|
15
|
+
* Lifecycle:
|
|
16
|
+
* UNINITIALIZED → INITIALIZING → READY → DESTROYING → DESTROYED
|
|
17
|
+
* Any failure moves the plugin to ERROR.
|
|
18
|
+
*/
|
|
19
|
+
export class BasePlugin extends ClassLogger {
|
|
20
|
+
_context;
|
|
21
|
+
_state = PluginState.UNINITIALIZED;
|
|
22
|
+
/**
|
|
23
|
+
* Current plugin state (read-only from outside).
|
|
24
|
+
*/
|
|
25
|
+
get state() {
|
|
26
|
+
return this._state;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Strongly typed access to the plugin context.
|
|
30
|
+
* Throws if accessed before initialize() or after destroy().
|
|
31
|
+
*/
|
|
32
|
+
get pluginContext() {
|
|
33
|
+
if (!this._context) {
|
|
34
|
+
throw new PluginError('Plugin context is not available. Initialize the plugin first.', PluginErrorCode.INVALID_STATE, this.manifest.name);
|
|
35
|
+
}
|
|
36
|
+
return this._context;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Backwards-compatible state accessor.
|
|
40
|
+
*/
|
|
41
|
+
getState() {
|
|
42
|
+
return this._state;
|
|
43
|
+
}
|
|
44
|
+
async initialize(context) {
|
|
45
|
+
const logger = this.mlog(this.initialize);
|
|
46
|
+
if (this._state !== PluginState.UNINITIALIZED) {
|
|
47
|
+
throw new PluginError(`Cannot initialize plugin in state ${this._state}`, PluginErrorCode.INITIALIZATION_FAILED, this.manifest.name);
|
|
48
|
+
}
|
|
49
|
+
this._state = PluginState.INITIALIZING;
|
|
50
|
+
this._context = context;
|
|
51
|
+
try {
|
|
52
|
+
logger.debug('Initializing plugin');
|
|
53
|
+
await this.onInitialize(context);
|
|
54
|
+
this._state = PluginState.READY;
|
|
55
|
+
logger.info('Plugin initialized successfully');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this._state = PluginState.ERROR;
|
|
59
|
+
logger.error('Plugin initialization failed', { error });
|
|
60
|
+
throw new PluginError('Failed to initialize plugin', PluginErrorCode.INITIALIZATION_FAILED, this.manifest.name, error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async destroy() {
|
|
64
|
+
const logger = this.mlog(this.destroy);
|
|
65
|
+
if (this._state === PluginState.DESTROYED) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this._state === PluginState.UNINITIALIZED) {
|
|
69
|
+
this._state = PluginState.DESTROYED;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._state = PluginState.DESTROYING;
|
|
73
|
+
try {
|
|
74
|
+
logger.info('Destroying plugin');
|
|
75
|
+
await this.onDestroy();
|
|
76
|
+
this._state = PluginState.DESTROYED;
|
|
77
|
+
this._context = undefined;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this._state = PluginState.ERROR;
|
|
81
|
+
// Fall back to console if logger is gone
|
|
82
|
+
try {
|
|
83
|
+
logger.error('Plugin destruction failed', { error });
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
console.error(`[${this.manifest.name}] Plugin destruction failed`, error);
|
|
87
|
+
}
|
|
88
|
+
throw new PluginError('Failed to destroy plugin', PluginErrorCode.DESTRUCTION_FAILED, this.manifest.name, error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async healthCheck() {
|
|
92
|
+
const logger = this.mlog(this.healthCheck);
|
|
93
|
+
const timestamp = Date.now();
|
|
94
|
+
if (this._state !== PluginState.READY) {
|
|
95
|
+
return {
|
|
96
|
+
healthy: false,
|
|
97
|
+
message: `Plugin not ready (state: ${this._state})`,
|
|
98
|
+
timestamp
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const customCheck = await this.onHealthCheck();
|
|
103
|
+
return (customCheck ?? {
|
|
104
|
+
healthy: true,
|
|
105
|
+
timestamp
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
logger.warn('Health check failed', { error });
|
|
110
|
+
return {
|
|
111
|
+
healthy: false,
|
|
112
|
+
message: error instanceof Error ? error.message : 'Health check failed',
|
|
113
|
+
timestamp
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async onHealthCheck() {
|
|
118
|
+
// Default implementation: no-op (host treats as healthy if READY)
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
get name() {
|
|
122
|
+
return this.manifest.name;
|
|
123
|
+
}
|
|
124
|
+
get family() {
|
|
125
|
+
return this.manifest.family ?? this.manifest.name;
|
|
126
|
+
}
|
|
127
|
+
get version() {
|
|
128
|
+
return this.manifest.version;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/plugin/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGpC,MAAM,CAAN,IAAY,WAOX;AAPD,WAAY,WAAW;IACnB,8CAA+B,CAAA;IAC/B,4CAA6B,CAAA;IAC7B,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,wCAAyB,CAAA;IACzB,sCAAuB,CAAA;AAC3B,CAAC,EAPW,WAAW,KAAX,WAAW,QAOtB;AAqED;;;;;;GAMG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AC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HoloLogger } from "../core/logger/index";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime context provided to plugins
|
|
4
|
+
*/
|
|
5
|
+
export interface PluginContext {
|
|
6
|
+
/**
|
|
7
|
+
* Logger instance scoped to this plugin host.
|
|
8
|
+
* The host may already have plugin-specific bindings applied.
|
|
9
|
+
*/
|
|
10
|
+
logger: HoloLogger;
|
|
11
|
+
/**
|
|
12
|
+
* Optional factory to create per-plugin loggers.
|
|
13
|
+
* If provided, BasePlugin will prefer this over `logger`.
|
|
14
|
+
*/
|
|
15
|
+
loggerFactory?: (pluginName: string) => HoloLogger;
|
|
16
|
+
/** Plugin-specific configuration */
|
|
17
|
+
config?: unknown;
|
|
18
|
+
/** Environment variables */
|
|
19
|
+
env?: Record<string, string | undefined>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/plugin/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;;OAGG;IACH,MAAM,EAAE,UAAU,CAAC;IAEnB;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,UAAU,CAAC;IAEnD,oCAAoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,4BAA4B;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAE5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/plugin/context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin error class for consistent error handling
|
|
3
|
+
*/
|
|
4
|
+
export declare class PluginError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly plugin?: string | undefined;
|
|
7
|
+
readonly details?: unknown | undefined;
|
|
8
|
+
constructor(message: string, code: string, plugin?: string | undefined, details?: unknown | undefined);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Common plugin error codes
|
|
12
|
+
*/
|
|
13
|
+
export declare enum PluginErrorCode {
|
|
14
|
+
INITIALIZATION_FAILED = "PLUGIN_INIT_FAILED",
|
|
15
|
+
DESTRUCTION_FAILED = "PLUGIN_DESTROY_FAILED",
|
|
16
|
+
INVALID_CONFIG = "PLUGIN_INVALID_CONFIG",
|
|
17
|
+
DEPENDENCY_MISSING = "PLUGIN_DEPENDENCY_MISSING",
|
|
18
|
+
INCOMPATIBLE_VERSION = "PLUGIN_INCOMPATIBLE_VERSION",
|
|
19
|
+
PERMISSION_DENIED = "PLUGIN_PERMISSION_DENIED",
|
|
20
|
+
HEALTH_CHECK_FAILED = "PLUGIN_HEALTH_CHECK_FAILED",
|
|
21
|
+
INVALID_STATE = "PLUGIN_INVALID_STATE",
|
|
22
|
+
UNKNOWN_ERROR = "PLUGIN_UNKNOWN_ERROR"
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/plugin/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;aAGd,IAAI,EAAE,MAAM;aACZ,MAAM,CAAC,EAAE,MAAM;aACf,OAAO,CAAC,EAAE,OAAO;gBAHjC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,OAAO,CAAC,EAAE,OAAO,YAAA;CAKxC;AAED;;GAEG;AACH,oBAAY,eAAe;IACvB,qBAAqB,uBAAuB;IAC5C,kBAAkB,0BAA0B;IAC5C,cAAc,0BAA0B;IACxC,kBAAkB,8BAA8B;IAChD,oBAAoB,gCAAgC;IACpD,iBAAiB,6BAA6B;IAC9C,mBAAmB,+BAA+B;IAClD,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;CACzC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin error class for consistent error handling
|
|
3
|
+
*/
|
|
4
|
+
export class PluginError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
plugin;
|
|
7
|
+
details;
|
|
8
|
+
constructor(message, code, plugin, details) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.plugin = plugin;
|
|
12
|
+
this.details = details;
|
|
13
|
+
this.name = 'PluginError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Common plugin error codes
|
|
18
|
+
*/
|
|
19
|
+
export var PluginErrorCode;
|
|
20
|
+
(function (PluginErrorCode) {
|
|
21
|
+
PluginErrorCode["INITIALIZATION_FAILED"] = "PLUGIN_INIT_FAILED";
|
|
22
|
+
PluginErrorCode["DESTRUCTION_FAILED"] = "PLUGIN_DESTROY_FAILED";
|
|
23
|
+
PluginErrorCode["INVALID_CONFIG"] = "PLUGIN_INVALID_CONFIG";
|
|
24
|
+
PluginErrorCode["DEPENDENCY_MISSING"] = "PLUGIN_DEPENDENCY_MISSING";
|
|
25
|
+
PluginErrorCode["INCOMPATIBLE_VERSION"] = "PLUGIN_INCOMPATIBLE_VERSION";
|
|
26
|
+
PluginErrorCode["PERMISSION_DENIED"] = "PLUGIN_PERMISSION_DENIED";
|
|
27
|
+
PluginErrorCode["HEALTH_CHECK_FAILED"] = "PLUGIN_HEALTH_CHECK_FAILED";
|
|
28
|
+
PluginErrorCode["INVALID_STATE"] = "PLUGIN_INVALID_STATE";
|
|
29
|
+
PluginErrorCode["UNKNOWN_ERROR"] = "PLUGIN_UNKNOWN_ERROR";
|
|
30
|
+
})(PluginErrorCode || (PluginErrorCode = {}));
|
|
31
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/plugin/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGd;IACA;IACA;IAJpB,YACI,OAAe,EACC,IAAY,EACZ,MAAe,EACf,OAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAAU;QAGjC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC9B,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,eAUX;AAVD,WAAY,eAAe;IACvB,+DAA4C,CAAA;IAC5C,+DAA4C,CAAA;IAC5C,2DAAwC,CAAA;IACxC,mEAAgD,CAAA;IAChD,uEAAoD,CAAA;IACpD,iEAA8C,CAAA;IAC9C,qEAAkD,CAAA;IAClD,yDAAsC,CAAA;IACtC,yDAAsC,CAAA;AAC1C,CAAC,EAVW,eAAe,KAAf,eAAe,QAU1B"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { IPlugin } from "./base";
|
|
2
|
+
/**
|
|
3
|
+
* Types of evaluation metrics
|
|
4
|
+
*/
|
|
5
|
+
export interface EvaluationMetric {
|
|
6
|
+
/**
|
|
7
|
+
* Stable identifier used as the key in EvaluationResult.metrics.
|
|
8
|
+
* If omitted, `name` MUST be used as the key.
|
|
9
|
+
*/
|
|
10
|
+
id?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Human-readable metric name (may be shown in UIs, logs, etc.).
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* What this metric measures and how to interpret it.
|
|
17
|
+
*/
|
|
18
|
+
description: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional unit (e.g. "probability", "score", "%", "tokens").
|
|
21
|
+
*/
|
|
22
|
+
unit?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Expected numeric range for this metric.
|
|
25
|
+
*/
|
|
26
|
+
range?: {
|
|
27
|
+
min: number;
|
|
28
|
+
max: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of an evaluation
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Issue found during evaluation
|
|
36
|
+
*/
|
|
37
|
+
export interface EvaluationIssue {
|
|
38
|
+
category: string;
|
|
39
|
+
severity: 'low' | 'medium' | 'high';
|
|
40
|
+
description: string;
|
|
41
|
+
location?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Detailed evaluation breakdown
|
|
45
|
+
*/
|
|
46
|
+
export interface EvaluationDetails {
|
|
47
|
+
categoryScores?: Record<string, number>;
|
|
48
|
+
issues?: EvaluationIssue[];
|
|
49
|
+
suggestions?: string[];
|
|
50
|
+
rawOutput?: string;
|
|
51
|
+
evaluationMethod?: string;
|
|
52
|
+
confidence?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface EvaluationResult {
|
|
55
|
+
/**
|
|
56
|
+
* Optional overall score, typically an aggregate over metrics.
|
|
57
|
+
*/
|
|
58
|
+
score?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Indicates whether the evaluated output is considered acceptable
|
|
61
|
+
* according to the evaluator's criteria and configuration.
|
|
62
|
+
*/
|
|
63
|
+
passed: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Per-metric scores keyed by metric id (or name if id is not provided).
|
|
66
|
+
*/
|
|
67
|
+
metrics: Record<string, number>;
|
|
68
|
+
/**
|
|
69
|
+
* Optional human-readable feedback or explanation.
|
|
70
|
+
*/
|
|
71
|
+
feedback?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Additional evaluation details
|
|
74
|
+
*/
|
|
75
|
+
details?: {
|
|
76
|
+
/**
|
|
77
|
+
* Detailed breakdown by evaluation category
|
|
78
|
+
*/
|
|
79
|
+
categoryScores?: Record<string, number>;
|
|
80
|
+
/**
|
|
81
|
+
* Specific issues found during evaluation
|
|
82
|
+
*/
|
|
83
|
+
issues?: Array<{
|
|
84
|
+
category: string;
|
|
85
|
+
severity: 'low' | 'medium' | 'high';
|
|
86
|
+
description: string;
|
|
87
|
+
location?: string;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Suggestions for improvement
|
|
91
|
+
*/
|
|
92
|
+
suggestions?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Raw model output if using LLM-based evaluation
|
|
95
|
+
*/
|
|
96
|
+
rawOutput?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Evaluation model/method used
|
|
99
|
+
*/
|
|
100
|
+
evaluationMethod?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Confidence score for the evaluation
|
|
103
|
+
*/
|
|
104
|
+
confidence?: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Evaluation timestamp (ms since epoch).
|
|
108
|
+
*/
|
|
109
|
+
timestamp: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Model-based evaluation settings
|
|
113
|
+
*/
|
|
114
|
+
export interface ModelEvaluation {
|
|
115
|
+
/**
|
|
116
|
+
* Model to use for evaluation
|
|
117
|
+
*/
|
|
118
|
+
model: string;
|
|
119
|
+
/**
|
|
120
|
+
* Temperature for model sampling
|
|
121
|
+
*/
|
|
122
|
+
temperature?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Custom evaluation prompt template
|
|
125
|
+
*/
|
|
126
|
+
promptTemplate?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Number of evaluation samples to generate
|
|
129
|
+
*/
|
|
130
|
+
numSamples?: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Rule-based evaluation settings
|
|
134
|
+
*/
|
|
135
|
+
export interface RuleBasedEvaluation {
|
|
136
|
+
/**
|
|
137
|
+
* Maximum response length
|
|
138
|
+
*/
|
|
139
|
+
maxResponseLength?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Minimum response length
|
|
142
|
+
*/
|
|
143
|
+
minResponseLength?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Required keywords/phrases in response
|
|
146
|
+
*/
|
|
147
|
+
requiredKeywords?: string[];
|
|
148
|
+
/**
|
|
149
|
+
* Prohibited keywords/phrases in response
|
|
150
|
+
*/
|
|
151
|
+
prohibitedKeywords?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Check for factual consistency
|
|
154
|
+
*/
|
|
155
|
+
checkFactualConsistency?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Check for harmful content
|
|
158
|
+
*/
|
|
159
|
+
checkHarmfulContent?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Configuration for evaluator plugins
|
|
163
|
+
*/
|
|
164
|
+
export interface EvaluatorConfig {
|
|
165
|
+
/**
|
|
166
|
+
* Whether this evaluator is enabled.
|
|
167
|
+
*/
|
|
168
|
+
enabled: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Per-metric thresholds. Keys must match metric id or name.
|
|
171
|
+
* Typically interpreted as minimum acceptable scores.
|
|
172
|
+
*/
|
|
173
|
+
thresholds?: Record<string, number>;
|
|
174
|
+
/**
|
|
175
|
+
* Per-metric weights used to compute the overall score.
|
|
176
|
+
*/
|
|
177
|
+
weights?: Record<string, number>;
|
|
178
|
+
/**
|
|
179
|
+
* Model-based evaluation settings (if using LLM for evaluation)
|
|
180
|
+
*/
|
|
181
|
+
modelEvaluation?: ModelEvaluation;
|
|
182
|
+
/**
|
|
183
|
+
* Rule-based evaluation settings
|
|
184
|
+
*/
|
|
185
|
+
ruleBasedEvaluation?: RuleBasedEvaluation;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Evaluator plugin interface for LLM output evaluation
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* class QualityEvaluatorPlugin
|
|
193
|
+
* extends BasePlugin
|
|
194
|
+
* implements IEvaluatorPlugin<unknown, unknown>
|
|
195
|
+
* {
|
|
196
|
+
* async evaluate(input: unknown, output: unknown): Promise<EvaluationResult> {
|
|
197
|
+
* const scores = await this.calculateScores(input, output);
|
|
198
|
+
* return {
|
|
199
|
+
* passed: scores.quality > 0.7,
|
|
200
|
+
* score: scores.overall,
|
|
201
|
+
* metrics: scores,
|
|
202
|
+
* timestamp: Date.now()
|
|
203
|
+
* };
|
|
204
|
+
* }
|
|
205
|
+
*
|
|
206
|
+
* getMetrics(): EvaluationMetric[] {
|
|
207
|
+
* return [
|
|
208
|
+
* { name: 'quality', description: 'Overall quality score', range: { min: 0, max: 1 } },
|
|
209
|
+
* { name: 'relevance', description: 'Relevance to input', range: { min: 0, max: 1 } }
|
|
210
|
+
* ];
|
|
211
|
+
* }
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export interface IEvaluatorPlugin<TInput = unknown, TOutput = unknown> extends IPlugin {
|
|
216
|
+
/**
|
|
217
|
+
* Evaluate LLM output against input.
|
|
218
|
+
* @param input The original input/prompt (typed per plugin).
|
|
219
|
+
* @param output The LLM output to evaluate (typed per plugin).
|
|
220
|
+
* @returns Evaluation result with scores and metrics.
|
|
221
|
+
*/
|
|
222
|
+
evaluate(input: TInput, output: TOutput): Promise<EvaluationResult>;
|
|
223
|
+
/**
|
|
224
|
+
* Get available evaluation metrics.
|
|
225
|
+
* @returns Array of evaluation metrics.
|
|
226
|
+
*/
|
|
227
|
+
getMetrics(): EvaluationMetric[];
|
|
228
|
+
/**
|
|
229
|
+
* Configure the evaluator. Implementations may merge with existing config.
|
|
230
|
+
* @param config Evaluator configuration (partial updates allowed).
|
|
231
|
+
*/
|
|
232
|
+
configure(config: Partial<EvaluatorConfig>): Promise<void>;
|
|
233
|
+
/**
|
|
234
|
+
* Batch evaluate multiple input/output pairs.
|
|
235
|
+
* @param pairs Array of input/output pairs.
|
|
236
|
+
* @returns Array of evaluation results (same order as input pairs).
|
|
237
|
+
*/
|
|
238
|
+
batchEvaluate?(pairs: Array<{
|
|
239
|
+
input: TInput;
|
|
240
|
+
output: TOutput;
|
|
241
|
+
}>): Promise<EvaluationResult[]>;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AAE/B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACf,CAAC;CACL;AAED;;GAEG;AACH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MA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