From 99f4354c2b2efdc22fd85b389310f056af81c628 Mon Sep 17 00:00:00 2001 From: Kuojian Lu Date: Tue, 21 Nov 2023 08:08:46 +0800 Subject: [PATCH] [JS] fix: remove schema from AI class (#832) ## Linked issues closes: #831 ## Details #### Change details - remove schame from action entry and method parameters ## Attestation Checklist - [x] My code follows the style guidelines of this project - I have checked for/fixed spelling, linting, and other errors - I have commented my code for clarity - I have made corresponding changes to the documentation (we use [TypeDoc](https://typedoc.org/) to document our code) - My changes generate no new warnings - I have added tests that validates my changes, and provides sufficient test coverage. I have tested with: - Local testing - E2E testing in Teams - New and existing unit tests pass locally with my changes ### Additional information > Feel free to add other relevant information below --- js/packages/teams-ai/src/AI.ts | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/js/packages/teams-ai/src/AI.ts b/js/packages/teams-ai/src/AI.ts index 78717d03e..26e32d32c 100644 --- a/js/packages/teams-ai/src/AI.ts +++ b/js/packages/teams-ai/src/AI.ts @@ -11,7 +11,6 @@ import { DefaultModerator } from './moderators'; import { Moderator } from './moderators/Moderator'; import { PredictedDoCommand, PredictedSayCommand, Planner, Plan } from './planners'; import { TurnState } from './TurnState'; -import { Schema } from 'jsonschema'; /** * Entities argument passed to the action handler for AI.DoCommandActionName. @@ -358,25 +357,20 @@ export class AI { * @template TParameters Optional. The type of parameters that the action handler expects. * @param name Unique name of the action. * @param handler Function to call when the action is triggered. - * @param schema Optional. Schema for the actions parameters. * @returns The AI system instance for chaining purposes. */ public action | undefined>( name: string | string[], - handler: (context: TurnContext, state: TState, parameters: TParameters, action?: string) => Promise, - schema?: Schema + handler: (context: TurnContext, state: TState, parameters: TParameters, action?: string) => Promise ): this { (Array.isArray(name) ? name : [name]).forEach((n) => { if (!this._actions.has(n)) { - this._actions.set(n, { handler, schema, allowOverrides: false }); + this._actions.set(n, { handler, allowOverrides: false }); } else { const entry = this._actions.get(n); if (entry!.allowOverrides) { entry!.handler = handler; entry!.allowOverrides = false; // Only override once - if (schema) { - entry!.schema = schema; - } } else { throw new Error( `The AI.action() method was called with a previously registered action named "${n}".` @@ -395,16 +389,14 @@ export class AI { * @template TParameters Optional. The type of parameters that the action handler expects. * @param name Unique name of the action. * @param handler Function to call when the action is triggered. - * @param schema Optional. The schema for the actions parameters. * @returns The AI system instance for chaining purposes. */ public defaultAction | undefined)>( name: string | string[], - handler: (context: TurnContext, state: TState, parameters: TParameters, action?: string) => Promise, - schema?: Schema + handler: (context: TurnContext, state: TState, parameters: TParameters, action?: string) => Promise ): this { (Array.isArray(name) ? name : [name]).forEach((n) => { - this._actions.set(n, { handler, schema, allowOverrides: true }); + this._actions.set(n, { handler, allowOverrides: true }); }); return this; @@ -433,19 +425,6 @@ export class AI { return await handler(context, state, parameters, action); } - /** - * Gets the schema for a given action. - * @param action Name of the action to get the schema for. - * @returns The schema for the action or undefined if the action doesn't have a schema. - */ - public getActionSchema(action: string): Schema | undefined { - if (!this._actions.has(action)) { - throw new Error(`Can't find an action named '${action}'.`); - } - - return this._actions.get(action)!.schema; - } - /** * Checks to see if the AI system has a handler for a given action. * @param action Name of the action to check. @@ -586,6 +565,5 @@ export class AI { */ interface ActionEntry { handler: (context: TurnContext, state: TState, entities?: any, action?: string) => Promise; - schema?: Schema; allowOverrides: boolean; }