@quo-systems/dock 0.1.0
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 +202 -0
- package/NOTICE +6 -0
- package/README.md +27 -0
- package/beings/avatar.ts +84 -0
- package/beings/desk.ts +46 -0
- package/beings/index.ts +5 -0
- package/beings/quo-dock.md +698 -0
- package/beings/setup.ts +23 -0
- package/beings/side.ts +51 -0
- package/beings/user.ts +78 -0
- package/cli/client.ts +65 -0
- package/cli/daemon.ts +582 -0
- package/cli/quo.ts +126 -0
- package/dist/beings/avatar.d.ts +32 -0
- package/dist/beings/avatar.js +82 -0
- package/dist/beings/desk.d.ts +42 -0
- package/dist/beings/desk.js +43 -0
- package/dist/beings/index.d.ts +3 -0
- package/dist/beings/index.js +5 -0
- package/dist/beings/setup.d.ts +2 -0
- package/dist/beings/setup.js +16 -0
- package/dist/beings/side.d.ts +25 -0
- package/dist/beings/side.js +37 -0
- package/dist/beings/user.d.ts +108 -0
- package/dist/beings/user.js +74 -0
- package/dist/cli/client.d.ts +14 -0
- package/dist/cli/client.js +51 -0
- package/dist/cli/daemon.d.ts +57 -0
- package/dist/cli/daemon.js +581 -0
- package/dist/cli/quo.d.ts +2 -0
- package/dist/cli/quo.js +121 -0
- package/dist/harbor/browser.d.ts +13 -0
- package/dist/harbor/browser.js +50 -0
- package/dist/harbor/disk.d.ts +19 -0
- package/dist/harbor/disk.js +126 -0
- package/dist/harbor/edge/edge.d.ts +26 -0
- package/dist/harbor/edge/edge.js +123 -0
- package/dist/harbor/edge/exercise.d.ts +7 -0
- package/dist/harbor/edge/exercise.js +179 -0
- package/dist/harbor/edge/storage.d.ts +20 -0
- package/dist/harbor/edge/storage.js +81 -0
- package/dist/harbor/edge/worker.d.ts +14 -0
- package/dist/harbor/edge/worker.js +47 -0
- package/dist/harbor/files.d.ts +14 -0
- package/dist/harbor/files.js +83 -0
- package/dist/harbor/idb.d.ts +15 -0
- package/dist/harbor/idb.js +85 -0
- package/dist/human/dom.d.ts +2 -0
- package/dist/human/dom.js +15 -0
- package/dist/human/html.d.ts +32 -0
- package/dist/human/html.js +136 -0
- package/dist/human/screen.d.ts +11 -0
- package/dist/human/screen.js +66 -0
- package/dist/human/tab.d.ts +7 -0
- package/dist/human/tab.js +68 -0
- package/dist/mcp/agent.d.ts +10 -0
- package/dist/mcp/agent.js +78 -0
- package/dist/mcp/http.d.ts +27 -0
- package/dist/mcp/http.js +96 -0
- package/dist/mcp/oauth.d.ts +98 -0
- package/dist/mcp/oauth.js +241 -0
- package/dist/mcp/pilot.d.ts +6 -0
- package/dist/mcp/pilot.js +68 -0
- package/dist/mcp/runner.d.ts +45 -0
- package/dist/mcp/runner.js +94 -0
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.js +63 -0
- package/dist/mcp/web/exchange.d.ts +23 -0
- package/dist/mcp/web/exchange.js +136 -0
- package/harbor/browser.ts +63 -0
- package/harbor/disk.ts +120 -0
- package/harbor/edge/edge.ts +147 -0
- package/harbor/edge/exercise.ts +187 -0
- package/harbor/edge/platform.d.ts +28 -0
- package/harbor/edge/storage.ts +82 -0
- package/harbor/edge/worker.ts +47 -0
- package/harbor/edge/wrangler.toml +21 -0
- package/harbor/files.ts +89 -0
- package/harbor/idb.ts +90 -0
- package/harbor/quo-harbor.md +403 -0
- package/human/dom.ts +21 -0
- package/human/html.ts +164 -0
- package/human/quo-human.md +86 -0
- package/human/screen.ts +76 -0
- package/human/tab.ts +84 -0
- package/mcp/agent.ts +94 -0
- package/mcp/http.ts +96 -0
- package/mcp/oauth.ts +260 -0
- package/mcp/pilot.ts +73 -0
- package/mcp/quo-mcp.md +262 -0
- package/mcp/runner.ts +131 -0
- package/mcp/server.ts +67 -0
- package/mcp/web/exchange.ts +146 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Razvan Gherghina
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# The dock
|
|
2
|
+
|
|
3
|
+
What every estate on Quo needs and nobody writes twice: a daemon and the
|
|
4
|
+
`quo` command, the front desk, the user being and the avatar, harbors on
|
|
5
|
+
disk, in a tab and on the edge, the model sides and the screen, the
|
|
6
|
+
credential exchange. An estate is all of one owner's harbors, and it is
|
|
7
|
+
built on the dock, on Quo.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @quo-systems/dock
|
|
11
|
+
npx quo init
|
|
12
|
+
npx quo serve
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`beings/quo-dock.md` is the truth of this package and the trunk of its four
|
|
16
|
+
documents; read it first. It knows nothing the spec of Quo does not say,
|
|
17
|
+
and adds no word to harbor, ward or being.
|
|
18
|
+
|
|
19
|
+
## Publishing
|
|
20
|
+
|
|
21
|
+
Published from 0.1.0 with no compatibility promise before 1.0.0. The
|
|
22
|
+
package ships an emitted `dist/` with its command, and the source beside it.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Apache-2.0. Copyright 2026 Razvan Gherghina. See [LICENSE](LICENSE) and
|
|
27
|
+
[NOTICE](NOTICE).
|
package/beings/avatar.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The avatar. Someone outside Quo's voice: a human at a screen, a model at
|
|
3
|
+
// an MCP client, a model in an API loop. One class for every side. She holds
|
|
4
|
+
// exactly one standing, `user`, and everything her side asks goes through
|
|
5
|
+
// it; the user being reaches her only to push, and she hands the push to
|
|
6
|
+
// every side she has. A side is in-process with her, holds the object, and
|
|
7
|
+
// calls the three methods below. Nothing of a side is in her cells.
|
|
8
|
+
import { Being, isSilence, isWord, wordOf } from '@quo-systems/quo';
|
|
9
|
+
import type { Answer, Blueprint, Invitation, JsonObject, OccupantRecord, Wanted } from '@quo-systems/quo';
|
|
10
|
+
|
|
11
|
+
// Her one standing, and the id under which the user being pushes to her.
|
|
12
|
+
// Two ids for one far being, because standings and occupants share one
|
|
13
|
+
// namespace and a record holds one or the other.
|
|
14
|
+
export const USER = 'user';
|
|
15
|
+
export const PUSHER = 'user:push';
|
|
16
|
+
|
|
17
|
+
export class Avatar extends Being {
|
|
18
|
+
static override cells = { inbox: [] as JsonObject[] };
|
|
19
|
+
static override asks = {
|
|
20
|
+
notify: { description: 'a push from the user being', input: { type: 'object' }, for: (occ: OccupantRecord | undefined) => occ?.id === PUSHER },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Her sides' ears. One identity is one avatar for life, and two sessions
|
|
24
|
+
// of that identity are two sides on her at once, so a push goes to every
|
|
25
|
+
// ear present; each side adds its own on open and removes it on close.
|
|
26
|
+
// Dropped if there is none.
|
|
27
|
+
readonly ears = new Set<(object: JsonObject) => void>();
|
|
28
|
+
|
|
29
|
+
// ---- what the user being may ask her
|
|
30
|
+
|
|
31
|
+
notify(args: JsonObject) {
|
|
32
|
+
(this.cells.inbox as JsonObject[]).push(args);
|
|
33
|
+
for (const ear of this.ears) ear(args);
|
|
34
|
+
return { notified: true };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ---- what her side calls. Not asks: nobody reaches these through a door.
|
|
38
|
+
|
|
39
|
+
// The credential exchange's last step. `desk` is the desk's public
|
|
40
|
+
// invitation, `proof` is what the route produced. She knocks the desk as a
|
|
41
|
+
// stranger, gets an invitation the user being minted, and joins with it. A
|
|
42
|
+
// knock on a public invitation births nothing, so she holds no standing at
|
|
43
|
+
// the desk afterwards. If she already holds `user`, this is a reconnect and
|
|
44
|
+
// nothing is minted.
|
|
45
|
+
async enter(desk: Invitation, proof: JsonObject): Promise<Blueprint | { error: string }> {
|
|
46
|
+
if (this.standings[USER]) return this.tools();
|
|
47
|
+
const inv = await this.knock(desk, 'device', { proof });
|
|
48
|
+
if (isSilence(inv)) return { error: 'silence' };
|
|
49
|
+
if (isWord(inv)) return { error: wordOf(inv) };
|
|
50
|
+
if (!inv || typeof inv !== 'object' || Array.isArray(inv) || 'error' in inv) return (inv as { error: string }) ?? { error: 'no invitation' };
|
|
51
|
+
return this.join(inv as unknown as Invitation);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Knock with an invitation, hand the user being one back so she can push,
|
|
55
|
+
// and take her as `user`. The only moment a standing is born here.
|
|
56
|
+
async join(invitation: Invitation): Promise<Blueprint | { error: string }> {
|
|
57
|
+
if (this.standings[USER]) return this.tools();
|
|
58
|
+
const mine = await this.invite(PUSHER);
|
|
59
|
+
if (mine === null) return { error: 'user is taken' };
|
|
60
|
+
const out = await this.knock(invitation, 'hello', { invitation: mine as unknown as JsonObject });
|
|
61
|
+
if (isSilence(out) || isWord(out)) {
|
|
62
|
+
this.occupants.remove(PUSHER);
|
|
63
|
+
return { error: isSilence(out) ? 'silence' : wordOf(out) };
|
|
64
|
+
}
|
|
65
|
+
await this.take(USER, invitation);
|
|
66
|
+
return this.tools();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Her describe, as the user being shows it to her. This is the tool list.
|
|
70
|
+
async tools(): Promise<Blueprint | { error: string }> {
|
|
71
|
+
const st = this.standings[USER];
|
|
72
|
+
if (!st) return { error: 'not joined' };
|
|
73
|
+
const bp = await st.ask();
|
|
74
|
+
if (isSilence(bp) || isWord(bp)) return { error: isSilence(bp) ? 'silence' : wordOf(bp) };
|
|
75
|
+
return bp as Blueprint;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// One call from the side, one ask on the standing. The three words pass
|
|
79
|
+
// through untouched; the side renders them.
|
|
80
|
+
call(name: string, args: JsonObject = {}, wanted?: Wanted): Promise<Answer> {
|
|
81
|
+
const st = this.standings[USER];
|
|
82
|
+
return st ? st.ask(name, args, wanted) : Promise.resolve({ error: 'not joined' });
|
|
83
|
+
}
|
|
84
|
+
}
|
package/beings/desk.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The front desk. The one public being of a world, and public for the first
|
|
3
|
+
// hello only: everything after is behind an invitation. It holds a standing
|
|
4
|
+
// to every user being, placed by the root, and trades a proof for a device
|
|
5
|
+
// invitation that the user being mints herself. The desk never mints one.
|
|
6
|
+
//
|
|
7
|
+
// A proof is what a route produced after authenticating by its own means. A
|
|
8
|
+
// verifier turns a proof of one kind into who it is for: which user, which
|
|
9
|
+
// client identity. Verifiers are the device's, set on the class before boot
|
|
10
|
+
// the way an envoy reads a secret from the device: never through cells.
|
|
11
|
+
import { Being, isSilence, isWord, wordOf } from '@quo-systems/quo';
|
|
12
|
+
import type { Asker, Json, JsonObject } from '@quo-systems/quo';
|
|
13
|
+
|
|
14
|
+
export type Proof = { kind: string; [more: string]: Json };
|
|
15
|
+
export type Verified = { user: string; client: string; wake?: boolean };
|
|
16
|
+
export type Verifier = (proof: Proof) => Promise<Verified | null> | Verified | null;
|
|
17
|
+
|
|
18
|
+
export class Desk extends Being {
|
|
19
|
+
// proof kind -> verifier. The route that makes a proof kind registers the
|
|
20
|
+
// verifier for it; the desk knows no kind by itself.
|
|
21
|
+
static verifiers: Record<string, Verifier> = {};
|
|
22
|
+
|
|
23
|
+
static override asks = {
|
|
24
|
+
hello: { description: 'how to get in', input: { type: 'object' } },
|
|
25
|
+
device: { description: 'trade a proof for a device invitation', input: { type: 'object', properties: { proof: { type: 'object' } }, required: ['proof'] } },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
hello(_args: JsonObject, asker: Asker) {
|
|
29
|
+
return { desk: true, asker: asker.id ?? null, kinds: Object.keys(Desk.verifiers), users: Object.keys(this.cells.standings).filter((k) => k.startsWith('user:')).map((k) => k.slice(5)) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async device(args: JsonObject) {
|
|
33
|
+
const proof = args.proof;
|
|
34
|
+
if (!proof || typeof proof !== 'object' || Array.isArray(proof) || typeof proof.kind !== 'string') return { error: 'proof has a kind' };
|
|
35
|
+
const verify = Object.hasOwn(Desk.verifiers, proof.kind) ? Desk.verifiers[proof.kind] : undefined;
|
|
36
|
+
if (typeof verify !== 'function') return { error: 'no such proof kind' };
|
|
37
|
+
const who = await verify(proof as Proof);
|
|
38
|
+
if (!who) return { error: 'refused' };
|
|
39
|
+
const user = this.standings[`user:${who.user}`];
|
|
40
|
+
if (!user) return { error: 'no such user' };
|
|
41
|
+
const inv = await user.ask('device', who.wake === true ? { client: who.client, wake: true } : { client: who.client });
|
|
42
|
+
if (isSilence(inv)) return { error: 'silence' };
|
|
43
|
+
if (isWord(inv)) return { error: wordOf(inv) };
|
|
44
|
+
return inv;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/beings/index.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The beings every side shares. See quo-estate.md, the trunk.
|
|
3
|
+
export { User, DESK } from './user.ts';
|
|
4
|
+
export { Desk, type Proof, type Verified, type Verifier } from './desk.ts';
|
|
5
|
+
export { Avatar, USER, PUSHER } from './avatar.ts';
|