Skip to content

Commit 18bda42

Browse files
committed
Merge remote-tracking branch 'origin/main' into update-docs-term
2 parents 62d3497 + 321fa00 commit 18bda42

32 files changed

Lines changed: 16897 additions & 23910 deletions

.github/workflows/jseval-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ jobs:
1212
node-version: [22.x]
1313
steps:
1414
- uses: actions/checkout@v4
15+
- uses: pnpm/action-setup@v6
1516
- uses: actions/setup-node@v4
1617
with:
1718
node-version: ${{ matrix.node-version }}
18-
cache: 'npm'
19-
- run: npm ci
20-
- run: npm test -w @my-code/js-eval
19+
cache: 'pnpm'
20+
- run: pnpm install --frozen-lockfile
21+
- run: pnpm run --filter @my-code/js-eval test

.github/workflows/node.js.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ jobs:
1212
node-version: [22.x]
1313
steps:
1414
- uses: actions/checkout@v4
15+
- uses: pnpm/action-setup@v6
1516
- uses: actions/setup-node@v4
1617
with:
1718
node-version: ${{ matrix.node-version }}
18-
cache: 'npm'
19-
- run: npm ci
20-
- run: npm run lint
19+
cache: 'pnpm'
20+
- run: pnpm install --frozen-lockfile
21+
- run: pnpm run lint
2122

2223
types:
2324
runs-on: ubuntu-latest
@@ -26,12 +27,28 @@ jobs:
2627
node-version: [22.x]
2728
steps:
2829
- uses: actions/checkout@v4
30+
- uses: pnpm/action-setup@v6
2931
- uses: actions/setup-node@v4
3032
with:
3133
node-version: ${{ matrix.node-version }}
32-
cache: 'npm'
33-
- run: npm ci
34-
- run: npm run tsc
34+
cache: 'pnpm'
35+
- run: pnpm install --frozen-lockfile
36+
- run: pnpm run tsc
37+
38+
test:
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
node-version: [22.x]
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: pnpm/action-setup@v6
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
cache: 'pnpm'
50+
- run: pnpm install --frozen-lockfile
51+
- run: pnpm run test
3552

3653
check-docs:
3754
runs-on: ubuntu-latest
@@ -40,9 +57,10 @@ jobs:
4057
node-version: [22.x]
4158
steps:
4259
- uses: actions/checkout@v4
60+
- uses: pnpm/action-setup@v6
4361
- uses: actions/setup-node@v4
4462
with:
4563
node-version: ${{ matrix.node-version }}
46-
cache: 'npm'
47-
- run: npm ci
48-
- run: npx tsx ./scripts/checkDocs.ts
64+
cache: 'pnpm'
65+
- run: pnpm ci
66+
- run: pnpm exec tsx ./scripts/checkDocs.ts

.github/workflows/question-example.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ jobs:
1717
- uses: actions/checkout@v6
1818
with:
1919
ref: ${{ github.head_ref }}
20+
- uses: pnpm/action-setup@v6
2021
- uses: actions/setup-node@v4
2122
with:
2223
node-version: ${{ matrix.node-version }}
23-
cache: 'npm'
24-
- run: npm ci
24+
cache: 'pnpm'
25+
- run: pnpm install --frozen-lockfile
2526

26-
- run: npx tsx ./scripts/questionExample.ts 4
27+
- run: pnpm exec tsx ./scripts/questionExample.ts 4
2728
env:
2829
API_KEY: ${{ secrets.API_KEY }}
2930

.github/workflows/runtime-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ jobs:
1212
node-version: [22.x]
1313
steps:
1414
- uses: actions/checkout@v4
15+
- uses: pnpm/action-setup@v6
1516
- uses: actions/setup-node@v4
1617
with:
1718
node-version: ${{ matrix.node-version }}
18-
cache: 'npm'
19-
- run: npm ci
20-
- run: npm test -w @my-code/runtime
19+
cache: 'pnpm'
20+
- run: pnpm install --frozen-lockfile
21+
- run: pnpm run --filter @my-code/runtime test

