@amaster.ai/workflow-client 1.1.42 → 1.1.43-beta.2

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 a(t){if(!t)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof t=="object"&&("inputs"in t||"response_mode"in t||"user"in t||"files"in t||"trace_id"in t)){let o=t;return {inputs:o.inputs||{},response_mode:o.response_mode||"blocking",user:o.user||"anonymous",files:o.files,trace_id:o.trace_id}}return {inputs:t,response_mode:"blocking",user:"anonymous"}}function p(t=httpClient.createHttpClient(),o={}){let{env:s}=o;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=a(i);r.inputs||(r.inputs={}),s&&r.inputs.env===void 0&&(r.inputs.env=s);let e=await t.request({url:`/api/runworkflow/${u}`,method:"post",headers:{"Content-Type":"application/json",...s?{"x-env":s}:{}},data:r});if(e.data?.data){let n=e.data.data;return {...e,data:{task_id:e.data.task_id||"",workflow_run_id:e.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}}}return {data:null,error:e.error||{status:e.status,message:"Invalid workflow response structure"},status:e.status}}}}exports.createWorkflowClient=p;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var httpClient=require('@amaster.ai/http-client');function l(t){if(!t)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof t=="object"&&p(t)){let e=t;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,usage_detail:e.usage_detail}}return {inputs:t,response_mode:"blocking",user:"anonymous"}}function p(t){let e=["inputs","response_mode","user","files","trace_id","usage","usage_detail"],r=["inputs","response_mode","user","files","trace_id"],s=Object.keys(t);return r.some(u=>u in t)?true:s.length>0&&s.every(u=>e.includes(u))}function d(t=httpClient.createHttpClient(),e={}){let{env:r}=e;return {async run(s,u){if(!s||s.includes("/"))return {data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400};let i=l(u);i.inputs||(i.inputs={}),r&&i.inputs.env===void 0&&(i.inputs.env=r);let o=await t.request({url:`/api/runworkflow/${s}`,method:"post",headers:{"Content-Type":"application/json",...r?{"x-env":r}:{}},data:i});if(o.data?.data){let n=o.data.data;return {...o,data:{task_id:o.data.task_id||"",workflow_run_id:o.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:o.error||{status:o.status,message:"Invalid workflow response structure"},status:o.status}}}}exports.createWorkflowClient=d;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","req","createWorkflowClient","http","createHttpClient","options","env","workflowName","normalizedRequest","response","innerData"],"mappings":"+DAoDA,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,QAAA,GAAYA,CAAAA,EACX,eAAA,GAAmBA,CAAAA,EACnB,MAAA,GAAUA,GACV,OAAA,GAAWA,CAAAA,EACX,UAAA,GAAcA,CAAAA,CAAAA,CAChB,CACA,IAAMC,CAAAA,CAAMD,CAAAA,CACZ,OAAO,CACL,MAAA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,IAAA,CAAME,CACR,CAAC,CAAA,CAED,GAAIC,CAAAA,CAAS,IAAA,EAAM,IAAA,CAAM,CACvB,IAAMC,CAAAA,CAAYD,CAAAA,CAAS,IAAA,CAAK,IAAA,CAChC,OAAO,CACL,GAAGA,CAAAA,CACH,IAAA,CAAM,CACJ,OAAA,CAASA,CAAAA,CAAS,IAAA,CAAK,OAAA,EAAW,EAAA,CAClC,gBAAiBA,CAAAA,CAAS,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,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,UAAA,CAAYA,EAAU,UAAA,EAAc,CAAA,CACpC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CACxC,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};\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};\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\" in inputs ||\n \"response_mode\" in inputs ||\n \"user\" in inputs ||\n \"files\" in inputs ||\n \"trace_id\" in inputs)\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 };\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 };\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 },\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","createWorkflowClient","http","createHttpClient","options","env","workflowName","normalizedRequest","response","innerData"],"mappings":"+DAwFA,SAASA,EACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,EACH,OAAO,CAAE,MAAA,CAAQ,GAAI,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,CAAA,CAGpE,GAAI,OAAOA,CAAAA,EAAW,UAAYC,CAAAA,CAAqBD,CAAM,CAAA,CAAG,CAC9D,IAAME,CAAAA,CAAMF,CAAAA,CACZ,OAAO,CACL,OAAQE,CAAAA,CAAI,MAAA,EAAU,EAAC,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OAAO,CACL,IAAA,CAAM,KACN,KAAA,CAAOD,CAAAA,CAAS,KAAA,EAAS,CACvB,OAAQA,CAAAA,CAAS,MAAA,CACjB,OAAA,CAAS,qCACX,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\";\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};\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 (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 };\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\"];\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\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"]}
package/dist/index.d.cts CHANGED
@@ -14,6 +14,38 @@ type WorkflowRunRequest = {
14
14
  user?: string;
15
15
  files?: WorkflowFile[];
16
16
  trace_id?: string;
17
+ usage?: boolean;
18
+ usage_detail?: boolean;
19
+ };
20
+ type WorkflowUsageSummary = {
21
+ workflow_run_id: string;
22
+ status: string;
23
+ total_tokens: number;
24
+ total_steps: number;
25
+ elapsed_time: number;
26
+ created_at: number | null;
27
+ finished_at: number | null;
28
+ is_finished: boolean;
29
+ };
30
+ type WorkflowNodeUsage = {
31
+ id: string;
32
+ node_execution_id: string | null;
33
+ index: number;
34
+ node_id: string;
35
+ node_type: string;
36
+ title: string;
37
+ status: string;
38
+ error: string | null;
39
+ elapsed_time: number;
40
+ created_at: number | null;
41
+ finished_at: number | null;
42
+ usage: Record<string, unknown>;
43
+ execution_metadata: Record<string, unknown>;
44
+ };
45
+ type WorkflowRunUsage = {
46
+ summary: WorkflowUsageSummary;
47
+ estimated_price_by_currency?: Record<string, string>;
48
+ nodes?: WorkflowNodeUsage[];
17
49
  };
