@graview/core 0.2.20 → 0.2.21

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 (67) hide show
  1. package/dist/arranging.d.ts.map +1 -1
  2. package/dist/arranging.js +8 -1
  3. package/dist/arranging.js.map +1 -1
  4. package/dist/document.schema.json +2 -2
  5. package/dist/index.d.ts +5 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/mutations/types.d.ts +2 -0
  10. package/dist/mutations/types.d.ts.map +1 -1
  11. package/dist/permissions/policy.d.ts +1 -0
  12. package/dist/permissions/policy.d.ts.map +1 -1
  13. package/dist/permissions/policy.js +2 -0
  14. package/dist/permissions/policy.js.map +1 -1
  15. package/dist/rooms/findings.d.ts +2 -2
  16. package/dist/rooms/findings.d.ts.map +1 -1
  17. package/dist/rooms/findings.js +8 -3
  18. package/dist/rooms/findings.js.map +1 -1
  19. package/dist/rooms/intent.d.ts +22 -0
  20. package/dist/rooms/intent.d.ts.map +1 -0
  21. package/dist/rooms/intent.js +54 -0
  22. package/dist/rooms/intent.js.map +1 -0
  23. package/dist/rooms/kind.d.ts +24 -4
  24. package/dist/rooms/kind.d.ts.map +1 -1
  25. package/dist/rooms/kind.js +144 -35
  26. package/dist/rooms/kind.js.map +1 -1
  27. package/dist/rooms/read.d.ts +33 -2
  28. package/dist/rooms/read.d.ts.map +1 -1
  29. package/dist/rooms/read.js +50 -2
  30. package/dist/rooms/read.js.map +1 -1
  31. package/dist/rooms/shape.d.ts +40 -2
  32. package/dist/rooms/shape.d.ts.map +1 -1
  33. package/dist/rooms/shape.js +35 -2
  34. package/dist/rooms/shape.js.map +1 -1
  35. package/dist/rooms/talk-shape.d.ts +29 -0
  36. package/dist/rooms/talk-shape.d.ts.map +1 -0
  37. package/dist/rooms/talk-shape.js +2 -0
  38. package/dist/rooms/talk-shape.js.map +1 -0
  39. package/dist/rooms/talk.d.ts +50 -0
  40. package/dist/rooms/talk.d.ts.map +1 -0
  41. package/dist/rooms/talk.js +105 -0
  42. package/dist/rooms/talk.js.map +1 -0
  43. package/dist/rooms/touches.d.ts +13 -0
  44. package/dist/rooms/touches.d.ts.map +1 -0
  45. package/dist/rooms/touches.js +70 -0
  46. package/dist/rooms/touches.js.map +1 -0
  47. package/dist/rooms/touchpoints.d.ts +66 -0
  48. package/dist/rooms/touchpoints.d.ts.map +1 -0
  49. package/dist/rooms/touchpoints.js +131 -0
  50. package/dist/rooms/touchpoints.js.map +1 -0
  51. package/dist/rooms.d.ts +12 -2
  52. package/dist/rooms.d.ts.map +1 -1
  53. package/dist/rooms.js +13 -2
  54. package/dist/rooms.js.map +1 -1
  55. package/dist/store.d.ts +14 -1
  56. package/dist/store.d.ts.map +1 -1
  57. package/dist/store.js +9 -1
  58. package/dist/store.js.map +1 -1
  59. package/dist/subscription-shape.d.ts +11 -0
  60. package/dist/subscription-shape.d.ts.map +1 -1
  61. package/dist/subscription-shape.js.map +1 -1
  62. package/dist/subscriptions.d.ts.map +1 -1
  63. package/dist/subscriptions.js +19 -1
  64. package/dist/subscriptions.js.map +1 -1
  65. package/dist/version.d.ts +1 -1
  66. package/dist/version.js +1 -1
  67. package/package.json +1 -1
