@amodalai/runtime 0.1.18 → 0.1.20
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/dist/src/agent/config-watcher.d.ts +2 -2
- package/dist/src/agent/config-watcher.js.map +1 -1
- package/dist/src/agent/local-server.js +6 -6
- package/dist/src/agent/local-server.js.map +1 -1
- package/dist/src/agent/proactive/proactive-runner.d.ts +2 -2
- package/dist/src/agent/proactive/proactive-runner.js.map +1 -1
- package/dist/src/agent/routes/chat.test.js +1 -1
- package/dist/src/agent/routes/chat.test.js.map +1 -1
- package/dist/src/agent/routes/evals.js +3 -3
- package/dist/src/agent/routes/evals.js.map +1 -1
- package/dist/src/agent/routes/inspect.js +5 -5
- package/dist/src/agent/routes/inspect.js.map +1 -1
- package/dist/src/agent/routes/inspect.test.js +3 -3
- package/dist/src/agent/routes/inspect.test.js.map +1 -1
- package/dist/src/agent/routes/stores.d.ts +2 -2
- package/dist/src/agent/routes/stores.test.js.map +1 -1
- package/dist/src/agent/routes/task.test.js +1 -1
- package/dist/src/agent/routes/task.test.js.map +1 -1
- package/dist/src/agent/snapshot-server.d.ts +4 -4
- package/dist/src/agent/snapshot-server.js +14 -14
- package/dist/src/agent/snapshot-server.js.map +1 -1
- package/dist/src/agent/user-context-fetcher.d.ts +2 -2
- package/dist/src/agent/user-context-fetcher.js.map +1 -1
- package/dist/src/server.d.ts +2 -0
- package/dist/src/server.js +1 -0
- package/dist/src/server.js.map +1 -1
- package/dist/src/session/session-manager.d.ts +17 -14
- package/dist/src/session/session-manager.js +90 -74
- package/dist/src/session/session-manager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
6
|
import express from 'express';
|
|
7
|
-
import { loadSnapshotFromFile,
|
|
7
|
+
import { loadSnapshotFromFile, snapshotToBundle } from '@amodalai/core';
|
|
8
8
|
import { SessionManager } from '../session/session-manager.js';
|
|
9
9
|
import { LocalToolExecutor } from './tool-executor-local.js';
|
|
10
10
|
import { createChatRouter } from './routes/chat.js';
|
|
@@ -17,27 +17,27 @@ import { errorHandler } from '../middleware/error-handler.js';
|
|
|
17
17
|
* locally before deploying to the platform.
|
|
18
18
|
*/
|
|
19
19
|
export async function createSnapshotServer(config) {
|
|
20
|
-
let
|
|
20
|
+
let bundle;
|
|
21
21
|
let deployId;
|
|
22
|
-
if (config.
|
|
23
|
-
|
|
24
|
-
deployId =
|
|
22
|
+
if (config.bundle) {
|
|
23
|
+
bundle = config.bundle;
|
|
24
|
+
deployId = bundle.origin;
|
|
25
25
|
}
|
|
26
26
|
else if (config.snapshot) {
|
|
27
|
-
|
|
27
|
+
bundle = snapshotToBundle(config.snapshot, `snapshot:${config.snapshot.deployId}`);
|
|
28
28
|
deployId = config.snapshot.deployId;
|
|
29
29
|
}
|
|
30
30
|
else if (config.snapshotPath) {
|
|
31
31
|
const snapshot = await loadSnapshotFromFile(config.snapshotPath);
|
|
32
|
-
|
|
32
|
+
bundle = snapshotToBundle(snapshot, config.snapshotPath);
|
|
33
33
|
deployId = snapshot.deployId;
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
throw new Error('One of snapshotPath, snapshot, or
|
|
36
|
+
throw new Error('One of snapshotPath, snapshot, or bundle must be provided');
|
|
37
37
|
}
|
|
38
38
|
// Set up tool executor — use injected executor if provided, otherwise local
|
|
39
39
|
let toolExecutor = config.toolExecutor;
|
|
40
|
-
if (!toolExecutor &&
|
|
40
|
+
if (!toolExecutor && bundle.tools.length > 0) {
|
|
41
41
|
toolExecutor = new LocalToolExecutor();
|
|
42
42
|
}
|
|
43
43
|
const sessionManager = new SessionManager({
|
|
@@ -49,7 +49,7 @@ export async function createSnapshotServer(config) {
|
|
|
49
49
|
targetDir: process.cwd(),
|
|
50
50
|
},
|
|
51
51
|
ttlMs: config.sessionTtlMs,
|
|
52
|
-
|
|
52
|
+
bundle,
|
|
53
53
|
toolExecutor,
|
|
54
54
|
shellExecutor: config.shellExecutor,
|
|
55
55
|
});
|
|
@@ -74,9 +74,9 @@ export async function createSnapshotServer(config) {
|
|
|
74
74
|
status: 'ok',
|
|
75
75
|
mode: 'snapshot',
|
|
76
76
|
deploy_id: deployId,
|
|
77
|
-
agent_name:
|
|
78
|
-
connections:
|
|
79
|
-
skills:
|
|
77
|
+
agent_name: bundle.config.name,
|
|
78
|
+
connections: bundle.connections.size,
|
|
79
|
+
skills: bundle.skills.length,
|
|
80
80
|
uptime_ms: Date.now() - startedAt,
|
|
81
81
|
active_sessions: sessionManager.size,
|
|
82
82
|
});
|
|
@@ -95,7 +95,7 @@ export async function createSnapshotServer(config) {
|
|
|
95
95
|
return new Promise((resolve) => {
|
|
96
96
|
const httpServer = app.listen(port, host, () => {
|
|
97
97
|
process.stderr.write(`[INFO] Snapshot server listening on ${host}:${port}\n`);
|
|
98
|
-
process.stderr.write(`[INFO] Deploy: ${deployId}, Agent: ${
|
|
98
|
+
process.stderr.write(`[INFO] Deploy: ${deployId}, Agent: ${bundle.config.name}\n`);
|
|
99
99
|
resolve(httpServer);
|
|
100
100
|
});
|
|
101
101
|
server = httpServer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-server.js","sourceRoot":"","sources":["../../../src/agent/snapshot-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"snapshot-server.js","sourceRoot":"","sources":["../../../src/agent/snapshot-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,oBAAoB,EAAE,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAA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jB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC1C,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACd,IAAI,GAAG;4BAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;4BAChB,OAAO,EAAE,CAAC;oBACjB,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;YAED,MAAM,cAAc,CAAC,QAAQ,EAAE,CAAC;YAEhC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Amodal Labs, Inc.
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
6
|
+
import type { AgentBundle } from '@amodalai/core';
|
|
7
7
|
import type { ConnectionsMap } from '@amodalai/core';
|
|
8
8
|
/**
|
|
9
9
|
* Fetches user context from a configured endpoint.
|
|
@@ -12,7 +12,7 @@ import type { ConnectionsMap } from '@amodalai/core';
|
|
|
12
12
|
* (method connection/path). The connection auth is resolved from
|
|
13
13
|
* the connections map.
|
|
14
14
|
*/
|
|
15
|
-
export declare function fetchUserContext(repo:
|
|
15
|
+
export declare function fetchUserContext(repo: AgentBundle, appToken: string, connectionsMap: ConnectionsMap): Promise<Record<string, unknown>>;
|
|
16
16
|
interface ParsedSpec {
|
|
17
17
|
method: string;
|
|
18
18
|
connection: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-context-fetcher.js","sourceRoot":"","sources":["../../../src/agent/user-context-fetcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,
|
|
1
|
+
{"version":3,"file":"user-context-fetcher.js","sourceRoot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39,8 @@ export interface CreateServerOptions {
|
|
|
39
39
|
sessionStore?: SessionStore;
|
|
40
40
|
/** Shutdown callback for hosting layer cleanup (e.g., drain audit batches) */
|
|
41
41
|
onShutdown?: () => Promise<void>;
|
|
42
|
+
/** Async callback that resolves an AgentBundle from a deploy ID (used by hosted runtime) */
|
|
43
|
+
bundleProvider?: (deployId: string) => Promise<import('@amodalai/core').AgentBundle | null>;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Create the Express server with all routes, session management,
|
package/dist/src/server.js
CHANGED
|
@@ -27,6 +27,7 @@ export function createServer(options) {
|
|
|
27
27
|
ttlMs: config.sessionTtlMs,
|
|
28
28
|
platformApiUrl: options.platformApiUrl,
|
|
29
29
|
sessionStore: options.sessionStore,
|
|
30
|
+
bundleProvider: options.bundleProvider,
|
|
30
31
|
});
|
|
31
32
|
// --- Automation runner ---
|
|
32
33
|
const runAutomation = createAutomationRunner({
|
package/dist/src/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,O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AAE;gBAC7B,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;oBAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,8BAA8B,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,CAC7D,CAAC;oBACF,OAAO,CAAC,UAAU,CAAC,CAAC;gBACtB,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,UAAU,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,IAAI;YACR,iBAAiB;YACjB,mBAAmB,CAAC,IAAI,EAAE,CAAC;YAE3B,oBAAoB;YACpB,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,GAAG,MAAM,CAAC;gBACjB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC1C,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACd,IAAI,GAAG;4BAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;4BAChB,OAAO,EAAE,CAAC;oBACjB,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;YAED,oDAAoD;YACpD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACvB,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;YAC7B,CAAC;YAED,iBAAiB;YACjB,MAAM,cAAc,CAAC,QAAQ,EAAE,CAAC;YAEhC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
6
|
import { AmodalConfig, type AmodalConfigParameters, Scheduler, type GeminiClient, PlanModeManager, McpManager } from '@amodalai/core';
|
|
7
|
-
import type {
|
|
7
|
+
import type { AgentBundle, CustomToolExecutor, CustomShellExecutor, StoreBackend } from '@amodalai/core';
|
|
8
8
|
import type { AuthContext } from '../middleware/auth.js';
|
|
9
9
|
export interface PendingAskUser {
|
|
10
10
|
resolve: (answers: Record<string, string>) => void;
|
|
@@ -80,8 +80,8 @@ export interface SessionManagerOptions {
|
|
|
80
80
|
cleanupIntervalMs?: number;
|
|
81
81
|
/** Platform API URL (for loading org-specific config per session) */
|
|
82
82
|
platformApiUrl?: string;
|
|
83
|
-
/**
|
|
84
|
-
|
|
83
|
+
/** AgentBundle for local dev mode — sessions initialized from bundle config instead of platform API */
|
|
84
|
+
bundle?: AgentBundle;
|
|
85
85
|
/** Custom tool executor (local dev) */
|
|
86
86
|
toolExecutor?: CustomToolExecutor;
|
|
87
87
|
/** Custom shell executor (local dev) */
|
|
@@ -90,6 +90,8 @@ export interface SessionManagerOptions {
|
|
|
90
90
|
storeBackend?: StoreBackend;
|
|
91
91
|
/** Pluggable session store for hydration (if not provided, falls back to platform API) */
|
|
92
92
|
sessionStore?: SessionStore;
|
|
93
|
+
/** Async callback that resolves an AgentBundle from a deploy ID (used by hosted runtime) */
|
|
94
|
+
bundleProvider?: (deployId: string) => Promise<AgentBundle | null>;
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
95
97
|
* Manages per-request sessions: creates Config + GeminiClient + Scheduler
|
|
@@ -100,11 +102,12 @@ export declare class SessionManager {
|
|
|
100
102
|
private baseParams;
|
|
101
103
|
private readonly ttlMs;
|
|
102
104
|
private readonly platformApiUrl?;
|
|
103
|
-
private
|
|
105
|
+
private bundle?;
|
|
104
106
|
private readonly toolExecutor?;
|
|
105
107
|
private readonly shellExecutor?;
|
|
106
108
|
private readonly sharedStoreBackend?;
|
|
107
109
|
private readonly sessionStore?;
|
|
110
|
+
private readonly bundleProvider?;
|
|
108
111
|
private cleanupTimer;
|
|
109
112
|
/** Deduplicates concurrent hydration requests for the same conversation */
|
|
110
113
|
private readonly pendingHydrations;
|
|
@@ -146,24 +149,24 @@ export declare class SessionManager {
|
|
|
146
149
|
*/
|
|
147
150
|
destroy(id: string): Promise<void>;
|
|
148
151
|
/**
|
|
149
|
-
* Get the
|
|
152
|
+
* Get the bundle (local dev mode).
|
|
150
153
|
*/
|
|
151
|
-
|
|
154
|
+
getBundle(): AgentBundle | undefined;
|
|
152
155
|
/**
|
|
153
|
-
* Update the
|
|
156
|
+
* Update the bundle for new sessions (hot reload).
|
|
154
157
|
* Existing sessions keep their old config.
|
|
155
158
|
*/
|
|
156
|
-
|
|
159
|
+
updateBundle(bundle: AgentBundle): void;
|
|
157
160
|
/**
|
|
158
161
|
* Re-register a session under a different ID (e.g., restoring original ID on session restore).
|
|
159
162
|
*/
|
|
160
163
|
reregister(session: ManagedSession, newId: string): void;
|
|
161
164
|
/**
|
|
162
165
|
* Create an admin session for the config chat.
|
|
163
|
-
* Uses admin agent skills/knowledge but the current
|
|
166
|
+
* Uses admin agent skills/knowledge but the current bundle's connections/stores.
|
|
164
167
|
*
|
|
165
|
-
* Temporarily swaps
|
|
166
|
-
* content, then restores the original
|
|
168
|
+
* Temporarily swaps bundle fields so create() builds the prompt with admin
|
|
169
|
+
* content, then restores the original bundle. This mirrors the old approach
|
|
167
170
|
* of building an adminRepo overlay.
|
|
168
171
|
*/
|
|
169
172
|
createAdminSession(getPort?: () => number | null): Promise<ManagedSession>;
|
|
@@ -173,7 +176,7 @@ export declare class SessionManager {
|
|
|
173
176
|
*/
|
|
174
177
|
getInspectMcpManager(): Promise<McpManager | undefined>;
|
|
175
178
|
/**
|
|
176
|
-
* Initialize MCP servers for a session from
|
|
179
|
+
* Initialize MCP servers for a session from bundle connections.
|
|
177
180
|
*/
|
|
178
181
|
/**
|
|
179
182
|
* Initialize the shared MCP manager (once, reused across sessions).
|
|
@@ -181,12 +184,12 @@ export declare class SessionManager {
|
|
|
181
184
|
*/
|
|
182
185
|
private initSharedMcp;
|
|
183
186
|
/**
|
|
184
|
-
* Build the list of upstream core tools to enable based on
|
|
187
|
+
* Build the list of upstream core tools to enable based on bundle config.
|
|
185
188
|
* Only tools relevant to the Amodal runtime are included.
|
|
186
189
|
*/
|
|
187
190
|
private buildCoreToolsList;
|
|
188
191
|
/**
|
|
189
|
-
* Build MCP server configs from
|
|
192
|
+
* Build MCP server configs from bundle connections.
|
|
190
193
|
*/
|
|
191
194
|
private buildMcpConfigs;
|
|
192
195
|
/**
|
|
@@ -35,11 +35,12 @@ export class SessionManager {
|
|
|
35
35
|
baseParams;
|
|
36
36
|
ttlMs;
|
|
37
37
|
platformApiUrl;
|
|
38
|
-
|
|
38
|
+
bundle;
|
|
39
39
|
toolExecutor;
|
|
40
40
|
shellExecutor;
|
|
41
41
|
sharedStoreBackend;
|
|
42
42
|
sessionStore;
|
|
43
|
+
bundleProvider;
|
|
43
44
|
cleanupTimer = null;
|
|
44
45
|
/** Deduplicates concurrent hydration requests for the same conversation */
|
|
45
46
|
pendingHydrations = new Map();
|
|
@@ -52,11 +53,12 @@ export class SessionManager {
|
|
|
52
53
|
this.baseParams = options.baseParams;
|
|
53
54
|
this.ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
54
55
|
this.platformApiUrl = options.platformApiUrl;
|
|
55
|
-
this.
|
|
56
|
+
this.bundle = options.bundle;
|
|
56
57
|
this.toolExecutor = options.toolExecutor;
|
|
57
58
|
this.shellExecutor = options.shellExecutor;
|
|
58
59
|
this.sharedStoreBackend = options.storeBackend;
|
|
59
60
|
this.sessionStore = options.sessionStore;
|
|
61
|
+
this.bundleProvider = options.bundleProvider;
|
|
60
62
|
const cleanupIntervalMs = options.cleanupIntervalMs ?? DEFAULT_CLEANUP_INTERVAL_MS;
|
|
61
63
|
this.cleanupTimer = setInterval(() => void this.cleanup(), cleanupIntervalMs);
|
|
62
64
|
// Don't keep the process alive just for cleanup
|
|
@@ -75,8 +77,7 @@ export class SessionManager {
|
|
|
75
77
|
approvalMode: ApprovalMode.YOLO,
|
|
76
78
|
interactive: false,
|
|
77
79
|
noBrowser: true,
|
|
78
|
-
|
|
79
|
-
coreTools: this.repo ? this.buildCoreToolsList(this.repo) : [],
|
|
80
|
+
coreTools: [],
|
|
80
81
|
policyEngineConfig: {
|
|
81
82
|
approvalMode: ApprovalMode.YOLO,
|
|
82
83
|
defaultDecision: PolicyDecision.ALLOW,
|
|
@@ -90,12 +91,15 @@ export class SessionManager {
|
|
|
90
91
|
if (role) {
|
|
91
92
|
sessionParams.activeRole = role;
|
|
92
93
|
}
|
|
93
|
-
//
|
|
94
|
-
|
|
94
|
+
// Resolve bundle: static bundle (local dev), or dynamic via bundleProvider (hosted)
|
|
95
|
+
const bundle = this.bundle ?? (deployId && this.bundleProvider ? await this.bundleProvider(deployId) : null);
|
|
96
|
+
// Inject bundle config into session params
|
|
97
|
+
if (bundle) {
|
|
98
|
+
sessionParams.coreTools = this.buildCoreToolsList(bundle);
|
|
95
99
|
const { buildConnectionsMap } = await import('@amodalai/core');
|
|
96
|
-
const connectionsMap = buildConnectionsMap(
|
|
100
|
+
const connectionsMap = buildConnectionsMap(bundle.connections);
|
|
97
101
|
sessionParams.connections = connectionsMap;
|
|
98
|
-
sessionParams.appDocuments =
|
|
102
|
+
sessionParams.appDocuments = bundle.knowledge.map((k) => ({
|
|
99
103
|
id: k.name,
|
|
100
104
|
scope_type: 'application',
|
|
101
105
|
scope_id: 'local',
|
|
@@ -108,16 +112,16 @@ export class SessionManager {
|
|
|
108
112
|
created_at: new Date().toISOString(),
|
|
109
113
|
updated_at: new Date().toISOString(),
|
|
110
114
|
}));
|
|
111
|
-
sessionParams.bundleSkills =
|
|
115
|
+
sessionParams.bundleSkills = bundle.skills.map((s) => ({
|
|
112
116
|
name: s.name,
|
|
113
117
|
description: s.description ?? '',
|
|
114
118
|
body: s.body,
|
|
115
119
|
}));
|
|
116
|
-
sessionParams.basePrompt =
|
|
117
|
-
sessionParams.agentName =
|
|
118
|
-
sessionParams.agentContext =
|
|
119
|
-
// Model config from
|
|
120
|
-
const mainModel =
|
|
120
|
+
sessionParams.basePrompt = bundle.config.basePrompt;
|
|
121
|
+
sessionParams.agentName = bundle.config.name;
|
|
122
|
+
sessionParams.agentContext = bundle.config.userContext ?? bundle.config.description;
|
|
123
|
+
// Model config from bundle
|
|
124
|
+
const mainModel = bundle.config.models?.main;
|
|
121
125
|
if (mainModel) {
|
|
122
126
|
sessionParams.modelConfig = {
|
|
123
127
|
provider: mainModel.provider ?? 'anthropic',
|
|
@@ -125,13 +129,14 @@ export class SessionManager {
|
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
// Stores
|
|
128
|
-
if (
|
|
129
|
-
sessionParams.stores =
|
|
132
|
+
if (bundle.stores.length > 0) {
|
|
133
|
+
sessionParams.stores = bundle.stores;
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
let config;
|
|
133
137
|
// Platform session: use AgentSDK to fetch KB docs, org details, secrets
|
|
134
|
-
|
|
138
|
+
// Skip SDK when bundle was resolved from a provider — bundle config takes precedence
|
|
139
|
+
if (auth?.token && this.platformApiUrl && !bundle) {
|
|
135
140
|
process.stderr.write(`[SESSION] Creating platform session: app=${auth.applicationId}, ` +
|
|
136
141
|
`org=${auth.orgId}, key=${auth.token.slice(0, 12)}..., sessionType=${sessionType ?? '(none)'}\n`);
|
|
137
142
|
const sdk = new AgentSDK({
|
|
@@ -202,15 +207,15 @@ export class SessionManager {
|
|
|
202
207
|
await config.initializeAuth();
|
|
203
208
|
// Register amodal tools (request, present, knowledge, stores)
|
|
204
209
|
await config.registerTools();
|
|
205
|
-
// Register custom tools from
|
|
206
|
-
if (this.
|
|
210
|
+
// Register custom tools from bundle tools/ directory
|
|
211
|
+
if (this.bundle && this.bundle.tools.length > 0) {
|
|
207
212
|
const { CustomToolAdapter } = await import('./custom-tool-adapter.js');
|
|
208
213
|
const { LocalToolExecutor } = await import('../agent/tool-executor-local.js');
|
|
209
214
|
const executor = this.toolExecutor ?? new LocalToolExecutor();
|
|
210
215
|
const registry = config.getUpstreamConfig().getToolRegistry();
|
|
211
216
|
// Session isn't created yet — we'll set it after session construction
|
|
212
217
|
// For now store the tools to register after session is built
|
|
213
|
-
for (const tool of this.
|
|
218
|
+
for (const tool of this.bundle.tools) {
|
|
214
219
|
if (tool.confirm === 'never')
|
|
215
220
|
continue; // hidden from LLM
|
|
216
221
|
// Create a placeholder session for the adapter — will be updated below
|
|
@@ -220,7 +225,7 @@ export class SessionManager {
|
|
|
220
225
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- adapter matches upstream tool interface
|
|
221
226
|
registry.registerTool(adapter);
|
|
222
227
|
}
|
|
223
|
-
process.stderr.write(`[SESSION] Registered ${String(this.
|
|
228
|
+
process.stderr.write(`[SESSION] Registered ${String(this.bundle.tools.length)} custom tool(s)\n`);
|
|
224
229
|
}
|
|
225
230
|
// Set model on upstream config so GeminiClient.startChat() can resolve it
|
|
226
231
|
if (sessionParams.modelConfig?.model) {
|
|
@@ -311,8 +316,8 @@ export class SessionManager {
|
|
|
311
316
|
name: config.getAgentName() ?? 'Amodal Agent',
|
|
312
317
|
description: config.getAgentDescription(),
|
|
313
318
|
agentContext: config.getAgentContext(),
|
|
314
|
-
agentOverride: this.
|
|
315
|
-
connections: this.
|
|
319
|
+
agentOverride: this.bundle?.agents?.main,
|
|
320
|
+
connections: this.bundle?.connections ? Array.from(this.bundle.connections.values()).map((conn) => ({
|
|
316
321
|
name: conn.name,
|
|
317
322
|
endpoints: (conn.surface ?? [])
|
|
318
323
|
.filter((ep) => ep.included)
|
|
@@ -320,21 +325,21 @@ export class SessionManager {
|
|
|
320
325
|
entities: conn.entities,
|
|
321
326
|
rules: conn.rules,
|
|
322
327
|
})) : undefined,
|
|
323
|
-
skills: this.
|
|
328
|
+
skills: this.bundle?.skills?.map((s) => ({
|
|
324
329
|
name: s.name,
|
|
325
330
|
description: s.description ?? '',
|
|
326
331
|
trigger: s.trigger,
|
|
327
332
|
body: s.body,
|
|
328
333
|
})),
|
|
329
|
-
knowledge: this.
|
|
334
|
+
knowledge: this.bundle?.knowledge?.map((k) => ({
|
|
330
335
|
name: k.name,
|
|
331
336
|
title: k.title,
|
|
332
337
|
body: k.body,
|
|
333
338
|
})),
|
|
334
|
-
...(this.
|
|
335
|
-
const { scopeLabels } = resolveScopeLabels(this.
|
|
336
|
-
const fieldGuidance = generateFieldGuidance(this.
|
|
337
|
-
const altLookup = generateAlternativeLookupGuidance(this.
|
|
339
|
+
...(this.bundle?.connections ? (() => {
|
|
340
|
+
const { scopeLabels } = resolveScopeLabels(this.bundle.connections, []);
|
|
341
|
+
const fieldGuidance = generateFieldGuidance(this.bundle.connections, []);
|
|
342
|
+
const altLookup = generateAlternativeLookupGuidance(this.bundle.connections);
|
|
338
343
|
return {
|
|
339
344
|
fieldGuidance: fieldGuidance || undefined,
|
|
340
345
|
scopeLabels: Object.keys(scopeLabels).length > 0 ? scopeLabels : undefined,
|
|
@@ -463,8 +468,8 @@ export class SessionManager {
|
|
|
463
468
|
appId: auth?.applicationId,
|
|
464
469
|
};
|
|
465
470
|
// Share MCP connection across sessions — connect once, reuse for all
|
|
466
|
-
if (this.
|
|
467
|
-
await this.initSharedMcp(this.
|
|
471
|
+
if (this.bundle && !this.sharedMcpManager) {
|
|
472
|
+
await this.initSharedMcp(this.bundle);
|
|
468
473
|
}
|
|
469
474
|
if (this.sharedMcpManager) {
|
|
470
475
|
session.mcpManager = this.sharedMcpManager;
|
|
@@ -530,6 +535,17 @@ export class SessionManager {
|
|
|
530
535
|
process.stderr.write(`[MCP] Failed to register MCP tools: ${msg}\n`);
|
|
531
536
|
}
|
|
532
537
|
}
|
|
538
|
+
// Guard: reject sessions with no agent configuration.
|
|
539
|
+
// If there are no skills, no base prompt, and no agent context, the agent
|
|
540
|
+
// would fall back to a generic assistant response — which is never correct
|
|
541
|
+
// for a deployed agent.
|
|
542
|
+
const hasSkills = sessionParams.bundleSkills && sessionParams.bundleSkills.length > 0;
|
|
543
|
+
const hasPrompt = !!sessionParams.basePrompt;
|
|
544
|
+
const hasContext = !!sessionParams.agentContext;
|
|
545
|
+
if (!hasSkills && !hasPrompt && !hasContext && deployId) {
|
|
546
|
+
throw new Error(`Agent not configured: deploy ${deployId} has no skills, base prompt, or context. ` +
|
|
547
|
+
'Ensure the deployment snapshot includes agent configuration.');
|
|
548
|
+
}
|
|
533
549
|
this.sessions.set(sessionId, session);
|
|
534
550
|
return session;
|
|
535
551
|
}
|
|
@@ -634,17 +650,17 @@ export class SessionManager {
|
|
|
634
650
|
// Local dev features
|
|
635
651
|
// ---------------------------------------------------------------------------
|
|
636
652
|
/**
|
|
637
|
-
* Get the
|
|
653
|
+
* Get the bundle (local dev mode).
|
|
638
654
|
*/
|
|
639
|
-
|
|
640
|
-
return this.
|
|
655
|
+
getBundle() {
|
|
656
|
+
return this.bundle;
|
|
641
657
|
}
|
|
642
658
|
/**
|
|
643
|
-
* Update the
|
|
659
|
+
* Update the bundle for new sessions (hot reload).
|
|
644
660
|
* Existing sessions keep their old config.
|
|
645
661
|
*/
|
|
646
|
-
|
|
647
|
-
this.
|
|
662
|
+
updateBundle(bundle) {
|
|
663
|
+
this.bundle = bundle;
|
|
648
664
|
// Reset inspect MCP manager so it picks up new connections
|
|
649
665
|
this.inspectMcpInitialized = false;
|
|
650
666
|
this.inspectMcp = undefined;
|
|
@@ -659,51 +675,51 @@ export class SessionManager {
|
|
|
659
675
|
}
|
|
660
676
|
/**
|
|
661
677
|
* Create an admin session for the config chat.
|
|
662
|
-
* Uses admin agent skills/knowledge but the current
|
|
678
|
+
* Uses admin agent skills/knowledge but the current bundle's connections/stores.
|
|
663
679
|
*
|
|
664
|
-
* Temporarily swaps
|
|
665
|
-
* content, then restores the original
|
|
680
|
+
* Temporarily swaps bundle fields so create() builds the prompt with admin
|
|
681
|
+
* content, then restores the original bundle. This mirrors the old approach
|
|
666
682
|
* of building an adminRepo overlay.
|
|
667
683
|
*/
|
|
668
684
|
async createAdminSession(getPort) {
|
|
669
|
-
if (!this.
|
|
670
|
-
throw new Error('Admin sessions require a
|
|
685
|
+
if (!this.bundle) {
|
|
686
|
+
throw new Error('Admin sessions require a bundle');
|
|
671
687
|
}
|
|
672
|
-
if (this.
|
|
688
|
+
if (this.bundle.source !== 'local') {
|
|
673
689
|
throw new Error('Admin sessions are only available for local repos');
|
|
674
690
|
}
|
|
675
|
-
const agentDir = await ensureAdminAgent(this.
|
|
691
|
+
const agentDir = await ensureAdminAgent(this.bundle.origin);
|
|
676
692
|
const adminContent = await loadAdminAgent(agentDir);
|
|
677
|
-
// Save original
|
|
678
|
-
const origSkills = this.
|
|
679
|
-
const origKnowledge = this.
|
|
680
|
-
const origAgents = this.
|
|
681
|
-
const origAutomations = this.
|
|
693
|
+
// Save original bundle fields
|
|
694
|
+
const origSkills = this.bundle.skills;
|
|
695
|
+
const origKnowledge = this.bundle.knowledge;
|
|
696
|
+
const origAgents = this.bundle.agents;
|
|
697
|
+
const origAutomations = this.bundle.automations;
|
|
682
698
|
// Swap in admin content so create() builds the prompt correctly
|
|
683
|
-
this.
|
|
684
|
-
this.
|
|
685
|
-
this.
|
|
699
|
+
this.bundle.skills = adminContent.skills;
|
|
700
|
+
this.bundle.knowledge = adminContent.knowledge;
|
|
701
|
+
this.bundle.agents = {
|
|
686
702
|
main: adminContent.agentPrompt ?? undefined,
|
|
687
703
|
simple: undefined,
|
|
688
704
|
subagents: [],
|
|
689
705
|
};
|
|
690
|
-
this.
|
|
706
|
+
this.bundle.automations = [];
|
|
691
707
|
let session;
|
|
692
708
|
try {
|
|
693
709
|
session = await this.create('admin');
|
|
694
710
|
}
|
|
695
711
|
finally {
|
|
696
|
-
// Restore original
|
|
697
|
-
this.
|
|
698
|
-
this.
|
|
699
|
-
this.
|
|
700
|
-
this.
|
|
712
|
+
// Restore original bundle fields
|
|
713
|
+
this.bundle.skills = origSkills;
|
|
714
|
+
this.bundle.knowledge = origKnowledge;
|
|
715
|
+
this.bundle.agents = origAgents;
|
|
716
|
+
this.bundle.automations = origAutomations;
|
|
701
717
|
}
|
|
702
718
|
session.appId = 'admin';
|
|
703
|
-
// Register admin file tools (read/write/delete
|
|
719
|
+
// Register admin file tools (read/write/delete agent files)
|
|
704
720
|
try {
|
|
705
721
|
const { createReadRepoFileTool, createWriteRepoFileTool, createDeleteRepoFileTool } = await import('./admin-file-tools.js');
|
|
706
|
-
const repoRoot = this.
|
|
722
|
+
const repoRoot = this.bundle.origin;
|
|
707
723
|
const upstream = session.config.getUpstreamConfig();
|
|
708
724
|
const toolRegistry = upstream.getToolRegistry();
|
|
709
725
|
toolRegistry.registerTool(createReadRepoFileTool(repoRoot)); // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
@@ -731,10 +747,10 @@ export class SessionManager {
|
|
|
731
747
|
if (this.inspectMcpInitialized)
|
|
732
748
|
return this.inspectMcp;
|
|
733
749
|
this.inspectMcpInitialized = true;
|
|
734
|
-
if (!this.
|
|
750
|
+
if (!this.bundle)
|
|
735
751
|
return undefined;
|
|
736
|
-
// Build MCP server configs from
|
|
737
|
-
const mcpServers = this.buildMcpConfigs(this.
|
|
752
|
+
// Build MCP server configs from bundle connections
|
|
753
|
+
const mcpServers = this.buildMcpConfigs(this.bundle);
|
|
738
754
|
if (Object.keys(mcpServers).length === 0)
|
|
739
755
|
return undefined;
|
|
740
756
|
const manager = new McpManager();
|
|
@@ -751,14 +767,14 @@ export class SessionManager {
|
|
|
751
767
|
}
|
|
752
768
|
}
|
|
753
769
|
/**
|
|
754
|
-
* Initialize MCP servers for a session from
|
|
770
|
+
* Initialize MCP servers for a session from bundle connections.
|
|
755
771
|
*/
|
|
756
772
|
/**
|
|
757
773
|
* Initialize the shared MCP manager (once, reused across sessions).
|
|
758
774
|
* Avoids reconnecting MCP servers for every eval/judge/admin session.
|
|
759
775
|
*/
|
|
760
|
-
async initSharedMcp(
|
|
761
|
-
const mcpServers = this.buildMcpConfigs(
|
|
776
|
+
async initSharedMcp(bundle) {
|
|
777
|
+
const mcpServers = this.buildMcpConfigs(bundle);
|
|
762
778
|
if (Object.keys(mcpServers).length === 0)
|
|
763
779
|
return;
|
|
764
780
|
const manager = new McpManager();
|
|
@@ -774,10 +790,10 @@ export class SessionManager {
|
|
|
774
790
|
}
|
|
775
791
|
}
|
|
776
792
|
/**
|
|
777
|
-
* Build the list of upstream core tools to enable based on
|
|
793
|
+
* Build the list of upstream core tools to enable based on bundle config.
|
|
778
794
|
* Only tools relevant to the Amodal runtime are included.
|
|
779
795
|
*/
|
|
780
|
-
buildCoreToolsList(
|
|
796
|
+
buildCoreToolsList(bundle) {
|
|
781
797
|
const tools = [
|
|
782
798
|
// Always available
|
|
783
799
|
'enter_plan_mode',
|
|
@@ -785,17 +801,17 @@ export class SessionManager {
|
|
|
785
801
|
'ask_user',
|
|
786
802
|
];
|
|
787
803
|
// Shell execution (opt-in via config.sandbox.shellExec)
|
|
788
|
-
if (
|
|
804
|
+
if (bundle.config.sandbox?.shellExec) {
|
|
789
805
|
tools.push('shell');
|
|
790
806
|
}
|
|
791
807
|
return tools;
|
|
792
808
|
}
|
|
793
809
|
/**
|
|
794
|
-
* Build MCP server configs from
|
|
810
|
+
* Build MCP server configs from bundle connections.
|
|
795
811
|
*/
|
|
796
|
-
buildMcpConfigs(
|
|
812
|
+
buildMcpConfigs(bundle) {
|
|
797
813
|
const mcpServers = {};
|
|
798
|
-
for (const [name, conn] of
|
|
814
|
+
for (const [name, conn] of bundle.connections) {
|
|
799
815
|
if (conn.spec.protocol === 'mcp') {
|
|
800
816
|
const resolvedHeaders = conn.spec.headers ? resolveEnvRefs(conn.spec.headers) : undefined;
|
|
801
817
|
const resolvedEnv = conn.spec.env ? resolveEnvRefs(conn.spec.env) : undefined;
|
|
@@ -810,8 +826,8 @@ export class SessionManager {
|
|
|
810
826
|
};
|
|
811
827
|
}
|
|
812
828
|
}
|
|
813
|
-
if (
|
|
814
|
-
for (const [name, config] of Object.entries(
|
|
829
|
+
if (bundle.mcpServers) {
|
|
830
|
+
for (const [name, config] of Object.entries(bundle.mcpServers)) {
|
|
815
831
|
if (!mcpServers[name]) {
|
|
816
832
|
mcpServers[name] = config;
|
|
817
833
|
}
|