.github/workflows/update-docs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ jobs:
1515
node-version: [22.x]
1616
steps:
1717
- uses: actions/checkout@v4
18+
- uses: pnpm/action-setup@v6
1819
- uses: actions/setup-node@v4
1920
with:
2021
node-version: ${{ matrix.node-version }}
21-
cache: 'npm'
22-
- run: npm ci
23-
- run: npx drizzle-kit migrate
22+
cache: 'pnpm'
23+
- run: pnpm install --frozen-lockfile
24+
- run: pnpm exec drizzle-kit migrate
2425
env:
2526
DATABASE_URL: ${{ secrets.DATABASE_URL }}
26-
- run: npx tsx ./scripts/checkDocs.ts --write
27+
- run: pnpm exec tsx ./scripts/checkDocs.ts --write
2728
env:
2829
DATABASE_URL: ${{ secrets.DATABASE_URL }}
2930
- name: Configure git for push

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55

66
FROM node:lts-slim AS dependencies
77

8+
# Install pnpm
9+
RUN npm install -g pnpm
10+
811
WORKDIR /app
912

10-
COPY package.json package-lock.json ./
13+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
1114
COPY packages/jsEval/package.json ./packages/jsEval/
1215
COPY packages/runtime/package.json ./packages/runtime/
1316

14-
RUN --mount=type=cache,target=/root/.npm \
15-
npm ci --no-audit --no-fund
17+
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
18+
pnpm install --frozen-lockfile
1619

1720
# これだけ時間かかるので先に実行する
1821
WORKDIR /app
1922
COPY ./scripts ./scripts
20-
RUN mkdir app && npx tsx ./scripts/removeHinting.ts
23+
RUN mkdir app && pnpm exec tsx ./scripts/removeHinting.ts
2124

2225
FROM node:lts-slim AS builder
2326

27+
# Install pnpm
28+
RUN npm install -g pnpm
29+
2430
# ビルド中にsentryでソースマップをアップロードするのに必要
2531
RUN apt-get update && apt-get install -y ca-certificates
2632

@@ -29,14 +35,16 @@ WORKDIR /app
2935

3036
# Copy project dependencies from dependencies stage
3137
COPY --from=dependencies /app/node_modules ./node_modules
38+
COPY --from=dependencies /app/packages/jsEval/node_modules ./packages/jsEval/node_modules
39+
COPY --from=dependencies /app/packages/runtime/node_modules ./packages/runtime/node_modules
3240

3341
# Copy application source code
3442
COPY . .
3543

3644
COPY --from=dependencies /app/app/m-plus-rounded-1c-nohint ./app/m-plus-rounded-1c-nohint
3745

3846
# Stop if documentation has any change that is not reflected to revisions.yml and database.
39-
RUN npx tsx ./scripts/checkDocs.ts --check-diff
47+
RUN pnpm exec tsx ./scripts/checkDocs.ts --check-diff
4048

4149
# Next.js collects completely anonymous telemetry data about general usage.
4250
# Learn more here: https://nextjs.org/telemetry
@@ -45,7 +53,7 @@ RUN npx tsx ./scripts/checkDocs.ts --check-diff
4553

4654
# Build Next.js application
4755
RUN --mount=type=cache,target=/app/.next/cache \
48-
npm run build
56+
pnpm run build
4957

5058
FROM node:lts-slim AS runner
5159

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ https://my-code.utcode.net
44

55
## インストール
66

