Skip to content

Commit eab95cb

Browse files
committed
docs(examples): update examples to use JsonObject type
Update example files to work with the new JsonObject type: examples/meta-tools.ts: - Import JsonObject from @stackone/ai - Add explicit type annotation for intents array using `as const satisfies Array<{ intent: string; params: JsonObject }>` examples/tanstack-ai-integration.test.ts: - Simplify test structure and remove redundant assertions
1 parent 7f106cc commit eab95cb

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

examples/meta-tools.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import process from 'node:process';
1010
import { openai } from '@ai-sdk/openai';
11-
import { StackOneToolSet, Tools } from '@stackone/ai';
11+
import { type JsonObject, StackOneToolSet, Tools } from '@stackone/ai';
1212
import { generateText, stepCountIs } from 'ai';
1313

1414
const apiKey = process.env.STACKONE_API_KEY;
@@ -160,7 +160,7 @@ const directMetaToolUsage = async (): Promise<void> => {
160160

161161
try {
162162
// Prepare parameters based on the tool's schema
163-
let params: Record<string, unknown> = {};
163+
let params = {} satisfies JsonObject;
164164
if (firstTool.name === 'bamboohr_list_employees') {
165165
params = { limit: 5 };
166166
} else if (firstTool.name === 'bamboohr_create_employee') {
@@ -173,7 +173,7 @@ const directMetaToolUsage = async (): Promise<void> => {
173173

174174
const result = await executeTool.execute({
175175
toolName: firstTool.name,
176-
params: params,
176+
params,
177177
});
178178

179179
console.log('Execution result:', JSON.stringify(result, null, 2));
@@ -209,7 +209,7 @@ const dynamicToolRouter = async (): Promise<void> => {
209209
const metaTools = await combinedTools.metaTools();
210210

211211
// Create a router function that finds and executes tools based on intent
212-
const routeAndExecute = async (intent: string, params: Record<string, unknown> = {}) => {
212+
const routeAndExecute = async (intent: string, params: JsonObject = {}) => {
213213
const filterTool = metaTools.getTool('meta_search_tools');
214214
const executeTool = metaTools.getTool('meta_execute_tool');
215215
if (!filterTool || !executeTool) throw new Error('Meta tools not found');
@@ -221,18 +221,18 @@ const dynamicToolRouter = async (): Promise<void> => {
221221
minScore: 0.5,
222222
});
223223

224-
const tools = searchResult.tools as Array<{ name: string; score: number }>;
225-
if (tools.length === 0) {
224+
const tools = searchResult.tools;
225+
if (!Array.isArray(tools) || tools.length === 0) {
226226
return { error: 'No relevant tools found for the given intent' };
227227
}
228228

229-
const selectedTool = tools[0];
229+
const selectedTool = tools[0] as { name: string; score: number };
230230
console.log(`Routing to: ${selectedTool.name} (score: ${selectedTool.score.toFixed(2)})`);
231231

232232
// Execute the selected tool
233233
return await executeTool.execute({
234234
toolName: selectedTool.name,
235-
params: params,
235+
params,
236236
});
237237
};
238238

@@ -244,7 +244,7 @@ const dynamicToolRouter = async (): Promise<void> => {
244244
params: { name: 'Jane Smith', email: 'jane@example.com' },
245245
},
246246
{ intent: 'Find recruitment candidates', params: { status: 'active' } },
247-
];
247+
] as const satisfies Array<{ intent: string; params: JsonObject }>;
248248

249249
for (const { intent, params } of intents) {
250250
console.log(`\nIntent: "${intent}"`);

examples/tanstack-ai-integration.test.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,19 @@ describe('tanstack-ai-integration example e2e', () => {
3333

3434
// Get a specific tool
3535
const employeeTool = tools.getTool('bamboohr_get_employee');
36-
expect(employeeTool).toBeDefined();
36+
assert(employeeTool, 'Expected bamboohr_get_employee tool to exist');
3737

3838
// Create TanStack AI compatible tool wrapper
3939
// Use toJsonSchema() to get the parameter schema in JSON Schema format
4040
const getEmployeeTool = {
41-
name: employeeTool!.name,
42-
description: employeeTool!.description,
43-
inputSchema: employeeTool!.toJsonSchema(),
44-
execute: async (args: Record<string, unknown>) => {
45-
return employeeTool!.execute(args);
46-
},
41+
name: employeeTool.name,
42+
description: employeeTool.description,
43+
inputSchema: employeeTool.toJsonSchema(),
44+
execute: employeeTool.execute.bind(employeeTool),
4745
};
4846

4947
expect(getEmployeeTool.name).toBe('bamboohr_get_employee');
50-
expect(getEmployeeTool.description).toContain('employee');
51-
expect(getEmployeeTool.inputSchema).toBeDefined();
5248
expect(getEmployeeTool.inputSchema.type).toBe('object');
53-
expect(typeof getEmployeeTool.execute).toBe('function');
5449
});
5550

5651
it('should execute tool directly', async () => {
@@ -68,9 +63,7 @@ describe('tanstack-ai-integration example e2e', () => {
6863
name: employeeTool.name,
6964
description: employeeTool.description,
7065
inputSchema: employeeTool.toJsonSchema(),
71-
execute: async (args: Record<string, unknown>) => {
72-
return employeeTool.execute(args);
73-
},
66+
execute: employeeTool.execute.bind(employeeTool),
7467
};
7568

7669
// Execute the tool directly to verify it works

0 commit comments

Comments
 (0)