@amaster.ai/workflow-client 1.1.43-beta.0 → 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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var httpClient=require('@amaster.ai/http-client');function l(
|
|
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
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/workflow-client.ts"],"names":["normalizeRunRequest","inputs","
|
|
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,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,CAAc,CAAC,QAAA,CAAU,eAAA,CAAiB,MAAA,CAAQ,QAAS,UAAA,CAAY,OAAA,CAAS,cAAc,CAAA,CAC9FC,EAAwB,CAAC,QAAA,CAAU,eAAA,CAAiB,MAAA,CAAQ,QAAS,UAAU,C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B,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.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
|
@@ -15,6 +15,7 @@ type WorkflowRunRequest = {
|
|
|
15
15
|
files?: WorkflowFile[];
|
|
16
16
|
trace_id?: string;
|
|
17
17
|
usage?: boolean;
|
|
18
|
+
usage_detail?: boolean;
|
|
18
19
|
};
|
|
19
20
|
type WorkflowUsageSummary = {
|
|
20
21
|
workflow_run_id: string;
|
|
@@ -43,8 +44,8 @@ type WorkflowNodeUsage = {
|
|
|
43
44
|
};
|
|
44
45
|
type WorkflowRunUsage = {
|
|
45
46
|
summary: WorkflowUsageSummary;
|
|
46
|
-
estimated_price_by_currency
|
|
47
|
-
nodes
|
|
47
|
+
estimated_price_by_currency?: Record<string, string>;
|
|
48
|
+
nodes?: WorkflowNodeUsage[];
|
|
48
49
|
};
|
|
49
50
|
type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
|
|
50
51
|
task_id: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ type WorkflowRunRequest = {
|
|
|
15
15
|
files?: WorkflowFile[];
|
|
16
16
|
trace_id?: string;
|
|
17
17
|
usage?: boolean;
|
|
18
|
+
usage_detail?: boolean;
|
|
18
19
|
};
|
|
19
20
|
type WorkflowUsageSummary = {
|
|
20
21
|
workflow_run_id: string;
|
|
@@ -43,8 +44,8 @@ type WorkflowNodeUsage = {
|
|
|
43
44
|
};
|
|
44
45
|
type WorkflowRunUsage = {
|
|
45
46
|
summary: WorkflowUsageSummary;
|
|
46
|
-
estimated_price_by_currency
|
|
47
|
-
nodes
|
|
47
|
+
estimated_price_by_currency?: Record<string, string>;
|
|
48
|
+
nodes?: WorkflowNodeUsage[];
|
|
48
49
|
};
|
|
49
50
|
type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
|
|
50
51
|
task_id: string;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {createHttpClient}from'@amaster.ai/http-client';function l(
|
|
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","
|
|
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,CAAc,CAAC,QAAA,CAAU,eAAA,CAAiB,MAAA,CAAQ,QAAS,UAAA,CAAY,OAAA,CAAS,cAAc,CAAA,CAC9FC,EAAwB,CAAC,QAAA,CAAU,eAAA,CAAiB,MAAA,CAAQ,QAAS,UAAU,CAAA,CAC/EC,CAAAA,CAAO,MAAA,CAAO,IAAA,CAAKH,CAAK,CAAA,CAE9B,OAAIE,EAAsB,IAAA,CAAME,CAAAA,EAAQA,CAAAA,IAAOJ,CAAK,EAC3C,IAAA,CAGFG,CAAAA,CAAK,MAAA,CAAS,CAAA,EAAKA,EA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,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.43-beta.
|
|
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.43-beta.
|
|
33
|
+
"@amaster.ai/http-client": "1.1.43-beta.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"axios": "^1.11.0"
|