├── packages ├── eslint │ ├── .gitignore │ ├── src │ │ ├── index.ts │ │ └── common.ts │ ├── tsconfig.esm.json │ └── package.json ├── tsc │ ├── .gitignore │ └── package.json ├── tsconfig │ ├── .gitignore │ ├── cjs.json │ ├── esm.json │ ├── vue.json │ └── package.json ├── anthropic │ ├── src │ │ ├── index.ts │ │ └── AnthropicModel.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── agentscript │ ├── src │ │ ├── index.ts │ │ ├── schema.ts │ │ ├── tools.ts │ │ ├── utils.ts │ │ ├── provider.ts │ │ └── anthropic.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ └── tsconfig.tests.json ├── llamaindex │ ├── src │ │ ├── index.ts │ │ ├── fromLlamaIndexModel.test.ts │ │ └── fromLlamaIndexModel.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── tools │ ├── src │ │ ├── index.ts │ │ ├── addToDate.ts │ │ ├── types │ │ │ └── Duration.ts │ │ └── summarizeData.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── linear │ ├── src │ │ ├── index.ts │ │ ├── types │ │ │ ├── Issue.ts │ │ │ └── IssueFilter.ts │ │ ├── LinearClient.ts │ │ └── gql.gql │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ ├── eslint.config.js │ ├── tsconfig.config.json │ ├── apollo.config.cjs │ ├── graphql.config.ts │ └── package.json ├── provider │ ├── src │ │ ├── index.ts │ │ ├── LanguageModel.ts │ │ ├── normalizeModel.ts │ │ ├── normalizeModel.test.ts │ │ ├── VercelModel.test.ts │ │ ├── LangChainModel.test.ts │ │ └── VercelModel.ts │ ├── vitest.config.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── utils │ ├── src │ │ ├── index.ts │ │ ├── getCurrentDatePrompt.ts │ │ ├── joinLines.ts │ │ └── normalizeText.ts │ ├── vitest.config.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── openapi │ ├── src │ │ ├── index.ts │ │ ├── utils │ │ │ ├── isReferenceObject.ts │ │ │ └── resolveReferenceObject.ts │ │ ├── parseOpenApiDoc.ts │ │ └── toolsFromOpenApi.test.ts │ ├── vitest.config.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.tests.json │ ├── tsconfig.esm.json │ └── package.json ├── serializer │ ├── src │ │ ├── index.ts │ │ ├── heapTypes.ts │ │ ├── heap.test.ts │ │ └── createDeserializer.ts │ ├── vitest.config.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── parser │ ├── src │ │ ├── index.ts │ │ ├── ParseError.ts │ │ ├── parseCodeResponse.ts │ │ ├── parseScript.regexes.test.ts │ │ └── parseCodeResponse.test.ts │ ├── vitest.config.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ └── package.json ├── core │ ├── vitest.config.ts │ ├── tests │ │ ├── smoke.test.cjs │ │ └── smoke.test.mjs │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ ├── eslint.config.js │ ├── src │ │ ├── tools │ │ │ ├── defineToolModule.ts │ │ │ ├── toolResult.ts │ │ │ └── filterTools.ts │ │ ├── runtime │ │ │ ├── RuntimeError.ts │ │ │ ├── utils │ │ │ │ ├── getChild.ts │ │ │ │ └── findFrameByTrace.ts │ │ │ ├── tests │ │ │ │ ├── toolsState.test.ts │ │ │ │ └── testUtils.ts │ │ │ └── runtimeController.ts │ │ ├── agent │ │ │ ├── rechainAgent.ts │ │ │ ├── createAgent.test.ts │ │ │ ├── createAgent.ts │ │ │ ├── inferAgent.ts │ │ │ ├── createAgentInternal.ts │ │ │ └── defineAgent.ts │ │ ├── meta │ │ │ ├── defaultMetadata.ts │ │ │ ├── defineMetadata.ts │ │ │ └── defineMetadata.test.ts │ │ ├── modules │ │ │ ├── renderComment.ts │ │ │ ├── renderDocDirective.ts │ │ │ ├── renderComment.test.ts │ │ │ ├── renderRuntime.ts │ │ │ ├── renderModule.ts │ │ │ ├── renderVariable.ts │ │ │ └── renderTool.ts │ │ ├── index.ts │ │ └── inferResult.ts │ └── package.json └── schema │ ├── tests │ ├── smoke.test.cjs │ └── smoke.test.mjs │ ├── eslint.config.js │ ├── tsconfig.esm.json │ ├── tsconfig.tests.json │ ├── src │ └── index.ts │ └── package.json ├── .npmignore ├── legacy ├── agent │ ├── src │ │ ├── index.ts │ │ ├── utils │ │ │ ├── defineSystemPrompt.ts │ │ │ ├── defineGraphNode.ts │ │ │ └── convertEventToPrompt.ts │ │ ├── LangModelProvider.ts │ │ ├── AgentStateStore.ts │ │ └── SlackBot.ts │ ├── README.md │ ├── .eslintrc.cjs │ ├── tsconfig.json │ └── package.json ├── linear │ ├── .eslintignore │ ├── src │ │ ├── index.ts │ │ └── LinearClient.ts │ ├── .eslintrc.cjs │ ├── tsconfig.json │ └── package.json ├── slack │ ├── .eslintignore │ ├── src │ │ ├── index.ts │ │ ├── SlackReceiver.ts │ │ ├── SlackClient.ts │ │ ├── SlackUsers.ts │ │ └── utils │ │ │ └── stringifyMessage.ts │ ├── .eslintrc.cjs │ ├── tsconfig.json │ └── package.json ├── database │ ├── src │ │ ├── schema.ts │ │ ├── index.ts │ │ ├── DatabaseClient.ts │ │ └── schema │ │ │ └── knowledge.ts │ ├── tsconfig.config.json │ ├── README.md │ ├── .eslintrc.cjs │ ├── drizzle.config.ts │ ├── tsconfig.json │ └── package.json ├── supabase │ └── .gitignore ├── cli │ ├── .eslintignore │ ├── src │ │ ├── commands │ │ │ ├── StartCommand.ts │ │ │ ├── DatabaseMigrateCommand.ts │ │ │ ├── NotionSyncCommand.ts │ │ │ └── ApplicationCommand.ts │ │ └── commands.ts │ ├── .eslintrc.cjs │ ├── tsconfig.json │ ├── bin │ │ └── cli.js │ └── package.json ├── notion │ ├── src │ │ ├── index.ts │ │ ├── NotionClient.ts │ │ └── SyncNotionPage.ts │ ├── README.md │ ├── .eslintrc.cjs │ ├── tsconfig.json │ └── package.json ├── rag │ ├── src │ │ ├── index.ts │ │ ├── EmbeddingModel.ts │ │ ├── KnowledgeRetriever.ts │ │ └── tools │ │ │ └── SearchKnowledgeTool.ts │ ├── README.md │ ├── .eslintrc.cjs │ ├── tsconfig.json │ └── package.json ├── core │ ├── src │ │ ├── utils │ │ │ ├── randomUid.ts │ │ │ └── toolChatAction.ts │ │ ├── models │ │ │ ├── KnowledgeType.ts │ │ │ ├── AgentState.ts │ │ │ ├── ChatMessage.ts │ │ │ └── AgentEvent.ts │ │ ├── EnvVariables.ts │ │ ├── TenantContext.ts │ │ ├── index.ts │ │ ├── Logger.ts │ │ └── Chat.ts │ ├── README.md │ ├── .eslintrc.cjs │ ├── tsconfig.json │ └── package.json └── agent-local │ ├── README.md │ ├── .eslintrc.cjs │ ├── src │ ├── index.ts │ └── server.ts │ ├── tsconfig.json │ └── package.json ├── .env.example ├── .npmrc ├── .vscode ├── extensions.json └── settings.json ├── .yarnrc.yml ├── eslint.config.mjs ├── tsconfig.esm.json ├── lerna.json ├── vitest.workspace.ts ├── .yarn └── plugins │ └── plugin-node-memory.cjs ├── .prettierrc ├── .github ├── ISSUE_TEMPLATE │ ├── FEATURE.yml │ └── BUG.yml ├── dependabot.yml └── workflows │ ├── automerge-release.yml │ ├── check-commit.yml │ └── release-npm.yml ├── nx.json ├── turbo.json ├── .gitignore └── package.json /packages/eslint/.gitignore: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | -------------------------------------------------------------------------------- /packages/tsc/.gitignore: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # smoke tests mostly 2 | *.cjs 3 | *.mjs 4 | -------------------------------------------------------------------------------- /packages/tsconfig/.gitignore: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | -------------------------------------------------------------------------------- /legacy/agent/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './SlackBot.js'; 2 | -------------------------------------------------------------------------------- /legacy/linear/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .eslintrc.cjs -------------------------------------------------------------------------------- /legacy/slack/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .eslintrc.cjs -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | NPM_TOKEN=your-npm-token 2 | GH_TOKEN=your-github-token 3 | -------------------------------------------------------------------------------- /legacy/database/src/schema.ts: -------------------------------------------------------------------------------- 1 | export * from './schema/knowledge.js'; 2 | -------------------------------------------------------------------------------- /packages/anthropic/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './AnthropicModel.js'; 2 | -------------------------------------------------------------------------------- /legacy/supabase/.gitignore: -------------------------------------------------------------------------------- 1 | # Supabase 2 | .branches 3 | .temp 4 | .env 5 | -------------------------------------------------------------------------------- /packages/agentscript/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@agentscript-ai/core'; 2 | -------------------------------------------------------------------------------- /packages/agentscript/src/schema.ts: -------------------------------------------------------------------------------- 1 | export * from '@agentscript-ai/schema'; 2 | -------------------------------------------------------------------------------- /packages/agentscript/src/tools.ts: -------------------------------------------------------------------------------- 1 | export * from '@agentscript-ai/tools'; 2 | -------------------------------------------------------------------------------- /packages/agentscript/src/utils.ts: -------------------------------------------------------------------------------- 1 | export * from '@agentscript-ai/utils'; 2 | -------------------------------------------------------------------------------- /packages/llamaindex/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './fromLlamaIndexModel.js'; 2 | -------------------------------------------------------------------------------- /legacy/cli/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | bin/cli.js 4 | .eslintrc.cjs 5 | -------------------------------------------------------------------------------- /legacy/linear/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './tools/CreateLinearTaskTool.js'; 2 | -------------------------------------------------------------------------------- /packages/agentscript/src/provider.ts: -------------------------------------------------------------------------------- 1 | export * from '@agentscript-ai/provider'; 2 | -------------------------------------------------------------------------------- /packages/agentscript/src/anthropic.ts: -------------------------------------------------------------------------------- 1 | export * from '@agentscript-ai/anthropic'; 2 | -------------------------------------------------------------------------------- /packages/tools/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './addToDate.js'; 2 | export * from './summarizeData.js'; 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | @nzyme:registry=https://registry.npmjs.org/ 2 | //registry.npmjs.org/:_authToken=${NPM_TOKEN} 3 | -------------------------------------------------------------------------------- /legacy/notion/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './NotionClient.js'; 2 | export * from './SyncNotionPages.js'; 3 | -------------------------------------------------------------------------------- /legacy/database/src/index.ts: -------------------------------------------------------------------------------- 1 | export * as db from './schema.js'; 2 | 3 | export * from './DatabaseClient.js'; 4 | -------------------------------------------------------------------------------- /packages/linear/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './tools/searchIssues.js'; 2 | export * from './LinearClient.js'; 3 | -------------------------------------------------------------------------------- /packages/provider/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './LanguageModel.js'; 2 | export * from './normalizeModel.js'; 3 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"] 3 | } 4 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | checksumBehavior: update 2 | 3 | nodeLinker: node-modules 4 | 5 | yarnPath: .yarn/releases/yarn-4.7.0.cjs 6 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import { packageJson } from '@nzyme/eslint'; 2 | 3 | export default [ 4 | // 5 | ...packageJson(), 6 | ]; 7 | -------------------------------------------------------------------------------- /packages/tsconfig/cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "extends": "@nzyme/tsconfig/cjs.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/tsconfig/esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "extends": "@nzyme/tsconfig/esm.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/tsconfig/vue.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "extends": "@nzyme/tsconfig/vue.json" 4 | } 5 | -------------------------------------------------------------------------------- /packages/eslint/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './common.js'; 2 | export { imports, jsdoc, packageJson, react, typescript, vue } from '@nzyme/eslint'; 3 | -------------------------------------------------------------------------------- /packages/utils/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './getCurrentDatePrompt.js'; 2 | export * from './joinLines.js'; 3 | export * from './normalizeText.js'; 4 | -------------------------------------------------------------------------------- /packages/openapi/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './filterOpenApiDoc.js'; 2 | export * from './parseOpenApiDoc.js'; 3 | export * from './toolsFromOpenApi.js'; 4 | -------------------------------------------------------------------------------- /packages/serializer/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './createDeserializer.js'; 2 | export * from './createSerializer.js'; 3 | export * from './heapTypes.js'; 4 | -------------------------------------------------------------------------------- /tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/esm.json", 3 | "include": ["vitest.workspace.ts"], 4 | "references": [] 5 | } 6 | -------------------------------------------------------------------------------- /legacy/rag/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './KnowledgeStore.js'; 2 | export * from './KnowledgeRetriever.js'; 3 | export * from './tools/SearchKnowledgeTool.js'; 4 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.0", 3 | "license": "Elastic License 2.0 (ELv2)", 4 | "packages": ["packages/*"], 5 | "npmClient": "yarn" 6 | } 7 | -------------------------------------------------------------------------------- /legacy/core/src/utils/randomUid.ts: -------------------------------------------------------------------------------- 1 | import { randomString } from '@nzyme/crypto-utils'; 2 | 3 | export function randomUid() { 4 | return randomString(12); 5 | } 6 | -------------------------------------------------------------------------------- /packages/parser/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './astTypes.js'; 2 | export * from './parseCodeResponse.js'; 3 | export * from './parseScript.js'; 4 | export * from './ParseError.js'; 5 | -------------------------------------------------------------------------------- /packages/core/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | include: ['**/*.test.ts'], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/openapi/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | include: ['**/*.test.ts'], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/parser/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | include: ['**/*.test.ts'], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/provider/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | include: ['**/*.test.ts'], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/utils/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | include: ['**/*.test.ts'], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/serializer/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vitest/config'; 2 | 3 | export default defineConfig({ 4 | test: { 5 | include: ['**/*.test.ts'], 6 | }, 7 | }); 8 | -------------------------------------------------------------------------------- /packages/agentscript/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('agentscript-ai'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/agentscript/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from 'agentscript-ai'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/core/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/core'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/core/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/core'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/linear/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/linear'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/linear/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/linear'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/parser/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/parser'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/parser/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/parser'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/schema/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/schema'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/schema/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/schema'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/tools/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/tools'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/tools/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/tools'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/utils/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/utils'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/utils/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/utils'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/openapi/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/llamaindex'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/openapi/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/llamaindex'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/provider/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/provider'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/provider/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/provider'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/anthropic/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/anthropic'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/anthropic/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/anthropic'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/llamaindex/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const p = require('@agentscript-ai/llamaindex'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/llamaindex/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/llamaindex'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/serializer/tests/smoke.test.cjs: -------------------------------------------------------------------------------- 1 | const s = require('@agentscript-ai/serializer'); 2 | 3 | // Simple smoke test to verify the package can be required 4 | if (!s) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /packages/serializer/tests/smoke.test.mjs: -------------------------------------------------------------------------------- 1 | import * as p from '@agentscript-ai/serializer'; 2 | 3 | // Simple smoke test to verify the package can be imported 4 | if (!p) throw new Error('Package failed to load'); 5 | -------------------------------------------------------------------------------- /legacy/agent/src/utils/defineSystemPrompt.ts: -------------------------------------------------------------------------------- 1 | import { SystemMessage } from '@langchain/core/messages'; 2 | 3 | export function defineSystemPrompt(prompt: string[]) { 4 | return new SystemMessage(prompt.join('\n')); 5 | } 6 | -------------------------------------------------------------------------------- /legacy/slack/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './SlackChat.js'; 2 | export * from './SlackClient.js'; 3 | export * from './SlackReceiver.js'; 4 | export * from './SlackUsers.js'; 5 | 6 | export * from './utils/stringifyMessage.js'; 7 | -------------------------------------------------------------------------------- /legacy/cli/src/commands/StartCommand.ts: -------------------------------------------------------------------------------- 1 | import { Command } from '@oclif/core'; 2 | 3 | export class StartCommand extends Command { 4 | static override description = 'Start the development server'; 5 | 6 | async run() {} 7 | } 8 | -------------------------------------------------------------------------------- /legacy/core/src/models/KnowledgeType.ts: -------------------------------------------------------------------------------- 1 | import { defineEnum } from '@nzyme/utils'; 2 | 3 | export const KnowledgeType = defineEnum(['NOTION_PAGE', 'GOOGLE_DOCS', 'WEBSITE']); 4 | export type KnowledgeType = (typeof KnowledgeType)[number]; 5 | -------------------------------------------------------------------------------- /packages/utils/src/getCurrentDatePrompt.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get the current date prompt. 3 | * @returns The current date prompt. 4 | */ 5 | export function getCurrentDatePrompt() { 6 | return `The current date is ${new Date().toISOString()}`; 7 | } 8 | -------------------------------------------------------------------------------- /legacy/cli/src/commands/DatabaseMigrateCommand.ts: -------------------------------------------------------------------------------- 1 | import { Command } from '@oclif/core'; 2 | 3 | export class DatabaseMigrateCommand extends Command { 4 | static override description = 'Start the development server'; 5 | 6 | async run() {} 7 | } 8 | -------------------------------------------------------------------------------- /legacy/core/src/EnvVariables.ts: -------------------------------------------------------------------------------- 1 | import { defineInterface } from '@nzyme/ioc'; 2 | 3 | export type EnvVariables = Record; 4 | 5 | export const EnvVariables = defineInterface({ 6 | name: 'EnvVariables', 7 | }); 8 | -------------------------------------------------------------------------------- /packages/parser/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/schema/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/tools/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/utils/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /legacy/cli/src/commands.ts: -------------------------------------------------------------------------------- 1 | import { NotionSyncCommand } from './commands/NotionSyncCommand.js'; 2 | import { StartCommand } from './commands/StartCommand.js'; 3 | 4 | export default { 5 | start: StartCommand, 6 | 'notion:sync': NotionSyncCommand, 7 | }; 8 | -------------------------------------------------------------------------------- /legacy/database/tsconfig.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "noEmit": true, 5 | "composite": false, 6 | "types": ["@types/node"] 7 | }, 8 | "include": ["*.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/agentscript/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/anthropic/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/llamaindex/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/openapi/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/provider/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/serializer/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc(), 8 | ...packageJson(), 9 | ]; 10 | -------------------------------------------------------------------------------- /packages/core/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/core/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/eslint/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/linear/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/linear/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/openapi/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/parser/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/parser/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/schema/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/schema/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/tools/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/tools/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/utils/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/utils/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/agentscript/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/agentscript/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/anthropic/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/anthropic/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/llamaindex/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/llamaindex/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/openapi/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/provider/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/provider/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /packages/serializer/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@nzyme/tsconfig/esm.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src" 6 | }, 7 | "include": ["src"], 8 | "exclude": ["src/**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/serializer/tsconfig.tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "noEmit": true 6 | }, 7 | "include": ["./src/**/*.ts", "./vitest.config.ts"], 8 | "exclude": [] 9 | } 10 | -------------------------------------------------------------------------------- /legacy/core/src/TenantContext.ts: -------------------------------------------------------------------------------- 1 | import { defineService } from '@nzyme/ioc'; 2 | 3 | export const TenantContext = defineService({ 4 | name: 'TenantContext', 5 | setup() { 6 | return { 7 | tenantId: 123n, 8 | }; 9 | }, 10 | }); 11 | -------------------------------------------------------------------------------- /legacy/slack/src/SlackReceiver.ts: -------------------------------------------------------------------------------- 1 | import type { Receiver } from '@slack/bolt'; 2 | 3 | import { defineInterface } from '@nzyme/ioc'; 4 | 5 | export type SlackReceiver = Receiver; 6 | export const SlackReceiver = defineInterface({ 7 | name: 'SlackReceiver', 8 | }); 9 | -------------------------------------------------------------------------------- /legacy/cli/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 7 | parserOptions: { 8 | project: `${__dirname}/tsconfig.json`, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /legacy/linear/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 7 | parserOptions: { 8 | project: `${__dirname}/tsconfig.json`, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /legacy/slack/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 7 | parserOptions: { 8 | project: `${__dirname}/tsconfig.json`, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /vitest.workspace.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import { fileURLToPath } from 'url'; 3 | import { defineWorkspace } from 'vitest/config'; 4 | 5 | const dirname = path.dirname(fileURLToPath(import.meta.url)); 6 | 7 | export default defineWorkspace([path.join(dirname, 'packages/*/vitest.config.ts')]); 8 | -------------------------------------------------------------------------------- /packages/linear/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript(), 7 | ...jsdoc({ 8 | ignores: ['src/gql.ts'], 9 | }), 10 | ...packageJson(), 11 | ]; 12 | -------------------------------------------------------------------------------- /packages/linear/tsconfig.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.esm.json", 3 | "compilerOptions": { 4 | "noEmit": true, 5 | "composite": false, 6 | "types": ["@types/node"], 7 | "allowJs": true 8 | }, 9 | "include": ["*.config.ts", "*.config.cjs"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/core/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { common, jsdoc, packageJson, typescript } from '@agentscript-ai/eslint'; 2 | 3 | export default [ 4 | // 5 | ...common(), 6 | ...typescript({ 7 | project: ['./tsconfig.json', './tsconfig.tests.json'], 8 | }), 9 | ...jsdoc(), 10 | ...packageJson(), 11 | ]; 12 | -------------------------------------------------------------------------------- /.yarn/plugins/plugin-node-memory.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: `plugin-node-memory`, 3 | factory: require => ({ 4 | hooks: { 5 | setupScriptEnvironment(project, scriptEnv) { 6 | scriptEnv.NODE_OPTIONS = `--max-old-space-size=8192`; 7 | }, 8 | }, 9 | }), 10 | }; 11 | -------------------------------------------------------------------------------- /legacy/agent/README.md: -------------------------------------------------------------------------------- 1 | # @agentscript-ai/agent 2 | 3 | A Slack bot powered by LangGraph JS and ChromaDB for maintaining conversation state. 4 | 5 | ## Setup 6 | 7 | 1. Copy `.env.example` to `.env` and fill in your API keys 8 | 2. Install dependencies: 9 | ```bash 10 | yarn install 11 | ``` 12 | 13 | ## Development 14 | -------------------------------------------------------------------------------- /legacy/core/README.md: -------------------------------------------------------------------------------- 1 | # @agentscript-ai/agent 2 | 3 | A Slack bot powered by LangGraph JS and ChromaDB for maintaining conversation state. 4 | 5 | ## Setup 6 | 7 | 1. Copy `.env.example` to `.env` and fill in your API keys 8 | 2. Install dependencies: 9 | ```bash 10 | yarn install 11 | ``` 12 | 13 | ## Development 14 | -------------------------------------------------------------------------------- /legacy/notion/README.md: -------------------------------------------------------------------------------- 1 | # @agentscript-ai/agent 2 | 3 | A Slack bot powered by LangGraph JS and ChromaDB for maintaining conversation state. 4 | 5 | ## Setup 6 | 7 | 1. Copy `.env.example` to `.env` and fill in your API keys 8 | 2. Install dependencies: 9 | ```bash 10 | yarn install 11 | ``` 12 | 13 | ## Development 14 | -------------------------------------------------------------------------------- /legacy/rag/README.md: -------------------------------------------------------------------------------- 1 | # @agentscript-ai/agent 2 | 3 | A Slack bot powered by LangGraph JS and ChromaDB for maintaining conversation state. 4 | 5 | ## Setup 6 | 7 | 1. Copy `.env.example` to `.env` and fill in your API keys 8 | 2. Install dependencies: 9 | ```bash 10 | yarn install 11 | ``` 12 | 13 | ## Development 14 | -------------------------------------------------------------------------------- /legacy/agent-local/README.md: -------------------------------------------------------------------------------- 1 | # @agentscript-ai/agent 2 | 3 | A Slack bot powered by LangGraph JS and ChromaDB for maintaining conversation state. 4 | 5 | ## Setup 6 | 7 | 1. Copy `.env.example` to `.env` and fill in your API keys 8 | 2. Install dependencies: 9 | ```bash 10 | yarn install 11 | ``` 12 | 13 | ## Development 14 | -------------------------------------------------------------------------------- /legacy/database/README.md: -------------------------------------------------------------------------------- 1 | # @agentscript-ai/agent 2 | 3 | A Slack bot powered by LangGraph JS and ChromaDB for maintaining conversation state. 4 | 5 | ## Setup 6 | 7 | 1. Copy `.env.example` to `.env` and fill in your API keys 8 | 2. Install dependencies: 9 | ```bash 10 | yarn install 11 | ``` 12 | 13 | ## Development 14 | -------------------------------------------------------------------------------- /legacy/agent/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 4 | parserOptions: { 5 | project: [ 6 | `${__dirname}/tsconfig.json`, 7 | // TS config for tests 8 | `${__dirname}/tsconfig.tests.json`, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /legacy/notion/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 4 | parserOptions: { 5 | project: [ 6 | `${__dirname}/tsconfig.json`, 7 | // TS config for tests 8 | `${__dirname}/tsconfig.tests.json`, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /legacy/rag/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 4 | parserOptions: { 5 | project: [ 6 | `${__dirname}/tsconfig.json`, 7 | // TS config for configs 8 | `${__dirname}/tsconfig.config.json`, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/parser/src/ParseError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Error thrown when parsing fails. 3 | */ 4 | export class ParseError extends Error { 5 | /** 6 | * @param message - Error message. 7 | * @param options - Error options. 8 | */ 9 | constructor(message: string, options: ErrorOptions) { 10 | super(message, options); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /legacy/core/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 4 | parserOptions: { 5 | project: [ 6 | `${__dirname}/tsconfig.json`, 7 | // TS config for configs 8 | `${__dirname}/tsconfig.config.json`, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/utils/src/joinLines.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Join lines into a single string. 3 | * @param lines - Lines to join. 4 | * @returns Joined lines. 5 | */ 6 | export function joinLines(lines: string | string[] | undefined | null) { 7 | if (!lines) { 8 | return ''; 9 | } 10 | 11 | return Array.isArray(lines) ? lines.join('\n') : lines; 12 | } 13 | -------------------------------------------------------------------------------- /legacy/agent-local/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 4 | parserOptions: { 5 | project: [ 6 | `${__dirname}/tsconfig.json`, 7 | // TS config for configs 8 | `${__dirname}/tsconfig.config.json`, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /legacy/database/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [require.resolve('@agentscript-ai/eslint/typescript')], 4 | parserOptions: { 5 | project: [ 6 | `${__dirname}/tsconfig.json`, 7 | // tsconfig for config files 8 | `${__dirname}/tsconfig.config.json`, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/linear/apollo.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-require-imports */ 2 | const path = require('path'); 3 | 4 | module.exports = { 5 | client: { 6 | service: { 7 | name: 'linear', 8 | url: 'https://api.linear.app/graphql', 9 | }, 10 | includes: [path.join(__dirname, './src/**/*.gql')], 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/core/src/tools/defineToolModule.ts: -------------------------------------------------------------------------------- 1 | import type { RuntimeModule } from '../agent/defineAgent.js'; 2 | 3 | /** 4 | * Convenience function to define a tool module with proper typing. 5 | * @param tools - The tools to define. 6 | * @returns The defined tool module. 7 | */ 8 | export function defineToolModule(tools: T) { 9 | return tools; 10 | } 11 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4, 3 | "singleQuote": true, 4 | "printWidth": 100, 5 | "arrowParens": "avoid", 6 | "trailingComma": "all", 7 | "endOfLine": "lf", 8 | "singleAttributePerLine": true, 9 | "overrides": [ 10 | { 11 | "files": ["*.yml", "*.yaml"], 12 | "options": { 13 | "tabWidth": 2 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/core/src/runtime/RuntimeError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Error thrown when an error occurs during runtime. 3 | */ 4 | export class RuntimeError extends Error { 5 | /** 6 | * @param message - Error message. 7 | * @param options - Error options. 8 | */ 9 | constructor(message: string, options?: ErrorOptions) { 10 | super(message, options); 11 | this.name = 'RuntimeError'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/FEATURE.yml: -------------------------------------------------------------------------------- 1 | name: 'New Feature' 2 | description: Create a ticket for a new feature 3 | labels: ['feature'] 4 | projects: ['AgentScript-AI/3'] 5 | assignees: 6 | - kedrzu 7 | body: 8 | - type: textarea 9 | id: summary 10 | attributes: 11 | label: 'Summary' 12 | description: Provide a brief explanation of the feature 13 | validations: 14 | required: true 15 | -------------------------------------------------------------------------------- /packages/tsc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/tsc", 3 | "version": "0.0.0", 4 | "type": "module", 5 | "sideEffects": false, 6 | "author": "Michał Kędrzyński ", 7 | "private": true, 8 | "scripts": { 9 | "watch": "yarn --cwd ../.. watch" 10 | }, 11 | "devDependencies": { 12 | "eslint": "^9.24.0", 13 | "typescript": "^5.8.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /legacy/slack/src/SlackClient.ts: -------------------------------------------------------------------------------- 1 | import { WebClient } from '@slack/web-api'; 2 | 3 | import { defineService } from '@nzyme/ioc'; 4 | 5 | export type SlackClient = WebClient; 6 | export const SlackClient = defineService({ 7 | name: 'SlackClient', 8 | setup() { 9 | const token = process.env.SLACK_BOT_TOKEN; 10 | const client = new WebClient(token); 11 | 12 | return client; 13 | }, 14 | }); 15 | -------------------------------------------------------------------------------- /packages/schema/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@nzyme/zchema'; 2 | 3 | declare module '@nzyme/zchema' { 4 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 5 | interface SchemaProps { 6 | /** 7 | * The name of the type. 8 | */ 9 | name?: string; 10 | 11 | /** 12 | * A description of the property. 13 | */ 14 | description?: string | string[]; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/llamaindex/src/fromLlamaIndexModel.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import { OpenAI } from '@llamaindex/openai'; 4 | import { fromLlamaIndexModel } from './fromLlamaIndexModel.js'; 5 | 6 | test('llamaindex openai model', () => { 7 | const model = new OpenAI({ 8 | model: 'gpt-4o', 9 | }); 10 | 11 | const normalized = fromLlamaIndexModel(model); 12 | expect(normalized.name).toBe('gpt-4o'); 13 | }); 14 | -------------------------------------------------------------------------------- /legacy/cli/src/commands/NotionSyncCommand.ts: -------------------------------------------------------------------------------- 1 | import { SyncNotionPages } from '@agentscript-ai/notion'; 2 | 3 | import { ApplicationCommand } from './ApplicationCommand.js'; 4 | 5 | export class NotionSyncCommand extends ApplicationCommand { 6 | static override description = 'Sync Notion pages'; 7 | 8 | async run() { 9 | const syncNotionPages = this.container.resolve(SyncNotionPages); 10 | await syncNotionPages(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /legacy/notion/src/NotionClient.ts: -------------------------------------------------------------------------------- 1 | import { Client } from '@notionhq/client'; 2 | 3 | import { EnvVariables } from '@agentscript-ai/core'; 4 | import { defineService } from '@nzyme/ioc'; 5 | 6 | export const NotionClient = defineService({ 7 | name: 'NotionClient', 8 | deps: { 9 | env: EnvVariables, 10 | }, 11 | setup({ env }) { 12 | return new Client({ 13 | auth: env.NOTION_TOKEN, 14 | }); 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /legacy/database/drizzle.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | 3 | import { config as configDotenv } from 'dotenv'; 4 | import { defineConfig } from 'drizzle-kit'; 5 | 6 | configDotenv({ 7 | path: path.resolve(__dirname, '../../.env'), 8 | override: true, 9 | }); 10 | 11 | export default defineConfig({ 12 | dialect: 'postgresql', 13 | schema: './src/schema', 14 | dbCredentials: { 15 | url: String(process.env.DATABASE_URL), 16 | }, 17 | }); 18 | -------------------------------------------------------------------------------- /legacy/linear/src/LinearClient.ts: -------------------------------------------------------------------------------- 1 | import { LinearClient as Linear } from '@linear/sdk'; 2 | 3 | import { EnvVariables } from '@agentscript-ai/core'; 4 | import { defineService } from '@nzyme/ioc'; 5 | 6 | export const LinearClient = defineService({ 7 | name: 'LinearClient', 8 | deps: { 9 | env: EnvVariables, 10 | }, 11 | setup({ env }) { 12 | return new Linear({ 13 | apiKey: env.LINEAR_API_KEY, 14 | }); 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/openapi/src/utils/isReferenceObject.ts: -------------------------------------------------------------------------------- 1 | import type { OpenAPIV3 } from 'openapi-types'; 2 | 3 | /** 4 | * Checks if the given schema is a reference object. 5 | * @param schema - The schema to check. 6 | * @returns True if the schema is a reference object, false otherwise. 7 | */ 8 | export function isReferenceObject( 9 | schema: T | OpenAPIV3.ReferenceObject, 10 | ): schema is OpenAPIV3.ReferenceObject { 11 | return '$ref' in (schema as object); 12 | } 13 | -------------------------------------------------------------------------------- /legacy/core/src/models/AgentState.ts: -------------------------------------------------------------------------------- 1 | import * as z from 'zod'; 2 | 3 | import { AgentEvent } from './AgentEvent.js'; 4 | import { ChatUser } from '../Chat.js'; 5 | 6 | export type AgentState = z.infer; 7 | export const AgentState = z.object({ 8 | id: z.string(), 9 | channelId: z.string(), 10 | threadId: z.string(), 11 | events: z.array(AgentEvent), 12 | tools: z.record(z.string(), z.unknown()), 13 | users: z.record(z.string(), ChatUser), 14 | }); 15 | -------------------------------------------------------------------------------- /legacy/linear/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/ioc/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/utils/tsconfig.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /legacy/notion/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/ioc/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/utils/tsconfig.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /legacy/rag/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/ioc/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/utils/tsconfig.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/core/src/agent/rechainAgent.ts: -------------------------------------------------------------------------------- 1 | import type { Agent } from './agentTypes.js'; 2 | 3 | /** 4 | * Rechains an agent. 5 | * @param agent - Agent to rechain. 6 | */ 7 | export function rechainAgent(agent: Agent) { 8 | const chain = agent.chain; 9 | 10 | if (chain && chain.length > 0) { 11 | for (let i = 1; i < chain.length; i++) { 12 | chain[i]!.root.parent = chain[i - 1]!.root; 13 | } 14 | 15 | agent.root.parent = chain[chain.length - 1]!.root; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /legacy/core/src/models/ChatMessage.ts: -------------------------------------------------------------------------------- 1 | import * as z from 'zod'; 2 | 3 | export type ChatMessageInfo = z.infer; 4 | export const ChatMessageInfo = z.object({ 5 | channelId: z.string(), 6 | threadId: z.string(), 7 | messageId: z.string(), 8 | userId: z.string(), 9 | timestamp: z.date(), 10 | }); 11 | 12 | export type ChatMessageWithContent = z.infer; 13 | export const ChatMessageWithContent = ChatMessageInfo.extend({ 14 | content: z.string(), 15 | }); 16 | -------------------------------------------------------------------------------- /legacy/core/src/index.ts: -------------------------------------------------------------------------------- 1 | export const EMBEDDING_DIMENSIONS = 1536; 2 | 3 | export * from './Chat.js'; 4 | export * from './EnvVariables.js'; 5 | export * from './TenantContext.js'; 6 | export * from './Logger.js'; 7 | export * from './defineTool.js'; 8 | 9 | export * from './models/AgentEvent.js'; 10 | export * from './models/AgentState.js'; 11 | export * from './models/ChatMessage.js'; 12 | export * from './models/KnowledgeType.js'; 13 | 14 | export * from './utils/randomUid.js'; 15 | export * from './utils/toolChatAction.js'; 16 | -------------------------------------------------------------------------------- /legacy/agent-local/src/index.ts: -------------------------------------------------------------------------------- 1 | import { install as installSourceMaps } from 'source-map-support'; 2 | 3 | import { loadEnvVariables, resolveLocalPath } from '@nzyme/project-utils'; 4 | import { devServerConfig, devServerStart } from '@nzyme/rollup-utils'; 5 | 6 | installSourceMaps(); 7 | loadEnvVariables(); 8 | 9 | devServerStart({ 10 | ...devServerConfig({ 11 | input: resolveLocalPath(import.meta, './server.ts'), 12 | outputDir: resolveLocalPath(import.meta, '../dist'), 13 | }), 14 | port: 3001, 15 | }); 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: 'npm' # See documentation for possible values 9 | directory: '/' # Location of package manifests 10 | schedule: 11 | interval: 'weekly' 12 | -------------------------------------------------------------------------------- /packages/core/src/meta/defaultMetadata.ts: -------------------------------------------------------------------------------- 1 | import { defineMetadata } from './defineMetadata.js'; 2 | 3 | /** 4 | * Stores the prompt of the agent. 5 | * @example 6 | * ```typescript 7 | * const prompt = promptMetadata(agent); 8 | * ``` 9 | */ 10 | export const promptMetadata = defineMetadata({ name: 'agentscript:prompt' }); 11 | 12 | /** 13 | * Stores the plan of the agent. 14 | * @example 15 | * ```typescript 16 | * const plan = planMetadata(agent); 17 | * ``` 18 | */ 19 | export const planMetadata = defineMetadata({ name: 'agentscript:plan' }); 20 | -------------------------------------------------------------------------------- /packages/tools/src/addToDate.ts: -------------------------------------------------------------------------------- 1 | import { add } from 'date-fns'; 2 | 3 | import { defineTool } from '@agentscript-ai/core'; 4 | import * as s from '@agentscript-ai/schema'; 5 | 6 | import { Duration } from './types/Duration.js'; 7 | 8 | /** 9 | * Add a duration to a date. 10 | */ 11 | export const addToDate = defineTool({ 12 | description: 'Add a duration to a date.', 13 | input: { 14 | date: s.date(), 15 | duration: Duration, 16 | }, 17 | output: s.date(), 18 | handler: ({ input: { date, duration } }) => add(date, duration), 19 | }); 20 | -------------------------------------------------------------------------------- /packages/linear/src/types/Issue.ts: -------------------------------------------------------------------------------- 1 | import * as s from '@agentscript-ai/schema'; 2 | 3 | /** 4 | * Issue type. 5 | */ 6 | export type Issue = s.Infer; 7 | 8 | /** 9 | * Issue schema. 10 | */ 11 | export const Issue = s.object({ 12 | name: 'Issue', 13 | description: 'Linear issue', 14 | props: { 15 | id: s.string(), 16 | url: s.string(), 17 | title: s.string(), 18 | description: s.string({ optional: true }), 19 | status: s.string(), 20 | createdAt: s.date(), 21 | updatedAt: s.date(), 22 | }, 23 | }); 24 | -------------------------------------------------------------------------------- /legacy/slack/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/ioc/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/slack/tsconfig.json" 15 | }, 16 | { 17 | "path": "../../nzyme/packages/utils/tsconfig.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /legacy/core/src/Logger.ts: -------------------------------------------------------------------------------- 1 | import { pino } from 'pino'; 2 | import pretty from 'pino-pretty'; 3 | 4 | import { defineService } from '@nzyme/ioc'; 5 | 6 | export type Logger = pino.Logger; 7 | export const Logger = defineService({ 8 | name: 'Logger', 9 | resolution: 'transient', 10 | setup({ source }) { 11 | const stream = pretty({ 12 | colorize: true, 13 | }); 14 | 15 | const options: pino.LoggerOptions = { 16 | name: source?.name, 17 | level: 'debug', 18 | }; 19 | 20 | return pino(options, stream); 21 | }, 22 | }); 23 | -------------------------------------------------------------------------------- /legacy/database/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/ioc/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/utils/tsconfig.json" 15 | }, 16 | { 17 | "path": "../../nzyme/packages/project-utils/tsconfig.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /legacy/rag/src/EmbeddingModel.ts: -------------------------------------------------------------------------------- 1 | import type { Embeddings } from '@langchain/core/embeddings'; 2 | import { OpenAIEmbeddings } from '@langchain/openai'; 3 | 4 | import { EnvVariables } from '@agentscript-ai/core'; 5 | import { defineService } from '@nzyme/ioc'; 6 | 7 | export const EmbeddingModel = defineService({ 8 | name: 'EmbeddingModel', 9 | deps: { 10 | env: EnvVariables, 11 | }, 12 | setup({ env }) { 13 | return new OpenAIEmbeddings({ 14 | modelName: 'text-embedding-3-small', 15 | apiKey: env.OPENAI_API_KEY, 16 | }); 17 | }, 18 | }); 19 | -------------------------------------------------------------------------------- /packages/tools/src/types/Duration.ts: -------------------------------------------------------------------------------- 1 | import * as s from '@agentscript-ai/schema'; 2 | 3 | /** 4 | * Duration type. 5 | */ 6 | export type Duration = s.Infer; 7 | 8 | /** 9 | * Duration type schema. 10 | */ 11 | export const Duration = s.object({ 12 | name: 'Duration', 13 | props: { 14 | years: s.number({ optional: true }), 15 | months: s.number({ optional: true }), 16 | days: s.number({ optional: true }), 17 | hours: s.number({ optional: true }), 18 | minutes: s.number({ optional: true }), 19 | seconds: s.number({ optional: true }), 20 | }, 21 | }); 22 | -------------------------------------------------------------------------------- /packages/openapi/src/parseOpenApiDoc.ts: -------------------------------------------------------------------------------- 1 | import { type AnyApiDefinitionFormat, load, upgrade } from '@scalar/openapi-parser'; 2 | import type { OpenAPIV3 } from 'openapi-types'; 3 | /** 4 | * Parses an OpenAPI definition. 5 | * @param openApi - The OpenAPI definition. 6 | * @returns The parsed OpenAPI definition. 7 | */ 8 | export async function parseOpenApiDoc( 9 | openApi: AnyApiDefinitionFormat, 10 | ): Promise { 11 | const openApiObject = await load(openApi); 12 | const upgradedOpenApi = upgrade(openApiObject.specification); 13 | 14 | return upgradedOpenApi.specification as OpenAPIV3.Document; 15 | } 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG.yml: -------------------------------------------------------------------------------- 1 | name: 'Bug Report' 2 | description: Create a ticket for a bug 3 | title: '[BUG]: ' 4 | labels: ['bug'] 5 | projects: ['AgentScript-AI/3'] 6 | assignees: 7 | - kedrzu 8 | body: 9 | - type: markdown 10 | attributes: 11 | value: | 12 | Thanks for taking the time to fill out this bug report! 13 | - type: textarea 14 | id: what-happened 15 | attributes: 16 | label: What happened? 17 | description: Also tell us, what did you expect to happen? 18 | placeholder: Tell us what you see! 19 | value: 'A bug happened!' 20 | validations: 21 | required: true 22 | -------------------------------------------------------------------------------- /packages/linear/src/LinearClient.ts: -------------------------------------------------------------------------------- 1 | import { defineService, envVariable } from '@nzyme/ioc'; 2 | import { GraphQLClient } from 'graphql-request'; 3 | 4 | 5 | /** 6 | * Linear client. 7 | */ 8 | export type LinearClient = GraphQLClient; 9 | 10 | /** 11 | * Linear client service. 12 | */ 13 | export const LinearClient = defineService({ 14 | name: 'LinearClient', 15 | deps: { 16 | apiKey: envVariable('LINEAR_API_KEY'), 17 | }, 18 | setup({ apiKey }) { 19 | return new GraphQLClient('https://api.linear.app/graphql', { 20 | headers: { 21 | Authorization: apiKey, 22 | }, 23 | }); 24 | }, 25 | }); 26 | -------------------------------------------------------------------------------- /legacy/rag/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/rag", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "dependencies": { 9 | "@agentscript-ai/core": "*", 10 | "@agentscript-ai/database": "*", 11 | "@langchain/core": "^0.3.22", 12 | "@langchain/openai": "^0.3.14", 13 | "@nzyme/ioc": "*", 14 | "@nzyme/utils": "*" 15 | }, 16 | "devDependencies": { 17 | "@agentscript-ai/eslint": "*", 18 | "@agentscript-ai/tsconfig": "*", 19 | "@types/node": "^20.11.24", 20 | "typescript": "^5.7.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /legacy/core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/crypto-utils/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/ioc/tsconfig.json" 15 | }, 16 | { 17 | "path": "../../nzyme/packages/types/tsconfig.json" 18 | }, 19 | { 20 | "path": "../../nzyme/packages/utils/tsconfig.json" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /legacy/database/src/DatabaseClient.ts: -------------------------------------------------------------------------------- 1 | import { drizzle } from 'drizzle-orm/postgres-js'; 2 | import postgres from 'postgres'; 3 | 4 | import { EnvVariables } from '@agentscript-ai/core'; 5 | import { defineService } from '@nzyme/ioc'; 6 | 7 | import * as db from './schema.js'; 8 | 9 | export const DatabaseClient = defineService({ 10 | name: 'DatabaseClient', 11 | deps: { 12 | env: EnvVariables, 13 | }, 14 | setup({ env }) { 15 | const url = String(env.DATABASE_URL); 16 | const driver = postgres(url); 17 | 18 | return drizzle(driver, { 19 | schema: db, 20 | logger: env.DATABASE_LOGGING === 'true', 21 | }); 22 | }, 23 | }); 24 | -------------------------------------------------------------------------------- /packages/linear/graphql.config.ts: -------------------------------------------------------------------------------- 1 | import type { CodegenConfig } from '@graphql-codegen/cli'; 2 | 3 | const config: CodegenConfig = { 4 | schema: 'https://api.linear.app/graphql', 5 | documents: ['src/**/*.gql'], 6 | overwrite: true, 7 | generates: { 8 | './src/gql.ts': { 9 | plugins: ['typescript', 'typescript-operations', 'typescript-graphql-request'], 10 | config: { 11 | useTypeImports: true, 12 | enumsAsConst: true, 13 | // allows to dump the whole GraphQL parsing library (50KB!) 14 | documentMode: 'string', 15 | }, 16 | }, 17 | }, 18 | }; 19 | 20 | export default config; 21 | -------------------------------------------------------------------------------- /packages/openapi/src/toolsFromOpenApi.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import { parseOpenApiDoc } from './parseOpenApiDoc.js'; 4 | import { toolsFromOpenApi } from './toolsFromOpenApi.js'; 5 | 6 | const swaggerUrl = 'https://petstore3.swagger.io/api/v3/openapi.json'; 7 | const apiUrl = 'https://petstore3.swagger.io/api/v3'; 8 | 9 | test('toolsFromOpenApi', async () => { 10 | const openApi = await fetch(swaggerUrl); 11 | const openApiJson = await openApi.text(); 12 | 13 | const spec = await parseOpenApiDoc(openApiJson); 14 | const tools = toolsFromOpenApi({ 15 | spec, 16 | baseUrl: apiUrl, 17 | }); 18 | 19 | expect(tools).toBeDefined(); 20 | }); 21 | -------------------------------------------------------------------------------- /legacy/agent-local/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "rootDir": "./src", 5 | "outDir": "./dist", 6 | "composite": false, 7 | "noEmit": true 8 | }, 9 | "include": ["src"], 10 | "references": [ 11 | { 12 | "path": "../../nzyme/packages/ioc/tsconfig.json" 13 | }, 14 | { 15 | "path": "../../nzyme/packages/project-utils/tsconfig.json" 16 | }, 17 | { 18 | "path": "../../nzyme/packages/rollup-utils/tsconfig.json" 19 | }, 20 | { 21 | "path": "../../nzyme/packages/utils/tsconfig.json" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /packages/core/src/agent/createAgent.test.ts: -------------------------------------------------------------------------------- 1 | import { validate } from 'uuid'; 2 | import { expect, test } from 'vitest'; 3 | 4 | import { parseScript } from '@agentscript-ai/parser'; 5 | 6 | import { createAgent } from './createAgent.js'; 7 | 8 | test('create agent with id', () => { 9 | const script = parseScript('foo()'); 10 | 11 | const agent = createAgent({ 12 | id: 'test', 13 | tools: {}, 14 | script, 15 | }); 16 | 17 | expect(agent.id).toBe('test'); 18 | }); 19 | 20 | test('create agent without id', () => { 21 | const script = parseScript('foo()'); 22 | 23 | const agent = createAgent({ tools: {}, script }); 24 | 25 | expect(validate(agent.id)).toBe(true); 26 | }); 27 | -------------------------------------------------------------------------------- /packages/utils/src/normalizeText.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Normalize text to an array of strings, split into lines. 3 | * 4 | * @param text - The text to normalize. 5 | * @returns An array of strings. 6 | */ 7 | export function normalizeText(text: string | string[] | undefined | null) { 8 | if (!text) { 9 | return []; 10 | } 11 | 12 | if (!Array.isArray(text)) { 13 | return text.split('\n').map(line => line.trim()); 14 | } 15 | 16 | const normalized: string[] = []; 17 | 18 | for (const line of text) { 19 | const lines = line.split('\n'); 20 | 21 | for (const l of lines) { 22 | normalized.push(l.trim()); 23 | } 24 | } 25 | 26 | return normalized; 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/automerge-release.yml: -------------------------------------------------------------------------------- 1 | name: Automerge release 2 | on: 3 | push: 4 | branches: [release] 5 | 6 | permissions: 7 | contents: write 8 | 9 | jobs: 10 | merge-branch: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | with: 15 | ref: main 16 | 17 | - name: Setup Git 18 | run: | 19 | git config --local user.email "actions@github.com" 20 | git config --local user.name "Github Actions" 21 | git fetch --unshallow 22 | 23 | - name: Merge release to main 24 | id: mergeRelease 25 | run: | 26 | git merge --no-ff origin/release -m "chore: auto-merge release -> main" 27 | git push 28 | -------------------------------------------------------------------------------- /nx.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/nx/schemas/nx-schema.json", 3 | "targetDefaults": { 4 | "eslint": { 5 | "dependsOn": ["^eslint"] 6 | }, 7 | "build": { 8 | "dependsOn": ["^build"] 9 | } 10 | }, 11 | "release": { 12 | "projects": ["packages/*", "!packages/tsc"], 13 | "releaseTagPattern": "v{version}", 14 | "version": { 15 | "conventionalCommits": true 16 | }, 17 | "changelog": { 18 | "workspaceChangelog": { 19 | "createRelease": "github" 20 | } 21 | }, 22 | "git": { 23 | "commitMessage": "chore(release): v{version}" 24 | } 25 | }, 26 | "defaultBase": "main" 27 | } 28 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderComment.ts: -------------------------------------------------------------------------------- 1 | import type { RenderContext } from './renderContext.js'; 2 | 3 | /** 4 | * Render a comment. 5 | * @param comment - The comment to render. 6 | * @param ctx - Render context. 7 | * @returns Rendered comment. 8 | */ 9 | export function renderComment(comment: string[], ctx: RenderContext) { 10 | let code = ''; 11 | 12 | if (comment.length === 0) { 13 | return; 14 | } 15 | 16 | if (comment.length > 1) { 17 | code = `${ctx.indent}/**`; 18 | for (const line of comment) { 19 | code += `\n${ctx.indent} * ${line}`; 20 | } 21 | code += `\n${ctx.indent} */`; 22 | } else { 23 | code = `${ctx.indent}/** ${comment[0]} */`; 24 | } 25 | 26 | return code; 27 | } 28 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "extends": ["//"], 4 | "tasks": { 5 | "dev": { 6 | "cache": false, 7 | "persistent": true 8 | }, 9 | "watch": { 10 | "cache": false, 11 | "persistent": true 12 | }, 13 | "codegen": { 14 | "cache": false 15 | }, 16 | "build": { 17 | "dependsOn": ["^build", "codegen"], 18 | "cache": false 19 | }, 20 | "smoke:cjs": { 21 | "cache": false, 22 | "persistent": false 23 | }, 24 | "smoke:mjs": { 25 | "cache": false, 26 | "persistent": false 27 | } 28 | }, 29 | "ui": "stream" 30 | } 31 | -------------------------------------------------------------------------------- /legacy/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/core", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "dependencies": { 9 | "@langchain/core": "^0.3.22", 10 | "@langchain/openai": "^0.3.14", 11 | "@nzyme/crypto-utils": "*", 12 | "@nzyme/ioc": "*", 13 | "@nzyme/types": "*", 14 | "@nzyme/utils": "*", 15 | "pino": "^9.5.0", 16 | "pino-pretty": "^13.0.0", 17 | "zod": "^3.23.8" 18 | }, 19 | "devDependencies": { 20 | "@agentscript-ai/eslint": "*", 21 | "@agentscript-ai/tsconfig": "*", 22 | "@types/node": "^20.11.24", 23 | "typescript": "^5.7.2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /legacy/database/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/database", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "scripts": { 9 | "push": "drizzle-kit push" 10 | }, 11 | "dependencies": { 12 | "@agentscript-ai/core": "*", 13 | "@nzyme/ioc": "*", 14 | "@nzyme/utils": "*", 15 | "dotenv": "^16.4.7", 16 | "drizzle-orm": "^0.36.4", 17 | "postgres": "^3.4.5" 18 | }, 19 | "devDependencies": { 20 | "@agentscript-ai/eslint": "*", 21 | "@agentscript-ai/tsconfig": "*", 22 | "@nzyme/project-utils": "*", 23 | "@types/node": "^20.11.24", 24 | "drizzle-kit": "^0.28.1", 25 | "typescript": "^5.7.2" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /legacy/cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo", 7 | "types": ["@types/node"] 8 | }, 9 | "include": ["src"], 10 | "references": [ 11 | { 12 | "path": "../../nzyme/packages/ioc/tsconfig.json" 13 | }, 14 | { 15 | "path": "../../nzyme/packages/logging/tsconfig.json" 16 | }, 17 | { 18 | "path": "../../nzyme/packages/node-utils/tsconfig.json" 19 | }, 20 | { 21 | "path": "../../nzyme/packages/project-utils/tsconfig.json" 22 | }, 23 | { 24 | "path": "../../nzyme/packages/utils/tsconfig.json" 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderDocDirective.ts: -------------------------------------------------------------------------------- 1 | import { normalizeText } from '@agentscript-ai/utils'; 2 | 3 | /** 4 | * Render a directive. 5 | * @param directive - The directive to render. 6 | * @param comment - The comment to render. 7 | * @returns The rendered directive. 8 | */ 9 | export function renderDocDirective(directive: string, comment: string | string[]) { 10 | const normalized = normalizeText(comment); 11 | 12 | if (normalized.length === 0) { 13 | return ''; 14 | } 15 | 16 | let result = `@${directive} ${normalized[0]}`; 17 | 18 | if (normalized.length > 1) { 19 | const indent = ' '.repeat(directive.length + 2); 20 | 21 | for (let i = 1; i < normalized.length; i++) { 22 | result += `\n${indent}${normalized[i]}`; 23 | } 24 | } 25 | 26 | return result; 27 | } 28 | -------------------------------------------------------------------------------- /legacy/agent/src/utils/defineGraphNode.ts: -------------------------------------------------------------------------------- 1 | import type { Annotation, StateDefinition, StateType, UpdateType } from '@langchain/langgraph'; 2 | 3 | import type { ServiceContext } from '@nzyme/ioc'; 4 | import { defineService } from '@nzyme/ioc'; 5 | 6 | export type AnnotationRoot = ReturnType>; 7 | 8 | export type GraphNode = (state: StateType) => Promise>; 9 | 10 | export interface GraphNodeDefinition { 11 | name: string; 12 | state: AnnotationRoot; 13 | setup: (ctx: ServiceContext) => GraphNode; 14 | } 15 | 16 | export function defineGraphNode(definition: GraphNodeDefinition) { 17 | return defineService({ 18 | name: definition.name, 19 | setup: definition.setup, 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderComment.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import { joinLines } from '@agentscript-ai/utils'; 4 | 5 | import { renderComment } from './renderComment.js'; 6 | import { createRenderContext } from './renderContext.js'; 7 | 8 | test('single line', () => { 9 | const comment = 'Hello'; 10 | const ctx = createRenderContext(); 11 | const code = renderComment([comment], ctx); 12 | 13 | expect(code).toEqual(`/** Hello */`); 14 | }); 15 | 16 | test('multiple lines', () => { 17 | const comment = ['Hello', 'World']; 18 | const ctx = createRenderContext(); 19 | const code = renderComment(comment, ctx); 20 | 21 | expect(code).toEqual( 22 | joinLines([ 23 | // 24 | '/**', 25 | ' * Hello', 26 | ' * World', 27 | ' */', 28 | ]), 29 | ); 30 | }); 31 | -------------------------------------------------------------------------------- /legacy/agent/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@agentscript-ai/tsconfig/base.json", 3 | "compilerOptions": { 4 | "outDir": "./dist", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./dist/.tsbuildinfo" 7 | }, 8 | "include": ["src"], 9 | "references": [ 10 | { 11 | "path": "../../nzyme/packages/crypto-utils/tsconfig.json" 12 | }, 13 | { 14 | "path": "../../nzyme/packages/ioc/tsconfig.json" 15 | }, 16 | { 17 | "path": "../../nzyme/packages/project-utils/tsconfig.json" 18 | }, 19 | { 20 | "path": "../../nzyme/packages/slack/tsconfig.json" 21 | }, 22 | { 23 | "path": "../../nzyme/packages/types/tsconfig.json" 24 | }, 25 | { 26 | "path": "../../nzyme/packages/utils/tsconfig.json" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /packages/core/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './inferResult.js'; 2 | 3 | export * from './agent/agentTypes.js'; 4 | export * from './agent/defineAgent.js'; 5 | export * from './agent/createAgent.js'; 6 | export * from './agent/inferAgent.js'; 7 | export * from './agent/restoreAgent.js'; 8 | export * from './agent/storeAgent.js'; 9 | export * from './agent/chainAgent.js'; 10 | 11 | export * from './runtime/executeAgent.js'; 12 | export * from './runtime/RuntimeError.js'; 13 | export * from './runtime/runtimeTypes.js'; 14 | 15 | export * from './modules/renderRuntime.js'; 16 | 17 | export * from './meta/defineMetadata.js'; 18 | export * from './meta/defaultMetadata.js'; 19 | 20 | export * from './tools/defineTool.js'; 21 | export * from './tools/defineToolModule.js'; 22 | export * from './tools/filterTools.js'; 23 | export * from './tools/refineTools.js'; 24 | export type * from './tools/toolResult.js'; 25 | -------------------------------------------------------------------------------- /packages/tsconfig/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/tsconfig", 3 | "version": "0.9.0", 4 | "license": "Elastic License 2.0 (ELv2)", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/AgentScript-AI/agentscript.git" 8 | }, 9 | "author": "Michał Kędrzyński ", 10 | "publishConfig": { 11 | "access": "public" 12 | }, 13 | "files": [ 14 | "*.json", 15 | "LICENSE", 16 | "README.md" 17 | ], 18 | "sideEffects": false, 19 | "main": "./base.json", 20 | "scripts": { 21 | "prepack": "cp ../../README.md . && cp ../../LICENSE ." 22 | }, 23 | "dependencies": { 24 | "@nzyme/tsconfig": "^0.14.0", 25 | "@types/node": "^22.14.0" 26 | }, 27 | "devDependencies": { 28 | "eslint": "^9.24.0", 29 | "typescript": "^5.8.3" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /legacy/agent/src/utils/convertEventToPrompt.ts: -------------------------------------------------------------------------------- 1 | import { AIMessage, HumanMessage, SystemMessage } from '@langchain/core/messages'; 2 | 3 | import type { AgentEvent } from '@agentscript-ai/core'; 4 | 5 | export function convertEventToPrompt(event: AgentEvent) { 6 | switch (event.type) { 7 | case 'HUMAN_MESSAGE': 8 | return new HumanMessage({ 9 | content: event.content, 10 | name: event.message.userId, 11 | }); 12 | 13 | case 'AGENT_MESSAGE': 14 | return new AIMessage({ 15 | content: event.content, 16 | name: event.message?.userId, 17 | }); 18 | 19 | case 'TOOL_EVENT': 20 | if (!event.content) { 21 | break; 22 | } 23 | 24 | return new SystemMessage({ 25 | content: event.content, 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /legacy/core/src/utils/toolChatAction.ts: -------------------------------------------------------------------------------- 1 | import * as z from 'zod'; 2 | 3 | import type { ToolCall } from '../models/AgentEvent.js'; 4 | 5 | export const TOOL_CHAT_ACTION_TYPE = 'TOOL_INTERACTION'; 6 | 7 | export interface ToolChatActionParams { 8 | stateId: string; 9 | call: ToolCall; 10 | params: Record; 11 | } 12 | 13 | export type ToolChatAction = z.infer; 14 | export const ToolChatAction = z.object({ 15 | stateId: z.string(), 16 | toolCallId: z.string(), 17 | params: z.record(z.unknown()), 18 | }); 19 | 20 | export function toolChatAction(params: ToolChatActionParams) { 21 | const action: ToolChatAction = { 22 | stateId: params.stateId, 23 | toolCallId: params.call.uid, 24 | params: params.params, 25 | }; 26 | 27 | return { 28 | action: TOOL_CHAT_ACTION_TYPE, 29 | value: JSON.stringify(action), 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /legacy/agent-local/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/agent-local", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "scripts": { 7 | "dev": "node --loader ts-node/esm src/index.ts" 8 | }, 9 | "dependencies": { 10 | "@agentscript-ai/agent": "*", 11 | "@agentscript-ai/core": "*", 12 | "@agentscript-ai/slack": "*", 13 | "@nzyme/ioc": "*", 14 | "@nzyme/project-utils": "*", 15 | "@nzyme/rollup-utils": "*", 16 | "@nzyme/utils": "*", 17 | "@slack/bolt": "^4.1.1", 18 | "source-map-support": "^0.5.21", 19 | "ts-node": "^10.9.2" 20 | }, 21 | "devDependencies": { 22 | "@agentscript-ai/eslint": "*", 23 | "@agentscript-ai/tsconfig": "*", 24 | "@types/node": "^20.11.24", 25 | "@types/source-map-support": "^0.5.10", 26 | "typescript": "^5.7.2" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /legacy/notion/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/notion", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "dependencies": { 9 | "@agentscript-ai/core": "*", 10 | "@agentscript-ai/database": "*", 11 | "@agentscript-ai/rag": "*", 12 | "@langchain/community": "^0.3.17", 13 | "@langchain/core": "^0.3.22", 14 | "@langchain/langgraph": "^0.2.23", 15 | "@notionhq/client": "^2.2.15", 16 | "@nzyme/ioc": "*", 17 | "@nzyme/utils": "*", 18 | "drizzle-orm": "^0.36.4", 19 | "notion-to-md": "^3.1.1", 20 | "zod": "^3.23.8" 21 | }, 22 | "devDependencies": { 23 | "@agentscript-ai/eslint": "*", 24 | "@agentscript-ai/tsconfig": "*", 25 | "@types/node": "^20.11.24", 26 | "typescript": "^5.7.2" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/eslint/src/common.ts: -------------------------------------------------------------------------------- 1 | import { imports } from '@nzyme/eslint'; 2 | import { globalIgnores } from 'eslint/config'; 3 | 4 | export function common() { 5 | return [ 6 | ...imports({ 7 | groups: [ 8 | { 9 | pattern: 'agentscript-ai', 10 | group: 'internal', 11 | }, 12 | { 13 | pattern: 'agentscript-ai/**', 14 | group: 'internal', 15 | }, 16 | { 17 | pattern: '@agentscript-ai/**', 18 | group: 'internal', 19 | }, 20 | { 21 | pattern: '@/**', 22 | group: 'internal', 23 | position: 'after', 24 | }, 25 | ], 26 | }), 27 | globalIgnores(['dist/**/*', 'dist-*/**/*', 'node_modules/**/*']), 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /legacy/linear/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/linear", 3 | "version": "1.0.0", 4 | "repository": "https://github.com/kedrzu/agentscript.git", 5 | "author": "Michał Kędrzyński ", 6 | "private": true, 7 | "type": "module", 8 | "main": "./dist/index.js", 9 | "module": "./dist/index.js", 10 | "types": "./dist/index.d.ts", 11 | "sideEffects": false, 12 | "scripts": { 13 | "eslint": "eslint . --fix --cache", 14 | "build": "tsc --build" 15 | }, 16 | "dependencies": { 17 | "@agentscript-ai/core": "*", 18 | "@agentscript-ai/database": "*", 19 | "@linear/sdk": "^35.0.0", 20 | "@nzyme/ioc": "*", 21 | "@nzyme/utils": "*", 22 | "zod": "^3.23.8" 23 | }, 24 | "devDependencies": { 25 | "@agentscript-ai/eslint": "*", 26 | "@agentscript-ai/tsconfig": "*", 27 | "@types/node": "^22.7.5" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/openapi/src/utils/resolveReferenceObject.ts: -------------------------------------------------------------------------------- 1 | import type { OpenAPIV3 } from 'openapi-types'; 2 | 3 | /** 4 | * Resolves a reference object to a schema. 5 | * @param spec - The OpenAPI specification. 6 | * @param ref - The reference object to resolve. 7 | * @returns The resolved schema and name. 8 | */ 9 | export function resolveReferenceObject(spec: OpenAPIV3.Document, ref: OpenAPIV3.ReferenceObject) { 10 | const path = ref.$ref?.split('/'); 11 | if (!path) { 12 | return null; 13 | } 14 | 15 | let current = spec as unknown as Record | undefined; 16 | 17 | for (const part of path) { 18 | if (part === '#') { 19 | continue; 20 | } 21 | 22 | current = current?.[part] as Record; 23 | } 24 | 25 | if (!current) { 26 | return null; 27 | } 28 | 29 | return { 30 | schema: current, 31 | name: path[path.length - 1]!, 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /packages/parser/src/parseCodeResponse.ts: -------------------------------------------------------------------------------- 1 | import { ParseError } from './ParseError.js'; 2 | 3 | const RESPONSE_WRAPPED_REGEX = /^([\s\S]*)```(\w*)?\n([\s\S]*)\n```/m; 4 | const RESPONSE_UNWRAPPED_REGEX = /^([\s\S]*?)\n(\/\/[\s\S]*)/m; 5 | 6 | /** 7 | * Parse the response from the LLM into a plan and code. 8 | * @param response - Response from the LLM. 9 | * @returns Plan and code. 10 | */ 11 | export function parseCodeResponse(response: string) { 12 | let match = response.match(RESPONSE_WRAPPED_REGEX); 13 | if (match) { 14 | return { 15 | plan: match[1]!.trim(), 16 | code: match[3]!.trim(), 17 | }; 18 | } 19 | 20 | match = response.match(RESPONSE_UNWRAPPED_REGEX); 21 | if (match) { 22 | return { 23 | plan: match[1]!.trim(), 24 | code: match[2]!.trim(), 25 | }; 26 | } 27 | 28 | throw new ParseError('No code found in response', { 29 | cause: response, 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /legacy/cli/src/commands/ApplicationCommand.ts: -------------------------------------------------------------------------------- 1 | import { Command, Flags } from '@oclif/core'; 2 | 3 | import { EnvVariables } from '@agentscript-ai/core'; 4 | import { createContainer } from '@nzyme/ioc'; 5 | import { Logger, PrettyLoggerFactory } from '@nzyme/logging'; 6 | 7 | export abstract class ApplicationCommand extends Command { 8 | public static override flags = { 9 | env: Flags.string({ 10 | name: 'env', 11 | description: 'Stage to operate on', 12 | }), 13 | }; 14 | 15 | protected readonly container = createContainer(); 16 | 17 | override async init() { 18 | await super.init(); 19 | 20 | this.container.set(EnvVariables, process.env); 21 | this.container.set(Logger, PrettyLoggerFactory); 22 | } 23 | 24 | override async finally(e: Error | undefined) { 25 | await super.finally(e); 26 | if (e) { 27 | console.error(e); 28 | } 29 | process.exit(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/linear/src/gql.gql: -------------------------------------------------------------------------------- 1 | query getIssues($filter: IssueFilter, $comments: Boolean!, $description: Boolean!) { 2 | issues(filter: $filter) { 3 | nodes { 4 | identifier 5 | url 6 | title 7 | state { 8 | name 9 | type 10 | } 11 | creator { 12 | ...User 13 | } 14 | createdAt 15 | updatedAt 16 | description @include(if: $description) 17 | comments @include(if: $comments) { 18 | nodes { 19 | id 20 | user { 21 | ...User 22 | } 23 | body 24 | } 25 | } 26 | } 27 | } 28 | } 29 | 30 | query getWorkflowStates { 31 | workflowStates { 32 | nodes { 33 | name 34 | } 35 | } 36 | } 37 | 38 | fragment User on User { 39 | id 40 | name 41 | email 42 | } 43 | -------------------------------------------------------------------------------- /legacy/agent-local/src/server.ts: -------------------------------------------------------------------------------- 1 | import slack from '@slack/bolt'; 2 | import { install as installSourceMaps } from 'source-map-support'; 3 | 4 | import { SlackBot } from '@agentscript-ai/agent'; 5 | import { Chat, EnvVariables } from '@agentscript-ai/core'; 6 | import { SlackChat, SlackReceiver } from '@agentscript-ai/slack'; 7 | import { createContainer } from '@nzyme/ioc'; 8 | import { loadEnvVariables } from '@nzyme/project-utils'; 9 | import { devServerRuntime } from '@nzyme/rollup-utils'; 10 | 11 | installSourceMaps(); 12 | loadEnvVariables(); 13 | 14 | const runtime = devServerRuntime(); 15 | const container = createContainer(); 16 | 17 | const receiver = new slack.HTTPReceiver({ 18 | signingSecret: String(process.env.SLACK_SIGNING_SECRET), 19 | port: runtime.port, 20 | }); 21 | 22 | container.set(EnvVariables, process.env); 23 | container.set(Chat, SlackChat); 24 | container.set(SlackReceiver, receiver); 25 | 26 | const slackApp = container.resolve(SlackBot); 27 | 28 | await slackApp.start(); 29 | 30 | runtime.start(); 31 | -------------------------------------------------------------------------------- /legacy/slack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/slack", 3 | "version": "1.0.0", 4 | "repository": "https://github.com/kedrzu/agentscript.git", 5 | "author": "Michał Kędrzyński ", 6 | "private": true, 7 | "type": "module", 8 | "main": "./dist/index.js", 9 | "module": "./dist/index.js", 10 | "types": "./dist/index.d.ts", 11 | "sideEffects": false, 12 | "scripts": { 13 | "eslint": "eslint . --fix --cache", 14 | "build": "tsc --build" 15 | }, 16 | "dependencies": { 17 | "@agentscript-ai/core": "*", 18 | "@agentscript-ai/database": "*", 19 | "@agentscript-ai/rag": "*", 20 | "@nzyme/ioc": "*", 21 | "@nzyme/slack": "*", 22 | "@nzyme/utils": "*", 23 | "@slack/bolt": "^4.1.1", 24 | "@slack/web-api": "7.6.0", 25 | "@tryfabric/mack": "^1.2.1" 26 | }, 27 | "devDependencies": { 28 | "@agentscript-ai/eslint": "*", 29 | "@agentscript-ai/tsconfig": "*", 30 | "@types/node": "^22.7.5" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/eslint/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/eslint", 3 | "version": "0.9.0", 4 | "license": "Elastic License 2.0 (ELv2)", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/AgentScript-AI/agentscript.git" 8 | }, 9 | "author": "Michał Kędrzyński ", 10 | "publishConfig": { 11 | "access": "public" 12 | }, 13 | "files": [ 14 | "dist", 15 | "LICENSE", 16 | "README.md" 17 | ], 18 | "type": "module", 19 | "sideEffects": false, 20 | "exports": { 21 | ".": { 22 | "import": "./dist/index.js", 23 | "types": "./dist/index.d.ts" 24 | } 25 | }, 26 | "scripts": { 27 | "prepack": "cp ../../README.md . && cp ../../LICENSE ." 28 | }, 29 | "dependencies": { 30 | "@nzyme/eslint": "^0.14.0", 31 | "tslib": "^2.8.1" 32 | }, 33 | "devDependencies": { 34 | "@agentscript-ai/tsconfig": "^0.9.0", 35 | "eslint": "^9.24.0", 36 | "typescript": "^5.8.3" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /legacy/agent/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/agent", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "main": "dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "dependencies": { 9 | "@agentscript-ai/core": "*", 10 | "@agentscript-ai/database": "*", 11 | "@agentscript-ai/linear": "*", 12 | "@agentscript-ai/notion": "*", 13 | "@agentscript-ai/rag": "*", 14 | "@agentscript-ai/slack": "*", 15 | "@langchain/core": "^0.3.19", 16 | "@langchain/langgraph": "^0.2.23", 17 | "@langchain/openai": "^0.3.14", 18 | "@nzyme/crypto-utils": "*", 19 | "@nzyme/ioc": "*", 20 | "@nzyme/project-utils": "*", 21 | "@nzyme/slack": "*", 22 | "@nzyme/types": "*", 23 | "@nzyme/utils": "*", 24 | "@slack/bolt": "^4.1.1", 25 | "debug": "^4.4.0", 26 | "zod": "^3.23.8" 27 | }, 28 | "devDependencies": { 29 | "@types/debug": "^4", 30 | "@types/node": "^20.11.24", 31 | "typescript": "^5.7.2" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/core/src/tools/toolResult.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Symbol to indicate that the tool is waiting for events. 3 | */ 4 | export const TOOL_AWAIT_RESULT = Symbol('toolAwait'); 5 | 6 | /** 7 | * Helper for the tool result. 8 | */ 9 | export const toolResultHelper: ToolResultHelper = Object.assign((output: unknown) => output, { 10 | await: () => TOOL_AWAIT_RESULT, 11 | }); 12 | 13 | /** 14 | * Special tool result type to indicate that the tool is waiting for events. 15 | */ 16 | export type ToolAwaitResult = typeof TOOL_AWAIT_RESULT; 17 | 18 | /** 19 | * Helper type for the tool result. 20 | */ 21 | export type ToolResultHelper = { 22 | /** 23 | * Helper function to return the output. 24 | * Makes it easier to proprly type the output of the tool. 25 | * @param output - Output to return. 26 | * @returns Output. 27 | */ 28 | (output: TOutput): TOutput; 29 | /** 30 | * Marks the tool as waiting for events. 31 | */ 32 | await(): ToolAwaitResult; 33 | }; 34 | 35 | /** 36 | * Result of the tool. 37 | */ 38 | export type ToolResult = TOutput | ToolAwaitResult; 39 | -------------------------------------------------------------------------------- /legacy/cli/bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { execute, settings } from '@oclif/core'; 4 | import consola from 'consola'; 5 | import sourceMap from 'source-map-support'; 6 | import * as tsx from 'tsx/esm/api'; 7 | import dotenv from 'dotenv'; 8 | 9 | dotenv.config(); 10 | consola.wrapAll(); 11 | sourceMap.install(); 12 | console.log(process.cwd()); 13 | tsx.register(); 14 | 15 | const debug = process.env.DEBUG === 'true'; 16 | 17 | // In dev mode, always show stack traces 18 | settings.debug = true; 19 | settings.performanceEnabled = true; 20 | 21 | // Set logging level 22 | consola.level = debug ? 5 : 3; 23 | 24 | const originalEmit = process.emit; 25 | process.emit = function (name, data, ...args) { 26 | if (name === `warning` && typeof data === `object`) { 27 | if (data.name === 'ExperimentalWarning') { 28 | return false; 29 | } 30 | 31 | if (data.name === 'DeprecationWarning' && data.message.includes('punycode')) { 32 | return false; 33 | } 34 | } 35 | 36 | return originalEmit.apply(process, arguments); 37 | }; 38 | 39 | // Start the CLI 40 | await execute({ dir: import.meta.url }); 41 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderRuntime.ts: -------------------------------------------------------------------------------- 1 | import { getMd5Hash } from '@nzyme/crypto-utils'; 2 | 3 | import { createRenderContext } from './renderContext.js'; 4 | import { renderModule } from './renderModule.js'; 5 | import { renderVariable } from './renderVariable.js'; 6 | import type { AgentRuntime } from '../agent/agentTypes.js'; 7 | import type { AgentDefinition } from '../agent/defineAgent.js'; 8 | 9 | /** 10 | * Render a runtime as TypeScript code. 11 | * @param agent - Agent to render. 12 | * @returns Rendered agent runtime. 13 | */ 14 | export function renderRuntime(agent: AgentDefinition): AgentRuntime { 15 | const ctx = createRenderContext(); 16 | 17 | if (agent.tools) { 18 | renderModule(agent.tools, ctx); 19 | } 20 | 21 | if (agent.output) { 22 | renderVariable({ 23 | name: 'result', 24 | type: agent.output, 25 | description: 'You must put the result of the task here.', 26 | ctx, 27 | }); 28 | } 29 | 30 | const code = ctx.code; 31 | const hash = `${getMd5Hash(code)}:${code.length}`; 32 | 33 | return { 34 | code, 35 | hash, 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /packages/llamaindex/src/fromLlamaIndexModel.ts: -------------------------------------------------------------------------------- 1 | import type { LLM, MessageContent } from '@llamaindex/core/llms'; 2 | 3 | import type { LanguageModel, LanguageModelInvokeParams } from '@agentscript-ai/provider'; 4 | 5 | /** 6 | * 7 | */ 8 | export function fromLlamaIndexModel(model: LLM): LanguageModel { 9 | return { 10 | name: model.metadata.model, 11 | invoke: async (params: LanguageModelInvokeParams) => { 12 | const response = await model.chat({ 13 | messages: params.messages, 14 | }); 15 | 16 | return { 17 | role: 'assistant', 18 | content: parseMessageContent(response.message.content), 19 | }; 20 | }, 21 | }; 22 | } 23 | 24 | function parseMessageContent(content: MessageContent): string { 25 | if (typeof content === 'string') { 26 | return content; 27 | } 28 | 29 | let text = ''; 30 | 31 | for (const detail of content) { 32 | if (detail.type !== 'text') { 33 | throw new Error(`Unsupported message content type: ${detail.type}`); 34 | } 35 | 36 | text += detail.text; 37 | } 38 | 39 | return text; 40 | } 41 | -------------------------------------------------------------------------------- /legacy/agent/src/LangModelProvider.ts: -------------------------------------------------------------------------------- 1 | import { BaseCallbackHandler } from '@langchain/core/callbacks/base'; 2 | import type { Serialized } from '@langchain/core/load/serializable'; 3 | import { ChatOpenAI } from '@langchain/openai'; 4 | 5 | import { EnvVariables, Logger } from '@agentscript-ai/core'; 6 | import { defineService } from '@nzyme/ioc'; 7 | 8 | export const LangModelProvider = defineService({ 9 | name: 'LangModelProvider', 10 | setup({ inject }) { 11 | const logger = inject(Logger); 12 | const env = inject(EnvVariables); 13 | 14 | return () => { 15 | return new ChatOpenAI({ 16 | openAIApiKey: env.OPENAI_API_KEY, 17 | modelName: 'gpt-4o-mini', 18 | callbacks: [new LoggerCallbackHandler(logger)], 19 | }); 20 | }; 21 | }, 22 | }); 23 | 24 | class LoggerCallbackHandler extends BaseCallbackHandler { 25 | constructor(private readonly logger: Logger) { 26 | super(); 27 | } 28 | 29 | readonly name = 'LoggerCallbackHandler'; 30 | 31 | override handleLLMStart(llm: Serialized, prompts: string[]) { 32 | this.logger.debug('LLM Start %O', { prompts }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/serializer/src/heapTypes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Heap. Allows for recursive serialization of values. 3 | */ 4 | export type Heap = HeapValue[]; 5 | 6 | /** 7 | * Heap value. 8 | */ 9 | export type HeapValue = 10 | | HeapPrimitive 11 | | HeapArray 12 | | HeapObject 13 | | HeapBigInt 14 | | HeapDate 15 | | HeapSymbol 16 | | HeapSet 17 | | HeapRegex; 18 | 19 | /** 20 | * Primitive serialized. 21 | */ 22 | export type HeapPrimitive = boolean | string | number | null; 23 | 24 | /** 25 | * Array serialized. 26 | */ 27 | export type HeapArray = ['a', ...values: number[]]; 28 | 29 | /** 30 | * Object serialized. 31 | */ 32 | export type HeapObject = ['o', ...values: (string | number)[]]; 33 | 34 | /** 35 | * BigInt serialized. 36 | */ 37 | export type HeapBigInt = ['bi', value: string]; 38 | 39 | /** 40 | * Date serialized. 41 | */ 42 | export type HeapDate = ['d', value: string]; 43 | 44 | /** 45 | * Symbol serialized. 46 | */ 47 | export type HeapSymbol = ['sm', value: string | undefined] | ['sm']; 48 | 49 | /** 50 | * Set serialized. 51 | */ 52 | export type HeapSet = ['st', ...values: number[]]; 53 | 54 | /** 55 | * Regex serialized. 56 | */ 57 | export type HeapRegex = ['r', value: string, flags: string]; 58 | -------------------------------------------------------------------------------- /packages/core/src/runtime/utils/getChild.ts: -------------------------------------------------------------------------------- 1 | import type { AstNode } from '@agentscript-ai/parser'; 2 | 3 | /** 4 | * Get the child of a node. 5 | * @param node - Node to get the child from. 6 | * @param index - Index of the child to get. 7 | * @returns Child of the node. 8 | */ 9 | export function getChild(node: AstNode, index: number): AstNode | undefined { 10 | switch (node.type) { 11 | case 'var': 12 | return index === 0 ? node.value : undefined; 13 | 14 | case 'assign': 15 | switch (index) { 16 | case 0: 17 | return node.right; 18 | case 1: 19 | return node.left; 20 | default: 21 | return undefined; 22 | } 23 | 24 | case 'array': 25 | return node.items[index]?.type === 'spread' 26 | ? node.items[index].value 27 | : node.items[index]; 28 | 29 | case 'object': 30 | return node.props[index]?.value; 31 | 32 | case 'call': 33 | return node.args?.[index]; 34 | 35 | case 'new': 36 | return node.args?.[index]; 37 | 38 | default: 39 | return undefined; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/provider/src/LanguageModel.ts: -------------------------------------------------------------------------------- 1 | import { defineInterface } from '@nzyme/ioc'; 2 | 3 | /** 4 | * Parameters for {@link LanguageModel.invoke}. 5 | */ 6 | export interface LanguageModelInvokeParams { 7 | /** 8 | * System prompt to use. 9 | * Can be passed as array of strings to allow for multi-line system prompts. 10 | */ 11 | systemPrompt?: string | string[]; 12 | /** 13 | * Messages to use 14 | */ 15 | messages: LanguageModelMessage[]; 16 | } 17 | 18 | /** 19 | * LLM message. 20 | */ 21 | export interface LanguageModelMessage { 22 | /** 23 | * Role of the message. 24 | */ 25 | role: 'user' | 'assistant'; 26 | /** 27 | * Content of the message. 28 | */ 29 | content: string; 30 | } 31 | 32 | /** 33 | * Language model. 34 | */ 35 | export interface LanguageModel { 36 | /** 37 | * Name of the language model 38 | */ 39 | name: string; 40 | /** 41 | * Invoke the language model. 42 | * @returns Response from the language model. 43 | */ 44 | invoke(params: LanguageModelInvokeParams): Promise; 45 | } 46 | 47 | /** 48 | * Language model injectable. 49 | */ 50 | export const LanguageModel = defineInterface({ 51 | name: 'LanguageModel', 52 | }); 53 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderModule.ts: -------------------------------------------------------------------------------- 1 | import type { RenderContext } from './renderContext.js'; 2 | import { renderTool } from './renderTool.js'; 3 | import type { RuntimeModule } from '../agent/defineAgent.js'; 4 | import { isTool } from '../tools/defineTool.js'; 5 | 6 | const VALID_NAME_REGEX = /^[a-zA-Z_][a-zA-Z_0-9]*$/; 7 | 8 | /** 9 | * Render a runtime module as TypeScript code. 10 | * @param module - Runtime module to render. 11 | * @param ctx - Render context. 12 | */ 13 | export function renderModule(module: RuntimeModule, ctx: RenderContext) { 14 | for (const [name, value] of Object.entries(module)) { 15 | if (!VALID_NAME_REGEX.test(name)) { 16 | throw new Error( 17 | `Invalid name: ${name}. Names must start with a letter or underscore and can only contain letters, numbers, and underscores.`, 18 | ); 19 | } 20 | 21 | if (isTool(value)) { 22 | renderTool({ name, tool: value, ctx }); 23 | } else if (typeof value === 'object' && value !== null) { 24 | ctx.addLine(); 25 | ctx.addLine(`namespace ${name} {`); 26 | renderModule(value, ctx.createChild(name)); 27 | ctx.addLine('}'); 28 | } else { 29 | throw new Error(`Invalid value: ${String(value)} for ${name}`); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | *.lcov 22 | 23 | # Dependency directories 24 | node_modules/ 25 | 26 | # TypeScript cache 27 | *.tsbuildinfo 28 | 29 | # Optional eslint cache 30 | .eslintcache 31 | 32 | # Optional stylelint cache 33 | .stylelintcache 34 | 35 | # Rollup cache 36 | .rollup.cache 37 | 38 | # Optional REPL history 39 | .node_repl_history 40 | 41 | # Output of 'npm pack' 42 | *.tgz 43 | 44 | # Yarn Integrity file 45 | .yarn-integrity 46 | 47 | # dotenv environment variable files 48 | .env 49 | .env.dev.local 50 | .env.test.local 51 | .env.prod.local 52 | .env.local 53 | 54 | 55 | # yarn v2 56 | .yarn/cache 57 | .yarn/unplugged 58 | .yarn/build-state.yml 59 | .yarn/install-state.gz 60 | .pnp.* 61 | 62 | # macOS 63 | .DS_Store 64 | 65 | dist 66 | dist-cjs 67 | .nx 68 | .turbo 69 | .nzyme 70 | 71 | packages/**/README.md 72 | packages/**/LICENSE 73 | 74 | # not needed for lib and messes up monorepos 75 | yarn.lock 76 | 77 | # these are generated by nzyme 78 | tsconfig.json 79 | tsconfig.cjs.json -------------------------------------------------------------------------------- /packages/core/src/runtime/utils/findFrameByTrace.ts: -------------------------------------------------------------------------------- 1 | import type { AstNode } from '@agentscript-ai/parser'; 2 | 3 | import type { Agent } from '../../agent/agentTypes.js'; 4 | import { RuntimeError } from '../RuntimeError.js'; 5 | import type { StackFrame } from '../runtimeTypes.js'; 6 | import { getChild } from './getChild.js'; 7 | 8 | /** 9 | * Find a frame by trace. 10 | * @param agent - Agent to find the frame in. 11 | * @param trace - Trace to find the frame by. 12 | * @returns Frame found. 13 | */ 14 | export function findFrameByTrace(agent: Agent, trace: string) { 15 | const path = trace.split(':').map(Number); 16 | if (path.length < 2) { 17 | throw new RuntimeError(`Invalid trace: ${trace}`); 18 | } 19 | 20 | if (path[0] !== 0) { 21 | throw new RuntimeError(`Invalid trace: ${trace}`); 22 | } 23 | 24 | let index = path[1]!; 25 | let node: AstNode | undefined = agent.script.ast[index]; 26 | let frame: StackFrame | undefined | null = agent.root.children?.[index]; 27 | 28 | for (let i = 2; i < path.length; i++) { 29 | if (!node) { 30 | throw new RuntimeError(`Node not found at index for trace ${trace}`); 31 | } 32 | 33 | index = path[i]!; 34 | node = getChild(node, index); 35 | frame = frame?.children?.[index]; 36 | } 37 | 38 | return { 39 | node, 40 | frame, 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /legacy/database/src/schema/knowledge.ts: -------------------------------------------------------------------------------- 1 | import { 2 | bigint, 3 | bigserial, 4 | index, 5 | integer, 6 | jsonb, 7 | pgEnum, 8 | pgTable, 9 | text, 10 | timestamp, 11 | uniqueIndex, 12 | vector, 13 | } from 'drizzle-orm/pg-core'; 14 | 15 | import { KnowledgeType } from '@agentscript-ai/core'; 16 | 17 | export const knowledgeType = pgEnum('knowledge_type', KnowledgeType); 18 | 19 | export const knowledge = pgTable( 20 | 'knowledge', 21 | { 22 | id: bigserial('id', { mode: 'bigint' }).primaryKey(), 23 | type: knowledgeType('type').notNull(), 24 | tenantId: bigint('tenant_id', { mode: 'bigint' }).notNull(), 25 | externalId: text('external_id').notNull(), 26 | chunk: integer('chunk').notNull(), 27 | title: text('title'), 28 | url: text('url').notNull(), 29 | content: text('content').notNull(), 30 | vector: vector('vector', { dimensions: 1536 }), 31 | metadata: jsonb('metadata'), 32 | updatedAt: timestamp('updated_at').notNull(), 33 | syncedAt: timestamp('synced_at').notNull(), 34 | }, 35 | table => [ 36 | uniqueIndex('externalIdIndex').on( 37 | table.tenantId, 38 | table.type, 39 | table.externalId, 40 | table.chunk, 41 | ), 42 | index('vectorIndex').using('hnsw', table.vector.op('vector_cosine_ops')), 43 | ], 44 | ); 45 | -------------------------------------------------------------------------------- /.github/workflows/check-commit.yml: -------------------------------------------------------------------------------- 1 | name: Check commit 2 | on: 3 | push: 4 | branches: [main, release] 5 | schedule: 6 | - cron: '0 10 * * *' 7 | workflow_dispatch: 8 | 9 | permissions: 10 | contents: write 11 | 12 | jobs: 13 | check-commit: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: latest 20 | 21 | - run: yarn install 22 | env: 23 | YARN_ENABLE_IMMUTABLE_INSTALLS: false 24 | - run: yarn monorepo 25 | - run: yarn update:deps 26 | 27 | - name: Commit nzyme updates 28 | run: | 29 | if git diff --exit-code; then 30 | echo "No changes to commit." 31 | else 32 | git config --local user.email "actions@github.com" 33 | git config --local user.name "Github Actions" 34 | git commit -a -m "chore: update nzyme packages" 35 | git push 36 | fi 37 | 38 | - run: yarn codegen 39 | - name: Commit codegen updates 40 | run: | 41 | if git diff --exit-code; then 42 | echo "No changes to commit." 43 | else 44 | git config --local user.email "actions@github.com" 45 | git config --local user.name "Github Actions" 46 | git commit -a -m "chore: execute codegen" 47 | git push 48 | fi 49 | 50 | - run: yarn build 51 | - run: yarn test 52 | - run: yarn smoke 53 | -------------------------------------------------------------------------------- /packages/provider/src/normalizeModel.ts: -------------------------------------------------------------------------------- 1 | import { defineInterface } from '@nzyme/ioc'; 2 | 3 | import type { LangChainModel } from './LangChainModel.js'; 4 | import { isLangChainModel, normalizeLangChainModel } from './LangChainModel.js'; 5 | import type { LanguageModel } from './LanguageModel.js'; 6 | import type { VercelModel } from './VercelModel.js'; 7 | import { isVercelModel, normalizeVercelModel } from './VercelModel.js'; 8 | 9 | /** 10 | * Language model input. 11 | * You can pass any language model from Vercel AI SDK or LangChain. 12 | */ 13 | export type LanguageModelInput = VercelModel | LangChainModel | LanguageModel; 14 | 15 | /** 16 | * Language model input injectable. 17 | */ 18 | export const LanguageModelInput = defineInterface({ 19 | name: 'LanguageModelInput', 20 | }); 21 | 22 | /** 23 | * Normalizes a language model. 24 | * @param model - Language model to normalize. 25 | * @returns Normalized language model. 26 | */ 27 | export function normalizeModel(model: LanguageModelInput): LanguageModel { 28 | if (isVercelModel(model)) { 29 | return normalizeVercelModel(model); 30 | } 31 | 32 | if (isLangChainModel(model)) { 33 | return normalizeLangChainModel(model); 34 | } 35 | 36 | if (isNativeModel(model)) { 37 | return model; 38 | } 39 | 40 | throw new Error('Invalid model'); 41 | } 42 | 43 | function isNativeModel(model: LanguageModelInput): model is LanguageModel { 44 | return typeof model === 'object' && 'invoke' in model && model.name !== undefined; 45 | } 46 | -------------------------------------------------------------------------------- /packages/provider/src/normalizeModel.test.ts: -------------------------------------------------------------------------------- 1 | import { openai } from '@ai-sdk/openai'; 2 | import { ChatOpenAI } from '@langchain/openai'; 3 | import { expect, test } from 'vitest'; 4 | 5 | import { isLangChainModel } from './LangChainModel.js'; 6 | import type { LanguageModel } from './LanguageModel.js'; 7 | import { isVercelModel } from './VercelModel.js'; 8 | import { normalizeModel } from './normalizeModel.js'; 9 | 10 | test('normalize vercel model', () => { 11 | const model = openai('gpt-4o'); 12 | const normalized = normalizeModel(model); 13 | 14 | expect(normalized.name).toBe('gpt-4o'); 15 | expect(isVercelModel(normalized)).toBe(false); 16 | expect(isLangChainModel(normalized)).toBe(false); 17 | }); 18 | 19 | test('normalize langchain model', () => { 20 | const model = new ChatOpenAI({ model: 'gpt-4o' }); 21 | const normalized = normalizeModel(model); 22 | 23 | expect(normalized.name).toBe('gpt-4o'); 24 | expect(isVercelModel(normalized)).toBe(false); 25 | expect(isLangChainModel(normalized)).toBe(false); 26 | }); 27 | 28 | test('normalize native model', () => { 29 | const model: LanguageModel = { 30 | name: 'claude-3-5-sonnet-latest', 31 | invoke: () => 32 | Promise.resolve({ 33 | role: 'assistant', 34 | content: 'test', 35 | }), 36 | }; 37 | const normalized = normalizeModel(model); 38 | 39 | expect(normalized).toBe(model); 40 | expect(isVercelModel(normalized)).toBe(false); 41 | expect(isLangChainModel(normalized)).toBe(false); 42 | }); 43 | -------------------------------------------------------------------------------- /packages/linear/src/types/IssueFilter.ts: -------------------------------------------------------------------------------- 1 | import * as s from '@agentscript-ai/schema'; 2 | 3 | interface IssueFilterOptions { 4 | statuses: string[]; 5 | } 6 | 7 | /** 8 | * Create a filter for issues. 9 | * @param options - The options for the filter. 10 | * @returns The filter. 11 | */ 12 | export function createIssueFilter(options: IssueFilterOptions) { 13 | return s.object({ 14 | props: { 15 | status: s.array({ 16 | of: s.enum(options.statuses), 17 | optional: true, 18 | description: 'Filter issues by status.', 19 | }), 20 | createdAt: s.extend(DateComparator, { 21 | optional: true, 22 | description: 'Filter issues by creation date.', 23 | }), 24 | updatedAt: s.extend(DateComparator, { 25 | optional: true, 26 | description: 'Filter issues by last updated date.', 27 | }), 28 | }, 29 | }); 30 | } 31 | 32 | const DateComparator = s.object({ 33 | props: { 34 | gt: s.string({ 35 | optional: true, 36 | description: 'Greater than', 37 | }), 38 | gte: s.string({ 39 | optional: true, 40 | description: 'Greater than or equal to', 41 | }), 42 | lt: s.string({ 43 | optional: true, 44 | description: 'Less than', 45 | }), 46 | lte: s.string({ 47 | optional: true, 48 | description: 'Less than or equal to', 49 | }), 50 | }, 51 | }); 52 | -------------------------------------------------------------------------------- /legacy/core/src/models/AgentEvent.ts: -------------------------------------------------------------------------------- 1 | import * as z from 'zod'; 2 | 3 | import { ChatMessageInfo } from './ChatMessage.js'; 4 | 5 | export type AgentEventBase = z.infer; 6 | export const AgentEventBase = z.object({ 7 | type: z.string(), 8 | uid: z.string(), 9 | timestamp: z.date(), 10 | message: ChatMessageInfo.optional(), 11 | }); 12 | 13 | export type HumanMessage = z.infer; 14 | export const HumanMessage = AgentEventBase.extend({ 15 | type: z.literal('HUMAN_MESSAGE'), 16 | content: z.string(), 17 | message: ChatMessageInfo, 18 | }); 19 | 20 | export type AgentMessage = z.infer; 21 | export const AgentMessage = AgentEventBase.extend({ 22 | type: z.literal('AGENT_MESSAGE'), 23 | content: z.string(), 24 | }); 25 | 26 | export type ToolCall = z.infer; 27 | export const ToolCall = AgentEventBase.extend({ 28 | type: z.literal('TOOL_CALL'), 29 | tool: z.string(), 30 | params: z.record(z.string(), z.unknown()), 31 | message: z.undefined().optional(), 32 | }); 33 | 34 | export type ToolEvent = z.infer; 35 | export const ToolEvent = AgentEventBase.extend({ 36 | type: z.literal('TOOL_EVENT'), 37 | content: z.string().optional(), 38 | data: z.unknown().nullish(), 39 | callId: z.string(), 40 | message: ChatMessageInfo.optional(), 41 | }); 42 | 43 | export type AgentEvent = z.infer; 44 | export const AgentEvent = z.discriminatedUnion('type', [ 45 | // 46 | HumanMessage, 47 | AgentMessage, 48 | ToolCall, 49 | ToolEvent, 50 | ]); 51 | -------------------------------------------------------------------------------- /packages/core/src/runtime/tests/toolsState.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import { parseScript } from '@agentscript-ai/parser'; 4 | import * as s from '@agentscript-ai/schema'; 5 | 6 | import { createAgent } from '../../agent/createAgent.js'; 7 | import { defineTool } from '../../tools/defineTool.js'; 8 | import { executeAgent } from '../executeAgent.js'; 9 | import { agentResult, completedFrame, rootFrame } from './testUtils.js'; 10 | 11 | test('simple tool state', async () => { 12 | const tool = defineTool({ 13 | description: 'A tool', 14 | input: { 15 | foo: s.string(), 16 | }, 17 | state: { 18 | bar: s.string(), 19 | }, 20 | handler: ({ input, state }) => { 21 | state.bar = input.foo + 'bar'; 22 | }, 23 | }); 24 | 25 | const tools = { 26 | tool, 27 | }; 28 | 29 | const script = parseScript([ 30 | // 31 | 'tool("foo");', 32 | ]); 33 | 34 | const agent = createAgent({ tools, script }); 35 | 36 | const result = await executeAgent({ agent }); 37 | const expectedStack = rootFrame({ 38 | status: 'done', 39 | children: [ 40 | completedFrame({ 41 | node: 'call', 42 | value: undefined, 43 | state: { 44 | bar: 'foobar', 45 | }, 46 | }), 47 | ], 48 | }); 49 | 50 | expect(result).toEqual(agentResult({ ticks: 0 })); 51 | expect(agent.root).toEqual(expectedStack); 52 | expect(agent.status).toBe('done'); 53 | }); 54 | -------------------------------------------------------------------------------- /packages/core/src/agent/createAgent.ts: -------------------------------------------------------------------------------- 1 | import type { EmptyObject } from '@nzyme/types'; 2 | 3 | import type { Script } from '@agentscript-ai/parser'; 4 | 5 | import type { Agent } from './agentTypes.js'; 6 | import { createAgentInternal } from './createAgentInternal.js'; 7 | import type { 8 | AgentDefinition, 9 | AgentInputBase, 10 | AgentOutputBase, 11 | AgentTools, 12 | } from './defineAgent.js'; 13 | import { renderRuntime } from '../modules/renderRuntime.js'; 14 | 15 | /** 16 | * Parameters for {@link createAgent}. 17 | */ 18 | export type CreateAgentOptions< 19 | TTools extends AgentTools, 20 | TInput extends AgentInputBase, 21 | TOutput extends AgentOutputBase, 22 | > = AgentDefinition & { 23 | /** 24 | * ID of the agent. 25 | * If not provided, it will be generated as a UUID. 26 | */ 27 | readonly id?: string; 28 | /** 29 | * AgentScript script to execute. 30 | */ 31 | readonly script: Script; 32 | /** 33 | * Plan for the agent. 34 | */ 35 | readonly plan?: string; 36 | /** 37 | * Prompt used to create the agent. 38 | */ 39 | readonly prompt?: string; 40 | }; 41 | 42 | /** 43 | * Create a new agent. 44 | * @param options - Agent options. 45 | * @returns New agent. 46 | */ 47 | export function createAgent< 48 | TTools extends AgentTools, 49 | TInput extends AgentInputBase = EmptyObject, 50 | TOutput extends AgentOutputBase = undefined, 51 | >(options: CreateAgentOptions) { 52 | return createAgentInternal({ 53 | ...options, 54 | runtime: renderRuntime(options), 55 | }) as Agent; 56 | } 57 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderVariable.ts: -------------------------------------------------------------------------------- 1 | import type * as s from '@agentscript-ai/schema'; 2 | import { normalizeText } from '@agentscript-ai/utils'; 3 | 4 | import { renderComment } from './renderComment.js'; 5 | import type { RenderContext } from './renderContext.js'; 6 | import { renderType } from './renderType.js'; 7 | 8 | /** 9 | * Parameters for {@link renderVariable}. 10 | */ 11 | export interface RenderVariableParams { 12 | /** 13 | * Render context. 14 | */ 15 | ctx: RenderContext; 16 | /** 17 | * Name of the variable. 18 | */ 19 | name: string; 20 | /** 21 | * Type of the variable. 22 | */ 23 | type: s.Schema; 24 | /** 25 | * Description of the variable. 26 | */ 27 | description?: string | string[]; 28 | /** 29 | * Whether the variable is constant. 30 | */ 31 | const?: boolean; 32 | } 33 | 34 | /** 35 | * Render a variable as TypeScript code. 36 | * @param params - Parameters for {@link renderVariable}. 37 | */ 38 | export function renderVariable(params: RenderVariableParams) { 39 | const { name, type, const: isConst = false, ctx } = params; 40 | 41 | const description: string[] = []; 42 | 43 | if (params.description) { 44 | description.push(...normalizeText(params.description)); 45 | } 46 | 47 | if (type.description) { 48 | description.push(...normalizeText(type.description)); 49 | } 50 | 51 | const typeName = renderType({ schema: type, ctx }); 52 | const comment = renderComment(description, ctx); 53 | 54 | ctx.addLine(); 55 | 56 | if (comment) { 57 | ctx.addLine(comment); 58 | } 59 | 60 | ctx.addLine(`${isConst ? 'const' : 'let'} ${name}: ${typeName}`); 61 | } 62 | -------------------------------------------------------------------------------- /packages/core/src/runtime/runtimeController.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | export interface RuntimeController { 5 | /** 6 | * 7 | */ 8 | tick(count?: number): void; 9 | /** 10 | * 11 | */ 12 | continue(): boolean; 13 | /** 14 | * 15 | */ 16 | ticks: number; 17 | } 18 | 19 | /** 20 | * 21 | */ 22 | export interface RuntimeControllerOptions { 23 | /** 24 | * 25 | */ 26 | ticks?: number; 27 | /** 28 | * 29 | */ 30 | timeout?: number | Date; 31 | /** 32 | * 33 | */ 34 | until?: () => boolean; 35 | } 36 | 37 | const TICK_MULTIPLIER = 1000; 38 | 39 | /** 40 | * 41 | */ 42 | export function createRuntimeControler(options: RuntimeControllerOptions): RuntimeController { 43 | const { timeout, until = () => false } = options; 44 | 45 | const maxTicks = options.ticks ? options.ticks * TICK_MULTIPLIER : Infinity; 46 | const timeoutDate = 47 | timeout != null 48 | ? typeof timeout === 'number' 49 | ? Date.now() + timeout 50 | : timeout.getTime() 51 | : null; 52 | 53 | let ticks = 0; 54 | 55 | return { 56 | tick(count = 1) { 57 | ticks += count * TICK_MULTIPLIER; 58 | }, 59 | continue() { 60 | if (ticks >= maxTicks) { 61 | return false; 62 | } 63 | 64 | if (timeoutDate && Date.now() > timeoutDate) { 65 | return false; 66 | } 67 | 68 | if (until()) { 69 | return false; 70 | } 71 | 72 | return true; 73 | }, 74 | get ticks() { 75 | return Math.round(ticks) / TICK_MULTIPLIER; 76 | }, 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /legacy/cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/cli", 3 | "repository": "https://github.com/kedrzu/agentscript.git", 4 | "author": "Michał Kędrzyński ", 5 | "version": "1.0.0", 6 | "type": "module", 7 | "bin": { 8 | "agentscript": "./bin/cli.js" 9 | }, 10 | "scripts": { 11 | "eslint": "eslint . --fix --cache", 12 | "build": "tsc --build" 13 | }, 14 | "dependencies": { 15 | "@agentscript-ai/notion": "*", 16 | "@nzyme/ioc": "*", 17 | "@nzyme/logging": "*", 18 | "@nzyme/node-utils": "*", 19 | "@nzyme/project-utils": "*", 20 | "@nzyme/utils": "*", 21 | "@oclif/core": "^4.0.33", 22 | "@oclif/plugin-help": "^6.2.18", 23 | "@oclif/plugin-version": "^2.2.16", 24 | "chalk": "^5.3.0", 25 | "consola": "^3.2.3", 26 | "dotenv": "^16.4.5", 27 | "source-map-support": "^0.5.21", 28 | "ts-node": "^10.9.2", 29 | "tsx": "^4.19.2" 30 | }, 31 | "devDependencies": { 32 | "@agentscript-ai/eslint": "*", 33 | "@agentscript-ai/tsconfig": "*", 34 | "@types/node": "^22.7.7", 35 | "@types/source-map-support": "^0.5.10", 36 | "oclif": "^4.15.28" 37 | }, 38 | "files": [ 39 | "/bin/cli.js", 40 | "/dist" 41 | ], 42 | "oclif": { 43 | "bin": "agentscript", 44 | "commands": { 45 | "strategy": "explicit", 46 | "target": "./dist/commands.js" 47 | }, 48 | "plugins": [ 49 | "@oclif/plugin-help", 50 | "@oclif/plugin-version" 51 | ], 52 | "topicSeparator": " " 53 | }, 54 | "depcheck": { 55 | "ignoreDeps": [ 56 | "@oclif/plugin-*" 57 | ] 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/core/src/agent/inferAgent.ts: -------------------------------------------------------------------------------- 1 | import type { EmptyObject } from '@nzyme/types'; 2 | 3 | import type { LanguageModelInput } from '@agentscript-ai/provider'; 4 | 5 | import type { Agent } from './agentTypes.js'; 6 | import type { 7 | AgentDefinition, 8 | AgentInputBase, 9 | AgentOutputBase, 10 | AgentTools, 11 | } from './defineAgent.js'; 12 | import { inferAgentInternal } from './inferAgentInternal.js'; 13 | 14 | /** 15 | * Parameters for {@link inferAgent}. 16 | */ 17 | export interface InferAgentParams< 18 | TTools extends AgentTools, 19 | TInput extends AgentInputBase, 20 | TOutput extends AgentOutputBase, 21 | > extends AgentDefinition { 22 | /** 23 | * ID of the agent. 24 | * If not provided, it will be generated as a UUID. 25 | */ 26 | id?: string; 27 | /** 28 | * Language model to use. 29 | */ 30 | model: LanguageModelInput; 31 | /** 32 | * Prompt to infer the agent from. 33 | */ 34 | prompt: string | string[]; 35 | /** 36 | * System prompt to use. 37 | */ 38 | systemPrompt?: string | string[]; 39 | } 40 | 41 | /** 42 | * Infer an agent from a given prompt. 43 | * @param params - Parameters for {@link inferAgent}. 44 | * @returns Inferred agent. 45 | */ 46 | export async function inferAgent< 47 | TTools extends AgentTools, 48 | TInput extends AgentInputBase = EmptyObject, 49 | TOutput extends AgentOutputBase = undefined, 50 | >(params: InferAgentParams) { 51 | const agent = await inferAgentInternal({ 52 | def: params, 53 | id: params.id, 54 | model: params.model, 55 | systemPrompt: params.systemPrompt, 56 | prompt: params.prompt, 57 | }); 58 | 59 | return agent as Agent; 60 | } 61 | -------------------------------------------------------------------------------- /packages/core/src/meta/defineMetadata.ts: -------------------------------------------------------------------------------- 1 | import type { Agent } from '../agent/agentTypes.js'; 2 | 3 | /** 4 | * Metadata options 5 | */ 6 | export interface MetadataOptions { 7 | /** 8 | * The name of the metadata 9 | */ 10 | name: string; 11 | } 12 | 13 | /** 14 | * Metadata is a record of arbitrary data. 15 | */ 16 | export type Metadata = Record; 17 | 18 | /** 19 | * Metadata definition 20 | */ 21 | export interface MetadataDefinition { 22 | /** 23 | * Get metadata value from an agent 24 | */ 25 | (agent: Agent): T | undefined; 26 | 27 | /** 28 | * Get metadata value from a wrapper 29 | */ 30 | (wrapper: MetadataWrapper): T | undefined; 31 | 32 | /** 33 | * Set metadata value on an agent 34 | */ 35 | (agent: Agent, value: T): void; 36 | 37 | /** 38 | * Set metadata value on a wrapper 39 | */ 40 | (wrapper: MetadataWrapper, value: T): void; 41 | } 42 | 43 | /** 44 | * Generic metadata wrapper. 45 | */ 46 | export interface MetadataWrapper { 47 | /** 48 | * Metadata. 49 | */ 50 | metadata: Metadata; 51 | } 52 | 53 | /** 54 | * Define agent metadata. 55 | * Can be used to store arbitrary data within an agent. 56 | * @param options - The metadata options 57 | * @returns The metadata 58 | */ 59 | export function defineMetadata(options: MetadataOptions): MetadataDefinition { 60 | const wrapper: Record> = { 61 | [options.name]: function (wrapper: MetadataWrapper, value?: T) { 62 | if (value === undefined) { 63 | return wrapper.metadata[options.name] as T | undefined; 64 | } 65 | 66 | wrapper.metadata[options.name] = value; 67 | }, 68 | }; 69 | 70 | return wrapper[options.name]!; 71 | } 72 | -------------------------------------------------------------------------------- /packages/tools/src/summarizeData.ts: -------------------------------------------------------------------------------- 1 | import { defineService } from '@nzyme/ioc'; 2 | 3 | import { defineTool } from '@agentscript-ai/core'; 4 | import { LanguageModelInput, normalizeModel } from '@agentscript-ai/provider'; 5 | import * as s from '@agentscript-ai/schema'; 6 | import { getCurrentDatePrompt } from '@agentscript-ai/utils'; 7 | 8 | /** 9 | * Tool to summarize any data. 10 | */ 11 | export const summarizeData = defineService({ 12 | name: 'summarizeData', 13 | deps: { 14 | model: LanguageModelInput, 15 | }, 16 | setup({ model }) { 17 | return defineTool({ 18 | description: 'Summarize any data', 19 | input: s.object({ 20 | props: { 21 | data: s.unknown({ 22 | description: 'The data to summarize. Can be in any format.', 23 | }), 24 | prompt: s.string({ 25 | description: [ 26 | 'The prompt to use to summarize the data.', 27 | 'Describe the expected outcome.', 28 | ], 29 | }), 30 | }, 31 | }), 32 | output: s.string(), 33 | async handler({ input: { data, prompt } }) { 34 | const result = await normalizeModel(model).invoke({ 35 | systemPrompt: [ 36 | `Your task is to summarize the following data based on the user prompt:`, 37 | JSON.stringify(data), 38 | getCurrentDatePrompt(), 39 | ], 40 | messages: [{ role: 'user', content: prompt }], 41 | }); 42 | 43 | return result.content; 44 | }, 45 | }); 46 | }, 47 | }); 48 | -------------------------------------------------------------------------------- /legacy/slack/src/SlackUsers.ts: -------------------------------------------------------------------------------- 1 | import type { ChatUser } from '@agentscript-ai/core'; 2 | import { defineService } from '@nzyme/ioc'; 3 | 4 | import { SlackClient } from './SlackClient.js'; 5 | 6 | export const SlackUsers = defineService({ 7 | name: 'SlackUsers', 8 | deps: { 9 | slack: SlackClient, 10 | }, 11 | setup({ slack }) { 12 | const users = new Map(); 13 | let self: Promise | undefined; 14 | 15 | return { 16 | getUser, 17 | getSelfUser, 18 | }; 19 | 20 | async function getUser(id: string) { 21 | let user = users.get(id); 22 | if (user) { 23 | return user; 24 | } 25 | 26 | const response = await slack.users.info({ user: id }); 27 | if (!response.user) { 28 | throw new Error(`User ${id} not found`); 29 | } 30 | 31 | user = { 32 | id: id, 33 | type: response.user.is_bot ? 'BOT' : 'HUMAN', 34 | name: response.user.real_name || response.user.name || id, 35 | email: response.user.profile?.email, 36 | description: response.user.profile?.title || undefined, 37 | }; 38 | 39 | users.set(user.id, user); 40 | 41 | return user; 42 | } 43 | 44 | async function getSelfUser() { 45 | if (self) { 46 | return await self; 47 | } 48 | 49 | const response = await slack.auth.test(); 50 | console.log(response); 51 | if (!response.user_id) { 52 | throw new Error('Failed to get self user'); 53 | } 54 | 55 | self = getUser(response.user_id); 56 | return await self; 57 | } 58 | }, 59 | }); 60 | -------------------------------------------------------------------------------- /legacy/core/src/Chat.ts: -------------------------------------------------------------------------------- 1 | import * as z from 'zod'; 2 | 3 | import { defineInterface } from '@nzyme/ioc'; 4 | 5 | import type { ChatMessageInfo, ChatMessageWithContent } from './models/ChatMessage.js'; 6 | 7 | export interface Chat { 8 | postMessage(params: ChatPostMessageParams): Promise; 9 | updateMessage(params: ChatUpdateMessageParams): Promise; 10 | getChannelType(channelId: string): ChatType; 11 | getMessages(params: ChatGetMessagesParams): Promise; 12 | getUser(userId: string): Promise; 13 | getSelfUser(): Promise; 14 | } 15 | 16 | export interface ChatActionButton { 17 | type: 'button'; 18 | text: string; 19 | action: string; 20 | value: string; 21 | style?: 'primary' | 'danger'; 22 | } 23 | 24 | export interface ChatActionsBlock { 25 | type: 'actions'; 26 | elements: ChatActionButton[]; 27 | } 28 | 29 | export interface ChatDividerBlock { 30 | type: 'divider'; 31 | } 32 | 33 | export type ChatBlock = ChatActionsBlock | ChatDividerBlock; 34 | 35 | export interface ChatPostMessageParams { 36 | channelId: string; 37 | threadId: string; 38 | blocks: (ChatBlock | string)[]; 39 | } 40 | 41 | export interface ChatUpdateMessageParams extends ChatPostMessageParams { 42 | messageId: string; 43 | } 44 | 45 | export interface ChatGetMessagesParams { 46 | channelId: string; 47 | threadId: string; 48 | from?: Date; 49 | } 50 | 51 | export type ChatType = 'DM' | 'CHANNEL'; 52 | 53 | export type ChatUser = z.infer; 54 | export const ChatUser = z.object({ 55 | id: z.string(), 56 | type: z.enum(['HUMAN', 'BOT']), 57 | name: z.string(), 58 | email: z.string().optional(), 59 | description: z.string().optional(), 60 | }); 61 | 62 | export const Chat = defineInterface({ 63 | name: 'Chat', 64 | }); 65 | -------------------------------------------------------------------------------- /packages/anthropic/src/AnthropicModel.ts: -------------------------------------------------------------------------------- 1 | import { Anthropic } from '@anthropic-ai/sdk'; 2 | import type { Injected } from '@nzyme/ioc'; 3 | import { constValue, defineService } from '@nzyme/ioc'; 4 | 5 | import { LanguageModel } from '@agentscript-ai/provider'; 6 | 7 | /** 8 | * Anthropic language model. 9 | */ 10 | export type AnthropicModel = Injected; 11 | 12 | /** 13 | * Anthropic language model. 14 | */ 15 | export const AnthropicModel = defineService({ 16 | name: 'AnthropicModel', 17 | implements: LanguageModel, 18 | deps: { 19 | model: constValue('claude-3-5-sonnet-latest'), 20 | apiKey: constValue(undefined), 21 | maxTokens: constValue(1024), 22 | }, 23 | setup: ({ model, apiKey, maxTokens }) => { 24 | const anthropic = new Anthropic({ apiKey }); 25 | 26 | return { 27 | name: `anthropic-${model}`, 28 | invoke: async params => { 29 | const response = await anthropic.messages.create({ 30 | model, 31 | system: Array.isArray(params.systemPrompt) 32 | ? params.systemPrompt.join('\n') 33 | : params.systemPrompt, 34 | messages: params.messages.map(message => ({ 35 | role: message.role, 36 | content: message.content, 37 | })), 38 | max_tokens: maxTokens, 39 | }); 40 | 41 | const content = response.content 42 | .filter(block => block.type === 'text') 43 | .map(block => block.text) 44 | .join('\n'); 45 | 46 | return { 47 | role: 'assistant', 48 | content, 49 | }; 50 | }, 51 | }; 52 | }, 53 | }); 54 | -------------------------------------------------------------------------------- /packages/utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/utils", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:esm": "tsc --build ./tsconfig.esm.json", 37 | "lint": "eslint . --fix --cache", 38 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 39 | "smoke:cjs": "node tests/smoke.test.cjs", 40 | "smoke:mjs": "node tests/smoke.test.mjs" 41 | }, 42 | "dependencies": { 43 | "@nzyme/utils": "^0.14.0", 44 | "@nzyme/zchema": "^0.14.0" 45 | }, 46 | "devDependencies": { 47 | "@agentscript-ai/eslint": "^0.9.0", 48 | "@agentscript-ai/tsconfig": "^0.9.0", 49 | "@types/node": "^22.14.0", 50 | "eslint": "^9.24.0", 51 | "typescript": "^5.8.3", 52 | "vitest": "^3.1.1" 53 | }, 54 | "publishConfig": { 55 | "access": "public" 56 | }, 57 | "nzyme": { 58 | "cjs": true 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /.github/workflows/release-npm.yml: -------------------------------------------------------------------------------- 1 | name: Release new version 2 | 3 | permissions: 4 | contents: write 5 | 6 | on: 7 | workflow_dispatch: 8 | inputs: 9 | dry_run: 10 | description: 'Dry run the release' 11 | required: false 12 | type: boolean 13 | default: false 14 | jobs: 15 | release: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v4 19 | with: 20 | ref: release 21 | fetch-tags: true 22 | fetch-depth: 0 23 | 24 | - name: Setup Git 25 | run: | 26 | git config --local user.email "actions@github.com" 27 | git config --local user.name "Github Actions" 28 | 29 | - name: Merge main to release 30 | if: github.ref_name == 'main' 31 | id: mergeMain 32 | run: | 33 | git merge --no-ff origin/main -m "chore: release new version" 34 | git push 35 | 36 | - uses: actions/setup-node@v4 37 | with: 38 | node-version: latest 39 | 40 | - run: yarn install 41 | env: 42 | YARN_ENABLE_IMMUTABLE_INSTALLS: false 43 | - run: yarn monorepo 44 | - run: yarn build 45 | - run: yarn test 46 | - run: yarn smoke 47 | 48 | - run: yarn release 49 | if: ${{ inputs.dry_run != true }} 50 | env: 51 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 52 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | 54 | - run: yarn release --dry-run 55 | if: ${{ inputs.dry_run }} 56 | env: 57 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 58 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 59 | 60 | - name: Merge release to main 61 | if: ${{ inputs.dry_run != true }} 62 | run: | 63 | git checkout main 64 | git pull 65 | git merge --no-ff release -m "chore: auto-merge release -> main" 66 | git push 67 | -------------------------------------------------------------------------------- /packages/core/src/inferResult.ts: -------------------------------------------------------------------------------- 1 | import { type LanguageModelInput, normalizeModel } from '@agentscript-ai/provider'; 2 | import { type Schema, coerce } from '@agentscript-ai/schema'; 3 | 4 | import { createRenderContext } from './modules/renderContext.js'; 5 | import { renderType } from './modules/renderType.js'; 6 | 7 | /** 8 | * Parameters for {@link inferResult}. 9 | */ 10 | export type InferResultParams = { 11 | /** 12 | * Language model to use. 13 | */ 14 | model: LanguageModelInput; 15 | 16 | /** 17 | * Prompt to infer the result. 18 | */ 19 | prompt: string; 20 | 21 | /** 22 | * System prompt to use. 23 | */ 24 | systemPrompt?: string; 25 | 26 | /** 27 | * Schema of the result. 28 | */ 29 | result: T; 30 | }; 31 | 32 | /** 33 | * Infer a structured result from a given prompt. 34 | * @param params - Parameters for {@link inferResult}. 35 | * @returns Inferred result. 36 | */ 37 | export async function inferResult(params: InferResultParams) { 38 | const renderContext = createRenderContext(); 39 | const resultType = renderType({ 40 | schema: params.result, 41 | ctx: renderContext, 42 | nameHint: 'Result', 43 | }); 44 | 45 | const systemPrompt = [ 46 | 'Given the following types:', 47 | `\`\`\`typescript\n${renderContext.code}\n\`\`\``, 48 | `Answer strictly in a structured format of the type ${resultType}. Do not include any other text or comments.`, 49 | '', 50 | params.prompt, 51 | ].join('\n'); 52 | 53 | const response = await normalizeModel(params.model).invoke({ 54 | systemPrompt, 55 | messages: [{ role: 'user', content: params.prompt }], 56 | }); 57 | 58 | const json = JSON.parse(response.content) as unknown; 59 | const result = coerce(params.result, json); 60 | 61 | return result; 62 | } 63 | -------------------------------------------------------------------------------- /packages/serializer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/serializer", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "type": "module", 11 | "exports": { 12 | ".": { 13 | "import": { 14 | "types": "./dist/index.d.ts", 15 | "default": "./dist/index.js" 16 | }, 17 | "require": { 18 | "types": "./dist/index.d.ts", 19 | "default": "./dist/index.cjs" 20 | }, 21 | "default": { 22 | "types": "./dist/index.d.ts", 23 | "default": "./dist/index.js" 24 | } 25 | } 26 | }, 27 | "main": "./dist/index.cjs", 28 | "types": "./dist/index.d.ts", 29 | "files": [ 30 | "dist", 31 | "LICENSE", 32 | "README.md" 33 | ], 34 | "scripts": { 35 | "build:esm": "tsc --build ./tsconfig.esm.json", 36 | "lint": "eslint . --fix --cache", 37 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 38 | "smoke:cjs": "node tests/smoke.test.cjs", 39 | "smoke:mjs": "node tests/smoke.test.mjs" 40 | }, 41 | "dependencies": { 42 | "@agentscript-ai/utils": "^0.9.0" 43 | }, 44 | "devDependencies": { 45 | "@agentscript-ai/eslint": "^0.9.0", 46 | "@agentscript-ai/tsconfig": "^0.9.0", 47 | "@nzyme/vitest": "^0.14.0", 48 | "@types/debug": "^4.1.12", 49 | "@types/node": "^22.14.0", 50 | "eslint": "^9.24.0", 51 | "typescript": "^5.8.3", 52 | "vitest": "^3.1.1" 53 | }, 54 | "publishConfig": { 55 | "access": "public" 56 | }, 57 | "nzyme": { 58 | "cjs": true 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/core/src/agent/createAgentInternal.ts: -------------------------------------------------------------------------------- 1 | import { v7 as uuid } from 'uuid'; 2 | 3 | import type { Agent, AgentRuntime, AgentState } from './agentTypes.js'; 4 | import type { CreateAgentOptions } from './createAgent.js'; 5 | import type { AgentInputBase, AgentOutputBase, AgentTools } from './defineAgent.js'; 6 | import { planMetadata, promptMetadata } from '../meta/defaultMetadata.js'; 7 | import type { StackFrame } from '../runtime/runtimeTypes.js'; 8 | 9 | /** 10 | * Parameters for {@link createAgentInternal}. 11 | */ 12 | export type CreateAgentInternalOptions = CreateAgentOptions< 13 | AgentTools, 14 | AgentInputBase, 15 | AgentOutputBase 16 | > & { 17 | /** 18 | * Runtime of the agent. 19 | */ 20 | readonly runtime: AgentRuntime; 21 | 22 | /** 23 | * Chain of agents. 24 | */ 25 | readonly chain?: AgentState[]; 26 | }; 27 | 28 | /** 29 | * Create a new agent. 30 | * @param options - Agent options. 31 | * @returns New agent. 32 | */ 33 | export function createAgentInternal(options: CreateAgentInternalOptions): Agent { 34 | const id = options.id ?? uuid(); 35 | const startedAt = new Date(); 36 | const root: StackFrame = { 37 | trace: '0', 38 | status: 'running', 39 | startedAt, 40 | updatedAt: startedAt, 41 | }; 42 | 43 | if (options.output) { 44 | root.variables = { result: undefined }; 45 | } 46 | 47 | const agent: Agent = { 48 | id, 49 | def: options, 50 | script: options.script, 51 | status: 'running', 52 | metadata: {}, 53 | root, 54 | createdAt: new Date(), 55 | runtime: options.runtime, 56 | chain: options.chain, 57 | }; 58 | 59 | if (options.plan) { 60 | planMetadata(agent, options.plan); 61 | } 62 | 63 | if (options.prompt) { 64 | promptMetadata(agent, options.prompt); 65 | } 66 | 67 | return agent; 68 | } 69 | -------------------------------------------------------------------------------- /packages/parser/src/parseScript.regexes.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import type { Script } from './astTypes.js'; 4 | import { parseScript } from './parseScript.js'; 5 | 6 | test('regex expression', () => { 7 | const code = 'const a = /test/'; 8 | 9 | const script = parseScript(code); 10 | const expected: Script = { 11 | code, 12 | ast: [ 13 | { 14 | type: 'var', 15 | name: 'a', 16 | value: { type: 'regex', value: 'test' }, 17 | }, 18 | ], 19 | }; 20 | 21 | expect(script).toEqual(expected); 22 | }); 23 | 24 | test('regex expression with flags', () => { 25 | const code = 'const a = /test/i'; 26 | 27 | const script = parseScript(code); 28 | const expected: Script = { 29 | code, 30 | ast: [ 31 | { 32 | type: 'var', 33 | name: 'a', 34 | value: { 35 | type: 'regex', 36 | value: 'test', 37 | flags: 'i', 38 | }, 39 | }, 40 | ], 41 | }; 42 | 43 | expect(script).toEqual(expected); 44 | }); 45 | 46 | test('new regex expression', () => { 47 | const code = 'const a = new RegExp("test", "i")'; 48 | const script = parseScript(code); 49 | 50 | const expected: Script = { 51 | code, 52 | ast: [ 53 | { 54 | type: 'var', 55 | name: 'a', 56 | value: { 57 | type: 'new', 58 | func: { type: 'ident', name: 'RegExp' }, 59 | args: [ 60 | { type: 'literal', value: 'test' }, 61 | { type: 'literal', value: 'i' }, 62 | ], 63 | }, 64 | }, 65 | ], 66 | }; 67 | 68 | expect(script).toEqual(expected); 69 | }); 70 | -------------------------------------------------------------------------------- /packages/schema/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/schema", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "module": "./dist/index.js", 30 | "types": "./dist/index.d.ts", 31 | "files": [ 32 | "dist", 33 | "LICENSE", 34 | "README.md" 35 | ], 36 | "scripts": { 37 | "build:esm": "tsc --build ./tsconfig.esm.json", 38 | "lint": "eslint . --fix --cache", 39 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 40 | "smoke:cjs": "node tests/smoke.test.cjs", 41 | "smoke:mjs": "node tests/smoke.test.mjs" 42 | }, 43 | "dependencies": { 44 | "@nzyme/utils": "^0.14.0", 45 | "@nzyme/zchema": "^0.14.0" 46 | }, 47 | "devDependencies": { 48 | "@agentscript-ai/eslint": "^0.9.0", 49 | "@agentscript-ai/tsconfig": "^0.9.0", 50 | "@types/node": "^22.14.0", 51 | "eslint": "^9.24.0", 52 | "typescript": "^5.8.3", 53 | "vitest": "^3.1.1" 54 | }, 55 | "publishConfig": { 56 | "access": "public" 57 | }, 58 | "nzyme": { 59 | "cjs": true 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /legacy/rag/src/KnowledgeRetriever.ts: -------------------------------------------------------------------------------- 1 | import { and, cosineDistance, desc, eq, gte, sql } from 'drizzle-orm'; 2 | 3 | import { Logger, TenantContext } from '@agentscript-ai/core'; 4 | import { DatabaseClient, db } from '@agentscript-ai/database'; 5 | import { defineService } from '@nzyme/ioc'; 6 | 7 | import { EmbeddingModel } from './EmbeddingModel.js'; 8 | 9 | export interface KnowledgeRetrieverParams { 10 | query: string; 11 | limit?: number; 12 | } 13 | 14 | export const KnowledgeRetriever = defineService({ 15 | name: 'KnowledgeRetriever', 16 | deps: { 17 | databaseClient: DatabaseClient, 18 | tenantContext: TenantContext, 19 | embeddingModel: EmbeddingModel, 20 | logger: Logger, 21 | }, 22 | setup({ databaseClient, tenantContext, embeddingModel, logger }) { 23 | return async (params: KnowledgeRetrieverParams) => { 24 | logger.debug('Querying "%s"', params.query, params); 25 | 26 | const queryVector = await embeddingModel.embedQuery(params.query); 27 | const similarity = sql`1 - (${cosineDistance(db.knowledge.vector, queryVector)})`; 28 | 29 | const results = await databaseClient 30 | .select({ 31 | id: db.knowledge.id, 32 | type: db.knowledge.type, 33 | title: db.knowledge.title, 34 | externalId: db.knowledge.externalId, 35 | url: db.knowledge.url, 36 | metadata: db.knowledge.metadata, 37 | content: db.knowledge.content, 38 | similarity, 39 | }) 40 | .from(db.knowledge) 41 | .where(and(eq(db.knowledge.tenantId, tenantContext.tenantId), gte(similarity, 0.3))) 42 | .orderBy(desc(similarity)) 43 | .limit(params.limit ?? 10); 44 | 45 | return results; 46 | }; 47 | }, 48 | }); 49 | -------------------------------------------------------------------------------- /packages/provider/src/VercelModel.test.ts: -------------------------------------------------------------------------------- 1 | import { anthropic } from '@ai-sdk/anthropic'; 2 | import { openai } from '@ai-sdk/openai'; 3 | import { ChatAnthropic } from '@langchain/anthropic'; 4 | import { ChatOpenAI } from '@langchain/openai'; 5 | import { expect, test } from 'vitest'; 6 | 7 | import type { LanguageModel } from './LanguageModel.js'; 8 | import { isVercelModel, normalizeVercelModel } from './VercelModel.js'; 9 | 10 | test('vercel openai model', () => { 11 | const model = openai('gpt-4o'); 12 | const check = isVercelModel(model); 13 | 14 | expect(check).toBe(true); 15 | 16 | const normalized = normalizeVercelModel(model); 17 | expect(normalized.name).toBe('gpt-4o'); 18 | expect(isVercelModel(normalized)).toBe(false); 19 | }); 20 | 21 | test('vercel anthropic model', () => { 22 | const model = anthropic('claude-3-5-sonnet-latest'); 23 | const check = isVercelModel(model); 24 | 25 | expect(check).toBe(true); 26 | 27 | const normalized = normalizeVercelModel(model); 28 | expect(normalized.name).toBe('claude-3-5-sonnet-latest'); 29 | expect(isVercelModel(normalized)).toBe(false); 30 | }); 31 | 32 | test('langchain openai model', () => { 33 | const model = new ChatOpenAI({ model: 'gpt-4o' }); 34 | const check = isVercelModel(model); 35 | 36 | expect(check).toBe(false); 37 | }); 38 | 39 | test('langchain anthropic model', () => { 40 | const model = new ChatAnthropic({ 41 | modelName: 'claude-3-5-sonnet-latest', 42 | apiKey: 'test', 43 | }); 44 | const check = isVercelModel(model); 45 | 46 | expect(check).toBe(false); 47 | }); 48 | 49 | test('native model', () => { 50 | const model: LanguageModel = { 51 | name: 'gpt-4o', 52 | invoke: () => 53 | Promise.resolve({ 54 | role: 'assistant', 55 | content: 'Hello, world!', 56 | }), 57 | }; 58 | 59 | expect(isVercelModel(model)).toBe(false); 60 | }); 61 | -------------------------------------------------------------------------------- /legacy/agent/src/AgentStateStore.ts: -------------------------------------------------------------------------------- 1 | import type { AgentState } from '@agentscript-ai/core'; 2 | import { defineService } from '@nzyme/ioc'; 3 | 4 | export const AgentStateStore = defineService({ 5 | name: 'AgentStateStore', 6 | setup() { 7 | const stateById = new Map(); 8 | const stateByChatId = new Map(); 9 | 10 | return { 11 | getState(id: string) { 12 | return Promise.resolve(stateById.get(id)); 13 | }, 14 | getStateForChat(channelId: string, threadId: string) { 15 | const id = `${channelId}:${threadId}`; 16 | let state = stateByChatId.get(id); 17 | if (!state) { 18 | state = { 19 | id, 20 | channelId, 21 | threadId, 22 | events: [], 23 | tools: {}, 24 | users: {}, 25 | }; 26 | 27 | stateById.set(state.id, state); 28 | stateByChatId.set(id, state); 29 | } 30 | 31 | return Promise.resolve(state); 32 | }, 33 | updateState(state: AgentState) { 34 | const chatIds = new Set(); 35 | for (const interaction of state.events) { 36 | if ('message' in interaction && interaction.message) { 37 | const chatId = `${interaction.message.channelId}:${interaction.message.threadId}`; 38 | if (chatId) { 39 | chatIds.add(chatId); 40 | } 41 | } 42 | } 43 | 44 | stateById.set(state.id, state); 45 | for (const chatId of chatIds) { 46 | stateByChatId.set(chatId, state); 47 | } 48 | }, 49 | }; 50 | }, 51 | }); 52 | -------------------------------------------------------------------------------- /packages/parser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/parser", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "type": "module", 11 | "exports": { 12 | ".": { 13 | "import": { 14 | "types": "./dist/index.d.ts", 15 | "default": "./dist/index.js" 16 | }, 17 | "require": { 18 | "types": "./dist/index.d.ts", 19 | "default": "./dist/index.cjs" 20 | }, 21 | "default": { 22 | "types": "./dist/index.d.ts", 23 | "default": "./dist/index.js" 24 | } 25 | } 26 | }, 27 | "main": "./dist/index.cjs", 28 | "types": "./dist/index.d.ts", 29 | "files": [ 30 | "dist", 31 | "LICENSE", 32 | "README.md" 33 | ], 34 | "scripts": { 35 | "build:esm": "tsc --build ./tsconfig.esm.json", 36 | "lint": "eslint . --fix --cache", 37 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 38 | "smoke:cjs": "node tests/smoke.test.cjs", 39 | "smoke:mjs": "node tests/smoke.test.mjs" 40 | }, 41 | "dependencies": { 42 | "@agentscript-ai/utils": "^0.9.0", 43 | "@babel/parser": "^7.27.0", 44 | "@babel/types": "^7.27.0" 45 | }, 46 | "devDependencies": { 47 | "@agentscript-ai/eslint": "^0.9.0", 48 | "@agentscript-ai/tsconfig": "^0.9.0", 49 | "@nzyme/vitest": "^0.14.0", 50 | "@types/debug": "^4.1.12", 51 | "@types/node": "^22.14.0", 52 | "eslint": "^9.24.0", 53 | "typescript": "^5.8.3", 54 | "vitest": "^3.1.1" 55 | }, 56 | "publishConfig": { 57 | "access": "public" 58 | }, 59 | "nzyme": { 60 | "cjs": true 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /packages/provider/src/LangChainModel.test.ts: -------------------------------------------------------------------------------- 1 | import { anthropic } from '@ai-sdk/anthropic'; 2 | import { openai } from '@ai-sdk/openai'; 3 | import { ChatAnthropic } from '@langchain/anthropic'; 4 | import { ChatOpenAI } from '@langchain/openai'; 5 | import { expect, test } from 'vitest'; 6 | 7 | import { isLangChainModel, normalizeLangChainModel } from './LangChainModel.js'; 8 | import type { LanguageModel } from './LanguageModel.js'; 9 | 10 | test('langchain openai model', () => { 11 | const model = new ChatOpenAI({ model: 'gpt-4o' }); 12 | const check = isLangChainModel(model); 13 | 14 | expect(check).toBe(true); 15 | 16 | const normalized = normalizeLangChainModel(model); 17 | 18 | expect(normalized.name).toBe('gpt-4o'); 19 | expect(isLangChainModel(normalized)).toBe(false); 20 | }); 21 | 22 | test('langchain anthropic model', () => { 23 | const model = new ChatAnthropic({ 24 | modelName: 'claude-3-5-sonnet-latest', 25 | apiKey: 'test', 26 | }); 27 | const check = isLangChainModel(model); 28 | 29 | expect(check).toBe(true); 30 | 31 | const normalized = normalizeLangChainModel(model); 32 | 33 | expect(normalized.name).toBe('claude-3-5-sonnet-latest'); 34 | expect(isLangChainModel(normalized)).toBe(false); 35 | }); 36 | 37 | test('vercel openai model', () => { 38 | const model = openai('gpt-4o'); 39 | const check = isLangChainModel(model); 40 | 41 | expect(check).toBe(false); 42 | }); 43 | 44 | test('vercel anthropic model', () => { 45 | const model = anthropic('claude-3-5-sonnet-latest'); 46 | const check = isLangChainModel(model); 47 | 48 | expect(check).toBe(false); 49 | }); 50 | 51 | test('native model', () => { 52 | const model: LanguageModel = { 53 | name: 'gpt-4o', 54 | invoke: () => 55 | Promise.resolve({ 56 | role: 'assistant', 57 | content: 'Hello, world!', 58 | }), 59 | }; 60 | 61 | expect(isLangChainModel(model)).toBe(false); 62 | }); 63 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "repository": { 3 | "type": "git", 4 | "url": "https://github.com/AgentScript-AI/agentscript.git" 5 | }, 6 | "author": "Michał Kędrzyński ", 7 | "private": true, 8 | "scripts": { 9 | "setup": "yarn && nzyme monorepo", 10 | "monorepo": "nzyme monorepo", 11 | "clean": "del \"**/tsconfig.*.dev.json\" \"**/dist\" \"**/.turbo\" \"**/.nzyme\" \"**/.tsbuildinfo\" \"**/*.tsbuildinfo\" \"!**/node_modules/**\"", 12 | "dev": "yarn setup && turbo run watch", 13 | "build": "yarn build:esm && yarn build:cjs", 14 | "build:cjs": "nzyme build cjs", 15 | "build:esm": "tsc --build", 16 | "build:turbo": "turbo run build:esm build:cjs", 17 | "codegen": "turbo run codegen", 18 | "watch": "yarn monorepo && yarn build:esm --watch", 19 | "update": "yarn upgrade-interactive", 20 | "update:deps": "yarn up \"@nzyme/*\"", 21 | "update:self": "yarn set version berry", 22 | "test": "vitest run", 23 | "coverage": "vitest run --coverage", 24 | "smoke": "turbo run smoke:cjs smoke:mjs", 25 | "release": "nx release --yes", 26 | "groundup": "yarn && yarn clean && nzyme monorepo && yarn build" 27 | }, 28 | "devDependencies": { 29 | "@nx/js": "^20.7.2", 30 | "@nzyme/cli": "^0.14.0", 31 | "@nzyme/eslint": "^0.14.0", 32 | "@swc-node/register": "^1.10.10", 33 | "@swc/core": "^1.11.18", 34 | "@vitest/coverage-v8": "3.1.1", 35 | "del-cli": "^6.0.0", 36 | "dotenv-cli": "^8.0.0", 37 | "eslint": "^9.24.0", 38 | "nx": "20.7.2", 39 | "prettier": "^3.5.3", 40 | "ts-node": "^10.9.2", 41 | "turbo": "^2.5.0", 42 | "typescript": "^5.8.3", 43 | "vitest": "^3.1.1" 44 | }, 45 | "workspaces": [ 46 | "packages/*" 47 | ], 48 | "packageManager": "yarn@4.7.0", 49 | "depcheck": { 50 | "ignoreDeps": [ 51 | "*" 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/anthropic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/anthropic", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:esm": "tsc --build ./tsconfig.esm.json", 37 | "lint": "eslint . --fix --cache", 38 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 39 | "smoke:cjs": "node tests/smoke.test.cjs", 40 | "smoke:mjs": "node tests/smoke.test.mjs" 41 | }, 42 | "dependencies": { 43 | "@agentscript-ai/provider": "^0.9.0", 44 | "@agentscript-ai/utils": "^0.9.0", 45 | "@anthropic-ai/sdk": "^0.39.0", 46 | "@nzyme/ioc": "^0.14.0", 47 | "@nzyme/utils": "^0.14.0" 48 | }, 49 | "devDependencies": { 50 | "@agentscript-ai/eslint": "^0.9.0", 51 | "@agentscript-ai/tsconfig": "^0.9.0", 52 | "@types/node": "^22.14.0", 53 | "eslint": "^9.24.0", 54 | "typescript": "^5.8.3", 55 | "vitest": "^3.1.1" 56 | }, 57 | "publishConfig": { 58 | "access": "public" 59 | }, 60 | "nzyme": { 61 | "cjs": true 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/core/src/meta/defineMetadata.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import type { MetadataWrapper } from './defineMetadata.js'; 4 | import { defineMetadata } from './defineMetadata.js'; 5 | 6 | test('number metadata', () => { 7 | const metadata = defineMetadata({ name: 'test' }); 8 | const wrapper: MetadataWrapper = { metadata: {} }; 9 | 10 | expect(metadata(wrapper)).toBeUndefined(); 11 | 12 | metadata(wrapper, 1); 13 | 14 | expect(metadata(wrapper)).toBe(1); 15 | expect(wrapper.metadata).toEqual({ test: 1 }); 16 | }); 17 | 18 | test('string metadata', () => { 19 | const metadata = defineMetadata({ name: 'test' }); 20 | const wrapper: MetadataWrapper = { metadata: {} }; 21 | 22 | expect(metadata(wrapper)).toBeUndefined(); 23 | 24 | metadata(wrapper, 'test'); 25 | 26 | expect(metadata(wrapper)).toBe('test'); 27 | expect(wrapper.metadata).toEqual({ test: 'test' }); 28 | }); 29 | 30 | test('object metadata', () => { 31 | const metadata = defineMetadata<{ a: number }>({ name: 'test' }); 32 | const wrapper: MetadataWrapper = { metadata: {} }; 33 | 34 | expect(metadata(wrapper)).toBeUndefined(); 35 | 36 | metadata(wrapper, { a: 1 }); 37 | 38 | expect(metadata(wrapper)).toEqual({ a: 1 }); 39 | expect(wrapper.metadata).toEqual({ test: { a: 1 } }); 40 | }); 41 | 42 | test('multiple metadata', () => { 43 | const metadata1 = defineMetadata<{ a: number }>({ name: 'test1' }); 44 | const metadata2 = defineMetadata<{ b: string }>({ name: 'test2' }); 45 | const wrapper: MetadataWrapper = { metadata: {} }; 46 | 47 | expect(metadata1(wrapper)).toBeUndefined(); 48 | expect(metadata2(wrapper)).toBeUndefined(); 49 | 50 | metadata1(wrapper, { a: 1 }); 51 | metadata2(wrapper, { b: 'test' }); 52 | 53 | expect(metadata1(wrapper)).toEqual({ a: 1 }); 54 | expect(metadata2(wrapper)).toEqual({ b: 'test' }); 55 | 56 | expect(wrapper.metadata).toEqual({ 57 | test1: { a: 1 }, 58 | test2: { b: 'test' }, 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /packages/llamaindex/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/llamaindex", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:esm": "tsc --build ./tsconfig.esm.json", 37 | "lint": "eslint . --fix --cache", 38 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 39 | "smoke:cjs": "node tests/smoke.test.cjs", 40 | "smoke:mjs": "node tests/smoke.test.mjs" 41 | }, 42 | "dependencies": { 43 | "@agentscript-ai/provider": "^0.9.0", 44 | "@agentscript-ai/utils": "^0.9.0", 45 | "@llamaindex/core": "^0.6.2", 46 | "@nzyme/utils": "^0.14.0" 47 | }, 48 | "devDependencies": { 49 | "@agentscript-ai/eslint": "^0.9.0", 50 | "@agentscript-ai/tsconfig": "^0.9.0", 51 | "@llamaindex/openai": "^0.3.0", 52 | "@types/node": "^22.14.0", 53 | "eslint": "^9.24.0", 54 | "typescript": "^5.8.3", 55 | "vitest": "^3.1.1" 56 | }, 57 | "publishConfig": { 58 | "access": "public" 59 | }, 60 | "nzyme": { 61 | "cjs": true 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/core/src/tools/filterTools.ts: -------------------------------------------------------------------------------- 1 | import type { ToolDefinition } from './defineTool.js'; 2 | import { isTool } from './defineTool.js'; 3 | import type { RuntimeModule } from '../agent/defineAgent.js'; 4 | 5 | /** 6 | * Filter tools by their names. 7 | * @param tools - The tools to filter. 8 | * @param toolNames - The names of the tools to filter. 9 | * @returns The filtered tools. 10 | */ 11 | export function filterTools(tools: RuntimeModule, toolNames: string[]) { 12 | const result: RuntimeModule = {}; 13 | 14 | // Return early if no tools or tool names 15 | if (!tools || !toolNames.length) { 16 | return result; 17 | } 18 | 19 | for (const path of toolNames) { 20 | const parts = path.split('.'); 21 | const tool = findTool(tools, parts); 22 | if (!tool) { 23 | continue; 24 | } 25 | 26 | setTool(result, parts, tool); 27 | } 28 | 29 | return result; 30 | } 31 | 32 | function findTool( 33 | tools: RuntimeModule, 34 | path: string[], 35 | ): ToolDefinition | RuntimeModule | undefined { 36 | let current: RuntimeModule = tools; 37 | 38 | // Traverse the path 39 | for (const segment of path) { 40 | const next = current[segment]; 41 | if (!next) { 42 | return; 43 | } 44 | 45 | if (isTool(next)) { 46 | return next; 47 | } 48 | 49 | current = next; 50 | } 51 | 52 | return current; 53 | } 54 | 55 | function setTool(tools: RuntimeModule, path: string[], tool: ToolDefinition | RuntimeModule): void { 56 | let current = tools; 57 | // Traverse the path and create nested objects as needed 58 | for (let i = 0; i < path.length - 1; i++) { 59 | const segment = path[i]!; 60 | if (!(segment in current)) { 61 | current[segment] = {}; 62 | } 63 | 64 | current = current[segment] as RuntimeModule; 65 | } 66 | 67 | // Set the tool at the final path segment 68 | const lastSegment = path[path.length - 1]!; 69 | current[lastSegment] = tool; 70 | } 71 | -------------------------------------------------------------------------------- /packages/core/src/runtime/tests/testUtils.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsdoc/require-jsdoc */ 2 | import { expect } from 'vitest'; 3 | 4 | import type { AstNode } from '@agentscript-ai/parser'; 5 | 6 | import type { ExecuteAgentResult } from '../executeAgent.js'; 7 | import type { StackFrame } from '../runtimeTypes.js'; 8 | 9 | export function rootFrame( 10 | frame: Omit & { 11 | status?: StackFrame['status']; 12 | }, 13 | ): StackFrame { 14 | return { 15 | ...frame, 16 | startedAt: anyDate(), 17 | updatedAt: anyDate(), 18 | trace: '0', 19 | status: frame.status || 'running', 20 | }; 21 | } 22 | 23 | export function agentResult(result: ExecuteAgentResult): ExecuteAgentResult { 24 | return result; 25 | } 26 | 27 | export function childFrame( 28 | frame: Omit & { 29 | status?: StackFrame['status']; 30 | node: AstNode['type'] | 'any'; 31 | }, 32 | ): StackFrame { 33 | const result: StackFrame = { 34 | ...frame, 35 | trace: expect.any(String) as string, 36 | startedAt: anyDate(), 37 | updatedAt: anyDate(), 38 | parent: expect.any(Object) as StackFrame, 39 | status: frame.status || 'running', 40 | node: 41 | frame.node === 'any' 42 | ? undefined 43 | : (expect.objectContaining({ type: frame.node }) as AstNode), 44 | }; 45 | 46 | if (!result.node) { 47 | delete result.node; 48 | } 49 | 50 | return result; 51 | } 52 | 53 | export function completedFrame( 54 | frame: Omit & { 55 | node: AstNode['type']; 56 | }, 57 | ): StackFrame { 58 | return childFrame({ 59 | ...frame, 60 | status: 'done', 61 | }); 62 | } 63 | 64 | export function anyNumber() { 65 | return expect.any(Number) as number; 66 | } 67 | 68 | export function anyDate() { 69 | return expect.any(Date) as Date; 70 | } 71 | -------------------------------------------------------------------------------- /packages/tools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/tools", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:esm": "tsc --build ./tsconfig.esm.json", 37 | "lint": "eslint . --fix --cache", 38 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 39 | "smoke:cjs": "node tests/smoke.test.cjs", 40 | "smoke:mjs": "node tests/smoke.test.mjs" 41 | }, 42 | "dependencies": { 43 | "@agentscript-ai/core": "^0.9.0", 44 | "@agentscript-ai/provider": "^0.9.0", 45 | "@agentscript-ai/schema": "^0.9.0", 46 | "@agentscript-ai/utils": "^0.9.0", 47 | "@nzyme/ioc": "^0.14.0", 48 | "@nzyme/utils": "^0.14.0", 49 | "date-fns": "^4.1.0" 50 | }, 51 | "devDependencies": { 52 | "@agentscript-ai/eslint": "^0.9.0", 53 | "@agentscript-ai/tsconfig": "^0.9.0", 54 | "@types/node": "^22.14.0", 55 | "eslint": "^9.24.0", 56 | "typescript": "^5.8.3", 57 | "vitest": "^3.1.1" 58 | }, 59 | "publishConfig": { 60 | "access": "public" 61 | }, 62 | "nzyme": { 63 | "cjs": true 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /packages/openapi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/openapi", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:esm": "tsc --build ./tsconfig.esm.json", 37 | "lint": "eslint . --fix --cache", 38 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 39 | "smoke:cjs": "node tests/smoke.test.cjs", 40 | "smoke:mjs": "node tests/smoke.test.mjs" 41 | }, 42 | "dependencies": { 43 | "@agentscript-ai/core": "^0.9.0", 44 | "@agentscript-ai/provider": "^0.9.0", 45 | "@agentscript-ai/schema": "^0.9.0", 46 | "@agentscript-ai/utils": "^0.9.0", 47 | "@nzyme/utils": "^0.14.0", 48 | "@scalar/openapi-parser": "^0.10.14", 49 | "@scalar/openapi-types": "^0.2.0", 50 | "openapi-types": "^12.1.3", 51 | "ufo": "^1.6.1" 52 | }, 53 | "devDependencies": { 54 | "@agentscript-ai/eslint": "^0.9.0", 55 | "@agentscript-ai/tsconfig": "^0.9.0", 56 | "@types/node": "^22.14.0", 57 | "eslint": "^9.24.0", 58 | "typescript": "^5.8.3", 59 | "vitest": "^3.1.1" 60 | }, 61 | "publishConfig": { 62 | "access": "public" 63 | }, 64 | "nzyme": { 65 | "cjs": true 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /packages/provider/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/provider", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:cjs": "tsc --build ./tsconfig.cjs.json", 37 | "build:esm": "tsc --build ./tsconfig.esm.json", 38 | "lint": "eslint . --fix --cache", 39 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 40 | "smoke:cjs": "node tests/smoke.test.cjs", 41 | "smoke:mjs": "node tests/smoke.test.mjs" 42 | }, 43 | "dependencies": { 44 | "@agentscript-ai/utils": "^0.9.0", 45 | "@ai-sdk/provider": "^1.1.2", 46 | "@langchain/core": "^0.3.44", 47 | "@nzyme/ioc": "^0.14.0", 48 | "@nzyme/utils": "^0.14.0" 49 | }, 50 | "devDependencies": { 51 | "@agentscript-ai/eslint": "^0.9.0", 52 | "@agentscript-ai/tsconfig": "^0.9.0", 53 | "@ai-sdk/anthropic": "^1.2.9", 54 | "@ai-sdk/openai": "^1.3.9", 55 | "@langchain/anthropic": "^0.3.17", 56 | "@langchain/openai": "^0.5.5", 57 | "@types/node": "^22.14.0", 58 | "eslint": "^9.24.0", 59 | "typescript": "^5.8.3", 60 | "vitest": "^3.1.1" 61 | }, 62 | "publishConfig": { 63 | "access": "public" 64 | }, 65 | "nzyme": { 66 | "cjs": true 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /legacy/notion/src/SyncNotionPage.ts: -------------------------------------------------------------------------------- 1 | import { NotionAPILoader } from '@langchain/community/document_loaders/web/notionapi'; 2 | 3 | import { EnvVariables, Logger } from '@agentscript-ai/core'; 4 | import { KnowledgeStore } from '@agentscript-ai/rag'; 5 | import { defineCommand } from '@nzyme/ioc'; 6 | 7 | export interface SyncNotionPageParams { 8 | pageId: string; 9 | } 10 | 11 | export const SyncNotionPage = defineCommand({ 12 | name: 'SyncNotionPage', 13 | deps: { 14 | env: EnvVariables, 15 | knowledgeStore: KnowledgeStore, 16 | logger: Logger, 17 | }, 18 | setup({ env, knowledgeStore, logger }) { 19 | const notionToken = env.NOTION_TOKEN; 20 | 21 | return async (params: SyncNotionPageParams) => { 22 | // Loading a page (including child pages all as separate documents) 23 | const pageLoader = new NotionAPILoader({ 24 | clientOptions: { 25 | auth: notionToken, 26 | }, 27 | id: params.pageId, 28 | propertiesAsHeader: true, 29 | callerOptions: {}, 30 | type: 'page', 31 | }); 32 | 33 | const pages = await pageLoader.load(); 34 | 35 | for (const page of pages) { 36 | const properties = page.metadata.properties as Record; 37 | const title = properties.title || properties._title || properties.Page; 38 | 39 | logger.info('Syncing Notion page "%s"', title, { 40 | title, 41 | url: page.metadata.url as string, 42 | externalId: page.metadata.notionId as string, 43 | updatedAt: new Date(page.metadata.last_edited_time as string), 44 | }); 45 | 46 | await knowledgeStore.upsertDocument({ 47 | type: 'NOTION_PAGE', 48 | title, 49 | url: page.metadata.url as string, 50 | externalId: page.metadata.notionId as string, 51 | updatedAt: new Date(page.metadata.last_edited_time as string), 52 | document: page, 53 | }); 54 | } 55 | }; 56 | }, 57 | }); 58 | -------------------------------------------------------------------------------- /legacy/rag/src/tools/SearchKnowledgeTool.ts: -------------------------------------------------------------------------------- 1 | import * as z from 'zod'; 2 | 3 | import { defineTool, randomUid } from '@agentscript-ai/core'; 4 | 5 | import { KnowledgeRetriever } from '../KnowledgeRetriever.js'; 6 | 7 | export type SearchKnowledgeToolInput = z.infer; 8 | export const SearchKnowledgeToolInput = z.object({ 9 | queries: z 10 | .array(z.string()) 11 | .describe( 12 | "Provide 3 queries based on the context to get better results. Don't include name of the tool in the query.", 13 | ), 14 | }); 15 | 16 | export const SearchKnowledgeTool = defineTool({ 17 | name: 'search_knowledge', 18 | description: 'Search for information in the knowledge base.', 19 | input: SearchKnowledgeToolInput, 20 | setup({ inject }) { 21 | const knowledgeRetriever = inject(KnowledgeRetriever); 22 | 23 | return { 24 | async invoke({ input, agent, call }) { 25 | const results = await Promise.all( 26 | input.queries.map(query => knowledgeRetriever({ query })), 27 | ); 28 | 29 | const resultsMap = new Map(); 30 | 31 | for (const result of results.flat()) { 32 | resultsMap.set(result.id, result); 33 | } 34 | 35 | const documents = [...resultsMap.values()] 36 | .sort((a, b) => b.similarity - a.similarity) 37 | .slice(0, 10) 38 | .map(result => ({ 39 | type: result.type, 40 | title: result.title, 41 | url: result.url, 42 | content: result.content, 43 | })); 44 | 45 | const content = `These are the documents that I found:\n${JSON.stringify(documents)}`; 46 | 47 | agent.events.push({ 48 | type: 'TOOL_EVENT', 49 | timestamp: new Date(), 50 | uid: randomUid(), 51 | callId: call.uid, 52 | content, 53 | }); 54 | 55 | return { 56 | requireResponse: true, 57 | }; 58 | }, 59 | }; 60 | }, 61 | }); 62 | -------------------------------------------------------------------------------- /legacy/slack/src/utils/stringifyMessage.ts: -------------------------------------------------------------------------------- 1 | import type { AppMentionEvent, BotMessageEvent, GenericMessageEvent } from '@slack/types'; 2 | 3 | import { blocksToMarkdown } from '@nzyme/slack'; 4 | import { mapNotNull } from '@nzyme/utils'; 5 | 6 | export function stringifyMessage(message: GenericMessageEvent | AppMentionEvent | BotMessageEvent) { 7 | let content = ''; 8 | 9 | if (message.blocks) { 10 | content = blocksToMarkdown(message.blocks); 11 | } 12 | 13 | if (!content && message.text) { 14 | content = message.text; 15 | } 16 | 17 | if ('files' in message && message.files) { 18 | content = appendNewline(content); 19 | content += 'Attached files:\n'; 20 | 21 | const files = mapNotNull(message.files, file => { 22 | if (isFile(file)) { 23 | return { 24 | name: file.name, 25 | url: file.url_private, 26 | }; 27 | } 28 | 29 | return null; 30 | }); 31 | 32 | content += JSON.stringify(files); 33 | 34 | // for (const file of message.files) { 35 | // if (!isFile(file)) { 36 | // continue; 37 | // } 38 | 39 | // content = appendNewline(content); 40 | 41 | // // if (file.mimetype.startsWith('image/')) { 42 | // // content += `![${file.name}](${ 43 | // // file.thumb_1024 || 44 | // // file.thumb_960 || 45 | // // file.thumb_720 || 46 | // // file.thumb_480 || 47 | // // file.thumb_360 || 48 | // // file.permalink_public || 49 | // // file.permalink 50 | // // })`; 51 | // // } else { 52 | // content += `[${file.name}](${file.permalink_public || file.permalink})`; 53 | // // } 54 | // } 55 | } 56 | 57 | return content; 58 | } 59 | 60 | type File = NonNullable[number]; 61 | 62 | function appendNewline(content: string) { 63 | if (content.length > 0) { 64 | return content + '\n'; 65 | } 66 | 67 | return content; 68 | } 69 | 70 | function isFile(file: File | { id: string }): file is File { 71 | return 'mimetype' in file; 72 | } 73 | -------------------------------------------------------------------------------- /packages/provider/src/VercelModel.ts: -------------------------------------------------------------------------------- 1 | import type { LanguageModelV1, LanguageModelV1Message } from '@ai-sdk/provider'; 2 | import { assert } from '@nzyme/utils'; 3 | 4 | import { joinLines } from '@agentscript-ai/utils'; 5 | 6 | import type { LanguageModel } from './LanguageModel.js'; 7 | 8 | /** 9 | * Vercel model type. 10 | */ 11 | export type VercelModel = LanguageModelV1; 12 | 13 | /** 14 | * Checks if a model is a Vercel model. 15 | * @param model - Model to check. 16 | * @returns True if the model is a Vercel model, false otherwise. 17 | */ 18 | export function isVercelModel(model: VercelModel | object): model is VercelModel { 19 | return ( 20 | 'doGenerate' in model && 21 | typeof model.doGenerate === 'function' && 22 | typeof model.provider === 'string' && 23 | model.specificationVersion === 'v1' 24 | ); 25 | } 26 | 27 | /** 28 | * Normalizes a Vercel model. 29 | * @param model - Vercel model to normalize. 30 | * @returns Normalized language model. 31 | */ 32 | export function normalizeVercelModel(model: VercelModel): LanguageModel { 33 | return { 34 | name: model.modelId, 35 | invoke: async params => { 36 | const messages: LanguageModelV1Message[] = []; 37 | 38 | if (params.systemPrompt) { 39 | messages.push({ 40 | role: 'system', 41 | content: joinLines(params.systemPrompt), 42 | }); 43 | } 44 | 45 | for (const message of params.messages) { 46 | messages.push({ 47 | role: message.role, 48 | content: [ 49 | { 50 | type: 'text', 51 | text: message.content, 52 | }, 53 | ], 54 | }); 55 | } 56 | 57 | const response = await model.doGenerate({ 58 | inputFormat: 'messages', 59 | prompt: messages, 60 | mode: { 61 | type: 'regular', 62 | }, 63 | }); 64 | 65 | assert(response.text, 'No text response from model'); 66 | 67 | return { 68 | role: 'assistant', 69 | content: response.text, 70 | }; 71 | }, 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /packages/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/core", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "type": "module", 11 | "exports": { 12 | ".": { 13 | "import": { 14 | "types": "./dist/index.d.ts", 15 | "default": "./dist/index.js" 16 | }, 17 | "require": { 18 | "types": "./dist/index.d.ts", 19 | "default": "./dist/index.cjs" 20 | }, 21 | "default": { 22 | "types": "./dist/index.d.ts", 23 | "default": "./dist/index.js" 24 | } 25 | } 26 | }, 27 | "main": "./dist/index.cjs", 28 | "types": "./dist/index.d.ts", 29 | "files": [ 30 | "dist", 31 | "LICENSE", 32 | "README.md" 33 | ], 34 | "scripts": { 35 | "build:esm": "tsc --build ./tsconfig.esm.json", 36 | "lint": "eslint . --fix --cache", 37 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 38 | "smoke:cjs": "node tests/smoke.test.cjs", 39 | "smoke:mjs": "node tests/smoke.test.mjs" 40 | }, 41 | "dependencies": { 42 | "@agentscript-ai/parser": "^0.9.0", 43 | "@agentscript-ai/provider": "^0.9.0", 44 | "@agentscript-ai/schema": "^0.9.0", 45 | "@agentscript-ai/serializer": "^0.9.0", 46 | "@agentscript-ai/utils": "^0.9.0", 47 | "@nzyme/crypto-utils": "^0.14.0", 48 | "@nzyme/ioc": "^0.14.0", 49 | "@nzyme/markdown": "^0.14.0", 50 | "@nzyme/types": "^0.14.0", 51 | "@nzyme/utils": "^0.14.0", 52 | "debug": "^4.4.0", 53 | "uuid": "^11.1.0" 54 | }, 55 | "devDependencies": { 56 | "@agentscript-ai/eslint": "^0.9.0", 57 | "@agentscript-ai/tsconfig": "^0.9.0", 58 | "@nzyme/vitest": "^0.14.0", 59 | "@types/debug": "^4.1.12", 60 | "@types/node": "^22.14.0", 61 | "eslint": "^9.24.0", 62 | "typescript": "^5.8.3", 63 | "vitest": "^3.1.1" 64 | }, 65 | "publishConfig": { 66 | "access": "public" 67 | }, 68 | "nzyme": { 69 | "cjs": true 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /packages/core/src/modules/renderTool.ts: -------------------------------------------------------------------------------- 1 | import * as s from '@agentscript-ai/schema'; 2 | import { normalizeText } from '@agentscript-ai/utils'; 3 | 4 | import { renderComment } from './renderComment.js'; 5 | import type { RenderContext } from './renderContext.js'; 6 | import { renderDocDirective } from './renderDocDirective.js'; 7 | import { renderType } from './renderType.js'; 8 | import type { ToolDefinition } from '../tools/defineTool.js'; 9 | 10 | interface RenderToolOptions { 11 | tool: ToolDefinition; 12 | name: string; 13 | ctx: RenderContext; 14 | } 15 | 16 | /** 17 | * Render a tool as TypeScript code. 18 | * @param options - Options for the tool. 19 | */ 20 | export function renderTool(options: RenderToolOptions) { 21 | const { tool, name, ctx } = options; 22 | 23 | let args = ''; 24 | 25 | const description = normalizeText(tool.description); 26 | 27 | const input = tool.input; 28 | if (s.isSchema(input, s.object)) { 29 | if (tool.singleArg) { 30 | const inputTypeName = renderType({ 31 | schema: input, 32 | ctx, 33 | nameHint: `${name}Params`, 34 | }); 35 | 36 | if (input.description) { 37 | description.push(renderDocDirective(`param params -`, input.description)); 38 | } 39 | 40 | args = `params: ${inputTypeName}`; 41 | } else { 42 | for (const [name, arg] of Object.entries(input.props)) { 43 | if (args.length > 0) { 44 | args += ', '; 45 | } 46 | 47 | args += `${name}: ${renderType({ schema: arg, ctx })}`; 48 | 49 | if (arg.description) { 50 | description.push(renderDocDirective(`param ${name} -`, arg.description)); 51 | } 52 | } 53 | } 54 | } 55 | 56 | if (tool.output.description) { 57 | description.push(renderDocDirective('returns', tool.output.description)); 58 | } 59 | 60 | const returnType = renderType({ 61 | schema: tool.output, 62 | ctx, 63 | nameHint: `${name}Result`, 64 | }); 65 | 66 | ctx.addLine(); 67 | ctx.addLine(); 68 | 69 | const comment = renderComment(description, ctx); 70 | if (comment) { 71 | ctx.addCode(comment); 72 | } 73 | 74 | ctx.addLine(`function ${name}(${args}): ${returnType};`); 75 | } 76 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true, 4 | "files.exclude": { 5 | "**/.git": true, 6 | // "**/dist": true, 7 | "**/node_modules/**": true, 8 | "**/tsconfig.tsbuildinfo": true 9 | }, 10 | // Allows formatting XML and SVG files by prettier 11 | "files.associations": { 12 | "*.xml": "html", 13 | "*.svg": "html" 14 | }, 15 | "search.exclude": { 16 | "**/dist": true, 17 | "**/node_modules/**": true, 18 | "**/*.code-search": true, 19 | "yarn.lock": true, 20 | "**/.yarn": true, 21 | "**/.pnp.*": true, 22 | "**/legacy": true 23 | }, 24 | "search.followSymlinks": true, 25 | "terminal.integrated.env.osx": { 26 | "NODE_OPTIONS": "--max-old-space-size=8192" 27 | }, 28 | "terminal.integrated.env.windows": { 29 | "NODE_OPTIONS": "--max-old-space-size=8192" 30 | }, 31 | "javascript.format.enable": false, 32 | "json.format.enable": false, 33 | "npm.packageManager": "yarn", 34 | "npm.scriptExplorerAction": "run", 35 | "typescript.format.enable": false, 36 | "typescript.tsdk": "node_modules/typescript/lib", 37 | "eslint.lintTask.enable": true, 38 | "eslint.useFlatConfig": false, 39 | "eslint.codeAction.showDocumentation": { 40 | "enable": true 41 | }, 42 | "eslint.validate": ["javascript", "typescript", "vue"], 43 | "typescript.enablePromptUseWorkspaceTsdk": true, 44 | "workbench.colorCustomizations": { 45 | "activityBar.activeBackground": "#e35252", 46 | "activityBar.background": "#e35252", 47 | "activityBar.foreground": "#ffffff", 48 | "activityBar.inactiveForeground": "#ffffff", 49 | "activityBarBadge.background": "#24db24", 50 | "activityBarBadge.foreground": "#15202b", 51 | "commandCenter.border": "#e7e7e799", 52 | "sash.hoverBorder": "#e35252", 53 | "statusBar.background": "#dc2626", 54 | "statusBar.foreground": "#ffffff", 55 | "statusBarItem.hoverBackground": "#e35252", 56 | "statusBarItem.remoteBackground": "#dc2626", 57 | "statusBarItem.remoteForeground": "#e7e7e7", 58 | "titleBar.activeBackground": "#dc2626", 59 | "titleBar.activeForeground": "#ffffff", 60 | "titleBar.inactiveBackground": "#dc262699", 61 | "titleBar.inactiveForeground": "#e7e7e799" 62 | }, 63 | "peacock.color": "dc2626" 64 | } 65 | -------------------------------------------------------------------------------- /packages/core/src/agent/defineAgent.ts: -------------------------------------------------------------------------------- 1 | import type { SomeObject } from '@nzyme/types'; 2 | 3 | import type * as s from '@agentscript-ai/schema'; 4 | 5 | import type { ToolDefinition } from '../tools/defineTool.js'; 6 | 7 | /** 8 | * Schema for the input of the agent. 9 | */ 10 | export type AgentInputDefinition = Record | undefined; 11 | /** 12 | * Schema for the output of the agent. 13 | */ 14 | export type AgentOutputDefinition = s.Schema | undefined; 15 | 16 | /** 17 | * Base type for tools available to the agent. 18 | */ 19 | export type AgentTools = RuntimeModule; 20 | /** 21 | * Base type for the input of the agent. 22 | */ 23 | export type AgentInputBase = Record; 24 | /** 25 | * Base type for the output of the agent. 26 | */ 27 | export type AgentOutputBase = s.Schema | undefined; 28 | 29 | /** 30 | * AgentScript agent definition. 31 | */ 32 | export type AgentDefinition< 33 | TTools extends AgentTools = AgentTools, 34 | TInput extends AgentInputBase = AgentInputBase, 35 | TOutput extends AgentOutputBase = AgentOutputBase, 36 | > = { 37 | /** 38 | * Tools available to the agent. 39 | */ 40 | readonly tools?: TTools; 41 | /** 42 | * Schema for the input of the runtime. 43 | * Provide if you want the agent to accept a specific input. 44 | * Describe the input for best results. 45 | */ 46 | readonly input?: TInput; 47 | /** 48 | * Schema for the output of the runtime. 49 | * Provide if you want the agent to return a specific value. 50 | * Describe the output for best results. 51 | */ 52 | readonly output?: TOutput; 53 | }; 54 | 55 | /** 56 | * AgentScript runtime module. 57 | */ 58 | export type RuntimeModule = { 59 | [name: string]: ToolDefinition | RuntimeModule; 60 | }; 61 | 62 | /** 63 | * Infer the output type of an agent. 64 | */ 65 | export type AgentOutput = s.InferOr; 66 | /** 67 | * Infer the input type of an agent. 68 | */ 69 | export type AgentInput = { 70 | [K in keyof TInput]: s.Infer; 71 | }; 72 | 73 | /** 74 | * Define an agent. Useful for code reuse. 75 | * @param agent - Agent to define. 76 | * @returns Defined agent. 77 | */ 78 | export function defineAgent< 79 | TTools extends AgentTools = SomeObject, 80 | TInput extends AgentInputBase = SomeObject, 81 | TOutput extends AgentOutputBase = undefined, 82 | >(agent: AgentDefinition) { 83 | return agent; 84 | } 85 | -------------------------------------------------------------------------------- /legacy/agent/src/SlackBot.ts: -------------------------------------------------------------------------------- 1 | import slack from '@slack/bolt'; 2 | 3 | import { EnvVariables, TOOL_CHAT_ACTION_TYPE, ToolChatAction } from '@agentscript-ai/core'; 4 | import { SlackReceiver, stringifyMessage } from '@agentscript-ai/slack'; 5 | import { defineService } from '@nzyme/ioc'; 6 | import { assertValue } from '@nzyme/utils'; 7 | 8 | import { Agent } from './Agent.js'; 9 | 10 | export const SlackBot = defineService({ 11 | name: 'SlackBot', 12 | setup({ inject }) { 13 | const agent = inject(Agent); 14 | const env = inject(EnvVariables); 15 | const slackReceiver = inject(SlackReceiver); 16 | 17 | const slackApp = new slack.App({ 18 | receiver: slackReceiver, 19 | token: env.SLACK_BOT_TOKEN, 20 | signingSecret: env.SLACK_SIGNING_SECRET, 21 | appToken: env.SLACK_APP_TOKEN, 22 | }); 23 | 24 | slackApp.message(async ({ message }) => { 25 | if (message.type !== 'message') { 26 | return; 27 | } 28 | 29 | if (message.subtype || !message.text) { 30 | return; 31 | } 32 | 33 | const channelId = message.channel; 34 | const threadId = message.thread_ts ?? message.ts; 35 | const content = stringifyMessage(message); 36 | 37 | await agent.newMessage({ 38 | messageId: message.ts, 39 | channelId, 40 | threadId, 41 | userId: message.user, 42 | timestamp: new Date(+message.ts), 43 | content, 44 | }); 45 | }); 46 | 47 | slackApp.action(TOOL_CHAT_ACTION_TYPE, async ({ action }) => { 48 | if (action.type === 'button') { 49 | const payload = ToolChatAction.parse(JSON.parse(action.value ?? '{}')); 50 | await agent.runToolInteraction(payload); 51 | } 52 | }); 53 | 54 | slackApp.event('app_mention', async ({ event }) => { 55 | const channelId = event.channel; 56 | const threadId = event.thread_ts ?? event.ts; 57 | const content = stringifyMessage(event); 58 | 59 | await agent.newMessage({ 60 | messageId: event.ts, 61 | channelId, 62 | threadId, 63 | userId: assertValue(event.user), 64 | timestamp: new Date(+event.ts), 65 | content, 66 | }); 67 | }); 68 | 69 | return slackApp; 70 | }, 71 | }); 72 | -------------------------------------------------------------------------------- /packages/linear/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@agentscript-ai/linear", 3 | "version": "0.9.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/AgentScript-AI/agentscript.git" 7 | }, 8 | "license": "Elastic License 2.0 (ELv2)", 9 | "author": "Michał Kędrzyński ", 10 | "sideEffects": false, 11 | "type": "module", 12 | "exports": { 13 | ".": { 14 | "import": { 15 | "types": "./dist/index.d.ts", 16 | "default": "./dist/index.js" 17 | }, 18 | "require": { 19 | "types": "./dist/index.d.ts", 20 | "default": "./dist/index.cjs" 21 | }, 22 | "default": { 23 | "types": "./dist/index.d.ts", 24 | "default": "./dist/index.js" 25 | } 26 | } 27 | }, 28 | "main": "./dist/index.cjs", 29 | "types": "./dist/index.d.ts", 30 | "files": [ 31 | "dist", 32 | "LICENSE", 33 | "README.md" 34 | ], 35 | "scripts": { 36 | "build:esm": "tsc --build ./tsconfig.esm.json", 37 | "codegen": "graphql-codegen --config graphql.config.ts", 38 | "lint": "eslint . --fix --cache", 39 | "prepack": "cp ../../README.md . && cp ../../LICENSE .", 40 | "smoke:cjs": "node tests/smoke.test.cjs", 41 | "smoke:mjs": "node tests/smoke.test.mjs", 42 | "watch": "yarn codegen --watch" 43 | }, 44 | "dependencies": { 45 | "@agentscript-ai/core": "^0.9.0", 46 | "@agentscript-ai/provider": "^0.9.0", 47 | "@agentscript-ai/schema": "^0.9.0", 48 | "@nzyme/ioc": "^0.14.0", 49 | "@nzyme/utils": "^0.14.0", 50 | "add": "^2.0.6", 51 | "debug": "^4.4.0", 52 | "graphql": "^16.10.0", 53 | "graphql-cli": "^4.1.0", 54 | "graphql-request": "^7.1.2" 55 | }, 56 | "devDependencies": { 57 | "@agentscript-ai/eslint": "^0.9.0", 58 | "@agentscript-ai/tsconfig": "^0.9.0", 59 | "@graphql-codegen/cli": "5.0.5", 60 | "@graphql-codegen/client-preset": "4.8.0", 61 | "@graphql-codegen/typescript-graphql-request": "^6.2.0", 62 | "@parcel/watcher": "^2.5.1", 63 | "@types/add": "^2.0.3", 64 | "@types/debug": "^4.1.12", 65 | "@types/node": "^22.14.0", 66 | "eslint": "^9.24.0", 67 | "typescript": "^5.8.3" 68 | }, 69 | "publishConfig": { 70 | "access": "public" 71 | }, 72 | "nzyme": { 73 | "cjs": true 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /packages/serializer/src/heap.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import { createDeserializer } from './createDeserializer.js'; 4 | import { createSerializer } from './createSerializer.js'; 5 | 6 | test('serializer and deserializer', () => { 7 | const serializer = createSerializer(); 8 | 9 | const value = { 10 | a: 1, 11 | b: 'ieaiea', 12 | c: [3, 4, 5], 13 | d: new Set([6, 7, 8]), 14 | e: new Date('2021-01-01'), 15 | f: { 16 | g: 45n, 17 | h: 'foo', 18 | i: false, 19 | j: true, 20 | k: null, 21 | l: undefined, 22 | m: /test/i, 23 | }, 24 | }; 25 | 26 | const index = serializer.push(value); 27 | 28 | const deserializer = createDeserializer(serializer.heap); 29 | const deserialized = deserializer.get(index); 30 | 31 | expect(deserialized).toEqual(value); 32 | }); 33 | 34 | test('recursive object', () => { 35 | const serializer = createSerializer(); 36 | 37 | const value = { 38 | a: 1, 39 | b: null as unknown, 40 | }; 41 | 42 | value.b = value; 43 | 44 | const index = serializer.push(value); 45 | 46 | const deserializer = createDeserializer(serializer.heap); 47 | const deserialized = deserializer.get(index); 48 | 49 | expect(deserialized).toEqual(value); 50 | }); 51 | 52 | test('symbol', () => { 53 | const serializer = createSerializer(); 54 | 55 | const value = { 56 | a: Symbol('foo'), 57 | b: Symbol(), 58 | }; 59 | 60 | const index = serializer.push(value); 61 | 62 | const deserializer = createDeserializer(serializer.heap); 63 | const deserialized = deserializer.get(index) as typeof value; 64 | 65 | expect(deserialized.a.description).toEqual('foo'); 66 | expect(deserialized.b.description).toEqual(undefined); 67 | }); 68 | 69 | test('multiple values', () => { 70 | const serializer = createSerializer(); 71 | 72 | const arr = [1, 2, 3, 4, 5n, true, 'foo', new Date('2021-01-01')]; 73 | const arrIndex = serializer.push(arr); 74 | 75 | const obj = { 76 | a: arr, 77 | b: new Set(arr), 78 | }; 79 | 80 | const objIndex = serializer.push(obj); 81 | 82 | const deserializer = createDeserializer(serializer.heap); 83 | 84 | const arrDeserialized = deserializer.get(arrIndex) as typeof arr; 85 | const objDeserialized = deserializer.get(objIndex) as typeof obj; 86 | 87 | expect(arrDeserialized).toEqual(arr); 88 | expect(objDeserialized).toEqual(obj); 89 | expect(objDeserialized.a).toBe(arrDeserialized); 90 | }); 91 | -------------------------------------------------------------------------------- /packages/parser/src/parseCodeResponse.test.ts: -------------------------------------------------------------------------------- 1 | import { expect, test } from 'vitest'; 2 | 3 | import { joinLines } from '@agentscript-ai/utils'; 4 | 5 | import { ParseError } from './ParseError.js'; 6 | import { parseCodeResponse } from './parseCodeResponse.js'; 7 | 8 | test('code is wrapped in ```typescript```', () => { 9 | const response = joinLines([ 10 | 'This is a plan:', 11 | '1. Create a function that logs "Hello, world!"', 12 | '2. Call the function', 13 | '', 14 | 'Here is the code:', 15 | '```typescript', 16 | '// Create a function that logs "Hello, world!"', 17 | 'const hello = "Hello, world!";', 18 | '// Call the function', 19 | 'console.log(hello);', 20 | '```', 21 | ]); 22 | 23 | const { plan, code } = parseCodeResponse(response); 24 | 25 | expect(plan).toBe( 26 | joinLines([ 27 | 'This is a plan:', 28 | '1. Create a function that logs "Hello, world!"', 29 | '2. Call the function', 30 | '', 31 | 'Here is the code:', 32 | ]), 33 | ); 34 | 35 | expect(code).toBe( 36 | joinLines([ 37 | '// Create a function that logs "Hello, world!"', 38 | 'const hello = "Hello, world!";', 39 | '// Call the function', 40 | 'console.log(hello);', 41 | ]), 42 | ); 43 | }); 44 | 45 | test('code is nod wrapped in ```typescript```', () => { 46 | const response = joinLines([ 47 | 'This is a plan:', 48 | '1. Create a function that logs "Hello, world!"', 49 | '2. Call the function', 50 | '', 51 | 'Here is the code:', 52 | '// Create a function that logs "Hello, world!"', 53 | 'const hello = "Hello, world!";', 54 | '// Call the function', 55 | 'console.log(hello);', 56 | ]); 57 | 58 | const { plan, code } = parseCodeResponse(response); 59 | 60 | expect(plan).toBe( 61 | joinLines([ 62 | 'This is a plan:', 63 | '1. Create a function that logs "Hello, world!"', 64 | '2. Call the function', 65 | '', 66 | 'Here is the code:', 67 | ]), 68 | ); 69 | 70 | expect(code).toBe( 71 | joinLines([ 72 | '// Create a function that logs "Hello, world!"', 73 | 'const hello = "Hello, world!";', 74 | '// Call the function', 75 | 'console.log(hello);', 76 | ]), 77 | ); 78 | }); 79 | 80 | test('no code found', () => { 81 | const response = 'This is a plan:'; 82 | 83 | expect(() => parseCodeResponse(response)).toThrow(ParseError); 84 | }); 85 | -------------------------------------------------------------------------------- /packages/serializer/src/createDeserializer.ts: -------------------------------------------------------------------------------- 1 | import type { Heap } from './heapTypes.js'; 2 | 3 | /** 4 | * Heap deserializer. 5 | */ 6 | export type Deserializer = ReturnType; 7 | 8 | /** 9 | * Create a heap deserializer. 10 | * @param heap - Heap to deserialize. 11 | * @returns Heap deserializer. 12 | */ 13 | export function createDeserializer(heap: Heap) { 14 | const heapMap = new Map(); 15 | 16 | return { get }; 17 | 18 | function get(index: number) { 19 | if (index === -1) { 20 | return undefined; 21 | } 22 | 23 | return heapMap.get(index) ?? deserialize(index); 24 | } 25 | 26 | function deserialize(index: number) { 27 | const serialized = heap[index]; 28 | 29 | if (!Array.isArray(serialized)) { 30 | heapMap.set(index, serialized); 31 | return serialized; 32 | } 33 | 34 | switch (serialized[0]) { 35 | case 'a': { 36 | const result: unknown[] = []; 37 | // set the result in the heap map for potential recursion 38 | heapMap.set(index, result); 39 | for (let i = 1; i < serialized.length; i++) { 40 | result.push(get(serialized[i] as number)); 41 | } 42 | 43 | return result; 44 | } 45 | 46 | case 'st': { 47 | const result = new Set(); 48 | // set the result in the heap map for potential recursion 49 | heapMap.set(index, result); 50 | for (let i = 1; i < serialized.length; i++) { 51 | result.add(get(serialized[i] as number)); 52 | } 53 | return result; 54 | } 55 | 56 | case 'o': { 57 | const result: Record = {}; 58 | // set the result in the heap map for potential recursion 59 | heapMap.set(index, result); 60 | for (let i = 1; i < serialized.length; i += 2) { 61 | result[serialized[i] as string] = get(serialized[i + 1] as number); 62 | } 63 | return result; 64 | } 65 | 66 | case 'bi': { 67 | return BigInt(serialized[1]); 68 | } 69 | 70 | case 'd': { 71 | return new Date(serialized[1]); 72 | } 73 | 74 | case 'sm': { 75 | return Symbol(serialized[1]); 76 | } 77 | 78 | case 'r': { 79 | return new RegExp(serialized[1], serialized[2]); 80 | } 81 | } 82 | } 83 | } 84 | --------------------------------------------------------------------------------