Skip to content

Commit 69b8cdb

Browse files
authored
Add the Claude Agent SDK Sample (#139)
1 parent a5274ea commit 69b8cdb

10 files changed

Lines changed: 430 additions & 6 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ updates:
2424
- '/common/backend/'
2525
- '/agents/agent-mastra/'
2626
- '/agents/agent-voltagent/'
27+
- '/agents/agent-sdk/'
2728
- '/basic/cdk/'
2829
- '/basic/app/'
2930
- '/mcp/clients/langgraph-mcp-client/'

agents/agent-sdk/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output.txt
2+
node_modules
3+
dist
4+
.mastra
5+
.env.development
6+
.env*
7+
*.db
8+
output.ts

agents/agent-sdk/eslint.config.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { defineConfig } from 'eslint/config';
2+
import eslint from '@eslint/js';
3+
import stylistic from '@stylistic/eslint-plugin';
4+
import tseslint from 'typescript-eslint';
5+
import eslintImport from 'eslint-plugin-import';
6+
7+
import { includeIgnoreFile } from '@eslint/compat';
8+
import path from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
const gitignorePath = path.resolve(__dirname, './.gitignore');
14+
15+
export default defineConfig(
16+
includeIgnoreFile(gitignorePath),
17+
{
18+
ignores: [
19+
'**/*.d.ts',
20+
'*.{js,jsx}',
21+
'src/tsconfig.json',
22+
'src/stories',
23+
'**/*.css',
24+
'node_modules/**/*',
25+
'./.next/*',
26+
'out',
27+
'.storybook',
28+
'dist',
29+
'.vinxi',
30+
'.output',
31+
],
32+
},
33+
eslint.configs.recommended,
34+
...tseslint.configs.strict,
35+
...tseslint.configs.stylistic,
36+
{
37+
files: ['src/**/*.{ts,tsx}'],
38+
languageOptions: {
39+
parser: tseslint.parser,
40+
ecmaVersion: 'latest',
41+
sourceType: 'module',
42+
parserOptions: {
43+
projectService: true,
44+
tsconfigRootDir: __dirname,
45+
project: [
46+
'./tsconfig.json',
47+
'./tsconfig-eslint.json',
48+
],
49+
},
50+
},
51+
plugins: {
52+
'@stylistic': stylistic,
53+
},
54+
extends: [eslintImport.flatConfigs.recommended, eslintImport.flatConfigs.typescript],
55+
rules: {
56+
'@stylistic/semi': ['error', 'always'],
57+
'@stylistic/indent': ['error', 2],
58+
'@stylistic/comma-dangle': ['error', 'always-multiline'],
59+
'@stylistic/quotes': ['error', 'single'],
60+
'import/no-unresolved': 'off',
61+
},
62+
}
63+
);

agents/agent-sdk/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "agent-sdk",
3+
"version": "1.0.0",
4+
"description": "Claude Agent SDK sample implementation for TypeScript",
5+
"main": "dist/index.js",
6+
"type": "module",
7+
"scripts": {
8+
"build": "tsc --build --clean && tsc",
9+
"clean": "tsc --build --clean",
10+
"watch": "tsc -w",
11+
"test": "vitest run --passWithNoTests",
12+
"dev": "tsx src/index.ts",
13+
"lint": "eslint .",
14+
"lint-fix": "eslint . --fix"
15+
},
16+
"devDependencies": {
17+
"@eslint/compat": "^1.4.1",
18+
"@eslint/js": "^9.39.1",
19+
"@stylistic/eslint-plugin": "^5.5.0",
20+
"@types/node": "^22.19.0",
21+
"@types/uuid": "^10.0.0",
22+
"@vitest/eslint-plugin": "^1.4.1",
23+
"dotenv": "^16.6.1",
24+
"esbuild": "^0.25.12",
25+
"eslint": "^9.39.1",
26+
"eslint-import-resolver-typescript": "^4.4.4",
27+
"eslint-plugin-import": "^2.32.0",
28+
"eslint-plugin-promise": "^7.2.1",
29+
"jiti": "^2.6.1",
30+
"tsx": "^4.20.6",
31+
"typescript": "^5.9.3",
32+
"typescript-eslint": "^8.46.3",
33+
"vite": "^7.2.2",
34+
"vite-tsconfig-paths": "^5.1.4",
35+
"vitest": "^4.0.8"
36+
},
37+
"dependencies": {
38+
"@anthropic-ai/claude-agent-sdk": "^0.1.30",
39+
"source-map-support": "^0.5.21",
40+
"uuid": "^13.0.0",
41+
"zod": "^4.1.12"
42+
}
43+
}

