@upstash/workflow 0.2.5-agents-2 → 0.2.5

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/solidjs.js CHANGED
@@ -1711,6 +1711,13 @@ var convertLangchainTool = (langchainTool) => {
1711
1711
  // src/agents/agent.ts
1712
1712
  var import_zod = require("zod");
1713
1713
  var import_ai2 = require("ai");
1714
+
1715
+ // src/serve/utils.ts
1716
+ var isDisabledWorkflowContext = (context) => {
1717
+ return "disabled" in context;
1718
+ };
1719
+
1720
+ // src/agents/agent.ts
1714
1721
  var Agent = class {
1715
1722
  name;
1716
1723
  tools;
@@ -1718,13 +1725,15 @@ var Agent = class {
1718
1725
  background;
1719
1726
  model;
1720
1727
  temparature;
1721
- constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }) {
1728
+ context;
1729
+ constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }, context) {
1722
1730
  this.name = name;
1723
1731
  this.tools = tools ?? {};
1724
1732
  this.maxSteps = maxSteps;
1725
1733
  this.background = background;
1726
1734
  this.model = model;
1727
1735
  this.temparature = temparature;
1736
+ this.context = context;
1728
1737
  }
1729
1738
  /**
1730
1739
  * Trigger the agent by passing a prompt
@@ -1734,6 +1743,9 @@ var Agent = class {
1734
1743
  */
