@theokit/cli 3.0.2 → 4.0.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +257 -0
  2. package/LICENSE +2 -2
  3. package/README.md +13 -0
  4. package/dist/bin/theokit.cjs +59 -28
  5. package/dist/bin/theokit.cjs.map +1 -1
  6. package/dist/bin/theokit.js +59 -28
  7. package/dist/bin/theokit.js.map +1 -1
  8. package/dist/index.cjs +59 -28
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +127 -10
  11. package/dist/index.d.ts +127 -10
  12. package/dist/index.js +59 -28
  13. package/dist/index.js.map +1 -1
  14. package/package.json +19 -16
  15. package/templates/chatbot/.env.example +14 -0
  16. package/templates/chatbot/README.md +34 -0
  17. package/templates/chatbot/package.json +20 -0
  18. package/templates/chatbot/src/index.ts +88 -0
  19. package/templates/chatbot/tsconfig.json +12 -0
  20. package/templates/minimal/README.md +1 -1
  21. package/templates/multi-agent/.env.example +14 -0
  22. package/templates/multi-agent/README.md +33 -0
  23. package/templates/multi-agent/package.json +20 -0
  24. package/templates/multi-agent/src/index.ts +90 -0
  25. package/templates/multi-agent/tsconfig.json +12 -0
  26. package/templates/rag-agent/.env.example +14 -0
  27. package/templates/rag-agent/README.md +34 -0
  28. package/templates/rag-agent/package.json +21 -0
  29. package/templates/rag-agent/src/index.ts +115 -0
  30. package/templates/rag-agent/tsconfig.json +12 -0
  31. package/templates/telegram-bot/README.md +4 -4
  32. package/templates/telegram-bot/package.json +2 -2
  33. package/templates/telegram-bot/src/index.ts +2 -2
  34. package/templates/workflow-automation/.env.example +14 -0
  35. package/templates/workflow-automation/README.md +33 -0
  36. package/templates/workflow-automation/package.json +20 -0
  37. package/templates/workflow-automation/src/index.ts +86 -0
  38. package/templates/workflow-automation/tsconfig.json +12 -0
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { GatewayRunner } from "@theokit/gateway";
9
9
  import { TelegramAdapter } from "@theokit/gateway-telegram";
10
- import { createAgentFactory } from "@theokit/sdk";
10
+ import { AgentFactory } from "@theokit/sdk";
11
11
  import { Bot } from "grammy";
12
12
 
13
13
  const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
