Skip to content

Commit

Permalink
Add temporary static homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 committed May 3, 2024
1 parent 89cedaf commit fb64d7f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface AiWarpConfig {
}[];
};
module?: string;
showAiWarpHomepage?: boolean;
aiProvider:
| {
openai: {
Expand Down
8 changes: 8 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { join } from 'node:path'
import { platformaticService, Stackable } from '@platformatic/service'
import fastifyUser from 'fastify-user'
import fastifyPlugin from 'fastify-plugin'
import fastifyStatic from '@fastify/static'
import { schema } from './lib/schema.js'
import { Generator } from './lib/generator.js'
import { AiWarpConfig } from './config.js'
Expand All @@ -19,6 +21,12 @@ const stackable: Stackable<AiWarpConfig> = async function (fastify, opts) {
await fastify.register(rateLimitPlugin, opts)
await fastify.register(apiPlugin, opts)

if (config.showAiWarpHomepage) {

Check failure on line 24 in index.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected nullable boolean value in conditional. Please handle the nullish case explicitly
await fastify.register(fastifyStatic, {
root: join(import.meta.dirname, 'static')
})
}

await fastify.register(platformaticService, opts)
}

Expand Down
4 changes: 4 additions & 0 deletions lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const aiWarpSchema = {
properties: {
...schema.schema.properties,
module: { type: 'string' },
showAiWarpHomepage: {
type: 'boolean',
default: true
},
aiProvider: {
type: 'object',
oneOf: [
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start-ai-warp": "./dist/cli/start.js"
},
"scripts": {
"build": "tsc --build",
"build": "tsc --build && cp -r ./static ./dist/",
"build:config": "node ./dist/lib/schema.js --dump-schema | json2ts > config.d.ts",
"clean": "rm -fr ./dist",
"lint": "ts-standard | snazzy",
Expand Down Expand Up @@ -38,6 +38,7 @@
"@azure/openai": "^1.0.0-beta.12",
"@fastify/error": "^3.4.1",
"@fastify/rate-limit": "^9.1.0",
"@fastify/static": "^7.0.3",
"@fastify/type-provider-typebox": "^4.0.0",
"@platformatic/config": "^1.24.0",
"@platformatic/generators": "^1.24.0",
Expand Down
42 changes: 42 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Warp</title>
</head>
<body>
<div>
<label for="prompt-text">Prompt: </label>
<textarea name="prompt text" id="prompt-text" cols="60" rows="1"></textarea>
<button id="prompt-button">Prompt</button>
</div>

<p id="response"></p>

<script>
const promptText = document.getElementById('prompt-text')
const responseText = document.getElementById('response')

const promptButton = document.getElementById('prompt-button')
promptButton.onclick = async () => {
const res = await fetch('/api/v1/prompt', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
prompt: promptText.value
})
})
const body = await res.json()

if (res.status === 200) {
responseText.innerHTML = body.response
} else {
responseText.innerHTML = `Error: ${body.message} (${body.code})`;
}
}
</script>
</body>
</html>

0 comments on commit fb64d7f

Please sign in to comment.