1735
1744
  async call({ prompt }) {
1736
1745
  try {
1746
+ if (isDisabledWorkflowContext(this.context)) {
1747
+ await this.context.sleep("abort", 0);
1748
+ }
1737
1749
  const result = await (0, import_ai2.generateText)({
1738
1750
  model: this.model,
1739
1751
  tools: this.tools,
@@ -1796,14 +1808,17 @@ var ManagerAgent = class extends Agent {
1796
1808
  model,
1797
1809
  maxSteps,
1798
1810
  name = "manager llm"
1799
- }) {
1800
- super({
1801
- background,
1802
- maxSteps,
1803
- tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
1804
- name,
1805
- model
1806
- });
1811
+ }, context) {
1812
+ super(
1813
+ {
1814
+ background,
1815
+ maxSteps,
1816
+ tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
1817
+ name,
1818
+ model
1819
+ },
1820
+ context
1821
+ );
1807
1822
  this.agents = agents;
1808
1823
  }
1809
1824
  };
@@ -1826,23 +1841,25 @@ var Task = class {
1826
1841
  */
1827
1842
  async run() {
1828
1843
  const { prompt, ...otherParams } = this.taskParameters;
1829
- const safePrompt = await this.context.run("Get Prompt", () => prompt);
1830
1844
  if ("agent" in otherParams) {
1831
1845
  const agent = otherParams.agent;
1832
1846
  const result = await agent.call({
1833
- prompt: safePrompt
1847
+ prompt
1834
1848
  });
1835
1849
  return { text: result.text };
1836
1850
  } else {
1837
1851
  const { agents, maxSteps, model, background } = otherParams;
1838
- const managerAgent = new ManagerAgent({
1839
- model,
1840
- maxSteps,
1841
- agents,
1842
- name: "Manager LLM",
1843
- background
1844
- });
1845
- const result = await managerAgent.call({ prompt: safePrompt });
1852
+ const managerAgent = new ManagerAgent(
1853
+ {
1854
+ model,
1855
+ maxSteps,
1856
+ agents,
1857
+ name: "Manager LLM",
1858
+ background
1859
+ },
1860
+ this.context
1861
+ );
1862
+ const result = await managerAgent.call({ prompt });
1846
1863
  return { text: result.text };
1847
1864
  }
1848
1865
  }
@@ -1879,10 +1896,13 @@ var WorkflowAgents = class {
1879
1896
  */
1880
1897
  agent(params) {
1881
1898
  const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
1882
- return new Agent({
1883
- ...params,
1884
- tools: wrappedTools
1885
- });
1899
+ return new Agent(
1900
+ {
1901
+ ...params,
1902
+ tools: wrappedTools
1903
+ },
1904
+ this.context
1905
+ );
1886
1906
  }
1887
1907
  task(taskParameters) {
1888
1908
  return new Task({ context: this.context, taskParameters });
@@ -2366,6 +2386,7 @@ function decodeBase64(base64) {
2366
2386
  var import_qstash8 = require("@upstash/qstash");
2367
2387
  var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
2368
2388
  static disabledMessage = "disabled-qstash-worklfow-run";
2389
+ disabled = true;
2369
2390
  /**
2370
2391
  * overwrite the WorkflowContext.addStep method to always raise WorkflowAbort
2371
2392
  * error in order to stop the execution whenever we encounter a step.
package/solidjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-VOM3CFYZ.mjs";
4
+ } from "./chunk-42MM2EPQ.mjs";
5
5
 
6
6
  // platforms/solidjs.ts
7
7
  var serve = (routeFunction, options) => {
package/svelte.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-D9gwTj2n.mjs';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-CalpUeFX.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'ai';
5
5
  import '@ai-sdk/openai';
package/svelte.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RequestHandler } from '@sveltejs/kit';
2
- import { R as RouteFunction, j as PublicServeOptions } from './types-D9gwTj2n.js';
2
+ import { R as RouteFunction, j as PublicServeOptions } from './types-CalpUeFX.js';
3
3
  import '@upstash/qstash';
4
4
  import 'ai';
5
5
  import '@ai-sdk/openai';
package/svelte.js CHANGED
@@ -1711,6 +1711,13 @@ var convertLangchainTool = (langchainTool) => {
1711
1711
  // src/agents/agent.ts
1712
1712
  var import_zod = require("zod");
1713
1713
  var import_ai2 = require("ai");
1714
+
1715
+ // src/serve/utils.ts
1716
+ var isDisabledWorkflowContext = (context) => {
1717
+ return "disabled" in context;
1718
+ };
1719
+
1720
+ // src/agents/agent.ts
1714
1721
  var Agent = class {
1715
1722
  name;
1716
1723
  tools;
@@ -1718,13 +1725,15 @@ var Agent = class {
1718
1725
  background;
1719
1726
  model;
1720
1727
  temparature;
1721
- constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }) {
1728
+ context;
1729
+ constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }, context) {
1722
1730
  this.name = name;
1723
1731
  this.tools = tools ?? {};
1724
1732
  this.maxSteps = maxSteps;
1725
1733
  this.background = background;
1726
1734
  this.model = model;
1727
1735
  this.temparature = temparature;
1736
+ this.context = context;
1728
1737
  }
1729
1738
  /**
1730
1739
  * Trigger the agent by passing a prompt
@@ -1734,6 +1743,9 @@ var Agent = class {
1734
1743
  */
1735
1744
  async call({ prompt }) {
1736
1745
  try {
1746
+ if (isDisabledWorkflowContext(this.context)) {
1747
+ await this.context.sleep("abort", 0);
1748
+ }
1737
1749
  const result = await (0, import_ai2.generateText)({
1738
1750
  model: this.model,
1739
1751
  tools: this.tools,
@@ -1796,14 +1808,17 @@ var ManagerAgent = class extends Agent {
1796
1808
  model,
1797
1809
  maxSteps,
1798
1810
  name = "manager llm"
1799
- }) {
1800
- super({
1801
- background,
1802
- maxSteps,
1803
- tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
1804
- name,
1805
- model
1806
- });
1811
+ }, context) {
1812
+ super(
1813
+ {
1814
+ background,
1815
+ maxSteps,
1816
+ tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
1817
+ name,
1818
+ model
1819
+ },
1820
+ context
1821
+ );
1807
1822
  this.agents = agents;
1808
1823
  }
1809
1824
  };
@@ -1826,23 +1841,25 @@ var Task = class {
1826
1841
  */
1827
1842
  async run() {
1828
1843
  const { prompt, ...otherParams } = this.taskParameters;
1829
- const safePrompt = await this.context.run("Get Prompt", () => prompt);
1830
1844
  if ("agent" in otherParams) {
1831
1845
  const agent = otherParams.agent;
1832
1846
  const result = await agent.call({
1833
- prompt: safePrompt
1847
+ prompt
1834
1848
  });
1835
1849
  return { text: result.text };
1836
1850
  } else {
1837
1851
  const { agents, maxSteps, model, background } = otherParams;
1838
- const managerAgent = new ManagerAgent({
1839
- model,
1840
- maxSteps,
1841
- agents,
1842
- name: "Manager LLM",
1843
- background
1844
- });
1845
- const result = await managerAgent.call({ prompt: safePrompt });
1852
+ const managerAgent = new ManagerAgent(
1853
+ {
1854
+ model,
1855
+ maxSteps,
1856
+ agents,
1857
+ name: "Manager LLM",
1858
+ background
1859
+ },
1860
+ this.context
1861
+ );
1862
+ const result = await managerAgent.call({ prompt });
1846
1863
  return { text: result.text };
1847
1864
  }
1848
1865
  }
@@ -1879,10 +1896,13 @@ var WorkflowAgents = class {
1879
1896
  */
1880
1897
  agent(params) {
1881
1898
  const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
1882
- return new Agent({
1883
- ...params,
1884
- tools: wrappedTools
1885
- });
1899
+ return new Agent(
1900
+ {
1901
+ ...params,
1902
+ tools: wrappedTools
1903
+ },
1904
+ this.context
1905
+ );
1886
1906
  }
1887
1907
  task(taskParameters) {
1888
1908
  return new Task({ context: this.context, taskParameters });
@@ -2366,6 +2386,7 @@ function decodeBase64(base64) {
2366
2386
  var import_qstash8 = require("@upstash/qstash");
2367
2387
  var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
2368
2388
  static disabledMessage = "disabled-qstash-worklfow-run";
2389
+ disabled = true;
2369
2390
  /**
2370
2391
  * overwrite the WorkflowContext.addStep method to always raise WorkflowAbort
2371
2392
  * error in order to stop the execution whenever we encounter a step.
package/svelte.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-VOM3CFYZ.mjs";
4
+ } from "./chunk-42MM2EPQ.mjs";
5
5
 
6
6
  // platforms/svelte.ts
7
7
  var serve = (routeFunction, options) => {
@@ -410,7 +410,8 @@ declare class Agent {
410
410
  readonly background: AgentParameters["background"];
411
411
  readonly model: AgentParameters["model"];
412
412
  readonly temparature: AgentParameters["temparature"];
413
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters);
413
+ private readonly context;
414
+ constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
414
415
  /**
415
416
  * Trigger the agent by passing a prompt
416
417
  *
@@ -410,7 +410,8 @@ declare class Agent {
410
410
  readonly background: AgentParameters["background"];
411
411
  readonly model: AgentParameters["model"];
412
412
  readonly temparature: AgentParameters["temparature"];
413
- constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters);
413
+ private readonly context;
414
+ constructor({ tools, maxSteps, background, name, model, temparature }: AgentParameters, context: WorkflowContext);
414
415
  /**
415
416
  * Trigger the agent by passing a prompt
416
417
  *