@genesislcap/ai-assistant 15.37.0 → 15.38.0

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 (73) hide show
  1. package/dist/custom-elements.json +638 -0
  2. package/dist/dts/genesis/calendar.d.ts +25 -0
  3. package/dist/dts/genesis/calendar.d.ts.map +1 -0
  4. package/dist/dts/genesis/config.d.ts +16 -0
  5. package/dist/dts/genesis/config.d.ts.map +1 -1
  6. package/dist/dts/genesis/criteria.d.ts +24 -2
  7. package/dist/dts/genesis/criteria.d.ts.map +1 -1
  8. package/dist/dts/genesis/event-fields.d.ts +84 -0
  9. package/dist/dts/genesis/event-fields.d.ts.map +1 -0
  10. package/dist/dts/genesis/filter-fields.d.ts +69 -5
  11. package/dist/dts/genesis/filter-fields.d.ts.map +1 -1
  12. package/dist/dts/genesis/index.d.ts +3 -0
  13. package/dist/dts/genesis/index.d.ts.map +1 -1
  14. package/dist/dts/genesis/register-genesis-assistant.d.ts +13 -0
  15. package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
  16. package/dist/dts/genesis/resource-tools.d.ts.map +1 -1
  17. package/dist/dts/genesis/review-model.d.ts +202 -0
  18. package/dist/dts/genesis/review-model.d.ts.map +1 -0
  19. package/dist/dts/genesis/row-source.d.ts +102 -0
  20. package/dist/dts/genesis/row-source.d.ts.map +1 -0
  21. package/dist/dts/genesis/serialisable.d.ts +25 -0
  22. package/dist/dts/genesis/serialisable.d.ts.map +1 -0
  23. package/dist/dts/genesis/server-text.d.ts +63 -0
  24. package/dist/dts/genesis/server-text.d.ts.map +1 -0
  25. package/dist/dts/genesis/type-name.d.ts +18 -0
  26. package/dist/dts/genesis/type-name.d.ts.map +1 -0
  27. package/dist/dts/genesis/types.d.ts +7 -0
  28. package/dist/dts/genesis/types.d.ts.map +1 -1
  29. package/dist/dts/genesis/value-compare.d.ts +19 -0
  30. package/dist/dts/genesis/value-compare.d.ts.map +1 -0
  31. package/dist/dts/genesis/write-commit.d.ts +53 -0
  32. package/dist/dts/genesis/write-commit.d.ts.map +1 -0
  33. package/dist/dts/genesis/write-outcome.d.ts +133 -0
  34. package/dist/dts/genesis/write-outcome.d.ts.map +1 -0
  35. package/dist/dts/genesis/write-payload.d.ts +129 -0
  36. package/dist/dts/genesis/write-payload.d.ts.map +1 -0
  37. package/dist/dts/genesis/write-plan.d.ts +109 -0
  38. package/dist/dts/genesis/write-plan.d.ts.map +1 -0
  39. package/dist/dts/genesis/write-review/write-review.d.ts +127 -0
  40. package/dist/dts/genesis/write-review/write-review.d.ts.map +1 -0
  41. package/dist/dts/genesis/write-review/write-review.styles.d.ts +2 -0
  42. package/dist/dts/genesis/write-review/write-review.styles.d.ts.map +1 -0
  43. package/dist/dts/genesis/write-review/write-review.template.d.ts +4 -0
  44. package/dist/dts/genesis/write-review/write-review.template.d.ts.map +1 -0
  45. package/dist/dts/genesis/write-tools.d.ts +99 -0
  46. package/dist/dts/genesis/write-tools.d.ts.map +1 -0
  47. package/dist/dts/react.d.ts +10 -0
  48. package/dist/esm/genesis/calendar.js +38 -0
  49. package/dist/esm/genesis/config.js +36 -1
  50. package/dist/esm/genesis/criteria.js +59 -55
  51. package/dist/esm/genesis/event-fields.js +158 -0
  52. package/dist/esm/genesis/filter-fields.js +111 -20
  53. package/dist/esm/genesis/index.js +2 -0
  54. package/dist/esm/genesis/register-genesis-assistant.js +76 -4
  55. package/dist/esm/genesis/resource-tools.js +21 -103
  56. package/dist/esm/genesis/review-model.js +248 -0
  57. package/dist/esm/genesis/row-source.js +127 -0
  58. package/dist/esm/genesis/serialisable.js +38 -0
  59. package/dist/esm/genesis/server-text.js +186 -0
  60. package/dist/esm/genesis/type-name.js +20 -0
  61. package/dist/esm/genesis/value-compare.js +87 -0
  62. package/dist/esm/genesis/write-commit.js +78 -0
  63. package/dist/esm/genesis/write-outcome.js +299 -0
  64. package/dist/esm/genesis/write-payload.js +632 -0
  65. package/dist/esm/genesis/write-plan.js +275 -0
  66. package/dist/esm/genesis/write-review/write-review.js +252 -0
  67. package/dist/esm/genesis/write-review/write-review.styles.js +214 -0
  68. package/dist/esm/genesis/write-review/write-review.template.js +182 -0
  69. package/dist/esm/genesis/write-tools.js +660 -0
  70. package/dist/react.cjs +7 -0
  71. package/dist/react.mjs +6 -0
  72. package/docs/genesis.md +152 -10
  73. package/package.json +18 -18
