@yaks/session 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 +1392 -2
- package/_dist/admission.d.ts +15 -0
- package/_dist/admission.d.ts.map +1 -0
- package/_dist/announce.d.ts +17 -0
- package/_dist/announce.d.ts.map +1 -0
- package/_dist/answer.d.ts +200 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/append.d.ts +10 -0
- package/_dist/append.d.ts.map +1 -0
- package/_dist/archive.d.ts +6 -0
- package/_dist/archive.d.ts.map +1 -0
- package/_dist/asks.d.ts +11 -0
- package/_dist/asks.d.ts.map +1 -0
- package/_dist/audit.d.ts +15 -0
- package/_dist/audit.d.ts.map +1 -0
- package/_dist/bounce.d.ts +19 -0
- package/_dist/bounce.d.ts.map +1 -0
- package/_dist/bus.d.ts +8 -0
- package/_dist/bus.d.ts.map +1 -0
- package/_dist/cache.d.ts +45 -0
- package/_dist/cache.d.ts.map +1 -0
- package/_dist/child-notice.d.ts +6 -0
- package/_dist/child-notice.d.ts.map +1 -0
- package/_dist/children.d.ts +59 -0
- package/_dist/children.d.ts.map +1 -0
- package/_dist/cli.d.ts +8 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/comp.d.ts +9 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/compact.d.ts +19 -0
- package/_dist/compact.d.ts.map +1 -0
- package/_dist/conversation.d.ts +158 -0
- package/_dist/conversation.d.ts.map +1 -0
- package/_dist/cost.d.ts +13 -0
- package/_dist/cost.d.ts.map +1 -0
- package/_dist/deferred.d.ts +79 -0
- package/_dist/deferred.d.ts.map +1 -0
- package/_dist/ended.d.ts +27 -0
- package/_dist/ended.d.ts.map +1 -0
- package/_dist/files.d.ts +73 -0
- package/_dist/files.d.ts.map +1 -0
- package/_dist/fork.d.ts +23 -0
- package/_dist/fork.d.ts.map +1 -0
- package/_dist/graft.d.ts +33 -0
- package/_dist/graft.d.ts.map +1 -0
- package/_dist/graph.d.ts +14 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/handoff.d.ts +29 -0
- package/_dist/handoff.d.ts.map +1 -0
- package/_dist/imported.d.ts +63 -0
- package/_dist/imported.d.ts.map +1 -0
- package/_dist/intake.d.ts +43 -0
- package/_dist/intake.d.ts.map +1 -0
- package/_dist/joined.d.ts +35 -0
- package/_dist/joined.d.ts.map +1 -0
- package/_dist/lease.d.ts +21 -0
- package/_dist/lease.d.ts.map +1 -0
- package/_dist/lines.d.ts +13 -0
- package/_dist/lines.d.ts.map +1 -0
- package/_dist/mod.d.ts +107 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/naming.d.ts +10 -0
- package/_dist/naming.d.ts.map +1 -0
- package/_dist/native.d.ts +13 -0
- package/_dist/native.d.ts.map +1 -0
- package/_dist/parts.d.ts +145 -0
- package/_dist/parts.d.ts.map +1 -0
- package/_dist/plugin.d.ts +33 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +67 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/prose.d.ts +7 -0
- package/_dist/prose.d.ts.map +1 -0
- package/_dist/providers.d.ts +36 -0
- package/_dist/providers.d.ts.map +1 -0
- package/_dist/reach.d.ts +39 -0
- package/_dist/reach.d.ts.map +1 -0
- package/_dist/react.d.ts +236 -0
- package/_dist/react.d.ts.map +1 -0
- package/_dist/readers.d.ts +221 -0
- package/_dist/readers.d.ts.map +1 -0
- package/_dist/reap.d.ts +21 -0
- package/_dist/reap.d.ts.map +1 -0
- package/_dist/recall.d.ts +32 -0
- package/_dist/recall.d.ts.map +1 -0
- package/_dist/routes.d.ts +15 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/run.d.ts +81 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/service.d.ts +131 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/source.d.ts +9 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/start.d.ts +29 -0
- package/_dist/start.d.ts.map +1 -0
- package/_dist/state.d.ts +75 -0
- package/_dist/state.d.ts.map +1 -0
- package/_dist/status.d.ts +38 -0
- package/_dist/status.d.ts.map +1 -0
- package/_dist/tail.d.ts +121 -0
- package/_dist/tail.d.ts.map +1 -0
- package/_dist/timing.d.ts +9 -0
- package/_dist/timing.d.ts.map +1 -0
- package/_dist/told.d.ts +17 -0
- package/_dist/told.d.ts.map +1 -0
- package/_dist/tools.d.ts +41 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/transcript.d.ts +5 -0
- package/_dist/transcript.d.ts.map +1 -0
- package/_dist/turn.d.ts +49 -0
- package/_dist/turn.d.ts.map +1 -0
- package/_dist/unknown.d.ts +6 -0
- package/_dist/unknown.d.ts.map +1 -0
- package/_dist/views.d.ts +9 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +9 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/wait.d.ts +15 -0
- package/_dist/wait.d.ts.map +1 -0
- package/_dist/wake.d.ts +116 -0
- package/_dist/wake.d.ts.map +1 -0
- package/_dist/watch.d.ts +52 -0
- package/_dist/watch.d.ts.map +1 -0
- package/_dist/who.d.ts +84 -0
- package/_dist/who.d.ts.map +1 -0
- package/_dist/window.d.ts +43 -0
- package/_dist/window.d.ts.map +1 -0
- package/admission.js +137 -0
- package/admission.js.map +1 -0
- package/admission.ts +164 -0
- package/announce.js +123 -0
- package/announce.js.map +1 -0
- package/announce.ts +126 -0
- package/answer.js +372 -0
- package/answer.js.map +1 -0
- package/answer.ts +426 -0
- package/append.js +125 -0
- package/append.js.map +1 -0
- package/append.ts +205 -0
- package/archive.js +62 -0
- package/archive.js.map +1 -0
- package/archive.ts +62 -0
- package/asks.js +80 -0
- package/asks.js.map +1 -0
- package/asks.ts +106 -0
- package/attempt.js +46 -0
- package/attempt.js.map +1 -0
- package/attempt.ts +60 -0
- package/audit.js +57 -0
- package/audit.js.map +1 -0
- package/audit.ts +65 -0
- package/bounce.js +29 -0
- package/bounce.js.map +1 -0
- package/bounce.ts +34 -0
- package/bus.js +568 -0
- package/bus.js.map +1 -0
- package/bus.ts +683 -0
- package/cache.js +169 -0
- package/cache.js.map +1 -0
- package/cache.ts +230 -0
- package/child-notice.js +128 -0
- package/child-notice.js.map +1 -0
- package/child-notice.ts +136 -0
- package/children.js +937 -0
- package/children.js.map +1 -0
- package/children.ts +925 -0
- package/claude-control.js +8 -0
- package/claude-control.js.map +1 -0
- package/claude-control.ts +12 -0
- package/cli.js +23 -0
- package/cli.js.map +1 -0
- package/cli.ts +28 -0
- package/comp.js +76 -0
- package/comp.js.map +1 -0
- package/comp.ts +78 -0
- package/compact.js +157 -0
- package/compact.js.map +1 -0
- package/compact.ts +209 -0
- package/compact_ask.js +280 -0
- package/compact_ask.js.map +1 -0
- package/compact_ask.ts +199 -0
- package/continue.js +131 -0
- package/continue.js.map +1 -0
- package/continue.ts +143 -0
- package/conversation.js +337 -0
- package/conversation.js.map +1 -0
- package/conversation.ts +593 -0
- package/cost.js +111 -0
- package/cost.js.map +1 -0
- package/cost.ts +93 -0
- package/deferred.js +207 -0
- package/deferred.js.map +1 -0
- package/deferred.ts +219 -0
- package/deno.json +1 -0
- package/dependencies.js +114 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +110 -0
- package/draining.js +20 -0
- package/draining.js.map +1 -0
- package/draining.ts +26 -0
- package/ended.js +210 -0
- package/ended.js.map +1 -0
- package/ended.ts +225 -0
- package/files.js +285 -0
- package/files.js.map +1 -0
- package/files.ts +318 -0
- package/fork.js +96 -0
- package/fork.js.map +1 -0
- package/fork.ts +124 -0
- package/graft.js +97 -0
- package/graft.js.map +1 -0
- package/graft.ts +88 -0
- package/graph.js +49 -0
- package/graph.js.map +1 -0
- package/graph.ts +61 -0
- package/handoff.js +111 -0
- package/handoff.js.map +1 -0
- package/handoff.ts +147 -0
- package/help.js +432 -0
- package/help.js.map +1 -0
- package/help.ts +431 -0
- package/hooks.js +253 -0
- package/hooks.js.map +1 -0
- package/hooks.ts +333 -0
- package/imported.js +259 -0
- package/imported.js.map +1 -0
- package/imported.ts +201 -0
- package/inspect.js +353 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +378 -0
- package/intake.js +115 -0
- package/intake.js.map +1 -0
- package/intake.ts +124 -0
- package/joined.js +67 -0
- package/joined.js.map +1 -0
- package/joined.ts +69 -0
- package/lease.js +146 -0
- package/lease.js.map +1 -0
- package/lease.ts +151 -0
- package/lifecycle.js +49 -0
- package/lifecycle.js.map +1 -0
- package/lifecycle.ts +46 -0
- package/lines.js +171 -0
- package/lines.js.map +1 -0
- package/lines.ts +177 -0
- package/listen.js +604 -0
- package/listen.js.map +1 -0
- package/listen.ts +976 -0
- package/log.js +78 -0
- package/log.js.map +1 -0
- package/log.ts +88 -0
- package/mod.js +107 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/name.js +51 -0
- package/name.js.map +1 -0
- package/name.ts +84 -0
- package/naming.js +96 -0
- package/naming.js.map +1 -0
- package/naming.ts +102 -0
- package/native.js +17 -0
- package/native.js.map +1 -0
- package/native.ts +17 -0
- package/package.json +133 -4
- package/parts.js +334 -0
- package/parts.js.map +1 -0
- package/parts.ts +383 -0
- package/plugin.js +77 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +98 -0
- package/project.js +354 -0
- package/project.js.map +1 -0
- package/project.ts +407 -0
- package/prompt.js +57 -0
- package/prompt.js.map +1 -0
- package/prompt.ts +92 -0
- package/prose.js +43 -0
- package/prose.js.map +1 -0
- package/prose.ts +63 -0
- package/providers.js +279 -0
- package/providers.js.map +1 -0
- package/providers.ts +306 -0
- package/pruning.js +80 -0
- package/pruning.js.map +1 -0
- package/pruning.ts +147 -0
- package/reach.js +923 -0
- package/reach.js.map +1 -0
- package/reach.ts +1107 -0
- package/react.js +2259 -0
- package/react.js.map +1 -0
- package/react.ts +2864 -0
- package/readers.js +956 -0
- package/readers.js.map +1 -0
- package/readers.ts +1017 -0
- package/reap.js +60 -0
- package/reap.js.map +1 -0
- package/reap.ts +65 -0
- package/recall.js +67 -0
- package/recall.js.map +1 -0
- package/recall.ts +114 -0
- package/reopen.js +45 -0
- package/reopen.js.map +1 -0
- package/reopen.ts +44 -0
- package/result-entry.js +32 -0
- package/result-entry.js.map +1 -0
- package/result-entry.ts +34 -0
- package/resume.js +266 -0
- package/resume.js.map +1 -0
- package/resume.ts +283 -0
- package/routes.js +129 -0
- package/routes.js.map +1 -0
- package/routes.ts +147 -0
- package/routine.js +179 -0
- package/routine.js.map +1 -0
- package/routine.ts +191 -0
- package/run.js +932 -0
- package/run.js.map +1 -0
- package/run.ts +999 -0
- package/service.js +806 -0
- package/service.js.map +1 -0
- package/service.ts +911 -0
- package/source.js +26 -0
- package/source.js.map +1 -0
- package/source.ts +40 -0
- package/start.js +197 -0
- package/start.js.map +1 -0
- package/start.ts +214 -0
- package/state.js +247 -0
- package/state.js.map +1 -0
- package/state.ts +404 -0
- package/status.js +1222 -0
- package/status.js.map +1 -0
- package/status.ts +1555 -0
- package/status_bench.ts +50 -0
- package/statusline.js +187 -0
- package/statusline.js.map +1 -0
- package/statusline.ts +232 -0
- package/tail.js +748 -0
- package/tail.js.map +1 -0
- package/tail.ts +815 -0
- package/talk.js +58 -0
- package/talk.js.map +1 -0
- package/talk.ts +51 -0
- package/task-context.js +41 -0
- package/task-context.js.map +1 -0
- package/task-context.ts +53 -0
- package/texted.js +65 -0
- package/texted.js.map +1 -0
- package/texted.ts +65 -0
- package/timing.js +37 -0
- package/timing.js.map +1 -0
- package/timing.ts +52 -0
- package/told.js +56 -0
- package/told.js.map +1 -0
- package/told.ts +54 -0
- package/tools.js +595 -0
- package/tools.js.map +1 -0
- package/tools.ts +633 -0
- package/transcript.js +34 -0
- package/transcript.js.map +1 -0
- package/transcript.ts +41 -0
- package/turn.js +47 -0
- package/turn.js.map +1 -0
- package/turn.ts +68 -0
- package/unknown.js +8 -0
- package/unknown.js.map +1 -0
- package/unknown.ts +9 -0
- package/views.js +15 -0
- package/views.js.map +1 -0
- package/views.ts +21 -0
- package/vocab.js +24 -0
- package/vocab.js.map +1 -0
- package/vocab.json +1573 -0
- package/vocab.ts +30 -0
- package/wait.js +30 -0
- package/wait.js.map +1 -0
- package/wait.ts +45 -0
- package/wake.js +552 -0
- package/wake.js.map +1 -0
- package/wake.ts +597 -0
- package/watch.js +520 -0
- package/watch.js.map +1 -0
- package/watch.ts +596 -0
- package/who.js +309 -0
- package/who.js.map +1 -0
- package/who.ts +347 -0
- package/window.js +179 -0
- package/window.js.map +1 -0
- package/window.ts +268 -0
- package/woken.js +129 -0
- package/woken.js.map +1 -0
- package/woken.ts +127 -0
package/append.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/** Transactional transcript ordering. Omit seq to append; explicit positions are
|
|
2
|
+
* reserved for import and must be positive, unique integers. */
|
|
3
|
+
import { after } from '@yaks/fp'
|
|
4
|
+
import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36/bundle'
|
|
5
|
+
import type { Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import type { Hook } from 'jsr:@yaks/graph@0.2.36/plugin'
|
|
7
|
+
import { line, parse } from '@yaks/query'
|
|
8
|
+
import { UnknownSession } from './unknown.js'
|
|
9
|
+
|
|
10
|
+
let entry = (b: Bundle | undefined) => b?.entry as Comp | undefined
|
|
11
|
+
|
|
12
|
+
export let sequencing: Hook = (bundles, tx) =>
|
|
13
|
+
after(
|
|
14
|
+
tx.get(bundles.filter((b) => b.entry).map((b) => b.entity.eid), ['entry']),
|
|
15
|
+
(existing) => {
|
|
16
|
+
let groups = new Map<string, Bundle[]>()
|
|
17
|
+
for (let b of bundles) {
|
|
18
|
+
let e = entry(b)
|
|
19
|
+
if (!e || b.$delete) continue
|
|
20
|
+
if (
|
|
21
|
+
e.seq != null && (!Number.isSafeInteger(e.seq) || Number(e.seq) < 1)
|
|
22
|
+
) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'entry.seq must be a positive integer; omit seq to append atomically',
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
let previous = entry(
|
|
28
|
+
existing.find((o) => o.entity.eid == b.entity.eid),
|
|
29
|
+
)
|
|
30
|
+
if (
|
|
31
|
+
previous?.session != null && e.session != null &&
|
|
32
|
+
previous.session != e.session
|
|
33
|
+
) {
|
|
34
|
+
throw new Error('entry.session cannot move an existing entry')
|
|
35
|
+
}
|
|
36
|
+
if (e.session == null) {
|
|
37
|
+
e.session = entry(existing.find((o) => o.entity.eid == b.entity.eid))
|
|
38
|
+
?.session
|
|
39
|
+
}
|
|
40
|
+
if (e.session != null) {
|
|
41
|
+
let id = String(e.session)
|
|
42
|
+
groups.set(id, [...groups.get(id) ?? [], b])
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Allocate parent entries before children that fork from the same batch.
|
|
46
|
+
let ordered: string[] = [], visiting = new Set<string>()
|
|
47
|
+
let order = (id: string) => {
|
|
48
|
+
if (ordered.includes(id)) return
|
|
49
|
+
if (visiting.has(id)) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'cyclic fork ancestry in append batch',
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
visiting.add(id)
|
|
55
|
+
let from =
|
|
56
|
+
(bundles.find((b) => b.entity.eid == id)?.fork as Comp | undefined)
|
|
57
|
+
?.from
|
|
58
|
+
let parent = entry(bundles.find((b) => b.entity.eid == from))?.session
|
|
59
|
+
if (parent && groups.has(String(parent))) order(String(parent))
|
|
60
|
+
visiting.delete(id)
|
|
61
|
+
ordered.push(id)
|
|
62
|
+
}
|
|
63
|
+
for (let id of groups.keys()) order(id)
|
|
64
|
+
let pending: void | Promise<void> = undefined
|
|
65
|
+
for (let session of ordered) {
|
|
66
|
+
let sessionBundles = groups.get(session)!
|
|
67
|
+
pending = after(pending, () =>
|
|
68
|
+
after(
|
|
69
|
+
tx.read(
|
|
70
|
+
parse(
|
|
71
|
+
'.entry.session=' + session +
|
|
72
|
+
'&.order=-entry.seq&.limit=1',
|
|
73
|
+
),
|
|
74
|
+
undefined,
|
|
75
|
+
['entry'],
|
|
76
|
+
),
|
|
77
|
+
(latest) =>
|
|
78
|
+
after(
|
|
79
|
+
sessionBundles.some((b) => entry(b)?.seq != null)
|
|
80
|
+
? tx.read(
|
|
81
|
+
parse(
|
|
82
|
+
'.entry.session=' + session + '&.entry.seq>=' +
|
|
83
|
+
Math.min(
|
|
84
|
+
...sessionBundles.filter((b) => entry(b)?.seq != null)
|
|
85
|
+
.map((
|
|
86
|
+
b,
|
|
87
|
+
) => Number(entry(b)!.seq)),
|
|
88
|
+
) + '&.entry.seq<=' + Math.max(
|
|
89
|
+
...sessionBundles.filter((b) => entry(b)?.seq != null)
|
|
90
|
+
.map((
|
|
91
|
+
b,
|
|
92
|
+
) => Number(entry(b)!.seq)),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
undefined,
|
|
96
|
+
['entry'],
|
|
97
|
+
)
|
|
98
|
+
: [],
|
|
99
|
+
(collisions) => {
|
|
100
|
+
let own = [
|
|
101
|
+
...existing.filter((b) => entry(b)?.session == session),
|
|
102
|
+
...latest,
|
|
103
|
+
...collisions,
|
|
104
|
+
]
|
|
105
|
+
return after(
|
|
106
|
+
tx.read(
|
|
107
|
+
line`.entity.eid=${session}&.session`,
|
|
108
|
+
undefined,
|
|
109
|
+
['fork'],
|
|
110
|
+
),
|
|
111
|
+
(found) => {
|
|
112
|
+
if (
|
|
113
|
+
!found[0] &&
|
|
114
|
+
!bundles.some((b) =>
|
|
115
|
+
b.entity.eid == session && b.session
|
|
116
|
+
)
|
|
117
|
+
) throw new UnknownSession(session)
|
|
118
|
+
let self = bundles.find((b) =>
|
|
119
|
+
b.entity.eid == session && b.fork
|
|
120
|
+
) ?? found[0]
|
|
121
|
+
let from = (self?.fork as Comp | undefined)?.from
|
|
122
|
+
let anchorInBatch = bundles.find((b) =>
|
|
123
|
+
b.entity.eid == from
|
|
124
|
+
)
|
|
125
|
+
return after(
|
|
126
|
+
from && !anchorInBatch
|
|
127
|
+
? tx.get([String(from)], ['entry'])
|
|
128
|
+
: [],
|
|
129
|
+
(anchors) => {
|
|
130
|
+
let floor = Number(
|
|
131
|
+
entry(
|
|
132
|
+
anchorInBatch ?? anchors[0] ??
|
|
133
|
+
{ entity: { eid: '' } },
|
|
134
|
+
)?.seq ?? 0,
|
|
135
|
+
)
|
|
136
|
+
let max = Math.max(
|
|
137
|
+
floor,
|
|
138
|
+
...own.map((b) =>
|
|
139
|
+
Number(entry(b)?.seq ?? 0)
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
let occupied = new Map(
|
|
143
|
+
own.map((
|
|
144
|
+
b,
|
|
145
|
+
) => [Number(entry(b)?.seq), b.entity.eid]),
|
|
146
|
+
)
|
|
147
|
+
for (let b of sessionBundles) {
|
|
148
|
+
let e = entry(b)!
|
|
149
|
+
let old = own.find((o) =>
|
|
150
|
+
o.entity.eid == b.entity.eid
|
|
151
|
+
)
|
|
152
|
+
if (
|
|
153
|
+
old && e.seq != null && e.seq != entry(old)?.seq
|
|
154
|
+
) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
'entry.seq cannot move an existing entry',
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
let seq = e.seq == null
|
|
160
|
+
? entry(old)?.seq ?? Math.floor(max) + 1
|
|
161
|
+
: e.seq
|
|
162
|
+
if (!Number.isSafeInteger(seq) || Number(seq) < 1) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
'entry sequence exhausted',
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
if (
|
|
168
|
+
Number(seq) <= floor ||
|
|
169
|
+
(occupied.has(Number(seq)) &&
|
|
170
|
+
occupied.get(Number(seq)) != b.entity.eid)
|
|
171
|
+
) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
'entry.seq is occupied or precedes the fork boundary; omit seq to append atomically',
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
e.seq = seq
|
|
177
|
+
occupied.set(Number(seq), b.entity.eid)
|
|
178
|
+
max = Math.max(max, Number(seq))
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
},
|
|
183
|
+
)
|
|
184
|
+
},
|
|
185
|
+
),
|
|
186
|
+
))
|
|
187
|
+
}
|
|
188
|
+
return after(pending, () => bundles)
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
/** Append an ordinary input or a passive notice. The session plugin assigns seq
|
|
193
|
+
* inside the graph transaction. Supply an eid for idempotent delivery and from
|
|
194
|
+
* for words authored outside the receiving model's own conversation. */
|
|
195
|
+
export let appendEntry = (g: Graph, session: string, body: string, opts: {
|
|
196
|
+
eid?: string
|
|
197
|
+
notice?: boolean
|
|
198
|
+
from?: string
|
|
199
|
+
} = {}): Bundle[] | Promise<Bundle[]> =>
|
|
200
|
+
g.apply([{
|
|
201
|
+
entity: { eid: opts.eid ?? crypto.randomUUID() },
|
|
202
|
+
entry: { session, ...opts.from ? { from: opts.from } : {} },
|
|
203
|
+
content: { body },
|
|
204
|
+
...opts.notice ? { notice: {} } : {},
|
|
205
|
+
}])
|
package/archive.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A compressed log is an asynchronous byte source. Its decoder streams under
|
|
2
|
+
// pipe backpressure; no expanded private file is kept, and EOF is successful
|
|
3
|
+
// only once the decoder has closed cleanly.
|
|
4
|
+
import { command as processCommand } from "@yaks/process/command";
|
|
5
|
+
export let archive = (path, signal)=>{
|
|
6
|
+
let child = processCommand('zstd', {
|
|
7
|
+
args: [
|
|
8
|
+
'-dcq',
|
|
9
|
+
'--',
|
|
10
|
+
path
|
|
11
|
+
],
|
|
12
|
+
stdout: 'piped',
|
|
13
|
+
stderr: 'piped'
|
|
14
|
+
}).spawn();
|
|
15
|
+
let reader = child.stdout.getReader();
|
|
16
|
+
let errors = new Response(child.stderr).text();
|
|
17
|
+
let decoder = new TextDecoder();
|
|
18
|
+
let closed = false;
|
|
19
|
+
let closing;
|
|
20
|
+
let source = {
|
|
21
|
+
done: false,
|
|
22
|
+
read: async ()=>{
|
|
23
|
+
if (closed) return undefined;
|
|
24
|
+
let chunk = await reader.read();
|
|
25
|
+
if (closed || signal?.aborted) return undefined;
|
|
26
|
+
if (!chunk.done) return decoder.decode(chunk.value, {
|
|
27
|
+
stream: true
|
|
28
|
+
});
|
|
29
|
+
let status = await child.status;
|
|
30
|
+
let error = await errors;
|
|
31
|
+
let cancelled = closed || signal?.aborted;
|
|
32
|
+
closed = true;
|
|
33
|
+
signal?.removeEventListener('abort', abort);
|
|
34
|
+
if (cancelled) return undefined;
|
|
35
|
+
if (!status.success) {
|
|
36
|
+
throw new Error(`Cannot read archive ${path}: ${error.trim()}`);
|
|
37
|
+
}
|
|
38
|
+
source.done = true;
|
|
39
|
+
return decoder.decode() || undefined;
|
|
40
|
+
},
|
|
41
|
+
close: ()=>closing ??= (async ()=>{
|
|
42
|
+
signal?.removeEventListener('abort', abort);
|
|
43
|
+
if (closed) return;
|
|
44
|
+
closed = true;
|
|
45
|
+
await reader.cancel().catch(()=>{});
|
|
46
|
+
try {
|
|
47
|
+
child.kill('SIGTERM');
|
|
48
|
+
} catch {}
|
|
49
|
+
await child.status;
|
|
50
|
+
await errors;
|
|
51
|
+
})()
|
|
52
|
+
};
|
|
53
|
+
let abort = ()=>{
|
|
54
|
+
void source.close();
|
|
55
|
+
};
|
|
56
|
+
signal?.addEventListener('abort', abort, {
|
|
57
|
+
once: true
|
|
58
|
+
});
|
|
59
|
+
if (signal?.aborted) abort();
|
|
60
|
+
return source;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=archive.js.map
|
package/archive.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.js","sources":["./archive.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,4CAA4C;AAE5C,SAAS,WAAW,cAAc,qCAA0C;AAQ5E,OAAO,IAAI,UAAU,CAAC,MAAc;EAClC,IAAI,QAAQ,eAAe,QAAQ;IACjC,MAAM;MAAC;MAAQ;MAAM;KAAK;IAC1B,QAAQ;IACR,QAAQ;EACV,GAAG,KAAK;EACR,IAAI,SAAS,MAAM,MAAM,CAAC,SAAS;EACnC,IAAI,SAAS,IAAI,SAAS,MAAM,MAAM,EAAE,IAAI;EAC5C,IAAI,UAAU,IAAI;EAClB,IAAI,SAAS;EACb,IAAI;EACJ,IAAI,SAAiB;IACnB,MAAM;IACN,MAAM;MACJ,IAAI,QAAQ,OAAO;MACnB,IAAI,QAAQ,MAAM,OAAO,IAAI;MAC7B,IAAI,UAAU,QAAQ,SAAS,OAAO;MACtC,IAAI,CAAC,MAAM,IAAI,EAAE,OAAO,QAAQ,MAAM,CAAC,MAAM,KAAK,EAAE;QAAE,QAAQ;MAAK;MACnE,IAAI,SAAS,MAAM,MAAM,MAAM;MAC/B,IAAI,QAAQ,MAAM;MAClB,IAAI,YAAY,UAAU,QAAQ;MAClC,SAAS;MACT,QAAQ,oBAAoB,SAAS;MACrC,IAAI,WAAW,OAAO;MACtB,IAAI,CAAC,OAAO,OAAO,EAAE;QACnB,MAAM,IAAI,MAAM,CAAC,oBAAoB,EAAE,KAAK,EAAE,EAAE,MAAM,IAAI,IAAI;MAChE;MACA,OAAO,IAAI,GAAG;MACd,OAAO,QAAQ,MAAM,MAAM;IAC7B;IACA,OAAO,IACL,YAAY,CAAC;QACX,QAAQ,oBAAoB,SAAS;QACrC,IAAI,QAAQ;QACZ,SAAS;QACT,MAAM,OAAO,MAAM,GAAG,KAAK,CAAC,KAAO;QACnC,IAAI;UACF,MAAM,IAAI,CAAC;QACb,EAAE,OAAM,CAAuB;QAC/B,MAAM,MAAM,MAAM;QAClB,MAAM;MACR,CAAC;EACL;EACA,IAAI,QAAQ;IACV,KAAK,OAAO,KAAK;EACnB;EACA,QAAQ,iBAAiB,SAAS,OAAO;IAAE,MAAM;EAAK;EACtD,IAAI,QAAQ,SAAS;EACrB,OAAO;AACT,EAAC"}
|
package/archive.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A compressed log is an asynchronous byte source. Its decoder streams under
|
|
2
|
+
// pipe backpressure; no expanded private file is kept, and EOF is successful
|
|
3
|
+
// only once the decoder has closed cleanly.
|
|
4
|
+
|
|
5
|
+
import { command as processCommand } from '@yaks/process/command'
|
|
6
|
+
|
|
7
|
+
export type Chunks = {
|
|
8
|
+
read: () => Promise<string | undefined>
|
|
9
|
+
close: () => Promise<void>
|
|
10
|
+
done: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export let archive = (path: string, signal?: AbortSignal): Chunks => {
|
|
14
|
+
let child = processCommand('zstd', {
|
|
15
|
+
args: ['-dcq', '--', path],
|
|
16
|
+
stdout: 'piped',
|
|
17
|
+
stderr: 'piped',
|
|
18
|
+
}).spawn()
|
|
19
|
+
let reader = child.stdout.getReader()
|
|
20
|
+
let errors = new Response(child.stderr).text()
|
|
21
|
+
let decoder = new TextDecoder()
|
|
22
|
+
let closed = false
|
|
23
|
+
let closing: Promise<void> | undefined
|
|
24
|
+
let source: Chunks = {
|
|
25
|
+
done: false,
|
|
26
|
+
read: async () => {
|
|
27
|
+
if (closed) return undefined
|
|
28
|
+
let chunk = await reader.read()
|
|
29
|
+
if (closed || signal?.aborted) return undefined
|
|
30
|
+
if (!chunk.done) return decoder.decode(chunk.value, { stream: true })
|
|
31
|
+
let status = await child.status
|
|
32
|
+
let error = await errors
|
|
33
|
+
let cancelled = closed || signal?.aborted
|
|
34
|
+
closed = true
|
|
35
|
+
signal?.removeEventListener('abort', abort)
|
|
36
|
+
if (cancelled) return undefined
|
|
37
|
+
if (!status.success) {
|
|
38
|
+
throw new Error(`Cannot read archive ${path}: ${error.trim()}`)
|
|
39
|
+
}
|
|
40
|
+
source.done = true
|
|
41
|
+
return decoder.decode() || undefined
|
|
42
|
+
},
|
|
43
|
+
close: () =>
|
|
44
|
+
closing ??= (async () => {
|
|
45
|
+
signal?.removeEventListener('abort', abort)
|
|
46
|
+
if (closed) return
|
|
47
|
+
closed = true
|
|
48
|
+
await reader.cancel().catch(() => {})
|
|
49
|
+
try {
|
|
50
|
+
child.kill('SIGTERM')
|
|
51
|
+
} catch { /* already closed */ }
|
|
52
|
+
await child.status
|
|
53
|
+
await errors
|
|
54
|
+
})(),
|
|
55
|
+
}
|
|
56
|
+
let abort = () => {
|
|
57
|
+
void source.close()
|
|
58
|
+
}
|
|
59
|
+
signal?.addEventListener('abort', abort, { once: true })
|
|
60
|
+
if (signal?.aborted) abort()
|
|
61
|
+
return source
|
|
62
|
+
}
|
package/asks.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// What was asked of a task's work, kept on the task. Words sent to a run at
|
|
2
|
+
// work on a task (`session_send`) are a comment on that task as well as what
|
|
3
|
+
// reaches the run, one row that is both (./listen.ts says it once), so the
|
|
4
|
+
// task holds every ask in order. A run that starts on the task later, or a
|
|
5
|
+
// run that resumes or is compacted, reads them all with its brief: a respawn
|
|
6
|
+
// never starts from the newest ask alone.
|
|
7
|
+
//
|
|
8
|
+
// An ask is a comment on the task that was said to its run (it carries
|
|
9
|
+
// `knock.from`) or that a person wrote. A run's own report on the task is
|
|
10
|
+
// neither.
|
|
11
|
+
import { human } from "@yaks/id";
|
|
12
|
+
import { line, sub } from "@yaks/query";
|
|
13
|
+
import { CLAIM } from "./comp.js";
|
|
14
|
+
let str = (v)=>typeof v == 'string' ? v : '';
|
|
15
|
+
let comp = (b, name)=>b?.[name] ?? {};
|
|
16
|
+
/** The task words sent to `session` are about: `task` where the caller named
|
|
17
|
+
* one, else the one task the session holds. None where it holds several or
|
|
18
|
+
* none, or the graph keeps no comments. */ export let askedOf = async (g, session, task)=>{
|
|
19
|
+
if (!g.vocab.comp('comment') || !g.vocab.comp(CLAIM)) return;
|
|
20
|
+
if (task) return task;
|
|
21
|
+
let held = await g.read(line`.${CLAIM}.session=${session}`);
|
|
22
|
+
return held.length == 1 ? held[0].entity.eid : undefined;
|
|
23
|
+
};
|
|
24
|
+
/** The comment that keeps words sent to `session` on `task`: it is also the
|
|
25
|
+
* knock that carries them to the session, so it is said once. */ export let ask = (session, task, text, from)=>({
|
|
26
|
+
entity: {
|
|
27
|
+
eid: crypto.randomUUID()
|
|
28
|
+
},
|
|
29
|
+
doc: {
|
|
30
|
+
body: text
|
|
31
|
+
},
|
|
32
|
+
comment: {
|
|
33
|
+
target: task
|
|
34
|
+
},
|
|
35
|
+
knock: {
|
|
36
|
+
target: session,
|
|
37
|
+
...from ? {
|
|
38
|
+
from
|
|
39
|
+
} : {}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
/** Every ask on these tasks, oldest first, each as its task's eid and the row
|
|
43
|
+
* with its author's title (`by`). */ export let asksOn = async (g, tasks)=>{
|
|
44
|
+
let out = new Map();
|
|
45
|
+
let made = !!g.vocab.prop('created', 'at');
|
|
46
|
+
let sent = !!g.vocab.comp('knock');
|
|
47
|
+
let person = made && !!g.vocab.comp('person');
|
|
48
|
+
if (!tasks.length || !g.vocab.comp('comment') || !(sent || person)) {
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
let said = sent && person ? line`(.knock.from | .created.by.person)` : sent ? line`.knock.from` : line`.created.by.person`;
|
|
52
|
+
let order = made ? line`.order=created.at` : line``;
|
|
53
|
+
let rows = await g.read(line`.comment.target=${tasks} ${sub(said)} ${sub(order)} *`);
|
|
54
|
+
for (let b of rows){
|
|
55
|
+
let on = str(comp(b, 'comment').target);
|
|
56
|
+
out.set(on, [
|
|
57
|
+
...out.get(on) ?? [],
|
|
58
|
+
b
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
};
|
|
63
|
+
/** The asks as a run reads them: one per line under its id and who asked,
|
|
64
|
+
* its words whole and indented beneath. */ export let asksSaid = async (g, rows, indent = '')=>{
|
|
65
|
+
let authors = [
|
|
66
|
+
...new Set(rows.map((b)=>str(comp(b, 'knock').from) || str(comp(b, 'created').by)))
|
|
67
|
+
].filter(Boolean);
|
|
68
|
+
let named = new Map((authors.length ? await g.get(authors, [
|
|
69
|
+
'doc'
|
|
70
|
+
]) : []).map((b)=>[
|
|
71
|
+
b.entity.eid,
|
|
72
|
+
str(comp(b, 'doc').title) || human(g.vocab)(b)
|
|
73
|
+
]));
|
|
74
|
+
return rows.map((b)=>{
|
|
75
|
+
let by = named.get(str(comp(b, 'knock').from) || str(comp(b, 'created').by));
|
|
76
|
+
let body = str(comp(b, 'doc').body).trim().replaceAll('\n', `\n${indent} `);
|
|
77
|
+
return `${indent}- ${human(g.vocab)(b)}${by ? ` from ${by}` : ''}: ${body}`;
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=asks.js.map
|
package/asks.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asks.js","sources":["./asks.ts"],"names":[],"mappings":"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"}
|
package/asks.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// What was asked of a task's work, kept on the task. Words sent to a run at
|
|
2
|
+
// work on a task (`session_send`) are a comment on that task as well as what
|
|
3
|
+
// reaches the run, one row that is both (./listen.ts says it once), so the
|
|
4
|
+
// task holds every ask in order. A run that starts on the task later, or a
|
|
5
|
+
// run that resumes or is compacted, reads them all with its brief: a respawn
|
|
6
|
+
// never starts from the newest ask alone.
|
|
7
|
+
//
|
|
8
|
+
// An ask is a comment on the task that was said to its run (it carries
|
|
9
|
+
// `knock.from`) or that a person wrote. A run's own report on the task is
|
|
10
|
+
// neither.
|
|
11
|
+
|
|
12
|
+
import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
13
|
+
import { human } from '@yaks/id'
|
|
14
|
+
import { line, sub } from '@yaks/query'
|
|
15
|
+
import { CLAIM } from './comp.js'
|
|
16
|
+
|
|
17
|
+
let str = (v: unknown): string => typeof v == 'string' ? v : ''
|
|
18
|
+
let comp = (b: Bundle | undefined, name: string): Comp =>
|
|
19
|
+
(b?.[name] ?? {}) as Comp
|
|
20
|
+
|
|
21
|
+
/** The task words sent to `session` are about: `task` where the caller named
|
|
22
|
+
* one, else the one task the session holds. None where it holds several or
|
|
23
|
+
* none, or the graph keeps no comments. */
|
|
24
|
+
export let askedOf = async (
|
|
25
|
+
g: Pick<Graph, 'vocab' | 'read'>,
|
|
26
|
+
session: Eid,
|
|
27
|
+
task?: Eid,
|
|
28
|
+
): Promise<Eid | undefined> => {
|
|
29
|
+
if (!g.vocab.comp('comment') || !g.vocab.comp(CLAIM)) return
|
|
30
|
+
if (task) return task
|
|
31
|
+
let held = await g.read(line`.${CLAIM}.session=${session}`)
|
|
32
|
+
return held.length == 1 ? held[0].entity.eid : undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The comment that keeps words sent to `session` on `task`: it is also the
|
|
36
|
+
* knock that carries them to the session, so it is said once. */
|
|
37
|
+
export let ask = (
|
|
38
|
+
session: Eid,
|
|
39
|
+
task: Eid,
|
|
40
|
+
text: string,
|
|
41
|
+
from?: Eid,
|
|
42
|
+
): Bundle => ({
|
|
43
|
+
entity: { eid: crypto.randomUUID() },
|
|
44
|
+
doc: { body: text },
|
|
45
|
+
comment: { target: task },
|
|
46
|
+
knock: { target: session, ...from ? { from } : {} },
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/** Every ask on these tasks, oldest first, each as its task's eid and the row
|
|
50
|
+
* with its author's title (`by`). */
|
|
51
|
+
export let asksOn = async (
|
|
52
|
+
g: Pick<Graph, 'vocab' | 'read' | 'get'>,
|
|
53
|
+
tasks: Eid[],
|
|
54
|
+
): Promise<Map<Eid, Bundle[]>> => {
|
|
55
|
+
let out = new Map<Eid, Bundle[]>()
|
|
56
|
+
let made = !!g.vocab.prop('created', 'at')
|
|
57
|
+
let sent = !!g.vocab.comp('knock')
|
|
58
|
+
let person = made && !!g.vocab.comp('person')
|
|
59
|
+
if (!tasks.length || !g.vocab.comp('comment') || !(sent || person)) {
|
|
60
|
+
return out
|
|
61
|
+
}
|
|
62
|
+
let said = sent && person
|
|
63
|
+
? line`(.knock.from | .created.by.person)`
|
|
64
|
+
: sent
|
|
65
|
+
? line`.knock.from`
|
|
66
|
+
: line`.created.by.person`
|
|
67
|
+
let order = made ? line`.order=created.at` : line``
|
|
68
|
+
let rows = await g.read(
|
|
69
|
+
line`.comment.target=${tasks} ${sub(said)} ${sub(order)} *`,
|
|
70
|
+
)
|
|
71
|
+
for (let b of rows) {
|
|
72
|
+
let on = str(comp(b, 'comment').target)
|
|
73
|
+
out.set(on, [...out.get(on) ?? [], b])
|
|
74
|
+
}
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The asks as a run reads them: one per line under its id and who asked,
|
|
79
|
+
* its words whole and indented beneath. */
|
|
80
|
+
export let asksSaid = async (
|
|
81
|
+
g: Pick<Graph, 'vocab' | 'get'>,
|
|
82
|
+
rows: Bundle[],
|
|
83
|
+
indent = '',
|
|
84
|
+
): Promise<string[]> => {
|
|
85
|
+
let authors = [
|
|
86
|
+
...new Set(
|
|
87
|
+
rows.map((b) => str(comp(b, 'knock').from) || str(comp(b, 'created').by)),
|
|
88
|
+
),
|
|
89
|
+
].filter(Boolean)
|
|
90
|
+
let named = new Map(
|
|
91
|
+
(authors.length ? await g.get(authors, ['doc']) : []).map((b) => [
|
|
92
|
+
b.entity.eid,
|
|
93
|
+
str(comp(b, 'doc').title) || human(g.vocab)(b),
|
|
94
|
+
]),
|
|
95
|
+
)
|
|
96
|
+
return rows.map((b) => {
|
|
97
|
+
let by = named.get(
|
|
98
|
+
str(comp(b, 'knock').from) || str(comp(b, 'created').by),
|
|
99
|
+
)
|
|
100
|
+
let body = str(comp(b, 'doc').body).trim().replaceAll(
|
|
101
|
+
'\n',
|
|
102
|
+
`\n${indent} `,
|
|
103
|
+
)
|
|
104
|
+
return `${indent}- ${human(g.vocab)(b)}${by ? ` from ${by}` : ''}: ${body}`
|
|
105
|
+
})
|
|
106
|
+
}
|
package/attempt.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A provider request is held while in flight, completed when released, or
|
|
2
|
+
// interrupted explicitly. No diagnostic code decides its lifecycle.
|
|
3
|
+
import { and, col, eq, exists, lit, notNull, select, table, when } from "@yaks/sql/core";
|
|
4
|
+
import { attemptState } from "./state.js";
|
|
5
|
+
export { attemptState } from "./state.js";
|
|
6
|
+
export let attemptDerived = (vocab)=>({
|
|
7
|
+
'attempt.state': {
|
|
8
|
+
tag: 'text',
|
|
9
|
+
values: [
|
|
10
|
+
'interrupted',
|
|
11
|
+
'inflight',
|
|
12
|
+
'completed'
|
|
13
|
+
],
|
|
14
|
+
deps: [
|
|
15
|
+
'attempt'
|
|
16
|
+
],
|
|
17
|
+
expr: (owner)=>when([
|
|
18
|
+
...vocab.comp('interrupted') ? [
|
|
19
|
+
[
|
|
20
|
+
exists(select({
|
|
21
|
+
cols: [
|
|
22
|
+
lit(1)
|
|
23
|
+
],
|
|
24
|
+
from: table('interrupted', 's'),
|
|
25
|
+
where: eq(col('entity', 's'), owner)
|
|
26
|
+
})),
|
|
27
|
+
lit('interrupted')
|
|
28
|
+
]
|
|
29
|
+
] : [],
|
|
30
|
+
[
|
|
31
|
+
exists(select({
|
|
32
|
+
cols: [
|
|
33
|
+
lit(1)
|
|
34
|
+
],
|
|
35
|
+
from: table('attempt', 's'),
|
|
36
|
+
where: and(eq(col('entity', 's'), owner), notNull(col('by', 's')))
|
|
37
|
+
})),
|
|
38
|
+
lit('inflight')
|
|
39
|
+
]
|
|
40
|
+
], lit('completed'))
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
export let attemptComputed = {
|
|
44
|
+
'attempt.state': (ask)=>ask.attempt ? attemptState(ask) : null
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=attempt.js.map
|
package/attempt.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.js","sources":["./attempt.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,oEAAoE;AAIpE,SACE,GAAG,EACH,GAAG,EAEH,EAAE,EACF,MAAM,EAEN,GAAG,EACH,OAAO,EACP,MAAM,EACN,KAAK,EACL,IAAI,8BAC4B;AAElC,SAAS,YAAY,qBAAoB;AACzC,SAAS,YAAY,qBAAoB;AAEzC,OAAO,IAAI,iBAAiB,CAAC,QAA0B,CAAC;IACtD,iBAAiB;MACf,KAAK;MACL,QAAQ;QAAC;QAAe;QAAY;OAAY;MAChD,MAAM;QAAC;OAAU;MACjB,MAAM,CAAC,QACL,KACE;aACK,MAAM,IAAI,CAAC,iBACV;YAAC;cACD,OAAO,OAAO;gBACZ,MAAM;kBAAC,IAAI;iBAAG;gBACd,MAAM,MAAM,eAAe;gBAC3B,OAAO,GAAG,IAAI,UAAU,MAAM;cAChC;cACA,IAAI;aACL;WAAiB,GAChB,EAAE;UACN;YACE,OAAO,OAAO;cACZ,MAAM;gBAAC,IAAI;eAAG;cACd,MAAM,MAAM,WAAW;cACvB,OAAO,IACL,GAAG,IAAI,UAAU,MAAM,QACvB,QAAQ,IAAI,MAAM;YAEtB;YACA,IAAI;WACL;SACF,EACD,IAAI;IAEV;EACF,CAAC,EAAC;AAEF,OAAO,IAAI,kBAA4B;EACrC,iBAAiB,CAAC,MAAQ,IAAI,OAAO,GAAG,aAAa,OAAO;AAC9D,EAAC"}
|
package/attempt.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// A provider request is held while in flight, completed when released, or
|
|
2
|
+
// interrupted explicitly. No diagnostic code decides its lifecycle.
|
|
3
|
+
|
|
4
|
+
import type { Computed } from 'jsr:@yaks/match@0.2.36'
|
|
5
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
|
|
6
|
+
import {
|
|
7
|
+
and,
|
|
8
|
+
col,
|
|
9
|
+
type Derived,
|
|
10
|
+
eq,
|
|
11
|
+
exists,
|
|
12
|
+
type Expr,
|
|
13
|
+
lit,
|
|
14
|
+
notNull,
|
|
15
|
+
select,
|
|
16
|
+
table,
|
|
17
|
+
when,
|
|
18
|
+
} from '@yaks/sql/core'
|
|
19
|
+
|
|
20
|
+
import { attemptState } from './state.js'
|
|
21
|
+
export { attemptState } from './state.js'
|
|
22
|
+
|
|
23
|
+
export let attemptDerived = (vocab: Vocab): Derived => ({
|
|
24
|
+
'attempt.state': {
|
|
25
|
+
tag: 'text',
|
|
26
|
+
values: ['interrupted', 'inflight', 'completed'],
|
|
27
|
+
deps: ['attempt'],
|
|
28
|
+
expr: (owner: Expr) =>
|
|
29
|
+
when(
|
|
30
|
+
[
|
|
31
|
+
...vocab.comp('interrupted')
|
|
32
|
+
? [[
|
|
33
|
+
exists(select({
|
|
34
|
+
cols: [lit(1)],
|
|
35
|
+
from: table('interrupted', 's'),
|
|
36
|
+
where: eq(col('entity', 's'), owner),
|
|
37
|
+
})),
|
|
38
|
+
lit('interrupted'),
|
|
39
|
+
] as [Expr, Expr]]
|
|
40
|
+
: [],
|
|
41
|
+
[
|
|
42
|
+
exists(select({
|
|
43
|
+
cols: [lit(1)],
|
|
44
|
+
from: table('attempt', 's'),
|
|
45
|
+
where: and(
|
|
46
|
+
eq(col('entity', 's'), owner),
|
|
47
|
+
notNull(col('by', 's')),
|
|
48
|
+
),
|
|
49
|
+
})),
|
|
50
|
+
lit('inflight'),
|
|
51
|
+
],
|
|
52
|
+
],
|
|
53
|
+
lit('completed'),
|
|
54
|
+
),
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
export let attemptComputed: Computed = {
|
|
59
|
+
'attempt.state': (ask) => ask.attempt ? attemptState(ask) : null,
|
|
60
|
+
}
|