Skip to content

Commit 14d0a6c

Browse files
Merge pull request #11 from aipotheosis-labs/feat/replacing-allowed_apps_only-field-in-function-search
feat/replacing-allowed_apps_only-field-in-function-search
2 parents af3ba0f + a0a17e8 commit 14d0a6c

File tree

10 files changed

+29
-34
lines changed

10 files changed

+29
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ const searchResults = await client.handleFunctionCall({
233233
limit: 10
234234
},
235235
linkedAccountOwnerId: 'user123',
236-
allowedAppsOnly: false,
236+
allowedOnly: false,
237237
format: FunctionDefinitionFormat.OPENAI_RESPONSES
238238
});
239239

__tests__/meta_functions/aci_handle_execution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('AI Integration Tests', () => {
6363
functionName: searchToolCall.name,
6464
functionArguments: searchArguments,
6565
linkedAccountOwnerId: 'test-user-id',
66-
allowedAppsOnly: false,
66+
allowedOnly: false,
6767
format: FunctionDefinitionFormat.OPENAI_RESPONSES,
6868
});
6969

__tests__/meta_functions/aci_search_functions_mock.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('ACI_SEARCH_FUNCTIONS Meta Function', () => {
105105
functionName: 'ACI_SEARCH_FUNCTIONS',
106106
functionArguments: { intent: 'test search' },
107107
linkedAccountOwnerId,
108-
allowedAppsOnly: true,
108+
allowedOnly: true,
109109
});
110110

111111
expect(mock.history.get.length).toBe(1);

examples/basic-usage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function main() {
1818
console.log('Searching for apps...');
1919
const apps = await client.apps.search({
2020
intent: 'I want to search the web',
21-
allowed_apps_only: false,
21+
allowed_only: false,
2222
include_functions: true,
2323
limit: 5,
2424
});
@@ -111,7 +111,7 @@ async function main() {
111111
console.log('\nSearching functions with OPENAI_RESPONSES format...');
112112
const searchResults = await client.functions.search({
113113
intent: 'I want to search the web',
114-
allowed_apps_only: false,
114+
allowed_only: false,
115115
limit: 5,
116116
format: FunctionDefinitionFormat.OPENAI_RESPONSES,
117117
});

examples/openai-dynamic-tool.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function main() {
6666
functionName: searchToolCall.name,
6767
functionArguments: searchArguments,
6868
linkedAccountOwnerId: 'your-user-id', // Replace with actual user ID
69-
allowedAppsOnly: false,
69+
allowedOnly: false,
7070
format: FunctionDefinitionFormat.OPENAI_RESPONSES,
7171
});
7272

@@ -107,7 +107,6 @@ async function main() {
107107
functionName: executeToolCall.name,
108108
functionArguments: executeArguments,
109109
linkedAccountOwnerId: process.env.LINKED_ACCOUNT_OWNER_ID as string,
110-
allowedAppsOnly: false,
111110
format: FunctionDefinitionFormat.OPENAI_RESPONSES,
112111
});
113112

examples/openai-static-tool.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ async function main() {
6161
functionName: toolCall.name,
6262
functionArguments: JSON.parse(toolCall.arguments),
6363
linkedAccountOwnerId: LINKED_ACCOUNT_OWNER_ID,
64-
allowedAppsOnly: true,
6564
format: FunctionDefinitionFormat.OPENAI_RESPONSES,
6665
});
6766

