@upstash/workflow 0.2.22 → 0.3.0-rc

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/nextjs.js CHANGED
@@ -183,12 +183,11 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
183
183
  var DEFAULT_CONTENT_TYPE = "application/json";
184
184
  var NO_CONCURRENCY = 1;
185
185
  var DEFAULT_RETRIES = 3;
186
- var VERSION = "v0.2.22";
186
+ var VERSION = "v0.3.0-rc";
187
187
  var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
188
188
  var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
189
189
  var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
190
190
  var TELEMETRY_HEADER_RUNTIME = "Upstash-Telemetry-Runtime";
191
- var TELEMETRY_HEADER_AGENT = "Upstash-Telemetry-Agent";
192
191
 
193
192
  // src/context/auto-executor.ts
194
193
  var import_qstash5 = require("@upstash/qstash");
@@ -561,9 +560,9 @@ var Ok = class {
561
560
  }
562
561
  safeUnwrap() {
563
562
  const value = this.value;
564
- return function* () {
563
+ return (function* () {
565
564
  return value;
566
- }();
565
+ })();
567
566
  }
568
567
  _unsafeUnwrap(_) {
569
568
  return this.value;
@@ -622,10 +621,10 @@ var Err = class {
622
621
  }
623
622
  safeUnwrap() {
624
623
  const error = this.error;
625
- return function* () {
624
+ return (function* () {
626
625
  yield err(error);
627
626
  throw new Error("Do not use this generator out of `safeTry`");
628
- }();
627
+ })();
629
628
  }
630
629
  _unsafeUnwrap(config) {
631
630
  throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config);
@@ -1592,20 +1591,6 @@ var LazyInvokeStep = class extends BaseLazyStep {
1592
1591
  }
1593
1592
  };
1594
1593
 
1595
- // src/agents/constants.ts
1596
- var AGENT_NAME_HEADER = "upstash-agent-name";
1597
- var MANAGER_AGENT_PROMPT = `You are an agent orchestrating other AI Agents.
1598
-
1599
- These other agents have tools available to them.
1600
-
1601
- Given a prompt, utilize these agents to address requests.
1602
-
1603
- Don't always call all the agents provided to you at the same time. You can call one and use it's response to call another.
1604
-
1605
- Avoid calling the same agent twice in one turn. Instead, prefer to call it once but provide everything
1606
- you need from that agent.
1607
- `;
1608
-
1609
1594
  // src/qstash/headers.ts
