@crosshands/contract 0.1.2
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 +21 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +82 -0
- package/dist/context.js.map +1 -0
- package/dist/errors.d.ts +164 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -0
- package/dist/generate-schemas.d.ts +2 -0
- package/dist/generate-schemas.d.ts.map +1 -0
- package/dist/generate-schemas.js +8 -0
- package/dist/generate-schemas.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +306 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +15 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/operations.d.ts +2115 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +205 -0
- package/dist/operations.js.map +1 -0
- package/dist/provider.d.ts +135 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +56 -0
- package/dist/provider.js.map +1 -0
- package/dist/schemas.d.ts +499 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +138 -0
- package/dist/schemas.js.map +1 -0
- package/dist/versions.d.ts +31 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +28 -0
- package/dist/versions.js.map +1 -0
- package/package.json +39 -0
- package/schemas/contract.json +7572 -0
- package/src/context.ts +107 -0
- package/src/errors.ts +82 -0
- package/src/generate-schemas.ts +9 -0
- package/src/index.ts +7 -0
- package/src/json-schema.ts +17 -0
- package/src/operations.ts +224 -0
- package/src/provider.ts +82 -0
- package/src/schemas.ts +161 -0
- package/src/versions.ts +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CrossHands contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InteractionContext, ReferenceBindings, TargetReference } from './schemas.js';
|
|
2
|
+
export declare const DEFAULT_INTERACTION_CONTEXT_TTL_MS = 120000;
|
|
3
|
+
export declare const DEFAULT_INTERACTION_CONTEXT_LIMIT = 32;
|
|
4
|
+
type InteractionContextStoreOptions = {
|
|
5
|
+
ttlMs?: number;
|
|
6
|
+
limit?: number;
|
|
7
|
+
now?: () => number;
|
|
8
|
+
tokenFactory?: () => string;
|
|
9
|
+
};
|
|
10
|
+
export declare class InteractionContextStore {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options?: InteractionContextStoreOptions);
|
|
13
|
+
issue(bindings: ReferenceBindings): InteractionContext;
|
|
14
|
+
resolve(token: string, now?: number): InteractionContext;
|
|
15
|
+
invalidateAll(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function assertReferenceFresh(reference: TargetReference, context: InteractionContext, current: ReferenceBindings, now?: number): void;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE1F,eAAO,MAAM,kCAAkC,SAAU,CAAA;AACzD,eAAO,MAAM,iCAAiC,KAAK,CAAA;AAEnD,KAAK,8BAA8B,GAAG;IACpC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,MAAM,CAAA;CAC5B,CAAA;AAED,qBAAa,uBAAuB;;gBAOtB,OAAO,GAAE,8BAAmC;IAUxD,KAAK,CAAC,QAAQ,EAAE,iBAAiB,GAAG,kBAAkB;IAkBtD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAc,GAAG,kBAAkB;IAe7D,aAAa,IAAI,IAAI;CAGtB;AAUD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,iBAAiB,EAC1B,GAAG,SAAa,GACf,IAAI,CAuBN"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { createComputerError } from './errors.js';
|
|
3
|
+
export const DEFAULT_INTERACTION_CONTEXT_TTL_MS = 120_000;
|
|
4
|
+
export const DEFAULT_INTERACTION_CONTEXT_LIMIT = 32;
|
|
5
|
+
export class InteractionContextStore {
|
|
6
|
+
#ttlMs;
|
|
7
|
+
#limit;
|
|
8
|
+
#now;
|
|
9
|
+
#tokenFactory;
|
|
10
|
+
#contexts = new Map();
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.#ttlMs = options.ttlMs ?? DEFAULT_INTERACTION_CONTEXT_TTL_MS;
|
|
13
|
+
this.#limit = options.limit ?? DEFAULT_INTERACTION_CONTEXT_LIMIT;
|
|
14
|
+
this.#now = options.now ?? Date.now;
|
|
15
|
+
this.#tokenFactory =
|
|
16
|
+
options.tokenFactory ?? (() => `ctx_${randomBytes(24).toString('base64url')}`);
|
|
17
|
+
if (this.#ttlMs <= 0 || this.#limit <= 0)
|
|
18
|
+
throw new RangeError('Context TTL and limit must be positive');
|
|
19
|
+
}
|
|
20
|
+
issue(bindings) {
|
|
21
|
+
const issuedAtMs = this.#now();
|
|
22
|
+
const context = {
|
|
23
|
+
token: this.#tokenFactory(),
|
|
24
|
+
...bindings,
|
|
25
|
+
issuedAt: new Date(issuedAtMs).toISOString(),
|
|
26
|
+
expiresAt: new Date(issuedAtMs + this.#ttlMs).toISOString()
|
|
27
|
+
};
|
|
28
|
+
this.#contexts.delete(context.token);
|
|
29
|
+
this.#contexts.set(context.token, context);
|
|
30
|
+
while (this.#contexts.size > this.#limit) {
|
|
31
|
+
const oldest = this.#contexts.keys().next().value;
|
|
32
|
+
if (oldest === undefined)
|
|
33
|
+
break;
|
|
34
|
+
this.#contexts.delete(oldest);
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
resolve(token, now = this.#now()) {
|
|
39
|
+
const context = this.#contexts.get(token);
|
|
40
|
+
if (context === undefined) {
|
|
41
|
+
throw createComputerError('interaction_context_invalid', 'Interaction context is unknown or forged');
|
|
42
|
+
}
|
|
43
|
+
if (Date.parse(context.expiresAt) < now) {
|
|
44
|
+
this.#contexts.delete(token);
|
|
45
|
+
throw createComputerError('interaction_context_expired', 'Interaction context has expired');
|
|
46
|
+
}
|
|
47
|
+
return context;
|
|
48
|
+
}
|
|
49
|
+
invalidateAll() {
|
|
50
|
+
this.#contexts.clear();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function sameProcess(a, b) {
|
|
54
|
+
return a.pid === b.pid && a.startedAt === b.startedAt && a.executableId === b.executableId;
|
|
55
|
+
}
|
|
56
|
+
function sameWindow(a, b) {
|
|
57
|
+
return a.id === b.id && a.ownerPid === b.ownerPid;
|
|
58
|
+
}
|
|
59
|
+
export function assertReferenceFresh(reference, context, current, now = Date.now()) {
|
|
60
|
+
const stale = reference.contextToken !== context.token ||
|
|
61
|
+
reference.brokerGeneration !== context.brokerGeneration ||
|
|
62
|
+
reference.providerGeneration !== context.providerGeneration ||
|
|
63
|
+
reference.graphicalSessionId !== context.graphicalSessionId ||
|
|
64
|
+
reference.brokerGeneration !== current.brokerGeneration ||
|
|
65
|
+
reference.providerGeneration !== current.providerGeneration ||
|
|
66
|
+
reference.graphicalSessionId !== current.graphicalSessionId ||
|
|
67
|
+
!sameProcess(reference.process, context.process) ||
|
|
68
|
+
!sameProcess(reference.process, current.process) ||
|
|
69
|
+
reference.appId !== context.appId ||
|
|
70
|
+
reference.appId !== current.appId ||
|
|
71
|
+
!sameWindow(reference.window, context.window) ||
|
|
72
|
+
!sameWindow(reference.window, current.window) ||
|
|
73
|
+
reference.snapshotId !== context.snapshotId ||
|
|
74
|
+
reference.snapshotId !== current.snapshotId ||
|
|
75
|
+
reference.desktopEpoch !== context.desktopEpoch ||
|
|
76
|
+
reference.desktopEpoch !== current.desktopEpoch ||
|
|
77
|
+
Date.parse(reference.expiresAt) < now ||
|
|
78
|
+
Date.parse(context.expiresAt) < now;
|
|
79
|
+
if (stale)
|
|
80
|
+
throw createComputerError('stale_target', 'Target reference is no longer fresh');
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -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QAC3C,SAAS,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU;QAC3C,SAAS,CAAC,YAAY,KAAK,OAAO,CAAC,YAAY;QAC/C,SAAS,CAAC,YAAY,KAAK,OAAO,CAAC,YAAY;QAC/C,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,GAAG;QACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,GAAG,CAAA;IAErC,IAAI,KAAK;QAAE,MAAM,mBAAmB,CAAC,cAAc,EAAE,qCAAqC,CAAC,CAAA;AAC7F,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ERROR_CATALOG: {
|
|
3
|
+
readonly app_not_found: {
|
|
4
|
+
readonly retry: true;
|
|
5
|
+
readonly remediation: "refresh_apps";
|
|
6
|
+
};
|
|
7
|
+
readonly app_unavailable: {
|
|
8
|
+
readonly retry: true;
|
|
9
|
+
readonly remediation: "refresh_apps";
|
|
10
|
+
};
|
|
11
|
+
readonly app_blocked: {
|
|
12
|
+
readonly retry: false;
|
|
13
|
+
readonly remediation: "choose_non_sensitive_target";
|
|
14
|
+
};
|
|
15
|
+
readonly window_not_found: {
|
|
16
|
+
readonly retry: true;
|
|
17
|
+
readonly remediation: "refresh_windows";
|
|
18
|
+
};
|
|
19
|
+
readonly window_unavailable: {
|
|
20
|
+
readonly retry: true;
|
|
21
|
+
readonly remediation: "refresh_windows";
|
|
22
|
+
};
|
|
23
|
+
readonly window_not_focused: {
|
|
24
|
+
readonly retry: true;
|
|
25
|
+
readonly remediation: "focus_window";
|
|
26
|
+
};
|
|
27
|
+
readonly permission_denied: {
|
|
28
|
+
readonly retry: false;
|
|
29
|
+
readonly remediation: "grant_permission";
|
|
30
|
+
};
|
|
31
|
+
readonly stale_target: {
|
|
32
|
+
readonly retry: true;
|
|
33
|
+
readonly remediation: "refresh_state";
|
|
34
|
+
};
|
|
35
|
+
readonly element_not_found: {
|
|
36
|
+
readonly retry: true;
|
|
37
|
+
readonly remediation: "refresh_state";
|
|
38
|
+
};
|
|
39
|
+
readonly element_not_clickable: {
|
|
40
|
+
readonly retry: true;
|
|
41
|
+
readonly remediation: "choose_actionable_target";
|
|
42
|
+
};
|
|
43
|
+
readonly action_not_supported: {
|
|
44
|
+
readonly retry: false;
|
|
45
|
+
readonly remediation: "choose_supported_operation";
|
|
46
|
+
};
|
|
47
|
+
readonly value_not_settable: {
|
|
48
|
+
readonly retry: false;
|
|
49
|
+
readonly remediation: "choose_settable_target";
|
|
50
|
+
};
|
|
51
|
+
readonly invalid_argument: {
|
|
52
|
+
readonly retry: false;
|
|
53
|
+
readonly remediation: "correct_request";
|
|
54
|
+
};
|
|
55
|
+
readonly timeout: {
|
|
56
|
+
readonly retry: false;
|
|
57
|
+
readonly remediation: "inspect_state_before_retry";
|
|
58
|
+
};
|
|
59
|
+
readonly unsupported_capability: {
|
|
60
|
+
readonly retry: false;
|
|
61
|
+
readonly remediation: "choose_supported_operation";
|
|
62
|
+
};
|
|
63
|
+
readonly provider_unavailable: {
|
|
64
|
+
readonly retry: true;
|
|
65
|
+
readonly remediation: "run_doctor";
|
|
66
|
+
};
|
|
67
|
+
readonly provider_crashed: {
|
|
68
|
+
readonly retry: true;
|
|
69
|
+
readonly remediation: "refresh_state";
|
|
70
|
+
};
|
|
71
|
+
readonly version_incompatible: {
|
|
72
|
+
readonly retry: false;
|
|
73
|
+
readonly remediation: "upgrade_or_downgrade";
|
|
74
|
+
};
|
|
75
|
+
readonly interaction_context_invalid: {
|
|
76
|
+
readonly retry: true;
|
|
77
|
+
readonly remediation: "refresh_state";
|
|
78
|
+
};
|
|
79
|
+
readonly interaction_context_expired: {
|
|
80
|
+
readonly retry: true;
|
|
81
|
+
readonly remediation: "refresh_state";
|
|
82
|
+
};
|
|
83
|
+
readonly session_unavailable: {
|
|
84
|
+
readonly retry: true;
|
|
85
|
+
readonly remediation: "unlock_graphical_session";
|
|
86
|
+
};
|
|
87
|
+
readonly screenshot_failed: {
|
|
88
|
+
readonly retry: true;
|
|
89
|
+
readonly remediation: "check_screenshot_permission";
|
|
90
|
+
};
|
|
91
|
+
readonly accessibility_error: {
|
|
92
|
+
readonly retry: true;
|
|
93
|
+
readonly remediation: "check_accessibility_permission";
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export type ComputerErrorCode = keyof typeof ERROR_CATALOG;
|
|
97
|
+
export type ComputerErrorRemediation = (typeof ERROR_CATALOG)[ComputerErrorCode]['remediation'];
|
|
98
|
+
export declare const ComputerErrorCodeSchema: z.ZodEnum<{
|
|
99
|
+
app_not_found: "app_not_found";
|
|
100
|
+
app_unavailable: "app_unavailable";
|
|
101
|
+
app_blocked: "app_blocked";
|
|
102
|
+
window_not_found: "window_not_found";
|
|
103
|
+
window_unavailable: "window_unavailable";
|
|
104
|
+
window_not_focused: "window_not_focused";
|
|
105
|
+
permission_denied: "permission_denied";
|
|
106
|
+
stale_target: "stale_target";
|
|
107
|
+
element_not_found: "element_not_found";
|
|
108
|
+
element_not_clickable: "element_not_clickable";
|
|
109
|
+
action_not_supported: "action_not_supported";
|
|
110
|
+
value_not_settable: "value_not_settable";
|
|
111
|
+
invalid_argument: "invalid_argument";
|
|
112
|
+
timeout: "timeout";
|
|
113
|
+
unsupported_capability: "unsupported_capability";
|
|
114
|
+
provider_unavailable: "provider_unavailable";
|
|
115
|
+
provider_crashed: "provider_crashed";
|
|
116
|
+
version_incompatible: "version_incompatible";
|
|
117
|
+
interaction_context_invalid: "interaction_context_invalid";
|
|
118
|
+
interaction_context_expired: "interaction_context_expired";
|
|
119
|
+
session_unavailable: "session_unavailable";
|
|
120
|
+
screenshot_failed: "screenshot_failed";
|
|
121
|
+
accessibility_error: "accessibility_error";
|
|
122
|
+
}>;
|
|
123
|
+
export declare const SerializedComputerErrorSchema: z.ZodObject<{
|
|
124
|
+
code: z.ZodEnum<{
|
|
125
|
+
app_not_found: "app_not_found";
|
|
126
|
+
app_unavailable: "app_unavailable";
|
|
127
|
+
app_blocked: "app_blocked";
|
|
128
|
+
window_not_found: "window_not_found";
|
|
129
|
+
window_unavailable: "window_unavailable";
|
|
130
|
+
window_not_focused: "window_not_focused";
|
|
131
|
+
permission_denied: "permission_denied";
|
|
132
|
+
stale_target: "stale_target";
|
|
133
|
+
element_not_found: "element_not_found";
|
|
134
|
+
element_not_clickable: "element_not_clickable";
|
|
135
|
+
action_not_supported: "action_not_supported";
|
|
136
|
+
value_not_settable: "value_not_settable";
|
|
137
|
+
invalid_argument: "invalid_argument";
|
|
138
|
+
timeout: "timeout";
|
|
139
|
+
unsupported_capability: "unsupported_capability";
|
|
140
|
+
provider_unavailable: "provider_unavailable";
|
|
141
|
+
provider_crashed: "provider_crashed";
|
|
142
|
+
version_incompatible: "version_incompatible";
|
|
143
|
+
interaction_context_invalid: "interaction_context_invalid";
|
|
144
|
+
interaction_context_expired: "interaction_context_expired";
|
|
145
|
+
session_unavailable: "session_unavailable";
|
|
146
|
+
screenshot_failed: "screenshot_failed";
|
|
147
|
+
accessibility_error: "accessibility_error";
|
|
148
|
+
}>;
|
|
149
|
+
message: z.ZodString;
|
|
150
|
+
retry: z.ZodBoolean;
|
|
151
|
+
remediation: z.ZodString;
|
|
152
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
153
|
+
}, z.core.$strict>;
|
|
154
|
+
export type SerializedComputerError = z.infer<typeof SerializedComputerErrorSchema>;
|
|
155
|
+
export declare class ComputerError extends Error {
|
|
156
|
+
readonly code: ComputerErrorCode;
|
|
157
|
+
readonly retry: boolean;
|
|
158
|
+
readonly remediation: ComputerErrorRemediation;
|
|
159
|
+
readonly details: unknown;
|
|
160
|
+
constructor(code: ComputerErrorCode, message: string, details?: unknown);
|
|
161
|
+
toJSON(): SerializedComputerError;
|
|
162
|
+
}
|
|
163
|
+
export declare function createComputerError(code: ComputerErrorCode, message: string, details?: unknown): ComputerError;
|
|
164
|
+
//# sour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
+
export const ERROR_CATALOG = {
|
|
3
|
+
app_not_found: { retry: true, remediation: 'refresh_apps' },
|
|
4
|
+
app_unavailable: { retry: true, remediation: 'refresh_apps' },
|
|
5
|
+
app_blocked: { retry: false, remediation: 'choose_non_sensitive_target' },
|
|
6
|
+
window_not_found: { retry: true, remediation: 'refresh_windows' },
|
|
7
|
+
window_unavailable: { retry: true, remediation: 'refresh_windows' },
|
|
8
|
+
window_not_focused: { retry: true, remediation: 'focus_window' },
|
|
9
|
+
permission_denied: { retry: false, remediation: 'grant_permission' },
|
|
10
|
+
stale_target: { retry: true, remediation: 'refresh_state' },
|
|
11
|
+
element_not_found: { retry: true, remediation: 'refresh_state' },
|
|
12
|
+
element_not_clickable: { retry: true, remediation: 'choose_actionable_target' },
|
|
13
|
+
action_not_supported: { retry: false, remediation: 'choose_supported_operation' },
|
|
14
|
+
value_not_settable: { retry: false, remediation: 'choose_settable_target' },
|
|
15
|
+
invalid_argument: { retry: false, remediation: 'correct_request' },
|
|
16
|
+
timeout: { retry: false, remediation: 'inspect_state_before_retry' },
|
|
17
|
+
unsupported_capability: { retry: false, remediation: 'choose_supported_operation' },
|
|
18
|
+
provider_unavailable: { retry: true, remediation: 'run_doctor' },
|
|
19
|
+
provider_crashed: { retry: true, remediation: 'refresh_state' },
|
|
20
|
+
version_incompatible: { retry: false, remediation: 'upgrade_or_downgrade' },
|
|
21
|
+
interaction_context_invalid: { retry: true, remediation: 'refresh_state' },
|
|
22
|
+
interaction_context_expired: { retry: true, remediation: 'refresh_state' },
|
|
23
|
+
session_unavailable: { retry: true, remediation: 'unlock_graphical_session' },
|
|
24
|
+
screenshot_failed: { retry: true, remediation: 'check_screenshot_permission' },
|
|
25
|
+
accessibility_error: { retry: true, remediation: 'check_accessibility_permission' }
|
|
26
|
+
};
|
|
27
|
+
export const ComputerErrorCodeSchema = z.enum(Object.keys(ERROR_CATALOG));
|
|
28
|
+
export const SerializedComputerErrorSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
code: ComputerErrorCodeSchema,
|
|
31
|
+
message: z.string().min(1),
|
|
32
|
+
retry: z.boolean(),
|
|
33
|
+
remediation: z.string().min(1),
|
|
34
|
+
details: z.unknown().optional()
|
|
35
|
+
})
|
|
36
|
+
.strict();
|
|
37
|
+
export class ComputerError extends Error {
|
|
38
|
+
code;
|
|
39
|
+
retry;
|
|
40
|
+
remediation;
|
|
41
|
+
details;
|
|
42
|
+
constructor(code, message, details) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = 'ComputerError';
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.retry = ERROR_CATALOG[code].retry;
|
|
47
|
+
this.remediation = ERROR_CATALOG[code].remediation;
|
|
48
|
+
this.details = details;
|
|
49
|
+
}
|
|
50
|
+
toJSON() {
|
|
51
|
+
return this.details === undefined
|
|
52
|
+
? { code: this.code, message: this.message, retry: this.retry, remediation: this.remediation }
|
|
53
|
+
: {
|
|
54
|
+
code: this.code,
|
|
55
|
+
message: this.message,
|
|
56
|
+
retry: this.retry,
|
|
57
|
+
remediation: this.remediation,
|
|
58
|
+
details: this.details
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function createComputerError(code, message, details) {
|
|
63
|
+
return new ComputerError(code, message, details);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE;IAC3D,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE;IAC7D,WAAW,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,6BAA6B,EAAE;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,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO,KAAK,SAAS;YAC/B,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;YAC9F,CAAC,CAAC;gBACE,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAA;IACP,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CACjC,IAAuB,EACvB,OAAe,EACf,OAAiB;IAEjB,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AAClD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-schemas.d.ts","sourceRoot":"","sources":["../src/generate-schemas.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { contractJsonSchemas } from './json-schema.js';
|
|
5
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const output = resolve(here, '../schemas/contract.json');
|
|
7
|
+
await writeFile(output, `${JSON.stringify(contractJsonSchemas, null, 2)}\n`, 'utf8');
|
|
8
|
+
//# sourceMappingURL=generate-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-schemas.js","sourceRoot":"","sources":["../src/generate-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AACpD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAA;AACxD,MAAM,SAAS,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './context.js';
|
|
2
|
+
export * from './errors.js';
|
|
3
|
+
export * from './json-schema.js';
|
|
4
|
+
export * from './operations.js';
|
|
5
|
+
export * from './provider.js';
|
|
6
|
+
export * from './schemas.js';
|
|
7
|
+
export * from './versions.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
|