@amaster.ai/workflow-client 1.1.10 → 1.1.11
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 +5 -2
- package/dist/index.d.ts +5 -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
|
|
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
|
|
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","req","createWorkflowClient","http","createHttpClient","workflowName","normalizedRequest","response","innerData"],"mappings":"+
|
|
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,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,2BAAAA,EAAiB,CACpCC,CAAAA,CAAiC,EAAC,CAClB,CAChB,GAAM,CAAE,GAAA,CAAAC,CAAI,CAAA,CAAID,CAAAA,CAEhB,OAAO,CACL,MAAM,GAAA,CACJE,CAAAA,CACAP,EACqD,CACrD,GAAI,CAACO,CAAAA,EAAgBA,CAAAA,CAAa,QAAA,CAAS,GAAG,CAAA,CAC5C,O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AAU,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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -30,6 +30,9 @@ type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
|
|
|
30
30
|
type WorkflowClient = {
|
|
31
31
|
run<TOutput = Record<string, unknown>>(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
type WorkflowClientOptions = {
|
|
34
|
+
env?: string;
|
|
35
|
+
};
|
|
36
|
+
declare function createWorkflowClient(http?: HttpClient, options?: WorkflowClientOptions): WorkflowClient;
|
|
34
37
|
|
|
35
|
-
export { type WorkflowClient, type WorkflowFile, type WorkflowInputValue, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, createWorkflowClient };
|
|
38
|
+
export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, createWorkflowClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,9 @@ type WorkflowRunResponse<TOutput = Record<string, unknown>> = {
|
|
|
30
30
|
type WorkflowClient = {
|
|
31
31
|
run<TOutput = Record<string, unknown>>(workflowName: string, inputs?: Record<string, WorkflowInputValue> | WorkflowRunRequest): Promise<ClientResult<WorkflowRunResponse<TOutput>>>;
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
type WorkflowClientOptions = {
|
|
34
|
+
env?: string;
|
|
35
|
+
};
|
|
36
|
+
declare function createWorkflowClient(http?: HttpClient, options?: WorkflowClientOptions): WorkflowClient;
|
|
34
37
|
|
|
35
|
-
export { type WorkflowClient, type WorkflowFile, type WorkflowInputValue, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, createWorkflowClient };
|
|
38
|
+
export { type WorkflowClient, type WorkflowClientOptions, type WorkflowFile, type WorkflowInputValue, type WorkflowResponseMode, type WorkflowRunRequest, type WorkflowRunResponse, createWorkflowClient };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {createHttpClient}from'@amaster.ai/http-client';function
|
|
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
|
|
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","workflowName","normalizedRequest","response","innerData"],"mappings":"
|
|
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,CAAAA,CAAiC,EAAC,CAClB,CAChB,GAAM,CAAE,GAAA,CAAAC,CAAI,CAAA,CAAID,CAAAA,CAEhB,OAAO,CACL,MAAM,GAAA,CACJE,CAAAA,CACAP,EACqD,CACrD,GAAI,CAACO,CAAAA,EAAgBA,CAAAA,CAAa,QAAA,CAAS,GAAG,CAAA,CAC5C,OAAO,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CACL,MAAA,CAAQ,GAAA,CACR,OAAA,CACE,kFACJ,CAA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AU,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amaster.ai/workflow-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "Workflow execution client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@amaster.ai/http-client": "1.1.
|
|
33
|
+
"@amaster.ai/http-client": "1.1.11"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"axios": "^1.11.0"
|