@ruakit/agent 0.0.0-stage → 0.1.0-alpha.1
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/NOTICE +4 -0
- package/dist/approval.d.ts +17 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +3 -0
- package/dist/approval.js.map +7 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +3 -0
- package/dist/constants.js.map +7 -0
- package/dist/decision-runtime.d.ts +5 -0
- package/dist/decision-runtime.d.ts.map +1 -0
- package/dist/decision-runtime.js +3 -0
- package/dist/decision-runtime.js.map +7 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +3 -0
- package/dist/errors.js.map +7 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +7 -0
- package/dist/operations.d.ts +10 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +3 -0
- package/dist/operations.js.map +7 -0
- package/dist/plan-transport.d.ts +11 -0
- package/dist/plan-transport.d.ts.map +1 -0
- package/dist/plan-transport.js +3 -0
- package/dist/plan-transport.js.map +7 -0
- package/dist/plan.d.ts +47 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +3 -0
- package/dist/plan.js.map +7 -0
- package/dist/request-outcome.d.ts +43 -0
- package/dist/request-outcome.d.ts.map +1 -0
- package/dist/request-outcome.js +3 -0
- package/dist/request-outcome.js.map +7 -0
- package/dist/request-state.d.ts +84 -0
- package/dist/request-state.d.ts.map +1 -0
- package/dist/request-state.js +3 -0
- package/dist/request-state.js.map +7 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +3 -0
- package/dist/runtime.js.map +7 -0
- package/dist/session.d.ts +49 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +3 -0
- package/dist/session.js.map +7 -0
- package/dist/transport.d.ts +11 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +3 -0
- package/dist/transport.js.map +7 -0
- package/dist/user-interruption.d.ts +6 -0
- package/dist/user-interruption.d.ts.map +1 -0
- package/dist/user-interruption.js +25 -0
- package/dist/user-interruption.js.map +1 -0
- package/package.json +32 -3
- package/src/approval.ts +47 -0
- package/src/constants.ts +13 -0
- package/src/decision-runtime.ts +26 -0
- package/src/errors.ts +56 -0
- package/src/index.ts +50 -0
- package/src/operations.ts +71 -0
- package/src/plan-transport.ts +82 -0
- package/src/plan.ts +468 -0
- package/src/request-outcome.ts +58 -0
- package/src/request-state.ts +189 -0
- package/src/runtime.ts +88 -0
- package/src/session.ts +408 -0
- package/src/transport.ts +52 -0
- package/README.md +0 -3
package/src/transport.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT
|
|
2
|
+
import { decisionSchema } from '@ruakit/schema';
|
|
3
|
+
import type { DecisionRequest, Decision } from '@ruakit/schema';
|
|
4
|
+
import { RuaKitError, parsePayload } from './errors.js';
|
|
5
|
+
|
|
6
|
+
/** Replace HTTP with another planner without changing browser execution. */
|
|
7
|
+
export interface RuaKitTransport {
|
|
8
|
+
dom(request: DecisionRequest, signal: AbortSignal): Promise<Decision>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface HttpTransportOptions {
|
|
12
|
+
serverUrl?: string;
|
|
13
|
+
fetch?: typeof globalThis.fetch;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createHttpTransport(options: HttpTransportOptions = {}): RuaKitTransport {
|
|
17
|
+
const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
18
|
+
const base = (options.serverUrl ?? '').replace(/\/$/, '');
|
|
19
|
+
return {
|
|
20
|
+
async dom(request, signal) {
|
|
21
|
+
const response = await fetcher(`${base}/v1/plan`, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
signal,
|
|
24
|
+
cache: 'no-store',
|
|
25
|
+
headers: { 'Content-Type': 'application/json' },
|
|
26
|
+
body: JSON.stringify(request),
|
|
27
|
+
});
|
|
28
|
+
let data: unknown;
|
|
29
|
+
try {
|
|
30
|
+
data = await response.json();
|
|
31
|
+
} catch (cause) {
|
|
32
|
+
throw new RuaKitError('HTTP_ERROR', 'The server returned invalid JSON.', { cause });
|
|
33
|
+
}
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
const message =
|
|
36
|
+
typeof data === 'object' &&
|
|
37
|
+
data !== null &&
|
|
38
|
+
'error' in data &&
|
|
39
|
+
typeof data.error === 'string'
|
|
40
|
+
? data.error
|
|
41
|
+
: `RuaKit request failed (${response.status}).`;
|
|
42
|
+
throw new RuaKitError('HTTP_ERROR', message);
|
|
43
|
+
}
|
|
44
|
+
return parsePayload(
|
|
45
|
+
decisionSchema,
|
|
46
|
+
data,
|
|
47
|
+
'INVALID_PLAN',
|
|
48
|
+
'The server returned an invalid decision.',
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
package/README.md
DELETED