berget 1.3.1 → 2.0.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.
Files changed (67) hide show
  1. package/.env.example +5 -0
  2. package/.github/workflows/publish.yml +56 -0
  3. package/.github/workflows/test.yml +38 -0
  4. package/AGENTS.md +184 -0
  5. package/README.md +177 -38
  6. package/TODO.md +2 -0
  7. package/blog-post.md +176 -0
  8. package/dist/index.js +11 -8
  9. package/dist/package.json +14 -3
  10. package/dist/src/commands/api-keys.js +4 -2
  11. package/dist/src/commands/chat.js +182 -23
  12. package/dist/src/commands/code.js +1424 -0
  13. package/dist/src/commands/index.js +2 -0
  14. package/dist/src/constants/command-structure.js +12 -0
  15. package/dist/src/schemas/opencode-schema.json +1121 -0
  16. package/dist/src/services/chat-service.js +10 -10
  17. package/dist/src/services/cluster-service.js +1 -1
  18. package/dist/src/utils/default-api-key.js +2 -2
  19. package/dist/src/utils/env-manager.js +86 -0
  20. package/dist/src/utils/error-handler.js +10 -3
  21. package/dist/src/utils/markdown-renderer.js +4 -4
  22. package/dist/src/utils/opencode-validator.js +122 -0
  23. package/dist/src/utils/token-manager.js +2 -2
  24. package/dist/tests/commands/chat.test.js +109 -0
  25. package/dist/tests/commands/code.test.js +414 -0
  26. package/dist/tests/utils/env-manager.test.js +148 -0
  27. package/dist/tests/utils/opencode-validator.test.js +103 -0
  28. package/dist/vitest.config.js +9 -0
  29. package/index.ts +67 -32
  30. package/opencode.json +182 -0
  31. package/package.json +14 -3
  32. package/src/client.ts +20 -20
  33. package/src/commands/api-keys.ts +93 -60
  34. package/src/commands/auth.ts +4 -2
  35. package/src/commands/billing.ts +6 -3
  36. package/src/commands/chat.ts +291 -97
  37. package/src/commands/clusters.ts +2 -2
  38. package/src/commands/code.ts +1696 -0
  39. package/src/commands/index.ts +2 -0
  40. package/src/commands/models.ts +3 -3
  41. package/src/commands/users.ts +2 -2
  42. package/src/constants/command-structure.ts +112 -58
  43. package/src/schemas/opencode-schema.json +991 -0
  44. package/src/services/api-key-service.ts +1 -1
  45. package/src/services/auth-service.ts +27 -25
  46. package/src/services/chat-service.ts +37 -44
  47. package/src/services/cluster-service.ts +5 -5
  48. package/src/services/collaborator-service.ts +3 -3
  49. package/src/services/flux-service.ts +2 -2
  50. package/src/services/helm-service.ts +2 -2
  51. package/src/services/kubectl-service.ts +3 -6
  52. package/src/types/api.d.ts +1032 -1010
  53. package/src/types/json.d.ts +3 -3
  54. package/src/utils/default-api-key.ts +54 -42
  55. package/src/utils/env-manager.ts +98 -0
  56. package/src/utils/error-handler.ts +24 -15
  57. package/src/utils/logger.ts +12 -12
  58. package/src/utils/markdown-renderer.ts +18 -18
  59. package/src/utils/opencode-validator.ts +134 -0
  60. package/src/utils/token-manager.ts +35 -23
  61. package/tests/commands/chat.test.ts +129 -0
  62. package/tests/commands/code.test.ts +505 -0
  63. package/tests/utils/env-manager.test.ts +199 -0
  64. package/tests/utils/opencode-validator.test.ts +118 -0
  65. package/tsconfig.json +8 -8
  66. package/vitest.config.ts +8 -0
  67. package/-27b-it +0 -0
