@maiaos/sdk 0.1.0-canary.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/README.md +177 -0
- package/dist/agent-permission/agent-permission.d.ts +9 -0
- package/dist/agent-permission/agent-permission.js +5 -0
- package/dist/agent-permission/effect.d.ts +4 -0
- package/dist/agent-permission/effect.js +34 -0
- package/dist/agent-permission/index.d.ts +2 -0
- package/dist/agent-permission/index.js +2 -0
- package/dist/approval/approval.d.ts +10 -0
- package/dist/approval/approval.js +5 -0
- package/dist/approval/effect.d.ts +5 -0
- package/dist/approval/effect.js +43 -0
- package/dist/approval/index.d.ts +2 -0
- package/dist/approval/index.js +2 -0
- package/dist/call/call.d.ts +26 -0
- package/dist/call/call.js +6 -0
- package/dist/call/effect.d.ts +5 -0
- package/dist/call/effect.js +46 -0
- package/dist/call/index.d.ts +2 -0
- package/dist/call/index.js +2 -0
- package/dist/client/effect.d.ts +8 -0
- package/dist/client/effect.js +283 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/local-node-client.d.ts +100 -0
- package/dist/client/local-node-client.js +4 -0
- package/dist/connection/connection.d.ts +19 -0
- package/dist/connection/connection.js +5 -0
- package/dist/connection/effect.d.ts +5 -0
- package/dist/connection/effect.js +119 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.js +2 -0
- package/dist/container/container.d.ts +14 -0
- package/dist/container/container.js +5 -0
- package/dist/container/effect.d.ts +4 -0
- package/dist/container/effect.js +90 -0
- package/dist/container/index.d.ts +2 -0
- package/dist/container/index.js +2 -0
- package/dist/discovery/discovery.d.ts +11 -0
- package/dist/discovery/discovery.js +5 -0
- package/dist/discovery/effect.d.ts +5 -0
- package/dist/discovery/effect.js +44 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/discovery/index.js +2 -0
- package/dist/execution/effect.d.ts +4 -0
- package/dist/execution/effect.js +8 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/relocation.d.ts +10 -0
- package/dist/execution/relocation.js +4 -0
- package/dist/feature-bindings/feature-bindings.d.ts +10 -0
- package/dist/feature-bindings/feature-bindings.js +2 -0
- package/dist/feature-bindings/index.d.ts +2 -0
- package/dist/feature-bindings/index.js +2 -0
- package/dist/hold/effect.d.ts +5 -0
- package/dist/hold/effect.js +61 -0
- package/dist/hold/hold.d.ts +12 -0
- package/dist/hold/hold.js +5 -0
- package/dist/hold/index.d.ts +2 -0
- package/dist/hold/index.js +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +21 -0
- package/dist/interaction/effect.d.ts +5 -0
- package/dist/interaction/effect.js +79 -0
- package/dist/interaction/index.d.ts +2 -0
- package/dist/interaction/index.js +2 -0
- package/dist/interaction/interaction.d.ts +12 -0
- package/dist/interaction/interaction.js +5 -0
- package/dist/node/attach.d.ts +11 -0
- package/dist/node/attach.js +33 -0
- package/dist/node/bridge-frame.d.ts +18 -0
- package/dist/node/bridge-frame.js +67 -0
- package/dist/node/bridge.d.ts +31 -0
- package/dist/node/bridge.js +148 -0
- package/dist/node/discovery.d.ts +187 -0
- package/dist/node/discovery.js +408 -0
- package/dist/node/effect.d.ts +9 -0
- package/dist/node/effect.js +9 -0
- package/dist/node/fetch.d.ts +2 -0
- package/dist/node/fetch.js +2 -0
- package/dist/node/http.d.ts +27 -0
- package/dist/node/http.js +258 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +3 -0
- package/dist/node/local-node.d.ts +26 -0
- package/dist/node/local-node.js +67 -0
- package/dist/node/session.d.ts +15 -0
- package/dist/node/session.js +27 -0
- package/dist/node/ssh.d.ts +16 -0
- package/dist/node/ssh.js +74 -0
- package/dist/node/transport.d.ts +52 -0
- package/dist/node/transport.js +211 -0
- package/dist/node-changes/effect.d.ts +11 -0
- package/dist/node-changes/effect.js +61 -0
- package/dist/node-changes/index.d.ts +2 -0
- package/dist/node-changes/index.js +2 -0
- package/dist/node-changes/node-changes.d.ts +21 -0
- package/dist/node-changes/node-changes.js +23 -0
- package/dist/port-lease/effect.d.ts +5 -0
- package/dist/port-lease/effect.js +53 -0
- package/dist/port-lease/index.d.ts +2 -0
- package/dist/port-lease/index.js +2 -0
- package/dist/port-lease/port-lease.d.ts +11 -0
- package/dist/port-lease/port-lease.js +5 -0
- package/dist/presentation/client.d.ts +10 -0
- package/dist/presentation/client.js +4 -0
- package/dist/presentation/effect.d.ts +5 -0
- package/dist/presentation/effect.js +30 -0
- package/dist/presentation/index.d.ts +5 -0
- package/dist/presentation/index.js +3 -0
- package/dist/presentation/project-list.d.ts +7 -0
- package/dist/presentation/project-list.js +24 -0
- package/dist/presentation/session-list.d.ts +7 -0
- package/dist/presentation/session-list.js +32 -0
- package/dist/project-guard/effect.d.ts +5 -0
- package/dist/project-guard/effect.js +39 -0
- package/dist/project-guard/index.d.ts +2 -0
- package/dist/project-guard/index.js +2 -0
- package/dist/project-guard/project-guard.d.ts +10 -0
- package/dist/project-guard/project-guard.js +5 -0
- package/dist/project-workspace/effect.d.ts +5 -0
- package/dist/project-workspace/effect.js +124 -0
- package/dist/project-workspace/index.d.ts +2 -0
- package/dist/project-workspace/index.js +2 -0
- package/dist/project-workspace/project-workspace.d.ts +23 -0
- package/dist/project-workspace/project-workspace.js +4 -0
- package/dist/provider-pool/effect.d.ts +4 -0
- package/dist/provider-pool/effect.js +5 -0
- package/dist/provider-pool/index.d.ts +2 -0
- package/dist/provider-pool/index.js +2 -0
- package/dist/provider-pool/provider-pool.d.ts +7 -0
- package/dist/provider-pool/provider-pool.js +4 -0
- package/dist/remote-node/effect.d.ts +4 -0
- package/dist/remote-node/effect.js +57 -0
- package/dist/remote-node/index.d.ts +2 -0
- package/dist/remote-node/index.js +2 -0
- package/dist/remote-node/remote-node.d.ts +12 -0
- package/dist/remote-node/remote-node.js +5 -0
- package/dist/request/classify.d.ts +15 -0
- package/dist/request/classify.js +96 -0
- package/dist/request/client-error.d.ts +10 -0
- package/dist/request/client-error.js +11 -0
- package/dist/request/effect.d.ts +22 -0
- package/dist/request/effect.js +104 -0
- package/dist/request/envelope-schema.d.ts +2 -0
- package/dist/request/envelope-schema.js +2 -0
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.js +4 -0
- package/dist/request/maia-client.d.ts +21 -0
- package/dist/request/maia-client.js +9 -0
- package/dist/request/options.d.ts +9 -0
- package/dist/request/options.js +2 -0
- package/dist/run-ledger/effect.d.ts +5 -0
- package/dist/run-ledger/effect.js +72 -0
- package/dist/run-ledger/index.d.ts +2 -0
- package/dist/run-ledger/index.js +2 -0
- package/dist/run-ledger/run-ledger.d.ts +12 -0
- package/dist/run-ledger/run-ledger.js +2 -0
- package/dist/session/effect.d.ts +4 -0
- package/dist/session/effect.js +7 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +2 -0
- package/dist/session/mailbox.d.ts +9 -0
- package/dist/session/mailbox.js +4 -0
- package/dist/session-creation/effect.d.ts +25 -0
- package/dist/session-creation/effect.js +269 -0
- package/dist/session-creation/index.d.ts +3 -0
- package/dist/session-creation/index.js +3 -0
- package/dist/session-creation/session-creation.d.ts +18 -0
- package/dist/session-creation/session-creation.js +24 -0
- package/dist/session-creation/tasks.d.ts +69 -0
- package/dist/session-creation/tasks.js +37 -0
- package/dist/session-view/index.d.ts +2 -0
- package/dist/session-view/index.js +2 -0
- package/dist/session-view/view.d.ts +42 -0
- package/dist/session-view/view.js +137 -0
- package/dist/stream/effect.d.ts +29 -0
- package/dist/stream/effect.js +77 -0
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.js +2 -0
- package/dist/stream/stream.d.ts +9 -0
- package/dist/stream/stream.js +2 -0
- package/dist/voice/effect.d.ts +7 -0
- package/dist/voice/effect.js +71 -0
- package/dist/voice/index.d.ts +4 -0
- package/dist/voice/index.js +3 -0
- package/dist/voice/managed-turn.d.ts +9 -0
- package/dist/voice/managed-turn.js +4 -0
- package/dist/voice/orchestrator-contract.d.ts +5 -0
- package/dist/voice/orchestrator-contract.js +4 -0
- package/dist/voice/orchestrator.d.ts +25 -0
- package/dist/voice/orchestrator.js +169 -0
- package/dist/voice/pi-relay-contract.d.ts +4 -0
- package/dist/voice/pi-relay-contract.js +2 -0
- package/dist/voice/pi-relay.d.ts +12 -0
- package/dist/voice/pi-relay.js +9 -0
- package/dist/voice/wire-schema.d.ts +215 -0
- package/dist/voice/wire-schema.js +16 -0
- package/package.json +84 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { MAX_NODE_API_OBSERVATION_FRAME_BYTES, NODE_API_OBSERVATION_PATH, NODE_API_WEBSOCKET_CLOSE_CODES, NODE_API_WEBSOCKET_PROTOCOL, nodeApiEndpointSchema, nodeApiObservationFrameSchema, nodeApiObservationSubscribeSchema, sessionAttachFrameSchema, sessionAttachSubscribeSchema, } from "@maiaos/protocol";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Queue from "effect/Queue";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Stream from "effect/Stream";
|
|
6
|
+
import { createLocalNodeClient, } from "../client/index.js";
|
|
7
|
+
import { MaiaClientError } from "../request/index.js";
|
|
8
|
+
import { makeNodeApiHttpRequest, resolveCredential, toClientError, } from "./http.js";
|
|
9
|
+
const MAX_OBSERVATION_BUFFERED_FRAMES = 256;
|
|
10
|
+
export const createNodeApiTransport = (options) => {
|
|
11
|
+
const request = makeNodeApiHttpRequest(options);
|
|
12
|
+
return {
|
|
13
|
+
request: (envelope, requestOptions) => {
|
|
14
|
+
const signal = requestOptions?.signal;
|
|
15
|
+
return Effect.runPromise(request(envelope, requestOptions), signal === undefined ? undefined : { signal }).catch((error) => {
|
|
16
|
+
throw toClientError(error, signal);
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const createNodeApiClient = (options) => createLocalNodeClient(createNodeApiTransport(options));
|
|
22
|
+
const decodeJsonFrame = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
|
|
23
|
+
const defaultWebSocketFactory = (url, protocols) => {
|
|
24
|
+
const webSocketConstructor = globalThis.WebSocket;
|
|
25
|
+
if (webSocketConstructor === undefined) {
|
|
26
|
+
throw new TypeError("No WebSocket implementation is available.");
|
|
27
|
+
}
|
|
28
|
+
return new webSocketConstructor(url, [...protocols]);
|
|
29
|
+
};
|
|
30
|
+
const webSocketUrl = (endpoint) => `${endpoint.origin.replace(/^http:/u, "ws:")}${NODE_API_OBSERVATION_PATH}`;
|
|
31
|
+
const observationError = (message, cause) => new MaiaClientError("transport_failure", message, { cause });
|
|
32
|
+
const observationCloseError = (close) => {
|
|
33
|
+
if (close.code === NODE_API_WEBSOCKET_CLOSE_CODES.authenticationFailed) {
|
|
34
|
+
return observationError("The Maia Node API observation authentication failed.");
|
|
35
|
+
}
|
|
36
|
+
if (close.code === NODE_API_WEBSOCKET_CLOSE_CODES.saturated) {
|
|
37
|
+
return new MaiaClientError("saturated", "The Maia Node API observation consumer was saturated.");
|
|
38
|
+
}
|
|
39
|
+
if (close.code === NODE_API_WEBSOCKET_CLOSE_CODES.serverShutdown) {
|
|
40
|
+
return observationError("The Maia Node API observation server stopped.");
|
|
41
|
+
}
|
|
42
|
+
if (close.code === NODE_API_WEBSOCKET_CLOSE_CODES.cursorResetRequired ||
|
|
43
|
+
close.code === NODE_API_WEBSOCKET_CLOSE_CODES.policyRevoked) {
|
|
44
|
+
return new MaiaClientError("invalid_response", "The Maia Node API observation requires a fresh snapshot.");
|
|
45
|
+
}
|
|
46
|
+
return observationError("The Maia Node API observation connection closed unexpectedly.", close);
|
|
47
|
+
};
|
|
48
|
+
const failSaturatedQueue = (queue, socket) => Queue.fail(queue, observationError("The Maia Node API observation buffer is saturated.")).pipe(Effect.tap(() => Effect.sync(() => {
|
|
49
|
+
socket.close(4429);
|
|
50
|
+
})));
|
|
51
|
+
const handleOfferedFrame = (accepted, offered) => {
|
|
52
|
+
if (!accepted)
|
|
53
|
+
return failSaturatedQueue(offered.queue, offered.socket);
|
|
54
|
+
return offered.frame.terminal ? Queue.end(offered.queue) : Effect.void;
|
|
55
|
+
};
|
|
56
|
+
const offerFrame = (queue, frame, socket) => {
|
|
57
|
+
Effect.runFork(Queue.offer(queue, frame).pipe(Effect.flatMap((accepted) => handleOfferedFrame(accepted, { frame, queue, socket }))));
|
|
58
|
+
};
|
|
59
|
+
const parseObservationEndpoint = (options) => Effect.try({
|
|
60
|
+
catch: (error) => observationError("The Maia Node API observation endpoint is invalid.", error),
|
|
61
|
+
try: () => nodeApiEndpointSchema.parse(options.endpoint),
|
|
62
|
+
});
|
|
63
|
+
const authenticateSubscribe = Effect.fn("NodeApiObservation.authenticate")(function* (options, contract) {
|
|
64
|
+
const token = yield* resolveCredential(options.credential).pipe(Effect.mapError((error) => observationError("The Maia Node API observation credential is unavailable.", error)));
|
|
65
|
+
return yield* Effect.try({
|
|
66
|
+
catch: (error) => observationError("The Maia Node API observation request is invalid.", error),
|
|
67
|
+
try: () => contract.subscribe(token),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
const openObservationSocket = Effect.fn("NodeApiObservation.open")(function* (options) {
|
|
71
|
+
const endpoint = yield* parseObservationEndpoint(options);
|
|
72
|
+
return yield* Effect.try({
|
|
73
|
+
catch: (error) => observationError("The Maia Node API observation connection could not be opened.", error),
|
|
74
|
+
try: () => (options.webSocketFactory ?? defaultWebSocketFactory)(webSocketUrl(endpoint), [NODE_API_WEBSOCKET_PROTOCOL]),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const decodeObservationFrame = (event, correlationId, decode) => {
|
|
78
|
+
if (typeof event.data !== "string") {
|
|
79
|
+
throw new TypeError("Observation frames must be text.");
|
|
80
|
+
}
|
|
81
|
+
if (new TextEncoder().encode(event.data).byteLength >
|
|
82
|
+
MAX_NODE_API_OBSERVATION_FRAME_BYTES) {
|
|
83
|
+
throw new TypeError("Observation frame exceeds its resource limit.");
|
|
84
|
+
}
|
|
85
|
+
const frame = decode(decodeJsonFrame(event.data));
|
|
86
|
+
if (frame.correlationId !== correlationId) {
|
|
87
|
+
throw new TypeError("Observation correlation does not match.");
|
|
88
|
+
}
|
|
89
|
+
return frame;
|
|
90
|
+
};
|
|
91
|
+
class ObservationSocketBridge {
|
|
92
|
+
closingWithFailure = false;
|
|
93
|
+
decode;
|
|
94
|
+
queue;
|
|
95
|
+
signal;
|
|
96
|
+
socket;
|
|
97
|
+
subscribe;
|
|
98
|
+
terminalReceived = false;
|
|
99
|
+
onAbort = () => {
|
|
100
|
+
this.closingWithFailure = true;
|
|
101
|
+
Effect.runFork(Queue.fail(this.queue, new MaiaClientError("cancelled", "The Maia Node API observation was cancelled.")));
|
|
102
|
+
this.socket.close(1000, "client_closed");
|
|
103
|
+
};
|
|
104
|
+
onClose = (event) => {
|
|
105
|
+
const close = event;
|
|
106
|
+
if (this.terminalReceived || close.code === 1000) {
|
|
107
|
+
if (!this.closingWithFailure)
|
|
108
|
+
Effect.runFork(Queue.end(this.queue));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.closingWithFailure = true;
|
|
112
|
+
Effect.runFork(Queue.fail(this.queue, observationCloseError(close)));
|
|
113
|
+
};
|
|
114
|
+
onError = (event) => {
|
|
115
|
+
this.closingWithFailure = true;
|
|
116
|
+
Effect.runFork(Queue.fail(this.queue, observationError("The Maia Node API observation transport failed.", event)));
|
|
117
|
+
};
|
|
118
|
+
onMessage = (event) => {
|
|
119
|
+
try {
|
|
120
|
+
const frame = decodeObservationFrame(event, this.subscribe.messageId, this.decode);
|
|
121
|
+
this.terminalReceived = frame.terminal;
|
|
122
|
+
offerFrame(this.queue, frame, this.socket);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
this.failInvalidFrame(error);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
onOpen = () => {
|
|
129
|
+
this.socket.send(JSON.stringify(this.subscribe));
|
|
130
|
+
};
|
|
131
|
+
constructor(input) {
|
|
132
|
+
this.decode = input.decode;
|
|
133
|
+
this.queue = input.queue;
|
|
134
|
+
this.signal = input.signal;
|
|
135
|
+
this.socket = input.socket;
|
|
136
|
+
this.subscribe = input.subscribe;
|
|
137
|
+
}
|
|
138
|
+
install() {
|
|
139
|
+
this.socket.addEventListener("close", this.onClose);
|
|
140
|
+
this.socket.addEventListener("error", this.onError);
|
|
141
|
+
this.socket.addEventListener("message", this.onMessage);
|
|
142
|
+
this.socket.addEventListener("open", this.onOpen);
|
|
143
|
+
this.signal?.addEventListener("abort", this.onAbort, { once: true });
|
|
144
|
+
if (this.signal?.aborted === true)
|
|
145
|
+
this.onAbort();
|
|
146
|
+
else if (this.socket.readyState === 1)
|
|
147
|
+
this.onOpen();
|
|
148
|
+
}
|
|
149
|
+
uninstall() {
|
|
150
|
+
this.socket.removeEventListener("close", this.onClose);
|
|
151
|
+
this.socket.removeEventListener("error", this.onError);
|
|
152
|
+
this.socket.removeEventListener("message", this.onMessage);
|
|
153
|
+
this.socket.removeEventListener("open", this.onOpen);
|
|
154
|
+
this.signal?.removeEventListener("abort", this.onAbort);
|
|
155
|
+
}
|
|
156
|
+
failInvalidFrame(error) {
|
|
157
|
+
this.closingWithFailure = true;
|
|
158
|
+
Effect.runFork(Queue.fail(this.queue, observationError("The Maia Node API observation frame is invalid.", error)).pipe(Effect.tap(() => Effect.sync(() => {
|
|
159
|
+
this.socket.close(4400);
|
|
160
|
+
}))));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const makeObservationQueue = () => Queue.make({
|
|
164
|
+
capacity: MAX_OBSERVATION_BUFFERED_FRAMES,
|
|
165
|
+
strategy: "dropping",
|
|
166
|
+
});
|
|
167
|
+
const acquireObservationSocket = (options) => Effect.acquireRelease(openObservationSocket(options), (socket) => Effect.sync(() => {
|
|
168
|
+
socket.close(1000, "client_closed");
|
|
169
|
+
}));
|
|
170
|
+
const installObservationBridge = (bridge) => Effect.acquireRelease(Effect.sync(() => {
|
|
171
|
+
bridge.install();
|
|
172
|
+
}), () => Effect.sync(() => {
|
|
173
|
+
bridge.uninstall();
|
|
174
|
+
}));
|
|
175
|
+
const ensureObservationActive = (signal) => signal?.aborted === true
|
|
176
|
+
? Effect.fail(new MaiaClientError("cancelled", "The Maia Node API observation was cancelled."))
|
|
177
|
+
: Effect.void;
|
|
178
|
+
const buildObservationStream = Effect.fn("NodeApiObservation.stream")(function* (options, contract) {
|
|
179
|
+
yield* ensureObservationActive(options.signal);
|
|
180
|
+
const [subscribe, queue, socket] = yield* Effect.all([
|
|
181
|
+
authenticateSubscribe(options, contract),
|
|
182
|
+
makeObservationQueue(),
|
|
183
|
+
acquireObservationSocket(options),
|
|
184
|
+
]);
|
|
185
|
+
const bridge = new ObservationSocketBridge({
|
|
186
|
+
decode: contract.decode,
|
|
187
|
+
queue,
|
|
188
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
189
|
+
socket,
|
|
190
|
+
subscribe,
|
|
191
|
+
});
|
|
192
|
+
yield* installObservationBridge(bridge);
|
|
193
|
+
return Stream.fromQueue(queue);
|
|
194
|
+
});
|
|
195
|
+
const makeObservationStream = (options) => Stream.unwrap(buildObservationStream(options, {
|
|
196
|
+
decode: (value) => nodeApiObservationFrameSchema.parse(value),
|
|
197
|
+
subscribe: (token) => nodeApiObservationSubscribeSchema.parse({
|
|
198
|
+
...options.subscribe,
|
|
199
|
+
authentication: { scheme: "maia.node.bearer/v1", token },
|
|
200
|
+
}),
|
|
201
|
+
}));
|
|
202
|
+
export const subscribeNodeApiObservations = (options) => Stream.toAsyncIterable(makeObservationStream(options));
|
|
203
|
+
export const makeSessionAttachStream = (options) => Stream.unwrap(buildObservationStream(options, {
|
|
204
|
+
decode: (value) => sessionAttachFrameSchema.parse(value),
|
|
205
|
+
subscribe: (token) => sessionAttachSubscribeSchema.parse({
|
|
206
|
+
...options.request,
|
|
207
|
+
authentication: { scheme: "maia.node.bearer/v1", token },
|
|
208
|
+
}),
|
|
209
|
+
}));
|
|
210
|
+
export const attachSession = (options) => Stream.toAsyncIterable(makeSessionAttachStream(options));
|
|
211
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import type { MaiaClientError } from "../request/index.js";
|
|
4
|
+
import type { StreamRelay } from "../stream/index.js";
|
|
5
|
+
import { type NodeChange, type NodeChangesSubscribe } from "./node-changes.js";
|
|
6
|
+
export declare const nodeChangesSubscribe: (instanceId: string, messageId: string, afterCursor: string | undefined) => NodeChangesSubscribe;
|
|
7
|
+
export declare const watchNodeChangesStream: (relay: StreamRelay<NodeChangesSubscribe>, options: {
|
|
8
|
+
readonly instanceId: string;
|
|
9
|
+
readonly nextId: (prefix: "request") => Effect.Effect<string>;
|
|
10
|
+
}) => Stream.Stream<NodeChange, MaiaClientError>;
|
|
11
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MAIA_PROTOCOL_VERSION, MAX_NODE_API_OBSERVATION_BATCH_RECORDS, MAX_NODE_API_OBSERVATION_FRAME_BYTES, NODE_API_SCHEMA_VERSION, nodeApiObservationFrameSchema, } from "@maiaos/protocol";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
import { RESNAPSHOT, resumeStream } from "../stream/effect.js";
|
|
6
|
+
import { reduceNodeChanges, } from "./node-changes.js";
|
|
7
|
+
const utf8 = new TextEncoder();
|
|
8
|
+
const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
9
|
+
export const nodeChangesSubscribe = (instanceId, messageId, afterCursor) => ({
|
|
10
|
+
kind: "subscribe",
|
|
11
|
+
messageId,
|
|
12
|
+
operationId: "observe.events",
|
|
13
|
+
parameters: {
|
|
14
|
+
...(afterCursor === undefined ? {} : { afterCursor }),
|
|
15
|
+
maxBatchRecords: MAX_NODE_API_OBSERVATION_BATCH_RECORDS,
|
|
16
|
+
scopes: [{ instanceId, kind: "node" }],
|
|
17
|
+
},
|
|
18
|
+
protocolVersion: MAIA_PROTOCOL_VERSION,
|
|
19
|
+
schemaVersion: NODE_API_SCHEMA_VERSION,
|
|
20
|
+
});
|
|
21
|
+
const decodeFrame = (text, messageId) => {
|
|
22
|
+
if (utf8.encode(text).byteLength > MAX_NODE_API_OBSERVATION_FRAME_BYTES)
|
|
23
|
+
return Option.none();
|
|
24
|
+
return Option.flatMap(decodeJson(text), (json) => {
|
|
25
|
+
const frame = nodeApiObservationFrameSchema.safeParse(json);
|
|
26
|
+
return frame.success && frame.data.correlationId === messageId
|
|
27
|
+
? Option.some(frame.data)
|
|
28
|
+
: Option.none();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const REVOKED = new Set([
|
|
32
|
+
"policy_revoked",
|
|
33
|
+
"principal_changed",
|
|
34
|
+
]);
|
|
35
|
+
const step = (frame) => {
|
|
36
|
+
if (frame.kind === "reset" && REVOKED.has(frame.data.reason))
|
|
37
|
+
return {
|
|
38
|
+
error: {
|
|
39
|
+
code: frame.data.reason,
|
|
40
|
+
message: "The Maia Node observation access changed.",
|
|
41
|
+
retryable: false,
|
|
42
|
+
},
|
|
43
|
+
kind: "error",
|
|
44
|
+
};
|
|
45
|
+
if (frame.kind === "gap" || frame.kind === "reset")
|
|
46
|
+
return { kind: "resnapshot" };
|
|
47
|
+
if (frame.kind === "error")
|
|
48
|
+
return { error: frame.data.error, kind: "error" };
|
|
49
|
+
return { cursor: frame.checkpoint.cursor, kind: "frame" };
|
|
50
|
+
};
|
|
51
|
+
export const watchNodeChangesStream = (relay, options) => resumeStream({
|
|
52
|
+
decode: decodeFrame,
|
|
53
|
+
nextId: options.nextId,
|
|
54
|
+
relay,
|
|
55
|
+
step,
|
|
56
|
+
subscribe: (messageId, cursor) => nodeChangesSubscribe(options.instanceId, messageId, cursor),
|
|
57
|
+
terminal: (frame) => frame.terminal,
|
|
58
|
+
}).pipe(Stream.map((frame) => frame.kind === RESNAPSHOT.kind
|
|
59
|
+
? [{ kind: "resync" }]
|
|
60
|
+
: Option.toArray(Option.fromNullishOr(reduceNodeChanges(frame)))), Stream.flattenIterable);
|
|
61
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { NodeApiObservationFrame, NodeApiObservationSubscribe } from "@maiaos/protocol";
|
|
2
|
+
import type { StreamRelay } from "../stream/index.js";
|
|
3
|
+
export type ChangedAggregate = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly revision: string;
|
|
6
|
+
readonly type: string;
|
|
7
|
+
};
|
|
8
|
+
export type NodeChange = {
|
|
9
|
+
readonly aggregateTypes: readonly string[];
|
|
10
|
+
readonly changed?: readonly ChangedAggregate[];
|
|
11
|
+
readonly kind: "records";
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "resync";
|
|
14
|
+
};
|
|
15
|
+
export type NodeChangesSubscribe = Omit<NodeApiObservationSubscribe, "authentication">;
|
|
16
|
+
export declare const reduceNodeChanges: (frame: NodeApiObservationFrame) => NodeChange | undefined;
|
|
17
|
+
export declare const watchNodeChanges: (relay: StreamRelay<NodeChangesSubscribe>, options: {
|
|
18
|
+
readonly instanceId: string;
|
|
19
|
+
readonly newId: (prefix: "request") => string;
|
|
20
|
+
}) => AsyncIterable<NodeChange>;
|
|
21
|
+
//# sourceMappingURL=node-changes.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import { watchNodeChangesStream } from "./effect.js";
|
|
4
|
+
export const reduceNodeChanges = (frame) => {
|
|
5
|
+
if (frame.kind === "event")
|
|
6
|
+
return {
|
|
7
|
+
aggregateTypes: frame.data.records.map((record) => record.aggregateType),
|
|
8
|
+
changed: frame.data.records.map((record) => ({
|
|
9
|
+
id: record.aggregateId,
|
|
10
|
+
revision: record.aggregateRevision,
|
|
11
|
+
type: record.aggregateType,
|
|
12
|
+
})),
|
|
13
|
+
kind: "records",
|
|
14
|
+
};
|
|
15
|
+
if (frame.kind === "snapshot")
|
|
16
|
+
return { kind: "resync" };
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
export const watchNodeChanges = (relay, options) => Stream.toAsyncIterable(watchNodeChangesStream(relay, {
|
|
20
|
+
instanceId: options.instanceId,
|
|
21
|
+
nextId: (prefix) => Effect.sync(() => options.newId(prefix)),
|
|
22
|
+
}));
|
|
23
|
+
//# sourceMappingURL=node-changes.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type EffectClient, type LocalNodeEffectRequester } from "../request/effect.js";
|
|
2
|
+
import { MaiaClientError } from "../request/index.js";
|
|
3
|
+
import type { PortLeaseClient } from "./port-lease.js";
|
|
4
|
+
export declare const makePortLeaseOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<PortLeaseClient, MaiaClientError | TError>;
|
|
5
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { portLeaseAcquireResultSchema, portLeaseListResultSchema, portLeaseReleaseResultSchema, portLeaseRenewResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { verifiedMutation, } from "../request/effect.js";
|
|
3
|
+
import { MaiaClientError } from "../request/index.js";
|
|
4
|
+
const requireMatch = (matches) => {
|
|
5
|
+
if (!matches)
|
|
6
|
+
throw new MaiaClientError("invalid_response", "The port lease response did not match the request.");
|
|
7
|
+
};
|
|
8
|
+
const ownerMatches = (owner, sessionId) => sessionId === undefined
|
|
9
|
+
? owner.kind === "principal"
|
|
10
|
+
: owner.kind === "session" && owner.sessionId === sessionId;
|
|
11
|
+
const parseAcquire = (value, input) => {
|
|
12
|
+
const result = portLeaseAcquireResultSchema.parse(value);
|
|
13
|
+
requireMatch(result.commandId === input.commandId &&
|
|
14
|
+
result.lease.purpose === input.purpose &&
|
|
15
|
+
result.lease.ports.length === (input.count ?? 1) &&
|
|
16
|
+
ownerMatches(result.lease.owner, input.sessionId));
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
const parseRenew = (value, input) => {
|
|
20
|
+
const result = portLeaseRenewResultSchema.parse(value);
|
|
21
|
+
requireMatch(result.commandId === input.commandId &&
|
|
22
|
+
result.lease.leaseId === input.leaseId &&
|
|
23
|
+
result.expectedRevision === input.expectedRevision);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
const parseRelease = (value, input) => {
|
|
27
|
+
const result = portLeaseReleaseResultSchema.parse(value);
|
|
28
|
+
requireMatch(result.commandId === input.commandId &&
|
|
29
|
+
result.lease.leaseId === input.leaseId);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
const parseList = (value, input) => {
|
|
33
|
+
const result = portLeaseListResultSchema.parse(value);
|
|
34
|
+
const { afterCursor, limit, sessionId } = input;
|
|
35
|
+
requireMatch(result.items.length <= limit &&
|
|
36
|
+
(result.nextCursor === undefined || result.nextCursor !== afterCursor) &&
|
|
37
|
+
(sessionId === undefined ||
|
|
38
|
+
result.items.every((item) => ownerMatches(item.lease.owner, sessionId))));
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
const makePortLeaseMutations = (request) => ({
|
|
42
|
+
acquirePortLease: (parameters, options) => request({ method: "port.lease.acquire", parameters }, { parse: (value) => parseAcquire(value, parameters) }, options),
|
|
43
|
+
releasePortLease: (parameters, options) => request({ method: "port.lease.release", parameters }, { parse: (value) => parseRelease(value, parameters) }, options),
|
|
44
|
+
renewPortLease: (parameters, options) => request({ method: "port.lease.renew", parameters }, { parse: (value) => parseRenew(value, parameters) }, options),
|
|
45
|
+
});
|
|
46
|
+
export const makePortLeaseOperations = (request) => {
|
|
47
|
+
const verified = (payload, output, options) => verifiedMutation(request(payload, output, options), options);
|
|
48
|
+
return {
|
|
49
|
+
...makePortLeaseMutations(verified),
|
|
50
|
+
listPortLeases: (parameters, options) => request({ method: "port.lease.list", parameters }, { parse: (value) => parseList(value, parameters) }, options),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { makePortLeaseClient, MAX_PORT_LEASE_COUNT, MAX_PORT_LEASE_PAGE_SIZE, PORT_LEASE_ERROR_CODES, PORT_LEASE_SCHEMA_VERSION, type PortLease, type PortLeaseAcquireParameters, portLeaseAcquireParametersSchema, type PortLeaseAcquireResult, portLeaseAcquireResultSchema, type PortLeaseClient, type PortLeaseErrorCode, type PortLeaseListParameters, portLeaseListParametersSchema, type PortLeaseListResult, portLeaseListResultSchema, type PortLeaseOwner, type PortLeaseReleaseParameters, portLeaseReleaseParametersSchema, type PortLeaseReleaseResult, portLeaseReleaseResultSchema, type PortLeaseRenewParameters, portLeaseRenewParametersSchema, type PortLeaseRenewResult, portLeaseRenewResultSchema, portLeaseSchema, } from "./port-lease.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { makePortLeaseClient, MAX_PORT_LEASE_COUNT, MAX_PORT_LEASE_PAGE_SIZE, PORT_LEASE_ERROR_CODES, PORT_LEASE_SCHEMA_VERSION, portLeaseAcquireParametersSchema, portLeaseAcquireResultSchema, portLeaseListParametersSchema, portLeaseListResultSchema, portLeaseReleaseParametersSchema, portLeaseReleaseResultSchema, portLeaseRenewParametersSchema, portLeaseRenewResultSchema, portLeaseSchema, } from "./port-lease.js";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PortLeaseAcquireParameters, PortLeaseAcquireResult, PortLeaseListParameters, PortLeaseListResult, PortLeaseReleaseParameters, PortLeaseReleaseResult, PortLeaseRenewParameters, PortLeaseRenewResult } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeRequester, LocalNodeRequestOptions } from "../request/index.js";
|
|
3
|
+
export type PortLeaseClient = {
|
|
4
|
+
readonly acquirePortLease: (parameters: PortLeaseAcquireParameters, options: LocalNodeRequestOptions) => Promise<PortLeaseAcquireResult>;
|
|
5
|
+
readonly listPortLeases: (parameters: PortLeaseListParameters, options: LocalNodeRequestOptions) => Promise<PortLeaseListResult>;
|
|
6
|
+
readonly releasePortLease: (parameters: PortLeaseReleaseParameters, options: LocalNodeRequestOptions) => Promise<PortLeaseReleaseResult>;
|
|
7
|
+
readonly renewPortLease: (parameters: PortLeaseRenewParameters, options: LocalNodeRequestOptions) => Promise<PortLeaseRenewResult>;
|
|
8
|
+
};
|
|
9
|
+
export declare const makePortLeaseClient: (request: LocalNodeRequester) => PortLeaseClient;
|
|
10
|
+
export { MAX_PORT_LEASE_COUNT, MAX_PORT_LEASE_PAGE_SIZE, PORT_LEASE_ERROR_CODES, PORT_LEASE_SCHEMA_VERSION, type PortLease, type PortLeaseAcquireParameters, portLeaseAcquireParametersSchema, type PortLeaseAcquireResult, portLeaseAcquireResultSchema, type PortLeaseErrorCode, type PortLeaseListParameters, portLeaseListParametersSchema, type PortLeaseListResult, portLeaseListResultSchema, type PortLeaseOwner, type PortLeaseReleaseParameters, portLeaseReleaseParametersSchema, type PortLeaseReleaseResult, portLeaseReleaseResultSchema, type PortLeaseRenewParameters, portLeaseRenewParametersSchema, type PortLeaseRenewResult, portLeaseRenewResultSchema, portLeaseSchema, } from "@maiaos/protocol";
|
|
11
|
+
//# sourceMappingURL=port-lease.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { fromPromiseRequester, toPromiseClient } from "../request/effect.js";
|
|
2
|
+
import { makePortLeaseOperations } from "./effect.js";
|
|
3
|
+
export const makePortLeaseClient = (request) => toPromiseClient(makePortLeaseOperations(fromPromiseRequester(request)));
|
|
4
|
+
export { MAX_PORT_LEASE_COUNT, MAX_PORT_LEASE_PAGE_SIZE, PORT_LEASE_ERROR_CODES, PORT_LEASE_SCHEMA_VERSION, portLeaseAcquireParametersSchema, portLeaseAcquireResultSchema, portLeaseListParametersSchema, portLeaseListResultSchema, portLeaseReleaseParametersSchema, portLeaseReleaseResultSchema, portLeaseRenewParametersSchema, portLeaseRenewResultSchema, portLeaseSchema, } from "@maiaos/protocol";
|
|
5
|
+
//# sourceMappingURL=port-lease.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PresentationCatalogParameters, PresentationCatalogResult, PresentationDirectoryParameters, PresentationDirectoryResult, PresentationProjectListParameters, PresentationProjectListResult, PresentationSessionListParameters, PresentationSessionListResult } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeRequester, LocalNodeRequestOptions } from "../request/index.js";
|
|
3
|
+
export type PresentationClient = {
|
|
4
|
+
readonly showPresentationCatalog: (parameters: PresentationCatalogParameters, options: LocalNodeRequestOptions) => Promise<PresentationCatalogResult>;
|
|
5
|
+
readonly showProjectList: (parameters: PresentationProjectListParameters, options: LocalNodeRequestOptions) => Promise<PresentationProjectListResult>;
|
|
6
|
+
readonly showSessionList: (parameters: PresentationSessionListParameters, options: LocalNodeRequestOptions) => Promise<PresentationSessionListResult>;
|
|
7
|
+
readonly showWorkspaceDirectory: (parameters: PresentationDirectoryParameters, options: LocalNodeRequestOptions) => Promise<PresentationDirectoryResult>;
|
|
8
|
+
};
|
|
9
|
+
export declare const makePresentationClient: (request: LocalNodeRequester) => PresentationClient;
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { fromPromiseRequester, toPromiseClient } from "../request/effect.js";
|
|
2
|
+
import { makePresentationOperations } from "./effect.js";
|
|
3
|
+
export const makePresentationClient = (request) => toPromiseClient(makePresentationOperations(fromPromiseRequester(request)));
|
|
4
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EffectClient, LocalNodeEffectRequester } from "../request/effect.js";
|
|
2
|
+
import { MaiaClientError } from "../request/index.js";
|
|
3
|
+
import type { PresentationClient } from "./client.js";
|
|
4
|
+
export declare const makePresentationOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<PresentationClient, MaiaClientError | TError>;
|
|
5
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { presentationCatalogResultSchema, presentationDirectoryParametersSchema, presentationDirectoryResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { MaiaClientError } from "../request/index.js";
|
|
4
|
+
import { requestProjectList } from "./project-list.js";
|
|
5
|
+
import { requestSessionList } from "./session-list.js";
|
|
6
|
+
const parseDirectory = (value, parameters) => {
|
|
7
|
+
const result = presentationDirectoryResultSchema.parse(value);
|
|
8
|
+
if (result.catalogDigest !== parameters.catalogDigest ||
|
|
9
|
+
result.catalogVersion !== parameters.catalogVersion ||
|
|
10
|
+
result.viewId !== parameters.viewId ||
|
|
11
|
+
result.generation !== parameters.generation ||
|
|
12
|
+
result.resources.items.length > parameters.page.limit)
|
|
13
|
+
throw new MaiaClientError("invalid_response", "The presentation response did not match the requested view.");
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const requestDirectory = (request, input, options) => Effect.gen(function* () {
|
|
17
|
+
const parameters = yield* Effect.try({
|
|
18
|
+
catch: () => new MaiaClientError("invalid_request", "The presentation request failed runtime validation."),
|
|
19
|
+
try: () => presentationDirectoryParametersSchema.parse(input),
|
|
20
|
+
});
|
|
21
|
+
const expected = { ...parameters, page: { ...parameters.page } };
|
|
22
|
+
return yield* request({ method: "presentation.workspace-directory.show", parameters }, { parse: (value) => parseDirectory(value, expected) }, options);
|
|
23
|
+
}).pipe(Effect.withSpan("PresentationClient.requestDirectory"));
|
|
24
|
+
export const makePresentationOperations = (request) => ({
|
|
25
|
+
showPresentationCatalog: (parameters, options) => request({ method: "presentation.catalog.show", parameters }, presentationCatalogResultSchema, options),
|
|
26
|
+
showProjectList: (parameters, options) => requestProjectList(request, parameters, options),
|
|
27
|
+
showSessionList: (parameters, options) => requestSessionList(request, parameters, options),
|
|
28
|
+
showWorkspaceDirectory: (parameters, options) => requestDirectory(request, parameters, options),
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { PresentationClient } from "./client.js";
|
|
2
|
+
export { makePresentationClient } from "./client.js";
|
|
3
|
+
export type { PresentationCatalogParameters, PresentationCatalogResult, PresentationDirectoryParameters, PresentationDirectoryResult, PresentationProjectListParameters, PresentationProjectListResult, PresentationProjectSpec, PresentationSessionListParameters, PresentationSessionListResult, PresentationSessionSpec, PresentationSpec, } from "@maiaos/protocol";
|
|
4
|
+
export { PRESENTATION_CATALOG_DIGEST, PRESENTATION_CATALOG_VERSION, presentationCatalogParametersSchema, presentationCatalogResultSchema, presentationDirectoryParametersSchema, presentationDirectoryResultSchema, presentationProjectListParametersSchema, presentationProjectListResultSchema, presentationProjectSpecSchema, presentationSessionListParametersSchema, presentationSessionListResultSchema, presentationSessionSpecSchema, presentationSpecSchema, } from "@maiaos/protocol";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { makePresentationClient } from "./client.js";
|
|
2
|
+
export { PRESENTATION_CATALOG_DIGEST, PRESENTATION_CATALOG_VERSION, presentationCatalogParametersSchema, presentationCatalogResultSchema, presentationDirectoryParametersSchema, presentationDirectoryResultSchema, presentationProjectListParametersSchema, presentationProjectListResultSchema, presentationProjectSpecSchema, presentationSessionListParametersSchema, presentationSessionListResultSchema, presentationSessionSpecSchema, presentationSpecSchema, } from "@maiaos/protocol";
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PresentationProjectListParameters, type PresentationProjectListResult } from "@maiaos/protocol";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import type { LocalNodeEffectRequester } from "../request/effect.js";
|
|
4
|
+
import type { LocalNodeRequestOptions } from "../request/index.js";
|
|
5
|
+
import { MaiaClientError } from "../request/index.js";
|
|
6
|
+
export declare const requestProjectList: <TError>(request: LocalNodeEffectRequester<TError>, input: PresentationProjectListParameters, options: LocalNodeRequestOptions) => Effect.Effect<PresentationProjectListResult, MaiaClientError | TError>;
|
|
7
|
+
//# sourceMappingURL=project-list.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { presentationProjectListParametersSchema, presentationProjectListResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { MaiaClientError } from "../request/index.js";
|
|
4
|
+
const parse = (value, expected) => {
|
|
5
|
+
const result = presentationProjectListResultSchema.parse(value);
|
|
6
|
+
if (result.catalogDigest !== expected.catalogDigest ||
|
|
7
|
+
result.catalogVersion !== expected.catalogVersion ||
|
|
8
|
+
result.viewId !== expected.viewId ||
|
|
9
|
+
result.generation !== expected.generation ||
|
|
10
|
+
result.resources.container.id !== expected.page.containerId ||
|
|
11
|
+
result.membershipCursor !== expected.page.afterCursor ||
|
|
12
|
+
result.resources.projects.length > expected.page.limit)
|
|
13
|
+
throw new MaiaClientError("invalid_response", "The Project presentation did not match the requested view.");
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
export const requestProjectList = (request, input, options) => Effect.gen(function* () {
|
|
17
|
+
const parameters = yield* Effect.try({
|
|
18
|
+
catch: () => new MaiaClientError("invalid_request", "The Project presentation request failed runtime validation."),
|
|
19
|
+
try: () => presentationProjectListParametersSchema.parse(input),
|
|
20
|
+
});
|
|
21
|
+
const expected = { ...parameters, page: { ...parameters.page } };
|
|
22
|
+
return yield* request({ method: "presentation.project-list.show", parameters }, { parse: (value) => parse(value, expected) }, options);
|
|
23
|
+
}).pipe(Effect.withSpan("PresentationClient.requestProjectList"));
|
|
24
|
+
//# sourceMappingURL=project-list.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PresentationSessionListParameters, type PresentationSessionListResult } from "@maiaos/protocol";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import type { LocalNodeEffectRequester } from "../request/effect.js";
|
|
4
|
+
import type { LocalNodeRequestOptions } from "../request/index.js";
|
|
5
|
+
import { MaiaClientError } from "../request/index.js";
|
|
6
|
+
export declare const requestSessionList: <TError>(request: LocalNodeEffectRequester<TError>, input: PresentationSessionListParameters, options: LocalNodeRequestOptions) => Effect.Effect<PresentationSessionListResult, MaiaClientError | TError>;
|
|
7
|
+
//# sourceMappingURL=session-list.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { presentationSessionListParametersSchema, presentationSessionListResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { MaiaClientError } from "../request/index.js";
|
|
4
|
+
const parse = (value, expected) => {
|
|
5
|
+
const result = presentationSessionListResultSchema.parse(value);
|
|
6
|
+
const target = result.target;
|
|
7
|
+
if (result.catalogDigest !== expected.catalogDigest ||
|
|
8
|
+
result.catalogVersion !== expected.catalogVersion ||
|
|
9
|
+
result.viewId !== expected.viewId ||
|
|
10
|
+
result.generation !== expected.generation ||
|
|
11
|
+
target.containerId !== expected.target.containerId ||
|
|
12
|
+
target.containerRevision !== expected.target.containerRevision ||
|
|
13
|
+
target.projectId !== expected.target.projectId ||
|
|
14
|
+
target.projectRevision !== expected.target.projectRevision ||
|
|
15
|
+
target.membershipCursor !== expected.target.membershipCursor ||
|
|
16
|
+
result.resources.items.length > expected.page.limit)
|
|
17
|
+
throw new MaiaClientError("invalid_response", "The Session presentation did not match the requested view.");
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
export const requestSessionList = (request, input, options) => Effect.gen(function* () {
|
|
21
|
+
const parameters = yield* Effect.try({
|
|
22
|
+
catch: () => new MaiaClientError("invalid_request", "The Session presentation request failed runtime validation."),
|
|
23
|
+
try: () => presentationSessionListParametersSchema.parse(input),
|
|
24
|
+
});
|
|
25
|
+
const expected = {
|
|
26
|
+
...parameters,
|
|
27
|
+
page: { ...parameters.page },
|
|
28
|
+
target: { ...parameters.target },
|
|
29
|
+
};
|
|
30
|
+
return yield* request({ method: "presentation.session-list.show", parameters }, { parse: (value) => parse(value, expected) }, options);
|
|
31
|
+
}).pipe(Effect.withSpan("PresentationClient.requestSessionList"));
|
|
32
|
+
//# sourceMappingURL=session-list.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type EffectClient, type LocalNodeEffectRequester } from "../request/effect.js";
|
|
2
|
+
import { MaiaClientError } from "../request/index.js";
|
|
3
|
+
import type { ProjectGuardClient } from "./project-guard.js";
|
|
4
|
+
export declare const makeProjectGuardOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<ProjectGuardClient, MaiaClientError | TError>;
|
|
5
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { projectGuardConfirmResultSchema, projectGuardPreviewResultSchema, projectGuardShowResultSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { verifiedMutation, } from "../request/effect.js";
|
|
3
|
+
import { MaiaClientError } from "../request/index.js";
|
|
4
|
+
const requireMatch = (matches) => {
|
|
5
|
+
if (!matches)
|
|
6
|
+
throw new MaiaClientError("invalid_response", "The Project guard response did not match the request.");
|
|
7
|
+
};
|
|
8
|
+
const sameLimits = (left, right) => left.maxDepth === right.maxDepth &&
|
|
9
|
+
left.maxLeasesPerSession === right.maxLeasesPerSession &&
|
|
10
|
+
left.maxLiveChildren === right.maxLiveChildren &&
|
|
11
|
+
left.maxMessagesPerMinute === right.maxMessagesPerMinute;
|
|
12
|
+
const parseShow = (value, input) => {
|
|
13
|
+
const result = projectGuardShowResultSchema.parse(value);
|
|
14
|
+
requireMatch(result.guard.projectId === input.projectId);
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const parsePreview = (value, input) => {
|
|
18
|
+
const result = projectGuardPreviewResultSchema.parse(value);
|
|
19
|
+
requireMatch(result.commandId === input.commandId &&
|
|
20
|
+
result.expectedRevision === input.expectedRevision &&
|
|
21
|
+
result.projectId === input.projectId &&
|
|
22
|
+
sameLimits(result.limits, input.limits));
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const parseConfirm = (value, input) => {
|
|
26
|
+
const result = projectGuardConfirmResultSchema.parse(value);
|
|
27
|
+
requireMatch(result.commandId === input.commandId &&
|
|
28
|
+
result.expectedRevision === input.expectedRevision &&
|
|
29
|
+
result.inputDigest === input.inputDigest &&
|
|
30
|
+
result.guard.projectId === input.projectId &&
|
|
31
|
+
sameLimits(result.guard.limits, input.limits));
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
export const makeProjectGuardOperations = (request) => ({
|
|
35
|
+
confirmProjectGuard: (parameters, options) => verifiedMutation(request({ method: "project.guard.confirm", parameters }, { parse: (value) => parseConfirm(value, parameters) }, options), options),
|
|
36
|
+
previewProjectGuard: (parameters, options) => request({ method: "project.guard.preview", parameters }, { parse: (value) => parsePreview(value, parameters) }, options),
|
|
37
|
+
showProjectGuard: (parameters, options) => request({ method: "project.guard.show", parameters }, { parse: (value) => parseShow(value, parameters) }, options),
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DEFAULT_SESSION_GUARD_LIMITS, makeProjectGuardClient, type ProjectGuard, type ProjectGuardClient, type ProjectGuardConfirmParameters, projectGuardConfirmParametersSchema, type ProjectGuardConfirmResult, projectGuardConfirmResultSchema, type ProjectGuardPreviewParameters, projectGuardPreviewParametersSchema, type ProjectGuardPreviewResult, projectGuardPreviewResultSchema, type ProjectGuardShowParameters, projectGuardShowParametersSchema, type ProjectGuardShowResult, projectGuardShowResultSchema, SESSION_GUARD_BOUNDS, SESSION_GUARD_ERROR_CODES, SESSION_ROLE_DENIED_ERROR_CODE, type SessionGuardLimits, type SessionRole, } from "./project-guard.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DEFAULT_SESSION_GUARD_LIMITS, makeProjectGuardClient, projectGuardConfirmParametersSchema, projectGuardConfirmResultSchema, projectGuardPreviewParametersSchema, projectGuardPreviewResultSchema, projectGuardShowParametersSchema, projectGuardShowResultSchema, SESSION_GUARD_BOUNDS, SESSION_GUARD_ERROR_CODES, SESSION_ROLE_DENIED_ERROR_CODE, } from "./project-guard.js";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|