@@ -21,7 +21,7 @@ if (TELEGRAM_BOT_TOKEN === undefined || TELEGRAM_BOT_TOKEN.length === 0) {
21
21
  const API_KEY = process.env.THEOKIT_API_KEY ?? "local";
22
22
  const MODEL = process.env.AGENT_MODEL ?? "anthropic/claude-3-5-sonnet-latest";
23
23
 
24
- const factory = createAgentFactory({
24
+ const factory = AgentFactory.create({
25
25
  apiKey: API_KEY,
26
26
  model: { id: MODEL },
27
27
  local: { cwd: process.cwd() },
@@ -0,0 +1,14 @@
1
+ # Copy to .env and fill in:
2
+ #
3
+ # THEOKIT_API_KEY — any non-empty string. Used by the SDK for cloud
4
+ # catalog reads; not strictly required for chat against Anthropic/OpenAI
5
+ # directly. Set to "local" if you're not using Theo cloud.
6
+ THEOKIT_API_KEY=local
7
+
8
+ # Provider key — pick ONE. The SDK auto-detects which one is set.
9
+ # ANTHROPIC_API_KEY=sk-ant-...
10
+ # OPENAI_API_KEY=sk-...
11
+ # OPENROUTER_API_KEY=sk-or-...
12
+
13
+ # Override the model (default: anthropic/claude-3-5-sonnet-latest).
14
+ # AGENT_MODEL=openai/gpt-4o-mini
@@ -0,0 +1,33 @@
1
+ # {{projectName}}
2
+
3
+ A scheduled, multi-step pipeline, scaffolded by `theokit init`.
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ pnpm install
9
+ cp .env.example .env
10
+ pnpm dev
11
+ ```
12
+
13
+ ## What this does
14
+
15
+ 1. `Workflow.create(…).then(…).commit()` builds a three-step pipeline:
16
+ `fn("collect")` → `agentStep("analyse")` → `fn("format")`.
17
+ 2. Runs it once so you can see the output.
18
+ 3. Hands the SAME committed workflow to `Cron.create({ cron, workflow })`.
19
+
20
+ The workflow is the unit of work; cron only decides when. `agentStep` runs the
21
+ agent and feeds it the previous step's output — there is no stream to drain by
22
+ hand, which is the difference between this and calling `agent.send` in a loop.
23
+
24
+ ## Requirements
25
+
26
+ - Node 22.12+.
27
+ - One of: Anthropic / OpenAI / OpenRouter API key.
28
+
29
+ ## Next steps
30
+
31
+ - `WORKFLOW_CRON="@hourly"` — five-field POSIX cron or a shorthand.
32
+ - Replace `fn("collect")` with a real fetch; the other two steps do not change.
33
+ - `.parallel(…)`, `.branch(…)`, `.foreach(…)` for fan-out and conditionals.
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "{{projectName}}",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "tsx --env-file=.env src/index.ts",
8
+ "start": "tsx --env-file=.env src/index.ts"
9
+ },
10
+ "dependencies": {
11
+ "@theokit/sdk": "^{{sdkVersion}}"
12
+ },
13
+ "devDependencies": {
14
+ "tsx": "^4.19.0",
15
+ "typescript": "^5.8.0"
16
+ },
17
+ "engines": {
18
+ "node": ">=22.12.0"
19
+ }
20
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * {{projectName}} — a scheduled, multi-step pipeline.
3
+ *
4
+ * Builds a real `Workflow` (fetch -> analyse -> format), runs it once so you can
5
+ * see the output, then hands the SAME committed workflow to `Cron` to run on a
6
+ * schedule. The workflow is the unit of work; cron only decides when.
7
+ */
8
+
9
+ import { Agent, agentStep, Cron, fn, Workflow } from "@theokit/sdk";
10
+
11
+ const API_KEY = process.env.THEOKIT_API_KEY ?? "local";
12
+ const MODEL = process.env.AGENT_MODEL ?? "anthropic/claude-3-5-sonnet-latest";
13
+ /** Five-field POSIX cron, or a shorthand like `@hourly`. */
14
+ const SCHEDULE = process.env.WORKFLOW_CRON ?? "*/5 * * * *";
15
+
16
+ async function main(): Promise<void> {
17
+ const analyst = await Agent.create({
18
+ agentId: "workflow-analyst",
19
+ apiKey: API_KEY,
20
+ model: { id: MODEL },
21
+ systemPrompt:
22
+ "You read a system health snapshot and reply with three bullet points: " +
23
+ "what is fine, what to watch, and what to act on now. No preamble.",
24
+ local: { cwd: process.cwd() },
25
+ });
26
+
27
+ try {
28
+ const pipeline = Workflow.create({ name: "health-report" })
29
+ // Step 1 — plain function. In production this reads an API or a database.
30
+ .then(
31
+ fn("collect", () => {
32
+ const at = new Date().toISOString();
33
+ return `[${at}] CPU 45% · Memory 72% · Requests 1.2k/s · Errors 0.3%`;
34
+ }),
35
+ )
36
+ // Step 2 — an agent step. The SDK runs the agent and feeds it the previous
37
+ // step's output; there is no stream to drain by hand.
38
+ .then(
39
+ agentStep("analyse", analyst, (snapshot) => `Analyse this snapshot:\n${String(snapshot)}`),
40
+ )
41
+ // Step 3 — shape the result. Keeping formatting OUT of the agent step is
42
+ // what lets you change the report without touching the prompt.
43
+ .then(fn("format", (report) => `--- health report ---\n${String(report)}\n---`))
44
+ .commit();
45
+
46
+ console.log("Running the pipeline once...\n");
47
+ const run = await pipeline.run({});
48
+ if (run.status === "completed") {
49
+ console.log(String(run.output));
50
+ } else {
51
+ console.error(`pipeline ${run.status}`);
52
+ process.exitCode = 1;
53
+ }
54
+
55
+ // Same committed workflow, now on a schedule. The field is `cron` — and a
56
+ // workflow target takes no `message`, because the workflow IS the work.
57
+ const job = await Cron.create({
58
+ name: "health-report",
59
+ cron: SCHEDULE,
60
+ workflow: pipeline,
61
+ apiKey: API_KEY,
62
+ });
63
+ console.log(`\nScheduled ${job.name ?? job.id} at "${job.cron}" (${job.timezone ?? "UTC"}).`);
64
+
65
+ await Cron.start({ apiKey: API_KEY });
66
+ console.log("Scheduler running. Ctrl+C to stop.");
67
+
68
+ // Wire shutdown ONCE, and await the stop: exiting while the scheduler still
69
+ // holds timers is what leaves a half-run behind.
70
+ process.on("SIGINT", () => {
71
+ void (async () => {
72
+ await Cron.stop();
73
+ await analyst.dispose();
74
+ process.exit(0);
75
+ })();
76
+ });
77
+ } catch (cause) {
78
+ await analyst.dispose();
79
+ throw cause;
80
+ }
81
+ }
82
+
83
+ main().catch((cause) => {
84
+ console.error("workflow failed:", cause instanceof Error ? cause.message : cause);
85
+ process.exit(1);
86
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "lib": ["ES2023", "ESNext.Disposable"]
10
+ },
11
+ "include": ["src/**/*.ts"]
12
+ }