@toddzheng024/dscode-bundle 0.1.0

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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/THIRD_PARTY_NOTICES.md +11 -0
  4. package/bin/apply_patch +4 -0
  5. package/bootstrap.mjs +21 -0
  6. package/cordis.patch.yml +756 -0
  7. package/package.json +327 -0
  8. package/plugins/auto-review/audit.mjs +20 -0
  9. package/plugins/auto-review/index.mjs +181 -0
  10. package/plugins/auto-review/policy.mjs +59 -0
  11. package/plugins/dscode/index.mjs +35 -0
  12. package/plugins/session-metrics/index.mjs +44 -0
  13. package/plugins/session-metrics/pricing.mjs +18 -0
  14. package/plugins/session-metrics/store.mjs +24 -0
  15. package/plugins/session-metrics/view.mjs +58 -0
  16. package/plugins/tui-tools/hooks.mjs +23 -0
  17. package/plugins/tui-tools/index.mjs +164 -0
  18. package/plugins/ultra/policy.mjs +11 -0
  19. package/presets/dscode/agent.cordis.yml +288 -0
  20. package/presets/dscode/preset.yml +3 -0
  21. package/vendor/bash/LICENSE +21 -0
  22. package/vendor/bash/index.js +449 -0
  23. package/vendor/bash/types/background.d.ts +19 -0
  24. package/vendor/bash/types/index.d.ts +22 -0
  25. package/vendor/bash/types/render.d.ts +38 -0
  26. package/vendor/deepseek/LICENSE +21 -0
  27. package/vendor/deepseek/index.js +2102 -0
  28. package/vendor/deepseek/types/adapter.d.ts +163 -0
  29. package/vendor/deepseek/types/file-id.d.ts +19 -0
  30. package/vendor/deepseek/types/file-store.d.ts +83 -0
  31. package/vendor/deepseek/types/files-api.d.ts +103 -0
  32. package/vendor/deepseek/types/image-tokens.d.ts +19 -0
  33. package/vendor/deepseek/types/index.d.ts +106 -0
  34. package/vendor/deepseek/types/request-pricing.d.ts +48 -0
  35. package/vendor/deepseek/types/serialize.d.ts +85 -0
  36. package/vendor/deepseek/types/sse.d.ts +24 -0
  37. package/vendor/deepseek/types/translate.d.ts +37 -0
  38. package/vendor/deepseek/types/types.d.ts +178 -0
  39. package/vendor/deepseek/types/upload-index.d.ts +68 -0
  40. package/vendor/persistent/LICENSE +21 -0
  41. package/vendor/persistent/index.js +386 -0
  42. package/vendor/persistent/types/index.d.ts +24 -0
  43. package/vendor/tui/LICENSE +21 -0
  44. package/vendor/tui/devtools-CdTl3MNy.mjs +3643 -0
  45. package/vendor/tui/index.mjs +39105 -0
  46. package/vendor/tui/invariant.mjs +21 -0
  47. package/vendor/tui/rolldown-runtime-CMFfr-1z.mjs +26 -0
  48. package/vendor/tui/startup.mjs +109 -0
  49. package/vendor/tui/theme-DCT8Y2xf.mjs +628 -0
  50. package/vendor/tui/types/app.d.ts +304 -0
  51. package/vendor/tui/types/approval.d.ts +59 -0
  52. package/vendor/tui/types/attachments.d.ts +52 -0
  53. package/vendor/tui/types/authorization-panel.d.ts +22 -0
  54. package/vendor/tui/types/authorization.d.ts +36 -0
  55. package/vendor/tui/types/commands.d.ts +52 -0
  56. package/vendor/tui/types/editor-keys.d.ts +105 -0
  57. package/vendor/tui/types/editor.d.ts +6 -0
  58. package/vendor/tui/types/fork.d.ts +8 -0
  59. package/vendor/tui/types/git-workflow.d.ts +32 -0
  60. package/vendor/tui/types/history.d.ts +97 -0
  61. package/vendor/tui/types/index.d.ts +124 -0
  62. package/vendor/tui/types/input-split.d.ts +54 -0
  63. package/vendor/tui/types/internals.d.ts +26 -0
  64. package/vendor/tui/types/invariant.d.ts +15 -0
  65. package/vendor/tui/types/kernel-panels.d.ts +167 -0
  66. package/vendor/tui/types/keyboard.d.ts +80 -0
  67. package/vendor/tui/types/mentions.d.ts +81 -0
  68. package/vendor/tui/types/model-capabilities.d.ts +82 -0
  69. package/vendor/tui/types/models.d.ts +119 -0
  70. package/vendor/tui/types/permissions.d.ts +27 -0
  71. package/vendor/tui/types/plugin-inventory.d.ts +11 -0
  72. package/vendor/tui/types/presets.d.ts +22 -0
  73. package/vendor/tui/types/provider-settings.d.ts +239 -0
  74. package/vendor/tui/types/questions.d.ts +54 -0
  75. package/vendor/tui/types/render/animations.d.ts +265 -0
  76. package/vendor/tui/types/render/editor.d.ts +162 -0
  77. package/vendor/tui/types/render/export.d.ts +9 -0
  78. package/vendor/tui/types/render/fuzzy.d.ts +21 -0
  79. package/vendor/tui/types/render/inspector.d.ts +36 -0
  80. package/vendor/tui/types/render/lines.d.ts +66 -0
  81. package/vendor/tui/types/render/markdown.d.ts +29 -0
  82. package/vendor/tui/types/render/projection.d.ts +461 -0
  83. package/vendor/tui/types/render/status.d.ts +196 -0
  84. package/vendor/tui/types/render/text.d.ts +58 -0
  85. package/vendor/tui/types/render/tool-detail.d.ts +94 -0
  86. package/vendor/tui/types/render/tool-preview.d.ts +28 -0
  87. package/vendor/tui/types/render/width.d.ts +29 -0
  88. package/vendor/tui/types/session-directory.d.ts +173 -0
  89. package/vendor/tui/types/session-switch.d.ts +17 -0
  90. package/vendor/tui/types/settings-file.d.ts +41 -0
  91. package/vendor/tui/types/skills.d.ts +47 -0
  92. package/vendor/tui/types/startup.d.ts +65 -0
  93. package/vendor/tui/types/store.d.ts +58 -0
  94. package/vendor/tui/types/subagents.d.ts +70 -0
  95. package/vendor/tui/types/theme-panel.d.ts +24 -0
  96. package/vendor/tui/types/theme.d.ts +215 -0
  97. package/vendor/tui/types/version.d.ts +18 -0
  98. package/vendor/tui/types/whale-glyph.d.ts +6 -0
