briyah 2.0.18 → 2.0.20

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 (44) hide show
  1. package/dist-sdk/server/src/ai/agent-config.d.ts +2 -0
  2. package/dist-sdk/server/src/ai/agent-store.service.js +4 -0
  3. package/dist-sdk/server/src/ai/agent.d.ts +7 -0
  4. package/dist-sdk/server/src/ai/agent.js +7 -0
  5. package/dist-sdk/server/src/app.service.d.ts +2 -0
  6. package/dist-sdk/server/src/app.service.js +2 -0
  7. package/dist-sdk/server/src/data/change-validation.d.ts +49 -0
  8. package/dist-sdk/server/src/data/change-validation.js +246 -0
  9. package/dist-sdk/server/src/data/data-guide.builder.d.ts +13 -0
  10. package/dist-sdk/server/src/data/data-guide.builder.js +56 -0
  11. package/dist-sdk/server/src/data/data-registry.js +7 -0
  12. package/dist-sdk/server/src/data/data.types.d.ts +98 -0
  13. package/dist-sdk/server/src/data/data.types.js +3 -1
  14. package/dist-sdk/server/src/data/propose-changes.d.ts +19 -0
  15. package/dist-sdk/server/src/data/propose-changes.js +69 -0
  16. package/dist-sdk/server/src/data/query-validation.d.ts +9 -1
  17. package/dist-sdk/server/src/data/query-validation.js +9 -5
  18. package/dist-sdk/server/src/data/run-query.d.ts +14 -0
  19. package/dist-sdk/server/src/data/run-query.js +39 -0
  20. package/dist-sdk/server/src/documents/document-conversion.d.ts +27 -9
  21. package/dist-sdk/server/src/documents/document-conversion.js +131 -10
  22. package/dist-sdk/server/src/documents/html-data.d.ts +49 -0
  23. package/dist-sdk/server/src/documents/html-data.js +120 -0
  24. package/dist-sdk/server/src/documents/html-template.d.ts +108 -0
  25. package/dist-sdk/server/src/documents/html-template.js +332 -0
  26. package/dist-sdk/server/src/documents/library/document.types.d.ts +64 -0
  27. package/dist-sdk/server/src/documents/library/document.types.js +6 -0
  28. package/dist-sdk/server/src/documents/library/html-template-guide.builder.d.ts +13 -0
  29. package/dist-sdk/server/src/documents/library/html-template-guide.builder.js +185 -0
  30. package/dist-sdk/server/src/documents/template-mapping.d.ts +203 -0
  31. package/dist-sdk/server/src/documents/template-mapping.js +452 -0
  32. package/dist-sdk/server/src/room/room.d.ts +2 -1
  33. package/dist-sdk/server/src/room/room.js +7 -3
  34. package/dist-sdk/server/src/sdk/index.d.ts +17 -4
  35. package/dist-sdk/server/src/sdk/index.js +37 -2
  36. package/dist-sdk/server/src/tools/core/data-change.tools.d.ts +19 -0
  37. package/dist-sdk/server/src/tools/core/data-change.tools.js +82 -0
  38. package/dist-sdk/server/src/tools/core/data.tools.js +22 -3
  39. package/dist-sdk/server/src/tools/core/document.tools.d.ts +22 -0
  40. package/dist-sdk/server/src/tools/core/document.tools.js +20 -6
  41. package/dist-sdk/server/src/tools/core/html-template.tools.d.ts +31 -0
  42. package/dist-sdk/server/src/tools/core/html-template.tools.js +494 -0
  43. package/dist-sdk/server/src/tools/core/index.js +4 -0
  44. package/package.json +1 -1
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.proposeDataChangesTool = void 0;
4
+ exports.proposalFromArgs = proposalFromArgs;
5
+ const coerce_1 = require("../shared/coerce");
6
+ const data_registry_1 = require("../../data/data-registry");
7
+ const propose_changes_1 = require("../../data/propose-changes");
8
+ const data_types_1 = require("../../data/data.types");
9
+ const PROPOSAL_EXAMPLE = '{"title": "Add the policy prefix to 2 claim numbers", "changes": [' +
10
+ '{"op": "update", "dataset": "claims", "key": "6f1c…", "set": {"claimNumber": "CA-24-1187"}, "reason": "Loss run lists it as CA-24-1187"}, ' +
11
+ '{"op": "create", "dataset": "claims", "values": {"claimNumber": "CA-24-1201", "lossDate": "2024-03-02"}}, ' +
12
+ '{"op": "delete", "dataset": "claims", "key": "9a2e…"}], ' +
13
+ '"note": "Claim 24-1190 is in the report but not in the records; left alone."}';
14
+ /** The proposal, in either form a model sends it. */
15
+ function proposalFromArgs(args) {
16
+ const wrapped = args?.proposal;
17
+ if (wrapped !== undefined && wrapped !== null && wrapped !== '') {
18
+ return (0, coerce_1.jsonObject)(wrapped, 'proposal', PROPOSAL_EXAMPLE);
19
+ }
20
+ if (args?.changes !== undefined && args.changes !== null && args.changes !== '') {
21
+ const fields = {};
22
+ for (const [key, value] of Object.entries(args)) {
23
+ if (key !== 'proposal')
24
+ fields[key] = (0, coerce_1.parsedIfJson)(value);
25
+ }
26
+ return fields;
27
+ }
28
+ throw new coerce_1.ArgumentError('proposal', wrapped, 'a JSON object with a title and changes', PROPOSAL_EXAMPLE);
29
+ }
30
+ exports.proposeDataChangesTool = {
31
+ name: 'propose_data_changes',
32
+ description: 'Proposes changes to the application\'s data for a person to approve. Nothing is changed ' +
33
+ 'by this call: the person sees every change and applies or discards it afterwards, and you ' +
34
+ 'are told which. Each change updates fields of one row ("update", by its key), adds a row ' +
35
+ '("create") or removes one ("delete", by its key). Only datasets and fields your data guide ' +
36
+ 'marks editable can be changed, and a key must come from a query_data result — never guess ' +
37
+ 'one. Put everything one request needs in one proposal, at most ' + data_types_1.MAX_DATA_CHANGES +
38
+ ' changes. Example: ' + PROPOSAL_EXAMPLE +
39
+ ' Send it as `proposal`, or its fields (title, changes, note) as the arguments themselves.',
40
+ parameters: [
41
+ {
42
+ name: 'proposal',
43
+ type: 'string',
44
+ description: 'The proposal as a JSON object: {"title", "changes": [...], "note"?}. Example: ' + PROPOSAL_EXAMPLE +
45
+ ' May be left out when its fields are sent as the arguments instead.',
46
+ required: false,
47
+ },
48
+ ],
49
+ handler: async (args, _helpers, context) => {
50
+ if (!(0, data_registry_1.hasDataSources)()) {
51
+ return {
52
+ ok: false,
53
+ summary: 'No data can be changed',
54
+ error: 'This application has not made any data available.',
55
+ };
56
+ }
57
+ const result = await (0, propose_changes_1.proposeDataChanges)(proposalFromArgs(args), context);
58
+ if (!result.ok) {
59
+ return {
60
+ ok: false,
61
+ summary: 'Proposal refused',
62
+ error: result.error,
63
+ ...(result.available ? { available: result.available } : {}),
64
+ };
65
+ }
66
+ return {
67
+ ok: true,
68
+ summary: result.summary,
69
+ // The room log's line for this call. It carries the id in a fixed
70
+ // form, `[proposal <id>]`, so a host replaying its room log can put
71
+ // the proposal back where it was made.
72
+ detail: `${result.summary} [proposal ${result.proposalId}]`,
73
+ proposalId: result.proposalId,
74
+ changeCount: result.changes.changes.length,
75
+ status: 'waiting for approval',
76
+ note: 'Nothing has been changed yet. The person now sees these changes and applies or discards them; ' +
77
+ 'you will be told which. Do not say the data has changed until then.',
78
+ };
79
+ },
80
+ // A proposal of hundreds of changes is a large argument but a small result.
81
+ timeoutMs: 60_000,
82
+ };
@@ -5,6 +5,7 @@ exports.queryFromArgs = queryFromArgs;
5
5
  const coerce_1 = require("../shared/coerce");
