runbios-sdk 0.2.1-dev.97 → 0.2.1-rc.118

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.
@@ -0,0 +1,378 @@
1
+ import type { HttpClient } from '../client.js';
2
+ import type { LoopTrace, LoopTraceListResponse, LoopTraceListParams, LoopCaptureParams, LoopCaptureResult, LoopImportParams, LoopImportResult, LoopSignal, LoopSignalParams, LoopCandidate, LoopCandidateParams, LoopGrader, LoopGraderParams, LoopLabel, LoopLabelCount, LoopGradeResult, LoopDataset, LoopDatasetListParams, LoopDatasetItem, LoopDatasetCreateParams, LoopConfig, LoopConfigParams, LoopStats, LoopJudge, LoopJudgeParams, LoopJudgeRun, LoopJudgeWork, LoopJudgeVerdict, LoopJudgeVerdictResult } from '../types.js';
3
+ /**
4
+ * The Conscious Loop -- capture what your model was asked and answered, record
5
+ * whether it was right, and turn those judgements into training data.
6
+ *
7
+ * Nothing is captured until you turn it on for a source, and you can turn it
8
+ * off again at any time. Anything that looks like a credential or a personal
9
+ * detail is removed before the record is written, never afterwards.
10
+ *
11
+ * Requires an API key carrying `loop:read` and/or `loop:write`. Those scopes are
12
+ * deliberately absent from the Read Only preset, because what they return is
13
+ * your raw prompts and completions rather than catalog metadata.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // 1. Decide that this source is recorded.
18
+ * await client.loop.setConfig('my-agent', { enabled: true, retention_days: 30 });
19
+ *
20
+ * // 2. Send what your model was asked and what it answered. Works whoever
21
+ * // served it -- us, another provider, or your own servers.
22
+ * const { trace_id } = await client.loop.capture({
23
+ * deployment_id: 'my-agent',
24
+ * model: 'gpt-4o',
25
+ * messages: [{ role: 'user', content: 'what is our refund window' }],
26
+ * completion: 'thirty days',
27
+ * });
28
+ *
29
+ * // 3. Say whether it was right. A rewrite is the most valuable answer here:
30
+ * // the model learns your version AND learns to avoid its own.
31
+ * await client.loop.signal(trace_id, {
32
+ * verdict: 'edited',
33
+ * correction: 'Thirty days from delivery, no questions asked.',
34
+ * });
35
+ *
36
+ * // 4. Turn the judgements into a training set and take the file.
37
+ * const ds = await client.loop.createDataset({ name: 'support', method: 'sft' });
38
+ * const jsonl = await client.loop.downloadDataset(ds.id);
39
+ * ```
40
+ */
41
+ export declare class Loop {
42
+ private readonly _http;
43
+ /** @internal */
44
+ constructor(_http: HttpClient);
45
+ /**
46
+ * Send one exchange to be captured.
47
+ *
48
+ * Works regardless of who served the model: ours, OpenAI, Fireworks, your own
49
+ * own servers, an agent framework. Pass `tool_calls` and `tools` when the turn
50
+ * invoked a function -- without them a tool-using exchange trains the model to
51
+ * answer in prose where it should have called something.
52
+ *
53
+ * The returned `trace_id` is OURS. If you pass your own `request_id` it is
54
+ * kept as an idempotency handle: sending the same one again returns the same
55
+ * trace rather than storing a second copy, so a retry is safe.
56
+ *
57
+ * When the source is not enabled this resolves with `captured: false` and a
58
+ * reason instead of throwing -- capture must never be the thing that breaks
59
+ * your application.
60
+ */
61
+ capture(params: LoopCaptureParams): Promise<LoopCaptureResult>;
62
+ /**
63
+ * Bring data you already have into the loop.
64
+ *
65
+ * This does NOT create a training set. It creates conversations, in the same
66
+ * place captured ones live and subject to the same review, rules, judges and
67
+ * labels. A row becomes trainable when something says it is good, never
68
+ * because it arrived in a file -- which is the one guarantee that separates
69
+ * a corpus from a pile.
70
+ *
71
+ * Each row is read for what it actually is. A `prompt`/`chosen`/`rejected`
72
+ * triple becomes a preference pair; an answer plus a yes-or-no becomes a
73
+ * thumbs verdict; a question and an answer waits for review; a question with
74
+ * no answer waits for an answer; a paragraph of prose is refused, because it
75
+ * is not a conversation.
76
+ *
77
+ * A verdict that arrives *with* the file is kept -- discarding somebody's
78
+ * judgement would be worse -- but it is recorded as having come from your
79
+ * earlier process rather than from a reviewer here, and the conversation
80
+ * records that it was imported. Neither fact can be reconstructed later, so
81
+ * both are written at the door.
82
+ *
83
+ * `source` is required and becomes the id every imported conversation is
84
+ * filed under: "everything in one bucket called import" is a corpus nobody
85
+ * can slice afterwards. At most 5000 rows per call, because the call is
86
+ * synchronous and somebody is waiting on it.
87
+ */
88
+ importRows(params: LoopImportParams): Promise<LoopImportResult>;
89
+ /** List captured conversations, newest first. */
90
+ listTraces(params?: LoopTraceListParams): Promise<LoopTraceListResponse>;
91
+ /** Read one conversation, with every verdict recorded on it. */
92
+ getTrace(id: string): Promise<LoopTrace>;
93
+ /**
94
+ * Delete a conversation.
95
+ *
96
+ * It also leaves every training set built from it, including sets already
97
+ * exported -- so a customer asking you to delete a conversation genuinely
98
+ * removes it from what the model will learn next. Training runs that have
99
+ * already finished are not affected.
100
+ */
101
+ deleteTrace(id: string): Promise<{
102
+ deleted: boolean;
103
+ trace_id: string;
104
+ }>;
105
+ /**
106
+ * Record a verdict on a conversation.
107
+ *
108
+ * Append-only: posting a second verdict does not replace the first. Two
109
+ * reviewers disagreeing about an answer is information worth keeping.
110
+ *
111
+ * `source` says who judged: `human`, `verifier` (a deterministic check --
112
+ * tests passed, schema valid), `judge` (a model grading a model), or
113
+ * `behavioural` (what the user did next). When several disagree, a human
114
+ * outranks a verifier, a verifier outranks a judge, and a judge outranks a
115
+ * behavioural hint.
116
+ */
117
+ signal(traceId: string, params: LoopSignalParams): Promise<LoopSignal>;
118
+ /**
119
+ * Thumbs up: this answer was good. Shorthand for `signal(id, { verdict:
120
+ * 'accepted' })` — there is one stored vocabulary behind both, so a thumbs-up
121
+ * and an "accepted" can never disagree in your corpus.
122
+ */
123
+ upvote(traceId: string, reason?: string): Promise<LoopSignal>;
124
+ /**
125
+ * Thumbs down: this answer was bad, and you have nothing better to offer.
126
+ *
127
+ * On its own this REMOVES the answer from training rather than teaching
128
+ * anything — there is no better version to learn. If you know what it should
129
+ * have said, `correct()` is worth far more.
130
+ */
131
+ downvote(traceId: string, reason?: string): Promise<LoopSignal>;
132
+ /**
133
+ * The model was wrong; here is what it should have said.
134
+ *
135
+ * The most valuable feedback there is, because it produces BOTH halves of a
136
+ * preference pair from one action: the model learns your answer and learns to
137
+ * avoid its own.
138
+ */
139
+ correct(traceId: string, answer: string, reason?: string): Promise<LoopSignal>;
140
+ /**
141
+ * Record the GOLD answer for this question — the reference, regardless of
142
+ * what the model happened to say.
143
+ *
144
+ * Different from `correct()` in a way that matters: a correction asserts the
145
+ * model was wrong, so the original becomes the rejected half of a pair. A gold
146
+ * answer asserts nothing about the model, so if it MATCHES what was said, no
147
+ * preference pair is invented — but SFT still learns it.
148
+ *
149
+ * It is the most reusable thing you can record: it trains SFT, forms a DPO
150
+ * pair when it differs from the answer, and stands in as the GRPO reference
151
+ * when you have not supplied a separate ground truth.
152
+ */
153
+ gold(traceId: string, answer: string, reason?: string): Promise<LoopSignal>;
154
+ /** Every verdict on one conversation, oldest first. */
155
+ listSignals(traceId: string): Promise<LoopSignal[]>;
156
+ /**
157
+ * Submit an alternative answer to a prompt already captured.
158
+ *
159
+ * This is what makes preference learning scale. A human rewrite is the best
160
+ * signal there is and the least available -- somebody has to sit down and
161
+ * write it. Sample the model several times for the same prompt, score the
162
+ * samples, and a DPO pair falls out automatically: best becomes chosen,
163
+ * worst becomes rejected. Point a stronger model at the prompt instead and
164
+ * the same machinery does distillation.
165
+ *
166
+ * Score them, or they cannot pair: an unscored alternative says nothing about
167
+ * which answer anybody prefers. `score_source` is required alongside a score,
168
+ * because precedence between a verifier, a judge and a person is the whole
169
+ * reason we record who judged.
170
+ *
171
+ * A human correction always outranks any score.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * for (const sample of await sampleMyModel(prompt, 4)) {
176
+ * await client.loop.addCandidate(traceId, {
177
+ * completion: sample.text,
178
+ * score: await myVerifier(sample.text),
179
+ * score_source: 'verifier',
180
+ * });
181
+ * }
182
+ * ```
183
+ */
184
+ addCandidate(traceId: string, params: LoopCandidateParams): Promise<LoopCandidate>;
185
+ /** Every alternative answer recorded for one prompt, oldest first. */
186
+ listCandidates(traceId: string): Promise<LoopCandidate[]>;
187
+ /**
188
+ * Label a conversation, so it can be selected later.
189
+ *
190
+ * An average over everything is the least useful thing to train on. A model
191
+ * weak at refunds is fixed with refund examples, and you can only select
192
+ * those if you said so when the conversation arrived.
193
+ *
194
+ * A label may name a `parent`, which is what makes a MASTER GROUP: labelling
195
+ * something `refunds` with parent `billing` makes it selectable as either,
196
+ * and selecting `billing` later gathers every child without you maintaining
197
+ * a list of them.
198
+ *
199
+ * Labels are lowercased and trimmed, so `Refunds` and `refunds` are one label.
200
+ */
201
+ label(traceId: string, labels: string[], parent?: string, attributes?: Record<string, string>): Promise<LoopLabel[]>;
202
+ /**
203
+ * Set named dimensions on a conversation: `{ category: 'billing',
204
+ * language: 'es' }`.
205
+ *
206
+ * An upsert per dimension, so correcting `category` leaves `task` and any
207
+ * bare tags exactly where they were — no delete-then-add.
208
+ */
209
+ setAttributes(traceId: string, attributes: Record<string, string>): Promise<LoopLabel[]>;
210
+ unlabel(traceId: string, label: string, key?: string): Promise<{
211
+ deleted: boolean;
212
+ key: string;
213
+ label: string;
214
+ }>;
215
+ /** Every label in the workspace, with how many conversations carry it. */
216
+ listLabels(): Promise<LoopLabelCount[]>;
217
+ /**
218
+ * Build a training set from the feedback recorded so far.
219
+ *
220
+ * The three methods need genuinely different things, so one set cannot be
221
+ * reshaped into another afterwards:
222
+ *
223
+ * - `sft` -- answers you marked right, and answers you rewrote.
224
+ * - `dpo` -- answers you REWROTE, so a better and a worse version of the same
225
+ * reply exist. Nothing else produces a pair.
226
+ * - `grpo` -- answers with a value or fact they can be checked against, or
227
+ * a judge rubric, which scores answers the run has not written yet.
228
+ * - `kto` -- anything carrying a yes or a no, INCLUDING a thumbs-down with
229
+ * nothing written. That row trains nothing under the other three methods,
230
+ * which is why this one exists: it is the feedback people actually give.
231
+ *
232
+ * `holdout_percent` holds back your most recent work rather than a random
233
+ * slice, so the evaluation measures whether the model generalised instead of
234
+ * memorised the same week.
235
+ *
236
+ * The result always reports `rejected_counts`: why rows were left out. A
237
+ * small set with a reason is useful; a small set without one is just alarming.
238
+ */
239
+ createDataset(params: LoopDatasetCreateParams): Promise<LoopDataset>;
240
+ /** List training sets, newest first. */
241
+ listDatasets(params?: LoopDatasetListParams): Promise<LoopDataset[]>;
242
+ /** Read one training set and its curation report. */
243
+ getDataset(id: string): Promise<LoopDataset>;
244
+ /**
245
+ * Page through the rows a training set actually contains.
246
+ *
247
+ * Worth reading before you spend money on a run: each row carries the address
248
+ * of the conversation it was built from.
249
+ */
250
+ listDatasetItems(id: string, params?: {
251
+ limit?: number;
252
+ offset?: number;
253
+ }): Promise<LoopDatasetItem[]>;
254
+ /**
255
+ * Download a training set as JSONL -- one training row per line, the format
256
+ * every trainer in this space reads.
257
+ *
258
+ * `split` defaults to the training rows; pass `holdout` for the slice held
259
+ * back, or `all` for both.
260
+ */
261
+ downloadDataset(id: string, split?: 'train' | 'holdout' | 'all'): Promise<string>;
262
+ /**
263
+ * Delete a training set.
264
+ *
265
+ * The conversations it was built from are untouched -- a set is a selection,
266
+ * and discarding the selection must not discard the evidence.
267
+ */
268
+ deleteDataset(id: string): Promise<{
269
+ deleted: boolean;
270
+ dataset_id: string;
271
+ }>;
272
+ /**
273
+ * Write a rule that scores answers without a person.
274
+ *
275
+ * Human review is the most trustworthy feedback and the least available. A
276
+ * grader is written once and applied to every answer afterwards: did it
277
+ * contain the required phrase, did it parse as the schema you asked for, is
278
+ * the number within tolerance of the known answer, did it call the function
279
+ * it should have.
280
+ *
281
+ * Every kind here is DETERMINISTIC -- no model call, no network. That is why
282
+ * a verifier outranks a judge when they disagree: it cannot be flattered and
283
+ * it cannot drift between runs.
284
+ *
285
+ * `weight` is the multiplier: a criterion that matters twice as much gets
286
+ * twice the weight, and the combined score is the weighted mean over the
287
+ * rules that actually applied.
288
+ *
289
+ * A caution worth knowing before you write a set: a rule made only of
290
+ * `forbidden` phrases is satisfied VACUOUSLY by an answer that says nothing.
291
+ * Pair it with a `required` phrase, or you are rewarding silence.
292
+ */
293
+ createGrader(params: LoopGraderParams): Promise<LoopGrader>;
294
+ /** Every rule this workspace has written. */
295
+ listGraders(): Promise<LoopGrader[]>;
296
+ deleteGrader(id: string): Promise<{
297
+ deleted: boolean;
298
+ grader_id: string;
299
+ }>;
300
+ /**
301
+ * Apply this workspace's rules to one captured answer AND to every
302
+ * alternative sampled for it.
303
+ *
304
+ * Grading both in one pass is the point: scoring only the original gives a
305
+ * verdict, while scoring the samples as well gives the preference pair. Sample
306
+ * your model, call this, and you have DPO data with nobody reading anything.
307
+ *
308
+ * A run where no rule could apply writes NOTHING -- no verdict, no scores.
309
+ * Recording a zero that no rule produced would poison curation with a
310
+ * judgement nobody reached, so `applied: 0` is reported instead.
311
+ */
312
+ grade(traceId: string): Promise<LoopGradeResult>;
313
+ /** Every source this workspace has configured. */
314
+ listConfigs(): Promise<LoopConfig[]>;
315
+ /**
316
+ * Read the capture setting for one source. A source nobody has configured
317
+ * reads back as disabled rather than missing, because "we are not recording
318
+ * this" is the honest answer.
319
+ */
320
+ getConfig(source: string): Promise<LoopConfig>;
321
+ /**
322
+ * Turn capture on or off for a source, and choose how long it is kept.
323
+ *
324
+ * This is the consent decision the whole feature rests on: nothing is
325
+ * recorded until it is made, and the row remembers who made it and when.
326
+ * `sample_rate` below 1 records a deterministic fraction, chosen so that every
327
+ * turn of one conversation is captured or skipped together -- half a
328
+ * conversation makes training rows with holes in them.
329
+ */
330
+ setConfig(source: string, params: LoopConfigParams): Promise<LoopConfig>;
331
+ /**
332
+ * How much there is, and how much of it each method could actually use.
333
+ *
334
+ * The `ready` numbers are upper bounds: duplicate questions are folded into
335
+ * one row while a set is built, so the finished count can be lower.
336
+ */
337
+ stats(): Promise<LoopStats>;
338
+ /** Write a rubric: what makes an answer good here, and what to score. */
339
+ createJudge(params: LoopJudgeParams): Promise<LoopJudge>;
340
+ listJudges(): Promise<LoopJudge[]>;
341
+ /**
342
+ * Rewrite a rubric. Runs already recorded keep the instructions they used:
343
+ * a verdict has to keep meaning what it meant when it was given.
344
+ */
345
+ updateJudge(judgeId: string, params: LoopJudgeParams): Promise<LoopJudge>;
346
+ /**
347
+ * Retire a rubric. Its runs go with it; the verdicts they wrote stay. A score
348
+ * is evidence about an answer, and it does not stop being true because the
349
+ * rubric was retired.
350
+ */
351
+ deleteJudge(judgeId: string): Promise<void>;
352
+ /**
353
+ * Open a run: select the conversations now, and freeze the rubric onto them.
354
+ *
355
+ * The selection is fixed at this moment on purpose. A run whose selection is
356
+ * a live query silently grows as conversations arrive, so "we scored the
357
+ * refunds slice" becomes a claim about a set that no longer exists.
358
+ */
359
+ startRun(judgeId: string, limit?: number): Promise<LoopJudgeRun>;
360
+ listRuns(judgeId?: string): Promise<LoopJudgeRun[]>;
361
+ getRun(runId: string): Promise<LoopJudgeRun>;
362
+ /**
363
+ * Take the next conversations to score, each rendered into a ready-to-send
364
+ * prompt. Nothing is marked taken, so a caller that dies half way loses
365
+ * nothing: ask again and the same items come back.
366
+ */
367
+ takeWork(runId: string, limit?: number): Promise<LoopJudgeWork>;
368
+ /**
369
+ * Hand the scores back. A verdict for a conversation outside this run, or
370
+ * scoring something the rubric never asked for, is refused and reported in
371
+ * `rejected` rather than silently dropped.
372
+ *
373
+ * Pass `finish` to close a run you have decided to stop early. Without it an
374
+ * unfinished run stays open, which is the honest state for work that was
375
+ * abandoned rather than completed.
376
+ */
377
+ postVerdicts(runId: string, verdicts: LoopJudgeVerdict[], finish?: boolean): Promise<LoopJudgeVerdictResult>;
378
+ }