Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/app/api/electric/[...path]/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function buildWhereClause(
return build(agentCommands, agentCommands.organizationId, organizationId);

case "auth.apikeys": {
const fragment = `"metadata"::jsonb->>'organizationId' = $1`;
const fragment = `"metadata" LIKE '%"organizationId":"' || $1 || '"%'`;
return { fragment, params: [organizationId] };
}

Expand Down
17 changes: 7 additions & 10 deletions apps/api/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ function getCorsHeaders(origin: string | null) {
"Access-Control-Allow-Origin": isAllowed ? origin : "",
"Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
"Access-Control-Allow-Headers":
"Content-Type, Authorization, x-trpc-source, trpc-accept",
"Content-Type, Authorization, x-trpc-source, trpc-accept, X-Electric-Backend",
"Access-Control-Expose-Headers": [
"Stream-Next-Offset",
"Stream-Cursor",
"Stream-Up-To-Date",
"Stream-Closed",
"Stream-Total-Size",
"Stream-Write-Units",
"Producer-Epoch",
"Producer-Expected-Seq",
"Producer-Received-Seq",
"electric-offset",
"electric-handle",
"electric-schema",
"electric-cursor",
"electric-chunk-last-offset",
"electric-up-to-date",
"ETag",
].join(", "),
"Access-Control-Allow-Credentials": "true",
Expand Down
4 changes: 0 additions & 4 deletions apps/desktop/src/renderer/lib/trpc-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function createTrpcStorageAdapter(config: TrpcStorageConfig): StateStorage {
localStorage.getItem(`${name}:version`) ?? "0",
10,
);
console.log(`[trpc-storage] getItem "${name}" version=${version}`);
return JSON.stringify({ state, version });
} catch (error) {
console.error("[trpc-storage] Failed to get state:", error);
Expand All @@ -48,9 +47,6 @@ function createTrpcStorageAdapter(config: TrpcStorageConfig): StateStorage {
version: number;
};
// Persist version in localStorage, bare state via tRPC.
console.log(
`[trpc-storage] setItem "${name}" version=${parsed.version}`,
);
localStorage.setItem(`${name}:version`, String(parsed.version));
await config.set(parsed.state);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ async function execute(
store.addPendingTerminalSetup({
workspaceId: workspace.id,
projectId: pending?.projectId ?? workspace.projectId,
initialCommands: [...(pending?.initialCommands ?? []), params.command],
initialCommands: pending?.initialCommands ?? null,
defaultPresets: pending?.defaultPresets,
agentCommand: params.command,
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function WorkspaceInitEffects() {
const processingRef = useRef<Set<string>>(new Set());

const addTab = useTabsStore((state) => state.addTab);
const addPane = useTabsStore((state) => state.addPane);
const setTabAutoTitle = useTabsStore((state) => state.setTabAutoTitle);
const { openPreset } = useTabsWithPresets();
const createOrAttach = useCreateOrAttachWithTheme();
Expand All @@ -43,6 +44,7 @@ export function WorkspaceInitEffects() {
(p) => p.commands.length > 0,
);
const hasPresets = shouldApplyPreset && presets.length > 0;
const { agentCommand } = setup;

if (hasSetupScript && hasPresets) {
const { tabId: setupTabId, paneId: setupPaneId } = addTab(
Expand All @@ -53,6 +55,12 @@ export function WorkspaceInitEffects() {
openPreset(setup.workspaceId, preset);
}

if (agentCommand) {
addPane(setupTabId, {
initialCommands: [agentCommand],
});
}

createOrAttach.mutate(
{
paneId: setupPaneId,
Expand Down Expand Up @@ -81,6 +89,13 @@ export function WorkspaceInitEffects() {
if (hasSetupScript) {
const { tabId, paneId } = addTab(setup.workspaceId);
setTabAutoTitle(tabId, "Workspace Setup");

if (agentCommand) {
addPane(tabId, {
initialCommands: [agentCommand],
});
}

createOrAttach.mutate(
{
paneId,
Expand Down Expand Up @@ -124,13 +139,35 @@ export function WorkspaceInitEffects() {
for (const preset of presets) {
openPreset(setup.workspaceId, preset);
}
if (agentCommand) {
const { tabId: agentTabId } = addTab(setup.workspaceId, {
initialCommands: [agentCommand],
});
setTabAutoTitle(agentTabId, "Agent");
}
onComplete();
return;
}

if (agentCommand) {
const { tabId: agentTabId } = addTab(setup.workspaceId, {
initialCommands: [agentCommand],
});
setTabAutoTitle(agentTabId, "Agent");
onComplete();
return;
}

onComplete();
},
[addTab, setTabAutoTitle, createOrAttach, openPreset, shouldApplyPreset],
[
addTab,
addPane,
setTabAutoTitle,
createOrAttach,
openPreset,
shouldApplyPreset,
],
);

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/renderer/stores/workspace-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface PendingTerminalSetup {
initialCommands: string[] | null;
/** When undefined, signals that presets haven't been fetched yet and should be loaded from the backend */
defaultPresets?: TerminalPreset[];
/** Agent command to run in a separate pane from the setup script */
agentCommand?: string;
}

interface WorkspaceInitState {
Expand Down
Loading