@iqai/adk 0.7.0 → 0.8.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 +8 -0
- package/dist/index.d.mts +745 -477
- package/dist/index.d.ts +745 -477
- package/dist/index.js +562 -10
- package/dist/index.mjs +550 -10
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9972,10 +9972,13 @@ __export(tools_exports, {
|
|
|
9972
9972
|
McpMemory: () => McpMemory,
|
|
9973
9973
|
McpNearAgent: () => McpNearAgent,
|
|
9974
9974
|
McpNearIntents: () => McpNearIntents,
|
|
9975
|
+
McpNotion: () => McpNotion,
|
|
9975
9976
|
McpOdos: () => McpOdos,
|
|
9976
9977
|
McpOpinion: () => McpOpinion,
|
|
9978
|
+
McpPlaywright: () => McpPlaywright,
|
|
9977
9979
|
McpPolymarket: () => McpPolymarket,
|
|
9978
9980
|
McpSamplingHandler: () => McpSamplingHandler,
|
|
9981
|
+
McpSequentialThinking: () => McpSequentialThinking,
|
|
9979
9982
|
McpTelegram: () => McpTelegram,
|
|
9980
9983
|
McpToolset: () => McpToolset,
|
|
9981
9984
|
McpUpbit: () => McpUpbit,
|
|
@@ -13426,11 +13429,16 @@ async function convertMcpToolToBaseTool(params) {
|
|
|
13426
13429
|
throw error;
|
|
13427
13430
|
}
|
|
13428
13431
|
}
|
|
13432
|
+
function sanitizeMcpToolName(name) {
|
|
13433
|
+
return name.replace(/-/g, "_");
|
|
13434
|
+
}
|
|
13429
13435
|
var McpToolAdapter = class extends BaseTool {
|
|
13430
13436
|
mcpTool;
|
|
13431
13437
|
client;
|
|
13432
13438
|
clientService = null;
|
|
13433
13439
|
toolHandler;
|
|
13440
|
+
/** The original MCP tool name, preserved for calls back to the MCP server. */
|
|
13441
|
+
originalMcpName;
|
|
13434
13442
|
logger = new Logger({ name: "McpToolAdapter" });
|
|
13435
13443
|
constructor(mcpTool, client, handler) {
|
|
13436
13444
|
let metadata = {};
|
|
@@ -13439,13 +13447,15 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
13439
13447
|
} else if (mcpTool._meta && typeof mcpTool._meta === "object") {
|
|
13440
13448
|
metadata = mcpTool._meta;
|
|
13441
13449
|
}
|
|
13450
|
+
const rawName = mcpTool.name || `mcp_${Date.now()}`;
|
|
13442
13451
|
super({
|
|
13443
|
-
name:
|
|
13452
|
+
name: sanitizeMcpToolName(rawName),
|
|
13444
13453
|
description: mcpTool.description || "MCP Tool",
|
|
13445
13454
|
isLongRunning: metadata.isLongRunning ?? false,
|
|
13446
13455
|
shouldRetryOnFailure: metadata.shouldRetryOnFailure ?? false,
|
|
13447
13456
|
maxRetryAttempts: metadata.maxRetryAttempts ?? 3
|
|
13448
13457
|
});
|
|
13458
|
+
this.originalMcpName = rawName;
|
|
13449
13459
|
this.mcpTool = mcpTool;
|
|
13450
13460
|
this.client = client;
|
|
13451
13461
|
this.toolHandler = handler;
|
|
@@ -13470,27 +13480,30 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
13470
13480
|
}
|
|
13471
13481
|
}
|
|
13472
13482
|
async runAsync(args, _context) {
|
|
13473
|
-
this.logger.debug(
|
|
13483
|
+
this.logger.debug(
|
|
13484
|
+
`Executing MCP tool ${this.originalMcpName} with args:`,
|
|
13485
|
+
args
|
|
13486
|
+
);
|
|
13474
13487
|
try {
|
|
13475
13488
|
if ("execute" in this.mcpTool && typeof this.mcpTool.execute === "function") {
|
|
13476
13489
|
return await this.mcpTool.execute(args);
|
|
13477
13490
|
}
|
|
13478
13491
|
if (this.clientService) {
|
|
13479
|
-
return await this.clientService.callTool(this.
|
|
13492
|
+
return await this.clientService.callTool(this.originalMcpName, args);
|
|
13480
13493
|
}
|
|
13481
13494
|
if (this.client && typeof this.client.callTool === "function") {
|
|
13482
13495
|
if (this.shouldRetryOnFailure) {
|
|
13483
13496
|
const executeWithRetry = withRetry(
|
|
13484
13497
|
async () => {
|
|
13485
13498
|
return await this.client.callTool({
|
|
13486
|
-
name: this.
|
|
13499
|
+
name: this.originalMcpName,
|
|
13487
13500
|
arguments: args
|
|
13488
13501
|
});
|
|
13489
13502
|
},
|
|
13490
13503
|
this,
|
|
13491
13504
|
async () => {
|
|
13492
13505
|
console.warn(
|
|
13493
|
-
`MCP tool ${this.
|
|
13506
|
+
`MCP tool ${this.originalMcpName} encountered a closed resource, but cannot reinitialize client.`
|
|
13494
13507
|
);
|
|
13495
13508
|
},
|
|
13496
13509
|
this.maxRetryAttempts
|
|
@@ -13498,23 +13511,26 @@ var McpToolAdapter = class extends BaseTool {
|
|
|
13498
13511
|
return await executeWithRetry();
|
|
13499
13512
|
}
|
|
13500
13513
|
const result = await this.client.callTool({
|
|
13501
|
-
name: this.
|
|
13514
|
+
name: this.originalMcpName,
|
|
13502
13515
|
arguments: args
|
|
13503
13516
|
});
|
|
13504
13517
|
return result;
|
|
13505
13518
|
}
|
|
13506
13519
|
if (this.toolHandler) {
|
|
13507
|
-
return await this.toolHandler(this.
|
|
13520
|
+
return await this.toolHandler(this.originalMcpName, args);
|
|
13508
13521
|
}
|
|
13509
13522
|
throw new McpError(
|
|
13510
|
-
`Cannot execute MCP tool ${this.
|
|
13523
|
+
`Cannot execute MCP tool ${this.originalMcpName}: No execution method found`,
|
|
13511
13524
|
"tool_execution_error" /* TOOL_EXECUTION_ERROR */
|
|
13512
13525
|
);
|
|
13513
13526
|
} catch (error) {
|
|
13514
13527
|
if (!(error instanceof McpError)) {
|
|
13515
|
-
console.error(
|
|
13528
|
+
console.error(
|
|
13529
|
+
`Error executing MCP tool ${this.originalMcpName}:`,
|
|
13530
|
+
error
|
|
13531
|
+
);
|
|
13516
13532
|
throw new McpError(
|
|
13517
|
-
`Error executing MCP tool ${this.
|
|
13533
|
+
`Error executing MCP tool ${this.originalMcpName}: ${error instanceof Error ? error.message : String(error)}`,
|
|
13518
13534
|
"tool_execution_error" /* TOOL_EXECUTION_ERROR */,
|
|
13519
13535
|
error instanceof Error ? error : void 0
|
|
13520
13536
|
);
|
|
@@ -13724,6 +13740,30 @@ function McpMemory(config = {}) {
|
|
|
13724
13740
|
);
|
|
13725
13741
|
return new McpToolset(mcpConfig);
|
|
13726
13742
|
}
|
|
13743
|
+
function McpNotion(config = {}) {
|
|
13744
|
+
const mcpConfig = createMcpConfig(
|
|
13745
|
+
"Notion MCP Client",
|
|
13746
|
+
"@notionhq/notion-mcp-server",
|
|
13747
|
+
config
|
|
13748
|
+
);
|
|
13749
|
+
return new McpToolset(mcpConfig);
|
|
13750
|
+
}
|
|
13751
|
+
function McpSequentialThinking(config = {}) {
|
|
13752
|
+
const mcpConfig = createMcpConfig(
|
|
13753
|
+
"Sequential Thinking MCP Client",
|
|
13754
|
+
"@modelcontextprotocol/server-sequential-thinking",
|
|
13755
|
+
config
|
|
13756
|
+
);
|
|
13757
|
+
return new McpToolset(mcpConfig);
|
|
13758
|
+
}
|
|
13759
|
+
function McpPlaywright(config = {}) {
|
|
13760
|
+
const mcpConfig = createMcpConfig(
|
|
13761
|
+
"Playwright MCP Client",
|
|
13762
|
+
"@playwright/mcp",
|
|
13763
|
+
config
|
|
13764
|
+
);
|
|
13765
|
+
return new McpToolset(mcpConfig);
|
|
13766
|
+
}
|
|
13727
13767
|
function McpGeneric(packageName, config = {}, name) {
|
|
13728
13768
|
const clientName = name || `${packageName} Client`;
|
|
13729
13769
|
const mcpConfig = createMcpConfig(clientName, packageName, config);
|
|
@@ -23380,6 +23420,494 @@ function streamTextWithFinalEvent(events) {
|
|
|
23380
23420
|
};
|
|
23381
23421
|
}
|
|
23382
23422
|
|
|
23423
|
+
// src/unified-memory/index.ts
|
|
23424
|
+
var unified_memory_exports = {};
|
|
23425
|
+
__export(unified_memory_exports, {
|
|
23426
|
+
MemoryBuilder: () => MemoryBuilder,
|
|
23427
|
+
defaultUnifiedMemoryConfig: () => defaultUnifiedMemoryConfig
|
|
23428
|
+
});
|
|
23429
|
+
|
|
23430
|
+
// src/unified-memory/types.ts
|
|
23431
|
+
var defaultUnifiedMemoryConfig = {
|
|
23432
|
+
lastMessages: 40
|
|
23433
|
+
};
|
|
23434
|
+
|
|
23435
|
+
// src/unified-memory/memory-builder.ts
|
|
23436
|
+
var WORKING_MEMORY_KEY = "__working_memory__";
|
|
23437
|
+
var MemoryBuilder = class _MemoryBuilder {
|
|
23438
|
+
sessionService;
|
|
23439
|
+
memoryService;
|
|
23440
|
+
appName;
|
|
23441
|
+
userId;
|
|
23442
|
+
lastMessages;
|
|
23443
|
+
workingMemoryEnabled;
|
|
23444
|
+
workingMemoryTemplate;
|
|
23445
|
+
constructor(config) {
|
|
23446
|
+
this.appName = config.appName;
|
|
23447
|
+
this.userId = config.userId;
|
|
23448
|
+
this.lastMessages = config.lastMessages ?? defaultUnifiedMemoryConfig.lastMessages;
|
|
23449
|
+
this.sessionService = new InMemorySessionService();
|
|
23450
|
+
this.workingMemoryEnabled = config.workingMemory?.enabled ?? false;
|
|
23451
|
+
this.workingMemoryTemplate = config.workingMemory?.template;
|
|
23452
|
+
}
|
|
23453
|
+
static create(config) {
|
|
23454
|
+
return new _MemoryBuilder(config);
|
|
23455
|
+
}
|
|
23456
|
+
withSessionService(service) {
|
|
23457
|
+
this.sessionService = service;
|
|
23458
|
+
return this;
|
|
23459
|
+
}
|
|
23460
|
+
withMemoryService(service) {
|
|
23461
|
+
this.memoryService = service;
|
|
23462
|
+
return this;
|
|
23463
|
+
}
|
|
23464
|
+
withAppName(appName) {
|
|
23465
|
+
this.appName = appName;
|
|
23466
|
+
return this;
|
|
23467
|
+
}
|
|
23468
|
+
withUserId(userId) {
|
|
23469
|
+
this.userId = userId;
|
|
23470
|
+
return this;
|
|
23471
|
+
}
|
|
23472
|
+
async createSession(state, sessionId) {
|
|
23473
|
+
const initialState = { ...state };
|
|
23474
|
+
if (this.workingMemoryEnabled && this.workingMemoryTemplate) {
|
|
23475
|
+
initialState[WORKING_MEMORY_KEY] = this.workingMemoryTemplate;
|
|
23476
|
+
}
|
|
23477
|
+
return this.sessionService.createSession(
|
|
23478
|
+
this.appName,
|
|
23479
|
+
this.userId,
|
|
23480
|
+
initialState,
|
|
23481
|
+
sessionId
|
|
23482
|
+
);
|
|
23483
|
+
}
|
|
23484
|
+
async getSession(sessionId) {
|
|
23485
|
+
return this.sessionService.getSession(this.appName, this.userId, sessionId);
|
|
23486
|
+
}
|
|
23487
|
+
async listSessions() {
|
|
23488
|
+
return this.sessionService.listSessions(this.appName, this.userId);
|
|
23489
|
+
}
|
|
23490
|
+
async deleteSession(sessionId) {
|
|
23491
|
+
return this.sessionService.deleteSession(
|
|
23492
|
+
this.appName,
|
|
23493
|
+
this.userId,
|
|
23494
|
+
sessionId
|
|
23495
|
+
);
|
|
23496
|
+
}
|
|
23497
|
+
async addMessage(session, message) {
|
|
23498
|
+
const author = message.role === "user" ? "user" : message.role === "assistant" ? "model" : "system";
|
|
23499
|
+
const event = new Event({
|
|
23500
|
+
author,
|
|
23501
|
+
content: {
|
|
23502
|
+
role: author,
|
|
23503
|
+
parts: [{ text: message.content }]
|
|
23504
|
+
}
|
|
23505
|
+
});
|
|
23506
|
+
const appended = await this.sessionService.appendEvent(session, event);
|
|
23507
|
+
if (this.memoryService) {
|
|
23508
|
+
await this.memoryService.addSessionToMemory(session);
|
|
23509
|
+
}
|
|
23510
|
+
return appended;
|
|
23511
|
+
}
|
|
23512
|
+
async addEvent(session, event) {
|
|
23513
|
+
const appended = await this.sessionService.appendEvent(session, event);
|
|
23514
|
+
if (this.memoryService) {
|
|
23515
|
+
await this.memoryService.addSessionToMemory(session);
|
|
23516
|
+
}
|
|
23517
|
+
return appended;
|
|
23518
|
+
}
|
|
23519
|
+
async recall(sessionId) {
|
|
23520
|
+
const session = await this.sessionService.getSession(
|
|
23521
|
+
this.appName,
|
|
23522
|
+
this.userId,
|
|
23523
|
+
sessionId,
|
|
23524
|
+
this.lastMessages === false ? void 0 : { numRecentEvents: this.lastMessages }
|
|
23525
|
+
);
|
|
23526
|
+
if (!session) {
|
|
23527
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
23528
|
+
}
|
|
23529
|
+
return session.events.map((event) => ({
|
|
23530
|
+
role: this.eventAuthorToRole(event.author),
|
|
23531
|
+
content: this.extractEventText(event)
|
|
23532
|
+
}));
|
|
23533
|
+
}
|
|
23534
|
+
async recallEvents(sessionId) {
|
|
23535
|
+
const session = await this.sessionService.getSession(
|
|
23536
|
+
this.appName,
|
|
23537
|
+
this.userId,
|
|
23538
|
+
sessionId,
|
|
23539
|
+
this.lastMessages === false ? void 0 : { numRecentEvents: this.lastMessages }
|
|
23540
|
+
);
|
|
23541
|
+
if (!session) {
|
|
23542
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
23543
|
+
}
|
|
23544
|
+
return session.events;
|
|
23545
|
+
}
|
|
23546
|
+
async search(query) {
|
|
23547
|
+
if (!this.memoryService) {
|
|
23548
|
+
throw new Error(
|
|
23549
|
+
"MemoryService is required for search. Use withMemoryService() to configure one."
|
|
23550
|
+
);
|
|
23551
|
+
}
|
|
23552
|
+
return this.memoryService.search({
|
|
23553
|
+
query,
|
|
23554
|
+
userId: this.userId,
|
|
23555
|
+
appName: this.appName
|
|
23556
|
+
});
|
|
23557
|
+
}
|
|
23558
|
+
async getWorkingMemory(sessionId) {
|
|
23559
|
+
const session = await this.sessionService.getSession(
|
|
23560
|
+
this.appName,
|
|
23561
|
+
this.userId,
|
|
23562
|
+
sessionId
|
|
23563
|
+
);
|
|
23564
|
+
if (!session) {
|
|
23565
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
23566
|
+
}
|
|
23567
|
+
const stored = session.state[WORKING_MEMORY_KEY];
|
|
23568
|
+
if (stored) return stored;
|
|
23569
|
+
if (this.workingMemoryEnabled && this.workingMemoryTemplate) {
|
|
23570
|
+
return this.workingMemoryTemplate;
|
|
23571
|
+
}
|
|
23572
|
+
return null;
|
|
23573
|
+
}
|
|
23574
|
+
async updateWorkingMemory(session, content) {
|
|
23575
|
+
const event = new Event({
|
|
23576
|
+
author: "system",
|
|
23577
|
+
actions: new EventActions({
|
|
23578
|
+
stateDelta: { [WORKING_MEMORY_KEY]: content }
|
|
23579
|
+
})
|
|
23580
|
+
});
|
|
23581
|
+
await this.sessionService.appendEvent(session, event);
|
|
23582
|
+
}
|
|
23583
|
+
async endSession(sessionId) {
|
|
23584
|
+
const session = await this.sessionService.endSession(
|
|
23585
|
+
this.appName,
|
|
23586
|
+
this.userId,
|
|
23587
|
+
sessionId
|
|
23588
|
+
);
|
|
23589
|
+
if (session && this.memoryService) {
|
|
23590
|
+
await this.memoryService.addSessionToMemory(session);
|
|
23591
|
+
}
|
|
23592
|
+
return session;
|
|
23593
|
+
}
|
|
23594
|
+
getSessionService() {
|
|
23595
|
+
return this.sessionService;
|
|
23596
|
+
}
|
|
23597
|
+
getMemoryService() {
|
|
23598
|
+
return this.memoryService;
|
|
23599
|
+
}
|
|
23600
|
+
eventAuthorToRole(author) {
|
|
23601
|
+
if (author === "user") return "user";
|
|
23602
|
+
if (author === "system") return "system";
|
|
23603
|
+
return "assistant";
|
|
23604
|
+
}
|
|
23605
|
+
extractEventText(event) {
|
|
23606
|
+
if (event.text) return event.text;
|
|
23607
|
+
if (event.content?.parts && Array.isArray(event.content.parts)) {
|
|
23608
|
+
const textParts = event.content.parts.filter(
|
|
23609
|
+
(part) => typeof part.text === "string" && part.text.length > 0
|
|
23610
|
+
).map((part) => part.text);
|
|
23611
|
+
if (textParts.length > 0) return textParts.join(" ");
|
|
23612
|
+
}
|
|
23613
|
+
return "";
|
|
23614
|
+
}
|
|
23615
|
+
};
|
|
23616
|
+
|
|
23617
|
+
// src/workflows/index.ts
|
|
23618
|
+
var workflows_exports = {};
|
|
23619
|
+
__export(workflows_exports, {
|
|
23620
|
+
InMemorySnapshotStore: () => InMemorySnapshotStore,
|
|
23621
|
+
Run: () => Run,
|
|
23622
|
+
Workflow: () => Workflow,
|
|
23623
|
+
createStep: () => createStep,
|
|
23624
|
+
createWorkflow: () => createWorkflow
|
|
23625
|
+
});
|
|
23626
|
+
|
|
23627
|
+
// src/workflows/step.ts
|
|
23628
|
+
function createStep(definition) {
|
|
23629
|
+
return {
|
|
23630
|
+
id: definition.id,
|
|
23631
|
+
description: definition.description,
|
|
23632
|
+
inputSchema: definition.inputSchema,
|
|
23633
|
+
outputSchema: definition.outputSchema,
|
|
23634
|
+
resumeSchema: definition.resumeSchema,
|
|
23635
|
+
suspendSchema: definition.suspendSchema,
|
|
23636
|
+
execute: definition.execute
|
|
23637
|
+
};
|
|
23638
|
+
}
|
|
23639
|
+
|
|
23640
|
+
// src/workflows/workflow.ts
|
|
23641
|
+
var SuspendError = class extends Error {
|
|
23642
|
+
constructor(suspendPayload) {
|
|
23643
|
+
super("Workflow suspended");
|
|
23644
|
+
this.suspendPayload = suspendPayload;
|
|
23645
|
+
this.name = "SuspendError";
|
|
23646
|
+
}
|
|
23647
|
+
};
|
|
23648
|
+
function generateRunId() {
|
|
23649
|
+
return `run_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
23650
|
+
}
|
|
23651
|
+
var Run = class _Run {
|
|
23652
|
+
constructor(workflow, runId) {
|
|
23653
|
+
this.workflow = workflow;
|
|
23654
|
+
this.runId = runId ?? generateRunId();
|
|
23655
|
+
this.createdAt = Date.now();
|
|
23656
|
+
this.updatedAt = this.createdAt;
|
|
23657
|
+
}
|
|
23658
|
+
runId;
|
|
23659
|
+
status = "pending";
|
|
23660
|
+
stepResults = {};
|
|
23661
|
+
suspendedStepId;
|
|
23662
|
+
suspendPayload;
|
|
23663
|
+
result;
|
|
23664
|
+
input;
|
|
23665
|
+
createdAt;
|
|
23666
|
+
updatedAt;
|
|
23667
|
+
async start(input) {
|
|
23668
|
+
if (this.status !== "pending") {
|
|
23669
|
+
throw new Error(`Cannot start run in status: ${this.status}`);
|
|
23670
|
+
}
|
|
23671
|
+
this.input = input;
|
|
23672
|
+
this.status = "running";
|
|
23673
|
+
return this.executeSteps(0);
|
|
23674
|
+
}
|
|
23675
|
+
async resume(options) {
|
|
23676
|
+
if (this.status !== "suspended") {
|
|
23677
|
+
throw new Error(`Cannot resume run in status: ${this.status}`);
|
|
23678
|
+
}
|
|
23679
|
+
const stepId = options.step ?? this.suspendedStepId;
|
|
23680
|
+
if (!stepId) {
|
|
23681
|
+
throw new Error("No suspended step to resume");
|
|
23682
|
+
}
|
|
23683
|
+
const stepIndex = this.workflow.stepGraph.findIndex((s) => s.id === stepId);
|
|
23684
|
+
if (stepIndex === -1) {
|
|
23685
|
+
throw new Error(`Step not found: ${stepId}`);
|
|
23686
|
+
}
|
|
23687
|
+
this.status = "running";
|
|
23688
|
+
return this.executeSteps(stepIndex, options.resumeData);
|
|
23689
|
+
}
|
|
23690
|
+
async executeSteps(startIndex, resumeData) {
|
|
23691
|
+
const steps = this.workflow.stepGraph;
|
|
23692
|
+
let isFirstResumedStep = resumeData !== void 0;
|
|
23693
|
+
for (let i = startIndex; i < steps.length; i++) {
|
|
23694
|
+
const step = steps[i];
|
|
23695
|
+
const startedAt = Date.now();
|
|
23696
|
+
const context4 = {
|
|
23697
|
+
runId: this.runId,
|
|
23698
|
+
workflowId: this.workflow.id,
|
|
23699
|
+
inputData: this.input,
|
|
23700
|
+
resumeData: isFirstResumedStep ? resumeData : void 0,
|
|
23701
|
+
suspend: (payload) => {
|
|
23702
|
+
throw new SuspendError(payload);
|
|
23703
|
+
},
|
|
23704
|
+
getStepResult: (stepId) => {
|
|
23705
|
+
const result = this.stepResults[stepId];
|
|
23706
|
+
if (result?.status === "success") {
|
|
23707
|
+
return result.output;
|
|
23708
|
+
}
|
|
23709
|
+
return void 0;
|
|
23710
|
+
}
|
|
23711
|
+
};
|
|
23712
|
+
try {
|
|
23713
|
+
const output = await step.execute(context4);
|
|
23714
|
+
const endedAt = Date.now();
|
|
23715
|
+
const previousResult = this.stepResults[step.id];
|
|
23716
|
+
if (previousResult?.status === "suspended") {
|
|
23717
|
+
this.stepResults[step.id] = {
|
|
23718
|
+
status: "success",
|
|
23719
|
+
output,
|
|
23720
|
+
payload: this.input,
|
|
23721
|
+
resumePayload: resumeData,
|
|
23722
|
+
startedAt: previousResult.startedAt,
|
|
23723
|
+
endedAt,
|
|
23724
|
+
suspendedAt: previousResult.suspendedAt,
|
|
23725
|
+
resumedAt: startedAt
|
|
23726
|
+
};
|
|
23727
|
+
} else {
|
|
23728
|
+
this.stepResults[step.id] = {
|
|
23729
|
+
status: "success",
|
|
23730
|
+
output,
|
|
23731
|
+
payload: this.input,
|
|
23732
|
+
startedAt,
|
|
23733
|
+
endedAt
|
|
23734
|
+
};
|
|
23735
|
+
}
|
|
23736
|
+
isFirstResumedStep = false;
|
|
23737
|
+
} catch (err) {
|
|
23738
|
+
if (err instanceof SuspendError) {
|
|
23739
|
+
this.status = "suspended";
|
|
23740
|
+
this.suspendedStepId = step.id;
|
|
23741
|
+
this.suspendPayload = err.suspendPayload;
|
|
23742
|
+
this.stepResults[step.id] = {
|
|
23743
|
+
status: "suspended",
|
|
23744
|
+
payload: this.input,
|
|
23745
|
+
suspendPayload: err.suspendPayload,
|
|
23746
|
+
startedAt,
|
|
23747
|
+
suspendedAt: Date.now()
|
|
23748
|
+
};
|
|
23749
|
+
await this.saveSnapshot();
|
|
23750
|
+
return {
|
|
23751
|
+
status: "suspended",
|
|
23752
|
+
steps: this.stepResults,
|
|
23753
|
+
suspendedStep: step.id,
|
|
23754
|
+
suspendPayload: err.suspendPayload
|
|
23755
|
+
};
|
|
23756
|
+
}
|
|
23757
|
+
this.status = "failed";
|
|
23758
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
23759
|
+
this.stepResults[step.id] = {
|
|
23760
|
+
status: "failed",
|
|
23761
|
+
error,
|
|
23762
|
+
payload: this.input,
|
|
23763
|
+
startedAt,
|
|
23764
|
+
endedAt: Date.now()
|
|
23765
|
+
};
|
|
23766
|
+
return {
|
|
23767
|
+
status: "failed",
|
|
23768
|
+
error,
|
|
23769
|
+
steps: this.stepResults
|
|
23770
|
+
};
|
|
23771
|
+
}
|
|
23772
|
+
}
|
|
23773
|
+
this.status = "success";
|
|
23774
|
+
const lastStep = steps[steps.length - 1];
|
|
23775
|
+
const lastResult = this.stepResults[lastStep.id];
|
|
23776
|
+
this.result = lastResult?.status === "success" ? lastResult.output : void 0;
|
|
23777
|
+
await this.workflow.snapshotStore?.delete(this.workflow.id, this.runId);
|
|
23778
|
+
return {
|
|
23779
|
+
status: "success",
|
|
23780
|
+
result: this.result,
|
|
23781
|
+
steps: this.stepResults
|
|
23782
|
+
};
|
|
23783
|
+
}
|
|
23784
|
+
async saveSnapshot() {
|
|
23785
|
+
if (!this.workflow.snapshotStore) return;
|
|
23786
|
+
const snapshot = {
|
|
23787
|
+
runId: this.runId,
|
|
23788
|
+
workflowId: this.workflow.id,
|
|
23789
|
+
status: this.status,
|
|
23790
|
+
input: this.input,
|
|
23791
|
+
stepResults: this.stepResults,
|
|
23792
|
+
suspendedStepId: this.suspendedStepId,
|
|
23793
|
+
suspendPayload: this.suspendPayload,
|
|
23794
|
+
createdAt: this.createdAt,
|
|
23795
|
+
updatedAt: Date.now()
|
|
23796
|
+
};
|
|
23797
|
+
await this.workflow.snapshotStore.save(snapshot);
|
|
23798
|
+
}
|
|
23799
|
+
getStatus() {
|
|
23800
|
+
return this.status;
|
|
23801
|
+
}
|
|
23802
|
+
getStepResults() {
|
|
23803
|
+
return this.stepResults;
|
|
23804
|
+
}
|
|
23805
|
+
getSuspendedStepId() {
|
|
23806
|
+
return this.suspendedStepId;
|
|
23807
|
+
}
|
|
23808
|
+
static async fromSnapshot(workflow, snapshot) {
|
|
23809
|
+
const run = new _Run(workflow, snapshot.runId);
|
|
23810
|
+
run.status = snapshot.status;
|
|
23811
|
+
run.input = snapshot.input;
|
|
23812
|
+
run.stepResults = snapshot.stepResults;
|
|
23813
|
+
run.suspendedStepId = snapshot.suspendedStepId;
|
|
23814
|
+
run.suspendPayload = snapshot.suspendPayload;
|
|
23815
|
+
run.createdAt = snapshot.createdAt;
|
|
23816
|
+
run.updatedAt = snapshot.updatedAt;
|
|
23817
|
+
return run;
|
|
23818
|
+
}
|
|
23819
|
+
};
|
|
23820
|
+
var Workflow = class {
|
|
23821
|
+
id;
|
|
23822
|
+
description;
|
|
23823
|
+
inputSchema;
|
|
23824
|
+
outputSchema;
|
|
23825
|
+
stepGraph = [];
|
|
23826
|
+
snapshotStore;
|
|
23827
|
+
committed = false;
|
|
23828
|
+
constructor(config) {
|
|
23829
|
+
this.id = config.id;
|
|
23830
|
+
this.description = config.description;
|
|
23831
|
+
this.inputSchema = config.inputSchema;
|
|
23832
|
+
this.outputSchema = config.outputSchema;
|
|
23833
|
+
}
|
|
23834
|
+
step(step) {
|
|
23835
|
+
if (this.committed) {
|
|
23836
|
+
throw new Error("Cannot add steps to a committed workflow");
|
|
23837
|
+
}
|
|
23838
|
+
this.stepGraph.push(step);
|
|
23839
|
+
return this;
|
|
23840
|
+
}
|
|
23841
|
+
withSnapshotStore(store) {
|
|
23842
|
+
this.snapshotStore = store;
|
|
23843
|
+
return this;
|
|
23844
|
+
}
|
|
23845
|
+
commit() {
|
|
23846
|
+
if (this.stepGraph.length === 0) {
|
|
23847
|
+
throw new Error("Workflow must have at least one step");
|
|
23848
|
+
}
|
|
23849
|
+
this.committed = true;
|
|
23850
|
+
return this;
|
|
23851
|
+
}
|
|
23852
|
+
createRun(runId) {
|
|
23853
|
+
if (!this.committed) {
|
|
23854
|
+
throw new Error("Workflow must be committed before creating a run");
|
|
23855
|
+
}
|
|
23856
|
+
return new Run(this, runId);
|
|
23857
|
+
}
|
|
23858
|
+
async resumeRun(runId) {
|
|
23859
|
+
if (!this.snapshotStore) {
|
|
23860
|
+
throw new Error("Cannot resume run without a snapshot store configured");
|
|
23861
|
+
}
|
|
23862
|
+
const snapshot = await this.snapshotStore.load(this.id, runId);
|
|
23863
|
+
if (!snapshot) {
|
|
23864
|
+
return null;
|
|
23865
|
+
}
|
|
23866
|
+
return Run.fromSnapshot(this, snapshot);
|
|
23867
|
+
}
|
|
23868
|
+
async listRuns() {
|
|
23869
|
+
if (!this.snapshotStore) {
|
|
23870
|
+
return [];
|
|
23871
|
+
}
|
|
23872
|
+
return this.snapshotStore.list(this.id);
|
|
23873
|
+
}
|
|
23874
|
+
};
|
|
23875
|
+
function createWorkflow(config) {
|
|
23876
|
+
return new Workflow(config);
|
|
23877
|
+
}
|
|
23878
|
+
|
|
23879
|
+
// src/workflows/snapshot-store.ts
|
|
23880
|
+
var InMemorySnapshotStore = class {
|
|
23881
|
+
snapshots = /* @__PURE__ */ new Map();
|
|
23882
|
+
getKey(workflowId, runId) {
|
|
23883
|
+
return `${workflowId}:${runId}`;
|
|
23884
|
+
}
|
|
23885
|
+
async save(snapshot) {
|
|
23886
|
+
const key = this.getKey(snapshot.workflowId, snapshot.runId);
|
|
23887
|
+
this.snapshots.set(key, { ...snapshot, updatedAt: Date.now() });
|
|
23888
|
+
}
|
|
23889
|
+
async load(workflowId, runId) {
|
|
23890
|
+
const key = this.getKey(workflowId, runId);
|
|
23891
|
+
return this.snapshots.get(key) ?? null;
|
|
23892
|
+
}
|
|
23893
|
+
async delete(workflowId, runId) {
|
|
23894
|
+
const key = this.getKey(workflowId, runId);
|
|
23895
|
+
this.snapshots.delete(key);
|
|
23896
|
+
}
|
|
23897
|
+
async list(workflowId) {
|
|
23898
|
+
const results = [];
|
|
23899
|
+
for (const [key, snapshot] of this.snapshots) {
|
|
23900
|
+
if (key.startsWith(`${workflowId}:`)) {
|
|
23901
|
+
results.push(snapshot);
|
|
23902
|
+
}
|
|
23903
|
+
}
|
|
23904
|
+
return results;
|
|
23905
|
+
}
|
|
23906
|
+
clear() {
|
|
23907
|
+
this.snapshots.clear();
|
|
23908
|
+
}
|
|
23909
|
+
};
|
|
23910
|
+
|
|
23383
23911
|
// src/version.ts
|
|
23384
23912
|
var VERSION = "0.1.0";
|
|
23385
23913
|
export {
|
|
@@ -23459,6 +23987,7 @@ export {
|
|
|
23459
23987
|
InMemoryMemoryService,
|
|
23460
23988
|
InMemoryRunner,
|
|
23461
23989
|
InMemorySessionService,
|
|
23990
|
+
InMemorySnapshotStore,
|
|
23462
23991
|
InMemoryStorageProvider,
|
|
23463
23992
|
InMemoryVectorStore,
|
|
23464
23993
|
InvocationContext,
|
|
@@ -23496,14 +24025,18 @@ export {
|
|
|
23496
24025
|
McpMemory,
|
|
23497
24026
|
McpNearAgent,
|
|
23498
24027
|
McpNearIntents,
|
|
24028
|
+
McpNotion,
|
|
23499
24029
|
McpOdos,
|
|
23500
24030
|
McpOpinion,
|
|
24031
|
+
McpPlaywright,
|
|
23501
24032
|
McpPolymarket,
|
|
23502
24033
|
McpSamplingHandler,
|
|
24034
|
+
McpSequentialThinking,
|
|
23503
24035
|
McpTelegram,
|
|
23504
24036
|
McpToolset,
|
|
23505
24037
|
McpUpbit,
|
|
23506
24038
|
memory_exports as Memory,
|
|
24039
|
+
MemoryBuilder,
|
|
23507
24040
|
MemoryService,
|
|
23508
24041
|
ModelFallbackPlugin,
|
|
23509
24042
|
models_exports as Models,
|
|
@@ -23531,6 +24064,7 @@ export {
|
|
|
23531
24064
|
RecallMemoryTool,
|
|
23532
24065
|
ReflectAndRetryToolPlugin,
|
|
23533
24066
|
RougeEvaluator,
|
|
24067
|
+
Run,
|
|
23534
24068
|
RunConfig,
|
|
23535
24069
|
Runner,
|
|
23536
24070
|
SEMCONV,
|
|
@@ -23547,12 +24081,15 @@ export {
|
|
|
23547
24081
|
tools_exports as Tools,
|
|
23548
24082
|
TrajectoryEvaluator,
|
|
23549
24083
|
TransferToAgentTool,
|
|
24084
|
+
unified_memory_exports as UnifiedMemory,
|
|
23550
24085
|
UserInteractionTool,
|
|
23551
24086
|
VERSION,
|
|
23552
24087
|
VectorStorageProvider,
|
|
23553
24088
|
VertexAiSessionService,
|
|
23554
24089
|
WebFetchTool,
|
|
23555
24090
|
WebSearchTool,
|
|
24091
|
+
Workflow,
|
|
24092
|
+
workflows_exports as Workflows,
|
|
23556
24093
|
WriteMemoryTool,
|
|
23557
24094
|
WriteTool,
|
|
23558
24095
|
_findFunctionCallEventIfLastEventIsFunctionResponse,
|
|
@@ -23576,7 +24113,10 @@ export {
|
|
|
23576
24113
|
createPostgresSessionService,
|
|
23577
24114
|
createSamplingHandler,
|
|
23578
24115
|
createSqliteSessionService,
|
|
24116
|
+
createStep,
|
|
23579
24117
|
createTool,
|
|
24118
|
+
createWorkflow,
|
|
24119
|
+
defaultUnifiedMemoryConfig,
|
|
23580
24120
|
extractTextFromContent,
|
|
23581
24121
|
formatSpanAttributes,
|
|
23582
24122
|
generateAuthEvent,
|