gauss-ts 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-CMp1wFzs.d.cts → agent-DXZT4Hd-.d.cts} +320 -6
- package/dist/{agent-CHrSUkPz.d.ts → agent-nEZAfWFD.d.ts} +320 -6
- package/dist/agent.cjs +4 -1
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +5 -3
- package/dist/agent.d.ts +5 -3
- package/dist/agent.js +4 -1
- package/dist/agent.js.map +1 -1
- package/dist/guardrail-8Z_HuIIT.d.ts +32 -0
- package/dist/guardrail-BGqhOeWA.d.cts +32 -0
- package/dist/index.cjs +26 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -8
- package/dist/index.d.ts +97 -8
- package/dist/index.js +26 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +1 -1
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/memory-BGrAWNqI.d.cts +28 -0
- package/dist/memory-U2EleSW-.d.ts +28 -0
- package/dist/middleware.d.cts +3 -31
- package/dist/middleware.d.ts +3 -31
- package/dist/orchestration.cjs +3 -1
- package/dist/orchestration.cjs.map +1 -1
- package/dist/orchestration.d.cts +20 -3
- package/dist/orchestration.d.ts +20 -3
- package/dist/orchestration.js +3 -1
- package/dist/orchestration.js.map +1 -1
- package/dist/rag.cjs +1 -1
- package/dist/rag.cjs.map +1 -1
- package/dist/rag.d.cts +7 -27
- package/dist/rag.d.ts +7 -27
- package/dist/rag.js +1 -1
- package/dist/rag.js.map +1 -1
- package/dist/tools.d.cts +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/{types-BkwC4s1P.d.cts → types-BayYAhZL.d.cts} +1 -1
- package/dist/{types-BkwC4s1P.d.ts → types-BayYAhZL.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { H as Handle, T as ToolDef,
|
|
1
|
+
import { H as Handle, T as ToolDef, a as Message, A as AgentOptions, b as ToolExecutor, c as AgentResult, D as Disposable, d as ProviderType, e as ProviderOptions, C as CodeExecutionOptions, f as ProviderCapabilities, S as StreamCallback } from './types-BayYAhZL.cjs';
|
|
2
|
+
import { M as MiddlewareChain, G as GuardrailChain } from './guardrail-BGqhOeWA.cjs';
|
|
3
|
+
import { M as Memory } from './memory-BGrAWNqI.cjs';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* A single event emitted during agent streaming.
|
|
@@ -100,6 +102,219 @@ declare class AgentStream implements AsyncIterable<StreamEvent> {
|
|
|
100
102
|
[Symbol.asyncIterator](): AsyncIterator<StreamEvent>;
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Typed Tool System — define tools with inline execute callbacks.
|
|
107
|
+
*
|
|
108
|
+
* Quick start:
|
|
109
|
+
* const weather = tool({
|
|
110
|
+
* name: "get_weather",
|
|
111
|
+
* description: "Get current weather for a city",
|
|
112
|
+
* parameters: { city: { type: "string", description: "City name" } },
|
|
113
|
+
* execute: async ({ city }) => ({ temp: 72, unit: "F", city }),
|
|
114
|
+
* });
|
|
115
|
+
* agent.addTools([weather]);
|
|
116
|
+
*
|
|
117
|
+
* The tool() helper creates a TypedToolDef that the agent auto-wires
|
|
118
|
+
* into a ToolExecutor when it detects typed tools with execute callbacks.
|
|
119
|
+
*
|
|
120
|
+
* @since 1.2.0
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A tool definition with a typed execute callback.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam TParams - The shape of the tool's input parameters.
|
|
127
|
+
* @typeParam TResult - The shape of the tool's return value.
|
|
128
|
+
*/
|
|
129
|
+
interface TypedToolDef<TParams = Record<string, unknown>, TResult = unknown> extends ToolDef {
|
|
130
|
+
/** The function to execute when the LLM invokes this tool. */
|
|
131
|
+
execute: (params: TParams) => Promise<TResult> | TResult;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a typed tool with an inline execute callback.
|
|
135
|
+
*
|
|
136
|
+
* @description Defines a tool that the agent can invoke during the agentic loop.
|
|
137
|
+
* When the LLM calls this tool, the `execute` callback is automatically invoked
|
|
138
|
+
* with the parsed parameters and the return value is sent back to the model.
|
|
139
|
+
*
|
|
140
|
+
* @param config - Tool configuration with name, description, parameters schema, and execute callback.
|
|
141
|
+
* @returns A {@link TypedToolDef} that can be passed to `agent.addTool()` or `agent.addTools()`.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const calculator = tool({
|
|
146
|
+
* name: "calculate",
|
|
147
|
+
* description: "Evaluate a math expression",
|
|
148
|
+
* parameters: {
|
|
149
|
+
* expression: { type: "string", description: "Math expression to evaluate" },
|
|
150
|
+
* },
|
|
151
|
+
* execute: async ({ expression }) => {
|
|
152
|
+
* return { result: eval(expression) };
|
|
153
|
+
* },
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* const agent = new Agent({ instructions: "You can do math." });
|
|
157
|
+
* agent.addTools([calculator]);
|
|
158
|
+
* const result = await agent.run("What is 2+2?");
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @since 1.2.0
|
|
162
|
+
*/
|
|
163
|
+
declare function tool<TParams = Record<string, unknown>, TResult = unknown>(config: {
|
|
164
|
+
name: string;
|
|
165
|
+
description: string;
|
|
166
|
+
parameters?: Record<string, unknown>;
|
|
167
|
+
execute: (params: TParams) => Promise<TResult> | TResult;
|
|
168
|
+
}): TypedToolDef<TParams, TResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Check if a tool definition has an execute callback (is a TypedToolDef).
|
|
171
|
+
*/
|
|
172
|
+
declare function isTypedTool(t: ToolDef): t is TypedToolDef;
|
|
173
|
+
/**
|
|
174
|
+
* Build a {@link ToolExecutor} from an array of typed tools.
|
|
175
|
+
*
|
|
176
|
+
* @description Creates a single async function that dispatches tool calls
|
|
177
|
+
* to the correct typed tool's execute callback based on the tool name.
|
|
178
|
+
*
|
|
179
|
+
* @param tools - Array of typed tool definitions with execute callbacks.
|
|
180
|
+
* @param fallback - Optional fallback executor for tools without execute callbacks.
|
|
181
|
+
* @returns A {@link ToolExecutor} that can be passed to `agent.runWithTools()`.
|
|
182
|
+
*
|
|
183
|
+
* @since 1.2.0
|
|
184
|
+
*/
|
|
185
|
+
declare function createToolExecutor(tools: TypedToolDef<any, any>[], fallback?: ToolExecutor): ToolExecutor;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* MCP Client — consume tools from external MCP servers.
|
|
189
|
+
*
|
|
190
|
+
* Quick start:
|
|
191
|
+
* const client = new McpClient({ command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem"] });
|
|
192
|
+
* await client.connect();
|
|
193
|
+
* const tools = await client.listTools();
|
|
194
|
+
* const result = await client.callTool("read_file", { path: "README.md" });
|
|
195
|
+
* client.close();
|
|
196
|
+
*
|
|
197
|
+
* Supports stdio transport (spawn subprocess) for local MCP servers.
|
|
198
|
+
*
|
|
199
|
+
* @since 1.2.0
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
/** Configuration for creating an MCP client. */
|
|
203
|
+
interface McpClientConfig {
|
|
204
|
+
/** Command to spawn the MCP server process (stdio transport). */
|
|
205
|
+
command: string;
|
|
206
|
+
/** Arguments for the command. */
|
|
207
|
+
args?: string[];
|
|
208
|
+
/** Environment variables for the subprocess. */
|
|
209
|
+
env?: Record<string, string>;
|
|
210
|
+
/** Connection timeout in milliseconds (default: 10000). */
|
|
211
|
+
timeoutMs?: number;
|
|
212
|
+
}
|
|
213
|
+
/** A tool definition from an MCP server. */
|
|
214
|
+
interface McpToolDef {
|
|
215
|
+
name: string;
|
|
216
|
+
description?: string;
|
|
217
|
+
inputSchema?: Record<string, unknown>;
|
|
218
|
+
}
|
|
219
|
+
/** Result from calling a tool on an MCP server. */
|
|
220
|
+
interface McpToolResult {
|
|
221
|
+
content: Array<{
|
|
222
|
+
type: string;
|
|
223
|
+
text?: string;
|
|
224
|
+
data?: string;
|
|
225
|
+
mimeType?: string;
|
|
226
|
+
}>;
|
|
227
|
+
isError?: boolean;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Client for consuming tools from external MCP (Model Context Protocol) servers.
|
|
231
|
+
*
|
|
232
|
+
* @description Connects to an MCP server via stdio transport (subprocess),
|
|
233
|
+
* performs the initialization handshake, and provides methods to list and
|
|
234
|
+
* call tools. Tools can be wired into agents via `agent.useMcpServer()`.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const client = new McpClient({
|
|
239
|
+
* command: "npx",
|
|
240
|
+
* args: ["-y", "@modelcontextprotocol/server-everything"],
|
|
241
|
+
* });
|
|
242
|
+
* await client.connect();
|
|
243
|
+
*
|
|
244
|
+
* const tools = await client.listTools();
|
|
245
|
+
* console.log(tools); // [{ name: "echo", description: "...", parameters: {...} }]
|
|
246
|
+
*
|
|
247
|
+
* const result = await client.callTool("echo", { message: "hello" });
|
|
248
|
+
* console.log(result); // { content: [{ type: "text", text: "hello" }] }
|
|
249
|
+
*
|
|
250
|
+
* client.close();
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @since 1.2.0
|
|
254
|
+
*/
|
|
255
|
+
declare class McpClient implements Disposable {
|
|
256
|
+
private readonly config;
|
|
257
|
+
private process;
|
|
258
|
+
private connected;
|
|
259
|
+
private closed;
|
|
260
|
+
private nextId;
|
|
261
|
+
private readonly pending;
|
|
262
|
+
private buffer;
|
|
263
|
+
private serverCapabilities;
|
|
264
|
+
private cachedTools;
|
|
265
|
+
constructor(config: McpClientConfig);
|
|
266
|
+
/**
|
|
267
|
+
* Connect to the MCP server and perform the initialization handshake.
|
|
268
|
+
*
|
|
269
|
+
* @throws {Error} If connection times out or the server rejects initialization.
|
|
270
|
+
*/
|
|
271
|
+
connect(): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* List all tools available on the connected MCP server.
|
|
274
|
+
*
|
|
275
|
+
* @returns Array of tool definitions in Gauss SDK format.
|
|
276
|
+
* @throws {Error} If not connected.
|
|
277
|
+
*/
|
|
278
|
+
listTools(): Promise<ToolDef[]>;
|
|
279
|
+
/**
|
|
280
|
+
* Call a tool on the MCP server.
|
|
281
|
+
*
|
|
282
|
+
* @param toolName - Name of the tool to invoke.
|
|
283
|
+
* @param args - Arguments to pass to the tool.
|
|
284
|
+
* @returns The tool execution result.
|
|
285
|
+
* @throws {Error} If not connected or the tool call fails.
|
|
286
|
+
*/
|
|
287
|
+
callTool(toolName: string, args?: Record<string, unknown>): Promise<McpToolResult>;
|
|
288
|
+
/**
|
|
289
|
+
* Get all tools as Gauss ToolDefs with a wired ToolExecutor.
|
|
290
|
+
*
|
|
291
|
+
* @description Returns the tools and a ToolExecutor that routes
|
|
292
|
+
* tool calls to this MCP server. Used by `agent.useMcpServer()`.
|
|
293
|
+
*
|
|
294
|
+
* @returns Object with `tools` (ToolDef[]) and `executor` (ToolExecutor).
|
|
295
|
+
*/
|
|
296
|
+
getToolsWithExecutor(): Promise<{
|
|
297
|
+
tools: ToolDef[];
|
|
298
|
+
executor: (callJson: string) => Promise<string>;
|
|
299
|
+
}>;
|
|
300
|
+
/**
|
|
301
|
+
* Close the connection and terminate the subprocess.
|
|
302
|
+
*/
|
|
303
|
+
close(): void;
|
|
304
|
+
/** Alias for close() — enables `using` pattern. */
|
|
305
|
+
destroy(): void;
|
|
306
|
+
[Symbol.dispose](): void;
|
|
307
|
+
/** Whether the client is currently connected. */
|
|
308
|
+
get isConnected(): boolean;
|
|
309
|
+
private request;
|
|
310
|
+
private notify;
|
|
311
|
+
private send;
|
|
312
|
+
private onData;
|
|
313
|
+
private onProcessError;
|
|
314
|
+
private onProcessClose;
|
|
315
|
+
private assertConnected;
|
|
316
|
+
}
|
|
317
|
+
|
|
103
318
|
/**
|
|
104
319
|
* Configuration object for creating an {@link Agent} instance.
|
|
105
320
|
*
|
|
@@ -129,8 +344,18 @@ interface AgentConfig {
|
|
|
129
344
|
providerOptions?: ProviderOptions;
|
|
130
345
|
/** System instructions prepended to every conversation. */
|
|
131
346
|
instructions?: string;
|
|
132
|
-
/** Tool definitions available to the agent. */
|
|
133
|
-
tools?: ToolDef[];
|
|
347
|
+
/** Tool definitions available to the agent. Accepts both raw ToolDef and typed tools with execute callbacks. */
|
|
348
|
+
tools?: (ToolDef | TypedToolDef)[];
|
|
349
|
+
/** Middleware chain to apply (logging, caching, rate limiting). */
|
|
350
|
+
middleware?: MiddlewareChain;
|
|
351
|
+
/** Guardrail chain to apply (PII, content moderation, schema validation). */
|
|
352
|
+
guardrails?: GuardrailChain;
|
|
353
|
+
/** Memory instance for automatic conversation history. */
|
|
354
|
+
memory?: Memory;
|
|
355
|
+
/** Session ID for memory scoping (default: auto-generated). */
|
|
356
|
+
sessionId?: string;
|
|
357
|
+
/** MCP clients to consume tools from external MCP servers. */
|
|
358
|
+
mcpClients?: McpClient[];
|
|
134
359
|
/** Sampling temperature (0–2). Higher values produce more creative output. */
|
|
135
360
|
temperature?: number;
|
|
136
361
|
/** Maximum number of agentic loop iterations before stopping. */
|
|
@@ -191,6 +416,12 @@ declare class Agent implements Disposable {
|
|
|
191
416
|
private _tools;
|
|
192
417
|
private _options;
|
|
193
418
|
private disposed;
|
|
419
|
+
private _middleware;
|
|
420
|
+
private _guardrails;
|
|
421
|
+
private _memory;
|
|
422
|
+
private _sessionId;
|
|
423
|
+
private _mcpClients;
|
|
424
|
+
private _mcpToolsLoaded;
|
|
194
425
|
/**
|
|
195
426
|
* Create a new Agent.
|
|
196
427
|
*
|
|
@@ -256,7 +487,7 @@ declare class Agent implements Disposable {
|
|
|
256
487
|
*
|
|
257
488
|
* @since 1.0.0
|
|
258
489
|
*/
|
|
259
|
-
addTool(tool: ToolDef): this;
|
|
490
|
+
addTool(tool: ToolDef | TypedToolDef): this;
|
|
260
491
|
/**
|
|
261
492
|
* Register multiple tool definitions at once. Chainable.
|
|
262
493
|
*
|
|
@@ -275,7 +506,7 @@ declare class Agent implements Disposable {
|
|
|
275
506
|
*
|
|
276
507
|
* @since 1.0.0
|
|
277
508
|
*/
|
|
278
|
-
addTools(tools: ToolDef[]): this;
|
|
509
|
+
addTools(tools: (ToolDef | TypedToolDef)[]): this;
|
|
279
510
|
/**
|
|
280
511
|
* Merge additional agent options into the current configuration. Chainable.
|
|
281
512
|
*
|
|
@@ -292,6 +523,79 @@ declare class Agent implements Disposable {
|
|
|
292
523
|
* @since 1.0.0
|
|
293
524
|
*/
|
|
294
525
|
setOptions(options: Partial<AgentOptions>): this;
|
|
526
|
+
/**
|
|
527
|
+
* Attach a middleware chain (logging, caching, rate limiting). Chainable.
|
|
528
|
+
*
|
|
529
|
+
* @param chain - A configured {@link MiddlewareChain} instance.
|
|
530
|
+
* @returns `this` for fluent chaining.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* agent.withMiddleware(
|
|
535
|
+
* new MiddlewareChain().useLogging().useCaching(60000).useRateLimit(100)
|
|
536
|
+
* );
|
|
537
|
+
* ```
|
|
538
|
+
*
|
|
539
|
+
* @since 1.2.0
|
|
540
|
+
*/
|
|
541
|
+
withMiddleware(chain: MiddlewareChain): this;
|
|
542
|
+
/**
|
|
543
|
+
* Attach a guardrail chain (content moderation, PII, schema validation). Chainable.
|
|
544
|
+
*
|
|
545
|
+
* @param chain - A configured {@link GuardrailChain} instance.
|
|
546
|
+
* @returns `this` for fluent chaining.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* agent.withGuardrails(
|
|
551
|
+
* new GuardrailChain().addPiiDetection("redact").addContentModeration(["violence"], [])
|
|
552
|
+
* );
|
|
553
|
+
* ```
|
|
554
|
+
*
|
|
555
|
+
* @since 1.2.0
|
|
556
|
+
*/
|
|
557
|
+
withGuardrails(chain: GuardrailChain): this;
|
|
558
|
+
/**
|
|
559
|
+
* Attach memory for automatic conversation history. Chainable.
|
|
560
|
+
*
|
|
561
|
+
* @description When memory is attached, the agent automatically:
|
|
562
|
+
* - Recalls recent entries before each run (prepended as context)
|
|
563
|
+
* - Stores the conversation (input + output) after each run
|
|
564
|
+
*
|
|
565
|
+
* @param memory - A {@link Memory} instance.
|
|
566
|
+
* @param sessionId - Optional session ID for scoping memory entries.
|
|
567
|
+
* @returns `this` for fluent chaining.
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* ```ts
|
|
571
|
+
* const memory = new Memory();
|
|
572
|
+
* agent.withMemory(memory, "session-123");
|
|
573
|
+
* await agent.run("Hello!"); // stored in memory
|
|
574
|
+
* await agent.run("What did I just say?"); // recalls previous context
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @since 1.2.0
|
|
578
|
+
*/
|
|
579
|
+
withMemory(memory: Memory, sessionId?: string): this;
|
|
580
|
+
/**
|
|
581
|
+
* Consume tools from an external MCP server. Chainable.
|
|
582
|
+
*
|
|
583
|
+
* @description Registers an MCP client whose tools will be loaded
|
|
584
|
+
* and made available to the agent on the first run.
|
|
585
|
+
*
|
|
586
|
+
* @param client - A connected {@link McpClient} instance.
|
|
587
|
+
* @returns `this` for fluent chaining.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```ts
|
|
591
|
+
* const mcp = new McpClient({ command: "npx", args: ["-y", "@mcp/server-fs"] });
|
|
592
|
+
* await mcp.connect();
|
|
593
|
+
* agent.useMcpServer(mcp);
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @since 1.2.0
|
|
597
|
+
*/
|
|
598
|
+
useMcpServer(client: McpClient): this;
|
|
295
599
|
/**
|
|
296
600
|
* Run the agentic loop to completion.
|
|
297
601
|
*
|
|
@@ -458,6 +762,16 @@ declare class Agent implements Disposable {
|
|
|
458
762
|
*/
|
|
459
763
|
[Symbol.dispose](): void;
|
|
460
764
|
private assertNotDisposed;
|
|
765
|
+
/**
|
|
766
|
+
* Resolve typed tools into plain ToolDefs + a ToolExecutor.
|
|
767
|
+
* @internal
|
|
768
|
+
*/
|
|
769
|
+
private resolveToolsAndExecutor;
|
|
770
|
+
/**
|
|
771
|
+
* Load tools from all connected MCP clients (lazy, once).
|
|
772
|
+
* @internal
|
|
773
|
+
*/
|
|
774
|
+
private ensureMcpTools;
|
|
461
775
|
}
|
|
462
776
|
/**
|
|
463
777
|
* One-liner convenience function — create an agent, run a prompt, and return the text.
|
|
@@ -482,4 +796,4 @@ declare class Agent implements Disposable {
|
|
|
482
796
|
*/
|
|
483
797
|
declare function gauss(prompt: string, config?: Omit<AgentConfig, "name">): Promise<string>;
|
|
484
798
|
|
|
485
|
-
export { type AgentConfig as A, type StreamEvent as S, Agent as a, AgentStream as b, gauss as g };
|
|
799
|
+
export { type AgentConfig as A, McpClient as M, type StreamEvent as S, type TypedToolDef as T, Agent as a, AgentStream as b, type McpClientConfig as c, type McpToolDef as d, type McpToolResult as e, createToolExecutor as f, gauss as g, isTypedTool as i, tool as t };
|