18
50
  type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
19
51
  task_id: string;
@@ -26,6 +58,7 @@ type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
26
58
  total_steps: number;
27
59
  created_at: number;
28
60
  finished_at: number;
61
+ usage?: WorkflowRunUsage;
29
62
  };
30
63
  type WorkflowClient = {
31
64
  run<TOutput = Record<string, unknown>>(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
@@ -35,4 +68,4 @@ type WorkflowClientOptions = {
35
68
  };
36
69
  declare function createWorkflowClient(http?: HttpClient, options?: WorkflowClientOptions): WorkflowClient;
37
70
 
38
- export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, createWorkflowClient };
71
+ export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowNodeUsage, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, type WorkflowRunUsage, type WorkflowUsageSummary, createWorkflowClient };
package/dist/index.d.ts CHANGED
@@ -14,6 +14,38 @@ type WorkflowRunRequest = {
14
14
  user?: string;
15
15
  files?: WorkflowFile[];
16
16
  trace_id?: string;
17
+ usage?: boolean;
18
+ usage_detail?: boolean;
19
+ };
20
+ type WorkflowUsageSummary = {
21
+ workflow_run_id: string;
22
+ status: string;
23
+ total_tokens: number;
24
+ total_steps: number;
25
+ elapsed_time: number;
26
+ created_at: number | null;
27
+ finished_at: number | null;
28
+ is_finished: boolean;
29
+ };
30
+ type WorkflowNodeUsage = {
31
+ id: string;
32
+ node_execution_id: string | null;
33
+ index: number;
34
+ node_id: string;
35
+ node_type: string;
36
+ title: string;
37
+ status: string;
38
+ error: string | null;
39
+ elapsed_time: number;
40
+ created_at: number | null;
41
+ finished_at: number | null;
42
+ usage: Record<string, unknown>;
43
+ execution_metadata: Record<string, unknown>;
44
+ };
45
+ type WorkflowRunUsage = {
46
+ summary: WorkflowUsageSummary;
47
+ estimated_price_by_currency?: Record<string, string>;
48
+ nodes?: WorkflowNodeUsage[];
17
49
  };
