@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.
- package/LICENSE +202 -0
- package/README.md +306 -2
- package/_dist/anatomy.d.ts +35 -0
- package/_dist/anatomy.d.ts.map +1 -0
- package/_dist/assembly.d.ts +94 -0
- package/_dist/assembly.d.ts.map +1 -0
- package/_dist/config.d.ts +150 -0
- package/_dist/config.d.ts.map +1 -0
- package/_dist/documents.d.ts +9 -0
- package/_dist/documents.d.ts.map +1 -0
- package/_dist/facets.d.ts +164 -0
- package/_dist/facets.d.ts.map +1 -0
- package/_dist/keepers.d.ts +15 -0
- package/_dist/keepers.d.ts.map +1 -0
- package/_dist/keywords.d.ts +3 -0
- package/_dist/keywords.d.ts.map +1 -0
- package/_dist/lending.d.ts +34 -0
- package/_dist/lending.d.ts.map +1 -0
- package/_dist/mod.d.ts +260 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/payments.d.ts +501 -0
- package/_dist/payments.d.ts.map +1 -0
- package/_dist/roles.d.ts +10 -0
- package/_dist/roles.d.ts.map +1 -0
- package/_dist/senders.d.ts +180 -0
- package/_dist/senders.d.ts.map +1 -0
- package/_dist/words.d.ts +27 -0
- package/_dist/words.d.ts.map +1 -0
- package/anatomy.js +432 -0
- package/anatomy.js.map +1 -0
- package/anatomy.ts +439 -0
- package/assembly.js +737 -0
- package/assembly.js.map +1 -0
- package/assembly.ts +930 -0
- package/config.js +149 -0
- package/config.js.map +1 -0
- package/config.ts +287 -0
- package/deno.json +1 -0
- package/documents.js +80 -0
- package/documents.js.map +1 -0
- package/documents.ts +105 -0
- package/facets.js +2 -0
- package/facets.js.map +1 -0
- package/facets.ts +236 -0
- package/keepers.js +7 -0
- package/keepers.js.map +1 -0
- package/keepers.ts +17 -0
- package/keywords.js +24 -0
- package/keywords.js.map +1 -0
- package/keywords.ts +25 -0
- package/lending.js +46 -0
- package/lending.js.map +1 -0
- package/lending.ts +77 -0
- package/mod.js +5 -0
- package/mod.js.map +1 -0
- package/mod.ts +356 -0
- package/package.json +79 -4
- package/payments.js +66 -0
- package/payments.js.map +1 -0
- package/payments.ts +665 -0
- package/roles.js +22 -0
- package/roles.js.map +1 -0
- package/roles.ts +18 -0
- package/senders.js +58 -0
- package/senders.js.map +1 -0
- package/senders.ts +272 -0
- package/words.js +134 -0
- package/words.js.map +1 -0
- package/words.ts +210 -0
package/mod.ts
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// The portable contract a host lends every plugin. Concrete hosts own drivers,
|
|
2
|
+
// directories and resource lifetime; plugins see the graph and capabilities.
|
|
3
|
+
import type {
|
|
4
|
+
Bundle,
|
|
5
|
+
Eid,
|
|
6
|
+
Graph,
|
|
7
|
+
Lent,
|
|
8
|
+
NamedTool,
|
|
9
|
+
News,
|
|
10
|
+
Storage,
|
|
11
|
+
} from 'jsr:@yaks/graph@0.2.36'
|
|
12
|
+
import type { Search } from 'jsr:@yaks/graph@0.2.36/tools'
|
|
13
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
|
|
14
|
+
import type { Derived, Raw, Row, Statements, Stmt } from 'jsr:@yaks/sql@0.2.36'
|
|
15
|
+
import type {
|
|
16
|
+
Authenticate,
|
|
17
|
+
Filter,
|
|
18
|
+
Handler,
|
|
19
|
+
Offers,
|
|
20
|
+
Route,
|
|
21
|
+
Told,
|
|
22
|
+
} from 'jsr:@yaks/api@0.2.36'
|
|
23
|
+
import type { Anatomy, AnatomyObserver } from 'jsr:@yaks/code@0.2.36/anatomy'
|
|
24
|
+
import type { Contributions } from 'jsr:@yaks/ui@0.2.36/contributions'
|
|
25
|
+
import type { Blobs } from 'jsr:@yaks/blob@0.2.36'
|
|
26
|
+
import type { TextTail } from 'jsr:@yaks/file@0.2.36'
|
|
27
|
+
import type { Effects } from 'jsr:@yaks/effects@0.2.36'
|
|
28
|
+
import type { Vault } from 'jsr:@yaks/secrets@0.2.36'
|
|
29
|
+
import type { Finding, Registry, Reply, Runner } from 'jsr:@yaks/tools@0.2.36'
|
|
30
|
+
import type { Context } from 'jsr:@yaks/tracker@0.2.36/report'
|
|
31
|
+
import type { Config } from './config.ts'
|
|
32
|
+
import type { Meaning } from './facets.ts'
|
|
33
|
+
import type { Chatter, Sender, Texter } from './senders.ts'
|
|
34
|
+
import type { Keeper } from './keepers.ts'
|
|
35
|
+
export type {
|
|
36
|
+
Chat,
|
|
37
|
+
Chatter,
|
|
38
|
+
Message,
|
|
39
|
+
Receipt,
|
|
40
|
+
Sender,
|
|
41
|
+
Text,
|
|
42
|
+
Texter,
|
|
43
|
+
TextReceipt,
|
|
44
|
+
} from './senders.ts'
|
|
45
|
+
export type { Config, Configured, Options, Plug } from './config.ts'
|
|
46
|
+
export type Role = string
|
|
47
|
+
/** An embedder a plugin lends by name, made from what a config names: its
|
|
48
|
+
* `model` and `dim`. The embedder's `model` names its vector space, and
|
|
49
|
+
* making one loads nothing until its first embed, so asking for the space is
|
|
50
|
+
* free. */
|
|
51
|
+
export type Embedding = (
|
|
52
|
+
said: { model: string; dim?: number; context?: number; count?: number },
|
|
53
|
+
) => {
|
|
54
|
+
model: string
|
|
55
|
+
embed: (text: string) => Float32Array | Promise<Float32Array>
|
|
56
|
+
}
|
|
57
|
+
export type Feed = (each: (news: News) => void | Promise<void>) => () => void
|
|
58
|
+
/** Cooperative storage-change observation. The adapter owns any migration. */
|
|
59
|
+
export type MigrationMonitor = {
|
|
60
|
+
read: () => {
|
|
61
|
+
generation: number
|
|
62
|
+
migration: string
|
|
63
|
+
state: 'pending' | 'applied' | 'failed'
|
|
64
|
+
announced: number
|
|
65
|
+
notBefore: number
|
|
66
|
+
finished: number | null
|
|
67
|
+
error: string | null
|
|
68
|
+
} | undefined
|
|
69
|
+
ready: () => number
|
|
70
|
+
}
|
|
71
|
+
/** What every plugin factory is handed: the graph being assembled, the
|
|
72
|
+
* vocabulary of components and tools it holds, the store under it, the
|
|
73
|
+
* host capabilities and the configuration that named them. `storage`,
|
|
74
|
+
* `graph`, `handler`, `runner` and `duties` are live from the moment each is
|
|
75
|
+
* built — a factory may keep a reference and must not call it before it
|
|
76
|
+
* returns, since an `extend` factory runs before there is a store to read and
|
|
77
|
+
* a `runs` factory is asked for its tools before there is a runner to run
|
|
78
|
+
* them. */
|
|
79
|
+
export interface Host {
|
|
80
|
+
/** HTTP transport owned by this host; portable callers use standard fetch. */
|
|
81
|
+
fetch?: typeof fetch
|
|
82
|
+
/** Working directory on a host that has one. */
|
|
83
|
+
cwd?: () => string
|
|
84
|
+
/** Bounded reads of local logs on a host that can read them. */
|
|
85
|
+
tailText?: TextTail
|
|
86
|
+
/** Already-observed composition metadata; never imports a lazy facet. */
|
|
87
|
+
anatomy: () => Anatomy
|
|
88
|
+
/** Already-loaded metadata only; never triggers an import or a factory. */
|
|
89
|
+
observe?: AnatomyObserver
|
|
90
|
+
config: Config
|
|
91
|
+
/** the roles this process serves over the graph (the roles selected by composition): the
|
|
92
|
+
* facets it imported, and so what else is wired in below */
|
|
93
|
+
roles: readonly Role[]
|
|
94
|
+
vocab: Vocab
|
|
95
|
+
storage: Storage & {
|
|
96
|
+
statements?: Statements
|
|
97
|
+
/** a filter line → a statement selecting the ids of the entities it
|
|
98
|
+
* admits (@yaks/sqlite `screen`): what a search beside the graph is
|
|
99
|
+
* narrowed by */
|
|
100
|
+
screen?: (query: string) => Raw | null
|
|
101
|
+
migrations?: MigrationMonitor
|
|
102
|
+
checks?: {
|
|
103
|
+
storage: () => Finding[]
|
|
104
|
+
archetypes: (sample: number) => Finding[]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** where this graph's secrets are kept: the concrete host supplies private
|
|
108
|
+
* files, memory or an encrypted store. @yaks/secrets seals into it and a
|
|
109
|
+
* config's `{"secret": "NAME"}` is read from it. */
|
|
110
|
+
vault: Vault
|
|
111
|
+
/** where this graph keeps content-addressed text (@yaks/blob): a
|
|
112
|
+
* table in its own database — what a `store: blob` property is written to,
|
|
113
|
+
* and where @yaks/page keeps an archived page unless it names a directory */
|
|
114
|
+
blobs: Blobs
|
|
115
|
+
/** binary artifacts shared by the harness and the HTTP blob door */
|
|
116
|
+
artifacts: Blobs
|
|
117
|
+
/** Named mail senders this host lends, selected by @yaks/mail's
|
|
118
|
+
* `sender: {via}`. The host owns credentials, metering and lifetime. */
|
|
119
|
+
senders?: Readonly<Record<string, Sender>>
|
|
120
|
+
/** Named in-process embedders this host lends, selected by
|
|
121
|
+
* @yaks/embedding's `embedder: {provider}` (@yaks/model2vec lends one). */
|
|
122
|
+
embedders?: Readonly<Record<string, Embedding>>
|
|
123
|
+
/** Named texters this host lends, selected by @yaks/phone's
|
|
124
|
+
* `sender: {via}`. The host owns credentials, metering and lifetime. */
|
|
125
|
+
texters?: Readonly<Record<string, Texter>>
|
|
126
|
+
/** Named keepers this host lends: where a key goes besides the vault, as
|
|
127
|
+
* @yaks/connections' `connection.keep` names them (./keepers.ts). */
|
|
128
|
+
keepers?: Readonly<Record<string, Keeper>>
|
|
129
|
+
/** Named chatters this host lends, one per chat platform, selected by
|
|
130
|
+
* @yaks/chat's `chat_post` by the platform's name. The host owns which
|
|
131
|
+
* bot's credential each connection posts with. */
|
|
132
|
+
chatters?: Readonly<Record<string, Chatter>>
|
|
133
|
+
/** Resolve a named chatter on demand if none was lent at assembly. */
|
|
134
|
+
chatter?: (via: string) => Chatter | undefined | Promise<Chatter | undefined>
|
|
135
|
+
/** Explicit workspace execution bindings; never an implicit local default. */
|
|
136
|
+
workspaces?: import('jsr:@yaks/machine@0.2.36/targets').Workspaces
|
|
137
|
+
/** Default sandbox intentions; provisioning is the sandbox effect's work. */
|
|
138
|
+
sandboxes?: {
|
|
139
|
+
request: (
|
|
140
|
+
id: string,
|
|
141
|
+
request?: { provider?: string; from?: string; image?: string },
|
|
142
|
+
) => Promise<string>
|
|
143
|
+
}
|
|
144
|
+
/** Host preparation of the checkout a native session works in where its
|
|
145
|
+
* home names none: a fixer's, and that of a session holding a task. */
|
|
146
|
+
resolveHome?: (
|
|
147
|
+
session: string,
|
|
148
|
+
) => Promise<import('jsr:@yaks/graph@0.2.36').Comp | undefined>
|
|
149
|
+
/** every property the store reads through an expression rather than as
|
|
150
|
+
* stored, keyed `comp.prop` — a @yaks/blob body resolves its address to its
|
|
151
|
+
* text — so a plugin reading SQL directly reads what the store reads */
|
|
152
|
+
derived: Derived
|
|
153
|
+
graph: Graph
|
|
154
|
+
/** A web role answers what only reads its store beside its HTTP thread:
|
|
155
|
+
* `graph`'s reads, `search` and `meaning` go through it, the reads once it
|
|
156
|
+
* is `answering` (@yaks/graph `Lent`). */
|
|
157
|
+
reader?: Lent & {
|
|
158
|
+
/** Committed SQL reads on the reader's connection, when it offers SQL. */
|
|
159
|
+
statements?: { query: (statement: Stmt) => Row[] | Promise<Row[]> }
|
|
160
|
+
/** Run an admitted read-only tool on the reader's graph. */
|
|
161
|
+
tool?: (name: string, call: Bundle) => Promise<Bundle[]>
|
|
162
|
+
/** Draw a large reply's prose using the reader's graph. */
|
|
163
|
+
readable?: (answer: Bundle[]) => Promise<Bundle[]>
|
|
164
|
+
search?: Search
|
|
165
|
+
meaning?: Meaning
|
|
166
|
+
}
|
|
167
|
+
/** Warm a web host, once however often it is called, and settle when it is
|
|
168
|
+
* warm: what its routes make {@link early} is made, its reads answer as fast
|
|
169
|
+
* as the next, its main thread is watched, and its duty roles are covered.
|
|
170
|
+
* A server taking over a port warms before it listens; any other listens
|
|
171
|
+
* first (@yaks/api `serve`). It rejects with what kept the host from
|
|
172
|
+
* warming. Absent where there is nothing to warm. */
|
|
173
|
+
warm?: () => Promise<void>
|
|
174
|
+
/** Hand the host a make a route does ahead of its first request (a page
|
|
175
|
+
* and the script it loads): started first as the host warms, and not
|
|
176
|
+
* before the server listens. The rest of warming waits until each has
|
|
177
|
+
* settled, so the first page a person opens competes with none of it. */
|
|
178
|
+
early?: (make: () => Promise<unknown>) => void
|
|
179
|
+
/** the post-commit registry: what a commit owes, written down by every
|
|
180
|
+
* process (@yaks/effects), and the observers a plugin registers while one of
|
|
181
|
+
* its tools runs */
|
|
182
|
+
fx: Effects
|
|
183
|
+
/** every route of this host as one request handler — built by the listed
|
|
184
|
+
* plugin that hosts routes ({@link RoutesFacet.handler}, @yaks/api) in a
|
|
185
|
+
* process serving `web`, and absent anywhere else. Whether any process
|
|
186
|
+
* listens with it is the `serve` tool's business (@yaks/api). */
|
|
187
|
+
handler?: Handler
|
|
188
|
+
/** every HTTP route the listed plugins contributed, in the order the config
|
|
189
|
+
* names them. Gathered only by a process serving `web` where a plugin
|
|
190
|
+
* hosts them: nothing else here answers a request. */
|
|
191
|
+
ui: Contributions
|
|
192
|
+
routes: Route[]
|
|
193
|
+
/** every filter the listed plugins put in front of those routes
|
|
194
|
+
* ({@link RoutesFacet.filter}), gathered where the routes are. */
|
|
195
|
+
filters: Filter[]
|
|
196
|
+
/** every tool declared across the plugins, joined to the code behind it,
|
|
197
|
+
* with this graph's own generic tier (@yaks/graph `tier`) first. One list: a
|
|
198
|
+
* command line runs it, and a transport that lists tools lists it. Built on
|
|
199
|
+
* first access, including an anatomy read that describes the tools. */
|
|
200
|
+
tools: NamedTool[]
|
|
201
|
+
/** Runtime provider catalogs shared by discovery and the runner. */
|
|
202
|
+
registry: Registry
|
|
203
|
+
/** Calls to another graph, supplied by a host with accounts. Mixed auth
|
|
204
|
+
* also admits tools the remote host offers signed out. */
|
|
205
|
+
remote?: (
|
|
206
|
+
name: string,
|
|
207
|
+
args: Record<string, unknown>,
|
|
208
|
+
options?: { as?: string; via?: string; url?: string; mixedAuth?: boolean },
|
|
209
|
+
) => Promise<Bundle[]>
|
|
210
|
+
/** Read authenticated JSON from another origin without exposing credentials. */
|
|
211
|
+
readJson?: (url: string | URL, options?: { via?: string }) => Promise<unknown>
|
|
212
|
+
/** ranked text search over this graph, where its vocabulary marks a property
|
|
213
|
+
* `search: true` and @yaks/fts indexed it — what the tier's `search` tool
|
|
214
|
+
* answers with, and what a transport restating the tier asks for. */
|
|
215
|
+
search?: Search
|
|
216
|
+
/** Read into memory what the plugins' reads would otherwise read from disk
|
|
217
|
+
* each time ({@link GraphFacet.preload}). A process that answers many reads
|
|
218
|
+
* (a read worker) runs it before its first; a command that reads once never
|
|
219
|
+
* does. Absent where no plugin preloads. */
|
|
220
|
+
preload?: () => Promise<void>
|
|
221
|
+
/** words ranked by meaning over this graph's vectors, where it keeps them:
|
|
222
|
+
* the index a plugin's graph facet offers (@yaks/embedding), or the one a
|
|
223
|
+
* concrete host lends. Absent where nothing embeds this graph's text. */
|
|
224
|
+
meaning?: Meaning
|
|
225
|
+
/** what a direct tool call is owed beside its answer, from every plugin
|
|
226
|
+
* that offers some : what {@link runner} adds, and
|
|
227
|
+
* what a runner of another's tools over this graph adds too (@yaks/harness).
|
|
228
|
+
* Absent where no plugin offers any. */
|
|
229
|
+
reply?: Reply
|
|
230
|
+
/** the one tool runner over this graph: what writes a `call` row, runs the
|
|
231
|
+
* function and writes the result back for recorded work. Direct read-only
|
|
232
|
+
* requests validate and answer without recording bookkeeping. Built on first
|
|
233
|
+
* access, or during assembly when the effects role needs its handlers. */
|
|
234
|
+
runner: Runner
|
|
235
|
+
/** Render a tool answer as plain text with this host's configured views.
|
|
236
|
+
* The answering tool's declaration decides how: a writing one (not
|
|
237
|
+
* `readOnly`) reads its answer back as it now stands, and a `page` one has
|
|
238
|
+
* a lone entity drawn whole; every other answer is a line per entity.
|
|
239
|
+
* `on` reads it back as the call read: on its `branch`, where it named one. */
|
|
240
|
+
text?: (
|
|
241
|
+
answer: Bundle[],
|
|
242
|
+
tool?: { readOnly?: boolean; page?: boolean },
|
|
243
|
+
on?: { branch?: number },
|
|
244
|
+
) => Promise<string>
|
|
245
|
+
/** A tool answer as its reader reads it, sent as data, printed or drawn:
|
|
246
|
+
* each eid in its prose drawn as the entity's id, where the answer or the
|
|
247
|
+
* small series this host holds in memory has it, else as its short handle
|
|
248
|
+
* (@yaks/tools/readable, @yaks/id/graph `held`). Absent, an answer is read
|
|
249
|
+
* as the tool gave it. */
|
|
250
|
+
readable?: (answer: Bundle[]) => Promise<Bundle[]>
|
|
251
|
+
/** The work this process does that nobody asked for: the effect pool where
|
|
252
|
+
* it serves `effects` (@yaks/effects `work` — any number of processes work
|
|
253
|
+
* it at once), and each plugin's `./service` where it serves that plugin.
|
|
254
|
+
* A service is taken under a lease named for its package (@yaks/effects
|
|
255
|
+
* `holding`), so of all the processes over one graph exactly one is running
|
|
256
|
+
* each — a second long-running process waits, and takes over when a killed
|
|
257
|
+
* holder's lease expires.
|
|
258
|
+
*
|
|
259
|
+
* The duty roles this host handed to a worker run there, under the
|
|
260
|
+
* same signal.
|
|
261
|
+
*
|
|
262
|
+
* Runs until `signal` aborts; left out, that signal is this host's own, so
|
|
263
|
+
* it stops with host shutdown. Pass an already-aborted signal for one
|
|
264
|
+
* pass each and no waiting. A command passing through never starts duties;
|
|
265
|
+
* a host that stays up calls the live form. `only` narrows a pass to the
|
|
266
|
+
* named duty roles. */
|
|
267
|
+
duties: (signal?: AbortSignal, only?: readonly Role[]) => Promise<void>
|
|
268
|
+
/** What host shutdown would have written for a process or a thread
|
|
269
|
+
* that will not write it itself: its calls ended as interrupted, saying
|
|
270
|
+
* `why`, its leases released, its `exit` stamped with no code. What this
|
|
271
|
+
* process writes for a thread of its own that it ended where it stood, or
|
|
272
|
+
* that failed (@yaks/threads), and a thread for itself when it is about to be
|
|
273
|
+
* ended so (@yaks/harness), so nobody waits out what it held. */
|
|
274
|
+
end: (holder: Eid, why: string) => Promise<void>
|
|
275
|
+
/** {@link Host.end} for each process on this machine that ended without
|
|
276
|
+
* closing (@yaks/process `vanished`). What a process about to stay up does
|
|
277
|
+
* before it reconciles (@yaks/api `serve`), so a crash leaves nothing held
|
|
278
|
+
* by the dead. Then it looks once more at every workspace process with no
|
|
279
|
+
* `exit` (@yaks/machine `overdue`), so one whose waiter stopped looking has
|
|
280
|
+
* its ending recorded. The worker does both on start and every hour.
|
|
281
|
+
* Answers the processes it closed. */
|
|
282
|
+
bury: () => Promise<Bundle[]>
|
|
283
|
+
/** Whether a lease's holder is over (@yaks/process `gone`): a process on
|
|
284
|
+
* this machine whose pid is gone, or one whose row records its `exit`, as a
|
|
285
|
+
* thread its process ended does. What a take asks before waiting out a
|
|
286
|
+
* holder's expiry (@yaks/effects `HoldOpts.gone`). */
|
|
287
|
+
gone: (holder: Eid) => Promise<boolean>
|
|
288
|
+
|
|
289
|
+
/** This process, as an entity (@yaks/process `started`): the row it wrote on
|
|
290
|
+
* the way in, what everything it writes is attributed to, and what a
|
|
291
|
+
* start-up effect compares against to tell its own creation from a child
|
|
292
|
+
* process's. */
|
|
293
|
+
me: Eid
|
|
294
|
+
/** who is calling — the answer every door over this graph gets, a command
|
|
295
|
+
* line and @yaks/api's endpoints alike, so what a caller writes is
|
|
296
|
+
* attributed to it (`signed` in @yaks/api) instead of to nobody. A request
|
|
297
|
+
* that came through a plugin's link (a tunnel) is whoever that link says
|
|
298
|
+
* ({@link RoutesFacet.arrived}), whatever run the request names. For every
|
|
299
|
+
* other request at most one plugin answers; where it names nobody, the
|
|
300
|
+
* answer is this host process itself (its writer). */
|
|
301
|
+
who: Authenticate
|
|
302
|
+
/** the tools this request is offered, by name, where the link it came
|
|
303
|
+
* through narrows them ({@link RoutesFacet.offers}); nothing for a request
|
|
304
|
+
* offered every tool. A door that lists or runs tools asks it (@yaks/mcp). */
|
|
305
|
+
offers?: Offers
|
|
306
|
+
/** what this request is told before a door's own instructions, where the
|
|
307
|
+
* link it came through says so ({@link RoutesFacet.told}): the text of the
|
|
308
|
+
* persona a tunnel's caller writes as. A door that instructs its callers
|
|
309
|
+
* asks it (@yaks/mcp). It never fails: a link that cannot say is reported
|
|
310
|
+
* ({@link report}) and tells nothing. */
|
|
311
|
+
told?: Told
|
|
312
|
+
/** Every commit another host makes to this store, as the patches it applied
|
|
313
|
+
* (@yaks/graph `News`): what a subscription registry or a cache over
|
|
314
|
+
* {@link graph} is fed so it sees the writes its graph's `effect` phase
|
|
315
|
+
* never ran for, and reads again what it holds when it missed some. Absent
|
|
316
|
+
* when no plugin offers one. */
|
|
317
|
+
feed?: Feed
|
|
318
|
+
/** This host shutting down, as one fact: aborted by host shutdown
|
|
319
|
+
* before the last transaction and before the database is closed. A plugin
|
|
320
|
+
* that arms a timer — a settle, a retry, a poll — hangs it off this signal,
|
|
321
|
+
* or its callback fires into a closed store and the process is held open by
|
|
322
|
+
* a timer nobody owns. The duties run under it too, so one abort
|
|
323
|
+
* stops everything this process was doing on its own. */
|
|
324
|
+
/** Report a failure through this host's telemetry, outside the graph.
|
|
325
|
+
* Context identifies the failing work; the host owns its sinks and lifetime. */
|
|
326
|
+
report?: (error: unknown, context?: Partial<Context>) => void | Promise<void>
|
|
327
|
+
stopping: AbortSignal
|
|
328
|
+
/** Release a plugin's resources after admitted work has drained, while the
|
|
329
|
+
* graph and reporter are still open. The concrete host awaits assembly.close. */
|
|
330
|
+
defer: (release: () => void | Promise<void>) => void
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export type {
|
|
334
|
+
Duty,
|
|
335
|
+
EffectsFacet,
|
|
336
|
+
FacetName,
|
|
337
|
+
Facets,
|
|
338
|
+
GraphFacet,
|
|
339
|
+
Load,
|
|
340
|
+
Meaning,
|
|
341
|
+
MeaningHit,
|
|
342
|
+
RoutesFacet,
|
|
343
|
+
ServiceFacet,
|
|
344
|
+
ToolsFacet,
|
|
345
|
+
VocabFacet,
|
|
346
|
+
} from './facets.ts'
|
|
347
|
+
export {
|
|
348
|
+
assemble,
|
|
349
|
+
type Assembly,
|
|
350
|
+
assembly,
|
|
351
|
+
type AssemblyOpts,
|
|
352
|
+
type Binding,
|
|
353
|
+
prepare,
|
|
354
|
+
type Prepared,
|
|
355
|
+
} from './assembly.js'
|
|
356
|
+
export { every, ROLES } from './roles.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/host",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/host",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./assembly": {
|
|
12
|
+
"types": "./_dist/assembly.d.ts",
|
|
13
|
+
"default": "./assembly.js"
|
|
14
|
+
},
|
|
15
|
+
"./roles": {
|
|
16
|
+
"types": "./_dist/roles.d.ts",
|
|
17
|
+
"default": "./roles.js"
|
|
18
|
+
},
|
|
19
|
+
"./senders": {
|
|
20
|
+
"types": "./_dist/senders.d.ts",
|
|
21
|
+
"default": "./senders.js"
|
|
22
|
+
},
|
|
23
|
+
"./keepers": {
|
|
24
|
+
"types": "./_dist/keepers.d.ts",
|
|
25
|
+
"default": "./keepers.js"
|
|
26
|
+
},
|
|
27
|
+
"./words": {
|
|
28
|
+
"types": "./_dist/words.d.ts",
|
|
29
|
+
"default": "./words.js"
|
|
30
|
+
},
|
|
31
|
+
"./config": {
|
|
32
|
+
"types": "./_dist/config.d.ts",
|
|
33
|
+
"default": "./config.js"
|
|
34
|
+
},
|
|
35
|
+
"./documents": {
|
|
36
|
+
"types": "./_dist/documents.d.ts",
|
|
37
|
+
"default": "./documents.js"
|
|
38
|
+
},
|
|
39
|
+
"./keywords": {
|
|
40
|
+
"types": "./_dist/keywords.d.ts",
|
|
41
|
+
"default": "./keywords.js"
|
|
42
|
+
},
|
|
43
|
+
"./anatomy": {
|
|
44
|
+
"types": "./_dist/anatomy.d.ts",
|
|
45
|
+
"default": "./anatomy.js"
|
|
46
|
+
},
|
|
47
|
+
"./lending": {
|
|
48
|
+
"types": "./_dist/lending.d.ts",
|
|
49
|
+
"default": "./lending.js"
|
|
50
|
+
},
|
|
51
|
+
"./payments": {
|
|
52
|
+
"types": "./_dist/payments.d.ts",
|
|
53
|
+
"default": "./payments.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"license": "Apache-2.0",
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@yaks/api": "0.2.36",
|
|
59
|
+
"@yaks/blob": "0.2.36",
|
|
60
|
+
"@yaks/code": "0.2.36",
|
|
61
|
+
"@yaks/edge": "0.2.36",
|
|
62
|
+
"@yaks/effects": "0.2.36",
|
|
63
|
+
"@yaks/file": "0.2.36",
|
|
64
|
+
"@yaks/fp": "0.2.36",
|
|
65
|
+
"@yaks/fts": "0.2.36",
|
|
66
|
+
"@yaks/git": "0.2.36",
|
|
67
|
+
"@yaks/graph": "0.2.36",
|
|
68
|
+
"@yaks/id": "0.2.36",
|
|
69
|
+
"@yaks/machine": "0.2.36",
|
|
70
|
+
"@yaks/names": "0.2.36",
|
|
71
|
+
"@yaks/sandbox": "0.2.36",
|
|
72
|
+
"@yaks/secrets": "0.2.36",
|
|
73
|
+
"@yaks/sql": "0.2.36",
|
|
74
|
+
"@yaks/tools": "0.2.36",
|
|
75
|
+
"@yaks/tracker": "0.2.36",
|
|
76
|
+
"@yaks/ui": "0.2.36",
|
|
77
|
+
"@yaks/vocab": "0.2.36"
|
|
78
|
+
},
|
|
79
|
+
"description": "The portable capabilities a host lends the plugins it composes.",
|
|
80
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
81
|
+
}
|
package/payments.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** What a payment provider lends a host that takes money through it (the
|
|
2
|
+
* lending kind `payments`, ./lending.ts): its name, for the sentences people
|
|
3
|
+
* read, the plans it sells a party, the shops a party sells through on an
|
|
4
|
+
* account of its own, and the webhook doors it hears both at. Each is
|
|
5
|
+
* functions over the provider's own wire, answering in words that name no
|
|
6
|
+
* provider, so a host's billing keeps its rules and refusals and a second
|
|
7
|
+
* provider has one contract to meet. */ /** One line of a cart: which product, how many, and its variant. */ /** The items as they ride the checkout and come back on the event: the product,
|
|
8
|
+
* how many, and the variant, in the shortest form that survives a round
|
|
9
|
+
* trip. They ride one tag, so its length is what decides how many lines fit
|
|
10
|
+
* in an order. Dashes come off the uuid to buy back four
|
|
11
|
+
* characters a line: a uuid without them is 32 characters and a line about
|
|
12
|
+
* 45. */ export let packed = (items)=>JSON.stringify(items.map((i)=>({
|
|
13
|
+
p: i.product.replace(/-/g, ''),
|
|
14
|
+
q: i.qty,
|
|
15
|
+
...i.options ? {
|
|
16
|
+
o: i.options
|
|
17
|
+
} : {}
|
|
18
|
+
})));
|
|
19
|
+
/** The cart read back out of a checkout's tags — {@link packed}, undone.
|
|
20
|
+
* Junk answers an empty list rather than throwing: an order whose items cannot
|
|
21
|
+
* be read is still an order somebody paid for, and losing the money over the
|
|
22
|
+
* label would be the worse mistake. */ export let unpacked = (items)=>{
|
|
23
|
+
try {
|
|
24
|
+
let out = JSON.parse(String(items ?? '[]'));
|
|
25
|
+
return (Array.isArray(out) ? out : []).map((i)=>({
|
|
26
|
+
product: String(i.p ?? '').replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, '$1-$2-$3-$4-$5'),
|
|
27
|
+
qty: Number(i.q ?? 1),
|
|
28
|
+
...i.o ? {
|
|
29
|
+
options: String(i.o)
|
|
30
|
+
} : {}
|
|
31
|
+
}));
|
|
32
|
+
} catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/** What a provider keeps of a card payment of `cents`: its rate, rounded to
|
|
37
|
+
* the nearest cent, plus its fixed amount, never more than the payment.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { charged } from '@yaks/host/payments'
|
|
41
|
+
* import { equal } from '@yaks/testing'
|
|
42
|
+
* let card = { bps: 290, cents: 30 }
|
|
43
|
+
* equal(charged(card, 2000), 88)
|
|
44
|
+
* equal(charged(card, 1999), 88)
|
|
45
|
+
* equal(charged(card, 10), 10)
|
|
46
|
+
* ```
|
|
47
|
+
*/ export let charged = (card, cents)=>Math.min(cents, Math.round(cents * card.bps / 10_000) + card.cents);
|
|
48
|
+
/** What a payer adds to `cents` so that what the provider keeps of the whole
|
|
49
|
+
* ({@link charged}) leaves the seller `cents`: the least that does.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { charged, covering } from '@yaks/host/payments'
|
|
53
|
+
* import { equal } from '@yaks/testing'
|
|
54
|
+
* let card = { bps: 290, cents: 30 }
|
|
55
|
+
* equal(covering(card, 10000), 330)
|
|
56
|
+
* equal(10330 - charged(card, 10330) >= 10000, true)
|
|
57
|
+
* equal(10329 - charged(card, 10329) < 10000, true)
|
|
58
|
+
* equal(covering(card, 2500), 106)
|
|
59
|
+
* ```
|
|
60
|
+
*/ export let covering = (card, cents)=>{
|
|
61
|
+
let whole = Math.ceil((cents + card.cents) / (1 - card.bps / 10_000)) - 1;
|
|
62
|
+
while(whole - charged(card, whole) < cents)whole++;
|
|
63
|
+
while(whole > cents && whole - 1 - charged(card, whole - 1) >= cents)whole--;
|
|
64
|
+
return whole - cents;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=payments.js.map
|
package/payments.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sources":["./payments.ts"],"names":[],"mappings":"AAAA;;;;;;sCAMsC,GAEtC,kEAAkE,GAGlE;;;;;OAKO,GACP,OAAO,IAAI,SAAS,CAAC,QACnB,KAAK,SAAS,CACZ,MAAM,GAAG,CAAC,CAAC,IAAM,CAAC;MAChB,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM;MAC3B,GAAG,EAAE,GAAG;MACR,GAAI,EAAE,OAAO,GAAG;QAAE,GAAG,EAAE,OAAO;MAAC,IAAI,CAAC,CAAC;IACvC,CAAC,IACF;AAEH;;;qCAGqC,GACrC,OAAO,IAAI,WAAW,CAAC;EACrB,IAAI;IACF,IAAI,MAAM,KAAK,KAAK,CAAC,OAAO,SAAS;IAKrC,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,IAAM,CAAC;QACjD,SAAS,OAAO,EAAE,CAAC,IAAI,IAAI,OAAO,CAChC,qCACA;QAEF,KAAK,OAAO,EAAE,CAAC,IAAI;QACnB,GAAI,EAAE,CAAC,GAAG;UAAE,SAAS,OAAO,EAAE,CAAC;QAAE,IAAI,CAAC,CAAC;MACzC,CAAC;EACH,EAAE,OAAM;IACN,OAAO,EAAE;EACX;AACF,EAAC;AAmeD;;;;;;;;;;;CAWC,GACD,OAAO,IAAI,UAAU,CACnB,MACA,QACW,KAAK,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,QAAQ,KAAK,GAAG,GAAG,UAAU,KAAK,KAAK,EAAC;AAEhF;;;;;;;;;;;;CAYC,GACD,OAAO,IAAI,WAAW,CAAC,MAAqB;EAC1C,IAAI,QAAQ,KAAK,IAAI,CAAC,CAAC,QAAQ,KAAK,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,GAAG,MAAM,KAAK;EACxE,MAAO,QAAQ,QAAQ,MAAM,SAAS,MAAO;EAC7C,MAAO,QAAQ,SAAS,QAAQ,IAAI,QAAQ,MAAM,QAAQ,MAAM,MAAO;EACvE,OAAO,QAAQ;AACjB,EAAC"}
|