@andreprado/agentkit 0.1.1 → 0.3.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/README.md +8 -77
- package/docs/guides/add-channel.md +14 -92
- package/docs/guides/add-knowledge.md +0 -21
- package/docs/guides/add-tool.md +5 -11
- package/docs/guides/channel-security.md +3 -207
- package/docs/guides/connect-discord.md +7 -172
- package/docs/guides/connect-slack.md +6 -121
- package/docs/guides/connect-telegram.md +6 -165
- package/docs/guides/connect-whatsapp-evolution.md +6 -116
- package/docs/guides/connect-whatsapp-uazapi.md +6 -134
- package/docs/guides/connect-whatsapp-zapster.md +6 -202
- package/docs/guides/create-agent.md +5 -14
- package/docs/guides/debug-channel.md +4 -156
- package/docs/guides/improve-local.md +13 -0
- package/docs/guides/local-only-migration.md +35 -0
- package/docs/guides/replay-local-traces.md +11 -0
- package/docs/guides/run-evals.md +2 -4
- package/docs/guides/security-rules.md +5 -154
- package/docs/guides/use-jev.md +3 -6
- package/docs/guides/use-provider.md +5 -6
- package/docs/guides/write-feedback.md +10 -0
- package/docs/llms-full.txt +27 -448
- package/docs/llms.txt +8 -44
- package/package.json +3 -5
- package/src/cli/commands/channels.ts +8 -1613
- package/src/cli/commands/feedback.ts +8 -86
- package/src/cli/commands/provider.ts +29 -11
- package/src/cli/constants.ts +0 -3
- package/src/cli/flags.ts +0 -28
- package/src/cli/help.ts +16 -92
- package/src/cli/index.ts +15 -1091
- package/src/index.ts +6 -158
- package/src/providers/codex-auth.ts +16 -2
- package/src/providers/pi.ts +36 -19
- package/src/runtime/channels/discord.ts +2 -2
- package/src/runtime/chat.ts +5 -3
- package/src/runtime/config.ts +14 -148
- package/src/runtime/database.ts +2 -2
- package/src/runtime/dev-server.ts +8 -8
- package/src/runtime/env.ts +11 -0
- package/src/runtime/improve.ts +2 -262
- package/src/runtime/inspect.ts +13 -73
- package/src/runtime/knowledge/ingest.ts +1 -1
- package/src/runtime/knowledge/tool.ts +16 -2
- package/src/runtime/knowledge/vector.ts +1 -1
- package/src/runtime/tool-runner.ts +5 -3
- package/src/runtime/tools.ts +10 -14
- package/src/storage/sqlite.ts +11 -32
- package/src/templates/blank.ts +15 -102
- package/src/templates/common.ts +60 -0
- package/src/templates/dentista.ts +7 -74
- package/src/templates/skills/agentkit-capsule/SKILL.md +5 -7
- package/src/templates/skills/agentkit-capsule/references/docs-router.md +2 -3
- package/src/templates/skills/agentkit-channels/SKILL.md +6 -119
- package/src/templates/skills/agentkit-channels/references/channel-buffering.md +0 -9
- package/src/templates/skills/agentkit-channels/references/channel-debugging.md +1 -64
- package/src/templates/skills/agentkit-channels/references/discord.md +2 -92
- package/src/templates/skills/agentkit-channels/references/slack.md +2 -55
- package/src/templates/skills/agentkit-channels/references/telegram.md +2 -71
- package/src/templates/skills/agentkit-channels/references/whatsapp-evolution.md +2 -56
- package/src/templates/skills/agentkit-channels/references/whatsapp-uazapi.md +2 -53
- package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +2 -70
- package/src/templates/skills/agentkit-database/SKILL.md +2 -4
- package/src/templates/skills/agentkit-evals/SKILL.md +1 -1
- package/src/templates/skills/agentkit-improve/SKILL.md +6 -85
- package/src/templates/skills/agentkit-improve/references/trace-packets.md +1 -1
- package/src/templates/skills/agentkit-provider/SKILL.md +1 -2
- package/src/templates/skills/agentkit-security/SKILL.md +1 -3
- package/src/templates/skills/agentkit-tools/SKILL.md +1 -1
- package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +1 -2
- package/src/templates/skills/agentkit-troubleshooting/SKILL.md +5 -11
- package/src/templates/support.ts +8 -92
- package/docs/guides/add-managed-composio.md +0 -165
- package/docs/guides/improve-from-production.md +0 -151
- package/docs/guides/prepare-deploy.md +0 -227
- package/docs/guides/replay-production-traces.md +0 -72
- package/docs/guides/send-feedback.md +0 -135
- package/src/cli/cloud-client.ts +0 -377
- package/src/cli/deploy-chat-ui.ts +0 -606
- package/src/cli/deploy-readiness.ts +0 -561
- package/src/cloud/artifact.ts +0 -139
- package/src/cloud/client.ts +0 -80
- package/src/cloud/contracts.ts +0 -63
- package/src/cloud/index.ts +0 -3
- package/src/runtime/build.ts +0 -43
- package/src/runtime/core/deploy-state.ts +0 -54
- package/src/runtime/core/manifest.ts +0 -283
- package/src/runtime/core/targets.ts +0 -133
- package/src/runtime/deploy-readiness.ts +0 -135
- package/src/runtime/deploy.ts +0 -1
- package/src/runtime/integrations/composio.ts +0 -425
- package/src/runtime/targets/cloudflare/build.ts +0 -3319
- package/src/runtime/targets/container/build.ts +0 -146
- package/src/runtime/targets/container/server.ts +0 -33
- package/src/runtime/targets/vps/deploy.ts +0 -223
- package/src/templates/skills/agentkit-deploy/SKILL.md +0 -52
- package/src/templates/skills/agentkit-integrations/SKILL.md +0 -98
package/src/runtime/database.ts
CHANGED
|
@@ -47,7 +47,7 @@ export async function applyCapsuleDatabaseMigrations(
|
|
|
47
47
|
): Promise<LocalDatabasePrepareResult["migrations"]> {
|
|
48
48
|
const database = capsule.config.storage.database;
|
|
49
49
|
|
|
50
|
-
if (!database || database.driver !== "
|
|
50
|
+
if (!database || database.driver !== "sqlite") {
|
|
51
51
|
return {
|
|
52
52
|
configured: false,
|
|
53
53
|
path: null,
|
|
@@ -125,7 +125,7 @@ export async function applyCapsuleDatabaseSchema(
|
|
|
125
125
|
): Promise<LocalDatabasePrepareResult["schema"]> {
|
|
126
126
|
const database = capsule.config.storage.database;
|
|
127
127
|
|
|
128
|
-
if (!database || database.driver !== "
|
|
128
|
+
if (!database || database.driver !== "sqlite" || !database.schema) {
|
|
129
129
|
return {
|
|
130
130
|
configured: false,
|
|
131
131
|
applied: false,
|
|
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { createServer as createHttpServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
|
|
4
4
|
import { createServer as createNetServer } from "node:net";
|
|
5
|
-
import { dirname,
|
|
5
|
+
import { dirname, relative, resolve } from "node:path";
|
|
6
6
|
import { Readable } from "node:stream";
|
|
7
7
|
|
|
8
8
|
import { openCapsuleStore, type ConversationRecord } from "../storage/sqlite";
|
|
@@ -423,6 +423,7 @@ async function authorizeDevRoute(
|
|
|
423
423
|
|
|
424
424
|
const env = await loadCapsuleEnv(capsule.root);
|
|
425
425
|
|
|
426
|
+
// Preserve the legacy deploy_not_ready code for clients handling missing local credentials.
|
|
426
427
|
if (kind === "admin") {
|
|
427
428
|
return authorizeBearerSecret(request, body, env.AGENTKIT_PRIVATE_TOKEN, {
|
|
428
429
|
missingCode: "deploy_not_ready",
|
|
@@ -438,15 +439,15 @@ async function authorizeDevRoute(
|
|
|
438
439
|
if (capsule.config.access.mode === "private") {
|
|
439
440
|
return authorizeBearerSecret(request, body, env.AGENTKIT_PRIVATE_TOKEN, {
|
|
440
441
|
missingCode: "deploy_not_ready",
|
|
441
|
-
missingMessage: "Private
|
|
442
|
-
unauthorizedMessage: "Missing or invalid
|
|
442
|
+
missingMessage: "Private access requires AGENTKIT_PRIVATE_TOKEN to be set.",
|
|
443
|
+
unauthorizedMessage: "Missing or invalid access token.",
|
|
443
444
|
});
|
|
444
445
|
}
|
|
445
446
|
|
|
446
447
|
return authorizeBearerSecret(request, body, env.AGENTKIT_ACCESS_TOKEN, {
|
|
447
448
|
missingCode: "deploy_not_ready",
|
|
448
|
-
missingMessage: "Token
|
|
449
|
-
unauthorizedMessage: "Missing or invalid
|
|
449
|
+
missingMessage: "Token access requires AGENTKIT_ACCESS_TOKEN to be set.",
|
|
450
|
+
unauthorizedMessage: "Missing or invalid access token.",
|
|
450
451
|
});
|
|
451
452
|
}
|
|
452
453
|
|
|
@@ -492,7 +493,6 @@ function readRequestAccessToken(request: Request, body: unknown): string {
|
|
|
492
493
|
|
|
493
494
|
const header =
|
|
494
495
|
request.headers.get("x-agentkit-access-token") ??
|
|
495
|
-
request.headers.get("x-agentkit-deploy-access-token") ??
|
|
496
496
|
"";
|
|
497
497
|
const token = header.startsWith("Bearer ") ? header.slice("Bearer ".length) : header;
|
|
498
498
|
if (token.trim()) {
|
|
@@ -900,7 +900,7 @@ async function flushDevChannelBuffer(
|
|
|
900
900
|
},
|
|
901
901
|
});
|
|
902
902
|
} catch {
|
|
903
|
-
// Local channel buffering is best-effort;
|
|
903
|
+
// Local channel buffering is best-effort; the buffer is not a durable delivery queue.
|
|
904
904
|
}
|
|
905
905
|
}
|
|
906
906
|
|
|
@@ -911,7 +911,7 @@ function unrefTimer(timer: ReturnType<typeof setTimeout>): void {
|
|
|
911
911
|
}
|
|
912
912
|
|
|
913
913
|
async function handleLocalFile(capsule: LoadedAgentCapsule, request: Request, rawKey: string): Promise<Response> {
|
|
914
|
-
if (capsule.config.storage.files?.driver !== "
|
|
914
|
+
if (capsule.config.storage.files?.driver !== "local") {
|
|
915
915
|
throw new AgentKitError("files_not_configured", "File storage is not configured for this Agent Capsule.");
|
|
916
916
|
}
|
|
917
917
|
|
package/src/runtime/env.ts
CHANGED
|
@@ -3,6 +3,17 @@ import { join } from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import { AgentKitError } from "./errors";
|
|
5
5
|
|
|
6
|
+
export function collectSecretValues(
|
|
7
|
+
scope: { secrets?: string[]; tools?: Array<{ secrets?: string[] }> } | undefined,
|
|
8
|
+
env: Record<string, string | undefined>,
|
|
9
|
+
): string[] {
|
|
10
|
+
const names = [...(scope?.secrets ?? []), ...(scope?.tools ?? []).flatMap((tool) => tool.secrets ?? [])];
|
|
11
|
+
return names.flatMap((name) => {
|
|
12
|
+
const value = env[name];
|
|
13
|
+
return value ? [value] : [];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
export async function loadCapsuleEnv(
|
|
7
18
|
root: string,
|
|
8
19
|
baseEnv: Record<string, string | undefined> = process.env,
|
package/src/runtime/improve.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { AgentKitError, isAgentKitError } from "./errors";
|
|
|
8
8
|
import { runAgentMessageFromCwd } from "./chat";
|
|
9
9
|
import { getConversationTraceFromCwd } from "./traces";
|
|
10
10
|
|
|
11
|
-
export type ImproveSource = "local"
|
|
11
|
+
export type ImproveSource = "local";
|
|
12
12
|
|
|
13
13
|
export type ImproveTraceMessage = {
|
|
14
14
|
role: "user" | "assistant" | "system" | "tool";
|
|
@@ -35,8 +35,6 @@ export type ImproveBundle = {
|
|
|
35
35
|
created_at: string;
|
|
36
36
|
source: ImproveSource;
|
|
37
37
|
since?: string;
|
|
38
|
-
deploy_id?: string;
|
|
39
|
-
evidence?: unknown;
|
|
40
38
|
traces: ImproveTracePacket[];
|
|
41
39
|
};
|
|
42
40
|
|
|
@@ -71,16 +69,6 @@ export type ImproveReplayResult = {
|
|
|
71
69
|
}>;
|
|
72
70
|
};
|
|
73
71
|
|
|
74
|
-
export type DeployImproveCollector = {
|
|
75
|
-
exportEvidence?(input: {
|
|
76
|
-
deployId: string;
|
|
77
|
-
since?: string;
|
|
78
|
-
conversationId?: string;
|
|
79
|
-
}): Promise<unknown | null>;
|
|
80
|
-
listConversations(): Promise<unknown>;
|
|
81
|
-
getTrace(conversationId: string): Promise<unknown>;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
72
|
export async function collectLocalImproveBundle(
|
|
85
73
|
cwd: string,
|
|
86
74
|
options: {
|
|
@@ -112,69 +100,6 @@ export async function collectLocalImproveBundle(
|
|
|
112
100
|
}, options.out);
|
|
113
101
|
}
|
|
114
102
|
|
|
115
|
-
export async function collectDeployImproveBundle(
|
|
116
|
-
cwd: string,
|
|
117
|
-
options: {
|
|
118
|
-
collector: DeployImproveCollector;
|
|
119
|
-
deployId: string;
|
|
120
|
-
since?: string;
|
|
121
|
-
conversationId?: string;
|
|
122
|
-
out?: string;
|
|
123
|
-
},
|
|
124
|
-
): Promise<ImproveCollectResult> {
|
|
125
|
-
const root = await findAgentCapsuleRoot(cwd);
|
|
126
|
-
|
|
127
|
-
if (options.collector.exportEvidence) {
|
|
128
|
-
const exported = await options.collector.exportEvidence({
|
|
129
|
-
deployId: options.deployId,
|
|
130
|
-
...(options.since ? { since: options.since } : {}),
|
|
131
|
-
...(options.conversationId ? { conversationId: options.conversationId } : {}),
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
if (exported) {
|
|
135
|
-
const normalized = normalizeDeployEvidenceExport(exported);
|
|
136
|
-
const traces = await tracePacketsFromDeployEvidenceExport({
|
|
137
|
-
collector: options.collector,
|
|
138
|
-
deployId: options.deployId,
|
|
139
|
-
evidence: normalized,
|
|
140
|
-
source: "deploy",
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
return writeImproveBundle(root, {
|
|
144
|
-
schema_version: 1,
|
|
145
|
-
created_at: normalized.created_at ?? new Date().toISOString(),
|
|
146
|
-
source: "deploy",
|
|
147
|
-
deploy_id: options.deployId,
|
|
148
|
-
...(options.since ? { since: options.since } : {}),
|
|
149
|
-
evidence: redactEvidenceValue(normalized.raw),
|
|
150
|
-
traces,
|
|
151
|
-
}, options.out);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const sinceDate = resolveSinceDate(options.since);
|
|
156
|
-
const summaries = options.conversationId
|
|
157
|
-
? [{ id: options.conversationId }]
|
|
158
|
-
: normalizeConversationSummaries(await options.collector.listConversations()).filter((conversation) =>
|
|
159
|
-
sinceDate && conversation.updated_at ? dateIsOnOrAfter(conversation.updated_at, sinceDate) : true,
|
|
160
|
-
);
|
|
161
|
-
const traces: ImproveTracePacket[] = [];
|
|
162
|
-
|
|
163
|
-
for (const summary of summaries) {
|
|
164
|
-
const trace = await options.collector.getTrace(summary.id);
|
|
165
|
-
traces.push(tracePacketFromPayload("deploy", summary.id, trace));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return writeImproveBundle(root, {
|
|
169
|
-
schema_version: 1,
|
|
170
|
-
created_at: new Date().toISOString(),
|
|
171
|
-
source: "deploy",
|
|
172
|
-
deploy_id: options.deployId,
|
|
173
|
-
...(options.since ? { since: options.since } : {}),
|
|
174
|
-
traces,
|
|
175
|
-
}, options.out);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
103
|
export async function generateImproveEvals(
|
|
179
104
|
cwd: string,
|
|
180
105
|
options: {
|
|
@@ -319,7 +244,6 @@ async function writeImproveBundle(root: string, bundle: ImproveBundle, out?: str
|
|
|
319
244
|
{
|
|
320
245
|
created_at: bundle.created_at,
|
|
321
246
|
source: bundle.source,
|
|
322
|
-
deploy_id: bundle.deploy_id ?? null,
|
|
323
247
|
trace_count: bundle.traces.length,
|
|
324
248
|
conversations: bundle.traces.map((trace) => ({
|
|
325
249
|
trace_id: trace.id,
|
|
@@ -329,7 +253,6 @@ async function writeImproveBundle(root: string, bundle: ImproveBundle, out?: str
|
|
|
329
253
|
messages: trace.trace.messages.length,
|
|
330
254
|
runs: Array.isArray(trace.trace.runs) ? trace.trace.runs.length : 0,
|
|
331
255
|
})),
|
|
332
|
-
evidence: summarizeImproveEvidence(bundle.evidence),
|
|
333
256
|
},
|
|
334
257
|
null,
|
|
335
258
|
2,
|
|
@@ -350,160 +273,6 @@ async function writeImproveBundle(root: string, bundle: ImproveBundle, out?: str
|
|
|
350
273
|
};
|
|
351
274
|
}
|
|
352
275
|
|
|
353
|
-
type NormalizedDeployEvidenceExport = {
|
|
354
|
-
created_at?: string;
|
|
355
|
-
deploy_id?: string;
|
|
356
|
-
traces: unknown[];
|
|
357
|
-
conversations: Array<{ id: string; updated_at?: string }>;
|
|
358
|
-
runs: unknown[];
|
|
359
|
-
raw: unknown;
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
function normalizeDeployEvidenceExport(payload: unknown): NormalizedDeployEvidenceExport {
|
|
363
|
-
const evidence = isRecord(payload) && isRecord(payload.evidence) ? payload.evidence : payload;
|
|
364
|
-
|
|
365
|
-
if (!isRecord(evidence)) {
|
|
366
|
-
throw new AgentKitError("deploy_improve_response_invalid", "Improve evidence export response was not an object.");
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const traces = Array.isArray(evidence.traces) ? evidence.traces : [];
|
|
370
|
-
const conversations = Array.isArray(evidence.conversations)
|
|
371
|
-
? evidence.conversations
|
|
372
|
-
.flatMap((conversation) => {
|
|
373
|
-
if (!isRecord(conversation)) {
|
|
374
|
-
return [];
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const id = readString(conversation, "id") ?? readString(conversation, "conversation_id");
|
|
378
|
-
|
|
379
|
-
if (!id) {
|
|
380
|
-
return [];
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const updatedAt = readString(conversation, "updated_at") ?? readString(conversation, "updatedAt");
|
|
384
|
-
return {
|
|
385
|
-
id,
|
|
386
|
-
...(updatedAt ? { updated_at: updatedAt } : {}),
|
|
387
|
-
};
|
|
388
|
-
})
|
|
389
|
-
: [];
|
|
390
|
-
|
|
391
|
-
return {
|
|
392
|
-
created_at: readString(evidence, "created_at") ?? readString(evidence, "createdAt"),
|
|
393
|
-
deploy_id: readString(evidence, "deploy_id") ?? readString(evidence, "deployId"),
|
|
394
|
-
traces,
|
|
395
|
-
conversations,
|
|
396
|
-
runs: Array.isArray(evidence.runs) ? evidence.runs : [],
|
|
397
|
-
raw: evidence,
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
async function tracePacketsFromDeployEvidenceExport(input: {
|
|
402
|
-
collector: DeployImproveCollector;
|
|
403
|
-
deployId: string;
|
|
404
|
-
evidence: NormalizedDeployEvidenceExport;
|
|
405
|
-
source: ImproveSource;
|
|
406
|
-
}): Promise<ImproveTracePacket[]> {
|
|
407
|
-
const traces: ImproveTracePacket[] = [];
|
|
408
|
-
const seenConversations = new Set<string>();
|
|
409
|
-
|
|
410
|
-
for (const rawTrace of input.evidence.traces) {
|
|
411
|
-
const trace = tracePacketFromPayload(input.source, input.deployId, rawTrace);
|
|
412
|
-
traces.push(trace);
|
|
413
|
-
seenConversations.add(trace.conversation_id);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
for (const conversation of input.evidence.conversations) {
|
|
417
|
-
if (seenConversations.has(conversation.id)) {
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
try {
|
|
422
|
-
const trace = await input.collector.getTrace(conversation.id);
|
|
423
|
-
const packet = tracePacketFromPayload(input.source, conversation.id, trace);
|
|
424
|
-
traces.push(packet);
|
|
425
|
-
seenConversations.add(packet.conversation_id);
|
|
426
|
-
} catch {
|
|
427
|
-
traces.push(syntheticEvidenceTrace(input.source, conversation.id, {
|
|
428
|
-
updated_at: conversation.updated_at,
|
|
429
|
-
reason: "conversation trace was not available from the hosted runtime",
|
|
430
|
-
}));
|
|
431
|
-
seenConversations.add(conversation.id);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
for (const run of input.evidence.runs) {
|
|
436
|
-
if (!isRecord(run)) {
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const conversationId = readString(run, "conversation_id") ?? readString(run, "conversationId");
|
|
441
|
-
|
|
442
|
-
if (conversationId && seenConversations.has(conversationId)) {
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
const runId = readString(run, "id") ?? readString(run, "run_id") ?? `run_${shortHash(JSON.stringify(run))}`;
|
|
447
|
-
traces.push(syntheticEvidenceTrace(input.source, conversationId ?? runId, {
|
|
448
|
-
title: readString(run, "title") ?? runId,
|
|
449
|
-
updated_at: readString(run, "updated_at") ?? readString(run, "updatedAt"),
|
|
450
|
-
raw: run,
|
|
451
|
-
}));
|
|
452
|
-
|
|
453
|
-
if (conversationId) {
|
|
454
|
-
seenConversations.add(conversationId);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return traces;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
function syntheticEvidenceTrace(
|
|
462
|
-
source: ImproveSource,
|
|
463
|
-
conversationId: string,
|
|
464
|
-
input: {
|
|
465
|
-
title?: string;
|
|
466
|
-
updated_at?: string;
|
|
467
|
-
reason?: string;
|
|
468
|
-
raw?: unknown;
|
|
469
|
-
},
|
|
470
|
-
): ImproveTracePacket {
|
|
471
|
-
const safeConversationId = redactEvalText(conversationId);
|
|
472
|
-
const title = input.title ? redactEvalText(input.title) : "Hosted evidence";
|
|
473
|
-
|
|
474
|
-
return {
|
|
475
|
-
id: `trace_${slugify(title)}_${shortHash(`${source}:${conversationId}:${JSON.stringify(input.raw ?? input.reason ?? "")}`)}`,
|
|
476
|
-
source,
|
|
477
|
-
conversation_id: safeConversationId,
|
|
478
|
-
title,
|
|
479
|
-
updated_at: input.updated_at,
|
|
480
|
-
trace: {
|
|
481
|
-
messages: [
|
|
482
|
-
{
|
|
483
|
-
role: "system",
|
|
484
|
-
content: redactEvalText(input.reason ?? "Hosted evidence did not include replayable conversation messages."),
|
|
485
|
-
...(input.updated_at ? { created_at: input.updated_at } : {}),
|
|
486
|
-
},
|
|
487
|
-
],
|
|
488
|
-
raw: redactEvidenceValue(input.raw ?? input.reason ?? null),
|
|
489
|
-
},
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function summarizeImproveEvidence(evidence: unknown): unknown {
|
|
494
|
-
if (!isRecord(evidence)) {
|
|
495
|
-
return evidence === undefined ? undefined : { available: true };
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return {
|
|
499
|
-
deploy_id: readString(evidence, "deploy_id") ?? readString(evidence, "deployId") ?? null,
|
|
500
|
-
runs: Array.isArray(evidence.runs) ? evidence.runs.length : 0,
|
|
501
|
-
conversations: Array.isArray(evidence.conversations) ? evidence.conversations.length : 0,
|
|
502
|
-
deliveries: Array.isArray(evidence.deliveries) ? evidence.deliveries.length : 0,
|
|
503
|
-
deploy_events: Array.isArray(evidence.deploy_events) ? evidence.deploy_events.length : 0,
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
|
|
507
276
|
async function readImproveBundle(path: string): Promise<ImproveBundle> {
|
|
508
277
|
const parsed = JSON.parse(await readFile(path, "utf8")) as unknown;
|
|
509
278
|
|
|
@@ -567,35 +336,6 @@ function resolveInsideCapsule(root: string, path: string, context: string): stri
|
|
|
567
336
|
return resolved;
|
|
568
337
|
}
|
|
569
338
|
|
|
570
|
-
function normalizeConversationSummaries(payload: unknown): Array<{ id: string; updated_at?: string }> {
|
|
571
|
-
const conversations = Array.isArray(payload)
|
|
572
|
-
? payload
|
|
573
|
-
: isRecord(payload) && Array.isArray(payload.conversations)
|
|
574
|
-
? payload.conversations
|
|
575
|
-
: null;
|
|
576
|
-
|
|
577
|
-
if (!conversations) {
|
|
578
|
-
throw new AgentKitError("deploy_conversation_response_invalid", "Conversation list response did not include conversations.");
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
return conversations.map((conversation) => {
|
|
582
|
-
if (!isRecord(conversation)) {
|
|
583
|
-
throw new AgentKitError("deploy_conversation_response_invalid", "Conversation list contained a non-object entry.");
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
const id = readString(conversation, "id") ?? readString(conversation, "conversation_id");
|
|
587
|
-
|
|
588
|
-
if (!id) {
|
|
589
|
-
throw new AgentKitError("deploy_conversation_response_invalid", "Conversation list entry did not include an id.");
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return {
|
|
593
|
-
id,
|
|
594
|
-
updated_at: readString(conversation, "updated_at") ?? readString(conversation, "updatedAt"),
|
|
595
|
-
};
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
|
|
599
339
|
function tracePacketFromPayload(source: ImproveSource, fallbackConversationId: string, payload: unknown): ImproveTracePacket {
|
|
600
340
|
const trace = normalizeTracePayload(fallbackConversationId, payload);
|
|
601
341
|
const safeConversationId = redactEvalText(trace.conversation_id);
|
|
@@ -628,7 +368,7 @@ function normalizeTracePayload(
|
|
|
628
368
|
runs?: unknown[];
|
|
629
369
|
} {
|
|
630
370
|
if (!isRecord(payload)) {
|
|
631
|
-
throw new AgentKitError("
|
|
371
|
+
throw new AgentKitError("conversation_response_invalid", "Conversation trace response was not an object.");
|
|
632
372
|
}
|
|
633
373
|
|
|
634
374
|
const conversationId = readString(payload, "id") ?? readString(payload, "conversation_id") ?? fallbackConversationId;
|
package/src/runtime/inspect.ts
CHANGED
|
@@ -4,11 +4,6 @@ import type { AgentChannel, AgentProvider, AgentRuntime, AccessMode } from "../i
|
|
|
4
4
|
import type { LoadedAgentCapsule } from "./config";
|
|
5
5
|
import { loadAgentCapsule } from "./config";
|
|
6
6
|
import { loadCapsuleEnv } from "./env";
|
|
7
|
-
import {
|
|
8
|
-
createManagedComposioTools,
|
|
9
|
-
managedComposioRequiredSecrets,
|
|
10
|
-
resolveManagedComposioIntegrations,
|
|
11
|
-
} from "./integrations/composio";
|
|
12
7
|
import { resolveKnowledgeConfig } from "./knowledge/config";
|
|
13
8
|
import { KNOWLEDGE_SEARCH_TOOL_NAME } from "./knowledge/tool";
|
|
14
9
|
import { resolveRuntimeTimeZone } from "./prompt-context";
|
|
@@ -27,7 +22,6 @@ export type AgentInspectState = {
|
|
|
27
22
|
};
|
|
28
23
|
prompt: string;
|
|
29
24
|
tools: string[];
|
|
30
|
-
integrations: AgentInspectIntegration[];
|
|
31
25
|
channels: AgentInspectChannel[];
|
|
32
26
|
transcription: {
|
|
33
27
|
enabled: boolean;
|
|
@@ -67,16 +61,9 @@ export type AgentInspectState = {
|
|
|
67
61
|
target: "bun";
|
|
68
62
|
database: "sqlite" | "none";
|
|
69
63
|
};
|
|
70
|
-
hosted: {
|
|
71
|
-
environment: "hosted";
|
|
72
|
-
target: "cloudflare";
|
|
73
|
-
database: "turso" | "none";
|
|
74
|
-
providerSupported: boolean;
|
|
75
|
-
};
|
|
76
64
|
aliases: ["ctx.db", "ctx.database", "ctx.storage.sql"];
|
|
77
65
|
};
|
|
78
66
|
secrets: Record<string, SecretState>;
|
|
79
|
-
managedSecrets: string[];
|
|
80
67
|
userSecrets: string[];
|
|
81
68
|
skills: AgentInspectSkills;
|
|
82
69
|
warnings: AgentInspectWarning[];
|
|
@@ -89,12 +76,6 @@ export type AgentInspectDatabase = {
|
|
|
89
76
|
schema: string | null;
|
|
90
77
|
migrations: string | null;
|
|
91
78
|
};
|
|
92
|
-
hosted: {
|
|
93
|
-
driver: "none" | "turso";
|
|
94
|
-
provisioning: "none" | "agentkit-managed";
|
|
95
|
-
schema: string | null;
|
|
96
|
-
migrations: string | null;
|
|
97
|
-
};
|
|
98
79
|
};
|
|
99
80
|
|
|
100
81
|
export type AgentInspectChannel = {
|
|
@@ -127,15 +108,6 @@ export type AgentInspectWarning = {
|
|
|
127
108
|
command?: string;
|
|
128
109
|
};
|
|
129
110
|
|
|
130
|
-
export type AgentInspectIntegration = {
|
|
131
|
-
name: string;
|
|
132
|
-
provider: "composio";
|
|
133
|
-
mode: "managed";
|
|
134
|
-
toolkits: string[];
|
|
135
|
-
tools: string[];
|
|
136
|
-
userId: string;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
111
|
export async function inspectAgentCapsule(
|
|
140
112
|
cwd = process.cwd(),
|
|
141
113
|
env: Record<string, string | undefined> = process.env,
|
|
@@ -151,10 +123,9 @@ export function buildInspectState(
|
|
|
151
123
|
): AgentInspectState {
|
|
152
124
|
const declaredSecrets = new Set(capsule.config.secrets);
|
|
153
125
|
const knowledge = resolveKnowledgeConfig(capsule.config);
|
|
154
|
-
const integrationTools = createManagedComposioTools(capsule.config);
|
|
155
126
|
const transcription = resolveTranscriptionConfig(capsule.config.transcription);
|
|
156
127
|
|
|
157
|
-
for (const tool of
|
|
128
|
+
for (const tool of capsule.config.tools ?? []) {
|
|
158
129
|
for (const secret of tool.secrets ?? []) {
|
|
159
130
|
declaredSecrets.add(secret);
|
|
160
131
|
}
|
|
@@ -174,10 +145,7 @@ export function buildInspectState(
|
|
|
174
145
|
declaredSecrets.add(transcription.secret);
|
|
175
146
|
}
|
|
176
147
|
|
|
177
|
-
const managedSecrets = managedCloudSecrets(capsule);
|
|
178
|
-
const managedSecretSet = new Set(managedSecrets);
|
|
179
148
|
const userSecrets = Array.from(declaredSecrets)
|
|
180
|
-
.filter((secret) => !managedSecretSet.has(secret))
|
|
181
149
|
.sort();
|
|
182
150
|
const secrets: Record<string, SecretState> = {};
|
|
183
151
|
|
|
@@ -202,16 +170,7 @@ export function buildInspectState(
|
|
|
202
170
|
}),
|
|
203
171
|
},
|
|
204
172
|
prompt: toCapsulePath(capsule.root, capsule.instructionsPath),
|
|
205
|
-
tools:
|
|
206
|
-
integrations: resolveManagedComposioIntegrations(capsule.config).map((integration) => ({
|
|
207
|
-
name: integration.name,
|
|
208
|
-
provider: integration.provider,
|
|
209
|
-
mode: integration.mode,
|
|
210
|
-
toolkits: integration.toolkits,
|
|
211
|
-
tools: integration.allowedTools,
|
|
212
|
-
userId: integration.userId,
|
|
213
|
-
confirmExternalWrites: integration.confirmExternalWrites !== false,
|
|
214
|
-
})),
|
|
173
|
+
tools: (capsule.config.tools ?? []).map((tool) => tool.name),
|
|
215
174
|
channels: (capsule.config.channels ?? []).map((channel) => ({
|
|
216
175
|
name: channel.name,
|
|
217
176
|
type: channel.type,
|
|
@@ -264,16 +223,9 @@ export function buildInspectState(
|
|
|
264
223
|
target: "bun",
|
|
265
224
|
database: capsule.storagePath ? "sqlite" : "none",
|
|
266
225
|
},
|
|
267
|
-
hosted: {
|
|
268
|
-
environment: "hosted",
|
|
269
|
-
target: "cloudflare",
|
|
270
|
-
database: database.hosted.driver === "turso" ? "turso" : "none",
|
|
271
|
-
providerSupported: true,
|
|
272
|
-
},
|
|
273
226
|
aliases: ["ctx.db", "ctx.database", "ctx.storage.sql"],
|
|
274
227
|
},
|
|
275
228
|
secrets,
|
|
276
|
-
managedSecrets,
|
|
277
229
|
userSecrets,
|
|
278
230
|
skills,
|
|
279
231
|
warnings,
|
|
@@ -287,8 +239,8 @@ function toCapsulePath(root: string, path: string): string {
|
|
|
287
239
|
|
|
288
240
|
function inspectDatabase(capsule: LoadedAgentCapsule): AgentInspectDatabase {
|
|
289
241
|
const database = capsule.config.storage.database;
|
|
290
|
-
const schema = database?.driver === "
|
|
291
|
-
const migrations = database?.driver === "
|
|
242
|
+
const schema = database?.driver === "sqlite" && database.schema ? database.schema : null;
|
|
243
|
+
const migrations = database?.driver === "sqlite" ? database.migrations ?? "migrations" : null;
|
|
292
244
|
|
|
293
245
|
return {
|
|
294
246
|
local: {
|
|
@@ -297,12 +249,6 @@ function inspectDatabase(capsule: LoadedAgentCapsule): AgentInspectDatabase {
|
|
|
297
249
|
schema,
|
|
298
250
|
migrations,
|
|
299
251
|
},
|
|
300
|
-
hosted: {
|
|
301
|
-
driver: database?.driver === "turso" ? "turso" : "none",
|
|
302
|
-
provisioning: database?.driver === "turso" ? "agentkit-managed" : "none",
|
|
303
|
-
schema,
|
|
304
|
-
migrations,
|
|
305
|
-
},
|
|
306
252
|
};
|
|
307
253
|
}
|
|
308
254
|
|
|
@@ -333,6 +279,15 @@ function inspectWarnings(
|
|
|
333
279
|
): AgentInspectWarning[] {
|
|
334
280
|
const warnings: AgentInspectWarning[] = [];
|
|
335
281
|
|
|
282
|
+
for (const channel of capsule.config.channels ?? []) {
|
|
283
|
+
if (channel.type === "discord" && channel.mode === "bot") {
|
|
284
|
+
warnings.push({
|
|
285
|
+
code: "discord_gateway_bridge_required",
|
|
286
|
+
message: `Discord channel "${channel.name}" uses bot mode, but AgentKit does not connect to the Gateway. Inviting the bot alone cannot deliver messages. Use interactions or run your own Gateway bridge to forward authenticated events.`,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
336
291
|
if (skills.status === "missing" || skills.status === "outdated") {
|
|
337
292
|
warnings.push({
|
|
338
293
|
code: "local_skills_outdated",
|
|
@@ -355,18 +310,3 @@ function inspectWarnings(
|
|
|
355
310
|
|
|
356
311
|
return warnings;
|
|
357
312
|
}
|
|
358
|
-
|
|
359
|
-
function managedCloudSecrets(capsule: LoadedAgentCapsule): string[] {
|
|
360
|
-
const secrets = new Set<string>();
|
|
361
|
-
|
|
362
|
-
if (capsule.config.storage.database?.driver === "turso") {
|
|
363
|
-
secrets.add("TURSO_AUTH_TOKEN");
|
|
364
|
-
secrets.add("TURSO_DATABASE_URL");
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
for (const secret of managedComposioRequiredSecrets(capsule.config)) {
|
|
368
|
-
secrets.add(secret);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return Array.from(secrets).sort();
|
|
372
|
-
}
|
|
@@ -271,7 +271,7 @@ async function ingestKnowledgeSource(
|
|
|
271
271
|
if (source.kind === "url") {
|
|
272
272
|
throw new AgentKitError(
|
|
273
273
|
"knowledge_source_unsupported",
|
|
274
|
-
"URL knowledge
|
|
274
|
+
"URL knowledge ingestion is not supported. Local Knowledge currently supports .md, .txt, and .csv files.",
|
|
275
275
|
);
|
|
276
276
|
}
|
|
277
277
|
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import type { AgentTool } from "../../index";
|
|
2
2
|
import type { LoadedAgentCapsule } from "../config";
|
|
3
3
|
import { resolveKnowledgeConfig } from "./config";
|
|
4
|
-
import { searchKnowledge } from "./retrieve";
|
|
4
|
+
import { searchKnowledge, type KnowledgeSearchResult } from "./retrieve";
|
|
5
5
|
|
|
6
6
|
export const KNOWLEDGE_SEARCH_TOOL_NAME = "agentkit_search_knowledge";
|
|
7
7
|
|
|
8
|
+
// Only the actual built-in tool may expose retrieval facts to the model.
|
|
9
|
+
const knowledgeTools = new WeakSet<AgentTool>();
|
|
10
|
+
|
|
11
|
+
export function knowledgeModelText(tool: AgentTool, output: unknown): string | undefined {
|
|
12
|
+
if (!knowledgeTools.has(tool)) return undefined;
|
|
13
|
+
const { results } = output as { results: Array<Pick<KnowledgeSearchResult, "content" | "source">> };
|
|
14
|
+
return results.map(({ content, source }) => {
|
|
15
|
+
const reference = [source.path, source.title, source.section, source.locator].filter(Boolean).join(" > ");
|
|
16
|
+
return `${content}\nSource: ${reference}`;
|
|
17
|
+
}).join("\n\n") || "No relevant Knowledge results found.";
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
export function createKnowledgeSearchTool(capsule: LoadedAgentCapsule): AgentTool | null {
|
|
9
21
|
const knowledge = resolveKnowledgeConfig(capsule.config);
|
|
10
22
|
|
|
@@ -12,7 +24,7 @@ export function createKnowledgeSearchTool(capsule: LoadedAgentCapsule): AgentToo
|
|
|
12
24
|
return null;
|
|
13
25
|
}
|
|
14
26
|
|
|
15
|
-
|
|
27
|
+
const tool: AgentTool = {
|
|
16
28
|
name: KNOWLEDGE_SEARCH_TOOL_NAME,
|
|
17
29
|
description: "Search the Agent Capsule's configured Knowledge sources for business-specific facts.",
|
|
18
30
|
visibility: "internal",
|
|
@@ -61,4 +73,6 @@ export function createKnowledgeSearchTool(capsule: LoadedAgentCapsule): AgentToo
|
|
|
61
73
|
};
|
|
62
74
|
},
|
|
63
75
|
};
|
|
76
|
+
knowledgeTools.add(tool);
|
|
77
|
+
return tool;
|
|
64
78
|
}
|
|
@@ -181,7 +181,7 @@ export async function searchLocalKnowledgeVectorRows(options: {
|
|
|
181
181
|
const result = await client.execute({
|
|
182
182
|
sql: `
|
|
183
183
|
SELECT
|
|
184
|
-
c.
|
|
184
|
+
c.chunk_id AS chunk_id,
|
|
185
185
|
c.source_id AS source_id,
|
|
186
186
|
c.content AS content,
|
|
187
187
|
c.title AS title,
|