dsh-model-think-level 2.5.1 → 2.6.1

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.
@@ -12,6 +12,13 @@
12
12
  * every key reaches the same relay, and the relay's own pool decides which
13
13
  * resource sees the request.
14
14
  *
15
+ * The same fan-out produces a second wording when the pool keeps a tool call's
16
+ * `fc_` handle but not the `rs_` reasoning item minted with it: the server
17
+ * answers `Item 'fc_…' of type 'function_call' was provided without its
18
+ * required 'reasoning' item: 'rs_…'`. That is the same condition — the replayed
19
+ * history and the backend serving it disagree about the items — so it shares
20
+ * one recognition point and one degradation ladder with the resource refusal.
21
+ *
15
22
  * Two facts make this module structural rather than a fetch-layer patch:
16
23
  *
17
24
  * 1. The refusal arrives in more than one shape. A relay may answer `400` with
@@ -36,6 +43,8 @@
36
43
  * item as new instead of resolving a foreign handle. A text signature cannot
37
44
  * keep its `phase` once the id is gone: pi-ai only reads `{v:1, id, phase?}`,
38
45
  * and a signature without a string `id` is sent verbatim as the item id.
46
+ * This is also the repair for a split `fc_`/`rs_` pair: with no item handle
47
+ * on the function call, the server stops looking for its reasoning sibling.
39
48
  * 2. `drop_reasoning` — additionally stop replaying historical reasoning items
40
49
  * altogether (the `thinkingSignature` is removed; the visible thinking text
41
50
  * stays in the local history untouched). Reasoning is the other thing bound
@@ -53,7 +62,9 @@ export declare const HISTORY_INSPECT_LIMIT = 65536;
53
62
  /** How long an error body may take before inspection is abandoned. */
54
63
  export declare const HISTORY_INSPECT_TIMEOUT_MS = 2000;
55
64
  /**
56
- * Whether a provider message is the resource-mismatch refusal.
65
+ * Whether a provider message is one of the foreign-history refusals: an item
66
+ * minted under another backend resource, or a tool call whose paired reasoning
67
+ * item the relay no longer replays.
57
68
  * @param text - the error body or stream error message, decoded.
58
69
  * @returns whether the history (not the request shape) is what failed.
59
70
  */
@@ -1,19 +1,14 @@
1
1
  /**
2
- * The image-generation config: `<DSH_HOME>/dsh-model-think-level/image.json`.
2
+ * Image configuration types, pure model derivation and legacy v2 parsing.
3
3
  *
4
- * The file holds no secrets — credential references only — which is what makes
5
- * it safe to keep in plain text and to hand to the MCP subprocess through one
6
- * `DSH_IMAGE_CONFIG` env var. Its `models[]` is a DERIVED SNAPSHOT: the source
7
- * of truth is the `llm-pi-ai` settings document's `inputImageGen` rows (the
8
- * same marker the Models page and the auto-fill write), and this file layers
9
- * the user's per-model overrides (endpoint verdict, param abilities, picked
10
- * size/quality/n) on top. Syncing keeps every override keyed by model id, so a
11
- * model that leaves the settings document drops out and one that comes back
12
- * keeps its overrides.
4
+ * Live model membership and connections are supplied by ImageConfiguration in
5
+ * state.ts from the host's resolved llm-pi-ai settings. Runtime consumers must
6
+ * use that adapter; the v2 file helpers below are retained for compatibility
7
+ * tests and legacy preference/diagnostic migration only.
13
8
  *
14
- * Parsing follows `key-index.ts`: read-never-throw for absent files, defensive
15
- * field-by-field drops for malformed content, and an atomic temp-then-rename
16
- * write so a crash mid-write cannot leave a half-parsed config behind.
9
+ * image.json now stores v3 preferences and connection-scoped observations. A
10
+ * stored v2 models[] snapshot never authorizes a model or supplies a connection
11
+ * to a live image operation.
17
12
  *
18
13
  * @module dsh-model-think-level/image/config
19
14
  */
@@ -42,7 +37,7 @@ export interface ImageModelSeed {
42
37
  readonly baseURL: string;
43
38
  readonly keyRef?: string;
44
39
  }
