@yaks/host 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.
Files changed (69) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +306 -2
  3. package/_dist/anatomy.d.ts +35 -0
  4. package/_dist/anatomy.d.ts.map +1 -0
  5. package/_dist/assembly.d.ts +94 -0
  6. package/_dist/assembly.d.ts.map +1 -0
  7. package/_dist/config.d.ts +150 -0
  8. package/_dist/config.d.ts.map +1 -0
  9. package/_dist/documents.d.ts +9 -0
  10. package/_dist/documents.d.ts.map +1 -0
  11. package/_dist/facets.d.ts +164 -0
  12. package/_dist/facets.d.ts.map +1 -0
  13. package/_dist/keepers.d.ts +15 -0
  14. package/_dist/keepers.d.ts.map +1 -0
  15. package/_dist/keywords.d.ts +3 -0
  16. package/_dist/keywords.d.ts.map +1 -0
  17. package/_dist/lending.d.ts +34 -0
  18. package/_dist/lending.d.ts.map +1 -0
  19. package/_dist/mod.d.ts +260 -0
  20. package/_dist/mod.d.ts.map +1 -0
  21. package/_dist/payments.d.ts +501 -0
  22. package/_dist/payments.d.ts.map +1 -0
  23. package/_dist/roles.d.ts +10 -0
  24. package/_dist/roles.d.ts.map +1 -0
  25. package/_dist/senders.d.ts +180 -0
  26. package/_dist/senders.d.ts.map +1 -0
  27. package/_dist/words.d.ts +27 -0
  28. package/_dist/words.d.ts.map +1 -0
  29. package/anatomy.js +432 -0
  30. package/anatomy.js.map +1 -0
  31. package/anatomy.ts +439 -0
  32. package/assembly.js +737 -0
  33. package/assembly.js.map +1 -0
  34. package/assembly.ts +930 -0
  35. package/config.js +149 -0
  36. package/config.js.map +1 -0
  37. package/config.ts +287 -0
  38. package/deno.json +1 -0
  39. package/documents.js +80 -0
  40. package/documents.js.map +1 -0
  41. package/documents.ts +105 -0
  42. package/facets.js +2 -0
  43. package/facets.js.map +1 -0
  44. package/facets.ts +236 -0
  45. package/keepers.js +7 -0
  46. package/keepers.js.map +1 -0
  47. package/keepers.ts +17 -0
  48. package/keywords.js +24 -0
  49. package/keywords.js.map +1 -0
  50. package/keywords.ts +25 -0
  51. package/lending.js +46 -0
  52. package/lending.js.map +1 -0
  53. package/lending.ts +77 -0
  54. package/mod.js +5 -0
  55. package/mod.js.map +1 -0
  56. package/mod.ts +356 -0
  57. package/package.json +79 -4
  58. package/payments.js +66 -0
  59. package/payments.js.map +1 -0
  60. package/payments.ts +665 -0
  61. package/roles.js +22 -0
  62. package/roles.js.map +1 -0
  63. package/roles.ts +18 -0
  64. package/senders.js +58 -0
  65. package/senders.js.map +1 -0
  66. package/senders.ts +272 -0
  67. package/words.js +134 -0
  68. package/words.js.map +1 -0
  69. package/words.ts +210 -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,307 @@
