@openclaw/gateway-protocol 0.0.0 → 2026.7.2-beta.4
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/CHANGELOG.md +144 -0
- package/LICENSE +21 -0
- package/README.md +157 -2
- package/dist/client-info.d.mts +94 -0
- package/dist/client-info.mjs +82 -0
- package/dist/connect-error-details.d.mts +114 -0
- package/dist/connect-error-details.mjs +296 -0
- package/dist/frame-guards.d.mts +7 -0
- package/dist/frame-guards.mjs +26 -0
- package/dist/frames-DEn_IEne.d.mts +341 -0
- package/dist/gateway-error-details-CsX7mtLy.d.mts +52 -0
- package/dist/gateway-error-details.d.mts +2 -0
- package/dist/gateway-error-details.mjs +68 -0
- package/dist/index.d.mts +3369 -0
- package/dist/index.mjs +433 -0
- package/dist/schema-BERXGeoi.d.mts +22723 -0
- package/dist/schema-jN_1K-NS.mjs +9898 -0
- package/dist/schema.d.mts +5 -0
- package/dist/schema.mjs +4 -0
- package/dist/startup-unavailable.d.mts +23 -0
- package/dist/startup-unavailable.mjs +34 -0
- package/dist/version-COV9CEyr.d.mts +11 -0
- package/dist/version.d.mts +2 -0
- package/dist/version.mjs +11 -0
- package/npm-shrinkwrap.json +25 -0
- package/package.json +89 -6
- package/protocol.schema.json +68070 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/gateway-error-details.d.ts
|
|
2
|
+
/** Gateway JSON-RPC style error codes shared by clients and server handlers. */
|
|
3
|
+
declare const ErrorCodes: {
|
|
4
|
+
/** Client has not completed account/device linking for this gateway. */readonly NOT_LINKED: "NOT_LINKED"; /** Device exists but still needs an explicit pairing approval. */
|
|
5
|
+
readonly NOT_PAIRED: "NOT_PAIRED"; /** Agent turn exceeded the gateway wait window. */
|
|
6
|
+
readonly AGENT_TIMEOUT: "AGENT_TIMEOUT"; /** Request payload failed protocol validation or method preconditions. */
|
|
7
|
+
readonly INVALID_REQUEST: "INVALID_REQUEST"; /** Authenticated caller lacks permission for the requested operation. */
|
|
8
|
+
readonly FORBIDDEN: "FORBIDDEN"; /** Approval resolution referenced a missing or expired approval request. */
|
|
9
|
+
readonly APPROVAL_NOT_FOUND: "APPROVAL_NOT_FOUND"; /** Gateway service or required backend is temporarily unavailable. */
|
|
10
|
+
readonly UNAVAILABLE: "UNAVAILABLE";
|
|
11
|
+
};
|
|
12
|
+
/** Closed set of canonical gateway error code strings. */
|
|
13
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
14
|
+
/** Stable discriminants for structured method-level failures. */
|
|
15
|
+
declare const GatewayErrorDetailCodes: {
|
|
16
|
+
readonly MISSING_SCOPE: "MISSING_SCOPE";
|
|
17
|
+
readonly MCP_APP_VIEW_EXPIRED: "MCP_APP_VIEW_EXPIRED";
|
|
18
|
+
readonly SESSION_OBSERVER_BUSY: "SESSION_OBSERVER_BUSY";
|
|
19
|
+
readonly SESSION_OBSERVER_UNAVAILABLE: "SESSION_OBSERVER_UNAVAILABLE";
|
|
20
|
+
readonly UNKNOWN_AGENT_ID: "UNKNOWN_AGENT_ID";
|
|
21
|
+
readonly WIZARD_NOT_FOUND: "WIZARD_NOT_FOUND";
|
|
22
|
+
};
|
|
23
|
+
/** Missing operator-scope details shared by WebSocket and HTTP responses. */
|
|
24
|
+
type MissingScopeErrorDetails = {
|
|
25
|
+
code: typeof GatewayErrorDetailCodes.MISSING_SCOPE;
|
|
26
|
+
missingScope: string;
|
|
27
|
+
requiredScopes: string[];
|
|
28
|
+
};
|
|
29
|
+
type McpAppViewExpiredErrorDetails = {
|
|
30
|
+
code: typeof GatewayErrorDetailCodes.MCP_APP_VIEW_EXPIRED;
|
|
31
|
+
};
|
|
32
|
+
/** Unknown agent details carried by agent-scoped method validation failures. */
|
|
33
|
+
type UnknownAgentIdErrorDetails = {
|
|
34
|
+
code: typeof GatewayErrorDetailCodes.UNKNOWN_AGENT_ID;
|
|
35
|
+
agentId: string;
|
|
36
|
+
};
|
|
37
|
+
/** Missing or expired process-local setup wizard session. */
|
|
38
|
+
type WizardNotFoundErrorDetails = {
|
|
39
|
+
code: typeof GatewayErrorDetailCodes.WIZARD_NOT_FOUND;
|
|
40
|
+
};
|
|
41
|
+
/** Structured details emitted by method-level failures. */
|
|
42
|
+
type GatewayErrorDetails = MissingScopeErrorDetails | McpAppViewExpiredErrorDetails | UnknownAgentIdErrorDetails | WizardNotFoundErrorDetails;
|
|
43
|
+
/** Reads validated missing-scope details from an untrusted protocol payload. */
|
|
44
|
+
declare function readMissingScopeErrorDetails(details: unknown): MissingScopeErrorDetails | null;
|
|
45
|
+
declare function isMcpAppViewExpiredError(error: unknown): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a method-level missing-scope failure, preferring structured details.
|
|
48
|
+
* The message fallback keeps clients compatible with gateways predating structured details.
|
|
49
|
+
*/
|
|
50
|
+
declare function readMissingScopeError(error: unknown): MissingScopeErrorDetails | null;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { McpAppViewExpiredErrorDetails as a, WizardNotFoundErrorDetails as c, readMissingScopeErrorDetails as d, GatewayErrorDetails as i, isMcpAppViewExpiredError as l, ErrorCodes as n, MissingScopeErrorDetails as o, GatewayErrorDetailCodes as r, UnknownAgentIdErrorDetails as s, ErrorCode as t, readMissingScopeError as u };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as McpAppViewExpiredErrorDetails, c as WizardNotFoundErrorDetails, d as readMissingScopeErrorDetails, i as GatewayErrorDetails, l as isMcpAppViewExpiredError, n as ErrorCodes, o as MissingScopeErrorDetails, r as GatewayErrorDetailCodes, s as UnknownAgentIdErrorDetails, t as ErrorCode, u as readMissingScopeError } from "./gateway-error-details-CsX7mtLy.mjs";
|
|
2
|
+
export { ErrorCode, ErrorCodes, GatewayErrorDetailCodes, GatewayErrorDetails, McpAppViewExpiredErrorDetails, MissingScopeErrorDetails, UnknownAgentIdErrorDetails, WizardNotFoundErrorDetails, isMcpAppViewExpiredError, readMissingScopeError, readMissingScopeErrorDetails };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/gateway-error-details.ts
|
|
2
|
+
/** Gateway JSON-RPC style error codes shared by clients and server handlers. */
|
|
3
|
+
const ErrorCodes = {
|
|
4
|
+
/** Client has not completed account/device linking for this gateway. */
|
|
5
|
+
NOT_LINKED: "NOT_LINKED",
|
|
6
|
+
/** Device exists but still needs an explicit pairing approval. */
|
|
7
|
+
NOT_PAIRED: "NOT_PAIRED",
|
|
8
|
+
/** Agent turn exceeded the gateway wait window. */
|
|
9
|
+
AGENT_TIMEOUT: "AGENT_TIMEOUT",
|
|
10
|
+
/** Request payload failed protocol validation or method preconditions. */
|
|
11
|
+
INVALID_REQUEST: "INVALID_REQUEST",
|
|
12
|
+
/** Authenticated caller lacks permission for the requested operation. */
|
|
13
|
+
FORBIDDEN: "FORBIDDEN",
|
|
14
|
+
/** Approval resolution referenced a missing or expired approval request. */
|
|
15
|
+
APPROVAL_NOT_FOUND: "APPROVAL_NOT_FOUND",
|
|
16
|
+
/** Gateway service or required backend is temporarily unavailable. */
|
|
17
|
+
UNAVAILABLE: "UNAVAILABLE"
|
|
18
|
+
};
|
|
19
|
+
/** Stable discriminants for structured method-level failures. */
|
|
20
|
+
const GatewayErrorDetailCodes = {
|
|
21
|
+
MISSING_SCOPE: "MISSING_SCOPE",
|
|
22
|
+
MCP_APP_VIEW_EXPIRED: "MCP_APP_VIEW_EXPIRED",
|
|
23
|
+
SESSION_OBSERVER_BUSY: "SESSION_OBSERVER_BUSY",
|
|
24
|
+
SESSION_OBSERVER_UNAVAILABLE: "SESSION_OBSERVER_UNAVAILABLE",
|
|
25
|
+
UNKNOWN_AGENT_ID: "UNKNOWN_AGENT_ID",
|
|
26
|
+
WIZARD_NOT_FOUND: "WIZARD_NOT_FOUND"
|
|
27
|
+
};
|
|
28
|
+
const LEGACY_MISSING_SCOPE_PATTERN = /\bmissing scope:\s*([a-z0-9._-]+)/i;
|
|
29
|
+
function asRecord(value) {
|
|
30
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
31
|
+
}
|
|
32
|
+
/** Reads validated missing-scope details from an untrusted protocol payload. */
|
|
33
|
+
function readMissingScopeErrorDetails(details) {
|
|
34
|
+
const record = asRecord(details);
|
|
35
|
+
if (record?.code !== GatewayErrorDetailCodes.MISSING_SCOPE) return null;
|
|
36
|
+
const missingScope = typeof record.missingScope === "string" ? record.missingScope.trim() : "";
|
|
37
|
+
const requiredScopes = Array.isArray(record.requiredScopes) ? record.requiredScopes.map((scope) => typeof scope === "string" ? scope.trim() : "") : [];
|
|
38
|
+
if (!missingScope || requiredScopes.length === 0 || requiredScopes.some((scope) => !scope)) return null;
|
|
39
|
+
return {
|
|
40
|
+
code: GatewayErrorDetailCodes.MISSING_SCOPE,
|
|
41
|
+
missingScope,
|
|
42
|
+
requiredScopes
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function isMcpAppViewExpiredError(error) {
|
|
46
|
+
return asRecord(asRecord(error)?.details)?.code === GatewayErrorDetailCodes.MCP_APP_VIEW_EXPIRED;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Reads a method-level missing-scope failure, preferring structured details.
|
|
50
|
+
* The message fallback keeps clients compatible with gateways predating structured details.
|
|
51
|
+
*/
|
|
52
|
+
function readMissingScopeError(error) {
|
|
53
|
+
const record = asRecord(error);
|
|
54
|
+
if (!record) return null;
|
|
55
|
+
const structured = readMissingScopeErrorDetails(record.details);
|
|
56
|
+
if (structured) return structured;
|
|
57
|
+
const gatewayError = record;
|
|
58
|
+
const code = typeof gatewayError.gatewayCode === "string" ? gatewayError.gatewayCode : typeof gatewayError.code === "string" ? gatewayError.code : "";
|
|
59
|
+
if (code !== ErrorCodes.FORBIDDEN && code !== ErrorCodes.INVALID_REQUEST) return null;
|
|
60
|
+
const missingScope = (typeof gatewayError.message === "string" ? gatewayError.message : "").match(LEGACY_MISSING_SCOPE_PATTERN)?.[1];
|
|
61
|
+
return missingScope ? {
|
|
62
|
+
code: GatewayErrorDetailCodes.MISSING_SCOPE,
|
|
63
|
+
missingScope,
|
|
64
|
+
requiredScopes: [missingScope]
|
|
65
|
+
} : null;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ErrorCodes, GatewayErrorDetailCodes, isMcpAppViewExpiredError, readMissingScopeError, readMissingScopeErrorDetails };
|