@tensorpass/aiconnect 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { AiConnect } from './client.ts';
4
4
  export type { AiConnectOptions, ConnectionState, SdkOptions, WebSignInFailure } from './client.ts';
5
5
  export * from './guards/index.ts';
6
6
  export { McpToolSource } from './mcpToolSource.ts';
7
+ export type { McpFetch, McpToolSourceOptions } from './mcpToolSource.ts';
7
8
  export { BROWSER_NAMES, browserOf, visitorBrowser, walletInstallUrl, walletStore, WALLET_STORES, } from './visitorBrowser.ts';
8
9
  export type { BrowserSignals, VisitorBrowser, WalletStore } from './visitorBrowser.ts';
9
10
  export { finalAnswer, runConversation } from './toolLoop.ts';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,2GAA2G;AAC3G,6GAA6G;AAC7G,wDAAwD;AAExD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,GACvF,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["// The site's side of AI Connect: the connection to the visitor's AI through the AI Wallet or, without it,\n// through an account the visitor signs in to on the page, the conversation loop that runs the site's tools\n// under the chat's guards, the site's tools read from its MCP server, and the `fetch` that lets the AI SDK a\n// site already uses answer through the same connection.\n\nexport { contentParts, dataUrl, inlineData, textOf } from './chatContent.ts';\nexport type { InlineData } from './chatContent.ts';\nexport { AiConnect } from './client.ts';\nexport type { AiConnectOptions, ConnectionState, SdkOptions, WebSignInFailure } from './client.ts';\nexport * from './guards/index.ts';\nexport { McpToolSource } from './mcpToolSource.ts';\nexport {\n BROWSER_NAMES, browserOf, visitorBrowser, walletInstallUrl, walletStore, WALLET_STORES,\n} from './visitorBrowser.ts';\nexport type { BrowserSignals, VisitorBrowser, WalletStore } from './visitorBrowser.ts';\nexport { finalAnswer, runConversation } from './toolLoop.ts';\nexport type { ConversationHooks, ConversationOptions } from './toolLoop.ts';\nexport type * from './types.ts';\nexport { WalletRequestError } from './walletProvider.ts';\nexport type { ChatEvent, WalletChatParams, WalletProvider, WalletRefusal } from './walletProvider.ts';\nexport type { WalletFetch } from './wireProtocols/walletFetch.ts';\nexport { finishSignIn } from './webAccounts/finishSignIn.ts';\nexport type { SignInReturn } from './webAccounts/finishSignIn.ts';\nexport { isSignInReturn } from './webAccounts/signInWindow.ts';\nexport { PLAN_GATEWAY } from './webAccounts/tensorPassAccount.ts';\nexport type { PlanAccess, PlanOffer, PlanPrice, PlanSubscription } from './webAccounts/tensorPassPlan.ts';\nexport type { PlanLevel } from './webAccounts/tensorPassAccount.ts';\nexport { WEB_ACCOUNT_NAMES } from './webAccounts/webAccount.ts';\nexport type { WebAccountId } from './webAccounts/webAccountStore.ts';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,2GAA2G;AAC3G,6GAA6G;AAC7G,wDAAwD;AAExD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,GACvF,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["// The site's side of AI Connect: the connection to the visitor's AI through the AI Wallet or, without it,\n// through an account the visitor signs in to on the page, the conversation loop that runs the site's tools\n// under the chat's guards, the site's tools read from its MCP server, and the `fetch` that lets the AI SDK a\n// site already uses answer through the same connection.\n\nexport { contentParts, dataUrl, inlineData, textOf } from './chatContent.ts';\nexport type { InlineData } from './chatContent.ts';\nexport { AiConnect } from './client.ts';\nexport type { AiConnectOptions, ConnectionState, SdkOptions, WebSignInFailure } from './client.ts';\nexport * from './guards/index.ts';\nexport { McpToolSource } from './mcpToolSource.ts';\nexport type { McpFetch, McpToolSourceOptions } from './mcpToolSource.ts';\nexport {\n BROWSER_NAMES, browserOf, visitorBrowser, walletInstallUrl, walletStore, WALLET_STORES,\n} from './visitorBrowser.ts';\nexport type { BrowserSignals, VisitorBrowser, WalletStore } from './visitorBrowser.ts';\nexport { finalAnswer, runConversation } from './toolLoop.ts';\nexport type { ConversationHooks, ConversationOptions } from './toolLoop.ts';\nexport type * from './types.ts';\nexport { WalletRequestError } from './walletProvider.ts';\nexport type { ChatEvent, WalletChatParams, WalletProvider, WalletRefusal } from './walletProvider.ts';\nexport type { WalletFetch } from './wireProtocols/walletFetch.ts';\nexport { finishSignIn } from './webAccounts/finishSignIn.ts';\nexport type { SignInReturn } from './webAccounts/finishSignIn.ts';\nexport { isSignInReturn } from './webAccounts/signInWindow.ts';\nexport { PLAN_GATEWAY } from './webAccounts/tensorPassAccount.ts';\nexport type { PlanAccess, PlanOffer, PlanPrice, PlanSubscription } from './webAccounts/tensorPassPlan.ts';\nexport type { PlanLevel } from './webAccounts/tensorPassAccount.ts';\nexport { WEB_ACCOUNT_NAMES } from './webAccounts/webAccount.ts';\nexport type { WebAccountId } from './webAccounts/webAccountStore.ts';\n"]}
@@ -1,10 +1,15 @@
1
1
  import type { ToolDefinition, ToolSource } from './types.ts';
2
+ export type McpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface McpToolSourceOptions {
4
+ fetch?: McpFetch;
5
+ }
2
6
  export declare class McpToolSource implements ToolSource {
3
7
  private readonly url;
4
8
  private readonly clientName;
9
+ private readonly fetch;
5
10
  private client;
6
11
  private definitions;
7
- constructor(url: string | URL, clientName?: string);
12
+ constructor(url: string | URL, clientName?: string, options?: McpToolSourceOptions);
8
13
  private connected;
9
14
  private connect;
10
15
  listTools(): Promise<ToolDefinition[]>;
@@ -2,15 +2,20 @@
2
2
  // Claude or ChatGPT, so one tool catalog serves the in page AI mode and the provider apps. The client
3
3
  // asks the server which protocol revision it serves: a server of the 2026-07-28 revision, such as a
4
4
  // Mastra `MCPServer`, answers in it, and a server of the 2025 revisions gets the 2025 handshake.
5
+ // A request from the page carries the site's cookies, so a site whose login is a cookie needs no
6
+ // option. A site whose login is a token the page sends itself, such as `Authorization: Bearer`,
7
+ // passes `fetch`, which adds it to each request.
5
8
  import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
6
9
  export class McpToolSource {
7
10
  url;
8
11
  clientName;
12
+ fetch;
9
13
  client = null;
10
14
  definitions = null;
11
- constructor(url, clientName = 'aiconnect') {
15
+ constructor(url, clientName = 'aiconnect', options = {}) {
12
16
  this.url = new URL(url, globalThis.location?.href);
13
17
  this.clientName = clientName;
18
+ this.fetch = options.fetch;
14
19
  }
15
20
  // The connection and the catalog are kept once read. A failed attempt is forgotten, so the next
16
21
  // call asks the server again.
@@ -23,7 +28,7 @@ export class McpToolSource {
23
28
  }
24
29
  async connect() {
25
30
  const client = new Client({ name: this.clientName, version: '0.1.0' }, { versionNegotiation: { mode: 'auto' } });
26
- await client.connect(new StreamableHTTPClientTransport(this.url));
31
+ await client.connect(new StreamableHTTPClientTransport(this.url, { fetch: this.fetch }));
27
32
  return client;
28
33
  }
29
34
  listTools() {
@@ -1 +1 @@
1
- {"version":3,"file":"mcpToolSource.js","sourceRoot":"","sources":["../src/mcpToolSource.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,sGAAsG;AACtG,oGAAoG;AACpG,iGAAiG;AAEjG,OAAO,EAAE,MAAM,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAQrF,MAAM,OAAO,aAAa;IACP,GAAG,CAAM;IACT,UAAU,CAAS;IAC5B,MAAM,GAA2B,IAAI,CAAC;IACtC,WAAW,GAAqC,IAAI,CAAC;IAE7D,YAAY,GAAiB,EAAE,UAAU,GAAG,WAAW;QACrD,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,gGAAgG;IAChG,8BAA8B;IACtB,SAAS;QACf,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACtD,IAAI,CAAC,MAAM,GAAG,IA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S,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,MAAM,IAAI,GAAI,MAAM,CAAC,OAAyB;aAC3C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;aACtC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;aACxB,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,CAAC;CACF","sourcesContent":["// The site's tools, read from its own MCP server. The same server is the connector users add in\n// Claude or ChatGPT, so one tool catalog serves the in page AI mode and the provider apps. The client\n// asks the server which protocol revision it serves: a server of the 2026-07-28 revision, such as a\n// Mastra `MCPServer`, answers in it, and a server of the 2025 revisions gets the 2025 handshake.\n\nimport { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';\nimport type { ToolDefinition, ToolSource } from './types.ts';\n\ninterface TextContent {\n type: string;\n text?: string;\n}\n\nexport class McpToolSource implements ToolSource {\n private readonly url: URL;\n private readonly clientName: string;\n private client: Promise<Client> | null = null;\n private definitions: Promise<ToolDefinition[]> | null = null;\n\n constructor(url: string | URL, clientName = 'aiconnect') {\n this.url = new URL(url, globalThis.location?.href);\n this.clientName = clientName;\n }\n\n // The connection and the catalog are kept once read. A failed attempt is forgotten, so the next\n // call asks the server again.\n private connected(): Promise<Client> {\n this.client ??= this.connect().catch((error: unknown) => {\n this.client = null;\n throw error;\n });\n return this.client;\n }\n\n private async connect(): Promise<Client> {\n const client = new Client({ name: this.clientName, version: '0.1.0' }, { versionNegotiation: { mode: 'auto' } });\n await client.connect(new StreamableHTTPClientTransport(this.url));\n return client;\n }\n\n listTools(): Promise<ToolDefinition[]> {\n this.definitions ??= this.readTools().catch((error: unknown) => {\n this.definitions = null;\n throw error;\n });\n return this.definitions;\n }\n\n private async readTools(): Promise<ToolDefinition[]> {\n const { tools } = await (await this.connected()).listTools();\n return tools.map((tool) => ({\n name: tool.name,\n description: tool.description ?? '',\n inputSchema: tool.inputSchema,\n }));\n }\n\n async callTool(name: string, args: Record<string, unknown>): Promise<string> {\n const client = await this.connected();\n const result = await client.callTool({ name, arguments: args });\n const text = (result.content as TextContent[])\n .filter((part) => part.type === 'text')\n .map((part) => part.text)\n .join('\\n');\n return result.isError ? `Tool error: ${text}` : text;\n }\n}\n"]}
1
+ {"version":3,"file":"mcpToolSource.js","sourceRoot":"","sources":["../src/mcpToolSource.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,sGAAsG;AACtG,oGAAoG;AACpG,iGAAiG;AACjG,iGAAiG;AACjG,gGAAgG;AAChG,iDAAiD;AAEjD,OAAO,EAAE,MAAM,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAerF,MAAM,OAAO,aAAa;IACP,GAAG,CAAM;IACT,UAAU,CAAS;IACnB,KAAK,CAAuB;IACrC,MAAM,GAA2B,IAAI,CAAC;IACtC,WAAW,GAAqC,IAAI,CAAC;IAE7D,YAAY,GAAiB,EAAE,UAAU,GAAG,WAAW,EAAE,UAAgC,EAAE;QACzF,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,gGAAgG;IAChG,8BAA8B;IACtB,SAAS;QACf,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,K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CAAC,OAAyB;aAC3C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;aACtC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;aACxB,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvD,CAAC;CACF","sourcesContent":["// The site's tools, read from its own MCP server. The same server is the connector users add in\n// Claude or ChatGPT, so one tool catalog serves the in page AI mode and the provider apps. The client\n// asks the server which protocol revision it serves: a server of the 2026-07-28 revision, such as a\n// Mastra `MCPServer`, answers in it, and a server of the 2025 revisions gets the 2025 handshake.\n// A request from the page carries the site's cookies, so a site whose login is a cookie needs no\n// option. A site whose login is a token the page sends itself, such as `Authorization: Bearer`,\n// passes `fetch`, which adds it to each request.\n\nimport { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';\nimport type { ToolDefinition, ToolSource } from './types.ts';\n\n// The fetch the client sends its requests with, called with the server's address and the request.\nexport type McpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>;\n\nexport interface McpToolSourceOptions {\n fetch?: McpFetch;\n}\n\ninterface TextContent {\n type: string;\n text?: string;\n}\n\nexport class McpToolSource implements ToolSource {\n private readonly url: URL;\n private readonly clientName: string;\n private readonly fetch: McpFetch | undefined;\n private client: Promise<Client> | null = null;\n private definitions: Promise<ToolDefinition[]> | null = null;\n\n constructor(url: string | URL, clientName = 'aiconnect', options: McpToolSourceOptions = {}) {\n this.url = new URL(url, globalThis.location?.href);\n this.clientName = clientName;\n this.fetch = options.fetch;\n }\n\n // The connection and the catalog are kept once read. A failed attempt is forgotten, so the next\n // call asks the server again.\n private connected(): Promise<Client> {\n this.client ??= this.connect().catch((error: unknown) => {\n this.client = null;\n throw error;\n });\n return this.client;\n }\n\n private async connect(): Promise<Client> {\n const client = new Client({ name: this.clientName, version: '0.1.0' }, { versionNegotiation: { mode: 'auto' } });\n await client.connect(new StreamableHTTPClientTransport(this.url, { fetch: this.fetch }));\n return client;\n }\n\n listTools(): Promise<ToolDefinition[]> {\n this.definitions ??= this.readTools().catch((error: unknown) => {\n this.definitions = null;\n throw error;\n });\n return this.definitions;\n }\n\n private async readTools(): Promise<ToolDefinition[]> {\n const { tools } = await (await this.connected()).listTools();\n return tools.map((tool) => ({\n name: tool.name,\n description: tool.description ?? '',\n inputSchema: tool.inputSchema,\n }));\n }\n\n async callTool(name: string, args: Record<string, unknown>): Promise<string> {\n const client = await this.connected();\n const result = await client.callTool({ name, arguments: args });\n const text = (result.content as TextContent[])\n .filter((part) => part.type === 'text')\n .map((part) => part.text)\n .join('\\n');\n return result.isError ? `Tool error: ${text}` : text;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tensorpass/aiconnect",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Headless SDK: connect a visitor's own AI account and run the site's tools with it.",
5
5
  "type": "module",
6
6
  "sideEffects": false,