@yaks/memory 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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +309 -2
  3. package/_dist/comp.d.ts +9 -0
  4. package/_dist/comp.d.ts.map +1 -0
  5. package/_dist/earlier.d.ts +108 -0
  6. package/_dist/earlier.d.ts.map +1 -0
  7. package/_dist/graph.d.ts +13 -0
  8. package/_dist/graph.d.ts.map +1 -0
  9. package/_dist/inspect.d.ts +28 -0
  10. package/_dist/inspect.d.ts.map +1 -0
  11. package/_dist/mod.d.ts +54 -0
  12. package/_dist/mod.d.ts.map +1 -0
  13. package/_dist/passage.d.ts +19 -0
  14. package/_dist/passage.d.ts.map +1 -0
  15. package/_dist/recall.d.ts +67 -0
  16. package/_dist/recall.d.ts.map +1 -0
  17. package/_dist/save.d.ts +45 -0
  18. package/_dist/save.d.ts.map +1 -0
  19. package/_dist/tools.d.ts +12 -0
  20. package/_dist/tools.d.ts.map +1 -0
  21. package/_dist/views.d.ts +17 -0
  22. package/_dist/views.d.ts.map +1 -0
  23. package/_dist/vocab.d.ts +7 -0
  24. package/_dist/vocab.d.ts.map +1 -0
  25. package/around.js +141 -0
  26. package/around.js.map +1 -0
  27. package/around.ts +152 -0
  28. package/comp.js +42 -0
  29. package/comp.js.map +1 -0
  30. package/comp.ts +45 -0
  31. package/deno.json +1 -0
  32. package/earlier.js +386 -0
  33. package/earlier.js.map +1 -0
  34. package/earlier.ts +494 -0
  35. package/graph.js +138 -0
  36. package/graph.js.map +1 -0
  37. package/graph.ts +133 -0
  38. package/inspect.js +168 -0
  39. package/inspect.js.map +1 -0
  40. package/inspect.ts +169 -0
  41. package/mod.js +54 -0
  42. package/mod.js.map +1 -0
  43. package/mod.ts +55 -0
  44. package/package.json +51 -4
  45. package/passage.js +67 -0
  46. package/passage.js.map +1 -0
  47. package/passage.ts +75 -0
  48. package/recall.js +145 -0
  49. package/recall.js.map +1 -0
  50. package/recall.ts +180 -0
  51. package/save.js +93 -0
  52. package/save.js.map +1 -0
  53. package/save.ts +113 -0
  54. package/tools.js +246 -0
  55. package/tools.js.map +1 -0
  56. package/tools.ts +250 -0
  57. package/views.js +18 -0
  58. package/views.js.map +1 -0
  59. package/views.ts +23 -0
  60. package/vocab.js +14 -0
  61. package/vocab.js.map +1 -0
  62. package/vocab.json +456 -0
  63. package/vocab.ts +16 -0
