├── .husky └── pre-commit ├── .npmrc ├── packages ├── baseai │ ├── src │ │ ├── data │ │ │ └── constants.ts │ │ ├── dev │ │ │ ├── utils │ │ │ │ ├── constants.ts │ │ │ │ ├── thread │ │ │ │ │ └── get-few-shot-messages.ts │ │ │ │ └── is-json-mode.ts │ │ │ ├── routes │ │ │ │ └── base.ts │ │ │ ├── hono │ │ │ │ ├── env.ts │ │ │ │ └── validate.ts │ │ │ ├── middleware │ │ │ │ ├── pre-flight.ts │ │ │ │ ├── post-only.ts │ │ │ │ ├── powered-by.ts │ │ │ │ ├── custom-cors.ts │ │ │ │ ├── logger.ts │ │ │ │ └── debug-base.ts │ │ │ └── providers │ │ │ │ ├── groq │ │ │ │ ├── index.ts │ │ │ │ ├── api.ts │ │ │ │ └── chatComplete.ts │ │ │ │ ├── cohere │ │ │ │ ├── api.ts │ │ │ │ └── index.ts │ │ │ │ ├── openai │ │ │ │ ├── index.ts │ │ │ │ └── api.ts │ │ │ │ ├── together-ai │ │ │ │ ├── index.ts │ │ │ │ └── api.ts │ │ │ │ ├── mistral-ai │ │ │ │ ├── api.ts │ │ │ │ └── index.ts │ │ │ │ ├── ollama │ │ │ │ ├── api.ts │ │ │ │ └── index.ts │ │ │ │ ├── perplexity │ │ │ │ ├── api.ts │ │ │ │ └── index.ts │ │ │ │ ├── google │ │ │ │ └── index.ts │ │ │ │ ├── fireworks-ai │ │ │ │ ├── api.ts │ │ │ │ └── index.ts │ │ │ │ └── anthropic │ │ │ │ ├── index.ts │ │ │ │ └── api.ts │ │ ├── utils │ │ │ ├── exit.ts │ │ │ ├── icons.ts │ │ │ ├── heading.ts │ │ │ ├── ts-format-code.ts │ │ │ ├── memory │ │ │ │ ├── get-available-memories.ts │ │ │ │ └── check-memory-exist.ts │ │ │ ├── get-available-tools.ts │ │ │ ├── get-available-pipes.ts │ │ │ ├── is-tool-present.ts │ │ │ ├── debug-mode.ts │ │ │ └── logger-utils.ts │ │ └── memory │ │ │ └── list.ts │ ├── .prettierrc.json │ ├── bin │ │ └── baseai.js │ ├── tsup.config.ts │ └── types │ │ ├── tools.ts │ │ └── config.ts └── core │ ├── src │ ├── data │ │ └── constants.ts │ ├── pipes │ │ └── index.ts │ ├── helpers │ │ ├── index.ts │ │ └── logger.ts │ ├── react │ │ └── index.ts │ ├── index.ts │ └── utils │ │ └── is-prod.ts │ ├── .env.example │ ├── types │ ├── index.ts │ ├── tools.ts │ ├── memory.ts │ └── config.ts │ ├── .gitignore │ ├── turbo.json │ ├── vitest.ui.react.config.js │ ├── .eslintrc.js │ ├── vitest.node.config.js │ ├── vitest.edge.config.js │ └── tsconfig.json ├── DEPLOY ├── examples ├── astro │ ├── src │ │ ├── env.d.ts │ │ ├── pages │ │ │ ├── index.astro │ │ │ ├── demo │ │ │ │ ├── memory │ │ │ │ │ └── index.astro │ │ │ │ ├── pipe-run │ │ │ │ │ └── index.astro │ │ │ │ ├── chat-simple │ │ │ │ │ └── index.astro │ │ │ │ ├── pipe-run-stream │ │ │ │ │ └── index.astro │ │ │ │ ├── tool-calling │ │ │ │ │ └── index.astro │ │ │ │ ├── chat-advanced │ │ │ │ │ └── index.astro │ │ │ │ └── pipe-run-pipes-as-tools │ │ │ │ │ └── index.astro │ │ │ └── api │ │ │ │ └── langbase │ │ │ │ └── pipes │ │ │ │ ├── run.ts │ │ │ │ ├── run-tool.ts │ │ │ │ ├── run-pipes-as-tools.ts │ │ │ │ ├── run-stream.ts │ │ │ │ └── run-memory.ts │ │ ├── components │ │ │ ├── ui │ │ │ │ ├── go-home.tsx │ │ │ │ └── input.tsx │ │ │ └── pages │ │ │ │ ├── memory │ │ │ │ └── index.tsx │ │ │ │ ├── chat-simple │ │ │ │ └── index.tsx │ │ │ │ ├── pipe-run │ │ │ │ └── index.tsx │ │ │ │ ├── pipe-stream │ │ │ │ └── index.tsx │ │ │ │ ├── tool-calling │ │ │ │ └── index.tsx │ │ │ │ ├── chat-advanced │ │ │ │ └── index.tsx │ │ │ │ └── pipe-run-pipes-as-tools │ │ │ │ └── index.tsx │ │ ├── middleware.ts │ │ ├── layouts │ │ │ └── Layout.astro │ │ └── lib │ │ │ └── utils.ts │ ├── public │ │ ├── favicon.ico │ │ └── favicon.svg │ ├── tsconfig.json │ ├── baseai │ │ ├── memory │ │ │ └── chat-with-docs │ │ │ │ └── index.ts │ │ ├── baseai.config.ts │ │ ├── tools │ │ │ ├── weather.ts │ │ │ ├── calculator.ts │ │ │ ├── pipe-call.ts │ │ │ └── pipe-call-maths.ts │ │ └── pipes │ │ │ ├── summary.ts │ │ │ └── pipe-with-tool.ts │ ├── .gitignore │ ├── astro.config.ts │ └── .env.baseai.example ├── nextjs │ ├── .eslintrc.json │ ├── app │ │ ├── favicon.ico │ │ ├── demo │ │ │ ├── chat-simple │ │ │ │ └── page.tsx │ │ │ ├── memory │ │ │ │ └── page.tsx │ │ │ ├── pipe-run │ │ │ │ └── page.tsx │ │ │ ├── tool-calling │ │ │ │ └── page.tsx │ │ │ ├── chat-advanced │ │ │ │ └── page.tsx │ │ │ ├── pipe-run-stream │ │ │ │ └── page.tsx │ │ │ ├── tool-calling-stream │ │ │ │ └── page.tsx │ │ │ └── pipe-run-pipes-as-tools │ │ │ │ └── page.tsx │ │ └── api │ │ │ └── langbase │ │ │ └── pipes │ │ │ ├── run-pipes-as-tools │ │ │ └── route.ts │ │ │ ├── run-tool │ │ │ └── route.ts │ │ │ ├── run-memory │ │ │ └── route.ts │ │ │ ├── run-tool-stream │ │ │ └── route.ts │ │ │ └── run │ │ │ └── route.ts │ ├── next.config.mjs │ ├── postcss.config.mjs │ ├── lib │ │ └── utils.ts │ ├── baseai │ │ ├── memory │ │ │ └── chat-with-docs │ │ │ │ └── index.ts │ │ ├── baseai.config.ts │ │ ├── tools │ │ │ ├── weather.ts │ │ │ ├── calculator.ts │ │ │ ├── pipe-call.ts │ │ │ └── pipe-call-maths.ts │ │ └── pipes │ │ │ ├── summary.ts │ │ │ ├── pipe-with-tool.ts │ │ │ └── pipe-with-tool-stream.ts │ ├── components.json │ ├── components │ │ └── ui │ │ │ ├── go-home.tsx │ │ │ └── input.tsx │ ├── public │ │ └── vercel.svg │ ├── tsconfig.json │ ├── .gitignore │ └── .env.baseai.example ├── remix │ ├── .gitignore │ ├── public │ │ ├── favicon.ico │ │ ├── logo-dark.png │ │ └── logo-light.png │ ├── postcss.config.js │ ├── app │ │ ├── lib │ │ │ └── utils.ts │ │ ├── components │ │ │ └── ui │ │ │ │ ├── go-home.tsx │ │ │ │ └── input.tsx │ │ ├── routes │ │ │ ├── api.langbase.pipes.run.ts │ │ │ ├── api.langbase.pipes.run-tool.ts │ │ │ ├── api.langbase.pipes.run-pipes-as-tools.ts │ │ │ ├── api.langbase.pipes.run-stream.ts │ │ │ ├── api.langbase.pipes.run-memory.ts │ │ │ ├── demo.chat-simple.tsx │ │ │ ├── demo.memory.tsx │ │ │ ├── demo.pipe-run.tsx │ │ │ ├── demo.tool-calling.tsx │ │ │ ├── demo.pipe-run-stream.tsx │ │ │ ├── demo.chat-advanced.tsx │ │ │ └── demo.pipe-run-pipes-as-tools.tsx │ │ └── entry.client.tsx │ ├── baseai │ │ ├── memory │ │ │ └── chat-with-docs │ │ │ │ └── index.ts │ │ ├── baseai.config.ts │ │ ├── tools │ │ │ ├── weather.ts │ │ │ ├── calculator.ts │ │ │ └── pipe-call.ts │ │ └── pipes │ │ │ ├── summary.ts │ │ │ └── pipe-with-tool.ts │ ├── vite.config.ts │ ├── .env.baseai.example │ └── tsconfig.json ├── agents │ ├── readme-writer-agent │ │ ├── .gitignore │ │ ├── utils │ │ │ ├── exec-sync.ts │ │ │ ├── get-dirname.ts │ │ │ ├── handle-error.ts │ │ │ ├── exit.ts │ │ │ ├── init.ts │ │ │ ├── heading.ts │ │ │ ├── generate-embeddings.ts │ │ │ ├── questions.ts │ │ │ ├── exit-server.ts │ │ │ ├── copy-project-files.ts │ │ │ └── start-baseai-server.ts │ │ ├── tsup.config.ts │ │ ├── baseai │ │ │ ├── memory │ │ │ │ └── code-files │ │ │ │ │ └── index.ts │ │ │ └── baseai.config.ts │ │ └── .env.baseai.example │ └── it-systems-triage-agent │ │ ├── .gitignore │ │ ├── baseai │ │ └── baseai.config.ts │ │ ├── package.json │ │ └── .env.baseai.example └── nodejs │ ├── .prettierrc │ ├── baseai │ ├── memory │ │ ├── chat-with-docs │ │ │ └── index.ts │ │ ├── chat-with-repo │ │ │ └── index.ts │ │ └── ai-agent-memory │ │ │ └── index.ts │ ├── baseai.config.ts │ └── pipes │ │ └── summary.ts │ ├── examples │ ├── pipe.generate.text.ts │ ├── pipe.run.ts │ └── pipe.stream.text.ts │ ├── .env.baseai.example │ └── package.json ├── .prettierignore ├── apps └── baseai.dev │ ├── wrangler.toml │ ├── public │ ├── caustics.jpg │ ├── email-agent.png │ ├── texture │ │ ├── panoenv.jpg │ │ ├── panoenv2.jpg │ │ ├── panoenv3.jpg │ │ ├── panoenv4.jpg │ │ ├── panoenv5.jpg │ │ ├── panoenv6.jpg │ │ ├── panoenv7.jpg │ │ ├── panoenv8.jpg │ │ └── panoenv9.jpg │ ├── AlteHaasGroteskBold.ttf │ ├── deploy │ │ ├── auth-api-dark.jpg │ │ └── auth-api-light.jpg │ └── favicon │ │ ├── 2024 │ │ ├── favicon.ico │ │ ├── mstile-70x70.png │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── mstile-144x144.png │ │ ├── mstile-150x150.png │ │ ├── mstile-310x150.png │ │ ├── mstile-310x310.png │ │ ├── apple-touch-icon.png │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ ├── browserconfig.xml │ │ └── site.webmanifest │ │ ├── old │ │ ├── favicon.ico │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── mstile-150x150.png │ │ ├── apple-touch-icon.png │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ ├── browserconfig.xml │ │ └── site.webmanifest │ │ ├── svg-black │ │ └── favicon.png │ │ └── svg-white │ │ └── favicon.png │ ├── src │ ├── app │ │ ├── favicon.ico │ │ ├── page.tsx │ │ ├── not-found.tsx │ │ ├── docs │ │ │ └── page.tsx │ │ └── learn │ │ │ └── page.tsx │ ├── data │ │ └── index.ts │ ├── mdx │ │ ├── recma.mjs │ │ ├── recma.ts │ │ ├── themes │ │ │ ├── index.mjs │ │ │ └── index.ts │ │ ├── remark.ts │ │ └── remark.mjs │ ├── types │ │ ├── mdx-annotations.d.ts │ │ └── markdown.ts │ ├── styles │ │ ├── webgl.css │ │ └── tailwind.css │ ├── lib │ │ ├── utils.ts │ │ ├── remToPx.ts │ │ ├── get-docs-by-slug.ts │ │ └── get-learn-by-slug.ts │ ├── components │ │ ├── mdx │ │ │ ├── Row.tsx │ │ │ ├── Wrapper.tsx │ │ │ ├── Properties.tsx │ │ │ ├── Col.tsx │ │ │ ├── spoiler.tsx │ │ │ ├── Property.tsx │ │ │ └── sub-property.tsx │ │ ├── icons │ │ │ ├── BoltIcon.tsx │ │ │ ├── ShirtIcon.tsx │ │ │ ├── LinkIcon.tsx │ │ │ ├── InfoIcon.tsx │ │ │ ├── CrossIcon.tsx │ │ │ ├── IconStream.tsx │ │ │ ├── MagnifyingGlassIcon.tsx │ │ │ ├── CheckIcon.tsx │ │ │ ├── BookIcon.tsx │ │ │ ├── DocumentIcon.tsx │ │ │ ├── PaperAirplaneIcon.tsx │ │ │ ├── FaceSmileIcon.tsx │ │ │ ├── ListIcon.tsx │ │ │ ├── PackageIcon.tsx │ │ │ ├── CopyIcon.tsx │ │ │ ├── PaperClipIcon.tsx │ │ │ ├── ChevronRightLeftIcon.tsx │ │ │ ├── IconFewShot.tsx │ │ │ ├── TwitterIcon.tsx │ │ │ ├── BellIcon.tsx │ │ │ ├── EnvelopeIcon.tsx │ │ │ ├── IconVersions.tsx │ │ │ ├── IconStoreMessages.tsx │ │ │ ├── CartIcon.tsx │ │ │ ├── ChatBubbleIcon.tsx │ │ │ ├── IconDoc.tsx │ │ │ ├── ShapesIcon.tsx │ │ │ ├── IconJsonMode.tsx │ │ │ ├── IconUsage.tsx │ │ │ ├── SquaresPlusIcon.tsx │ │ │ ├── MapPinIcon.tsx │ │ │ ├── CalendarIcon.tsx │ │ │ ├── ClipboardIcon.tsx │ │ │ ├── IconApi.tsx │ │ │ ├── IconKeyset.tsx │ │ │ ├── FolderIcon.tsx │ │ │ ├── IconExperiments.tsx │ │ │ ├── OpenLink.tsx │ │ │ ├── icon-up.tsx │ │ │ ├── icon-down.tsx │ │ │ ├── UsersIcon.tsx │ │ │ └── IconFork.tsx │ │ ├── ui │ │ │ ├── iconists │ │ │ │ ├── icon-usage.tsx │ │ │ │ ├── icon-api.tsx │ │ │ │ └── icon-chat.tsx │ │ │ └── icons │ │ │ │ └── info-circle.tsx │ │ ├── content.tsx │ │ ├── Prose.tsx │ │ └── HeroPattern.tsx │ ├── images │ │ └── logos │ │ │ └── ruby.svg │ ├── scripts │ │ ├── remove-runtime.js │ │ └── set-runtime.js │ └── hooks │ │ └── use-copy-to-clipboard.tsx │ ├── postcss.config.js │ ├── .eslintrc.json │ ├── prettier.config.js │ ├── components.json │ ├── next.config.mjs │ ├── types.d.ts │ ├── README.md │ ├── .gitignore │ └── content │ └── docs │ └── memory │ └── list.mdx ├── tools ├── eslint-config │ ├── README.md │ ├── CHANGELOG.md │ ├── index.js │ ├── package.json │ ├── library.js │ ├── next.js │ └── react-internal.js └── tsconfig │ ├── package.json │ ├── CHANGELOG.md │ ├── node16.json │ ├── node14.json │ ├── react-library.json │ ├── nextjs.json │ └── base.json ├── pnpm-workspace.yaml ├── .vscode └── settings.json ├── .github ├── dependabot.yml ├── SECURITY.md ├── ISSUE_TEMPLATE │ └── config.yml └── .roadmap │ └── playwright.yml ├── .eslintrc.js ├── .prettierrc ├── .gitignore ├── .changeset ├── config.json └── README.md ├── .kodiak.toml ├── LICENSE └── .env.baseai.example /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | auto-install-peers = true 2 | -------------------------------------------------------------------------------- /packages/baseai/src/data/constants.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/core/src/data/constants.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/utils/constants.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /DEPLOY: -------------------------------------------------------------------------------- 1 | Deployment at: Thu Oct 31 22:47:48 CET 2024 2 | -------------------------------------------------------------------------------- /packages/core/.env.example: -------------------------------------------------------------------------------- 1 | # Pipes. 2 | PIPE_LESS_WORDY= 3 | -------------------------------------------------------------------------------- /packages/core/src/pipes/index.ts: -------------------------------------------------------------------------------- 1 | export * from './pipes'; 2 | -------------------------------------------------------------------------------- /packages/core/src/helpers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './stream'; 2 | -------------------------------------------------------------------------------- /packages/core/src/react/index.ts: -------------------------------------------------------------------------------- 1 | export * from './use-pipe'; 2 | -------------------------------------------------------------------------------- /examples/astro/src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// -------------------------------------------------------------------------------- /examples/nextjs/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /examples/remix/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | /.cache 4 | /build 5 | .env 6 | .vercel 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .next 2 | .nuxt 3 | node_modules 4 | dist 5 | .svelte-kit 6 | .solid 7 | _nuxt 8 | -------------------------------------------------------------------------------- /apps/baseai.dev/wrangler.toml: -------------------------------------------------------------------------------- 1 | name="baseai" 2 | compatibility_flags = ['nodejs_compat_v2'] 3 | -------------------------------------------------------------------------------- /packages/core/types/index.ts: -------------------------------------------------------------------------------- 1 | export type Headers = Record; 2 | -------------------------------------------------------------------------------- /tools/eslint-config/README.md: -------------------------------------------------------------------------------- 1 | # `@turbo/eslint-config` 2 | 3 | Collection of internal eslint configurations. 4 | -------------------------------------------------------------------------------- /examples/nextjs/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/examples/nextjs/app/favicon.ico -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'apps/*' 3 | - 'packages/*' 4 | - 'tools/*' 5 | - 'examples/*' 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.workingDirectories": [ 3 | { 4 | "mode": "auto" 5 | } 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /examples/astro/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/examples/astro/public/favicon.ico -------------------------------------------------------------------------------- /examples/remix/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/examples/remix/public/favicon.ico -------------------------------------------------------------------------------- /apps/baseai.dev/public/caustics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/caustics.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/src/app/favicon.ico -------------------------------------------------------------------------------- /examples/remix/public/logo-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/examples/remix/public/logo-dark.png -------------------------------------------------------------------------------- /examples/remix/public/logo-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/examples/remix/public/logo-light.png -------------------------------------------------------------------------------- /apps/baseai.dev/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {} 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/email-agent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/email-agent.png -------------------------------------------------------------------------------- /apps/baseai.dev/src/data/index.ts: -------------------------------------------------------------------------------- 1 | export const MOBILE_BREAKPOINT = 768; 2 | 3 | export const BASE_URL = 'https://baseai.dev'; 4 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv.jpg -------------------------------------------------------------------------------- /examples/remix/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv2.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv3.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv4.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv5.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv6.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv7.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv8.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/texture/panoenv9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/texture/panoenv9.jpg -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/.gitignore: -------------------------------------------------------------------------------- 1 | # baseai 2 | **/.baseai/ 3 | # env file 4 | .env 5 | /baseai/memory/code-files/documents 6 | -------------------------------------------------------------------------------- /examples/nextjs/next.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = {}; 3 | 4 | export default nextConfig; 5 | -------------------------------------------------------------------------------- /apps/baseai.dev/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals", 3 | "rules": { 4 | "@next/next/no-img-element": "off" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/AlteHaasGroteskBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/AlteHaasGroteskBold.ttf -------------------------------------------------------------------------------- /apps/baseai.dev/public/deploy/auth-api-dark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/deploy/auth-api-dark.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/favicon.ico -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/favicon.ico -------------------------------------------------------------------------------- /apps/baseai.dev/src/mdx/recma.mjs: -------------------------------------------------------------------------------- 1 | import { mdxAnnotations } from 'mdx-annotations'; 2 | 3 | export const recmaPlugins = [mdxAnnotations.recma]; 4 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/mdx/recma.ts: -------------------------------------------------------------------------------- 1 | import { mdxAnnotations } from 'mdx-annotations'; 2 | 3 | export const recmaPlugins = [mdxAnnotations.recma]; 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: 'npm' 4 | directory: '/' 5 | schedule: 6 | interval: 'daily' 7 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/deploy/auth-api-light.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/deploy/auth-api-light.jpg -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/mstile-70x70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/mstile-70x70.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/favicon-16x16.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/favicon-32x32.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/svg-black/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/svg-black/favicon.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/svg-white/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/svg-white/favicon.png -------------------------------------------------------------------------------- /apps/baseai.dev/src/app/page.tsx: -------------------------------------------------------------------------------- 1 | import Hero from "@/components/home/hero"; 2 | 3 | export default function Homepage() { 4 | return ; 5 | } 6 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/favicon-16x16.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/favicon-32x32.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/mstile-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/mstile-144x144.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/mstile-150x150.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/mstile-310x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/mstile-310x150.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/mstile-310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/mstile-310x310.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/mstile-150x150.png -------------------------------------------------------------------------------- /apps/baseai.dev/src/types/mdx-annotations.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'mdx-annotations' { 2 | const mdxAnnotations: any; 3 | export { mdxAnnotations }; 4 | } 5 | -------------------------------------------------------------------------------- /packages/core/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | /test-results/ 3 | /playwright-report/ 4 | /blob-report/ 5 | /playwright/.cache/ 6 | /react 7 | /helpers 8 | /pipes 9 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/apple-touch-icon.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/apple-touch-icon.png -------------------------------------------------------------------------------- /apps/baseai.dev/src/mdx/themes/index.mjs: -------------------------------------------------------------------------------- 1 | import shadesOfPurple from './shades-of-purple.json' assert { type: 'json' }; 2 | 3 | export default { shadesOfPurple }; 4 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/mdx/themes/index.ts: -------------------------------------------------------------------------------- 1 | import shadesOfPurple from './shades-of-purple.json' assert { type: 'json' }; 2 | 3 | export default { shadesOfPurple }; 4 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/android-chrome-192x192.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/2024/android-chrome-512x512.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/android-chrome-192x192.png -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LangbaseInc/BaseAI/HEAD/apps/baseai.dev/public/favicon/old/android-chrome-512x512.png -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/exec-sync.ts: -------------------------------------------------------------------------------- 1 | import {promisify} from 'util'; 2 | import {exec} from 'child_process'; 3 | export const execAsync = promisify(exec); 4 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/styles/webgl.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @layer base { 3 | img { 4 | @apply inline-block; 5 | } 6 | } 7 | @tailwind components; 8 | @tailwind utilities; 9 | -------------------------------------------------------------------------------- /examples/agents/it-systems-triage-agent/.gitignore: -------------------------------------------------------------------------------- 1 | # baseai 2 | **/.baseai/ 3 | node_modules 4 | .env 5 | package-lock.json 6 | pnpm-lock.yaml 7 | # env file 8 | .env 9 | 10 | -------------------------------------------------------------------------------- /packages/core/turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "//" 4 | ], 5 | "tasks": { 6 | "build": { 7 | "outputs": [ 8 | "**/dist/**" 9 | ] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: ['@baseai/eslint-config/library.js'], 4 | settings: { 5 | next: { 6 | rootDir: ['apps/*/'], 7 | }, 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/mdx/remark.ts: -------------------------------------------------------------------------------- 1 | import { mdxAnnotations } from 'mdx-annotations' 2 | import remarkGfm from 'remark-gfm' 3 | 4 | export const remarkPlugins = [mdxAnnotations.remark, remarkGfm] 5 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/mdx/remark.mjs: -------------------------------------------------------------------------------- 1 | import { mdxAnnotations } from 'mdx-annotations' 2 | import remarkGfm from 'remark-gfm' 3 | 4 | export const remarkPlugins = [mdxAnnotations.remark, remarkGfm] 5 | -------------------------------------------------------------------------------- /examples/nextjs/postcss.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('postcss-load-config').Config} */ 2 | const config = { 3 | plugins: { 4 | tailwindcss: {}, 5 | }, 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/exit.ts: -------------------------------------------------------------------------------- 1 | const exit = { 2 | success: () => { 3 | process.exit(0); 4 | }, 5 | fail: () => { 6 | process.exit(1); 7 | } 8 | }; 9 | 10 | export default exit; 11 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting Security Issues 2 | 3 | If you find a security vulnerability, please email us at `security@langbase.com`. 4 | 5 | We will promptly investigate and fix legitimate reports. 6 | -------------------------------------------------------------------------------- /examples/nextjs/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import {type ClassValue, clsx} from 'clsx'; 2 | import {twMerge} from 'tailwind-merge'; 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)); 6 | } 7 | -------------------------------------------------------------------------------- /tools/tsconfig/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@baseai/tsconfig", 3 | "version": "0.0.2", 4 | "private": true, 5 | "license": "Apache-2.0", 6 | "publishConfig": { 7 | "access": "public" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { type ClassValue, clsx } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /examples/remix/app/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import {type ClassValue, clsx} from 'clsx'; 2 | import {twMerge} from 'tailwind-merge'; 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)); 6 | } 7 | -------------------------------------------------------------------------------- /packages/baseai/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "arrowParens": "avoid", 4 | "singleQuote": true, 5 | "printWidth": 80, 6 | "useTabs": true, 7 | "tabWidth": 4, 8 | "semi": true 9 | } 10 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": false, 3 | "trailingComma": "all", 4 | "arrowParens": "avoid", 5 | "singleQuote": true, 6 | "printWidth": 80, 7 | "useTabs": true, 8 | "tabWidth": 4, 9 | "semi": true 10 | } 11 | -------------------------------------------------------------------------------- /tools/tsconfig/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @baseai/tsconfig 2 | 3 | ## 0.0.2 4 | 5 | ### Patch Changes 6 | 7 | - Initial release 8 | 9 | ## 0.0.1 10 | 11 | ### Patch Changes 12 | 13 | - Initial package. Let's do this IA. 14 | -------------------------------------------------------------------------------- /examples/astro/src/pages/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../layouts/Layout.astro'; 3 | import {Home} from '../components/pages/home'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tools/eslint-config/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @baseai/eslint-config 2 | 3 | ## 0.0.2 4 | 5 | ### Patch Changes 6 | 7 | - Initial release 8 | 9 | ## 0.0.1 10 | 11 | ### Patch Changes 12 | 13 | - Initial package. Let's do this IA. 14 | -------------------------------------------------------------------------------- /examples/nodejs/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": false, 3 | "trailingComma": "all", 4 | "arrowParens": "avoid", 5 | "singleQuote": true, 6 | "printWidth": 80, 7 | "useTabs": true, 8 | "tabWidth": 4, 9 | "semi": true 10 | } 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a Question 4 | url: https://github.com/LangbaseInc/baseai/discussions 5 | about: Please ask your questions in our discussions forum. 6 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/routes/base.ts: -------------------------------------------------------------------------------- 1 | export const registerRoot = (app: any) => 2 | app.get('/', (c: any) => { 3 | return c.json({ 4 | success: true, 5 | message: 'BaseAI Local API', 6 | link: 'https://langbase.com/docs' 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/core/types/tools.ts: -------------------------------------------------------------------------------- 1 | export interface Tool { 2 | run: (...args: any[]) => Promise | any; 3 | type: 'function'; 4 | function: { 5 | name: string; 6 | description?: string; 7 | parameters?: Record; 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/icons.ts: -------------------------------------------------------------------------------- 1 | import figures from 'figures'; 2 | 3 | const icons = { 4 | pipe: figures.lineDownDoubleRightDouble, 5 | tool: figures.lineDownLeftBoldRightBold, 6 | memory: figures.nodejs 7 | }; 8 | 9 | export default icons; 10 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/Row.tsx: -------------------------------------------------------------------------------- 1 | export function Row({ children }: { children: React.ReactNode }) { 2 | return ( 3 |
4 | {children} 5 |
6 | ); 7 | } 8 | -------------------------------------------------------------------------------- /tools/tsconfig/node16.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Node 16", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "lib": ["ES2021"], 7 | "module": "ES2022", 8 | "target": "ES2021" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tools/tsconfig/node14.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Node 14", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "lib": ["ES2020"], 7 | "module": "commonjs", 8 | "target": "ES2020" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/memory/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {Memory} from '../../../components/pages/memory'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/core/src/index.ts: -------------------------------------------------------------------------------- 1 | export type {Memory as MemoryI} from '../types/memory'; 2 | export type {Pipe as PipeI, Message, MessageRole} from '../types/pipes'; 3 | export type {Tool as ToolI} from '../types/tools'; 4 | export * from './helpers/'; 5 | export * from './pipes/'; 6 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/pipe-run/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {PipeRun} from '../../../components/pages/pipe-run'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/chat-simple/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {ChatSimple} from '../../../components/pages/chat-simple'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tools/eslint-config/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['next', 'turbo', 'prettier'], 3 | rules: { 4 | '@next/next/no-html-link-for-pages': 'off', 5 | }, 6 | parserOptions: { 7 | babelOptions: { 8 | presets: [require.resolve('next/babel')], 9 | }, 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/pipe-run-stream/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {PipeStream} from '../../../components/pages/pipe-stream'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/tool-calling/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {ToolCalling} from '../../../components/pages/tool-calling'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/chat-advanced/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {ChatAdvanced} from '../../../components/pages/chat-advanced'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/lib/remToPx.ts: -------------------------------------------------------------------------------- 1 | export function remToPx(remValue: number) { 2 | let rootFontSize = 3 | typeof window === 'undefined' 4 | ? 16 5 | : parseFloat( 6 | window.getComputedStyle(document.documentElement).fontSize 7 | ); 8 | 9 | return remValue * rootFontSize; 10 | } 11 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/hono/env.ts: -------------------------------------------------------------------------------- 1 | import {z} from 'zod'; 2 | 3 | export const zEnv = z.object({}); 4 | 5 | export type Env = z.infer; 6 | 7 | export type Services = {}; 8 | 9 | export type HonoEnv = { 10 | Bindings: Env; 11 | Variables: { 12 | userAgent?: string; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tools/tsconfig/react-library.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "React Library", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "jsx": "react-jsx", 7 | "lib": ["dom", "ES2015"], 8 | "module": "ESNext", 9 | "target": "es6" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /apps/baseai.dev/prettier.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('prettier').Options} */ 2 | module.exports = { 3 | trailingComma: 'none', 4 | arrowParens: 'avoid', 5 | singleQuote: true, 6 | printWidth: 80, 7 | useTabs: true, 8 | tabWidth: 4, 9 | semi: true, 10 | plugins: ['prettier-plugin-tailwindcss'] 11 | }; 12 | -------------------------------------------------------------------------------- /examples/remix/baseai/memory/chat-with-docs/index.ts: -------------------------------------------------------------------------------- 1 | import {MemoryI} from '@baseai/core'; 2 | 3 | const buidMemory = (): MemoryI => ({ 4 | name: 'chat-with-docs', 5 | description: 'Chat with given docs', 6 | useGit: false, 7 | include: ['documents/**/*'], 8 | }); 9 | 10 | export default buidMemory; 11 | -------------------------------------------------------------------------------- /examples/astro/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "astro/tsconfigs/strict", 3 | "compilerOptions": { 4 | "jsx": "react-jsx", 5 | "jsxImportSource": "react", 6 | "paths": { 7 | "@/*": ["./src/*"] 8 | } 9 | }, 10 | "include": ["env.d.ts", "**/*.ts", "**/*.tsx"], 11 | "exclude": ["node_modules"] 12 | } 13 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/middleware/pre-flight.ts: -------------------------------------------------------------------------------- 1 | import {MiddlewareHandler} from 'hono'; 2 | 3 | export const preFlight = (): MiddlewareHandler => { 4 | return async function preFlight(c, next) { 5 | if (c.req.method === 'OPTIONS') { 6 | return new Response(null); 7 | } 8 | await next(); 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/get-dirname.ts: -------------------------------------------------------------------------------- 1 | import {dirname} from 'path'; 2 | import {fileURLToPath} from 'url'; 3 | import path from 'path'; 4 | 5 | const __filename = fileURLToPath(import.meta.url); 6 | let dirName = dirname(__filename); 7 | dirName = path.join(dirName, '..'); 8 | 9 | export {dirName}; 10 | -------------------------------------------------------------------------------- /examples/astro/src/pages/demo/pipe-run-pipes-as-tools/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../../../layouts/Layout.astro'; 3 | import {PipeRunPipesAsTools} from '../../../components/pages/pipe-run-pipes-as-tools'; 4 | --- 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #000000 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #000000 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/baseai/bin/baseai.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { install } from 'source-map-support'; 4 | import { fileURLToPath } from 'url'; 5 | 6 | install(); 7 | 8 | const __filename = fileURLToPath(import.meta.url); 9 | const distPath = new URL('../dist/index.js', import.meta.url).pathname; 10 | 11 | import(distPath); 12 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/groq/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import GroqAPIConfig from './api'; 3 | import { GroqChatCompleteConfig } from './chatComplete'; 4 | 5 | const GroqConfig: ProviderConfigs = { 6 | chatComplete: GroqChatCompleteConfig, 7 | api: GroqAPIConfig 8 | }; 9 | 10 | export default GroqConfig; 11 | -------------------------------------------------------------------------------- /examples/astro/src/components/ui/go-home.tsx: -------------------------------------------------------------------------------- 1 | export default function GoHome() { 2 | return ( 3 | 7 | ← More examples 8 | 9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/middleware/post-only.ts: -------------------------------------------------------------------------------- 1 | import {MiddlewareHandler} from 'hono'; 2 | 3 | export const allowOnlyPost = (): MiddlewareHandler => { 4 | return async function allowOnlyPost(c, next) { 5 | if (c.req.method !== 'POST') { 6 | return c.json({message: 'Bad Request - Only POST requests allowed.'}, 400); 7 | } 8 | await next(); 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | test-results 3 | node_modules 4 | .turbo 5 | *.log 6 | .next 7 | dist 8 | /dist 9 | dist-ssr 10 | *.local 11 | .env 12 | .cache 13 | server/dist 14 | public/dist 15 | .turbo 16 | /test-results/ 17 | /playwright-report/ 18 | /blob-report/ 19 | /playwright/.cache/ 20 | .x* 21 | .del* 22 | _* 23 | **/node_modules/ 24 | 25 | # BaseAI 26 | **/.baseai/ 27 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/Wrapper.tsx: -------------------------------------------------------------------------------- 1 | import { Prose } from '@/components/Prose'; 2 | 3 | // Article layout wrapper 4 | export function Wrapper({ children }: { children: React.ReactNode }) { 5 | return ( 6 |
7 | {children} 8 |
9 | ); 10 | } 11 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/cohere/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const CohereAPIConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.cohere.ai/v1', 4 | headers: (llmApiKey: string) => { 5 | return { Authorization: `Bearer ${llmApiKey}` }; 6 | }, 7 | chatComplete: '/chat' 8 | }; 9 | 10 | export default CohereAPIConfig; 11 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/openai/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import OpenAIAPIConfig from './api'; 3 | import { OpenAIChatCompleteConfig } from './chatComplete'; 4 | 5 | const OpenAIConfig: ProviderConfigs = { 6 | api: OpenAIAPIConfig, 7 | chatComplete: OpenAIChatCompleteConfig 8 | }; 9 | 10 | export default OpenAIConfig; 11 | -------------------------------------------------------------------------------- /packages/core/vitest.ui.react.config.js: -------------------------------------------------------------------------------- 1 | import react from '@vitejs/plugin-react'; 2 | import {defineConfig} from 'vite'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | test: { 8 | environment: 'jsdom', 9 | globals: true, 10 | include: ['**/*.ui.test.ts{,x}'], 11 | exclude: ['**/node_modules/**'], 12 | }, 13 | }); 14 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/handle-error.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | type Spinner = ReturnType; 3 | 4 | export async function handleError({ 5 | spinner, 6 | error, 7 | }: { 8 | spinner: Spinner; 9 | error: Error; 10 | }) { 11 | spinner.stop(); 12 | p.log.error(`ERROR: ${(error as Error).message}`); 13 | process.exit(1); 14 | } 15 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/middleware/powered-by.ts: -------------------------------------------------------------------------------- 1 | import type { MiddlewareHandler } from 'hono'; 2 | 3 | export const poweredBy = (): MiddlewareHandler => { 4 | return async function poweredBy(c, next) { 5 | await next(); 6 | c.res.headers.set('lb-powered-by', 'Langbase'); 7 | c.res.headers.set('powered-by', 'BaseAI'); 8 | c.res.headers.set('env', 'local'); 9 | }; 10 | }; 11 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/openai/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const OpenAIAPIConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.openai.com/v1', 4 | headers: (API_KEY: string) => { 5 | return { Authorization: `Bearer ${API_KEY}` }; 6 | }, 7 | chatComplete: '/chat/completions' 8 | }; 9 | 10 | export default OpenAIAPIConfig; 11 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/groq/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const GroqAPIConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.groq.com/openai/v1', 4 | headers: (llmApiKey: string) => { 5 | return { Authorization: `Bearer ${llmApiKey}` }; 6 | }, 7 | chatComplete: '/chat/completions' 8 | }; 9 | 10 | export default GroqAPIConfig; 11 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/BoltIcon.tsx: -------------------------------------------------------------------------------- 1 | export function BoltIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /examples/nodejs/baseai/memory/chat-with-docs/index.ts: -------------------------------------------------------------------------------- 1 | import {MemoryI} from '@baseai/core'; 2 | 3 | const buildMemory = (): MemoryI => ({ 4 | name: 'chat-with-docs', 5 | description: 'Chat with docs', 6 | git: { 7 | enabled: false, 8 | include: ['documents/**/*'], 9 | gitignore: true, 10 | deployedAt: '', 11 | embeddedAt: '', 12 | }, 13 | }); 14 | 15 | export default buildMemory; 16 | -------------------------------------------------------------------------------- /examples/nodejs/baseai/memory/chat-with-repo/index.ts: -------------------------------------------------------------------------------- 1 | import {MemoryI} from '@baseai/core'; 2 | 3 | const memoryChatWithRepo = (): MemoryI => ({ 4 | name: 'chat-with-repo', 5 | description: '', 6 | git: { 7 | enabled: true, 8 | include: ['examples/**/*'], 9 | gitignore: true, 10 | deployedAt: '', 11 | embeddedAt: '', 12 | }, 13 | }); 14 | 15 | export default memoryChatWithRepo; 16 | -------------------------------------------------------------------------------- /packages/core/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [ 4 | '@langbase/eslint-config/library.js', 5 | 'plugin:prettier/recommended', // prettier 6 | ], 7 | parser: '@typescript-eslint/parser', 8 | parserOptions: { 9 | project: true, 10 | }, 11 | plugins: ['prettier'], // prettier 12 | rules: { 13 | 'prettier/prettier': 'error', // prettier 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/Properties.tsx: -------------------------------------------------------------------------------- 1 | export function Properties({ children }: { children: React.ReactNode }) { 2 | return ( 3 |
4 |
    8 | {children} 9 |
10 |
11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/memory/chat-with-docs/index.ts: -------------------------------------------------------------------------------- 1 | import {MemoryI} from '@baseai/core'; 2 | 3 | const buidMemory = (): MemoryI => ({ 4 | name: 'chat-with-docs', 5 | description: 'Chat with given docs', 6 | git: { 7 | enabled: false, 8 | include: ['documents/**/*'], 9 | gitignore: true, 10 | deployedAt: '', 11 | embeddedAt: '', 12 | }, 13 | }); 14 | 15 | export default buidMemory; 16 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/together-ai/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import TogetherAIApiConfig from './api'; 3 | import { TogetherAIChatCompleteConfig } from './chatComplete'; 4 | 5 | const TogetherAIConfig: ProviderConfigs = { 6 | chatComplete: TogetherAIChatCompleteConfig, 7 | api: TogetherAIApiConfig 8 | }; 9 | 10 | export default TogetherAIConfig; 11 | -------------------------------------------------------------------------------- /packages/baseai/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup'; 2 | 3 | export default defineConfig({ 4 | clean: true, 5 | dts: true, 6 | entry: ['src/index.ts'], 7 | format: ['esm'], 8 | sourcemap: true, 9 | // target: 'esnext', 10 | target: 'node16', 11 | outDir: 'dist', 12 | splitting: false, 13 | bundle: true, 14 | minify: true, 15 | external: ['react', 'svelte', 'vue'] 16 | }); 17 | -------------------------------------------------------------------------------- /apps/baseai.dev/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.js", 8 | "css": "src/styles/global.css", 9 | "baseColor": "zinc", 10 | "cssVariables": true 11 | }, 12 | "aliases": { 13 | "components": "@/components", 14 | "utils": "@/lib/utils" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/astro/baseai/memory/chat-with-docs/index.ts: -------------------------------------------------------------------------------- 1 | import type {MemoryI} from '@baseai/core'; 2 | 3 | const buidMemory = (): MemoryI => ({ 4 | name: 'chat-with-docs', 5 | description: 'Chat with given docs', 6 | git: { 7 | enabled: false, 8 | include: ['documents/**/*'], 9 | gitignore: true, 10 | deployedAt: '', 11 | embeddedAt: '', 12 | }, 13 | }); 14 | 15 | export default buidMemory; 16 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/mistral-ai/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const MistralAIAPIConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.mistral.ai/v1', 4 | headers: (llmApiKey: string) => { 5 | return { 6 | Authorization: `Bearer ${llmApiKey}` 7 | }; 8 | }, 9 | chatComplete: '/chat/completions' 10 | }; 11 | 12 | export default MistralAIAPIConfig; 13 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import {defineConfig} from 'tsup'; 2 | 3 | export default defineConfig({ 4 | clean: true, 5 | dts: true, 6 | entry: ['index.ts'], 7 | format: ['esm'], 8 | sourcemap: true, 9 | // target: 'esnext', 10 | target: 'node16', 11 | outDir: 'dist', 12 | splitting: false, 13 | bundle: true, 14 | minify: true, 15 | external: ['react', 'svelte', 'vue'], 16 | }); 17 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/utils/thread/get-few-shot-messages.ts: -------------------------------------------------------------------------------- 1 | import type { Message, Pipe } from 'types/pipe'; 2 | 3 | export function getPipeFewShotsMessages(pipe: Pipe): Message[] { 4 | const fewShotMessages: Message[] = pipe.messages.filter( 5 | m => m.role !== 'system' 6 | ); 7 | 8 | if (fewShotMessages && fewShotMessages.length > 0) { 9 | return fewShotMessages; 10 | } 11 | 12 | return []; 13 | } 14 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/Col.tsx: -------------------------------------------------------------------------------- 1 | import clsx from 'clsx'; 2 | 3 | export function Col({ 4 | children, 5 | sticky = false 6 | }: { 7 | children: React.ReactNode; 8 | sticky?: boolean; 9 | }) { 10 | return ( 11 |
:first-child]:mt-0 [&>:last-child]:mb-0', 14 | sticky && 'xl:sticky xl:top-24' 15 | )} 16 | > 17 | {children} 18 |
19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /examples/remix/app/components/ui/go-home.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "@remix-run/react"; 2 | 3 | export default function GoHome() { 4 | return ( 5 | 9 | ← More examples 10 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /packages/core/vitest.node.config.js: -------------------------------------------------------------------------------- 1 | import {defineConfig} from 'vite'; 2 | 3 | // https://vitejs.dev/config/ 4 | export default defineConfig({ 5 | test: { 6 | environment: 'node', 7 | globals: true, 8 | include: ['**/*.test.ts{,x}'], 9 | exclude: [ 10 | '**/*.ui.test.ts{,x}', 11 | '**/*.e2e.test.ts{,x}', 12 | '**/node_modules/**', 13 | ], 14 | typecheck: { 15 | enabled: true, 16 | }, 17 | }, 18 | }); 19 | -------------------------------------------------------------------------------- /apps/baseai.dev/next.config.mjs: -------------------------------------------------------------------------------- 1 | 2 | import withSearch from './src/mdx/search.mjs'; 3 | 4 | /** @type {import('next').NextConfig} */ 5 | const nextConfig = { 6 | pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'mdx'], 7 | images: { 8 | domains: ['raw.githubusercontent.com/'] 9 | }, 10 | transpilePackages: ['next-mdx-remote'], 11 | async redirects() { 12 | return []; 13 | } 14 | }; 15 | 16 | export default withSearch(nextConfig); 17 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/baseai/memory/code-files/index.ts: -------------------------------------------------------------------------------- 1 | import {MemoryI} from '@baseai/core'; 2 | 3 | const memoryCodeFiles = (): MemoryI => ({ 4 | name: 'code-files', 5 | description: 'Memory that contains project files', 6 | git: { 7 | enabled: false, 8 | include: ['documents/**/*'], 9 | gitignore: true, 10 | deployedAt: '', 11 | embeddedAt: '', 12 | }, 13 | }); 14 | 15 | export default memoryCodeFiles; 16 | -------------------------------------------------------------------------------- /examples/astro/baseai/baseai.config.ts: -------------------------------------------------------------------------------- 1 | import type {BaseAIConfig} from 'baseai'; 2 | 3 | export const config: BaseAIConfig = { 4 | log: { 5 | isEnabled: true, 6 | logSensitiveData: false, 7 | pipe: true, 8 | 'pipe.completion': true, 9 | 'pipe.request': true, 10 | 'pipe.response': true, 11 | tool: false, 12 | memory: true, 13 | }, 14 | memory: { 15 | useLocalEmbeddings: false, 16 | }, 17 | envFilePath: '.env', 18 | }; 19 | -------------------------------------------------------------------------------- /examples/nextjs/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "default", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "app/globals.css", 9 | "baseColor": "neutral", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils" 16 | } 17 | } -------------------------------------------------------------------------------- /examples/nextjs/components/ui/go-home.tsx: -------------------------------------------------------------------------------- 1 | import Link from 'next/link'; 2 | import React from 'react'; 3 | 4 | export default function GoHome() { 5 | return ( 6 | 10 | ← More examples 11 | 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /packages/core/vitest.edge.config.js: -------------------------------------------------------------------------------- 1 | import {defineConfig} from 'vite'; 2 | 3 | // https://vitejs.dev/config/ 4 | export default defineConfig({ 5 | test: { 6 | environment: 'edge-runtime', 7 | globals: true, 8 | include: ['**/*.test.ts{,x}'], 9 | exclude: [ 10 | '**/*.ui.test.ts{,x}', 11 | '**/*.e2e.test.ts{,x}', 12 | '**/node_modules/**', 13 | ], 14 | typecheck: { 15 | enabled: true, 16 | }, 17 | }, 18 | }); 19 | -------------------------------------------------------------------------------- /examples/nodejs/baseai/baseai.config.ts: -------------------------------------------------------------------------------- 1 | import type {BaseAIConfig} from 'baseai'; 2 | 3 | export const config: BaseAIConfig = { 4 | log: { 5 | isEnabled: true, 6 | logSensitiveData: false, 7 | pipe: true, 8 | 'pipe.completion': true, 9 | 'pipe.request': true, 10 | 'pipe.response': true, 11 | tool: false, 12 | memory: false, 13 | }, 14 | memory: { 15 | useLocalEmbeddings: false, 16 | }, 17 | envFilePath: '.env', 18 | }; 19 | -------------------------------------------------------------------------------- /examples/remix/baseai/baseai.config.ts: -------------------------------------------------------------------------------- 1 | import type {BaseAIConfig} from 'baseai'; 2 | 3 | export const config: BaseAIConfig = { 4 | log: { 5 | isEnabled: true, 6 | logSensitiveData: false, 7 | pipe: true, 8 | 'pipe.completion': true, 9 | 'pipe.request': true, 10 | 'pipe.response': true, 11 | tool: false, 12 | memory: false, 13 | }, 14 | memory: { 15 | useLocalEmbeddings: false, 16 | }, 17 | envFilePath: '.env', 18 | }; 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/utils/is-json-mode.ts: -------------------------------------------------------------------------------- 1 | import { jsonModeModels } from '@/dev/data/models'; 2 | 3 | export function isJsonModeOn({ 4 | currentModel, 5 | jsonMode 6 | }: { 7 | currentModel: string; 8 | jsonMode: boolean; 9 | }) { 10 | const modelHasJsonMode = jsonModeModels.includes(currentModel); 11 | const jsonModeOn = jsonMode; 12 | if (jsonModeOn && modelHasJsonMode) { 13 | return true; 14 | } 15 | 16 | return false; 17 | } 18 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "public", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [ 11 | "baseai.dev", 12 | "example-astro", 13 | "example-nextjs", 14 | "example-nodejs", 15 | "example-remix" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/ShirtIcon.tsx: -------------------------------------------------------------------------------- 1 | export function ShirtIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 10 | ); 11 | } 12 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/baseai.config.ts: -------------------------------------------------------------------------------- 1 | import type {BaseAIConfig} from 'baseai'; 2 | 3 | export const config: BaseAIConfig = { 4 | log: { 5 | isEnabled: true, 6 | logSensitiveData: false, 7 | pipe: true, 8 | 'pipe.completion': true, 9 | 'pipe.request': true, 10 | 'pipe.response': true, 11 | tool: true, 12 | memory: true, 13 | }, 14 | envFilePath: '.env.local', 15 | memory: { 16 | useLocalEmbeddings: false, 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /examples/nodejs/examples/pipe.generate.text.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config'; 2 | import {generateText, Pipe} from '@baseai/core'; 3 | import pipeSummary from '../baseai/pipes/summary'; 4 | 5 | const pipe = new Pipe(pipeSummary()); 6 | 7 | async function main() { 8 | const response = await generateText({ 9 | pipe, 10 | messages: [{role: 'user', content: 'Hello'}], 11 | }); 12 | 13 | console.log('response: ', response); 14 | } 15 | 16 | main(); 17 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/lib/get-docs-by-slug.ts: -------------------------------------------------------------------------------- 1 | import docsContent from '../../content/docs/docs.json'; 2 | 3 | export async function getDocsBySlug({ 4 | slug, 5 | section 6 | }: { 7 | slug: string; 8 | section?: string; 9 | }) { 10 | const docContent = docsContent.find( 11 | doc => doc.slug === slug && doc.section === section 12 | ); 13 | 14 | return { 15 | content: docContent?.content, 16 | frontmatter: docContent?.frontmatter 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/together-ai/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const TogetherAIApiConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.together.xyz', 4 | headers: (API_KEY: string) => { 5 | return { Authorization: `Bearer ${API_KEY}` }; 6 | }, 7 | chatComplete: '/v1/chat/completions', 8 | complete: '/v1/completions', 9 | embed: '/v1/embeddings' 10 | }; 11 | 12 | export default TogetherAIApiConfig; 13 | -------------------------------------------------------------------------------- /.kodiak.toml: -------------------------------------------------------------------------------- 1 | # .kodiak.toml 2 | version = 1 3 | 4 | [merge] 5 | automerge_label = "automerge" 6 | require_automerge_label = true 7 | method = "squash" 8 | delete_branch_on_merge = true 9 | optimistic_updates = false 10 | prioritize_ready_to_merge = true 11 | notify_on_conflict = false 12 | 13 | [merge.message] 14 | title = "pull_request_title" 15 | body = "pull_request_body" 16 | include_pr_number = true 17 | body_type = "markdown" 18 | strip_html_comments = true 19 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/lib/get-learn-by-slug.ts: -------------------------------------------------------------------------------- 1 | import learnContent from '../../content/learn/learn.json'; 2 | 3 | export async function getLearnBySlug({ 4 | slug, 5 | section 6 | }: { 7 | slug: string; 8 | section?: string; 9 | }) { 10 | const docContent = learnContent.find( 11 | doc => doc.slug === slug && doc.section === section 12 | ); 13 | 14 | return { 15 | content: docContent?.content, 16 | frontmatter: docContent?.frontmatter 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /apps/baseai.dev/types.d.ts: -------------------------------------------------------------------------------- 1 | import { type SearchOptions } from 'flexsearch'; 2 | 3 | declare module '@/mdx/search.mjs' { 4 | export type Result = { 5 | url: string; 6 | title: string; 7 | pageTitle?: string; 8 | }; 9 | 10 | export function search( 11 | query: string, 12 | options?: SearchOptions 13 | ): Array; 14 | } 15 | 16 | declare module 'mdx-annotations' { 17 | const mdxAnnotations: any; 18 | export { mdxAnnotations }; 19 | } 20 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/baseai/baseai.config.ts: -------------------------------------------------------------------------------- 1 | import type {BaseAIConfig} from 'baseai'; 2 | 3 | export const config: BaseAIConfig = { 4 | log: { 5 | isEnabled: false, 6 | logSensitiveData: false, 7 | pipe: true, 8 | 'pipe.completion': true, 9 | 'pipe.request': true, 10 | 'pipe.response': true, 11 | tool: true, 12 | memory: true, 13 | }, 14 | memory: { 15 | useLocalEmbeddings: false, 16 | }, 17 | envFilePath: '.env', 18 | }; 19 | -------------------------------------------------------------------------------- /examples/agents/it-systems-triage-agent/baseai/baseai.config.ts: -------------------------------------------------------------------------------- 1 | import type {BaseAIConfig} from 'baseai'; 2 | 3 | export const config: BaseAIConfig = { 4 | log: { 5 | isEnabled: false, 6 | logSensitiveData: false, 7 | pipe: true, 8 | 'pipe.completion': true, 9 | 'pipe.request': false, 10 | 'pipe.response': false, 11 | tool: false, 12 | memory: false, 13 | }, 14 | memory: { 15 | useLocalEmbeddings: false, 16 | }, 17 | envFilePath: '.env', 18 | }; 19 | -------------------------------------------------------------------------------- /examples/astro/src/middleware.ts: -------------------------------------------------------------------------------- 1 | import type {APIContext, APIRoute} from 'astro'; 2 | import {mapMetaEnvToProcessEnv} from './lib/utils'; 3 | 4 | export function onRequest( 5 | context: APIContext, 6 | next: () => ReturnType, 7 | ): ReturnType { 8 | // Map the meta environment variables to process environment variables 9 | mapMetaEnvToProcessEnv(); 10 | 11 | // Return a Response or the result of calling `next()` 12 | return next(); 13 | } 14 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/exit.ts: -------------------------------------------------------------------------------- 1 | import pc from 'picocolors'; 2 | import figures from 'figures'; 3 | import * as p from '@clack/prompts'; 4 | import {heading} from './heading'; 5 | 6 | export async function exit({path}: {path: string}) { 7 | p.outro( 8 | heading({ 9 | text: 'readme.md', 10 | sub: `instructions written in \n ${pc.dim(figures.pointer)} ${pc.italic(pc.dim(path))}`, 11 | green: true, 12 | }), 13 | ); 14 | process.exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/ollama/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig, ProviderOptions } from 'types/providers'; 2 | 3 | const OllamaAPIConfig: ProviderAPIConfig = { 4 | headers: () => { 5 | return {}; 6 | }, 7 | getBaseURL: ({ providerOptions }: { providerOptions: ProviderOptions }) => { 8 | return providerOptions.customHost ?? 'http://localhost:11434'; 9 | }, 10 | chatComplete: '/v1/chat/completions' 11 | }; 12 | 13 | export default OllamaAPIConfig; 14 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/LinkIcon.tsx: -------------------------------------------------------------------------------- 1 | export function LinkIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/InfoIcon.tsx: -------------------------------------------------------------------------------- 1 | export function InfoIcon(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/CrossIcon.tsx: -------------------------------------------------------------------------------- 1 | export function CrossIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/perplexity/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const PerplexityAIApiConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.perplexity.ai', 4 | headers: (llmApiKey: string) => { 5 | return { 6 | Authorization: `Bearer ${llmApiKey}`, 7 | 'content-type': 'application/json', 8 | accept: 'application/json' 9 | }; 10 | }, 11 | chatComplete: '/chat/completions' 12 | }; 13 | 14 | export default PerplexityAIApiConfig; 15 | -------------------------------------------------------------------------------- /examples/agents/it-systems-triage-agent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "it-systems-triage-agent", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "baseai": "baseai" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "description": "", 12 | "dependencies": { 13 | "@baseai/core": "^0.9.19", 14 | "dotenv": "^16.4.5", 15 | "inquirer": "^12.0.0", 16 | "ora": "^8.1.0" 17 | }, 18 | "devDependencies": { 19 | "baseai": "^0.9.19" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/astro/.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | dist/ 3 | 4 | # generated types 5 | .astro/ 6 | 7 | # dependencies 8 | node_modules/ 9 | 10 | # logs 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # environment variables 17 | .env 18 | .env.production 19 | 20 | # macOS-specific files 21 | .DS_Store 22 | 23 | # jetbrains setting folder 24 | .idea/ 25 | 26 | # vscode 27 | .vscode/ 28 | # baseai 29 | /.baseai/ 30 | .vercel 31 | # baseai 32 | **/.baseai/ 33 | -------------------------------------------------------------------------------- /apps/baseai.dev/README.md: -------------------------------------------------------------------------------- 1 | # BaseAI Docs 2 | 3 | This is the source code for the BaseAI docs website. It is built with Next.js, Tailwind CSS and deployed on Cloudflare Pages. 4 | 5 | ## Getting started 6 | 7 | To get started, first install dependencies via npm: 8 | 9 | ```bash 10 | npm install 11 | ``` 12 | 13 | Then start the development server: 14 | 15 | ```bash 16 | npm run dev 17 | ``` 18 | 19 | Finally, open [http://localhost:3000](http://localhost:3000) in your browser to view the website. 20 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconStream.tsx: -------------------------------------------------------------------------------- 1 | export function IconStream( 2 | props: JSX.IntrinsicElements['svg'] 3 | ) { 4 | return ( 5 | 13 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/MagnifyingGlassIcon.tsx: -------------------------------------------------------------------------------- 1 | export function MagnifyingGlassIcon( 2 | props: React.ComponentPropsWithoutRef<'svg'> 3 | ) { 4 | return ( 5 | 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/types/markdown.ts: -------------------------------------------------------------------------------- 1 | import { MDXRemoteSerializeResult } from 'next-mdx-remote'; 2 | 3 | export type ContentT = 4 | | MDXRemoteSerializeResult, Record> 5 | | undefined; 6 | 7 | export type FrontmatterT = { 8 | url: string; 9 | slug: string; 10 | title: string; 11 | imageUrl: string; 12 | tags: string | string[]; 13 | section: string; 14 | description: string; 15 | modifiedDate: string | Date; 16 | publishedDate: string | Date; 17 | }; 18 | -------------------------------------------------------------------------------- /examples/nodejs/examples/pipe.run.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config'; 2 | import {Pipe} from '@baseai/core'; 3 | import pipeSummary from '../baseai/pipes/summary'; 4 | 5 | const pipe = new Pipe(pipeSummary()); 6 | 7 | async function main() { 8 | const userMsg = 'Who is an AI Engineer?'; 9 | 10 | const response = await pipe.run({ 11 | messages: [ 12 | { 13 | role: 'user', 14 | content: userMsg, 15 | }, 16 | ], 17 | }); 18 | console.log('response: ', response); 19 | } 20 | 21 | main(); 22 | -------------------------------------------------------------------------------- /examples/astro/astro.config.ts: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import {defineConfig} from 'astro/config'; 3 | import react from '@astrojs/react'; 4 | import tailwind from '@astrojs/tailwind'; 5 | import vercel from '@astrojs/vercel/serverless'; 6 | import node from '@astrojs/node'; 7 | 8 | // https://astro.build/config 9 | export default defineConfig({ 10 | output: 'server', 11 | integrations: [ 12 | react(), 13 | tailwind({ 14 | configFile: './tailwind.config.ts', 15 | }), 16 | ], 17 | adapter: vercel(), 18 | }); 19 | -------------------------------------------------------------------------------- /examples/remix/vite.config.ts: -------------------------------------------------------------------------------- 1 | import {vitePlugin as remix} from '@remix-run/dev'; 2 | import {defineConfig} from 'vite'; 3 | import tsconfigPaths from 'vite-tsconfig-paths'; 4 | import {vercelPreset} from '@vercel/remix/vite'; 5 | 6 | export default defineConfig({ 7 | plugins: [ 8 | remix({ 9 | future: { 10 | v3_fetcherPersist: true, 11 | v3_relativeSplatPath: true, 12 | v3_throwAbortReason: true, 13 | }, 14 | presets: [vercelPreset()], 15 | }), 16 | tsconfigPaths(), 17 | ], 18 | }); 19 | -------------------------------------------------------------------------------- /packages/core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/@baseai/tsconfig/react-library.json", 3 | "include": ["."], 4 | "exclude": ["*/dist", "dist", "build", "node_modules"], 5 | "compilerOptions": { 6 | "allowSyntheticDefaultImports": true, 7 | "lib": ["dom", "dom.iterable", "esnext"], 8 | "target": "ES2018", 9 | "stripInternal": true, 10 | // "sourceMap": true, 11 | // "inlineSources": true, 12 | "baseUrl": "." 13 | // "paths": { 14 | // "@/*": ["src/*"] 15 | // } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/CheckIcon.tsx: -------------------------------------------------------------------------------- 1 | export function CheckIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/BookIcon.tsx: -------------------------------------------------------------------------------- 1 | export function BookIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/init.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import clearConsole from 'clear-any-console'; 3 | 4 | export function init({clear, title, version, tagLine, description}) { 5 | clear && clearConsole(); 6 | const bg = chalk.hex('#6CC644').inverse.bold; 7 | const clr = chalk.hex(`#000000`).bold; 8 | 9 | console.log(); 10 | console.log( 11 | `${clr(`${bg(` ${title} `)}`)} v${version} ${chalk.dim(tagLine)}\n${chalk.dim( 12 | description, 13 | )}`, 14 | ); 15 | console.log(); 16 | } 17 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/DocumentIcon.tsx: -------------------------------------------------------------------------------- 1 | export function DocumentIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/heading.ts: -------------------------------------------------------------------------------- 1 | import color from 'picocolors'; 2 | 3 | export function heading({ 4 | text, 5 | sub, 6 | dim, 7 | green 8 | }: { 9 | text: string; 10 | sub?: string; 11 | dim?: boolean; 12 | green?: boolean; 13 | }) { 14 | if (green) { 15 | return `${color.bgGreen(color.black(` ${text} `))} ${sub && sub}`; 16 | } 17 | if (dim) { 18 | return `${color.bgBlack(color.white(` ${text} `))} ${sub && sub}`; 19 | } 20 | return `${color.bold(color.bgCyan(color.black(` ${text} `)))} ${sub && sub}`; 21 | } 22 | -------------------------------------------------------------------------------- /packages/core/src/helpers/logger.ts: -------------------------------------------------------------------------------- 1 | import {isProd} from '../utils/is-prod'; 2 | 3 | export const logger = (category: any, value?: unknown, logHeader?: string) => { 4 | if (isProd()) return; 5 | 6 | console.log(''); 7 | if (logHeader) { 8 | console.log(`======= ${logHeader} =======`); 9 | } 10 | console.log(`❯❯ ${category}`); 11 | 12 | if (typeof value === 'object' && value !== null) { 13 | console.dir(value, {depth: null, colors: true}); 14 | } else if (value !== undefined) { 15 | console.log(value); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/PaperAirplaneIcon.tsx: -------------------------------------------------------------------------------- 1 | export function PaperAirplaneIcon( 2 | props: React.ComponentPropsWithoutRef<'svg'> 3 | ) { 4 | return ( 5 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/FaceSmileIcon.tsx: -------------------------------------------------------------------------------- 1 | export function FaceSmileIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/ListIcon.tsx: -------------------------------------------------------------------------------- 1 | export function ListIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/heading.ts: -------------------------------------------------------------------------------- 1 | import color from 'picocolors'; 2 | 3 | export function heading({ 4 | text, 5 | sub, 6 | dim, 7 | green, 8 | }: { 9 | text: string; 10 | sub?: string; 11 | dim?: boolean; 12 | green?: boolean; 13 | }) { 14 | if (green) { 15 | return `${color.bgGreen(color.black(` ${text} `))} ${sub && sub}`; 16 | } 17 | if (dim) { 18 | return `${color.bgBlack(color.white(` ${text} `))} ${sub && sub}`; 19 | } 20 | return `${color.bold(color.bgCyan(color.black(` ${text} `)))} ${sub && sub}`; 21 | } 22 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/chat-simple/page.tsx: -------------------------------------------------------------------------------- 1 | import ChatSimple from '@/components/chat-simple'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | `usePipe()`: Chat 11 |

12 |

13 | Chat with the AI agent 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/middleware/custom-cors.ts: -------------------------------------------------------------------------------- 1 | import type { MiddlewareHandler } from 'hono'; 2 | import { cors } from 'hono/cors'; 3 | 4 | // Custom CORS middleware configuration 5 | export const customCors: MiddlewareHandler = cors({ 6 | origin: '*', // Equivalent to 'Access-Control-Allow-Origin' 7 | maxAge: 86400, // Equivalent to 'Access-Control-Max-Age' 8 | allowMethods: ['GET', 'POST', 'OPTIONS'], // Equivalent to 'Access-Control-Allow-Methods' 9 | allowHeaders: ['Content-Type', 'Authorization'] // Equivalent to 'Access-Control-Allow-Headers' 10 | }); 11 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/2024/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LANGBASE", 3 | "short_name": "LANGBASE", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#000000", 17 | "background_color": "#000000", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/PackageIcon.tsx: -------------------------------------------------------------------------------- 1 | export function PackageIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /apps/baseai.dev/public/favicon/old/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Langbase.com", 3 | "short_name": "Langbase.com", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#ffffff", 17 | "background_color": "#ffffff", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/CopyIcon.tsx: -------------------------------------------------------------------------------- 1 | export function CopyIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/PaperClipIcon.tsx: -------------------------------------------------------------------------------- 1 | export function PaperClipIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 11 | ); 12 | } 13 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/memory/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import PipeRunMemory from '../../pipe-run-with-memory'; 3 | 4 | export const Memory = () => { 5 | return ( 6 |
7 | 8 |

9 | AI Agent Pipes: Memory 10 |

11 | 12 |

13 | Run a pipe with memory. 14 |

15 | 16 | 17 |
18 | ); 19 | }; 20 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/memory/page.tsx: -------------------------------------------------------------------------------- 1 | import PipeRunMemory from '@/components/pipe-run-with-memory'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | AI Agent Pipes: Memory 11 |

12 |

13 | Run a pipe with memory. 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/chat-simple/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import ChatSimpleExample from '../../chat-simple'; 3 | 4 | export const ChatSimple = () => { 5 | return ( 6 |
7 | 8 | 9 |

10 | `usePipe()`: Chat 11 |

12 | 13 |

14 | Chat with the AI agent 15 |

16 | 17 | 18 |
19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /packages/core/types/memory.ts: -------------------------------------------------------------------------------- 1 | export interface GitConfig { 2 | enabled: boolean; 3 | include: string[]; 4 | gitignore?: boolean; 5 | deployedAt?: string; 6 | embeddedAt?: string; 7 | } 8 | 9 | export interface MemoryDocumentI { 10 | name: string; 11 | size: string; 12 | content: string; 13 | blob: Blob; 14 | path: string; 15 | } 16 | 17 | export interface Document { 18 | meta?: (doc: MemoryDocumentI) => Record; 19 | } 20 | 21 | export interface Memory { 22 | name: string; 23 | description?: string; 24 | git: GitConfig; 25 | documents?: Document; 26 | } 27 | -------------------------------------------------------------------------------- /tools/tsconfig/nextjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Next.js", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "target": "es5", 7 | "noEmit": true, 8 | "allowJs": true, 9 | "module": "esnext", 10 | "jsx": "preserve", 11 | "incremental": true, 12 | "declaration": false, 13 | "declarationMap": false, 14 | "resolveJsonModule": true, 15 | "moduleResolution": "Bundler", 16 | "lib": ["dom", "dom.iterable", "esnext"] 17 | }, 18 | "include": ["src", "next-env.d.ts"], 19 | "exclude": ["node_modules"] 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/ChevronRightLeftIcon.tsx: -------------------------------------------------------------------------------- 1 | export function ChevronRightLeftIcon( 2 | props: React.ComponentPropsWithoutRef<'svg'> 3 | ) { 4 | return ( 5 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/baseai/types/tools.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | 3 | export interface Tool { 4 | run: (...args: any[]) => Promise | any; 5 | type: 'function'; 6 | function: { 7 | name: string; 8 | description?: string; 9 | parameters?: Record; 10 | }; 11 | } 12 | 13 | export const pipeToolSchema = z.object({ 14 | type: z.literal('function'), 15 | function: z.object({ 16 | name: z.string(), 17 | description: z.string().optional(), 18 | parameters: z.record(z.any()).optional() 19 | }) 20 | }); 21 | 22 | export type PipeTool = z.infer; 23 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/images/logos/ruby.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/pipe-run/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import PipeRunExample from '../../pipe-run'; 3 | 4 | export const PipeRun = () => { 5 | return ( 6 |
7 | 8 | 9 |

10 | ⌘ Langbase AI Agent Pipe: Run 11 |

12 | 13 |

14 | Run a pipe to generate a text completion 15 |

16 | 17 | 18 |
19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /examples/nextjs/app/api/langbase/pipes/run-pipes-as-tools/route.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import {NextRequest} from 'next/server'; 3 | import pipeWithPipeAsTool from '../../../../../baseai/pipes/pipe-with-pipes-as-tools'; 4 | 5 | export async function POST(req: NextRequest) { 6 | const runOptions = await req.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(pipeWithPipeAsTool()); 10 | 11 | // 2. Run the pipe 12 | const result = await pipe.run(runOptions); 13 | 14 | // 3. Return the response stringified. 15 | return new Response(JSON.stringify(result)); 16 | } 17 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/pipe-run/page.tsx: -------------------------------------------------------------------------------- 1 | import PipeRunExample from '@/components/pipe-run'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | ⌘ Langbase AI Agent Pipe: Run 11 |

12 | 13 |

14 | Run a pipe to generate a text completion 15 |

16 | 17 | 18 |
19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/tool-calling/page.tsx: -------------------------------------------------------------------------------- 1 | import PipeRunToolExample from '@/components/pipe-run-with-tool'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | AI Agent Pipes: Tool Calling 11 |

12 |

13 | Run a pipe with tool calling. 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2023 Langbase, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconFewShot.tsx: -------------------------------------------------------------------------------- 1 | export function IconFewShot( 2 | props: JSX.IntrinsicElements['svg'] 3 | ) { 4 | return ( 5 | 13 | 17 | 18 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/TwitterIcon.tsx: -------------------------------------------------------------------------------- 1 | export function TwitterIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /examples/nextjs/app/api/langbase/pipes/run-tool/route.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import {NextRequest} from 'next/server'; 3 | import pipeWithTools from '../../../../../baseai/pipes/pipe-with-tool'; 4 | 5 | export async function POST(req: NextRequest) { 6 | const runOptions = await req.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(pipeWithTools()); 10 | 11 | // 2. Run the pipe with user messages and other run options. 12 | let result = await pipe.run(runOptions); 13 | 14 | // 2. Return the response stringified. 15 | return new Response(JSON.stringify(result)); 16 | } 17 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/chat-advanced/page.tsx: -------------------------------------------------------------------------------- 1 | import ChatAdvanced from '@/components/chat-advanced'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | `usePipe()`: Chat Advanced 11 |

12 |

13 | A kitchen sink example with all `usePipe()` chat features 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/pipe-run-stream/page.tsx: -------------------------------------------------------------------------------- 1 | import PipeStreamExample from '@/components/pipe-stream'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | ⌘ Langbase AI Agent Pipe: Stream 11 |

12 |

13 | Stream a pipe to stream a text completion 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/BellIcon.tsx: -------------------------------------------------------------------------------- 1 | export function BellIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/EnvelopeIcon.tsx: -------------------------------------------------------------------------------- 1 | export function EnvelopeIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/pipe-stream/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import PipeStreamExample from '../../pipe-stream'; 3 | 4 | export const PipeStream = () => { 5 | return ( 6 |
7 | 8 | 9 |

10 | ⌘ Langbase AI Agent Pipe: Stream 11 |

12 | 13 |

14 | Stream a pipe to stream a text completion 15 |

16 | 17 | 18 |
19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/middleware/logger.ts: -------------------------------------------------------------------------------- 1 | import type { MiddlewareHandler } from 'hono'; 2 | 3 | export const logger = (): MiddlewareHandler => { 4 | return async function logger(c, next) { 5 | await next(); 6 | c.req.matchedRoutes.forEach(({ handler, method, path }, i) => { 7 | const name = 8 | handler.name || 9 | (handler.length < 2 ? '[handler]' : '[middleware]'); 10 | console.log( 11 | method, 12 | ' ', 13 | path, 14 | ' '.repeat(Math.max(10 - path.length, 0)), 15 | name, 16 | i === c.req.routeIndex ? '<- respond from here' : '' 17 | ); 18 | }); 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /tools/eslint-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@baseai/eslint-config", 3 | "version": "0.0.2", 4 | "license": "Apache-2.0", 5 | "private": true, 6 | "files": [ 7 | "library.js", 8 | "next.js", 9 | "react-internal.js" 10 | ], 11 | "devDependencies": { 12 | "@next/eslint-plugin-next": "^14.1.4", 13 | "@typescript-eslint/eslint-plugin": "^7.1.0", 14 | "@typescript-eslint/parser": "^7.1.0", 15 | "@vercel/style-guide": "^5.2.0", 16 | "eslint-config-prettier": "^9.1.0", 17 | "eslint-config-turbo": "^2.0.0", 18 | "eslint-plugin-only-warn": "^1.1.0", 19 | "typescript": "^5.3.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconVersions.tsx: -------------------------------------------------------------------------------- 1 | export function IconVersions( 2 | props: JSX.IntrinsicElements['svg'] 3 | ) { 4 | return ( 5 | 13 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/tool-calling/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import PipeRunToolExample from '../../pipe-run-with-tool'; 3 | 4 | export const ToolCalling = () => { 5 | return ( 6 |
7 | 8 |

9 | ⌘ Langbase: Composable Pipe Run 10 |

11 | 12 |

13 | Run a pipe that can call another pipe. 14 |

15 | 16 | 17 |
18 | ); 19 | }; 20 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/ts-format-code.ts: -------------------------------------------------------------------------------- 1 | import * as prettier from 'prettier'; 2 | 3 | /** 4 | * Formats the given TypeScript code string using Prettier with specified options. 5 | * 6 | * @param code - The TypeScript code to format. 7 | * @returns A promise that resolves to the formatted code string. 8 | */ 9 | export async function formatCode(code: string) { 10 | return await prettier.format(code, { 11 | parser: 'typescript', 12 | singleQuote: true, 13 | trailingComma: 'none', 14 | arrowParens: 'avoid', 15 | printWidth: 80, 16 | useTabs: true, 17 | semi: true, 18 | tabWidth: 4 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconStoreMessages.tsx: -------------------------------------------------------------------------------- 1 | export function IconStoreMessages( 2 | props: JSX.IntrinsicElements['svg'] 3 | ) { 4 | return ( 5 | 13 | 14 | 15 | 21 | 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/tool-calling-stream/page.tsx: -------------------------------------------------------------------------------- 1 | import PipeRunToolStreamExample from '@/components/pipe-run-with-tool-stream'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | AI Agent Pipes: Tool Calling 11 |

12 |

13 | Run a pipe with tool calling. 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /apps/baseai.dev/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | 37 | # content 38 | content/docs/docs.json 39 | content/learn/learn.json 40 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/CartIcon.tsx: -------------------------------------------------------------------------------- 1 | export function CartIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /examples/nextjs/app/demo/pipe-run-pipes-as-tools/page.tsx: -------------------------------------------------------------------------------- 1 | import PipeRunPipesAsTools from '@/components/pipe-run-pipes-as-tools'; 2 | import GoHome from '@/components/ui/go-home'; 3 | 4 | export default function Page() { 5 | return ( 6 |
7 | 8 | 9 |

10 | ⌘ Langbase: Composable Pipe Run 11 |

12 |

13 | Run a pipe that can call another pipe. 14 |

15 | 16 |
17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/cohere/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import CohereAPIConfig from './api'; 3 | import { 4 | CohereChatCompleteConfig, 5 | CohereChatCompleteResponseTransform, 6 | CohereChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const CohereConfig: ProviderConfigs = { 10 | chatComplete: CohereChatCompleteConfig, 11 | api: CohereAPIConfig, 12 | responseTransforms: { 13 | chatComplete: CohereChatCompleteResponseTransform, 14 | 'stream-chatComplete': CohereChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default CohereConfig; 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/google/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import GoogleApiConfig from './api'; 3 | import { 4 | GoogleChatCompleteConfig, 5 | GoogleChatCompleteResponseTransform, 6 | GoogleChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const GoogleConfig: ProviderConfigs = { 10 | api: GoogleApiConfig, 11 | chatComplete: GoogleChatCompleteConfig, 12 | responseTransforms: { 13 | chatComplete: GoogleChatCompleteResponseTransform, 14 | 'stream-chatComplete': GoogleChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default GoogleConfig; 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/ollama/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import OllamaAPIConfig from './api'; 3 | import { 4 | OllamaChatCompleteConfig, 5 | OllamaChatCompleteResponseTransform, 6 | OllamaChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const OllamaConfig: ProviderConfigs = { 10 | api: OllamaAPIConfig, 11 | chatComplete: OllamaChatCompleteConfig, 12 | responseTransforms: { 13 | chatComplete: OllamaChatCompleteResponseTransform, 14 | 'stream-chatComplete': OllamaChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default OllamaConfig; 19 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/generate-embeddings.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | import {execAsync} from './exec-sync'; 3 | import {handleError} from './handle-error'; 4 | 5 | export async function generateEmbeddings({dirName}: {dirName: string}) { 6 | const spinner = p.spinner(); 7 | spinner.start('Understanding your project codebase...'); 8 | 9 | try { 10 | await execAsync(`npx baseai@latest embed -m code-files`, { 11 | cwd: dirName, 12 | }); 13 | 14 | spinner.stop('Developed understanding of your project codebase.'); 15 | } catch (error) { 16 | handleError({spinner, error}); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/astro/baseai/tools/weather.ts: -------------------------------------------------------------------------------- 1 | const getWeather = ({location}: {location: string}) => { 2 | return `Weather of ${location} is 16`; 3 | }; 4 | 5 | const toolGetWeather = () => ({ 6 | run: getWeather, 7 | type: 'function', 8 | function: { 9 | name: 'getWeather', 10 | description: 'Get the current weather of a given location', 11 | parameters: { 12 | type: 'object', 13 | required: ['location'], 14 | properties: { 15 | location: { 16 | type: 'string', 17 | description: 'The city and state, e.g. San Francisco, CA', 18 | }, 19 | }, 20 | }, 21 | }, 22 | }); 23 | export default toolGetWeather; 24 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/chat-advanced/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import ChatAdvancedExample from '../../chat-advanced'; 3 | 4 | export const ChatAdvanced = () => { 5 | return ( 6 |
7 | 8 | 9 |

10 | `usePipe()`: Chat Advanced 11 |

12 | 13 |

14 | A kitchen sink example with all `usePipe()` chat features 15 |

16 | 17 | 18 |
19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /examples/astro/src/pages/api/langbase/pipes/run.ts: -------------------------------------------------------------------------------- 1 | import {mapMetaEnvToProcessEnv} from './../../../../lib/utils'; 2 | import getPipeSummary from '../../../../../baseai/pipes/summary'; 3 | import {Pipe} from '@baseai/core'; 4 | import type {APIRoute} from 'astro'; 5 | 6 | export const POST: APIRoute = async ({request}) => { 7 | const runOptions = await request.json(); 8 | 9 | // 1. Initiate the Pipe. 10 | const pipe = new Pipe(getPipeSummary()); 11 | 12 | // 2. Run the pipe 13 | const result = await pipe.run(runOptions); 14 | 15 | // 3. Return the response stringified. 16 | return new Response(JSON.stringify(result)); 17 | }; 18 | -------------------------------------------------------------------------------- /examples/remix/app/routes/api.langbase.pipes.run.ts: -------------------------------------------------------------------------------- 1 | import type {ActionFunction} from '@remix-run/node'; 2 | import getPipeSummary from '~/../baseai/pipes/summary'; 3 | import {Pipe} from '@baseai/core'; 4 | 5 | export const action: ActionFunction = async ({request}) => { 6 | const runOptions = await request.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | // const pipe = new Pipe(getPipeTinyLlama()); 10 | const pipe = new Pipe(getPipeSummary()); 11 | 12 | // 2. Run the pipe 13 | const result = await pipe.run(runOptions); 14 | 15 | // 3. Return the response stringified. 16 | return new Response(JSON.stringify(result)); 17 | }; 18 | -------------------------------------------------------------------------------- /examples/remix/baseai/tools/weather.ts: -------------------------------------------------------------------------------- 1 | const getWeather = ({location}: {location: string}) => { 2 | return `Weather of ${location} is 16`; 3 | }; 4 | 5 | const toolGetWeather = () => ({ 6 | run: getWeather, 7 | type: 'function', 8 | function: { 9 | name: 'getWeather', 10 | description: 'Get the current weather of a given location', 11 | parameters: { 12 | type: 'object', 13 | required: ['location'], 14 | properties: { 15 | location: { 16 | type: 'string', 17 | description: 'The city and state, e.g. San Francisco, CA', 18 | }, 19 | }, 20 | }, 21 | }, 22 | }); 23 | export default toolGetWeather; 24 | -------------------------------------------------------------------------------- /apps/baseai.dev/content/docs/memory/list.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'List' 3 | description: "List all memory in your current project directory." 4 | tags: 5 | - baseai 6 | - memory 7 | - langbase 8 | - list 9 | section: 'Memory' 10 | published: 2024-09-24 11 | modified: 2024-09-24 12 | --- 13 | 14 | # List all memory 15 | 16 | List all memory in your current project directory. 17 | 18 | --- 19 | 20 | Use the `memory list` command to list all memory in your current project directory. 21 | 22 | ```bash 23 | npx baseai@latest memory --list 24 | ``` 25 | 26 | It will list all memory in the current project directory. 27 | 28 | --- 29 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/ChatBubbleIcon.tsx: -------------------------------------------------------------------------------- 1 | export function ChatBubbleIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/astro/src/components/pages/pipe-run-pipes-as-tools/index.tsx: -------------------------------------------------------------------------------- 1 | import GoHome from '../../ui/go-home'; 2 | import PipeRunToolExample from '../../pipe-run-pipes-as-tools'; 3 | 4 | export const PipeRunPipesAsTools = () => { 5 | return ( 6 |
7 | 8 |

9 | ⌘ Langbase: Composable Pipe Run 10 |

11 | 12 |

13 | Run a pipe that can call another pipe. 14 |

15 | 16 | 17 |
18 | ); 19 | }; 20 | -------------------------------------------------------------------------------- /examples/nextjs/app/api/langbase/pipes/run-memory/route.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import {NextRequest} from 'next/server'; 3 | import pipeWithMemory from '../../../../../baseai/pipes/pipe-with-memory'; 4 | 5 | export async function POST(req: NextRequest) { 6 | const runOptions = await req.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(pipeWithMemory()); 10 | 11 | // 2. Run the pipe with user messages and other run options. 12 | const {stream} = await pipe.run(runOptions); 13 | 14 | // 3. Return the ReadableStream directly. 15 | return new Response(stream, { 16 | status: 200, 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/tools/weather.ts: -------------------------------------------------------------------------------- 1 | const getWeather = ({location}: {location: string}) => { 2 | return `Weather of ${location} is 16`; 3 | }; 4 | 5 | const toolGetWeather = () => ({ 6 | run: getWeather, 7 | type: 'function', 8 | function: { 9 | name: 'getWeather', 10 | description: 'Get the current weather of a given location', 11 | parameters: { 12 | type: 'object', 13 | required: ['location'], 14 | properties: { 15 | location: { 16 | type: 'string', 17 | description: 'The city and state, e.g. San Francisco, CA', 18 | }, 19 | }, 20 | }, 21 | }, 22 | }); 23 | export default toolGetWeather; 24 | -------------------------------------------------------------------------------- /examples/nextjs/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/remix/app/routes/api.langbase.pipes.run-tool.ts: -------------------------------------------------------------------------------- 1 | import type {ActionFunction} from '@remix-run/node'; 2 | import getPipeWithTool from '~/../baseai/pipes/pipe-with-tool'; 3 | import {Pipe} from '@baseai/core'; 4 | 5 | export const action: ActionFunction = async ({request}) => { 6 | const runOptions = await request.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(getPipeWithTool()); 10 | 11 | // 2. Run the pipe with user messages and other run options. 12 | const result = await pipe.run(runOptions); 13 | 14 | // 2. Return the response stringified. 15 | return new Response(JSON.stringify(result)); 16 | }; 17 | -------------------------------------------------------------------------------- /examples/astro/src/pages/api/langbase/pipes/run-tool.ts: -------------------------------------------------------------------------------- 1 | import {mapMetaEnvToProcessEnv} from './../../../../lib/utils'; 2 | import getPipeWithTool from '../../../../../baseai/pipes/summary'; 3 | import {Pipe} from '@baseai/core'; 4 | import type {APIRoute} from 'astro'; 5 | 6 | export const POST: APIRoute = async ({request}) => { 7 | const runOptions = await request.json(); 8 | 9 | // 1. Initiate the Pipe. 10 | const pipe = new Pipe(getPipeWithTool()); 11 | 12 | // 2. Run the pipe 13 | const result = await pipe.run(runOptions); 14 | 15 | // 3. Return the response stringified. 16 | return new Response(JSON.stringify(result)); 17 | }; 18 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/fireworks-ai/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | const FireworksAIAPIConfig: ProviderAPIConfig = { 3 | baseURL: 'https://api.fireworks.ai/inference/v1', 4 | headers: ({ llmApiKey }: { llmApiKey: string }) => { 5 | return { 6 | Authorization: `Bearer ${llmApiKey}`, 7 | Accept: 'application/json' 8 | }; 9 | }, 10 | getEndpoint: ({ endpoint }: { endpoint: string }) => { 11 | switch (endpoint) { 12 | case 'chatComplete': 13 | return '/chat/completions'; 14 | default: 15 | return ''; 16 | } 17 | } 18 | }; 19 | 20 | export default FireworksAIAPIConfig; 21 | -------------------------------------------------------------------------------- /tools/tsconfig/base.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Default", 4 | "compilerOptions": { 5 | "strict": true, 6 | "composite": false, 7 | "declaration": true, 8 | "skipLibCheck": true, 9 | "inlineSources": false, 10 | "declarationMap": true, 11 | "esModuleInterop": true, 12 | "noUnusedLocals": false, 13 | "isolatedModules": true, 14 | "moduleResolution": "node", 15 | "noUnusedParameters": false, 16 | "preserveWatchOutput": true, 17 | "forceConsistentCasingInFileNames": true, 18 | "types": ["@types/node", "vitest/globals"] 19 | }, 20 | "exclude": ["node_modules"] 21 | } 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconDoc.tsx: -------------------------------------------------------------------------------- 1 | export function IconDoc(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/ShapesIcon.tsx: -------------------------------------------------------------------------------- 1 | export function ShapesIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/nodejs/baseai/memory/ai-agent-memory/index.ts: -------------------------------------------------------------------------------- 1 | import {MemoryI} from '@baseai/core'; 2 | 3 | const memoryAiAgentMemory = (): MemoryI => ({ 4 | name: 'ai-agent-memory', 5 | description: 'My list of docs as memory for an AI agent pipe', 6 | git: { 7 | enabled: true, 8 | include: ['**/*'], 9 | gitignore: true, 10 | deployedAt: '', 11 | embeddedAt: '', 12 | }, 13 | documents: { 14 | meta: doc => { 15 | // generate a URL for each document 16 | const url = `https://example.com/${doc.path}`; 17 | return { 18 | url, 19 | name: doc.name, 20 | }; 21 | }, 22 | }, 23 | }); 24 | 25 | export default memoryAiAgentMemory; 26 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconJsonMode.tsx: -------------------------------------------------------------------------------- 1 | export function IconJsonMode( 2 | props: JSX.IntrinsicElements['svg'] 3 | ) { 4 | return ( 5 | 13 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconUsage.tsx: -------------------------------------------------------------------------------- 1 | export function IconUsage(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/memory/get-available-memories.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | 4 | export async function getAvailableMemories() { 5 | try { 6 | // Construct the path containing all memories folders. 7 | const memoryPath = path.join(process.cwd(), 'baseai', 'memory'); 8 | 9 | // Check if the baseai directory exists. 10 | if (!fs.existsSync(memoryPath)) return []; 11 | 12 | // Get all directories names in the memory path. 13 | const memoryNames = await fs.promises.readdir(memoryPath); 14 | 15 | // Return the memory names. 16 | return memoryNames; 17 | } catch (error: any) { 18 | return []; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/ui/iconists/icon-usage.tsx: -------------------------------------------------------------------------------- 1 | export function IconUsage(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /examples/nextjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["dom", "dom.iterable", "esnext"], 4 | "allowJs": true, 5 | "skipLibCheck": true, 6 | "strict": true, 7 | "noEmit": true, 8 | "esModuleInterop": true, 9 | "module": "esnext", 10 | "moduleResolution": "bundler", 11 | "resolveJsonModule": true, 12 | "isolatedModules": true, 13 | "jsx": "preserve", 14 | "incremental": true, 15 | "plugins": [ 16 | { 17 | "name": "next" 18 | } 19 | ], 20 | "paths": { 21 | "@/*": ["./*"] 22 | } 23 | }, 24 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 25 | "exclude": ["node_modules"] 26 | } 27 | -------------------------------------------------------------------------------- /examples/remix/app/entry.client.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * By default, Remix will handle hydrating your app on the client for you. 3 | * You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨ 4 | * For more information, see https://remix.run/file-conventions/entry.client 5 | */ 6 | 7 | import { RemixBrowser } from "@remix-run/react"; 8 | import { startTransition, StrictMode } from "react"; 9 | import { hydrateRoot } from "react-dom/client"; 10 | 11 | startTransition(() => { 12 | hydrateRoot( 13 | document, 14 | 15 | 16 | 17 | ); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/anthropic/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import AnthropicAPIConfig from './api'; 3 | import { 4 | AnthropicChatCompleteConfig, 5 | AnthropicChatCompleteResponseTransform, 6 | AnthropicChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const AnthropicConfig: ProviderConfigs = { 10 | chatComplete: AnthropicChatCompleteConfig, 11 | api: AnthropicAPIConfig, 12 | responseTransforms: { 13 | chatComplete: AnthropicChatCompleteResponseTransform, 14 | 'stream-chatComplete': AnthropicChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default AnthropicConfig; 19 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/mistral-ai/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import MistralAIAPIConfig from './api'; 3 | import { 4 | MistralAIChatCompleteConfig, 5 | MistralAIChatCompleteResponseTransform, 6 | MistralAIChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const MistralAIConfig: ProviderConfigs = { 10 | chatComplete: MistralAIChatCompleteConfig, 11 | api: MistralAIAPIConfig, 12 | responseTransforms: { 13 | chatComplete: MistralAIChatCompleteResponseTransform, 14 | 'stream-chatComplete': MistralAIChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default MistralAIConfig; 19 | -------------------------------------------------------------------------------- /examples/nextjs/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .yarn/install-state.gz 8 | 9 | # testing 10 | /coverage 11 | 12 | # next.js 13 | /.next/ 14 | /out/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | 38 | # baseai 39 | /.baseai/ 40 | # baseai 41 | **/.baseai/ 42 | # env file 43 | .env 44 | -------------------------------------------------------------------------------- /examples/astro/src/pages/api/langbase/pipes/run-pipes-as-tools.ts: -------------------------------------------------------------------------------- 1 | import {mapMetaEnvToProcessEnv} from './../../../../lib/utils'; 2 | import getPipeWithPipesAsTools from '../../../../../baseai/pipes/pipe-with-pipes-as-tools'; 3 | import {Pipe} from '@baseai/core'; 4 | import type {APIRoute} from 'astro'; 5 | 6 | export const POST: APIRoute = async ({request}) => { 7 | const runOptions = await request.json(); 8 | 9 | // 1. Initiate the Pipe. 10 | const pipe = new Pipe(getPipeWithPipesAsTools()); 11 | 12 | // 2. Run the pipe 13 | const result = await pipe.run(runOptions); 14 | 15 | // 3. Return the response stringified. 16 | return new Response(JSON.stringify(result)); 17 | }; 18 | -------------------------------------------------------------------------------- /examples/remix/app/routes/api.langbase.pipes.run-pipes-as-tools.ts: -------------------------------------------------------------------------------- 1 | import type {ActionFunction} from '@remix-run/node'; 2 | import getPipeWithPipesAsTools from '~/../baseai/pipes/pipe-with-pipes-as-tools'; 3 | import {Pipe} from '@baseai/core'; 4 | 5 | export const action: ActionFunction = async ({request}) => { 6 | const runOptions = await request.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | // const pipe = new Pipe(getPipeTinyLlama()); 10 | const pipe = new Pipe(getPipeWithPipesAsTools()); 11 | 12 | // 2. Run the pipe 13 | const result = await pipe.run(runOptions); 14 | 15 | // 3. Return the response stringified. 16 | return new Response(JSON.stringify(result)); 17 | }; 18 | -------------------------------------------------------------------------------- /examples/remix/app/routes/api.langbase.pipes.run-stream.ts: -------------------------------------------------------------------------------- 1 | import getPipeSummary from '~/../baseai/pipes/summary'; 2 | import {Pipe} from '@baseai/core'; 3 | import {ActionFunction} from '@remix-run/node'; 4 | 5 | export const action: ActionFunction = async ({request}) => { 6 | const runOptions = await request.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(getPipeSummary()); 10 | 11 | // 2. Run the Pipe. 12 | const {stream, threadId} = await pipe.run(runOptions); 13 | 14 | // 3. Return the ReadableStream directly. 15 | return new Response(stream, { 16 | status: 200, 17 | headers: { 18 | 'lb-thread-id': threadId ?? '', 19 | }, 20 | }); 21 | }; 22 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/fireworks-ai/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import FireworksAIAPIConfig from './api'; 3 | import { 4 | FireworksAIChatCompleteConfig, 5 | FireworksAIChatCompleteResponseTransform, 6 | FireworksAIChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const FireworksAIConfig: ProviderConfigs = { 10 | chatComplete: FireworksAIChatCompleteConfig, 11 | api: FireworksAIAPIConfig, 12 | responseTransforms: { 13 | chatComplete: FireworksAIChatCompleteResponseTransform, 14 | 'stream-chatComplete': FireworksAIChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default FireworksAIConfig; 19 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/get-available-tools.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | 4 | export async function getAvailableTools() { 5 | // Construct the path containing all tools folders. 6 | const toolsPath = path.join(process.cwd(), 'baseai', 'tools'); 7 | 8 | // Check if the baseai directory exists. 9 | if (!fs.existsSync(toolsPath)) return []; 10 | 11 | // Get all directories names in the tool path. 12 | const toolsNames = await fs.promises.readdir(toolsPath); 13 | 14 | // Make complete paths for each tool. 15 | const toolsPaths = toolsNames.map(toolName => toolName.replace('.ts', '')); 16 | 17 | // Return the tool names. 18 | return toolsPaths; 19 | } 20 | -------------------------------------------------------------------------------- /packages/core/src/utils/is-prod.ts: -------------------------------------------------------------------------------- 1 | const FORCE_PROD = false; 2 | const TEST_PROD_LOCALLY = FORCE_PROD; 3 | 4 | export function isProd() { 5 | if (TEST_PROD_LOCALLY) return true; 6 | return process.env.NODE_ENV === 'production'; 7 | } 8 | 9 | export function isLocal() { 10 | return process.env.NODE_ENV !== 'production'; 11 | } 12 | 13 | export function getApiUrl(prod?: boolean) { 14 | if (prod) return 'https://api.langbase.com'; 15 | else return 'http://localhost:9000'; 16 | 17 | // TODO: Make local port configurable. 18 | // return isProd() ? 'https://api.langbase.com' : 'http://localhost:9000'; 19 | // return isProd() ? 'http://localhost:8787' : 'http://localhost:9000'; 20 | } 21 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/anthropic/api.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderAPIConfig } from 'types/providers'; 2 | 3 | const AnthropicAPIConfig: ProviderAPIConfig = { 4 | baseURL: 'https://api.anthropic.com/v1', 5 | headers: ({ 6 | llmApiKey, 7 | endpoint 8 | }: { 9 | llmApiKey: string; 10 | endpoint: string; 11 | }) => { 12 | const headers: Record = { 13 | 'X-API-Key': `${llmApiKey}`, 14 | 'anthropic-version': '2023-06-01' 15 | }; 16 | if (endpoint === 'chatComplete') { 17 | headers['anthropic-beta'] = 'messages-2023-12-15'; 18 | } 19 | return headers; 20 | }, 21 | chatComplete: '/messages' 22 | }; 23 | 24 | export default AnthropicAPIConfig; 25 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/perplexity/index.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfigs } from 'types/providers'; 2 | import PerplexityAIApiConfig from './api'; 3 | import { 4 | PerplexityAIChatCompleteConfig, 5 | PerplexityAIChatCompleteResponseTransform, 6 | PerplexityAIChatCompleteStreamChunkTransform 7 | } from './chatComplete'; 8 | 9 | const PerplexityAIConfig: ProviderConfigs = { 10 | chatComplete: PerplexityAIChatCompleteConfig, 11 | api: PerplexityAIApiConfig, 12 | responseTransforms: { 13 | chatComplete: PerplexityAIChatCompleteResponseTransform, 14 | 'stream-chatComplete': PerplexityAIChatCompleteStreamChunkTransform 15 | } 16 | }; 17 | 18 | export default PerplexityAIConfig; 19 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/SquaresPlusIcon.tsx: -------------------------------------------------------------------------------- 1 | export function SquaresPlusIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/questions.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | 3 | export async function questions() { 4 | const readme = await p.group( 5 | { 6 | level: () => 7 | p.select({ 8 | message: 9 | 'Choose the level of detail you want in the README.', 10 | options: [ 11 | {label: 'Simple', value: 'simple' as unknown as any}, 12 | { 13 | label: 'Detailed', 14 | value: 'detailed' as unknown as any, 15 | }, 16 | ], 17 | }), 18 | }, 19 | { 20 | onCancel: () => { 21 | p.cancel('Operation cancelled.'); 22 | process.exit(0); 23 | }, 24 | }, 25 | ); 26 | 27 | return {level: readme.level}; 28 | } 29 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/hono/validate.ts: -------------------------------------------------------------------------------- 1 | import {ApiErrorZod, ErrorCodesType} from './errors'; 2 | 3 | async function validate({ 4 | schema, 5 | input, 6 | code = `BAD_REQUEST`, 7 | message, 8 | }: { 9 | schema: any; 10 | input: any; 11 | code?: ErrorCodesType; 12 | message?: string; 13 | }) { 14 | const result = await schema.safeParseAsync(input); 15 | ApiErrorZod.handle({code, result, message}); 16 | 17 | // Since ApiError.handle throws, TypeScript may not infer that execution ends above 18 | // and result.data is now avaiable. 19 | // @ts-ignore - TS doesn't know that the function ends above. 20 | return result.data; // Return the validated data 21 | } 22 | 23 | export default validate; 24 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/middleware/debug-base.ts: -------------------------------------------------------------------------------- 1 | import type { MiddlewareHandler } from 'hono'; 2 | import { dlog } from '../utils/dlog'; 3 | 4 | export const debugBase = (): MiddlewareHandler => { 5 | return async function debugUrl(c, next) { 6 | const url = new URL(c.req.url); 7 | const path = url.pathname; 8 | 9 | dlog('API HIT', { 10 | url: c.req.url, 11 | path: path, 12 | method: c.req.method 13 | }); 14 | 15 | if (c.req.method.toUpperCase() === 'POST') { 16 | try { 17 | const req = await c.req.json(); 18 | dlog('REQUEST BODY', req); 19 | } catch (error) { 20 | dlog('ERROR PARSING REQUEST BODY', error); 21 | } 22 | } 23 | 24 | await next(); 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/get-available-pipes.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | 4 | export async function getAvailablePipes() { 5 | // Construct the path containing all pipes folders. 6 | const pipesPath = path.join(process.cwd(), 'baseai', 'pipes'); 7 | 8 | // Check if the baseai directory exists. 9 | if (!fs.existsSync(pipesPath)) return []; 10 | 11 | // Get all directories names in the pipe path. 12 | const pipeNames = await fs.promises.readdir(pipesPath); 13 | 14 | // Make complete paths for each pipe. 15 | const slugifiedPipes = pipeNames.map(pipeName => 16 | pipeName.replace('.ts', '') 17 | ); 18 | 19 | // Return the pipe names. 20 | return slugifiedPipes; 21 | } 22 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/is-tool-present.ts: -------------------------------------------------------------------------------- 1 | import slugify from '@sindresorhus/slugify'; 2 | 3 | /** 4 | * Checks if a tool with the given name is present in the list of all tools. 5 | * 6 | * @param {Object} params - The parameters for the function. 7 | * @param {string} params.name - The name of the tool to check for. 8 | * @param {string[]} params.allTools - The list of all tools. 9 | * @returns {boolean} - Returns `true` if the tool is present, otherwise `false`. 10 | */ 11 | export function isToolPresent({ 12 | name, 13 | allTools 14 | }: { 15 | name: string; 16 | allTools: string[]; 17 | }) { 18 | return allTools.some(tool => { 19 | return slugify(tool) === slugify(name); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/MapPinIcon.tsx: -------------------------------------------------------------------------------- 1 | export function MapPinIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /examples/remix/app/routes/api.langbase.pipes.run-memory.ts: -------------------------------------------------------------------------------- 1 | import type {ActionFunction} from '@remix-run/node'; 2 | import getPipeWithMemory from '~/../baseai/pipes/pipe-with-memory'; 3 | import {Pipe} from '@baseai/core'; 4 | 5 | export const action: ActionFunction = async ({request}) => { 6 | const runOptions = await request.json(); 7 | console.log('runOptions:', runOptions); 8 | 9 | // 1. Initiate the Pipe. 10 | const pipe = new Pipe(getPipeWithMemory()); 11 | 12 | // 2. Run the pipe with user messages and other run options. 13 | const {stream} = await pipe.run(runOptions); 14 | 15 | // 3. Return the ReadableStream directly. 16 | return new Response(stream, { 17 | status: 200, 18 | }); 19 | }; 20 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/CalendarIcon.tsx: -------------------------------------------------------------------------------- 1 | export function CalendarIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/ClipboardIcon.tsx: -------------------------------------------------------------------------------- 1 | export function ClipboardIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/exit-server.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | import {spawn} from 'child_process'; 3 | 4 | export async function exitServer() { 5 | const spinner = p.spinner(); 6 | spinner.start('Stopping AI server...'); 7 | // Spawn the server process detached from the parent 8 | const serverProcess = spawn('npx', ['kill-port', '9000'], { 9 | // Detach the process so it runs independently 10 | detached: true, 11 | // Pipe stdout/stderr to files or ignore them 12 | stdio: 'ignore', 13 | shell: process.platform === 'win32', 14 | }); 15 | 16 | // Unref the process so it won't keep the parent alive 17 | serverProcess.unref(); 18 | spinner.stop('AI server stopped.'); 19 | } 20 | -------------------------------------------------------------------------------- /examples/astro/src/layouts/Layout.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import './globals.css'; 3 | 4 | interface Props { 5 | title: string; 6 | } 7 | 8 | const {title} = Astro.props; 9 | --- 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {title} 19 | 20 | 21 |
24 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /tools/eslint-config/library.js: -------------------------------------------------------------------------------- 1 | const {resolve} = require('node:path'); 2 | 3 | const project = resolve(process.cwd(), 'tsconfig.json'); 4 | 5 | /** @type {import("eslint").Linter.Config} */ 6 | module.exports = { 7 | extends: ['eslint:recommended', 'prettier', 'turbo'], 8 | plugins: ['only-warn'], 9 | globals: { 10 | React: true, 11 | JSX: true, 12 | }, 13 | env: { 14 | node: true, 15 | }, 16 | settings: { 17 | 'import/resolver': { 18 | typescript: { 19 | project, 20 | }, 21 | }, 22 | }, 23 | ignorePatterns: [ 24 | // Ignore dotfiles 25 | '.*.js', 26 | 'node_modules/', 27 | 'dist/', 28 | ], 29 | overrides: [ 30 | { 31 | files: ['*.js?(x)', '*.ts?(x)'], 32 | }, 33 | ], 34 | }; 35 | -------------------------------------------------------------------------------- /packages/baseai/src/memory/list.ts: -------------------------------------------------------------------------------- 1 | import { heading } from '@/utils/heading'; 2 | import icons from '@/utils/icons'; 3 | import { getAvailableMemories } from '@/utils/memory/get-available-memories'; 4 | import * as p from '@clack/prompts'; 5 | 6 | export async function listMemory() { 7 | const availableMemories = await getAvailableMemories(); 8 | if (availableMemories.length === 0) { 9 | p.log.message('No memory available.'); 10 | return; 11 | } 12 | p.intro( 13 | heading({ 14 | text: 'MEMORY', 15 | sub: 'List of all available memory sets' 16 | }) 17 | ); 18 | console.log(''); 19 | availableMemories.forEach(item => { 20 | console.log(`${icons.memory} ${item}`); 21 | }); 22 | 23 | process.exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconApi.tsx: -------------------------------------------------------------------------------- 1 | export function IconApi(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/ui/iconists/icon-api.tsx: -------------------------------------------------------------------------------- 1 | export function IconApi(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /examples/astro/src/pages/api/langbase/pipes/run-stream.ts: -------------------------------------------------------------------------------- 1 | import {mapMetaEnvToProcessEnv} from './../../../../lib/utils'; 2 | import getPipeSummary from '../../../../../baseai/pipes/summary'; 3 | import {Pipe} from '@baseai/core'; 4 | import type {APIRoute} from 'astro'; 5 | 6 | export const POST: APIRoute = async ({request}) => { 7 | const runOptions = await request.json(); 8 | 9 | // 1. Initiate the Pipe. 10 | const pipe = new Pipe(getPipeSummary()); 11 | 12 | // 2. Run the Pipe. 13 | const {stream, threadId} = await pipe.run(runOptions); 14 | 15 | // 3. Return the ReadableStream directly. 16 | return new Response(stream, { 17 | status: 200, 18 | headers: { 19 | 'lb-thread-id': threadId ?? '', 20 | }, 21 | }); 22 | }; 23 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/spoiler.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Accordion, 3 | AccordionContent, 4 | AccordionItem, 5 | AccordionTrigger 6 | } from '@/components/ui/accordion'; 7 | 8 | export function Spoiler({ 9 | title, 10 | children 11 | }: { 12 | title: string; 13 | children: React.ReactNode; 14 | }) { 15 | return ( 16 | 21 | 22 | 23 |

{title}

24 |
25 | {children} 26 |
27 |
28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /examples/astro/src/pages/api/langbase/pipes/run-memory.ts: -------------------------------------------------------------------------------- 1 | import {mapMetaEnvToProcessEnv} from './../../../../lib/utils'; 2 | import getPipeWithMemory from '../../../../../baseai/pipes/pipe-with-memory'; 3 | import {Pipe} from '@baseai/core'; 4 | import type {APIRoute} from 'astro'; 5 | 6 | export const POST: APIRoute = async ({request}) => { 7 | const runOptions = await request.json(); 8 | 9 | // 1. Initiate the Pipe. 10 | const pipe = new Pipe(getPipeWithMemory()); 11 | 12 | // 2. Run the Pipe. 13 | const {stream, threadId} = await pipe.run(runOptions); 14 | 15 | // 3. Return the ReadableStream directly. 16 | return new Response(stream, { 17 | status: 200, 18 | headers: { 19 | 'lb-thread-id': threadId ?? '', 20 | }, 21 | }); 22 | }; 23 | -------------------------------------------------------------------------------- /tools/eslint-config/next.js: -------------------------------------------------------------------------------- 1 | const {resolve} = require('node:path'); 2 | 3 | const project = resolve(process.cwd(), 'tsconfig.json'); 4 | 5 | /** @type {import("eslint").Linter.Config} */ 6 | module.exports = { 7 | extends: [ 8 | 'eslint:recommended', 9 | 'prettier', 10 | require.resolve('@vercel/style-guide/eslint/next'), 11 | 'turbo', 12 | ], 13 | globals: { 14 | React: true, 15 | JSX: true, 16 | }, 17 | env: { 18 | node: true, 19 | }, 20 | plugins: ['only-warn'], 21 | settings: { 22 | 'import/resolver': { 23 | typescript: { 24 | project, 25 | }, 26 | }, 27 | }, 28 | ignorePatterns: [ 29 | // Ignore dotfiles 30 | '.*.js', 31 | 'node_modules/', 32 | ], 33 | overrides: [{files: ['*.js?(x)', '*.ts?(x)']}], 34 | }; 35 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/content.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { MarkdownComponents } from '@/components/mdx'; 4 | import { MDXRemoteSerializeResult } from 'next-mdx-remote'; 5 | import { Wrapper } from './mdx/Wrapper'; 6 | import dynamic from 'next/dynamic'; 7 | 8 | const MDXRemote = dynamic( 9 | () => import('next-mdx-remote').then(mod => mod.MDXRemote), 10 | { ssr: false } 11 | ); 12 | 13 | export default function Content({ 14 | content 15 | }: { 16 | content?: MDXRemoteSerializeResult< 17 | Record, 18 | Record 19 | >; 20 | }) { 21 | 22 | 23 | return ( 24 | 25 | {content && ( 26 | 27 | )} 28 | 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconKeyset.tsx: -------------------------------------------------------------------------------- 1 | export function IconKeyset(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/scripts/remove-runtime.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | function getPath(type) { 4 | return [ 5 | `${process.cwd()}/src/app/${type}/[section]/page.tsx`, 6 | `${process.cwd()}/src/app/${type}/[section]/[slug]/page.tsx` 7 | ]; 8 | } 9 | 10 | async function main() { 11 | const runTime = `export const runtime = 'edge';\n\n`; 12 | 13 | getPath('docs').forEach(async path => { 14 | const docContent = fs.readFileSync(path, 'utf-8'); 15 | 16 | await fs.promises.writeFile(path, docContent.replace(runTime, '')); 17 | }); 18 | 19 | getPath('learn').forEach(async path => { 20 | const learnContent = fs.readFileSync(path, 'utf-8'); 21 | await fs.promises.writeFile(path, learnContent.replace(runTime, '')); 22 | }); 23 | } 24 | 25 | main(); 26 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/memory/check-memory-exist.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | import fs from 'fs/promises'; 3 | import path from 'path'; 4 | 5 | export const checkMemoryExists = async (memoryName: string) => { 6 | const memoryDir = path.join(process.cwd(), 'baseai', 'memory', memoryName); 7 | const indexFilePath = path.join(memoryDir, 'index.ts'); 8 | 9 | try { 10 | await fs.access(memoryDir); 11 | } catch (error) { 12 | p.cancel(`Memory '${memoryName}' does not exist.`); 13 | process.exit(1); 14 | } 15 | 16 | try { 17 | await fs.access(indexFilePath); 18 | } catch (error) { 19 | p.cancel( 20 | `Index file for memory '${memoryName}/index.ts' does not exist.` 21 | ); 22 | process.exit(1); 23 | } 24 | 25 | return true; 26 | }; 27 | -------------------------------------------------------------------------------- /examples/nodejs/baseai/pipes/summary.ts: -------------------------------------------------------------------------------- 1 | import {PipeI} from '@baseai/core'; 2 | 3 | const buildPipe = (): PipeI => ({ 4 | apiKey: process.env.LANGBASE_API_KEY!, // Replace with your API key https://langbase.com/docs/api-reference/api-keys 5 | name: 'summary', 6 | description: '', 7 | status: 'private', 8 | model: 'openai:gpt-4o-mini', 9 | stream: true, 10 | json: false, 11 | store: true, 12 | moderate: true, 13 | top_p: 1, 14 | max_tokens: 1000, 15 | temperature: 0.7, 16 | presence_penalty: 1, 17 | frequency_penalty: 1, 18 | stop: [], 19 | tool_choice: 'auto', 20 | parallel_tool_calls: false, 21 | messages: [{role: 'system', content: `You are a helpful AI assistant.`}], 22 | variables: [], 23 | memory: [], 24 | tools: [], 25 | }); 26 | 27 | export default buildPipe; 28 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/FolderIcon.tsx: -------------------------------------------------------------------------------- 1 | export function FolderIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/Prose.tsx: -------------------------------------------------------------------------------- 1 | import clsx from 'clsx'; 2 | 3 | export function Prose({ 4 | as, 5 | className, 6 | ...props 7 | }: Omit, 'as' | 'className'> & { 8 | as?: T; 9 | className?: string; 10 | }) { 11 | let Component = as ?? 'div'; 12 | 13 | return ( 14 | *)` is used to select all direct children without an increase in specificity like you'd get from just `& > *` 19 | '[html_:where(&>*)]:mx-auto [html_:where(&>*)]:max-w-2xl [html_:where(&>*)]:lg:mx-[calc(50%-min(50%,theme(maxWidth.lg)))] [html_:where(&>*)]:lg:max-w-3xl' 20 | )} 21 | {...props} 22 | /> 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /examples/astro/src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import {type ClassValue, clsx} from 'clsx'; 2 | import {twMerge} from 'tailwind-merge'; 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)); 6 | } 7 | 8 | /** 9 | * Maps environment variables from `import.meta.env` to `process.env`. 10 | * 11 | * This function iterates over all keys in `import.meta.env` and assigns 12 | * each value to the corresponding key in `process.env`. This is useful 13 | * for ensuring that environment variables are accessible in a Node.js 14 | * environment when using tools like Vite or Astro that provide `import.meta.env`. 15 | */ 16 | export function mapMetaEnvToProcessEnv() { 17 | Object.keys(import.meta.env).forEach(key => { 18 | process.env[key] = import.meta.env[key]; 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/styles/tailwind.css: -------------------------------------------------------------------------------- 1 | @layer base { 2 | :root { 3 | /* --shiki-color-text: theme('colors.white'); 4 | --shiki-token-constant: theme('colors.emerald.300'); 5 | --shiki-token-string: theme('colors.emerald.300'); 6 | --shiki-token-comment: theme('colors.zinc.500'); 7 | --shiki-token-keyword: theme('colors.sky.300'); 8 | --shiki-token-parameter: theme('colors.pink.300'); 9 | --shiki-token-function: theme('colors.violet.300'); 10 | --shiki-token-string-expression: theme('colors.emerald.300'); 11 | --shiki-token-punctuation: theme('colors.zinc.200'); */ 12 | } 13 | 14 | [inert] ::-webkit-scrollbar { 15 | display: none; 16 | } 17 | } 18 | 19 | @tailwind base; 20 | @tailwind components; 21 | @tailwind utilities; 22 | @import './global.css'; 23 | -------------------------------------------------------------------------------- /examples/astro/public/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /examples/nextjs/app/api/langbase/pipes/run-tool-stream/route.ts: -------------------------------------------------------------------------------- 1 | import pipeWithToolsStream from '@/baseai/pipes/pipe-with-tool-stream'; 2 | import {Pipe, RunResponseStream} from '@baseai/core'; 3 | import {NextRequest} from 'next/server'; 4 | 5 | export async function POST(req: NextRequest) { 6 | const runOptions = await req.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(pipeWithToolsStream()); 10 | 11 | // 2. Run the pipe with user messages and other run options. 12 | let {stream, threadId} = (await pipe.run({ 13 | ...runOptions, 14 | stream: true, 15 | })) as unknown as RunResponseStream; 16 | 17 | // 3. Stream the response. 18 | return new Response(stream, { 19 | status: 200, 20 | headers: { 21 | 'lb-thread-id': threadId ?? '', 22 | }, 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/pipes/summary.ts: -------------------------------------------------------------------------------- 1 | import {PipeI} from '@baseai/core'; 2 | 3 | const pipeSummary = (): PipeI => ({ 4 | apiKey: process.env.LANGBASE_API_KEY!, 5 | name: 'summary', 6 | description: 'AI Summary agent', 7 | status: 'private', 8 | model: 'openai:gpt-4o-mini', 9 | stream: true, 10 | json: false, 11 | store: true, 12 | moderate: true, 13 | top_p: 1, 14 | max_tokens: 100, 15 | temperature: 0.7, 16 | presence_penalty: 1, 17 | frequency_penalty: 1, 18 | stop: [], 19 | tool_choice: 'auto', 20 | parallel_tool_calls: false, 21 | messages: [ 22 | { 23 | role: 'system', 24 | content: `You are a helpful AI assistant. Make everything Less wordy.`, 25 | }, 26 | ], 27 | variables: [], 28 | tools: [], 29 | memory: [], 30 | }); 31 | 32 | export default pipeSummary; 33 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.chat-simple.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import ChatSimple from '~/components/chat-simple'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | export const meta: MetaFunction = () => { 6 | return [ 7 | { title: 'Simple Chat Pipe ⌘' }, 8 | { name: "description", content: "Chat with the AI agent" }, 9 | ]; 10 | }; 11 | 12 | export default function Page() { 13 | return ( 14 |
15 | 16 | 17 |

18 | `usePipe()`: Chat 19 |

20 |

21 | Chat with the AI agent 22 |

23 | 24 |
25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/debug-mode.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | import { heading } from './heading'; 3 | 4 | export default function debugMode(cli: any) { 5 | p.intro( 6 | heading({ 7 | text: 'DEBUG MODE', 8 | sub: 'logs will be verbose...', 9 | dim: true 10 | }) 11 | ); 12 | console.log(); 13 | 14 | p.intro( 15 | heading({ 16 | text: 'cwd', 17 | dim: true 18 | }) 19 | ); 20 | console.log(process.cwd()); 21 | console.log(); 22 | 23 | p.intro( 24 | heading({ 25 | text: 'cli.flags', 26 | dim: true 27 | }) 28 | ); 29 | console.log(cli.flags); 30 | console.log(); 31 | 32 | p.intro( 33 | heading({ 34 | text: 'cli.input', 35 | sub: 'commands', 36 | dim: true 37 | }) 38 | ); 39 | console.log(cli.input); 40 | console.log(); 41 | } 42 | -------------------------------------------------------------------------------- /.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/hooks/use-copy-to-clipboard.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import * as React from 'react'; 4 | 5 | export interface useCopyToClipboardProps { 6 | timeout?: number; 7 | } 8 | 9 | export function useCopyToClipboard({ 10 | timeout = 2000 11 | }: useCopyToClipboardProps) { 12 | const [isCopied, setIsCopied] = React.useState(false); 13 | 14 | const copyToClipboard = (value: string) => { 15 | if (typeof window === 'undefined' || !navigator.clipboard?.writeText) { 16 | return; 17 | } 18 | 19 | if (!value) { 20 | return; 21 | } 22 | 23 | navigator.clipboard.writeText(value).then(() => { 24 | setIsCopied(true); 25 | 26 | setTimeout(() => { 27 | setIsCopied(false); 28 | }, timeout); 29 | }); 30 | }; 31 | 32 | return { isCopied, copyToClipboard }; 33 | } 34 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.memory.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import PipeRunMemory from '~/components/pipe-run-with-memory'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | export const meta: MetaFunction = () => { 6 | return [ 7 | { title: 'AI Agent with Memory ⌘' }, 8 | { name: "description", content: "Run an AI agent with memory" }, 9 | ]; 10 | }; 11 | export default function Page() { 12 | return ( 13 |
14 | 15 | 16 |

17 | AI Agent Pipes: Memory 18 |

19 |

20 | Run a pipe with memory. 21 |

22 | 23 |
24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/app/not-found.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { Button } from '@/components/Button'; 4 | import { HeroPattern } from '@/components/HeroPattern'; 5 | import { useRouter } from 'next/navigation'; 6 | 7 | export default function NotFound() { 8 | const router = useRouter(); 9 | 10 | return ( 11 |
12 | 13 |
14 |

404

15 |

Page not found

16 |

Sorry, we couldn’t find the page you’re looking for.

17 | 24 |
25 |
26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconExperiments.tsx: -------------------------------------------------------------------------------- 1 | export function IconExperiments(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/ui/iconists/icon-chat.tsx: -------------------------------------------------------------------------------- 1 | export function IconChat(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /packages/baseai/types/config.ts: -------------------------------------------------------------------------------- 1 | // Define the specific log categories as a type 2 | export type LogCategories = 3 | | 'pipe' 4 | | 'pipe.completion' 5 | | 'pipe.request' 6 | | 'pipe.response' 7 | | 'tool' 8 | | 'tool.calls' 9 | | 'memory' 10 | | 'memory.similarChunks' 11 | | 'memory.augmentedContext'; 12 | 13 | // Define a recursive type for nested categories 14 | type NestedCategories = { 15 | [key in LogCategories]?: boolean | NestedCategories; 16 | }; 17 | 18 | // Logger config 19 | export type LoggerConfig = { 20 | isEnabled: boolean; 21 | logSensitiveData: boolean; 22 | } & NestedCategories; 23 | 24 | export interface MemoryConfig { 25 | useLocalEmbeddings: boolean; 26 | } 27 | 28 | export interface BaseAIConfig { 29 | log: LoggerConfig; 30 | memory: MemoryConfig; 31 | envFilePath: string; 32 | } 33 | -------------------------------------------------------------------------------- /packages/core/types/config.ts: -------------------------------------------------------------------------------- 1 | // Define the specific log categories as a type 2 | export type LogCategories = 3 | | 'pipe' 4 | | 'pipe.completion' 5 | | 'pipe.request' 6 | | 'pipe.response' 7 | | 'tool' 8 | | 'tool.calls' 9 | | 'memory' 10 | | 'memory.similarChunks' 11 | | 'memory.augmentedContext'; 12 | 13 | // Define a recursive type for nested categories 14 | type NestedCategories = { 15 | [key in LogCategories]?: boolean | NestedCategories; 16 | }; 17 | 18 | // Logger config 19 | export type LoggerConfig = { 20 | isEnabled: boolean; 21 | logSensitiveData: boolean; 22 | } & NestedCategories; 23 | 24 | export interface BaseAIConfig { 25 | log: LoggerConfig; 26 | memory: { 27 | useLocalEmbeddings: boolean; 28 | }; 29 | envFilePath: string; 30 | // Other configuration options can be added here 31 | } 32 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/scripts/set-runtime.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | function getPath(type) { 4 | return [ 5 | `${process.cwd()}/src/app/${type}/[section]/page.tsx`, 6 | `${process.cwd()}/src/app/${type}/[section]/[slug]/page.tsx` 7 | ]; 8 | } 9 | 10 | async function main() { 11 | const runTime = `export const runtime = 'edge';\n\n`; 12 | 13 | getPath('docs').forEach(async path => { 14 | const file = fs.readFileSync(path, 'utf-8'); 15 | 16 | if (!file.includes(runTime)) { 17 | await fs.promises.writeFile(path, runTime.concat(file)); 18 | } 19 | }); 20 | 21 | getPath('learn').forEach(async path => { 22 | const file = fs.readFileSync(path, 'utf-8'); 23 | if (!file.includes(runTime)) { 24 | await fs.promises.writeFile(path, runTime.concat(file)); 25 | } 26 | }); 27 | } 28 | 29 | main(); 30 | -------------------------------------------------------------------------------- /examples/astro/.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | -------------------------------------------------------------------------------- /examples/astro/baseai/tools/calculator.ts: -------------------------------------------------------------------------------- 1 | import * as math from 'mathjs'; 2 | 3 | export async function calculator({expression}: {expression: string}) { 4 | return math.evaluate(expression); 5 | } 6 | 7 | const toolCalculator = () => ({ 8 | run: calculator, 9 | type: 'function' as const, 10 | function: { 11 | name: 'calculator', 12 | description: 13 | `A tool that can evaluate mathematical expressions. ` + 14 | `Example expressions: ` + 15 | `'5.6 * (5 + 10.5)', '7.86 cm to inch', 'cos(80 deg) ^ 4'.`, 16 | parameters: { 17 | type: 'object', 18 | required: ['expression'], 19 | properties: { 20 | expression: { 21 | type: 'string', 22 | description: 'The mathematical expression to evaluate.', 23 | }, 24 | }, 25 | }, 26 | }, 27 | }); 28 | 29 | export default toolCalculator; 30 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/tools/calculator.ts: -------------------------------------------------------------------------------- 1 | import * as math from 'mathjs'; 2 | 3 | export async function calculator({expression}: {expression: string}) { 4 | return math.evaluate(expression); 5 | } 6 | 7 | const toolCalculator = () => ({ 8 | run: calculator, 9 | type: 'function' as const, 10 | function: { 11 | name: 'calculator', 12 | description: 13 | `A tool that can evaluate mathematical expressions. ` + 14 | `Example expressions: ` + 15 | `'5.6 * (5 + 10.5)', '7.86 cm to inch', 'cos(80 deg) ^ 4'.`, 16 | parameters: { 17 | type: 'object', 18 | required: ['expression'], 19 | properties: { 20 | expression: { 21 | type: 'string', 22 | description: 'The mathematical expression to evaluate.', 23 | }, 24 | }, 25 | }, 26 | }, 27 | }); 28 | 29 | export default toolCalculator; 30 | -------------------------------------------------------------------------------- /examples/nodejs/.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | -------------------------------------------------------------------------------- /examples/remix/.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.pipe-run.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import PipeRunExample from '~/components/pipe-run'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | 6 | export const meta: MetaFunction = () => { 7 | return [ 8 | { title: 'Pipe ⌘ ' }, 9 | { name: "description", content: "Run a pipe" }, 10 | ]; 11 | }; 12 | 13 | export default function Page() { 14 | return ( 15 |
16 | 17 | 18 |

19 | ⌘ Langbase AI Agent Pipe: Run 20 |

21 | 22 |

23 | Run a pipe to generate a text completion 24 |

25 | 26 | 27 |
28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /examples/remix/baseai/tools/calculator.ts: -------------------------------------------------------------------------------- 1 | import * as math from 'mathjs'; 2 | 3 | export async function calculator({expression}: {expression: string}) { 4 | return math.evaluate(expression); 5 | } 6 | 7 | const toolCalculator = () => ({ 8 | run: calculator, 9 | type: 'function' as const, 10 | function: { 11 | name: 'calculator', 12 | description: 13 | `A tool that can evaluate mathematical expressions. ` + 14 | `Example expressions: ` + 15 | `'5.6 * (5 + 10.5)', '7.86 cm to inch', 'cos(80 deg) ^ 4'.`, 16 | parameters: { 17 | type: 'object', 18 | required: ['expression'], 19 | properties: { 20 | expression: { 21 | type: 'string', 22 | description: 'The mathematical expression to evaluate.', 23 | }, 24 | }, 25 | }, 26 | }, 27 | }); 28 | 29 | export default toolCalculator; 30 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/app/docs/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from '@/components/content'; 2 | import { getDocsBySlug } from '@/lib/get-docs-by-slug'; 3 | import { ContentT } from '@/types/markdown'; 4 | 5 | export default async function DocPage() { 6 | let content: ContentT; 7 | 8 | if (process.env.NODE_ENV === 'production') { 9 | const data = await getDocsBySlug({ 10 | section: 'docs', 11 | slug: 'index' 12 | }); 13 | 14 | content = data.content; 15 | } else { 16 | // dynamically import the file 17 | const { getContentBySlugOnDev } = await import('@/lib/get-content-by-slug-on-dev'); 18 | 19 | const data = await getContentBySlugOnDev({ 20 | type: 'docs', 21 | slug: 'index', 22 | section: 'docs', 23 | }); 24 | 25 | content = data.content; 26 | } 27 | 28 | return ; 29 | } 30 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/OpenLink.tsx: -------------------------------------------------------------------------------- 1 | export function OpenLink(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /examples/remix/baseai/pipes/summary.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '../../../../packages/core/types/pipes'; 2 | 3 | const getPipeSummary = (): Pipe => ({ 4 | apiKey: process.env.LANGBASE_USER_API_KEY!, 5 | name: 'summary', 6 | description: 'AI Summary agent', 7 | status: 'private', 8 | model: 'openai:gpt-4o-mini', 9 | stream: true, 10 | json: false, 11 | store: true, 12 | moderate: true, 13 | top_p: 1, 14 | max_tokens: 100, 15 | temperature: 0.7, 16 | presence_penalty: 1, 17 | frequency_penalty: 1, 18 | stop: [], 19 | tool_choice: 'auto', 20 | parallel_tool_calls: false, 21 | messages: [ 22 | { 23 | role: 'system', 24 | content: `You are a helpful AI assistant. Make everything Less wordy.`, 25 | }, 26 | ], 27 | variables: [], 28 | tools: [], 29 | memory: [], 30 | }); 31 | 32 | export default getPipeSummary; 33 | -------------------------------------------------------------------------------- /packages/baseai/src/dev/providers/groq/chatComplete.ts: -------------------------------------------------------------------------------- 1 | import type { ProviderConfig } from 'types/providers'; 2 | export const GroqChatCompleteConfig: ProviderConfig = { 3 | model: { 4 | param: 'model', 5 | required: true, 6 | default: 'mixtral-8x7b-32768' 7 | }, 8 | messages: { 9 | param: 'messages', 10 | default: '' 11 | }, 12 | max_tokens: { 13 | param: 'max_tokens', 14 | default: 100, 15 | min: 0 16 | }, 17 | temperature: { 18 | param: 'temperature', 19 | default: 1, 20 | min: 0, 21 | max: 2 22 | }, 23 | top_p: { 24 | param: 'top_p', 25 | default: 1, 26 | min: 0, 27 | max: 1 28 | }, 29 | stream: { 30 | param: 'stream', 31 | default: false 32 | }, 33 | stop: { 34 | param: 'stop' 35 | }, 36 | n: { 37 | param: 'n', 38 | default: 1, 39 | max: 1, 40 | min: 1 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /.github/.roadmap/playwright.yml: -------------------------------------------------------------------------------- 1 | name: Playwright Tests 2 | on: 3 | push: 4 | branches: [ main, master ] 5 | pull_request: 6 | branches: [ main, master ] 7 | jobs: 8 | test: 9 | timeout-minutes: 60 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - uses: actions/setup-node@v4 14 | with: 15 | node-version: lts/* 16 | - name: Install dependencies 17 | run: npm install -g pnpm && pnpm install 18 | - name: Install Playwright Browsers 19 | run: pnpm exec playwright install --with-deps 20 | - name: Run Playwright tests 21 | run: pnpm exec playwright test 22 | - uses: actions/upload-artifact@v4 23 | if: always() 24 | with: 25 | name: playwright-report 26 | path: playwright-report/ 27 | retention-days: 30 28 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/app/learn/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from '@/components/content'; 2 | import { getLearnBySlug } from '@/lib/get-learn-by-slug'; 3 | import { ContentT } from '@/types/markdown'; 4 | 5 | export default async function LearnPage() { 6 | let content: ContentT; 7 | 8 | if (process.env.NODE_ENV === 'production') { 9 | const data = await getLearnBySlug({ 10 | slug: 'index', 11 | section: 'learn', 12 | }); 13 | 14 | content = data.content; 15 | } else { 16 | // dynamically import the file 17 | const { getContentBySlugOnDev } = await import('@/lib/get-content-by-slug-on-dev'); 18 | 19 | const data = await getContentBySlugOnDev({ 20 | section: 'learn', 21 | slug: 'index', 22 | type: 'learn' 23 | }); 24 | 25 | content = data.content; 26 | } 27 | 28 | return ; 29 | } 30 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/icon-up.tsx: -------------------------------------------------------------------------------- 1 | export function IconUp(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 17 | 18 | ); 19 | } 20 | 21 | export { IconUp as ChevronUpIcon }; 22 | -------------------------------------------------------------------------------- /examples/nextjs/.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | XAI_API_KEY= 23 | -------------------------------------------------------------------------------- /examples/agents/it-systems-triage-agent/.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/icon-down.tsx: -------------------------------------------------------------------------------- 1 | export function IconDown(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 17 | 18 | ); 19 | } 20 | 21 | export { IconDown as ChevronDownIcon }; 22 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.tool-calling.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import PipeRunToolExample from '~/components/pipe-run-with-tool'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | export const meta: MetaFunction = () => { 6 | return [ 7 | { title: 'AI Agent Pipe Tool ⌘' }, 8 | { name: "description", content: "Run an AI agent with a tool" }, 9 | ]; 10 | }; 11 | 12 | 13 | export default function Page() { 14 | return ( 15 |
16 | 17 | 18 |

19 | AI Agent Pipes: Tool Calling 20 |

21 |

22 | Run a pipe with tool calling. 23 |

24 | 25 |
26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/.env.baseai.example: -------------------------------------------------------------------------------- 1 | # !! SERVER SIDE ONLY !! 2 | # Keep all your API keys secret — use only on the server side. 3 | 4 | # TODO: ADD: Both in your production and local env files. 5 | # Langbase API key for your User or Org account. 6 | # How to get this API key https://langbase.com/docs/api-reference/api-keys 7 | LANGBASE_API_KEY= 8 | 9 | # TODO: ADD: LOCAL ONLY. Add only to local env files. 10 | # Following keys are needed for local pipe runs. For providers you are using. 11 | # For Langbase, please add the key to your LLM keysets. 12 | # Read more: Langbase LLM Keysets https://langbase.com/docs/features/keysets 13 | OPENAI_API_KEY= 14 | ANTHROPIC_API_KEY= 15 | COHERE_API_KEY= 16 | FIREWORKS_API_KEY= 17 | GOOGLE_API_KEY= 18 | GROQ_API_KEY= 19 | MISTRAL_API_KEY= 20 | PERPLEXITY_API_KEY= 21 | TOGETHER_API_KEY= 22 | XAI_API_KEY= 23 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/copy-project-files.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | import path from 'path'; 3 | import {execAsync} from './exec-sync'; 4 | import {handleError} from './handle-error'; 5 | 6 | export async function copyProjectFiles({dirName}: {dirName: string}) { 7 | const spinner = p.spinner(); 8 | spinner.start('Copying project files...'); 9 | 10 | const source = process.cwd(); 11 | const destination = path.join( 12 | dirName, 13 | 'baseai', 14 | 'memory', 15 | 'code-files', 16 | 'documents', 17 | ); 18 | 19 | try { 20 | await execAsync(`rm -rf ${destination}`); 21 | await execAsync(`mkdir -p ${destination}`); 22 | await execAsync(`cp -rp ${source}/* ${destination}`); 23 | spinner.stop('Project files copied successfully.'); 24 | } catch (error) { 25 | handleError({spinner, error}); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/ui/icons/info-circle.tsx: -------------------------------------------------------------------------------- 1 | export function IconInfoCircle(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 17 | 18 | ) 19 | } 20 | -------------------------------------------------------------------------------- /examples/astro/baseai/pipes/summary.ts: -------------------------------------------------------------------------------- 1 | import type {PipeI} from '@baseai/core'; 2 | 3 | const pipeSummary = (): PipeI => ({ 4 | // Replace with your API key https://langbase.com/docs/api-reference/api-keys 5 | apiKey: process.env.LANGBASE_API_KEY!, 6 | name: 'summary', 7 | description: '', 8 | status: 'private', 9 | model: 'openai:gpt-4o-mini', 10 | stream: true, 11 | json: false, 12 | store: true, 13 | moderate: true, 14 | top_p: 1, 15 | max_tokens: 1000, 16 | temperature: 0.7, 17 | presence_penalty: 1, 18 | frequency_penalty: 1, 19 | stop: [], 20 | tool_choice: 'auto', 21 | parallel_tool_calls: false, 22 | messages: [ 23 | { 24 | role: 'system', 25 | content: `You are a helpful AI assistant. Make everything Less wordy.`, 26 | }, 27 | ], 28 | variables: [], 29 | memory: [], 30 | tools: [], 31 | }); 32 | 33 | export default pipeSummary; 34 | -------------------------------------------------------------------------------- /examples/nextjs/app/api/langbase/pipes/run/route.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import {NextRequest} from 'next/server'; 3 | import pipeSummary from '../../../../../baseai/pipes/summary'; 4 | 5 | export async function POST(req: NextRequest) { 6 | const runOptions = await req.json(); 7 | 8 | // 1. Initiate the Pipe. 9 | const pipe = new Pipe(pipeSummary()); 10 | 11 | // 2. Run the pipe 12 | try { 13 | const result = await pipe.run(runOptions); 14 | 15 | // 3. Return the response stringified. 16 | return new Response(JSON.stringify(result)); 17 | } catch (error: any) { 18 | // 4. Return the error response 19 | 20 | return new Response( 21 | JSON.stringify({ 22 | error, 23 | }), 24 | { 25 | status: error.status || 500, 26 | headers: { 27 | 'Content-Type': 'application/json', 28 | }, 29 | }, 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/Property.tsx: -------------------------------------------------------------------------------- 1 | export function Property({ 2 | name, 3 | children, 4 | type 5 | }: { 6 | name: string; 7 | children: React.ReactNode; 8 | type?: string; 9 | }) { 10 | return ( 11 |
  • 12 |
    13 |
    Name
    14 |
    15 | {name} 16 |
    17 | {type && ( 18 | <> 19 |
    Type
    20 |
    21 | {type} 22 |
    23 | 24 | )} 25 |
    Description
    26 |
    27 | {children} 28 |
    29 |
    30 |
  • 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/mdx/sub-property.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Accordion, 3 | AccordionContent, 4 | AccordionItem, 5 | AccordionTrigger 6 | } from '@/components/ui/accordion'; 7 | import { Property } from './Property'; 8 | 9 | export function Sub({ 10 | name, 11 | type, 12 | children 13 | }: { 14 | name: string; 15 | type: string; 16 | children: React.ReactNode; 17 | }) { 18 | return ( 19 | 24 | 25 | {name} 26 | 27 | 28 | {children} 29 | 30 | 31 | 32 | 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/tools/pipe-call.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import pipeSummary from '../pipes/summary'; 3 | 4 | const runSummaryPipe = async ({prompt}: {prompt: string}) => { 5 | const pipe = new Pipe(pipeSummary()); 6 | const result = await pipe.run({ 7 | messages: [{role: 'user', content: `${prompt} — please max one line`}], 8 | }); 9 | 10 | return result.completion; 11 | }; 12 | 13 | const toolPipeCall = () => ({ 14 | run: runSummaryPipe, 15 | type: 'function', 16 | function: { 17 | name: 'runSummaryPipe', 18 | description: `Call a pipe that can summarize text.`, 19 | parameters: { 20 | type: 'object', 21 | required: ['prompt'], 22 | properties: { 23 | prompt: { 24 | type: 'string', 25 | description: 'User input to summarize', 26 | }, 27 | }, 28 | }, 29 | }, 30 | }); 31 | 32 | export default toolPipeCall; 33 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.pipe-run-stream.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import PipeStreamExample from '~/components/pipe-stream'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | export const meta: MetaFunction = () => { 6 | return [ 7 | { title: 'AI Agent Pipe Stream ⌘' }, 8 | { name: "description", content: "AI Agent pipe to stream a text completion" }, 9 | ]; 10 | }; 11 | 12 | 13 | export default function Page() { 14 | return ( 15 |
    16 | 17 | 18 |

    19 | ⌘ Langbase AI Agent Pipe: Stream 20 |

    21 |

    22 | Stream a pipe to stream a text completion 23 |

    24 | 25 |
    26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /examples/astro/baseai/tools/pipe-call.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import getPipeSummary from '../pipes/summary'; 3 | 4 | const runSummaryPipe = async ({prompt}: {prompt: string}) => { 5 | const pipe = new Pipe(getPipeSummary()); 6 | const result = await pipe.run({ 7 | messages: [{role: 'user', content: `${prompt} — please max one line`}], 8 | }); 9 | 10 | return result.completion; 11 | }; 12 | 13 | const toolPipeCall = () => ({ 14 | run: runSummaryPipe, 15 | type: 'function', 16 | function: { 17 | name: 'runSummaryPipe', 18 | description: `Call a pipe that can summarize text.`, 19 | parameters: { 20 | type: 'object', 21 | required: ['prompt'], 22 | properties: { 23 | prompt: { 24 | type: 'string', 25 | description: 'User input to summarize', 26 | }, 27 | }, 28 | }, 29 | }, 30 | }); 31 | 32 | export default toolPipeCall; 33 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.chat-advanced.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import ChatAdvanced from '~/components/chat-advanced'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | export const meta: MetaFunction = () => { 6 | return [ 7 | { title: 'Advanced Chat Pipe ⌘' }, 8 | { name: "description", content: "A kitchen sink example with all `usePipe()` chat features" }, 9 | ]; 10 | }; 11 | 12 | export default function Page() { 13 | return ( 14 |
    15 | 16 | 17 |

    18 | `usePipe()`: Chat Advanced 19 |

    20 |

    21 | A kitchen sink example with all `usePipe()` chat features 22 |

    23 | 24 |
    25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /examples/remix/baseai/tools/pipe-call.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import getPipeSummary from '../pipes/summary'; 3 | 4 | const runSummaryPipe = async ({prompt}: {prompt: string}) => { 5 | const pipe = new Pipe(getPipeSummary()); 6 | const result = await pipe.run({ 7 | messages: [{role: 'user', content: `${prompt} — please max one line`}], 8 | }); 9 | 10 | return result.completion; 11 | }; 12 | 13 | const toolPipeCall = () => ({ 14 | run: runSummaryPipe, 15 | type: 'function', 16 | function: { 17 | name: 'runSummaryPipe', 18 | description: `Call a pipe that can summarize text.`, 19 | parameters: { 20 | type: 'object', 21 | required: ['prompt'], 22 | properties: { 23 | prompt: { 24 | type: 'string', 25 | description: 'User input to summarize', 26 | }, 27 | }, 28 | }, 29 | }, 30 | }); 31 | 32 | export default toolPipeCall; 33 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/HeroPattern.tsx: -------------------------------------------------------------------------------- 1 | export function HeroPattern() { 2 | return ( 3 |
    4 |
    5 |
    6 | 13 |
    14 |
    15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /examples/nextjs/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import {cn} from '@/lib/utils'; 4 | 5 | export interface InputProps extends React.InputHTMLAttributes {} 6 | 7 | const Input = React.forwardRef(({className, type, ...props}, ref) => { 8 | return ( 9 | 18 | ); 19 | }); 20 | Input.displayName = 'Input'; 21 | 22 | export {Input}; 23 | -------------------------------------------------------------------------------- /examples/remix/app/routes/demo.pipe-run-pipes-as-tools.tsx: -------------------------------------------------------------------------------- 1 | import { MetaFunction } from '@remix-run/node'; 2 | import PipeRunPipesAsTools from '~/components/pipe-run-pipes-as-tools'; 3 | import GoHome from '~/components/ui/go-home'; 4 | 5 | export const meta: MetaFunction = () => { 6 | return [ 7 | { title: 'AI Agent with Pipes as Tools ⌘' }, 8 | { name: "description", content: "Run an AI agent with pipes as tools" }, 9 | ]; 10 | }; 11 | 12 | export default function Page() { 13 | return ( 14 |
    15 | 16 | 17 |

    18 | ⌘ Langbase: Composable Pipe Run 19 |

    20 |

    21 | Run a pipe that can call another pipe. 22 |

    23 | 24 |
    25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /examples/remix/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "**/*.ts", 4 | "**/*.tsx", 5 | "**/.server/**/*.ts", 6 | "**/.server/**/*.tsx", 7 | "**/.client/**/*.ts", 8 | "**/.client/**/*.tsx" 9 | ], 10 | "compilerOptions": { 11 | "lib": ["DOM", "DOM.Iterable", "ES2022"], 12 | "types": ["@remix-run/node", "vite/client"], 13 | "isolatedModules": true, 14 | "esModuleInterop": true, 15 | "jsx": "react-jsx", 16 | "module": "ESNext", 17 | "moduleResolution": "Bundler", 18 | "resolveJsonModule": true, 19 | "target": "ES2022", 20 | "strict": true, 21 | "allowJs": true, 22 | "skipLibCheck": true, 23 | "forceConsistentCasingInFileNames": true, 24 | "baseUrl": ".", 25 | "paths": { 26 | "~/*": ["./app/*"] 27 | }, 28 | 29 | // Vite takes care of building everything, not tsc. 30 | "noEmit": true 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/baseai/src/utils/logger-utils.ts: -------------------------------------------------------------------------------- 1 | import * as p from '@clack/prompts'; 2 | import type { LogCategories } from 'types/config'; 3 | import Logger from './logger'; 4 | 5 | let loggerInstance: Logger | null = null; 6 | let initializationPromise: Promise | null = null; 7 | 8 | export const initLogger = async (): Promise => { 9 | if (!initializationPromise) { 10 | initializationPromise = Logger.initialize(); 11 | } 12 | loggerInstance = await initializationPromise; 13 | }; 14 | 15 | const getLogger = (): Logger => { 16 | if (!loggerInstance) { 17 | p.cancel('Logger has not been initialized. Call initLogger() first.'); 18 | process.exit(1); 19 | } 20 | return loggerInstance; 21 | }; 22 | 23 | export const logger = ( 24 | category: LogCategories, 25 | value?: unknown, 26 | logHeader?: string 27 | ) => { 28 | getLogger().log(category, value, logHeader); 29 | }; 30 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/pipes/pipe-with-tool.ts: -------------------------------------------------------------------------------- 1 | import {PipeI} from '@baseai/core'; 2 | import toolCalculator from '../tools/calculator'; 3 | import toolGetWeather from '../tools/weather'; 4 | 5 | const pipeWithTools = (): PipeI => ({ 6 | apiKey: process.env.LANGBASE_API_KEY!, 7 | name: 'pipe-with-tool', 8 | description: 'An AI agent pipe that can call tools', 9 | status: 'public', 10 | model: 'openai:gpt-4o-mini', 11 | stream: false, 12 | json: false, 13 | store: true, 14 | moderate: true, 15 | top_p: 1, 16 | max_tokens: 1000, 17 | temperature: 0.7, 18 | presence_penalty: 1, 19 | frequency_penalty: 1, 20 | stop: [], 21 | tool_choice: 'auto', 22 | parallel_tool_calls: true, 23 | messages: [{role: 'system', content: `You are a helpful AI assistant.`}], 24 | variables: [], 25 | memory: [], 26 | tools: [toolGetWeather(), toolCalculator()], 27 | }); 28 | export default pipeWithTools; 29 | -------------------------------------------------------------------------------- /examples/remix/app/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { cn } from '~/lib/utils'; 4 | 5 | export interface InputProps extends React.InputHTMLAttributes { } 6 | 7 | const Input = React.forwardRef(({ className, type, ...props }, ref) => { 8 | return ( 9 | 18 | ); 19 | }); 20 | Input.displayName = 'Input'; 21 | 22 | export { Input }; 23 | -------------------------------------------------------------------------------- /examples/agents/readme-writer-agent/utils/start-baseai-server.ts: -------------------------------------------------------------------------------- 1 | import {exec, spawn} from 'child_process'; 2 | import * as p from '@clack/prompts'; 3 | 4 | export async function startBaseAIDevServer() { 5 | const spinner = p.spinner(); 6 | spinner.start('Starting AI server...'); 7 | // Spawn the server process detached from the parent 8 | const serverProcess = spawn('npx', ['baseai', 'dev'], { 9 | // Detach the process so it runs independently 10 | detached: true, 11 | // Pipe stdout/stderr to files or ignore them 12 | stdio: 'ignore', 13 | shell: process.platform === 'win32', 14 | }); 15 | 16 | // Unref the process so it won't keep the parent alive 17 | serverProcess.unref(); 18 | 19 | // Wait a bit for the server to start 20 | return new Promise(resolve => { 21 | setTimeout(() => { 22 | spinner.stop('AI server started.'); 23 | resolve(true); 24 | }, 2000); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /examples/astro/baseai/pipes/pipe-with-tool.ts: -------------------------------------------------------------------------------- 1 | import type {PipeI} from '@baseai/core'; 2 | import toolCalculator from '../tools/calculator'; 3 | import toolGetWeather from '../tools/weather'; 4 | 5 | const getPipeWithTool = (): PipeI => ({ 6 | apiKey: process.env.LANGBASE_API_KEY!, 7 | name: 'pipe-with-tool', 8 | description: 'An AI agent pipe that can call tools', 9 | status: 'public', 10 | model: 'openai:gpt-4o-mini', 11 | stream: true, 12 | json: false, 13 | store: true, 14 | moderate: true, 15 | top_p: 1, 16 | max_tokens: 1000, 17 | temperature: 0.7, 18 | presence_penalty: 1, 19 | frequency_penalty: 1, 20 | stop: [], 21 | tool_choice: 'auto', 22 | parallel_tool_calls: true, 23 | messages: [{role: 'system', content: `You are a helpful AI assistant.`}], 24 | variables: [], 25 | memory: [], 26 | tools: [toolGetWeather(), toolCalculator()], 27 | }); 28 | export default getPipeWithTool; 29 | -------------------------------------------------------------------------------- /examples/nodejs/examples/pipe.stream.text.ts: -------------------------------------------------------------------------------- 1 | import 'dotenv/config'; 2 | import {getRunner, Pipe} from '@baseai/core'; 3 | import pipeSummary from '../baseai/pipes/summary'; 4 | 5 | const pipe = new Pipe(pipeSummary()); 6 | 7 | async function main() { 8 | const {stream, threadId, rawResponse} = await pipe.run({ 9 | messages: [{role: 'user', content: 'Hello'}], 10 | stream: true, 11 | }); 12 | 13 | // Convert the stream to a stream runner. 14 | const runner = getRunner(stream); 15 | 16 | // Method 1: Using event listeners 17 | runner.on('connect', () => { 18 | console.log('Stream started.\n'); 19 | }); 20 | 21 | runner.on('content', content => { 22 | process.stdout.write(content); 23 | }); 24 | 25 | runner.on('end', () => { 26 | console.log('\nStream ended.'); 27 | }); 28 | 29 | runner.on('error', error => { 30 | console.error('Error:', error); 31 | }); 32 | } 33 | 34 | main(); 35 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/UsersIcon.tsx: -------------------------------------------------------------------------------- 1 | export function UsersIcon(props: React.ComponentPropsWithoutRef<'svg'>) { 2 | return ( 3 | 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/pipes/pipe-with-tool-stream.ts: -------------------------------------------------------------------------------- 1 | import {PipeI} from '@baseai/core'; 2 | import toolCalculator from '../tools/calculator'; 3 | import toolGetWeather from '../tools/weather'; 4 | 5 | const pipeWithToolsStream = (): PipeI => ({ 6 | apiKey: process.env.LANGBASE_API_KEY!, 7 | name: 'pipe-with-tool', 8 | description: 'An AI agent pipe that can call tools', 9 | status: 'public', 10 | model: 'openai:gpt-4o-mini', 11 | stream: true, 12 | json: false, 13 | store: true, 14 | moderate: true, 15 | top_p: 1, 16 | max_tokens: 1000, 17 | temperature: 0.7, 18 | presence_penalty: 1, 19 | frequency_penalty: 1, 20 | stop: [], 21 | tool_choice: 'auto', 22 | parallel_tool_calls: true, 23 | messages: [{role: 'system', content: `You are a helpful AI assistant.`}], 24 | variables: [], 25 | memory: [], 26 | tools: [toolGetWeather(), toolCalculator()], 27 | }); 28 | export default pipeWithToolsStream; 29 | -------------------------------------------------------------------------------- /examples/nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-nodejs", 3 | "private": true, 4 | "version": "0.0.0", 5 | "description": "Nodejs example on how to use BaseAI", 6 | "type": "module", 7 | "main": "index.js", 8 | "scripts": { 9 | "baseai": "baseai", 10 | "pipe.run": "npx tsx ./examples/pipe.run.ts", 11 | "pipe.run.stream": "npx tsx ./examples/pipe.run.stream.ts", 12 | "pipe.run.stream.loop": "npx tsx ./examples/pipe.run.stream.loop.ts", 13 | "pipe.generate.text": "npx tsx ./examples/pipe.generate.text.ts", 14 | "pipe.stream.text": "npx tsx ./examples/pipe.stream.text.ts" 15 | }, 16 | "keywords": [], 17 | "author": "Ahmad Awais (https://twitter.com/MrAhmadAwais)", 18 | "license": "UNLICENSED", 19 | "dependencies": { 20 | "@baseai/core": "^0.9.43", 21 | "dotenv": "^16.4.5" 22 | }, 23 | "devDependencies": { 24 | "baseai": "^0.9.44", 25 | "tsx": "^4.19.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tools/eslint-config/react-internal.js: -------------------------------------------------------------------------------- 1 | const {resolve} = require('node:path'); 2 | 3 | const project = resolve(process.cwd(), 'tsconfig.json'); 4 | 5 | /* 6 | * This is a custom ESLint configuration for use with 7 | * internal (bundled by their consumer) libraries 8 | * that utilize React. 9 | */ 10 | 11 | /** @type {import("eslint").Linter.Config} */ 12 | module.exports = { 13 | extends: ['eslint:recommended', 'prettier', 'turbo'], 14 | plugins: ['only-warn'], 15 | globals: { 16 | React: true, 17 | JSX: true, 18 | }, 19 | env: { 20 | browser: true, 21 | }, 22 | settings: { 23 | 'import/resolver': { 24 | typescript: { 25 | project, 26 | }, 27 | }, 28 | }, 29 | ignorePatterns: [ 30 | // Ignore dotfiles 31 | '.*.js', 32 | 'node_modules/', 33 | 'dist/', 34 | ], 35 | overrides: [ 36 | // Force ESLint to detect .tsx files 37 | {files: ['*.js?(x)', '*.ts?(x)']}, 38 | ], 39 | }; 40 | -------------------------------------------------------------------------------- /examples/astro/src/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import {cn} from '../../lib/utils'; 3 | 4 | export interface InputProps 5 | extends React.InputHTMLAttributes {} 6 | 7 | const Input = React.forwardRef( 8 | ({className, type, ...props}, ref) => { 9 | return ( 10 | 19 | ); 20 | }, 21 | ); 22 | Input.displayName = 'Input'; 23 | 24 | export {Input}; 25 | -------------------------------------------------------------------------------- /examples/remix/baseai/pipes/pipe-with-tool.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '../../../../packages/core/types/pipes'; 2 | import toolCalculator from '../tools/calculator'; 3 | import toolGetWeather from '../tools/weather'; 4 | 5 | const getPipeWithTool = (): Pipe => ({ 6 | apiKey: process.env.LANGBASE_USER_API_KEY!, 7 | name: 'pipe-with-tool', 8 | description: 'An AI agent pipe that can call tools', 9 | status: 'public', 10 | model: 'openai:gpt-4o-mini', 11 | stream: true, 12 | json: false, 13 | store: true, 14 | moderate: true, 15 | top_p: 1, 16 | max_tokens: 1000, 17 | temperature: 0.7, 18 | presence_penalty: 1, 19 | frequency_penalty: 1, 20 | stop: [], 21 | tool_choice: 'auto', 22 | parallel_tool_calls: true, 23 | messages: [{role: 'system', content: `You are a helpful AI assistant.`}], 24 | variables: [], 25 | memory: [], 26 | tools: [toolGetWeather(), toolCalculator()], 27 | }); 28 | export default getPipeWithTool; 29 | -------------------------------------------------------------------------------- /apps/baseai.dev/src/components/icons/IconFork.tsx: -------------------------------------------------------------------------------- 1 | export function IconFork(props: JSX.IntrinsicElements['svg']) { 2 | return ( 3 | 11 | 15 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/astro/baseai/tools/pipe-call-maths.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import getPipeWithTool from '../pipes/pipe-with-tool'; 3 | 4 | const runPipeWithMaths = async ({prompt}: {prompt: string}) => { 5 | const pipe = new Pipe(getPipeWithTool()); 6 | const result = await pipe.run({ 7 | messages: [{role: 'user', content: prompt}], 8 | }); 9 | 10 | return result.completion; 11 | }; 12 | 13 | const toolPipeCallMaths = () => ({ 14 | run: runPipeWithMaths, 15 | type: 'function', 16 | function: { 17 | name: 'runPipeWithMaths', 18 | description: `Call a pipe that can do maths and tell weather from different tools.`, 19 | parameters: { 20 | type: 'object', 21 | required: ['prompt'], 22 | properties: { 23 | prompt: { 24 | type: 'string', 25 | description: 'User input to do maths or to get weather.', 26 | }, 27 | }, 28 | }, 29 | }, 30 | }); 31 | 32 | export default toolPipeCallMaths; 33 | -------------------------------------------------------------------------------- /examples/nextjs/baseai/tools/pipe-call-maths.ts: -------------------------------------------------------------------------------- 1 | import {Pipe} from '@baseai/core'; 2 | import getPipeWithTool from '../pipes/pipe-with-tool'; 3 | 4 | const runPipeWithMaths = async ({prompt}: {prompt: string}) => { 5 | const pipe = new Pipe(getPipeWithTool()); 6 | const result = await pipe.run({ 7 | messages: [{role: 'user', content: prompt}], 8 | }); 9 | 10 | return result.completion; 11 | }; 12 | 13 | const toolPipeCallMaths = () => ({ 14 | run: runPipeWithMaths, 15 | type: 'function', 16 | function: { 17 | name: 'runPipeWithMaths', 18 | description: `Call a pipe that can do maths and tell weather from different tools.`, 19 | parameters: { 20 | type: 'object', 21 | required: ['prompt'], 22 | properties: { 23 | prompt: { 24 | type: 'string', 25 | description: 'User input to do maths or to get weather.', 26 | }, 27 | }, 28 | }, 29 | }, 30 | }); 31 | 32 | export default toolPipeCallMaths; 33 | --------------------------------------------------------------------------------