-
Notifications
You must be signed in to change notification settings - Fork 0
Open Cloud sandbox agents as Herdr panes #3
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
+3,378
−1,255
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,74 @@ | ||
| import { pathToFileURL } from 'node:url'; | ||
|
|
||
| import { prepareCloudPane } from './cloud.mjs'; | ||
| import { attachMode, fleetProjectDir, openedPane } from './fleet.mjs'; | ||
| import { requestHerdr } from './herdr-socket.mjs'; | ||
| import { waitForDismiss } from './fleet-picker.mjs'; | ||
|
|
||
| export const CLOUD_AGENT_ENTRYPOINT = 'fleet-agent'; | ||
|
|
||
| export async function runCloudPicker({ | ||
| environment = process.env, | ||
| prepare = prepareCloudPane, | ||
| request = requestHerdr, | ||
| logger = console, | ||
| } = {}) { | ||
| const socketPath = environment.HERDR_SOCKET_PATH; | ||
| if (!socketPath) throw new Error('Herdr did not provide HERDR_SOCKET_PATH'); | ||
| const pluginId = environment.HERDR_PLUGIN_ID; | ||
| if (!pluginId) throw new Error('Herdr did not provide HERDR_PLUGIN_ID'); | ||
|
|
||
| const projectDir = fleetProjectDir(environment); | ||
| const mode = attachMode(environment.HERDR_RELAY_ATTACH_MODE); | ||
| const prepared = await prepare({ environment }); | ||
| const label = prepared.cloudAgent.harness || 'agent-relay'; | ||
| const response = await request(socketPath, 'plugin.pane.open', { | ||
| plugin_id: pluginId, | ||
| entrypoint: CLOUD_AGENT_ENTRYPOINT, | ||
| placement: 'tab', | ||
| cwd: projectDir, | ||
| focus: true, | ||
| env: { | ||
| HERDR_RELAY_AGENT_NAME: prepared.agentName, | ||
| HERDR_RELAY_AGENT_LABEL: label, | ||
| HERDR_RELAY_ATTACH_MODE: mode, | ||
| RELAY_BROKER_URL: prepared.box.execUrl, | ||
| ...(prepared.box.apiKey ? { RELAY_BROKER_API_KEY: prepared.box.apiKey } : {}), | ||
| }, | ||
| }); | ||
| const pane = openedPane(response); | ||
| try { | ||
| await request(socketPath, 'pane.rename', { | ||
| pane_id: pane.pane_id, | ||
| label: prepared.agentName, | ||
| }); | ||
| } catch (error) { | ||
| logger.warn(`Could not label cloud pane ${pane.pane_id}: ${error.message}`); | ||
| } | ||
| logger.log( | ||
| `Opened Daytona sandbox agent "${prepared.agentName}" as Herdr pane ${pane.pane_id}; ` + | ||
| `working directory ${prepared.box.relayfileMountPath} is a live Relayfile mount.` | ||
| ); | ||
| return { | ||
| paneId: pane.pane_id, | ||
| agentName: prepared.agentName, | ||
| sandboxId: prepared.box.sandboxId, | ||
| relayfileMountPath: prepared.box.relayfileMountPath, | ||
| }; | ||
| } | ||
|
|
||
| export function isDirectEntrypoint(moduleUrl, argv1) { | ||
| return Boolean(argv1) && moduleUrl === pathToFileURL(argv1).href; | ||
| } | ||
|
|
||
| export async function main({ dismiss = waitForDismiss, pickerOptions } = {}) { | ||
| try { | ||
| await runCloudPicker(pickerOptions); | ||
| } catch (error) { | ||
| console.error(`Agent Relay cloud pane failed: ${error.message}`); | ||
| process.exitCode = 1; | ||
| await dismiss(); | ||
| } | ||
| } | ||
|
|
||
| if (isDirectEntrypoint(import.meta.url, process.argv[1])) await main(); |
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.
Uh oh!
There was an error while loading. Please reload this page.