Skip to content

Commit 8c80934

Browse files
authored
Merge pull request #24 from cloudflare/aj/add-formatting
Add formatting (fix) and linting (fix) to pre-push hook
2 parents d52ce87 + 586b985 commit 8c80934

File tree

137 files changed

+81823
-80843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+81823
-80843
lines changed

.changeset/config.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3-
"changelog": [
4-
"@changesets/changelog-github",
5-
{ "repo": "cloudflare/ai" }
6-
],
3+
"changelog": ["@changesets/changelog-github", { "repo": "cloudflare/ai" }],
74
"commit": false,
85
"fixed": [],
96
"linked": [],

.husky/pre-push

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,55 @@
11
#!/bin/sh
2-
# This husky pre-push hook fails if the lockfile changes after npm install.
3-
# Replace "package-lock.json" with your actual lockfile if needed.
2+
# This Husky pre-push hook checks two things:
3+
# 1. That the lockfile is not modified by `npm install`.
4+
# 2. That formatting does not introduce any unstaged changes.
5+
6+
# ANSI colour codes for yellow and reset.
7+
YELLOW="\033[1;33m"
8+
RESET="\033[0m"
49

10+
# Replace "package-lock.json" with your actual lockfile if needed.
511
LOCKFILE="package-lock.json"
612

7-
# Ensure the lockfile exists.
13+
# 1. Ensure the lockfile exists.
814
if [ ! -f "$LOCKFILE" ]; then
9-
echo "Error: $LOCKFILE not found."
15+
echo ""
16+
echo "**ACTION REQUIRED**"
17+
echo "${YELLOW}The lockfile ($LOCKFILE) was not found. Please ensure it is present.${RESET}"
18+
echo ""
1019
exit 1
1120
fi
1221

13-
# Calculate the original hash of the lockfile.
22+
# 2. Calculate the original hash of the lockfile.
1423
ORIGINAL_HASH=$(sha256sum "$LOCKFILE" | cut -d ' ' -f 1)
1524

16-
# Run npm install.
25+
# 3. Run npm install.
1726
npm install
1827

19-
# Recalculate the hash after npm install.
28+
# 4. Recalculate the hash after npm install.
2029
NEW_HASH=$(sha256sum "$LOCKFILE" | cut -d ' ' -f 1)
2130

22-
# Compare the hashes.
31+
# 5. Compare the hashes.
2332
if [ "$ORIGINAL_HASH" != "$NEW_HASH" ]; then
24-
echo "Error: $LOCKFILE has been modified after npm install. Please review and commit the updated lockfile."
33+
echo ""
34+
echo "**ACTION REQUIRED**"
35+
echo "${YELLOW}Your lockfile has been modified after npm install. Please review and commit the updated lockfile.${RESET}"
36+
echo ""
37+
exit 1
38+
fi
39+
40+
# 6. Run Nx format across all projects.
41+
npx nx run-many -t format lint:fix
42+
npm run format
43+
npm run lint:fix
44+
45+
# 7. Check if formatting introduced any changes that need committing.
46+
if [ -n "$(git status --porcelain)" ]; then
47+
echo ""
48+
echo "**ACTION REQUIRED**"
49+
echo "${YELLOW}Formatting and/or linting caused changes. Please commit them before pushing.${RESET}"
50+
echo ""
2551
exit 1
2652
fi
2753

28-
# Continue with the remaining pre-push commands.
54+
# 8. Continue with the remaining pre-push commands.
2955
npx nx affected --base=main --head=HEAD -t lint types test:ci type-check build

biome.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"enabled": true
55
},
66
"files": {
7-
"ignore": ["node_modules/**/*", "dist/**/*"]
7+
"ignore": ["worker-configuration.d.ts", "types/workerd.d.ts"]
8+
},
9+
"vcs": {
10+
"enabled": true,
11+
"clientKind": "git",
12+
"useIgnoreFile": true
813
},
914
"linter": {
1015
"enabled": true,
@@ -23,7 +28,6 @@
2328
},
2429
"formatter": {
2530
"enabled": true,
26-
"indentStyle": "tab",
2731
"indentWidth": 4,
2832
"lineWidth": 100
2933
}

demos/agent-scheduler/.gitignore

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
node_modules
2+
3+
.nx
4+
.idea
5+
.vscode
6+
.zed
7+
# Logs
8+
9+
logs
10+
_.log
11+
npm-debug.log_
12+
yarn-debug.log*
13+
yarn-error.log*
14+
lerna-debug.log*
15+
.pnpm-debug.log*
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
\*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
\*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
\*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
\*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.cache
112+
.parcel-cache
113+
114+
# Next.js build output
115+
116+
.next
117+
out
118+
119+
# Nuxt.js build / generate output
120+
121+
.nuxt
122+
dist
123+
124+
# Gatsby files
125+
126+
.cache/
127+
128+
# Comment in the public line in if your project uses Gatsby and not Next.js
129+
130+
# https://nextjs.org/blog/next-9-1#public-directory-support
131+
132+
# public
133+
134+
# vuepress build output
135+
136+
.vuepress/dist
137+
138+
# vuepress v2.x temp and cache directory
139+
140+
.temp
141+
.cache
142+
143+
# Docusaurus cache and generated files
144+
145+
.docusaurus
146+
147+
# Serverless directories
148+
149+
.serverless/
150+
151+
# FuseBox cache
152+
153+
.fusebox/
154+
155+
# DynamoDB Local files
156+
157+
.dynamodb/
158+
159+
# TernJS port file
160+
161+
.tern-port
162+
163+
# Stores VSCode versions used for testing VSCode extensions
164+
165+
.vscode-test
166+
167+
# yarn v2
168+
169+
.yarn/cache
170+
.yarn/unplugged
171+
.yarn/build-state.yml
172+
.yarn/install-state.gz
173+
.pnp.\*
174+
175+
# wrangler project
176+
177+
.dev.vars
178+
.wrangler/

