@amaster.ai/workflow-client 1.1.44 → 1.1.45-beta.1
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.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","isWorkflowRunRequest","req","value","requestKeys","structuralRequestKeys","keys","key","validateWorkflowName","workflowName","applyEnvToRequest","request","env","createWorkflowClient","http","createHttpClient","options","validationError","normalizedRequest","response","innerData","asyncRunId","workflowRunId"],"mappings":"+DAiJA,SAASA,EACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,EACH,OAAO,CAAE,MAAA,CAAQ,GAAI,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,EAGpE,GAAI,OAAOA,CAAAA,EAAW,QAAA,EAAYC,EAAqBD,CAAM,CAAA,CAAG,CAC9D,IAAME,EAAMF,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQE,EAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UAAA,CACpC,IAAA,CAAMA,EAAI,IAAA,EAAQ,WAAA,CAClB,KAAA,CAAOA,CAAAA,CAAI,MACX,QAAA,CAAUA,CAAAA,CAAI,QAAA,CACd,KAAA,CAAOA,EAAI,KAAA,CACX,YAAA,CAAcA,CAAAA,CAAI,YAAA,CAClB,SAAUA,CAAAA,CAAI,QAChB,CACF,CAEA,OAAO,CACL,MAAA,CAAQF,CAAAA,CACR,aAAA,CAAe,WACf,IAAA,CAAM,WACR,CACF,CAEA,SAASC,CAAAA,CAAqBE,CAAAA,CAAyC,CACrE,IAAMC,CAAAA,CAAc,CAAC,QAAA,CAAU,eAAA,CAAiB,OAAQ,OAAA,CAAS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CAAcA,CAAAA,CAAU,cAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,EACtC,UAAA,CAAYA,CAAAA,CAAU,UAAA,EAAc,CAAA,CACpC,YAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,GAAIA,EAAU,KAAA,CAAQ,CAAE,KAAA,CAAOA,CAAAA,CAAU,KAAM,CAAA,CAAI,EACrD,CACF,CACF,CAEA,OAAO,CACL,IAAA,CAAM,KACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,OAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,gDACX,EACA,MAAA,CAAQA,CAAAA,CAAS,MACnB,CACF,CACF,CACF","file":"index.cjs","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\n\nexport type WorkflowResponseMode = \"blocking\" | \"streaming\" | \"async\";\n\nexport type WorkflowInputValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | Record<string, unknown>\n | unknown[];\n\nexport type WorkflowFile = {\n name?: string;\n type?: string;\n url?: string;\n [key: string]: unknown;\n};\n\nexport type WorkflowRunRequest = {\n inputs?: Record<string, WorkflowInputValue>;\n response_mode?: WorkflowResponseMode;\n user?: string;\n files?: WorkflowFile[];\n trace_id?: string;\n usage?: boolean;\n usage_detail?: boolean;\n callback?: WorkflowCallbackConfig;\n};\n\nexport type WorkflowCallbackConfig = {\n name?: string;\n include_outputs?: boolean;\n include_usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowUsageSummary = {\n workflow_run_id: string;\n status: string;\n total_tokens: number;\n total_steps: number;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n is_finished: boolean;\n};\n\nexport type WorkflowNodeUsage = {\n id: string;\n node_execution_id: string | null;\n index: number;\n node_id: string;\n node_type: string;\n title: string;\n status: string;\n error: string | null;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n usage: Record<string, unknown>;\n execution_metadata: Record<string, unknown>;\n};\n\nexport type WorkflowRunUsage = {\n summary: WorkflowUsageSummary;\n estimated_price_by_currency?: Record<string, string>;\n nodes?: WorkflowNodeUsage[];\n};\n\nexport type WorkflowRunResponse<TOutput = Record<string, unknown>> = {\n task_id: string;\n workflow_run_id: string;\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n};\n\nexport type WorkflowAsyncRunStatus =\n | \"pending\"\n | \"queued\"\n | \"running\"\n | \"succeeded\"\n | \"failed\"\n | \"paused\"\n | \"rate_limited\"\n | \"retrying\"\n | string;\n\nexport type WorkflowAsyncRunResponse = {\n async_run_id: string;\n workflow_trigger_log_id: string;\n workflow_run_id: string | null;\n task_id?: string;\n status: WorkflowAsyncRunStatus;\n queue?: string;\n created_at?: number | null;\n};\n\nexport type WorkflowAsyncRunDetailResponse = WorkflowAsyncRunResponse & {\n workflow_id?: string;\n error?: string | null;\n outputs?: Record<string, unknown> | null;\n elapsed_time?: number | null;\n total_tokens?: number | null;\n triggered_at?: number | null;\n finished_at?: number | null;\n};\n\nexport type WorkflowRunDetailOptions = {\n usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowClient = {\n run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>>;\n getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>>;\n getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options?: WorkflowRunDetailOptions\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n};\n\nexport type WorkflowClientOptions = {\n env?: string;\n};\n\nfunction normalizeRunRequest(\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n): WorkflowRunRequest {\n if (!inputs) {\n return { inputs: {}, response_mode: \"blocking\", user: \"anonymous\" };\n }\n\n if (typeof inputs === \"object\" && isWorkflowRunRequest(inputs)) {\n const req = inputs as WorkflowRunRequest;\n return {\n inputs: req.inputs || {},\n response_mode: req.response_mode || \"blocking\",\n user: req.user || \"anonymous\",\n files: req.files,\n trace_id: req.trace_id,\n usage: req.usage,\n usage_detail: req.usage_detail,\n callback: req.callback,\n };\n }\n\n return {\n inputs: inputs as Record<string, WorkflowInputValue>,\n response_mode: \"blocking\",\n user: \"anonymous\",\n };\n}\n\nfunction isWorkflowRunRequest(value: Record<string, unknown>): boolean {\n const requestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\", \"usage\", \"usage_detail\", \"callback\"];\n const structuralRequestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\"];\n const keys = Object.keys(value);\n\n if (structuralRequestKeys.some((key) => key in value)) {\n return true;\n }\n\n return keys.length > 0 && keys.every((key) => requestKeys.includes(key));\n}\n\nfunction validateWorkflowName(workflowName: string): ClientResult<never> | null {\n if (!workflowName || workflowName.includes(\"/\")) {\n return {\n data: null,\n error: {\n status: 400,\n message:\n \"Invalid workflowName: use workflow YAML filename without extension (no subpaths)\",\n },\n status: 400,\n };\n }\n return null;\n}\n\nfunction applyEnvToRequest(request: WorkflowRunRequest, env?: string): WorkflowRunRequest {\n if (!request.inputs) {\n request.inputs = {};\n }\n if (env && request.inputs.env === undefined) {\n request.inputs.env = env;\n }\n return request;\n}\n\nexport function createWorkflowClient(\n http: HttpClient = createHttpClient(),\n options: WorkflowClientOptions = {}\n): WorkflowClient {\n const { env } = options;\n\n return {\n async run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n\n // Workflow callers can now provide env through createWorkflowClient so\n // downstream workflows can wire environment-aware behavior directly from\n // the runtime context.\n\n const response = await http.request<{\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n task_id: string;\n workflow_run_id: string;\n }>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: response.data.task_id || \"\",\n workflow_run_id: response.data.workflow_run_id || \"\",\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow response structure\",\n },\n status: response.status,\n };\n },\n async runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n normalizedRequest.response_mode = \"async\";\n\n const response = await http.request<WorkflowAsyncRunResponse>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run response structure\",\n },\n status: response.status,\n };\n },\n async getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<WorkflowAsyncRunDetailResponse>({\n url: `/api/runworkflow/${workflowName}/async-runs/${asyncRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run detail response structure\",\n },\n status: response.status,\n };\n },\n async getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options: WorkflowRunDetailOptions = {}\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<{\n workflow_run_id: string;\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n }>({\n url: `/api/runworkflow/${workflowName}/runs/${workflowRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n params: {\n ...(options.usage !== undefined ? { usage: options.usage } : {}),\n ...(options.usage_detail !== undefined ? { usage_detail: options.usage_detail } : {}),\n },\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: \"\",\n workflow_run_id: response.data.workflow_run_id || workflowRunId,\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow run detail response structure\",\n },\n status: response.status,\n };\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","isWorkflowRunRequest","req","value","requestKeys","structuralRequestKeys","keys","key","validateWorkflowName","workflowName","applyEnvToRequest","request","env","createWorkflowClient","http","createHttpClient","options","validationError","normalizedRequest","response","innerData","asyncRunId","workflowRunId"],"mappings":"+DAoJA,SAASA,EACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,EACH,OAAO,CAAE,MAAA,CAAQ,GAAI,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,EAGpE,GAAI,OAAOA,CAAAA,EAAW,QAAA,EAAYC,EAAqBD,CAAM,CAAA,CAAG,CAC9D,IAAME,EAAMF,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQE,EAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UAAA,CACpC,IAAA,CAAMA,EAAI,IAAA,EAAQ,WAAA,CAClB,KAAA,CAAOA,CAAAA,CAAI,MACX,QAAA,CAAUA,CAAAA,CAAI,QAAA,CACd,KAAA,CAAOA,EAAI,KAAA,CACX,YAAA,CAAcA,CAAAA,CAAI,YAAA,CAClB,SAAUA,CAAAA,CAAI,QAChB,CACF,CAEA,OAAO,CACL,MAAA,CAAQF,CAAAA,CACR,aAAA,CAAe,WACf,IAAA,CAAM,WACR,CACF,CAEA,SAASC,CAAAA,CAAqBE,CAAAA,CAAyC,CACrE,IAAMC,CAAAA,CAAc,CAAC,QAAA,CAAU,eAAA,CAAiB,OAAQ,OAAA,CAAS,UAAA,CAAY,OAAA,CAAS,cAAA,CAAgB,UAAU,CAAA,CAC1GC,CAAAA,CAAwB,CAAC,QAAA,CAAU,gBAAiB,MAAA,CAAQ,OAAA,CAAS,UAA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CACpC,YAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,GAAIA,EAAU,KAAA,CAAQ,CAAE,KAAA,CAAOA,CAAAA,CAAU,KAAM,CAAA,CAAI,EACrD,CACF,CACF,CAEA,OAAO,CACL,IAAA,CAAM,KACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,OAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,gDACX,EACA,MAAA,CAAQA,CAAAA,CAAS,MACnB,CACF,CACF,CACF","file":"index.cjs","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\n\nexport type WorkflowResponseMode = \"blocking\" | \"streaming\" | \"async\";\n\nexport type WorkflowInputValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | Record<string, unknown>\n | unknown[];\n\nexport type WorkflowFile = {\n name?: string;\n type?: string;\n url?: string;\n [key: string]: unknown;\n};\n\nexport type WorkflowRunRequest = {\n inputs?: Record<string, WorkflowInputValue>;\n response_mode?: WorkflowResponseMode;\n user?: string;\n files?: WorkflowFile[];\n trace_id?: string;\n usage?: boolean;\n usage_detail?: boolean;\n callback?: WorkflowCallbackConfig;\n};\n\nexport type WorkflowCallbackConfig = {\n name?: string;\n include_outputs?: boolean;\n include_usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowUsageSummary = {\n workflow_run_id: string;\n status: string;\n total_tokens: number;\n workflow_run_total_tokens?: number;\n node_usage_total_tokens?: number;\n billable_total_tokens?: number;\n total_steps: number;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n is_finished: boolean;\n};\n\nexport type WorkflowNodeUsage = {\n id: string;\n node_execution_id: string | null;\n index: number;\n node_id: string;\n node_type: string;\n title: string;\n status: string;\n error: string | null;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n usage: Record<string, unknown>;\n execution_metadata: Record<string, unknown>;\n};\n\nexport type WorkflowRunUsage = {\n summary: WorkflowUsageSummary;\n estimated_price_by_currency?: Record<string, string>;\n nodes?: WorkflowNodeUsage[];\n};\n\nexport type WorkflowRunResponse<TOutput = Record<string, unknown>> = {\n task_id: string;\n workflow_run_id: string;\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n};\n\nexport type WorkflowAsyncRunStatus =\n | \"pending\"\n | \"queued\"\n | \"running\"\n | \"succeeded\"\n | \"failed\"\n | \"paused\"\n | \"rate_limited\"\n | \"retrying\"\n | string;\n\nexport type WorkflowAsyncRunResponse = {\n async_run_id: string;\n workflow_trigger_log_id: string;\n workflow_run_id: string | null;\n task_id?: string;\n status: WorkflowAsyncRunStatus;\n queue?: string;\n created_at?: number | null;\n};\n\nexport type WorkflowAsyncRunDetailResponse = WorkflowAsyncRunResponse & {\n workflow_id?: string;\n error?: string | null;\n outputs?: Record<string, unknown> | null;\n elapsed_time?: number | null;\n total_tokens?: number | null;\n triggered_at?: number | null;\n finished_at?: number | null;\n};\n\nexport type WorkflowRunDetailOptions = {\n usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowClient = {\n run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>>;\n getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>>;\n getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options?: WorkflowRunDetailOptions\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n};\n\nexport type WorkflowClientOptions = {\n env?: string;\n};\n\nfunction normalizeRunRequest(\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n): WorkflowRunRequest {\n if (!inputs) {\n return { inputs: {}, response_mode: \"blocking\", user: \"anonymous\" };\n }\n\n if (typeof inputs === \"object\" && isWorkflowRunRequest(inputs)) {\n const req = inputs as WorkflowRunRequest;\n return {\n inputs: req.inputs || {},\n response_mode: req.response_mode || \"blocking\",\n user: req.user || \"anonymous\",\n files: req.files,\n trace_id: req.trace_id,\n usage: req.usage,\n usage_detail: req.usage_detail,\n callback: req.callback,\n };\n }\n\n return {\n inputs: inputs as Record<string, WorkflowInputValue>,\n response_mode: \"blocking\",\n user: \"anonymous\",\n };\n}\n\nfunction isWorkflowRunRequest(value: Record<string, unknown>): boolean {\n const requestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\", \"usage\", \"usage_detail\", \"callback\"];\n const structuralRequestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\"];\n const keys = Object.keys(value);\n\n if (structuralRequestKeys.some((key) => key in value)) {\n return true;\n }\n\n return keys.length > 0 && keys.every((key) => requestKeys.includes(key));\n}\n\nfunction validateWorkflowName(workflowName: string): ClientResult<never> | null {\n if (!workflowName || workflowName.includes(\"/\")) {\n return {\n data: null,\n error: {\n status: 400,\n message:\n \"Invalid workflowName: use workflow YAML filename without extension (no subpaths)\",\n },\n status: 400,\n };\n }\n return null;\n}\n\nfunction applyEnvToRequest(request: WorkflowRunRequest, env?: string): WorkflowRunRequest {\n if (!request.inputs) {\n request.inputs = {};\n }\n if (env && request.inputs.env === undefined) {\n request.inputs.env = env;\n }\n return request;\n}\n\nexport function createWorkflowClient(\n http: HttpClient = createHttpClient(),\n options: WorkflowClientOptions = {}\n): WorkflowClient {\n const { env } = options;\n\n return {\n async run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n\n // Workflow callers can now provide env through createWorkflowClient so\n // downstream workflows can wire environment-aware behavior directly from\n // the runtime context.\n\n const response = await http.request<{\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n task_id: string;\n workflow_run_id: string;\n }>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: response.data.task_id || \"\",\n workflow_run_id: response.data.workflow_run_id || \"\",\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow response structure\",\n },\n status: response.status,\n };\n },\n async runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n normalizedRequest.response_mode = \"async\";\n\n const response = await http.request<WorkflowAsyncRunResponse>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run response structure\",\n },\n status: response.status,\n };\n },\n async getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<WorkflowAsyncRunDetailResponse>({\n url: `/api/runworkflow/${workflowName}/async-runs/${asyncRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run detail response structure\",\n },\n status: response.status,\n };\n },\n async getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options: WorkflowRunDetailOptions = {}\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<{\n workflow_run_id: string;\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n }>({\n url: `/api/runworkflow/${workflowName}/runs/${workflowRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n params: {\n ...(options.usage !== undefined ? { usage: options.usage } : {}),\n ...(options.usage_detail !== undefined ? { usage_detail: options.usage_detail } : {}),\n },\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: \"\",\n workflow_run_id: response.data.workflow_run_id || workflowRunId,\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow run detail response structure\",\n },\n status: response.status,\n };\n },\n };\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -28,6 +28,9 @@ type WorkflowUsageSummary = {
|
|
|
28
28
|
workflow_run_id: string;
|
|
29
29
|
status: string;
|
|
30
30
|
total_tokens: number;
|
|
31
|
+
workflow_run_total_tokens?: number;
|
|
32
|
+
node_usage_total_tokens?: number;
|
|
33
|
+
billable_total_tokens?: number;
|
|
31
34
|
total_steps: number;
|
|
32
35
|
elapsed_time: number;
|
|
33
36
|
created_at: number | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ type WorkflowUsageSummary = {
|
|
|
28
28
|
workflow_run_id: string;
|
|
29
29
|
status: string;
|
|
30
30
|
total_tokens: number;
|
|
31
|
+
workflow_run_total_tokens?: number;
|
|
32
|
+
node_usage_total_tokens?: number;
|
|
33
|
+
billable_total_tokens?: number;
|
|
31
34
|
total_steps: number;
|
|
32
35
|
elapsed_time: number;
|
|
33
36
|
created_at: number | null;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","isWorkflowRunRequest","req","value","requestKeys","structuralRequestKeys","keys","key","validateWorkflowName","workflowName","applyEnvToRequest","request","env","createWorkflowClient","http","createHttpClient","options","validationError","normalizedRequest","response","innerData","asyncRunId","workflowRunId"],"mappings":"uDAiJA,SAASA,EACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,EACH,OAAO,CAAE,MAAA,CAAQ,GAAI,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,EAGpE,GAAI,OAAOA,CAAAA,EAAW,QAAA,EAAYC,EAAqBD,CAAM,CAAA,CAAG,CAC9D,IAAME,EAAMF,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQE,EAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UA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A,CAED,GAAIG,CAAAA,CAAS,IAAA,EAAM,KAAM,CACvB,IAAMC,CAAAA,CAAYD,CAAAA,CAAS,KAAK,IAAA,CAChC,OAAO,CACL,GAAGA,CAAAA,CACH,IAAA,CAAM,CACJ,OAAA,CAAS,GACT,eAAA,CAAiBA,CAAAA,CAAS,IAAA,CAAK,eAAA,EAAmBG,EAClD,MAAA,CAAQF,CAAAA,CAAU,MAAA,EAAU,SAAA,CAC5B,QAASA,CAAAA,CAAU,OAAA,EAAY,EAAC,CAChC,MAAOA,CAAAA,CAAU,KAAA,EAAS,IAAA,CAC1B,YAAA,CAAcA,EAAU,YAAA,EAAgB,CAAA,CACxC,YAAA,CAAcA,CAAAA,CAAU,cAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,EACtC,UAAA,CAAYA,CAAAA,CAAU,UAAA,EAAc,CAAA,CACpC,YAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,GAAIA,EAAU,KAAA,CAAQ,CAAE,KAAA,CAAOA,CAAAA,CAAU,KAAM,CAAA,CAAI,EACrD,CACF,CACF,CAEA,OAAO,CACL,IAAA,CAAM,KACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,OAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,gDACX,EACA,MAAA,CAAQA,CAAAA,CAAS,MACnB,CACF,CACF,CACF","file":"index.js","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\n\nexport type WorkflowResponseMode = \"blocking\" | \"streaming\" | \"async\";\n\nexport type WorkflowInputValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | Record<string, unknown>\n | unknown[];\n\nexport type WorkflowFile = {\n name?: string;\n type?: string;\n url?: string;\n [key: string]: unknown;\n};\n\nexport type WorkflowRunRequest = {\n inputs?: Record<string, WorkflowInputValue>;\n response_mode?: WorkflowResponseMode;\n user?: string;\n files?: WorkflowFile[];\n trace_id?: string;\n usage?: boolean;\n usage_detail?: boolean;\n callback?: WorkflowCallbackConfig;\n};\n\nexport type WorkflowCallbackConfig = {\n name?: string;\n include_outputs?: boolean;\n include_usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowUsageSummary = {\n workflow_run_id: string;\n status: string;\n total_tokens: number;\n total_steps: number;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n is_finished: boolean;\n};\n\nexport type WorkflowNodeUsage = {\n id: string;\n node_execution_id: string | null;\n index: number;\n node_id: string;\n node_type: string;\n title: string;\n status: string;\n error: string | null;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n usage: Record<string, unknown>;\n execution_metadata: Record<string, unknown>;\n};\n\nexport type WorkflowRunUsage = {\n summary: WorkflowUsageSummary;\n estimated_price_by_currency?: Record<string, string>;\n nodes?: WorkflowNodeUsage[];\n};\n\nexport type WorkflowRunResponse<TOutput = Record<string, unknown>> = {\n task_id: string;\n workflow_run_id: string;\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n};\n\nexport type WorkflowAsyncRunStatus =\n | \"pending\"\n | \"queued\"\n | \"running\"\n | \"succeeded\"\n | \"failed\"\n | \"paused\"\n | \"rate_limited\"\n | \"retrying\"\n | string;\n\nexport type WorkflowAsyncRunResponse = {\n async_run_id: string;\n workflow_trigger_log_id: string;\n workflow_run_id: string | null;\n task_id?: string;\n status: WorkflowAsyncRunStatus;\n queue?: string;\n created_at?: number | null;\n};\n\nexport type WorkflowAsyncRunDetailResponse = WorkflowAsyncRunResponse & {\n workflow_id?: string;\n error?: string | null;\n outputs?: Record<string, unknown> | null;\n elapsed_time?: number | null;\n total_tokens?: number | null;\n triggered_at?: number | null;\n finished_at?: number | null;\n};\n\nexport type WorkflowRunDetailOptions = {\n usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowClient = {\n run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>>;\n getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>>;\n getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options?: WorkflowRunDetailOptions\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n};\n\nexport type WorkflowClientOptions = {\n env?: string;\n};\n\nfunction normalizeRunRequest(\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n): WorkflowRunRequest {\n if (!inputs) {\n return { inputs: {}, response_mode: \"blocking\", user: \"anonymous\" };\n }\n\n if (typeof inputs === \"object\" && isWorkflowRunRequest(inputs)) {\n const req = inputs as WorkflowRunRequest;\n return {\n inputs: req.inputs || {},\n response_mode: req.response_mode || \"blocking\",\n user: req.user || \"anonymous\",\n files: req.files,\n trace_id: req.trace_id,\n usage: req.usage,\n usage_detail: req.usage_detail,\n callback: req.callback,\n };\n }\n\n return {\n inputs: inputs as Record<string, WorkflowInputValue>,\n response_mode: \"blocking\",\n user: \"anonymous\",\n };\n}\n\nfunction isWorkflowRunRequest(value: Record<string, unknown>): boolean {\n const requestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\", \"usage\", \"usage_detail\", \"callback\"];\n const structuralRequestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\"];\n const keys = Object.keys(value);\n\n if (structuralRequestKeys.some((key) => key in value)) {\n return true;\n }\n\n return keys.length > 0 && keys.every((key) => requestKeys.includes(key));\n}\n\nfunction validateWorkflowName(workflowName: string): ClientResult<never> | null {\n if (!workflowName || workflowName.includes(\"/\")) {\n return {\n data: null,\n error: {\n status: 400,\n message:\n \"Invalid workflowName: use workflow YAML filename without extension (no subpaths)\",\n },\n status: 400,\n };\n }\n return null;\n}\n\nfunction applyEnvToRequest(request: WorkflowRunRequest, env?: string): WorkflowRunRequest {\n if (!request.inputs) {\n request.inputs = {};\n }\n if (env && request.inputs.env === undefined) {\n request.inputs.env = env;\n }\n return request;\n}\n\nexport function createWorkflowClient(\n http: HttpClient = createHttpClient(),\n options: WorkflowClientOptions = {}\n): WorkflowClient {\n const { env } = options;\n\n return {\n async run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n\n // Workflow callers can now provide env through createWorkflowClient so\n // downstream workflows can wire environment-aware behavior directly from\n // the runtime context.\n\n const response = await http.request<{\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n task_id: string;\n workflow_run_id: string;\n }>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: response.data.task_id || \"\",\n workflow_run_id: response.data.workflow_run_id || \"\",\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow response structure\",\n },\n status: response.status,\n };\n },\n async runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n normalizedRequest.response_mode = \"async\";\n\n const response = await http.request<WorkflowAsyncRunResponse>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run response structure\",\n },\n status: response.status,\n };\n },\n async getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<WorkflowAsyncRunDetailResponse>({\n url: `/api/runworkflow/${workflowName}/async-runs/${asyncRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run detail response structure\",\n },\n status: response.status,\n };\n },\n async getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options: WorkflowRunDetailOptions = {}\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<{\n workflow_run_id: string;\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n }>({\n url: `/api/runworkflow/${workflowName}/runs/${workflowRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n params: {\n ...(options.usage !== undefined ? { usage: options.usage } : {}),\n ...(options.usage_detail !== undefined ? { usage_detail: options.usage_detail } : {}),\n },\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: \"\",\n workflow_run_id: response.data.workflow_run_id || workflowRunId,\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow run detail response structure\",\n },\n status: response.status,\n };\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","isWorkflowRunRequest","req","value","requestKeys","structuralRequestKeys","keys","key","validateWorkflowName","workflowName","applyEnvToRequest","request","env","createWorkflowClient","http","createHttpClient","options","validationError","normalizedRequest","response","innerData","asyncRunId","workflowRunId"],"mappings":"uDAoJA,SAASA,EACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,EACH,OAAO,CAAE,MAAA,CAAQ,GAAI,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,EAGpE,GAAI,OAAOA,CAAAA,EAAW,QAAA,EAAYC,EAAqBD,CAAM,CAAA,CAAG,CAC9D,IAAME,EAAMF,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQE,EAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UAAA,CACpC,IAAA,CAAMA,EAAI,IAAA,EAAQ,WAAA,CAClB,KAAA,CAAOA,CAAAA,CAAI,MACX,QAAA,CAAUA,CAAAA,CAAI,QAAA,CACd,KAAA,CA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ACH,IAAA,CAAM,CACJ,OAAA,CAAS,GACT,eAAA,CAAiBA,CAAAA,CAAS,IAAA,CAAK,eAAA,EAAmBG,EAClD,MAAA,CAAQF,CAAAA,CAAU,MAAA,EAAU,SAAA,CAC5B,QAASA,CAAAA,CAAU,OAAA,EAAY,EAAC,CAChC,MAAOA,CAAAA,CAAU,KAAA,EAAS,IAAA,CAC1B,YAAA,CAAcA,EAAU,YAAA,EAAgB,CAAA,CACxC,YAAA,CAAcA,CAAAA,CAAU,cAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,EACtC,UAAA,CAAYA,CAAAA,CAAU,UAAA,EAAc,CAAA,CACpC,YAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,GAAIA,EAAU,KAAA,CAAQ,CAAE,KAAA,CAAOA,CAAAA,CAAU,KAAM,CAAA,CAAI,EACrD,CACF,CACF,CAEA,OAAO,CACL,IAAA,CAAM,KACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,OAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,gDACX,EACA,MAAA,CAAQA,CAAAA,CAAS,MACnB,CACF,CACF,CACF","file":"index.js","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\n\nexport type WorkflowResponseMode = \"blocking\" | \"streaming\" | \"async\";\n\nexport type WorkflowInputValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | Record<string, unknown>\n | unknown[];\n\nexport type WorkflowFile = {\n name?: string;\n type?: string;\n url?: string;\n [key: string]: unknown;\n};\n\nexport type WorkflowRunRequest = {\n inputs?: Record<string, WorkflowInputValue>;\n response_mode?: WorkflowResponseMode;\n user?: string;\n files?: WorkflowFile[];\n trace_id?: string;\n usage?: boolean;\n usage_detail?: boolean;\n callback?: WorkflowCallbackConfig;\n};\n\nexport type WorkflowCallbackConfig = {\n name?: string;\n include_outputs?: boolean;\n include_usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowUsageSummary = {\n workflow_run_id: string;\n status: string;\n total_tokens: number;\n workflow_run_total_tokens?: number;\n node_usage_total_tokens?: number;\n billable_total_tokens?: number;\n total_steps: number;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n is_finished: boolean;\n};\n\nexport type WorkflowNodeUsage = {\n id: string;\n node_execution_id: string | null;\n index: number;\n node_id: string;\n node_type: string;\n title: string;\n status: string;\n error: string | null;\n elapsed_time: number;\n created_at: number | null;\n finished_at: number | null;\n usage: Record<string, unknown>;\n execution_metadata: Record<string, unknown>;\n};\n\nexport type WorkflowRunUsage = {\n summary: WorkflowUsageSummary;\n estimated_price_by_currency?: Record<string, string>;\n nodes?: WorkflowNodeUsage[];\n};\n\nexport type WorkflowRunResponse<TOutput = Record<string, unknown>> = {\n task_id: string;\n workflow_run_id: string;\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n};\n\nexport type WorkflowAsyncRunStatus =\n | \"pending\"\n | \"queued\"\n | \"running\"\n | \"succeeded\"\n | \"failed\"\n | \"paused\"\n | \"rate_limited\"\n | \"retrying\"\n | string;\n\nexport type WorkflowAsyncRunResponse = {\n async_run_id: string;\n workflow_trigger_log_id: string;\n workflow_run_id: string | null;\n task_id?: string;\n status: WorkflowAsyncRunStatus;\n queue?: string;\n created_at?: number | null;\n};\n\nexport type WorkflowAsyncRunDetailResponse = WorkflowAsyncRunResponse & {\n workflow_id?: string;\n error?: string | null;\n outputs?: Record<string, unknown> | null;\n elapsed_time?: number | null;\n total_tokens?: number | null;\n triggered_at?: number | null;\n finished_at?: number | null;\n};\n\nexport type WorkflowRunDetailOptions = {\n usage?: boolean;\n usage_detail?: boolean;\n};\n\nexport type WorkflowClient = {\n run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>>;\n getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>>;\n getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options?: WorkflowRunDetailOptions\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;\n};\n\nexport type WorkflowClientOptions = {\n env?: string;\n};\n\nfunction normalizeRunRequest(\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n): WorkflowRunRequest {\n if (!inputs) {\n return { inputs: {}, response_mode: \"blocking\", user: \"anonymous\" };\n }\n\n if (typeof inputs === \"object\" && isWorkflowRunRequest(inputs)) {\n const req = inputs as WorkflowRunRequest;\n return {\n inputs: req.inputs || {},\n response_mode: req.response_mode || \"blocking\",\n user: req.user || \"anonymous\",\n files: req.files,\n trace_id: req.trace_id,\n usage: req.usage,\n usage_detail: req.usage_detail,\n callback: req.callback,\n };\n }\n\n return {\n inputs: inputs as Record<string, WorkflowInputValue>,\n response_mode: \"blocking\",\n user: \"anonymous\",\n };\n}\n\nfunction isWorkflowRunRequest(value: Record<string, unknown>): boolean {\n const requestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\", \"usage\", \"usage_detail\", \"callback\"];\n const structuralRequestKeys = [\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\"];\n const keys = Object.keys(value);\n\n if (structuralRequestKeys.some((key) => key in value)) {\n return true;\n }\n\n return keys.length > 0 && keys.every((key) => requestKeys.includes(key));\n}\n\nfunction validateWorkflowName(workflowName: string): ClientResult<never> | null {\n if (!workflowName || workflowName.includes(\"/\")) {\n return {\n data: null,\n error: {\n status: 400,\n message:\n \"Invalid workflowName: use workflow YAML filename without extension (no subpaths)\",\n },\n status: 400,\n };\n }\n return null;\n}\n\nfunction applyEnvToRequest(request: WorkflowRunRequest, env?: string): WorkflowRunRequest {\n if (!request.inputs) {\n request.inputs = {};\n }\n if (env && request.inputs.env === undefined) {\n request.inputs.env = env;\n }\n return request;\n}\n\nexport function createWorkflowClient(\n http: HttpClient = createHttpClient(),\n options: WorkflowClientOptions = {}\n): WorkflowClient {\n const { env } = options;\n\n return {\n async run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n\n // Workflow callers can now provide env through createWorkflowClient so\n // downstream workflows can wire environment-aware behavior directly from\n // the runtime context.\n\n const response = await http.request<{\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n task_id: string;\n workflow_run_id: string;\n }>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: response.data.task_id || \"\",\n workflow_run_id: response.data.workflow_run_id || \"\",\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow response structure\",\n },\n status: response.status,\n };\n },\n async runAsync(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\n ): Promise<ClientResult<WorkflowAsyncRunResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const normalizedRequest = applyEnvToRequest(normalizeRunRequest(inputs), env);\n normalizedRequest.response_mode = \"async\";\n\n const response = await http.request<WorkflowAsyncRunResponse>({\n url: `/api/runworkflow/${workflowName}`,\n method: \"post\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(env ? { \"x-env\": env } : {}),\n },\n data: normalizedRequest,\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run response structure\",\n },\n status: response.status,\n };\n },\n async getAsyncRun(\n workflowName: string,\n asyncRunId: string\n ): Promise<ClientResult<WorkflowAsyncRunDetailResponse>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<WorkflowAsyncRunDetailResponse>({\n url: `/api/runworkflow/${workflowName}/async-runs/${asyncRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n });\n\n if (response.data?.async_run_id) {\n return response;\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow async run detail response structure\",\n },\n status: response.status,\n };\n },\n async getRun<TOutput = Record<string, unknown>>(\n workflowName: string,\n workflowRunId: string,\n options: WorkflowRunDetailOptions = {}\n ): Promise<ClientResult<WorkflowRunResponse<TOutput>>> {\n const validationError = validateWorkflowName(workflowName);\n if (validationError) {\n return validationError;\n }\n\n const response = await http.request<{\n workflow_run_id: string;\n data: {\n status: string;\n outputs: TOutput;\n error: string | null;\n elapsed_time: number;\n total_tokens: number;\n total_steps: number;\n created_at: number;\n finished_at: number;\n usage?: WorkflowRunUsage;\n };\n }>({\n url: `/api/runworkflow/${workflowName}/runs/${workflowRunId}`,\n method: \"get\",\n headers: {\n ...(env ? { \"x-env\": env } : {}),\n },\n params: {\n ...(options.usage !== undefined ? { usage: options.usage } : {}),\n ...(options.usage_detail !== undefined ? { usage_detail: options.usage_detail } : {}),\n },\n });\n\n if (response.data?.data) {\n const innerData = response.data.data;\n return {\n ...response,\n data: {\n task_id: \"\",\n workflow_run_id: response.data.workflow_run_id || workflowRunId,\n status: innerData.status || \"unknown\",\n outputs: innerData.outputs || ({} as TOutput),\n error: innerData.error || null,\n elapsed_time: innerData.elapsed_time || 0,\n total_tokens: innerData.total_tokens || 0,\n total_steps: innerData.total_steps || 0,\n created_at: innerData.created_at || 0,\n finished_at: innerData.finished_at || 0,\n ...(innerData.usage ? { usage: innerData.usage } : {}),\n },\n };\n }\n\n return {\n data: null,\n error: response.error || {\n status: response.status,\n message: \"Invalid workflow run detail response structure\",\n },\n status: response.status,\n };\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amaster.ai/workflow-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.45-beta.1",
|
|
4
4
|
"description": "Workflow execution client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@amaster.ai/http-client": "1.1.
|
|
33
|
+
"@amaster.ai/http-client": "1.1.45-beta.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"axios": "^1.11.0"
|