@opengeni/config 0.2.5 → 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,6 +31,23 @@ 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>;
@@ -79,7 +96,13 @@ declare const SettingsSchema: z.ZodObject<{
79
96
  delegationSecret: z.ZodOptional<z.ZodString>;
80
97
  streamTokenSecret: z.ZodOptional<z.ZodString>;
81
98
  streamControlEnabled: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
99
+ toolspaceEnabled: z.ZodDefault<z.ZodPreprocess<z.ZodBoolean>>;
100
+ toolspaceMaxCallsPerTurn: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
82
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>;
83
106
  goalMaxAutoContinuations: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
84
107
  goalNoProgressLimit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
85
108
  agentMaxModelCallsPerTurn: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
@@ -94,6 +117,7 @@ declare const SettingsSchema: z.ZodObject<{
94
117
  off: "off";
95
118
  }>>;
96
119
  contextWindowTokens: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
120
+ contextCompactionThresholdRatio: z.ZodPipe<z.ZodDefault<z.ZodCoercedNumber<unknown>>, z.ZodTransform<number, number>>;
97
121
  contextReservedOutputTokens: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
98
122
  contextServerCompactThresholdTokens: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
99
123
  contextCompactSoftFraction: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
@@ -320,7 +344,24 @@ declare const SettingsSchema: z.ZodObject<{
320
344
  allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
321
345
  timeoutMs: z.ZodOptional<z.ZodNumber>;
322
346
  cacheToolsList: z.ZodDefault<z.ZodBoolean>;
347
+ requireApproval: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
323
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>>;
324
365
  }, z.core.$strip>>>;
325
366
  }, z.core.$strip>;
326
367
  type Settings = z.infer<typeof SettingsSchema>;
@@ -394,6 +435,16 @@ declare const RegistryProviderSchema: z.ZodObject<{
394
435
  }, z.core.$strip>>;
395
436
  }, z.core.$strip>;
396
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>;
397
448
  /**
398
449
  * Runtime-resolved provider (built-in or registry), client-construction-ready.
399
450
  * The built-in OpenAI/Azure provider is always present and always "responses";
@@ -519,7 +570,7 @@ declare function contextInputBudgetTokens(settings: Pick<Settings, "contextWindo
519
570
  * floor(B * softFraction). This is what sidesteps the SDK's wrong 240k
520
571
  * fallback for gpt-5.5 (which is absent from its hardcoded window map).
521
572
  */
522
- declare function contextServerCompactThreshold(settings: Pick<Settings, "contextWindowTokens" | "contextReservedOutputTokens" | "contextServerCompactThresholdTokens" | "contextCompactSoftFraction">): number;
573
+ declare function contextServerCompactThreshold(settings: Pick<Settings, "contextWindowTokens" | "contextReservedOutputTokens" | "contextServerCompactThresholdTokens" | "contextCompactSoftFraction" | "contextCompactionThresholdRatio">): number;
523
574
  declare function configuredStaticUsageLimits(settings: Settings): StaticUsageLimitsConfig;
524
575
  declare function configuredEntitlements(settings: Settings): EntitlementsConfig;
525
576
  declare function calculateModelUsageCostMicros(settings: Settings, model: string, usage: ModelUsageInput): number;
@@ -572,7 +623,9 @@ declare function collectGitIdentityEnvironment(settings: Settings): Record<strin
572
623
  * simply yields no auth); the BLOCKING attach-vs-turn error this helper fixes is
573
624
  * for the common (no-repo) and workspace-environment-attached cases.
574
625
  */
575
- 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>;
576
629
  /**
577
630
  * Whether a resource set carries a GitHub-App-connected repository (installation
578
631
  * + repository ids present) — the SAME predicate the worker turn uses to decide
@@ -633,6 +686,7 @@ declare function sandboxWarmRateMicrosPerSecond(settings: Settings, backend: str
633
686
  * name so a malformed registry fails fast at boot (validateSettings calls this).
634
687
  */
