@lssm/lib.ai-agent 1.41.0 → 1.42.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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/agent/agent-factory.d.ts +104 -0
- package/dist/agent/agent-factory.d.ts.map +1 -0
- package/dist/agent/agent-factory.js +103 -1
- package/dist/agent/agent-factory.js.map +1 -0
- package/dist/agent/contract-spec-agent.d.ts +75 -0
- package/dist/agent/contract-spec-agent.d.ts.map +1 -0
- package/dist/agent/contract-spec-agent.js +148 -1
- package/dist/agent/contract-spec-agent.js.map +1 -0
- package/dist/agent/index.d.ts +3 -0
- package/dist/agent/index.js +4 -1
- package/dist/approval/index.d.ts +2 -0
- package/dist/approval/index.js +3 -1
- package/dist/approval/workflow.d.ts +156 -0
- package/dist/approval/workflow.d.ts.map +1 -0
- package/dist/approval/workflow.js +160 -1
- package/dist/approval/workflow.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +21 -1
- package/dist/knowledge/index.d.ts +2 -0
- package/dist/knowledge/index.js +3 -1
- package/dist/knowledge/injector.d.ts +38 -0
- package/dist/knowledge/injector.d.ts.map +1 -0
- package/dist/knowledge/injector.js +50 -5
- package/dist/knowledge/injector.js.map +1 -0
- package/dist/memory/in-memory.d.ts +22 -0
- package/dist/memory/in-memory.d.ts.map +1 -0
- package/dist/memory/in-memory.js +48 -2
- package/dist/memory/in-memory.js.map +1 -0
- package/dist/memory/index.d.ts +3 -0
- package/dist/memory/index.js +4 -1
- package/dist/memory/manager.d.ts +42 -0
- package/dist/memory/manager.d.ts.map +1 -0
- package/dist/memory/manager.js +80 -1
- package/dist/memory/manager.js.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.js +4 -1
- package/dist/schema/json-schema-to-zod.d.ts +55 -0
- package/dist/schema/json-schema-to-zod.d.ts.map +1 -0
- package/dist/schema/json-schema-to-zod.js +124 -1
- package/dist/schema/json-schema-to-zod.js.map +1 -0
- package/dist/schema/schema-output.d.ts +77 -0
- package/dist/schema/schema-output.d.ts.map +1 -0
- package/dist/schema/schema-output.js +65 -1
- package/dist/schema/schema-output.js.map +1 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +3 -1
- package/dist/session/store.d.ts +74 -0
- package/dist/session/store.d.ts.map +1 -0
- package/dist/session/store.js +79 -1
- package/dist/session/store.js.map +1 -0
- package/dist/spec/index.d.ts +3 -0
- package/dist/spec/index.js +4 -1
- package/dist/spec/registry.d.ts +78 -0
- package/dist/spec/registry.d.ts.map +1 -0
- package/dist/spec/registry.js +117 -1
- package/dist/spec/registry.js.map +1 -0
- package/dist/spec/spec.d.ts +127 -0
- package/dist/spec/spec.d.ts.map +1 -0
- package/dist/spec/spec.js +30 -1
- package/dist/spec/spec.js.map +1 -0
- package/dist/telemetry/adapter.d.ts +73 -0
- package/dist/telemetry/adapter.d.ts.map +1 -0
- package/dist/telemetry/adapter.js +103 -1
- package/dist/telemetry/adapter.js.map +1 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +3 -1
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.js +6 -1
- package/dist/tools/knowledge-tool.d.ts +21 -0
- package/dist/tools/knowledge-tool.d.ts.map +1 -0
- package/dist/tools/knowledge-tool.js +51 -6
- package/dist/tools/knowledge-tool.js.map +1 -0
- package/dist/tools/mcp-client.d.ts +59 -0
- package/dist/tools/mcp-client.d.ts.map +1 -0
- package/dist/tools/mcp-client.js +58 -1
- package/dist/tools/mcp-client.js.map +1 -0
- package/dist/tools/mcp-server.d.ts +46 -0
- package/dist/tools/mcp-server.d.ts.map +1 -0
- package/dist/tools/mcp-server.js +69 -1
- package/dist/tools/mcp-server.js.map +1 -0
- package/dist/tools/tool-adapter.d.ts +50 -0
- package/dist/tools/tool-adapter.d.ts.map +1 -0
- package/dist/tools/tool-adapter.js +80 -1
- package/dist/tools/tool-adapter.js.map +1 -0
- package/dist/types.d.ts +146 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +49 -40
package/dist/session/store.js
CHANGED
|
@@ -1 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/session/store.ts
|
|
2
|
+
/**
|
|
3
|
+
* In-memory session store for development and testing.
|
|
4
|
+
*/
|
|
5
|
+
var InMemorySessionStore = class {
|
|
6
|
+
sessions = /* @__PURE__ */ new Map();
|
|
7
|
+
async get(sessionId) {
|
|
8
|
+
return this.sessions.get(sessionId) ?? null;
|
|
9
|
+
}
|
|
10
|
+
async create(session) {
|
|
11
|
+
const now = /* @__PURE__ */ new Date();
|
|
12
|
+
const fullSession = {
|
|
13
|
+
...session,
|
|
14
|
+
createdAt: now,
|
|
15
|
+
updatedAt: now
|
|
16
|
+
};
|
|
17
|
+
this.sessions.set(session.sessionId, fullSession);
|
|
18
|
+
return fullSession;
|
|
19
|
+
}
|
|
20
|
+
async appendStep(sessionId, step) {
|
|
21
|
+
const session = this.sessions.get(sessionId);
|
|
22
|
+
if (session) {
|
|
23
|
+
session.steps.push(step);
|
|
24
|
+
session.updatedAt = /* @__PURE__ */ new Date();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async appendMessage(sessionId, message) {
|
|
28
|
+
const session = this.sessions.get(sessionId);
|
|
29
|
+
if (session) {
|
|
30
|
+
session.messages.push(message);
|
|
31
|
+
session.updatedAt = /* @__PURE__ */ new Date();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async update(sessionId, updates) {
|
|
35
|
+
const session = this.sessions.get(sessionId);
|
|
36
|
+
if (session) Object.assign(session, updates, { updatedAt: /* @__PURE__ */ new Date() });
|
|
37
|
+
}
|
|
38
|
+
async delete(sessionId) {
|
|
39
|
+
return this.sessions.delete(sessionId);
|
|
40
|
+
}
|
|
41
|
+
async listByAgent(agentId, limit = 100) {
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const session of this.sessions.values()) if (session.agentId === agentId) {
|
|
44
|
+
results.push(session);
|
|
45
|
+
if (results.length >= limit) break;
|
|
46
|
+
}
|
|
47
|
+
return results.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
48
|
+
}
|
|
49
|
+
async listByTenant(tenantId, limit = 100) {
|
|
50
|
+
const results = [];
|
|
51
|
+
for (const session of this.sessions.values()) if (session.tenantId === tenantId) {
|
|
52
|
+
results.push(session);
|
|
53
|
+
if (results.length >= limit) break;
|
|
54
|
+
}
|
|
55
|
+
return results.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clear all sessions (for testing).
|
|
59
|
+
*/
|
|
60
|
+
clear() {
|
|
61
|
+
this.sessions.clear();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Create an in-memory session store.
|
|
66
|
+
*/
|
|
67
|
+
function createInMemorySessionStore() {
|
|
68
|
+
return new InMemorySessionStore();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate a unique session ID.
|
|
72
|
+
*/
|
|
73
|
+
function generateSessionId() {
|
|
74
|
+
return `sess_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { InMemorySessionStore, createInMemorySessionStore, generateSessionId };
|
|
79
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","names":["fullSession: AgentSessionState","results: AgentSessionState[]"],"sources":["../../src/session/store.ts"],"sourcesContent":["import type { ModelMessage, StepResult, ToolSet } from 'ai';\nimport type { AgentSessionState } from '../types';\n\n/**\n * Interface for persisting agent session state.\n *\n * Implementations can use in-memory storage, databases,\n * or external services like Redis.\n */\nexport interface AgentSessionStore {\n /**\n * Get a session by ID.\n */\n get(sessionId: string): Promise<AgentSessionState | null>;\n\n /**\n * Create a new session.\n */\n create(\n session: Omit<AgentSessionState, 'createdAt' | 'updatedAt'>\n ): Promise<AgentSessionState>;\n\n /**\n * Append a step to a session.\n */\n appendStep(sessionId: string, step: StepResult<ToolSet>): Promise<void>;\n\n /**\n * Append a message to a session.\n */\n appendMessage(sessionId: string, message: ModelMessage): Promise<void>;\n\n /**\n * Update session properties.\n */\n update(\n sessionId: string,\n updates: Partial<Pick<AgentSessionState, 'status' | 'metadata'>>\n ): Promise<void>;\n\n /**\n * Delete a session.\n */\n delete(sessionId: string): Promise<boolean>;\n\n /**\n * List sessions by agent ID.\n */\n listByAgent(agentId: string, limit?: number): Promise<AgentSessionState[]>;\n\n /**\n * List sessions by tenant ID.\n */\n listByTenant(tenantId: string, limit?: number): Promise<AgentSessionState[]>;\n}\n\n/**\n * In-memory session store for development and testing.\n */\nexport class InMemorySessionStore implements AgentSessionStore {\n private readonly sessions = new Map<string, AgentSessionState>();\n\n async get(sessionId: string): Promise<AgentSessionState | null> {\n return this.sessions.get(sessionId) ?? null;\n }\n\n async create(\n session: Omit<AgentSessionState, 'createdAt' | 'updatedAt'>\n ): Promise<AgentSessionState> {\n const now = new Date();\n const fullSession: AgentSessionState = {\n ...session,\n createdAt: now,\n updatedAt: now,\n };\n this.sessions.set(session.sessionId, fullSession);\n return fullSession;\n }\n\n async appendStep(\n sessionId: string,\n step: StepResult<ToolSet>\n ): Promise<void> {\n const session = this.sessions.get(sessionId);\n if (session) {\n session.steps.push(step);\n session.updatedAt = new Date();\n }\n }\n\n async appendMessage(sessionId: string, message: ModelMessage): Promise<void> {\n const session = this.sessions.get(sessionId);\n if (session) {\n session.messages.push(message);\n session.updatedAt = new Date();\n }\n }\n\n async update(\n sessionId: string,\n updates: Partial<Pick<AgentSessionState, 'status' | 'metadata'>>\n ): Promise<void> {\n const session = this.sessions.get(sessionId);\n if (session) {\n Object.assign(session, updates, { updatedAt: new Date() });\n }\n }\n\n async delete(sessionId: string): Promise<boolean> {\n return this.sessions.delete(sessionId);\n }\n\n async listByAgent(\n agentId: string,\n limit = 100\n ): Promise<AgentSessionState[]> {\n const results: AgentSessionState[] = [];\n for (const session of this.sessions.values()) {\n if (session.agentId === agentId) {\n results.push(session);\n if (results.length >= limit) break;\n }\n }\n return results.sort(\n (a, b) => b.updatedAt.getTime() - a.updatedAt.getTime()\n );\n }\n\n async listByTenant(\n tenantId: string,\n limit = 100\n ): Promise<AgentSessionState[]> {\n const results: AgentSessionState[] = [];\n for (const session of this.sessions.values()) {\n if (session.tenantId === tenantId) {\n results.push(session);\n if (results.length >= limit) break;\n }\n }\n return results.sort(\n (a, b) => b.updatedAt.getTime() - a.updatedAt.getTime()\n );\n }\n\n /**\n * Clear all sessions (for testing).\n */\n clear(): void {\n this.sessions.clear();\n }\n}\n\n/**\n * Create an in-memory session store.\n */\nexport function createInMemorySessionStore(): AgentSessionStore {\n return new InMemorySessionStore();\n}\n\n/**\n * Generate a unique session ID.\n */\nexport function generateSessionId(): string {\n return `sess_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n}\n"],"mappings":";;;;AA2DA,IAAa,uBAAb,MAA+D;CAC7D,AAAiB,2BAAW,IAAI,KAAgC;CAEhE,MAAM,IAAI,WAAsD;AAC9D,SAAO,KAAK,SAAS,IAAI,UAAU,IAAI;;CAGzC,MAAM,OACJ,SAC4B;EAC5B,MAAM,sBAAM,IAAI,MAAM;EACtB,MAAMA,cAAiC;GACrC,GAAG;GACH,WAAW;GACX,WAAW;GACZ;AACD,OAAK,SAAS,IAAI,QAAQ,WAAW,YAAY;AACjD,SAAO;;CAGT,MAAM,WACJ,WACA,MACe;EACf,MAAM,UAAU,KAAK,SAAS,IAAI,UAAU;AAC5C,MAAI,SAAS;AACX,WAAQ,MAAM,KAAK,KAAK;AACxB,WAAQ,4BAAY,IAAI,MAAM;;;CAIlC,MAAM,cAAc,WAAmB,SAAsC;EAC3E,MAAM,UAAU,KAAK,SAAS,IAAI,UAAU;AAC5C,MAAI,SAAS;AACX,WAAQ,SAAS,KAAK,QAAQ;AAC9B,WAAQ,4BAAY,IAAI,MAAM;;;CAIlC,MAAM,OACJ,WACA,SACe;EACf,MAAM,UAAU,KAAK,SAAS,IAAI,UAAU;AAC5C,MAAI,QACF,QAAO,OAAO,SAAS,SAAS,EAAE,2BAAW,IAAI,MAAM,EAAE,CAAC;;CAI9D,MAAM,OAAO,WAAqC;AAChD,SAAO,KAAK,SAAS,OAAO,UAAU;;CAGxC,MAAM,YACJ,SACA,QAAQ,KACsB;EAC9B,MAAMC,UAA+B,EAAE;AACvC,OAAK,MAAM,WAAW,KAAK,SAAS,QAAQ,CAC1C,KAAI,QAAQ,YAAY,SAAS;AAC/B,WAAQ,KAAK,QAAQ;AACrB,OAAI,QAAQ,UAAU,MAAO;;AAGjC,SAAO,QAAQ,MACZ,GAAG,MAAM,EAAE,UAAU,SAAS,GAAG,EAAE,UAAU,SAAS,CACxD;;CAGH,MAAM,aACJ,UACA,QAAQ,KACsB;EAC9B,MAAMA,UAA+B,EAAE;AACvC,OAAK,MAAM,WAAW,KAAK,SAAS,QAAQ,CAC1C,KAAI,QAAQ,aAAa,UAAU;AACjC,WAAQ,KAAK,QAAQ;AACrB,OAAI,QAAQ,UAAU,MAAO;;AAGjC,SAAO,QAAQ,MACZ,GAAG,MAAM,EAAE,UAAU,SAAS,GAAG,EAAE,UAAU,SAAS,CACxD;;;;;CAMH,QAAc;AACZ,OAAK,SAAS,OAAO;;;;;;AAOzB,SAAgB,6BAAgD;AAC9D,QAAO,IAAI,sBAAsB;;;;;AAMnC,SAAgB,oBAA4B;AAC1C,QAAO,QAAQ,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,GAAG,GAAG"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AgentConfidencePolicy, AgentEscalationPolicy, AgentKnowledgeRef, AgentMemoryConfig, AgentMeta, AgentPolicy, AgentSpec, AgentToolConfig, agentKey, defineAgent } from "./spec.js";
|
|
2
|
+
import { AgentRegistry, createAgentRegistry } from "./registry.js";
|
|
3
|
+
export { AgentConfidencePolicy, AgentEscalationPolicy, AgentKnowledgeRef, AgentMemoryConfig, AgentMeta, AgentPolicy, AgentRegistry, AgentSpec, AgentToolConfig, agentKey, createAgentRegistry, defineAgent };
|
package/dist/spec/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import{agentKey
|
|
1
|
+
import { agentKey, defineAgent } from "./spec.js";
|
|
2
|
+
import { AgentRegistry, createAgentRegistry } from "./registry.js";
|
|
3
|
+
|
|
4
|
+
export { AgentRegistry, agentKey, createAgentRegistry, defineAgent };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AgentSpec } from "./spec.js";
|
|
2
|
+
|
|
3
|
+
//#region src/spec/registry.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Registry for managing agent specifications.
|
|
7
|
+
*
|
|
8
|
+
* Provides registration, lookup, and version management for agent specs.
|
|
9
|
+
*/
|
|
10
|
+
declare class AgentRegistry {
|
|
11
|
+
private readonly specs;
|
|
12
|
+
/**
|
|
13
|
+
* Register an agent specification.
|
|
14
|
+
*
|
|
15
|
+
* @param spec - The agent specification to register
|
|
16
|
+
* @returns This registry for chaining
|
|
17
|
+
* @throws Error if the spec is already registered
|
|
18
|
+
*/
|
|
19
|
+
register(spec: AgentSpec): this;
|
|
20
|
+
/**
|
|
21
|
+
* Unregister an agent specification.
|
|
22
|
+
*
|
|
23
|
+
* @param name - Agent name
|
|
24
|
+
* @param version - Agent version
|
|
25
|
+
* @returns True if the spec was removed
|
|
26
|
+
*/
|
|
27
|
+
unregister(name: string, version: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* List all registered agent specifications.
|
|
30
|
+
*/
|
|
31
|
+
list(): AgentSpec[];
|
|
32
|
+
/**
|
|
33
|
+
* List all unique agent names (without versions).
|
|
34
|
+
*/
|
|
35
|
+
listNames(): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Get an agent specification by name and optional version.
|
|
38
|
+
*
|
|
39
|
+
* @param name - Agent name
|
|
40
|
+
* @param version - Optional version. If omitted, returns the latest version.
|
|
41
|
+
* @returns The agent spec or undefined if not found
|
|
42
|
+
*/
|
|
43
|
+
get(name: string, version?: number): AgentSpec | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Get an agent specification or throw if not found.
|
|
46
|
+
*
|
|
47
|
+
* @param name - Agent name
|
|
48
|
+
* @param version - Optional version
|
|
49
|
+
* @returns The agent spec
|
|
50
|
+
* @throws Error if the spec is not found
|
|
51
|
+
*/
|
|
52
|
+
require(name: string, version?: number): AgentSpec;
|
|
53
|
+
/**
|
|
54
|
+
* Check if an agent is registered.
|
|
55
|
+
*
|
|
56
|
+
* @param name - Agent name
|
|
57
|
+
* @param version - Optional version
|
|
58
|
+
*/
|
|
59
|
+
has(name: string, version?: number): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get all versions of an agent.
|
|
62
|
+
*
|
|
63
|
+
* @param name - Agent name
|
|
64
|
+
* @returns Array of specs sorted by version (ascending)
|
|
65
|
+
*/
|
|
66
|
+
getVersions(name: string): AgentSpec[];
|
|
67
|
+
/**
|
|
68
|
+
* Clear all registered specs.
|
|
69
|
+
*/
|
|
70
|
+
clear(): void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new agent registry.
|
|
74
|
+
*/
|
|
75
|
+
declare function createAgentRegistry(): AgentRegistry;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { AgentRegistry, createAgentRegistry };
|
|
78
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","names":[],"sources":["../../src/spec/registry.ts"],"sourcesContent":[],"mappings":";;;;;;AAQA;;;AAuDuC,cAvD1B,aAAA,CAuD0B;EA0BI,iBAAA,KAAA;EA0Bd;;AAqB7B;;;;;iBAtHiB;;;;;;;;;;;;UAuBP;;;;;;;;;;;;uCAsB6B;;;;;;;;;2CA0BI;;;;;;;;;;;;;;6BA0Bd;;;;;;;;;iBAqBb,mBAAA,CAAA,GAAuB"}
|
package/dist/spec/registry.js
CHANGED
|
@@ -1 +1,117 @@
|
|
|
1
|
-
import{agentKey
|
|
1
|
+
import { agentKey } from "./spec.js";
|
|
2
|
+
|
|
3
|
+
//#region src/spec/registry.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registry for managing agent specifications.
|
|
6
|
+
*
|
|
7
|
+
* Provides registration, lookup, and version management for agent specs.
|
|
8
|
+
*/
|
|
9
|
+
var AgentRegistry = class {
|
|
10
|
+
specs = /* @__PURE__ */ new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Register an agent specification.
|
|
13
|
+
*
|
|
14
|
+
* @param spec - The agent specification to register
|
|
15
|
+
* @returns This registry for chaining
|
|
16
|
+
* @throws Error if the spec is already registered
|
|
17
|
+
*/
|
|
18
|
+
register(spec) {
|
|
19
|
+
const key = agentKey(spec.meta);
|
|
20
|
+
if (this.specs.has(key)) throw new Error(`Duplicate agent spec registered for ${key}`);
|
|
21
|
+
this.specs.set(key, spec);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unregister an agent specification.
|
|
26
|
+
*
|
|
27
|
+
* @param name - Agent name
|
|
28
|
+
* @param version - Agent version
|
|
29
|
+
* @returns True if the spec was removed
|
|
30
|
+
*/
|
|
31
|
+
unregister(name, version) {
|
|
32
|
+
return this.specs.delete(`${name}.v${version}`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* List all registered agent specifications.
|
|
36
|
+
*/
|
|
37
|
+
list() {
|
|
38
|
+
return [...this.specs.values()];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* List all unique agent names (without versions).
|
|
42
|
+
*/
|
|
43
|
+
listNames() {
|
|
44
|
+
const names = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const spec of this.specs.values()) names.add(spec.meta.key);
|
|
46
|
+
return [...names];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get an agent specification by name and optional version.
|
|
50
|
+
*
|
|
51
|
+
* @param name - Agent name
|
|
52
|
+
* @param version - Optional version. If omitted, returns the latest version.
|
|
53
|
+
* @returns The agent spec or undefined if not found
|
|
54
|
+
*/
|
|
55
|
+
get(name, version) {
|
|
56
|
+
if (version != null) return this.specs.get(`${name}.v${version}`);
|
|
57
|
+
let latest;
|
|
58
|
+
let maxVersion = -Infinity;
|
|
59
|
+
for (const spec of this.specs.values()) {
|
|
60
|
+
if (spec.meta.key !== name) continue;
|
|
61
|
+
if (spec.meta.version > maxVersion) {
|
|
62
|
+
latest = spec;
|
|
63
|
+
maxVersion = spec.meta.version;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return latest;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get an agent specification or throw if not found.
|
|
70
|
+
*
|
|
71
|
+
* @param name - Agent name
|
|
72
|
+
* @param version - Optional version
|
|
73
|
+
* @returns The agent spec
|
|
74
|
+
* @throws Error if the spec is not found
|
|
75
|
+
*/
|
|
76
|
+
require(name, version) {
|
|
77
|
+
const spec = this.get(name, version);
|
|
78
|
+
if (!spec) throw new Error(`Agent spec not found for ${name}${version != null ? `.v${version}` : ""}`);
|
|
79
|
+
return spec;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if an agent is registered.
|
|
83
|
+
*
|
|
84
|
+
* @param name - Agent name
|
|
85
|
+
* @param version - Optional version
|
|
86
|
+
*/
|
|
87
|
+
has(name, version) {
|
|
88
|
+
return this.get(name, version) !== void 0;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get all versions of an agent.
|
|
92
|
+
*
|
|
93
|
+
* @param name - Agent name
|
|
94
|
+
* @returns Array of specs sorted by version (ascending)
|
|
95
|
+
*/
|
|
96
|
+
getVersions(name) {
|
|
97
|
+
const versions = [];
|
|
98
|
+
for (const spec of this.specs.values()) if (spec.meta.key === name) versions.push(spec);
|
|
99
|
+
return versions.sort((a, b) => a.meta.version - b.meta.version);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Clear all registered specs.
|
|
103
|
+
*/
|
|
104
|
+
clear() {
|
|
105
|
+
this.specs.clear();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Create a new agent registry.
|
|
110
|
+
*/
|
|
111
|
+
function createAgentRegistry() {
|
|
112
|
+
return new AgentRegistry();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { AgentRegistry, createAgentRegistry };
|
|
117
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":["latest: AgentSpec | undefined","versions: AgentSpec[]"],"sources":["../../src/spec/registry.ts"],"sourcesContent":["import type { AgentSpec } from './spec';\nimport { agentKey } from './spec';\n\n/**\n * Registry for managing agent specifications.\n *\n * Provides registration, lookup, and version management for agent specs.\n */\nexport class AgentRegistry {\n private readonly specs = new Map<string, AgentSpec>();\n\n /**\n * Register an agent specification.\n *\n * @param spec - The agent specification to register\n * @returns This registry for chaining\n * @throws Error if the spec is already registered\n */\n register(spec: AgentSpec): this {\n const key = agentKey(spec.meta);\n if (this.specs.has(key)) {\n throw new Error(`Duplicate agent spec registered for ${key}`);\n }\n this.specs.set(key, spec);\n return this;\n }\n\n /**\n * Unregister an agent specification.\n *\n * @param name - Agent name\n * @param version - Agent version\n * @returns True if the spec was removed\n */\n unregister(name: string, version: number): boolean {\n return this.specs.delete(`${name}.v${version}`);\n }\n\n /**\n * List all registered agent specifications.\n */\n list(): AgentSpec[] {\n return [...this.specs.values()];\n }\n\n /**\n * List all unique agent names (without versions).\n */\n listNames(): string[] {\n const names = new Set<string>();\n for (const spec of this.specs.values()) {\n names.add(spec.meta.key);\n }\n return [...names];\n }\n\n /**\n * Get an agent specification by name and optional version.\n *\n * @param name - Agent name\n * @param version - Optional version. If omitted, returns the latest version.\n * @returns The agent spec or undefined if not found\n */\n get(name: string, version?: number): AgentSpec | undefined {\n if (version != null) {\n return this.specs.get(`${name}.v${version}`);\n }\n\n // Find latest version\n let latest: AgentSpec | undefined;\n let maxVersion = -Infinity;\n for (const spec of this.specs.values()) {\n if (spec.meta.key !== name) continue;\n if (spec.meta.version > maxVersion) {\n latest = spec;\n maxVersion = spec.meta.version;\n }\n }\n return latest;\n }\n\n /**\n * Get an agent specification or throw if not found.\n *\n * @param name - Agent name\n * @param version - Optional version\n * @returns The agent spec\n * @throws Error if the spec is not found\n */\n require(name: string, version?: number): AgentSpec {\n const spec = this.get(name, version);\n if (!spec) {\n throw new Error(\n `Agent spec not found for ${name}${version != null ? `.v${version}` : ''}`\n );\n }\n return spec;\n }\n\n /**\n * Check if an agent is registered.\n *\n * @param name - Agent name\n * @param version - Optional version\n */\n has(name: string, version?: number): boolean {\n return this.get(name, version) !== undefined;\n }\n\n /**\n * Get all versions of an agent.\n *\n * @param name - Agent name\n * @returns Array of specs sorted by version (ascending)\n */\n getVersions(name: string): AgentSpec[] {\n const versions: AgentSpec[] = [];\n for (const spec of this.specs.values()) {\n if (spec.meta.key === name) {\n versions.push(spec);\n }\n }\n return versions.sort((a, b) => a.meta.version - b.meta.version);\n }\n\n /**\n * Clear all registered specs.\n */\n clear(): void {\n this.specs.clear();\n }\n}\n\n/**\n * Create a new agent registry.\n */\nexport function createAgentRegistry(): AgentRegistry {\n return new AgentRegistry();\n}\n"],"mappings":";;;;;;;;AAQA,IAAa,gBAAb,MAA2B;CACzB,AAAiB,wBAAQ,IAAI,KAAwB;;;;;;;;CASrD,SAAS,MAAuB;EAC9B,MAAM,MAAM,SAAS,KAAK,KAAK;AAC/B,MAAI,KAAK,MAAM,IAAI,IAAI,CACrB,OAAM,IAAI,MAAM,uCAAuC,MAAM;AAE/D,OAAK,MAAM,IAAI,KAAK,KAAK;AACzB,SAAO;;;;;;;;;CAUT,WAAW,MAAc,SAA0B;AACjD,SAAO,KAAK,MAAM,OAAO,GAAG,KAAK,IAAI,UAAU;;;;;CAMjD,OAAoB;AAClB,SAAO,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC;;;;;CAMjC,YAAsB;EACpB,MAAM,wBAAQ,IAAI,KAAa;AAC/B,OAAK,MAAM,QAAQ,KAAK,MAAM,QAAQ,CACpC,OAAM,IAAI,KAAK,KAAK,IAAI;AAE1B,SAAO,CAAC,GAAG,MAAM;;;;;;;;;CAUnB,IAAI,MAAc,SAAyC;AACzD,MAAI,WAAW,KACb,QAAO,KAAK,MAAM,IAAI,GAAG,KAAK,IAAI,UAAU;EAI9C,IAAIA;EACJ,IAAI,aAAa;AACjB,OAAK,MAAM,QAAQ,KAAK,MAAM,QAAQ,EAAE;AACtC,OAAI,KAAK,KAAK,QAAQ,KAAM;AAC5B,OAAI,KAAK,KAAK,UAAU,YAAY;AAClC,aAAS;AACT,iBAAa,KAAK,KAAK;;;AAG3B,SAAO;;;;;;;;;;CAWT,QAAQ,MAAc,SAA6B;EACjD,MAAM,OAAO,KAAK,IAAI,MAAM,QAAQ;AACpC,MAAI,CAAC,KACH,OAAM,IAAI,MACR,4BAA4B,OAAO,WAAW,OAAO,KAAK,YAAY,KACvE;AAEH,SAAO;;;;;;;;CAST,IAAI,MAAc,SAA2B;AAC3C,SAAO,KAAK,IAAI,MAAM,QAAQ,KAAK;;;;;;;;CASrC,YAAY,MAA2B;EACrC,MAAMC,WAAwB,EAAE;AAChC,OAAK,MAAM,QAAQ,KAAK,MAAM,QAAQ,CACpC,KAAI,KAAK,KAAK,QAAQ,KACpB,UAAS,KAAK,KAAK;AAGvB,SAAO,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ;;;;;CAMjE,QAAc;AACZ,OAAK,MAAM,OAAO;;;;;;AAOtB,SAAgB,sBAAqC;AACnD,QAAO,IAAI,eAAe"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { OwnerShipMeta } from "@lssm/lib.contracts/ownership";
|
|
2
|
+
import { KnowledgeCategory } from "@lssm/lib.contracts/knowledge/spec";
|
|
3
|
+
import { PolicyRef } from "@lssm/lib.contracts/policy/spec";
|
|
4
|
+
|
|
5
|
+
//#region src/spec/spec.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Metadata for an agent specification.
|
|
9
|
+
*/
|
|
10
|
+
type AgentMeta = OwnerShipMeta;
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for a tool that an agent can use.
|
|
13
|
+
*/
|
|
14
|
+
interface AgentToolConfig {
|
|
15
|
+
/** Tool name (unique within the agent) */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Human-readable description for the LLM */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** JSON Schema fragment for tool parameters */
|
|
20
|
+
schema?: Record<string, unknown>;
|
|
21
|
+
/** Optional cooldown in milliseconds between invocations */
|
|
22
|
+
cooldownMs?: number;
|
|
23
|
+
/** Maximum execution time before timeout */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
/** Whether the tool can be executed without human approval (AI SDK needsApproval = !automationSafe) */
|
|
26
|
+
automationSafe?: boolean;
|
|
27
|
+
/** Explicit approval requirement (overrides automationSafe) */
|
|
28
|
+
requiresApproval?: boolean;
|
|
29
|
+
/** Optional policy guard that must evaluate to allow the tool call */
|
|
30
|
+
policy?: PolicyRef;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reference to a knowledge space that the agent can access.
|
|
34
|
+
*/
|
|
35
|
+
interface AgentKnowledgeRef {
|
|
36
|
+
/** Knowledge space key */
|
|
37
|
+
key: string;
|
|
38
|
+
/** Optional specific version */
|
|
39
|
+
version?: number;
|
|
40
|
+
/** Filter by knowledge category */
|
|
41
|
+
category?: KnowledgeCategory;
|
|
42
|
+
/** Whether the knowledge is required (static injection) or optional (dynamic RAG) */
|
|
43
|
+
required?: boolean;
|
|
44
|
+
/** Additional instructions appended when the space is available */
|
|
45
|
+
instructions?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Memory configuration for agent session persistence.
|
|
49
|
+
*/
|
|
50
|
+
interface AgentMemoryConfig {
|
|
51
|
+
/** Maximum entries to keep in memory */
|
|
52
|
+
maxEntries?: number;
|
|
53
|
+
/** Time-to-live in minutes */
|
|
54
|
+
ttlMinutes?: number;
|
|
55
|
+
/** Number of messages before triggering summarization */
|
|
56
|
+
summaryTrigger?: number;
|
|
57
|
+
/** Whether to persist to long-term storage */
|
|
58
|
+
persistLongTerm?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Confidence policy for agent responses.
|
|
62
|
+
*/
|
|
63
|
+
interface AgentConfidencePolicy {
|
|
64
|
+
/** Minimum acceptable confidence before escalation. Defaults to 0.7 */
|
|
65
|
+
min?: number;
|
|
66
|
+
/** Default value used when provider does not report confidence */
|
|
67
|
+
default?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Escalation policy for handling uncertain or failed agent responses.
|
|
71
|
+
*/
|
|
72
|
+
interface AgentEscalationPolicy {
|
|
73
|
+
/** Auto escalate when confidence < threshold */
|
|
74
|
+
confidenceThreshold?: number;
|
|
75
|
+
/** Escalate when a tool throws irrecoverable errors */
|
|
76
|
+
onToolFailure?: boolean;
|
|
77
|
+
/** Escalate when iteration budget exceeded */
|
|
78
|
+
onTimeout?: boolean;
|
|
79
|
+
/** Optional human approval workflow ID */
|
|
80
|
+
approvalWorkflow?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Combined policy configuration for an agent.
|
|
84
|
+
*/
|
|
85
|
+
interface AgentPolicy {
|
|
86
|
+
confidence?: AgentConfidencePolicy;
|
|
87
|
+
escalation?: AgentEscalationPolicy;
|
|
88
|
+
/** Feature flags to apply to this agent */
|
|
89
|
+
flags?: string[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Complete specification for a ContractSpec agent.
|
|
93
|
+
*/
|
|
94
|
+
interface AgentSpec {
|
|
95
|
+
meta: AgentMeta;
|
|
96
|
+
/** System instructions for the agent */
|
|
97
|
+
instructions: string;
|
|
98
|
+
/** Human-readable description */
|
|
99
|
+
description?: string;
|
|
100
|
+
/** Tags for categorization */
|
|
101
|
+
tags?: string[];
|
|
102
|
+
/** Tools the agent can use */
|
|
103
|
+
tools: AgentToolConfig[];
|
|
104
|
+
/** Memory/session configuration */
|
|
105
|
+
memory?: AgentMemoryConfig;
|
|
106
|
+
/** Knowledge spaces the agent can access */
|
|
107
|
+
knowledge?: AgentKnowledgeRef[];
|
|
108
|
+
/** Policy configuration */
|
|
109
|
+
policy?: AgentPolicy;
|
|
110
|
+
/** Maximum steps per generation (defaults to 10) */
|
|
111
|
+
maxSteps?: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Define and validate an agent specification.
|
|
115
|
+
*
|
|
116
|
+
* @param spec - The agent specification
|
|
117
|
+
* @returns The frozen, validated specification
|
|
118
|
+
* @throws Error if the specification is invalid
|
|
119
|
+
*/
|
|
120
|
+
declare function defineAgent(spec: AgentSpec): AgentSpec;
|
|
121
|
+
/**
|
|
122
|
+
* Generate a unique key for an agent spec.
|
|
123
|
+
*/
|
|
124
|
+
declare function agentKey(meta: AgentMeta): string;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { AgentConfidencePolicy, AgentEscalationPolicy, AgentKnowledgeRef, AgentMemoryConfig, AgentMeta, AgentPolicy, AgentSpec, AgentToolConfig, agentKey, defineAgent };
|
|
127
|
+
//# sourceMappingURL=spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../src/spec/spec.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAOA;AAKiB,KALL,SAAA,GAAY,aAWb;AAgBX;AAgBA;AAcA;AAUiB,UA9DA,eAAA,CA8DqB;EAcrB;EAUA,IAAA,EAAA,MAAS;EAClB;EAQC,WAAA,CAAA,EAAA,MAAA;EAEE;EAEG,MAAA,CAAA,EA7FH,MA6FG,CAAA,MAAA,EAAA,OAAA,CAAA;EAEH;EAAW,UAAA,CAAA,EAAA,MAAA;EAYN;EA+BA,SAAA,CAAA,EAAQ,MAAA;;;;;;WAhIb;;;;;UAMM,iBAAA;;;;;;aAMJ;;;;;;;;;UAUI,iBAAA;;;;;;;;;;;;;UAcA,qBAAA;;;;;;;;;UAUA,qBAAA;;;;;;;;;;;;;UAcA,WAAA;eACF;eACA;;;;;;;UAQE,SAAA;QACT;;;;;;;;SAQC;;WAEE;;cAEG;;WAEH;;;;;;;;;;;iBAYK,WAAA,OAAkB,YAAY;;;;iBA+B9B,QAAA,OAAe"}
|
package/dist/spec/spec.js
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/spec/spec.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define and validate an agent specification.
|
|
4
|
+
*
|
|
5
|
+
* @param spec - The agent specification
|
|
6
|
+
* @returns The frozen, validated specification
|
|
7
|
+
* @throws Error if the specification is invalid
|
|
8
|
+
*/
|
|
9
|
+
function defineAgent(spec) {
|
|
10
|
+
if (!spec.meta?.key) throw new Error("Agent key is required");
|
|
11
|
+
if (!Number.isFinite(spec.meta.version)) throw new Error(`Agent ${spec.meta.key} is missing a numeric version`);
|
|
12
|
+
if (!spec.instructions?.trim()) throw new Error(`Agent ${spec.meta.key} requires instructions`);
|
|
13
|
+
if (!spec.tools?.length) throw new Error(`Agent ${spec.meta.key} must expose at least one tool`);
|
|
14
|
+
const toolNames = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const tool of spec.tools) {
|
|
16
|
+
if (toolNames.has(tool.name)) throw new Error(`Agent ${spec.meta.key} has duplicate tool name: ${tool.name}`);
|
|
17
|
+
toolNames.add(tool.name);
|
|
18
|
+
}
|
|
19
|
+
return Object.freeze(spec);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generate a unique key for an agent spec.
|
|
23
|
+
*/
|
|
24
|
+
function agentKey(meta) {
|
|
25
|
+
return `${meta.key}.v${meta.version}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { agentKey, defineAgent };
|
|
30
|
+
//# sourceMappingURL=spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.js","names":[],"sources":["../../src/spec/spec.ts"],"sourcesContent":["import type { OwnerShipMeta } from '@lssm/lib.contracts/ownership';\nimport type { KnowledgeCategory } from '@lssm/lib.contracts/knowledge/spec';\nimport type { PolicyRef } from '@lssm/lib.contracts/policy/spec';\n\n/**\n * Metadata for an agent specification.\n */\nexport type AgentMeta = OwnerShipMeta;\n\n/**\n * Configuration for a tool that an agent can use.\n */\nexport interface AgentToolConfig {\n /** Tool name (unique within the agent) */\n name: string;\n /** Human-readable description for the LLM */\n description?: string;\n /** JSON Schema fragment for tool parameters */\n schema?: Record<string, unknown>;\n /** Optional cooldown in milliseconds between invocations */\n cooldownMs?: number;\n /** Maximum execution time before timeout */\n timeoutMs?: number;\n /** Whether the tool can be executed without human approval (AI SDK needsApproval = !automationSafe) */\n automationSafe?: boolean;\n /** Explicit approval requirement (overrides automationSafe) */\n requiresApproval?: boolean;\n /** Optional policy guard that must evaluate to allow the tool call */\n policy?: PolicyRef;\n}\n\n/**\n * Reference to a knowledge space that the agent can access.\n */\nexport interface AgentKnowledgeRef {\n /** Knowledge space key */\n key: string;\n /** Optional specific version */\n version?: number;\n /** Filter by knowledge category */\n category?: KnowledgeCategory;\n /** Whether the knowledge is required (static injection) or optional (dynamic RAG) */\n required?: boolean;\n /** Additional instructions appended when the space is available */\n instructions?: string;\n}\n\n/**\n * Memory configuration for agent session persistence.\n */\nexport interface AgentMemoryConfig {\n /** Maximum entries to keep in memory */\n maxEntries?: number;\n /** Time-to-live in minutes */\n ttlMinutes?: number;\n /** Number of messages before triggering summarization */\n summaryTrigger?: number;\n /** Whether to persist to long-term storage */\n persistLongTerm?: boolean;\n}\n\n/**\n * Confidence policy for agent responses.\n */\nexport interface AgentConfidencePolicy {\n /** Minimum acceptable confidence before escalation. Defaults to 0.7 */\n min?: number;\n /** Default value used when provider does not report confidence */\n default?: number;\n}\n\n/**\n * Escalation policy for handling uncertain or failed agent responses.\n */\nexport interface AgentEscalationPolicy {\n /** Auto escalate when confidence < threshold */\n confidenceThreshold?: number;\n /** Escalate when a tool throws irrecoverable errors */\n onToolFailure?: boolean;\n /** Escalate when iteration budget exceeded */\n onTimeout?: boolean;\n /** Optional human approval workflow ID */\n approvalWorkflow?: string;\n}\n\n/**\n * Combined policy configuration for an agent.\n */\nexport interface AgentPolicy {\n confidence?: AgentConfidencePolicy;\n escalation?: AgentEscalationPolicy;\n /** Feature flags to apply to this agent */\n flags?: string[];\n}\n\n/**\n * Complete specification for a ContractSpec agent.\n */\nexport interface AgentSpec {\n meta: AgentMeta;\n /** System instructions for the agent */\n instructions: string;\n /** Human-readable description */\n description?: string;\n /** Tags for categorization */\n tags?: string[];\n /** Tools the agent can use */\n tools: AgentToolConfig[];\n /** Memory/session configuration */\n memory?: AgentMemoryConfig;\n /** Knowledge spaces the agent can access */\n knowledge?: AgentKnowledgeRef[];\n /** Policy configuration */\n policy?: AgentPolicy;\n /** Maximum steps per generation (defaults to 10) */\n maxSteps?: number;\n}\n\n/**\n * Define and validate an agent specification.\n *\n * @param spec - The agent specification\n * @returns The frozen, validated specification\n * @throws Error if the specification is invalid\n */\nexport function defineAgent(spec: AgentSpec): AgentSpec {\n if (!spec.meta?.key) {\n throw new Error('Agent key is required');\n }\n if (!Number.isFinite(spec.meta.version)) {\n throw new Error(`Agent ${spec.meta.key} is missing a numeric version`);\n }\n if (!spec.instructions?.trim()) {\n throw new Error(`Agent ${spec.meta.key} requires instructions`);\n }\n if (!spec.tools?.length) {\n throw new Error(`Agent ${spec.meta.key} must expose at least one tool`);\n }\n\n // Validate tool names are unique\n const toolNames = new Set<string>();\n for (const tool of spec.tools) {\n if (toolNames.has(tool.name)) {\n throw new Error(\n `Agent ${spec.meta.key} has duplicate tool name: ${tool.name}`\n );\n }\n toolNames.add(tool.name);\n }\n\n return Object.freeze(spec);\n}\n\n/**\n * Generate a unique key for an agent spec.\n */\nexport function agentKey(meta: AgentMeta): string {\n return `${meta.key}.v${meta.version}`;\n}\n"],"mappings":";;;;;;;;AA6HA,SAAgB,YAAY,MAA4B;AACtD,KAAI,CAAC,KAAK,MAAM,IACd,OAAM,IAAI,MAAM,wBAAwB;AAE1C,KAAI,CAAC,OAAO,SAAS,KAAK,KAAK,QAAQ,CACrC,OAAM,IAAI,MAAM,SAAS,KAAK,KAAK,IAAI,+BAA+B;AAExE,KAAI,CAAC,KAAK,cAAc,MAAM,CAC5B,OAAM,IAAI,MAAM,SAAS,KAAK,KAAK,IAAI,wBAAwB;AAEjE,KAAI,CAAC,KAAK,OAAO,OACf,OAAM,IAAI,MAAM,SAAS,KAAK,KAAK,IAAI,gCAAgC;CAIzE,MAAM,4BAAY,IAAI,KAAa;AACnC,MAAK,MAAM,QAAQ,KAAK,OAAO;AAC7B,MAAI,UAAU,IAAI,KAAK,KAAK,CAC1B,OAAM,IAAI,MACR,SAAS,KAAK,KAAK,IAAI,4BAA4B,KAAK,OACzD;AAEH,YAAU,IAAI,KAAK,KAAK;;AAG1B,QAAO,OAAO,OAAO,KAAK;;;;;AAM5B,SAAgB,SAAS,MAAyB;AAChD,QAAO,GAAG,KAAK,IAAI,IAAI,KAAK"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { StepResult, ToolSet } from "ai";
|
|
2
|
+
|
|
3
|
+
//#region src/telemetry/adapter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Metric sample compatible with @lssm/lib.evolution OperationMetricSample.
|
|
7
|
+
*/
|
|
8
|
+
interface OperationMetricSample {
|
|
9
|
+
operation: {
|
|
10
|
+
name: string;
|
|
11
|
+
version: number;
|
|
12
|
+
};
|
|
13
|
+
durationMs: number;
|
|
14
|
+
success: boolean;
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Interface for collecting telemetry metrics.
|
|
20
|
+
*
|
|
21
|
+
* Implementations can send metrics to:
|
|
22
|
+
* - @lssm/lib.evolution for self-improvement
|
|
23
|
+
* - PostHog for analytics
|
|
24
|
+
* - Custom monitoring systems
|
|
25
|
+
*/
|
|
26
|
+
interface TelemetryCollector {
|
|
27
|
+
/**
|
|
28
|
+
* Collect a metric sample.
|
|
29
|
+
*/
|
|
30
|
+
collect(sample: OperationMetricSample): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Track an agent step for telemetry.
|
|
34
|
+
*
|
|
35
|
+
* Called from ContractSpecAgent.onStepFinish to feed metrics
|
|
36
|
+
* to the evolution engine.
|
|
37
|
+
*
|
|
38
|
+
* @param collector - Telemetry collector
|
|
39
|
+
* @param agentId - Agent identifier (e.g., "support.bot.v1")
|
|
40
|
+
* @param step - AI SDK step result
|
|
41
|
+
* @param durationMs - Optional step duration in milliseconds
|
|
42
|
+
*/
|
|
43
|
+
declare function trackAgentStep(collector: TelemetryCollector, agentId: string, step: StepResult<ToolSet>, durationMs?: number): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* In-memory telemetry collector for testing.
|
|
46
|
+
*/
|
|
47
|
+
declare class InMemoryTelemetryCollector implements TelemetryCollector {
|
|
48
|
+
private readonly samples;
|
|
49
|
+
collect(sample: OperationMetricSample): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Get all collected samples.
|
|
52
|
+
*/
|
|
53
|
+
getSamples(): OperationMetricSample[];
|
|
54
|
+
/**
|
|
55
|
+
* Get samples for a specific operation.
|
|
56
|
+
*/
|
|
57
|
+
getSamplesForOperation(operationName: string): OperationMetricSample[];
|
|
58
|
+
/**
|
|
59
|
+
* Clear all samples.
|
|
60
|
+
*/
|
|
61
|
+
clear(): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create an in-memory telemetry collector.
|
|
65
|
+
*/
|
|
66
|
+
declare function createInMemoryTelemetryCollector(): InMemoryTelemetryCollector;
|
|
67
|
+
/**
|
|
68
|
+
* No-op telemetry collector that discards all metrics.
|
|
69
|
+
*/
|
|
70
|
+
declare const noopTelemetryCollector: TelemetryCollector;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { InMemoryTelemetryCollector, OperationMetricSample, TelemetryCollector, createInMemoryTelemetryCollector, noopTelemetryCollector, trackAgentStep };
|
|
73
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","names":[],"sources":["../../src/telemetry/adapter.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAgBiB,UAhBA,qBAAA,CAoBC;EA0BI,SAAA,EAAA;IACT,IAAA,EAAA,MAAA;IAEM,OAAA,EAAA,MAAA;EAAX,CAAA;EAEL,UAAA,EAAA,MAAA;EAAO,OAAA,EAAA,OAAA;EAyCG,SAAA,EAxFA,IAwFA;EAGW,QAAA,CAAA,EA1FX,MA0FW,CAAA,MAAA,EAAA,OAAA,CAAA;;;;;;AA6BxB;AAOA;;;UAnHiB,kBAAA;;;;kBAIC,wBAAwB;;;;;;;;;;;;;iBA0BpB,cAAA,YACT,2CAEL,WAAW,gCAEhB;;;;cAyCU,0BAAA,YAAsC;;kBAG3B,wBAAwB;;;;gBAOhC;;;;iDAOiC;;;;;;;;;iBAejC,gCAAA,CAAA,GAAoC;;;;cAOvC,wBAAwB"}
|