@yaks/inbox 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +202 -0
  2. package/Person.tsx +275 -0
  3. package/Project.tsx +83 -0
  4. package/README.md +311 -2
  5. package/_dist/actions-browser.d.ts +8 -0
  6. package/_dist/actions-browser.d.ts.map +1 -0
  7. package/_dist/actions.d.ts +22 -0
  8. package/_dist/actions.d.ts.map +1 -0
  9. package/_dist/asks.d.ts +15 -0
  10. package/_dist/asks.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +12 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/letters.d.ts +24 -0
  14. package/_dist/letters.d.ts.map +1 -0
  15. package/_dist/mail.d.ts +4 -0
  16. package/_dist/mail.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +7 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/options.d.ts +18 -0
  20. package/_dist/options.d.ts.map +1 -0
  21. package/_dist/queries.d.ts +23 -0
  22. package/_dist/queries.d.ts.map +1 -0
  23. package/_dist/read.d.ts +18 -0
  24. package/_dist/read.d.ts.map +1 -0
  25. package/_dist/reader.d.ts +25 -0
  26. package/_dist/reader.d.ts.map +1 -0
  27. package/_dist/service.d.ts +8 -0
  28. package/_dist/service.d.ts.map +1 -0
  29. package/_dist/threads.d.ts +33 -0
  30. package/_dist/threads.d.ts.map +1 -0
  31. package/_dist/tools.d.ts +12 -0
  32. package/_dist/tools.d.ts.map +1 -0
  33. package/_dist/vocab.d.ts +5 -0
  34. package/_dist/vocab.d.ts.map +1 -0
  35. package/actions-browser.js +165 -0
  36. package/actions-browser.js.map +1 -0
  37. package/actions-browser.ts +158 -0
  38. package/actions.js +34 -0
  39. package/actions.js.map +1 -0
  40. package/actions.ts +53 -0
  41. package/asks.js +76 -0
  42. package/asks.js.map +1 -0
  43. package/asks.ts +94 -0
  44. package/deno.json +1 -0
  45. package/front.js +41 -0
  46. package/front.js.map +1 -0
  47. package/front.json +68 -0
  48. package/front.ts +38 -0
  49. package/graph.js +176 -0
  50. package/graph.js.map +1 -0
  51. package/graph.ts +182 -0
  52. package/inspect.tsx +22 -0
  53. package/letters.js +233 -0
  54. package/letters.js.map +1 -0
  55. package/letters.ts +325 -0
  56. package/mail.js +122 -0
  57. package/mail.js.map +1 -0
  58. package/mail.ts +148 -0
  59. package/mod.js +11 -0
  60. package/mod.js.map +1 -0
  61. package/mod.ts +24 -0
  62. package/options.js +15 -0
  63. package/options.js.map +1 -0
  64. package/options.ts +42 -0
  65. package/package.json +76 -4
  66. package/queries.js +240 -0
  67. package/queries.js.map +1 -0
  68. package/queries.ts +302 -0
  69. package/read.js +453 -0
  70. package/read.js.map +1 -0
  71. package/read.ts +476 -0
  72. package/reader.js +105 -0
  73. package/reader.js.map +1 -0
  74. package/reader.ts +147 -0
  75. package/service.js +29 -0
  76. package/service.js.map +1 -0
  77. package/service.ts +45 -0
  78. package/threads.js +182 -0
  79. package/threads.js.map +1 -0
  80. package/threads.ts +276 -0
  81. package/tools.js +101 -0
  82. package/tools.js.map +1 -0
  83. package/tools.ts +103 -0
  84. package/views.tsx +30 -0
  85. package/vocab.js +12 -0
  86. package/vocab.js.map +1 -0
  87. package/vocab.json +242 -0
  88. package/vocab.ts +11 -0
