@yadsh/dsh-sleev 0.0.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.
- package/LICENSE +22 -0
- package/README.md +129 -0
- package/README.zh-CN.md +129 -0
- package/cordis.patch.yml +4 -0
- package/docs/compatibility.md +49 -0
- package/docs/development.md +76 -0
- package/docs/sample-settings.yml +34 -0
- package/lib/client.js +504 -0
- package/lib/host/optimizer/sleev/headers.js +44 -0
- package/lib/index.js +241 -0
- package/lib/shared/telemetry.js +1 -0
- package/lib/types/client/index.d.ts +17 -0
- package/lib/types/client/settings-controller.d.ts +59 -0
- package/lib/types/host/optimizer/sleev/headers.d.ts +29 -0
- package/lib/types/host/request-classifier.d.ts +5 -0
- package/lib/types/host/stream-observer.d.ts +15 -0
- package/lib/types/host/telemetry-store.d.ts +34 -0
- package/lib/types/host/usage.d.ts +7 -0
- package/lib/types/index.d.ts +29 -0
- package/lib/types/shared/config.d.ts +26 -0
- package/lib/types/shared/settings.d.ts +3 -0
- package/lib/types/shared/telemetry.d.ts +40 -0
- package/package.json +124 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import { installSettingsSection, settingsNamespace } from "@deepseek-ai/dsh-settings";
|
|
3
|
+
import z from "@deepseek-ai/schemastery";
|
|
4
|
+
import { isAgentLoopRequest } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
//#region src/shared/config.ts
|
|
7
|
+
/** Cordis loader schema. Semantic validation remains in {@link resolveConfig}. */
|
|
8
|
+
const ConfigSchema = z.object({
|
|
9
|
+
routes: z.array(z.string()).default([]),
|
|
10
|
+
routePrefixes: z.array(z.string()).default(["sleev-"]),
|
|
11
|
+
maxRecentCalls: z.number().step(1).min(1).default(100),
|
|
12
|
+
logLevel: z.union([
|
|
13
|
+
"off",
|
|
14
|
+
"info",
|
|
15
|
+
"debug"
|
|
16
|
+
]).default("info")
|
|
17
|
+
});
|
|
18
|
+
function uniqueNonEmpty(values, field) {
|
|
19
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20
|
+
const result = [];
|
|
21
|
+
for (const value of values) {
|
|
22
|
+
const normalized = value.trim();
|
|
23
|
+
if (normalized.length === 0) throw new Error(`dsh-sleev: ${field} cannot contain an empty value`);
|
|
24
|
+
if (seen.has(normalized)) continue;
|
|
25
|
+
seen.add(normalized);
|
|
26
|
+
result.push(normalized);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
/** Apply runtime defaults and reject ambiguous route matchers. */
|
|
31
|
+
function resolveConfig(config = {}) {
|
|
32
|
+
const maxRecentCalls = config.maxRecentCalls ?? 100;
|
|
33
|
+
if (!Number.isSafeInteger(maxRecentCalls) || maxRecentCalls < 1) throw new Error("dsh-sleev: maxRecentCalls must be a positive safe integer");
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
routes: Object.freeze(uniqueNonEmpty(config.routes ?? [], "routes")),
|
|
36
|
+
routePrefixes: Object.freeze(uniqueNonEmpty(config.routePrefixes ?? ["sleev-"], "routePrefixes")),
|
|
37
|
+
maxRecentCalls,
|
|
38
|
+
logLevel: config.logLevel ?? "info"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Whether a DSH route is explicitly declared as externally optimized. */
|
|
42
|
+
function matchesOptimizedRoute(provider, config) {
|
|
43
|
+
return config.routes.includes(provider) || config.routePrefixes.some((prefix) => provider.startsWith(prefix));
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/shared/settings.ts
|
|
47
|
+
/** Stable raw namespace shared by the Host registration and browser card. */
|
|
48
|
+
const SLEEV_SETTINGS_NAMESPACE_ID = "sleev";
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/host/request-classifier.ts
|
|
51
|
+
/** Classify main loop and known auxiliary calls without inspecting prompts. */
|
|
52
|
+
function classifyRequest(options) {
|
|
53
|
+
if (options.purpose === "compaction") return "compaction";
|
|
54
|
+
if (options.purpose === "session-title") return "session-title";
|
|
55
|
+
if (isAgentLoopRequest(options)) return "agent";
|
|
56
|
+
if (options.purpose === void 0) return "one-shot";
|
|
57
|
+
return "unknown";
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/host/stream-observer.ts
|
|
61
|
+
function errorCode(error) {
|
|
62
|
+
const code = error?.code;
|
|
63
|
+
return typeof code === "string" && code.length > 0 ? code : void 0;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Observe usage and terminal state while yielding every downstream chunk once,
|
|
67
|
+
* unchanged and without buffering. Early consumer return is recorded as abort.
|
|
68
|
+
*/
|
|
69
|
+
async function* observeStream(downstream, observation) {
|
|
70
|
+
let terminal = false;
|
|
71
|
+
try {
|
|
72
|
+
for await (const chunk of downstream) {
|
|
73
|
+
if (chunk.type === "usage") observation.observeUsage(chunk.usage);
|
|
74
|
+
if (chunk.type === "finish") {
|
|
75
|
+
terminal = true;
|
|
76
|
+
if (chunk.reason.kind === "aborted") observation.finish({ kind: "aborted" });
|
|
77
|
+
else if (chunk.reason.kind === "error") observation.finish({
|
|
78
|
+
kind: "error",
|
|
79
|
+
...chunk.reason.failure.code.length === 0 ? {} : { code: chunk.reason.failure.code }
|
|
80
|
+
});
|
|
81
|
+
else observation.finish({ kind: "success" });
|
|
82
|
+
}
|
|
83
|
+
yield chunk;
|
|
84
|
+
}
|
|
85
|
+
if (!terminal) {
|
|
86
|
+
terminal = true;
|
|
87
|
+
observation.finish({
|
|
88
|
+
kind: "error",
|
|
89
|
+
code: "STREAM_INCOMPLETE"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (!terminal) {
|
|
94
|
+
terminal = true;
|
|
95
|
+
const code = errorCode(error);
|
|
96
|
+
observation.finish({
|
|
97
|
+
kind: "error",
|
|
98
|
+
...code === void 0 ? {} : { code }
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
} finally {
|
|
103
|
+
if (!terminal) observation.finish({ kind: "aborted" });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/host/usage.ts
|
|
108
|
+
/** Normalize optional cache buckets while preserving disjoint semantics. */
|
|
109
|
+
function normalizeUsage(usage) {
|
|
110
|
+
return Object.freeze({
|
|
111
|
+
inputTokens: usage.inputTokens,
|
|
112
|
+
outputTokens: usage.outputTokens,
|
|
113
|
+
cacheReadTokens: usage.cacheReadTokens ?? 0,
|
|
114
|
+
cacheWriteTokens: usage.cacheWriteTokens ?? 0,
|
|
115
|
+
...usage.reasoningTokens === void 0 ? {} : { reasoningTokens: usage.reasoningTokens }
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Compute effective provider input as uncached + cache reads + cache writes. */
|
|
119
|
+
function deriveUsage(usage) {
|
|
120
|
+
return Object.freeze({ effectiveInputTokens: usage.inputTokens + usage.cacheReadTokens + usage.cacheWriteTokens });
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/host/telemetry-store.ts
|
|
124
|
+
/** Bounded, process-local telemetry owner for the M1 observer. */
|
|
125
|
+
var CallTelemetryStore = class {
|
|
126
|
+
logger;
|
|
127
|
+
completed = [];
|
|
128
|
+
now;
|
|
129
|
+
createId;
|
|
130
|
+
constructor(logger, config, options = {}) {
|
|
131
|
+
this.logger = logger;
|
|
132
|
+
this.readConfig = typeof config === "function" ? config : () => config;
|
|
133
|
+
this.now = options.now ?? Date.now;
|
|
134
|
+
this.createId = options.createId ?? randomUUID;
|
|
135
|
+
}
|
|
136
|
+
readConfig;
|
|
137
|
+
/** Begin one call and return an idempotent lifecycle sink. */
|
|
138
|
+
begin(options, kind) {
|
|
139
|
+
const startConfig = this.readConfig();
|
|
140
|
+
const callId = this.createId();
|
|
141
|
+
const startedAt = this.now();
|
|
142
|
+
let usage;
|
|
143
|
+
let finished = false;
|
|
144
|
+
if (startConfig.logLevel === "debug") this.logger.debug(`dsh-sleev: call-start ${JSON.stringify({
|
|
145
|
+
callId,
|
|
146
|
+
provider: options.provider,
|
|
147
|
+
model: options.model,
|
|
148
|
+
kind,
|
|
149
|
+
sessionId: options.sessionId
|
|
150
|
+
})}`);
|
|
151
|
+
return {
|
|
152
|
+
observeUsage: (value) => {
|
|
153
|
+
usage = normalizeUsage(value);
|
|
154
|
+
},
|
|
155
|
+
finish: (result) => {
|
|
156
|
+
if (finished) return;
|
|
157
|
+
finished = true;
|
|
158
|
+
const finishedAt = this.now();
|
|
159
|
+
const telemetry = Object.freeze({
|
|
160
|
+
schemaVersion: 1,
|
|
161
|
+
callId,
|
|
162
|
+
...options.sessionId === void 0 ? {} : { sessionId: String(options.sessionId) },
|
|
163
|
+
kind,
|
|
164
|
+
provider: options.provider,
|
|
165
|
+
model: options.model,
|
|
166
|
+
optimizer: "sleev",
|
|
167
|
+
startedAt,
|
|
168
|
+
finishedAt,
|
|
169
|
+
durationMs: Math.max(0, finishedAt - startedAt),
|
|
170
|
+
...usage === void 0 ? {} : {
|
|
171
|
+
providerUsage: usage,
|
|
172
|
+
derived: deriveUsage(usage)
|
|
173
|
+
},
|
|
174
|
+
result
|
|
175
|
+
});
|
|
176
|
+
this.completed.push(telemetry);
|
|
177
|
+
const finishConfig = this.reconfigure();
|
|
178
|
+
if (finishConfig.logLevel !== "off") {
|
|
179
|
+
const message = `dsh-sleev: call-end ${JSON.stringify(telemetry)}`;
|
|
180
|
+
if (finishConfig.logLevel === "debug") this.logger.debug(message);
|
|
181
|
+
else this.logger.info(message);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** Return a detached newest-last snapshot for diagnostics and future UI. */
|
|
187
|
+
listRecent() {
|
|
188
|
+
return this.completed.slice();
|
|
189
|
+
}
|
|
190
|
+
/** Apply a changed retention bound immediately and return its config. */
|
|
191
|
+
reconfigure() {
|
|
192
|
+
const config = this.readConfig();
|
|
193
|
+
if (this.completed.length > config.maxRecentCalls) this.completed.splice(0, this.completed.length - config.maxRecentCalls);
|
|
194
|
+
return config;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/index.ts
|
|
199
|
+
const name = "dsh-sleev";
|
|
200
|
+
/** User-editable settings section rendered by the browser client card. */
|
|
201
|
+
const SLEEV_SETTINGS_NAMESPACE = settingsNamespace(SLEEV_SETTINGS_NAMESPACE_ID);
|
|
202
|
+
/** Host-side observer service. Routing itself remains owned by llm-pi-ai. */
|
|
203
|
+
var SleevIntegrationService = class extends Service {
|
|
204
|
+
static inject = ["llm"];
|
|
205
|
+
static Config = ConfigSchema;
|
|
206
|
+
telemetry;
|
|
207
|
+
constructor(ctx, input = {}) {
|
|
208
|
+
super(ctx, "sleev");
|
|
209
|
+
const resolvedEntry = resolveConfig(input);
|
|
210
|
+
const entry = {
|
|
211
|
+
routes: [...resolvedEntry.routes],
|
|
212
|
+
routePrefixes: [...resolvedEntry.routePrefixes],
|
|
213
|
+
maxRecentCalls: resolvedEntry.maxRecentCalls,
|
|
214
|
+
logLevel: resolvedEntry.logLevel
|
|
215
|
+
};
|
|
216
|
+
let configSource = () => entry;
|
|
217
|
+
this.telemetry = new CallTelemetryStore(ctx.logger, () => resolveConfig(configSource()));
|
|
218
|
+
installSettingsSection(ctx, SLEEV_SETTINGS_NAMESPACE, ConfigSchema, entry, {
|
|
219
|
+
setSource: (current) => {
|
|
220
|
+
configSource = current;
|
|
221
|
+
},
|
|
222
|
+
onChange: () => this.telemetry.reconfigure()
|
|
223
|
+
});
|
|
224
|
+
ctx.on("llm/stream", (options, next) => {
|
|
225
|
+
const config = resolveConfig(configSource());
|
|
226
|
+
if (!matchesOptimizedRoute(options.provider, config)) return next();
|
|
227
|
+
const handle = this.telemetry.begin(options, classifyRequest(options));
|
|
228
|
+
return observeStream(next(), handle);
|
|
229
|
+
}, { global: true });
|
|
230
|
+
if (resolvedEntry.logLevel !== "off") ctx.logger.info(`dsh-sleev: observer active ${JSON.stringify({
|
|
231
|
+
routes: resolvedEntry.routes,
|
|
232
|
+
routePrefixes: resolvedEntry.routePrefixes
|
|
233
|
+
})}`);
|
|
234
|
+
}
|
|
235
|
+
/** Bounded completed-call snapshot; no prompts, headers, or credentials. */
|
|
236
|
+
listRecentCalls() {
|
|
237
|
+
return this.telemetry.listRecent();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
export { CallTelemetryStore, ConfigSchema, SLEEV_SETTINGS_NAMESPACE, SleevIntegrationService, SleevIntegrationService as default, classifyRequest, deriveUsage, matchesOptimizedRoute, name, normalizeUsage, observeStream, resolveConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ClientContext } from "@deepseek-ai/dsh-client-runtime/client";
|
|
2
|
+
import type { InjectFace, PropsLocale, PropsRuntime } from "@deepseek-ai/dsh-client-ui-slots";
|
|
3
|
+
import { type SleevSettingsCardFace } from "./settings-controller.js";
|
|
4
|
+
export * from "./settings-controller.js";
|
|
5
|
+
type SleevLocaleKey = "title" | "description" | "expand" | "collapse" | "unsaved" | "overridden" | "reset" | "routes" | "routesHint" | "routePrefixes" | "routePrefixesHint" | "maxRecentCalls" | "maxRecentCallsHint" | "logLevel" | "logLevelHint" | "logOff" | "logInfo" | "logDebug" | "invalidNumber" | "readOnly" | "saveFailed" | "discard" | "save" | "saving";
|
|
6
|
+
declare module "@deepseek-ai/dsh-client-ui-slots" {
|
|
7
|
+
interface LocaleNamespaceMap {
|
|
8
|
+
"dsh-sleev": SleevLocaleKey;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
type SleevSettingsCardProps = PropsRuntime<"settings.plugin.item"> & PropsLocale<"dsh-sleev"> & InjectFace<SleevSettingsCardFace>;
|
|
12
|
+
/** Settings card contributed to the official Plugins → Plugin configuration tab. */
|
|
13
|
+
export declare function SleevSettingsCard(props: SleevSettingsCardProps): import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export declare const inject: string[];
|
|
15
|
+
/** Register Sleev's localized settings card in the official keyed plugin slot. */
|
|
16
|
+
export declare function apply(ctx: ClientContext): void;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type SettingsScope, type SnapshotStore } from "@deepseek-ai/dsh-client-runtime/client";
|
|
2
|
+
export type SleevLogLevel = "off" | "info" | "debug";
|
|
3
|
+
/** Browser-visible shape of the Host `sleev` settings namespace. */
|
|
4
|
+
export interface SleevSettings {
|
|
5
|
+
readonly routes?: string[];
|
|
6
|
+
readonly routePrefixes?: string[];
|
|
7
|
+
readonly maxRecentCalls?: number;
|
|
8
|
+
readonly logLevel?: SleevLogLevel;
|
|
9
|
+
}
|
|
10
|
+
export type SleevSettingsField = keyof SleevSettings;
|
|
11
|
+
export interface SleevSettingsFieldState {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly overridden: boolean;
|
|
14
|
+
readonly invalid: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface SleevSettingsCardState {
|
|
17
|
+
readonly available: boolean;
|
|
18
|
+
readonly writable: boolean;
|
|
19
|
+
readonly dirty: boolean;
|
|
20
|
+
readonly invalid: boolean;
|
|
21
|
+
readonly saving: boolean;
|
|
22
|
+
readonly failed: boolean;
|
|
23
|
+
readonly routes: SleevSettingsFieldState;
|
|
24
|
+
readonly routePrefixes: SleevSettingsFieldState;
|
|
25
|
+
readonly maxRecentCalls: SleevSettingsFieldState;
|
|
26
|
+
readonly logLevel: SleevSettingsFieldState;
|
|
27
|
+
}
|
|
28
|
+
export interface SleevSettingsCardFace {
|
|
29
|
+
readonly hooks: {
|
|
30
|
+
readonly sleevSettings: SnapshotStore<SleevSettingsCardState>;
|
|
31
|
+
};
|
|
32
|
+
readonly edit: (field: SleevSettingsField, value: string) => void;
|
|
33
|
+
readonly save: () => void;
|
|
34
|
+
readonly discard: () => void;
|
|
35
|
+
readonly resetField: (field: SleevSettingsField) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Staged form controller matching DSH's built-in plugin settings cards. */
|
|
38
|
+
export declare class SleevSettingsController {
|
|
39
|
+
private readonly scope;
|
|
40
|
+
private readonly drafts;
|
|
41
|
+
private readonly store;
|
|
42
|
+
private readonly unsubscribe;
|
|
43
|
+
private saving;
|
|
44
|
+
private failed;
|
|
45
|
+
constructor(scope: SettingsScope<SleevSettings>);
|
|
46
|
+
inject(): SleevSettingsCardFace;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
private base;
|
|
49
|
+
private effective;
|
|
50
|
+
private stored;
|
|
51
|
+
private format;
|
|
52
|
+
private parse;
|
|
53
|
+
private fieldState;
|
|
54
|
+
private plan;
|
|
55
|
+
private project;
|
|
56
|
+
private save;
|
|
57
|
+
private publish;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=settings-controller.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Default loopback listener installed by the Sleev CLI. */
|
|
2
|
+
export declare const DEFAULT_SLEEV_GATEWAY_URL = "http://127.0.0.1:17321/v1";
|
|
3
|
+
/**
|
|
4
|
+
* Temporary compatibility choice for DSH's pi-ai transport.
|
|
5
|
+
*
|
|
6
|
+
* Sleev does not currently document a native DeepSeek Harness id. Keep this
|
|
7
|
+
* value visible and user-overridable rather than presenting it as guaranteed.
|
|
8
|
+
*/
|
|
9
|
+
export declare const EXPERIMENTAL_DSH_HARNESS_ID = "pi";
|
|
10
|
+
/** Route a provider Sleev knows by its provider id. */
|
|
11
|
+
export interface SleevKnownProviderTarget {
|
|
12
|
+
readonly kind: "provider";
|
|
13
|
+
readonly provider: string;
|
|
14
|
+
readonly harnessId: string;
|
|
15
|
+
}
|
|
16
|
+
/** Route an arbitrary OpenAI-compatible upstream URL through Sleev. */
|
|
17
|
+
export interface SleevCustomProviderTarget {
|
|
18
|
+
readonly kind: "custom";
|
|
19
|
+
readonly baseUrl: string;
|
|
20
|
+
readonly harnessId: string;
|
|
21
|
+
}
|
|
22
|
+
/** Sleev routing target accepted by {@link buildSleevHeaders}. */
|
|
23
|
+
export type SleevRouteTarget = SleevKnownProviderTarget | SleevCustomProviderTarget;
|
|
24
|
+
/**
|
|
25
|
+
* Build only the public Sleev routing headers. Authorization remains owned by
|
|
26
|
+
* DSH credentials and llm-pi-ai, so this result can be logged or inspected.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildSleevHeaders(target: SleevRouteTarget): Readonly<Record<string, string>>;
|
|
29
|
+
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type GenerateOptions } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { RequestKind } from "../shared/telemetry.js";
|
|
3
|
+
/** Classify main loop and known auxiliary calls without inspecting prompts. */
|
|
4
|
+
export declare function classifyRequest(options: GenerateOptions): RequestKind;
|
|
5
|
+
//# sourceMappingURL=request-classifier.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StreamChunk } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { CallResult } from "../shared/telemetry.js";
|
|
3
|
+
/** Lifecycle callbacks used by the transparent stream wrapper. */
|
|
4
|
+
export interface StreamObservation {
|
|
5
|
+
observeUsage(usage: Extract<StreamChunk, {
|
|
6
|
+
type: "usage";
|
|
7
|
+
}>["usage"]): void;
|
|
8
|
+
finish(result: CallResult): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Observe usage and terminal state while yielding every downstream chunk once,
|
|
12
|
+
* unchanged and without buffering. Early consumer return is recorded as abort.
|
|
13
|
+
*/
|
|
14
|
+
export declare function observeStream(downstream: AsyncIterable<StreamChunk>, observation: StreamObservation): AsyncIterable<StreamChunk>;
|
|
15
|
+
//# sourceMappingURL=stream-observer.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GenerateOptions, TokenUsage } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { ResolvedConfig } from "../shared/config.js";
|
|
3
|
+
import type { CallResult, OptimizerCallTelemetry, RequestKind } from "../shared/telemetry.js";
|
|
4
|
+
/** Minimal logger face used by Cordis and isolated unit tests. */
|
|
5
|
+
export interface TelemetryLogger {
|
|
6
|
+
debug(message: string): void;
|
|
7
|
+
info(message: string): void;
|
|
8
|
+
}
|
|
9
|
+
/** Mutable handle kept only for the duration of a streaming call. */
|
|
10
|
+
export interface CallHandle {
|
|
11
|
+
observeUsage(usage: TokenUsage): void;
|
|
12
|
+
finish(result: CallResult): void;
|
|
13
|
+
}
|
|
14
|
+
interface StoreOptions {
|
|
15
|
+
readonly now?: () => number;
|
|
16
|
+
readonly createId?: () => string;
|
|
17
|
+
}
|
|
18
|
+
/** Bounded, process-local telemetry owner for the M1 observer. */
|
|
19
|
+
export declare class CallTelemetryStore {
|
|
20
|
+
private readonly logger;
|
|
21
|
+
private readonly completed;
|
|
22
|
+
private readonly now;
|
|
23
|
+
private readonly createId;
|
|
24
|
+
constructor(logger: TelemetryLogger, config: ResolvedConfig | (() => ResolvedConfig), options?: StoreOptions);
|
|
25
|
+
private readonly readConfig;
|
|
26
|
+
/** Begin one call and return an idempotent lifecycle sink. */
|
|
27
|
+
begin(options: GenerateOptions, kind: RequestKind): CallHandle;
|
|
28
|
+
/** Return a detached newest-last snapshot for diagnostics and future UI. */
|
|
29
|
+
listRecent(): readonly OptimizerCallTelemetry[];
|
|
30
|
+
/** Apply a changed retention bound immediately and return its config. */
|
|
31
|
+
reconfigure(): ResolvedConfig;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=telemetry-store.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TokenUsage } from "@deepseek-ai/dsh-llm";
|
|
2
|
+
import type { DerivedUsageTelemetry, ProviderUsageTelemetry } from "../shared/telemetry.js";
|
|
3
|
+
/** Normalize optional cache buckets while preserving disjoint semantics. */
|
|
4
|
+
export declare function normalizeUsage(usage: TokenUsage): ProviderUsageTelemetry;
|
|
5
|
+
/** Compute effective provider input as uncached + cache reads + cache writes. */
|
|
6
|
+
export declare function deriveUsage(usage: ProviderUsageTelemetry): DerivedUsageTelemetry;
|
|
7
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Context, Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Config } from "./shared/config.js";
|
|
3
|
+
import type { OptimizerCallTelemetry } from "./shared/telemetry.js";
|
|
4
|
+
export declare const name = "dsh-sleev";
|
|
5
|
+
/** User-editable settings section rendered by the browser client card. */
|
|
6
|
+
export declare const SLEEV_SETTINGS_NAMESPACE: import("@deepseek-ai/dsh-settings").SettingsNamespace;
|
|
7
|
+
declare module "@deepseek-ai/cordis" {
|
|
8
|
+
interface Context {
|
|
9
|
+
sleev: SleevIntegrationService;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Host-side observer service. Routing itself remains owned by llm-pi-ai. */
|
|
13
|
+
export declare class SleevIntegrationService extends Service {
|
|
14
|
+
static inject: string[];
|
|
15
|
+
static Config: import("@deepseek-ai/schemastery").default<Config>;
|
|
16
|
+
private readonly telemetry;
|
|
17
|
+
constructor(ctx: Context, input?: Config);
|
|
18
|
+
/** Bounded completed-call snapshot; no prompts, headers, or credentials. */
|
|
19
|
+
listRecentCalls(): readonly OptimizerCallTelemetry[];
|
|
20
|
+
}
|
|
21
|
+
export { classifyRequest } from "./host/request-classifier.js";
|
|
22
|
+
export { observeStream } from "./host/stream-observer.js";
|
|
23
|
+
export { CallTelemetryStore } from "./host/telemetry-store.js";
|
|
24
|
+
export { deriveUsage, normalizeUsage } from "./host/usage.js";
|
|
25
|
+
export { ConfigSchema, matchesOptimizedRoute, resolveConfig, } from "./shared/config.js";
|
|
26
|
+
export type { Config, ResolvedConfig } from "./shared/config.js";
|
|
27
|
+
export type * from "./shared/telemetry.js";
|
|
28
|
+
export default SleevIntegrationService;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
/** Loader configuration for the host-side Sleev observer. */
|
|
3
|
+
export interface Config {
|
|
4
|
+
/** Exact DSH provider route names known to pass through Sleev. */
|
|
5
|
+
readonly routes?: string[];
|
|
6
|
+
/** Provider-name prefixes known to pass through Sleev (default `sleev-`). */
|
|
7
|
+
readonly routePrefixes?: string[];
|
|
8
|
+
/** Maximum number of completed calls retained in process memory (default 100). */
|
|
9
|
+
readonly maxRecentCalls?: number;
|
|
10
|
+
/** Telemetry logging verbosity (default `info`). */
|
|
11
|
+
readonly logLevel?: "off" | "info" | "debug";
|
|
12
|
+
}
|
|
13
|
+
/** Fully materialized and validated observer configuration. */
|
|
14
|
+
export interface ResolvedConfig {
|
|
15
|
+
readonly routes: readonly string[];
|
|
16
|
+
readonly routePrefixes: readonly string[];
|
|
17
|
+
readonly maxRecentCalls: number;
|
|
18
|
+
readonly logLevel: "off" | "info" | "debug";
|
|
19
|
+
}
|
|
20
|
+
/** Cordis loader schema. Semantic validation remains in {@link resolveConfig}. */
|
|
21
|
+
export declare const ConfigSchema: z<Config>;
|
|
22
|
+
/** Apply runtime defaults and reject ambiguous route matchers. */
|
|
23
|
+
export declare function resolveConfig(config?: Config): ResolvedConfig;
|
|
24
|
+
/** Whether a DSH route is explicitly declared as externally optimized. */
|
|
25
|
+
export declare function matchesOptimizedRoute(provider: string, config: Pick<ResolvedConfig, "routes" | "routePrefixes">): boolean;
|
|
26
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Stable request classification used by host metrics and future clients. */
|
|
2
|
+
export type RequestKind = "agent" | "compaction" | "session-title" | "one-shot" | "unknown";
|
|
3
|
+
/** Provider-reported disjoint token buckets. */
|
|
4
|
+
export interface ProviderUsageTelemetry {
|
|
5
|
+
readonly inputTokens: number;
|
|
6
|
+
readonly outputTokens: number;
|
|
7
|
+
readonly cacheReadTokens: number;
|
|
8
|
+
readonly cacheWriteTokens: number;
|
|
9
|
+
readonly reasoningTokens?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Derived wire-boundary token-volume metrics. */
|
|
12
|
+
export interface DerivedUsageTelemetry {
|
|
13
|
+
readonly effectiveInputTokens: number;
|
|
14
|
+
}
|
|
15
|
+
/** Terminal result of one observed model call. */
|
|
16
|
+
export type CallResult = {
|
|
17
|
+
readonly kind: "success";
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "error";
|
|
20
|
+
readonly code?: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "aborted";
|
|
23
|
+
};
|
|
24
|
+
/** Secret-free telemetry for one request routed through an optimizer alias. */
|
|
25
|
+
export interface OptimizerCallTelemetry {
|
|
26
|
+
readonly schemaVersion: 1;
|
|
27
|
+
readonly callId: string;
|
|
28
|
+
readonly sessionId?: string;
|
|
29
|
+
readonly kind: RequestKind;
|
|
30
|
+
readonly provider: string;
|
|
31
|
+
readonly model: string;
|
|
32
|
+
readonly optimizer: "sleev";
|
|
33
|
+
readonly startedAt: number;
|
|
34
|
+
readonly finishedAt: number;
|
|
35
|
+
readonly durationMs: number;
|
|
36
|
+
readonly providerUsage?: ProviderUsageTelemetry;
|
|
37
|
+
readonly derived?: DerivedUsageTelemetry;
|
|
38
|
+
readonly result: CallResult;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=telemetry.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yadsh/dsh-sleev",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Sleev routing observability for DeepSeek Harness",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/xarleyn/dsh-plugins.git",
|
|
8
|
+
"directory": "plugins/dsh-sleev"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/xarleyn/dsh-plugins/tree/main/plugins/dsh-sleev#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/xarleyn/dsh-plugins/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/types/index.d.ts",
|
|
20
|
+
"default": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./client": {
|
|
23
|
+
"types": "./lib/types/client/index.d.ts",
|
|
24
|
+
"default": "./lib/client.js"
|
|
25
|
+
},
|
|
26
|
+
"./telemetry": {
|
|
27
|
+
"types": "./lib/types/shared/telemetry.d.ts",
|
|
28
|
+
"default": "./lib/shared/telemetry.js"
|
|
29
|
+
},
|
|
30
|
+
"./sleev": {
|
|
31
|
+
"types": "./lib/types/host/optimizer/sleev/headers.d.ts",
|
|
32
|
+
"default": "./lib/host/optimizer/sleev/headers.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"dsh": {
|
|
37
|
+
"bundle": {
|
|
38
|
+
"patch": "./cordis.patch.yml"
|
|
39
|
+
},
|
|
40
|
+
"client": {
|
|
41
|
+
"inject": [
|
|
42
|
+
"@deepseek-ai/dsh-client-locale",
|
|
43
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
44
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins"
|
|
45
|
+
],
|
|
46
|
+
"platform": "web"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"lib/**/*.js",
|
|
51
|
+
"lib/types/**/*.d.ts",
|
|
52
|
+
"cordis.patch.yml",
|
|
53
|
+
"docs/*",
|
|
54
|
+
"README.md",
|
|
55
|
+
"README.zh-CN.md",
|
|
56
|
+
"LICENSE"
|
|
57
|
+
],
|
|
58
|
+
"scripts": {
|
|
59
|
+
"clean": "node -e \"require('node:fs').rmSync('lib', { recursive: true, force: true })\"",
|
|
60
|
+
"lint": "eslint src tests scripts",
|
|
61
|
+
"format": "prettier --check . --end-of-line auto",
|
|
62
|
+
"format:write": "prettier --write . --end-of-line auto",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:package": "node scripts/verify-package.mjs",
|
|
66
|
+
"verify": "pnpm run test:package",
|
|
67
|
+
"smoke:packed": "node scripts/smoke-packed-dsh.mjs",
|
|
68
|
+
"build": "pnpm run clean && tsdown && tsc -p tsconfig.build.json",
|
|
69
|
+
"smoke:neuraldeep": "tsx scripts/smoke-neuraldeep.ts",
|
|
70
|
+
"check": "pnpm run format && pnpm run typecheck && pnpm run test && pnpm run build && pnpm run test:package",
|
|
71
|
+
"prepare": "tsdown && tsc -p tsconfig.build.json",
|
|
72
|
+
"prepublishOnly": "pnpm run check"
|
|
73
|
+
},
|
|
74
|
+
"keywords": [
|
|
75
|
+
"deepseek",
|
|
76
|
+
"deepseek-harness",
|
|
77
|
+
"dsh",
|
|
78
|
+
"dsh-plugin",
|
|
79
|
+
"sleev",
|
|
80
|
+
"context-optimization"
|
|
81
|
+
],
|
|
82
|
+
"license": "MIT",
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@deepseek-ai/cordis": "catalog:dsh",
|
|
88
|
+
"@deepseek-ai/schemastery": "catalog:dsh",
|
|
89
|
+
"@deepseek-ai/dsh-client-locale": "catalog:dsh",
|
|
90
|
+
"@deepseek-ai/dsh-client-runtime": "catalog:dsh",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-settings": "catalog:dsh",
|
|
92
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "catalog:dsh",
|
|
93
|
+
"@deepseek-ai/dsh-client-ui-slots": "catalog:dsh",
|
|
94
|
+
"@deepseek-ai/dsh-llm": "catalog:dsh",
|
|
95
|
+
"@deepseek-ai/dsh-settings": "catalog:dsh",
|
|
96
|
+
"react": "^18.2.0"
|
|
97
|
+
},
|
|
98
|
+
"dependencies": {},
|
|
99
|
+
"devDependencies": {
|
|
100
|
+
"@deepseek-ai/cordis": "catalog:dsh-dev",
|
|
101
|
+
"@deepseek-ai/schemastery": "catalog:dsh-dev",
|
|
102
|
+
"@deepseek-ai/dsh-client-locale": "catalog:dsh-dev",
|
|
103
|
+
"@deepseek-ai/dsh-client-runtime": "catalog:dsh-dev",
|
|
104
|
+
"@deepseek-ai/dsh-client-ui-settings": "catalog:dsh-dev",
|
|
105
|
+
"@deepseek-ai/dsh-client-ui-settings-plugins": "catalog:dsh-dev",
|
|
106
|
+
"@deepseek-ai/dsh-client-ui-slots": "catalog:dsh-dev",
|
|
107
|
+
"@deepseek-ai/dsh-llm": "catalog:dsh-dev",
|
|
108
|
+
"@deepseek-ai/dsh-llm-pi-ai": "catalog:dsh-dev",
|
|
109
|
+
"@deepseek-ai/dsh-settings": "catalog:dsh-dev",
|
|
110
|
+
"@types/node": "catalog:tooling",
|
|
111
|
+
"@types/react": "catalog:frontend-dev",
|
|
112
|
+
"eslint": "catalog:tooling",
|
|
113
|
+
"prettier": "catalog:tooling",
|
|
114
|
+
"react": "catalog:frontend-dev",
|
|
115
|
+
"tsdown": "catalog:tooling",
|
|
116
|
+
"tsx": "4.22.4",
|
|
117
|
+
"typescript": "catalog:plugin-tooling",
|
|
118
|
+
"vitest": "catalog:tooling"
|
|
119
|
+
},
|
|
120
|
+
"publishConfig": {
|
|
121
|
+
"access": "public",
|
|
122
|
+
"registry": "https://registry.npmjs.org/"
|
|
123
|
+
}
|
|
124
|
+
}
|