mirror of
https://github.com/soconnor0919/hristudio.git
synced 2026-05-08 13:58:55 -04:00
Compare commits
3 Commits
86c1f35537
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 14182bf078 | |||
| 943c7bd963 | |||
| 6b54724171 |
+1
-1
Submodule robot-plugins updated: 8f5ee4891f...8334b809f2
@@ -835,6 +835,40 @@ export function PropertiesPanelBase({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs">After this step, go to</Label>
|
||||
<p className="text-muted-foreground mb-1 text-[10px]">
|
||||
Override the next step (use to converge branch paths).
|
||||
</p>
|
||||
<Select
|
||||
value={(selectedStep.trigger.conditions as any)?.nextStepId ?? "__linear__"}
|
||||
onValueChange={(val) => {
|
||||
onStepUpdate(selectedStep.id, {
|
||||
trigger: {
|
||||
...selectedStep.trigger,
|
||||
conditions: {
|
||||
...(selectedStep.trigger.conditions as any),
|
||||
nextStepId: val === "__linear__" ? undefined : val,
|
||||
},
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="mt-1 h-7 w-full text-xs">
|
||||
<SelectValue placeholder="Next step (default)" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__linear__">Next step (default)</SelectItem>
|
||||
{design.steps
|
||||
.filter((s) => s.id !== selectedStep.id)
|
||||
.map((s) => (
|
||||
<SelectItem key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -792,8 +792,11 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
);
|
||||
}
|
||||
|
||||
// Default: Linear progression
|
||||
const nextIndex = currentStepIndex + 1;
|
||||
// Default: Linear progression (skip steps marked as skipped by branching)
|
||||
let nextIndex = currentStepIndex + 1;
|
||||
while (nextIndex < steps.length && skippedSteps.has(nextIndex)) {
|
||||
nextIndex++;
|
||||
}
|
||||
if (nextIndex < steps.length) {
|
||||
// Mark current step as complete
|
||||
setCompletedSteps((prev) => {
|
||||
@@ -922,8 +925,8 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
// Log action execution
|
||||
console.log("Executing action:", actionId, parameters);
|
||||
|
||||
// Handle branching logic (wizard_wait_for_response)
|
||||
if (parameters?.value && parameters?.label) {
|
||||
// Handle branching logic (wizard_wait_for_response / branch)
|
||||
if (parameters?.label || parameters?.nextStepId) {
|
||||
setLastResponse(String(parameters.value));
|
||||
|
||||
// If nextStepId is provided, jump immediately
|
||||
@@ -942,6 +945,24 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
console.log(
|
||||
`[WizardInterface] Choice-based jump to step ${targetIndex} (${nextId})`,
|
||||
);
|
||||
|
||||
// Mark other branch targets as skipped so linear progression bypasses them
|
||||
const branchingStep = steps[currentStepIndex];
|
||||
const allOptions =
|
||||
(branchingStep?.conditions?.options as any[]) ?? [];
|
||||
setSkippedSteps((prev) => {
|
||||
const next = new Set(prev);
|
||||
for (const opt of allOptions) {
|
||||
if (opt.nextStepId && opt.nextStepId !== nextId) {
|
||||
const otherIdx = steps.findIndex(
|
||||
(s) => s.id === opt.nextStepId,
|
||||
);
|
||||
if (otherIdx !== -1) next.add(otherIdx);
|
||||
}
|
||||
}
|
||||
return next;
|
||||
});
|
||||
|
||||
handleNextStep(targetIndex);
|
||||
return; // Exit after jump
|
||||
} else {
|
||||
|
||||
@@ -499,6 +499,7 @@ export function WizardActionItem({
|
||||
// Manual/Wizard Actions (Leaf nodes)
|
||||
!isContainer &&
|
||||
action.type !== "wizard_wait_for_response" &&
|
||||
!isBranch &&
|
||||
!isCompleted && (
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -524,7 +525,7 @@ export function WizardActionItem({
|
||||
<div className="grid grid-cols-1 gap-2 pt-3 sm:grid-cols-2">
|
||||
{(action.parameters.options as any[]).map((opt, optIdx) => {
|
||||
const label = typeof opt === "string" ? opt : opt.label;
|
||||
const value = typeof opt === "string" ? opt : opt.value;
|
||||
const value = typeof opt === "string" ? opt : (opt.value ?? opt.label);
|
||||
const nextStepId =
|
||||
typeof opt === "object" ? opt.nextStepId : undefined;
|
||||
|
||||
|
||||
@@ -593,7 +593,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
// Broadcast trial status update
|
||||
await wsManager.broadcast(input.id, {
|
||||
await wsManager.broadcastExternal(input.id, {
|
||||
type: "trial_status",
|
||||
data: {
|
||||
trial: trial[0],
|
||||
@@ -655,7 +655,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
// Broadcast trial status update
|
||||
await wsManager.broadcast(input.id, {
|
||||
await wsManager.broadcastExternal(input.id, {
|
||||
type: "trial_status",
|
||||
data: {
|
||||
trial,
|
||||
@@ -718,7 +718,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
// Broadcast trial status update
|
||||
await wsManager.broadcast(input.id, {
|
||||
await wsManager.broadcastExternal(input.id, {
|
||||
type: "trial_status",
|
||||
data: {
|
||||
trial: trial[0],
|
||||
@@ -878,7 +878,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
.returning();
|
||||
|
||||
// Broadcast new event to all subscribers
|
||||
await wsManager.broadcast(input.trialId, {
|
||||
await wsManager.broadcastExternal(input.trialId, {
|
||||
type: "trial_event",
|
||||
data: {
|
||||
event,
|
||||
@@ -922,7 +922,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
.returning();
|
||||
|
||||
// Broadcast intervention to all subscribers
|
||||
await wsManager.broadcast(input.trialId, {
|
||||
await wsManager.broadcastExternal(input.trialId, {
|
||||
type: "intervention_logged",
|
||||
data: {
|
||||
intervention,
|
||||
@@ -986,7 +986,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
}
|
||||
|
||||
// Broadcast annotation to all subscribers
|
||||
await wsManager.broadcast(input.trialId, {
|
||||
await wsManager.broadcastExternal(input.trialId, {
|
||||
type: "annotation_added",
|
||||
data: {
|
||||
annotation,
|
||||
@@ -1380,7 +1380,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
.returning();
|
||||
|
||||
// Broadcast robot action to all subscribers
|
||||
await wsManager.broadcast(input.trialId, {
|
||||
await wsManager.broadcastExternal(input.trialId, {
|
||||
type: "trial_action_executed",
|
||||
data: {
|
||||
action_type: `${input.pluginName}.${input.actionId}`,
|
||||
@@ -1439,7 +1439,7 @@ export const trialsRouter = createTRPCRouter({
|
||||
.returning();
|
||||
|
||||
// Broadcast robot action to all subscribers
|
||||
await wsManager.broadcast(input.trialId, {
|
||||
await wsManager.broadcastExternal(input.trialId, {
|
||||
type: "trial_action_executed",
|
||||
data: {
|
||||
action_type: `${input.pluginName}.${input.actionId}`,
|
||||
|
||||
@@ -441,10 +441,6 @@ export class TrialExecutionEngine {
|
||||
case "hristudio-core.loop":
|
||||
return await this.executeLoopAction(trialId, action);
|
||||
|
||||
case "branch":
|
||||
case "hristudio-core.branch":
|
||||
return await this.executeBranchAction(trialId, action);
|
||||
|
||||
default:
|
||||
// Check if it's a robot action (contains plugin prefix)
|
||||
if (
|
||||
|
||||
@@ -146,6 +146,24 @@ class WebSocketManager {
|
||||
);
|
||||
}
|
||||
|
||||
// Called from Next.js tRPC router — POSTs to the Bun ws-server process
|
||||
// which holds the actual client connections.
|
||||
async broadcastExternal(
|
||||
trialId: string,
|
||||
message: OutgoingMessage,
|
||||
): Promise<void> {
|
||||
const wsPort = process.env.WS_PORT ?? "3001";
|
||||
try {
|
||||
await fetch(`http://localhost:${wsPort}/internal/broadcast`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ trialId, message }),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`[WS] Failed to broadcast externally for trial ${trialId}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async broadcastToAll(message: OutgoingMessage): Promise<void> {
|
||||
const messageStr = JSON.stringify(message);
|
||||
const disconnectedClients: string[] = [];
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
],
|
||||
"incremental": true,
|
||||
/* Path Aliases */
|
||||
"baseUrl": ".",
|
||||
// "baseUrl": ".",
|
||||
"paths": {
|
||||
"~/*": [
|
||||
"./src/*"
|
||||
|
||||
+17
-4
@@ -46,9 +46,22 @@ console.log(`Starting WebSocket server on port ${port}...`);
|
||||
|
||||
serve<WSData>({
|
||||
port,
|
||||
fetch(req, server) {
|
||||
async fetch(req, server) {
|
||||
const url = new URL(req.url);
|
||||
|
||||
// Internal broadcast endpoint — called by Next.js tRPC router
|
||||
if (url.pathname === "/internal/broadcast") {
|
||||
if (req.method !== "POST") {
|
||||
return new Response("Method not allowed", { status: 405 });
|
||||
}
|
||||
const { trialId, message } = (await req.json()) as {
|
||||
trialId: string;
|
||||
message: { type: string; data: Record<string, unknown> };
|
||||
};
|
||||
await wsManager.broadcast(trialId, message);
|
||||
return new Response("OK", { status: 200 });
|
||||
}
|
||||
|
||||
if (url.pathname === "/api/websocket") {
|
||||
if (req.headers.get("upgrade") !== "websocket") {
|
||||
return new Response("WebSocket upgrade required", { status: 426 });
|
||||
@@ -114,7 +127,7 @@ serve<WSData>({
|
||||
}),
|
||||
);
|
||||
},
|
||||
message(ws: ServerWebSocket<WSData>, message) {
|
||||
async message(ws: ServerWebSocket<WSData>, message) {
|
||||
const { clientId, trialId } = ws.data;
|
||||
|
||||
try {
|
||||
@@ -131,7 +144,7 @@ serve<WSData>({
|
||||
break;
|
||||
|
||||
case "request_trial_status": {
|
||||
const status = wsManager.getTrialStatusSync(trialId);
|
||||
const status = await wsManager.getTrialStatus(trialId);
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: "trial_status",
|
||||
@@ -146,7 +159,7 @@ serve<WSData>({
|
||||
}
|
||||
|
||||
case "request_trial_events": {
|
||||
const events = wsManager.getTrialEventsSync(
|
||||
const events = await wsManager.getTrialEvents(
|
||||
trialId,
|
||||
msg.data?.limit ?? 100,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user