@dbx-tools/appkit-mastra-shared 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wire-format types and URL helpers shipped by `@dbx-tools/appkit-mastra`'s
3
+ * `clientConfig()` surface.
4
+ *
5
+ * Kept dependency-free (no `pg`, no `fastembed`, no Mastra runtime) so
6
+ * the React client and any browser bundle can import these types
7
+ * without dragging in server-only dependencies. The server-side plugin
8
+ * publishes resolved paths through this contract; the client reads
9
+ * them back via `usePluginClientConfig<MastraClientConfig>("mastra")`
10
+ * and composes URLs with {@link chatUrl}.
11
+ */
12
+ export * from "./src/protocol.js";
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wire-format types and URL helpers shipped by `@dbx-tools/appkit-mastra`'s
3
+ * `clientConfig()` surface.
4
+ *
5
+ * Kept dependency-free (no `pg`, no `fastembed`, no Mastra runtime) so
6
+ * the React client and any browser bundle can import these types
7
+ * without dragging in server-only dependencies. The server-side plugin
8
+ * publishes resolved paths through this contract; the client reads
9
+ * them back via `usePluginClientConfig<MastraClientConfig>("mastra")`
10
+ * and composes URLs with {@link chatUrl}.
11
+ */
12
+ export * from "./src/protocol.js";
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Shape of the data published by {@link MastraPlugin.clientConfig} plus
3
+ * a tiny URL helper. Kept dependency-free so the React client can
4
+ * import it without dragging in `pg`, `fastembed`, or Mastra itself.
5
+ *
6
+ * Server-side, `MastraPlugin` derives every path from the plugin mount
7
+ * (AppKit conventionally serves plugin `foo` at `/api/foo`). Publishing
8
+ * the resolved paths lets the client compute URLs without hard-coding
9
+ * `/api/mastra` anywhere - rename the plugin and the React client
10
+ * keeps working.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { usePluginClientConfig } from "@databricks/appkit-ui/react";
15
+ * import { chatUrl, type MastraClientConfig } from "@dbx-tools/appkit-mastra-shared";
16
+ *
17
+ * const config = usePluginClientConfig<MastraClientConfig>("mastra");
18
+ * const transport = new DefaultChatTransport({
19
+ * api: chatUrl(config, selectedAgentId),
20
+ * });
21
+ * ```
22
+ */
23
+ /** JSON-safe descriptor published by the Mastra plugin's `clientConfig()`. */
24
+ export interface MastraClientConfig {
25
+ /** Plugin mount path. Always `/api/<pluginName>`. */
26
+ basePath: string;
27
+ /**
28
+ * Chat endpoint for the **default** agent, i.e.
29
+ * `${basePath}/route/chat`. Equivalent to `chatUrl(config)`.
30
+ */
31
+ chatPath: string;
32
+ /**
33
+ * Template form used by the route handler:
34
+ * `${basePath}/route/chat/:agentId`. Provided for documentation /
35
+ * tools that want the OpenAPI-style placeholder; clients should
36
+ * normally call {@link chatUrl} instead.
37
+ */
38
+ chatPathTemplate: string;
39
+ /** Models catalogue endpoint: `${basePath}/models`. */
40
+ modelsPath: string;
41
+ /** Agent id `chatRoute` binds to when the client doesn't name one. */
42
+ defaultAgent: string;
43
+ /** Every registered agent id in registration order. */
44
+ agents: string[];
45
+ }
46
+ /**
47
+ * Minimal descriptor for a Databricks Model Serving endpoint. Mirrors
48
+ * the server-side `ServingEndpointSummary` from `serving.ts` and is
49
+ * kept here so the React client can type the `/models` response
50
+ * without importing the full plugin (which would pull in `pg`,
51
+ * `fastembed`, and Mastra itself).
52
+ */
53
+ export interface ServingEndpointSummary {
54
+ /** Endpoint name as listed by the Model Serving REST API. */
55
+ name: string;
56
+ /** Task hint (e.g. `"llm/v1/chat"`). Useful for filtering. */
57
+ task?: string;
58
+ /** Ready / updating / failed state. */
59
+ state?: string;
60
+ /** Free-form description; mostly informational. */
61
+ description?: string;
62
+ }
63
+ /** JSON payload returned by `GET ${basePath}/models`. */
64
+ export interface ServingEndpointsResponse {
65
+ endpoints: ServingEndpointSummary[];
66
+ }
67
+ /**
68
+ * Compute the chat URL for a given agent, falling back to the default
69
+ * when `agentId` is omitted. Returns `config.chatPath` directly for
70
+ * the default agent (the `chatRoute` mount that does not require an
71
+ * `:agentId` segment).
72
+ */
73
+ export declare function chatUrl(config: Pick<MastraClientConfig, "chatPath" | "defaultAgent">, agentId?: string): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shape of the data published by {@link MastraPlugin.clientConfig} plus
3
+ * a tiny URL helper. Kept dependency-free so the React client can
4
+ * import it without dragging in `pg`, `fastembed`, or Mastra itself.
5
+ *
6
+ * Server-side, `MastraPlugin` derives every path from the plugin mount
7
+ * (AppKit conventionally serves plugin `foo` at `/api/foo`). Publishing
8
+ * the resolved paths lets the client compute URLs without hard-coding
9
+ * `/api/mastra` anywhere - rename the plugin and the React client
10
+ * keeps working.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { usePluginClientConfig } from "@databricks/appkit-ui/react";
15
+ * import { chatUrl, type MastraClientConfig } from "@dbx-tools/appkit-mastra-shared";
16
+ *
17
+ * const config = usePluginClientConfig<MastraClientConfig>("mastra");
18
+ * const transport = new DefaultChatTransport({
19
+ * api: chatUrl(config, selectedAgentId),
20
+ * });
21
+ * ```
22
+ */
23
+ /**
24
+ * Compute the chat URL for a given agent, falling back to the default
25
+ * when `agentId` is omitted. Returns `config.chatPath` directly for
26
+ * the default agent (the `chatRoute` mount that does not require an
27
+ * `:agentId` segment).
28
+ */
29
+ export function chatUrl(config, agentId) {
30
+ const id = agentId ?? config.defaultAgent;
31
+ if (!id || id === config.defaultAgent)
32
+ return config.chatPath;
33
+ return `${config.chatPath}/${encodeURIComponent(id)}`;
34
+ }
package/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wire-format types and URL helpers shipped by `@dbx-tools/appkit-mastra`'s
3
+ * `clientConfig()` surface.
4
+ *
5
+ * Kept dependency-free (no `pg`, no `fastembed`, no Mastra runtime) so
6
+ * the React client and any browser bundle can import these types
7
+ * without dragging in server-only dependencies. The server-side plugin
8
+ * publishes resolved paths through this contract; the client reads
9
+ * them back via `usePluginClientConfig<MastraClientConfig>("mastra")`
10
+ * and composes URLs with {@link chatUrl}.
11
+ */
12
+ export * from "./src/protocol.js";
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "main": "dist/index.js",
3
+ "types": "dist/index.d.ts",
4
+ "exports": {
5
+ ".": {
6
+ "source": "./index.ts",
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ }
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "index.ts",
14
+ "src"
15
+ ],
16
+ "license": "Apache-2.0",
17
+ "homepage": "https://github.com/reggie-db/dbx-tools-appkit#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/reggie-db/dbx-tools-appkit/issues"
20
+ },
21
+ "publishConfig": {
22
+ "registry": "https://registry.npmjs.org/",
23
+ "access": "public"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/reggie-db/dbx-tools-appkit.git",
28
+ "directory": "packages/mastra-shared"
29
+ },
30
+ "name": "@dbx-tools/appkit-mastra-shared",
31
+ "version": "0.1.0",
32
+ "module": "index.ts",
33
+ "type": "module"
34
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Shape of the data published by {@link MastraPlugin.clientConfig} plus
3
+ * a tiny URL helper. Kept dependency-free so the React client can
4
+ * import it without dragging in `pg`, `fastembed`, or Mastra itself.
5
+ *
6
+ * Server-side, `MastraPlugin` derives every path from the plugin mount
7
+ * (AppKit conventionally serves plugin `foo` at `/api/foo`). Publishing
8
+ * the resolved paths lets the client compute URLs without hard-coding
9
+ * `/api/mastra` anywhere - rename the plugin and the React client
10
+ * keeps working.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * import { usePluginClientConfig } from "@databricks/appkit-ui/react";
15
+ * import { chatUrl, type MastraClientConfig } from "@dbx-tools/appkit-mastra-shared";
16
+ *
17
+ * const config = usePluginClientConfig<MastraClientConfig>("mastra");
18
+ * const transport = new DefaultChatTransport({
19
+ * api: chatUrl(config, selectedAgentId),
20
+ * });
21
+ * ```
22
+ */
23
+
24
+ /** JSON-safe descriptor published by the Mastra plugin's `clientConfig()`. */
25
+ export interface MastraClientConfig {
26
+ /** Plugin mount path. Always `/api/<pluginName>`. */
27
+ basePath: string;
28
+ /**
29
+ * Chat endpoint for the **default** agent, i.e.
30
+ * `${basePath}/route/chat`. Equivalent to `chatUrl(config)`.
31
+ */
32
+ chatPath: string;
33
+ /**
34
+ * Template form used by the route handler:
35
+ * `${basePath}/route/chat/:agentId`. Provided for documentation /
36
+ * tools that want the OpenAPI-style placeholder; clients should
37
+ * normally call {@link chatUrl} instead.
38
+ */
39
+ chatPathTemplate: string;
40
+ /** Models catalogue endpoint: `${basePath}/models`. */
41
+ modelsPath: string;
42
+ /** Agent id `chatRoute` binds to when the client doesn't name one. */
43
+ defaultAgent: string;
44
+ /** Every registered agent id in registration order. */
45
+ agents: string[];
46
+ }
47
+
48
+ /**
49
+ * Minimal descriptor for a Databricks Model Serving endpoint. Mirrors
50
+ * the server-side `ServingEndpointSummary` from `serving.ts` and is
51
+ * kept here so the React client can type the `/models` response
52
+ * without importing the full plugin (which would pull in `pg`,
53
+ * `fastembed`, and Mastra itself).
54
+ */
55
+ export interface ServingEndpointSummary {
56
+ /** Endpoint name as listed by the Model Serving REST API. */
57
+ name: string;
58
+ /** Task hint (e.g. `"llm/v1/chat"`). Useful for filtering. */
59
+ task?: string;
60
+ /** Ready / updating / failed state. */
61
+ state?: string;
62
+ /** Free-form description; mostly informational. */
63
+ description?: string;
64
+ }
65
+
66
+ /** JSON payload returned by `GET ${basePath}/models`. */
67
+ export interface ServingEndpointsResponse {
68
+ endpoints: ServingEndpointSummary[];
69
+ }
70
+
71
+ /**
72
+ * Compute the chat URL for a given agent, falling back to the default
73
+ * when `agentId` is omitted. Returns `config.chatPath` directly for
74
+ * the default agent (the `chatRoute` mount that does not require an
75
+ * `:agentId` segment).
76
+ */
77
+ export function chatUrl(
78
+ config: Pick<MastraClientConfig, "chatPath" | "defaultAgent">,
79
+ agentId?: string,
80
+ ): string {
81
+ const id = agentId ?? config.defaultAgent;
82
+ if (!id || id === config.defaultAgent) return config.chatPath;
83
+ return `${config.chatPath}/${encodeURIComponent(id)}`;
84
+ }