@chatwarden/core 0.1.6 → 0.1.7

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 (131) hide show
  1. package/README.md +50 -0
  2. package/dist/src/ai/agreement.d.ts +46 -0
  3. package/dist/src/ai/agreement.d.ts.map +1 -0
  4. package/dist/src/ai/agreement.js +71 -0
  5. package/dist/src/ai/agreement.js.map +1 -0
  6. package/dist/src/ai/breaker.d.ts +31 -0
  7. package/dist/src/ai/breaker.d.ts.map +1 -0
  8. package/dist/src/ai/breaker.js +62 -0
  9. package/dist/src/ai/breaker.js.map +1 -0
  10. package/dist/src/ai/budget.d.ts +26 -0
  11. package/dist/src/ai/budget.d.ts.map +1 -0
  12. package/dist/src/ai/budget.js +57 -0
  13. package/dist/src/ai/budget.js.map +1 -0
  14. package/dist/src/ai/case.d.ts +37 -0
  15. package/dist/src/ai/case.d.ts.map +1 -0
  16. package/dist/src/ai/case.js +30 -0
  17. package/dist/src/ai/case.js.map +1 -0
  18. package/dist/src/ai/casebook.d.ts +59 -0
  19. package/dist/src/ai/casebook.d.ts.map +1 -0
  20. package/dist/src/ai/casebook.js +47 -0
  21. package/dist/src/ai/casebook.js.map +1 -0
  22. package/dist/src/ai/ceilings.d.ts +42 -0
  23. package/dist/src/ai/ceilings.d.ts.map +1 -0
  24. package/dist/src/ai/ceilings.js +59 -0
  25. package/dist/src/ai/ceilings.js.map +1 -0
  26. package/dist/src/ai/fake.d.ts +41 -0
  27. package/dist/src/ai/fake.d.ts.map +1 -0
  28. package/dist/src/ai/fake.js +75 -0
  29. package/dist/src/ai/fake.js.map +1 -0
  30. package/dist/src/ai/hash.d.ts +13 -0
  31. package/dist/src/ai/hash.d.ts.map +1 -0
  32. package/dist/src/ai/hash.js +19 -0
  33. package/dist/src/ai/hash.js.map +1 -0
  34. package/dist/src/ai/inert.d.ts +5 -0
  35. package/dist/src/ai/inert.d.ts.map +1 -0
  36. package/dist/src/ai/inert.js +22 -0
  37. package/dist/src/ai/inert.js.map +1 -0
  38. package/dist/src/ai/injection.d.ts +8 -0
  39. package/dist/src/ai/injection.d.ts.map +1 -0
  40. package/dist/src/ai/injection.js +30 -0
  41. package/dist/src/ai/injection.js.map +1 -0
  42. package/dist/src/ai/lines.d.ts +64 -0
  43. package/dist/src/ai/lines.d.ts.map +1 -0
  44. package/dist/src/ai/lines.js +172 -0
  45. package/dist/src/ai/lines.js.map +1 -0
  46. package/dist/src/ai/prompt.d.ts +44 -0
  47. package/dist/src/ai/prompt.d.ts.map +1 -0
  48. package/dist/src/ai/prompt.js +185 -0
  49. package/dist/src/ai/prompt.js.map +1 -0
  50. package/dist/src/ai/redact.d.ts +29 -0
  51. package/dist/src/ai/redact.d.ts.map +1 -0
  52. package/dist/src/ai/redact.js +160 -0
  53. package/dist/src/ai/redact.js.map +1 -0
  54. package/dist/src/ai/schema.d.ts +6 -0
  55. package/dist/src/ai/schema.d.ts.map +1 -0
  56. package/dist/src/ai/schema.js +50 -0
  57. package/dist/src/ai/schema.js.map +1 -0
  58. package/dist/src/ai/service.d.ts +328 -0
  59. package/dist/src/ai/service.d.ts.map +1 -0
  60. package/dist/src/ai/service.js +749 -0
  61. package/dist/src/ai/service.js.map +1 -0
  62. package/dist/src/ai/types.d.ts +180 -0
  63. package/dist/src/ai/types.d.ts.map +1 -0
  64. package/dist/src/ai/types.js +23 -0
  65. package/dist/src/ai/types.js.map +1 -0
  66. package/dist/src/ai/validate.d.ts +30 -0
  67. package/dist/src/ai/validate.d.ts.map +1 -0
  68. package/dist/src/ai/validate.js +160 -0
  69. package/dist/src/ai/validate.js.map +1 -0
  70. package/dist/src/ai/worker.d.ts +74 -0
  71. package/dist/src/ai/worker.d.ts.map +1 -0
  72. package/dist/src/ai/worker.js +286 -0
  73. package/dist/src/ai/worker.js.map +1 -0
  74. package/dist/src/audit.d.ts +12 -3
  75. package/dist/src/audit.d.ts.map +1 -1
  76. package/dist/src/audit.js +30 -4
  77. package/dist/src/audit.js.map +1 -1
  78. package/dist/src/chatwarden.d.ts +16 -0
  79. package/dist/src/chatwarden.d.ts.map +1 -1
  80. package/dist/src/chatwarden.js +49 -1
  81. package/dist/src/chatwarden.js.map +1 -1
  82. package/dist/src/decide.d.ts +36 -1
  83. package/dist/src/decide.d.ts.map +1 -1
  84. package/dist/src/decide.js +62 -2
  85. package/dist/src/decide.js.map +1 -1
  86. package/dist/src/documents.d.ts +1 -1
  87. package/dist/src/documents.d.ts.map +1 -1
  88. package/dist/src/documents.js +4 -1
  89. package/dist/src/documents.js.map +1 -1
  90. package/dist/src/index.d.ts +27 -5
  91. package/dist/src/index.d.ts.map +1 -1
  92. package/dist/src/index.js +17 -2
  93. package/dist/src/index.js.map +1 -1
  94. package/dist/src/profile.d.ts +30 -1
  95. package/dist/src/profile.d.ts.map +1 -1
  96. package/dist/src/profile.js +43 -4
  97. package/dist/src/profile.js.map +1 -1
  98. package/dist/src/retention.d.ts +19 -0
  99. package/dist/src/retention.d.ts.map +1 -1
  100. package/dist/src/retention.js +33 -10
  101. package/dist/src/retention.js.map +1 -1
  102. package/dist/src/types.d.ts +269 -2
  103. package/dist/src/types.d.ts.map +1 -1
  104. package/dist/src/types.js.map +1 -1
  105. package/package.json +2 -2
  106. package/src/ai/agreement.ts +106 -0
  107. package/src/ai/breaker.ts +73 -0
  108. package/src/ai/budget.ts +65 -0
  109. package/src/ai/case.ts +74 -0
  110. package/src/ai/casebook.ts +75 -0
  111. package/src/ai/ceilings.ts +68 -0
  112. package/src/ai/fake.ts +105 -0
  113. package/src/ai/hash.ts +20 -0
  114. package/src/ai/inert.ts +26 -0
  115. package/src/ai/injection.ts +32 -0
  116. package/src/ai/lines.ts +216 -0
  117. package/src/ai/prompt.ts +208 -0
  118. package/src/ai/redact.ts +174 -0
  119. package/src/ai/schema.ts +51 -0
  120. package/src/ai/service.ts +955 -0
  121. package/src/ai/types.ts +165 -0
  122. package/src/ai/validate.ts +173 -0
  123. package/src/ai/worker.ts +364 -0
  124. package/src/audit.ts +31 -5
  125. package/src/chatwarden.ts +64 -1
  126. package/src/decide.ts +97 -4
  127. package/src/documents.ts +5 -2
  128. package/src/index.ts +52 -1
  129. package/src/profile.ts +68 -4
  130. package/src/retention.ts +47 -10
  131. package/src/types.ts +294 -2
