@dbx-tools/appkit-mastra-shared 0.1.4 → 0.1.5
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/dist/src/protocol.d.ts +90 -0
- package/dist/src/protocol.js +20 -0
- package/package.json +1 -1
- package/src/protocol.ts +107 -0
package/dist/src/protocol.d.ts
CHANGED
|
@@ -38,6 +38,27 @@ export interface MastraClientConfig {
|
|
|
38
38
|
chatPathTemplate: string;
|
|
39
39
|
/** Models catalogue endpoint: `${basePath}/models`. */
|
|
40
40
|
modelsPath: string;
|
|
41
|
+
/**
|
|
42
|
+
* Thread history endpoint for the **default** agent:
|
|
43
|
+
* `${basePath}/route/history`. Returns AI SDK V5 `UIMessage`s for
|
|
44
|
+
* the current session's thread; takes `page` and `perPage` query
|
|
45
|
+
* params. See {@link historyUrl}.
|
|
46
|
+
*/
|
|
47
|
+
historyPath: string;
|
|
48
|
+
/**
|
|
49
|
+
* Templated form of {@link historyPath}: `${basePath}/route/history/:agentId`.
|
|
50
|
+
* Use this to reach a non-default agent's history; clients should
|
|
51
|
+
* normally call {@link historyUrl} instead.
|
|
52
|
+
*/
|
|
53
|
+
historyPathTemplate: string;
|
|
54
|
+
/**
|
|
55
|
+
* Chart-rendering endpoint:
|
|
56
|
+
* `${basePath}/route/render-chart`. POST a dataset; receive an
|
|
57
|
+
* Echarts `EChartsOption` JSON. Used by the chat client to fill
|
|
58
|
+
* the placeholders the model emits via `[[chart:<id>]]`
|
|
59
|
+
* markers without blocking the main agent stream.
|
|
60
|
+
*/
|
|
61
|
+
renderChartPath: string;
|
|
41
62
|
/** Agent id `chatRoute` binds to when the client doesn't name one. */
|
|
42
63
|
defaultAgent: string;
|
|
43
64
|
/** Every registered agent id in registration order. */
|
|
@@ -71,3 +92,72 @@ export interface ServingEndpointsResponse {
|
|
|
71
92
|
* `:agentId` segment).
|
|
72
93
|
*/
|
|
73
94
|
export declare function chatUrl(config: Pick<MastraClientConfig, "chatPath" | "defaultAgent">, agentId?: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Structural shape for an AI SDK V5 `UIMessage`. Defined locally so
|
|
97
|
+
* the shared types package stays dependency-free (no `ai` import).
|
|
98
|
+
* The runtime values returned by the `/history` endpoint are produced
|
|
99
|
+
* by `toAISdkV5Messages` and are 1:1 compatible with `UIMessage` from
|
|
100
|
+
* the `ai` package; clients can safely cast when needed.
|
|
101
|
+
*/
|
|
102
|
+
export interface MastraHistoryUIMessage {
|
|
103
|
+
id: string;
|
|
104
|
+
role: "system" | "user" | "assistant";
|
|
105
|
+
parts: ReadonlyArray<unknown>;
|
|
106
|
+
metadata?: unknown;
|
|
107
|
+
}
|
|
108
|
+
/** JSON payload returned by `GET ${basePath}/history`. */
|
|
109
|
+
export interface MastraHistoryResponse {
|
|
110
|
+
/**
|
|
111
|
+
* Page of UI-formatted messages, oldest -> newest. Always
|
|
112
|
+
* chronological regardless of the underlying pagination order so
|
|
113
|
+
* the client can prepend the array to the live transcript without
|
|
114
|
+
* sorting.
|
|
115
|
+
*/
|
|
116
|
+
uiMessages: MastraHistoryUIMessage[];
|
|
117
|
+
/** Zero-indexed page that produced this response. */
|
|
118
|
+
page: number;
|
|
119
|
+
/** Number of items requested per page. */
|
|
120
|
+
perPage: number;
|
|
121
|
+
/** Total number of messages in the thread. */
|
|
122
|
+
total: number;
|
|
123
|
+
/** True when at least one older page is still available. */
|
|
124
|
+
hasMore: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Body accepted by `POST ${basePath}/route/render-chart`. The
|
|
128
|
+
* server-side chart-planner agent picks a chart type and axis
|
|
129
|
+
* encodings, then expands the result into a full
|
|
130
|
+
* `EChartsOption` JSON.
|
|
131
|
+
*
|
|
132
|
+
* `data` is an array of objects keyed by column name (the same
|
|
133
|
+
* shape every row in a SQL row set has). `title` is shown above
|
|
134
|
+
* the chart; `description` is an optional one-line intent the
|
|
135
|
+
* planner can use to bias chart-type selection.
|
|
136
|
+
*/
|
|
137
|
+
export interface RenderChartRequest {
|
|
138
|
+
title: string;
|
|
139
|
+
description?: string;
|
|
140
|
+
data: Array<Record<string, unknown>>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* JSON returned by `POST ${basePath}/route/render-chart`. The
|
|
144
|
+
* `option` field is an Apache Echarts `EChartsOption` JSON the
|
|
145
|
+
* client passes verbatim to `<ReactECharts option={...} />`.
|
|
146
|
+
* `chartType` echoes the planner's pick so the caller can label
|
|
147
|
+
* the chart in surrounding prose.
|
|
148
|
+
*/
|
|
149
|
+
export interface RenderChartResponse {
|
|
150
|
+
option: Record<string, unknown>;
|
|
151
|
+
chartType: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Build the history URL for a given agent + page. Mirrors
|
|
155
|
+
* {@link chatUrl}: the default agent uses the bare `historyPath`,
|
|
156
|
+
* any other agent appends `/<encoded id>` to it. `page` and
|
|
157
|
+
* `perPage` are appended as query parameters when provided.
|
|
158
|
+
*/
|
|
159
|
+
export declare function historyUrl(config: Pick<MastraClientConfig, "historyPath" | "defaultAgent">, options?: {
|
|
160
|
+
agentId?: string;
|
|
161
|
+
page?: number;
|
|
162
|
+
perPage?: number;
|
|
163
|
+
}): string;
|
package/dist/src/protocol.js
CHANGED
|
@@ -32,3 +32,23 @@ export function chatUrl(config, agentId) {
|
|
|
32
32
|
return config.chatPath;
|
|
33
33
|
return `${config.chatPath}/${encodeURIComponent(id)}`;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the history URL for a given agent + page. Mirrors
|
|
37
|
+
* {@link chatUrl}: the default agent uses the bare `historyPath`,
|
|
38
|
+
* any other agent appends `/<encoded id>` to it. `page` and
|
|
39
|
+
* `perPage` are appended as query parameters when provided.
|
|
40
|
+
*/
|
|
41
|
+
export function historyUrl(config, options = {}) {
|
|
42
|
+
const id = options.agentId ?? config.defaultAgent;
|
|
43
|
+
const base = !id || id === config.defaultAgent
|
|
44
|
+
? config.historyPath
|
|
45
|
+
: `${config.historyPath}/${encodeURIComponent(id)}`;
|
|
46
|
+
const params = new URLSearchParams();
|
|
47
|
+
if (options.page !== undefined)
|
|
48
|
+
params.set("page", String(options.page));
|
|
49
|
+
if (options.perPage !== undefined) {
|
|
50
|
+
params.set("perPage", String(options.perPage));
|
|
51
|
+
}
|
|
52
|
+
const qs = params.toString();
|
|
53
|
+
return qs ? `${base}?${qs}` : base;
|
|
54
|
+
}
|
package/package.json
CHANGED
package/src/protocol.ts
CHANGED
|
@@ -39,6 +39,27 @@ export interface MastraClientConfig {
|
|
|
39
39
|
chatPathTemplate: string;
|
|
40
40
|
/** Models catalogue endpoint: `${basePath}/models`. */
|
|
41
41
|
modelsPath: string;
|
|
42
|
+
/**
|
|
43
|
+
* Thread history endpoint for the **default** agent:
|
|
44
|
+
* `${basePath}/route/history`. Returns AI SDK V5 `UIMessage`s for
|
|
45
|
+
* the current session's thread; takes `page` and `perPage` query
|
|
46
|
+
* params. See {@link historyUrl}.
|
|
47
|
+
*/
|
|
48
|
+
historyPath: string;
|
|
49
|
+
/**
|
|
50
|
+
* Templated form of {@link historyPath}: `${basePath}/route/history/:agentId`.
|
|
51
|
+
* Use this to reach a non-default agent's history; clients should
|
|
52
|
+
* normally call {@link historyUrl} instead.
|
|
53
|
+
*/
|
|
54
|
+
historyPathTemplate: string;
|
|
55
|
+
/**
|
|
56
|
+
* Chart-rendering endpoint:
|
|
57
|
+
* `${basePath}/route/render-chart`. POST a dataset; receive an
|
|
58
|
+
* Echarts `EChartsOption` JSON. Used by the chat client to fill
|
|
59
|
+
* the placeholders the model emits via `[[chart:<id>]]`
|
|
60
|
+
* markers without blocking the main agent stream.
|
|
61
|
+
*/
|
|
62
|
+
renderChartPath: string;
|
|
42
63
|
/** Agent id `chatRoute` binds to when the client doesn't name one. */
|
|
43
64
|
defaultAgent: string;
|
|
44
65
|
/** Every registered agent id in registration order. */
|
|
@@ -82,3 +103,89 @@ export function chatUrl(
|
|
|
82
103
|
if (!id || id === config.defaultAgent) return config.chatPath;
|
|
83
104
|
return `${config.chatPath}/${encodeURIComponent(id)}`;
|
|
84
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Structural shape for an AI SDK V5 `UIMessage`. Defined locally so
|
|
109
|
+
* the shared types package stays dependency-free (no `ai` import).
|
|
110
|
+
* The runtime values returned by the `/history` endpoint are produced
|
|
111
|
+
* by `toAISdkV5Messages` and are 1:1 compatible with `UIMessage` from
|
|
112
|
+
* the `ai` package; clients can safely cast when needed.
|
|
113
|
+
*/
|
|
114
|
+
export interface MastraHistoryUIMessage {
|
|
115
|
+
id: string;
|
|
116
|
+
role: "system" | "user" | "assistant";
|
|
117
|
+
parts: ReadonlyArray<unknown>;
|
|
118
|
+
metadata?: unknown;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** JSON payload returned by `GET ${basePath}/history`. */
|
|
122
|
+
export interface MastraHistoryResponse {
|
|
123
|
+
/**
|
|
124
|
+
* Page of UI-formatted messages, oldest -> newest. Always
|
|
125
|
+
* chronological regardless of the underlying pagination order so
|
|
126
|
+
* the client can prepend the array to the live transcript without
|
|
127
|
+
* sorting.
|
|
128
|
+
*/
|
|
129
|
+
uiMessages: MastraHistoryUIMessage[];
|
|
130
|
+
/** Zero-indexed page that produced this response. */
|
|
131
|
+
page: number;
|
|
132
|
+
/** Number of items requested per page. */
|
|
133
|
+
perPage: number;
|
|
134
|
+
/** Total number of messages in the thread. */
|
|
135
|
+
total: number;
|
|
136
|
+
/** True when at least one older page is still available. */
|
|
137
|
+
hasMore: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Body accepted by `POST ${basePath}/route/render-chart`. The
|
|
142
|
+
* server-side chart-planner agent picks a chart type and axis
|
|
143
|
+
* encodings, then expands the result into a full
|
|
144
|
+
* `EChartsOption` JSON.
|
|
145
|
+
*
|
|
146
|
+
* `data` is an array of objects keyed by column name (the same
|
|
147
|
+
* shape every row in a SQL row set has). `title` is shown above
|
|
148
|
+
* the chart; `description` is an optional one-line intent the
|
|
149
|
+
* planner can use to bias chart-type selection.
|
|
150
|
+
*/
|
|
151
|
+
export interface RenderChartRequest {
|
|
152
|
+
title: string;
|
|
153
|
+
description?: string;
|
|
154
|
+
data: Array<Record<string, unknown>>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* JSON returned by `POST ${basePath}/route/render-chart`. The
|
|
159
|
+
* `option` field is an Apache Echarts `EChartsOption` JSON the
|
|
160
|
+
* client passes verbatim to `<ReactECharts option={...} />`.
|
|
161
|
+
* `chartType` echoes the planner's pick so the caller can label
|
|
162
|
+
* the chart in surrounding prose.
|
|
163
|
+
*/
|
|
164
|
+
export interface RenderChartResponse {
|
|
165
|
+
option: Record<string, unknown>;
|
|
166
|
+
chartType: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Build the history URL for a given agent + page. Mirrors
|
|
171
|
+
* {@link chatUrl}: the default agent uses the bare `historyPath`,
|
|
172
|
+
* any other agent appends `/<encoded id>` to it. `page` and
|
|
173
|
+
* `perPage` are appended as query parameters when provided.
|
|
174
|
+
*/
|
|
175
|
+
export function historyUrl(
|
|
176
|
+
config: Pick<MastraClientConfig, "historyPath" | "defaultAgent">,
|
|
177
|
+
options: { agentId?: string; page?: number; perPage?: number } = {},
|
|
178
|
+
): string {
|
|
179
|
+
const id = options.agentId ?? config.defaultAgent;
|
|
180
|
+
const base =
|
|
181
|
+
!id || id === config.defaultAgent
|
|
182
|
+
? config.historyPath
|
|
183
|
+
: `${config.historyPath}/${encodeURIComponent(id)}`;
|
|
184
|
+
const params = new URLSearchParams();
|
|
185
|
+
if (options.page !== undefined) params.set("page", String(options.page));
|
|
186
|
+
if (options.perPage !== undefined) {
|
|
187
|
+
params.set("perPage", String(options.perPage));
|
|
188
|
+
}
|
|
189
|
+
const qs = params.toString();
|
|
190
|
+
return qs ? `${base}?${qs}` : base;
|
|
191
|
+
}
|