@@ -0,0 +1,163 @@
1
+ /**
2
+ * `DeepSeekAdapter`: fetch + SSE against a DeepSeek (OpenAI-compatible)
3
+ * chat-completions endpoint, emitting harness StreamChunks. The adapter is
4
+ * transport-only: connection facts arrive through a thunk resolved once per
5
+ * operation and the bearer token through a per-request resolver, so the
6
+ * registering plugin owns validation, layering, and credential policy.
7
+ *
8
+ * @module dsh-llm-deepseek/adapter
9
+ */
10
+ import { LlmAdapter } from '@deepseek-ai/dsh-llm';
11
+ import type { GenerateOptions, ImageAttachmentAccess, LlmModelInfo, LlmProviderInfo, PreparedAdapterCall, LlmResolvedModelInfo, ModelModality, ResolvedRetryPolicy, StreamChunk, SystemPromptUpdate } from '@deepseek-ai/dsh-llm';
12
+ import type { AttachmentStore, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
13
+ import type { CredentialRef } from '@deepseek-ai/dsh-credentials';
14
+ import type { AnonymousUserId } from '@deepseek-ai/dsh-anonymous-user-id';
15
+ import type { DeepSeekLlmApiExtensionRequest, PreparedDeepSeekLlmApiExtensions } from '@deepseek-ai/dsh-deepseek-llm-api-extensions';
16
+ import type { RequestDefaults } from './serialize.ts';
17
+ import { DeepSeekFileStore } from './file-store.ts';
18
+ import type { DeepSeekFilePolicy } from './file-store.ts';
19
+ import type { WireError } from './types.ts';
20
+ /** One optional model entry advertised by the direct-fetch adapter. */
21
+ export interface DeepSeekCatalogModel {
22
+ /** Wire model id accepted by the configured endpoint. */
23
+ id: string;
24
+ /** Selector label; defaults to {@link id}. */
25
+ name?: string;
26
+ /** Optional selector detail for deployments with similar model variants. */
27
+ description?: string;
28
+ /** Known combined request/response context capacity; omitted when deployment metadata is unavailable. */
29
+ contextWindow?: number;
30
+ /** Per-request output cap for this model; omission falls back to the profile's {@link DeepSeekConnectionOptions.maxTokens}. */
31
+ maxTokens?: number;
32
+ /** Accepted request modalities; omission is text-only. */
33
+ inputModalities?: ModelModality[];
34
+ /** Total-pixel budget for one deterministic request preview, or the 512-by-512 `low` preset. */
35
+ imagePixelBudget?: number | 'low';
36
+ /** Encoded-byte target for one deterministic request preview; the smallest quality-ladder output is used when no quality fits. */
37
+ imageMaxBytes?: number;
38
+ /**
39
+ * `'in-history'` declares that the endpoint reads the latest `system`
40
+ * message at any position of the conversation as the complete effective
41
+ * system prompt; omission means only a leading system message is read.
42
+ */
43
+ systemPromptUpdate?: SystemPromptUpdate;
44
+ }
45
+ /**
46
+ * Validated connection facts for one operation. The plugin's
47
+ * `resolveAdapterOptions` is the one explicit resolve step producing this
48
+ * shape; the adapter trusts it and re-reads it per operation, which is what
49
+ * makes a configuration change reach the next request without re-registration.
50
+ */
51
+ export interface DeepSeekConnectionOptions {
52
+ /** Endpoint base; `/chat/completions` is appended. */
53
+ baseURL: string;
54
+ /**
55
+ * Credential reference of this same resolution, resolved per request.
56
+ * Travelling with the endpoint is the point: a request can never pair one
57
+ * generation's URL with another generation's secret. Configuration carries
58
+ * only this name — a literal key is not a configuration value.
59
+ */
60
+ apiKeyEnv: CredentialRef;
61
+ /** Request defaults applied to every call (thinking mode, effort). */
62
+ defaults: RequestDefaults;
63
+ /** Default per-request output cap; explicit request values win. */
64
+ maxTokens: number;
65
+ /** Positive context capacity used when the selected model has no exact value. */
66
+ defaultContextWindow: number;
67
+ /** Advisory models exposed to discovery consumers; requests remain unrestricted. */
68
+ models: readonly DeepSeekCatalogModel[];
69
+ /** Maximum provider idle time while one stream read is outstanding. */
70
+ streamIdleTimeoutMs: number;
71
+ /** Maximum accumulated file-referenced image bytes in one request. */
72
+ maxRequestFilesBytes: number;
73
+ /** Maximum accumulated base64 image payload after Files API fallback. */
74
+ maxInlineRequestImageBytes: number;
75
+ /** Maximum number of represented images in one request. */
76
+ maxImagesPerRequest: number;
77
+ /** Raw-byte removal step after the file-reference bound is exceeded. */
78
+ imageOffloadByteQuantum: number;
79
+ /** Base64-byte removal step after the inline fallback bound is exceeded. */
80
+ inlineImageOffloadByteQuantum: number;
81
+ /** Image-count removal step after the count bound is exceeded. */
82
+ imageOffloadCountQuantum: number;
83
+ /** Maximum duration of one request-image Files API resolution. */
84
+ filesApiTimeoutMs: number;
85
+ /** Upload expiry, refresh, and quota-recovery policy. */
86
+ filePolicy: DeepSeekFilePolicy;
87
+ /** Provider-owned model-request retry policy, already resolved. */
88
+ retryPolicy: ResolvedRetryPolicy;
89
+ }
90
+ /** Constructor options for {@link DeepSeekAdapter}: the operation-local resolution hooks the plugin owns. */
91
+ export interface DeepSeekAdapterOptions {
92
+ /** Current validated connection facts; called once per operation. */
93
+ options: () => DeepSeekConnectionOptions;
94
+ /**
95
+ * Resolve the bearer token for the connection facts of one request. The
96
+ * snapshot is passed in — never re-read — so the key can only ever come
97
+ * from the same resolution as the endpoint it is sent to. Throws `LlmError`
98
+ * `MISSING_CREDENTIAL` when no key is available anywhere.
99
+ */
100
+ resolveApiKey: (connection: DeepSeekConnectionOptions) => Promise<string>;
101
+ /** Resolve the harness-home anonymous id shared with telemetry and feedback. */
102
+ resolveUserId: () => AnonymousUserId;
103
+ /** Resolve the current durable attachment service; absence rejects image input. */
104
+ resolveAttachments?: () => AttachmentStore | undefined;
105
+ /** Bridge one attachment reference into the current model-tool execution world. */
106
+ resolveImageAccess?: (attachments: AttachmentStore, ref: ImageAttachmentRef) => ImageAttachmentAccess | undefined;
107
+ /** Resolve the process-wide upload reuse store. */
108
+ resolveFiles?: () => DeepSeekFileStore;
109
+ /** Prepare the official API's plugin-contributed top-level fields for one exact wire request. */
110
+ prepareExtensions: (request: DeepSeekLlmApiExtensionRequest) => Promise<PreparedDeepSeekLlmApiExtensions>;
111
+ }
112
+ /** Default maximum idle interval while an adapter stream read is outstanding. */
113
+ export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
114
+ /** Default combined request/response context capacity. */
115
+ export declare const DEFAULT_CONTEXT_WINDOW = 1000000;
116
+ /** Default per-request output-token cap. */
117
+ export declare const DEFAULT_MAX_TOKENS = 256000;
118
+ /** Default bound on accumulated base64 image payload after Files API fallback. */
119
+ export declare const DEFAULT_MAX_INLINE_REQUEST_IMAGE_BYTES: number;
120
+ /** Deterministic raw-byte removal step. */
121
+ export declare const DEFAULT_IMAGE_OFFLOAD_BYTE_QUANTUM: number;
122
+ /** Deterministic base64-byte removal step after Files API fallback. */
123
+ export declare const DEFAULT_INLINE_IMAGE_OFFLOAD_BYTE_QUANTUM: number;
124
+ /** Deterministic image-count removal step. */
125
+ export declare const DEFAULT_IMAGE_OFFLOAD_COUNT_QUANTUM = 20;
126
+ /** Default explicit lifetime for uploaded images. */
127
+ export declare const DEFAULT_FILE_EXPIRY_SECONDS: number;
128
+ /** Default proactive refresh window for indexed file ids. */
129
+ export declare const DEFAULT_FILE_REFRESH_MARGIN_SECONDS: number;
130
+ /** Default number of oldest harness-owned files removed on quota recovery. */
131
+ export declare const DEFAULT_FILE_QUOTA_CLEANUP_BATCH = 100;
132
+ /** Default deadline for resolving one request image through the Files API. */
133
+ export declare const DEFAULT_FILES_API_TIMEOUT_MS = 60000;
134
+ /**
135
+ * Map an HTTP status to a stable LlmError code.
136
+ * @param status - status of a non-2xx provider response.
137
+ * @param error - parsed provider error body, when available.
138
+ * @returns the normalized harness error code.
139
+ */
140
+ export declare function httpErrorCode(status: number, error?: WireError['error']): string;
141
+ /**
142
+ * The first real `LlmAdapter`. One instance serves every model name it was
143
+ * registered under (the harness model name IS the wire model name).
144
+ *
145
+ * One stable signal reaches both initial fetch and body reads. Caller aborts
146
+ * map to `ABORTED`; the configured per-read idle watchdog maps to `TIMEOUT`.
147
+ */
148
+ export declare class DeepSeekAdapter extends LlmAdapter {
149
+ private readonly config;
150
+ private readonly files;
151
+ constructor(config: DeepSeekAdapterOptions);
152
+ providerInfo(provider: string): LlmProviderInfo;
153
+ providerRetryPolicy(_provider: string): ResolvedRetryPolicy;
154
+ imageRequestPricing(_provider: string, model: string): ReturnType<LlmAdapter['imageRequestPricing']>;
155
+ listModels(provider: string): Promise<readonly LlmModelInfo[]>;
156
+ resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
157
+ private modelInfoFor;
158
+ prepareCall(provider: string, model: string, _signal?: AbortSignal): Promise<PreparedAdapterCall>;
159
+ stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
160
+ private streamWithConnection;
161
+ private request;
162
+ }
163
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1,19 @@
1
+ /** DeepSeek Files API identifiers. @module dsh-llm-deepseek/file-id */
2
+ import type { Branded } from '@deepseek-ai/dsh-brand';
3
+ /** Opaque identifier returned by the DeepSeek Files API. */
4
+ export type DeepSeekFileId = Branded<'DeepSeekFileId'>;
5
+ /**
6
+ * Brand a provider-returned file identifier after wire validation.
7
+ * @param id - non-empty Files API identifier.
8
+ * @returns the same string with its provider identity attached at type level.
9
+ */
10
+ export declare function DeepSeekFileId(id: string): DeepSeekFileId;
11
+ /** Non-secret digest identifying one endpoint and API-key file namespace. */
12
+ export type DeepSeekFileScope = Branded<'DeepSeekFileScope'>;
13
+ /**
14
+ * Brand a locally derived namespace digest.
15
+ * @param scope - SHA-256 digest of endpoint and API key.
16
+ * @returns the same string with namespace identity attached at type level.
17
+ */
18
+ export declare function DeepSeekFileScope(scope: string): DeepSeekFileScope;
19
+ //# sourceMappingURL=file-id.d.ts.map
@@ -0,0 +1,83 @@
1
+ /** DeepSeek Files API upload reuse, invalidation, and quota recovery. @module dsh-llm-deepseek/file-store */
2
+ import type { RequestImageAttachment } from '@deepseek-ai/dsh-attachment';
3
+ import type { DeepSeekFileId } from './file-id.ts';
4
+ import { DeepSeekUploadIndex } from './upload-index.ts';
5
+ import type { DeepSeekUploadRecord } from './upload-index.ts';
6
+ /** DeepSeek chat accepts at most 32 MiB per image even when it is referenced by file id. */
7
+ export declare const MAX_CHAT_IMAGE_BYTES: number;
8
+ /** Resolved file-store policy from the plugin configuration. */
9
+ export interface DeepSeekFilePolicy {
10
+ expiresAfterSeconds: number;
11
+ refreshMarginSeconds: number;
12
+ quotaCleanupBatch: number;
13
+ }
14
+ /** Connection facts needed by file operations. */
15
+ export interface DeepSeekFileConnection {
16
+ baseURL: string;
17
+ apiKey: string;
18
+ }
19
+ /** Result of one file-id resolution. */
20
+ export interface DeepSeekFileReference {
21
+ record: DeepSeekUploadRecord;
22
+ uploaded: boolean;
23
+ }
24
+ interface FileStoreOptions {
25
+ index?: DeepSeekUploadIndex;
26
+ now?: () => number;
27
+ fetch?: typeof fetch;
28
+ }
29
+ /** User-scoped durable file-id reuse for the DeepSeek route. */
30
+ export declare class DeepSeekFileStore {
31
+ private readonly index;
32
+ private readonly now;
33
+ private readonly fetchImpl;
34
+ private readonly inflight;
35
+ /**
36
+ * @param options - testable index, clock, and transport boundaries.
37
+ */
38
+ constructor(options?: FileStoreOptions);
39
+ private client;
40
+ /**
41
+ * Resolve or upload one deterministic request image. Concurrent calls share one upload while retaining independent waits.
42
+ * @param version - deterministic model-request bytes and complete transformation identity.
43
+ * @param connection - endpoint and API-key snapshot.
44
+ * @param policy - expiry and quota-recovery policy.
45
+ * @param signal - cancellation of this wait; shared transport stops when no waiter remains.
46
+ * @returns a reusable file id and whether this call published a new upload.
47
+ */
48
+ ensureUploaded(version: RequestImageAttachment, connection: DeepSeekFileConnection, policy: DeepSeekFilePolicy, signal?: AbortSignal): Promise<DeepSeekFileReference>;
49
+ private ensureUploadedOnce;
50
+ /**
51
+ * Invalidate one exact local mapping after the chat endpoint rejects its remote id.
52
+ * @param version - request-image version whose remote generation failed.
53
+ * @param fileId - exact rejected file id.
54
+ * @param connection - endpoint and API-key snapshot.
55
+ */
56
+ invalidate(version: RequestImageAttachment, fileId: DeepSeekFileId, connection: DeepSeekFileConnection): Promise<void>;
57
+ /**
58
+ * Delete the indexed remote file for one attachment and remove its local mapping.
59
+ * @param version - exact request-image version to release.
60
+ * @param connection - endpoint and API-key snapshot.
61
+ * @param policy - expiry policy used to locate a reusable mapping.
62
+ * @param signal - request cancellation.
63
+ * @returns whether an indexed file existed and was deleted.
64
+ */
65
+ release(version: RequestImageAttachment, connection: DeepSeekFileConnection, policy: DeepSeekFilePolicy, signal?: AbortSignal): Promise<boolean>;
66
+ /**
67
+ * Delete the oldest provider files whose names identify harness ownership.
68
+ * @param connection - endpoint and API-key snapshot.
69
+ * @param count - positive maximum number of files to delete.
70
+ * @param signal - request cancellation.
71
+ * @returns number of successfully deleted files.
72
+ */
73
+ reclaimOldestOwned(connection: DeepSeekFileConnection, count: number, signal?: AbortSignal): Promise<number>;
74
+ /**
75
+ * Delete every remote harness-owned file in the active API-key namespace and clear its index.
76
+ * @param connection - endpoint and API-key snapshot.
77
+ * @param signal - request cancellation.
78
+ * @returns number of deleted files.
79
+ */
80
+ releaseAll(connection: DeepSeekFileConnection, signal?: AbortSignal): Promise<number>;
81
+ }
82
+ export {};
83
+ //# sourceMappingURL=file-store.d.ts.map
@@ -0,0 +1,103 @@
1
+ /** OpenAI-compatible DeepSeek Files API transport. @module dsh-llm-deepseek/files-api */
2
+ import { LlmError } from '@deepseek-ai/dsh-llm';
3
+ import type { ImageMediaType } from '@deepseek-ai/dsh-attachment';
4
+ import type { DeepSeekFileId as DeepSeekFileIdType } from './file-id.ts';
5
+ /** Minimum provider-supported file lifetime. */
6
+ export declare const MIN_FILE_EXPIRY_SECONDS = 3600;
7
+ /** Maximum provider-supported file lifetime. */
8
+ export declare const MAX_FILE_EXPIRY_SECONDS = 2592000;
9
+ /** Maximum Files API upload size. */
10
+ export declare const MAX_FILE_UPLOAD_BYTES: number;
11
+ /** Current per-key file-count quota. */
12
+ export declare const MAX_STORED_FILE_COUNT = 10000;
13
+ /** Current per-key storage quota. */
14
+ export declare const MAX_STORED_FILE_BYTES: number;
15
+ /** Validated file object returned by the OpenAI-compatible endpoint. */
16
+ export interface DeepSeekFileObject {
17
+ id: DeepSeekFileIdType;
18
+ bytes: number;
19
+ createdAt: number;
20
+ filename: string;
21
+ purpose: 'user_data';
22
+ expiresAt?: number;
23
+ }
24
+ /** One page returned by `GET /files`. */
25
+ export interface DeepSeekFilePage {
26
+ data: DeepSeekFileObject[];
27
+ firstId?: DeepSeekFileIdType;
28
+ lastId?: DeepSeekFileIdType;
29
+ hasMore: boolean;
30
+ }
31
+ /** Files API operation failure with its HTTP status retained for recovery policy. */
32
+ export declare class DeepSeekFilesError extends LlmError {
33
+ /** Parsed provider detail used only for error classification. */
34
+ readonly detail: string;
35
+ /**
36
+ * @param message - user-readable provider failure.
37
+ * @param status - HTTP status returned by the Files API.
38
+ * @param detail - provider error fields joined for classification.
39
+ */
40
+ constructor(message: string, status: number, detail: string);
41
+ }
42
+ /**
43
+ * Whether an upload failure reports a provider storage or file-count quota.
44
+ * @param error - Files API operation failure.
45
+ * @returns whether one bounded remote cleanup and upload retry may recover.
46
+ */
47
+ export declare function isFilesQuotaError(error: unknown): error is DeepSeekFilesError;
48
+ interface FilesApiOptions {
49
+ baseURL: string;
50
+ apiKey: string;
51
+ fetch?: typeof fetch;
52
+ }
53
+ /** Direct client for the OpenAI-compatible `/files` endpoints. */
54
+ export declare class DeepSeekFilesClient {
55
+ private readonly baseURL;
56
+ private readonly apiKey;
57
+ private readonly fetchImpl;
58
+ /**
59
+ * @param options - endpoint, API-key snapshot, and optional test transport.
60
+ */
61
+ constructor(options: FilesApiOptions);
62
+ private request;
63
+ /**
64
+ * Upload one image with an explicit expiry.
65
+ * @param input - deterministic request-version bytes, media type, filename, lifetime, and cancellation.
66
+ * @returns the validated provider file object, including `expires_at`.
67
+ */
68
+ upload(input: {
69
+ data: Uint8Array;
70
+ mediaType: ImageMediaType;
71
+ filename: string;
72
+ expiresAfterSeconds: number;
73
+ signal?: AbortSignal;
74
+ }): Promise<DeepSeekFileObject & {
75
+ expiresAt: number;
76
+ }>;
77
+ /**
78
+ * List one ascending or descending page of user-data files.
79
+ * @param options - pagination, ordering, and cancellation.
80
+ * @returns the validated page.
81
+ */
82
+ list(options?: {
83
+ after?: DeepSeekFileIdType;
84
+ limit?: number;
85
+ order?: 'asc' | 'desc';
86
+ signal?: AbortSignal;
87
+ }): Promise<DeepSeekFilePage>;
88
+ /**
89
+ * Retrieve one file object.
90
+ * @param fileId - provider file identifier.
91
+ * @param signal - request cancellation.
92
+ * @returns the validated file object.
93
+ */
94
+ retrieve(fileId: DeepSeekFileIdType, signal?: AbortSignal): Promise<DeepSeekFileObject>;
95
+ /**
96
+ * Delete one provider file.
97
+ * @param fileId - provider file identifier.
98
+ * @param signal - request cancellation.
99
+ */
100
+ delete(fileId: DeepSeekFileIdType, signal?: AbortSignal): Promise<void>;
101
+ }
102
+ export {};
103
+ //# sourceMappingURL=files-api.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * DeepSeek v4 vision-token accounting: the provider's published image-token
3
+ * calculator (api-docs.deepseek.com, Token & Token Usage) ported verbatim.
4
+ * The provider resizes every request image onto a 14px-patch grid, downsamples
5
+ * 3:1 per axis, and caps one image at 384 tokens; the port prices the
6
+ * pad-to-4 alignment at its 3-token upper bound because request pricing has
7
+ * no preceding-token position. Actual usage remains authoritative.
8
+ *
9
+ * @module dsh-llm-deepseek/image-tokens
10
+ */
11
+ /**
12
+ * Vision tokens DeepSeek v4 charges for one request image of the given
13
+ * dimensions, at the worst-case alignment pad.
14
+ * @param width - positive integer request-image width in pixels.
15
+ * @param height - positive integer request-image height in pixels.
16
+ * @returns the provider vision-token price, at most 384.
17
+ */
18
+ export declare function deepSeekImageTokens(width: number, height: number): number;
19
+ //# sourceMappingURL=image-tokens.d.ts.map
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Register a {@link DeepSeekAdapter} for the `deepseek-official` provider route on
3
+ * `ctx.llm`, with connection facts resolved per request instead of frozen at
4
+ * load: the plugin layers its `cordis.yml` entry config under the optional
5
+ * `llm-deepseek` user-settings section (`ctx.settings`) and resolves the API
6
+ * key through the optional credential seam (`ctx.credentials`), so a changed
7
+ * base URL, catalog, or key reaches the very next request without restarting
8
+ * anything, while an in-flight stream keeps the facts it started with. The
9
+ * one registration-captured fact — the retry policy — re-registers the route
10
+ * in place when it changes.
11
+ * @module @deepseek-ai/dsh-llm-deepseek
12
+ */
13
+ import type { Context } from '@deepseek-ai/cordis';
14
+ import z from '@deepseek-ai/schemastery';
15
+ import type { RetryPolicyConfig } from '@deepseek-ai/dsh-llm';
16
+ import { type LaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment';
17
+ import type { DeepSeekCatalogModel, DeepSeekConnectionOptions } from './adapter.ts';
18
+ export { DEFAULT_CONTEXT_WINDOW, DEFAULT_FILE_EXPIRY_SECONDS, DEFAULT_FILE_QUOTA_CLEANUP_BATCH, DEFAULT_FILE_REFRESH_MARGIN_SECONDS, DEFAULT_FILES_API_TIMEOUT_MS, DEFAULT_IMAGE_OFFLOAD_BYTE_QUANTUM, DEFAULT_IMAGE_OFFLOAD_COUNT_QUANTUM, DEFAULT_INLINE_IMAGE_OFFLOAD_BYTE_QUANTUM, DEFAULT_MAX_INLINE_REQUEST_IMAGE_BYTES, DEFAULT_MAX_TOKENS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DeepSeekAdapter, } from './adapter.ts';
19
+ export type { DeepSeekAdapterOptions, DeepSeekCatalogModel, DeepSeekConnectionOptions } from './adapter.ts';
20
+ export { DEFAULT_LOW_DETAIL_IMAGE_PIXEL_BUDGET, DEFAULT_MAX_IMAGES_PER_REQUEST, DEFAULT_MAX_REQUEST_FILES_BYTES, DEFAULT_REQUEST_IMAGE_MAX_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, deepSeekImageRequestPricing, resolveRequestImagePolicy, } from './request-pricing.ts';
21
+ export { deepSeekImageTokens } from './image-tokens.ts';
22
+ export { DeepSeekFileStore, MAX_CHAT_IMAGE_BYTES } from './file-store.ts';
23
+ export type { DeepSeekFileConnection, DeepSeekFilePolicy, DeepSeekFileReference } from './file-store.ts';
24
+ export { DeepSeekFilesClient, MAX_FILE_EXPIRY_SECONDS, MAX_FILE_UPLOAD_BYTES, MAX_STORED_FILE_BYTES, MAX_STORED_FILE_COUNT, MIN_FILE_EXPIRY_SECONDS } from './files-api.ts';
25
+ export type { DeepSeekFileObject, DeepSeekFilePage } from './files-api.ts';
26
+ export { DeepSeekFileId } from './file-id.ts';
27
+ export type { DeepSeekFileId as DeepSeekFileIdType } from './file-id.ts';
28
+ export { DeepSeekUploadIndex, deepSeekFileScope } from './upload-index.ts';
29
+ export type { DeepSeekUploadRecord } from './upload-index.ts';
30
+ export type { RequestDefaults } from './serialize.ts';
31
+ export type * from './types.ts';
32
+ export declare const name = "llm-deepseek";
33
+ export declare const inject: string[];
34
+ /**
35
+ * Plugin config, validated by the same-named schemastery schema and doubling
36
+ * as the `llm-deepseek` settings-section shape. Every field is optional in
37
+ * yml: a missing API key resolves through {@link Config.apiKeyEnv} at each
38
+ * request (a request without any key fails with `MISSING_CREDENTIAL`, not at
39
+ * plugin load), omitted thinking mode uses the provider default, and omitted
40
+ * reasoning effort resolves to `high`.
41
+ */
42
+ export interface Config {
43
+ /** Credential reference (environment-variable name) resolved per request; defaults to `DEEPSEEK_API_KEY`. */
44
+ apiKeyEnv?: string;
45
+ /** Endpoint base; falls back to $DEEPSEEK_BASE_URL from a trusted environment layer, then the public API. */
46
+ baseURL?: string;
47
+ /** Deployment thinking policy; `disabled` limits every conversation request to `off`. */
48
+ thinking?: 'enabled' | 'disabled';
49
+ /** Default thinking effort (default `high`); `off` disables thinking per request. */
50
+ reasoningEffort?: 'off' | 'low' | 'high' | 'max';
51
+ /** Default per-request output cap (default 256,000); a model's own cap and explicit request values win. */
52
+ maxTokens?: number;
53
+ /** Positive context capacity used when the selected model has no exact value (default 1,000,000). */
54
+ defaultContextWindow?: number;
55
+ /** Advisory models shown by discovery consumers; defaults to V41 Flash, V4 Flash, V4 Pro, and V4 Flash Vision Exp. */
56
+ models?: DeepSeekCatalogModel[];
57
+ /** Maximum provider idle time while one stream read is outstanding (default five minutes). */
58
+ streamIdleTimeoutMs?: number;
59
+ /** Maximum accumulated file-referenced image bytes per chat request (default 128 MiB). */
60
+ maxRequestFilesBytes?: number;
61
+ /** Maximum accumulated base64 image payload after Files API fallback (default 20 MiB). */
62
+ maxInlineRequestImageBytes?: number;
63
+ /** Maximum number of represented images per chat request (default 600). */
64
+ maxImagesPerRequest?: number;
65
+ /** Raw-byte removal step after the request exceeds its file bound (default 64 MiB). */
66
+ imageOffloadByteQuantum?: number;
67
+ /** Base64-byte removal step after inline fallback exceeds its bound (default 10 MiB). */
68
+ inlineImageOffloadByteQuantum?: number;
69
+ /** Image-count removal step after the request exceeds its count bound (default 20). */
70
+ imageOffloadCountQuantum?: number;
71
+ /** Maximum duration of one request-image Files API resolution (default one minute). */
72
+ filesApiTimeoutMs?: number;
73
+ /** Explicit lifetime assigned to each uploaded image (default seven days). */
74
+ fileExpiresAfterSeconds?: number;
75
+ /** Remaining lifetime below which an indexed file is replaced (default one hour). */
76
+ fileRefreshMarginSeconds?: number;
77
+ /** Oldest harness-owned files deleted before one quota-recovery upload retry (default 100). */
78
+ fileQuotaCleanupBatch?: number;
79
+ /** Provider-owned model-request retry policy; omission uses normal mode with five retries. */
80
+ retryPolicy?: RetryPolicyConfig;
81
+ }
82
+ export declare const Config: z<Config>;
83
+ /** Public API default; the internal endpoint comes from $DEEPSEEK_BASE_URL. */
84
+ export declare const PUBLIC_BASE_URL = "https://api.deepseek.com";
85
+ /**
86
+ * One resolution's complete request facts. Connection and credential facts
87
+ * are one value on purpose: a snapshot the resolver rejects keeps the whole
88
+ * previous generation, so a request can never pair a stale endpoint with a
89
+ * newer key.
90
+ */
91
+ export type ResolvedDeepSeekOptions = DeepSeekConnectionOptions;
92
+ /**
93
+ * The one explicit resolve step from raw config to validated connection
94
+ * facts. Programmatic construction may bypass Schemastery normalization, so
95
+ * every default and bound is re-judged here — for the composition entry at
96
+ * load (fail loud) and for each settings snapshot at its first use.
97
+ * @param config - raw plugin config or resolved settings snapshot.
98
+ * @param environment - this run's environment layers, or `undefined` outside
99
+ * the product CLI. Every layer may supply an endpoint: the product trusts the
100
+ * project it is launched in, so a checkout can point its own agent at the
101
+ * gateway that checkout is meant to use.
102
+ * @returns validated connection facts plus the credential reference.
103
+ */
104
+ export declare function resolveAdapterOptions(config: Config, environment?: LaunchEnvironmentSnapshot): ResolvedDeepSeekOptions;
105
+ export declare function apply(ctx: Context, config: Config): void;
106
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Provider-side request-image pricing for DeepSeek routes: reproduces the
3
+ * adapter's deterministic request projection (per-model pixel budget,
4
+ * oldest-first offload under the raw-byte and count budgets) and prices every
5
+ * retained image with the published v4 vision-token accounting. Consumed
6
+ * synchronously by the token meter through `LlmAdapter.imageRequestPricing`;
7
+ * provider usage remains the authoritative anchor for completed requests.
8
+ *
9
+ * @module dsh-llm-deepseek/request-pricing
10
+ */
11
+ import type { ImageAttachmentAccessResolver, LlmImageRequestPricing } from '@deepseek-ai/dsh-llm';
12
+ import type { ImageRequestPolicy } from '@deepseek-ai/dsh-attachment';
13
+ import type { DeepSeekCatalogModel, DeepSeekConnectionOptions } from './adapter.ts';
14
+ /** Default bound on accumulated file-referenced image bytes per request. */
15
+ export declare const DEFAULT_MAX_REQUEST_FILES_BYTES: number;
16
+ /** Provider request image-count limit. */
17
+ export declare const DEFAULT_MAX_IMAGES_PER_REQUEST = 600;
18
+ /** Total-pixel budget matching DeepSeek's normal vision projection. */
19
+ export declare const DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET = 640000;
20
+ /** Total-pixel budget matching provider low-detail image input. */
21
+ export declare const DEFAULT_LOW_DETAIL_IMAGE_PIXEL_BUDGET: number;
22
+ /** Encoded-byte target for one deterministic model-request image; the smallest quality-ladder output is used when no quality fits. */
23
+ export declare const DEFAULT_REQUEST_IMAGE_MAX_BYTES: number;
24
+ /**
25
+ * Resolve the request-image budgets owned by one DeepSeek model route.
26
+ * @param model - Advertised model route and its optional image overrides.
27
+ * @returns Complete pixel and encoded-byte budgets.
28
+ * @internal
29
+ */
30
+ export declare function resolveRequestImagePolicy(model: DeepSeekCatalogModel): ImageRequestPolicy;
31
+ /**
32
+ * Build the request-image pricing for one DeepSeek route from a validated
33
+ * connection snapshot. Uncatalogued and text-only models price every
34
+ * occurrence as its deterministic text substitution; image-capable models
35
+ * reproduce the adapter's first-stage oldest-first offload from durable byte
36
+ * lengths and price retained images by their projected request dimensions,
37
+ * with each occurrence's handle or placeholder text built through the same
38
+ * access resolution the serializer uses. The base64 fallback's tighter inline
39
+ * budget is not reproduced, so a fallback request can only cost less than
40
+ * this estimate; access paths resolve at pricing time, so a path that changes
41
+ * before the request only shifts the text price by its own length.
42
+ * @param connection - validated connection facts of the pricing resolution.
43
+ * @param model - exact model id named by the request header.
44
+ * @param resolveAccess - current execution-world access resolution shared with request serialization.
45
+ * @returns synchronous per-occurrence pricing for the route.
46
+ */
47
+ export declare function deepSeekImageRequestPricing(connection: DeepSeekConnectionOptions, model: string, resolveAccess?: ImageAttachmentAccessResolver): LlmImageRequestPricing;
48
+ //# sourceMappingURL=request-pricing.d.ts.map
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Serialize harness messages into DeepSeek chat completions. Text-only
3
+ * requests retain string user content; the image path resolves durable
4
+ * attachments into ordered file-id or inline parts. Tool-result images follow their
5
+ * string-only tool messages in a separate user message.
6
+ * @module dsh-llm-deepseek/serialize
7
+ */
8
+ import type { ContentBlock, GenerateOptions, ImageAttachmentAccessResolver, Message } from '@deepseek-ai/dsh-llm';
9
+ import type { ImageAttachmentRef, RequestImageAttachment } from '@deepseek-ai/dsh-attachment';
10
+ import type { WireMessage, WireRequest } from './types.ts';
11
+ /** Adapter-level request defaults (from plugin config). */
12
+ export interface RequestDefaults {
13
+ thinking?: 'enabled' | 'disabled' | undefined;
14
+ reasoningEffort?: 'off' | 'low' | 'high' | 'max' | undefined;
15
+ }
16
+ /** Provider representation for every retained image in one request. */
17
+ export type ImageRequestRepresentation = {
18
+ kind: 'file';
19
+ /** Resolve a retained request version to a reusable DeepSeek file id. */
20
+ resolveFileId: (version: RequestImageAttachment, block: Extract<ContentBlock, {
21
+ type: 'image';
22
+ }>, location: ImageWireLocation) => Promise<string>;
23
+ } | {
24
+ kind: 'base64';
25
+ };
26
+ /** Dependencies required only when the request contains image input. */
27
+ export interface ImageSerializationOptions {
28
+ /** One representation used for every retained image in this request. */
29
+ representation: ImageRequestRepresentation;
30
+ /** Request versions prepared for the conservatively retained normalized attachments, keyed by attachment id. */
31
+ requestImages: ReadonlyMap<ImageAttachmentRef['attachmentId'], RequestImageAttachment>;
32
+ /** Resolve current tool access independently from deterministic request-image versions. */
33
+ resolveImageAccess?: ImageAttachmentAccessResolver;
34
+ /** Positive bound on accumulated represented image bytes. */
35
+ maxRequestImageBytes: number;
36
+ /** Maximum represented images in one request. */
37
+ maxImagesPerRequest?: number;
38
+ /** Represented-byte removal step applied after the request exceeds its byte bound. */
39
+ byteQuantum?: number;
40
+ /** Image-count removal step applied after the request exceeds its count bound. */
41
+ countQuantum?: number;
42
+ }
43
+ /** Durable message and image ordinal used in provider diagnostics. */
44
+ export interface ImageWireLocation {
45
+ message: number;
46
+ image: number;
47
+ }
48
+ /**
49
+ * Serialize the conversation. `tool-result` blocks become standalone
50
+ * `{role: 'tool'}` messages; the harness puts each tool result in its own
51
+ * user-role message, so a mixed user message contributes its text first and
52
+ * its tool results as separate wire messages after.
53
+ * @param messages - the harness conversation, in order.
54
+ * @returns the wire messages; order preserved, each tool result expanded into its own entry.
55
+ */
56
+ export declare function serializeMessages(messages: Message[]): WireMessage[];
57
+ /**
58
+ * Serialize image-capable history after resolving durable attachments.
59
+ * Consecutive tool results keep string `tool` messages and share one following
60
+ * user message containing their images.
61
+ * @param messages - transient request history after request-size offloading.
62
+ * @param images - prepared request versions, one provider representation, and its budget.
63
+ * @returns ordered DeepSeek wire messages.
64
+ */
65
+ export declare function serializeMessagesWithImages(messages: readonly Message[], images: ImageSerializationOptions): Promise<WireMessage[]>;
66
+ /**
67
+ * Build the full wire request. Always streaming (`stream: true`, usage
68
+ * reporting on); optional fields are omitted rather than sent as null, so
69
+ * provider defaults apply.
70
+ * @param options - the harness request (model, history, system, tools, sampling).
71
+ * @param defaults - adapter-level thinking defaults; undefined fields put nothing on the wire.
72
+ * @returns the chat-completions request body.
73
+ */
74
+ export declare function serializeRequest(options: GenerateOptions, defaults?: RequestDefaults): WireRequest;
75
+ /**
76
+ * Build one image-capable request while keeping durable bytes out of session
77
+ * messages. Oversized oldest images become per-image text after their
78
+ * exact request-version byte lengths are known and before provider serialization.
79
+ * @param options - harness request containing image-capable user content.
80
+ * @param images - request versions, optional current access resolver, and request bounds.
81
+ * @param defaults - adapter-level thinking defaults.
82
+ * @returns the fully materialized DeepSeek request body.
83
+ */
84
+ export declare function serializeRequestWithImages(options: GenerateOptions, images: ImageSerializationOptions, defaults?: RequestDefaults): Promise<WireRequest>;
85
+ //# sourceMappingURL=serialize.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Decode an SSE byte stream into event `data` payloads. Framing — chunk
3
+ * reassembly, UTF-8/CRLF/BOM handling, comment and non-data field skipping,
4
+ * multi-`data:` joining — is `eventsource-parser`'s. Comments are reported
5
+ * only through an optional transport-activity callback. This module keeps the
6
+ * DeepSeek protocol: the literal `[DONE]` is yielded so the caller owns final
7
+ * flushing, and EOF before it raises {@link LlmError}. Framing is spec-strict:
8
+ * an event dispatches only on its blank-line terminator, so an unterminated
9
+ * tail at EOF is truncation, not a flushable payload.
10
+ *
11
+ * @module dsh-llm-deepseek/sse
12
+ */
13
+ /** The terminal payload DeepSeek (and OpenAI) send after the last chunk. */
14
+ export declare const DONE = "[DONE]";
15
+ /**
16
+ * Parse an SSE byte stream into data payloads. Yields `[DONE]` as the final
17
+ * value and returns; throws `LlmError('STREAM_CLOSED')` when the stream ends
18
+ * without it (truncated response — the model call cannot be trusted).
19
+ * @param stream - raw SSE bytes; reads may split anywhere, including mid-UTF-8 sequence.
20
+ * @param onComment - optional transport-activity callback; comments never enter the yielded payload stream.
21
+ * @returns each event's data payload in arrival order, the `[DONE]` sentinel last.
22
+ */
23
+ export declare function parseSse(stream: ReadableStream<BufferSource>, onComment?: (comment: string) => void): AsyncGenerator<string>;
24
+ //# sourceMappingURL=sse.d.ts.map