diff --git a/.changeset/cuddly-mangos-train.md b/.changeset/cuddly-mangos-train.md new file mode 100644 index 0000000..521dadb --- /dev/null +++ b/.changeset/cuddly-mangos-train.md @@ -0,0 +1,6 @@ +--- +'@callstack/byorg-discord': minor +'discord-example': minor +--- + +discord: changed passing bot token variable and discord login diff --git a/docs/src/docs/core/system-prompt.md b/docs/src/docs/core/system-prompt.md index 5b0b795..c1bf0ea 100644 --- a/docs/src/docs/core/system-prompt.md +++ b/docs/src/docs/core/system-prompt.md @@ -20,7 +20,7 @@ export const systemPrompt = (context: RequestContext): Promise | string let date = new Date().toDateString(); let userName = context.extras.userName; - return `You are a helpful AI bot. Your name is Cassandra. You work for Callstack. + return `You are a helpful AI bot. Your name is Byorg. You work for ACME. Current date: ${date} You are talking with: ${userName}`; }; diff --git a/docs/src/docs/core/usage.mdx b/docs/src/docs/core/usage.mdx index 5a5b530..df26474 100644 --- a/docs/src/docs/core/usage.mdx +++ b/docs/src/docs/core/usage.mdx @@ -33,7 +33,7 @@ Here is step by step how to start with byorg. import { RequestContext } from '@callstack/byorg-core'; const systemPrompt = (context: RequestContext): Promise | string => { - return "You are a helpful AI assistant named Cassandra"; + return "You are a helpful AI assistant named Byorg"; }; ``` ### Create an Application instance diff --git a/examples/bare/package.json b/examples/bare/package.json index 476e425..2e97bf1 100644 --- a/examples/bare/package.json +++ b/examples/bare/package.json @@ -12,8 +12,8 @@ }, "dependencies": { "@ai-sdk/openai": "^1.0.2", - "@callstack/byorg-core": "0.4.2", - "@callstack/byorg-utils": "0.4.2" + "@callstack/byorg-core": "workspace:*", + "@callstack/byorg-utils": "workspace:*" }, "devDependencies": { "dotenv-cli": "^7.4.2", diff --git a/examples/discord/package.json b/examples/discord/package.json index 1177eaa..1973d27 100644 --- a/examples/discord/package.json +++ b/examples/discord/package.json @@ -14,14 +14,15 @@ }, "dependencies": { "@ai-sdk/openai": "^1.0.2", - "@callstack/byorg-core": "0.4.2", - "@callstack/byorg-discord": "0.4.2", - "@callstack/byorg-utils": "0.4.2" + "@callstack/byorg-core": "workspace:*", + "@callstack/byorg-discord": "workspace:*", + "@callstack/byorg-utils": "workspace:*", + "zlib-sync": "^0.1.9" }, "devDependencies": { - "dotenv-cli": "^7.4.2", "@callstack/eslint-config": "^14.2.0", "@rsbuild/core": "^1.0.5", + "dotenv-cli": "^7.4.2", "eslint": "^8.57.0", "prettier": "^3.3.3", "typescript": "^5.6.3" diff --git a/examples/discord/rsbuild.config.ts b/examples/discord/rsbuild.config.ts index 3a80ae0..8585ad5 100644 --- a/examples/discord/rsbuild.config.ts +++ b/examples/discord/rsbuild.config.ts @@ -28,6 +28,11 @@ export default defineConfig({ '.js': ['.js', '.ts'], }, }, + ignoreWarnings: [ + /the request of a dependency is an expression/, + /Can't resolve 'bufferutil'/, + /Can't resolve 'utf-8-validate'/, + ], }, }, }); diff --git a/examples/discord/src/index.ts b/examples/discord/src/index.ts index 06ba3fc..21615cf 100644 --- a/examples/discord/src/index.ts +++ b/examples/discord/src/index.ts @@ -1,33 +1,37 @@ -// TODO -// import readline from 'readline'; -// import { Message, VercelChatModelAdapter, createApp } from '@callstack/byorg-core'; -// import { createOpenAI } from '@ai-sdk/openai'; -// import { requireEnv } from '@callstack/byorg-utils'; -// import { createDiscordApp } from '@callstack/byorg-discord'; +import { VercelChatModelAdapter, createApp } from '@callstack/byorg-core'; +import { createOpenAI } from '@ai-sdk/openai'; +import { logger, requireEnv } from '@callstack/byorg-utils'; +import { createDiscordApp } from '@callstack/byorg-discord'; -// const LANGUAGE_MODEL = 'gpt-4o-2024-11-20'; -// const API_KEY = requireEnv('OPENAI_API_KEY'); +const LANGUAGE_MODEL = 'gpt-4o-2024-11-20'; +const API_KEY = requireEnv('OPENAI_API_KEY'); +const DISCORD_BOT_TOKEN = requireEnv('DISCORD_BOT_TOKEN'); -// const openAiProvider = createOpenAI({ -// apiKey: API_KEY, -// compatibility: 'strict', // strict mode, enable when using the OpenAI API -// }); +const openAiProvider = createOpenAI({ + apiKey: API_KEY, + compatibility: 'strict', // strict mode, enable when using the OpenAI API +}); -// const openAiModel = openAiProvider.languageModel(LANGUAGE_MODEL); +const chatModel = new VercelChatModelAdapter({ + languageModel: openAiProvider.languageModel(LANGUAGE_MODEL), +}); -// const chatModel = new VercelChatModelAdapter({ -// languageModel: openAiModel, -// }); +const systemPrompt = () => { + return 'Your name is Byorg. You are a helpful AI Assistant.'; +}; -// const systemPrompt = () => { -// return 'Your name is Cassandra. You are an AI Assistant.'; -// }; +const app = createApp({ + chatModel, + systemPrompt, +}); -// const app = createApp({ -// chatModel, -// systemPrompt, -// }); +const discord = await createDiscordApp({ app }); -// // const discord = createDiscordApp({ -// // app, -// // }); +void (async () => { + try { + await discord.login(DISCORD_BOT_TOKEN); + logger.info('Discord ready.'); + } catch (error) { + logger.error('Dev Slack start error:', error); + } +})(); diff --git a/examples/slack/package.json b/examples/slack/package.json index c337e96..29b62ef 100644 --- a/examples/slack/package.json +++ b/examples/slack/package.json @@ -14,9 +14,9 @@ }, "dependencies": { "@ai-sdk/openai": "^1.0.2", - "@callstack/byorg-core": "0.4.2", - "@callstack/byorg-slack": "0.4.2", - "@callstack/byorg-utils": "0.4.2" + "@callstack/byorg-core": "workspace:*", + "@callstack/byorg-slack": "workspace:*", + "@callstack/byorg-utils": "workspace:*" }, "devDependencies": { "dotenv-cli": "^7.4.2", diff --git a/packages/core/package.json b/packages/core/package.json index 83db772..547aac2 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -29,7 +29,7 @@ "test:watch": "vitest" }, "dependencies": { - "@callstack/byorg-utils": "workspace:^*", + "@callstack/byorg-utils": "workspace:*", "ts-regex-builder": "^1.8.2", "zod": "^3.23.8" }, diff --git a/packages/discord/package.json b/packages/discord/package.json index b6dbd7a..1fc7ed2 100644 --- a/packages/discord/package.json +++ b/packages/discord/package.json @@ -27,7 +27,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@callstack/byorg-core": "workspace:^*", + "@callstack/byorg-core": "workspace:*", "discord-interactions": "^4.1.0", "discord.js": "^14.15.3" }, diff --git a/packages/discord/src/index.ts b/packages/discord/src/index.ts index 961e4c5..214d2f3 100644 --- a/packages/discord/src/index.ts +++ b/packages/discord/src/index.ts @@ -8,10 +8,9 @@ export type DiscordApplicationConfig = { app: Application; }; -export async function createDiscordApp(options: DiscordApplicationConfig) { +export function createDiscordApp(options: DiscordApplicationConfig) { const { app } = options; - const botToken = process.env['DISCORD_BOT_TOKEN'] as string; const client = new Client({ intents: [ GatewayIntentBits.DirectMessages, @@ -76,8 +75,6 @@ export async function createDiscordApp(options: DiscordApplicationConfig) { await pendingEffects; }); - await client.login(botToken); - return client; } diff --git a/packages/document-loaders/package.json b/packages/document-loaders/package.json index 0a81810..35a74be 100644 --- a/packages/document-loaders/package.json +++ b/packages/document-loaders/package.json @@ -27,7 +27,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@callstack/byorg-utils": "workspace:^*", + "@callstack/byorg-utils": "workspace:*", "@google-cloud/local-auth": "^3.0.1", "@notionhq/client": "^2.2.15", "google-auth-library": "^9.14.1", diff --git a/packages/slack/package.json b/packages/slack/package.json index 5f49a61..b1c7b73 100644 --- a/packages/slack/package.json +++ b/packages/slack/package.json @@ -29,9 +29,9 @@ "test:watch": "vitest" }, "dependencies": { - "@callstack/byorg-core": "workspace:^*", - "@callstack/byorg-utils": "workspace:^*", - "@callstack/slack-rich-text": "workspace:^*", + "@callstack/byorg-core": "workspace:*", + "@callstack/byorg-utils": "workspace:*", + "@callstack/slack-rich-text": "workspace:*", "@slack/bolt": "^3.21.1", "@slack/web-api": "^6.12.1", "p-debounce": "^4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18af79f..776eec7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,11 +88,11 @@ importers: specifier: ^1.0.2 version: 1.0.2(zod@3.23.8) '@callstack/byorg-core': - specifier: 0.4.2 - version: 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) + specifier: workspace:* + version: link:../../packages/core '@callstack/byorg-utils': - specifier: 0.4.2 - version: 0.4.2 + specifier: workspace:* + version: link:../../packages/utils devDependencies: '@callstack/eslint-config': specifier: ^14.2.0 @@ -119,14 +119,17 @@ importers: specifier: ^1.0.2 version: 1.0.2(zod@3.23.8) '@callstack/byorg-core': - specifier: 0.4.2 - version: 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) + specifier: workspace:* + version: link:../../packages/core '@callstack/byorg-discord': - specifier: 0.4.2 - version: 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) + specifier: workspace:* + version: link:../../packages/discord '@callstack/byorg-utils': - specifier: 0.4.2 - version: 0.4.2 + specifier: workspace:* + version: link:../../packages/utils + zlib-sync: + specifier: ^0.1.9 + version: 0.1.9 devDependencies: '@callstack/eslint-config': specifier: ^14.2.0 @@ -153,14 +156,14 @@ importers: specifier: ^1.0.2 version: 1.0.2(zod@3.23.8) '@callstack/byorg-core': - specifier: 0.4.2 - version: 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) + specifier: workspace:* + version: link:../../packages/core '@callstack/byorg-slack': - specifier: 0.4.2 - version: 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) + specifier: workspace:* + version: link:../../packages/slack '@callstack/byorg-utils': - specifier: 0.4.2 - version: 0.4.2 + specifier: workspace:* + version: link:../../packages/utils devDependencies: '@callstack/eslint-config': specifier: ^14.2.0 @@ -184,7 +187,7 @@ importers: packages/core: dependencies: '@callstack/byorg-utils': - specifier: workspace:^* + specifier: workspace:* version: link:../utils ts-regex-builder: specifier: ^1.8.2 @@ -209,7 +212,7 @@ importers: packages/discord: dependencies: '@callstack/byorg-core': - specifier: workspace:^* + specifier: workspace:* version: link:../core discord-interactions: specifier: ^4.1.0 @@ -228,7 +231,7 @@ importers: packages/document-loaders: dependencies: '@callstack/byorg-utils': - specifier: workspace:^* + specifier: workspace:* version: link:../utils '@google-cloud/local-auth': specifier: ^3.0.1 @@ -277,13 +280,13 @@ importers: packages/slack: dependencies: '@callstack/byorg-core': - specifier: workspace:^* + specifier: workspace:* version: link:../core '@callstack/byorg-utils': - specifier: workspace:^* + specifier: workspace:* version: link:../utils '@callstack/slack-rich-text': - specifier: workspace:^* + specifier: workspace:* version: link:../slack-rich-text '@slack/bolt': specifier: ^3.21.1 @@ -600,20 +603,6 @@ packages: '@bufbuild/protobuf@2.2.2': resolution: {integrity: sha512-UNtPCbrwrenpmrXuRwn9jYpPoweNXj8X5sMvYgsqYyaH8jQ6LfUJSk3dJLnBK+6sfYPrF4iAIo5sd5HQ+tg75A==} - '@callstack/byorg-core@0.4.2': - resolution: {integrity: sha512-RS/4QpX54O1/8KsEi8itncfFCraKzGMpqcnt7SQZTTBRvCtkctE7GfXuJYdFjirypUBFs4AgbsJCcYlYgc7PIw==} - peerDependencies: - ai: ^4.0.3 - - '@callstack/byorg-discord@0.4.2': - resolution: {integrity: sha512-yKI8fmTXQqsnczv/dYXsCBapge2Rygr9vpYbYhJ8iRVDymCpoYQr3hjDCacKSATX4rlz5r2IvHrYWSiduvBU6Q==} - - '@callstack/byorg-slack@0.4.2': - resolution: {integrity: sha512-RuFyn8R/9cQGaJhmUTTGkNk+ISpzWYsf9hGm9ymjMFrPtuuB2aKfudC3l3K0/A/je6cwLsQw+GbPbcwrn8UT+A==} - - '@callstack/byorg-utils@0.4.2': - resolution: {integrity: sha512-7nFLUT9w1iRyu2LPEjmOhRoEanrt0QDWaHFlD9uU6hlmhnEb2PLjTPHkQLqkd65qO6Nb4j9kxlSpqmjpqjdGiw==} - '@callstack/eslint-config@14.2.0': resolution: {integrity: sha512-q3Qu/dct79wUHI6DqLWJP8/On+NOIP72hndrFQocbVd+MQVvwR3Vc1G6w0qyIujHe3Cm4MCZc9yn+pEPGX2msw==} engines: {node: '>=18.0.0'} @@ -626,11 +615,6 @@ packages: peerDependencies: eslint: '>=8.1.0' - '@callstack/slack-rich-text@0.4.2': - resolution: {integrity: sha512-mPToRxJCkVuOMbWZqOUI0vLNXoVw2TMzjOn0UtSXJjphBROo05N4ARt6rEREjYw5yd+vYtyQpRbgRuh7Ub6d0Q==} - peerDependencies: - '@slack/web-api': ^6.11.2 - '@changesets/apply-release-plan@7.0.6': resolution: {integrity: sha512-TKhVLtiwtQOgMAC0fCJfmv93faiViKSDqr8oMEqrnNs99gtSC1sZh/aEMS9a+dseU1ESZRCK+ofLgGY7o0fw/Q==} @@ -5830,6 +5814,9 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} + zlib-sync@0.1.9: + resolution: {integrity: sha512-DinB43xCjVwIBDpaIvQqHbmDsnYnSt6HJ/yiB2MZQGTqgPcwBSZqLkimXwK8BvdjQ/MaZysb5uEenImncqvCqQ==} + zod-to-json-schema@3.23.5: resolution: {integrity: sha512-5wlSS0bXfF/BrL4jPAbz9da5hDlDptdEppYfe+x4eIJ7jioqKG9uUxOwPzqof09u/XeVdrgFu29lZi+8XNDJtA==} peerDependencies: @@ -6133,41 +6120,6 @@ snapshots: '@bufbuild/protobuf@2.2.2': {} - '@callstack/byorg-core@0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8))': - dependencies: - '@callstack/byorg-utils': 0.4.2 - ai: 4.0.3(react@18.3.1)(zod@3.23.8) - ts-regex-builder: 1.8.2 - zod: 3.23.8 - - '@callstack/byorg-discord@0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8))': - dependencies: - '@callstack/byorg-core': 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) - discord-interactions: 4.1.0 - discord.js: 14.16.3 - transitivePeerDependencies: - - ai - - bufferutil - - utf-8-validate - - '@callstack/byorg-slack@0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8))': - dependencies: - '@callstack/byorg-core': 0.4.2(ai@4.0.3(react@18.3.1)(zod@3.23.8)) - '@callstack/byorg-utils': 0.4.2 - '@callstack/slack-rich-text': 0.4.2(@slack/web-api@6.13.0) - '@slack/bolt': 3.22.0 - '@slack/web-api': 6.13.0 - p-debounce: 4.0.0 - ts-regex-builder: 1.8.2 - transitivePeerDependencies: - - ai - - bufferutil - - debug - - supports-color - - utf-8-validate - - '@callstack/byorg-utils@0.4.2': {} - '@callstack/eslint-config@14.2.0(@types/eslint@9.6.1)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.5.0(eslint@8.57.1)(typescript@5.7.2))(eslint-plugin-import@2.31.0)(eslint@8.57.1))(eslint@8.57.1)(jest@29.7.0(@types/node@22.9.1)(ts-node@10.9.2(@types/node@22.9.1)(typescript@5.7.2)))(typescript@5.6.3)': dependencies: '@babel/core': 7.25.2 @@ -6230,13 +6182,6 @@ snapshots: - supports-color - typescript - '@callstack/slack-rich-text@0.4.2(@slack/web-api@6.13.0)': - dependencies: - '@slack/web-api': 6.13.0 - date-fns: 3.6.0 - marked: 14.1.3 - ts-regex-builder: 1.8.2 - '@changesets/apply-release-plan@7.0.6': dependencies: '@changesets/config': 3.0.4 @@ -11120,8 +11065,7 @@ snapshots: ms@2.1.3: {} - nan@2.22.0: - optional: true + nan@2.22.0: {} nanoid@3.3.7: {} @@ -12740,6 +12684,10 @@ snapshots: yocto-queue@0.1.0: {} + zlib-sync@0.1.9: + dependencies: + nan: 2.22.0 + zod-to-json-schema@3.23.5(zod@3.23.8): dependencies: zod: 3.23.8