@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.
- package/LICENSE +202 -0
- package/README.md +309 -2
- package/_dist/comp.d.ts +9 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/earlier.d.ts +108 -0
- package/_dist/earlier.d.ts.map +1 -0
- package/_dist/graph.d.ts +13 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/inspect.d.ts +28 -0
- package/_dist/inspect.d.ts.map +1 -0
- package/_dist/mod.d.ts +54 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/passage.d.ts +19 -0
- package/_dist/passage.d.ts.map +1 -0
- package/_dist/recall.d.ts +67 -0
- package/_dist/recall.d.ts.map +1 -0
- package/_dist/save.d.ts +45 -0
- package/_dist/save.d.ts.map +1 -0
- package/_dist/tools.d.ts +12 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/views.d.ts +17 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/around.js +141 -0
- package/around.js.map +1 -0
- package/around.ts +152 -0
- package/comp.js +42 -0
- package/comp.js.map +1 -0
- package/comp.ts +45 -0
- package/deno.json +1 -0
- package/earlier.js +386 -0
- package/earlier.js.map +1 -0
- package/earlier.ts +494 -0
- package/graph.js +138 -0
- package/graph.js.map +1 -0
- package/graph.ts +133 -0
- package/inspect.js +168 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +169 -0
- package/mod.js +54 -0
- package/mod.js.map +1 -0
- package/mod.ts +55 -0
- package/package.json +51 -4
- package/passage.js +67 -0
- package/passage.js.map +1 -0
- package/passage.ts +75 -0
- package/recall.js +145 -0
- package/recall.js.map +1 -0
- package/recall.ts +180 -0
- package/save.js +93 -0
- package/save.js.map +1 -0
- package/save.ts +113 -0
- package/tools.js +246 -0
- package/tools.js.map +1 -0
- package/tools.ts +250 -0
- package/views.js +18 -0
- package/views.js.map +1 -0
- package/views.ts +23 -0
- package/vocab.js +14 -0
- package/vocab.js.map +1 -0
- package/vocab.json +456 -0
- package/vocab.ts +16 -0
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
*/ import { type JSX } from "@types/react";
|
|
19
|
+
import { type Props, type View } from "@yaks/inspect";
|
|
20
|
+
/** One memory a belief cites: the words verbatim, who said them, when and
|
|
21
|
+
* where, what somebody wrote about them, and, where they were said in a
|
|
22
|
+
* conversation, the turns around them, drawn as the package that keeps the
|
|
23
|
+
* conversation draws it (`Inspect.Conversation`). */ export declare let Cited: ({}: Props) => JSX.Element;
|
|
24
|
+
/** A belief's page. */ export declare let BeliefPage: ({}: Props) => JSX.Element;
|
|
25
|
+
/** A belief's reading in a topic's lists: what it states, and where it
|
|
26
|
+
* holds. */ export declare let BeliefTile: ({}: Props) => JSX.Element;
|
|
27
|
+
/** The pages this package draws in the inspector. */ export declare let inspectViews: View[];
|
|
28
|
+
//# sourceMappingURL=inspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","sources":["../inspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GAEyC,SAA6B,KAAK,GAAG,uBAA0C;AAGzH,SAME,KAAK,KAAK,EAGV,KAAK,IAAI,6BACsB;AAcjC;;;mDAGmD,GACnD,OAAO,YAAI,QAAS,IAAc,KAAK,KAAG,IAAI,QAmC7C;AAyCD,qBAAqB,GACrB,OAAO,YAAI,aAAc,IAAW,KAAK,KAAG,IAAI,QAoB/C;AAED;UACU,GACV,OAAO,YAAI,aAAc,IAAc,KAAK,KAAG,IAAI,QAUlD;AAED,mDAAmD,GACnD,OAAO,YAAI,cAAc,OAIxB"}
|
package/_dist/mod.d.ts
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.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDC,GAED,0BAAyB;AACzB,0BAAyB;AACzB,4BAA2B;AAC3B,6BAA4B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Memory } from "./recall.js";
|
|
2
|
+
/** The most memories a passage shows. */ export declare let LAST: number;
|
|
3
|
+
/** The most bytes it spends on them. */ export declare let BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* One space's memories as the passage renders them, or '' where it has none.
|
|
6
|
+
* `name` is the person the heading is about — whoever said most of them.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // ## What the owner has said
|
|
10
|
+
* // In ada, his own words, newest first…
|
|
11
|
+
* //
|
|
12
|
+
* // "use grams, never cups"
|
|
13
|
+
* // about the recipes app
|
|
14
|
+
* ```
|
|
15
|
+
*/ export declare let passage: (where: {
|
|
16
|
+
name: string;
|
|
17
|
+
space: string;
|
|
18
|
+
}, held: Memory[]) => string;
|
|
19
|
+
//# sourceMappingURL=passage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passage.d.ts","sources":["../passage.ts"],"names":[],"mappings":"AAaA,cAAc,MAAM,sBAAqB;AAEzC,uCAAuC,GACvC,OAAO,YAAI,aAAQ;AAEnB,sCAAsC,GACtC,OAAO,YAAI,cAAY;AAuBvB;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,UACT;EAAS,MAAM,MAAM;EAAE,OAAO,MAAM;GACpC,MAAM,aACL,MAAM,CAiBR"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Bundle, Eid } from "@yaks/graph";
|
|
2
|
+
import { type Built } from "@yaks/query";
|
|
3
|
+
/** One memory, read back. */ export type Memory = {
|
|
4
|
+
eid: Eid;
|
|
5
|
+
/** the person's own words */ said: string;
|
|
6
|
+
/** the line or two needed to read them, or '' */ context: string;
|
|
7
|
+
/** the app it was about, by slug, or '' */ about: string;
|
|
8
|
+
/** who said it — the name where the store gave one, else their id */ by: string;
|
|
9
|
+
/** when they said it, as the store stamped it */ at: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The words an entity holds: a doc's body, else a transcript entry's content,
|
|
13
|
+
* else a doc's title, else ''.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* words({ entity: { eid: 'e1' }, content: { body: 'use grams' } })
|
|
17
|
+
* // 'use grams'
|
|
18
|
+
* ```
|
|
19
|
+
*/ export declare let words: (b: {
|
|
20
|
+
[comp: string]: unknown;
|
|
21
|
+
}) => string;
|
|
22
|
+
/** One bundle as a memory. */ export declare let heard: (b: Bundle) => Memory;
|
|
23
|
+
/**
|
|
24
|
+
* Words as search terms, stripped of anything the query string cannot carry:
|
|
25
|
+
* its own punctuation (`&`, `=`, `.`) would be read as grammar, and a
|
|
26
|
+
* full-text index matches words anyway.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* terms('.doc&how do they like it?')
|
|
30
|
+
* // 'doc how do they like it'
|
|
31
|
+
* ```
|
|
32
|
+
*/ export declare let terms: (said: string) => string;
|
|
33
|
+
/** What a recall is looking for: which memories, and what ranks them. */ export type Asked = {
|
|
34
|
+
/** at most this many */ limit: number;
|
|
35
|
+
/** the space they were said in */ space?: Eid;
|
|
36
|
+
/** the project they are scoped to */ scope?: Eid;
|
|
37
|
+
/** only the ones recording a correction somebody gave */ feedback?: boolean;
|
|
38
|
+
/** the words to select by — the store's own full-text index */ said?: string;
|
|
39
|
+
/** an entity to rank by meaning instead, where the server has embeddings */ near?: Eid;
|
|
40
|
+
/** particular ones, by id */ eids?: Eid[];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The query string that finds memories: with words, the memories containing
|
|
44
|
+
* every one of them, which is what somebody searching means; with a `near`,
|
|
45
|
+
* ranked by meaning; otherwise the newest words first. Words do not rank:
|
|
46
|
+
* @yaks/fts compiles a word into a condition and keeps its bm25 score for the
|
|
47
|
+
* search tool, so a query string carrying words is a filter and the newest
|
|
48
|
+
* still come first. A quarantined memory never comes back. Every component
|
|
49
|
+
* comes back (`*`), since the words may be a doc's body or an entry's content
|
|
50
|
+
* and a row carries only what its query names.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* line({ space: 's1', limit: 8 })
|
|
54
|
+
* // '.memory.space=s1&!quarantined&*&.order=-created.at&.limit=8'
|
|
55
|
+
* ```
|
|
56
|
+
*/ export declare let line: (asked: Asked) => Built;
|
|
57
|
+
/**
|
|
58
|
+
* The bundles a store returned, in the order a ranking named them. A store
|
|
59
|
+
* returns a set; the ranking is the caller's, and an id the store did not
|
|
60
|
+
* return (a memory since deleted, one the caller may not read) drops out.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* ordered(['b', 'a'], [{ entity: { eid: 'a' } }, { entity: { eid: 'b' } }])
|
|
64
|
+
* // [{ entity: { eid: 'b' } }, { entity: { eid: 'a' } }]
|
|
65
|
+
* ```
|
|
66
|
+
*/ export declare let ordered: (ids: Eid[], held: Bundle[]) => Bundle[];
|
|
67
|
+
//# sourceMappingURL=recall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.d.ts","sources":["../recall.ts"],"names":[],"mappings":"AAmBA,cAAc,MAAM,EAAQ,GAAG,2BAAgC;AAC/D,SAAS,KAAK,KAAK,2BAAgD;AAMnE,2BAA2B,GAC3B,YAAY;EACV,KAAK;EACL,2BAA2B,GAC3B,MAAM,MAAM;EACZ,+CAA+C,GAC/C,SAAS,MAAM;EACf,yCAAyC,GACzC,OAAO,MAAM;EACb,mEAAmE,GACnE,IAAI,MAAM;EACV,+CAA+C,GAC/C,IAAI,MAAM;;AA2BZ;;;;;;;;CAQC,GACD,OAAO,YAAI,QAAS;GAAM,MAAM,MAAM,GAAG,OAAO;MAAK,MAAM,CAM1D;AAED,4BAA4B,GAC5B,OAAO,YAAI,QAAS,GAAG,WAAS,OAW/B;AAED;;;;;;;;;CASC,GACD,OAAO,YAAI,QAAS,MAAM,MAAM,KAAG,MAAM,CAC8B;AAEvE,uEAAuE,GACvE,YAAY;EACV,sBAAsB,GACtB,OAAO,MAAM;EACb,gCAAgC,GAChC,QAAQ;EACR,mCAAmC,GACnC,QAAQ;EACR,uDAAuD,GACvD,WAAW,OAAO;EAClB,6DAA6D,GAC7D,OAAO,MAAM;EACb,0EAA0E,GAC1E,OAAO;EACP,2BAA2B,GAC3B,OAAO;;AAGT;;;;;;;;;;;;;;CAcC,GACD,OAAO,YAAI,OAAQ,OAAO,UAAQ,MAsBjC;AAED;;;;;;;;;CASC,GACD,OAAO,YAAI,UAAW,KAAK,OAAO,MAAM,aAAW,SAGlD"}
|
package/_dist/save.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Bundle, Eid } from "@yaks/graph";
|
|
2
|
+
/** The most context a memory carries, in lines. */ export declare let LINES: number;
|
|
3
|
+
/** Why a save was rejected, worded so an agent can fix it. */ export declare let EMPTY: any;
|
|
4
|
+
/**
|
|
5
|
+
* The context, truncated: blank lines dropped, each line trimmed,
|
|
6
|
+
* {@link LINES} kept.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* clamped(' we were looking at\n\nthe recipe app\nand also this\nand this')
|
|
10
|
+
* // 'we were looking at\nthe recipe app'
|
|
11
|
+
* ```
|
|
12
|
+
*/ export declare let clamped: (context: string) => string;
|
|
13
|
+
/** What a caller hands over to mark words the graph already holds. All of it
|
|
14
|
+
* but the entity is about where the words belong: a graph with no spaces in it
|
|
15
|
+
* keeps memories all the same. */ export type Marking = {
|
|
16
|
+
/** the entity holding the words */ eid: Eid;
|
|
17
|
+
/** the space they belong to */ space?: Eid;
|
|
18
|
+
/** the project they belong to — absent for a principle everybody carries */ scope?: Eid;
|
|
19
|
+
/** who gave the correction, when the words are one; `true` where they are
|
|
20
|
+
* feedback and nobody knows whose */ feedback?: Eid | true;
|
|
21
|
+
/** the line or two needed to read them */ context?: string;
|
|
22
|
+
/** the app they were about, by slug */ about?: string;
|
|
23
|
+
};
|
|
24
|
+
/** What a caller hands over to keep words the graph holds nowhere yet. */ export type Saving = Marking & {
|
|
25
|
+
/** the person's own words, verbatim */ said: string;
|
|
26
|
+
/** the index line a recall shows first, where somebody gave one */ title?: string;
|
|
27
|
+
};
|
|
28
|
+
/** The component marking a memory as a correction somebody gave. */ export declare let FEEDBACK: string;
|
|
29
|
+
/**
|
|
30
|
+
* A mark on an entity that already holds the words, as the bundles
|
|
31
|
+
* that write it: `memory` and, for a correction, `feedback`, and nothing
|
|
32
|
+
* about the words themselves. Who marked it, and when, the graph stamps.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* marked({ eid: 'e1', context: 'looking at the recipe app' })
|
|
36
|
+
* // [{ entity: { eid: 'e1' },
|
|
37
|
+
* // memory: { context: 'looking at the recipe app' } }]
|
|
38
|
+
* ```
|
|
39
|
+
*/ export declare let marked: (m: Marking) => Bundle[];
|
|
40
|
+
/**
|
|
41
|
+
* Words the graph holds nowhere yet, as the bundles that keep them:
|
|
42
|
+
* a doc whose body is the words exactly as they were said, marked. The byline
|
|
43
|
+
* is stamped by the graph, so nothing here writes one.
|
|
44
|
+
*/ export declare let saved: (m: Saving) => Bundle[];
|
|
45
|
+
//# sourceMappingURL=save.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save.d.ts","sources":["../save.ts"],"names":[],"mappings":"AAkBA,cAAc,MAAM,EAAE,GAAG,2BAAgC;AAIzD,iDAAiD,GACjD,OAAO,YAAI,cAAS;AAEpB,4DAA4D,GAC5D,OAAO,YAAI,WAE2B;AAEtC;;;;;;;;CAQC,GACD,OAAO,YAAI,UAAW,SAAS,MAAM,KAAG,MAAM,CAEf;AAE/B;;gCAEgC,GAChC,YAAY;EACV,iCAAiC,GACjC,KAAK;EACL,6BAA6B,GAC7B,QAAQ;EACR,0EAA0E,GAC1E,QAAQ;EACR;qCACmC,GACnC,WAAW,MAAM,IAAI;EACrB,wCAAwC,GACxC,UAAU,MAAM;EAChB,qCAAqC,GACrC,QAAQ,MAAM;;AAGhB,wEAAwE,GACxE,YAAY,SAAS;EACnB,qCAAqC,GACrC,MAAM,MAAM;EACZ,iEAAiE,GACjE,QAAQ,MAAM;;AAGhB,kEAAkE,GAClE,OAAO,YAAI,iBAAqB;AAEhC;;;;;;;;;;CAUC,GACD,OAAO,YAAI,SAAU,GAAG,YAAU,SAejC;AAED;;;;CAIC,GACD,OAAO,YAAI,QAAS,GAAG,WAAS,SAM/B"}
|
package/_dist/tools.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { witnessed } from "@yaks/doc";
|
|
2
|
+
import type { Runs } from "@yaks/graph/tools";
|
|
3
|
+
import type { Host } from "@yaks/host";
|
|
4
|
+
/** How many memories a recall returns when the caller gave no limit. */ export declare let LIMIT: number;
|
|
5
|
+
/** Why a save that would overwrite unread words is rejected: how to get the
|
|
6
|
+
* token it is missing, and why that token is not in this message. */ export declare let unread: (id: string) => string;
|
|
7
|
+
/** What a recall asks of its host: words ranked by meaning, where it keeps
|
|
8
|
+
* vectors, and where to say that ranking failed. */ export type Ranking = Partial<Pick<Host, 'meaning' | 'report'>>;
|
|
9
|
+
/** The implementations of the tools ./vocab.json declares. A factory, like
|
|
10
|
+
* every other entry point in these packages. A host sharing a graph between
|
|
11
|
+
* spaces binds saves and recalls to one space through its options. */ export declare let runs: (host?: Ranking, _dts_1: never) => Runs;
|
|
12
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAuCA,SAAS,SAAS,yBAA8B;AAChD,cAAc,IAAI,iCAAsC;AACxD,cAAc,IAAI,0BAA+B;AAMjD,sEAAsE,GACtE,OAAO,YAAI,cAAS;AAOpB;mEACmE,GACnE,OAAO,YAAI,SAAU,IAAI,MAAM,KAAG,MAAM,CAI8B;AAgDtE;kDACkD,GAClD,YAAY,UAAU,QAAQ,KAAK,MAAM,YAAY;AAiBrD;;oEAEoE,GACpE,OAAO,YAAI,OACT,OAAM,SACN,kBACC,KAmHD"}
|
package/_dist/views.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { View } from "@yaks/inspect";
|
|
2
|
+
/** How many turns either side of a cited one a belief's page shows. */ export declare let AROUND: {
|
|
3
|
+
readonly before: number;
|
|
4
|
+
readonly after: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* What a belief states, without the words it quotes: its body up to the
|
|
8
|
+
* first quote.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { statement } from './views.ts'
|
|
12
|
+
* statement('Tests never share a lock.\n\n> never share a lock\n(Jeff)')
|
|
13
|
+
* // 'Tests never share a lock.'
|
|
14
|
+
* ```
|
|
15
|
+
*/ export declare let statement: (body: string) => string;
|
|
16
|
+
/** The inspector's domain pages and parts. */ export declare let inspectViews: () => Promise<View[]>;
|
|
17
|
+
//# sourceMappingURL=views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAEA,cAAc,IAAI,6BAAkC;AAEpD,qEAAqE,GACrE,OAAO,YAAI;WAAW;WAAW;EAAU;AAE3C;;;;;;;;;CASC,GACD,OAAO,YAAI,YAAa,MAAM,MAAM,KAAG,MAAM,CACR;AAErC,4CAA4C,GAC5C,OAAO,YAAI,oBAAmB,QAAQ,QACc"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
import { memoryDoc } from "./comp.js";
|
|
3
|
+
export { memoryDoc };
|
|
4
|
+
/** What this package is: its manifest's description, the one place it is
|
|
5
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
6
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
7
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AACtD,SAAS,SAAS,oBAAmB;AAGrC,SAAS,SAAS,GAAE;AAEpB;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAwB"}
|
package/around.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Reading around a memory, the way `grep -C` reads around a line. A memory is a
|
|
2
|
+
// mark on where somebody said something, and the words alone are rarely enough
|
|
3
|
+
// to understand it: what came just before them in the conversation, what the
|
|
4
|
+
// comment was on, who replied, which session it was and what that session was
|
|
5
|
+
// working on. These four tools answer those, one each, so a model building
|
|
6
|
+
// beliefs from memories walks out from one only as far as it needs.
|
|
7
|
+
//
|
|
8
|
+
// They are ordinary reads over the graph. What they know of other packages'
|
|
9
|
+
// components (a transcript entry's `entry{session, seq}`, a comment's
|
|
10
|
+
// `comment{target}`, a `worked` edge, a `claim`) they learn from the rows a
|
|
11
|
+
// query answers and the names a query speaks, never by importing the package
|
|
12
|
+
// that declares them; where a graph does not declare one, the tool answers
|
|
13
|
+
// without it or says it cannot.
|
|
14
|
+
import { line } from "@yaks/query";
|
|
15
|
+
import { argsOf } from "@yaks/graph/call";
|
|
16
|
+
import { Refused } from "@yaks/graph/errors";
|
|
17
|
+
/** How many entries either side of one `memory_around` reads when not told. */ export let CONTEXT = 3;
|
|
18
|
+
let str = (v)=>v == null ? '' : String(v);
|
|
19
|
+
let comp = (b, name)=>b?.[name] ?? undefined;
|
|
20
|
+
let count = (v)=>{
|
|
21
|
+
let n = Number(v ?? CONTEXT);
|
|
22
|
+
return Number.isFinite(n) ? Math.max(0, Math.floor(n)) : CONTEXT;
|
|
23
|
+
};
|
|
24
|
+
// Entities as they stand, whole, in the order asked and each once; one deleted
|
|
25
|
+
// or never there is left out.
|
|
26
|
+
let wholes = async (graph, eids)=>{
|
|
27
|
+
let want = [
|
|
28
|
+
...new Set(eids.filter(Boolean))
|
|
29
|
+
];
|
|
30
|
+
if (!want.length) return [];
|
|
31
|
+
let found = new Map((await graph.get(want)).filter((b)=>!b.tombstone).map((b)=>[
|
|
32
|
+
b.entity.eid,
|
|
33
|
+
b
|
|
34
|
+
]));
|
|
35
|
+
return want.flatMap((eid)=>found.has(eid) ? [
|
|
36
|
+
found.get(eid)
|
|
37
|
+
] : []);
|
|
38
|
+
};
|
|
39
|
+
// The one entity a call names, whole, or a refusal saying there is none.
|
|
40
|
+
let named = async (graph, call)=>{
|
|
41
|
+
let id = str(argsOf(call).id);
|
|
42
|
+
let [b] = await wholes(graph, [
|
|
43
|
+
id
|
|
44
|
+
]);
|
|
45
|
+
if (!b) throw new Refused(`nothing is ${id}`);
|
|
46
|
+
return b;
|
|
47
|
+
};
|
|
48
|
+
// Oldest first: by when each was made, then by number, then by eid, so two
|
|
49
|
+
// written in the same millisecond still come back in one order.
|
|
50
|
+
let oldest = (a, b)=>str(comp(a, 'created')?.at).localeCompare(str(comp(b, 'created')?.at)) || Number(a.entity.num ?? 0) - Number(b.entity.num ?? 0) || a.entity.eid.localeCompare(b.entity.eid);
|
|
51
|
+
/** The reads, as the tools ./vocab.json declares them. */ export let around = {
|
|
52
|
+
// The entries either side of one in its transcript, counted by position,
|
|
53
|
+
// whatever their kind: `.entry.seq` orders a transcript and may skip numbers.
|
|
54
|
+
memory_around: async (call, graph)=>{
|
|
55
|
+
let args = argsOf(call);
|
|
56
|
+
let e = await named(graph, call);
|
|
57
|
+
let at = comp(e, 'entry');
|
|
58
|
+
if (!at?.session) {
|
|
59
|
+
throw new Refused(`${str(args.id)} is no transcript entry`);
|
|
60
|
+
}
|
|
61
|
+
let side = async (op, n)=>n ? await graph.read(op == '<' ? line`.entry.session=${str(at.session)}&.entry.seq<${Number(at.seq)}&*&.order=-entry.seq&.limit=${n}` : line`.entry.session=${str(at.session)}&.entry.seq>${Number(at.seq)}&*&.order=entry.seq&.limit=${n}`) : [];
|
|
62
|
+
let ahead = await side('<', count(args.before));
|
|
63
|
+
let behind = await side('>', count(args.after));
|
|
64
|
+
return [
|
|
65
|
+
...ahead.reverse(),
|
|
66
|
+
e,
|
|
67
|
+
...behind
|
|
68
|
+
];
|
|
69
|
+
},
|
|
70
|
+
// Every target the entity's components name, whichever component names it:
|
|
71
|
+
// a comment's, and any other package's aimed thing (a letter, a knock).
|
|
72
|
+
memory_target: async (call, graph)=>{
|
|
73
|
+
let e = await named(graph, call);
|
|
74
|
+
let aims = Object.keys(e).flatMap((c)=>graph.vocab.prop(c, 'target')?.category == 'ref' ? [
|
|
75
|
+
str(comp(e, c)?.target)
|
|
76
|
+
] : []);
|
|
77
|
+
let found = await wholes(graph, aims);
|
|
78
|
+
if (!found.length) {
|
|
79
|
+
throw new Refused(`${str(argsOf(call).id)} is aimed at nothing`);
|
|
80
|
+
}
|
|
81
|
+
return found;
|
|
82
|
+
},
|
|
83
|
+
// Up past every comment the entity replies to, to what they are all about;
|
|
84
|
+
// then down through every comment below that, a level at a time.
|
|
85
|
+
memory_thread: async (call, graph)=>{
|
|
86
|
+
let root = await named(graph, call);
|
|
87
|
+
let seen = new Set([
|
|
88
|
+
root.entity.eid
|
|
89
|
+
]);
|
|
90
|
+
for(;;){
|
|
91
|
+
let t = str(comp(root, 'comment')?.target);
|
|
92
|
+
let [up] = seen.has(t) ? [] : await wholes(graph, [
|
|
93
|
+
t
|
|
94
|
+
]);
|
|
95
|
+
if (!up) break;
|
|
96
|
+
seen.add(t);
|
|
97
|
+
root = up;
|
|
98
|
+
}
|
|
99
|
+
let below = [];
|
|
100
|
+
let known = new Set([
|
|
101
|
+
root.entity.eid
|
|
102
|
+
]);
|
|
103
|
+
for(let level = [
|
|
104
|
+
root.entity.eid
|
|
105
|
+
]; level.length;){
|
|
106
|
+
let found = (await graph.read(line`.comment.target=${level}&*`)).filter((b)=>!known.has(b.entity.eid));
|
|
107
|
+
for (let b of found)known.add(b.entity.eid);
|
|
108
|
+
below.push(...found);
|
|
109
|
+
level = found.map((b)=>b.entity.eid);
|
|
110
|
+
}
|
|
111
|
+
return [
|
|
112
|
+
root,
|
|
113
|
+
...below.sort(oldest)
|
|
114
|
+
];
|
|
115
|
+
},
|
|
116
|
+
// The session: a transcript entry's own, or the one anything else was
|
|
117
|
+
// written through. Then what it worked on (`worked` edges from it) and what
|
|
118
|
+
// it holds a claim on now, where the graph declares either.
|
|
119
|
+
memory_session: async (call, graph)=>{
|
|
120
|
+
let e = await named(graph, call);
|
|
121
|
+
let s = str(comp(e, 'entry')?.session) || str(comp(e, 'created')?.via);
|
|
122
|
+
let [session] = await wholes(graph, [
|
|
123
|
+
s
|
|
124
|
+
]);
|
|
125
|
+
// Written through something else (a process, a client): no session.
|
|
126
|
+
if (!comp(session, 'session')) {
|
|
127
|
+
throw new Refused(`${str(argsOf(call).id)} was written through no session`);
|
|
128
|
+
}
|
|
129
|
+
let has = (c)=>!!graph.vocab.comp(c);
|
|
130
|
+
let worked = has('edge') && has('worked') ? (await graph.read(line`.edge.from=${s}&.worked&?edge`)).map((b)=>str(comp(b, 'edge')?.to)) : [];
|
|
131
|
+
let claimed = has('claim') ? (await graph.read(line`.claim.session=${s}`)).map((b)=>b.entity.eid) : [];
|
|
132
|
+
return [
|
|
133
|
+
session,
|
|
134
|
+
...await wholes(graph, [
|
|
135
|
+
...worked,
|
|
136
|
+
...claimed
|
|
137
|
+
])
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=around.js.map
|
package/around.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"around.js","sources":["./around.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,oEAAoE;AACpE,EAAE;AACF,4EAA4E;AAC5E,sEAAsE;AACtE,4EAA4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AM,MAAM,OAAO;IAC3B,IAAI,IAAI,IAAI,KAAK,GAAG,UAAU,YAAY,IAAI,KAAK,GAAG,YAAY;IAClE,IAAI,CAAC,QAAQ,GAAG,MAAM,OAAO,OAAO;MAAC;KAAE;IACvC,oEAAoE;IACpE,IAAI,CAAC,KAAK,SAAS,YAAY;MAC7B,MAAM,IAAI,QACR,GAAG,IAAI,OAAO,MAAM,EAAE,EAAE,+BAA+B,CAAC;IAE5D;IACA,IAAI,MAAM,CAAC,IAAc,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC;IAC5C,IAAI,SAAS,IAAI,WAAW,IAAI,YAC5B,CAAC,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,cAAc,CAAC,CAAC,EACrD,GAAG,CAAC,CAAC,IAAM,IAAI,KAAK,GAAG,SAAS,OACjC,EAAE;IACN,IAAI,UAAU,IAAI,WACd,CAAC,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG,IACrE,EAAE;IACN,OAAO;MAAC;SAAY,MAAM,OAAO,OAAO;WAAI;WAAW;OAAQ;KAAE;EACnE;AACF,EAAC"}
|
package/around.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Reading around a memory, the way `grep -C` reads around a line. A memory is a
|
|
2
|
+
// mark on where somebody said something, and the words alone are rarely enough
|
|
3
|
+
// to understand it: what came just before them in the conversation, what the
|
|
4
|
+
// comment was on, who replied, which session it was and what that session was
|
|
5
|
+
// working on. These four tools answer those, one each, so a model building
|
|
6
|
+
// beliefs from memories walks out from one only as far as it needs.
|
|
7
|
+
//
|
|
8
|
+
// They are ordinary reads over the graph. What they know of other packages'
|
|
9
|
+
// components (a transcript entry's `entry{session, seq}`, a comment's
|
|
10
|
+
// `comment{target}`, a `worked` edge, a `claim`) they learn from the rows a
|
|
11
|
+
// query answers and the names a query speaks, never by importing the package
|
|
12
|
+
// that declares them; where a graph does not declare one, the tool answers
|
|
13
|
+
// without it or says it cannot.
|
|
14
|
+
|
|
15
|
+
import type { Bundle, Comp, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
16
|
+
import { line } from '@yaks/query'
|
|
17
|
+
import { argsOf } from '@yaks/graph/call'
|
|
18
|
+
import { Refused } from '@yaks/graph/errors'
|
|
19
|
+
import type { Runs } from 'jsr:@yaks/graph@0.2.36/tools'
|
|
20
|
+
|
|
21
|
+
/** How many entries either side of one `memory_around` reads when not told. */
|
|
22
|
+
export let CONTEXT = 3
|
|
23
|
+
|
|
24
|
+
let str = (v: unknown): string => v == null ? '' : String(v)
|
|
25
|
+
|
|
26
|
+
let comp = (b: Bundle | undefined, name: string): Comp | undefined =>
|
|
27
|
+
(b?.[name] ?? undefined) as Comp | undefined
|
|
28
|
+
|
|
29
|
+
let count = (v: unknown): number => {
|
|
30
|
+
let n = Number(v ?? CONTEXT)
|
|
31
|
+
return Number.isFinite(n) ? Math.max(0, Math.floor(n)) : CONTEXT
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Entities as they stand, whole, in the order asked and each once; one deleted
|
|
35
|
+
// or never there is left out.
|
|
36
|
+
let wholes = async (graph: Graph, eids: string[]): Promise<Bundle[]> => {
|
|
37
|
+
let want = [...new Set(eids.filter(Boolean))]
|
|
38
|
+
if (!want.length) return []
|
|
39
|
+
let found = new Map(
|
|
40
|
+
(await graph.get(want)).filter((b) => !b.tombstone)
|
|
41
|
+
.map((b) => [b.entity.eid, b]),
|
|
42
|
+
)
|
|
43
|
+
return want.flatMap((eid) => found.has(eid) ? [found.get(eid)!] : [])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The one entity a call names, whole, or a refusal saying there is none.
|
|
47
|
+
let named = async (graph: Graph, call: Bundle): Promise<Bundle> => {
|
|
48
|
+
let id = str(argsOf(call).id)
|
|
49
|
+
let [b] = await wholes(graph, [id])
|
|
50
|
+
if (!b) throw new Refused(`nothing is ${id}`)
|
|
51
|
+
return b
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Oldest first: by when each was made, then by number, then by eid, so two
|
|
55
|
+
// written in the same millisecond still come back in one order.
|
|
56
|
+
let oldest = (a: Bundle, b: Bundle): number =>
|
|
57
|
+
str(comp(a, 'created')?.at).localeCompare(str(comp(b, 'created')?.at)) ||
|
|
58
|
+
Number(a.entity.num ?? 0) - Number(b.entity.num ?? 0) ||
|
|
59
|
+
a.entity.eid.localeCompare(b.entity.eid)
|
|
60
|
+
|
|
61
|
+
/** The reads, as the tools ./vocab.json declares them. */
|
|
62
|
+
export let around: Runs = {
|
|
63
|
+
// The entries either side of one in its transcript, counted by position,
|
|
64
|
+
// whatever their kind: `.entry.seq` orders a transcript and may skip numbers.
|
|
65
|
+
memory_around: async (call, graph): Promise<Bundle[]> => {
|
|
66
|
+
let args = argsOf(call)
|
|
67
|
+
let e = await named(graph, call)
|
|
68
|
+
let at = comp(e, 'entry')
|
|
69
|
+
if (!at?.session) {
|
|
70
|
+
throw new Refused(`${str(args.id)} is no transcript entry`)
|
|
71
|
+
}
|
|
72
|
+
let side = async (op: '<' | '>', n: number) =>
|
|
73
|
+
n
|
|
74
|
+
? await graph.read(
|
|
75
|
+
op == '<'
|
|
76
|
+
? line`.entry.session=${str(at.session)}&.entry.seq<${
|
|
77
|
+
Number(at.seq)
|
|
78
|
+
}&*&.order=-entry.seq&.limit=${n}`
|
|
79
|
+
: line`.entry.session=${str(at.session)}&.entry.seq>${
|
|
80
|
+
Number(at.seq)
|
|
81
|
+
}&*&.order=entry.seq&.limit=${n}`,
|
|
82
|
+
)
|
|
83
|
+
: []
|
|
84
|
+
let ahead = await side('<', count(args.before))
|
|
85
|
+
let behind = await side('>', count(args.after))
|
|
86
|
+
return [...ahead.reverse(), e, ...behind]
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// Every target the entity's components name, whichever component names it:
|
|
90
|
+
// a comment's, and any other package's aimed thing (a letter, a knock).
|
|
91
|
+
memory_target: async (call, graph): Promise<Bundle[]> => {
|
|
92
|
+
let e = await named(graph, call)
|
|
93
|
+
let aims = Object.keys(e).flatMap((c) =>
|
|
94
|
+
graph.vocab.prop(c, 'target')?.category == 'ref'
|
|
95
|
+
? [str(comp(e, c)?.target)]
|
|
96
|
+
: []
|
|
97
|
+
)
|
|
98
|
+
let found = await wholes(graph, aims)
|
|
99
|
+
if (!found.length) {
|
|
100
|
+
throw new Refused(`${str(argsOf(call).id)} is aimed at nothing`)
|
|
101
|
+
}
|
|
102
|
+
return found
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Up past every comment the entity replies to, to what they are all about;
|
|
106
|
+
// then down through every comment below that, a level at a time.
|
|
107
|
+
memory_thread: async (call, graph): Promise<Bundle[]> => {
|
|
108
|
+
let root = await named(graph, call)
|
|
109
|
+
let seen = new Set([root.entity.eid])
|
|
110
|
+
for (;;) {
|
|
111
|
+
let t = str(comp(root, 'comment')?.target)
|
|
112
|
+
let [up] = seen.has(t) ? [] : await wholes(graph, [t])
|
|
113
|
+
if (!up) break
|
|
114
|
+
seen.add(t)
|
|
115
|
+
root = up
|
|
116
|
+
}
|
|
117
|
+
let below: Bundle[] = []
|
|
118
|
+
let known = new Set([root.entity.eid])
|
|
119
|
+
for (let level = [root.entity.eid]; level.length;) {
|
|
120
|
+
let found = (await graph.read(line`.comment.target=${level}&*`))
|
|
121
|
+
.filter((b) => !known.has(b.entity.eid))
|
|
122
|
+
for (let b of found) known.add(b.entity.eid)
|
|
123
|
+
below.push(...found)
|
|
124
|
+
level = found.map((b) => b.entity.eid)
|
|
125
|
+
}
|
|
126
|
+
return [root, ...below.sort(oldest)]
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
// The session: a transcript entry's own, or the one anything else was
|
|
130
|
+
// written through. Then what it worked on (`worked` edges from it) and what
|
|
131
|
+
// it holds a claim on now, where the graph declares either.
|
|
132
|
+
memory_session: async (call, graph): Promise<Bundle[]> => {
|
|
133
|
+
let e = await named(graph, call)
|
|
134
|
+
let s = str(comp(e, 'entry')?.session) || str(comp(e, 'created')?.via)
|
|
135
|
+
let [session] = await wholes(graph, [s])
|
|
136
|
+
// Written through something else (a process, a client): no session.
|
|
137
|
+
if (!comp(session, 'session')) {
|
|
138
|
+
throw new Refused(
|
|
139
|
+
`${str(argsOf(call).id)} was written through no session`,
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
let has = (c: string) => !!graph.vocab.comp(c)
|
|
143
|
+
let worked = has('edge') && has('worked')
|
|
144
|
+
? (await graph.read(line`.edge.from=${s}&.worked&?edge`))
|
|
145
|
+
.map((b) => str(comp(b, 'edge')?.to))
|
|
146
|
+
: []
|
|
147
|
+
let claimed = has('claim')
|
|
148
|
+
? (await graph.read(line`.claim.session=${s}`)).map((b) => b.entity.eid)
|
|
149
|
+
: []
|
|
150
|
+
return [session, ...await wholes(graph, [...worked, ...claimed])]
|
|
151
|
+
},
|
|
152
|
+
}
|
package/comp.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The component this package is about: `memory`, a mark on something a person
|
|
2
|
+
// said. Beside it, ./vocab.json declares what is built from memories: `belief`,
|
|
3
|
+
// a conclusion a builder drew about a subject, often a topic (@yaks/topic).
|
|
4
|
+
//
|
|
5
|
+
// A memory is NOT a note an agent took. It is the person's own sentence, kept
|
|
6
|
+
// as they said it, because a paraphrase is strictly less than what was said —
|
|
7
|
+
// an agent that summarises can only ever remove information, and the next
|
|
8
|
+
// agent cannot get it back. So a memory never holds words of its own: it marks
|
|
9
|
+
// the entity where the words already are, whatever that entity is —
|
|
10
|
+
//
|
|
11
|
+
// { entity: { eid: e }, a session entry: what they typed
|
|
12
|
+
// entry: { session: s, seq: 12 },
|
|
13
|
+
// content: { body: 'use grams, never cups' },
|
|
14
|
+
// memory: { context: 'about the recipe app', at, by, via } }
|
|
15
|
+
//
|
|
16
|
+
// — a comment, a doc, a transcript entry. Only words the graph holds nowhere
|
|
17
|
+
// yet (said in a chat on yaks.app, say) get an entity made for them, a doc
|
|
18
|
+
// whose body is the sentence. The words are read from whichever holds them
|
|
19
|
+
// (./recall.ts `words`), by component, never by kind.
|
|
20
|
+
//
|
|
21
|
+
// A mark is what the graph calls a component whose `at`, `by` and `via` it
|
|
22
|
+
// fills in the first time it is written (@yaks/graph ./stamp.ts), so a memory
|
|
23
|
+
// records who marked the words and when; nothing needs approving. Who said
|
|
24
|
+
// them, and when, is the entity's own `created{at, by}`. And a mark says what
|
|
25
|
+
// happened to an entity, never what the entity is: a comment marked as a
|
|
26
|
+
// memory is still a comment (@yaks/vocab `kindOrder`), and only a doc that is
|
|
27
|
+
// nothing but a memory is shown as one.
|
|
28
|
+
//
|
|
29
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
30
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
31
|
+
// import and keeps the prose about why it is shaped the way it is.
|
|
32
|
+
import doc from './vocab.json' with {
|
|
33
|
+
type: 'json'
|
|
34
|
+
};
|
|
35
|
+
/** The component marking a thing a person said. */ export let MEMORY = 'memory';
|
|
36
|
+
/**
|
|
37
|
+
* The memory vocabulary document, to load beside @yaks/doc's and your own:
|
|
38
|
+
* `loadVocab([docDoc, memoryDoc, ...mine])`. It declares nothing about what a
|
|
39
|
+
* space is — that component is your own document's — only that a memory
|
|
40
|
+
* belongs to one.
|
|
41
|
+
*/ export let memoryDoc = doc;
|
|
42
|
+
//# sourceMappingURL=comp.js.map
|
package/comp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,+EAA+E;AAC/E,oEAAoE;AACpE,EAAE;AACF,iFAAiF;AACjF,sCAAsC;AACtC,kDAAkD;AAClD,iEAAiE;AACjE,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E,sDAAsD;AACtD,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAC9E,wCAAwC;AACxC,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,mEAAmE;AAGnE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,iDAAiD,GACjD,OAAO,IAAI,SAAS,SAAQ;AAE5B;;;;;CAKC,GACD,OAAO,IAAI,YAAsB,IAAG"}
|