-
Notifications
You must be signed in to change notification settings - Fork 374
Add TrueFoundryAgentStore for agents #560
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
72c6a3f
Add TrueFoundryAgentStore for SF remote agent sync
bhaveshpatel640 5de1e94
Merge branch 'main' into AGE-2064
bhaveshpatel640 2dcbc86
Merge branch 'main' into AGE-2064
bhaveshpatel640 c9270c5
Reserve tfg/trueforge agent names and filter listAgents by external_ids
bhaveshpatel640 364eb10
Merge branch 'main' into AGE-2064
bhaveshpatel640 bb53fda
comments addressed
bhaveshpatel640 b4d5837
Merge branch 'main' into AGE-2064
bhaveshpatel640 e10aaf7
Approach A — Insert first in create
bhaveshpatel640 6845b06
Approach B — Advisory lock in update
bhaveshpatel640 67459f4
Merge branch 'main' into AGE-2064
bhaveshpatel640 2b721e6
Hold agent update lock on delete
bhaveshpatel640 92733d4
comments addressed
bhaveshpatel640 ed35613
Merge branch 'main' into AGE-2064
bhaveshpatel640 33e9d6d
Take the agent update lock in TrueFoundryAgentStore. Do not pass it i…
bhaveshpatel640 8060262
Merge branch 'main' into AGE-2064
bhaveshpatel640 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@truefoundry/trueforge": patch | ||
| --- | ||
|
|
||
| Sync ServiceFoundry remote agents on create/update/delete and store the remote id in `external_id`. Filter `listAgents` by `external_ids`. Keep general ServiceFoundry HTTP at 10s and agent CRUD calls at 3s. |
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,5 @@ | ||
| --- | ||
| "@truefoundry/trueforge": patch | ||
| --- | ||
|
|
||
| Reject reserved agent names `tfg` and `trueforge` in create requests. |
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
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
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { | |
| type DeleteAgentInput, | ||
| type GetAgentInput, | ||
| type IAgentStore, | ||
| type ListAgentsInput, | ||
| type UpdateAgentInput, | ||
| } from '../../agentStore'; | ||
| import { parseStoredCreatedBySubject } from '../../createdBySubject'; | ||
|
|
@@ -55,9 +56,16 @@ export class PostgresAgentStore implements IAgentStore<Transaction<Database>> { | |
| this.#db = db; | ||
| } | ||
|
|
||
| async listAgents(tenantId: string, transaction?: Transaction<Database>): Promise<AgentRecord[]> { | ||
| async listAgents(input: ListAgentsInput, transaction?: Transaction<Database>): Promise<AgentRecord[]> { | ||
| if (input.external_ids?.length === 0) { | ||
| return []; | ||
| } | ||
| const db = transaction ?? this.#db; | ||
| const rows = await db.selectFrom('agent').selectAll().where('tenant_id', '=', tenantId).orderBy('name').execute(); | ||
| let query = db.selectFrom('agent').selectAll().where('tenant_id', '=', input.tenant_id); | ||
| if (input.external_ids !== undefined) { | ||
| query = query.where('external_id', 'in', [...input.external_ids]); | ||
| } | ||
| const rows = await query.orderBy('name').execute(); | ||
| return rows.map(toRecord); | ||
| } | ||
|
|
||
|
|
@@ -73,6 +81,10 @@ export class PostgresAgentStore implements IAgentStore<Transaction<Database>> { | |
| return row === undefined ? undefined : toRecord(row); | ||
| } | ||
|
|
||
| withTransaction<T>(fn: (transaction: Transaction<Database>) => Promise<T>): Promise<T> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? Why can't we take |
||
| return this.#db.transaction().execute(fn); | ||
| } | ||
|
|
||
| async createAgent(input: CreateAgentInput, transaction?: Transaction<Database>): Promise<AgentRecord> { | ||
| const db = transaction ?? this.#db; | ||
| try { | ||
|
|
||
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.