@senselab-ai/sensei 0.0.0-stage → 0.2.0

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/client.js ADDED
@@ -0,0 +1,623 @@
1
+ /**
2
+ * The client for Sensei runs: a thin wrapper over `/v1/runs`, `/v1/agents`,
3
+ * `/v1/tools`, `/v1/repos` and `/v1/schedules`, and over `/v1/model` for the
4
+ * project's own trained model. Every method returns the API's JSON as it
5
+ * is; `runs.events` yields events as they happen. `Sensei` (run.ts) is the
6
+ * short way to run something and read the result.
7
+ */
8
+ import { readFileSync } from "node:fs";
9
+ import { homedir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { Evals } from "./evals.js";
12
+ import { VERSION } from "./version.js";
13
+ export const DEFAULT_URL = "https://runs.sense-lab.ai";
14
+ /** Which version made the request. */
15
+ const USER_AGENT = `sensei-js/${VERSION}`;
16
+ /** Where a call came from, as the service records it. */
17
+ const THROUGH = "sdk-js";
18
+ /** A run in one of these has stopped moving until someone acts (or for good). */
19
+ export const SETTLED = ["verified", "done", "unverified", "failed", "cancelled", "waiting"];
20
+ /**
21
+ * A project's model in one of these stays there until someone acts or new
22
+ * work arrives: what `model.wait` waits for unless told otherwise.
23
+ */
24
+ export const MODEL_SETTLED = ["waiting", "live", "no_room", "taken_off", "on_hold"];
25
+ export class SenseiError extends Error {
26
+ /** The HTTP status, or 0 when the call was never made. */
27
+ status;
28
+ code;
29
+ constructor(status, message, code) {
30
+ super(message);
31
+ this.name = "SenseiError";
32
+ this.status = status;
33
+ this.code = code;
34
+ }
35
+ }
36
+ // --------------------------------------------------------------------------
37
+ // The key and the address
38
+ // --------------------------------------------------------------------------
39
+ /** Where `sensei login` (the command) keeps the key. */
40
+ export function configPath() {
41
+ return join(homedir(), ".config", "sensei", "config.json");
42
+ }
43
+ function readConfig() {
44
+ try {
45
+ const doc = JSON.parse(readFileSync(configPath(), "utf8"));
46
+ if (typeof doc !== "object" || doc === null)
47
+ return {};
48
+ return Object.fromEntries(Object.entries(doc).filter((kv) => typeof kv[1] === "string"));
49
+ }
50
+ catch {
51
+ return {};
52
+ }
53
+ }
54
+ /**
55
+ * Explicit argument, then environment, then `~/.config/sensei/config.json`
56
+ * (written by `sensei login`). The file is read only when it is needed.
57
+ */
58
+ export function resolveConfig(baseUrl, apiKey) {
59
+ let saved;
60
+ const fromFile = (name) => (saved ??= readConfig())[name];
61
+ const env = process.env;
62
+ const url = (baseUrl || env.SENSEI_RUNS_URL || fromFile("url") || DEFAULT_URL).trim().replace(/\/+$/, "");
63
+ const key = (apiKey || env.SENSEI_API_KEY || env.SENSELAB_API_KEY || fromFile("api_key") || "").trim();
64
+ if (!key) {
65
+ throw new SenseiError(0, "No API key. Run `sensei login`, or set SENSEI_API_KEY (create a key on the Access management page).", "no_api_key");
66
+ }
67
+ return { baseUrl: url, apiKey: key };
68
+ }
69
+ function isMapping(value) {
70
+ return typeof value === "object" && value !== null && !Array.isArray(value);
71
+ }
72
+ /** Whether there is something in it: not null, false, 0, "", [] or {}. */
73
+ function filled(value) {
74
+ if (Array.isArray(value))
75
+ return value.length > 0;
76
+ if (isMapping(value))
77
+ return Object.keys(value).length > 0;
78
+ return Boolean(value);
79
+ }
80
+ function failed(status) {
81
+ return status < 200 || status >= 300;
82
+ }
83
+ /** The error the service sent: `{error: {message, code}}`. */
84
+ function errorOf(status, text, otherwise) {
85
+ let err = {};
86
+ try {
87
+ const doc = JSON.parse(text);
88
+ if (isMapping(doc) && isMapping(doc.error))
89
+ err = doc.error;
90
+ }
91
+ catch {
92
+ // Not JSON: the text is all there is.
93
+ }
94
+ const message = typeof err.message === "string" && err.message ? err.message : otherwise;
95
+ return new SenseiError(status, message, typeof err.code === "string" ? err.code : undefined);
96
+ }
97
+ const seg = encodeURIComponent;
98
+ const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
99
+ export class Client {
100
+ baseUrl;
101
+ runs;
102
+ agents;
103
+ tools;
104
+ /** What the project's runs are given by name: plain settings, and secrets for setup. */
105
+ settings;
106
+ repos;
107
+ schedules;
108
+ model;
109
+ /** The end-to-end check: saved tasks on two versions of the model (evals.ts). */
110
+ evals;
111
+ #key;
112
+ #fetch;
113
+ #through;
114
+ constructor(options = {}) {
115
+ const config = resolveConfig(options.baseUrl, options.apiKey);
116
+ this.baseUrl = config.baseUrl;
117
+ this.#key = config.apiKey;
118
+ this.#fetch = options.fetch ?? ((url, init) => fetch(url, init));
119
+ this.#through = options.through ?? THROUGH;
120
+ this.runs = new Runs(this);
121
+ this.agents = new Agents(this);
122
+ this.tools = new Tools(this);
123
+ this.settings = new Settings(this);
124
+ this.repos = new Repos(this);
125
+ this.schedules = new Schedules(this);
126
+ this.model = new Model(this);
127
+ this.evals = new Evals(this);
128
+ }
129
+ /** @internal The answer as it arrives, for a caller that reads the body itself. */
130
+ send(method, path, call = {}) {
131
+ const query = new URLSearchParams();
132
+ for (const [name, value] of Object.entries(call.params ?? {})) {
133
+ if (value != null)
134
+ query.set(name, String(value));
135
+ }
136
+ const search = query.toString();
137
+ const url = `${this.baseUrl}${path}${search ? `?${search}` : ""}`;
138
+ const headers = {
139
+ Authorization: `Bearer ${this.#key}`,
140
+ "User-Agent": USER_AGENT,
141
+ "x-sensei-through": this.#through,
142
+ ...call.headers,
143
+ };
144
+ const init = { method, headers };
145
+ if (call.body !== undefined) {
146
+ headers["Content-Type"] = "application/json";
147
+ init.body = JSON.stringify(call.body);
148
+ }
149
+ return this.#fetch(url, init);
150
+ }
151
+ /** One call to the API: its JSON, or a `SenseiError` when it says no. */
152
+ async request(method, path, call = {}) {
153
+ const res = await this.send(method, path, call);
154
+ const text = await res.text();
155
+ if (failed(res.status))
156
+ throw errorOf(res.status, text, text.slice(0, 300));
157
+ return (text ? JSON.parse(text) : null);
158
+ }
159
+ }
160
+ // --------------------------------------------------------------------------
161
+ // Names
162
+ // --------------------------------------------------------------------------
163
+ /**
164
+ * An option, as it is written here, to the field the API calls it. This is
165
+ * the one place a name changes; a name that is not here is the same on both
166
+ * sides.
167
+ */
168
+ const API_NAMES = {
169
+ askFirst: "ask_first",
170
+ baseRef: "base_ref",
171
+ openPr: "open_pr",
172
+ approveBeforePush: "approve_before_push",
173
+ dryRun: "dry_run",
174
+ callbackUrl: "callback_url",
175
+ testCommand: "test_command",
176
+ defaultBranch: "default_branch",
177
+ headerName: "header_name",
178
+ trialShare: "trial_share",
179
+ };
180
+ function apiName(option) {
181
+ return API_NAMES[option] ?? option;
182
+ }
183
+ /** The options of a one-off said in words: a definition's own. */
184
+ const ONE_OFF = ["tools", "askFirst", "computer", "output", "check"];
185
+ const LAUNCH = ["input", "baseRef", "attempts", "budget"];
186
+ /** What happens to a change to a repository once it is made. */
187
+ const POLICY = ["openPr", "approveBeforePush", "dryRun", "branch", "callbackUrl", "testCommand", "image"];
188
+ /** The body of `POST /v1/runs`. */
189
+ export function runBody(params) {
190
+ const body = {};
191
+ // With an agent or a definition that names no repository, `repo` is the
192
+ // repository that run works on.
193
+ if (params.repo)
194
+ body.repo = params.repo;
195
+ if (params.definition != null) {
196
+ body.definition = params.definition;
197
+ if (params.save != null)
198
+ body.save = params.save;
199
+ }
200
+ else if (params.agent) {
201
+ body.agent = params.agent;
202
+ }
203
+ else {
204
+ body.task = params.task || "";
205
+ for (const option of ONE_OFF) {
206
+ if (filled(params[option]))
207
+ body[apiName(option)] = params[option];
208
+ }
209
+ }
210
+ for (const option of LAUNCH) {
211
+ if (filled(params[option]))
212
+ body[apiName(option)] = params[option];
213
+ }
214
+ const policy = {};
215
+ for (const option of POLICY) {
216
+ if (params[option] != null)
217
+ policy[apiName(option)] = params[option];
218
+ }
219
+ if (filled(policy))
220
+ body.policy = policy;
221
+ if (params.pr != null)
222
+ body.pr = params.pr;
223
+ return body;
224
+ }
225
+ /** The fields that were given, under the API's names. */
226
+ function given(fields) {
227
+ const body = {};
228
+ for (const [option, value] of Object.entries(fields)) {
229
+ if (value !== undefined)
230
+ body[apiName(option)] = value;
231
+ }
232
+ return body;
233
+ }
234
+ /** As `given`, without what is empty. */
235
+ function nonEmpty(fields) {
236
+ return given(Object.fromEntries(Object.entries(fields).filter(([, value]) => filled(value))));
237
+ }
238
+ // --------------------------------------------------------------------------
239
+ // Runs
240
+ // --------------------------------------------------------------------------
241
+ /** The lines of a body, as they arrive: split on \n, \r\n or \r. */
242
+ async function* lines(body) {
243
+ const reader = body.getReader();
244
+ const decoder = new TextDecoder();
245
+ let buffer = "";
246
+ try {
247
+ for (;;) {
248
+ const { done, value } = await reader.read();
249
+ buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
250
+ const ending = /\r\n|\n|\r/g;
251
+ let start = 0;
252
+ for (;;) {
253
+ ending.lastIndex = start;
254
+ const hit = ending.exec(buffer);
255
+ if (hit === null)
256
+ break;
257
+ // A \r that ends a chunk may be the first half of \r\n.
258
+ if (hit[0] === "\r" && hit.index === buffer.length - 1 && !done)
259
+ break;
260
+ yield buffer.slice(start, hit.index);
261
+ start = hit.index + hit[0].length;
262
+ }
263
+ buffer = buffer.slice(start);
264
+ if (done) {
265
+ if (buffer)
266
+ yield buffer;
267
+ return;
268
+ }
269
+ }
270
+ }
271
+ finally {
272
+ // Whoever stops reading early closes the connection.
273
+ await reader.cancel().catch(() => undefined);
274
+ }
275
+ }
276
+ export class Runs {
277
+ #c;
278
+ constructor(client) {
279
+ this.#c = client;
280
+ }
281
+ /**
282
+ * Start a run. One of: `agent` (a saved agent, by name), `definition`
283
+ * (what a definition file holds), or `task` in words (with `repo` it is a
284
+ * change to that repository).
285
+ */
286
+ create(params) {
287
+ return this.#c.request("POST", "/v1/runs", { body: runBody(params) });
288
+ }
289
+ /**
290
+ * Start many changes to one repository as one batch. Each task is a run
291
+ * of its own, worked alone from the same commit. The changes that verify
292
+ * are tested together, and pull requests are opened for the ones that
293
+ * fit. It answers at once: `get` or `wait` follow it, and `result.batch`
294
+ * says how each task did alone and together.
295
+ */
296
+ batch(params) {
297
+ const { repo, tasks, together, ...rest } = params;
298
+ const body = { repo, tasks, ...nonEmpty(rest) };
299
+ if (together != null)
300
+ body.together = together;
301
+ return this.#c.request("POST", "/v1/runs", { body });
302
+ }
303
+ /**
304
+ * Test a finished batch's changes together once more, against the branch
305
+ * as it is now: after some were merged, or the branch moved. Changes
306
+ * already merged are left out.
307
+ */
308
+ checkAgain(runId) {
309
+ return this.#c.request("POST", `/v1/runs/${seg(runId)}/check`);
310
+ }
311
+ get(runId) {
312
+ return this.#c.request("GET", `/v1/runs/${seg(runId)}`);
313
+ }
314
+ async list(params = {}) {
315
+ const { status, limit = 50, agent, parent } = params;
316
+ const query = { limit };
317
+ if (status)
318
+ query.status = status;
319
+ if (agent)
320
+ query.agent = agent;
321
+ if (parent)
322
+ query.parent = parent;
323
+ return (await this.#c.request("GET", "/v1/runs", { params: query })).data;
324
+ }
325
+ /**
326
+ * The run once it has finished or has a question for a person.
327
+ * `timeoutMs` returns it as it is when the time is up.
328
+ */
329
+ async wait(runId, options = {}) {
330
+ const { timeoutMs, pollMs = 1500 } = options;
331
+ const deadline = timeoutMs != null ? performance.now() + timeoutMs : null;
332
+ for (;;) {
333
+ const run = await this.get(runId);
334
+ if (SETTLED.includes(run.status) || (deadline !== null && performance.now() >= deadline))
335
+ return run;
336
+ await sleep(pollMs);
337
+ }
338
+ }
339
+ /**
340
+ * Answer a waiting run: `approve`, `correct` (with `text`: what to do
341
+ * instead, kept for the agent's later runs) or `reject`.
342
+ */
343
+ answer(runId, decision, text) {
344
+ return this.#c.request("POST", `/v1/runs/${seg(runId)}/answer`, { body: { decision, ...nonEmpty({ text }) } });
345
+ }
346
+ /**
347
+ * Say how a finished run turned out: `right` or `wrong`. It is what
348
+ * Sensei learns from, and what the agent's numbers count.
349
+ */
350
+ outcome(runId, outcome, options = {}) {
351
+ const { note, step } = options;
352
+ return this.#c.request("POST", `/v1/runs/${seg(runId)}/outcome`, { body: nonEmpty({ outcome, note, step }) });
353
+ }
354
+ /**
355
+ * Events as they happen, until the run is done or waiting. Reconnects
356
+ * from the last event seen if the connection closes before that.
357
+ */
358
+ async *events(runId, options = {}) {
359
+ let cursor = options.after ?? 0;
360
+ for (;;) {
361
+ const res = await this.#c.send("GET", `/v1/runs/${seg(runId)}/events`, {
362
+ params: { after: cursor },
363
+ headers: { Accept: "text/event-stream" },
364
+ });
365
+ if (failed(res.status))
366
+ throw errorOf(res.status, await res.text(), "stream failed");
367
+ let ended = false;
368
+ let data = [];
369
+ if (res.body !== null) {
370
+ for await (const line of lines(res.body)) {
371
+ if (line === "") {
372
+ if (data.length > 0) {
373
+ const event = JSON.parse(data.join("\n"));
374
+ data = [];
375
+ cursor = Math.trunc(Number(event.seq)) || cursor;
376
+ yield event;
377
+ if (event.kind === "done" || event.kind === "waiting") {
378
+ ended = true;
379
+ break;
380
+ }
381
+ }
382
+ continue;
383
+ }
384
+ if (line.startsWith("data:"))
385
+ data.push(line.slice(5).trimStart());
386
+ }
387
+ }
388
+ if (ended)
389
+ return;
390
+ const run = await this.get(runId);
391
+ if (SETTLED.includes(run.status))
392
+ return;
393
+ }
394
+ }
395
+ /** Push the change a run is waiting to push (and open its pull request). */
396
+ approve(runId) {
397
+ return this.#c.request("POST", `/v1/runs/${seg(runId)}/approve`, { body: {} });
398
+ }
399
+ /** A new attempt, with what a person said. */
400
+ resume(runId, options = {}) {
401
+ return this.#c.request("POST", `/v1/runs/${seg(runId)}/resume`, { body: nonEmpty({ guidance: options.guidance }) });
402
+ }
403
+ cancel(runId) {
404
+ return this.#c.request("POST", `/v1/runs/${seg(runId)}/cancel`, { body: {} });
405
+ }
406
+ }
407
+ // --------------------------------------------------------------------------
408
+ // Repositories
409
+ // --------------------------------------------------------------------------
410
+ export class Repos {
411
+ #c;
412
+ constructor(client) {
413
+ this.#c = client;
414
+ }
415
+ async list() {
416
+ return (await this.#c.request("GET", "/v1/repos")).data;
417
+ }
418
+ connect(url, options = {}) {
419
+ const { token, defaultBranch } = options;
420
+ return this.#c.request("POST", "/v1/repos", { body: { url, ...nonEmpty({ token, defaultBranch }) } });
421
+ }
422
+ async disconnect(repoId) {
423
+ await this.#c.request("DELETE", `/v1/repos/${seg(repoId)}`);
424
+ }
425
+ }
426
+ // --------------------------------------------------------------------------
427
+ // Agents
428
+ // --------------------------------------------------------------------------
429
+ /** Definitions saved under a name, so anyone on the project runs them by name. */
430
+ export class Agents {
431
+ #c;
432
+ constructor(client) {
433
+ this.#c = client;
434
+ }
435
+ async list() {
436
+ return (await this.#c.request("GET", "/v1/agents")).data;
437
+ }
438
+ get(name, options = {}) {
439
+ const call = options.version ? { params: { version: options.version } } : {};
440
+ return this.#c.request("GET", `/v1/agents/${seg(name)}`, call);
441
+ }
442
+ async save(definition) {
443
+ const name = definition.agent;
444
+ if (!name) {
445
+ throw new SenseiError(0, "The definition needs a name: agent: refund-requests", "invalid_definition");
446
+ }
447
+ return this.#c.request("PUT", `/v1/agents/${seg(name)}`, { body: { definition } });
448
+ }
449
+ check(definition) {
450
+ return this.#c.request("POST", "/v1/agents/check", { body: { definition } });
451
+ }
452
+ async remove(name) {
453
+ await this.#c.request("DELETE", `/v1/agents/${seg(name)}`);
454
+ }
455
+ /** Take back a correction the team made. */
456
+ async forget(name, noteId) {
457
+ await this.#c.request("DELETE", `/v1/agents/${seg(name)}/notes/${seg(noteId)}`);
458
+ }
459
+ }
460
+ // --------------------------------------------------------------------------
461
+ // Tools
462
+ // --------------------------------------------------------------------------
463
+ /** The team's own systems, connected once on the project (MCP servers). */
464
+ export class Tools {
465
+ #c;
466
+ constructor(client) {
467
+ this.#c = client;
468
+ }
469
+ async list() {
470
+ return (await this.#c.request("GET", "/v1/tools")).data;
471
+ }
472
+ connect(name, url, options = {}) {
473
+ const { secret, headerName } = options;
474
+ return this.#c.request("POST", "/v1/tools", { body: nonEmpty({ name, url, secret, headerName }) });
475
+ }
476
+ async disconnect(name) {
477
+ await this.#c.request("DELETE", `/v1/tools/${seg(name)}`);
478
+ }
479
+ }
480
+ // --------------------------------------------------------------------------
481
+ // Settings and secrets
482
+ // --------------------------------------------------------------------------
483
+ /**
484
+ * What a project's runs are given by name. A setting is a plain value in
485
+ * the environment of everything a run does, and is shown. A secret is given
486
+ * to the setup commands of a run that names it (`secrets:`) and to nothing
487
+ * else, and is never returned.
488
+ */
489
+ export class Settings {
490
+ #c;
491
+ constructor(client) {
492
+ this.#c = client;
493
+ }
494
+ /** The settings and secrets, and the names recent runs needed and did not get. */
495
+ list() {
496
+ return this.#c.request("GET", "/v1/settings");
497
+ }
498
+ set(name, value, options = {}) {
499
+ return this.#c.request("PUT", `/v1/settings/${seg(name)}`, { body: { value, secret: options.secret === true } });
500
+ }
501
+ async remove(name) {
502
+ await this.#c.request("DELETE", `/v1/settings/${seg(name)}`);
503
+ }
504
+ }
505
+ // --------------------------------------------------------------------------
506
+ // Schedules
507
+ // --------------------------------------------------------------------------
508
+ /** A saved agent, run on a timetable. */
509
+ export class Schedules {
510
+ #c;
511
+ constructor(client) {
512
+ this.#c = client;
513
+ }
514
+ async list() {
515
+ return (await this.#c.request("GET", "/v1/schedules")).data;
516
+ }
517
+ /** `when` is words such as "every weekday at 09:00", or a 5-field cron expression. */
518
+ create(params) {
519
+ const { agent, when, input, timezone } = params;
520
+ return this.#c.request("POST", "/v1/schedules", { body: given({ agent, when, input, timezone }) });
521
+ }
522
+ update(scheduleId, params) {
523
+ const { when, input, timezone, enabled } = params;
524
+ return this.#c.request("PATCH", `/v1/schedules/${seg(scheduleId)}`, {
525
+ body: given({ when, input, timezone, enabled }),
526
+ });
527
+ }
528
+ async remove(scheduleId) {
529
+ await this.#c.request("DELETE", `/v1/schedules/${seg(scheduleId)}`);
530
+ }
531
+ }
532
+ // --------------------------------------------------------------------------
533
+ // The project's own model
534
+ // --------------------------------------------------------------------------
535
+ /**
536
+ * The project's own model: the version of Sensei trained on its verified
537
+ * work. The project is the one the key belongs to.
538
+ *
539
+ * Any key reads. `promote`, `discard`, `rollback`, `setTrial` and `settings`
540
+ * change what the project's keys are served, so they need a key an account
541
+ * admin has allowed to "Manage model versions" on the Keys page; any other
542
+ * key gets a `SenseiError` with status 403 and code
543
+ * `manage_model_versions_required`.
544
+ */
545
+ export class Model {
546
+ #c;
547
+ constructor(client) {
548
+ this.#c = client;
549
+ }
550
+ /**
551
+ * Where the model is. `state` is one word; `summary` says it in a
552
+ * sentence. `page: true` adds everything the dashboard's model page
553
+ * shows, under `page`.
554
+ */
555
+ get(options = {}) {
556
+ return this.#c.request("GET", "/v1/model", options.page ? { params: { include: "page" } } : {});
557
+ }
558
+ /** Every version, newest first, with its state and what its check found. */
559
+ async versions() {
560
+ return (await this.#c.request("GET", "/v1/model/versions")).data;
561
+ }
562
+ /**
563
+ * What happened, oldest first. `since` is an event id (the `cursor` of
564
+ * the last answer) or an ISO time; pass the cursor back to read only what
565
+ * came after.
566
+ */
567
+ events(params = {}) {
568
+ const { since, limit } = params;
569
+ return this.#c.request("GET", "/v1/model/events", { params: { since, limit } });
570
+ }
571
+ /**
572
+ * The model once its state is one of `until`. Asks again every `pollMs`;
573
+ * `timeoutMs` returns it as it is when the time is up, so check `state`
574
+ * on what comes back.
575
+ */
576
+ async wait(options = {}) {
577
+ const { until = MODEL_SETTLED, timeoutMs, pollMs = 15000 } = options;
578
+ const deadline = timeoutMs != null ? performance.now() + timeoutMs : null;
579
+ for (;;) {
580
+ const model = await this.get();
581
+ if (until.includes(model.state))
582
+ return model;
583
+ const left = deadline !== null ? deadline - performance.now() : pollMs;
584
+ if (left <= 0)
585
+ return model;
586
+ await sleep(Math.min(pollMs, left));
587
+ }
588
+ }
589
+ /** The version waiting becomes what every key of the project is served. */
590
+ promote() {
591
+ return this.#c.request("POST", "/v1/model/candidate/promote", { body: {} });
592
+ }
593
+ /** Set the version waiting aside. Nothing changes for the project's keys. */
594
+ discard(reason) {
595
+ return this.#c.request("POST", "/v1/model/candidate/discard", { body: nonEmpty({ reason }) });
596
+ }
597
+ /** One step back: the version before the live one, or the base model. */
598
+ rollback() {
599
+ return this.#c.request("POST", "/v1/model/rollback", { body: {} });
600
+ }
601
+ /**
602
+ * Serve the version waiting to `share` percent of the project's
603
+ * sessions: 5, 10, 25 or 50. 0 stops the trial and keeps the version.
604
+ */
605
+ setTrial(share) {
606
+ return this.#c.request("PUT", "/v1/model/trial", { body: { share } });
607
+ }
608
+ /**
609
+ * Change the project's settings; with nothing passed, read them.
610
+ * `promotion`: `auto` (a version that passes its check goes live by
611
+ * itself) or `review` (it waits for a decision). `trialShare`: the share
612
+ * of sessions (5, 10, 25 or 50) a version is tried on by itself, where
613
+ * Sensei tries a version before making it live. `emails`: whether the
614
+ * account's admins are emailed about this project's versions.
615
+ */
616
+ async settings(params = {}) {
617
+ const { promotion, trialShare, emails } = params;
618
+ const body = given({ promotion, trialShare, emails });
619
+ if (Object.keys(body).length === 0)
620
+ return (await this.get()).settings;
621
+ return (await this.#c.request("PUT", "/v1/model/settings", { body })).model.settings;
622
+ }
623
+ }