@evolinkai/cli 0.14.1 → 0.15.0
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 +18 -2
- package/package.json +2 -2
- package/skills/evolink-cli/SKILL.md +5 -1
- package/skills/evolink-cli/references/ad-rebuild.md +76 -0
- package/src/cli.mjs +35 -3
- package/src/help.mjs +14 -1
- package/src/platform/core/src/services/gpt-image-tokens.js +18 -16
- package/src/platform/core/src/services/omni-tokens.js +17 -15
- package/src/platform/core/src/services/pricing-quote-client.js +86 -22
- package/src/platform/core/src/services/pricing-rules-client.js +15 -3
- package/src/platform/core/src/services/pricing-rules-estimate.js +18 -5
- package/src/platform/core/src/services/qwen-tts-tokens.js +12 -10
- package/src/platform/core/src/tools/estimate-cost.js +3 -3
- package/src/platform/core/src/tools/generate.js +4 -4
- package/src/platform/core/src/tools/get-pricing-rules.js +5 -2
- package/src/platform/core/src/version.js +1 -1
- package/src/platform/source.json +23 -23
- package/src/state.mjs +18 -4
- package/src/workflow.mjs +138 -0
package/src/platform/source.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema_version": 1,
|
|
3
3
|
"repository": "Evolink-AI/evolink-mcp",
|
|
4
4
|
"baseline": "acc9fd43b945e3917b47809fc94f85ba26c7c8db",
|
|
5
|
-
"source_sha256": "
|
|
5
|
+
"source_sha256": "73373b724e4642c9e50ebb6306e5a9a943310d5fcd46457a6c00a7668011dd71",
|
|
6
6
|
"files": {
|
|
7
7
|
"packages/core/src/branding.ts": "534b944a1370f210a3858c1a85b1a23071aca8e26b7a3e70e4d859ba5b152ff7",
|
|
8
8
|
"packages/core/src/config.ts": "85e1f33f5a6f0c298d3acabbf50a3c328cc50152fd2da0b029ed033aa819b874",
|
|
@@ -12,31 +12,31 @@
|
|
|
12
12
|
"packages/core/src/data/model-params.ts": "0e945b1129c0009d006463f3bcf3f9a81e4967b80afb104b25a3706fce6532e1",
|
|
13
13
|
"packages/core/src/platform-client.ts": "d272d1fbd7939acd69482207f1a75550e4ff8f584deee8f6d0c8ace86e453b6d",
|
|
14
14
|
"packages/core/src/platform-operations.ts": "cc961cdd754dd5bee335d01400329e3f3f6748fc53641f8bb5c2ab59f86c793a",
|
|
15
|
-
"packages/core/src/request-context.ts": "
|
|
16
|
-
"packages/core/src/server.ts": "
|
|
15
|
+
"packages/core/src/request-context.ts": "f879548dce4a274bbcc27dc45f7ca2bb0539d798fcc373c71db01d7002ca65c6",
|
|
16
|
+
"packages/core/src/server.ts": "f7d1cd3cf92bb312139551459b708e45916a0a1d919c4961d92133002951dd9f",
|
|
17
17
|
"packages/core/src/services/api-client.ts": "3c94d862afdebb09faee121bc9a8560858046c76335c155d6a47f71567da0d8e",
|
|
18
18
|
"packages/core/src/services/batch-generation.ts": "ad8dbccf04331e27e5ede8cf0b27627f1200bf8fecfafdeaed22f63daa1edf90",
|
|
19
19
|
"packages/core/src/services/catalog-client.ts": "154cf6249ec36d3105eb5abae7eda323f06f4d995277c47c30e8d2b5c95cf691",
|
|
20
20
|
"packages/core/src/services/error-handler.ts": "fd07d5dbd4cad3b4e75d7192c4d49623d92666fef40bd688646e0f756c208d5a",
|
|
21
21
|
"packages/core/src/services/file-client.ts": "9bd94da9a0719fba0050be261fb5210397be4e8b9e6ebc8a2e916fcc185fd2d2",
|
|
22
|
-
"packages/core/src/services/gpt-image-tokens.ts": "
|
|
22
|
+
"packages/core/src/services/gpt-image-tokens.ts": "54891a5ccd660b10700f5ce025273c3eafa25714943f86065e5084aa87ed1ccd",
|
|
23
23
|
"packages/core/src/services/http-policy.ts": "75853ef3635ca0f2f48e37334d211240bd10ba4b97ed6d892622d808c3e6c977",
|
|
24
24
|
"packages/core/src/services/media-preview.ts": "89410d8eb9a02e6fb9d9bc0de8a69b48bec7a06039e54569b9fea7e35527b6c4",
|
|
25
25
|
"packages/core/src/services/mj-prompt.ts": "a264b370df9c8929317078fbec267101c7ba54b3e5310def44dad29f4572dc5f",
|
|
26
26
|
"packages/core/src/services/model-capabilities.ts": "77766e4a2ff0edcfc3c5125e3f53589b703bd11e49c69b71aa81dba5af3e1fd6",
|
|
27
27
|
"packages/core/src/services/model-catalog.ts": "0cad28a41774ea99ff6caf66860ac33a02e8fab254243368d502935b33842364",
|
|
28
28
|
"packages/core/src/services/model-recommendations.ts": "e986db35ac3a5e3c0c8daa1d4b9e5426e081b90674740de96fbcb11ddc2baf35",
|
|
29
|
-
"packages/core/src/services/omni-tokens.ts": "
|
|
29
|
+
"packages/core/src/services/omni-tokens.ts": "a173657311741abf782dd33252744d590f31f38408cd8c415602f39f2f0c679a",
|
|
30
30
|
"packages/core/src/services/param-validator.ts": "f045100e6722bf12a91bac0b593f41c98b9a755a38eae074a941f9bbe340a1e3",
|
|
31
31
|
"packages/core/src/services/preview-download.ts": "719e100e05f7632f633551773159ba7202f755c6d6ff5ecf364b40eeb26bee7b",
|
|
32
32
|
"packages/core/src/services/pricing-call-limit.ts": "6ae56916cd08680c97d266ac08dc6e4cb9bb998a656bde82e703e8a50b471bc1",
|
|
33
33
|
"packages/core/src/services/pricing-client.ts": "c6bc7a74c3ac34a28b014f6f60b0f794346c540e2aa26d58ec62b50dc74dae25",
|
|
34
34
|
"packages/core/src/services/pricing-derived.ts": "70ac6538859d37d76db3d827048ad3d59053eaa8dbe40c25c06cbd5118062ebc",
|
|
35
|
-
"packages/core/src/services/pricing-quote-client.ts": "
|
|
36
|
-
"packages/core/src/services/pricing-rules-client.ts": "
|
|
37
|
-
"packages/core/src/services/pricing-rules-estimate.ts": "
|
|
35
|
+
"packages/core/src/services/pricing-quote-client.ts": "73be2945c035906a95679917c903d25ced518f79aa71dd8a8809c436b917f029",
|
|
36
|
+
"packages/core/src/services/pricing-rules-client.ts": "1eca54a44eaf897181d123794b03f7d38dad64c9b903c99e916dc9de6f9c0c05",
|
|
37
|
+
"packages/core/src/services/pricing-rules-estimate.ts": "8578f8e7c8da167979fb4d28af5f75912532eeb3404e36885fe0a3f312e120c1",
|
|
38
38
|
"packages/core/src/services/public-error.ts": "b74fbaf9a8b5265a392939e744d33a0b30783d287334a7c68e7d4a27d9e34937",
|
|
39
|
-
"packages/core/src/services/qwen-tts-tokens.ts": "
|
|
39
|
+
"packages/core/src/services/qwen-tts-tokens.ts": "585e39f3972df4b3ab0201c23f147621278d4c02ce7d7d5dad15d35937826eeb",
|
|
40
40
|
"packages/core/src/services/search-usage.ts": "8c5997b79a699d176313cc2a2f2b2e6ebd23b878e66035bc39600180de3266ad",
|
|
41
41
|
"packages/core/src/services/seedance-input.ts": "e16fa0c03af1afe3afba12045e69b731ec71a9d8af6ef0e30a0a988a36de251b",
|
|
42
42
|
"packages/core/src/services/task-response.ts": "09887c6c325dd04b4f6569ca243673d499cfe4acd414e8209cc8c9e9349513f2",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"packages/core/src/tool-guidance.ts": "e726593a9b6aee2d3d7c2d9ea9a8178b5eab75d8cf6de2a897382085d7d079f4",
|
|
47
47
|
"packages/core/src/tools/check-balance.ts": "f27b269a3c3c838a54fe54005eb72f637ddfdc2982d932901282bbf072d1efca",
|
|
48
48
|
"packages/core/src/tools/discovery.ts": "50adaf61d2e159a78348661b1b49b0332d47079275f943da67b5f132f8997218",
|
|
49
|
-
"packages/core/src/tools/estimate-cost.ts": "
|
|
50
|
-
"packages/core/src/tools/generate.ts": "
|
|
49
|
+
"packages/core/src/tools/estimate-cost.ts": "452aa35c9a5c65cc5acb5f809a524d4f7fc3dc9b7a879c09b66678b871137c6f",
|
|
50
|
+
"packages/core/src/tools/generate.ts": "bdde43dda6eff13c1ded24fc2189e2a8350bc1f5ee386a7238fd3d731b68980e",
|
|
51
51
|
"packages/core/src/tools/get-model.ts": "2be7759cd62cddbab0c74e504f6694a577ba4fbaf037cd77ae8ab638f5d6ef32",
|
|
52
|
-
"packages/core/src/tools/get-pricing-rules.ts": "
|
|
52
|
+
"packages/core/src/tools/get-pricing-rules.ts": "9908d2b63d090e1f4bbc9dd0ffdddb88041d026bea2eed9a457f5ad3706c7549",
|
|
53
53
|
"packages/core/src/tools/get-task.ts": "41aa5d994c2820096c38c01d69bcea56adfbc6f500314d6858e2ba54aa63520d",
|
|
54
54
|
"packages/core/src/tools/list-tasks.ts": "4f28537439179ae73db2836900ac7196fa7259803f6786ce310c1e77aa3d6c5b",
|
|
55
55
|
"packages/core/src/tools/prepare-upload.ts": "c58cfb04725cc660e34f68391727e99f726e355f9329d91ced56878212294d40",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"packages/core/src/tools/task-format.ts": "fea6591b9fc7b9bd33862bc154ba28baba163ca022e5b1e7e1480cc52a3289e5",
|
|
60
60
|
"packages/core/src/tools/task-usage.ts": "ba05d054e1d60d67f6ab75cc6d9169f453c87e0e89c17a2c1be5fc429e8f9f47",
|
|
61
61
|
"packages/core/src/tools/upload-file.ts": "da6f239d1b1e6a13a7b418d24e738ebabf9823b2656111eeaa70eb247421ad40",
|
|
62
|
-
"packages/core/src/version.ts": "
|
|
62
|
+
"packages/core/src/version.ts": "6db07196d75a897dd6c46d73d02da79550ba190feb2f1911ad478fe5afaab338"
|
|
63
63
|
},
|
|
64
64
|
"artifacts": {
|
|
65
65
|
"core/src/config.js": "e5f001e6bb30fa3ca49ca1383b3deb83ea495d20079adefad6d0451f5bbee0e3",
|
|
@@ -75,22 +75,22 @@
|
|
|
75
75
|
"core/src/services/catalog-client.js": "82d08cc7154aec3fc1ea30f91ffd8b178e732b9b87cfa9117435c7ad01718318",
|
|
76
76
|
"core/src/services/error-handler.js": "edea48a8eaf90b4193a503c0418ba7157acabfe89833a39c1d41bbf568de8355",
|
|
77
77
|
"core/src/services/file-client.js": "d11798bfddc6637727a874532ad218b5deac58d6bca8f20abcd2c30b132210e4",
|
|
78
|
-
"core/src/services/gpt-image-tokens.js": "
|
|
78
|
+
"core/src/services/gpt-image-tokens.js": "ebc9a9f344b122877508baf681827f50bbe8dd506deae7f9d5a752f71d7bd45d",
|
|
79
79
|
"core/src/services/http-policy.js": "1a78c5d1fa34fec4ef9044efd67e44d30b13a5afdc50e70b394e0e370116a2ff",
|
|
80
80
|
"core/src/services/mj-prompt.js": "1f367fc96fc6af26520d49a8b12cb7200ecf44d9f1fd311c24ab23ef15d5b27f",
|
|
81
81
|
"core/src/services/model-capabilities.js": "d0ffa771076b66d738192b456ec119b672bcade6e3d55bfafd32b44697d4a96a",
|
|
82
82
|
"core/src/services/model-catalog.js": "e25b005d48a38106565919cdfb50abf2b018b92e7d762a88470ba3af1ba2fa06",
|
|
83
83
|
"core/src/services/model-recommendations.js": "f330f941d26aa9fc127c2f7479cb2be026d6111a3f3066e89442ff29ec33803a",
|
|
84
|
-
"core/src/services/omni-tokens.js": "
|
|
84
|
+
"core/src/services/omni-tokens.js": "23e8e1fa8ea3d54d4e8c4bbe047b271fae1f54bbe46a396bd02ec05871c5024f",
|
|
85
85
|
"core/src/services/param-validator.js": "8a42dd254d9383ed1d92238f65e5407faa979398b3c7bca08eb46933be396d47",
|
|
86
86
|
"core/src/services/pricing-call-limit.js": "96bf04c9138b36300ef03366b851a5a4974cb12bba2dc63065f78402543ce22b",
|
|
87
87
|
"core/src/services/pricing-client.js": "2f0f74f7769442e4edf8c3f37a66bb1c6c099253189e9b2079ad265d1327225d",
|
|
88
88
|
"core/src/services/pricing-derived.js": "aad78fd0cc522cd2d9684967f6a5b3b1013b36315dd79368a4e1131318bb0ed8",
|
|
89
|
-
"core/src/services/pricing-quote-client.js": "
|
|
90
|
-
"core/src/services/pricing-rules-client.js": "
|
|
91
|
-
"core/src/services/pricing-rules-estimate.js": "
|
|
89
|
+
"core/src/services/pricing-quote-client.js": "4a088131b09c0b2fa19e5cd614212df7b3ffac369e55e92905045e51b502143e",
|
|
90
|
+
"core/src/services/pricing-rules-client.js": "5508af7f0c10641cdf66a479a5ecee2999b13f78a3e18b771bf28bac3c214840",
|
|
91
|
+
"core/src/services/pricing-rules-estimate.js": "dfc9092d7f3aa4b3a6452d7cb7568ef9c9357c7ec78a003e24943004c53929f9",
|
|
92
92
|
"core/src/services/public-error.js": "60995dcbcb23d43800a9db36acefe86402781226516e3634b3bf0351ba0623e8",
|
|
93
|
-
"core/src/services/qwen-tts-tokens.js": "
|
|
93
|
+
"core/src/services/qwen-tts-tokens.js": "e326ab1c317ff1908bfb9445bffa52c11e45a1206db46684c849fdc281b74fce",
|
|
94
94
|
"core/src/services/search-usage.js": "35e99dae5a548bef57a9b3b61d8ed28f4e6444308943baa71c608ad79953588a",
|
|
95
95
|
"core/src/services/seedance-input.js": "cfe5ea052c7926c31e2492bcb3e524cec0c3e4f4419f1f823d2f9cf275b52220",
|
|
96
96
|
"core/src/services/task-response.js": "28969c1aa86a8bcdf5dbfa4149fa86fa526dcd5730f922df0eed882ec30ddeaa",
|
|
@@ -98,10 +98,10 @@
|
|
|
98
98
|
"core/src/tool-guidance.js": "f4dd30891defd600dad0dcad380c8071f4620265198a18382d407799f3026f40",
|
|
99
99
|
"core/src/tools/check-balance.js": "75baa61e57e289fd61a45251665df599967ba0beb4b33cc3976280a9d89421bf",
|
|
100
100
|
"core/src/tools/discovery.js": "6095a2f699fbf465bcae3387b137901ecdbbbb00bbfa6f4b3250a7c293c45b70",
|
|
101
|
-
"core/src/tools/estimate-cost.js": "
|
|
102
|
-
"core/src/tools/generate.js": "
|
|
101
|
+
"core/src/tools/estimate-cost.js": "9c239581dc4511884a272b7af8ddcca279b76450f8868d4b4e131a5bcc042db8",
|
|
102
|
+
"core/src/tools/generate.js": "56432e9ab524c23bb36c9354b2c21e99b56b64142cc81d3ca7219fe7825f97cf",
|
|
103
103
|
"core/src/tools/get-model.js": "2a150605c736ac0d6bd124337f55f3d4b797b074fb2aa6d04ca391c2a4b124ca",
|
|
104
|
-
"core/src/tools/get-pricing-rules.js": "
|
|
104
|
+
"core/src/tools/get-pricing-rules.js": "e9a86a46c7d7d4e4df013989a359dfe76430ca53bc349c98e00267a74519dbdd",
|
|
105
105
|
"core/src/tools/get-task.js": "8803606894bfa0fed3da3177ce17818c03938973108a5b5e0477103b52ba9e9b",
|
|
106
106
|
"core/src/tools/list-tasks.js": "d2ce0d4e9fe1f885c6c3304e6ad9d33e589d6450c8ab680588b021bd2f0e3356",
|
|
107
107
|
"core/src/tools/search-models.js": "fdfca6d0a77763a57ac686d7a1a4acf412e282cbcf7dbdfc903a405b582597d9",
|
|
@@ -109,6 +109,6 @@
|
|
|
109
109
|
"core/src/tools/task-billing.js": "f49b252afcaf4a6275f5db6ebc8e6380387b2406bd5fc91e7367e3523025af8b",
|
|
110
110
|
"core/src/tools/task-format.js": "13c558fab7278cb62c07df924eb37a0d0f1771fdd0c531b661e8499e7c2393b3",
|
|
111
111
|
"core/src/tools/task-usage.js": "3aae5d7807efc2c762bf604cf9ecfecf8f9008185bcef584e6d4243404418dc5",
|
|
112
|
-
"core/src/version.js": "
|
|
112
|
+
"core/src/version.js": "910a925240248ac2f5432ed5bc587751b4eac2896439b4aa2825a4402efa1799"
|
|
113
113
|
}
|
|
114
114
|
}
|
package/src/state.mjs
CHANGED
|
@@ -60,6 +60,17 @@ async function recovering(dir) {
|
|
|
60
60
|
}
|
|
61
61
|
return active;
|
|
62
62
|
}
|
|
63
|
+
// A command can record itself late in a directory that is being released only after a recovery
|
|
64
|
+
// ran for this lock, and a recovery leaves its directory behind. The release then holds a ticket
|
|
65
|
+
// there like a recovery does, so that command waits for the release and finds its record removed.
|
|
66
|
+
async function release(dir, recovery) {
|
|
67
|
+
const ticket = path.join(recovery, `${hostID}.${process.pid}.${randomUUID()}`);
|
|
68
|
+
const held = await fs.writeFile(ticket, '', { flag: 'wx', mode: 0o600 }).then(() => true, error => {
|
|
69
|
+
if (error.code === 'ENOENT') return false;
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
try { await removeLock(dir); } finally { if (held) await fs.unlink(ticket); }
|
|
73
|
+
}
|
|
63
74
|
|
|
64
75
|
export class State {
|
|
65
76
|
// Retain the original storage location so renaming the command preserves sessions and request IDs.
|
|
@@ -116,16 +127,19 @@ export class State {
|
|
|
116
127
|
if (!acquired) { busy(); await pause(); continue; }
|
|
117
128
|
let entered = false;
|
|
118
129
|
try {
|
|
119
|
-
|
|
130
|
+
// Exclusive: a command whose new directory a recovery removed may only get here after the
|
|
131
|
+
// directory was created again, and must not replace the record of that newer owner.
|
|
132
|
+
await fs.writeFile(path.join(dir, 'owner.json'), JSON.stringify({ pid: process.pid, hostname: os.hostname(), token }), { flag: 'wx', mode: 0o600 });
|
|
120
133
|
while (await recovering(recovery)) { busy(); await pause(); }
|
|
121
|
-
// Another recovery may have removed this not-yet-entered owner.
|
|
134
|
+
// Another recovery or a release may have removed this not-yet-entered owner.
|
|
122
135
|
if ((await ownerOf(dir))?.token !== token) { busy(); continue; }
|
|
123
136
|
entered = true;
|
|
124
137
|
return await fn();
|
|
125
138
|
} catch (error) {
|
|
126
|
-
|
|
139
|
+
// ENOENT: the directory was removed first. EEXIST: another command recorded itself first.
|
|
140
|
+
if (entered || (error.code !== 'ENOENT' && error.code !== 'EEXIST')) throw error;
|
|
127
141
|
} finally {
|
|
128
|
-
if ((await ownerOf(dir))?.token === token) await
|
|
142
|
+
if ((await ownerOf(dir))?.token === token) await release(dir, recovery);
|
|
129
143
|
}
|
|
130
144
|
busy();
|
|
131
145
|
}
|
package/src/workflow.mjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import { CliError, requireThat, safeMessage, localFile } from './errors.mjs';
|
|
3
|
+
import { USER_AGENT } from './network.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Workflow rules and video reads come from the signed-in EvoLink MCP service (the OAuth resource this CLI
|
|
7
|
+
* logs in to), not from the platform API: the rules and the prompts behind a read stay on that service.
|
|
8
|
+
* The CLI sends one JSON-RPC tools/call with the login token and prints what comes back.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** How the tool names in workflow rules map to this CLI. Shown with every rules answer. */
|
|
12
|
+
export const WORKFLOW_COMMANDS = Object.freeze({
|
|
13
|
+
get_media_workflow: 'evolink workflow rules NAME [--section ID] [--run RUN_ID] --json',
|
|
14
|
+
'get_media_workflow with estimate': 'evolink workflow estimate NAME --run RUN_ID --seconds N --keyframes N [--quality 480p|720p|1080p] [--aspect-ratio 9:16] [--creator-images N] --json',
|
|
15
|
+
analyze_video: 'evolink video analyze FILE_URL --run RUN_ID --step STEP --purpose PURPOSE [--target-file FILE] [--attempt N] --json',
|
|
16
|
+
get_video_analysis: 'evolink video analysis ANALYSIS_ID --json',
|
|
17
|
+
'upload_file, prepare_upload': 'evolink upload FILE --json',
|
|
18
|
+
'search_models, get_model': 'evolink models search|show ... --json',
|
|
19
|
+
estimate_cost: 'evolink estimate --model MODEL --input-file FILE --json',
|
|
20
|
+
'generate_image, generate_video, generate_audio': 'evolink generate image|video|audio --quote ID --confirm --json',
|
|
21
|
+
'get_task, list_tasks': 'evolink tasks get|wait|list|batch ... --json',
|
|
22
|
+
check_balance: 'evolink balance --json',
|
|
23
|
+
make_frames: 'not in the CLI: extract frames, crops and contact sheets with local ffmpeg',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const COMMANDS_TEXT = ['In this CLI the tools named in the rules are these commands:',
|
|
27
|
+
...Object.entries(WORKFLOW_COMMANDS).map(([tool, command]) => ` ${tool}: ${command}`)].join('\n');
|
|
28
|
+
|
|
29
|
+
/** Results a failed call still carries for the assistant: they are passed on whole, not shortened like an error. */
|
|
30
|
+
const KEPT_FAILURES = new Set(['analysis_truncated']);
|
|
31
|
+
/** Categories that say only what kind of failure it was; the service's code then names the cause. */
|
|
32
|
+
const BROAD_CATEGORIES = new Set(['invalid_request', 'server_error', 'not_found', 'analysis_incomplete']);
|
|
33
|
+
const NOT_OFFERED = 'This EvoLink service does not offer workflows for this login yet. Nothing was charged.';
|
|
34
|
+
const REFUSED_VALUES = 'The EvoLink workflow service does not accept these values. Check the workflow name and the options against the workflow rules. Nothing was charged.';
|
|
35
|
+
/** A read keeps running on EvoLink when the answer is lost; the same command returns it without a second charge. */
|
|
36
|
+
const READ_MAY_RUN = 'If the read had started it may still finish: repeat exactly the same command to collect it without a second charge.';
|
|
37
|
+
/** An answer that cannot be read says nothing about a charge. The same read command returns a read that had started. */
|
|
38
|
+
const unreadable = name => new CliError('unsupported_response', name === 'analyze_video'
|
|
39
|
+
? 'EvoLink returned no structured result. Repeat exactly the same command: a read that had started is collected without a second charge. If it keeps happening, update the CLI.'
|
|
40
|
+
: 'EvoLink returned no structured result. Retry, or update the CLI.');
|
|
41
|
+
/** Far above any target a workflow accepts; stops a video or another large file passed by mistake. */
|
|
42
|
+
const MAX_TARGET_BYTES = 1_000_000;
|
|
43
|
+
|
|
44
|
+
export class Workflows {
|
|
45
|
+
constructor(credentials, { signal, fetchFn = fetch, timeoutMs = 75_000 } = {}) {
|
|
46
|
+
this.credentials = credentials; this.signal = signal; this.fetchFn = fetchFn; this.timeoutMs = timeoutMs;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One tools/call on the MCP service. A refused login is retried once with a renewed token. */
|
|
50
|
+
async call(name, args) {
|
|
51
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
52
|
+
const access = await this.credentials.access(attempt > 0);
|
|
53
|
+
let response, message;
|
|
54
|
+
try {
|
|
55
|
+
const limit = AbortSignal.timeout(this.timeoutMs);
|
|
56
|
+
response = await this.fetchFn(this.credentials.server.href, { method: 'POST', redirect: 'error', credentials: 'omit',
|
|
57
|
+
headers: { Authorization: `Bearer ${access.access_token}`, 'Content-Type': 'application/json',
|
|
58
|
+
Accept: 'application/json, text/event-stream', 'User-Agent': USER_AGENT },
|
|
59
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } }),
|
|
60
|
+
signal: this.signal ? AbortSignal.any([this.signal, limit]) : limit });
|
|
61
|
+
if (response.status === 401) {
|
|
62
|
+
await response.body?.cancel();
|
|
63
|
+
if (attempt === 0) continue;
|
|
64
|
+
throw new CliError('login_required', 'The EvoLink login was not accepted. Run evolink auth login.');
|
|
65
|
+
}
|
|
66
|
+
if (response.status === 429) {
|
|
67
|
+
const wait = Number(response.headers.get('retry-after'));
|
|
68
|
+
await response.body?.cancel();
|
|
69
|
+
throw new CliError('rate_limited', 'Too many requests on this EvoLink connection. Wait, then retry the same command.',
|
|
70
|
+
Number.isFinite(wait) && wait > 0 ? { retry_after_seconds: wait } : undefined);
|
|
71
|
+
}
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
await response.body?.cancel();
|
|
74
|
+
// A proxy can answer 5xx while a read is under way: only a refusal, or a free command, is called uncharged.
|
|
75
|
+
throw new CliError('workflow_unavailable', `The EvoLink workflow service returned HTTP ${response.status}. ${
|
|
76
|
+
name === 'analyze_video' && response.status >= 500 ? READ_MAY_RUN : 'Retry later; nothing was charged by this command.'}`);
|
|
77
|
+
}
|
|
78
|
+
message = await response.json();
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof CliError) throw error;
|
|
81
|
+
if (this.signal?.aborted) throw new CliError('interrupted', `Stopped waiting locally.${name === 'analyze_video' ? ` ${READ_MAY_RUN}` : ''}`, undefined, 130);
|
|
82
|
+
throw new CliError('connection_failed', `The EvoLink workflow service did not answer. ${name === 'analyze_video' ? READ_MAY_RUN : 'Retry the command; it is free.'}`);
|
|
83
|
+
}
|
|
84
|
+
const result = message?.result;
|
|
85
|
+
const data = result?.structuredContent;
|
|
86
|
+
const text = (result?.content ?? []).filter(item => item?.type === 'text' && typeof item.text === 'string').map(item => item.text).join('\n');
|
|
87
|
+
if (!data || typeof data !== 'object') {
|
|
88
|
+
// Before a tool runs, the service answers with text only (the MCP SDK) or with a JSON-RPC error:
|
|
89
|
+
// a tool it does not have, because no workflow is offered, or arguments it does not accept.
|
|
90
|
+
const said = String(message?.error?.message ?? (result?.isError ? text : ''));
|
|
91
|
+
const unknown = /tool \S+ not found|unknown tool/i.test(said);
|
|
92
|
+
if (unknown) throw new CliError('workflow_unavailable', NOT_OFFERED, { tool: name });
|
|
93
|
+
if (/input validation error|invalid arguments|invalid params/i.test(said)) throw new CliError('invalid_option', REFUSED_VALUES, { tool: name, reason: safeMessage(said).slice(0, 600) });
|
|
94
|
+
throw unreadable(name);
|
|
95
|
+
}
|
|
96
|
+
if (result.isError || data.ok === false) {
|
|
97
|
+
// The category names account and limit problems the way the rest of this CLI does; for a broad one the code says more.
|
|
98
|
+
const { category, code: finer } = data.error ?? {};
|
|
99
|
+
const code = (BROAD_CATEGORIES.has(category) || !category ? finer : category) || category || 'workflow_failed';
|
|
100
|
+
// A cut-off read was charged and carries what was read so far: return it whole, marked as failed.
|
|
101
|
+
if (KEPT_FAILURES.has(code)) return { ...data, ok: false, text };
|
|
102
|
+
throw new CliError(code, safeMessage(data.error?.message || text || 'The EvoLink workflow service refused this request.'),
|
|
103
|
+
{ ...data, text: safeMessage(text) });
|
|
104
|
+
}
|
|
105
|
+
if (data.ok !== true) throw unreadable(name);
|
|
106
|
+
return { ...data, text };
|
|
107
|
+
}
|
|
108
|
+
throw new CliError('login_required', 'The login expired. Run evolink auth login.');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async rules(workflow, { section, run } = {}) {
|
|
112
|
+
const result = await this.call('get_media_workflow', { workflow, ...(section !== undefined ? { section } : {}), ...(run !== undefined ? { run_id: run } : {}) });
|
|
113
|
+
return { ...result, cli_commands: WORKFLOW_COMMANDS, text: `${COMMANDS_TEXT}\n\n${result.text}` };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async estimate(workflow, { run, seconds, keyframes, quality, aspectRatio, creatorImages } = {}) {
|
|
117
|
+
return this.call('get_media_workflow', { workflow, ...(run !== undefined ? { run_id: run } : {}), estimate: {
|
|
118
|
+
output_seconds: seconds, keyframes, ...(quality !== undefined ? { quality } : {}),
|
|
119
|
+
...(aspectRatio !== undefined ? { aspect_ratio: aspectRatio } : {}), ...(creatorImages !== undefined ? { creator_images: creatorImages } : {}) } });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async analyze(videoUrl, { run, step, purpose, targetFile, attempt } = {}) {
|
|
123
|
+
let target;
|
|
124
|
+
if (targetFile !== undefined) {
|
|
125
|
+
const stat = await localFile(() => fs.stat(targetFile), { file: targetFile });
|
|
126
|
+
requireThat(stat.isFile(), 'invalid_file', 'The target path is not a regular file.');
|
|
127
|
+
requireThat(stat.size <= MAX_TARGET_BYTES, 'invalid_input', 'The target file is larger than 1 MB. Pass the target sheet and timeline as a text file.');
|
|
128
|
+
target = await localFile(() => fs.readFile(targetFile, 'utf8'), { file: targetFile });
|
|
129
|
+
requireThat(target.trim(), 'invalid_input', 'The target file is empty.');
|
|
130
|
+
}
|
|
131
|
+
return this.call('analyze_video', { run_id: run, step, purpose, video_url: videoUrl,
|
|
132
|
+
...(target !== undefined ? { target } : {}), ...(attempt !== undefined ? { attempt } : {}) });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async analysis(id) {
|
|
136
|
+
return this.call('get_video_analysis', { analysis_id: id });
|
|
137
|
+
}
|
|
138
|
+
}
|