Skip to content
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

Simplify actions typing #11390

Merged
merged 14 commits into from
Mar 16, 2025
Prev Previous commit
Next Next commit
Simplify Process action
Fraggle committed Mar 16, 2025
commit 37327741c371f5309488f36d28d07eddd1ad3749
4 changes: 2 additions & 2 deletions front/components/actions/process/ProcessActionDetails.tsx
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ import { useMemo } from "react";

import { ActionDetailsWrapper } from "@app/components/actions/ActionDetailsWrapper";
import type { ActionDetailsComponentBaseProps } from "@app/components/actions/types";
import type { ProcessActionType } from "@app/lib/actions/types/process";
import { PROCESS_ACTION_TOP_K } from "@app/lib/actions/types/process";
import type { ProcessActionType } from "@app/lib/actions/process";
import { PROCESS_ACTION_TOP_K } from "@app/lib/actions/process";

export function ProcessActionDetails({
action,
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import type {
AssistantBuilderProcessConfiguration,
} from "@app/components/assistant_builder/types";
import { EmptyCallToAction } from "@app/components/EmptyCallToAction";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/types/process";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/process";
import { classNames } from "@app/lib/utils";
import type { Result, SpaceType, WorkspaceType } from "@app/types";
import { Err, Ok } from "@app/types";
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {
} from "@app/components/assistant_builder/types";
import { REASONING_MODEL_CONFIGS } from "@app/components/providers/types";
import type { DustAppRunConfigurationType } from "@app/lib/actions/dust_app_run";
import type { ProcessConfigurationType } from "@app/lib/actions/process";
import type { TablesQueryConfigurationType } from "@app/lib/actions/tables_query";
import type { AgentActionConfigurationType } from "@app/lib/actions/types/agent";
import {
@@ -21,7 +22,6 @@ import {
isTablesQueryConfiguration,
isWebsearchConfiguration,
} from "@app/lib/actions/types/guards";
import type { ProcessConfigurationType } from "@app/lib/actions/types/process";
import type { ReasoningConfigurationType } from "@app/lib/actions/types/reasoning";
import type { RetrievalConfigurationType } from "@app/lib/actions/types/retrieval";
import { getContentNodesForDataSourceView } from "@app/lib/api/data_source_view";
2 changes: 1 addition & 1 deletion front/components/assistant_builder/types.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import {
DEFAULT_TABLES_QUERY_ACTION_NAME,
DEFAULT_WEBSEARCH_ACTION_NAME,
} from "@app/lib/actions/constants";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/types/process";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/process";
import type { FetchAssistantTemplateResponse } from "@app/pages/api/templates/[tId]";
import type {
AgentConfigurationScope,
2 changes: 1 addition & 1 deletion front/lib/actions/browse.ts
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ type BrowseSuccessEvent = {
action: BrowseActionType;
};

export type BrowseRunningActionEvents = BrowseParamsEvent;
export type BrowseActionRunningEvents = BrowseParamsEvent;

function isStringArray(value: unknown): value is string[] {
return Array.isArray(value) && value.every((t) => typeof t === "string");
2 changes: 1 addition & 1 deletion front/lib/actions/configuration/process.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { Op } from "sequelize";
import { renderRetrievalTimeframeType } from "@app/lib/actions/configuration/helpers";
import { getDataSource } from "@app/lib/actions/configuration/retrieval";
import { DEFAULT_PROCESS_ACTION_NAME } from "@app/lib/actions/constants";
import type { ProcessConfigurationType } from "@app/lib/actions/types/process";
import type { ProcessConfigurationType } from "@app/lib/actions/process";
import { AgentDataSourceConfiguration } from "@app/lib/models/assistant/actions/data_sources";
import { AgentProcessConfiguration } from "@app/lib/models/assistant/actions/process";
import { Workspace } from "@app/lib/models/workspace";
144 changes: 115 additions & 29 deletions front/lib/actions/process.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import {
timeFrameFromNow,
} from "@app/lib/actions/retrieval";
import { runActionStreamed } from "@app/lib/actions/server";
import type { ExtractActionBlob } from "@app/lib/actions/types";
import { BaseAction } from "@app/lib/actions/types";
import type {
ActionConfigurationType,
@@ -20,18 +21,9 @@ import type {
import type { BaseActionRunParams } from "@app/lib/actions/types/base";
import { BaseActionConfigurationServerRunner } from "@app/lib/actions/types/base";
import type {
ProcessActionOutputsType,
ProcessActionType,
ProcessConfigurationType,
ProcessErrorEvent,
ProcessParamsEvent,
ProcessSchemaPropertyType,
ProcessSuccessEvent,
} from "@app/lib/actions/types/process";
import {
PROCESS_ACTION_TOP_K,
renderSchemaPropertiesAsJSONSchema,
} from "@app/lib/actions/types/process";
DataSourceConfiguration,
RetrievalTimeframe,
} from "@app/lib/actions/types/retrieval";
import { constructPromptMultiActions } from "@app/lib/api/assistant/generation";
import { getSupportedModelConfig } from "@app/lib/assistant";
import type { Authenticator } from "@app/lib/auth";
@@ -50,22 +42,110 @@ import type {
} from "@app/types";
import { Ok } from "@app/types";

interface ProcessActionBlob {
id: ModelId; // AgentProcessAction.
agentMessageId: ModelId;
params: {
relativeTimeFrame: TimeFrame | null;
tagsIn: string[] | null;
tagsNot: string[] | null;
};
schema: ProcessSchemaPropertyType[];
outputs: ProcessActionOutputsType | null;
functionCallId: string | null;
functionCallName: string | null;
step: number;
export const PROCESS_SCHEMA_ALLOWED_TYPES = [
"string",
"number",
"boolean",
] as const;

// Properties in the process configuration table are stored as an array of objects.
export type ProcessSchemaPropertyType = {
name: string;
type: (typeof PROCESS_SCHEMA_ALLOWED_TYPES)[number];
description: string;
};

function renderSchemaPropertiesAsJSONSchema(
schema: ProcessSchemaPropertyType[]
): { [name: string]: { type: string; description: string } } {
let jsonSchema: { [name: string]: { type: string; description: string } } =
{};

if (schema.length > 0) {
schema.forEach((f) => {
jsonSchema[f.name] = {
type: f.type,
description: f.description,
};
});
} else {
// Default schema for extraction.
jsonSchema = {
required_data: {
type: "string",
description:
"Minimal (short and concise) piece of information extracted to follow instructions",
},
};
}

return jsonSchema;
}

export class ProcessAction extends BaseAction {
export type ProcessConfigurationType = {
id: ModelId;
sId: string;

type: "process_configuration";

dataSources: DataSourceConfiguration[];
relativeTimeFrame: RetrievalTimeframe;
schema: ProcessSchemaPropertyType[];

name: string;
description: string | null;
};

export type ProcessActionOutputsType = {
data: unknown[];
min_timestamp: number;
total_documents: number;
total_chunks: number;
total_tokens: number;
};

// Use top_k of 768 as 512 worked really smoothly during initial tests. Might update to 1024 in the
// future based on user feedback.
export const PROCESS_ACTION_TOP_K = 768;

/**
* Process Action Events
*/

// Event sent before the execution with the finalized params to be used.
type ProcessParamsEvent = {
type: "process_params";
created: number;
configurationId: string;
messageId: string;
dataSources: DataSourceConfiguration[];
action: ProcessActionType;
};

type ProcessErrorEvent = {
type: "process_error";
created: number;
configurationId: string;
messageId: string;
error: {
code: string;
message: string;
};
};

type ProcessSuccessEvent = {
type: "process_success";
created: number;
configurationId: string;
messageId: string;
action: ProcessActionType;
};

export type ProcessActionRunningEvents = ProcessParamsEvent;

type ProcessActionBlob = ExtractActionBlob<ProcessActionType>;

export class ProcessActionType extends BaseAction {
readonly agentMessageId: ModelId;
readonly params: {
relativeTimeFrame: TimeFrame | null;
@@ -275,7 +355,7 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
configurationId: agentConfiguration.sId,
messageId: agentMessage.sId,
dataSources: actionConfiguration.dataSources,
action: new ProcessAction({
action: new ProcessActionType({
id: action.id,
agentMessageId: agentMessage.agentMessageId,
params: {
@@ -288,6 +368,8 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
functionCallId: action.functionCallId,
functionCallName: action.functionCallName,
step: action.step,
type: "process_action",
generatedFiles: [],
}),
};

@@ -463,7 +545,7 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
created: Date.now(),
configurationId: agentConfiguration.sId,
messageId: agentMessage.sId,
action: new ProcessAction({
action: new ProcessActionType({
id: action.id,
agentMessageId: agentMessage.agentMessageId,
params: {
@@ -476,6 +558,8 @@ export class ProcessConfigurationServerRunner extends BaseActionConfigurationSer
functionCallId: action.functionCallId,
functionCallName: action.functionCallName,
step: action.step,
type: "process_action",
generatedFiles: [],
}),
};
}
@@ -544,7 +628,7 @@ export async function processActionTypesFromAgentMessageIds(
};
}

return new ProcessAction({
return new ProcessActionType({
id: action.id,
agentMessageId: action.agentMessageId,
params: {
@@ -557,6 +641,8 @@ export async function processActionTypesFromAgentMessageIds(
functionCallId: action.functionCallId,
functionCallName: action.functionCallName,
step: action.step,
type: "process_action",
generatedFiles: [],
});
});
}
2 changes: 1 addition & 1 deletion front/lib/actions/runners.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { BrowseConfigurationServerRunner } from "@app/lib/actions/browse";
import { ConversationIncludeFileConfigurationServerRunner } from "@app/lib/actions/conversation/include_file";
import type { DustAppRunConfigurationType } from "@app/lib/actions/dust_app_run";
import { DustAppRunConfigurationServerRunner } from "@app/lib/actions/dust_app_run";
import type { ProcessConfigurationType } from "@app/lib/actions/process";
import { ProcessConfigurationServerRunner } from "@app/lib/actions/process";
import { ReasoningConfigurationServerRunner } from "@app/lib/actions/reasoning";
import { RetrievalConfigurationServerRunner } from "@app/lib/actions/retrieval";
@@ -16,7 +17,6 @@ import type {
BaseActionConfigurationStaticMethods,
} from "@app/lib/actions/types/base";
import type { ConversationIncludeFileConfigurationType } from "@app/lib/actions/types/conversation/include_file";
import type { ProcessConfigurationType } from "@app/lib/actions/types/process";
import type { ReasoningConfigurationType } from "@app/lib/actions/types/reasoning";
import type { RetrievalConfigurationType } from "@app/lib/actions/types/retrieval";
import type { SearchLabelsConfigurationType } from "@app/lib/actions/types/search_labels";
14 changes: 7 additions & 7 deletions front/lib/actions/types/agent.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import type {
BrowseActionRunningEvents,
BrowseConfigurationType,
BrowseRunningActionEvents,
} from "@app/lib/actions/browse";
import type {
DustAppRunActionRunningEvents,
DustAppRunConfigurationType,
} from "@app/lib/actions/dust_app_run";
import type {
ProcessActionRunningEvents,
ProcessConfigurationType,
} from "@app/lib/actions/process";
import type {
TablesQueryActionRunningEvents,
TablesQueryConfigurationType,
@@ -14,10 +18,6 @@ import type {
ConversationIncludeFileConfigurationType,
ConversationIncludeFileParamsEvent,
} from "@app/lib/actions/types/conversation/include_file";
import type {
ProcessConfigurationType,
ProcessParamsEvent,
} from "@app/lib/actions/types/process";
import type {
ReasoningConfigurationType,
ReasoningStartedEvent,
@@ -113,10 +113,10 @@ export type AgentActionSpecification = {

// Event sent during the execution of an action. These are action specific.
export type AgentActionSpecificEvent =
| BrowseRunningActionEvents
| BrowseActionRunningEvents
| ConversationIncludeFileParamsEvent
| DustAppRunActionRunningEvents
| ProcessParamsEvent
| ProcessActionRunningEvents
| ReasoningStartedEvent
| ReasoningThinkingEvent
| ReasoningTokensEvent
8 changes: 4 additions & 4 deletions front/lib/actions/types/guards.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,10 @@ import type {
DustAppRunActionType,
DustAppRunConfigurationType,
} from "@app/lib/actions/dust_app_run";
import type {
ProcessActionType,
ProcessConfigurationType,
} from "@app/lib/actions/process";
import type {
TablesQueryActionType,
TablesQueryConfigurationType,
@@ -15,10 +19,6 @@ import type {
ConversationIncludeFileActionType,
ConversationIncludeFileConfigurationType,
} from "@app/lib/actions/types/conversation/include_file";
import type {
ProcessActionType,
ProcessConfigurationType,
} from "@app/lib/actions/types/process";
import type { ReasoningConfigurationType } from "@app/lib/actions/types/reasoning";
import type {
RetrievalActionType,
127 changes: 0 additions & 127 deletions front/lib/actions/types/process.ts

This file was deleted.

2 changes: 1 addition & 1 deletion front/lib/api/assistant/configuration.ts
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ import {
DEFAULT_TABLES_QUERY_ACTION_NAME,
DEFAULT_WEBSEARCH_ACTION_NAME,
} from "@app/lib/actions/constants";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/process";
import type { TableDataSourceConfiguration } from "@app/lib/actions/tables_query";
import type { AgentActionConfigurationType } from "@app/lib/actions/types/agent";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/types/process";
import type {
DataSourceConfiguration,
RetrievalTimeframe,
2 changes: 1 addition & 1 deletion front/lib/api/assistant/configuration/process.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { Op } from "sequelize";
import { renderRetrievalTimeframeType } from "@app/lib/actions/configuration/helpers";
import { getDataSource } from "@app/lib/actions/configuration/retrieval";
import { DEFAULT_PROCESS_ACTION_NAME } from "@app/lib/actions/constants";
import type { ProcessConfigurationType } from "@app/lib/actions/types/process";
import type { ProcessConfigurationType } from "@app/lib/actions/process";
import { AgentDataSourceConfiguration } from "@app/lib/models/assistant/actions/data_sources";
import { AgentProcessConfiguration } from "@app/lib/models/assistant/actions/process";
import { Workspace } from "@app/lib/models/workspace";
2 changes: 1 addition & 1 deletion front/lib/models/assistant/actions/process.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { DataTypes } from "sequelize";
import type {
ProcessActionOutputsType,
ProcessSchemaPropertyType,
} from "@app/lib/actions/types/process";
} from "@app/lib/actions/process";
import { AgentConfiguration } from "@app/lib/models/assistant/agent";
import { AgentMessage } from "@app/lib/models/assistant/conversation";
import { frontSequelize } from "@app/lib/resources/storage";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { NextApiRequest, NextApiResponse } from "next";

import type { ProcessSchemaPropertyType } from "@app/lib/actions/process";
import { PROCESS_SCHEMA_ALLOWED_TYPES } from "@app/lib/actions/process";
import { runAction } from "@app/lib/actions/server";
import type { ProcessSchemaPropertyType } from "@app/lib/actions/types/process";
import { PROCESS_SCHEMA_ALLOWED_TYPES } from "@app/lib/actions/types/process";
import { withSessionAuthenticationForWorkspace } from "@app/lib/api/auth_wrappers";
import type { Authenticator } from "@app/lib/auth";
import { cloneBaseConfig, getDustProdActionRegistry } from "@app/lib/registry";
2 changes: 1 addition & 1 deletion front/types/assistant/conversation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { BrowseActionType } from "@app/lib/actions/browse";
import type { DustAppRunActionType } from "@app/lib/actions/dust_app_run";
import type { ProcessActionType } from "@app/lib/actions/process";
import type { TablesQueryActionType } from "@app/lib/actions/tables_query";
import type { ConversationIncludeFileActionType } from "@app/lib/actions/types/conversation/include_file";
import type { ConversationListFilesActionType } from "@app/lib/actions/types/conversation/list_files";
import type { ProcessActionType } from "@app/lib/actions/types/process";
import type { ReasoningActionType } from "@app/lib/actions/types/reasoning";
import type { RetrievalActionType } from "@app/lib/actions/types/retrieval";
import type { SearchLabelsActionType } from "@app/lib/actions/types/search_labels";