opencode-next 1.0.1 → 1.0.3
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/lib/client.js +9 -2
- package/lib/config.js +7 -3
- package/lib/constants.js +1 -0
- package/lib/go/adapter.js +2 -2
- package/lib/index.js +1 -0
- package/lib/ui.js +58 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -22,8 +22,15 @@ export function canonicalSessionId(signal = '') {
|
|
|
22
22
|
if (typeof signal === 'string' && CANONICAL_SESSION_PATTERN.test(signal)) {
|
|
23
23
|
return signal;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const hasSignal = signal !== undefined && signal !== null && String(signal) !== '';
|
|
26
|
+
const seed = hasSignal ? String(signal) : `${Date.now()}:${Math.random()}`;
|
|
27
|
+
const sum = crypto.createHash("sha256").update("ses\0" + seed).digest();
|
|
28
|
+
// Deterministic epoch-bounded timestamp when a session signal is given, so the same session
|
|
29
|
+
// never drifts across 1ms clock boundaries between turns or tests.
|
|
30
|
+
const tsMs = hasSignal
|
|
31
|
+
? 1700000000000 + (sum.readUInt32BE(0) % 100000000000)
|
|
32
|
+
: Date.now();
|
|
33
|
+
return `ses_${invertedTimestampHex(tsMs)}${base62Fixed(BigInt("0x" + sum.subarray(6, 16).toString("hex")), 14)}`;
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
export function randomId(prefix = 'req', length = 16) {
|
package/lib/config.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
GO_CREDENTIAL_ENV_VAR,
|
|
7
7
|
OPENCODE_INFERENCE_URL,
|
|
8
8
|
DEFAULT_STREAM_IDLE_MS,
|
|
9
|
+
GO_DEFAULT_FIRST_EVENT_MS,
|
|
9
10
|
DEFAULT_PROBE_INTERVAL_MS,
|
|
10
11
|
DEFAULT_CATALOG_POLL_MS,
|
|
11
12
|
DEFAULT_IMAGE_PIXEL_BUDGET,
|
|
@@ -148,13 +149,15 @@ export const Config = Schema.object({
|
|
|
148
149
|
providerId: Schema.string().default(GO_PROVIDER),
|
|
149
150
|
providerName: Schema.string().default(GO_PROVIDER_NAME),
|
|
150
151
|
credentialRef: Schema.string().default(GO_CREDENTIAL_ENV_VAR),
|
|
151
|
-
cachePath: Schema.string().default('')
|
|
152
|
+
cachePath: Schema.string().default(''),
|
|
153
|
+
firstEventTimeoutMs: Schema.number().min(1000).default(GO_DEFAULT_FIRST_EVENT_MS)
|
|
152
154
|
}).default({
|
|
153
155
|
enabled: true,
|
|
154
156
|
providerId: GO_PROVIDER,
|
|
155
157
|
providerName: GO_PROVIDER_NAME,
|
|
156
158
|
credentialRef: GO_CREDENTIAL_ENV_VAR,
|
|
157
|
-
cachePath: ''
|
|
159
|
+
cachePath: '',
|
|
160
|
+
firstEventTimeoutMs: GO_DEFAULT_FIRST_EVENT_MS
|
|
158
161
|
}).description('Independent OpenCode Go subscription provider (enabled by default; set enabled: false to disable). Resolves the Console Personal API Key via DSH credential service or environment variable; never stores raw API keys.')
|
|
159
162
|
});
|
|
160
163
|
|
|
@@ -194,7 +197,8 @@ export function resolveConfig(raw = {}) {
|
|
|
194
197
|
providerId: raw.goSubscription?.providerId || GO_PROVIDER,
|
|
195
198
|
providerName: raw.goSubscription?.providerName || GO_PROVIDER_NAME,
|
|
196
199
|
credentialRef: raw.goSubscription?.credentialRef || GO_CREDENTIAL_ENV_VAR,
|
|
197
|
-
cachePath: raw.goSubscription?.cachePath || ''
|
|
200
|
+
cachePath: raw.goSubscription?.cachePath || '',
|
|
201
|
+
firstEventTimeoutMs: Number(raw.goSubscription?.firstEventTimeoutMs) || GO_DEFAULT_FIRST_EVENT_MS
|
|
198
202
|
}
|
|
199
203
|
};
|
|
200
204
|
}
|
package/lib/constants.js
CHANGED
package/lib/go/adapter.js
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
|
-
DEFAULT_FIRST_EVENT_MS,
|
|
16
15
|
DEFAULT_IMAGE_MAX_BYTES,
|
|
17
16
|
DEFAULT_IMAGE_PIXEL_BUDGET,
|
|
18
17
|
DEFAULT_STREAM_IDLE_MS,
|
|
18
|
+
GO_DEFAULT_FIRST_EVENT_MS,
|
|
19
19
|
GO_PROVIDER,
|
|
20
20
|
GO_PROVIDER_NAME
|
|
21
21
|
} from '../constants.js';
|
|
@@ -414,7 +414,7 @@ export class OpenCodeGoAdapter {
|
|
|
414
414
|
#firstEventMs() {
|
|
415
415
|
const configured = Number(this.#config.firstEventTimeoutMs);
|
|
416
416
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
417
|
-
return Math.
|
|
417
|
+
return Math.max(GO_DEFAULT_FIRST_EVENT_MS, this.#idleMs());
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
#pixelBudget() {
|
package/lib/index.js
CHANGED
|
@@ -128,6 +128,7 @@ export function apply(ctx, config) {
|
|
|
128
128
|
providerId: goProviderId,
|
|
129
129
|
providerName: goConfig.providerName || GO_PROVIDER_NAME,
|
|
130
130
|
streamIdleTimeoutMs: resolved.streamIdleTimeoutMs,
|
|
131
|
+
firstEventTimeoutMs: goConfig.firstEventTimeoutMs,
|
|
131
132
|
resolveAttachments,
|
|
132
133
|
imagePixelBudget: resolved.imagePixelBudget,
|
|
133
134
|
imageMaxBytes: resolved.imageMaxBytes
|
package/lib/ui.js
CHANGED
|
@@ -4567,6 +4567,64 @@ window.__ModuleLoader__.load({
|
|
|
4567
4567
|
這樣無論宿主語言是什麼,那一行都是可預期的。 */
|
|
4568
4568
|
const navLabel = 'OpenCode-Next';
|
|
4569
4569
|
|
|
4570
|
+
// 設定左側導覽列圖示裝飾器:把 DSH 預設的齒輪圖示換成 OpenCode-Next 專屬標誌。
|
|
4571
|
+
const NAV_ICON_SVG =
|
|
4572
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="76 76 360 360" width="16" height="16" fill="none" data-ocn-nav="1" style="flex:none;vertical-align:middle;">' +
|
|
4573
|
+
'<defs>' +
|
|
4574
|
+
'<linearGradient id="ocn-nav-gRing" gradientUnits="userSpaceOnUse" x1="0" y1="158" x2="0" y2="354">' +
|
|
4575
|
+
'<stop offset="0" stop-color="#A8B5C8"/>' +
|
|
4576
|
+
'<stop offset="1" stop-color="#5B6B82"/>' +
|
|
4577
|
+
'</linearGradient>' +
|
|
4578
|
+
'<linearGradient id="ocn-nav-gChev" x1="0" y1="0" x2="1" y2="1">' +
|
|
4579
|
+
'<stop offset="0" stop-color="#06B6D4"/>' +
|
|
4580
|
+
'<stop offset="1" stop-color="#2563EB"/>' +
|
|
4581
|
+
'</linearGradient>' +
|
|
4582
|
+
'<mask id="ocn-nav-cut" maskUnits="userSpaceOnUse" x="0" y="0" width="512" height="512">' +
|
|
4583
|
+
'<rect width="512" height="512" fill="#fff"/>' +
|
|
4584
|
+
'<path d="M377.15 200.85 A78 78 0 1 0 377.15 311.15" fill="none" stroke="#000" stroke-width="64" stroke-linecap="round"/>' +
|
|
4585
|
+
'</mask>' +
|
|
4586
|
+
'</defs>' +
|
|
4587
|
+
'<g transform="translate(256 256) scale(1.12) translate(-256 -256)">' +
|
|
4588
|
+
'<g transform="translate(11 0)">' +
|
|
4589
|
+
'<circle cx="190" cy="256" r="78" fill="none" stroke="url(#ocn-nav-gRing)" stroke-width="40" mask="url(#ocn-nav-cut)"/>' +
|
|
4590
|
+
'<path d="M377.15 200.85 A78 78 0 1 0 377.15 311.15" fill="none" stroke="url(#ocn-nav-gRing)" stroke-width="40" stroke-linecap="round"/>' +
|
|
4591
|
+
'<path d="M334 234 L356 256 L334 278" fill="none" stroke="url(#ocn-nav-gChev)" stroke-width="16" stroke-linecap="round" stroke-linejoin="round"/>' +
|
|
4592
|
+
'</g>' +
|
|
4593
|
+
'</g>' +
|
|
4594
|
+
'</svg>';
|
|
4595
|
+
|
|
4596
|
+
function patchNavIcon() {
|
|
4597
|
+
if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return;
|
|
4598
|
+
if (!document.querySelector('[role="dialog"]')) return;
|
|
4599
|
+
for (const span of document.querySelectorAll('span')) {
|
|
4600
|
+
if (span.textContent && span.textContent.trim() === navLabel) {
|
|
4601
|
+
const btn = span.closest('button');
|
|
4602
|
+
if (btn) {
|
|
4603
|
+
const svg = btn.querySelector('svg');
|
|
4604
|
+
if (svg && svg.dataset.ocnNav !== '1') {
|
|
4605
|
+
svg.outerHTML = NAV_ICON_SVG;
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
}
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
|
|
4612
|
+
if (typeof window !== 'undefined' && typeof window.setInterval === 'function') {
|
|
4613
|
+
const timer = window.setInterval(patchNavIcon, 400);
|
|
4614
|
+
const onClick = () => queueMicrotask(patchNavIcon);
|
|
4615
|
+
if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
|
|
4616
|
+
document.addEventListener('click', onClick, true);
|
|
4617
|
+
}
|
|
4618
|
+
if (typeof ctx.effect === 'function') {
|
|
4619
|
+
ctx.effect(() => () => {
|
|
4620
|
+
window.clearInterval?.(timer);
|
|
4621
|
+
if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
|
|
4622
|
+
document.removeEventListener('click', onClick, true);
|
|
4623
|
+
}
|
|
4624
|
+
}, 'opencode-next: nav icon timer');
|
|
4625
|
+
}
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4570
4628
|
ctx.slots.inject('settings.section', () =>
|
|
4571
4629
|
ctx.slots.register(
|
|
4572
4630
|
{
|