diff --git a/.changeset/afraid-numbers-sleep.md b/.changeset/afraid-numbers-sleep.md new file mode 100644 index 00000000000..ed22cde3503 --- /dev/null +++ b/.changeset/afraid-numbers-sleep.md @@ -0,0 +1,5 @@ +--- +'@mastra/server': minor +--- + +Removed unsupported experimental textSearch requests. diff --git a/.changeset/eight-times-stop.md b/.changeset/eight-times-stop.md new file mode 100644 index 00000000000..eac8a876cb4 --- /dev/null +++ b/.changeset/eight-times-stop.md @@ -0,0 +1,5 @@ +--- +'@mastra/pg': patch +--- + +Reject unsupported token search predicates. diff --git a/.changeset/obs870-token-cli.md b/.changeset/obs870-token-cli.md new file mode 100644 index 00000000000..d37d47dfd1f --- /dev/null +++ b/.changeset/obs870-token-cli.md @@ -0,0 +1,5 @@ +--- +'mastra': minor +--- + +Updated experimental search commands for supporting hosts. diff --git a/.changeset/obs870-token-clickhouse.md b/.changeset/obs870-token-clickhouse.md new file mode 100644 index 00000000000..5537092e256 --- /dev/null +++ b/.changeset/obs870-token-clickhouse.md @@ -0,0 +1,5 @@ +--- +'@mastra/clickhouse': patch +--- + +Reject unsupported token search predicates. diff --git a/.changeset/obs870-token-client.md b/.changeset/obs870-token-client.md new file mode 100644 index 00000000000..f4f774b7e98 --- /dev/null +++ b/.changeset/obs870-token-client.md @@ -0,0 +1,5 @@ +--- +'@mastra/client-js': minor +--- + +Updated experimental search types for supporting hosts. diff --git a/.changeset/obs870-token-duckdb.md b/.changeset/obs870-token-duckdb.md new file mode 100644 index 00000000000..163154ec1ef --- /dev/null +++ b/.changeset/obs870-token-duckdb.md @@ -0,0 +1,5 @@ +--- +'@mastra/duckdb': patch +--- + +Reject unsupported token search predicates. diff --git a/.changeset/shaky-baths-go.md b/.changeset/shaky-baths-go.md new file mode 100644 index 00000000000..417438dc861 --- /dev/null +++ b/.changeset/shaky-baths-go.md @@ -0,0 +1,5 @@ +--- +'@mastra/core': minor +--- + +Replaced experimental textSearch contracts and capabilities with token predicates for supporting hosts. diff --git a/.changeset/stale-meteors-tell.md b/.changeset/stale-meteors-tell.md new file mode 100644 index 00000000000..bbe32bb1937 --- /dev/null +++ b/.changeset/stale-meteors-tell.md @@ -0,0 +1,5 @@ +--- +'@mastra/playground-ui': minor +--- + +Added content filters with matching histograms for supporting hosts. diff --git a/client-sdks/client-js/src/route-types.generated.ts b/client-sdks/client-js/src/route-types.generated.ts index 0d98083b8b3..a24d327c6cb 100644 --- a/client-sdks/client-js/src/route-types.generated.ts +++ b/client-sdks/client-js/src/route-types.generated.ts @@ -71,6 +71,7 @@ type InputShared_Auxiliary_208 = literal: string; }; } + | InputShared_Type_16 | { op: 'and' | 'or'; args: InputShared_Auxiliary_208[]; @@ -82,32 +83,32 @@ type InputShared_Auxiliary_208 = | { spans: | { - some: InputShared_Auxiliary_231; + some: InputShared_Auxiliary_236; } | { - none: InputShared_Auxiliary_231; + none: InputShared_Auxiliary_236; }; } | { scores: | { - some: InputShared_Auxiliary_231; + some: InputShared_Auxiliary_236; } | { - none: InputShared_Auxiliary_231; + none: InputShared_Auxiliary_236; }; } | { feedback: | { - some: InputShared_Auxiliary_231; + some: InputShared_Auxiliary_236; } | { - none: InputShared_Auxiliary_231; + none: InputShared_Auxiliary_236; }; }; -type InputShared_Auxiliary_231 = +type InputShared_Auxiliary_236 = | { op: 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte'; left: @@ -154,23 +155,24 @@ type InputShared_Auxiliary_231 = literal: string; }; } + | InputShared_Type_16 | { op: 'and' | 'or'; - args: InputShared_Auxiliary_231[]; + args: InputShared_Auxiliary_236[]; } | { op: 'not'; - arg: InputShared_Auxiliary_231; + arg: InputShared_Auxiliary_236; }; -type InputShared_Auxiliary_278 = +type InputShared_Auxiliary_283 = | { op: 'and' | 'or'; - args: InputShared_Auxiliary_278[]; + args: InputShared_Auxiliary_283[]; } | { op: 'not'; - arg: InputShared_Auxiliary_278; + arg: InputShared_Auxiliary_283; } | { traces: @@ -182,7 +184,7 @@ type InputShared_Auxiliary_278 = }; }; -type InputShared_Auxiliary_735 = +type InputShared_Auxiliary_740 = | { op: 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte'; left: @@ -227,19 +229,19 @@ type InputShared_Auxiliary_735 = } | { op: 'and' | 'or'; - args: InputShared_Auxiliary_735[]; + args: InputShared_Auxiliary_740[]; } | { op: 'not'; - arg: InputShared_Auxiliary_735; + arg: InputShared_Auxiliary_740; }; -type InputShared_Auxiliary_809 = { +type InputShared_Auxiliary_814 = { id?: string | undefined; name: string; type: 'file' | 'folder'; content?: string | undefined; - children?: InputShared_Auxiliary_809[] | undefined; + children?: InputShared_Auxiliary_814[] | undefined; }; type Shared_Auxiliary_799 = { @@ -580,7 +582,17 @@ type InputShared_Type_15 = | 'memory' | 'classifier'; -type InputShared_Type_16 = +type InputShared_Type_16 = { + op: 'hasAllTokens'; + left: { + path: 'input' | 'output' | 'error' | 'inputPreview' | 'outputPreview' | 'errorPreview' | 'all'; + }; + right: { + literal: string; + }; +}; + +type InputShared_Type_17 = | 'count' | 'duration.avg' | 'duration.min' @@ -620,7 +632,7 @@ type InputShared_Type_16 = | 'timeToFirstChunk.p99' | 'timeToFirstChunk.count'; -type InputShared_Type_17 = { +type InputShared_Type_18 = { /** Filter by timestamp range */ timestamp?: InputShared_Type_13 | undefined; /** Filter by trace ID */ @@ -683,7 +695,7 @@ type InputShared_Type_17 = { source?: string | undefined; }; -type InputShared_Type_18 = { +type InputShared_Type_19 = { /** Filter by timestamp range */ timestamp?: InputShared_Type_13 | undefined; /** Filter by trace ID */ @@ -743,7 +755,7 @@ type InputShared_Type_18 = { reviewStatus?: ('needs-review' | 'reviewed') | undefined; }; -type InputShared_Type_19 = +type InputShared_Type_20 = | 'entityType' | 'entityName' | 'parentEntityType' @@ -759,7 +771,7 @@ type InputShared_Type_19 = | 'threadId' | 'resourceId'; -type InputShared_Type_20 = { +type InputShared_Type_21 = { /** Filter by timestamp range */ timestamp?: InputShared_Type_13 | undefined; /** Filter by trace ID */ @@ -830,7 +842,7 @@ type InputShared_Type_20 = { | undefined; }; -type InputShared_Type_21 = { +type InputShared_Type_22 = { /** Part type - text for TextParts */ kind: 'text'; /** Text content */ @@ -843,7 +855,7 @@ type InputShared_Type_21 = { | undefined; }; -type InputShared_Type_22 = { +type InputShared_Type_23 = { /** base64 encoded content of the file */ bytes: string; /** Optional mimeType for the file */ @@ -852,7 +864,7 @@ type InputShared_Type_22 = { name?: string | undefined; }; -type InputShared_Type_23 = { +type InputShared_Type_24 = { /** URL for the File content */ uri: string; /** Optional mimeType for the file */ @@ -861,11 +873,11 @@ type InputShared_Type_23 = { name?: string | undefined; }; -type InputShared_Type_24 = { +type InputShared_Type_25 = { /** Part type - file for FileParts */ kind: 'file'; /** File content either as url or bytes */ - file: InputShared_Type_22 | InputShared_Type_23; + file: InputShared_Type_23 | InputShared_Type_24; /** Optional metadata associated with the part */ metadata?: | { @@ -874,7 +886,7 @@ type InputShared_Type_24 = { | undefined; }; -type InputShared_Type_25 = { +type InputShared_Type_26 = { /** Part type - data for DataParts */ kind: 'data'; /** Structured data content */ @@ -889,7 +901,7 @@ type InputShared_Type_25 = { | undefined; }; -type InputShared_Type_26 = { +type InputShared_Type_27 = { text?: string | undefined; raw?: string | undefined; url?: string | undefined; @@ -903,7 +915,7 @@ type InputShared_Type_26 = { | undefined; }; -type InputShared_Type_27 = { +type InputShared_Type_28 = { /** Event type */ kind?: 'message' | undefined; /** Identifier created by the message creator */ @@ -911,7 +923,7 @@ type InputShared_Type_27 = { /** Message sender's role */ role: 'user' | 'agent' | 'ROLE_USER' | 'ROLE_AGENT'; /** Message content */ - parts: ((InputShared_Type_21 | InputShared_Type_24 | InputShared_Type_25) | InputShared_Type_26)[]; + parts: ((InputShared_Type_22 | InputShared_Type_25 | InputShared_Type_26) | InputShared_Type_27)[]; /** The context the message is associated with */ contextId?: string | undefined; /** Identifier of task the message is related to */ @@ -928,24 +940,24 @@ type InputShared_Type_27 = { | undefined; }; -type InputShared_Type_28 = { +type InputShared_Type_29 = { /** Supported authentication schemes - e.g. Basic, Bearer */ schemes: string[]; /** Optional credentials */ credentials?: string | undefined; }; -type InputShared_Type_29 = { +type InputShared_Type_30 = { /** URL for sending the push notifications */ url: string; /** Push Notification ID - created by server to support multiple callbacks */ id?: string | undefined; /** Token unique to this task/session */ token?: string | undefined; - authentication?: InputShared_Type_28 | undefined; + authentication?: InputShared_Type_29 | undefined; }; -type InputShared_Type_30 = { +type InputShared_Type_31 = { /** Accepted output modalities by the client */ acceptedOutputModes?: string[] | undefined; /** If the server should treat the client as a blocking request */ @@ -954,13 +966,13 @@ type InputShared_Type_30 = { returnImmediately?: boolean | undefined; /** Number of recent messages to be retrieved */ historyLength?: number | undefined; - pushNotificationConfig?: InputShared_Type_29 | undefined; - taskPushNotificationConfig?: InputShared_Type_29 | undefined; + pushNotificationConfig?: InputShared_Type_30 | undefined; + taskPushNotificationConfig?: InputShared_Type_30 | undefined; }; -type InputShared_Type_31 = { - message: InputShared_Type_27; - configuration?: InputShared_Type_30 | undefined; +type InputShared_Type_32 = { + message: InputShared_Type_28; + configuration?: InputShared_Type_31 | undefined; /** Extension metadata */ metadata?: | { @@ -969,7 +981,7 @@ type InputShared_Type_31 = { | undefined; }; -type InputShared_Type_32 = +type InputShared_Type_33 = | 'equals' | 'not_equals' | 'contains' @@ -983,33 +995,33 @@ type InputShared_Type_32 = | 'exists' | 'not_exists'; -type InputShared_Type_33 = +type InputShared_Type_34 = | { field: string; - operator: InputShared_Type_32; + operator: InputShared_Type_33; value?: unknown | undefined; } | { operator: 'AND' | 'OR'; conditions: { field: string; - operator: InputShared_Type_32; + operator: InputShared_Type_33; value?: unknown | undefined; }[]; }; -type InputShared_Type_34 = +type InputShared_Type_35 = | { field: string; - operator: InputShared_Type_32; + operator: InputShared_Type_33; value?: unknown | undefined; } | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_33[]; + conditions: InputShared_Type_34[]; }; -type InputShared_Type_35 = +type InputShared_Type_36 = | { type: 'text'; content: string; @@ -1020,7 +1032,7 @@ type InputShared_Type_35 = rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; } @@ -1030,12 +1042,12 @@ type InputShared_Type_35 = rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; -type InputShared_Type_36 = { +type InputShared_Type_37 = { /** Model provider (e.g., openai, anthropic) */ provider: string; /** Model name (e.g., gpt-4o, claude-3-opus) */ @@ -1043,43 +1055,43 @@ type InputShared_Type_36 = { [x: string]: unknown; }; -type InputShared_Type_37 = - | InputShared_Type_36 +type InputShared_Type_38 = + | InputShared_Type_37 | { - value: InputShared_Type_36; + value: InputShared_Type_37; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[]; -type InputShared_Type_38 = { +type InputShared_Type_39 = { [key: string]: { description?: string | undefined; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; }; -type InputShared_Type_39 = - | InputShared_Type_38 +type InputShared_Type_40 = + | InputShared_Type_39 | { - value: InputShared_Type_38; + value: InputShared_Type_39; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[]; -type InputShared_Type_40 = { +type InputShared_Type_41 = { temperature?: number | undefined; maxTokens?: number | undefined; topP?: number | undefined; @@ -1091,7 +1103,7 @@ type InputShared_Type_40 = { maxRetries?: number | undefined; }; -type InputShared_Type_41 = { +type InputShared_Type_42 = { traceName?: string | undefined; attributes?: | { @@ -1102,7 +1114,7 @@ type InputShared_Type_41 = { traceId?: string | undefined; }; -type InputShared_Type_42 = { +type InputShared_Type_43 = { runId?: string | undefined; savePerStep?: boolean | undefined; maxSteps?: number | undefined; @@ -1119,9 +1131,9 @@ type InputShared_Type_42 = { } ) | undefined; - modelSettings?: InputShared_Type_40 | undefined; + modelSettings?: InputShared_Type_41 | undefined; returnScorerData?: boolean | undefined; - tracingOptions?: InputShared_Type_41 | undefined; + tracingOptions?: InputShared_Type_42 | undefined; requireToolApproval?: boolean | undefined; autoResumeSuspendedTools?: boolean | undefined; eagerToolExecution?: boolean | undefined; @@ -1138,32 +1150,32 @@ type InputShared_Type_42 = { [x: string]: unknown; }; -type InputShared_Type_43 = { - /** Default options for agent execution */ - value: InputShared_Type_42; - rules?: - | { - operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; - } - | undefined; -}; - type InputShared_Type_44 = { - value: { - [key: string]: { - tools?: InputShared_Type_38 | undefined; - }; - }; + /** Default options for agent execution */ + value: InputShared_Type_43; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; type InputShared_Type_45 = { + value: { + [key: string]: { + tools?: InputShared_Type_39 | undefined; + }; + }; + rules?: + | { + operator: 'AND' | 'OR'; + conditions: InputShared_Type_35[]; + } + | undefined; +}; + +type InputShared_Type_46 = { kind: 'author' | 'invoker' | 'platform'; toolkit: string; connectionId: string; @@ -1171,7 +1183,7 @@ type InputShared_Type_45 = { scope?: ('shared' | 'per-author' | 'caller-supplied') | undefined; }; -type InputShared_Type_46 = { +type InputShared_Type_47 = { tools: { [key: string]: { toolkit?: string | undefined; @@ -1179,23 +1191,23 @@ type InputShared_Type_46 = { }; }; connections: { - [key: string]: InputShared_Type_45[]; + [key: string]: InputShared_Type_46[]; }; }; -type InputShared_Type_47 = { +type InputShared_Type_48 = { value: { - [key: string]: InputShared_Type_46; + [key: string]: InputShared_Type_47; }; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; -type InputShared_Type_48 = { +type InputShared_Type_49 = { /** Unique ID for this step within the graph */ id: string; /** ProcessorProvider ID that creates this processor */ @@ -1215,77 +1227,77 @@ type InputShared_Type_48 = { )[]; }; -type InputShared_Type_49 = { +type InputShared_Type_50 = { steps: { type: 'step'; - step: InputShared_Type_48; + step: InputShared_Type_49; }[]; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; -type InputShared_Type_50 = +type InputShared_Type_51 = | { type: 'step'; - step: InputShared_Type_48; + step: InputShared_Type_49; } | { type: 'parallel'; branches: { type: 'step'; - step: InputShared_Type_48; + step: InputShared_Type_49; }[][]; } | { type: 'conditional'; - conditions: InputShared_Type_49[]; + conditions: InputShared_Type_50[]; }; -type InputShared_Type_51 = { +type InputShared_Type_52 = { type: 'conditional'; conditions: { - steps: InputShared_Type_50[]; + steps: InputShared_Type_51[]; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[]; }; -type InputShared_Type_52 = { +type InputShared_Type_53 = { /** Ordered list of processor graph entries */ steps: ( | { type: 'step'; - step: InputShared_Type_48; + step: InputShared_Type_49; } | { type: 'parallel'; - branches: InputShared_Type_50[][]; + branches: InputShared_Type_51[][]; } - | InputShared_Type_51 + | InputShared_Type_52 )[]; }; -type InputShared_Type_53 = - | InputShared_Type_52 +type InputShared_Type_54 = + | InputShared_Type_53 | { - value: InputShared_Type_52; + value: InputShared_Type_53; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[]; -type InputShared_Type_54 = { +type InputShared_Type_55 = { /** Number of semantically similar messages to retrieve */ topK: number; /** Amount of surrounding context to include with each retrieved message */ @@ -1303,7 +1315,7 @@ type InputShared_Type_54 = { indexName?: string | undefined; }; -type InputShared_Type_55 = { +type InputShared_Type_56 = { /** Model ID in format provider/model-name (ModelRouterModelId); defaults to the agent's own model */ model?: string | undefined; /** Custom instructions for title generation */ @@ -1314,7 +1326,7 @@ type InputShared_Type_55 = { emitEvent?: boolean | undefined; }; -type InputShared_Type_56 = { +type InputShared_Type_57 = { readOnly?: boolean | undefined; lastMessages?: (number | false) | undefined; messageHistory?: @@ -1323,11 +1335,11 @@ type InputShared_Type_56 = { atMaxRemoveTokens?: number | undefined; } | undefined; - semanticRecall?: (boolean | InputShared_Type_54) | undefined; - generateTitle?: (boolean | InputShared_Type_55) | undefined; + semanticRecall?: (boolean | InputShared_Type_55) | undefined; + generateTitle?: (boolean | InputShared_Type_56) | undefined; }; -type InputShared_Type_57 = { +type InputShared_Type_58 = { /** Observer model ID */ model?: string | undefined; /** Token threshold that triggers observation */ @@ -1358,7 +1370,7 @@ type InputShared_Type_57 = { blockAfter?: number | undefined; }; -type InputShared_Type_58 = { +type InputShared_Type_59 = { /** Reflector model ID */ model?: string | undefined; /** Token threshold that triggers reflection */ @@ -1385,7 +1397,7 @@ type InputShared_Type_58 = { bufferActivation?: number | undefined; }; -type InputShared_Type_59 = { +type InputShared_Type_60 = { /** Model ID for both Observer and Reflector */ model?: string | undefined; /** Memory scope */ @@ -1393,33 +1405,16 @@ type InputShared_Type_59 = { /** Share token budget between messages and observations */ shareTokenBudget?: boolean | undefined; /** Observation step configuration */ - observation?: InputShared_Type_57 | undefined; + observation?: InputShared_Type_58 | undefined; /** Reflection step configuration */ - reflection?: InputShared_Type_58 | undefined; -}; - -type InputShared_Type_60 = { - /** Vector database identifier or false to disable */ - vector?: (string | false) | undefined; - /** Memory behavior configuration, excluding workingMemory and threads */ - options?: InputShared_Type_56 | undefined; - /** Embedding model ID in the format "provider/model" (e.g., "openai/text-embedding-3-small") */ - embedder?: string | undefined; - /** Options to pass to the embedder, omitting telemetry */ - embedderOptions?: - | { - [key: string]: unknown; - } - | undefined; - /** Serialized observational memory configuration */ - observationalMemory?: (boolean | InputShared_Type_59) | undefined; + reflection?: InputShared_Type_59 | undefined; }; type InputShared_Type_61 = { /** Vector database identifier or false to disable */ vector?: (string | false) | undefined; /** Memory behavior configuration, excluding workingMemory and threads */ - options?: InputShared_Type_56 | undefined; + options?: InputShared_Type_57 | undefined; /** Embedding model ID in the format "provider/model" (e.g., "openai/text-embedding-3-small") */ embedder?: string | undefined; /** Options to pass to the embedder, omitting telemetry */ @@ -1429,11 +1424,28 @@ type InputShared_Type_61 = { } | undefined; /** Serialized observational memory configuration */ - observationalMemory?: (boolean | InputShared_Type_59) | undefined; + observationalMemory?: (boolean | InputShared_Type_60) | undefined; +}; + +type InputShared_Type_62 = { + /** Vector database identifier or false to disable */ + vector?: (string | false) | undefined; + /** Memory behavior configuration, excluding workingMemory and threads */ + options?: InputShared_Type_57 | undefined; + /** Embedding model ID in the format "provider/model" (e.g., "openai/text-embedding-3-small") */ + embedder?: string | undefined; + /** Options to pass to the embedder, omitting telemetry */ + embedderOptions?: + | { + [key: string]: unknown; + } + | undefined; + /** Serialized observational memory configuration */ + observationalMemory?: (boolean | InputShared_Type_60) | undefined; type?: never | undefined; }; -type InputShared_Type_62 = +type InputShared_Type_63 = | { type: 'id'; /** Registry key (or id) of a Memory instance registered on Mastra */ @@ -1441,23 +1453,23 @@ type InputShared_Type_62 = } | { type: 'inline'; - config: InputShared_Type_60; + config: InputShared_Type_61; } - | InputShared_Type_61; + | InputShared_Type_62; -type InputShared_Type_63 = - | InputShared_Type_62 +type InputShared_Type_64 = + | InputShared_Type_63 | { - value: InputShared_Type_62; + value: InputShared_Type_63; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[]; -type InputShared_Type_64 = { +type InputShared_Type_65 = { description?: string | undefined; sampling?: | ( @@ -1473,24 +1485,24 @@ type InputShared_Type_64 = { rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; - } - | undefined; -}; - -type InputShared_Type_65 = { - value: { - [key: string]: InputShared_Type_64; - }; - rules?: - | { - operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; type InputShared_Type_66 = { + value: { + [key: string]: InputShared_Type_65; + }; + rules?: + | { + operator: 'AND' | 'OR'; + conditions: InputShared_Type_35[]; + } + | undefined; +}; + +type InputShared_Type_67 = { [key: string]: { description?: string | undefined; instructions?: string | undefined; @@ -1499,19 +1511,19 @@ type InputShared_Type_66 = { }; }; -type InputShared_Type_67 = - | InputShared_Type_66 +type InputShared_Type_68 = + | InputShared_Type_67 | { - value: InputShared_Type_66; + value: InputShared_Type_67; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[]; -type InputShared_Type_68 = +type InputShared_Type_69 = | { /** Filesystem provider name */ provider: string; @@ -1522,7 +1534,7 @@ type InputShared_Type_68 = } | undefined; -type InputShared_Type_69 = +type InputShared_Type_70 = | { /** Sandbox provider name */ provider: string; @@ -1533,7 +1545,7 @@ type InputShared_Type_69 = } | undefined; -type InputShared_Type_70 = { +type InputShared_Type_71 = { [key: string]: { /** Filesystem provider name */ provider: string; @@ -1544,7 +1556,7 @@ type InputShared_Type_70 = { }; }; -type InputShared_Type_71 = { +type InputShared_Type_72 = { /** Vector store provider identifier */ vectorProvider?: string | undefined; /** Vector store provider-specific configuration */ @@ -1579,7 +1591,7 @@ type InputShared_Type_71 = { autoIndexPaths?: string[] | undefined; }; -type InputShared_Type_72 = { +type InputShared_Type_73 = { /** Whether the tool is enabled */ enabled?: boolean | undefined; /** Whether the tool requires user approval before execution */ @@ -1588,7 +1600,7 @@ type InputShared_Type_72 = { requireReadBeforeWrite?: boolean | undefined; }; -type InputShared_Type_73 = { +type InputShared_Type_74 = { /** Default: whether all tools are enabled */ enabled?: boolean | undefined; /** Default: whether all tools require user approval */ @@ -1596,35 +1608,35 @@ type InputShared_Type_73 = { /** Per-tool overrides keyed by workspace tool name */ tools?: | { - [key: string]: InputShared_Type_72; + [key: string]: InputShared_Type_73; } | undefined; }; -type InputShared_Type_74 = { +type InputShared_Type_75 = { /** Name of the workspace */ name: string; /** Description of the workspace */ description?: string | undefined; /** Filesystem configuration */ - filesystem?: InputShared_Type_68; + filesystem?: InputShared_Type_69; /** Sandbox configuration */ - sandbox?: InputShared_Type_69; + sandbox?: InputShared_Type_70; /** Mounted filesystems keyed by mount path */ - mounts?: InputShared_Type_70 | undefined; + mounts?: InputShared_Type_71 | undefined; /** Search configuration */ - search?: InputShared_Type_71 | undefined; + search?: InputShared_Type_72 | undefined; /** Array of skill IDs */ skills?: string[] | undefined; /** Workspace tool configuration */ - tools?: InputShared_Type_73 | undefined; + tools?: InputShared_Type_74 | undefined; /** Whether to automatically sync the workspace */ autoSync?: boolean | undefined; /** Operation timeout in milliseconds */ operationTimeout?: number | undefined; }; -type InputShared_Type_75 = { +type InputShared_Type_76 = { type: 'provider'; /** Workspace provider identifier */ provider: string; @@ -1634,7 +1646,7 @@ type InputShared_Type_75 = { }; }; -type InputShared_Type_76 = { +type InputShared_Type_77 = { value: | { type: 'id'; @@ -1642,18 +1654,18 @@ type InputShared_Type_76 = { } | { type: 'inline'; - config: InputShared_Type_74; + config: InputShared_Type_75; } - | InputShared_Type_75; + | InputShared_Type_76; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; -type InputShared_Type_77 = +type InputShared_Type_78 = | ( | ( | { @@ -1662,15 +1674,15 @@ type InputShared_Type_77 = } | { type: 'inline'; - config: InputShared_Type_74; + config: InputShared_Type_75; } - | InputShared_Type_75 + | InputShared_Type_76 ) - | InputShared_Type_76[] + | InputShared_Type_77[] ) | undefined; -type InputShared_Type_78 = { +type InputShared_Type_79 = { /** Image format (default: jpeg) */ format?: ('jpeg' | 'png') | undefined; /** JPEG quality 0-100 (default: 80) */ @@ -1683,7 +1695,7 @@ type InputShared_Type_78 = { everyNthFrame?: number | undefined; }; -type InputShared_Type_79 = { +type InputShared_Type_80 = { /** Browser provider type (e.g., stagehand, playwright) */ provider: string; /** Run browser in headless mode (default: true) */ @@ -1700,23 +1712,23 @@ type InputShared_Type_79 = { /** Default timeout in milliseconds (default: 10000) */ timeout?: number | undefined; /** Screencast options for streaming browser frames */ - screencast?: InputShared_Type_78 | undefined; + screencast?: InputShared_Type_79 | undefined; }; -type InputShared_Type_80 = { +type InputShared_Type_81 = { value: { type: 'inline'; - config: InputShared_Type_79; + config: InputShared_Type_80; }; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }; -type InputShared_Type_81 = { +type InputShared_Type_82 = { type: 'agent'; id: string; agentId: string; @@ -1738,7 +1750,7 @@ type InputShared_Type_81 = { | undefined; }; -type InputShared_Type_82 = { +type InputShared_Type_83 = { type: 'tool'; id: string; toolId: string; @@ -1755,7 +1767,7 @@ type InputShared_Type_82 = { | undefined; }; -type InputShared_Type_83 = { +type InputShared_Type_84 = { type: 'mapping'; id: string; description?: string | undefined; @@ -1767,10 +1779,10 @@ type InputShared_Type_83 = { mapConfig: string; }; -type InputShared_Type_84 = - | InputShared_Type_81 +type InputShared_Type_85 = | InputShared_Type_82 | InputShared_Type_83 + | InputShared_Type_84 | { type: 'workflow'; id: string; @@ -1778,7 +1790,7 @@ type InputShared_Type_84 = description?: string | undefined; }; -type InputShared_Type_85 = { +type InputShared_Type_86 = { type: 'parallel'; id?: string | undefined; description?: string | undefined; @@ -1787,10 +1799,10 @@ type InputShared_Type_85 = { [key: string]: unknown; } | undefined; - steps: InputShared_Type_84[]; + steps: InputShared_Type_85[]; }; -type InputShared_Type_86 = { +type InputShared_Type_87 = { type: 'foreach'; id?: string | undefined; description?: string | undefined; @@ -1800,8 +1812,8 @@ type InputShared_Type_86 = { } | undefined; step: - | InputShared_Type_81 | InputShared_Type_82 + | InputShared_Type_83 | { type: 'workflow'; id: string; @@ -1815,7 +1827,7 @@ type InputShared_Type_86 = { | undefined; }; -type InputShared_Type_87 = { +type InputShared_Type_88 = { type: 'sleep'; id: string; description?: string | undefined; @@ -1827,7 +1839,7 @@ type InputShared_Type_87 = { duration: number; }; -type InputShared_Type_88 = { +type InputShared_Type_89 = { type: 'sleepUntil'; id: string; description?: string | undefined; @@ -1839,7 +1851,7 @@ type InputShared_Type_88 = { date: string; }; -type InputShared_Type_89 = { +type InputShared_Type_90 = { type: 'conditional'; id?: string | undefined; description?: string | undefined; @@ -1848,11 +1860,11 @@ type InputShared_Type_89 = { [key: string]: unknown; } | undefined; - steps: InputShared_Type_84[]; - predicates: InputShared_Auxiliary_735[]; + steps: InputShared_Type_85[]; + predicates: InputShared_Auxiliary_740[]; }; -type InputShared_Type_90 = { +type InputShared_Type_91 = { type: 'loop'; id?: string | undefined; description?: string | undefined; @@ -1861,29 +1873,29 @@ type InputShared_Type_90 = { [key: string]: unknown; } | undefined; - step: InputShared_Type_84; + step: InputShared_Type_85; loopType: 'dowhile' | 'dountil'; - predicate: InputShared_Auxiliary_735; + predicate: InputShared_Auxiliary_740; }; -type InputShared_Type_91 = - | InputShared_Type_81 +type InputShared_Type_92 = | InputShared_Type_82 | InputShared_Type_83 + | InputShared_Type_84 | { type: 'workflow'; id: string; workflowId: string; description?: string | undefined; } - | InputShared_Type_85 | InputShared_Type_86 | InputShared_Type_87 | InputShared_Type_88 | InputShared_Type_89 - | InputShared_Type_90; + | InputShared_Type_90 + | InputShared_Type_91; -type InputShared_Type_92 = { +type InputShared_Type_93 = { /** Transport type: stdio for local processes, http for remote servers */ type: 'stdio' | 'http'; /** Command to run (stdio only) */ @@ -1902,7 +1914,7 @@ type InputShared_Type_92 = { timeout?: number | undefined; }; -type InputShared_Type_93 = +type InputShared_Type_94 = | 'llm-judge' | 'answer-relevancy' | 'answer-similarity' @@ -1916,7 +1928,7 @@ type InputShared_Type_93 = | 'tool-call-accuracy' | 'toxicity'; -type InputShared_Type_94 = +type InputShared_Type_95 = | { /** Minimum score value (default: 0) */ min?: number | undefined; @@ -1925,7 +1937,7 @@ type InputShared_Type_94 = } | undefined; -type InputShared_Type_95 = +type InputShared_Type_96 = | { type: 'external'; /** Package path for external source */ @@ -1942,7 +1954,7 @@ type InputShared_Type_95 = mastraPath: string; }; -type InputShared_Type_96 = { +type InputShared_Type_97 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -1967,7 +1979,7 @@ type InputShared_Type_96 = { success?: boolean | undefined; }; -type InputShared_Type_97 = { +type InputShared_Type_98 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -1993,7 +2005,7 @@ type InputShared_Type_97 = { success?: boolean | undefined; }; -type InputShared_Type_98 = { +type InputShared_Type_99 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2011,7 +2023,7 @@ type InputShared_Type_98 = { finishReason?: string | undefined; }; -type InputShared_Type_99 = { +type InputShared_Type_100 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2026,7 +2038,7 @@ type InputShared_Type_99 = { agentId?: string | undefined; }; -type InputShared_Type_100 = { +type InputShared_Type_101 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2047,7 +2059,7 @@ type InputShared_Type_100 = { | undefined; }; -type InputShared_Type_101 = { +type InputShared_Type_102 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2063,7 +2075,7 @@ type InputShared_Type_101 = { status?: string | undefined; }; -type InputShared_Type_102 = { +type InputShared_Type_103 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2079,7 +2091,7 @@ type InputShared_Type_102 = { selectedSteps?: string[] | undefined; }; -type InputShared_Type_103 = { +type InputShared_Type_104 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2095,7 +2107,7 @@ type InputShared_Type_103 = { parallelSteps?: string[] | undefined; }; -type InputShared_Type_104 = { +type InputShared_Type_105 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2111,7 +2123,7 @@ type InputShared_Type_104 = { totalIterations?: number | undefined; }; -type InputShared_Type_105 = { +type InputShared_Type_106 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2127,7 +2139,7 @@ type InputShared_Type_105 = { sleepType?: string | undefined; }; -type InputShared_Type_106 = { +type InputShared_Type_107 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2143,7 +2155,7 @@ type InputShared_Type_106 = { eventReceived?: boolean | undefined; }; -type InputShared_Type_107 = { +type InputShared_Type_108 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2158,8 +2170,7 @@ type InputShared_Type_107 = { processorId?: string | undefined; }; -type InputShared_Type_108 = - | InputShared_Type_96 +type InputShared_Type_109 = | InputShared_Type_97 | InputShared_Type_98 | InputShared_Type_99 @@ -2170,9 +2181,10 @@ type InputShared_Type_108 = | InputShared_Type_104 | InputShared_Type_105 | InputShared_Type_106 - | InputShared_Type_107; + | InputShared_Type_107 + | InputShared_Type_108; -type InputShared_Type_109 = { +type InputShared_Type_110 = { /** Step name to match */ name: string; durationMs?: number | undefined; @@ -2186,9 +2198,9 @@ type InputShared_Type_109 = { stepType?: undefined | undefined; }; -type InputShared_Type_110 = { +type InputShared_Type_111 = { /** Expected steps for accuracy checking */ - steps?: (InputShared_Type_108 | InputShared_Type_109)[] | undefined; + steps?: (InputShared_Type_109 | InputShared_Type_110)[] | undefined; /** How to compare step ordering (default: relaxed) */ ordering?: ('strict' | 'relaxed' | 'unordered') | undefined; /** Whether to allow repeated steps (default: true) */ @@ -2209,7 +2221,7 @@ type InputShared_Type_110 = { maxRetriesPerTool?: number | undefined; }; -type InputShared_Type_111 = { +type InputShared_Type_112 = { /** Name of the tool this mock applies to */ toolName: string; /** Arguments to match against the tool call */ @@ -2222,14 +2234,14 @@ type InputShared_Type_111 = { matchArgs?: ('strict' | 'ignore') | undefined; }; -type InputShared_Type_112 = { +type InputShared_Type_113 = { /** How this item was created */ type: 'csv' | 'json' | 'trace' | 'llm' | 'experiment-result' | 'candidate-screener'; /** Reference identifier (e.g., trace id, csv filename) */ referenceId?: string | undefined; }; -type InputShared_Type_113 = { +type InputShared_Type_114 = { behavior?: ('deliver' | 'persist' | 'discard') | undefined; attributes?: | { @@ -2238,7 +2250,7 @@ type InputShared_Type_113 = { | undefined; }; -type InputShared_Type_114 = { +type InputShared_Type_115 = { behavior?: ('wake' | 'persist' | 'discard') | undefined; attributes?: | { @@ -3897,10 +3909,14 @@ type Shared_Type_69 = { traceQuery: boolean; /** Supports explicit `rootSource: 'aggregated'` trace queries */ traceQueryAggregatedRoots: boolean; - /** Literal substring search across any span in a trace */ - traceQueryTextSearch: boolean; - /** Literal substring search within individual spans */ - spanQueryTextSearch: boolean; + /** Token matching across any span in a trace */ + traceQueryTokenSearch: boolean; + /** Token matching within individual spans */ + spanQueryTokenSearch: boolean; + /** Token predicates in trace aggregates */ + traceAggregateTokenSearch: boolean; + /** Token predicates in span aggregates */ + spanAggregateTokenSearch: boolean; /** `durationMs` predicates in trace and thread queries */ traceQueryRootDuration: boolean; /** `runId`, `sessionId`, `userId` and `organizationId` predicates in trace and thread queries */ @@ -10824,7 +10840,6 @@ export interface GetObservabilityTracesTraceIdSpanIdScores_RouteContract { // ============================================================================ export type PostObservabilityTracesQuery_Body = { rootSource?: ('legacy' | 'aggregated') | undefined; - textSearch?: string | undefined; timeRange: { from: string; to: string; @@ -10922,8 +10937,8 @@ export type PostObservabilityTracesAggregate_Body = { where?: InputShared_Auxiliary_208 | undefined; groupBy?: string[]; interval?: ('1m' | '5m' | '15m' | '1h' | '1d') | undefined; - measures: (InputShared_Type_16 | `countDistinct.${string}`)[]; - having?: InputShared_Auxiliary_231 | undefined; + measures: (InputShared_Type_17 | `countDistinct.${string}`)[]; + having?: InputShared_Auxiliary_236 | undefined; orderBy?: { field: string; direction: 'asc' | 'desc'; @@ -11020,11 +11035,11 @@ export type PostObservabilitySpansAggregate_Body = { from: string; to: string; }; - where?: InputShared_Auxiliary_231 | undefined; + where?: InputShared_Auxiliary_236 | undefined; groupBy?: string[]; interval?: ('1m' | '5m' | '15m' | '1h' | '1d') | undefined; - measures: (InputShared_Type_16 | `countDistinct.${string}`)[]; - having?: InputShared_Auxiliary_231 | undefined; + measures: (InputShared_Type_17 | `countDistinct.${string}`)[]; + having?: InputShared_Auxiliary_236 | undefined; orderBy?: { field: string; direction: 'asc' | 'desc'; @@ -11072,7 +11087,7 @@ export type PostObservabilityThreadsQuery_Body = field: 'startedAt' | 'endedAt'; }; }; - where?: InputShared_Auxiliary_231 | undefined; + where?: InputShared_Auxiliary_236 | undefined; orderBy?: { field: 'startedAt' | 'endedAt'; direction: 'asc' | 'desc'; @@ -11090,7 +11105,7 @@ export type PostObservabilityThreadsQuery_Body = }; where?: InputShared_Auxiliary_208 | undefined; }; - where?: InputShared_Auxiliary_278 | undefined; + where?: InputShared_Auxiliary_283 | undefined; page?: { limit?: number; after?: (string | null) | undefined; @@ -11167,8 +11182,7 @@ export type PostObservabilitySpansQuery_Body = { from: string; to: string; }; - where?: InputShared_Auxiliary_231 | undefined; - textSearch?: string | undefined; + where?: InputShared_Auxiliary_236 | undefined; orderBy?: { field: 'startedAt' | 'endedAt' | 'timeToFirstChunkMs' | 'timeToFirstTokenMs' | 'durationMs' | 'model' | 'provider'; direction: 'asc' | 'desc'; @@ -11912,7 +11926,7 @@ export type PostObservabilityScoresAggregate_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Filters for querying scores */ - filters?: InputShared_Type_17 | undefined; + filters?: InputShared_Type_18 | undefined; /** Comparison period for aggregate queries */ comparePeriod?: ('previous_period' | 'previous_day' | 'previous_week') | undefined; }; @@ -11958,7 +11972,7 @@ export type PostObservabilityScoresBreakdown_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Filters for querying scores */ - filters?: InputShared_Type_17 | undefined; + filters?: InputShared_Type_18 | undefined; }; export type PostObservabilityScoresBreakdown_Response = { @@ -12004,7 +12018,7 @@ export type PostObservabilityScoresTimeseries_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Filters for querying scores */ - filters?: InputShared_Type_17 | undefined; + filters?: InputShared_Type_18 | undefined; /** Fields to group by */ groupBy?: string[] | undefined; }; @@ -12054,7 +12068,7 @@ export type PostObservabilityScoresPercentiles_Body = { /** Time bucket interval */ interval: '1m' | '5m' | '15m' | '1h' | '1d'; /** Filters for querying scores */ - filters?: InputShared_Type_17 | undefined; + filters?: InputShared_Type_18 | undefined; }; export type PostObservabilityScoresPercentiles_Response = { @@ -12509,7 +12523,7 @@ export type PostObservabilityFeedbackAggregate_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Filters for querying feedback */ - filters?: InputShared_Type_18 | undefined; + filters?: InputShared_Type_19 | undefined; /** Comparison period for aggregate queries */ comparePeriod?: ('previous_period' | 'previous_day' | 'previous_week') | undefined; }; @@ -12548,7 +12562,7 @@ export type PostObservabilityFeedbackBreakdown_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Filters for querying feedback */ - filters?: InputShared_Type_18 | undefined; + filters?: InputShared_Type_19 | undefined; }; export type PostObservabilityFeedbackBreakdown_Response = PostObservabilityScoresBreakdown_Response; @@ -12585,7 +12599,7 @@ export type PostObservabilityFeedbackTimeseries_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Filters for querying feedback */ - filters?: InputShared_Type_18 | undefined; + filters?: InputShared_Type_19 | undefined; /** Fields to group by */ groupBy?: string[] | undefined; }; @@ -12635,7 +12649,7 @@ export type PostObservabilityFeedbackPercentiles_Body = { /** Time bucket interval */ interval: '1m' | '5m' | '15m' | '1h' | '1d'; /** Filters for querying feedback */ - filters?: InputShared_Type_18 | undefined; + filters?: InputShared_Type_19 | undefined; }; export type PostObservabilityFeedbackPercentiles_Response = PostObservabilityScoresPercentiles_Response; @@ -12668,9 +12682,9 @@ export type PostObservabilityMetricsAggregate_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Column to apply count_distinct over (required when aggregation is 'count_distinct'). Restricted to allowlisted metric dimensions. */ - distinctColumn?: InputShared_Type_19 | undefined; + distinctColumn?: InputShared_Type_20 | undefined; /** Filters for querying metrics */ - filters?: InputShared_Type_20 | undefined; + filters?: InputShared_Type_21 | undefined; /** Comparison period for aggregate queries */ comparePeriod?: ('previous_period' | 'previous_day' | 'previous_week') | undefined; }; @@ -12722,9 +12736,9 @@ export type PostObservabilityMetricsBreakdown_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Column to apply count_distinct over (required when aggregation is 'count_distinct'). Restricted to allowlisted metric dimensions. */ - distinctColumn?: InputShared_Type_19 | undefined; + distinctColumn?: InputShared_Type_20 | undefined; /** Filters for querying metrics */ - filters?: InputShared_Type_20 | undefined; + filters?: InputShared_Type_21 | undefined; /** Maximum number of groups to return (server-side TopK). Required for high-cardinality groupBy. */ limit?: number | undefined; /** Sort direction for the aggregated value (defaults to 'DESC' at the storage layer; pairs with limit for top/bottom-N). */ @@ -12776,9 +12790,9 @@ export type PostObservabilityMetricsTimeseries_Body = { /** Aggregation function */ aggregation: 'sum' | 'avg' | 'min' | 'max' | 'count' | 'count_distinct' | 'last'; /** Column to apply count_distinct over (required when aggregation is 'count_distinct'). Restricted to allowlisted metric dimensions. */ - distinctColumn?: InputShared_Type_19 | undefined; + distinctColumn?: InputShared_Type_20 | undefined; /** Filters for querying metrics */ - filters?: InputShared_Type_20 | undefined; + filters?: InputShared_Type_21 | undefined; /** Fields to group by */ groupBy?: string[] | undefined; }; @@ -12830,7 +12844,7 @@ export type PostObservabilityMetricsPercentiles_Body = { /** Time bucket interval */ interval: '1m' | '5m' | '15m' | '1h' | '1d'; /** Filters for querying metrics */ - filters?: InputShared_Type_20 | undefined; + filters?: InputShared_Type_21 | undefined; }; export type PostObservabilityMetricsPercentiles_Response = PostObservabilityScoresPercentiles_Response; @@ -13921,13 +13935,13 @@ export type PostA2aAgentId_Body = jsonrpc: '2.0'; id: string | number; method: 'message/send' | 'SendMessage'; - params: InputShared_Type_31; + params: InputShared_Type_32; } | { jsonrpc: '2.0'; id: string | number; method: 'message/stream' | 'SendStreamingMessage'; - params: InputShared_Type_31; + params: InputShared_Type_32; } | { jsonrpc: '2.0'; @@ -13995,7 +14009,7 @@ export type PostA2aAgentId_Body = params: { /** Task id */ taskId: string; - pushNotificationConfig: InputShared_Type_29; + pushNotificationConfig: InputShared_Type_30; }; } | { @@ -14009,7 +14023,7 @@ export type PostA2aAgentId_Body = id?: string | undefined; /** Token unique to this task/session */ token?: string | undefined; - authentication?: InputShared_Type_28 | undefined; + authentication?: InputShared_Type_29 | undefined; /** Task id */ taskId: string; tenant?: string | undefined; @@ -16090,7 +16104,7 @@ export interface GetStoredAgents_RouteContract { // ============================================================================ export type PostStoredAgentsPreviewInstructions_Body = { /** Array of instruction blocks to resolve */ - blocks: InputShared_Type_35[]; + blocks: InputShared_Type_36[]; /** Request context for variable interpolation and rule evaluation */ context?: | { @@ -16167,9 +16181,9 @@ export type PostStoredAgentsStoredAgentIdExport_Body = { /** Description of the agent */ description?: (string | undefined) | undefined; /** System instructions for the agent (string or array of instruction blocks) */ - instructions?: (string | InputShared_Type_35[]) | undefined; + instructions?: (string | InputShared_Type_36[]) | undefined; /** Model configuration — static value or array of conditional variants */ - model?: InputShared_Type_37 | undefined; + model?: InputShared_Type_38 | undefined; /** Ordered model fallback list owned by Studio */ modelList?: | ( @@ -16184,23 +16198,23 @@ export type PostStoredAgentsStoredAgentIdExport_Body = { ) | undefined; /** Tool keys mapped to per-tool config — static or conditional */ - tools?: (InputShared_Type_39 | undefined) | undefined; + tools?: (InputShared_Type_40 | undefined) | undefined; /** Default options for generate/stream calls — static or conditional */ - defaultOptions?: ((InputShared_Type_42 | InputShared_Type_43[]) | undefined) | undefined; + defaultOptions?: ((InputShared_Type_43 | InputShared_Type_44[]) | undefined) | undefined; /** Workflow keys with optional per-workflow config — static or conditional */ - workflows?: (InputShared_Type_39 | undefined) | undefined; + workflows?: (InputShared_Type_40 | undefined) | undefined; /** Agent keys with optional per-agent config — static or conditional */ - agents?: (InputShared_Type_39 | undefined) | undefined; + agents?: (InputShared_Type_40 | undefined) | undefined; /** Map of tool provider IDs to their tool configurations — static or conditional */ integrationTools?: | ( | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined ) @@ -16210,9 +16224,9 @@ export type PostStoredAgentsStoredAgentIdExport_Body = { | ( | ( | { - [key: string]: InputShared_Type_46; + [key: string]: InputShared_Type_47; } - | InputShared_Type_47[] + | InputShared_Type_48[] ) | undefined ) @@ -16223,36 +16237,36 @@ export type PostStoredAgentsStoredAgentIdExport_Body = { | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined ) | undefined; /** Input processor graph — static or conditional */ - inputProcessors?: (InputShared_Type_53 | undefined) | undefined; + inputProcessors?: (InputShared_Type_54 | undefined) | undefined; /** Output processor graph — static or conditional */ - outputProcessors?: (InputShared_Type_53 | undefined) | undefined; + outputProcessors?: (InputShared_Type_54 | undefined) | undefined; /** Memory: registered memory reference or inline config — static, conditional, or null to disable memory */ - memory?: ((InputShared_Type_63 | null) | undefined) | undefined; + memory?: ((InputShared_Type_64 | null) | undefined) | undefined; /** Scorer keys with optional sampling config — static or conditional */ scorers?: | ( | ( | { - [key: string]: InputShared_Type_64; + [key: string]: InputShared_Type_65; } - | InputShared_Type_65[] + | InputShared_Type_66[] ) | undefined ) | undefined; /** Skill IDs mapped to per-skill config — static or conditional */ - skills?: (InputShared_Type_67 | undefined) | undefined; + skills?: (InputShared_Type_68 | undefined) | undefined; /** Workspace reference (stored ID or inline config) — static or conditional */ - workspace?: InputShared_Type_77 | undefined; + workspace?: InputShared_Type_78 | undefined; /** Browser configuration — object config, true (apply default), false/null (disable) */ browser?: | ( @@ -16260,9 +16274,9 @@ export type PostStoredAgentsStoredAgentIdExport_Body = { | ( | { type: 'inline'; - config: InputShared_Type_79; + config: InputShared_Type_80; } - | InputShared_Type_80[] + | InputShared_Type_81[] ) | boolean | null @@ -16334,9 +16348,9 @@ export type PostStoredAgentsStoredAgentIdChangeRequest_Body = { /** Description of the agent */ description?: (string | undefined) | undefined; /** System instructions for the agent (string or array of instruction blocks) */ - instructions?: (string | InputShared_Type_35[]) | undefined; + instructions?: (string | InputShared_Type_36[]) | undefined; /** Model configuration — static value or array of conditional variants */ - model?: InputShared_Type_37 | undefined; + model?: InputShared_Type_38 | undefined; /** Ordered model fallback list owned by Studio */ modelList?: | ( @@ -16351,23 +16365,23 @@ export type PostStoredAgentsStoredAgentIdChangeRequest_Body = { ) | undefined; /** Tool keys mapped to per-tool config — static or conditional */ - tools?: (InputShared_Type_39 | undefined) | undefined; + tools?: (InputShared_Type_40 | undefined) | undefined; /** Default options for generate/stream calls — static or conditional */ - defaultOptions?: ((InputShared_Type_42 | InputShared_Type_43[]) | undefined) | undefined; + defaultOptions?: ((InputShared_Type_43 | InputShared_Type_44[]) | undefined) | undefined; /** Workflow keys with optional per-workflow config — static or conditional */ - workflows?: (InputShared_Type_39 | undefined) | undefined; + workflows?: (InputShared_Type_40 | undefined) | undefined; /** Agent keys with optional per-agent config — static or conditional */ - agents?: (InputShared_Type_39 | undefined) | undefined; + agents?: (InputShared_Type_40 | undefined) | undefined; /** Map of tool provider IDs to their tool configurations — static or conditional */ integrationTools?: | ( | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined ) @@ -16377,9 +16391,9 @@ export type PostStoredAgentsStoredAgentIdChangeRequest_Body = { | ( | ( | { - [key: string]: InputShared_Type_46; + [key: string]: InputShared_Type_47; } - | InputShared_Type_47[] + | InputShared_Type_48[] ) | undefined ) @@ -16390,36 +16404,36 @@ export type PostStoredAgentsStoredAgentIdChangeRequest_Body = { | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined ) | undefined; /** Input processor graph — static or conditional */ - inputProcessors?: (InputShared_Type_53 | undefined) | undefined; + inputProcessors?: (InputShared_Type_54 | undefined) | undefined; /** Output processor graph — static or conditional */ - outputProcessors?: (InputShared_Type_53 | undefined) | undefined; + outputProcessors?: (InputShared_Type_54 | undefined) | undefined; /** Memory: registered memory reference or inline config — static, conditional, or null to disable memory */ - memory?: ((InputShared_Type_63 | null) | undefined) | undefined; + memory?: ((InputShared_Type_64 | null) | undefined) | undefined; /** Scorer keys with optional sampling config — static or conditional */ scorers?: | ( | ( | { - [key: string]: InputShared_Type_64; + [key: string]: InputShared_Type_65; } - | InputShared_Type_65[] + | InputShared_Type_66[] ) | undefined ) | undefined; /** Skill IDs mapped to per-skill config — static or conditional */ - skills?: (InputShared_Type_67 | undefined) | undefined; + skills?: (InputShared_Type_68 | undefined) | undefined; /** Workspace reference (stored ID or inline config) — static or conditional */ - workspace?: InputShared_Type_77 | undefined; + workspace?: InputShared_Type_78 | undefined; /** Browser configuration — object config, true (apply default), false/null (disable) */ browser?: | ( @@ -16427,9 +16441,9 @@ export type PostStoredAgentsStoredAgentIdChangeRequest_Body = { | ( | { type: 'inline'; - config: InputShared_Type_79; + config: InputShared_Type_80; } - | InputShared_Type_80[] + | InputShared_Type_81[] ) | boolean | null @@ -16544,17 +16558,17 @@ export type PostStoredAgents_Body = { /** Description of the agent */ description?: string | undefined; /** System instructions for the agent (string or array of instruction blocks) */ - instructions: string | InputShared_Type_35[]; + instructions: string | InputShared_Type_36[]; /** Model configuration — static value or array of conditional variants. When omitted, the builder default model is applied server-side. */ model?: | ( - | InputShared_Type_36 + | InputShared_Type_37 | { - value: InputShared_Type_36; + value: InputShared_Type_37; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[] @@ -16571,31 +16585,31 @@ export type PostStoredAgents_Body = { }[] | undefined; /** Tool keys mapped to per-tool config — static or conditional */ - tools?: InputShared_Type_39 | undefined; + tools?: InputShared_Type_40 | undefined; /** Default options for generate/stream calls — static or conditional */ - defaultOptions?: (InputShared_Type_42 | InputShared_Type_43[]) | undefined; + defaultOptions?: (InputShared_Type_43 | InputShared_Type_44[]) | undefined; /** Workflow keys with optional per-workflow config — static or conditional */ - workflows?: InputShared_Type_39 | undefined; + workflows?: InputShared_Type_40 | undefined; /** Agent keys with optional per-agent config — static or conditional */ - agents?: InputShared_Type_39 | undefined; + agents?: InputShared_Type_40 | undefined; /** Map of tool provider IDs to their tool configurations — static or conditional */ integrationTools?: | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined; /** Tool provider connections and per-tool config (provider-agnostic). Coexists with the deprecated `integrationTools` field. */ toolProviders?: | ( | { - [key: string]: InputShared_Type_46; + [key: string]: InputShared_Type_47; } - | InputShared_Type_47[] + | InputShared_Type_48[] ) | undefined; /** Map of stored MCP client IDs to their tool configurations — static or conditional */ @@ -16603,26 +16617,26 @@ export type PostStoredAgents_Body = { | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined; /** Input processor graph — static or conditional */ - inputProcessors?: InputShared_Type_53 | undefined; + inputProcessors?: InputShared_Type_54 | undefined; /** Output processor graph — static or conditional */ - outputProcessors?: InputShared_Type_53 | undefined; + outputProcessors?: InputShared_Type_54 | undefined; /** Memory: registered memory reference or inline config — static or conditional */ memory?: | ( - | InputShared_Type_62 + | InputShared_Type_63 | { - value: InputShared_Type_62; + value: InputShared_Type_63; rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; }[] @@ -16632,24 +16646,24 @@ export type PostStoredAgents_Body = { scorers?: | ( | { - [key: string]: InputShared_Type_64; + [key: string]: InputShared_Type_65; } - | InputShared_Type_65[] + | InputShared_Type_66[] ) | undefined; /** Skill IDs mapped to per-skill config — static or conditional */ - skills?: InputShared_Type_67 | undefined; + skills?: InputShared_Type_68 | undefined; /** Workspace reference (stored ID or inline config) — static or conditional */ - workspace?: InputShared_Type_77; + workspace?: InputShared_Type_78; /** Browser configuration — object config, true (apply default), false/null (disable) */ browser?: | ( | ( | { type: 'inline'; - config: InputShared_Type_79; + config: InputShared_Type_80; } - | InputShared_Type_80[] + | InputShared_Type_81[] ) | boolean | null @@ -16717,9 +16731,9 @@ export type PatchStoredAgentsStoredAgentId_Body = { /** Description of the agent */ description?: (string | undefined) | undefined; /** System instructions for the agent (string or array of instruction blocks) */ - instructions?: (string | InputShared_Type_35[]) | undefined; + instructions?: (string | InputShared_Type_36[]) | undefined; /** Model configuration — static value or array of conditional variants */ - model?: InputShared_Type_37 | undefined; + model?: InputShared_Type_38 | undefined; /** Ordered model fallback list owned by Studio */ modelList?: | ( @@ -16734,23 +16748,23 @@ export type PatchStoredAgentsStoredAgentId_Body = { ) | undefined; /** Tool keys mapped to per-tool config — static or conditional */ - tools?: (InputShared_Type_39 | undefined) | undefined; + tools?: (InputShared_Type_40 | undefined) | undefined; /** Default options for generate/stream calls — static or conditional */ - defaultOptions?: ((InputShared_Type_42 | InputShared_Type_43[]) | undefined) | undefined; + defaultOptions?: ((InputShared_Type_43 | InputShared_Type_44[]) | undefined) | undefined; /** Workflow keys with optional per-workflow config — static or conditional */ - workflows?: (InputShared_Type_39 | undefined) | undefined; + workflows?: (InputShared_Type_40 | undefined) | undefined; /** Agent keys with optional per-agent config — static or conditional */ - agents?: (InputShared_Type_39 | undefined) | undefined; + agents?: (InputShared_Type_40 | undefined) | undefined; /** Map of tool provider IDs to their tool configurations — static or conditional */ integrationTools?: | ( | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined ) @@ -16760,9 +16774,9 @@ export type PatchStoredAgentsStoredAgentId_Body = { | ( | ( | { - [key: string]: InputShared_Type_46; + [key: string]: InputShared_Type_47; } - | InputShared_Type_47[] + | InputShared_Type_48[] ) | undefined ) @@ -16773,36 +16787,36 @@ export type PatchStoredAgentsStoredAgentId_Body = { | ( | { [key: string]: { - tools?: InputShared_Type_38 | undefined; + tools?: InputShared_Type_39 | undefined; }; } - | InputShared_Type_44[] + | InputShared_Type_45[] ) | undefined ) | undefined; /** Input processor graph — static or conditional */ - inputProcessors?: (InputShared_Type_53 | undefined) | undefined; + inputProcessors?: (InputShared_Type_54 | undefined) | undefined; /** Output processor graph — static or conditional */ - outputProcessors?: (InputShared_Type_53 | undefined) | undefined; + outputProcessors?: (InputShared_Type_54 | undefined) | undefined; /** Memory: registered memory reference or inline config — static, conditional, or null to disable memory */ - memory?: ((InputShared_Type_63 | null) | undefined) | undefined; + memory?: ((InputShared_Type_64 | null) | undefined) | undefined; /** Scorer keys with optional sampling config — static or conditional */ scorers?: | ( | ( | { - [key: string]: InputShared_Type_64; + [key: string]: InputShared_Type_65; } - | InputShared_Type_65[] + | InputShared_Type_66[] ) | undefined ) | undefined; /** Skill IDs mapped to per-skill config — static or conditional */ - skills?: (InputShared_Type_67 | undefined) | undefined; + skills?: (InputShared_Type_68 | undefined) | undefined; /** Workspace reference (stored ID or inline config) — static or conditional */ - workspace?: InputShared_Type_77 | undefined; + workspace?: InputShared_Type_78 | undefined; /** Browser configuration — object config, true (apply default), false/null (disable) */ browser?: | ( @@ -16810,9 +16824,9 @@ export type PatchStoredAgentsStoredAgentId_Body = { | ( | { type: 'inline'; - config: InputShared_Type_79; + config: InputShared_Type_80; } - | InputShared_Type_80[] + | InputShared_Type_81[] ) | boolean | null @@ -17827,7 +17841,7 @@ export type PostStoredWorkflows_Body = { } | undefined; /** Static workflow graph — ordered array of serialized step entries with all refs as ids. */ - graph: InputShared_Type_91[]; + graph: InputShared_Type_92[]; /** Helper workflow definitions this workflow nests. Saved with it as one unit — the whole set is validated together, hydrated in derived dependency order, and rejected together, so a failed save never leaves orphaned helpers behind. Each helper becomes an ordinary dynamic workflow in its own right. */ dependencies?: | { @@ -17858,7 +17872,7 @@ export type PostStoredWorkflows_Body = { } | undefined; /** Static workflow graph — ordered array of serialized step entries with all refs as ids. */ - graph: InputShared_Type_91[]; + graph: InputShared_Type_92[]; }[] | undefined; }; @@ -18047,7 +18061,7 @@ export type PostStoredMcpClients_Body = { description?: string | undefined; /** Map of server name to server configuration */ servers: { - [key: string]: InputShared_Type_92; + [key: string]: InputShared_Type_93; }; }; @@ -18094,7 +18108,7 @@ export type PatchStoredMcpClientsStoredMCPClientId_Body = { /** Map of server name to server configuration */ servers?: | { - [key: string]: InputShared_Type_92; + [key: string]: InputShared_Type_93; } | undefined; }; @@ -18540,7 +18554,7 @@ export type PostStoredPromptBlocks_Body = { rules?: | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined; /** JSON Schema defining available variables for {{variableName}} interpolation and conditions */ @@ -18595,7 +18609,7 @@ export type PatchStoredPromptBlocksStoredPromptBlockId_Body = { | ( | { operator: 'AND' | 'OR'; - conditions: InputShared_Type_34[]; + conditions: InputShared_Type_35[]; } | undefined ) @@ -19071,13 +19085,13 @@ export type PostStoredScorers_Body = { /** Description of the scorer */ description?: string | undefined; /** Scorer type: llm-judge for custom, or a preset type name */ - type: InputShared_Type_93; + type: InputShared_Type_94; /** Model configuration for LLM judge */ - model?: InputShared_Type_36 | undefined; + model?: InputShared_Type_37 | undefined; /** System instructions for the judge LLM (used when type is llm-judge) */ instructions?: string | undefined; /** Score range configuration (used when type is llm-judge) */ - scoreRange?: InputShared_Type_94; + scoreRange?: InputShared_Type_95; /** Serializable config options for preset scorers */ presetConfig?: | { @@ -19139,13 +19153,13 @@ export type PatchStoredScorersStoredScorerId_Body = { /** Description of the scorer */ description?: (string | undefined) | undefined; /** Scorer type: llm-judge for custom, or a preset type name */ - type?: InputShared_Type_93 | undefined; + type?: InputShared_Type_94 | undefined; /** Model configuration for LLM judge */ - model?: (InputShared_Type_36 | undefined) | undefined; + model?: (InputShared_Type_37 | undefined) | undefined; /** System instructions for the judge LLM (used when type is llm-judge) */ instructions?: (string | undefined) | undefined; /** Score range configuration (used when type is llm-judge) */ - scoreRange?: InputShared_Type_94 | undefined; + scoreRange?: InputShared_Type_95 | undefined; /** Serializable config options for preset scorers */ presetConfig?: | ( @@ -19706,17 +19720,17 @@ export type PostStoredWorkspaces_Body = { /** Description of the workspace */ description?: string | undefined; /** Filesystem configuration */ - filesystem?: InputShared_Type_68; + filesystem?: InputShared_Type_69; /** Sandbox configuration */ - sandbox?: InputShared_Type_69; + sandbox?: InputShared_Type_70; /** Mounted filesystems keyed by mount path */ - mounts?: InputShared_Type_70 | undefined; + mounts?: InputShared_Type_71 | undefined; /** Search configuration */ - search?: InputShared_Type_71 | undefined; + search?: InputShared_Type_72 | undefined; /** Array of skill IDs */ skills?: string[] | undefined; /** Workspace tool configuration */ - tools?: InputShared_Type_73 | undefined; + tools?: InputShared_Type_74 | undefined; /** Whether to automatically sync the workspace */ autoSync?: boolean | undefined; /** Operation timeout in milliseconds */ @@ -19763,17 +19777,17 @@ export type PatchStoredWorkspacesStoredWorkspaceId_Body = { /** Description of the workspace */ description?: (string | undefined) | undefined; /** Filesystem configuration */ - filesystem?: InputShared_Type_68 | undefined; + filesystem?: InputShared_Type_69 | undefined; /** Sandbox configuration */ - sandbox?: InputShared_Type_69 | undefined; + sandbox?: InputShared_Type_70 | undefined; /** Mounted filesystems keyed by mount path */ - mounts?: (InputShared_Type_70 | undefined) | undefined; + mounts?: (InputShared_Type_71 | undefined) | undefined; /** Search configuration */ - search?: (InputShared_Type_71 | undefined) | undefined; + search?: (InputShared_Type_72 | undefined) | undefined; /** Array of skill IDs */ skills?: (string[] | undefined) | undefined; /** Workspace tool configuration */ - tools?: (InputShared_Type_73 | undefined) | undefined; + tools?: (InputShared_Type_74 | undefined) | undefined; /** Whether to automatically sync the workspace */ autoSync?: (boolean | undefined) | undefined; /** Operation timeout in milliseconds */ @@ -19944,7 +19958,7 @@ export type PostStoredSkills_Body = { /** Compatibility requirements */ compatibility?: unknown | undefined; /** Source location of the skill */ - source?: InputShared_Type_95 | undefined; + source?: InputShared_Type_96 | undefined; /** List of reference file paths */ references?: string[] | undefined; /** List of script file paths */ @@ -19952,7 +19966,7 @@ export type PostStoredSkills_Body = { /** List of asset file paths */ assets?: string[] | undefined; /** Full file tree structure for the skill */ - files?: InputShared_Auxiliary_809[] | undefined; + files?: InputShared_Auxiliary_814[] | undefined; /** Additional metadata for the skill */ metadata?: | { @@ -20002,7 +20016,7 @@ export type PatchStoredSkillsStoredSkillId_Body = { /** Compatibility requirements */ compatibility?: (unknown | undefined) | undefined; /** Source location of the skill */ - source?: (InputShared_Type_95 | undefined) | undefined; + source?: (InputShared_Type_96 | undefined) | undefined; /** List of reference file paths */ references?: (string[] | undefined) | undefined; /** List of script file paths */ @@ -20010,7 +20024,7 @@ export type PatchStoredSkillsStoredSkillId_Body = { /** List of asset file paths */ assets?: (string[] | undefined) | undefined; /** Full file tree structure for the skill */ - files?: (InputShared_Auxiliary_809[] | undefined) | undefined; + files?: (InputShared_Auxiliary_814[] | undefined) | undefined; /** Additional metadata for the skill */ metadata?: | ( @@ -21188,9 +21202,9 @@ export type PostDatasetsDatasetIdItems_Body = { /** Expected output for comparison */ groundTruth?: unknown | undefined; /** Expected trajectory configuration for trajectory scoring */ - expectedTrajectory?: (InputShared_Type_110 | undefined) | null; + expectedTrajectory?: (InputShared_Type_111 | undefined) | null; /** Ordered item-level static tool mocks served in place of executing the real tool */ - toolMocks?: InputShared_Type_111[] | undefined; + toolMocks?: InputShared_Type_112[] | undefined; /** Policy for undeclared tool calls. 'allow' runs them live; 'deny' fails the experiment item */ unmockedToolPolicy?: ('allow' | 'deny') | undefined; /** IDs of scorers selected for this item */ @@ -21208,7 +21222,7 @@ export type PostDatasetsDatasetIdItems_Body = { } | undefined; /** Source/provenance of this dataset item */ - source?: InputShared_Type_112 | undefined; + source?: InputShared_Type_113 | undefined; }; export type PostDatasetsDatasetIdItems_Response = Shared_Type_92; @@ -21243,9 +21257,9 @@ export type PostDatasetsDatasetIdItemsBatch_Body = { input: unknown; groundTruth?: unknown | undefined; /** Expected trajectory configuration for trajectory scoring */ - expectedTrajectory?: (InputShared_Type_110 | undefined) | null; + expectedTrajectory?: (InputShared_Type_111 | undefined) | null; /** Ordered item-level static tool mocks served in place of executing the real tool */ - toolMocks?: InputShared_Type_111[] | undefined; + toolMocks?: InputShared_Type_112[] | undefined; /** Policy for undeclared tool calls. 'allow' runs them live; 'deny' fails the experiment item */ unmockedToolPolicy?: ('allow' | 'deny') | undefined; scorerIds?: string[] | undefined; @@ -21260,7 +21274,7 @@ export type PostDatasetsDatasetIdItemsBatch_Body = { } | undefined; /** Source/provenance of this dataset item */ - source?: InputShared_Type_112 | undefined; + source?: InputShared_Type_113 | undefined; }[]; }; @@ -21365,9 +21379,9 @@ export type PatchDatasetsDatasetIdItemsItemId_Body = { /** Expected output for comparison */ groundTruth?: unknown | undefined; /** Expected trajectory configuration for trajectory scoring */ - expectedTrajectory?: (InputShared_Type_110 | undefined) | null; + expectedTrajectory?: (InputShared_Type_111 | undefined) | null; /** Ordered item-level static tool mocks served in place of executing the real tool */ - toolMocks?: InputShared_Type_111[] | undefined; + toolMocks?: InputShared_Type_112[] | undefined; /** Policy for undeclared tool calls. 'allow' runs them live; 'deny' fails the experiment item */ unmockedToolPolicy?: ('allow' | 'deny') | undefined; /** IDs of scorers selected for this item */ @@ -21385,7 +21399,7 @@ export type PatchDatasetsDatasetIdItemsItemId_Body = { } | undefined; /** Source/provenance of this dataset item */ - source?: InputShared_Type_112 | undefined; + source?: InputShared_Type_113 | undefined; }; export type PatchDatasetsDatasetIdItemsItemId_Response = PostDatasetsDatasetIdItems_Response; @@ -23584,8 +23598,8 @@ export type PostSchedules_Body = [key: string]: (string | number | boolean | null) | undefined; } | undefined; - ifActive?: InputShared_Type_113 | undefined; - ifIdle?: InputShared_Type_114 | undefined; + ifActive?: InputShared_Type_114 | undefined; + ifIdle?: InputShared_Type_115 | undefined; providerOptions?: | { [key: string]: unknown; @@ -23665,8 +23679,8 @@ export type PatchSchedulesScheduleId_Body = { [key: string]: (string | number | boolean | null) | undefined; } | undefined; - ifActive?: InputShared_Type_113 | undefined; - ifIdle?: InputShared_Type_114 | undefined; + ifActive?: InputShared_Type_114 | undefined; + ifIdle?: InputShared_Type_115 | undefined; providerOptions?: | { [key: string]: unknown; diff --git a/docs/src/content/en/reference/server/builtin-mcp-tools.mdx b/docs/src/content/en/reference/server/builtin-mcp-tools.mdx index 42e743433cd..9fe58e98f1b 100644 --- a/docs/src/content/en/reference/server/builtin-mcp-tools.mdx +++ b/docs/src/content/en/reference/server/builtin-mcp-tools.mdx @@ -84,9 +84,9 @@ A `tool_` entry uses the tool's own `mcp.annotations` when the tool defines | Tool | Arguments | Route | Permission | | - | - | - | - | -| `query_traces` | `timeRange*`, `where`, `textSearch`, `rootSource`, `group`, `orderBy`, `page` | `POST /observability/traces/query` | `observability:read` | +| `query_traces` | `timeRange*`, `where`, `rootSource`, `group`, `orderBy`, `page` | `POST /observability/traces/query` | `observability:read` | | `aggregate_traces` | `timeRange*`, `measures*`, `where`, `groupBy`, `interval`, `having`, `orderBy`, `limit` | `POST /observability/traces/aggregate` | `observability:read` | -| `query_spans` | `timeRange*`, `where`, `textSearch`, `orderBy`, `page` | `POST /observability/spans/query` | `observability:read` | +| `query_spans` | `timeRange*`, `where`, `orderBy`, `page` | `POST /observability/spans/query` | `observability:read` | | `aggregate_spans` | `timeRange*`, `measures*`, `where`, `groupBy`, `interval`, `having`, `orderBy`, `limit` | `POST /observability/spans/aggregate` | `observability:read` | | `query_threads` | `timeRange*`, `where`, `orderBy`, `page` | `POST /observability/threads/query` | `observability:read` | | `get_trace_query_fields` | `timeRange*`, `predicateScope*`, `search`, `limit` | `POST /observability/traces/query/fields` | `observability:read` | diff --git a/packages/cli/src/commands/api/route-metadata.generated.ts b/packages/cli/src/commands/api/route-metadata.generated.ts index 691420ba038..cee3b52975a 100644 --- a/packages/cli/src/commands/api/route-metadata.generated.ts +++ b/packages/cli/src/commands/api/route-metadata.generated.ts @@ -2115,7 +2115,6 @@ export const API_ROUTE_METADATA = { "page", "pagination", "rootSource", - "textSearch", "timeRange", "where" ], @@ -2197,7 +2196,6 @@ export const API_ROUTE_METADATA = { "bodyParams": [ "orderBy", "page", - "textSearch", "timeRange", "where" ], diff --git a/packages/core/src/storage/domains/observability/base.ts b/packages/core/src/storage/domains/observability/base.ts index 5b30413b9ca..d47990799b5 100644 --- a/packages/core/src/storage/domains/observability/base.ts +++ b/packages/core/src/storage/domains/observability/base.ts @@ -121,9 +121,11 @@ import type { ObservabilityStorageStrategy, TracingStorageStrategy } from './typ * - `span-query-duration-sort`: ordering completed spans by `durationMs` * - `span-query-model-provider-sort`: ordering completed spans by their model/provider columns * - `span-query-context-fields`: identity, context and parent/root entity predicates added to `querySpans` - * - `span-query-text-search`: literal substring search in `querySpans` - * - `trace-query-text-search`: literal substring search across any span in `queryTraces` + * - `span-query-token-search`: token matching in `querySpans` + * - `trace-query-token-search`: token matching across any span in `queryTraces` * - `span-query-model-fields`: `model` and `provider` predicates in `querySpans` and `aggregateSpans` + * - `trace-aggregate-token-search`: token matching across any span in `aggregateTraces` + * - `span-aggregate-token-search`: token matching in `aggregateSpans` * - `span-aggregate`: `aggregateSpans`, including every `querySpans` predicate field * - `span-aggregate-model-dimensions`: `model` and `provider` in `aggregateSpans` `groupBy` and `countDistinct` * - `trace-query`: `queryTraces` @@ -164,8 +166,10 @@ export type ObservabilityStorageFeature = | 'span-query-duration-sort' | 'span-query-model-provider-sort' | 'span-query-context-fields' - | 'span-query-text-search' - | 'trace-query-text-search' + | 'span-query-token-search' + | 'trace-query-token-search' + | 'trace-aggregate-token-search' + | 'span-aggregate-token-search' | 'span-query-model-fields' | 'span-aggregate' | 'span-aggregate-model-dimensions' diff --git a/packages/core/src/storage/domains/observability/index.ts b/packages/core/src/storage/domains/observability/index.ts index b091416bcf5..07aa374965d 100644 --- a/packages/core/src/storage/domains/observability/index.ts +++ b/packages/core/src/storage/domains/observability/index.ts @@ -1,5 +1,4 @@ export * from './base'; -export * from './text-search'; export * from './discovery'; export * from './feedback'; export * from './inmemory'; @@ -67,6 +66,7 @@ export { TraceQueryCursorError, TraceQueryExecutionError, TraceQueryResourceLimitError, + TraceQueryUnsupportedError, resolveTraceQueryTimeoutMs, findPredicateComplexityIssue, isTraceQueryMetadataPath, @@ -165,3 +165,6 @@ export * from './tracing'; export * from './types'; export * from './span-query'; export * from './thread-query'; + +export { TRACE_QUERY_TOKEN_FIELDS, hasTraceQueryTokenPredicate } from './trace-query'; +export type { TraceQueryTokenField } from './trace-query'; diff --git a/packages/core/src/storage/domains/observability/span-aggregate.ts b/packages/core/src/storage/domains/observability/span-aggregate.ts index 3e400df9187..992b6ef4696 100644 --- a/packages/core/src/storage/domains/observability/span-aggregate.ts +++ b/packages/core/src/storage/domains/observability/span-aggregate.ts @@ -241,14 +241,21 @@ export interface TrustedSpanAggregatePlan { */ export function planSpanAggregate( input: unknown, - options: Pick = {}, + options: Pick = {}, ): TrustedSpanAggregatePlan { const request = parseSpanAggregateRequest(input); const issues: TraceQueryIssue[] = []; - const where = request.where ? planSpanQuerySelectionPredicate(request.where, issues) : undefined; + const where = request.where + ? planSpanQuerySelectionPredicate(request.where, issues, options.allowTokenSearch) + : undefined; const plan = planAggregateGroups(request, issues, { isDimension: isSpanAggregateDimension, parseMeasure: parseSpanAggregateMeasure, }); - return { result: 'spanAggregate', ...plan, where, scope: normalizeTraceQueryTenantScope(options.scope) }; + return { + result: 'spanAggregate', + ...plan, + where, + scope: normalizeTraceQueryTenantScope(options.scope), + }; } diff --git a/packages/core/src/storage/domains/observability/span-query.test.ts b/packages/core/src/storage/domains/observability/span-query.test.ts index a7f544ae3f8..096a9d7e1f0 100644 --- a/packages/core/src/storage/domains/observability/span-query.test.ts +++ b/packages/core/src/storage/domains/observability/span-query.test.ts @@ -515,39 +515,6 @@ describe('bounded result contract', () => { }); }); -describe('span text search', () => { - it('normalizes case and outer whitespace without interpreting punctuation or inner spaces', () => { - expect(planSpanQuery({ timeRange, textSearch: ' Error 50%_\\path ', where })).toMatchObject({ - textSearch: 'error 50%_\\path', - where: planSpanQuery({ timeRange, where }).where, - }); - }); - - it.each(['', ' ', 'ab', '😀😀', 'x'.repeat(257), null, 123])('rejects invalid search input: %j', textSearch => { - expect(() => parseSpanQueryRequest({ timeRange, textSearch })).toThrow(); - }); - - it.each(['abc', '😀😀😀', 'x'.repeat(256)])('accepts bounded search input', textSearch => { - expect(parseSpanQueryRequest({ timeRange, textSearch }).textSearch).toBe(textSearch); - }); - - it('binds pagination to search while allowing equivalent case and whitespace', () => { - const plan = planSpanQuery({ timeRange, textSearch: ' ERROR ' }); - const after = encodeSpanQueryCursor(plan, values); - expect(planSpanQuery({ timeRange, textSearch: 'error', page: { after, limit: 5 } }).cursor).toEqual({ - ...values, - sortValue: '2026-10-01T12:00:00.000Z', - }); - for (const textSearch of ['timeout', undefined]) { - expect(() => planSpanQuery({ timeRange, textSearch, page: { after } })).toThrow(TraceQueryCursorError); - } - const noSearchCursor = encodeSpanQueryCursor(planSpanQuery({ timeRange }), values); - expect(() => planSpanQuery({ timeRange, textSearch: 'error', page: { after: noSearchCursor } })).toThrow( - TraceQueryCursorError, - ); - }); -}); - describe.each(['model', 'provider'] as const)('span %s ordering', field => { const request = { timeRange, orderBy: [{ field, direction: 'asc' as const }] }; const options = { allowSpanModelProviderOrdering: true, scope }; diff --git a/packages/core/src/storage/domains/observability/span-query.ts b/packages/core/src/storage/domains/observability/span-query.ts index 9c49cd4bdf3..db0ea3a0f2c 100644 --- a/packages/core/src/storage/domains/observability/span-query.ts +++ b/packages/core/src/storage/domains/observability/span-query.ts @@ -6,7 +6,6 @@ * define its version rule; endedAt alone is not a general-purpose revision number. */ import { z } from 'zod/v4'; -import { observabilityTextSearchSchema } from './text-search'; import { findPredicateComplexityIssue, formatTraceQuerySchemaIssues, @@ -53,7 +52,6 @@ const requestSchema = z .object({ timeRange: timeRangeSchema, where: traceQueryScalarPredicateSchema.optional(), - textSearch: observabilityTextSearchSchema.optional(), orderBy: z .array(z.object({ field: z.enum(SPAN_QUERY_ORDER_FIELDS), direction: z.enum(['asc', 'desc']) }).strict()) .length(1) @@ -240,7 +238,6 @@ export interface TrustedSpanQueryPlan { result: 'spans'; timeRange: { from: string; to: string }; where?: TrustedTraceQueryScalarPredicate; - textSearch?: string; scope?: TraceQueryPlanOptions['scope']; orderBy: NormalizedSpanQueryRequest['orderBy'][number]; limit: number; @@ -275,7 +272,9 @@ export function planSpanQuery(input: unknown, options: SpanQueryPlanOptions = {} message: 'Span model/provider ordering requires a supporting host and store', }); } - const where = request.where ? planSpanQuerySelectionPredicate(request.where, issues) : undefined; + const where = request.where + ? planSpanQuerySelectionPredicate(request.where, issues, options.allowTokenSearch) + : undefined; if (issues.length) throw new TraceQueryValidationError(issues); const scope = normalizeTraceQueryTenantScope(options.scope); const timeRange = { @@ -286,7 +285,6 @@ export function planSpanQuery(input: unknown, options: SpanQueryPlanOptions = {} // Page size may change without invalidating a cursor. const binding = digestBinding({ version: 1, - textSearch: request.textSearch, result: 'spans', timeRange, where, @@ -326,7 +324,6 @@ export function planSpanQuery(input: unknown, options: SpanQueryPlanOptions = {} } return { result: 'spans', - textSearch: request.textSearch, timeRange, where, scope, diff --git a/packages/core/src/storage/domains/observability/text-search.ts b/packages/core/src/storage/domains/observability/text-search.ts deleted file mode 100644 index 51d1e67b5cc..00000000000 --- a/packages/core/src/storage/domains/observability/text-search.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { z } from 'zod/v4'; - -export const OBSERVABILITY_TEXT_SEARCH_MAX_LENGTH = 256; - -/** - * Case-insensitive literal substring search. Omit the field to disable search; - * empty input is invalid. Whitespace inside the term and punctuation are literal. - * Length is measured in Unicode code points after case normalization. - */ -export const observabilityTextSearchSchema = z - .string() - .trim() - .toLowerCase() - .refine(value => Array.from(value).length >= 3, 'Text search requires at least 3 characters') - .refine( - value => Array.from(value).length <= OBSERVABILITY_TEXT_SEARCH_MAX_LENGTH, - `Text search must contain at most ${OBSERVABILITY_TEXT_SEARCH_MAX_LENGTH} characters`, - ); diff --git a/packages/core/src/storage/domains/observability/token-predicates.test.ts b/packages/core/src/storage/domains/observability/token-predicates.test.ts new file mode 100644 index 00000000000..acedac582d3 --- /dev/null +++ b/packages/core/src/storage/domains/observability/token-predicates.test.ts @@ -0,0 +1,221 @@ +import { describe, expect, it } from 'vitest'; +import { planSpanAggregate } from './span-aggregate'; +import { planSpanQuery, encodeSpanQueryCursor } from './span-query'; +import { parseTraceAggregateRequest } from './trace-aggregate'; +import { planTraceAggregate } from './trace-aggregate-planner'; +import { + parseQueryThreadsInput, + parseTraceQueryRequest, + TraceQueryCursorError, + TRACE_QUERY_TOKEN_FIELDS, +} from './trace-query'; +import { planThreadQuery, planTraceQuery } from './trace-query-plan'; + +const issue = (code: string, path: Array) => + expect.objectContaining({ issues: expect.arrayContaining([expect.objectContaining({ code, path })]) }); + +const options = { allowTokenSearch: true }; +const timeRange = { from: '2026-11-01T00:00:00Z', to: '2026-11-08T00:00:00Z' }; +const token = (path: string, literal: unknown) => ({ op: 'hasAllTokens', left: { path }, right: { literal } }); +const conjunction = { op: 'and', args: [token('input', 'tacos'), token('output', 'nachos')] }; +const cases = [ + ['spans', (where: unknown, extra = {}) => planSpanQuery({ timeRange, where, ...extra }, options), false], + [ + 'span aggregates', + (where: unknown, extra = {}) => planSpanAggregate({ timeRange, where, measures: ['count'], ...extra }, options), + false, + ], + [ + 'traces', + (where: unknown, extra = {}) => planTraceQuery(parseTraceQueryRequest({ timeRange, where, ...extra }), options), + true, + ], + [ + 'trace aggregates', + (where: unknown, extra = {}) => + planTraceAggregate(parseTraceAggregateRequest({ timeRange, where, measures: ['count'], ...extra }), options), + true, + ], +] as const; + +describe.each(cases)('%s token predicates', (_, plan, related) => { + const wrap = (predicate: unknown) => (related ? { spans: { some: predicate } } : predicate); + it.each([ + ['direct NOT', { op: 'not', arg: token('input', 'tacos') }], + ['NOT around AND', { op: 'not', arg: conjunction }], + ['double NOT', { op: 'not', arg: { op: 'not', arg: token('input', 'tacos') } }], + ['NOT under OR', { op: 'or', args: [token('output', 'nachos'), { op: 'not', arg: token('input', 'tacos') }] }], + ])('rejects token search beneath %s', (_, predicate) => { + expect(() => plan(wrap(predicate))).toThrow( + expect.objectContaining({ + issues: expect.arrayContaining([ + expect.objectContaining({ + code: 'operator_not_allowed', + message: 'Token search is not supported beneath not or none', + }), + ]), + }), + ); + }); + if (related) { + it.each([ + ['spans.none', { spans: { none: conjunction } }], + ['NOT around spans.some', { op: 'not', arg: { spans: { some: conjunction } } }], + ['NOT inside spans.none', { spans: { none: { op: 'not', arg: token('input', 'tacos') } } }], + ])('rejects token search beneath %s', (_, predicate) => { + expect(() => plan(predicate)).toThrow( + expect.objectContaining({ + issues: expect.arrayContaining([ + expect.objectContaining({ + code: 'operator_not_allowed', + message: 'Token search is not supported beneath not or none', + }), + ]), + }), + ); + }); + } + it('allows a positive search alongside an ordinary negative filter', () => { + const result = plan( + wrap({ + op: 'and', + args: [ + token('input', 'tacos'), + { op: 'not', arg: { op: 'eq', left: { path: 'name' }, right: { literal: 'ignored' } } }, + ], + }), + ); + expect(result.where).toMatchObject( + related + ? { type: 'relation', quantifier: 'some', predicate: { type: 'boolean', operator: 'and' } } + : { type: 'boolean', operator: 'and' }, + ); + }); + it.each(['first', 'last'])('enforces the literal budget with the token predicate %s', position => { + const memberships = Array.from({ length: 10 }, (_, index) => ({ + op: 'in', + value: { path: 'name' }, + set: Array.from({ length: index === 9 ? 99 : 100 }, (_, value) => `span-${value}`), + })); + const search = token('input', 'tacos'); + const where = () => + wrap({ op: 'and', args: position === 'first' ? [search, ...memberships] : [...memberships, search] }); + + expect(() => plan(where())).not.toThrow(); + memberships[9]!.set.push('span-99'); + expect(() => plan(where())).toThrow( + expect.objectContaining({ + issues: expect.arrayContaining([ + expect.objectContaining({ message: 'Trace queries are limited to 1000 literal units' }), + ]), + }), + ); + }); + it('preserves same-span conjunctions and selected fields', () => { + const result = plan(wrap(conjunction)); + const expected = { + type: 'boolean', + operator: 'and', + args: [ + { type: 'tokens', field: 'input', operator: 'hasAllTokens', value: 'tacos' }, + { type: 'tokens', field: 'output', operator: 'hasAllTokens', value: 'nachos' }, + ], + }; + expect(result.where).toEqual( + related ? { type: 'relation', collection: 'spans', quantifier: 'some', predicate: expected } : expected, + ); + }); + it.each(TRACE_QUERY_TOKEN_FIELDS)('supports %s without changing token case or punctuation', field => { + const result = plan(wrap(token(field, ' foo-Bar 😀 '))); + const expected = { type: 'tokens', field, operator: 'hasAllTokens', value: 'foo-Bar 😀' }; + expect(result.where).toEqual( + related ? { type: 'relation', collection: 'spans', quantifier: 'some', predicate: expected } : expected, + ); + }); + it.each(['attributes', 'requestContext', 'name', 'all); DROP TABLE spans'])('rejects nonindexed field %s', field => { + expect(() => plan(wrap(token(field, 'tacos')))).toThrow(issue('invalid_request', ['where'])); + }); + it.each(['', ' ', 'x'.repeat(257), null, 12])('rejects invalid search value %j', value => { + expect(() => plan(wrap(token('input', value)))).toThrow( + issue( + 'invalid_request', + typeof value === 'string' + ? [...(related ? ['where', 'spans', 'some'] : ['where']), 'right', 'literal'] + : ['where'], + ), + ); + }); + it('counts Unicode code points for the token value limit', () => { + expect(() => plan(wrap(token('input', '😀'.repeat(256))))).not.toThrow(); + expect(() => plan(wrap(token('input', '😀'.repeat(257))))).toThrow( + issue('invalid_request', [...(related ? ['where', 'spans', 'some'] : ['where']), 'right', 'literal']), + ); + }); + it('rejects the removed top-level textSearch field', () => { + expect(() => plan(undefined, { textSearch: 'tacos' })).toThrow(issue('invalid_request', [])); + }); +}); + +it('binds span cursors to token fields and values', () => { + const plan = planSpanQuery({ timeRange, where: token('input', 'tacos') }, options); + const after = encodeSpanQueryCursor(plan, { + organizationId: null, + resourceId: null, + traceId: 'trace', + spanId: 'span', + sortValue: '2026-11-02T00:00:00Z', + }); + for (const where of [token('output', 'tacos'), token('input', 'nachos'), undefined]) { + expect(() => planSpanQuery({ timeRange, where, page: { after } }, options)).toThrow(TraceQueryCursorError); + } +}); +it('rejects trace root, feedback, score, and delta token predicates', () => { + for (const [where, path] of [ + [token('input', 'tacos'), ['where']], + [{ feedback: { some: token('input', 'tacos') } }, ['where', 'feedback', 'some']], + [{ scores: { some: token('input', 'tacos') } }, ['where', 'scores', 'some']], + ] as const) { + expect(() => planTraceQuery(parseTraceQueryRequest({ timeRange, where }), options)).toThrow( + issue('field_not_allowed', [...path]), + ); + } + expect(() => + planTraceQuery( + parseTraceQueryRequest({ timeRange, mode: 'delta', where: { spans: { some: token('all', 'tacos') } } }), + options, + ), + ).toThrow(issue('invalid_request', ['where'])); +}); + +it('rejects token predicates when an older host has not opted in', () => { + const where = token('all', 'tacos'); + const traceWhere = { spans: { some: where } }; + expect(() => planSpanQuery({ timeRange, where })).toThrow(issue('operator_not_allowed', ['where', 'op'])); + expect(() => planSpanAggregate({ timeRange, where, measures: ['count'] })).toThrow( + issue('operator_not_allowed', ['where', 'op']), + ); + expect(() => planTraceQuery(parseTraceQueryRequest({ timeRange, where: traceWhere }))).toThrow( + issue('operator_not_allowed', ['where', 'spans', 'some', 'op']), + ); + expect(() => + planTraceAggregate(parseTraceAggregateRequest({ timeRange, where: traceWhere, measures: ['count'] })), + ).toThrow(issue('operator_not_allowed', ['where', 'spans', 'some', 'op'])); +}); + +it.each(['selection', 'related trace'])('explains that thread queries cannot use token search in %s', location => { + const where = { spans: { some: token('input', 'tacos') } }; + const request = + location === 'selection' + ? { traces: { timeRange, where } } + : { traces: { timeRange }, where: { traces: { some: where } } }; + expect(() => planThreadQuery(parseQueryThreadsInput(request), options)).toThrow( + expect.objectContaining({ + issues: expect.arrayContaining([ + expect.objectContaining({ + code: 'operator_not_allowed', + message: 'Token search is not supported in thread queries', + }), + ]), + }), + ); +}); diff --git a/packages/core/src/storage/domains/observability/trace-aggregate-planner.ts b/packages/core/src/storage/domains/observability/trace-aggregate-planner.ts index 22c7b1a06c8..283bb1fff38 100644 --- a/packages/core/src/storage/domains/observability/trace-aggregate-planner.ts +++ b/packages/core/src/storage/domains/observability/trace-aggregate-planner.ts @@ -213,15 +213,22 @@ interface HavingState { */ export function planTraceAggregate( request: NormalizedTraceAggregateRequest, - options: Pick = {}, + options: Pick = {}, ): TrustedTraceAggregatePlan { const issues: TraceQueryIssue[] = []; - const where = request.where ? planTraceQuerySelectionPredicate(request.where, issues) : undefined; + const where = request.where + ? planTraceQuerySelectionPredicate(request.where, issues, ['where'], options.allowTokenSearch) + : undefined; const plan = planAggregateGroups(request, issues, { isDimension: isTraceAggregateDimension, parseMeasure: parseTraceAggregateMeasure, }); - return { result: 'aggregate', ...plan, where, scope: normalizeTraceQueryTenantScope(options.scope) }; + return { + result: 'aggregate', + ...plan, + where, + scope: normalizeTraceQueryTenantScope(options.scope), + }; } /** @internal The parts of an aggregate request that trace and span scopes share. */ diff --git a/packages/core/src/storage/domains/observability/trace-aggregate.test.ts b/packages/core/src/storage/domains/observability/trace-aggregate.test.ts index 677ce4db17e..3e8a954ed1c 100644 --- a/packages/core/src/storage/domains/observability/trace-aggregate.test.ts +++ b/packages/core/src/storage/domains/observability/trace-aggregate.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; +import { planSpanAggregate } from './span-aggregate'; import { getTraceAggregateCountDistinctField, isTraceAggregateCountDistinctMeasure, @@ -9,6 +10,7 @@ import { TRACE_AGGREGATE_MAX_LIMIT, traceAggregateResponseSchema, } from './trace-aggregate'; +import { planTraceAggregate } from './trace-aggregate-planner'; import { TRACE_QUERY_MAX_NODES, TRACE_QUERY_MAX_PATH_BYTES, TraceQueryValidationError } from './trace-query'; import type { TraceQueryScalarPredicate } from './trace-query'; diff --git a/packages/core/src/storage/domains/observability/trace-query-plan.ts b/packages/core/src/storage/domains/observability/trace-query-plan.ts index 93b7c878353..117b0fcf2db 100644 --- a/packages/core/src/storage/domains/observability/trace-query-plan.ts +++ b/packages/core/src/storage/domains/observability/trace-query-plan.ts @@ -5,6 +5,7 @@ import { z } from 'zod/v4'; import { defaultDeltaLimit } from '../shared'; import { compareTraceQueryStrings, + hasTraceQueryTokenPredicate, isTraceQuerySortValueFor, normalizeTraceQueryTenantScope, planPredicate, @@ -60,7 +61,13 @@ export function planTraceQuery( message: 'Grouped trace queries use fixed threadId ordering', }); } - const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues }; + const state: PlannerState = { + nodes: 0, + relatedClauses: 0, + literalUnits: 0, + issues, + allowTokenSearch: options.allowTokenSearch, + }; const where = request.where ? planPredicate(request.where, 'trace', ['where'], 1, state) : undefined; if (rootSource && where && hasMetadataPredicate(where)) { issues.push({ @@ -69,6 +76,9 @@ export function planTraceQuery( message: 'Aggregated roots do not support metadata predicates', }); } + if (request.mode === 'delta' && hasTraceQueryTokenPredicate(where)) { + issues.push({ code: 'invalid_request', path: ['where'], message: 'Token search is not supported in delta mode' }); + } if (issues.length > 0) throw new TraceQueryValidationError(issues); const timeRange = { from: from.toISOString(), to: to.toISOString() }; @@ -79,7 +89,6 @@ export function planTraceQuery( const orderBy = { field: 'threadId', direction: 'asc' } as const; const binding = digestBinding({ rootSource, - textSearch: request.textSearch, timeRange, where, result, @@ -92,7 +101,6 @@ export function planTraceQuery( return { result, rootSource, - textSearch: request.textSearch, timeRange, where, scope, @@ -108,7 +116,6 @@ export function planTraceQuery( const orderBy = request.orderBy?.[0] ?? ({ field: 'startedAt', direction: 'desc' } as const); const deltaBinding = digestBinding({ rootSource, - textSearch: request.textSearch, timeRange, where, result: 'trace-delta', @@ -119,7 +126,6 @@ export function planTraceQuery( return { result, rootSource, - textSearch: request.textSearch, timeRange, where, scope, @@ -134,7 +140,6 @@ export function planTraceQuery( return { result, rootSource, - textSearch: request.textSearch, timeRange, where, scope, @@ -149,7 +154,6 @@ export function planTraceQuery( const page = request.page ?? { limit: 100 }; const binding = digestBinding({ rootSource, - textSearch: request.textSearch, timeRange, where, result, @@ -164,7 +168,6 @@ export function planTraceQuery( return { result, rootSource, - textSearch: request.textSearch, timeRange, where, scope, @@ -197,7 +200,7 @@ export function planThreadQuery( }); } - const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues }; + const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues, isThreadQuery: true }; const traceWhere = request.traces.where ? planPredicate(request.traces.where, 'trace', ['traces', 'where'], 1, state) : undefined; @@ -337,6 +340,7 @@ function stableStringify(value: unknown): string { } function hasMetadataPredicate(predicate: TrustedTraceQueryPredicate): boolean { + if (predicate.type === 'tokens') return false; if (predicate.type === 'boolean') return predicate.args.some(hasMetadataPredicate); if (predicate.type === 'not') return hasMetadataPredicate(predicate.arg); if (predicate.type === 'relation') return hasMetadataPredicate(predicate.predicate); diff --git a/packages/core/src/storage/domains/observability/trace-query.test.ts b/packages/core/src/storage/domains/observability/trace-query.test.ts index d43b69eb319..66541e4fa2e 100644 --- a/packages/core/src/storage/domains/observability/trace-query.test.ts +++ b/packages/core/src/storage/domains/observability/trace-query.test.ts @@ -2256,44 +2256,6 @@ describe('trace-query responses and storage capability', () => { }); }); -describe('trace text search', () => { - it.each(['', ' ', 'ab', '😀😀', 'x'.repeat(257), null, 123])('rejects invalid search input: %j', textSearch => { - expect(() => parsed({ ...baseRequest, textSearch })).toThrow(TraceQueryValidationError); - }); - - it('carries normalized search through keyset, page, and grouped plans', () => { - for (const fields of [{}, { pagination: { page: 0, perPage: 20 } }, { group: { by: ['threadId'] } }]) { - expect(planTraceQuery(parsed({ ...baseRequest, ...fields, textSearch: ' ERROR 50%_ ' }))).toMatchObject({ - textSearch: 'error 50%_', - }); - } - }); - - it('binds trace and group cursors to search', () => { - for (const group of [undefined, { by: ['threadId'] }]) { - const plan = planTraceQuery(parsed({ ...baseRequest, group, textSearch: ' ERROR ' })); - if (plan.paginationMode !== 'keyset') throw new Error('Expected keyset plan'); - const values = - plan.result === 'groups' - ? { result: 'groups' as const, threadId: 'thread-1' } - : { result: 'traces' as const, traceId: 'trace-1', sortValue: '2026-08-15T00:00:00.000Z' }; - const after = encodeTraceQueryCursor(plan, values); - expect(planTraceQuery(parsed({ ...baseRequest, group, textSearch: 'error', page: { after } }))).toMatchObject({ - binding: plan.binding, - }); - for (const textSearch of ['timeout', undefined]) { - expect(() => planTraceQuery(parsed({ ...baseRequest, group, textSearch, page: { after } }))).toThrow( - TraceQueryCursorError, - ); - } - } - }); - - it('rejects text search in delta mode because root updates cannot track matching child arrivals', () => { - expect(() => parsed({ ...baseRequest, textSearch: 'error', mode: 'delta' })).toThrow(TraceQueryValidationError); - }); -}); - describe('aggregated trace roots contract', () => { const options = { allowAggregatedRoots: true }; diff --git a/packages/core/src/storage/domains/observability/trace-query.ts b/packages/core/src/storage/domains/observability/trace-query.ts index 4638c1ff542..0cc242f6f59 100644 --- a/packages/core/src/storage/domains/observability/trace-query.ts +++ b/packages/core/src/storage/domains/observability/trace-query.ts @@ -7,7 +7,6 @@ import { paginationArgsSchema, paginationInfoSchema, } from '../shared'; -import { observabilityTextSearchSchema } from './text-search'; import type { SpanRecord } from './tracing'; export const TRACE_QUERY_MAX_DEPTH = 12; @@ -65,6 +64,41 @@ const collectionMemberSchema = literalStringSchema.refine( 'Collection predicates require a non-empty string value', ); const timestampLiteralSchema = z.string().datetime({ offset: true }); +export const TRACE_QUERY_TOKEN_FIELDS = [ + 'input', + 'output', + 'error', + 'inputPreview', + 'outputPreview', + 'errorPreview', + 'all', +] as const; +export type TraceQueryTokenField = (typeof TRACE_QUERY_TOKEN_FIELDS)[number]; +/** + * Positive whole-token matching on indexed span content. For `all`, one underlying column + * must contain every query token; tokens cannot be satisfied across different columns. + * The planner preserves case. Tokenization and case folding belong to the supporting store. + * A literal producing no tokens matches nothing, including missing content. + * `not` and `none` ancestors are unsupported; + * positive predicates can compose through `and`, `or`, and `spans.some`. + */ +const tokenPredicateSchema = z + .object({ + op: z.literal('hasAllTokens'), + left: z.object({ path: z.enum(TRACE_QUERY_TOKEN_FIELDS) }).strict(), + right: z + .object({ + literal: z + .string() + .trim() + .min(1) + .refine(value => Array.from(value).length <= 256, 'Token search must contain at most 256 characters') + .meta({ maxLength: 256 }), + }) + .strict(), + }) + .strict(); + const textLiteralSchema = z.object({ literal: literalStringSchema }).strict(); const predicatePathSchema = z .string() @@ -104,6 +138,7 @@ export const traceQueryScalarPredicateSchema: z.ZodType; export type TrustedTraceQueryScalarPredicate = + | { type: 'tokens'; field: TraceQueryTokenField; operator: 'hasAllTokens'; value: string } | { type: 'comparison'; field: TraceQueryPredicateField; @@ -870,7 +907,6 @@ export interface TraceQueryTenantScope { export interface TrustedTraceQueryBasePlan { rootSource?: 'aggregated'; timeRange: { from: string; to: string }; - textSearch?: string; where?: TrustedTraceQueryPredicate; scope?: TraceQueryTenantScope; } @@ -1003,6 +1039,16 @@ export class TraceQueryCursorError extends Error { } } +/** A valid query uses a feature the selected storage adapter cannot execute. */ +export class TraceQueryUnsupportedError extends Error { + readonly code = 'TRACE_QUERY_UNSUPPORTED'; + + constructor(message: string) { + super(message); + this.name = 'TraceQueryUnsupportedError'; + } +} + export class TraceQueryExecutionError extends Error { readonly code = 'TRACE_QUERY_EXECUTION_TIMEOUT'; @@ -1037,6 +1083,8 @@ type PredicateContext = TraceQueryPredicateScope | 'spanQuery' | 'threadQuery'; /** @internal */ export interface PlannerState { + allowTokenSearch?: boolean; + isThreadQuery?: boolean; nodes: number; relatedClauses: number; literalUnits: number; @@ -1163,6 +1211,8 @@ export function parseGetTraceQueryValuesArgs(input: unknown): NormalizedGetTrace } export interface TraceQueryPlanOptions { + /** Opt in only when the host checks indexed token-search support before execution. */ + allowTokenSearch?: boolean; /** The host provides an aggregated-root reader. Defaults to false. */ allowAggregatedRoots?: boolean; /** Opaque host authorization state bound into keyset cursors. */ @@ -1316,8 +1366,9 @@ export function planTraceQuerySelectionPredicate( where: TraceQueryPredicate, issues: TraceQueryIssue[], path: Array = ['where'], + allowTokenSearch = false, ): TrustedTraceQueryPredicate | undefined { - const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues }; + const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues, allowTokenSearch }; return planPredicate(where, 'trace', path, 1, state); } @@ -1325,8 +1376,9 @@ export function planTraceQuerySelectionPredicate( export function planSpanQuerySelectionPredicate( where: TraceQueryScalarPredicate, issues: TraceQueryIssue[], + allowTokenSearch = false, ): TrustedTraceQueryScalarPredicate | undefined { - const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues }; + const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues, allowTokenSearch }; // Scalar grammar cannot produce a related-record predicate. return planPredicate(where, 'spanQuery', ['where'], 1, state) as TrustedTraceQueryScalarPredicate | undefined; } @@ -1336,7 +1388,7 @@ export function planThreadQuerySelectionPredicate( where: TraceQueryScalarPredicate, issues: TraceQueryIssue[], ): TrustedTraceQueryScalarPredicate | undefined { - const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues }; + const state: PlannerState = { nodes: 0, relatedClauses: 0, literalUnits: 0, issues, isThreadQuery: true }; return planPredicate(where, 'threadQuery', ['where'], 1, state) as TrustedTraceQueryScalarPredicate | undefined; } @@ -1347,6 +1399,7 @@ export function planPredicate( path: Array, depth: number, state: PlannerState, + underNegation = false, ): TrustedTraceQueryPredicate | TrustedTraceQueryScalarPredicate | undefined { state.nodes += 1; if (depth > TRACE_QUERY_MAX_DEPTH || state.nodes > TRACE_QUERY_MAX_NODES) { @@ -1376,7 +1429,14 @@ export function planPredicate( 'spans' in predicate ? predicate.spans : 'scores' in predicate ? predicate.scores : predicate.feedback; const quantifier = 'some' in clause ? 'some' : 'none'; const nested = 'some' in clause ? clause.some : clause.none; - const planned = planPredicate(nested, collection, [...path, collection, quantifier], depth + 1, state); + const planned = planPredicate( + nested, + collection, + [...path, collection, quantifier], + depth + 1, + state, + underNegation || quantifier === 'none', + ); return planned ? { type: 'relation', collection, quantifier, predicate: planned as TrustedTraceQueryScalarPredicate } : undefined; @@ -1384,15 +1444,49 @@ export function planPredicate( if (predicate.op === 'and' || predicate.op === 'or') { const args = predicate.args - .map((arg, index) => planPredicate(arg, context, [...path, 'args', index], depth + 1, state)) + .map((arg, index) => planPredicate(arg, context, [...path, 'args', index], depth + 1, state, underNegation)) .filter((arg): arg is TrustedTraceQueryPredicate => arg !== undefined); return { type: 'boolean', operator: predicate.op, args }; } if (predicate.op === 'not') { - const arg = planPredicate(predicate.arg, context, [...path, 'arg'], depth + 1, state); + const arg = planPredicate(predicate.arg, context, [...path, 'arg'], depth + 1, state, true); return arg ? { type: 'not', arg } : undefined; } + if (predicate.op === 'hasAllTokens') { + if (state.isThreadQuery || underNegation) { + state.issues.push({ + code: 'operator_not_allowed', + path: [...path, 'op'], + message: state.isThreadQuery + ? 'Token search is not supported in thread queries' + : 'Token search is not supported beneath not or none', + }); + return undefined; + } + if (!state.allowTokenSearch) { + state.issues.push({ + code: 'operator_not_allowed', + path: [...path, 'op'], + message: 'Token search requires a supporting host', + }); + return undefined; + } + if (context !== 'spans' && context !== 'spanQuery') { + state.issues.push({ code: 'field_not_allowed', path, message: 'Token matching is supported only on spans' }); + return undefined; + } + state.literalUnits += 1; + if (state.literalUnits > TRACE_QUERY_MAX_LITERAL_UNITS) { + addPredicateComplexityIssue( + [...path, 'right', 'literal'], + `Trace queries are limited to ${TRACE_QUERY_MAX_LITERAL_UNITS} literal units`, + state, + ); + } + return { type: 'tokens', field: predicate.left.path, operator: 'hasAllTokens', value: predicate.right.literal }; + } + const rules = rulesForContext(context); if (predicate.op === 'exists' || predicate.op === 'notExists') { const field = normalizeTraceQueryPath(predicate.path); @@ -1634,3 +1728,13 @@ function normalizeSet(values: TraceQueryLiteral[], rule: FieldRule): Array; } + +/** Whether a trusted predicate requires indexed token-search support. */ +export function hasTraceQueryTokenPredicate(predicate: TrustedTraceQueryPredicate | undefined): boolean { + if (!predicate) return false; + if (predicate.type === 'tokens') return true; + if (predicate.type === 'boolean') return predicate.args.some(hasTraceQueryTokenPredicate); + if (predicate.type === 'not') return hasTraceQueryTokenPredicate(predicate.arg); + if (predicate.type === 'relation') return hasTraceQueryTokenPredicate(predicate.predicate); + return false; +} diff --git a/packages/playground-ui/src/domains/observability/hooks/use-observability-list-filters.ts b/packages/playground-ui/src/domains/observability/hooks/use-observability-list-filters.ts index 0598f16ce08..ca85cde6491 100644 --- a/packages/playground-ui/src/domains/observability/hooks/use-observability-list-filters.ts +++ b/packages/playground-ui/src/domains/observability/hooks/use-observability-list-filters.ts @@ -1,5 +1,4 @@ import { useLayoutEffect, useMemo, useRef, useState } from 'react'; -import { effectiveTextSearch } from '../lib/text-search'; import { rangeBeforeZoom, rememberZoom } from '../lib/zoom-memory'; import type { ZoomMemory } from '../lib/zoom-memory'; import { @@ -55,9 +54,9 @@ export function useObservabilityListFilters( url?: ObservabilityListUrlState, { sortFields, - withTextSearch = false, + withTokenSearch = false, defaultDatePreset = OBSERVABILITY_LIST_DEFAULT_DATE_PRESET, - }: { sortFields?: readonly F[]; defaultDatePreset?: TraceDatePreset; withTextSearch?: boolean } = {}, + }: { sortFields?: readonly F[]; withTokenSearch?: boolean; defaultDatePreset?: TraceDatePreset } = {}, ) { const { searchParams, setSearchParams } = useListSearchParams(url); @@ -70,9 +69,14 @@ export function useObservabilityListFilters( [datesKey], ); const { tokens, groups } = useMemo( - () => readObservabilityListFilters(searchParams), + () => { + const filters = readObservabilityListFilters(searchParams); + return withTokenSearch + ? filters + : { ...filters, tokens: filters.tokens.filter(token => token.operatorId !== 'hasAllTokens') }; + }, // eslint-disable-next-line react-hooks/exhaustive-deps -- only re-read when the filter params change - [filtersKey], + [filtersKey, withTokenSearch], ); const urlSort = readObservabilityListSort( searchParams, @@ -156,23 +160,10 @@ export function useObservabilityListFilters( const setSort = (next: ObservabilityListSort) => update(params => writeObservabilityListSort(params, next)); - const searchValue = withTextSearch ? (searchParams.get('textSearch') ?? undefined) : undefined; - const textSearch = effectiveTextSearch(searchValue); - const setTextSearch = (value: string | undefined) => - update(next => { - if (value !== undefined) next.set('textSearch', value); - else next.delete('textSearch'); - next.delete('page'); - next.delete('traceId'); - next.delete('spanId'); - }); - const contentFiltersApplied = !!textSearch || tokens.length > 0 || groups.length > 0; + const contentFiltersApplied = tokens.length > 0 || groups.length > 0; const filtersApplied = contentFiltersApplied || datePreset !== defaultDatePreset; return { - searchValue, - textSearch, - setTextSearch, datePreset, dateFrom, dateTo, diff --git a/packages/playground-ui/src/domains/observability/lib/text-search-filter.ts b/packages/playground-ui/src/domains/observability/lib/text-search-filter.ts deleted file mode 100644 index 46a5d7bd214..00000000000 --- a/packages/playground-ui/src/domains/observability/lib/text-search-filter.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { effectiveTextSearch } from './text-search'; -import type { FilterBarField, FilterBarItem } from '@/ds/components/FilterBar'; -import { IconMagnifyingGlass } from '@/ds/icons/central/IconMagnifyingGlass'; - -export const TEXT_SEARCH_FIELD: FilterBarField = { - id: 'textSearch', - label: 'Contains text', - icon: IconMagnifyingGlass, - operators: ['is'], - rootOnly: true, - singleton: true, - validateInput: value => (effectiveTextSearch(value) ? undefined : 'Enter between 3 and 256 characters to search'), -}; - -export function textSearchFilterItems(value: string | undefined): FilterBarItem[] { - return value !== undefined - ? [{ id: TEXT_SEARCH_FIELD.id, fieldId: TEXT_SEARCH_FIELD.id, operatorId: 'is', value }] - : []; -} diff --git a/packages/playground-ui/src/domains/observability/lib/text-search.test.ts b/packages/playground-ui/src/domains/observability/lib/text-search.test.ts deleted file mode 100644 index b3139be6214..00000000000 --- a/packages/playground-ui/src/domains/observability/lib/text-search.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { observabilityTextSearchSchema } from '@mastra/core/storage'; -import { describe, expect, it } from 'vitest'; -import { effectiveTextSearch } from './text-search'; - -describe('effectiveTextSearch', () => { - describe('when the draft is normalized', () => { - it.each(['', ' ', 'ab', ' ABC ', 'İİ', '😀😀😀', '😀'.repeat(256), '😀'.repeat(257), 'a%b_c'])( - 'matches API validation for %s', - value => { - const parsed = observabilityTextSearchSchema.safeParse(value); - expect(effectiveTextSearch(value)).toBe(parsed.success ? parsed.data : undefined); - }, - ); - }); -}); diff --git a/packages/playground-ui/src/domains/observability/lib/text-search.ts b/packages/playground-ui/src/domains/observability/lib/text-search.ts deleted file mode 100644 index 04501a9cd53..00000000000 --- a/packages/playground-ui/src/domains/observability/lib/text-search.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** Matches the API's Unicode code-point limits without importing server-only storage code. */ -export function effectiveTextSearch(value: string | undefined): string | undefined { - const text = value?.trim().toLowerCase(); - if (!text) return undefined; - const length = Array.from(text).length; - return length >= 3 && length <= 256 ? text : undefined; -} diff --git a/packages/playground-ui/src/domains/observability/lib/token-search-predicate.test.ts b/packages/playground-ui/src/domains/observability/lib/token-search-predicate.test.ts new file mode 100644 index 00000000000..7ae308524d3 --- /dev/null +++ b/packages/playground-ui/src/domains/observability/lib/token-search-predicate.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest'; +import { hasTokenSearchFilter, withTokenSearchFields } from './token-search-predicate'; + +describe('trace content filters', () => { + it.each(['all', 'input', 'output', 'error', 'inputPreview', 'outputPreview', 'errorPreview'])( + 'counts only span-scoped %s tokens as applied', + field => { + const token = { fieldId: field, operatorId: 'hasAllTokens', value: 'needle' }; + expect(hasTokenSearchFilter(token)).toBe(false); + expect(hasTokenSearchFilter({ ...token, fieldId: `spans.${field}` })).toBe(true); + expect(hasTokenSearchFilter({ id: 'group', logic: 'or', nodes: [token] })).toBe(false); + expect(hasTokenSearchFilter({ ...token, fieldId: `spans.${field}`, value: '!!!' })).toBe(false); + }, + ); + + it('labels trace fields as span-scoped and preserves Error presence operators', () => { + const fields = withTokenSearchFields( + [{ id: 'spans.error', label: 'Span error', operators: ['exists', 'notExists'] }], + true, + 'spans.', + ); + expect(fields.map(field => field.label)).toEqual([ + 'Any span content', + 'Span input', + 'Span output', + 'Span error', + 'Span input preview', + 'Span output preview', + 'Span error preview', + ]); + expect(fields.find(field => field.id === 'spans.error')?.operators).toEqual([ + 'exists', + 'notExists', + 'hasAllTokens', + ]); + expect(withTokenSearchFields([], true)[0]?.label).toBe('Any Content'); + }); +}); diff --git a/packages/playground-ui/src/domains/observability/lib/token-search-predicate.ts b/packages/playground-ui/src/domains/observability/lib/token-search-predicate.ts new file mode 100644 index 00000000000..e2f6bcac246 --- /dev/null +++ b/packages/playground-ui/src/domains/observability/lib/token-search-predicate.ts @@ -0,0 +1,58 @@ +import type { TraceQueryScalarPredicate, TraceQueryTokenField } from '@mastra/core/storage'; +import type { TraceFilterNode } from '@/domains/traces/trace-query-filters'; +import type { FilterBarField } from '@/ds/components/FilterBar/types'; +import { IconExclamationTriangle } from '@/ds/icons/central/IconExclamationTriangle'; +import { IconMagnifyingGlass } from '@/ds/icons/central/IconMagnifyingGlass'; + +const TOKEN_FIELDS = [ + ['all', 'Any Content'], + ['input', 'Input'], + ['output', 'Output'], + ['error', 'Error'], + ['inputPreview', 'Input Preview'], + ['outputPreview', 'Output Preview'], + ['errorPreview', 'Error Preview'], +] as const satisfies ReadonlyArray; + +export const isTokenSearchField = (path: string): path is TraceQueryTokenField => + TOKEN_FIELDS.some(([field]) => field === path); + +export function tokenSearchValue(value: unknown): string | undefined { + if (typeof value !== 'string') return undefined; + const text = value.trim(); + // splitByNonAlpha keeps non-ASCII sequences, including symbols, as tokens. + if (!/[a-zA-Z0-9\u0080-\uFFFF]/.test(text) || Array.from(text).length > 256) return undefined; + return text || undefined; +} + +export function tokenSearchPredicate(path: string, value: unknown): TraceQueryScalarPredicate | undefined { + const literal = tokenSearchValue(value); + return isTokenSearchField(path) && literal ? { op: 'hasAllTokens', left: { path }, right: { literal } } : undefined; +} + +export function withTokenSearchFields(fields: FilterBarField[], enabled: boolean, prefix = ''): FilterBarField[] { + if (!enabled) return fields; + const searchable = TOKEN_FIELDS.map(([path, label]): FilterBarField => { + const existing = fields.find(field => field.id === prefix + path); + return { + ...existing, + id: prefix + path, + label: prefix === 'spans.' ? (path === 'all' ? 'Any span content' : `Span ${label.toLowerCase()}`) : label, + icon: + path === 'error' || path === 'errorPreview' ? IconExclamationTriangle : (existing?.icon ?? IconMagnifyingGlass), + operators: [...(existing?.operators ?? []), 'hasAllTokens'], + alwaysShowOperator: true, + validateInput: value => (tokenSearchValue(value) ? undefined : 'Enter words to search (up to 256 characters)'), + }; + }); + return [...searchable, ...fields.filter(field => !searchable.some(search => search.id === field.id))]; +} + +export function hasTokenSearchFilter(node: TraceFilterNode): boolean { + if ('nodes' in node) return node.nodes.some(hasTokenSearchFilter); + return ( + node.operatorId === 'hasAllTokens' && + node.fieldId.startsWith('spans.') && + !!tokenSearchPredicate(node.fieldId.slice('spans.'.length), node.value) + ); +} diff --git a/packages/playground-ui/src/domains/observability/saved-view-state.test.ts b/packages/playground-ui/src/domains/observability/saved-view-state.test.ts index 3fdbf3e5674..dc633a5be06 100644 --- a/packages/playground-ui/src/domains/observability/saved-view-state.test.ts +++ b/packages/playground-ui/src/domains/observability/saved-view-state.test.ts @@ -242,18 +242,15 @@ describe("the page's default date preset", () => { }); }); -describe.each(['traces', 'spans'] as const)('text search in %s saved views', page => { - describe('when a search is saved', () => { - it('restores the term when the view is applied', () => { - const state = savedViewFromSearchParams(page, new URLSearchParams('textSearch=needle')); - const applied = applySavedView(state, new URLSearchParams('textSearch=other')); - expect(applied.params.get('textSearch')).toBe('needle'); - }); - }); - describe('when a view has no search', () => { - it('clears a search left by the previous view', () => { - const state = savedViewFromSearchParams(page, new URLSearchParams()); - expect(applySavedView(state, new URLSearchParams('textSearch=old')).params.has('textSearch')).toBe(false); - }); - }); +describe.each(['traces', 'spans'] as const)('content fields in %s saved views', page => { + it.each(['all', 'input', 'output', 'error', 'inputPreview', 'outputPreview', 'errorPreview'])( + 'round-trips %s word search', + field => { + const key = page === 'spans' ? `filter.${field}` : `filterSpan${field[0].toUpperCase()}${field.slice(1)}`; + const state = savedViewFromSearchParams(page, new URLSearchParams(`${key}=needle&${key}.op=hasAllTokens`)); + const applied = applySavedView(state, new URLSearchParams()); + expect(applied.params.get(key)).toBe('needle'); + expect(applied.params.get(`${key}.op`)).toBe('hasAllTokens'); + }, + ); }); diff --git a/packages/playground-ui/src/domains/observability/saved-view-state.ts b/packages/playground-ui/src/domains/observability/saved-view-state.ts index 67bb844adb6..8dc9787c81f 100644 --- a/packages/playground-ui/src/domains/observability/saved-view-state.ts +++ b/packages/playground-ui/src/domains/observability/saved-view-state.ts @@ -16,6 +16,7 @@ import type { SavedViewSort, SavedViewState, } from '@mastra/core/storage'; +import { withTokenSearchFields } from './lib/token-search-predicate'; import { readObservabilityListFilters, writeObservabilityListFilters, @@ -113,17 +114,6 @@ const acceptsWith = const operatorsByField = (fields: readonly { id: string; operators?: string[] }[]) => new Map(fields.map(field => [field.id, field.operators])); -const searchOptions = { - readOptions: (params: URLSearchParams) => { - const textSearch = params.get('textSearch'); - return textSearch ? { textSearch } : {}; - }, - writeOptions: (params: URLSearchParams, options: Record) => { - if (typeof options.textSearch === 'string' && options.textSearch) params.set('textSearch', options.textSearch); - else params.delete('textSearch'); - }, -}; - const noOptions = { readOptions: () => ({}), writeOptions: () => {}, @@ -136,27 +126,36 @@ const splitNodes = (nodes: TraceFilterNode[]) => ({ // The widest field set each page can offer (every server capability on); the page's own query // builder still leaves out what the connected server can't run. -const TRACE_FIELD_OPERATORS = operatorsByField([ - ...createTraceFilterBarFields({ - availableRootEntityNames: [], - availableEnvironments: [], - withRootDuration: true, - withTimeToFirstChunk: true, - withTimeToFirstToken: true, - }), - { id: 'tags', operators: TRACE_TAGS_OPERATORS }, -]); +const TRACE_FIELD_OPERATORS = operatorsByField( + withTokenSearchFields( + [ + ...createTraceFilterBarFields({ + availableRootEntityNames: [], + availableEnvironments: [], + withRootDuration: true, + withTimeToFirstChunk: true, + withTimeToFirstToken: true, + }), + { id: 'tags', label: 'Tags', operators: TRACE_TAGS_OPERATORS }, + ], + true, + 'spans.', + ), +); const TRACE_URL_FIELD_IDS = new Set([...TRACE_SYNTHETIC_FILTER_FIELD_IDS, ...TRACE_PROPERTY_FILTER_FIELD_IDS]); const SPAN_FIELD_IDS = new Set([...SPAN_CORE_FILTER_FIELD_IDS, ...SPAN_CONTEXT_FILTER_FIELD_IDS]); const SPAN_FIELD_OPERATORS = operatorsByField( - createSpanFilterBarFields({ - withContextFields: true, - withTimeToFirstChunk: true, - withTimeToFirstToken: true, - entityNames: [], - environments: [], - }), + withTokenSearchFields( + createSpanFilterBarFields({ + withContextFields: true, + withTimeToFirstChunk: true, + withTimeToFirstToken: true, + entityNames: [], + environments: [], + }), + true, + ), ); const THREAD_FIELD_IDS = new Set(THREAD_FILTER_FIELD_IDS); @@ -203,12 +202,10 @@ const PAGE_SPECS: Record = { readOptions: params => { const listMode = params.get(TRACE_LIST_MODE_PARAM); return { - ...searchOptions.readOptions(params), ...(listMode && TRACE_LIST_MODE_VALUES.has(listMode as TraceListMode) ? { listMode } : {}), }; }, writeOptions: (params, options) => { - searchOptions.writeOptions(params, options); const { listMode } = options; if (typeof listMode === 'string' && TRACE_LIST_MODE_VALUES.has(listMode as TraceListMode)) { params.set(TRACE_LIST_MODE_PARAM, listMode); @@ -219,10 +216,10 @@ const PAGE_SPECS: Record = { }, spans: { ...observabilityListFilters, - ...searchOptions, + ...noOptions, sortFields: SPAN_LIST_SORT_FIELDS, acceptsToken: acceptsWith( - fieldId => SPAN_FIELD_IDS.has(fieldId), + fieldId => SPAN_FIELD_IDS.has(fieldId) || SPAN_FIELD_OPERATORS.has(fieldId), fieldId => SPAN_FIELD_OPERATORS.get(fieldId), ), columns: 'spans', diff --git a/packages/playground-ui/src/domains/spans/components/__tests__/spans-explorer-body.msw.test.tsx b/packages/playground-ui/src/domains/spans/components/__tests__/spans-explorer-body.msw.test.tsx index 7ec2c446d10..24ae1420816 100644 --- a/packages/playground-ui/src/domains/spans/components/__tests__/spans-explorer-body.msw.test.tsx +++ b/packages/playground-ui/src/domains/spans/components/__tests__/spans-explorer-body.msw.test.tsx @@ -140,218 +140,161 @@ describe('SpansExplorerBody', () => { window.localStorage.clear(); }); - describe('when text search is supported', () => { - const renderSearchableBody = async (initial: string) => { - setHandlers(spanRowsPage, { - ...spanAggregateCapabilities, - capabilities: { ...spanAggregateCapabilities.capabilities, spanQueryTextSearch: true }, - }); - server.use( - http.post(SPANS_AGGREGATE_URL, () => HttpResponse.json(spanCountsAggregate({ to: new Date().toISOString() }))), - ); - const result = renderBodyAtUrl(initial); - await waitFor(() => expect(result.queries.length).toBeGreaterThan(0)); - return result; + describe('indexed content filters', () => { + const searchable = { + ...spanAggregateCapabilities, + capabilities: { + ...spanAggregateCapabilities.capabilities, + spanQueryTokenSearch: true, + spanAggregateTokenSearch: true, + }, }; - - it('marks an invalid restored search with a validation warning', async () => { - setHandlers(spanRowsPage, { - ...spanQueryCapabilities, - capabilities: { ...spanQueryCapabilities.capabilities, spanQueryTextSearch: true }, - }); - const { queries } = renderBodyAtUrl('textSearch=ab'); + it('offers exists first when adding an Error filter on a search-enabled host', async () => { + setHandlers(spanRowsPage, searchable); + server.use( + http.post(SPANS_AGGREGATE_URL, () => HttpResponse.json({ rows: [], truncated: false })), + ); + const { queries } = renderBodyAtUrl(''); await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - expect(screen.getByRole('group', { name: 'Contains text ab' }).getAttribute('aria-invalid')).toBe('true'); - expect(screen.getByTitle('Enter between 3 and 256 characters to search')).toBeTruthy(); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - }); - - it('applies a corrected restored search', async () => { - setHandlers(spanRowsPage, { - ...spanQueryCapabilities, - capabilities: { ...spanQueryCapabilities.capabilities, spanQueryTextSearch: true }, - }); - const { queries } = renderBodyAtUrl('textSearch=ab'); - await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - fireEvent.click(screen.getByRole('combobox', { name: 'Value: ab' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'needle' } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - await waitFor(() => expect(queries.at(-1)).toHaveProperty('textSearch', 'needle')); - expect(screen.getByRole('group', { name: 'Contains text needle' }).getAttribute('aria-invalid')).toBeNull(); - }); - - it('does not offer an existing search field when editing another chip', async () => { - setHandlers(spanRowsPage, { - ...spanQueryCapabilities, - capabilities: { ...spanQueryCapabilities.capabilities, spanQueryTextSearch: true }, - }); - const { queries } = renderBodyAtUrl('filter.status=error&textSearch=needle'); - await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - const original = queries.at(-1); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - await screen.findByRole('option', { name: 'Span name' }); - expect(screen.queryByRole('option', { name: 'Contains text' })).toBeNull(); - expect(queries.at(-1)).toEqual(original); - }); - - it('preserves an editable empty search after changing the field', async () => { - setHandlers(spanRowsPage, { - ...spanQueryCapabilities, - capabilities: { ...spanQueryCapabilities.capabilities, spanQueryTextSearch: true }, - }); - const { queries } = renderBodyAtUrl('filter.status=error'); - await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - expect(await screen.findByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(currentSearchParams().get('textSearch')).toBe(''); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - }); - - it('applies text entered into an empty search chip', async () => { - setHandlers(spanRowsPage, { - ...spanQueryCapabilities, - capabilities: { ...spanQueryCapabilities.capabilities, spanQueryTextSearch: true }, - }); - const { queries } = renderBodyAtUrl('filter.status=error'); - await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - expect(await screen.findByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(currentSearchParams().get('textSearch')).toBe(''); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - fireEvent.click(screen.getByRole('combobox', { name: 'Value: …' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'needle' } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - await waitFor(() => expect(queries.at(-1)).toHaveProperty('textSearch', 'needle')); - }); - - it('removes an empty draft from the URL', async () => { - setHandlers(spanRowsPage, { - ...spanQueryCapabilities, - capabilities: { ...spanQueryCapabilities.capabilities, spanQueryTextSearch: true }, - }); - const { queries } = renderBodyAtUrl('filter.status=error'); - await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - expect(await screen.findByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(currentSearchParams().get('textSearch')).toBe(''); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - fireEvent.click(screen.getByRole('button', { name: 'Remove Contains text filter' })); - await waitFor(() => expect(currentSearchParams().has('textSearch')).toBe(false)); - }); - - it('applies normalized search without losing other filters', async () => { - const { queries } = await renderSearchableBody('filter.status=error'); - const originalWhere = queries.at(-1)?.where; const input = screen.getByRole('combobox', { name: 'Add filter' }); fireEvent.focus(input); - fireEvent.change(input, { target: { value: 'Contains text' } }); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - fireEvent.change(input, { target: { value: 'NEEDLE' } }); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - fireEvent.keyDown(input, { key: 'Enter' }); - await waitFor(() => expect(queries.at(-1)).toHaveProperty('textSearch', 'needle')); - expect(queries.at(-1)?.where).toEqual(originalWhere); + fireEvent.change(input, { target: { value: 'Error' } }); + fireEvent.click(await screen.findByRole('option', { name: 'Error', exact: true })); + expect(screen.getAllByRole('option').map(option => option.textContent)).toEqual([ + 'exists', + 'does not exist', + 'contains words', + ]); + fireEvent.click(screen.getByRole('option', { name: 'exists', exact: true })); + await waitFor(() => + expect(queries.at(-1)?.where).toEqual({ op: 'and', args: [{ op: 'exists', path: 'error' }] }), + ); + expect(screen.getByRole('group', { name: 'Error exists' }).getAttribute('aria-invalid')).not.toBe('true'); }); - - it('preserves the entered search in the URL', async () => { - const { queries } = await renderSearchableBody('filter.status=error'); - const input = screen.getByRole('combobox', { name: 'Add filter' }); - fireEvent.focus(input); - fireEvent.change(input, { target: { value: 'Contains text' } }); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - fireEvent.change(input, { target: { value: 'NEEDLE' } }); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - fireEvent.keyDown(input, { key: 'Enter' }); - await waitFor(() => expect(queries.at(-1)).toHaveProperty('textSearch', 'needle')); - expect(currentSearchParams().get('textSearch')).toBe('NEEDLE'); + it.each(['exists', 'notExists'])('keeps Error %s valid on search-enabled hosts', async operator => { + setHandlers(spanRowsPage, searchable); + server.use( + http.post(SPANS_AGGREGATE_URL, () => HttpResponse.json({ rows: [], truncated: false })), + ); + const { queries } = renderBodyAtUrl(`filter.error=&filter.error.op=${operator}`); + await waitFor(() => expect(queries.length).toBeGreaterThan(0)); + const label = operator === 'exists' ? 'exists' : 'does not exist'; + expect(screen.getByRole('group', { name: `Error ${label}` }).getAttribute('aria-invalid')).not.toBe('true'); + expect(queries.at(-1)?.where).toEqual({ op: 'and', args: [{ op: operator, path: 'error' }] }); }); - - it('hides the histogram after applying search', async () => { - const { queries } = await renderSearchableBody('filter.status=error'); - const input = screen.getByRole('combobox', { name: 'Add filter' }); - fireEvent.focus(input); - fireEvent.change(input, { target: { value: 'Contains text' } }); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - fireEvent.change(input, { target: { value: 'NEEDLE' } }); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - fireEvent.keyDown(input, { key: 'Enter' }); - await waitFor(() => expect(queries.at(-1)).toHaveProperty('textSearch', 'needle')); - expect(screen.queryByRole('region', { name: 'Spans over time' })).toBeNull(); - }); - - it('rejects an oversized edit without changing the applied search', async () => { - const { queries } = await renderSearchableBody('filter.status=error&textSearch=NEEDLE'); - fireEvent.click(screen.getByRole('combobox', { name: 'Value: NEEDLE' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'x'.repeat(257) } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - expect(await screen.findByText('Enter between 3 and 256 characters to search')).toBeTruthy(); - expect(currentSearchParams().get('textSearch')).toBe('NEEDLE'); - }); - - it('applies a valid edit', async () => { - const { queries } = await renderSearchableBody('filter.status=error&textSearch=NEEDLE'); - fireEvent.click(screen.getByRole('combobox', { name: 'Value: NEEDLE' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'updated' } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - await waitFor(() => expect(queries.at(-1)).toHaveProperty('textSearch', 'updated')); - }); - - it('removes search without losing other filters', async () => { - const { queries } = await renderSearchableBody('filter.status=error&textSearch=NEEDLE'); - const originalWhere = queries.at(-1)?.where; - fireEvent.click(screen.getByRole('button', { name: 'Remove Contains text filter' })); - await waitFor(() => expect(queries.at(-1)).not.toHaveProperty('textSearch')); - expect(currentSearchParams().has('textSearch')).toBe(false); - expect(queries.at(-1)?.where).toEqual(originalWhere); - }); - - it('restores the histogram after removing search', async () => { - const { queries } = await renderSearchableBody('filter.status=error&textSearch=NEEDLE'); - fireEvent.click(screen.getByRole('button', { name: 'Remove Contains text filter' })); - await waitFor(() => expect(queries.at(-1)).not.toHaveProperty('textSearch')); - await screen.findByRole('region', { name: 'Spans over time' }); - }); - - it('restores search from the URL without requesting an unfiltered histogram', async () => { - setHandlers(spanRowsPage, { - ...spanAggregateCapabilities, - capabilities: { ...spanAggregateCapabilities.capabilities, spanQueryTextSearch: true }, - }); + it.each(['spanQueryTokenSearch', 'spanAggregateTokenSearch'] as const)( + 'disables search for the whole page without %s', + async capability => { + setHandlers(spanRowsPage, { + ...searchable, + capabilities: { ...searchable.capabilities, [capability]: false }, + }); + server.use( + http.post(SPANS_AGGREGATE_URL, () => + HttpResponse.json({ rows: [], truncated: false }), + ), + ); + const { queries } = renderBodyAtUrl('filter.all=needle&filter.all.op=hasAllTokens'); + await waitFor(() => expect(queries.length).toBeGreaterThan(0)); + expect(tokenTerms(queries.at(-1))).toEqual([]); + const input = screen.getByRole('combobox', { name: 'Add filter' }); + fireEvent.focus(input); + fireEvent.change(input, { target: { value: 'Any Content' } }); + expect(screen.queryByRole('option', { name: 'Any Content' })).toBeNull(); + }, + ); + it.each([ + ['all', 'Any Content'], + ['input', 'Input'], + ['output', 'Output'], + ['error', 'Error'], + ['inputPreview', 'Input Preview'], + ['outputPreview', 'Output Preview'], + ['errorPreview', 'Error Preview'], + ] as const)('uses the same %s search for lists and histograms', async (field, label) => { + setHandlers(spanRowsPage, searchable); const aggregate = vi.fn(); server.use( - http.post(SPANS_AGGREGATE_URL, () => { - aggregate(); + http.post(SPANS_AGGREGATE_URL, async ({ request }) => { + const body = spanAggregateRequestSchema.parse(await request.json()); + planSpanAggregate(body, { allowTokenSearch: true }); + aggregate(body); return HttpResponse.json({ rows: [], truncated: false }); }), ); - const { queries } = renderBodyAtUrl('textSearch=needle'); + const { queries } = renderBodyAtUrl(`filter.${field}=OK&filter.${field}.op=hasAllTokens`); await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - expect(queries.at(-1)).toHaveProperty('textSearch', 'needle'); - expect(screen.getByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(screen.getByText('needle')).toBeTruthy(); - expect(screen.queryByRole('region', { name: 'Spans over time' })).toBeNull(); - expect(aggregate).not.toHaveBeenCalled(); + expect(queries.at(-1)?.where).toEqual({ + op: 'and', + args: [{ op: 'hasAllTokens', left: { path: field }, right: { literal: 'OK' } }], + }); + expect(screen.getByRole('button', { name: `Remove ${label} filter` })).toBeTruthy(); + expect(screen.getByText('contains words')).toBeTruthy(); + await waitFor(() => expect(aggregate).toHaveBeenCalled()); + expect(aggregate.mock.calls.at(-1)?.[0].where).toEqual(queries.at(-1)?.where); + expect(screen.getByRole('region', { name: 'Spans over time' })).toBeTruthy(); }); - }); - - describe('when text search is unavailable', () => { - it('ignores a search restored from a shared URL', async () => { - setHandlers(spanRowsPage); - const { queries } = renderBodyAtUrl('textSearch=needle'); + it('adds Any Content with the word operator and preserves it in the URL', async () => { + setHandlers(spanRowsPage, searchable); + server.use( + http.post(SPANS_AGGREGATE_URL, () => HttpResponse.json({ rows: [], truncated: false })), + ); + const { queries } = renderBodyAtUrl('filter.status=error'); await waitFor(() => expect(queries.length).toBeGreaterThan(0)); - expect(queries.at(-1)).not.toHaveProperty('textSearch'); - expect(screen.queryByRole('button', { name: 'Remove Contains text filter' })).toBeNull(); const input = screen.getByRole('combobox', { name: 'Add filter' }); fireEvent.focus(input); - fireEvent.change(input, { target: { value: 'Contains text' } }); - expect(screen.queryByRole('option', { name: 'Contains text' })).toBeNull(); + fireEvent.change(input, { target: { value: 'Any Content' } }); + fireEvent.click(await screen.findByRole('option', { name: 'Any Content' })); + fireEvent.change(input, { target: { value: 'id' } }); + fireEvent.keyDown(input, { key: 'Enter' }); + await waitFor(() => expect(tokenTerms(queries.at(-1))).toEqual(['id'])); + expect(currentSearchParams().get('filter.all')).toBe('id'); + expect(currentSearchParams().get('filter.all.op')).toBe('hasAllTokens'); + expect(currentSearchParams().has('textSearch')).toBe(false); + fireEvent.click(screen.getByRole('button', { name: 'Remove Any Content filter' })); + await waitFor(() => expect(tokenTerms(queries.at(-1))).toEqual([])); + expect(queries.at(-1)?.where).toEqual({ + op: 'and', + args: [{ op: 'eq', left: { path: 'status' }, right: { literal: 'error' } }], + }); + await screen.findByRole('region', { name: 'Spans over time' }); + }); + it.each(['---', 'x'.repeat(257)])('rejects invalid edits without changing the applied search: %s', async value => { + setHandlers(spanRowsPage, searchable); + server.use( + http.post(SPANS_AGGREGATE_URL, () => HttpResponse.json({ rows: [], truncated: false })), + ); + const { queries } = renderBodyAtUrl('filter.input=needle&filter.input.op=hasAllTokens'); + await waitFor(() => expect(queries.length).toBeGreaterThan(0)); + fireEvent.click(screen.getByRole('combobox', { name: 'Value: needle' })); + const editor = screen.getByPlaceholderText('Type a value…'); + fireEvent.change(editor, { target: { value } }); + fireEvent.keyDown(editor, { key: 'Enter' }); + expect(await screen.findByText('Enter words to search (up to 256 characters)')).toBeTruthy(); + expect(tokenTerms(queries.at(-1))).toEqual(['needle']); + }); + it.each([ + ['all', 'Any Content'], + ['input', 'Input'], + ['output', 'Output'], + ['error', 'Error'], + ['inputPreview', 'Input Preview'], + ['outputPreview', 'Output Preview'], + ['errorPreview', 'Error Preview'], + ] as const)('does not send %s token predicates without the span capability', async (field, label) => { + setHandlers(spanRowsPage, { + ...spanQueryCapabilities, + capabilities: { ...spanQueryCapabilities.capabilities, traceQueryTokenSearch: true }, + }); + const { queries } = renderBodyAtUrl(`filter.${field}=needle&filter.${field}.op=hasAllTokens`); + await waitFor(() => expect(queries.length).toBeGreaterThan(0)); + expect(tokenTerms(queries.at(-1))).toEqual([]); + expect(screen.queryByRole('button', { name: `Remove ${label} filter` })).toBeNull(); + expect(screen.queryByText('needle')).toBeNull(); + const input = screen.getByRole('combobox', { name: 'Add filter' }); + fireEvent.focus(input); + fireEvent.change(input, { target: { value: 'Any Content' } }); + expect(screen.queryByRole('option', { name: 'Any Content' })).toBeNull(); }); }); @@ -1185,3 +1128,17 @@ describe('SpansExplorerBody histogram', () => { }); }); }); + +function tokenTerms(value: unknown): unknown[] { + if (!value || typeof value !== 'object') return []; + if ( + 'op' in value && + value.op === 'hasAllTokens' && + 'right' in value && + value.right && + typeof value.right === 'object' && + 'literal' in value.right + ) + return [value.right.literal]; + return Object.values(value).flatMap(child => (Array.isArray(child) ? child.flatMap(tokenTerms) : tokenTerms(child))); +} diff --git a/packages/playground-ui/src/domains/spans/components/spans-explorer-body.tsx b/packages/playground-ui/src/domains/spans/components/spans-explorer-body.tsx index d33c7edcbfd..aa5ad2c6eb0 100644 --- a/packages/playground-ui/src/domains/spans/components/spans-explorer-body.tsx +++ b/packages/playground-ui/src/domains/spans/components/spans-explorer-body.tsx @@ -43,8 +43,10 @@ export type SpansExplorerBodyProps = { /** The spans page body: filter bar, span list and the host's span panel. Router-agnostic. */ export function SpansExplorerBody({ selection, onSelectionChange, renderPanel, urlState }: SpansExplorerBodyProps) { const { data: capabilities, isLoading: isCapabilitiesLoading } = useObservabilityCapabilities(); - const withTextSearch = capabilities?.capabilities.spanQueryTextSearch ?? false; - const filters = useObservabilityListFilters(urlState, { sortFields: SPAN_LIST_SORT_FIELDS, withTextSearch }); + const withTokenSearch = !!( + capabilities?.capabilities.spanQueryTokenSearch && capabilities.capabilities.spanAggregateTokenSearch + ); + const filters = useObservabilityListFilters(urlState, { sortFields: SPAN_LIST_SORT_FIELDS, withTokenSearch }); const { timeRange, tokens, groups } = filters; const columns = useTraceColumnPreferences({ scope: 'spans' }); @@ -91,22 +93,31 @@ export function SpansExplorerBody({ selection, onSelectionChange, renderPanel, u const where = useMemo( () => buildSpanQueryWhere(tokens, groups, { + withTokenSearch, withContextFields, withOutcomeFields, withModelFields, withTimeToFirstChunk, withTimeToFirstToken, }), - [tokens, groups, withContextFields, withOutcomeFields, withModelFields, withTimeToFirstChunk, withTimeToFirstToken], + [ + tokens, + groups, + withTokenSearch, + withContextFields, + withOutcomeFields, + withModelFields, + withTimeToFirstChunk, + withTimeToFirstToken, + ], ); const query = useMemo( () => ({ timeRange, orderBy: [{ field: sortField, direction: sortDirection }], - ...(where ? { where } : {}), - ...(filters.textSearch ? { textSearch: filters.textSearch } : {}), + where, }), - [timeRange, sortField, sortDirection, where, filters.textSearch], + [timeRange, sortField, sortDirection, where], ); const { spans, hasNextPage, isFetchingNextPage, setEndOfListElement, isLoading, isError, error } = useSpansListSource( @@ -143,9 +154,7 @@ export function SpansExplorerBody({ selection, onSelectionChange, renderPanel, u filters.onZoom(from, to)} /> diff --git a/packages/playground-ui/src/domains/spans/components/spans-explorer-histogram.tsx b/packages/playground-ui/src/domains/spans/components/spans-explorer-histogram.tsx index c2276ab3ca5..6940ad71659 100644 --- a/packages/playground-ui/src/domains/spans/components/spans-explorer-histogram.tsx +++ b/packages/playground-ui/src/domains/spans/components/spans-explorer-histogram.tsx @@ -15,8 +15,6 @@ import { } from '@/domains/observability/lib/histogram-buckets'; export type SpansExplorerHistogramProps = { - /** Applied list search; aggregates do not yet support text search (OBS-936). */ - textSearch?: string; /** The span list's resolved time range. */ timeRange: SpanQueryArgs['timeRange']; /** The span list's filter predicate, from `buildSpanQueryWhere`. */ @@ -29,7 +27,7 @@ export type SpansExplorerHistogramProps = { * Span and error counts over the span list's time range and filters. * Renders nothing when the server can't aggregate spans or the window is wider than it aggregates. */ -export function SpansExplorerHistogram({ timeRange, where, textSearch, onZoom }: SpansExplorerHistogramProps) { +export function SpansExplorerHistogram({ timeRange, where, onZoom }: SpansExplorerHistogramProps) { const aggregateAvailable = useSpanAggregateAvailable(); const request = useMemo( @@ -44,7 +42,7 @@ export function SpansExplorerHistogram({ timeRange, where, textSearch, onZoom }: [timeRange, where], ); - const hidden = !!textSearch || !aggregateAvailable.enabled || exceedsAggregateWindow(timeRange); + const hidden = !aggregateAvailable.enabled || exceedsAggregateWindow(timeRange); const { data, isLoading, isError, isPlaceholderData } = useSpanAggregate({ request, diff --git a/packages/playground-ui/src/domains/spans/components/spans-filter-bar.tsx b/packages/playground-ui/src/domains/spans/components/spans-filter-bar.tsx index b3c5d1598b8..3ee61631522 100644 --- a/packages/playground-ui/src/domains/spans/components/spans-filter-bar.tsx +++ b/packages/playground-ui/src/domains/spans/components/spans-filter-bar.tsx @@ -12,9 +12,7 @@ import { FILTER_BAR_TIME_RANGE_FIELD_ID } from '@/ds/components/FilterBar/filter const createItemId = (fieldId: string) => fieldId; export type SpansFilterBarProps = { - withTextSearch?: boolean; - textSearch?: string; - onTextSearchChange?: (value: string | undefined) => void; + withTokenSearch?: boolean; datePreset: TraceDatePreset; dateFrom?: Date; dateTo?: Date; @@ -37,9 +35,7 @@ export type SpansFilterBarProps = { /** The spans filter bar: the time range plus the fields `querySpans()` accepts. */ export function SpansFilterBar({ - withTextSearch = false, - textSearch, - onTextSearchChange, + withTokenSearch = false, datePreset, dateFrom, dateTo, @@ -55,13 +51,11 @@ export function SpansFilterBar({ describeSuggestionsError, disabled, }: SpansFilterBarProps) { - const fields = useSpansFilterBarFields({ timeRange, withTextSearch }); + const fields = useSpansFilterBarFields({ timeRange, withTokenSearch }); const { filterBarValue, onFilterBarChange } = useSpansFilterBar({ tokens, groups, onFiltersChange, - textSearch, - onTextSearchChange, }); return ( diff --git a/packages/playground-ui/src/domains/spans/hooks/use-spans-filter-bar.ts b/packages/playground-ui/src/domains/spans/hooks/use-spans-filter-bar.ts index 0dca45a60bb..0449a10bcd2 100644 --- a/packages/playground-ui/src/domains/spans/hooks/use-spans-filter-bar.ts +++ b/packages/playground-ui/src/domains/spans/hooks/use-spans-filter-bar.ts @@ -11,7 +11,7 @@ import { import type { TraceFilterGroup, TraceFilterToken } from '../../traces/trace-query-filters'; import type { TraceDatePreset } from '../../traces/types'; import { createSpanFilterBarFields } from '../span-filters'; -import { TEXT_SEARCH_FIELD, textSearchFilterItems } from '@/domains/observability/lib/text-search-filter'; +import { withTokenSearchFields } from '@/domains/observability/lib/token-search-predicate'; import { isFilterBarGroup } from '@/ds/components/FilterBar'; import type { FilterBarExpression, FilterBarField, FilterBarItem } from '@/ds/components/FilterBar'; import { @@ -35,7 +35,7 @@ const NO_SUGGESTIONS: string[] = []; export type UseSpansFilterBarFieldsOptions = { /** Window the value suggestions are looked up in. */ timeRange: TraceQueryDiscoveryTimeRange; - withTextSearch?: boolean; + withTokenSearch?: boolean; }; /** @@ -44,7 +44,7 @@ export type UseSpansFilterBarFieldsOptions = { */ export function useSpansFilterBarFields({ timeRange, - withTextSearch = false, + withTokenSearch = false, }: UseSpansFilterBarFieldsOptions): FilterBarField[] { const client = useMastraClient(); const { data: capabilities } = useObservabilityCapabilities(); @@ -61,20 +61,22 @@ export function useSpansFilterBarFields({ return useMemo( () => [ FILTER_BAR_TIME_RANGE_FIELD, - ...(withTextSearch ? [TEXT_SEARCH_FIELD] : []), - ...createSpanFilterBarFields({ - withContextFields, - withTimeToFirstChunk, - withTimeToFirstToken, - withOutcomeFields, - withModelFields, - entityNames, - environments, - valueSuggestions: path => createTraceQueryValuesResolver(client, timeRange, 'spans', path), - }), + ...withTokenSearchFields( + createSpanFilterBarFields({ + withContextFields, + withTimeToFirstChunk, + withTimeToFirstToken, + withOutcomeFields, + withModelFields, + entityNames, + environments, + valueSuggestions: path => createTraceQueryValuesResolver(client, timeRange, 'spans', path), + }), + withTokenSearch, + ), ], [ - withTextSearch, + withTokenSearch, withContextFields, withTimeToFirstChunk, withTimeToFirstToken, @@ -89,8 +91,6 @@ export function useSpansFilterBarFields({ } export type UseSpansFilterBarOptions = { - textSearch?: string; - onTextSearchChange?: (value: string | undefined) => void; tokens: TraceFilterToken[]; groups: TraceFilterGroup[]; onFiltersChange: (tokens: TraceFilterToken[], groups: TraceFilterGroup[]) => void; @@ -100,13 +100,7 @@ export type UseSpansFilterBarOptions = { * The span filters as a filter bar value, and the handlers that write bar edits back. * The time range is a synthetic, always-present item; it never round-trips to tokens. */ -export function useSpansFilterBar({ - tokens, - groups, - onFiltersChange, - textSearch, - onTextSearchChange, -}: UseSpansFilterBarOptions): { +export function useSpansFilterBar({ tokens, groups, onFiltersChange }: UseSpansFilterBarOptions): { filterBarValue: FilterBarExpression; onFilterBarChange: (expression: FilterBarExpression) => void; /** Replaces any filter on `fieldId` with `is value`, e.g. from a list cell. */ @@ -118,27 +112,21 @@ export function useSpansFilterBar({ const groupsExpression = traceFiltersToFilterBarExpression([], groups); return { ...groupsExpression, - nodes: [FILTER_BAR_TIME_RANGE_ITEM, ...textSearchFilterItems(textSearch), ...items, ...groupsExpression.nodes], + nodes: [FILTER_BAR_TIME_RANGE_ITEM, ...items, ...groupsExpression.nodes], }; - }, [items, groups, textSearch]); + }, [items, groups]); const onFilterBarChange = useCallback( (expression: FilterBarExpression) => { const next = filterBarExpressionToTraceFilters({ ...expression, nodes: expression.nodes.filter( - node => - isFilterBarGroup(node) || - (node.fieldId !== FILTER_BAR_TIME_RANGE_FIELD_ID && node.fieldId !== TEXT_SEARCH_FIELD.id), + node => isFilterBarGroup(node) || node.fieldId !== FILTER_BAR_TIME_RANGE_FIELD_ID, ), }); onFiltersChange(next.tokens, next.groups); - const search = expression.nodes.find(node => !isFilterBarGroup(node) && node.fieldId === TEXT_SEARCH_FIELD.id); - const nextText = - search && !isFilterBarGroup(search) && typeof search.value === 'string' ? search.value : undefined; - if (nextText !== textSearch) onTextSearchChange?.(nextText); }, - [onFiltersChange, textSearch, onTextSearchChange], + [onFiltersChange], ); const onFilterByField = useCallback( @@ -148,10 +136,10 @@ export function useSpansFilterBar({ const groupNodes = filterBarValue.nodes.filter(isFilterBarGroup); onFilterBarChange({ ...filterBarValue, - nodes: [...textSearchFilterItems(textSearch), ...withoutField, item, ...groupNodes], + nodes: [...withoutField, item, ...groupNodes], }); }, - [items, filterBarValue, onFilterBarChange, textSearch], + [items, filterBarValue, onFilterBarChange], ); return { filterBarValue, onFilterBarChange, onFilterByField }; diff --git a/packages/playground-ui/src/domains/spans/span-filters.ts b/packages/playground-ui/src/domains/spans/span-filters.ts index 38612533d37..f6c622bc8d1 100644 --- a/packages/playground-ui/src/domains/spans/span-filters.ts +++ b/packages/playground-ui/src/domains/spans/span-filters.ts @@ -1,5 +1,6 @@ import { EntityType, SpanType } from '@mastra/core/observability'; import type { TraceQueryScalarPredicate } from '@mastra/core/storage'; +import { tokenSearchPredicate } from '../observability/lib/token-search-predicate'; import { isLegacyAnyValue, ROOT_ENTITY_TYPE_OPTIONS, @@ -260,8 +261,11 @@ export function createSpanFilterBarFields({ function tokenToSpanQueryPredicate( token: TraceFilterToken, allowedFieldIds: ReadonlySet, + withTokenSearch: boolean, ): TraceQueryScalarPredicate | undefined { const { fieldId } = token; + if (token.operatorId === 'hasAllTokens') + return withTokenSearch ? tokenSearchPredicate(fieldId, token.value) : undefined; if (!allowedFieldIds.has(fieldId)) return undefined; const operatorId = token.operatorId ?? 'is'; const isPresence = operatorId === 'exists' || operatorId === 'notExists'; @@ -295,12 +299,13 @@ function tokenToSpanQueryPredicate( function groupToSpanQueryPredicate( group: TraceFilterGroup, allowedFieldIds: ReadonlySet, + withTokenSearch: boolean, ): TraceQueryScalarPredicate | undefined { const args = group.nodes .map(node => isTraceFilterGroup(node) - ? groupToSpanQueryPredicate(node, allowedFieldIds) - : tokenToSpanQueryPredicate(node, allowedFieldIds), + ? groupToSpanQueryPredicate(node, allowedFieldIds, withTokenSearch) + : tokenToSpanQueryPredicate(node, allowedFieldIds, withTokenSearch), ) .filter((predicate): predicate is TraceQueryScalarPredicate => Boolean(predicate)); if (args.length === 0) return undefined; @@ -317,10 +322,16 @@ export function buildSpanQueryWhere( groups: TraceFilterGroup[], { withContextFields, + withTokenSearch = false, withOutcomeFields = false, withModelFields = false, ...support - }: StreamingTimingSupport & { withContextFields: boolean; withOutcomeFields?: boolean; withModelFields?: boolean }, + }: StreamingTimingSupport & { + withTokenSearch?: boolean; + withContextFields: boolean; + withOutcomeFields?: boolean; + withModelFields?: boolean; + }, ): TraceQueryScalarPredicate | undefined { const allowedFieldIds = withoutUnrecordedStreamingTimings( new Set([ @@ -332,8 +343,8 @@ export function buildSpanQueryWhere( support, ); const args = [ - ...tokens.map(token => tokenToSpanQueryPredicate(token, allowedFieldIds)), - ...groups.map(group => groupToSpanQueryPredicate(group, allowedFieldIds)), + ...tokens.map(token => tokenToSpanQueryPredicate(token, allowedFieldIds, withTokenSearch)), + ...groups.map(group => groupToSpanQueryPredicate(group, allowedFieldIds, withTokenSearch)), ].filter((predicate): predicate is TraceQueryScalarPredicate => Boolean(predicate)); return args.length ? { op: 'and', args } : undefined; } diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/fixtures/traces-explorer.ts b/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/fixtures/traces-explorer.ts index bafadc5af16..886d822edf9 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/fixtures/traces-explorer.ts +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/fixtures/traces-explorer.ts @@ -109,7 +109,11 @@ export const traceAggregateCapabilities: GetObservabilityCapabilitiesResponse = export const traceTextSearchCapabilities: GetObservabilityCapabilitiesResponse = { ...traceAggregateCapabilities, - capabilities: { ...traceAggregateCapabilities.capabilities, traceQueryTextSearch: true }, + capabilities: { + ...traceAggregateCapabilities.capabilities, + traceQueryTokenSearch: true, + traceAggregateTokenSearch: true, + }, }; const HOUR = 60 * 60 * 1000; diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-actions.test.ts b/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-actions.test.ts index fc8f18214ef..b41334ed6dc 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-actions.test.ts +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-actions.test.ts @@ -227,6 +227,18 @@ describe('applyDateRange', () => { }); describe('sanitizeTracesFilters', () => { + it.each(['all', 'input', 'output', 'error', 'inputPreview', 'outputPreview', 'errorPreview'])( + 'drops unsupported %s content chips and preserves supported chips', + field => { + const filters: TracesFilters = { + ...baseFilters, + tokens: [{ fieldId: `spans.${field}`, operatorId: 'hasAllTokens', value: 'needle' }], + }; + expect(sanitizeTracesFilters(filters, {}).tokens).toEqual([]); + expect(sanitizeTracesFilters(filters, { withTokenSearch: true })).toBe(filters); + }, + ); + describe('when the filters hold entries the query cannot run', () => { it('drops a running status, unsupported fields and root duration without support', () => { const filters: TracesFilters = { @@ -447,11 +459,3 @@ describe('buildTracesLegacyFilters', () => { }); }); }); - -describe('trace search with date presets', () => { - describe('when the user changes the time window', () => { - it('keeps the applied search', () => { - expect(applyDatePreset({ ...baseFilters, textSearch: 'needle' }, 'last-24h').textSearch).toBe('needle'); - }); - }); -}); diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-histogram.msw.test.tsx b/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-histogram.msw.test.tsx index 625281a3388..9c33de5f649 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-histogram.msw.test.tsx +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/__tests__/traces-explorer-histogram.msw.test.tsx @@ -72,7 +72,7 @@ const setHandlers = ({ const parsed = traceAggregateRequestSchema.safeParse(body); if (!parsed.success) return HttpResponse.json({ error: parsed.error.message }, { status: 400 }); try { - planTraceAggregate(parsed.data); + planTraceAggregate(parsed.data, { allowTokenSearch: capabilities.capabilities.traceAggregateTokenSearch }); } catch (error) { return HttpResponse.json({ error: String(error) }, { status: 400 }); } @@ -499,191 +499,142 @@ describe('TracesExplorer.Histogram', () => { expect(chart()).toBeNull(); }); }); - describe('when text search is supported', () => { - it('marks an invalid restored search with a validation warning', async () => { - setHandlers({ capabilities: traceTextSearchCapabilities }); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, textSearch: 'ab' } }); - expect(screen.getByRole('group', { name: 'Contains text ab' }).getAttribute('aria-invalid')).toBe('true'); - expect(screen.getByTitle('Enter between 3 and 256 characters to search')).toBeTruthy(); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - expect(chart()).not.toBeNull(); - }); - - it('rejects an oversized edit without changing the applied search', async () => { - setHandlers({ capabilities: traceTextSearchCapabilities }); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, textSearch: 'needle' } }); - fireEvent.click(screen.getByRole('combobox', { name: 'Value: needle' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'x'.repeat(257) } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - expect(await screen.findByText('Enter between 3 and 256 characters to search')).toBeTruthy(); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).toHaveProperty('textSearch', 'needle'); - }); - - it('applies an edited search without losing other filters', async () => { + describe('indexed content filters', () => { + it.each(['traceQueryTokenSearch', 'traceAggregateTokenSearch'] as const)( + 'disables search for the whole page without %s', + async capability => { + setHandlers({ + capabilities: { + ...traceTextSearchCapabilities, + capabilities: { ...traceTextSearchCapabilities.capabilities, [capability]: false }, + }, + }); + await renderExplorer({ + initialFilters: { + ...DEFAULT_TRACES_FILTERS, + tokens: [{ fieldId: 'spans.all', operatorId: 'hasAllTokens', value: 'needle' }], + }, + }); + expect(tokenTerms(onTraceQuery.mock.calls.at(-1)?.[0])).toEqual([]); + expect(tokenTerms(onAggregate.mock.calls.at(-1)?.[0])).toEqual([]); + expect(chart()).not.toBeNull(); + const input = screen.getByRole('combobox', { name: 'Add filter' }); + fireEvent.focus(input); + fireEvent.change(input, { target: { value: 'Any span content' } }); + expect(screen.queryByRole('option', { name: 'Any span content' })).toBeNull(); + }, + ); + it.each([ + ['all', 'Any span content'], + ['input', 'Span input'], + ['output', 'Span output'], + ['error', 'Span error'], + ['inputPreview', 'Span input preview'], + ['outputPreview', 'Span output preview'], + ['errorPreview', 'Span error preview'], + ] as const)('uses the same %s search for lists and histograms', async (field, label) => { setHandlers({ capabilities: traceTextSearchCapabilities }); await renderExplorer({ - initialFilters: { ...DEFAULT_TRACES_FILTERS, tokens: FAILED_ONLY, textSearch: 'needle' }, + initialFilters: { + ...DEFAULT_TRACES_FILTERS, + tokens: [{ fieldId: `spans.${field}`, operatorId: 'hasAllTokens', value: 'id' }], + }, }); - const originalWhere = onTraceQuery.mock.calls.at(-1)?.[0].where; - fireEvent.click(screen.getByRole('combobox', { name: 'Value: needle' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'updated' } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - await waitFor(() => expect(onTraceQuery.mock.calls.at(-1)?.[0]).toHaveProperty('textSearch', 'updated')); - expect(onTraceQuery.mock.calls.at(-1)?.[0].where).toEqual(originalWhere); + expect(onTraceQuery.mock.calls.at(-1)?.[0].where).toEqual({ + op: 'and', + args: [{ spans: { some: { op: 'hasAllTokens', left: { path: field }, right: { literal: 'id' } } } }], + }); + expect(screen.getByRole('button', { name: `Remove ${label} filter` })).toBeTruthy(); + expect(screen.getByText('contains words')).toBeTruthy(); + expect(onAggregate.mock.calls.at(-1)?.[0].where).toEqual(onTraceQuery.mock.calls.at(-1)?.[0].where); }); - - it('does not offer an existing search field when editing another chip', async () => { + it('requires input and output conditions on the same span', async () => { setHandlers({ capabilities: traceTextSearchCapabilities }); await renderExplorer({ - initialFilters: { ...DEFAULT_TRACES_FILTERS, tokens: FAILED_ONLY, textSearch: 'needle' }, + initialFilters: { + ...DEFAULT_TRACES_FILTERS, + tokens: [ + { fieldId: 'spans.input', operatorId: 'hasAllTokens', value: 'payment' }, + { fieldId: 'spans.output', operatorId: 'hasAllTokens', value: 'declined' }, + ], + }, + }); + expect(onTraceQuery.mock.calls.at(-1)?.[0].where).toEqual({ + op: 'and', + args: [ + { + spans: { + some: { + op: 'and', + args: [ + { op: 'hasAllTokens', left: { path: 'input' }, right: { literal: 'payment' } }, + { op: 'hasAllTokens', left: { path: 'output' }, right: { literal: 'declined' } }, + ], + }, + }, + }, + ], }); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - await screen.findByRole('option', { name: 'Trace ID' }); - expect(screen.queryByRole('option', { name: 'Contains text' })).toBeNull(); }); - - it('preserves an editable empty search after changing the field', async () => { - setHandlers({ - capabilities: traceTextSearchCapabilities, - }); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, tokens: FAILED_ONLY } }); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - expect(await screen.findByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - }); - - it('applies text entered into an empty search chip', async () => { - setHandlers({ - capabilities: traceTextSearchCapabilities, - }); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, tokens: FAILED_ONLY } }); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - expect(await screen.findByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - fireEvent.click(screen.getByRole('combobox', { name: 'Value: …' })); - const editor = screen.getByPlaceholderText('Type a value…'); - fireEvent.change(editor, { target: { value: 'needle' } }); - fireEvent.keyDown(editor, { key: 'Enter' }); - await waitFor(() => - expect(onTraceQuery).toHaveBeenLastCalledWith(expect.objectContaining({ textSearch: 'needle' })), - ); - }); - - it('removes an empty search chip', async () => { - setHandlers({ - capabilities: traceTextSearchCapabilities, - }); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, tokens: FAILED_ONLY } }); - fireEvent.click(screen.getByRole('combobox', { name: 'Field: Status' })); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - expect(await screen.findByRole('button', { name: 'Remove Contains text filter' })).toBeTruthy(); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - fireEvent.click(screen.getByRole('button', { name: 'Remove Contains text filter' })); - await waitFor(() => expect(screen.queryByRole('button', { name: 'Remove Contains text filter' })).toBeNull()); - }); - - it('applies the search to the list on commit', async () => { - setHandlers({ - capabilities: traceTextSearchCapabilities, - }); - await renderExplorer(); - const search = screen.getByRole('combobox', { name: 'Add filter' }); - fireEvent.focus(search); - fireEvent.change(search, { target: { value: 'Contains text' } }); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - onAggregate.mockClear(); - fireEvent.change(search, { target: { value: 'needle' } }); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - fireEvent.keyDown(search, { key: 'Enter' }); - await waitFor(() => - expect(onTraceQuery).toHaveBeenLastCalledWith(expect.objectContaining({ textSearch: 'needle' })), - ); - }); - - it('suppresses the histogram after search is applied', async () => { - setHandlers({ - capabilities: traceTextSearchCapabilities, - }); + it('keeps Any Content search and histogram filters in sync through removal', async () => { + setHandlers({ capabilities: traceTextSearchCapabilities }); const result = await renderExplorer(); - const search = screen.getByRole('combobox', { name: 'Add filter' }); - fireEvent.focus(search); - fireEvent.change(search, { target: { value: 'Contains text' } }); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - onAggregate.mockClear(); - fireEvent.change(search, { target: { value: 'needle' } }); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - fireEvent.keyDown(search, { key: 'Enter' }); - await waitFor(() => - expect(onTraceQuery).toHaveBeenLastCalledWith(expect.objectContaining({ textSearch: 'needle' })), - ); - await settle(result.queryClient); - expect(chart()).toBeNull(); - expect(onAggregate).not.toHaveBeenCalled(); - expect(onTraceQuery.mock.calls.at(-1)?.[0].where).toBeUndefined(); - }); - - it('restores the histogram when search is removed', async () => { - setHandlers({ capabilities: traceTextSearchCapabilities }); - const result = await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, textSearch: 'needle' } }); - fireEvent.click(screen.getByRole('button', { name: 'Remove Contains text filter' })); - await waitFor(() => expect(chart()).not.toBeNull()); - await settle(result.queryClient); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - }); - }); - - describe('when text search is not supported', () => { - it('does not expose a search control', async () => { - setHandlers(); - await renderExplorer(); const input = screen.getByRole('combobox', { name: 'Add filter' }); fireEvent.focus(input); - fireEvent.change(input, { target: { value: 'Contains text' } }); - expect(screen.queryByRole('option', { name: 'Contains text' })).toBeNull(); - }); - }); - - describe('when search is restored on an unsupported backend', () => { - it('keeps the ordinary list and histogram available', async () => { - setHandlers(); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, textSearch: 'needle' } }); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - expect(chart()).not.toBeNull(); - }); - }); - - describe('when search is too short after normalization', () => { - it('explains the minimum without sending an invalid query', async () => { - setHandlers({ - capabilities: traceTextSearchCapabilities, - }); - const result = await renderExplorer(); - const search = screen.getByRole('combobox', { name: 'Add filter' }); - fireEvent.focus(search); - fireEvent.change(search, { target: { value: 'Contains text' } }); - fireEvent.click(await screen.findByRole('option', { name: 'Contains text' })); - fireEvent.change(search, { target: { value: ' ab ' } }); - fireEvent.keyDown(search, { key: 'Enter' }); - expect(await screen.findByText('Enter between 3 and 256 characters to search')).toBeTruthy(); - fireEvent.keyDown(search, { key: 'Escape' }); + fireEvent.change(input, { target: { value: 'Any span content' } }); + fireEvent.click(await screen.findByRole('option', { name: 'Any span content' })); + onAggregate.mockClear(); + fireEvent.change(input, { target: { value: 'ok' } }); + fireEvent.keyDown(input, { key: 'Enter' }); + await waitFor(() => expect(tokenTerms(onTraceQuery.mock.calls.at(-1)?.[0])).toEqual(['ok'])); + fireEvent.keyDown(input, { key: 'Escape' }); await settle(result.queryClient); - expect(onTraceQuery.mock.calls.at(-1)?.[0]).not.toHaveProperty('textSearch'); - expect(screen.getByRole('region', { name: 'Traces over time', hidden: true })).toBeTruthy(); + await waitFor(() => expect(chart()).not.toBeNull()); + expect(onAggregate.mock.calls.at(-1)?.[0].where).toEqual(onTraceQuery.mock.calls.at(-1)?.[0].where); + fireEvent.click(screen.getByRole('button', { name: 'Remove Any span content filter' })); + await waitFor(() => expect(chart()).not.toBeNull()); }); - }); - - describe('when an indexed search is restored', () => { - it('normalizes the term and suppresses the initial histogram request', async () => { + it.each([ + ['all', 'Any span content'], + ['input', 'Span input'], + ['output', 'Span output'], + ['error', 'Span error'], + ['inputPreview', 'Span input preview'], + ['outputPreview', 'Span output preview'], + ['errorPreview', 'Span error preview'], + ] as const)('does not send %s token predicates without the trace capability', async field => { setHandlers({ - capabilities: traceTextSearchCapabilities, + capabilities: { + ...traceAggregateCapabilities, + capabilities: { ...traceAggregateCapabilities.capabilities, spanQueryTokenSearch: true }, + }, }); - await renderExplorer({ initialFilters: { ...DEFAULT_TRACES_FILTERS, textSearch: ' NEEDLE ' } }); - expect(onTraceQuery).toHaveBeenLastCalledWith(expect.objectContaining({ textSearch: 'needle' })); - expect(onAggregate).not.toHaveBeenCalled(); + await renderExplorer({ + initialFilters: { + ...DEFAULT_TRACES_FILTERS, + tokens: [{ fieldId: `spans.${field}`, operatorId: 'hasAllTokens', value: 'needle' }], + }, + }); + expect(tokenTerms(onTraceQuery.mock.calls.at(-1)?.[0])).toEqual([]); + expect(chart()).not.toBeNull(); + const input = screen.getByRole('combobox', { name: 'Add filter' }); + fireEvent.focus(input); + fireEvent.change(input, { target: { value: 'Any span content' } }); + expect(screen.queryByRole('option', { name: 'Any span content' })).toBeNull(); }); }); }); + +function tokenTerms(value: unknown): unknown[] { + if (!value || typeof value !== 'object') return []; + if ( + 'op' in value && + value.op === 'hasAllTokens' && + 'right' in value && + value.right && + typeof value.right === 'object' && + 'literal' in value.right + ) + return [value.right.literal]; + return Object.values(value).flatMap(child => (Array.isArray(child) ? child.flatMap(tokenTerms) : tokenTerms(child))); +} diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-actions.ts b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-actions.ts index 0b60e274646..1f6257f26ee 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-actions.ts +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-actions.ts @@ -31,7 +31,6 @@ export type TracesFilters = { dateFrom?: Date; /** Only read when `datePreset` is `custom`. */ dateTo?: Date; - textSearch?: string; tokens: TraceFilterToken[]; groups: TraceFilterGroup[]; }; @@ -113,9 +112,7 @@ export const applyFilterTokens = ( /** Switching to `custom` keeps the current dates so the picker opens on them; any other preset drops them. */ export const applyDatePreset = (filters: TracesFilters, datePreset: TraceDatePreset): TracesFilters => - datePreset === 'custom' - ? { ...filters, datePreset } - : { datePreset, textSearch: filters.textSearch, tokens: filters.tokens, groups: filters.groups }; + datePreset === 'custom' ? { ...filters, datePreset } : { datePreset, tokens: filters.tokens, groups: filters.groups }; // The picker can report a date right after switching away from `custom`; those are ignored. export const applyDate = (filters: TracesFilters, date: Date | undefined, end: 'from' | 'to'): TracesFilters => { @@ -142,7 +139,10 @@ const isQueryableToken = (token: TraceFilterToken, unqueryableFieldIds: Readonly */ export const sanitizeTracesFilters = (filters: TracesFilters, support: TraceQueryFieldSupport): TracesFilters => { const unqueryableFieldIds = traceQueryUnqueryableFieldIds(support); - const tokens = filters.tokens.filter(token => isQueryableToken(token, unqueryableFieldIds)); + const tokens = filters.tokens.filter( + token => + isQueryableToken(token, unqueryableFieldIds) && (support.withTokenSearch || token.operatorId !== 'hasAllTokens'), + ); return tokens.length === filters.tokens.length ? filters : { ...filters, tokens }; }; @@ -189,6 +189,7 @@ export const buildTracesQueryRequest = ({ tokens: filters.tokens, groups: filters.groups, excludedFieldIds: traceQueryUnqueryableFieldIds(support), + withTokenSearch: support.withTokenSearch, now, }); diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-context.ts b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-context.ts index 85e9d094d39..22ab41baf19 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-context.ts +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-context.ts @@ -33,7 +33,7 @@ export type TracesConfigContextValue = { scopedFieldIds: ReadonlySet; hiddenFieldIds: readonly string[]; withQueryTrace: boolean; - withTextSearch: boolean; + withTokenSearch: boolean; withFeedback: boolean; feedbackOptions?: FeedbackOptions; /** The span query API is on, so the host can offer a spans view next to the traces list. */ @@ -64,7 +64,6 @@ export type TracesConfigContextValue = { export type TracesFiltersActions = { /** Replaces the filter tokens and groups. The scope tokens are always kept. */ setFilterTokens: (tokens: TracesFilters['tokens'], groups: TracesFilters['groups']) => void; - setTextSearch: (value: string | undefined) => void; setDatePreset: (preset: TraceDatePreset) => void; setDate: (value: Date | undefined, end: 'from' | 'to') => void; setDateRange: (from: Date | undefined, to: Date | undefined) => void; @@ -77,8 +76,7 @@ export type TracesFiltersActions = { export type TracesFiltersContextValue = TracesFiltersActions & { /** The host's filters with the entries this server can't query dropped. */ filters: TracesFilters; - /** Normalized search accepted by the query API; raw text stays in filters. */ - textSearch?: string; + hasTokenSearch: boolean; dateFrom?: Date; dateTo?: Date; filtersApplied: boolean; diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-histogram.tsx b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-histogram.tsx index 15f62b20842..93fec5069c2 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-histogram.tsx +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-histogram.tsx @@ -27,12 +27,13 @@ export function TracesExplorerHistogram() { const { rootSource, withQueryTrace, + withTokenSearch, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, withOutcomeFields, } = useTracesConfig(); - const { filters, textSearch, dateFrom, dateTo, runningSelected, zoomDateRange } = useTracesFilters(); + const { filters, dateFrom, dateTo, runningSelected, zoomDateRange } = useTracesFilters(); const aggregateAvailable = useTraceAggregateAvailable(); const selectionKey = JSON.stringify( @@ -40,6 +41,7 @@ export function TracesExplorerHistogram() { filters, dateFrom, dateTo, + withTokenSearch, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, @@ -55,6 +57,7 @@ export function TracesExplorerHistogram() { filters, dateFrom, dateTo, + withTokenSearch, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, @@ -69,10 +72,19 @@ export function TracesExplorerHistogram() { // No groupBy means a single group; the default limit would multiply past the server's row cap. limit: 1, }; - }, [filters, dateFrom, dateTo, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, withOutcomeFields, now]); + }, [ + filters, + dateFrom, + dateTo, + withRootDuration, + withTimeToFirstChunk, + withTimeToFirstToken, + withOutcomeFields, + withTokenSearch, + now, + ]); const hidden = - !!textSearch || rootSource === 'aggregated' || !withQueryTrace || !aggregateAvailable.enabled || diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-list-provider.tsx b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-list-provider.tsx index 9864c72d3ea..3bb6e90b335 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-list-provider.tsx +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-list-provider.tsx @@ -31,6 +31,7 @@ export const TracesListProvider = memo(function TracesListProvider({ const { rootSource, withQueryTrace, + withTokenSearch, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, @@ -40,7 +41,7 @@ export const TracesListProvider = memo(function TracesListProvider({ withDeltaPolling, isCapabilitiesLoading, } = useTracesConfig(); - const { filters, textSearch, dateFrom, dateTo } = useTracesFilters(); + const { filters, hasTokenSearch, dateFrom, dateTo } = useTracesFilters(); const { displayedPreferences } = useTraceUsageColumns(); // A TTFC/TTFT sort the store can't run, or on a column that isn't shown, lists newest first instead. // The host keeps its raw value, like filters the server can't query. @@ -55,24 +56,27 @@ export const TracesListProvider = memo(function TracesListProvider({ const sort = sortable ? hostSort : DEFAULT_TRACES_SORT; const list = useTracesListSource({ rolling: !dateTo, - query: now => ({ - ...buildTracesQueryRequest({ + query: now => { + const query = buildTracesQueryRequest({ filters, dateFrom, dateTo, + withTokenSearch, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, withOutcomeFields, now, - }), - ...(rootSource === 'aggregated' ? { rootSource } : {}), - ...(textSearch ? { textSearch } : {}), - }), + }); + return { + ...query, + ...(rootSource === 'aggregated' ? { rootSource } : {}), + }; + }, orderBy: [sort], // An explicit projection must never fall back to the legacy list endpoint. withQueryTrace: rootSource === 'aggregated' || withQueryTrace, - withDeltaPolling: !textSearch && rootSource !== 'aggregated' && withDeltaPolling, + withDeltaPolling: !hasTokenSearch && rootSource !== 'aggregated' && withDeltaPolling, enabled: !isCapabilitiesLoading, legacyFilters: buildTracesLegacyFilters({ filters, dateFrom, dateTo }), }); diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-root.tsx b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-root.tsx index 605af37d46e..deada21af9d 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-root.tsx +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/traces-explorer-root.tsx @@ -46,7 +46,7 @@ import { useTraceQueryDiscoveryAvailable, useTraceQueryRootDurationAvailable, } from '@/domains/capabilities'; -import { effectiveTextSearch } from '@/domains/observability/lib/text-search'; +import { hasTokenSearchFilter } from '@/domains/observability/lib/token-search-predicate'; import { rangeBeforeZoom, rememberZoom } from '@/domains/observability/lib/zoom-memory'; import type { ZoomMemory } from '@/domains/observability/lib/zoom-memory'; @@ -123,19 +123,20 @@ export function TracesExplorerRoot({ withTimeToFirstToken && (capabilities?.capabilities.traceQueryTimeToFirstTokenSort ?? false); const withOutcomeFields = withQueryTrace && (capabilities?.capabilities.traceQueryOutcomeFields ?? false); - const withTextSearch = withQueryTrace && (capabilities?.capabilities.traceQueryTextSearch ?? false); + const withTokenSearch = + withQueryTrace && + !!(capabilities?.capabilities.traceQueryTokenSearch && capabilities.capabilities.traceAggregateTokenSearch); // Entries the server can't query are ignored, never written back: the host keeps its raw value. const filters = useMemo(() => { - const sanitized = sanitizeTracesFilters(rawFilters, { + return sanitizeTracesFilters(rawFilters, { + withTokenSearch, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, withOutcomeFields, }); - if (withTextSearch || sanitized.textSearch === undefined) return sanitized; - return { ...sanitized, textSearch: undefined }; - }, [rawFilters, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, withOutcomeFields, withTextSearch]); + }, [rawFilters, withRootDuration, withTimeToFirstChunk, withTimeToFirstToken, withOutcomeFields, withTokenSearch]); const isScoped = !!scope; const scopedFieldIds = isScoped ? SCOPED_FIELD_IDS : NO_FIELD_IDS; @@ -205,10 +206,6 @@ export function TracesExplorerRoot({ const scopeTokens = base.tokens.filter(token => scoped.has(token.fieldId)); updateFilters(applyFilterTokens(base, [...scopeTokens, ...tokens], groups)); }, - setTextSearch: value => { - if (latest.current.filters.textSearch === value) return; - updateFilters({ ...latest.current.filters, textSearch: value }); - }, setDatePreset: preset => pickRange(applyDatePreset(latest.current.filters, preset)), setDate: (value, end) => pickRange(applyDate(latest.current.filters, value, end)), setDateRange: (from, to) => pickRange(applyDateRange(latest.current.filters, from, to)), @@ -222,7 +219,6 @@ export function TracesExplorerRoot({ const before = rangeBeforeZoom(zoomMemory.current, base); zoomMemory.current = undefined; updateFilters({ - textSearch: base.textSearch, tokens: base.tokens, groups: base.groups, ...(before ?? { datePreset: defaultPreset }), @@ -252,7 +248,7 @@ export function TracesExplorerRoot({ scopedFieldIds, hiddenFieldIds, withQueryTrace, - withTextSearch, + withTokenSearch, withFeedback, feedbackOptions: hasFeedbackOptions ? { contextMode, feedbackUserId, allowDelete, allowReview } : undefined, withSpanQuery, @@ -275,7 +271,7 @@ export function TracesExplorerRoot({ scopedFieldIds, hiddenFieldIds, withQueryTrace, - withTextSearch, + withTokenSearch, withFeedback, hasFeedbackOptions, contextMode, @@ -298,22 +294,31 @@ export function TracesExplorerRoot({ ], ); - const textSearch = effectiveTextSearch(filters.textSearch); - const contentFiltersApplied = !!textSearch || filters.tokens.length > 0 || filters.groups.length > 0; + const tokenSearchApplied = withTokenSearch && [...filters.tokens, ...filters.groups].some(hasTokenSearchFilter); + const contentFiltersApplied = filters.tokens.length > 0 || filters.groups.length > 0; const filtersApplied = contentFiltersApplied || filters.datePreset !== initialFilters.datePreset || !!dateTo; const runningSelected = useMemo(() => selectsRunningStatus(rawFilters), [rawFilters]); const filtersValue = useMemo( () => ({ ...filtersActions, filters, - textSearch, + hasTokenSearch: tokenSearchApplied, dateFrom, dateTo, filtersApplied, contentFiltersApplied, runningSelected, }), - [filtersActions, filters, textSearch, dateFrom, dateTo, filtersApplied, contentFiltersApplied, runningSelected], + [ + filtersActions, + filters, + tokenSearchApplied, + dateFrom, + dateTo, + filtersApplied, + contentFiltersApplied, + runningSelected, + ], ); // Not memoized: the selection consumers (Layout, List, Panel) also re-render on filter and list diff --git a/packages/playground-ui/src/domains/traces/components/traces-explorer/use-traces-filter-bar.ts b/packages/playground-ui/src/domains/traces/components/traces-explorer/use-traces-filter-bar.ts index 9d643bfdd1e..7a44db0618d 100644 --- a/packages/playground-ui/src/domains/traces/components/traces-explorer/use-traces-filter-bar.ts +++ b/packages/playground-ui/src/domains/traces/components/traces-explorer/use-traces-filter-bar.ts @@ -12,7 +12,7 @@ import type { TraceQueryRelatedScope } from '../../trace-query-filters'; import { getSelectedEntityOption } from './traces-explorer-actions'; import { useTracesConfig, useTracesFilters } from './traces-explorer-context'; import { useTracesDiscovery } from './use-traces-discovery'; -import { TEXT_SEARCH_FIELD, textSearchFilterItems } from '@/domains/observability/lib/text-search-filter'; +import { withTokenSearchFields } from '@/domains/observability/lib/token-search-predicate'; import { isFilterBarGroup } from '@/ds/components/FilterBar'; import type { FilterBarExpression, FilterBarField, FilterBarItem } from '@/ds/components/FilterBar'; import { @@ -27,7 +27,7 @@ const NO_SUGGESTIONS: string[] = []; export function useTracesFilterBarFields(): FilterBarField[] { const { hiddenFieldIds, - withTextSearch, + withTokenSearch, withQueryTrace, withRootDuration, withTimeToFirstChunk, @@ -48,23 +48,26 @@ export function useTracesFilterBarFields(): FilterBarField[] { return useMemo( () => [ FILTER_BAR_TIME_RANGE_FIELD, - ...(withTextSearch ? [TEXT_SEARCH_FIELD] : []), - ...createTraceFilterBarFields({ - availableRootEntityNames: rootEntityNames, - availableEnvironments: environments, - hiddenFieldIds, - metadataFields, - canonicalTraceFields: canonicalFields, - valueSuggestions: withQueryTrace - ? (relatedScope: TraceQueryRelatedScope | 'trace', path: string) => - createTraceQueryValuesResolver(client, discoveryTimeRange, relatedScope, path) - : undefined, - withQueryTrace, - withRootDuration, - withTimeToFirstChunk, - withTimeToFirstToken, - withOutcomeFields, - }), + ...withTokenSearchFields( + createTraceFilterBarFields({ + availableRootEntityNames: rootEntityNames, + availableEnvironments: environments, + hiddenFieldIds, + metadataFields, + canonicalTraceFields: canonicalFields, + valueSuggestions: withQueryTrace + ? (relatedScope: TraceQueryRelatedScope | 'trace', path: string) => + createTraceQueryValuesResolver(client, discoveryTimeRange, relatedScope, path) + : undefined, + withQueryTrace, + withRootDuration, + withTimeToFirstChunk, + withTimeToFirstToken, + withOutcomeFields, + }), + withTokenSearch, + 'spans.', + ), ], [ rootEntityNames, @@ -72,7 +75,7 @@ export function useTracesFilterBarFields(): FilterBarField[] { hiddenFieldIds, metadataFields, canonicalFields, - withTextSearch, + withTokenSearch, withQueryTrace, withRootDuration, withTimeToFirstChunk, @@ -89,13 +92,10 @@ export function useTracesFilterBarFields(): FilterBarField[] { * Scope items never show up in the bar; the explorer keeps them on every edit. */ export function useTracesFilterBar() { - const { scopedFieldIds, withTextSearch } = useTracesConfig(); - const { filters, setFilterTokens, setTextSearch } = useTracesFilters(); + const { scopedFieldIds } = useTracesConfig(); + const { filters, setFilterTokens } = useTracesFilters(); - const items = [ - ...textSearchFilterItems(withTextSearch ? filters.textSearch : undefined), - ...traceTokensToFilterBarItems(filters.tokens).filter(item => !scopedFieldIds.has(item.fieldId)), - ]; + const items = [...traceTokensToFilterBarItems(filters.tokens).filter(item => !scopedFieldIds.has(item.fieldId))]; // The time range is a synthetic, always-present item so it takes part in keyboard // navigation; it never round-trips to filter tokens. Expression mode so root-level AND/OR // groups render as "Advanced filter" chips. @@ -110,17 +110,9 @@ export function useTracesFilterBar() { const onFilterBarChange = (expression: FilterBarExpression) => { const { tokens, groups } = filterBarExpressionToTraceFilters({ ...expression, - nodes: expression.nodes.filter( - node => - isFilterBarGroup(node) || - (node.fieldId !== FILTER_BAR_TIME_RANGE_FIELD_ID && node.fieldId !== TEXT_SEARCH_FIELD.id), - ), + nodes: expression.nodes.filter(node => isFilterBarGroup(node) || node.fieldId !== FILTER_BAR_TIME_RANGE_FIELD_ID), }); - const search = expression.nodes.find(node => !isFilterBarGroup(node) && node.fieldId === TEXT_SEARCH_FIELD.id); - const textSearch = - search && !isFilterBarGroup(search) && typeof search.value === 'string' ? search.value : undefined; setFilterTokens(tokens, groups); - if (withTextSearch && textSearch !== filters.textSearch) setTextSearch(textSearch); }; return { diff --git a/packages/playground-ui/src/domains/traces/hooks/__tests__/use-traces-list-source.msw.test.tsx b/packages/playground-ui/src/domains/traces/hooks/__tests__/use-traces-list-source.msw.test.tsx index 53eeedf1088..8077fb9a9b2 100644 --- a/packages/playground-ui/src/domains/traces/hooks/__tests__/use-traces-list-source.msw.test.tsx +++ b/packages/playground-ui/src/domains/traces/hooks/__tests__/use-traces-list-source.msw.test.tsx @@ -237,17 +237,32 @@ describe('useTracesListSource', () => { vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval', 'Date'], shouldAdvanceTime: true }); vi.setSystemTime(new Date('2026-09-01T10:00:00.000Z')); const { rerender } = renderHook( - ({ textSearch }: { textSearch?: string }) => + ({ searchTerm }: { searchTerm?: string }) => useTracesListSource({ - query: now => ({ ...query(now), ...(textSearch ? { textSearch } : {}) }), - withDeltaPolling: !textSearch, + query: now => ({ + ...query(now), + ...(searchTerm + ? { + where: { + spans: { + some: { + op: 'hasAllTokens' as const, + left: { path: 'all' as const }, + right: { literal: searchTerm }, + }, + }, + }, + } + : {}), + }), + withDeltaPolling: !searchTerm, }), - { wrapper: Wrapper, initialProps: { textSearch: undefined } }, + { wrapper: Wrapper, initialProps: { searchTerm: undefined } }, ); await waitFor(() => expect(requests.listRequests).toHaveLength(1)); await waitFor(() => expect(requests.deltaRequests).toHaveLength(1)); vi.setSystemTime(new Date('2026-09-01T12:00:00.000Z')); - rerender({ textSearch: 'needle' }); + rerender({ searchTerm: 'needle' }); await waitFor(() => expect(requests.listRequests).toHaveLength(2)); expect(Date.parse(requests.listRequests[1]?.timeRange.to ?? '')).toBeGreaterThanOrEqual( Date.parse('2026-09-01T12:00:00.000Z'), diff --git a/packages/playground-ui/src/domains/traces/trace-filters.test.ts b/packages/playground-ui/src/domains/traces/trace-filters.test.ts index 77504f4850a..2896402ea04 100644 --- a/packages/playground-ui/src/domains/traces/trace-filters.test.ts +++ b/packages/playground-ui/src/domains/traces/trace-filters.test.ts @@ -87,6 +87,7 @@ describe('TRACE_FILTER_BAR_OPERATORS', () => { lte: 'at most', matches: 'matches', notMatches: 'does not match', + hasAllTokens: 'contains words', }); }); }); @@ -1049,3 +1050,16 @@ describe('filterBarExpressionToTraceFilters', () => { }); }); }); + +describe('content search URL state', () => { + it('preserves the error word operator through a shared URL', () => { + const tokens = getTracePropertyFilterTokens( + new URLSearchParams('filterSpanError=timeout&filterSpanError.op=hasAllTokens'), + ); + expect(tokens).toEqual([{ fieldId: 'spans.error', operatorId: 'hasAllTokens', value: 'timeout' }]); + const params = new URLSearchParams(); + applyTracePropertyFilterTokens(params, tokens); + expect(params.get('filterSpanError')).toBe('timeout'); + expect(params.get('filterSpanError.op')).toBe('hasAllTokens'); + }); +}); diff --git a/packages/playground-ui/src/domains/traces/trace-filters.ts b/packages/playground-ui/src/domains/traces/trace-filters.ts index cab6c1aef54..a31dacde9ff 100644 --- a/packages/playground-ui/src/domains/traces/trace-filters.ts +++ b/packages/playground-ui/src/domains/traces/trace-filters.ts @@ -172,6 +172,12 @@ export const TRACE_PROPERTY_FILTER_PARAM_BY_FIELD = { 'spans.timeToFirstChunkMs': 'filterSpanTimeToFirstChunkMs', 'spans.timeToFirstTokenMs': 'filterSpanTimeToFirstTokenMs', 'spans.error': 'filterSpanError', + 'spans.input': 'filterSpanInput', + 'spans.output': 'filterSpanOutput', + 'spans.inputPreview': 'filterSpanInputPreview', + 'spans.outputPreview': 'filterSpanOutputPreview', + 'spans.errorPreview': 'filterSpanErrorPreview', + 'spans.all': 'filterSpanAll', 'scores.scorerId': 'filterScorerId', 'scores.score': 'filterScore', 'feedback.feedbackType': 'filterFeedbackType', @@ -200,7 +206,7 @@ export const traceFilterTokenOperator = (token: TraceFilterToken): TraceFilterOp /** The legacy pick-multi neutral value. A text-match literal `Any` is a real word, not the sentinel. */ export const isLegacyAnyValue = (value: unknown, operatorId: TraceFilterOperatorId): boolean => - value === 'Any' && operatorId !== 'matches' && operatorId !== 'notMatches'; + value === 'Any' && operatorId !== 'matches' && operatorId !== 'notMatches' && operatorId !== 'hasAllTokens'; const readTraceFilterOperator = (searchParams: URLSearchParams, valueParam: string) => { const raw = searchParams.get(traceFilterOperatorParam(valueParam)); @@ -298,6 +304,7 @@ export const TRACE_FILTER_BAR_OPERATORS: (FilterBarOperator & { id: TraceFilterO { id: 'lte', label: 'at most' }, { id: 'matches', label: 'matches', freeText: true }, { id: 'notMatches', label: 'does not match', freeText: true }, + { id: 'hasAllTokens', label: 'contains words', freeText: true }, ]; export const TRACE_STRING_OPERATORS: TraceFilterOperatorId[] = ['is', 'isNot', 'in', 'notIn', 'exists', 'notExists']; @@ -413,6 +420,7 @@ const TRACE_FILTER_BAR_FIELD_ICONS: Record = { /** Which optional trace query fields the server declares support for. */ export type TraceQueryFieldSupport = { + withTokenSearch?: boolean; /** Root `durationMs`, declared by `traceQueryRootDuration`. */ withRootDuration?: boolean; /** Root and span `timeToFirstChunkMs`, declared by `traceQueryTimeToFirstChunk`. */ @@ -780,10 +788,9 @@ export function getTracePropertyFilterTokens(searchParams: URLSearchParams): Tra const operatorId = readTraceFilterOperator(searchParams, paramName); const raw = searchParams.getAll(paramName); - // Presence-only fields can't match a value; a hand-edited URL that gives - // them one would show a chip for a filter that is never applied. A pending - // chip (empty value, no operator yet) must still survive the round-trip. - if (TRACE_FILTER_BAR_PRESENCE_FIELD_IDS.has(fieldId)) { + // Error supports presence and gated word search. Other value operators are + // invalid; retain pending chips so users can finish selecting an operator. + if (TRACE_FILTER_BAR_PRESENCE_FIELD_IDS.has(fieldId) && operatorId !== 'hasAllTokens') { if (operatorId ? !isPresenceOperator(operatorId) : Boolean(raw[0])) continue; } diff --git a/packages/playground-ui/src/domains/traces/trace-query-filters.ts b/packages/playground-ui/src/domains/traces/trace-query-filters.ts index f1c0d2d06d4..c23c294a27b 100644 --- a/packages/playground-ui/src/domains/traces/trace-query-filters.ts +++ b/packages/playground-ui/src/domains/traces/trace-query-filters.ts @@ -1,5 +1,6 @@ import type { QueryTracesInput } from '@mastra/client-js'; import type { TraceQueryPredicate, TraceQueryScalarPredicate } from '@mastra/core/storage'; +import { tokenSearchPredicate } from '../observability/lib/token-search-predicate'; import { isLegacyAnyValue } from './trace-filters'; import type { buildTraceListFilters, TraceStatusFilter } from './trace-filters'; import type { PropertyFilterToken } from '@/ds/components/PropertyFilter/types'; @@ -27,6 +28,7 @@ export const TRACE_FILTER_OPERATOR_IDS = [ 'lte', 'matches', 'notMatches', + 'hasAllTokens', ] as const; export type TraceFilterOperatorId = (typeof TRACE_FILTER_OPERATOR_IDS)[number]; @@ -61,6 +63,7 @@ const TRACE_FILTER_OPERATOR_TO_QUERY_OP = { lte: 'lte', matches: 'matches', notMatches: 'notMatches', + hasAllTokens: 'hasAllTokens', } as const satisfies Record; /** Fields whose values must be sent as numbers. Non-numeric input is dropped. */ @@ -136,6 +139,8 @@ export function scalarPredicate( ): TraceQueryScalarPredicate | undefined { const queryOp = TRACE_FILTER_OPERATOR_TO_QUERY_OP[op]; switch (queryOp) { + case 'hasAllTokens': + return tokenSearchPredicate(path, values[0]); case 'exists': case 'notExists': return { op: queryOp, path }; @@ -187,9 +192,16 @@ const TRACE_QUERY_PRESENCE_ONLY_FIELD_IDS = new Set(['spans.error']); function tokenToTraceQueryPredicate( token: TraceFilterToken, excludedFieldIds: ReadonlySet, + withTokenSearch: boolean, ): TokenPredicate | undefined { if (TRACE_QUERY_UNSUPPORTED_FILTER_FIELDS.has(token.fieldId) || excludedFieldIds.has(token.fieldId)) return undefined; const operatorId = token.operatorId ?? (token.fieldId === 'tags' ? 'in' : 'is'); + if (operatorId === 'hasAllTokens') { + const { scope, path } = resolveTraceQueryPath(token.fieldId); + if (!withTokenSearch || scope !== 'spans') return undefined; + const predicate = tokenSearchPredicate(path, token.value); + return predicate ? { scope, predicate } : undefined; + } const isPresence = operatorId === 'exists' || operatorId === 'notExists'; // Hand-edited URLs can pair these fields with value operators; drop them rather than fail the page. if (TRACE_QUERY_PRESENCE_ONLY_FIELD_IDS.has(token.fieldId) && !isPresence) return undefined; @@ -253,13 +265,17 @@ function tokenToTraceQueryPredicate( * merged into a single `some`. Inside an `or` group each token stands alone. */ function predicatesForTokens( tokens: TraceFilterToken[], - { mergeRelated, excludedFieldIds }: { mergeRelated: boolean; excludedFieldIds: ReadonlySet }, + { + mergeRelated, + excludedFieldIds, + withTokenSearch, + }: { mergeRelated: boolean; excludedFieldIds: ReadonlySet; withTokenSearch: boolean }, ) { const args: TraceQueryPredicate[] = []; const related: Record = { spans: [], scores: [], feedback: [] }; for (const token of tokens) { - const result = tokenToTraceQueryPredicate(token, excludedFieldIds); + const result = tokenToTraceQueryPredicate(token, excludedFieldIds, withTokenSearch); if (!result) continue; if (!('scope' in result)) { args.push(result.predicate); @@ -283,12 +299,13 @@ function predicatesForTokens( function groupToTraceQueryPredicate( group: TraceFilterGroup, excludedFieldIds: ReadonlySet, + withTokenSearch: boolean, ): TraceQueryPredicate | undefined { const tokens = group.nodes.filter((node): node is TraceFilterToken => !isTraceFilterGroup(node)); - const args = predicatesForTokens(tokens, { mergeRelated: group.logic === 'and', excludedFieldIds }); + const args = predicatesForTokens(tokens, { mergeRelated: group.logic === 'and', excludedFieldIds, withTokenSearch }); for (const node of group.nodes) { if (!isTraceFilterGroup(node)) continue; - const predicate = groupToTraceQueryPredicate(node, excludedFieldIds); + const predicate = groupToTraceQueryPredicate(node, excludedFieldIds, withTokenSearch); if (predicate) args.push(predicate); } if (args.length === 0) return undefined; @@ -303,6 +320,7 @@ export function buildTraceQueryRequest({ tokens, groups = [], excludedFieldIds = new Set(), + withTokenSearch = false, now, }: Omit[0], 'tokens' | 'status'> & { status?: TraceStatusFilter; @@ -310,6 +328,7 @@ export function buildTraceQueryRequest({ groups?: TraceFilterGroup[]; /** Fields the server cannot query (e.g. `durationMs` without `traceQueryRootDuration`); dropped from tokens and groups. */ excludedFieldIds?: ReadonlySet; + withTokenSearch?: boolean; now: Date; }): Pick { const args: TraceQueryPredicate[] = []; @@ -317,10 +336,10 @@ export function buildTraceQueryRequest({ if (rootEntityType) args.push({ op: 'eq', left: { path: 'entityType' }, right: { literal: rootEntityType } }); if (status && status !== 'running') args.push({ op: 'eq', left: { path: 'status' }, right: { literal: status } }); - args.push(...predicatesForTokens(tokens, { mergeRelated: true, excludedFieldIds })); + args.push(...predicatesForTokens(tokens, { mergeRelated: true, excludedFieldIds, withTokenSearch })); for (const group of groups) { - const predicate = groupToTraceQueryPredicate(group, excludedFieldIds); + const predicate = groupToTraceQueryPredicate(group, excludedFieldIds, withTokenSearch); if (predicate) args.push(predicate); } diff --git a/packages/playground-ui/src/ds/components/FilterBar/filter-bar-chip.tsx b/packages/playground-ui/src/ds/components/FilterBar/filter-bar-chip.tsx index 3fa103c7611..5ad50c4f608 100644 --- a/packages/playground-ui/src/ds/components/FilterBar/filter-bar-chip.tsx +++ b/packages/playground-ui/src/ds/components/FilterBar/filter-bar-chip.tsx @@ -140,7 +140,7 @@ type ChipContext = { draft: boolean; /** Filter already removed from the value, playing its exit: segments are inert labels. */ leaving: boolean; - /** The field allows a single operator, so the operator segment is not shown. */ + /** The field allows a single operator and does not require its label to stay visible. */ operatorImplied: boolean; }; @@ -216,8 +216,11 @@ export function FilterBarChip({ }; }, [leaving, item.id, settleRemove]); - const validationMessage = !draft && typeof item.value === 'string' ? field?.validateInput?.(item.value) : undefined; - const operatorImplied = field ? ctx.getFieldOperators(field).length === 1 : false; + const validationMessage = + !draft && operator?.arity !== 'none' && typeof item.value === 'string' + ? field?.validateInput?.(item.value) + : undefined; + const operatorImplied = field ? !field.alwaysShowOperator && ctx.getFieldOperators(field).length === 1 : false; const label = [ field?.label ?? item.fieldId, operatorImplied ? '' : (operator?.label ?? item.operatorId), @@ -382,7 +385,11 @@ function SegmentCombobox({ if (chip.readOnly || chip.draft || chip.leaving) { return ( @@ -426,7 +433,11 @@ function SegmentCombobox({ tabIndex={segment === 'value' ? 0 : -1} aria-label={`${ariaLabel}: ${fullLabel}`} title={fullLabel} - className={cn(editableSegmentClass, isField && 'text-foreground')} + className={cn( + editableSegmentClass, + isField && 'text-foreground', + segment === 'operator' && chip.field?.alwaysShowOperator && 'shrink-0', + )} style={isField ? fieldSegmentAccentStyle(chip.field) : undefined} /> } diff --git a/packages/playground-ui/src/ds/components/FilterBar/types.ts b/packages/playground-ui/src/ds/components/FilterBar/types.ts index 0248f9d56dd..fa8282812d5 100644 --- a/packages/playground-ui/src/ds/components/FilterBar/types.ts +++ b/packages/playground-ui/src/ds/components/FilterBar/types.ts @@ -66,6 +66,8 @@ export type FilterBarField = { type?: FilterBarFieldType; /** Operator ids allowed for this field. Defaults to every root operator. */ operators?: string[]; + /** Keep the operator label visible even when this field allows only one operator. */ + alwaysShowOperator?: boolean; /** Field-specific labels for operators, keyed by operator id (e.g. `notExists` → `is not recorded`). */ operatorLabels?: Record; /** diff --git a/packages/playground/src/pages/traces/hooks/__tests__/use-traces-route-state.test.tsx b/packages/playground/src/pages/traces/hooks/__tests__/use-traces-route-state.test.tsx index f14df568bd0..b1d9d958f8a 100644 --- a/packages/playground/src/pages/traces/hooks/__tests__/use-traces-route-state.test.tsx +++ b/packages/playground/src/pages/traces/hooks/__tests__/use-traces-route-state.test.tsx @@ -42,39 +42,6 @@ function renderRouteState(initialEntry: string) { } describe('useTracesRouteState', () => { - describe('when a shared URL contains a text search', () => { - it('restores the search', () => { - const { result } = renderRouteState('/traces?textSearch=needle'); - expect(result.current.route.filters.textSearch).toBe('needle'); - }); - - it('removes a cleared search from the URL', () => { - const { result, params } = renderRouteState('/traces?textSearch=needle'); - act(() => - result.current.route.setState(applyFilters({ ...result.current.route.filters, textSearch: undefined })), - ); - expect(params().has('textSearch')).toBe(false); - }); - }); - - describe('when a filter field changes to an empty text search', () => { - it('preserves the editable chip through URL state', () => { - const { result, params } = renderRouteState('/traces'); - act(() => result.current.route.setState(applyFilters({ ...result.current.route.filters, textSearch: '' }))); - expect(params().get('textSearch')).toBe(''); - expect(result.current.route.filters.textSearch).toBe(''); - }); - - it('removes an empty draft from the URL', () => { - const { result, params } = renderRouteState('/traces?textSearch='); - act(() => - result.current.route.setState(applyFilters({ ...result.current.route.filters, textSearch: undefined })), - ); - expect(params().has('textSearch')).toBe(false); - expect(result.current.route.filters.textSearch).toBeUndefined(); - }); - }); - describe('when the URL is empty', () => { it('decodes the default selection, filters and sort', () => { const { result } = renderRouteState('/traces'); diff --git a/packages/playground/src/pages/traces/hooks/use-traces-route-state.ts b/packages/playground/src/pages/traces/hooks/use-traces-route-state.ts index 00687c4453b..8a05a4e1397 100644 --- a/packages/playground/src/pages/traces/hooks/use-traces-route-state.ts +++ b/packages/playground/src/pages/traces/hooks/use-traces-route-state.ts @@ -67,7 +67,6 @@ function decodeFilters(params: URLSearchParams): TracesFilters { : DEFAULT_TRACES_FILTERS.datePreset; return { datePreset, - textSearch: params.get('textSearch') ?? undefined, dateFrom: parseDate(params.get(TRACE_DATE_FROM_PARAM)), dateTo: parseDate(params.get(TRACE_DATE_TO_PARAM)), tokens: getTracePropertyFilterTokens(params), @@ -96,8 +95,6 @@ function setOrDelete(params: URLSearchParams, key: string, value: string | undef function encodeFilters(base: URLSearchParams, filters: TracesFilters): URLSearchParams { const next = new URLSearchParams(base); // An empty value preserves an editable chip after changing its field; absence removes it. - if (filters.textSearch !== undefined) next.set('textSearch', filters.textSearch); - else next.delete('textSearch'); setOrDelete( next, TRACE_DATE_PRESET_PARAM, diff --git a/packages/server/src/server/handlers/observability-legacy-search-core-compat.test.ts b/packages/server/src/server/handlers/observability-legacy-search-core-compat.test.ts new file mode 100644 index 00000000000..291bdd859f8 --- /dev/null +++ b/packages/server/src/server/handlers/observability-legacy-search-core-compat.test.ts @@ -0,0 +1,40 @@ +import { Mastra } from '@mastra/core'; +import { describe, expect, it, vi } from 'vitest'; +import { HTTPException } from '../http-exception'; +import { createTestServerContext } from './test-utils'; + +// Older Core accepts this field; newer Server must never silently discard it. +vi.mock('@mastra/core/storage', async importOriginal => { + const actual = await importOriginal(); + const { z } = await import('zod/v4'); + const legacySchema = z.object({ + timeRange: z.object({ from: z.string(), to: z.string() }), + textSearch: z.string().optional(), + }); + return { ...actual, traceQueryRequestSchema: legacySchema, spanQueryRequestSchema: legacySchema }; +}); + +const { QUERY_TRACES, QUERY_SPANS } = await import('./observability-new-endpoints'); + +describe('legacy search Core compatibility', () => { + it.each([ + [QUERY_TRACES, 'TRACE_QUERY_UNSUPPORTED'], + [QUERY_SPANS, 'SPAN_QUERY_UNSUPPORTED'], + ] as const)('rejects accepted legacy search before reaching storage (%s)', async (route, code) => { + const mastra = new Mastra({}); + const storage = vi.spyOn(mastra, 'getStorage'); + const body = route.bodySchema!.parse({ + timeRange: { from: '2026-08-01T00:00:00Z', to: '2026-08-02T00:00:00Z' }, + textSearch: 'needle', + }); + try { + await route.handler({ ...createTestServerContext({ mastra }), ...body }); + expect.fail('Legacy search must be rejected'); + } catch (error) { + if (!(error instanceof HTTPException)) throw error; + expect(error.status).toBe(501); + expect(await error.getResponse().json()).toMatchObject({ code, message: expect.stringContaining('textSearch') }); + } + expect(storage).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/server/src/server/handlers/observability-new-endpoints.ts b/packages/server/src/server/handlers/observability-new-endpoints.ts index 8be96d6c2ec..6b099096246 100644 --- a/packages/server/src/server/handlers/observability-new-endpoints.ts +++ b/packages/server/src/server/handlers/observability-new-endpoints.ts @@ -120,7 +120,6 @@ import { isObservabilityOutcomeField, supportsObservabilityTraceQueryOutcomeFields, assertObservabilityTraceQuerySupported, - assertObservabilityTextSearchSupported, createObservabilityListQuerySchema, getObservabilityStorageCapabilities, getObservabilityStore, @@ -341,7 +340,6 @@ export const QUERY_TRACES = createNewRoute(NEW_ROUTE_DEFS.QUERY_TRACES, { requestContext, timeRange, where, - textSearch, rootSource, group, orderBy, @@ -350,7 +348,14 @@ export const QUERY_TRACES = createNewRoute(NEW_ROUTE_DEFS.QUERY_TRACES, { mode, after, limit, + ...legacy }) => { + if ('textSearch' in legacy && legacy.textSearch !== undefined) { + throwTraceQueryError(501, { + code: 'TRACE_QUERY_UNSUPPORTED', + message: 'The experimental textSearch field is no longer supported', + }); + } if (rootSource === 'aggregated') { throwTraceQueryError(501, { code: 'TRACE_QUERY_UNSUPPORTED', @@ -380,7 +385,6 @@ export const QUERY_TRACES = createNewRoute(NEW_ROUTE_DEFS.QUERY_TRACES, { timeRange, where, ...(rootSource === undefined || rootSource === 'legacy' ? {} : { rootSource }), - ...(textSearch === undefined ? {} : { textSearch }), group, orderBy, page, @@ -408,7 +412,6 @@ export const QUERY_TRACES = createNewRoute(NEW_ROUTE_DEFS.QUERY_TRACES, { try { observabilityStore = await getObservabilityStore(mastra); assertObservabilityTraceQuerySupported(observabilityStore); - assertObservabilityTextSearchSupported(observabilityStore, plan.textSearch, 'trace'); assertObservabilityTraceQueryRootDurationSupported(observabilityStore, plan.where); assertObservabilityTraceQueryContextFieldsSupported(observabilityStore, plan.where); assertObservabilityTraceQueryTimeToFirstChunkSupported(observabilityStore, plan.where); @@ -434,6 +437,12 @@ export const QUERY_TRACES = createNewRoute(NEW_ROUTE_DEFS.QUERY_TRACES, { try { return await observabilityStore.queryTraces(plan); } catch (error) { + if ( + typeof coreStorage.TraceQueryUnsupportedError === 'function' && + error instanceof coreStorage.TraceQueryUnsupportedError + ) { + throwTraceQueryError(501, { code: 'TRACE_QUERY_UNSUPPORTED', message: error.message }); + } if (error instanceof coreStorage.TraceQueryCursorError) { throwTraceQueryError(error.code === 'TRACE_QUERY_CURSOR_CONFLICT' ? 409 : 400, { code: error.code, @@ -543,7 +552,16 @@ export const AGGREGATE_TRACES = createNewRoute(NEW_ROUTE_DEFS.AGGREGATE_TRACES, let plan; try { plan = coreStorage.planTraceAggregate( - { timeRange, where, groupBy, interval, measures, having, orderBy, limit }, + { + timeRange, + where, + groupBy, + interval, + measures, + having, + orderBy, + limit, + }, { scope: resolveTraceQueryScope(requestContext, 'TRACE_AGGREGATE_UNSUPPORTED') }, ); } catch (error) { @@ -578,6 +596,12 @@ export const AGGREGATE_TRACES = createNewRoute(NEW_ROUTE_DEFS.AGGREGATE_TRACES, try { return await observabilityStore.aggregateTraces(plan); } catch (error) { + if ( + typeof coreStorage.TraceQueryUnsupportedError === 'function' && + error instanceof coreStorage.TraceQueryUnsupportedError + ) { + throwTraceQueryError(501, { code: 'TRACE_AGGREGATE_UNSUPPORTED', message: error.message }); + } if (error instanceof coreStorage.TraceQueryResourceLimitError) { throwTraceQueryError(503, { code: error.code, message: error.message }); } @@ -680,7 +704,16 @@ export const AGGREGATE_SPANS = createNewRoute(NEW_ROUTE_DEFS.AGGREGATE_SPANS, { let plan; try { plan = coreStorage.planSpanAggregate( - { timeRange, where, groupBy, interval, measures, having, orderBy, limit }, + { + timeRange, + where, + groupBy, + interval, + measures, + having, + orderBy, + limit, + }, { scope: resolveTraceQueryScope(requestContext, 'SPAN_AGGREGATE_UNSUPPORTED') }, ); } catch (error) { @@ -713,6 +746,12 @@ export const AGGREGATE_SPANS = createNewRoute(NEW_ROUTE_DEFS.AGGREGATE_SPANS, { try { return await observabilityStore.aggregateSpans(plan); } catch (error) { + if ( + typeof coreStorage.TraceQueryUnsupportedError === 'function' && + error instanceof coreStorage.TraceQueryUnsupportedError + ) { + throwTraceQueryError(501, { code: 'SPAN_AGGREGATE_UNSUPPORTED', message: error.message }); + } if (error instanceof coreStorage.TraceQueryResourceLimitError) { throwTraceQueryError(503, { code: error.code, message: error.message }); } @@ -793,11 +832,17 @@ export const QUERY_SPANS = createNewRoute(NEW_ROUTE_DEFS.QUERY_SPANS, { code: 'SPAN_QUERY_UNSUPPORTED', message: 'Span queries require a newer @mastra/core. Please upgrade.', }), - handler: async ({ mastra, requestContext, timeRange, where, textSearch, orderBy, page }) => { + handler: async ({ mastra, requestContext, timeRange, where, orderBy, page, ...legacy }) => { + if ('textSearch' in legacy && legacy.textSearch !== undefined) { + throwTraceQueryError(501, { + code: 'SPAN_QUERY_UNSUPPORTED', + message: 'The experimental textSearch field is no longer supported', + }); + } let plan; try { plan = coreStorage.planSpanQuery( - { timeRange, where, ...(textSearch === undefined ? {} : { textSearch }), orderBy, page }, + { timeRange, where, orderBy, page }, { scope: resolveTraceQueryScope(requestContext, 'SPAN_QUERY_UNSUPPORTED'), allowSpanDurationOrdering: true, @@ -823,7 +868,6 @@ export const QUERY_SPANS = createNewRoute(NEW_ROUTE_DEFS.QUERY_SPANS, { assertObservabilitySpanQuerySupported(observabilityStore); assertObservabilitySpanDurationSortSupported(observabilityStore, plan.orderBy); assertObservabilitySpanModelProviderSortSupported(observabilityStore, plan.orderBy); - assertObservabilityTextSearchSupported(observabilityStore, plan.textSearch, 'span'); assertObservabilitySpanQueryFieldsSupported(observabilityStore, plan.where); assertObservabilitySpanQueryModelFieldsSupported(observabilityStore, plan.where); assertObservabilitySpanQueryOutcomeFieldsSupported(observabilityStore, plan); @@ -845,6 +889,12 @@ export const QUERY_SPANS = createNewRoute(NEW_ROUTE_DEFS.QUERY_SPANS, { try { return await observabilityStore.querySpans(plan); } catch (error) { + if ( + typeof coreStorage.TraceQueryUnsupportedError === 'function' && + error instanceof coreStorage.TraceQueryUnsupportedError + ) { + throwTraceQueryError(501, { code: 'SPAN_QUERY_UNSUPPORTED', message: error.message }); + } if (error instanceof coreStorage.TraceQueryCursorError) { throwTraceQueryError(error.code === 'TRACE_QUERY_CURSOR_CONFLICT' ? 409 : 400, { code: error.code, diff --git a/packages/server/src/server/handlers/observability-shared.test.ts b/packages/server/src/server/handlers/observability-shared.test.ts index 143f8d28fb3..f6be01d40d9 100644 --- a/packages/server/src/server/handlers/observability-shared.test.ts +++ b/packages/server/src/server/handlers/observability-shared.test.ts @@ -1,14 +1,11 @@ -import type { Mastra } from '@mastra/core/mastra'; +import { Mastra } from '@mastra/core/mastra'; import { InMemoryStore } from '@mastra/core/storage'; import type { MastraCompositeStore } from '@mastra/core/storage'; import { describe, it, expect, vi } from 'vitest'; import { HTTPException } from '../http-exception'; -import { - assertObservabilityTextSearchSupported, - getObservabilityStorageCapabilities, - getObservabilityStore, - getScoresStore, -} from './observability-shared'; +import { QUERY_TRACES, QUERY_SPANS, AGGREGATE_TRACES, AGGREGATE_SPANS } from './observability-new-endpoints'; +import { getObservabilityStorageCapabilities, getObservabilityStore, getScoresStore } from './observability-shared'; +import { createTestServerContext } from './test-utils'; const createMockMastra = (storage?: Partial): Mastra => ({ @@ -75,21 +72,54 @@ describe('getScoresStore', () => { }); }); -describe('text search capabilities', () => { - it.each(['span', 'trace'] as const)( - 'rejects %s search on a real store without indexed search support', - async kind => { - const store = await new InMemoryStore().getStore('observability'); - if (!store) throw new Error('Missing observability store'); - const capabilities = getObservabilityStorageCapabilities(store); - expect(capabilities.spanQueryTextSearch).toBe(false); - expect(capabilities.traceQueryTextSearch).toBe(false); - expect(() => assertObservabilityTextSearchSupported(store, 'error', kind)).toThrow( - expect.objectContaining({ status: 501 }), - ); - // The same store remains usable for requests that don't ask for text search. - assertObservabilityTextSearchSupported(store, undefined, kind); - expect(await store.getEntityTypes({})).toEqual({ entityTypes: [] }); - }, - ); +describe('token search is unavailable in OSS Server', () => { + it('does not advertise token search even when a store declares support', () => { + const store = { + getFeatures: () => [ + 'trace-query', + 'span-query', + 'trace-aggregate', + 'span-aggregate', + 'trace-query-token-search', + 'span-query-token-search', + 'trace-aggregate-token-search', + 'span-aggregate-token-search', + ], + } as Parameters[0]; + expect(getObservabilityStorageCapabilities(store)).toMatchObject({ + traceQueryTokenSearch: false, + spanQueryTokenSearch: false, + traceAggregateTokenSearch: false, + spanAggregateTokenSearch: false, + }); + }); + it.each([ + ['queryTraces', QUERY_TRACES, true, false], + ['querySpans', QUERY_SPANS, false, false], + ['aggregateTraces', AGGREGATE_TRACES, true, true], + ['aggregateSpans', AGGREGATE_SPANS, false, true], + ] as const)('rejects %s token predicates during planning', async (_, route, trace, aggregate) => { + const mastra = new Mastra({ storage: new InMemoryStore() }); + const token = { op: 'hasAllTokens' as const, left: { path: 'input' as const }, right: { literal: 'tacos' } }; + const request = { + timeRange: { from: '2026-11-01T00:00:00Z', to: '2026-11-02T00:00:00Z' }, + where: trace ? { spans: { some: token } } : token, + ...(aggregate ? { measures: ['count'] } : {}), + }; + const error = await route + .handler({ ...createTestServerContext({ mastra }), ...route.bodySchema!.parse(request) } as Parameters< + typeof route.handler + >[0]) + .catch(error => error); + expect(error).toBeInstanceOf(HTTPException); + expect(error.status).toBe(422); + await expect(error.getResponse().json()).resolves.toMatchObject({ + issues: expect.arrayContaining([ + expect.objectContaining({ + code: 'operator_not_allowed', + message: 'Token search requires a supporting host', + }), + ]), + }); + }); }); diff --git a/packages/server/src/server/handlers/observability-shared.ts b/packages/server/src/server/handlers/observability-shared.ts index 6da81bb3310..6ae59c7987a 100644 --- a/packages/server/src/server/handlers/observability-shared.ts +++ b/packages/server/src/server/handlers/observability-shared.ts @@ -204,19 +204,6 @@ export function assertObservabilitySpanAggregateSupported(observabilityStore: Ob }); } -/** Reject unsupported search instead of silently returning unfiltered results. */ -export function assertObservabilityTextSearchSupported( - observabilityStore: ObservabilityStorage, - textSearch: string | undefined, - kind: 'span' | 'trace', -) { - if (textSearch !== undefined && !getFeatures(observabilityStore)?.includes(`${kind}-query-text-search`)) { - throw new HTTPException(501, { - message: 'Text search is not supported by the configured observability store', - }); - } -} - export function assertObservabilitySpanQuerySupported(observabilityStore: ObservabilityStorage) { if (getFeatures(observabilityStore)?.includes(OBSERVABILITY_SPAN_QUERY_STORAGE_FEATURE)) return; @@ -229,7 +216,12 @@ export function assertObservabilitySpanQueryFieldsSupported( observabilityStore: ObservabilityStorage, predicate: TrustedTraceQueryScalarPredicate | undefined, ) { - if (!predicate || getFeatures(observabilityStore)?.includes('span-query-context-fields')) return; + if ( + !predicate || + predicate.type === 'tokens' || + getFeatures(observabilityStore)?.includes('span-query-context-fields') + ) + return; if (predicate.type === 'boolean') { for (const arg of predicate.args) assertObservabilitySpanQueryFieldsSupported(observabilityStore, arg); } else if (predicate.type === 'not') { @@ -384,6 +376,7 @@ function usesRootDuration(predicate: TrustedTraceQueryPredicate | TrustedThreadP if (predicate.type === 'relation') { return predicate.collection === 'traces' && usesRootDuration(predicate.predicate); } + if (predicate.type === 'tokens') return false; return predicate.field === 'durationMs'; } @@ -411,6 +404,7 @@ function usesField( if (predicate.type === 'boolean') return predicate.args.some(arg => usesField(arg, fields)); if (predicate.type === 'not') return usesField(predicate.arg, fields); if (predicate.type === 'relation') return usesField(predicate.predicate, fields); + if (predicate.type === 'tokens') return false; return fields.has(predicate.field); } @@ -492,6 +486,7 @@ function rootSpanFieldIssues( if (predicate.type === 'relation') { return predicate.collection === 'traces' ? rootSpanFieldIssues(observabilityStore, predicate.predicate) : []; } + if (predicate.type === 'tokens') return []; return supportsObservabilityTraceQueryRootSpanField(observabilityStore, predicate.field) ? [] : [rootSpanFieldIssue(['where'], predicate.field)]; @@ -695,7 +690,7 @@ export type ObservabilityStorageCapabilities = { deltaPolling: boolean; traceQuery: boolean; traceQueryAggregatedRoots: boolean; - traceQueryTextSearch: boolean; + traceQueryTokenSearch: boolean; traceQueryRootDuration: boolean; traceQueryContextIds: boolean; traceQueryContextFields: boolean; @@ -708,10 +703,11 @@ export type ObservabilityStorageCapabilities = { traceQueryDiscovery: boolean; traceQueryTenantScope: boolean; traceAggregate: boolean; + traceAggregateTokenSearch: boolean; threadQuery: boolean; threadQueryRows: boolean; spanQuery: boolean; - spanQueryTextSearch: boolean; + spanQueryTokenSearch: boolean; spanQueryDurationSort: boolean; spanQueryModelProviderSort: boolean; spanQueryContextFields: boolean; @@ -719,6 +715,7 @@ export type ObservabilityStorageCapabilities = { spanQueryOutcomeFields: boolean; traceQueryOutcomeFields: boolean; spanAggregate: boolean; + spanAggregateTokenSearch: boolean; spanAggregateModelDimensions: boolean; aggregateTimeToFirstMeasures: boolean; /** Days of traces the store keeps. Omitted when the store does not report a limit. */ @@ -741,7 +738,7 @@ export const NO_OBSERVABILITY_STORAGE_CAPABILITIES: ObservabilityStorageCapabili deltaPolling: false, traceQuery: false, traceQueryAggregatedRoots: false, - traceQueryTextSearch: false, + traceQueryTokenSearch: false, traceQueryRootDuration: false, traceQueryContextIds: false, traceQueryContextFields: false, @@ -754,11 +751,13 @@ export const NO_OBSERVABILITY_STORAGE_CAPABILITIES: ObservabilityStorageCapabili traceQueryDiscovery: false, traceQueryTenantScope: false, traceAggregate: false, + traceAggregateTokenSearch: false, threadQuery: false, threadQueryRows: false, spanQuery: false, - spanQueryTextSearch: false, + spanQueryTokenSearch: false, spanAggregate: false, + spanAggregateTokenSearch: false, spanQueryDurationSort: false, spanQueryModelProviderSort: false, spanQueryContextFields: false, @@ -835,8 +834,9 @@ export function getObservabilityStorageCapabilities( coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE) && declares(OBSERVABILITY_DELTA_POLLING_STORAGE_FEATURE), traceQuery, traceQueryAggregatedRoots: false, - traceQueryTextSearch: - traceQuery && coreStorage.observabilityTextSearchSchema !== undefined && declares('trace-query-text-search'), + // OSS Server never opts into indexed token search. + traceAggregateTokenSearch: false, + traceQueryTokenSearch: false, traceQueryRootDuration: (traceQuery || threadQuery) && declares(OBSERVABILITY_TRACE_QUERY_ROOT_DURATION_STORAGE_FEATURE), traceQueryContextIds: @@ -869,8 +869,9 @@ export function getObservabilityStorageCapabilities( threadQueryRows: threadQuery && typeof coreStorage.planThreadRowsQuery === 'function' && declares('thread-query-rows'), spanQuery, - spanQueryTextSearch: - spanQuery && coreStorage.observabilityTextSearchSchema !== undefined && declares('span-query-text-search'), + // OSS Server never opts into token search; the same scalar-field walker prerequisite applies here. + spanAggregateTokenSearch: false, + spanQueryTokenSearch: false, spanQueryDurationSort: spanQuery && coreStorage.SPAN_QUERY_ORDER_FIELDS?.includes('durationMs') === true && diff --git a/packages/server/src/server/handlers/observability-span-aggregate.test.ts b/packages/server/src/server/handlers/observability-span-aggregate.test.ts index 4ee41552aea..938854fee9d 100644 --- a/packages/server/src/server/handlers/observability-span-aggregate.test.ts +++ b/packages/server/src/server/handlers/observability-span-aggregate.test.ts @@ -1,5 +1,6 @@ import type { Mastra } from '@mastra/core'; import { + TraceQueryUnsupportedError, TraceQueryExecutionError, TraceQueryResourceLimitError, spanAggregateRequestSchema, @@ -415,3 +416,18 @@ describe('AGGREGATE_SPANS', () => { expect(JSON.stringify(responses['200'])).toContain('truncated'); }); }); + +it('maps a typed store unsupported error to the route-specific 501', async () => { + const { mastra, observabilityStore } = createHarness(); + observabilityStore.aggregateSpans.mockRejectedValue( + new TraceQueryUnsupportedError('Indexed token search is not supported by this store'), + ); + const error = await captureHttpException( + AGGREGATE_SPANS.handler(params(mastra, { timeRange: TIME_RANGE, measures: ['count'] })), + ); + expect(error.status).toBe(501); + expect(getDeclaredErrorSchema(501).parse(await error.getResponse().json())).toEqual({ + code: 'SPAN_AGGREGATE_UNSUPPORTED', + message: 'Indexed token search is not supported by this store', + }); +}); diff --git a/packages/server/src/server/handlers/observability-span-query.test.ts b/packages/server/src/server/handlers/observability-span-query.test.ts index 0973c18261c..ecc58094828 100644 --- a/packages/server/src/server/handlers/observability-span-query.test.ts +++ b/packages/server/src/server/handlers/observability-span-query.test.ts @@ -5,6 +5,7 @@ import { planSpanQuery, spanQueryRequestSchema, TraceQueryCursorError, + TraceQueryUnsupportedError, TraceQueryExecutionError, TraceQueryResourceLimitError, } from '@mastra/core/storage'; @@ -637,3 +638,16 @@ it.each(['durationMs', 'model', 'provider'] as const)( expect(observabilityStore.querySpans).not.toHaveBeenCalled(); }, ); + +it('maps a typed store unsupported error to the route-specific 501', async () => { + const { mastra, observabilityStore } = createHarness(); + observabilityStore.querySpans.mockRejectedValue( + new TraceQueryUnsupportedError('Indexed token search is not supported by this store'), + ); + const error = await captureHttpException(QUERY_SPANS.handler(params(mastra, { timeRange: TIME_RANGE }))); + expect(error.status).toBe(501); + expect(getDeclaredErrorSchema(501).parse(await error.getResponse().json())).toEqual({ + code: 'SPAN_QUERY_UNSUPPORTED', + message: 'Indexed token search is not supported by this store', + }); +}); diff --git a/packages/server/src/server/handlers/observability-text-search-core-compat.test.ts b/packages/server/src/server/handlers/observability-text-search-core-compat.test.ts deleted file mode 100644 index 828c4cabbe1..00000000000 --- a/packages/server/src/server/handlers/observability-text-search-core-compat.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Mastra } from '@mastra/core'; -import { InMemoryStore } from '@mastra/core/storage'; -import { describe, expect, it, vi } from 'vitest'; - -import { HTTPException } from '../http-exception'; -import { createTestServerContext } from './test-utils'; - -// Model the pre-search Core contract, retaining real schema validation and planning. -vi.mock('@mastra/core/storage', async importOriginal => { - const actual = await importOriginal(); - const legacyRequestSchema = actual.spanQueryRequestSchema.out.omit({ textSearch: true }); - return { - ...actual, - observabilityTextSearchSchema: undefined, - planSpanQuery: (input: unknown, options: Parameters[1]) => - actual.planSpanQuery(legacyRequestSchema.parse(input), options), - }; -}); - -const { QUERY_SPANS } = await import('./observability-new-endpoints'); -const { getObservabilityStorageCapabilities } = await import('./observability-shared'); - -describe('text search with pre-search Core', () => { - it('lets an ordinary span request reach the store capability check instead of failing old schema validation', async () => { - const mastra = new Mastra({ storage: new InMemoryStore() }); - try { - await QUERY_SPANS.handler({ - ...createTestServerContext({ mastra }), - timeRange: { from: '2026-08-01T00:00:00Z', to: '2026-08-02T00:00:00Z' }, - }); - throw new Error('Expected unsupported in-memory span queries'); - } catch (error) { - expect(error).toBeInstanceOf(HTTPException); - const response = (error as HTTPException).getResponse(); - expect(response.status).toBe(501); - await expect(response.json()).resolves.toMatchObject({ code: 'SPAN_QUERY_UNSUPPORTED' }); - } - }); - - it('does not advertise search when Core cannot parse it, even if the store declares it', () => { - const capabilities = getObservabilityStorageCapabilities({ - getFeatures: () => ['span-query', 'trace-query', 'span-query-text-search', 'trace-query-text-search'], - } as Parameters[0]); - expect(capabilities).toMatchObject({ - spanQuery: true, - traceQuery: true, - spanQueryTextSearch: false, - traceQueryTextSearch: false, - }); - }); -}); diff --git a/packages/server/src/server/handlers/observability-trace-aggregate.test.ts b/packages/server/src/server/handlers/observability-trace-aggregate.test.ts index 5166bdc8746..3577a46c476 100644 --- a/packages/server/src/server/handlers/observability-trace-aggregate.test.ts +++ b/packages/server/src/server/handlers/observability-trace-aggregate.test.ts @@ -1,6 +1,7 @@ import type { Mastra } from '@mastra/core'; import { coreFeatures } from '@mastra/core/features'; import { + TraceQueryUnsupportedError, TraceQueryExecutionError, TraceQueryResourceLimitError, traceAggregateRequestSchema, @@ -657,3 +658,18 @@ describe('AGGREGATE_TRACES', () => { ); }); }); + +it('maps a typed store unsupported error to the route-specific 501', async () => { + const { mastra, observabilityStore } = createHarness(); + observabilityStore.aggregateTraces.mockRejectedValue( + new TraceQueryUnsupportedError('Indexed token search is not supported by this store'), + ); + const error = await captureHttpException( + AGGREGATE_TRACES.handler(params(mastra, { timeRange: TIME_RANGE, measures: ['count'] })), + ); + expect(error.status).toBe(501); + expect(getDeclaredErrorSchema(501).parse(await error.getResponse().json())).toEqual({ + code: 'TRACE_AGGREGATE_UNSUPPORTED', + message: 'Indexed token search is not supported by this store', + }); +}); diff --git a/packages/server/src/server/handlers/observability-trace-query.test.ts b/packages/server/src/server/handlers/observability-trace-query.test.ts index 72b67158958..0d0ff7690bf 100644 --- a/packages/server/src/server/handlers/observability-trace-query.test.ts +++ b/packages/server/src/server/handlers/observability-trace-query.test.ts @@ -16,6 +16,7 @@ import { getTraceQueryFieldsArgsSchema, getTraceQueryFieldsResponseSchema, getTraceQueryValuesArgsSchema, + TraceQueryUnsupportedError, TraceQueryExecutionError, TraceQueryResourceLimitError, parseTraceQueryRequest, @@ -1598,3 +1599,16 @@ describe('trace-query discovery routes', () => { }); }); }); + +it('maps a typed store unsupported error to the route-specific 501', async () => { + const { mastra, observabilityStore } = createHarness(); + observabilityStore.queryTraces.mockRejectedValue( + new TraceQueryUnsupportedError('Indexed token search is not supported by this store'), + ); + const error = await captureHttpException(QUERY_TRACES.handler(params(mastra, { timeRange: TIME_RANGE }))); + expect(error.status).toBe(501); + expect(getDeclaredErrorSchema(501).parse(await error.getResponse().json())).toEqual({ + code: 'TRACE_QUERY_UNSUPPORTED', + message: 'Indexed token search is not supported by this store', + }); +}); diff --git a/packages/server/src/server/handlers/system.test.ts b/packages/server/src/server/handlers/system.test.ts index b30aa49503f..525af7e74b7 100644 --- a/packages/server/src/server/handlers/system.test.ts +++ b/packages/server/src/server/handlers/system.test.ts @@ -19,8 +19,10 @@ const NO_OBSERVABILITY_CAPABILITIES = { deltaPolling: false, traceQuery: false, traceQueryAggregatedRoots: false, - traceQueryTextSearch: false, - spanQueryTextSearch: false, + traceQueryTokenSearch: false, + spanQueryTokenSearch: false, + spanAggregateTokenSearch: false, + traceAggregateTokenSearch: false, traceQueryRootDuration: false, traceQueryContextIds: false, traceQueryContextFields: false, diff --git a/packages/server/src/server/schemas/system.test.ts b/packages/server/src/server/schemas/system.test.ts index 4b44e71f65a..ff7c70ef922 100644 --- a/packages/server/src/server/schemas/system.test.ts +++ b/packages/server/src/server/schemas/system.test.ts @@ -6,14 +6,18 @@ describe('observabilityStorageCapabilitiesSchema', () => { it('treats omitted search capabilities from older servers as unavailable', () => { const { traceQueryAggregatedRoots: _roots, - spanQueryTextSearch: _span, - traceQueryTextSearch: _trace, + spanQueryTokenSearch: _span, + traceQueryTokenSearch: _trace, + traceAggregateTokenSearch: _traceAggregate, + spanAggregateTokenSearch: _spanAggregate, ...legacyCapabilities } = NO_OBSERVABILITY_STORAGE_CAPABILITIES; expect(observabilityStorageCapabilitiesSchema.parse(legacyCapabilities)).toMatchObject({ traceQueryAggregatedRoots: false, - spanQueryTextSearch: false, - traceQueryTextSearch: false, + spanQueryTokenSearch: false, + traceQueryTokenSearch: false, + traceAggregateTokenSearch: false, + spanAggregateTokenSearch: false, }); }); diff --git a/packages/server/src/server/schemas/system.ts b/packages/server/src/server/schemas/system.ts index db40d68bd06..e4db57620b5 100644 --- a/packages/server/src/server/schemas/system.ts +++ b/packages/server/src/server/schemas/system.ts @@ -41,8 +41,10 @@ export const observabilityStorageCapabilitiesSchema = z.object({ .boolean() .default(false) .describe("Supports explicit `rootSource: 'aggregated'` trace queries"), - traceQueryTextSearch: z.boolean().default(false).describe('Literal substring search across any span in a trace'), - spanQueryTextSearch: z.boolean().default(false).describe('Literal substring search within individual spans'), + traceQueryTokenSearch: z.boolean().default(false).describe('Token matching across any span in a trace'), + spanQueryTokenSearch: z.boolean().default(false).describe('Token matching within individual spans'), + traceAggregateTokenSearch: z.boolean().default(false).describe('Token predicates in trace aggregates'), + spanAggregateTokenSearch: z.boolean().default(false).describe('Token predicates in span aggregates'), traceQueryRootDuration: z.boolean().describe('`durationMs` predicates in trace and thread queries'), traceQueryContextIds: z .boolean() diff --git a/stores/_test-utils/src/domains/observability-vnext/trace-query.ts b/stores/_test-utils/src/domains/observability-vnext/trace-query.ts index 7b5b9562ec2..348581b5a7f 100644 --- a/stores/_test-utils/src/domains/observability-vnext/trace-query.ts +++ b/stores/_test-utils/src/domains/observability-vnext/trace-query.ts @@ -11,29 +11,31 @@ import { parseTraceQueryRequest, planThreadQuery, planTraceQuery, - type NormalizedQueryThreadsInput, - type NormalizedTraceQueryRequest, - type TraceAggregateDimension, - type QueryThreadsInput, - type QueryThreadsResult, - type TraceQueryGroupResponse, - type TraceQueryPaginatedTraceResponse, - type TraceQueryPredicate, - type TraceQueryRequest, - type TraceQueryResponse, - type TraceQueryScalarPredicate, - type TraceQueryTrace, - type TraceQueryTraceResponse, - type SpanAggregateDimension, - type TrustedThreadPredicate, - type TrustedThreadQueryPlan, - type TraceQuerySortValue, - type TrustedTraceQueryKeysetTracesPlan, - type TrustedTraceQueryPlan, - type TrustedTraceQueryPredicate, - type TrustedTraceQueryScalarPredicate, - type TraceQueryTenantScope, - type ObservabilityStorageFeature, +} from '@mastra/core/storage'; +import type { + NormalizedQueryThreadsInput, + NormalizedTraceQueryRequest, + TraceAggregateDimension, + QueryThreadsInput, + QueryThreadsResult, + TraceQueryGroupResponse, + TraceQueryPaginatedTraceResponse, + TraceQueryPredicate, + TraceQueryRequest, + TraceQueryResponse, + TraceQueryScalarPredicate, + TraceQueryTrace, + TraceQueryTraceResponse, + SpanAggregateDimension, + TrustedThreadPredicate, + TrustedThreadQueryPlan, + TraceQuerySortValue, + TrustedTraceQueryKeysetTracesPlan, + TrustedTraceQueryPlan, + TrustedTraceQueryPredicate, + TrustedTraceQueryScalarPredicate, + TraceQueryTenantScope, + ObservabilityStorageFeature, } from '@mastra/core/storage'; export interface RawTraceQuerySpan { @@ -3261,6 +3263,7 @@ function evaluateScalarPredicate( : predicate.args.some(arg => evaluateScalarPredicate(arg, record)); } if (predicate.type === 'not') return !evaluateScalarPredicate(predicate.arg, record); + if (predicate.type === 'tokens') throw new Error('Token search requires store-specific conformance tests'); const value = record[predicate.field as keyof typeof record] as unknown; if (predicate.type === 'collection') { // Missing and empty collections are indistinguishable: both mean "no members". diff --git a/stores/clickhouse/src/storage/domains/observability/v-next/span-query.ts b/stores/clickhouse/src/storage/domains/observability/v-next/span-query.ts index e8b4c8a81c6..423e32a4ea1 100644 --- a/stores/clickhouse/src/storage/domains/observability/v-next/span-query.ts +++ b/stores/clickhouse/src/storage/domains/observability/v-next/span-query.ts @@ -125,6 +125,7 @@ function predicateFields( if (!predicate) return fields; if (predicate.type === 'boolean') for (const arg of predicate.args) predicateFields(arg, fields); else if (predicate.type === 'not') predicateFields(predicate.arg, fields); + else if (predicate.type === 'tokens') return fields; else fields.add(predicate.field); return fields; } diff --git a/stores/clickhouse/src/storage/domains/observability/v-next/thread-query.ts b/stores/clickhouse/src/storage/domains/observability/v-next/thread-query.ts index fe291b8d929..e91fde43c5b 100644 --- a/stores/clickhouse/src/storage/domains/observability/v-next/thread-query.ts +++ b/stores/clickhouse/src/storage/domains/observability/v-next/thread-query.ts @@ -39,6 +39,7 @@ function predicateFields( if (!predicate) return fields; if (predicate.type === 'boolean') for (const arg of predicate.args) predicateFields(arg, fields); else if (predicate.type === 'not') predicateFields(predicate.arg, fields); + else if (predicate.type === 'tokens') return fields; else fields.add(predicate.field); return fields; } diff --git a/stores/clickhouse/src/storage/domains/observability/v-next/token-search-rejection.test.ts b/stores/clickhouse/src/storage/domains/observability/v-next/token-search-rejection.test.ts new file mode 100644 index 00000000000..8dc9d202460 --- /dev/null +++ b/stores/clickhouse/src/storage/domains/observability/v-next/token-search-rejection.test.ts @@ -0,0 +1,45 @@ +import { + parseTraceQueryRequest, + parseTraceAggregateRequest, + planTraceQuery, + planSpanQuery, + planTraceAggregate, + planSpanAggregate, +} from '@mastra/core/storage'; +import { describe, expect, it } from 'vitest'; +import { compileClickHouseSpanQuery } from './span-query'; +import { compileClickHouseTraceAggregate, compileClickHouseSpanAggregate } from './trace-aggregate'; +import { compileClickHouseTraceQueryKeys } from './trace-query'; + +const timeRange = { from: '2026-01-01T00:00:00.000Z', to: '2026-01-02T00:00:00.000Z' }; +const options = { allowTokenSearch: true }; + +describe('unsupported indexed token search', () => { + it.each(['all', 'input', 'output', 'error', 'inputPreview', 'outputPreview', 'errorPreview'] as const)( + 'rejects %s before executing list or aggregate SQL', + field => { + const token = { op: 'hasAllTokens', left: { path: field }, right: { literal: 'needle' } } as const; + const where = { op: 'and', args: [token] } as const; + const tracesWhere = { spans: { some: where } }; + const tracePlan = planTraceQuery(parseTraceQueryRequest({ timeRange, where: tracesWhere }), options); + if (tracePlan.result !== 'traces') throw new Error('Expected a trace list plan'); + const compile = [ + () => compileClickHouseTraceQueryKeys(tracePlan), + () => compileClickHouseSpanQuery(planSpanQuery({ timeRange, where }, options)), + () => + compileClickHouseTraceAggregate( + planTraceAggregate( + parseTraceAggregateRequest({ timeRange, where: tracesWhere, measures: ['count'] }), + options, + ), + ), + () => compileClickHouseSpanAggregate(planSpanAggregate({ timeRange, where, measures: ['count'] }, options)), + ]; + for (const run of compile) { + expect(run).toThrow( + expect.objectContaining({ name: 'TraceQueryUnsupportedError', code: 'TRACE_QUERY_UNSUPPORTED' }), + ); + } + }, + ); +}); diff --git a/stores/clickhouse/src/storage/domains/observability/v-next/trace-query.ts b/stores/clickhouse/src/storage/domains/observability/v-next/trace-query.ts index 5e67fb66044..bb674198502 100644 --- a/stores/clickhouse/src/storage/domains/observability/v-next/trace-query.ts +++ b/stores/clickhouse/src/storage/domains/observability/v-next/trace-query.ts @@ -258,6 +258,8 @@ function compileScalarPredicate( parameters: ParameterBuilder, allowMetadata = false, ): string { + if (predicate.type === 'tokens') + throw new coreStorage.TraceQueryUnsupportedError('Indexed token search is not supported by this store'); if (predicate.type === 'boolean') { const parts = predicate.args.map(arg => `(${compileScalarPredicate(arg, registry, parameters, allowMetadata)})`); return parts.join(predicate.operator === 'and' ? ' AND ' : ' OR '); diff --git a/stores/duckdb/src/storage/domains/observability/thread-query.ts b/stores/duckdb/src/storage/domains/observability/thread-query.ts index 9b6ecca7662..c0e16cbc02b 100644 --- a/stores/duckdb/src/storage/domains/observability/thread-query.ts +++ b/stores/duckdb/src/storage/domains/observability/thread-query.ts @@ -34,6 +34,7 @@ function predicateFields( if (!predicate) return fields; if (predicate.type === 'boolean') for (const arg of predicate.args) predicateFields(arg, fields); else if (predicate.type === 'not') predicateFields(predicate.arg, fields); + else if (predicate.type === 'tokens') return fields; else fields.add(predicate.field); return fields; } diff --git a/stores/duckdb/src/storage/domains/observability/token-search-rejection.test.ts b/stores/duckdb/src/storage/domains/observability/token-search-rejection.test.ts new file mode 100644 index 00000000000..066979fc59a --- /dev/null +++ b/stores/duckdb/src/storage/domains/observability/token-search-rejection.test.ts @@ -0,0 +1,44 @@ +import { + parseTraceQueryRequest, + parseTraceAggregateRequest, + planTraceQuery, + planSpanQuery, + planTraceAggregate, + planSpanAggregate, +} from '@mastra/core/storage'; +import { describe, expect, it } from 'vitest'; +import { compileDuckDBSpanQuery } from './span-query'; +import { compileDuckDBTraceAggregate, compileDuckDBSpanAggregate } from './trace-aggregate'; +import { compileDuckDBTraceQuery } from './trace-query'; + +const timeRange = { from: '2026-01-01T00:00:00.000Z', to: '2026-01-02T00:00:00.000Z' }; +const options = { allowTokenSearch: true }; + +describe('unsupported indexed token search', () => { + it.each(['all', 'input', 'output', 'error', 'inputPreview', 'outputPreview', 'errorPreview'] as const)( + 'rejects %s before executing list or aggregate SQL', + field => { + const token = { op: 'hasAllTokens', left: { path: field }, right: { literal: 'needle' } } as const; + const where = { op: 'and', args: [token] } as const; + const tracesWhere = { spans: { some: where } }; + const compile = [ + () => + compileDuckDBTraceQuery(planTraceQuery(parseTraceQueryRequest({ timeRange, where: tracesWhere }), options)), + () => compileDuckDBSpanQuery(planSpanQuery({ timeRange, where }, options)), + () => + compileDuckDBTraceAggregate( + planTraceAggregate( + parseTraceAggregateRequest({ timeRange, where: tracesWhere, measures: ['count'] }), + options, + ), + ), + () => compileDuckDBSpanAggregate(planSpanAggregate({ timeRange, where, measures: ['count'] }, options)), + ]; + for (const run of compile) { + expect(run).toThrow( + expect.objectContaining({ name: 'TraceQueryUnsupportedError', code: 'TRACE_QUERY_UNSUPPORTED' }), + ); + } + }, + ); +}); diff --git a/stores/duckdb/src/storage/domains/observability/trace-query.ts b/stores/duckdb/src/storage/domains/observability/trace-query.ts index 645c743f37f..0ceb34f18c2 100644 --- a/stores/duckdb/src/storage/domains/observability/trace-query.ts +++ b/stores/duckdb/src/storage/domains/observability/trace-query.ts @@ -197,6 +197,8 @@ function compileScalarPredicate( registry: Partial>, allowMetadata = false, ): SqlFragment { + if (predicate.type === 'tokens') + throw new coreStorage.TraceQueryUnsupportedError('Indexed token search is not supported by this store'); if (predicate.type === 'boolean') { const values: unknown[] = []; const parts = predicate.args.map(arg => { @@ -439,7 +441,7 @@ const ROOT_PUSHDOWN_FIELDS = new Set([ ]); function isRootPushdownPredicate(predicate: TrustedTraceQueryPredicate): boolean { - if (predicate.type === 'relation') return false; + if (predicate.type === 'relation' || predicate.type === 'tokens') return false; if (predicate.type === 'boolean') return predicate.args.every(isRootPushdownPredicate); if (predicate.type === 'not') return isRootPushdownPredicate(predicate.arg); return ROOT_PUSHDOWN_FIELDS.has(predicate.field); diff --git a/stores/pg/src/storage/domains/observability/v-next/thread-query.ts b/stores/pg/src/storage/domains/observability/v-next/thread-query.ts index 22a850e1ae9..d66f3faf5dd 100644 --- a/stores/pg/src/storage/domains/observability/v-next/thread-query.ts +++ b/stores/pg/src/storage/domains/observability/v-next/thread-query.ts @@ -36,6 +36,7 @@ function predicateFields( if (!predicate) return fields; if (predicate.type === 'boolean') for (const arg of predicate.args) predicateFields(arg, fields); else if (predicate.type === 'not') predicateFields(predicate.arg, fields); + else if (predicate.type === 'tokens') return fields; else fields.add(predicate.field); return fields; } diff --git a/stores/pg/src/storage/domains/observability/v-next/token-search-rejection.test.ts b/stores/pg/src/storage/domains/observability/v-next/token-search-rejection.test.ts new file mode 100644 index 00000000000..83ea3da092c --- /dev/null +++ b/stores/pg/src/storage/domains/observability/v-next/token-search-rejection.test.ts @@ -0,0 +1,49 @@ +import { + parseTraceQueryRequest, + parseTraceAggregateRequest, + planTraceQuery, + planSpanQuery, + planTraceAggregate, + planSpanAggregate, +} from '@mastra/core/storage'; +import { describe, expect, it } from 'vitest'; +import { compilePostgresSpanQuery } from './span-query'; +import { compilePostgresTraceAggregate, compilePostgresSpanAggregate } from './trace-aggregate'; +import { compilePostgresTraceQuery } from './trace-query'; + +const timeRange = { from: '2026-01-01T00:00:00.000Z', to: '2026-01-02T00:00:00.000Z' }; +const options = { allowTokenSearch: true }; + +describe('unsupported indexed token search', () => { + it.each(['all', 'input', 'output', 'error', 'inputPreview', 'outputPreview', 'errorPreview'] as const)( + 'rejects %s before executing list or aggregate SQL', + field => { + const token = { op: 'hasAllTokens', left: { path: field }, right: { literal: 'needle' } } as const; + const where = { op: 'and', args: [token] } as const; + const tracesWhere = { spans: { some: where } }; + const compile = [ + () => + compilePostgresTraceQuery( + 'public', + planTraceQuery(parseTraceQueryRequest({ timeRange, where: tracesWhere }), options), + ), + () => compilePostgresSpanQuery('public', planSpanQuery({ timeRange, where }, options)), + () => + compilePostgresTraceAggregate( + 'public', + planTraceAggregate( + parseTraceAggregateRequest({ timeRange, where: tracesWhere, measures: ['count'] }), + options, + ), + ), + () => + compilePostgresSpanAggregate('public', planSpanAggregate({ timeRange, where, measures: ['count'] }, options)), + ]; + for (const run of compile) { + expect(run).toThrow( + expect.objectContaining({ name: 'TraceQueryUnsupportedError', code: 'TRACE_QUERY_UNSUPPORTED' }), + ); + } + }, + ); +}); diff --git a/stores/pg/src/storage/domains/observability/v-next/trace-query.ts b/stores/pg/src/storage/domains/observability/v-next/trace-query.ts index a769220184c..f8d742b1802 100644 --- a/stores/pg/src/storage/domains/observability/v-next/trace-query.ts +++ b/stores/pg/src/storage/domains/observability/v-next/trace-query.ts @@ -294,6 +294,8 @@ function compileScalarPredicate( parameterOffset: number, allowMetadata = false, ): SqlFragment { + if (predicate.type === 'tokens') + throw new coreStorage.TraceQueryUnsupportedError('Indexed token search is not supported by this store'); if (predicate.type === 'boolean') { const values: unknown[] = []; const parts = predicate.args.map(arg => { @@ -488,7 +490,7 @@ const ROOT_PUSHDOWN_FIELDS = new Set([ ]); function isRootPushdownPredicate(predicate: TrustedTraceQueryPredicate): boolean { - if (predicate.type === 'relation') return false; + if (predicate.type === 'relation' || predicate.type === 'tokens') return false; if (predicate.type === 'boolean') return predicate.args.every(isRootPushdownPredicate); if (predicate.type === 'not') return isRootPushdownPredicate(predicate.arg); return ROOT_PUSHDOWN_FIELDS.has(predicate.field);