@@ -0,0 +1,42 @@
1
+ import type { SanctionKind } from '../types.js';
2
+ /**
3
+ * The longest step the one-key accept may pre-fill, and the longest a later level 3 may take: 24 hours.
4
+ * @experimental
5
+ */
6
+ export declare const AI_MAX_PREFILL_MS: number;
7
+ /**
8
+ * The kinds an AI step may ever be: a note, a warning or a chat restriction. Never a ban and never an area ban. A frozen list.
9
+ * @experimental
10
+ */
11
+ export declare const AI_MAX_KIND: readonly SanctionKind[];
12
+ /** True for a kind in {@link AI_MAX_KIND}. Anything else (a ban, an area ban, a prototype key, a non-string) is false. */
13
+ export declare function isAllowedKind(kind: unknown): kind is SanctionKind;
14
+ /**
15
+ * Thrown by `assertWithinCeilings`. `code` is a fixed string, never echoed text.
16
+ * @experimental
17
+ */
18
+ export declare class AICeilingError extends Error {
19
+ readonly code: 'ceiling_kind' | 'ceiling_duration' | 'ceiling_evidence';
20
+ constructor(code: AICeilingError['code'], message: string);
21
+ }
22
+ /**
23
+ * Throws when a step an AI proposes would break a ceiling: a kind outside {@link AI_MAX_KIND} (a ban, an area ban), a chat
24
+ * restriction with no length, any length (any kind, a warning or note included) that is not a finite number above 0 and at most
25
+ * {@link AI_MAX_PREFILL_MS}, or evidence with no line by the reported person.
26
+ * `evidence.cited` is the refs the AI cited; `evidence.ownRefs` the refs of lines the reported person wrote.
27
+ * @experimental
28
+ */
29
+ export declare function assertWithinCeilings(step: {
30
+ kind: SanctionKind;
31
+ durationMs: number | null;
32
+ }, evidence: {
33
+ cited: readonly string[];
34
+ ownRefs: ReadonlySet<string>;
35
+ }): void;
36
+ /**
37
+ * Whether the AI may act on this person. Always true now; level 3 will back it with a "do not automate" mark. Called on every
38
+ * path that could ever act. Reads and drafts are advice, so they are produced either way.
39
+ * @experimental
40
+ */
41
+ export declare function automationAllowed(person: string): boolean;
42
+ //# sourceMappingURL=ceilings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ceilings.d.ts","sourceRoot":"","sources":["../../../src/ai/ceilings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAiB,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,YAAY,EAAwD,CAAC;AAExG,0HAA0H;AAC1H,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,YAAY,CAEjE;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;gBAC5D,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM;CAK1D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACvD,QAAQ,EAAE;IAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,GACnE,IAAI,CAWN;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGzD"}
@@ -0,0 +1,59 @@
1
+ // The ceilings (design section 8). They hold in code, not by convention: the AI module cannot write a sanction at all (an ESLint
2
+ // rule forbids importing the sanction modules), and anything that pre-fills a step for a human, or one day acts, passes through
3
+ // `assertWithinCeilings`.
4
+ /**
5
+ * The longest step the one-key accept may pre-fill, and the longest a later level 3 may take: 24 hours.
6
+ * @experimental
7
+ */
8
+ export const AI_MAX_PREFILL_MS = 24 * 3_600_000;
9
+ /**
10
+ * The kinds an AI step may ever be: a note, a warning or a chat restriction. Never a ban and never an area ban. A frozen list.
11
+ * @experimental
12
+ */
13
+ export const AI_MAX_KIND = Object.freeze(['note', 'warning', 'chat']);
14
+ /** True for a kind in {@link AI_MAX_KIND}. Anything else (a ban, an area ban, a prototype key, a non-string) is false. */
15
+ export function isAllowedKind(kind) {
16
+ return typeof kind === 'string' && AI_MAX_KIND.includes(kind);
17
+ }
18
+ /**
19
+ * Thrown by `assertWithinCeilings`. `code` is a fixed string, never echoed text.
20
+ * @experimental
21
+ */
22
+ export class AICeilingError extends Error {
23
+ code;
24
+ constructor(code, message) {
25
+ super(message);
26
+ this.name = 'AICeilingError';
27
+ this.code = code;
28
+ }
29
+ }
30
+ /**
31
+ * Throws when a step an AI proposes would break a ceiling: a kind outside {@link AI_MAX_KIND} (a ban, an area ban), a chat
32
+ * restriction with no length, any length (any kind, a warning or note included) that is not a finite number above 0 and at most
33
+ * {@link AI_MAX_PREFILL_MS}, or evidence with no line by the reported person.
34
+ * `evidence.cited` is the refs the AI cited; `evidence.ownRefs` the refs of lines the reported person wrote.
35
+ * @experimental
36
+ */
37
+ export function assertWithinCeilings(step, evidence) {
38
+ if (!isAllowedKind(step.kind))
39
+ throw new AICeilingError('ceiling_kind', 'this kind is beyond what the AI may do');
40
+ // No kind may carry more than 24 hours, a warning or note included; a chat restriction must carry a length.
41
+ const d = step.durationMs;
42
+ const lengthOk = typeof d === 'number' && Number.isFinite(d) && d > 0 && d <= AI_MAX_PREFILL_MS;
43
+ if (!(d === null && step.kind !== 'chat') && !lengthOk) {
44
+ throw new AICeilingError('ceiling_duration', 'duration is beyond what the AI may do (24 hours at most)');
45
+ }
46
+ if (!evidence.cited.some((ref) => evidence.ownRefs.has(ref))) {
47
+ throw new AICeilingError('ceiling_evidence', 'no cited evidence line is by the reported person');
48
+ }
49
+ }
50
+ /**
51
+ * Whether the AI may act on this person. Always true now; level 3 will back it with a "do not automate" mark. Called on every
52
+ * path that could ever act. Reads and drafts are advice, so they are produced either way.
53
+ * @experimental
54
+ */
55
+ export function automationAllowed(person) {
56
+ void person;
57
+ return true;
58
+ }
59
+ //# sourceMappingURL=ceilings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ceilings.js","sourceRoot":"","sources":["../../../src/ai/ceilings.ts"],"names":[],"mappings":"AAEA,iIAAiI;AACjI,gIAAgI;AAChI,0BAA0B;AAE1B;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,SAAS,CAAC;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAA4B,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAU,CAAC,CAAC;AAExG,0HAA0H;AAC1H,MAAM,UAAU,aAAa,CAAC,IAAa;IACzC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAoB,CAAC,CAAC;AAChF,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAA2D;IACxE,YAAY,IAA4B,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAuD,EACvD,QAAoE;IAEpE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,cAAc,CAAC,cAAc,EAAE,wCAAwC,CAAC,CAAC;IAClH,4GAA4G;IAC5G,MAAM,CAAC,GAAY,IAAI,CAAC,UAAU,CAAC;IACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC;IAChG,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvD,MAAM,IAAI,cAAc,CAAC,kBAAkB,EAAE,0DAA0D,CAAC,CAAC;IAC3G,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,cAAc,CAAC,kBAAkB,EAAE,kDAAkD,CAAC,CAAC;IACnG,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,KAAK,MAAM,CAAC;IACZ,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { AIError } from './types.js';
2
+ import type { AbortSignalLike, AIRead, AIReadInput, AIUsage, ModerationAI } from './types.js';
3
+ /** One scripted call: an answer (with optional usage), a thrown error, a call that never returns, or the default answer with this usage. */
4
+ export type FakeStep = {
5
+ output: unknown;
6
+ usage?: Partial<AIUsage>;
7
+ } | {
8
+ error: AIError;
9
+ } | {
10
+ hang: true;
11
+ } | {
12
+ usage: Partial<AIUsage>;
13
+ };
14
+ /** What a function script is given. `call` counts from 1. */
15
+ export interface FakeCallContext {
16
+ call: number;
17
+ signal: AbortSignalLike;
18
+ }
19
+ export type FakeScript = readonly FakeStep[] | ((input: AIReadInput, ctx: FakeCallContext) => FakeStep | Promise<FakeStep>);
20
+ /** The fake adapter, with what it was asked kept for the test to look at. */
21
+ export interface FakeModerationAI extends ModerationAI {
22
+ /** Every input it was called with, oldest first. */
23
+ readonly calls: AIReadInput[];
24
+ /** The abort signal of each call. */
25
+ readonly signals: AbortSignalLike[];
26
+ readonly callCount: number;
27
+ /** Add a step to the end of the queue (a queue script only). */
28
+ push(...steps: FakeStep[]): void;
29
+ }
30
+ /** Usage of a fake call unless a step says otherwise: 1 000 micro-dollars. */
31
+ export declare const FAKE_USAGE: AIUsage;
32
+ /**
33
+ * A valid answer for `input`, by a simple rule: nothing by P1 means banter and no action; otherwise P1 was rude, citing the first
34
+ * line P1 wrote, with a recommendation to uphold under the first active rule. Overrides replace fields.
35
+ */
36
+ export declare function fakeRead(input: AIReadInput, over?: Partial<AIRead>): AIRead;
37
+ /** The adapter id is what the audit trail shows, so it keeps to the audit actor's characters. */
38
+ export declare function createFakeModerationAI(script?: FakeScript, opts?: {
39
+ id?: string;
40
+ }): FakeModerationAI;
41
+ //# sourceMappingURL=fake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake.d.ts","sourceRoot":"","sources":["../../../src/ai/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAgB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK5G,4IAA4I;AAC5I,MAAM,MAAM,QAAQ,GAChB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,GAC7C;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC;AAEhC,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,MAAM,UAAU,GAAG,SAAS,QAAQ,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,eAAe,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE5H,6EAA6E;AAC7E,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,eAAe,EAAE,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gEAAgE;IAChE,IAAI,CAAC,GAAG,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;CAClC;AAED,8EAA8E;AAC9E,eAAO,MAAM,UAAU,EAAE,OAOvB,CAAC;AAEH;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,GAAE,OAAO,CAAC,MAAM,CAAM,GAAG,MAAM,CAwB/E;AAED,iGAAiG;AACjG,wBAAgB,sBAAsB,CAAC,MAAM,GAAE,UAAe,EAAE,IAAI,GAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,gBAAgB,CA+B5G"}
@@ -0,0 +1,75 @@
1
+ import { AIError } from './types.js';
2
+ /** Usage of a fake call unless a step says otherwise: 1 000 micro-dollars. */
3
+ export const FAKE_USAGE = Object.freeze({
4
+ model: 'fake-1',
5
+ inputTokens: 1000,
6
+ outputTokens: 100,
7
+ cacheReadTokens: 0,
8
+ cacheWriteTokens: 0,
9
+ costMicros: 1000,
10
+ });
11
+ /**
12
+ * A valid answer for `input`, by a simple rule: nothing by P1 means banter and no action; otherwise P1 was rude, citing the first
13
+ * line P1 wrote, with a recommendation to uphold under the first active rule. Overrides replace fields.
14
+ */
15
+ export function fakeRead(input, over = {}) {
16
+ const own = input.lines.filter((l) => l.who === 'P1').map((l) => l.ref);
17
+ const rule = input.rules[0]?.number ?? 'uncovered';
18
+ const base = own.length === 0
19
+ ? {
20
+ severity: 'banter',
21
+ rule: null,
22
+ summary: 'Nothing in the lines breaks a rule.',
23
+ evidence: [],
24
+ confidence: 'medium',
25
+ injectionSuspected: false,
26
+ recommendation: { verdict: 'no_action', severity: 'banter', rule: null, evidence: [] },
27
+ }
28
+ : {
29
+ severity: 'rude',
30
+ rule,
31
+ summary: 'The reported player was rude in chat.',
32
+ evidence: [own[0]],
33
+ confidence: 'medium',
34
+ injectionSuspected: false,
35
+ recommendation: { verdict: 'upheld', severity: 'rude', rule, evidence: [own[0]] },
36
+ };
37
+ return { ...base, ...over };
38
+ }
39
+ /** The adapter id is what the audit trail shows, so it keeps to the audit actor's characters. */
40
+ export function createFakeModerationAI(script = [], opts = {}) {
41
+ const queue = typeof script === 'function' ? [] : [...script];
42
+ const calls = [];
43
+ const signals = [];
44
+ return {
45
+ id: opts.id ?? 'fake:model',
46
+ calls,
47
+ signals,
48
+ get callCount() {
49
+ return calls.length;
50
+ },
51
+ push: (...steps) => void queue.push(...steps),
52
+ async read(input, options) {
53
+ calls.push(input);
54
+ signals.push(options.signal);
55
+ const call = calls.length;
56
+ const step = typeof script === 'function' ? await script(input, { call, signal: options.signal }) : queue.shift();
57
+ if (step !== undefined && 'error' in step)
58
+ throw step.error;
59
+ if (step !== undefined && 'hang' in step) {
60
+ // Never answers; settles only when the caller gives up, as a real client does on abort.
61
+ return await new Promise((_, reject) => {
62
+ const stop = () => reject(new AIError('timeout', 'aborted'));
63
+ if (options.signal.aborted)
64
+ stop();
65
+ else
66
+ options.signal.addEventListener('abort', stop, { once: true });
67
+ });
68
+ }
69
+ const usage = { ...FAKE_USAGE, ...(step !== undefined && 'usage' in step ? step.usage : {}) };
70
+ const output = step !== undefined && 'output' in step ? step.output : fakeRead(input);
71
+ return { output, usage };
72
+ },
73
+ };
74
+ }
75
+ //# sourceMappingURL=fake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake.js","sourceRoot":"","sources":["../../../src/ai/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAgCrC,8EAA8E;AAC9E,M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gBACxF,OAAO,MAAM,IAAI,OAAO,CAAe,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;oBACnD,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;oBACnE,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO;wBAAE,IAAI,EAAE,CAAC;;wBAC9B,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBACtE,CAAC,CAAC,CAAC;YACL,CAAC;YACD,MAAM,KAAK,GAAY,EAAE,GAAG,UAAU,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;YACvG,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,IAAI,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACtF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { AIReadInput } from './types.js';
2
+ /**
3
+ * The input hash a stored read is valid for (design section 6): sha256 over the prompt version, the rendered stable prefix (the
4
+ * policy text that changes meaning), the case's own rendered inputs and the adapter id, in that order. The casebook examples are
5
+ * NOT part of it: a growing casebook must not make every stored read look stale, and the read records the ids of the examples it
6
+ * used instead (`AIStoredRead.exampleIds`). The `example:` rows are therefore left out of the variable part before hashing; no
7
+ * other row of the data block can begin that way (a chat line starts `L<n> `, the rest are fixed keys). The fields are framed as a
8
+ * JSON array, so no part can slide into the next. Object key order in `input` cannot matter: only those values are read. A hex
9
+ * string of 64 characters.
10
+ * @experimental
11
+ */
12
+ export declare function inputHash(input: AIReadInput, adapterId: string): string;
13
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/ai/hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMvE"}
@@ -0,0 +1,19 @@
1
+ import { sha256Hex } from '../crypto.js';
2
+ /**
3
+ * The input hash a stored read is valid for (design section 6): sha256 over the prompt version, the rendered stable prefix (the
4
+ * policy text that changes meaning), the case's own rendered inputs and the adapter id, in that order. The casebook examples are
5
+ * NOT part of it: a growing casebook must not make every stored read look stale, and the read records the ids of the examples it
6
+ * used instead (`AIStoredRead.exampleIds`). The `example:` rows are therefore left out of the variable part before hashing; no
7
+ * other row of the data block can begin that way (a chat line starts `L<n> `, the rest are fixed keys). The fields are framed as a
8
+ * JSON array, so no part can slide into the next. Object key order in `input` cannot matter: only those values are read. A hex
9
+ * string of 64 characters.
10
+ * @experimental
11
+ */
12
+ export function inputHash(input, adapterId) {
13
+ const caseInputs = input.prompt.variable
14
+ .split('\n')
15
+ .filter((row) => !row.startsWith('example: '))
16
+ .join('\n');
17
+ return sha256Hex(JSON.stringify([input.promptVersion, input.prompt.stable, caseInputs, adapterId]));
18
+ }
19
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../src/ai/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,KAAkB,EAAE,SAAiB;IAC7D,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ;SACrC,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;SAC7C,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { AiFacade, AiStatsView } from './service.js';
2
+ /** The facade when no AI is configured: always off, never touches the store. */
3
+ export declare function createInertAi(): AiFacade;
4
+ export declare const emptyStats: (since: number) => AiStatsView;
5
+ //# sourceMappingURL=inert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inert.d.ts","sourceRoot":"","sources":["../../../src/ai/inert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAY,MAAM,cAAc,CAAC;AAKpE,gFAAgF;AAChF,wBAAgB,aAAa,IAAI,QAAQ,CAgBxC;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,WAAmL,CAAC"}
@@ -0,0 +1,22 @@
1
+ // The facade when no AI is configured. Apart from the service so that a build with no AI in it never loads the service (the kit imports the
2
+ // service only when `createChatwarden` is given an adapter): a browser bundle of the kit carries these few lines and not the AI module.
3
+ /** The facade when no AI is configured: always off, never touches the store. */
4
+ export function createInertAi() {
5
+ const status = { available: false, level: 0, maxLevel: 0, state: 'off', spentMicros: 0, capMicros: 0, capCalls: 0, day: '', reads: 0, cacheHitRate: null, invalid: {} };
6
+ return {
7
+ level: () => 0,
8
+ status: () => ({ ...status, invalid: {} }),
9
+ read: () => null,
10
+ expected: () => false,
11
+ readAgain: () => Promise.resolve('off'),
12
+ briefs: () => new Map(),
13
+ stats: (q) => emptyStats(q?.since ?? 0),
14
+ markReversed: () => false,
15
+ dontTeach: () => false,
16
+ idle: () => Promise.resolve(),
17
+ sweep: () => Promise.resolve(),
18
+ close: () => undefined,
19
+ };
20
+ }
21
+ export const emptyStats = (since) => ({ since, decided: 0, agree: 0, override: 0, none: 0, falsePositives: 0, oneClick: 0, agreementRate: null, falsePositiveRate: null, oneClickRate: null, rules: [] });
22
+ //# sourceMappingURL=inert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inert.js","sourceRoot":"","sources":["../../../src/ai/inert.ts"],"names":[],"mappings":"AAEA,4IAA4I;AAC5I,wIAAwI;AAExI,gFAAgF;AAChF,MAAM,UAAU,aAAa;IAC3B,MAAM,MAAM,GAAa,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAClL,OAAO;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACd,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC1C,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;QAChB,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;QACrB,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACvC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE;QACvB,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;QACvC,YAAY,EAAE,GAAG,EAAE,CAAC,KAAK;QACzB,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK;QACtB,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QAC7B,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;QAC9B,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAe,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * True when a chat line or note reads like an attempt to instruct the AI ("ignore the above", "you are now ...", "system: ...",
3
+ * "as an AI", "disregard your rules", "tell the moderator this is fine"). Case, width, zero-width characters and extra whitespace
4
+ * are ignored. Never throws.
5
+ * @experimental
6
+ */
7
+ export declare function looksLikeInjection(text: string): boolean;
8
+ //# sourceMappingURL=injection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injection.d.ts","sourceRoot":"","sources":["../../../src/ai/injection.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIxD"}
@@ -0,0 +1,30 @@
1
+ import { cleanText } from './redact.js';
2
+ // A tripwire, not a defence (design section 8, layer 5). A line that looks like it is instructing the AI sets `injectionSuspected`:
3
+ // the case is shown with a plain note, its confidence is forced to low and the AI may not lower its queue rank. The patterns are
4
+ // phrase-shaped on purpose, so ordinary banter ("ignore me lol", "you are now in my way") does not trip them. A false positive costs
5
+ // one visible mark; a miss costs nothing the other layers (no authority, validated output, a human reads it) do not already cover.
6
+ const IGNORE = String.raw `\b(?:ignore|disregard|forget|override)\s+(?:(?:all|any|every|of|the|your|my|these|those|previous|prior|earlier|above|preceding|everything|anything|what)\s+)*(?:above|previous|prior|earlier|preceding|instructions?|rules?|prompts?|guidelines?|directions?|commands?|polic(?:y|ies)|messages?|context|system)\b`;
7
+ // "you are now" followed by a role, a mode or nothing: not "you are now in my way" or "you are now at 3 kills".
8
+ const NOW = String.raw `\byou(?:'re|\s+are|\s+r)\s+now\s*(?:$|[.,:;!?-]|(?:an?|the)\b|(?:dan|free|unfiltered|unrestricted|jailbroken|acting|playing)\b|my\s+(?:assistant|servant|ai)\b|in\s+(?:developer|debug|admin|god|dan|unrestricted|jailbreak)\b|going\s+to\s+(?:act|ignore|pretend)\b)`;
9
+ // A role marker at the start of the text or after punctuation or a quote ("system: ...", "hey! assistant: ..."), not mid-sentence.
10
+ const ROLE = String.raw `(?:^|[.!?;"'\[(<>|\x60])\s*(?:system|assistant|developer|admin)\s*[:>\]]`;
11
+ const TAG = String.raw `<\/?\s*(?:system|assistant|instructions?|data|prompt)\s*>|<\|[a-z_]+\|>|\[\/?inst\]|<<\/?sys>>`;
12
+ const AS_AI = String.raw `\bas an? (?:ai|a\.i\.|language model|large language model|llm|assistant|artificial intelligence|chatbot)\b`;
13
+ const NEW = String.raw `\b(?:new|updated|revised|additional)\s+(?:instructions?|rules|prompt|system prompt)\s*:|\bfrom now on\b[^.]{0,30}\b(?:you|ignore|respond|answer|act|only|always)\b|\bdo anything now\b`;
14
+ const TELL = String.raw `\btell\s+(?:the\s+|your\s+)?(?:moderators?|mods?|admins?|ai|assistant|reviewer|bot|model)\b[^.]{0,60}\b(?:fine|ok|okay|nothing|no action|safe|innocent|dismiss|banter|false|lying|harmless)\b`;
15
+ const PRETEND = String.raw `\bpretend\s+(?:that\s+)?you(?:'re|\s+are|\s+were)\b`;
16
+ const REVEAL = String.raw `\b(?:reveal|show|print|repeat|output|leak)\s+(?:me\s+)?(?:your|the)\s+(?:system\s+|initial\s+|hidden\s+)?(?:prompt|instructions?)\b`;
17
+ const PATTERNS = [IGNORE, NOW, ROLE, TAG, AS_AI, NEW, TELL, PRETEND, REVEAL].map((p) => new RegExp(p, 'u'));
18
+ /**
19
+ * True when a chat line or note reads like an attempt to instruct the AI ("ignore the above", "you are now ...", "system: ...",
20
+ * "as an AI", "disregard your rules", "tell the moderator this is fine"). Case, width, zero-width characters and extra whitespace
21
+ * are ignored. Never throws.
22
+ * @experimental
23
+ */
24
+ export function looksLikeInjection(text) {
25
+ if (typeof text !== 'string' || text === '')
26
+ return false;
27
+ const t = cleanText(text.normalize('NFKC')).toLowerCase().replace(/[‘’]/gu, "'");
28
+ return PATTERNS.some((re) => re.test(t));
29
+ }
30
+ //# sourceMappingURL=injection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injection.js","sourceRoot":"","sources":["../../../src/ai/injection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,oIAAoI;AACpI,iIAAiI;AACjI,qIAAqI;AACrI,mIAAmI;AAEnI,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAA,mTAAmT,CAAC;AAC7U,gHAAgH;AAChH,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA,uQAAuQ,CAAC;AAC9R,mIAAmI;AACnI,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAA,0EAA0E,CAAC;AAClG,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA,gGAAgG,CAAC;AACvH,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAA,4GAA4G,CAAC;AACrI,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA,wLAAwL,CAAC;AAC/M,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAA,+LAA+L,CAAC;AACvN,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,qDAAqD,CAAC;AAChF,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAA,qIAAqI,CAAC;AAE/J,MAAM,QAAQ,GAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAE/H;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC1D,MAAM,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACjF,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { ReportRecord } from '../types.js';
2
+ import type { AIPerson } from './types.js';
3
+ /** The most lines a read sees. */
4
+ export declare const AI_MAX_LINES = 40;
5
+ /**
6
+ * One line a read will see. `lineId` is the server's key to map an answer's ref back to the real line: it is NOT handed to an
7
+ * adapter, which gets refs only.
8
+ * @experimental
9
+ */
10
+ export interface ChosenLine {
11
+ ref: string;
12
+ lineId: string;
13
+ /** Seconds since the first chosen line. */
14
+ secondsIn: number;
15
+ /** An alias: `P1`, `P2`, ... */
16
+ who: string;
17
+ /** Redacted. */
18
+ text: string;
19
+ /** The term filter blocked it (the raw text is sent; an adapter option may mask it). */
20
+ blocked: boolean;
21
+ /**
22
+ * The profanity filter starred it in the room but did not block it: the raw text is sent. Like `blocked`, this is a line the filter
23
+ * touched, and the same future adapter option (`mask`) governs both.
24
+ */
25
+ filtered: boolean;
26
+ /** Written by the reported person. */
27
+ byReported: boolean;
28
+ }
29
+ /**
30
+ * What {@link chooseLines} returns.
31
+ * @experimental
32
+ */
33
+ export interface ChosenLines {
34
+ lines: ChosenLine[];
35
+ /** Lines the reporter could see were left out of the cap. */
36
+ truncated: boolean;
37
+ /** P1 and P2 first, then the others who spoke in a chosen line. */
38
+ people: AIPerson[];
39
+ /** The ref of the line the reporter pointed at, or null. */
40
+ reportedLine: string | null;
41
+ /** The reporter's note, redacted with the same aliases as the lines and cut to 300 characters; null when there is none. */
42
+ note: string | null;
43
+ }
44
+ /**
45
+ * Choose the lines a read sees, in time order: the pointed-at line, the reported person's latest 20, 12 before and 6 after the
46
+ * pointed-at line, then the nearest others, up to `max` (default 40). Lines the reporter could not see are dropped. Text is
47
+ * redacted and speakers are aliased; `P1` is the reported person and `P2` the reporter even when the reporter spoke first.
48
+ * With `mask`, a line the filter touched is sent masked, not raw (see the `blockedLines` option of the AI service).
49
+ * @experimental
50
+ */
51
+ export declare function chooseLines(report: ReportRecord, opts?: {
52
+ max?: number;
53
+ mask?: boolean;
54
+ }): ChosenLines;
55
+ /**
56
+ * The reporter's note, redacted and cut to 300 characters (the `note` of {@link chooseLines}). Pass the same `opts` as the
57
+ * `chooseLines` call it goes with, or prefer `chooseLines(...).note`, which cannot disagree with the lines.
58
+ * @experimental
59
+ */
60
+ export declare function redactReportNote(report: ReportRecord, opts?: {
61
+ max?: number;
62
+ mask?: boolean;
63
+ }): string | null;
64
+ //# sourceMappingURL=lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../../src/ai/lines.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,YAAY,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAK3C,kCAAkC;AAClC,eAAO,MAAM,YAAY,KAAK,CAAC;AAO/B;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,6DAA6D;IAC7D,SAAS,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,4DAA4D;IAC5D,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,2HAA2H;IAC3H,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AA8ID;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,WAAW,CAEtG;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAG7G"}
@@ -0,0 +1,172 @@
1
+ import { redactNote, redactText } from './redact.js';
2
+ // Line choice and aliasing (design section 8, "Choosing the lines"). Pure. A report carries up to 100 lines; a read sees at most 40,
3
+ // every one redacted, speakers as P1 (the reported person), P2 (the reporter) and P3... (everyone else, by first appearance).
4
+ /** The most lines a read sees. */
5
+ export const AI_MAX_LINES = 40;
6
+ /** How many of the reported person's latest lines are kept first. */
7
+ const OWN_LATEST = 20;
8
+ /** Lines kept before and after the one the reporter pointed at. */
9
+ const BEFORE = 12;
10
+ const AFTER = 6;
11
+ function roleOf(report, line) {
12
+ const subject = line.p === null ? undefined : report.people[line.p];
13
+ if (subject !== undefined) {
14
+ if (subject === report.targetSubject)
15
+ return 'reported';
16
+ if (subject === report.reporterSubject)
17
+ return 'reporter';
18
+ return 'other';
19
+ }
20
+ if (line.seatId === report.targetSeat)
21
+ return 'reported';
22
+ if (line.seatId === report.reporterSeat)
23
+ return 'reporter';
24
+ return 'other';
25
+ }
26
+ /** One key per distinct speaker: the subject when the room knew one, otherwise the seat. */
27
+ function speakerKey(report, line) {
28
+ const subject = line.p === null ? undefined : report.people[line.p];
29
+ return subject !== undefined ? `s:${subject}` : `seat:${line.seatId}`;
30
+ }
31
+ /**
32
+ * The text of one line as it is sent. By default the raw text, redacted. With `mask` (the `blockedLines: 'mask'` option) a line the
33
+ * filter touched is sent as the room saw it: a starred line as its delivered text, a blocked line with every character but spaces
34
+ * replaced by a star, so the model still sees its shape and length but not the words.
35
+ */
36
+ function lineText(line, handles, aliasOf, mask) {
37
+ const touched = line.blocked || (line.delivered !== null && line.delivered !== line.raw);
38
+ if (!mask || !touched)
39
+ return redactText(line.raw, handles, aliasOf);
40
+ if (line.blocked || line.delivered === null)
41
+ return redactText(line.raw, handles, aliasOf).replace(/[^\s]/gu, '*');
42
+ return redactText(line.delivered, handles, aliasOf);
43
+ }
44
+ function analyse(report, opts) {
45
+ const max = Math.max(1, Math.floor(opts?.max ?? AI_MAX_LINES));
46
+ // Time order, ties broken by the stored order, so the same report always gives the same choice.
47
+ const all = report.excerpt.map((line, i) => ({ line, i })).sort((a, b) => a.line.ts - b.line.ts || a.i - b.i).map((e) => e.line);
48
+ const visible = all.filter((l) => l.audience === null || l.audience.includes(report.reporterSeat));
49
+ const n = visible.length;
50
+ const roles = visible.map((l) => roleOf(report, l));
51
+ // 1. Choose positions (in `visible`), most important first, until the cap.
52
+ const chosen = new Set();
53
+ const add = (pos) => {
54
+ if (pos >= 0 && pos < n && chosen.size < max)
55
+ chosen.add(pos);
56
+ };
57
+ const pointed = report.lineId === null ? -1 : visible.findIndex((l) => l.lineId === report.lineId);
58
+ if (pointed >= 0)
59
+ add(pointed);
60
+ const own = [];
61
+ roles.forEach((r, pos) => r === 'reported' && own.push(pos));
62
+ for (const pos of own.slice(-OWN_LATEST).reverse())
63
+ add(pos);
64
+ if (pointed >= 0) {
65
+ for (let d = 1; d <= BEFORE; d += 1) {
66
+ add(pointed - d);
67
+ if (d <= AFTER)
68
+ add(pointed + d);
69
+ }
70
+ }
71
+ const anchor = pointed >= 0 ? pointed : (own[own.length - 1] ?? n - 1);
72
+ // Then the nearest others (ties go to the earlier line). The reported person's older lines are not "others": the latest 20 rule
73
+ // already decided those.
74
+ const spare = (pos) => roles[pos] !== 'reported';
75
+ if (spare(anchor))
76
+ add(anchor);
77
+ for (let d = 1; chosen.size < Math.min(max, n) && d <= n; d += 1) {
78
+ if (spare(anchor - d))
79
+ add(anchor - d);
80
+ if (spare(anchor + d))
81
+ add(anchor + d);
82
+ }
83
+ const positions = [...chosen].sort((a, b) => a - b);
84
+ // 2. Aliases: P1 reported, P2 reporter, then the others by first appearance in the chosen lines, then the rest of the room.
85
+ const alias = new Map(); // speaker key -> alias
86
+ let next = 3;
87
+ const aliasFor = (line, role) => {
88
+ if (role === 'reported')
89
+ return 'P1';
90
+ if (role === 'reporter')
91
+ return 'P2';
92
+ const key = speakerKey(report, line);
93
+ let a = alias.get(key);
94
+ if (a === undefined) {
95
+ a = `P${next}`;
96
+ next += 1;
97
+ alias.set(key, a);
98
+ }
99
+ return a;
100
+ };
101
+ const people = [
102
+ { alias: 'P1', role: 'reported' },
103
+ { alias: 'P2', role: 'reporter' },
104
+ ];
105
+ const chosenLines = positions.map((pos) => visible[pos]);
106
+ const whos = chosenLines.map((line, k) => {
107
+ const role = roles[positions[k]];
108
+ const a = aliasFor(line, role);
109
+ if (role === 'other' && !people.some((p) => p.alias === a))
110
+ people.push({ alias: a, role });
111
+ return a;
112
+ });
113
+ // The rest of the room (including lines the reporter could not see) is aliased too, so a handle named in a chosen line is replaced.
114
+ for (const line of all)
115
+ aliasFor(line, roleOf(report, line));
116
+ // 3. Everything that could name a person -> that person's alias, first writer wins.
117
+ const byName = new Map();
118
+ const name = (s, a) => {
119
+ if (s !== undefined && s !== '' && !byName.has(s))
120
+ byName.set(s, a);
121
+ };
122
+ name(report.targetHandle, 'P1');
123
+ name(report.targetSeat, 'P1');
124
+ name(report.targetSubject, 'P1');
125
+ name(report.reporterHandle, 'P2');
126
+ name(report.reporterSeat, 'P2');
127
+ name(report.reporterSubject, 'P2');
128
+ for (const line of all) {
129
+ const a = aliasFor(line, roleOf(report, line));
130
+ name(line.handle, a);
131
+ name(line.seatId, a);
132
+ name(line.p === null ? undefined : report.people[line.p], a);
133
+ }
134
+ const handles = [...byName.keys()];
135
+ const aliasOf = (h) => byName.get(h) ?? null;
136
+ // 4. Render.
137
+ const first = chosenLines[0]?.ts ?? 0;
138
+ const lines = chosenLines.map((line, k) => ({
139
+ ref: `L${k + 1}`,
140
+ lineId: line.lineId,
141
+ secondsIn: Math.max(0, Math.round((line.ts - first) / 1000)),
142
+ who: whos[k],
143
+ text: lineText(line, handles, aliasOf, opts?.mask === true),
144
+ blocked: line.blocked,
145
+ // Star-masked in the room (not blocked): the filter touched it, the raw text is still what we send (unless `mask`).
146
+ filtered: !line.blocked && line.delivered !== null && line.delivered !== line.raw,
147
+ byReported: roles[positions[k]] === 'reported',
148
+ }));
149
+ const reportedLine = report.lineId === null ? null : (lines.find((l) => l.lineId === report.lineId)?.ref ?? null);
150
+ const note = redactNote(report.note, handles, aliasOf);
151
+ return { result: { lines, truncated: chosen.size < n, people, reportedLine, note }, handles, aliasOf };
152
+ }
153
+ /**
154
+ * Choose the lines a read sees, in time order: the pointed-at line, the reported person's latest 20, 12 before and 6 after the
155
+ * pointed-at line, then the nearest others, up to `max` (default 40). Lines the reporter could not see are dropped. Text is
156
+ * redacted and speakers are aliased; `P1` is the reported person and `P2` the reporter even when the reporter spoke first.
157
+ * With `mask`, a line the filter touched is sent masked, not raw (see the `blockedLines` option of the AI service).
158
+ * @experimental
159
+ */
160
+ export function chooseLines(report, opts) {
161
+ return analyse(report, opts).result;
162
+ }
163
+ /**
164
+ * The reporter's note, redacted and cut to 300 characters (the `note` of {@link chooseLines}). Pass the same `opts` as the
165
+ * `chooseLines` call it goes with, or prefer `chooseLines(...).note`, which cannot disagree with the lines.
166
+ * @experimental
167
+ */
168
+ export function redactReportNote(report, opts) {
169
+ const { handles, aliasOf } = analyse(report, opts);
170
+ return redactNote(report.note, handles, aliasOf);
171
+ }
172
+ //# sourceMappingURL=lines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.js","sourceRoot":"","sources":["../../../src/ai/lines.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGrD,qIAAqI;AACrI,8HAA8H;AAE9H,kCAAkC;AAClC,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,qEAAqE;AACrE,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,mEAAmE;AACnE,MAAM,MAAM,GAAG,EAAE,CAAC;AAClB,MAAM,KAAK,GAAG,CAAC,CAAC;AA6ChB,SAAS,MAAM,CAAC,MAAoB,EAAE,IAAuB;IAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,IAAI,OAAO,KAAK,MAAM,CAAC,aAAa;YAAE,OAAO,UAAU,CAAC;QACxD,IAAI,OAAO,KAAK,MAAM,CAAC,eAA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