@toddzheng024/dscode-bundle 0.7.6 → 0.7.7
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/THIRD_PARTY_NOTICES.md +3 -3
- package/cordis.patch.yml +26 -5
- package/package.json +4 -4
- package/plugins/auto-review/index.mjs +6 -1
- package/plugins/compaction/tetris.mjs +65 -0
- package/plugins/compaction/threshold.mjs +46 -0
- package/plugins/credentials/index.mjs +2 -2
- package/plugins/i18n/messages.mjs +18 -0
- package/plugins/openrouter/adapter.mjs +157 -0
- package/plugins/openrouter/index.mjs +112 -0
- package/plugins/openrouter/models.mjs +151 -0
- package/plugins/openrouter/search.mjs +109 -0
- package/plugins/openrouter/wire.mjs +413 -0
- package/plugins/providers/catalog.mjs +18 -68
- package/plugins/providers/openrouter-account.mjs +171 -0
- package/plugins/session-metrics/balance.mjs +29 -19
- package/plugins/session-metrics/index.mjs +19 -9
- package/plugins/session-metrics/pricing.mjs +26 -6
- package/plugins/session-metrics/view.mjs +1 -1
- package/plugins/ultra/policy.mjs +0 -16
- package/presets/dscode/agent.cordis.yml +1 -1
- package/vendor/compaction-basic/index.js +983 -0
- package/vendor/compaction-basic/types/config.d.ts +37 -0
- package/vendor/compaction-basic/types/index.d.ts +84 -0
- package/vendor/compaction-basic/types/region.d.ts +65 -0
- package/vendor/compaction-basic/types/summarizer.d.ts +64 -0
- package/vendor/compaction-basic/types/types.d.ts +73 -0
- package/vendor/tui/dscode-providers/catalog.mjs +18 -68
- package/vendor/tui/dscode-providers/openrouter-account.mjs +171 -0
- package/vendor/tui/index.mjs +390 -165
- package/plugins/session-metrics/openrouter-prices.mjs +0 -96
- package/vendor/pi-ai/index.js +0 -2701
- package/vendor/pi-ai/types/adapter.d.ts +0 -105
- package/vendor/pi-ai/types/auth.d.ts +0 -60
- package/vendor/pi-ai/types/catalog.d.ts +0 -355
- package/vendor/pi-ai/types/config.d.ts +0 -208
- package/vendor/pi-ai/types/context.d.ts +0 -42
- package/vendor/pi-ai/types/discovery.d.ts +0 -43
- package/vendor/pi-ai/types/index.d.ts +0 -69
- package/vendor/pi-ai/types/login.d.ts +0 -21
- package/vendor/pi-ai/types/provider.d.ts +0 -59
- package/vendor/pi-ai/types/replay.d.ts +0 -63
- package/vendor/pi-ai/types/stream.d.ts +0 -43
- /package/vendor/{pi-ai → compaction-basic}/LICENSE +0 -0
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration schema and provider-profile validation for the pi-ai adapter.
|
|
3
|
-
* Profiles are a dict keyed by provider route, so the composition base and a
|
|
4
|
-
* user-settings layer merge per provider and the route set is structural.
|
|
5
|
-
*
|
|
6
|
-
* A route key is not required to name an installed pi-ai provider. When it does,
|
|
7
|
-
* that provider's endpoint, protocol, display name, and model catalog are the
|
|
8
|
-
* profile's defaults and the profile overrides them field by field; when it does
|
|
9
|
-
* not, the profile is the whole provider declaration. Stored reads retain
|
|
10
|
-
* catalog diagnostics beside serviceable models; writes validate every changed
|
|
11
|
-
* provider before persistence. Self-contained profile constraints apply to both.
|
|
12
|
-
*
|
|
13
|
-
* @module dsh-llm-pi-ai/config
|
|
14
|
-
*/
|
|
15
|
-
import type { CacheRetention, ModelThinkingLevel, Provider, ThinkingBudgets, Transport } from '@earendil-works/pi-ai';
|
|
16
|
-
import z from '@deepseek-ai/schemastery';
|
|
17
|
-
import type { CredentialRef } from '@deepseek-ai/dsh-credentials';
|
|
18
|
-
import type { ResolvedRetryPolicy, RetryPolicyConfig } from '@deepseek-ai/dsh-llm';
|
|
19
|
-
import type { PiAiCompatProfile, PiAiModality, PiAiModelOverride, PiAiModelProfile } from './catalog.ts';
|
|
20
|
-
/** Default maximum idle interval while an adapter stream read is outstanding. */
|
|
21
|
-
export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
|
|
22
|
-
/**
|
|
23
|
-
* Default request-level bound on base64-encoded image payload. Every image in
|
|
24
|
-
* history is re-encoded into every request body, so an unbounded conversation
|
|
25
|
-
* eventually exceeds a provider or gateway request-size cap and the session
|
|
26
|
-
* can never complete another request. The 20MiB default admits fifteen 1MiB
|
|
27
|
-
* request versions after base64 expansion and reserves request capacity for
|
|
28
|
-
* system prompts, history, tools, and JSON.
|
|
29
|
-
* Deployments behind stricter gateways lower it per route.
|
|
30
|
-
*/
|
|
31
|
-
export declare const DEFAULT_MAX_REQUEST_IMAGE_BYTES: number;
|
|
32
|
-
/** Default total-pixel budget preserves the complete 2048px normalized attachment. */
|
|
33
|
-
export declare const DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET: number;
|
|
34
|
-
/** Default raw encoded-byte target before inline base64 expansion; the smallest quality-ladder output is used when no quality fits. */
|
|
35
|
-
export declare const DEFAULT_REQUEST_IMAGE_MAX_BYTES: number;
|
|
36
|
-
/** Context capacity assumed for a model neither configuration nor the catalog sizes. */
|
|
37
|
-
export declare const DEFAULT_CONTEXT_WINDOW = 262144;
|
|
38
|
-
/** Output capability assumed for a model neither configuration nor the catalog sizes. */
|
|
39
|
-
export declare const DEFAULT_MAX_TOKENS = 32768;
|
|
40
|
-
/**
|
|
41
|
-
* Modalities assumed for a model neither configuration nor the catalog
|
|
42
|
-
* declares. Text is the floor every supported protocol certainly carries, so
|
|
43
|
-
* this is the absence of a declaration rather than a guess at the endpoint:
|
|
44
|
-
* nothing can interrogate a gateway for its modalities, and the two wrong
|
|
45
|
-
* answers do not cost the same. Under-claiming refuses the image before it is
|
|
46
|
-
* attached, naming the model. Over-claiming admits one the provider then
|
|
47
|
-
* rejects mid-turn, after the message is durable, leaving the session
|
|
48
|
-
* repeating a request that cannot succeed.
|
|
49
|
-
*/
|
|
50
|
-
export declare const DEFAULT_INPUT: readonly PiAiModality[];
|
|
51
|
-
export type { PiAiCompatProfile, PiAiModality, PiAiModelOverride, PiAiModelProfile, PiAiReasoningEfforts, PiAiThinkingFormat, } from './catalog.ts';
|
|
52
|
-
/** Configuration for one pi-ai provider route; the `providers` dict key IS the route. */
|
|
53
|
-
export interface PiAiProviderProfile {
|
|
54
|
-
/** Credential reference (environment-variable name) resolved per request through `ctx.credentials`. */
|
|
55
|
-
apiKeyEnv?: string;
|
|
56
|
-
/** Name shown by configuration surfaces; defaults to the route key. */
|
|
57
|
-
displayName?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Wire protocol every model on this route speaks. Omission keeps each
|
|
60
|
-
* installed catalog model's own protocol, which is why a catalog route needs
|
|
61
|
-
* no protocol at all; a route the catalog does not ship must name one.
|
|
62
|
-
*/
|
|
63
|
-
api?: string;
|
|
64
|
-
/** Endpoint for this route's models; defaults to the installed catalog's endpoint. */
|
|
65
|
-
baseURL?: string;
|
|
66
|
-
/**
|
|
67
|
-
* This route's model catalog. Omission serves the installed catalog for the
|
|
68
|
-
* route unchanged; an explicit list replaces it, each entry defaulting its
|
|
69
|
-
* unset fields from the installed model of the same id.
|
|
70
|
-
*/
|
|
71
|
-
models?: PiAiModelProfile[];
|
|
72
|
-
/**
|
|
73
|
-
* Installed-catalog customizations by model id: each entry reshapes that
|
|
74
|
-
* one model with the same fields a {@link models} entry takes, while the
|
|
75
|
-
* rest of the catalog keeps serving untouched. Only meaningful on a catalog
|
|
76
|
-
* route with no `models` list — `models` already replaces the catalog, so
|
|
77
|
-
* an override beside it, on a route the catalog does not ship, or naming a
|
|
78
|
-
* model the catalog does not describe is refused rather than skipped.
|
|
79
|
-
*/
|
|
80
|
-
modelOverrides?: Record<string, PiAiModelOverride>;
|
|
81
|
-
/**
|
|
82
|
-
* pi-ai wire-compatibility switches defaulting every model on this route
|
|
83
|
-
* whose protocol declares them; each model's own `compat` overrides per
|
|
84
|
-
* field. What neither sets keeps the installed catalog entry's value, then
|
|
85
|
-
* pi-ai's own detection. A switch no model on the route could read is
|
|
86
|
-
* refused rather than left looking applied.
|
|
87
|
-
*/
|
|
88
|
-
compat?: PiAiCompatProfile;
|
|
89
|
-
/**
|
|
90
|
-
* Context capacity for a model this route lists that neither the entry nor
|
|
91
|
-
* the installed catalog sizes (default 262,144). A guess by construction, so
|
|
92
|
-
* a deployment whose gateway serves smaller models corrects it here.
|
|
93
|
-
*/
|
|
94
|
-
defaultContextWindow?: number;
|
|
95
|
-
/**
|
|
96
|
-
* Output capability for a model this route lists that neither the entry nor
|
|
97
|
-
* the installed catalog sizes (default 32,768). This sizes the model; it
|
|
98
|
-
* never becomes a per-request cap on its own.
|
|
99
|
-
*/
|
|
100
|
-
defaultMaxTokens?: number;
|
|
101
|
-
/**
|
|
102
|
-
* Request modalities for a model this route lists that neither its entry's
|
|
103
|
-
* {@link PiAiModelProfile.input} nor the installed catalog declares (default
|
|
104
|
-
* `[text]`). A fallback like the capacities above, not an override: a
|
|
105
|
-
* catalog model keeps the modalities the catalog records for it, and this
|
|
106
|
-
* value never narrows one. A gateway serving vision models the catalog does
|
|
107
|
-
* not describe declares `[text, image]` once here instead of on every entry.
|
|
108
|
-
* Unlike an entry's list, this one may not be empty — nothing sits below it
|
|
109
|
-
* to answer instead.
|
|
110
|
-
*/
|
|
111
|
-
defaultInput?: PiAiModality[];
|
|
112
|
-
/** Provider request headers, validated against Fetch when the profile resolves; Harness attribution wins reserved names. */
|
|
113
|
-
headers?: Record<string, string>;
|
|
114
|
-
/** Provider-neutral pi-ai reasoning level. */
|
|
115
|
-
reasoning?: ModelThinkingLevel;
|
|
116
|
-
/** Token budgets used by reasoning providers that support them. */
|
|
117
|
-
thinkingBudgets?: ThinkingBudgets;
|
|
118
|
-
/** Prompt-cache retention preference. */
|
|
119
|
-
cacheRetention?: CacheRetention;
|
|
120
|
-
/** Streaming transport preference. */
|
|
121
|
-
transport?: Transport;
|
|
122
|
-
/** HTTP/provider SDK timeout in milliseconds. */
|
|
123
|
-
timeoutMs?: number;
|
|
124
|
-
/** WebSocket connection timeout in milliseconds. */
|
|
125
|
-
websocketConnectTimeoutMs?: number;
|
|
126
|
-
/** Maximum provider idle time while one stream read is outstanding. */
|
|
127
|
-
streamIdleTimeoutMs?: number;
|
|
128
|
-
/**
|
|
129
|
-
* Maximum base64-encoded image payload per request. When a request's
|
|
130
|
-
* accumulated images exceed it, the oldest images are replaced by text
|
|
131
|
-
* placeholders until the request fits, so a long session keeps completing
|
|
132
|
-
* requests instead of being rejected by a request-size cap.
|
|
133
|
-
*/
|
|
134
|
-
maxRequestImageBytes?: number;
|
|
135
|
-
/** Total-pixel budget for each deterministic inline request version. */
|
|
136
|
-
requestImagePixelBudget?: number;
|
|
137
|
-
/**
|
|
138
|
-
* Raw encoded-byte target for each deterministic inline request version;
|
|
139
|
-
* the smallest quality-ladder output is used when no quality fits.
|
|
140
|
-
*/
|
|
141
|
-
requestImageMaxBytes?: number;
|
|
142
|
-
/** Provider-owned model-request retry policy; omission uses normal mode with five retries. */
|
|
143
|
-
retryPolicy?: RetryPolicyConfig;
|
|
144
|
-
}
|
|
145
|
-
/** Validated profile with its route stamped and every adapter-owned default resolved. */
|
|
146
|
-
export interface ResolvedPiAiProviderProfile extends Omit<PiAiProviderProfile, 'apiKeyEnv' | 'retryPolicy' | 'models' | 'displayName'> {
|
|
147
|
-
/** Harness route key and the `Models` collection key (the configuration dict key). */
|
|
148
|
-
provider: string;
|
|
149
|
-
/** Resolved display name for selectors and configuration surfaces. */
|
|
150
|
-
displayName: string;
|
|
151
|
-
/** Validated credential reference, when one is configured. */
|
|
152
|
-
apiKeyEnv?: CredentialRef;
|
|
153
|
-
/** Positive finite provider-idle interval after defaulting. */
|
|
154
|
-
streamIdleTimeoutMs: number;
|
|
155
|
-
/** Positive request-level base64 image payload bound after defaulting. */
|
|
156
|
-
maxRequestImageBytes: number;
|
|
157
|
-
/** Positive total-pixel request-version budget after defaulting. */
|
|
158
|
-
requestImagePixelBudget: number;
|
|
159
|
-
/** Positive raw request-version byte target after defaulting; the smallest quality-ladder output is used when no quality fits. */
|
|
160
|
-
requestImageMaxBytes: number;
|
|
161
|
-
/** Immutable retry policy captured with this provider route. */
|
|
162
|
-
retryPolicy: ResolvedRetryPolicy;
|
|
163
|
-
/**
|
|
164
|
-
* The pi-ai provider containing this route's serviceable models. Absent when
|
|
165
|
-
* a stored route cannot be constructed; its configuration remains editable.
|
|
166
|
-
*/
|
|
167
|
-
piProvider?: Provider;
|
|
168
|
-
/** First model diagnostic, or the route failure when no model diagnostic is available. */
|
|
169
|
-
catalogError?: string;
|
|
170
|
-
/** Per-model failures reported before attempting a request. */
|
|
171
|
-
modelErrors: ReadonlyMap<string, string>;
|
|
172
|
-
/**
|
|
173
|
-
* Per-request output caps this profile explicitly configured, by model id.
|
|
174
|
-
* The seam materializes one only into a request that names no cap of its
|
|
175
|
-
* own, so a catalog capability must not appear here.
|
|
176
|
-
*/
|
|
177
|
-
configuredMaxTokens: ReadonlyMap<string, number>;
|
|
178
|
-
}
|
|
179
|
-
/** Plugin configuration: the provider routes this instance owns. */
|
|
180
|
-
export interface Config {
|
|
181
|
-
/**
|
|
182
|
-
* pi-ai provider routes, keyed by provider. An empty (or omitted) dict is
|
|
183
|
-
* the dormant settings-driven posture: the adapter mounts with no routes
|
|
184
|
-
* and registers them the moment a settings section supplies profiles.
|
|
185
|
-
*/
|
|
186
|
-
providers?: Record<string, PiAiProviderProfile>;
|
|
187
|
-
}
|
|
188
|
-
/** Runtime schema for {@link Config}. */
|
|
189
|
-
export declare const Config: z<Config>;
|
|
190
|
-
/**
|
|
191
|
-
* Reject new or changed provider profiles that cannot be served. Unchanged
|
|
192
|
-
* stored profiles may need repair after a catalog upgrade and do not block
|
|
193
|
-
* edits to another provider. Removed profiles require no catalog validation.
|
|
194
|
-
* @param config - the resolved section to check.
|
|
195
|
-
* @param previous - current resolved section; omission checks every provider.
|
|
196
|
-
* @throws Error naming the route and configuration entry that cannot be served.
|
|
197
|
-
*/
|
|
198
|
-
export declare function assertServiceable(config: Config, previous?: Config): void;
|
|
199
|
-
/**
|
|
200
|
-
* Resolve scalar defaults and materialize each route's serviceable models.
|
|
201
|
-
* Deferred catalog validation retains diagnostics without deleting configured
|
|
202
|
-
* routes. An omitted dict resolves to the empty, dormant route set.
|
|
203
|
-
* @param providers - configured provider profiles keyed by route.
|
|
204
|
-
* @param validation - writes require a complete catalog; stored reads retain catalog diagnostics.
|
|
205
|
-
* @returns validated profiles in configuration order.
|
|
206
|
-
*/
|
|
207
|
-
export declare function resolveProfiles(providers: Readonly<Record<string, PiAiProviderProfile>> | undefined, validation?: 'strict' | 'deferred'): Map<string, ResolvedPiAiProviderProfile>;
|
|
208
|
-
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Harness request-history conversion into pi-ai's Context vocabulary.
|
|
3
|
-
*
|
|
4
|
-
* @module dsh-llm-pi-ai/context
|
|
5
|
-
*/
|
|
6
|
-
import type { GenerateOptions, ImageAttachmentAccessResolver } from '@deepseek-ai/dsh-llm';
|
|
7
|
-
import type { AttachmentStore, ImageRequestPolicy } from '@deepseek-ai/dsh-attachment';
|
|
8
|
-
import type { Context as PiContext } from '@earendil-works/pi-ai';
|
|
9
|
-
/** Inputs that bind deterministic request images to one current tool execution world. */
|
|
10
|
-
export interface PiImageRequestContext {
|
|
11
|
-
/** Durable provider that resolves request-image bytes and provider-owned host objects. */
|
|
12
|
-
attachments: AttachmentStore;
|
|
13
|
-
/** Resolve current tool access separately from deterministic request-image versions. */
|
|
14
|
-
resolveImageAccess: ImageAttachmentAccessResolver;
|
|
15
|
-
/** Request-level bound on base64-encoded image payload; omission leaves every image in place. */
|
|
16
|
-
maxRequestImageBytes?: number;
|
|
17
|
-
/** Route pixel and raw encoded-byte budgets. */
|
|
18
|
-
requestImagePolicy?: ImageRequestPolicy;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Convert text-only harness history to a synchronous pi-ai Context. Tool
|
|
22
|
-
* result names are recovered from preceding assistant tool calls.
|
|
23
|
-
* @param options - the harness request; `options.system`, else a leading `system` message, maps to pi-ai's single `systemPrompt` slot.
|
|
24
|
-
* @param images - absent; selects the synchronous conversion.
|
|
25
|
-
* @param onReplayDegrade - forwarded to {@link toPiAssistant} for each assistant message.
|
|
26
|
-
* @returns the pi-ai context; `tools` is omitted when the request declares none.
|
|
27
|
-
* @throws {LlmError} `UNSUPPORTED_CONTENT` for images in any history role, including a leading system message.
|
|
28
|
-
*/
|
|
29
|
-
export declare function toPiContext(options: GenerateOptions, images?: undefined, onReplayDegrade?: (reason: string) => void): PiContext;
|
|
30
|
-
/**
|
|
31
|
-
* Convert harness history to a pi-ai Context while resolving durable images.
|
|
32
|
-
* Tool result names are recovered from preceding assistant tool calls. When
|
|
33
|
-
* the accumulated base64 image payload exceeds `maxRequestImageBytes`, the
|
|
34
|
-
* oldest images are replaced by text placeholders until the request fits, so
|
|
35
|
-
* an image-heavy session keeps clearing gateway request-size caps.
|
|
36
|
-
* @param options - the harness request; `options.system`, else a leading `system` message, maps to pi-ai's single `systemPrompt` slot.
|
|
37
|
-
* @param images - attachment provider, current path resolver, and request limits.
|
|
38
|
-
* @param onReplayDegrade - forwarded to {@link toPiAssistant} for each assistant message.
|
|
39
|
-
* @returns the asynchronously resolved pi-ai context.
|
|
40
|
-
*/
|
|
41
|
-
export declare function toPiContext(options: GenerateOptions, images: PiImageRequestContext, onReplayDegrade?: (reason: string) => void): Promise<PiContext>;
|
|
42
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Answering "which models can this provider serve?" for the configuration
|
|
3
|
-
* surface's "fetch available models" action.
|
|
4
|
-
*
|
|
5
|
-
* A route the installed pi-ai catalog ships is answered **from that catalog**,
|
|
6
|
-
* with no network call at all: pi-ai's registry is the authoritative list for
|
|
7
|
-
* its own providers, and it carries the capacities a listing endpoint would
|
|
8
|
-
* not disclose. Only a route the catalog does not describe — a gateway, a
|
|
9
|
-
* self-hosted server — is interrogated over the wire.
|
|
10
|
-
*
|
|
11
|
-
* Neither path is a catalog refresh. Nothing here is stored: the request
|
|
12
|
-
* carries a draft the user is still editing, and the reply is candidate
|
|
13
|
-
* metadata the surface offers for adoption. `settings.yaml` remains the only
|
|
14
|
-
* thing that decides what a route serves.
|
|
15
|
-
*
|
|
16
|
-
* OpenAI-compatible and Anthropic Messages protocols are interrogated through
|
|
17
|
-
* their native model-listing endpoints. The parser accepts the standard
|
|
18
|
-
* `data` array and the enriched `models` map some compatible gateways expose.
|
|
19
|
-
* Every other protocol reports that it cannot be interrogated so the surface
|
|
20
|
-
* falls back to hand-entry rather than guessing its response fields.
|
|
21
|
-
*
|
|
22
|
-
* @module dsh-llm-pi-ai/discovery
|
|
23
|
-
*/
|
|
24
|
-
import type { LlmDiscoveredModel, LlmModelDiscoveryOperation } from '@deepseek-ai/dsh-llm';
|
|
25
|
-
/** Host-owned profile inputs that a configuration draft deliberately omits. */
|
|
26
|
-
export interface StoredModelDiscoveryProfile {
|
|
27
|
-
/** Deployment headers configured on the named route. */
|
|
28
|
-
readonly headers: Readonly<Record<string, string>> | undefined;
|
|
29
|
-
/** Resolve the named route's credential only when the draft carries none. */
|
|
30
|
-
readonly resolveApiKey: () => Promise<string | undefined>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Interrogate one draft provider endpoint for the models it advertises.
|
|
34
|
-
* @param request - the endpoint, protocol, and one-shot credential to use.
|
|
35
|
-
* @param storedProfile - Host-owned headers and lazy credential resolution for
|
|
36
|
-
* the named route. It is read only on the path that reaches the network; the
|
|
37
|
-
* credential is resolved only when the draft carries none.
|
|
38
|
-
* @returns the advertised models in endpoint order.
|
|
39
|
-
* @throws LlmError when the protocol has no readable listing, the endpoint
|
|
40
|
-
* refuses or fails the request, or the reply is not a model listing.
|
|
41
|
-
*/
|
|
42
|
-
export declare function discoverModels(request: LlmModelDiscoveryOperation, storedProfile?: () => StoredModelDiscoveryProfile | undefined): Promise<readonly LlmDiscoveredModel[]>;
|
|
43
|
-
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic pi-ai-backed LLM adapter plugin. One plugin instance owns a dict of
|
|
3
|
-
* provider routes; a route naming an installed pi-ai provider inherits that
|
|
4
|
-
* provider's endpoint, protocol, and model catalog as defaults, and a route
|
|
5
|
-
* pi-ai does not ship is declared outright. Profile facts resolve per request
|
|
6
|
-
* over the optional `llm-pi-ai` user-settings section and the optional
|
|
7
|
-
* credential seam, so a changed key, endpoint, model, or knob reaches the next
|
|
8
|
-
* request without a restart; a changed *route set* (or a route's
|
|
9
|
-
* registration-captured retry policy) re-registers the same adapter instance
|
|
10
|
-
* in place.
|
|
11
|
-
*
|
|
12
|
-
* ```yaml
|
|
13
|
-
* - id: llm
|
|
14
|
-
* name: '@deepseek-ai/dsh-llm-pi-ai'
|
|
15
|
-
* config:
|
|
16
|
-
* providers:
|
|
17
|
-
* # Catalog route: everything but the credential comes from pi-ai.
|
|
18
|
-
* openai:
|
|
19
|
-
* apiKeyEnv: OPENAI_API_KEY
|
|
20
|
-
* retryPolicy:
|
|
21
|
-
* mode: normal
|
|
22
|
-
* maxRetries: 2
|
|
23
|
-
* # Catalog route with the catalog narrowed and one capacity corrected.
|
|
24
|
-
* anthropic:
|
|
25
|
-
* apiKeyEnv: ANTHROPIC_API_KEY
|
|
26
|
-
* models:
|
|
27
|
-
* - id: claude-sonnet-4-5
|
|
28
|
-
* contextWindow: 200000
|
|
29
|
-
* # Hand-declared route: pi-ai ships nothing under this key.
|
|
30
|
-
* acme-gateway:
|
|
31
|
-
* displayName: Acme Gateway
|
|
32
|
-
* apiKeyEnv: ACME_GATEWAY_API_KEY
|
|
33
|
-
* api: openai-completions
|
|
34
|
-
* baseURL: https://gateway.acme.example/v1
|
|
35
|
-
* # Reasoning dialect for a URL pi-ai cannot recognize.
|
|
36
|
-
* compat:
|
|
37
|
-
* thinkingFormat: deepseek
|
|
38
|
-
* models:
|
|
39
|
-
* - id: acme-large
|
|
40
|
-
* name: Acme Large
|
|
41
|
-
* contextWindow: 65536
|
|
42
|
-
* maxTokens: 4096
|
|
43
|
-
* - id: acme-think
|
|
44
|
-
* name: Acme Think
|
|
45
|
-
* contextWindow: 262144
|
|
46
|
-
* maxTokens: 32768
|
|
47
|
-
* # key = selectable level, value = wire spelling; only off may
|
|
48
|
-
* # leave the value empty (supported, send nothing).
|
|
49
|
-
* reasoningEfforts:
|
|
50
|
-
* off:
|
|
51
|
-
* high: high
|
|
52
|
-
* max: ultra
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @module @deepseek-ai/dsh-llm-pi-ai
|
|
56
|
-
*/
|
|
57
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
58
|
-
import { Config } from './config.ts';
|
|
59
|
-
export { PiAiAdapter } from './adapter.ts';
|
|
60
|
-
export type { PiAiAdapterOptions } from './adapter.ts';
|
|
61
|
-
export { Config } from './config.ts';
|
|
62
|
-
export type { PiAiCompatProfile, PiAiModality, PiAiModelOverride, PiAiModelProfile, PiAiProviderProfile, PiAiReasoningEfforts, PiAiThinkingFormat, ResolvedPiAiProviderProfile, } from './config.ts';
|
|
63
|
-
export { recordKeyFor } from './auth.ts';
|
|
64
|
-
export { supportedProtocols } from './provider.ts';
|
|
65
|
-
export declare const name = "llm-pi-ai";
|
|
66
|
-
export declare const inject: string[];
|
|
67
|
-
/** Register one generic pi-ai adapter for all configured provider routes. */
|
|
68
|
-
export declare function apply(ctx: Context, config: Config): void;
|
|
69
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization flows for the pi-ai providers that ship a login. This is the
|
|
3
|
-
* whole of the translation between the harness's neutral notice/prompt
|
|
4
|
-
* vocabulary and pi-ai's `AuthInteraction`; nothing above it knows which
|
|
5
|
-
* library ran the conversation.
|
|
6
|
-
*
|
|
7
|
-
* @module dsh-llm-pi-ai/login
|
|
8
|
-
*/
|
|
9
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
-
import type { PiAiAuthInjection } from './adapter.ts';
|
|
11
|
-
/**
|
|
12
|
-
* Register one authorization flow per installed provider that ships a login.
|
|
13
|
-
*
|
|
14
|
-
* Registration is unconditional on configuration: a provider has to be signed
|
|
15
|
-
* into before a route for it is worth adding, so the flow exists from the
|
|
16
|
-
* moment the plugin mounts rather than appearing once a profile does.
|
|
17
|
-
* @param ctx - the plugin context carrying `ctx.authorization`.
|
|
18
|
-
* @param auth - the injectables every collection here is built with.
|
|
19
|
-
*/
|
|
20
|
-
export declare function registerPiAiFlows(ctx: Context, auth: PiAiAuthInjection): void;
|
|
21
|
-
//# sourceMappingURL=login.d.ts.map
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Construction of the pi-ai `Provider` that one configured route registers into
|
|
3
|
-
* the adapter's `Models` collection.
|
|
4
|
-
*
|
|
5
|
-
* Two constructions, one decision: a route the installed catalog ships, whose
|
|
6
|
-
* profile does not override the wire protocol, **reuses that catalog provider**
|
|
7
|
-
* with its models replaced — the catalog provider owns API implementations this
|
|
8
|
-
* package cannot reconstruct (Bedrock loads its Smithy module through a
|
|
9
|
-
* separate entry point), so rebuilding it from parts would silently narrow
|
|
10
|
-
* which providers work. Every other route — one pi-ai has never heard of, or a
|
|
11
|
-
* catalog route pointed at a different protocol — is built by `createProvider`
|
|
12
|
-
* over the protocol table below.
|
|
13
|
-
*
|
|
14
|
-
* Credentials never reach this module's storage: the harness resolves a route's
|
|
15
|
-
* key through `ctx.credentials` before the request enters pi-ai and hands it
|
|
16
|
-
* over as a stream option, which `Models` presents to `resolve()` as the
|
|
17
|
-
* credential key.
|
|
18
|
-
*
|
|
19
|
-
* @module dsh-llm-pi-ai/provider
|
|
20
|
-
*/
|
|
21
|
-
import type { Api, Model, Provider } from '@earendil-works/pi-ai';
|
|
22
|
-
/**
|
|
23
|
-
* Every wire protocol a configured route may name, most-reached first. The
|
|
24
|
-
* order is the table's and therefore stable; a configuration surface offering
|
|
25
|
-
* a choice presents the first as its default, which is why the protocol a
|
|
26
|
-
* hand-declared gateway most often speaks — and the one endpoint interrogation
|
|
27
|
-
* can read — leads.
|
|
28
|
-
* @returns the supported protocol identifiers.
|
|
29
|
-
*/
|
|
30
|
-
export declare function supportedProtocols(): readonly string[];
|
|
31
|
-
/** The resolved route facts provider construction reads. */
|
|
32
|
-
export interface ProviderSpec {
|
|
33
|
-
/** Provider route key; also the `Models` collection key and each model's `provider`. */
|
|
34
|
-
provider: string;
|
|
35
|
-
/** Display name for selectors and status labels. */
|
|
36
|
-
displayName: string;
|
|
37
|
-
/** Wire protocol override; absent means each model keeps its catalog protocol. */
|
|
38
|
-
api?: string;
|
|
39
|
-
/** Endpoint override already applied to {@link models}; kept for provider-level display. */
|
|
40
|
-
baseURL?: string;
|
|
41
|
-
/** The route's materialized models, in configuration order. */
|
|
42
|
-
models: readonly Model<Api>[];
|
|
43
|
-
/**
|
|
44
|
-
* Whether the profile names a credential, which it does through `apiKeyEnv`
|
|
45
|
-
* alone: configuration carries the reference, never the secret. Only that
|
|
46
|
-
* decides whether {@link routeAuth} adds the harness's own api-key method to
|
|
47
|
-
* a catalog provider that offers none; the key itself still arrives per
|
|
48
|
-
* request, never at construction.
|
|
49
|
-
*/
|
|
50
|
-
namesCredential: boolean;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Build the pi-ai provider for one resolved route.
|
|
54
|
-
* @param spec - the resolved route facts.
|
|
55
|
-
* @returns the provider to register in the adapter's `Models` collection.
|
|
56
|
-
* @throws Error when the route names a wire protocol this build cannot serve.
|
|
57
|
-
*/
|
|
58
|
-
export declare function buildProvider(spec: ProviderSpec): Provider;
|
|
59
|
-
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Durable pi-ai replay metadata and assistant-history reconstruction.
|
|
3
|
-
*
|
|
4
|
-
* Harness content remains the durable source for text and tool calls. This
|
|
5
|
-
* module stores only the provider-native metadata needed to reconstruct a
|
|
6
|
-
* pi-ai assistant message on a later request.
|
|
7
|
-
*
|
|
8
|
-
* @module dsh-llm-pi-ai/replay
|
|
9
|
-
*/
|
|
10
|
-
import type { Message, ReplayEnvelope } from '@deepseek-ai/dsh-llm';
|
|
11
|
-
import type { Api, AssistantMessage } from '@earendil-works/pi-ai';
|
|
12
|
-
/** Per-block half of the pi-ai replay envelope, one entry per content block. */
|
|
13
|
-
export type PiAiReplayBlock = {
|
|
14
|
-
type: 'text';
|
|
15
|
-
textSignature?: string;
|
|
16
|
-
} | {
|
|
17
|
-
type: 'reasoning';
|
|
18
|
-
thinkingSignature?: string;
|
|
19
|
-
redacted?: boolean;
|
|
20
|
-
} | {
|
|
21
|
-
type: 'tool-call';
|
|
22
|
-
thoughtSignature?: string;
|
|
23
|
-
};
|
|
24
|
-
/** Versioned response-level half of the pi-ai replay envelope. */
|
|
25
|
-
export interface PiAiReplayResponse {
|
|
26
|
-
kind: 'pi-ai';
|
|
27
|
-
version: 2;
|
|
28
|
-
api: Api;
|
|
29
|
-
provider: string;
|
|
30
|
-
/** Requested model identity, matching the durable assistant source. */
|
|
31
|
-
model: string;
|
|
32
|
-
/** Provider-reported model; only Anthropic replays it as the native model (reported in `message.model`, not `message.responseModel`). */
|
|
33
|
-
responseModel?: string;
|
|
34
|
-
responseId?: string;
|
|
35
|
-
/** Provider-native effort for historical replay; absence is preserved. */
|
|
36
|
-
providerThinkingLevel?: string;
|
|
37
|
-
stopReason: AssistantMessage['stopReason'];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Project a successful pi-ai response into the minimal durable replay state.
|
|
41
|
-
* The per-block half is index-aligned with the streamed blocks (pi-ai content
|
|
42
|
-
* order), so `BlockAssembler` prunes an entry with its block whenever assembly
|
|
43
|
-
* removes one.
|
|
44
|
-
* @param message - completed native pi-ai assistant response.
|
|
45
|
-
* @param requestedModel - request identity stored in the assistant source; defaults to the native model.
|
|
46
|
-
* @returns the versioned lossless-JSON replay projection.
|
|
47
|
-
*/
|
|
48
|
-
export declare function toPiReplayState(message: AssistantMessage, requestedModel?: string): ReplayEnvelope;
|
|
49
|
-
/**
|
|
50
|
-
* Convert one durable Harness assistant message into pi-ai history.
|
|
51
|
-
*
|
|
52
|
-
* Durable content is the authoritative record; replay metadata only restores
|
|
53
|
-
* native fidelity (ids, signatures). A replay state this build cannot use —
|
|
54
|
-
* another adapter's kind, another version, a malformed value, or metadata that
|
|
55
|
-
* no longer matches the content — therefore degrades the one message to
|
|
56
|
-
* provider-neutral history instead of failing the request.
|
|
57
|
-
* @param message - assistant content with required source and optional adapter-owned replay metadata.
|
|
58
|
-
* @param onDegrade - called with the diagnostic reason when an unusable replay
|
|
59
|
-
* state falls back to provider-neutral conversion.
|
|
60
|
-
* @returns a native pi-ai assistant message reconstructed from durable content.
|
|
61
|
-
*/
|
|
62
|
-
export declare function toPiAssistant(message: Message, onDegrade?: (reason: string) => void): AssistantMessage;
|
|
63
|
-
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pi-ai assistant event translation into the Harness streaming protocol.
|
|
3
|
-
*
|
|
4
|
-
* pi-ai tool-call arguments are parsed objects while the Harness keeps their
|
|
5
|
-
* raw JSON representation. pi-ai also reports failures as terminal stream
|
|
6
|
-
* events, which this module maps into Harness finish chunks.
|
|
7
|
-
*
|
|
8
|
-
* @module dsh-llm-pi-ai/stream
|
|
9
|
-
*/
|
|
10
|
-
import type { FinishReason, StreamChunk, TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
11
|
-
import type { AssistantMessage, AssistantMessageEvent, Usage as PiUsage } from '@earendil-works/pi-ai';
|
|
12
|
-
/**
|
|
13
|
-
* Map pi-ai usage (reasoning folded into output by pi-ai).
|
|
14
|
-
* @param usage - cumulative usage from the terminal pi-ai event.
|
|
15
|
-
* @returns harness counts with pi-ai's exact total; cache fields appear only
|
|
16
|
-
* when non-zero (pi-ai reports zeros, not absence).
|
|
17
|
-
*/
|
|
18
|
-
export declare function mapUsage(usage: PiUsage): TokenUsage;
|
|
19
|
-
/**
|
|
20
|
-
* Map a terminal pi-ai event to the harness finish reason.
|
|
21
|
-
* @param message - the assistant message carried by the `done` or `error` event.
|
|
22
|
-
* @param contextWindow - resolved catalog capacity for usage-based overflow detection.
|
|
23
|
-
* @returns the mapped harness reason. Recognized error text, `stop` usage above
|
|
24
|
-
* `contextWindow`, and zero-output `length` usage that fills the window map
|
|
25
|
-
* to `CONTEXT_WINDOW_EXCEEDED`; a `stop` with no content blocks maps to an
|
|
26
|
-
* `EMPTY_RESPONSE` error, while terminal `pending` and `deferred` states map
|
|
27
|
-
* to non-retryable `PI_AI_ERROR` failures.
|
|
28
|
-
*/
|
|
29
|
-
export declare function mapStopReason(message: AssistantMessage, contextWindow?: number): FinishReason;
|
|
30
|
-
/**
|
|
31
|
-
* Translate the pi-ai event stream into StreamChunks. pi-ai never throws
|
|
32
|
-
* mid-stream — failures arrive as `error` events, which become error/aborted
|
|
33
|
-
* `finish` chunks (the harness protocol's other error-delivery style).
|
|
34
|
-
* @param events - one assistant turn's pi-ai event stream.
|
|
35
|
-
* @param contextWindow - resolved catalog capacity for usage-based overflow detection.
|
|
36
|
-
* @param callerSignal - caller cancellation state; an aborted caller makes any
|
|
37
|
-
* in-band terminal error an aborted finish.
|
|
38
|
-
* @param requestedModel - request model identity for durable replay provenance.
|
|
39
|
-
* @returns the harness chunks, ending with `usage` then `finish`; throws
|
|
40
|
-
* `LlmError` (`STREAM_CLOSED`) if the source ends without a terminal event.
|
|
41
|
-
*/
|
|
42
|
-
export declare function toStreamChunks(events: AsyncIterable<AssistantMessageEvent>, contextWindow?: number, callerSignal?: AbortSignal, requestedModel?: string): AsyncGenerator<StreamChunk>;
|
|
43
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
File without changes
|