@foggy-projects/deepseek-harness-plugin 0.4.2-rc.3 → 0.4.4-rc.1

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 (52) hide show
  1. package/README.md +222 -173
  2. package/THIRD-PARTY-RUNTIME-NOTICES.md +16 -16
  3. package/cordis.patch.yml +6 -6
  4. package/docs/COMMUNITY-MARKETPLACES.md +64 -64
  5. package/docs/PUBLIC-BETA-READINESS.md +109 -109
  6. package/docs/RELEASE-CANDIDATE-0.4.0-RC.2.md +38 -38
  7. package/docs/RELEASE-CANDIDATE-0.4.0-RC.3.md +18 -18
  8. package/docs/RELEASE-CANDIDATE-0.4.1-DSH-0.1.5-RC.1.md +60 -60
  9. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.1.md +62 -62
  10. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.2.md +50 -50
  11. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.3.md +34 -34
  12. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.4.md +32 -0
  13. package/docs/RELEASE-CANDIDATE-0.4.2-DSH-0.1.7-RC.5.md +27 -0
  14. package/docs/RELEASE-CANDIDATE-0.4.3-DSH-0.2.0-RC.1.md +96 -0
  15. package/docs/RELEASE-CANDIDATE-0.4.4-DSH-0.2.1-RC.1.md +135 -0
  16. package/docs/WINDOWS-BETA-ACCEPTANCE.md +113 -113
  17. package/experience/linux/README.md +53 -53
  18. package/experience/linux/prepare.sh +2 -2
  19. package/lib/atomic-json.js +41 -41
  20. package/lib/client.js +1222 -906
  21. package/lib/component-manager.js +164 -0
  22. package/lib/component-releases.js +363 -0
  23. package/lib/diagnostics.js +86 -86
  24. package/lib/index.js +764 -698
  25. package/lib/operation-lock.js +139 -0
  26. package/lib/python-runtime.js +339 -339
  27. package/lib/query-tool.js +134 -104
  28. package/lib/remote-descriptor.js +74 -59
  29. package/lib/remote.js +8 -8
  30. package/lib/runtime-settings.js +89 -89
  31. package/lib/skill-provider.js +116 -116
  32. package/lib/typert.js +9 -9
  33. package/lib/version.js +20 -20
  34. package/lib/viewer-preview.js +44 -27
  35. package/package.json +25 -15
  36. package/skills/foggy-deepseek-onboarding/SKILL.md +149 -143
  37. package/skills/foggy-deepseek-onboarding/assets/connection.schema.json +48 -48
  38. package/skills/foggy-deepseek-onboarding/assets/datasource.example.json +14 -14
  39. package/skills/foggy-deepseek-onboarding/assets/env.example +14 -14
  40. package/skills/foggy-deepseek-onboarding/assets/onboarding-state.schema.json +71 -71
  41. package/skills/foggy-deepseek-onboarding/assets/semantic-plan.example.json +8 -8
  42. package/skills/foggy-deepseek-onboarding/assets/semantic-plan.schema.json +21 -21
  43. package/skills/foggy-deepseek-onboarding/assets/versions.json +23 -23
  44. package/skills/foggy-deepseek-onboarding/references/onboarding-workflow.md +168 -168
  45. package/skills/foggy-deepseek-onboarding/scripts/doctor.ps1 +4 -4
  46. package/skills/foggy-deepseek-onboarding/scripts/install.ps1 +4 -4
  47. package/skills/foggy-deepseek-onboarding/scripts/invoke-onboarding.ps1 +32 -32
  48. package/skills/foggy-deepseek-onboarding/scripts/onboard.ps1 +4 -4
  49. package/skills/foggy-deepseek-onboarding/scripts/onboarding.py +3721 -3681
  50. package/skills/foggy-deepseek-onboarding/scripts/runtime-start.ps1 +4 -4
  51. package/skills/foggy-deepseek-onboarding/scripts/runtime-stop.ps1 +4 -4
  52. package/skills/foggy-deepseek-onboarding/scripts/uninstall.ps1 +4 -4