@@ -0,0 +1,118 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ validateOpenCodeConfig,
4
+ fixOpenCodeConfig,
5
+ } from '../../src/utils/opencode-validator'
6
+ import { readFileSync } from 'fs'
7
+
8
+ describe('OpenCode Validator', () => {
9
+ it('should validate a correct OpenCode configuration', () => {
10
+ const validConfig = {
11
+ $schema: 'https://opencode.ai/config.json',
12
+ username: 'test-user',
13
+ model: 'gpt-4',
14
+ agent: {
15
+ test: {
16
+ model: 'gpt-4',
17
+ temperature: 0.7,
18
+ prompt: 'Test agent',
19
+ permission: {
20
+ edit: 'allow',
21
+ bash: 'allow',
22
+ webfetch: 'allow',
23
+ },
24
+ },
25
+ },
26
+ }
27
+
28
+ const result = validateOpenCodeConfig(validConfig)
29
+ expect(result.valid).toBe(true)
30
+ expect(result.errors).toBeUndefined()
31
+ })
32
+
33
+ it('should reject invalid configuration', () => {
34
+ const invalidConfig = {
35
+ username: 123, // Should be string
36
+ model: 'gpt-4',
37
+ agent: {
38
+ test: {
39
+ model: 'gpt-4',
40
+ temperature: 'high', // Should be number
41
+ prompt: 'Test agent',
42
+ permission: {
43
+ edit: 'invalid', // Should be enum value
44
+ bash: 'allow',
45
+ webfetch: 'allow',
46
+ },
47
+ },
48
+ },
49
+ }
50
+
51
+ const result = validateOpenCodeConfig(invalidConfig)
52
+ expect(result.valid).toBe(false)
53
+ expect(result.errors).toBeDefined()
54
+ expect(result.errors!.length).toBeGreaterThan(0)
55
+ })
56
+
57
+ it('should fix common configuration issues', () => {
58
+ const configWithIssues = {
59
+ username: 'test-user',
60
+ model: 'gpt-4',
61
+ tools: {
62
+ compact: { threshold: 80000 }, // Should be boolean
63
+ },
64
+ maxTokens: 4000, // Invalid property
65
+ provider: {
66
+ berget: {
67
+ models: {
68
+ 'test-model': {
69
+ name: 'Test Model',
70
+ maxTokens: 4000, // Should be moved to limit.context
71
+ contextWindow: 8000, // Should be moved to limit.context
72
+ },
73
+ },
74
+ },
75
+ },
76
+ }
77
+
78
+ const fixed = fixOpenCodeConfig(configWithIssues)
79
+
80
+ // tools.compact should be boolean
81
+ expect(typeof fixed.tools.compact).toBe('boolean')
82
+
83
+ // maxTokens should be removed
84
+ expect(fixed.maxTokens).toBeUndefined()
85
+
86
+ // maxTokens and contextWindow should be moved to limit.context
87
+ expect(fixed.provider.berget.models['test-model'].limit).toBeDefined()
88
+ expect(fixed.provider.berget.models['test-model'].limit.context).toBe(8000)
89
+ expect(fixed.provider.berget.models['test-model'].maxTokens).toBeUndefined()
90
+ expect(
91
+ fixed.provider.berget.models['test-model'].contextWindow,
92
+ ).toBeUndefined()
93
+ })
94
+
95
+ it('should validate the current opencode.json file', () => {
96
+ try {
97
+ const currentConfig = JSON.parse(readFileSync('opencode.json', 'utf8'))
98
+
99
+ // Apply fixes to handle common issues
100
+ const fixedConfig = fixOpenCodeConfig(currentConfig)
101
+
102
+ // Validate the fixed config
103
+ const result = validateOpenCodeConfig(fixedConfig)
104
+
105
+ // The fixed config should be valid according to the JSON Schema
106
+ expect(result.valid).toBe(true)
107
+
108
+ if (!result.valid) {
109
+ console.log('Fixed opencode.json validation errors:')
110
+ result.errors?.forEach((err) => console.log(` - ${err}`))
111
+ }
112
+ } catch (error) {
113
+ // If we can't read the file, that's ok for this test
114
+ console.log('Could not read opencode.json for testing:', error)
115
+ expect.fail('Should be able to read opencode.json')
116
+ }
117
+ })
118
+ })
package/tsconfig.json CHANGED
@@ -11,7 +11,7 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14
+ "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
17
  // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -25,7 +25,7 @@
25
25
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
26
 
27
27
  /* Modules */
28
- "module": "commonjs", /* Specify what module code is generated. */
28
+ "module": "commonjs" /* Specify what module code is generated. */,
29
29
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
30
  // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -39,7 +39,7 @@
39
39
  // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
40
  // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
41
  // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
- "resolveJsonModule": true, /* Enable importing .json files. */
42
+ "resolveJsonModule": true /* Enable importing .json files. */,
43
43
  // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44
44
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
45
 
@@ -55,7 +55,7 @@
55
55
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
56
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
57
  // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58
- "outDir": "./dist/", /* Specify an output folder for all emitted files. */
58
+ "outDir": "./dist/" /* Specify an output folder for all emitted files. */,
59
59
  // "removeComments": true, /* Disable emitting comments. */
60
60
  // "noEmit": true, /* Disable emitting files from a compilation. */
61
61
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@@ -77,12 +77,12 @@
77
77
  // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78
78
  // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79
79
  // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
80
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
81
81
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
82
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
83
83
 
84
84
  /* Type Checking */
85
- "strict": true, /* Enable all strict type-checking options. */
85
+ "strict": true /* Enable all strict type-checking options. */,
86
86
  // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87
87
  // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88
88
  // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
@@ -104,6 +104,6 @@
104
104
 
105
105
  /* Completeness */
106
106
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
107
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
108
  }
109
109
  }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ },
8
+ })
package/-27b-it DELETED
File without changes