@@ -0,0 +1,109 @@
1
+ import type { GenesisEventField } from './event-fields';
2
+ import type { GenesisRowSource } from './row-source';
3
+ import type { GenesisEventOp } from './types';
4
+ /**
5
+ * The two data phases either side of the review: what the user is asked to approve, and whether
6
+ * it is still true when they do.
7
+ *
8
+ * @remarks
9
+ * Kept out of the tool handler so both can be tested as data — a fake row source and a list of
10
+ * rows — rather than through an interaction, a driver and a socket. The handler's job is to run
11
+ * these in order and report what came back.
12
+ */
13
+ /** One row on its way to the review: either something that can be written, or why it cannot. */
14
+ export interface PlannedRow {
15
+ /** Position in the model's own list, carried through the review and into the outcome. */
16
+ index: number;
17
+ /**
18
+ * What found this row, and what will find it again at approve time. The SAME key both times:
19
+ * a re-read by anything else would be re-reading a different question.
20
+ */
21
+ key?: Record<string, unknown>;
22
+ /** The payload, frozen, when the row can be written. */
23
+ details?: Record<string, unknown>;
24
+ /** The row as it stood when the review was built — what the user was shown as "now". */
25
+ preImage?: Record<string, unknown>;
26
+ /** Why this row cannot be written. Shown in the review; never selectable. */
27
+ problems?: string[];
28
+ /**
29
+ * What the row's outcome must also say about a row that CAN be written: a blank the model sent
30
+ * that was kept as the row's value, rather than clearing the column it may have meant to.
31
+ */
32
+ notes?: string[];
33
+ }
34
+ /** @internal */
35
+ export interface PlanOptions {
36
+ op: GenesisEventOp;
37
+ fields: readonly GenesisEventField[];
38
+ /** Required for a modify or a delete; an insert has no row to read. */
39
+ source?: GenesisRowSource;
40
+ }
41
+ /**
42
+ * A batch a person can actually read before approving it.
43
+ *
44
+ * @remarks
45
+ * A cap rather than a truncation: writing the first 25 of 400 rows and reporting it as done is
46
+ * the kind of partial success nobody asked for. The model is told to send fewer, and each batch
47
+ * gets its own approval.
48
+ */
49
+ export declare const MAX_WRITE_ROWS = 25;
50
+ /**
51
+ * Builds what the review will show, reading the current row for every modify and delete.
52
+ *
53
+ * @remarks
54
+ * Reads run together — they are reads, and a batch of 25 sequential round trips is a visibly
55
+ * slow assistant — while the writes that follow are strictly sequential (see `commitRows`).
56
+ *
57
+ * @internal
58
+ */
59
+ export declare function planWrite(rows: unknown, { op, fields, source }: PlanOptions): Promise<{
60
+ status: 'ok';
61
+ rows: PlannedRow[];
62
+ } | {
63
+ status: 'rejected';
64
+ reason: string;
65
+ }>;
66
+ /**
67
+ * Whether a row still looks the way the review showed it.
68
+ *
69
+ * @internal
70
+ */
71
+ export type RowStillCurrent = {
72
+ status: 'current';
73
+ }
74
+ /** Somebody else changed it while the review was open. Never written; the user saw the old one. */
75
+ | {
76
+ status: 'changed';
77
+ fields: string[];
78
+ } | {
79
+ status: 'gone';
80
+ }
81
+ /** The re-read itself failed, so whether it is current is unknown — which is not "current". */
82
+ | {
83
+ status: 'unreadable';
84
+ reason: string;
85
+ };
86
+ /**
87
+ * Re-reads one row and compares it with what the review showed.
88
+ *
89
+ * @remarks
90
+ * A review is open for as long as it takes a person to read it, and the same row can be changed
91
+ * by somebody else in that time. Committing the payload built from the row as it WAS would write
92
+ * the reviewed values straight over their change, and the ACK would say it worked.
93
+ *
94
+ * Compared over the event's own fields, because those are exactly the ones the write can affect.
95
+ * That deliberately includes a field that was empty and now is not: a generated modify replaces
96
+ * the record, so a field the pre-image had no value for is written as null, and "someone filled
97
+ * it in while you were reading" is precisely the change that would be undone.
98
+ *
99
+ * Both sides go through {@link sameValue}, which normalises each with the field's declared type
100
+ * — never one raw against one normalised. A read stamps a big integer as text where the payload
101
+ * holds a number, so a raw comparison would call every row changed and drop the whole batch.
102
+ *
103
+ * @internal
104
+ */
105
+ export declare function stillCurrent(row: PlannedRow, { source, fields }: {
106
+ source: GenesisRowSource;
107
+ fields: readonly GenesisEventField[];
108
+ }): Promise<RowStillCurrent>;
109
+ //# sourceMappingURL=write-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-plan.d.ts","sourceRoot":"","sources":["../../../src/genesis/write-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAS9C;;;;;;;;GAQG;AAEH,gGAAgG;AAChG,MAAM,WAAW,UAAU;IACzB,yFAAyF;IACzF,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,gBAAgB;AAChB,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,cAAc,CAAC;IACnB,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACrC,uEAAuE;IACvE,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AAWjC;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,GAClC,OAAO,CAAC;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,UAAU,EAAE,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAoNxF;AAsBD;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE;AACvB,mGAAmG;GACjG;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GACvC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;AACpB,+FAA+F;GAC7F;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,UAAU,EACf,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,GACrF,OAAO,CAAC,eAAe,CAAC,CAmB1B"}
@@ -0,0 +1,127 @@
1
+ import { GenesisElement } from '@genesislcap/web-core';
2
+ import type { AiChatInteraction } from '../../types/ai-chat-widget';
3
+ import { type ReviewModel } from '../review-model';
4
+ /**
5
+ * The tag the bridge asks for by name when it requests the review interaction.
6
+ *
7
+ * @beta
8
+ */
9
+ export declare const GENESIS_WRITE_REVIEW = "genesis-write-review";
10
+ /**
11
+ * The review a user reads before anything is written.
12
+ *
13
+ * @remarks
14
+ * Deliberately thin: it renders {@link ReviewModel} and reports which rows were selected. Every
15
+ * rule it obeys — nothing selected at first, no Write on an empty selection, a refused row that
16
+ * cannot be chosen, which fields are marked as changed — lives in the model, where it is tested
17
+ * without a DOM and cannot be undone by a change to the markup.
18
+ *
19
+ * **It resolves with row INDEXES, never rows.** The payloads stay with the tool that built
20
+ * them, so what gets committed is the object the user saw by construction rather than by
21
+ * discipline: nothing this component returns could be a rebuilt or cloned row, because it
22
+ * returns no rows at all.
23
+ *
24
+ * @beta
25
+ */
26
+ export declare class GenesisWriteReview extends GenesisElement {
27
+ /** Set by the interaction wrapper on every (re)mount. */
28
+ interactionId: string;
29
+ /** The host-set descriptor: the model to render while pending, the outcome once resolved. */
30
+ interaction: AiChatInteraction<ReviewModel, number[]>;
31
+ /** Chosen rows, by index. Starts empty — see {@link canWrite} and the model's own reasoning. */
32
+ selected: number[];
33
+ /** True while the user is writing a reason for denying. */
34
+ denying: boolean;
35
+ denyReason: string;
36
+ /**
37
+ * The rows, whether the review is still open or already resolved: a user who has approved a
38
+ * write should still be able to see what they approved. Acting on it is what `resolved`
39
+ * stops, not reading it.
40
+ */
41
+ get model(): ReviewModel | undefined;
42
+ get resolved(): boolean;
43
+ /**
44
+ * The rows the user approved, once the review has resolved — empty for a rejection or a
45
+ * timeout, and while it is still open.
46
+ */
47
+ get approved(): number[];
48
+ /**
49
+ * What a CLOSED review can truthfully say about its outcome.
50
+ *
51
+ * @remarks
52
+ * A review knows what was approved; only the tool's reply knows what was WRITTEN. A delete the
53
+ * user approved can still be refused at commit — the row changed while the review was open — and
54
+ * a review that went on showing its removal tint read as though it happened, on every re-mount.
55
+ * So it says what it knows and where the rest is, in words a screen reader and a greyscale
56
+ * screen carry as well as the tints do.
57
+ */
58
+ get closedSummary(): string;
59
+ /**
60
+ * Every mount is a fresh element whose selection starts empty, so each state says where its
61
+ * selection comes from.
62
+ *
63
+ * @remarks
64
+ * A RESOLVED review shows what was approved, whether it resolved just now or is re-mounted from
65
+ * history — its boxes used to show unticked under the tints of rows that WERE approved. Seeded
66
+ * from the result, the one thing both paths have, and never from the context: the host disposes
67
+ * that on resolve, and a disposed context's state still holds whatever was last parked there.
68
+ *
69
+ * A PENDING review resumes from its interaction context what the user had ticked, and a deny
70
+ * they had started: a reparent, a dock or a transcript re-render rebuilds the element while
71
+ * the review is open, and everything it held was dropped. Assigned once, not replayed through
72
+ * the setters, and never written back from here — only a user's action parks (see `park`).
73
+ * Each restored box goes from unticked to ticked once when it binds and echoes once, into a
74
+ * setter that already agrees.
75
+ */
76
+ interactionChanged(): void;
77
+ /**
78
+ * Keeps what the user has done so far on the interaction's context, where the next mount of a
79
+ * still-open review finds it.
80
+ *
81
+ * @remarks
82
+ * Called from the user-driven mutators only. Writing from `selectedChanged` or
83
+ * `interactionChanged` would let the field initializer's empty selection, or a resolved
84
+ * re-seed, overwrite what was parked. The context is read from `interaction` every time and
85
+ * never cached: once the review resolves there is none, and a kept reference to a disposed one
86
+ * would go on accepting writes nobody reads.
87
+ */
88
+ private park;
89
+ get rowsSelected(): number;
90
+ /** Whether Write may fire: never on an empty selection. */
91
+ get writable(): boolean;
92
+ get allSelected(): boolean;
93
+ isSelected(index: number): boolean;
94
+ /**
95
+ * Makes one row agree with what its checkbox now says. A row the bridge refused cannot be
96
+ * chosen, whatever the markup does.
97
+ *
98
+ * @remarks
99
+ * SET from the checkbox, never toggled, and a no-op when the row already agrees. The checkbox
100
+ * emits `change` for a PROGRAMMATIC update too (FAST's `checkedChanged`), so every time the
101
+ * selection moves a box through its `:checked` binding, that box echoes. A handler that
102
+ * toggled turned each echo into another change of selection, which moved another box, which
103
+ * echoed — and FAST drains updates queued during a flush in the same flush, so the loop never
104
+ * yielded the main thread and the whole application froze. An echo now finds the row already
105
+ * agreeing and does nothing, so the first echo is the last.
106
+ */
107
+ setSelected(index: number, checked: boolean): void;
108
+ /**
109
+ * One click for a good batch — a deliberate one, which is the point of starting empty.
110
+ *
111
+ * @remarks
112
+ * Compared with {@link allSelected}, the value the select-all box DISPLAYS, and not with the
113
+ * selection. The difference is the case that matters: unticking one row of a full selection
114
+ * makes `allSelected` false, the select-all box follows it, and it echoes `change` with
115
+ * `false`. Measured against the selection, that echo reads as "clear everything" and takes
116
+ * every other row with it. Measured against what the box displays, it agrees and does nothing.
117
+ */
118
+ setAll(checked: boolean): void;
119
+ write(): void;
120
+ /** The one way this widget talks back: `interaction-completed`, exactly once. */
121
+ private resolve;
122
+ startDeny(): void;
123
+ /** The deny reason as the user types it. */
124
+ setDenyReason(reason: string): void;
125
+ confirmDeny(): void;
126
+ }
127
+ //# sourceMappingURL=write-review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-review.d.ts","sourceRoot":"","sources":["../../../../src/genesis/write-review/write-review.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,cAAc,EAAc,MAAM,uBAAuB,CAAC;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAiD,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAIlG;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAS3D;;;;;;;;;;;;;;;GAeG;AACH,qBACa,kBAAmB,SAAQ,cAAc;IACpD,yDAAyD;IACzD,aAAa,SAAM;IAEnB,6FAA6F;IACjF,WAAW,EAAG,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;IAEnE,gGAAgG;IACpF,QAAQ,EAAE,MAAM,EAAE,CAAsB;IAEpD,2DAA2D;IAC/C,OAAO,UAAS;IAChB,UAAU,SAAM;IAE5B;;;;OAIG;IACH,IAAI,KAAK,IAAI,WAAW,GAAG,SAAS,CAEnC;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,EAAE,CAUvB;IAED;;;;;;;;;OASG;IACH,IAAI,aAAa,IAAI,MAAM,CAU1B;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,kBAAkB,IAAI,IAAI;IAc1B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,IAAI;IASZ,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,2DAA2D;IAC3D,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,WAAW,IAAI,OAAO,CAGzB;IAED,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlC;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IASlD;;;;;;;;;OASG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAM9B,KAAK,IAAI,IAAI;IASb,iFAAiF;IACjF,OAAO,CAAC,OAAO;IAIf,SAAS,IAAI,IAAI;IAKjB,4CAA4C;IAC5C,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKnC,WAAW,IAAI,IAAI;CAOpB"}
@@ -0,0 +1,2 @@
1
+ export declare const WriteReviewStyles: import("@microsoft/fast-element").ElementStyles;
2
+ //# sourceMappingURL=write-review.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-review.styles.d.ts","sourceRoot":"","sources":["../../../../src/genesis/write-review/write-review.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,iDAoN7B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ViewTemplate } from '@genesislcap/web-core';
2
+ import type { GenesisWriteReview } from './write-review';
3
+ export declare const WriteReviewTemplate: ViewTemplate<GenesisWriteReview>;
4
+ //# sourceMappingURL=write-review.template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-review.template.d.ts","sourceRoot":"","sources":["../../../../src/genesis/write-review/write-review.template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAQ,MAAM,uBAAuB,CAAC;AAGzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAwJzD,eAAO,MAAM,mBAAmB,EAAE,YAAY,CAAC,kBAAkB,CAwEhE,CAAC"}
@@ -0,0 +1,99 @@
1
+ import type { ChatToolDefinition, ChatToolHandlers } from '@genesislcap/foundation-ai';
2
+ import { type Connect } from '@genesislcap/foundation-comms';
3
+ import { GENESIS_DATA_SOURCE } from './resource-tools';
4
+ import type { GenesisAiResource } from './types';
5
+ import type { GenesisWriteStatus } from './write-outcome';
6
+ /**
7
+ * The write tools: build a payload, show it to the user, and commit only what they selected.
8
+ *
9
+ * @remarks
10
+ * The shape of this handler is the whole safety argument, so it is worth stating in order:
11
+ *
12
+ * 1. the model's arguments become payloads, each built against the event's own metadata and, for
13
+ * a modify or a delete, merged over the row as it currently stands;
14
+ * 2. those payload objects are rendered in the review, by reference;
15
+ * 3. the user selects rows, and the review resolves with their INDEXES — never rows, so nothing
16
+ * that comes back could be a rebuilt or cloned payload;
17
+ * 4. each selected modify or delete is re-read and compared with what the review showed;
18
+ * 5. what survives is committed, and the objects committed are the objects from step 2.
19
+ *
20
+ * At no point is a payload re-derived from the model's original arguments. That is the gap the
21
+ * review exists to close: a payload rebuilt after approval is a payload nobody approved, and it
22
+ * would look identical in every log.
23
+ */
24
+ /** What one row of a write ended up as, from the model's point of view. */
25
+ export type GenesisWriteRowStatus = GenesisWriteStatus
26
+ /** The user did not select it. Nothing was sent. */
27
+ | 'not_selected'
28
+ /** It changed between the review and the approval, so it was left alone. */
29
+ | 'changed_since_review';
30
+ /**
31
+ * What a write tool returns to the model.
32
+ *
33
+ * @beta
34
+ */
35
+ export interface GenesisWriteResult {
36
+ source: typeof GENESIS_DATA_SOURCE;
37
+ untrusted: true;
38
+ resource: string;
39
+ /** False when the user closed the review without approving anything. */
40
+ approved: boolean;
41
+ /** One line per row the model sent, in the order it sent them. */
42
+ rows: Array<{
43
+ index: number;
44
+ status: GenesisWriteRowStatus;
45
+ /**
46
+ * Whether the row is KNOWN to have reached the database. False on `unknown` does NOT mean
47
+ * nothing was written — read `status` before counting or offering to try again.
48
+ */
49
+ committed: boolean;
50
+ message: string;
51
+ /** Keys the server generated, e.g. `[{ TRADE_ID: '000000000000001TRLO1' }]`. */
52
+ generated?: Array<Record<string, unknown>>;
53
+ /**
54
+ * Per-field reasons, when the reply named fields. Carried because the model needs to know
55
+ * WHICH field it got wrong to fix it — without this the mapper was sanitising a field name
56
+ * nothing ever received.
57
+ */
58
+ fields?: Array<{
59
+ field?: string;
60
+ text: string;
61
+ }>;
62
+ /** Server warnings. Shown, never suppressed. */
63
+ warnings?: string[];
64
+ }>;
65
+ summary: string;
66
+ }
67
+ /**
68
+ * Options for {@link createGenesisWriteTools}.
69
+ *
70
+ * @beta
71
+ */
72
+ export interface GenesisWriteToolsOptions {
73
+ /** The connection to write through. Defaults to the app's own, resolved from DI on first use. */
74
+ connect?: Connect;
75
+ /**
76
+ * Which request resource a modify or delete reads its rows from, by event name. Defaults to
77
+ * the `REQ_` resource for the same table (`EVENT_TRADE_MODIFY` reads `REQ_TRADE`) when the app
78
+ * exposes one; an event with no source gets no tool at all, because a modify that cannot read
79
+ * its row cannot be built (see `buildEventPayload`).
80
+ */
81
+ rowSources?: Record<string, string>;
82
+ /** @internal Tests shorten these; the defaults suit a real app. */
83
+ timeouts?: {
84
+ metadataMs?: number;
85
+ readMs?: number;
86
+ commitMs?: number;
87
+ reviewMs?: number;
88
+ };
89
+ }
90
+ /**
91
+ * Builds the assistant's write tools from an app's event resources.
92
+ *
93
+ * @beta
94
+ */
95
+ export declare function createGenesisWriteTools(resources: readonly GenesisAiResource[], options?: GenesisWriteToolsOptions): {
96
+ toolDefinitions: () => Promise<ChatToolDefinition[]>;
97
+ toolHandlers: ChatToolHandlers;
98
+ };
99
+ //# sourceMappingURL=write-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-tools.d.ts","sourceRoot":"","sources":["../../../src/genesis/write-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAKzE,OAAO,EAAE,mBAAmB,EAAyB,MAAM,kBAAkB,CAAC;AAI9E,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,SAAS,CAAC;AAEjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAgB1D;;;;;;;;;;;;;;;;;GAiBG;AAEH,2EAA2E;AAC3E,MAAM,MAAM,qBAAqB,GAC7B,kBAAkB;AACpB,oDAAoD;GAClD,cAAc;AAChB,4EAA4E;GAC1E,sBAAsB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,mBAAmB,CAAC;IACnC,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,QAAQ,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,IAAI,EAAE,KAAK,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,qBAAqB,CAAC;QAC9B;;;WAGG;QACH,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,gFAAgF;QAChF,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAC3C;;;;WAIG;QACH,MAAM,CAAC,EAAE,KAAK,CAAC;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACjD,gDAAgD;QAChD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,iGAAiG;IACjG,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,mEAAmE;IACnE,QAAQ,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3F;AA4QD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,SAAS,iBAAiB,EAAE,EACvC,OAAO,GAAE,wBAA6B,GACrC;IAAE,eAAe,EAAE,MAAM,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,gBAAgB,CAAA;CAAE,CA+N1F"}
@@ -14,6 +14,7 @@ import type { AiHaloOverlay as AiHaloOverlayWC } from './components/halo-overlay
14
14
  import type { AiPlasmaOrbIndicator as AiPlasmaOrbIndicatorWC } from './components/plasma-orb-indicator';