1
- # Temporary Holding Version
1
+ # @yaks/host
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The portable assembly and capabilities a host lends the plugins it composes. A
4
+ **host** composes a graph and supplies its storage, vault, blobs, artifacts,
5
+ tools, effects, caller attribution and shutdown signal. The concrete host owns
6
+ connections, directories and resource lifetime; a plugin never receives a SQL
7
+ driver or a state directory.
8
+
9
+ A plugin factory receives a `Host` and its configured options. It keeps the host
10
+ reference when its graph or tools are still being assembled:
11
+
12
+ ```ts
13
+ import type { Host } from '@yaks/host'
14
+ import { equal } from '@yaks/testing'
15
+
16
+ let factory = (host: Pick<Host, 'stopping'>) => () => host.stopping.aborted
17
+ let stop = new AbortController()
18
+ let stopped = factory({ stopping: stop.signal })
19
+ equal(stopped(), false)
20
+ stop.abort()
21
+ equal(stopped(), true)
22
+ ```
23
+
24
+ | Export | Provides |
25
+ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26
+ | `@yaks/host` | `assembly`, facet contracts, `Host`, `Config`, `Configured`, `Options`, `Plug`, `Role`, `Feed`, `MigrationMonitor`, `Message`, `Receipt`, `Sender`, `ROLES`, `every` |
27
+ | `@yaks/host/assembly` | `assembly`, `prepare`, `assemble`, `Prepared`, `Assembly`, `AssemblyOpts`, `Binding`, `Meaning` |
28
+ | `@yaks/host/roles` | Role and facet selection data without loading the assembly runtime |
29
+ | `@yaks/host/senders` | `Message`, `Receipt`, `Sender`, `Built`, `afresh`, `Unsent`, `Undeliverable`, `Notice`, `Notices`, `Unsigned`, `Arrival`, `Incoming`, `MailDomains`, `MailDomain`, `DomainRecord` |
30
+ | `@yaks/host/lending` | `lending`, `Lends`: what plugins lend a host by name |
31
+ | `@yaks/host/payments` | `Payments`, `Plans`, `Shops`, `Door`, `Heard`, `Subscription`, `Checkout`, `Sale`, `Paid`, …: a payment provider's contract; `packed` and `unpacked`, a cart as it rides an order's `items` |
32
+ | `@yaks/host/words` | Vocabulary assembly, `wordsOf`, `taking`, `Words`, `Declared`, `Taken` |
33
+ | `@yaks/host/config` | Configuration types, `used`, `given`, `chosen`, `configured`, `revealed`, `holding`, `Reveal`, `meet`, `Unmet`, `numbering` |
34
+ | `@yaks/host/documents`, `@yaks/host/keywords` | Shared intrinsic declarations and vocabulary keywords |
35
+ | `@yaks/host/anatomy` | Composition evidence, projected when read |
36
+
37
+ ## Assembly
38
+
39
+ A **facet** is a plugin's subpath, such as `./vocab` or `./graph`. A **role**
40
+ selects the facets its process serves: `graph` loads vocabulary and graph hooks,
41
+ `web` loads routes and UI contributions, `effects` loads effect handlers, and a
42
+ plugin's own role loads its service. Tool implementations load on their first
43
+ call. `Load` supplies modules or `null` for a subpath a plugin does not export;
44
+ an import failure is an error.
45
+
46
+ `assembly(config, roles, load, opts)` loads those facets and builds their
47
+ vocabulary. Its `words` lets the concrete host prepare storage before
48
+ `bind(binding)` builds the graph, effect bindings, tools, runner and routes. The
49
+ returned services are handed to the host's scheduler. `Host.defer(release)`
50
+ registers plugin resource cleanup. The concrete host stops admission through
51
+ `Host.stopping`, drains effects and services, then awaits the binding's
52
+ `close()` before closing its graph or reporter. Cleanup runs once in reverse
53
+ registration order; a failed cleanup still lets the remaining cleanups run.
54
+
55
+ A host with synchronous transactions can call `prepare(config, roles, load)`
56
+ before opening storage, then `assemble(config, roles, load, prepared, opts)`
57
+ inside its transaction. `opts.words` supplies an already-loaded `Words` value
58
+ when the host shares its vocabulary with a schema plan. `wordsOf` accepts
59
+ `{ implicit: false, keywords }` to hold a graph to its explicit declarations and
60
+ keyword vocabularies. Graph facets supply hooks and rules; vocabulary facets and
61
+ graph-owned documents supply their declarations.
62
+
63
+ A config entry's `facets` restricts which subpaths its host imports, within the
64
+ roles it serves. `{ use: '@yaks/task', facets: ['vocab'] }` loads declarations
65
+ without graph hooks, effects or tool implementations. Omitted `facets` allows
66
+ every exported facet; `[]` imports none.
67
+
68
+ A config entry's `words` selects names from its plugin's vocabulary `$defs`,
69
+ including components, tools, rules and effects:
70
+ `{ use: '@yaks/task', words:
71
+ ['task', 'cancelled'] }`. Omitted `words` takes
72
+ every definition; `[]` takes none. An unknown name is an error. Selection
73
+ retains the plugin's keywords and computed-property factories. The host's
74
+ intrinsic machine, git and invocation definitions remain available where no
75
+ plugin supplies them.
76
+
77
+ `opts.docs` supplies the graph's own vocabulary documents. Its component
78
+ declarations replace plugin declarations and extensions of the same name;
79
+ extensions in `opts.docs` still add to plugin components. Duplicate plugin
80
+ declarations are errors even when the graph shadows that name.
81
+
82
+ The complete in-memory binding example runs in
83
+ [`assembly_example_test.ts`](./assembly_example_test.ts), where it binds the
84
+ host, writes a book through the graph and reads it back. The vocabulary plan is
85
+ prepared independently of those binding and graph operations.
86
+
87
+ ```ts
88
+ import { assembly } from '@yaks/host'
89
+
90
+ // const plan = await assembly(config, ['graph'], load, { docs })
91
+ // const { host } = plan.bind(binding) // host-supplied storage, effects and resources
92
+ // await host.graph.apply([{ entity: { eid: 'b' }, book: { title: 'Dune' } }])
93
+ ```
94
+
95
+ `Binding.storage` receives the host and a shared query-extension list. After
96
+ storage binds, the assembly adds plugin extensions, then `Binding.extend` adds
97
+ the host's own compilers. `Binding.install` prepares schema before graph-facet
98
+ installers run. `Binding.graph` can add the host's own hooks and graph options
99
+ around the contributed plugins. `Binding.clock` (an @yaks/fp `Clock`) is the
100
+ clock the graph and the tool runner keep, each its own when it is absent.
101
+ `Binding.ready` lends graph-dependent capabilities before effect factories run.
102
+ `Host.meaning` ranks words by meaning among what a filter line admits: the index
103
+ a plugin's graph facet offers, or one the binding lends in `Binding.host`, never
104
+ both. `Binding.search` combines the host's text search with it.
105
+
106
+ ## Storage capabilities
107
+
108
+ `Host.storage` is [graph storage](../graph/README.md#storage), not a particular
109
+ backend. SQL-backed storage may offer a
110
+ [statement capability](../sql/README.md#statement-capability) for indexes beside
111
+ the graph. It also may offer bound storage diagnostics and a migration monitor.
112
+ A plugin needing an absent capability reports that fact rather than guessing a
113
+ connection or a file location.
114
+
115
+ Storage is bound before query extensions are asked for. The graph, request
116
+ handler, tool runner and duties become available as composition builds each one.
117
+ Factories retain the host reference and use those parts only after their factory
118
+ returns.
119
+
120
+ ## Required plugins
121
+
122
+ A plugin can shape a store so that only it reads and writes the store's rows
123
+ correctly from then on: [@yaks/blob](../blob/README.md) keeps an address where a
124
+ body's text was. Its graph facet says so with `required(options)`, which may
125
+ depend on its options, so a plugin can require itself only under the option that
126
+ shapes its rows. `Assembly.required` names every plugin of a composition that
127
+ says so. A writing host records them in the store before it writes, and every
128
+ host, reading or writing, refuses a store whose recorded requirements its config
129
+ does not compose: `meet(config, requirements)` throws `Unmet`, a `CallError`
130
+ naming each plugin missing. A plugin listed with its `graph` facet left out is
131
+ not composed.
132
+
133
+ A plugin removed from a store on purpose leaves the config and drops its
134
+ requirement from the store, which for a SQLite store is one statement
135
+ ([@yaks/sqlite](../sqlite/README.md#the-plugins-a-store-requires)).
136
+
137
+ ## Workspaces and sandboxes
138
+
139
+ `Host.workspaces.connect(id)` opens an existing file-and-command workspace at
140
+ its recorded placement. It never chooses the graph server's directory.
141
+ `Host.sandboxes.request(id, request?)` records a sandbox intention before
142
+ provisioning; it requires an explicitly configured adapter or default provider.
143
+ Sandbox effects provision that intention. Missing configuration refuses rather
144
+ than creating a local directory. `Host.resolveHome(session)` may prepare a
145
+ configured native fixer's worktree independently of sandbox provisioning.
146
+
147
+ A session's `home{workspace, cwd}` is a default target, not a permission grant.
148
+ Changing it, stopping a session or closing a host does not dispose its
149
+ workspace. Explicit sandbox disposal stops execution and retains writable files
150
+ in recoverable trash; `sandbox_restore` returns the retained resource. See
151
+ [@yaks/machine](../machine/README.md) for execution and
152
+ [@yaks/sandbox](../sandbox/README.md) for lifecycle and adapter configuration.
153
+
154
+ ## Mail senders
155
+
156
+ `Host.senders` lends named
157
+ [senders](../mail/README.md#the-transport-is-supplied-by-the-caller).
158
+ `@yaks/mail` selects one with `sender: {via: name}` in its plugin options. The
159
+ host constructs its own and owns their credentials, metering and lifetime. A
160
+ provider plugin lends one too, from its graph facet's `senders(host, options)`,
161
+ built from its own options. One name has one sender: two parties lending a name
162
+ fail composition. `afresh(build)` (`@yaks/host/senders`) makes a sender that
163
+ builds again at every use, and says through `waiting()` why it cannot send yet,
164
+ so a letter waits for a credential instead of bouncing. `Message.id` is the
165
+ caller's letter UUID, for an asynchronous receipt. `Incoming` is a
166
+ provider-neutral letter with headers, text and attachments; its provider
167
+ supplies the receiving server's verdicts separately from the author's headers:
168
+ `verified` is DKIM, unset where nobody checked, and `vouched` is DMARC passing
169
+ for the From domain. The assembly passes this capability to plugin factories
170
+ through `Binding.host` or `Binding.ready`. A sender rejects with `Unsent`
171
+ (`@yaks/host/senders`) when the message certainly never left, so mail tries it
172
+ again instead of bouncing it, and with `Undeliverable` when its provider refused
173
+ an address on the letter, so mail bounces it as the letter's outcome rather than
174
+ a failure of the sender.
175
+
176
+ ```ts
177
+ import type { Host, Message } from '@yaks/host'
178
+ import { post } from '@yaks/mail/effects'
179
+ import { equal } from '@yaks/testing'
180
+
181
+ let sent: Message[] = []
182
+ let host: Pick<Host, 'senders'> = {
183
+ senders: {
184
+ platform: {
185
+ send: (message) => {
186
+ sent.push(message)
187
+ return Promise.resolve({ id: 'letter-1' })
188
+ },
189
+ },
190
+ },
191
+ }
192
+ let { sender } = post({ via: 'platform' }, host)
193
+ let receipt = await sender!.send({
194
+ from: 'hello@books.example',
195
+ to: 'ana@example.com',
196
+ subject: 'Friday',
197
+ text: 'Bring a dish.',
198
+ html: '<p>Bring a dish.</p>',
199
+ })
200
+ equal(receipt, { id: 'letter-1' })
201
+ equal(sent.map((message) => message.subject), ['Friday'])
202
+ ```
203
+
204
+ ## Hosts that route mail themselves
205
+
206
+ A host that composes no graph, such as a Worker, names its mail providers in a
207
+ config too, and asks their graph facets with `lending` (`@yaks/host/lending`)
208
+ for what each lends by name: `senders`, the `notices` readers of a provider's
209
+ signed word about a letter it carried (a `Notice`: the receipt, and the tags the
210
+ letter was sent with, which say whose it was, or the `letters` it received, as
211
+ `Incoming`s, for a provider that takes mail in by webhook), and the `arrivals`
212
+ that read a letter the runtime handed the host, in the runtime's own shape, as
213
+ an `Incoming`. A request its provider did not sign rejects as `Unsigned`. Its
214
+ `mailDomains` set a domain up for sending and receiving (`setup`), read the DNS
215
+ records it needs with whether each has `arrived` (`read`), and `remove` it, each
216
+ domain named by its domain name, never the provider's id for it. The host reads
217
+ each option a config writes as a reference through `configured(config,
218
+ reveal)`:
219
+ `{"secret": NAME}` and `{"binding": NAME}`, read when accessed; `holding(env)`
220
+ reads both from a Worker's env.
221
+
222
+ ## Embedders
223
+
224
+ `Host.embedders` lends named in-process embedders the same way:
225
+ `@yaks/embedding` selects one with `embedder: {provider: name, model, dim?}`,
226
+ and a provider plugin lends one from its graph facet's
227
+ `embedders(host, options)`, as `@yaks/model2vec` lends `model2vec`. An
228
+ `Embedding` makes an embedder from the `model` and `dim` a config names; the
229
+ embedder's `model` names its vector space, and nothing loads until its first
230
+ embed. One name has one embedder.
231
+
232
+ ## Texters
233
+
234
+ `Host.texters` lends named texters to @yaks/phone's `sender: {via}` the same
235
+ way: a provider plugin lends one from its graph facet's `texters(host, options)`
236
+ (@yaks/phone/plugin builds it), and a texter that cannot send yet says why
237
+ through `waiting()`.
238
+
239
+ ## Keepers
240
+
241
+ `Host.keepers` lends named keepers: places a key goes besides the graph's own
242
+ vault. A keeper puts a value at one of its own addresses (`keep(at, value)`),
243
+ and a provider plugin lends one from its graph facet's `keepers(host,
244
+ options)`.
245
+ Whoever asks for a key names where it goes as data, each place a keeper's name
246
+ and its address there (`@yaks/host/keepers` `Place`), and @yaks/connections
247
+ hands a pasted key to each; it names no keeper itself.
248
+
249
+ ## Payment providers
250
+
251
+ A host that takes money itself asks for `payments` the same way: a provider
252
+ plugin lends a `Payments` from its graph facet's `payments(host, options)`, its
253
+ `name` for the sentences people read, its `plans`, its `shops` and its webhook
254
+ `doors` (`@yaks/host/payments`), functions over its own wire that answer in
255
+ words naming no provider. `plans` mints a payer once, says whom it is billed to,
256
+ opens a hosted checkout for a tier by the month or year (with a trial for time
257
+ already given free) and a hosted portal, reads a subscription as
258
+ `{id, payer, tier, status, until,
259
+ ending, tags}` and moves its next charge. The
260
+ provider decides which tier a price buys and where a status stands (`standing`:
261
+ `paying`, `owing`, `lapsed` or `ended`); the host keeps its own rules over them.
262
+
263
+ `shops` is a party selling on an account of its own: it opens the account once
264
+ (`{account, ready, submitted}`, ready only once the provider lets it take
265
+ payments), answers the address of the provider's onboarding for it, opens a
266
+ hosted checkout on it for a sale (its lines, currency, the host's fee and the
267
+ tags that ride the checkout and its payment). The host keeps the fee, the cart
268
+ and the order.
269
+
270
+ `doors` are where the provider posts what happened, by name; a host serves each
271
+ at `/<via>/<name>`, `via` the name the provider is lent under. A door verifies
272
+ one request and answers what it heard (`{heard}`) or why it refused it
273
+ (`{refused, ours}`, `ours` where the host's own secret may be wrong), and
274
+ nothing where it holds no secret. What it heard is a `Heard` in the host's
275
+ words: a subscription changed (`about: 'subscription'`, the subscription read on
276
+ asking), or, on a seller's account, the seller changed, the seller revoked the
277
+ host, a checkout completed (`Paid`), or a payment was refunded, disputed, lost
278
+ or restored, its payment and tags read on asking. @yaks/stripe lends one.
279
+
280
+ ## Failure reporting
281
+
282
+ `Host.report(error, context)` hands a failure to the concrete host's reporter.
283
+ Context identifies the failing work through `during.entity`, `during.kind`,
284
+ `during.session` and `during.process`; `eid` preserves an occurrence's identity
285
+ across redelivery. The host owns delivery and shutdown, so plugins use its
286
+ reporter without opening a sink.
287
+
288
+ ```ts
289
+ import { equal } from '@yaks/testing'
290
+ import type { Host } from '@yaks/host'
291
+
292
+ let told: unknown[] = []
293
+ let host: Pick<Host, 'report'> = {
294
+ report: (error) => {
295
+ told.push(error)
296
+ },
297
+ }
298
+ await host.report?.('missing field', { during: { entity: 'work' } })
299
+ equal(told, ['missing field'])
300
+ ```
301
+
302
+ ## Concrete hosts
303
+
304
+ [@yaks/cli](../cli/README.md) opens the box's database and binds this interface.
305
+ Its caller owns shutdown and closing. This package imports no CLI, native
306
+ storage implementation or filesystem API. It owns the shared assembly and
307
+ contract; the box owns its loader, command line and resource provisioning.
@@ -0,0 +1,35 @@
1
+ import { type Anatomy, type AnatomyObservation, type AnatomySource } from "@yaks/code/anatomy";
2
+ import type { NamedTool, Plugin } from "@yaks/graph";
3
+ import type { Vocab, VocabDoc } from "@yaks/vocab";
4
+ export declare let secretNames: (source: unknown, seen?: Set<object>) => string[];
5
+ /** Evidence gathered during one composition, projected only when read. */ export type Composition = {
6
+ read: () => Anatomy;
7
+ observe: (observation: AnatomyObservation) => void;
8
+ attempted: (owner: string, name: string) => void;
9
+ loaded: (owner: string, name: string, present: boolean) => void;
10
+ binding: (owner: string, name: string) => void;
11
+ declarations: (docs: VocabDoc[], vocab: Vocab) => void;
12
+ graph: (owner: string, plugins: Plugin[]) => void;
13
+ graphed: () => void;
14
+ tier: (tools: NamedTool[], owner?: string) => void;
15
+ runs: (owner: string, names: string[], joined: string[]) => void;
16
+ effects: (handlers: Map<string, string>, serving: boolean) => void;
17
+ due: (names: string[]) => void;
18
+ routes: (owner: string, routes: {
19
+ method: string;
20
+ path: string;
21
+ }[]) => void;
22
+ };
23
+ /** Capture only already-made contributions; none of these methods runs code.
24
+ * What a composition observes is kept as it arrives and applied when its
25
+ * anatomy is read: projecting the vocabulary's declarations is tens of
26
+ * milliseconds of every command, and almost no command reads its anatomy.
27
+ * Package descriptors carry names and allowed facets, never resolved options.
28
+ * Repeated entries select the union of their facets. */ export declare let compositionAnatomy: (packages: {
29
+ name: string;
30
+ facets?: readonly string[];
31
+ }[], roles: readonly string[], common: Record<string, readonly string[]>, secrets?: {
32
+ name: string;
33
+ package: string;
34
+ }[], where?: Pick<AnatomySource, 'host' | 'scope'>) => Composition;
35
+ //# sourceMappingURL=anatomy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anatomy.d.ts","sources":["../anatomy.ts"],"names":[],"mappings":"AAEA,SACE,KAAK,OAAO,EAIZ,KAAK,kBAAkB,EAGvB,KAAK,aAAa,kCACkB;AACtC,cAAc,SAAS,EAAE,MAAM,2BAAgC;AAC/D,cAAc,KAAK,EAAE,QAAQ,2BAAgC;AAI7D,OAAO,YAAI,cACT,QAAQ,OAAO,EACf,OAAM,IAAI,MAAM,MACf,MAAM,GAaR;AAeD,wEAAwE,GACxE,YAAY;EACV,YAAY;EACZ,UAAU,aAAa,uBAAuB,IAAI;EAClD,YAAY,OAAO,MAAM,EAAE,MAAM,MAAM,KAAK,IAAI;EAChD,SAAS,OAAO,MAAM,EAAE,MAAM,MAAM,EAAE,SAAS,OAAO,KAAK,IAAI;EAC/D,UAAU,OAAO,MAAM,EAAE,MAAM,MAAM,KAAK,IAAI;EAC9C,eAAe,MAAM,YAAY,OAAO,UAAU,IAAI;EACtD,QAAQ,OAAO,MAAM,EAAE,SAAS,aAAa,IAAI;EACjD,eAAe,IAAI;EACnB,OAAO,OAAO,aAAa,QAAQ,MAAM,KAAK,IAAI;EAClD,OAAO,OAAO,MAAM,EAAE,OAAO,MAAM,IAAI,QAAQ,MAAM,OAAO,IAAI;EAChE,UAAU,UAAU,IAAI,MAAM,EAAE,MAAM,GAAG,SAAS,OAAO,KAAK,IAAI;EAClE,MAAM,OAAO,MAAM,OAAO,IAAI;EAC9B,SAAS,OAAO,MAAM,EAAE;IAAU,QAAQ,MAAM;IAAE,MAAM,MAAM;UAAS,IAAI;;AAG7E;;;;;sDAKsD,GACtD,OAAO,YAAI,qBACT;EAAY,MAAM,MAAM;EAAE,kBAAkB,MAAM;KAClD,gBAAgB,MAAM,IACtB,QAAQ,OAAO,MAAM,WAAW,MAAM,KACtC;EAAW,MAAM,MAAM;EAAE,SAAS,MAAM;KACxC,QAAO,KAAK,eAAe,SAAS,aAInC,YAsWF"}
@@ -0,0 +1,94 @@
1
+ /** Assemble a graph from role-selected facets and capabilities lent by its host. */ import type { Actor, Bundle, Comp, Graph, GraphBranches, NamedTool } from "@yaks/graph";
2
+ import { type graph } from "@yaks/graph";
3
+ import { type Clock } from "@yaks/fp";
4
+ import { type Search } from "@yaks/graph/tools";
5
+ import type { runner } from "@yaks/tools";
6
+ import type { VocabDoc } from "@yaks/vocab";
7
+ import type { Effects } from "@yaks/effects";
8
+ import { type Operation } from "@yaks/effects/invocation";
9
+ import type { Extension, History, Stmt } from "@yaks/sql";
10
+ import type { Host, Role } from "./mod.js";
11
+ import { type Config, type Configured, type Options } from "./config.js";
12
+ import type { Duty, Load } from "./facets.js";
13
+ import { type Composition } from "./anatomy.js";
14
+ import { type Taken, type Words } from "./words.js";
15
+ /** The parts built from facets, rather than lent by a concrete host. */ type Built = 'anatomy' | 'observe' | 'config' | 'roles' | 'vocab' | 'derived' | 'storage' | 'graph' | 'fx' | 'ui' | 'who' | 'feed' | 'handler' | 'routes' | 'filters' | 'tools' | 'registry' | 'search' | 'reply' | 'runner' | 'defer';
16
+ /** Storage and runtime capabilities; the assembly owns neither their IO nor lifetime. */ export type Binding = {
17
+ host: Omit<Host, Built>;
18
+ storage: (host: Host, extend: Extension[], words: Words, history?: History) => Host['storage'];
19
+ effects: (host: Host, disabled: string[]) => Effects;
20
+ /** The concrete host's implementations of callable effects. */ operations?: (host: Host) => Record<string, Operation>;
21
+ /** Host clause compilers follow the plugins' compilers. */ extend?: (host: Host) => Extension[];
22
+ /** Construct the graph with any additional hooks and options the host owns. */ graph?: typeof graph;
23
+ /** The branches of the host's store, each with the graph its own host
24
+ * composes over it (@yaks/graph `GraphBranches`), asked once the store is
25
+ * bound. */ branches?: (host: Host) => GraphBranches | undefined;
26
+ /** Suppress the assembled plugins' post-commit effects on a branch.
27
+ * Observers attached to the bound graph can still see its commits. */ unobserved?: boolean;
28
+ /** Bring the store to its composed schema, given the statements the graph
29
+ * plugins need beside the store's own, after extensions have bound and
30
+ * before graph plugins are asked. A reader leaves it out. */ schema?: (host: Host, stmts: Stmt[]) => void;
31
+ /** The host's graph-dependent capabilities, before effect and tool factories. */ ready?: (host: Host) => void;
32
+ /** Combine the host's text index with its meaning index, where it has one
33
+ * ({@link Host.meaning}). */ search?: (host: Host) => Search | undefined;
34
+ /** Operations supplied by the concrete host beside graph and plugin tools. */ tools?: {
35
+ package: string;
36
+ offer: (host: Host) => NamedTool[];
37
+ /** What the offer is made from: the registry and its runner are made
38
+ * again when it moves. */ revision?: () => unknown;
39
+ /** Whether the graph's generic tools are offered beside it (they are by
40
+ * default). A host whose callers reach the graph through doors of its own
41
+ * offers only its own and its plugins'. */ generic?: boolean;
42
+ };
43
+ /** How the host's runner runs calls, beside what the assembly gives it:
44
+ * the graph its records are written through, where that is not the host's
45
+ * (a store whose door guards what it is sent records calls as itself),
46
+ * which calls are its to run, and where its failures go. */ calls?: (host: Host) => {
47
+ records?: Graph;
48
+ takes?: (call: Bundle) => boolean;
49
+ report?: (error: unknown, call: Bundle, tool?: string) => unknown;
50
+ };
51
+ actor?: Actor | null;
52
+ process?: Comp;
53
+ readOnly?: boolean;
54
+ /** The clock the host keeps: its graph's and its runner's (default each
55
+ * one's own). */ clock?: Clock;
56
+ /** Per-host capabilities added to a configured occurrence's options. */ options?: (plugin: string, options: Options) => Options;
57
+ /** Loading and binding evidence belongs to this host, never the shared plan. */ observed?: Composition;
58
+ };
59
+ export type Assembly = {
60
+ words: Words;
61
+ /** The plugins whose graph facet says, under its options, that a store this
62
+ * host writes requires it (GraphFacet `required`): what a writing host
63
+ * records in the store beside its schema. */ required: string[];
64
+ /** Bind the loaded facets to the host's capabilities. Services are returned for its scheduler. */ bind: (binding: Binding) => {
65
+ host: Host;
66
+ services: Duty[];
67
+ /** Interrupt calls already admitted by this host, without constructing a runner. */ interrupt: (why: string) => Promise<Bundle[]>;
68
+ /** Await after draining admitted work, before closing graph or reporter. */ close: () => Promise<void>;
69
+ };
70
+ };
71
+ export type AssemblyOpts = {
72
+ /** Read factories admit no imperative work; loaded before binding. */ readOnly?: boolean;
73
+ /** Resolved plugin options, when the concrete host has a vault. */ plugins?: Configured[];
74
+ /** Already-loaded vocabulary, shared with the concrete host's schema plan. */ words?: Words;
75
+ /** The graph's own vocabulary. Its component declarations shadow plugins. */ docs?: VocabDoc[];
76
+ observed?: Composition;
77
+ part?: (name: string) => void;
78
+ };
79
+ /** The role-selected modules, loaded before a host opens its transaction. */ export type Prepared = {
80
+ vocab: Taken<'vocab'>;
81
+ graph: Taken<'graph'>;
82
+ effects: Taken<'effects'>;
83
+ routes: Taken<'routes'>;
84
+ ui: Taken<'ui'>;
85
+ service: Taken<'service'>;
86
+ factories: {
87
+ graph: typeof graph;
88
+ runner: typeof runner;
89
+ };
90
+ };
91
+ /** Import only the facets a host serves; binding the result performs no imports. */ export declare let prepare: (config: Config, roles: readonly Role[], load: Load, opts?: AssemblyOpts) => Promise<Prepared>;
92
+ /** Pure assembly of imported facets; its binding runs inside the host's transaction. */ export declare let assemble: (config: Config, roles: readonly Role[], load: Load, prepared: Prepared, opts?: AssemblyOpts) => Assembly;
93
+ /** Load only the roles served, then assemble once the host can lend storage. */ export declare let assembly: (config: Config, roles: readonly Role[], load: Load, opts?: AssemblyOpts) => Promise<Assembly>;
94
+ //# sourceMappingURL=assembly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assembly.d.ts","sources":["../assembly.ts"],"names":[],"mappings":"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"}