capable-kit 0.0.1-alpha.8 → 0.1.0-alpha.10
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/CHANGELOG.md +214 -0
- package/README.md +6 -0
- package/dist/ai-sdk.d.mts +3 -3
- package/dist/ai-sdk.mjs +9 -7
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +2 -2
- package/dist/bin.mjs +4 -4
- package/dist/cli.d.mts +9 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +1 -1
- package/dist/eve.d.mts +82 -5
- package/dist/eve.mjs +364 -23
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-F4ba_olD.d.mts → index-1A44jLuE.d.mts} +54 -16
- package/dist/{index-Dl4NK9G0.d.mts → index-CHuCLJIs.d.mts} +3 -3
- package/dist/{index-hdH_K5Zc.d.mts → index-D-NV4PiU.d.mts} +4 -4
- package/dist/{index-_qKFfWV4.d.mts → index-WiBWfyTn.d.mts} +63 -26
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +7 -2
- package/dist/mcp.mjs +1 -1
- package/dist/{mount-CEFAplR5.mjs → mount-BmLHp349.mjs} +16 -8
- package/dist/mount-BmLHp349.mjs.map +1 -0
- package/dist/react-query.d.mts +2 -2
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +3 -3
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-D_0PIhqq.mjs → src-3LE9S4QE.mjs} +67 -38
- package/dist/src-3LE9S4QE.mjs.map +1 -0
- package/dist/{src-D-cm2gQ6.mjs → src-B2WeUwUT.mjs} +64 -32
- package/dist/src-B2WeUwUT.mjs.map +1 -0
- package/dist/{src-BWxDO2Ua.mjs → src-C5jGDnuu.mjs} +3 -3
- package/dist/{src-BWxDO2Ua.mjs.map → src-C5jGDnuu.mjs.map} +1 -1
- package/dist/src-DePlcG_t.mjs +787 -0
- package/dist/src-DePlcG_t.mjs.map +1 -0
- package/dist/{src-rkr5j_NH.mjs → src-_6OmFRYa.mjs} +28 -10
- package/dist/src-_6OmFRYa.mjs.map +1 -0
- package/dist/{subscription-B-auXJbm.d.mts → subscription-DPdwovhw.d.mts} +2 -2
- package/dist/swr.d.mts +2 -2
- package/dist/swr.mjs +1 -1
- package/dist/swr.mjs.map +1 -1
- package/docs/CONTEXT.md +39 -20
- package/docs/README.md +3 -0
- package/docs/internal/README.md +3 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +1 -1
- package/docs/internal/adr/0003-capability-reference-customization.md +68 -0
- package/docs/internal/architecture.md +31 -17
- package/docs/internal/capability-first-model.md +126 -17
- package/docs/internal/eve-recovery-validation.md +86 -0
- package/docs/internal/feedback/v-ray/README.md +258 -0
- package/docs/internal/feedback/v-ray/inference.mjs +43 -0
- package/docs/internal/feedback/v-ray/reproduce.mjs +36 -0
- package/docs/internal/implementation-friction.md +386 -1
- package/docs/internal/releases.md +79 -0
- package/docs/site/capable-orpc-and-trpc.mdx +2 -2
- package/docs/site/concepts/apps.mdx +7 -1
- package/docs/site/concepts/architecture.mdx +9 -1
- package/docs/site/concepts/capabilities.mdx +41 -4
- package/docs/site/concepts/errors.mdx +11 -1
- package/docs/site/concepts/presentations.mdx +20 -0
- package/docs/site/patterns/composition.mdx +152 -8
- package/docs/site/patterns/remote-apps.mdx +6 -2
- package/docs/site/patterns/subscriptions.mdx +79 -32
- package/docs/site/quickstart.mdx +1 -1
- package/docs/site/reference/packages-and-entry-points.mdx +50 -3
- package/docs/site/surfaces/cli.mdx +44 -0
- package/docs/site/surfaces/eve.mdx +65 -18
- package/docs/site/surfaces/typescript.mdx +3 -3
- package/package-docs.mjs +3 -0
- package/package.json +10 -11
- package/src/bin.ts +0 -0
- package/src/index.test.ts +2 -1
- package/src/index.ts +6 -1
- package/src/package.test.ts +9 -0
- package/dist/mount-CEFAplR5.mjs.map +0 -1
- package/dist/src-D-cm2gQ6.mjs.map +0 -1
- package/dist/src-D_0PIhqq.mjs.map +0 -1
- package/dist/src-betOfnDL.mjs +0 -481
- package/dist/src-betOfnDL.mjs.map +0 -1
- package/dist/src-rkr5j_NH.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as CapabilityTree, O as AppContext, V as PresentationPart, Y as MaybePromise, a as CapabilityDefinition, ct as InferSchemaInput, j as CapabilityGroupDefinition, k as AppDefinition, m as CapabilityOutput, ot as AnyObjectSchema, s as CapabilityExecution, t as AnyCapability, v as SubscribableCapability } from "./index-WiBWfyTn.mjs";
|
|
2
2
|
//#region packages/app/src/manifest.d.ts
|
|
3
3
|
type JsonSchema = Readonly<Record<string, unknown>>;
|
|
4
4
|
type ManifestError = {
|
|
@@ -9,15 +9,20 @@ type ManifestError = {
|
|
|
9
9
|
};
|
|
10
10
|
type ManifestCapability = {
|
|
11
11
|
readonly type: "capability";
|
|
12
|
+
readonly customization?: {
|
|
13
|
+
/** Use the Capability's placed path for surface navigation. */
|
|
14
|
+
readonly navigation?: "destination";
|
|
15
|
+
readonly title?: string;
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
readonly meta?: Readonly<Record<string, unknown>>;
|
|
18
|
+
};
|
|
12
19
|
readonly id: string;
|
|
13
20
|
readonly path: readonly string[];
|
|
14
21
|
readonly title?: string;
|
|
15
22
|
readonly description?: string;
|
|
16
23
|
readonly deprecated: boolean;
|
|
17
24
|
readonly effect?: "read" | "write" | "destructive";
|
|
18
|
-
readonly
|
|
19
|
-
readonly mode: "replace";
|
|
20
|
-
};
|
|
25
|
+
readonly execution: CapabilityExecution;
|
|
21
26
|
readonly input?: JsonSchema;
|
|
22
27
|
readonly output?: JsonSchema;
|
|
23
28
|
readonly errors: Readonly<Record<string, ManifestError>>;
|
|
@@ -33,13 +38,14 @@ type ManifestGroup = {
|
|
|
33
38
|
};
|
|
34
39
|
type ManifestNode = ManifestGroup | ManifestCapability;
|
|
35
40
|
type ApplicationManifest = {
|
|
36
|
-
readonly protocol: "capable.capabilities.
|
|
41
|
+
readonly protocol: "capable.capabilities.v4";
|
|
37
42
|
readonly name: string;
|
|
38
43
|
readonly version: string;
|
|
39
44
|
readonly description?: string;
|
|
40
45
|
readonly capabilities: readonly ManifestNode[];
|
|
41
46
|
};
|
|
42
47
|
declare function createAppManifest(definition: AppDefinition<any>): ApplicationManifest;
|
|
48
|
+
declare function flattenManifestCapabilities(nodes: readonly ManifestNode[]): readonly ManifestCapability[];
|
|
43
49
|
//#endregion
|
|
44
50
|
//#region packages/app/src/runtime.d.ts
|
|
45
51
|
type CapabilityCall = {
|
|
@@ -57,12 +63,12 @@ interface ApplicationTransport {
|
|
|
57
63
|
readonly signal?: AbortSignal;
|
|
58
64
|
}): Promise<ApplicationManifest>;
|
|
59
65
|
call(call: CapabilityCall): Promise<CapabilityResult>;
|
|
60
|
-
subscribe(call: CapabilityCall): AsyncIterableIterator<CapabilityResult
|
|
66
|
+
subscribe(call: CapabilityCall): Promise<AsyncIterableIterator<CapabilityResult>>;
|
|
61
67
|
}
|
|
62
68
|
declare const APP_RUNTIME_SYMBOL: unique symbol;
|
|
63
69
|
declare const APP_CAPABILITIES_SYMBOL: unique symbol;
|
|
64
|
-
type
|
|
65
|
-
readonly "~capable/capability"
|
|
70
|
+
type AppCapabilityReference<TCapability extends AnyCapability = AnyCapability> = {
|
|
71
|
+
readonly "~capable/capability": TCapability;
|
|
66
72
|
};
|
|
67
73
|
type AppCapabilityInput<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<any, infer TInput, any, any, any> ? TInput extends AnyObjectSchema ? InferSchemaInput<TInput> : Record<never, never> : never;
|
|
68
74
|
type AppCapabilityOutput<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<any, any, infer TOutput, any, any> ? TOutput : never;
|
|
@@ -70,9 +76,10 @@ type AppCapabilityOptions = {
|
|
|
70
76
|
readonly signal?: AbortSignal;
|
|
71
77
|
};
|
|
72
78
|
type AppCapabilityArgs<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<any, infer TInput, any, any, any> ? TInput extends undefined ? [input?: Record<never, never>, options?: AppCapabilityOptions] : Record<never, never> extends AppCapabilityInput<TCapability> ? [input?: AppCapabilityInput<TCapability>, options?: AppCapabilityOptions] : [input: AppCapabilityInput<TCapability>, options?: AppCapabilityOptions] : never;
|
|
73
|
-
type AppCapabilityCall<TCapability extends AnyCapability> = ((...args: AppCapabilityArgs<TCapability>) => Promise<AppCapabilityOutput<TCapability>>) &
|
|
74
|
-
type AppCapabilityIsSubscribable<TCall> = TCall extends
|
|
75
|
-
type
|
|
79
|
+
type AppCapabilityCall<TCapability extends AnyCapability> = ((...args: AppCapabilityArgs<TCapability>) => Promise<AppCapabilityOutput<TCapability>>) & AppCapabilityReference<TCapability>;
|
|
80
|
+
type AppCapabilityIsSubscribable<TCall> = TCall extends AppCapabilityReference<infer TCapability> ? TCapability["execution"] extends "live" | "events" ? true : false : false;
|
|
81
|
+
type AppCapabilityIsLive<TCall> = TCall extends AppCapabilityReference<infer TCapability> ? TCapability["execution"] extends "live" ? true : false : false;
|
|
82
|
+
type CallableTree<TTree> = TTree extends AnyCapability ? TTree["execution"] extends "events" ? AppCapabilityReference<TTree> : AppCapabilityCall<TTree> : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any> ? CallableTree<TCapabilities> : TTree extends CapabilityTree ? { readonly [TKey in keyof TTree]: CallableTree<TTree[TKey]>; } : never;
|
|
76
83
|
type App<TCapabilities extends CapabilityTree = CapabilityTree> = CallableTree<TCapabilities> & {
|
|
77
84
|
readonly [APP_RUNTIME_SYMBOL]: ApplicationTransport;
|
|
78
85
|
readonly [APP_CAPABILITIES_SYMBOL]?: TCapabilities;
|
|
@@ -87,7 +94,7 @@ type AppCapabilities<TApplication extends AnyApp> = TApplication extends {
|
|
|
87
94
|
} ? TCapabilities : never;
|
|
88
95
|
declare function getAppRuntime(app: AnyApp): ApplicationTransport;
|
|
89
96
|
declare function isApp(value: unknown): value is AnyApp;
|
|
90
|
-
declare function subscribe<const TCapability extends SubscribableCapability>(capabilityCall:
|
|
97
|
+
declare function subscribe<const TCapability extends SubscribableCapability>(capabilityCall: AppCapabilityReference<TCapability>, ...args: AppCapabilityArgs<TCapability>): AsyncIterableIterator<CapabilityOutput<TCapability>>;
|
|
91
98
|
type AppContextProvider<TContext> = (call: {
|
|
92
99
|
readonly id: string;
|
|
93
100
|
readonly signal?: AbortSignal;
|
|
@@ -110,10 +117,41 @@ declare class TransportError extends Error {
|
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
119
|
//#endregion
|
|
120
|
+
//#region packages/app/src/customization.d.ts
|
|
121
|
+
declare global {
|
|
122
|
+
interface CapableCustomizationMeta {}
|
|
123
|
+
}
|
|
124
|
+
type CapabilityCustomization = {
|
|
125
|
+
readonly title?: string;
|
|
126
|
+
readonly description?: string;
|
|
127
|
+
readonly meta?: keyof CapableCustomizationMeta extends never ? never : Partial<CapableCustomizationMeta>;
|
|
128
|
+
};
|
|
129
|
+
declare const CUSTOMIZED_SYMBOL: unique symbol;
|
|
130
|
+
type CustomizedCapability<TCapability extends AnyCapability = any> = {
|
|
131
|
+
readonly [CUSTOMIZED_SYMBOL]: true;
|
|
132
|
+
readonly reference: AppCapabilityReference<TCapability>;
|
|
133
|
+
readonly customization: CapabilityCustomization;
|
|
134
|
+
};
|
|
135
|
+
/** Customize a bound local or remote reference without changing its execution. */
|
|
136
|
+
declare function customize<TCapability extends AnyCapability>(reference: AppCapabilityReference<TCapability> | CustomizedCapability<TCapability>, options: CapabilityCustomization): CustomizedCapability<TCapability>;
|
|
137
|
+
/** Surface-facing fields only. Policies and executors retain the source contract. */
|
|
138
|
+
declare function getCapabilityDisplay(capability: ManifestCapability): {
|
|
139
|
+
readonly title?: string;
|
|
140
|
+
readonly description?: string;
|
|
141
|
+
readonly meta: Readonly<Record<string, unknown>>;
|
|
142
|
+
};
|
|
143
|
+
/** Navigation overrides come from the destination only for relocated leaves. */
|
|
144
|
+
declare function getCapabilityNavigationMeta<TSurface extends keyof CapableCustomizationMeta>(capability: ManifestCapability, surface: TSurface): CapableCustomizationMeta[TSurface] | undefined;
|
|
145
|
+
//#endregion
|
|
113
146
|
//#region packages/app/src/composition.d.ts
|
|
114
147
|
type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
|
|
115
|
-
type
|
|
116
|
-
|
|
148
|
+
type AppComposition = AnyApp | {
|
|
149
|
+
readonly [key: string]: AppComposition | AppCapabilityReference | CustomizedCapability;
|
|
150
|
+
};
|
|
151
|
+
type ComposedNode<TNode> = TNode extends AnyApp ? AppCapabilities<TNode> : TNode extends CustomizedCapability<infer TCapability> ? TCapability : TNode extends AppCapabilityReference<infer TCapability> ? TCapability : TNode extends Readonly<Record<string, unknown>> ? { readonly [TKey in keyof TNode]: ComposedNode<TNode[TKey]>; } : never;
|
|
152
|
+
type ComposedCapabilities<TNodes extends readonly AppComposition[]> = UnionToIntersection<ComposedNode<TNodes[number]>> extends (infer TCapabilities extends CapabilityTree) ? TCapabilities : never;
|
|
153
|
+
/** Compose executable Apps, subtrees, and Capability references into one tree. */
|
|
154
|
+
declare function composeApps<const TNodes extends readonly [AppComposition, ...AppComposition[]]>(...nodes: TNodes): App<ComposedCapabilities<TNodes>>;
|
|
117
155
|
type SelectionNode<TTree> = TTree extends AnyCapability ? true : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any> ? true | SelectionNode<TCapabilities> : TTree extends CapabilityTree ? true | { readonly [TKey in keyof TTree]?: SelectionNode<TTree[TKey]>; } : never;
|
|
118
156
|
type ApplicationSelection<TCapabilities extends CapabilityTree = CapabilityTree> = {
|
|
119
157
|
readonly include?: Exclude<SelectionNode<TCapabilities>, true>;
|
|
@@ -121,5 +159,5 @@ type ApplicationSelection<TCapabilities extends CapabilityTree = CapabilityTree>
|
|
|
121
159
|
};
|
|
122
160
|
declare function selectApp<const TCapabilities extends CapabilityTree>(application: App<TCapabilities>, selection: ApplicationSelection<TCapabilities>): App<TCapabilities>;
|
|
123
161
|
//#endregion
|
|
124
|
-
export { JsonSchema as C,
|
|
125
|
-
//# sourceMappingURL=index-
|
|
162
|
+
export { JsonSchema as A, TransportError as C, isApp as D, getAppRuntime as E, createAppManifest as F, flattenManifestCapabilities as I, ManifestError as M, ManifestGroup as N, subscribe as O, ManifestNode as P, CapabilityResult as S, createRemoteApp as T, AppCapabilityReference as _, CustomizedCapability as a, CallableTree as b, getCapabilityNavigationMeta as c, AnyApp as d, App as f, AppCapabilityIsSubscribable as g, AppCapabilityIsLive as h, CapabilityCustomization as i, ManifestCapability as j, ApplicationManifest as k, APP_CAPABILITIES_SYMBOL as l, AppCapabilityCall as m, composeApps as n, customize as o, AppCapabilities as p, selectApp as r, getCapabilityDisplay as s, ApplicationSelection as t, APP_RUNTIME_SYMBOL as u, AppContextProvider as v, createApp as w, CapabilityCall as x, ApplicationTransport as y };
|
|
163
|
+
//# sourceMappingURL=index-1A44jLuE.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { M as CapabilityTree, P as LocatedCapability, k as AppDefinition } from "./index-WiBWfyTn.mjs";
|
|
2
|
+
import { d as AnyApp, t as ApplicationSelection, y as ApplicationTransport } from "./index-1A44jLuE.mjs";
|
|
3
3
|
//#region packages/fetch/src/codec.d.ts
|
|
4
4
|
type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
5
5
|
readonly [key: string]: JsonValue;
|
|
@@ -70,4 +70,4 @@ declare function createHttpHandler<const TCapabilities extends CapabilityTree, T
|
|
|
70
70
|
};
|
|
71
71
|
//#endregion
|
|
72
72
|
export { HttpGroupMeta as a, FetchHandler as c, createProtocolHandler as d, JsonValue as f, HttpCapabilityMeta as i, TransportHeaders as l, defineProtocolCodec as m, CompiledHttpRoute as n, HttpMethod as o, ProtocolCodec as p, ContextProvider as r, createHttpHandler as s, CapabilitySelection as t, createHttpTransport as u };
|
|
73
|
-
//# sourceMappingURL=index-
|
|
73
|
+
//# sourceMappingURL=index-CHuCLJIs.d.mts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as ApplicationSelection } from "./index-
|
|
3
|
-
import { p as ProtocolCodec, r as ContextProvider, t as CapabilitySelection } from "./index-
|
|
1
|
+
import { Y as MaybePromise, k as AppDefinition } from "./index-WiBWfyTn.mjs";
|
|
2
|
+
import { t as ApplicationSelection } from "./index-1A44jLuE.mjs";
|
|
3
|
+
import { p as ProtocolCodec, r as ContextProvider, t as CapabilitySelection } from "./index-CHuCLJIs.mjs";
|
|
4
4
|
//#region packages/server/src/index.d.ts
|
|
5
5
|
type ServerMount<TContext> = {
|
|
6
6
|
readonly kind: "capable.server.mount";
|
|
@@ -40,4 +40,4 @@ type CreateServerArgs<TContext> = [TContext] extends [undefined] ? [options?: Cr
|
|
|
40
40
|
declare function createServer<TContext>(app: AppDefinition<any, TContext>, ...[providedOptions]: CreateServerArgs<TContext>): CapableServer;
|
|
41
41
|
//#endregion
|
|
42
42
|
export { createServer as a, ServerMount as i, CompiledServerMount as n, http as o, ServerMiddleware as r, protocol as s, CapableServer as t };
|
|
43
|
-
//# sourceMappingURL=index-
|
|
43
|
+
//# sourceMappingURL=index-D-NV4PiU.d.mts.map
|
|
@@ -145,7 +145,7 @@ declare function group<const TCapabilities extends CapabilityTree, const TErrors
|
|
|
145
145
|
readonly title?: string;
|
|
146
146
|
readonly description?: string;
|
|
147
147
|
readonly errors?: TErrors;
|
|
148
|
-
readonly middleware?: readonly CapabilityMiddleware<
|
|
148
|
+
readonly middleware?: readonly CapabilityMiddleware<NoInfer<SharedContext<TCapabilities>>>[];
|
|
149
149
|
readonly meta?: TMeta;
|
|
150
150
|
readonly capabilities: TCapabilities;
|
|
151
151
|
}): CapabilityGroupDefinition<TCapabilities, TErrors, TMeta>;
|
|
@@ -162,19 +162,24 @@ type AppDefinition<TCapabilities extends CapabilityTree = CapabilityTree, TConte
|
|
|
162
162
|
readonly name: string;
|
|
163
163
|
readonly version: string;
|
|
164
164
|
readonly description?: string;
|
|
165
|
+
readonly errors: AnyDefinedErrors;
|
|
166
|
+
readonly middleware: readonly CapabilityMiddleware<any>[];
|
|
165
167
|
readonly capabilities: TCapabilities;
|
|
166
168
|
readonly locatedCapabilities: readonly LocatedCapability[];
|
|
167
169
|
readonly "~capable/context"?: TContext;
|
|
168
170
|
};
|
|
169
|
-
type CapabilityTreeContext<TTree> = TTree extends CapabilityDefinition<infer TContext, any, any, any, any> ? TContext : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any> ? CapabilityTreeContext<TCapabilities> : TTree extends Readonly<Record<string, unknown>> ? CapabilityTreeContext<TTree[keyof TTree]> : never;
|
|
171
|
+
type CapabilityTreeContext<TTree> = TTree extends CapabilityDefinition<infer TContext, any, any, any, any> ? TContext : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any> ? CapabilityTreeContext<TCapabilities> : TTree extends Readonly<Record<string, unknown>> ? CapabilityTree extends TTree ? unknown : CapabilityTreeContext<TTree[keyof TTree]> : never;
|
|
170
172
|
type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
|
|
173
|
+
type SharedContext<TCapabilities> = [Exclude<CapabilityTreeContext<TCapabilities>, undefined>] extends [never] ? undefined : UnionToIntersection<Exclude<CapabilityTreeContext<TCapabilities>, undefined>>;
|
|
171
174
|
type AppContext<TDefinition extends AppDefinition<any, any>> = TDefinition extends AppDefinition<any, infer TContext> ? TContext : never;
|
|
172
175
|
declare function defineApp<const TCapabilities extends CapabilityTree>(config: {
|
|
173
176
|
readonly name?: string;
|
|
174
177
|
readonly version?: string;
|
|
175
178
|
readonly description?: string;
|
|
179
|
+
readonly errors?: AnyDefinedErrors;
|
|
180
|
+
readonly middleware?: readonly CapabilityMiddleware<NoInfer<SharedContext<TCapabilities>>>[];
|
|
176
181
|
readonly capabilities: TCapabilities;
|
|
177
|
-
}): AppDefinition<TCapabilities,
|
|
182
|
+
}): AppDefinition<TCapabilities, SharedContext<TCapabilities>>;
|
|
178
183
|
declare function isCapabilityGroup(value: unknown): value is AnyCapabilityGroup;
|
|
179
184
|
//#endregion
|
|
180
185
|
//#region packages/core/src/capability.d.ts
|
|
@@ -197,13 +202,19 @@ type CapabilitySubscriberArgs<TContext, TInput> = {
|
|
|
197
202
|
};
|
|
198
203
|
type CapabilitySubscriber<TContext, TInput, TOutput> = (args: CapabilitySubscriberArgs<TContext, TInput>) => AsyncIterable<TOutput>;
|
|
199
204
|
type CapabilityMiddlewareArgs<TContext, TInput = unknown> = {
|
|
205
|
+
readonly capability: {
|
|
206
|
+
readonly id: string;
|
|
207
|
+
readonly effect: CapabilityEffect | undefined;
|
|
208
|
+
};
|
|
209
|
+
readonly mode: "call" | "subscribe";
|
|
200
210
|
readonly input: TInput;
|
|
201
211
|
readonly context: TContext;
|
|
202
212
|
readonly signal?: AbortSignal;
|
|
203
213
|
next(): Promise<unknown>;
|
|
204
214
|
};
|
|
205
215
|
type CapabilityMiddleware<TContext, TInput = unknown> = (args: CapabilityMiddlewareArgs<TContext, TInput>) => MaybePromise<unknown>;
|
|
206
|
-
type
|
|
216
|
+
type CapabilityExecution = "unary" | "live" | "events";
|
|
217
|
+
type CapabilityDefinition<TContext = unknown, TInput extends AnyObjectSchema | undefined = AnyObjectSchema | undefined, TOutput = unknown, TErrors extends AnyDefinedErrors = AnyDefinedErrors, TMeta extends OpenMeta<CapabilityMetaRegistry> = OpenMeta<CapabilityMetaRegistry>, TExecution extends CapabilityExecution = CapabilityExecution> = {
|
|
207
218
|
readonly [CAPABILITY_SYMBOL]: true;
|
|
208
219
|
readonly id: string;
|
|
209
220
|
readonly title?: string;
|
|
@@ -215,19 +226,31 @@ type CapabilityDefinition<TContext = unknown, TInput extends AnyObjectSchema | u
|
|
|
215
226
|
readonly errors: TErrors;
|
|
216
227
|
readonly middleware: readonly CapabilityMiddleware<TContext, ParsedInput<TInput>>[];
|
|
217
228
|
readonly meta: TMeta;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
toPresentation?(output: TOutput, options: {
|
|
230
|
+
readonly context: TContext;
|
|
231
|
+
}): MaybePromise<PresentationValue>;
|
|
221
232
|
readonly "~capable/context"?: (context: TContext) => TContext;
|
|
222
233
|
readonly "~capable/input"?: TInput;
|
|
223
234
|
readonly "~capable/output"?: TOutput;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
235
|
+
} & (TExecution extends "events" ? {
|
|
236
|
+
readonly execution: "events";
|
|
237
|
+
readonly handler?: never;
|
|
238
|
+
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, any>;
|
|
239
|
+
} : TExecution extends "live" ? {
|
|
240
|
+
readonly execution: "live";
|
|
241
|
+
readonly handler: (args: CapabilityHandlerArgs<TContext, ParsedInput<TInput>>) => MaybePromise<TOutput>;
|
|
242
|
+
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, any>;
|
|
243
|
+
} : {
|
|
244
|
+
readonly execution: "unary";
|
|
245
|
+
readonly handler: (args: CapabilityHandlerArgs<TContext, ParsedInput<TInput>>) => MaybePromise<TOutput>;
|
|
246
|
+
readonly subscribe?: never;
|
|
247
|
+
});
|
|
248
|
+
type AnyCapability = CapabilityDefinition<any, any, any, any, any, CapabilityExecution>;
|
|
227
249
|
type CapabilityInput<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<any, infer TInput, any, any, any> ? TInput extends AnyObjectSchema ? InferSchemaInput<TInput> : EmptyInput : never;
|
|
228
250
|
type CapabilityOutput<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<any, any, infer TOutput, any, any> ? TOutput : never;
|
|
229
251
|
type CapabilityContext<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<infer TContext, any, any, any, any> ? TContext : never;
|
|
230
|
-
type SubscribableCapability = CapabilityDefinition<any, any, any, any, any,
|
|
252
|
+
type SubscribableCapability = CapabilityDefinition<any, any, any, any, any, "live" | "events">;
|
|
253
|
+
type CallableCapability = CapabilityDefinition<any, any, any, any, any, "unary" | "live">;
|
|
231
254
|
type ExecuteCapabilityOptions<TCapability extends AnyCapability> = TCapability extends CapabilityDefinition<infer TContext, infer TInput, any, any, any> ? (TInput extends AnyObjectSchema ? {
|
|
232
255
|
readonly input: InferSchemaInput<TInput>;
|
|
233
256
|
} : {
|
|
@@ -256,32 +279,46 @@ type ExplicitOutputCapabilityConfig<TContext, TInput extends AnyObjectSchema | u
|
|
|
256
279
|
readonly toPresentation?: PresentationRenderer<InferSchemaOutput<TOutput>, TContext>;
|
|
257
280
|
readonly subscribe?: CapabilitySubscriber<TContext, ParsedInput<TInput>, InferSchemaInput<TOutput>>;
|
|
258
281
|
};
|
|
259
|
-
type InferredOutputCapabilityConfig<TContext, TInput extends AnyObjectSchema | undefined,
|
|
282
|
+
type InferredOutputCapabilityConfig<TContext, TInput extends AnyObjectSchema | undefined, TReturn, TErrors extends AnyDefinedErrors, TMeta extends OpenMeta<CapabilityMetaRegistry>> = CapabilityBaseConfig<TContext, TInput, TErrors, TMeta> & {
|
|
283
|
+
readonly output?: never;
|
|
284
|
+
readonly handler: (args: CapabilityHandlerArgs<TContext, ParsedInput<TInput>>) => TReturn;
|
|
285
|
+
readonly toPresentation?: PresentationRenderer<Awaited<TReturn>, TContext>;
|
|
286
|
+
readonly subscribe?: CapabilitySubscriber<TContext, ParsedInput<TInput>, Awaited<TReturn>>;
|
|
287
|
+
};
|
|
288
|
+
type ExplicitEventConfig<TContext, TInput extends AnyObjectSchema | undefined, TOutput extends AnySchema, TErrors extends AnyDefinedErrors, TMeta extends OpenMeta<CapabilityMetaRegistry>> = Omit<ExplicitOutputCapabilityConfig<TContext, TInput, TOutput, TErrors, TMeta>, "handler" | "subscribe" | "effect"> & {
|
|
289
|
+
readonly handler?: never;
|
|
290
|
+
readonly effect: "read";
|
|
291
|
+
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, InferSchemaInput<TOutput>>;
|
|
292
|
+
};
|
|
293
|
+
type InferredEventConfig<TContext, TInput extends AnyObjectSchema | undefined, TOutput, TErrors extends AnyDefinedErrors, TMeta extends OpenMeta<CapabilityMetaRegistry>> = CapabilityBaseConfig<TContext, TInput, TErrors, TMeta> & {
|
|
294
|
+
readonly handler?: never;
|
|
260
295
|
readonly output?: never;
|
|
261
|
-
readonly
|
|
262
|
-
readonly
|
|
263
|
-
readonly
|
|
296
|
+
readonly effect: "read";
|
|
297
|
+
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, TOutput>;
|
|
298
|
+
readonly toPresentation?: PresentationRenderer<NoInfer<TOutput>, TContext>;
|
|
264
299
|
};
|
|
265
300
|
type CapabilityFactory<TContext> = {
|
|
301
|
+
<TInput extends AnyObjectSchema | undefined = undefined, TOutput extends AnySchema = AnySchema, const TErrors extends AnyDefinedErrors = DefinedNoErrors, const TMeta extends OpenMeta<CapabilityMetaRegistry> = {}>(config: ExplicitEventConfig<TContext, TInput, TOutput, TErrors, TMeta>): CapabilityDefinition<TContext, TInput, InferSchemaOutput<TOutput>, TErrors, TMeta, "events">;
|
|
302
|
+
<TInput extends AnyObjectSchema | undefined = undefined, TOutput = unknown, const TErrors extends AnyDefinedErrors = DefinedNoErrors, const TMeta extends OpenMeta<CapabilityMetaRegistry> = {}>(config: InferredEventConfig<TContext, TInput, TOutput, TErrors, TMeta>): CapabilityDefinition<TContext, TInput, TOutput, TErrors, TMeta, "events">;
|
|
266
303
|
<TInput extends AnyObjectSchema | undefined = undefined, TOutput extends AnySchema = AnySchema, const TErrors extends AnyDefinedErrors = DefinedNoErrors, const TMeta extends OpenMeta<CapabilityMetaRegistry> = {}>(config: ExplicitOutputCapabilityConfig<TContext, TInput, TOutput, TErrors, TMeta> & {
|
|
267
304
|
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, InferSchemaInput<TOutput>>;
|
|
268
|
-
}): CapabilityDefinition<TContext, TInput, InferSchemaOutput<TOutput>, TErrors, TMeta,
|
|
305
|
+
}): CapabilityDefinition<TContext, TInput, InferSchemaOutput<TOutput>, TErrors, TMeta, "live">;
|
|
269
306
|
<TInput extends AnyObjectSchema | undefined = undefined, TOutput extends AnySchema = AnySchema, const TErrors extends AnyDefinedErrors = DefinedNoErrors, const TMeta extends OpenMeta<CapabilityMetaRegistry> = {}>(config: ExplicitOutputCapabilityConfig<TContext, TInput, TOutput, TErrors, TMeta> & {
|
|
270
307
|
readonly subscribe?: never;
|
|
271
|
-
}): CapabilityDefinition<TContext, TInput, InferSchemaOutput<TOutput>, TErrors, TMeta,
|
|
272
|
-
<TInput extends AnyObjectSchema | undefined = undefined,
|
|
273
|
-
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, Awaited<
|
|
274
|
-
}): CapabilityDefinition<TContext, TInput, Awaited<
|
|
275
|
-
<TInput extends AnyObjectSchema | undefined = undefined,
|
|
308
|
+
}): CapabilityDefinition<TContext, TInput, InferSchemaOutput<TOutput>, TErrors, TMeta, "unary">;
|
|
309
|
+
<TInput extends AnyObjectSchema | undefined = undefined, TReturn = unknown, const TErrors extends AnyDefinedErrors = DefinedNoErrors, const TMeta extends OpenMeta<CapabilityMetaRegistry> = {}>(config: InferredOutputCapabilityConfig<TContext, TInput, TReturn, TErrors, TMeta> & {
|
|
310
|
+
readonly subscribe: CapabilitySubscriber<TContext, ParsedInput<TInput>, Awaited<TReturn>>;
|
|
311
|
+
}): CapabilityDefinition<TContext, TInput, Awaited<TReturn>, TErrors, TMeta, "live">;
|
|
312
|
+
<TInput extends AnyObjectSchema | undefined = undefined, TReturn = unknown, const TErrors extends AnyDefinedErrors = DefinedNoErrors, const TMeta extends OpenMeta<CapabilityMetaRegistry> = {}>(config: InferredOutputCapabilityConfig<TContext, TInput, TReturn, TErrors, TMeta> & {
|
|
276
313
|
readonly subscribe?: never;
|
|
277
|
-
}): CapabilityDefinition<TContext, TInput, Awaited<
|
|
314
|
+
}): CapabilityDefinition<TContext, TInput, Awaited<TReturn>, TErrors, TMeta, "unary">;
|
|
278
315
|
};
|
|
279
316
|
type CapabilityFunction = CapabilityFactory<undefined> & {
|
|
280
317
|
<TContext>(): CapabilityFactory<TContext>;
|
|
281
318
|
withContext<TContext>(): CapabilityFactory<TContext>;
|
|
282
319
|
};
|
|
283
320
|
declare const capability: CapabilityFunction;
|
|
284
|
-
declare function executeCapability<const TCapability extends
|
|
321
|
+
declare function executeCapability<const TCapability extends CallableCapability>(capability: TCapability, options: ExecuteCapabilityOptions<TCapability>): Promise<CapabilityOutput<TCapability>>;
|
|
285
322
|
declare function executeLocatedCapability(located: LocatedCapability, input: unknown, options: {
|
|
286
323
|
readonly context: unknown;
|
|
287
324
|
readonly signal?: AbortSignal;
|
|
@@ -291,8 +328,8 @@ declare function subscribeCapability<const TCapability extends SubscribableCapab
|
|
|
291
328
|
declare function subscribeLocatedCapability(located: LocatedCapability, input: unknown, options: {
|
|
292
329
|
readonly context: unknown;
|
|
293
330
|
readonly signal?: AbortSignal;
|
|
294
|
-
}): AsyncIterableIterator<unknown
|
|
331
|
+
}): Promise<AsyncIterableIterator<unknown>>;
|
|
295
332
|
declare function isCapability(value: unknown): value is AnyCapability;
|
|
296
333
|
//#endregion
|
|
297
|
-
export {
|
|
298
|
-
//# sourceMappingURL=index-
|
|
334
|
+
export { CapabilityErrorContract as $, CAPABILITY_GROUP_SYMBOL as A, MarkdownPresentationPart as B, isCapability as C, AnyCapabilityGroup as D, APPLICATION_SYMBOL as E, defineApp as F, TablePresentationPart as G, PresentationRenderer as H, group as I, renderPresentationMarkdown as J, normalizePresentation as K, isCapabilityGroup as L, CapabilityTree as M, GroupMetaRegistry as N, AppContext as O, LocatedCapability as P, CAPABILITY_ERRORS_SYMBOL as Q, FilePresentationPart as R, executeLocatedCapability as S, subscribeLocatedCapability as T, PresentationTableCell as U, PresentationPart as V, PresentationValue as W, md as X, MaybePromise as Y, AnyDefinedErrors as Z, ExecuteCapabilityOptions as _, CapabilityDefinition as a, defineErrors as at, capability as b, CapabilityFactory as c, InferSchemaInput as ct, CapabilityMetaRegistry as d, SchemaValidationError as dt, CapabilityErrorDefinition as et, CapabilityMiddleware as f, parseSchema as ft, CapabilitySubscriberArgs as g, CapabilitySubscriber as h, CapabilityContext as i, ErrorMetaRegistry as it, CapabilityGroupDefinition as j, AppDefinition as k, CapabilityHandlerArgs as l, InferSchemaOutput as lt, CapabilityOutput as m, CAPABILITY_SYMBOL as n, CapableError as nt, CapabilityEffect as o, AnyObjectSchema as ot, CapabilityMiddlewareArgs as p, schemaToJsonSchema as pt, present as q, CallableCapability as r, DefinedErrors as rt, CapabilityExecution as s, AnySchema as st, AnyCapability as t, CapabilityErrorFactory as tt, CapabilityInput as u, Schema as ut, SubscribableCapability as v, subscribeCapability as w, executeCapability as x, SubscribeCapabilityOptions as y, ImagePresentationPart as z };
|
|
335
|
+
//# sourceMappingURL=index-WiBWfyTn.d.mts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as watchQuery, t as WatchQueryOptions } from "./subscription-
|
|
3
|
-
import { _ as
|
|
4
|
-
export { type App, type AppCapabilityCall, type AppContext, type AppContextProvider, type AppDefinition, type ApplicationSelection, type CapabilityContext, type CapabilityDefinition, type CapabilityEffect, type CapabilityFactory, type CapabilityHandlerArgs, type CapabilityInput, type CapabilityMiddleware, type CapabilityMiddlewareArgs, type CapabilityOutput, type CapabilitySubscriber, type CapabilitySubscriberArgs, type CapabilityTree, type DefinedErrors, type ExecuteCapabilityOptions, type PresentationPart, type PresentationRenderer, type PresentationTableCell, type PresentationValue, type WatchQueryOptions, capability, createApp, createRemoteApp, defineApp, defineErrors, executeCapability, group, md,
|
|
1
|
+
import { F as defineApp, H as PresentationRenderer, I as group, M as CapabilityTree, O as AppContext, U as PresentationTableCell, V as PresentationPart, W as PresentationValue, X as md, _ as ExecuteCapabilityOptions, a as CapabilityDefinition, at as defineErrors, b as capability, c as CapabilityFactory, f as CapabilityMiddleware, g as CapabilitySubscriberArgs, h as CapabilitySubscriber, i as CapabilityContext, k as AppDefinition, l as CapabilityHandlerArgs, m as CapabilityOutput, o as CapabilityEffect, p as CapabilityMiddlewareArgs, q as present, rt as DefinedErrors, s as CapabilityExecution, u as CapabilityInput, x as executeCapability } from "./index-WiBWfyTn.mjs";
|
|
2
|
+
import { n as watchQuery, t as WatchQueryOptions } from "./subscription-DPdwovhw.mjs";
|
|
3
|
+
import { O as subscribe, T as createRemoteApp, _ as AppCapabilityReference, a as CustomizedCapability, f as App, i as CapabilityCustomization, m as AppCapabilityCall, n as composeApps, o as customize, r as selectApp, t as ApplicationSelection, v as AppContextProvider, w as createApp } from "./index-1A44jLuE.mjs";
|
|
4
|
+
export { type App, type AppCapabilityCall, type AppCapabilityReference, type AppContext, type AppContextProvider, type AppDefinition, type ApplicationSelection, type CapabilityContext, type CapabilityCustomization, type CapabilityDefinition, type CapabilityEffect, type CapabilityExecution, type CapabilityFactory, type CapabilityHandlerArgs, type CapabilityInput, type CapabilityMiddleware, type CapabilityMiddlewareArgs, type CapabilityOutput, type CapabilitySubscriber, type CapabilitySubscriberArgs, type CapabilityTree, type CustomizedCapability, type DefinedErrors, type ExecuteCapabilityOptions, type PresentationPart, type PresentationRenderer, type PresentationTableCell, type PresentationValue, type WatchQueryOptions, capability, composeApps, createApp, createRemoteApp, customize, defineApp, defineErrors, executeCapability, group, md, present, selectApp, subscribe, watchQuery };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as defineErrors, c as executeCapability, g as watchQuery, i as group, r as defineApp, s as capability, v as present } from "./src-
|
|
1
|
+
import { S as defineErrors, c as executeCapability, g as watchQuery, i as group, r as defineApp, s as capability, v as present } from "./src-B2WeUwUT.mjs";
|
|
2
2
|
import { t as md } from "./projection-Cgq2u0Wt.mjs";
|
|
3
|
-
import { n as selectApp,
|
|
4
|
-
export { capability, createApp, createRemoteApp, defineApp, defineErrors, executeCapability, group, md,
|
|
3
|
+
import { l as createApp, n as selectApp, p as subscribe, r as customize, t as composeApps, u as createRemoteApp } from "./src-DePlcG_t.mjs";
|
|
4
|
+
export { capability, composeApps, createApp, createRemoteApp, customize, defineApp, defineErrors, executeCapability, group, md, present, selectApp, subscribe, watchQuery };
|
package/dist/mcp.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as ServerMount } from "./index-
|
|
1
|
+
import { A as JsonSchema, S as CapabilityResult, d as AnyApp, t as ApplicationSelection } from "./index-1A44jLuE.mjs";
|
|
2
|
+
import { i as ServerMount } from "./index-D-NV4PiU.mjs";
|
|
3
3
|
//#region packages/mcp/src/index.d.ts
|
|
4
4
|
type McpCapabilityMeta = false | {
|
|
5
5
|
readonly name?: string;
|
|
@@ -7,6 +7,11 @@ type McpCapabilityMeta = false | {
|
|
|
7
7
|
readonly idempotentHint?: boolean;
|
|
8
8
|
readonly openWorldHint?: boolean;
|
|
9
9
|
};
|
|
10
|
+
declare global {
|
|
11
|
+
interface CapableCustomizationMeta {
|
|
12
|
+
readonly mcp?: McpCapabilityMeta;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
10
15
|
type McpIcon = {
|
|
11
16
|
readonly src: string;
|
|
12
17
|
readonly mimeType?: string;
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createMcp, t as mcp } from "./mount-
|
|
1
|
+
import { n as createMcp, t as mcp } from "./mount-BmLHp349.mjs";
|
|
2
2
|
export { createMcp, mcp };
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import { y as renderPresentationMarkdown } from "./src-
|
|
2
|
-
import { a as
|
|
1
|
+
import { y as renderPresentationMarkdown } from "./src-B2WeUwUT.mjs";
|
|
2
|
+
import { a as getCapabilityNavigationMeta, c as TransportError, d as getAppRuntime, h as flattenManifestCapabilities, i as getCapabilityDisplay, l as createApp, n as selectApp } from "./src-DePlcG_t.mjs";
|
|
3
3
|
import { Server, createMcpHandler } from "@modelcontextprotocol/server";
|
|
4
4
|
//#region packages/mcp/src/index.ts
|
|
5
5
|
async function createMcp(app) {
|
|
6
6
|
const runtime = getAppRuntime(app);
|
|
7
|
-
const tools =
|
|
7
|
+
const tools = flattenManifestCapabilities((await runtime.manifest()).capabilities).map((capability) => ({
|
|
8
|
+
...capability,
|
|
9
|
+
...getCapabilityDisplay(capability)
|
|
10
|
+
})).filter((capability) => {
|
|
11
|
+
const meta = capability.meta.mcp;
|
|
12
|
+
if (meta === false) return false;
|
|
13
|
+
if (capability.execution !== "events") return true;
|
|
14
|
+
if (meta !== void 0) throw new Error(`Event Capability "${capability.id}" cannot be exposed as an MCP tool`);
|
|
15
|
+
return false;
|
|
16
|
+
}).map((capability) => {
|
|
8
17
|
const meta = readMcpMeta(capability);
|
|
18
|
+
const navigation = getCapabilityNavigationMeta(capability, "mcp");
|
|
19
|
+
const name = navigation === false ? void 0 : navigation?.name;
|
|
9
20
|
return Object.freeze({
|
|
10
|
-
name:
|
|
21
|
+
name: name ?? capability.path.join("__"),
|
|
11
22
|
...capability.title ? { title: capability.title } : {},
|
|
12
23
|
...capability.description ? { description: capability.description } : {},
|
|
13
24
|
...meta?.icons ? { icons: meta.icons } : {},
|
|
@@ -63,9 +74,6 @@ function isRecord(value) {
|
|
|
63
74
|
function invalidMcpMeta(capability, reason) {
|
|
64
75
|
throw new Error(`Capability "${capability.id}" has invalid MCP metadata: ${reason}`);
|
|
65
76
|
}
|
|
66
|
-
function flatten(nodes) {
|
|
67
|
-
return nodes.flatMap((node) => node.type === "capability" ? [node] : flatten(node.children));
|
|
68
|
-
}
|
|
69
77
|
//#endregion
|
|
70
78
|
//#region packages/mcp/src/presentation.ts
|
|
71
79
|
function toMcpContent(presentation, output) {
|
|
@@ -224,4 +232,4 @@ function validateCacheHint(hint, field) {
|
|
|
224
232
|
//#endregion
|
|
225
233
|
export { createMcp as n, mcp as t };
|
|
226
234
|
|
|
227
|
-
//# sourceMappingURL=mount-
|
|
235
|
+
//# sourceMappingURL=mount-BmLHp349.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-BmLHp349.mjs","names":[],"sources":["../../mcp/src/index.ts","../../mcp/src/presentation.ts","../../mcp/src/mount.ts"],"sourcesContent":["import type { CapabilityMetaRegistry } from \"@capable/core\";\nimport {\n getAppRuntime,\n getCapabilityDisplay,\n getCapabilityNavigationMeta,\n flattenManifestCapabilities,\n type AnyApp,\n type JsonSchema,\n type ManifestCapability,\n type CapabilityResult,\n} from \"@capable/app\";\n\nexport type McpCapabilityMeta =\n | false\n | {\n readonly name?: string;\n readonly icons?: readonly McpIcon[];\n readonly idempotentHint?: boolean;\n readonly openWorldHint?: boolean;\n };\n\ndeclare global {\n interface CapableCustomizationMeta {\n readonly mcp?: McpCapabilityMeta;\n }\n}\n\nexport type McpIcon = {\n readonly src: string;\n readonly mimeType?: string;\n readonly sizes?: readonly string[];\n readonly theme?: \"light\" | \"dark\";\n};\n\ndeclare module \"@capable/core\" {\n interface CapabilityMetaRegistry {\n readonly mcp?: McpCapabilityMeta;\n }\n}\n\nexport type McpTool = {\n readonly name: string;\n readonly title?: string;\n readonly description?: string;\n readonly icons?: readonly McpIcon[];\n readonly inputSchema: JsonSchema;\n readonly outputSchema?: JsonSchema;\n readonly _meta: {\n readonly \"dev.capable/capabilityId\": string;\n };\n readonly annotations: {\n readonly readOnlyHint: boolean;\n readonly destructiveHint: boolean;\n readonly idempotentHint?: boolean;\n readonly openWorldHint?: boolean;\n };\n call(\n input: unknown,\n options?: { readonly signal?: AbortSignal },\n ): Promise<CapabilityResult>;\n};\n\nexport async function createMcp(\n app: AnyApp,\n): Promise<readonly McpTool[]> {\n const runtime = getAppRuntime(app);\n const manifest = await runtime.manifest();\n const tools = flattenManifestCapabilities(manifest.capabilities)\n .map((capability) => ({ ...capability, ...getCapabilityDisplay(capability) }))\n .filter((capability) => {\n const meta = capability.meta.mcp;\n if (meta === false) return false;\n if (capability.execution !== \"events\") return true;\n if (meta !== undefined) {\n throw new Error(\n `Event Capability \"${capability.id}\" cannot be exposed as an MCP tool`,\n );\n }\n return false;\n })\n .map((capability) => {\n const meta = readMcpMeta(capability);\n const navigation = getCapabilityNavigationMeta(capability, \"mcp\");\n const name = navigation === false ? undefined : navigation?.name;\n return Object.freeze({\n name: name ?? capability.path.join(\"__\"),\n ...(capability.title ? { title: capability.title } : {}),\n ...(capability.description ? { description: capability.description } : {}),\n ...(meta?.icons ? { icons: meta.icons } : {}),\n inputSchema: capability.input ?? {\n type: \"object\",\n properties: {},\n additionalProperties: false,\n },\n ...(capability.output\n ? { outputSchema: capability.output }\n : {}),\n _meta: {\n \"dev.capable/capabilityId\": capability.id,\n },\n annotations: {\n readOnlyHint: capability.effect === \"read\",\n destructiveHint: capability.effect === \"destructive\",\n ...(meta?.idempotentHint !== undefined\n ? { idempotentHint: meta.idempotentHint }\n : {}),\n ...(meta?.openWorldHint !== undefined\n ? { openWorldHint: meta.openWorldHint }\n : {}),\n },\n call(input: unknown, options?: { readonly signal?: AbortSignal }) {\n return runtime.call({\n id: capability.id,\n input,\n presentation: true,\n ...(options?.signal ? { signal: options.signal } : {}),\n });\n },\n });\n });\n const names = new Set<string>();\n for (const tool of tools) {\n if (names.has(tool.name)) {\n throw new Error(`Duplicate MCP tool name \"${tool.name}\"`);\n }\n names.add(tool.name);\n }\n return tools;\n}\n\nfunction readMcpMeta(\n capability: ManifestCapability,\n): Exclude<McpCapabilityMeta, false> | undefined {\n const value = capability.meta.mcp;\n if (value === undefined) return undefined;\n if (!isRecord(value)) return invalidMcpMeta(capability, \"must be an object\");\n if (value.name !== undefined && typeof value.name !== \"string\") {\n return invalidMcpMeta(capability, \"name must be a string\");\n }\n if (\n value.idempotentHint !== undefined &&\n typeof value.idempotentHint !== \"boolean\"\n ) {\n return invalidMcpMeta(capability, \"idempotentHint must be a boolean\");\n }\n if (\n value.openWorldHint !== undefined &&\n typeof value.openWorldHint !== \"boolean\"\n ) {\n return invalidMcpMeta(capability, \"openWorldHint must be a boolean\");\n }\n if (\n value.icons !== undefined &&\n (!Array.isArray(value.icons) || !value.icons.every(isMcpIcon))\n ) {\n return invalidMcpMeta(capability, \"icons must be MCP icon descriptors\");\n }\n return value as Exclude<McpCapabilityMeta, false>;\n}\n\nfunction isMcpIcon(value: unknown): value is McpIcon {\n if (!isRecord(value) || typeof value.src !== \"string\") return false;\n if (value.mimeType !== undefined && typeof value.mimeType !== \"string\") {\n return false;\n }\n if (\n value.sizes !== undefined &&\n (!Array.isArray(value.sizes) ||\n !value.sizes.every((size) => typeof size === \"string\"))\n ) {\n return false;\n }\n return value.theme === undefined || value.theme === \"light\" ||\n value.theme === \"dark\";\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction invalidMcpMeta(\n capability: ManifestCapability,\n reason: string,\n): never {\n throw new Error(\n `Capability \"${capability.id}\" has invalid MCP metadata: ${reason}`,\n );\n}\n","import {\n renderPresentationMarkdown,\n type PresentationPart,\n} from \"@capable/core\";\nimport type { CallToolResult } from \"@modelcontextprotocol/server\";\n\nexport function toMcpContent(\n presentation: readonly PresentationPart[] | undefined,\n output: unknown,\n): CallToolResult[\"content\"] {\n if (!presentation?.length) {\n return [{ type: \"text\", text: stringify(output) }];\n }\n const content: CallToolResult[\"content\"] = [];\n for (const part of presentation) {\n if (part.type === \"markdown\") {\n content.push({ type: \"text\", text: renderPresentationMarkdown(part) });\n continue;\n }\n if (part.type === \"table\") {\n content.push({\n type: \"text\",\n text: renderPresentationMarkdown(part),\n });\n continue;\n }\n if (part.type === \"image\") {\n content.push(\n { type: \"text\", text: `[Image: ${part.alt}]` },\n {\n type: \"image\",\n data: part.base64,\n mimeType: part.mimeType,\n },\n );\n continue;\n }\n content.push({\n type: \"resource_link\",\n uri: part.url,\n name: part.name,\n ...(part.description ? { description: part.description } : {}),\n ...(part.mimeType ? { mimeType: part.mimeType } : {}),\n ...(part.size === undefined ? {} : { size: part.size }),\n });\n }\n return content;\n}\n\nfunction stringify(value: unknown): string {\n return typeof value === \"string\"\n ? value\n : JSON.stringify(value) ?? String(value);\n}\n","import type { ServerMount } from \"@capable/server\";\nimport {\n createApp,\n selectApp,\n TransportError,\n type ApplicationSelection,\n} from \"@capable/app\";\nimport {\n createMcpHandler,\n Server,\n type CallToolResult,\n type Icon,\n type Implementation,\n type Tool,\n} from \"@modelcontextprotocol/server\";\nimport {\n createMcp,\n type McpIcon,\n type McpTool,\n} from \"./index.ts\";\nimport { toMcpContent } from \"./presentation.ts\";\n\nexport type McpCacheHint = {\n readonly ttlMs?: number;\n readonly cacheScope?: \"public\" | \"private\";\n};\n\nexport type McpMountOptions = {\n readonly path?: string;\n readonly name?: string;\n readonly version?: string;\n readonly title?: string;\n readonly description?: string;\n readonly websiteUrl?: string;\n readonly icons?: readonly McpIcon[];\n readonly instructions?: string;\n readonly selection?: ApplicationSelection;\n readonly cache?: {\n readonly discovery?: McpCacheHint;\n readonly tools?: McpCacheHint;\n };\n};\n\nexport function mcp<TContext = any>(\n options: McpMountOptions = {},\n): ServerMount<TContext> {\n validateCacheHint(options.cache?.discovery, \"discovery\");\n validateCacheHint(options.cache?.tools, \"tools\");\n const path = normalizePath(options.path ?? \"/mcp\");\n return {\n kind: \"capable.server.mount\",\n compile(app, context, onError) {\n const description = options.description ?? app.description;\n const handler = createMcpHandler(async ({ requestInfo }) => {\n try {\n if (!requestInfo) {\n throw new Error(\n \"The MCP HTTP handler requires request information\",\n );\n }\n const executable = createApp(\n app,\n context\n ? { context: () => context({ request: requestInfo }) }\n : undefined as never,\n );\n const exposed = options.selection\n ? selectApp(executable, options.selection)\n : executable;\n const tools = await createMcp(exposed);\n return createMcpServer(tools, {\n name: options.name ?? app.name ?? \"capable\",\n version: options.version ?? app.version ?? \"0.0.0\",\n ...(options.title !== undefined ? { title: options.title } : {}),\n ...(description !== undefined\n ? { description }\n : {}),\n ...(options.websiteUrl !== undefined\n ? { websiteUrl: options.websiteUrl }\n : {}),\n ...(options.icons !== undefined\n ? { icons: toProtocolIcons(options.icons) }\n : {}),\n }, options);\n } catch (error) {\n onError?.(error);\n throw error;\n }\n }, {\n legacy: \"stateless\",\n });\n return {\n name: \"mcp\",\n async fetch(request) {\n if (new URL(request.url).pathname !== path) return undefined;\n return handler.fetch(request);\n },\n };\n },\n };\n}\n\nfunction createMcpServer(\n tools: readonly McpTool[],\n info: Implementation,\n options: Pick<McpMountOptions, \"instructions\" | \"cache\">,\n): Server {\n const server = new Server(info, {\n capabilities: { tools: {} },\n ...(options.instructions !== undefined\n ? { instructions: options.instructions }\n : {}),\n ...(options.cache !== undefined\n ? {\n cacheHints: {\n ...(options.cache.discovery !== undefined\n ? { \"server/discover\": options.cache.discovery }\n : {}),\n ...(options.cache.tools !== undefined\n ? { \"tools/list\": options.cache.tools }\n : {}),\n },\n }\n : {}),\n });\n server.setRequestHandler(\"tools/list\", () => ({\n tools: tools.map(toProtocolTool),\n }));\n server.setRequestHandler(\"tools/call\", async (request, context) => {\n const tool = tools.find(({ name }) => name === request.params.name);\n if (!tool) {\n return toolError(`Unknown tool \"${request.params.name}\"`);\n }\n try {\n const result = await tool.call(request.params.arguments ?? {}, {\n signal: context.mcpReq.signal,\n });\n return server.projectCallToolResult({\n content: toMcpContent(result.presentation, result.output),\n structuredContent: result.output,\n } satisfies CallToolResult, tool.outputSchema);\n } catch (error) {\n if (!(error instanceof TransportError)) throw error;\n return toolError(error.message, {\n code: error.code,\n status: error.status,\n data: error.data,\n });\n }\n });\n return server;\n}\n\nfunction toProtocolTool(tool: McpTool): Tool {\n return {\n name: tool.name,\n ...(tool.title ? { title: tool.title } : {}),\n ...(tool.description ? { description: tool.description } : {}),\n ...(tool.icons ? { icons: toProtocolIcons(tool.icons) } : {}),\n inputSchema: tool.inputSchema as Tool[\"inputSchema\"],\n ...(tool.outputSchema\n ? { outputSchema: tool.outputSchema as Tool[\"outputSchema\"] }\n : {}),\n _meta: tool._meta,\n annotations: tool.annotations,\n };\n}\n\nfunction toProtocolIcons(icons: readonly McpIcon[]): Icon[] {\n return icons.map((icon) => ({\n src: icon.src,\n ...(icon.mimeType !== undefined ? { mimeType: icon.mimeType } : {}),\n ...(icon.sizes !== undefined ? { sizes: [...icon.sizes] } : {}),\n ...(icon.theme !== undefined ? { theme: icon.theme } : {}),\n }));\n}\n\nfunction toolError(\n message: string,\n details?: Record<string, unknown>,\n): CallToolResult {\n return {\n isError: true,\n content: [{\n type: \"text\",\n text: details ? JSON.stringify({ message, ...details }) : message,\n }],\n };\n}\n\nfunction normalizePath(value: string): string {\n return `/${value.split(\"/\").filter(Boolean).join(\"/\")}`;\n}\n\nfunction validateCacheHint(\n hint: McpCacheHint | undefined,\n field: \"discovery\" | \"tools\",\n): void {\n if (!hint) return;\n if (\n hint.ttlMs !== undefined &&\n (!Number.isSafeInteger(hint.ttlMs) || hint.ttlMs < 0)\n ) {\n throw new RangeError(\n `MCP ${field} cache ttlMs must be a non-negative safe integer`,\n );\n }\n if (\n hint.cacheScope !== undefined &&\n hint.cacheScope !== \"public\" &&\n hint.cacheScope !== \"private\"\n ) {\n throw new RangeError(\n `MCP ${field} cache cacheScope must be \"public\" or \"private\"`,\n );\n }\n}\n"],"mappings":";;;;AA8DA,eAAsB,UACpB,KAC6B;CAC7B,MAAM,UAAU,cAAc,GAAG;CAEjC,MAAM,QAAQ,6BAA4B,MADnB,QAAQ,SAAS,EAAA,CACW,YAAY,CAAC,CAC7D,KAAK,gBAAgB;EAAE,GAAG;EAAY,GAAG,qBAAqB,UAAU;CAAE,EAAE,CAAC,CAC7E,QAAQ,eAAe;EACtB,MAAM,OAAO,WAAW,KAAK;EAC7B,IAAI,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KAAK,UAAU;EAC1B,KAAK,KAAK;EACV,GAAI,KAAK,aAAa,KAAA,IAAY,EAAE,UAAU,KAAK,SAAS,IAAI,CAAC;EACjE,GAAI,KAAK,UAAU,KAAA,IAAY,EAAE,OAAO,CAAC,GAAG,KAAK,KAAK,EAAE,IAAI,CAAC;EAC7D,GAAI,KAAK,UAAU,KAAA,IAAY,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;CAC1D,EAAE;AACJ;AAEA,SAAS,UACP,SACA,SACgB;CAChB,OAAO;EACL,SAAS;EACT,SAAS,CAAC;GACR,MAAM;GACN,MAAM,UAAU,KAAK,UAAU;IAAE;IAAS,GAAG;GAAQ,CAAC,IAAI;EAC5D,CAAC;CACH;AACF;AAEA,SAAS,cAAc,OAAuB;CAC5C,OAAO,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACtD;AAEA,SAAS,kBACP,MACA,OACM;CACN,IAAI,CAAC,MAAM;CACX,IACE,KAAK,UAAU,KAAA,MACd,CAAC,OAAO,cAAc,KAAK,KAAK,KAAK,KAAK,QAAQ,IAEnD,MAAM,IAAI,WACR,OAAO,MAAM,iDACf;CAEF,IACE,KAAK,eAAe,KAAA,KACpB,KAAK,eAAe,YACpB,KAAK,eAAe,WAEpB,MAAM,IAAI,WACR,OAAO,MAAM,gDACf;AAEJ"}
|
package/dist/react-query.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as AppCapabilityReference, h as AppCapabilityIsLive } from "./index-1A44jLuE.mjs";
|
|
2
2
|
import { QueryFunction, QueryKey, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
3
3
|
//#region packages/react-query/src/index.d.ts
|
|
4
4
|
type CapabilityCall = (...args: any[]) => Promise<any>;
|
|
@@ -24,7 +24,7 @@ type ReactQueryLiveCapability<TCall extends CapabilityCall> = ReactQueryCapabili
|
|
|
24
24
|
readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
type ReactQueryNode<TValue> = TValue extends CapabilityCall ?
|
|
27
|
+
type ReactQueryNode<TValue> = TValue extends CapabilityCall ? AppCapabilityIsLive<TValue> extends true ? ReactQueryLiveCapability<TValue> : ReactQueryCapability<TValue> : TValue extends object ? { readonly [TKey in Extract<keyof TValue, string> as TValue[TKey] extends AppCapabilityReference ? TValue[TKey] extends CapabilityCall ? TKey : never : TKey]: ReactQueryNode<TValue[TKey]>; } : never;
|
|
28
28
|
type ReactQueryApp<TApp extends object> = ReactQueryNode<TApp>;
|
|
29
29
|
declare function createReactQuery<const TApp extends object>(app: TApp, options?: {
|
|
30
30
|
readonly keyPrefix?: QueryKey;
|
package/dist/react-query.mjs
CHANGED
package/dist/react-query.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.mjs","names":[],"sources":["../../react-query/src/index.ts"],"sourcesContent":["import {\n subscribe,\n type
|
|
1
|
+
{"version":3,"file":"react-query.mjs","names":[],"sources":["../../react-query/src/index.ts"],"sourcesContent":["import {\n subscribe,\n type AppCapabilityIsLive,\n type AppCapabilityReference,\n} from \"@capable/app\";\nimport {\n experimental_streamedQuery,\n type QueryFunction,\n type QueryKey,\n type UseMutationOptions,\n type UseQueryOptions,\n} from \"@tanstack/react-query\";\n\ntype CapabilityCall = (...args: any[]) => Promise<any>;\n\nconst subscribeCall = subscribe as unknown as (\n capabilityCall: CapabilityCall,\n input: unknown,\n options: { readonly signal: AbortSignal },\n) => AsyncIterableIterator<unknown>;\n\ntype CapabilityInput<TCall extends CapabilityCall> =\n Exclude<Parameters<TCall>[0], undefined>;\n\ntype CapabilityVariables<TCall extends CapabilityCall> =\n undefined extends Parameters<TCall>[0]\n ? void\n : Parameters<TCall>[0];\n\ntype CapabilityOutput<TCall extends CapabilityCall> =\n Awaited<ReturnType<TCall>>;\n\nexport type CapabilityQueryOptions<\n TCall extends CapabilityCall,\n TData = CapabilityOutput<TCall>,\n> = Omit<\n UseQueryOptions<\n CapabilityOutput<TCall>,\n Error,\n TData,\n QueryKey\n >,\n \"queryKey\" | \"queryFn\"\n>;\n\nexport type CapabilityMutationOptions<\n TCall extends CapabilityCall,\n TOnMutateResult = unknown,\n> = Omit<\n UseMutationOptions<\n CapabilityOutput<TCall>,\n Error,\n CapabilityVariables<TCall>,\n TOnMutateResult\n >,\n \"mutationKey\" | \"mutationFn\"\n>;\n\nexport type ReactQueryCapability<TCall extends CapabilityCall> = {\n queryKey(input?: CapabilityInput<TCall>): QueryKey;\n queryOptions<TData = CapabilityOutput<TCall>>(\n input: CapabilityInput<TCall>,\n options?: CapabilityQueryOptions<TCall, TData>,\n ): UseQueryOptions<\n CapabilityOutput<TCall>,\n Error,\n TData,\n QueryKey\n > & {\n readonly queryKey: QueryKey;\n readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;\n };\n mutationOptions<TOnMutateResult = unknown>(\n options?: CapabilityMutationOptions<TCall, TOnMutateResult>,\n ): UseMutationOptions<\n CapabilityOutput<TCall>,\n Error,\n CapabilityVariables<TCall>,\n TOnMutateResult\n > & {\n readonly mutationKey: QueryKey;\n readonly mutationFn: (\n variables: CapabilityVariables<TCall>,\n ) => Promise<CapabilityOutput<TCall>>;\n };\n};\n\nexport type ReactQueryLiveCapability<TCall extends CapabilityCall> =\n ReactQueryCapability<TCall> & {\n liveQueryOptions<TData = CapabilityOutput<TCall>>(\n input: CapabilityInput<TCall>,\n options?: CapabilityQueryOptions<TCall, TData>,\n ): UseQueryOptions<\n CapabilityOutput<TCall>,\n Error,\n TData,\n QueryKey\n > & {\n readonly queryKey: QueryKey;\n readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;\n };\n };\n\ntype ReactQueryNode<TValue> =\n TValue extends CapabilityCall\n ? AppCapabilityIsLive<TValue> extends true\n ? ReactQueryLiveCapability<TValue>\n : ReactQueryCapability<TValue>\n : TValue extends object\n ? {\n readonly [TKey in Extract<keyof TValue, string> as\n TValue[TKey] extends AppCapabilityReference\n ? TValue[TKey] extends CapabilityCall ? TKey : never\n : TKey]: ReactQueryNode<TValue[TKey]>;\n }\n : never;\n\nexport type ReactQueryApp<TApp extends object> = ReactQueryNode<TApp>;\n\nexport function createReactQuery<const TApp extends object>(\n app: TApp,\n options: {\n readonly keyPrefix?: QueryKey;\n } = {},\n): ReactQueryApp<TApp> {\n const keyPrefix = Object.freeze([...(options.keyPrefix ?? [\"capable\"])]);\n\n const callableAt = (path: readonly string[]): CapabilityCall => {\n let current: unknown = app;\n for (const segment of path) {\n current = (current as Record<string, unknown>)[segment];\n }\n return current as CapabilityCall;\n };\n\n const capabilityKey = (\n path: readonly string[],\n input?: unknown,\n ): QueryKey => Object.freeze([\n ...keyPrefix,\n ...path,\n ...(input === undefined ? [] : [input]),\n ]);\n\n const proxy = (path: readonly string[]): unknown =>\n new Proxy({}, {\n get(_target, key) {\n if (key === \"then\") return undefined;\n if (key === \"queryKey\") {\n return (input?: unknown) => capabilityKey(path, input);\n }\n if (key === \"queryOptions\") {\n return (\n input: unknown,\n queryOptions: Record<string, unknown> = {},\n ) => ({\n ...queryOptions,\n queryKey: capabilityKey(path, input),\n queryFn: ({ signal }: { readonly signal: AbortSignal }) =>\n callableAt(path)(input, { signal }),\n });\n }\n if (key === \"liveQueryOptions\") {\n return (\n input: unknown,\n queryOptions: Record<string, unknown> = {},\n ) => ({\n ...queryOptions,\n queryKey: capabilityKey(path, input),\n queryFn: experimental_streamedQuery<unknown, unknown>({\n streamFn: ({ signal }) =>\n subscribeCall(callableAt(path), input, { signal }),\n reducer: (_current, output) => output,\n initialValue: undefined,\n }) as QueryFunction<unknown, QueryKey>,\n });\n }\n if (key === \"mutationOptions\") {\n return (\n mutationOptions: Record<string, unknown> = {},\n ) => ({\n ...mutationOptions,\n mutationKey: capabilityKey(path),\n mutationFn: (input?: unknown) =>\n callableAt(path)(input ?? {}),\n });\n }\n if (typeof key !== \"string\") return undefined;\n return proxy([...path, key]);\n },\n });\n\n return proxy([]) as ReactQueryApp<TApp>;\n}\n"],"mappings":";;;AAeA,MAAM,gBAAgB;AAwGtB,SAAgB,iBACd,KACA,UAEI,CAAC,GACgB;CACrB,MAAM,YAAY,OAAO,OAAO,CAAC,GAAI,QAAQ,aAAa,CAAC,SAAS,CAAE,CAAC;CAEvE,MAAM,cAAc,SAA4C;EAC9D,IAAI,UAAmB;EACvB,KAAK,MAAM,WAAW,MACpB,UAAW,QAAoC;EAEjD,OAAO;CACT;CAEA,MAAM,iBACJ,MACA,UACa,OAAO,OAAO;EAC3B,GAAG;EACH,GAAG;EACH,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK;CACvC,CAAC;CAED,MAAM,SAAS,SACb,IAAI,MAAM,CAAC,GAAG,EACZ,IAAI,SAAS,KAAK;EAChB,IAAI,QAAQ,QAAQ,OAAO,KAAA;EAC3B,IAAI,QAAQ,YACV,QAAQ,UAAoB,cAAc,MAAM,KAAK;EAEvD,IAAI,QAAQ,gBACV,QACE,OACA,eAAwC,CAAC,OACrC;GACJ,GAAG;GACH,UAAU,cAAc,MAAM,KAAK;GACnC,UAAU,EAAE,aACV,WAAW,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC;EACtC;EAEF,IAAI,QAAQ,oBACV,QACE,OACA,eAAwC,CAAC,OACrC;GACJ,GAAG;GACH,UAAU,cAAc,MAAM,KAAK;GACnC,SAAS,2BAA6C;IACpD,WAAW,EAAE,aACX,cAAc,WAAW,IAAI,GAAG,OAAO,EAAE,OAAO,CAAC;IACnD,UAAU,UAAU,WAAW;IAC/B,cAAc,KAAA;GAChB,CAAC;EACH;EAEF,IAAI,QAAQ,mBACV,QACE,kBAA2C,CAAC,OACxC;GACJ,GAAG;GACH,aAAa,cAAc,IAAI;GAC/B,aAAa,UACX,WAAW,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;EAChC;EAEF,IAAI,OAAO,QAAQ,UAAU,OAAO,KAAA;EACpC,OAAO,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;CAC7B,EACF,CAAC;CAEH,OAAO,MAAM,CAAC,CAAC;AACjB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as CapableServer } from "./index-
|
|
1
|
+
import { t as CapableServer } from "./index-D-NV4PiU.mjs";
|
|
2
2
|
//#region packages/nitro-host/src/runtime-support.d.ts
|
|
3
3
|
type CapableNitroEntryOptions = {
|
|
4
4
|
/** The default export of the project's `capable.app.*`. */
|
package/dist/runtime-support.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createHttpHandler } from "./src-
|
|
2
|
-
import { t as mcp } from "./mount-
|
|
3
|
-
import { n as http, r as protocol, t as createServer } from "./src-
|
|
1
|
+
import { t as createHttpHandler } from "./src-_6OmFRYa.mjs";
|
|
2
|
+
import { t as mcp } from "./mount-BmLHp349.mjs";
|
|
3
|
+
import { n as http, r as protocol, t as createServer } from "./src-C5jGDnuu.mjs";
|
|
4
4
|
//#region packages/nitro-host/src/dev-index.ts
|
|
5
5
|
function devIndex() {
|
|
6
6
|
return {
|
package/dist/server.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createServer, i as ServerMount, n as CompiledServerMount, o as http, r as ServerMiddleware, s as protocol, t as CapableServer } from "./index-
|
|
1
|
+
import { a as createServer, i as ServerMount, n as CompiledServerMount, o as http, r as ServerMiddleware, s as protocol, t as CapableServer } from "./index-D-NV4PiU.mjs";
|
|
2
2
|
export { CapableServer, CompiledServerMount, ServerMiddleware, ServerMount, createServer, http, protocol };
|
package/dist/server.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as http, r as protocol, t as createServer } from "./src-
|
|
1
|
+
import { n as http, r as protocol, t as createServer } from "./src-C5jGDnuu.mjs";
|
|
2
2
|
export { createServer, http, protocol };
|