@lace-cloud/chat-core 0.19.0 → 0.20.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/README.md CHANGED
@@ -25,12 +25,16 @@ A tool is a schema and a handler. `ToolSchema` is
25
25
  `{name, title, description, inputSchema}`: the name the model calls the
26
26
  tool by, the short label a host shows a person, the description that
27
27
  carries the tool's guidance to any host, and the JSON schema of its
28
- input. `ToolHandler` is `(input) → Promise<ToolResult>`, with
28
+ input. `ToolHandler` is `(input, signal?) → Promise<ToolResult>`, with
29
29
  `ToolResult` `{content, isError?}`; a tool whose result carries data for
30
30
  its host beside the text states that result as the handler's type
31
- parameter (`ToolHandler<R>`, `ToolRegistration<R>`). A `ToolRegistry`
32
- holds the pairs; every host constructs its own with
33
- `createToolRegistry()` and registers the tools its environment provides.
31
+ parameter (`ToolHandler<R>`, `ToolRegistration<R>`). `signal` is the
32
+ host's cancellation of the call (an `AbortSignal`), where its chat has
33
+ one: once it aborts, a tool starts nothing further and stops waiting, and
34
+ what it already sent stands. A host with none calls a handler with the
35
+ input alone. A `ToolRegistry` holds the pairs; every host constructs its
36
+ own with `createToolRegistry()` and registers the tools its environment
37
+ provides.
34
38
 
