@andreprado/agentkit 0.1.0-alpha.10
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 +69 -0
- package/bin/agentkit.mjs +23 -0
- package/docs/guides/add-channel.md +114 -0
- package/docs/guides/add-knowledge.md +134 -0
- package/docs/guides/add-tool.md +342 -0
- package/docs/guides/agentkit-skills-architecture.md +471 -0
- package/docs/guides/channel-security.md +81 -0
- package/docs/guides/channels-implementation-map.md +243 -0
- package/docs/guides/channels-production-handoff.md +102 -0
- package/docs/guides/connect-telegram.md +110 -0
- package/docs/guides/connect-whatsapp-zapster.md +119 -0
- package/docs/guides/create-agent.md +220 -0
- package/docs/guides/prepare-deploy.md +209 -0
- package/docs/guides/run-evals.md +179 -0
- package/docs/guides/security-rules.md +156 -0
- package/docs/guides/use-provider.md +140 -0
- package/docs/llms-full.txt +876 -0
- package/docs/llms.txt +83 -0
- package/docs/portable-deploy-release-checklist.md +41 -0
- package/package.json +47 -0
- package/src/cli/args.ts +36 -0
- package/src/cli/cloud-client.ts +265 -0
- package/src/cli/commands/channels.ts +810 -0
- package/src/cli/commands/knowledge.ts +136 -0
- package/src/cli/constants.ts +4 -0
- package/src/cli/deploy-chat-ui.ts +392 -0
- package/src/cli/deploy-readiness.ts +348 -0
- package/src/cli/flags.ts +162 -0
- package/src/cli/help.ts +184 -0
- package/src/cli/index.ts +1276 -0
- package/src/cli/process.ts +31 -0
- package/src/cloud/artifact.ts +139 -0
- package/src/cloud/client.ts +79 -0
- package/src/cloud/contracts.ts +63 -0
- package/src/cloud/index.ts +3 -0
- package/src/create-project.ts +177 -0
- package/src/index.ts +408 -0
- package/src/providers/index.ts +25 -0
- package/src/providers/pi.ts +286 -0
- package/src/providers/test.ts +133 -0
- package/src/providers/types.ts +34 -0
- package/src/runtime/build.ts +43 -0
- package/src/runtime/channel-buffer.ts +30 -0
- package/src/runtime/channel-test-harness.ts +112 -0
- package/src/runtime/channels/telegram.ts +360 -0
- package/src/runtime/channels/website.ts +132 -0
- package/src/runtime/channels/whatsapp-meta.ts +71 -0
- package/src/runtime/channels/whatsapp-zapster.ts +278 -0
- package/src/runtime/channels.ts +138 -0
- package/src/runtime/chat.ts +218 -0
- package/src/runtime/config.ts +684 -0
- package/src/runtime/conversations.ts +38 -0
- package/src/runtime/core/deploy-state.ts +54 -0
- package/src/runtime/core/manifest.ts +213 -0
- package/src/runtime/core/targets.ts +133 -0
- package/src/runtime/database.ts +256 -0
- package/src/runtime/db-commands.ts +167 -0
- package/src/runtime/deploy-readiness.ts +105 -0
- package/src/runtime/deploy.ts +1 -0
- package/src/runtime/dev-server.ts +1247 -0
- package/src/runtime/docs.ts +36 -0
- package/src/runtime/env.ts +152 -0
- package/src/runtime/errors.ts +13 -0
- package/src/runtime/evals.ts +509 -0
- package/src/runtime/inspect.ts +203 -0
- package/src/runtime/knowledge/chunk.ts +333 -0
- package/src/runtime/knowledge/config.ts +135 -0
- package/src/runtime/knowledge/embeddings.ts +133 -0
- package/src/runtime/knowledge/ingest.ts +521 -0
- package/src/runtime/knowledge/prompt-policy.ts +30 -0
- package/src/runtime/knowledge/retrieve.ts +283 -0
- package/src/runtime/knowledge/schema.ts +56 -0
- package/src/runtime/knowledge/tool.ts +64 -0
- package/src/runtime/knowledge/vector.ts +258 -0
- package/src/runtime/runtime-contract.ts +93 -0
- package/src/runtime/spec.ts +152 -0
- package/src/runtime/sync.ts +144 -0
- package/src/runtime/targets/cloudflare/build.ts +2517 -0
- package/src/runtime/targets/container/build.ts +146 -0
- package/src/runtime/targets/container/server.ts +33 -0
- package/src/runtime/targets/vps/deploy.ts +206 -0
- package/src/runtime/tool-runner.ts +65 -0
- package/src/runtime/tools.ts +470 -0
- package/src/runtime/traces.ts +41 -0
- package/src/storage/sqlite.ts +1118 -0
- package/src/templates/blank.ts +394 -0
- package/src/templates/dentista.ts +1003 -0
- package/src/templates/index.ts +33 -0
- package/src/templates/skills/agentkit-build-agent/SKILL.md +51 -0
- package/src/templates/skills/agentkit-build-agent/templates/appointment-intake.instructions.md +20 -0
- package/src/templates/skills/agentkit-build-agent/templates/sales-qualifier.instructions.md +17 -0
- package/src/templates/skills/agentkit-build-agent/templates/support-agent.instructions.md +16 -0
- package/src/templates/skills/agentkit-capsule/SKILL.md +62 -0
- package/src/templates/skills/agentkit-capsule/references/docs-router.md +15 -0
- package/src/templates/skills/agentkit-channels/SKILL.md +62 -0
- package/src/templates/skills/agentkit-channels/references/channel-buffering.md +58 -0
- package/src/templates/skills/agentkit-channels/references/channel-debugging.md +41 -0
- package/src/templates/skills/agentkit-channels/references/telegram.md +38 -0
- package/src/templates/skills/agentkit-channels/references/whatsapp-zapster.md +44 -0
- package/src/templates/skills/agentkit-database/SKILL.md +45 -0
- package/src/templates/skills/agentkit-database/templates/appointments.schema.sql +15 -0
- package/src/templates/skills/agentkit-database/templates/leads.schema.sql +17 -0
- package/src/templates/skills/agentkit-deploy/SKILL.md +44 -0
- package/src/templates/skills/agentkit-evals/SKILL.md +60 -0
- package/src/templates/skills/agentkit-evals/templates/multi-turn.eval.md +22 -0
- package/src/templates/skills/agentkit-evals/templates/no-leak.eval.md +14 -0
- package/src/templates/skills/agentkit-evals/templates/smoke.eval.md +14 -0
- package/src/templates/skills/agentkit-evals/templates/tool-call.eval.md +18 -0
- package/src/templates/skills/agentkit-knowledge/SKILL.md +40 -0
- package/src/templates/skills/agentkit-knowledge/templates/faq.md +14 -0
- package/src/templates/skills/agentkit-knowledge/templates/policies.md +14 -0
- package/src/templates/skills/agentkit-knowledge/templates/prices.csv +3 -0
- package/src/templates/skills/agentkit-prompts/SKILL.md +45 -0
- package/src/templates/skills/agentkit-prompts/templates/knowledge-grounded-faq.instructions.md +11 -0
- package/src/templates/skills/agentkit-provider/SKILL.md +57 -0
- package/src/templates/skills/agentkit-security/SKILL.md +55 -0
- package/src/templates/skills/agentkit-tools/SKILL.md +36 -0
- package/src/templates/skills/agentkit-tools/examples/database-write.tool.md +35 -0
- package/src/templates/skills/agentkit-tools/examples/eval-safe-external-action.tool.md +37 -0
- package/src/templates/skills/agentkit-tools/examples/lookup-order.tool.md +46 -0
- package/src/templates/skills/agentkit-troubleshooting/SKILL.md +52 -0
- package/src/templates/support.ts +401 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { access, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { delimiter, join, relative, resolve } from "node:path";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
import { loadAgentCapsule } from "./config";
|
|
7
|
+
import { openPreparedCapsuleStore } from "./database";
|
|
8
|
+
import { AgentKitError } from "./errors";
|
|
9
|
+
|
|
10
|
+
export type DbMigrateResult = {
|
|
11
|
+
root: string;
|
|
12
|
+
databasePath: string;
|
|
13
|
+
migrationsPath: string | null;
|
|
14
|
+
migrationsApplied: string[];
|
|
15
|
+
migrationsSkipped: string[];
|
|
16
|
+
schemaPath: string | null;
|
|
17
|
+
schemaApplied: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type DbResetResult = DbMigrateResult & {
|
|
21
|
+
resetPath: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type DbSeedResult = DbMigrateResult & {
|
|
25
|
+
seedPath: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type DbShellResult =
|
|
29
|
+
| {
|
|
30
|
+
opened: true;
|
|
31
|
+
databasePath: string;
|
|
32
|
+
exitCode: number;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
opened: false;
|
|
36
|
+
databasePath: string;
|
|
37
|
+
command: string;
|
|
38
|
+
message: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export async function migrateLocalDatabase(cwd = process.cwd()): Promise<DbMigrateResult> {
|
|
42
|
+
const capsule = await loadAgentCapsule(cwd);
|
|
43
|
+
const prepared = await openPreparedCapsuleStore(capsule);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
return {
|
|
47
|
+
root: capsule.root,
|
|
48
|
+
databasePath: prepared.databasePath,
|
|
49
|
+
migrationsPath: prepared.migrations.path,
|
|
50
|
+
migrationsApplied: prepared.migrations.applied,
|
|
51
|
+
migrationsSkipped: prepared.migrations.skipped,
|
|
52
|
+
schemaPath: prepared.schema.path,
|
|
53
|
+
schemaApplied: prepared.schema.applied,
|
|
54
|
+
};
|
|
55
|
+
} finally {
|
|
56
|
+
prepared.store.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function resetLocalDatabase(cwd = process.cwd()): Promise<DbResetResult> {
|
|
61
|
+
const capsule = await loadAgentCapsule(cwd);
|
|
62
|
+
const databasePath = requireLocalDatabasePath(capsule.storagePath);
|
|
63
|
+
|
|
64
|
+
await rm(databasePath, { force: true });
|
|
65
|
+
const migrated = await migrateLocalDatabase(capsule.root);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...migrated,
|
|
69
|
+
resetPath: databasePath,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function seedLocalDatabase(cwd = process.cwd(), seedFile = "seed.sql"): Promise<DbSeedResult> {
|
|
74
|
+
const capsule = await loadAgentCapsule(cwd);
|
|
75
|
+
const seedPath = resolve(capsule.root, seedFile);
|
|
76
|
+
|
|
77
|
+
let seedSql: string;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
seedSql = await readFile(seedPath, "utf8");
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new AgentKitError(
|
|
83
|
+
"database_schema_error",
|
|
84
|
+
`Could not read seed SQL file at ${relative(capsule.root, seedPath)}. Use agentkit db seed --file <path>.`,
|
|
85
|
+
{ cause: error },
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const prepared = await openPreparedCapsuleStore(capsule);
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
prepared.store.applyApplicationSchema(seedSql);
|
|
93
|
+
return {
|
|
94
|
+
root: capsule.root,
|
|
95
|
+
databasePath: prepared.databasePath,
|
|
96
|
+
migrationsPath: prepared.migrations.path,
|
|
97
|
+
migrationsApplied: prepared.migrations.applied,
|
|
98
|
+
migrationsSkipped: prepared.migrations.skipped,
|
|
99
|
+
schemaPath: prepared.schema.path,
|
|
100
|
+
schemaApplied: prepared.schema.applied,
|
|
101
|
+
seedPath,
|
|
102
|
+
};
|
|
103
|
+
} finally {
|
|
104
|
+
prepared.store.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function openLocalDatabaseShell(cwd = process.cwd()): Promise<DbShellResult> {
|
|
109
|
+
const migrated = await migrateLocalDatabase(cwd);
|
|
110
|
+
const sqlite3 = await findExecutable("sqlite3");
|
|
111
|
+
const command = `sqlite3 ${JSON.stringify(migrated.databasePath)}`;
|
|
112
|
+
|
|
113
|
+
if (!sqlite3) {
|
|
114
|
+
return {
|
|
115
|
+
opened: false,
|
|
116
|
+
databasePath: migrated.databasePath,
|
|
117
|
+
command,
|
|
118
|
+
message: "sqlite3 was not found on PATH. Install sqlite3, then run the command below.",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const exitCode = await runInteractiveCommand(sqlite3, [migrated.databasePath]);
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
opened: true,
|
|
126
|
+
databasePath: migrated.databasePath,
|
|
127
|
+
exitCode,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function runInteractiveCommand(command: string, args: string[]): Promise<number> {
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const child = spawn(command, args, {
|
|
134
|
+
stdio: "inherit",
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
child.once("error", reject);
|
|
138
|
+
child.once("close", (code) => resolve(code ?? 1));
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function requireLocalDatabasePath(storagePath: string | undefined): string {
|
|
143
|
+
if (!storagePath) {
|
|
144
|
+
throw new AgentKitError("invalid_config", "Local database commands require storage.path or storage.driver: agentkit.");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return storagePath;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function findExecutable(name: string): Promise<string | null> {
|
|
151
|
+
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
152
|
+
if (!directory) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const candidate = join(directory, name);
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
await access(candidate, constants.X_OK);
|
|
160
|
+
return candidate;
|
|
161
|
+
} catch {
|
|
162
|
+
// Keep looking.
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import { loadAgentCapsule } from "./config";
|
|
4
|
+
import { buildSharedAgentManifest } from "./core/manifest";
|
|
5
|
+
import { listCapsuleEnv } from "./env";
|
|
6
|
+
|
|
7
|
+
export type DeployReadinessSecretSource = {
|
|
8
|
+
dotenv: boolean;
|
|
9
|
+
environment: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type DeployReadinessContext = {
|
|
13
|
+
root: string;
|
|
14
|
+
projectName: string;
|
|
15
|
+
projectId: string;
|
|
16
|
+
target: "cloudflare";
|
|
17
|
+
runtime: "edge" | "local";
|
|
18
|
+
provider: {
|
|
19
|
+
name: string;
|
|
20
|
+
model: string;
|
|
21
|
+
};
|
|
22
|
+
accessMode: "private" | "token" | "public";
|
|
23
|
+
requiredSecrets: string[];
|
|
24
|
+
userManagedSecrets: string[];
|
|
25
|
+
agentKitManagedSecrets: string[];
|
|
26
|
+
localSecrets: Record<string, DeployReadinessSecretSource>;
|
|
27
|
+
knowledge: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
sourceCount: number;
|
|
30
|
+
embeddingProvider: string;
|
|
31
|
+
databaseDriver: "none" | "turso";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export async function loadDeployReadinessContext(
|
|
36
|
+
cwd = process.cwd(),
|
|
37
|
+
env: Record<string, string | undefined> = process.env,
|
|
38
|
+
): Promise<DeployReadinessContext> {
|
|
39
|
+
const capsule = await loadAgentCapsule(cwd);
|
|
40
|
+
const manifest = buildSharedAgentManifest(capsule);
|
|
41
|
+
const dotenvNames = new Set(await listCapsuleEnv(capsule.root));
|
|
42
|
+
const requiredSecrets = manifest.secrets;
|
|
43
|
+
const localSecrets: Record<string, DeployReadinessSecretSource> = {};
|
|
44
|
+
|
|
45
|
+
for (const name of requiredSecrets) {
|
|
46
|
+
const source = {
|
|
47
|
+
dotenv: dotenvNames.has(name),
|
|
48
|
+
environment: Boolean(env[name]),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (source.dotenv || source.environment) {
|
|
52
|
+
localSecrets[name] = source;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const agentKitManagedSecrets = requiredSecrets.filter((name) =>
|
|
57
|
+
isAgentKitManagedDeploySecret(name, {
|
|
58
|
+
accessMode: capsule.config.access.mode,
|
|
59
|
+
databaseDriver: manifest.storage.database.driver,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
const managed = new Set(agentKitManagedSecrets);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
root: capsule.root,
|
|
66
|
+
projectName: capsule.config.name,
|
|
67
|
+
projectId: stableCloudProjectId(capsule.config.name),
|
|
68
|
+
target: "cloudflare",
|
|
69
|
+
runtime: capsule.config.runtime,
|
|
70
|
+
provider: {
|
|
71
|
+
name: capsule.config.provider.name,
|
|
72
|
+
model: capsule.config.provider.model,
|
|
73
|
+
},
|
|
74
|
+
accessMode: capsule.config.access.mode,
|
|
75
|
+
requiredSecrets,
|
|
76
|
+
userManagedSecrets: requiredSecrets.filter((name) => !managed.has(name)),
|
|
77
|
+
agentKitManagedSecrets,
|
|
78
|
+
localSecrets,
|
|
79
|
+
knowledge: {
|
|
80
|
+
enabled: manifest.knowledge.enabled,
|
|
81
|
+
sourceCount: manifest.knowledge.sources.length,
|
|
82
|
+
embeddingProvider: manifest.knowledge.embedding.provider,
|
|
83
|
+
databaseDriver: manifest.storage.database.driver,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function stableCloudProjectId(name: string): string {
|
|
89
|
+
return `proj_${createHash("sha256").update(name).digest("hex").slice(0, 16)}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isAgentKitManagedDeploySecret(
|
|
93
|
+
name: string,
|
|
94
|
+
context: { accessMode: DeployReadinessContext["accessMode"]; databaseDriver: "none" | "turso" },
|
|
95
|
+
): boolean {
|
|
96
|
+
if (context.databaseDriver === "turso" && (name === "TURSO_DATABASE_URL" || name === "TURSO_AUTH_TOKEN")) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (context.accessMode === "private" && name === "AGENTKIT_PRIVATE_TOKEN") {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../cloud";
|