mastra 0.1.57-alpha.96 → 0.1.57-alpha.97
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/templates/express-server.d.ts.map +1 -1
- package/dist/templates/express-server.js +24 -119
- package/dist/templates/netlify.d.ts.map +1 -1
- package/dist/templates/netlify.js +16 -59
- package/dist/templates/worker.d.ts.map +1 -1
- package/dist/templates/worker.js +11 -95
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express-server.d.ts","sourceRoot":"","sources":["../../src/templates/express-server.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"express-server.d.ts","sourceRoot":"","sources":["../../src/templates/express-server.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AA48BzC,eAAO,MAAM,OAAO,oBAAkB,CAAC;AAQvC,eAAe,OAAO,CAAC"}
|
|
@@ -163,11 +163,14 @@ app.get('/api/agents', async (_req, res) => {
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
/**
|
|
166
|
-
* POST /api/agents
|
|
167
|
-
* @summary Send
|
|
166
|
+
* POST /api/agents/:agentId/generate
|
|
167
|
+
* @summary Send messages to agent
|
|
168
168
|
* @tags Agent
|
|
169
169
|
* @param {string} agentId.path.required - Agent identifier
|
|
170
170
|
* @param {Messages} request.body.required - Messages to send
|
|
171
|
+
* @param {string} request.body.optional - Thread ID
|
|
172
|
+
* @param {string} request.body.optional - Resource ID
|
|
173
|
+
* @param {string} request.body.optional - Output schema
|
|
171
174
|
* @return {object} 200 - Agent response
|
|
172
175
|
* @return {Error} 400 - Validation error
|
|
173
176
|
* @return {Error} 500 - Server error
|
|
@@ -176,7 +179,7 @@ app.post('/api/agents/:agentId/generate', async (req, res) => {
|
|
|
176
179
|
try {
|
|
177
180
|
const agentId = req.params.agentId;
|
|
178
181
|
const agent = mastra.getAgent(agentId);
|
|
179
|
-
const { messages, threadId, resourceid } = req.body;
|
|
182
|
+
const { messages, threadId, resourceid, output } = req.body;
|
|
180
183
|
const { ok, errorResponse } = await validateBody({
|
|
181
184
|
messages,
|
|
182
185
|
});
|
|
@@ -184,26 +187,33 @@ app.post('/api/agents/:agentId/generate', async (req, res) => {
|
|
|
184
187
|
res.status(400).json({ error: errorResponse });
|
|
185
188
|
return;
|
|
186
189
|
}
|
|
187
|
-
const result = await agent.generate(messages, { threadId, resourceid });
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
const result = await agent.generate(messages, { output, threadId, resourceid });
|
|
191
|
+
if (output) {
|
|
192
|
+
res.json({
|
|
193
|
+
object: result.object,
|
|
194
|
+
agent: result.agent,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
res.json({ text: result.text, agent: agent.name });
|
|
199
|
+
}
|
|
193
200
|
}
|
|
194
201
|
catch (error) {
|
|
195
202
|
const apiError = error;
|
|
196
|
-
console.error('Error
|
|
197
|
-
res.status(apiError.status || 500).json({ error: apiError.message || 'Error
|
|
203
|
+
console.error('Error generating from agent', apiError);
|
|
204
|
+
res.status(apiError.status || 500).json({ error: apiError.message || 'Error generating from agent' });
|
|
198
205
|
return;
|
|
199
206
|
}
|
|
200
207
|
});
|
|
201
208
|
/**
|
|
202
|
-
* POST /api/agents
|
|
209
|
+
* POST /api/agents/:agentId/stream
|
|
203
210
|
* @summary Stream messages to agent
|
|
204
211
|
* @tags Agent
|
|
205
212
|
* @param {string} agentId.path.required - Agent identifier
|
|
206
213
|
* @param {Messages} request.body.required - Messages to stream
|
|
214
|
+
* @param {string} request.body.optional - Thread ID
|
|
215
|
+
* @param {string} request.body.optional - Resource ID
|
|
216
|
+
* @param {string} request.body.optional - Output schema
|
|
207
217
|
* @return {stream} 200 - Agent response stream
|
|
208
218
|
* @return {Error} 400 - Validation error
|
|
209
219
|
* @return {Error} 500 - Server error
|
|
@@ -212,7 +222,7 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
|
|
|
212
222
|
try {
|
|
213
223
|
const agentId = req.params.agentId;
|
|
214
224
|
const agent = mastra.getAgent(agentId);
|
|
215
|
-
const { messages, threadId, resourceid } = req.body;
|
|
225
|
+
const { messages, threadId, resourceid, output } = req.body;
|
|
216
226
|
const { ok, errorResponse } = await validateBody({
|
|
217
227
|
messages,
|
|
218
228
|
});
|
|
@@ -221,6 +231,7 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
|
|
|
221
231
|
return;
|
|
222
232
|
}
|
|
223
233
|
const streamResult = await agent.stream(messages, {
|
|
234
|
+
output,
|
|
224
235
|
threadId,
|
|
225
236
|
resourceid,
|
|
226
237
|
});
|
|
@@ -233,112 +244,6 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
|
|
|
233
244
|
return;
|
|
234
245
|
}
|
|
235
246
|
});
|
|
236
|
-
/**
|
|
237
|
-
* POST /api/agents/{agentId}/text-object
|
|
238
|
-
* @summary Get structured output from agent
|
|
239
|
-
* @tags Agent
|
|
240
|
-
* @param {string} agentId.path.required - Agent identifier
|
|
241
|
-
* @param {TextObjectRequest} request.body.required - Request with messages and schema spec
|
|
242
|
-
* @return {object} 200 - Structured output response
|
|
243
|
-
* @return {Error} 400 - Validation error
|
|
244
|
-
* @return {Error} 500 - Server error
|
|
245
|
-
*/
|
|
246
|
-
app.post('/api/agents/:agentId/text-object', async (req, res) => {
|
|
247
|
-
try {
|
|
248
|
-
const agentId = req.params.agentId;
|
|
249
|
-
const agent = mastra.getAgent(agentId);
|
|
250
|
-
const { messages, schema, threadId, resourceid } = req.body;
|
|
251
|
-
const { ok, errorResponse } = await validateBody({
|
|
252
|
-
messages,
|
|
253
|
-
schema,
|
|
254
|
-
});
|
|
255
|
-
if (!ok) {
|
|
256
|
-
res.status(400).json({ error: errorResponse });
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const result = await agent.generate(messages, { output: schema, threadId, resourceid });
|
|
260
|
-
const objectResult = {
|
|
261
|
-
object: result.object,
|
|
262
|
-
agent: result.agent,
|
|
263
|
-
};
|
|
264
|
-
res.json(objectResult);
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
const apiError = error;
|
|
268
|
-
console.error('Error getting structured output from agent', apiError);
|
|
269
|
-
res
|
|
270
|
-
.status(apiError.status || 500)
|
|
271
|
-
.json({ error: apiError.message || 'Error getting structured output from agent' });
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
/**
|
|
276
|
-
* POST /api/agents/{agentId}/stream-object
|
|
277
|
-
* @summary Stream structured output from agent
|
|
278
|
-
* @tags Agent
|
|
279
|
-
* @param {string} agentId.path.required - Agent identifier
|
|
280
|
-
* @param {TextObjectRequest} request.body.required - Request with messages and schema spec
|
|
281
|
-
* @return {stream} 200 - Structured output stream
|
|
282
|
-
* @return {Error} 400 - Validation error
|
|
283
|
-
* @return {Error} 500 - Server error
|
|
284
|
-
*/
|
|
285
|
-
app.post('/api/agents/:agentId/stream-object', async (req, res) => {
|
|
286
|
-
try {
|
|
287
|
-
const agentId = req.params.agentId;
|
|
288
|
-
const agent = mastra.getAgent(agentId);
|
|
289
|
-
const { messages, schema, threadId, resourceid } = req.body;
|
|
290
|
-
const { ok, errorResponse } = await validateBody({
|
|
291
|
-
messages,
|
|
292
|
-
schema,
|
|
293
|
-
});
|
|
294
|
-
if (!ok) {
|
|
295
|
-
res.status(400).json({ error: errorResponse });
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
const streamResult = await agent.stream(messages, { output: schema, threadId, resourceid });
|
|
299
|
-
streamResult.pipeTextStreamToResponse(res);
|
|
300
|
-
}
|
|
301
|
-
catch (error) {
|
|
302
|
-
const apiError = error;
|
|
303
|
-
console.error('Error streaming structured output from agent', apiError);
|
|
304
|
-
res
|
|
305
|
-
.status(apiError.status || 500)
|
|
306
|
-
.json({ error: apiError.message || 'Error streaming structured output from agent' });
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
/**
|
|
311
|
-
* POST /api/agents/{agentId}/tools/{toolId}/execute
|
|
312
|
-
* @summary Execute an Agent tool
|
|
313
|
-
* @tags Agent
|
|
314
|
-
* @param {string} agentId.path.required - Agent identifier
|
|
315
|
-
* @param {string} toolId.path.required - Tool identifier
|
|
316
|
-
* @param {object} request.body.required - Tool input data
|
|
317
|
-
* @return {object} 200 - Tool execution result
|
|
318
|
-
* @return {Error} 500 - Server error
|
|
319
|
-
*/
|
|
320
|
-
app.post('/api/agents/:agentId/tools/:toolId/execute', async (req, res) => {
|
|
321
|
-
try {
|
|
322
|
-
const agentId = req.params.agentId;
|
|
323
|
-
const toolId = req.params.toolId;
|
|
324
|
-
const agent = mastra.getAgent(agentId);
|
|
325
|
-
const tool = Object.values(agent?.tools || {}).find((tool) => tool.id === toolId);
|
|
326
|
-
const result = await tool.execute({
|
|
327
|
-
context: {
|
|
328
|
-
...req.body,
|
|
329
|
-
},
|
|
330
|
-
mastra,
|
|
331
|
-
runId: agentId,
|
|
332
|
-
});
|
|
333
|
-
res.json(result);
|
|
334
|
-
}
|
|
335
|
-
catch (error) {
|
|
336
|
-
const apiError = error;
|
|
337
|
-
console.error('Error executing tool', apiError);
|
|
338
|
-
res.status(apiError.status || 500).json({ error: apiError.message || 'Error executing tool' });
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
247
|
/**
|
|
343
248
|
* GET /api/workflows
|
|
344
249
|
* @summary Get all workflows
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"netlify.d.ts","sourceRoot":"","sources":["../../src/templates/netlify.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"netlify.d.ts","sourceRoot":"","sources":["../../src/templates/netlify.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAuqBzC,eAAO,MAAM,OAAO,oBAAkB,CAAC"}
|
|
@@ -92,21 +92,27 @@ app.post('/api/agents/:agentId/generate', async (req, res) => {
|
|
|
92
92
|
try {
|
|
93
93
|
const agentId = req.params.agentId;
|
|
94
94
|
const agent = mastra.getAgent(agentId);
|
|
95
|
-
const { messages, threadId, resourceid } = req.body;
|
|
96
|
-
const { ok, errorResponse } = await validateBody({
|
|
97
|
-
messages,
|
|
98
|
-
});
|
|
95
|
+
const { messages, threadId, resourceid, output } = req.body;
|
|
96
|
+
const { ok, errorResponse } = await validateBody({ messages });
|
|
99
97
|
if (!ok) {
|
|
100
98
|
res.status(400).json({ error: errorResponse });
|
|
101
99
|
return;
|
|
102
100
|
}
|
|
103
|
-
const result = await agent.generate(messages, { threadId, resourceid });
|
|
104
|
-
|
|
101
|
+
const result = await agent.generate(messages, { output, threadId, resourceid });
|
|
102
|
+
if (output) {
|
|
103
|
+
res.json({
|
|
104
|
+
object: result.object,
|
|
105
|
+
agent: result.agent,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
res.json({ text: result.text, agent: agent.name });
|
|
110
|
+
}
|
|
105
111
|
}
|
|
106
112
|
catch (error) {
|
|
107
113
|
const apiError = error;
|
|
108
|
-
console.error('Error
|
|
109
|
-
res.status(apiError.status || 500).json({ error: apiError.message || 'Error
|
|
114
|
+
console.error('Error generating from agent', apiError);
|
|
115
|
+
res.status(apiError.status || 500).json({ error: apiError.message || 'Error generating from agent' });
|
|
110
116
|
return;
|
|
111
117
|
}
|
|
112
118
|
});
|
|
@@ -114,7 +120,7 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
|
|
|
114
120
|
try {
|
|
115
121
|
const agentId = req.params.agentId;
|
|
116
122
|
const agent = mastra.getAgent(agentId);
|
|
117
|
-
const { messages, threadId, resourceid } = req.body;
|
|
123
|
+
const { messages, threadId, resourceid, output } = req.body;
|
|
118
124
|
const { ok, errorResponse } = await validateBody({
|
|
119
125
|
messages,
|
|
120
126
|
});
|
|
@@ -123,6 +129,7 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
|
|
|
123
129
|
return;
|
|
124
130
|
}
|
|
125
131
|
const streamResult = await agent.stream(messages, {
|
|
132
|
+
output,
|
|
126
133
|
threadId,
|
|
127
134
|
resourceid,
|
|
128
135
|
});
|
|
@@ -135,56 +142,6 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
|
|
|
135
142
|
return;
|
|
136
143
|
}
|
|
137
144
|
});
|
|
138
|
-
app.post('/api/agents/:agentId/text-object', async (req, res) => {
|
|
139
|
-
try {
|
|
140
|
-
const agentId = req.params.agentId;
|
|
141
|
-
const agent = mastra.getAgent(agentId);
|
|
142
|
-
const { messages, schema, threadId, resourceid } = req.body;
|
|
143
|
-
const { ok, errorResponse } = await validateBody({
|
|
144
|
-
messages,
|
|
145
|
-
schema,
|
|
146
|
-
});
|
|
147
|
-
if (!ok) {
|
|
148
|
-
res.status(400).json({ error: errorResponse });
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const result = await agent.generate(messages, { output: schema, threadId, resourceid });
|
|
152
|
-
res.json(result);
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
const apiError = error;
|
|
156
|
-
console.error('Error getting structured output from agent', apiError);
|
|
157
|
-
res
|
|
158
|
-
.status(apiError.status || 500)
|
|
159
|
-
.json({ error: apiError.message || 'Error getting structured output from agent' });
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
app.post('/api/agents/:agentId/stream-object', async (req, res) => {
|
|
164
|
-
try {
|
|
165
|
-
const agentId = req.params.agentId;
|
|
166
|
-
const agent = mastra.getAgent(agentId);
|
|
167
|
-
const { messages, schema, threadId, resourceid } = req.body;
|
|
168
|
-
const { ok, errorResponse } = await validateBody({
|
|
169
|
-
messages,
|
|
170
|
-
schema,
|
|
171
|
-
});
|
|
172
|
-
if (!ok) {
|
|
173
|
-
res.status(400).json({ error: errorResponse });
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
const streamResult = await agent.stream(messages, { output: schema, threadId, resourceid });
|
|
177
|
-
streamResult.pipeTextStreamToResponse(res);
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
const apiError = error;
|
|
181
|
-
console.error('Error streaming structured output from agent', apiError);
|
|
182
|
-
res
|
|
183
|
-
.status(apiError.status || 500)
|
|
184
|
-
.json({ error: apiError.message || 'Error streaming structured output from agent' });
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
145
|
app.post('/api/agents/:agentId/tools/:toolId/execute', async (req, res) => {
|
|
189
146
|
try {
|
|
190
147
|
const agentId = req.params.agentId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/templates/worker.ts"],"names":[],"mappings":"AA8CA,UAAU,gBAAgB;IACxB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvC,sBAAsB,IAAI,IAAI,CAAC;CAChC;;
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/templates/worker.ts"],"names":[],"mappings":"AA8CA,UAAU,gBAAgB;IACxB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvC,sBAAsB,IAAI,IAAI,CAAC;CAChC;;mBAm8BsB,OAAO,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,gBAAgB;;AADlF,wBAQE"}
|
package/dist/templates/worker.js
CHANGED
|
@@ -116,7 +116,7 @@ router.post('/api/agents/:agentId/generate', async ({ params, json, mastra }) =>
|
|
|
116
116
|
try {
|
|
117
117
|
const agentId = decodeURIComponent(params.agentId);
|
|
118
118
|
const agent = mastra.getAgent(agentId);
|
|
119
|
-
const { messages, threadId, resourceid } = await json();
|
|
119
|
+
const { messages, threadId, resourceid, output } = await json();
|
|
120
120
|
const { ok, errorResponse } = await validateBody({ messages });
|
|
121
121
|
if (!ok) {
|
|
122
122
|
return new Response(JSON.stringify({ error: errorResponse }), {
|
|
@@ -134,8 +134,10 @@ router.post('/api/agents/:agentId/generate', async ({ params, json, mastra }) =>
|
|
|
134
134
|
},
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
const result = await agent.generate(messages, { threadId, resourceid });
|
|
138
|
-
return new Response(
|
|
137
|
+
const result = await agent.generate(messages, { output, threadId, resourceid });
|
|
138
|
+
return new Response(output
|
|
139
|
+
? JSON.stringify({ object: result.object, agent: result.agent })
|
|
140
|
+
: JSON.stringify({ text: result.text, agent: agent.name }), {
|
|
139
141
|
headers: {
|
|
140
142
|
'Content-Type': 'application/json',
|
|
141
143
|
},
|
|
@@ -143,8 +145,8 @@ router.post('/api/agents/:agentId/generate', async ({ params, json, mastra }) =>
|
|
|
143
145
|
}
|
|
144
146
|
catch (error) {
|
|
145
147
|
const apiError = error;
|
|
146
|
-
console.error('Error
|
|
147
|
-
return new Response(JSON.stringify({ error: apiError.message || 'Error
|
|
148
|
+
console.error('Error generating from agent', apiError);
|
|
149
|
+
return new Response(JSON.stringify({ error: apiError.message || 'Error generating from agent' }), {
|
|
148
150
|
status: apiError.status || 500,
|
|
149
151
|
headers: {
|
|
150
152
|
'Content-Type': 'application/json',
|
|
@@ -156,52 +158,9 @@ router.post('/api/agents/:agentId/stream', async ({ params, json, mastra }) => {
|
|
|
156
158
|
try {
|
|
157
159
|
const agentId = decodeURIComponent(params.agentId);
|
|
158
160
|
const agent = mastra.getAgent(agentId);
|
|
159
|
-
const { messages, threadId, resourceid } = await json();
|
|
160
|
-
const { ok, errorResponse } = await validateBody({ messages });
|
|
161
|
-
if (!ok) {
|
|
162
|
-
return new Response(JSON.stringify({ error: errorResponse }), {
|
|
163
|
-
status: 400,
|
|
164
|
-
headers: {
|
|
165
|
-
'Content-Type': 'application/json',
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
if (!Array.isArray(messages)) {
|
|
170
|
-
return new Response(JSON.stringify({ error: { messages: 'Messages should be an array' } }), {
|
|
171
|
-
status: 400,
|
|
172
|
-
headers: {
|
|
173
|
-
'Content-Type': 'application/json',
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
const streamResult = await agent.stream(messages, { threadId, resourceid });
|
|
178
|
-
return streamResult.toDataStreamResponse({
|
|
179
|
-
headers: {
|
|
180
|
-
'Content-Type': 'text/x-unknown',
|
|
181
|
-
'content-encoding': 'identity',
|
|
182
|
-
'transfer-encoding': 'chunked',
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
const apiError = error;
|
|
188
|
-
console.error('Error streaming from agent', apiError);
|
|
189
|
-
return new Response(JSON.stringify({ error: apiError.message || 'Error streaming from agent' }), {
|
|
190
|
-
status: apiError.status || 500,
|
|
191
|
-
headers: {
|
|
192
|
-
'Content-Type': 'application/json',
|
|
193
|
-
},
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
router.post('/api/agents/:agentId/text-object', async ({ params, json, mastra }) => {
|
|
198
|
-
try {
|
|
199
|
-
const agentId = decodeURIComponent(params.agentId);
|
|
200
|
-
const agent = mastra.getAgent(agentId);
|
|
201
|
-
const { messages, schema, threadId, resourceid } = await json();
|
|
161
|
+
const { messages, threadId, resourceid, output } = await json();
|
|
202
162
|
const { ok, errorResponse } = await validateBody({
|
|
203
163
|
messages,
|
|
204
|
-
schema,
|
|
205
164
|
});
|
|
206
165
|
if (!ok) {
|
|
207
166
|
return new Response(JSON.stringify({ error: errorResponse }), {
|
|
@@ -219,50 +178,7 @@ router.post('/api/agents/:agentId/text-object', async ({ params, json, mastra })
|
|
|
219
178
|
},
|
|
220
179
|
});
|
|
221
180
|
}
|
|
222
|
-
const
|
|
223
|
-
return new Response(JSON.stringify(result), {
|
|
224
|
-
headers: {
|
|
225
|
-
'Content-Type': 'application/json',
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
const apiError = error;
|
|
231
|
-
console.error('Error getting structured output from agent', apiError);
|
|
232
|
-
return new Response(JSON.stringify({ error: apiError.message || 'Error getting structured output from agent' }), {
|
|
233
|
-
status: apiError.status || 500,
|
|
234
|
-
headers: {
|
|
235
|
-
'Content-Type': 'application/json',
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
router.post('/api/agents/:agentId/stream-object', async ({ params, json, mastra }) => {
|
|
241
|
-
try {
|
|
242
|
-
const agentId = decodeURIComponent(params.agentId);
|
|
243
|
-
const agent = mastra.getAgent(agentId);
|
|
244
|
-
const { messages, schema, threadId, resourceid } = await json();
|
|
245
|
-
const { ok, errorResponse } = await validateBody({
|
|
246
|
-
messages,
|
|
247
|
-
schema,
|
|
248
|
-
});
|
|
249
|
-
if (!ok) {
|
|
250
|
-
return new Response(JSON.stringify({ error: errorResponse }), {
|
|
251
|
-
status: 400,
|
|
252
|
-
headers: {
|
|
253
|
-
'Content-Type': 'application/json',
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (!Array.isArray(messages)) {
|
|
258
|
-
return new Response(JSON.stringify({ error: { messages: 'Messages should be an array' } }), {
|
|
259
|
-
status: 400,
|
|
260
|
-
headers: {
|
|
261
|
-
'Content-Type': 'application/json',
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
const streamResult = await agent.stream(messages, { output: schema, threadId, resourceid });
|
|
181
|
+
const streamResult = await agent.stream(messages, { threadId, resourceid, output });
|
|
266
182
|
return streamResult.toTextStreamResponse({
|
|
267
183
|
headers: {
|
|
268
184
|
'Content-Type': 'text/x-unknown',
|
|
@@ -273,8 +189,8 @@ router.post('/api/agents/:agentId/stream-object', async ({ params, json, mastra
|
|
|
273
189
|
}
|
|
274
190
|
catch (error) {
|
|
275
191
|
const apiError = error;
|
|
276
|
-
console.error('Error streaming
|
|
277
|
-
return new Response(JSON.stringify({ error: apiError.message || 'Error streaming
|
|
192
|
+
console.error('Error streaming from agent', apiError);
|
|
193
|
+
return new Response(JSON.stringify({ error: apiError.message || 'Error streaming from agent' }), {
|
|
278
194
|
status: apiError.status || 500,
|
|
279
195
|
headers: {
|
|
280
196
|
'Content-Type': 'application/json',
|