dsh-lcx-codex 0.4.2 → 0.4.3-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -202
- package/cordis.patch.yml +3 -20
- package/lib/client.js +273 -146
- package/lib/compact-v2.js +218 -199
- package/lib/dsh-compat.js +227 -100
- package/lib/dsh-responses.js +445 -277
- package/lib/index.js +851 -757
- package/lib/json-store.js +50 -31
- package/lib/native-checkpoint.js +520 -194
- package/lib/responses-request.js +106 -121
- package/lib/responses-stream.js +972 -443
- package/lib/route.js +229 -355
- package/lib/service-mutex.js +73 -64
- package/lib/token-budget.js +176 -108
- package/lib/transport.js +277 -67
- package/lib/types/client/index.d.ts +6 -0
- package/lib/types/compact-v2.d.ts +104 -0
- package/lib/types/dsh-compat.d.ts +78 -0
- package/lib/types/dsh-responses.d.ts +82 -0
- package/lib/types/index.d.ts +83 -0
- package/lib/types/json-store.d.ts +10 -0
- package/lib/types/native-checkpoint.d.ts +213 -0
- package/lib/types/responses-request.d.ts +58 -0
- package/lib/types/responses-stream.d.ts +51 -0
- package/lib/types/route.d.ts +132 -0
- package/lib/types/service-mutex.d.ts +14 -0
- package/lib/types/token-budget.d.ts +50 -0
- package/lib/types/transport.d.ts +20 -0
- package/lib/types/web-run-output.d.ts +29 -0
- package/lib/types/web-search-alpha.d.ts +286 -0
- package/lib/types/web-search-capability.d.ts +26 -0
- package/lib/types/web-search-hosted.d.ts +246 -0
- package/lib/types/web-search-ref-store.d.ts +22 -0
- package/lib/web-run-output.js +167 -18
- package/lib/web-search-alpha.js +865 -163
- package/lib/web-search-capability.js +55 -65
- package/lib/web-search-hosted.js +210 -32
- package/lib/web-search-ref-store.js +63 -59
- package/package.json +79 -27
- package/ARCHITECTURE.md +0 -117
- package/CHANGELOG.md +0 -224
- package/README_EN.md +0 -277
- package/assets/dsh-lcx-codex-banner.jpg +0 -0
- package/lib/legacy-v3.js +0 -20
- package/lib/responses-replay.js +0 -68
- package/scripts/probe-alpha.mjs +0 -43
- package/scripts/validate-dsh-schema.mjs +0 -31
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import "@deepseek-ai/dsh-agent";
|
|
4
|
+
import "@deepseek-ai/dsh-tools";
|
|
5
|
+
import "@deepseek-ai/dsh-web";
|
|
6
|
+
export declare const name = "lcx-codex";
|
|
7
|
+
export declare const inject: string[];
|
|
8
|
+
type ConfigInput = {
|
|
9
|
+
supportsLongCacheRetention?: unknown;
|
|
10
|
+
supportsExplicitPromptCacheMode?: unknown;
|
|
11
|
+
alphaCapabilityPath?: unknown;
|
|
12
|
+
alphaRefPath?: unknown;
|
|
13
|
+
alphaProfile?: unknown;
|
|
14
|
+
alphaGroup?: unknown;
|
|
15
|
+
alphaMaxOutputTokens?: unknown;
|
|
16
|
+
webSearchProvider?: unknown;
|
|
17
|
+
webMaxResults?: unknown;
|
|
18
|
+
timeoutMs?: unknown;
|
|
19
|
+
maxResponseBytes?: unknown;
|
|
20
|
+
maxAttempts?: unknown;
|
|
21
|
+
maxRequestImageBytes?: unknown;
|
|
22
|
+
requestImagePixelBudget?: unknown;
|
|
23
|
+
requestImageMaxBytes?: unknown;
|
|
24
|
+
portableReplayMaxChars?: unknown;
|
|
25
|
+
nativeRetentionTokenBudget?: unknown;
|
|
26
|
+
assistantRetentionTokenReserve?: unknown;
|
|
27
|
+
assistantRetentionPerMessageTokenCap?: unknown;
|
|
28
|
+
};
|
|
29
|
+
type HostContext = Context;
|
|
30
|
+
export declare const Config: z<Schemastery.ObjectS<{
|
|
31
|
+
supportsLongCacheRetention: z<boolean, boolean>;
|
|
32
|
+
supportsExplicitPromptCacheMode: z<boolean, boolean>;
|
|
33
|
+
alphaCapabilityPath: z<string, string>;
|
|
34
|
+
alphaRefPath: z<string, string>;
|
|
35
|
+
alphaProfile: z<string, string>;
|
|
36
|
+
alphaGroup: z<string, string>;
|
|
37
|
+
alphaMaxOutputTokens: z<number, number>;
|
|
38
|
+
webSearchProvider: z<string, string>;
|
|
39
|
+
webMaxResults: z<number, number>;
|
|
40
|
+
timeoutMs: z<number, number>;
|
|
41
|
+
maxResponseBytes: z<number, number>;
|
|
42
|
+
maxAttempts: z<number, number>;
|
|
43
|
+
maxRequestImageBytes: z<number, number>;
|
|
44
|
+
requestImagePixelBudget: z<number, number>;
|
|
45
|
+
requestImageMaxBytes: z<number, number>;
|
|
46
|
+
portableReplayMaxChars: z<number, number>;
|
|
47
|
+
nativeRetentionTokenBudget: z<number, number>;
|
|
48
|
+
assistantRetentionTokenReserve: z<number, number>;
|
|
49
|
+
assistantRetentionPerMessageTokenCap: z<number, number>;
|
|
50
|
+
}>, Schemastery.ObjectT<{
|
|
51
|
+
supportsLongCacheRetention: z<boolean, boolean>;
|
|
52
|
+
supportsExplicitPromptCacheMode: z<boolean, boolean>;
|
|
53
|
+
alphaCapabilityPath: z<string, string>;
|
|
54
|
+
alphaRefPath: z<string, string>;
|
|
55
|
+
alphaProfile: z<string, string>;
|
|
56
|
+
alphaGroup: z<string, string>;
|
|
57
|
+
alphaMaxOutputTokens: z<number, number>;
|
|
58
|
+
webSearchProvider: z<string, string>;
|
|
59
|
+
webMaxResults: z<number, number>;
|
|
60
|
+
timeoutMs: z<number, number>;
|
|
61
|
+
maxResponseBytes: z<number, number>;
|
|
62
|
+
maxAttempts: z<number, number>;
|
|
63
|
+
maxRequestImageBytes: z<number, number>;
|
|
64
|
+
requestImagePixelBudget: z<number, number>;
|
|
65
|
+
requestImageMaxBytes: z<number, number>;
|
|
66
|
+
portableReplayMaxChars: z<number, number>;
|
|
67
|
+
nativeRetentionTokenBudget: z<number, number>;
|
|
68
|
+
assistantRetentionTokenReserve: z<number, number>;
|
|
69
|
+
assistantRetentionPerMessageTokenCap: z<number, number>;
|
|
70
|
+
}>>;
|
|
71
|
+
export declare function compactionPressureBand(totalTokens: number, contextWindow: number, policy: {
|
|
72
|
+
auto: number;
|
|
73
|
+
emergency: number;
|
|
74
|
+
}): {
|
|
75
|
+
ratioPercent: number;
|
|
76
|
+
band: string;
|
|
77
|
+
};
|
|
78
|
+
export declare function apply(ctx: HostContext, configInput?: ConfigInput): void;
|
|
79
|
+
export declare namespace apply {
|
|
80
|
+
export { inject };
|
|
81
|
+
export { Config };
|
|
82
|
+
}
|
|
83
|
+
export default apply;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class JsonStore<T> {
|
|
2
|
+
readonly file: string;
|
|
3
|
+
readonly empty: () => T;
|
|
4
|
+
readonly validate: (data: unknown) => data is T;
|
|
5
|
+
readonly corruptCode: string;
|
|
6
|
+
data: T;
|
|
7
|
+
constructor(file: string, empty: () => T, validate: (data: unknown) => data is T, corruptCode?: string);
|
|
8
|
+
refresh(): void;
|
|
9
|
+
update(mutator: (current: T) => T): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { ResponseInputItem } from "openai/resources/responses/responses.js";
|
|
2
|
+
import { Session, type SessionEvent } from "@deepseek-ai/dsh-session";
|
|
3
|
+
import { requestImageHandleText, type Message, type StreamChunk, type TokenUsage } from "@deepseek-ai/dsh-llm";
|
|
4
|
+
type CompactionItem = {
|
|
5
|
+
type: "compaction";
|
|
6
|
+
encrypted_content: string;
|
|
7
|
+
};
|
|
8
|
+
export type NativeOutputItem = ResponseInputItem;
|
|
9
|
+
type RouteIdentity = {
|
|
10
|
+
provider: string;
|
|
11
|
+
model: string;
|
|
12
|
+
baseURL: string;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
};
|
|
15
|
+
type CompactionSummaryEvent = SessionEvent<"compaction/summary">;
|
|
16
|
+
type RetentionOptions = {
|
|
17
|
+
tokenBudget?: number;
|
|
18
|
+
assistantTokenReserve?: number;
|
|
19
|
+
assistantPerMessageTokenCap?: number;
|
|
20
|
+
};
|
|
21
|
+
type RetentionPlan = {
|
|
22
|
+
items: unknown[];
|
|
23
|
+
clientCount: number;
|
|
24
|
+
assistantCount: number;
|
|
25
|
+
estimatedTokens: number;
|
|
26
|
+
clientEstimatedTokens: number;
|
|
27
|
+
assistantEstimatedTokens: number;
|
|
28
|
+
};
|
|
29
|
+
type NativeCheckpointBase = {
|
|
30
|
+
compactionId: string;
|
|
31
|
+
provider: string;
|
|
32
|
+
model: string;
|
|
33
|
+
baseURLFingerprint: string;
|
|
34
|
+
sourceSessionId: string;
|
|
35
|
+
nativeOutput: NativeOutputItem[];
|
|
36
|
+
nativeCompaction?: CompactionItem;
|
|
37
|
+
retainedInputCount?: number;
|
|
38
|
+
retainedClientCount?: number;
|
|
39
|
+
retainedAssistantCount?: number;
|
|
40
|
+
retainedEstimatedTokens?: number;
|
|
41
|
+
createdAt?: number;
|
|
42
|
+
};
|
|
43
|
+
export type NativeCheckpointV5 = NativeCheckpointBase & {
|
|
44
|
+
type: "lcx-native-compaction-v5";
|
|
45
|
+
version: 5;
|
|
46
|
+
retentionPolicy?: "conversation-fidelity-v1";
|
|
47
|
+
};
|
|
48
|
+
export type NativeCheckpointBlock = NativeCheckpointV5;
|
|
49
|
+
declare module "@deepseek-ai/dsh-llm" {
|
|
50
|
+
interface ContentBlockMap {
|
|
51
|
+
"lcx-native-compaction-v5": NativeCheckpointV5;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
type NativeCompactionResult = {
|
|
55
|
+
compaction: CompactionItem;
|
|
56
|
+
};
|
|
57
|
+
type ImageAttachmentRef = Parameters<typeof requestImageHandleText>[0];
|
|
58
|
+
type CheckpointRouteRecord = {
|
|
59
|
+
version: number;
|
|
60
|
+
provider: unknown;
|
|
61
|
+
model: unknown;
|
|
62
|
+
baseURLFingerprint: unknown;
|
|
63
|
+
sourceSessionId: unknown;
|
|
64
|
+
};
|
|
65
|
+
type CreateCheckpointOptions = {
|
|
66
|
+
session: Session;
|
|
67
|
+
route: RouteIdentity;
|
|
68
|
+
result: NativeCompactionResult;
|
|
69
|
+
input?: unknown[];
|
|
70
|
+
ephemeralPreludeItemCount?: number;
|
|
71
|
+
imageMap?: ReadonlyMap<string, ImageAttachmentRef>;
|
|
72
|
+
retentionOptions?: RetentionOptions;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {object} NativeCheckpointBase
|
|
76
|
+
* @property {string} compactionId
|
|
77
|
+
* @property {string} provider
|
|
78
|
+
* @property {string} model
|
|
79
|
+
* @property {string} baseURLFingerprint
|
|
80
|
+
* @property {string} sourceSessionId
|
|
81
|
+
* @property {NativeOutputItem[]} nativeOutput
|
|
82
|
+
* @property {CompactionItem} [nativeCompaction]
|
|
83
|
+
* @property {number} [retainedInputCount]
|
|
84
|
+
* @property {number} [retainedClientCount]
|
|
85
|
+
* @property {number} [retainedAssistantCount]
|
|
86
|
+
* @property {number} [retainedEstimatedTokens]
|
|
87
|
+
* @property {number} [createdAt]
|
|
88
|
+
*/
|
|
89
|
+
/** @typedef {NativeCheckpointBase & { type: 'lcx-native-compaction-v5', version: 5, retentionPolicy?: 'conversation-fidelity-v1' }} NativeCheckpointV5 */
|
|
90
|
+
/** @typedef {NativeCheckpointV5} NativeCheckpointBlock */
|
|
91
|
+
/**
|
|
92
|
+
* Minimal validated candidate shape. DSH rawOutput is unknown until the existing
|
|
93
|
+
* version, field, count, and compaction validation below has completed.
|
|
94
|
+
* @typedef {object} NativeCheckpointCandidate
|
|
95
|
+
* @property {typeof NATIVE_BLOCK_TYPE} type
|
|
96
|
+
* @property {typeof NATIVE_BLOCK_VERSION} version
|
|
97
|
+
* @property {unknown} [compactionId]
|
|
98
|
+
* @property {unknown} [nativeOutput]
|
|
99
|
+
* @property {unknown} [provider]
|
|
100
|
+
* @property {unknown} [model]
|
|
101
|
+
* @property {unknown} [baseURLFingerprint]
|
|
102
|
+
* @property {unknown} [sourceSessionId]
|
|
103
|
+
* @property {unknown} [retainedInputCount]
|
|
104
|
+
* @property {unknown} [retainedClientCount]
|
|
105
|
+
* @property {unknown} [retainedAssistantCount]
|
|
106
|
+
*/
|
|
107
|
+
/** @typedef {{ compaction: CompactionItem }} NativeCompactionResult */
|
|
108
|
+
/** @typedef {{ session: Session, route: RouteIdentity, result: NativeCompactionResult, input?: unknown[], ephemeralPreludeItemCount?: number, imageMap?: unknown, retentionOptions?: RetentionOptions }} CreateCheckpointOptions */
|
|
109
|
+
/** @typedef {Error & { code?: string }} LcxError */
|
|
110
|
+
export declare const NATIVE_BLOCK_TYPE = "lcx-native-compaction-v5";
|
|
111
|
+
export declare const NATIVE_BLOCK_VERSION = 5;
|
|
112
|
+
export declare const RETAINED_MESSAGE_TOKEN_BUDGET = 64000;
|
|
113
|
+
export declare const ASSISTANT_RETENTION_TOKEN_RESERVE = 24000;
|
|
114
|
+
export declare const ASSISTANT_RETENTION_PER_MESSAGE_TOKEN_CAP = 3000;
|
|
115
|
+
/**
|
|
116
|
+
* @param {unknown[] | null | undefined} input
|
|
117
|
+
* @param {RetentionOptions} [options]
|
|
118
|
+
* @returns {unknown[]}
|
|
119
|
+
*/
|
|
120
|
+
export declare function retainedCompactionInput(input: readonly unknown[] | null | undefined, options?: RetentionOptions): unknown[];
|
|
121
|
+
/**
|
|
122
|
+
* @param {unknown[] | null | undefined} input
|
|
123
|
+
* @param {RetentionOptions} [options]
|
|
124
|
+
* @returns {RetentionPlan}
|
|
125
|
+
*/
|
|
126
|
+
export declare function retainedConversationPlan(input: readonly unknown[] | null | undefined, options?: RetentionOptions): RetentionPlan;
|
|
127
|
+
/**
|
|
128
|
+
* @param {unknown[] | null | undefined} input
|
|
129
|
+
* @param {RetentionOptions} [options]
|
|
130
|
+
*/
|
|
131
|
+
export declare function retainedConversationInput<T>(input: readonly T[] | null | undefined, options?: RetentionOptions): T[];
|
|
132
|
+
/** @param {unknown[] | null | undefined} items */
|
|
133
|
+
export declare function hasRetainedCompactionInput(items: readonly unknown[] | null | undefined): boolean;
|
|
134
|
+
export declare function compactCheckpointId(message: Message | null | undefined): string | undefined;
|
|
135
|
+
/** Reject reserved checkpoint markers without interpreting unsupported formats or opening sidecars. */
|
|
136
|
+
export declare function assertSupportedCheckpointMessage(message: Message): void;
|
|
137
|
+
/** @param {Session | null | undefined} session */
|
|
138
|
+
export declare function activeCompactionId(session: Session | null | undefined): string | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* @param {CreateCheckpointOptions} options
|
|
141
|
+
* @returns {NativeCheckpointV5}
|
|
142
|
+
*/
|
|
143
|
+
export declare function createNativeCheckpointBlock({ session, route, result, input, ephemeralPreludeItemCount, imageMap, retentionOptions, }: CreateCheckpointOptions): NativeCheckpointV5;
|
|
144
|
+
/**
|
|
145
|
+
* @param {NativeCheckpointBlock} block
|
|
146
|
+
* @param {unknown} usage
|
|
147
|
+
* @returns {UnknownRecord[]}
|
|
148
|
+
*/
|
|
149
|
+
export declare function nativeCheckpointChunks(block: NativeCheckpointBlock, usage: TokenUsage | undefined): StreamChunk[];
|
|
150
|
+
/**
|
|
151
|
+
* @param {Session | null | undefined} session
|
|
152
|
+
* @param {string | null | undefined} compactionId
|
|
153
|
+
* @returns {CompactionSummaryEvent | undefined}
|
|
154
|
+
*/
|
|
155
|
+
export declare function compactionSummaryEvent(session: Session | null | undefined, compactionId: string | null | undefined): CompactionSummaryEvent | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* @param {CompactionSummaryEvent | null | undefined} event
|
|
158
|
+
* @returns {NativeCheckpointBlock | undefined}
|
|
159
|
+
*/
|
|
160
|
+
export declare function stateFromSummaryEvent(event: CompactionSummaryEvent | null | undefined): {
|
|
161
|
+
compactionId: string;
|
|
162
|
+
provider: string;
|
|
163
|
+
model: string;
|
|
164
|
+
baseURLFingerprint: string;
|
|
165
|
+
sourceSessionId: string;
|
|
166
|
+
nativeOutput: NativeOutputItem[];
|
|
167
|
+
nativeCompaction: CompactionItem;
|
|
168
|
+
retainedInputCount?: number | undefined;
|
|
169
|
+
retainedClientCount?: number | undefined;
|
|
170
|
+
retainedAssistantCount?: number | undefined;
|
|
171
|
+
type: string;
|
|
172
|
+
version: number;
|
|
173
|
+
} | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* @param {Session} session
|
|
176
|
+
* @param {Message} message
|
|
177
|
+
*/
|
|
178
|
+
export declare function checkpointStateForMessage(session: Session, message: Message): {
|
|
179
|
+
compactionId: string;
|
|
180
|
+
provider: string;
|
|
181
|
+
model: string;
|
|
182
|
+
baseURLFingerprint: string;
|
|
183
|
+
sourceSessionId: string;
|
|
184
|
+
nativeOutput: NativeOutputItem[];
|
|
185
|
+
nativeCompaction: CompactionItem;
|
|
186
|
+
retainedInputCount?: number | undefined;
|
|
187
|
+
retainedClientCount?: number | undefined;
|
|
188
|
+
retainedAssistantCount?: number | undefined;
|
|
189
|
+
type: string;
|
|
190
|
+
version: number;
|
|
191
|
+
} | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* @param {NativeCheckpointBlock} state
|
|
194
|
+
* @param {RouteIdentity} route
|
|
195
|
+
* @param {unknown} ctx
|
|
196
|
+
*/
|
|
197
|
+
export declare function stateRouteCompatible(state: CheckpointRouteRecord | null | undefined, route: RouteIdentity, ctx: unknown): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* @param {Session} session
|
|
200
|
+
* @param {string} compactionId
|
|
201
|
+
* @returns {Message[]}
|
|
202
|
+
*/
|
|
203
|
+
export declare function shadowedMessagesForCheckpoint(session: Session, compactionId: string): Message[];
|
|
204
|
+
/**
|
|
205
|
+
* @param {Session} session
|
|
206
|
+
* @param {string} compactionId
|
|
207
|
+
* @param {{ maxChars?: number }} [options]
|
|
208
|
+
* @returns {Message[]}
|
|
209
|
+
*/
|
|
210
|
+
export declare function portableMessagesForCheckpoint(session: Session, compactionId: string, options?: {
|
|
211
|
+
maxChars?: number;
|
|
212
|
+
}): Message[];
|
|
213
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** @typedef {'none' | 'short' | 'long'} CacheRetention */
|
|
2
|
+
type UnknownRecord = Record<string, unknown>;
|
|
3
|
+
type CacheRetention = "none" | "short" | "long";
|
|
4
|
+
type ResponsesCompat = {
|
|
5
|
+
supportsLongCacheRetention?: boolean;
|
|
6
|
+
supportsExplicitPromptCacheMode?: boolean;
|
|
7
|
+
supportsMaxOutputTokens?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type PiResponsesModel = {
|
|
10
|
+
id: string;
|
|
11
|
+
provider: string;
|
|
12
|
+
reasoning?: boolean;
|
|
13
|
+
thinkingLevelMap?: Record<string, string | null>;
|
|
14
|
+
compat?: ResponsesCompat;
|
|
15
|
+
};
|
|
16
|
+
type GenerationControls = {
|
|
17
|
+
reasoningEffort?: unknown;
|
|
18
|
+
temperature?: unknown;
|
|
19
|
+
maxTokens?: unknown;
|
|
20
|
+
};
|
|
21
|
+
type BuildResponsesBodyOptions = GenerationControls & {
|
|
22
|
+
model: PiResponsesModel | string;
|
|
23
|
+
input: unknown[];
|
|
24
|
+
tools?: unknown;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
promptCacheKey?: string;
|
|
27
|
+
promptCacheRetention?: string;
|
|
28
|
+
cacheRetention?: CacheRetention;
|
|
29
|
+
samplingParams?: UnknownRecord;
|
|
30
|
+
};
|
|
31
|
+
type ResponsesWireBody = UnknownRecord & {
|
|
32
|
+
model: string;
|
|
33
|
+
input: unknown[];
|
|
34
|
+
stream: boolean;
|
|
35
|
+
store: boolean;
|
|
36
|
+
tool_choice?: string;
|
|
37
|
+
parallel_tool_calls?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Pi-parity generation controls for OpenAI Responses.
|
|
41
|
+
* @param {GenerationControls & { model?: PiResponsesModel | string, includeDefaultReasoning?: boolean }} [controls]
|
|
42
|
+
*/
|
|
43
|
+
export declare function responsesGenerationEnvelope({ model, reasoningEffort, temperature, maxTokens, includeDefaultReasoning, }?: GenerationControls & {
|
|
44
|
+
model?: PiResponsesModel | string;
|
|
45
|
+
includeDefaultReasoning?: boolean;
|
|
46
|
+
}): UnknownRecord;
|
|
47
|
+
/**
|
|
48
|
+
* Build the shared LCX-owned request envelope while retaining Pi 0.85.1 Responses semantics.
|
|
49
|
+
* Production LCX ordinary/compact/replay construction places the DSH system prompt in canonical input.
|
|
50
|
+
* @param {BuildResponsesBodyOptions} options
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildResponsesBody({ model, input, tools, sessionId, promptCacheKey, promptCacheRetention, cacheRetention, reasoningEffort, temperature, maxTokens, samplingParams, }: BuildResponsesBodyOptions): ResponsesWireBody;
|
|
53
|
+
/**
|
|
54
|
+
* Compact is the standard request plus the one opaque-history transition patch.
|
|
55
|
+
* @param {BuildResponsesBodyOptions} options
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildCompactionResponsesBody(options: BuildResponsesBodyOptions): ResponsesWireBody;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Model as PiModel } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { StreamChunk } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
type UnknownRecord = Record<string, unknown>;
|
|
4
|
+
type PiResponsesModel = PiModel<"openai-responses">;
|
|
5
|
+
type ManagedFailure = {
|
|
6
|
+
message: string;
|
|
7
|
+
code: string;
|
|
8
|
+
status?: number;
|
|
9
|
+
requestId?: string;
|
|
10
|
+
providerRetryAfterMs?: number;
|
|
11
|
+
};
|
|
12
|
+
type AbortLike = Pick<AbortSignal, "aborted" | "reason">;
|
|
13
|
+
type StreamRequestOptions = {
|
|
14
|
+
baseURL: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
model: string;
|
|
17
|
+
piModel: PiResponsesModel;
|
|
18
|
+
body: UnknownRecord;
|
|
19
|
+
grammarToolInputProperties?: ReadonlyMap<string, string>;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
maxResponseBytes?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Provider bodies/messages are deliberately not surfaced. Only a stable class and safe facts leave the wire boundary.
|
|
28
|
+
* @param {unknown} error
|
|
29
|
+
* @param {AbortSignal} [signal]
|
|
30
|
+
*/
|
|
31
|
+
export declare function managedFailure(error: unknown, signal: AbortLike | undefined): ManagedFailure;
|
|
32
|
+
/** @param {unknown} error @param {AbortSignal} [signal] */
|
|
33
|
+
export declare function managedFailureChunk(error: unknown, signal?: AbortLike): StreamChunk;
|
|
34
|
+
/**
|
|
35
|
+
* Send one LCX-owned OpenAI Responses request. Ordinary and replay use one provider attempt;
|
|
36
|
+
* the DSH agent recovery layer remains the visible retry owner.
|
|
37
|
+
* @param {object} options
|
|
38
|
+
* @param {string} options.baseURL
|
|
39
|
+
* @param {string} options.provider
|
|
40
|
+
* @param {string} options.model
|
|
41
|
+
* @param {UnknownRecord} options.piModel
|
|
42
|
+
* @param {UnknownRecord} options.body
|
|
43
|
+
* @param {Map<string, string>} [options.grammarToolInputProperties]
|
|
44
|
+
* @param {Record<string, string>} [options.headers]
|
|
45
|
+
* @param {AbortSignal} [options.signal]
|
|
46
|
+
* @param {number} [options.timeoutMs]
|
|
47
|
+
* @param {number} [options.maxAttempts]
|
|
48
|
+
* @param {number} [options.maxResponseBytes]
|
|
49
|
+
*/
|
|
50
|
+
export declare function streamResponsesRequest({ baseURL, provider, model, piModel, body, grammarToolInputProperties, headers, signal, timeoutMs, maxAttempts, maxResponseBytes, }: StreamRequestOptions): AsyncGenerator<StreamChunk, void, any>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import { type Session } from "@deepseek-ai/dsh-session";
|
|
3
|
+
import "@deepseek-ai/dsh-settings";
|
|
4
|
+
import { resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
type HeaderMap = Record<string, string>;
|
|
6
|
+
type RetryPolicyConfig = Parameters<typeof resolveRetryPolicy>[0];
|
|
7
|
+
type CacheRetention = "none" | "short" | "long";
|
|
8
|
+
type ResponsesCompat = {
|
|
9
|
+
supportsDeveloperRole?: boolean;
|
|
10
|
+
sessionAffinityFormat?: "openai" | "openai-nosession" | "openrouter";
|
|
11
|
+
supportsStrictMode?: boolean;
|
|
12
|
+
supportsLongCacheRetention?: boolean;
|
|
13
|
+
supportsOpenAIGrammarTools?: boolean;
|
|
14
|
+
supportsAdditionalTools?: boolean;
|
|
15
|
+
supportsToolSearch?: boolean;
|
|
16
|
+
supportsExplicitPromptCacheMode?: boolean;
|
|
17
|
+
supportsMaxOutputTokens?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type RouteIdentity = {
|
|
20
|
+
provider: string;
|
|
21
|
+
model: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
sessionId: string;
|
|
24
|
+
};
|
|
25
|
+
type RouteOptions = {
|
|
26
|
+
provider?: unknown;
|
|
27
|
+
model?: unknown;
|
|
28
|
+
sessionId?: unknown;
|
|
29
|
+
};
|
|
30
|
+
type ProviderModelProfile = {
|
|
31
|
+
id?: unknown;
|
|
32
|
+
compat?: unknown;
|
|
33
|
+
};
|
|
34
|
+
type ProviderProfile = {
|
|
35
|
+
api?: string;
|
|
36
|
+
baseURL?: string;
|
|
37
|
+
apiKeyEnv?: string;
|
|
38
|
+
headers?: HeaderMap;
|
|
39
|
+
cacheRetention?: unknown;
|
|
40
|
+
timeoutMs?: unknown;
|
|
41
|
+
maxRequestImageBytes?: unknown;
|
|
42
|
+
requestImagePixelBudget?: unknown;
|
|
43
|
+
requestImageMaxBytes?: unknown;
|
|
44
|
+
retryPolicy?: RetryPolicyConfig;
|
|
45
|
+
compat?: unknown;
|
|
46
|
+
models?: ProviderModelProfile[];
|
|
47
|
+
modelOverrides?: Record<string, ProviderModelProfile>;
|
|
48
|
+
};
|
|
49
|
+
type LlmSettingsSection = {
|
|
50
|
+
providers?: Record<string, ProviderProfile>;
|
|
51
|
+
};
|
|
52
|
+
type RequestHeaderConfig = {
|
|
53
|
+
provider?: unknown;
|
|
54
|
+
model?: unknown;
|
|
55
|
+
reasoningEffort?: unknown;
|
|
56
|
+
temperature?: unknown;
|
|
57
|
+
maxTokens?: unknown;
|
|
58
|
+
};
|
|
59
|
+
type RequestHeader = {
|
|
60
|
+
config?: RequestHeaderConfig;
|
|
61
|
+
};
|
|
62
|
+
type RouteSession = Pick<Session, "requestHeader">;
|
|
63
|
+
export type RouteContext = Pick<Context, "credentials" | "logger" | "sessions" | "settings">;
|
|
64
|
+
type RoutePolicy = {
|
|
65
|
+
cacheRetention?: unknown;
|
|
66
|
+
supportsLongCacheRetention?: unknown;
|
|
67
|
+
supportsExplicitPromptCacheMode?: unknown;
|
|
68
|
+
responsesCompat?: unknown;
|
|
69
|
+
timeoutMs?: number;
|
|
70
|
+
maxAttempts?: number;
|
|
71
|
+
maxRequestImageBytes?: number;
|
|
72
|
+
requestImagePixelBudget?: number;
|
|
73
|
+
requestImageMaxBytes?: number;
|
|
74
|
+
};
|
|
75
|
+
type UnresolvedRouteConfig = RoutePolicy & {
|
|
76
|
+
provider: string;
|
|
77
|
+
model: string;
|
|
78
|
+
baseURL: string;
|
|
79
|
+
apiKeyEnv: string;
|
|
80
|
+
headers?: HeaderMap;
|
|
81
|
+
};
|
|
82
|
+
export type ResolvedResponsesRoute = UnresolvedRouteConfig & {
|
|
83
|
+
api: "openai-responses";
|
|
84
|
+
cacheRetention: CacheRetention;
|
|
85
|
+
supportsLongCacheRetention: boolean;
|
|
86
|
+
responsesCompat?: ResponsesCompat;
|
|
87
|
+
};
|
|
88
|
+
type GenerationControls = {
|
|
89
|
+
reasoningEffort?: unknown;
|
|
90
|
+
temperature?: unknown;
|
|
91
|
+
maxTokens?: unknown;
|
|
92
|
+
};
|
|
93
|
+
type CheckpointRouteRecord = {
|
|
94
|
+
version: number;
|
|
95
|
+
provider: unknown;
|
|
96
|
+
model: unknown;
|
|
97
|
+
baseURLFingerprint: unknown;
|
|
98
|
+
sourceSessionId: unknown;
|
|
99
|
+
};
|
|
100
|
+
/** @param {unknown} value */
|
|
101
|
+
export declare function normalizeBaseURL(value: unknown): string;
|
|
102
|
+
/** @param {unknown} baseURL */
|
|
103
|
+
export declare function baseURLFingerprint(baseURL: unknown): string;
|
|
104
|
+
/** @param {Partial<RouteIdentity> | null | undefined} route @param {{ includeSession?: boolean }} [options] */
|
|
105
|
+
export declare function routeFingerprint(route: Partial<RouteIdentity> | null | undefined, options?: {
|
|
106
|
+
includeSession?: boolean;
|
|
107
|
+
}): string;
|
|
108
|
+
/** @param {Partial<RouteIdentity> | null | undefined} route @param {Partial<Pick<ResolvedResponsesRoute, 'cacheRetention'>>} [config] @param {RouteContext | null | undefined} [ctx] */
|
|
109
|
+
export declare function promptCacheSessionId(route: Partial<RouteIdentity> | null | undefined, config?: Partial<Pick<ResolvedResponsesRoute, "cacheRetention">>, ctx?: RouteContext | null | undefined): string | undefined;
|
|
110
|
+
/** @param {Partial<RouteIdentity> | null | undefined} route @param {Partial<Pick<ResolvedResponsesRoute, 'cacheRetention'>>} [config] @param {RouteContext | null | undefined} [ctx] */
|
|
111
|
+
export declare function promptCacheKey(route: Partial<RouteIdentity> | null | undefined, config?: Partial<Pick<ResolvedResponsesRoute, "cacheRetention">>, ctx?: RouteContext | null | undefined): string | undefined;
|
|
112
|
+
/** @param {Partial<Pick<ResolvedResponsesRoute, 'cacheRetention' | 'supportsLongCacheRetention' | 'responsesCompat'>>} [config] */
|
|
113
|
+
export declare function promptCacheRetention(config?: Partial<Pick<ResolvedResponsesRoute, "cacheRetention" | "supportsLongCacheRetention" | "responsesCompat">>): "24h" | undefined;
|
|
114
|
+
/** @param {RouteContext | null | undefined} ctx @param {string} namespace */
|
|
115
|
+
export declare function settingsValue(ctx: RouteContext | null | undefined, namespace: string): LlmSettingsSection | undefined;
|
|
116
|
+
/** Resolve only the selected DSH profile; policy cannot supply route identity or credentials. */
|
|
117
|
+
export declare function resolveResponsesRouteConfig(ctx: RouteContext | null | undefined, options: RouteOptions & {
|
|
118
|
+
purpose?: string;
|
|
119
|
+
}, policy: RoutePolicy): ResolvedResponsesRoute | undefined;
|
|
120
|
+
/** @param {RouteContext | null | undefined} ctx @param {Pick<ResolvedResponsesRoute, 'apiKeyEnv'>} config */
|
|
121
|
+
export declare function resolveApiKey(ctx: RouteContext | null | undefined, config: Pick<ResolvedResponsesRoute, "apiKeyEnv">): Promise<string>;
|
|
122
|
+
/** @param {RouteContext | null | undefined} ctx @param {ResolvedResponsesRoute} config @param {unknown} sessionId @param {string | null | undefined} requestId @returns {Promise<HeaderMap>} */
|
|
123
|
+
export declare function authenticatedHeaders(ctx: RouteContext | null | undefined, config: ResolvedResponsesRoute, sessionId: unknown, requestId: string | null | undefined): Promise<HeaderMap>;
|
|
124
|
+
/** @param {RouteOptions | null | undefined} options @param {Pick<UnresolvedRouteConfig, 'provider' | 'model' | 'baseURL'>} config @returns {RouteIdentity} */
|
|
125
|
+
export declare function currentRoute(options: RouteOptions | null | undefined, config: Pick<UnresolvedRouteConfig, "provider" | "model" | "baseURL">): RouteIdentity;
|
|
126
|
+
/** @param {RequestHeader | null | undefined} header @param {Partial<RouteIdentity> | null | undefined} route @returns {GenerationControls} */
|
|
127
|
+
export declare function generationControlsFromHeader(header: RequestHeader | null | undefined, route: Partial<RouteIdentity> | null | undefined): GenerationControls;
|
|
128
|
+
/** @param {RouteSession | null | undefined} session @param {Partial<RouteIdentity> | null | undefined} route @returns {GenerationControls} */
|
|
129
|
+
export declare function generationControlsFromSession(session: RouteSession | null | undefined, route: Partial<RouteIdentity> | null | undefined): GenerationControls;
|
|
130
|
+
/** @param {CheckpointRouteRecord | null | undefined} record @param {RouteIdentity} route @param {unknown} ctx */
|
|
131
|
+
export declare function routeCompatible(record: CheckpointRouteRecord | null | undefined, route: RouteIdentity, ctx: unknown): boolean;
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Release = () => void;
|
|
2
|
+
export declare class ServiceMutex {
|
|
3
|
+
private locked;
|
|
4
|
+
private closed;
|
|
5
|
+
private closeReason?;
|
|
6
|
+
private readonly queue;
|
|
7
|
+
private readonly idleWaiters;
|
|
8
|
+
constructor();
|
|
9
|
+
acquire(signal?: AbortSignal): Promise<Release>;
|
|
10
|
+
release(): void;
|
|
11
|
+
run<T>(signal: AbortSignal | undefined, task: () => T | Promise<T>): Promise<T>;
|
|
12
|
+
close(reason?: Error): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const PORTABLE_BUDGET_ERROR_CODE = "LCX_PORTABLE_BUDGET_EXCEEDED";
|
|
2
|
+
/**
|
|
3
|
+
* A small conservative fallback, deliberately not a tokenizer. The baseline
|
|
4
|
+
* preserves legacy /4 while CJK and structural characters cost more.
|
|
5
|
+
* @param {unknown} value
|
|
6
|
+
* @returns {number | undefined}
|
|
7
|
+
*/
|
|
8
|
+
export declare function estimateTextTokens(value: unknown): number | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Project an item to model-visible fields only. Opaque provider state, raw
|
|
11
|
+
* binary, and replay/session metadata are intentionally excluded.
|
|
12
|
+
* @param {unknown} item
|
|
13
|
+
* @returns {unknown | undefined}
|
|
14
|
+
*/
|
|
15
|
+
export declare function modelVisibleBudgetView(item: unknown): {
|
|
16
|
+
type: string;
|
|
17
|
+
call_id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
arguments: string;
|
|
20
|
+
output?: undefined;
|
|
21
|
+
role?: undefined;
|
|
22
|
+
content?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
name?: undefined;
|
|
25
|
+
arguments?: undefined;
|
|
26
|
+
type: string;
|
|
27
|
+
call_id: string;
|
|
28
|
+
output: string;
|
|
29
|
+
role?: undefined;
|
|
30
|
+
content?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
name?: undefined;
|
|
33
|
+
arguments?: undefined;
|
|
34
|
+
type?: undefined;
|
|
35
|
+
call_id?: undefined;
|
|
36
|
+
output?: undefined;
|
|
37
|
+
role: string;
|
|
38
|
+
content: unknown[];
|
|
39
|
+
} | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* @param {unknown} item
|
|
42
|
+
* @returns {number | undefined}
|
|
43
|
+
*/
|
|
44
|
+
export declare function estimateBudgetItem(item: unknown): number | undefined;
|
|
45
|
+
/** @param {unknown} maxChars */
|
|
46
|
+
export declare function portableTokenCeiling(maxChars: unknown): number | undefined;
|
|
47
|
+
/** @param {string} message */
|
|
48
|
+
export declare function portableBudgetError(message: string): Error & {
|
|
49
|
+
code: string;
|
|
50
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type AbortLike = Pick<AbortSignal, "aborted" | "reason" | "addEventListener">;
|
|
2
|
+
type RetryOptions = {
|
|
3
|
+
maxAttempts?: number;
|
|
4
|
+
maxResponseBytes?: number;
|
|
5
|
+
};
|
|
6
|
+
type SseRetryOptions<T = Response> = RetryOptions & {
|
|
7
|
+
consume?: (response: Response, options: {
|
|
8
|
+
requestSignal?: AbortSignal;
|
|
9
|
+
}) => Promise<T>;
|
|
10
|
+
};
|
|
11
|
+
type JsonRequestBody = Record<string, unknown>;
|
|
12
|
+
type SseRequestBody = Record<string, unknown>;
|
|
13
|
+
export declare function abortIfNeeded(signal: AbortLike | undefined): void;
|
|
14
|
+
export declare function fetchJsonWithRetry(url: string | URL | Request, body: JsonRequestBody, headers: HeadersInit | undefined, signal: AbortSignal | undefined, timeoutMs?: number | undefined, options?: RetryOptions): Promise<any>;
|
|
15
|
+
export declare function fetchSseWithRetry<T = Response>(url: string | URL | Request, body: SseRequestBody, headers: HeadersInit | undefined, signal: AbortSignal | undefined, timeoutMs?: number | undefined, options?: SseRetryOptions<T>): Promise<T>;
|
|
16
|
+
export declare function consumeSse(response: Response, onEvent: (event: unknown) => void, options?: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
maxResponseBytes?: number;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface WebRunLink {
|
|
2
|
+
id: number;
|
|
3
|
+
label: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface WebRunLine {
|
|
7
|
+
text: string;
|
|
8
|
+
heading?: number;
|
|
9
|
+
line?: number;
|
|
10
|
+
page?: number;
|
|
11
|
+
pageEnd?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface WebRunBlock {
|
|
14
|
+
title?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
references: string[];
|
|
17
|
+
links: WebRunLink[];
|
|
18
|
+
metadata: string[];
|
|
19
|
+
lines: WebRunLine[];
|
|
20
|
+
}
|
|
21
|
+
export declare function parseWebRunOutput(output: string): WebRunBlock[];
|
|
22
|
+
export declare function outputLineRange(blocks: WebRunBlock[]): {
|
|
23
|
+
first: number;
|
|
24
|
+
last: number;
|
|
25
|
+
} | undefined;
|
|
26
|
+
export declare function outputDomains(blocks: WebRunBlock[]): string[];
|
|
27
|
+
export declare function outputLinks(blocks: WebRunBlock[]): WebRunLink[];
|
|
28
|
+
export declare function outputPdfRefs(blocks: WebRunBlock[]): string[];
|
|
29
|
+
export declare function blockPlainText(block: Pick<WebRunBlock, "lines">): string;
|