Skip to content

Commit eafb09b

Browse files
committed
patch
1 parent 17ffdaa commit eafb09b

2 files changed

Lines changed: 91 additions & 27 deletions

File tree

src/functions/test/overrideAdvisor.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ const METHOD_NAME = "function.test.overrideAdvisor";
99
/**
1010
* Type representing a partial advisor schema configuration.
1111
* Used for advisor service configuration with optional properties.
12-
*/
12+
*/
1313
type TAdvisorSchema<T = string> = {
1414
advisorName: IAdvisorSchema<T>["advisorName"];
1515
} & Partial<IAdvisorSchema<T>>;
1616

1717
/**
1818
* Function implementation
19-
*/
20-
const overrideAdvisorInternal = beginContext((publicAdvisorSchema: TAdvisorSchema) => {
21-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
22-
swarm.loggerService.log(METHOD_NAME, {
23-
advisorSchema: publicAdvisorSchema,
24-
});
19+
*/
20+
const overrideAdvisorInternal = beginContext(
21+
(publicAdvisorSchema: TAdvisorSchema) => {
22+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
23+
swarm.loggerService.log(METHOD_NAME, {
24+
advisorSchema: publicAdvisorSchema,
25+
});
2526

26-
const advisorSchema = removeUndefined(publicAdvisorSchema);
27+
const advisorSchema = removeUndefined(publicAdvisorSchema);
2728

28-
return swarm.advisorSchemaService.override(advisorSchema.advisorName, advisorSchema);
29-
});
29+
return swarm.advisorSchemaService.override(
30+
advisorSchema.advisorName,
31+
advisorSchema
32+
);
33+
}
34+
);
3035

3136
/**
3237
* Overrides an existing advisor schema in the swarm system with a new or partial schema.
@@ -55,7 +60,9 @@ const overrideAdvisorInternal = beginContext((publicAdvisorSchema: TAdvisorSchem
5560
* advisorName: "StructuredAdvisor",
5661
* getChat: async (args) => `Query: ${args.message.query}`
5762
* });
58-
*/
63+
*/
5964
export function overrideAdvisor<T = string>(advisorSchema: TAdvisorSchema<T>) {
60-
return overrideAdvisorInternal(advisorSchema as TAdvisorSchema);
65+
return overrideAdvisorInternal(
66+
advisorSchema as TAdvisorSchema
67+
) as TAdvisorSchema<T>;
6168
}

types.d.ts

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10296,9 +10296,35 @@ interface IFetchInfoToolParams<T = Record<string, any>> extends IFetchInfoParams
1029610296
declare function addFetchInfo<T = Record<string, any>>(params: IFetchInfoToolParams<T>): string;
1029710297

1029810298
/**
10299-
* Adds an advisor schema to the system
10299+
* Adds an advisor schema to the system.
10300+
* Registers the advisor with validation and schema services, making it available for chat operations.
10301+
*
1030010302
* @function addAdvisor
10301-
* @param {IAdvisorSchema} advisorSchema - The schema definition for advisor.
10303+
* @template T - The type of message content the advisor accepts (defaults to string). Can be a custom object, Blob, or string.
10304+
* @param {IAdvisorSchema<T>} advisorSchema - The schema definition for advisor, including name, chat handler, and optional callbacks.
10305+
* @returns {string} The advisorName that was registered.
10306+
*
10307+
* @example
10308+
* // Using default string message type
10309+
* addAdvisor({
10310+
* advisorName: "TextAdvisor",
10311+
* getChat: async (args) => `Response to: ${args.message}`
10312+
* });
10313+
*
10314+
* @example
10315+
* // Using custom message type
10316+
* interface CustomMessage { text: string; metadata: Record<string, any> }
10317+
* addAdvisor<CustomMessage>({
10318+
* advisorName: "StructuredAdvisor",
10319+
* getChat: async (args) => `Processing: ${args.message.text}`
10320+
* });
10321+
*
10322+
* @example
10323+
* // Using Blob message type
10324+
* addAdvisor<Blob>({
10325+
* advisorName: "BlobAdvisor",
10326+
* getChat: async (args) => `Received blob of size: ${args.message.size}`
10327+
* });
1030210328
*/
1030310329
declare function addAdvisor<T = string>(advisorSchema: IAdvisorSchema<T>): string;
1030410330

