@akohn/dashql 0.0.19-dev.247 → 0.0.19-dev.261.g8742d37fb
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/dist/platform/session/agent_session_client.d.ts +6 -0
- package/dist/platform/session/agent_session_protocol.d.ts +1 -1
- package/dist/platform/session/agent_session_protocol.js +4 -4
- package/dist/platform/workbook/chart_config.d.ts +35 -0
- package/dist/platform/workbook/chart_config.js +222 -0
- package/dist/platform/workbook/run_events.d.ts +7 -0
- package/dist/platform/workbook/run_events.js +16 -0
- package/dist/wasm/dashql_core.d.ts +1407 -1400
- package/dist/wasm/dashql_core.js +51 -33
- package/dist/wasm/dashql_core.wasm +0 -0
- package/package.json +1 -1
|
@@ -12,6 +12,12 @@ export interface AgentSessionRunRequest {
|
|
|
12
12
|
scripts: string[];
|
|
13
13
|
refresh: boolean;
|
|
14
14
|
rows: number;
|
|
15
|
+
chart?: AgentSessionChartSize | null;
|
|
16
|
+
}
|
|
17
|
+
export interface AgentSessionChartSize {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
scale: number;
|
|
15
21
|
}
|
|
16
22
|
export type AgentSessionRunMessage = ({
|
|
17
23
|
type: 'run';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const AGENT_SESSION_PROTOCOL =
|
|
1
|
+
export declare const AGENT_SESSION_PROTOCOL = 2;
|
|
2
2
|
export declare const AGENT_SESSION_MIN_PROTOCOL = 1;
|
|
3
3
|
export declare const AGENT_SESSION_PROTOCOL_HEADER = "X-DashQL-Protocol";
|
|
4
4
|
export declare const AGENT_SESSION_MIN_PROTOCOL_HEADER = "X-DashQL-Min-Protocol";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// dist/.stage/src/platform/session/agent_session_protocol.ts
|
|
2
|
-
var AGENT_SESSION_PROTOCOL =
|
|
2
|
+
var AGENT_SESSION_PROTOCOL = 2;
|
|
3
3
|
var AGENT_SESSION_MIN_PROTOCOL = 1;
|
|
4
4
|
var AGENT_SESSION_PROTOCOL_HEADER = "X-DashQL-Protocol";
|
|
5
5
|
var AGENT_SESSION_MIN_PROTOCOL_HEADER = "X-DashQL-Min-Protocol";
|
|
@@ -7,7 +7,7 @@ var AgentSessionProtocolError = class extends Error {
|
|
|
7
7
|
outdated;
|
|
8
8
|
serverProtocol;
|
|
9
9
|
constructor(outdated, serverProtocol) {
|
|
10
|
-
super(outdated === "server" ? `the server of the session speaks protocol ${serverProtocol ?? "none"}, this client needs 1 or newer: update dashql-cli` : `the server of the session speaks protocol ${serverProtocol ?? "none"} and needs a newer client than protocol
|
|
10
|
+
super(outdated === "server" ? `the server of the session speaks protocol ${serverProtocol ?? "none"}, this client needs 1 or newer: update dashql-cli` : `the server of the session speaks protocol ${serverProtocol ?? "none"} and needs a newer client than protocol 2`);
|
|
11
11
|
this.outdated = outdated;
|
|
12
12
|
this.serverProtocol = serverProtocol;
|
|
13
13
|
this.name = "AgentSessionProtocolError";
|
|
@@ -22,7 +22,7 @@ function serverAcceptsAgentSessionClient(clientProtocol) {
|
|
|
22
22
|
}
|
|
23
23
|
function outdatedAgentSessionSide(serverProtocol, serverMinProtocol) {
|
|
24
24
|
if (serverProtocol == null || serverMinProtocol == null || serverProtocol < 1) return "server";
|
|
25
|
-
if (
|
|
25
|
+
if (2 < serverMinProtocol) return "client";
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
function checkAgentSessionAnswer(response) {
|
|
@@ -32,7 +32,7 @@ function checkAgentSessionAnswer(response) {
|
|
|
32
32
|
}
|
|
33
33
|
async function fetchAgentSession(input, init = {}, send = fetch) {
|
|
34
34
|
const headers = new Headers(init.headers);
|
|
35
|
-
headers.set(AGENT_SESSION_PROTOCOL_HEADER, String(
|
|
35
|
+
headers.set(AGENT_SESSION_PROTOCOL_HEADER, String(2));
|
|
36
36
|
const response = await send(input, {
|
|
37
37
|
...init,
|
|
38
38
|
headers
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Config, TopLevelSpec } from 'vega-lite';
|
|
2
|
+
export interface ChartColors {
|
|
3
|
+
categorical: string[];
|
|
4
|
+
primary: string;
|
|
5
|
+
critical: string;
|
|
6
|
+
grid: string;
|
|
7
|
+
label: string;
|
|
8
|
+
title: string;
|
|
9
|
+
text: string;
|
|
10
|
+
surface: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const LIGHT_CHART_COLORS: ChartColors;
|
|
13
|
+
export declare const CHART_FALLBACK_FONT = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif";
|
|
14
|
+
export declare function createChartConfig(colors: ChartColors, font: string): Config;
|
|
15
|
+
export declare const CHART_IMAGE_WIDTH = 800;
|
|
16
|
+
export declare const CHART_IMAGE_HEIGHT = 500;
|
|
17
|
+
export declare const CHART_IMAGE_SCALE = 2;
|
|
18
|
+
export declare const CHART_IMAGE_BACKGROUND = "#ffffff";
|
|
19
|
+
export declare const CHART_IMAGE_PADDING = 16;
|
|
20
|
+
export declare function chartImageSpec(spec: TopLevelSpec, rows: readonly object[], width: number, height: number): TopLevelSpec;
|
|
21
|
+
export declare function chartImageConfig(config: Config): Config;
|
|
22
|
+
export declare function withViewEncodings<T>(spec: T): T;
|
|
23
|
+
export declare function chartSpecProblems(spec: Record<string, unknown>, columns: readonly string[] | null): string[];
|
|
24
|
+
interface VegaLiteLogger {
|
|
25
|
+
level(): VegaLiteLogger;
|
|
26
|
+
error(...message: unknown[]): VegaLiteLogger;
|
|
27
|
+
warn(...message: unknown[]): VegaLiteLogger;
|
|
28
|
+
info(...message: unknown[]): VegaLiteLogger;
|
|
29
|
+
debug(...message: unknown[]): VegaLiteLogger;
|
|
30
|
+
}
|
|
31
|
+
export type VegaLiteCompile = (spec: TopLevelSpec, options: {
|
|
32
|
+
logger: VegaLiteLogger;
|
|
33
|
+
}) => unknown;
|
|
34
|
+
export declare function compileProblems(compile: VegaLiteCompile, spec: Record<string, unknown>): string[];
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { stringifyError } from "../logger/logger.js";
|
|
2
|
+
// dist/.stage/src/platform/workbook/chart_config.ts
|
|
3
|
+
var LIGHT_CHART_COLORS = {
|
|
4
|
+
categorical: [
|
|
5
|
+
"#0969da",
|
|
6
|
+
"#e16f24",
|
|
7
|
+
"#8250df",
|
|
8
|
+
"#1a7f37",
|
|
9
|
+
"#e85aad",
|
|
10
|
+
"#bf8700",
|
|
11
|
+
"#54aeff",
|
|
12
|
+
"#953800"
|
|
13
|
+
],
|
|
14
|
+
primary: "#0969da",
|
|
15
|
+
critical: "#cf222e",
|
|
16
|
+
grid: "#eaeef2",
|
|
17
|
+
label: "#6e7781",
|
|
18
|
+
title: "#57606a",
|
|
19
|
+
text: "#24292f",
|
|
20
|
+
surface: "#ffffff"
|
|
21
|
+
};
|
|
22
|
+
var CHART_FALLBACK_FONT = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif";
|
|
23
|
+
function createChartConfig(colors, font) {
|
|
24
|
+
return {
|
|
25
|
+
background: "transparent",
|
|
26
|
+
font,
|
|
27
|
+
padding: 0,
|
|
28
|
+
view: { stroke: null },
|
|
29
|
+
range: { category: colors.categorical },
|
|
30
|
+
mark: { color: colors.primary },
|
|
31
|
+
bar: {
|
|
32
|
+
cornerRadius: 0,
|
|
33
|
+
binSpacing: 1,
|
|
34
|
+
continuousBandSize: 2
|
|
35
|
+
},
|
|
36
|
+
line: {
|
|
37
|
+
strokeWidth: 2,
|
|
38
|
+
strokeCap: "round",
|
|
39
|
+
strokeJoin: "round"
|
|
40
|
+
},
|
|
41
|
+
area: { line: false },
|
|
42
|
+
point: {
|
|
43
|
+
filled: true,
|
|
44
|
+
size: 50,
|
|
45
|
+
stroke: colors.surface,
|
|
46
|
+
strokeWidth: 2,
|
|
47
|
+
opacity: 1
|
|
48
|
+
},
|
|
49
|
+
rule: {
|
|
50
|
+
color: colors.title,
|
|
51
|
+
strokeWidth: 1
|
|
52
|
+
},
|
|
53
|
+
tick: { thickness: 2 },
|
|
54
|
+
text: {
|
|
55
|
+
color: colors.text,
|
|
56
|
+
fontSize: 11
|
|
57
|
+
},
|
|
58
|
+
axis: {
|
|
59
|
+
domain: false,
|
|
60
|
+
ticks: false,
|
|
61
|
+
grid: true,
|
|
62
|
+
gridColor: colors.grid,
|
|
63
|
+
gridWidth: 1,
|
|
64
|
+
labelColor: colors.label,
|
|
65
|
+
labelFontSize: 10,
|
|
66
|
+
labelPadding: 6,
|
|
67
|
+
titleColor: colors.title,
|
|
68
|
+
titleFontSize: 11,
|
|
69
|
+
titleFontWeight: 500,
|
|
70
|
+
titlePadding: 8
|
|
71
|
+
},
|
|
72
|
+
axisX: {
|
|
73
|
+
grid: false,
|
|
74
|
+
labelFlush: true,
|
|
75
|
+
labelOverlap: true
|
|
76
|
+
},
|
|
77
|
+
axisBand: { grid: false },
|
|
78
|
+
legend: {
|
|
79
|
+
labelColor: colors.label,
|
|
80
|
+
labelFontSize: 11,
|
|
81
|
+
titleColor: colors.title,
|
|
82
|
+
titleFontSize: 11,
|
|
83
|
+
titleFontWeight: 500,
|
|
84
|
+
symbolSize: 64,
|
|
85
|
+
symbolStrokeWidth: 0
|
|
86
|
+
},
|
|
87
|
+
header: {
|
|
88
|
+
labelColor: colors.title,
|
|
89
|
+
titleColor: colors.title,
|
|
90
|
+
labelFontSize: 11,
|
|
91
|
+
titleFontSize: 11
|
|
92
|
+
},
|
|
93
|
+
title: {
|
|
94
|
+
color: colors.text,
|
|
95
|
+
fontSize: 13,
|
|
96
|
+
fontWeight: 600,
|
|
97
|
+
anchor: "start",
|
|
98
|
+
offset: 8
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var CHART_IMAGE_WIDTH = 800;
|
|
103
|
+
var CHART_IMAGE_HEIGHT = 500;
|
|
104
|
+
var CHART_IMAGE_SCALE = 2;
|
|
105
|
+
var CHART_IMAGE_BACKGROUND = "#ffffff";
|
|
106
|
+
var CHART_IMAGE_PADDING = 16;
|
|
107
|
+
function chartImageSpec(spec, rows, width, height) {
|
|
108
|
+
return {
|
|
109
|
+
...withViewEncodings(spec),
|
|
110
|
+
data: { values: rows },
|
|
111
|
+
width,
|
|
112
|
+
height,
|
|
113
|
+
autosize: {
|
|
114
|
+
type: "fit",
|
|
115
|
+
contains: "padding"
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function chartImageConfig(config) {
|
|
120
|
+
return {
|
|
121
|
+
...config,
|
|
122
|
+
background: CHART_IMAGE_BACKGROUND,
|
|
123
|
+
padding: 16
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
var VIEW_LIST_KEYS = [
|
|
127
|
+
"layer",
|
|
128
|
+
"concat",
|
|
129
|
+
"hconcat",
|
|
130
|
+
"vconcat"
|
|
131
|
+
];
|
|
132
|
+
function isObject(value) {
|
|
133
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
134
|
+
}
|
|
135
|
+
function withViewEncodings(spec) {
|
|
136
|
+
if (!isObject(spec)) return spec;
|
|
137
|
+
let out = null;
|
|
138
|
+
const set = (key, value) => {
|
|
139
|
+
out ??= { ...spec };
|
|
140
|
+
out[key] = value;
|
|
141
|
+
};
|
|
142
|
+
if ("mark" in spec && !isObject(spec.encoding)) set("encoding", {});
|
|
143
|
+
for (const key of VIEW_LIST_KEYS) {
|
|
144
|
+
const views = spec[key];
|
|
145
|
+
if (!Array.isArray(views)) continue;
|
|
146
|
+
const next = views.map(withViewEncodings);
|
|
147
|
+
if (next.some((view, i) => view !== views[i])) set(key, next);
|
|
148
|
+
}
|
|
149
|
+
if (isObject(spec.spec)) {
|
|
150
|
+
const view = withViewEncodings(spec.spec);
|
|
151
|
+
if (view !== spec.spec) set("spec", view);
|
|
152
|
+
}
|
|
153
|
+
return out ?? spec;
|
|
154
|
+
}
|
|
155
|
+
var SIZE_KEYS = [
|
|
156
|
+
"width",
|
|
157
|
+
"height",
|
|
158
|
+
"autosize",
|
|
159
|
+
"padding"
|
|
160
|
+
];
|
|
161
|
+
function collectFields(spec, read, made) {
|
|
162
|
+
if (Array.isArray(spec)) {
|
|
163
|
+
for (const item of spec) collectFields(item, read, made);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!isObject(spec)) return;
|
|
167
|
+
if (Array.isArray(spec.transform)) for (const transform of spec.transform) {
|
|
168
|
+
if (!isObject(transform)) continue;
|
|
169
|
+
const outputs = [transform.as, ...[
|
|
170
|
+
"aggregate",
|
|
171
|
+
"window",
|
|
172
|
+
"joinaggregate"
|
|
173
|
+
].flatMap((key) => Array.isArray(transform[key]) ? transform[key].map((op) => isObject(op) ? op.as : null) : [])];
|
|
174
|
+
for (const output of outputs.flat()) if (typeof output === "string") made.add(output);
|
|
175
|
+
}
|
|
176
|
+
if (isObject(spec.encoding)) for (const channel of Object.values(spec.encoding)) for (const definition of Array.isArray(channel) ? channel : [channel]) {
|
|
177
|
+
if (!isObject(definition)) continue;
|
|
178
|
+
if (typeof definition.field === "string") read.add(definition.field);
|
|
179
|
+
const condition = definition.condition;
|
|
180
|
+
for (const branch of Array.isArray(condition) ? condition : [condition]) if (isObject(branch) && typeof branch.field === "string") read.add(branch.field);
|
|
181
|
+
}
|
|
182
|
+
for (const key of [...VIEW_LIST_KEYS, "spec"]) collectFields(spec[key], read, made);
|
|
183
|
+
}
|
|
184
|
+
function chartSpecProblems(spec, columns) {
|
|
185
|
+
const problems = [];
|
|
186
|
+
const sizes = SIZE_KEYS.filter((key) => key in spec);
|
|
187
|
+
if (sizes.length > 0) problems.push(`leave the size to DashQL, it fits every chart to its card: remove ${sizes.join(", ")}`);
|
|
188
|
+
if (columns != null) {
|
|
189
|
+
const read = /* @__PURE__ */ new Set();
|
|
190
|
+
const made = /* @__PURE__ */ new Set();
|
|
191
|
+
collectFields(spec, read, made);
|
|
192
|
+
const known = new Set(columns);
|
|
193
|
+
const missing = [...read].filter((field) => !made.has(field) && !known.has(field) && !known.has(field.split(/(?<!\\)[.[]/)[0].replace(/\\(.)/g, "$1")));
|
|
194
|
+
for (const field of missing) problems.push(`the field ${JSON.stringify(field)} is no column of the result, its columns are ${columns.join(", ") || "none"}`);
|
|
195
|
+
}
|
|
196
|
+
return problems;
|
|
197
|
+
}
|
|
198
|
+
function compileProblems(compile, spec) {
|
|
199
|
+
const problems = [];
|
|
200
|
+
const text = (message) => typeof message === "string" ? message : stringifyError(message);
|
|
201
|
+
const collect = (...message) => {
|
|
202
|
+
problems.push(message.map(text).join(" "));
|
|
203
|
+
return logger;
|
|
204
|
+
};
|
|
205
|
+
const logger = {
|
|
206
|
+
level: () => logger,
|
|
207
|
+
error: collect,
|
|
208
|
+
warn: collect,
|
|
209
|
+
info: () => logger,
|
|
210
|
+
debug: () => logger
|
|
211
|
+
};
|
|
212
|
+
try {
|
|
213
|
+
compile({
|
|
214
|
+
...withViewEncodings(spec),
|
|
215
|
+
data: { values: [] }
|
|
216
|
+
}, { logger });
|
|
217
|
+
} catch (e) {
|
|
218
|
+
problems.push(text(e));
|
|
219
|
+
}
|
|
220
|
+
return problems;
|
|
221
|
+
}
|
|
222
|
+
export { CHART_FALLBACK_FONT, CHART_IMAGE_BACKGROUND, CHART_IMAGE_HEIGHT, CHART_IMAGE_PADDING, CHART_IMAGE_SCALE, CHART_IMAGE_WIDTH, LIGHT_CHART_COLORS, chartImageConfig, chartImageSpec, chartSpecProblems, compileProblems, createChartConfig, withViewEncodings };
|
|
@@ -53,6 +53,13 @@ export type RunEvent = {
|
|
|
53
53
|
} | {
|
|
54
54
|
type: 'run_failed';
|
|
55
55
|
error: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'script_chart';
|
|
58
|
+
script: string;
|
|
59
|
+
png: Uint8Array | null;
|
|
60
|
+
width: number | null;
|
|
61
|
+
height: number | null;
|
|
62
|
+
error: string | null;
|
|
56
63
|
} | {
|
|
57
64
|
type: 'run_finished';
|
|
58
65
|
ms: number;
|
|
@@ -13,6 +13,10 @@ function toBase64(bytes) {
|
|
|
13
13
|
return btoa(binary);
|
|
14
14
|
}
|
|
15
15
|
function encodeRunEvent(event, rows) {
|
|
16
|
+
if (event.type === "script_chart") return {
|
|
17
|
+
...event,
|
|
18
|
+
png: event.png == null ? null : toBase64(event.png)
|
|
19
|
+
};
|
|
16
20
|
if (event.type !== "script_done") return event;
|
|
17
21
|
const table = event.table == null ? null : toBase64(arrow.tableToIPC(event.table.slice(0, rows), "stream"));
|
|
18
22
|
return {
|
|
@@ -23,6 +27,18 @@ function encodeRunEvent(event, rows) {
|
|
|
23
27
|
function decodeRunEvent(value) {
|
|
24
28
|
if (value == null || typeof value !== "object" || typeof value.type !== "string") return null;
|
|
25
29
|
const event = value;
|
|
30
|
+
if (event.type === "script_chart") {
|
|
31
|
+
let png = null;
|
|
32
|
+
try {
|
|
33
|
+
png = typeof event.png === "string" ? fromBase64(event.png) : null;
|
|
34
|
+
} catch {
|
|
35
|
+
png = null;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
...event,
|
|
39
|
+
png
|
|
40
|
+
};
|
|
41
|
+
}
|
|
26
42
|
if (event.type !== "script_done") return event;
|
|
27
43
|
let table = null;
|
|
28
44
|
if (typeof event.table === "string") try {
|