1610
1595
  var WorkflowHeaders = class {
1611
1596
  userHeaders;
@@ -1654,8 +1639,7 @@ var WorkflowHeaders = class {
1654
1639
  [WORKFLOW_URL_HEADER]: this.workflowConfig.workflowUrl,
1655
1640
  [WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody,WF_DetectTrigger" + (this.keepTriggerConfig ? ",WF_TriggerOnConfig" : ""),
1656
1641
  [WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
1657
- ...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {},
1658
- ...this.workflowConfig.telemetry && this.stepInfo?.lazyStep instanceof LazyCallStep && this.stepInfo.lazyStep.headers[AGENT_NAME_HEADER] ? { [TELEMETRY_HEADER_AGENT]: "true" } : {}
1642
+ ...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {}
1659
1643
  };
1660
1644
  if (this.stepInfo?.lazyStep.stepType !== "Call") {
1661
1645
  this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
@@ -2318,309 +2302,6 @@ var WorkflowApi = class extends BaseWorkflowApi {
2318
2302
  }
2319
2303
  };
2320
2304
 
2321
- // src/agents/index.ts
2322
- var import_openai2 = require("@ai-sdk/openai");
2323
-
2324
- // src/agents/adapters.ts
2325
- var import_ai = require("ai");
2326
- var fetchWithContextCall = async (context, agentCallParams, ...params) => {
2327
- const [input, init] = params;
2328
- try {
2329
- const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
2330
- const body = init?.body ? JSON.parse(init.body) : void 0;
2331
- const agentName = headers[AGENT_NAME_HEADER];
2332
- const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
2333
- const responseInfo = await context.call(stepName, {
2334
- url: input.toString(),
2335
- method: init?.method,
2336
- headers,
2337
- body,
2338
- timeout: agentCallParams?.timeout,
2339
- retries: agentCallParams?.retries,
2340
- retryDelay: agentCallParams?.retryDelay,
2341
- flowControl: agentCallParams?.flowControl
2342
- });
2343
- const responseHeaders = new Headers(
2344
- Object.entries(responseInfo.header).reduce(
2345
- (acc, [key, values]) => {
2346
- acc[key] = values.join(", ");
2347
- return acc;
2348
- },
2349
- {}
2350
- )
2351
- );
2352
- return new Response(JSON.stringify(responseInfo.body), {
2353
- status: responseInfo.status,
2354
- headers: responseHeaders
2355
- });
2356
- } catch (error) {
2357
- if (error instanceof Error && isInstanceOf(error, WorkflowAbort)) {
2358
- throw error;
2359
- } else {
2360
- console.error("Error in fetch implementation:", error);
2361
- throw error;
2362
- }
2363
- }
2364
- };
2365
- var createWorkflowModel = ({
2366
- context,
2367
- provider,
2368
- providerParams,
2369
- agentCallParams
2370
- }) => {
2371
- return provider({
2372
- fetch: (...params) => fetchWithContextCall(context, agentCallParams, ...params),
2373
- ...providerParams
2374
- });
2375
- };
2376
- var wrapTools = ({
2377
- context,
2378
- tools
2379
- }) => {
2380
- return Object.fromEntries(
2381
- Object.entries(tools).map((toolInfo) => {
2382
- const [toolName, tool3] = toolInfo;
2383
- const executeAsStep = "executeAsStep" in tool3 ? tool3.executeAsStep : true;
2384
- const aiSDKTool = convertToAISDKTool(tool3);
2385
- const execute = aiSDKTool.execute;
2386
- if (execute && executeAsStep) {
2387
- const wrappedExecute = (...params) => {
2388
- return context.run(`Run tool ${toolName}`, () => execute(...params));
2389
- };
2390
- aiSDKTool.execute = wrappedExecute;
2391
- }
2392
- return [toolName, aiSDKTool];
2393
- })
2394
- );
2395
- };
2396
- var convertToAISDKTool = (tool3) => {
2397
- const isLangchainTool = "invoke" in tool3;
2398
- return isLangchainTool ? convertLangchainTool(tool3) : tool3;
2399
- };
2400
- var convertLangchainTool = (langchainTool) => {
2401
- return (0, import_ai.tool)({
2402
- description: langchainTool.description,
2403
- parameters: langchainTool.schema,
2404
- execute: async (...param) => langchainTool.invoke(...param)
2405
- });
2406
- };
2407
-
2408
- // src/agents/agent.ts
2409
- var import_zod = require("zod");
2410
- var import_ai2 = require("ai");
2411
-
2412
- // src/serve/utils.ts
2413
- var isDisabledWorkflowContext = (context) => {
2414
- return "disabled" in context;
2415
- };
2416
-
2417
- // src/agents/agent.ts
2418
- var Agent = class {
2419
- name;
2420
- tools;
2421
- maxSteps;
2422
- background;
2423
- model;
2424
- temparature;
2425
- context;
2426
- constructor({ tools, maxSteps, background, name, model, temparature = 0.1 }, context) {
2427
- this.name = name;
2428
- this.tools = tools ?? {};
2429
- this.maxSteps = maxSteps;
2430
- this.background = background;
2431
- this.model = model;
2432
- this.temparature = temparature;
2433
- this.context = context;
2434
- }
2435
- /**
2436
- * Trigger the agent by passing a prompt
2437
- *
2438
- * @param prompt task to assign to the agent
2439
- * @returns Response as `{ text: string }`
2440
- */
2441
- async call({ prompt }) {
2442
- try {
2443
- if (isDisabledWorkflowContext(this.context)) {
2444
- await this.context.sleep("abort", 0);
2445
- }
2446
- const result = await (0, import_ai2.generateText)({
2447
- model: this.model,
2448
- tools: this.tools,
2449
- maxSteps: this.maxSteps,
2450
- system: this.background,
2451
- prompt,
2452
- headers: {
2453
- [AGENT_NAME_HEADER]: this.name
2454
- },
2455
- temperature: this.temparature
2456
- });
2457
- return { text: result.text };
2458
- } catch (error) {
2459
- if (isInstanceOf(error, import_ai2.ToolExecutionError)) {
2460
- if (error.cause instanceof Error && isInstanceOf(error.cause, WorkflowAbort)) {
2461
- throw error.cause;
2462
- } else if (isInstanceOf(error.cause, import_ai2.ToolExecutionError) && isInstanceOf(error.cause.cause, WorkflowAbort)) {
2463
- throw error.cause.cause;
2464
- } else {
2465
- throw error;
2466
- }
2467
- } else {
2468
- throw error;
2469
- }
2470
- }
2471
- }
2472
- /**
2473
- * Convert the agent to a tool which can be used by other agents.
2474
- *
2475
- * @returns the agent as a tool
2476
- */
2477
- asTool() {
2478
- const toolDescriptions = Object.values(this.tools).map((tool3) => tool3.description).join("\n");
2479
- return (0, import_ai2.tool)({
2480
- parameters: import_zod.z.object({ prompt: import_zod.z.string() }),
2481
- execute: async ({ prompt }) => {
2482
- return await this.call({ prompt });
2483
- },
2484
- description: `An AI Agent with the following background: ${this.background}Has access to the following tools: ${toolDescriptions}`
2485
- });
2486
- }
2487
- };
2488
- var ManagerAgent = class extends Agent {
2489
- agents;
2490
- /**
2491
- * A manager agent which coordinates agents available to it to achieve a
2492
- * given task
2493
- *
2494
- * @param name Name of the agent
2495
- * @param background Background of the agent. If not passed, default will be used.
2496
- * @param model LLM model to use
2497
- * @param agents: List of agents available to the agent
2498
- * @param maxSteps number of times the manager agent can call the LLM at most.
2499
- * If the agent abruptly stops execution after calling other agents, you may
2500
- * need to increase maxSteps
2501
- */
2502
- constructor({
2503
- agents,
2504
- background = MANAGER_AGENT_PROMPT,
2505
- model,
2506
- maxSteps,
2507
- name = "manager llm"
2508
- }, context) {
2509
- super(
2510
- {
2511
- background,
2512
- maxSteps,
2513
- tools: Object.fromEntries(agents.map((agent) => [agent.name, agent.asTool()])),
2514
- name,
2515
- model
2516
- },
2517
- context
2518
- );
2519
- this.agents = agents;
2520
- }
2521
- };
2522
-
2523
- // src/agents/task.ts
2524
- var Task = class {
2525
- context;
2526
- taskParameters;
2527
- constructor({
2528
- context,
2529
- taskParameters
2530
- }) {
2531
- this.context = context;
2532
- this.taskParameters = taskParameters;
2533
- }
2534
- /**
2535
- * Run the agents to complete the task
2536
- *
2537
- * @returns Result of the task as { text: string }
2538
- */
2539
- async run() {
2540
- const { prompt, ...otherParams } = this.taskParameters;
2541
- if ("agent" in otherParams) {
2542
- const agent = otherParams.agent;
2543
- const result = await agent.call({
2544
- prompt
2545
- });
2546
- return { text: result.text };
2547
- } else {
2548
- const { agents, maxSteps, model, background } = otherParams;
2549
- const managerAgent = new ManagerAgent(
2550
- {
2551
- model,
2552
- maxSteps,
2553
- agents,
2554
- name: "Manager LLM",
2555
- background
2556
- },
2557
- this.context
2558
- );
2559
- const result = await managerAgent.call({ prompt });
2560
- return { text: result.text };
2561
- }
2562
- }
2563
- };
2564
-
2565
- // src/agents/index.ts
2566
- var WorkflowAgents = class {
2567
- context;
2568
- constructor({ context }) {
2569
- this.context = context;
2570
- }
2571
- /**
2572
- * Defines an agent
2573
- *
2574
- * ```ts
2575
- * const researcherAgent = context.agents.agent({
2576
- * model,
2577
- * name: 'academic',
2578
- * maxSteps: 2,
2579
- * tools: {
2580
- * wikiTool: new WikipediaQueryRun({
2581
- * topKResults: 1,
2582
- * maxDocContentLength: 500,
2583
- * })
2584
- * },
2585
- * background:
2586
- * 'You are researcher agent with access to Wikipedia. ' +
2587
- * 'Utilize Wikipedia as much as possible for correct information',
2588
- * });
2589
- * ```
2590
- *
2591
- * @param params agent parameters
2592
- * @returns
2593
- */
2594
- agent(params) {
2595
- const wrappedTools = wrapTools({ context: this.context, tools: params.tools });
2596
- return new Agent(
2597
- {
2598
- ...params,
2599
- tools: wrappedTools
2600
- },
2601
- this.context
2602
- );
2603
- }
2604
- task(taskParameters) {
2605
- return new Task({ context: this.context, taskParameters });
2606
- }
2607
- /**
2608
- * creates an openai model for agents
2609
- */
2610
- openai(...params) {
2611
- const [model, settings] = params;
2612
- const { baseURL, apiKey, callSettings, ...otherSettings } = settings ?? {};
2613
- const openaiModel = this.AISDKModel({
2614
- context: this.context,
2615
- provider: import_openai2.createOpenAI,
2616
- providerParams: { baseURL, apiKey, compatibility: "strict" },
2617
- agentCallParams: callSettings
2618
- });
2619
- return openaiModel(model, otherSettings);
2620
- }
2621
- AISDKModel = createWorkflowModel;
2622
- };
2623
-
2624
2305
  // src/serve/serve-many.ts
2625
2306
  var getWorkflowId = (url) => {
2626
2307
  const components = url.split("/");
@@ -2929,7 +2610,7 @@ var WorkflowContext = class {
2929
2610
  * @returns result of the step function
2930
2611
  */
2931
2612
  async run(stepName, stepFunction) {
2932
- const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
2613
+ const wrappedStepFunction = (() => this.executor.wrapStep(stepName, stepFunction));
2933
2614
  return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2934
2615
  }
2935
2616
  /**
@@ -3100,11 +2781,6 @@ var WorkflowContext = class {
3100
2781
  context: this
3101
2782
  });
3102
2783
  }
3103
- get agents() {
3104
- return new WorkflowAgents({
3105
- context: this
3106
- });
3107
- }
3108
2784
  };
3109
2785
 
3110
2786
  // src/logger.ts
package/nextjs.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-BON2RKOR.mjs";
5
+ } from "./chunk-AGYYZKP7.mjs";
6
6
 
7
7
  // platforms/nextjs.ts
8
8
  var appTelemetry = {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@upstash/workflow","version":"v0.2.22","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"},"./tanstack":{"import":"./tanstack.mjs","require":"./tanstack.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@ai-sdk/anthropic":"^1.1.15","@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@tanstack/react-start":"^1.132.48","@types/bun":"^1.1.10","@types/express":"^5.0.3","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^5.1.0","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.2.1","@upstash/qstash":"^2.8.2","ai":"^4.1.54","zod":"^3.24.1"},"directories":{"example":"examples"}}
1
+ {"name":"@upstash/workflow","version":"v0.3.0-rc","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"},"./tanstack":{"import":"./tanstack.mjs","require":"./tanstack.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.3","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^5.1.0","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@upstash/qstash":"^2.8.4"},"directories":{"example":"examples"},"peerDependencies":{"zod":"^3.25.0 || ^4.0.0"}}
@@ -1,4 +1,4 @@
1
- import { o as PublicServeOptions, R as RouteFunction, z as InvokableWorkflow } from './types-9nCq6bRP.mjs';
1
+ import { n as PublicServeOptions, R as RouteFunction, y as InvokableWorkflow } from './types-DESkn7K9.mjs';
2
2
 
3
3
  type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
4
4
  declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<PublicServeOptions> = OmitOptionsInServeMany<PublicServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
@@ -1,4 +1,4 @@
1
- import { o as PublicServeOptions, R as RouteFunction, z as InvokableWorkflow } from './types-9nCq6bRP.js';
1
+ import { n as PublicServeOptions, R as RouteFunction, y as InvokableWorkflow } from './types-DESkn7K9.js';
2
2
 
3
3
  type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
4
4
  declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<PublicServeOptions> = OmitOptionsInServeMany<PublicServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
package/solidjs.d.mts CHANGED
@@ -1,9 +1,7 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, o as PublicServeOptions } from './types-9nCq6bRP.mjs';
2
+ import { R as RouteFunction, n as PublicServeOptions } from './types-DESkn7K9.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
- import 'ai';
6
- import '@ai-sdk/openai';
7
5
 
8
6
  /**
9
7
  * Serve method to serve a Upstash Workflow in a SolidJS project
package/solidjs.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, o as PublicServeOptions } from './types-9nCq6bRP.js';
2
+ import { R as RouteFunction, n as PublicServeOptions } from './types-DESkn7K9.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
- import 'ai';
6
- import '@ai-sdk/openai';
7
5
 
8
6
  /**
9
7
  * Serve method to serve a Upstash Workflow in a SolidJS project