18
50
  type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
19
51
  task_id: string;
@@ -26,6 +58,7 @@ type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
26
58
  total_steps: number;
27
59
  created_at: number;
28
60
  finished_at: number;
61
+ usage?: WorkflowRunUsage;
29
62
  };
30
63
  type WorkflowClient = {
31
64
  run<TOutput = Record<string, unknown>>(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
@@ -35,4 +68,4 @@ type WorkflowClientOptions = {
35
68
  };
36
69
  declare function createWorkflowClient(http?: HttpClient, options?: WorkflowClientOptions): WorkflowClient;
37
70
 
38
- export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, createWorkflowClient };
71
+ export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowNodeUsage, type WorkflowResponseMode, 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 a(t){if(!t)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof t=="object"&&("inputs"in t||"response_mode"in t||"user"in t||"files"in t||"trace_id"in t)){let o=t;return {inputs:o.inputs||{},response_mode:o.response_mode||"blocking",user:o.user||"anonymous",files:o.files,trace_id:o.trace_id}}return {inputs:t,response_mode:"blocking",user:"anonymous"}}function p(t=createHttpClient(),o={}){let{env:s}=o;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=a(i);r.inputs||(r.inputs={}),s&&r.inputs.env===void 0&&(r.inputs.env=s);let e=await t.request({url:`/api/runworkflow/${u}`,method:"post",headers:{"Content-Type":"application/json",...s?{"x-env":s}:{}},data:r});if(e.data?.data){let n=e.data.data;return {...e,data:{task_id:e.data.task_id||"",workflow_run_id:e.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}}}return {data:null,error:e.error||{status:e.status,message:"Invalid workflow response structure"},status:e.status}}}}export{p as createWorkflowClient};//# sourceMappingURL=index.js.map
1
+ import {createHttpClient}from'@amaster.ai/http-client';function l(t){if(!t)return {inputs:{},response_mode:"blocking",user:"anonymous"};if(typeof t=="object"&&p(t)){let e=t;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,usage_detail:e.usage_detail}}return {inputs:t,response_mode:"blocking",user:"anonymous"}}function p(t){let e=["inputs","response_mode","user","files","trace_id","usage","usage_detail"],r=["inputs","response_mode","user","files","trace_id"],s=Object.keys(t);return r.some(u=>u in t)?true:s.length>0&&s.every(u=>e.includes(u))}function d(t=createHttpClient(),e={}){let{env:r}=e;return {async run(s,u){if(!s||s.includes("/"))return {data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400};let i=l(u);i.inputs||(i.inputs={}),r&&i.inputs.env===void 0&&(i.inputs.env=r);let o=await t.request({url:`/api/runworkflow/${s}`,method:"post",headers:{"Content-Type":"application/json",...r?{"x-env":r}:{}},data:i});if(o.data?.data){let n=o.data.data;return {...o,data:{task_id:o.data.task_id||"",workflow_run_id:o.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:o.error||{status:o.status,message:"Invalid workflow response structure"},status:o.status}}}}export{d 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","req","createWorkflowClient","http","createHttpClient","options","env","workflowName","normalizedRequest","response","innerData"],"mappings":"uDAoDA,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,QAAA,GAAYA,CAAAA,EACX,eAAA,GAAmBA,CAAAA,EACnB,MAAA,GAAUA,GACV,OAAA,GAAWA,CAAAA,EACX,UAAA,GAAcA,CAAAA,CAAAA,CAChB,CACA,IAAMC,CAAAA,CAAMD,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQC,CAAAA,CAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UAAA,CACpC,IAAA,CAAMA,CAAAA,CAAI,IAAA,EAAQ,WAAA,CAClB,KAAA,CAAOA,CAAAA,CAAI,KAAA,CACX,QAAA,CAAUA,CAAAA,CAAI,QAChB,CACF,CAEA,OAAO,CACL,MAAA,CAAQD,CAAAA,CACR,aAAA,CAAe,UAAA,CACf,IAAA,CAAM,WACR,CACF,CAEO,SAASE,CAAAA,CACdC,CAAAA,CAAmBC,gBAAAA,EAAiB,CACpCC,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ASA,CAAAA,CAAU,OAAA,EAAY,EAAC,CAChC,KAAA,CAAOA,CAAAA,CAAU,KAAA,EAAS,IAAA,CAC1B,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,UAAA,CAAYA,EAAU,UAAA,EAAc,CAAA,CACpC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CACxC,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};\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};\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\" in inputs ||\n \"response_mode\" in inputs ||\n \"user\" in inputs ||\n \"files\" in inputs ||\n \"trace_id\" in inputs)\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 };\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 };\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 },\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","createWorkflowClient","http","createHttpClient","options","env","workflowName","normalizedRequest","response","innerData"],"mappings":"uDAwFA,SAASA,EACPC,CAAAA,CACoB,CACpB,GAAI,CAACA,EACH,OAAO,CAAE,MAAA,CAAQ,GAAI,aAAA,CAAe,UAAA,CAAY,IAAA,CAAM,WAAY,CAAA,CAGpE,GAAI,OAAOA,CAAAA,EAAW,UAAYC,CAAAA,CAAqBD,CAAM,CAAA,CAAG,CAC9D,IAAME,CAAAA,CAAMF,CAAAA,CACZ,OAAO,CACL,OAAQE,CAAAA,CAAI,MAAA,EAAU,EAAC,CACvB,aAAA,CAAeA,CAAAA,CAAI,aAAA,EAAiB,UAAA,CACpC,KAAMA,CAAAA,CAAI,IAAA,EAAQ,WAAA,CAClB,KAAA,CAAOA,EAAI,KAAA,CACX,QAAA,CAAUA,CAAAA,CAAI,QAAA,CACd,MAAOA,CAAAA,CAAI,KAAA,CACX,YAAA,CAAcA,CAAAA,CAAI,YACpB,CACF,CAEA,OAAO,CACL,MAAA,CAAQF,CAAAA,CACR,aAAA,CAAe,UAAA,CACf,KAAM,WACR,CACF,CAEA,SAASC,EAAqBE,CAAAA,CAAyC,CACrE,IAAMC,CAAAA,C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B,kBAAA,CAChB,GAAID,CAAAA,CAAM,CAAE,OAAA,CAASA,CAAI,CAAA,CAAI,EAC/B,CAAA,CACA,IAAA,CAAME,CACR,CAAC,CAAA,CAED,GAAIC,CAAAA,CAAS,IAAA,EAAM,KAAM,CACvB,IAAMC,CAAAA,CAAYD,CAAAA,CAAS,KAAK,IAAA,CAChC,OAAO,CACL,GAAGA,EACH,IAAA,CAAM,CACJ,OAAA,CAASA,CAAAA,CAAS,IAAA,CAAK,OAAA,EAAW,EAAA,CAClC,eAAA,CAAiBA,EAAS,IAAA,CAAK,eAAA,EAAmB,EAAA,CAClD,MAAA,CAAQC,EAAU,MAAA,EAAU,SAAA,CAC5B,OAAA,CAASA,CAAAA,CAAU,SAAY,EAAC,CAChC,KAAA,CAAOA,CAAAA,CAAU,KAAA,EAAS,IAAA,CAC1B,YAAA,CAAcA,CAAAA,CAAU,cAAgB,CAAA,CACxC,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,EACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,WAAYA,CAAAA,CAAU,UAAA,EAAc,CAAA,CACpC,WAAA,CAAaA,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,qCACX,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\";\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};\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 (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 };\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\"];\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\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/workflow-client",
3
- "version": "1.1.42",
3
+ "version": "1.1.43-beta.2",
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.42"
33
+ "@amaster.ai/http-client": "1.1.43-beta.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "axios": "^1.11.0"