35
39
  ```ts
36
40
  import { createToolRegistry, type ToolSchema } from '@lace-cloud/chat-core';
@@ -49,8 +53,16 @@ Capability is a port's presence. The surface's ports are the canvas's own
49
53
  `openEngineCommands` there hand them out. The one port of this package's
50
54
  own is `Transport`: one POST to Lace's API under `/api/v1/candidates/*`,
51
55
  with the developer's credential attached by the host per request. The
52
- package never sees a credential. A host with none supplies no `Transport`,
53
- and the tools then compose the model's reading alone and report nothing.
56
+ package never sees a credential. A host with none supplies no
57
+ `Transport`, and the tools then compose the model's reading alone and
58
+ report nothing. A host reads the credential per request, so a request it
59
+ finds none for (the developer signed out) it answers `{carried: false}`: it
60
+ carried nothing, and the change call that request was for composes from
61
+ then on exactly as with no `Transport` (below). Otherwise it answers with
62
+ Lace's `{status, body}` (`Answered`). Timing is the package's: each
63
+ request's `init` carries a `signal` (`AbortSignal`) the package aborts
64
+ when it gives the request up, and a host hands it to its request and adds
65
+ no timer of its own.
54
66
 
55
67
  ```ts
56
68
  import { canvasTools, createToolRegistry, moduleTools } from '@lace-cloud/chat-core';
@@ -214,8 +226,11 @@ of the tools reads them with no ports at all.
214
226
  `after` are that input's binding or that instance's presence;
215
227
  `revision` is the frame its apply produced; `questions` are the
216
228
  decision's questions in the order reported, each its kind and its
217
- candidates' ids; `reported` says the decision was reported to Lace, so
218
- its outcomes are. `id` is the decision's.
229
+ candidates' ids; `reported` says its decision report was sent, so its
230
+ outcomes are read: it is false where a request of the change call Lace
231
+ did not answer had already ended its requests, and true for a report
232
+ sent, settled or not, a cancelled call's included. `id` is the
233
+ decision's.
219
234
  - **What happened next to a change.** `changeOutcomes(record, frames, own?)`
220
235
  is a pure function from a `ChangeRecord`, the session's frames after
221
236
  the change and the revisions the package's own applies produced to the
@@ -259,14 +274,31 @@ of the tools reads them with no ports at all.
259
274
  the source has delivered the frame that carries the call, so the
260
275
  canvas their result ends with shows the save or the generate; when the
261
276
  session's stream ends first, the result says what the engine did and
262
- that the canvas below is from before it.
277
+ that the canvas below is from before it. A Save or a Generate whose call
278
+ is cancelled before it is sent is not sent, and the result says nothing
279
+ was done; one cancelled after it was sent goes on in the engine, the
280
+ tool stops waiting for it, and the result says so.
281
+ - **A change call its host cancels applies nothing after the
282
+ cancellation.** The change tool checks the call's `signal` before each
283
+ change, before each decision, before each registry listing or wiring
284
+ read, and immediately before each apply. Once it aborts, nothing further
285
+ is started: a rank in flight is given up and its request aborted, a
286
+ listing or wiring read in progress is no longer waited on, and the
287
+ change in progress and every later one say "not applied. The call was
288
+ cancelled before it applied." An apply already sent is the engine's and
289
+ is not undone. If it stands, its decision is still reported, bounded,
290
+ though the call no longer waits on it, and its record says it was
291
+ reported, so what the developer does next to it is read. If the engine
292
+ refuses it after the cancel, the result gives the engine's reason, and
293
+ like every change the call did not apply, it is not reported.
263
294
  - **One spelling of a reason.** A refused Save, Generate or apply names
264
295
  the reason it carries as a failure document spells it (`reasonWire`:
265
296
  `unsaved`, `source_refused`, …), or the API's own code when the API
266
297
  decided it, so a model reads one vocabulary from every tool.
267
298
  - The module tools each run one command (`module validate`,
268
299
  `registry list`, `registry describe`) and return its document trimmed
269
- to what a model needs.
300
+ to what a model needs. Each hands the call's `signal` to the command,
301
+ so a cancelled call stops waiting on it.
270
302
  - **A module tool's result is a `ModuleToolResult`**: the text the model
271
303
  reads, and `failure`, the failure document of a command that failed
272
304
  and wrote one (`CommandFailure`, from `CommandExitError.failure`). The
@@ -293,9 +325,14 @@ over the host's `Transport`.
293
325
  in rank order each with its `rightness`, and the head's thresholds, one
294
326
  `{from}` per kind a threshold shipped for. A question is read against
295
327
  the thresholds of the reply it came from, never against a value held
296
- from elsewhere. A 503 (`ranking_unavailable`), a transport that throws
297
- or a body that is not a reply is one failed call: the question is
298
- the model's alone and is reported with no capture.
328
+ from elsewhere. A 503 (`ranking_unavailable`) or a body that is not a
329
+ reply, a request that failed or got no answer within the bound below, or
330
+ a rank given up because the change call's requests had ended is one
331
+ failed call: the question is the model's alone and is reported with no
332
+ capture. The result says what happened: `status N` where Lace answered
333
+ with one, `the request failed` where the transport threw, rejected or
334
+ returned no status, `no answer from Lace` where nothing came within the
335
+ bound.
299
336
  - **Collection is the service's side effect of being asked.** At the rank
300
337
  call the API stores the question as asked (the request and statement as
301
338
  rendered, the candidates as sent, both arms' scores, the head) under
@@ -323,8 +360,35 @@ over the host's `Transport`.
323
360
  `POST /api/v1/candidates/decisions/:id/outcomes` as an `OutcomeReport`
324
361
  `{event, question?, candidate?}`.
325
362
  - The API derives each question's label from the outcomes alone; nobody
326
- reviews by default. A report the API refuses or the transport drops is
327
- one failed call: nothing retries it and nothing in the UI says so.
363
+ reviews by default. A report the API refuses, that fails, that gets no
364
+ answer within the bound below, or that is not made because the change
365
+ call's requests had ended is one failed call: nothing retries it and
366
+ nothing in the UI says so.
367
+ - **Every request is bounded, and one request Lace does not answer ends a
368
+ change call's requests.** The package waits at most
369
+ `RANKING_CALL_TIMEOUT_MS` (12 seconds) for the answer to any request it
370
+ makes, a rank, a decision or an outcome; then it gives the request up
371
+ and aborts its `signal`, whether or not the host's request has ended. The
372
+ rank route waits at most 10 seconds for the ranking before it answers
373
+ 503, so an answer the API sends is heard. Lace answered a request when
374
+ its API returned a status. Once a request made for one change call has
375
+ no answer (it failed: the transport threw, rejected or returned no
376
+ status; nothing came within the bound; or the host carried it nothing),
377
+ every later request of that call is given up without being made: its
378
+ questions are the model's alone and its decisions are not reported. A
379
+ status, any status, stops nothing. This ends with its change call, and
380
+ no outcome is given up for it: each is bounded on its own. So when
381
+ Lace's API does not answer at all, a change call waits one bound, and a
382
+ host whose request fails sooner costs the call that once.
383
+ - **A request the host carried nothing.** A host that finds no
384
+ credential for a request answers `{carried: false}`. The change call
385
+ that request was for composes from then on exactly as with no
386
+ `Transport`: its questions are the model's alone ("Lace did not
387
+ rank", and no `steps` question), no later request of the call is made,
388
+ no decision report is made after it, and a record whose report was not
389
+ made does not say it was reported, so no outcome of it is posted. An
390
+ outcome the host carries nothing is simply not made. The next change
391
+ call asks again.
328
392
 
329
393
  No rank call carries more than `RANK_CANDIDATES_MAX` (256) candidates, a
330
394
  request and statement together over `RANK_REQUEST_MAX_CHARS` (4,000