-
Notifications
You must be signed in to change notification settings - Fork 10
feat(workflow-executor): implement AgentPort adapter using agent-client #1496
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
Merged
matthv
merged 12 commits into
feat/prd-214-setup-workflow-executor-package
from
feature/prd-232-implementer-agentport-avec-agent-client
Mar 18, 2026
+411
−17
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8bf3638
feat(workflow-executor): implement AgentPort adapter using agent-client
matthv 81f38bd
refactor(workflow-executor): replace RecordRef with CollectionRef
matthv 1acc164
fix(workflow-executor): address review — dedicated error class, all r…
matthv 871c2fd
refactor(workflow-executor): inject CollectionRef instead of fetching…
matthv f439e91
refactor(workflow-executor): move actions into CollectionRef, remove …
matthv 9594223
refactor(workflow-executor): return ActionRef[] from getActions inste…
matthv 182fa84
fix(workflow-executor): support composite PKs in getRecord via primar…
matthv cdeb2dc
refactor(workflow-executor): use Record<string, unknown> for recordId…
matthv 2a2d898
refactor(workflow-executor): change recordId to Array<string | number>
matthv 2703ae7
fix(workflow-executor): rename RecordRef to CollectionRef in executio…
matthv 889ea3b
fix(workflow-executor): merge duplicate dependencies blocks in packag…
matthv e7fcf1b
fix(workflow-executor): revert selectedRecord type to CollectionRef
matthv 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
129 changes: 129 additions & 0 deletions
129
packages/workflow-executor/src/adapters/agent-client-agent-port.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,129 @@ | ||
| import type { AgentPort } from '../ports/agent-port'; | ||
| import type { ActionRef, CollectionRef, RecordData } from '../types/record'; | ||
| import type { RemoteAgentClient, SelectOptions } from '@forestadmin/agent-client'; | ||
|
|
||
| import { RecordNotFoundError } from '../errors'; | ||
|
|
||
| function buildPkFilter( | ||
| primaryKeyFields: string[], | ||
| recordId: Array<string | number>, | ||
| ): SelectOptions['filters'] { | ||
| if (primaryKeyFields.length === 1) { | ||
| return { field: primaryKeyFields[0], operator: 'Equal', value: recordId[0] }; | ||
| } | ||
|
|
||
| return { | ||
| aggregator: 'And', | ||
| conditions: primaryKeyFields.map((field, i) => ({ | ||
| field, | ||
| operator: 'Equal', | ||
| value: recordId[i], | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| // agent-client methods (update, relation, action) still expect the pipe-encoded string format | ||
| function encodePk(recordId: Array<string | number>): string { | ||
| return recordId.map(v => String(v)).join('|'); | ||
| } | ||
|
|
||
| function extractRecordId( | ||
| primaryKeyFields: string[], | ||
| record: Record<string, unknown>, | ||
| ): Array<string | number> { | ||
| return primaryKeyFields.map(field => record[field] as string | number); | ||
| } | ||
|
|
||
| export default class AgentClientAgentPort implements AgentPort { | ||
| private readonly client: RemoteAgentClient; | ||
| private readonly collectionRefs: Record<string, CollectionRef>; | ||
|
|
||
| constructor(params: { | ||
| client: RemoteAgentClient; | ||
| collectionRefs: Record<string, CollectionRef>; | ||
| }) { | ||
| this.client = params.client; | ||
| this.collectionRefs = params.collectionRefs; | ||
| } | ||
|
|
||
| async getRecord(collectionName: string, recordId: Array<string | number>): Promise<RecordData> { | ||
| const ref = this.getCollectionRef(collectionName); | ||
| const records = await this.client.collection(collectionName).list<Record<string, unknown>>({ | ||
| filters: buildPkFilter(ref.primaryKeyFields, recordId), | ||
| pagination: { size: 1, number: 1 }, | ||
matthv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| if (records.length === 0) { | ||
| throw new RecordNotFoundError(collectionName, encodePk(recordId)); | ||
| } | ||
|
|
||
| return { ...ref, recordId, values: records[0] }; | ||
| } | ||
|
|
||
| async updateRecord( | ||
| collectionName: string, | ||
| recordId: Array<string | number>, | ||
| values: Record<string, unknown>, | ||
| ): Promise<RecordData> { | ||
| const ref = this.getCollectionRef(collectionName); | ||
| const updatedRecord = await this.client | ||
| .collection(collectionName) | ||
| .update<Record<string, unknown>>(encodePk(recordId), values); | ||
|
|
||
| return { ...ref, recordId, values: updatedRecord }; | ||
| } | ||
|
|
||
| async getRelatedData( | ||
| collectionName: string, | ||
| recordId: Array<string | number>, | ||
| relationName: string, | ||
| ): Promise<RecordData[]> { | ||
| const relatedRef = this.getCollectionRef(relationName); | ||
|
|
||
| const records = await this.client | ||
| .collection(collectionName) | ||
| .relation(relationName, encodePk(recordId)) | ||
| .list<Record<string, unknown>>(); | ||
|
|
||
| return records.map(record => ({ | ||
| ...relatedRef, | ||
| recordId: extractRecordId(relatedRef.primaryKeyFields, record), | ||
| values: record, | ||
| })); | ||
| } | ||
|
|
||
| async getActions(collectionName: string): Promise<ActionRef[]> { | ||
| const ref = this.collectionRefs[collectionName]; | ||
|
|
||
| return ref ? ref.actions : []; | ||
| } | ||
|
|
||
| async executeAction( | ||
| collectionName: string, | ||
| actionName: string, | ||
| recordIds: Array<string | number>[], | ||
| ): Promise<unknown> { | ||
| const encodedIds = recordIds.map(id => encodePk(id)); | ||
| const action = await this.client | ||
| .collection(collectionName) | ||
| .action(actionName, { recordIds: encodedIds }); | ||
|
|
||
| return action.execute(); | ||
| } | ||
|
|
||
| private getCollectionRef(collectionName: string): CollectionRef { | ||
| const ref = this.collectionRefs[collectionName]; | ||
|
|
||
| if (!ref) { | ||
| return { | ||
| collectionName, | ||
| collectionDisplayName: collectionName, | ||
| primaryKeyFields: ['id'], | ||
| fields: [], | ||
| actions: [], | ||
| }; | ||
| } | ||
|
|
||
| return ref; | ||
| } | ||
| } | ||
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
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 |
|---|---|---|
| @@ -1,19 +1,23 @@ | ||
| /** @draft Types derived from the workflow-executor spec -- subject to change. */ | ||
|
|
||
| import type { RecordData } from '../types/record'; | ||
| import type { ActionRef, RecordData } from '../types/record'; | ||
|
|
||
| export interface AgentPort { | ||
| getRecord(collectionName: string, recordId: string): Promise<RecordData>; | ||
| getRecord(collectionName: string, recordId: Array<string | number>): Promise<RecordData>; | ||
| updateRecord( | ||
| collectionName: string, | ||
| recordId: string, | ||
| recordId: Array<string | number>, | ||
| values: Record<string, unknown>, | ||
| ): Promise<RecordData>; | ||
| getRelatedData( | ||
| collectionName: string, | ||
| recordId: string, | ||
| recordId: Array<string | number>, | ||
| relationName: string, | ||
| ): Promise<RecordData[]>; | ||
| getActions(collectionName: string): Promise<string[]>; | ||
| executeAction(collectionName: string, actionName: string, recordIds: string[]): Promise<unknown>; | ||
| getActions(collectionName: string): Promise<ActionRef[]>; | ||
| executeAction( | ||
| collectionName: string, | ||
| actionName: string, | ||
| recordIds: Array<string | number>[], | ||
| ): Promise<unknown>; | ||
| } |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low
adapters/agent-client-agent-port.ts:30extractRecordIduses a type assertionas string | numberonrecord[field], but when the field is missing, this passesundefinedthrough silently. When the resulting array is passed toencodePk,String(undefined)produces the literal string"undefined", corrupting the record ID. This is reachable ingetRelatedDatawhen the API response omits expected primary key fields, or whengetCollectionRefdefaults to['id']for an unknown collection but the actual records use a different key.function extractRecordId( primaryKeyFields: string[], record: Record<string, unknown>, ): Array<string | number> { - return primaryKeyFields.map(field => record[field] as string | number); + return primaryKeyFields.map(field => { + const value = record[field]; + if (value === undefined || value === null) { + throw new Error(`Missing primary key field: ${field}`); + } + if (typeof value !== 'string' && typeof value !== 'number') { + throw new Error(`Invalid primary key type for ${field}: ${typeof value}`); + } + return value; + }); }🚀 Reply "fix it for me" or copy this AI Prompt for your agent: