@method-ai-hq/sdk 0.18.1 → 0.18.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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
MIT-licensed JavaScript API and the `method` CLI. Source and releases: https://github.com/method-ai-hq/method-sdk
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npm install https://github.com/method-ai-hq/method-sdk/releases/download/v0.18.
|
|
6
|
+
npm install https://github.com/method-ai-hq/method-sdk/releases/download/v0.18.2/method-ai-hq-sdk-0.18.2.tgz
|
|
7
7
|
npx method --version
|
|
8
8
|
```
|
|
9
9
|
|
|
@@ -60,9 +60,6 @@ export async function runCurrentFile(file, flags, syncFactory, onEvent, client =
|
|
|
60
60
|
const json = (path) => path ? JSON.parse(readFileSync(authoringPath(path), "utf8")) : undefined;
|
|
61
61
|
if (flags.resume)
|
|
62
62
|
assertCheckpointExecutor(json(join(flags['run-dir'], 'checkpoint.json')));
|
|
63
|
-
const setup = await localSetup(file, flags, baseConfig);
|
|
64
|
-
let config = setup.config;
|
|
65
|
-
const sourceRoot = setup.sourceRoot;
|
|
66
63
|
const method = (await import('./authoring.js')).readDocument(file);
|
|
67
64
|
const controller = new AbortController();
|
|
68
65
|
const stop = () => controller.abort(Object.assign(new Error("Interrupted by operator"), { code: "interrupted" }));
|
|
@@ -87,6 +84,9 @@ export async function runCurrentFile(file, flags, syncFactory, onEvent, client =
|
|
|
87
84
|
}
|
|
88
85
|
catch { /* the run's setup failure */ }
|
|
89
86
|
await sync?.start(method, inputs, {}, false);
|
|
87
|
+
const setup = await localSetup(file, flags, baseConfig);
|
|
88
|
+
let config = setup.config;
|
|
89
|
+
const sourceRoot = setup.sourceRoot;
|
|
90
90
|
// A run with its own OpenRouter key (config.classification.api_key_env) needs no Method sign-in for classification.
|
|
91
91
|
const needs = accountNeeds(method, config);
|
|
92
92
|
const classification = needs.classification ? managedClassification(client) : undefined;
|
|
@@ -85,12 +85,12 @@ async function accountSync(path, flags) {
|
|
|
85
85
|
return { client, outbox, version, sync: () => new Sync(client, runDir, state.workflow_id, state.version_id, state.id, readDocument(path).run_data === "device", outbox) };
|
|
86
86
|
}
|
|
87
87
|
const method = readDocument(path);
|
|
88
|
-
|
|
89
|
-
const needs = accountNeeds(method, setup.config);
|
|
90
|
-
if (needs
|
|
88
|
+
// A setup that fails here fails the run too, and the run sends its failed record.
|
|
89
|
+
const needs = await localSetup(path, flags).then(setup => accountNeeds(method, setup.config), () => undefined);
|
|
90
|
+
if (needs?.classification && !client.token())
|
|
91
91
|
await client.login();
|
|
92
92
|
if (!client.token()) {
|
|
93
|
-
process.stderr.write(`Sign in to keep versions and runs in your account${needs
|
|
93
|
+
process.stderr.write(`Sign in to keep versions and runs in your account${needs?.models ? " and to use hosted models" : ""}: method login\n`);
|
|
94
94
|
return undefined;
|
|
95
95
|
}
|
|
96
96
|
const version = await prepareVersion(client, outbox, path);
|
|
@@ -4,7 +4,7 @@ import runtimeInfo from '@withmethod/runtime/package.json' with { type: 'json' }
|
|
|
4
4
|
import { startRunWorker, waitForRun, cancelRun, workerAlive } from './run-worker.js';
|
|
5
5
|
import { methodCache } from './prepare.js';
|
|
6
6
|
import { restorePackage } from './method-files.js';
|
|
7
|
-
import { publish } from './versions.js';
|
|
7
|
+
import { publish, methodContent } from './versions.js';
|
|
8
8
|
import { runSaved } from './run-saved.js';
|
|
9
9
|
import { bindInput, bindConnection } from './bindings.js';
|
|
10
10
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
@@ -24,6 +24,18 @@ import { methodHelp, overviewHelp as help } from "./method-help.js";
|
|
|
24
24
|
function safePath(path) {
|
|
25
25
|
return authoringPath(path);
|
|
26
26
|
}
|
|
27
|
+
/** A run target that can save a version: a saved Method (ID or link), or a Method file that loads. */
|
|
28
|
+
function loads(target) {
|
|
29
|
+
if (!target || !existsSync(target))
|
|
30
|
+
return true;
|
|
31
|
+
try {
|
|
32
|
+
loadWorkflow(methodContent(readDocument(target)));
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
27
39
|
async function dispatchRunWorker(args, flags, extra = [], savedClient) {
|
|
28
40
|
if (process.env.METHOD_RUN_WORKER === '1' || (!/[/\\]method\.(?:js|ts)$/.test(process.argv[1] ?? '') && !flags.background))
|
|
29
41
|
return false;
|
|
@@ -44,8 +56,9 @@ async function dispatchRunWorker(args, flags, extra = [], savedClient) {
|
|
|
44
56
|
const resolved = await withInputsFrom(flags, directory, /\.method$/i.test(args[1] ?? '') ? args[1] : undefined, client);
|
|
45
57
|
workerArgs = [...withoutOptions(workerArgs, ['inputs-from', 'inputs']), '--inputs', resolved.inputs];
|
|
46
58
|
}
|
|
47
|
-
// A new run of a signed-in computer is synced; a resumed run keeps the link that it has.
|
|
48
|
-
|
|
59
|
+
// A new run of a signed-in computer is synced; a resumed run keeps the link that it has. A Method file that does not
|
|
60
|
+
// load saves no version, so its run sends no record and gets no link.
|
|
61
|
+
const server = !flags.resume && client?.token() && loads(args[1]) ? client.server : undefined;
|
|
49
62
|
await startRunWorker(workerArgs, directory, flags.background, server);
|
|
50
63
|
return true;
|
|
51
64
|
}
|
|
@@ -48,10 +48,17 @@ export async function runSaved(saved, flags, client) {
|
|
|
48
48
|
return completed;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
flags = await withInputsFrom(flags, directory, undefined, client);
|
|
52
51
|
const inputFile = join(directory, 'requested-inputs.json');
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
// The start line already linked to this run: inputs that cannot be read fail it below, after its start is recorded.
|
|
53
|
+
let inputs = {}, unreadable;
|
|
54
|
+
try {
|
|
55
|
+
flags = await withInputsFrom(flags, directory, undefined, client);
|
|
56
|
+
inputs = flags.inputs ? JSON.parse(readFileSync(resolve(flags.inputs), 'utf8')) : existsSync(inputFile) ? JSON.parse(readFileSync(inputFile, 'utf8')) : {};
|
|
57
|
+
writePrivateJson(inputFile, inputs);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
unreadable = error;
|
|
61
|
+
}
|
|
55
62
|
const setupFile = join(directory, 'setup.json');
|
|
56
63
|
const setupEvents = existsSync(setupFile) ? JSON.parse(readFileSync(setupFile, 'utf8')) : [];
|
|
57
64
|
setupEvents.push({ at: new Date().toISOString(), type: 'setup_started' });
|
|
@@ -61,6 +68,8 @@ export async function runSaved(saved, flags, client) {
|
|
|
61
68
|
let acquired = false, started = false, revision = 0;
|
|
62
69
|
const statePath = `/api/cli/methods/${encodeURIComponent(saved.workflow_id)}/state`;
|
|
63
70
|
try {
|
|
71
|
+
if (unreadable)
|
|
72
|
+
throw unreadable;
|
|
64
73
|
const resuming = !!flags.resume && existsSync(join(directory, 'checkpoint.json'));
|
|
65
74
|
if (resuming)
|
|
66
75
|
assertCheckpointExecutor(JSON.parse(readFileSync(join(directory, 'checkpoint.json'), 'utf8')));
|