@mastra/client-js 0.13.2 → 0.14.0-alpha.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.
- package/CHANGELOG.md +11 -0
- package/dist/client.d.ts +2 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +12 -214
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -214
- package/dist/index.js.map +1 -1
- package/dist/resources/index.d.ts +0 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/types.d.ts +1 -21
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/resources/legacy-workflow.d.ts +0 -90
- package/dist/resources/legacy-workflow.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1511,193 +1511,6 @@ var Vector = class extends BaseResource {
|
|
|
1511
1511
|
}
|
|
1512
1512
|
};
|
|
1513
1513
|
|
|
1514
|
-
// src/resources/legacy-workflow.ts
|
|
1515
|
-
var RECORD_SEPARATOR = "";
|
|
1516
|
-
var LegacyWorkflow = class extends BaseResource {
|
|
1517
|
-
constructor(options, workflowId) {
|
|
1518
|
-
super(options);
|
|
1519
|
-
this.workflowId = workflowId;
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Retrieves details about the legacy workflow
|
|
1523
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1524
|
-
* @returns Promise containing legacy workflow details including steps and graphs
|
|
1525
|
-
*/
|
|
1526
|
-
details(runtimeContext) {
|
|
1527
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}${runtimeContextQueryString(runtimeContext)}`);
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* Retrieves all runs for a legacy workflow
|
|
1531
|
-
* @param params - Parameters for filtering runs
|
|
1532
|
-
* @param runtimeContext - Optional runtime context to pass as query parameter
|
|
1533
|
-
* @returns Promise containing legacy workflow runs array
|
|
1534
|
-
*/
|
|
1535
|
-
runs(params, runtimeContext) {
|
|
1536
|
-
const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
|
|
1537
|
-
const searchParams = new URLSearchParams();
|
|
1538
|
-
if (params?.fromDate) {
|
|
1539
|
-
searchParams.set("fromDate", params.fromDate.toISOString());
|
|
1540
|
-
}
|
|
1541
|
-
if (params?.toDate) {
|
|
1542
|
-
searchParams.set("toDate", params.toDate.toISOString());
|
|
1543
|
-
}
|
|
1544
|
-
if (params?.limit) {
|
|
1545
|
-
searchParams.set("limit", String(params.limit));
|
|
1546
|
-
}
|
|
1547
|
-
if (params?.offset) {
|
|
1548
|
-
searchParams.set("offset", String(params.offset));
|
|
1549
|
-
}
|
|
1550
|
-
if (params?.resourceId) {
|
|
1551
|
-
searchParams.set("resourceId", params.resourceId);
|
|
1552
|
-
}
|
|
1553
|
-
if (runtimeContextParam) {
|
|
1554
|
-
searchParams.set("runtimeContext", runtimeContextParam);
|
|
1555
|
-
}
|
|
1556
|
-
if (searchParams.size) {
|
|
1557
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs?${searchParams}`);
|
|
1558
|
-
} else {
|
|
1559
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/runs`);
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Creates a new legacy workflow run
|
|
1564
|
-
* @returns Promise containing the generated run ID
|
|
1565
|
-
*/
|
|
1566
|
-
createRun(params) {
|
|
1567
|
-
const searchParams = new URLSearchParams();
|
|
1568
|
-
if (!!params?.runId) {
|
|
1569
|
-
searchParams.set("runId", params.runId);
|
|
1570
|
-
}
|
|
1571
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/create-run?${searchParams.toString()}`, {
|
|
1572
|
-
method: "POST"
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Starts a legacy workflow run synchronously without waiting for the workflow to complete
|
|
1577
|
-
* @param params - Object containing the runId and triggerData
|
|
1578
|
-
* @returns Promise containing success message
|
|
1579
|
-
*/
|
|
1580
|
-
start(params) {
|
|
1581
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1582
|
-
method: "POST",
|
|
1583
|
-
body: params?.triggerData
|
|
1584
|
-
});
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
|
|
1588
|
-
* @param stepId - ID of the step to resume
|
|
1589
|
-
* @param runId - ID of the legacy workflow run
|
|
1590
|
-
* @param context - Context to resume the legacy workflow with
|
|
1591
|
-
* @returns Promise containing the legacy workflow resume results
|
|
1592
|
-
*/
|
|
1593
|
-
resume({
|
|
1594
|
-
stepId,
|
|
1595
|
-
runId,
|
|
1596
|
-
context
|
|
1597
|
-
}) {
|
|
1598
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume?runId=${runId}`, {
|
|
1599
|
-
method: "POST",
|
|
1600
|
-
body: {
|
|
1601
|
-
stepId,
|
|
1602
|
-
context
|
|
1603
|
-
}
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1608
|
-
* @param params - Object containing the optional runId and triggerData
|
|
1609
|
-
* @returns Promise containing the workflow execution results
|
|
1610
|
-
*/
|
|
1611
|
-
startAsync(params) {
|
|
1612
|
-
const searchParams = new URLSearchParams();
|
|
1613
|
-
if (!!params?.runId) {
|
|
1614
|
-
searchParams.set("runId", params.runId);
|
|
1615
|
-
}
|
|
1616
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1617
|
-
method: "POST",
|
|
1618
|
-
body: params?.triggerData
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
/**
|
|
1622
|
-
* Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
|
|
1623
|
-
* @param params - Object containing the runId, stepId, and context
|
|
1624
|
-
* @returns Promise containing the workflow resume results
|
|
1625
|
-
*/
|
|
1626
|
-
resumeAsync(params) {
|
|
1627
|
-
return this.request(`/api/workflows/legacy/${this.workflowId}/resume-async?runId=${params.runId}`, {
|
|
1628
|
-
method: "POST",
|
|
1629
|
-
body: {
|
|
1630
|
-
stepId: params.stepId,
|
|
1631
|
-
context: params.context
|
|
1632
|
-
}
|
|
1633
|
-
});
|
|
1634
|
-
}
|
|
1635
|
-
/**
|
|
1636
|
-
* Creates an async generator that processes a readable stream and yields records
|
|
1637
|
-
* separated by the Record Separator character (\x1E)
|
|
1638
|
-
*
|
|
1639
|
-
* @param stream - The readable stream to process
|
|
1640
|
-
* @returns An async generator that yields parsed records
|
|
1641
|
-
*/
|
|
1642
|
-
async *streamProcessor(stream) {
|
|
1643
|
-
const reader = stream.getReader();
|
|
1644
|
-
let doneReading = false;
|
|
1645
|
-
let buffer = "";
|
|
1646
|
-
try {
|
|
1647
|
-
while (!doneReading) {
|
|
1648
|
-
const { done, value } = await reader.read();
|
|
1649
|
-
doneReading = done;
|
|
1650
|
-
if (done && !value) continue;
|
|
1651
|
-
try {
|
|
1652
|
-
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1653
|
-
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1654
|
-
buffer = chunks.pop() || "";
|
|
1655
|
-
for (const chunk of chunks) {
|
|
1656
|
-
if (chunk) {
|
|
1657
|
-
if (typeof chunk === "string") {
|
|
1658
|
-
try {
|
|
1659
|
-
const parsedChunk = JSON.parse(chunk);
|
|
1660
|
-
yield parsedChunk;
|
|
1661
|
-
} catch {
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
} catch {
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
if (buffer) {
|
|
1670
|
-
try {
|
|
1671
|
-
yield JSON.parse(buffer);
|
|
1672
|
-
} catch {
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
} finally {
|
|
1676
|
-
reader.cancel().catch(() => {
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Watches legacy workflow transitions in real-time
|
|
1682
|
-
* @param runId - Optional run ID to filter the watch stream
|
|
1683
|
-
* @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
|
|
1684
|
-
*/
|
|
1685
|
-
async watch({ runId }, onRecord) {
|
|
1686
|
-
const response = await this.request(`/api/workflows/legacy/${this.workflowId}/watch?runId=${runId}`, {
|
|
1687
|
-
stream: true
|
|
1688
|
-
});
|
|
1689
|
-
if (!response.ok) {
|
|
1690
|
-
throw new Error(`Failed to watch legacy workflow: ${response.statusText}`);
|
|
1691
|
-
}
|
|
1692
|
-
if (!response.body) {
|
|
1693
|
-
throw new Error("Response body is null");
|
|
1694
|
-
}
|
|
1695
|
-
for await (const record of this.streamProcessor(response.body)) {
|
|
1696
|
-
onRecord(record);
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
|
|
1701
1514
|
// src/resources/tool.ts
|
|
1702
1515
|
var Tool = class extends BaseResource {
|
|
1703
1516
|
constructor(options, toolId) {
|
|
@@ -1734,7 +1547,7 @@ var Tool = class extends BaseResource {
|
|
|
1734
1547
|
};
|
|
1735
1548
|
|
|
1736
1549
|
// src/resources/workflow.ts
|
|
1737
|
-
var
|
|
1550
|
+
var RECORD_SEPARATOR = "";
|
|
1738
1551
|
var Workflow = class extends BaseResource {
|
|
1739
1552
|
constructor(options, workflowId) {
|
|
1740
1553
|
super(options);
|
|
@@ -1758,7 +1571,7 @@ var Workflow = class extends BaseResource {
|
|
|
1758
1571
|
if (done && !value) continue;
|
|
1759
1572
|
try {
|
|
1760
1573
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
1761
|
-
const chunks = (buffer + decoded).split(
|
|
1574
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR);
|
|
1762
1575
|
buffer = chunks.pop() || "";
|
|
1763
1576
|
for (const chunk of chunks) {
|
|
1764
1577
|
if (chunk) {
|
|
@@ -2004,7 +1817,7 @@ var Workflow = class extends BaseResource {
|
|
|
2004
1817
|
async transform(chunk, controller) {
|
|
2005
1818
|
try {
|
|
2006
1819
|
const decoded = new TextDecoder().decode(chunk);
|
|
2007
|
-
const chunks = decoded.split(
|
|
1820
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2008
1821
|
for (const chunk2 of chunks) {
|
|
2009
1822
|
if (chunk2) {
|
|
2010
1823
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2051,7 +1864,7 @@ var Workflow = class extends BaseResource {
|
|
|
2051
1864
|
async transform(chunk, controller) {
|
|
2052
1865
|
try {
|
|
2053
1866
|
const decoded = new TextDecoder().decode(chunk);
|
|
2054
|
-
const chunks = decoded.split(
|
|
1867
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2055
1868
|
for (const chunk2 of chunks) {
|
|
2056
1869
|
if (chunk2) {
|
|
2057
1870
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2102,7 +1915,7 @@ var Workflow = class extends BaseResource {
|
|
|
2102
1915
|
async transform(chunk, controller) {
|
|
2103
1916
|
try {
|
|
2104
1917
|
const decoded = new TextDecoder().decode(chunk);
|
|
2105
|
-
const chunks = decoded.split(
|
|
1918
|
+
const chunks = decoded.split(RECORD_SEPARATOR);
|
|
2106
1919
|
for (const chunk2 of chunks) {
|
|
2107
1920
|
if (chunk2) {
|
|
2108
1921
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2189,7 +2002,7 @@ var Workflow = class extends BaseResource {
|
|
|
2189
2002
|
async start(controller) {
|
|
2190
2003
|
try {
|
|
2191
2004
|
for await (const record of records) {
|
|
2192
|
-
const json = JSON.stringify(record) +
|
|
2005
|
+
const json = JSON.stringify(record) + RECORD_SEPARATOR;
|
|
2193
2006
|
controller.enqueue(encoder.encode(json));
|
|
2194
2007
|
}
|
|
2195
2008
|
controller.close();
|
|
@@ -2312,7 +2125,7 @@ var MCPTool = class extends BaseResource {
|
|
|
2312
2125
|
};
|
|
2313
2126
|
|
|
2314
2127
|
// src/resources/agent-builder.ts
|
|
2315
|
-
var
|
|
2128
|
+
var RECORD_SEPARATOR2 = "";
|
|
2316
2129
|
var AgentBuilder = class extends BaseResource {
|
|
2317
2130
|
constructor(options, actionId) {
|
|
2318
2131
|
super(options);
|
|
@@ -2452,7 +2265,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2452
2265
|
if (done && !value) continue;
|
|
2453
2266
|
try {
|
|
2454
2267
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2455
|
-
const chunks = (buffer + decoded).split(
|
|
2268
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
|
|
2456
2269
|
buffer = chunks.pop() || "";
|
|
2457
2270
|
for (const chunk of chunks) {
|
|
2458
2271
|
if (chunk) {
|
|
@@ -2509,7 +2322,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2509
2322
|
async transform(chunk, controller) {
|
|
2510
2323
|
try {
|
|
2511
2324
|
const decoded = new TextDecoder().decode(chunk);
|
|
2512
|
-
const chunks = decoded.split(
|
|
2325
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2513
2326
|
for (const chunk2 of chunks) {
|
|
2514
2327
|
if (chunk2) {
|
|
2515
2328
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2558,7 +2371,7 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2558
2371
|
async transform(chunk, controller) {
|
|
2559
2372
|
try {
|
|
2560
2373
|
const decoded = new TextDecoder().decode(chunk);
|
|
2561
|
-
const chunks = decoded.split(
|
|
2374
|
+
const chunks = decoded.split(RECORD_SEPARATOR2);
|
|
2562
2375
|
for (const chunk2 of chunks) {
|
|
2563
2376
|
if (chunk2) {
|
|
2564
2377
|
const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
|
|
@@ -2801,7 +2614,7 @@ var NetworkMemoryThread = class extends BaseResource {
|
|
|
2801
2614
|
};
|
|
2802
2615
|
|
|
2803
2616
|
// src/resources/vNextNetwork.ts
|
|
2804
|
-
var
|
|
2617
|
+
var RECORD_SEPARATOR3 = "";
|
|
2805
2618
|
var VNextNetwork = class extends BaseResource {
|
|
2806
2619
|
constructor(options, networkId) {
|
|
2807
2620
|
super(options);
|
|
@@ -2854,7 +2667,7 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2854
2667
|
if (done && !value) continue;
|
|
2855
2668
|
try {
|
|
2856
2669
|
const decoded = value ? new TextDecoder().decode(value) : "";
|
|
2857
|
-
const chunks = (buffer + decoded).split(
|
|
2670
|
+
const chunks = (buffer + decoded).split(RECORD_SEPARATOR3);
|
|
2858
2671
|
buffer = chunks.pop() || "";
|
|
2859
2672
|
for (const chunk of chunks) {
|
|
2860
2673
|
if (chunk) {
|
|
@@ -3100,21 +2913,6 @@ var MastraClient = class extends BaseResource {
|
|
|
3100
2913
|
getTool(toolId) {
|
|
3101
2914
|
return new Tool(this.options, toolId);
|
|
3102
2915
|
}
|
|
3103
|
-
/**
|
|
3104
|
-
* Retrieves all available legacy workflows
|
|
3105
|
-
* @returns Promise containing map of legacy workflow IDs to legacy workflow details
|
|
3106
|
-
*/
|
|
3107
|
-
getLegacyWorkflows() {
|
|
3108
|
-
return this.request("/api/workflows/legacy");
|
|
3109
|
-
}
|
|
3110
|
-
/**
|
|
3111
|
-
* Gets a legacy workflow instance by ID
|
|
3112
|
-
* @param workflowId - ID of the legacy workflow to retrieve
|
|
3113
|
-
* @returns Legacy Workflow instance
|
|
3114
|
-
*/
|
|
3115
|
-
getLegacyWorkflow(workflowId) {
|
|
3116
|
-
return new LegacyWorkflow(this.options, workflowId);
|
|
3117
|
-
}
|
|
3118
2916
|
/**
|
|
3119
2917
|
* Retrieves all available workflows
|
|
3120
2918
|
* @param runtimeContext - Optional runtime context to pass as query parameter
|