package/front.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "$vocabulary": {
3
+ "https://yak.sh/vocab/core": true
4
+ },
5
+ "title": "inbox front",
6
+ "description": "The inbox views' own state in their page graph, never synced.",
7
+ "$defs": {
8
+ "inboxAction": {
9
+ "component": true,
10
+ "durable": "connection",
11
+ "sync": "server",
12
+ "description": "an action taken on an inbox card",
13
+ "properties": {
14
+ "space": { "type": "string" },
15
+ "kind": { "type": "string" },
16
+ "target": { "type": "string" },
17
+ "answer": { "type": "string" }
18
+ }
19
+ },
20
+ "inboxReceipt": {
21
+ "component": true,
22
+ "durable": "connection",
23
+ "sync": "server",
24
+ "description": "the inbox host's answer to the card action",
25
+ "properties": {
26
+ "label": { "type": "string" },
27
+ "href": {
28
+ "type": "string",
29
+ "description": "where the conversation the action started goes on"
30
+ }
31
+ }
32
+ },
33
+ "inboxActionNote": {
34
+ "component": true,
35
+ "durable": "connection",
36
+ "sync": "none",
37
+ "description": "an action error shown beside the inbox card",
38
+ "properties": {
39
+ "message": { "type": "string" }
40
+ }
41
+ },
42
+ "inboxView": {
43
+ "component": true,
44
+ "type": "object",
45
+ "sync": "none",
46
+ "durable": "connection",
47
+ "description": "the inbox's expanded threads and search switches; words remain synced drafts",
48
+ "properties": {
49
+ "open": {
50
+ "type": "boolean",
51
+ "description": "the thread is expanded"
52
+ },
53
+ "direction": {
54
+ "type": "string",
55
+ "enum": [
56
+ "both",
57
+ "said",
58
+ "received"
59
+ ]
60
+ },
61
+ "all": {
62
+ "type": "boolean",
63
+ "description": "include archived threads"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
package/front.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The inbox views' own state: which threads are expanded and how the search
3
+ * is switched. It is the page's, never the graph's, so it lives in a page
4
+ * graph of the views' own (./front.json), a @yaks/client over RAM that no
5
+ * server hears of, where a remount finds it again. What a person types is a
6
+ * draft (@yaks/draft), kept everywhere, not this.
7
+ *
8
+ * @module
9
+ */
10
+
11
+ import { type Client, client } from '@yaks/client'
12
+ import { derivedEid } from '@yaks/graph/identity'
13
+ import { useRows } from '@yaks/ux'
14
+ import { loadVocab, type VocabDoc } from '@yaks/vocab'
15
+ import doc from './front.json' with { type: 'json' }
16
+
17
+ let made: Client | undefined
18
+
19
+ /** The inbox views' page graph, made when a view first asks for it: a server
20
+ * that imports the views to see what they offer never makes one. */
21
+ export let front = (): Client =>
22
+ made ??= client(loadVocab([doc as VocabDoc]), [], {
23
+ vault: false,
24
+ wireVault: false,
25
+ page: false,
26
+ })
27
+
28
+ /** One view's state at a stable place, read live and changed in place: a
29
+ * thread's (`thread:<eid>`) or a person's search (`search:<eid>`). */
30
+ export let usePage = <T extends Record<string, unknown>>(place: string) => {
31
+ let eid = derivedEid(`inboxView|${place}`)
32
+ let [state] = useRows(front(), `.inboxView .entity.eid=${eid}`)
33
+ return {
34
+ value: state?.inboxView as T | undefined,
35
+ set: (value: Partial<T>) =>
36
+ void front().mutate([{ entity: { eid }, inboxView: value }]),
37
+ }
38
+ }
package/graph.js ADDED
@@ -0,0 +1,176 @@
1
+ // The inbox read is a query result, not a stored snapshot of attention.
2
+ import { derivedEid } from "@yaks/graph/identity";
3
+ import { map, parse } from "@yaks/query";
4
+ import { readInbox, readThread } from "./read.js";
5
+ let request = (query)=>{
6
+ let values = {};
7
+ map(query, (c)=>{
8
+ if (c.kind == 'pred' && c.path[0] == 'inbox_summary' && c.op == '=' && c.value?.kind == 'scalar') {
9
+ values[c.path[1]] = c.value.raw;
10
+ }
11
+ return c;
12
+ });
13
+ if (!values.actor) return;
14
+ return {
15
+ actor: values.actor,
16
+ text: values.text,
17
+ direction: values.direction,
18
+ all: values.all == 'true',
19
+ lane: values.lane,
20
+ thread: values.thread
21
+ };
22
+ };
23
+ let dependencies = [
24
+ 'subscription',
25
+ 'doc',
26
+ 'content',
27
+ 'comment',
28
+ 'entry',
29
+ 'output',
30
+ 'notice',
31
+ 'reasoning',
32
+ 'result',
33
+ 'exception',
34
+ 'refusal',
35
+ 'ask',
36
+ 'call',
37
+ 'stop',
38
+ 'commit',
39
+ 'prompt',
40
+ 'session',
41
+ 'project',
42
+ 'design',
43
+ 'task',
44
+ 'decision',
45
+ 'filed',
46
+ 'mail',
47
+ 'mail_notice',
48
+ 'notified',
49
+ 'knock',
50
+ 'deliver',
51
+ 'notification',
52
+ 'bug',
53
+ 'created',
54
+ 'opened',
55
+ 'archived',
56
+ 'completed',
57
+ 'cancelled',
58
+ 'failed',
59
+ 'blocked',
60
+ 'broken',
61
+ 'resolved',
62
+ 'regressed',
63
+ 'decided',
64
+ 'exit',
65
+ 'requires',
66
+ 'edge'
67
+ ];
68
+ /** The web host's reader executes the same view in its read worker. Other
69
+ * graph hosts calculate it through their own committed read interface. */ export let plugins = (host)=>{
70
+ // Exact completed results only, bounded by entries and bytes. A revision
71
+ // observes external commits too; hosts unable to prove it do not memoize.
72
+ let kept = new Map();
73
+ let pending = new Map();
74
+ let bytes = 0;
75
+ return [
76
+ {
77
+ name: '@yaks/inbox',
78
+ view: (ctx, original)=>{
79
+ let asked = request(original);
80
+ if (!asked || !ctx.vocab) return null;
81
+ let v = ctx.vocab;
82
+ return {
83
+ original,
84
+ vocab: v,
85
+ query: parse(''),
86
+ dependencies: dependencies.filter((c)=>!!v.comp(c)),
87
+ expand: async ()=>{
88
+ if (host.reader) return host.reader.read(original);
89
+ let revision = await host.graph.storage.revision?.();
90
+ let key = JSON.stringify(asked);
91
+ let cached = kept.get(key);
92
+ if (revision !== undefined && cached?.revision === revision) {
93
+ kept.delete(key);
94
+ kept.set(key, cached);
95
+ return structuredClone(cached.value);
96
+ }
97
+ let pendingKey = JSON.stringify([
98
+ key,
99
+ revision
100
+ ]);
101
+ let inFlight = revision === undefined ? undefined : pending.get(pendingKey);
102
+ if (inFlight) return structuredClone(await inFlight);
103
+ let compute = async ()=>{
104
+ let source = {
105
+ read: (query)=>host.graph.read(query, {
106
+ native: true
107
+ }),
108
+ get: (ids, comps)=>host.graph.get(ids, comps, {
109
+ native: true
110
+ })
111
+ };
112
+ let found = asked.thread ? await readThread(source, v, asked.actor, asked.thread) : await readInbox(source, v, asked.actor, asked);
113
+ let threads = Array.isArray(found) ? found : found ? [
114
+ found
115
+ ] : [];
116
+ // Only rows the completed list actually draws cross this door. The
117
+ // historical messages remain on the server until detail is requested.
118
+ let summary = threads.map((t)=>({
119
+ ...t,
120
+ messages: asked.thread ? t.messages : []
121
+ }));
122
+ let params = {
123
+ actor: asked.actor,
124
+ text: asked.text ?? '',
125
+ direction: asked.direction ?? '',
126
+ all: !!asked.all,
127
+ lane: asked.lane ?? '',
128
+ thread: asked.thread ?? ''
129
+ };
130
+ return [
131
+ {
132
+ entity: {
133
+ eid: derivedEid('inbox-summary|' + JSON.stringify(params))
134
+ },
135
+ inbox_summary: {
136
+ ...params,
137
+ threads: summary
138
+ }
139
+ }
140
+ ];
141
+ };
142
+ let work = compute();
143
+ if (revision !== undefined) pending.set(pendingKey, work);
144
+ try {
145
+ let value = await work;
146
+ if (revision !== undefined && await host.graph.storage.revision?.() === revision) {
147
+ let size = JSON.stringify(value).length * 2;
148
+ let old = kept.get(key);
149
+ if (old) bytes -= old.bytes;
150
+ kept.delete(key);
151
+ if (size <= 2 * 1024 * 1024) {
152
+ kept.set(key, {
153
+ revision,
154
+ value: structuredClone(value),
155
+ bytes: size
156
+ });
157
+ bytes += size;
158
+ }
159
+ while(kept.size > 8 || bytes > 2 * 1024 * 1024){
160
+ let first = kept.keys().next().value;
161
+ bytes -= kept.get(first).bytes;
162
+ kept.delete(first);
163
+ }
164
+ }
165
+ return value;
166
+ } finally{
167
+ if (pending.get(pendingKey) === work) pending.delete(pendingKey);
168
+ }
169
+ },
170
+ answer: (rows)=>rows
171
+ };
172
+ }
173
+ }
174
+ ];
175
+ };
176
+ //# sourceMappingURL=graph.js.map
package/graph.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,SAAS,UAAU,oCAAyC;AAC5D,SAAS,GAAG,EAAE,KAAK,2BAA4C;AAE/D,SAAS,SAAS,EAAE,UAAU,oBAAmB;AAIjD,IAAI,UAAU,CAAC;EACb,IAAI,SAAiC,CAAC;EACtC,IAAI,OAAO,CAAC;IACV,IACE,EAAE,IAAI,IAAI,UAAU,EAAE,IAAI,CAAC,EAAE,IAAI,mBAAmB,EAAE,EAAE,IAAI,OAC5D,EAAE,KAAK,EAAE,QAAQ,UACjB;MACA,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG;IACjC;IACA,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aAAa,aACb,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC,QAAQ,SAAS,UAC1C;gBACA,IAAI,OAAO,KAAK,SAAS,CAAC,OAAO,MAAM,GAAG;gBAC1C,IAAI,MAAM,KAAK,GAAG,CAAC;gBACnB,IAAI,KAAK,SAAS,IAAI,KAAK;gBAC3B,KAAK,MAAM,CAAC;gBACZ,IAAI,QAAQ,IAAI,OAAO,MAAM;kBAC3B,KAAK,GAAG,CAAC,KAAK;oBACZ;oBACA,OAAO,gBAAgB;oBACvB,OAAO;kBACT;kBACA,SAAS;gBACX;gBACA,MAAO,KAAK,IAAI,GAAG,KAAK,QAAQ,IAAI,OAAO,KAAM;kBAC/C,IAAI,QAAQ,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK;kBACpC,SAAS,KAAK,GAAG,CAAC,OAAQ,KAAK;kBAC/B,KAAK,MAAM,CAAC;gBACd;cACF;cACA,OAAO;YACT,SAAU;cACR,IAAI,QAAQ,GAAG,CAAC,gBAAgB,MAAM,QAAQ,MAAM,CAAC;YACvD;UACF;UACA,QAAQ,CAAC,OAAS;QACpB;MACF;IACF;GAAE;AACJ,EAAC"}
package/graph.ts ADDED
@@ -0,0 +1,182 @@
1
+ // The inbox read is a query result, not a stored snapshot of attention.
2
+ import type { Bundle, Graph, Plugin } from 'jsr:@yaks/graph@0.2.36'
3
+ import { derivedEid } from '@yaks/graph/identity'
4
+ import { map, parse, type Query } from '@yaks/query'
5
+ import type { Search } from './threads.ts'
6
+ import { readInbox, readThread } from './read.js'
7
+
8
+ export type SummaryRequest = Search & { actor: string; thread?: string }
9
+
10
+ let request = (query: Query): SummaryRequest | undefined => {
11
+ let values: Record<string, string> = {}
12
+ map(query, (c) => {
13
+ if (
14
+ c.kind == 'pred' && c.path[0] == 'inbox_summary' && c.op == '=' &&
15
+ c.value?.kind == 'scalar'
16
+ ) {
17
+ values[c.path[1]] = c.value.raw
18
+ }
19
+ return c
20
+ })
21
+ if (!values.actor) return
22
+ return {
23
+ actor: values.actor,
24
+ text: values.text,
25
+ direction: values.direction as Search['direction'],
26
+ all: values.all == 'true',
27
+ lane: values.lane as Search['lane'],
28
+ thread: values.thread,
29
+ }
30
+ }
31
+ let dependencies = [
32
+ 'subscription',
33
+ 'doc',
34
+ 'content',
35
+ 'comment',
36
+ 'entry',
37
+ 'output',
38
+ 'notice',
39
+ 'reasoning',
40
+ 'result',
41
+ 'exception',
42
+ 'refusal',
43
+ 'ask',
44
+ 'call',
45
+ 'stop',
46
+ 'commit',
47
+ 'prompt',
48
+ 'session',
49
+ 'project',
50
+ 'design',
51
+ 'task',
52
+ 'decision',
53
+ 'filed',
54
+ 'mail',
55
+ 'mail_notice',
56
+ 'notified',
57
+ 'knock',
58
+ 'deliver',
59
+ 'notification',
60
+ 'bug',
61
+ 'created',
62
+ 'opened',
63
+ 'archived',
64
+ 'completed',
65
+ 'cancelled',
66
+ 'failed',
67
+ 'blocked',
68
+ 'broken',
69
+ 'resolved',
70
+ 'regressed',
71
+ 'decided',
72
+ 'exit',
73
+ 'requires',
74
+ 'edge',
75
+ ]
76
+
77
+ /** The web host's reader executes the same view in its read worker. Other
78
+ * graph hosts calculate it through their own committed read interface. */
79
+ export let plugins = (
80
+ host: { graph: Graph; reader?: Pick<Graph, 'read'> },
81
+ ): Plugin[] => {
82
+ // Exact completed results only, bounded by entries and bytes. A revision
83
+ // observes external commits too; hosts unable to prove it do not memoize.
84
+ let kept = new Map<
85
+ string,
86
+ { revision: unknown; value: Bundle[]; bytes: number }
87
+ >()
88
+ let pending = new Map<string, Promise<Bundle[]>>()
89
+ let bytes = 0
90
+ return [{
91
+ name: '@yaks/inbox',
92
+ view: (ctx, original) => {
93
+ let asked = request(original)
94
+ if (!asked || !ctx.vocab) return null
95
+ let v = ctx.vocab
96
+ return {
97
+ original,
98
+ vocab: v,
99
+ query: parse(''),
100
+ dependencies: dependencies.filter((c) => !!v.comp(c)),
101
+ expand: async () => {
102
+ if (host.reader) return host.reader.read(original)
103
+ let revision = await host.graph.storage.revision?.()
104
+ let key = JSON.stringify(asked)
105
+ let cached = kept.get(key)
106
+ if (revision !== undefined && cached?.revision === revision) {
107
+ kept.delete(key)
108
+ kept.set(key, cached)
109
+ return structuredClone(cached.value)
110
+ }
111
+ let pendingKey = JSON.stringify([key, revision])
112
+ let inFlight = revision === undefined
113
+ ? undefined
114
+ : pending.get(pendingKey)
115
+ if (inFlight) return structuredClone(await inFlight)
116
+ let compute = async () => {
117
+ let source: Pick<Graph, 'read' | 'get'> = {
118
+ read: (query) => host.graph.read(query, { native: true }),
119
+ get: (ids: string[], comps?: string[]) =>
120
+ host.graph.get(ids, comps, { native: true }),
121
+ }
122
+ let found = asked.thread
123
+ ? await readThread(source, v, asked.actor, asked.thread)
124
+ : await readInbox(source, v, asked.actor, asked)
125
+ let threads = Array.isArray(found) ? found : found ? [found] : []
126
+ // Only rows the completed list actually draws cross this door. The
127
+ // historical messages remain on the server until detail is requested.
128
+ let summary = threads.map((t) => ({
129
+ ...t,
130
+ messages: asked.thread ? t.messages : [],
131
+ }))
132
+ let params = {
133
+ actor: asked.actor,
134
+ text: asked.text ?? '',
135
+ direction: asked.direction ?? '',
136
+ all: !!asked.all,
137
+ lane: asked.lane ?? '',
138
+ thread: asked.thread ?? '',
139
+ }
140
+ return [{
141
+ entity: {
142
+ eid: derivedEid('inbox-summary|' + JSON.stringify(params)),
143
+ },
144
+ inbox_summary: { ...params, threads: summary },
145
+ }] as Bundle[]
146
+ }
147
+ let work = compute()
148
+ if (revision !== undefined) pending.set(pendingKey, work)
149
+ try {
150
+ let value = await work
151
+ if (
152
+ revision !== undefined &&
153
+ await host.graph.storage.revision?.() === revision
154
+ ) {
155
+ let size = JSON.stringify(value).length * 2
156
+ let old = kept.get(key)
157
+ if (old) bytes -= old.bytes
158
+ kept.delete(key)
159
+ if (size <= 2 * 1024 * 1024) {
160
+ kept.set(key, {
161
+ revision,
162
+ value: structuredClone(value),
163
+ bytes: size,
164
+ })
165
+ bytes += size
166
+ }
167
+ while (kept.size > 8 || bytes > 2 * 1024 * 1024) {
168
+ let first = kept.keys().next().value!
169
+ bytes -= kept.get(first)!.bytes
170
+ kept.delete(first)
171
+ }
172
+ }
173
+ return value
174
+ } finally {
175
+ if (pending.get(pendingKey) === work) pending.delete(pendingKey)
176
+ }
177
+ },
178
+ answer: (rows) => rows,
179
+ }
180
+ },
181
+ }]
182
+ }
package/inspect.tsx ADDED
@@ -0,0 +1,22 @@
1
+ /** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
2
+ // The inbox pages a browsing host draws. The views facet loads these only
3
+ // when that host asks for its inspector registrations.
4
+ import { parse } from 'jsr:@yaks/query@0.2.36'
5
+ import type { View } from 'jsr:@yaks/inspect@0.2.36'
6
+ import { PersonInbox } from './Person.tsx'
7
+ import { ProjectInbox } from './Project.tsx'
8
+
9
+ export let inspectViews: View[] = [
10
+ {
11
+ view: 'Inbox',
12
+ match: parse('.person'),
13
+ Render: ({ e, io, ctx }) => (
14
+ <PersonInbox
15
+ e={e}
16
+ io={io}
17
+ limit={typeof ctx.limit == 'number' ? ctx.limit : undefined}
18
+ />
19
+ ),
20
+ },
21
+ { view: 'Inbox', match: parse('.project'), Render: ProjectInbox },
22
+ ]