Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | 2209x 2209x 8x 8x 8x 2209x 3x 3x 2209x 9x 9x 9x 2209x 8x 8x 8x 2209x 4x 4x 4x 2209x 3x 3x 3x 2209x 3x 3x 2209x 3x 3x 3x 2209x 3x 3x 3x 2209x 3x 3x 3x 2209x 3x 3x 3x 2209x 3x 3x 2209x 3x 3x 3x 2209x 3x 3x 3x 2209x 3x 3x 3x 3x 2209x 13x 2209x 3x 3x 3x 2209x 3x 3x 3x | import {
CreateDashboardBody,
CreateWidgetBody,
Dashboard,
DashboardWidget,
DashboardWithWidgets,
GenerationProposal,
MessageListTarget,
SaveMessageBody,
WidgetPlacement,
WidgetTypeSpec,
} from "@/objects/Dashboard";
import { Dictionary } from "@/types/ext";
import { dispositionFilename, saveBlob } from "@/util/download";
import { AxiosRequestConfig } from "axios";
import { HistoricalAPIRouter } from "../HistoricalApiRouter";
/** Client for /app/dashboards — user-composed boards of widgets.
*
* Reading a board is what drives automations: the backend returns cached
* widget results immediately and queues a regeneration for anything past its
* refresh interval, flagging `refreshing` so the caller knows to poll. */
export class DashboardRouter extends HistoricalAPIRouter {
constructor(
host: string,
token: string | null = null,
default_config: AxiosRequestConfig | null = null,
headers: Dictionary<string> = {},
) {
super("dashboards", host, token, default_config, headers);
}
/** The widget types the backend can render, for the widget picker. */
widgetTypes = async (): Promise<WidgetTypeSpec[]> => {
const res = await this.api.get<WidgetTypeSpec[]>(
this.endpoint("widget-types"),
);
Eif (super.validRes(res)) {
return res.data;
}
return [];
};
/** Compose a dashboard from a description. Creates nothing — the proposal
* is reviewed and then posted to `create` like any other board. */
generate = async (
description: string,
aiModelId?: string,
): Promise<GenerationProposal> => {
// Designing a whole board is a single long LLM call; spread the default
// config so withCredentials survives the per-request timeout override.
const res = await this.api.post<GenerationProposal>(
this.endpoint("generate"),
{ description, ai_model_id: aiModelId ?? null },
{ ...(this.api.default_config ?? {}), timeout: 180000 },
);
return res.data;
};
/** `includeSystem` adds the built-in boards after the user's own — for the
* Dashboards page; counts of "your boards" leave it off. */
list = async ({
includeSystem = false,
}: { includeSystem?: boolean } = {}): Promise<Dashboard[]> => {
const res = await this.api.get<Dashboard[]>(
this.prefix,
includeSystem ? { params: { include_system: true } } : undefined,
);
Eif (super.validRes(res)) {
return res.data;
}
return [];
};
getById = async (id: string): Promise<DashboardWithWidgets | null> => {
const res = await this.api.get<DashboardWithWidgets>(this.endpoint(id));
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
create = async (
body: CreateDashboardBody,
): Promise<DashboardWithWidgets | null> => {
const res = await this.api.post<DashboardWithWidgets>(this.prefix, body);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
update = async (
id: string,
body: {
name?: string;
description?: string | null;
icon?: string | null;
accent?: string | null;
position?: number;
},
): Promise<Dashboard | null> => {
const res = await this.api.patch<Dashboard>(this.endpoint(id), body);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
delete = async (id: string): Promise<boolean> => {
const res = await this.api.delete(this.endpoint(id));
return res.status === 204;
};
/** Promote a board to home, demoting whichever held the flag. */
setHome = async (id: string): Promise<Dashboard | null> => {
const res = await this.api.post<Dashboard>(this.endpoint(`${id}/home`), {});
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
/** Every saved-messages widget the user can save a chat answer into. */
messageLists = async (): Promise<MessageListTarget[]> => {
const res = await this.api.get<MessageListTarget[]>(
this.endpoint("message-lists"),
);
Eif (super.validRes(res)) {
return res.data;
}
return [];
};
// ── Widgets ────────────────────────────────────────────────────────────────
addWidget = async (
dashboardId: string,
body: CreateWidgetBody,
): Promise<DashboardWidget | null> => {
const res = await this.api.post<DashboardWidget>(
this.endpoint(`${dashboardId}/widgets`),
body,
);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
updateWidget = async (
dashboardId: string,
widgetId: string,
body: Partial<CreateWidgetBody>,
): Promise<DashboardWidget | null> => {
const res = await this.api.patch<DashboardWidget>(
this.endpoint(`${dashboardId}/widgets/${widgetId}`),
body,
);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
deleteWidget = async (
dashboardId: string,
widgetId: string,
): Promise<boolean> => {
const res = await this.api.delete(
this.endpoint(`${dashboardId}/widgets/${widgetId}`),
);
return res.status === 204;
};
/** Persist the whole grid after a drag or resize, in one write. */
saveLayout = async (
dashboardId: string,
placements: WidgetPlacement[],
): Promise<DashboardWidget[]> => {
const res = await this.api.put<DashboardWidget[]>(
this.endpoint(`${dashboardId}/layout`),
{ placements },
);
Eif (super.validRes(res)) {
return res.data;
}
return [];
};
/** Force a dynamic widget to regenerate, ignoring its interval. */
refreshWidget = async (
dashboardId: string,
widgetId: string,
): Promise<DashboardWidget | null> => {
const res = await this.api.post<DashboardWidget>(
this.endpoint(`${dashboardId}/widgets/${widgetId}/refresh`),
{},
);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
/** Download a tile's latest answer as a PDF, rendered by svc-core from
* what the tile stored — the `index`-th document in it, or with the
* tile's PDF on, the answer laid out. Resolves false when it failed. */
downloadWidgetDocument = async (
dashboardId: string,
widgetId: string,
index = 0,
fallbackName = "document.pdf",
): Promise<boolean> => {
const res = await this.api
.get(
this.endpoint(`${dashboardId}/widgets/${widgetId}/document.pdf`, {
index,
}),
{ responseType: "blob", withCredentials: true },
)
.catch(() => null);
Iif (res?.status !== 200) return false;
saveBlob(
res.data as Blob,
dispositionFilename(res.headers?.["content-disposition"]) ?? fallbackName,
);
return true;
};
/** Where an image a tile's document shows is served: the copy svc-ai
* stored when it made the document, named by its hash (an `<img src>`). */
widgetImageUrl = (
dashboardId: string,
widgetId: string,
asset: string,
): string =>
this.api.endpoint(
this.endpoint(
`${dashboardId}/widgets/${widgetId}/images/${encodeURIComponent(asset)}`,
),
);
// ── Saved-message items ────────────────────────────────────────────────────
//
// Appending is a server-side operation rather than a config rewrite, so the
// caller never has to read the widget first and two saves cannot clobber
// one another.
saveMessage = async (
dashboardId: string,
widgetId: string,
body: SaveMessageBody,
): Promise<DashboardWidget | null> => {
const res = await this.api.post<DashboardWidget>(
this.endpoint(`${dashboardId}/widgets/${widgetId}/items`),
body,
);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
deleteSavedMessage = async (
dashboardId: string,
widgetId: string,
itemId: string,
): Promise<DashboardWidget | null> => {
const res = await this.api.delete(
this.endpoint(`${dashboardId}/widgets/${widgetId}/items/${itemId}`),
);
Eif (super.validRes(res)) {
return res.data as DashboardWidget;
}
return null;
};
}
|