Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2fc6235

Browse files
Add packages for one-line hosted playground
1 parent e281e83 commit 2fc6235

File tree

21 files changed

+619
-62
lines changed

21 files changed

+619
-62
lines changed

‎examples/be-example-express-sqlite/proxy-server/.idea/workspace.xml‎

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import {ConvoStackBackendExpress} from "convostack/backend-express";
2+
import express from "express";
3+
import {StorageEnginePrismaSQLite} from "convostack/storage-engine-prisma-sqlite";
4+
import cors, {CorsOptions} from "cors";
5+
import {AuthJWT} from "convostack/auth-jwt";
6+
import {createServer} from "http";
7+
import * as dotenv from "dotenv";
8+
import {DefaultAgentManager} from "convostack/agent";
9+
import {IStorageEngine, IConversationEventServiceOptions} from "convostack/models";
10+
import {StorageEnginePrismaPostgres} from "convostack/storage-engine-prisma-postgres";
11+
import {StorageEnginePrismaMySQL} from "convostack/storage-engine-prisma-mysql";
12+
import {RedisPubSub} from "graphql-redis-subscriptions";
13+
import Redis, {RedisOptions} from "ioredis";
14+
import {AgentHTTPClient} from "convostack/agent-http";
15+
16+
dotenv.config();
17+
18+
const port = process.env.PORT || "3000";
19+
const host = process.env.HOST || "localhost";
20+
const proxyUrl = 'http://localhost:8088/client'
21+
console.log("Configuring server...");
22+
23+
const corsOptions: CorsOptions = {
24+
origin: ["http://localhost:5173", "https://studio.apollographql.com"],
25+
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
26+
preflightContinue: false,
27+
optionsSuccessStatus: 204
28+
};
29+
30+
const main = async () => {
31+
const app = express();
32+
app.use(cors(corsOptions));
33+
const httpServer = createServer(app);
34+
35+
let storage: IStorageEngine;
36+
switch (process.env.STORAGE_ENGINE) {
37+
case 'sqlite':
38+
storage = new StorageEnginePrismaSQLite(process.env.DATABASE_URL);
39+
await (storage as StorageEnginePrismaSQLite).init();
40+
break;
41+
case 'postgres':
42+
storage = new StorageEnginePrismaPostgres(process.env.DATABASE_URL);
43+
await (storage as StorageEnginePrismaPostgres).init();
44+
break;
45+
case 'mysql':
46+
storage = new StorageEnginePrismaMySQL(process.env.DATABASE_URL);
47+
await (storage as StorageEnginePrismaMySQL).init();
48+
break;
49+
default:
50+
throw new Error(`Invalid storage engine: ${process.env.STORAGE_ENGINE}`)
51+
}
52+
53+
const convEventsOpts = {} as IConversationEventServiceOptions;
54+
if (process.env.REDIS_URL) {
55+
convEventsOpts.pubSubEngine = new RedisPubSub({
56+
connection: process.env.REDIS_URL
57+
});
58+
convEventsOpts.cache = new Redis(process.env.REDIS_URL);
59+
}
60+
61+
const backend = new ConvoStackBackendExpress({
62+
basePath: "/",
63+
storage,
64+
auth: new AuthJWT(storage, {
65+
jwtSecret: process.env.JWT_SECRET,
66+
userDataVerificationSecret: process.env.USER_VERIFICATION_HASH_SECRET,
67+
allowAnonUsers: process.env.ALLOW_ANONYMOUS_USERS == "true",
68+
requireUserVerificationHash: !(
69+
process.env.REQUIRE_USER_VERIFICATION_HASH == "false"
70+
)
71+
}),
72+
agents: new DefaultAgentManager({
73+
"default": {
74+
agent: new AgentHTTPClient(`${proxyUrl}?agentId=${encodeURIComponent('rjKv1v2JHNrwZdWzPP+YOJvsTR11N+7HfItM')}`),
75+
metadata: {
76+
displayName: "Echo Agent",
77+
primer: "This is demo echo agent. Write me a message, and I will send it back to you!"
78+
}
79+
}
80+
}, "default"),
81+
});
82+
83+
await backend.init(app, httpServer);
84+
85+
console.log(`Starting server on port ${port}...`);
86+
httpServer.listen(parseInt(port), host, () => {
87+
console.log(`Server is running on http://${host}:${port}/graphql`);
88+
});
89+
};
90+
91+
try {
92+
main();
93+
} catch (err) {
94+
console.error(err);
95+
}

‎examples/fe-example-react/src/main.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
1313
<>
1414
<ConvoStackWrapper>
1515
<ConvoStackWidget
16-
graphqlUrl="http://localhost:3033/graphql"
17-
websocketUrl="ws://localhost:3033/graphql"
18-
workspaceId="clijh54bz0009wud1v4yhrt8o"
19-
userData={{
20-
email: "m@sdfgfsdgg.com",
21-
name: "zxx",
22-
hash: "z420",
23-
userId: "mmsxsddfmm",
24-
}}
16+
graphqlUrl="http://localhost:3000/graphql"
17+
websocketUrl="ws://localhost:3000/graphql"
18+
// workspaceId="clijh54bz0009wud1v4yhrt8o"
19+
// userData={{
20+
// email: "m@sdfgfsdgg.com",
21+
// name: "zxx",
22+
// hash: "z420",
23+
// userId: "mmsxsddfmm",
24+
// }}
2525
customStyling={{
2626
headerText: "My Custom Header",
2727
widgetLocation: "right",

‎examples/fe-example-react/tsconfig.tsbuildinfo‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /