@vwork/cli 0.1.2 → 0.1.4
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/codegen.js +45 -10
- package/dist/functions.js +1 -1
- package/dist/index.js +15 -2
- package/dist/observability.js +7 -1
- package/dist/oclif-command.js +2 -0
- package/package.json +30 -30
package/dist/codegen.js
CHANGED
|
@@ -36,16 +36,32 @@ export async function runCodegenCommand(command, client, config) {
|
|
|
36
36
|
const bindingNames = arrayFlag(command.flags.binding);
|
|
37
37
|
const sourceCode = stringFlag(command.flags["source-code"]);
|
|
38
38
|
const draftInvoke = draftInvokeInput(command);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
const session = await client.request("POST", `${appPath}/codegen-sessions`, {
|
|
40
|
+
target: `workerd_function:${functionName}`,
|
|
41
|
+
title: `${functionName} codegen`,
|
|
42
|
+
description: prompt
|
|
43
|
+
});
|
|
44
|
+
const requestBody = {
|
|
45
|
+
session_id: String(session.id),
|
|
46
|
+
prompt,
|
|
47
|
+
auth_required: command.flags["no-auth"] === true ? false : true,
|
|
48
|
+
...(bindingNames.length > 0 ? { binding_names: bindingNames } : {}),
|
|
49
|
+
...(sourceCode ? { source_code: sourceCode } : {}),
|
|
50
|
+
...(command.flags.repair === true ? { repair: { enabled: true, max_attempts: 2 } } : {}),
|
|
51
|
+
...(draftInvoke ? { draft_invoke: draftInvoke } : {})
|
|
48
52
|
};
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
value: await client.request("POST", `${appPath}/functions/${encodeURIComponent(functionName)}/codegen`, requestBody)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (!isGatewayTimeout(error))
|
|
60
|
+
throw error;
|
|
61
|
+
return {
|
|
62
|
+
value: await waitForCodegenSessionRun(client, appPath, String(session.id))
|
|
63
|
+
};
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
66
|
if (group === "runs" && action === "list") {
|
|
51
67
|
const body = await client.request("GET", `${appPath}/code-generations`);
|
|
@@ -100,7 +116,8 @@ function draftInvokeInput(command) {
|
|
|
100
116
|
return {
|
|
101
117
|
enabled: true,
|
|
102
118
|
...(body ? { body } : {}),
|
|
103
|
-
...(bindings ? { bindings } : {})
|
|
119
|
+
...(bindings ? { bindings } : {}),
|
|
120
|
+
response_contract: "vwork_function_output_v1"
|
|
104
121
|
};
|
|
105
122
|
}
|
|
106
123
|
function optionalJsonObjectFlag(command, key) {
|
|
@@ -113,6 +130,24 @@ function optionalJsonObjectFlag(command, key) {
|
|
|
113
130
|
}
|
|
114
131
|
return parsed;
|
|
115
132
|
}
|
|
133
|
+
async function waitForCodegenSessionRun(client, appPath, sessionId) {
|
|
134
|
+
const deadline = Date.now() + 180_000;
|
|
135
|
+
let lastRuns = [];
|
|
136
|
+
do {
|
|
137
|
+
const body = await client.request("GET", `${appPath}/codegen-sessions/${encodeURIComponent(sessionId)}/runs`);
|
|
138
|
+
lastRuns = body.code_generations;
|
|
139
|
+
if (lastRuns.length > 0)
|
|
140
|
+
return lastRuns[0];
|
|
141
|
+
await sleep(3_000);
|
|
142
|
+
} while (Date.now() < deadline);
|
|
143
|
+
throw new Error(`Timed out waiting for codegen run in session ${sessionId}`);
|
|
144
|
+
}
|
|
145
|
+
function isGatewayTimeout(error) {
|
|
146
|
+
return Boolean(error && typeof error === "object" && "status" in error && error.status === 524);
|
|
147
|
+
}
|
|
148
|
+
function sleep(ms) {
|
|
149
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
150
|
+
}
|
|
116
151
|
function mcpConfigSnippet(command, config) {
|
|
117
152
|
const workspace = stringFlag(command.flags.workspace) ?? process.cwd();
|
|
118
153
|
const appId = stringFlag(command.flags.app) ?? config.appId;
|
package/dist/functions.js
CHANGED
|
@@ -108,7 +108,7 @@ async function runFunctionRouteCommand(command, client, appPath) {
|
|
|
108
108
|
const basePath = `${appPath}/function-routes`;
|
|
109
109
|
if (action === "list") {
|
|
110
110
|
const body = await client.request("GET", basePath);
|
|
111
|
-
return { rows: body.routes };
|
|
111
|
+
return { rows: body.function_routes ?? body.routes ?? [] };
|
|
112
112
|
}
|
|
113
113
|
if (action === "add" || action === "create") {
|
|
114
114
|
const functionName = stringFlag(command.flags.function) ?? requiredPosition(command, 0, "function name");
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
2
4
|
import { fileURLToPath } from "node:url";
|
|
3
5
|
import { runOclifCli } from "./oclif-command.js";
|
|
4
6
|
export async function runCli(argv, env, cwd) {
|
|
@@ -8,10 +10,21 @@ export async function runCli(argv, env, cwd) {
|
|
|
8
10
|
export function isDirectCliEntrypoint(moduleUrl, argvPath) {
|
|
9
11
|
if (!argvPath)
|
|
10
12
|
return false;
|
|
11
|
-
|
|
13
|
+
const argvPaths = new Set(candidatePaths(argvPath));
|
|
14
|
+
return candidatePaths(fileURLToPath(moduleUrl)).some((candidate) => argvPaths.has(candidate));
|
|
12
15
|
}
|
|
13
16
|
function normalizePath(value) {
|
|
14
|
-
return value.replace(/\\/g, "/");
|
|
17
|
+
return resolve(value).replace(/\\/g, "/").toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
function candidatePaths(value) {
|
|
20
|
+
const paths = new Set([normalizePath(value)]);
|
|
21
|
+
try {
|
|
22
|
+
paths.add(normalizePath(realpathSync.native(value)));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Keep the direct normalized path when realpath cannot resolve.
|
|
26
|
+
}
|
|
27
|
+
return [...paths];
|
|
15
28
|
}
|
|
16
29
|
function withRuntime(env, cwd, run) {
|
|
17
30
|
const originalEnv = process.env;
|
package/dist/observability.js
CHANGED
|
@@ -4,7 +4,7 @@ export async function runObservabilityCommand(command, client) {
|
|
|
4
4
|
if (action === "access-logs") {
|
|
5
5
|
const query = new URLSearchParams();
|
|
6
6
|
const source = stringFlag(command.flags.source);
|
|
7
|
-
const app = stringFlag(command.flags.app);
|
|
7
|
+
const app = await resolveAppId(client, stringFlag(command.flags.app));
|
|
8
8
|
const limit = stringFlag(command.flags.limit);
|
|
9
9
|
if (source)
|
|
10
10
|
query.set("source", source);
|
|
@@ -18,3 +18,9 @@ export async function runObservabilityCommand(command, client) {
|
|
|
18
18
|
}
|
|
19
19
|
throw new Error(`Unknown observability command: ${action ?? ""}`);
|
|
20
20
|
}
|
|
21
|
+
async function resolveAppId(client, target) {
|
|
22
|
+
if (!target)
|
|
23
|
+
return undefined;
|
|
24
|
+
const app = await client.request("GET", `/apps/lookup/${encodeURIComponent(target)}`);
|
|
25
|
+
return String(app.id);
|
|
26
|
+
}
|
package/dist/oclif-command.js
CHANGED
|
@@ -228,6 +228,8 @@ function maxPathLength(path) {
|
|
|
228
228
|
return 3;
|
|
229
229
|
if (path[0] === "functions" && path[1] === "previews")
|
|
230
230
|
return 3;
|
|
231
|
+
if (path[0] === "functions" && path[1] === "routes")
|
|
232
|
+
return 3;
|
|
231
233
|
if (path[0] === "functions" && path[1] === "queue-bindings")
|
|
232
234
|
return 3;
|
|
233
235
|
return 2;
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vwork/cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"files": [
|
|
6
|
-
"dist/*.js",
|
|
7
|
-
"dist/auth/*.js",
|
|
8
|
-
"package.json"
|
|
9
|
-
],
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"registry": "https://registry.npmjs.org/"
|
|
12
|
-
},
|
|
13
|
-
"bin": {
|
|
14
|
-
"vwork": "dist/index.js"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
1
|
+
{
|
|
2
|
+
"name": "@vwork/cli",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist/*.js",
|
|
7
|
+
"dist/auth/*.js",
|
|
8
|
+
"package.json"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://registry.npmjs.org/"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"vwork": "dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "tsx src/index.ts",
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"test": "pnpm --filter @vwork/platform-client build && tsx --test src/test/*.test.ts",
|
|
20
|
+
"typecheck": "pnpm --filter @vwork/platform-client build && tsc -p tsconfig.json --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@oclif/core": "^4.11.7",
|
|
18
24
|
"@vwork/platform-client": "^0.1.0"
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@types/node": "^22.10.2",
|
|
22
|
-
"tsx": "^4.19.2",
|
|
23
|
-
"typescript": "^5.7.2"
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
"dev": "tsx src/index.ts",
|
|
27
|
-
"build": "tsc -p tsconfig.json",
|
|
28
|
-
"test": "pnpm --filter @vwork/platform-client build && tsx --test src/test/*.test.ts",
|
|
29
|
-
"typecheck": "pnpm --filter @vwork/platform-client build && tsc -p tsconfig.json --noEmit"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.10.2",
|
|
28
|
+
"tsx": "^4.19.2",
|
|
29
|
+
"typescript": "^5.7.2"
|
|
30
|
+
}
|
|
31
|
+
}
|