635
688
  declare function parseModelProvidersJson(raw: string): RegistryProvider[];
689
+ declare function parseIntegrationsOauthClientsJson(raw: string | undefined): Record<string, IntegrationOAuthClientConfig>;
636
690
  declare function parseStaticUsageLimitsJson(raw: string): StaticUsageLimitsConfig;
637
691
  declare function parseStaticEntitlementsJson(raw: string): EntitlementsConfig;
638
692
  /**
@@ -657,6 +711,7 @@ declare function parseStaticEntitlementsJson(raw: string): EntitlementsConfig;
657
711
  * the one binding a mounted embed cannot leave unset.
658
712
  */
659
713
  declare function firstPartyMcpBaseUrl(settings: Settings): string;
714
+ declare function firstPartyMcpWorkspaceUrl(settings: Settings, workspaceId: string): string;
660
715
  /**
661
716
  * Resolve the secret used to sign/verify scoped stream tokens (master-spine
662
717
  * §C.3). Falls back to `delegationSecret` (the same HMAC envelope family —
@@ -721,4 +776,4 @@ interface NatsControlPlaneAuth {
721
776
  }
722
777
  declare function resolveNatsControlPlaneAuth(settings: Settings): NatsControlPlaneAuth | null;
723
778
 
724
- 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,6 +73,14 @@ 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"),
@@ -124,7 +132,13 @@ var SettingsSchema = z.object({
124
132
  // holder of stream:control gets 403 until this flips. Keeps stream:control a
125
133
  // declared-but-inert permission so later hardening is a flag flip.
126
134
  streamControlEnabled: EnvBoolean.default(false),
135
+ toolspaceEnabled: EnvBoolean.default(false),
136
+ toolspaceMaxCallsPerTurn: z.coerce.number().int().positive().default(200),
127
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("{}"),
128
142
  // Session goal guard rails. Goals are designed for runs that legitimately
129
143
  // span days, so length is bounded by pathology detection (no-progress
130
144
  // streaks, budget exhaustion), never by count. goalMaxAutoContinuations is
@@ -161,15 +175,26 @@ var SettingsSchema = z.object({
161
175
  // derived from these settings on the server path, and use the same numbers to
162
176
  // budget the client path.
163
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
+ }),
164
188
  // Tokens reserved for model output; subtracted from the window to get the
165
189
  // usable input budget B = contextWindowTokens - contextReservedOutputTokens.
166
190
  contextReservedOutputTokens: z.coerce.number().int().nonnegative().default(128e3),
167
191
  // Server path only: explicit compact_threshold (tokens) handed to the SDK's
168
- // StaticCompactionPolicy. Defaults to floor(B * contextCompactSoftFraction)
169
- // when unset.
192
+ // StaticCompactionPolicy. Defaults to floor(contextWindowTokens *
193
+ // contextCompactionThresholdRatio) when unset.
170
194
  contextServerCompactThresholdTokens: z.coerce.number().int().positive().optional(),
171
- // Server path/back-compat knobs. The client compaction path ignores these:
172
- // 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.
173
198
  contextCompactSoftFraction: z.coerce.number().positive().max(1).default(0.7),
174
199
  contextCompactHardFraction: z.coerce.number().positive().max(1).default(0.85),
175
200
  // Deprecated for the client path; parsed for env/back-compat only.
@@ -559,13 +584,22 @@ var SettingsSchema = z.object({
559
584
  allowedTools: z.array(z.string().min(1)).optional(),
560
585
  timeoutMs: z.number().int().positive().optional(),
561
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(),
562
595
  /**
563
596
  * Extra request headers sent to this MCP server (credential injection
564
597
  * for workspace-enabled capability MCPs). Populated at runtime from
565
598
  * encrypted capability-installation credentials; do not put secrets in
566
599
  * OPENGENI_MCP_SERVERS.
567
600
  */
