@owlmeans/llm 0.1.18-rc.6 → 0.1.18-rc.9
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/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/llm/SKILL.md +108 -3
- package/build/execution/service.d.ts.map +1 -1
- package/build/execution/service.js +30 -5
- package/build/execution/service.js.map +1 -1
- package/build/execution/types.d.ts +46 -5
- package/build/execution/types.d.ts.map +1 -1
- package/build/helpers/spectate.d.ts.map +1 -1
- package/build/helpers/spectate.js +12 -5
- package/build/helpers/spectate.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/model.d.ts.map +1 -1
- package/build/model.js +30 -17
- package/build/model.js.map +1 -1
- package/build/plugins/anthropic.d.ts +13 -0
- package/build/plugins/anthropic.d.ts.map +1 -1
- package/build/plugins/anthropic.js +42 -5
- package/build/plugins/anthropic.js.map +1 -1
- package/build/plugins/openai.d.ts +12 -0
- package/build/plugins/openai.d.ts.map +1 -1
- package/build/plugins/openai.js +29 -3
- package/build/plugins/openai.js.map +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js +42 -7
- package/build/service.js.map +1 -1
- package/build/types.d.ts +57 -1
- package/build/types.d.ts.map +1 -1
- package/build/utils/config.d.ts +11 -0
- package/build/utils/config.d.ts.map +1 -1
- package/build/utils/config.js +21 -1
- package/build/utils/config.js.map +1 -1
- package/package.json +8 -8
- package/src/execution/service.ts +30 -5
- package/src/execution/types.ts +50 -5
- package/src/helpers/spectate.ts +14 -5
- package/src/index.ts +4 -2
- package/src/model.ts +44 -17
- package/src/plugins/anthropic.ts +46 -5
- package/src/plugins/openai.ts +33 -3
- package/src/service.ts +53 -7
- package/src/types.ts +57 -1
- package/src/utils/config.ts +23 -1
- package/tests/execution.spec.ts +81 -0
- package/tests/helpers.spec.ts +4 -1
- package/tests/plugins.spec.ts +141 -0
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/llm",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-08-
|
|
4
|
+
"version": "0.1.18-rc.8",
|
|
5
|
+
"generatedAt": "2026-08-29T20:14:19.669Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/llm
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/llm": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/llm": "^0.1.18-rc.8"` in `dependencies` (plus the `@langchain/*` peers)
|
|
12
12
|
|
|
13
13
|
The inference runtime. Everything provider-specific is a **plugin**; the model itself only
|
|
14
14
|
owns the provider-independent parts (streaming discipline, retries, validation,
|
|
@@ -21,7 +21,7 @@ observability). Serializable contracts live in `@owlmeans/llm-common`.
|
|
|
21
21
|
| `makeLlmModel(options, spectator)` | The four-method model: `ask` / `talk` / `invoke` / `request`. |
|
|
22
22
|
| `makeLlmService(options, alias?)` · `appendLlmService(ctx, options, alias?)` | Model factory/registry — resolves a `ModelConfig` by alias, memoized per alias+override. |
|
|
23
23
|
| `llmServiceApi(options, self)` | The factory half WITHOUT `createService`, to compose into your own service (role accessors, domain helpers). |
|
|
24
|
-
| `makeExecutionService(alias?, options?)` · `appendExecutionService(ctx, alias?, options?)` | Frozen 3-level executions + policy resolution + snapshot/restore/checkpoint. |
|
|
24
|
+
| `makeExecutionService(alias?, options?)` · `appendExecutionService(ctx, alias?, options?)` | Frozen 3-level executions + policy resolution + snapshot/restore/checkpoint + advice. |
|
|
25
25
|
| `makePromptService(options?, alias?)` · `appendPromptService(ctx, options?, alias?)` · `promptServiceApi(options, self)` | Skill registry + the composition plugin chain. Also at `@owlmeans/llm/prompt`. |
|
|
26
26
|
| `rolePlugin`, `skillsPlugin`, `contextPlugin`, `BUILT_IN_PROMPT_PLUGINS` | The built-in composition plugins. |
|
|
27
27
|
| `renderSkill`, `sortSkills`, `joinChunks`, `compareAlias`, `prefixHash` | Deterministic rendering primitives — reuse them, never re-implement. |
|
|
@@ -29,6 +29,8 @@ observability). Serializable contracts live in `@owlmeans/llm-common`.
|
|
|
29
29
|
| `executionServiceApi(options, self)` | The execution half without `createService`, for the same composition pattern. |
|
|
30
30
|
| `plugins`, `registerLlmPlugin`, `resolvePlugin`, `pluginOf`, `pluginFor` | The provider-plugin registry. Also at `@owlmeans/llm/plugins`. |
|
|
31
31
|
| `anthropicPlugin`, `openAiPlugin`, `compatiblePlugin`, `openAiFamily` | Built-in providers; `openAiFamily` is the shared OpenAI-client behaviour to spread into a new plugin. |
|
|
32
|
+
| `NO_SAMPLING_PREFIXES`, `rejectsSampling(model)` | Which Claude families reject `temperature`/`top_p`/`top_k` (4.7+ and the 5 family). Consumers pin presets against it. |
|
|
33
|
+
| `RESPONSES_API_PREFIXES`, `usesResponsesApi(model)` | Which OpenAI families go through the Responses API and therefore reject `temperature`/`top_p` (`gpt-5*`, `codex-*`). The OpenAI counterpart of the pair above; consumers pin presets against it. |
|
|
32
34
|
| `withRetry`, `registerFatalError`, `spectate`, `normalizeInput`, `parseJsonContent`, `coerceToSchema` | Helpers usable alongside a model. Also at `@owlmeans/llm/helpers`. |
|
|
33
35
|
| `LlmError`, `LlmModelError`, `LlmMissconfiguredError`, `LlmPluginError`, `LlmRetryExceededError` | `ResilientError` family. `LlmModelError` is the RETRYABLE one. |
|
|
34
36
|
| `mergePrompt`, `mergePolicy`, `resolveRole`, `effortPatch` | Execution merge helpers; `mergePrompt` unions skills and takes the deepest role. |
|
|
@@ -60,6 +62,32 @@ Adding a function? Decide which side it belongs to first, then place it. Do not
|
|
|
60
62
|
| `cacheKey` (via `ModelConfig.cacheKey`) | provider cache-routing hints such as OpenAI's `prompt_cache_key` |
|
|
61
63
|
| `isFatal` | "this error can never be retried" |
|
|
62
64
|
|
|
65
|
+
### A provider that removes a parameter is a plugin concern too
|
|
66
|
+
|
|
67
|
+
`build` is not the only place a parameter reaches the wire, and `refine` is not only a retry
|
|
68
|
+
hook — **every** call is made on the instance `refine` returns, attempt 0 included. A knob
|
|
69
|
+
suppressed in `build` and re-applied in `refine` therefore ships on every single request, not
|
|
70
|
+
on a retry: an unsupported `temperature` restored there 400s the model's whole family on the
|
|
71
|
+
first call, and `isFatal` correctly refuses to retry it, so the failure is immediate and total.
|
|
72
|
+
|
|
73
|
+
Both built-in plugins gate their rejected parameters in **both** hooks, through a predicate the
|
|
74
|
+
package root exports:
|
|
75
|
+
|
|
76
|
+
| Family | Rejects | Predicate |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| Claude 4.7+ and the 5 family | `temperature`, `top_p`, `top_k` | `NO_SAMPLING_PREFIXES` / `rejectsSampling(model)` |
|
|
79
|
+
| OpenAI Responses API (`gpt-5*`, `codex-*`) | `temperature`, `top_p` | `RESPONSES_API_PREFIXES` / `usesResponsesApi(model)` |
|
|
80
|
+
|
|
81
|
+
Models below those lines keep the deterministic `temperature: 0` default. `refine` reads the
|
|
82
|
+
id off the ACTIVE base (`model.model ?? lc_kwargs.model`), so a same-family `fallback` rung is
|
|
83
|
+
judged on its own id rather than the primary's, and the OpenAI check also accepts a
|
|
84
|
+
`useResponsesApi` already on `lc_kwargs`.
|
|
85
|
+
|
|
86
|
+
Export the predicate rather than keeping it private: consumers pin presets against it
|
|
87
|
+
(`viable-agent`'s `tests/presets.test.ts` asserts no preset entry declares a parameter its
|
|
88
|
+
model rejects), and a second hand-written copy of the list drifts exactly when a new family is
|
|
89
|
+
added — the moment it has to be right.
|
|
90
|
+
|
|
63
91
|
**Registration order is load-bearing.** Instance-based lookup (`pluginFor`) returns the
|
|
64
92
|
FIRST plugin whose `owns` matches. `compatible` is registered before `openai` because both
|
|
65
93
|
build a `ChatOpenAI`, and assuming the tool-calling hack for an unlabelled model is safe
|
|
@@ -102,6 +130,23 @@ inherited method signatures**, which would be a contravariance error.
|
|
|
102
130
|
`snapshot` excludes `state` itself; without that, every `derive`/`escalate`/`withPurpose`
|
|
103
131
|
on a task would nest another copy of the previous state.
|
|
104
132
|
|
|
133
|
+
`forHelper` also accepts `output` — an initial `maxTokens` for a helper whose one answer is
|
|
134
|
+
genuinely large (a whole source file rather than a decision). It is a model selector, not a
|
|
135
|
+
field the helper carries: it becomes a call override, is clamped to `maxOutput`, doubles from
|
|
136
|
+
there under retry, and survives `temperatureFactory`.
|
|
137
|
+
|
|
138
|
+
### The plugin seam has two hooks, dispatched independently
|
|
139
|
+
|
|
140
|
+
`ExecutionPlugin` carries `onCheckpoint`/`onRestore` (persist and resume an
|
|
141
|
+
`ExecutionState`) and `advise` (answer a performer's question about the project it is
|
|
142
|
+
working in — `ExecutionService.advise(exec, request)`, first usable answer wins, a throwing
|
|
143
|
+
plugin is skipped, `null` when nobody answers). Advice is advisory by contract: a caller
|
|
144
|
+
appends whatever comes back and proceeds unchanged on `null`.
|
|
145
|
+
|
|
146
|
+
`checkpoint` dispatches on plugins that declare **`onCheckpoint`**, not on the plugin count —
|
|
147
|
+
otherwise registering an advise-only plugin would silently start composing snapshots nobody
|
|
148
|
+
consumes.
|
|
149
|
+
|
|
105
150
|
## Classify a provider error by walking `cause`, never by `instanceof` or a surface read
|
|
106
151
|
|
|
107
152
|
Two independent layers hide the wire shape of a provider failure, and each one alone is
|
|
@@ -162,10 +207,70 @@ Note what this does NOT bound: a call that keeps streaming forever, and retries.
|
|
|
162
207
|
error misclassified as retryable multiplies its own latency by `DEFAULT_MODEL_RETRIES` —
|
|
163
208
|
see the `instanceof` trap above.
|
|
164
209
|
|
|
210
|
+
## An outer validation loop must pass its attempt in
|
|
211
|
+
|
|
212
|
+
A caller that validates the OUTPUT — a diff that has to apply, a file that must not come
|
|
213
|
+
back truncated — runs its own retry loop around whole `ask` calls. Every one of those calls
|
|
214
|
+
starts a FRESH inner loop at attempt 0, so the escalator's two rungs never move: same model,
|
|
215
|
+
same output budget, same deterministic answer, N times. Pass `escalation: <outer attempt>`
|
|
216
|
+
in `LlmCallOptions` and the per-call escalator starts that far up its ladder instead —
|
|
217
|
+
`maxTokens` doubling and the `FALLBACK_AFTER_ATTEMPTS` switch to `ModelConfig.fallback` both
|
|
218
|
+
advance. It is clamped to `retries - 1`, moves the STARTING rung only, and never changes how
|
|
219
|
+
many attempts the call itself makes.
|
|
220
|
+
|
|
221
|
+
Two things this depends on, and both are preset data rather than code: the role must
|
|
222
|
+
actually declare a `fallback`, and that fallback must be in the same plugin `family` (a
|
|
223
|
+
cross-family one is skipped with a warning, because switching provider mid-call flips the
|
|
224
|
+
structured-output shape).
|
|
225
|
+
|
|
226
|
+
`LlmCallOptions.fatal` is the matching lever in the other direction — a per-call resolver
|
|
227
|
+
consulted before the global ones and the plugin's `isFatal`, for an error the caller knows
|
|
228
|
+
no retry can fix.
|
|
229
|
+
|
|
230
|
+
## Output caps: what the deployment wants vs what the provider allows
|
|
231
|
+
|
|
232
|
+
Four fields, and conflating them is what turns an escalation into a fatal 400 hours into a
|
|
233
|
+
run:
|
|
234
|
+
|
|
235
|
+
| Field | Means |
|
|
236
|
+
|---|---|
|
|
237
|
+
| `maxTokens` | the budget asked for on the FIRST attempt |
|
|
238
|
+
| `maxTokensCap` | the ceiling the deployment budgets for the escalator |
|
|
239
|
+
| `maxOutput` | what the PROVIDER accepts in one request — a fact about the model |
|
|
240
|
+
| `contextWindow` | total window (input + output); informational, never sent |
|
|
241
|
+
|
|
242
|
+
`resolveOutputCap` (`utils/config.ts`) is the one place that reconciles them: the declared
|
|
243
|
+
cap chooses the ceiling and the capability trims it, and `DEFAULT_MAX_OUTPUT_CAP` applies
|
|
244
|
+
only when neither is stated. `createModel` additionally clamps `maxTokens` to `maxOutput`
|
|
245
|
+
and warns about a cap above it. For an aggregated model `maxOutput` is the limit of the
|
|
246
|
+
`inferenceProvider` actually pinned, which is often far below what the model can do
|
|
247
|
+
elsewhere. `combinedWindow: true` marks a model whose window is shared between input and
|
|
248
|
+
output (MiniMax M2.x, gpt-oss) — nothing enforces it at runtime; it keeps presets honest
|
|
249
|
+
about leaving room for the prompt.
|
|
250
|
+
|
|
251
|
+
**A `fallback` that changes `model` must restate `contextWindow`/`maxOutput`** (and reset
|
|
252
|
+
`combinedWindow`): the fallback config is `{...primaryConfig, ...fallback}`, so every field
|
|
253
|
+
the patch does not name is inherited from a different model.
|
|
254
|
+
|
|
255
|
+
## Config precedence: a preset is a base, not a final word
|
|
256
|
+
|
|
257
|
+
`createModel` layers four sources, lowest first:
|
|
258
|
+
|
|
259
|
+
presetOf(base.preset) < base < presetOf(override.preset) < override
|
|
260
|
+
|
|
261
|
+
A `preset` is a BASE that its referent refines, so it sits UNDER the config naming it.
|
|
262
|
+
Assigning it last — as this did until the layering was fixed — meant a role declaring
|
|
263
|
+
`preset:` silently discarded both its own fields and the caller's override, which is how
|
|
264
|
+
effort-tier token caps and `temperatureFactory`'s temperature vanished for preset-based
|
|
265
|
+
roles. An override naming a preset (how the execution layer delivers a `modelOverrides`
|
|
266
|
+
string pin) outranks the alias but still yields to explicit override fields. Resolution is
|
|
267
|
+
ONE level deep: a preset meant to carry a model must name one.
|
|
268
|
+
|
|
165
269
|
## Resilience already handled — do not reimplement
|
|
166
270
|
|
|
167
271
|
Idle stream deadline · duplicate-final-chunk dedup · output-budget escalation · reasoning-cap
|
|
168
|
-
shrink · same-family fallback model ·
|
|
272
|
+
shrink · same-family fallback model · caller-seeded ladder position (`escalation`) · schema
|
|
273
|
+
coercion · JSON salvage from prose · `NullCapture`
|
|
169
274
|
diagnostics · fatal-error short-circuit · blank-content sanitization (whitespace-only text
|
|
170
275
|
blocks are dropped before every call — a blank block, e.g. an empty file read pasted into a
|
|
171
276
|
prompt, is otherwise a fatal Anthropic 400; blank tool results are stubbed to keep their
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/execution/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAKlE,OAAO,KAAK,EACkB,gBAAgB,EAAE,uBAAuB,EAAE,cAAc,EACrD,oBAAoB,EACrD,MAAM,YAAY,CAAA;AAMnB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,WAClE,uBAAuB,QAC1B,MAAM,gBAAgB,CAAC,CAAC,CAAC,KAC9B,gBAAgB,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/execution/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAKlE,OAAO,KAAK,EACkB,gBAAgB,EAAE,uBAAuB,EAAE,cAAc,EACrD,oBAAoB,EACrD,MAAM,YAAY,CAAA;AAMnB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,WAClE,uBAAuB,QAC1B,MAAM,gBAAgB,CAAC,CAAC,CAAC,KAC9B,gBAAgB,CAAC,CAAC,CA2JpB,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,UACrE,MAAM,YACJ,uBAAuB,KAC/B,gBAAgB,CAAC,CAAC,CAMpB,CAAA;AAED,eAAO,MAAM,sBAAsB,GACjC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,cAAc,GAAG,cAAc,OAEtF,CAAC,UACC,MAAM,YACJ,uBAAuB,KAC/B,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAQ5B,CAAA"}
|
|
@@ -61,10 +61,13 @@ export const executionServiceApi = (options, self) => {
|
|
|
61
61
|
return freeze(taskExec);
|
|
62
62
|
},
|
|
63
63
|
forHelper: (parent, input) => {
|
|
64
|
-
const { role, effort, dedication, prompt, ...extras } = input;
|
|
64
|
+
const { role, effort, dedication, prompt, output, ...extras } = input;
|
|
65
65
|
const localPolicy = effort != null ? mergePolicy(parent.policy, { effort }) : parent.policy;
|
|
66
66
|
const scoped = { ...parent, policy: localPolicy };
|
|
67
67
|
const merged = mergePrompt(parent.prompt, prompt);
|
|
68
|
+
// Destructured out of `extras` deliberately: `output` selects a model budget, it is
|
|
69
|
+
// not a field the helper carries around.
|
|
70
|
+
const sizing = output != null ? { maxTokens: output } : undefined;
|
|
68
71
|
const helperExec = {
|
|
69
72
|
...parent,
|
|
70
73
|
...extras,
|
|
@@ -75,8 +78,8 @@ export const executionServiceApi = (options, self) => {
|
|
|
75
78
|
policy: localPolicy,
|
|
76
79
|
...(merged != null ? { prompt: merged } : {}),
|
|
77
80
|
role: resolveRole(localPolicy, role),
|
|
78
|
-
model: self().model(scoped, role),
|
|
79
|
-
temperatureFactory: self().temperatureFactory(scoped, role),
|
|
81
|
+
model: self().model(scoped, role, sizing),
|
|
82
|
+
temperatureFactory: self().temperatureFactory(scoped, role, sizing),
|
|
80
83
|
};
|
|
81
84
|
// A helper is not resumable — drop a parent task's composed state.
|
|
82
85
|
delete helperExec.state;
|
|
@@ -93,7 +96,10 @@ export const executionServiceApi = (options, self) => {
|
|
|
93
96
|
const clean = Object.fromEntries(Object.entries(merged).filter(([, value]) => value !== undefined));
|
|
94
97
|
return exec.models().getModel(effectiveRole, clean);
|
|
95
98
|
},
|
|
96
|
-
temperatureFactory: (exec, role) => temperature => self().model(exec, role, {
|
|
99
|
+
temperatureFactory: (exec, role, baseOverride) => temperature => self().model(exec, role, {
|
|
100
|
+
// A budget the helper was built with survives a temperature refinement — the
|
|
101
|
+
// work is the same size whether or not it is being retried creatively.
|
|
102
|
+
...(typeof baseOverride === 'object' ? baseOverride : {}),
|
|
97
103
|
...(temperature != null ? { temperature } : {}),
|
|
98
104
|
...(temperature != null && temperature > 0.2 ? { topP: 0.8 } : {}),
|
|
99
105
|
}),
|
|
@@ -101,12 +107,31 @@ export const executionServiceApi = (options, self) => {
|
|
|
101
107
|
plugins.push(plugin);
|
|
102
108
|
},
|
|
103
109
|
checkpoint: async (exec, key) => {
|
|
104
|
-
|
|
110
|
+
// Guarded on the HOOK, not on the plugin count: a plugin registered for `advise`
|
|
111
|
+
// alone must not make checkpointing start composing snapshots nobody consumes.
|
|
112
|
+
if (!plugins.some(plugin => plugin.onCheckpoint != null)) {
|
|
105
113
|
return;
|
|
106
114
|
}
|
|
107
115
|
const state = self().snapshot(exec);
|
|
108
116
|
await Promise.all(plugins.map(plugin => plugin.onCheckpoint?.(state, exec, key)));
|
|
109
117
|
},
|
|
118
|
+
advise: async (exec, request) => {
|
|
119
|
+
for (const plugin of plugins) {
|
|
120
|
+
if (plugin.advise == null)
|
|
121
|
+
continue;
|
|
122
|
+
try {
|
|
123
|
+
const advice = await plugin.advise(exec, request);
|
|
124
|
+
if (advice != null && advice.trim() !== '') {
|
|
125
|
+
return advice;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
// Advice is an optimization. A broken advisor must never take the work with it.
|
|
130
|
+
console.warn(`Execution advisor failed for "${request.kind}":`, e);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
},
|
|
110
135
|
snapshot: exec => {
|
|
111
136
|
if (exec.level === ExecutionLevel.Task) {
|
|
112
137
|
return freeze({ ...exec.state });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/execution/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MA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AwB,CAC7E,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAGpC,GAAM,EACN,KAAK,GAAW,iBAAiB,EACjC,OAAO,GAA4B,EAAE,EACR,EAAE;IAC/B,MAAM,OAAO,GAAG,GAAkC,CAAA;IAElD,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAI,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IAEhE,OAAO,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAsB,KAAK,CAAC,CAAA;IAEtE,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -69,6 +69,16 @@ export interface HelperExecutionInput {
|
|
|
69
69
|
prompt?: PromptPolicy;
|
|
70
70
|
/** Refines `purpose.dedication`. */
|
|
71
71
|
dedication?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Initial output-token budget for this helper's model (`ModelConfig.maxTokens`), for
|
|
74
|
+
* work whose ONE answer is genuinely large — a whole source file rather than a decision.
|
|
75
|
+
*
|
|
76
|
+
* The role's preset value sizes the common case; a helper that routinely needs more
|
|
77
|
+
* would otherwise spend its first attempt producing a truncated answer and only reach a
|
|
78
|
+
* workable budget through the retry escalator, which doubles from this number. Clamped
|
|
79
|
+
* to the provider's `maxOutput` and preserved across `temperatureFactory`.
|
|
80
|
+
*/
|
|
81
|
+
output?: number;
|
|
72
82
|
}
|
|
73
83
|
/** Collaborators re-attached to a state that was restored from storage. */
|
|
74
84
|
export interface RestoreCollaborators {
|
|
@@ -77,16 +87,35 @@ export interface RestoreCollaborators {
|
|
|
77
87
|
files?: FileProviderRef;
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
|
-
*
|
|
90
|
+
* What a performer wants to know before it acts. Runtime-only — never snapshotted, so it
|
|
91
|
+
* carries whatever the advisor and its callers agree on.
|
|
92
|
+
*/
|
|
93
|
+
export interface AdviceRequest {
|
|
94
|
+
/** Which advisor is being asked; an advisor that does not own this kind returns null. */
|
|
95
|
+
kind: string;
|
|
96
|
+
/** The work at hand, in the caller's own words — normally the assignment text. */
|
|
97
|
+
task: string;
|
|
98
|
+
/** Anything that narrows the answer (a subproject, a path prefix, an entity). */
|
|
99
|
+
hints?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Extension seam. A plugin observes flow boundaries (via
|
|
81
103
|
* {@link ExecutionService.checkpoint}) and can persist/enqueue the JSON-safe
|
|
82
|
-
* {@link ExecutionState}, or supply one back on resume
|
|
83
|
-
*
|
|
104
|
+
* {@link ExecutionState}, or supply one back on resume; it may also ANSWER a performer's
|
|
105
|
+
* question about its surroundings (`advise`). This package ships NO concrete
|
|
106
|
+
* implementation — with no plugin registered, both seams are no-ops.
|
|
84
107
|
*/
|
|
85
108
|
export interface ExecutionPlugin {
|
|
86
109
|
/** Fired at a flow boundary with a JSON-safe snapshot; persist/enqueue as desired. */
|
|
87
110
|
onCheckpoint?: (state: ExecutionState, exec: Execution, key?: string) => Promise<void>;
|
|
88
111
|
/** Resume hook: return a previously persisted state for `key`, or `null`. */
|
|
89
112
|
onRestore?: (key: string) => Promise<ExecutionState | null>;
|
|
113
|
+
/**
|
|
114
|
+
* Answer a performer's question about the project it is working in. Return the text to
|
|
115
|
+
* hand the model, or `null` when this plugin does not own the request's `kind` — or
|
|
116
|
+
* cannot answer it. Advice is advisory: a `null` never blocks the work.
|
|
117
|
+
*/
|
|
118
|
+
advise?: (exec: Execution, request: AdviceRequest) => Promise<string | null>;
|
|
90
119
|
}
|
|
91
120
|
/**
|
|
92
121
|
* The set of domain types an {@link ExecutionService} works with. A consumer declares
|
|
@@ -117,13 +146,25 @@ export interface ExecutionService<S extends ExecutionShape = ExecutionShape> ext
|
|
|
117
146
|
withPurpose: <E extends S['exec']>(exec: E, patch: Partial<S['purpose']>) => E;
|
|
118
147
|
escalate: <E extends S['exec']>(exec: E, patch: Partial<ModelPolicy>) => E;
|
|
119
148
|
model: (exec: S['exec'], role?: ModelRole, override?: ModelConfigOverride) => BaseChatModel;
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
/**
|
|
150
|
+
* A factory that re-resolves the same role at another temperature. `baseOverride` is
|
|
151
|
+
* layered UNDER the temperature patch, so a caller-chosen budget (see
|
|
152
|
+
* `HelperExecutionInput.output`) survives the refinement.
|
|
153
|
+
*/
|
|
154
|
+
temperatureFactory: (exec: S['exec'], role?: ModelRole, baseOverride?: ModelConfigOverride) => TemperatureFactory;
|
|
155
|
+
/** Register an execution plugin (checkpoint/resume, advice). No-op seam until provided. */
|
|
122
156
|
use: (plugin: ExecutionPlugin) => void;
|
|
123
157
|
/** Snapshot `exec` and dispatch it to every registered plugin. No-op if none. */
|
|
124
158
|
checkpoint: (exec: S['exec'], key?: string) => Promise<void>;
|
|
125
159
|
snapshot: (exec: S['exec']) => ExecutionState;
|
|
126
160
|
restore: (state: ExecutionState, collaborators?: S['collaborators']) => S['exec'];
|
|
161
|
+
/**
|
|
162
|
+
* Ask the registered plugins about the project this execution runs in. Plugins are
|
|
163
|
+
* consulted in registration order and the FIRST usable answer wins, so one advisor owns
|
|
164
|
+
* each `kind` rather than several concatenating half-answers. Never throws: a plugin
|
|
165
|
+
* that fails is skipped, and `null` means nobody answered.
|
|
166
|
+
*/
|
|
167
|
+
advise: (exec: S['exec'], request: AdviceRequest) => Promise<string | null>;
|
|
127
168
|
}
|
|
128
169
|
export interface ExecutionServiceOptions {
|
|
129
170
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/execution/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EACV,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAC5E,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,KAClE,kBAAkB,CAAA;IAGvB,2FAA2F;IAC3F,GAAG,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAA;IACtC,iFAAiF;IACjF,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5D,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,cAAc,CAAA;IAC7C,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAA;IAEjF;;;;;OAKG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CAC5E;AAED,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC5B;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc;IAC7E,UAAU,EAAE,MAAM,gBAAgB,CAAC,CAAC,CAAC,CAAA;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spectate.d.ts","sourceRoot":"","sources":["../../src/helpers/spectate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAA;AAIjE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"spectate.d.ts","sourceRoot":"","sources":["../../src/helpers/spectate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAe,MAAM,0BAA0B,CAAA;AAIjE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAwC/D;;;GAGG;AACH,eAAO,MAAM,QAAQ,cAAe,YAAY,YAAY,MAAM,aAEvD,cAAc,EAAE,WACd,SAAS,UACV,MAAM,WACL,MAAM,cACH,MAAM,iEA+BnB,CAAA"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { BaseMessage } from '@langchain/core/messages';
|
|
2
2
|
import { SpectatorContentType } from '@owlmeans/llm-common';
|
|
3
3
|
import { hasCacheActivity, readCacheUsage } from './cache.js';
|
|
4
|
+
/**
|
|
5
|
+
* The trace's `content` column is a string; LangChain content is a string-or-blocks union, and
|
|
6
|
+
* tool calls are arrays. Anything non-string must be stored as JSON — a plain string coercion
|
|
7
|
+
* downstream turns it into `[object Object]` and destroys the readable half of the trace
|
|
8
|
+
* (`raw` keeps the payload, but `content` is what trace readers query).
|
|
9
|
+
*/
|
|
10
|
+
const asText = (content) => typeof content === 'string' ? content : JSON.stringify(content) ?? '';
|
|
4
11
|
/** Normalize one prompt message into the spectator's storage shape. */
|
|
5
12
|
const describeInput = (msg, callType) => {
|
|
6
13
|
const entry = {
|
|
@@ -11,7 +18,7 @@ const describeInput = (msg, callType) => {
|
|
|
11
18
|
};
|
|
12
19
|
if (msg instanceof BaseMessage) {
|
|
13
20
|
entry.type = msg.type;
|
|
14
|
-
entry.content = msg.content;
|
|
21
|
+
entry.content = asText(msg.content);
|
|
15
22
|
entry.name = msg.name;
|
|
16
23
|
entry.contentType = typeof msg.content === 'string' ? SpectatorContentType.Text : SpectatorContentType.Json;
|
|
17
24
|
entry.usage = 'usage_metadata' in msg ? msg.usage_metadata : undefined;
|
|
@@ -19,11 +26,11 @@ const describeInput = (msg, callType) => {
|
|
|
19
26
|
}
|
|
20
27
|
else if (typeof msg === 'object' && 'content' in msg) {
|
|
21
28
|
entry.type = msg.role ?? 'unknown';
|
|
22
|
-
entry.content = msg.content ?? msg;
|
|
29
|
+
entry.content = asText(msg.content ?? msg);
|
|
23
30
|
entry.raw = JSON.stringify(msg);
|
|
24
31
|
}
|
|
25
32
|
else {
|
|
26
|
-
entry.content = msg;
|
|
33
|
+
entry.content = asText(msg);
|
|
27
34
|
entry.raw = JSON.stringify(msg);
|
|
28
35
|
}
|
|
29
36
|
return entry;
|
|
@@ -44,11 +51,11 @@ export const spectate = (spectator, callType) => async (input, message, action,
|
|
|
44
51
|
raw: JSON.stringify({ message, content: message.content, meta: message.response_metadata }),
|
|
45
52
|
};
|
|
46
53
|
if (message.tool_calls != null && message.tool_calls.length > 0) {
|
|
47
|
-
completion.content = message.tool_calls;
|
|
54
|
+
completion.content = asText(message.tool_calls);
|
|
48
55
|
completion.contentType = SpectatorContentType.ToolCall;
|
|
49
56
|
}
|
|
50
57
|
else {
|
|
51
|
-
completion.content = message.content;
|
|
58
|
+
completion.content = asText(message.content);
|
|
52
59
|
}
|
|
53
60
|
// Silent unless the provider reported cache activity, so it costs nothing when
|
|
54
61
|
// caching is off — and is the one signal that tells a stable prefix from a broken one.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spectate.js","sourceRoot":"","sources":["../../src/helpers/spectate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAG3D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE7D,uEAAuE;AACvE,MAAM,aAAa,GAAG,CAAC,GAAmB,EAAE,QAAgB,EAAyB,EAAE;IACrF,MAAM,KAAK,GAA0B;QACnC,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,oBAAoB,CAAC,IAAI;KACvC,CAAA;IAED,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACrB,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,
|
|
1
|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AC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC;KAC5F,CAAA;IAED,IAAI,OAAO,CAAC,UAAU,IAAI,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChE,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAC/C,UAAU,CAAC,WAAW,GAAG,oBAAoB,CAAC,QAAQ,CAAA;IACxD,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,CAAC;IAED,+EAA+E;IAC/E,uFAAuF;IACvF,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACrC,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,CACT,iBAAiB,MAAM,WAAW,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,QAAQ,cAAc,KAAK,CAAC,KAAK,EAAE,CACnG,CAAA;IACH,CAAC;IAED,OAAO,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC,CAAA;AAC3F,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export * from './execution/index.js';
|
|
|
8
8
|
export * from './prompt/index.js';
|
|
9
9
|
export type * from './plugins/types.js';
|
|
10
10
|
export { plugins, registerLlmPlugin, pluginOf, pluginFor, resolvePlugin } from './plugins/index.js';
|
|
11
|
-
export { anthropicPlugin, ANTHROPIC_FAMILY } from './plugins/anthropic.js';
|
|
11
|
+
export { anthropicPlugin, ANTHROPIC_FAMILY, NO_SAMPLING_PREFIXES, rejectsSampling } from './plugins/anthropic.js';
|
|
12
12
|
export { compatiblePlugin } from './plugins/compatible.js';
|
|
13
|
-
export { openAiPlugin, openAiFamily, OPENAI_FAMILY } from './plugins/openai.js';
|
|
13
|
+
export { openAiPlugin, openAiFamily, OPENAI_FAMILY, RESPONSES_API_PREFIXES, usesResponsesApi, } from './plugins/openai.js';
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,mBAAmB,YAAY,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,mBAAmB,oBAAoB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,mBAAmB,YAAY,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,mBAAmB,oBAAoB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,GACpF,MAAM,qBAAqB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export * from './helpers/index.js';
|
|
|
6
6
|
export * from './execution/index.js';
|
|
7
7
|
export * from './prompt/index.js';
|
|
8
8
|
export { plugins, registerLlmPlugin, pluginOf, pluginFor, resolvePlugin } from './plugins/index.js';
|
|
9
|
-
export { anthropicPlugin, ANTHROPIC_FAMILY } from './plugins/anthropic.js';
|
|
9
|
+
export { anthropicPlugin, ANTHROPIC_FAMILY, NO_SAMPLING_PREFIXES, rejectsSampling } from './plugins/anthropic.js';
|
|
10
10
|
export { compatiblePlugin } from './plugins/compatible.js';
|
|
11
|
-
export { openAiPlugin, openAiFamily, OPENAI_FAMILY } from './plugins/openai.js';
|
|
11
|
+
export { openAiPlugin, openAiFamily, OPENAI_FAMILY, RESPONSES_API_PREFIXES, usesResponsesApi, } from './plugins/openai.js';
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAE3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAE3B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,GACpF,MAAM,qBAAqB,CAAA"}
|
package/build/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EACuB,QAAQ,EAAE,eAAe,EAC1D,YAAY,EACb,MAAM,YAAY,CAAA;AA8CnB;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,oFAStB,eAAe,aAAa,YAAY,KAAG,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EACuB,QAAQ,EAAE,eAAe,EAC1D,YAAY,EACb,MAAM,YAAY,CAAA;AA8CnB;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,oFAStB,eAAe,aAAa,YAAY,KAAG,QAma7C,CAAA"}
|
package/build/model.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Ajv } from 'ajv';
|
|
2
2
|
import { AIMessage, BaseMessage } from '@langchain/core/messages';
|
|
3
3
|
import { StructuredMode } from '@owlmeans/llm-common';
|
|
4
|
-
import {
|
|
4
|
+
import { DEFAULT_MODEL_RETRIES, FALLBACK_AFTER_ATTEMPTS, MAX_CACHE_BREAKPOINTS, } from './consts.js';
|
|
5
5
|
import { LlmModelError } from './errors.js';
|
|
6
6
|
import { pluginFor, pluginOf } from './plugins/index.js';
|
|
7
7
|
import { coerceToSchema, parseJsonContent } from './helpers/json.js';
|
|
8
8
|
import { normalizeInput } from './helpers/messages.js';
|
|
9
9
|
import { withRetry } from './helpers/retry.js';
|
|
10
10
|
import { spectate } from './helpers/spectate.js';
|
|
11
|
-
import { idleTimeout, readConfig } from './utils/config.js';
|
|
11
|
+
import { idleTimeout, readConfig, resolveOutputCap } from './utils/config.js';
|
|
12
12
|
import { reportNull } from './utils/null-report.js';
|
|
13
13
|
import { applyNoThink, dropBlankContent, ensureJsonMention, stripCacheMarkers } from './utils/prompt.js';
|
|
14
14
|
import { resolveSchemaValidator, toToolName, unwrapNamed } from './utils/schema.js';
|
|
@@ -66,6 +66,15 @@ export const makeLlmModel = ({ model, outputErrors = false, captureNull = false,
|
|
|
66
66
|
const config = readConfig(model);
|
|
67
67
|
const plugin = pluginOf(config.provider) ?? pluginFor(model);
|
|
68
68
|
const timeout = idleTimeout(config);
|
|
69
|
+
/**
|
|
70
|
+
* Where on the escalation ladder this call starts.
|
|
71
|
+
*
|
|
72
|
+
* The ladder has exactly `retries` rungs, so a seed past the last one buys nothing and
|
|
73
|
+
* would only inflate the attempt number handed to `refine`. Clamped, `refineModel` sees
|
|
74
|
+
* at most `2 * (retries - 1)` — the escalator's own doubling stays bounded by the
|
|
75
|
+
* output cap either way.
|
|
76
|
+
*/
|
|
77
|
+
const ladderSeed = (escalation) => Math.max(0, Math.min(Math.floor(escalation ?? 0), retries - 1));
|
|
69
78
|
/**
|
|
70
79
|
* Normalize, compose the system prompt, then apply every in-place prompt adaptation, in
|
|
71
80
|
* dependency order.
|
|
@@ -158,9 +167,9 @@ export const makeLlmModel = ({ model, outputErrors = false, captureNull = false,
|
|
|
158
167
|
const basePlugin = pluginOf(baseConfig.provider) ?? pluginFor(base);
|
|
159
168
|
if (basePlugin == null)
|
|
160
169
|
return base;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
// Read from the ACTIVE base — after the fallback swap that is the fallback's own
|
|
171
|
+
// config, so the escalator sizes the model it is actually talking to.
|
|
172
|
+
const maxOutputCap = resolveOutputCap(baseConfig);
|
|
164
173
|
const refined = basePlugin.refine({ base, attempt, temperature, maxOutputCap });
|
|
165
174
|
if (attempt > 0) {
|
|
166
175
|
const maxTokens = refined.maxTokens;
|
|
@@ -220,10 +229,11 @@ export const makeLlmModel = ({ model, outputErrors = false, captureNull = false,
|
|
|
220
229
|
return { piece, result, mode };
|
|
221
230
|
};
|
|
222
231
|
const helper = {
|
|
223
|
-
ask: async (input, { ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills }) => {
|
|
232
|
+
ask: async (input, { ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills, escalation, fatal, }) => {
|
|
224
233
|
const msgs = await prepare(input, action, useCache, cacheMax, false, skills);
|
|
225
|
-
|
|
226
|
-
|
|
234
|
+
const seed = ladderSeed(escalation);
|
|
235
|
+
return withRetry({ retries, outputErrors, fatal }, async (i) => {
|
|
236
|
+
const refined = refineModel(seed + i);
|
|
227
237
|
console.log('Use model to ask: ', refined.getName(), refined.lc_kwargs.model);
|
|
228
238
|
const startedAt = Date.now();
|
|
229
239
|
let result = null;
|
|
@@ -258,10 +268,11 @@ export const makeLlmModel = ({ model, outputErrors = false, captureNull = false,
|
|
|
258
268
|
return output;
|
|
259
269
|
});
|
|
260
270
|
},
|
|
261
|
-
talk: async (input, { ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills }) => {
|
|
271
|
+
talk: async (input, { ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills, escalation, fatal, }) => {
|
|
262
272
|
const msgs = await prepare(input, action, useCache, cacheMax, false, skills);
|
|
263
|
-
|
|
264
|
-
|
|
273
|
+
const seed = ladderSeed(escalation);
|
|
274
|
+
return withRetry({ retries, outputErrors, fatal }, async (i) => {
|
|
275
|
+
const refined = refineModel(seed + i);
|
|
265
276
|
console.log('Use model to talk: ', refined.getName(), refined.lc_kwargs.model);
|
|
266
277
|
const startedAt = Date.now();
|
|
267
278
|
let result = null;
|
|
@@ -285,12 +296,13 @@ export const makeLlmModel = ({ model, outputErrors = false, captureNull = false,
|
|
|
285
296
|
return message;
|
|
286
297
|
});
|
|
287
298
|
},
|
|
288
|
-
invoke: async (input, schema, { temperature, ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills }) => {
|
|
299
|
+
invoke: async (input, schema, { temperature, ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills, escalation, fatal, }) => {
|
|
289
300
|
const msgs = await prepare(input, action, useCache, cacheMax, true, skills);
|
|
290
301
|
const { name, innerSchema, validate } = resolveSchemaValidator(ajv, schema);
|
|
291
302
|
const toolName = toToolName(innerSchema.title ?? name);
|
|
292
|
-
|
|
293
|
-
|
|
303
|
+
const seed = ladderSeed(escalation);
|
|
304
|
+
return withRetry({ retries, outputErrors, fatal }, async (i) => {
|
|
305
|
+
const refined = refineModel(seed + i, temperature);
|
|
294
306
|
console.log('Use model invoke: ', refined.getName(), refined.lc_kwargs.model);
|
|
295
307
|
const startedAt = Date.now();
|
|
296
308
|
const { piece, result: collected } = await streamStructured(refined, msgs, innerSchema, toolName, action);
|
|
@@ -323,12 +335,13 @@ export const makeLlmModel = ({ model, outputErrors = false, captureNull = false,
|
|
|
323
335
|
return result;
|
|
324
336
|
});
|
|
325
337
|
},
|
|
326
|
-
request: async (input, schema, { ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills }) => {
|
|
338
|
+
request: async (input, schema, { ref, filter, action, useCache = false, cacheMax = MAX_CACHE_BREAKPOINTS, skills, escalation, fatal, }) => {
|
|
327
339
|
const msgs = await prepare(input, action, useCache, cacheMax, true, skills);
|
|
328
340
|
const { name, innerSchema, validate } = resolveSchemaValidator(ajv, schema);
|
|
329
341
|
const toolName = toToolName(innerSchema.title ?? name);
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
const seed = ladderSeed(escalation);
|
|
343
|
+
return withRetry({ retries, outputErrors, fatal }, async (i) => {
|
|
344
|
+
const refined = refineModel(seed + i);
|
|
332
345
|
console.log('Use model request: ', refined.getName(), refined.lc_kwargs.model);
|
|
333
346
|
const startedAt = Date.now();
|
|
334
347
|
const { piece, result: collected } = await streamStructured(refined, msgs, innerSchema, toolName, action);
|