demos/agent-scheduler/biome.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"enabled": true
55
},
66
"files": {
7-
"ignore": ["node_modules/**/*", ".wrangler/**/*"]
7+
"ignore": ["worker-configuration.d.ts"]
8+
},
9+
"vcs": {
10+
"enabled": true,
11+
"clientKind": "git",
12+
"useIgnoreFile": true
813
},
914
"linter": {
1015
"enabled": true,
@@ -23,8 +28,7 @@
2328
},
2429
"formatter": {
2530
"enabled": true,
26-
"indentStyle": "tab",
2731
"indentWidth": 4,
28-
"lineWidth": 140
32+
"lineWidth": 100
2933
}
3034
}

demos/agent-scheduler/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
"build": "vite build",
77
"preview": "npm run build && vite preview",
88
"deploy": "npm run build && wrangler deploy",
9+
"format": "biome format --write",
910
"test": "vitest",
1011
"test:ci": "vitest --watch=false",
1112
"cf-typegen": "wrangler types",
12-
"lint": "biome lint --error-on-warnings ./src",
13+
"lint": "biome lint --error-on-warnings",
14+
"lint:fix": "biome lint --fix",
1315
"type-check": "tsc --noEmit"
1416
},
1517
"devDependencies": {
18+
"@biomejs/biome": "^1.8.2",
1619
"@cloudflare/vitest-pool-workers": "^0.7.5",
1720
"typescript": "^5.5.2",
1821
"vitest": "~3.0.7",

demos/agent-scheduler/src/SchedulerAgent.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ export class SchedulerAgent extends Agent<{ AI: any }, SchedulerAgentState> {
7171
/**
7272
* Processes user queries and determines the appropriate scheduling action.
7373
*/
74-
async query(query: string): Promise<{ confirmation?: Confirmation; message?: string } | Schedule[] | string | undefined> {
74+
async query(
75+
query: string,
76+
): Promise<
77+
{ confirmation?: Confirmation; message?: string } | Schedule[] | string | undefined
78+
> {
7579
const workersai = createWorkersAI({ binding: this.env.AI });
7680
const aiModel = workersai("@cf/meta/llama-3.3-70b-instruct-fp8-fast");
7781

@@ -87,7 +91,10 @@ export class SchedulerAgent extends Agent<{ AI: any }, SchedulerAgentState> {
8791
}
8892

8993
if (action === "add") {
90-
const [payload, scheduleType] = await Promise.all([extractAlarmMessage(aiModel, query), extractAlarmType(aiModel, query)]);
94+
const [payload, scheduleType] = await Promise.all([
95+
extractAlarmMessage(aiModel, query),
96+
extractAlarmType(aiModel, query),
97+
]);
9198

9299
// We can use the same logic for delayed and schedule as they both refer to a
93100
// specific time in the future.
@@ -163,7 +170,10 @@ export class SchedulerAgent extends Agent<{ AI: any }, SchedulerAgentState> {
163170
/**
164171
* Confirms or rejects a pending scheduling operation based on user input.
165172
*/
166-
async confirm(confirmationId: string, userConfirmed: boolean): Promise<Schedule | string | false | undefined> {
173+
async confirm(
174+
confirmationId: string,
175+
userConfirmed: boolean,
176+
): Promise<Schedule | string | false | undefined> {
167177
const confirmation = this.state.confirmations.find((c) => c.id === confirmationId);
168178

169179
if (!confirmation) {
@@ -204,7 +214,9 @@ export class SchedulerAgent extends Agent<{ AI: any }, SchedulerAgentState> {
204214
result = "User chose not to proceed with this action.";
205215
}
206216

207-
const remainingConfirmations = this.state.confirmations.filter((c) => c.id !== confirmationId);
217+
const remainingConfirmations = this.state.confirmations.filter(
218+
(c) => c.id !== confirmationId,
219+
);
208220

209221
this.setState({
210222
...this.state,

demos/agent-scheduler/src/llm/extract-scheduled-date.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { generateObject, type LanguageModel } from "ai";
22
import z from "zod";
33

4-
export async function extractScheduledDate(
5-
model: LanguageModel,
6-
query: string,
7-
) {
4+
export async function extractScheduledDate(model: LanguageModel, query: string) {
85
const { object } = await generateObject({
96
model,
107
schema: z.object({

demos/agent-scheduler/src/types/hono.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { Hono, Context as HonoContext, MiddlewareHandler as HonoMiddlewareHandler } from "hono";
1+
import type {
2+
Hono,
3+
Context as HonoContext,
4+
MiddlewareHandler as HonoMiddlewareHandler,
5+
} from "hono";
26

37
export type Variables = Record<string, string>;
48

0 commit comments

Comments
 (0)