diff --git a/app/(playground)/p/[agentId]/beta-proto/flow/action.ts b/app/(playground)/p/[agentId]/beta-proto/flow/action.ts new file mode 100644 index 00000000..e74aba5b --- /dev/null +++ b/app/(playground)/p/[agentId]/beta-proto/flow/action.ts @@ -0,0 +1,42 @@ +import type { Flow, QueuedFlow, RunningFlow } from "./types"; + +const v2FlowActionTypes = { + setFlow: "v2.setFlow", +} as const; + +type V2FlowActionType = + (typeof v2FlowActionTypes)[keyof typeof v2FlowActionTypes]; + +interface SetFlowAction { + type: Extract; + input: SetFlowActionInput; +} +type SetFlowActionInput = + | Omit + | Omit; + +export type V2FlowAction = SetFlowAction; + +export function isV2FlowAction(action: unknown): action is V2FlowAction { + return Object.values(v2FlowActionTypes).includes( + (action as V2FlowAction).type, + ); +} + +export function setFlow({ input }: { input: SetFlowActionInput }) { + return { + type: v2FlowActionTypes.setFlow, + input, + }; +} + +export function v2FlowReducer( + flow: Flow | null | undefined, + action: V2FlowAction, +): Flow | null | undefined { + switch (action.type) { + case v2FlowActionTypes.setFlow: + return { ...action.input, object: "flow" }; + } + return flow; +} diff --git a/app/(playground)/p/[agentId]/beta-proto/flow/components/run-button.tsx b/app/(playground)/p/[agentId]/beta-proto/flow/components/run-button.tsx new file mode 100644 index 00000000..0ce804d9 --- /dev/null +++ b/app/(playground)/p/[agentId]/beta-proto/flow/components/run-button.tsx @@ -0,0 +1,76 @@ +"use client"; + +import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; +import { forwardRef } from "react"; +import { SparklesIcon } from "../../components/icons/sparkles"; +import type { GiselleNode } from "../../giselle-node/types"; +import { useGraph } from "../../graph/context"; +import { runFlow } from "../composite-actions"; + +interface RunButtonInnerProps + extends React.ButtonHTMLAttributes { + onClick?: () => void; +} +const RunButtonInner = forwardRef( + (props: RunButtonInnerProps, ref) => { + return ( + + ); + }, +); + +export function RunButton() { + const { state, dispatch } = useGraph(); + const finalNodes = state.graph.nodes.filter((node) => node.isFinal); + const handleClickRunButton = (node: GiselleNode) => { + dispatch(runFlow(node)); + }; + if (finalNodes.length === 1) { + return ( + { + handleClickRunButton(finalNodes[0]); + }} + /> + ); + } + return ( + + + + + + + + {finalNodes.map((node) => ( + + + + ))} + + + + + ); +} diff --git a/app/(playground)/p/[agentId]/beta-proto/flow/composite-actions.ts b/app/(playground)/p/[agentId]/beta-proto/flow/composite-actions.ts new file mode 100644 index 00000000..b664c061 --- /dev/null +++ b/app/(playground)/p/[agentId]/beta-proto/flow/composite-actions.ts @@ -0,0 +1,54 @@ +import type { GiselleNode } from "../giselle-node/types"; +import type { ThunkAction } from "../graph/context"; +import { playgroundModes } from "../graph/types"; +import { updateMode } from "../graph/v2/mode"; +import { setFlow } from "./action"; +import { runAction } from "./server-action"; +import { flowStatuses } from "./types"; +import { createFlowActionId, createFlowId, resolveActionLayers } from "./utils"; + +export function runFlow(finalNode: GiselleNode): ThunkAction { + return async (dispatch, getState) => { + const state = getState(); + dispatch( + setFlow({ + input: { + id: createFlowId(), + status: flowStatuses.queued, + finalNodeId: finalNode.id, + }, + }), + ); + dispatch( + updateMode({ + input: { + mode: playgroundModes.view, + }, + }), + ); + const actionLayers = resolveActionLayers( + state.graph.connectors, + finalNode.id, + ); + dispatch( + setFlow({ + input: { + id: createFlowId(), + status: flowStatuses.running, + finalNodeId: finalNode.id, + actionLayers, + }, + }), + ); + for (const actionLayer of actionLayers) { + await Promise.all( + actionLayer.actions.map(async (action) => { + await runAction({ + nodeId: action.nodeId, + agentId: state.graph.agentId, + }); + }), + ); + } + }; +} diff --git a/app/(playground)/p/[agentId]/beta-proto/flow/server-action.ts b/app/(playground)/p/[agentId]/beta-proto/flow/server-action.ts new file mode 100644 index 00000000..66e057af --- /dev/null +++ b/app/(playground)/p/[agentId]/beta-proto/flow/server-action.ts @@ -0,0 +1,159 @@ +"use server"; + +import { agents, db } from "@/drizzle"; +import { eq } from "drizzle-orm"; +import type { Artifact } from "../artifact/types"; +import { type StructuredData, fileStatuses } from "../files/types"; +import { + giselleNodeArchetypes, + textGeneratorParameterNames, +} from "../giselle-node/blueprints"; +import { + type GiselleNode, + type GiselleNodeId, + giselleNodeCategories, +} from "../giselle-node/types"; +import type { Graph } from "../graph/types"; +import type { TextContent } from "../text-content/types"; +import type { AgentId } from "../types"; +import { + type WebSearchItem, + type WebSearchItemReference, + webSearchItemStatus, + webSearchStatus, +} from "../web-search/types"; + +type Source = Artifact | TextContent | StructuredData | WebSearchItem; +interface GatherInstructionSourcesInput { + node: GiselleNode; + graph: Graph; +} +async function gatherInstructionSources(input: GatherInstructionSourcesInput) { + if (!Array.isArray(input.node.properties.sources)) { + return []; + } + const instructionSources: Source[] = []; + for (const source of input.node.properties.sources) { + if ( + typeof source !== "object" || + source === null || + typeof source.id !== "string" || + typeof source.object !== "string" + ) { + continue; + } + if (source.object === "textContent") { + instructionSources.push(source); + } else if (source.object === "artifact.reference") { + const artifact = input.graph.artifacts.find( + (artifact) => artifact.id === source.id, + ); + if (artifact !== undefined) { + instructionSources.push(artifact); + } + } else if (source.object === "file") { + if ( + typeof source.status === "string" && + source.status === fileStatuses.processed && + typeof source.structuredDataBlobUrl === "string" && + typeof source.name === "string" + ) { + const structuredData = await fetch(source.structuredDataBlobUrl).then( + (res) => res.text(), + ); + instructionSources.push({ + id: source.id, + object: "file", + title: source.name, + content: structuredData, + }); + } + } else if (source.object === "webSearch") { + if ( + typeof source.status === "string" && + source.status === webSearchStatus.completed && + Array.isArray(source.items) + ) { + await Promise.all( + (source.items as WebSearchItemReference[]).map(async (item) => { + if (item.status === webSearchItemStatus.completed) { + const webSearchData = await fetch(item.contentBlobUrl).then( + (res) => res.text(), + ); + instructionSources.push({ + id: item.id, + object: "webSearch.item", + url: item.url, + title: item.title, + content: webSearchData, + relevance: item.relevance, + }); + } + }), + ); + } + } + } + return instructionSources; +} + +interface RunActionInput { + agentId: AgentId; + nodeId: GiselleNodeId; +} +export async function runAction(input: RunActionInput) { + const agent = await db.query.agents.findFirst({ + where: eq(agents.id, input.agentId), + }); + if (agent === undefined) { + throw new Error(`Agent with id ${input.agentId} not found`); + } + const graph = agent.graphv2; + + const instructionConnector = graph.connectors.find( + (connector) => + connector.target === input.nodeId && + connector.sourceNodeCategory === giselleNodeCategories.instruction, + ); + + if (instructionConnector === undefined) { + throw new Error(`No instruction connector found for node ${input.nodeId}`); + } + + const instructionNode = graph.nodes.find( + (node) => node.id === instructionConnector.source, + ); + const actionNode = graph.nodes.find( + (node) => node.id === instructionConnector.target, + ); + + if (instructionNode === undefined || actionNode === undefined) { + throw new Error( + `Instruction node ${instructionConnector.source} or action node ${instructionConnector.target} not found`, + ); + } + + const sources = await gatherInstructionSources({ + node: instructionNode, + graph, + }); + + switch (instructionConnector.targetNodeArcheType) { + case giselleNodeArchetypes.textGenerator: + await generateText(); + break; + case giselleNodeArchetypes.webSearch: + await webSearch(); + break; + } +} + +async function generateText() { + console.log( + "\x1b[33m\x1b[1mTODO:\x1b[0m Implement text generation functionality", + ); +} + +async function webSearch() { + console.log("\x1b[33m\x1b[1mTODO:\x1b[0m Implement websearch functionality"); +} diff --git a/app/(playground)/p/[agentId]/beta-proto/flow/types.ts b/app/(playground)/p/[agentId]/beta-proto/flow/types.ts new file mode 100644 index 00000000..79156c8e --- /dev/null +++ b/app/(playground)/p/[agentId]/beta-proto/flow/types.ts @@ -0,0 +1,76 @@ +import type { GiselleNodeId } from "../giselle-node/types"; + +export type FlowId = `flw_${string}`; + +export const flowStatuses = { + queued: "queued", + running: "running", + completed: "completed", + failed: "failed", +} as const; + +type FlowStatus = (typeof flowStatuses)[keyof typeof flowStatuses]; + +interface BaseFlow { + object: "flow"; + id: FlowId; +} +export interface QueuedFlow extends BaseFlow { + status: Extract; + finalNodeId: GiselleNodeId; +} + +export interface RunningFlow extends BaseFlow { + status: Extract; + finalNodeId: GiselleNodeId; + actionLayers: FlowActionLayer[]; +} + +export type Flow = QueuedFlow | RunningFlow; + +export type FlowActionLayerId = `flw.stk_${string}`; +export const flowActionLayerStatuses = { + queued: "queued", + running: "running", + completed: "completed", + failed: "failed", +} as const; +type FlowActionLayerType = + (typeof flowActionLayerStatuses)[keyof typeof flowActionLayerStatuses]; +interface BaseFlowActionLayer { + object: "flow.actionLayer"; + id: FlowActionLayerId; + actions: FlowAction[]; +} +interface QueuedFlowActionLayer extends BaseFlowActionLayer { + status: Extract; +} +interface RunningFlowActionLayer extends BaseFlowActionLayer { + status: Extract; +} +export type FlowActionLayer = QueuedFlowActionLayer | RunningFlowActionLayer; + +export type FlowActionId = `flw.act_${string}`; +export const flowActionStatuses = { + queued: "queued", + running: "running", + completed: "completed", + failed: "failed", +} as const; + +type FlowActionStatus = + (typeof flowActionStatuses)[keyof typeof flowActionStatuses]; + +interface BaseFlowAction { + id: FlowActionId; + object: "flow.action"; + nodeId: GiselleNodeId; +} +interface QueuedFlowAction extends BaseFlowAction { + status: Extract; +} +interface RunningFlowAction extends BaseFlowAction { + status: Extract; +} + +type FlowAction = QueuedFlowAction | RunningFlowAction; diff --git a/app/(playground)/p/[agentId]/beta-proto/flow/utils.ts b/app/(playground)/p/[agentId]/beta-proto/flow/utils.ts new file mode 100644 index 00000000..f94441ce --- /dev/null +++ b/app/(playground)/p/[agentId]/beta-proto/flow/utils.ts @@ -0,0 +1,119 @@ +import { createId } from "@paralleldrive/cuid2"; +import type { ConnectorObject } from "../connector/types"; +import { + type GiselleNodeId, + giselleNodeCategories, +} from "../giselle-node/types"; +import { + type FlowActionId, + type FlowActionLayer, + type FlowActionLayerId, + type FlowId, + flowActionLayerStatuses, + flowActionStatuses, +} from "./types"; + +export const createFlowId = (): FlowId => `flw_${createId()}`; +export const createFlowActionId = (): FlowActionId => `flw.act_${createId()}`; +export const createFlowActionStackId = (): FlowActionLayerId => + `flw.stk_${createId()}`; + +function getRelevantConnectors( + connectors: ConnectorObject[], + targetNode: GiselleNodeId, +): ConnectorObject[] { + const relevantConnectors: ConnectorObject[] = []; + const relevantNodes = new Set([targetNode]); + let connectorsToProcess = connectors.filter( + (connector) => connector.target === targetNode, + ); + + while (connectorsToProcess.length > 0) { + relevantConnectors.push(...connectorsToProcess); + const sourceNodes = connectorsToProcess.map( + (connector) => connector.source, + ); + for (const node of sourceNodes) { + relevantNodes.add(node); + } + + connectorsToProcess = connectors.filter( + (connector) => + !relevantConnectors.includes(connector) && + sourceNodes.includes(connector.target), + ); + } + + return relevantConnectors; +} + +function buildDependencyGraph( + connectors: ConnectorObject[], +): Map> { + const dependencyMap = new Map>(); + + for (const connector of connectors) { + if (connector.sourceNodeCategory === giselleNodeCategories.instruction) { + continue; + } + if (!dependencyMap.has(connector.source)) { + dependencyMap.set(connector.source, new Set()); + } + if (!dependencyMap.has(connector.target)) { + dependencyMap.set(connector.target, new Set()); + } + dependencyMap.get(connector.target)?.add(connector.source); + } + + return dependencyMap; +} + +export function resolveActionLayers( + connectors: ConnectorObject[], + targetNode: GiselleNodeId, +): FlowActionLayer[] { + const relevantConnectors = getRelevantConnectors(connectors, targetNode); + const dependencyMap = buildDependencyGraph(relevantConnectors); + + const result: FlowActionLayer[] = []; + const visited = new Set(); + const nodes = Array.from(dependencyMap.keys()); + + while (visited.size < nodes.length) { + const currentLayer: GiselleNodeId[] = []; + + for (const node of nodes) { + if (!visited.has(node)) { + const dependencies = dependencyMap.get(node) || new Set(); + const isReady = Array.from(dependencies).every((dep) => + visited.has(dep), + ); + + if (isReady) { + currentLayer.push(node); + } + } + } + + if (currentLayer.length === 0 && visited.size < nodes.length) { + throw new Error("Circular dependency detected"); + } + + for (const node of currentLayer) { + visited.add(node); + } + result.push({ + id: createFlowActionStackId(), + object: "flow.actionLayer", + status: flowActionLayerStatuses.queued, + actions: currentLayer.map((nodeId) => ({ + id: createFlowActionId(), + object: "flow.action", + status: flowActionStatuses.queued, + nodeId, + })), + }); + } + + return result; +} diff --git a/app/(playground)/p/[agentId]/beta-proto/graph/actions.ts b/app/(playground)/p/[agentId]/beta-proto/graph/actions.ts index ccbb6204..402e1bfc 100644 --- a/app/(playground)/p/[agentId]/beta-proto/graph/actions.ts +++ b/app/(playground)/p/[agentId]/beta-proto/graph/actions.ts @@ -13,6 +13,7 @@ import { type StructuredData, fileStatuses, } from "../files/types"; +import type { V2FlowAction } from "../flow/action"; import { type GiselleNodeArchetype, giselleNodeArchetypes, @@ -1343,4 +1344,5 @@ export type GraphAction = | RemoveParameterFromNodeAction | UpsertWebSearchAction | V2NodeAction - | V2ModeAction; + | V2ModeAction + | V2FlowAction; diff --git a/app/(playground)/p/[agentId]/beta-proto/graph/reducer.ts b/app/(playground)/p/[agentId]/beta-proto/graph/reducer.ts index cd9d47f4..36627d49 100644 --- a/app/(playground)/p/[agentId]/beta-proto/graph/reducer.ts +++ b/app/(playground)/p/[agentId]/beta-proto/graph/reducer.ts @@ -1,3 +1,4 @@ +import { isV2FlowAction, v2FlowReducer } from "../flow/action"; import type { GraphAction } from "./actions"; import type { GraphState } from "./types"; import { isV2ModeAction, v2ModeReducer } from "./v2/mode"; @@ -25,6 +26,15 @@ export const graphReducer = ( }, }; } + if (isV2FlowAction(action)) { + return { + ...state, + graph: { + ...state.graph, + flow: v2FlowReducer(state.graph.flow, action), + }, + }; + } switch (action.type) { case "addNode": return { diff --git a/app/(playground)/p/[agentId]/beta-proto/graph/types.ts b/app/(playground)/p/[agentId]/beta-proto/graph/types.ts index 43f77054..1a07cb10 100644 --- a/app/(playground)/p/[agentId]/beta-proto/graph/types.ts +++ b/app/(playground)/p/[agentId]/beta-proto/graph/types.ts @@ -1,6 +1,8 @@ import type { Artifact } from "../artifact/types"; import type { ConnectorObject } from "../connector/types"; +import type { Flow } from "../flow/types"; import type { GiselleNode } from "../giselle-node/types"; +import type { AgentId } from "../types"; import type { WebSearch } from "../web-search/types"; export const playgroundModes = { @@ -10,11 +12,13 @@ export const playgroundModes = { export type PlaygroundMode = (typeof playgroundModes)[keyof typeof playgroundModes]; export type Graph = { + agentId: AgentId; nodes: GiselleNode[]; connectors: ConnectorObject[]; artifacts: Artifact[]; webSearches: WebSearch[]; mode: PlaygroundMode; + flow?: Flow | null | undefined; }; export type GraphState = { diff --git a/app/(playground)/p/[agentId]/beta-proto/header.tsx b/app/(playground)/p/[agentId]/beta-proto/header.tsx index 713a2a14..bb404f18 100644 --- a/app/(playground)/p/[agentId]/beta-proto/header.tsx +++ b/app/(playground)/p/[agentId]/beta-proto/header.tsx @@ -3,6 +3,7 @@ import Link from "next/link"; import { SparklesIcon } from "./components/icons/sparkles"; import { ModeButton } from "./components/mode-button"; import { useFeatureFlags } from "./feature-flags/context"; +import { RunButton } from "./flow/components/run-button"; import { useGraph } from "./graph/context"; import { playgroundModes } from "./graph/types"; @@ -40,16 +41,7 @@ export function Header() { )} {viewFlag && (
- +
)} diff --git a/app/(playground)/p/[agentId]/beta-proto/viewer.tsx b/app/(playground)/p/[agentId]/beta-proto/viewer.tsx index 8591b682..4a5c1884 100644 --- a/app/(playground)/p/[agentId]/beta-proto/viewer.tsx +++ b/app/(playground)/p/[agentId]/beta-proto/viewer.tsx @@ -1,8 +1,16 @@ +import { useMemo } from "react"; import bg from "./bg.png"; import { WilliIcon } from "./components/icons/willi"; +import type { ConnectorObject } from "./connector/types"; +import { + type GiselleNodeId, + giselleNodeCategories, +} from "./giselle-node/types"; +import { useGraph } from "./graph/context"; import { Header } from "./header"; export function Viewer() { + const { state } = useGraph(); return (
-
No exist
+ {state.graph.flow == null ? ( +
No exist
+ ) : ( +
+ {state.graph.flow.finalNodeId} +
+ )}
-
- -

- This has not yet been executed -

-

- You have not yet executed the node.
- Let's execute the entire thing and create the final output. -

-
+ {state.graph.flow == null ? ( +
+ +

+ This has not yet been executed +

+

+ You have not yet executed the node.
+ Let's execute the entire thing and create the final output. +

+
+ ) : ( +
{JSON.stringify(state.graph.flow, null, 2)}
+ )}
diff --git a/drizzle/schema.ts b/drizzle/schema.ts index ac66628b..08ed7355 100644 --- a/drizzle/schema.ts +++ b/drizzle/schema.ts @@ -127,13 +127,7 @@ export const agents = pgTable("agents", { .notNull() .references(() => teams.dbId, { onDelete: "cascade" }), name: text("name"), - graphv2: jsonb("graphv2").$type().notNull().default({ - nodes: [], - connectors: [], - artifacts: [], - webSearches: [], - mode: playgroundModes.edit, - }), + graphv2: jsonb("graphv2").$type().notNull(), graph: jsonb("graph") .$type() .notNull() diff --git a/migrations/0004_handy_kylun.sql b/migrations/0004_handy_kylun.sql new file mode 100644 index 00000000..81fa8de8 --- /dev/null +++ b/migrations/0004_handy_kylun.sql @@ -0,0 +1 @@ +ALTER TABLE "agents" ALTER COLUMN "graphv2" DROP DEFAULT; diff --git a/migrations/meta/0004_snapshot.json b/migrations/meta/0004_snapshot.json new file mode 100644 index 00000000..a40ad9b1 --- /dev/null +++ b/migrations/meta/0004_snapshot.json @@ -0,0 +1,1625 @@ +{ + "id": "d687c106-1d4b-4bc2-bf92-b396c8040ec4", + "prevId": "a86fb817-4757-427f-814a-904695837d72", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.agents": { + "name": "agents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "team_db_id": { + "name": "team_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "graphv2": { + "name": "graphv2", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "graph": { + "name": "graph", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{\"nodes\":[],\"edges\":[],\"viewport\":{\"x\":0,\"y\":0,\"zoom\":1}}'::jsonb" + }, + "graph_hash": { + "name": "graph_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "agents_team_db_id_teams_db_id_fk": { + "name": "agents_team_db_id_teams_db_id_fk", + "tableFrom": "agents", + "tableTo": "teams", + "columnsFrom": ["team_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "agents_id_unique": { + "name": "agents_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + }, + "agents_graph_hash_unique": { + "name": "agents_graph_hash_unique", + "nullsNotDistinct": false, + "columns": ["graph_hash"] + } + } + }, + "public.builds": { + "name": "builds", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "graph": { + "name": "graph", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "graph_hash": { + "name": "graph_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_db_id": { + "name": "agent_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "before_id": { + "name": "before_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "after_id": { + "name": "after_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "builds_agent_db_id_agents_db_id_fk": { + "name": "builds_agent_db_id_agents_db_id_fk", + "tableFrom": "builds", + "tableTo": "agents", + "columnsFrom": ["agent_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "builds_id_unique": { + "name": "builds_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + }, + "builds_graph_hash_unique": { + "name": "builds_graph_hash_unique", + "nullsNotDistinct": false, + "columns": ["graph_hash"] + } + } + }, + "public.edges": { + "name": "edges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "build_db_id": { + "name": "build_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_port_db_id": { + "name": "target_port_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "source_port_db_id": { + "name": "source_port_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "edges_build_db_id_builds_db_id_fk": { + "name": "edges_build_db_id_builds_db_id_fk", + "tableFrom": "edges", + "tableTo": "builds", + "columnsFrom": ["build_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "edges_target_port_db_id_ports_db_id_fk": { + "name": "edges_target_port_db_id_ports_db_id_fk", + "tableFrom": "edges", + "tableTo": "ports", + "columnsFrom": ["target_port_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "edges_source_port_db_id_ports_db_id_fk": { + "name": "edges_source_port_db_id_ports_db_id_fk", + "tableFrom": "edges", + "tableTo": "ports", + "columnsFrom": ["source_port_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "edges_target_port_db_id_source_port_db_id_unique": { + "name": "edges_target_port_db_id_source_port_db_id_unique", + "nullsNotDistinct": false, + "columns": ["target_port_db_id", "source_port_db_id"] + }, + "edges_id_build_db_id_unique": { + "name": "edges_id_build_db_id_unique", + "nullsNotDistinct": false, + "columns": ["id", "build_db_id"] + } + } + }, + "public.file_openai_file_representations": { + "name": "file_openai_file_representations", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "file_db_id": { + "name": "file_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "openai_file_id": { + "name": "openai_file_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "file_openai_file_representations_file_db_id_files_db_id_fk": { + "name": "file_openai_file_representations_file_db_id_files_db_id_fk", + "tableFrom": "file_openai_file_representations", + "tableTo": "files", + "columnsFrom": ["file_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "file_openai_file_representations_openai_file_id_unique": { + "name": "file_openai_file_representations_openai_file_id_unique", + "nullsNotDistinct": false, + "columns": ["openai_file_id"] + } + } + }, + "public.files": { + "name": "files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "blob_url": { + "name": "blob_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "files_id_unique": { + "name": "files_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + }, + "public.knowledge_content_openai_vector_store_file_representations": { + "name": "knowledge_content_openai_vector_store_file_representations", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "knowledge_content_db_id": { + "name": "knowledge_content_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "openai_vector_store_file_id": { + "name": "openai_vector_store_file_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "openai_vector_store_status": { + "name": "openai_vector_store_status", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "knowledge_content_openai_vector_store_file_representations_knowledge_content_db_id_knowledge_contents_db_id_fk": { + "name": "knowledge_content_openai_vector_store_file_representations_knowledge_content_db_id_knowledge_contents_db_id_fk", + "tableFrom": "knowledge_content_openai_vector_store_file_representations", + "tableTo": "knowledge_contents", + "columnsFrom": ["knowledge_content_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "kcovsfr_knowledge_content_db_id_unique": { + "name": "kcovsfr_knowledge_content_db_id_unique", + "nullsNotDistinct": false, + "columns": ["knowledge_content_db_id"] + }, + "kcovsfr_openai_vector_store_file_id_unique": { + "name": "kcovsfr_openai_vector_store_file_id_unique", + "nullsNotDistinct": false, + "columns": ["openai_vector_store_file_id"] + } + } + }, + "public.knowledge_contents": { + "name": "knowledge_contents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "knowledge_content_type": { + "name": "knowledge_content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "knowledge_db_id": { + "name": "knowledge_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_db_id": { + "name": "file_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "knowledge_contents_knowledge_db_id_knowledges_db_id_fk": { + "name": "knowledge_contents_knowledge_db_id_knowledges_db_id_fk", + "tableFrom": "knowledge_contents", + "tableTo": "knowledges", + "columnsFrom": ["knowledge_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_contents_file_db_id_files_db_id_fk": { + "name": "knowledge_contents_file_db_id_files_db_id_fk", + "tableFrom": "knowledge_contents", + "tableTo": "files", + "columnsFrom": ["file_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "knowledge_contents_id_unique": { + "name": "knowledge_contents_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + }, + "knowledge_contents_file_db_id_knowledge_db_id_unique": { + "name": "knowledge_contents_file_db_id_knowledge_db_id_unique", + "nullsNotDistinct": false, + "columns": ["file_db_id", "knowledge_db_id"] + } + } + }, + "public.knowledge_openai_vector_store_representations": { + "name": "knowledge_openai_vector_store_representations", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "knowledge_db_id": { + "name": "knowledge_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "openai_vector_store_id": { + "name": "openai_vector_store_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "knowledge_openai_vector_store_representations_knowledge_db_id_knowledges_db_id_fk": { + "name": "knowledge_openai_vector_store_representations_knowledge_db_id_knowledges_db_id_fk", + "tableFrom": "knowledge_openai_vector_store_representations", + "tableTo": "knowledges", + "columnsFrom": ["knowledge_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "knowledge_openai_vector_store_representations_openai_vector_store_id_unique": { + "name": "knowledge_openai_vector_store_representations_openai_vector_store_id_unique", + "nullsNotDistinct": false, + "columns": ["openai_vector_store_id"] + } + } + }, + "public.knowledges": { + "name": "knowledges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_db_id": { + "name": "agent_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "knowledges_agent_db_id_agents_db_id_fk": { + "name": "knowledges_agent_db_id_agents_db_id_fk", + "tableFrom": "knowledges", + "tableTo": "agents", + "columnsFrom": ["agent_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "knowledges_id_unique": { + "name": "knowledges_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + }, + "public.nodes": { + "name": "nodes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "build_db_id": { + "name": "build_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "class_name": { + "name": "class_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "graph": { + "name": "graph", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "nodes_build_db_id_builds_db_id_fk": { + "name": "nodes_build_db_id_builds_db_id_fk", + "tableFrom": "nodes", + "tableTo": "builds", + "columnsFrom": ["build_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "nodes_id_build_db_id_unique": { + "name": "nodes_id_build_db_id_unique", + "nullsNotDistinct": false, + "columns": ["id", "build_db_id"] + } + } + }, + "public.oauth_credentials": { + "name": "oauth_credentials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_account_id": { + "name": "provider_account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "oauth_credentials_user_id_users_db_id_fk": { + "name": "oauth_credentials_user_id_users_db_id_fk", + "tableFrom": "oauth_credentials", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_credentials_user_id_provider_provider_account_id_unique": { + "name": "oauth_credentials_user_id_provider_provider_account_id_unique", + "nullsNotDistinct": false, + "columns": ["user_id", "provider", "provider_account_id"] + } + } + }, + "public.organizations": { + "name": "organizations", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.ports": { + "name": "ports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "node_db_id": { + "name": "node_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "ports_node_db_id_nodes_db_id_fk": { + "name": "ports_node_db_id_nodes_db_id_fk", + "tableFrom": "ports", + "tableTo": "nodes", + "columnsFrom": ["node_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "ports_id_node_db_id_unique": { + "name": "ports_id_node_db_id_unique", + "nullsNotDistinct": false, + "columns": ["id", "node_db_id"] + } + } + }, + "public.request_port_messages": { + "name": "request_port_messages", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_db_id": { + "name": "request_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "port_db_id": { + "name": "port_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "request_port_messages_request_db_id_requests_db_id_fk": { + "name": "request_port_messages_request_db_id_requests_db_id_fk", + "tableFrom": "request_port_messages", + "tableTo": "requests", + "columnsFrom": ["request_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "request_port_messages_port_db_id_ports_db_id_fk": { + "name": "request_port_messages_port_db_id_ports_db_id_fk", + "tableFrom": "request_port_messages", + "tableTo": "ports", + "columnsFrom": ["port_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_port_messages_request_db_id_port_db_id_unique": { + "name": "request_port_messages_request_db_id_port_db_id_unique", + "nullsNotDistinct": false, + "columns": ["request_db_id", "port_db_id"] + } + } + }, + "public.request_results": { + "name": "request_results", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_db_id": { + "name": "request_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "request_results_request_db_id_requests_db_id_fk": { + "name": "request_results_request_db_id_requests_db_id_fk", + "tableFrom": "request_results", + "tableTo": "requests", + "columnsFrom": ["request_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_results_request_db_id_unique": { + "name": "request_results_request_db_id_unique", + "nullsNotDistinct": false, + "columns": ["request_db_id"] + } + } + }, + "public.request_runners": { + "name": "request_runners", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_db_id": { + "name": "request_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "runner_id": { + "name": "runner_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "request_runners_request_db_id_requests_db_id_fk": { + "name": "request_runners_request_db_id_requests_db_id_fk", + "tableFrom": "request_runners", + "tableTo": "requests", + "columnsFrom": ["request_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_runners_runner_id_unique": { + "name": "request_runners_runner_id_unique", + "nullsNotDistinct": false, + "columns": ["runner_id"] + } + } + }, + "public.request_stack_runners": { + "name": "request_stack_runners", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_stack_db_id": { + "name": "request_stack_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "runner_id": { + "name": "runner_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "request_stack_runners_request_stack_db_id_request_stacks_db_id_fk": { + "name": "request_stack_runners_request_stack_db_id_request_stacks_db_id_fk", + "tableFrom": "request_stack_runners", + "tableTo": "request_stacks", + "columnsFrom": ["request_stack_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_stack_runners_runner_id_unique": { + "name": "request_stack_runners_runner_id_unique", + "nullsNotDistinct": false, + "columns": ["runner_id"] + } + } + }, + "public.request_stacks": { + "name": "request_stacks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_db_id": { + "name": "request_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "start_node_db_id": { + "name": "start_node_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "end_node_db_id": { + "name": "end_node_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "request_stacks_request_db_id_requests_db_id_fk": { + "name": "request_stacks_request_db_id_requests_db_id_fk", + "tableFrom": "request_stacks", + "tableTo": "requests", + "columnsFrom": ["request_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "request_stacks_start_node_db_id_nodes_db_id_fk": { + "name": "request_stacks_start_node_db_id_nodes_db_id_fk", + "tableFrom": "request_stacks", + "tableTo": "nodes", + "columnsFrom": ["start_node_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "request_stacks_end_node_db_id_nodes_db_id_fk": { + "name": "request_stacks_end_node_db_id_nodes_db_id_fk", + "tableFrom": "request_stacks", + "tableTo": "nodes", + "columnsFrom": ["end_node_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_stacks_id_unique": { + "name": "request_stacks_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + }, + "public.request_steps": { + "name": "request_steps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "request_stack_db_id": { + "name": "request_stack_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "node_db_id": { + "name": "node_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'in_progress'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "request_steps_request_stack_db_id_request_stacks_db_id_fk": { + "name": "request_steps_request_stack_db_id_request_stacks_db_id_fk", + "tableFrom": "request_steps", + "tableTo": "request_stacks", + "columnsFrom": ["request_stack_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "request_steps_node_db_id_nodes_db_id_fk": { + "name": "request_steps_node_db_id_nodes_db_id_fk", + "tableFrom": "request_steps", + "tableTo": "nodes", + "columnsFrom": ["node_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "request_steps_id_unique": { + "name": "request_steps_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + }, + "public.requests": { + "name": "requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "build_db_id": { + "name": "build_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "requests_build_db_id_builds_db_id_fk": { + "name": "requests_build_db_id_builds_db_id_fk", + "tableFrom": "requests", + "tableTo": "builds", + "columnsFrom": ["build_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "requests_id_unique": { + "name": "requests_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + }, + "public.stripe_user_mappings": { + "name": "stripe_user_mappings", + "schema": "", + "columns": { + "user_db_id": { + "name": "user_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "stripe_user_mappings_user_db_id_users_db_id_fk": { + "name": "stripe_user_mappings_user_db_id_users_db_id_fk", + "tableFrom": "stripe_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "stripe_user_mappings_user_db_id_unique": { + "name": "stripe_user_mappings_user_db_id_unique", + "nullsNotDistinct": false, + "columns": ["user_db_id"] + }, + "stripe_user_mappings_stripe_customer_id_unique": { + "name": "stripe_user_mappings_stripe_customer_id_unique", + "nullsNotDistinct": false, + "columns": ["stripe_customer_id"] + } + } + }, + "public.subscriptions": { + "name": "subscriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "organization_db_id": { + "name": "organization_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancel_at_period_end": { + "name": "cancel_at_period_end", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "cancel_at": { + "name": "cancel_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "current_period_start": { + "name": "current_period_start", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "current_period_end": { + "name": "current_period_end", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created": { + "name": "created", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "trial_start": { + "name": "trial_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "trial_end": { + "name": "trial_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "subscriptions_organization_db_id_organizations_db_id_fk": { + "name": "subscriptions_organization_db_id_organizations_db_id_fk", + "tableFrom": "subscriptions", + "tableTo": "organizations", + "columnsFrom": ["organization_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "subscriptions_id_unique": { + "name": "subscriptions_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + }, + "public.supabase_user_mappings": { + "name": "supabase_user_mappings", + "schema": "", + "columns": { + "user_db_id": { + "name": "user_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "supabase_user_id": { + "name": "supabase_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "supabase_user_mappings_user_db_id_users_db_id_fk": { + "name": "supabase_user_mappings_user_db_id_users_db_id_fk", + "tableFrom": "supabase_user_mappings", + "tableTo": "users", + "columnsFrom": ["user_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "supabase_user_mappings_user_db_id_unique": { + "name": "supabase_user_mappings_user_db_id_unique", + "nullsNotDistinct": false, + "columns": ["user_db_id"] + }, + "supabase_user_mappings_supabase_user_id_unique": { + "name": "supabase_user_mappings_supabase_user_id_unique", + "nullsNotDistinct": false, + "columns": ["supabase_user_id"] + } + } + }, + "public.team_memberships": { + "name": "team_memberships", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_db_id": { + "name": "user_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "team_db_id": { + "name": "team_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "team_memberships_user_db_id_users_db_id_fk": { + "name": "team_memberships_user_db_id_users_db_id_fk", + "tableFrom": "team_memberships", + "tableTo": "users", + "columnsFrom": ["user_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "team_memberships_team_db_id_teams_db_id_fk": { + "name": "team_memberships_team_db_id_teams_db_id_fk", + "tableFrom": "team_memberships", + "tableTo": "teams", + "columnsFrom": ["team_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "team_memberships_user_db_id_team_db_id_unique": { + "name": "team_memberships_user_db_id_team_db_id_unique", + "nullsNotDistinct": false, + "columns": ["user_db_id", "team_db_id"] + } + } + }, + "public.teams": { + "name": "teams", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "organization_db_id": { + "name": "organization_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "teams_organization_db_id_organizations_db_id_fk": { + "name": "teams_organization_db_id_organizations_db_id_fk", + "tableFrom": "teams", + "tableTo": "organizations", + "columnsFrom": ["organization_db_id"], + "columnsTo": ["db_id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.trigger_nodes": { + "name": "trigger_nodes", + "schema": "", + "columns": { + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "build_db_id": { + "name": "build_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "node_db_id": { + "name": "node_db_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "trigger_nodes_build_db_id_builds_db_id_fk": { + "name": "trigger_nodes_build_db_id_builds_db_id_fk", + "tableFrom": "trigger_nodes", + "tableTo": "builds", + "columnsFrom": ["build_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "trigger_nodes_node_db_id_nodes_db_id_fk": { + "name": "trigger_nodes_node_db_id_nodes_db_id_fk", + "tableFrom": "trigger_nodes", + "tableTo": "nodes", + "columnsFrom": ["node_db_id"], + "columnsTo": ["db_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "trigger_nodes_build_db_id_unique": { + "name": "trigger_nodes_build_db_id_unique", + "nullsNotDistinct": false, + "columns": ["build_db_id"] + } + } + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "db_id": { + "name": "db_id", + "type": "serial", + "primaryKey": true, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_id_unique": { + "name": "users_id_unique", + "nullsNotDistinct": false, + "columns": ["id"] + } + } + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index 9c49b17f..e99fe607 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -29,6 +29,13 @@ "when": 1729227804577, "tag": "0003_messy_fabian_cortez", "breakpoints": true + }, + { + "idx": 4, + "version": "7", + "when": 1729759218608, + "tag": "0004_handy_kylun", + "breakpoints": true } ] } diff --git a/scripts/20241024-db-patch-add-agent-id.ts b/scripts/20241024-db-patch-add-agent-id.ts new file mode 100644 index 00000000..24efafab --- /dev/null +++ b/scripts/20241024-db-patch-add-agent-id.ts @@ -0,0 +1,23 @@ +import { playgroundModes } from "@/app/(playground)/p/[agentId]/beta-proto/graph/types"; +import { + type MigrateGraphV2Function, + migrateAgents, +} from "./utils/agent-data-migration"; + +// Logging the start of the operation with more detail +console.log( + "Starting the update of agent data to set 'agentId' property on graph.", +); + +// Function to update the graph of an agent +const updateAgentGraph: MigrateGraphV2Function = (agent) => ({ + ...agent.graphv2, + agentId: agent.id, +}); + +await migrateAgents({ + migrateGraphV2: updateAgentGraph, // Pass the function instead of inline definition +}); + +// Final log statement completion +console.log("All agents have been successfully updated!"); diff --git a/services/agents/actions/create-agent.ts b/services/agents/actions/create-agent.ts index d2c49e86..11433b76 100644 --- a/services/agents/actions/create-agent.ts +++ b/services/agents/actions/create-agent.ts @@ -1,6 +1,7 @@ "use server"; import { getCurrentTeam } from "@/app/(auth)/lib"; +import { playgroundModes } from "@/app/(playground)/p/[agentId]/beta-proto/graph/types"; import { agents, db } from "@/drizzle"; import { createId } from "@paralleldrive/cuid2"; import { revalidateGetAgents } from "./get-agent"; @@ -14,6 +15,14 @@ export const createAgent = async (args: CreateAgentArgs) => { await db.insert(agents).values({ id, teamDbId: team.dbId, + graphv2: { + agentId: id, + nodes: [], + connectors: [], + artifacts: [], + webSearches: [], + mode: playgroundModes.edit, + }, }); revalidateGetAgents({ userId: args.userId,