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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checking a chart an agent described, before anything is drawn.
|
|
3
|
+
*
|
|
4
|
+
* The answer is written for the agent: each refusal says what was wrong and what
|
|
5
|
+
* would be right, so its next attempt is a correction rather than another guess.
|
|
6
|
+
* A chart that passes is normalized — trimmed, defaulted, numbers that arrived as
|
|
7
|
+
* strings read as numbers — so a renderer never has to be forgiving.
|
|
8
|
+
*/
|
|
9
|
+
import { ChartSpec } from './chart.types';
|
|
10
|
+
/**
|
|
11
|
+
* Each branch names the other's field as absent: this project compiles without
|
|
12
|
+
* strictNullChecks, which turns off narrowing on `ok`, and a caller reads
|
|
13
|
+
* `error` after `if (!checked.ok)`.
|
|
14
|
+
*/
|
|
15
|
+
export type ChartValidation = {
|
|
16
|
+
ok: true;
|
|
17
|
+
spec: ChartSpec;
|
|
18
|
+
error?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
error: string;
|
|
22
|
+
spec?: undefined;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @param raw What the agent sent, already parsed from JSON
|
|
26
|
+
* @returns The normalized spec, or what is wrong with it
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateChart(raw: unknown): ChartValidation;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateChart = validateChart;
|
|
4
|
+
/**
|
|
5
|
+
* Checking a chart an agent described, before anything is drawn.
|
|
6
|
+
*
|
|
7
|
+
* The answer is written for the agent: each refusal says what was wrong and what
|
|
8
|
+
* would be right, so its next attempt is a correction rather than another guess.
|
|
9
|
+
* A chart that passes is normalized — trimmed, defaulted, numbers that arrived as
|
|
10
|
+
* strings read as numbers — so a renderer never has to be forgiving.
|
|
11
|
+
*/
|
|
12
|
+
const chart_types_1 = require("./chart.types");
|
|
13
|
+
/** A short label: trimmed, and cut where a chart could not show the rest anyway. */
|
|
14
|
+
function label(value, max) {
|
|
15
|
+
const text = value === undefined || value === null ? '' : String(value).trim();
|
|
16
|
+
return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}…`;
|
|
17
|
+
}
|
|
18
|
+
/** A value as a number: a number, a numeric string ("1,234", "$5.6"), or null for a gap. */
|
|
19
|
+
function value(raw) {
|
|
20
|
+
if (raw === null || raw === '')
|
|
21
|
+
return null;
|
|
22
|
+
if (typeof raw === 'number')
|
|
23
|
+
return Number.isFinite(raw) ? raw : undefined;
|
|
24
|
+
if (typeof raw === 'string') {
|
|
25
|
+
const parsed = Number(raw.replace(/[$,%\s]/g, ''));
|
|
26
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
function fail(error) {
|
|
31
|
+
return { ok: false, error };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @param raw What the agent sent, already parsed from JSON
|
|
35
|
+
* @returns The normalized spec, or what is wrong with it
|
|
36
|
+
*/
|
|
37
|
+
function validateChart(raw) {
|
|
38
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
39
|
+
return fail('A chart is a JSON object: {"type": "line", "categories": [...], "series": [{"name": ..., "values": [...]}]}.');
|
|
40
|
+
}
|
|
41
|
+
const input = raw;
|
|
42
|
+
const type = String(input.type ?? '').trim().toLowerCase();
|
|
43
|
+
if (!chart_types_1.CHART_TYPES.includes(type)) {
|
|
44
|
+
return fail(`"type" must be one of: ${chart_types_1.CHART_TYPES.join(', ')}.`);
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(input.categories) || input.categories.length === 0) {
|
|
47
|
+
return fail('"categories" must be a list of labels, one for each point along the axis (or each pie slice).');
|
|
48
|
+
}
|
|
49
|
+
if (input.categories.length > chart_types_1.MAX_CHART_CATEGORIES) {
|
|
50
|
+
return fail(`${input.categories.length} categories are too many to read; at most ${chart_types_1.MAX_CHART_CATEGORIES}. ` +
|
|
51
|
+
'Group the data (by year rather than month, say) or chart the top ones.');
|
|
52
|
+
}
|
|
53
|
+
const categories = input.categories.map((category) => label(category, 60));
|
|
54
|
+
if (categories.some((category) => !category)) {
|
|
55
|
+
return fail('Every category needs a label; one is empty.');
|
|
56
|
+
}
|
|
57
|
+
const rawSeries = Array.isArray(input.series)
|
|
58
|
+
? input.series
|
|
59
|
+
: input.series && typeof input.series === 'object'
|
|
60
|
+
? [input.series]
|
|
61
|
+
: [];
|
|
62
|
+
if (rawSeries.length === 0) {
|
|
63
|
+
return fail('"series" must be a list of {"name": ..., "values": [...]}, with one value per category.');
|
|
64
|
+
}
|
|
65
|
+
if (rawSeries.length > chart_types_1.MAX_CHART_SERIES) {
|
|
66
|
+
return fail(`${rawSeries.length} series are too many for one chart; at most ${chart_types_1.MAX_CHART_SERIES}.`);
|
|
67
|
+
}
|
|
68
|
+
const series = [];
|
|
69
|
+
for (const [index, entry] of rawSeries.entries()) {
|
|
70
|
+
const item = entry;
|
|
71
|
+
const name = label(item?.name, 60) || (rawSeries.length === 1 ? '' : `Series ${index + 1}`);
|
|
72
|
+
if (!Array.isArray(item?.values)) {
|
|
73
|
+
return fail(`Series ${name ? `"${name}"` : index + 1} needs "values": a list with one number per category.`);
|
|
74
|
+
}
|
|
75
|
+
if (item.values.length !== categories.length) {
|
|
76
|
+
return fail(`Series ${name ? `"${name}"` : index + 1} has ${item.values.length} value(s) but there are ` +
|
|
77
|
+
`${categories.length} categories. Give exactly one value per category, in order — null where there is no data.`);
|
|
78
|
+
}
|
|
79
|
+
const values = [];
|
|
80
|
+
for (const [position, rawValue] of item.values.entries()) {
|
|
81
|
+
const parsed = value(rawValue);
|
|
82
|
+
if (parsed === undefined) {
|
|
83
|
+
return fail(`Series ${name ? `"${name}"` : index + 1}, "${categories[position]}": ${JSON.stringify(rawValue)} ` +
|
|
84
|
+
'is not a number. Use a plain number, or null where there is no data.');
|
|
85
|
+
}
|
|
86
|
+
values.push(parsed);
|
|
87
|
+
}
|
|
88
|
+
if (values.every((v) => v === null)) {
|
|
89
|
+
return fail(`Series ${name ? `"${name}"` : index + 1} has no values at all.`);
|
|
90
|
+
}
|
|
91
|
+
series.push({ name, values });
|
|
92
|
+
}
|
|
93
|
+
if (type === 'pie') {
|
|
94
|
+
if (series.length !== 1) {
|
|
95
|
+
return fail('A pie shows one whole: give exactly one series. To compare several, use "column".');
|
|
96
|
+
}
|
|
97
|
+
if (categories.length > chart_types_1.MAX_PIE_SLICES) {
|
|
98
|
+
return fail(`${categories.length} slices are too many for a pie; at most ${chart_types_1.MAX_PIE_SLICES}. ` +
|
|
99
|
+
'Combine the smallest into "Other", or use "bar".');
|
|
100
|
+
}
|
|
101
|
+
if (series[0].values.some((v) => v !== null && v < 0)) {
|
|
102
|
+
return fail('A pie cannot show a negative value. Use "column" or "bar".');
|
|
103
|
+
}
|
|
104
|
+
if (!series[0].values.some((v) => v !== null && v > 0)) {
|
|
105
|
+
return fail('A pie needs at least one value above zero.');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (type === 'stacked-column' && series.some((s) => s.values.some((v) => v !== null && v < 0))) {
|
|
109
|
+
return fail('A stacked column cannot show a negative value. Use "column", which can.');
|
|
110
|
+
}
|
|
111
|
+
let format = 'number';
|
|
112
|
+
if (input.format !== undefined && input.format !== null && input.format !== '') {
|
|
113
|
+
format = String(input.format).trim().toLowerCase();
|
|
114
|
+
if (!chart_types_1.CHART_VALUE_FORMATS.includes(format)) {
|
|
115
|
+
return fail(`"format" must be one of: ${chart_types_1.CHART_VALUE_FORMATS.join(', ')}.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const spec = {
|
|
119
|
+
type,
|
|
120
|
+
...(label(input.title, 120) ? { title: label(input.title, 120) } : {}),
|
|
121
|
+
categories,
|
|
122
|
+
series,
|
|
123
|
+
...(label(input.xLabel, 60) ? { xLabel: label(input.xLabel, 60) } : {}),
|
|
124
|
+
...(label(input.yLabel, 60) ? { yLabel: label(input.yLabel, 60) } : {}),
|
|
125
|
+
...(format !== 'number' ? { format } : {}),
|
|
126
|
+
...(type === 'line' && input.startAtZero === true ? { startAtZero: true } : {}),
|
|
127
|
+
};
|
|
128
|
+
return { ok: true, spec };
|
|
129
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A chart, described as data.
|
|
3
|
+
*
|
|
4
|
+
* An agent asked for a graph has the numbers and no way to draw them, and an
|
|
5
|
+
* image model asked to draw one invents a plausible chart with numbers of its own.
|
|
6
|
+
* So an agent describes the chart in this small, fixed shape — what kind, the
|
|
7
|
+
* categories along the axis, the series of values — and Briyah draws it as SVG,
|
|
8
|
+
* exactly.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately small rather than a general chart language: every field here is
|
|
11
|
+
* one a model fills in correctly from an example, and every chart it can express
|
|
12
|
+
* is one a business reader wants. Anything that needs more is a report a host
|
|
13
|
+
* builds itself.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* - `line`: a trend over time — categories are periods, in order.
|
|
17
|
+
* - `column`: comparing categories side by side; several series group.
|
|
18
|
+
* - `bar`: `column` turned on its side, for long names or many categories.
|
|
19
|
+
* - `stacked-column`: parts of a whole across categories; totals on top.
|
|
20
|
+
* - `pie`: shares of one whole. One series, a few slices, no negatives.
|
|
21
|
+
*/
|
|
22
|
+
export type ChartType = 'line' | 'column' | 'bar' | 'stacked-column' | 'pie';
|
|
23
|
+
export declare const CHART_TYPES: readonly ChartType[];
|
|
24
|
+
/** How values are written on the axis, the labels and the legend. */
|
|
25
|
+
export type ChartValueFormat = 'number' | 'currency' | 'percent';
|
|
26
|
+
export declare const CHART_VALUE_FORMATS: readonly ChartValueFormat[];
|
|
27
|
+
export interface ChartSeries {
|
|
28
|
+
/** What the series is, as the legend shows it. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** One value per category, in the same order. `null` is a gap: no data there. */
|
|
31
|
+
values: (number | null)[];
|
|
32
|
+
}
|
|
33
|
+
export interface ChartSpec {
|
|
34
|
+
type: ChartType;
|
|
35
|
+
/** The chart's heading. */
|
|
36
|
+
title?: string;
|
|
37
|
+
/** The labels along the category axis — periods, names — in order. A pie's slices. */
|
|
38
|
+
categories: string[];
|
|
39
|
+
series: ChartSeries[];
|
|
40
|
+
/** What the category axis measures, e.g. "Quarter". */
|
|
41
|
+
xLabel?: string;
|
|
42
|
+
/** What the value axis measures, e.g. "Miles". */
|
|
43
|
+
yLabel?: string;
|
|
44
|
+
/** How values are written. Absent means `number`; `percent` takes 12.5 to mean 12.5%. */
|
|
45
|
+
format?: ChartValueFormat;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a line chart's value axis starts at zero. Absent means it fits the
|
|
48
|
+
* data, which shows the movement in a series that never nears zero. Columns
|
|
49
|
+
* and bars always start at zero: a bar's length is its value.
|
|
50
|
+
*/
|
|
51
|
+
startAtZero?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** The fence language a chart block is written with in markdown: ```chart */
|
|
54
|
+
export declare const CHART_BLOCK_LANGUAGE = "chart";
|
|
55
|
+
/** Most categories a chart takes. Past this a chart is unreadable; group the data first. */
|
|
56
|
+
export declare const MAX_CHART_CATEGORIES = 60;
|
|
57
|
+
/** Most series a chart takes. Past this the legend is a list nobody reads. */
|
|
58
|
+
export declare const MAX_CHART_SERIES = 8;
|
|
59
|
+
/** Most slices a pie takes. Past this the slices are slivers. */
|
|
60
|
+
export declare const MAX_PIE_SLICES = 12;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* A chart, described as data.
|
|
4
|
+
*
|
|
5
|
+
* An agent asked for a graph has the numbers and no way to draw them, and an
|
|
6
|
+
* image model asked to draw one invents a plausible chart with numbers of its own.
|
|
7
|
+
* So an agent describes the chart in this small, fixed shape — what kind, the
|
|
8
|
+
* categories along the axis, the series of values — and Briyah draws it as SVG,
|
|
9
|
+
* exactly.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately small rather than a general chart language: every field here is
|
|
12
|
+
* one a model fills in correctly from an example, and every chart it can express
|
|
13
|
+
* is one a business reader wants. Anything that needs more is a report a host
|
|
14
|
+
* builds itself.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.MAX_PIE_SLICES = exports.MAX_CHART_SERIES = exports.MAX_CHART_CATEGORIES = exports.CHART_BLOCK_LANGUAGE = exports.CHART_VALUE_FORMATS = exports.CHART_TYPES = void 0;
|
|
18
|
+
exports.CHART_TYPES = ['line', 'column', 'bar', 'stacked-column', 'pie'];
|
|
19
|
+
exports.CHART_VALUE_FORMATS = ['number', 'currency', 'percent'];
|
|
20
|
+
/** The fence language a chart block is written with in markdown: ```chart */
|
|
21
|
+
exports.CHART_BLOCK_LANGUAGE = 'chart';
|
|
22
|
+
/** Most categories a chart takes. Past this a chart is unreadable; group the data first. */
|
|
23
|
+
exports.MAX_CHART_CATEGORIES = 60;
|
|
24
|
+
/** Most series a chart takes. Past this the legend is a list nobody reads. */
|
|
25
|
+
exports.MAX_CHART_SERIES = 8;
|
|
26
|
+
/** Most slices a pie takes. Past this the slices are slivers. */
|
|
27
|
+
exports.MAX_PIE_SLICES = 12;
|
|
@@ -127,6 +127,7 @@ class PackInstantiationService {
|
|
|
127
127
|
imageModel: template.imageModel,
|
|
128
128
|
illustrationMode: template.illustrationMode ?? 'on-request',
|
|
129
129
|
imageAspect: template.imageAspect ?? 'square',
|
|
130
|
+
timeZone: template.timeZone,
|
|
130
131
|
});
|
|
131
132
|
room.saveMetadata();
|
|
132
133
|
return { roomId, agentIds, warnings };
|
|
@@ -149,6 +149,12 @@ export interface PackRoomTemplate {
|
|
|
149
149
|
illustrationMode?: 'off' | 'on-request' | 'auto';
|
|
150
150
|
/** The default shape of the room's pictures. Absent means `square`. */
|
|
151
151
|
imageAspect?: ImageAspect;
|
|
152
|
+
/**
|
|
153
|
+
* The IANA time zone the room's agents are told today's date in. Absent means
|
|
154
|
+
* they are not told — what a story or campaign wants. A name the runtime does
|
|
155
|
+
* not know is dropped when the pack is read.
|
|
156
|
+
*/
|
|
157
|
+
timeZone?: string;
|
|
152
158
|
/**
|
|
153
159
|
* The roster, as loaded.
|
|
154
160
|
*
|
|
@@ -67,6 +67,7 @@ exports.roomAgentKey = roomAgentKey;
|
|
|
67
67
|
const fs = __importStar(require("fs"));
|
|
68
68
|
const path = __importStar(require("path"));
|
|
69
69
|
const app_types_1 = require("../../../shared/types/app.types");
|
|
70
|
+
const room_clock_1 = require("../room/room-clock");
|
|
70
71
|
const prompt_resolver_1 = require("../config/prompt-resolver");
|
|
71
72
|
const logger_1 = require("../common/logger");
|
|
72
73
|
/** Subdirectories of a pack, by what they hold. */
|
|
@@ -321,6 +322,8 @@ function validateRoomTemplate(value, file) {
|
|
|
321
322
|
? { illustrationMode: value.illustrationMode }
|
|
322
323
|
: {}),
|
|
323
324
|
...(app_types_1.IMAGE_ASPECTS.includes(value.imageAspect) && { imageAspect: value.imageAspect }),
|
|
325
|
+
...(typeof value.timeZone === 'string' &&
|
|
326
|
+
(0, room_clock_1.isTimeZone)(value.timeZone.trim()) && { timeZone: value.timeZone.trim() }),
|
|
324
327
|
agents,
|
|
325
328
|
...(isValidKey(value.roomLeader) && { roomLeader: value.roomLeader }),
|
|
326
329
|
...(isValidKey(value.moderator) && { moderator: value.moderator }),
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Today's real date, for rooms that work in the present.
|
|
3
|
+
*
|
|
4
|
+
* A model knows nothing of the date. Asked about "this year", an agent guesses
|
|
5
|
+
* from the newest thing it has seen, and an assistant answering about policies in
|
|
6
|
+
* force once asked the person to confirm what year it was. So a room can name a
|
|
7
|
+
* time zone, and every turn its agents take starts with the date and time there.
|
|
8
|
+
*
|
|
9
|
+
* Opt-in, never a default: a story or a campaign keeps its own clock (the room's
|
|
10
|
+
* situation time), and a real date beside it would be one more fact for a narrator
|
|
11
|
+
* to get wrong. And never cached: it goes in the per-turn prompt, which is sent
|
|
12
|
+
* uncached and kept out of history, so the minute changing costs nothing.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Whether a name is an IANA time zone this runtime knows — `America/Chicago`,
|
|
16
|
+
* `UTC`. Checked when the setting is made, so a typo is refused there rather than
|
|
17
|
+
* failing every turn afterwards.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isTimeZone(name: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The line an agent's turn opens with: "Today is Monday, November 2, 2026; the
|
|
22
|
+
* time is 9:58 PM (America/Chicago)."
|
|
23
|
+
*
|
|
24
|
+
* @param timeZone An IANA time zone, already checked with {@link isTimeZone}
|
|
25
|
+
* @param now The moment to describe. Defaults to now.
|
|
26
|
+
*/
|
|
27
|
+
export declare function describeNow(timeZone: string, now?: Date): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Today's real date, for rooms that work in the present.
|
|
4
|
+
*
|
|
5
|
+
* A model knows nothing of the date. Asked about "this year", an agent guesses
|
|
6
|
+
* from the newest thing it has seen, and an assistant answering about policies in
|
|
7
|
+
* force once asked the person to confirm what year it was. So a room can name a
|
|
8
|
+
* time zone, and every turn its agents take starts with the date and time there.
|
|
9
|
+
*
|
|
10
|
+
* Opt-in, never a default: a story or a campaign keeps its own clock (the room's
|
|
11
|
+
* situation time), and a real date beside it would be one more fact for a narrator
|
|
12
|
+
* to get wrong. And never cached: it goes in the per-turn prompt, which is sent
|
|
13
|
+
* uncached and kept out of history, so the minute changing costs nothing.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.isTimeZone = isTimeZone;
|
|
17
|
+
exports.describeNow = describeNow;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a name is an IANA time zone this runtime knows — `America/Chicago`,
|
|
20
|
+
* `UTC`. Checked when the setting is made, so a typo is refused there rather than
|
|
21
|
+
* failing every turn afterwards.
|
|
22
|
+
*/
|
|
23
|
+
function isTimeZone(name) {
|
|
24
|
+
if (!name || typeof name !== 'string')
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
new Intl.DateTimeFormat('en-US', { timeZone: name });
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The line an agent's turn opens with: "Today is Monday, November 2, 2026; the
|
|
36
|
+
* time is 9:58 PM (America/Chicago)."
|
|
37
|
+
*
|
|
38
|
+
* @param timeZone An IANA time zone, already checked with {@link isTimeZone}
|
|
39
|
+
* @param now The moment to describe. Defaults to now.
|
|
40
|
+
*/
|
|
41
|
+
function describeNow(timeZone, now = new Date()) {
|
|
42
|
+
const date = now.toLocaleDateString('en-US', {
|
|
43
|
+
timeZone,
|
|
44
|
+
weekday: 'long',
|
|
45
|
+
year: 'numeric',
|
|
46
|
+
month: 'long',
|
|
47
|
+
day: 'numeric',
|
|
48
|
+
});
|
|
49
|
+
const time = now.toLocaleTimeString('en-US', { timeZone, hour: 'numeric', minute: '2-digit' });
|
|
50
|
+
return `Today is ${date}; the time is ${time} (${timeZone}).`;
|
|
51
|
+
}
|
|
@@ -92,6 +92,14 @@ export interface RoomConfig {
|
|
|
92
92
|
* reused across every later scene whatever its shape.
|
|
93
93
|
*/
|
|
94
94
|
imageAspect?: ImageAspect;
|
|
95
|
+
/**
|
|
96
|
+
* An IANA time zone (`America/Chicago`) in which every agent's turn is told
|
|
97
|
+
* today's date and time. Absent means the agents are not told, which is right
|
|
98
|
+
* for a story — it keeps its own clock — and was how every room worked before.
|
|
99
|
+
* A room that works in the present, an assistant answering about "this year",
|
|
100
|
+
* should set it. See `room-clock.ts`.
|
|
101
|
+
*/
|
|
102
|
+
timeZone?: string;
|
|
95
103
|
}
|
|
96
104
|
/**
|
|
97
105
|
* Every setting a room carries, without its identity or its content.
|
|
@@ -258,6 +258,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
|
|
|
258
258
|
imageModel: room.getImageModel(),
|
|
259
259
|
illustrationMode: room.getIllustrationMode(),
|
|
260
260
|
imageAspect: room.getImageAspect(),
|
|
261
|
+
timeZone: room.getTimeZone(),
|
|
261
262
|
};
|
|
262
263
|
}
|
|
263
264
|
/**
|
|
@@ -293,6 +294,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
|
|
|
293
294
|
room.setImageModel(settings.imageModel);
|
|
294
295
|
room.setIllustrationMode(settings.illustrationMode);
|
|
295
296
|
room.setImageAspect(settings.imageAspect);
|
|
297
|
+
room.setTimeZone(settings.timeZone);
|
|
296
298
|
room.setRoomLeader(settings.roomLeader);
|
|
297
299
|
room.setTurnMode(settings.turnMode);
|
|
298
300
|
room.setModerator(settings.moderator);
|
|
@@ -507,6 +509,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
|
|
|
507
509
|
room.setImageModel(config.imageModel);
|
|
508
510
|
room.setIllustrationMode(config.illustrationMode);
|
|
509
511
|
room.setImageAspect(config.imageAspect);
|
|
512
|
+
room.setTimeZone(config.timeZone);
|
|
510
513
|
// Add agents to the room (loaded from adjacent agents directory)
|
|
511
514
|
//
|
|
512
515
|
// An id that resolves to nothing is a deleted agent the room still
|
|
@@ -587,6 +590,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
|
|
|
587
590
|
imageModel: room.getImageModel(),
|
|
588
591
|
illustrationMode: room.getIllustrationMode(),
|
|
589
592
|
imageAspect: room.getImageAspect(),
|
|
593
|
+
timeZone: room.getTimeZone(),
|
|
590
594
|
};
|
|
591
595
|
const metadataPath = path.join(roomDir, 'metadata.json');
|
|
592
596
|
fs.writeFileSync(metadataPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
@@ -159,6 +159,8 @@ export declare class Room {
|
|
|
159
159
|
private illustrationMode;
|
|
160
160
|
/** The default shape of this room's pictures. See {@link RoomConfig.imageAspect}. */
|
|
161
161
|
private imageAspect;
|
|
162
|
+
/** Where the room tells its agents the date. See {@link RoomConfig.timeZone}. */
|
|
163
|
+
private timeZone;
|
|
162
164
|
/**
|
|
163
165
|
* Agents that work for this room but never take a turn in it: the illustrator
|
|
164
166
|
* and the two artists.
|
|
@@ -235,6 +237,14 @@ export declare class Room {
|
|
|
235
237
|
*/
|
|
236
238
|
getImageAspect(): ImageAspect;
|
|
237
239
|
setImageAspect(aspect: ImageAspect | undefined): void;
|
|
240
|
+
/** @returns The time zone this room's agents are told the date in, or undefined when they are not told. */
|
|
241
|
+
getTimeZone(): string | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* @param timeZone An IANA time zone, or empty/undefined to stop telling the
|
|
244
|
+
* agents the date. A name this runtime does not know is ignored with a
|
|
245
|
+
* warning — the endpoints refuse one before it gets here.
|
|
246
|
+
*/
|
|
247
|
+
setTimeZone(timeZone: string | undefined): void;
|
|
238
248
|
/**
|
|
239
249
|
* Registers an agent that works for this room without ever taking a turn.
|
|
240
250
|
* Idempotent, since the illustration service resolves its agents on every call.
|
|
@@ -1023,12 +1033,13 @@ export declare class Room {
|
|
|
1023
1033
|
*/
|
|
1024
1034
|
setSituationTime(time: string): void;
|
|
1025
1035
|
/**
|
|
1026
|
-
* Builds the situation header shared by every agent's transient prompt:
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1029
|
-
* line is omitted when
|
|
1036
|
+
* Builds the situation header shared by every agent's transient prompt: today's
|
|
1037
|
+
* real date, when the room names a time zone; the in-story time on its own
|
|
1038
|
+
* labeled line (flagged as a 24-hour clock so a character doesn't misread
|
|
1039
|
+
* "10:30" as 10:30 PM); then the situation text. Each line is omitted when it
|
|
1040
|
+
* has nothing to say.
|
|
1030
1041
|
*
|
|
1031
|
-
* @returns The
|
|
1042
|
+
* @returns The header lines, or '' if there are none
|
|
1032
1043
|
*/
|
|
1033
1044
|
private buildSituationHeader;
|
|
1034
1045
|
/**
|
|
@@ -7,6 +7,7 @@ const message_1 = require("./message");
|
|
|
7
7
|
const nickname_1 = require("./nickname");
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
9
|
const errors_1 = require("../common/errors");
|
|
10
|
+
const room_clock_1 = require("./room-clock");
|
|
10
11
|
const logger_1 = require("../common/logger");
|
|
11
12
|
/**
|
|
12
13
|
* A Room that contains agents
|
|
@@ -187,6 +188,8 @@ class Room {
|
|
|
187
188
|
illustrationMode = 'on-request';
|
|
188
189
|
/** The default shape of this room's pictures. See {@link RoomConfig.imageAspect}. */
|
|
189
190
|
imageAspect = 'square';
|
|
191
|
+
/** Where the room tells its agents the date. See {@link RoomConfig.timeZone}. */
|
|
192
|
+
timeZone;
|
|
190
193
|
/**
|
|
191
194
|
* Agents that work for this room but never take a turn in it: the illustrator
|
|
192
195
|
* and the two artists.
|
|
@@ -330,6 +333,24 @@ class Room {
|
|
|
330
333
|
setImageAspect(aspect) {
|
|
331
334
|
this.imageAspect = aspect || 'square';
|
|
332
335
|
}
|
|
336
|
+
/** @returns The time zone this room's agents are told the date in, or undefined when they are not told. */
|
|
337
|
+
getTimeZone() {
|
|
338
|
+
return this.timeZone;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* @param timeZone An IANA time zone, or empty/undefined to stop telling the
|
|
342
|
+
* agents the date. A name this runtime does not know is ignored with a
|
|
343
|
+
* warning — the endpoints refuse one before it gets here.
|
|
344
|
+
*/
|
|
345
|
+
setTimeZone(timeZone) {
|
|
346
|
+
const name = timeZone?.trim() || undefined;
|
|
347
|
+
if (name && !(0, room_clock_1.isTimeZone)(name)) {
|
|
348
|
+
logger_1.logger.warn(`Room ${this.name}: "${name}" is not a time zone; agents will not be told the date`);
|
|
349
|
+
this.timeZone = undefined;
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
this.timeZone = name;
|
|
353
|
+
}
|
|
333
354
|
/**
|
|
334
355
|
* Registers an agent that works for this room without ever taking a turn.
|
|
335
356
|
* Idempotent, since the illustration service resolves its agents on every call.
|
|
@@ -2375,15 +2396,21 @@ Recent Message: ${message.getContent()}
|
|
|
2375
2396
|
this.currentSituationTime = time || '';
|
|
2376
2397
|
}
|
|
2377
2398
|
/**
|
|
2378
|
-
* Builds the situation header shared by every agent's transient prompt:
|
|
2379
|
-
*
|
|
2380
|
-
*
|
|
2381
|
-
* line is omitted when
|
|
2399
|
+
* Builds the situation header shared by every agent's transient prompt: today's
|
|
2400
|
+
* real date, when the room names a time zone; the in-story time on its own
|
|
2401
|
+
* labeled line (flagged as a 24-hour clock so a character doesn't misread
|
|
2402
|
+
* "10:30" as 10:30 PM); then the situation text. Each line is omitted when it
|
|
2403
|
+
* has nothing to say.
|
|
2382
2404
|
*
|
|
2383
|
-
* @returns The
|
|
2405
|
+
* @returns The header lines, or '' if there are none
|
|
2384
2406
|
*/
|
|
2385
2407
|
buildSituationHeader() {
|
|
2386
2408
|
const lines = [];
|
|
2409
|
+
// The real date first, for a room that asked for it (see room-clock.ts). A
|
|
2410
|
+
// story never does, so its in-story time below stays the only clock.
|
|
2411
|
+
if (this.timeZone) {
|
|
2412
|
+
lines.push((0, room_clock_1.describeNow)(this.timeZone));
|
|
2413
|
+
}
|
|
2387
2414
|
if (this.currentSituationTime) {
|
|
2388
2415
|
lines.push(`Current time: ${this.currentSituationTime} (24-hour clock)`);
|
|
2389
2416
|
}
|
|
@@ -30,6 +30,11 @@ export { DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT } from '../data/data.types';
|
|
|
30
30
|
export { registerDataSource, unregisterDataSource, listDataSources, listDatasets, } from '../data/data-registry';
|
|
31
31
|
export { buildDataGuideMarkdown } from '../data/data-guide.builder';
|
|
32
32
|
export { queryRows } from '../data/row-executor';
|
|
33
|
+
export type { ChartSpec, ChartSeries, ChartType, ChartValueFormat } from '../charts/chart.types';
|
|
34
|
+
export { CHART_BLOCK_LANGUAGE, CHART_TYPES } from '../charts/chart.types';
|
|
35
|
+
export { validateChart } from '../charts/chart-validation';
|
|
36
|
+
export type { ChartValidation } from '../charts/chart-validation';
|
|
37
|
+
export { renderChartSvg, formatChartValue } from '../charts/chart-svg';
|
|
33
38
|
export { PackService } from '../packs/pack.service';
|
|
34
39
|
export type { PackView } from '../packs/pack.service';
|
|
35
40
|
export { PackInstantiationService } from '../packs/pack-instantiation.service';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.formatChartValue = exports.renderChartSvg = exports.validateChart = exports.CHART_TYPES = exports.CHART_BLOCK_LANGUAGE = exports.queryRows = exports.buildDataGuideMarkdown = exports.listDatasets = exports.listDataSources = exports.unregisterDataSource = exports.registerDataSource = exports.MAX_ROW_LIMIT = exports.DEFAULT_ROW_LIMIT = exports.NativeToolRegistry = exports.availableToolPacks = exports.registerToolPacks = exports.installToolPacks = exports.dnd5eTools = exports.buildMarkdown = exports.pageMarker = exports.stripWrappingFence = exports.splitMarkdownIntoPages = exports.libraryDocumentIdOf = exports.isLibraryAttachment = exports.libraryAttachmentName = exports.DEFAULT_EMBEDDING_MODEL = exports.EMBEDDING_DIMENSIONS = exports.embedTexts = exports.DEFAULT_CHUNK_OVERLAP_CHARS = exports.DEFAULT_CHUNK_MAX_CHARS = exports.embeddingInput = exports.chunkPages = exports.buildDocumentGuideMarkdown = exports.listDocumentSources = exports.unregisterDocumentSource = exports.registerDocumentSource = exports.insufficientBalanceMessage = exports.setInsufficientBalanceMessage = exports.InsufficientBalanceError = exports.currentUsageTags = exports.runWithUsageTags = exports.MAX_ATTACHED_IMAGE_BYTES = exports.ATTACHMENT_IMAGE_TYPES = exports.isAttachmentImage = exports.detectAttachmentMimeType = exports.UnsupportedDocumentError = exports.convertLocalDocument = exports.detectDocumentType = exports.BriyahConfigService = exports.Briyah = void 0;
|
|
4
|
+
exports.RoomMessage = exports.Room = exports.Agent = exports.PackInstantiationService = exports.PackService = void 0;
|
|
4
5
|
// Main SDK exports
|
|
5
6
|
var briyah_1 = require("./briyah");
|
|
6
7
|
Object.defineProperty(exports, "Briyah", { enumerable: true, get: function () { return briyah_1.Briyah; } });
|
|
@@ -94,6 +95,14 @@ Object.defineProperty(exports, "buildDataGuideMarkdown", { enumerable: true, get
|
|
|
94
95
|
// ordering semantics as every other host.
|
|
95
96
|
var row_executor_1 = require("../data/row-executor");
|
|
96
97
|
Object.defineProperty(exports, "queryRows", { enumerable: true, get: function () { return row_executor_1.queryRows; } });
|
|
98
|
+
var chart_types_1 = require("../charts/chart.types");
|
|
99
|
+
Object.defineProperty(exports, "CHART_BLOCK_LANGUAGE", { enumerable: true, get: function () { return chart_types_1.CHART_BLOCK_LANGUAGE; } });
|
|
100
|
+
Object.defineProperty(exports, "CHART_TYPES", { enumerable: true, get: function () { return chart_types_1.CHART_TYPES; } });
|
|
101
|
+
var chart_validation_1 = require("../charts/chart-validation");
|
|
102
|
+
Object.defineProperty(exports, "validateChart", { enumerable: true, get: function () { return chart_validation_1.validateChart; } });
|
|
103
|
+
var chart_svg_1 = require("../charts/chart-svg");
|
|
104
|
+
Object.defineProperty(exports, "renderChartSvg", { enumerable: true, get: function () { return chart_svg_1.renderChartSvg; } });
|
|
105
|
+
Object.defineProperty(exports, "formatChartValue", { enumerable: true, get: function () { return chart_svg_1.formatChartValue; } });
|
|
97
106
|
// Packs: a domain's prompt folders, documents, tools and templates, installed for
|
|
98
107
|
// everyone and enabled per user.
|
|
99
108
|
//
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NativeToolDefinition } from '../native-tool.types';
|
|
2
|
+
/**
|
|
3
|
+
* Turns numbers into a chart an application can draw exactly.
|
|
4
|
+
*
|
|
5
|
+
* The agent describes the chart as data; the tool checks it and hands back the
|
|
6
|
+
* ```chart block to put in a message or a document, where the host draws it with
|
|
7
|
+
* `renderChartSvg`. Checking here is the point: a chart written straight into a
|
|
8
|
+
* document with a typo would just fail to draw, and the agent would never know.
|
|
9
|
+
* Drawn once here too, so a spec that validates but cannot be drawn is caught in
|
|
10
|
+
* the same turn.
|
|
11
|
+
*
|
|
12
|
+
* Never an image model's job: asked for a chart, one draws a plausible picture
|
|
13
|
+
* with numbers of its own.
|
|
14
|
+
*/
|
|
15
|
+
export declare const makeChartTool: NativeToolDefinition;
|