-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exports & updates for VS Code extension
- Loading branch information
Showing
18 changed files
with
285 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Agent, AgentConfig } from '..'; | ||
|
||
export default class AgentFactory { | ||
private static agentCreators: { [role: string]: (agentConfig: AgentConfig) => Agent } = {}; | ||
|
||
static registerAgentCreator(role: string, agentCreator: (agentConfig: AgentConfig) => Agent) { | ||
this.agentCreators[role] = agentCreator; | ||
} | ||
|
||
static createAgent(agentConfig: AgentConfig): Agent | undefined { | ||
if (agentConfig.routing?.roles?.length) { | ||
const agentCreator = this.agentCreators[agentConfig.routing.roles.sort().join(',')]; | ||
if (agentCreator) { | ||
return agentCreator(agentConfig); | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { areRequirementsMet } from './stepRequirements'; | ||
export { LinkDefinition, StepDefinition, StepProvide, StepRequirement, ToolObjectDefinition } from './WorkflowSchema'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { RoutingContext } from '..'; | ||
import { StepRequirement } from './WorkflowSchema'; | ||
|
||
export const areRequirementsMet = (context: RoutingContext, requirements?: StepRequirement[]) => { | ||
if (!requirements) { | ||
return true; | ||
} | ||
|
||
return requirements.every((requirement) => { | ||
// is the required key even in the context? | ||
if (!(requirement.name in context)) { | ||
if (requirement.condition === 'undefined') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
const contextValue = context[requirement.name]; | ||
|
||
if (requirement.condition) { | ||
if (requirement.condition === 'undefined') { | ||
return contextValue === undefined; | ||
} | ||
if (typeof requirement.condition === 'number') { | ||
return Array.isArray(contextValue) || typeof contextValue === 'string' | ||
? contextValue.length >= requirement.condition | ||
: false; | ||
} | ||
if (Array.isArray(contextValue)) { | ||
return contextValue.includes(requirement.condition); | ||
} | ||
if ( | ||
typeof contextValue === 'string' && | ||
requirement.condition.startsWith('/') && | ||
requirement.condition.endsWith('/') | ||
) { | ||
return new RegExp(requirement.condition).test(contextValue); | ||
} | ||
} | ||
|
||
return !!contextValue; | ||
}); | ||
}; |
Oops, something went wrong.