@evolinkai/mcp 0.0.0-stage → 1.4.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/LICENSE +178 -0
- package/README.md +67 -2
- package/dist/core/src/branding.d.ts +3 -0
- package/dist/core/src/branding.d.ts.map +1 -0
- package/dist/core/src/branding.js +8 -0
- package/dist/core/src/branding.js.map +1 -0
- package/dist/core/src/config.d.ts +19 -0
- package/dist/core/src/config.d.ts.map +1 -0
- package/dist/core/src/config.js +90 -0
- package/dist/core/src/config.js.map +1 -0
- package/dist/core/src/data/model-params.d.ts +49 -0
- package/dist/core/src/data/model-params.d.ts.map +1 -0
- package/dist/core/src/data/model-params.generated.d.ts +2 -0
- package/dist/core/src/data/model-params.generated.d.ts.map +1 -0
- package/dist/core/src/data/model-params.generated.js +3 -0
- package/dist/core/src/data/model-params.generated.js.map +1 -0
- package/dist/core/src/data/model-params.js +22 -0
- package/dist/core/src/data/model-params.js.map +1 -0
- package/dist/core/src/request-context.d.ts +79 -0
- package/dist/core/src/request-context.d.ts.map +1 -0
- package/dist/core/src/request-context.js +52 -0
- package/dist/core/src/request-context.js.map +1 -0
- package/dist/core/src/server.d.ts +36 -0
- package/dist/core/src/server.d.ts.map +1 -0
- package/dist/core/src/server.js +123 -0
- package/dist/core/src/server.js.map +1 -0
- package/dist/core/src/services/api-client.d.ts +142 -0
- package/dist/core/src/services/api-client.d.ts.map +1 -0
- package/dist/core/src/services/api-client.js +179 -0
- package/dist/core/src/services/api-client.js.map +1 -0
- package/dist/core/src/services/error-handler.d.ts +51 -0
- package/dist/core/src/services/error-handler.d.ts.map +1 -0
- package/dist/core/src/services/error-handler.js +403 -0
- package/dist/core/src/services/error-handler.js.map +1 -0
- package/dist/core/src/services/file-client.d.ts +54 -0
- package/dist/core/src/services/file-client.d.ts.map +1 -0
- package/dist/core/src/services/file-client.js +131 -0
- package/dist/core/src/services/file-client.js.map +1 -0
- package/dist/core/src/services/http-policy.d.ts +40 -0
- package/dist/core/src/services/http-policy.d.ts.map +1 -0
- package/dist/core/src/services/http-policy.js +120 -0
- package/dist/core/src/services/http-policy.js.map +1 -0
- package/dist/core/src/services/media-preview.d.ts +24 -0
- package/dist/core/src/services/media-preview.d.ts.map +1 -0
- package/dist/core/src/services/media-preview.js +155 -0
- package/dist/core/src/services/media-preview.js.map +1 -0
- package/dist/core/src/services/model-catalog.d.ts +24 -0
- package/dist/core/src/services/model-catalog.d.ts.map +1 -0
- package/dist/core/src/services/model-catalog.js +45 -0
- package/dist/core/src/services/model-catalog.js.map +1 -0
- package/dist/core/src/services/param-validator.d.ts +21 -0
- package/dist/core/src/services/param-validator.d.ts.map +1 -0
- package/dist/core/src/services/param-validator.js +164 -0
- package/dist/core/src/services/param-validator.js.map +1 -0
- package/dist/core/src/services/preview-download.d.ts +11 -0
- package/dist/core/src/services/preview-download.d.ts.map +1 -0
- package/dist/core/src/services/preview-download.js +106 -0
- package/dist/core/src/services/preview-download.js.map +1 -0
- package/dist/core/src/services/pricing-client.d.ts +95 -0
- package/dist/core/src/services/pricing-client.d.ts.map +1 -0
- package/dist/core/src/services/pricing-client.js +396 -0
- package/dist/core/src/services/pricing-client.js.map +1 -0
- package/dist/core/src/services/upload-policy.d.ts +19 -0
- package/dist/core/src/services/upload-policy.d.ts.map +1 -0
- package/dist/core/src/services/upload-policy.js +168 -0
- package/dist/core/src/services/upload-policy.js.map +1 -0
- package/dist/core/src/services/upload-slots.d.ts +63 -0
- package/dist/core/src/services/upload-slots.d.ts.map +1 -0
- package/dist/core/src/services/upload-slots.js +24 -0
- package/dist/core/src/services/upload-slots.js.map +1 -0
- package/dist/core/src/services/utm.d.ts +29 -0
- package/dist/core/src/services/utm.d.ts.map +1 -0
- package/dist/core/src/services/utm.js +64 -0
- package/dist/core/src/services/utm.js.map +1 -0
- package/dist/core/src/tool-guidance.d.ts +6 -0
- package/dist/core/src/tool-guidance.d.ts.map +1 -0
- package/dist/core/src/tool-guidance.js +49 -0
- package/dist/core/src/tool-guidance.js.map +1 -0
- package/dist/core/src/tools/check-balance.d.ts +4 -0
- package/dist/core/src/tools/check-balance.d.ts.map +1 -0
- package/dist/core/src/tools/check-balance.js +82 -0
- package/dist/core/src/tools/check-balance.js.map +1 -0
- package/dist/core/src/tools/estimate-cost.d.ts +4 -0
- package/dist/core/src/tools/estimate-cost.d.ts.map +1 -0
- package/dist/core/src/tools/estimate-cost.js +131 -0
- package/dist/core/src/tools/estimate-cost.js.map +1 -0
- package/dist/core/src/tools/generate.d.ts +4 -0
- package/dist/core/src/tools/generate.d.ts.map +1 -0
- package/dist/core/src/tools/generate.js +221 -0
- package/dist/core/src/tools/generate.js.map +1 -0
- package/dist/core/src/tools/get-model.d.ts +5 -0
- package/dist/core/src/tools/get-model.d.ts.map +1 -0
- package/dist/core/src/tools/get-model.js +117 -0
- package/dist/core/src/tools/get-model.js.map +1 -0
- package/dist/core/src/tools/get-task.d.ts +7 -0
- package/dist/core/src/tools/get-task.d.ts.map +1 -0
- package/dist/core/src/tools/get-task.js +56 -0
- package/dist/core/src/tools/get-task.js.map +1 -0
- package/dist/core/src/tools/list-tasks.d.ts +6 -0
- package/dist/core/src/tools/list-tasks.d.ts.map +1 -0
- package/dist/core/src/tools/list-tasks.js +149 -0
- package/dist/core/src/tools/list-tasks.js.map +1 -0
- package/dist/core/src/tools/prepare-upload.d.ts +6 -0
- package/dist/core/src/tools/prepare-upload.d.ts.map +1 -0
- package/dist/core/src/tools/prepare-upload.js +134 -0
- package/dist/core/src/tools/prepare-upload.js.map +1 -0
- package/dist/core/src/tools/search-models.d.ts +5 -0
- package/dist/core/src/tools/search-models.d.ts.map +1 -0
- package/dist/core/src/tools/search-models.js +97 -0
- package/dist/core/src/tools/search-models.js.map +1 -0
- package/dist/core/src/tools/shared.d.ts +55 -0
- package/dist/core/src/tools/shared.d.ts.map +1 -0
- package/dist/core/src/tools/shared.js +137 -0
- package/dist/core/src/tools/shared.js.map +1 -0
- package/dist/core/src/tools/task-format.d.ts +48 -0
- package/dist/core/src/tools/task-format.d.ts.map +1 -0
- package/dist/core/src/tools/task-format.js +212 -0
- package/dist/core/src/tools/task-format.js.map +1 -0
- package/dist/core/src/tools/upload-file.d.ts +17 -0
- package/dist/core/src/tools/upload-file.d.ts.map +1 -0
- package/dist/core/src/tools/upload-file.js +134 -0
- package/dist/core/src/tools/upload-file.js.map +1 -0
- package/dist/core/src/version.d.ts +3 -0
- package/dist/core/src/version.d.ts.map +1 -0
- package/dist/core/src/version.js +3 -0
- package/dist/core/src/version.js.map +1 -0
- package/dist/evolink-media/src/index.d.ts +3 -0
- package/dist/evolink-media/src/index.d.ts.map +1 -0
- package/dist/evolink-media/src/index.js +18 -0
- package/dist/evolink-media/src/index.js.map +1 -0
- package/package.json +46 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-params.generated.js","sourceRoot":"","sources":["../../../../../core/src/data/model-params.generated.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,MAAM,CAAC,MAAM,iBAAiB,GAAW,u2idAAu2id,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MODEL_PARAMS_JSON } from './model-params.generated.js';
|
|
2
|
+
let index;
|
|
3
|
+
function load() {
|
|
4
|
+
index ??= JSON.parse(MODEL_PARAMS_JSON);
|
|
5
|
+
return index;
|
|
6
|
+
}
|
|
7
|
+
export function modelParamsMeta() {
|
|
8
|
+
return load().meta;
|
|
9
|
+
}
|
|
10
|
+
export function allModelParams() {
|
|
11
|
+
return Object.values(load().models);
|
|
12
|
+
}
|
|
13
|
+
/** Exact model ID first, then a case-insensitive match. */
|
|
14
|
+
export function findModelParams(model) {
|
|
15
|
+
const models = load().models;
|
|
16
|
+
const trimmed = model.trim();
|
|
17
|
+
if (models[trimmed])
|
|
18
|
+
return models[trimmed];
|
|
19
|
+
const lower = trimmed.toLowerCase();
|
|
20
|
+
return Object.values(models).find(entry => entry.model.toLowerCase() === lower);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=model-params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-params.js","sourceRoot":"","sources":["../../../../../core/src/data/model-params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAuDhE,IAAI,KAAmC,CAAC;AAExC,SAAS,IAAI;IACX,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAqB,CAAC;IAC5D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,EAAE,CAAC,IAAI,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,MAAM,CAAC,OAAO,CAAC;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-request EvoLink credentials for the hosted (remote) MCP service.
|
|
3
|
+
*
|
|
4
|
+
* The stdio packages never enter a scope, so getApiKey() keeps reading
|
|
5
|
+
* EVOLINK_API_KEY or the CLI credential helper there. Inside a scope the
|
|
6
|
+
* request's own credential is the only one used: there is no fallback to
|
|
7
|
+
* process-wide credentials.
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestCredentials {
|
|
10
|
+
/** Caller's own API key (hosted api-key mode); absent for signed-in connections. */
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
/** Signed-in connections (key custody A): the gateway finds the connection's key itself. */
|
|
13
|
+
serviceChannel?: ServiceChannelCredentials;
|
|
14
|
+
/**
|
|
15
|
+
* Signed-in connections: the account (Passport subject) that owns this
|
|
16
|
+
* request's one-time uploads, so get_upload only shows the account's own.
|
|
17
|
+
*/
|
|
18
|
+
uploadOwner?: string;
|
|
19
|
+
/** Agent-readable reason surfaced by tools that need an API key when there is none. */
|
|
20
|
+
unavailableReason?: string;
|
|
21
|
+
/** Assistant name sent as X-Evo-Client-Name; the hosted service takes it from the HTTP User-Agent. */
|
|
22
|
+
clientName?: string;
|
|
23
|
+
/** Signed-in connections: the verified token's client_id; only used to tag site links with the assistant. */
|
|
24
|
+
clientId?: string;
|
|
25
|
+
/** Edition for site links' utm_campaign; the hosted service sets mcp_remote on every request. */
|
|
26
|
+
linkCampaign?: LinkCampaign;
|
|
27
|
+
/** Hosted service: told about every tool call of this request, for usage records. */
|
|
28
|
+
onToolCall?: (call: ToolCallRecord) => void;
|
|
29
|
+
}
|
|
30
|
+
/** utm_campaign of site links: the hosted service is mcp_remote, the npm packages mcp_local. */
|
|
31
|
+
export type LinkCampaign = 'mcp_remote' | 'mcp_local';
|
|
32
|
+
/** One tool call as usage records see it: no arguments except the model name. */
|
|
33
|
+
export interface ToolCallRecord {
|
|
34
|
+
tool: string;
|
|
35
|
+
ok: boolean;
|
|
36
|
+
/** Error category of a failed call (`exception` when the tool threw). */
|
|
37
|
+
category?: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
durationMs: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Key custody A: this service never holds a user's key. A signed-in call
|
|
43
|
+
* forwards the connection's Passport access token, which this service has
|
|
44
|
+
* already verified; the gateway verifies it again, takes the session, account
|
|
45
|
+
* and client from it, checks the session with Passport and bills the account's
|
|
46
|
+
* EvoLink MCP key.
|
|
47
|
+
*/
|
|
48
|
+
export interface ServiceChannelCredentials {
|
|
49
|
+
/** The connection's Passport access token (audience: this MCP server, scope mcp). */
|
|
50
|
+
accessToken: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function runWithRequestCredentials<T>(credentials: RequestCredentials, fn: () => T): T;
|
|
53
|
+
export declare function currentRequestCredentials(): RequestCredentials | undefined;
|
|
54
|
+
/** Hosted mode: never fall back to EVOLINK_API_KEY or the local credential helper. */
|
|
55
|
+
export declare function disableProcessCredentials(): void;
|
|
56
|
+
export declare function processCredentialsAllowed(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* How this request is billed: `signed_in` spends the account's internal MCP key
|
|
59
|
+
* through the service channel (its limit is the user's "EvoLink MCP limit");
|
|
60
|
+
* `api_key` is the hosted service with the caller's own API key; `local` is a
|
|
61
|
+
* stdio server with EVOLINK_API_KEY or the CLI login.
|
|
62
|
+
*/
|
|
63
|
+
export type CredentialMode = 'local' | 'api_key' | 'signed_in';
|
|
64
|
+
export declare function currentCredentialMode(): CredentialMode;
|
|
65
|
+
/** stdio: remember the assistant name from the MCP initialize handshake. */
|
|
66
|
+
export declare function setProcessClientName(name: string | undefined): void;
|
|
67
|
+
/** The request's assistant name inside a hosted scope, otherwise the stdio client's. */
|
|
68
|
+
export declare function currentClientName(): string | undefined;
|
|
69
|
+
/** stdio entry points: which edition this process is, for site links outside a hosted request. */
|
|
70
|
+
export declare function setProcessLinkCampaign(campaign: LinkCampaign): void;
|
|
71
|
+
/** What site links need to know about the caller: the hosted request's own values, otherwise the stdio client's. */
|
|
72
|
+
export declare function currentLinkContext(): {
|
|
73
|
+
clientId?: string;
|
|
74
|
+
clientName?: string;
|
|
75
|
+
campaign: LinkCampaign;
|
|
76
|
+
};
|
|
77
|
+
/** Printable ASCII only, at most 64 characters, so it is safe in a header and a log line. */
|
|
78
|
+
export declare function sanitizeClientName(value: string | undefined): string | undefined;
|
|
79
|
+
//# sourceMappingURL=request-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../../../core/src/request-context.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4FAA4F;IAC5F,cAAc,CAAC,EAAE,yBAAyB,CAAC;IAC3C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sGAAsG;IACtG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6GAA6G;IAC7G,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iGAAiG;IACjG,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,qFAAqF;IACrF,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC7C;AAED,gGAAgG;AAChG,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;AAEtD,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,CAAC;IACZ,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,qFAAqF;IACrF,WAAW,EAAE,MAAM,CAAC;CACrB;AAOD,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE5F;AAED,wBAAgB,yBAAyB,IAAI,kBAAkB,GAAG,SAAS,CAE1E;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD;AAED,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAE/D,wBAAgB,qBAAqB,IAAI,cAAc,CAGtD;AAED,4EAA4E;AAC5E,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAEnE;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAItD;AAED,kGAAkG;AAClG,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAEnE;AAED,oHAAoH;AACpH,wBAAgB,kBAAkB,IAAI;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,CAMvG;AAED,6FAA6F;AAC7F,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGhF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const storage = new AsyncLocalStorage();
|
|
3
|
+
let processCredentialsDisabled = false;
|
|
4
|
+
let processClientName;
|
|
5
|
+
let processLinkCampaign = 'mcp_local';
|
|
6
|
+
export function runWithRequestCredentials(credentials, fn) {
|
|
7
|
+
return storage.run(credentials, fn);
|
|
8
|
+
}
|
|
9
|
+
export function currentRequestCredentials() {
|
|
10
|
+
return storage.getStore();
|
|
11
|
+
}
|
|
12
|
+
/** Hosted mode: never fall back to EVOLINK_API_KEY or the local credential helper. */
|
|
13
|
+
export function disableProcessCredentials() {
|
|
14
|
+
processCredentialsDisabled = true;
|
|
15
|
+
}
|
|
16
|
+
export function processCredentialsAllowed() {
|
|
17
|
+
return !processCredentialsDisabled;
|
|
18
|
+
}
|
|
19
|
+
export function currentCredentialMode() {
|
|
20
|
+
if (storage.getStore()?.serviceChannel)
|
|
21
|
+
return 'signed_in';
|
|
22
|
+
return processCredentialsDisabled ? 'api_key' : 'local';
|
|
23
|
+
}
|
|
24
|
+
/** stdio: remember the assistant name from the MCP initialize handshake. */
|
|
25
|
+
export function setProcessClientName(name) {
|
|
26
|
+
processClientName = sanitizeClientName(name);
|
|
27
|
+
}
|
|
28
|
+
/** The request's assistant name inside a hosted scope, otherwise the stdio client's. */
|
|
29
|
+
export function currentClientName() {
|
|
30
|
+
const scoped = storage.getStore();
|
|
31
|
+
if (scoped)
|
|
32
|
+
return sanitizeClientName(scoped.clientName);
|
|
33
|
+
return processClientName;
|
|
34
|
+
}
|
|
35
|
+
/** stdio entry points: which edition this process is, for site links outside a hosted request. */
|
|
36
|
+
export function setProcessLinkCampaign(campaign) {
|
|
37
|
+
processLinkCampaign = campaign;
|
|
38
|
+
}
|
|
39
|
+
/** What site links need to know about the caller: the hosted request's own values, otherwise the stdio client's. */
|
|
40
|
+
export function currentLinkContext() {
|
|
41
|
+
const scoped = storage.getStore();
|
|
42
|
+
if (scoped) {
|
|
43
|
+
return { clientId: scoped.clientId, clientName: sanitizeClientName(scoped.clientName), campaign: scoped.linkCampaign ?? processLinkCampaign };
|
|
44
|
+
}
|
|
45
|
+
return { clientName: processClientName, campaign: processLinkCampaign };
|
|
46
|
+
}
|
|
47
|
+
/** Printable ASCII only, at most 64 characters, so it is safe in a header and a log line. */
|
|
48
|
+
export function sanitizeClientName(value) {
|
|
49
|
+
const cleaned = (value ?? '').replace(/[^\x20-\x7e]/g, '').trim().slice(0, 64);
|
|
50
|
+
return cleaned || undefined;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=request-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.js","sourceRoot":"","sources":["../../../../core/src/request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,k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CAAC,QAAQ,EAAE,CAAC;IAClC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,YAAY,IAAI,mBAAmB,EAAE,CAAC;IAChJ,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,CAAC;AAC1E,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/E,OAAO,OAAO,IAAI,SAAS,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { ServerConfig } from './config.js';
|
|
3
|
+
import { type LinkCampaign } from './request-context.js';
|
|
4
|
+
import type { UploadSlots } from './services/upload-slots.js';
|
|
5
|
+
import { type Thumbnailer } from './services/media-preview.js';
|
|
6
|
+
export { type ServerConfig, createConfig, getApiKey } from './config.js';
|
|
7
|
+
export interface ServerOptions {
|
|
8
|
+
/** Allow upload_file to read local paths (stdio only); the hosted service sets false. */
|
|
9
|
+
localFileUploads?: boolean;
|
|
10
|
+
/** Offer upload_file at all. */
|
|
11
|
+
uploads?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Signed-in hosted connection: it has no API key of its own, so upload_file
|
|
14
|
+
* asks the gateway for a short-lived upload token per upload and takes
|
|
15
|
+
* base64 only up to 1 MB. With uploadSlots it also offers prepare_upload and
|
|
16
|
+
* get_upload (one-time upload addresses for larger local files).
|
|
17
|
+
*/
|
|
18
|
+
signedIn?: {
|
|
19
|
+
uploadSlots?: UploadSlots;
|
|
20
|
+
};
|
|
21
|
+
/** Remember the client's name from initialize for X-Evo-Client-Name (stdio only; hosted requests carry their own). */
|
|
22
|
+
trackClientName?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Edition for the server info's site link: the hosted service passes mcp_remote (it builds each server
|
|
25
|
+
* before entering the request's scope); stdio servers take the process's campaign (setProcessLinkCampaign).
|
|
26
|
+
*/
|
|
27
|
+
linkCampaign?: LinkCampaign;
|
|
28
|
+
/** Disable optional media thumbnails; original results and resource links are always returned. */
|
|
29
|
+
resultPreviews?: boolean;
|
|
30
|
+
/** Internal preview renderer, for embedders and transport integration tests. */
|
|
31
|
+
thumbnailer?: Thumbnailer;
|
|
32
|
+
}
|
|
33
|
+
/** Sent to the client at initialize; most assistants add it to their instructions. */
|
|
34
|
+
export declare const SERVER_INSTRUCTIONS: string;
|
|
35
|
+
export declare function createServer(config: ServerConfig, options?: ServerOptions): McpServer;
|
|
36
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../core/src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAuE,KAAK,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AAWnJ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAK9D,OAAO,EAAqC,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGlG,OAAO,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEzE,MAAM,WAAW,aAAa;IAC5B,yFAAyF;IACzF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gCAAgC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE,CAAC;IACzC,sHAAsH;IACtH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kGAAkG;IAClG,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gFAAgF;IAChF,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,QAWpB,CAAC;AAEb,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,aAAkB,GAAG,SAAS,CAsCzF"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { currentLinkContext, currentRequestCredentials, setProcessClientName } from './request-context.js';
|
|
3
|
+
import { registerCheckBalance } from './tools/check-balance.js';
|
|
4
|
+
import { registerEstimateCost } from './tools/estimate-cost.js';
|
|
5
|
+
import { registerGenerateTools } from './tools/generate.js';
|
|
6
|
+
import { registerGetModel } from './tools/get-model.js';
|
|
7
|
+
import { registerGetTask } from './tools/get-task.js';
|
|
8
|
+
import { registerListTasks } from './tools/list-tasks.js';
|
|
9
|
+
import { registerPrepareUpload } from './tools/prepare-upload.js';
|
|
10
|
+
import { registerSearchModels } from './tools/search-models.js';
|
|
11
|
+
import { registerUploadFile } from './tools/upload-file.js';
|
|
12
|
+
import { RESULT_DELIVERY_INSTRUCTIONS } from './tools/task-format.js';
|
|
13
|
+
import { withUtm } from './services/utm.js';
|
|
14
|
+
import { MCP_VERSION } from './version.js';
|
|
15
|
+
import { GENERATION_CONFIRMATION_GUIDANCE, MEDIA_ROUTING_GUIDANCE, PAID_GENERATION_GUIDANCE } from './tool-guidance.js';
|
|
16
|
+
import { EVOLINK_ICONS } from './branding.js';
|
|
17
|
+
import { addResultPreviews, PREVIEW_LIMITS } from './services/media-preview.js';
|
|
18
|
+
import { ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
19
|
+
export { createConfig, getApiKey } from './config.js';
|
|
20
|
+
/** Sent to the client at initialize; most assistants add it to their instructions. */
|
|
21
|
+
export const SERVER_INSTRUCTIONS = [
|
|
22
|
+
'EvoLink creates images, videos, music and speech with 150+ models, billed to the user\'s EvoLink balance (68 credits ≈ $1).',
|
|
23
|
+
'- Find a model with search_models; read its parameters and prices with get_model.',
|
|
24
|
+
`- ${MEDIA_ROUTING_GUIDANCE}`,
|
|
25
|
+
`- ${PAID_GENERATION_GUIDANCE}`,
|
|
26
|
+
GENERATION_CONFIRMATION_GUIDANCE,
|
|
27
|
+
'- generate_video and generate_audio return a task_id; wait for it with get_task (up to 45 s per call). Never call a generate tool again to check progress: that charges again.',
|
|
28
|
+
`- ${RESULT_DELIVERY_INSTRUCTIONS}`,
|
|
29
|
+
'- Reference images, audio and video are passed as public http(s) links. For a file on the user\'s computer, use upload_file when it is listed (a hosted connection takes base64 only up to its size limit); for a larger local file use prepare_upload when it is listed and run the command it returns on the user\'s computer. Otherwise ask the user for a public link. Chat attachments cannot be read as files.',
|
|
30
|
+
'- Errors include a next step (for example a top-up link); follow it instead of retrying blindly.',
|
|
31
|
+
'- When a call is refused for money, tell the user which reason the error names: the EvoLink MCP limit (or daily limit) they set, EvoLink MCP being paused, or the account balance. They need different fixes, so never call an MCP limit a low balance; give the link from the error and do not retry until the user has acted.',
|
|
32
|
+
].join('\n');
|
|
33
|
+
export function createServer(config, options = {}) {
|
|
34
|
+
const server = new McpServer({
|
|
35
|
+
name: config.channel === 'beta' ? 'evolink-mcp-beta' : 'evolink-mcp',
|
|
36
|
+
title: 'EvoLink',
|
|
37
|
+
icons: EVOLINK_ICONS,
|
|
38
|
+
version: MCP_VERSION,
|
|
39
|
+
// Sent before the client says who it is, so the source is the generic mcp_client.
|
|
40
|
+
websiteUrl: withUtm('https://evolink.ai/mcp', {
|
|
41
|
+
source: 'mcp_client',
|
|
42
|
+
campaign: options.linkCampaign ?? currentLinkContext().campaign,
|
|
43
|
+
content: 'server_info',
|
|
44
|
+
}),
|
|
45
|
+
}, { instructions: SERVER_INSTRUCTIONS });
|
|
46
|
+
if (options.trackClientName ?? true) {
|
|
47
|
+
server.server.oninitialized = () => setProcessClientName(server.server.getClientVersion()?.name);
|
|
48
|
+
}
|
|
49
|
+
observeToolCalls(server, options);
|
|
50
|
+
registerSearchModels(server);
|
|
51
|
+
registerGetModel(server);
|
|
52
|
+
registerEstimateCost(server, config);
|
|
53
|
+
registerGenerateTools(server, config);
|
|
54
|
+
registerGetTask(server, config);
|
|
55
|
+
registerListTasks(server, config);
|
|
56
|
+
if (options.uploads ?? true) {
|
|
57
|
+
const slots = options.signedIn?.uploadSlots;
|
|
58
|
+
registerUploadFile(server, {
|
|
59
|
+
localFiles: options.localFileUploads ?? true,
|
|
60
|
+
signedIn: options.signedIn ? { config, oneTimeUploads: Boolean(slots) } : undefined,
|
|
61
|
+
});
|
|
62
|
+
if (slots)
|
|
63
|
+
registerPrepareUpload(server, config, slots);
|
|
64
|
+
}
|
|
65
|
+
registerCheckBalance(server, config);
|
|
66
|
+
return server;
|
|
67
|
+
}
|
|
68
|
+
/** The model a call asked for, when its arguments name one. */
|
|
69
|
+
function modelOf(args) {
|
|
70
|
+
const input = args[0];
|
|
71
|
+
if (!input || typeof input !== 'object')
|
|
72
|
+
return undefined;
|
|
73
|
+
const model = input.model;
|
|
74
|
+
return typeof model === 'string' && model.length > 0 && model.length <= 100 ? model : undefined;
|
|
75
|
+
}
|
|
76
|
+
function callRecord(tool, args, result, durationMs) {
|
|
77
|
+
const outcome = result;
|
|
78
|
+
const model = modelOf(args);
|
|
79
|
+
const record = { tool, ok: outcome?.isError !== true, durationMs };
|
|
80
|
+
if (!record.ok) {
|
|
81
|
+
const category = outcome?.structuredContent?.error?.category;
|
|
82
|
+
record.category = typeof category === 'string' ? category : 'error';
|
|
83
|
+
}
|
|
84
|
+
if (model)
|
|
85
|
+
record.model = model;
|
|
86
|
+
return record;
|
|
87
|
+
}
|
|
88
|
+
/** Tells the request's observer (hosted service usage records) about every tool call; stdio has none. */
|
|
89
|
+
function observeToolCalls(server, options) {
|
|
90
|
+
// SDK 1.32's high-level registerTool drops icons. Enrich its native tools/list
|
|
91
|
+
// handler so schemas, annotations and future SDK list behavior stay intact.
|
|
92
|
+
const setHandler = server.server.setRequestHandler.bind(server.server);
|
|
93
|
+
server.server.setRequestHandler = ((schema, handler) => {
|
|
94
|
+
setHandler(schema, schema === ListToolsRequestSchema ? async (...args) => {
|
|
95
|
+
const result = await handler(...args);
|
|
96
|
+
return { ...result, tools: result.tools.map(tool => ({ ...tool, icons: EVOLINK_ICONS })) };
|
|
97
|
+
} : handler);
|
|
98
|
+
});
|
|
99
|
+
const register = server.registerTool.bind(server);
|
|
100
|
+
const previewTools = new Set(['generate_image', 'generate_video', 'get_task', 'list_tasks']);
|
|
101
|
+
const observed = (name, config, handler) => register(name, { ...config, icons: EVOLINK_ICONS }, async (...args) => {
|
|
102
|
+
const report = currentRequestCredentials()?.onToolCall;
|
|
103
|
+
const started = Date.now();
|
|
104
|
+
try {
|
|
105
|
+
let result = await handler(...args);
|
|
106
|
+
if (options.resultPreviews !== false && previewTools.has(name)) {
|
|
107
|
+
// Optional enrichment cannot change a successful generation into an error.
|
|
108
|
+
try {
|
|
109
|
+
result = await addResultPreviews(result, options.thumbnailer, args[1]?.signal, PREVIEW_LIMITS.callBudgetMs - (Date.now() - started));
|
|
110
|
+
}
|
|
111
|
+
catch { /* Preserve original delivery if preview enrichment is unavailable. */ }
|
|
112
|
+
}
|
|
113
|
+
report?.(callRecord(name, args, result, Date.now() - started));
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
report?.({ tool: name, ok: false, category: 'exception', durationMs: Date.now() - started, ...(modelOf(args) ? { model: modelOf(args) } : {}) });
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
server.registerTool = observed;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../core/src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,oBAAoB,EAA0C,MAAM,sBAAsB,CAAC;AACnJ,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gCAAgC,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAoB,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAA6C,MAAM,oCAAoC,CAAC;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K,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACjJ,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,YAAY,GAAG,QAAiD,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { type ServerConfig } from '../config.js';
|
|
2
|
+
import { type GatewayErrorInfo } from './error-handler.js';
|
|
3
|
+
export type TaskStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
4
|
+
export interface TaskResponse {
|
|
5
|
+
created: number;
|
|
6
|
+
id: string;
|
|
7
|
+
model: string;
|
|
8
|
+
object: string;
|
|
9
|
+
progress: number;
|
|
10
|
+
status: TaskStatus;
|
|
11
|
+
type: string;
|
|
12
|
+
duration?: number;
|
|
13
|
+
video_duration?: number;
|
|
14
|
+
results?: string[];
|
|
15
|
+
result_data?: ResultDataItem[] | Record<string, unknown>;
|
|
16
|
+
task_info?: {
|
|
17
|
+
can_cancel?: boolean;
|
|
18
|
+
estimated_time?: number;
|
|
19
|
+
video_duration?: number;
|
|
20
|
+
};
|
|
21
|
+
usage?: {
|
|
22
|
+
billing_rule?: string;
|
|
23
|
+
credits_reserved?: number;
|
|
24
|
+
credits_used?: number;
|
|
25
|
+
cost?: {
|
|
26
|
+
credits?: number;
|
|
27
|
+
usd?: number;
|
|
28
|
+
cny?: number;
|
|
29
|
+
};
|
|
30
|
+
user_group?: string;
|
|
31
|
+
};
|
|
32
|
+
error?: {
|
|
33
|
+
code?: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
type?: string;
|
|
36
|
+
suggestion?: string;
|
|
37
|
+
};
|
|
38
|
+
request_id?: string;
|
|
39
|
+
/** Set by the MCP client when the gateway answered a repeated Idempotency-Key with the original response. */
|
|
40
|
+
idempotency_replayed?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ResultDataItem {
|
|
43
|
+
result_id?: string;
|
|
44
|
+
duration?: number;
|
|
45
|
+
tags?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
image_url?: string;
|
|
48
|
+
audio_url?: string;
|
|
49
|
+
stream_audio_url?: string;
|
|
50
|
+
video_url?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface TaskListItem {
|
|
53
|
+
id: string;
|
|
54
|
+
model: string;
|
|
55
|
+
type: string;
|
|
56
|
+
status: TaskStatus;
|
|
57
|
+
progress: number;
|
|
58
|
+
created_at: number;
|
|
59
|
+
duration?: number;
|
|
60
|
+
has_results?: boolean;
|
|
61
|
+
result_count?: number;
|
|
62
|
+
has_error?: boolean;
|
|
63
|
+
credits_used?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface TaskListResponse {
|
|
66
|
+
data: TaskListItem[];
|
|
67
|
+
total: number;
|
|
68
|
+
page: number;
|
|
69
|
+
page_size: number;
|
|
70
|
+
}
|
|
71
|
+
export interface CreditsResponse {
|
|
72
|
+
user: {
|
|
73
|
+
remaining_credits: number;
|
|
74
|
+
used_credits: number;
|
|
75
|
+
};
|
|
76
|
+
token: {
|
|
77
|
+
remaining_credits: number;
|
|
78
|
+
used_credits: number;
|
|
79
|
+
unlimited_credits: boolean;
|
|
80
|
+
/** Daily limit of the calling key, when one is set (newer gateways). */
|
|
81
|
+
daily_limit_credits?: number;
|
|
82
|
+
daily_used_credits?: number;
|
|
83
|
+
reset_timezone?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export declare class ApiHttpError extends Error {
|
|
87
|
+
readonly status: number;
|
|
88
|
+
readonly retryAfterMs?: number | undefined;
|
|
89
|
+
readonly requestId?: string | undefined;
|
|
90
|
+
readonly info?: GatewayErrorInfo | undefined;
|
|
91
|
+
constructor(status: number, message: string, retryAfterMs?: number | undefined, requestId?: string | undefined, info?: GatewayErrorInfo | undefined);
|
|
92
|
+
}
|
|
93
|
+
export declare function withRetry<T>(fn: () => Promise<T>, retries: number, baseDelayMs: number): Promise<T>;
|
|
94
|
+
export interface SubmitOptions {
|
|
95
|
+
path: string;
|
|
96
|
+
body: Record<string, unknown>;
|
|
97
|
+
tool: string;
|
|
98
|
+
/** Reused on a retry of the same intent; a fresh one is generated when absent. */
|
|
99
|
+
idempotencyKey?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Submit one paid intent. At most one transport retry, always with the same
|
|
103
|
+
* idempotency key, so the gateway ledger (Idempotency-Key) can return the
|
|
104
|
+
* original task instead of creating a second one.
|
|
105
|
+
*/
|
|
106
|
+
export declare function submitTask(config: ServerConfig, options: SubmitOptions): Promise<TaskResponse>;
|
|
107
|
+
/** @deprecated kept for callers outside the tools; use submitTask. */
|
|
108
|
+
export declare function apiRequest(config: ServerConfig, options: {
|
|
109
|
+
method: 'GET' | 'POST';
|
|
110
|
+
path: string;
|
|
111
|
+
body?: Record<string, unknown>;
|
|
112
|
+
tool?: string;
|
|
113
|
+
}): Promise<TaskResponse>;
|
|
114
|
+
/** One task (GET /v1/tasks/{id}). Unfinished tasks sync with the provider on every read, so callers pace themselves. */
|
|
115
|
+
export declare function queryTask(config: ServerConfig, taskId: string, tool?: string): Promise<TaskResponse>;
|
|
116
|
+
/** Up to 50 tasks in one call (POST /v1/tasks/batch); unknown or foreign IDs are simply absent. */
|
|
117
|
+
export declare function queryTasks(config: ServerConfig, taskIds: string[], tool?: string): Promise<TaskResponse[]>;
|
|
118
|
+
export interface ListTasksQuery {
|
|
119
|
+
status?: string;
|
|
120
|
+
type?: string;
|
|
121
|
+
model?: string;
|
|
122
|
+
page?: number;
|
|
123
|
+
pageSize?: number;
|
|
124
|
+
}
|
|
125
|
+
/** The account's recent tasks, newest first (GET /v1/tasks). Items carry no result links. */
|
|
126
|
+
export declare function listTasks(config: ServerConfig, query: ListTasksQuery, tool?: string): Promise<TaskListResponse>;
|
|
127
|
+
export interface UploadToken {
|
|
128
|
+
/** evup_…: only files-api's three upload endpoints accept it. Never log it. */
|
|
129
|
+
token: string;
|
|
130
|
+
/** Unix seconds. files-api caches a check for up to 5 minutes, so it may keep working briefly after this. */
|
|
131
|
+
expiresAt: number;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A short-lived upload token for a signed-in hosted connection (POST
|
|
135
|
+
* /v1/files/upload-token). The connection has no API key of its own, so
|
|
136
|
+
* files-api takes this token instead. Free; the gateway allows 30 a minute per
|
|
137
|
+
* account.
|
|
138
|
+
*/
|
|
139
|
+
export declare function requestUploadToken(config: ServerConfig, tool: string): Promise<UploadToken>;
|
|
140
|
+
/** Account balance and this key's usage (GET /v1/credits). */
|
|
141
|
+
export declare function getCredits(config: ServerConfig, tool?: string): Promise<CreditsResponse>;
|
|
142
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../../../../core/src/services/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,cAAc,CAAC;AACrE,OAAO,EAA4C,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AA2BrG,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEzF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EA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