15
15
  import type { FoundationAiPopoutManager as FoundationAiPopoutManagerWC } from './components/popout-manager/popout-manager';
16
16
  import type { AiWavesIndicator as AiWavesIndicatorWC } from './components/waves-indicator';
17
+ import type { GenesisWriteReview as GenesisWriteReviewWC } from './genesis/write-review/write-review';
17
18
  import type { FoundationAiAssistant as FoundationAiAssistantWC } from './main/main';
18
19
  import type { ChatSuggestions as ChatSuggestionsWC } from './suggestions/chat-suggestions';
19
20
  import type { ChatHeaderMouseDownDetail, InteractionCompletedEventDetail, InteractionCostEventDetail, SessionClearedDetail } from '@genesislcap/ai-assistant';
@@ -162,4 +163,13 @@ export declare const FoundationAiPopoutManager: React.ForwardRefExoticComponent<
162
163
  >;
163
164
  export type FoundationAiPopoutManagerRef = FoundationAiPopoutManagerWC;
164
165
 
166
+ export declare const GenesisWriteReview: React.ForwardRefExoticComponent<
167
+ React.PropsWithChildren<
168
+ Omit<PublicOf<GenesisWriteReviewWC>, 'children' | 'style'> &
169
+ HTMLWCProps & {
170
+ }
171
+ > & React.RefAttributes<GenesisWriteReviewWC>
172
+ >;
173
+ export type GenesisWriteReviewRef = GenesisWriteReviewWC;
174
+
165
175
  export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The epoch millis, UTC, of a date and time given as its parts — or `undefined` when the parts do
