@meetploy/emulator 1.16.0 → 1.17.1
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.
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { readPloyConfigSync, getWorkerEntryPoint as sharedGetWorkerEntryPoint, getWorkflowName, getWorkflowTimeout, getWorkflowStepTimeout, getWorkflowRetries, DEFAULT_WORKFLOW_TIMEOUT_S, DEFAULT_STEP_TIMEOUT_S, DEFAULT_RETRIES, hasBindings as sharedHasBindings, } from "@meetploy/tools/cli";
|
|
1
|
+
import { readPloyConfigSync, getWorkerEntryPoint as sharedGetWorkerEntryPoint, getWorkflowName, getWorkflowTimeout, getWorkflowStepTimeout, getWorkflowRetries, DEFAULT_WORKFLOW_TIMEOUT_S, DEFAULT_STEP_TIMEOUT_S, DEFAULT_RETRIES, hasBindings as sharedHasBindings, resolveAgentSDKBindings, } from "@meetploy/tools/cli";
|
|
2
2
|
export { getWorkflowName, getWorkflowTimeout, getWorkflowStepTimeout, getWorkflowRetries, DEFAULT_WORKFLOW_TIMEOUT_S, DEFAULT_STEP_TIMEOUT_S, DEFAULT_RETRIES, };
|
|
3
3
|
export function readPloyConfig(projectDir, configPath) {
|
|
4
|
-
const
|
|
5
|
-
if (!
|
|
4
|
+
const raw = readPloyConfigSync(projectDir, configPath);
|
|
5
|
+
if (!raw.kind) {
|
|
6
6
|
throw new Error(`Missing required field 'kind' in ${configPath ?? "ploy.yaml"}`);
|
|
7
7
|
}
|
|
8
|
-
if (
|
|
9
|
-
throw new Error(`Invalid kind '${
|
|
8
|
+
if (raw.kind !== "dynamic" && raw.kind !== "worker") {
|
|
9
|
+
throw new Error(`Invalid kind '${raw.kind}' in ${configPath ?? "ploy.yaml"}. Must be 'dynamic' or 'worker'`);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return resolveAgentSDKBindings(raw);
|
|
12
12
|
}
|
|
13
13
|
export function getWorkerEntryPoint(projectDir, config) {
|
|
14
14
|
return sharedGetWorkerEntryPoint(projectDir, config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ploy-config.js","sourceRoot":"","sources":["../../src/config/ploy-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,kBAAkB,EAClB,mBAAmB,IAAI,yBAAyB,EAChD,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EACf,WAAW,IAAI,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ploy-config.js","sourceRoot":"","sources":["../../src/config/ploy-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,kBAAkB,EAClB,mBAAmB,IAAI,yBAAyB,EAChD,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EACf,WAAW,IAAI,iBAAiB,EAChC,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,GACf,CAAC;AAEF,MAAM,UAAU,cAAc,CAC7B,UAAkB,EAClB,UAAmB;IAEnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEvD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACd,oCAAoC,UAAU,IAAI,WAAW,EAAE,CAC/D,CAAC;IACH,CAAC;IAED,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACd,iBAAiB,GAAG,CAAC,IAAI,QAAQ,UAAU,IAAI,WAAW,iCAAiC,CAC3F,CAAC;IACH,CAAC;IAGD,OAAO,uBAAuB,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAClC,UAAkB,EAClB,MAAkB;IAElB,OAAO,yBAAyB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC7C,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const STATE_RUNTIME_CODE = "\ninterface StateUpdateDoc {\n $set?: Record<string, unknown>;\n $unset?: Record<string, unknown>;\n $inc?: Record<string, number>;\n $push?: Record<string, unknown>;\n $pop?: Record<string, 1 | -1>;\n}\n\ninterface StateBinding {\n get: (key: string) => Promise<string | null>;\n set: (key: string, value: string) => Promise<void>;\n delete: (key: string) => Promise<void>;\n update: (key: string, update: StateUpdateDoc) => Promise<void>;\n}\n\
|
|
1
|
+
export declare const STATE_RUNTIME_CODE = "\ninterface StateUpdateDoc {\n $set?: Record<string, unknown>;\n $unset?: Record<string, unknown>;\n $inc?: Record<string, number>;\n $push?: Record<string, unknown>;\n $pop?: Record<string, 1 | -1>;\n}\n\ninterface StateBinding {\n get: (key: string) => Promise<string | null>;\n set: (key: string, value: string) => Promise<void>;\n delete: (key: string) => Promise<void>;\n update: (key: string, update: StateUpdateDoc) => Promise<void>;\n}\n\nfunction getErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction createStateRequestError(action: string, endpoint: string, error: unknown): Error {\n const message = \"State \" + action + \" failed while calling \" + endpoint + \": \" + getErrorMessage(error);\n if (error instanceof Error) {\n return new Error(message, { cause: error });\n }\n return new Error(message);\n}\n\nasync function requestState(action: string, serviceUrl: string, payload: Record<string, unknown>): Promise<Response> {\n const endpoint = serviceUrl + \"/state/\" + action;\n let response: Response;\n\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(payload),\n });\n } catch (error) {\n throw createStateRequestError(action, endpoint, error);\n }\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n \"State \" + action + \" failed (status \" + response.status + \" \" + response.statusText + \") from \" + endpoint + \": \" + (errorText || \"empty response body\"),\n );\n }\n\n return response;\n}\n\nexport function initializeState(stateName: string, serviceUrl: string): StateBinding {\n return {\n async get(key: string): Promise<string | null> {\n const response = await requestState(\"get\", serviceUrl, { stateName, key });\n const result = await response.json();\n return result.value ?? null;\n },\n\n async set(key: string, value: string): Promise<void> {\n await requestState(\"set\", serviceUrl, { stateName, key, value });\n },\n\n async delete(key: string): Promise<void> {\n await requestState(\"delete\", serviceUrl, { stateName, key });\n },\n\n async update(key: string, update: StateUpdateDoc): Promise<void> {\n await requestState(\"update\", serviceUrl, { stateName, key, update });\n },\n };\n}\n";
|
|
@@ -14,61 +14,60 @@ interface StateBinding {
|
|
|
14
14
|
update: (key: string, update: StateUpdateDoc) => Promise<void>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function getErrorMessage(error: unknown): string {
|
|
18
|
+
return error instanceof Error ? error.message : String(error);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createStateRequestError(action: string, endpoint: string, error: unknown): Error {
|
|
22
|
+
const message = "State " + action + " failed while calling " + endpoint + ": " + getErrorMessage(error);
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
return new Error(message, { cause: error });
|
|
25
|
+
}
|
|
26
|
+
return new Error(message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function requestState(action: string, serviceUrl: string, payload: Record<string, unknown>): Promise<Response> {
|
|
30
|
+
const endpoint = serviceUrl + "/state/" + action;
|
|
31
|
+
let response: Response;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
response = await fetch(endpoint, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: { "Content-Type": "application/json" },
|
|
37
|
+
body: JSON.stringify(payload),
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw createStateRequestError(action, endpoint, error);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const errorText = await response.text();
|
|
45
|
+
throw new Error(
|
|
46
|
+
"State " + action + " failed (status " + response.status + " " + response.statusText + ") from " + endpoint + ": " + (errorText || "empty response body"),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return response;
|
|
51
|
+
}
|
|
52
|
+
|
|
17
53
|
export function initializeState(stateName: string, serviceUrl: string): StateBinding {
|
|
18
54
|
return {
|
|
19
55
|
async get(key: string): Promise<string | null> {
|
|
20
|
-
const response = await
|
|
21
|
-
method: "POST",
|
|
22
|
-
headers: { "Content-Type": "application/json" },
|
|
23
|
-
body: JSON.stringify({ stateName, key }),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (!response.ok) {
|
|
27
|
-
const errorText = await response.text();
|
|
28
|
-
throw new Error("State get failed: " + errorText);
|
|
29
|
-
}
|
|
30
|
-
|
|
56
|
+
const response = await requestState("get", serviceUrl, { stateName, key });
|
|
31
57
|
const result = await response.json();
|
|
32
58
|
return result.value ?? null;
|
|
33
59
|
},
|
|
34
60
|
|
|
35
61
|
async set(key: string, value: string): Promise<void> {
|
|
36
|
-
|
|
37
|
-
method: "POST",
|
|
38
|
-
headers: { "Content-Type": "application/json" },
|
|
39
|
-
body: JSON.stringify({ stateName, key, value }),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
const errorText = await response.text();
|
|
44
|
-
throw new Error("State set failed: " + errorText);
|
|
45
|
-
}
|
|
62
|
+
await requestState("set", serviceUrl, { stateName, key, value });
|
|
46
63
|
},
|
|
47
64
|
|
|
48
65
|
async delete(key: string): Promise<void> {
|
|
49
|
-
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers: { "Content-Type": "application/json" },
|
|
52
|
-
body: JSON.stringify({ stateName, key }),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
const errorText = await response.text();
|
|
57
|
-
throw new Error("State delete failed: " + errorText);
|
|
58
|
-
}
|
|
66
|
+
await requestState("delete", serviceUrl, { stateName, key });
|
|
59
67
|
},
|
|
60
68
|
|
|
61
69
|
async update(key: string, update: StateUpdateDoc): Promise<void> {
|
|
62
|
-
|
|
63
|
-
method: "POST",
|
|
64
|
-
headers: { "Content-Type": "application/json" },
|
|
65
|
-
body: JSON.stringify({ stateName, key, update }),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (!response.ok) {
|
|
69
|
-
const errorText = await response.text();
|
|
70
|
-
throw new Error("State update failed: " + errorText);
|
|
71
|
-
}
|
|
70
|
+
await requestState("update", serviceUrl, { stateName, key, update });
|
|
72
71
|
},
|
|
73
72
|
};
|
|
74
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-runtime.js","sourceRoot":"","sources":["../../src/runtime/state-runtime.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG
|
|
1
|
+
{"version":3,"file":"state-runtime.js","sourceRoot":"","sources":["../../src/runtime/state-runtime.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyEjC,CAAC"}
|