7+
Node.js に加えて [pnpm 11](https://pnpm.io/ja/installation) をインストールしてください。
8+
79
```bash
8-
npm ci
10+
pnpm install --frozen-lockfile
911
```
1012

1113
## 開発環境
1214

1315
```bash
14-
npx prisma dev
16+
pnpm exec prisma dev
1517
```
1618
を実行し、`t` キーを押して表示される DATABASE_URL をコピー
1719

@@ -44,37 +46,37 @@ SENTRY_DSN=
4446

4547
別のターミナルで、
4648
```bash
47-
npm run db-migrate
49+
pnpm run db-migrate
4850
```
4951
でデータベースを初期化
5052

5153
```bash
52-
npm run db-docs
54+
pnpm run db-docs
5355
```
5456
でデータベースにドキュメントのページ情報を挿入します。
5557
(public/docs/以下にmarkdownを追加・削除したら再度実行する必要があります)
5658

5759
```bash
58-
npm run dev
60+
pnpm run dev
5961
```
6062
[http://localhost:3000](http://localhost:3000) で開きます。
6163

6264
```bash
63-
npm run format
65+
pnpm run format
6466
```
6567
でコードを整形します。
6668

6769
```bash
68-
npm run lint
70+
pnpm run lint
6971
```
7072
でコードをチェックします。出てくるwarningやerrorはできるだけ直しましょう。
7173

7274
### データベースのスキーマ
7375

74-
* データベースのスキーマ(./app/schema/hoge.ts)を編集した場合、 `npm run db-generate` (`npx drizzle-kit generate`) でmigrationファイルを作成し、 `npm run db-migrate` (`npx drizzle-kit migrate`) でデータベースに反映します。
76+
* データベースのスキーマ(./app/schema/hoge.ts)を編集した場合、 `pnpm run db-generate` (`pnpm exec drizzle-kit generate`) でmigrationファイルを作成し、 `pnpm run db-migrate` (`pnpm exec drizzle-kit migrate`) でデータベースに反映します。
7577
* 本番環境のデータベースのmigrateはmainにpushされた際にGitHub Actionで実行されます
7678
* スキーマのファイルを追加した場合は app/lib/drizzle.ts でimportを追加する必要があります(たぶん)
77-
* `npx prisma dev` で立ち上げたデータベースは `npx prisma dev ls` でデータベース名の確認・ `npx prisma dev rm default` で削除ができるらしい
79+
* `pnpm exec prisma dev` で立ち上げたデータベースは `pnpm exec prisma dev ls` でデータベース名の確認・ `pnpm exec prisma dev rm default` で削除ができるらしい
7880

7981
### 本番環境の場合
8082

@@ -136,7 +138,7 @@ Cloudflare Worker のビルドログとステータス表示が見れますが
136138
* REPLのコード例は1セクションに最大1つまで。
137139
* コードエディターとコード実行ブロックはいくつでも置けます。
138140
* ページ0以外の各ページの最後はレベル2見出し「この章のまとめ」と、レベル3見出し「練習問題n」を置く
139-
* 編集したドキュメントにローカルの開発環境でアクセスする際は `npm run db-docs` を実行してください。これにより `public/docs/revisions-dev.yml` が更新・作成され、チャットが正しく動作するようになります。
141+
* 編集したドキュメントにローカルの開発環境でアクセスする際は `pnpm run db-docs` を実行してください。これにより `public/docs/revisions-dev.yml` が更新・作成され、チャットが正しく動作するようになります。
140142
* 本番環境用の `revisions.yml` は、main ブランチに push された際に GitHub Action によって自動的に更新されます。
141143

142144
### ベースとなるドキュメントの作り方

app/(docs)/@chat/chat/[chatId]/chatArea.tsx

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import { ChatAreaStateUpdater } from "@/(docs)/chatAreaState";
44
import { useStreamingChatContext } from "@/(docs)/streamingChatContext";
5+
import { useSendChat } from "@/(docs)/useSendChat";
56
import { deleteChatAction } from "@/actions/deleteChat";
67
import { ChatWithMessages } from "@/lib/chatHistory";
7-
import { LangId, MarkdownSection, PageSlug } from "@/lib/docs";
8+
import { DynamicMarkdownSection, LangId, MarkdownSection, PageSlug } from "@/lib/docs";
89
import { Heading } from "@/markdown/heading";
910
import { StyledMarkdown } from "@/markdown/markdown";
1011
import { usePagesListForLang } from "@/pagesListContext";
@@ -74,9 +75,17 @@ interface Props {
7475
langId: LangId;
7576
pageSlug: PageSlug;
7677
targetSection: MarkdownSection | undefined;
78+
priorSectionContent: DynamicMarkdownSection[];
7779
}
7880
export function ChatAreaContent(props: Props) {
79-
const { chatId, chatData, langId, pageSlug, targetSection } = props;
81+
const {
82+
chatId,
83+
chatData,
84+
langId,
85+
pageSlug,
86+
targetSection,
87+
priorSectionContent,
88+
} = props;
8089

8190
const langEntry = usePagesListForLang(langId);
8291
const pageEntry = langEntry?.pages.find((p) => p.slug === pageSlug);
@@ -92,6 +101,23 @@ export function ChatAreaContent(props: Props) {
92101
const router = useRouter();
93102
const streamingChatContext = useStreamingChatContext();
94103
const isStreamingThis = streamingChatContext.chatId === chatId;
104+
const { sendChat, isLoading: isRegenerating } = useSendChat();
105+
106+
const handleRegenerate = async () => {
107+
if (!confirm("このチャットを削除して再生成してもよろしいですか?")) {
108+
return;
109+
}
110+
const firstUserMsg = chatData.messages.find((m) => m.role === "user");
111+
const userQuestion = firstUserMsg ? firstUserMsg.content : chatData.title;
112+
113+
await sendChat({
114+
path: { lang: langId, page: pageSlug },
115+
userQuestion,
116+
questionScope: "page",
117+
sectionContent: priorSectionContent,
118+
deleteChatOnCreated: chatId,
119+
});
120+
};
95121

96122
return (
97123
<>
@@ -117,12 +143,55 @@ export function ChatAreaContent(props: Props) {
117143
</li>
118144
</ul>
119145
</div>
120-
<div className="flex flex-wrap items-center">
146+
<div className="flex flex-wrap items-center gap-2">
121147
<div className="flex-1 text-sm opacity-40" suppressHydrationWarning>
122148
{chatData.createdAt.toLocaleString()}
123149
</div>
150+
<button
151+
className="btn btn-secondary btn-soft btn-sm"
152+
disabled={isStreamingThis || isRegenerating}
153+
onClick={handleRegenerate}
154+
>
155+
<svg
156+
className={clsx("w-4 h-4", isRegenerating && "animate-spin")}
157+
viewBox="0 0 24 24"
158+
fill="none"
159+
xmlns="http://www.w3.org/2000/svg"
160+
>
161+
<path
162+
d="M4.06189 13C4.55399 16.944 7.92083 20 12 20C15.5463 20 18.5721 17.7719 19.5714 14.619"
163+
stroke="currentColor"
164+
strokeWidth="2"
165+
strokeLinecap="round"
166+
strokeLinejoin="round"
167+
/>
168+
<path
169+
d="M19.9381 11C19.446 7.05601 16.0792 4 12 4C8.45371 4 5.42788 6.22811 4.42857 9.38095"
170+
stroke="currentColor"
171+
strokeWidth="2"
172+
strokeLinecap="round"
173+
strokeLinejoin="round"
174+
/>
175+
<path
176+
d="M14 14.619H19.5714V20"
177+
stroke="currentColor"
178+
strokeWidth="2"
179+
strokeLinecap="round"
180+
strokeLinejoin="round"
181+
/>
182+
<path
183+
d="M10 9.38095H4.42857V4"
184+
stroke="currentColor"
185+
strokeWidth="2"
186+
strokeLinecap="round"
187+
strokeLinejoin="round"
188+
/>
189+
</svg>
190+
再生成
191+
</button>
124192
<button
125193
className="btn btn-error btn-soft btn-sm"
194+
disabled={isStreamingThis || isRegenerating}
126195
onClick={async () => {
127196
if (confirm("このチャットを削除してもよろしいですか?")) {
128197
await deleteChatAction(chatId);

0 commit comments

Comments
 (0)