3
+ * not name an instant that exists.
4
+ *
5
+ * @remarks
6
+ * `Date.UTC` never refuses a part. It carries one that is out of range into the next unit, so
7
+ * `2026-13-01` is 2027-01-01, `2026-02-30` is 2026-03-02 and `T25:00` is one o'clock the next
8
+ * day — each a real instant, written and reported `written`, with only the user's eye on the
9
+ * review between a typo and a record moved by a month. Range limits per part are not enough
10
+ * either: a day of 31 is valid, just not in September. So the instant is built and then read
11
+ * back, and anything that does not come back as the parts it was built from is refused. That
12
+ * one comparison covers every out-of-range part and every day a month does not have, leap years
13
+ * included.
14
+ *
15
+ * It also refuses a year below 100, on purpose: `Date.UTC` reads those as 19xx, so `0026-01-01`
16
+ * would be 1926. No trade is dated in the year 26, so the likelier reading is a typo, and
17
+ * refusing it beats writing either century.
18
+ *
19
+ * The one rule for the read path's criteria bounds and the write path's payloads, so a value is a
20
+ * date on both or on neither.
21
+ *
22
+ * @internal
23
+ */
24
+ export function utcMillisOf(year, month, day, hour = '0', minute = '0', second = '0') {
25
+ const parts = [year, month, day, hour, minute, second].map(Number);
26
+ const [y, mo, d, h, mi, s] = parts;
27
+ const millis = Date.UTC(y, mo - 1, d, h, mi, s);
28
+ const at = new Date(millis);
29
+ const readBack = [
30
+ at.getUTCFullYear(),
31
+ at.getUTCMonth() + 1,
32
+ at.getUTCDate(),
33
+ at.getUTCHours(),
34
+ at.getUTCMinutes(),
35
+ at.getUTCSeconds(),
36
+ ];
37
+ return readBack.every((part, index) => part === parts[index]) ? millis : undefined;
38
+ }
@@ -1,5 +1,5 @@
1
1
  import { AI_TIER_IDS, AI_TIER_VENDORS } from '@genesislcap/foundation-ai';
