@mastra/client-js 1.11.2 → 1.12.0-alpha.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/CHANGELOG.md +94 -0
- package/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +3 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-server-mastra-client.md +12 -10
- package/dist/docs/references/reference-client-js-conversations.md +135 -0
- package/dist/docs/references/reference-client-js-mastra-client.md +4 -0
- package/dist/docs/references/reference-client-js-responses.md +213 -0
- package/dist/index.cjs +183 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +183 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/conversations.d.ts +15 -0
- package/dist/resources/conversations.d.ts.map +1 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/responses.d.ts +22 -0
- package/dist/resources/responses.d.ts.map +1 -0
- package/dist/types.d.ts +216 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -324,7 +324,11 @@ async function executeToolCallAndRespond({
|
|
|
324
324
|
}
|
|
325
325
|
];
|
|
326
326
|
const updatedMessages = threadId ? newMessages : [...Array.isArray(params.messages) ? params.messages : [], ...newMessages];
|
|
327
|
-
|
|
327
|
+
const respondOptions = {
|
|
328
|
+
...params
|
|
329
|
+
};
|
|
330
|
+
delete respondOptions.messages;
|
|
331
|
+
return respondFn(updatedMessages, respondOptions);
|
|
328
332
|
}
|
|
329
333
|
}
|
|
330
334
|
}
|
|
@@ -1955,6 +1959,45 @@ var Processor = class extends BaseResource {
|
|
|
1955
1959
|
});
|
|
1956
1960
|
}
|
|
1957
1961
|
};
|
|
1962
|
+
|
|
1963
|
+
// src/resources/conversations.ts
|
|
1964
|
+
var ConversationItems = class extends BaseResource {
|
|
1965
|
+
constructor(options) {
|
|
1966
|
+
super(options);
|
|
1967
|
+
}
|
|
1968
|
+
list(conversationId, requestContext) {
|
|
1969
|
+
return this.request(
|
|
1970
|
+
`/v1/conversations/${encodeURIComponent(conversationId)}/items${requestContextQueryString(requestContext)}`
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
var Conversations = class extends BaseResource {
|
|
1975
|
+
items;
|
|
1976
|
+
constructor(options) {
|
|
1977
|
+
super(options);
|
|
1978
|
+
this.items = new ConversationItems(options);
|
|
1979
|
+
}
|
|
1980
|
+
create(params) {
|
|
1981
|
+
const { requestContext, ...body } = params;
|
|
1982
|
+
return this.request(`/v1/conversations${requestContextQueryString(requestContext)}`, {
|
|
1983
|
+
method: "POST",
|
|
1984
|
+
body
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
retrieve(conversationId, requestContext) {
|
|
1988
|
+
return this.request(
|
|
1989
|
+
`/v1/conversations/${encodeURIComponent(conversationId)}${requestContextQueryString(requestContext)}`
|
|
1990
|
+
);
|
|
1991
|
+
}
|
|
1992
|
+
delete(conversationId, requestContext) {
|
|
1993
|
+
return this.request(
|
|
1994
|
+
`/v1/conversations/${encodeURIComponent(conversationId)}${requestContextQueryString(requestContext)}`,
|
|
1995
|
+
{
|
|
1996
|
+
method: "DELETE"
|
|
1997
|
+
}
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
1958
2001
|
function deserializeWorkflowError(result) {
|
|
1959
2002
|
if (result.status === "failed" && result.error) {
|
|
1960
2003
|
result.error = error.getErrorFromUnknown(result.error, {
|
|
@@ -4111,12 +4154,151 @@ var StoredSkill = class extends BaseResource {
|
|
|
4111
4154
|
}
|
|
4112
4155
|
};
|
|
4113
4156
|
|
|
4157
|
+
// src/resources/responses.ts
|
|
4158
|
+
function getOutputText(output) {
|
|
4159
|
+
return output.flatMap((item) => item.type === "message" ? item.content : []).map((part) => typeof part?.text === "string" ? part.text : "").filter(Boolean).join("");
|
|
4160
|
+
}
|
|
4161
|
+
function attachOutputText(response) {
|
|
4162
|
+
return {
|
|
4163
|
+
...response,
|
|
4164
|
+
output_text: getOutputText(response.output)
|
|
4165
|
+
};
|
|
4166
|
+
}
|
|
4167
|
+
function hydrateOutputItem(item) {
|
|
4168
|
+
if (item.type !== "message") {
|
|
4169
|
+
return item;
|
|
4170
|
+
}
|
|
4171
|
+
return {
|
|
4172
|
+
...item,
|
|
4173
|
+
content: item.content ?? []
|
|
4174
|
+
};
|
|
4175
|
+
}
|
|
4176
|
+
function hydrateStreamEvent(event) {
|
|
4177
|
+
if (typeof event === "object" && event !== null && "response" in event && (event.type === "response.created" || event.type === "response.in_progress" || event.type === "response.completed")) {
|
|
4178
|
+
return {
|
|
4179
|
+
...event,
|
|
4180
|
+
response: attachOutputText(event.response)
|
|
4181
|
+
};
|
|
4182
|
+
}
|
|
4183
|
+
if (typeof event === "object" && event !== null && "output" in event) {
|
|
4184
|
+
return attachOutputText(event);
|
|
4185
|
+
}
|
|
4186
|
+
if (typeof event === "object" && event !== null && "item" in event && (event.type === "response.output_item.added" || event.type === "response.output_item.done")) {
|
|
4187
|
+
return {
|
|
4188
|
+
...event,
|
|
4189
|
+
item: hydrateOutputItem(event.item)
|
|
4190
|
+
};
|
|
4191
|
+
}
|
|
4192
|
+
return event;
|
|
4193
|
+
}
|
|
4194
|
+
function parseSseBlock(block) {
|
|
4195
|
+
const normalizedBlock = block.replace(/\r\n/g, "\n").trim();
|
|
4196
|
+
if (!normalizedBlock) {
|
|
4197
|
+
return null;
|
|
4198
|
+
}
|
|
4199
|
+
const dataLines = normalizedBlock.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice("data:".length).trim());
|
|
4200
|
+
if (!dataLines.length) {
|
|
4201
|
+
return null;
|
|
4202
|
+
}
|
|
4203
|
+
const data = dataLines.join("\n");
|
|
4204
|
+
if (data === "[DONE]") {
|
|
4205
|
+
return null;
|
|
4206
|
+
}
|
|
4207
|
+
return hydrateStreamEvent(JSON.parse(data));
|
|
4208
|
+
}
|
|
4209
|
+
var ResponsesStream = class {
|
|
4210
|
+
constructor(response) {
|
|
4211
|
+
this.response = response;
|
|
4212
|
+
}
|
|
4213
|
+
asResponse() {
|
|
4214
|
+
return this.response;
|
|
4215
|
+
}
|
|
4216
|
+
async *[Symbol.asyncIterator]() {
|
|
4217
|
+
if (!this.response.body) {
|
|
4218
|
+
return;
|
|
4219
|
+
}
|
|
4220
|
+
const reader = this.response.body.getReader();
|
|
4221
|
+
const decoder = new TextDecoder();
|
|
4222
|
+
let buffer = "";
|
|
4223
|
+
let completed = false;
|
|
4224
|
+
try {
|
|
4225
|
+
while (true) {
|
|
4226
|
+
const { done, value } = await reader.read();
|
|
4227
|
+
buffer += decoder.decode(value ?? new Uint8Array(), { stream: !done });
|
|
4228
|
+
let boundaryIndex = buffer.indexOf("\n\n");
|
|
4229
|
+
while (boundaryIndex !== -1) {
|
|
4230
|
+
const block = buffer.slice(0, boundaryIndex);
|
|
4231
|
+
buffer = buffer.slice(boundaryIndex + 2);
|
|
4232
|
+
const parsed = parseSseBlock(block);
|
|
4233
|
+
if (parsed) {
|
|
4234
|
+
yield parsed;
|
|
4235
|
+
}
|
|
4236
|
+
boundaryIndex = buffer.indexOf("\n\n");
|
|
4237
|
+
}
|
|
4238
|
+
if (done) {
|
|
4239
|
+
break;
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
const finalEvent = parseSseBlock(buffer);
|
|
4243
|
+
completed = true;
|
|
4244
|
+
if (finalEvent) {
|
|
4245
|
+
yield finalEvent;
|
|
4246
|
+
}
|
|
4247
|
+
} finally {
|
|
4248
|
+
if (!completed) {
|
|
4249
|
+
await reader.cancel();
|
|
4250
|
+
}
|
|
4251
|
+
reader.releaseLock();
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
};
|
|
4255
|
+
var Responses = class extends BaseResource {
|
|
4256
|
+
constructor(options) {
|
|
4257
|
+
super(options);
|
|
4258
|
+
}
|
|
4259
|
+
async create(params) {
|
|
4260
|
+
const { requestContext, ...body } = params;
|
|
4261
|
+
const path = `/v1/responses${requestContextQueryString(requestContext)}`;
|
|
4262
|
+
if (params.stream) {
|
|
4263
|
+
const response2 = await this.request(path, {
|
|
4264
|
+
method: "POST",
|
|
4265
|
+
body,
|
|
4266
|
+
stream: true
|
|
4267
|
+
});
|
|
4268
|
+
return new ResponsesStream(response2);
|
|
4269
|
+
}
|
|
4270
|
+
const response = await this.request(path, {
|
|
4271
|
+
method: "POST",
|
|
4272
|
+
body
|
|
4273
|
+
});
|
|
4274
|
+
return attachOutputText(response);
|
|
4275
|
+
}
|
|
4276
|
+
stream(params) {
|
|
4277
|
+
return this.create({ ...params, stream: true });
|
|
4278
|
+
}
|
|
4279
|
+
async retrieve(responseId, requestContext) {
|
|
4280
|
+
const response = await this.request(
|
|
4281
|
+
`/v1/responses/${encodeURIComponent(responseId)}${requestContextQueryString(requestContext)}`
|
|
4282
|
+
);
|
|
4283
|
+
return attachOutputText(response);
|
|
4284
|
+
}
|
|
4285
|
+
delete(responseId, requestContext) {
|
|
4286
|
+
return this.request(`/v1/responses/${encodeURIComponent(responseId)}${requestContextQueryString(requestContext)}`, {
|
|
4287
|
+
method: "DELETE"
|
|
4288
|
+
});
|
|
4289
|
+
}
|
|
4290
|
+
};
|
|
4291
|
+
|
|
4114
4292
|
// src/client.ts
|
|
4115
4293
|
var MastraClient = class extends BaseResource {
|
|
4116
4294
|
observability;
|
|
4295
|
+
conversations;
|
|
4296
|
+
responses;
|
|
4117
4297
|
constructor(options) {
|
|
4118
4298
|
super(options);
|
|
4119
4299
|
this.observability = new Observability(options);
|
|
4300
|
+
this.conversations = new Conversations(options);
|
|
4301
|
+
this.responses = new Responses(options);
|
|
4120
4302
|
}
|
|
4121
4303
|
/**
|
|
4122
4304
|
* Retrieves all available agents
|