src/client.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ import {
1919
import { FunctionDefinitionFormat } from './types/functions';
2020

2121
interface HandleFunctionCallParams {
22+
/** Name of the function to be called */
2223
functionName: string;
24+
/** Dictionary containing all input arguments required to execute the specified function */
2325
functionArguments: Record<string, any>;
26+
/** Specifies with credentials of which linked account the function should be executed */
2427
linkedAccountOwnerId?: string;
28+
/** @deprecated Use allowedOnly instead. If true, only returns enabled functions of apps that are allowed to be used by the agent/accessor */
2529
allowedAppsOnly?: boolean;
30+
/** If true, only returns enabled functions of apps that are allowed to be used by the agent/accessor. If false, returns all functions of all apps. */
31+
allowedOnly?: boolean;
32+
/** Format of the function definition to return */
2633
format?: FunctionDefinitionFormat;
2734
}
2835

@@ -97,22 +104,18 @@ export class ACI {
97104
*
98105
* It supports handling built-in meta functions (ACI_SEARCH_FUNCTIONS, ACI_EXECUTE_FUNCTION) and also handling
99106
* executing third-party functions directly.
100-
*
101-
* @param functionName - Name of the function to be called
102-
* @param functionArguments - Object containing the input arguments for the function
103-
* @param linkedAccountOwnerId - Specifies the end-user (account owner) on behalf of whom to execute functions
104-
* @param allowedAppsOnly - If true, only returns functions/apps that are allowed to be used by the agent/accessor
105-
* @param format - Format of the function definition (for ACI_SEARCH_FUNCTIONS)
107+
*
108+
* @param {HandleFunctionCallParams} params
106109
* @returns The result of the function execution (varies based on the function)
107110
*/
108111
public async handleFunctionCall(params: HandleFunctionCallParams): Promise<any> {
109-
const { functionName, functionArguments, linkedAccountOwnerId, allowedAppsOnly, format } =
112+
const { functionName, functionArguments, linkedAccountOwnerId, allowedOnly, allowedAppsOnly, format } =
110113
params;
111114

112115
if (functionName === ACI_SEARCH_FUNCTIONS) {
113116
const functions = await this.functions.search({
114117
...functionArguments,
115-
allowed_apps_only: allowedAppsOnly,
118+
allowed_only: allowedOnly ?? allowedAppsOnly,
116119
format: format,
117120
});
118121

src/resource/functions.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
FunctionExecutionResult,
55
FunctionDefinition,
66
FunctionDefinitionFormat,
7+
SearchFunctionsParams,
78
} from '../types/functions';
89
import { ValidationError } from '../exceptions';
910
import { FunctionsSchema } from '../schemas';
@@ -25,32 +26,22 @@ export class FunctionsResource extends APIResource {
2526
* Searches for functions based on specified criteria.
2627
* TODO: return specific type for returned functions based on FunctionDefinitionFormat
2728
*
28-
* @param params - Search parameters
29-
* @param params.app_names - List of app names to filter functions by
30-
* @param params.intent - Search results will be sorted by relevance to this intent
31-
* @param params.allowed_apps_only - If true, only returns functions of apps that are allowed by the agent/accessor
32-
* @param params.format - Format of the function definitions to return
33-
* @param params.limit - For pagination, maximum number of functions to return
34-
* @param params.offset - For pagination, number of functions to skip before returning results
29+
* @param {SearchFunctionsParams} params
3530
* @returns Promise resolving to an array of function definitions matching the search criteria
3631
* @throws Various exceptions for different HTTP status codes
3732
*/
38-
async search(params: {
39-
app_names?: string[];
40-
intent?: string;
41-
allowed_apps_only?: boolean;
42-
format?: FunctionDefinitionFormat;
43-
limit?: number;
44-
offset?: number;
45-
}): Promise<FunctionDefinition[]> {
33+
async search(params: SearchFunctionsParams): Promise<FunctionDefinition[]> {
4634
try {
4735
// Validate params with Zod
4836
const validatedParams = this.validateInput(FunctionsSchema.search, params);
4937

38+
const { allowed_only, allowed_apps_only, format, ...rest } = validatedParams;
39+
5040
// Create a new params object with the format converted to lowercase
5141
const apiParams = {
52-
...validatedParams,
53-
format: this.formatToLowercase(validatedParams.format),
42+
...rest,
43+
allowed_only: allowed_only ?? allowed_apps_only,
44+
format: this.formatToLowercase(format),
5445
};
5546

5647
const response = await this.client.get('/functions/search', {

src/schemas/functions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const FunctionsSchema = {
66
app_names: z.array(z.string()).optional(),
77
intent: z.string().optional(),
88
allowed_apps_only: z.boolean().optional(),
9+
allowed_only: z.boolean().optional(),
910
format: z.nativeEnum(FunctionDefinitionFormat).optional(),
1011
limit: z.number().int().positive().optional(),
1112
offset: z.number().int().nonnegative().optional(),

src/types/functions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ export interface SearchFunctionsParams {
6666
app_names?: string[];
6767
/** Intent to search for relevant functions */
6868
intent?: string;
69-
/** If true, only returns functions/apps that are allowed to be used by the agent/accessor */
69+
/** @deprecated Use allowed_only instead. If true, only returns enabled functions of apps that are allowed to be used by the agent/accessor */
7070
allowed_apps_only?: boolean;
71+
/** If true, only returns enabled functions of apps that are allowed to be used by the agent/accessor. If false, returns all functions of all apps. */
72+
allowed_only?: boolean;
7173
/** Format of the function definition to return */
7274
format?: FunctionDefinitionFormat;
7375
/** Maximum number of functions to return */

0 commit comments

Comments
 (0)