2
- import { GENESIS_EVENT_OPS } from './types';
2
+ import { GENESIS_EVENT_OPS, } from './types';
3
3
  /** The default read cap, and the ceiling the config may raise it to. */
4
4
  export const DEFAULT_MAX_ROWS = 50;
5
5
  export const MAX_ROWS_CEILING = 1000;
@@ -12,6 +12,25 @@ const RESOURCE_NAME = /^(REQ|EVENT)_[A-Z0-9_]+$/;
12
12
  * reaches the model through its description, not its name.
13
13
  */
14
14
  export const toolNameOf = (resourceName) => resourceName.toLowerCase();
15
+ /**
16
+ * The op a resource's NAME declares, when it declares one.
17
+ *
18
+ * @remarks
19
+ * Exported so the config validator and the write-tool factory apply one rule. A validator only
20
+ * the registration path reaches is not a guarantee: `createGenesisWriteTools` is exported and
21
+ * documented, and a mis-declared op there takes the insert branch — no row read, no merge, no
22
+ * staleness check — and replaces the record with every unnamed column null.
23
+ *
24
+ * A name that claims no operation is the app's own business: `EVENT_TRADE_AMEND` may well be a
25
+ * modify, and there is nothing in the name to contradict.
26
+ *
27
+ * @internal
28
+ */
29
+ export const opFromName = (resourceName) => {
30
+ var _a;
31
+ const suffix = (_a = /_(INSERT|MODIFY|DELETE)$/.exec(resourceName)) === null || _a === void 0 ? void 0 : _a[1];
32
+ return suffix ? suffix.toLowerCase() : undefined;
33
+ };
15
34
  /**
16
35
  * Checks a generated AI config before anything is registered, returning every problem found.
17
36
  *
@@ -39,6 +58,16 @@ export function validateGenesisAiConfig(config) {
39
58
  if (c.systemPrompt !== undefined && typeof c.systemPrompt !== 'string') {
40
59
  problems.push('systemPrompt must be a string');
41
60
  }
61
+ // No resources — absent or an empty list — is accepted, and deliberately: this is NOT the
62
+ // "loosest default" shape the rest of the bridge refuses. An assistant with no generated tools
63
+ // is a real configuration — one whose tools all come from the app's own extensions, or a plain
64
+ // chat helper with none — and nothing it can do writes a record or reads one. Refusing it would
65
+ // be the bridge deciding for the app what an assistant is for. The rule is about defaults that
66
+ // pick which GUARANTEES apply; an empty list picks none, because there is nothing to guard.
67
+ //
68
+ // Accepted, but not silent: it looks exactly like a list that came out empty by mistake, so
69
+ // registration logs a warning naming both causes. What that case needs is a signal, not a
70
+ // block.
42
71
  if (c.resources === undefined)
43
72
  return problems;
44
73
  if (!Array.isArray(c.resources))
@@ -69,6 +98,12 @@ export function validateGenesisAiConfig(config) {
69
98
  if (!GENESIS_EVENT_OPS.includes(resource.op)) {
70
99
  problems.push(`${name}: op must be one of ${GENESIS_EVENT_OPS.join(', ')}`);
71
100
  }
101
+ // The same cross-check `kind` gets, for the same reason: a name and a declaration that
102
+ // disagree are a generator bug, and this one is not cosmetic — see opFromName.
103
+ const declared = opFromName(name);
104
+ if (declared && resource.op !== declared) {
105
+ problems.push(`${name}: op must be '${declared}' to match its name (got ${String(resource.op)})`);
106
+ }
72
107
  if (resource.maxRows !== undefined)
73
108
  problems.push(`${name}: maxRows applies to requests only`);
74
109
  }