45
- /** One image model as the config stores it: derived facts + user overrides. */
40
+ /** One current derived image model, combined with connection-scoped diagnostics. */
46
41
  export interface ImageModel {
47
42
  readonly id: string;
48
43
  readonly route: string;
@@ -67,7 +62,7 @@ export interface ImageDefaults {
67
62
  readonly n: number;
68
63
  readonly timeoutMs: number;
69
64
  }
70
- /** The whole config document, exactly as it sits on disk. */
65
+ /** One live runtime projection; version 2 is the legacy structural contract. */
71
66
  export interface ImageConfig {
72
67
  readonly version: 2;
73
68
  /**
@@ -94,6 +89,7 @@ export declare const IMAGE_FALLBACK_PARAMS: ImageParams;
94
89
  export declare function imageConfigFilePath(home?: string): string;
95
90
  /** A fresh, empty config. */
96
91
  export declare function emptyImageConfig(now?: () => Date): ImageConfig;
92
+ export declare function parseImageParams(raw: unknown): ImageParams | undefined;
97
93
  /**
98
94
  * Parse an already-decoded config document. Never throws and never trusts the
99
95
  * input: anything unrecognisable is dropped field by field, so a hand-edited
@@ -95,8 +95,8 @@ export declare class GenerateError extends Error {
95
95
  }
96
96
  /** The faces this core needs from its host. All injectable for tests. */
97
97
  export interface GenerateDeps {
98
- /** The live config; read fresh per call (the MCP path re-reads the file). */
99
- readonly config?: () => ImageConfig;
98
+ /** One operation's live snapshot, supplied by the host; never read a disk catalogue. */
99
+ readonly config: () => ImageConfig;
100
100
  /** Resolve one credential reference to its value. */
101
101
  readonly resolveKey: (ref: string, signal?: AbortSignal) => Promise<string | undefined>;
102
102
  /** The fetch beneath any wrapper — the images call must not be re-intercepted. */
@@ -104,7 +104,7 @@ export interface GenerateDeps {
104
104
  /** Base dir for relative `outputDir`s (defaults to the harness home). */
105
105
  readonly home?: () => string;
106
106
  /** Persist `lastGoodParams` after a successful fallback (host: config file). */
107
- readonly persistLastGood?: (modelId: string, params: ImageModel['lastGoodParams']) => void;
107
+ readonly persistLastGood?: (modelId: string, params: ImageModel['lastGoodParams'], model: ImageModel) => void;
108
108
  /** Now, for file stamps (defaults to Date.now). */
109
109
  readonly now?: () => number;
110
110
  /** Per-call timeout override (ms). */
@@ -0,0 +1,45 @@
1
+ import { type ImageConfig, type ImageDefaults, type ImageModel, type ImageParams } from './config.js';
2
+ export interface ImageObservation {
3
+ /** Hash of the connection that produced this observation; contains no URL or key. */
4
+ readonly source: string;
5
+ readonly endpoint: ImageModel['endpoint'];
6
+ readonly lastGoodParams: ImageParams | null;
7
+ }
8
+ export interface ImagePreferences {
9
+ readonly version: 3;
10
+ readonly enabled: boolean;
11
+ readonly defaultModel: string | null;
12
+ readonly defaults: ImageDefaults;
13
+ readonly outputDir: string;
14
+ readonly observations: Readonly<Record<string, ImageObservation>>;
15
+ }
16
+ interface SettingsDescriptor {
17
+ readonly ns: string;
18
+ readonly value?: unknown;
19
+ readonly revision?: number;
20
+ }
21
+ export declare class ImageConfigurationError extends Error {
22
+ readonly code: 'settings-unavailable' | 'settings-invalid' | 'preferences-unreadable';
23
+ constructor(code: 'settings-unavailable' | 'settings-invalid' | 'preferences-unreadable', message: string);
24
+ }
25
+ /** One source adapter for every consumer; an operation captures one read(). */
26
+ export declare class ImageConfiguration {
27
+ private readonly deps;
28
+ private readonly file;
29
+ private readonly now;
30
+ constructor(deps: {
31
+ readonly describe: () => readonly SettingsDescriptor[];
32
+ readonly file?: string;
33
+ readonly now?: () => Date;
34
+ });
35
+ private load;
36
+ preferences(): ImagePreferences;
37
+ private base;
38
+ read(): ImageConfig;
39
+ private project;
40
+ /** The saved switch wins even while the model provider is unavailable. */
41
+ forGeneration(): ImageConfig;
42
+ update(mutate: (preferences: ImagePreferences) => ImagePreferences): ImagePreferences;
43
+ record(model: ImageModel, params: ImageParams | null): void;
44
+ }
45
+ export {};
@@ -113,4 +113,4 @@ export declare function registerGenerateImageTool(ctx: Context, deps: ImageToolD
113
113
  * several candidates the resolver refuses, and the hint then has to say so —
114
114
  * naming a model there is a promise the call cannot keep.
115
115
  */
116
- export declare function imageToolHint(config: ImageConfig): string;
116
+ export declare function imageToolHint(config: ImageConfig, toolName?: string): string;