@miragon/mcp-toolkit-core 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/engine/context-builder.d.ts +5 -0
- package/dist/engine/context-builder.d.ts.map +1 -0
- package/dist/engine/context-builder.js +22 -0
- package/dist/engine/context-builder.js.map +1 -0
- package/dist/engine/pipeline-executor.d.ts +21 -0
- package/dist/engine/pipeline-executor.d.ts.map +1 -0
- package/dist/engine/pipeline-executor.js +80 -0
- package/dist/engine/pipeline-executor.js.map +1 -0
- package/dist/framework/active-modules.d.ts +30 -0
- package/dist/framework/active-modules.d.ts.map +1 -0
- package/dist/framework/active-modules.js +44 -0
- package/dist/framework/active-modules.js.map +1 -0
- package/dist/framework/catalogue.d.ts +148 -0
- package/dist/framework/catalogue.d.ts.map +1 -0
- package/dist/framework/catalogue.js +132 -0
- package/dist/framework/catalogue.js.map +1 -0
- package/dist/framework/dashboard-store.d.ts +136 -0
- package/dist/framework/dashboard-store.d.ts.map +1 -0
- package/dist/framework/dashboard-store.js +301 -0
- package/dist/framework/dashboard-store.js.map +1 -0
- package/dist/framework/layout-schemas.d.ts +106 -0
- package/dist/framework/layout-schemas.d.ts.map +1 -0
- package/dist/framework/layout-schemas.js +67 -0
- package/dist/framework/layout-schemas.js.map +1 -0
- package/dist/framework/layout-types.d.ts +25 -0
- package/dist/framework/layout-types.d.ts.map +1 -0
- package/dist/framework/layout-types.js +7 -0
- package/dist/framework/layout-types.js.map +1 -0
- package/dist/framework/manifest.d.ts +65 -0
- package/dist/framework/manifest.d.ts.map +1 -0
- package/dist/framework/manifest.js +47 -0
- package/dist/framework/manifest.js.map +1 -0
- package/dist/framework/render-view.d.ts +53 -0
- package/dist/framework/render-view.d.ts.map +1 -0
- package/dist/framework/render-view.js +73 -0
- package/dist/framework/render-view.js.map +1 -0
- package/dist/framework/view-builders.d.ts +79 -0
- package/dist/framework/view-builders.d.ts.map +1 -0
- package/dist/framework/view-builders.js +113 -0
- package/dist/framework/view-builders.js.map +1 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +6 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/translator.d.ts +59 -0
- package/dist/i18n/translator.d.ts.map +1 -0
- package/dist/i18n/translator.js +48 -0
- package/dist/i18n/translator.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/org-gate.d.ts +22 -0
- package/dist/middleware/org-gate.d.ts.map +1 -0
- package/dist/middleware/org-gate.js +28 -0
- package/dist/middleware/org-gate.js.map +1 -0
- package/dist/middleware/role-filter.d.ts +79 -0
- package/dist/middleware/role-filter.d.ts.map +1 -0
- package/dist/middleware/role-filter.js +95 -0
- package/dist/middleware/role-filter.js.map +1 -0
- package/dist/registry/app-loader.d.ts +35 -0
- package/dist/registry/app-loader.d.ts.map +1 -0
- package/dist/registry/app-loader.js +55 -0
- package/dist/registry/app-loader.js.map +1 -0
- package/dist/registry/step-registry.d.ts +27 -0
- package/dist/registry/step-registry.d.ts.map +1 -0
- package/dist/registry/step-registry.js +53 -0
- package/dist/registry/step-registry.js.map +1 -0
- package/dist/registry/widget-registry.d.ts +15 -0
- package/dist/registry/widget-registry.d.ts.map +1 -0
- package/dist/registry/widget-registry.js +28 -0
- package/dist/registry/widget-registry.js.map +1 -0
- package/dist/rest/client.d.ts +3 -0
- package/dist/rest/client.d.ts.map +1 -0
- package/dist/rest/client.js +155 -0
- package/dist/rest/client.js.map +1 -0
- package/dist/rest/errors.d.ts +14 -0
- package/dist/rest/errors.d.ts.map +1 -0
- package/dist/rest/errors.js +21 -0
- package/dist/rest/errors.js.map +1 -0
- package/dist/rest/index.d.ts +6 -0
- package/dist/rest/index.d.ts.map +1 -0
- package/dist/rest/index.js +4 -0
- package/dist/rest/index.js.map +1 -0
- package/dist/rest/tool.d.ts +60 -0
- package/dist/rest/tool.d.ts.map +1 -0
- package/dist/rest/tool.js +81 -0
- package/dist/rest/tool.js.map +1 -0
- package/dist/rest/types.d.ts +66 -0
- package/dist/rest/types.d.ts.map +1 -0
- package/dist/rest/types.js +2 -0
- package/dist/rest/types.js.map +1 -0
- package/dist/tools/app-resource-uri.d.ts +28 -0
- package/dist/tools/app-resource-uri.d.ts.map +1 -0
- package/dist/tools/app-resource-uri.js +30 -0
- package/dist/tools/app-resource-uri.js.map +1 -0
- package/dist/tools/backend-registry.d.ts +111 -0
- package/dist/tools/backend-registry.d.ts.map +1 -0
- package/dist/tools/backend-registry.js +154 -0
- package/dist/tools/backend-registry.js.map +1 -0
- package/dist/tools/create-framework-app.d.ts +147 -0
- package/dist/tools/create-framework-app.d.ts.map +1 -0
- package/dist/tools/create-framework-app.js +111 -0
- package/dist/tools/create-framework-app.js.map +1 -0
- package/dist/tools/index.d.ts +22 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/register-catalogue-tool.d.ts +22 -0
- package/dist/tools/register-catalogue-tool.d.ts.map +1 -0
- package/dist/tools/register-catalogue-tool.js +45 -0
- package/dist/tools/register-catalogue-tool.js.map +1 -0
- package/dist/tools/register-dashboard-tools.d.ts +32 -0
- package/dist/tools/register-dashboard-tools.d.ts.map +1 -0
- package/dist/tools/register-dashboard-tools.js +149 -0
- package/dist/tools/register-dashboard-tools.js.map +1 -0
- package/dist/tools/register-framework-tools.d.ts +83 -0
- package/dist/tools/register-framework-tools.d.ts.map +1 -0
- package/dist/tools/register-framework-tools.js +154 -0
- package/dist/tools/register-framework-tools.js.map +1 -0
- package/dist/tools/register-tool.d.ts +45 -0
- package/dist/tools/register-tool.d.ts.map +1 -0
- package/dist/tools/register-tool.js +82 -0
- package/dist/tools/register-tool.js.map +1 -0
- package/dist/tools/register-widget-tool.d.ts +51 -0
- package/dist/tools/register-widget-tool.d.ts.map +1 -0
- package/dist/tools/register-widget-tool.js +45 -0
- package/dist/tools/register-widget-tool.js.map +1 -0
- package/dist/tools/tool-call-name.d.ts +53 -0
- package/dist/tools/tool-call-name.d.ts.map +1 -0
- package/dist/tools/tool-call-name.js +92 -0
- package/dist/tools/tool-call-name.js.map +1 -0
- package/dist/tools/with-tool-errors.d.ts +16 -0
- package/dist/tools/with-tool-errors.d.ts.map +1 -0
- package/dist/tools/with-tool-errors.js +28 -0
- package/dist/tools/with-tool-errors.js.map +1 -0
- package/dist/types/app.d.ts +44 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/app.js +2 -0
- package/dist/types/app.js.map +1 -0
- package/dist/types/config.d.ts +15 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/context.d.ts +18 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/meta.d.ts +99 -0
- package/dist/types/meta.d.ts.map +1 -0
- package/dist/types/meta.js +66 -0
- package/dist/types/meta.js.map +1 -0
- package/dist/types/pipeline.d.ts +9 -0
- package/dist/types/pipeline.d.ts.map +1 -0
- package/dist/types/pipeline.js +2 -0
- package/dist/types/pipeline.js.map +1 -0
- package/dist/types/step.d.ts +51 -0
- package/dist/types/step.d.ts.map +1 -0
- package/dist/types/step.js +2 -0
- package/dist/types/step.js.map +1 -0
- package/dist/types/view-data.d.ts +67 -0
- package/dist/types/view-data.d.ts.map +1 -0
- package/dist/types/view-data.js +2 -0
- package/dist/types/view-data.js.map +1 -0
- package/dist/types/widget.d.ts +57 -0
- package/dist/types/widget.d.ts.map +1 -0
- package/dist/types/widget.js +2 -0
- package/dist/types/widget.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-types.js","sourceRoot":"","sources":["../../src/framework/layout-types.ts"],"names":[],"mappings":"AASA,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAC7B,MAAoB;IAEpB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IAClD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { StepRegistry } from "../registry/step-registry.js";
|
|
2
|
+
import type { WidgetRegistry } from "../registry/widget-registry.js";
|
|
3
|
+
import type { OptionalKeyDeclaration } from "../types/step.js";
|
|
4
|
+
import type { AppConfig } from "../types/config.js";
|
|
5
|
+
export interface FrameworkManifest {
|
|
6
|
+
activeApps: string[];
|
|
7
|
+
steps: {
|
|
8
|
+
id: string;
|
|
9
|
+
app: string;
|
|
10
|
+
/** One-line description of what the step does. */
|
|
11
|
+
description?: string;
|
|
12
|
+
dataType: string;
|
|
13
|
+
requires: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Keys the step reads opportunistically (scoping/filter inputs) but does
|
|
16
|
+
* not strictly need. Mirrors `PipelineStepDefinition.optionalKeys`.
|
|
17
|
+
*/
|
|
18
|
+
optionalKeys?: OptionalKeyDeclaration[];
|
|
19
|
+
produces: string[];
|
|
20
|
+
}[];
|
|
21
|
+
widgets: {
|
|
22
|
+
id: string;
|
|
23
|
+
app: string;
|
|
24
|
+
/** One-line description of what the widget shows. */
|
|
25
|
+
description?: string;
|
|
26
|
+
requires: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Step `dataType`s the widget can render. Pair with `steps[].dataType`
|
|
29
|
+
* to find which step populates this widget.
|
|
30
|
+
*/
|
|
31
|
+
consumes?: string[];
|
|
32
|
+
size: string;
|
|
33
|
+
/**
|
|
34
|
+
* JSON Schema for the per-instance props the widget accepts via a
|
|
35
|
+
* layout cell's `props` field. Omitted for widgets that take no
|
|
36
|
+
* per-instance props. Same JSON-Schema contract the LLM already
|
|
37
|
+
* understands from MCP tool input schemas, so it can construct scoped
|
|
38
|
+
* views (e.g. one tab per `processDefinitionKey`) without guessing.
|
|
39
|
+
*/
|
|
40
|
+
propsSchema?: Record<string, unknown>;
|
|
41
|
+
}[];
|
|
42
|
+
pipelines: {
|
|
43
|
+
id: string;
|
|
44
|
+
steps: {
|
|
45
|
+
id: string;
|
|
46
|
+
step: string;
|
|
47
|
+
optional?: boolean;
|
|
48
|
+
}[];
|
|
49
|
+
}[];
|
|
50
|
+
keyContracts: {
|
|
51
|
+
key: string;
|
|
52
|
+
producedBy: string[];
|
|
53
|
+
consumedBy: string[];
|
|
54
|
+
optionallyConsumedBy: string[];
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Produces a JSON-serializable manifest of everything the framework currently
|
|
59
|
+
* knows about: active apps, registered pipeline steps, available widgets, and
|
|
60
|
+
* the key contracts derived from step `requires`/`produces`. Consumers expose
|
|
61
|
+
* this via a `get-framework-manifest` tool so the LLM can learn what is
|
|
62
|
+
* composable via `render-view`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getFrameworkManifest(stepRegistry: StepRegistry, widgetRegistry: WidgetRegistry, config: AppConfig): FrameworkManifest;
|
|
65
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/framework/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,EAAE,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
* Produces a JSON-serializable manifest of everything the framework currently
|
|
3
|
+
* knows about: active apps, registered pipeline steps, available widgets, and
|
|
4
|
+
* the key contracts derived from step `requires`/`produces`. Consumers expose
|
|
5
|
+
* this via a `get-framework-manifest` tool so the LLM can learn what is
|
|
6
|
+
* composable via `render-view`.
|
|
7
|
+
*/
|
|
8
|
+
export function getFrameworkManifest(stepRegistry, widgetRegistry, config) {
|
|
9
|
+
return {
|
|
10
|
+
activeApps: config.activeApps.map((a) => a.app),
|
|
11
|
+
steps: stepRegistry.getAll().map((step) => ({
|
|
12
|
+
id: step.id,
|
|
13
|
+
app: appOf(step.id),
|
|
14
|
+
...(step.description ? { description: step.description } : {}),
|
|
15
|
+
dataType: step.dataType,
|
|
16
|
+
requires: step.requires,
|
|
17
|
+
...(step.optionalKeys && step.optionalKeys.length > 0
|
|
18
|
+
? { optionalKeys: step.optionalKeys }
|
|
19
|
+
: {}),
|
|
20
|
+
produces: step.produces,
|
|
21
|
+
})),
|
|
22
|
+
widgets: widgetRegistry.getAll().map((widget) => ({
|
|
23
|
+
id: widget.id,
|
|
24
|
+
app: appOf(widget.id),
|
|
25
|
+
...(widget.description ? { description: widget.description } : {}),
|
|
26
|
+
requires: widget.requires,
|
|
27
|
+
...(widget.consumes && widget.consumes.length > 0 ? { consumes: widget.consumes } : {}),
|
|
28
|
+
size: widget.size,
|
|
29
|
+
...(widget.propsSchema ? { propsSchema: widget.propsSchema } : {}),
|
|
30
|
+
})),
|
|
31
|
+
pipelines: Object.entries(config.pipelines).map(([id, pipeline]) => ({
|
|
32
|
+
id,
|
|
33
|
+
steps: pipeline.steps ?? [],
|
|
34
|
+
})),
|
|
35
|
+
keyContracts: stepRegistry.getKeyContracts(),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Splits a namespaced id like `"lexoffice:load-invoice"` into the
|
|
40
|
+
* leading namespace. Falls back to the full id if no colon is present
|
|
41
|
+
* (i.e. a malformed id) so callers always get a non-empty string.
|
|
42
|
+
*/
|
|
43
|
+
function appOf(id) {
|
|
44
|
+
const colon = id.indexOf(":");
|
|
45
|
+
return colon >= 0 ? id.slice(0, colon) : id;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/framework/manifest.ts"],"names":[],"mappings":"AAsDA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,YAA0B,EAC1B,cAA8B,EAC9B,MAAiB;IAEjB,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAE/C,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1C,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9D,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC;gBACnD,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE;gBACrC,CAAC,CAAC,EAAE,CAAC;YACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QAEH,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAChD,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,GA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
|
3
|
+
import type { PipelineStepRef } from "../types/pipeline.js";
|
|
4
|
+
import type { ViewStructuredContent } from "../types/view-data.js";
|
|
5
|
+
import type { LayoutConfig } from "./layout-types.js";
|
|
6
|
+
export interface RenderViewInput {
|
|
7
|
+
keys?: Record<string, unknown>;
|
|
8
|
+
steps?: PipelineStepRef[];
|
|
9
|
+
layout: LayoutConfig;
|
|
10
|
+
title?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RenderViewOptions {
|
|
13
|
+
input: RenderViewInput;
|
|
14
|
+
stepRegistry: StepRegistry;
|
|
15
|
+
appConfigs?: Record<string, Record<string, unknown>>;
|
|
16
|
+
/**
|
|
17
|
+
* Per-request context (currently: the calling userId) that the pipeline
|
|
18
|
+
* executor uses to pre-bind user-scoped `callTool` closures on step
|
|
19
|
+
* `appConfig`s. Pass it through from the tool handler's
|
|
20
|
+
* `ctx.auth?.user?.userId`.
|
|
21
|
+
*/
|
|
22
|
+
ctx?: PipelineExecutionContext;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the in-iframe visual builder is usable on this server (i.e.
|
|
25
|
+
* `app.builder` is on and `get-builder-catalogue` is registered). Echoed
|
|
26
|
+
* into `structuredContent.builderAvailable` so the `McpAppView` shell shows
|
|
27
|
+
* its Build affordance only when the builder can actually be serviced.
|
|
28
|
+
* Defaults to `false` — `createFrameworkApp` passes the real value through
|
|
29
|
+
* from `options.app.builder`.
|
|
30
|
+
*/
|
|
31
|
+
builderAvailable?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Executes a pipeline of steps to populate the keys map and returns a payload
|
|
35
|
+
* ready to be embedded into an MCP App widget. The resulting `structuredContent`
|
|
36
|
+
* is consumed by the `McpAppView` component in `@miragon/mcp-toolkit-ui`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function renderView(options: RenderViewOptions): Promise<{
|
|
39
|
+
content: {
|
|
40
|
+
type: "text";
|
|
41
|
+
text: string;
|
|
42
|
+
}[];
|
|
43
|
+
isError: boolean;
|
|
44
|
+
structuredContent?: undefined;
|
|
45
|
+
} | {
|
|
46
|
+
content: {
|
|
47
|
+
type: "text";
|
|
48
|
+
text: string;
|
|
49
|
+
}[];
|
|
50
|
+
structuredContent: ViewStructuredContent;
|
|
51
|
+
isError?: undefined;
|
|
52
|
+
}>;
|
|
53
|
+
//# sourceMappingURL=render-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-view.d.ts","sourceRoot":"","sources":["../../src/framework/render-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAE/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,eAAe,EAAE,CAAA;IACzB,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,eAAe,CAAA;IACtB,YAAY,EAAE,YAAY,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACpD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,wBAAwB,CAAA;IAC9B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;GAuE1D"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { executePipeline } from "../engine/pipeline-executor.js";
|
|
2
|
+
import { validatePipeline } from "../engine/context-builder.js";
|
|
3
|
+
/**
|
|
4
|
+
* Executes a pipeline of steps to populate the keys map and returns a payload
|
|
5
|
+
* ready to be embedded into an MCP App widget. The resulting `structuredContent`
|
|
6
|
+
* is consumed by the `McpAppView` component in `@miragon/mcp-toolkit-ui`.
|
|
7
|
+
*/
|
|
8
|
+
export async function renderView(options) {
|
|
9
|
+
const { input, stepRegistry, appConfigs, ctx, builderAvailable } = options;
|
|
10
|
+
const initialKeys = input.keys ?? {};
|
|
11
|
+
const pipelineConfig = { steps: input.steps };
|
|
12
|
+
if (input.steps?.length) {
|
|
13
|
+
const validation = validatePipeline(pipelineConfig, stepRegistry, Object.keys(initialKeys));
|
|
14
|
+
if (!validation.valid) {
|
|
15
|
+
return {
|
|
16
|
+
content: [
|
|
17
|
+
{
|
|
18
|
+
type: "text",
|
|
19
|
+
text: `Pipeline validation failed: ${validation.issues.join("; ")}`,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
isError: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const context = await executePipeline({
|
|
27
|
+
config: pipelineConfig,
|
|
28
|
+
initialKeys,
|
|
29
|
+
registry: stepRegistry,
|
|
30
|
+
appConfigs,
|
|
31
|
+
ctx,
|
|
32
|
+
});
|
|
33
|
+
const textSummary = [
|
|
34
|
+
input.title ?? "View",
|
|
35
|
+
`Steps: ${Object.keys(context.steps).join(", ") || "none"}`,
|
|
36
|
+
`Keys: ${Object.keys(context.keys).join(", ")}`,
|
|
37
|
+
context.errors.length > 0
|
|
38
|
+
? `Errors: ${context.errors.map((e) => `${e.stepId}: ${e.reason}`).join("; ")}`
|
|
39
|
+
: "",
|
|
40
|
+
]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join("\n");
|
|
43
|
+
const structuredContent = {
|
|
44
|
+
_refreshParams: {
|
|
45
|
+
keys: input.keys,
|
|
46
|
+
steps: input.steps,
|
|
47
|
+
layout: input.layout,
|
|
48
|
+
title: input.title,
|
|
49
|
+
},
|
|
50
|
+
title: input.title,
|
|
51
|
+
context: {
|
|
52
|
+
keys: context.keys,
|
|
53
|
+
stepIds: Object.keys(context.steps),
|
|
54
|
+
stepData: Object.fromEntries(Object.entries(context.steps).map(([id, result]) => [
|
|
55
|
+
id,
|
|
56
|
+
{
|
|
57
|
+
data: result.data,
|
|
58
|
+
keys: result.keys,
|
|
59
|
+
_app: result._app,
|
|
60
|
+
_dataType: result._dataType,
|
|
61
|
+
},
|
|
62
|
+
])),
|
|
63
|
+
errors: context.errors,
|
|
64
|
+
},
|
|
65
|
+
layout: input.layout,
|
|
66
|
+
builderAvailable: builderAvailable ?? false,
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
content: [{ type: "text", text: textSummary }],
|
|
70
|
+
structuredContent,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=render-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-view.js","sourceRoot":"","sources":["../../src/framework/render-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAiC,MAAM,gCAAgC,CAAA;AAC/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAmC/D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAA0B;IACzD,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAA;IAC1E,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAA;IACpC,MAAM,cAAc,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAA;IAE7C,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACxB,MAAM,UAA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AK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB;QACD,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE;YACP,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YACnC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAC1B,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;gBAClD,EAAE;gBACF;oBACE,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,MAAM,CAAC,SAAS;iBAC5B;aACF,CAAC,CACH;YACD,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB;QACD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,gBAAgB,EAAE,gBAAgB,IAAI,KAAK;KAC5C,CAAA;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;QACvD,iBAAiB;KAClB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { LayoutConfig } from "./layout-types.js";
|
|
2
|
+
import type { ViewStructuredContent } from "../types/view-data.js";
|
|
3
|
+
export interface SingleWidgetViewInput {
|
|
4
|
+
widget: string;
|
|
5
|
+
app: string;
|
|
6
|
+
dataType: string;
|
|
7
|
+
data: unknown;
|
|
8
|
+
title?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Short model-facing summary emitted on the text channel (1-2 sentences,
|
|
11
|
+
* e.g. "Process list: 12 definitions matching ..."). The full data payload
|
|
12
|
+
* lives only in `structuredContent` — never put bulky data (BPMN XML, row
|
|
13
|
+
* arrays) in the summary. Falls back to a generic one-liner derived from
|
|
14
|
+
* the widget type and an item count when omitted.
|
|
15
|
+
*/
|
|
16
|
+
summary?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ComposedViewEntry {
|
|
19
|
+
/** Stable id used as the step result key (must be unique within the view). */
|
|
20
|
+
id?: string;
|
|
21
|
+
/** Step `_dataType` widgets resolve through `adaptDataWidget`. */
|
|
22
|
+
dataType: string;
|
|
23
|
+
/** Eager data payload — same shape the matching widget expects. */
|
|
24
|
+
data: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface ComposedViewInput {
|
|
27
|
+
app: string;
|
|
28
|
+
layout: LayoutConfig;
|
|
29
|
+
entries: ComposedViewEntry[];
|
|
30
|
+
title?: string;
|
|
31
|
+
/** Same contract as {@link SingleWidgetViewInput.summary}. */
|
|
32
|
+
summary?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Shape both view builders return — the `McpAppView` envelope plus a summary. */
|
|
35
|
+
export interface ViewToolResult {
|
|
36
|
+
content: {
|
|
37
|
+
type: "text";
|
|
38
|
+
text: string;
|
|
39
|
+
}[];
|
|
40
|
+
structuredContent: ViewStructuredContent;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Best-effort item count for the generic fallback summary: array length or a
|
|
44
|
+
* conventional `totalCount`/`total` field. Returns null when not derivable.
|
|
45
|
+
*/
|
|
46
|
+
export declare function deriveItemCount(data: unknown): number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Generic model-facing summary used when a caller omits `summary`. Names the
|
|
49
|
+
* view (its `title`, or the widget ids) and appends a derivable item count.
|
|
50
|
+
*/
|
|
51
|
+
export declare function defaultSummary(widgets: string[], data: unknown, title?: string): string;
|
|
52
|
+
/** Widget ids across all three LayoutConfig variants (rows array, rows object, tabs). */
|
|
53
|
+
export declare function collectLayoutWidgets(layout: LayoutConfig): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Multi-widget variant of {@link buildSingleWidgetView}. Lets `*_show_*` tools
|
|
56
|
+
* compose several small widgets into a layout while keeping the eager
|
|
57
|
+
* (no-pipeline) execution model: each widget resolves its slice through
|
|
58
|
+
* `adaptDataWidget` by `_dataType`. Widgets that share a `dataType` all
|
|
59
|
+
* receive the same data object and are expected to render their own slice.
|
|
60
|
+
*
|
|
61
|
+
* The text channel carries only the model-facing `summary`; the data payload
|
|
62
|
+
* lives in `structuredContent.context.stepData`. In-widget refresh callers
|
|
63
|
+
* must therefore parse results structuredContent-first (the toolkit's
|
|
64
|
+
* text-first `useToolQuery` would only see the summary string).
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildComposedView(input: ComposedViewInput): ViewToolResult;
|
|
67
|
+
/**
|
|
68
|
+
* Builds an MCP tool result that renders a single widget through the same
|
|
69
|
+
* `McpAppView` shell as `render-view`. Use this from `*_show_*` tools that
|
|
70
|
+
* compute their data eagerly (no pipeline) — the widget data is exposed under
|
|
71
|
+
* `context.stepData["result"]` with the given `_dataType`, so the registry
|
|
72
|
+
* adapter (`adaptDataWidget`) can route it to the right widget component.
|
|
73
|
+
*
|
|
74
|
+
* The text channel carries only the model-facing `summary` (the model never
|
|
75
|
+
* needs the rendered payload); the data lives in `structuredContent`.
|
|
76
|
+
* In-widget refresh callers parse structuredContent-first.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildSingleWidgetView(input: SingleWidgetViewInput): ViewToolResult;
|
|
79
|
+
//# sourceMappingURL=view-builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-builders.d.ts","sourceRoot":"","sources":["../../src/framework/view-builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAElE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IA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* Best-effort item count for the generic fallback summary: array length or a
|
|
3
|
+
* conventional `totalCount`/`total` field. Returns null when not derivable.
|
|
4
|
+
*/
|
|
5
|
+
export function deriveItemCount(data) {
|
|
6
|
+
if (Array.isArray(data))
|
|
7
|
+
return data.length;
|
|
8
|
+
if (data && typeof data === "object") {
|
|
9
|
+
const d = data;
|
|
10
|
+
if (typeof d.totalCount === "number")
|
|
11
|
+
return d.totalCount;
|
|
12
|
+
if (typeof d.total === "number")
|
|
13
|
+
return d.total;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generic model-facing summary used when a caller omits `summary`. Names the
|
|
19
|
+
* view (its `title`, or the widget ids) and appends a derivable item count.
|
|
20
|
+
*/
|
|
21
|
+
export function defaultSummary(widgets, data, title) {
|
|
22
|
+
const label = title ?? widgets.join(", ");
|
|
23
|
+
const count = deriveItemCount(data);
|
|
24
|
+
const countSuffix = count === null ? "" : ` (${count} item${count === 1 ? "" : "s"})`;
|
|
25
|
+
return `Rendered widget "${label}"${countSuffix}. Full data is shown in the widget.`;
|
|
26
|
+
}
|
|
27
|
+
/** Widget ids across all three LayoutConfig variants (rows array, rows object, tabs). */
|
|
28
|
+
export function collectLayoutWidgets(layout) {
|
|
29
|
+
const rows = Array.isArray(layout)
|
|
30
|
+
? layout
|
|
31
|
+
: "rows" in layout
|
|
32
|
+
? layout.rows
|
|
33
|
+
: layout.tabs.flatMap((tab) => tab.rows);
|
|
34
|
+
return rows.flatMap((row) => row.row.map((cell) => cell.widget));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Multi-widget variant of {@link buildSingleWidgetView}. Lets `*_show_*` tools
|
|
38
|
+
* compose several small widgets into a layout while keeping the eager
|
|
39
|
+
* (no-pipeline) execution model: each widget resolves its slice through
|
|
40
|
+
* `adaptDataWidget` by `_dataType`. Widgets that share a `dataType` all
|
|
41
|
+
* receive the same data object and are expected to render their own slice.
|
|
42
|
+
*
|
|
43
|
+
* The text channel carries only the model-facing `summary`; the data payload
|
|
44
|
+
* lives in `structuredContent.context.stepData`. In-widget refresh callers
|
|
45
|
+
* must therefore parse results structuredContent-first (the toolkit's
|
|
46
|
+
* text-first `useToolQuery` would only see the summary string).
|
|
47
|
+
*/
|
|
48
|
+
export function buildComposedView(input) {
|
|
49
|
+
const stepData = {};
|
|
50
|
+
const stepIds = [];
|
|
51
|
+
for (const [idx, entry] of input.entries.entries()) {
|
|
52
|
+
const id = entry.id ?? `result_${idx}`;
|
|
53
|
+
stepIds.push(id);
|
|
54
|
+
stepData[id] = {
|
|
55
|
+
data: entry.data,
|
|
56
|
+
keys: {},
|
|
57
|
+
_app: input.app,
|
|
58
|
+
_dataType: entry.dataType,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const widgets = collectLayoutWidgets(input.layout);
|
|
62
|
+
const summary = input.summary ??
|
|
63
|
+
defaultSummary(widgets, input.entries.length === 1 ? input.entries[0].data : null, input.title);
|
|
64
|
+
return {
|
|
65
|
+
content: [{ type: "text", text: summary }],
|
|
66
|
+
structuredContent: {
|
|
67
|
+
title: input.title,
|
|
68
|
+
context: {
|
|
69
|
+
keys: {},
|
|
70
|
+
stepIds,
|
|
71
|
+
stepData,
|
|
72
|
+
errors: [],
|
|
73
|
+
},
|
|
74
|
+
layout: input.layout,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Builds an MCP tool result that renders a single widget through the same
|
|
80
|
+
* `McpAppView` shell as `render-view`. Use this from `*_show_*` tools that
|
|
81
|
+
* compute their data eagerly (no pipeline) — the widget data is exposed under
|
|
82
|
+
* `context.stepData["result"]` with the given `_dataType`, so the registry
|
|
83
|
+
* adapter (`adaptDataWidget`) can route it to the right widget component.
|
|
84
|
+
*
|
|
85
|
+
* The text channel carries only the model-facing `summary` (the model never
|
|
86
|
+
* needs the rendered payload); the data lives in `structuredContent`.
|
|
87
|
+
* In-widget refresh callers parse structuredContent-first.
|
|
88
|
+
*/
|
|
89
|
+
export function buildSingleWidgetView(input) {
|
|
90
|
+
const layout = [{ row: [{ widget: input.widget }] }];
|
|
91
|
+
const summary = input.summary ?? defaultSummary([input.widget], input.data, input.title);
|
|
92
|
+
return {
|
|
93
|
+
content: [{ type: "text", text: summary }],
|
|
94
|
+
structuredContent: {
|
|
95
|
+
title: input.title,
|
|
96
|
+
context: {
|
|
97
|
+
keys: {},
|
|
98
|
+
stepIds: ["result"],
|
|
99
|
+
stepData: {
|
|
100
|
+
result: {
|
|
101
|
+
data: input.data,
|
|
102
|
+
keys: {},
|
|
103
|
+
_app: input.app,
|
|
104
|
+
_dataType: input.dataType,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
errors: [],
|
|
108
|
+
},
|
|
109
|
+
layout,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=view-builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-builders.js","sourceRoot":"","sources":["../../src/framework/view-builders.ts"],"names":[],"mappings":"AA2CA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAa;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,CAAA;IAC3C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAA+B,CAAA;QACzC,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,UAAU,CAAA;QACzD,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,KAAK,CAAA;IACjD,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAiB,EAAE,IAAa,EAAE,KAAc;IAC7E,MAAM,K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ACnD,iBAAiB,EAAE;YACjB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE;gBACP,IAAI,EAAE,EAAE;gBACR,OAAO,EAAE,CAAC,QAAQ,CAAC;gBACnB,QAAQ,EAAE;oBACR,MAAM,EAAE;wBACN,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,IAAI,EAAE,EAAE;wBACR,IAAI,EAAE,KAAK,CAAC,GAAG;wBACf,SAAS,EAAE,KAAK,CAAC,QAAQ;qBAC1B;iBACF;gBACD,MAAM,EAAE,EAAE;aACX;YACD,MAAM;SACP;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,YAAY,EACV,OAAO,EACP,cAAc,EACd,QAAQ,EACR,SAAS,EACT,uBAAuB,GACxB,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Localization engine. Browser-safe (pure data + functions, no `node:*`, no
|
|
2
|
+
// `mcp-use/*`), so it is re-exported from the core root barrel and shared by the
|
|
3
|
+
// server (tool summaries) and the UI (widget strings). Ships no catalogs — the
|
|
4
|
+
// consuming app provides its own and decides where the active locale comes from.
|
|
5
|
+
export { createTranslator } from "./translator.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAAiF;AACjF,+EAA+E;AAC/E,iFAAiF;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal, dependency-free translation engine shared by the server (tool
|
|
3
|
+
* summaries / messages) and the UI (widget strings). It deliberately ships *no*
|
|
4
|
+
* catalogs — a consuming app provides its own message catalogs and decides where
|
|
5
|
+
* the active locale comes from (a header, a user profile, a session store …).
|
|
6
|
+
*
|
|
7
|
+
* Browser-bundle-safe: pure data + functions, no `node:*` and no `mcp-use/*`, so
|
|
8
|
+
* it ships from the core root barrel and runs in a widget bundle and on the
|
|
9
|
+
* server alike.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A single message. Either:
|
|
13
|
+
* - a string, optionally with `{name}` placeholders interpolated from params
|
|
14
|
+
* (e.g. `"{count} open incidents"`), or
|
|
15
|
+
* - a function of the params, for logic a template can't express (plurals,
|
|
16
|
+
* conditionals).
|
|
17
|
+
*
|
|
18
|
+
* Strings keep catalogs pure data (JSON-serialisable); reach for a function only
|
|
19
|
+
* when interpolation isn't enough.
|
|
20
|
+
*/
|
|
21
|
+
export type Message = string | ((params: Record<string, unknown>) => string);
|
|
22
|
+
/** One locale's messages, keyed by a dotted message key (e.g. `"engine.list.empty"`). */
|
|
23
|
+
export type MessageCatalog = Record<string, Message>;
|
|
24
|
+
/** Per-locale catalogs, keyed by a locale tag (e.g. `"en"`, `"de"`). */
|
|
25
|
+
export type Catalogs = Record<string, MessageCatalog>;
|
|
26
|
+
/** Resolves a message for an explicit locale. */
|
|
27
|
+
export type Translate = (locale: string, key: string, params?: Record<string, unknown>) => string;
|
|
28
|
+
export interface CreateTranslatorOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Locale used when the requested locale has no catalog, or has a catalog but
|
|
31
|
+
* not the requested key. Defaults to `"en"`.
|
|
32
|
+
*/
|
|
33
|
+
fallbackLocale?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build a {@link Translate} over the given catalogs. Resolution falls back in a
|
|
37
|
+
* fixed chain so a partial translation degrades predictably rather than
|
|
38
|
+
* crashing:
|
|
39
|
+
*
|
|
40
|
+
* requested locale → fallback locale → the key itself
|
|
41
|
+
*
|
|
42
|
+
* Returning the key for a wholly-unknown message keeps a missing translation
|
|
43
|
+
* visible (and greppable) in development instead of rendering an empty string.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const t = createTranslator({
|
|
47
|
+
* en: { "greeting": ({ name }) => `Hello, ${name}` },
|
|
48
|
+
* de: { "greeting": ({ name }) => `Hallo, ${name}` },
|
|
49
|
+
* })
|
|
50
|
+
* t("de", "greeting", { name: "Ada" }) // "Hallo, Ada"
|
|
51
|
+
* t("fr", "greeting", { name: "Ada" }) // "Hello, Ada" (fallback)
|
|
52
|
+
* t("de", "missing") // "missing" (key passthrough)
|
|
53
|
+
*
|
|
54
|
+
* // String templates interpolate `{name}` placeholders from params:
|
|
55
|
+
* const u = createTranslator({ en: { hi: "Hi {name}, {n} new" } })
|
|
56
|
+
* u("en", "hi", { name: "Ada", n: 3 }) // "Hi Ada, 3 new"
|
|
57
|
+
*/
|
|
58
|
+
export declare function createTranslator(catalogs: Catalogs, options?: CreateTranslatorOptions): Translate;
|
|
59
|
+
//# sourceMappingURL=translator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translator.d.ts","sourceRoot":"","sources":["../../src/i18n/translator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,CAAA;AAE5E,yFAAyF;AACzF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpD,wEAAwE;AACxE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAErD,iDAAiD;AACjD,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAA;AAEjG,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,uBAA4B,GACpC,SAAS,CAYX"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal, dependency-free translation engine shared by the server (tool
|
|
3
|
+
* summaries / messages) and the UI (widget strings). It deliberately ships *no*
|
|
4
|
+
* catalogs — a consuming app provides its own message catalogs and decides where
|
|
5
|
+
* the active locale comes from (a header, a user profile, a session store …).
|
|
6
|
+
*
|
|
7
|
+
* Browser-bundle-safe: pure data + functions, no `node:*` and no `mcp-use/*`, so
|
|
8
|
+
* it ships from the core root barrel and runs in a widget bundle and on the
|
|
9
|
+
* server alike.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Build a {@link Translate} over the given catalogs. Resolution falls back in a
|
|
13
|
+
* fixed chain so a partial translation degrades predictably rather than
|
|
14
|
+
* crashing:
|
|
15
|
+
*
|
|
16
|
+
* requested locale → fallback locale → the key itself
|
|
17
|
+
*
|
|
18
|
+
* Returning the key for a wholly-unknown message keeps a missing translation
|
|
19
|
+
* visible (and greppable) in development instead of rendering an empty string.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const t = createTranslator({
|
|
23
|
+
* en: { "greeting": ({ name }) => `Hello, ${name}` },
|
|
24
|
+
* de: { "greeting": ({ name }) => `Hallo, ${name}` },
|
|
25
|
+
* })
|
|
26
|
+
* t("de", "greeting", { name: "Ada" }) // "Hallo, Ada"
|
|
27
|
+
* t("fr", "greeting", { name: "Ada" }) // "Hello, Ada" (fallback)
|
|
28
|
+
* t("de", "missing") // "missing" (key passthrough)
|
|
29
|
+
*
|
|
30
|
+
* // String templates interpolate `{name}` placeholders from params:
|
|
31
|
+
* const u = createTranslator({ en: { hi: "Hi {name}, {n} new" } })
|
|
32
|
+
* u("en", "hi", { name: "Ada", n: 3 }) // "Hi Ada, 3 new"
|
|
33
|
+
*/
|
|
34
|
+
export function createTranslator(catalogs, options = {}) {
|
|
35
|
+
const fallbackLocale = options.fallbackLocale ?? "en";
|
|
36
|
+
return (locale, key, params) => {
|
|
37
|
+
const message = catalogs[locale]?.[key] ?? catalogs[fallbackLocale]?.[key];
|
|
38
|
+
if (message === undefined)
|
|
39
|
+
return key;
|
|
40
|
+
if (typeof message === "function")
|
|
41
|
+
return message(params ?? {});
|
|
42
|
+
if (!params)
|
|
43
|
+
return message;
|
|
44
|
+
// Interpolate `{name}` placeholders; leave unknown ones untouched.
|
|
45
|
+
return message.replace(/\{(\w+)\}/g, (whole, name) => name in params ? String(params[name]) : whole);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=translator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translator.js","sourceRoot":"","sources":["../../src/i18n/translator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA+BH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAkB,EAClB,UAAmC,EAAE;IAErC,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAA;IACrD,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;QAC7B,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;QAC1E,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,GAAG,CAAA;QACrC,IAAI,OAAO,OAAO,KAAK,UAAU;YAAE,OAAO,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;QAC/D,IAAI,CAAC,MAAM;YAAE,OAAO,OAAO,CAAA;QAC3B,mEAAmE;QACnE,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE,CAC3D,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAC9C,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|