opensteer 0.5.4 → 0.5.6
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 +6 -0
- package/README.md +2 -0
- package/bin/opensteer.mjs +163 -38
- package/dist/{chunk-YIQDOALV.js → chunk-AVXUMEDG.js} +3 -2
- package/dist/{chunk-SPHS6YWD.js → chunk-DN3GI5CH.js} +3 -2
- package/dist/{chunk-QHZFY3ZK.js → chunk-FAHE5DB2.js} +79 -20
- package/dist/{chunk-XIH3WGPY.js → chunk-SGZYTGY3.js} +232 -22
- package/dist/cli/server.cjs +353 -58
- package/dist/cli/server.js +42 -16
- package/dist/{extractor-CZFCFUME.js → extractor-4Q3TFZJB.js} +2 -2
- package/dist/index.cjs +316 -43
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +8 -4
- package/dist/{resolver-ZREUOOTV.js → resolver-MGN64KCP.js} +2 -2
- package/package.json +2 -2
- package/skills/opensteer/SKILL.md +92 -99
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
health checks to remove startup races across concurrent commands.
|
|
15
15
|
- Added strict in-daemon request serialization for session commands, while
|
|
16
16
|
keeping `ping` out of the queue for reliable liveness checks.
|
|
17
|
+
- Breaking: CLI daemon routing is now scoped by canonical `cwd`
|
|
18
|
+
(`realpath(cwd)`) + logical session (`--session`/`OPENSTEER_SESSION`) rather
|
|
19
|
+
than machine-wide session id matching; the same logical session can run in
|
|
20
|
+
parallel across different directories.
|
|
17
21
|
- Breaking: removed legacy `ai` config from `OpensteerConfig`; use top-level `model` instead.
|
|
18
22
|
- Breaking: `OPENSTEER_AI_MODEL` is no longer supported; use `OPENSTEER_MODEL`.
|
|
19
23
|
- Breaking: `OPENSTEER_RUNTIME` is no longer supported; use `OPENSTEER_MODE`.
|
|
@@ -23,6 +27,8 @@
|
|
|
23
27
|
- Cloud mode now falls back to `OPENSTEER_API_KEY` when `cloud.apiKey` is omitted.
|
|
24
28
|
- Added automatic `.env` loading from `storage.rootDir` (default `process.cwd()`) so constructor config can consume env vars without requiring `import 'dotenv/config'`.
|
|
25
29
|
- `.env` autoload follows common precedence (`.env.<NODE_ENV>.local`, `.env.local`, `.env.<NODE_ENV>`, `.env`) with `.env.local` skipped in `test`, does not overwrite existing env values, and can be disabled via `OPENSTEER_DISABLE_DOTENV_AUTOLOAD`.
|
|
30
|
+
- Opensteer now reuses one resolved runtime env snapshot for config, CUA provider key resolution, and built-in AI resolve/extract provider setup; dotenv loading still does not mutate global `process.env`.
|
|
31
|
+
- AI helper exports now accept optional `env` maps (`getModelProvider`, `createResolveCallback`, `createExtractCallback`) for deterministic provider initialization without relying on ambient process env state.
|
|
26
32
|
- Mutating actions now include smart best-effort post-action wait with per-action
|
|
27
33
|
profiles and optional per-call overrides via `wait`.
|
|
28
34
|
- Added structured interaction diagnostics via `OpensteerActionError` for
|
package/README.md
CHANGED
|
@@ -111,6 +111,8 @@ opensteer close --session demo
|
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
For non-interactive runs, set `OPENSTEER_SESSION` or `OPENSTEER_CLIENT_ID`.
|
|
114
|
+
Runtime daemon routing for `OPENSTEER_SESSION` is scoped by canonical `cwd`
|
|
115
|
+
(`realpath(cwd)`) + logical session id.
|
|
114
116
|
|
|
115
117
|
## For AI Agents
|
|
116
118
|
|
package/bin/opensteer.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
closeSync,
|
|
7
7
|
existsSync,
|
|
8
8
|
openSync,
|
|
9
|
+
realpathSync,
|
|
9
10
|
readFileSync,
|
|
10
11
|
readdirSync,
|
|
11
12
|
unlinkSync,
|
|
@@ -55,11 +56,13 @@ const RUNTIME_PREFIX = 'opensteer-'
|
|
|
55
56
|
const SOCKET_SUFFIX = '.sock'
|
|
56
57
|
const PID_SUFFIX = '.pid'
|
|
57
58
|
const LOCK_SUFFIX = '.lock'
|
|
59
|
+
const METADATA_SUFFIX = '.meta.json'
|
|
58
60
|
const CLIENT_BINDING_PREFIX = `${RUNTIME_PREFIX}client-`
|
|
59
61
|
const CLIENT_BINDING_SUFFIX = '.session'
|
|
60
62
|
const CLOSE_ALL_REQUEST = { id: 1, command: 'close', args: {} }
|
|
61
63
|
const PING_REQUEST = { id: 1, command: 'ping', args: {} }
|
|
62
64
|
const SESSION_ID_PATTERN = /^[a-zA-Z0-9_-]+$/
|
|
65
|
+
const RUNTIME_SESSION_PREFIX = 'sc-'
|
|
63
66
|
|
|
64
67
|
function getVersion() {
|
|
65
68
|
try {
|
|
@@ -214,7 +217,20 @@ function isInteractiveTerminal() {
|
|
|
214
217
|
return Boolean(process.stdin.isTTY && process.stdout.isTTY)
|
|
215
218
|
}
|
|
216
219
|
|
|
217
|
-
function
|
|
220
|
+
function resolveScopeDir() {
|
|
221
|
+
const cwd = process.cwd()
|
|
222
|
+
try {
|
|
223
|
+
return realpathSync(cwd)
|
|
224
|
+
} catch {
|
|
225
|
+
return cwd
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function buildRuntimeSession(scopeDir, logicalSession) {
|
|
230
|
+
return `${RUNTIME_SESSION_PREFIX}${hashKey(`${scopeDir}:${logicalSession}`).slice(0, 24)}`
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function resolveSession(flags, scopeDir) {
|
|
218
234
|
if (flags.session !== undefined) {
|
|
219
235
|
if (flags.session === true) {
|
|
220
236
|
throw new Error('--session requires a session id value.')
|
|
@@ -244,7 +260,7 @@ function resolveSession(flags) {
|
|
|
244
260
|
process.env.OPENSTEER_CLIENT_ID.trim().length > 0
|
|
245
261
|
) {
|
|
246
262
|
const clientId = process.env.OPENSTEER_CLIENT_ID.trim()
|
|
247
|
-
const clientKey = `client:${
|
|
263
|
+
const clientKey = `client:${scopeDir}:${clientId}`
|
|
248
264
|
const bound = readClientBinding(clientKey)
|
|
249
265
|
if (bound) {
|
|
250
266
|
return { session: bound, source: 'client_binding' }
|
|
@@ -256,7 +272,7 @@ function resolveSession(flags) {
|
|
|
256
272
|
}
|
|
257
273
|
|
|
258
274
|
if (isInteractiveTerminal()) {
|
|
259
|
-
const ttyKey = `tty:${
|
|
275
|
+
const ttyKey = `tty:${scopeDir}:${process.ppid}`
|
|
260
276
|
const bound = readClientBinding(ttyKey)
|
|
261
277
|
if (bound) {
|
|
262
278
|
return { session: bound, source: 'tty_default' }
|
|
@@ -284,6 +300,10 @@ function getLockPath(session) {
|
|
|
284
300
|
return join(tmpdir(), `${RUNTIME_PREFIX}${session}${LOCK_SUFFIX}`)
|
|
285
301
|
}
|
|
286
302
|
|
|
303
|
+
function getMetadataPath(session) {
|
|
304
|
+
return join(tmpdir(), `${RUNTIME_PREFIX}${session}${METADATA_SUFFIX}`)
|
|
305
|
+
}
|
|
306
|
+
|
|
287
307
|
function buildRequest(command, flags, positional) {
|
|
288
308
|
const id = 1
|
|
289
309
|
const globalFlags = {}
|
|
@@ -430,20 +450,80 @@ function cleanStaleFiles(session, options = {}) {
|
|
|
430
450
|
unlinkSync(getPidPath(session))
|
|
431
451
|
} catch { }
|
|
432
452
|
}
|
|
453
|
+
|
|
454
|
+
try {
|
|
455
|
+
unlinkSync(getMetadataPath(session))
|
|
456
|
+
} catch { }
|
|
433
457
|
}
|
|
434
458
|
|
|
435
|
-
function startServer(
|
|
459
|
+
function startServer(runtimeSession, logicalSession, scopeDir) {
|
|
436
460
|
const child = spawn('node', [SERVER_SCRIPT], {
|
|
437
461
|
detached: true,
|
|
438
462
|
stdio: ['ignore', 'ignore', 'ignore'],
|
|
439
463
|
env: {
|
|
440
464
|
...process.env,
|
|
441
|
-
OPENSTEER_SESSION:
|
|
465
|
+
OPENSTEER_SESSION: runtimeSession,
|
|
466
|
+
OPENSTEER_LOGICAL_SESSION: logicalSession,
|
|
467
|
+
OPENSTEER_SCOPE_DIR: scopeDir,
|
|
442
468
|
},
|
|
443
469
|
})
|
|
444
470
|
child.unref()
|
|
445
471
|
}
|
|
446
472
|
|
|
473
|
+
function readMetadata(session) {
|
|
474
|
+
const metadataPath = getMetadataPath(session)
|
|
475
|
+
if (!existsSync(metadataPath)) {
|
|
476
|
+
return null
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
try {
|
|
480
|
+
const raw = JSON.parse(readFileSync(metadataPath, 'utf-8'))
|
|
481
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
482
|
+
return null
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (
|
|
486
|
+
typeof raw.logicalSession !== 'string' ||
|
|
487
|
+
!raw.logicalSession.trim() ||
|
|
488
|
+
typeof raw.scopeDir !== 'string' ||
|
|
489
|
+
!raw.scopeDir.trim() ||
|
|
490
|
+
typeof raw.runtimeSession !== 'string' ||
|
|
491
|
+
!raw.runtimeSession.trim()
|
|
492
|
+
) {
|
|
493
|
+
return null
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
logicalSession: raw.logicalSession.trim(),
|
|
498
|
+
scopeDir: raw.scopeDir,
|
|
499
|
+
runtimeSession: raw.runtimeSession.trim(),
|
|
500
|
+
createdAt:
|
|
501
|
+
typeof raw.createdAt === 'number' ? raw.createdAt : undefined,
|
|
502
|
+
updatedAt:
|
|
503
|
+
typeof raw.updatedAt === 'number' ? raw.updatedAt : undefined,
|
|
504
|
+
}
|
|
505
|
+
} catch {
|
|
506
|
+
return null
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function writeMetadata(runtimeSession, logicalSession, scopeDir) {
|
|
511
|
+
const metadataPath = getMetadataPath(runtimeSession)
|
|
512
|
+
const existing = readMetadata(runtimeSession)
|
|
513
|
+
const now = Date.now()
|
|
514
|
+
const payload = {
|
|
515
|
+
runtimeSession,
|
|
516
|
+
logicalSession,
|
|
517
|
+
scopeDir,
|
|
518
|
+
createdAt: existing?.createdAt ?? now,
|
|
519
|
+
updatedAt: now,
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
try {
|
|
523
|
+
writeFileSync(metadataPath, JSON.stringify(payload, null, 2))
|
|
524
|
+
} catch { }
|
|
525
|
+
}
|
|
526
|
+
|
|
447
527
|
function sendCommand(socketPath, request, timeoutMs = RESPONSE_TIMEOUT) {
|
|
448
528
|
return new Promise((resolve, reject) => {
|
|
449
529
|
const socket = connect(socketPath)
|
|
@@ -606,8 +686,14 @@ async function waitForServerReady(session, timeout) {
|
|
|
606
686
|
throw new Error(`Timed out waiting for server '${session}' to become healthy.`)
|
|
607
687
|
}
|
|
608
688
|
|
|
609
|
-
async function ensureServer(
|
|
610
|
-
|
|
689
|
+
async function ensureServer(context) {
|
|
690
|
+
const runtimeSession = context.runtimeSession
|
|
691
|
+
if (await isServerHealthy(runtimeSession)) {
|
|
692
|
+
writeMetadata(
|
|
693
|
+
runtimeSession,
|
|
694
|
+
context.logicalSession,
|
|
695
|
+
context.scopeDir
|
|
696
|
+
)
|
|
611
697
|
return
|
|
612
698
|
}
|
|
613
699
|
|
|
@@ -620,31 +706,45 @@ async function ensureServer(session) {
|
|
|
620
706
|
const deadline = Date.now() + CONNECT_TIMEOUT
|
|
621
707
|
|
|
622
708
|
while (Date.now() < deadline) {
|
|
623
|
-
if (await isServerHealthy(
|
|
709
|
+
if (await isServerHealthy(runtimeSession)) {
|
|
710
|
+
writeMetadata(
|
|
711
|
+
runtimeSession,
|
|
712
|
+
context.logicalSession,
|
|
713
|
+
context.scopeDir
|
|
714
|
+
)
|
|
624
715
|
return
|
|
625
716
|
}
|
|
626
717
|
|
|
627
|
-
const existingPid = readPid(getPidPath(
|
|
718
|
+
const existingPid = readPid(getPidPath(runtimeSession))
|
|
628
719
|
if (existingPid && isPidAlive(existingPid)) {
|
|
629
720
|
await sleep(POLL_INTERVAL)
|
|
630
721
|
continue
|
|
631
722
|
}
|
|
632
723
|
|
|
633
|
-
recoverStaleStartLock(
|
|
724
|
+
recoverStaleStartLock(runtimeSession)
|
|
634
725
|
|
|
635
|
-
if (acquireStartLock(
|
|
726
|
+
if (acquireStartLock(runtimeSession)) {
|
|
636
727
|
try {
|
|
637
|
-
if (!(await isServerHealthy(
|
|
638
|
-
startServer(
|
|
728
|
+
if (!(await isServerHealthy(runtimeSession))) {
|
|
729
|
+
startServer(
|
|
730
|
+
runtimeSession,
|
|
731
|
+
context.logicalSession,
|
|
732
|
+
context.scopeDir
|
|
733
|
+
)
|
|
639
734
|
}
|
|
640
735
|
|
|
641
736
|
await waitForServerReady(
|
|
642
|
-
|
|
737
|
+
runtimeSession,
|
|
643
738
|
Math.max(500, deadline - Date.now())
|
|
644
739
|
)
|
|
740
|
+
writeMetadata(
|
|
741
|
+
runtimeSession,
|
|
742
|
+
context.logicalSession,
|
|
743
|
+
context.scopeDir
|
|
744
|
+
)
|
|
645
745
|
return
|
|
646
746
|
} finally {
|
|
647
|
-
releaseStartLock(
|
|
747
|
+
releaseStartLock(runtimeSession)
|
|
648
748
|
}
|
|
649
749
|
}
|
|
650
750
|
|
|
@@ -652,7 +752,7 @@ async function ensureServer(session) {
|
|
|
652
752
|
}
|
|
653
753
|
|
|
654
754
|
throw new Error(
|
|
655
|
-
`Failed to start server for session '${
|
|
755
|
+
`Failed to start server for session '${context.logicalSession}' in cwd scope '${context.scopeDir}' within ${CONNECT_TIMEOUT}ms.`
|
|
656
756
|
)
|
|
657
757
|
}
|
|
658
758
|
|
|
@@ -665,24 +765,39 @@ function listSessions() {
|
|
|
665
765
|
continue
|
|
666
766
|
}
|
|
667
767
|
|
|
668
|
-
const
|
|
768
|
+
const runtimeSession = entry.slice(
|
|
669
769
|
RUNTIME_PREFIX.length,
|
|
670
770
|
entry.length - PID_SUFFIX.length
|
|
671
771
|
)
|
|
672
|
-
if (!
|
|
772
|
+
if (!runtimeSession) {
|
|
673
773
|
continue
|
|
674
774
|
}
|
|
675
775
|
|
|
676
776
|
const pid = readPid(join(tmpdir(), entry))
|
|
677
777
|
if (!pid || !isPidAlive(pid)) {
|
|
678
|
-
cleanStaleFiles(
|
|
778
|
+
cleanStaleFiles(runtimeSession)
|
|
679
779
|
continue
|
|
680
780
|
}
|
|
681
781
|
|
|
682
|
-
|
|
782
|
+
const metadata = readMetadata(runtimeSession)
|
|
783
|
+
sessions.push({
|
|
784
|
+
name: metadata?.logicalSession || runtimeSession,
|
|
785
|
+
logicalSession: metadata?.logicalSession || runtimeSession,
|
|
786
|
+
runtimeSession,
|
|
787
|
+
scopeDir: metadata?.scopeDir || null,
|
|
788
|
+
pid,
|
|
789
|
+
})
|
|
683
790
|
}
|
|
684
791
|
|
|
685
|
-
sessions.sort((a, b) =>
|
|
792
|
+
sessions.sort((a, b) => {
|
|
793
|
+
const scopeA = a.scopeDir || ''
|
|
794
|
+
const scopeB = b.scopeDir || ''
|
|
795
|
+
if (scopeA !== scopeB) {
|
|
796
|
+
return scopeA.localeCompare(scopeB)
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
return a.logicalSession.localeCompare(b.logicalSession)
|
|
800
|
+
})
|
|
686
801
|
return sessions
|
|
687
802
|
}
|
|
688
803
|
|
|
@@ -692,9 +807,9 @@ async function closeAllSessions() {
|
|
|
692
807
|
const failures = []
|
|
693
808
|
|
|
694
809
|
for (const session of sessions) {
|
|
695
|
-
const socketPath = getSocketPath(session.
|
|
810
|
+
const socketPath = getSocketPath(session.runtimeSession)
|
|
696
811
|
if (!existsSync(socketPath)) {
|
|
697
|
-
cleanStaleFiles(session.
|
|
812
|
+
cleanStaleFiles(session.runtimeSession)
|
|
698
813
|
continue
|
|
699
814
|
}
|
|
700
815
|
|
|
@@ -704,12 +819,12 @@ async function closeAllSessions() {
|
|
|
704
819
|
closed.push(session)
|
|
705
820
|
} else {
|
|
706
821
|
failures.push(
|
|
707
|
-
`${session.
|
|
822
|
+
`${session.logicalSession} (${session.scopeDir || 'unknown scope'}): ${response?.error || 'unknown close error'}`
|
|
708
823
|
)
|
|
709
824
|
}
|
|
710
825
|
} catch (err) {
|
|
711
826
|
failures.push(
|
|
712
|
-
`${session.
|
|
827
|
+
`${session.logicalSession} (${session.scopeDir || 'unknown scope'}): ${err instanceof Error ? err.message : String(err)}`
|
|
713
828
|
)
|
|
714
829
|
}
|
|
715
830
|
}
|
|
@@ -817,7 +932,7 @@ Navigation:
|
|
|
817
932
|
|
|
818
933
|
Sessions:
|
|
819
934
|
sessions List active session-scoped daemons
|
|
820
|
-
status Show resolved
|
|
935
|
+
status Show resolved logical/runtime session and session state
|
|
821
936
|
|
|
822
937
|
Observation:
|
|
823
938
|
snapshot [--mode action] Get page snapshot
|
|
@@ -868,7 +983,7 @@ Skills:
|
|
|
868
983
|
skills --help Show skills installer help
|
|
869
984
|
|
|
870
985
|
Global Flags:
|
|
871
|
-
--session <id>
|
|
986
|
+
--session <id> Logical session id (scoped by canonical cwd)
|
|
872
987
|
--name <namespace> Selector namespace for cache storage on 'open'
|
|
873
988
|
--headless Launch browser in headless mode
|
|
874
989
|
--connect-url <url> Connect to a running browser (e.g. http://localhost:9222)
|
|
@@ -881,7 +996,7 @@ Global Flags:
|
|
|
881
996
|
--version, -v Show version
|
|
882
997
|
|
|
883
998
|
Environment:
|
|
884
|
-
OPENSTEER_SESSION
|
|
999
|
+
OPENSTEER_SESSION Logical session id (equivalent to --session)
|
|
885
1000
|
OPENSTEER_CLIENT_ID Stable client identity for default session binding
|
|
886
1001
|
OPENSTEER_NAME Default selector namespace for 'open' when --name is omitted
|
|
887
1002
|
OPENSTEER_MODE Runtime routing: "local" (default) or "cloud"
|
|
@@ -925,27 +1040,37 @@ async function main() {
|
|
|
925
1040
|
|
|
926
1041
|
let resolvedSession
|
|
927
1042
|
let resolvedName
|
|
1043
|
+
const scopeDir = resolveScopeDir()
|
|
928
1044
|
try {
|
|
929
|
-
resolvedSession = resolveSession(flags)
|
|
1045
|
+
resolvedSession = resolveSession(flags, scopeDir)
|
|
930
1046
|
resolvedName = resolveName(flags, resolvedSession.session)
|
|
931
1047
|
} catch (err) {
|
|
932
1048
|
error(err instanceof Error ? err.message : 'Failed to resolve session')
|
|
933
1049
|
}
|
|
934
1050
|
|
|
935
|
-
const
|
|
1051
|
+
const logicalSession = resolvedSession.session
|
|
1052
|
+
const runtimeSession = buildRuntimeSession(scopeDir, logicalSession)
|
|
936
1053
|
const sessionSource = resolvedSession.source
|
|
937
1054
|
const name = resolvedName.name
|
|
938
1055
|
const nameSource = resolvedName.source
|
|
939
|
-
const socketPath = getSocketPath(
|
|
1056
|
+
const socketPath = getSocketPath(runtimeSession)
|
|
1057
|
+
const routingContext = {
|
|
1058
|
+
logicalSession,
|
|
1059
|
+
runtimeSession,
|
|
1060
|
+
scopeDir,
|
|
1061
|
+
}
|
|
940
1062
|
|
|
941
1063
|
if (command === 'status') {
|
|
942
1064
|
output({
|
|
943
1065
|
ok: true,
|
|
944
|
-
resolvedSession:
|
|
1066
|
+
resolvedSession: logicalSession,
|
|
1067
|
+
logicalSession,
|
|
1068
|
+
runtimeSession,
|
|
1069
|
+
scopeDir,
|
|
945
1070
|
sessionSource,
|
|
946
1071
|
resolvedName: name,
|
|
947
1072
|
nameSource,
|
|
948
|
-
serverRunning: await isServerHealthy(
|
|
1073
|
+
serverRunning: await isServerHealthy(runtimeSession),
|
|
949
1074
|
socketPath,
|
|
950
1075
|
sessions: listSessions(),
|
|
951
1076
|
})
|
|
@@ -961,20 +1086,20 @@ async function main() {
|
|
|
961
1086
|
request.args.name = name
|
|
962
1087
|
}
|
|
963
1088
|
|
|
964
|
-
if (!(await isServerHealthy(
|
|
1089
|
+
if (!(await isServerHealthy(runtimeSession))) {
|
|
965
1090
|
if (command !== 'open') {
|
|
966
1091
|
error(
|
|
967
|
-
`No server running for session '${
|
|
1092
|
+
`No server running for session '${logicalSession}' in cwd scope '${scopeDir}' (resolved from ${sessionSource}). Run 'opensteer open' first or use 'opensteer sessions' to see active sessions.`
|
|
968
1093
|
)
|
|
969
1094
|
}
|
|
970
1095
|
|
|
971
1096
|
try {
|
|
972
|
-
await ensureServer(
|
|
1097
|
+
await ensureServer(routingContext)
|
|
973
1098
|
} catch (err) {
|
|
974
1099
|
error(
|
|
975
1100
|
err instanceof Error
|
|
976
1101
|
? err.message
|
|
977
|
-
: `Failed to start server for session '${
|
|
1102
|
+
: `Failed to start server for session '${logicalSession}' in cwd scope '${scopeDir}'.`
|
|
978
1103
|
)
|
|
979
1104
|
}
|
|
980
1105
|
}
|
|
@@ -992,7 +1117,7 @@ async function main() {
|
|
|
992
1117
|
error(
|
|
993
1118
|
formatTransportFailure(
|
|
994
1119
|
err,
|
|
995
|
-
`Failed to run '${command}' for session '${
|
|
1120
|
+
`Failed to run '${command}' for session '${logicalSession}' in cwd scope '${scopeDir}'`
|
|
996
1121
|
)
|
|
997
1122
|
)
|
|
998
1123
|
}
|
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
buildExtractSystemPrompt,
|
|
6
6
|
buildExtractUserPrompt,
|
|
7
7
|
getModelProvider
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-FAHE5DB2.js";
|
|
9
9
|
|
|
10
10
|
// src/ai/extractor.ts
|
|
11
11
|
function createExtractCallback(model, options) {
|
|
12
12
|
const temperature = options?.temperature ?? 1;
|
|
13
13
|
const maxTokens = options?.maxTokens ?? null;
|
|
14
|
+
const env = options?.env;
|
|
14
15
|
return async (args) => {
|
|
15
16
|
let generateText;
|
|
16
17
|
try {
|
|
@@ -21,7 +22,7 @@ function createExtractCallback(model, options) {
|
|
|
21
22
|
`To use AI extraction with model '${model}', install 'ai' with your package manager.`
|
|
22
23
|
);
|
|
23
24
|
}
|
|
24
|
-
const modelProvider = await getModelProvider(model);
|
|
25
|
+
const modelProvider = await getModelProvider(model, { env });
|
|
25
26
|
const request = {
|
|
26
27
|
model: modelProvider,
|
|
27
28
|
system: buildExtractSystemPrompt(),
|
|
@@ -2,12 +2,13 @@ import {
|
|
|
2
2
|
buildResolveSystemPrompt,
|
|
3
3
|
buildResolveUserPrompt,
|
|
4
4
|
getModelProvider
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-FAHE5DB2.js";
|
|
6
6
|
|
|
7
7
|
// src/ai/resolver.ts
|
|
8
8
|
function createResolveCallback(model, options) {
|
|
9
9
|
const temperature = options?.temperature ?? 1;
|
|
10
10
|
const maxTokens = options?.maxTokens ?? null;
|
|
11
|
+
const env = options?.env;
|
|
11
12
|
return async (args) => {
|
|
12
13
|
let generateObject;
|
|
13
14
|
let z;
|
|
@@ -26,7 +27,7 @@ function createResolveCallback(model, options) {
|
|
|
26
27
|
`To use AI resolution with model '${model}', install 'zod' with your package manager.`
|
|
27
28
|
);
|
|
28
29
|
}
|
|
29
|
-
const modelProvider = await getModelProvider(model);
|
|
30
|
+
const modelProvider = await getModelProvider(model, { env });
|
|
30
31
|
const schema = z.object({
|
|
31
32
|
element: z.number().describe(
|
|
32
33
|
"Counter number of the matching element, or -1 if no match"
|
|
@@ -1,17 +1,49 @@
|
|
|
1
1
|
// src/ai/model.ts
|
|
2
|
+
var OPENAI_PROVIDER_INFO = {
|
|
3
|
+
pkg: "@ai-sdk/openai",
|
|
4
|
+
providerFn: "openai",
|
|
5
|
+
factoryFn: "createOpenAI",
|
|
6
|
+
apiKeyEnvVar: "OPENAI_API_KEY",
|
|
7
|
+
baseUrlEnvVar: "OPENAI_BASE_URL"
|
|
8
|
+
};
|
|
9
|
+
var ANTHROPIC_PROVIDER_INFO = {
|
|
10
|
+
pkg: "@ai-sdk/anthropic",
|
|
11
|
+
providerFn: "anthropic",
|
|
12
|
+
factoryFn: "createAnthropic",
|
|
13
|
+
apiKeyEnvVar: "ANTHROPIC_API_KEY",
|
|
14
|
+
baseUrlEnvVar: "ANTHROPIC_BASE_URL"
|
|
15
|
+
};
|
|
16
|
+
var GOOGLE_PROVIDER_INFO = {
|
|
17
|
+
pkg: "@ai-sdk/google",
|
|
18
|
+
providerFn: "google",
|
|
19
|
+
factoryFn: "createGoogleGenerativeAI",
|
|
20
|
+
apiKeyEnvVar: "GOOGLE_GENERATIVE_AI_API_KEY"
|
|
21
|
+
};
|
|
22
|
+
var XAI_PROVIDER_INFO = {
|
|
23
|
+
pkg: "@ai-sdk/xai",
|
|
24
|
+
providerFn: "xai",
|
|
25
|
+
factoryFn: "createXai",
|
|
26
|
+
apiKeyEnvVar: "XAI_API_KEY"
|
|
27
|
+
};
|
|
28
|
+
var GROQ_PROVIDER_INFO = {
|
|
29
|
+
pkg: "@ai-sdk/groq",
|
|
30
|
+
providerFn: "groq",
|
|
31
|
+
factoryFn: "createGroq",
|
|
32
|
+
apiKeyEnvVar: "GROQ_API_KEY"
|
|
33
|
+
};
|
|
2
34
|
var PROVIDER_MAP = {
|
|
3
|
-
"openai/":
|
|
4
|
-
"anthropic/":
|
|
5
|
-
"google/":
|
|
6
|
-
"xai/":
|
|
7
|
-
"gpt-":
|
|
8
|
-
"o1-":
|
|
9
|
-
"o3-":
|
|
10
|
-
"o4-":
|
|
11
|
-
"claude-":
|
|
12
|
-
"gemini-":
|
|
13
|
-
"grok-":
|
|
14
|
-
"groq/":
|
|
35
|
+
"openai/": OPENAI_PROVIDER_INFO,
|
|
36
|
+
"anthropic/": ANTHROPIC_PROVIDER_INFO,
|
|
37
|
+
"google/": GOOGLE_PROVIDER_INFO,
|
|
38
|
+
"xai/": XAI_PROVIDER_INFO,
|
|
39
|
+
"gpt-": OPENAI_PROVIDER_INFO,
|
|
40
|
+
"o1-": OPENAI_PROVIDER_INFO,
|
|
41
|
+
"o3-": OPENAI_PROVIDER_INFO,
|
|
42
|
+
"o4-": OPENAI_PROVIDER_INFO,
|
|
43
|
+
"claude-": ANTHROPIC_PROVIDER_INFO,
|
|
44
|
+
"gemini-": GOOGLE_PROVIDER_INFO,
|
|
45
|
+
"grok-": XAI_PROVIDER_INFO,
|
|
46
|
+
"groq/": GROQ_PROVIDER_INFO
|
|
15
47
|
};
|
|
16
48
|
function resolveProviderInfo(modelStr) {
|
|
17
49
|
for (const [prefix, info] of Object.entries(PROVIDER_MAP)) {
|
|
@@ -28,7 +60,7 @@ function resolveProviderInfo(modelStr) {
|
|
|
28
60
|
);
|
|
29
61
|
}
|
|
30
62
|
}
|
|
31
|
-
return
|
|
63
|
+
return OPENAI_PROVIDER_INFO;
|
|
32
64
|
}
|
|
33
65
|
function stripProviderPrefix(modelStr) {
|
|
34
66
|
const slash = modelStr.indexOf("/");
|
|
@@ -39,23 +71,50 @@ function stripProviderPrefix(modelStr) {
|
|
|
39
71
|
}
|
|
40
72
|
return modelStr;
|
|
41
73
|
}
|
|
42
|
-
|
|
43
|
-
|
|
74
|
+
function normalizeEnvValue(value) {
|
|
75
|
+
if (typeof value !== "string") return void 0;
|
|
76
|
+
const trimmed = value.trim();
|
|
77
|
+
return trimmed.length ? trimmed : void 0;
|
|
78
|
+
}
|
|
79
|
+
function buildFactoryOptions(provider, env) {
|
|
80
|
+
const apiKey = normalizeEnvValue(env[provider.apiKeyEnvVar]);
|
|
81
|
+
if (!apiKey) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`API key is missing in the resolved Opensteer environment. Set ${provider.apiKeyEnvVar} in your runtime environment or .env file under storage.rootDir.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const baseURL = provider.baseUrlEnvVar ? normalizeEnvValue(env[provider.baseUrlEnvVar]) : void 0;
|
|
87
|
+
return {
|
|
88
|
+
apiKey,
|
|
89
|
+
...baseURL ? { baseURL } : {}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function getModelProvider(modelStr, options = {}) {
|
|
93
|
+
const info = resolveProviderInfo(modelStr);
|
|
44
94
|
let mod;
|
|
45
95
|
try {
|
|
46
|
-
mod = await import(pkg);
|
|
96
|
+
mod = await import(info.pkg);
|
|
47
97
|
} catch {
|
|
48
98
|
throw new Error(
|
|
49
|
-
`To use AI resolution with model '${modelStr}', install 'ai' and '${pkg}' with your package manager.`
|
|
99
|
+
`To use AI resolution with model '${modelStr}', install 'ai' and '${info.pkg}' with your package manager.`
|
|
50
100
|
);
|
|
51
101
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
102
|
+
const providerExportName = options.env ? info.factoryFn : info.providerFn;
|
|
103
|
+
const providerExport = mod[providerExportName];
|
|
104
|
+
if (typeof providerExport !== "function") {
|
|
54
105
|
throw new Error(
|
|
55
|
-
`Provider '${
|
|
106
|
+
`Provider '${providerExportName}' not found in '${info.pkg}'. Ensure you have the latest version installed.`
|
|
56
107
|
);
|
|
57
108
|
}
|
|
58
109
|
const modelId = stripProviderPrefix(modelStr);
|
|
110
|
+
const provider = options.env != null ? providerExport(
|
|
111
|
+
buildFactoryOptions(info, options.env)
|
|
112
|
+
) : providerExport;
|
|
113
|
+
if (typeof provider !== "function") {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Provider '${providerExportName}' from '${info.pkg}' did not return a model factory function.`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
59
118
|
return provider(modelId);
|
|
60
119
|
}
|
|
61
120
|
|