Skip to content

Commit fc8cd6e

Browse files
committed
feat: rename auth-example to full-cycle-example, enhance GraphQL client integration, and add environment configuration
1 parent 4e945ee commit fc8cd6e

7 files changed

Lines changed: 168 additions & 35 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REST_API_URL=https://api.badai.io/graphql
2+
WS_API_URL=wss://api.badai.io/graphql-ws
3+
AGENT_ID=260ec0fe-92ae-4693-92a5-097364196a06
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
*storybook.log
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@badaitech/badai-api-example",
3+
"type": "module",
4+
"version": "0.5.5-dev.20",
5+
"private": true,
6+
"description": "Bad AI GraphQL API client example",
7+
"license": "BUSL-1.1",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com//badaitech/chaingraph.git",
11+
"directory": "./packages/badai-api-example"
12+
},
13+
"scripts": {
14+
"run": "bun run src/full-cycle-example.ts",
15+
"typecheck": "tsc -b"
16+
},
17+
"publishConfig": {
18+
"registry": "https://npm.pkg.github.com"
19+
},
20+
"dependencies": {
21+
"@badaitech/badai-api": "workspace:*",
22+
"@types/node": "^22.14.0",
23+
"graphql": "^16.11.0",
24+
"graphql-request": "^7.2.0",
25+
"graphql-ws": "^6.0.6",
26+
"keccak256": "^1.0.6",
27+
"viem": "^2.37.7"
28+
},
29+
"devDependencies": {
30+
"@badaitech/typescript-config": "workspace:*"
31+
}
32+
}

packages/badai-api/src/auth-example.ts renamed to packages/badai-api-example/src/full-cycle-example.ts

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
77
*/
88

9-
import type { MessageEvent } from './gql/client/graphql'
109
import process from 'node:process'
10+
import { createGraphQLClient, GraphQL } from '@badaitech/badai-api'
1111
import { print } from 'graphql'
12-
import {
13-
createClient,
14-
15-
} from 'graphql-ws'
12+
import { createClient } from 'graphql-ws'
1613
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
17-
import { createGraphQLClient } from './gql/client'
18-
import { Event } from './gql/client/graphql'
19-
// import { SubscribeMessagesDocument } from './gql/client/graphql'
20-
import { GraphQL } from './index'
2114

22-
const restApiUrl = process.env.REST_API_URL ?? 'http://localhost:9151/graphql'
15+
const restApiUrl = process.env.REST_API_URL ?? 'http://localhost:9151/graphql' // ?? 'http://localhost:9151/graphql'
2316
const wsApiUrl = process.env.WS_API_URL ?? 'ws://localhost:9151/graphql'
17+
const agentId = process.env.AGENT_ID ?? ''
2418

2519
let activeSocket: WebSocket | null = null
2620
let pingTimeout: ReturnType<typeof setTimeout> | null = null
@@ -176,6 +170,7 @@ async function main() {
176170
GraphQL.CreateChatRoomDocument,
177171
{
178172
session,
173+
agents: [agentId],
179174
},
180175
)
181176

@@ -187,6 +182,8 @@ async function main() {
187182
resolveMessageFinished = resolve
188183
})
189184

185+
let agentResponse = ''
186+
190187
const cancel = wsClient.subscribe(
191188
{
192189
query: print(GraphQL.SubscribeMessagesDocument),
@@ -197,16 +194,51 @@ async function main() {
197194
},
198195
},
199196
{
200-
next: ({ data }) => {
201-
console.log('Subscription data:', JSON.stringify(data, null, 2))
197+
next: async ({ data }) => {
198+
// console.log('Subscription data:', JSON.stringify(data, null, 2))
202199
if (!data?.subscribeMessages)
203200
return
204201

205-
const event = data.subscribeMessages as MessageEvent
202+
const event = data.subscribeMessages as GraphQL.MessageEvent
206203

207204
switch (event.event) {
208-
case Event.MessageFinished:
209-
resolveMessageFinished()
205+
case GraphQL.Event.Subscribed: {
206+
// send message to the chat room from the user we just created
207+
console.log('Subscription confirmed, sending message...')
208+
const { sendMessage } = await restClient.request(
209+
GraphQL.SendMessageDocument,
210+
{
211+
session,
212+
chat_id: createChatRoom.id,
213+
message: {
214+
is_system: false,
215+
finished: true,
216+
need_answer: true,
217+
text: 'Find in the web the current weather in Paris.',
218+
},
219+
},
220+
)
221+
222+
console.log('Sent Message:', sendMessage)
223+
}
224+
break
225+
226+
case GraphQL.Event.MessageCreated:
227+
console.log(`Message Created by @${event.message?.participant?.username}: ${event.message?.text || '<no text>'} with version ${event.message?.version}`)
228+
break
229+
230+
case GraphQL.Event.MessageDeltaAdd:
231+
if (event.message?.participant?.is_agent) {
232+
console.log(`Message Delta Add by @${event.message?.participant?.username} [${event.message?.version}]: ${event.message?.text}`)
233+
}
234+
break
235+
236+
case GraphQL.Event.MessageFinished:
237+
if (event.message?.participant?.is_agent) {
238+
agentResponse = event.message.text
239+
resolveMessageFinished()
240+
}
241+
210242
break
211243
}
212244
},
@@ -221,28 +253,14 @@ async function main() {
221253
},
222254
)
223255

224-
// send message to the chat room
225-
const { sendMessage } = await restClient.request(
226-
GraphQL.SendMessageDocument,
227-
{
228-
session,
229-
chat_id: createChatRoom.id,
230-
message: {
231-
is_system: false,
232-
finished: true,
233-
need_answer: true,
234-
text: 'Hello, world!',
235-
},
236-
},
237-
)
238-
239-
console.log('Sent Message:', sendMessage)
240-
241256
// Wait for MessageFinished event
242257
console.log('Waiting for MessageFinished event...')
243258
await onMessageFinishedPromise
244259
console.log('MessageFinished event received, shutting down gracefully...')
245260

261+
console.log('\n\n--- Summary ---')
262+
console.log('Agent response:', agentResponse)
263+
246264
// Clean up
247265
cancel()
248266
wsClient.dispose()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "@badaitech/typescript-config/base.json",
4+
"compilerOptions": {
5+
"jsx": "react-jsx",
6+
"lib": ["dom", "ESNext", "ESNext.AsyncIterable"],
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"baseUrl": ".",
10+
"rootDir": "./src",
11+
"paths": {
12+
"@badaitech/typescript-config/*": ["../typescript-config/*"],
13+
"@badaitech/badai-api/*": ["../badai-api/src/*"]
14+
},
15+
/** Emit types for internal packages to speed up editor performance. */
16+
"declaration": true,
17+
"declarationMap": true,
18+
"emitDeclarationOnly": false,
19+
"outDir": "dist"
20+
},
21+
"include": ["src"],
22+
"exclude": [
23+
"node_modules",
24+
"dist"
25+
]
26+
}

packages/chaingraph-executor/server/implementations/distributed/KafkaTaskQueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class KafkaTaskQueue implements ITaskQueue {
8383
minBytes: 1, // fetch.min.bytes equivalent - fetch even single bytes
8484
maxBytes: 52428800, // fetch.max.bytes equivalent - 50MB max fetch
8585
maxBytesPerPartition: 10485760, // max.partition.fetch.bytes equivalent - 10MB per partition
86-
readUncommitted: true, // Read only committed messages
86+
readUncommitted: false, // Read only committed messages
8787
allowAutoTopicCreation: false,
8888
retry: {
8989
initialRetryTime: 100,

pnpm-lock.yaml

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)