@frontmcp/sdk 0.2.1 → 0.2.2
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/package.json +3 -3
- package/src/decorators/front-mcp.decorator.js.map +1 -1
- package/src/decorators/hook.decorator.d.ts +12 -0
- package/src/decorators/{flow-hooks.decorator.js → hook.decorator.js} +18 -13
- package/src/decorators/hook.decorator.js.map +1 -0
- package/src/decorators/index.d.ts +1 -1
- package/src/decorators/index.js +1 -1
- package/src/decorators/index.js.map +1 -1
- package/src/decorators/tool.decorator.d.ts +34 -6
- package/src/decorators/tool.decorator.js +8 -1
- package/src/decorators/tool.decorator.js.map +1 -1
- package/src/dynamic/dynamic.plugin.d.ts +1 -0
- package/src/dynamic/dynamic.plugin.js +3 -0
- package/src/dynamic/dynamic.plugin.js.map +1 -1
- package/src/entries/base.entry.d.ts +1 -1
- package/src/entries/base.entry.js.map +1 -1
- package/src/entries/flow.entry.js.map +1 -1
- package/src/entries/hook.entry.d.ts +12 -0
- package/src/entries/hook.entry.js +20 -0
- package/src/entries/hook.entry.js.map +1 -0
- package/src/entries/index.d.ts +1 -0
- package/src/entries/index.js +1 -0
- package/src/entries/index.js.map +1 -1
- package/src/entries/plugin.entry.d.ts +2 -1
- package/src/entries/plugin.entry.js.map +1 -1
- package/src/entries/scope.entry.d.ts +2 -1
- package/src/entries/scope.entry.js.map +1 -1
- package/src/entries/tool.entry.d.ts +5 -2
- package/src/entries/tool.entry.js.map +1 -1
- package/src/interfaces/flow.interface.d.ts +9 -6
- package/src/interfaces/flow.interface.js +4 -2
- package/src/interfaces/flow.interface.js.map +1 -1
- package/src/interfaces/hook.interface.d.ts +3 -0
- package/src/{metadata/flow-hooks.metadata.js → interfaces/hook.interface.js} +1 -1
- package/src/interfaces/hook.interface.js.map +1 -0
- package/src/interfaces/index.d.ts +1 -0
- package/src/interfaces/index.js +1 -0
- package/src/interfaces/index.js.map +1 -1
- package/src/interfaces/internal/registry.interface.d.ts +30 -4
- package/src/interfaces/internal/registry.interface.js.map +1 -1
- package/src/interfaces/tool.interface.d.ts +11 -4
- package/src/interfaces/tool.interface.js +2 -1
- package/src/interfaces/tool.interface.js.map +1 -1
- package/src/metadata/flow.metadata.d.ts +2 -0
- package/src/metadata/flow.metadata.js.map +1 -1
- package/src/metadata/hook.metadata.d.ts +19 -0
- package/src/metadata/hook.metadata.js +3 -0
- package/src/metadata/hook.metadata.js.map +1 -0
- package/src/metadata/index.d.ts +1 -1
- package/src/metadata/index.js +1 -1
- package/src/metadata/index.js.map +1 -1
- package/src/metadata/tool.metadata.d.ts +0 -100
- package/src/metadata/tool.metadata.js +1 -6
- package/src/metadata/tool.metadata.js.map +1 -1
- package/src/records/hook.record.d.ts +11 -0
- package/src/records/hook.record.js +8 -0
- package/src/records/hook.record.js.map +1 -0
- package/src/records/index.d.ts +1 -0
- package/src/records/index.js +1 -0
- package/src/records/index.js.map +1 -1
- package/src/records/plugin.record.d.ts +13 -3
- package/src/records/plugin.record.js +1 -1
- package/src/records/plugin.record.js.map +1 -1
- package/src/records/tool.record.d.ts +1 -1
- package/src/records/tool.record.js.map +1 -1
- package/src/schemas/annotated-class.schema.js +5 -1
- package/src/schemas/annotated-class.schema.js.map +1 -1
- package/src/tokens/flow-hook.tokens.js +2 -2
- package/src/tokens/flow-hook.tokens.js.map +1 -1
- package/src/tokens/tool.tokens.d.ts +1 -0
- package/src/tokens/tool.tokens.js +2 -1
- package/src/tokens/tool.tokens.js.map +1 -1
- package/src/decorators/flow-hooks.decorator.d.ts +0 -12
- package/src/decorators/flow-hooks.decorator.js.map +0 -1
- package/src/metadata/flow-hooks.metadata.d.ts +0 -20
- package/src/metadata/flow-hooks.metadata.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,gEAAsC;AACtC,6DAAmC;AACnC,4DAAkC;AAClC,2DAAiC;AACjC,0DAAgC;AAChC,+DAAqC;AACrC,oEAA0C;AAC1C,8DAAoC;AACpC,6DAAmC;AACnC,2DAAiC;AACjC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AAEnC,qDAA0B","sourcesContent":["export * from './base.interface';\nexport * from './front-mcp.interface';\nexport * from './server.interface';\nexport * from './scope.interface';\nexport * from './flow.interface';\nexport * from './app.interface';\nexport * from './provider.interface';\nexport * from './auth-provider.interface';\nexport * from './adapter.interface';\nexport * from './plugin.interface';\nexport * from './tool.interface';\nexport * from './resource.interface';\nexport * from './prompt.interface';\nexport * from './logger.interface';\n\nexport * from './internal'"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,gEAAsC;AACtC,6DAAmC;AACnC,4DAAkC;AAClC,2DAAiC;AACjC,2DAAiC;AACjC,0DAAgC;AAChC,+DAAqC;AACrC,oEAA0C;AAC1C,8DAAoC;AACpC,6DAAmC;AACnC,2DAAiC;AACjC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AAEnC,qDAA0B","sourcesContent":["export * from './base.interface';\nexport * from './front-mcp.interface';\nexport * from './server.interface';\nexport * from './scope.interface';\nexport * from './flow.interface';\nexport * from './hook.interface';\nexport * from './app.interface';\nexport * from './provider.interface';\nexport * from './auth-provider.interface';\nexport * from './adapter.interface';\nexport * from './plugin.interface';\nexport * from './tool.interface';\nexport * from './resource.interface';\nexport * from './prompt.interface';\nexport * from './logger.interface';\n\nexport * from './internal'"]}
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
import { ScopeEntry, FlowEntry, AuthProviderEntry, AppEntry, ProviderEntry, PluginEntry, AdapterEntry, PromptEntry, ResourceEntry, ToolEntry, LoggerEntry } from '../../entries';
|
|
2
2
|
import { Token } from '../base.interface';
|
|
3
|
-
import { EntryOwnerRef } from '../../entries
|
|
3
|
+
import { EntryOwnerRef } from '../../entries';
|
|
4
4
|
import { FrontMcpAuth } from './primary-auth-provider.interface';
|
|
5
5
|
import { FlowName } from '../../metadata';
|
|
6
|
+
import { HookEntry } from "../../entries/hook.entry";
|
|
7
|
+
import { FlowCtxOf, FlowInputOf, FlowStagesOf } from "../flow.interface";
|
|
8
|
+
import { HookRecord } from "../../records";
|
|
6
9
|
export interface ScopeRegistryInterface {
|
|
7
10
|
getScopes(): ScopeEntry[];
|
|
8
11
|
}
|
|
9
12
|
export interface FlowRegistryInterface {
|
|
10
13
|
getFlows(): FlowEntry<FlowName>[];
|
|
11
14
|
}
|
|
15
|
+
export interface HookRegistryInterface {
|
|
16
|
+
/**
|
|
17
|
+
* used to pull hooks registered by a class and related to that class only,
|
|
18
|
+
* like registering hooks on specific tool execution
|
|
19
|
+
* @param token
|
|
20
|
+
*/
|
|
21
|
+
getClsHooks(token: Token): HookEntry[];
|
|
22
|
+
/**
|
|
23
|
+
* Used to pull all hooks registered to specific flow by name,
|
|
24
|
+
* this is used to construct the flow graph and execute hooks in order
|
|
25
|
+
* @param flow
|
|
26
|
+
*/
|
|
27
|
+
getFlowHooks<Name extends FlowName>(flow: Name): HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[];
|
|
28
|
+
/**
|
|
29
|
+
* Used to pull all hooks registered to specific flow and stage by name,
|
|
30
|
+
* this is used to construct the flow graph and execute hooks in order
|
|
31
|
+
* @param flow
|
|
32
|
+
* @param stage
|
|
33
|
+
*/
|
|
34
|
+
getFlowStageHooks<Name extends FlowName>(flow: Name, stage: FlowStagesOf<Name> | string): HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[];
|
|
35
|
+
registerHooks(embedded: boolean, ...records: HookRecord[]): Promise<void[]>;
|
|
36
|
+
}
|
|
12
37
|
export interface ProviderViews {
|
|
13
|
-
/** App-wide singletons, created at boot. Immutable from
|
|
38
|
+
/** App-wide singletons, created at boot. Immutable from invokes POV. */
|
|
14
39
|
global: ReadonlyMap<Token, unknown>;
|
|
15
40
|
/** Session-scoped cache for this sessionId. Mutable. */
|
|
16
41
|
session: Map<Token, unknown>;
|
|
@@ -38,7 +63,7 @@ export interface AdapterRegistryInterface {
|
|
|
38
63
|
}
|
|
39
64
|
export interface ToolRegistryInterface {
|
|
40
65
|
owner: EntryOwnerRef;
|
|
41
|
-
getTools(includeHidden?: boolean): ToolEntry
|
|
66
|
+
getTools(includeHidden?: boolean): ToolEntry[];
|
|
42
67
|
getInlineTools(): ToolEntry<any, any>[];
|
|
43
68
|
}
|
|
44
69
|
export interface ResourceRegistryInterface {
|
|
@@ -53,13 +78,14 @@ export interface LoggerRegistryInterface {
|
|
|
53
78
|
getLoggers(): LoggerEntry[];
|
|
54
79
|
}
|
|
55
80
|
export type GlobalRegistryKind = 'LoggerRegistry' | 'ScopeRegistry';
|
|
56
|
-
export type ScopedRegistryKind = 'AppRegistry' | 'AuthRegistry' | 'FlowRegistry';
|
|
81
|
+
export type ScopedRegistryKind = 'AppRegistry' | 'AuthRegistry' | 'FlowRegistry' | 'HookRegistry';
|
|
57
82
|
export type AppRegistryKind = 'ProviderRegistry' | 'PluginRegistry' | 'AdapterRegistry' | 'ToolRegistry' | 'PromptRegistry' | 'ResourceRegistry';
|
|
58
83
|
export type RegistryKind = GlobalRegistryKind | ScopedRegistryKind | AppRegistryKind;
|
|
59
84
|
export type RegistryType = {
|
|
60
85
|
LoggerRegistry: LoggerRegistryInterface;
|
|
61
86
|
ScopeRegistry: ScopeRegistryInterface;
|
|
62
87
|
FlowRegistry: FlowRegistryInterface;
|
|
88
|
+
HookRegistry: HookRegistryInterface;
|
|
63
89
|
AppRegistry: AppRegistryInterface;
|
|
64
90
|
AuthRegistry: AuthRegistryInterface;
|
|
65
91
|
ProviderRegistry: ProviderRegistryInterface;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/internal/registry.interface.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ScopeEntry,\n FlowEntry,\n AuthProviderEntry,\n AppEntry,\n ProviderEntry,\n PluginEntry,\n AdapterEntry,\n PromptEntry,\n ResourceEntry,\n ToolEntry, LoggerEntry,\n} from '../../entries';\nimport {
|
|
1
|
+
{"version":3,"file":"registry.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/internal/registry.interface.ts"],"names":[],"mappings":"","sourcesContent":["import {\n ScopeEntry,\n FlowEntry,\n AuthProviderEntry,\n AppEntry,\n ProviderEntry,\n PluginEntry,\n AdapterEntry,\n PromptEntry,\n ResourceEntry,\n ToolEntry, LoggerEntry,\n} from '../../entries';\nimport {Token} from '../base.interface';\nimport {EntryOwnerRef} from '../../entries';\nimport {FrontMcpAuth} from './primary-auth-provider.interface';\nimport {FlowName} from '../../metadata';\nimport {HookEntry} from \"../../entries/hook.entry\";\nimport {FlowCtxOf, FlowInputOf, FlowStagesOf} from \"../flow.interface\";\nimport {HookRecord} from \"../../records\";\n\nexport interface ScopeRegistryInterface {\n getScopes(): ScopeEntry[];\n}\n\nexport interface FlowRegistryInterface {\n getFlows(): FlowEntry<FlowName>[];\n}\n\nexport interface HookRegistryInterface {\n /**\n * used to pull hooks registered by a class and related to that class only,\n * like registering hooks on specific tool execution\n * @param token\n */\n getClsHooks(token: Token): HookEntry[];\n\n /**\n * Used to pull all hooks registered to specific flow by name,\n * this is used to construct the flow graph and execute hooks in order\n * @param flow\n */\n getFlowHooks<Name extends FlowName>(flow: Name): HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[];\n\n\n /**\n * Used to pull all hooks registered to specific flow and stage by name,\n * this is used to construct the flow graph and execute hooks in order\n * @param flow\n * @param stage\n */\n getFlowStageHooks<Name extends FlowName>(\n flow: Name,\n stage: FlowStagesOf<Name> | string\n ): HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[]\n registerHooks(embedded:boolean,...records: HookRecord[]): Promise<void[]>;\n}\n\n\nexport interface ProviderViews {\n /** App-wide singletons, created at boot. Immutable from invokes POV. */\n global: ReadonlyMap<Token, unknown>;\n /** Session-scoped cache for this sessionId. Mutable. */\n session: Map<Token, unknown>;\n /** Request-scoped providers for this single invocation. Mutable. */\n request: Map<Token, unknown>;\n}\n\n\nexport interface ProviderRegistryInterface {\n get<T>(token: Token<T>): T;\n\n getProviders(): ProviderEntry[];\n\n getRegistries<T extends RegistryKind>(type: T): RegistryType[T][];\n\n // TODO: fix session type\n buildViews(session: any): Promise<ProviderViews>;\n}\n\nexport interface AuthRegistryInterface {\n getPrimary(): FrontMcpAuth;\n\n getAuthProviders(): AuthProviderEntry[];\n}\n\nexport interface AppRegistryInterface {\n getApps(): AppEntry[];\n}\n\nexport interface PluginRegistryInterface {\n getPlugins(): PluginEntry[];\n}\n\nexport interface AdapterRegistryInterface {\n getAdapters(): AdapterEntry[];\n}\n\nexport interface ToolRegistryInterface {\n owner: EntryOwnerRef;\n\n // inline tools plus discovered by nested tool registries\n getTools(includeHidden?: boolean): ToolEntry[];\n\n // inline tools only\n getInlineTools(): ToolEntry<any, any>[];\n}\n\n\nexport interface ResourceRegistryInterface {\n // inline resources plus discovered by nested tool registries\n getResources(): ResourceEntry<any, any>[];\n\n // inline resources only\n getInlineResources(): ResourceEntry<any, any>[];\n}\n\n\nexport interface PromptRegistryInterface {\n // inline prompts plus discovered by nested tool registries\n getPrompts(): PromptEntry[];\n\n // inline prompts only\n getInlinePrompts(): PromptEntry[];\n}\n\n\nexport interface LoggerRegistryInterface {\n getLoggers(): LoggerEntry[];\n\n}\n\n\nexport type GlobalRegistryKind =\n | 'LoggerRegistry'\n | 'ScopeRegistry'\n\nexport type ScopedRegistryKind =\n | 'AppRegistry'\n | 'AuthRegistry'\n | 'FlowRegistry'\n | 'HookRegistry'\n\nexport type AppRegistryKind =\n | 'ProviderRegistry'\n | 'PluginRegistry'\n | 'AdapterRegistry'\n | 'ToolRegistry'\n | 'PromptRegistry'\n | 'ResourceRegistry'\n\n\nexport type RegistryKind = GlobalRegistryKind | ScopedRegistryKind | AppRegistryKind;\n\nexport type RegistryType = {\n LoggerRegistry: LoggerRegistryInterface;\n ScopeRegistry: ScopeRegistryInterface;\n FlowRegistry: FlowRegistryInterface;\n HookRegistry: HookRegistryInterface;\n AppRegistry: AppRegistryInterface;\n AuthRegistry: AuthRegistryInterface,\n ProviderRegistry: ProviderRegistryInterface;\n PluginRegistry: PluginRegistryInterface;\n AdapterRegistry: AdapterRegistryInterface;\n ToolRegistry: ToolRegistryInterface;\n ResourceRegistry: ResourceRegistryInterface;\n PromptRegistry: PromptRegistryInterface;\n}"]}
|
|
@@ -11,13 +11,20 @@ type HistoryEntry<T> = {
|
|
|
11
11
|
value: T | undefined;
|
|
12
12
|
note?: string;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export type ToolCtorArgs<In> = {
|
|
15
|
+
metadata: ToolMetadata;
|
|
16
|
+
input: In;
|
|
17
|
+
providers: ProviderRegistryInterface;
|
|
18
|
+
logger: FrontMcpLogger;
|
|
19
|
+
authInfo: AuthInfo;
|
|
20
|
+
};
|
|
21
|
+
export declare abstract class ToolContext<In = any, Out = any> {
|
|
15
22
|
private providers;
|
|
16
23
|
readonly authInfo: AuthInfo;
|
|
17
24
|
protected readonly runId: string;
|
|
18
25
|
protected readonly toolId: string;
|
|
19
26
|
protected readonly toolName: string;
|
|
20
|
-
|
|
27
|
+
readonly metadata: ToolMetadata;
|
|
21
28
|
protected readonly logger: FrontMcpLogger;
|
|
22
29
|
protected activeStage: string;
|
|
23
30
|
private _rawInput?;
|
|
@@ -27,7 +34,7 @@ export declare abstract class ToolContext<In, Out> {
|
|
|
27
34
|
private _error?;
|
|
28
35
|
private readonly _inputHistory;
|
|
29
36
|
private readonly _outputHistory;
|
|
30
|
-
constructor(
|
|
37
|
+
constructor(args: ToolCtorArgs<In>);
|
|
31
38
|
abstract execute(input: In): Promise<Out>;
|
|
32
39
|
get<T>(token: Token<T>): T;
|
|
33
40
|
tryGet<T>(token: Token<T>): T | undefined;
|
|
@@ -37,7 +44,7 @@ export declare abstract class ToolContext<In, Out> {
|
|
|
37
44
|
get output(): Out | undefined;
|
|
38
45
|
set output(v: Out | undefined);
|
|
39
46
|
get outputHistory(): ReadonlyArray<HistoryEntry<Out>>;
|
|
40
|
-
|
|
47
|
+
respond(value: Out): never;
|
|
41
48
|
/** Fail the run (invoker will run error/finalize). */
|
|
42
49
|
protected fail(err: Error): never;
|
|
43
50
|
mark(stage: string): void;
|
|
@@ -22,7 +22,8 @@ class ToolContext {
|
|
|
22
22
|
// ---- histories
|
|
23
23
|
_inputHistory = [];
|
|
24
24
|
_outputHistory = [];
|
|
25
|
-
constructor(
|
|
25
|
+
constructor(args) {
|
|
26
|
+
const { metadata, input, providers, logger, authInfo } = args;
|
|
26
27
|
this.runId = (0, crypto_1.randomUUID)();
|
|
27
28
|
this.toolName = metadata.name;
|
|
28
29
|
this.toolId = metadata.id ?? metadata.name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.interface.js","sourceRoot":"","sources":["../../../src/interfaces/tool.interface.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAKlC,qDAA6C;
|
|
1
|
+
{"version":3,"file":"tool.interface.js","sourceRoot":"","sources":["../../../src/interfaces/tool.interface.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAKlC,qDAA6C;AAuB7C,MAAsB,WAAW;IACvB,SAAS,CAA4B;IACpC,QAAQ,CAAW;IAET,KAAK,CAAS;IACd,MAAM,CAAS;IACf,QAAQ,CAAS;IAC3B,QAAQ,CAAe;IACb,MAAM,CAAiB;IAEhC,WAAW,CAAS;IAE9B,uCAAuC;IAC/B,SAAS,CAAqB;IAC9B,MAAM,CAAM;IAEpB,wCAAwC;IAChC,YAAY,CAAsB;IAClC,OAAO,CAAO;IAEd,MAAM,CAAS;IAEvB,iBAAiB;IACA,aAAa,GAAuB,EAAE,CAAC;IACvC,cAAc,GAAwB,EAAE,CAAC;IAG1D,YAAY,IAAsB;QAChC,MAAM,EAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAC5D,IAAI,CAAC,KAAK,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAID,GAAG,CAAI,KAAe;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAI,KAAe;QACvB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;YACpE,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAY,CAAC;IAC3B,CAAC;IAED,IAAW,KAAK,CAAC,CAAiB;QAChC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,KAAK,EAAE,IAAI,CAAC,WAAW;YACvB,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;IACL,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAW,MAAM,CAAC,CAAkB;QAClC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,GAAE,CAAC,CAAC;IACjF,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,KAAU;QAChB,iEAAiE;QACjE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,4BAAW,CAAC,OAAO,CAAM,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,sDAAsD;IAC5C,IAAI,CAAC,GAAU;QACvB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,4BAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,KAAa;QAChB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,KAAwB,EAAE,IAAkB;QAChD,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF;AAvGD,kCAuGC","sourcesContent":["import {randomUUID} from \"crypto\";\nimport {FuncType, Token, Type} from \"./base.interface\";\nimport {ProviderRegistryInterface} from \"./internal\";\nimport {ToolMetadata} from \"../metadata\";\nimport {FrontMcpLogger} from \"./logger.interface\";\nimport {FlowControl} from \"./flow.interface\";\nimport {URL} from \"url\";\nimport {AuthInfo} from \"@modelcontextprotocol/sdk/server/auth/types.js\";\n\nexport type ToolType<T = any> =\n | Type<T>\n | FuncType<T>\n\ntype HistoryEntry<T> = {\n at: number;\n stage?: string;\n value: T | undefined;\n note?: string;\n};\n\nexport type ToolCtorArgs<In> = {\n metadata: ToolMetadata;\n input: In;\n providers: ProviderRegistryInterface;\n logger: FrontMcpLogger\n authInfo: AuthInfo;\n}\n\nexport abstract class ToolContext<In = any, Out= any> {\n private providers: ProviderRegistryInterface;\n readonly authInfo: AuthInfo;\n\n protected readonly runId: string;\n protected readonly toolId: string;\n protected readonly toolName: string;\n readonly metadata: ToolMetadata;\n protected readonly logger: FrontMcpLogger;\n\n protected activeStage: string;\n\n // ---- INPUT storages (backing fields)\n private _rawInput?: Partial<In> | any;\n private _input?: In;\n\n // ---- OUTPUT storages (backing fields)\n private _outputDraft?: Partial<Out> | any;\n private _output?: Out;\n\n private _error?: Error;\n\n // ---- histories\n private readonly _inputHistory: HistoryEntry<In>[] = [];\n private readonly _outputHistory: HistoryEntry<Out>[] = [];\n\n\n constructor(args: ToolCtorArgs<In>) {\n const {metadata, input, providers, logger, authInfo} = args;\n this.runId = randomUUID();\n this.toolName = metadata.name;\n this.toolId = metadata.id ?? metadata.name;\n this.metadata = metadata;\n this._input = input;\n this.providers = providers;\n this.logger = logger.child(`tool:${this.toolId}`);\n this.authInfo = authInfo;\n }\n\n abstract execute(input: In): Promise<Out>;\n\n get<T>(token: Token<T>): T {\n return this.providers.get(token);\n }\n\n tryGet<T>(token: Token<T>): T | undefined {\n try {\n return this.providers.get(token);\n } catch (e) {\n this.logger.warn(\"Requesting provider that doesn't exist: \", token);\n return undefined;\n }\n }\n\n public get input(): In {\n return this._input as In;\n }\n\n public set input(v: In | undefined) {\n this._input = v;\n this._inputHistory.push({\n at: Date.now(),\n stage: this.activeStage,\n value: v,\n });\n }\n\n public get inputHistory(): ReadonlyArray<HistoryEntry<In>> {\n return this._inputHistory;\n }\n\n public get output(): Out | undefined {\n return this._output;\n }\n\n public set output(v: Out | undefined) {\n this._output = v;\n this._outputHistory.push({at: Date.now(), stage: this.activeStage, value: v,});\n }\n\n public get outputHistory(): ReadonlyArray<HistoryEntry<Out>> {\n return this._outputHistory;\n }\n\n respond(value: Out): never {\n // record validated output and surface the value via control flow\n this.output = value;\n FlowControl.respond<Out>(value);\n }\n\n /** Fail the run (invoker will run error/finalize). */\n protected fail(err: Error): never {\n this._error = err;\n FlowControl.fail(err);\n }\n\n mark(stage: string): void {\n this.activeStage = stage;\n }\n\n fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n return fetch(input, init);\n }\n}\n\n"]}
|
|
@@ -19,6 +19,7 @@ export type FlowRunOptions<Ctx, Plan extends FlowPlan<string>, Input, Output ext
|
|
|
19
19
|
output: Output;
|
|
20
20
|
state: State;
|
|
21
21
|
stage: StagesFromPlan<Plan>;
|
|
22
|
+
executeStage: ExecuteStagesFromPlan<Plan>;
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Declarative metadata describing what a FrontMcpFlow contributes at app scope.
|
|
@@ -41,6 +42,7 @@ export type FlowPhase = 'pre' | 'execute' | 'post' | 'finalize' | 'error';
|
|
|
41
42
|
type Values<T> = T[keyof T];
|
|
42
43
|
type ArrayElem<T> = T extends ReadonlyArray<infer U> ? U : never;
|
|
43
44
|
export type StagesFromPlan<P extends FlowPlan<string>> = ArrayElem<Values<Required<P>>>;
|
|
45
|
+
export type ExecuteStagesFromPlan<P extends FlowPlan<string>> = ArrayElem<Required<P['execute']>>;
|
|
44
46
|
export type FlowPlan<Base extends string> = {
|
|
45
47
|
steps?: Record<Base, StepInfo>;
|
|
46
48
|
} & Partial<Record<FlowPhase, Base[]>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.metadata.js","sourceRoot":"","sources":["../../../src/metadata/flow.metadata.ts"],"names":[],"mappings":";;;AAAA,6BAAsB;
|
|
1
|
+
{"version":3,"file":"flow.metadata.js","sourceRoot":"","sources":["../../../src/metadata/flow.metadata.ts"],"names":[],"mappings":";;;AAAA,6BAAsB;AA4DT,QAAA,0BAA0B,GAAG,OAAC,CAAC,MAAM,CAAC;IACjD,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,MAAM,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;IACrE,WAAW,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IACjC,YAAY,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;IAC7C,IAAI,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IAC1B,SAAS,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE;IACtC,UAAU,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;CACD,CAAC,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import {z} from 'zod';\nimport {RawZodShape} from '../types';\nimport {HttpMethod, ServerRequest, Token} from '../interfaces';\nimport {ScopeEntry} from '../entries';\n\ndeclare global {\n // eslint-disable-next-line\n export interface ExtendFlows {\n\n }\n}\n\nexport type FlowName = keyof ExtendFlows;\n\nexport type CanActivateFlow = (request: ServerRequest, scope: ScopeEntry) => Promise<boolean>;\n\nexport interface FlowMiddlewareOptions {\n path?: RegExp | string; // string can be \"/test/**\" or \"/test/*/asds\", default to all paths\n method?: HttpMethod; // default to all methods\n canActivate?: CanActivateFlow[];\n}\n\nexport type FlowRunOptions<Ctx, Plan extends FlowPlan<string>, Input, Output extends (z.ZodObject<any> | z.ZodUnion<any> | z.ZodDiscriminatedUnion<any, any>), State extends z.ZodObject<any>> = {\n ctx: Ctx;\n plan: Plan;\n input: Input;\n output: Output;\n state: State;\n stage: StagesFromPlan<Plan>;\n executeStage: ExecuteStagesFromPlan<Plan>;\n}\n\n/**\n * Declarative metadata describing what a FrontMcpFlow contributes at app scope.\n */\nexport interface FlowMetadata<Name extends FlowName> {\n name: Name;\n description?: string;\n plan: FlowPlan<ExtendFlows[Name]['stage']>;\n inputSchema: ExtendFlows[Name]['input'];\n outputSchema: ExtendFlows[Name]['output'];\n access: 'public' | 'authorized';\n dependsOn?: Token[];\n middleware?: FlowMiddlewareOptions;\n}\n\n\nexport type StepInfo = string | { title?: string; description?: string; };\nexport type FlowPhase = 'pre' | 'execute' | 'post' | 'finalize' | 'error';\ntype Values<T> = T[keyof T];\ntype ArrayElem<T> = T extends ReadonlyArray<infer U> ? U : never;\n\nexport type StagesFromPlan<P extends FlowPlan<string>> = ArrayElem<Values<Required<P>>>;\nexport type ExecuteStagesFromPlan<P extends FlowPlan<string>> = ArrayElem<Required<P['execute']>>;\n\nexport type FlowPlan<Base extends string> = {\n steps?: Record<Base, StepInfo>;\n} & Partial<Record<FlowPhase, Base[]>>;\n\n\nexport const frontMcpFlowMetadataSchema = z.object({\n name: z.string().min(1),\n description: z.string().optional(),\n access: z.enum(['public', 'authorized']).optional().default('public'),\n inputSchema: z.instanceof(Object),\n outputSchema: z.instanceof(Object).optional(),\n plan: z.instanceof(Object),\n dependsOn: z.array(z.any()).optional(),\n middleware: z.instanceof(Object).optional(),\n} satisfies RawZodShape<FlowMetadata<never>>).passthrough();\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Token } from "../interfaces";
|
|
2
|
+
import { FlowName } from "./flow.metadata";
|
|
3
|
+
export type HookStageType = 'stage' | 'will' | 'did' | 'around';
|
|
4
|
+
export type HookPriority = number;
|
|
5
|
+
export interface HookOptions<Ctx> {
|
|
6
|
+
priority?: HookPriority;
|
|
7
|
+
filter?: (ctx: Ctx) => boolean | Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
export interface TokenHookMetadata {
|
|
10
|
+
hooks: HookMetadata[];
|
|
11
|
+
}
|
|
12
|
+
export interface HookMetadata<Name extends FlowName = FlowName, Stage = string, Ctx = any> extends HookOptions<Ctx> {
|
|
13
|
+
type: HookStageType;
|
|
14
|
+
flow: Name;
|
|
15
|
+
stage: Stage;
|
|
16
|
+
target: Token;
|
|
17
|
+
method: string;
|
|
18
|
+
static?: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook.metadata.js","sourceRoot":"","sources":["../../../src/metadata/hook.metadata.ts"],"names":[],"mappings":"","sourcesContent":["import {Token} from \"../interfaces\";\nimport {FlowName} from \"./flow.metadata\";\n\nexport type HookStageType = 'stage' | 'will' | 'did' | 'around';\nexport type HookPriority = number;\n\n\nexport interface HookOptions<Ctx> {\n priority?: HookPriority;\n filter?: (ctx: Ctx) => boolean | Promise<boolean>;\n}\n\nexport interface TokenHookMetadata {\n hooks: HookMetadata[];\n}\n\nexport interface HookMetadata<Name extends FlowName = FlowName, Stage = string, Ctx = any> extends HookOptions<Ctx> {\n type: HookStageType;\n flow: Name,\n stage: Stage;\n target: Token;\n method: string;\n static?: boolean;\n}"]}
|
package/src/metadata/index.d.ts
CHANGED
package/src/metadata/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./front-mcp.metadata"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./flow.metadata"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./
|
|
6
|
+
tslib_1.__exportStar(require("./hook.metadata"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./app.metadata"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./provider.metadata"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./auth-provider.metadata"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metadata/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,0DAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metadata/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,0DAAgC;AAChC,0DAAgC;AAChC,yDAA+B;AAC/B,8DAAoC;AACpC,mEAAyC;AACzC,6DAAmC;AACnC,4DAAkC;AAClC,0DAAgC;AAChC,8DAAoC;AACpC,4DAAkC;AAClC,4DAAkC","sourcesContent":["export * from './front-mcp.metadata';\nexport * from './flow.metadata';\nexport * from './hook.metadata';\nexport * from './app.metadata';\nexport * from './provider.metadata';\nexport * from './auth-provider.metadata';\nexport * from './adapter.metadata';\nexport * from './plugin.metadata';\nexport * from './tool.metadata';\nexport * from './resource.metadata';\nexport * from './prompt.metadata';\nexport * from './logger.metadata';\n"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ToolContext } from '../interfaces';
|
|
3
|
-
import { ToolHookStage } from '../interfaces/tool-hook.interface';
|
|
4
2
|
import type { JSONSchema7 } from 'json-schema';
|
|
5
3
|
declare global {
|
|
6
4
|
/**
|
|
@@ -178,101 +176,3 @@ export declare const frontMcpToolMetadataSchema: z.ZodObject<{
|
|
|
178
176
|
}, z.ZodTypeAny, "passthrough">>>;
|
|
179
177
|
hideFromDiscovery: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
180
178
|
}, z.ZodTypeAny, "passthrough">>;
|
|
181
|
-
export interface ToolInlineMetadata<In = any, Out = any> extends ToolMetadata<In, Out> {
|
|
182
|
-
execute(input: In, ctx: ToolContext<In, Out>): Promise<Out> | Out;
|
|
183
|
-
hooks?: [ToolHookStage, ((ctx: ToolContext<In, Out>) => Promise<void> | void)][];
|
|
184
|
-
}
|
|
185
|
-
export declare const frontMcpToolInlineMetadataSchema: z.ZodObject<{
|
|
186
|
-
id: z.ZodOptional<z.ZodString>;
|
|
187
|
-
name: z.ZodString;
|
|
188
|
-
description: z.ZodOptional<z.ZodString>;
|
|
189
|
-
inputSchema: z.ZodType<Object, z.ZodTypeDef, Object>;
|
|
190
|
-
rawInputSchema: z.ZodOptional<z.ZodAny>;
|
|
191
|
-
outputSchema: z.ZodOptional<z.ZodType<Object, z.ZodTypeDef, Object>>;
|
|
192
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
193
|
-
annotations: z.ZodOptional<z.ZodObject<{
|
|
194
|
-
title: z.ZodOptional<z.ZodString>;
|
|
195
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
196
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
197
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
198
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
199
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
200
|
-
title: z.ZodOptional<z.ZodString>;
|
|
201
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
202
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
203
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
204
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
205
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
206
|
-
title: z.ZodOptional<z.ZodString>;
|
|
207
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
208
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
209
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
210
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
211
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
|
212
|
-
hideFromDiscovery: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
213
|
-
} & {
|
|
214
|
-
execute: z.ZodFunction<z.ZodTuple<[z.ZodAny, z.ZodAny], z.ZodUnknown>, z.ZodUnion<[z.ZodPromise<z.ZodAny>, z.ZodAny]>>;
|
|
215
|
-
hooks: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodNativeEnum<typeof ToolHookStage>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodPromise<z.ZodVoid>, z.ZodVoid]>>], null>, "many">>;
|
|
216
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
217
|
-
id: z.ZodOptional<z.ZodString>;
|
|
218
|
-
name: z.ZodString;
|
|
219
|
-
description: z.ZodOptional<z.ZodString>;
|
|
220
|
-
inputSchema: z.ZodType<Object, z.ZodTypeDef, Object>;
|
|
221
|
-
rawInputSchema: z.ZodOptional<z.ZodAny>;
|
|
222
|
-
outputSchema: z.ZodOptional<z.ZodType<Object, z.ZodTypeDef, Object>>;
|
|
223
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
224
|
-
annotations: z.ZodOptional<z.ZodObject<{
|
|
225
|
-
title: z.ZodOptional<z.ZodString>;
|
|
226
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
227
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
228
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
230
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
231
|
-
title: z.ZodOptional<z.ZodString>;
|
|
232
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
233
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
234
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
235
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
236
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
237
|
-
title: z.ZodOptional<z.ZodString>;
|
|
238
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
239
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
240
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
241
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
242
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
|
243
|
-
hideFromDiscovery: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
244
|
-
} & {
|
|
245
|
-
execute: z.ZodFunction<z.ZodTuple<[z.ZodAny, z.ZodAny], z.ZodUnknown>, z.ZodUnion<[z.ZodPromise<z.ZodAny>, z.ZodAny]>>;
|
|
246
|
-
hooks: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodNativeEnum<typeof ToolHookStage>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodPromise<z.ZodVoid>, z.ZodVoid]>>], null>, "many">>;
|
|
247
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
248
|
-
id: z.ZodOptional<z.ZodString>;
|
|
249
|
-
name: z.ZodString;
|
|
250
|
-
description: z.ZodOptional<z.ZodString>;
|
|
251
|
-
inputSchema: z.ZodType<Object, z.ZodTypeDef, Object>;
|
|
252
|
-
rawInputSchema: z.ZodOptional<z.ZodAny>;
|
|
253
|
-
outputSchema: z.ZodOptional<z.ZodType<Object, z.ZodTypeDef, Object>>;
|
|
254
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
255
|
-
annotations: z.ZodOptional<z.ZodObject<{
|
|
256
|
-
title: z.ZodOptional<z.ZodString>;
|
|
257
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
258
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
259
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
260
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
261
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
262
|
-
title: z.ZodOptional<z.ZodString>;
|
|
263
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
264
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
265
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
266
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
267
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
268
|
-
title: z.ZodOptional<z.ZodString>;
|
|
269
|
-
readOnlyHint: z.ZodOptional<z.ZodBoolean>;
|
|
270
|
-
destructiveHint: z.ZodOptional<z.ZodBoolean>;
|
|
271
|
-
idempotentHint: z.ZodOptional<z.ZodBoolean>;
|
|
272
|
-
openWorldHint: z.ZodOptional<z.ZodBoolean>;
|
|
273
|
-
}, z.ZodTypeAny, "passthrough">>>;
|
|
274
|
-
hideFromDiscovery: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
275
|
-
} & {
|
|
276
|
-
execute: z.ZodFunction<z.ZodTuple<[z.ZodAny, z.ZodAny], z.ZodUnknown>, z.ZodUnion<[z.ZodPromise<z.ZodAny>, z.ZodAny]>>;
|
|
277
|
-
hooks: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodNativeEnum<typeof ToolHookStage>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodPromise<z.ZodVoid>, z.ZodVoid]>>], null>, "many">>;
|
|
278
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.frontMcpToolMetadataSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const tool_hook_interface_1 = require("../interfaces/tool-hook.interface");
|
|
6
5
|
const mcpToolAnnotationsSchema = zod_1.z.object({
|
|
7
6
|
title: zod_1.z.string().optional(),
|
|
8
7
|
readOnlyHint: zod_1.z.boolean().optional(),
|
|
@@ -21,8 +20,4 @@ exports.frontMcpToolMetadataSchema = zod_1.z.object({
|
|
|
21
20
|
annotations: mcpToolAnnotationsSchema.optional(),
|
|
22
21
|
hideFromDiscovery: zod_1.z.boolean().optional().default(false),
|
|
23
22
|
}).passthrough();
|
|
24
|
-
exports.frontMcpToolInlineMetadataSchema = exports.frontMcpToolMetadataSchema.extend({
|
|
25
|
-
execute: zod_1.z.function().args(zod_1.z.any(), zod_1.z.any()).returns(zod_1.z.promise(zod_1.z.any()).or(zod_1.z.any())),
|
|
26
|
-
hooks: zod_1.z.array(zod_1.z.tuple([zod_1.z.nativeEnum(tool_hook_interface_1.ToolHookStage), zod_1.z.function().returns(zod_1.z.promise(zod_1.z.void()).or(zod_1.z.void()))])).optional(),
|
|
27
|
-
});
|
|
28
23
|
//# sourceMappingURL=tool.metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.metadata.js","sourceRoot":"","sources":["../../../src/metadata/tool.metadata.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"tool.metadata.js","sourceRoot":"","sources":["../../../src/metadata/tool.metadata.ts"],"names":[],"mappings":";;;AAAA,6BAAsB;AA0DtB,MAAM,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,YAAY,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACpC,eAAe,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACvC,cAAc,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,aAAa,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACC,CAAC,CAAC,WAAW,EAAE,CAAC;AAwD3C,QAAA,0BAA0B,GAAG,OAAC,CAAC,MAAM,CAAC;IACjD,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,WAAW,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IACjC,cAAc,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAClC,YAAY,EAAE,OAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE;IAC7C,IAAI,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC3C,WAAW,EAAE,wBAAwB,CAAC,QAAQ,EAAE;IAChD,iBAAiB,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CACO,CAAC,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import {z} from 'zod';\nimport {RawZodShape} from '../types';\nimport {ToolContext} from '../interfaces';\nimport {ToolHookStage} from '../interfaces/tool-hook.interface';\nimport type {JSONSchema7} from 'json-schema';\n\ndeclare global {\n /**\n * Declarative metadata extends to the an McpTool decorator.\n */\n export interface ExtendFrontMcpToolMetadata {\n }\n}\n\n\nexport interface ToolAnnotations {\n [x: string]: unknown;\n\n /**\n * A human-readable title for the tool.\n */\n title?: string;\n /**\n * If true, the tool does not modify its environment.\n *\n * Default: false\n */\n readOnlyHint?: boolean;\n /**\n * If true, the tool may perform destructive updates to its environment.\n * If false, the tool performs only additive updates.\n *\n * (This property is meaningful only when `readOnlyHint == false`)\n *\n * Default: true\n */\n destructiveHint?: boolean;\n /**\n * If true, calling the tool repeatedly with the same arguments\n * will have no additional effect on the its environment.\n *\n * (This property is meaningful only when `readOnlyHint == false`)\n *\n * Default: false\n */\n idempotentHint?: boolean;\n /**\n * If true, this tool may interact with an \"open world\" of external\n * entities. If false, the tool's domain of interaction is closed.\n * For example, the world of a web search tool is open, whereas that\n * of a memory tool is not.\n *\n * Default: true\n */\n openWorldHint?: boolean;\n}\n\n\nconst mcpToolAnnotationsSchema = z.object({\n title: z.string().optional(),\n readOnlyHint: z.boolean().optional(),\n destructiveHint: z.boolean().optional(),\n idempotentHint: z.boolean().optional(),\n openWorldHint: z.boolean().optional(),\n} satisfies RawZodShape<ToolAnnotations>).passthrough();\n\n\n/**\n * Declarative metadata describing what an McpTool contributes.\n */\nexport interface ToolMetadata<In = z.ZodRawShape, Out = z.ZodRawShape> extends ExtendFrontMcpToolMetadata {\n /**\n * Optional unique identifier for the tool.\n * If omitted, a consumer may derive an ID from the class or file name.\n */\n id?: string;\n\n /**\n * Human‑readable name of the tool, used in UIs, logs, and discovery.\n */\n name: string;\n\n /**\n * Short summary describing what the tool does and when to use it.\n */\n description?: string;\n\n /**\n * Zod schema describing the expected input payload for the tool.\n * Used for validation and for generating automatic docs/UX.\n */\n inputSchema: In;\n /**\n * Zod schema describing the expected input payload for the tool.\n * Used for validation and for generating automatic docs/UX.\n */\n rawInputSchema?: JSONSchema7;\n\n /**\n * Zod schema describing the structure of the tool's successful output.\n */\n outputSchema?: Out;\n\n /**\n * Optional list of tags/labels that categorize the tool for discovery and filtering.\n */\n tags?: string[];\n\n annotations?: ToolAnnotations;\n\n /**\n * If true, the tool will not be shown in the tool/list action results.\n * this method can still be called directly with tool/call even if hidden.\n * use case: tools that are intended to be private or internal. (usually for testing / private apis)\n * Default: false\n */\n hideFromDiscovery?: boolean;\n}\n\n\nexport const frontMcpToolMetadataSchema = z.object({\n id: z.string().optional(),\n name: z.string().min(1),\n description: z.string().optional(),\n inputSchema: z.instanceof(Object),\n rawInputSchema: z.any().optional(),\n outputSchema: z.instanceof(Object).optional(),\n tags: z.array(z.string().min(1)).optional(),\n annotations: mcpToolAnnotationsSchema.optional(),\n hideFromDiscovery: z.boolean().optional().default(false),\n} satisfies RawZodShape<ToolMetadata, ExtendFrontMcpToolMetadata>).passthrough();\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HookType } from '../interfaces';
|
|
2
|
+
import { HookMetadata } from '../metadata';
|
|
3
|
+
export declare enum HookKind {
|
|
4
|
+
METHOD_TOKEN = "METHOD_TOKEN"
|
|
5
|
+
}
|
|
6
|
+
export type HooksMethodToken = {
|
|
7
|
+
kind: HookKind.METHOD_TOKEN;
|
|
8
|
+
provide: HookType;
|
|
9
|
+
metadata: HookMetadata;
|
|
10
|
+
};
|
|
11
|
+
export type HookRecord = HooksMethodToken;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HookKind = void 0;
|
|
4
|
+
var HookKind;
|
|
5
|
+
(function (HookKind) {
|
|
6
|
+
HookKind["METHOD_TOKEN"] = "METHOD_TOKEN";
|
|
7
|
+
})(HookKind || (exports.HookKind = HookKind = {}));
|
|
8
|
+
//# sourceMappingURL=hook.record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook.record.js","sourceRoot":"","sources":["../../../src/records/hook.record.ts"],"names":[],"mappings":";;;AAGA,IAAY,QAEX;AAFD,WAAY,QAAQ;IAClB,yCAA6B,CAAA;AAC/B,CAAC,EAFW,QAAQ,wBAAR,QAAQ,QAEnB","sourcesContent":["import {HookType} from '../interfaces';\nimport {HookMetadata} from '../metadata';\n\nexport enum HookKind {\n METHOD_TOKEN = 'METHOD_TOKEN',\n}\n\nexport type HooksMethodToken = {\n kind: HookKind.METHOD_TOKEN;\n provide: HookType;\n metadata: HookMetadata\n};\n\nexport type HookRecord =\n | HooksMethodToken\n"]}
|
package/src/records/index.d.ts
CHANGED
package/src/records/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./scope.record"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./flow.record"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./hook.record"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./app.record"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./provider.record"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./auth-provider.record"), exports);
|
package/src/records/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/records/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,wDAA8B;AAC9B,uDAA6B;AAC7B,4DAAkC;AAClC,iEAAuC;AACvC,0DAAgC;AAChC,2DAAiC;AAEjC,wDAA8B;AAC9B,4DAAkC;AAClC,0DAAgC;AAChC,0DAAgC","sourcesContent":["export * from './scope.record';\nexport * from './flow.record';\nexport * from './app.record';\nexport * from './provider.record';\nexport * from './auth-provider.record';\nexport * from './plugin.record';\nexport * from './adapter.record';\n\nexport * from './tool.record';\nexport * from './resource.record';\nexport * from './prompt.record';\nexport * from './logger.record';"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/records/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,wDAA8B;AAC9B,wDAA8B;AAC9B,uDAA6B;AAC7B,4DAAkC;AAClC,iEAAuC;AACvC,0DAAgC;AAChC,2DAAiC;AAEjC,wDAA8B;AAC9B,4DAAkC;AAClC,0DAAgC;AAChC,0DAAgC","sourcesContent":["export * from './scope.record';\nexport * from './flow.record';\nexport * from './hook.record';\nexport * from './app.record';\nexport * from './provider.record';\nexport * from './auth-provider.record';\nexport * from './plugin.record';\nexport * from './adapter.record';\n\nexport * from './tool.record';\nexport * from './resource.record';\nexport * from './prompt.record';\nexport * from './logger.record';"]}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import { ClassType, FactoryType, Type } from '../interfaces';
|
|
1
|
+
import { ClassType, FactoryType, Type, ValueType } from '../interfaces';
|
|
2
2
|
import { PluginMetadata } from '../metadata';
|
|
3
|
+
import { ProviderRecord } from "./provider.record";
|
|
3
4
|
export declare enum PluginKind {
|
|
4
5
|
CLASS_TOKEN = "CLASS_TOKEN",
|
|
5
6
|
CLASS = "CLASS",
|
|
6
|
-
FACTORY = "FACTORY"
|
|
7
|
+
FACTORY = "FACTORY",
|
|
8
|
+
VALUE = "VALUE"
|
|
7
9
|
}
|
|
8
10
|
export interface PluginClassTokenRecord {
|
|
9
11
|
kind: PluginKind.CLASS_TOKEN;
|
|
10
12
|
provide: Type;
|
|
11
13
|
metadata: PluginMetadata;
|
|
14
|
+
providers?: ProviderRecord[];
|
|
12
15
|
}
|
|
13
16
|
export interface PluginClassRecord extends ClassType<any> {
|
|
14
17
|
kind: PluginKind.CLASS;
|
|
15
18
|
metadata: PluginMetadata;
|
|
19
|
+
providers?: ProviderRecord[];
|
|
16
20
|
}
|
|
17
21
|
export interface PluginFactoryRecord extends FactoryType<any, any[]> {
|
|
18
22
|
kind: PluginKind.FACTORY;
|
|
19
23
|
metadata: PluginMetadata;
|
|
24
|
+
providers?: ProviderRecord[];
|
|
20
25
|
}
|
|
21
|
-
export
|
|
26
|
+
export interface PluginValueRecord extends ValueType<any> {
|
|
27
|
+
kind: PluginKind.VALUE;
|
|
28
|
+
metadata: PluginMetadata;
|
|
29
|
+
providers?: ProviderRecord[];
|
|
30
|
+
}
|
|
31
|
+
export type PluginRecord = PluginClassTokenRecord | PluginClassRecord | PluginFactoryRecord | PluginValueRecord;
|
|
@@ -6,6 +6,6 @@ var PluginKind;
|
|
|
6
6
|
PluginKind["CLASS_TOKEN"] = "CLASS_TOKEN";
|
|
7
7
|
PluginKind["CLASS"] = "CLASS";
|
|
8
8
|
PluginKind["FACTORY"] = "FACTORY";
|
|
9
|
+
PluginKind["VALUE"] = "VALUE";
|
|
9
10
|
})(PluginKind || (exports.PluginKind = PluginKind = {}));
|
|
10
|
-
;
|
|
11
11
|
//# sourceMappingURL=plugin.record.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.record.js","sourceRoot":"","sources":["../../../src/records/plugin.record.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plugin.record.js","sourceRoot":"","sources":["../../../src/records/plugin.record.ts"],"names":[],"mappings":";;;AAIA,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,yCAA2B,CAAA;IAC3B,6BAAe,CAAA;IACf,iCAAmB,CAAA;IACnB,6BAAe,CAAA;AACjB,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB","sourcesContent":["import {ClassType, FactoryType, Type, ValueType} from '../interfaces';\nimport {PluginMetadata} from '../metadata';\nimport {ProviderRecord} from \"./provider.record\";\n\nexport enum PluginKind {\n CLASS_TOKEN = 'CLASS_TOKEN',\n CLASS = 'CLASS',\n FACTORY = 'FACTORY',\n VALUE = 'VALUE',\n}\n\nexport interface PluginClassTokenRecord {\n kind: PluginKind.CLASS_TOKEN;\n provide: Type,\n metadata: PluginMetadata;\n providers?: ProviderRecord[];\n}\n\nexport interface PluginClassRecord extends ClassType<any> {\n kind: PluginKind.CLASS;\n metadata: PluginMetadata;\n providers?: ProviderRecord[];\n}\n\nexport interface PluginFactoryRecord extends FactoryType<any, any[]> {\n kind: PluginKind.FACTORY;\n metadata: PluginMetadata;\n providers?: ProviderRecord[];\n}\n\nexport interface PluginValueRecord extends ValueType<any> {\n kind: PluginKind.VALUE;\n metadata: PluginMetadata;\n providers?: ProviderRecord[];\n}\n\nexport type PluginRecord =\n | PluginClassTokenRecord\n | PluginClassRecord\n | PluginFactoryRecord\n | PluginValueRecord\n\n\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.record.js","sourceRoot":"","sources":["../../../src/records/tool.record.ts"],"names":[],"mappings":";;;AAIA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,uCAA2B,CAAA;IAC3B,iCAAqB,CAAA;AACvB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB","sourcesContent":["import {ToolContext, Type} from '../interfaces';\nimport {ToolMetadata} from '../metadata';\n\n\nexport enum ToolKind {\n CLASS_TOKEN = 'CLASS_TOKEN',\n FUNCTION = 'FUNCTION',\n}\n\nexport type ToolClassTokenRecord = {\n kind: ToolKind.CLASS_TOKEN;\n provide: Type<ToolContext
|
|
1
|
+
{"version":3,"file":"tool.record.js","sourceRoot":"","sources":["../../../src/records/tool.record.ts"],"names":[],"mappings":";;;AAIA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,uCAA2B,CAAA;IAC3B,iCAAqB,CAAA;AACvB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB","sourcesContent":["import {ToolContext, Type} from '../interfaces';\nimport {ToolMetadata} from '../metadata';\n\n\nexport enum ToolKind {\n CLASS_TOKEN = 'CLASS_TOKEN',\n FUNCTION = 'FUNCTION',\n}\n\nexport type ToolClassTokenRecord = {\n kind: ToolKind.CLASS_TOKEN;\n provide: Type<ToolContext>;\n metadata: ToolMetadata\n};\n\nexport type ToolFunctionTokenRecord = {\n kind: ToolKind.FUNCTION;\n provide: (...args: any[]) => any | Promise<any>;\n metadata: ToolMetadata\n};\n\nexport type ToolRecord =\n | ToolClassTokenRecord\n | ToolFunctionTokenRecord;\n"]}
|
|
@@ -20,7 +20,11 @@ exports.annotatedFrontMcpAuthProvidersSchema = zod_1.z.custom((v) => {
|
|
|
20
20
|
(v['useFactory'] && metadata_1.frontMcpAuthProviderMetadataSchema.passthrough().safeParse(v).success);
|
|
21
21
|
}, { message: 'plugins items must be annotated with @AuthProvider() | @FrontMcpAuthProvider().' });
|
|
22
22
|
exports.annotatedFrontMcpPluginsSchema = zod_1.z.custom((v) => {
|
|
23
|
-
return (typeof v === 'function' && Reflect.hasMetadata(tokens_1.FrontMcpPluginTokens.type, v))
|
|
23
|
+
return (typeof v === 'function' && Reflect.hasMetadata(tokens_1.FrontMcpPluginTokens.type, v))
|
|
24
|
+
||
|
|
25
|
+
(v['useValue'] && Reflect.hasMetadata(tokens_1.FrontMcpPluginTokens.type, v.useValue.constructor))
|
|
26
|
+
||
|
|
27
|
+
(v['useFactory'] && metadata_1.frontMcpPluginMetadataSchema.passthrough().safeParse(v).success);
|
|
24
28
|
}, { message: 'plugins items must be annotated with @Plugin() | @FrontMcpPlugin().' });
|
|
25
29
|
exports.annotatedFrontMcpAdaptersSchema = zod_1.z.custom((v) => {
|
|
26
30
|
return typeof v === 'function' && Reflect.hasMetadata(tokens_1.FrontMcpAdapterTokens.type, v)
|