@decocms/bindings 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -2
- package/src/core/client/proxy.ts +6 -22
- package/src/core/plugins.ts +19 -3
- package/src/core/server-plugin.ts +103 -0
- package/src/well-known/workflow.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/bindings",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"check": "tsc --noEmit",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"zod": "^4.0.0",
|
|
14
14
|
"zod-from-json-schema": "^0.5.2"
|
|
15
15
|
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"hono": "^4.7.10",
|
|
18
|
+
"kysely": "^0.27.5"
|
|
19
|
+
},
|
|
16
20
|
"exports": {
|
|
17
21
|
".": "./src/index.ts",
|
|
18
22
|
"./collections": "./src/well-known/collections.ts",
|
|
@@ -24,7 +28,8 @@
|
|
|
24
28
|
"./prompt": "./src/well-known/prompt.ts",
|
|
25
29
|
"./workflow": "./src/well-known/workflow.ts",
|
|
26
30
|
"./plugins": "./src/core/plugins.ts",
|
|
27
|
-
"./plugin-router": "./src/core/plugin-router.tsx"
|
|
31
|
+
"./plugin-router": "./src/core/plugin-router.tsx",
|
|
32
|
+
"./server-plugin": "./src/core/server-plugin.ts"
|
|
28
33
|
},
|
|
29
34
|
"engines": {
|
|
30
35
|
"node": ">=24.0.0"
|
package/src/core/client/proxy.ts
CHANGED
|
@@ -67,16 +67,8 @@ export function createMCPClientProxy<T extends Record<string, unknown>>(
|
|
|
67
67
|
}
|
|
68
68
|
async function callToolFn(
|
|
69
69
|
args: Record<string, unknown>,
|
|
70
|
-
|
|
70
|
+
toolName = name,
|
|
71
71
|
) {
|
|
72
|
-
let toolName: string | symbol;
|
|
73
|
-
let requestInit: RequestInit | undefined;
|
|
74
|
-
if (typeof toolNameOrRequestInit === "object") {
|
|
75
|
-
toolName = name;
|
|
76
|
-
requestInit = toolNameOrRequestInit;
|
|
77
|
-
} else {
|
|
78
|
-
toolName ??= name;
|
|
79
|
-
}
|
|
80
72
|
const debugId = options?.debugId?.();
|
|
81
73
|
const extraHeaders = debugId
|
|
82
74
|
? { "x-trace-debug-id": debugId }
|
|
@@ -85,21 +77,13 @@ export function createMCPClientProxy<T extends Record<string, unknown>>(
|
|
|
85
77
|
const { client, callStreamableTool } = await createClient(extraHeaders);
|
|
86
78
|
|
|
87
79
|
if (options?.streamable?.[String(toolName)]) {
|
|
88
|
-
return callStreamableTool(
|
|
89
|
-
String(toolName),
|
|
90
|
-
args,
|
|
91
|
-
requestInit?.signal ?? undefined,
|
|
92
|
-
);
|
|
80
|
+
return callStreamableTool(String(toolName), args);
|
|
93
81
|
}
|
|
94
82
|
|
|
95
|
-
const { structuredContent, isError, content } = await client.callTool(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
undefined,
|
|
101
|
-
{ signal: requestInit?.signal ?? undefined },
|
|
102
|
-
);
|
|
83
|
+
const { structuredContent, isError, content } = await client.callTool({
|
|
84
|
+
name: String(toolName),
|
|
85
|
+
arguments: args as Record<string, unknown>,
|
|
86
|
+
});
|
|
103
87
|
|
|
104
88
|
if (isError) {
|
|
105
89
|
const maybeErrorMessage = (content as { text: string }[])?.[0]?.text;
|
package/src/core/plugins.ts
CHANGED
|
@@ -43,14 +43,21 @@ export interface PluginRenderHeaderProps {
|
|
|
43
43
|
onConnectionChange: (connectionId: string) => void;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Client Plugin interface.
|
|
48
|
+
*
|
|
49
|
+
* Defines the contract for client-side plugins that extend the Mesh UI.
|
|
50
|
+
* Client plugins are separate from server plugins to avoid bundling
|
|
51
|
+
* server code into the client bundle.
|
|
52
|
+
*/
|
|
53
|
+
export interface ClientPlugin<TBinding extends Binder> {
|
|
47
54
|
id: string;
|
|
48
55
|
/**
|
|
49
56
|
* Short description of the plugin shown in the settings UI.
|
|
50
57
|
*/
|
|
51
58
|
description?: string;
|
|
52
59
|
binding: TBinding;
|
|
53
|
-
setup
|
|
60
|
+
setup?: PluginSetup;
|
|
54
61
|
/**
|
|
55
62
|
* Optional custom layout component for this plugin.
|
|
56
63
|
* If not provided, a default layout with connection selector will be used.
|
|
@@ -68,7 +75,16 @@ export interface Plugin<TBinding extends Binder> {
|
|
|
68
75
|
renderEmptyState?: () => ReactNode;
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated Use ClientPlugin instead
|
|
80
|
+
*/
|
|
81
|
+
export interface Plugin<TBinding extends Binder>
|
|
82
|
+
extends ClientPlugin<TBinding> {
|
|
83
|
+
setup: PluginSetup; // Required for backwards compatibility
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type AnyClientPlugin = ClientPlugin<Binder>;
|
|
87
|
+
export type AnyPlugin = Plugin<Binder>;
|
|
72
88
|
|
|
73
89
|
// Re-export plugin router utilities
|
|
74
90
|
export {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server Plugin Interface
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract for server-side plugins that can extend Mesh with:
|
|
5
|
+
* - MCP tools
|
|
6
|
+
* - API routes (authenticated and public)
|
|
7
|
+
* - Database migrations
|
|
8
|
+
* - Storage factories
|
|
9
|
+
*
|
|
10
|
+
* Server plugins are separate from client plugins to avoid bundling
|
|
11
|
+
* server code into the client bundle.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Hono } from "hono";
|
|
15
|
+
import type { Kysely } from "kysely";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Tool definition compatible with MCP tools.
|
|
19
|
+
* This is a simplified type - the actual implementation uses the full ToolDefinition from mesh.
|
|
20
|
+
*/
|
|
21
|
+
export interface ServerPluginToolDefinition {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
inputSchema: unknown;
|
|
25
|
+
outputSchema?: unknown;
|
|
26
|
+
handler: (input: unknown, ctx: unknown) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Database migration definition for plugins.
|
|
31
|
+
*/
|
|
32
|
+
export interface ServerPluginMigration {
|
|
33
|
+
/** Unique name for ordering (e.g., "001-initial-schema") */
|
|
34
|
+
name: string;
|
|
35
|
+
/** Apply the migration */
|
|
36
|
+
up: (db: Kysely<unknown>) => Promise<void>;
|
|
37
|
+
/** Revert the migration */
|
|
38
|
+
down: (db: Kysely<unknown>) => Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Context provided to server plugins for route registration and storage creation.
|
|
43
|
+
*/
|
|
44
|
+
export interface ServerPluginContext {
|
|
45
|
+
/** Database instance */
|
|
46
|
+
db: Kysely<unknown>;
|
|
47
|
+
/** Credential vault for encrypting sensitive data */
|
|
48
|
+
vault: {
|
|
49
|
+
encrypt: (value: string) => Promise<string>;
|
|
50
|
+
decrypt: (value: string) => Promise<string>;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Server Plugin interface.
|
|
56
|
+
*
|
|
57
|
+
* Plugins export this interface from their server entry point.
|
|
58
|
+
* Tools are registered at startup but gated by org settings at runtime.
|
|
59
|
+
*/
|
|
60
|
+
export interface ServerPlugin {
|
|
61
|
+
/** Unique plugin identifier (e.g., "user-sandbox") */
|
|
62
|
+
id: string;
|
|
63
|
+
|
|
64
|
+
/** Short description shown in settings UI */
|
|
65
|
+
description?: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* MCP tools this plugin provides.
|
|
69
|
+
* Tools are wrapped with org-enabled gating at registration time.
|
|
70
|
+
*/
|
|
71
|
+
tools?: ServerPluginToolDefinition[];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Authenticated API routes.
|
|
75
|
+
* Mounted at /api/plugins/:pluginId/*
|
|
76
|
+
* Requires Mesh authentication.
|
|
77
|
+
*/
|
|
78
|
+
routes?: (app: Hono, ctx: ServerPluginContext) => void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Public API routes (no authentication required).
|
|
82
|
+
* Mounted at the root level.
|
|
83
|
+
* Use for endpoints that external users access (e.g., connect flow).
|
|
84
|
+
*/
|
|
85
|
+
publicRoutes?: (app: Hono, ctx: ServerPluginContext) => void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Database migrations for this plugin.
|
|
89
|
+
* Run alongside core migrations in name order.
|
|
90
|
+
*/
|
|
91
|
+
migrations?: ServerPluginMigration[];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Factory to create plugin-specific storage adapters.
|
|
95
|
+
* Called during context initialization.
|
|
96
|
+
*/
|
|
97
|
+
createStorage?: (ctx: ServerPluginContext) => unknown;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Type helper for any server plugin
|
|
102
|
+
*/
|
|
103
|
+
export type AnyServerPlugin = ServerPlugin;
|
|
@@ -205,7 +205,12 @@ export const WorkflowExecutionSchema = BaseCollectionEntitySchema.extend({
|
|
|
205
205
|
completed_steps: z
|
|
206
206
|
.object({
|
|
207
207
|
success: z
|
|
208
|
-
.array(
|
|
208
|
+
.array(
|
|
209
|
+
z.object({
|
|
210
|
+
name: z.string(),
|
|
211
|
+
completed_at_epoch_ms: z.number(),
|
|
212
|
+
}),
|
|
213
|
+
)
|
|
209
214
|
.describe("Names of the steps that were completed successfully"),
|
|
210
215
|
error: z.array(z.string()).describe("Names of the steps that errored"),
|
|
211
216
|
})
|