Skip to content
2 changes: 1 addition & 1 deletion docs/docs/production/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ httpServer.listen(parseInt(port), host, () => {

To deploy ConvoStack using Fly.io, check out [this guide](./deploy-with-fly-io).

### Best Redis free tier option: Neon
### Best Postgres free tier option: Neon

Looking for a free Postgres option? We recommend trying [Neon](https://neon.tech/) with the Fly.io deployment.

Expand Down

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

16 changes: 16 additions & 0 deletions examples/be-example-express-sqlite/src/agent-playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {playground, PlaygroundAgentProxy} from "@convostack/playground";
import {AgentEcho} from "@convostack/agent-echo";
import {IAgentCallbacks, IAgentContext, IAgentResponse} from "@convostack/agent";

const agent = new AgentEcho();
// One-liner for hosted version
playground(agent)

// playground({
// reply(context: IAgentContext, callbacks?: IAgentCallbacks): Promise<IAgentResponse> {
// // Your logic
// }
// })
// const pap = new PlaygroundAgentProxy(agent);
// pap.setProxyUrl('ws://localhost:8088/agent')
// pap.connect()
104 changes: 104 additions & 0 deletions examples/be-example-express-sqlite/src/server-playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { ConvoStackBackendExpress } from "convostack/backend-express";
import express from "express";
import { StorageEnginePrismaSQLite } from "convostack/storage-engine-prisma-sqlite";
import cors, { CorsOptions } from "cors";
import { AuthJWT } from "convostack/auth-jwt";
import { createServer } from "http";
import * as dotenv from "dotenv";
import { DefaultAgentManager } from "convostack/agent";
import {
IStorageEngine,
IConversationEventServiceOptions,
} from "convostack/models";
import { StorageEnginePrismaPostgres } from "convostack/storage-engine-prisma-postgres";
import { StorageEnginePrismaMySQL } from "convostack/storage-engine-prisma-mysql";
import { RedisPubSub } from "graphql-redis-subscriptions";
import Redis, { RedisOptions } from "ioredis";
import { AgentHTTPClient } from "convostack/agent-http";

dotenv.config();

const port = process.env.PORT || "3000";
const host = process.env.HOST || "localhost";
const proxyUrl = "https://playground-proxy.convostack.ai/client";
console.log("Configuring server...");

const corsOptions: CorsOptions = {
origin: ["http://localhost:5173", "https://studio.apollographql.com"],
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
preflightContinue: false,
optionsSuccessStatus: 204,
};

const main = async () => {
const app = express();
app.use(cors(corsOptions));
const httpServer = createServer(app);

let storage: IStorageEngine;
switch (process.env.STORAGE_ENGINE) {
case "sqlite":
storage = new StorageEnginePrismaSQLite(process.env.DATABASE_URL);
await (storage as StorageEnginePrismaSQLite).init();
break;
case "postgres":
storage = new StorageEnginePrismaPostgres(process.env.DATABASE_URL);
await (storage as StorageEnginePrismaPostgres).init();
break;
case "mysql":
storage = new StorageEnginePrismaMySQL(process.env.DATABASE_URL);
await (storage as StorageEnginePrismaMySQL).init();
break;
default:
throw new Error(`Invalid storage engine: ${process.env.STORAGE_ENGINE}`);
}

const convEventsOpts = {} as IConversationEventServiceOptions;
if (process.env.REDIS_URL) {
convEventsOpts.pubSubEngine = new RedisPubSub({
connection: process.env.REDIS_URL,
});
convEventsOpts.cache = new Redis(process.env.REDIS_URL);
}

const backend = new ConvoStackBackendExpress({
basePath: "/",
storage,
auth: new AuthJWT(storage, {
jwtSecret: process.env.JWT_SECRET,
userDataVerificationSecret: process.env.USER_VERIFICATION_HASH_SECRET,
allowAnonUsers: process.env.ALLOW_ANONYMOUS_USERS == "true",
requireUserVerificationHash: !(
process.env.REQUIRE_USER_VERIFICATION_HASH == "false"
),
}),
agents: new DefaultAgentManager(
{
default: {
agent: new AgentHTTPClient(
`${proxyUrl}?agentId=${"MS3BCizycRqJe84tqqzkqxQ5g%2BGJ25oAuImc"}`
),
metadata: {
displayName: "Echo Agent",
primer:
"This is demo echo agent. Write me a message, and I will send it back to you!",
},
},
},
"default"
),
});

await backend.init(app, httpServer);

console.log(`Starting server on port ${port}...`);
httpServer.listen(parseInt(port), host, () => {
console.log(`Server is running on http://${host}:${port}/graphql`);
});
};

try {
main();
} catch (err) {
console.error(err);
}
18 changes: 9 additions & 9 deletions examples/fe-example-react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<>
<ConvoStackWrapper>
<ConvoStackWidget
graphqlUrl="http://localhost:3033/graphql"
websocketUrl="ws://localhost:3033/graphql"
workspaceId="clijh54bz0009wud1v4yhrt8o"
userData={{
email: "m@sdfgfsdgg.com",
name: "zxx",
hash: "z420",
userId: "mmsxsddfmm",
}}
graphqlUrl="http://localhost:3000/graphql"
websocketUrl="ws://localhost:3000/graphql"
// workspaceId="clijh54bz0009wud1v4yhrt8o"
// userData={{
// email: "m@sdfgfsdgg.com",
// name: "zxx",
// hash: "z420",
// userId: "mmsxsddfmm",
// }}
customStyling={{
headerText: "My Custom Header",
widgetLocation: "right",
Expand Down
2 changes: 1 addition & 1 deletion examples/fe-example-react/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

Loading