dsh-opencode-go 0.1.22 → 0.1.24

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 (37) hide show
  1. package/LICENSE +1 -0
  2. package/README.en.md +70 -147
  3. package/README.md +70 -145
  4. package/THIRD_PARTY_NOTICES.md +6 -2
  5. package/docs/advanced.en.md +137 -0
  6. package/docs/advanced.md +135 -0
  7. package/docs/assets/accounts.png +0 -0
  8. package/docs/assets/advanced-settings.png +0 -0
  9. package/docs/assets/model-settings.png +0 -0
  10. package/docs/assets/usage-panel.png +0 -0
  11. package/docs/development.md +17 -3
  12. package/docs/verification.md +183 -0
  13. package/lib/build-info.json +1 -1
  14. package/lib/client.js +456 -410
  15. package/lib/index.js +50626 -5092
  16. package/lib/types/account-manager.d.ts +2 -0
  17. package/lib/types/accounts.d.ts +3 -1
  18. package/lib/types/adapter.d.ts +5 -3
  19. package/lib/types/catalog.d.ts +1 -1
  20. package/lib/types/client/accounts-controller.d.ts +2 -0
  21. package/lib/types/client/hint-mark.d.ts +17 -0
  22. package/lib/types/client/host-primitives.d.ts +11 -0
  23. package/lib/types/client/locales.d.ts +5 -3
  24. package/lib/types/client/section-controller.d.ts +0 -2
  25. package/lib/types/config-contract.d.ts +3 -2
  26. package/lib/types/config.d.ts +1 -1
  27. package/lib/types/conversion/stream.d.ts +2 -1
  28. package/lib/types/gateway-diagnostics.d.ts +1 -0
  29. package/lib/types/gateway-url.d.ts +6 -0
  30. package/lib/types/google-fetch.d.ts +6 -0
  31. package/lib/types/google-generative-ai.d.ts +3 -0
  32. package/lib/types/index.d.ts +1 -1
  33. package/lib/types/model-metadata.d.ts +2 -2
  34. package/lib/types/request-budget.d.ts +12 -0
  35. package/lib/types/sdk-types.d.ts +1893 -305
  36. package/lib/vendor-licenses.txt +1760 -2
  37. package/package.json +3 -2
@@ -17,6 +17,8 @@ export declare class GoAccountManager {
17
17
  recover(): Promise<void>;
18
18
  private row;
19
19
  private run;
20
+ /** Preserve an old selection by moving it first in the same revision-guarded write. */
21
+ private normalizeOrder;
20
22
  private complete;
21
23
  private enqueue;
22
24
  execute(raw: AccountCommand): Promise<SettingsWriteResult>;
@@ -19,7 +19,9 @@ export interface AccountSettings {
19
19
  accountOperations?: readonly GoAccountOperation[];
20
20
  }
21
21
  export declare function accountRefOf(settings: AccountSettings): string;
22
- /** Include an externally selected reference without rewriting existing configuration. */
22
+ /** Promote one account while preserving every other account's relative order. */
23
+ export declare function moveAccountFirst(accounts: readonly GoAccount[], ref: string): readonly GoAccount[];
24
+ /** Read legacy selections as the first account until the host persists their order. */
23
25
  export declare function accountsOf(settings: AccountSettings): readonly GoAccount[];
24
26
  export declare function assertAccounts(accounts: readonly GoAccount[] | null | undefined, selectedRef?: string): void;
25
27
  /** Safe UI notice for a successful request using a fallback account. */
@@ -85,7 +85,7 @@ export interface OpencodeGoAdapterOptions {
85
85
  onReplayDegrade?: (reason: string) => void;
86
86
  /** Re-read picker models after a background catalog refresh commits. */
87
87
  onCatalogRefresh?: () => void;
88
- /** Host account-state version, captured before asynchronous model discovery. */
88
+ /** Host account-state version for actual requests, captured before asynchronous model discovery. */
89
89
  accountGeneration?: () => number;
90
90
  /** One outcome for both the displayed notice and the persisted selection. */
91
91
  onAccountSettled?: (event: GoAccountSettlement) => void;
@@ -103,6 +103,8 @@ export declare class OpencodeGoAdapter extends LlmAdapter {
103
103
  private readonly transport;
104
104
  /** Per-reference rejection deadlines, isolated by the gateway that rejected it. */
105
105
  private readonly rejectedKeys;
106
+ /** Reference updates invalidate rejections from attempts using an older key. */
107
+ private readonly credentialVersions;
106
108
  /** Monotonic sequence of the latest request this adapter started. */
107
109
  private callSeq;
108
110
  constructor(options: OpencodeGoAdapterOptions);
@@ -122,13 +124,13 @@ export declare class OpencodeGoAdapter extends LlmAdapter {
122
124
  listModels(_provider: string): Promise<readonly LlmModelInfo[]>;
123
125
  resolveModel(_provider: string, model: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
124
126
  /** Capture limits and protocol before discovery can yield to a settings update. */
125
- private callSnapshot;
127
+ private modelSnapshot;
126
128
  /** Keep capability resolution and eventual dispatch on the same configuration. */
127
129
  prepareCall(_provider: string, model: string, signal?: AbortSignal): Promise<{
128
130
  model: LlmResolvedModelInfo;
129
131
  stream: (options: GenerateOptions) => AsyncIterable<StreamChunk>;
130
132
  }>;
131
- /** Describe one model: capacities plus the reasoning levels it actually offers. */
133
+ /** Report the same default allowance used by dispatch so the host can budget compaction. */
132
134
  private modelInfo;
133
135
  /** Validate an explicit effort against the model's own levels, without clamping. */
134
136
  private resolveReasoningLevel;
@@ -3,7 +3,7 @@ import type { LlmDiscoveredModel } from '@deepseek-ai/dsh-llm';
3
3
  import { type GoModelCatalog } from './models-contract.ts';
4
4
  import type { ModelMetadata } from './model-metadata.ts';
5
5
  export { PROVIDER_ID, DISPLAY_NAME } from './provider-identity.ts';
6
- export declare const DEFAULT_BASE_URL = "https://opencode.ai/zen/go/v1";
6
+ export { DEFAULT_BASE_URL } from './gateway-url.ts';
7
7
  export interface CatalogSnapshot {
8
8
  readonly details: ModelMetadata['details'];
9
9
  readonly models: ReadonlyMap<string, Model<Api>>;
@@ -28,6 +28,8 @@ export interface GoAccountsState {
28
28
  export interface GoAccountsActions {
29
29
  loadAccounts: () => void;
30
30
  addAccount: (name: string, key: string) => Promise<boolean>;
31
+ /** A newly opened addition form owns a fresh ID; retries keep its existing ID. */
32
+ resetAddition?: () => void;
31
33
  renameAccount: (ref: string, name: string) => Promise<boolean>;
32
34
  removeAccount: (ref: string) => Promise<boolean>;
33
35
  selectAccount: (ref: string) => Promise<boolean>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The hint mark a label carries and the sentence behind it.
3
+ *
4
+ * The Host's own Tooltip opens the sentence on hover and on keyboard focus, while
5
+ * the same sentence stays in the document so assistive technology reads it without
6
+ * opening anything. A Host that ships no question glyph still gets a mark, and a
7
+ * Host with no Tooltip keeps the sentence visible instead of hiding it.
8
+ */
9
+ /** A focusable help trigger; fields also retain their {@link HintText} description. */
10
+ export declare function HintMark(props: {
11
+ hint: string;
12
+ }): import("react").JSX.Element;
13
+ /** The hint sentence, at the id a control points its `aria-describedby` at. */
14
+ export declare function HintText(props: {
15
+ id: string;
16
+ hint: string;
17
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Host UI atoms this page reaches for across DSH generations.
3
+ *
4
+ * Icon names moved from pixel size (`IconQuestionOutline14`, DSH 0.1.6 and older) to
5
+ * stroke weight (`IconQuestionOutlineRegular`, 0.1.7 and later), and the old alias is
6
+ * gone in 0.2. A missing atom is not a cosmetic loss here: React throws on an
7
+ * undefined element type, which takes the whole settings surface down with it, so
8
+ * every lookup resolves the current name first and keeps the older one behind it.
9
+ */
10
+ /** The atom's component, or undefined when this Host ships neither name. */
11
+ export declare function hostAtom<T>(host: Record<string, unknown>, current: string, previous: string): T | undefined;
@@ -136,8 +136,12 @@ export declare const en: {
136
136
  limitsEmpty: string;
137
137
  limitsContextLabel: string;
138
138
  limitsOutputLabel: string;
139
- advancedSummary: string;
139
+ advancedResetAll: string;
140
140
  advancedLabel: string;
141
+ groupUsageProtocol: string;
142
+ groupConnection: string;
143
+ groupCacheTimeouts: string;
144
+ groupImages: string;
141
145
  advancedHint: string;
142
146
  usageDisplayLabel: string;
143
147
  usageDisplayHint: string;
@@ -148,8 +152,6 @@ export declare const en: {
148
152
  protocolOverridesHint: string;
149
153
  protocolOverridesAuto: string;
150
154
  protocolOverridesResponses: string;
151
- apiKeyEnvLabel: string;
152
- apiKeyEnvHint: string;
153
155
  baseURLLabel: string;
154
156
  baseURLHint: string;
155
157
  proxyURLLabel: string;
@@ -63,8 +63,6 @@ export interface OpencodeGoSectionState extends FormShell {
63
63
  modelVisibility: Readonly<Record<string, boolean>>;
64
64
  pickerSaving: boolean;
65
65
  pickerFailed: boolean;
66
- /** Credential reference naming the environment key. */
67
- apiKeyEnv: FieldState;
68
66
  /** The gateway endpoint. */
69
67
  baseURL: FieldState;
70
68
  proxyURL: FieldState;
@@ -36,13 +36,14 @@ export interface OpencodeGoConfig {
36
36
  modelVisibility?: Record<string, boolean>;
37
37
  /** Experimental opt-in routing; omitted/null entries follow the catalog. */
38
38
  protocolOverrides?: GoProtocolOverrides;
39
- /** Credential reference: the environment variable the key resolves from. */
39
+ /** Legacy credential reference, kept in sync with the first/current account. */
40
40
  apiKeyEnv: string;
41
+ /** The first account is current; subsequent accounts are tried in order. */
41
42
  accounts?: GoAccount[] | null;
42
43
  accountOperations?: GoAccountOperation[];
43
44
  /** Try other saved accounts on quota/credential rejection before any content is emitted. */
44
45
  autoSwitch?: boolean;
45
- /** The gateway endpoint; also the base of the live model listing. */
46
+ /** Shared gateway base for model discovery, inference and usage requests. */
46
47
  baseURL: string;
47
48
  /** Optional HTTP(S) or SOCKS5 proxy; blank uses the default network transport. */
48
49
  proxyURL: string;
@@ -35,7 +35,7 @@ export declare function readConfig(config: LiveConfig): OpencodeGoConfig;
35
35
  * the composition layer and as the settings section's write validator, so a
36
36
  * bad URL fails where it is written, never at first request.
37
37
  * @param raw - the configured base URL.
38
- * @returns the normalized base URL without trailing slashes.
38
+ * @returns the current gateway base URL without trailing slashes.
39
39
  */
40
40
  export declare function assertBaseURL(raw: string): string;
41
41
  /**
@@ -37,7 +37,8 @@ export declare function mapStopReason(message: AssistantMessage, contextWindow?:
37
37
  * in-band terminal error an aborted finish.
38
38
  * @param requestedModel - request model identity recorded for durable replay.
39
39
  * @param requestedProvider - DSH provider identity recorded for durable replay.
40
- * @returns the harness chunks, ending with `usage` then `finish`; throws
40
+ * @returns the harness chunks, ending with measured `usage` then `finish`;
41
+ * failures with no measured tokens omit usage to preserve context pressure. Throws
41
42
  * `LlmError` (`STREAM_CLOSED`) if the source ends without a terminal event.
42
43
  */
43
44
  export declare function toStreamChunks(events: AsyncIterable<AssistantMessageEvent>, contextWindow?: number, callerSignal?: AbortSignal, requestedModel?: string, requestedProvider?: string): AsyncGenerator<StreamChunk>;
@@ -13,6 +13,7 @@ export declare class GatewayDiagnostics {
13
13
  directory?: string;
14
14
  callId?: string;
15
15
  attempt?: number;
16
+ contextWindow?: number;
16
17
  onResponse?: (status: number, requestId?: string) => void;
17
18
  });
18
19
  private redact;
@@ -0,0 +1,6 @@
1
+ /** Public Go gateway shared by discovery, inference and usage. */
2
+ export declare const DEFAULT_BASE_URL = "https://opencode.ai/inference/go/v1";
3
+ /**
4
+ * Migrate the legacy official address before any request is constructed.
5
+ */
6
+ export declare function migrateGatewayBaseURL(baseURL: string): string;
@@ -0,0 +1,6 @@
1
+ export declare function withGoogleFetch<T>(options: {
2
+ fetch?: typeof globalThis.fetch;
3
+ headers?: Record<string, string | null>;
4
+ } | undefined, request: () => T): T;
5
+ /** The pinned Google SDK's HTTP call uses this binding in builds and tests. */
6
+ export declare const googleFetch: typeof globalThis.fetch;
@@ -0,0 +1,3 @@
1
+ import type { SimpleStreamOptions, StreamFunction } from './sdk-types.ts';
2
+ export declare const stream: StreamFunction<'google-generative-ai'>;
3
+ export declare const streamSimple: StreamFunction<'google-generative-ai', SimpleStreamOptions>;
@@ -17,7 +17,7 @@
17
17
  * config:
18
18
  * enabled: true # false withdraws the route; the plugin stays mounted
19
19
  * apiKeyEnv: OPENCODE_API_KEY # default
20
- * baseURL: https://opencode.ai/zen/go/v1 # default
20
+ * baseURL: https://opencode.ai/inference/go/v1 # default
21
21
  * refreshMinutes: 60 # live catalog re-resolution interval
22
22
  * ```
23
23
  *
@@ -1,4 +1,4 @@
1
- /** Convert OpenCode's online models.dev metadata into the SDK's three wire protocols. */
1
+ /** Convert OpenCode's online models.dev metadata into the supported SDK wire protocols. */
2
2
  import type { Api, Model } from './sdk-types.ts';
3
3
  import { type GoModel } from './models-contract.ts';
4
4
  export declare const MODEL_METADATA_URL = "https://models.dev/api.json";
@@ -9,7 +9,7 @@ export interface ModelMetadata {
9
9
  readonly details: ReadonlyMap<string, ModelDetails>;
10
10
  readonly errors: ReadonlyMap<string, string>;
11
11
  }
12
- /** Anthropic's SDK appends /v1/messages; the OpenAI SDKs append paths below /v1. */
12
+ /** Use the current gateway for every protocol, then normalize SDK paths. */
13
13
  export declare function modelBaseURL(api: Api, baseURL: string): string;
14
14
  /** Shared Responses defaults for declared models and explicit protocol overrides. */
15
15
  export declare function responsesCompatibility(): NonNullable<Model<'openai-responses'>['compat']>;
@@ -0,0 +1,12 @@
1
+ /** Output allowance shared by model resolution and request dispatch. */
2
+ import type { OpencodeGoModelLimits } from './config-contract.ts';
3
+ /**
4
+ * Reserve 64k by default only for deepseek-v4.1-flash. Other models retain the
5
+ * SDK's default when neither the caller nor settings specify an allowance.
6
+ * Per-model settings continue to cap caller values for every model. The model
7
+ * has already had capacity overrides applied.
8
+ */
9
+ export declare function requestMaxTokens(model: {
10
+ id: string;
11
+ maxTokens: number;
12
+ }, limits: OpencodeGoModelLimits, requested?: number): number | undefined;