@yaks/tunnel 0.0.0-stage → 0.2.36
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/README.md +319 -2
- package/_dist/cloudflare.d.ts +38 -0
- package/_dist/cloudflare.d.ts.map +1 -0
- package/_dist/effects.d.ts +37 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/filter.d.ts +68 -0
- package/_dist/filter.d.ts.map +1 -0
- package/_dist/gateway.d.ts +14 -0
- package/_dist/gateway.d.ts.map +1 -0
- package/_dist/hosted.d.ts +101 -0
- package/_dist/hosted.d.ts.map +1 -0
- package/_dist/mod.d.ts +5 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/routes.d.ts +31 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/service.d.ts +24 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/cloudflare.js +170 -0
- package/cloudflare.js.map +1 -0
- package/cloudflare.ts +233 -0
- package/deno.json +1 -0
- package/effects.js +103 -0
- package/effects.js.map +1 -0
- package/effects.ts +143 -0
- package/filter.js +95 -0
- package/filter.js.map +1 -0
- package/filter.ts +128 -0
- package/gateway.js +37 -0
- package/gateway.js.map +1 -0
- package/gateway.ts +46 -0
- package/hosted.js +345 -0
- package/hosted.js.map +1 -0
- package/hosted.ts +496 -0
- package/mod.js +15 -0
- package/mod.js.map +1 -0
- package/mod.ts +35 -0
- package/package.json +45 -4
- package/routes.js +94 -0
- package/routes.js.map +1 -0
- package/routes.ts +144 -0
- package/service.js +119 -0
- package/service.js.map +1 -0
- package/service.ts +164 -0
- package/vocab.js +16 -0
- package/vocab.js.map +1 -0
- package/vocab.json +62 -0
- package/vocab.ts +17 -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 Jeff Peterson
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,320 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/tunnel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@yaks/tunnel` gives a hosted space a tunnel to a machine without opening a port
|
|
4
|
+
on it. The space's apps reach the paths the machine opens to them, on its own
|
|
5
|
+
server, and nothing else on that machine or its network.
|
|
6
|
+
|
|
7
|
+
Three Cloudflare resources make the tunnel:
|
|
8
|
+
|
|
9
|
+
- a **Cloudflare Tunnel**, the machine's own outbound connection. `cloudflared`
|
|
10
|
+
runs on the machine with the tunnel's token and dials Cloudflare, so the
|
|
11
|
+
machine needs no public address and no open port.
|
|
12
|
+
- a **Workers VPC Service**, one host and port behind that tunnel: the machine's
|
|
13
|
+
server. A Worker bound to it reaches exactly that service, whatever URL it
|
|
14
|
+
fetches.
|
|
15
|
+
- a **gateway**, the one Worker bound to that service. It lives in the hosting
|
|
16
|
+
platform's dispatch namespace, so only the platform calls it, and it marks
|
|
17
|
+
every request it passes on with `x-yak-tunnel`, over whatever the request
|
|
18
|
+
said. An app never holds the binding: it asks the platform, and the platform
|
|
19
|
+
decides.
|
|
20
|
+
|
|
21
|
+
On the machine, the server's **filter** answers a marked request only at the
|
|
22
|
+
paths the machine opened to the tunnel, and refuses the rest (403) before any
|
|
23
|
+
route sees them. A marked request is also never one of the machine's own
|
|
24
|
+
callers: it writes as the persona the machine names for the tunnel, and is
|
|
25
|
+
offered only the tools the machine lists. The dedicated VPC listener sets the
|
|
26
|
+
mark at ingress; the ordinary listener continues serving local requests.
|
|
27
|
+
|
|
28
|
+
The platform also says who is asking, in `x-yak-caller`: its own word for the
|
|
29
|
+
kind of caller, set on every request it hands the gateway and taken off whatever
|
|
30
|
+
a caller sent. The machine opens a path, a tool or a persona to every request
|
|
31
|
+
through the tunnel, or only to the callers it names
|
|
32
|
+
([Who is asking](#who-is-asking)).
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
deno add jsr:@yaks/tunnel
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Entry points:
|
|
39
|
+
|
|
40
|
+
- `@yaks/tunnel`: the account calls (`connect`, `disconnect`, `tunnels`,
|
|
41
|
+
`services`, `gateways`), the tunnel's two ends (`GATEWAY`, `HEADER`, `CALLER`,
|
|
42
|
+
`filter`, `opens`, `offered`, `named`) and the vocabulary.
|
|
43
|
+
- `@yaks/tunnel/hosted`: the hosting platform's end: the door its spaces' owners
|
|
44
|
+
make and change a tunnel at, who may reach a machine through one, and the
|
|
45
|
+
request as it goes on to the gateway ([Hosting tunnels](#hosting-tunnels)).
|
|
46
|
+
- `@yaks/tunnel/routes`: what a machine's server puts in front of its routes:
|
|
47
|
+
the filter over the paths its config opens, who a request through the tunnel
|
|
48
|
+
writes as, and the tools it is offered.
|
|
49
|
+
- `@yaks/tunnel/service`: the connector, which keeps `cloudflared` running for
|
|
50
|
+
as long as its role runs.
|
|
51
|
+
- `@yaks/tunnel/vocab`: `tunnel{id, service, adopted}` and its
|
|
52
|
+
`tunnel_trashed{at}` mark.
|
|
53
|
+
|
|
54
|
+
## Making a tunnel
|
|
55
|
+
|
|
56
|
+
```ts ignore
|
|
57
|
+
import { connect, disconnect, gateways } from '@yaks/tunnel'
|
|
58
|
+
|
|
59
|
+
let api = { account: ACCOUNT_ID, token: API_TOKEN }
|
|
60
|
+
let uploader = { account: ACCOUNT_ID, token: WORKERS_TOKEN }
|
|
61
|
+
let { tunnel, service, token } = await connect(api, 'my-box', { port: 5173 })
|
|
62
|
+
await gateways(uploader, 'my-namespace').put('tunnel-ada', service)
|
|
63
|
+
// ... later
|
|
64
|
+
await gateways(uploader, 'my-namespace').remove('tunnel-ada')
|
|
65
|
+
await disconnect(api, { tunnel, service })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`connect` makes the tunnel, then the service behind it on `127.0.0.1` at the
|
|
69
|
+
port given (the machine's server), or at `host` when the server listens
|
|
70
|
+
elsewhere on the machine's network. If the service cannot be made, the tunnel is
|
|
71
|
+
removed again, so a failure leaves nothing in the account. `disconnect` removes
|
|
72
|
+
both; a resource that is already gone is not an error.
|
|
73
|
+
|
|
74
|
+
`gateways(api, namespace).put(name, service)` uploads the gateway in front of
|
|
75
|
+
the service into a Workers for Platforms dispatch namespace; putting it again
|
|
76
|
+
replaces it. The platform reaches it with its dispatch binding
|
|
77
|
+
(`env.DISPATCH.get(name)`) once it has decided an app may reach the machine.
|
|
78
|
+
|
|
79
|
+
`tunnels(api).rotate(id)` gives the tunnel a new secret and answers its new
|
|
80
|
+
token. A connector already running keeps its connection until it restarts; a
|
|
81
|
+
connector holding the old token cannot open a new one.
|
|
82
|
+
|
|
83
|
+
The API token the tunnel and service calls are made with needs **Cloudflare
|
|
84
|
+
Tunnel Write** and the **Connectivity Directory Admin** role. The one a gateway
|
|
85
|
+
is uploaded with needs **Workers Scripts Edit** and **Connectivity Directory
|
|
86
|
+
Bind**. An account holds at most 1,000 VPC Services.
|
|
87
|
+
|
|
88
|
+
## Hosting tunnels
|
|
89
|
+
|
|
90
|
+
`@yaks/tunnel/hosted` is what a platform that hosts spaces answers about their
|
|
91
|
+
tunnels, whatever it runs on. The platform lends it what only it knows: who is
|
|
92
|
+
asking and where they stand, the account and the gateways' namespace, where the
|
|
93
|
+
record is written, and the one call that hands a request to a space's gateway (a
|
|
94
|
+
`Relay`, which answers null for a tunnel with no gateway and throws for a
|
|
95
|
+
machine that did not answer). yaks.app's is a Workers for Platforms dispatch
|
|
96
|
+
binding.
|
|
97
|
+
|
|
98
|
+
```ts ignore
|
|
99
|
+
import { door, machine, reach } from '@yaks/tunnel/hosted'
|
|
100
|
+
|
|
101
|
+
let answer = await door(req, keeping) // GET ?space=ada, POST do=connect …
|
|
102
|
+
let fromApp = await reach(req, '/tunneled/mail/inbound', {
|
|
103
|
+
space,
|
|
104
|
+
app,
|
|
105
|
+
itself: true,
|
|
106
|
+
}, relay)
|
|
107
|
+
let box = machine(space, owner, { caller: 'connector' }, relay)
|
|
108
|
+
await box('http://machine/mcp')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- `door` is the platform's door onto a space's tunnel (`/api/tunnel` on
|
|
112
|
+
yaks.app). A GET answers the space's tunnel to its owner. A POST changes it:
|
|
113
|
+
`connect` with the machine's `port` makes the pair and its gateway and answers
|
|
114
|
+
the token once, `rotate` puts the gateway again with a new token for a pair
|
|
115
|
+
the platform made. `disconnect` puts the pair in the trash with its names
|
|
116
|
+
held, removing only the generated gateway. `restore` reconnects that pair, and
|
|
117
|
+
`purge` asks its owner to permanently remove it through the shared
|
|
118
|
+
confirmation page. `adopt` records a pair made elsewhere. The space’s owner
|
|
119
|
+
changes it; adopting names the platform's own resources, so only the
|
|
120
|
+
platform's owner does it. `tell` is the machine telling its owner what changed
|
|
121
|
+
there (`@yaks/tunnel/effects`, the `tunnel_tell` effect), by their own
|
|
122
|
+
connection to the platform: it names the conversation it is news for and the
|
|
123
|
+
knock that says it, and the platform takes it in (yaks.app's Operator hears it
|
|
124
|
+
on its `machine` channel).
|
|
125
|
+
- `reach` is an app's own worker asking for its space's machine, at a path under
|
|
126
|
+
`TUNNELED`. Only the app itself does, never its visitor, and only an app built
|
|
127
|
+
in the space (`barred`): an installed copy's code was written elsewhere.
|
|
128
|
+
- `machine` is the space's owner asking with no app between, as their connector
|
|
129
|
+
or their Operator, which reaches only its own space's machine (`owners`).
|
|
130
|
+
- Either way the request goes on (`onward`) with the platform's own headers
|
|
131
|
+
taken off and `x-yak-caller` put on, and `x-via`, `x-yak-with` and `x-yak-by`
|
|
132
|
+
where the owner's Operator says them. Every way a request fails to arrive is
|
|
133
|
+
an answer: `no_tunnel` (404), `no_gateway` (503) and `unreached` (502).
|
|
134
|
+
|
|
135
|
+
## The token is a credential
|
|
136
|
+
|
|
137
|
+
Whoever holds a tunnel's token can run the tunnel. `connect` and `rotate` hand
|
|
138
|
+
it to their caller and never log or keep it; the caller puts it in a vault. On
|
|
139
|
+
the machine, the connector passes it to `cloudflared` in the environment
|
|
140
|
+
(`TUNNEL_TOKEN`), never on the command line, so no process listing shows it.
|
|
141
|
+
|
|
142
|
+
## The machine's end
|
|
143
|
+
|
|
144
|
+
A config names the paths the tunnel opens, and the tunnel's token as a secret
|
|
145
|
+
read from the vault:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"plugins": [
|
|
150
|
+
{
|
|
151
|
+
"use": "@yaks/api",
|
|
152
|
+
"with": {
|
|
153
|
+
"listeners": [{
|
|
154
|
+
"port": 5174,
|
|
155
|
+
"hostname": "127.0.0.1",
|
|
156
|
+
"headers": { "x-yak-tunnel": "1" }
|
|
157
|
+
}]
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"use": "@yaks/tunnel",
|
|
162
|
+
"with": {
|
|
163
|
+
"token": { "secret": "TUNNEL_TOKEN" },
|
|
164
|
+
"routes": ["/mail/inbound"]
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Point the VPC service at this dedicated port, rather than the ordinary local
|
|
172
|
+
listener. Every request arriving there receives the tunnel mark before any route
|
|
173
|
+
or policy sees it, even if it bypassed the gateway or supplied a different mark.
|
|
174
|
+
Both listeners stop and restart together.
|
|
175
|
+
|
|
176
|
+
`routes` are URLPattern pathnames (`/mail/inbound`, `/hooks/*`), and none opens
|
|
177
|
+
nothing: `/apply` and `/query` stay closed to the tunnel unless the machine's
|
|
178
|
+
owner lists them. The filter is the `web` role's, so it stands in front of every
|
|
179
|
+
route of the process that serves HTTP.
|
|
180
|
+
|
|
181
|
+
### Who is asking
|
|
182
|
+
|
|
183
|
+
`routes`, `tools` and `persona` at the top of the config are what every request
|
|
184
|
+
through the tunnel gets, and any app built in the space can send one. What only
|
|
185
|
+
one kind of caller gets goes under `callers`, by the platform's word for it:
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"use": "@yaks/tunnel",
|
|
190
|
+
"with": {
|
|
191
|
+
"routes": ["/mail/inbound"],
|
|
192
|
+
"callers": {
|
|
193
|
+
"operator": {
|
|
194
|
+
"routes": ["/mcp", "/model/step"],
|
|
195
|
+
"tools": ["task_list", "task_update", "graph_query"],
|
|
196
|
+
"persona": "N-153900"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
yaks.app says one of three words:
|
|
204
|
+
|
|
205
|
+
| `x-yak-caller` | who is asking |
|
|
206
|
+
| -------------- | ------------------------------------------------------------------------ |
|
|
207
|
+
| `app` | an app's own worker, built in the tunnel's space |
|
|
208
|
+
| `operator` | the Operator of the space's owner, in a conversation or a run of its own |
|
|
209
|
+
| `connector` | the owner's own assistant, signed in to yaks.app, calling `command` |
|
|
210
|
+
|
|
211
|
+
A caller named under `callers` is answered at its paths and everyone's, is
|
|
212
|
+
offered its tools and everyone's, and writes as its own persona, or everyone's
|
|
213
|
+
where it names none. A request saying no word, or one the config names nothing
|
|
214
|
+
for, gets what everyone does. So a path that reads the machine's graph or spends
|
|
215
|
+
its owner's subscription belongs under `callers`, never at the top.
|
|
216
|
+
|
|
217
|
+
### Tools through the tunnel
|
|
218
|
+
|
|
219
|
+
A hosted assistant uses the machine's tools by opening `/mcp` (@yaks/mcp) and
|
|
220
|
+
saying which tools the tunnel offers and who its callers are:
|
|
221
|
+
|
|
222
|
+
```json
|
|
223
|
+
{
|
|
224
|
+
"use": "@yaks/tunnel",
|
|
225
|
+
"with": {
|
|
226
|
+
"callers": {
|
|
227
|
+
"operator": {
|
|
228
|
+
"routes": ["/mcp"],
|
|
229
|
+
"tools": ["task_list", "task_update", "graph_query"],
|
|
230
|
+
"persona": "N-153900"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- `tools` are the only tools a request through the tunnel is listed or may call,
|
|
238
|
+
by name, and none offers nothing. A call to any other is answered as a call to
|
|
239
|
+
a tool that does not exist. The hosted side can narrow this list and cannot
|
|
240
|
+
widen it. A hosted model reads mail and web pages that strangers wrote, so
|
|
241
|
+
leave off any tool that starts an agent or runs a command.
|
|
242
|
+
- `persona` is the persona every request through the tunnel writes as (`by`),
|
|
243
|
+
named by eid, number or name. Without one such a request writes as nobody.
|
|
244
|
+
Where an opened path instructs its callers (`/mcp` at `initialize`), such a
|
|
245
|
+
request is told that persona's text first, composed as `yak persona read`
|
|
246
|
+
composes it (`told`), so a hosted Operator knows what the persona holds.
|
|
247
|
+
- The request names the conversation it comes from in `x-via`. The machine keeps
|
|
248
|
+
one session standing for each (`session{persona, source}`, its eid derived
|
|
249
|
+
from the conversation's id; @yaks/session `standIn`), and what the request
|
|
250
|
+
writes is stamped `via` that session. `source` is the conversation's id where
|
|
251
|
+
that is an eid. A request naming none speaks through one session kept for the
|
|
252
|
+
tunnel.
|
|
253
|
+
|
|
254
|
+
Whatever a request through the tunnel names in `x-via`, it never speaks as one
|
|
255
|
+
of the machine's own sessions, and never as the machine's person. Nor does an
|
|
256
|
+
argument it sends: a tool's `by` (`decision_answer`, `design_decide`), which
|
|
257
|
+
asks for a mark recorded as somebody else's, is dropped from a write through the
|
|
258
|
+
tunnel's session (@yaks/session `attributing`), and the answer is `decided.by`
|
|
259
|
+
the caller's persona. Only [the owner's own words](#the-owners-own-words) are
|
|
260
|
+
recorded as the owner's.
|
|
261
|
+
|
|
262
|
+
### The owner's own words
|
|
263
|
+
|
|
264
|
+
One kind of request is the machine's person's own: a hosted assistant passing on
|
|
265
|
+
what its person wrote, word for word, where the platform read the words and who
|
|
266
|
+
wrote them itself. The platform then names that person in `x-yak-by`, by its own
|
|
267
|
+
id for them, and the machine's config says which of the platform's people is its
|
|
268
|
+
own:
|
|
269
|
+
|
|
270
|
+
```json
|
|
271
|
+
{
|
|
272
|
+
"use": "@yaks/tunnel",
|
|
273
|
+
"with": {
|
|
274
|
+
"callers": {
|
|
275
|
+
"operator": {
|
|
276
|
+
"routes": ["/mcp"],
|
|
277
|
+
"tools": ["comment_new", "decision_answer"],
|
|
278
|
+
"persona": "N-153900",
|
|
279
|
+
"owner": "3f0c9a52-6d1e-4b7a-9c58-2a4d7e61b0f3"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
- `owner` is the platform's id for the person the machine's config names as its
|
|
287
|
+
`person`. A request naming them in `x-yak-by` writes `by` that `person` and
|
|
288
|
+
`via` the machine's own process, as what they type at the machine's own page
|
|
289
|
+
does, and through no session. So a comment it writes reads as the person's
|
|
290
|
+
everywhere a graph tells a person's comment from an agent's.
|
|
291
|
+
- A request naming anybody else, or any at all where the config names no `owner`
|
|
292
|
+
or no `person`, is refused (403) and writes nothing.
|
|
293
|
+
- It is offered the same tools as its caller. Only the platform sets the header,
|
|
294
|
+
and takes it off whatever an app or a model sends.
|
|
295
|
+
|
|
296
|
+
### Model steps through the tunnel
|
|
297
|
+
|
|
298
|
+
A hosted space runs model steps on the machine's own providers by opening
|
|
299
|
+
`/model/step` (@yaks/model/step) to the caller that may spend them, which
|
|
300
|
+
[@yaks/harness](../harness/README.md#answering-another-hosts-model-steps)
|
|
301
|
+
answers from the providers its `serve` option names. The gateway hands back the
|
|
302
|
+
machine's answer as it arrives, so the reply streams to the platform piece by
|
|
303
|
+
piece.
|
|
304
|
+
|
|
305
|
+
With a token, the service runs `cloudflared` and starts it again whenever it
|
|
306
|
+
exits, after a pause that grows to a minute while it keeps failing. The machine
|
|
307
|
+
needs `cloudflared` on its `PATH`, or `cloudflared` in the options names the one
|
|
308
|
+
to run. A machine whose tunnel something else already runs leaves the token out,
|
|
309
|
+
and the service ends at once. Ending the role stops the connector.
|
|
310
|
+
|
|
311
|
+
## The record
|
|
312
|
+
|
|
313
|
+
`tunnel{id, service, adopted}` on an entity says which tunnel it reaches a
|
|
314
|
+
machine by and which VPC Service its gateway is bound to. `adopted` marks a pair
|
|
315
|
+
made elsewhere and only recorded here: purging it forgets the ids and leaves the
|
|
316
|
+
resources alone. `tunnel_trashed{at}` keeps the pair and its shared names while
|
|
317
|
+
disabling reach. It stays recoverable until restored or its owner confirms a
|
|
318
|
+
permanent purge. All three are written by the server, never by a client
|
|
319
|
+
(`stamped`, `wire: false`). A hosting platform keeps one on each space that has
|
|
320
|
+
a tunnel, and puts that space's gateway in front of its service.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** The account, and the token its calls are made with. */ export type Api = {
|
|
2
|
+
account: string;
|
|
3
|
+
token: string;
|
|
4
|
+
/** the fetch the calls go through; the global one when left out */ fetch?: (url: string, init: RequestInit) => Promise<Response>;
|
|
5
|
+
};
|
|
6
|
+
/** A tunnel as made: its id, and the token `cloudflared` runs it with. */ export type Made = {
|
|
7
|
+
id: string;
|
|
8
|
+
token: string;
|
|
9
|
+
};
|
|
10
|
+
/** A machine's pair: the tunnel, and the VPC Service behind it. */ export type Pair = {
|
|
11
|
+
tunnel: string;
|
|
12
|
+
service: string;
|
|
13
|
+
};
|
|
14
|
+
/** Where a VPC Service sends a Worker's requests: a port on the machine, and
|
|
15
|
+
* the address it listens on there (`127.0.0.1` unless said). */ export type Target = {
|
|
16
|
+
port: number;
|
|
17
|
+
host?: string;
|
|
18
|
+
};
|
|
19
|
+
/** The account's Cloudflare Tunnels, each run by `cloudflared` with its
|
|
20
|
+
* token and configured from the account rather than a file on the machine. */ export declare let tunnels: (api: Api) => any;
|
|
21
|
+
/** The account's Workers VPC Services, each one host and port behind one
|
|
22
|
+
* tunnel. */ export declare let services: (api: Api) => any;
|
|
23
|
+
/** The gateways in one dispatch namespace. */ export type Gateways = {
|
|
24
|
+
put: (name: string, service: string) => Promise<void>;
|
|
25
|
+
remove: (name: string) => Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
/** The gateways in front of tunnels: one Worker per tunnel in a Workers for
|
|
28
|
+
* Platforms dispatch namespace, where only the platform that owns the
|
|
29
|
+
* namespace can call it (./gateway.ts). */ export declare let gateways: (api: Api, namespace: string) => Gateways;
|
|
30
|
+
/**
|
|
31
|
+
* A machine's pair made: a tunnel, and a VPC Service behind it on `to`. Answers
|
|
32
|
+
* both ids and the token. A service that cannot be made takes its tunnel
|
|
33
|
+
* with it, so a failure leaves nothing behind in the account.
|
|
34
|
+
*/ export declare let connect: (api: Api, name: string, to: Target) => Promise<Pair & {
|
|
35
|
+
token: string;
|
|
36
|
+
}>;
|
|
37
|
+
/** A machine's pair removed: the service first, since it names the tunnel. */ export declare let disconnect: (api: Api, pair: Pair) => Promise<void>;
|
|
38
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sources":["../cloudflare.ts"],"names":[],"mappings":"AA0BA,wDAAwD,GACxD,YAAY;EACV,SAAS,MAAM;EACf,OAAO,MAAM;EACb,iEAAiE,GACjE,SAAS,KAAK,MAAM,EAAE,MAAM,gBAAgB,QAAQ;;AAGtD,wEAAwE,GACxE,YAAY;EAAS,IAAI,MAAM;EAAE,OAAO,MAAM;;AAE9C,iEAAiE,GACjE,YAAY;EAAS,QAAQ,MAAM;EAAE,SAAS,MAAM;;AAEpD;8DAC8D,GAC9D,YAAY;EAAW,MAAM,MAAM;EAAE,OAAO,MAAM;;AAyDlD;4EAC4E,GAC5E,OAAO,YAAI,UAAW,KAAK,YA6BzB;AAEF;WACW,GACX,OAAO,YAAI,WAAY,KAAK,YAmB1B;AAOF,4CAA4C,GAC5C,YAAY;EACV,MAAM,MAAM,MAAM,EAAE,SAAS,MAAM,KAAK,QAAQ,IAAI;EACpD,SAAS,MAAM,MAAM,KAAK,QAAQ,IAAI;;AAGxC;;yCAEyC,GACzC,OAAO,YAAI,WAAY,KAAK,KAAK,WAAW,MAAM,KAAG,SA4BpD;AAWD;;;;CAIC,GACD,OAAO,YAAI,UACT,KAAK,KACL,MAAM,MAAM,EACZ,IAAI,WACH,QAAQ;EAAS,OAAO,MAAM;GAShC;AAED,4EAA4E,GAC5E,OAAO,YAAI,aAAoB,KAAK,KAAK,MAAM,SAAO,QAAQ,IAAI,EAGjE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Handlers } from "@yaks/effects";
|
|
2
|
+
import type { Eid, Graph } from "@yaks/graph";
|
|
3
|
+
import type { Vault } from "@yaks/secrets";
|
|
4
|
+
/** What a config file can set for this facet, beside ./routes.ts's own. */ export type Options = {
|
|
5
|
+
/** the platform the tunnel's conversations are held on */ platform?: string;
|
|
6
|
+
/** which of the person's connections to it to speak as (its account) */ as?: string;
|
|
7
|
+
};
|
|
8
|
+
/** What a knock tells the platform: the conversation it is news for, the
|
|
9
|
+
* knock that names it, its words, and what it tells of, where it names one
|
|
10
|
+
* entity here (`knock{about}`), so an alert about it opens at its row. */ export type Told = {
|
|
11
|
+
conversation: string;
|
|
12
|
+
key: Eid;
|
|
13
|
+
text: string;
|
|
14
|
+
about?: Eid;
|
|
15
|
+
outcome?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Telling the platform one thing. */ export type Tell = (told: Told) => Promise<void>;
|
|
18
|
+
/** What this facet reads off the host: the graph, the vault the person's
|
|
19
|
+
* connection is kept in, and the person the config names. */ export type Hosting = {
|
|
20
|
+
graph: Pick<Graph, 'get' | 'apply' | 'read' | 'address'>;
|
|
21
|
+
vault: Vault;
|
|
22
|
+
config?: {
|
|
23
|
+
person?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** The platform a tunnel's conversations are held on, unless the config says
|
|
27
|
+
* another. */ export declare let PLATFORM: string;
|
|
28
|
+
/** Where the platform hears its machine. */ export declare let TELL: string;
|
|
29
|
+
/** What the knock `eid` tells the platform, or nothing where it is said
|
|
30
|
+
* already or is not at a session standing at this door for a conversation
|
|
31
|
+
* held with the machine's person (`session.person`). */ export declare let telling: (g: Pick<Graph, 'get'>, eid: Eid) => Promise<Told | undefined>;
|
|
32
|
+
/** Tell the platform what the knock `eid` says, and mark it said. */ export declare let tellOf: (g: Pick<Graph, 'get' | 'apply'>, tell: Tell, eid: Eid) => Promise<void>;
|
|
33
|
+
/** Telling the platform at `options.platform` as the config's person, through
|
|
34
|
+
* their connection to it. */ export declare let platformTell: (host: Hosting, options?: Options, fetching?: typeof fetch) => Tell;
|
|
35
|
+
export declare let platformReady: (host: Hosting, options: Options, tunnel: string) => Promise<void>;
|
|
36
|
+
/** The effect behind `tunnel_tell`. */ export declare let effects: (host: Hosting, options?: Options) => Handlers;
|
|
37
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sources":["../effects.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,6BAAkC;AACxD,cAA4B,GAAG,EAAE,KAAK,2BAAgC;AACtE,cAAc,KAAK,6BAAkC;AAIrD,yEAAyE,GACzE,YAAY;EACV,wDAAwD,GACxD,WAAW,MAAM;EACjB,sEAAsE,GACtE,KAAK,MAAM;;AAGb;;wEAEwE,GACxE,YAAY;EACV,cAAc,MAAM;EACpB,KAAK;EACL,MAAM,MAAM;EACZ,QAAQ;EACR,UAAU,MAAM;;AAGlB,oCAAoC,GACpC,YAAY,QAAQ,MAAM,SAAS,QAAQ,IAAI;AAE/C;2DAC2D,GAC3D,YAAY;EACV,OAAO,KAAK,OAAO,QAAQ,UAAU,SAAS;EAC9C,OAAO;EACP;IAAW,SAAS,MAAM;;;AAG5B;YACY,GACZ,OAAO,YAAI,iBAA6B;AAExC,0CAA0C,GAC1C,OAAO,YAAI,aAAoB;AAM/B;;sDAEsD,GACtD,OAAO,YAAI,UACT,GAAG,KAAK,OAAO,QACf,KAAK,QACJ,QAAQ,OAAO,SAAS,EAkB1B;AAED,mEAAmE,GACnE,OAAO,YAAI,SACT,GAAG,KAAK,OAAO,QAAQ,UACvB,MAAM,MACN,KAAK,QACJ,QAAQ,IAAI,EAKd;AAED;2BAC2B,GAC3B,OAAO,YAAI,eACT,MAAM,SACN,UAAS,SACT,kBAAiB,UAChB,KAC6D;AAEhE,OAAO,YAAI,gBACT,MAAM,SACN,SAAS,SACT,QAAQ,MAAM,KACb,QAAQ,IAAI,EAAwD;AA2BvE,qCAAqC,GACrC,OAAO,YAAI,UAAW,MAAM,SAAS,UAAS,YAAe,SAG3D"}
|