-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adapted from https://github.com/threepointone/durable-chat Non-template changes: - Add wrangler.toml to wrangler.json conversion to CLI
- Loading branch information
1 parent
42cf96e
commit d3e61a3
Showing
21 changed files
with
4,835 additions
and
653 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import toml from "toml"; | ||
|
||
const TEMPLATE_DIRECTORY_SUFFIX = "-template"; | ||
|
||
export function getTemplatePaths(templateDirectory: string): string[] { | ||
export type Template = { name: string; path: string }; | ||
|
||
export function getTemplates(templateDirectory: string): Template[] { | ||
return fs | ||
.readdirSync(templateDirectory) | ||
.filter( | ||
(file) => | ||
file.endsWith(TEMPLATE_DIRECTORY_SUFFIX) && | ||
fs.statSync(file).isDirectory(), | ||
) | ||
.map((template) => path.join(templateDirectory, template)); | ||
.map((name) => ({ | ||
name, | ||
path: path.join(templateDirectory, name), | ||
})); | ||
} | ||
|
||
export function readToml(filePath: string): unknown { | ||
return toml.parse(fs.readFileSync(filePath, { encoding: "utf-8" })); | ||
} | ||
|
||
export function readJSON(filePath: string): unknown { | ||
export function readJson(filePath: string): unknown { | ||
return JSON.parse(fs.readFileSync(filePath, { encoding: "utf-8" })); | ||
} | ||
|
||
export function writeJSON(filePath: string, object: unknown) { | ||
export function writeJson(filePath: string, object: unknown) { | ||
fs.writeFileSync(filePath, JSON.stringify(object, undefined, 2) + "\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Durable Chat App | ||
|
||
Chat with an AI assistant backed by a Durable Object. | ||
|
||
## Develop Locally | ||
|
||
Use this template with [C3](https://developers.cloudflare.com/pages/get-started/c3/) (the `create-cloudflare` CLI): | ||
|
||
``` | ||
npm create cloudflare@latest -- --template=cloudflare/templates/durable-chat-template | ||
``` | ||
|
||
## Preview Deployment | ||
|
||
A live public deployment of this template is available at [https://durable-chat-template.templates.workers.dev](https://durable-chat-template.templates.workers.dev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "durable-chat-template", | ||
"description": "Chat with an AI assistant backed by a Durable Object.", | ||
"cloudflare": { | ||
"label": "Durable Chat App", | ||
"products": [ | ||
"Workers", | ||
"Durable Objects", | ||
"AI" | ||
], | ||
"categories": [ | ||
"ai" | ||
], | ||
"icon_urls": [ | ||
"https://imagedelivery.net/wSMYJvS3Xw-n339CbDyDIA/5ca0ca32-e897-4699-d4c1-6b680512f000/public" | ||
] | ||
}, | ||
"dependencies": { | ||
"eventsource-parser": "3.0.0", | ||
"nanoid": "5.0.8", | ||
"partyserver": "0.0.57", | ||
"partysocket": "1.0.2", | ||
"react": "18.3.1", | ||
"react-dom": "18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "4.20241112.0", | ||
"@types/react": "18.3.12", | ||
"@types/react-dom": "18.3.1", | ||
"esbuild": "0.24.0", | ||
"typescript": "5.6.3", | ||
"wrangler": "3.87.0" | ||
}, | ||
"scripts": { | ||
"check": "tsc && wrangler --experimental-json-config deploy --dry-run", | ||
"deploy": "wrangler --experimental-json-config deploy", | ||
"dev": "wrangler --experimental-json-config dev", | ||
"types": "wrangler --experimental-json-config types ./src/server/worker-configuration.d.ts" | ||
} | ||
} |
Oops, something went wrong.