ctxpkg 0.0.1 → 0.0.4
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/bin/cli.js +1 -1
- package/bin/daemon.js +1 -1
- package/dist/agent/agent.d.ts +65 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +291 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/agent.prompts.d.ts +13 -0
- package/dist/agent/agent.prompts.d.ts.map +1 -0
- package/{src/agent/agent.prompts.ts → dist/agent/agent.prompts.js} +11 -12
- package/dist/agent/agent.prompts.js.map +1 -0
- package/dist/agent/agent.test-runner.d.ts +73 -0
- package/dist/agent/agent.test-runner.d.ts.map +1 -0
- package/dist/agent/agent.test-runner.js +316 -0
- package/dist/agent/agent.test-runner.js.map +1 -0
- package/dist/agent/agent.test-runner.schemas.d.ts +382 -0
- package/dist/agent/agent.test-runner.schemas.d.ts.map +1 -0
- package/dist/agent/agent.test-runner.schemas.js +110 -0
- package/dist/agent/agent.test-runner.schemas.js.map +1 -0
- package/dist/agent/agent.types.d.ts +122 -0
- package/dist/agent/agent.types.d.ts.map +1 -0
- package/dist/agent/agent.types.js +19 -0
- package/dist/agent/agent.types.js.map +1 -0
- package/dist/backend/backend.d.ts +16 -0
- package/dist/backend/backend.d.ts.map +1 -0
- package/dist/backend/backend.js +79 -0
- package/dist/backend/backend.js.map +1 -0
- package/dist/backend/backend.protocol.d.ts +74 -0
- package/dist/backend/backend.protocol.d.ts.map +1 -0
- package/dist/backend/backend.protocol.js +46 -0
- package/dist/backend/backend.protocol.js.map +1 -0
- package/dist/backend/backend.schemas.d.ts +141 -0
- package/dist/backend/backend.schemas.d.ts.map +1 -0
- package/dist/backend/backend.schemas.js +59 -0
- package/dist/backend/backend.schemas.js.map +1 -0
- package/dist/backend/backend.services.d.ts +290 -0
- package/dist/backend/backend.services.d.ts.map +1 -0
- package/dist/backend/backend.services.js +103 -0
- package/dist/backend/backend.services.js.map +1 -0
- package/dist/backend/backend.types.d.ts +25 -0
- package/dist/backend/backend.types.d.ts.map +1 -0
- package/dist/backend/backend.types.js +6 -0
- package/dist/backend/backend.types.js.map +1 -0
- package/dist/cli/cli.agent.d.ts +4 -0
- package/dist/cli/cli.agent.d.ts.map +1 -0
- package/dist/cli/cli.agent.js +158 -0
- package/dist/cli/cli.agent.js.map +1 -0
- package/dist/cli/cli.chat.d.ts +4 -0
- package/dist/cli/cli.chat.d.ts.map +1 -0
- package/dist/cli/cli.chat.js +311 -0
- package/dist/cli/cli.chat.js.map +1 -0
- package/dist/cli/cli.client.d.ts +11 -0
- package/dist/cli/cli.client.d.ts.map +1 -0
- package/dist/cli/cli.client.js +40 -0
- package/dist/cli/cli.client.js.map +1 -0
- package/dist/cli/cli.collections.d.ts +4 -0
- package/dist/cli/cli.collections.d.ts.map +1 -0
- package/dist/cli/cli.collections.js +411 -0
- package/dist/cli/cli.collections.js.map +1 -0
- package/dist/cli/cli.config.d.ts +4 -0
- package/dist/cli/cli.config.d.ts.map +1 -0
- package/dist/cli/cli.config.js +192 -0
- package/dist/cli/cli.config.js.map +1 -0
- package/dist/cli/cli.d.ts +4 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.daemon.d.ts +4 -0
- package/dist/cli/cli.daemon.d.ts.map +1 -0
- package/dist/cli/cli.daemon.js +116 -0
- package/dist/cli/cli.daemon.js.map +1 -0
- package/dist/cli/cli.documents.d.ts +4 -0
- package/dist/cli/cli.documents.d.ts.map +1 -0
- package/dist/cli/cli.documents.js +332 -0
- package/dist/cli/cli.documents.js.map +1 -0
- package/dist/cli/cli.js +23 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/cli.mcp.d.ts +4 -0
- package/dist/cli/cli.mcp.d.ts.map +1 -0
- package/dist/cli/cli.mcp.js +146 -0
- package/dist/cli/cli.mcp.js.map +1 -0
- package/dist/cli/cli.utils.d.ts +51 -0
- package/dist/cli/cli.utils.d.ts.map +1 -0
- package/dist/cli/cli.utils.js +95 -0
- package/dist/cli/cli.utils.js.map +1 -0
- package/dist/client/client.adapters.d.ts +38 -0
- package/dist/client/client.adapters.d.ts.map +1 -0
- package/dist/client/client.adapters.js +233 -0
- package/dist/client/client.adapters.js.map +1 -0
- package/dist/client/client.d.ts +16 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +74 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/client.types.d.ts +10 -0
- package/dist/client/client.types.d.ts.map +1 -0
- package/dist/client/client.types.js +2 -0
- package/dist/client/client.types.js.map +1 -0
- package/dist/collections/collections.d.ts +219 -0
- package/dist/collections/collections.d.ts.map +1 -0
- package/dist/collections/collections.js +933 -0
- package/dist/collections/collections.js.map +1 -0
- package/dist/collections/collections.schemas.d.ts +298 -0
- package/dist/collections/collections.schemas.d.ts.map +1 -0
- package/dist/collections/collections.schemas.js +117 -0
- package/dist/collections/collections.schemas.js.map +1 -0
- package/dist/config/config.d.ts +29 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +112 -0
- package/dist/config/config.js.map +1 -0
- package/dist/daemon/daemon.config.d.ts +6 -0
- package/dist/daemon/daemon.config.d.ts.map +1 -0
- package/dist/daemon/daemon.config.js +19 -0
- package/dist/daemon/daemon.config.js.map +1 -0
- package/dist/daemon/daemon.d.ts +10 -0
- package/dist/daemon/daemon.d.ts.map +1 -0
- package/dist/daemon/daemon.js +173 -0
- package/dist/daemon/daemon.js.map +1 -0
- package/dist/daemon/daemon.manager.d.ts +20 -0
- package/dist/daemon/daemon.manager.d.ts.map +1 -0
- package/dist/daemon/daemon.manager.js +176 -0
- package/dist/daemon/daemon.manager.js.map +1 -0
- package/dist/daemon/daemon.schemas.d.ts +38 -0
- package/dist/daemon/daemon.schemas.d.ts.map +1 -0
- package/dist/daemon/daemon.schemas.js +15 -0
- package/dist/daemon/daemon.schemas.js.map +1 -0
- package/dist/database/database.d.ts +10 -0
- package/dist/database/database.d.ts.map +1 -0
- package/dist/database/database.js +52 -0
- package/dist/database/database.js.map +1 -0
- package/dist/database/migrations/migrations.001-init.d.ts +9 -0
- package/dist/database/migrations/migrations.001-init.d.ts.map +1 -0
- package/dist/database/migrations/migrations.001-init.js +46 -0
- package/dist/database/migrations/migrations.001-init.js.map +1 -0
- package/dist/database/migrations/migrations.002-fts5.d.ts +11 -0
- package/dist/database/migrations/migrations.002-fts5.d.ts.map +1 -0
- package/dist/database/migrations/migrations.002-fts5.js +29 -0
- package/dist/database/migrations/migrations.002-fts5.js.map +1 -0
- package/dist/database/migrations/migrations.d.ts +11 -0
- package/dist/database/migrations/migrations.d.ts.map +1 -0
- package/dist/database/migrations/migrations.js +14 -0
- package/dist/database/migrations/migrations.js.map +1 -0
- package/dist/database/migrations/migrations.types.d.ts +8 -0
- package/dist/database/migrations/migrations.types.d.ts.map +1 -0
- package/dist/database/migrations/migrations.types.js +2 -0
- package/dist/database/migrations/migrations.types.js.map +1 -0
- package/dist/documents/documents.d.ts +58 -0
- package/dist/documents/documents.d.ts.map +1 -0
- package/dist/documents/documents.js +597 -0
- package/dist/documents/documents.js.map +1 -0
- package/dist/documents/documents.schemas.d.ts +418 -0
- package/dist/documents/documents.schemas.d.ts.map +1 -0
- package/dist/documents/documents.schemas.js +111 -0
- package/dist/documents/documents.schemas.js.map +1 -0
- package/dist/embedder/embedder.d.ts +22 -0
- package/dist/embedder/embedder.d.ts.map +1 -0
- package/dist/embedder/embedder.js +46 -0
- package/dist/embedder/embedder.js.map +1 -0
- package/dist/exports.d.ts +2 -0
- package/dist/exports.d.ts.map +1 -0
- package/dist/exports.js +2 -0
- package/dist/exports.js.map +1 -0
- package/dist/mcp/mcp.d.ts +44 -0
- package/dist/mcp/mcp.d.ts.map +1 -0
- package/dist/mcp/mcp.js +62 -0
- package/dist/mcp/mcp.js.map +1 -0
- package/dist/tools/agent/agent.d.ts +14 -0
- package/dist/tools/agent/agent.d.ts.map +1 -0
- package/dist/tools/agent/agent.js +31 -0
- package/dist/tools/agent/agent.js.map +1 -0
- package/dist/tools/documents/documents.d.ts +28 -0
- package/dist/tools/documents/documents.d.ts.map +1 -0
- package/dist/tools/documents/documents.js +336 -0
- package/dist/tools/documents/documents.js.map +1 -0
- package/dist/tools/tools.langchain.d.ts +11 -0
- package/dist/tools/tools.langchain.d.ts.map +1 -0
- package/dist/tools/tools.langchain.js +30 -0
- package/dist/tools/tools.langchain.js.map +1 -0
- package/dist/tools/tools.mcp.d.ts +12 -0
- package/dist/tools/tools.mcp.d.ts.map +1 -0
- package/dist/tools/tools.mcp.js +38 -0
- package/dist/tools/tools.mcp.js.map +1 -0
- package/{src/tools/tools.types.ts → dist/tools/tools.types.d.ts} +10 -16
- package/dist/tools/tools.types.d.ts.map +1 -0
- package/dist/tools/tools.types.js +7 -0
- package/dist/tools/tools.types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/utils.services.d.ts +14 -0
- package/dist/utils/utils.services.d.ts.map +1 -0
- package/dist/utils/utils.services.js +33 -0
- package/dist/utils/utils.services.js.map +1 -0
- package/package.json +5 -2
- package/src/agent/AGENTS.md +0 -249
- package/src/agent/agent.test-runner.schemas.ts +0 -158
- package/src/agent/agent.test-runner.ts +0 -436
- package/src/agent/agent.ts +0 -371
- package/src/agent/agent.types.ts +0 -94
- package/src/backend/AGENTS.md +0 -112
- package/src/backend/backend.protocol.ts +0 -95
- package/src/backend/backend.schemas.ts +0 -123
- package/src/backend/backend.services.ts +0 -151
- package/src/backend/backend.ts +0 -111
- package/src/backend/backend.types.ts +0 -34
- package/src/cli/AGENTS.md +0 -213
- package/src/cli/cli.agent.ts +0 -197
- package/src/cli/cli.chat.ts +0 -369
- package/src/cli/cli.client.ts +0 -55
- package/src/cli/cli.collections.ts +0 -491
- package/src/cli/cli.config.ts +0 -252
- package/src/cli/cli.daemon.ts +0 -160
- package/src/cli/cli.documents.ts +0 -413
- package/src/cli/cli.mcp.ts +0 -177
- package/src/cli/cli.ts +0 -28
- package/src/cli/cli.utils.ts +0 -122
- package/src/client/AGENTS.md +0 -135
- package/src/client/client.adapters.ts +0 -279
- package/src/client/client.ts +0 -86
- package/src/client/client.types.ts +0 -17
- package/src/collections/AGENTS.md +0 -185
- package/src/collections/collections.schemas.ts +0 -195
- package/src/collections/collections.ts +0 -1160
- package/src/config/config.ts +0 -118
- package/src/daemon/AGENTS.md +0 -168
- package/src/daemon/daemon.config.ts +0 -23
- package/src/daemon/daemon.manager.ts +0 -215
- package/src/daemon/daemon.schemas.ts +0 -22
- package/src/daemon/daemon.ts +0 -205
- package/src/database/AGENTS.md +0 -211
- package/src/database/database.ts +0 -64
- package/src/database/migrations/migrations.001-init.ts +0 -56
- package/src/database/migrations/migrations.002-fts5.ts +0 -32
- package/src/database/migrations/migrations.ts +0 -20
- package/src/database/migrations/migrations.types.ts +0 -9
- package/src/documents/AGENTS.md +0 -301
- package/src/documents/documents.schemas.ts +0 -190
- package/src/documents/documents.ts +0 -734
- package/src/embedder/embedder.ts +0 -53
- package/src/exports.ts +0 -0
- package/src/mcp/AGENTS.md +0 -264
- package/src/mcp/mcp.ts +0 -105
- package/src/tools/AGENTS.md +0 -228
- package/src/tools/agent/agent.ts +0 -45
- package/src/tools/documents/documents.ts +0 -401
- package/src/tools/tools.langchain.ts +0 -37
- package/src/tools/tools.mcp.ts +0 -46
- package/src/utils/utils.services.ts +0 -46
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Common tool definition format that can be converted to Langchain or MCP tools.
|
|
5
4
|
*
|
|
@@ -7,29 +6,24 @@ import * as z from 'zod';
|
|
|
7
6
|
* be adapted to different tool runtime environments.
|
|
8
7
|
*/
|
|
9
8
|
type ToolDefinition<TInput extends z.ZodType = z.ZodType, TOutput = unknown> = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
/** Unique name for the tool */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Description of what the tool does */
|
|
12
|
+
description: string;
|
|
13
|
+
/** Zod schema for input validation */
|
|
14
|
+
schema: TInput;
|
|
15
|
+
/** The handler function that executes the tool */
|
|
16
|
+
handler: (input: z.infer<TInput>) => Promise<TOutput>;
|
|
18
17
|
};
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* A collection of tool definitions - using eslint-disable for any here since
|
|
22
20
|
* the specific tool types are erased when collecting into a record
|
|
23
21
|
*/
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
22
|
type ToolDefinitions = Record<string, ToolDefinition<any, any>>;
|
|
26
|
-
|
|
27
23
|
/**
|
|
28
24
|
* Helper to create a type-safe tool definition
|
|
29
25
|
*/
|
|
30
|
-
const defineTool
|
|
31
|
-
definition: ToolDefinition<TInput, TOutput>,
|
|
32
|
-
): ToolDefinition<TInput, TOutput> => definition;
|
|
33
|
-
|
|
26
|
+
declare const defineTool: <TInput extends z.ZodType, TOutput>(definition: ToolDefinition<TInput, TOutput>) => ToolDefinition<TInput, TOutput>;
|
|
34
27
|
export { defineTool };
|
|
35
28
|
export type { ToolDefinition, ToolDefinitions };
|
|
29
|
+
//# sourceMappingURL=tools.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.types.d.ts","sourceRoot":"","sources":["../../src/tools/tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;;GAKG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI;IAC7E,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvD,CAAC;AAEF;;;GAGG;AAEH,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEhE;;GAEG;AACH,QAAA,MAAM,UAAU,GAAI,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,EACnD,YAAY,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1C,cAAc,CAAC,MAAM,EAAE,OAAO,CAAe,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.types.js","sourceRoot":"","sources":["../../src/tools/tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AA0BzB;;GAEG;AACH,MAAM,UAAU,GAAG,CACjB,UAA2C,EACV,EAAE,CAAC,UAAU,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/exports.ts","../src/agent/agent.prompts.ts","../src/agent/agent.test-runner.schemas.ts","../src/agent/agent.test-runner.ts","../src/agent/agent.ts","../src/agent/agent.types.ts","../src/backend/backend.protocol.ts","../src/backend/backend.schemas.ts","../src/backend/backend.services.ts","../src/backend/backend.ts","../src/backend/backend.types.ts","../src/cli/cli.agent.ts","../src/cli/cli.chat.ts","../src/cli/cli.client.ts","../src/cli/cli.collections.ts","../src/cli/cli.config.ts","../src/cli/cli.daemon.ts","../src/cli/cli.documents.ts","../src/cli/cli.mcp.ts","../src/cli/cli.ts","../src/cli/cli.utils.ts","../src/client/client.adapters.ts","../src/client/client.ts","../src/client/client.types.ts","../src/collections/collections.schemas.ts","../src/collections/collections.ts","../src/config/config.ts","../src/daemon/daemon.config.ts","../src/daemon/daemon.manager.ts","../src/daemon/daemon.schemas.ts","../src/daemon/daemon.ts","../src/database/database.ts","../src/database/migrations/migrations.001-init.ts","../src/database/migrations/migrations.002-fts5.ts","../src/database/migrations/migrations.ts","../src/database/migrations/migrations.types.ts","../src/documents/documents.schemas.ts","../src/documents/documents.ts","../src/embedder/embedder.ts","../src/mcp/mcp.ts","../src/tools/tools.langchain.ts","../src/tools/tools.mcp.ts","../src/tools/tools.types.ts","../src/tools/agent/agent.ts","../src/tools/documents/documents.ts","../src/utils/utils.services.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const destroy: unique symbol;
|
|
2
|
+
declare const instanceKey: unique symbol;
|
|
3
|
+
type ServiceDependency<T> = new (services: Services) => T & {
|
|
4
|
+
[destroy]?: () => Promise<void> | void;
|
|
5
|
+
};
|
|
6
|
+
declare class Services {
|
|
7
|
+
[instanceKey]: Map<ServiceDependency<unknown>, unknown>;
|
|
8
|
+
constructor();
|
|
9
|
+
get: <T>(service: ServiceDependency<T>) => T;
|
|
10
|
+
set: <T>(service: ServiceDependency<T>, instance: Partial<T>) => void;
|
|
11
|
+
destroy: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export { Services, destroy };
|
|
14
|
+
//# sourceMappingURL=utils.services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.services.d.ts","sourceRoot":"","sources":["../../src/utils/utils.services.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,eAAoB,CAAC;AAClC,QAAA,MAAM,WAAW,eAAsB,CAAC;AAExC,KAAK,iBAAiB,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,QAAQ,KAAK,CAAC,GAAG;IAC1D,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,cAAM,QAAQ;IACZ,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;;IAMjD,GAAG,GAAI,CAAC,EAAE,SAAS,iBAAiB,CAAC,CAAC,CAAC,KAQzB,CAAC,CACpB;IAEK,GAAG,GAAI,CAAC,EAAE,SAAS,iBAAiB,CAAC,CAAC,CAAC,EAAE,UAAU,OAAO,CAAC,CAAC,CAAC,UAElE;IAEK,OAAO,sBAaZ;CACH;AAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const destroy = Symbol('destroy');
|
|
2
|
+
const instanceKey = Symbol('instances');
|
|
3
|
+
class Services {
|
|
4
|
+
[instanceKey];
|
|
5
|
+
constructor() {
|
|
6
|
+
this[instanceKey] = new Map();
|
|
7
|
+
}
|
|
8
|
+
get = (service) => {
|
|
9
|
+
if (!this[instanceKey].has(service)) {
|
|
10
|
+
this[instanceKey].set(service, new service(this));
|
|
11
|
+
}
|
|
12
|
+
const instance = this[instanceKey].get(service);
|
|
13
|
+
if (!instance) {
|
|
14
|
+
throw new Error('Could not generate instance');
|
|
15
|
+
}
|
|
16
|
+
return instance;
|
|
17
|
+
};
|
|
18
|
+
set = (service, instance) => {
|
|
19
|
+
this[instanceKey].set(service, instance);
|
|
20
|
+
};
|
|
21
|
+
destroy = async () => {
|
|
22
|
+
await Promise.all(Array.from(this[instanceKey].values()).map(async (instance) => {
|
|
23
|
+
if (typeof instance === 'object' &&
|
|
24
|
+
instance &&
|
|
25
|
+
destroy in instance &&
|
|
26
|
+
typeof instance[destroy] === 'function') {
|
|
27
|
+
await instance[destroy]();
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export { Services, destroy };
|
|
33
|
+
//# sourceMappingURL=utils.services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.services.js","sourceRoot":"","sources":["../../src/utils/utils.services.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAClC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAMxC,MAAM,QAAQ;IACZ,CAAC,WAAW,CAAC,CAA2C;IAExD;QACE,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;IAChC,CAAC;IAEM,GAAG,GAAG,CAAI,OAA6B,EAAE,EAAE;QAChD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,QAAa,CAAC;IACvB,CAAC,CAAC;IAEK,GAAG,GAAG,CAAI,OAA6B,EAAE,QAAoB,EAAE,EAAE;QACtE,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEK,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAC5D,IACE,OAAO,QAAQ,KAAK,QAAQ;gBAC5B,QAAQ;gBACR,OAAO,IAAI,QAAQ;gBACnB,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,UAAU,EACvC,CAAC;gBACD,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;CACH;AAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"main": "dist/exports.js",
|
|
4
|
+
"repository": {
|
|
5
|
+
"url": "https://github.com/morten-olsen/ctxpkg"
|
|
6
|
+
},
|
|
4
7
|
"bin": {
|
|
5
8
|
"ctxpkg": "./bin/cli.js"
|
|
6
9
|
},
|
|
7
10
|
"files": [
|
|
8
|
-
"
|
|
11
|
+
"dist",
|
|
9
12
|
"bin"
|
|
10
13
|
],
|
|
11
14
|
"exports": {
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
"vitest": "4.0.17"
|
|
32
35
|
},
|
|
33
36
|
"name": "ctxpkg",
|
|
34
|
-
"version": "0.0.
|
|
37
|
+
"version": "0.0.4",
|
|
35
38
|
"license": "AGPL-3.0",
|
|
36
39
|
"imports": {
|
|
37
40
|
"#root/*": "./src/*"
|
package/src/agent/AGENTS.md
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
# Agent — Agent Guidelines
|
|
2
|
-
|
|
3
|
-
This document describes the agent module architecture for AI agents working on this codebase.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The agent module provides a LangChain-based agent that uses document tools to search and synthesize information. It's designed to reduce token/context costs by consolidating multiple tool calls into a single, synthesized answer.
|
|
8
|
-
|
|
9
|
-
## File Structure
|
|
10
|
-
|
|
11
|
-
| File | Purpose |
|
|
12
|
-
|------|---------|
|
|
13
|
-
| `agent.ts` | Main agent implementation, factory, and retry logic |
|
|
14
|
-
| `agent.types.ts` | TypeScript types and Zod schemas |
|
|
15
|
-
| `agent.prompts.ts` | System prompts and templates |
|
|
16
|
-
|
|
17
|
-
## Architecture
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
┌─────────────────────────────────────────────────────────────────────┐
|
|
21
|
-
│ DocumentAgent │
|
|
22
|
-
│ ┌───────────────────────────────────────────────────────────────┐ │
|
|
23
|
-
│ │ LangGraph React Agent │ │
|
|
24
|
-
│ │ │ │
|
|
25
|
-
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
|
|
26
|
-
│ │ │ search │ │ get_section │ │ get_document, etc. │ │ │
|
|
27
|
-
│ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │ │
|
|
28
|
-
│ │ │ │
|
|
29
|
-
│ │ Uses configured LLM (OpenAI-compatible API) │ │
|
|
30
|
-
│ └───────────────────────────────────────────────────────────────┘ │
|
|
31
|
-
│ │
|
|
32
|
-
│ Features: │
|
|
33
|
-
│ • Verbose mode with step callbacks │
|
|
34
|
-
│ • Conversation history for multi-turn chat │
|
|
35
|
-
│ • Collection filtering via system prompt │
|
|
36
|
-
│ • Retry logic with exponential backoff │
|
|
37
|
-
└─────────────────────────────────────────────────────────────────────┘
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Usage
|
|
41
|
-
|
|
42
|
-
### Creating an Agent
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { createDocumentAgent, getLLMConfigFromAppConfig } from '#root/agent/agent.ts';
|
|
46
|
-
import { createClient } from '#root/client/client.ts';
|
|
47
|
-
|
|
48
|
-
const client = await createClient({ mode: 'daemon' });
|
|
49
|
-
const llmConfig = await getLLMConfigFromAppConfig();
|
|
50
|
-
|
|
51
|
-
const agent = createDocumentAgent({
|
|
52
|
-
client,
|
|
53
|
-
llmConfig,
|
|
54
|
-
aliasMap: new Map([['docs', 'pkg:file://./docs/manifest.json']]),
|
|
55
|
-
collections: ['docs'], // Optional: restrict to specific collections
|
|
56
|
-
onStep: (step) => console.log(step), // Optional: verbose callbacks
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// One-shot query (stateless)
|
|
60
|
-
const response = await agent.ask(
|
|
61
|
-
'How do I implement streaming?',
|
|
62
|
-
'Building a chatbot that streams responses'
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
console.log(response.answer);
|
|
66
|
-
console.log(response.sources);
|
|
67
|
-
console.log(response.confidence);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Multi-turn Conversation
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
// First message
|
|
74
|
-
const response1 = await agent.chat(
|
|
75
|
-
'What authentication methods are available?',
|
|
76
|
-
'Building a secure API'
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// Follow-up (maintains conversation context)
|
|
80
|
-
const response2 = await agent.chat(
|
|
81
|
-
'How do I implement the OAuth2 option?',
|
|
82
|
-
'Building a secure API'
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// Clear history when starting new topic
|
|
86
|
-
agent.clearHistory();
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Verbose Mode
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
const agent = createDocumentAgent({
|
|
93
|
-
client,
|
|
94
|
-
llmConfig,
|
|
95
|
-
onStep: (step) => {
|
|
96
|
-
switch (step.type) {
|
|
97
|
-
case 'thinking':
|
|
98
|
-
console.log(`[thinking] ${step.content}`);
|
|
99
|
-
break;
|
|
100
|
-
case 'tool_call':
|
|
101
|
-
console.log(`[tool] ${step.toolName}`);
|
|
102
|
-
console.log(` Input: ${JSON.stringify(step.toolInput)}`);
|
|
103
|
-
break;
|
|
104
|
-
case 'tool_result':
|
|
105
|
-
console.log(`[result] ${step.content}`);
|
|
106
|
-
break;
|
|
107
|
-
case 'error':
|
|
108
|
-
console.log(`[retry] ${step.content}`);
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Agent Response Format
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
type AgentResponse = {
|
|
119
|
-
answer: string; // Synthesized answer
|
|
120
|
-
sources: Array<{ // References used
|
|
121
|
-
collection: string;
|
|
122
|
-
document: string;
|
|
123
|
-
section?: string;
|
|
124
|
-
}>;
|
|
125
|
-
confidence: 'high' | 'medium' | 'low';
|
|
126
|
-
note?: string; // Optional note
|
|
127
|
-
};
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## LLM Configuration
|
|
131
|
-
|
|
132
|
-
The agent uses configuration from `config.ts`:
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
llm: {
|
|
136
|
-
provider: string; // OpenAI-compatible API base URL
|
|
137
|
-
model: string; // Model identifier
|
|
138
|
-
apiKey: string; // API key
|
|
139
|
-
temperature: number; // 0-2
|
|
140
|
-
maxTokens: number; // Max response tokens
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
Configure via CLI:
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
ctxpkg config set llm.apiKey sk-...
|
|
148
|
-
ctxpkg config set llm.model gpt-4o
|
|
149
|
-
ctxpkg config set llm.provider https://api.openai.com/v1
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
Or via environment variables:
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
export CTXPKG_LLM_API_KEY=sk-...
|
|
156
|
-
export CTXPKG_LLM_MODEL=gpt-4o
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
## Agent Design
|
|
160
|
-
|
|
161
|
-
### Tool Selection
|
|
162
|
-
|
|
163
|
-
The agent uses LangGraph's React agent pattern with these tools:
|
|
164
|
-
|
|
165
|
-
- `documents_search` — Semantic search across collections
|
|
166
|
-
- `documents_list_documents` — Browse collection contents
|
|
167
|
-
- `documents_get_outline` — Get document structure
|
|
168
|
-
- `documents_get_section` — Get specific sections
|
|
169
|
-
- `documents_get_document` — Get full documents
|
|
170
|
-
- `documents_list_collections` — List available collections
|
|
171
|
-
- `documents_search_batch` — Batch searches
|
|
172
|
-
- `documents_find_related` — Find related content
|
|
173
|
-
|
|
174
|
-
### Termination
|
|
175
|
-
|
|
176
|
-
The agent stops when:
|
|
177
|
-
|
|
178
|
-
1. It has synthesized a complete answer (JSON response)
|
|
179
|
-
2. Maximum iterations reached (default: 15)
|
|
180
|
-
3. No more relevant information to find
|
|
181
|
-
|
|
182
|
-
### Response Parsing
|
|
183
|
-
|
|
184
|
-
The agent is prompted to respond in JSON format. The parser:
|
|
185
|
-
|
|
186
|
-
1. Looks for ```json code blocks
|
|
187
|
-
2. Tries to parse the whole content as JSON
|
|
188
|
-
3. Falls back to treating content as plain answer
|
|
189
|
-
|
|
190
|
-
### Retry Logic
|
|
191
|
-
|
|
192
|
-
The agent automatically retries on transient errors:
|
|
193
|
-
|
|
194
|
-
- **Rate limits**: 429 errors
|
|
195
|
-
- **Server errors**: 500, 502, 503, 504
|
|
196
|
-
- **Network errors**: ECONNRESET, ETIMEDOUT
|
|
197
|
-
|
|
198
|
-
Retry configuration:
|
|
199
|
-
- Max retries: 3
|
|
200
|
-
- Initial delay: 1000ms
|
|
201
|
-
- Max delay: 30000ms
|
|
202
|
-
- Backoff multiplier: 2x
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
import { withRetry, isRetryableError } from '#root/agent/agent.ts';
|
|
206
|
-
|
|
207
|
-
// Use retry logic for custom async operations
|
|
208
|
-
const result = await withRetry(
|
|
209
|
-
() => someAsyncOperation(),
|
|
210
|
-
{ maxRetries: 3, initialDelayMs: 1000, maxDelayMs: 30000, backoffMultiplier: 2 },
|
|
211
|
-
(attempt, error, delayMs) => console.log(`Retry ${attempt}: ${error.message}`)
|
|
212
|
-
);
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
## Key Patterns
|
|
216
|
-
|
|
217
|
-
### Lazy Config Loading
|
|
218
|
-
|
|
219
|
-
Config is loaded dynamically to avoid circular imports:
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
const getLLMConfigFromAppConfig = async (): Promise<LLMConfig> => {
|
|
223
|
-
const { config } = await import('#root/config/config.ts');
|
|
224
|
-
// ...
|
|
225
|
-
};
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
### Tool Conversion
|
|
229
|
-
|
|
230
|
-
Document tools are defined once and converted for LangChain:
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
const toolDefinitions = createDocumentToolDefinitions({ client, aliasMap });
|
|
234
|
-
const langchainTools = toLangchainTools(toolDefinitions);
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
### Collection Filtering
|
|
238
|
-
|
|
239
|
-
Collections can be restricted via the `collections` option:
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
const agent = createDocumentAgent({
|
|
243
|
-
client,
|
|
244
|
-
llmConfig,
|
|
245
|
-
collections: ['my-docs', 'api-docs'], // Only search these
|
|
246
|
-
});
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
This adds instructions to the system prompt telling the agent to pass these collections in all search calls.
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validation modes for test assertions
|
|
5
|
-
*/
|
|
6
|
-
export const validationModeSchema = z.enum(['semantic', 'llm', 'keywords']);
|
|
7
|
-
export type ValidationMode = z.infer<typeof validationModeSchema>;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Individual test case
|
|
11
|
-
*/
|
|
12
|
-
export const testCaseSchema = z.object({
|
|
13
|
-
/** Unique identifier for the test */
|
|
14
|
-
id: z.string(),
|
|
15
|
-
|
|
16
|
-
/** The question to ask the agent */
|
|
17
|
-
query: z.string(),
|
|
18
|
-
|
|
19
|
-
/** Use case context for the question */
|
|
20
|
-
useCase: z.string(),
|
|
21
|
-
|
|
22
|
-
/** Expected answer description or reference answer */
|
|
23
|
-
expected: z.string(),
|
|
24
|
-
|
|
25
|
-
/** Keywords that should appear in the answer (for keywords mode) */
|
|
26
|
-
keywords: z.array(z.string()).optional(),
|
|
27
|
-
|
|
28
|
-
/** Override validation mode for this specific test */
|
|
29
|
-
validationMode: validationModeSchema.optional(),
|
|
30
|
-
|
|
31
|
-
/** Custom validation instructions for LLM mode */
|
|
32
|
-
validationInstructions: z.string().optional(),
|
|
33
|
-
|
|
34
|
-
/** Override pass threshold for this specific test (0-1) */
|
|
35
|
-
passThreshold: z.number().min(0).max(1).optional(),
|
|
36
|
-
|
|
37
|
-
/** Whether this test is currently skipped */
|
|
38
|
-
skip: z.boolean().optional(),
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export type TestCase = z.infer<typeof testCaseSchema>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Collection specification (same as context.json format)
|
|
45
|
-
*/
|
|
46
|
-
export const collectionSpecSchema = z.object({
|
|
47
|
-
url: z.string(),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
export type CollectionSpec = z.infer<typeof collectionSpecSchema>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Test suite options
|
|
54
|
-
*/
|
|
55
|
-
export const testOptionsSchema = z.object({
|
|
56
|
-
/** Default validation mode (default: semantic) */
|
|
57
|
-
validationMode: validationModeSchema.optional().default('semantic'),
|
|
58
|
-
|
|
59
|
-
/** Pass threshold for semantic similarity (0-1, default: 0.75) */
|
|
60
|
-
passThreshold: z.number().min(0).max(1).optional().default(0.75),
|
|
61
|
-
|
|
62
|
-
/** Default validation instructions for LLM mode */
|
|
63
|
-
validationInstructions: z.string().optional(),
|
|
64
|
-
|
|
65
|
-
/** Maximum time per test in milliseconds (default: 60000) */
|
|
66
|
-
timeoutMs: z.number().optional().default(60000),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
export type TestOptions = z.infer<typeof testOptionsSchema>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Complete test suite file structure
|
|
73
|
-
*/
|
|
74
|
-
export const testSuiteSchema = z.object({
|
|
75
|
-
/** Name of the test suite */
|
|
76
|
-
name: z.string(),
|
|
77
|
-
|
|
78
|
-
/** Description of what this test suite covers */
|
|
79
|
-
description: z.string().optional(),
|
|
80
|
-
|
|
81
|
-
/** Collections to sync before running tests */
|
|
82
|
-
collections: z.record(z.string(), collectionSpecSchema),
|
|
83
|
-
|
|
84
|
-
/** Test suite options */
|
|
85
|
-
options: testOptionsSchema.optional(),
|
|
86
|
-
|
|
87
|
-
/** Test cases */
|
|
88
|
-
tests: z.array(testCaseSchema).min(1),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export type TestSuite = z.infer<typeof testSuiteSchema>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Result of a single test case
|
|
95
|
-
*/
|
|
96
|
-
export const testResultSchema = z.object({
|
|
97
|
-
/** Test case ID */
|
|
98
|
-
id: z.string(),
|
|
99
|
-
|
|
100
|
-
/** Whether the test passed */
|
|
101
|
-
passed: z.boolean(),
|
|
102
|
-
|
|
103
|
-
/** Score (0-1) for semantic/llm validation */
|
|
104
|
-
score: z.number().optional(),
|
|
105
|
-
|
|
106
|
-
/** The agent's actual answer */
|
|
107
|
-
actualAnswer: z.string(),
|
|
108
|
-
|
|
109
|
-
/** Validation reasoning (from LLM mode) or match details */
|
|
110
|
-
reasoning: z.string().optional(),
|
|
111
|
-
|
|
112
|
-
/** Keywords found (for keywords mode) */
|
|
113
|
-
keywordsFound: z.array(z.string()).optional(),
|
|
114
|
-
|
|
115
|
-
/** Keywords missing (for keywords mode) */
|
|
116
|
-
keywordsMissing: z.array(z.string()).optional(),
|
|
117
|
-
|
|
118
|
-
/** Time taken in milliseconds */
|
|
119
|
-
durationMs: z.number(),
|
|
120
|
-
|
|
121
|
-
/** Error message if the test failed to run */
|
|
122
|
-
error: z.string().optional(),
|
|
123
|
-
|
|
124
|
-
/** Whether the test was skipped */
|
|
125
|
-
skipped: z.boolean().optional(),
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
export type TestResult = z.infer<typeof testResultSchema>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Complete test run results
|
|
132
|
-
*/
|
|
133
|
-
export const testRunResultSchema = z.object({
|
|
134
|
-
/** Test suite name */
|
|
135
|
-
suiteName: z.string(),
|
|
136
|
-
|
|
137
|
-
/** When the test run started */
|
|
138
|
-
startedAt: z.string(),
|
|
139
|
-
|
|
140
|
-
/** When the test run completed */
|
|
141
|
-
completedAt: z.string(),
|
|
142
|
-
|
|
143
|
-
/** Total duration in milliseconds */
|
|
144
|
-
durationMs: z.number(),
|
|
145
|
-
|
|
146
|
-
/** Summary statistics */
|
|
147
|
-
summary: z.object({
|
|
148
|
-
total: z.number(),
|
|
149
|
-
passed: z.number(),
|
|
150
|
-
failed: z.number(),
|
|
151
|
-
skipped: z.number(),
|
|
152
|
-
}),
|
|
153
|
-
|
|
154
|
-
/** Individual test results */
|
|
155
|
-
results: z.array(testResultSchema),
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
export type TestRunResult = z.infer<typeof testRunResultSchema>;
|