briyah 2.0.14 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/dist-sdk/server/src/app.controller.d.ts +4 -0
- package/dist-sdk/server/src/app.controller.js +4 -2
- package/dist-sdk/server/src/app.service.d.ts +15 -2
- package/dist-sdk/server/src/app.service.js +30 -2
- package/dist-sdk/server/src/charts/chart-svg.d.ts +24 -0
- package/dist-sdk/server/src/charts/chart-svg.js +415 -0
- package/dist-sdk/server/src/charts/chart-validation.d.ts +28 -0
- package/dist-sdk/server/src/charts/chart-validation.js +129 -0
- package/dist-sdk/server/src/charts/chart.types.d.ts +60 -0
- package/dist-sdk/server/src/charts/chart.types.js +27 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +1 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +6 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +3 -0
- package/dist-sdk/server/src/room/room-clock.d.ts +27 -0
- package/dist-sdk/server/src/room/room-clock.js +51 -0
- package/dist-sdk/server/src/room/room-config.d.ts +8 -0
- package/dist-sdk/server/src/room/room-store.service.js +4 -0
- package/dist-sdk/server/src/room/room.d.ts +16 -5
- package/dist-sdk/server/src/room/room.js +32 -5
- package/dist-sdk/server/src/sdk/index.d.ts +5 -0
- package/dist-sdk/server/src/sdk/index.js +10 -1
- package/dist-sdk/server/src/tools/core/chart.tool.d.ts +15 -0
- package/dist-sdk/server/src/tools/core/chart.tool.js +83 -0
- package/dist-sdk/server/src/tools/core/data.tools.d.ts +14 -2
- package/dist-sdk/server/src/tools/core/data.tools.js +31 -4
- package/dist-sdk/server/src/tools/core/index.js +2 -0
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +7 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +17 -0
- package/dist-sdk/shared/types/app.types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeChartTool = void 0;
|
|
4
|
+
const coerce_1 = require("../shared/coerce");
|
|
5
|
+
const chart_validation_1 = require("../../charts/chart-validation");
|
|
6
|
+
const chart_svg_1 = require("../../charts/chart-svg");
|
|
7
|
+
const chart_types_1 = require("../../charts/chart.types");
|
|
8
|
+
const CHART_EXAMPLE = '{"type": "line", "title": "Fleet miles by quarter", "yLabel": "Miles", ' +
|
|
9
|
+
'"categories": ["2025 Q1", "2025 Q2", "2025 Q3"], ' +
|
|
10
|
+
'"series": [{"name": "Fleet miles", "values": [970269, 1007320, 962897]}]}';
|
|
11
|
+
/**
|
|
12
|
+
* The chart, in either form a model sends it: wrapped in `chart` — as the
|
|
13
|
+
* parameter declares — or as the arguments themselves, the way the example shows
|
|
14
|
+
* it. The same leniency as `query_data`'s, for the same reason.
|
|
15
|
+
*/
|
|
16
|
+
function chartFromArgs(args) {
|
|
17
|
+
const wrapped = args?.chart;
|
|
18
|
+
if (wrapped !== undefined && wrapped !== null && wrapped !== '') {
|
|
19
|
+
return (0, coerce_1.jsonObject)(wrapped, 'chart', CHART_EXAMPLE);
|
|
20
|
+
}
|
|
21
|
+
if (args?.type !== undefined || args?.series !== undefined) {
|
|
22
|
+
const fields = {};
|
|
23
|
+
for (const [key, value] of Object.entries(args)) {
|
|
24
|
+
if (key !== 'chart')
|
|
25
|
+
fields[key] = (0, coerce_1.parsedIfJson)(value);
|
|
26
|
+
}
|
|
27
|
+
return fields;
|
|
28
|
+
}
|
|
29
|
+
throw new coerce_1.ArgumentError('chart', wrapped, 'a JSON object describing the chart', CHART_EXAMPLE);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Turns numbers into a chart an application can draw exactly.
|
|
33
|
+
*
|
|
34
|
+
* The agent describes the chart as data; the tool checks it and hands back the
|
|
35
|
+
* ```chart block to put in a message or a document, where the host draws it with
|
|
36
|
+
* `renderChartSvg`. Checking here is the point: a chart written straight into a
|
|
37
|
+
* document with a typo would just fail to draw, and the agent would never know.
|
|
38
|
+
* Drawn once here too, so a spec that validates but cannot be drawn is caught in
|
|
39
|
+
* the same turn.
|
|
40
|
+
*
|
|
41
|
+
* Never an image model's job: asked for a chart, one draws a plausible picture
|
|
42
|
+
* with numbers of its own.
|
|
43
|
+
*/
|
|
44
|
+
exports.makeChartTool = {
|
|
45
|
+
name: 'make_chart',
|
|
46
|
+
description: 'Makes a chart — line, column, bar, stacked-column or pie — from numbers you already have ' +
|
|
47
|
+
'(read from a document, or returned by a query). Describe it as JSON: ' +
|
|
48
|
+
CHART_EXAMPLE +
|
|
49
|
+
'. One value per category in every series, in order; null where there is no data. ' +
|
|
50
|
+
'Optional: "xLabel", "yLabel", "format" ("number", "currency" or "percent"), and for a ' +
|
|
51
|
+
'line, "startAtZero": true. The result has a `block`: put it in your message or ' +
|
|
52
|
+
'document exactly as given, on lines of its own, and the application draws the chart ' +
|
|
53
|
+
'there. If the chart is refused, fix what the error names and try again.',
|
|
54
|
+
parameters: [
|
|
55
|
+
{
|
|
56
|
+
name: 'chart',
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'The chart as a JSON object. Example: ' + CHART_EXAMPLE +
|
|
59
|
+
' May be left out when its fields are sent as the arguments instead.',
|
|
60
|
+
required: false,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
async handler(args) {
|
|
64
|
+
const raw = chartFromArgs(args);
|
|
65
|
+
const checked = (0, chart_validation_1.validateChart)(raw);
|
|
66
|
+
if (!checked.ok) {
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
summary: 'Chart refused',
|
|
70
|
+
error: checked.error,
|
|
71
|
+
types: [...chart_types_1.CHART_TYPES],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
(0, chart_svg_1.renderChartSvg)(checked.spec);
|
|
75
|
+
const points = checked.spec.categories.length;
|
|
76
|
+
return {
|
|
77
|
+
ok: true,
|
|
78
|
+
summary: `Chart ready: ${checked.spec.title || `${checked.spec.type}, ${points} categories`}`,
|
|
79
|
+
block: `\`\`\`${chart_types_1.CHART_BLOCK_LANGUAGE}\n${JSON.stringify(checked.spec)}\n\`\`\``,
|
|
80
|
+
note: 'Put the block in your message or document exactly as given, on lines of its own.',
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
@@ -8,10 +8,22 @@
|
|
|
8
8
|
* names it chose rather than from anything a model produced. That is the whole
|
|
9
9
|
* safety argument, and it holds without a read-only database role behind it.
|
|
10
10
|
*
|
|
11
|
-
* The DSL
|
|
11
|
+
* The DSL is declared as one parameter because {@link ToolParameter} cannot
|
|
12
12
|
* express nesting. Models reproduce a shown example far more reliably than they
|
|
13
|
-
* invent a shape, so the description carries two worked ones.
|
|
13
|
+
* invent a shape, so the description carries two worked ones. But every example
|
|
14
|
+
* a model sees — here and in the data guide — is the query itself, and a model
|
|
15
|
+
* following them sends the query's fields as the arguments, with no `query`
|
|
16
|
+
* around them. Refusing that cost a call on most first questions, so both forms
|
|
17
|
+
* are read: see {@link queryFromArgs}.
|
|
14
18
|
*/
|
|
15
19
|
import { NativeToolDefinition } from '../native-tool.types';
|
|
20
|
+
/**
|
|
21
|
+
* The query, in either form a model sends it: wrapped in `query` — a JSON string
|
|
22
|
+
* or an object — as the parameter declares, or as the arguments themselves, the
|
|
23
|
+
* way the data guide shows every query. In the second form a nested value sent as
|
|
24
|
+
* a JSON string (`"filters": "[...]"`) is read as the JSON it holds; anything else
|
|
25
|
+
* passes through for {@link validateQuery} to judge.
|
|
26
|
+
*/
|
|
27
|
+
export declare function queryFromArgs(args: Record<string, any>): Record<string, any>;
|
|
16
28
|
export declare const describeDataTool: NativeToolDefinition;
|
|
17
29
|
export declare const queryDataTool: NativeToolDefinition;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.queryDataTool = exports.describeDataTool = void 0;
|
|
4
|
+
exports.queryFromArgs = queryFromArgs;
|
|
4
5
|
const coerce_1 = require("../shared/coerce");
|
|
5
6
|
const data_registry_1 = require("../../data/data-registry");
|
|
6
7
|
const query_validation_1 = require("../../data/query-validation");
|
|
@@ -11,6 +12,28 @@ const QUERY_EXAMPLE = '{"dataset": "claims", "filters": [{"field": "year", "op":
|
|
|
11
12
|
'"orderBy": [{"by": "sum_incurred", "dir": "desc"}], "limit": 10}';
|
|
12
13
|
const LIST_EXAMPLE = '{"dataset": "drivers", "filters": [{"field": "age", "op": "lt", "value": 30}, ' +
|
|
13
14
|
'{"field": "active", "op": "eq", "value": true}], "select": ["firstName", "lastName", "age"]}';
|
|
15
|
+
/**
|
|
16
|
+
* The query, in either form a model sends it: wrapped in `query` — a JSON string
|
|
17
|
+
* or an object — as the parameter declares, or as the arguments themselves, the
|
|
18
|
+
* way the data guide shows every query. In the second form a nested value sent as
|
|
19
|
+
* a JSON string (`"filters": "[...]"`) is read as the JSON it holds; anything else
|
|
20
|
+
* passes through for {@link validateQuery} to judge.
|
|
21
|
+
*/
|
|
22
|
+
function queryFromArgs(args) {
|
|
23
|
+
const wrapped = args?.query;
|
|
24
|
+
if (wrapped !== undefined && wrapped !== null && wrapped !== '') {
|
|
25
|
+
return (0, coerce_1.jsonObject)(wrapped, 'query', QUERY_EXAMPLE);
|
|
26
|
+
}
|
|
27
|
+
if (args?.dataset !== undefined && args.dataset !== null && args.dataset !== '') {
|
|
28
|
+
const fields = {};
|
|
29
|
+
for (const [key, value] of Object.entries(args)) {
|
|
30
|
+
if (key !== 'query')
|
|
31
|
+
fields[key] = (0, coerce_1.parsedIfJson)(value);
|
|
32
|
+
}
|
|
33
|
+
return fields;
|
|
34
|
+
}
|
|
35
|
+
throw new coerce_1.ArgumentError('query', wrapped, 'a JSON object naming a dataset', QUERY_EXAMPLE);
|
|
36
|
+
}
|
|
14
37
|
/** Names every dataset, for an error that teaches rather than just refuses. */
|
|
15
38
|
function datasetNames() {
|
|
16
39
|
return (0, data_registry_1.listDatasets)().map((set) => set.name);
|
|
@@ -83,13 +106,17 @@ exports.queryDataTool = {
|
|
|
83
106
|
' To keep only some groups, add "having": conditions on the query\'s own metrics by ' +
|
|
84
107
|
'their "as", e.g. "having": [{"field": "sum_incurred", "op": "gt", "value": 100000}].' +
|
|
85
108
|
' Only the datasets and fields in your data guide exist; if a question needs ' +
|
|
86
|
-
'something that is not there, say so rather than substituting a field that looks close.'
|
|
109
|
+
'something that is not there, say so rather than substituting a field that looks close.' +
|
|
110
|
+
' Send the query as `query`, or its fields (dataset, filters, …) as the arguments themselves — either works.',
|
|
87
111
|
parameters: [
|
|
88
112
|
{
|
|
89
113
|
name: 'query',
|
|
90
114
|
type: 'string',
|
|
91
|
-
description: 'The query as a JSON object. Example: ' + QUERY_EXAMPLE
|
|
92
|
-
|
|
115
|
+
description: 'The query as a JSON object. Example: ' + QUERY_EXAMPLE +
|
|
116
|
+
' May be left out when the query\'s own fields are sent as the arguments instead.',
|
|
117
|
+
// Not required, so the unwrapped form reaches the handler: a missing
|
|
118
|
+
// query is refused there, with the example, rather than here.
|
|
119
|
+
required: false,
|
|
93
120
|
},
|
|
94
121
|
],
|
|
95
122
|
handler: async (args, _helpers, context) => {
|
|
@@ -100,7 +127,7 @@ exports.queryDataTool = {
|
|
|
100
127
|
error: 'This application has not made any data available to query.',
|
|
101
128
|
};
|
|
102
129
|
}
|
|
103
|
-
const raw = (
|
|
130
|
+
const raw = queryFromArgs(args);
|
|
104
131
|
const checked = (0, query_validation_1.validateQuery)(raw, (0, data_registry_1.listDatasets)());
|
|
105
132
|
if (!checked.ok) {
|
|
106
133
|
// A refusal, not a malfunction: it names what was allowed instead so
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.CORE_TOOL_GROUP = void 0;
|
|
18
18
|
exports.coreTools = coreTools;
|
|
19
|
+
const chart_tool_1 = require("./chart.tool");
|
|
19
20
|
const create_image_tool_1 = require("./create-image.tool");
|
|
20
21
|
const data_tools_1 = require("./data.tools");
|
|
21
22
|
const document_tools_1 = require("./document.tools");
|
|
@@ -35,6 +36,7 @@ function coreTools() {
|
|
|
35
36
|
rename_tool_1.renameAgentTool,
|
|
36
37
|
illustrate_tool_1.illustrateTool,
|
|
37
38
|
create_image_tool_1.createImageTool,
|
|
39
|
+
chart_tool_1.makeChartTool,
|
|
38
40
|
data_tools_1.describeDataTool,
|
|
39
41
|
data_tools_1.queryDataTool,
|
|
40
42
|
...document_tools_1.documentTools,
|
|
@@ -74,6 +74,13 @@ export declare function jsonObject(value: unknown, param: string, example?: stri
|
|
|
74
74
|
* @throws {ArgumentError} If the value is present but is not an array
|
|
75
75
|
*/
|
|
76
76
|
export declare function jsonArray(value: unknown, param: string, example?: string): any[];
|
|
77
|
+
/**
|
|
78
|
+
* A value read as the JSON it holds, when it is a string that looks like an
|
|
79
|
+
* array or object — models send nested arguments that way unprompted — and as
|
|
80
|
+
* itself otherwise, including a string that only looks like JSON. Whoever reads
|
|
81
|
+
* the value next judges it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function parsedIfJson(value: unknown): unknown;
|
|
77
84
|
/**
|
|
78
85
|
* Normalizes a name for comparison: lowercase, punctuation and extra
|
|
79
86
|
* whitespace removed. Lets "Thalia Emberwood" match "thalia emberwood" and
|
|
@@ -19,6 +19,7 @@ exports.str = str;
|
|
|
19
19
|
exports.list = list;
|
|
20
20
|
exports.jsonObject = jsonObject;
|
|
21
21
|
exports.jsonArray = jsonArray;
|
|
22
|
+
exports.parsedIfJson = parsedIfJson;
|
|
22
23
|
exports.nameKey = nameKey;
|
|
23
24
|
exports.matchName = matchName;
|
|
24
25
|
exports.matchNames = matchNames;
|
|
@@ -184,6 +185,22 @@ function jsonArray(value, param, example) {
|
|
|
184
185
|
}
|
|
185
186
|
throw new ArgumentError(param, value, 'a JSON array', example);
|
|
186
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* A value read as the JSON it holds, when it is a string that looks like an
|
|
190
|
+
* array or object — models send nested arguments that way unprompted — and as
|
|
191
|
+
* itself otherwise, including a string that only looks like JSON. Whoever reads
|
|
192
|
+
* the value next judges it.
|
|
193
|
+
*/
|
|
194
|
+
function parsedIfJson(value) {
|
|
195
|
+
if (typeof value !== 'string' || !/^\s*[[{]/.test(value))
|
|
196
|
+
return value;
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(value);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
187
204
|
/** Removes a surrounding markdown code fence, which models add unprompted. */
|
|
188
205
|
function stripCodeFence(text) {
|
|
189
206
|
const trimmed = text.trim();
|
|
@@ -236,6 +236,11 @@ export interface RoomDetails {
|
|
|
236
236
|
* for another. Absent means 'square'. See {@link ImageAspect}.
|
|
237
237
|
*/
|
|
238
238
|
imageAspect?: ImageAspect;
|
|
239
|
+
/**
|
|
240
|
+
* The IANA time zone in which this room's agents are told today's date on every
|
|
241
|
+
* turn. Absent means they are not told — a story keeps its own clock.
|
|
242
|
+
*/
|
|
243
|
+
timeZone?: string;
|
|
239
244
|
/**
|
|
240
245
|
* Nickname of the agent that places messages it cannot route mechanically.
|
|
241
246
|
* Only consulted in 'moderated' mode. Absent falls back to the first agent in
|
package/package.json
CHANGED