@owlmeans/llm-common 0.1.18-rc.9 → 0.1.18
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 +2 -2
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/llm-common/SKILL.md +64 -12
- package/build/consts.d.ts +107 -7
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +125 -5
- package/build/consts.js.map +1 -1
- package/build/delegate/consts.d.ts +25 -0
- package/build/delegate/consts.d.ts.map +1 -0
- package/build/delegate/consts.js +28 -0
- package/build/delegate/consts.js.map +1 -0
- package/build/delegate/index.d.ts +3 -0
- package/build/delegate/index.d.ts.map +1 -0
- package/build/delegate/index.js +3 -0
- package/build/delegate/index.js.map +1 -0
- package/build/delegate/types.d.ts +85 -0
- package/build/delegate/types.d.ts.map +1 -0
- package/build/delegate/types.js +13 -0
- package/build/delegate/types.js.map +1 -0
- package/build/files/types.d.ts +10 -0
- package/build/files/types.d.ts.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/inquiry/consts.d.ts +48 -0
- package/build/inquiry/consts.d.ts.map +1 -0
- package/build/inquiry/consts.js +50 -0
- package/build/inquiry/consts.js.map +1 -0
- package/build/inquiry/helper/types.d.ts +47 -0
- package/build/inquiry/helper/types.d.ts.map +1 -0
- package/build/inquiry/helper/types.js +2 -0
- package/build/inquiry/helper/types.js.map +1 -0
- package/build/inquiry/helper.d.ts +4 -0
- package/build/inquiry/helper.d.ts.map +1 -0
- package/build/inquiry/helper.js +39 -0
- package/build/inquiry/helper.js.map +1 -0
- package/build/inquiry/index.d.ts +6 -0
- package/build/inquiry/index.d.ts.map +1 -0
- package/build/inquiry/index.js +4 -0
- package/build/inquiry/index.js.map +1 -0
- package/build/inquiry/types.d.ts +72 -0
- package/build/inquiry/types.d.ts.map +1 -0
- package/build/inquiry/types.js +2 -0
- package/build/inquiry/types.js.map +1 -0
- package/build/inquiry/utils.d.ts +14 -0
- package/build/inquiry/utils.d.ts.map +1 -0
- package/build/inquiry/utils.js +14 -0
- package/build/inquiry/utils.js.map +1 -0
- package/build/results/consts.d.ts +19 -0
- package/build/results/consts.d.ts.map +1 -0
- package/build/results/consts.js +30 -0
- package/build/results/consts.js.map +1 -0
- package/build/results/consts.local.d.ts +3 -0
- package/build/results/consts.local.d.ts.map +1 -0
- package/build/results/consts.local.js +3 -0
- package/build/results/consts.local.js.map +1 -0
- package/build/results/index.d.ts +4 -0
- package/build/results/index.d.ts.map +1 -0
- package/build/results/index.js +3 -0
- package/build/results/index.js.map +1 -0
- package/build/results/types.d.ts +37 -0
- package/build/results/types.d.ts.map +1 -0
- package/build/results/types.js +2 -0
- package/build/results/types.js.map +1 -0
- package/build/results/utils.d.ts +11 -0
- package/build/results/utils.d.ts.map +1 -0
- package/build/results/utils.js +27 -0
- package/build/results/utils.js.map +1 -0
- package/build/spectator/types.d.ts +6 -0
- package/build/spectator/types.d.ts.map +1 -1
- package/build/types.d.ts +99 -7
- package/build/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/consts.ts +129 -5
- package/src/delegate/consts.ts +26 -0
- package/src/delegate/index.ts +2 -0
- package/src/delegate/types.ts +91 -0
- package/src/files/types.ts +11 -0
- package/src/index.ts +3 -0
- package/src/inquiry/consts.ts +52 -0
- package/src/inquiry/helper/types.ts +47 -0
- package/src/inquiry/helper.ts +53 -0
- package/src/inquiry/index.ts +5 -0
- package/src/inquiry/types.ts +77 -0
- package/src/inquiry/utils.ts +20 -0
- package/src/results/consts.local.ts +2 -0
- package/src/results/consts.ts +32 -0
- package/src/results/index.ts +3 -0
- package/src/results/types.ts +37 -0
- package/src/results/utils.ts +34 -0
- package/src/spectator/types.ts +6 -0
- package/src/types.ts +101 -7
- package/tests/inquiry.spec.ts +111 -0
- package/tests/results.spec.ts +81 -0
- package/tsconfig.json +3 -1
package/src/files/types.ts
CHANGED
|
@@ -17,6 +17,17 @@
|
|
|
17
17
|
* that stops a rich helper from satisfying this one.
|
|
18
18
|
*/
|
|
19
19
|
export interface LlmFileProvider {
|
|
20
|
+
/**
|
|
21
|
+
* Stable identity of WHAT this provider reads — a project root, a sandbox id.
|
|
22
|
+
*
|
|
23
|
+
* A prompt plugin that caches resolved reads across calls has nothing else to key on:
|
|
24
|
+
* providers are late-bound and often rebuilt per request, so object identity says
|
|
25
|
+
* nothing, and a cache shared between two projects serves the first one's files to the
|
|
26
|
+
* second. A provider that supplies no key is treated as uncacheable rather than as one
|
|
27
|
+
* more anonymous member of a shared bucket.
|
|
28
|
+
*/
|
|
29
|
+
key?: string
|
|
30
|
+
|
|
20
31
|
/** Read a file relative to the root. With `noThrow`, a missing file yields `''`. */
|
|
21
32
|
readFile: (filePath: string, noThrow?: boolean) => Promise<string>
|
|
22
33
|
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What shape of answer a question expects. Deliberately three, because a question a person is
|
|
3
|
+
* asked mid-run is answered in seconds or not at all: pick one of these, say it in your own
|
|
4
|
+
* words, or say yes/no. Anything richer is a form, and a form belongs to an application screen.
|
|
5
|
+
*/
|
|
6
|
+
export enum InquiryKind {
|
|
7
|
+
Choice = 'choice',
|
|
8
|
+
Text = 'text',
|
|
9
|
+
Confirm = 'confirm',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What a run is allowed to do when it needs a decision that is not its own.
|
|
14
|
+
*
|
|
15
|
+
* - `Ask` — put it to a person through the seated transport and wait.
|
|
16
|
+
* - `Default` — assume the question's own default (or record a decline) and carry on. The caller
|
|
17
|
+
* is expected to RECORD the assumption; a run nobody is watching must never block.
|
|
18
|
+
* - `Refuse` — nobody may be asked at all; the attempt is an error.
|
|
19
|
+
*/
|
|
20
|
+
export enum InquiryPolicy {
|
|
21
|
+
Ask = 'ask',
|
|
22
|
+
Default = 'default',
|
|
23
|
+
Refuse = 'refuse',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The ONE ceiling on a stored answer, in characters. An answer is a decision, not a document.
|
|
28
|
+
*
|
|
29
|
+
* Every layer that carries an answer references this constant rather than choosing its own:
|
|
30
|
+
* `viable-common`'s `CONNECT_INQUIRY_MAX_TEXT` (the wire copy) equals it, `capAnswer` enforces it,
|
|
31
|
+
* and the connector's answer schema caps `text` at it. Three ceilings for one value is how a
|
|
32
|
+
* user's answer gets accepted on the wire and silently halved further in.
|
|
33
|
+
*/
|
|
34
|
+
export const DEFAULT_INQUIRY_ANSWER_CHARS = 2_000
|
|
35
|
+
|
|
36
|
+
/** How many options one question may offer. Beyond this it is not a question. */
|
|
37
|
+
export const DEFAULT_INQUIRY_OPTIONS = 12
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* How much of an answer's free text a resumable pipeline STATE may hold.
|
|
41
|
+
*
|
|
42
|
+
* A pipeline state is keys, markers and paths — a couple of full-size answers would make it prose,
|
|
43
|
+
* which is the invariant the whole pipeline design rests on. The decision (`value`/`declined`)
|
|
44
|
+
* stays whole; the prose is cut here and belongs in whatever document the application keeps for
|
|
45
|
+
* it (`stateAnswerOf`).
|
|
46
|
+
*/
|
|
47
|
+
export const INQUIRY_STATE_TEXT_CHARS = 200
|
|
48
|
+
|
|
49
|
+
/** The answer value of a confirmed {@link InquiryKind.Confirm}. */
|
|
50
|
+
export const CONFIRM_YES = 'yes'
|
|
51
|
+
/** The answer value of a refused {@link InquiryKind.Confirm}. */
|
|
52
|
+
export const CONFIRM_NO = 'no'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Inquiry, InquiryAnswer } from '../types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pure helpers over an inquiry and its answer — no IO, no state, no clock.
|
|
5
|
+
*
|
|
6
|
+
* They are here rather than in the runtime because every layer needs the same reading of an
|
|
7
|
+
* answer: the execution service, the pipeline runner, the `ask_user` tool, the connector and the
|
|
8
|
+
* screen that finally shows it. A second reading of "was this answered" is a second contract.
|
|
9
|
+
*/
|
|
10
|
+
export interface InquiryHelper {
|
|
11
|
+
/**
|
|
12
|
+
* What to assume when nobody answers: the question's own default, or a decline.
|
|
13
|
+
*
|
|
14
|
+
* A decline is an ANSWER — the run carries on and records what it assumed — which is why this
|
|
15
|
+
* never throws and never returns null.
|
|
16
|
+
*/
|
|
17
|
+
defaultAnswerFor: (inquiry: Inquiry) => InquiryAnswer
|
|
18
|
+
/**
|
|
19
|
+
* The one thing an answer says, as a string — the first chosen value, else the free text, else
|
|
20
|
+
* `null` when it says nothing at all (a decline, or an empty answer).
|
|
21
|
+
*/
|
|
22
|
+
answeredWith: (answer: InquiryAnswer) => string | null
|
|
23
|
+
/** Nobody could decide. Distinct from an empty answer — see {@link InquiryHelper.answeredWith}. */
|
|
24
|
+
isDeclined: (answer: InquiryAnswer) => boolean
|
|
25
|
+
/**
|
|
26
|
+
* Cut an answer's free TEXT to the ceiling and SAY SO.
|
|
27
|
+
*
|
|
28
|
+
* Only the prose is cut. A `value` IS the decision — for a choice it has to equal one of the
|
|
29
|
+
* question's own option values — so slicing one does not degrade an answer, it silently replaces
|
|
30
|
+
* it with an identifier nobody offered and nothing matches, which `answeredWith` then hands on as
|
|
31
|
+
* what the person chose. An over-long value is a defect upstream rather than a long answer (the
|
|
32
|
+
* connector's schema refuses one outright instead of shortening it), so it travels on whole and is
|
|
33
|
+
* REPORTED through `truncated` — the flag every consumer already reads as "this is not exactly
|
|
34
|
+
* what the person gave".
|
|
35
|
+
*/
|
|
36
|
+
capAnswer: (answer: InquiryAnswer, max?: number) => InquiryAnswer
|
|
37
|
+
/**
|
|
38
|
+
* The copy of an answer a resumable pipeline STATE keeps: the decision whole, the prose cut to
|
|
39
|
+
* {@link INQUIRY_STATE_TEXT_CHARS}.
|
|
40
|
+
*
|
|
41
|
+
* The full answer goes back to whoever asked; only this reduced one is persisted, so a run that
|
|
42
|
+
* asks several questions still holds a state made of keys rather than of paragraphs.
|
|
43
|
+
*/
|
|
44
|
+
stateAnswerOf: (answer: InquiryAnswer) => InquiryAnswer
|
|
45
|
+
/** One-line label of a question — for a note, a trace line or a run row. */
|
|
46
|
+
renderInquiry: (inquiry: Inquiry) => string
|
|
47
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DEFAULT_INQUIRY_ANSWER_CHARS, INQUIRY_STATE_TEXT_CHARS } from './consts.js'
|
|
2
|
+
import type { Inquiry, InquiryAnswer } from './types.js'
|
|
3
|
+
import type { InquiryHelper } from './helper/types.js'
|
|
4
|
+
|
|
5
|
+
export const createInquiryHelper = (): InquiryHelper => {
|
|
6
|
+
const defaultAnswerFor = (inquiry: Inquiry): InquiryAnswer =>
|
|
7
|
+
inquiry.default != null
|
|
8
|
+
? { inquiryId: inquiry.id, value: inquiry.default }
|
|
9
|
+
: { inquiryId: inquiry.id, declined: true }
|
|
10
|
+
|
|
11
|
+
const answeredWith = (answer: InquiryAnswer): string | null => {
|
|
12
|
+
const value = Array.isArray(answer.value) ? answer.value[0] : answer.value
|
|
13
|
+
if (value != null && value !== '') return value
|
|
14
|
+
if (answer.text != null && answer.text !== '') return answer.text
|
|
15
|
+
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isDeclined = (answer: InquiryAnswer): boolean => answer.declined === true
|
|
20
|
+
|
|
21
|
+
const capAnswer = (
|
|
22
|
+
answer: InquiryAnswer, max: number = DEFAULT_INQUIRY_ANSWER_CHARS
|
|
23
|
+
): InquiryAnswer => {
|
|
24
|
+
const text = answer.text != null && answer.text.length > max
|
|
25
|
+
? answer.text.slice(0, max)
|
|
26
|
+
: undefined
|
|
27
|
+
const values = Array.isArray(answer.value)
|
|
28
|
+
? answer.value
|
|
29
|
+
: answer.value != null ? [answer.value] : []
|
|
30
|
+
const oversized = values.some(value => value.length > max)
|
|
31
|
+
|
|
32
|
+
if (text == null && !oversized) return answer
|
|
33
|
+
|
|
34
|
+
return { ...answer, ...(text != null ? { text } : {}), truncated: true }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const stateAnswerOf = (answer: InquiryAnswer): InquiryAnswer =>
|
|
38
|
+
answer.text != null && answer.text.length > INQUIRY_STATE_TEXT_CHARS
|
|
39
|
+
? { ...answer, text: answer.text.slice(0, INQUIRY_STATE_TEXT_CHARS), truncated: true }
|
|
40
|
+
: answer
|
|
41
|
+
|
|
42
|
+
const renderInquiry = (inquiry: Inquiry): string => {
|
|
43
|
+
const options = inquiry.options != null && inquiry.options.length > 0
|
|
44
|
+
? ` (${inquiry.options.map(option => option.value).join(' | ')})`
|
|
45
|
+
: ''
|
|
46
|
+
|
|
47
|
+
return `[${inquiry.kind}] ${inquiry.question}${options}`.replace(/\s+/g, ' ').trim()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { defaultAnswerFor, answeredWith, isDeclined, capAnswer, stateAnswerOf, renderInquiry }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const inquiryHelper = createInquiryHelper()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { InquiryKind, InquiryPolicy } from './consts.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One question put to a person while a run is in flight, and the answer that comes back.
|
|
5
|
+
*
|
|
6
|
+
* Everything here is serializable for the same reason a delegated task is: whoever answers is
|
|
7
|
+
* outside this process — a browser dialog, a coding agent driving the application through a
|
|
8
|
+
* connector, a test double — and the question may outlive the process that asked it, parked on a
|
|
9
|
+
* pipeline run row until somebody comes back to it.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface InquiryOption {
|
|
13
|
+
value: string
|
|
14
|
+
label: string
|
|
15
|
+
description?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Inquiry {
|
|
19
|
+
/** Stable id, chosen by whoever asks. The ONLY thing that routes an answer back. */
|
|
20
|
+
id: string
|
|
21
|
+
kind: InquiryKind
|
|
22
|
+
/** One question, in plain words. */
|
|
23
|
+
question: string
|
|
24
|
+
/** One or two sentences of background. Never the whole task. */
|
|
25
|
+
context?: string
|
|
26
|
+
/** Required for {@link InquiryKind.Choice}; ignored otherwise. */
|
|
27
|
+
options?: InquiryOption[]
|
|
28
|
+
multiple?: boolean
|
|
29
|
+
/** A `Choice` the answerer may answer in their own words instead. */
|
|
30
|
+
allowText?: boolean
|
|
31
|
+
/** What to assume when nobody answers. {@link InquiryPolicy.Default} returns exactly this. */
|
|
32
|
+
default?: string | string[]
|
|
33
|
+
expiresAt?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface InquiryAnswer {
|
|
37
|
+
inquiryId: string
|
|
38
|
+
value?: string | string[]
|
|
39
|
+
text?: string
|
|
40
|
+
/** Nobody could decide. A legitimate ANSWER, never a failure. */
|
|
41
|
+
declined?: boolean
|
|
42
|
+
/**
|
|
43
|
+
* This answer is not exactly the one that was given. Never an answerer's own flag.
|
|
44
|
+
*
|
|
45
|
+
* Two writers, two ceilings: `capAnswer` cuts the text to `DEFAULT_INQUIRY_ANSWER_CHARS` (and
|
|
46
|
+
* raises this WITHOUT cutting when a `value` arrived over that ceiling, since a shortened
|
|
47
|
+
* identifier matches no option), while `stateAnswerOf` cuts the text again to the much smaller
|
|
48
|
+
* `INQUIRY_STATE_TEXT_CHARS` a pipeline state may hold. So a flag read back off a resumed run
|
|
49
|
+
* says the state's copy is short — not that the person hit the answer ceiling.
|
|
50
|
+
*
|
|
51
|
+
* It exists so no cut is silent: whoever records the answer can say that the rest of it was
|
|
52
|
+
* dropped, instead of the answerer discovering it in the work that followed.
|
|
53
|
+
*/
|
|
54
|
+
truncated?: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* How a question reaches a person.
|
|
59
|
+
*
|
|
60
|
+
* One method, like `DelegateTransport` beside it, and for the same reason: routing, waiting,
|
|
61
|
+
* redelivery and giving up all belong to whoever implements it. A transport that cannot serve the
|
|
62
|
+
* question must THROW rather than answer — a declined answer is a decision, while a channel that
|
|
63
|
+
* is not there is terminal, and the two must never look alike.
|
|
64
|
+
*/
|
|
65
|
+
export interface InquiryTransport {
|
|
66
|
+
ask: (inquiry: Inquiry, signal?: AbortSignal) => Promise<InquiryAnswer>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* How one run may put a question to a person. Carried on an execution's serializable state, so a
|
|
71
|
+
* resumed run keeps the channel and the policy it was started with.
|
|
72
|
+
*/
|
|
73
|
+
export interface InquiryConfig {
|
|
74
|
+
/** The key the application seated an {@link InquiryTransport} under. */
|
|
75
|
+
transport?: string
|
|
76
|
+
policy: InquiryPolicy
|
|
77
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { inquiryHelper } from './helper.js'
|
|
2
|
+
import type { Inquiry, InquiryAnswer } from './types.js'
|
|
3
|
+
|
|
4
|
+
/** @deprecated compat:factory-refactor — use `inquiryHelper.defaultAnswerFor(…)` */
|
|
5
|
+
export const defaultAnswerFor = (inquiry: Inquiry): InquiryAnswer => inquiryHelper.defaultAnswerFor(inquiry)
|
|
6
|
+
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `inquiryHelper.answeredWith(…)` */
|
|
8
|
+
export const answeredWith = (answer: InquiryAnswer): string | null => inquiryHelper.answeredWith(answer)
|
|
9
|
+
|
|
10
|
+
/** @deprecated compat:factory-refactor — use `inquiryHelper.isDeclined(…)` */
|
|
11
|
+
export const isDeclined = (answer: InquiryAnswer): boolean => inquiryHelper.isDeclined(answer)
|
|
12
|
+
|
|
13
|
+
/** @deprecated compat:factory-refactor — use `inquiryHelper.capAnswer(…)` */
|
|
14
|
+
export const capAnswer = (answer: InquiryAnswer, max?: number): InquiryAnswer => inquiryHelper.capAnswer(answer, max)
|
|
15
|
+
|
|
16
|
+
/** @deprecated compat:factory-refactor — use `inquiryHelper.stateAnswerOf(…)` */
|
|
17
|
+
export const stateAnswerOf = (answer: InquiryAnswer): InquiryAnswer => inquiryHelper.stateAnswerOf(answer)
|
|
18
|
+
|
|
19
|
+
/** @deprecated compat:factory-refactor — use `inquiryHelper.renderInquiry(…)` */
|
|
20
|
+
export const renderInquiry = (inquiry: Inquiry): string => inquiryHelper.renderInquiry(inquiry)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed wording that introduces a {@link CumulativeResults} view in a prompt.
|
|
3
|
+
*
|
|
4
|
+
* Written for the WEAKEST model a pipeline may run on, so every rule is literal and says what to do
|
|
5
|
+
* rather than what to consider. It is a pure constant — no interpolation, no clock — because it
|
|
6
|
+
* opens a block that recurs verbatim on every call of a step, and the rules are the reason the
|
|
7
|
+
* block exists at all: a list of names with no instruction attached is read as a suggestion, and a
|
|
8
|
+
* suggestion is exactly what a model re-derives, renames or re-cases.
|
|
9
|
+
*
|
|
10
|
+
* The last rules carry the list's own limits. It is written between steps and can go stale in ways
|
|
11
|
+
* a live file read cannot, so a file actually shown in the conversation must win; and it may leave
|
|
12
|
+
* things out for space, so "not listed" means "does not exist yet" only when nothing was left out.
|
|
13
|
+
*/
|
|
14
|
+
export const CUMULATIVE_RESULTS_PREAMBLE = `## Results of earlier steps
|
|
15
|
+
|
|
16
|
+
Everything below was read from the project's files by code, after each earlier step of this work finished. No model wrote it.
|
|
17
|
+
|
|
18
|
+
Rules for using it:
|
|
19
|
+
- These are the AUTHORITATIVE names produced by earlier steps. Use every name, path and import specifier exactly as written here. Never re-derive, rename, re-case or guess a different path.
|
|
20
|
+
- Import a listed symbol only from the specifier listed for it.
|
|
21
|
+
- Never declare anything listed here a second time. Import it, call it or extend it instead.
|
|
22
|
+
- Anything the current task needs that this list does not contain does not exist yet, unless the list says it left something out for space; then look in the project's files first. Create a missing thing only if the task says to, and never under a name that merely resembles a listed one.
|
|
23
|
+
- A source file actually shown elsewhere in this conversation is NEWER than this list and wins wherever the two disagree: this list can go stale between steps, a file you are shown cannot.
|
|
24
|
+
- An entry marked "(names only)" lists names without their detail. Read that file before relying on its shape.
|
|
25
|
+
- A summary marked "(not verified)" was written by a model and never checked against the files. Treat it as a hint, never as a fact.`
|
|
26
|
+
|
|
27
|
+
/** Opens the line naming the steps a view left out for space. The names follow it. */
|
|
28
|
+
export const CUMULATIVE_RESULTS_OMITTED_LEAD = 'Not listed here for space:'
|
|
29
|
+
|
|
30
|
+
/** Closes that line — what the model is to do about a step it cannot see. */
|
|
31
|
+
export const CUMULATIVE_RESULTS_OMITTED_TAIL =
|
|
32
|
+
'Those steps finished and what they made exists in the project\'s files. Look there before creating anything they may already have made.'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One producing step's contribution to a {@link CumulativeResults} view, already rendered.
|
|
3
|
+
*
|
|
4
|
+
* `step` names the step that produced it — for a step of a pipeline composed under another, the
|
|
5
|
+
* composing path as well (`design/screens`) — so two pipelines' steps of the same name never read
|
|
6
|
+
* as one.
|
|
7
|
+
*/
|
|
8
|
+
export interface CumulativeResultsSection {
|
|
9
|
+
step: string
|
|
10
|
+
text: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What the earlier steps of a pipeline produced, cut for ONE later step.
|
|
15
|
+
*
|
|
16
|
+
* Serializable and immutable: it travels on `ExecutionState.results`, so it survives a snapshot and
|
|
17
|
+
* a restore, and a resumed run composes the same prompt the interrupted one did. Everything in it is
|
|
18
|
+
* already rendered — the view is cut by the pipeline runtime, where the budgets are known, and the
|
|
19
|
+
* prompt layer only places it.
|
|
20
|
+
*/
|
|
21
|
+
export interface CumulativeResults {
|
|
22
|
+
/** The step this view was cut for. */
|
|
23
|
+
step: string
|
|
24
|
+
/** Oldest first. Each is one producing step, rendered in full or as names only. */
|
|
25
|
+
sections: CumulativeResultsSection[]
|
|
26
|
+
/** Steps whose results exist but were left out of this view to stay inside its budget. */
|
|
27
|
+
omitted: string[]
|
|
28
|
+
/** Characters of the sections as rendered, separators included. */
|
|
29
|
+
chars: number
|
|
30
|
+
/**
|
|
31
|
+
* A digest of the sections — for a trace line or a debugger, to tell two views apart.
|
|
32
|
+
*
|
|
33
|
+
* NEVER rendered into a prompt: it is exactly the kind of varying, meaningless byte a model would
|
|
34
|
+
* copy into its answer or treat as an instruction.
|
|
35
|
+
*/
|
|
36
|
+
digest: string
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CUMULATIVE_RESULTS_OMITTED_LEAD, CUMULATIVE_RESULTS_OMITTED_TAIL, CUMULATIVE_RESULTS_PREAMBLE,
|
|
3
|
+
} from './consts.js'
|
|
4
|
+
import type { CumulativeResults } from './types.js'
|
|
5
|
+
import { SEPARATOR } from './consts.local.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A {@link CumulativeResults} view as prompt text, or `''` when there is nothing to say.
|
|
9
|
+
*
|
|
10
|
+
* Pure and total: the same view renders to the same bytes on every runtime, and an absent or empty
|
|
11
|
+
* view renders to NOTHING — not a heading over an empty list, which a model would read as "no
|
|
12
|
+
* earlier step produced anything" and act on. The view's digest is never rendered; its sections are
|
|
13
|
+
* placed in the order the view holds them, which is oldest first.
|
|
14
|
+
*/
|
|
15
|
+
export const renderCumulativeResults = (view: CumulativeResults | null | undefined): string => {
|
|
16
|
+
if (view == null) {
|
|
17
|
+
return ''
|
|
18
|
+
}
|
|
19
|
+
const sections = view.sections.map(section => section.text.trim()).filter(text => text !== '')
|
|
20
|
+
const omitted = view.omitted.filter(step => step.trim() !== '')
|
|
21
|
+
if (sections.length === 0 && omitted.length === 0) {
|
|
22
|
+
return ''
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const parts = [CUMULATIVE_RESULTS_PREAMBLE, ...sections]
|
|
26
|
+
if (omitted.length > 0) {
|
|
27
|
+
parts.push(
|
|
28
|
+
`${CUMULATIVE_RESULTS_OMITTED_LEAD} ${omitted.map(step => `\`${step}\``).join(', ')}. `
|
|
29
|
+
+ CUMULATIVE_RESULTS_OMITTED_TAIL,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return parts.join(SEPARATOR)
|
|
34
|
+
}
|
package/src/spectator/types.ts
CHANGED
|
@@ -9,6 +9,12 @@ export interface SpectatorArgument {
|
|
|
9
9
|
tries?: number
|
|
10
10
|
messages: SpectatorEntryMessage[]
|
|
11
11
|
startedAt?: number
|
|
12
|
+
/**
|
|
13
|
+
* The model that ANSWERED — the active rung's own model id, which differs from the role's
|
|
14
|
+
* primary once a fallback took over. Absent when the caller could not tell; a sink then falls
|
|
15
|
+
* back to its own resolution.
|
|
16
|
+
*/
|
|
17
|
+
model?: string
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
/** A stored spectator record — the argument plus the resolved call context. */
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { ExecutionEffort, ExecutionLevel, PromptBlock } from './consts.js'
|
|
1
|
+
import type { ExecutionEffort, ExecutionLevel, ModelEffort, PackagePurpose, PromptBlock } from './consts.js'
|
|
2
|
+
import type { InquiryConfig } from './inquiry/types.js'
|
|
3
|
+
import type { CumulativeResults } from './results/types.js'
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Free-form observability metadata attached to every model call — forwarded to the
|
|
@@ -32,6 +34,8 @@ export interface ModelConfigPatch {
|
|
|
32
34
|
maxTokensCap?: number
|
|
33
35
|
topP?: number
|
|
34
36
|
disableThinking?: boolean
|
|
37
|
+
/** Provider-native effort; clamped to what the model accepts, dropped where it accepts none. */
|
|
38
|
+
effort?: ModelEffort
|
|
35
39
|
/** Total window the model accepts (input + output). Informational / validation only. */
|
|
36
40
|
contextWindow?: number
|
|
37
41
|
/** What the PROVIDER can emit in one request. Hard ceiling for `maxTokens`/`maxTokensCap`. */
|
|
@@ -55,6 +59,12 @@ export interface ModelPolicy {
|
|
|
55
59
|
roleOverrides?: Partial<Record<ModelRole, ModelRole>>
|
|
56
60
|
/** "Pin a role to a specific model/config" — alias or partial config override. */
|
|
57
61
|
modelOverrides?: Partial<Record<ModelRole, ModelConfigOverride>>
|
|
62
|
+
/**
|
|
63
|
+
* Role resolved by `ExecutionService.utility` for cheap side calls. Defaults to
|
|
64
|
+
* `UTILITY_ROLE`; name another alias when the deployment calls its cheap tier
|
|
65
|
+
* something else. `roleOverrides` still applies on top of whichever one is used.
|
|
66
|
+
*/
|
|
67
|
+
utilityRole?: ModelRole
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/**
|
|
@@ -64,6 +74,48 @@ export interface ModelPolicy {
|
|
|
64
74
|
*/
|
|
65
75
|
export type CacheTtl = '5m' | '1h'
|
|
66
76
|
|
|
77
|
+
/**
|
|
78
|
+
* A cache lifetime per breakpoint of the prompt layout, earliest first. An omitted key keeps the
|
|
79
|
+
* level below it (the service default, then `'5m'`). Whatever is asked, the lifetimes never RISE
|
|
80
|
+
* along the prefix — a provider refuses a longer-lived entry after a shorter-lived one — so a
|
|
81
|
+
* `'1h'` behind a `'5m'` is clamped to `'5m'`.
|
|
82
|
+
*/
|
|
83
|
+
export interface CacheTtlPolicy {
|
|
84
|
+
/** The role + skills breakpoint — stable for a persona. */
|
|
85
|
+
skills?: CacheTtl
|
|
86
|
+
/** The packages breakpoint — stable for a persona working on one story. */
|
|
87
|
+
packages?: CacheTtl
|
|
88
|
+
/** The project message's breakpoint — stable for one step of the work. */
|
|
89
|
+
project?: CacheTtl
|
|
90
|
+
/** The breakpoint after the caller's `stable` lead messages — stable for one batch of calls. */
|
|
91
|
+
stable?: CacheTtl
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Which package documentation a persona works with, chosen ONCE per persona and story rather than
|
|
96
|
+
* detected from each message — so the packages block stays byte-identical for every call of that
|
|
97
|
+
* work. Present, it switches the package plugin from detection to selection; absent, packages are
|
|
98
|
+
* detected from the messages as before.
|
|
99
|
+
*
|
|
100
|
+
* Arrays merge down the execution chain as a first-seen union; the plugin sorts what it renders.
|
|
101
|
+
*/
|
|
102
|
+
export interface PromptFocus {
|
|
103
|
+
/** The `@owlmeans/*` packages whose documentation belongs in the cached packages block. */
|
|
104
|
+
packages?: string[]
|
|
105
|
+
/** Which parts of those packages to load, by what they are for. */
|
|
106
|
+
purposes?: PackagePurpose[]
|
|
107
|
+
/** Parts named outright, as `<package>#<part>` (`@owlmeans/web-panel#picker`). */
|
|
108
|
+
parts?: string[]
|
|
109
|
+
/** Domain types whose definitions belong in the project message. */
|
|
110
|
+
types?: string[]
|
|
111
|
+
/**
|
|
112
|
+
* Whether a package a call's messages IMPORT but the focus lacks is still loaded, into the
|
|
113
|
+
* uncached tail (cores only, capped). Defaults to `true`; `false` keeps the prompt to the focus.
|
|
114
|
+
* The deepest level that sets it wins.
|
|
115
|
+
*/
|
|
116
|
+
late?: boolean
|
|
117
|
+
}
|
|
118
|
+
|
|
67
119
|
/**
|
|
68
120
|
* One named, reusable chunk of system-prompt knowledge — a capability the model is told
|
|
69
121
|
* it has. Registered once (by the package that owns the knowledge or by the final app)
|
|
@@ -102,10 +154,15 @@ export interface PromptPolicy {
|
|
|
102
154
|
role?: string
|
|
103
155
|
/** Skill aliases enabled at this level. */
|
|
104
156
|
skills?: string[]
|
|
105
|
-
/** Mark the composed system
|
|
157
|
+
/** Mark the composed prompt cacheable (system and project message). Defaults to `true`. */
|
|
106
158
|
cacheSystem?: boolean
|
|
107
|
-
/**
|
|
108
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Cache lifetimes: one for every breakpoint, or one per breakpoint. Defaults to `'5m'`
|
|
161
|
+
* everywhere; `'1h'` is opt-in and never rises along the prefix (see {@link CacheTtlPolicy}).
|
|
162
|
+
*/
|
|
163
|
+
cacheTtl?: CacheTtl | CacheTtlPolicy
|
|
164
|
+
/** Which package documentation and types this work uses — see {@link PromptFocus}. */
|
|
165
|
+
focus?: PromptFocus
|
|
109
166
|
}
|
|
110
167
|
|
|
111
168
|
/**
|
|
@@ -116,8 +173,13 @@ export interface PromptPolicy {
|
|
|
116
173
|
export interface CacheUsage {
|
|
117
174
|
/** Tokens served from cache (~0.1x price). */
|
|
118
175
|
read: number
|
|
119
|
-
/** Tokens written to cache (~1.25x price at 5m TTL, ~2x at 1h). */
|
|
176
|
+
/** Tokens written to cache (~1.25x price at 5m TTL, ~2x at 1h) — both lifetimes together. */
|
|
120
177
|
creation: number
|
|
178
|
+
/**
|
|
179
|
+
* Of {@link creation}, the tokens written at the 1-hour TTL. Present only when the provider
|
|
180
|
+
* reported a non-zero 1-hour write.
|
|
181
|
+
*/
|
|
182
|
+
creationLong?: number
|
|
121
183
|
/** Tokens processed at full price. */
|
|
122
184
|
input: number
|
|
123
185
|
output: number
|
|
@@ -135,11 +197,33 @@ export interface ExecutionState {
|
|
|
135
197
|
policy: ModelPolicy
|
|
136
198
|
/** Role + skills for this level; merged downward by `ExecutionService`. */
|
|
137
199
|
prompt?: PromptPolicy
|
|
200
|
+
/**
|
|
201
|
+
* How this run may put a question to a person. Serializable, and deliberately NOT a
|
|
202
|
+
* collaborator: a run that is resumed days later must ask through the same channel, under the
|
|
203
|
+
* same policy, as the one that parked it.
|
|
204
|
+
*/
|
|
205
|
+
inquiry?: InquiryConfig
|
|
206
|
+
/**
|
|
207
|
+
* What the earlier steps of the pipeline this execution works inside produced, cut for the step
|
|
208
|
+
* at hand. Rendered into `PromptBlock.Results` by the prompt service.
|
|
209
|
+
*
|
|
210
|
+
* State, not a collaborator: it is plain rendered text, and a resumed run must compose the
|
|
211
|
+
* prompt the interrupted one did. Inherited by every refinement like any other state field, and
|
|
212
|
+
* replaced — never merged — when a later step is handed its own view.
|
|
213
|
+
*/
|
|
214
|
+
results?: CumulativeResults
|
|
138
215
|
}
|
|
139
216
|
|
|
140
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* The task level's own fields.
|
|
219
|
+
*
|
|
220
|
+
* `phase`, `completed` and `cursor` are LABELS — for a trace line, a prompt, a log — and never a
|
|
221
|
+
* workflow position. Recoverable position lives on a pipeline run row (`@owlmeans/agent`), which is
|
|
222
|
+
* a single authority; an execution that also claimed to know where a run stood would be a second
|
|
223
|
+
* one, and the two would disagree the first time a step wrote only one of them.
|
|
224
|
+
*/
|
|
141
225
|
export interface TaskExecutionState extends ExecutionState {
|
|
142
|
-
/**
|
|
226
|
+
/** A label for the stage a task considers itself in. Never read back to decide anything. */
|
|
143
227
|
phase?: string
|
|
144
228
|
completed?: string[]
|
|
145
229
|
cursor?: string
|
|
@@ -177,7 +261,10 @@ export interface NullCapture {
|
|
|
177
261
|
request: {
|
|
178
262
|
messages: unknown[]
|
|
179
263
|
schema?: { toolName: string; innerSchema: unknown }
|
|
264
|
+
/** Whether the prepared request carried at least one cache breakpoint. */
|
|
180
265
|
useCache: boolean
|
|
266
|
+
/** How many lead messages the caller declared stable across calls (`LlmCallOptions.stable`). */
|
|
267
|
+
stable?: number
|
|
181
268
|
}
|
|
182
269
|
response: {
|
|
183
270
|
content: unknown
|
|
@@ -187,11 +274,18 @@ export interface NullCapture {
|
|
|
187
274
|
tool_calls?: unknown
|
|
188
275
|
} | null
|
|
189
276
|
diagnostics: {
|
|
277
|
+
/** Whatever the provider called it — OpenAI's `finish_reason` or Anthropic's `stop_reason`. */
|
|
190
278
|
finishReason?: string
|
|
191
279
|
inputTokens?: number
|
|
192
280
|
outputTokens?: number
|
|
193
281
|
reasoningTokens?: number
|
|
194
282
|
contentEmpty: boolean
|
|
283
|
+
/**
|
|
284
|
+
* Content arrived, but none of it was text — the shape of an answer that was all reasoning.
|
|
285
|
+
* Distinguishes "spent the budget thinking" from "returned nothing at all", which
|
|
286
|
+
* `contentEmpty` alone cannot.
|
|
287
|
+
*/
|
|
288
|
+
thinkingOnly?: boolean
|
|
195
289
|
hadToolCall: boolean
|
|
196
290
|
}
|
|
197
291
|
}
|