568
- headers: z.record(z.string(), z.string()).optional()
601
+ headers: z.record(z.string(), z.string()).optional(),
602
+ connectionRef: McpServerConnectionRefSchema.optional()
569
603
  })).default([])
570
604
  });
571
605
  var ModelPricingSchema = z.object({
@@ -604,6 +638,11 @@ var RegistryProviderSchema = z.object({
604
638
  defaultHeaders: z.record(z.string(), z.string()).optional(),
605
639
  models: z.array(RegistryModelSchema).min(1)
606
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
+ });
607
646
  var defaultModelPricing = {
608
647
  "gpt-5.5": {
609
648
  inputMicrosPerMillionTokens: 5e6,
@@ -749,13 +788,20 @@ function getSettings() {
749
788
  delegationSecret: optional("OPENGENI_DELEGATION_SECRET"),
750
789
  streamTokenSecret: optional("OPENGENI_STREAM_TOKEN_SECRET"),
751
790
  streamControlEnabled: optional("OPENGENI_STREAM_CONTROL_ENABLED"),
791
+ toolspaceEnabled: optional("OPENGENI_TOOLSPACE_ENABLED"),
792
+ toolspaceMaxCallsPerTurn: optional("OPENGENI_TOOLSPACE_MAX_CALLS_PER_TURN"),
752
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"),
753
798
  goalMaxAutoContinuations: optional("OPENGENI_GOAL_MAX_AUTO_CONTINUATIONS"),
754
799
  goalNoProgressLimit: optional("OPENGENI_GOAL_NO_PROGRESS_LIMIT"),
755
800
  agentMaxModelCallsPerTurn: optional("OPENGENI_AGENT_MAX_MODEL_CALLS_PER_TURN"),
756
801
  sessionHistorySource: optional("OPENGENI_SESSION_HISTORY_SOURCE"),
757
802
  contextCompactionMode: optional("OPENGENI_CONTEXT_COMPACTION_MODE"),
758
803
  contextWindowTokens: optional("OPENGENI_CONTEXT_WINDOW_TOKENS"),
804
+ contextCompactionThresholdRatio: optional("OPENGENI_COMPACTION_THRESHOLD_RATIO"),
759
805
  contextReservedOutputTokens: optional("OPENGENI_CONTEXT_RESERVED_OUTPUT_TOKENS"),
760
806
  contextServerCompactThresholdTokens: optional("OPENGENI_CONTEXT_SERVER_COMPACT_THRESHOLD_TOKENS"),
761
807
  contextCompactSoftFraction: optional("OPENGENI_CONTEXT_COMPACT_SOFT_FRACTION"),
@@ -1086,7 +1132,7 @@ function contextServerCompactThreshold(settings) {
1086
1132
  if (settings.contextServerCompactThresholdTokens) {
1087
1133
  return settings.contextServerCompactThresholdTokens;
1088
1134
  }
1089
- return Math.floor(contextInputBudgetTokens(settings) * settings.contextCompactSoftFraction);
1135
+ return Math.floor(settings.contextWindowTokens * settings.contextCompactionThresholdRatio);
1090
1136
  }
1091
1137
  function configuredStaticUsageLimits(settings) {
1092
1138
  return parseStaticUsageLimitsJson(settings.staticUsageLimitsJson);
@@ -1149,7 +1195,7 @@ function collectGitIdentityEnvironment(settings) {
1149
1195
  GIT_COMMITTER_EMAIL: settings.gitCommitterEmail ?? settings.gitAuthorEmail
1150
1196
  }).filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0));
1151
1197
  }
1152
- function stableSandboxEnvironmentForRun(settings, workspaceEnvironment = {}) {
1198
+ function stableSandboxEnvironmentForRun(settings, workspaceEnvironment = {}, options = {}) {
1153
1199
  const environment = {
1154
1200
  ...collectSandboxEnvironment(settings),
1155
1201
  ...collectGitIdentityEnvironment(settings),
@@ -1160,6 +1206,12 @@ function stableSandboxEnvironmentForRun(settings, workspaceEnvironment = {}) {
1160
1206
  environment.HOME ??= descriptor.workspaceRoot;
1161
1207
  }
1162
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
+ }
1163
1215
  return environment;
1164
1216
  }
1165
1217
  function hasGitHubRepositorySelection(resources) {
@@ -1333,6 +1385,33 @@ function parseModelProvidersJson(raw) {
1333
1385
  return result.data;
1334
1386
  });
1335
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
+ }
1336
1415
  function parseStaticUsageLimitsJson(raw) {
1337
1416
  if (!raw.trim() || raw.trim() === "{}") {
1338
1417
  return {};
@@ -1413,7 +1492,7 @@ function ensureBuiltInMcpServers(settings) {
1413
1492
  id: "docs",
1414
1493
  name: "Document Search",
1415
1494
  url: firstPartyDocsMcpUrl,
1416
- 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"],
1417
1496
  cacheToolsList: false
1418
1497
  }],
1419
1498
  ...existing
@@ -1422,6 +1501,17 @@ function ensureBuiltInMcpServers(settings) {
1422
1501
  function firstPartyMcpBaseUrl(settings) {
1423
1502
  return settings.opengeniMcpUrl ?? `http://127.0.0.1:${settings.apiPort}/v1/workspaces/{workspaceId}/mcp`;
1424
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
+ }
1425
1515
  function firstPartyMcpServerUrl(settings) {
1426
1516
  return firstPartyMcpBaseUrl(settings);
1427
1517
  }
@@ -1429,6 +1519,9 @@ function firstPartyDocumentsMcpServerUrl(mcpUrl) {
1429
1519
  return `${mcpUrl.replace(/\/+$/, "")}/docs`;
1430
1520
  }
1431
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
+ }
1432
1525
  if (settings.productAccessMode === "managed") {
1433
1526
  if (!settings.publicBaseUrl) {
1434
1527
  throw new Error("OPENGENI_PUBLIC_BASE_URL is required when OPENGENI_PRODUCT_ACCESS_MODE=managed");
@@ -1447,6 +1540,18 @@ function validateSettings(settings) {
1447
1540
  }
1448
1541
  }
1449
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);
1450
1555
  if (settings.productAccessMode === "configured" && !["local", "test"].includes(settings.environment) && !settings.delegationSecret && !settings.authRequired) {
1451
1556
  throw new Error("OPENGENI_PRODUCT_ACCESS_MODE=configured requires OPENGENI_DELEGATION_SECRET or OPENGENI_AUTH_REQUIRED=true outside local/test");
1452
1557
  }
@@ -1688,6 +1793,8 @@ function delay(ms) {
1688
1793
  export {
1689
1794
  AGENT_INSTRUCTIONS_CORE_PLACEHOLDER,
1690
1795
  DEFAULT_AGENT_INSTRUCTIONS,
1796
+ IntegrationOAuthClientConfigSchema,
1797
+ McpServerConnectionRefSchema,
1691
1798
  ModelProviderApi,
1692
1799
  RegistryProviderKind,
1693
1800
  SANDBOX_REQUIRED_ENV,
@@ -1709,9 +1816,11 @@ export {
1709
1816
  effectiveModalIdleTimeoutSeconds,
1710
1817
  environmentsEncryptionKeyBytes,
1711
1818
  firstPartyMcpBaseUrl,
1819
+ firstPartyMcpWorkspaceUrl,
1712
1820
  getSettings,
1713
1821
  hasGitHubRepositorySelection,
1714
1822
  parseExposedPorts,
1823
+ parseIntegrationsOauthClientsJson,
1715
1824
  parseMcpServers,
1716
1825
  parseModelPricingJson,
1717
1826
  parseModelProvidersJson,