@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/routes.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sources":["./routes.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,+BAA+B;AAC/B,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AACtE,uEAAuE;AACvE,kCAAkC;AAClC,4DAA4D;AAC5D,EAAE;AACF,sEAAsE;AACtE,gEAAgE;AAChE,6CAA6C;AAC7C,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,qEAAqE;AAIrE,SAAoB,KAAK,mBAA6B;AACtD,SAAS,IAAI,wBAAuB;AAEpC,SAAS,SAAS,yBAAwB;AAC1C,SAAS,aAAa,sBAAqB;AAC3C,SAAS,MAAM,EAAE,MAAM,sBAAqC;AAC5D,SAAS,OAAO,EAAE,SAAS,wBAAuB;AAClD,SAAS,UAAU,0BAAyB;AAE5C,SAAS,MAAM,GAAE;AAEjB,6CAA6C,GAC7C,OAAO,IAAI,OAAO,gBAAe;AAEjC,8DAA8D,GAC9D,OAAO,IAAI,SAAS,kBAAiB;AAErC,+EAA+E;AAC/E,6EAA6E;AAC7E,0EAA0E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N,QAAQ,OAAO;QACb,IAAI,OAAgB,MAAM,QAAQ,IAAI,GAAG,KAAK,CAAC,IAAM;QACrD,IAAI,CAAC,QAAQ,OAAO,QAAQ,YAAY,MAAM,OAAO,CAAC,OAAO;UAC3D,OAAO,SAAS,IAAI,CAClB;YAAE,OAAO;UAAgC,GACzC;YAAE,QAAQ;UAAI;QAElB;QACA,0EAA0E;QAC1E,8DAA8D;QAC9D,IAAI,QAAQ;QACZ,IAAI,MAAM,eAAe,IAAI,oBAAoB;UAC/C,IAAI,QAAQ,OAAO,MAAM,MAAM,IAAI,WAAW,MAAM,MAAM,GAAG;UAC7D,IAAI,QAAQ,UAAU;UACtB,IAAI,OAAO;YACT,OAAO,SAAS,IAAI,CAAC;cACnB,UAAU;cACV,QAAQ,MAAM,QAAQ,MAAM,SAAS,OAAO;YAC9C;UACF;UACA,IAAI,WAAW,OAAO,IAAI,CAAC,SACvB,KACA,MAAM,OAAO,MAAM,MAAM,IAAI,CAAC,OAAO,IAAI,OAAO,WAAW;UAC/D,IAAI,OAAO;YACT,cAAc,OAAO,KAAK,QAAQ;YAClC;WACD,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC;UACvB,OAAO,SAAS,IAAI,CAClB,OACI;YACA,oBAAoB;cAClB,eAAe;cACf,mBAAmB;YACrB;UACF,IACE,CAAC;QAET;QACA,IAAI,OAAO,MAAM,UAAU,MAAM,SAAS;QAC1C,IAAI,MAAM,OAAO;QACjB,IAAI,MAAM,KAAK,KAAK,KAAK,EAAE,OAAO,OAAO,SAAS,IAAI,CAAC,CAAC;QACxD,OAAO,SAAS,IAAI,CAClB,MAAM,MAAM,MAAM,MAAc,IAAM,KAAK;MAE/C;IACF;GAAE;AACJ,EAAC"}
|
package/routes.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// The hook door, exported as `@yaks/session/routes`: where a harness reports
|
|
2
|
+
// each tool call of a session it runs (Claude Code's HTTP hook, installed by
|
|
3
|
+
// ./hooks.ts), and hears back what the bus owes that session (./bus.ts
|
|
4
|
+
// `heard`). A harness runs many contexts under one session id, and only its
|
|
5
|
+
// hook says which context an event came from, so this is the one place the
|
|
6
|
+
// session's own line of work can be told from its subagents: before a call,
|
|
7
|
+
// the hook says which run makes it, and a door the call then reaches writes
|
|
8
|
+
// as that run (./announce.ts).
|
|
9
|
+
//
|
|
10
|
+
// A prompt is answered with its transcript's timing and, beside it, what the
|
|
11
|
+
// configured person said, kept and decided before on the same subject
|
|
12
|
+
// (@yaks/memory/earlier). The recall includes reads that finish within
|
|
13
|
+
// RECALL ms. A prompt the harness
|
|
14
|
+
// wrote, a background task's notification, recalls nothing.
|
|
15
|
+
//
|
|
16
|
+
// `/yak:continue` is answered here, before the harness asks its model
|
|
17
|
+
// anything (./continue.ts), and so is Claude Code's status line
|
|
18
|
+
// (`POST /session/status`, ./statusline.ts).
|
|
19
|
+
//
|
|
20
|
+
// A body that is not a hook event is the caller's mistake, refused with a
|
|
21
|
+
// 400. Anything else that goes wrong is thrown to the host, which reports it;
|
|
22
|
+
// the harness treats a failed hook as nothing to add and carries on.
|
|
23
|
+
|
|
24
|
+
import type { Host } from 'jsr:@yaks/host@0.2.36'
|
|
25
|
+
import type { Authenticate, Route } from 'jsr:@yaks/api@0.2.36'
|
|
26
|
+
import { type Door, heard, type Hook } from './bus.js'
|
|
27
|
+
import { hear } from './announce.js'
|
|
28
|
+
import type { Runner } from 'jsr:@yaks/tools@0.2.36'
|
|
29
|
+
import { lifecycle } from './lifecycle.js'
|
|
30
|
+
import { promptContext } from './prompt.js'
|
|
31
|
+
import { RECALL, recall, type Recalling } from './recall.js'
|
|
32
|
+
import { carryOn, continued } from './continue.js'
|
|
33
|
+
import { statusLine } from './statusline.js'
|
|
34
|
+
|
|
35
|
+
export { RECALL }
|
|
36
|
+
|
|
37
|
+
/** Where the harness posts its hook events. */
|
|
38
|
+
export let PATH = '/session/hook'
|
|
39
|
+
|
|
40
|
+
/** Where Claude Code's status line posts what it was handed. */
|
|
41
|
+
export let STATUS = '/session/status'
|
|
42
|
+
|
|
43
|
+
// Whether the harness still waits for this answer. It gives up on a hook after
|
|
44
|
+
// its timeout (2 s, ./hooks.ts), and Deno tells a handler its client hung up
|
|
45
|
+
// only once the event loop turns, so the door lets it turn before asking.
|
|
46
|
+
let open = (request: Request): Promise<boolean> =>
|
|
47
|
+
new Promise((done) => setTimeout(() => done(!request.signal.aborted)))
|
|
48
|
+
|
|
49
|
+
// A prompt the harness wrote itself: Claude Code submits a finished
|
|
50
|
+
// background task's notification as a prompt. It is nobody's words, so
|
|
51
|
+
// nothing was said before on its subject.
|
|
52
|
+
let NOTICE = /^\s*<task-notification>/
|
|
53
|
+
|
|
54
|
+
/** `POST /session/hook`: one hook event in, the context it adds out. */
|
|
55
|
+
export let routes = (
|
|
56
|
+
host: Door & Recalling & {
|
|
57
|
+
who?: Authenticate
|
|
58
|
+
runner?: Runner
|
|
59
|
+
text?: Host['text']
|
|
60
|
+
tailText?: Host['tailText']
|
|
61
|
+
},
|
|
62
|
+
{ wait = RECALL }: { wait?: number } = {},
|
|
63
|
+
): Route[] => {
|
|
64
|
+
return [{
|
|
65
|
+
method: 'POST',
|
|
66
|
+
path: STATUS,
|
|
67
|
+
handle: async (request) => {
|
|
68
|
+
// It writes plan readings: a browser's cross-origin post is no status
|
|
69
|
+
// line.
|
|
70
|
+
if (request.headers.has('origin')) {
|
|
71
|
+
return new Response('', { status: 403 })
|
|
72
|
+
}
|
|
73
|
+
let status: unknown = await request.json().catch(() => null)
|
|
74
|
+
if (!status || typeof status != 'object' || Array.isArray(status)) {
|
|
75
|
+
return new Response('', { status: 400 })
|
|
76
|
+
}
|
|
77
|
+
return new Response(await statusLine(host.graph, status))
|
|
78
|
+
},
|
|
79
|
+
}, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
path: '/session/earlier',
|
|
82
|
+
handle: async (request) => {
|
|
83
|
+
// This door carries private historical words; apply the host's identity
|
|
84
|
+
// boundary just as the graph read door does. Browser cross-origin posts
|
|
85
|
+
// are not prompt hooks.
|
|
86
|
+
if (request.headers.has('origin')) {
|
|
87
|
+
return new Response('', { status: 403 })
|
|
88
|
+
}
|
|
89
|
+
await host.who?.(request)
|
|
90
|
+
let input = await request.json().catch(() => null)
|
|
91
|
+
if (typeof input?.words != 'string' || typeof input?.before != 'string') {
|
|
92
|
+
return new Response('', { status: 400 })
|
|
93
|
+
}
|
|
94
|
+
return new Response(
|
|
95
|
+
await recall(host, null).said(input.words, input.before),
|
|
96
|
+
)
|
|
97
|
+
},
|
|
98
|
+
}, {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
path: PATH,
|
|
101
|
+
handle: async (request) => {
|
|
102
|
+
let hook: unknown = await request.json().catch(() => null)
|
|
103
|
+
if (!hook || typeof hook != 'object' || Array.isArray(hook)) {
|
|
104
|
+
return Response.json(
|
|
105
|
+
{ error: 'a hook event is a JSON object' },
|
|
106
|
+
{ status: 400 },
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
// A prompt's context is its transcript's timing, read as the CLI reads it
|
|
110
|
+
// (./cli.ts), and what its person said before, within `wait`.
|
|
111
|
+
let event = hook as Record<string, unknown>
|
|
112
|
+
if (event.hook_event_name == 'UserPromptSubmit') {
|
|
113
|
+
let words = typeof event.prompt == 'string' ? event.prompt : ''
|
|
114
|
+
let asked = continued(words)
|
|
115
|
+
if (asked) {
|
|
116
|
+
return Response.json({
|
|
117
|
+
decision: 'block',
|
|
118
|
+
reason: await carryOn(host, request, event, asked),
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
let recalled = NOTICE.test(words)
|
|
122
|
+
? ''
|
|
123
|
+
: await recall(host, wait).said(words, new Date().toISOString())
|
|
124
|
+
let text = [
|
|
125
|
+
promptContext(event, host.tailText),
|
|
126
|
+
recalled,
|
|
127
|
+
].filter(Boolean).join('\n\n')
|
|
128
|
+
return Response.json(
|
|
129
|
+
text
|
|
130
|
+
? {
|
|
131
|
+
hookSpecificOutput: {
|
|
132
|
+
hookEventName: 'UserPromptSubmit',
|
|
133
|
+
additionalContext: text,
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
: {},
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
let edge = await lifecycle(host, request, event)
|
|
140
|
+
if (edge) return edge
|
|
141
|
+
if (await hear(host.graph, hook)) return Response.json({})
|
|
142
|
+
return Response.json(
|
|
143
|
+
await heard(host, hook as Hook, () => open(request)),
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
}]
|
|
147
|
+
}
|
package/routine.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// The rule on a knock or an arriving letter: whose it is, settled in the
|
|
2
|
+
// write that leaves it.
|
|
3
|
+
//
|
|
4
|
+
// A project wearing `helper{persona, provider, model, effort}` has its
|
|
5
|
+
// operator's routine taken by a helper (./help.ts). An item is routine when
|
|
6
|
+
// it is addressed to that operator and is not for the operator's own session.
|
|
7
|
+
//
|
|
8
|
+
// Addressed to the operator:
|
|
9
|
+
//
|
|
10
|
+
// - a knock at the project, at a project filed under it at any depth, or at a
|
|
11
|
+
// session a person opened (`session.operator`) wearing a persona homed
|
|
12
|
+
// there;
|
|
13
|
+
// - a letter that arrived (no `deliver`) for one of those projects or for an
|
|
14
|
+
// address filed under one (@yaks/mail's `mail.target`), unless it answers a
|
|
15
|
+
// letter another session wrote that may still hear the answer
|
|
16
|
+
// (./listen.ts).
|
|
17
|
+
//
|
|
18
|
+
// The operator's own:
|
|
19
|
+
//
|
|
20
|
+
// - a person's act or words: `knock.from` (@yaks/notify), else whoever wrote
|
|
21
|
+
// the knock or the letter, wears `person`. @yaks/mail names a letter's
|
|
22
|
+
// writer only where its edge vouched for the From address, so a letter
|
|
23
|
+
// that merely says it is from a person is routine. A watcher's knock
|
|
24
|
+
// telling of the owner's comment or answer, his text and his mail all name
|
|
25
|
+
// him so.
|
|
26
|
+
// - a hand-up: the knock was written through a session wearing `helping`, or
|
|
27
|
+
// through one opened on a topic (@yaks/topic's `session.topic`, read by
|
|
28
|
+
// name). The session that stays on a topic is no helper, and a hand-up is
|
|
29
|
+
// all of its writing that reaches another session.
|
|
30
|
+
// - a task update a worker knocks its parent with. A run's exit report
|
|
31
|
+
// carries a comment on the task.
|
|
32
|
+
//
|
|
33
|
+
// A routine item gets `routine{project}` in the same batch, so no listener
|
|
34
|
+
// ever reads it as the operator's (./listen.ts leaves it out) and
|
|
35
|
+
// `session_help` is owed by the commit that wrote it.
|
|
36
|
+
import { hook } from "@yaks/graph/plugin";
|
|
37
|
+
import { writers } from "@yaks/graph";
|
|
38
|
+
import { SESSION } from "./comp.js";
|
|
39
|
+
/** On a project: its operator's routine goes to a helper. */ export let HELPER = 'helper';
|
|
40
|
+
/** On a session: a helper, and the project whose operator it helps. */ export let HELPING = 'helping';
|
|
41
|
+
/** On a knock or a letter: a helper's to take. */ export let ROUTINE = 'routine';
|
|
42
|
+
let comp = (b, name)=>b?.[name] ?? {};
|
|
43
|
+
let str = (v)=>typeof v == 'string' ? v : '';
|
|
44
|
+
let unique = (ids)=>[
|
|
45
|
+
...new Set(ids.filter(Boolean))
|
|
46
|
+
];
|
|
47
|
+
// What an item is addressed to: a knock's target, or the entity a letter
|
|
48
|
+
// that arrived is for.
|
|
49
|
+
let target = (b)=>str(comp(b, 'knock').target) || (b.mail && !b.deliver ? str(comp(b, 'mail').target) : '');
|
|
50
|
+
// Which of `ids` wear `name`.
|
|
51
|
+
let wearing = async (tx, ids, name)=>new Set((ids.length ? await tx.get(ids, [
|
|
52
|
+
name
|
|
53
|
+
]) : []).filter((b)=>b[name]).map((b)=>b.entity.eid));
|
|
54
|
+
// How far up a line of projects is followed: a longer one is a cycle.
|
|
55
|
+
let DEPTH = 8;
|
|
56
|
+
// The nearest project wearing `helper` at or above each of these projects.
|
|
57
|
+
// An operator hears what is held for its persona's home and for every
|
|
58
|
+
// project filed under it (./listen.ts `below`), so its helper takes the same.
|
|
59
|
+
let nearest = async (tx, projects)=>{
|
|
60
|
+
let found = new Map();
|
|
61
|
+
let at = new Map(projects.map((p)=>[
|
|
62
|
+
p,
|
|
63
|
+
p
|
|
64
|
+
]));
|
|
65
|
+
for(let depth = 0; at.size && depth < DEPTH; depth++){
|
|
66
|
+
let rows = new Map((await tx.get(unique([
|
|
67
|
+
...at.values()
|
|
68
|
+
]), [
|
|
69
|
+
HELPER,
|
|
70
|
+
'project',
|
|
71
|
+
'filed'
|
|
72
|
+
])).map((b)=>[
|
|
73
|
+
b.entity.eid,
|
|
74
|
+
b
|
|
75
|
+
]));
|
|
76
|
+
for (let [start, here] of [
|
|
77
|
+
...at
|
|
78
|
+
]){
|
|
79
|
+
let b = rows.get(here);
|
|
80
|
+
let up = b?.project ? str(comp(b, 'filed').project) : '';
|
|
81
|
+
if (b?.[HELPER]) found.set(start, here);
|
|
82
|
+
if (b?.[HELPER] || !up) at.delete(start);
|
|
83
|
+
else at.set(start, up);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return found;
|
|
87
|
+
};
|
|
88
|
+
// The helped project each addressed entity leads to: from a project, itself
|
|
89
|
+
// or the nearest above it; from a session a person opened, the home of the
|
|
90
|
+
// persona it wears; from an address, the project it is filed under.
|
|
91
|
+
let helped = async (tx, targets)=>{
|
|
92
|
+
let rows = await tx.get(targets, [
|
|
93
|
+
HELPER,
|
|
94
|
+
SESSION,
|
|
95
|
+
'project',
|
|
96
|
+
'email',
|
|
97
|
+
'filed'
|
|
98
|
+
]);
|
|
99
|
+
let worn = (b)=>comp(b, SESSION).operator == true ? str(comp(b, SESSION).persona) : '';
|
|
100
|
+
let personas = unique(rows.map(worn));
|
|
101
|
+
let home = new Map((personas.length ? await tx.get(personas, [
|
|
102
|
+
'persona'
|
|
103
|
+
]) : []).map((b)=>[
|
|
104
|
+
b.entity.eid,
|
|
105
|
+
str(comp(b, 'persona').home)
|
|
106
|
+
]));
|
|
107
|
+
let lead = (b)=>b[HELPER] || b.project ? b.entity.eid : home.get(worn(b)) ?? (b.email ? str(comp(b, 'filed').project) : '');
|
|
108
|
+
let leads = unique(rows.map(lead));
|
|
109
|
+
let projects = leads.length ? await nearest(tx, leads) : new Map();
|
|
110
|
+
return new Map(rows.filter((b)=>projects.has(lead(b))).map((b)=>[
|
|
111
|
+
b.entity.eid,
|
|
112
|
+
projects.get(lead(b))
|
|
113
|
+
]));
|
|
114
|
+
};
|
|
115
|
+
// The letters among these that answer one another session wrote and may
|
|
116
|
+
// still hear the answer to: that session's, not the project's. A session a
|
|
117
|
+
// person opened is the operator the letter is addressed to already.
|
|
118
|
+
let answering = async (tx, letters)=>{
|
|
119
|
+
let to = (b)=>str(comp(b, 'mail').reply_to);
|
|
120
|
+
let answered = unique(letters.map(to));
|
|
121
|
+
let writer = new Map((answered.length ? await tx.get(answered, [
|
|
122
|
+
'created'
|
|
123
|
+
]) : []).map((b)=>[
|
|
124
|
+
b.entity.eid,
|
|
125
|
+
str(comp(b, 'created').via)
|
|
126
|
+
]));
|
|
127
|
+
let sessions = unique([
|
|
128
|
+
...writer.values()
|
|
129
|
+
]);
|
|
130
|
+
let open = new Set((sessions.length ? await tx.get(sessions, [
|
|
131
|
+
SESSION
|
|
132
|
+
]) : []).filter((b)=>b[SESSION] && comp(b, SESSION).ended != true && comp(b, SESSION).operator != true).map((b)=>b.entity.eid));
|
|
133
|
+
return new Set(letters.filter((b)=>open.has(writer.get(to(b)) ?? '')));
|
|
134
|
+
};
|
|
135
|
+
let routed = async (bundles, items, tx)=>{
|
|
136
|
+
let project = await helped(tx, unique(items.map(target)));
|
|
137
|
+
let mine = items.filter((b)=>project.has(target(b)));
|
|
138
|
+
if (!mine.length) return bundles;
|
|
139
|
+
let knocks = mine.filter((b)=>b.knock);
|
|
140
|
+
let letters = mine.filter((b)=>!b.knock);
|
|
141
|
+
let writer = writers(bundles);
|
|
142
|
+
let from = (b)=>str(comp(b, 'knock').from) || str(writer(b.entity.eid).by);
|
|
143
|
+
let via = (b)=>str(writer(b.entity.eid).via);
|
|
144
|
+
let people = await wearing(tx, unique(mine.map(from)), 'person');
|
|
145
|
+
let sessions = unique(knocks.map(via));
|
|
146
|
+
let senders = new Map((sessions.length ? await tx.get(sessions, [
|
|
147
|
+
HELPING,
|
|
148
|
+
SESSION,
|
|
149
|
+
'spawned'
|
|
150
|
+
]) : []).map((b)=>[
|
|
151
|
+
b.entity.eid,
|
|
152
|
+
b
|
|
153
|
+
]));
|
|
154
|
+
let update = (b)=>!b.comment && comp(senders.get(via(b)), 'spawned').parent == target(b) ? str(comp(b, 'knock').about) : '';
|
|
155
|
+
let tasks = await wearing(tx, unique(knocks.map(update)), 'task');
|
|
156
|
+
let direct = (b)=>{
|
|
157
|
+
let sender = senders.get(via(b));
|
|
158
|
+
return sender?.[HELPING] || comp(sender, SESSION).topic || tasks.has(update(b));
|
|
159
|
+
};
|
|
160
|
+
let theirs = await answering(tx, letters);
|
|
161
|
+
let routine = new Set([
|
|
162
|
+
...knocks.filter((b)=>!people.has(from(b)) && !direct(b)),
|
|
163
|
+
...letters.filter((b)=>!people.has(from(b)) && !theirs.has(b))
|
|
164
|
+
]);
|
|
165
|
+
return bundles.map((b)=>routine.has(b) ? {
|
|
166
|
+
...b,
|
|
167
|
+
[ROUTINE]: {
|
|
168
|
+
project: project.get(target(b))
|
|
169
|
+
}
|
|
170
|
+
} : b);
|
|
171
|
+
};
|
|
172
|
+
/** The write hook that marks a routine knock or letter `routine{project}`. */ export let routing = hook([
|
|
173
|
+
'knock',
|
|
174
|
+
'mail'
|
|
175
|
+
], (bundles, tx)=>{
|
|
176
|
+
let items = bundles.filter((b)=>target(b) && !(ROUTINE in b));
|
|
177
|
+
return items.length ? routed(bundles, items, tx) : bundles;
|
|
178
|
+
});
|
|
179
|
+
//# sourceMappingURL=routine.js.map
|
package/routine.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routine.js","sources":["./routine.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wBAAwB;AACxB,EAAE;AACF,uEAAuE;AACvE,4EAA4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AI,OAAO,KAChE,IAAI,KAAK,GAAG,SAAS,KAAK,IAC1B;EACN,IAAI,QAAQ,MAAM,QAAQ,IAAI,OAAO,OAAO,GAAG,CAAC,UAAU;EAC1D,IAAI,SAAS,CAAC;IACZ,IAAI,SAAS,QAAQ,GAAG,CAAC,IAAI;IAC7B,OAAO,QAAQ,CAAC,QAAQ,IAAI,KAAK,QAAQ,SAAS,KAAK,IACrD,MAAM,GAAG,CAAC,OAAO;EACrB;EACA,IAAI,SAAS,MAAM,UAAU,IAAI;EACjC,IAAI,UAAU,IAAI,IAAI;OACjB,OAAO,MAAM,CAAC,CAAC,IAAM,CAAC,OAAO,GAAG,CAAC,KAAK,OAAO,CAAC,OAAO;OACrD,QAAQ,MAAM,CAAC,CAAC,IAAM,CAAC,OAAO,GAAG,CAAC,KAAK,OAAO,CAAC,OAAO,GAAG,CAAC;GAC9D;EACD,OAAO,QAAQ,GAAG,CAAC,CAAC,IAClB,QAAQ,GAAG,CAAC,KACR;MAAE,GAAG,CAAC;MAAE,CAAC,QAAQ,EAAE;QAAE,SAAS,QAAQ,GAAG,CAAC,OAAO;MAAI;IAAE,IACvD;AAER;AAEA,4EAA4E,GAC5E,OAAO,IAAI,UAAU,KACnB;EAAC;EAAS;CAAO,EACjB,CAAC,SAAS;EACR,IAAI,QAAQ,QAAQ,MAAM,CAAC,CAAC,IAAM,OAAO,MAAM,CAAC,CAAC,WAAW,CAAC;EAC7D,OAAO,MAAM,MAAM,GAAG,OAAO,SAAS,OAAO,MAAM;AACrD,GACD"}
|
package/routine.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// The rule on a knock or an arriving letter: whose it is, settled in the
|
|
2
|
+
// write that leaves it.
|
|
3
|
+
//
|
|
4
|
+
// A project wearing `helper{persona, provider, model, effort}` has its
|
|
5
|
+
// operator's routine taken by a helper (./help.ts). An item is routine when
|
|
6
|
+
// it is addressed to that operator and is not for the operator's own session.
|
|
7
|
+
//
|
|
8
|
+
// Addressed to the operator:
|
|
9
|
+
//
|
|
10
|
+
// - a knock at the project, at a project filed under it at any depth, or at a
|
|
11
|
+
// session a person opened (`session.operator`) wearing a persona homed
|
|
12
|
+
// there;
|
|
13
|
+
// - a letter that arrived (no `deliver`) for one of those projects or for an
|
|
14
|
+
// address filed under one (@yaks/mail's `mail.target`), unless it answers a
|
|
15
|
+
// letter another session wrote that may still hear the answer
|
|
16
|
+
// (./listen.ts).
|
|
17
|
+
//
|
|
18
|
+
// The operator's own:
|
|
19
|
+
//
|
|
20
|
+
// - a person's act or words: `knock.from` (@yaks/notify), else whoever wrote
|
|
21
|
+
// the knock or the letter, wears `person`. @yaks/mail names a letter's
|
|
22
|
+
// writer only where its edge vouched for the From address, so a letter
|
|
23
|
+
// that merely says it is from a person is routine. A watcher's knock
|
|
24
|
+
// telling of the owner's comment or answer, his text and his mail all name
|
|
25
|
+
// him so.
|
|
26
|
+
// - a hand-up: the knock was written through a session wearing `helping`, or
|
|
27
|
+
// through one opened on a topic (@yaks/topic's `session.topic`, read by
|
|
28
|
+
// name). The session that stays on a topic is no helper, and a hand-up is
|
|
29
|
+
// all of its writing that reaches another session.
|
|
30
|
+
// - a task update a worker knocks its parent with. A run's exit report
|
|
31
|
+
// carries a comment on the task.
|
|
32
|
+
//
|
|
33
|
+
// A routine item gets `routine{project}` in the same batch, so no listener
|
|
34
|
+
// ever reads it as the operator's (./listen.ts leaves it out) and
|
|
35
|
+
// `session_help` is owed by the commit that wrote it.
|
|
36
|
+
|
|
37
|
+
import type { Bundle, Comp, Eid } from 'jsr:@yaks/graph@0.2.36/bundle'
|
|
38
|
+
import { hook } from '@yaks/graph/plugin'
|
|
39
|
+
import type { Tx } from '@yaks/graph'
|
|
40
|
+
import { writers } from '@yaks/graph'
|
|
41
|
+
import { SESSION } from './comp.js'
|
|
42
|
+
|
|
43
|
+
/** On a project: its operator's routine goes to a helper. */
|
|
44
|
+
export let HELPER = 'helper'
|
|
45
|
+
/** On a session: a helper, and the project whose operator it helps. */
|
|
46
|
+
export let HELPING = 'helping'
|
|
47
|
+
/** On a knock or a letter: a helper's to take. */
|
|
48
|
+
export let ROUTINE = 'routine'
|
|
49
|
+
|
|
50
|
+
let comp = (b: Bundle | undefined, name: string): Comp =>
|
|
51
|
+
(b?.[name] ?? {}) as Comp
|
|
52
|
+
let str = (v: unknown): string => typeof v == 'string' ? v : ''
|
|
53
|
+
let unique = (ids: string[]): Eid[] => [...new Set(ids.filter(Boolean))]
|
|
54
|
+
|
|
55
|
+
// What an item is addressed to: a knock's target, or the entity a letter
|
|
56
|
+
// that arrived is for.
|
|
57
|
+
let target = (b: Bundle): string =>
|
|
58
|
+
str(comp(b, 'knock').target) ||
|
|
59
|
+
(b.mail && !b.deliver ? str(comp(b, 'mail').target) : '')
|
|
60
|
+
|
|
61
|
+
// Which of `ids` wear `name`.
|
|
62
|
+
let wearing = async (tx: Tx, ids: Eid[], name: string): Promise<Set<Eid>> =>
|
|
63
|
+
new Set(
|
|
64
|
+
(ids.length ? await tx.get(ids, [name]) : [])
|
|
65
|
+
.filter((b) => b[name]).map((b) => b.entity.eid),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
// How far up a line of projects is followed: a longer one is a cycle.
|
|
69
|
+
let DEPTH = 8
|
|
70
|
+
|
|
71
|
+
// The nearest project wearing `helper` at or above each of these projects.
|
|
72
|
+
// An operator hears what is held for its persona's home and for every
|
|
73
|
+
// project filed under it (./listen.ts `below`), so its helper takes the same.
|
|
74
|
+
let nearest = async (tx: Tx, projects: Eid[]): Promise<Map<Eid, Eid>> => {
|
|
75
|
+
let found = new Map<Eid, Eid>()
|
|
76
|
+
let at = new Map(projects.map((p) => [p, p]))
|
|
77
|
+
for (let depth = 0; at.size && depth < DEPTH; depth++) {
|
|
78
|
+
let rows = new Map(
|
|
79
|
+
(await tx.get(unique([...at.values()]), [HELPER, 'project', 'filed']))
|
|
80
|
+
.map((b) => [b.entity.eid, b]),
|
|
81
|
+
)
|
|
82
|
+
for (let [start, here] of [...at]) {
|
|
83
|
+
let b = rows.get(here)
|
|
84
|
+
let up = b?.project ? str(comp(b, 'filed').project) : ''
|
|
85
|
+
if (b?.[HELPER]) found.set(start, here)
|
|
86
|
+
if (b?.[HELPER] || !up) at.delete(start)
|
|
87
|
+
else at.set(start, up)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return found
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// The helped project each addressed entity leads to: from a project, itself
|
|
94
|
+
// or the nearest above it; from a session a person opened, the home of the
|
|
95
|
+
// persona it wears; from an address, the project it is filed under.
|
|
96
|
+
let helped = async (tx: Tx, targets: Eid[]): Promise<Map<Eid, Eid>> => {
|
|
97
|
+
let rows = await tx.get(targets, [
|
|
98
|
+
HELPER,
|
|
99
|
+
SESSION,
|
|
100
|
+
'project',
|
|
101
|
+
'email',
|
|
102
|
+
'filed',
|
|
103
|
+
])
|
|
104
|
+
let worn = (b: Bundle) =>
|
|
105
|
+
comp(b, SESSION).operator == true ? str(comp(b, SESSION).persona) : ''
|
|
106
|
+
let personas = unique(rows.map(worn))
|
|
107
|
+
let home = new Map(
|
|
108
|
+
(personas.length ? await tx.get(personas, ['persona']) : [])
|
|
109
|
+
.map((b) => [b.entity.eid, str(comp(b, 'persona').home)]),
|
|
110
|
+
)
|
|
111
|
+
let lead = (b: Bundle) =>
|
|
112
|
+
b[HELPER] || b.project
|
|
113
|
+
? b.entity.eid
|
|
114
|
+
: home.get(worn(b)) ?? (b.email ? str(comp(b, 'filed').project) : '')
|
|
115
|
+
let leads = unique(rows.map(lead))
|
|
116
|
+
let projects = leads.length ? await nearest(tx, leads) : new Map<Eid, Eid>()
|
|
117
|
+
return new Map(
|
|
118
|
+
rows.filter((b) => projects.has(lead(b)))
|
|
119
|
+
.map((b) => [b.entity.eid, projects.get(lead(b))!]),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The letters among these that answer one another session wrote and may
|
|
124
|
+
// still hear the answer to: that session's, not the project's. A session a
|
|
125
|
+
// person opened is the operator the letter is addressed to already.
|
|
126
|
+
let answering = async (tx: Tx, letters: Bundle[]): Promise<Set<Bundle>> => {
|
|
127
|
+
let to = (b: Bundle) => str(comp(b, 'mail').reply_to)
|
|
128
|
+
let answered = unique(letters.map(to))
|
|
129
|
+
let writer = new Map(
|
|
130
|
+
(answered.length ? await tx.get(answered, ['created']) : [])
|
|
131
|
+
.map((b) => [b.entity.eid, str(comp(b, 'created').via)]),
|
|
132
|
+
)
|
|
133
|
+
let sessions = unique([...writer.values()])
|
|
134
|
+
let open = new Set(
|
|
135
|
+
(sessions.length ? await tx.get(sessions, [SESSION]) : [])
|
|
136
|
+
.filter((b) =>
|
|
137
|
+
b[SESSION] && comp(b, SESSION).ended != true &&
|
|
138
|
+
comp(b, SESSION).operator != true
|
|
139
|
+
).map((b) => b.entity.eid),
|
|
140
|
+
)
|
|
141
|
+
return new Set(letters.filter((b) => open.has(writer.get(to(b)) ?? '')))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let routed = async (bundles: Bundle[], items: Bundle[], tx: Tx) => {
|
|
145
|
+
let project = await helped(tx, unique(items.map(target)))
|
|
146
|
+
let mine = items.filter((b) => project.has(target(b)))
|
|
147
|
+
if (!mine.length) return bundles
|
|
148
|
+
let knocks = mine.filter((b) => b.knock)
|
|
149
|
+
let letters = mine.filter((b) => !b.knock)
|
|
150
|
+
let writer = writers(bundles)
|
|
151
|
+
let from = (b: Bundle) =>
|
|
152
|
+
str(comp(b, 'knock').from) || str(writer(b.entity.eid).by)
|
|
153
|
+
let via = (b: Bundle) => str(writer(b.entity.eid).via)
|
|
154
|
+
let people = await wearing(tx, unique(mine.map(from)), 'person')
|
|
155
|
+
let sessions = unique(knocks.map(via))
|
|
156
|
+
let senders = new Map(
|
|
157
|
+
(sessions.length
|
|
158
|
+
? await tx.get(sessions, [HELPING, SESSION, 'spawned'])
|
|
159
|
+
: [])
|
|
160
|
+
.map((b) => [b.entity.eid, b]),
|
|
161
|
+
)
|
|
162
|
+
let update = (b: Bundle) =>
|
|
163
|
+
!b.comment && comp(senders.get(via(b)), 'spawned').parent == target(b)
|
|
164
|
+
? str(comp(b, 'knock').about)
|
|
165
|
+
: ''
|
|
166
|
+
let tasks = await wearing(tx, unique(knocks.map(update)), 'task')
|
|
167
|
+
let direct = (b: Bundle) => {
|
|
168
|
+
let sender = senders.get(via(b))
|
|
169
|
+
return sender?.[HELPING] || comp(sender, SESSION).topic ||
|
|
170
|
+
tasks.has(update(b))
|
|
171
|
+
}
|
|
172
|
+
let theirs = await answering(tx, letters)
|
|
173
|
+
let routine = new Set([
|
|
174
|
+
...knocks.filter((b) => !people.has(from(b)) && !direct(b)),
|
|
175
|
+
...letters.filter((b) => !people.has(from(b)) && !theirs.has(b)),
|
|
176
|
+
])
|
|
177
|
+
return bundles.map((b) =>
|
|
178
|
+
routine.has(b)
|
|
179
|
+
? { ...b, [ROUTINE]: { project: project.get(target(b)) } }
|
|
180
|
+
: b
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The write hook that marks a routine knock or letter `routine{project}`. */
|
|
185
|
+
export let routing = hook(
|
|
186
|
+
['knock', 'mail'],
|
|
187
|
+
(bundles, tx) => {
|
|
188
|
+
let items = bundles.filter((b) => target(b) && !(ROUTINE in b))
|
|
189
|
+
return items.length ? routed(bundles, items, tx) : bundles
|
|
190
|
+
},
|
|
191
|
+
)
|