-
Notifications
You must be signed in to change notification settings - Fork 18
Add codegen support for ChatMessageTrigger #3442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
14
commits into
main
Choose a base branch
from
devin/1766434179-chat-message-trigger-codegen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a575a6c
Add codegen support for ChatMessageTrigger
devin-ai-integration[bot] 2cea6c1
Fix trigger ordering and add CHAT_MESSAGE test
devin-ai-integration[bot] 519fbc7
Add snapshot test for ChatMessageTrigger codegen
devin-ai-integration[bot] 54d173f
Add ChatMessageTriggerSerializer to WorkflowTriggerSerializer union
devin-ai-integration[bot] 490232d
Add serializer test for CHAT_MESSAGE trigger deserialization
devin-ai-integration[bot] 538a965
Remove if statement from test assertion
devin-ai-integration[bot] c3a539e
Revert serializer test changes
devin-ai-integration[bot] 892b352
Add ChatMessageTrigger codegen with exec_config.output support
devin-ai-integration[bot] be85276
Fix Prettier formatting in chat-message-trigger.ts
devin-ai-integration[bot] 8245f27
Use generated ChatMessageTrigger subclass in workflow graph
devin-ai-integration[bot] e6d843b
Handle all WorkflowValueDescriptor types in ChatMessageTrigger and ge…
devin-ai-integration[bot] 09f191e
Remove entrypoint node from chat-message-trigger test fixture
devin-ai-integration[bot] a6f4e3a
Update snapshot for chat-message-trigger test after removing entrypoi…
devin-ai-integration[bot] 6b4fc2b
Remove top node and rename bottom node to some node in chat-message-t…
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
127 changes: 127 additions & 0 deletions
127
ee/codegen/src/__test__/generate-code-fixtures/chat-message-trigger.ts
This file contains hidden or 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,127 @@ | ||
| export default { | ||
| workflow_raw_data: { | ||
| nodes: [ | ||
| { | ||
| id: "entrypoint-node", | ||
| type: "ENTRYPOINT", | ||
| data: { | ||
| label: "Entrypoint", | ||
| source_handle_id: "entrypoint-source", | ||
| }, | ||
| inputs: [], | ||
| }, | ||
| { | ||
| id: "top-node", | ||
| type: "GENERIC", | ||
| label: "Top Node", | ||
| display_data: null, | ||
| base: { | ||
| name: "BaseNode", | ||
| module: ["vellum", "workflows", "nodes", "bases", "base"], | ||
| }, | ||
| definition: { | ||
| name: "TopNode", | ||
| module: ["testing", "nodes", "top_node"], | ||
| }, | ||
| trigger: { | ||
| id: "top-target", | ||
| merge_behavior: "AWAIT_ATTRIBUTES", | ||
| }, | ||
| ports: [ | ||
| { | ||
| id: "top-default-port-id", | ||
| name: "default", | ||
| type: "DEFAULT", | ||
| }, | ||
| ], | ||
| outputs: [], | ||
| attributes: [], | ||
| }, | ||
| { | ||
| id: "bottom-node", | ||
| type: "GENERIC", | ||
| label: "Bottom Node", | ||
| display_data: null, | ||
| base: { | ||
| name: "BaseNode", | ||
| module: ["vellum", "workflows", "nodes", "bases", "base"], | ||
| }, | ||
| definition: { | ||
| name: "BottomNode", | ||
| module: ["testing", "nodes", "bottom_node"], | ||
| }, | ||
| trigger: { | ||
| id: "bottom-target", | ||
| merge_behavior: "AWAIT_ATTRIBUTES", | ||
| }, | ||
| ports: [ | ||
| { | ||
| id: "bottom-default-port-id", | ||
| name: "default", | ||
| type: "DEFAULT", | ||
| }, | ||
| ], | ||
| outputs: [ | ||
| { | ||
| id: "bottom-output-id", | ||
| name: "result", | ||
| type: "STRING", | ||
| }, | ||
| ], | ||
| attributes: [], | ||
| }, | ||
| ], | ||
| edges: [ | ||
| { | ||
| id: "edge-1", | ||
| source_node_id: "entrypoint-node", | ||
| source_handle_id: "entrypoint-source", | ||
| target_node_id: "top-node", | ||
| target_handle_id: "top-target", | ||
| type: "DEFAULT", | ||
| }, | ||
| { | ||
| id: "edge-2", | ||
| source_node_id: "chat-message-trigger", | ||
| source_handle_id: "chat-message-trigger", | ||
| target_node_id: "bottom-node", | ||
| target_handle_id: "bottom-target", | ||
| type: "DEFAULT", | ||
| }, | ||
| ], | ||
| output_values: [], | ||
| }, | ||
| input_variables: [], | ||
| output_variables: [], | ||
| triggers: [ | ||
| { | ||
| id: "chat-message-trigger", | ||
| type: "CHAT_MESSAGE", | ||
| attributes: [ | ||
| { | ||
| id: "message-attribute-id", | ||
| key: "message", | ||
| type: "JSON", | ||
| }, | ||
| ], | ||
| exec_config: { | ||
| output: { | ||
| type: "NODE_OUTPUT", | ||
| node_id: "bottom-node", | ||
| node_output_id: "bottom-output-id", | ||
| }, | ||
| }, | ||
| display_data: { | ||
| label: "Chat Message", | ||
| position: { | ||
| x: 100, | ||
| y: 200, | ||
| }, | ||
| z_index: 1, | ||
| icon: "vellum:icon:message", | ||
| color: "blue", | ||
| }, | ||
| }, | ||
| ], | ||
| assertions: ["workflow.py", "triggers/chat_message.py"], | ||
| }; |
This file contains hidden or 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
120 changes: 120 additions & 0 deletions
120
ee/codegen/src/generators/triggers/chat-message-trigger.ts
This file contains hidden or 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,120 @@ | ||
| import { python } from "@fern-api/python-ast"; | ||
|
|
||
| import { | ||
| OUTPUTS_CLASS_NAME, | ||
| VELLUM_WORKFLOW_TRIGGERS_MODULE_PATH, | ||
| } from "src/constants"; | ||
| import { AccessAttribute } from "src/generators/extensions/access-attribute"; | ||
| import { Class } from "src/generators/extensions/class"; | ||
| import { ClassInstantiation } from "src/generators/extensions/class-instantiation"; | ||
| import { Field } from "src/generators/extensions/field"; | ||
| import { MethodArgument } from "src/generators/extensions/method-argument"; | ||
| import { Reference } from "src/generators/extensions/reference"; | ||
| import { BaseTrigger } from "src/generators/triggers/base-trigger"; | ||
| import { createPythonClassName, toPythonSafeSnakeCase } from "src/utils/casing"; | ||
|
|
||
| import type { AstNode } from "src/generators/extensions/ast-node"; | ||
| import type { ChatMessageTrigger as ChatMessageTriggerType } from "src/types/vellum"; | ||
|
|
||
| export declare namespace ChatMessageTriggerGenerator { | ||
| interface Args { | ||
| workflowContext: BaseTrigger.Args<ChatMessageTriggerType>["workflowContext"]; | ||
| trigger: ChatMessageTriggerType; | ||
| } | ||
| } | ||
|
|
||
| export class ChatMessageTrigger extends BaseTrigger<ChatMessageTriggerType> { | ||
| protected generateClassName(): string { | ||
| const label = this.trigger.displayData?.label || "ChatMessageTrigger"; | ||
| return createPythonClassName(label, { | ||
| force: true, | ||
| }); | ||
| } | ||
|
|
||
| protected getModuleName(): string { | ||
| const label = this.trigger.displayData?.label || "chat_message"; | ||
| return toPythonSafeSnakeCase(label); | ||
| } | ||
|
|
||
| protected getBaseTriggerClassName(): string { | ||
| return "ChatMessageTrigger"; | ||
| } | ||
|
|
||
| protected getTriggerClassBody(): AstNode[] { | ||
| const body: AstNode[] = []; | ||
|
|
||
| // Add attribute fields | ||
| body.push(...this.createAttributeFields()); | ||
|
|
||
| // Create Config class if execConfig.output is present | ||
| const execConfig = this.trigger.execConfig; | ||
| if (execConfig?.output) { | ||
| body.push(this.createConfigClass(execConfig.output)); | ||
| } | ||
|
|
||
| return body; | ||
| } | ||
|
|
||
| private createConfigClass( | ||
| output: NonNullable<ChatMessageTriggerType["execConfig"]>["output"] | ||
| ): AstNode { | ||
| const configClass = new Class({ | ||
| name: "Config", | ||
| extends_: [ | ||
| new Reference({ | ||
| name: "ChatMessageTrigger", | ||
| modulePath: VELLUM_WORKFLOW_TRIGGERS_MODULE_PATH, | ||
| attribute: ["Config"], | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| if (output && output.type === "NODE_OUTPUT") { | ||
| const nodeContext = this.workflowContext.findNodeContext(output.nodeId); | ||
|
|
||
| if (nodeContext) { | ||
| const nodeOutputName = nodeContext.getNodeOutputNameById( | ||
| output.nodeOutputId | ||
| ); | ||
|
|
||
| if (nodeOutputName) { | ||
| const lazyReferenceValue = new ClassInstantiation({ | ||
| classReference: new Reference({ | ||
| name: "LazyReference", | ||
| modulePath: [ | ||
| ...this.workflowContext.sdkModulePathNames | ||
| .WORKFLOWS_MODULE_PATH, | ||
| "references", | ||
| ], | ||
| }), | ||
| arguments_: [ | ||
| new MethodArgument({ | ||
| value: python.lambda({ | ||
| body: new AccessAttribute({ | ||
| lhs: new Reference({ | ||
| name: nodeContext.nodeClassName, | ||
| modulePath: nodeContext.nodeModulePath, | ||
| }), | ||
| rhs: new Reference({ | ||
| name: `${OUTPUTS_CLASS_NAME}.${nodeOutputName}`, | ||
| modulePath: [], | ||
| }), | ||
| }), | ||
| }), | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| configClass.add( | ||
| new Field({ | ||
| name: "output", | ||
| initializer: lazyReferenceValue, | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return configClass; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.