@ebitex/mcp 0.0.0-stage → 1.1.313
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 +201 -0
- package/README.md +143 -2
- package/dist/app.d.ts +57 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +8 -0
- package/dist/app.js.map +1 -0
- package/dist/apps/content/app.d.ts +23 -0
- package/dist/apps/content/app.d.ts.map +1 -0
- package/dist/apps/content/app.js +95 -0
- package/dist/apps/content/app.js.map +1 -0
- package/dist/apps/content/client.d.ts +34 -0
- package/dist/apps/content/client.d.ts.map +1 -0
- package/dist/apps/content/client.js +68 -0
- package/dist/apps/content/client.js.map +1 -0
- package/dist/apps/content/config.d.ts +29 -0
- package/dist/apps/content/config.d.ts.map +1 -0
- package/dist/apps/content/config.js +30 -0
- package/dist/apps/content/config.js.map +1 -0
- package/dist/apps/content/errors.d.ts +59 -0
- package/dist/apps/content/errors.d.ts.map +1 -0
- package/dist/apps/content/errors.js +122 -0
- package/dist/apps/content/errors.js.map +1 -0
- package/dist/apps/content/resources/helpCorpus.generated.d.ts +7 -0
- package/dist/apps/content/resources/helpCorpus.generated.d.ts.map +1 -0
- package/dist/apps/content/resources/helpCorpus.generated.js +162 -0
- package/dist/apps/content/resources/helpCorpus.generated.js.map +1 -0
- package/dist/apps/content/resources/register.d.ts +8 -0
- package/dist/apps/content/resources/register.d.ts.map +1 -0
- package/dist/apps/content/resources/register.js +81 -0
- package/dist/apps/content/resources/register.js.map +1 -0
- package/dist/apps/content/routes.d.ts +67 -0
- package/dist/apps/content/routes.d.ts.map +1 -0
- package/dist/apps/content/routes.js +163 -0
- package/dist/apps/content/routes.js.map +1 -0
- package/dist/apps/content/session.d.ts +60 -0
- package/dist/apps/content/session.d.ts.map +1 -0
- package/dist/apps/content/session.js +81 -0
- package/dist/apps/content/session.js.map +1 -0
- package/dist/apps/content/tools/catalog.d.ts +58 -0
- package/dist/apps/content/tools/catalog.d.ts.map +1 -0
- package/dist/apps/content/tools/catalog.js +81 -0
- package/dist/apps/content/tools/catalog.js.map +1 -0
- package/dist/apps/content/tools/cursor.d.ts +62 -0
- package/dist/apps/content/tools/cursor.d.ts.map +1 -0
- package/dist/apps/content/tools/cursor.js +94 -0
- package/dist/apps/content/tools/cursor.js.map +1 -0
- package/dist/apps/content/tools/register.d.ts +36 -0
- package/dist/apps/content/tools/register.d.ts.map +1 -0
- package/dist/apps/content/tools/register.js +470 -0
- package/dist/apps/content/tools/register.js.map +1 -0
- package/dist/apps/content/tools/result.d.ts +28 -0
- package/dist/apps/content/tools/result.d.ts.map +1 -0
- package/dist/apps/content/tools/result.js +26 -0
- package/dist/apps/content/tools/result.js.map +1 -0
- package/dist/apps/content/tools/whoami.d.ts +36 -0
- package/dist/apps/content/tools/whoami.d.ts.map +1 -0
- package/dist/apps/content/tools/whoami.js +39 -0
- package/dist/apps/content/tools/whoami.js.map +1 -0
- package/dist/apps/index.d.ts +8 -0
- package/dist/apps/index.d.ts.map +1 -0
- package/dist/apps/index.js +8 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/config.d.ts +46 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +69 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +51 -0
- package/dist/main.js.map +1 -0
- package/dist/server.d.ts +51 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +104 -0
- package/dist/server.js.map +1 -0
- package/package.json +44 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { toContentApiError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* The HTTP client for `/content/management/v1`.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately **one method per verb**, not one per endpoint. The endpoints come from
|
|
6
|
+
* the route table, which is the only place in this package that knows a route exists — so a newly
|
|
7
|
+
* reachable family is a row there rather than a method here, and there is no second list to keep in
|
|
8
|
+
* step with the first.
|
|
9
|
+
*
|
|
10
|
+
* It is also the only module that holds the key, and the only one that calls `fetch`. Both are
|
|
11
|
+
* worth keeping true: a test drives the whole server by substituting one function.
|
|
12
|
+
*/
|
|
13
|
+
export const ROUTE_PREFIX = '/content/management/v1';
|
|
14
|
+
export function createClient(options) {
|
|
15
|
+
const doFetch = options.fetchImpl ?? globalThis.fetch;
|
|
16
|
+
return {
|
|
17
|
+
baseUrl: options.baseUrl,
|
|
18
|
+
async request(method, path, body) {
|
|
19
|
+
const response = await doFetch(`${options.baseUrl}${ROUTE_PREFIX}${path}`, {
|
|
20
|
+
method,
|
|
21
|
+
headers: {
|
|
22
|
+
Authorization: `Bearer ${options.key}`,
|
|
23
|
+
Accept: 'application/json',
|
|
24
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
25
|
+
},
|
|
26
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok)
|
|
29
|
+
throw await toContentApiError(response);
|
|
30
|
+
// 204 (every delete) carries no body. Returning `null` rather than throwing on an empty parse
|
|
31
|
+
// keeps the caller from having to know which responses are empty.
|
|
32
|
+
//
|
|
33
|
+
// A 202 is NOT empty — both publish phases, and since spec 775-management-import-async-job the
|
|
34
|
+
// import, answer `{ id, status }`. This comment used to say otherwise, harmlessly while nothing
|
|
35
|
+
// read a kick-off's body; it is corrected because something does now, and because a caller who
|
|
36
|
+
// believed it would return the envelope as though it were the operation's result.
|
|
37
|
+
if (response.status === 204)
|
|
38
|
+
return null;
|
|
39
|
+
const text = await response.text();
|
|
40
|
+
if (!text)
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(text);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return text;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds a query string from values that may be absent, skipping the absent ones.
|
|
53
|
+
*
|
|
54
|
+
* Kept here rather than inlined because the API rejects unknown *properties* on a body but is
|
|
55
|
+
* ordinary about query parameters — the asymmetry is easy to forget, and sending `limit=undefined`
|
|
56
|
+
* as a literal string is the kind of thing that reads as an API bug for an afternoon.
|
|
57
|
+
*/
|
|
58
|
+
export function query(params) {
|
|
59
|
+
const search = new URLSearchParams();
|
|
60
|
+
for (const [name, value] of Object.entries(params)) {
|
|
61
|
+
if (value === undefined || value === null || value === '')
|
|
62
|
+
continue;
|
|
63
|
+
search.set(name, String(value));
|
|
64
|
+
}
|
|
65
|
+
const rendered = search.toString();
|
|
66
|
+
return rendered ? `?${rendered}` : '';
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/apps/content/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,wBAAwB,CAAA;AAiBpD,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAA;IAErD,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI;YAC9B,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,GAAG,YAAY,GAAG,IAAI,EAAE,EAAE;gBACzE,MAAM;gBACN,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,OAAO,CAAC,GAAG,EAAE;oBACtC,MAAM,EAAE,kBAAkB;oBAC1B,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,C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I,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Content app reads from the environment.
|
|
3
|
+
*
|
|
4
|
+
* An MCP server is launched by a host process with a config block, not by a person at a prompt, so
|
|
5
|
+
* a misconfiguration has no interactive moment in which to be noticed. A key that is present but
|
|
6
|
+
* wrong stops the server at startup naming the variable; it never surfaces later as a `401` on
|
|
7
|
+
* whatever tool the agent happened to call first, which an agent would reasonably read as a wrong
|
|
8
|
+
* credential and retry.
|
|
9
|
+
*/
|
|
10
|
+
/** Minted in Content under Settings > API Keys > Management keys. Setting it turns the Content app on. */
|
|
11
|
+
export declare const KEY_VAR = "EBITEX_CONTENT_MANAGEMENT_KEY";
|
|
12
|
+
/** A second key, bound to the environment `content_transfer` imports *into*. */
|
|
13
|
+
export declare const TARGET_KEY_VAR = "EBITEX_CONTENT_TARGET_MANAGEMENT_KEY";
|
|
14
|
+
/**
|
|
15
|
+
* The realm this session expects its key to act in. A key is bound to one realm, so this never selects one: it is a check, made once against `GET /whoami`
|
|
16
|
+
* at startup, so a config block pointing at another brand's key stops instead of writing there. Unset, nothing is checked.
|
|
17
|
+
*/
|
|
18
|
+
export declare const REALM_VAR = "EBITEX_CONTENT_REALM";
|
|
19
|
+
export type ContentConfig = {
|
|
20
|
+
key: string;
|
|
21
|
+
/** Present only when {@link TARGET_KEY_VAR} is set; `content_transfer` is otherwise export-only. */
|
|
22
|
+
targetKey: string | null;
|
|
23
|
+
/** The realm key the operator expects the key to act in, or null for no check. */
|
|
24
|
+
expectedRealm: string | null;
|
|
25
|
+
};
|
|
26
|
+
export declare function isContentConfigured(env: Record<string, string | undefined>): boolean;
|
|
27
|
+
/** The Content app's settings. Call only once {@link isContentConfigured} is true. */
|
|
28
|
+
export declare function readContentConfig(env: Record<string, string | undefined>): ContentConfig;
|
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/apps/content/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,0GAA0G;AAC1G,eAAO,MAAM,OAAO,kCAAkC,CAAA;AAEtD,gFAAgF;AAChF,eAAO,MAAM,cAAc,yCAAyC,CAAA;AAEpE;;;GAGG;AACH,eAAO,MAAM,SAAS,yBAAyB,CAAA;AAE/C,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,oGAAoG;IACpG,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,kFAAkF;IAClF,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B,CAAA;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,CAEpF;AAED,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,aAAa,CAMxF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Content app reads from the environment.
|
|
3
|
+
*
|
|
4
|
+
* An MCP server is launched by a host process with a config block, not by a person at a prompt, so
|
|
5
|
+
* a misconfiguration has no interactive moment in which to be noticed. A key that is present but
|
|
6
|
+
* wrong stops the server at startup naming the variable; it never surfaces later as a `401` on
|
|
7
|
+
* whatever tool the agent happened to call first, which an agent would reasonably read as a wrong
|
|
8
|
+
* credential and retry.
|
|
9
|
+
*/
|
|
10
|
+
/** Minted in Content under Settings > API Keys > Management keys. Setting it turns the Content app on. */
|
|
11
|
+
export const KEY_VAR = 'EBITEX_CONTENT_MANAGEMENT_KEY';
|
|
12
|
+
/** A second key, bound to the environment `content_transfer` imports *into*. */
|
|
13
|
+
export const TARGET_KEY_VAR = 'EBITEX_CONTENT_TARGET_MANAGEMENT_KEY';
|
|
14
|
+
/**
|
|
15
|
+
* The realm this session expects its key to act in. A key is bound to one realm, so this never selects one: it is a check, made once against `GET /whoami`
|
|
16
|
+
* at startup, so a config block pointing at another brand's key stops instead of writing there. Unset, nothing is checked.
|
|
17
|
+
*/
|
|
18
|
+
export const REALM_VAR = 'EBITEX_CONTENT_REALM';
|
|
19
|
+
export function isContentConfigured(env) {
|
|
20
|
+
return Boolean(env[KEY_VAR]?.trim());
|
|
21
|
+
}
|
|
22
|
+
/** The Content app's settings. Call only once {@link isContentConfigured} is true. */
|
|
23
|
+
export function readContentConfig(env) {
|
|
24
|
+
return {
|
|
25
|
+
key: env[KEY_VAR].trim(),
|
|
26
|
+
targetKey: env[TARGET_KEY_VAR]?.trim() || null,
|
|
27
|
+
expectedRealm: env[REALM_VAR]?.trim() || null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/apps/content/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,0GAA0G;AAC1G,MAAM,CAAC,MAAM,OAAO,GAAG,+BAA+B,CAAA;AAEtD,gFAAgF;AAChF,MAAM,CAAC,MAAM,cAAc,GAAG,sCAAsC,CAAA;AAEpE;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,sBAAsB,CAAA;AAU/C,MAAM,UAAU,mBAAmB,CAAC,GAAuC;IACzE,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;AACtC,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,iBAAiB,CAAC,GAAuC;IACvE,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,OAAO,CAAE,CAAC,IAAI,EAAE;QACzB,SAAS,EAAE,GAAG,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI;QAC9C,aAAa,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI;KAC9C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a refusal from the API reaches the agent.
|
|
3
|
+
*
|
|
4
|
+
* The rule is that the error **is** the control loop. An agent works by try → read the error → fix,
|
|
5
|
+
* and that loop only closes if the error still says what to change. Content's per-entity write
|
|
6
|
+
* refuses an invalid document with the failing field's path and message; a bundle import names every
|
|
7
|
+
* invalid item. So this module's entire job is to lose none of that.
|
|
8
|
+
*
|
|
9
|
+
* Concretely, it does **not** branch on the error code, and that is deliberate rather than lazy:
|
|
10
|
+
* mapping each code to a friendly sentence is right for a person looking at a form and wrong here
|
|
11
|
+
* twice over — it discards the field paths a program needs, and it goes stale the first time the API
|
|
12
|
+
* adds a code, when an unmapped code falls through to a branch that drops the body. Emitting the
|
|
13
|
+
* whole body cannot go stale, because it makes no claim about shape.
|
|
14
|
+
*
|
|
15
|
+
* One shaping *is* applied, and only one: the body is pretty-printed. That changes no content.
|
|
16
|
+
*
|
|
17
|
+
* One line is *added*, never substituted: the request's reference, read from the `X-Request-Id`
|
|
18
|
+
* response header. It goes on its own line between the heading and the
|
|
19
|
+
* body, so the body is still relayed exactly as the server sent it — including its own `requestId`,
|
|
20
|
+
* which an unhandled `500` carries.
|
|
21
|
+
*/
|
|
22
|
+
/** A non-2xx response, carrying everything the server said about it. */
|
|
23
|
+
export declare class ContentApiError extends Error {
|
|
24
|
+
readonly status: number;
|
|
25
|
+
/** The API's own `error` code when the body carries one — `validation_failed`, `scope_denied`, … */
|
|
26
|
+
readonly code: string | null;
|
|
27
|
+
/** The parsed body, or the raw text when it was not JSON (a proxy's HTML error page, say). */
|
|
28
|
+
readonly body: unknown;
|
|
29
|
+
/**
|
|
30
|
+
* The request's reference — the `X-Request-Id` header, else the body's own `requestId` — or `null`
|
|
31
|
+
* when neither was present (a response something in front of the API generated).
|
|
32
|
+
*/
|
|
33
|
+
readonly requestId: string | null;
|
|
34
|
+
constructor(status: number, code: string | null, body: unknown, message: string, requestId?: string | null);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Builds the error from a response, reading the body once.
|
|
38
|
+
*
|
|
39
|
+
* A body that is not JSON is kept as text rather than discarded: when something in front of the API
|
|
40
|
+
* answers (a proxy timeout, a WAF), that text is the only evidence of what happened, and an empty
|
|
41
|
+
* error would send the agent looking at its own request.
|
|
42
|
+
*/
|
|
43
|
+
export declare function toContentApiError(response: Response): Promise<ContentApiError>;
|
|
44
|
+
/**
|
|
45
|
+
* The text an agent actually reads.
|
|
46
|
+
*
|
|
47
|
+
* Line one is the status and the API's own code, so the machine-readable identity is never buried.
|
|
48
|
+
* Line two, when the response carried one, is the request's reference — what support needs to find
|
|
49
|
+
* the request in the logs.
|
|
50
|
+
* Everything after it is the body, verbatim. No summary, no count, no "and 3 more" — an elision
|
|
51
|
+
* here would remove exactly the field the next call has to set.
|
|
52
|
+
*/
|
|
53
|
+
export declare function describe(status: number, code: string | null, body: unknown, requestId?: string | null): string;
|
|
54
|
+
/**
|
|
55
|
+
* The one sentence an agent can relay to its user. The key's scopes are not the problem here — the
|
|
56
|
+
* role the key runs as is — and the fix is in the key's settings, not in anything the agent can do.
|
|
57
|
+
*/
|
|
58
|
+
export declare function permissionHint(permission: string): string;
|
|
59
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/apps/content/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wEAAwE;AACxE,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,oGAAoG;IACpG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;gBAErB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAM,GAAG,IAAW;CAQjH;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC,CAkBpF;AAaD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CASpH;AASD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKzD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a refusal from the API reaches the agent.
|
|
3
|
+
*
|
|
4
|
+
* The rule is that the error **is** the control loop. An agent works by try → read the error → fix,
|
|
5
|
+
* and that loop only closes if the error still says what to change. Content's per-entity write
|
|
6
|
+
* refuses an invalid document with the failing field's path and message; a bundle import names every
|
|
7
|
+
* invalid item. So this module's entire job is to lose none of that.
|
|
8
|
+
*
|
|
9
|
+
* Concretely, it does **not** branch on the error code, and that is deliberate rather than lazy:
|
|
10
|
+
* mapping each code to a friendly sentence is right for a person looking at a form and wrong here
|
|
11
|
+
* twice over — it discards the field paths a program needs, and it goes stale the first time the API
|
|
12
|
+
* adds a code, when an unmapped code falls through to a branch that drops the body. Emitting the
|
|
13
|
+
* whole body cannot go stale, because it makes no claim about shape.
|
|
14
|
+
*
|
|
15
|
+
* One shaping *is* applied, and only one: the body is pretty-printed. That changes no content.
|
|
16
|
+
*
|
|
17
|
+
* One line is *added*, never substituted: the request's reference, read from the `X-Request-Id`
|
|
18
|
+
* response header. It goes on its own line between the heading and the
|
|
19
|
+
* body, so the body is still relayed exactly as the server sent it — including its own `requestId`,
|
|
20
|
+
* which an unhandled `500` carries.
|
|
21
|
+
*/
|
|
22
|
+
/** A non-2xx response, carrying everything the server said about it. */
|
|
23
|
+
export class ContentApiError extends Error {
|
|
24
|
+
status;
|
|
25
|
+
/** The API's own `error` code when the body carries one — `validation_failed`, `scope_denied`, … */
|
|
26
|
+
code;
|
|
27
|
+
/** The parsed body, or the raw text when it was not JSON (a proxy's HTML error page, say). */
|
|
28
|
+
body;
|
|
29
|
+
/**
|
|
30
|
+
* The request's reference — the `X-Request-Id` header, else the body's own `requestId` — or `null`
|
|
31
|
+
* when neither was present (a response something in front of the API generated).
|
|
32
|
+
*/
|
|
33
|
+
requestId;
|
|
34
|
+
constructor(status, code, body, message, requestId = null) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'ContentApiError';
|
|
37
|
+
this.status = status;
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.body = body;
|
|
40
|
+
this.requestId = requestId;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds the error from a response, reading the body once.
|
|
45
|
+
*
|
|
46
|
+
* A body that is not JSON is kept as text rather than discarded: when something in front of the API
|
|
47
|
+
* answers (a proxy timeout, a WAF), that text is the only evidence of what happened, and an empty
|
|
48
|
+
* error would send the agent looking at its own request.
|
|
49
|
+
*/
|
|
50
|
+
export async function toContentApiError(response) {
|
|
51
|
+
const text = await response.text().catch(() => '');
|
|
52
|
+
let body = text;
|
|
53
|
+
let code = null;
|
|
54
|
+
if (text) {
|
|
55
|
+
try {
|
|
56
|
+
body = JSON.parse(text);
|
|
57
|
+
if (body && typeof body === 'object' && typeof body.error === 'string') {
|
|
58
|
+
code = body.error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Not JSON. `body` stays the raw text.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const requestId = readRequestId(response, body);
|
|
66
|
+
return new ContentApiError(response.status, code, body, describe(response.status, code, body, requestId), requestId);
|
|
67
|
+
}
|
|
68
|
+
function readRequestId(response, body) {
|
|
69
|
+
const header = response.headers.get('X-Request-Id');
|
|
70
|
+
if (header)
|
|
71
|
+
return header;
|
|
72
|
+
if (body && typeof body === 'object' && typeof body.requestId === 'string') {
|
|
73
|
+
return body.requestId || null;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The text an agent actually reads.
|
|
79
|
+
*
|
|
80
|
+
* Line one is the status and the API's own code, so the machine-readable identity is never buried.
|
|
81
|
+
* Line two, when the response carried one, is the request's reference — what support needs to find
|
|
82
|
+
* the request in the logs.
|
|
83
|
+
* Everything after it is the body, verbatim. No summary, no count, no "and 3 more" — an elision
|
|
84
|
+
* here would remove exactly the field the next call has to set.
|
|
85
|
+
*/
|
|
86
|
+
export function describe(status, code, body, requestId = null) {
|
|
87
|
+
const statusLine = code ? `HTTP ${status} ${code}` : `HTTP ${status}`;
|
|
88
|
+
const withId = requestId ? `${statusLine}\nRequest id: ${requestId}` : statusLine;
|
|
89
|
+
const missing = missingPermission(status, body);
|
|
90
|
+
const heading = missing ? `${withId}\n${permissionHint(missing)}` : withId;
|
|
91
|
+
if (body === undefined || body === null || body === '')
|
|
92
|
+
return heading;
|
|
93
|
+
const rendered = typeof body === 'string' ? body : safeStringify(body);
|
|
94
|
+
return `${heading}\n${rendered}`;
|
|
95
|
+
}
|
|
96
|
+
/** The permission a `403 permission_denied` names, or null for any other response. */
|
|
97
|
+
function missingPermission(status, body) {
|
|
98
|
+
if (status !== 403 || !body || typeof body !== 'object')
|
|
99
|
+
return null;
|
|
100
|
+
const { error, permission } = body;
|
|
101
|
+
return error === 'permission_denied' && typeof permission === 'string' && permission ? permission : null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The one sentence an agent can relay to its user. The key's scopes are not the problem here — the
|
|
105
|
+
* role the key runs as is — and the fix is in the key's settings, not in anything the agent can do.
|
|
106
|
+
*/
|
|
107
|
+
export function permissionHint(permission) {
|
|
108
|
+
return (`Missing permission: ${permission}. The role this key runs as does not hold it, so the key's ` +
|
|
109
|
+
`scopes are not the problem. Ask the user to run the key as a role that has ${permission}.`);
|
|
110
|
+
}
|
|
111
|
+
function safeStringify(value) {
|
|
112
|
+
try {
|
|
113
|
+
return JSON.stringify(value, null, 2);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// A cycle cannot occur in a parsed JSON body, but stringify can still throw on a BigInt. Saying
|
|
117
|
+
// so beats throwing while reporting an error, which would replace a useful message with a
|
|
118
|
+
// useless one.
|
|
119
|
+
return String(value);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/apps/content/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wEAAwE;AACxE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAAQ;IACvB,oGAAoG;IAC3F,IAAI,CAAe;IAC5B,8FAA8F;IACrF,IAAI,CAAS;IACtB;;;OAGG;IACM,SAAS,CAAe;IAEjC,YAAY,MAAc,EAAE,IAAmB,EAAE,IAAa,EAAE,OAAe,EAAE,YAA2B,IAAI;QAC9G,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,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E,UAAU,GAAG,CAC5F,CAAA;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,gGAAgG;QAChG,0FAA0F;QAC1F,eAAe;QACf,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpCorpus.generated.d.ts","sourceRoot":"","sources":["../../../../src/apps/content/resources/helpCorpus.generated.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAErE,eAAO,MAAM,WAAW,EAAE,SAAS,EA4JlC,CAAA"}
|