@gaunt-sloth/agent 0.1.8 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/cli-acp.js +35 -0
- package/cli.js +35 -0
- package/dist/builtInToolsConfig.d.ts +26 -0
- package/dist/builtInToolsConfig.js +148 -0
- package/dist/builtInToolsConfig.js.map +1 -0
- package/dist/core/GthDeepAgent.d.ts +76 -0
- package/dist/core/GthDeepAgent.js +368 -0
- package/dist/core/GthDeepAgent.js.map +1 -0
- package/dist/core/debugCapture.d.ts +51 -0
- package/dist/core/debugCapture.js +2 -0
- package/dist/core/debugCapture.js.map +1 -0
- package/dist/core/deepAgentPermissions.d.ts +55 -0
- package/dist/core/deepAgentPermissions.js +120 -0
- package/dist/core/deepAgentPermissions.js.map +1 -0
- package/dist/core/gthAcpServer.d.ts +27 -0
- package/dist/core/gthAcpServer.js +71 -0
- package/dist/core/gthAcpServer.js.map +1 -0
- package/dist/core/gthDeepAgentFactory.d.ts +8 -0
- package/dist/core/gthDeepAgentFactory.js +9 -0
- package/dist/core/gthDeepAgentFactory.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/OAuthClientProviderImpl.d.ts +37 -0
- package/dist/mcp/OAuthClientProviderImpl.js +223 -0
- package/dist/mcp/OAuthClientProviderImpl.js.map +1 -0
- package/dist/middleware/binaryContentInjectionMiddleware.d.ts +22 -0
- package/dist/middleware/binaryContentInjectionMiddleware.js +125 -0
- package/dist/middleware/binaryContentInjectionMiddleware.js.map +1 -0
- package/dist/middleware/registry.d.ts +34 -0
- package/dist/middleware/registry.js +124 -0
- package/dist/middleware/registry.js.map +1 -0
- package/dist/middleware/types.d.ts +89 -0
- package/dist/middleware/types.js +9 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/modules/a2a/A2AClientWrapper.d.ts +22 -0
- package/dist/modules/a2a/A2AClientWrapper.js +63 -0
- package/dist/modules/a2a/A2AClientWrapper.js.map +1 -0
- package/dist/modules/acpModule.d.ts +37 -0
- package/dist/modules/acpModule.js +67 -0
- package/dist/modules/acpModule.js.map +1 -0
- package/dist/modules/apiAgUiModule.d.ts +2 -0
- package/dist/modules/apiAgUiModule.js +417 -0
- package/dist/modules/apiAgUiModule.js.map +1 -0
- package/dist/modules/interactiveSessionModule.d.ts +9 -0
- package/dist/modules/interactiveSessionModule.js +99 -0
- package/dist/modules/interactiveSessionModule.js.map +1 -0
- package/dist/resolvers.d.ts +18 -0
- package/dist/resolvers.js +140 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/tools/A2AAgentTool.d.ts +24 -0
- package/dist/tools/A2AAgentTool.js +37 -0
- package/dist/tools/A2AAgentTool.js.map +1 -0
- package/dist/tools/GthCustomToolkit.d.ts +41 -0
- package/dist/tools/GthCustomToolkit.js +289 -0
- package/dist/tools/GthCustomToolkit.js.map +1 -0
- package/dist/tools/GthDevToolkit.d.ts +24 -0
- package/dist/tools/GthDevToolkit.js +189 -0
- package/dist/tools/GthDevToolkit.js.map +1 -0
- package/dist/tools/GthFileSystemToolkit.d.ts +36 -0
- package/dist/tools/GthFileSystemToolkit.js +775 -0
- package/dist/tools/GthFileSystemToolkit.js.map +1 -0
- package/dist/tools/binaryUtils.d.ts +13 -0
- package/dist/tools/binaryUtils.js +55 -0
- package/dist/tools/binaryUtils.js.map +1 -0
- package/dist/tools/gthStatusUpdateTool.d.ts +2 -0
- package/dist/tools/gthStatusUpdateTool.js +15 -0
- package/dist/tools/gthStatusUpdateTool.js.map +1 -0
- package/dist/tools/gthWebFetchTool.d.ts +2 -0
- package/dist/tools/gthWebFetchTool.js +47 -0
- package/dist/tools/gthWebFetchTool.js.map +1 -0
- package/dist/tools/showA2UISurfaceTool.d.ts +9 -0
- package/dist/tools/showA2UISurfaceTool.js +25 -0
- package/dist/tools/showA2UISurfaceTool.js.map +1 -0
- package/dist/utils/mcpUtils.d.ts +13 -0
- package/dist/utils/mcpUtils.js +225 -0
- package/dist/utils/mcpUtils.js.map +1 -0
- package/package.json +49 -10
- package/index.js +0 -6
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Middleware registry for Gaunt Sloth Assistant.
|
|
4
|
+
*
|
|
5
|
+
* This module provides factory functions for creating predefined middleware instances
|
|
6
|
+
* and a resolver to convert middleware configurations into middleware objects.
|
|
7
|
+
*/
|
|
8
|
+
import { displayWarning } from '@gaunt-sloth/core/utils/consoleUtils.js';
|
|
9
|
+
import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
|
|
10
|
+
import { anthropicPromptCachingMiddleware, summarizationMiddleware, } from 'langchain';
|
|
11
|
+
import { createBinaryContentInjectionMiddleware, } from '#src/middleware/binaryContentInjectionMiddleware.js';
|
|
12
|
+
const predefinedMiddlewareFactories = {
|
|
13
|
+
/**
|
|
14
|
+
* Anthropic prompt caching middleware. see https://docs.langchain.com/oss/javascript/langchain/middleware#anthropic-prompt-caching
|
|
15
|
+
*/
|
|
16
|
+
'anthropic-prompt-caching': (settings, gthConfig) => createAnthropicPromptCachingMiddleware(settings, gthConfig),
|
|
17
|
+
/**
|
|
18
|
+
* Summarization middleware. see https://docs.langchain.com/oss/javascript/langchain/middleware#summarization
|
|
19
|
+
*/
|
|
20
|
+
summarization: (settings, gthConfig) => createSummarizationMiddleware(settings, gthConfig),
|
|
21
|
+
/**
|
|
22
|
+
* Binary content injection middleware.
|
|
23
|
+
* Intercepts tool results containing binary data (images, PDFs, audio) and injects them
|
|
24
|
+
* as HumanMessage content blocks before the next model call.
|
|
25
|
+
* This works around LangChain's limitation where ToolMessage doesn't support binary content.
|
|
26
|
+
*/
|
|
27
|
+
'binary-content-injection': (settings, gthConfig) => createBinaryContentInjectionMiddleware(settings, gthConfig),
|
|
28
|
+
};
|
|
29
|
+
function isPredefinedMiddlewareName(name) {
|
|
30
|
+
return name in predefinedMiddlewareFactories;
|
|
31
|
+
}
|
|
32
|
+
function isPredefinedMiddlewareObject(config) {
|
|
33
|
+
return (typeof config === 'object' &&
|
|
34
|
+
config !== null &&
|
|
35
|
+
'name' in config &&
|
|
36
|
+
typeof config.name === 'string' &&
|
|
37
|
+
isPredefinedMiddlewareName(config.name));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create Anthropic prompt caching middleware.
|
|
41
|
+
* This middleware adds cache control headers to reduce API costs.
|
|
42
|
+
*/
|
|
43
|
+
export async function createAnthropicPromptCachingMiddleware(config, _) {
|
|
44
|
+
debugLog(`Creating Anthropic prompt caching middleware with TTL: ${config.ttl || 'default'}`);
|
|
45
|
+
// Dynamic import for async initialization
|
|
46
|
+
return Promise.resolve(anthropicPromptCachingMiddleware({ ttl: config.ttl }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create summarization middleware.
|
|
50
|
+
* This middleware automatically condenses conversation history when approaching token limits.
|
|
51
|
+
*
|
|
52
|
+
* @param config - Configuration for the middleware
|
|
53
|
+
* @param gthConfig - Full Gaunt Sloth configuration
|
|
54
|
+
* @returns Middleware object
|
|
55
|
+
*/
|
|
56
|
+
export async function createSummarizationMiddleware(config, gthConfig) {
|
|
57
|
+
debugLog('Creating summarization middleware');
|
|
58
|
+
return Promise.resolve(summarizationMiddleware({
|
|
59
|
+
model: config.model || gthConfig.llm,
|
|
60
|
+
...config,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve middleware configuration into middleware instances.
|
|
65
|
+
* Converts string identifiers and config objects into actual middleware.
|
|
66
|
+
* Automatically injects binary-content-injection middleware if binaryFormats is enabled.
|
|
67
|
+
*
|
|
68
|
+
* @param configs - Array of middleware configurations
|
|
69
|
+
* @param gthConfig - Full Gaunt Sloth configuration
|
|
70
|
+
* @returns Array of middleware instances
|
|
71
|
+
*/
|
|
72
|
+
export async function resolveMiddleware(configs, gthConfig) {
|
|
73
|
+
const configsToResolve = configs || [];
|
|
74
|
+
const middleware = [];
|
|
75
|
+
// Auto-inject binary-content-injection middleware if binaryFormats is configured
|
|
76
|
+
// It is only auto-injected if binaryFormats is enabled.
|
|
77
|
+
const hasBinaryFormats = gthConfig.binaryFormats !== undefined &&
|
|
78
|
+
gthConfig.binaryFormats !== false &&
|
|
79
|
+
gthConfig.binaryFormats.length > 0;
|
|
80
|
+
const hasBinaryMiddleware = configsToResolve.some((c) => c === 'binary-content-injection' ||
|
|
81
|
+
(typeof c === 'object' && 'name' in c && c.name === 'binary-content-injection'));
|
|
82
|
+
if (hasBinaryFormats && !hasBinaryMiddleware) {
|
|
83
|
+
debugLog('Auto-injecting binary-content-injection middleware (binaryFormats is enabled)');
|
|
84
|
+
middleware.push(await createPredefinedMiddleware('binary-content-injection', {}, gthConfig));
|
|
85
|
+
}
|
|
86
|
+
for (const config of configsToResolve) {
|
|
87
|
+
try {
|
|
88
|
+
// Handle string configuration (predefined middleware with defaults)
|
|
89
|
+
if (typeof config === 'string') {
|
|
90
|
+
middleware.push(await createPredefinedMiddleware(config, {}, gthConfig));
|
|
91
|
+
}
|
|
92
|
+
// Handle predefined middleware with custom settings
|
|
93
|
+
else if (isPredefinedMiddlewareObject(config)) {
|
|
94
|
+
const { name, ...settings } = config;
|
|
95
|
+
middleware.push(await createPredefinedMiddleware(name, settings, gthConfig));
|
|
96
|
+
}
|
|
97
|
+
// Handle custom middleware object (JS config only)
|
|
98
|
+
else {
|
|
99
|
+
debugLog('Adding custom middleware');
|
|
100
|
+
middleware.push(config);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
displayWarning(`Failed to create middleware: ${error instanceof Error ? error.message : String(error)}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return middleware;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a predefined middleware instance by name.
|
|
111
|
+
*
|
|
112
|
+
* @param name - Name of the predefined middleware
|
|
113
|
+
* @param settings - Configuration settings for the middleware
|
|
114
|
+
* @param gthConfig - Full Gaunt Sloth configuration
|
|
115
|
+
* @returns Middleware instance
|
|
116
|
+
*/
|
|
117
|
+
async function createPredefinedMiddleware(name, settings, gthConfig) {
|
|
118
|
+
if (!isPredefinedMiddlewareName(name)) {
|
|
119
|
+
throw new Error(`Unknown predefined middleware: ${name}`);
|
|
120
|
+
}
|
|
121
|
+
const factory = predefinedMiddlewareFactories[name];
|
|
122
|
+
return factory(settings, gthConfig);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/middleware/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EACL,gCAAgC,EAChC,uBAAuB,GAExB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,sCAAsC,GAEvC,MAAM,qDAAqD,CAAC;AAO7D,MAAM,6BAA6B,GAAG;IACpC;;OAEG;IACH,0BAA0B,EAAE,CAC1B,QAAiC,EACjC,SAAoB,EACM,EAAE,CAC5B,sCAAsC,CAAC,QAAwC,EAAE,SAAS,CAAC;IAC7F;;OAEG;IACH,aAAa,EAAE,CACb,QAAiC,EACjC,SAAoB,EACM,EAAE,CAC5B,6BAA6B,CAAC,QAA+B,EAAE,SAAS,CAAC;IAC3E;;;;;OAKG;IACH,0BAA0B,EAAE,CAC1B,QAAiC,EACjC,SAAoB,EACM,EAAE,CAC5B,sCAAsC,CACpC,QAAoD,EACpD,SAAS,CACV;CACkD,CAAC;AAExD,SAAS,0BAA0B,CACjC,IAAY;IAEZ,OAAO,IAAI,IAAI,6BAA6B,CAAC;AAC/C,CAAC;AAED,SAAS,4BAA4B,CACnC,MAAwB;IAExB,OAAO,CACL,OAAO,MAA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ACZ,QAAiC,EACjC,SAAoB;IAEpB,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,OAAO,GAAG,6BAA6B,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Type definitions for middleware configuration in Gaunt Sloth Assistant.
|
|
4
|
+
*
|
|
5
|
+
* Middleware provides hooks to intercept and control agent execution at critical points.
|
|
6
|
+
* This module defines the configuration interfaces for both predefined and custom middleware.
|
|
7
|
+
*/
|
|
8
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
9
|
+
import { AgentMiddleware } from 'langchain';
|
|
10
|
+
/**
|
|
11
|
+
* Predefined middleware types that can be configured via JSON config.
|
|
12
|
+
*/
|
|
13
|
+
export type PredefinedMiddlewareName = 'anthropic-prompt-caching' | 'summarization' | 'binary-content-injection';
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for Anthropic prompt caching middleware.
|
|
16
|
+
*/
|
|
17
|
+
export interface AnthropicPromptCachingConfig {
|
|
18
|
+
/**
|
|
19
|
+
* Cache TTL (time to live).
|
|
20
|
+
* Examples: "5m" for 5 minutes, "1h" for 1 hour
|
|
21
|
+
*/
|
|
22
|
+
ttl?: '5m' | '1h';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for summarization middleware.
|
|
26
|
+
*/
|
|
27
|
+
export interface SummarizationConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Model to use for summarization.
|
|
30
|
+
* If not provided, uses the main LLM from config.
|
|
31
|
+
*/
|
|
32
|
+
model?: BaseChatModel;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum tokens before triggering summarization.
|
|
35
|
+
* Set one of:
|
|
36
|
+
*/
|
|
37
|
+
trigger?: {
|
|
38
|
+
fraction?: number;
|
|
39
|
+
tokens?: number;
|
|
40
|
+
messages?: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* How many tokens, messages, or a fraction of context to keep.
|
|
44
|
+
* Set one of:
|
|
45
|
+
*/
|
|
46
|
+
keep?: {
|
|
47
|
+
fraction?: number;
|
|
48
|
+
tokens?: number;
|
|
49
|
+
messages?: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Custom prompt template for summarization.
|
|
53
|
+
*/
|
|
54
|
+
summaryPrompt?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Configuration for image format transformation middleware.
|
|
58
|
+
*/
|
|
59
|
+
export interface ImageFormatTransformConfig {
|
|
60
|
+
/**
|
|
61
|
+
* Detail level for image processing.
|
|
62
|
+
* Examples: "low", "high", "auto"
|
|
63
|
+
*/
|
|
64
|
+
detail?: 'low' | 'high' | 'auto';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Configuration for binary content injection middleware.
|
|
68
|
+
* This middleware intercepts tool results containing binary data (images, PDFs, audio)
|
|
69
|
+
* and injects them as HumanMessage content blocks.
|
|
70
|
+
*/
|
|
71
|
+
export interface BinaryContentInjectionConfig {
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Union type of all predefined middleware configurations.
|
|
75
|
+
*/
|
|
76
|
+
export type PredefinedMiddlewareConfig = ({
|
|
77
|
+
name: 'anthropic-prompt-caching';
|
|
78
|
+
} & AnthropicPromptCachingConfig) | ({
|
|
79
|
+
name: 'summarization';
|
|
80
|
+
} & SummarizationConfig) | ({
|
|
81
|
+
name: 'binary-content-injection';
|
|
82
|
+
} & BinaryContentInjectionConfig);
|
|
83
|
+
/**
|
|
84
|
+
* Middleware configuration that can be specified in JSON or JS config.
|
|
85
|
+
* - String: Name of predefined middleware with default settings
|
|
86
|
+
* - PredefinedMiddlewareConfig: Predefined middleware with custom settings (JSON compatible)
|
|
87
|
+
* - CustomMiddleware: Custom middleware object (JS config only)
|
|
88
|
+
*/
|
|
89
|
+
export type MiddlewareConfig = string | PredefinedMiddlewareConfig | AgentMiddleware;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Type definitions for middleware configuration in Gaunt Sloth Assistant.
|
|
4
|
+
*
|
|
5
|
+
* Middleware provides hooks to intercept and control agent execution at critical points.
|
|
6
|
+
* This module defines the configuration interfaces for both predefined and custom middleware.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/middleware/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Configuration for A2A client */
|
|
2
|
+
export interface A2AClientConfig {
|
|
3
|
+
/** Unique identifier for the agent */
|
|
4
|
+
agentId: string;
|
|
5
|
+
/** URL endpoint for the A2A agent */
|
|
6
|
+
agentUrl: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper around the A2A SDK client for communicating with external agents.
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
export declare class A2AClientWrapper {
|
|
13
|
+
private client;
|
|
14
|
+
private config;
|
|
15
|
+
constructor(config: A2AClientConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Sends a message to the A2A agent and returns the response.
|
|
18
|
+
* @param messageText - The message to send to the agent
|
|
19
|
+
* @returns The agent's response as a string
|
|
20
|
+
*/
|
|
21
|
+
sendMessage(messageText: string): Promise<string>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module A2AClientWrapper
|
|
3
|
+
* Wrapper for A2A (Agent-to-Agent) protocol client.
|
|
4
|
+
* @experimental A2A support is experimental and may change.
|
|
5
|
+
*/
|
|
6
|
+
import { A2AClient } from '@a2a-js/sdk/client';
|
|
7
|
+
import { debugLog, debugLogError } from '@gaunt-sloth/core/utils/debugUtils.js';
|
|
8
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
/**
|
|
10
|
+
* Wrapper around the A2A SDK client for communicating with external agents.
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
export class A2AClientWrapper {
|
|
14
|
+
client;
|
|
15
|
+
config;
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
// Initialize with agent URL. The SDK will fetch the agent card.
|
|
19
|
+
this.client = new A2AClient(config.agentUrl);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sends a message to the A2A agent and returns the response.
|
|
23
|
+
* @param messageText - The message to send to the agent
|
|
24
|
+
* @returns The agent's response as a string
|
|
25
|
+
*/
|
|
26
|
+
async sendMessage(messageText) {
|
|
27
|
+
debugLog(`Sending message to A2A agent ${this.config.agentId} at ${this.config.agentUrl}: ${messageText}`);
|
|
28
|
+
try {
|
|
29
|
+
const messageId = uuidv4();
|
|
30
|
+
const response = await this.client.sendMessage({
|
|
31
|
+
message: {
|
|
32
|
+
kind: 'message',
|
|
33
|
+
messageId: messageId,
|
|
34
|
+
role: 'user',
|
|
35
|
+
parts: [{ kind: 'text', text: messageText }],
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
debugLog(`Received response from A2A agent: ${JSON.stringify(response)}`);
|
|
39
|
+
// Check for error response
|
|
40
|
+
if ('error' in response) {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
throw new Error(`A2A Error: ${JSON.stringify(response.error)}`);
|
|
43
|
+
}
|
|
44
|
+
// Extract text from response
|
|
45
|
+
// The result is likely a TaskStatus which contains a message
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const result = response.result;
|
|
48
|
+
if (result.message && result.message.parts && result.message.parts.length > 0) {
|
|
49
|
+
// Assuming the first part is text for now
|
|
50
|
+
return result.message.parts[0].text || JSON.stringify(result.message.parts);
|
|
51
|
+
}
|
|
52
|
+
else if (result.state) {
|
|
53
|
+
return `Task state: ${result.state}`;
|
|
54
|
+
}
|
|
55
|
+
return JSON.stringify(result);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
debugLogError('Error sending message to A2A agent', error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=A2AClientWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A2AClientWrapper.js","sourceRoot":"","sources":["../../../src/modules/a2a/A2AClientWrapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAUpC;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAY;IAClB,MAAM,CAAkB;IAEhC,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,gEAAgE;QAChE,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,WAAmB;QACnC,QAAQ,CACN,gCAAgC,IAAI,CAAC,MAAM,CAAC,OAAO,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,WAAW,EAAE,CACjG,CAAC;QACF,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;YAC3B,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d,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* ACP (Agent Client Protocol) server entry for the Gaunt Sloth deep agent.
|
|
4
|
+
*
|
|
5
|
+
* This is a parallel front-door to the AG-UI server ({@link startAgUiServer}); both expose
|
|
6
|
+
* the SAME {@link GthDeepAgent}. AG-UI stays the robot-controller path; ACP is an additional
|
|
7
|
+
* way to drive Galvanized Pukeko from an ACP host (Zed, JetBrains, a future Pukeko client).
|
|
8
|
+
*
|
|
9
|
+
* It reuses {@link GthDeepAgent.buildDeepAgentParams} so tool resolution (with the filesystem
|
|
10
|
+
* disabled so deepagents owns fs access), the `.aiignore`/filesystem→permission mapping and the
|
|
11
|
+
* fs-denial-softening middleware are identical to the local runner path. `deepagents-acp`
|
|
12
|
+
* supplies the rest of the coding-agent surface itself: a per-session `ACPFilesystemBackend`
|
|
13
|
+
* (proxying reads/writes through the ACP client so unsaved editor buffers are visible), the
|
|
14
|
+
* checkpointer, interactive `session/request_permission` gating, and tool-call/plan reporting.
|
|
15
|
+
*/
|
|
16
|
+
import type { GthConfig } from '@gaunt-sloth/core/config.js';
|
|
17
|
+
import type { GthCommand } from '@gaunt-sloth/core/core/types.js';
|
|
18
|
+
export interface StartAcpServerOptions {
|
|
19
|
+
/** Agent name advertised to the ACP client (used for session routing). */
|
|
20
|
+
name?: string;
|
|
21
|
+
/** Human-readable description shown to ACP clients when listing agents. */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** gsloth command whose config/prompt to apply (defaults to `'code'`, the full-fs agent). */
|
|
24
|
+
command?: GthCommand;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Start the Gaunt Sloth deep agent as an ACP server over stdio.
|
|
28
|
+
*
|
|
29
|
+
* Resolves once the stdio transport is listening; the process then stays alive serving the
|
|
30
|
+
* ACP host until it is terminated. The returned promise rejecting means startup failed.
|
|
31
|
+
*
|
|
32
|
+
* NOTE: deepagents-acp 0.1.12 does NOT forward `permissions` to `createDeepAgent` — on the ACP
|
|
33
|
+
* path fs gating is delegated to the host's interactive permission prompts, not gsloth's
|
|
34
|
+
* `.aiignore`→permissions mapping. `permissions` is still passed here for forward-compatibility
|
|
35
|
+
* (if a later deepagents-acp forwards it, gsloth's mapping applies with no change here).
|
|
36
|
+
*/
|
|
37
|
+
export declare function startAcpServer(config: GthConfig, options?: StartAcpServerOptions): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* ACP (Agent Client Protocol) server entry for the Gaunt Sloth deep agent.
|
|
4
|
+
*
|
|
5
|
+
* This is a parallel front-door to the AG-UI server ({@link startAgUiServer}); both expose
|
|
6
|
+
* the SAME {@link GthDeepAgent}. AG-UI stays the robot-controller path; ACP is an additional
|
|
7
|
+
* way to drive Galvanized Pukeko from an ACP host (Zed, JetBrains, a future Pukeko client).
|
|
8
|
+
*
|
|
9
|
+
* It reuses {@link GthDeepAgent.buildDeepAgentParams} so tool resolution (with the filesystem
|
|
10
|
+
* disabled so deepagents owns fs access), the `.aiignore`/filesystem→permission mapping and the
|
|
11
|
+
* fs-denial-softening middleware are identical to the local runner path. `deepagents-acp`
|
|
12
|
+
* supplies the rest of the coding-agent surface itself: a per-session `ACPFilesystemBackend`
|
|
13
|
+
* (proxying reads/writes through the ACP client so unsaved editor buffers are visible), the
|
|
14
|
+
* checkpointer, interactive `session/request_permission` gating, and tool-call/plan reporting.
|
|
15
|
+
*/
|
|
16
|
+
import { getProcessCwd, stderr } from '@gaunt-sloth/core/utils/systemUtils.js';
|
|
17
|
+
import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
|
|
18
|
+
import { GthDeepAgent } from '#src/core/GthDeepAgent.js';
|
|
19
|
+
import { startGthAcpServer } from '#src/core/gthAcpServer.js';
|
|
20
|
+
import { createResolvers } from '#src/resolvers.js';
|
|
21
|
+
/**
|
|
22
|
+
* ACP-side status routing: the ACP protocol owns stdout (JSON-RPC framing), so agent
|
|
23
|
+
* status/info must never touch it. Route everything to stderr.
|
|
24
|
+
*/
|
|
25
|
+
const acpStatusUpdate = (_level, message) => {
|
|
26
|
+
stderr.write(`${message}\n`);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Start the Gaunt Sloth deep agent as an ACP server over stdio.
|
|
30
|
+
*
|
|
31
|
+
* Resolves once the stdio transport is listening; the process then stays alive serving the
|
|
32
|
+
* ACP host until it is terminated. The returned promise rejecting means startup failed.
|
|
33
|
+
*
|
|
34
|
+
* NOTE: deepagents-acp 0.1.12 does NOT forward `permissions` to `createDeepAgent` — on the ACP
|
|
35
|
+
* path fs gating is delegated to the host's interactive permission prompts, not gsloth's
|
|
36
|
+
* `.aiignore`→permissions mapping. `permissions` is still passed here for forward-compatibility
|
|
37
|
+
* (if a later deepagents-acp forwards it, gsloth's mapping applies with no change here).
|
|
38
|
+
*/
|
|
39
|
+
export async function startAcpServer(config, options = {}) {
|
|
40
|
+
const command = options.command ?? 'code';
|
|
41
|
+
const agent = new GthDeepAgent(acpStatusUpdate, createResolvers());
|
|
42
|
+
const params = await agent.buildDeepAgentParams(command, config);
|
|
43
|
+
// gsloth's composed system prompt (backstory + guidelines + per-command mode prompt + system
|
|
44
|
+
// prompt) comes back on `params.systemPrompt` — the SAME prompt the local runner passes to
|
|
45
|
+
// createDeepAgent. ACP has no per-turn hook, so it sets the agent's `systemPrompt` here.
|
|
46
|
+
const systemPrompt = params.systemPrompt;
|
|
47
|
+
// workspaceRoot is only the startup default: startGthAcpServer re-roots the filesystem backend
|
|
48
|
+
// to each ACP session's `cwd` (the IDE's project root). Use the raw process cwd, not
|
|
49
|
+
// getCurrentWorkDir() — its INIT_CWD preference leaks stale paths into this long-lived subprocess.
|
|
50
|
+
const workspaceRoot = getProcessCwd();
|
|
51
|
+
debugLog(`Starting ACP server (command: ${command}, startup workspace: ${workspaceRoot})`);
|
|
52
|
+
await startGthAcpServer({
|
|
53
|
+
agents: {
|
|
54
|
+
name: options.name ?? 'gaunt-sloth',
|
|
55
|
+
description: options.description ?? 'Gaunt Sloth deep coding agent',
|
|
56
|
+
model: params.model,
|
|
57
|
+
tools: params.tools,
|
|
58
|
+
systemPrompt,
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
middleware: params.middleware,
|
|
61
|
+
// Forward-compat: ignored by deepagents-acp 0.1.12 (the host gates fs interactively).
|
|
62
|
+
permissions: params.permissions,
|
|
63
|
+
},
|
|
64
|
+
workspaceRoot,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=acpModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acpModule.js","sourceRoot":"","sources":["../../src/modules/acpModule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAWpD;;;GAGG;AACH,MAAM,eAAe,GAAyB,CAAC,MAAmB,EAAE,OAAe,EAAQ,EAAE;IAC3F,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAiB,EACjB,UAAiC,EAAE;IAEnC,MAAM,OAAO,GAAe,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC;IAEtD,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;IACnE,MAA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