docs: add integrations, remove package @xsai-ext/mcp (#92)
* docs: add integrations * chore(mcp): remove package
This commit is contained in:
1 parent
0410de21f1
commit
9a8b11febb
16 files changed
+286
-675
No files matched your search
@@ -3,6 +3,7 @@ ignorePaths: []
|
||||
dictionaryDefinitions: []
|
||||
dictionaries: []
|
||||
words:
|
||||
- agentic
|
||||
- all-minilm
|
||||
- arktype
|
||||
- automd
|
||||
@@ -12,6 +13,7 @@ words:
|
||||
- changelogithub
|
||||
- codestral
|
||||
- cognitivecomputations
|
||||
- composio
|
||||
- deepinfra
|
||||
- deepseek
|
||||
- elevenlabs
|
||||
|
||||
@@ -14,7 +14,7 @@ export const baseOptions: BaseLayoutProps = {
|
||||
links: [
|
||||
{
|
||||
active: 'nested-url',
|
||||
text: 'Documentation',
|
||||
text: 'Docs',
|
||||
url: '/docs',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Agentic
|
||||
description: Agentic adapter for xsAI.
|
||||
---
|
||||
|
||||
> This code is untested, feel free to test it yourself and provide feedback.
|
||||
|
||||
```package-install
|
||||
npm i @agentic/core @xsai/tool
|
||||
```
|
||||
|
||||
```ts
|
||||
import { type AIFunctionLike, AIFunctionSet } from '@agentic/core'
|
||||
import { tool } from '@xsai/tool'
|
||||
|
||||
export const createTools = (...aiFunctionLikeTools: AIFunctionLike[]) =>
|
||||
Promise.all(new AIFunctionSet(aiFunctionLikeTools)
|
||||
.map(fn => await tool({
|
||||
name: fn.spec.name,
|
||||
description: fn.spec.description,
|
||||
parameters: fn.inputSchema,
|
||||
execute: fn.impl
|
||||
})))
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```ts
|
||||
import 'dotenv/config'
|
||||
|
||||
import { WeatherClient } from '@agentic/weather'
|
||||
import { generateText } from '@xsai/generate-text'
|
||||
import { env } from 'node:process'
|
||||
|
||||
import { createTools } from './utils/create-tools'
|
||||
|
||||
async function main() {
|
||||
const weather = new WeatherClient()
|
||||
|
||||
const result = await generateText({
|
||||
apiKey: env.OPENAI_API_KEY!,
|
||||
baseURL: 'https://api.openai.com/v1/',
|
||||
maxSteps: 5,
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
content: 'You are a helpful assistant. Be as concise as possible.',
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: 'What is the weather in San Francisco?'
|
||||
},
|
||||
],
|
||||
model: 'gpt-4o-mini',
|
||||
tools: createTools(weather),
|
||||
toolChoice: 'required',
|
||||
temperature: 0,
|
||||
})
|
||||
|
||||
console.log(result.toolResults[0])
|
||||
}
|
||||
|
||||
await main()
|
||||
```
|
||||
@@ -0,0 +1,166 @@
|
||||
---
|
||||
title: Composio
|
||||
description: Composio adapter for xsAI.
|
||||
---
|
||||
|
||||
> This code is untested, feel free to test it yourself and provide feedback.
|
||||
|
||||
```package-install
|
||||
npm i composio-core zod @xsai/shared-chat @xsai/tool
|
||||
```
|
||||
|
||||
```ts
|
||||
import type { Tool } from '@xsai/shared-chat'
|
||||
|
||||
import { tool } from '@xsai/tool'
|
||||
import { ComposioToolSet, RawActionData } from 'composio-core'
|
||||
import { z } from 'zod'
|
||||
|
||||
type Optional<T> = T | null
|
||||
|
||||
const ZExecuteToolCallParams = z.object({
|
||||
actions: z.array(z.string()).optional(),
|
||||
apps: z.array(z.string()).optional(),
|
||||
params: z.record(z.any()).optional(),
|
||||
entityId: z.string().optional(),
|
||||
useCase: z.string().optional(),
|
||||
useCaseLimit: z.number().optional(),
|
||||
connectedAccountId: z.string().optional(),
|
||||
tags: z.array(z.string()).optional(),
|
||||
filterByAvailableApps: z.boolean().optional().default(false),
|
||||
})
|
||||
|
||||
export class XSAIToolSet extends ComposioToolSet {
|
||||
fileName: string = 'js/src/frameworks/xsai.ts'
|
||||
|
||||
constructor(
|
||||
config: {
|
||||
apiKey?: Optional<string>
|
||||
baseUrl?: Optional<string>
|
||||
entityId?: string
|
||||
connectedAccountIds?: Record<string, string>
|
||||
allowTracing?: boolean
|
||||
} = {}
|
||||
) {
|
||||
super({
|
||||
apiKey: config.apiKey || null,
|
||||
baseUrl: config.baseUrl || null,
|
||||
runtime: null,
|
||||
entityId: config.entityId || "default",
|
||||
connectedAccountIds: config.connectedAccountIds,
|
||||
allowTracing: config.allowTracing || false,
|
||||
});
|
||||
}
|
||||
|
||||
private async generateTool(
|
||||
schema: RawActionData,
|
||||
entityId: Optional<string> = null
|
||||
) {
|
||||
return tool({
|
||||
name: schema.name
|
||||
description: schema.description,
|
||||
parameters: schema.parameters,
|
||||
execute: async (params) => await this.executeToolCall(
|
||||
{
|
||||
name: schema.name,
|
||||
arguments: JSON.stringify(params),
|
||||
},
|
||||
entityId || this.entityId
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async getTools(
|
||||
filters: {
|
||||
actions?: Array<string>;
|
||||
apps?: Array<string>;
|
||||
tags?: Optional<Array<string>>;
|
||||
useCase?: Optional<string>;
|
||||
useCaseLimit?: Optional<number>;
|
||||
filterByAvailableApps?: Optional<boolean>;
|
||||
integrationId?: Optional<string>;
|
||||
},
|
||||
entityId: Optional<string> = null
|
||||
): Promise<Record<string, Tool>> {
|
||||
const {
|
||||
apps,
|
||||
tags,
|
||||
useCase,
|
||||
useCaseLimit,
|
||||
filterByAvailableApps,
|
||||
actions,
|
||||
} = ZExecuteToolCallParams.parse(filters)
|
||||
|
||||
const actionsList = await this.getToolsSchema(
|
||||
{
|
||||
apps,
|
||||
actions,
|
||||
tags,
|
||||
useCase,
|
||||
useCaseLimit,
|
||||
filterByAvailableApps,
|
||||
},
|
||||
entityId,
|
||||
filters.integrationId
|
||||
)
|
||||
|
||||
const tools: Record<string, Tool> = {}
|
||||
actionsList.forEach((actionSchema) => {
|
||||
tools[actionSchema.name!] = await this.generateTool(
|
||||
actionSchema,
|
||||
entityId
|
||||
)
|
||||
})
|
||||
|
||||
return tools
|
||||
}
|
||||
|
||||
async executeToolCall(
|
||||
tool: { name: string; arguments: unknown },
|
||||
entityId: Optional<string> = null
|
||||
): Promise<string> {
|
||||
const toolSchema = await this.getToolsSchema({ actions: [tool.name] })
|
||||
const appName = toolSchema[0]?.appName?.toLowerCase()
|
||||
const connectedAccountId = appName && this.connectedAccountIds?.[appName]
|
||||
|
||||
return JSON.stringify(
|
||||
await this.executeAction({
|
||||
action: tool.name,
|
||||
params:
|
||||
typeof tool.arguments === "string"
|
||||
? JSON.parse(tool.arguments)
|
||||
: tool.arguments,
|
||||
entityId: entityId || this.entityId,
|
||||
connectedAccountId: connectedAccountId,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```ts
|
||||
import { generateText } from '@xsai/generate-text'
|
||||
import { env } from 'node:process'
|
||||
|
||||
import { XSAIToolSet } from './utils/xsai-tool-set'
|
||||
|
||||
const toolset = new XSAIToolSet()
|
||||
|
||||
const tools = await toolset.getTools({ apps: ["github"] })
|
||||
|
||||
const output = await generateText({
|
||||
apiKey: env.OPENAI_API_KEY!,
|
||||
baseURL: 'https://api.openai.com/v1/',
|
||||
maxSteps: 5,
|
||||
model: 'gpt-4o-mini',
|
||||
tools,
|
||||
messages: [{
|
||||
role: 'user',
|
||||
prompt: 'Star the repository "moeru-ai/xsai"',
|
||||
}]
|
||||
})
|
||||
|
||||
console.log(output.text)
|
||||
```
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
title: Model Context Protocol
|
||||
description: Model Context Protocol adapter for xsAI.
|
||||
---
|
||||
|
||||
> This code is untested, feel free to test it yourself and provide feedback.
|
||||
|
||||
```package-install
|
||||
npm i @modelcontextprotocol/sdk @xsai/tool
|
||||
```
|
||||
|
||||
```ts
|
||||
import type { Client } from '@modelcontextprotocol/sdk'
|
||||
import { tool } from '@xsai/tool'
|
||||
|
||||
export const getTools = async (mcpServers: Record<string, Client>) =>
|
||||
Promise.all(
|
||||
Object.entries(mcpServers)
|
||||
.map(async ([serverName, client]) => client
|
||||
.listTools()
|
||||
.then(({ tools }) => tools.map(({ description, inputSchema, name }) => ({
|
||||
execute: async args => client.callTool({
|
||||
arguments: args as Record<string, unknown>,
|
||||
name,
|
||||
}).then(res => JSON.stringify(res)),
|
||||
function: {
|
||||
description,
|
||||
name: name === serverName ? name : `${serverName}_${name}`,
|
||||
parameters: inputSchema,
|
||||
strict: true,
|
||||
},
|
||||
type: 'function',
|
||||
})))),
|
||||
).then(tools => tools.flat())
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```ts
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
||||
|
||||
import { getTools } from './utils/get-tools'
|
||||
|
||||
const transport = new StdioClientTransport({ command: 'node', args: ['server.js'] })
|
||||
const client = new Client({ name: 'example-client', version: '1.0.0' })
|
||||
|
||||
await client.connect(transport)
|
||||
|
||||
const tools = await getTools({ example: client })
|
||||
```
|
||||
@@ -4,6 +4,8 @@
|
||||
"index",
|
||||
"---Packages---",
|
||||
"...packages",
|
||||
"---Integrations---",
|
||||
"...integrations",
|
||||
"---References---",
|
||||
"references"
|
||||
]
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
"[xsai](https://tsdocs.dev/search/docs/xsai)",
|
||||
"[xsfetch](https://tsdocs.dev/search/docs/xsfetch)",
|
||||
"[xsschema](https://tsdocs.dev/search/docs/xsschema)",
|
||||
"[@xsai-ext/mcp](https://tsdocs.dev/search/docs/@xsai-ext/mcp)",
|
||||
"[@xsai-ext/providers-cloud](https://tsdocs.dev/search/docs/@xsai-ext/providers-cloud)",
|
||||
"[@xsai-ext/providers-local](https://tsdocs.dev/search/docs/@xsai-ext/providers-local)",
|
||||
"[@xsai-ext/shared-providers](https://tsdocs.dev/search/docs/@xsai-ext/shared-providers)"
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
{
|
||||
"name": "@xsai-ext/mcp",
|
||||
"type": "module",
|
||||
"version": "0.1.0-beta.9",
|
||||
"private": true,
|
||||
"description": "extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.",
|
||||
"author": "Moeru AI",
|
||||
"license": "MIT",
|
||||
"homepage": "https://xsai.js.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/moeru-ai/xsai.git",
|
||||
"directory": "packages-ext/mcp"
|
||||
},
|
||||
"bugs": "https://github.com/moeru-ai/xsai/issues",
|
||||
"keywords": [
|
||||
"xsai",
|
||||
"openai",
|
||||
"ai"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./sse": "./src/sse.ts",
|
||||
"./stdio": "./src/stdio.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./sse": {
|
||||
"types": "./dist/sse.d.ts",
|
||||
"default": "./dist/sse.js"
|
||||
},
|
||||
"./stdio": {
|
||||
"types": "./dist/stdio.d.ts",
|
||||
"default": "./dist/stdio.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@modelcontextprotocol/sdk": "catalog:"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xsai/shared-chat": "workspace:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@modelcontextprotocol/sdk": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './utils/get-tools'
|
||||
@@ -1,23 +0,0 @@
|
||||
import type { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js'
|
||||
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
||||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
||||
|
||||
export type CreateSSEClientsOptions = Record<string, SSEClientTransportOptions & {
|
||||
url: URL
|
||||
}>
|
||||
|
||||
/** @experimental */
|
||||
export const createSSEClients = async (mcpServers: CreateSSEClientsOptions, version: string = '1.0.0'): Promise<Record<string, Client>> =>
|
||||
Object.fromEntries(
|
||||
await Promise.all(
|
||||
Object.entries(mcpServers)
|
||||
.map(async ([serverName, { url, ...options }]) => {
|
||||
const transport = new SSEClientTransport(url, options)
|
||||
const client = new Client({ name: serverName, version })
|
||||
await client.connect(transport)
|
||||
|
||||
return [serverName, client] as const
|
||||
}),
|
||||
),
|
||||
)
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js'
|
||||
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
||||
import { stderr } from 'node:process'
|
||||
|
||||
export type CreateStdioClientsOptions = Record<string, StdioServerParameters>
|
||||
|
||||
/** @experimental */
|
||||
export const createStdioClients = async (mcpServers: CreateStdioClientsOptions, version: string = '1.0.0'): Promise<Record<string, Client>> =>
|
||||
Object.fromEntries(
|
||||
await Promise.all(
|
||||
Object.entries(mcpServers)
|
||||
.map(async ([serverName, server]) => {
|
||||
const transport = new StdioClientTransport({ ...server, stderr })
|
||||
const client = new Client({ name: serverName, version })
|
||||
await client.connect(transport)
|
||||
|
||||
return [serverName, client] as const
|
||||
}),
|
||||
),
|
||||
)
|
||||
@@ -1,28 +0,0 @@
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
||||
import type { Tool } from '@xsai/shared-chat'
|
||||
|
||||
/** @internal */
|
||||
const getAllToolsFromClient = async (serverName: string, client: Client): Promise<Tool[]> =>
|
||||
client
|
||||
.listTools()
|
||||
.then(({ tools }) => tools.map(({ description, inputSchema, name }) => ({
|
||||
execute: async args => client.callTool({
|
||||
arguments: args as Record<string, unknown>,
|
||||
name,
|
||||
// eslint-disable-next-line sonarjs/no-nested-functions
|
||||
}).then(res => JSON.stringify(res)),
|
||||
function: {
|
||||
description,
|
||||
name: name === serverName ? name : `${serverName}_${name}`,
|
||||
parameters: inputSchema,
|
||||
strict: true,
|
||||
},
|
||||
type: 'function',
|
||||
})))
|
||||
|
||||
/** @experimental */
|
||||
export const getAllTools = async (mcpServers: Record<string, Client>): Promise<Tool[]> =>
|
||||
Promise.all(
|
||||
Object.entries(mcpServers)
|
||||
.map(async ([serverName, client]) => getAllToolsFromClient(serverName, client)),
|
||||
).then(tools => tools.flat())
|
||||
@@ -1,12 +0,0 @@
|
||||
import { defineConfig } from 'tsup'
|
||||
|
||||
import defaults from '../../tsup.config'
|
||||
|
||||
export default defineConfig({
|
||||
...defaults,
|
||||
entry: [
|
||||
'src/index.ts',
|
||||
'src/sse.ts',
|
||||
'src/stdio.ts',
|
||||
],
|
||||
})
|
||||
Generated
-523
File diff suppressed because it is too large.
Load diff
@@ -12,5 +12,3 @@ catalog:
|
||||
zod-to-json-schema: ^3.24.3
|
||||
|
||||
type-fest: ^4.35.0
|
||||
|
||||
'@modelcontextprotocol/sdk': ^1.6.1
|
||||
@@ -3,7 +3,6 @@
|
||||
"include": [
|
||||
"packages/**/src",
|
||||
"packages/**/test",
|
||||
"packages-ext/mcp/src",
|
||||
"packages-ext/providers-cloud/src",
|
||||
"packages-ext/providers-local/src",
|
||||
"packages-ext/shared-providers/src"
|
||||
|
||||
Reference in new issue
Block a user