@@ -10737,7 +10763,7 @@ declare function overrideMCP(mcpSchema: TMCPSchema): IMCPSchema;
1073710763
/**
1073810764
* Type representing a partial advisor schema configuration.
1073910765
* Used for advisor service configuration with optional properties.
10740-
*/
10766+
*/
1074110767
type TAdvisorSchema<T = string> = {
1074210768
advisorName: IAdvisorSchema<T>["advisorName"];
1074310769
} & Partial<IAdvisorSchema<T>>;
@@ -10746,21 +10772,30 @@ type TAdvisorSchema<T = string> = {
1074610772
* This function updates the configuration of an advisor identified by its `advisorName`, applying the provided schema properties.
1074710773
* It operates outside any existing method or execution contexts to ensure isolation, leveraging `beginContext` for a clean execution scope.
1074810774
* Logs the override operation if logging is enabled in the global configuration.
10775+
* Only the provided properties will be updated - omitted properties remain unchanged.
1074910776
*
10750-
*
10751-
* @param {TAdvisorSchema} advisorSchema - The schema definition for advisor.
10777+
* @function overrideAdvisor
10778+
* @template T - The type of message content the advisor accepts (defaults to string). Can be a custom object, Blob, or string.
10779+
* @param {TAdvisorSchema<T>} advisorSchema - Partial schema definition for advisor. Must include `advisorName`, other properties are optional.
10780+
* @returns {IAdvisorSchema<T>} The updated complete advisor schema.
1075210781
* @throws {Error} If the advisor schema service encounters an error during the override operation (e.g., invalid advisorName or schema).
1075310782
*
1075410783
* @example
10755-
* // Override an advisor's schema with new properties
10784+
* // Override advisor's description only
1075610785
* overrideAdvisor({
1075710786
* advisorName: "KnowledgeBase",
10758-
* description: "Updated knowledge repository",
10759-
* storage: "AdvisorStorage",
10787+
* docDescription: "Updated knowledge repository",
1076010788
* });
10761-
* // Logs the operation (if enabled) and updates the advisor schema in the swarm.
10762-
*/
10763-
declare function overrideAdvisor<T = string>(advisorSchema: TAdvisorSchema<T>): IAdvisorSchema<string>;
10789+
*
10790+
* @example
10791+
* // Override advisor with custom message type
10792+
* interface CustomMessage { query: string; context: string[] }
10793+
* overrideAdvisor<CustomMessage>({
10794+
* advisorName: "StructuredAdvisor",
10795+
* getChat: async (args) => `Query: ${args.message.query}`
10796+
* });
10797+
*/
10798+
declare function overrideAdvisor<T = string>(advisorSchema: TAdvisorSchema<T>): TAdvisorSchema<T>;
1076410799

1076510800
/**
1076610801
* @module overrideCompute
@@ -11184,11 +11219,33 @@ declare function executeForce(content: string, clientId: string): Promise<string
1118411219
/** Image type as either an array of Uint8Array or an array of strings */
1118511220
type Image = Uint8Array | string;
1118611221
/**
11187-
* Initiates an ask process within a chat context
11222+
* Initiates an ask process within a chat context.
11223+
* Sends a message to the specified advisor and returns the chat response.
11224+
* Supports custom message types including objects, Blob, or string.
11225+
*
1118811226
* @function ask
11189-
* @param {T} message - The message content to process or send.
11190-
* @param {AdvisorName} advisorName - The name of the advisor.
11191-
* @param {Image[]} [images] - Optional array of images (as Uint8Array or string).
11227+
* @template T - The type of message content (defaults to string). Can be a custom object, Blob, or string.
11228+
* @param {T} message - The message content to process or send. Type should match the advisor's expected message type.
11229+
* @param {AdvisorName} advisorName - The name of the advisor to handle the message.
11230+
* @param {Image[]} [images] - Optional array of images (as Uint8Array or string) to accompany the message.
11231+
* @returns {Promise<string>} The response from the advisor's chat handler.
11232+
*
11233+
* @example
11234+
* // Using default string message type
11235+
* const response = await ask("Hello", "TextAdvisor");
11236+
*
11237+
* @example
11238+
* // Using custom message type
11239+
* interface CustomMessage { text: string; priority: number }
11240+
* const response = await ask<CustomMessage>(
11241+
* { text: "Important", priority: 1 },
11242+
* "StructuredAdvisor"
11243+
* );
11244+
*
11245+
* @example
11246+
* // Using Blob message type with images
11247+
* const blob = new Blob(["data"], { type: "text/plain" });
11248+
* const response = await ask<Blob>(blob, "BlobAdvisor", [imageData]);
1119211249
*/
1119311250
declare function ask<T = string>(message: T, advisorName: AdvisorName, images?: Image[]): Promise<string>;
1119411251

0 commit comments

Comments
 (0)