6
6
  const data_registry_1 = require("../../data/data-registry");
7
7
  const query_validation_1 = require("../../data/query-validation");
8
+ const data_guide_builder_1 = require("../../data/data-guide.builder");
8
9
  /** Serialized characters a query result may occupy. Under the tool's own budget. */
9
10
  const RESULT_BUDGET = 20_000;
10
11
  const QUERY_EXAMPLE = '{"dataset": "claims", "filters": [{"field": "year", "op": "gte", "value": 2022}], ' +
@@ -42,7 +43,9 @@ exports.describeDataTool = {
42
43
  name: 'describe_data',
43
44
  description: 'Lists the datasets you can query, or the fields of one dataset. Your attached ' +
44
45
  'data guide already describes these — use this when you need to confirm a field ' +
45
- 'exists, or when the guide and a query result disagree.',
46
+ 'exists, when the guide and a query result disagree, or to list the fields of a set ' +
47
+ 'the guide does not list them for. Pass search to narrow a long field list to the ' +
48
+ 'fields whose name, label or description contains that text.',
46
49
  parameters: [
47
50
  {
48
51
  name: 'dataset',
@@ -50,6 +53,12 @@ exports.describeDataTool = {
50
53
  description: 'The dataset to describe. Omit to list every dataset.',
51
54
  required: false,
52
55
  },
56
+ {
57
+ name: 'search',
58
+ type: 'string',
59
+ description: 'With a dataset: only the fields whose name, label or description contains this text (any case).',
60
+ required: false,
61
+ },
53
62
  ],
54
63
  handler: async (args) => {
55
64
  if (!(0, data_registry_1.hasDataSources)()) {
@@ -83,16 +92,26 @@ exports.describeDataTool = {
83
92
  available: datasetNames(),
84
93
  };
85
94
  }
95
+ const search = args.search === undefined || args.search === null ? '' : String(args.search).trim().toLowerCase();
96
+ const fields = search
97
+ ? set.fields.filter((field) => [field.name, field.label, field.description].some((text) => (text || '').toLowerCase().includes(search)))
98
+ : set.fields;
86
99
  return {
87
100
  ok: true,
88
- summary: `Described the "${set.name}" dataset`,
101
+ summary: `Described the "${set.name}" dataset${search ? ` (${fields.length} field(s) matching "${search}")` : ''}`,
89
102
  dataset: set.name,
90
103
  label: set.label || set.name,
91
104
  description: set.description,
92
105
  notes: set.notes || [],
93
- fields: set.fields,
106
+ ...(set.key ? { key: set.key } : {}),
107
+ ...(set.edits ? { edits: set.edits } : {}),
108
+ // One line per field, as the data guide writes them: a set with
109
+ // hundreds of fields still fits, and reads the same as the guide.
110
+ fields: fields.map(data_guide_builder_1.describeField),
94
111
  };
95
112
  },
113
+ // A questionnaire's worth of field lines.
114
+ maxResultChars: 60_000,
96
115
  timeoutMs: 5_000,
97
116
  };
98
117
  exports.queryDataTool = {
@@ -18,6 +18,7 @@
18
18
  * host lists for this call's context — never passed through on trust.
19
19
  */
20
20
  import { NativeToolDefinition } from '../native-tool.types';
21
+ import { DocumentSource, DocumentSummary } from '../../documents/library/document.types';
21
22
  /**
22
23
  * The file name a held library document is attached under.
23
24
  *
@@ -30,6 +31,27 @@ export declare function libraryAttachmentName(documentId: string, name: string):
30
31
  export declare function isLibraryAttachment(fileName: string): boolean;
31
32
  /** The library document id an attachment holds, or undefined for any other attachment. */
32
33
  export declare function libraryDocumentIdOf(fileName: string): string | undefined;
34
+ export declare const unavailable: {
35
+ ok: boolean;
36
+ summary: string;
37
+ error: string;
38
+ };
39
+ /** Every document in scope, each paired with the source that owns it. */
40
+ export declare function inScope(context: unknown): Promise<{
41
+ source: DocumentSource;
42
+ document: DocumentSummary;
43
+ }[]>;
44
+ export declare function unknownDocument(documentId: string, scope: {
45
+ document: DocumentSummary;
46
+ }[]): {
47
+ available?: {
48
+ documentId: string;
49
+ name: string;
50
+ }[];
51
+ ok: boolean;
52
+ summary: string;
53
+ error: string;
54
+ };
33
55
  export declare const listDocumentsTool: NativeToolDefinition;
34
56
  export declare const findInDocumentsTool: NativeToolDefinition;
35
57
  export declare const readDocumentTool: NativeToolDefinition;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.documentTools = exports.unloadDocumentTool = exports.loadDocumentTool = exports.readDocumentTool = exports.findInDocumentsTool = exports.listDocumentsTool = void 0;
3
+ exports.documentTools = exports.unloadDocumentTool = exports.loadDocumentTool = exports.readDocumentTool = exports.findInDocumentsTool = exports.listDocumentsTool = exports.unavailable = void 0;
4
4
  exports.libraryAttachmentName = libraryAttachmentName;
5
5
  exports.isLibraryAttachment = isLibraryAttachment;
6
6
  exports.libraryDocumentIdOf = libraryDocumentIdOf;
7
+ exports.inScope = inScope;
8
+ exports.unknownDocument = unknownDocument;
7
9
  const coerce_1 = require("../shared/coerce");
8
10
  const document_registry_1 = require("../../documents/library/document-registry");
9
11
  /** A holding request past this many characters must be confirmed. Override with `DOCUMENT_LOAD_CONFIRM_CHARS`. */
@@ -52,7 +54,7 @@ function limitFromEnv(name, fallback) {
52
54
  const value = Number(process.env[name]);
53
55
  return Number.isFinite(value) && value > 0 ? value : fallback;
54
56
  }
55
- const unavailable = {
57
+ exports.unavailable = {
56
58
  ok: false,
57
59
  summary: 'No documents are available',
58
60
  error: 'This application has not made any documents available to search.',
@@ -94,6 +96,16 @@ function listedEntry(document, held, withSummary) {
94
96
  ...(document.addedAt ? { addedAt: document.addedAt } : {}),
95
97
  ...(document.state && document.state !== 'ready' ? { state: document.state } : {}),
96
98
  ...(held.has(document.documentId) ? { heldInFull: true } : {}),
99
+ ...(document.template?.length
100
+ ? {
101
+ htmlTemplate: {
102
+ dataBlocks: document.template,
103
+ ...(document.templateRecipe
104
+ ? { recipe: { savedAt: document.templateRecipe.savedAt, parameters: document.templateRecipe.parameters } }
105
+ : {}),
106
+ },
107
+ }
108
+ : {}),
97
109
  ...(withSummary && document.summary ? { summary: clip(document.summary, LIST_SUMMARY_CHARS) } : {}),
98
110
  };
99
111
  }
@@ -141,6 +153,8 @@ exports.listDocumentsTool = {
141
153
  description: 'Lists the documents available to you: each one\'s documentId, name, kind, page count, ' +
142
154
  'size and a short summary, and which of them you are holding in full. Documents can ' +
143
155
  'be added while you work, so list again rather than relying on an earlier answer. ' +
156
+ 'A document with htmlTemplate is an HTML page drawn from embedded data, which ' +
157
+ 'inspect_html_template and fill_html_template can make a new page from. ' +
144
158
  'A large library comes back without summaries, or in pages: when the result has a ' +
145
159
  'nextOffset you have NOT seen every document — call again with that offset, or narrow ' +
146
160
  'with kind or name, before saying what the library holds.',
@@ -166,7 +180,7 @@ exports.listDocumentsTool = {
166
180
  ],
167
181
  handler: async (args, helpers, context) => {
168
182
  if (!(0, document_registry_1.hasDocumentSources)())
169
- return unavailable;
183
+ return exports.unavailable;
170
184
  const kind = optionalString(args.kind, 'kind').toLowerCase();
171
185
  const name = optionalString(args.name, 'name').toLowerCase();
172
186
  const offset = Math.max(0, (0, coerce_1.int)(args.offset, 'offset', 0));
@@ -248,7 +262,7 @@ exports.findInDocumentsTool = {
248
262
  ],
249
263
  handler: async (args, _helpers, context) => {
250
264
  if (!(0, document_registry_1.hasDocumentSources)())
251
- return unavailable;
265
+ return exports.unavailable;
252
266
  const query = (0, coerce_1.str)(args.query, 'query');
253
267
  if (!query) {
254
268
  return { ok: false, summary: 'Nothing to search for', error: 'Say what to look for in "query".' };
@@ -310,7 +324,7 @@ exports.readDocumentTool = {
310
324
  ],
311
325
  handler: async (args, _helpers, context) => {
312
326
  if (!(0, document_registry_1.hasDocumentSources)())
313
- return unavailable;
327
+ return exports.unavailable;
314
328
  const documentId = (0, coerce_1.str)(args.documentId, 'documentId');
315
329
  const scope = await inScope(context);
316
330
  const match = scope.find(({ document }) => document.documentId === documentId);
@@ -370,7 +384,7 @@ exports.loadDocumentTool = {
370
384
  ],
371
385
  handler: async (args, helpers, context) => {
372
386
  if (!(0, document_registry_1.hasDocumentSources)())
373
- return unavailable;
387
+ return exports.unavailable;
374
388
  if (!helpers.documents) {
375
389
  return {
376
390
  ok: false,
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Making a new HTML page from a template in the document library.
3
+ *
4
+ * A template is an HTML page whose scripts draw everything from an embedded JSON
5
+ * data block (`html-data.ts`). An agent asked for "one like this, for someone
6
+ * else" inspects the template's data, works out what each part means, and names
7
+ * the changes; `fill_html_template` copies the page with exactly that data
8
+ * replaced and hands it to the host as a new document.
9
+ *
10
+ * A change can hold its value, or describe it: a query and how each row becomes a
11
+ * record (`template-mapping.ts`). Those queries run here, with the host's context,
12
+ * and their rows go straight into the page — never through the agent. A fill that
13
+ * works can be saved on the template as a recipe, with the customer as a
14
+ * parameter, so the next fill replays its queries and the agent writes only the
15
+ * narrative.
16
+ *
17
+ * Both tools read the template's original file through the source's optional
18
+ * `original`, the fill adds its result through `create`, and recipes go through
19
+ * `saveRecipe` / `recipe` — so they work for any host whose source implements
20
+ * them, and refuse plainly for one that does not. Scope is the same as every
21
+ * document tool's: an id is used only after the host lists it for this context.
22
+ */
23
+ import { NativeToolDefinition } from '../native-tool.types';
24
+ /**
25
+ * The most rows one query in a fill may bring back. Far above `query_data`'s,
26
+ * because these rows go into the page, not into an agent's context.
27
+ */
28
+ export declare const TEMPLATE_FILL_MAX_ROWS = 10000;
29
+ export declare const inspectHtmlTemplateTool: NativeToolDefinition;
30
+ export declare const fillHtmlTemplateTool: NativeToolDefinition;
31
+ export declare const htmlTemplateTools: NativeToolDefinition[];