@inkeep/agents-sdk 0.39.4 → 0.40.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/_virtual/rolldown_runtime.js +7 -0
- package/dist/agent.d.ts +186 -0
- package/dist/agent.js +720 -0
- package/dist/agentFullClient.d.ts +22 -0
- package/dist/agentFullClient.js +120 -0
- package/dist/artifact-component.d.ts +34 -0
- package/dist/artifact-component.js +104 -0
- package/dist/builderFunctions.d.ts +283 -0
- package/dist/builderFunctions.js +327 -0
- package/dist/builderFunctionsExperimental.d.ts +24 -0
- package/dist/builderFunctionsExperimental.js +27 -0
- package/dist/builders.d.ts +111 -0
- package/dist/builders.js +52 -0
- package/dist/credential-provider.d.ts +176 -0
- package/dist/credential-provider.js +237 -0
- package/dist/credential-ref.d.ts +60 -0
- package/dist/credential-ref.js +33 -0
- package/dist/data-component.d.ts +39 -0
- package/dist/data-component.js +109 -0
- package/dist/environment-settings.d.ts +27 -0
- package/dist/environment-settings.js +41 -0
- package/dist/external-agent.d.ts +64 -0
- package/dist/external-agent.js +156 -0
- package/dist/function-tool.d.ts +37 -0
- package/dist/function-tool.js +66 -0
- package/dist/index.d.ts +19 -1825
- package/dist/index.js +19 -4058
- package/dist/module-hosted-tool-manager.d.ts +40 -0
- package/dist/module-hosted-tool-manager.js +359 -0
- package/dist/project.d.ts +214 -0
- package/dist/project.js +615 -0
- package/dist/projectFullClient.d.ts +23 -0
- package/dist/projectFullClient.js +162 -0
- package/dist/runner.d.ts +41 -0
- package/dist/runner.js +145 -0
- package/dist/status-component.d.ts +22 -0
- package/dist/status-component.js +36 -0
- package/dist/subAgent.d.ts +52 -0
- package/dist/subAgent.js +616 -0
- package/dist/telemetry-provider.d.ts +218 -0
- package/dist/telemetry-provider.js +390 -0
- package/dist/tool.d.ts +53 -0
- package/dist/tool.js +130 -0
- package/dist/types.d.ts +296 -0
- package/dist/types.js +39 -0
- package/dist/utils/generateIdFromName.d.ts +9 -0
- package/dist/utils/generateIdFromName.js +12 -0
- package/dist/utils/getFunctionToolDeps.d.ts +17 -0
- package/dist/utils/getFunctionToolDeps.js +131 -0
- package/dist/utils/tool-normalization.d.ts +42 -0
- package/dist/utils/tool-normalization.js +41 -0
- package/dist/utils/validateFunction.d.ts +10 -0
- package/dist/utils/validateFunction.js +13 -0
- package/package.json +11 -16
- package/dist/index.cjs +0 -4147
- package/dist/index.d.cts +0 -1825
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/environment-settings.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a setting helper with TypeScript autocomplete
|
|
4
|
+
*/
|
|
5
|
+
function createEnvironmentSettings(environments) {
|
|
6
|
+
return {
|
|
7
|
+
getEnvironmentCredential: (key) => {
|
|
8
|
+
const currentEnv = process.env.INKEEP_ENV || "development";
|
|
9
|
+
const env = environments[currentEnv];
|
|
10
|
+
if (!env) throw new Error(`Environment '${currentEnv}' not found. Available: ${Object.keys(environments).join(", ")}`);
|
|
11
|
+
const credential = env.credentials?.[key];
|
|
12
|
+
if (!credential) throw new Error(`Credential '${String(key)}' not found in environment '${currentEnv}'`);
|
|
13
|
+
return credential;
|
|
14
|
+
},
|
|
15
|
+
getEnvironmentMcp: (key) => {
|
|
16
|
+
const currentEnv = process.env.INKEEP_ENV || "development";
|
|
17
|
+
const env = environments[currentEnv];
|
|
18
|
+
if (!env) throw new Error(`Environment '${currentEnv}' not found. Available: ${Object.keys(environments).join(", ")}`);
|
|
19
|
+
const mcpServer = env.mcpServers?.[key];
|
|
20
|
+
if (!mcpServer) throw new Error(`MCP Server '${String(key)}' not found in environment '${currentEnv}'`);
|
|
21
|
+
return mcpServer;
|
|
22
|
+
},
|
|
23
|
+
getEnvironmentSetting: (key) => {
|
|
24
|
+
const currentEnv = process.env.INKEEP_ENV || "development";
|
|
25
|
+
const env = environments[currentEnv];
|
|
26
|
+
if (!env) throw new Error(`Environment '${currentEnv}' not found. Available: ${Object.keys(environments).join(", ")}`);
|
|
27
|
+
const credential = env.credentials?.[key];
|
|
28
|
+
if (!credential) throw new Error(`Credential '${String(key)}' not found in environment '${currentEnv}'`);
|
|
29
|
+
return credential;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create type-safe environment configurations
|
|
35
|
+
*/
|
|
36
|
+
function registerEnvironmentSettings(config) {
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createEnvironmentSettings, registerEnvironmentSettings };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ExternalAgentInterface, subAgentExternalAgentInterface } from "./types.js";
|
|
2
|
+
import { CredentialReferenceApiInsert } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/external-agent.d.ts
|
|
5
|
+
type ExternalAgentConfig = {
|
|
6
|
+
type?: 'external';
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
credentialReference?: CredentialReferenceApiInsert;
|
|
12
|
+
};
|
|
13
|
+
declare class ExternalAgent implements ExternalAgentInterface {
|
|
14
|
+
config: ExternalAgentConfig;
|
|
15
|
+
readonly type: "external";
|
|
16
|
+
private initialized;
|
|
17
|
+
private tenantId;
|
|
18
|
+
private projectId;
|
|
19
|
+
private baseURL;
|
|
20
|
+
constructor(config: ExternalAgentConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the external agent by upserting it in the database
|
|
23
|
+
*/
|
|
24
|
+
init(): Promise<void>;
|
|
25
|
+
setContext(tenantId: string, projectId: string): void;
|
|
26
|
+
getId(): string;
|
|
27
|
+
with(options: {
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
}): subAgentExternalAgentInterface;
|
|
30
|
+
private upsertExternalAgent;
|
|
31
|
+
/**
|
|
32
|
+
* Get the external agent configuration
|
|
33
|
+
*/
|
|
34
|
+
getConfig(): ExternalAgentConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Get the external agent name
|
|
37
|
+
*/
|
|
38
|
+
getName(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Get the external agent base URL
|
|
41
|
+
*/
|
|
42
|
+
getBaseUrl(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get the tenant ID
|
|
45
|
+
*/
|
|
46
|
+
getTenantId(): string;
|
|
47
|
+
getDescription(): string;
|
|
48
|
+
getCredentialReferenceId(): string | undefined;
|
|
49
|
+
getCredentialReference(): CredentialReferenceApiInsert | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Factory function to create external agents - follows the same pattern as agent()
|
|
53
|
+
*/
|
|
54
|
+
declare function externalAgent(config: ExternalAgentConfig): ExternalAgent;
|
|
55
|
+
/**
|
|
56
|
+
* Helper function to create multiple external agents
|
|
57
|
+
*/
|
|
58
|
+
declare function externalAgents(configs: Record<string, ExternalAgentConfig>): Record<string, ExternalAgent>;
|
|
59
|
+
/**
|
|
60
|
+
* Helper to batch initialize external agents
|
|
61
|
+
*/
|
|
62
|
+
declare function initializeExternalAgents(builders: ExternalAgent[]): Promise<void>;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ExternalAgent, ExternalAgentConfig, externalAgent, externalAgents, initializeExternalAgents };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { getLogger } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/external-agent.ts
|
|
4
|
+
const logger = getLogger("external-agent-builder");
|
|
5
|
+
var ExternalAgent = class {
|
|
6
|
+
config;
|
|
7
|
+
type = "external";
|
|
8
|
+
initialized = false;
|
|
9
|
+
tenantId;
|
|
10
|
+
projectId;
|
|
11
|
+
baseURL;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = {
|
|
14
|
+
...config,
|
|
15
|
+
type: "external"
|
|
16
|
+
};
|
|
17
|
+
this.tenantId = "default";
|
|
18
|
+
this.projectId = "default";
|
|
19
|
+
this.baseURL = this.config.baseUrl;
|
|
20
|
+
logger.debug({
|
|
21
|
+
externalAgentName: this.config.name,
|
|
22
|
+
baseUrl: this.config.baseUrl,
|
|
23
|
+
tenantId: this.tenantId
|
|
24
|
+
}, "External Agent constructor initialized");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Initialize the external agent by upserting it in the database
|
|
28
|
+
*/
|
|
29
|
+
async init() {
|
|
30
|
+
if (this.initialized) return;
|
|
31
|
+
try {
|
|
32
|
+
await this.upsertExternalAgent();
|
|
33
|
+
logger.info({ externalSubAgentId: this.getId() }, "External agent initialized successfully");
|
|
34
|
+
this.initialized = true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.error({
|
|
37
|
+
externalSubAgentId: this.getId(),
|
|
38
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
39
|
+
}, "Failed to initialize external agent");
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setContext(tenantId, projectId) {
|
|
44
|
+
this.tenantId = tenantId;
|
|
45
|
+
this.projectId = projectId;
|
|
46
|
+
}
|
|
47
|
+
getId() {
|
|
48
|
+
return this.config.id;
|
|
49
|
+
}
|
|
50
|
+
with(options) {
|
|
51
|
+
return {
|
|
52
|
+
externalAgent: this,
|
|
53
|
+
headers: options.headers
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async upsertExternalAgent() {
|
|
57
|
+
const externalAgentData = {
|
|
58
|
+
id: this.getId(),
|
|
59
|
+
name: this.config.name,
|
|
60
|
+
description: this.config.description,
|
|
61
|
+
baseUrl: this.config.baseUrl,
|
|
62
|
+
credentialReferenceId: this.config.credentialReference?.id || void 0
|
|
63
|
+
};
|
|
64
|
+
const updateResponse = await fetch(`${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/external-agents/${this.getId()}`, {
|
|
65
|
+
method: "PUT",
|
|
66
|
+
headers: { "Content-Type": "application/json" },
|
|
67
|
+
body: JSON.stringify(externalAgentData)
|
|
68
|
+
});
|
|
69
|
+
if (updateResponse.ok) {
|
|
70
|
+
logger.info({ externalSubAgentId: this.getId() }, "External agent updated successfully");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (updateResponse.status === 404) {
|
|
74
|
+
logger.info({ externalSubAgentId: this.getId() }, "External agent not found, creating new external agent");
|
|
75
|
+
const createResponse = await fetch(`${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/external-agents`, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: { "Content-Type": "application/json" },
|
|
78
|
+
body: JSON.stringify(externalAgentData)
|
|
79
|
+
});
|
|
80
|
+
if (!createResponse.ok) {
|
|
81
|
+
const errorText$1 = await createResponse.text().catch(() => "Unknown error");
|
|
82
|
+
throw new Error(`Failed to create external agent: ${createResponse.status} ${createResponse.statusText} - ${errorText$1}`);
|
|
83
|
+
}
|
|
84
|
+
logger.info({ externalSubAgentId: this.getId() }, "External agent created successfully");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const errorText = await updateResponse.text().catch(() => "Unknown error");
|
|
88
|
+
throw new Error(`Failed to update external agent: ${updateResponse.status} ${updateResponse.statusText} - ${errorText}`);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the external agent configuration
|
|
92
|
+
*/
|
|
93
|
+
getConfig() {
|
|
94
|
+
return { ...this.config };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the external agent name
|
|
98
|
+
*/
|
|
99
|
+
getName() {
|
|
100
|
+
return this.config.name;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the external agent base URL
|
|
104
|
+
*/
|
|
105
|
+
getBaseUrl() {
|
|
106
|
+
return this.config.baseUrl;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the tenant ID
|
|
110
|
+
*/
|
|
111
|
+
getTenantId() {
|
|
112
|
+
return this.tenantId;
|
|
113
|
+
}
|
|
114
|
+
getDescription() {
|
|
115
|
+
return this.config.description || "";
|
|
116
|
+
}
|
|
117
|
+
getCredentialReferenceId() {
|
|
118
|
+
return this.config.credentialReference?.id || void 0;
|
|
119
|
+
}
|
|
120
|
+
getCredentialReference() {
|
|
121
|
+
return this.config.credentialReference || void 0;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Factory function to create external agents - follows the same pattern as agent()
|
|
126
|
+
*/
|
|
127
|
+
function externalAgent(config) {
|
|
128
|
+
return new ExternalAgent(config);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Helper function to create multiple external agents
|
|
132
|
+
*/
|
|
133
|
+
function externalAgents(configs) {
|
|
134
|
+
const builders = {};
|
|
135
|
+
for (const [name, config] of Object.entries(configs)) builders[name] = externalAgent(config);
|
|
136
|
+
return builders;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Helper to batch initialize external agents
|
|
140
|
+
*/
|
|
141
|
+
async function initializeExternalAgents(builders) {
|
|
142
|
+
logger.info({ count: builders.length }, "Batch initializing external agents");
|
|
143
|
+
const initPromises = builders.map(async (builder) => {
|
|
144
|
+
return await builder.init();
|
|
145
|
+
});
|
|
146
|
+
try {
|
|
147
|
+
await Promise.all(initPromises);
|
|
148
|
+
logger.info({ count: builders.length }, "All external agents initialized successfully");
|
|
149
|
+
} catch (error) {
|
|
150
|
+
logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Failed to initialize some external agents");
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
export { ExternalAgent, externalAgent, externalAgents, initializeExternalAgents };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FunctionToolConfig } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/function-tool.d.ts
|
|
4
|
+
interface FunctionToolInterface {
|
|
5
|
+
config: FunctionToolConfig;
|
|
6
|
+
getId(): string;
|
|
7
|
+
getName(): string;
|
|
8
|
+
getDescription(): string;
|
|
9
|
+
getInputSchema(): Record<string, unknown>;
|
|
10
|
+
getDependencies(): Record<string, string>;
|
|
11
|
+
getExecuteFunction(): (params: any) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
declare class FunctionTool implements FunctionToolInterface {
|
|
14
|
+
config: FunctionToolConfig;
|
|
15
|
+
private id;
|
|
16
|
+
constructor(config: FunctionToolConfig);
|
|
17
|
+
getId(): string;
|
|
18
|
+
getName(): string;
|
|
19
|
+
getDescription(): string;
|
|
20
|
+
getInputSchema(): Record<string, unknown>;
|
|
21
|
+
getDependencies(): Record<string, string>;
|
|
22
|
+
getExecuteFunction(): (params: any) => Promise<any>;
|
|
23
|
+
serializeFunction(): {
|
|
24
|
+
id: string;
|
|
25
|
+
inputSchema: Record<string, unknown>;
|
|
26
|
+
executeCode: string;
|
|
27
|
+
dependencies: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
serializeTool(): {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
functionId: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { FunctionTool, FunctionToolInterface };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { generateIdFromName } from "./utils/generateIdFromName.js";
|
|
2
|
+
import { getFunctionToolDeps } from "./utils/getFunctionToolDeps.js";
|
|
3
|
+
import { getLogger } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/function-tool.ts
|
|
6
|
+
const logger = getLogger("function-tool");
|
|
7
|
+
var FunctionTool = class {
|
|
8
|
+
config;
|
|
9
|
+
id;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.id = generateIdFromName(config.name);
|
|
13
|
+
if (!config.dependencies) {
|
|
14
|
+
const executeCode = typeof config.execute === "string" ? config.execute : config.execute.toString();
|
|
15
|
+
const deps = getFunctionToolDeps(config.name, executeCode);
|
|
16
|
+
for (const dep in deps) if (deps[dep] === false) {
|
|
17
|
+
delete deps[dep];
|
|
18
|
+
throw new Error(`Dependency \x1b[1;32m${dep}\x1b[0m used in function tool \x1b[1;32m${config.name}\x1b[0m is neither installed nor in dependencies object.`);
|
|
19
|
+
}
|
|
20
|
+
this.config.dependencies = deps;
|
|
21
|
+
}
|
|
22
|
+
logger.info({
|
|
23
|
+
id: this.id,
|
|
24
|
+
name: config.name
|
|
25
|
+
}, "FunctionTool constructor initialized");
|
|
26
|
+
}
|
|
27
|
+
getId() {
|
|
28
|
+
return this.id;
|
|
29
|
+
}
|
|
30
|
+
getName() {
|
|
31
|
+
return this.config.name;
|
|
32
|
+
}
|
|
33
|
+
getDescription() {
|
|
34
|
+
return this.config.description || "";
|
|
35
|
+
}
|
|
36
|
+
getInputSchema() {
|
|
37
|
+
return this.config.inputSchema;
|
|
38
|
+
}
|
|
39
|
+
getDependencies() {
|
|
40
|
+
return this.config.dependencies || {};
|
|
41
|
+
}
|
|
42
|
+
getExecuteFunction() {
|
|
43
|
+
if (typeof this.config.execute === "string") throw new Error("Cannot get execute function from string-based function tool. Use serializeFunction() instead.");
|
|
44
|
+
return this.config.execute;
|
|
45
|
+
}
|
|
46
|
+
serializeFunction() {
|
|
47
|
+
const executeCode = typeof this.config.execute === "string" ? this.config.execute : this.config.execute.toString();
|
|
48
|
+
return {
|
|
49
|
+
id: this.id,
|
|
50
|
+
inputSchema: this.config.inputSchema,
|
|
51
|
+
executeCode,
|
|
52
|
+
dependencies: this.config.dependencies || {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
serializeTool() {
|
|
56
|
+
return {
|
|
57
|
+
id: this.id,
|
|
58
|
+
name: this.config.name,
|
|
59
|
+
description: this.config.description,
|
|
60
|
+
functionId: this.id
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { FunctionTool };
|