@maiaos/sdk 0.1.0-canary.64 → 0.1.0-canary.65
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/README.md +98 -0
- package/dist/approval/effect.d.ts +2 -0
- package/dist/approval/effect.js +1 -1
- package/dist/board/board.d.ts +23 -0
- package/dist/board/board.js +2 -0
- package/dist/board/effect.d.ts +5 -0
- package/dist/board/effect.js +176 -0
- package/dist/board/index.d.ts +3 -0
- package/dist/board/index.js +2 -0
- package/dist/browser/effect.d.ts +9 -0
- package/dist/browser/effect.js +8 -0
- package/dist/browser/exchange.d.ts +14 -0
- package/dist/browser/exchange.js +49 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/observation.d.ts +9 -0
- package/dist/browser/observation.js +73 -0
- package/dist/browser/options.d.ts +19 -0
- package/dist/browser/options.js +2 -0
- package/dist/browser/paste.d.ts +5 -0
- package/dist/browser/paste.js +13 -0
- package/dist/browser/session.d.ts +32 -0
- package/dist/browser/session.js +79 -0
- package/dist/browser/sign-out.d.ts +5 -0
- package/dist/browser/sign-out.js +6 -0
- package/dist/browser/status.d.ts +9 -0
- package/dist/browser/status.js +22 -0
- package/dist/browser/transport.d.ts +4 -0
- package/dist/browser/transport.js +21 -0
- package/dist/call/call.d.ts +1 -1
- package/dist/call/call.js +28 -0
- package/dist/call/effect.js +26 -8
- package/dist/client/effect.js +47 -2
- package/dist/client/local-node-client.d.ts +24 -4
- package/dist/connection/effect.js +3 -0
- package/dist/discovery/discovery.d.ts +1 -1
- package/dist/discovery/discovery.js +1 -1
- package/dist/discovery/effect.js +11 -8
- package/dist/discovery/index.d.ts +1 -1
- package/dist/discovery/index.js +1 -1
- package/dist/executor/index.d.ts +2 -0
- package/dist/executor/index.js +2 -0
- package/dist/feature-bindings/feature-bindings.d.ts +7 -2
- package/dist/fleet-events/effect.d.ts +7 -0
- package/dist/fleet-events/effect.js +141 -0
- package/dist/fleet-events/fleet-events.d.ts +5 -0
- package/dist/fleet-events/fleet-events.js +7 -0
- package/dist/fleet-events/index.d.ts +3 -0
- package/dist/fleet-events/index.js +3 -0
- package/dist/fleet-events/item.d.ts +24 -0
- package/dist/fleet-events/item.js +16 -0
- package/dist/github/effect.d.ts +5 -0
- package/dist/github/effect.js +69 -0
- package/dist/github/github.d.ts +11 -0
- package/dist/github/github.js +2 -0
- package/dist/github/index.d.ts +3 -0
- package/dist/github/index.js +2 -0
- package/dist/goal/effect.d.ts +7 -0
- package/dist/goal/effect.js +65 -0
- package/dist/goal/goal.d.ts +11 -0
- package/dist/goal/goal.js +2 -0
- package/dist/goal/index.d.ts +3 -0
- package/dist/goal/index.js +2 -0
- package/dist/inbox/client.d.ts +4 -0
- package/dist/inbox/client.js +4 -0
- package/dist/inbox/effect.d.ts +5 -0
- package/dist/inbox/effect.js +70 -0
- package/dist/inbox/inbox.d.ts +11 -0
- package/dist/inbox/inbox.js +2 -0
- package/dist/inbox/index.d.ts +3 -0
- package/dist/inbox/index.js +3 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +17 -4
- package/dist/node/deadlines.js +6 -0
- package/dist/node/discovery.d.ts +27 -3
- package/dist/node/discovery.js +127 -85
- package/dist/node/effect.d.ts +4 -2
- package/dist/node/effect.js +4 -2
- package/dist/node/http.js +14 -6
- package/dist/node/local-node.d.ts +1 -0
- package/dist/node/session.d.ts +20 -1
- package/dist/node/session.js +85 -3
- package/dist/node/transport.d.ts +1 -1
- package/dist/node-changes/effect.d.ts +10 -0
- package/dist/node-changes/effect.js +12 -16
- package/dist/node-update/effect.d.ts +7 -0
- package/dist/node-update/effect.js +69 -0
- package/dist/node-update/index.d.ts +3 -0
- package/dist/node-update/index.js +2 -0
- package/dist/node-update/node-update.d.ts +16 -0
- package/dist/node-update/node-update.js +2 -0
- package/dist/pairing/effect.d.ts +5 -0
- package/dist/pairing/effect.js +40 -0
- package/dist/pairing/index.d.ts +3 -0
- package/dist/pairing/index.js +2 -0
- package/dist/pairing/pairing.d.ts +9 -0
- package/dist/pairing/pairing.js +2 -0
- package/dist/principal/effect.d.ts +5 -0
- package/dist/principal/effect.js +36 -0
- package/dist/principal/index.d.ts +3 -0
- package/dist/principal/index.js +2 -0
- package/dist/principal/principal.d.ts +8 -0
- package/dist/principal/principal.js +2 -0
- package/dist/project-knowledge/effect.d.ts +5 -0
- package/dist/project-knowledge/effect.js +95 -0
- package/dist/project-knowledge/index.d.ts +2 -0
- package/dist/project-knowledge/index.js +2 -0
- package/dist/project-knowledge/project-knowledge.d.ts +14 -0
- package/dist/project-knowledge/project-knowledge.js +2 -0
- package/dist/project-workspace/effect.js +32 -1
- package/dist/project-workspace/project-workspace.d.ts +4 -1
- package/dist/reach/effect.d.ts +5 -0
- package/dist/reach/effect.js +28 -0
- package/dist/reach/index.d.ts +3 -0
- package/dist/reach/index.js +2 -0
- package/dist/reach/reach.d.ts +8 -0
- package/dist/reach/reach.js +2 -0
- package/dist/request/classify.d.ts +3 -0
- package/dist/request/classify.js +3 -1
- package/dist/request/effect.d.ts +1 -0
- package/dist/request/effect.js +9 -1
- package/dist/request/resume-claim.d.ts +5 -0
- package/dist/request/resume-claim.js +22 -0
- package/dist/routine/effect.js +127 -1
- package/dist/routine/index.d.ts +1 -1
- package/dist/routine/index.js +1 -1
- package/dist/routine/routine.d.ts +11 -2
- package/dist/routine/routine.js +1 -1
- package/dist/secret/effect.d.ts +5 -0
- package/dist/secret/effect.js +30 -0
- package/dist/secret/index.d.ts +3 -0
- package/dist/secret/index.js +2 -0
- package/dist/secret/secret.d.ts +8 -0
- package/dist/secret/secret.js +2 -0
- package/dist/session-creation/effect.d.ts +1 -0
- package/dist/session-creation/effect.js +4 -2
- package/dist/session-supervision/effect.d.ts +59 -0
- package/dist/session-supervision/effect.js +316 -0
- package/dist/session-supervision/index.d.ts +2 -0
- package/dist/session-supervision/index.js +2 -0
- package/dist/session-supervision/session-supervision.d.ts +34 -0
- package/dist/session-supervision/session-supervision.js +5 -0
- package/dist/session-watch/effect.d.ts +12 -0
- package/dist/session-watch/effect.js +43 -0
- package/dist/session-watch/index.d.ts +2 -0
- package/dist/session-watch/index.js +2 -0
- package/dist/session-watch/item.d.ts +14 -0
- package/dist/session-watch/item.js +2 -0
- package/dist/shell/change-source.d.ts +5 -0
- package/dist/shell/change-source.js +15 -0
- package/dist/shell/effect.d.ts +3 -0
- package/dist/shell/effect.js +2 -0
- package/dist/shell/index.d.ts +5 -0
- package/dist/shell/index.js +5 -0
- package/dist/shell/lifecycle.d.ts +42 -0
- package/dist/shell/lifecycle.js +83 -0
- package/dist/shell/relay.d.ts +35 -0
- package/dist/shell/relay.js +37 -0
- package/dist/shell/transport.d.ts +16 -0
- package/dist/shell/transport.js +143 -0
- package/dist/shell/update.d.ts +27 -0
- package/dist/shell/update.js +38 -0
- package/dist/skills-sync/effect.d.ts +23 -0
- package/dist/skills-sync/effect.js +126 -0
- package/dist/skills-sync/fan-out.d.ts +42 -0
- package/dist/skills-sync/fan-out.js +2 -0
- package/dist/skills-sync/index.d.ts +4 -0
- package/dist/skills-sync/index.js +3 -0
- package/dist/skills-sync/skills-sync.d.ts +8 -0
- package/dist/skills-sync/skills-sync.js +2 -0
- package/dist/stream/effect.d.ts +11 -7
- package/dist/stream/effect.js +21 -2
- package/dist/voice/wire-schema.d.ts +1 -0
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.js +1 -1
- package/package.json +29 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VLLNT
|
|
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.
|
package/README.md
CHANGED
|
@@ -46,6 +46,104 @@ and an optional `deadlineAt`, a `bigint` on your own `Clock.monotonicTimeNanos`
|
|
|
46
46
|
for an in-process requester that bounds its waiting. The SDK's own requesters
|
|
47
47
|
ignore `deadlineAt`.
|
|
48
48
|
|
|
49
|
+
## Browser
|
|
50
|
+
|
|
51
|
+
`@maiaos/sdk/browser` is the transport of a page that a Node serves at
|
|
52
|
+
`/panel/`: it posts each request to the Node's panel operation path with the
|
|
53
|
+
browser's own cookie and the session value in the Node's panel header, and
|
|
54
|
+
tells the page when the Node ends the session. `@maiaos/sdk/browser/effect`
|
|
55
|
+
holds the page's Effect programs: the `#code=` sign-in, the pasted link or
|
|
56
|
+
code, and the sign-out. It also exports the Effect client
|
|
57
|
+
(`createLocalNodeEffectClient`), browser-safe: a test fails if the entry
|
|
58
|
+
reaches a Node built-in.
|
|
59
|
+
|
|
60
|
+
For live updates instead of polling, `createBrowserNodeChangeSource` returns a
|
|
61
|
+
`NodeChangeSource`: `watchNodeChanges(instanceId)` streams the Node's change
|
|
62
|
+
signals (`observe.events`) and `watchSession(sessionId, after?)` one Session's
|
|
63
|
+
transcript items (`session.attach`). Each subscription asks for its own
|
|
64
|
+
one-use ticket, opens the panel's observation socket, checks every frame
|
|
65
|
+
against the registry's schema and, after a dropped socket or the Node's
|
|
66
|
+
`resync`, tickets again and resumes after the last record it handed on; a
|
|
67
|
+
`resync` item tells the page to rebuild from the records that follow. Another
|
|
68
|
+
platform implements the same interface over its own relay with
|
|
69
|
+
`makeNodeChangeSource`. The Node's panel integration test
|
|
70
|
+
(`services/node/src/runtime/node-api/panel/session.integration.test.ts`)
|
|
71
|
+
proves it against the built Node and measures its latency. The local web
|
|
72
|
+
panel,
|
|
73
|
+
[`@maiaos/panel`](https://github.com/vllnt/maia/blob/main/apps/panel/README.md),
|
|
74
|
+
is its first host.
|
|
75
|
+
|
|
76
|
+
## Native shell
|
|
77
|
+
|
|
78
|
+
`@maiaos/sdk/shell` is the transport, stream relay and boot calls of a page
|
|
79
|
+
that a native shell hosts and hands an `invoke` function to. The page never
|
|
80
|
+
holds a credential: the shell adds it.
|
|
81
|
+
|
|
82
|
+
- `createShellTransport(invoke, { newId, target? })` sends each request to
|
|
83
|
+
the shell's `node_request` command and an abort to `node_cancel`. It
|
|
84
|
+
refuses a request over 512 KiB or already cancelled before any native
|
|
85
|
+
call, and turns the shell's typed refusals into `MaiaClientError` codes.
|
|
86
|
+
- `createShellStreamRelay(invoke, openChannel)` is the Node's change relay
|
|
87
|
+
(`observe.events`) over `observation_subscribe` and `observation_cancel`;
|
|
88
|
+
`openChannel` opens the channel the shell sends frames on. A subscription
|
|
89
|
+
the shell refuses rejects with the `MaiaClientError` the transport gives
|
|
90
|
+
that reason, and no cancel follows: a refused duplicate must not end the
|
|
91
|
+
subscription that holds its ID. A subscription that fails with no declared
|
|
92
|
+
reason is cancelled once under the same ID. A cancel ends within 1 second,
|
|
93
|
+
whatever the shell answers.
|
|
94
|
+
- `@maiaos/sdk/shell/effect` exports `createShellNodeChangeSource(invoke,
|
|
95
|
+
openChannel, nextId)`, the same `NodeChangeSource` as the browser's, with
|
|
96
|
+
one Session's items over `session_attach` and `session_detach`.
|
|
97
|
+
- `readShellNodeLifecycle(invoke)` and `startShellNode(invoke)` read and
|
|
98
|
+
start the Node on the shell's machine over `node_lifecycle_status` and
|
|
99
|
+
`node_lifecycle_start`. Both answer a `ShellNodeLifecycle`: `detecting`,
|
|
100
|
+
`starting` (with `profile`), `ready` (with `instanceId`, `owner`, `pid`
|
|
101
|
+
and `profile`), `unavailable` or `failed` (with `reason`, and with
|
|
102
|
+
`profile` when the shell reported one of 1 to 128 characters; any other
|
|
103
|
+
`profile` is dropped and the record keeps its state and reason). An answer
|
|
104
|
+
that is not a whole record reads as `unavailable` with the reason
|
|
105
|
+
`invalid_response` and no `profile`, never as `ready`. The shell sends no
|
|
106
|
+
event: the page calls the read again, and owns the pause and the deadline.
|
|
107
|
+
- `reportShellReady(invoke)` tells the shell that the page mounted. It
|
|
108
|
+
resolves on the shell's `null` answer and rejects any other.
|
|
109
|
+
- `readShellCapabilities(invoke)` reads which Node service steps the shell
|
|
110
|
+
can offer now, over `shell_capabilities`. It answers a `ShellCapabilities`:
|
|
111
|
+
`nodeService` (the shell ran the Node's own service check and got a whole
|
|
112
|
+
answer) and `nodeServiceInstalled` (that answer). False means "not known to
|
|
113
|
+
be available now", not "no service": the shell answers false, false
|
|
114
|
+
whenever it could not finish its check, also while another read runs. Any
|
|
115
|
+
answer that is not the whole version 1 record reads false, false, and so
|
|
116
|
+
does one that says installed without a service the shell could check. The
|
|
117
|
+
SDK asks once, with no retry and no cache: read it at boot and after a
|
|
118
|
+
service step, never in a loop. A shell without the command rejects, which
|
|
119
|
+
a caller treats like false, false.
|
|
120
|
+
- `readShellUpdateStatus(invoke)` reads what the shell knows about updates,
|
|
121
|
+
over `shell_update_status`: `bundleVersion`, and `pendingBundle`,
|
|
122
|
+
`nativeUpdate` and `fallback`, each `null` when the shell reported none.
|
|
123
|
+
- `reportShellPageBusy(invoke, busy)` tells the shell whether the page is
|
|
124
|
+
busy, over `page_busy_set`, once per call with no debounce.
|
|
125
|
+
|
|
126
|
+
Both update functions ask the shell once, with no retry and no cache, and
|
|
127
|
+
reject with a `MaiaClientError`: `invalid_response` for an answer that is not
|
|
128
|
+
a whole record (or, for the busy report, not `null`), `invalid_request` when
|
|
129
|
+
the shell does not offer the command or denied the page, and
|
|
130
|
+
`transport_failure` otherwise, also when the host has not answered after 6
|
|
131
|
+
seconds.
|
|
132
|
+
|
|
133
|
+
The three boot functions and the capabilities read reject with a
|
|
134
|
+
`MaiaClientError`, mapped as the transport maps a refusal. The lifecycle
|
|
135
|
+
read, the ready report and the capabilities read also reject as a
|
|
136
|
+
`transport_failure` when the host has not answered after 6 seconds (the
|
|
137
|
+
bridge's 5-second deadline plus its 1-second cancellation deadline). The
|
|
138
|
+
start has no page-side deadline: the shell answers it only once its Node is
|
|
139
|
+
ready or failed, under a bound of its own.
|
|
140
|
+
|
|
141
|
+
The host generates every ID, and the shell admits one prefix per command
|
|
142
|
+
pair: `renderer_` for a request, `observation_` for a change subscription
|
|
143
|
+
and `attach_` for a Session's items, each followed by letters and digits.
|
|
144
|
+
The entry imports no webview framework; a test fails if it reaches a Node
|
|
145
|
+
built-in or any package but `effect`.
|
|
146
|
+
|
|
49
147
|
## Status
|
|
50
148
|
|
|
51
149
|
**Source candidate.** This is the only request boundary between product
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type ApprovalRespondParameters } from "@maiaos/protocol";
|
|
1
2
|
import { type EffectClient, type LocalNodeEffectRequester } from "../request/effect.js";
|
|
2
3
|
import { MaiaClientError } from "../request/index.js";
|
|
3
4
|
import type { ApprovalClient } from "./approval.js";
|
|
5
|
+
export declare const decided: (status: string, input: Pick<ApprovalRespondParameters, "decision">, forSession: boolean) => boolean;
|
|
4
6
|
export declare const makeApprovalOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<ApprovalClient, MaiaClientError | TError>;
|
|
5
7
|
//# sourceMappingURL=effect.d.ts.map
|
package/dist/approval/effect.js
CHANGED
|
@@ -18,7 +18,7 @@ const parseShow = (value, input) => {
|
|
|
18
18
|
requireMatch(result.approval.approvalId === input.approvalId);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
-
const decided = (status, input, forSession) => {
|
|
21
|
+
export const decided = (status, input, forSession) => {
|
|
22
22
|
if (input.decision === "answer")
|
|
23
23
|
return status === "answered";
|
|
24
24
|
if (input.decision === "deny")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BoardMessagePostParameters, BoardMessagePostResult, BoardMessageReplyParameters, BoardMessageReplyResult, BoardPathReadParameters, BoardPathReadResult, BoardTaskAssignParameters, BoardTaskAssignResult, BoardTaskCancelParameters, BoardTaskCancelResult, BoardTaskClaimParameters, BoardTaskClaimResult, BoardTaskCompleteParameters, BoardTaskCompleteResult, BoardTaskCreateParameters, BoardTaskCreateResult, BoardTaskFailParameters, BoardTaskFailResult, BoardTaskListParameters, BoardTaskListResult, BoardTaskNeedsReplaceParameters, BoardTaskNeedsReplaceResult, BoardTaskPlanParameters, BoardTaskPlanResult, BoardTaskPromoteParameters, BoardTaskPromoteResult, BoardTaskReleaseParameters, BoardTaskReleaseResult, BoardTaskRenewParameters, BoardTaskRenewResult, BoardTaskReopenParameters, BoardTaskReopenResult, BoardTaskShowParameters, BoardTaskShowResult, BoardThreadShowParameters, BoardThreadShowResult } from "@maiaos/protocol";
|
|
2
|
+
import type { LocalNodeRequestOptions } from "../request/index.js";
|
|
3
|
+
export type BoardClient = {
|
|
4
|
+
readonly assignBoardTask: (parameters: BoardTaskAssignParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskAssignResult>;
|
|
5
|
+
readonly cancelBoardTask: (parameters: BoardTaskCancelParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskCancelResult>;
|
|
6
|
+
readonly claimBoardTask: (parameters: BoardTaskClaimParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskClaimResult>;
|
|
7
|
+
readonly completeBoardTask: (parameters: BoardTaskCompleteParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskCompleteResult>;
|
|
8
|
+
readonly createBoardTask: (parameters: BoardTaskCreateParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskCreateResult>;
|
|
9
|
+
readonly failBoardTask: (parameters: BoardTaskFailParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskFailResult>;
|
|
10
|
+
readonly listBoardTasks: (parameters: BoardTaskListParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskListResult>;
|
|
11
|
+
readonly planBoardTasks: (parameters: BoardTaskPlanParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskPlanResult>;
|
|
12
|
+
readonly postBoardMessage: (parameters: BoardMessagePostParameters, options: LocalNodeRequestOptions) => Promise<BoardMessagePostResult>;
|
|
13
|
+
readonly promoteBoardThread: (parameters: BoardTaskPromoteParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskPromoteResult>;
|
|
14
|
+
readonly readBoardPath: (parameters: BoardPathReadParameters, options: LocalNodeRequestOptions) => Promise<BoardPathReadResult>;
|
|
15
|
+
readonly releaseBoardTask: (parameters: BoardTaskReleaseParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskReleaseResult>;
|
|
16
|
+
readonly renewBoardTask: (parameters: BoardTaskRenewParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskRenewResult>;
|
|
17
|
+
readonly reopenBoardTask: (parameters: BoardTaskReopenParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskReopenResult>;
|
|
18
|
+
readonly replaceBoardTaskNeeds: (parameters: BoardTaskNeedsReplaceParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskNeedsReplaceResult>;
|
|
19
|
+
readonly replyToBoardMessage: (parameters: BoardMessageReplyParameters, options: LocalNodeRequestOptions) => Promise<BoardMessageReplyResult>;
|
|
20
|
+
readonly showBoardTask: (parameters: BoardTaskShowParameters, options: LocalNodeRequestOptions) => Promise<BoardTaskShowResult>;
|
|
21
|
+
readonly showBoardThread: (parameters: BoardThreadShowParameters, options: LocalNodeRequestOptions) => Promise<BoardThreadShowResult>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=board.d.ts.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 { BoardClient } from "./board.js";
|
|
4
|
+
export declare const makeBoardOperations: <TError>(request: LocalNodeEffectRequester<TError>) => EffectClient<BoardClient, MaiaClientError | TError>;
|
|
5
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { boardMessagePostResultSchema, boardMessageReplyResultSchema, boardPathReadResultSchema, boardTaskAssignResultSchema, boardTaskCancelResultSchema, boardTaskClaimResultSchema, boardTaskCompleteResultSchema, boardTaskCreateResultSchema, boardTaskFailResultSchema, boardTaskListResultSchema, boardTaskNeedsReplaceResultSchema, boardTaskPlanResultSchema, boardTaskPromoteResultSchema, boardTaskReleaseResultSchema, boardTaskRenewResultSchema, boardTaskReopenResultSchema, boardTaskShowResultSchema, boardThreadShowResultSchema, } 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 board response did not match the request.");
|
|
7
|
+
};
|
|
8
|
+
const nextRevision = (task, expected) => BigInt(task.revision) === BigInt(expected) + 1n;
|
|
9
|
+
const underPath = (path, prefix) => path === prefix || path.startsWith(`${prefix}/`);
|
|
10
|
+
const sameNeeds = (got, wanted) => (got ?? []).join("\n") === (wanted ?? []).join("\n");
|
|
11
|
+
const parseCreate = (value, input) => {
|
|
12
|
+
const result = boardTaskCreateResultSchema.parse(value);
|
|
13
|
+
requireMatch(result.commandId === input.commandId &&
|
|
14
|
+
result.task.workspaceId === input.workspaceId &&
|
|
15
|
+
result.task.path === input.path &&
|
|
16
|
+
result.task.text === input.text &&
|
|
17
|
+
sameNeeds(result.task.needs, input.needs));
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
const parsePlan = (value, input) => {
|
|
21
|
+
const result = boardTaskPlanResultSchema.parse(value);
|
|
22
|
+
requireMatch(result.commandId === input.commandId &&
|
|
23
|
+
result.tasks.length === input.tasks.length &&
|
|
24
|
+
result.tasks.every((task, index) => task.key === input.tasks[index]?.key &&
|
|
25
|
+
task.path === input.tasks[index].path));
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
const claimedAs = (task, agent) => {
|
|
29
|
+
const claimant = task.claim?.claimant;
|
|
30
|
+
return (claimant !== undefined &&
|
|
31
|
+
(agent === undefined ||
|
|
32
|
+
(claimant.kind === "session" && claimant.agent === agent)));
|
|
33
|
+
};
|
|
34
|
+
const parseClaim = (value, input) => {
|
|
35
|
+
const result = boardTaskClaimResultSchema.parse(value);
|
|
36
|
+
const { commandId, task } = result;
|
|
37
|
+
const target = input.taskId === undefined
|
|
38
|
+
? task.workspaceId === input.workspaceId &&
|
|
39
|
+
underPath(task.path, input.path ?? "")
|
|
40
|
+
: task.id === input.taskId &&
|
|
41
|
+
nextRevision(task, input.expectedRevision ?? "0");
|
|
42
|
+
requireMatch(commandId === input.commandId && target && claimedAs(task, input.as));
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
const parseChange = (schema) => (value, input) => {
|
|
46
|
+
const result = schema.parse(value);
|
|
47
|
+
requireMatch(result.commandId === input.commandId &&
|
|
48
|
+
result.task.id === input.taskId &&
|
|
49
|
+
nextRevision(result.task, input.expectedRevision));
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const parseRenew = parseChange(boardTaskRenewResultSchema);
|
|
53
|
+
const parseRelease = parseChange(boardTaskReleaseResultSchema);
|
|
54
|
+
const parseComplete = parseChange(boardTaskCompleteResultSchema);
|
|
55
|
+
const parseFail = parseChange(boardTaskFailResultSchema);
|
|
56
|
+
const parseCancel = parseChange(boardTaskCancelResultSchema);
|
|
57
|
+
const parseReopen = parseChange(boardTaskReopenResultSchema);
|
|
58
|
+
const parseAssign = (value, input) => {
|
|
59
|
+
const result = parseChange(boardTaskAssignResultSchema)(value, input);
|
|
60
|
+
requireMatch(result.task.assignee === input.assignee);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
const parsePromote = (value, input) => {
|
|
64
|
+
const result = boardTaskPromoteResultSchema.parse(value);
|
|
65
|
+
requireMatch(result.commandId === input.commandId &&
|
|
66
|
+
result.task.id === input.threadId &&
|
|
67
|
+
result.task.workspaceId === input.workspaceId &&
|
|
68
|
+
sameNeeds(result.task.needs, input.needs));
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
const parseNeedsReplace = (value, input) => {
|
|
72
|
+
const result = parseChange(boardTaskNeedsReplaceResultSchema)(value, input);
|
|
73
|
+
requireMatch(sameNeeds(result.task.needs, input.needs));
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
const heldBy = (task, { projectId, sessionId }) => {
|
|
77
|
+
if (projectId === undefined && sessionId === undefined)
|
|
78
|
+
return true;
|
|
79
|
+
const claimant = task.claim?.claimant;
|
|
80
|
+
return (claimant?.kind === "session" &&
|
|
81
|
+
claimant.sessionId !== undefined &&
|
|
82
|
+
(sessionId === undefined || claimant.sessionId === sessionId));
|
|
83
|
+
};
|
|
84
|
+
const parseList = (value, input) => {
|
|
85
|
+
const result = boardTaskListResultSchema.parse(value);
|
|
86
|
+
requireMatch(result.items.length <= (input.limit ?? result.items.length) &&
|
|
87
|
+
result.items.every((task) => (input.workspaceId === undefined ||
|
|
88
|
+
task.workspaceId === input.workspaceId) &&
|
|
89
|
+
(input.state === undefined || task.state === input.state) &&
|
|
90
|
+
(input.path === undefined || underPath(task.path, input.path)) &&
|
|
91
|
+
heldBy(task, input)));
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
const parseShow = (value, input) => {
|
|
95
|
+
const result = boardTaskShowResultSchema.parse(value);
|
|
96
|
+
requireMatch(result.task.id === input.taskId &&
|
|
97
|
+
result.messages.length <= (input.limit ?? result.messages.length));
|
|
98
|
+
return result;
|
|
99
|
+
};
|
|
100
|
+
const actedAs = (actor, agent) => agent === undefined || (actor?.kind === "session" && actor.agent === agent);
|
|
101
|
+
const parsePost = (value, input) => {
|
|
102
|
+
const result = boardMessagePostResultSchema.parse(value);
|
|
103
|
+
requireMatch(result.commandId === input.commandId &&
|
|
104
|
+
result.thread.path === input.path &&
|
|
105
|
+
result.message.text === input.text &&
|
|
106
|
+
actedAs(result.message.author, input.as));
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
const parseReply = (value, input) => {
|
|
110
|
+
const result = boardMessageReplyResultSchema.parse(value);
|
|
111
|
+
requireMatch(result.commandId === input.commandId &&
|
|
112
|
+
result.message.threadId === input.threadId &&
|
|
113
|
+
result.message.text === input.text &&
|
|
114
|
+
actedAs(result.message.author, input.as));
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
const parseReadPath = (value, input) => {
|
|
118
|
+
const result = boardPathReadResultSchema.parse(value);
|
|
119
|
+
requireMatch(result.items.length <= (input.limit ?? result.items.length) &&
|
|
120
|
+
actedAs(result.actor, input.as) &&
|
|
121
|
+
result.items.every((thread) => thread.workspaceId === input.workspaceId &&
|
|
122
|
+
underPath(thread.path, input.path)));
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
const parseShowThread = (value, input) => {
|
|
126
|
+
const result = boardThreadShowResultSchema.parse(value);
|
|
127
|
+
requireMatch(result.thread.id === input.threadId &&
|
|
128
|
+
result.messages.length <= (input.limit ?? result.messages.length) &&
|
|
129
|
+
actedAs(result.actor, input.as));
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
const makeMessageMutations = (request) => ({
|
|
133
|
+
postBoardMessage: (parameters, options) => request({ method: "board.message.post", parameters }, { parse: (value) => parsePost(value, parameters) }, options),
|
|
134
|
+
replyToBoardMessage: (parameters, options) => request({ method: "board.message.reply", parameters }, { parse: (value) => parseReply(value, parameters) }, options),
|
|
135
|
+
});
|
|
136
|
+
const makeMessageReads = (request) => ({
|
|
137
|
+
readBoardPath: (parameters, options) => request({ method: "board.path.read", parameters }, { parse: (value) => parseReadPath(value, parameters) }, options),
|
|
138
|
+
showBoardThread: (parameters, options) => request({ method: "board.thread.show", parameters }, { parse: (value) => parseShowThread(value, parameters) }, options),
|
|
139
|
+
});
|
|
140
|
+
const makeClaimMutations = (request) => ({
|
|
141
|
+
claimBoardTask: (parameters, options) => request({ method: "board.task.claim", parameters }, { parse: (value) => parseClaim(value, parameters) }, options),
|
|
142
|
+
createBoardTask: (parameters, options) => request({ method: "board.task.create", parameters }, { parse: (value) => parseCreate(value, parameters) }, options),
|
|
143
|
+
planBoardTasks: (parameters, options) => request({ method: "board.task.plan", parameters }, { parse: (value) => parsePlan(value, parameters) }, options),
|
|
144
|
+
});
|
|
145
|
+
const makeHeldMutations = (request) => ({
|
|
146
|
+
completeBoardTask: (parameters, options) => request({ method: "board.task.complete", parameters }, { parse: (value) => parseComplete(value, parameters) }, options),
|
|
147
|
+
failBoardTask: (parameters, options) => request({ method: "board.task.fail", parameters }, { parse: (value) => parseFail(value, parameters) }, options),
|
|
148
|
+
...makeHandBackMutations(request),
|
|
149
|
+
});
|
|
150
|
+
const makeHandBackMutations = (request) => ({
|
|
151
|
+
releaseBoardTask: (parameters, options) => request({ method: "board.task.release", parameters }, { parse: (value) => parseRelease(value, parameters) }, options),
|
|
152
|
+
renewBoardTask: (parameters, options) => request({ method: "board.task.renew", parameters }, { parse: (value) => parseRenew(value, parameters) }, options),
|
|
153
|
+
});
|
|
154
|
+
const makeLifecycleMutations = (request) => ({
|
|
155
|
+
cancelBoardTask: (parameters, options) => request({ method: "board.task.cancel", parameters }, { parse: (value) => parseCancel(value, parameters) }, options),
|
|
156
|
+
reopenBoardTask: (parameters, options) => request({ method: "board.task.reopen", parameters }, { parse: (value) => parseReopen(value, parameters) }, options),
|
|
157
|
+
});
|
|
158
|
+
const makeManageMutations = (request) => ({
|
|
159
|
+
assignBoardTask: (parameters, options) => request({ method: "board.task.assign", parameters }, { parse: (value) => parseAssign(value, parameters) }, options),
|
|
160
|
+
promoteBoardThread: (parameters, options) => request({ method: "board.task.promote", parameters }, { parse: (value) => parsePromote(value, parameters) }, options),
|
|
161
|
+
replaceBoardTaskNeeds: (parameters, options) => request({ method: "board.task.needs.replace", parameters }, { parse: (value) => parseNeedsReplace(value, parameters) }, options),
|
|
162
|
+
});
|
|
163
|
+
export const makeBoardOperations = (request) => {
|
|
164
|
+
const verified = (payload, output, options) => verifiedMutation(request(payload, output, options), options);
|
|
165
|
+
return {
|
|
166
|
+
...makeClaimMutations(verified),
|
|
167
|
+
...makeHeldMutations(verified),
|
|
168
|
+
...makeLifecycleMutations(verified),
|
|
169
|
+
...makeManageMutations(verified),
|
|
170
|
+
...makeMessageMutations(verified),
|
|
171
|
+
...makeMessageReads(request),
|
|
172
|
+
listBoardTasks: (parameters, options) => request({ method: "board.task.list", parameters }, { parse: (value) => parseList(value, parameters) }, options),
|
|
173
|
+
showBoardTask: (parameters, options) => request({ method: "board.task.show", parameters }, { parse: (value) => parseShow(value, parameters) }, options),
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type BoardClient } from "./board.js";
|
|
2
|
+
export { BOARD_ERROR_CODES, type BoardActor, type BoardClaim, type BoardErrorCode, type BoardMessage, type BoardMessagePostParameters, boardMessagePostParametersSchema, type BoardMessagePostResult, type BoardMessageReplyParameters, boardMessageReplyParametersSchema, type BoardMessageReplyResult, type BoardPathReadParameters, boardPathReadParametersSchema, type BoardPathReadResult, type BoardPlanTask, type BoardTask, type BoardTaskAssignParameters, boardTaskAssignParametersSchema, type BoardTaskAssignResult, type BoardTaskCancelParameters, boardTaskCancelParametersSchema, type BoardTaskCancelResult, type BoardTaskClaimParameters, boardTaskClaimParametersSchema, type BoardTaskClaimResult, type BoardTaskCompleteParameters, boardTaskCompleteParametersSchema, type BoardTaskCompleteResult, type BoardTaskCreateParameters, boardTaskCreateParametersSchema, type BoardTaskCreateResult, type BoardTaskFailParameters, boardTaskFailParametersSchema, type BoardTaskFailResult, type BoardTaskListParameters, boardTaskListParametersSchema, type BoardTaskListResult, type BoardTaskNeedsReplaceParameters, boardTaskNeedsReplaceParametersSchema, type BoardTaskNeedsReplaceResult, type BoardTaskPlanParameters, boardTaskPlanParametersSchema, type BoardTaskPlanResult, type BoardTaskPromoteParameters, boardTaskPromoteParametersSchema, type BoardTaskPromoteResult, type BoardTaskReleaseParameters, boardTaskReleaseParametersSchema, type BoardTaskReleaseResult, type BoardTaskRenewParameters, boardTaskRenewParametersSchema, type BoardTaskRenewResult, type BoardTaskReopenParameters, boardTaskReopenParametersSchema, type BoardTaskReopenResult, type BoardTaskShowParameters, boardTaskShowParametersSchema, type BoardTaskShowResult, type BoardTaskState, type BoardTaskSummary, type BoardThreadShowParameters, boardThreadShowParametersSchema, type BoardThreadShowResult, type BoardThreadSummary, DEFAULT_BOARD_LEASE_SECONDS, MAX_BOARD_LEASE_SECONDS, MAX_BOARD_PLAN_JSON_BYTES, MAX_BOARD_PLAN_TASKS, MAX_BOARD_PLAN_TEXT_BYTES, MAX_BOARD_TASK_NEEDS, MAX_BOARD_TASK_PAGE_SIZE, MAX_BOARD_THREAD_MESSAGES, MAX_BOARD_THREAD_PAGE_SIZE, MIN_BOARD_LEASE_SECONDS, } from "@maiaos/protocol";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { BOARD_ERROR_CODES, boardMessagePostParametersSchema, boardMessageReplyParametersSchema, boardPathReadParametersSchema, boardTaskAssignParametersSchema, boardTaskCancelParametersSchema, boardTaskClaimParametersSchema, boardTaskCompleteParametersSchema, boardTaskCreateParametersSchema, boardTaskFailParametersSchema, boardTaskListParametersSchema, boardTaskNeedsReplaceParametersSchema, boardTaskPlanParametersSchema, boardTaskPromoteParametersSchema, boardTaskReleaseParametersSchema, boardTaskRenewParametersSchema, boardTaskReopenParametersSchema, boardTaskShowParametersSchema, boardThreadShowParametersSchema, DEFAULT_BOARD_LEASE_SECONDS, MAX_BOARD_LEASE_SECONDS, MAX_BOARD_PLAN_JSON_BYTES, MAX_BOARD_PLAN_TASKS, MAX_BOARD_PLAN_TEXT_BYTES, MAX_BOARD_TASK_NEEDS, MAX_BOARD_TASK_PAGE_SIZE, MAX_BOARD_THREAD_MESSAGES, MAX_BOARD_THREAD_PAGE_SIZE, MIN_BOARD_LEASE_SECONDS, } from "@maiaos/protocol";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createLocalNodeEffectClient, type LocalNodeEffectClient, } from "../client/effect.js";
|
|
2
|
+
export { makeNodeChangeSource, type NodeChangeRelays, type NodeChangeSource, } from "../node-changes/effect.js";
|
|
3
|
+
export { createBrowserNodeChangeSource, createBrowserStreamRelay, } from "./observation.js";
|
|
4
|
+
export type { BrowserStreamOptions, BrowserWebSocket } from "./options.js";
|
|
5
|
+
export { signInWithPaste } from "./paste.js";
|
|
6
|
+
export { clearSession, codeOfPaste, endSession, PANEL_SESSION_STORAGE_KEY, readSession, redeemCode, type Revocation, type SessionPlatform, type SessionStorage, type SignIn, type SignInPlatform, startSession, } from "./session.js";
|
|
7
|
+
export { signOut } from "./sign-out.js";
|
|
8
|
+
export { makeSignInStatus, type SignInState, type SignInStatus, } from "./status.js";
|
|
9
|
+
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createLocalNodeEffectClient, } from "../client/effect.js";
|
|
2
|
+
export { makeNodeChangeSource, } from "../node-changes/effect.js";
|
|
3
|
+
export { createBrowserNodeChangeSource, createBrowserStreamRelay, } from "./observation.js";
|
|
4
|
+
export { signInWithPaste } from "./paste.js";
|
|
5
|
+
export { clearSession, codeOfPaste, endSession, PANEL_SESSION_STORAGE_KEY, readSession, redeemCode, startSession, } from "./session.js";
|
|
6
|
+
export { signOut } from "./sign-out.js";
|
|
7
|
+
export { makeSignInStatus, } from "./status.js";
|
|
8
|
+
//# sourceMappingURL=effect.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect, Layer, Option } from "effect";
|
|
2
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import { MaiaClientError, type MaiaTransport } from "../request/index.js";
|
|
4
|
+
import type { BrowserTransportOptions } from "./options.js";
|
|
5
|
+
type Envelope = Parameters<MaiaTransport["request"]>[0];
|
|
6
|
+
export declare const clientLayer: (fetch: typeof globalThis.fetch | undefined) => Layer.Layer<HttpClient.HttpClient, never, never>;
|
|
7
|
+
export declare const failure: (message: string, cause?: unknown) => MaiaClientError;
|
|
8
|
+
export declare const sessionHeaders: (session: Option.Option<string>) => {} | {
|
|
9
|
+
"x-maia-panel-session": string;
|
|
10
|
+
};
|
|
11
|
+
export declare const withDeadline: <TValue, TError, TRequirements>(effect: Effect.Effect<TValue, TError, TRequirements>) => Effect.Effect<TValue, TError | MaiaClientError, TRequirements>;
|
|
12
|
+
export declare const exchange: (options: BrowserTransportOptions, envelope: Envelope) => Effect.Effect<unknown, MaiaClientError, never>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=exchange.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NODE_API_JSON_CONTENT_TYPE, NODE_API_PANEL_OPERATION_PATH, NODE_API_PANEL_SESSION_HEADER, protocolErrorEnvelopeSchema, protocolRequestEnvelopeSchema, protocolSuccessEnvelopeSchema, } from "@maiaos/protocol";
|
|
2
|
+
import { Effect, Layer, Option } from "effect";
|
|
3
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
4
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
5
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
6
|
+
import { MaiaClientError } from "../request/index.js";
|
|
7
|
+
const REQUEST_INIT = {
|
|
8
|
+
cache: "no-store",
|
|
9
|
+
credentials: "same-origin",
|
|
10
|
+
redirect: "error",
|
|
11
|
+
referrerPolicy: "no-referrer",
|
|
12
|
+
};
|
|
13
|
+
export const clientLayer = (fetch) => (fetch === undefined
|
|
14
|
+
? FetchHttpClient.layer
|
|
15
|
+
: FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetch)))).pipe(Layer.provide(Layer.succeed(FetchHttpClient.RequestInit, REQUEST_INIT)));
|
|
16
|
+
export const failure = (message, cause) => new MaiaClientError("transport_failure", message, { cause });
|
|
17
|
+
export const sessionHeaders = (session) => Option.match(session, {
|
|
18
|
+
onNone: () => ({}),
|
|
19
|
+
onSome: (value) => ({ [NODE_API_PANEL_SESSION_HEADER]: value }),
|
|
20
|
+
});
|
|
21
|
+
const operationRequest = (origin, session, envelope) => Effect.try({
|
|
22
|
+
catch: (cause) => failure("The Maia Node API request failed runtime validation.", cause),
|
|
23
|
+
try: () => JSON.stringify(protocolRequestEnvelopeSchema.parse(envelope)),
|
|
24
|
+
}).pipe(Effect.map((body) => HttpClientRequest.post(`${origin}${NODE_API_PANEL_OPERATION_PATH}`).pipe(HttpClientRequest.setHeaders(sessionHeaders(session)), HttpClientRequest.bodyText(body, NODE_API_JSON_CONTENT_TYPE))));
|
|
25
|
+
const responseEnvelope = (json) => {
|
|
26
|
+
const success = protocolSuccessEnvelopeSchema.safeParse(json);
|
|
27
|
+
return success.success
|
|
28
|
+
? success.data
|
|
29
|
+
: protocolErrorEnvelopeSchema.parse(json);
|
|
30
|
+
};
|
|
31
|
+
const decodeResponse = (response) => response.json.pipe(Effect.flatMap((json) => Effect.try(() => responseEnvelope(json))), Effect.mapError((cause) => new MaiaClientError("invalid_response", "The Maia Node API response failed runtime validation.", { cause })));
|
|
32
|
+
const DEADLINE = "30 seconds";
|
|
33
|
+
export const withDeadline = (effect) => effect.pipe(Effect.timeoutOrElse({
|
|
34
|
+
duration: DEADLINE,
|
|
35
|
+
orElse: () => Effect.fail(new MaiaClientError("outcome_unknown", "The Maia Node API request outcome is unknown.")),
|
|
36
|
+
}));
|
|
37
|
+
const UNAUTHORIZED = 401;
|
|
38
|
+
const send = (options, envelope) => Effect.gen(function* () {
|
|
39
|
+
const client = yield* HttpClient.HttpClient;
|
|
40
|
+
const request = yield* operationRequest(options.origin, Option.fromNullishOr(options.session?.()), envelope);
|
|
41
|
+
const response = yield* client
|
|
42
|
+
.execute(request)
|
|
43
|
+
.pipe(Effect.mapError((cause) => failure("The Maia Node API request failed.", cause)));
|
|
44
|
+
if (response.status === UNAUTHORIZED)
|
|
45
|
+
yield* Effect.sync(() => options.onSignedOut?.());
|
|
46
|
+
return yield* decodeResponse(response);
|
|
47
|
+
}).pipe(Effect.scoped, withDeadline);
|
|
48
|
+
export const exchange = (options, envelope) => send(options, envelope).pipe(Effect.provide(clientLayer(options.fetch)));
|
|
49
|
+
//# sourceMappingURL=exchange.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type NodeChangeSource } from "../node-changes/effect.js";
|
|
3
|
+
import type { StreamRelay } from "../stream/index.js";
|
|
4
|
+
import type { BrowserStreamOptions } from "./options.js";
|
|
5
|
+
export declare const createBrowserStreamRelay: <TSubscribe extends object>(options: BrowserStreamOptions) => StreamRelay<TSubscribe>;
|
|
6
|
+
export declare const createBrowserNodeChangeSource: (options: BrowserStreamOptions & {
|
|
7
|
+
readonly nextId: (prefix: "request") => Effect.Effect<string>;
|
|
8
|
+
}) => NodeChangeSource;
|
|
9
|
+
//# sourceMappingURL=observation.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { NODE_API_PANEL_OBSERVATION_PATH, NODE_API_PANEL_OBSERVATION_TICKET_PATH, NODE_API_PANEL_TICKET_PARAMETER, NODE_API_WEBSOCKET_PROTOCOL, } from "@maiaos/protocol";
|
|
2
|
+
import { Effect, Option, Schema } from "effect";
|
|
3
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
4
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
5
|
+
import { makeNodeChangeSource, } from "../node-changes/effect.js";
|
|
6
|
+
import { MaiaClientError } from "../request/index.js";
|
|
7
|
+
import { clientLayer, failure, sessionHeaders, withDeadline, } from "./exchange.js";
|
|
8
|
+
const ticketSchema = Schema.Struct({
|
|
9
|
+
ticket: Schema.String.check(Schema.isPattern(/^[\w-]{43}$/u)),
|
|
10
|
+
});
|
|
11
|
+
const UNAUTHORIZED = 401;
|
|
12
|
+
const ISSUED = 200;
|
|
13
|
+
const ticketRequest = (options) => HttpClientRequest.post(`${options.origin}${NODE_API_PANEL_OBSERVATION_TICKET_PATH}`).pipe(HttpClientRequest.setHeaders(sessionHeaders(Option.fromNullishOr(options.session?.()))));
|
|
14
|
+
const decodeTicket = (response) => response.json.pipe(Effect.flatMap(Schema.decodeUnknownEffect(ticketSchema)), Effect.map(({ ticket }) => ticket), Effect.mapError((cause) => new MaiaClientError("invalid_response", "The Maia Node observation ticket is invalid.", { cause })));
|
|
15
|
+
const fetchTicket = (options) => Effect.gen(function* () {
|
|
16
|
+
const client = yield* HttpClient.HttpClient;
|
|
17
|
+
const response = yield* client
|
|
18
|
+
.execute(ticketRequest(options))
|
|
19
|
+
.pipe(Effect.mapError((cause) => failure("The Maia Node observation ticket request failed.", cause)));
|
|
20
|
+
if (response.status === UNAUTHORIZED) {
|
|
21
|
+
yield* Effect.sync(() => options.onSignedOut?.());
|
|
22
|
+
return yield* Effect.fail(failure("The Maia panel session ended."));
|
|
23
|
+
}
|
|
24
|
+
if (response.status !== ISSUED)
|
|
25
|
+
return yield* Effect.fail(failure("The Maia Node refused an observation ticket."));
|
|
26
|
+
return yield* decodeTicket(response);
|
|
27
|
+
}).pipe(Effect.scoped, withDeadline, Effect.provide(clientLayer(options.fetch)));
|
|
28
|
+
const platformWebSocket = (url, protocols) => new globalThis.WebSocket(url, [...protocols]);
|
|
29
|
+
const socketUrl = (origin, ticket) => `${origin.replace(/^http/u, "ws")}${NODE_API_PANEL_OBSERVATION_PATH}?${NODE_API_PANEL_TICKET_PARAMETER}=${ticket}`;
|
|
30
|
+
const wire = (socket, subscribe, onEvent) => {
|
|
31
|
+
let open = true;
|
|
32
|
+
const closed = (reason) => {
|
|
33
|
+
if (!open)
|
|
34
|
+
return;
|
|
35
|
+
open = false;
|
|
36
|
+
onEvent({ kind: "closed", reason });
|
|
37
|
+
};
|
|
38
|
+
socket.addEventListener("open", () => {
|
|
39
|
+
socket.send(subscribe);
|
|
40
|
+
});
|
|
41
|
+
socket.addEventListener("message", ({ data }) => {
|
|
42
|
+
if (open)
|
|
43
|
+
onEvent({ kind: "frame", text: typeof data === "string" ? data : "" });
|
|
44
|
+
});
|
|
45
|
+
socket.addEventListener("close", () => {
|
|
46
|
+
closed("closed");
|
|
47
|
+
});
|
|
48
|
+
socket.addEventListener("error", () => {
|
|
49
|
+
closed("error");
|
|
50
|
+
socket.close();
|
|
51
|
+
});
|
|
52
|
+
return () => {
|
|
53
|
+
open = false;
|
|
54
|
+
socket.close(1000, "client_closed");
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const subscribeOnce = (options, subscribe, onEvent) => Effect.gen(function* () {
|
|
58
|
+
const ticket = yield* fetchTicket(options);
|
|
59
|
+
const socket = yield* Effect.try({
|
|
60
|
+
catch: (cause) => failure("The Maia Node observation socket could not open.", cause),
|
|
61
|
+
try: () => (options.webSocket ?? platformWebSocket)(socketUrl(options.origin, ticket), [NODE_API_WEBSOCKET_PROTOCOL]),
|
|
62
|
+
});
|
|
63
|
+
return wire(socket, JSON.stringify({
|
|
64
|
+
...subscribe,
|
|
65
|
+
authentication: { scheme: "maia.node.bearer/v1", token: ticket },
|
|
66
|
+
}), onEvent);
|
|
67
|
+
});
|
|
68
|
+
export const createBrowserStreamRelay = (options) => (subscribe, onEvent) => Effect.runPromise(subscribeOnce(options, subscribe, onEvent));
|
|
69
|
+
export const createBrowserNodeChangeSource = (options) => makeNodeChangeSource({
|
|
70
|
+
changes: createBrowserStreamRelay(options),
|
|
71
|
+
session: createBrowserStreamRelay(options),
|
|
72
|
+
}, options.nextId);
|
|
73
|
+
//# sourceMappingURL=observation.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type ReadSession = () => string | undefined;
|
|
2
|
+
export type BrowserTransportOptions = {
|
|
3
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
4
|
+
readonly onSignedOut?: () => void;
|
|
5
|
+
readonly origin: string;
|
|
6
|
+
readonly session?: ReadSession;
|
|
7
|
+
};
|
|
8
|
+
export type BrowserWebSocket = {
|
|
9
|
+
readonly addEventListener: (type: "close" | "error" | "message" | "open", listener: (event: {
|
|
10
|
+
readonly data?: unknown;
|
|
11
|
+
}) => void) => void;
|
|
12
|
+
readonly close: (code?: number, reason?: string) => void;
|
|
13
|
+
readonly send: (data: string) => void;
|
|
14
|
+
};
|
|
15
|
+
export type BrowserStreamOptions = BrowserTransportOptions & {
|
|
16
|
+
readonly webSocket?: (url: string, protocols: readonly string[]) => BrowserWebSocket;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type SessionPlatform } from "./session.js";
|
|
3
|
+
import type { SignInStatus } from "./status.js";
|
|
4
|
+
export declare const signInWithPaste: (status: SignInStatus, platform: SessionPlatform, pasted: string) => Effect.Effect<void>;
|
|
5
|
+
//# sourceMappingURL=paste.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { codeOfPaste, redeemCode, } from "./session.js";
|
|
3
|
+
export const signInWithPaste = (status, platform, pasted) => Effect.gen(function* () {
|
|
4
|
+
yield* Effect.sync(() => {
|
|
5
|
+
status.set("starting");
|
|
6
|
+
});
|
|
7
|
+
const code = codeOfPaste(pasted);
|
|
8
|
+
const next = code === undefined ? "refused" : yield* redeemCode(platform, code);
|
|
9
|
+
yield* Effect.sync(() => {
|
|
10
|
+
status.set(next);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=paste.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
export type SessionStorage = {
|
|
3
|
+
readonly getItem: (key: string) => null | string;
|
|
4
|
+
readonly removeItem: (key: string) => void;
|
|
5
|
+
readonly setItem: (key: string, value: string) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const PANEL_SESSION_STORAGE_KEY = "maia.panel.session";
|
|
8
|
+
export type SignIn = "refused" | "signed-in" | "signed-out";
|
|
9
|
+
export type SessionPlatform = {
|
|
10
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
11
|
+
readonly location: {
|
|
12
|
+
readonly origin: string;
|
|
13
|
+
};
|
|
14
|
+
readonly storage?: SessionStorage;
|
|
15
|
+
};
|
|
16
|
+
export type SignInPlatform = SessionPlatform & {
|
|
17
|
+
readonly location: {
|
|
18
|
+
readonly hash: string;
|
|
19
|
+
readonly origin: string;
|
|
20
|
+
readonly pathname: string;
|
|
21
|
+
readonly search: string;
|
|
22
|
+
};
|
|
23
|
+
readonly replaceAddress: (address: string) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const codeOfPaste: (pasted: string) => string | undefined;
|
|
26
|
+
export declare const readSession: (storage?: SessionStorage) => Option.Option<string>;
|
|
27
|
+
export declare const clearSession: (storage?: SessionStorage) => void;
|
|
28
|
+
export type Revocation = "confirmed" | "unconfirmed";
|
|
29
|
+
export declare const endSession: (platform: SessionPlatform, afterClear?: Effect.Effect<void>) => Effect.Effect<Revocation>;
|
|
30
|
+
export declare const redeemCode: (platform: SessionPlatform, code: string) => Effect.Effect<SignIn>;
|
|
31
|
+
export declare const startSession: (platform: SignInPlatform) => Effect.Effect<SignIn>;
|
|
32
|
+
//# sourceMappingURL=session.d.ts.map
|