Chat, tool and generation types
The messages, content parts, tools, JSON Schema, generation options, tool choice and response format that @tensorpass/aiconnect exchanges with AI Wallet, with their types generated from the source.
Part of the @tensorpass/aiconnect reference. The tables are generated from the package's TypeScript source each time the docs are built. Open a row to see its full type.
Chat types
The chat format the site and the wallet share. The wallet translates it to each provider's own format and back. ChatMessage is a union of four messages, one per role:
Prop
Type
SystemMessage
Prop
Type
UserMessage
Prop
Type
content is a string, or a list of parts when the message carries images.
AssistantMessage
Prop
Type
ToolMessage
Prop
Type
A ToolMessage answers the ToolCall whose id it carries in toolCallId.
ToolCall
Prop
Type
ContentPart
A union of two parts, one per type:
Prop
Type
TextPart
Prop
Type
ImagePart
Prop
Type
url is a data: URL, or an https URL for the providers that fetch images themselves.
const messages: ChatMessage[] = [
{ role: 'system', content: 'You recommend books from this site\'s catalog.' },
{ role: 'user', content: 'A calm book for tonight' },
{ role: 'assistant', content: '', toolCalls: [{ id: 'call_1', name: 'search_books', arguments: { mood: 'calm' } }] },
{ role: 'tool', toolCallId: 'call_1', name: 'search_books', content: '[{"title":"Piranesi"}]' },
];
const cover: ContentPart[] = [
{ type: 'text', text: 'Which book has this cover?' },
{ type: 'image', url: 'https://example.com/covers/piranesi.jpg' },
];
messages.push({ role: 'user', content: cover });Tool types
The tools a site offers. Any object that implements ToolSource can feed runConversation and useAiChat.
ToolDefinition
Prop
Type
ToolSource
Prop
Type
JsonSchema
The type of inputSchema, a JSON Schema object:
Prop
Type
const empty: JsonSchema = { type: 'object', properties: {} };
const clock: ToolSource = {
listTools: async () => [{
name: 'current_time',
description: 'The current time of the visitor\'s computer, in UTC, as an ISO 8601 string.',
inputSchema: empty,
}],
callTool: async () => new Date().toISOString(),
};GenerationOptions
What the site asks of the answer, in ChatRequest.options.
Prop
Type
maxTokens, temperature, topP and stop are hints: the account's connector leaves out those its provider refuses. toolChoice and responseFormat always reach the provider.
GenerationHint
The names of the hints, each with the type of its option:
Prop
Type
ToolChoice
Whether the model may answer in text, must call a tool, or must call the named one. A tool choice is one of these strings:
Prop
Type
Or an object that names the tool:
Prop
Type
ResponseFormat
An answer in JSON, held to schema when one is given. strict asks the providers that offer it to refuse any schema they cannot enforce exactly.
Prop
Type
const { message, finishReason } = await state.session.chat({
messages: [{ role: 'user', content: 'Three calm books, as JSON.' }],
options: {
maxTokens: 400,
toolChoice: 'none',
responseFormat: {
type: 'json',
name: 'books',
schema: { type: 'object', properties: { titles: { type: 'array', items: { type: 'string' } } } },
},
},
});
const { titles } = JSON.parse(message.content) as { titles: string[] };
// The hints a ChatGPT plan account refuses, which its connector leaves out of every call.
const refusedByChatGpt: GenerationHint[] = ['maxTokens', 'temperature', 'topP'];Conversations
runConversation, the tool loop of @tensorpass/aiconnect, with its options and hooks, finalAnswer and the chat content helpers, with their types generated from the source.
Sessions and the wallet
The provider session, chat request and response, finish reasons and usage, WalletLink, the WalletProvider interface a wallet implements and its chat events, with their types generated from the source.