@opengeni/config 0.2.4 → 0.3.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.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Cloudgeni-ai
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/dist/index.d.ts CHANGED
@@ -31,10 +31,28 @@ declare const AGENT_INSTRUCTIONS_CORE_PLACEHOLDER = "{{core}}";
31
31
  * character here changes that default; a runtime test pins it.
32
32
  */
33
33
  declare const DEFAULT_AGENT_INSTRUCTIONS: string;
34
+ declare const McpServerConnectionRefSchema: z.ZodObject<{
35
+ connectionId: z.ZodOptional<z.ZodString>;
36
+ providerDomain: z.ZodString;
37
+ kind: z.ZodOptional<z.ZodEnum<{
38
+ oauth2: "oauth2";
39
+ api_key: "api_key";
40
+ app_install: "app_install";
41
+ delegated: "delegated";
42
+ }>>;
43
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
44
+ resource: z.ZodOptional<z.ZodString>;
45
+ subjectScope: z.ZodOptional<z.ZodEnum<{
46
+ workspace: "workspace";
47
+ subject: "subject";
48
+ }>>;
49
+ }, z.core.$strict>;
50
+ type McpServerConnectionRef = z.infer<typeof McpServerConnectionRefSchema>;
34
51
  declare const SettingsSchema: z.ZodObject<{
35
52
  serviceName: z.ZodDefault<z.ZodString>;
36
53
  environment: z.ZodDefault<z.ZodString>;
37
54
  deploymentRevision: z.ZodDefault<z.ZodString>;
55
+ serverVersion: z.ZodOptional<z.ZodString>;
38
56
  databaseUrl: z.ZodDefault<z.ZodString>;
39
57
  dbSchema: z.ZodDefault<z.ZodString>;
40
58
  rlsStrategy: z.ZodDefault<z.ZodEnum<{
@@ -78,7 +96,13 @@ declare const SettingsSchema: z.ZodObject<{
78
96
  delegationSecret: z.ZodOptional<z.ZodString>;
79
97
  streamTokenSecret: z.ZodOptional<z.ZodString>;
80
98
  streamControlEnabled: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
99
+ toolspaceEnabled: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
100
+ toolspaceMaxCallsPerTurn: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
81
101
  environmentsEncryptionKey: z.ZodOptional<z.ZodString>;
102
+ integrationsEnabled: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
103
+ integrationsStateSecret: z.ZodOptional<z.ZodString>;
104
+ integrationsAllowPrivateNetworkTargets: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
105
+ integrationsOauthClientsJson: z.ZodDefault<z.ZodString>;
82
106
  goalMaxAutoContinuations: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
83
107
  goalNoProgressLimit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
84
108
  agentMaxModelCallsPerTurn: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
@@ -93,6 +117,7 @@ declare const SettingsSchema: z.ZodObject<{
93
117
  off: "off";
94
118
  }>>;
95
119
  contextWindowTokens: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
120
+ contextCompactionThresholdRatio: z.ZodPipe<z.ZodDefault<z.ZodCoercedNumber<unknown>>, z.ZodTransform<number, number>>;
96
121
  contextReservedOutputTokens: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
97
122
  contextServerCompactThresholdTokens: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
98
123
  contextCompactSoftFraction: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
@@ -105,6 +130,7 @@ declare const SettingsSchema: z.ZodObject<{
105
130
  authAllowMetrics: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
106
131
  apiHost: z.ZodDefault<z.ZodString>;
107
132
  apiPort: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
133
+ workerHttpPort: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
108
134
  opengeniMcpUrl: z.ZodOptional<z.ZodString>;
109
135
  corsAllowOriginRegex: z.ZodDefault<z.ZodString>;
110
136
  openaiProvider: z.ZodDefault<z.ZodEnum<{
@@ -318,7 +344,24 @@ declare const SettingsSchema: z.ZodObject<{
318
344
  allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
319
345
  timeoutMs: z.ZodOptional<z.ZodNumber>;
320
346
  cacheToolsList: z.ZodDefault<z.ZodBoolean>;
347
+ requireApproval: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
321
348
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
349
+ connectionRef: z.ZodOptional<z.ZodObject<{
350
+ connectionId: z.ZodOptional<z.ZodString>;
351
+ providerDomain: z.ZodString;
352
+ kind: z.ZodOptional<z.ZodEnum<{
353
+ oauth2: "oauth2";
354
+ api_key: "api_key";
355
+ app_install: "app_install";
356
+ delegated: "delegated";
357
+ }>>;
358
+ scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
359
+ resource: z.ZodOptional<z.ZodString>;
360
+ subjectScope: z.ZodOptional<z.ZodEnum<{
361
+ workspace: "workspace";
362
+ subject: "subject";
363
+ }>>;
364
+ }, z.core.$strict>>;
322
365
  }, z.core.$strip>>>;
323
366
  }, z.core.$strip>;
324
367
  type Settings = z.infer<typeof SettingsSchema>;
@@ -392,6 +435,16 @@ declare const RegistryProviderSchema: z.ZodObject<{
392
435
  }, z.core.$strip>>;
393
436
  }, z.core.$strip>;
394
437
  type RegistryProvider = z.infer<typeof RegistryProviderSchema>;
438
+ declare const IntegrationOAuthClientConfigSchema: z.ZodObject<{
439
+ clientId: z.ZodString;
440
+ clientSecret: z.ZodOptional<z.ZodString>;
441
+ tokenEndpointAuthMethod: z.ZodDefault<z.ZodEnum<{
442
+ none: "none";
443
+ client_secret_post: "client_secret_post";
444
+ client_secret_basic: "client_secret_basic";
445
+ }>>;
446
+ }, z.core.$strip>;
447
+ type IntegrationOAuthClientConfig = z.infer<typeof IntegrationOAuthClientConfigSchema>;
395
448
  /**
396
449
  * Runtime-resolved provider (built-in or registry), client-construction-ready.
397
450
  * The built-in OpenAI/Azure provider is always present and always "responses";
@@ -517,7 +570,7 @@ declare function contextInputBudgetTokens(settings: Pick<Settings, "contextWindo
517
570
  * floor(B * softFraction). This is what sidesteps the SDK's wrong 240k
518
571
  * fallback for gpt-5.5 (which is absent from its hardcoded window map).
519
572
  */
520
- declare function contextServerCompactThreshold(settings: Pick<Settings, "contextWindowTokens" | "contextReservedOutputTokens" | "contextServerCompactThresholdTokens" | "contextCompactSoftFraction">): number;
573
+ declare function contextServerCompactThreshold(settings: Pick<Settings, "contextWindowTokens" | "contextReservedOutputTokens" | "contextServerCompactThresholdTokens" | "contextCompactSoftFraction" | "contextCompactionThresholdRatio">): number;
521
574
  declare function configuredStaticUsageLimits(settings: Settings): StaticUsageLimitsConfig;
522
575
  declare function configuredEntitlements(settings: Settings): EntitlementsConfig;
523
576
  declare function calculateModelUsageCostMicros(settings: Settings, model: string, usage: ModelUsageInput): number;
@@ -570,7 +623,9 @@ declare function collectGitIdentityEnvironment(settings: Settings): Record<strin
570
623
  * simply yields no auth); the BLOCKING attach-vs-turn error this helper fixes is
571
624
  * for the common (no-repo) and workspace-environment-attached cases.
572
625
  */
573
- declare function stableSandboxEnvironmentForRun(settings: Settings, workspaceEnvironment?: Record<string, string>): Record<string, string>;
626
+ declare function stableSandboxEnvironmentForRun(settings: Settings, workspaceEnvironment?: Record<string, string>, options?: {
627
+ workspaceId?: string;
628
+ }): Record<string, string>;
574
629
  /**
575
630
  * Whether a resource set carries a GitHub-App-connected repository (installation
576
631
  * + repository ids present) — the SAME predicate the worker turn uses to decide
@@ -631,6 +686,7 @@ declare function sandboxWarmRateMicrosPerSecond(settings: Settings, backend: str
631
686
  * name so a malformed registry fails fast at boot (validateSettings calls this).
632
687
  */
633
688
  declare function parseModelProvidersJson(raw: string): RegistryProvider[];
689
+ declare function parseIntegrationsOauthClientsJson(raw: string | undefined): Record<string, IntegrationOAuthClientConfig>;
634
690
  declare function parseStaticUsageLimitsJson(raw: string): StaticUsageLimitsConfig;
635
691
  declare function parseStaticEntitlementsJson(raw: string): EntitlementsConfig;
636
692
  /**
@@ -655,6 +711,7 @@ declare function parseStaticEntitlementsJson(raw: string): EntitlementsConfig;
655
711
  * the one binding a mounted embed cannot leave unset.
656
712
  */
657
713
  declare function firstPartyMcpBaseUrl(settings: Settings): string;
714
+ declare function firstPartyMcpWorkspaceUrl(settings: Settings, workspaceId: string): string;
658
715
  /**
659
716
  * Resolve the secret used to sign/verify scoped stream tokens (master-spine
660
717
  * §C.3). Falls back to `delegationSecret` (the same HMAC envelope family —
@@ -719,4 +776,4 @@ interface NatsControlPlaneAuth {
719
776
  }
720
777
  declare function resolveNatsControlPlaneAuth(settings: Settings): NatsControlPlaneAuth | null;
721
778
 
722
- export { AGENT_INSTRUCTIONS_CORE_PLACEHOLDER, type ConfiguredModel, type ContextCompactionMode, DEFAULT_AGENT_INSTRUCTIONS, type EntitlementsConfig, type McpServerConfig, type ModelPricing, ModelProviderApi, type ModelUsageInput, type NatsCalloutConfig, type NatsControlPlaneAuth, type RegistryProvider, RegistryProviderKind, type ResolvedModelProvider, SANDBOX_REQUIRED_ENV, type SandboxRequiredEnv, type Settings, type StartupRetryOptions, type StaticUsageLimitsConfig, applyGitAuthPointerEnvironment, calculateModelUsageCostMicros, collectGitIdentityEnvironment, collectSandboxEnvironment, configuredAllowedModels, configuredAllowedReasoningEfforts, configuredEntitlements, configuredModelPricing, configuredModels, configuredProviders, configuredStaticUsageLimits, contextInputBudgetTokens, contextServerCompactThreshold, dbSearchPath, defaultModelPricing, effectiveModalIdleTimeoutSeconds, environmentsEncryptionKeyBytes, firstPartyMcpBaseUrl, getSettings, hasGitHubRepositorySelection, parseExposedPorts, parseMcpServers, parseModelPricingJson, parseModelProvidersJson, parseSandboxWarmRateJson, parseStaticEntitlementsJson, parseStaticUsageLimitsJson, requiredSandboxEnvForBackend, resolveContextCompactionMode, resolveEnrollmentSigningSecret, resolveModelProvider, resolveNatsCalloutConfig, resolveNatsControlPlaneAuth, resolveProviderApiKey, resolveRelayTokenSecret, resolveStreamTokenSecret, retryStartupDependency, sandboxEnvironmentVariableNames, sandboxLifecycleHookIds, sandboxPreparationProfiles, sandboxWarmRateMicrosPerSecond, stableSandboxEnvironmentForRun, startupRetryOptions, streamTokenDegraded };
779
+ export { AGENT_INSTRUCTIONS_CORE_PLACEHOLDER, type ConfiguredModel, type ContextCompactionMode, DEFAULT_AGENT_INSTRUCTIONS, type EntitlementsConfig, type IntegrationOAuthClientConfig, IntegrationOAuthClientConfigSchema, type McpServerConfig, type McpServerConnectionRef, McpServerConnectionRefSchema, type ModelPricing, ModelProviderApi, type ModelUsageInput, type NatsCalloutConfig, type NatsControlPlaneAuth, type RegistryProvider, RegistryProviderKind, type ResolvedModelProvider, SANDBOX_REQUIRED_ENV, type SandboxRequiredEnv, type Settings, type StartupRetryOptions, type StaticUsageLimitsConfig, applyGitAuthPointerEnvironment, calculateModelUsageCostMicros, collectGitIdentityEnvironment, collectSandboxEnvironment, configuredAllowedModels, configuredAllowedReasoningEfforts, configuredEntitlements, configuredModelPricing, configuredModels, configuredProviders, configuredStaticUsageLimits, contextInputBudgetTokens, contextServerCompactThreshold, dbSearchPath, defaultModelPricing, effectiveModalIdleTimeoutSeconds, environmentsEncryptionKeyBytes, firstPartyMcpBaseUrl, firstPartyMcpWorkspaceUrl, getSettings, hasGitHubRepositorySelection, parseExposedPorts, parseIntegrationsOauthClientsJson, parseMcpServers, parseModelPricingJson, parseModelProvidersJson, parseSandboxWarmRateJson, parseStaticEntitlementsJson, parseStaticUsageLimitsJson, requiredSandboxEnvForBackend, resolveContextCompactionMode, resolveEnrollmentSigningSecret, resolveModelProvider, resolveNatsCalloutConfig, resolveNatsControlPlaneAuth, resolveProviderApiKey, resolveRelayTokenSecret, resolveStreamTokenSecret, retryStartupDependency, sandboxEnvironmentVariableNames, sandboxLifecycleHookIds, sandboxPreparationProfiles, sandboxWarmRateMicrosPerSecond, stableSandboxEnvironmentForRun, startupRetryOptions, streamTokenDegraded };
package/dist/index.js CHANGED
@@ -73,10 +73,21 @@ var DEFAULT_AGENT_INSTRUCTIONS = [
73
73
  "Return concise, factual summaries with files changed, commands run, and remaining blockers.",
74
74
  AGENT_INSTRUCTIONS_CORE_PLACEHOLDER
75
75
  ].join(" ");
76
+ var McpServerConnectionRefSchema = z.object({
77
+ connectionId: z.string().uuid().optional(),
78
+ providerDomain: z.string().min(1),
79
+ kind: z.enum(["oauth2", "api_key", "app_install", "delegated"]).optional(),
80
+ scopes: z.array(z.string().min(1)).optional(),
81
+ resource: z.string().min(1).optional(),
82
+ subjectScope: z.enum(["workspace", "subject"]).optional()
83
+ }).strict();
76
84
  var SettingsSchema = z.object({
77
85
  serviceName: z.string().default("opengeni"),
78
86
  environment: z.string().default("local"),
79
87
  deploymentRevision: z.string().default("dev"),
88
+ // The release-train version baked into official images (OPENGENI_SERVER_VERSION).
89
+ // Absent on dev/source builds — consumers must treat it as optional.
90
+ serverVersion: z.string().optional(),
80
91
  databaseUrl: z.string().default("postgres://opengeni:opengeni@127.0.0.1:5432/opengeni"),
81
92
  // Step I (§7.8 runtime half). Dedicated Postgres schema for the EMBEDDED
82
93
  // topology. Default "" → standalone: no search_path scoping, server default
@@ -121,7 +132,13 @@ var SettingsSchema = z.object({
121
132
  // holder of stream:control gets 403 until this flips. Keeps stream:control a
122
133
  // declared-but-inert permission so later hardening is a flag flip.
123
134
  streamControlEnabled: EnvBoolean.default(false),
135
+ toolspaceEnabled: EnvBoolean.default(false),
136
+ toolspaceMaxCallsPerTurn: z.coerce.number().int().positive().default(200),
124
137
  environmentsEncryptionKey: z.string().optional(),
138
+ integrationsEnabled: EnvBoolean.default(false),
139
+ integrationsStateSecret: z.string().optional(),
140
+ integrationsAllowPrivateNetworkTargets: EnvBoolean.default(false),
141
+ integrationsOauthClientsJson: z.string().default("{}"),
125
142
  // Session goal guard rails. Goals are designed for runs that legitimately
126
143
  // span days, so length is bounded by pathology detection (no-progress
127
144
  // streaks, budget exhaustion), never by count. goalMaxAutoContinuations is
@@ -158,15 +175,26 @@ var SettingsSchema = z.object({
158
175
  // derived from these settings on the server path, and use the same numbers to
159
176
  // budget the client path.
160
177
  contextWindowTokens: z.coerce.number().int().positive().default(105e4),
178
+ // Proactive compaction threshold as a ratio of the model context window.
179
+ // Defaults to 60% and is clamped to [0.3, 0.9] so deployments can tune the
180
+ // trigger without accidentally disabling compaction or waiting until the
181
+ // provider is already at the cliff.
182
+ contextCompactionThresholdRatio: z.coerce.number().default(0.6).transform((value) => {
183
+ if (!Number.isFinite(value)) {
184
+ return 0.6;
185
+ }
186
+ return Math.min(0.9, Math.max(0.3, value));
187
+ }),
161
188
  // Tokens reserved for model output; subtracted from the window to get the
162
189
  // usable input budget B = contextWindowTokens - contextReservedOutputTokens.
163
190
  contextReservedOutputTokens: z.coerce.number().int().nonnegative().default(128e3),
164
191
  // Server path only: explicit compact_threshold (tokens) handed to the SDK's
165
- // StaticCompactionPolicy. Defaults to floor(B * contextCompactSoftFraction)
166
- // when unset.
192
+ // StaticCompactionPolicy. Defaults to floor(contextWindowTokens *
193
+ // contextCompactionThresholdRatio) when unset.
167
194
  contextServerCompactThresholdTokens: z.coerce.number().int().positive().optional(),
168
- // Server path/back-compat knobs. The client compaction path ignores these:
169
- // it uses Codex-parity 0.9 * (window - reserved output - 20k summary buffer).
195
+ // Deprecated back-compat knobs. The threshold is now controlled by
196
+ // contextCompactionThresholdRatio; these remain parsed so older deployments do
197
+ // not fail boot when their env still contains them.
170
198
  contextCompactSoftFraction: z.coerce.number().positive().max(1).default(0.7),
171
199
  contextCompactHardFraction: z.coerce.number().positive().max(1).default(0.85),
172
200
  // Deprecated for the client path; parsed for env/back-compat only.
@@ -180,6 +208,7 @@ var SettingsSchema = z.object({
180
208
  authAllowMetrics: EnvBoolean.default(false),
181
209
  apiHost: z.string().default("0.0.0.0"),
182
210
  apiPort: z.coerce.number().int().positive().default(8e3),
211
+ workerHttpPort: z.coerce.number().int().positive().default(8001),
183
212
  opengeniMcpUrl: z.string().url().optional(),
184
213
  corsAllowOriginRegex: z.string().default(String.raw`^https?://(localhost|127\.0\.0\.1)(:\d+)?$`),
185
214
  openaiProvider: z.enum(["openai", "azure"]).default("openai"),
@@ -555,13 +584,22 @@ var SettingsSchema = z.object({
555
584
  allowedTools: z.array(z.string().min(1)).optional(),
556
585
  timeoutMs: z.number().int().positive().optional(),
557
586
  cacheToolsList: z.boolean().default(false),
587
+ /**
588
+ * Human-approval policy for this server's tools, overlaid per-run from a
589
+ * session MCP server row (never from OPENGENI_MCP_SERVERS). `true` = all
590
+ * tools require approval; a string[] = only the listed UNPREFIXED tool
591
+ * names do; absent = auto-run (the historical default). Enforced in the
592
+ * runtime by attaching `needsApproval` to the matching MCP tools.
593
+ */
594
+ requireApproval: z.union([z.boolean(), z.array(z.string().min(1))]).optional(),
558
595
  /**
559
596
  * Extra request headers sent to this MCP server (credential injection
560
597
  * for workspace-enabled capability MCPs). Populated at runtime from
561
598
  * encrypted capability-installation credentials; do not put secrets in
562
599
  * OPENGENI_MCP_SERVERS.
563
600
  */
564
- headers: z.record(z.string(), z.string()).optional()
601
+ headers: z.record(z.string(), z.string()).optional(),
602
+ connectionRef: McpServerConnectionRefSchema.optional()
565
603
  })).default([])
