@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/dist/index.js CHANGED
@@ -946,6 +946,7 @@ __export(src_exports, {
946
946
  InMemoryMemoryService: () => InMemoryMemoryService,
947
947
  InMemoryRunner: () => InMemoryRunner,
948
948
  InMemorySessionService: () => InMemorySessionService,
949
+ InMemorySnapshotStore: () => InMemorySnapshotStore,
949
950
  InMemoryStorageProvider: () => InMemoryStorageProvider,
950
951
  InMemoryVectorStore: () => InMemoryVectorStore,
951
952
  InvocationContext: () => InvocationContext,
@@ -983,14 +984,18 @@ __export(src_exports, {
983
984
  McpMemory: () => McpMemory,
984
985
  McpNearAgent: () => McpNearAgent,
985
986
  McpNearIntents: () => McpNearIntents,
987
+ McpNotion: () => McpNotion,
986
988
  McpOdos: () => McpOdos,
987
989
  McpOpinion: () => McpOpinion,
990
+ McpPlaywright: () => McpPlaywright,
988
991
  McpPolymarket: () => McpPolymarket,
989
992
  McpSamplingHandler: () => McpSamplingHandler,
993
+ McpSequentialThinking: () => McpSequentialThinking,
990
994
  McpTelegram: () => McpTelegram,
991
995
  McpToolset: () => McpToolset,
992
996
  McpUpbit: () => McpUpbit,
993
997
  Memory: () => memory_exports,
998
+ MemoryBuilder: () => MemoryBuilder,
994
999
  MemoryService: () => MemoryService,
995
1000
  ModelFallbackPlugin: () => ModelFallbackPlugin,
996
1001
  Models: () => models_exports,
@@ -1018,6 +1023,7 @@ __export(src_exports, {
1018
1023
  RecallMemoryTool: () => RecallMemoryTool,
1019
1024
  ReflectAndRetryToolPlugin: () => ReflectAndRetryToolPlugin,
1020
1025
  RougeEvaluator: () => RougeEvaluator,
1026
+ Run: () => Run,
1021
1027
  RunConfig: () => RunConfig,
1022
1028
  Runner: () => Runner,
1023
1029
  SEMCONV: () => SEMCONV,
@@ -1034,12 +1040,15 @@ __export(src_exports, {
1034
1040
  Tools: () => tools_exports,
1035
1041
  TrajectoryEvaluator: () => TrajectoryEvaluator,
1036
1042
  TransferToAgentTool: () => TransferToAgentTool,
1043
+ UnifiedMemory: () => unified_memory_exports,
1037
1044
  UserInteractionTool: () => UserInteractionTool,
1038
1045
  VERSION: () => VERSION,
1039
1046
  VectorStorageProvider: () => VectorStorageProvider,
1040
1047
  VertexAiSessionService: () => VertexAiSessionService,
1041
1048
  WebFetchTool: () => WebFetchTool,
1042
1049
  WebSearchTool: () => WebSearchTool,
1050
+ Workflow: () => Workflow,
1051
+ Workflows: () => workflows_exports,
1043
1052
  WriteMemoryTool: () => WriteMemoryTool,
1044
1053
  WriteTool: () => WriteTool,
1045
1054
  _findFunctionCallEventIfLastEventIsFunctionResponse: () => _findFunctionCallEventIfLastEventIsFunctionResponse,
@@ -1063,7 +1072,10 @@ __export(src_exports, {
1063
1072
  createPostgresSessionService: () => createPostgresSessionService,
1064
1073
  createSamplingHandler: () => createSamplingHandler,
1065
1074
  createSqliteSessionService: () => createSqliteSessionService,
1075
+ createStep: () => createStep,
1066
1076
  createTool: () => createTool,
1077
+ createWorkflow: () => createWorkflow,
1078
+ defaultUnifiedMemoryConfig: () => defaultUnifiedMemoryConfig,
1067
1079
  extractTextFromContent: () => extractTextFromContent,
1068
1080
  formatSpanAttributes: () => formatSpanAttributes,
1069
1081
  generateAuthEvent: () => generateAuthEvent,
@@ -10182,10 +10194,13 @@ __export(tools_exports, {
10182
10194
  McpMemory: () => McpMemory,
10183
10195
  McpNearAgent: () => McpNearAgent,
10184
10196
  McpNearIntents: () => McpNearIntents,
10197
+ McpNotion: () => McpNotion,
10185
10198
  McpOdos: () => McpOdos,
10186
10199
  McpOpinion: () => McpOpinion,
10200
+ McpPlaywright: () => McpPlaywright,
10187
10201
  McpPolymarket: () => McpPolymarket,
10188
10202
  McpSamplingHandler: () => McpSamplingHandler,
10203
+ McpSequentialThinking: () => McpSequentialThinking,
10189
10204
  McpTelegram: () => McpTelegram,
10190
10205
  McpToolset: () => McpToolset,
10191
10206
  McpUpbit: () => McpUpbit,
@@ -13633,11 +13648,16 @@ async function convertMcpToolToBaseTool(params) {
13633
13648
  throw error;
13634
13649
  }
13635
13650
  }
13651
+ function sanitizeMcpToolName(name) {
13652
+ return name.replace(/-/g, "_");
13653
+ }
13636
13654
  var McpToolAdapter = class extends BaseTool {
13637
13655
  mcpTool;
13638
13656
  client;
13639
13657
  clientService = null;
13640
13658
  toolHandler;
13659
+ /** The original MCP tool name, preserved for calls back to the MCP server. */
13660
+ originalMcpName;
13641
13661
  logger = new Logger({ name: "McpToolAdapter" });
13642
13662
  constructor(mcpTool, client, handler) {
13643
13663
  let metadata = {};
@@ -13646,13 +13666,15 @@ var McpToolAdapter = class extends BaseTool {
13646
13666
  } else if (mcpTool._meta && typeof mcpTool._meta === "object") {
13647
13667
  metadata = mcpTool._meta;
13648
13668
  }
13669
+ const rawName = mcpTool.name || `mcp_${Date.now()}`;
13649
13670
  super({
13650
- name: mcpTool.name || `mcp_${Date.now()}`,
13671
+ name: sanitizeMcpToolName(rawName),
13651
13672
  description: mcpTool.description || "MCP Tool",
13652
13673
  isLongRunning: metadata.isLongRunning ?? false,
13653
13674
  shouldRetryOnFailure: metadata.shouldRetryOnFailure ?? false,
13654
13675
  maxRetryAttempts: metadata.maxRetryAttempts ?? 3
13655
13676
  });
13677
+ this.originalMcpName = rawName;
13656
13678
  this.mcpTool = mcpTool;
13657
13679
  this.client = client;
13658
13680
  this.toolHandler = handler;
@@ -13677,27 +13699,30 @@ var McpToolAdapter = class extends BaseTool {
13677
13699
  }
13678
13700
  }
13679
13701
  async runAsync(args, _context) {
13680
- this.logger.debug(`Executing MCP tool ${this.name} with args:`, args);
13702
+ this.logger.debug(
13703
+ `Executing MCP tool ${this.originalMcpName} with args:`,
13704
+ args
13705
+ );
13681
13706
  try {
13682
13707
  if ("execute" in this.mcpTool && typeof this.mcpTool.execute === "function") {
13683
13708
  return await this.mcpTool.execute(args);
13684
13709
  }
13685
13710
  if (this.clientService) {
13686
- return await this.clientService.callTool(this.name, args);
13711
+ return await this.clientService.callTool(this.originalMcpName, args);
13687
13712
  }
13688
13713
  if (this.client && typeof this.client.callTool === "function") {
13689
13714
  if (this.shouldRetryOnFailure) {
13690
13715
  const executeWithRetry = withRetry(
13691
13716
  async () => {
13692
13717
  return await this.client.callTool({
13693
- name: this.name,
13718
+ name: this.originalMcpName,
13694
13719
  arguments: args
13695
13720
  });
13696
13721
  },
13697
13722
  this,
13698
13723
  async () => {
13699
13724
  console.warn(
13700
- `MCP tool ${this.name} encountered a closed resource, but cannot reinitialize client.`
13725
+ `MCP tool ${this.originalMcpName} encountered a closed resource, but cannot reinitialize client.`
13701
13726
  );
13702
13727
  },
13703
13728
  this.maxRetryAttempts
@@ -13705,23 +13730,26 @@ var McpToolAdapter = class extends BaseTool {
13705
13730
  return await executeWithRetry();
13706
13731
  }
13707
13732
  const result = await this.client.callTool({
13708
- name: this.name,
13733
+ name: this.originalMcpName,
13709
13734
  arguments: args
13710
13735
  });
13711
13736
  return result;
13712
13737
  }
13713
13738
  if (this.toolHandler) {
13714
- return await this.toolHandler(this.name, args);
13739
+ return await this.toolHandler(this.originalMcpName, args);
13715
13740
  }
13716
13741
  throw new McpError(
13717
- `Cannot execute MCP tool ${this.name}: No execution method found`,
13742
+ `Cannot execute MCP tool ${this.originalMcpName}: No execution method found`,
13718
13743
  "tool_execution_error" /* TOOL_EXECUTION_ERROR */
13719
13744
  );
13720
13745
  } catch (error) {
13721
13746
  if (!(error instanceof McpError)) {
13722
- console.error(`Error executing MCP tool ${this.name}:`, error);
13747
+ console.error(
13748
+ `Error executing MCP tool ${this.originalMcpName}:`,
13749
+ error
13750
+ );
13723
13751
  throw new McpError(
13724
- `Error executing MCP tool ${this.name}: ${error instanceof Error ? error.message : String(error)}`,
13752
+ `Error executing MCP tool ${this.originalMcpName}: ${error instanceof Error ? error.message : String(error)}`,
13725
13753
  "tool_execution_error" /* TOOL_EXECUTION_ERROR */,
13726
13754
  error instanceof Error ? error : void 0
13727
13755
  );
@@ -13931,6 +13959,30 @@ function McpMemory(config = {}) {
13931
13959
  );
13932
13960
  return new McpToolset(mcpConfig);
13933
13961
  }
13962
+ function McpNotion(config = {}) {
13963
+ const mcpConfig = createMcpConfig(
13964
+ "Notion MCP Client",
13965
+ "@notionhq/notion-mcp-server",
13966
+ config
13967
+ );
13968
+ return new McpToolset(mcpConfig);
13969
+ }
13970
+ function McpSequentialThinking(config = {}) {
13971
+ const mcpConfig = createMcpConfig(
13972
+ "Sequential Thinking MCP Client",
13973
+ "@modelcontextprotocol/server-sequential-thinking",
13974
+ config
13975
+ );
13976
+ return new McpToolset(mcpConfig);
13977
+ }
13978
+ function McpPlaywright(config = {}) {
13979
+ const mcpConfig = createMcpConfig(
13980
+ "Playwright MCP Client",
13981
+ "@playwright/mcp",
13982
+ config
13983
+ );
13984
+ return new McpToolset(mcpConfig);
13985
+ }
13934
13986
  function McpGeneric(packageName, config = {}, name) {
13935
13987
  const clientName = name || `${packageName} Client`;
13936
13988
  const mcpConfig = createMcpConfig(clientName, packageName, config);
@@ -23585,6 +23637,494 @@ function streamTextWithFinalEvent(events) {
23585
23637
  };
23586
23638
  }
23587
23639
 
23640
+ // src/unified-memory/index.ts
23641
+ var unified_memory_exports = {};
23642
+ __export(unified_memory_exports, {
23643
+ MemoryBuilder: () => MemoryBuilder,
23644
+ defaultUnifiedMemoryConfig: () => defaultUnifiedMemoryConfig
23645
+ });
23646
+
23647
+ // src/unified-memory/types.ts
23648
+ var defaultUnifiedMemoryConfig = {
23649
+ lastMessages: 40
23650
+ };
23651
+
23652
+ // src/unified-memory/memory-builder.ts
23653
+ var WORKING_MEMORY_KEY = "__working_memory__";
23654
+ var MemoryBuilder = class _MemoryBuilder {
23655
+ sessionService;
23656
+ memoryService;
23657
+ appName;
23658
+ userId;
23659
+ lastMessages;
23660
+ workingMemoryEnabled;
23661
+ workingMemoryTemplate;
23662
+ constructor(config) {
23663
+ this.appName = config.appName;
23664
+ this.userId = config.userId;
23665
+ this.lastMessages = config.lastMessages ?? defaultUnifiedMemoryConfig.lastMessages;
23666
+ this.sessionService = new InMemorySessionService();
23667
+ this.workingMemoryEnabled = config.workingMemory?.enabled ?? false;
23668
+ this.workingMemoryTemplate = config.workingMemory?.template;
23669
+ }
23670
+ static create(config) {
23671
+ return new _MemoryBuilder(config);
23672
+ }
23673
+ withSessionService(service) {
23674
+ this.sessionService = service;
23675
+ return this;
23676
+ }
23677
+ withMemoryService(service) {
23678
+ this.memoryService = service;
23679
+ return this;
23680
+ }
23681
+ withAppName(appName) {
23682
+ this.appName = appName;
23683
+ return this;
23684
+ }
23685
+ withUserId(userId) {
23686
+ this.userId = userId;
23687
+ return this;
23688
+ }
23689
+ async createSession(state, sessionId) {
23690
+ const initialState = { ...state };
23691
+ if (this.workingMemoryEnabled && this.workingMemoryTemplate) {
23692
+ initialState[WORKING_MEMORY_KEY] = this.workingMemoryTemplate;
23693
+ }
23694
+ return this.sessionService.createSession(
23695
+ this.appName,
23696
+ this.userId,
23697
+ initialState,
23698
+ sessionId
23699
+ );
23700
+ }
23701
+ async getSession(sessionId) {
23702
+ return this.sessionService.getSession(this.appName, this.userId, sessionId);
23703
+ }
23704
+ async listSessions() {
23705
+ return this.sessionService.listSessions(this.appName, this.userId);
23706
+ }
23707
+ async deleteSession(sessionId) {
23708
+ return this.sessionService.deleteSession(
23709
+ this.appName,
23710
+ this.userId,
23711
+ sessionId
23712
+ );
23713
+ }
23714
+ async addMessage(session, message) {
23715
+ const author = message.role === "user" ? "user" : message.role === "assistant" ? "model" : "system";
23716
+ const event = new Event({
23717
+ author,
23718
+ content: {
23719
+ role: author,
23720
+ parts: [{ text: message.content }]
23721
+ }
23722
+ });
23723
+ const appended = await this.sessionService.appendEvent(session, event);
23724
+ if (this.memoryService) {
23725
+ await this.memoryService.addSessionToMemory(session);
23726
+ }
23727
+ return appended;
23728
+ }
23729
+ async addEvent(session, event) {
23730
+ const appended = await this.sessionService.appendEvent(session, event);
23731
+ if (this.memoryService) {
23732
+ await this.memoryService.addSessionToMemory(session);
23733
+ }
23734
+ return appended;
23735
+ }
23736
+ async recall(sessionId) {
23737
+ const session = await this.sessionService.getSession(
23738
+ this.appName,
23739
+ this.userId,
23740
+ sessionId,
23741
+ this.lastMessages === false ? void 0 : { numRecentEvents: this.lastMessages }
23742
+ );
23743
+ if (!session) {
23744
+ throw new Error(`Session not found: ${sessionId}`);
23745
+ }
23746
+ return session.events.map((event) => ({
23747
+ role: this.eventAuthorToRole(event.author),
23748
+ content: this.extractEventText(event)
23749
+ }));
23750
+ }
23751
+ async recallEvents(sessionId) {
23752
+ const session = await this.sessionService.getSession(
23753
+ this.appName,
23754
+ this.userId,
23755
+ sessionId,
23756
+ this.lastMessages === false ? void 0 : { numRecentEvents: this.lastMessages }
23757
+ );
23758
+ if (!session) {
23759
+ throw new Error(`Session not found: ${sessionId}`);
23760
+ }
23761
+ return session.events;
23762
+ }
23763
+ async search(query) {
23764
+ if (!this.memoryService) {
23765
+ throw new Error(
23766
+ "MemoryService is required for search. Use withMemoryService() to configure one."
23767
+ );
23768
+ }
23769
+ return this.memoryService.search({
23770
+ query,
23771
+ userId: this.userId,
23772
+ appName: this.appName
23773
+ });
23774
+ }
23775
+ async getWorkingMemory(sessionId) {
23776
+ const session = await this.sessionService.getSession(
23777
+ this.appName,
23778
+ this.userId,
23779
+ sessionId
23780
+ );
23781
+ if (!session) {
23782
+ throw new Error(`Session not found: ${sessionId}`);
23783
+ }
23784
+ const stored = session.state[WORKING_MEMORY_KEY];
23785
+ if (stored) return stored;
23786
+ if (this.workingMemoryEnabled && this.workingMemoryTemplate) {
23787
+ return this.workingMemoryTemplate;
23788
+ }
23789
+ return null;
23790
+ }
23791
+ async updateWorkingMemory(session, content) {
23792
+ const event = new Event({
23793
+ author: "system",
23794
+ actions: new EventActions({
23795
+ stateDelta: { [WORKING_MEMORY_KEY]: content }
23796
+ })
23797
+ });
23798
+ await this.sessionService.appendEvent(session, event);
23799
+ }
23800
+ async endSession(sessionId) {
23801
+ const session = await this.sessionService.endSession(
23802
+ this.appName,
23803
+ this.userId,
23804
+ sessionId
23805
+ );
23806
+ if (session && this.memoryService) {
23807
+ await this.memoryService.addSessionToMemory(session);
23808
+ }
23809
+ return session;
23810
+ }
23811
+ getSessionService() {
23812
+ return this.sessionService;
23813
+ }
23814
+ getMemoryService() {
23815
+ return this.memoryService;
23816
+ }
23817
+ eventAuthorToRole(author) {
23818
+ if (author === "user") return "user";
23819
+ if (author === "system") return "system";
23820
+ return "assistant";
23821
+ }
23822
+ extractEventText(event) {
23823
+ if (event.text) return event.text;
23824
+ if (event.content?.parts && Array.isArray(event.content.parts)) {
23825
+ const textParts = event.content.parts.filter(
23826
+ (part) => typeof part.text === "string" && part.text.length > 0
23827
+ ).map((part) => part.text);
23828
+ if (textParts.length > 0) return textParts.join(" ");
23829
+ }
23830
+ return "";
23831
+ }
23832
+ };
23833
+
23834
+ // src/workflows/index.ts
23835
+ var workflows_exports = {};
23836
+ __export(workflows_exports, {
23837
+ InMemorySnapshotStore: () => InMemorySnapshotStore,
23838
+ Run: () => Run,
23839
+ Workflow: () => Workflow,
23840
+ createStep: () => createStep,
23841
+ createWorkflow: () => createWorkflow
23842
+ });
23843
+
23844
+ // src/workflows/step.ts
23845
+ function createStep(definition) {
23846
+ return {
23847
+ id: definition.id,
23848
+ description: definition.description,
23849
+ inputSchema: definition.inputSchema,
23850
+ outputSchema: definition.outputSchema,
23851
+ resumeSchema: definition.resumeSchema,
23852
+ suspendSchema: definition.suspendSchema,
23853
+ execute: definition.execute
23854
+ };
23855
+ }
23856
+
23857
+ // src/workflows/workflow.ts
23858
+ var SuspendError = class extends Error {
23859
+ constructor(suspendPayload) {
23860
+ super("Workflow suspended");
23861
+ this.suspendPayload = suspendPayload;
23862
+ this.name = "SuspendError";
23863
+ }
23864
+ };
23865
+ function generateRunId() {
23866
+ return `run_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
23867
+ }
23868
+ var Run = class _Run {
23869
+ constructor(workflow, runId) {
23870
+ this.workflow = workflow;
23871
+ this.runId = runId ?? generateRunId();
23872
+ this.createdAt = Date.now();
23873
+ this.updatedAt = this.createdAt;
23874
+ }
23875
+ runId;
23876
+ status = "pending";
23877
+ stepResults = {};
23878
+ suspendedStepId;
23879
+ suspendPayload;
23880
+ result;
23881
+ input;
23882
+ createdAt;
23883
+ updatedAt;
23884
+ async start(input) {
23885
+ if (this.status !== "pending") {
23886
+ throw new Error(`Cannot start run in status: ${this.status}`);
23887
+ }
23888
+ this.input = input;
23889
+ this.status = "running";
23890
+ return this.executeSteps(0);
23891
+ }
23892
+ async resume(options) {
23893
+ if (this.status !== "suspended") {
23894
+ throw new Error(`Cannot resume run in status: ${this.status}`);
23895
+ }
23896
+ const stepId = options.step ?? this.suspendedStepId;
23897
+ if (!stepId) {
23898
+ throw new Error("No suspended step to resume");
23899
+ }
23900
+ const stepIndex = this.workflow.stepGraph.findIndex((s) => s.id === stepId);
23901
+ if (stepIndex === -1) {
23902
+ throw new Error(`Step not found: ${stepId}`);
23903
+ }
23904
+ this.status = "running";
23905
+ return this.executeSteps(stepIndex, options.resumeData);
23906
+ }
23907
+ async executeSteps(startIndex, resumeData) {
23908
+ const steps = this.workflow.stepGraph;
23909
+ let isFirstResumedStep = resumeData !== void 0;
23910
+ for (let i = startIndex; i < steps.length; i++) {
23911
+ const step = steps[i];
23912
+ const startedAt = Date.now();
23913
+ const context4 = {
23914
+ runId: this.runId,
23915
+ workflowId: this.workflow.id,
23916
+ inputData: this.input,
23917
+ resumeData: isFirstResumedStep ? resumeData : void 0,
23918
+ suspend: (payload) => {
23919
+ throw new SuspendError(payload);
23920
+ },
23921
+ getStepResult: (stepId) => {
23922
+ const result = this.stepResults[stepId];
23923
+ if (result?.status === "success") {
23924
+ return result.output;
23925
+ }
23926
+ return void 0;
23927
+ }
23928
+ };
23929
+ try {
23930
+ const output = await step.execute(context4);
23931
+ const endedAt = Date.now();
23932
+ const previousResult = this.stepResults[step.id];
23933
+ if (previousResult?.status === "suspended") {
23934
+ this.stepResults[step.id] = {
23935
+ status: "success",
23936
+ output,
23937
+ payload: this.input,
23938
+ resumePayload: resumeData,
23939
+ startedAt: previousResult.startedAt,
23940
+ endedAt,
23941
+ suspendedAt: previousResult.suspendedAt,
23942
+ resumedAt: startedAt
23943
+ };
23944
+ } else {
23945
+ this.stepResults[step.id] = {
23946
+ status: "success",
23947
+ output,
23948
+ payload: this.input,
23949
+ startedAt,
23950
+ endedAt
23951
+ };
23952
+ }
23953
+ isFirstResumedStep = false;
23954
+ } catch (err) {
23955
+ if (err instanceof SuspendError) {
23956
+ this.status = "suspended";
23957
+ this.suspendedStepId = step.id;
23958
+ this.suspendPayload = err.suspendPayload;
23959
+ this.stepResults[step.id] = {
23960
+ status: "suspended",
23961
+ payload: this.input,
23962
+ suspendPayload: err.suspendPayload,
23963
+ startedAt,
23964
+ suspendedAt: Date.now()
23965
+ };
23966
+ await this.saveSnapshot();
23967
+ return {
23968
+ status: "suspended",
23969
+ steps: this.stepResults,
23970
+ suspendedStep: step.id,
23971
+ suspendPayload: err.suspendPayload
23972
+ };
23973
+ }
23974
+ this.status = "failed";
23975
+ const error = err instanceof Error ? err : new Error(String(err));
23976
+ this.stepResults[step.id] = {
23977
+ status: "failed",
23978
+ error,
23979
+ payload: this.input,
23980
+ startedAt,
23981
+ endedAt: Date.now()
23982
+ };
23983
+ return {
23984
+ status: "failed",
23985
+ error,
23986
+ steps: this.stepResults
23987
+ };
23988
+ }
23989
+ }
23990
+ this.status = "success";
23991
+ const lastStep = steps[steps.length - 1];
23992
+ const lastResult = this.stepResults[lastStep.id];
23993
+ this.result = lastResult?.status === "success" ? lastResult.output : void 0;
23994
+ await this.workflow.snapshotStore?.delete(this.workflow.id, this.runId);
23995
+ return {
23996
+ status: "success",
23997
+ result: this.result,
23998
+ steps: this.stepResults
23999
+ };
24000
+ }
24001
+ async saveSnapshot() {
24002
+ if (!this.workflow.snapshotStore) return;
24003
+ const snapshot = {
24004
+ runId: this.runId,
24005
+ workflowId: this.workflow.id,
24006
+ status: this.status,
24007
+ input: this.input,
24008
+ stepResults: this.stepResults,
24009
+ suspendedStepId: this.suspendedStepId,
24010
+ suspendPayload: this.suspendPayload,
24011
+ createdAt: this.createdAt,
24012
+ updatedAt: Date.now()
24013
+ };
24014
+ await this.workflow.snapshotStore.save(snapshot);
24015
+ }
24016
+ getStatus() {
24017
+ return this.status;
24018
+ }
24019
+ getStepResults() {
24020
+ return this.stepResults;
24021
+ }
24022
+ getSuspendedStepId() {
24023
+ return this.suspendedStepId;
24024
+ }
24025
+ static async fromSnapshot(workflow, snapshot) {
24026
+ const run = new _Run(workflow, snapshot.runId);
24027
+ run.status = snapshot.status;
24028
+ run.input = snapshot.input;
24029
+ run.stepResults = snapshot.stepResults;
24030
+ run.suspendedStepId = snapshot.suspendedStepId;
24031
+ run.suspendPayload = snapshot.suspendPayload;
24032
+ run.createdAt = snapshot.createdAt;
24033
+ run.updatedAt = snapshot.updatedAt;
24034
+ return run;
24035
+ }
24036
+ };
24037
+ var Workflow = class {
24038
+ id;
24039
+ description;
24040
+ inputSchema;
24041
+ outputSchema;
24042
+ stepGraph = [];
24043
+ snapshotStore;
24044
+ committed = false;
24045
+ constructor(config) {
24046
+ this.id = config.id;
24047
+ this.description = config.description;
24048
+ this.inputSchema = config.inputSchema;
24049
+ this.outputSchema = config.outputSchema;
24050
+ }
24051
+ step(step) {
24052
+ if (this.committed) {
24053
+ throw new Error("Cannot add steps to a committed workflow");
24054
+ }
24055
+ this.stepGraph.push(step);
24056
+ return this;
24057
+ }
24058
+ withSnapshotStore(store) {
24059
+ this.snapshotStore = store;
24060
+ return this;
24061
+ }
24062
+ commit() {
24063
+ if (this.stepGraph.length === 0) {
24064
+ throw new Error("Workflow must have at least one step");
24065
+ }
24066
+ this.committed = true;
24067
+ return this;
24068
+ }
24069
+ createRun(runId) {
24070
+ if (!this.committed) {
24071
+ throw new Error("Workflow must be committed before creating a run");
24072
+ }
24073
+ return new Run(this, runId);
24074
+ }
24075
+ async resumeRun(runId) {
24076
+ if (!this.snapshotStore) {
24077
+ throw new Error("Cannot resume run without a snapshot store configured");
24078
+ }
24079
+ const snapshot = await this.snapshotStore.load(this.id, runId);
24080
+ if (!snapshot) {
24081
+ return null;
24082
+ }
24083
+ return Run.fromSnapshot(this, snapshot);
24084
+ }
24085
+ async listRuns() {
24086
+ if (!this.snapshotStore) {
24087
+ return [];
24088
+ }
24089
+ return this.snapshotStore.list(this.id);
24090
+ }
24091
+ };
24092
+ function createWorkflow(config) {
24093
+ return new Workflow(config);
24094
+ }
24095
+
24096
+ // src/workflows/snapshot-store.ts
24097
+ var InMemorySnapshotStore = class {
24098
+ snapshots = /* @__PURE__ */ new Map();
24099
+ getKey(workflowId, runId) {
24100
+ return `${workflowId}:${runId}`;
24101
+ }
24102
+ async save(snapshot) {
24103
+ const key = this.getKey(snapshot.workflowId, snapshot.runId);
24104
+ this.snapshots.set(key, { ...snapshot, updatedAt: Date.now() });
24105
+ }
24106
+ async load(workflowId, runId) {
24107
+ const key = this.getKey(workflowId, runId);
24108
+ return this.snapshots.get(key) ?? null;
24109
+ }
24110
+ async delete(workflowId, runId) {
24111
+ const key = this.getKey(workflowId, runId);
24112
+ this.snapshots.delete(key);
24113
+ }
24114
+ async list(workflowId) {
24115
+ const results = [];
24116
+ for (const [key, snapshot] of this.snapshots) {
24117
+ if (key.startsWith(`${workflowId}:`)) {
24118
+ results.push(snapshot);
24119
+ }
24120
+ }
24121
+ return results;
24122
+ }
24123
+ clear() {
24124
+ this.snapshots.clear();
24125
+ }
24126
+ };
24127
+
23588
24128
  // src/version.ts
23589
24129
  var VERSION = "0.1.0";
23590
24130
  // Annotate the CommonJS export names for ESM import in node:
@@ -23665,6 +24205,7 @@ var VERSION = "0.1.0";
23665
24205
  InMemoryMemoryService,
23666
24206
  InMemoryRunner,
23667
24207
  InMemorySessionService,
24208
+ InMemorySnapshotStore,
23668
24209
  InMemoryStorageProvider,
23669
24210
  InMemoryVectorStore,
23670
24211
  InvocationContext,
@@ -23702,14 +24243,18 @@ var VERSION = "0.1.0";
23702
24243
  McpMemory,
23703
24244
  McpNearAgent,
23704
24245
  McpNearIntents,
24246
+ McpNotion,
23705
24247
  McpOdos,
23706
24248
  McpOpinion,
24249
+ McpPlaywright,
23707
24250
  McpPolymarket,
23708
24251
  McpSamplingHandler,
24252
+ McpSequentialThinking,
23709
24253
  McpTelegram,
23710
24254
  McpToolset,
23711
24255
  McpUpbit,
23712
24256
  Memory,
24257
+ MemoryBuilder,
23713
24258
  MemoryService,
23714
24259
  ModelFallbackPlugin,
23715
24260
  Models,
@@ -23737,6 +24282,7 @@ var VERSION = "0.1.0";
23737
24282
  RecallMemoryTool,
23738
24283
  ReflectAndRetryToolPlugin,
23739
24284
  RougeEvaluator,
24285
+ Run,
23740
24286
  RunConfig,
23741
24287
  Runner,
23742
24288
  SEMCONV,
@@ -23753,12 +24299,15 @@ var VERSION = "0.1.0";
23753
24299
  Tools,
23754
24300
  TrajectoryEvaluator,
23755
24301
  TransferToAgentTool,
24302
+ UnifiedMemory,
23756
24303
  UserInteractionTool,
23757
24304
  VERSION,
23758
24305
  VectorStorageProvider,
23759
24306
  VertexAiSessionService,
23760
24307
  WebFetchTool,
23761
24308
  WebSearchTool,
24309
+ Workflow,
24310
+ Workflows,
23762
24311
  WriteMemoryTool,
23763
24312
  WriteTool,
23764
24313
  _findFunctionCallEventIfLastEventIsFunctionResponse,
@@ -23782,7 +24331,10 @@ var VERSION = "0.1.0";
23782
24331
  createPostgresSessionService,
23783
24332
  createSamplingHandler,
23784
24333
  createSqliteSessionService,
24334
+ createStep,
23785
24335
  createTool,
24336
+ createWorkflow,
24337
+ defaultUnifiedMemoryConfig,
23786
24338
  extractTextFromContent,
23787
24339
  formatSpanAttributes,
23788
24340
  generateAuthEvent,