@amaster.ai/workflow-client 1.1.43-beta.0 → 1.1.43-beta.3

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 CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var httpClient=require('@amaster.ai/http-client');function l(n){if(!n)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof n=="object"&&(["inputs","response_mode","user","files","trace_id"].some(e=>e in n)||"usage"in n&&Object.keys(n).length===1)){let e=n;return {inputs:e.inputs||{},response_mode:e.response_mode||"blocking",user:e.user||"anonymous",files:e.files,trace_id:e.trace_id,usage:e.usage}}return {inputs:n,response_mode:"blocking",user:"anonymous"}}function p(n=httpClient.createHttpClient(),e={}){let{env:s}=e;return {async run(u,i){if(!u||u.includes("/"))return {data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400};let r=l(i);r.inputs||(r.inputs={}),s&&r.inputs.env===void 0&&(r.inputs.env=s);let o=await n.request({url:`/api/runworkflow/${u}`,method:"post",headers:{"Content-Type":"application/json",...s?{"x-env":s}:{}},data:r});if(o.data?.data){let t=o.data.data;return {...o,data:{task_id:o.data.task_id||"",workflow_run_id:o.data.workflow_run_id||"",status:t.status||"unknown",outputs:t.outputs||{},error:t.error||null,elapsed_time:t.elapsed_time||0,total_tokens:t.total_tokens||0,total_steps:t.total_steps||0,created_at:t.created_at||0,finished_at:t.finished_at||0,...t.usage?{usage:t.usage}:{}}}}return {data:null,error:o.error||{status:o.status,message:"Invalid workflow response structure"},status:o.status}}}}exports.createWorkflowClient=p;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var httpClient=require('@amaster.ai/http-client');function d(e){if(!e)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof e=="object"&&g(e)){let r=e;return {inputs:r.inputs||{},response_mode:r.response_mode||"blocking",user:r.user||"anonymous",files:r.files,trace_id:r.trace_id,usage:r.usage,usage_detail:r.usage_detail,callback:r.callback}}return {inputs:e,response_mode:"blocking",user:"anonymous"}}function g(e){let r=["inputs","response_mode","user","files","trace_id","usage","usage_detail","callback"],a=["inputs","response_mode","user","files","trace_id"],s=Object.keys(e);return a.some(l=>l in e)?true:s.length>0&&s.every(l=>r.includes(l))}function i(e){return !e||e.includes("/")?{data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400}:null}function p(e,r){return e.inputs||(e.inputs={}),r&&e.inputs.env===void 0&&(e.inputs.env=r),e}function k(e=httpClient.createHttpClient(),r={}){let{env:a}=r;return {async run(s,l){let o=i(s);if(o)return o;let u=p(d(l),a),t=await e.request({url:`/api/runworkflow/${s}`,method:"post",headers:{"Content-Type":"application/json",...a?{"x-env":a}:{}},data:u});if(t.data?.data){let n=t.data.data;return {...t,data:{task_id:t.data.task_id||"",workflow_run_id:t.data.workflow_run_id||"",status:n.status||"unknown",outputs:n.outputs||{},error:n.error||null,elapsed_time:n.elapsed_time||0,total_tokens:n.total_tokens||0,total_steps:n.total_steps||0,created_at:n.created_at||0,finished_at:n.finished_at||0,...n.usage?{usage:n.usage}:{}}}}return {data:null,error:t.error||{status:t.status,message:"Invalid workflow response structure"},status:t.status}},async runAsync(s,l){let o=i(s);if(o)return o;let u=p(d(l),a);u.response_mode="async";let t=await e.request({url:`/api/runworkflow/${s}`,method:"post",headers:{"Content-Type":"application/json",...a?{"x-env":a}:{}},data:u});return t.data?.async_run_id?t:{data:null,error:t.error||{status:t.status,message:"Invalid workflow async run response structure"},status:t.status}},async getAsyncRun(s,l){let o=i(s);if(o)return o;let u=await e.request({url:`/api/runworkflow/${s}/async-runs/${l}`,method:"get",headers:{...a?{"x-env":a}:{}}});return u.data?.async_run_id?u:{data:null,error:u.error||{status:u.status,message:"Invalid workflow async run detail response structure"},status:u.status}},async getRun(s,l,o={}){let u=i(s);if(u)return u;let t=await e.request({url:`/api/runworkflow/${s}/runs/${l}`,method:"get",headers:{...a?{"x-env":a}:{}},params:{...o.usage!==void 0?{usage:o.usage}:{},...o.usage_detail!==void 0?{usage_detail:o.usage_detail}:{}}});if(t.data?.data){let n=t.data.data;return {...t,data:{task_id:"",workflow_run_id:t.data.workflow_run_id||l,status:n.status||"unknown",outputs:n.outputs||{},error:n.error||null,elapsed_time:n.elapsed_time||0,total_tokens:n.total_tokens||0,total_steps:n.total_steps||0,created_at:n.created_at||0,finished_at:n.finished_at||0,...n.usage?{usage:n.usage}:{}}}}return {data:null,error:t.error||{status:t.status,message:"Invalid workflow run detail response structure"},status:t.status}}}}exports.createWorkflowClient=k;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","key","req","createWorkflowClient","http","createHttpClient","options","env","workflowName","normalizedRequest","response","innerData"],"mappings":"+DAuFA,SAASA,CAAAA,CACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,CAAAA,CACH,OAAO,CAAE,MAAA,CAAQ,EAAC,CAAG,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,CAAA,CAGpE,GACE,OAAOA,CAAAA,EAAW,QAAA,GACjB,CAAC,QAAA,CAAU,eAAA,CAAiB,MAAA,CAAQ,QAAS,UAAU,CAAA,CAAE,IAAA,CAAMC,CAAAA,EAAQA,CAAAA,IAAOD,CAAM,CAAA,EAClF,OAAA,GAAWA,CAAAA,EAAU,MAAA,CAAO,IAAA,CAAKA,CAAM,CAAA,CAAE,MAAA,GAAW,CAAA,CAAA,CACvD,CACA,IAAME,CAAAA,CAAMF,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQE,CAAAA,CAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UAAA,CACpC,IAAA,CAAMA,CAAAA,CAAI,IAAA,EAAQ,YAClB,KAAA,CAAOA,CAAAA,CAAI,KAAA,CACX,QAAA,CAAUA,CAAAA,CAAI,QAAA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AAA,CAAM,CACJ,OAAA,CAASA,CAAAA,CAAS,IAAA,CAAK,OAAA,EAAW,EAAA,CAClC,eAAA,CAAiBA,EAAS,IAAA,CAAK,eAAA,EAAmB,EAAA,CAClD,MAAA,CAAQC,CAAAA,CAAU,MAAA,EAAU,SAAA,CAC5B,OAAA,CAASA,CAAAA,CAAU,OAAA,EAAY,EAAC,CAChC,KAAA,CAAOA,CAAAA,CAAU,KAAA,EAAS,IAAA,CAC1B,aAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,UAAA,CAAYA,CAAAA,CAAU,UAAA,EAAc,CAAA,CACpC,WAAA,CAAaA,EAAU,WAAA,EAAe,CAAA,CACtC,GAAIA,CAAAA,CAAU,KAAA,CAAQ,CAAE,KAAA,CAAOA,CAAAA,CAAU,KAAM,CAAA,CAAI,EACrD,CACF,CACF,CAEA,OAAO,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,MAAA,CAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,qCACX,CAAA,CACA,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\";\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};\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 WorkflowClient = {\n run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\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 (\n typeof inputs === \"object\" &&\n ([\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\"].some((key) => key in inputs) ||\n (\"usage\" in inputs && Object.keys(inputs).length === 1))\n ) {\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 };\n }\n\n return {\n inputs: inputs as Record<string, WorkflowInputValue>,\n response_mode: \"blocking\",\n user: \"anonymous\",\n };\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 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\n const normalizedRequest = normalizeRunRequest(inputs);\n\n if (!normalizedRequest.inputs) {\n normalizedRequest.inputs = {};\n }\n\n if (env && normalizedRequest.inputs.env === undefined) {\n normalizedRequest.inputs.env = env;\n }\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 };\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":"+DAkJA,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,UAAU,CAAA,CAC/EC,EAAO,MAAA,CAAO,IAAA,CAAKH,CAAK,CAAA,CAE9B,OAAIE,CAAAA,CAAsB,IAAA,CAAME,CAAAA,EAAQA,CAAAA,IAAOJ,CAAK,CAAA,CAC3C,IAAA,CAGFG,CAAAA,CAAK,MAAA,C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AAOD,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 url: string;\n secret?: 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"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ClientResult, HttpClient } from '@amaster.ai/http-client';
2
2
 
