@amaster.ai/workflow-client 1.0.0-beta.0 → 1.0.0-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/README.md CHANGED
@@ -1,53 +1 @@
1
1
  # @amaster.ai/workflow-client
2
-
3
- Workflow execution client for running automated workflows.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pnpm add @amaster.ai/workflow-client @amaster.ai/http-client axios
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```typescript
14
- import { createWorkflowClient } from "@amaster.ai/workflow-client";
15
-
16
- const client = createWorkflowClient();
17
-
18
- const result = await client.run("data-processing", {
19
- input_file: "data.csv",
20
- output_format: "json",
21
- });
22
-
23
- if (result.data) {
24
- console.log("Workflow completed:", result.data.outputs);
25
- console.log("Elapsed time:", result.data.elapsed_time, "seconds");
26
- }
27
- ```
28
-
29
- ## API Reference
30
-
31
- ### `run(workflowName, inputs?)`
32
-
33
- Execute a workflow by name.
34
-
35
- ```typescript
36
- // Simple inputs
37
- await client.run("my-workflow", {
38
- field1: "value1",
39
- field2: 123,
40
- });
41
-
42
- // Full request with options
43
- await client.run("my-workflow", {
44
- inputs: { field1: "value1" },
45
- response_mode: "blocking",
46
- user: "john@example.com",
47
- files: [{ url: "https://...", name: "doc.pdf" }],
48
- });
49
- ```
50
-
51
- ## License
52
-
53
- MIT
package/dist/index.cjs CHANGED
@@ -1,102 +1,2 @@
1
- 'use strict';
2
-
3
- var httpClient = require('@amaster.ai/http-client');
4
-
5
- // src/workflow-client.ts
6
- function extractAppIdFromUrl() {
7
- if (typeof window === "undefined") {
8
- return null;
9
- }
10
- try {
11
- const url = window.location.href;
12
- const pathMatch = /\/app\/([\da-f-]+)(?:\/|$)/.exec(url);
13
- if (pathMatch && pathMatch[1]) {
14
- return pathMatch[1];
15
- }
16
- const hostname = window.location.hostname;
17
- const domainMatch = /^([\da-f-]+)(?:-[^.]+)?\.amaster\.(?:local|ai)$/.exec(hostname);
18
- if (domainMatch && domainMatch[1]) {
19
- return domainMatch[1];
20
- }
21
- return null;
22
- } catch {
23
- return null;
24
- }
25
- }
26
- function normalizeRunRequest(inputs) {
27
- if (!inputs) {
28
- return { inputs: {}, response_mode: "blocking", user: "anonymous" };
29
- }
30
- if (typeof inputs === "object" && ("inputs" in inputs || "response_mode" in inputs || "user" in inputs || "files" in inputs || "trace_id" in inputs)) {
31
- const req = inputs;
32
- return {
33
- inputs: req.inputs || {},
34
- response_mode: req.response_mode || "blocking",
35
- user: req.user || "anonymous",
36
- files: req.files,
37
- trace_id: req.trace_id
38
- };
39
- }
40
- return {
41
- inputs,
42
- response_mode: "blocking",
43
- user: "anonymous"
44
- };
45
- }
46
- function createWorkflowClient(http = httpClient.createHttpClient()) {
47
- return {
48
- async run(workflowName, inputs) {
49
- if (!workflowName || workflowName.includes("/")) {
50
- return {
51
- data: null,
52
- error: {
53
- status: 400,
54
- message: "Invalid workflowName: use workflow YAML filename without extension (no subpaths)"
55
- },
56
- status: 400
57
- };
58
- }
59
- const normalizedRequest = normalizeRunRequest(inputs);
60
- const appId = extractAppIdFromUrl();
61
- if (appId && normalizedRequest.inputs) {
62
- normalizedRequest.inputs.app_id = appId;
63
- }
64
- const response = await http.request({
65
- url: `/api/runworkflow/${workflowName}`,
66
- method: "post",
67
- headers: { "Content-Type": "application/json" },
68
- data: normalizedRequest
69
- });
70
- if (response.data?.data) {
71
- const innerData = response.data.data;
72
- return {
73
- ...response,
74
- data: {
75
- task_id: response.data.task_id || "",
76
- workflow_run_id: response.data.workflow_run_id || "",
77
- status: innerData.status || "unknown",
78
- outputs: innerData.outputs || {},
79
- error: innerData.error || null,
80
- elapsed_time: innerData.elapsed_time || 0,
81
- total_tokens: innerData.total_tokens || 0,
82
- total_steps: innerData.total_steps || 0,
83
- created_at: innerData.created_at || 0,
84
- finished_at: innerData.finished_at || 0
85
- }
86
- };
87
- }
88
- return {
89
- data: null,
90
- error: response.error || {
91
- status: response.status,
92
- message: "Invalid workflow response structure"
93
- },
94
- status: response.status
95
- };
96
- }
97
- };
98
- }
99
-
100
- exports.createWorkflowClient = createWorkflowClient;
101
- //# sourceMappingURL=index.cjs.map
1
+ 'use strict';var httpClient=require('@amaster.ai/http-client');function i(){if(typeof window>"u")return null;try{let t=window.location.href,e=/\/app\/([\da-f-]+)(?:\/|$)/.exec(t);if(e&&e[1])return e[1];let s=window.location.hostname,r=/^([\da-f-]+)(?:-[^.]+)?\.amaster\.(?:local|ai)$/.exec(s);return r&&r[1]?r[1]:null}catch{return null}}function l(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 e=t;return {inputs:e.inputs||{},response_mode:e.response_mode||"blocking",user:e.user||"anonymous",files:e.files,trace_id:e.trace_id}}return {inputs:t,response_mode:"blocking",user:"anonymous"}}function p(t=httpClient.createHttpClient()){return {async run(e,s){if(!e||e.includes("/"))return {data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400};let r=l(s),u=i();u&&r.inputs&&(r.inputs.app_id=u);let n=await t.request({url:`/api/runworkflow/${e}`,method:"post",headers:{"Content-Type":"application/json"},data:r});if(n.data?.data){let o=n.data.data;return {...n,data:{task_id:n.data.task_id||"",workflow_run_id:n.data.workflow_run_id||"",status:o.status||"unknown",outputs:o.outputs||{},error:o.error||null,elapsed_time:o.elapsed_time||0,total_tokens:o.total_tokens||0,total_steps:o.total_steps||0,created_at:o.created_at||0,finished_at:o.finished_at||0}}}return {data:null,error:n.error||{status:n.status,message:"Invalid workflow response structure"},status:n.status}}}}exports.createWorkflowClient=p;//# sourceMappingURL=index.cjs.map
102
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/workflow-client.ts"],"names":["createHttpClient"],"mappings":";;;;;AAOA,SAAS,mBAAA,GAAqC;AAC5C,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC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,IAAmB,EAAA;AAAA,YAClD,MAAA,EAAQ,UAAU,MAAA,IAAU,SAAA;AAAA,YAC5B,OAAA,EAAS,SAAA,CAAU,OAAA,IAAY,EAAC;AAAA,YAChC,KAAA,EAAO,UAAU,KAAA,IAAS,IAAA;AAAA,YAC1B,YAAA,EAAc,UAAU,YAAA,IAAgB,CAAA;AAAA,YACxC,YAAA,EAAc,UAAU,YAAA,IAAgB,CAAA;AAAA,YACxC,WAAA,EAAa,UAAU,WAAA,IAAe,CAAA;AAAA,YACtC,UAAA,EAAY,UAAU,UAAA,IAAc,CAAA;AAAA,YACpC,WAAA,EAAa,UAAU,WAAA,IAAe;AAAA;AACxC,SACF;AAAA,MACF;AAEA,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,IAAA;AAAA,QACN,KAAA,EAAO,SAAS,KAAA,IAAS;AAAA,UACvB,QAAQ,QAAA,CAAS,MAAA;AAAA,UACjB,OAAA,EAAS;AAAA,SACX;AAAA,QACA,QAAQ,QAAA,CAAS;AAAA,OACnB;AAAA,IACF;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\n\n/**\n * Extract app_id from current page URL or domain\n * Method 1: From URL path - /app/{app_id}/...\n * Method 2: From domain (subdomain) - {app_id}-{env}.amaster.local\n */\nfunction extractAppIdFromUrl(): string | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n try {\n // Method 1: Try to extract from URL path first\n const url = window.location.href;\n const pathMatch = /\\/app\\/([\\da-f-]+)(?:\\/|$)/.exec(url);\n if (pathMatch && pathMatch[1]) {\n return pathMatch[1];\n }\n\n // Method 2: Try to extract from domain (subdomain)\n const hostname = window.location.hostname;\n const domainMatch = /^([\\da-f-]+)(?:-[^.]+)?\\.amaster\\.(?:local|ai)$/.exec(hostname);\n if (domainMatch && domainMatch[1]) {\n return domainMatch[1];\n }\n\n return null;\n } catch {\n return null;\n }\n}\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\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(http: HttpClient = createHttpClient()): WorkflowClient {\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 // Auto-inject app_id from URL if not already provided\n const appId = extractAppIdFromUrl();\n if (appId && normalizedRequest.inputs) {\n normalizedRequest.inputs.app_id = appId;\n }\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: { \"Content-Type\": \"application/json\" },\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":["extractAppIdFromUrl","url","pathMatch","hostname","domainMatch","normalizeRunRequest","inputs","req","createWorkflowClient","http","createHttpClient","workflowName","normalizedRequest","appId","response","innerData"],"mappings":"+DAOA,SAASA,CAAAA,EAAqC,CAC5C,GAAI,OAAO,MAAA,CAAW,GAAA,CACpB,OAAO,IAAA,CAGT,GAAI,CAEF,IAAMC,CAAAA,CAAM,MAAA,CAAO,QAAA,CAAS,IAAA,CACtBC,CAAAA,CAAY,4BAAA,CAA6B,KAAKD,CAAG,CAAA,CACvD,GAAIC,CAAAA,EAAaA,CAAAA,CAAU,CAAC,CAAA,CAC1B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jB,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\n/**\n * Extract app_id from current page URL or domain\n * Method 1: From URL path - /app/{app_id}/...\n * Method 2: From domain (subdomain) - {app_id}-{env}.amaster.local\n */\nfunction extractAppIdFromUrl(): string | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n try {\n // Method 1: Try to extract from URL path first\n const url = window.location.href;\n const pathMatch = /\\/app\\/([\\da-f-]+)(?:\\/|$)/.exec(url);\n if (pathMatch && pathMatch[1]) {\n return pathMatch[1];\n }\n\n // Method 2: Try to extract from domain (subdomain)\n const hostname = window.location.hostname;\n const domainMatch = /^([\\da-f-]+)(?:-[^.]+)?\\.amaster\\.(?:local|ai)$/.exec(hostname);\n if (domainMatch && domainMatch[1]) {\n return domainMatch[1];\n }\n\n return null;\n } catch {\n return null;\n }\n}\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\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(http: HttpClient = createHttpClient()): WorkflowClient {\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 // Auto-inject app_id from URL if not already provided\n const appId = extractAppIdFromUrl();\n if (appId && normalizedRequest.inputs) {\n normalizedRequest.inputs.app_id = appId;\n }\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: { \"Content-Type\": \"application/json\" },\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.js CHANGED
@@ -1,100 +1,2 @@
1
- import { createHttpClient } from '@amaster.ai/http-client';
2
-
3
- // src/workflow-client.ts
4
- function extractAppIdFromUrl() {
5
- if (typeof window === "undefined") {
6
- return null;
7
- }
8
- try {
9
- const url = window.location.href;
10
- const pathMatch = /\/app\/([\da-f-]+)(?:\/|$)/.exec(url);
11
- if (pathMatch && pathMatch[1]) {
12
- return pathMatch[1];
13
- }
14
- const hostname = window.location.hostname;
15
- const domainMatch = /^([\da-f-]+)(?:-[^.]+)?\.amaster\.(?:local|ai)$/.exec(hostname);
16
- if (domainMatch && domainMatch[1]) {
17
- return domainMatch[1];
18
- }
19
- return null;
20
- } catch {
21
- return null;
22
- }
23
- }
24
- function normalizeRunRequest(inputs) {
25
- if (!inputs) {
26
- return { inputs: {}, response_mode: "blocking", user: "anonymous" };
27
- }
28
- if (typeof inputs === "object" && ("inputs" in inputs || "response_mode" in inputs || "user" in inputs || "files" in inputs || "trace_id" in inputs)) {
29
- const req = inputs;
30
- return {
31
- inputs: req.inputs || {},
32
- response_mode: req.response_mode || "blocking",
33
- user: req.user || "anonymous",
34
- files: req.files,
35
- trace_id: req.trace_id
36
- };
37
- }
38
- return {
39
- inputs,
40
- response_mode: "blocking",
41
- user: "anonymous"
42
- };
43
- }
44
- function createWorkflowClient(http = createHttpClient()) {
45
- return {
46
- async run(workflowName, inputs) {
47
- if (!workflowName || workflowName.includes("/")) {
48
- return {
49
- data: null,
50
- error: {
51
- status: 400,
52
- message: "Invalid workflowName: use workflow YAML filename without extension (no subpaths)"
53
- },
54
- status: 400
55
- };
56
- }
57
- const normalizedRequest = normalizeRunRequest(inputs);
58
- const appId = extractAppIdFromUrl();
59
- if (appId && normalizedRequest.inputs) {
60
- normalizedRequest.inputs.app_id = appId;
61
- }
62
- const response = await http.request({
63
- url: `/api/runworkflow/${workflowName}`,
64
- method: "post",
65
- headers: { "Content-Type": "application/json" },
66
- data: normalizedRequest
67
- });
68
- if (response.data?.data) {
69
- const innerData = response.data.data;
70
- return {
71
- ...response,
72
- data: {
73
- task_id: response.data.task_id || "",
74
- workflow_run_id: response.data.workflow_run_id || "",
75
- status: innerData.status || "unknown",
76
- outputs: innerData.outputs || {},
77
- error: innerData.error || null,
78
- elapsed_time: innerData.elapsed_time || 0,
79
- total_tokens: innerData.total_tokens || 0,
80
- total_steps: innerData.total_steps || 0,
81
- created_at: innerData.created_at || 0,
82
- finished_at: innerData.finished_at || 0
83
- }
84
- };
85
- }
86
- return {
87
- data: null,
88
- error: response.error || {
89
- status: response.status,
90
- message: "Invalid workflow response structure"
91
- },
92
- status: response.status
93
- };
94
- }
95
- };
96
- }
97
-
98
- export { createWorkflowClient };
99
- //# sourceMappingURL=index.js.map
1
+ import {createHttpClient}from'@amaster.ai/http-client';function i(){if(typeof window>"u")return null;try{let t=window.location.href,e=/\/app\/([\da-f-]+)(?:\/|$)/.exec(t);if(e&&e[1])return e[1];let s=window.location.hostname,r=/^([\da-f-]+)(?:-[^.]+)?\.amaster\.(?:local|ai)$/.exec(s);return r&&r[1]?r[1]:null}catch{return null}}function l(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 e=t;return {inputs:e.inputs||{},response_mode:e.response_mode||"blocking",user:e.user||"anonymous",files:e.files,trace_id:e.trace_id}}return {inputs:t,response_mode:"blocking",user:"anonymous"}}function p(t=createHttpClient()){return {async run(e,s){if(!e||e.includes("/"))return {data:null,error:{status:400,message:"Invalid workflowName: use workflow YAML filename without extension (no subpaths)"},status:400};let r=l(s),u=i();u&&r.inputs&&(r.inputs.app_id=u);let n=await t.request({url:`/api/runworkflow/${e}`,method:"post",headers:{"Content-Type":"application/json"},data:r});if(n.data?.data){let o=n.data.data;return {...n,data:{task_id:n.data.task_id||"",workflow_run_id:n.data.workflow_run_id||"",status:o.status||"unknown",outputs:o.outputs||{},error:o.error||null,elapsed_time:o.elapsed_time||0,total_tokens:o.total_tokens||0,total_steps:o.total_steps||0,created_at:o.created_at||0,finished_at:o.finished_at||0}}}return {data:null,error:n.error||{status:n.status,message:"Invalid workflow response structure"},status:n.status}}}}export{p as createWorkflowClient};//# sourceMappingURL=index.js.map
100
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/workflow-client.ts"],"names":[],"mappings":";;;AAOA,SAAS,mBAAA,GAAqC;AAC5C,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAI;AAEF,IAAA,MAAM,GAAA,GAAM,OAAO,QAAA,CAAS,IAAA;AAC5B,IAAA,MAAM,SAAA,GAAY,4BAAA,CAA6B,IAAA,CAAK,GAAG,CAAA;AACvD,IAAA,IAAI,SAAA,IAAa,SAAA,CAAU,CAAC,CAAA,EAAG;AAC7B,MAAA,OAAO,UAAU,CAAC,CAAA;AAAA,IACpB;AAGA,IAAA,MAAM,QAAA,GAAW,OAAO,QAAA,CAAS,QAAA;AACjC,IAAA,MAAM,WAAA,GAAc,iDAAA,CAAkD,IAAA,CAAK,QAAQ,CAAA;AACnF,IAAA,IAAI,WAAA,IAAe,WAAA,CAAY,CAAC,CAAA,EAAG;AACjC,MAAA,OAAO,YAAY,CAAC,CAAA;AAAA,IACtB;AAEA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAgDA,SAAS,oBACP,MAAA,EACoB;AACpB,EAAA,IAAI,CAAC,MA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index.js","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\n\n/**\n * Extract app_id from current page URL or domain\n * Method 1: From URL path - /app/{app_id}/...\n * Method 2: From domain (subdomain) - {app_id}-{env}.amaster.local\n */\nfunction extractAppIdFromUrl(): string | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n try {\n // Method 1: Try to extract from URL path first\n const url = window.location.href;\n const pathMatch = /\\/app\\/([\\da-f-]+)(?:\\/|$)/.exec(url);\n if (pathMatch && pathMatch[1]) {\n return pathMatch[1];\n }\n\n // Method 2: Try to extract from domain (subdomain)\n const hostname = window.location.hostname;\n const domainMatch = /^([\\da-f-]+)(?:-[^.]+)?\\.amaster\\.(?:local|ai)$/.exec(hostname);\n if (domainMatch && domainMatch[1]) {\n return domainMatch[1];\n }\n\n return null;\n } catch {\n return null;\n }\n}\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\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(http: HttpClient = createHttpClient()): WorkflowClient {\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 // Auto-inject app_id from URL if not already provided\n const appId = extractAppIdFromUrl();\n if (appId && normalizedRequest.inputs) {\n normalizedRequest.inputs.app_id = appId;\n }\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: { \"Content-Type\": \"application/json\" },\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":["extractAppIdFromUrl","url","pathMatch","hostname","domainMatch","normalizeRunRequest","inputs","req","createWorkflowClient","http","createHttpClient","workflowName","normalizedRequest","appId","response","innerData"],"mappings":"uDAOA,SAASA,CAAAA,EAAqC,CAC5C,GAAI,OAAO,MAAA,CAAW,GAAA,CACpB,OAAO,IAAA,CAGT,GAAI,CAEF,IAAMC,CAAAA,CAAM,MAAA,CAAO,QAAA,CAAS,IAAA,CACtBC,CAAAA,CAAY,4BAAA,CAA6B,KAAKD,CAAG,CAAA,CACvD,GAAIC,CAAAA,EAAaA,CAAAA,CAAU,CAAC,CAAA,CAC1B,OAAOA,EAAU,CAAC,CAAA,CAIpB,IAAMC,CAAAA,CAAW,MAAA,CAAO,QAAA,CAAS,QAAA,CAC3BC,CAAAA,CAAc,iDAAA,CAAkD,IAAA,CAAKD,CAAQ,CAAA,CACnF,OAAIC,CAAAA,EAAeA,CAAAA,CAAY,CAAC,EACvBA,CAAAA,CAAY,CAAC,CAAA,CAGf,IACT,CAAA,KAAQ,CACN,OAAO,IACT,CACF,CAgDA,SAASC,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,GACnB,MAAA,GAAUA,CAAAA,EACV,OAAA,GAAWA,CAAAA,EACX,UAAA,GAAcA,CAAAA,CAAAA,CAChB,CACA,IAAMC,EAAMD,CAAAA,CACZ,OAAO,CACL,MAAA,CAAQC,CAAAA,CAA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,eAAA,CAAiBA,CAAAA,CAAS,IAAA,CAAK,eAAA,EAAmB,EAAA,CAClD,OAAQC,CAAAA,CAAU,MAAA,EAAU,SAAA,CAC5B,OAAA,CAASA,CAAAA,CAAU,OAAA,EAAY,EAAC,CAChC,MAAOA,CAAAA,CAAU,KAAA,EAAS,IAAA,CAC1B,YAAA,CAAcA,CAAAA,CAAU,YAAA,EAAgB,CAAA,CACxC,YAAA,CAAcA,EAAU,YAAA,EAAgB,CAAA,CACxC,WAAA,CAAaA,CAAAA,CAAU,WAAA,EAAe,CAAA,CACtC,UAAA,CAAYA,CAAAA,CAAU,YAAc,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,EAAS,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\n/**\n * Extract app_id from current page URL or domain\n * Method 1: From URL path - /app/{app_id}/...\n * Method 2: From domain (subdomain) - {app_id}-{env}.amaster.local\n */\nfunction extractAppIdFromUrl(): string | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n try {\n // Method 1: Try to extract from URL path first\n const url = window.location.href;\n const pathMatch = /\\/app\\/([\\da-f-]+)(?:\\/|$)/.exec(url);\n if (pathMatch && pathMatch[1]) {\n return pathMatch[1];\n }\n\n // Method 2: Try to extract from domain (subdomain)\n const hostname = window.location.hostname;\n const domainMatch = /^([\\da-f-]+)(?:-[^.]+)?\\.amaster\\.(?:local|ai)$/.exec(hostname);\n if (domainMatch && domainMatch[1]) {\n return domainMatch[1];\n }\n\n return null;\n } catch {\n return null;\n }\n}\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\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(http: HttpClient = createHttpClient()): WorkflowClient {\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 // Auto-inject app_id from URL if not already provided\n const appId = extractAppIdFromUrl();\n if (appId && normalizedRequest.inputs) {\n normalizedRequest.inputs.app_id = appId;\n }\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: { \"Content-Type\": \"application/json\" },\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.0.0-beta.0",
3
+ "version": "1.0.0-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.0.0-beta.0"
33
+ "@amaster.ai/http-client": "1.0.0-beta.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "axios": "^1.11.0"