@@ -0,0 +1,54 @@
1
+ import { isIntent } from "./shape.js";
2
+ const REPORT = /\b(bug|broken|breaks|crash(?:es|ed)?|error|fails?|failed|doesn'?t|does not|not working|nothing happens|does nothing)\b/i;
3
+ const REQUEST = /(^|\s)@owners?\b|\bplease (add|make|let|give|allow|change|remove|create)\b|\bcould (you|the owners?) (add|make|let|give|allow)\b/i;
4
+ const CHANGE = /\b(can|could|should) (we|the app|this app|it) (have|add|show|get|be|look|use|let)\b|\bi wish (this|the app|it)\b|\bit would be (nice|great|good|better) (if|to)\b|\bwhat if (we|the app|this)\b|\b(add|need) a (field|column|kind|view|page|choice)\b/i;
5
+ const QUESTION_START = /^(who|what|when|where|which|why|how|is|are|was|were|do|does|did|can|could|should|will|would|has|have)\b/i;
6
+ const MENTION = /(^|\s)@[\p{L}\p{N}]/u;
7
+ /** Words a sentence that asks for something done begins with, past a "please". */
8
+ const VERB = /^(?:please\s+)?([a-z]+)\b/i;
9
+ /** The verbs an act is said with: the first word of its name and of its title ("mark-done", "Mark it done": "mark"). */
10
+ function actVerbs(act) {
11
+ return [act.name, act.title ?? ""].map((said) => said.toLowerCase().split(/[^a-z0-9]+/).find((word) => word !== "") ?? "").filter((word) => word !== "");
12
+ }
13
+ /**
14
+ * THE APP'S GUESS AT A MESSAGE'S INTENT, without a model: a request where
15
+ * it asks the owners (`@owners`, "please add"); a change where it wishes the
16
+ * app were otherwise ("can we", "should the app", "I wish"); a report where
17
+ * it says something is broken ("bug", "doesn't work"); something to do where it begins with a verb
18
+ * that names an act the seat may run; a question where it asks one (a
19
+ * question mark, or a question's first word) and names no person; else talk.
20
+ */
21
+ export function guessIntent(text, context = {}) {
22
+ const said = text.replace(/\s+/g, " ").trim();
23
+ if (said === "")
24
+ return "discussion";
25
+ if (REQUEST.test(said))
26
+ return "request";
27
+ if (CHANGE.test(said))
28
+ return "change";
29
+ if (REPORT.test(said))
30
+ return "report";
31
+ const verb = VERB.exec(said)?.[1]?.toLowerCase();
32
+ if (verb && !said.endsWith("?") && (context.acts ?? []).some((act) => actVerbs(act).includes(verb)))
33
+ return "act";
34
+ if (MENTION.test(said))
35
+ return "discussion";
36
+ if (said.endsWith("?") || QUESTION_START.test(said))
37
+ return "answer";
38
+ return "discussion";
39
+ }
40
+ /** The guess a composer posts with: the host's (a model's), where it gives one, else the app's own. */
41
+ export async function intentFor(text, context = {}, host) {
42
+ if (host) {
43
+ try {
44
+ const guessed = await host(text, context);
45
+ if (isIntent(guessed))
46
+ return guessed;
47
+ }
48
+ catch {
49
+ // A host's guess that fails leaves it to the app's own.
50
+ }
51
+ }
52
+ return guessIntent(text, context);
53
+ }
54
+ //# sourceMappingURL=intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"int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I,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;IACjD,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAClH,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC;IAC5C,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,QAAQ,CAAC;IACrE,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAY,EAAE,UAAyB,EAAE,EAAE,IAAoB;IAC7F,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC1C,IAAI,QAAQ,CAAC,OAAO,CAAC;gBAAE,OAAO,OAAO,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,wDAAwD;QAC1D,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC"}
@@ -4,6 +4,8 @@ import type { Grant, Policy, Sight } from "../permissions/types.js";
4
4
  import { type AnySchema } from "../schema/schema.js";
5
5
  import type { AnyNodeDefinition } from "../schema/types.js";
6
6
  import { type AppRooms, type ChatSwitched } from "./shape.js";
7
+ import { type IntentContext } from "./intent.js";
8
+ import type { TalkSettings } from "./talk-shape.js";
7
9
  /** Whether a kind's definition is the framework's own, that stands on no page of the app: a room's messages are read in their room. */
8
10
  export declare const isPlaceless: (definition: unknown) => boolean;
9
11
  /** Whether an act, a grant or a sight is one `withRooms` folded in. */
@@ -17,6 +19,8 @@ export declare const isRoomsOwn: (part: unknown) => boolean;
17
19
  export declare function unfoldedApp<A extends object>(app: A): A;
18
20
  /** Whether an app had its rooms folded in. */
19
21
  export declare const roomsFolded: (app: object) => boolean;
22
+ /** What the host said of talk for an app's schema — its visitors' say — where it supplied the rooms (`talk`); undefined where it did not. */
23
+ export declare const talkOfSchema: (schema: AnySchema) => TalkSettings | undefined;
20
24
  /** Whether a room of the app reads `@Name` as a mention: unless it says `mentions: false`. A room the kind was not made for reads none. */
21
25
  export declare function mentionsOnIn(schema: AnySchema, room: unknown): boolean;
22
26
  /** The rooms an app's schema was given its message kind for: what a page reads them from when it holds only the store. */
@@ -30,9 +34,16 @@ export declare const talkOn: (store: ChatSwitched & {
30
34
  readonly schema: AnySchema;
31
35
  }) => boolean;
32
36
  /** The framework's message kind, for these rooms. */
33
- export declare function messageKind(rooms: AppRooms): AnyNodeDefinition;
37
+ export declare function messageKind(rooms: AppRooms, talk?: TalkSettings): AnyNodeDefinition;
38
+ /** Extra the acts of an app's rooms are made with: what the host said of talk, and the acts a message may name (for the guess at what it is). */
39
+ export interface RoomActsOptions {
40
+ readonly talk?: TalkSettings;
41
+ readonly acts?: () => IntentContext["acts"];
42
+ /** The roles that may change everything in the app (`editorRolesOf`): who answers a conversation with the owners. */
43
+ readonly editors?: readonly string[] | "*";
44
+ }
34
45
  /** The three acts of an app's rooms: post, edit your own, remove your own (or anybody's, for a role a room lets moderate). */
35
- export declare function roomActs(rooms: AppRooms, schema?: AnySchema): AnyMutationDefinition<AnySchema>[];
46
+ export declare function roomActs(rooms: AppRooms, schema?: AnySchema, options?: RoomActsOptions): AnyMutationDefinition<AnySchema>[];
36
47
  /**
37
48
  * THE THREE ACTS OF A CONVERSATION WITH THE AI (Graview HQ
38
49
  * feature:f-conversations-in-the-graph): keep a finished turn — what the
@@ -42,11 +53,11 @@ export declare function roomActs(rooms: AppRooms, schema?: AnySchema): AnyMutati
42
53
  * editors or everybody, or keep it to its asker again. Streamed words are
43
54
  * never kept: only a turn once it is over.
44
55
  */
45
- export declare function aiRoomActs(schema?: AnySchema): AnyMutationDefinition<AnySchema>[];
56
+ export declare function aiRoomActs(schema?: AnySchema, rooms?: AppRooms, acts?: () => IntentContext["acts"]): AnyMutationDefinition<AnySchema>[];
46
57
  /** The grant that lets the acts be run: each room says who it admits, and the acts hold to it. */
47
58
  export declare const ROOMS_GRANT: Grant;
48
59
  /** Each room's sight over its messages: its readers, and a thread's messages only where the record is seen too. */
49
- export declare function roomSights(rooms: AppRooms): Sight[];
60
+ export declare function roomSights(rooms: AppRooms, policy?: Policy): Sight[];
50
61
  /**
51
62
  * WHO MAY CHANGE EVERYTHING IN THE APP: the roles a grant of every act
52
63
  * names, which "Share with the app's editors" shares a conversation with.
@@ -78,6 +89,15 @@ export declare function roomsPolicy(policy: Policy | undefined, rooms: AppRooms,
78
89
  * it, nor read them as the app's own records (`refuseKeptTalkTaken`).
79
90
  */
80
91
  export declare function withRooms<A extends GraviewApp<AnySchema>>(app: A): A;
92
+ /** The app a store's schema was folded for, by `withRooms` or `withTalk`; undefined for a schema no fold made. */
93
+ export declare const foldedAppOfSchema: (schema: object) => GraviewApp<AnySchema> | undefined;
94
+ /**
95
+ * FOLD THESE ROOMS INTO AN APP NOT YET FOLDED: `withRooms` with its own
96
+ * rooms, and `withTalk` with the host's merged in (Graview HQ
97
+ * feature:f-talk-to-the-app) — the app before the fold stays the one its
98
+ * author declared, whatever rooms the host brought.
99
+ */
100
+ export declare function foldRooms<A extends GraviewApp<AnySchema>>(app: A, rooms: AppRooms, talk?: TalkSettings): A;
81
101
  /**
82
102
  * A SNAPSHOT WITHOUT ITS TALK: every message taken out, for a copy that is
83
103
  * not this app's own history — a template, a remix, an export for
@@ -1 +1 @@
1
- {"version":3,"file":"kind.d.ts","sourceRoot":"","sources":["../../src/rooms/kind.ts"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AM,CAAA;KAAE,EAAE,CAAA;CAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAI9M"}
@@ -6,7 +6,9 @@ import { ActRefusal } from "../refused.js";
6
6
  import { createSchema } from "../schema/schema.js";
7
7
  import { defineNode, labelOf, withArticle } from "../schema/define-node.js";
8
8
  import { excerpt } from "../excerpt.js";
9
- import { AI_ROOM_ACTS, ASKS_ROOM, chatOn, DESIGN_ROOM, EDIT_MESSAGE, FRAMEWORK_ROOMS, isFrameworkRoom, KEEP_AI_TURN, LONGEST_MESSAGE, MESSAGE_KIND, POST_MESSAGE, REMOVE_MESSAGE, ROOM_ACTS, SETTLE_AI_TURN, SHARE_CONVERSATION } from "./shape.js";
9
+ import { AI_ROOM_ACTS, ANY_RECORD, ASKS_ROOM, chatOn, DESIGN_ROOM, EDIT_MESSAGE, FRAMEWORK_ROOMS, INTENTS, isFrameworkRoom, KEEP_AI_TURN, LONGEST_MESSAGE, MESSAGE_KIND, POST_MESSAGE, REMOVE_MESSAGE, ROOM_ACTS, SET_MESSAGE_INTENT, SETTLE_AI_TURN, SHARE_CONVERSATION, threadRoomsFor } from "./shape.js";
10
+ import { guessIntent } from "./intent.js";
11
+ import { touchesIn } from "./touches.js";
10
12
  /*
11
13
  * AN APP WITH ROOMS IS GIVEN WHAT THEY NEED, from the declaration alone
12
14
  * (Graview HQ feature:f-chat-rooms): the framework's `message` kind, the
@@ -56,10 +58,22 @@ export function unfoldedApp(app) {
56
58
  }
57
59
  /** Whether an app had its rooms folded in. */
58
60
  export const roomsFolded = (app) => UNFOLDED.has(app);
59
- /** The kinds a room's thread is on, each once. */
60
- const threadKinds = (rooms) => [...new Set(Object.values(rooms).flatMap((room) => (room.about ? [room.about] : [])))];
61
+ /** The kinds a room's thread is on, each once: every kind of the app (the message kind aside) where a room is a thread on any record. */
62
+ const threadKinds = (rooms, schema) => {
63
+ const named = [...new Set(Object.values(rooms).flatMap((room) => (room.about && room.about !== ANY_RECORD ? [room.about] : [])))];
64
+ if (!Object.values(rooms).some((room) => room.about === ANY_RECORD) || !schema)
65
+ return named;
66
+ return [...new Set([...named, ...schema.kinds.filter((kind) => kind !== MESSAGE_KIND)])];
67
+ };
61
68
  /** The rooms a message kind was made for, by its definition. */
62
69
  const ROOMS_OF_KIND = new WeakMap();
70
+ /** What the host said of talk where it supplied the rooms (`talk`), by the message kind's definition. */
71
+ const TALK_OF_KIND = new WeakMap();
72
+ /** What the host said of talk for an app's schema — its visitors' say — where it supplied the rooms (`talk`); undefined where it did not. */
73
+ export const talkOfSchema = (schema) => {
74
+ const definition = schema.tryDefinition(MESSAGE_KIND);
75
+ return definition ? TALK_OF_KIND.get(definition) : undefined;
76
+ };
63
77
  /** Whether a room of the app reads `@Name` as a mention: unless it says `mentions: false`. A room the kind was not made for reads none. */
64
78
  export function mentionsOnIn(schema, room) {
65
79
  const rooms = ROOMS_OF_KIND.get(schema.tryDefinition(MESSAGE_KIND) ?? {});
@@ -76,7 +90,7 @@ export const roomsOn = (store) => (chatOn(store) ? roomsOfSchema(store.schema) :
76
90
  /** Whether a page offers this store's conversations at all — the rooms' and those kept with the AI, in Conversations, on a record and on the bell: the app keeps talk, and chat is on. */
77
91
  export const talkOn = (store) => chatOn(store) && store.schema.tryDefinition(MESSAGE_KIND) !== undefined;
78
92
  /** The framework's message kind, for these rooms. */
79
- export function messageKind(rooms) {
93
+ export function messageKind(rooms, talk) {
80
94
  const ids = [...Object.keys(rooms), ...FRAMEWORK_ROOMS];
81
95
  const definition = defineNode(MESSAGE_KIND, {
82
96
  description: "Something somebody said in one of the app's rooms or in the thread on one of its records, or to the app's AI and what it said back.",
@@ -99,6 +113,8 @@ export function messageKind(rooms) {
99
113
  batches: z.optional(z.array(z.string())),
100
114
  entry: z.optional(z.string()),
101
115
  shared: z.optional(z.enum(["editors", "everyone"])),
116
+ intent: z.optional(z.enum(INTENTS)),
117
+ touches: z.optional(z.array(z.string())),
102
118
  }),
103
119
  plural: "Messages",
104
120
  display: { glance: ["body", "authorName", "at"] },
@@ -112,6 +128,8 @@ export function messageKind(rooms) {
112
128
  // The rooms the app declared, never the framework's: a page draws a room, a thread or a bell only for those.
113
129
  if (Object.keys(rooms).length > 0)
114
130
  ROOMS_OF_KIND.set(definition, rooms);
131
+ if (talk)
132
+ TALK_OF_KIND.set(definition, talk);
115
133
  return definition;
116
134
  }
117
135
  /** Whether a seat holding these roles is one a list of roles admits: unsaid, everybody. The host's own seat, acting for nobody, is always admitted. */
@@ -136,7 +154,7 @@ function messageNamed(ctx, id) {
136
154
  return node;
137
155
  }
138
156
  /** Whether a message is the acting seat's own: its author is the seat, or the person the seat acts as. */
139
- const ownMessage = (ctx, message) => (ctx.by?.id !== undefined && message.author === ctx.by.id) || (ctx.me !== undefined && message.author === ctx.me);
157
+ const ownMessage = (ctx, message) => (ctx.by?.id !== undefined && message.author === ctx.by.id) || (ctx.by?.kind !== "agent" && ctx.me !== undefined && message.author === ctx.me) || (ctx.by?.kind === "agent" && message.author === authorOf(ctx));
140
158
  /** A body as it is kept: trimmed at its ends, never empty, never longer than a message is. */
141
159
  function bodyOf(body) {
142
160
  const said = body.replace(/\r\n?/g, "\n").trim();
@@ -146,10 +164,29 @@ function bodyOf(body) {
146
164
  throw new ActRefusal(`A message holds ${LONGEST_MESSAGE} characters; this one has ${said.length}.`, "invalid");
147
165
  return said;
148
166
  }
167
+ /** Whether a seat is a visitor: somebody who never joined the app, or an agent acting for one. */
168
+ const isVisitorSeat = (by) => by?.visitor === true || by?.kind === "visitor";
169
+ /** What a message said to the owners is: a request or a report, never talk. */
170
+ const toOwnersIntent = (intent) => (intent === "report" ? "report" : "request");
171
+ /** Who a message is by: the acting seat as itself — an agent by its own id, or its name, never as the person it acts for. */
172
+ function authorOf(ctx) {
173
+ const by = ctx.by;
174
+ if (by?.kind === "agent") {
175
+ if (by.id !== undefined)
176
+ return by.id;
177
+ // An agent with no id of its own is itself for the person it acts for: two people's agents of one name are two authors.
178
+ const name = (by.name ?? "agent").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "agent";
179
+ return `agent:${name}${by.person?.id !== undefined ? `@${by.person.id}` : ""}`;
180
+ }
181
+ return by?.id ?? ctx.me ?? by?.kind ?? "someone";
182
+ }
149
183
  /** The three acts of an app's rooms: post, edit your own, remove your own (or anybody's, for a role a room lets moderate). */
150
- export function roomActs(rooms, schema) {
184
+ export function roomActs(rooms, schema, options = {}) {
151
185
  const ids = Object.keys(rooms);
152
- const threads = threadKinds(rooms);
186
+ const threads = threadKinds(rooms, schema);
187
+ const talk = options.talk;
188
+ /** Whether the acting seat is on a conversation with the owners: whoever began it, the app's owners, or the host's own seat. */
189
+ const ownersSide = (ctx, _rooms, asker) => ctx.by?.system === true || (asker !== undefined && (askerOf(ctx) === asker || authorOf(ctx) === asker)) || options.editors === "*" || (options.editors ?? []).some((role) => (ctx.by?.roles ?? []).includes(role));
153
190
  const post = defineMutation(POST_MESSAGE, {
154
191
  title: "Post a message",
155
192
  description: "Say something in one of the app's rooms, or in the thread on a record.",
@@ -159,6 +196,7 @@ export function roomActs(rooms, schema) {
159
196
  ...(threads.length > 0 ? { about: z.optional(refTo(threads)) } : {}),
160
197
  body: z.string().check(z.minLength(1), z.maxLength(LONGEST_MESSAGE)),
161
198
  replyTo: z.optional(refTo([MESSAGE_KIND])),
199
+ intent: z.optional(z.enum(INTENTS)),
162
200
  }),
163
201
  describe: (args, graph) => {
164
202
  const room = rooms[args.room];
@@ -170,37 +208,55 @@ export function roomActs(rooms, schema) {
170
208
  apply(ctx, args) {
171
209
  const room = roomNamed(rooms, args.room);
172
210
  const about = "about" in args && typeof args.about === "string" && args.about !== "" ? args.about : undefined;
211
+ const anyRecord = room.about === ANY_RECORD;
173
212
  if (room.about && about === undefined)
174
- throw new ActRefusal(`${room.title} is a thread on each ${room.about}: say which one this is about.`, "invalid");
213
+ throw new ActRefusal(anyRecord ? `${room.title} is a thread on a record: say which one this is about.` : `${room.title} is a thread on each ${room.about}: say which one this is about.`, "invalid");
175
214
  if (!room.about && about !== undefined)
176
215
  throw new ActRefusal(`${room.title} is one room for the whole app, about no one record.`, "invalid");
177
216
  if (about !== undefined) {
178
217
  const record = ctx.graph.getNode(about);
179
- if (!record || record.kind !== room.about)
180
- throw new ActRefusal(`There is no ${room.about} "${about}" here to talk about.`, "missing");
218
+ if (!record || (anyRecord ? !threadRoomsFor(rooms, record.kind).includes(args.room) : record.kind !== room.about)) {
219
+ throw new ActRefusal(anyRecord ? (record ? `A ${record.kind} has its own thread; say it there.` : `There is no record "${about}" here to talk about.`) : `There is no ${room.about} "${about}" here to talk about.`, "missing");
220
+ }
181
221
  }
182
222
  const allowed = room.post ?? room.read;
183
223
  if (!admits(allowed, ctx.by))
184
224
  throw new ActRefusal(`Only ${rolesSaid(allowed)} may post in ${room.title}.`, "forbidden");
185
- if (args.replyTo !== undefined) {
186
- const answered = messageNamed(ctx, args.replyTo);
187
- if (answered.room !== args.room || (answered.about ?? undefined) !== about)
188
- throw new ActRefusal("A reply answers a message in the same room, or the same thread.", "invalid");
225
+ const answered = args.replyTo !== undefined ? messageNamed(ctx, args.replyTo) : undefined;
226
+ if (answered && (answered.room !== args.room || (answered.about ?? undefined) !== about))
227
+ throw new ActRefusal("A reply answers a message in the same room, or the same thread.", "invalid");
228
+ const body = bodyOf(args.body);
229
+ const guessed = args.intent ?? guessIntent(body, { acts: options.acts?.() ?? [] });
230
+ const intent = room.to === "owners" ? toOwnersIntent(guessed) : guessed;
231
+ // Visitors, where the host supplied the rooms (`talk.visitors`): kept out unless it lets them send the owners a request or a report.
232
+ if (talk && isVisitorSeat(ctx.by)) {
233
+ if (talk.visitors !== "limited")
234
+ throw new ActRefusal("Visitors may not post here.", "forbidden");
235
+ if (room.to !== "owners")
236
+ throw new ActRefusal("A visitor may only send the app's owners a request or a report.", "forbidden");
189
237
  }
238
+ // Said to the owners: the conversation is its first author's, and seen by them and the owners (`to: "owners"`).
239
+ const asker = room.to === "owners" ? (answered ? (answered.asker ?? answered.author) : (askerOf(ctx) ?? authorOf(ctx))) : undefined;
240
+ if (room.to === "owners" && answered && !ownersSide(ctx, rooms, asker))
241
+ throw new ActRefusal("Only whoever began it, or the app's owners, may answer a conversation with the owners.", "forbidden");
190
242
  const by = ctx.by;
191
- const author = by?.id ?? ctx.me ?? by?.kind ?? "someone";
243
+ const author = authorOf(ctx);
244
+ const touches = touchesIn(body, ctx.graph, (schema ?? ctx.schema), about);
192
245
  ctx.addNode({
193
246
  // Unguessable, so an id asked for or stepped past says nothing of a room the seat may not read.
194
247
  id: ctx.freshId(`${args.room}-${unguessable()}`, MESSAGE_KIND),
195
248
  kind: MESSAGE_KIND,
196
249
  room: args.room,
197
250
  ...(about !== undefined ? { about } : {}),
198
- body: bodyOf(args.body),
251
+ body,
199
252
  author,
200
253
  ...(by?.name ? { authorName: by.name } : {}),
201
254
  ...(by?.kind ? { authorKind: by.kind } : {}),
202
255
  at: ctx.now ?? new Date().toISOString(),
203
256
  ...(args.replyTo !== undefined ? { replyTo: args.replyTo } : {}),
257
+ ...(asker !== undefined ? { asker } : {}),
258
+ intent,
259
+ ...(touches.length > 0 ? { touches } : {}),
204
260
  });
205
261
  },
206
262
  });
@@ -208,7 +264,7 @@ export function roomActs(rooms, schema) {
208
264
  title: "Edit the message",
209
265
  description: "Change what you said. Only its author may.",
210
266
  subject: { kinds: [MESSAGE_KIND], arg: "id" },
211
- writes: ["body", "editedAt"],
267
+ writes: ["body", "editedAt", "touches"],
212
268
  idempotent: true,
213
269
  input: z.object({ id: refTo([MESSAGE_KIND]), body: z.string().check(z.minLength(1), z.maxLength(LONGEST_MESSAGE)) }),
214
270
  describe: (args) => `Edit a message: ${excerpt(args.body, 60)}`,
@@ -221,7 +277,8 @@ export function roomActs(rooms, schema) {
221
277
  const body = bodyOf(args.body);
222
278
  if (body === message.body)
223
279
  return;
224
- ctx.patchNode(args.id, { body, editedAt: ctx.now ?? new Date().toISOString() });
280
+ const touches = touchesIn(body, ctx.graph, (schema ?? ctx.schema), message.about);
281
+ ctx.patchNode(args.id, { body, editedAt: ctx.now ?? new Date().toISOString(), touches: touches.length > 0 ? touches : undefined });
225
282
  },
226
283
  });
227
284
  const remove = defineMutation(REMOVE_MESSAGE, {
@@ -301,8 +358,7 @@ const OUTCOMES = ["offered", "accepted", "partly", "dismissed", "drawn", "failed
301
358
  * editors or everybody, or keep it to its asker again. Streamed words are
302
359
  * never kept: only a turn once it is over.
303
360
  */
304
- export function aiRoomActs(schema) {
305
- void schema;
361
+ export function aiRoomActs(schema, rooms = {}, acts) {
306
362
  const keep = defineMutation(KEEP_AI_TURN, {
307
363
  title: "Keep a conversation with the AI",
308
364
  description: "Keep what somebody asked the app's AI and what it said back, as two messages of a conversation only they see until they share it.",
@@ -319,6 +375,7 @@ export function aiRoomActs(schema) {
319
375
  outcome: z.optional(z.enum(OUTCOMES)),
320
376
  batches: z.optional(z.array(z.string())),
321
377
  entry: z.optional(z.string()),
378
+ intent: z.optional(z.enum(INTENTS)),
322
379
  }),
323
380
  describe: (args) => `Keep a conversation with the AI: ${excerpt(args.ask, 60)}`,
324
381
  apply(ctx, args) {
@@ -349,10 +406,16 @@ export function aiRoomActs(schema) {
349
406
  ...(args.door ? { door: args.door } : {}),
350
407
  ...(opener?.shared ? { shared: opener.shared } : {}),
351
408
  };
409
+ // What the person asked for: as the page said it, else "Better UI" asks a change, else the app's own guess.
410
+ const ask = turnBody(args.ask, "(asked)");
411
+ const intent = args.intent ?? (args.room === DESIGN_ROOM || args.door === "better" ? "change" : guessIntent(ask, { acts: acts?.() ?? [] }));
412
+ const touches = touchesIn(ask, ctx.graph, (schema ?? ctx.schema), about);
352
413
  ctx.addNode({
353
414
  ...common,
354
415
  id: askId,
355
- body: turnBody(args.ask, "(asked)"),
416
+ body: ask,
417
+ intent,
418
+ ...(touches.length > 0 ? { touches } : {}),
356
419
  author: asker ?? "someone",
357
420
  ...(person?.name ? { authorName: person.name } : {}),
358
421
  authorKind: "human",
@@ -428,9 +491,31 @@ export function aiRoomActs(schema) {
428
491
  ctx.patchNode(message.id, { shared });
429
492
  },
430
493
  });
431
- for (const act of [keep, settle, share])
494
+ const switchIntent = defineMutation(SET_MESSAGE_INTENT, {
495
+ title: "Say what the message is",
496
+ description: "Switch what a message is — a question, something to do, a change to the app, a request to the owners, a problem report or talk. Its author's, a moderator's or the host's.",
497
+ subject: { kinds: [MESSAGE_KIND], arg: "id" },
498
+ writes: ["intent"],
499
+ idempotent: true,
500
+ input: z.object({ id: refTo([MESSAGE_KIND]), intent: z.enum(INTENTS) }),
501
+ describe: (args) => `Say the message is ${args.intent}`,
502
+ apply(ctx, args) {
503
+ const message = messageNamed(ctx, args.id);
504
+ if (message.removed)
505
+ throw new ActRefusal("That message was removed.", "invalid");
506
+ const room = rooms[message.room];
507
+ const mine = ownMessage(ctx, message) || (isFrameworkRoom(message.room) && asksIt(ctx, message));
508
+ if (!mine && ctx.by?.system !== true && !(room?.moderate && admits(room.moderate, ctx.by)))
509
+ throw new ActRefusal("Only whoever said it, or the app, may say what a message is.", "forbidden");
510
+ if (room?.to === "owners" && args.intent !== "request" && args.intent !== "report")
511
+ throw new ActRefusal(`What is said in ${room.title} is a request or a report.`, "invalid");
512
+ if (message.intent !== args.intent)
513
+ ctx.patchNode(args.id, { intent: args.intent });
514
+ },
515
+ });
516
+ for (const act of [keep, settle, share, switchIntent])
432
517
  FRAMEWORK.add(act);
433
- return [keep, settle, share];
518
+ return [keep, settle, share, switchIntent];
434
519
  }
435
520
  /** The grant that lets the acts be run: each room says who it admits, and the acts hold to it. */
436
521
  export const ROOMS_GRANT = {
@@ -441,14 +526,23 @@ export const ROOMS_GRANT = {
441
526
  };
442
527
  FRAMEWORK.add(ROOMS_GRANT);
443
528
  /** Each room's sight over its messages: its readers, and a thread's messages only where the record is seen too. */
444
- export function roomSights(rooms) {
445
- return Object.entries(rooms).map(([id, room]) => framework({
446
- roles: room.read ?? "*",
447
- kinds: [MESSAGE_KIND],
448
- where: { field: "room", is: [id] },
449
- ...(room.about ? { follows: "about" } : {}),
450
- describe: `${room.read ? `Only ${rolesSaid(room.read)}` : "Everybody"} may read ${room.title}${room.about ? `, and only on ${withArticle(room.about)} they can see` : ""}.`,
451
- }));
529
+ export function roomSights(rooms, policy) {
530
+ return Object.entries(rooms).flatMap(([id, room]) => (room.to === "owners" ? ownersSights(id, room, policy) : [framework({
531
+ roles: room.read ?? "*",
532
+ kinds: [MESSAGE_KIND],
533
+ where: { field: "room", is: [id] },
534
+ ...(room.about ? { follows: "about" } : {}),
535
+ describe: `${room.read ? `Only ${rolesSaid(room.read)}` : "Everybody"} may read ${room.title}${room.about === ANY_RECORD ? ", and only on a record they can see" : room.about ? `, and only on ${withArticle(room.about)} they can see` : ""}.`,
536
+ })]));
537
+ }
538
+ /** A room to the owners' sights: each conversation by whoever began it, and by the app's editors (who may also be limited by the room's `read`). */
539
+ function ownersSights(id, room, policy) {
540
+ const editors = editorRolesOf(policy);
541
+ const readers = room.read ? (editors === "*" ? room.read : editors.filter((role) => room.read.includes(role))) : editors;
542
+ return [
543
+ framework({ roles: "*", kinds: [MESSAGE_KIND], where: { field: "room", is: [id] }, mine: "asker", describe: `A conversation in ${room.title} is seen by whoever began it.` }),
544
+ ...(readers === "*" || readers.length > 0 ? [framework({ roles: readers, kinds: [MESSAGE_KIND], where: { field: "room", is: [id] }, describe: `The app's owners read ${room.title}.` })] : []),
545
+ ];
452
546
  }
453
547
  /** A part of the policy the framework folded in, known as such. */
454
548
  function framework(part) {
@@ -493,7 +587,7 @@ export function roomsPolicy(policy, rooms, kinds, taken = new Set()) {
493
587
  const grant = taken.size === 0 && acts.length === ROOMS_GRANT.mutations.length ? ROOMS_GRANT : framework({ ...ROOMS_GRANT, mutations: acts.filter((act) => !taken.has(act)) });
494
588
  const grants = base.grants.some((one) => FRAMEWORK.has(one) && one.mutations !== "*") ? base.grants : [...base.grants, grant];
495
589
  const sights = base.sees?.length ? base.sees : [framework({ roles: "*", kinds: kinds.filter((kind) => kind !== MESSAGE_KIND), describe: "Everybody sees everything else here." })];
496
- return { ...base, grants, sees: [...sights.filter((sight) => !sight.kinds.includes(MESSAGE_KIND)), ...roomSights(rooms), ...frameworkRoomSights(policy)] };
590
+ return { ...base, grants, sees: [...sights.filter((sight) => !sight.kinds.includes(MESSAGE_KIND)), ...roomSights(rooms, policy), ...frameworkRoomSights(policy)] };
497
591
  }
498
592
  /**
499
593
  * FOLD AN APP'S ROOMS IN: its schema with the message kind, its acts with
@@ -511,15 +605,30 @@ export function withRooms(app) {
511
605
  return app;
512
606
  if (app.schema.tryDefinition(MESSAGE_KIND))
513
607
  return app;
514
- const rooms = app.rooms ?? {};
515
- const kind = messageKind(rooms);
608
+ return foldRooms(app, app.rooms ?? {});
609
+ }
610
+ /** The folded app a schema was folded for: what a store opened on it with `talk` folds again (`withTalk`). */
611
+ const FOLDED_OF_SCHEMA = new WeakMap();
612
+ /** The app a store's schema was folded for, by `withRooms` or `withTalk`; undefined for a schema no fold made. */
613
+ export const foldedAppOfSchema = (schema) => FOLDED_OF_SCHEMA.get(schema);
614
+ /**
615
+ * FOLD THESE ROOMS INTO AN APP NOT YET FOLDED: `withRooms` with its own
616
+ * rooms, and `withTalk` with the host's merged in (Graview HQ
617
+ * feature:f-talk-to-the-app) — the app before the fold stays the one its
618
+ * author declared, whatever rooms the host brought.
619
+ */
620
+ export function foldRooms(app, rooms, talk) {
621
+ const kind = messageKind(rooms, talk);
516
622
  const schema = createSchema([...app.schema.definitions, kind], app.schema.computed);
517
623
  const taken = new Set((app.mutations ?? []).map((mutation) => mutation.name));
518
- const acts = [...(Object.keys(rooms).length > 0 ? roomActs(rooms, schema) : []), ...aiRoomActs(schema)].filter((act) => !taken.has(act.name));
624
+ const own = (app.mutations ?? []).map((mutation) => ({ name: mutation.name, title: mutation.title }));
625
+ const editors = editorRolesOf(app.policy);
626
+ const acts = [...(Object.keys(rooms).length > 0 ? roomActs(rooms, schema, { acts: () => own, editors, ...(talk ? { talk } : {}) }) : []), ...aiRoomActs(schema, rooms, () => own)].filter((act) => !taken.has(act.name));
519
627
  // An act of the app's own by one of these names (`room-act-taken`) is not widened by the rooms' grant.
520
628
  const policy = roomsPolicy(app.policy, rooms, schema.kinds, taken);
521
629
  const folded = { ...app, schema, mutations: [...(app.mutations ?? []), ...acts], ...(policy ? { policy } : {}) };
522
630
  UNFOLDED.set(folded, app);
631
+ FOLDED_OF_SCHEMA.set(schema, folded);
523
632
  return folded;
524
633
  }
525
634
  /**