566
604
  });
567
605
  var ModelPricingSchema = z.object({
@@ -600,6 +638,11 @@ var RegistryProviderSchema = z.object({
600
638
  defaultHeaders: z.record(z.string(), z.string()).optional(),
601
639
  models: z.array(RegistryModelSchema).min(1)
602
640
  });
641
+ var IntegrationOAuthClientConfigSchema = z.object({
642
+ clientId: z.string().min(1),
643
+ clientSecret: z.string().min(1).optional(),
644
+ tokenEndpointAuthMethod: z.enum(["none", "client_secret_post", "client_secret_basic"]).default("none")
645
+ });
603
646
  var defaultModelPricing = {
604
647
  "gpt-5.5": {
605
648
  inputMicrosPerMillionTokens: 5e6,
@@ -719,6 +762,7 @@ function getSettings() {
719
762
  serviceName: optional("OPENGENI_SERVICE_NAME"),
720
763
  environment: optional("OPENGENI_ENVIRONMENT"),
721
764
  deploymentRevision: optional("OPENGENI_DEPLOYMENT_REVISION") ?? optional("SOURCE_VERSION") ?? optional("GITHUB_SHA"),
765
+ serverVersion: optional("OPENGENI_SERVER_VERSION"),
722
766
  databaseUrl: optional("OPENGENI_DATABASE_URL"),
723
767
  dbSchema: optional("OPENGENI_DB_SCHEMA"),
724
768
  rlsStrategy: optional("OPENGENI_RLS_STRATEGY"),
@@ -744,13 +788,20 @@ function getSettings() {
744
788
  delegationSecret: optional("OPENGENI_DELEGATION_SECRET"),
745
789
  streamTokenSecret: optional("OPENGENI_STREAM_TOKEN_SECRET"),
746
790
  streamControlEnabled: optional("OPENGENI_STREAM_CONTROL_ENABLED"),
791
+ toolspaceEnabled: optional("OPENGENI_TOOLSPACE_ENABLED"),
792
+ toolspaceMaxCallsPerTurn: optional("OPENGENI_TOOLSPACE_MAX_CALLS_PER_TURN"),
747
793
  environmentsEncryptionKey: optional("OPENGENI_ENVIRONMENTS_ENCRYPTION_KEY"),
794
+ integrationsEnabled: optional("OPENGENI_INTEGRATIONS_ENABLED"),
795
+ integrationsStateSecret: optional("OPENGENI_INTEGRATIONS_STATE_SECRET"),
796
+ integrationsAllowPrivateNetworkTargets: optional("OPENGENI_INTEGRATIONS_ALLOW_PRIVATE_NETWORK_TARGETS"),
797
+ integrationsOauthClientsJson: optional("OPENGENI_INTEGRATIONS_OAUTH_CLIENTS_JSON"),
748
798
  goalMaxAutoContinuations: optional("OPENGENI_GOAL_MAX_AUTO_CONTINUATIONS"),
749
799
  goalNoProgressLimit: optional("OPENGENI_GOAL_NO_PROGRESS_LIMIT"),
750
800
  agentMaxModelCallsPerTurn: optional("OPENGENI_AGENT_MAX_MODEL_CALLS_PER_TURN"),
751
801
  sessionHistorySource: optional("OPENGENI_SESSION_HISTORY_SOURCE"),
752
802
  contextCompactionMode: optional("OPENGENI_CONTEXT_COMPACTION_MODE"),
753
803
  contextWindowTokens: optional("OPENGENI_CONTEXT_WINDOW_TOKENS"),
804
+ contextCompactionThresholdRatio: optional("OPENGENI_COMPACTION_THRESHOLD_RATIO"),
754
805
  contextReservedOutputTokens: optional("OPENGENI_CONTEXT_RESERVED_OUTPUT_TOKENS"),
755
806
  contextServerCompactThresholdTokens: optional("OPENGENI_CONTEXT_SERVER_COMPACT_THRESHOLD_TOKENS"),
756
807
  contextCompactSoftFraction: optional("OPENGENI_CONTEXT_COMPACT_SOFT_FRACTION"),
@@ -763,6 +814,7 @@ function getSettings() {
763
814
  authAllowMetrics: optional("OPENGENI_AUTH_ALLOW_METRICS"),
764
815
  apiHost: optional("OPENGENI_API_HOST"),
765
816
  apiPort: optional("OPENGENI_API_PORT"),
817
+ workerHttpPort: optional("OPENGENI_WORKER_HTTP_PORT"),
766
818
  opengeniMcpUrl: optional("OPENGENI_MCP_URL"),
767
819
  corsAllowOriginRegex: optional("OPENGENI_CORS_ALLOW_ORIGIN_REGEX"),
768
820
  openaiProvider: optional("OPENGENI_OPENAI_PROVIDER"),
@@ -1080,7 +1132,7 @@ function contextServerCompactThreshold(settings) {
1080
1132
  if (settings.contextServerCompactThresholdTokens) {
1081
1133
  return settings.contextServerCompactThresholdTokens;
1082
1134
  }
1083
- return Math.floor(contextInputBudgetTokens(settings) * settings.contextCompactSoftFraction);
1135
+ return Math.floor(settings.contextWindowTokens * settings.contextCompactionThresholdRatio);
1084
1136
  }
1085
1137
  function configuredStaticUsageLimits(settings) {
1086
1138
  return parseStaticUsageLimitsJson(settings.staticUsageLimitsJson);
@@ -1143,7 +1195,7 @@ function collectGitIdentityEnvironment(settings) {
1143
1195
  GIT_COMMITTER_EMAIL: settings.gitCommitterEmail ?? settings.gitAuthorEmail
1144
1196
  }).filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0));
1145
1197
  }
1146
- function stableSandboxEnvironmentForRun(settings, workspaceEnvironment = {}) {
1198
+ function stableSandboxEnvironmentForRun(settings, workspaceEnvironment = {}, options = {}) {
1147
1199
  const environment = {
1148
1200
  ...collectSandboxEnvironment(settings),
1149
1201
  ...collectGitIdentityEnvironment(settings),
@@ -1154,6 +1206,12 @@ function stableSandboxEnvironmentForRun(settings, workspaceEnvironment = {}) {
1154
1206
  environment.HOME ??= descriptor.workspaceRoot;
1155
1207
  }
1156
1208
  environment.OPENGENI_GIT_TOKEN_FILE ??= `${environment.HOME ?? descriptor.workspaceRoot}/.opengeni/git-token`;
1209
+ if (settings.toolspaceEnabled) {
1210
+ environment.OPENGENI_TOOLSPACE_TOKEN_FILE ??= `${environment.HOME ?? descriptor.workspaceRoot}/.opengeni/toolspace-token`;
1211
+ if (options.workspaceId) {
1212
+ environment.OPENGENI_TOOLSPACE_URL ??= firstPartyMcpWorkspaceUrl(settings, options.workspaceId);
1213
+ }
1214
+ }
1157
1215
  return environment;
1158
1216
  }
1159
1217
  function hasGitHubRepositorySelection(resources) {
@@ -1327,6 +1385,33 @@ function parseModelProvidersJson(raw) {
1327
1385
  return result.data;
1328
1386
  });
1329
1387
  }
1388
+ function parseIntegrationsOauthClientsJson(raw) {
1389
+ if (!raw?.trim() || raw.trim() === "{}") {
1390
+ return {};
1391
+ }
1392
+ let parsed;
1393
+ try {
1394
+ parsed = JSON.parse(raw);
1395
+ } catch (error) {
1396
+ const message = error instanceof Error ? error.message : String(error);
1397
+ throw new Error(`OPENGENI_INTEGRATIONS_OAUTH_CLIENTS_JSON must be valid JSON: ${message}`);
1398
+ }
1399
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1400
+ throw new Error("OPENGENI_INTEGRATIONS_OAUTH_CLIENTS_JSON must be a JSON object keyed by authorization-server issuer or URL");
1401
+ }
1402
+ const out = {};
1403
+ for (const [key, value] of Object.entries(parsed)) {
1404
+ if (!key.trim()) {
1405
+ throw new Error("OPENGENI_INTEGRATIONS_OAUTH_CLIENTS_JSON contains an empty issuer key");
1406
+ }
1407
+ const result = IntegrationOAuthClientConfigSchema.safeParse(value);
1408
+ if (!result.success) {
1409
+ throw new Error(`OPENGENI_INTEGRATIONS_OAUTH_CLIENTS_JSON client for ${key} is invalid: ${result.error.message}`);
1410
+ }
1411
+ out[key] = result.data;
1412
+ }
1413
+ return out;
1414
+ }
1330
1415
  function parseStaticUsageLimitsJson(raw) {
1331
1416
  if (!raw.trim() || raw.trim() === "{}") {
1332
1417
  return {};
@@ -1407,7 +1492,7 @@ function ensureBuiltInMcpServers(settings) {
1407
1492
  id: "docs",
1408
1493
  name: "Document Search",
1409
1494
  url: firstPartyDocsMcpUrl,
1410
- allowedTools: ["search_documents", "fetch_document_chunk", "list_document_bases"],
1495
+ allowedTools: ["search_documents", "fetch_document_chunk", "list_document_bases", "knowledge_search", "knowledge_fetch", "memory_search", "memory_propose"],
1411
1496
  cacheToolsList: false
1412
1497
  }],
1413
1498
  ...existing
@@ -1416,6 +1501,17 @@ function ensureBuiltInMcpServers(settings) {
1416
1501
  function firstPartyMcpBaseUrl(settings) {
1417
1502
  return settings.opengeniMcpUrl ?? `http://127.0.0.1:${settings.apiPort}/v1/workspaces/{workspaceId}/mcp`;
1418
1503
  }
1504
+ function firstPartyMcpWorkspaceUrl(settings, workspaceId) {
1505
+ const raw = firstPartyMcpBaseUrl(settings);
1506
+ if (raw.includes("{workspaceId}")) {
1507
+ return raw.replaceAll("{workspaceId}", workspaceId);
1508
+ }
1509
+ const url = new URL(raw);
1510
+ url.pathname = `/v1/workspaces/${workspaceId}/mcp`;
1511
+ url.search = "";
1512
+ url.hash = "";
1513
+ return url.toString();
1514
+ }
1419
1515
  function firstPartyMcpServerUrl(settings) {
1420
1516
  return firstPartyMcpBaseUrl(settings);
1421
1517
  }
@@ -1423,6 +1519,9 @@ function firstPartyDocumentsMcpServerUrl(mcpUrl) {
1423
1519
  return `${mcpUrl.replace(/\/+$/, "")}/docs`;
1424
1520
  }
1425
1521
  function validateSettings(settings) {
1522
+ if (settings.toolspaceEnabled && !settings.delegationSecret) {
1523
+ throw new Error("OPENGENI_DELEGATION_SECRET is required when OPENGENI_TOOLSPACE_ENABLED=true");
1524
+ }
1426
1525
  if (settings.productAccessMode === "managed") {
1427
1526
  if (!settings.publicBaseUrl) {
1428
1527
  throw new Error("OPENGENI_PUBLIC_BASE_URL is required when OPENGENI_PRODUCT_ACCESS_MODE=managed");
@@ -1441,6 +1540,18 @@ function validateSettings(settings) {
1441
1540
  }
1442
1541
  }
1443
1542
  environmentsEncryptionKeyBytes(settings);
1543
+ if (settings.integrationsEnabled) {
1544
+ if (settings.productAccessMode === "managed" && !settings.publicBaseUrl) {
1545
+ throw new Error("OPENGENI_PUBLIC_BASE_URL is required when OPENGENI_INTEGRATIONS_ENABLED=true and OPENGENI_PRODUCT_ACCESS_MODE=managed");
1546
+ }
1547
+ if (settings.publicBaseUrl && !settings.publicBaseUrl.startsWith("https://") && !["local", "test"].includes(settings.environment)) {
1548
+ throw new Error("OPENGENI_PUBLIC_BASE_URL must use https when OPENGENI_INTEGRATIONS_ENABLED=true outside local/test");
1549
+ }
1550
+ if (!settings.integrationsStateSecret && !["local", "test"].includes(settings.environment)) {
1551
+ throw new Error("OPENGENI_INTEGRATIONS_STATE_SECRET is required when OPENGENI_INTEGRATIONS_ENABLED=true outside local/test");
1552
+ }
1553
+ }
1554
+ parseIntegrationsOauthClientsJson(settings.integrationsOauthClientsJson);
1444
1555
  if (settings.productAccessMode === "configured" && !["local", "test"].includes(settings.environment) && !settings.delegationSecret && !settings.authRequired) {
1445
1556
  throw new Error("OPENGENI_PRODUCT_ACCESS_MODE=configured requires OPENGENI_DELEGATION_SECRET or OPENGENI_AUTH_REQUIRED=true outside local/test");
1446
1557
  }
@@ -1682,6 +1793,8 @@ function delay(ms) {
1682
1793
  export {
1683
1794
  AGENT_INSTRUCTIONS_CORE_PLACEHOLDER,
1684
1795
  DEFAULT_AGENT_INSTRUCTIONS,
1796
+ IntegrationOAuthClientConfigSchema,
1797
+ McpServerConnectionRefSchema,
1685
1798
  ModelProviderApi,
1686
1799
  RegistryProviderKind,
1687
1800
  SANDBOX_REQUIRED_ENV,
@@ -1703,9 +1816,11 @@ export {
1703
1816
  effectiveModalIdleTimeoutSeconds,
1704
1817
  environmentsEncryptionKeyBytes,
1705
1818
  firstPartyMcpBaseUrl,
1819
+ firstPartyMcpWorkspaceUrl,
1706
1820
  getSettings,
1707
1821
  hasGitHubRepositorySelection,
1708
1822
  parseExposedPorts,
1823
+ parseIntegrationsOauthClientsJson,
1709
1824
  parseMcpServers,
1710
1825
  parseModelPricingJson,
1711
1826
  parseModelProvidersJson,