package/graph.ts ADDED
@@ -0,0 +1,133 @@
1
+ // What a write is answered with from memory: the `reply` the graph facet
2
+ // gives the host, beside the neighbours @yaks/embedding answers with.
3
+ //
4
+ // An agent that writes a task, a comment or a memory is told what the graph's
5
+ // person said and decided before that bears on it: their few nearest earlier
6
+ // words, and the nearest decisions already answered (./earlier.ts `bearing`).
7
+ // A prompt recalls by the person's message; this recalls by what the agent is
8
+ // doing about it, which is where a correction it never saw would have helped.
9
+ // Each is a `hit` naming, under `said`, the entity it bears on and, under
10
+ // `by`, who said it. What the calling session wrote or was told since its
11
+ // latest compaction is left out: it holds that already. The person's own
12
+ // writes are answered with nothing.
13
+ //
14
+ // Nothing here fails or holds a write: it committed before a reply is asked
15
+ // for, and a recall slower than WAIT answers nothing.
16
+
17
+ import { type Bundle, type Comp, type Eid, who } from '@yaks/graph'
18
+ import { called } from '@yaks/graph/hit'
19
+ import type { Host } from 'jsr:@yaks/host@0.2.36'
20
+ import { and, eq, present } from '@yaks/query'
21
+ import { became, type Reply } from '@yaks/tools'
22
+ import { bearing, clip, type Held, titleOf } from './earlier.js'
23
+
24
+ /** How long a write's answer waits for what was said before, in
25
+ * milliseconds: as long as it waits for its neighbours (@yaks/embedding
26
+ * `WAIT`), which are asked at the same time. */
27
+ export let WAIT = 1000
28
+
29
+ /** How many of one call's new entities are looked at. */
30
+ export let MOST = 3
31
+
32
+ /** How much of a written entity's text the recall is keyed on. */
33
+ export let TEXT = 4000
34
+
35
+ let part = (b: Bundle | undefined, c: string): Comp => (b?.[c] ?? {}) as Comp
36
+ let str = (v: unknown): string => typeof v == 'string' ? v : ''
37
+
38
+ /** The text of something written, as a recall is keyed on it: its title and
39
+ * its words. */
40
+ export let textOf = (b: Bundle): string =>
41
+ [part(b, 'doc').title, part(b, 'doc').body, part(b, 'content').body]
42
+ .map(str).filter((s) => s.trim()).join('\n').slice(0, TEXT)
43
+
44
+ // What the session behind a call already holds: everything since its latest
45
+ // compaction, or since it began.
46
+ let held = async (host: Host, via?: Eid): Promise<Held | undefined> => {
47
+ if (!via) return
48
+ let cuts = host.vocab.comp('checkpoint') && host.vocab.comp('entry')
49
+ ? await host.graph.read(
50
+ and(eq('entry.session', via), present('checkpoint')),
51
+ )
52
+ : []
53
+ let since = cuts.map((b) => str(part(b, 'created').at)).sort().at(-1)
54
+ return { via, since }
55
+ }
56
+
57
+ /** The reply: for each entity the call's write made, the person's nearest
58
+ * earlier words and answered decisions, as `hit` bundles. */
59
+ export let reply = (host: Host): Reply => async (call, _answer, wrote) => {
60
+ let configured = host.config.person
61
+ if (!configured || !host.meaning) return []
62
+ let born = wrote.filter((b) =>
63
+ (became(host.vocab, b) ?? 'entity') != 'entity'
64
+ )
65
+ .map((b) => b.entity.eid)
66
+ if (!born.length) return []
67
+ let person = (await host.graph.address([configured])).get(configured) ??
68
+ configured
69
+ let actor = who(call)
70
+ if (actor?.by == person) return []
71
+ let [p] = await host.graph.get([person], ['doc'])
72
+ let name = str(part(p, 'doc').title)
73
+ let made = (await host.graph.get(born.slice(0, MOST), ['doc', 'content']))
74
+ .filter((b) => textOf(b).trim())
75
+ if (!made.length) return []
76
+ let holds = await held(host, actor?.via)
77
+ let before = new Date().toISOString()
78
+ let id = called(host.vocab)
79
+ let shown = new Set<Eid>()
80
+ let out: Bundle[] = []
81
+ let found = await Promise.all(made.map((b) =>
82
+ bearing(host.graph, {
83
+ person,
84
+ name,
85
+ words: textOf(b),
86
+ before,
87
+ meaning: host.meaning,
88
+ held: holds,
89
+ wait: WAIT,
90
+ })
91
+ ))
92
+ // Each row whole, for the kind its components make it and its status, and
93
+ // the ids the comments among them are on: a comment's words alone do not
94
+ // say which task they are about.
95
+ let rows = found.flatMap((f) => [...f.said.map((q) => q.from), ...f.decided])
96
+ let targets = rows.map((b) => str(part(b, 'comment').target)).filter(Boolean)
97
+ let whole = new Map(
98
+ (await host.graph.get([
99
+ ...new Set([...rows.map((b) => b.entity.eid), ...targets]),
100
+ ])).map((b) => [b.entity.eid, b]),
101
+ )
102
+ let status = (b: Bundle) =>
103
+ Object.values(b).map((c) => str((c as Comp | null)?.status)).find(Boolean)
104
+ made.forEach((b, i) => {
105
+ let hit = (found: Bundle, rest: Comp) => {
106
+ let from = whole.get(found.entity.eid) ?? found
107
+ if (shown.has(from.entity.eid)) return
108
+ shown.add(from.entity.eid)
109
+ let state = status(from)
110
+ out.push({
111
+ entity: from.entity,
112
+ hit: {
113
+ id: id(from),
114
+ kind: host.vocab.kindOf(from),
115
+ source: 'meaning',
116
+ said: b.entity.eid,
117
+ ...name ? { by: name } : {},
118
+ ...state ? { status: state } : {},
119
+ ...rest,
120
+ },
121
+ })
122
+ }
123
+ for (let q of found[i].said) {
124
+ let target = whole.get(str(part(q.from, 'comment').target))
125
+ hit(q.from, {
126
+ ...target ? { target: id(target) } : {},
127
+ snippet: `${q.at.slice(0, 10)} ${JSON.stringify(clip(q.words))}`,
128
+ })
129
+ }
130
+ for (let d of found[i].decided) hit(d, { title: titleOf(d), snippet: '' })
131
+ })
132
+ return out
133
+ }
package/inspect.js ADDED
@@ -0,0 +1,168 @@
1
+ /**
2
+ * How a belief reads in the inspector (@yaks/inspect): the `/views` facet's
3
+ * `inspectViews`, `Inspect.Page`, drawn ahead of the page any entity has,
4
+ * most specific match first. It draws what is its own and asks the inspector
5
+ * for the parts any page has (`io.show`: the head, the body, the facts, the
6
+ * links, the history).
7
+ *
8
+ * - A belief says what it says in full, what it is about and where it holds,
9
+ * then what it was built from: each memory it cites (`cites` edges), the
10
+ * words verbatim with who said them, when and where, the line of context
11
+ * somebody wrote about them, and the conversation around them where they
12
+ * were said in one, as the package that keeps conversations draws it
13
+ * (`Inspect.Conversation`, @yaks/session).
14
+ * - In a topic's lists (`Topic.List.Tile`, @yaks/topic), a belief reads as
15
+ * what it states, and where it holds.
16
+ *
17
+ * @module
18
+ */ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from "react";
19
+ import { parse } from "@yaks/query";
20
+ import * as ui from "@yaks/ui";
21
+ import { mention, Part, useNamed, usePageNotes } from "@yaks/inspect";
22
+ import { words } from "./recall.js";
23
+ import { AROUND, statement } from "./views.js";
24
+ let comp = (b, name)=>b?.[name] ?? {};
25
+ let str = (b, name, prop)=>{
26
+ let v = comp(b, name)[prop];
27
+ return typeof v == 'string' ? v : '';
28
+ };
29
+ let rows = (a)=>a?.rows ?? [];
30
+ /** One memory a belief cites: the words verbatim, who said them, when and
31
+ * where, what somebody wrote about them, and, where they were said in a
32
+ * conversation, the turns around them, drawn as the package that keeps the
33
+ * conversation draws it (`Inspect.Conversation`). */ export let Cited = ({ e: m, io })=>{
34
+ let by = str(m, 'created', 'by');
35
+ let session = str(m, 'entry', 'session');
36
+ let on = str(m, 'comment', 'target');
37
+ useNamed(io, [
38
+ by,
39
+ session,
40
+ on
41
+ ]);
42
+ let when = str(m, 'created', 'at');
43
+ let where = [
44
+ session ? /*#__PURE__*/ h('span', {
45
+ key: 'in'
46
+ }, 'in ', mention(io, session)) : null,
47
+ on ? /*#__PURE__*/ h('span', {
48
+ key: 'on'
49
+ }, 'on ', mention(io, on)) : null
50
+ ];
51
+ return /*#__PURE__*/ h('div', {
52
+ 'data-cited': m.entity.eid
53
+ }, /*#__PURE__*/ h(ui.Quote, {}, /*#__PURE__*/ h(ui.Quote.Text, {}, words(m)), /*#__PURE__*/ h(ui.Quote.By, {}, by ? mention(io, by) : null, when ? /*#__PURE__*/ h('span', {
54
+ title: when
55
+ }, io.when(when)) : null, ...where.filter(Boolean), /*#__PURE__*/ h('a', {
56
+ href: io.link(m.entity.eid)
57
+ }, m.feedback ? 'a correction' : 'the memory')), str(m, 'memory', 'context') ? /*#__PURE__*/ h(ui.Quote.Note, {}, str(m, 'memory', 'context')) : null), io.show(m, 'Inspect.Conversation', {
58
+ ...AROUND,
59
+ whole: false
60
+ }));
61
+ };
62
+ /** What a belief was built from: each memory it cites, read in place. */ let Evidence = ({ e, io, notes })=>{
63
+ let eid = e.entity.eid;
64
+ let got = io.ask({
65
+ cites: `.cites&.edge.from=${eid}&?edge`
66
+ });
67
+ let cited = rows(got.cites).map((b)=>str(b, 'edge', 'to')).filter(Boolean);
68
+ let whole = io.ask(cited.length ? {
69
+ cited: `.entity.eid=${cited.join(',')}&*`
70
+ } : {});
71
+ let held = new Map(rows(whole.cited).map((b)=>[
72
+ b.entity.eid,
73
+ b
74
+ ]));
75
+ let ready = got.cites?.ready && (!cited.length || whole.cited?.ready);
76
+ return /*#__PURE__*/ h(Part, {
77
+ io,
78
+ eid,
79
+ subject: io.id(e),
80
+ heading: 'Built from',
81
+ count: got.cites?.ready ? cited.length : undefined,
82
+ notes
83
+ }, got.cites?.error || whole.cited?.error ? /*#__PURE__*/ h(ui.Rows.More, {}, got.cites?.error ?? whole.cited?.error) : !ready && !held.size ? /*#__PURE__*/ h(ui.Loading, {}) : !cited.length ? /*#__PURE__*/ h(ui.Rows.More, {}, 'it cites nothing') : cited.map((to)=>{
84
+ let m = held.get(to);
85
+ return m ? io.show(m, 'Belief.Cited', {}) : !whole.cited?.ready ? /*#__PURE__*/ h(ui.Loading, {
86
+ key: to
87
+ }) : /*#__PURE__*/ h(ui.Rows.More, {
88
+ key: to
89
+ }, mention(io, to), ' is gone');
90
+ }));
91
+ };
92
+ /** A belief's page. */ export let BeliefPage = ({ e, io })=>{
93
+ let notes = usePageNotes(io, e, [
94
+ 'Built from'
95
+ ]);
96
+ let about = str(e, 'belief', 'about');
97
+ let scope = str(e, 'belief', 'scope');
98
+ useNamed(io, [
99
+ about,
100
+ scope
101
+ ]);
102
+ let sub = [
103
+ about ? [
104
+ 'about ',
105
+ mention(io, about)
106
+ ] : 'about nothing',
107
+ ' · ',
108
+ scope ? [
109
+ 'holds for ',
110
+ mention(io, scope)
111
+ ] : 'holds everywhere'
112
+ ];
113
+ return /*#__PURE__*/ h('div', {
114
+ 'data-inspect': e.entity.eid
115
+ }, io.show(e, 'Inspect.Head', {
116
+ sub,
117
+ notes: notes.get('')
118
+ }), io.show(e, 'Inspect.Body'), /*#__PURE__*/ h(Evidence, {
119
+ e,
120
+ io,
121
+ notes
122
+ }), io.show(e, 'Inspect.Facts', {
123
+ notes,
124
+ skip: [
125
+ 'belief'
126
+ ]
127
+ }), io.show(e, 'Inspect.Links', {
128
+ notes,
129
+ skip: [
130
+ 'cites'
131
+ ]
132
+ }), io.show(e, 'Inspect.History', {
133
+ notes
134
+ }));
135
+ };
136
+ /** A belief's reading in a topic's lists: what it states, and where it
137
+ * holds. */ export let BeliefTile = ({ e: b, io })=>{
138
+ let scope = str(b, 'belief', 'scope');
139
+ useNamed(io, [
140
+ scope
141
+ ]);
142
+ return /*#__PURE__*/ h(ui.Rows.Item, {
143
+ 'data-belief': b.entity.eid
144
+ }, io.show(b, 'Inspect.Reference.Inline', {}), scope ? [
145
+ ' · for ',
146
+ mention(io, scope)
147
+ ] : null, /*#__PURE__*/ h(ui.Body, {
148
+ mod: 'short'
149
+ }, statement(str(b, 'doc', 'body'))));
150
+ };
151
+ /** The pages this package draws in the inspector. */ export let inspectViews = [
152
+ {
153
+ view: 'Belief.Cited',
154
+ match: parse('.memory'),
155
+ Render: Cited
156
+ },
157
+ {
158
+ view: 'Topic.List.Tile',
159
+ match: parse('.belief'),
160
+ Render: BeliefTile
161
+ },
162
+ {
163
+ view: 'Inspect.Page',
164
+ match: parse('.belief'),
165
+ Render: BeliefPage
166
+ }
167
+ ];
168
+ //# sourceMappingURL=inspect.js.map
package/inspect.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect.js","sources":["./inspect.ts"],"names":[],"mappings":"A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C,GAAG,iBAAiB;IAAE;IAAO,MAAM;MAAC;KAAQ;EAAC,IACrD,GAAG,IAAI,CAAC,GAAG,mBAAmB;IAAE;EAAM;AAE1C,EAAC;AAED;UACU,GACV,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,EAAS;EAC1C,IAAI,QAAQ,IAAI,GAAG,UAAU;EAC7B,SAAS,IAAI;IAAC;GAAM;EACpB,qBAAO,EACL,GAAG,IAAI,CAAC,IAAI,EACZ;IAAE,eAAe,EAAE,MAAM,CAAC,GAAG;EAAC,GAC9B,GAAG,IAAI,CAAC,GAAG,4BAA4B,CAAC,IACxC,QAAQ;IAAC;IAAW,QAAQ,IAAI;GAAO,GAAG,oBAC1C,EAAE,GAAG,IAAI,EAAE;IAAE,KAAK;EAAQ,GAAG,UAAU,IAAI,GAAG,OAAO;AAEzD,EAAC;AAED,mDAAmD,GACnD,OAAO,IAAI,eAAuB;EAChC;IAAE,MAAM;IAAgB,OAAO,MAAM;IAAY,QAAQ;EAAM;EAC/D;IAAE,MAAM;IAAmB,OAAO,MAAM;IAAY,QAAQ;EAAW;EACvE;IAAE,MAAM;IAAgB,OAAO,MAAM;IAAY,QAAQ;EAAW;CACrE,CAAA"}
package/inspect.ts ADDED
@@ -0,0 +1,169 @@
1
+ /**
2
+ * How a belief reads in the inspector (@yaks/inspect): the `/views` facet's
3
+ * `inspectViews`, `Inspect.Page`, drawn ahead of the page any entity has,
4
+ * most specific match first. It draws what is its own and asks the inspector
5
+ * for the parts any page has (`io.show`: the head, the body, the facts, the
6
+ * links, the history).
7
+ *
8
+ * - A belief says what it says in full, what it is about and where it holds,
9
+ * then what it was built from: each memory it cites (`cites` edges), the
10
+ * words verbatim with who said them, when and where, the line of context
11
+ * somebody wrote about them, and the conversation around them where they
12
+ * were said in one, as the package that keeps conversations draws it
13
+ * (`Inspect.Conversation`, @yaks/session).
14
+ * - In a topic's lists (`Topic.List.Tile`, @yaks/topic), a belief reads as
15
+ * what it states, and where it holds.
16
+ *
17
+ * @module
18
+ */
19
+
20
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h, type JSX, type ReactNode } from 'react'
21
+ import { parse } from '@yaks/query'
22
+ import * as ui from '@yaks/ui'
23
+ import {
24
+ type Answer,
25
+ type Bundle,
26
+ type Io,
27
+ mention,
28
+ Part,
29
+ type Props,
30
+ useNamed,
31
+ usePageNotes,
32
+ type View,
33
+ } from '@yaks/inspect'
34
+ import { words } from './recall.js'
35
+
36
+ import { AROUND, statement } from './views.js'
37
+
38
+ type Comp = Record<string, unknown>
39
+ let comp = (b: Bundle | undefined, name: string): Comp =>
40
+ (b?.[name] ?? {}) as Comp
41
+ let str = (b: Bundle | undefined, name: string, prop: string): string => {
42
+ let v = comp(b, name)[prop]
43
+ return typeof v == 'string' ? v : ''
44
+ }
45
+ let rows = (a?: Answer): Bundle[] => a?.rows ?? []
46
+
47
+ /** One memory a belief cites: the words verbatim, who said them, when and
48
+ * where, what somebody wrote about them, and, where they were said in a
49
+ * conversation, the turns around them, drawn as the package that keeps the
50
+ * conversation draws it (`Inspect.Conversation`). */
51
+ export let Cited = ({ e: m, io }: Props): JSX.Element => {
52
+ let by = str(m, 'created', 'by')
53
+ let session = str(m, 'entry', 'session')
54
+ let on = str(m, 'comment', 'target')
55
+ useNamed(io, [by, session, on])
56
+ let when = str(m, 'created', 'at')
57
+ let where: ReactNode[] = [
58
+ session ? h('span', { key: 'in' }, 'in ', mention(io, session)) : null,
59
+ on ? h('span', { key: 'on' }, 'on ', mention(io, on)) : null,
60
+ ]
61
+ return h(
62
+ 'div',
63
+ { 'data-cited': m.entity.eid },
64
+ h(
65
+ ui.Quote,
66
+ {},
67
+ h(ui.Quote.Text, {}, words(m)),
68
+ h(
69
+ ui.Quote.By,
70
+ {},
71
+ by ? mention(io, by) : null,
72
+ when ? h('span', { title: when }, io.when(when)) : null,
73
+ ...where.filter(Boolean),
74
+ h(
75
+ 'a',
76
+ { href: io.link(m.entity.eid) },
77
+ m.feedback ? 'a correction' : 'the memory',
78
+ ),
79
+ ),
80
+ str(m, 'memory', 'context')
81
+ ? h(ui.Quote.Note, {}, str(m, 'memory', 'context'))
82
+ : null,
83
+ ),
84
+ io.show(m, 'Inspect.Conversation', { ...AROUND, whole: false }),
85
+ )
86
+ }
87
+
88
+ /** What a belief was built from: each memory it cites, read in place. */
89
+ let Evidence = (
90
+ { e, io, notes }: { e: Bundle; io: Io; notes: Map<string, Bundle[]> },
91
+ ): JSX.Element => {
92
+ let eid = e.entity.eid
93
+ let got = io.ask({ cites: `.cites&.edge.from=${eid}&?edge` })
94
+ let cited = rows(got.cites).map((b) => str(b, 'edge', 'to')).filter(Boolean)
95
+ let whole = io.ask(
96
+ cited.length ? { cited: `.entity.eid=${cited.join(',')}&*` } : {},
97
+ )
98
+ let held = new Map(rows(whole.cited).map((b) => [b.entity.eid, b]))
99
+ let ready = got.cites?.ready && (!cited.length || whole.cited?.ready)
100
+ return h(
101
+ Part,
102
+ {
103
+ io,
104
+ eid,
105
+ subject: io.id(e),
106
+ heading: 'Built from',
107
+ count: got.cites?.ready ? cited.length : undefined,
108
+ notes,
109
+ },
110
+ got.cites?.error || whole.cited?.error
111
+ ? h(ui.Rows.More, {}, got.cites?.error ?? whole.cited?.error)
112
+ : !ready && !held.size
113
+ ? h(ui.Loading, {})
114
+ : !cited.length
115
+ ? h(ui.Rows.More, {}, 'it cites nothing')
116
+ : cited.map((to) => {
117
+ let m = held.get(to)
118
+ return m
119
+ ? io.show(m, 'Belief.Cited', {})
120
+ : !whole.cited?.ready
121
+ ? h(ui.Loading, { key: to })
122
+ : h(ui.Rows.More, { key: to }, mention(io, to), ' is gone')
123
+ }),
124
+ )
125
+ }
126
+
127
+ /** A belief's page. */
128
+ export let BeliefPage = ({ e, io }: Props): JSX.Element => {
129
+ let notes = usePageNotes(io, e, ['Built from'])
130
+ let about = str(e, 'belief', 'about')
131
+ let scope = str(e, 'belief', 'scope')
132
+ useNamed(io, [about, scope])
133
+ let sub = [
134
+ about ? ['about ', mention(io, about)] : 'about nothing',
135
+ ' · ',
136
+ scope ? ['holds for ', mention(io, scope)] : 'holds everywhere',
137
+ ]
138
+ return h(
139
+ 'div',
140
+ { 'data-inspect': e.entity.eid },
141
+ io.show(e, 'Inspect.Head', { sub, notes: notes.get('') }),
142
+ io.show(e, 'Inspect.Body'),
143
+ h(Evidence, { e, io, notes }),
144
+ io.show(e, 'Inspect.Facts', { notes, skip: ['belief'] }),
145
+ io.show(e, 'Inspect.Links', { notes, skip: ['cites'] }),
146
+ io.show(e, 'Inspect.History', { notes }),
147
+ )
148
+ }
149
+
150
+ /** A belief's reading in a topic's lists: what it states, and where it
151
+ * holds. */
152
+ export let BeliefTile = ({ e: b, io }: Props): JSX.Element => {
153
+ let scope = str(b, 'belief', 'scope')
154
+ useNamed(io, [scope])
155
+ return h(
156
+ ui.Rows.Item,
157
+ { 'data-belief': b.entity.eid },
158
+ io.show(b, 'Inspect.Reference.Inline', {}),
159
+ scope ? [' · for ', mention(io, scope)] : null,
160
+ h(ui.Body, { mod: 'short' }, statement(str(b, 'doc', 'body'))),
161
+ )
162
+ }
163
+
164
+ /** The pages this package draws in the inspector. */
165
+ export let inspectViews: View[] = [
166
+ { view: 'Belief.Cited', match: parse('.memory'), Render: Cited },
167
+ { view: 'Topic.List.Tile', match: parse('.belief'), Render: BeliefTile },
168
+ { view: 'Inspect.Page', match: parse('.belief'), Render: BeliefPage },
169
+ ]
package/mod.js ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @yaks/memory — what a person said, kept in their own words: the `memory`
3
+ * component domain for a {@link https://jsr.io/@yaks/graph | @yaks/graph},
4
+ * with the halves that make it useful — marking what somebody said, having it
5
+ * read back at the start of the next conversation, and reading around it.
6
+ *
7
+ * An agent that summarises what somebody told it can only ever remove
8
+ * information. Everything the summary keeps was already in the sentence, and
9
+ * everything it drops is gone for good — so the next agent, and the one after
10
+ * that, work from a copy of a copy. This package is the other way round: a
11
+ * memory marks the person's sentence where it already is (a session entry, a
12
+ * comment, a doc), and only words the graph holds nowhere get a doc of their
13
+ * own, with the line or two of context somebody needs to read them later.
14
+ *
15
+ * ```ts
16
+ * import { marked, saved } from '@yaks/memory'
17
+ *
18
+ * // [{ entity: { eid: 'entry1' }, memory: { about: 'recipes' } }]
19
+ * marked({ eid: 'entry1', about: 'recipes' })
20
+ * // { entity: { eid: 'm1' },
21
+ * // doc: { body: 'use grams, never cups' },
22
+ * // memory: { space: 's1', about: 'recipes' } }
23
+ * saved({ eid: 'm1', said: 'use grams, never cups', space: 's1',
24
+ * about: 'recipes' })
25
+ * ```
26
+ *
27
+ * The pieces:
28
+ *
29
+ * - {@link memoryDoc} is the component, as JSON Schema — a mark, whose `at`,
30
+ * `by` and `via` the graph stamps;
31
+ * - {@link marked} is the write that marks words the graph already holds, and
32
+ * {@link saved} the one that keeps words it holds nowhere: an empty sentence
33
+ * is rejected, and the context is truncated to {@link LINES} lines so it
34
+ * stays context and never becomes the summary the sentence was saved instead
35
+ * of;
36
+ * - {@link words} reads the words from whichever component holds them;
37
+ * - {@link line} builds the read: a query string in the filter grammar every
38
+ * yaks store answers — with words in it, the store's full-text index selects
39
+ * them; with none, newest first — and {@link ordered} puts what a store
40
+ * returned into the order a ranking by meaning named;
41
+ * - {@link passage} builds the text an agent is given at the start of a
42
+ * conversation: the newest few, whole, under one heading, bounded by
43
+ * {@link LAST} and {@link BYTES}.
44
+ *
45
+ * The tools, including the four that read around a memory, are
46
+ * `@yaks/memory/tools`. It imports no platform API, so the same package runs
47
+ * on a server, in a worker, and in a browser tab.
48
+ *
49
+ * @module
50
+ */ export * from "./comp.js";
51
+ export * from "./save.js";
52
+ export * from "./recall.js";
53
+ export * from "./passage.js";
54
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDC,GAED,0BAAyB;AACzB,0BAAyB;AACzB,4BAA2B;AAC3B,6BAA4B"}
package/mod.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @yaks/memory — what a person said, kept in their own words: the `memory`
3
+ * component domain for a {@link https://jsr.io/@yaks/graph | @yaks/graph},
4
+ * with the halves that make it useful — marking what somebody said, having it
5
+ * read back at the start of the next conversation, and reading around it.
6
+ *
7
+ * An agent that summarises what somebody told it can only ever remove
8
+ * information. Everything the summary keeps was already in the sentence, and
9
+ * everything it drops is gone for good — so the next agent, and the one after
10
+ * that, work from a copy of a copy. This package is the other way round: a
11
+ * memory marks the person's sentence where it already is (a session entry, a
12
+ * comment, a doc), and only words the graph holds nowhere get a doc of their
13
+ * own, with the line or two of context somebody needs to read them later.
14
+ *
15
+ * ```ts
16
+ * import { marked, saved } from '@yaks/memory'
17
+ *
18
+ * // [{ entity: { eid: 'entry1' }, memory: { about: 'recipes' } }]
19
+ * marked({ eid: 'entry1', about: 'recipes' })
20
+ * // { entity: { eid: 'm1' },
21
+ * // doc: { body: 'use grams, never cups' },
22
+ * // memory: { space: 's1', about: 'recipes' } }
23
+ * saved({ eid: 'm1', said: 'use grams, never cups', space: 's1',
24
+ * about: 'recipes' })
25
+ * ```
26
+ *
27
+ * The pieces:
28
+ *
29
+ * - {@link memoryDoc} is the component, as JSON Schema — a mark, whose `at`,
30
+ * `by` and `via` the graph stamps;
31
+ * - {@link marked} is the write that marks words the graph already holds, and
32
+ * {@link saved} the one that keeps words it holds nowhere: an empty sentence
33
+ * is rejected, and the context is truncated to {@link LINES} lines so it
34
+ * stays context and never becomes the summary the sentence was saved instead
35
+ * of;
36
+ * - {@link words} reads the words from whichever component holds them;
37
+ * - {@link line} builds the read: a query string in the filter grammar every
38
+ * yaks store answers — with words in it, the store's full-text index selects
39
+ * them; with none, newest first — and {@link ordered} puts what a store
40
+ * returned into the order a ranking by meaning named;
41
+ * - {@link passage} builds the text an agent is given at the start of a
42
+ * conversation: the newest few, whole, under one heading, bounded by
43
+ * {@link LAST} and {@link BYTES}.
44
+ *
45
+ * The tools, including the four that read around a memory, are
46
+ * `@yaks/memory/tools`. It imports no platform API, so the same package runs
47
+ * on a server, in a worker, and in a browser tab.
48
+ *
49
+ * @module
50
+ */
51
+
52
+ export * from './comp.js'
53
+ export * from './save.js'
54
+ export * from './recall.js'
55
+ export * from './passage.js'
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@yaks/memory",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/memory",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./vocab": {
12
+ "types": "./_dist/vocab.d.ts",
13
+ "default": "./vocab.js"
14
+ },
15
+ "./tools": {
16
+ "types": "./_dist/tools.d.ts",
17
+ "default": "./tools.js"
18
+ },
19
+ "./inspect": {
20
+ "types": "./_dist/inspect.d.ts",
21
+ "default": "./inspect.js"
22
+ },
23
+ "./views": {
24
+ "types": "./_dist/views.d.ts",
25
+ "default": "./views.js"
26
+ },
27
+ "./earlier": {
28
+ "types": "./_dist/earlier.d.ts",
29
+ "default": "./earlier.js"
30
+ },
31
+ "./graph": {
32
+ "types": "./_dist/graph.d.ts",
33
+ "default": "./graph.js"
34
+ }
35
+ },
36
+ "license": "Apache-2.0",
37
+ "dependencies": {
38
+ "@yaks/doc": "0.2.36",
39
+ "@yaks/fts": "0.2.36",
40
+ "@yaks/graph": "0.2.36",
41
+ "@yaks/host": "0.2.36",
42
+ "@yaks/id": "0.2.36",
43
+ "@yaks/inspect": "0.2.36",
44
+ "@yaks/query": "0.2.36",
45
+ "@yaks/tools": "0.2.36",
46
+ "@yaks/ui": "0.2.36",
47
+ "@yaks/vocab": "0.2.36",
48
+ "@types/react": "19.3.0",
49
+ "react": "19.3.0"
50
+ },
51
+ "description": "Stores a person's words with context as graph entities and retrieves them for subsequent conversations.",
52
+ "repository": "https://github.com/yak-sh/yak.git"
53
+ }