3
- type WorkflowResponseMode = "blocking" | "streaming";
3
+ type WorkflowResponseMode = "blocking" | "streaming" | "async";
4
4
  type WorkflowInputValue = string | number | boolean | null | undefined | Record<string, unknown> | unknown[];
5
5
  type WorkflowFile = {
6
6
  name?: string;
@@ -15,6 +15,15 @@ type WorkflowRunRequest = {
15
15
  files?: WorkflowFile[];
16
16
  trace_id?: string;
17
17
  usage?: boolean;
18
+ usage_detail?: boolean;
19
+ callback?: WorkflowCallbackConfig;
20
+ };
21
+ type WorkflowCallbackConfig = {
22
+ url: string;
23
+ secret?: string;
24
+ include_outputs?: boolean;
25
+ include_usage?: boolean;
26
+ usage_detail?: boolean;
18
27
  };
19
28
  type WorkflowUsageSummary = {
20
29
  workflow_run_id: string;
@@ -43,8 +52,8 @@ type WorkflowNodeUsage = {
43
52
  };
44
53
  type WorkflowRunUsage = {
45
54
  summary: WorkflowUsageSummary;
46
- estimated_price_by_currency: Record<string, string>;
47
- nodes: WorkflowNodeUsage[];
55
+ estimated_price_by_currency?: Record<string, string>;
56
+ nodes?: WorkflowNodeUsage[];
48
57
  };
49
58
  type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
50
59
  task_id: string;
@@ -59,12 +68,38 @@ type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
59
68
  finished_at: number;
60
69
  usage?: WorkflowRunUsage;
61
70
  };
71
+ type WorkflowAsyncRunStatus = "pending" | "queued" | "running" | "succeeded" | "failed" | "paused" | "rate_limited" | "retrying" | string;
72
+ type WorkflowAsyncRunResponse = {
73
+ async_run_id: string;
74
+ workflow_trigger_log_id: string;
75
+ workflow_run_id: string | null;
76
+ task_id?: string;
77
+ status: WorkflowAsyncRunStatus;
78
+ queue?: string;
79
+ created_at?: number | null;
80
+ };
81
+ type WorkflowAsyncRunDetailResponse = WorkflowAsyncRunResponse & {
82
+ workflow_id?: string;
83
+ error?: string | null;
84
+ outputs?: Record<string, unknown> | null;
85
+ elapsed_time?: number | null;
86
+ total_tokens?: number | null;
87
+ triggered_at?: number | null;
88
+ finished_at?: number | null;
89
+ };
90
+ type WorkflowRunDetailOptions = {
91
+ usage?: boolean;
92
+ usage_detail?: boolean;
93
+ };
62
94
  type WorkflowClient = {
63
95
  run<TOutput = Record<string, unknown>>(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
96
+ runAsync(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowAsyncRunResponse>>;
97
+ getAsyncRun(workflowName: string, asyncRunId: string): Promise<ClientResult<WorkflowAsyncRunDetailResponse>>;
98
+ getRun<TOutput = Record<string, unknown>>(workflowName: string, workflowRunId: string, options?: WorkflowRunDetailOptions): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
64
99
  };
65
100
  type WorkflowClientOptions = {
66
101
  env?: string;
67
102
  };
68
103
  declare function createWorkflowClient(http?: HttpClient, options?: WorkflowClientOptions): WorkflowClient;
69
104
 
70
- export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowNodeUsage, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, type WorkflowRunUsage, type WorkflowUsageSummary, createWorkflowClient };
105
+ export { type WorkflowAsyncRunDetailResponse, type WorkflowAsyncRunResponse, type WorkflowAsyncRunStatus, type WorkflowCallbackConfig, type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowNodeUsage, type WorkflowResponseMode, type WorkflowRunDetailOptions, type WorkflowRunRequest, type WorkflowRunResponse, type WorkflowRunUsage, type WorkflowUsageSummary, createWorkflowClient };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ClientResult, HttpClient } from '@amaster.ai/http-client';
2
2
 
3
- type WorkflowResponseMode = "blocking" | "streaming";
3
+ type WorkflowResponseMode = "blocking" | "streaming" | "async";
4
4
  type WorkflowInputValue = string | number | boolean | null | undefined | Record<string, unknown> | unknown[];
5
5
  type WorkflowFile = {
6
6
  name?: string;
@@ -15,6 +15,15 @@ type WorkflowRunRequest = {
15
15
  files?: WorkflowFile[];
16
16
  trace_id?: string;
17
17
  usage?: boolean;
18
+ usage_detail?: boolean;
19
+ callback?: WorkflowCallbackConfig;
20
+ };
21
+ type WorkflowCallbackConfig = {
22
+ url: string;
23
+ secret?: string;
24
+ include_outputs?: boolean;
25
+ include_usage?: boolean;
26
+ usage_detail?: boolean;
18
27
  };
19
28
  type WorkflowUsageSummary = {
20
29
  workflow_run_id: string;
@@ -43,8 +52,8 @@ type WorkflowNodeUsage = {
43
52
  };
44
53
  type WorkflowRunUsage = {
45
54
  summary: WorkflowUsageSummary;
46
- estimated_price_by_currency: Record<string, string>;
47
- nodes: WorkflowNodeUsage[];
55
+ estimated_price_by_currency?: Record<string, string>;
56
+ nodes?: WorkflowNodeUsage[];
48
57
  };
49
58
  type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
50
59
  task_id: string;
@@ -59,12 +68,38 @@ type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
59
68
  finished_at: number;
60
69
  usage?: WorkflowRunUsage;
61
70
  };
71
+ type WorkflowAsyncRunStatus = "pending" | "queued" | "running" | "succeeded" | "failed" | "paused" | "rate_limited" | "retrying" | string;
72
+ type WorkflowAsyncRunResponse = {
73
+ async_run_id: string;
74
+ workflow_trigger_log_id: string;
75
+ workflow_run_id: string | null;
76
+ task_id?: string;
77
+ status: WorkflowAsyncRunStatus;
78
+ queue?: string;
79
+ created_at?: number | null;
80
+ };
81
+ type WorkflowAsyncRunDetailResponse = WorkflowAsyncRunResponse & {
82
+ workflow_id?: string;
83
+ error?: string | null;
84
+ outputs?: Record<string, unknown> | null;
85
+ elapsed_time?: number | null;
86
+ total_tokens?: number | null;
87
+ triggered_at?: number | null;
88
+ finished_at?: number | null;
89
+ };
90
+ type WorkflowRunDetailOptions = {
91
+ usage?: boolean;
92
+ usage_detail?: boolean;
93
+ };
62
94
  type WorkflowClient = {
63
95
  run<TOutput = Record<string, unknown>>(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
96
+ runAsync(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowAsyncRunResponse>>;
97
+ getAsyncRun(workflowName: string, asyncRunId: string): Promise<ClientResult<WorkflowAsyncRunDetailResponse>>;
98
+ getRun<TOutput = Record<string, unknown>>(workflowName: string, workflowRunId: string, options?: WorkflowRunDetailOptions): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
64
99
  };
65
100
  type WorkflowClientOptions = {
66
101
  env?: string;
67
102
  };
68
103
  declare function createWorkflowClient(http?: HttpClient, options?: WorkflowClientOptions): WorkflowClient;
69
104
 
70
- export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowNodeUsage, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, type WorkflowRunUsage, type WorkflowUsageSummary, createWorkflowClient };
105
+ export { type WorkflowAsyncRunDetailResponse, type WorkflowAsyncRunResponse, type WorkflowAsyncRunStatus, type WorkflowCallbackConfig, type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowNodeUsage, type WorkflowResponseMode, type WorkflowRunDetailOptions, type WorkflowRunRequest, type WorkflowRunResponse, type WorkflowRunUsage, type WorkflowUsageSummary, createWorkflowClient };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {createHttpClient}from'@amaster.ai/http-client';function l(n){if(!n)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof n=="object"&&(["inputs","response_mode","user","files","trace_id"].some(e=>e in n)||"usage"in n&&Object.keys(n).length===1)){let e=n;return {inputs:e.inputs||{},response_mode:e.response_mode||"blocking",user:e.user||"anonymous",files:e.files,trace_id:e.trace_id,usage:e.usage}}return {inputs:n,response_mode:"blocking",user:"anonymous"}}function p(n=createHttpClient(),e={}){let{env:s}=e;return {async run(u,i){if(!u||u.includes("/"))return {data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400};let r=l(i);r.inputs||(r.inputs={}),s&&r.inputs.env===void 0&&(r.inputs.env=s);let o=await n.request({url:`/api/runworkflow/${u}`,method:"post",headers:{"Content-Type":"application/json",...s?{"x-env":s}:{}},data:r});if(o.data?.data){let t=o.data.data;return {...o,data:{task_id:o.data.task_id||"",workflow_run_id:o.data.workflow_run_id||"",status:t.status||"unknown",outputs:t.outputs||{},error:t.error||null,elapsed_time:t.elapsed_time||0,total_tokens:t.total_tokens||0,total_steps:t.total_steps||0,created_at:t.created_at||0,finished_at:t.finished_at||0,...t.usage?{usage:t.usage}:{}}}}return {data:null,error:o.error||{status:o.status,message:"Invalid workflow response structure"},status:o.status}}}}export{p as createWorkflowClient};//# sourceMappingURL=index.js.map
1
+ import {createHttpClient}from'@amaster.ai/http-client';function d(e){if(!e)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof e=="object"&&g(e)){let r=e;return {inputs:r.inputs||{},response_mode:r.response_mode||"blocking",user:r.user||"anonymous",files:r.files,trace_id:r.trace_id,usage:r.usage,usage_detail:r.usage_detail,callback:r.callback}}return {inputs:e,response_mode:"blocking",user:"anonymous"}}function g(e){let r=["inputs","response_mode","user","files","trace_id","usage","usage_detail","callback"],a=["inputs","response_mode","user","files","trace_id"],s=Object.keys(e);return a.some(l=>l in e)?true:s.length>0&&s.every(l=>r.includes(l))}function i(e){return !e||e.includes("/")?{data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400}:null}function p(e,r){return e.inputs||(e.inputs={}),r&&e.inputs.env===void 0&&(e.inputs.env=r),e}function k(e=createHttpClient(),r={}){let{env:a}=r;return {async run(s,l){let o=i(s);if(o)return o;let u=p(d(l),a),t=await e.request({url:`/api/runworkflow/${s}`,method:"post",headers:{"Content-Type":"application/json",...a?{"x-env":a}:{}},data:u});if(t.data?.data){let n=t.data.data;return {...t,data:{task_id:t.data.task_id||"",workflow_run_id:t.data.workflow_run_id||"",status:n.status||"unknown",outputs:n.outputs||{},error:n.error||null,elapsed_time:n.elapsed_time||0,total_tokens:n.total_tokens||0,total_steps:n.total_steps||0,created_at:n.created_at||0,finished_at:n.finished_at||0,...n.usage?{usage:n.usage}:{}}}}return {data:null,error:t.error||{status:t.status,message:"Invalid workflow response structure"},status:t.status}},async runAsync(s,l){let o=i(s);if(o)return o;let u=p(d(l),a);u.response_mode="async";let t=await e.request({url:`/api/runworkflow/${s}`,method:"post",headers:{"Content-Type":"application/json",...a?{"x-env":a}:{}},data:u});return t.data?.async_run_id?t:{data:null,error:t.error||{status:t.status,message:"Invalid workflow async run response structure"},status:t.status}},async getAsyncRun(s,l){let o=i(s);if(o)return o;let u=await e.request({url:`/api/runworkflow/${s}/async-runs/${l}`,method:"get",headers:{...a?{"x-env":a}:{}}});return u.data?.async_run_id?u:{data:null,error:u.error||{status:u.status,message:"Invalid workflow async run detail response structure"},status:u.status}},async getRun(s,l,o={}){let u=i(s);if(u)return u;let t=await e.request({url:`/api/runworkflow/${s}/runs/${l}`,method:"get",headers:{...a?{"x-env":a}:{}},params:{...o.usage!==void 0?{usage:o.usage}:{},...o.usage_detail!==void 0?{usage_detail:o.usage_detail}:{}}});if(t.data?.data){let n=t.data.data;return {...t,data:{task_id:"",workflow_run_id:t.data.workflow_run_id||l,status:n.status||"unknown",outputs:n.outputs||{},error:n.error||null,elapsed_time:n.elapsed_time||0,total_tokens:n.total_tokens||0,total_steps:n.total_steps||0,created_at:n.created_at||0,finished_at:n.finished_at||0,...n.usage?{usage:n.usage}:{}}}}return {data:null,error:t.error||{status:t.status,message:"Invalid workflow run detail response structure"},status:t.status}}}}export{k as createWorkflowClient};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","key","req","createWorkflowClient","http","createHttpClient","options","env","workflowName","normalizedRequest","response","innerData"],"mappings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IA,CAAAA,CAAU,KAAA,CAAQ,CAAE,KAAA,CAAOA,CAAAA,CAAU,KAAM,CAAA,CAAI,EACrD,CACF,CACF,CAEA,OAAO,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,MAAA,CAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,qCACX,CAAA,CACA,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\";\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};\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 WorkflowClient = {\n run<TOutput = Record<string, unknown>>(\n workflowName: string,\n inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest\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 (\n typeof inputs === \"object\" &&\n ([\"inputs\", \"response_mode\", \"user\", \"files\", \"trace_id\"].some((key) => key in inputs) ||\n (\"usage\" in inputs && Object.keys(inputs).length === 1))\n ) {\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 };\n }\n\n return {\n inputs: inputs as Record<string, WorkflowInputValue>,\n response_mode: \"blocking\",\n user: \"anonymous\",\n };\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 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\n const normalizedRequest = normalizeRunRequest(inputs);\n\n if (!normalizedRequest.inputs) {\n normalizedRequest.inputs = {};\n }\n\n if (env && normalizedRequest.inputs.env === undefined) {\n normalizedRequest.inputs.env = env;\n }\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 };\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":"uDAkJA,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,EAA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,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 url: string;\n secret?: 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/workflow-client",
3
- "version": "1.1.43-beta.0",
3
+ "version": "1.1.43-beta.3",
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.43-beta.0"
33
+ "@amaster.ai/http-client": "1.1.43-beta.3"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "axios": "^1.11.0"