Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { CoreMessage, streamText } from 'ai';
import { env } from 'cloudflare:workers';
import { verifySignature, streamResponse } from '@layercode/node-server-sdk';
import { Context } from 'hono';
import { Hono } from 'hono';

const sessionMessages = {} as Record<string, CoreMessage[]>;

const SYSTEM_PROMPT = `You are a helpful conversation assistant. You should respond to the user's message in a conversational manner. Your output will be spoken by a TTS model. You should respond in a way that is easy for the TTS model to speak and sound natural.`;
const WELCOME_MESSAGE = 'Welcome to Layercode. How can I help you today?';

export const onRequestPost = async (c: Context) => {
const app = new Hono();

app.post('/', async (c) => {
if (!env.GOOGLE_GENERATIVE_AI_API_KEY) {
return c.json({ error: 'GOOGLE_GENERATIVE_AI_API_KEY is not set' }, 500);
}
Expand Down Expand Up @@ -68,4 +70,6 @@ export const onRequestPost = async (c: Context) => {
// Here we return the textStream chunks as SSE messages to Layercode, to be spoken to the user
await stream.ttsTextStream(textStream);
});
};
});

export { app };
10 changes: 7 additions & 3 deletions src/authorize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Context } from 'hono';
import { Hono } from 'hono';
import { env } from 'cloudflare:workers';

export const onRequestPost = async (c: Context) => {
const app = new Hono();

app.post('/', async (c) => {
try {
const response = await fetch("https://api.layercode.com/v1/pipelines/authorize_session", {
method: 'POST',
Expand All @@ -20,4 +22,6 @@ export const onRequestPost = async (c: Context) => {
} catch (error) {
return c.json({ error: error });
}
};
});

export { app }
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Hono } from 'hono';
import { onRequestPost as onRequestPostAgent } from './agent';
import { onRequestPost as onRequestPostAuthorize } from './authorize';
import { app as agentApp } from './agent';
import { app as authorizeApp } from './authorize';
import { cors } from 'hono/cors'

const app = new Hono();

app.post('/agent', onRequestPostAgent);
app.route('/agent', agentApp);

app.use('/authorize', cors())
app.post('/authorize', onRequestPostAuthorize);
app.route('/authorize', authorizeApp);


export default app;