@evolinkai/cli 0.6.0 → 0.8.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 +65 -5
- package/package.json +27 -8
- package/skills/evolink-cli/SKILL.md +11 -4
- package/skills/evolink-cli/references/capabilities.md +38 -0
- package/skills/evolink-cli/references/usage-and-budget.md +17 -0
- package/src/api.mjs +55 -0
- package/src/auth.mjs +6 -7
- package/src/cli.mjs +96 -29
- package/src/doctor.mjs +9 -6
- package/src/files.mjs +143 -7
- package/src/help.mjs +68 -0
- package/src/media.mjs +9 -7
- package/src/network.mjs +12 -1
- package/src/oauth.mjs +82 -0
- package/src/platform/LICENSE +178 -0
- package/src/platform/NOTICE +6 -0
- package/src/platform/core/src/config.js +92 -0
- package/src/platform/core/src/data/model-constraints.js +37 -0
- package/src/platform/core/src/data/model-params.generated.js +4 -0
- package/src/platform/core/src/data/model-params.js +28 -0
- package/src/platform/core/src/platform-client.js +50 -0
- package/src/platform/core/src/platform-operations.js +22 -0
- package/src/platform/core/src/request-context.js +53 -0
- package/src/platform/core/src/services/api-client.js +205 -0
- package/src/platform/core/src/services/catalog-client.js +45 -0
- package/src/platform/core/src/services/error-handler.js +404 -0
- package/src/platform/core/src/services/file-client.js +133 -0
- package/src/platform/core/src/services/http-policy.js +136 -0
- package/src/platform/core/src/services/model-capabilities.js +24 -0
- package/src/platform/core/src/services/model-catalog.js +68 -0
- package/src/platform/core/src/services/model-recommendations.js +35 -0
- package/src/platform/core/src/services/param-validator.js +201 -0
- package/src/platform/core/src/services/pricing-client.js +451 -0
- package/src/platform/core/src/services/utm.js +65 -0
- package/src/platform/core/src/tool-guidance.js +50 -0
- package/src/platform/core/src/tools/check-balance.js +90 -0
- package/src/platform/core/src/tools/discovery.js +86 -0
- package/src/platform/core/src/tools/estimate-cost.js +136 -0
- package/src/platform/core/src/tools/generate.js +234 -0
- package/src/platform/core/src/tools/get-model.js +146 -0
- package/src/platform/core/src/tools/get-task.js +57 -0
- package/src/platform/core/src/tools/list-tasks.js +170 -0
- package/src/platform/core/src/tools/search-models.js +115 -0
- package/src/platform/core/src/tools/shared.js +138 -0
- package/src/platform/core/src/tools/task-format.js +245 -0
- package/src/platform/core/src/tools/task-usage.js +108 -0
- package/src/platform/core/src/version.js +4 -0
- package/src/platform/source.json +80 -0
- package/src/setup.mjs +9 -5
- package/src/mcp.mjs +0 -36
package/src/media.mjs
CHANGED
|
@@ -38,12 +38,12 @@ export function checkEstimate(quote, cap) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export class Media {
|
|
41
|
-
constructor({ mcp, state, server, now = Date.now }) { this.
|
|
41
|
+
constructor({ client, mcp = client, state, server, now = Date.now }) { this.client = mcp; this.state = state; this.server = server.href; this.now = now; }
|
|
42
42
|
async estimate(args) {
|
|
43
43
|
const { max_cost_usd, ...input } = args;
|
|
44
44
|
let quote;
|
|
45
45
|
try {
|
|
46
|
-
quote = await this.
|
|
46
|
+
quote = await this.client.call('estimate_cost', input);
|
|
47
47
|
checkEstimate(quote, max_cost_usd);
|
|
48
48
|
requireThat(['image', 'video', 'audio'].includes(quote.type), 'unsupported_model', 'This model is not a media generation model.');
|
|
49
49
|
} catch (error) { throw quoteError(error, max_cost_usd); }
|
|
@@ -53,6 +53,7 @@ export class Media {
|
|
|
53
53
|
const id = randomUUID();
|
|
54
54
|
const argsToSubmit = { ...input, model: quote.model, ...(effectiveCap !== undefined ? { max_cost_usd: effectiveCap } : {}) };
|
|
55
55
|
const stored = { id, server: this.server, binding: quote._binding, args: argsToSubmit,
|
|
56
|
+
...(this.client.apiUrl ? { backend: 'platform', api_origin: this.client.apiUrl.origin } : {}),
|
|
56
57
|
type: quote.type, args_hash: hash(argsToSubmit), fingerprint: priceFingerprint(quote), estimate: quote.estimate,
|
|
57
58
|
created_at: this.now(), expires_at: this.now() + 15 * 60_000, state: 'quoted', client_request_id: `cli-${randomUUID()}` };
|
|
58
59
|
await this.state.write('quotes', id, stored);
|
|
@@ -62,7 +63,8 @@ export class Media {
|
|
|
62
63
|
async load(id) {
|
|
63
64
|
const quote = await this.state.read('quotes', id);
|
|
64
65
|
requireThat(quote?.server === this.server, 'quote_not_found', 'This quote does not exist for the current server.');
|
|
65
|
-
requireThat(quote.
|
|
66
|
+
requireThat(!quote.api_origin || quote.api_origin === this.client.apiUrl?.origin, 'quote_platform_changed', 'This quote belongs to a different platform API.');
|
|
67
|
+
requireThat(quote.binding === (await this.client.credentials.access()).binding, 'quote_session_changed', 'This quote belongs to a different login. Estimate again in the current session.');
|
|
66
68
|
requireThat(quote.args_hash === hash(quote.args), 'quote_changed', 'The saved request changed. Estimate again.');
|
|
67
69
|
return quote;
|
|
68
70
|
}
|
|
@@ -72,7 +74,7 @@ export class Media {
|
|
|
72
74
|
return this.state.lock(`quote-${id}`, async () => {
|
|
73
75
|
const quote = await this.load(id);
|
|
74
76
|
requireThat(quote.type === kind, 'quote_type_mismatch', 'Use the media type shown in the saved quote.');
|
|
75
|
-
if (quote.task_id) return { ...await this.
|
|
77
|
+
if (quote.task_id) return { ...await this.client.call('get_task', { task_id: quote.task_id, wait_seconds: 0 }), quote_id: id, recovered: true };
|
|
76
78
|
requireThat(quote.state !== 'refused', 'submission_refused',
|
|
77
79
|
'EvoLink refused this submission and reported no charge. Resolve the original error, estimate again with the same budget, and obtain approval for the new quote.',
|
|
78
80
|
{ quote_id: id, client_request_id: quote.client_request_id, charged: 'no', submission_allowed: false });
|
|
@@ -86,7 +88,7 @@ export class Media {
|
|
|
86
88
|
const { max_cost_usd, ...checkArgs } = quote.args;
|
|
87
89
|
let fresh;
|
|
88
90
|
try {
|
|
89
|
-
fresh = await this.
|
|
91
|
+
fresh = await this.client.call('estimate_cost', checkArgs);
|
|
90
92
|
requireThat(priceFingerprint(fresh) === quote.fingerprint, 'price_changed', 'The quote changed. Estimate again and obtain approval for the new quote.', { estimate: fresh.estimate });
|
|
91
93
|
checkEstimate(fresh, max_cost_usd);
|
|
92
94
|
} catch (error) { throw quoteError(error, max_cost_usd); }
|
|
@@ -95,7 +97,7 @@ export class Media {
|
|
|
95
97
|
await this.state.write('quotes', id, quote);
|
|
96
98
|
let result;
|
|
97
99
|
try {
|
|
98
|
-
result = await this.
|
|
100
|
+
result = await this.client.call(`generate_${kind}`, { ...quote.args, client_request_id: quote.client_request_id });
|
|
99
101
|
requireThat(typeof result.task_id === 'string' && result.task_id.length > 0, 'outcome_unknown', 'The submission returned no task ID. Recover with the original quote.');
|
|
100
102
|
} catch (e) {
|
|
101
103
|
quote.state = e.details?.charged === 'no' ? 'refused' : 'outcome_unknown';
|
|
@@ -118,7 +120,7 @@ export class Media {
|
|
|
118
120
|
for (;;) {
|
|
119
121
|
if (signal?.aborted) throw new CliError('interrupted', 'Stopped waiting locally. The EvoLink task continues.', { task_id: taskId }, 130);
|
|
120
122
|
const remaining = Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
|
|
121
|
-
const task = await this.
|
|
123
|
+
const task = await this.client.call('get_task', { task_id: taskId, wait_seconds: Math.min(30, remaining) });
|
|
122
124
|
if (task.status === 'completed') return task;
|
|
123
125
|
if (['failed', 'cancelled'].includes(task.status)) throw new CliError('task_failed', 'The generation task did not complete.', { task });
|
|
124
126
|
progress(`${task.task_id}: ${task.status}${task.progress !== undefined ? ` (${task.progress}%)` : ''}`);
|
package/src/network.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import { CLI_VERSION } from './version.mjs';
|
|
|
7
7
|
|
|
8
8
|
export const SERVER = 'https://mcp.evolink.ai/mcp';
|
|
9
9
|
export const ISSUER = 'https://passport.evolink.ai';
|
|
10
|
+
export const API = 'https://api.evolink.ai';
|
|
11
|
+
export const FILES = 'https://files-api.evolink.ai';
|
|
10
12
|
export const USER_AGENT = `EvoLinkCLI/${CLI_VERSION}`;
|
|
11
13
|
export const loopback = url => url.protocol === 'http:' && ['127.0.0.1', '[::1]'].includes(url.hostname);
|
|
12
14
|
|
|
@@ -19,7 +21,7 @@ export function serverURL(value = SERVER) {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export function authFetch(server, fetchFn = fetch) {
|
|
22
|
-
const origins = new Set([server.
|
|
24
|
+
const origins = new Set([server.href === SERVER ? ISSUER : server.origin]);
|
|
23
25
|
return async (input, options = {}) => {
|
|
24
26
|
const url = new URL(input instanceof Request ? input.url : input);
|
|
25
27
|
requireThat(origins.has(url.origin) && !url.username && !url.password, 'untrusted_auth_server', 'The login endpoint is outside the configured EvoLink service.');
|
|
@@ -29,6 +31,15 @@ export function authFetch(server, fetchFn = fetch) {
|
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
export function serviceURL(value, production, resource) {
|
|
35
|
+
let url;
|
|
36
|
+
try { url = new URL(value); } catch { throw new CliError('invalid_api_url', 'Invalid platform service URL.'); }
|
|
37
|
+
requireThat(!url.username && !url.password && !url.search && !url.hash && url.pathname === '/'
|
|
38
|
+
&& (url.origin === production || loopback(resource) && loopback(url)),
|
|
39
|
+
'invalid_api_url', 'Use the EvoLink production service, or an explicit loopback service with a loopback test resource.');
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
|
|
32
43
|
const blocked = new net.BlockList();
|
|
33
44
|
for (const [network, prefix] of [['0.0.0.0', 8], ['10.0.0.0', 8], ['127.0.0.0', 8], ['169.254.0.0', 16],
|
|
34
45
|
['172.16.0.0', 12], ['192.168.0.0', 16], ['224.0.0.0', 3], ['100.64.0.0', 10]]) blocked.addSubnet(network, prefix, 'ipv4');
|
package/src/oauth.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { randomBytes, createHash } from 'node:crypto';
|
|
2
|
+
import { CliError, requireThat } from './errors.mjs';
|
|
3
|
+
import { ISSUER, SERVER } from './network.mjs';
|
|
4
|
+
|
|
5
|
+
// Passport discovery is independent of MCP health and protected-resource metadata.
|
|
6
|
+
export async function metadata(server, fetchFn) {
|
|
7
|
+
const issuer = server.href === SERVER ? ISSUER : server.origin;
|
|
8
|
+
const response = await fetchFn(`${issuer}/.well-known/oauth-authorization-server`);
|
|
9
|
+
requireThat(response.ok, 'login_unavailable', 'Passport login discovery is unavailable. Retry login.');
|
|
10
|
+
const data = await response.json();
|
|
11
|
+
requireThat(data.issuer === issuer && data.code_challenge_methods_supported?.includes('S256'),
|
|
12
|
+
'invalid_auth_metadata', 'Passport did not provide the expected issuer and PKCE method.');
|
|
13
|
+
for (const key of ['authorization_endpoint', 'token_endpoint', 'registration_endpoint', 'revocation_endpoint']) {
|
|
14
|
+
let endpoint;
|
|
15
|
+
try { endpoint = new URL(data[key]); } catch { throw new CliError('invalid_auth_metadata', 'Passport did not provide valid login endpoints.'); }
|
|
16
|
+
requireThat(endpoint.origin === issuer && !endpoint.username && !endpoint.password && !endpoint.hash,
|
|
17
|
+
'untrusted_auth_server', 'The login endpoint is outside Passport.');
|
|
18
|
+
}
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function client(provider, data, fetchFn) {
|
|
23
|
+
let value = await provider.clientInformation();
|
|
24
|
+
if (value) requireThat(value.issuer === data.issuer && typeof value.client_id === 'string' && !value.client_secret,
|
|
25
|
+
'invalid_client', 'The saved public OAuth client belongs to a different service.');
|
|
26
|
+
if (!value) {
|
|
27
|
+
const response = await fetchFn(data.registration_endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
28
|
+
body: JSON.stringify(provider.clientMetadata) });
|
|
29
|
+
requireThat(response.ok, 'registration_failed', 'Passport could not register this CLI login.');
|
|
30
|
+
value = await response.json();
|
|
31
|
+
requireThat(typeof value.client_id === 'string' && value.client_id.length > 0, 'invalid_client', 'Passport returned no public client ID.');
|
|
32
|
+
requireThat(!value.client_secret && value.token_endpoint_auth_method !== 'client_secret_basic', 'invalid_client', 'The CLI requires a public OAuth client.');
|
|
33
|
+
value = { client_id: value.client_id, issuer: data.issuer, token_endpoint_auth_method: 'none',
|
|
34
|
+
redirect_uris: value.redirect_uris ?? provider.clientMetadata.redirect_uris };
|
|
35
|
+
await provider.saveClientInformation(value);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function token(provider, data, clientInfo, parameters, fetchFn) {
|
|
41
|
+
const response = await fetchFn(data.token_endpoint, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
42
|
+
body: new URLSearchParams({ client_id: clientInfo.client_id, resource: provider.server.href, ...parameters }) });
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
let code;
|
|
45
|
+
try { code = (await response.json()).error; } catch { /* Never echo credential-bearing response bodies. */ }
|
|
46
|
+
throw new CliError(code === 'invalid_grant' ? 'login_expired' : code === 'invalid_client' ? 'invalid_client' : 'login_unavailable',
|
|
47
|
+
code === 'invalid_grant' ? 'This login expired. Run evolink auth login.' : 'Passport could not complete this login. Retry auth login.');
|
|
48
|
+
}
|
|
49
|
+
const value = await response.json();
|
|
50
|
+
requireThat(typeof value.access_token === 'string' && value.access_token.length > 0 && value.token_type?.toLowerCase() === 'bearer'
|
|
51
|
+
&& Number.isFinite(value.expires_in) && value.expires_in > 0 && (!value.issuer || value.issuer === data.issuer)
|
|
52
|
+
&& (!value.scope || value.scope.split(' ').includes('mcp')), 'invalid_token_response', 'Passport returned an invalid login response.');
|
|
53
|
+
const prior = await provider.tokens();
|
|
54
|
+
const oldRefresh = parameters.grant_type === 'refresh_token' ? prior?.refresh_token : undefined;
|
|
55
|
+
requireThat(typeof value.refresh_token === 'string' && value.refresh_token.length > 0 || oldRefresh,
|
|
56
|
+
'invalid_token_response', 'Passport returned no refresh credential.');
|
|
57
|
+
await provider.saveTokens({ ...value, refresh_token: value.refresh_token || oldRefresh, issuer: data.issuer });
|
|
58
|
+
return 'AUTHORIZED';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function refresh(provider, fetchFn) {
|
|
62
|
+
const data = await metadata(provider.server, fetchFn);
|
|
63
|
+
const info = await client(provider, data, fetchFn);
|
|
64
|
+
const saved = await provider.tokens();
|
|
65
|
+
requireThat(saved?.issuer === data.issuer && saved.refresh_token, 'login_required', 'Run evolink auth login.');
|
|
66
|
+
return token(provider, data, info, { grant_type: 'refresh_token', refresh_token: saved.refresh_token }, fetchFn);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function authorize(provider, fetchFn, authorizationCode) {
|
|
70
|
+
const data = await metadata(provider.server, fetchFn);
|
|
71
|
+
const info = await client(provider, data, fetchFn);
|
|
72
|
+
if (authorizationCode) return token(provider, data, info, { grant_type: 'authorization_code', code: authorizationCode,
|
|
73
|
+
redirect_uri: String(provider.redirectUrl), code_verifier: await provider.codeVerifier() }, fetchFn);
|
|
74
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
75
|
+
await provider.saveCodeVerifier(verifier);
|
|
76
|
+
const url = new URL(data.authorization_endpoint);
|
|
77
|
+
url.search = new URLSearchParams({ client_id: info.client_id, response_type: 'code', redirect_uri: String(provider.redirectUrl),
|
|
78
|
+
scope: 'mcp offline_access', resource: provider.server.href, state: provider.state(),
|
|
79
|
+
code_challenge: createHash('sha256').update(verifier).digest('base64url'), code_challenge_method: 'S256' }).toString();
|
|
80
|
+
await provider.redirectToAuthorization(url);
|
|
81
|
+
return 'REDIRECT';
|
|
82
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and the Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any Contribution
|
|
81
|
+
embodied within the Work constitutes direct or contributory patent
|
|
82
|
+
infringement, then any patent licenses granted to You under this License
|
|
83
|
+
for that Work shall terminate as of the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
86
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
87
|
+
modifications, and in Source or Object form, provided that You
|
|
88
|
+
meet the following conditions:
|
|
89
|
+
|
|
90
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
91
|
+
a copy of this License; and
|
|
92
|
+
|
|
93
|
+
(b) You must cause any modified files to carry prominent notices
|
|
94
|
+
stating that You changed the files; and
|
|
95
|
+
|
|
96
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
97
|
+
that You distribute, all copyright, patent, trademark, and
|
|
98
|
+
attribution notices from the Source form of the Work,
|
|
99
|
+
excluding those notices that do not pertain to any part of
|
|
100
|
+
the Derivative Works; and
|
|
101
|
+
|
|
102
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
103
|
+
distribution, You must include a readable copy of the
|
|
104
|
+
attribution notices contained within such NOTICE file, in
|
|
105
|
+
at least one of the following places: within a NOTICE text file
|
|
106
|
+
distributed as part of the Derivative Works; within the Source
|
|
107
|
+
form or documentation, if provided along with the Derivative Works;
|
|
108
|
+
or, within a display generated by the Derivative Works, if and
|
|
109
|
+
wherever such third-party notices normally appear. The contents
|
|
110
|
+
of the NOTICE file are for informational purposes only and
|
|
111
|
+
do not modify the License. You may add Your own attribution
|
|
112
|
+
notices within Derivative Works that You distribute, alongside
|
|
113
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
114
|
+
that such additional attribution notices cannot be construed
|
|
115
|
+
as modifying the License.
|
|
116
|
+
|
|
117
|
+
You may add Your own license statement for Your modifications and
|
|
118
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
119
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
120
|
+
Contribution, either on an original or modified basis.
|
|
121
|
+
|
|
122
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
123
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
124
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
125
|
+
this License, without any additional terms or conditions.
|
|
126
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
127
|
+
the terms of any separate license agreement you may have executed
|
|
128
|
+
with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
131
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
132
|
+
except as required for reasonable and customary use in describing the
|
|
133
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
136
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
137
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
138
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
139
|
+
implied, including, without limitation, any warranties or conditions
|
|
140
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
141
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
142
|
+
appropriateness of using or reproducing the Work and assume any
|
|
143
|
+
risks associated with Your exercise of permissions under this License.
|
|
144
|
+
|
|
145
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
146
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
147
|
+
unless required by applicable law (such as deliberate and grossly
|
|
148
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
149
|
+
liable to You for damages, including any direct, indirect, special,
|
|
150
|
+
incidental, or exemplary damages of any character arising as a
|
|
151
|
+
result of this License or out of the use or inability to use the
|
|
152
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
153
|
+
work stoppage, computer failure or malfunction, or all other
|
|
154
|
+
commercial damages or losses), even if such Contributor has been
|
|
155
|
+
advised of the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
158
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
159
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
160
|
+
or other liability obligations and/or rights consistent with this
|
|
161
|
+
License. However, in accepting such obligations, You may offer only
|
|
162
|
+
conditions that are completely consistent with this License.
|
|
163
|
+
|
|
164
|
+
END OF TERMS AND CONDITIONS
|
|
165
|
+
|
|
166
|
+
Copyright 2024 EvoLink AI
|
|
167
|
+
|
|
168
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
169
|
+
you may not use this file except in compliance with the License.
|
|
170
|
+
You may obtain a copy of the License at
|
|
171
|
+
|
|
172
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
173
|
+
|
|
174
|
+
Unless required by applicable law or agreed to in writing, software
|
|
175
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
176
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
177
|
+
See the License for the specific language governing permissions and
|
|
178
|
+
limitations under the License.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright 2024 EvoLink AI. SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Generated from Evolink-AI/evolink-mcp; adapted for direct REST operations. See platform/LICENSE and platform/NOTICE.
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { currentRequestCredentials, processCredentialsAllowed } from './request-context.js';
|
|
5
|
+
import { API_KEYS_URL } from './services/http-policy.js';
|
|
6
|
+
import { trackedLink } from './services/utm.js';
|
|
7
|
+
import { MCP_VERSION } from './version.js';
|
|
8
|
+
const BASE_URLS = {
|
|
9
|
+
official: 'https://api.evolink.ai',
|
|
10
|
+
beta: 'https://beta-api.evolink.ai',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* EVOLINK_BASE_URL overrides the channel default so the same build can point
|
|
14
|
+
* at canary/staging gateways (e.g. https://t-api.evolink.ai) without patching
|
|
15
|
+
* dist. HTTPS is required except for loopback development hosts.
|
|
16
|
+
*/
|
|
17
|
+
function resolveBaseUrl(channel) {
|
|
18
|
+
const override = (process.env.EVOLINK_BASE_URL ?? '').trim().replace(/\/+$/, '');
|
|
19
|
+
if (!override)
|
|
20
|
+
return BASE_URLS[channel];
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = new URL(override);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new Error(`EVOLINK_BASE_URL is not a valid URL: ${override}`);
|
|
27
|
+
}
|
|
28
|
+
const loopback = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1';
|
|
29
|
+
if (parsed.protocol !== 'https:' && !(parsed.protocol === 'http:' && loopback)) {
|
|
30
|
+
throw new Error('EVOLINK_BASE_URL must use HTTPS (or HTTP on localhost).');
|
|
31
|
+
}
|
|
32
|
+
return override;
|
|
33
|
+
}
|
|
34
|
+
export function createConfig(channel) {
|
|
35
|
+
return {
|
|
36
|
+
channel,
|
|
37
|
+
baseUrl: resolveBaseUrl(channel),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The User-Agent of the hosted service's gateway calls. EvoLink's own services
|
|
42
|
+
* use "<service>/<version>"; the gateway records whether a signed-in call came
|
|
43
|
+
* through this service (mcp_via_service) and never authenticates by it.
|
|
44
|
+
*/
|
|
45
|
+
export const MCP_SERVICE_USER_AGENT = `evolink-mcp-service/${MCP_VERSION}`;
|
|
46
|
+
/**
|
|
47
|
+
* Authentication headers for one gateway call. A signed-in hosted connection
|
|
48
|
+
* forwards its own Passport access token (key custody A) with the service
|
|
49
|
+
* User-Agent; everything else sends the caller's API key.
|
|
50
|
+
*/
|
|
51
|
+
export function gatewayAuthHeaders() {
|
|
52
|
+
const channel = currentRequestCredentials()?.serviceChannel;
|
|
53
|
+
if (!channel)
|
|
54
|
+
return { 'Authorization': `Bearer ${getApiKey()}` };
|
|
55
|
+
return {
|
|
56
|
+
'User-Agent': currentRequestCredentials()?.http?.userAgent ?? MCP_SERVICE_USER_AGENT,
|
|
57
|
+
'Authorization': `Bearer ${channel.accessToken}`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function getApiKey() {
|
|
61
|
+
const scoped = currentRequestCredentials();
|
|
62
|
+
if (scoped) {
|
|
63
|
+
if (scoped.apiKey)
|
|
64
|
+
return scoped.apiKey;
|
|
65
|
+
throw new Error(scoped.unavailableReason ?? 'No EvoLink credential is available for this request.');
|
|
66
|
+
}
|
|
67
|
+
if (!processCredentialsAllowed()) {
|
|
68
|
+
throw new Error('No EvoLink credential is available for this request.');
|
|
69
|
+
}
|
|
70
|
+
const configured = process.env.EVOLINK_API_KEY?.trim();
|
|
71
|
+
if (configured)
|
|
72
|
+
return configured;
|
|
73
|
+
const helper = process.env.EVOLINK_CREDENTIAL_HELPER?.trim() || 'evolink';
|
|
74
|
+
if (helper.includes('\0'))
|
|
75
|
+
throw new Error('EVOLINK_CREDENTIAL_HELPER is invalid');
|
|
76
|
+
try {
|
|
77
|
+
const key = execFileSync(helper, ['credential', 'get'], {
|
|
78
|
+
encoding: 'utf8',
|
|
79
|
+
timeout: 5_000,
|
|
80
|
+
maxBuffer: 64 * 1024,
|
|
81
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
82
|
+
}).trim();
|
|
83
|
+
if (key)
|
|
84
|
+
return key;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Return one stable recovery message without echoing helper stderr or key material.
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`No EvoLink API key is available. Set EVOLINK_API_KEY to a key from ${trackedLink(API_KEYS_URL, 'api_keys')}, ` +
|
|
90
|
+
'or set EVOLINK_CREDENTIAL_HELPER to an API-key helper that implements `credential get`. ' +
|
|
91
|
+
'The browser-login @evolinkai/cli does not export API keys; use its own `evolink auth login` workflow or hosted MCP for OAuth.');
|
|
92
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2024 EvoLink AI. SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Generated from Evolink-AI/evolink-mcp; adapted for direct REST operations. See platform/LICENSE and platform/NOTICE.
|
|
3
|
+
/** Reviewed structured supplements for constraints still described only in OpenAPI prose.
|
|
4
|
+
* Sources: GroAPI unified_videos_validation.go / common/gpt_image2_token.go,
|
|
5
|
+
* and mintlify-docs en/api-manual/audio-series/doubao-seed-audio/*.json.
|
|
6
|
+
* Kept outside generated data so rebuilding the docs index cannot erase them.
|
|
7
|
+
*/
|
|
8
|
+
export function withModelConstraints(model) {
|
|
9
|
+
if (/^wan3\.0-(?:prime-)?(?:text-to-video|image-to-video|reference-video)$/.test(model.model)) {
|
|
10
|
+
model.params.duration = { ...model.params.duration, anyOf: [
|
|
11
|
+
{ type: 'integer', minimum: 2, maximum: 30 }, { type: 'integer', enum: [-1] },
|
|
12
|
+
] };
|
|
13
|
+
const properties = model.inputSchema?.schema.properties;
|
|
14
|
+
if (properties)
|
|
15
|
+
properties.duration = { type: 'integer', anyOf: model.params.duration.anyOf, description: model.params.duration.description, default: model.params.duration.default };
|
|
16
|
+
}
|
|
17
|
+
if (['gpt-image-2', 'gpt-image-2.5-flare', 'gpt-image-2.5-sunburst', 'gpt-image-2-beta'].includes(model.model)) {
|
|
18
|
+
model.constraints = { ...model.constraints, imageSize: {
|
|
19
|
+
param: 'size', allowed: ['auto', '1:1', '1:2', '2:1', '1:3', '3:1', '2:3', '3:2', '3:4', '4:3', '4:5', '5:4', '9:16', '16:9', '9:21', '21:9'],
|
|
20
|
+
allowPixels: model.model !== 'gpt-image-2-beta', step: 16, minEdge: 16, maxEdge: 3840,
|
|
21
|
+
minPixels: 655360, maxPixels: 8294400, maxRatio: 3,
|
|
22
|
+
...(model.model === 'gpt-image-2-beta' ? { ratioResolution: '1K' } : {}),
|
|
23
|
+
} };
|
|
24
|
+
const properties = model.inputSchema?.schema.properties;
|
|
25
|
+
if (properties)
|
|
26
|
+
properties.size = { type: 'string', anyOf: [
|
|
27
|
+
{ enum: model.constraints.imageSize.allowed },
|
|
28
|
+
...(model.constraints.imageSize.allowPixels ? [{ pattern: '^\\d+[x×]\\d+$' }] : []),
|
|
29
|
+
], default: model.params.size?.default, description: model.params.size?.description, 'x-evolink-image-size': model.constraints.imageSize };
|
|
30
|
+
}
|
|
31
|
+
if (model.model === 'doubao-seed-audio-1-0') {
|
|
32
|
+
model.constraints = { ...model.constraints, outputDuration: 'unknown', mutuallyExclusive: [['audio_references', 'image_urls']] };
|
|
33
|
+
if (model.inputSchema)
|
|
34
|
+
model.inputSchema.schema['x-evolink-mutually-exclusive'] = model.constraints.mutuallyExclusive;
|
|
35
|
+
}
|
|
36
|
+
return model;
|
|
37
|
+
}
|