Compare commits

..

4 Commits

Author SHA1 Message Date
Peter Steinberger
05b6b95f50
docs: improve cookbook README 2026-04-30 01:00:57 +01:00
Peter Steinberger
2ce294c83e
style: polish cookbook web examples 2026-04-29 22:46:59 +01:00
Peter Steinberger
57413aeb3d
feat: add standalone sdk examples 2026-04-29 22:36:12 +01:00
Peter Steinberger
f1cb5bed7c
feat: build sdk cookbook 2026-04-29 22:01:18 +01:00
9 changed files with 1483 additions and 1376 deletions

View File

@ -2,7 +2,6 @@ import { cancelRunRecipe } from "../../../recipes/cancel-a-run/index.js";
import { modelStatusRecipe } from "../../../recipes/model-status/index.js";
import { reuseSessionRecipe } from "../../../recipes/reuse-session/index.js";
import { runAgentRecipe } from "../../../recipes/run-an-agent/index.js";
import { redactSensitiveOutput } from "../../../recipes/_shared/run-main.js";
import { streamEventsRecipe } from "../../../recipes/stream-events/index.js";
function usage(): string {
@ -39,11 +38,7 @@ async function main(argv: string[]): Promise<unknown> {
try {
const result = await main(process.argv.slice(2));
if (typeof result === "string") {
process.stdout.write(`${result}\n`);
} else {
console.log(JSON.stringify(redactSensitiveOutput(result), null, 2));
}
console.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;

View File

@ -3,14 +3,14 @@
"version": "0.0.0",
"private": true,
"type": "module",
"packageManager": "pnpm@10.23.0",
"scripts": {
"check": "pnpm format:check && pnpm typecheck && pnpm lint && pnpm test && pnpm docs:check && pnpm examples:check",
"check": "pnpm format:check && pnpm typecheck && pnpm test && pnpm docs:check && pnpm examples:check",
"docs:check": "node scripts/check-docs.mjs",
"example:node-cli": "tsx examples/node-cli/src/index.ts",
"examples:check": "pnpm --filter @openclaw/cookbook-quickstart check && pnpm --filter @openclaw/cookbook-coding-agent-cli check && pnpm --filter @openclaw/cookbook-agent-workbench check && pnpm --filter @openclaw/cookbook-run-board check",
"format": "oxfmt --write .",
"format:check": "oxfmt --check .",
"lint": "oxlint --deny-warnings recipes examples sdk packages scripts test types",
"format": "prettier --write .",
"format:check": "prettier --check .",
"recipe:cancel-a-run": "tsx recipes/cancel-a-run/index.ts",
"recipe:custom-transport": "tsx recipes/custom-transport/index.ts",
"recipe:model-status": "tsx recipes/model-status/index.ts",
@ -18,25 +18,21 @@
"recipe:run-agent": "tsx recipes/run-an-agent/index.ts",
"recipe:stream-events": "tsx recipes/stream-events/index.ts",
"test": "vitest run",
"typecheck": "tsgo --noEmit"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@openclaw/sdk": "workspace:*"
},
"devDependencies": {
"@types/node": "^25.6.0",
"@typescript/native-preview": "7.0.0-dev.20260503.1",
"@vitejs/plugin-react": "^6.0.1",
"lucide-react": "^1.14.0",
"oxfmt": "^0.47.0",
"oxlint": "^1.62.0",
"oxlint-tsgolint": "^0.22.1",
"react": "^19.2.5",
"react-dom": "^19.2.5",
"@types/node": "^24.10.1",
"@vitejs/plugin-react": "^5.1.2",
"vite": "^7.3.0",
"prettier": "^3.7.4",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"lucide-react": "^0.562.0",
"tsx": "^4.21.0",
"typescript": "^6.0.3",
"vite": "^8.0.10",
"typescript": "^5.9.3",
"vitest": "^4.1.5"
},
"packageManager": "pnpm@10.23.0"
}
}

2695
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@ export async function runMain(action: () => Promise<unknown>): Promise<void> {
try {
const result = await action();
if (result !== undefined) {
console.log(JSON.stringify(redactSensitiveOutput(result), null, 2));
console.log(JSON.stringify(result, null, 2));
}
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
@ -17,33 +17,3 @@ export async function runMain(action: () => Promise<unknown>): Promise<void> {
process.exitCode = 1;
}
}
export function redactSensitiveOutput(value: unknown, seen = new WeakSet<object>()): unknown {
if (Array.isArray(value)) {
return value.map((entry) => redactSensitiveOutput(entry, seen));
}
if (value && typeof value === "object") {
if (seen.has(value)) {
return "[Circular]";
}
seen.add(value);
return Object.fromEntries(
Object.entries(value).map(([key, entry]) => [
key,
isSensitiveKey(key) ? "[REDACTED]" : redactSensitiveOutput(entry, seen),
]),
);
}
return value;
}
function isSensitiveKey(key: string): boolean {
const normalized = key.toLowerCase();
return (
normalized.includes("token") ||
normalized.includes("password") ||
normalized.includes("secret") ||
normalized.includes("authorization") ||
normalized.endsWith("key")
);
}

View File

@ -3,26 +3,26 @@
"version": "0.1.0",
"private": true,
"type": "module",
"packageManager": "pnpm@10.23.0",
"scripts": {
"build": "tsgo -p tsconfig.json && vite build",
"build": "tsc -p tsconfig.json && vite build",
"check": "pnpm typecheck && pnpm build",
"dev": "vite",
"preview": "vite preview",
"typecheck": "tsgo -p tsconfig.json --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@openclaw/sdk": "workspace:*",
"@vitejs/plugin-react": "^6.0.1",
"lucide-react": "^1.14.0",
"react": "^19.2.5",
"react-dom": "^19.2.5",
"vite": "^8.0.10"
"@vitejs/plugin-react": "^5.1.2",
"lucide-react": "^0.562.0",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vite": "^7.3.0"
},
"devDependencies": {
"@types/node": "^25.6.0",
"@types/react": "^19.2.14",
"@types/node": "^24.12.2",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"typescript": "^6.0.3"
},
"packageManager": "pnpm@10.23.0"
"typescript": "^5.9.3"
}
}

