@eddyskywalker/dsh-chatgpt-subscription 0.33.0 → 0.34.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.
- package/CHANGELOG.md +45 -0
- package/README.md +51 -110
- package/lib/client.js +1483 -335
- package/lib/client.js.map +1 -1
- package/lib/index.js +5934 -1974
- package/lib/types/client/common/format.d.ts +10 -0
- package/lib/types/client/common/format.d.ts.map +1 -1
- package/lib/types/client/hub/brand-icons.d.ts +2 -2
- package/lib/types/client/hub/brand-icons.d.ts.map +1 -1
- package/lib/types/client/hub/providers.d.ts.map +1 -1
- package/lib/types/client/index.d.ts +2 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/opendesign/OpenDesignComposerQuota.d.ts +20 -0
- package/lib/types/client/opendesign/OpenDesignComposerQuota.d.ts.map +1 -0
- package/lib/types/client/opendesign/OpenDesignSection.d.ts +18 -0
- package/lib/types/client/opendesign/OpenDesignSection.d.ts.map +1 -0
- package/lib/types/client/opendesign/api.d.ts +45 -0
- package/lib/types/client/opendesign/api.d.ts.map +1 -0
- package/lib/types/client/opendesign/locales.d.ts +689 -0
- package/lib/types/client/opendesign/locales.d.ts.map +1 -0
- package/lib/types/client/opendesign/styles.d.ts +11 -0
- package/lib/types/client/opendesign/styles.d.ts.map +1 -0
- package/lib/types/client/qoder/QoderSection.d.ts +12 -2
- package/lib/types/client/qoder/QoderSection.d.ts.map +1 -1
- package/lib/types/client/qoder/locales.d.ts +7 -1
- package/lib/types/client/qoder/locales.d.ts.map +1 -1
- package/lib/types/client/qoder/useQoderSection.d.ts.map +1 -1
- package/lib/types/host/common/model-request-control.d.ts +1 -1
- package/lib/types/host/common/model-request-control.d.ts.map +1 -1
- package/lib/types/host/common/request-diagnostics.d.ts +1 -1
- package/lib/types/host/common/request-diagnostics.d.ts.map +1 -1
- package/lib/types/host/kimi-code/adapter.d.ts +31 -0
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/mapper.d.ts +8 -0
- package/lib/types/host/kimi-code/mapper.d.ts.map +1 -1
- package/lib/types/host/kimi-code/types.d.ts +92 -0
- package/lib/types/host/kimi-code/types.d.ts.map +1 -1
- package/lib/types/host/opendesign/account-pool.d.ts +54 -0
- package/lib/types/host/opendesign/account-pool.d.ts.map +1 -0
- package/lib/types/host/opendesign/adapter.d.ts +69 -0
- package/lib/types/host/opendesign/adapter.d.ts.map +1 -0
- package/lib/types/host/opendesign/catalog.d.ts +44 -0
- package/lib/types/host/opendesign/catalog.d.ts.map +1 -0
- package/lib/types/host/opendesign/client.d.ts +148 -0
- package/lib/types/host/opendesign/client.d.ts.map +1 -0
- package/lib/types/host/opendesign/line.d.ts +49 -0
- package/lib/types/host/opendesign/line.d.ts.map +1 -0
- package/lib/types/host/opendesign/mapper.d.ts +128 -0
- package/lib/types/host/opendesign/mapper.d.ts.map +1 -0
- package/lib/types/host/opendesign/oauth.d.ts +105 -0
- package/lib/types/host/opendesign/oauth.d.ts.map +1 -0
- package/lib/types/host/opendesign/routes.d.ts +74 -0
- package/lib/types/host/opendesign/routes.d.ts.map +1 -0
- package/lib/types/host/opendesign/token-store.d.ts +154 -0
- package/lib/types/host/opendesign/token-store.d.ts.map +1 -0
- package/lib/types/host/opendesign/types.d.ts +180 -0
- package/lib/types/host/opendesign/types.d.ts.map +1 -0
- package/lib/types/host/qoder/adapter.d.ts +26 -2
- package/lib/types/host/qoder/adapter.d.ts.map +1 -1
- package/lib/types/host/qoder/client.d.ts +112 -0
- package/lib/types/host/qoder/client.d.ts.map +1 -1
- package/lib/types/host/qoder/model-catalog.d.ts +52 -6
- package/lib/types/host/qoder/model-catalog.d.ts.map +1 -1
- package/lib/types/host/qoder/routes.d.ts +23 -0
- package/lib/types/host/qoder/routes.d.ts.map +1 -1
- package/lib/types/host/qoder/token-store.d.ts +56 -7
- package/lib/types/host/qoder/token-store.d.ts.map +1 -1
- package/lib/types/index.d.ts +11 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/opendesign-contracts.d.ts +159 -0
- package/lib/types/shared/opendesign-contracts.d.ts.map +1 -0
- package/lib/types/shared/qoder-contracts.d.ts +40 -1
- package/lib/types/shared/qoder-contracts.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport for the OpenDesign link gateway. Transport only: no account or
|
|
3
|
+
* retry policy lives here (see `adapter.ts`).
|
|
4
|
+
*
|
|
5
|
+
* - `POST {baseURL}/chat/completions` — the chat endpoint this line speaks
|
|
6
|
+
* - `GET {baseURL}/models` — the key's live catalog; also the auth probe,
|
|
7
|
+
* because listing costs no credits while a token of chat does
|
|
8
|
+
*
|
|
9
|
+
* The base URL is the OpenAI spelling and already ends in `/v1`
|
|
10
|
+
* (src/host/opendesign/types.ts records how that was verified), so paths append
|
|
11
|
+
* literally.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-chatgpt-subscription/opendesign-client
|
|
14
|
+
*/
|
|
15
|
+
import { type OpenDesignDiscoveredModel } from './types.ts';
|
|
16
|
+
export interface OpenDesignHttpResult {
|
|
17
|
+
status: number;
|
|
18
|
+
ok: boolean;
|
|
19
|
+
json: unknown;
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
/** Combine a caller signal with a timeout signal. */
|
|
23
|
+
export declare function withTimeout(signal: AbortSignal | undefined, timeoutMs: number | undefined): AbortSignal | undefined;
|
|
24
|
+
/** Strip a trailing slash so paths can be appended literally. */
|
|
25
|
+
export declare function trimBase(baseURL: string): string;
|
|
26
|
+
/** The gateway's chat-completions endpoint for one base URL. */
|
|
27
|
+
export declare function chatURL(baseURL: string): string;
|
|
28
|
+
/** The gateway's catalog endpoint for one base URL. */
|
|
29
|
+
export declare function modelsURL(baseURL: string): string;
|
|
30
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
31
|
+
/** Send one JSON request and decode whatever comes back; never throws for HTTP errors. */
|
|
32
|
+
export declare function sendJSON(fetchFn: typeof fetch, url: string, { method, apiKey, body, signal, timeoutMs, headers, }?: {
|
|
33
|
+
method?: string;
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
body?: unknown;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
headers?: Record<string, string>;
|
|
39
|
+
}): Promise<OpenDesignHttpResult>;
|
|
40
|
+
/** Open a streaming chat completion and hand back the live response. */
|
|
41
|
+
export declare function openChatStream({ fetchFn, baseURL, apiKey, body, signal, headers, }: {
|
|
42
|
+
fetchFn: typeof fetch;
|
|
43
|
+
baseURL: string;
|
|
44
|
+
apiKey: string;
|
|
45
|
+
body: unknown;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
headers?: Record<string, string>;
|
|
48
|
+
}): Promise<Response>;
|
|
49
|
+
/** The gateway's own one-line explanation, when it sent one. */
|
|
50
|
+
export declare function firstMessage(envelope: unknown): string;
|
|
51
|
+
/**
|
|
52
|
+
* The live catalog one key may list.
|
|
53
|
+
*
|
|
54
|
+
* Returns ids plus whatever metadata the listing published, or null on any
|
|
55
|
+
* failure — a refused or unreachable gateway is a fact the caller reports, not
|
|
56
|
+
* an exception the route drops.
|
|
57
|
+
*/
|
|
58
|
+
export declare function fetchGatewayCatalog({ fetchFn, baseURL, apiKey, signal, timeoutMs, }: {
|
|
59
|
+
fetchFn: typeof fetch;
|
|
60
|
+
baseURL: string;
|
|
61
|
+
apiKey: string;
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
timeoutMs?: number;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
ids: string[];
|
|
66
|
+
catalog: Record<string, OpenDesignDiscoveredModel>;
|
|
67
|
+
} | null>;
|
|
68
|
+
/**
|
|
69
|
+
* One id compared without its separators.
|
|
70
|
+
*
|
|
71
|
+
* The AMR control-plane catalog spells ids `public_model_deepseek_v4_1_flash`
|
|
72
|
+
* (the open-source daemon normalizes the same spellings at its boundary), while
|
|
73
|
+
* the link gateway and this line's table use `deepseek-v4.1-flash`. Comparing
|
|
74
|
+
* alphanumerics only maps one onto the other without a per-model translation
|
|
75
|
+
* table that would rot the moment a model is added.
|
|
76
|
+
*/
|
|
77
|
+
export declare function canonicalModelKey(id: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* The control-plane catalog: the AMR-side listing, which DOES carry metadata.
|
|
80
|
+
*
|
|
81
|
+
* `GET {amr}/models` with a control key (the open-source daemon reads the same
|
|
82
|
+
* catalog through `vela model list --all --format json`, whose items carry
|
|
83
|
+
* `metadata.contextWindowTokens`). Ids are normalized onto the known wire ids
|
|
84
|
+
* with {@link canonicalModelKey}; an id the line does not know is kept as the
|
|
85
|
+
* slug it arrived as, never dropped.
|
|
86
|
+
*
|
|
87
|
+
* A runtime key is not accepted here (the console's control-plane surfaces
|
|
88
|
+
* reject it), so this is an OAuth-account capability; the gateway listing stays
|
|
89
|
+
* the path for a pasted key.
|
|
90
|
+
*/
|
|
91
|
+
export declare function fetchControlPlaneCatalog({ fetchFn, controlKey, apiBase, knownIds, signal, timeoutMs, }: {
|
|
92
|
+
fetchFn: typeof fetch;
|
|
93
|
+
controlKey: string;
|
|
94
|
+
apiBase?: string;
|
|
95
|
+
knownIds?: readonly string[];
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
timeoutMs?: number;
|
|
98
|
+
}): Promise<{
|
|
99
|
+
ids: string[];
|
|
100
|
+
catalog: Record<string, OpenDesignDiscoveredModel>;
|
|
101
|
+
} | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Verify one key with the free catalog read.
|
|
104
|
+
*
|
|
105
|
+
* A chat probe would spend credits to learn the same thing, so the probe is the
|
|
106
|
+
* listing: 200 proves the key works (and how many models it sees), 401/403
|
|
107
|
+
* proves it does not, and anything else is reported as the gateway sent it.
|
|
108
|
+
*/
|
|
109
|
+
export declare function testApiKey({ fetchFn, baseURL, apiKey, signal, timeoutMs, }: {
|
|
110
|
+
fetchFn: typeof fetch;
|
|
111
|
+
baseURL: string;
|
|
112
|
+
apiKey: string;
|
|
113
|
+
signal?: AbortSignal;
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
}): Promise<{
|
|
116
|
+
authorized: boolean;
|
|
117
|
+
ms: number;
|
|
118
|
+
error: string;
|
|
119
|
+
modelCount: number;
|
|
120
|
+
}>;
|
|
121
|
+
/** One wallet reading: the balance string as served, or the refusal as data. */
|
|
122
|
+
export interface OpenDesignWalletBalance {
|
|
123
|
+
ok: boolean;
|
|
124
|
+
/** USD balance, exactly as the service strings it (e.g. "12.34"). */
|
|
125
|
+
balanceUsd: string | null;
|
|
126
|
+
/** ISO instant the service stamped on the reading, when it sent one. */
|
|
127
|
+
updatedAt: string | null;
|
|
128
|
+
error: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Read one OAuth account's wallet balance with its control key.
|
|
132
|
+
*
|
|
133
|
+
* Wire shape from the open-source daemon's reader
|
|
134
|
+
* (apps/daemon/src/integrations/vela-wallet.ts, nexu-io/open-design): the
|
|
135
|
+
* balance is a STRING matching /^\d+(?:\.\d+)?$/ — a number-shaped field of
|
|
136
|
+
* any other type is not a balance. A refusal is reported as data, never thrown:
|
|
137
|
+
* the card shows it beside controls that keep working without it. Billing reads
|
|
138
|
+
* are display-only upstream too (OPEND-3553 in the same repo): a wallet 401/403
|
|
139
|
+
* says nothing about the chat credential, so it must never mark the account.
|
|
140
|
+
*/
|
|
141
|
+
export declare function fetchWalletBalance({ fetchFn, controlKey, apiBase, signal, timeoutMs, }: {
|
|
142
|
+
fetchFn: typeof fetch;
|
|
143
|
+
controlKey: string;
|
|
144
|
+
apiBase?: string;
|
|
145
|
+
signal?: AbortSignal;
|
|
146
|
+
timeoutMs?: number;
|
|
147
|
+
}): Promise<OpenDesignWalletBalance>;
|
|
148
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../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BnC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
|
|
3
|
+
import { type ProviderRouteClaim } from '../common/provider-route.ts';
|
|
4
|
+
import { OpenDesignAccountPool } from './account-pool.ts';
|
|
5
|
+
import { OpenDesignAdapter } from './adapter.ts';
|
|
6
|
+
import { OpenDesignLoginManager } from './oauth.ts';
|
|
7
|
+
import { OPENDESIGN_ROUTES } from './routes.ts';
|
|
8
|
+
import { OpenDesignModelSettingsStore, type OpenDesignModelSettings } from './token-store.ts';
|
|
9
|
+
import type { HubSummarySource } from '../hub-overview.ts';
|
|
10
|
+
export interface OpenDesignLineOptions {
|
|
11
|
+
/** Proxy-aware fetch that routes and catalog syncs use. */
|
|
12
|
+
fetchFn: typeof fetch;
|
|
13
|
+
/** Controlled/diagnostic fetch that live adapter chat streams use; defaults to fetchFn. */
|
|
14
|
+
modelFetchFn?: typeof fetch;
|
|
15
|
+
/** Durable attachment service, for image input. */
|
|
16
|
+
attachments?: Pick<AttachmentStore, 'readImage' | 'readImageRequest'>;
|
|
17
|
+
}
|
|
18
|
+
export interface OpenDesignLine {
|
|
19
|
+
adapter: OpenDesignAdapter;
|
|
20
|
+
modelSettings: OpenDesignModelSettingsStore;
|
|
21
|
+
accountPool: OpenDesignAccountPool;
|
|
22
|
+
login: OpenDesignLoginManager;
|
|
23
|
+
claim: ProviderRouteClaim;
|
|
24
|
+
disposeRoutes: () => void;
|
|
25
|
+
/** Owner overview card source, read from local snapshots only. */
|
|
26
|
+
hubSource: HubSummarySource;
|
|
27
|
+
/** Release every registration this line made. */
|
|
28
|
+
dispose(): void;
|
|
29
|
+
}
|
|
30
|
+
/** Every id the line knows: the shipped table plus the synced live catalog. */
|
|
31
|
+
export declare function openDesignKnownModelIds(settings: OpenDesignModelSettings): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Every id the line advertises right now.
|
|
34
|
+
*
|
|
35
|
+
* The selection rule is shared by the adapter, the status route and the hub
|
|
36
|
+
* card — they must all read this one function, not three private copies: the
|
|
37
|
+
* user's tick list and the shipped table speak the same id vocabulary here (the
|
|
38
|
+
* gateway's own wire ids), so a cold-start intersection cannot empty the picker,
|
|
39
|
+
* and an explicit "everything off" (`[]`) still wins.
|
|
40
|
+
*/
|
|
41
|
+
export declare function openDesignVisibleModelIds(settings: OpenDesignModelSettings): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Build the line.
|
|
44
|
+
* @param ctx - host plugin context (owns `llm` and `webServer`).
|
|
45
|
+
* @param options - the proxy-aware fetch and the attachment reader.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createOpenDesignLine(ctx: Context, options: OpenDesignLineOptions): OpenDesignLine;
|
|
48
|
+
export { OPENDESIGN_ROUTES };
|
|
49
|
+
//# sourceMappingURL=line.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/line.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAGzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAoD,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACjG,OAAO,EAAE,4BAA4B,EAAE,KAAK,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAE7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,MAAM,WAAW,qBAAqB;IACpC,2DAA2D;IAC3D,OAAO,EAAE,OAAO,KAAK,CAAA;IACrB,2FAA2F;IAC3F,YAAY,CAAC,EAAE,OAAO,KAAK,CAAA;IAC3B,mDAAmD;IACnD,WAAW,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,kBAAkB,CAAC,CAAA;CACtE;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,iBAAiB,CAAA;IAC1B,aAAa,EAAE,4BAA4B,CAAA;IAC3C,WAAW,EAAE,qBAAqB,CAAA;IAClC,KAAK,EAAE,sBAAsB,CAAA;IAC7B,KAAK,EAAE,kBAAkB,CAAA;IACzB,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,kEAAkE;IAClE,SAAS,EAAE,gBAAgB,CAAA;IAC3B,iDAAiD;IACjD,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,+EAA+E;AAC/E,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,EAAE,CAInF;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,EAAE,CAIrF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAmFjG;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenDesign wire mapping: the harness conversation in, an OpenAI-compatible
|
|
3
|
+
* `chat/completions` body out; decoded SSE frames in, harness stream chunks out.
|
|
4
|
+
*
|
|
5
|
+
* The request order rules matter more than they look: an assistant message
|
|
6
|
+
* carrying `tool_calls` must be followed immediately by one `tool` message per
|
|
7
|
+
* call id, or a validating gateway rejects the whole request with "insufficient
|
|
8
|
+
* tool messages following tool_calls message". Everything that would otherwise
|
|
9
|
+
* land inside that run is held back until the group closes.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-chatgpt-subscription/opendesign-mapper
|
|
12
|
+
*/
|
|
13
|
+
import { type StreamChunk, type TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import type { GenerateOptions, Message } from '../common/llm-compat.ts';
|
|
15
|
+
import { type ResolvedRequestImages } from '../common/request-images.ts';
|
|
16
|
+
/** The sentence a no-content finish carries, shared with the sibling lines. */
|
|
17
|
+
export declare const NO_ANSWER_PHRASE = "ended the turn without an answer or a tool call";
|
|
18
|
+
/** One OpenAI wire message. */
|
|
19
|
+
export interface OpenDesignWireMessage {
|
|
20
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
21
|
+
content: string | Array<Record<string, unknown>>;
|
|
22
|
+
reasoning_content?: string;
|
|
23
|
+
tool_calls?: Array<{
|
|
24
|
+
id: string;
|
|
25
|
+
type: 'function';
|
|
26
|
+
function: {
|
|
27
|
+
name: string;
|
|
28
|
+
arguments: string;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
tool_call_id?: string;
|
|
32
|
+
}
|
|
33
|
+
/** One request body, as sent to the gateway. */
|
|
34
|
+
export interface OpenDesignWireBody {
|
|
35
|
+
model: string;
|
|
36
|
+
messages: OpenDesignWireMessage[];
|
|
37
|
+
stream: true;
|
|
38
|
+
stream_options: {
|
|
39
|
+
include_usage: true;
|
|
40
|
+
};
|
|
41
|
+
tools?: Array<{
|
|
42
|
+
type: 'function';
|
|
43
|
+
function: {
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
parameters: Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
temperature?: number;
|
|
50
|
+
max_tokens?: number;
|
|
51
|
+
stop?: readonly string[];
|
|
52
|
+
reasoning_effort?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Convert the harness conversation to wire messages.
|
|
56
|
+
*
|
|
57
|
+
* Tool results become standalone `role: 'tool'` messages. A user message
|
|
58
|
+
* carrying an image switches to the OpenAI content-part array; a text-only one
|
|
59
|
+
* keeps the plain-string form. An image nested in a tool result has no OpenAI
|
|
60
|
+
* `tool` wire spelling, so it rides a following user message instead — the same
|
|
61
|
+
* shape the shipped adapters use. Deferring that message until the next non-tool
|
|
62
|
+
* message keeps a parallel group's answers contiguous.
|
|
63
|
+
*
|
|
64
|
+
* `developer` becomes `system`: the newer OpenAI spelling is not accepted by
|
|
65
|
+
* every OpenAI-compatible gateway, while `system` is.
|
|
66
|
+
*/
|
|
67
|
+
export declare function serializeMessages(messages: readonly Message[], images: ResolvedRequestImages): OpenDesignWireMessage[];
|
|
68
|
+
/**
|
|
69
|
+
* Build the wire request for one harness call.
|
|
70
|
+
* @param options - the harness request (model, system, history, tools, sampling).
|
|
71
|
+
* @param connection - resolved connection facts (default output budget).
|
|
72
|
+
* @param images - attachmentId → prepared request version.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildOpenDesignBody(options: GenerateOptions, connection: {
|
|
75
|
+
maxTokens: number;
|
|
76
|
+
}, images: ResolvedRequestImages): OpenDesignWireBody;
|
|
77
|
+
/** Map an OpenAI `finish_reason` to the harness finish reason. */
|
|
78
|
+
export declare function mapFinishReason(reason: string): StreamChunk & {
|
|
79
|
+
type: 'finish';
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Map OpenAI usage fields to disjoint harness counts.
|
|
83
|
+
*
|
|
84
|
+
* `prompt_tokens` includes cache hits per the OpenAI convention, and the harness
|
|
85
|
+
* counts are disjoint, so cached tokens are subtracted out of `inputTokens`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mapUsage(usage: Record<string, unknown> | null | undefined): TokenUsage;
|
|
88
|
+
/**
|
|
89
|
+
* Read one delta's reasoning text, tolerating both wire spellings.
|
|
90
|
+
*
|
|
91
|
+
* Prefers the string field, and falls back to joining the `reasoning_details`
|
|
92
|
+
* parts, which is where a gateway that omits the flat field puts the same text.
|
|
93
|
+
*/
|
|
94
|
+
export declare function reasoningOf(delta: Record<string, unknown>): string | undefined;
|
|
95
|
+
/** The gateway's error string, whichever envelope it arrived in. */
|
|
96
|
+
export declare function errorText(error: unknown): string;
|
|
97
|
+
/** Whether the payload is a bare error object rather than a completion chunk. */
|
|
98
|
+
export declare function isErrorPayload(payload: unknown): payload is {
|
|
99
|
+
error: unknown;
|
|
100
|
+
};
|
|
101
|
+
/** Whether one refusal is about the credential at all. */
|
|
102
|
+
export declare function isAuthenticationError(message: string, status?: number): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Map a gateway error payload to a stable harness code.
|
|
105
|
+
*
|
|
106
|
+
* OpenDesign meters in dollar-denominated credits, so the exhausted state reads
|
|
107
|
+
* as an insufficient-balance/credits refusal, not a window name: 402, or the
|
|
108
|
+
* gateway's own wording about credits/balance running out, is QUOTA. Anything
|
|
109
|
+
* merely mentioning a plan or a limit is NOT — a temporary billing-lookup
|
|
110
|
+
* failure must not stand an account down.
|
|
111
|
+
*/
|
|
112
|
+
export declare function streamErrorCode(message: string, status?: number): string;
|
|
113
|
+
/**
|
|
114
|
+
* Parse an SSE body into decoded JSON frames.
|
|
115
|
+
* @param body - a web ReadableStream of UTF-8 bytes.
|
|
116
|
+
* @returns every `data:` payload up to `[DONE]`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function parseServerSentEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<unknown | '[DONE]'>;
|
|
119
|
+
/**
|
|
120
|
+
* Translate decoded SSE payloads into harness stream chunks.
|
|
121
|
+
*
|
|
122
|
+
* Deltas stream through as they arrive; block ends, usage and the finish reason
|
|
123
|
+
* are all deferred to the `[DONE]` sentinel, so no chunk ever follows `finish`.
|
|
124
|
+
* A completion with no content at all becomes an `EMPTY_RESPONSE` error finish
|
|
125
|
+
* rather than a silent empty message.
|
|
126
|
+
*/
|
|
127
|
+
export declare function translate(payloads: AsyncIterable<unknown | '[DONE]'>): AsyncGenerator<StreamChunk>;
|
|
128
|
+
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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G;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAWxE;AAED;;;;GAIG;AACH,wBAAuB,qBAAqB,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC,OAAO,GAAG,QAAQ,CAAC,CA2CjH;AAcD;;;;;;;GAOG;AACH,wBAAuB,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,cAAc,CAAC,WAAW,CAAC,CA+FzG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { OpenDesignOAuthCredentials } from './token-store.ts';
|
|
2
|
+
/** An auth failure with the HTTP facts a caller can judge. */
|
|
3
|
+
export declare class OpenDesignOAuthError extends Error {
|
|
4
|
+
readonly status?: number;
|
|
5
|
+
readonly code?: string;
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
status?: number;
|
|
8
|
+
code?: string;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** One device authorization, as the create call returns it. */
|
|
13
|
+
export interface OpenDesignDeviceAuthorization {
|
|
14
|
+
deviceId: string;
|
|
15
|
+
userCode: string;
|
|
16
|
+
activationUrl: string;
|
|
17
|
+
deviceSecret: string;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
pollIntervalSeconds: number;
|
|
20
|
+
}
|
|
21
|
+
/** Step 1: create one device authorization. */
|
|
22
|
+
export declare function startOpenDesignDeviceAuth(fetchFn: typeof fetch, { apiBase, host, signal, timeoutMs, }: {
|
|
23
|
+
apiBase?: string;
|
|
24
|
+
host: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
}): Promise<OpenDesignDeviceAuthorization>;
|
|
28
|
+
/** One poll verdict: still waiting, or the issued credential pair. */
|
|
29
|
+
export type OpenDesignDevicePoll = {
|
|
30
|
+
pending: true;
|
|
31
|
+
} | {
|
|
32
|
+
pending: false;
|
|
33
|
+
credentials: OpenDesignOAuthCredentials;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Step 3: one poll of the device grant.
|
|
37
|
+
*
|
|
38
|
+
* Completion is read from the payload's SHAPE: `runtimeKey`/`controlKey`
|
|
39
|
+
* present means approved, whatever `status` says; a non-pending status with no
|
|
40
|
+
* keys is a refusal (denied or expired), reported with the service's own words.
|
|
41
|
+
*/
|
|
42
|
+
export declare function pollOpenDesignDevice(fetchFn: typeof fetch, authorization: Pick<OpenDesignDeviceAuthorization, 'deviceId' | 'deviceSecret'>, { apiBase, signal, timeoutMs, }?: {
|
|
43
|
+
apiBase?: string;
|
|
44
|
+
signal?: AbortSignal;
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
}): Promise<OpenDesignDevicePoll>;
|
|
47
|
+
/** One login flow, as the settings card renders it. */
|
|
48
|
+
export type OpenDesignLoginStatus = 'idle' | 'pending' | 'complete' | 'failed' | 'cancelled';
|
|
49
|
+
export interface OpenDesignLoginFlow {
|
|
50
|
+
id: string;
|
|
51
|
+
status: OpenDesignLoginStatus;
|
|
52
|
+
userCode: string;
|
|
53
|
+
verificationUri: string;
|
|
54
|
+
expiresAt: number;
|
|
55
|
+
intervalSeconds: number;
|
|
56
|
+
error: string;
|
|
57
|
+
accountAlias: string;
|
|
58
|
+
}
|
|
59
|
+
export interface OpenDesignLoginOptions {
|
|
60
|
+
fetchFn: typeof fetch;
|
|
61
|
+
/** AMR control-plane base; a test seam and a deployment override. */
|
|
62
|
+
apiBase?: string;
|
|
63
|
+
/** This machine's name, recorded on the authorization the console lists. */
|
|
64
|
+
host(): string;
|
|
65
|
+
/** Persist a newly signed-in account; throws make the flow fail. */
|
|
66
|
+
onLogin(credentials: OpenDesignOAuthCredentials): Promise<void>;
|
|
67
|
+
logger?: {
|
|
68
|
+
warn(message: string, ...args: unknown[]): void;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* One device-authorization sign-in at a time.
|
|
73
|
+
*
|
|
74
|
+
* Polling is driven by the card (`GET /login/status`): each request makes at
|
|
75
|
+
* most one AMR call, and only after the advertised interval has elapsed. A host
|
|
76
|
+
* restart therefore loses the pending flow rather than keeping a poll loop
|
|
77
|
+
* alive with no reader — the same contract the sibling lines use.
|
|
78
|
+
*/
|
|
79
|
+
export declare class OpenDesignLoginManager {
|
|
80
|
+
private readonly options;
|
|
81
|
+
private flow;
|
|
82
|
+
private sequence;
|
|
83
|
+
constructor(options: OpenDesignLoginOptions);
|
|
84
|
+
/** Start a new flow, cancelling any previous one. */
|
|
85
|
+
begin({ signal }?: {
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
}): Promise<OpenDesignLoginFlow>;
|
|
88
|
+
/** The latest flow, or null when this process never started one. */
|
|
89
|
+
current(): OpenDesignLoginFlow | null;
|
|
90
|
+
/**
|
|
91
|
+
* Advance one flow and return its state.
|
|
92
|
+
*
|
|
93
|
+
* A flow the caller does not name is not advanced: two cards (or a stale one)
|
|
94
|
+
* cannot spend each other's polls.
|
|
95
|
+
*/
|
|
96
|
+
status(id: string, { signal, timeoutMs }?: {
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
}): Promise<OpenDesignLoginFlow>;
|
|
100
|
+
/** Abandon one flow; a late browser confirmation is then ignored. */
|
|
101
|
+
cancel(id: string): boolean;
|
|
102
|
+
/** Mark every flow cancelled for teardown. */
|
|
103
|
+
dispose(): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/oauth.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAQlE,8DAA8D;AAC9D,qBAAa,oBAAqB,SAAQ,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IAIrC;;;;;OAKG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA0DhI,qEAAqE;IACrE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAQ3B,8CAA8C;IAC9C,OAAO,IAAI,IAAI;CAKhB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OpenDesign settings API.
|
|
3
|
+
*
|
|
4
|
+
* The surface is the one every sibling line exposes — status, accounts, models —
|
|
5
|
+
* plus the controls this line genuinely has: device-authorization sign-in, an
|
|
6
|
+
* explicit catalog sync, and the wallet-balance read an OAuth account's control
|
|
7
|
+
* key can make.
|
|
8
|
+
*
|
|
9
|
+
* Reads never trigger an upstream call; the catalog is synced by its own action
|
|
10
|
+
* and behind a successful sign-in, and quota is refreshed by its own action.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-chatgpt-subscription/opendesign-routes
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
import type { OpenDesignAccountPool } from './account-pool.ts';
|
|
16
|
+
import { type OpenDesignModelSettingsStore } from './token-store.ts';
|
|
17
|
+
import type { OpenDesignLoginManager } from './oauth.ts';
|
|
18
|
+
import { openPlatformBrowser } from '../step-code/routes.ts';
|
|
19
|
+
import { type OpenDesignUsageAccountDto, type OpenDesignWebStatus } from '../../shared/opendesign-contracts.ts';
|
|
20
|
+
export interface OpenDesignRouteOptions {
|
|
21
|
+
settings: OpenDesignModelSettingsStore;
|
|
22
|
+
accountPool: OpenDesignAccountPool;
|
|
23
|
+
/** Proxy-aware fetch for account verification, quota reads and catalog syncs. */
|
|
24
|
+
fetchFn: typeof fetch;
|
|
25
|
+
/** Device-authorization sign-in state, when the composition installed one. */
|
|
26
|
+
login?: OpenDesignLoginManager;
|
|
27
|
+
/**
|
|
28
|
+
* Browser opener for `/login/start`; defaults to a no-op because the settings
|
|
29
|
+
* card opens the activation URL itself via `window.open`.
|
|
30
|
+
*/
|
|
31
|
+
openBrowser?: (url: string) => void;
|
|
32
|
+
serving(): boolean;
|
|
33
|
+
conflict(): string | null;
|
|
34
|
+
}
|
|
35
|
+
/** Named browser opener for deployments that want the host to launch the activation URL. */
|
|
36
|
+
export declare const openOpenDesignBrowser: typeof openPlatformBrowser;
|
|
37
|
+
/**
|
|
38
|
+
* Latest wallet readings, in-process only.
|
|
39
|
+
*
|
|
40
|
+
* A reading is a snapshot, not a stream: a restart starts blank rather than
|
|
41
|
+
* serving a stale figure as if fresh, and a failed refresh keeps the previous
|
|
42
|
+
* one with its error attached (the card shows both).
|
|
43
|
+
*/
|
|
44
|
+
interface UsageStore {
|
|
45
|
+
readings: Map<string, OpenDesignUsageAccountDto>;
|
|
46
|
+
fetchedAt: number;
|
|
47
|
+
}
|
|
48
|
+
/** Assemble the whole status payload the OpenDesign tab renders. */
|
|
49
|
+
export declare function getOpenDesignWebStatus(options: OpenDesignRouteOptions, usageStore?: UsageStore): Promise<OpenDesignWebStatus>;
|
|
50
|
+
/** The route table, exported so the client and this file can be checked against each other. */
|
|
51
|
+
export declare const OPENDESIGN_ROUTES: {
|
|
52
|
+
readonly status: "GET";
|
|
53
|
+
readonly settings: "POST";
|
|
54
|
+
readonly accounts: "GET|POST";
|
|
55
|
+
readonly 'login/start': "POST";
|
|
56
|
+
readonly 'login/status': "GET";
|
|
57
|
+
readonly 'login/cancel': "POST";
|
|
58
|
+
readonly models: "GET|POST";
|
|
59
|
+
readonly 'models/visibility': "POST";
|
|
60
|
+
readonly 'models/visibility-all': "POST";
|
|
61
|
+
readonly 'models/context-window': "POST";
|
|
62
|
+
readonly 'catalog/refresh': "POST";
|
|
63
|
+
readonly usage: "GET|POST";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Register the OpenDesign settings API under `/opendesign/api`.
|
|
67
|
+
*
|
|
68
|
+
* Registered unconditionally: the card is how a user adds their first key, so
|
|
69
|
+
* gating it on winning the route would leave a contested id with no way to
|
|
70
|
+
* configure it at all.
|
|
71
|
+
*/
|
|
72
|
+
export declare function registerOpenDesignRoutes(ctx: Context, options: OpenDesignRouteOptions): () => void;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../../src/host/opendesign/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAKL,KAAK,4BAA4B,EAClC,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAOL,KAAK,yBAAyB,EAE9B,KAAK,mBAAmB,EACzB,MAAM,sCAAsC,CAAA;AAsG7C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,4BAA4B,CAAA;IACtC,WAAW,EAAE,qBAAqB,CAAA;IAClC,iFAAiF;IACjF,OAAO,EAAE,OAAO,KAAK,CAAA;IACrB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,OAAO,IAAI,OAAO,CAAA;IAClB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,4BAAsB,CAAA;AAExD;;;;;;GAMG;AACH,UAA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