agents/agent-sdk/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { query } from '@anthropic-ai/claude-agent-sdk';
2+
3+
(async () => {
4+
const stream = query({
5+
prompt:
6+
'Node.js のプログラムでフィボナッチ数列を出力するプログラムを TypeScript 書いて、現在の作業ディレクトリに output.ts という名前で保存してください。ファイルパスは相対パスで ./output.ts としてください。',
7+
options: {
8+
// systemPrompt: '',
9+
allowedTools: ['Write'],
10+
cwd: process.cwd(),
11+
},
12+
});
13+
14+
for await (const message of stream) {
15+
// 実行途中の出力をログ表示
16+
console.log(message);
17+
}
18+
19+
console.log('\n処理を完了しました。');
20+
})();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": ["./tsconfig.json"],
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"exclude": [
7+
"node_modules",
8+
"cdk.out"
9+
]
10+
}

agents/agent-sdk/tsconfig.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "nodenext",
5+
"lib": [
6+
"esnext",
7+
"dom"
8+
],
9+
"moduleResolution": "nodenext",
10+
"moduleDetection": "force",
11+
"resolveJsonModule": true,
12+
"allowJs": true,
13+
"esModuleInterop": true,
14+
"isolatedModules": true,
15+
"declaration": true,
16+
"strict": true,
17+
"noImplicitAny": true,
18+
"strictNullChecks": true,
19+
"noImplicitThis": true,
20+
"alwaysStrict": true,
21+
"noUnusedLocals": false,
22+
"noUnusedParameters": false,
23+
"noImplicitReturns": true,
24+
"noFallthroughCasesInSwitch": false,
25+
"inlineSourceMap": true,
26+
"inlineSources": true,
27+
"experimentalDecorators": true,
28+
"strictPropertyInitialization": false,
29+
"skipLibCheck": true,
30+
"outDir": "./dist",
31+
"typeRoots": [
32+
"./node_modules",
33+
"./node_modules/@types"
34+
],
35+
"types": [
36+
"node"
37+
]
38+
},
39+
"exclude": [
40+
"node_modules",
41+
"cdk.out",
42+
"*.config.*"
43+
]
44+
}

agents/agent-sdk/vitest.config.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/// <reference types="vitest" />
2+
/// <reference types="vite/client" />
3+
4+
import { defineConfig } from 'vitest/config';
5+
import * as dotenv from 'dotenv';
6+
import { resolve } from 'path';
7+
8+
export default defineConfig({
9+
// モノレポ用の共通設定
10+
resolve: {
11+
alias: {
12+
// パッケージ間の直接参照
13+
'@llm-ts-example/common-core': resolve(__dirname, '../../common/core/src'),
14+
'@llm-ts-example/common-backend': resolve(__dirname, '../../common/backend/src')
15+
}
16+
},
17+
server: {
18+
fs: {
19+
// モノレポ内のファイルアクセスを許可
20+
allow: ['..']
21+
}
22+
},
23+
build: {
24+
target: 'esnext',
25+
rollupOptions: {
26+
// ESModuleとして出力
27+
output: {
28+
format: 'es'
29+
}
30+
}
31+
},
32+
root: '.',
33+
test: {
34+
environment: 'node',
35+
globals: true,
36+
isolate: true,
37+
env: dotenv.config({ path: '.env.test' }).parsed,
38+
testTimeout: 30000,
39+
},
40+
});

0 commit comments

Comments
 (0)