package/lib/query-tool.js CHANGED
@@ -1,104 +1,134 @@
1
- import { execFile } from 'node:child_process'
2
- import { mkdtemp, readFile, rmdir, unlink, writeFile } from 'node:fs/promises'
3
- import { tmpdir } from 'node:os'
4
- import { join } from 'node:path'
5
- import { promisify } from 'node:util'
6
- import { defineTool } from '@deepseek-ai/dsh-tools'
7
-
8
- const execFileAsync = promisify(execFile)
9
- const identifier = /^[A-Za-z0-9_.-]{1,128}$/
10
-
11
- export function assertStandardDsl(payload) {
12
- if (!payload || typeof payload !== 'object' || Array.isArray(payload)) throw new Error('Query DSL must be a JSON object')
13
- if (payload.route === 'DSL_CTE' || 'executable_plan' in payload || 'executablePlan' in payload) {
14
- throw new Error('CTE preview is not supported in this release; use a standard QM DSL query')
15
- }
16
- if (!Array.isArray(payload.columns) || payload.columns.length === 0 || !payload.columns.every((item) => typeof item === 'string')) {
17
- throw new Error('Standard QM DSL requires non-empty columns')
18
- }
19
- }
20
-
21
- export function previewPayload(payload) {
22
- assertStandardDsl(payload)
23
- const supported = new Set(['columns', 'slice', 'groupBy', 'orderBy', 'calculatedFields', 'extData'])
24
- const unsupported = Object.keys(payload).filter((key) => !supported.has(key) && !['start', 'limit', 'returnTotal'].includes(key))
25
- if (unsupported.length) throw new Error(`DataViewer preview does not support: ${unsupported.join(', ')}`)
26
- for (const key of ['slice', 'groupBy', 'orderBy', 'calculatedFields']) {
27
- if (payload[key] !== undefined && (!Array.isArray(payload[key]) || payload[key].some((item) => !item || typeof item !== 'object' || Array.isArray(item)))) {
28
- throw new Error(`DataViewer preview requires object-form ${key} entries`)
29
- }
30
- }
31
- return Object.fromEntries([...supported].filter((key) => payload[key] !== undefined).map((key) => [key, payload[key]]))
32
- }
33
-
34
- export function safeRuntimeUrl(value) {
35
- const url = new URL(value)
36
- if (url.protocol !== 'http:' || !['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname)
37
- || url.username || url.password || url.pathname !== '/' || url.search || url.hash) {
38
- throw new Error('Managed Runtime URL must be a plain loopback HTTP origin')
39
- }
40
- return url.origin
41
- }
42
-
43
- export async function managedConnection(roots) {
44
- const install = JSON.parse(await readFile(join(roots.installRoot, 'install-state.json'), 'utf8'))
45
- const runtime = JSON.parse(await readFile(join(roots.dataRoot, 'runtime-state.json'), 'utf8'))
46
- if (!install.cli?.command) throw new Error('Foggy CLI is not installed')
47
- return { cli: install.cli.command, runtimeUrl: safeRuntimeUrl(runtime.runtimeUrl) }
48
- }
49
-
50
- async function cliJson(cli, runtimeUrl, namespace, command, signal) {
51
- const { stdout } = await execFileAsync(cli, ['--base-url', runtimeUrl, '--namespace', namespace, '--output', 'json', ...command], {
52
- signal,
53
- windowsHide: true,
54
- timeout: 120_000,
55
- maxBuffer: 8 * 1024 * 1024,
56
- })
57
- const value = JSON.parse(stdout.trim())
58
- if (value?.success !== true) throw new Error(value?.error?.message || value?.error?.code || 'Foggy query failed')
59
- return value
60
- }
61
-
62
- export function createFoggyQueryTool(roots) {
63
- return defineTool({
64
- name: 'foggy_query',
65
- description: 'Validate and execute a bounded, read-only standard Foggy QueryModel DSL query against the managed local Runtime. On success Harness shows a query card; its DataViewer preview link is created only if the user clicks Open DataViewer. CTE is not supported here.',
66
- parameters: {
67
- model: { type: 'string', required: true, description: 'Published Foggy QueryModel name' },
68
- namespace: { type: 'string', required: true, description: 'Foggy namespace' },
69
- payload: { type: 'object', additionalProperties: true, required: true, description: 'Standard QueryModel DSL, including explicit columns and bounded limit' },
70
- },
71
- output: {
72
- schema: { type: 'object', additionalProperties: false, properties: {
73
- model: { type: 'string', required: true },
74
- namespace: { type: 'string', required: true },
75
- validation: { type: 'json', required: true },
76
- execution: { type: 'json', required: true },
77
- } },
78
- render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }],
79
- },
80
- timeoutMs: 150_000,
81
- async execute({ model, namespace, payload }, exec) {
82
- if (!identifier.test(model) || !identifier.test(namespace)) throw new Error('Invalid model or namespace')
83
- assertStandardDsl(payload)
84
- if (!Number.isInteger(payload.limit) || payload.limit < 1 || payload.limit > 100) {
85
- throw new Error('Query DSL limit must be an integer from 1 to 100')
86
- }
87
- const { cli, runtimeUrl } = await managedConnection(roots)
88
- const directory = await mkdtemp(join(tmpdir(), 'foggy-dsh-query-'))
89
- const payloadPath = join(directory, 'query.json')
90
- try {
91
- await writeFile(payloadPath, JSON.stringify(payload), { encoding: 'utf8', flag: 'wx' })
92
- const validation = await cliJson(cli, runtimeUrl, namespace, ['query', 'validate', model, '--payload', payloadPath], exec.signal)
93
- const execution = await cliJson(cli, runtimeUrl, namespace, ['query', 'execute', model, '--payload', payloadPath], exec.signal)
94
- return { model, namespace, validation, execution }
95
- } finally {
96
- await unlink(payloadPath).catch(() => {})
97
- await rmdir(directory).catch(() => {})
98
- }
99
- },
100
- presentCall({ model }) {
101
- return { card: 'generic', title: `Foggy DSL · ${model}`, kind: 'read' }
102
- },
103
- })
104
- }
1
+ import { execFile } from 'node:child_process'
2
+ import { mkdtemp, readFile, rmdir, unlink, writeFile } from 'node:fs/promises'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { promisify } from 'node:util'
6
+
7
+ const execFileAsync = promisify(execFile)
8
+ const identifier = /^[A-Za-z0-9_.-]{1,128}$/
9
+
10
+ export function assertStandardDsl(payload) {
11
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload)) throw new Error('Query DSL must be a JSON object')
12
+ if (payload.route === 'DSL_CTE' || 'executable_plan' in payload || 'executablePlan' in payload) {
13
+ throw new Error('CTE preview is not supported in this release; use a standard QM DSL query')
14
+ }
15
+ if (!Array.isArray(payload.columns) || payload.columns.length === 0 || !payload.columns.every((item) => typeof item === 'string')) {
16
+ throw new Error('Standard QM DSL requires non-empty columns')
17
+ }
18
+ }
19
+
20
+ export function previewPayload(payload) {
21
+ assertStandardDsl(payload)
22
+ if (!Array.isArray(payload.slice) || payload.slice.length === 0) {
23
+ throw new Error('DataViewer requires at least one slice filter. Add a filter before opening the viewer.')
24
+ }
25
+ const supported = new Set(['columns', 'slice', 'having', 'groupBy', 'orderBy', 'calculatedFields', 'extData'])
26
+ const unsupported = Object.keys(payload).filter((key) => !supported.has(key) && !['start', 'limit', 'returnTotal'].includes(key))
27
+ if (unsupported.length) throw new Error(`DataViewer preview does not support: ${unsupported.join(', ')}`)
28
+ for (const key of ['slice', 'having', 'calculatedFields']) {
29
+ if (payload[key] !== undefined && (!Array.isArray(payload[key]) || payload[key].some((item) => !item || typeof item !== 'object' || Array.isArray(item)))) {
30
+ throw new Error(`DataViewer preview requires object-form ${key} entries`)
31
+ }
32
+ }
33
+ const result = Object.fromEntries([...supported].filter((key) => payload[key] !== undefined).map((key) => [key, payload[key]]))
34
+ if (payload.groupBy !== undefined) {
35
+ if (!Array.isArray(payload.groupBy) || payload.groupBy.some((item) => typeof item !== 'string' && (!item || typeof item !== 'object' || Array.isArray(item)))) {
36
+ throw new Error('DataViewer preview requires field names or object-form groupBy entries')
37
+ }
38
+ result.groupBy = payload.groupBy.map((item) => typeof item === 'string' ? { field: item } : item)
39
+ }
40
+ if (payload.orderBy !== undefined) {
41
+ if (!Array.isArray(payload.orderBy) || payload.orderBy.some((item) => typeof item !== 'string' && (!item || typeof item !== 'object' || Array.isArray(item)))) {
42
+ throw new Error('DataViewer preview requires field names or object-form orderBy entries')
43
+ }
44
+ result.orderBy = payload.orderBy.map((item) => {
45
+ if (typeof item !== 'string') return item
46
+ const shorthand = item.trim().match(/^(-)?(.+?)(?:\s+(asc|desc))?$/i)
47
+ if (!shorthand || !shorthand[2].trim()) throw new Error('DataViewer preview requires a valid orderBy field')
48
+ return { field: shorthand[2].trim(), dir: shorthand[1] ? 'desc' : (shorthand[3] || 'asc').toLowerCase() }
49
+ })
50
+ }
51
+ return result
52
+ }
53
+
54
+ export function safeRuntimeUrl(value) {
55
+ const url = new URL(value)
56
+ if (url.protocol !== 'http:' || !['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname)
57
+ || url.username || url.password || url.pathname !== '/' || url.search || url.hash) {
58
+ throw new Error('Managed Runtime URL must be a plain loopback HTTP origin')
59
+ }
60
+ return url.origin
61
+ }
62
+
63
+ export async function managedConnection(roots) {
64
+ const install = JSON.parse(await readFile(join(roots.installRoot, 'install-state.json'), 'utf8'))
65
+ const runtime = JSON.parse(await readFile(join(roots.dataRoot, 'runtime-state.json'), 'utf8'))
66
+ if (!install.cli?.command) throw new Error('Foggy CLI is not installed')
67
+ return { cli: install.cli.command, runtimeUrl: safeRuntimeUrl(runtime.runtimeUrl) }
68
+ }
69
+
70
+ async function cliJson(cli, runtimeUrl, namespace, command, signal) {
71
+ const { stdout } = await execFileAsync(cli, ['--base-url', runtimeUrl, '--namespace', namespace, '--output', 'json', ...command], {
72
+ signal,
73
+ windowsHide: true,
74
+ timeout: 120_000,
75
+ maxBuffer: 8 * 1024 * 1024,
76
+ })
77
+ const value = JSON.parse(stdout.trim())
78
+ if (value?.success !== true) throw new Error(value?.error?.message || value?.error?.code || 'Foggy query failed')
79
+ return value
80
+ }
81
+
82
+ export function createFoggyQueryTool(roots) {
83
+ return {
84
+ name: 'foggy_query',
85
+ description: 'Validate and execute a bounded, read-only standard Foggy QueryModel DSL query against the managed local Runtime. On success Harness shows a query card; its DataViewer preview link is created only if the user clicks Open DataViewer. CTE is not supported here.',
86
+ parameters: {
87
+ type: 'object',
88
+ properties: {
89
+ model: { type: 'string', description: 'Published Foggy QueryModel name' },
90
+ namespace: { type: 'string', description: 'Foggy namespace' },
91
+ payload: { type: 'object', additionalProperties: true, description: 'Standard QueryModel DSL, including explicit columns and bounded limit' },
92
+ },
93
+ required: ['model', 'namespace', 'payload'],
94
+ },
95
+ output: {
96
+ schema: {
97
+ type: 'object',
98
+ additionalProperties: false,
99
+ properties: {
100
+ model: { type: 'string' },
101
+ namespace: { type: 'string' },
102
+ validation: {},
103
+ execution: {},
104
+ },
105
+ required: ['model', 'namespace', 'validation', 'execution'],
106
+ },
107
+ render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }],
108
+ },
109
+ timeoutMs: 150_000,
110
+ async execute(args, exec) {
111
+ const { model, namespace, payload } = args || {}
112
+ if (!identifier.test(model) || !identifier.test(namespace)) throw new Error('Invalid model or namespace')
113
+ assertStandardDsl(payload)
114
+ if (!Number.isInteger(payload.limit) || payload.limit < 1 || payload.limit > 100) {
115
+ throw new Error('Query DSL limit must be an integer from 1 to 100')
116
+ }
117
+ const { cli, runtimeUrl } = await managedConnection(roots)
118
+ const directory = await mkdtemp(join(tmpdir(), 'foggy-dsh-query-'))
119
+ const payloadPath = join(directory, 'query.json')
120
+ try {
121
+ await writeFile(payloadPath, JSON.stringify(payload), { encoding: 'utf8', flag: 'wx' })
122
+ const validation = await cliJson(cli, runtimeUrl, namespace, ['query', 'validate', model, '--payload', payloadPath], exec?.signal)
123
+ const execution = await cliJson(cli, runtimeUrl, namespace, ['query', 'execute', model, '--payload', payloadPath], exec?.signal)
124
+ return { model, namespace, validation, execution }
125
+ } finally {
126
+ await unlink(payloadPath).catch(() => {})
127
+ await rmdir(directory).catch(() => {})
128
+ }
129
+ },
130
+ presentCall({ model }) {
131
+ return { card: 'generic', title: `Foggy DSL · ${model}`, kind: 'read' }
132
+ },
133
+ }
134
+ }
@@ -1,59 +1,74 @@
1
- import { z } from 'zod'
2
-
3
- const resultSchema = z.unknown()
4
- const runtimeSettingsInputSchema = z.object({
5
- port: z.number().int().min(1024).max(65535),
6
- }).strict()
7
- const viewerPreviewInputSchema = z.object({
8
- model: z.string(),
9
- namespace: z.string(),
10
- payload: z.record(z.string(), z.unknown()),
11
- }).strict()
12
-
13
- function strictCodec(typeSymbol, schema) {
14
- return {
15
- mode: 'strict',
16
- typeSymbol,
17
- // DSH 0.1.5 consumes `schema`; DSH 0.1.7 materializes it through `create()`.
18
- schema,
19
- create: () => schema,
20
- }
21
- }
22
-
23
- function descriptor(method, parameters = []) {
24
- return {
25
- id: `@foggy-projects/deepseek-harness-plugin#foggyIntegration/${method}`,
26
- service: 'foggyIntegration',
27
- namespace: 'foggyIntegration',
28
- method,
29
- invocation: { kind: 'direct' },
30
- parameters,
31
- result: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyIntegrationResult', resultSchema),
32
- sourceLocation: { file: 'lib/index.js', line: 1, column: 1 },
33
- }
34
- }
35
-
36
- export const descriptors = [
37
- descriptor('status'),
38
- descriptor('plan'),
39
- descriptor('initialize'),
40
- descriptor('initializeAndStart'),
41
- descriptor('repair'),
42
- descriptor('updateComponents'),
43
- descriptor('repairPython'),
44
- descriptor('repairSemanticQuerySkill'),
45
- descriptor('runtimeStart'),
46
- descriptor('runtimeStop'),
47
- descriptor('saveRuntimeSettings', [{
48
- name: 'input',
49
- wire: 'input',
50
- source: 'json',
51
- codec: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyRuntimeSettingsInput', runtimeSettingsInputSchema),
52
- }]),
53
- descriptor('createViewerPreview', [{
54
- name: 'input',
55
- wire: 'input',
56
- source: 'json',
57
- codec: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyViewerPreviewInput', viewerPreviewInputSchema),
58
- }]),
59
- ]
1
+ import { z } from 'zod'
2
+
3
+ const resultSchema = z.unknown()
4
+ const runtimeSettingsInputSchema = z.object({
5
+ port: z.number().int().min(1024).max(65535),
6
+ }).strict()
7
+ const viewerPreviewInputSchema = z.object({
8
+ model: z.string(),
9
+ namespace: z.string(),
10
+ payload: z.record(z.string(), z.unknown()),
11
+ }).strict()
12
+ const componentVersionInputSchema = z.object({
13
+ component: z.enum(['launcher', 'cli']),
14
+ version: z.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/).max(80),
15
+ }).strict()
16
+
17
+ function strictCodec(typeSymbol, schema) {
18
+ return {
19
+ mode: 'strict',
20
+ typeSymbol,
21
+ // Legacy DSH consumes `schema`; DSH 0.2.0 materializes it through `create()`.
22
+ schema,
23
+ create: () => schema,
24
+ }
25
+ }
26
+
27
+ function descriptor(method, parameters = []) {
28
+ return {
29
+ id: `@foggy-projects/deepseek-harness-plugin#foggyIntegration/${method}`,
30
+ service: 'foggyIntegration',
31
+ namespace: 'foggyIntegration',
32
+ method,
33
+ invocation: { kind: 'direct' },
34
+ parameters,
35
+ result: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyIntegrationResult', resultSchema),
36
+ sourceLocation: { file: 'lib/index.js', line: 1, column: 1 },
37
+ }
38
+ }
39
+
40
+ export const descriptors = [
41
+ descriptor('status'),
42
+ descriptor('plan'),
43
+ descriptor('initialize'),
44
+ descriptor('initializeAndStart'),
45
+ descriptor('repair'),
46
+ descriptor('updateComponents'),
47
+ descriptor('componentVersions'),
48
+ descriptor('checkComponentVersions'),
49
+ descriptor('useComponentVersion', [{
50
+ name: 'input', wire: 'input', source: 'json',
51
+ codec: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyComponentVersionInput', componentVersionInputSchema),
52
+ }]),
53
+ descriptor('repairPython'),
54
+ descriptor('repairCli'),
55
+ descriptor('repairLauncher'),
56
+ descriptor('repairAnalysisSkill'),
57
+ descriptor('repairSemanticQuerySkill'),
58
+ descriptor('migrateProfiles'),
59
+ descriptor('diagnostics'),
60
+ descriptor('runtimeStart'),
61
+ descriptor('runtimeStop'),
62
+ descriptor('saveRuntimeSettings', [{
63
+ name: 'input',
64
+ wire: 'input',
65
+ source: 'json',
66
+ codec: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyRuntimeSettingsInput', runtimeSettingsInputSchema),
67
+ }]),
68
+ descriptor('createViewerPreview', [{
69
+ name: 'input',
70
+ wire: 'input',
71
+ source: 'json',
72
+ codec: strictCodec('@foggy-projects/deepseek-harness-plugin#FoggyViewerPreviewInput', viewerPreviewInputSchema),
73
+ }]),
74
+ ]
package/lib/remote.js CHANGED
@@ -1,8 +1,8 @@
1
- import { descriptors } from './remote-descriptor.js'
2
-
3
- export const TYPERT_REMOTE = {
4
- package: '@foggy-projects/deepseek-harness-plugin',
5
- descriptors,
6
- }
7
-
8
- export default TYPERT_REMOTE
1
+ import { descriptors } from './remote-descriptor.js'
2
+
3
+ export const TYPERT_REMOTE = {
4
+ package: '@foggy-projects/deepseek-harness-plugin',
5
+ descriptors,
6
+ }
7
+
8
+ export default TYPERT_REMOTE
@@ -1,89 +1,89 @@
1
- import { readFile } from 'node:fs/promises'
2
- import { join } from 'node:path'
3
- import { writeJsonAtomic } from './atomic-json.js'
4
-
5
- export const RUNTIME_SETTINGS_SCHEMA = 'foggy-deepseek-runtime-settings/v1'
6
- export const DEFAULT_RUNTIME_PORT = 18166
7
- export const MIN_RUNTIME_PORT = 1024
8
- export const MAX_RUNTIME_PORT = 65535
9
-
10
- export function normalizeRuntimePort(value) {
11
- const port = typeof value === 'string' && value.trim() !== '' ? Number(value) : value
12
- if (!Number.isInteger(port) || port < MIN_RUNTIME_PORT || port > MAX_RUNTIME_PORT) {
13
- throw new Error(`Runtime port must be an integer between ${MIN_RUNTIME_PORT} and ${MAX_RUNTIME_PORT}`)
14
- }
15
- return port
16
- }
17
-
18
- export function runtimeUrlForPort(port) {
19
- return `http://127.0.0.1:${normalizeRuntimePort(port)}`
20
- }
21
-
22
- export function runtimeSettingsPath(dataRoot) {
23
- return join(dataRoot, 'runtime-settings.json')
24
- }
25
-
26
- export async function readRuntimeSettings(dataRoot, { defaultPort = DEFAULT_RUNTIME_PORT } = {}) {
27
- const path = runtimeSettingsPath(dataRoot)
28
- const fallbackPort = normalizeRuntimePort(defaultPort)
29
- try {
30
- const payload = JSON.parse(await readFile(path, 'utf8'))
31
- if (payload?.schemaVersion !== RUNTIME_SETTINGS_SCHEMA) {
32
- throw new Error(`expected schemaVersion ${RUNTIME_SETTINGS_SCHEMA}`)
33
- }
34
- const port = normalizeRuntimePort(payload.runtimePort)
35
- return {
36
- valid: true,
37
- source: 'configured',
38
- schemaVersion: RUNTIME_SETTINGS_SCHEMA,
39
- port,
40
- runtimeUrl: runtimeUrlForPort(port),
41
- updatedAt: payload.updatedAt ?? null,
42
- path,
43
- error: null,
44
- }
45
- } catch (error) {
46
- if (error?.code === 'ENOENT') {
47
- return {
48
- valid: true,
49
- source: 'default',
50
- schemaVersion: RUNTIME_SETTINGS_SCHEMA,
51
- port: fallbackPort,
52
- runtimeUrl: runtimeUrlForPort(fallbackPort),
53
- updatedAt: null,
54
- path,
55
- error: null,
56
- }
57
- }
58
- return {
59
- valid: false,
60
- source: 'invalid',
61
- schemaVersion: RUNTIME_SETTINGS_SCHEMA,
62
- port: fallbackPort,
63
- runtimeUrl: runtimeUrlForPort(fallbackPort),
64
- updatedAt: null,
65
- path,
66
- error: String(error?.message ?? error),
67
- }
68
- }
69
- }
70
-
71
- export async function writeRuntimeSettings(dataRoot, input) {
72
- const runtimePort = normalizeRuntimePort(input?.port)
73
- const payload = {
74
- schemaVersion: RUNTIME_SETTINGS_SCHEMA,
75
- runtimePort,
76
- updatedAt: new Date().toISOString(),
77
- }
78
- const path = runtimeSettingsPath(dataRoot)
79
- await writeJsonAtomic(path, payload)
80
- return {
81
- valid: true,
82
- source: 'configured',
83
- ...payload,
84
- port: runtimePort,
85
- runtimeUrl: runtimeUrlForPort(runtimePort),
86
- path,
87
- error: null,
88
- }
89
- }
1
+ import { readFile } from 'node:fs/promises'
2
+ import { join } from 'node:path'
3
+ import { writeJsonAtomic } from './atomic-json.js'
4
+
5
+ export const RUNTIME_SETTINGS_SCHEMA = 'foggy-deepseek-runtime-settings/v1'
6
+ export const DEFAULT_RUNTIME_PORT = 18166
7
+ export const MIN_RUNTIME_PORT = 1024
8
+ export const MAX_RUNTIME_PORT = 65535
9
+
10
+ export function normalizeRuntimePort(value) {
11
+ const port = typeof value === 'string' && value.trim() !== '' ? Number(value) : value
12
+ if (!Number.isInteger(port) || port < MIN_RUNTIME_PORT || port > MAX_RUNTIME_PORT) {
13
+ throw new Error(`Runtime port must be an integer between ${MIN_RUNTIME_PORT} and ${MAX_RUNTIME_PORT}`)
14
+ }
15
+ return port
16
+ }
17
+
18
+ export function runtimeUrlForPort(port) {
19
+ return `http://127.0.0.1:${normalizeRuntimePort(port)}`
20
+ }
21
+
22
+ export function runtimeSettingsPath(dataRoot) {
23
+ return join(dataRoot, 'runtime-settings.json')
24
+ }
25
+
26
+ export async function readRuntimeSettings(dataRoot, { defaultPort = DEFAULT_RUNTIME_PORT } = {}) {
27
+ const path = runtimeSettingsPath(dataRoot)
28
+ const fallbackPort = normalizeRuntimePort(defaultPort)
29
+ try {
30
+ const payload = JSON.parse(await readFile(path, 'utf8'))
31
+ if (payload?.schemaVersion !== RUNTIME_SETTINGS_SCHEMA) {
32
+ throw new Error(`expected schemaVersion ${RUNTIME_SETTINGS_SCHEMA}`)
33
+ }
34
+ const port = normalizeRuntimePort(payload.runtimePort)
35
+ return {
36
+ valid: true,
37
+ source: 'configured',
38
+ schemaVersion: RUNTIME_SETTINGS_SCHEMA,
39
+ port,
40
+ runtimeUrl: runtimeUrlForPort(port),
41
+ updatedAt: payload.updatedAt ?? null,
42
+ path,
43
+ error: null,
44
+ }
45
+ } catch (error) {
46
+ if (error?.code === 'ENOENT') {
47
+ return {
48
+ valid: true,
49
+ source: 'default',
50
+ schemaVersion: RUNTIME_SETTINGS_SCHEMA,
51
+ port: fallbackPort,
52
+ runtimeUrl: runtimeUrlForPort(fallbackPort),
53
+ updatedAt: null,
54
+ path,
55
+ error: null,
56
+ }
57
+ }
58
+ return {
59
+ valid: false,
60
+ source: 'invalid',
61
+ schemaVersion: RUNTIME_SETTINGS_SCHEMA,
62
+ port: fallbackPort,
63
+ runtimeUrl: runtimeUrlForPort(fallbackPort),
64
+ updatedAt: null,
65
+ path,
66
+ error: String(error?.message ?? error),
67
+ }
68
+ }
69
+ }
70
+
71
+ export async function writeRuntimeSettings(dataRoot, input) {
72
+ const runtimePort = normalizeRuntimePort(input?.port)
73
+ const payload = {
74
+ schemaVersion: RUNTIME_SETTINGS_SCHEMA,
75
+ runtimePort,
76
+ updatedAt: new Date().toISOString(),
77
+ }
78
+ const path = runtimeSettingsPath(dataRoot)
79
+ await writeJsonAtomic(path, payload)
80
+ return {
81
+ valid: true,
82
+ source: 'configured',
83
+ ...payload,
84
+ port: runtimePort,
85
+ runtimeUrl: runtimeUrlForPort(runtimePort),
86
+ path,
87
+ error: null,
88
+ }
89
+ }