Skip to content

Forward SDK Version to Callbacks #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions src/agents/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { WorkflowAgents } from ".";
import { tool } from "ai";
import { z } from "zod";
import { getAgentsApi } from "./task.test";
import { WORKFLOW_PROTOCOL_VERSION } from "../constants";

describe("agents", () => {
const openaiToken = nanoid();
Expand Down Expand Up @@ -105,6 +106,7 @@ describe("agents", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
Expand Down Expand Up @@ -172,6 +174,7 @@ describe("agents", () => {
"upstash-callback-forward-upstash-workflow-stepid": "2",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-retries": "5",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
Expand Down Expand Up @@ -238,6 +241,7 @@ describe("agents", () => {
"upstash-callback-forward-upstash-workflow-stepid": "3",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent manager llm",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-retries": "5",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
Expand Down
4 changes: 4 additions & 0 deletions src/agents/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WorkflowAgents } from ".";
import { tool } from "ai";
import { z } from "zod";
import { DisabledWorkflowContext } from "../serve/authorization";
import { WORKFLOW_PROTOCOL_VERSION } from "../constants";
import { createAnthropic } from "@ai-sdk/anthropic";
import { createOpenAI } from "@ai-sdk/openai";

Expand Down Expand Up @@ -118,6 +119,7 @@ describe("tasks", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent my agent",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
Expand Down Expand Up @@ -196,6 +198,7 @@ describe("tasks", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "Call Agent Manager LLM",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": workflowRunId,
Expand Down Expand Up @@ -262,6 +265,7 @@ describe("tasks", () => {
"upstash-callback-feature-set": "LazyFetch,InitialBody",
"upstash-callback-forward-upstash-workflow-callback": "true",
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-sdk-version": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
Expand Down
14 changes: 10 additions & 4 deletions src/context/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ describe("context tests", () => {
"application/x-www-form-urlencoded",
"upstash-callback-forward-upstash-workflow-invoke-count": "7",
"upstash-forward-upstash-workflow-invoke-count": "7",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "my-step",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
Expand Down Expand Up @@ -393,6 +394,7 @@ describe("context tests", () => {
"upstash-callback-forward-upstash-workflow-callback": "true",
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "my-step",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
Expand Down Expand Up @@ -557,6 +559,7 @@ describe("context tests", () => {
"upstash-callback-forward-upstash-workflow-callback": "true",
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": stepName,
"upstash-callback-forward-upstash-workflow-steptype": "Call",
Expand Down Expand Up @@ -640,11 +643,11 @@ describe("context tests", () => {
"upstash-callback-forward-upstash-workflow-callback": "true",
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-invoke-count": "5",
"upstash-forward-upstash-workflow-invoke-count": "5",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": stepName,
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "5",
"upstash-callback-retries": "2",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
Expand All @@ -653,6 +656,7 @@ describe("context tests", () => {
"upstash-feature-set": "WF_NoDelete,InitialBody",
"upstash-forward-authorization": `Bearer ${openAIToken}`,
"upstash-forward-content-type": "application/json",
"upstash-forward-upstash-workflow-invoke-count": "5",
"upstash-method": "POST",
"upstash-retries": "0",
"upstash-workflow-calltype": "toCallback",
Expand Down Expand Up @@ -721,6 +725,7 @@ describe("context tests", () => {
"upstash-callback-forward-upstash-workflow-callback": "true",
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": stepName,
"upstash-callback-forward-upstash-workflow-steptype": "Call",
Expand Down Expand Up @@ -811,11 +816,11 @@ describe("context tests", () => {
"upstash-callback-forward-upstash-workflow-callback": "true",
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-invoke-count": "3",
"upstash-forward-upstash-workflow-invoke-count": "3",
"upstash-callback-forward-upstash-workflow-sdk-version": WORKFLOW_PROTOCOL_VERSION,
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": stepName,
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-invoke-count": "3",
"upstash-callback-retries": "2",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
Expand All @@ -825,6 +830,7 @@ describe("context tests", () => {
"upstash-forward-x-api-key": anthropicToken,
"upstash-forward-anthropic-version": "2023-06-01",
"upstash-forward-content-type": "application/json",
"upstash-forward-upstash-workflow-invoke-count": "3",
"upstash-method": method,
"upstash-retries": "0",
"upstash-workflow-calltype": "toCallback",
Expand Down
9 changes: 8 additions & 1 deletion src/context/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import { WorkflowError } from "../error";
import { getWorkflowRunId } from "../utils";
import { WorkflowContext } from "./context";
import { getHeaders, prepareFlowControl } from "../qstash/headers";
import { WORKFLOW_FEATURE_HEADER, WORKFLOW_INIT_HEADER, WORKFLOW_URL_HEADER } from "../constants";
import {
WORKFLOW_FEATURE_HEADER,
WORKFLOW_INIT_HEADER,
WORKFLOW_PROTOCOL_VERSION,
WORKFLOW_PROTOCOL_VERSION_HEADER,
WORKFLOW_URL_HEADER,
} from "../constants";
import { getTelemetryHeaders, HeadersResponse } from "../workflow-requests";

type StepParams = { context: WorkflowContext } & Pick<HeaderParams, "telemetry"> &
Expand Down Expand Up @@ -450,6 +456,7 @@ export class LazyCallStep<TResult = unknown, TBody = unknown> extends BaseLazySt
"Upstash-Callback-Workflow-Url": context.url,
"Upstash-Callback-Feature-Set": "LazyFetch,InitialBody",

[`Upstash-Callback-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`]: WORKFLOW_PROTOCOL_VERSION,
"Upstash-Callback-Forward-Upstash-Workflow-Callback": "true",
"Upstash-Callback-Forward-Upstash-Workflow-StepId": step.stepId.toString(),
"Upstash-Callback-Forward-Upstash-Workflow-StepName": this.stepName,
Expand Down
1 change: 1 addition & 0 deletions src/serve/serve-many.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ describe("serveMany", () => {
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-stepname": "call other workflow",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-forward-upstash-workflow-sdk-version": "1",
"upstash-callback-workflow-calltype": "fromCallback",
"upstash-callback-workflow-init": "false",
"upstash-callback-workflow-runid": "wfr_id",
Expand Down
1 change: 1 addition & 0 deletions src/serve/serve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ describe("serve", () => {
"upstash-callback-forward-upstash-workflow-concurrent": "1",
"upstash-callback-forward-upstash-workflow-contenttype": "application/json",
"upstash-callback-forward-upstash-workflow-stepid": "1",
"upstash-callback-forward-upstash-workflow-sdk-version": "1",
"upstash-callback-forward-upstash-workflow-stepname": "call step",
"upstash-callback-forward-upstash-workflow-steptype": "Call",
"upstash-callback-retries": "2",
Expand Down
1 change: 1 addition & 0 deletions src/workflow-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ describe("Workflow Requests", () => {
"Upstash-Callback-Forward-Upstash-Workflow-StepId": stepId.toString(),
"Upstash-Callback-Forward-Upstash-Workflow-StepName": stepName,
"Upstash-Callback-Forward-Upstash-Workflow-StepType": "Call",
"Upstash-Callback-Forward-Upstash-Workflow-Sdk-Version": WORKFLOW_PROTOCOL_VERSION,
"Upstash-Callback-Workflow-CallType": "fromCallback",
"Upstash-Callback-Workflow-RunId": workflowRunId,
"Upstash-Callback-Workflow-Init": "false",
Expand Down
Loading