View File

@ -2,24 +2,24 @@
"name": "@openclaw/cookbook-coding-agent-cli",
"version": "0.1.0",
"private": true,
"type": "module",
"packageManager": "pnpm@10.23.0",
"bin": {
"openclaw-agent": "./dist/index.js"
},
"type": "module",
"scripts": {
"build": "tsgo -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"check": "pnpm typecheck && pnpm build",
"dev": "tsx src/index.ts",
"start": "node dist/index.js",
"typecheck": "tsgo -p tsconfig.json --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@openclaw/sdk": "workspace:*"
},
"devDependencies": {
"@types/node": "^25.6.0",
"@types/node": "^24.12.2",
"tsx": "^4.21.0",
"typescript": "^6.0.3"
},
"packageManager": "pnpm@10.23.0"
"typescript": "^5.9.3"
}
}

View File

@ -3,23 +3,23 @@
"version": "0.1.0",
"private": true,
"type": "module",
"packageManager": "pnpm@10.23.0",
"engines": {
"node": ">=22"
},
"scripts": {
"build": "tsgo -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"check": "pnpm typecheck && pnpm build",
"dev": "tsx src/index.ts",
"start": "node dist/index.js",
"typecheck": "tsgo -p tsconfig.json --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@openclaw/sdk": "workspace:*"
},
"devDependencies": {
"@types/node": "^25.6.0",
"@types/node": "^24.12.2",
"tsx": "^4.21.0",
"typescript": "^6.0.3"
},
"engines": {
"node": ">=22"
},
"packageManager": "pnpm@10.23.0"
"typescript": "^5.9.3"
}
}

View File

@ -3,26 +3,26 @@
"version": "0.1.0",
"private": true,
"type": "module",
"packageManager": "pnpm@10.23.0",
"scripts": {
"build": "tsgo -p tsconfig.json && vite build",
"build": "tsc -p tsconfig.json && vite build",
"check": "pnpm typecheck && pnpm build",
"dev": "vite",
"preview": "vite preview",
"typecheck": "tsgo -p tsconfig.json --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@openclaw/sdk": "workspace:*",
"@vitejs/plugin-react": "^6.0.1",
"lucide-react": "^1.14.0",
"react": "^19.2.5",
"react-dom": "^19.2.5",
"vite": "^8.0.10"
"@vitejs/plugin-react": "^5.1.2",
"lucide-react": "^0.562.0",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vite": "^7.3.0"
},
"devDependencies": {
"@types/node": "^25.6.0",
"@types/react": "^19.2.14",
"@types/node": "^24.12.2",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"typescript": "^6.0.3"
},
"packageManager": "pnpm@10.23.0"
"typescript": "^5.9.3"
}
}

View File

@ -4,7 +4,6 @@ import { customTransportRecipe } from "../recipes/custom-transport/index.js";
import { modelStatusRecipe } from "../recipes/model-status/index.js";
import { reuseSessionRecipe } from "../recipes/reuse-session/index.js";
import { runAgentRecipe } from "../recipes/run-an-agent/index.js";
import { redactSensitiveOutput } from "../recipes/_shared/run-main.js";
import { streamEventsRecipe } from "../recipes/stream-events/index.js";
describe("cookbook recipes", () => {
@ -51,16 +50,4 @@ describe("cookbook recipes", () => {
expect(result.runId).toBe("cookbook-run");
expect(result.calls.map((call) => call.method)).toEqual(["agent", "agent.wait"]);
});
it("redacts sensitive fields before console output", () => {
expect(
redactSensitiveOutput({
sessionKey: "cookbook-demo",
nested: { token: "abc123", ok: true },
}),
).toEqual({
sessionKey: "[REDACTED]",
nested: { token: "[REDACTED]", ok: true },
});
});
});