🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(in-app-agent): background execution refactoring - move runtime ownership to worker (#15981)
Lysander Kiesele68e201a66ac
diff --git a/.env.dev.example b/.env.dev.exampleindex 667c11a3cc..7a377d2916 100644--- a/.env.dev.example+++ b/.env.dev.example@@ -219,6 +219,10 @@ LANGFUSE_IN_APP_AGENT_AWS_PROFILE="playground"QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED="true"# LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY=5+# Web-only admission ceilings.+# LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER=5+# LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG=20+# V4 migration flags. Pinned to dual write mode to ensure we cover the tests;# bare deployments get the flipped v4 code defaults (events_only / direct).# Write target: `legacy` | `dual` | `events_only`.diff --git a/knip.jsonc b/knip.jsoncindex 6b23568b43..f7f75b6bc4 100644--- a/knip.jsonc+++ b/knip.jsonc@@ -32,13 +32,6 @@"raw-loader",// The next-auth patch requires this module from core/lib/oauth/client.js."https-proxy-agent",- // In-app-agent servertests vi.mock these runtime deps of the shared- // agent module (@langfuse/shared/in-app-agent/server); the mock- // specifiers must resolve from web.- "@aws-sdk/client-lambda-microvms",- "@aws-sdk/credential-providers",- "dockerode",- "@types/dockerode",],},"ee": {diff --git a/packages/shared/AGENTS.md b/packages/shared/AGENTS.mdindex e508b3eb42..0f7b5ca3a8 100644--- a/packages/shared/AGENTS.md+++ b/packages/shared/AGENTS.md@@ -55,16 +55,14 @@signature helpers for secrets and signed payloads.- `@langfuse/shared/query` via `src/features/query/index.ts`: dashboard query feature.- `@langfuse/shared/in-app-agent` via `src/in-app-agent/index.ts`:- client-safe in-app-agent contracts (AG-UI schemas, constants, id helpers,- and durable interrupt parsing shared by browser and server runtimes).- `AgUiRunAgentInput` is a compile-time-only execution contract; there is no- runtime input or browser runtime-state schema. Never re-export server code- here.-- `@langfuse/shared/in-app-agent/server` (plus per-module subpaths via the- `./in-app-agent/server/*` wildcard) via `src/in-app-agent/server/`:- the in-app-agent runtime (Mastra/Bedrock/MCP loop, tools, persistence,- sandbox), consumed by web's router/watch adapters and the worker execution- processor.+ client-safe durable in-app-agent contracts: AG-UI messages/events/context,+ run requests/status/errors, approval events, constants, message helpers,+ and interrupt parsing. Never re-export server code here.+- In-app-agent server contracts use explicit subpaths only:+ `persistence`, `runLifecycle`, `tunables`, `eventCompaction`, `mcpPolicy`,+ `toolResults`, `toolErrors`, and `systemPrompt`. These are storage/lifecycle or durable+ cross-process policy contracts; the Mastra runtime and sandbox belong to the+ worker.- Narrower exported subpaths also exist for targeted imports:`@langfuse/shared/src/server/auth/apiKeys`,`@langfuse/shared/src/server/ee/ingestionMasking`, anddiff --git a/packages/shared/package.json b/packages/shared/package.jsonindex d7c41192a6..91538fab2e 100644--- a/packages/shared/package.json+++ b/packages/shared/package.json@@ -67,17 +67,37 @@"import": "./dist/src/in-app-agent/index.js","require": "./dist/src/in-app-agent/index.js"},- "./in-app-agent/server": {- "import": "./dist/src/in-app-agent/server/index.js",- "require": "./dist/src/in-app-agent/server/index.js"+ "./in-app-agent/server/persistence": {+ "import": "./dist/src/in-app-agent/server/persistence.js",+ "require": "./dist/src/in-app-agent/server/persistence.js"},- "./in-app-agent/server/sandbox": {- "import": "./dist/src/in-app-agent/server/sandbox/index.js",- "require": "./dist/src/in-app-agent/server/sandbox/index.js"+ "./in-app-agent/server/runLifecycle": {+ "import": "./dist/src/in-app-agent/server/runLifecycle.js",+ "require": "./dist/src/in-app-agent/server/runLifecycle.js"},- "./in-app-agent/server/*": {- "import": "./dist/src/in-app-agent/server/*.js",- "require": "./dist/src/in-app-agent/server/*.js"+ "./in-app-agent/server/tunables": {+ "import": "./dist/src/in-app-agent/server/tunables.js",+ "require": "./dist/src/in-app-agent/server/tunables.js"+ },+ "./in-app-agent/server/eventCompaction": {+ "import": "./dist/src/in-app-agent/server/eventCompaction.js",+ "require": "./dist/src/in-app-agent/server/eventCompaction.js"+ },+ "./in-app-agent/server/mcpPolicy": {+ "import": "./dist/src/in-app-agent/server/mcpPolicy.js",+ "require": "./dist/src/in-app-agent/server/mcpPolicy.js"+ },+ "./in-app-agent/server/toolResults": {+ "import": "./dist/src/in-app-agent/server/toolResults.js",+ "require": "./dist/src/in-app-agent/server/toolResults.js"+ },+ "./in-app-agent/server/toolErrors": {+ "import": "./dist/src/in-app-agent/server/toolErrors.js",+ "require": "./dist/src/in-app-agent/server/toolErrors.js"+ },+ "./in-app-agent/server/systemPrompt": {+ "import": "./dist/src/in-app-agent/server/systemPrompt.js",+ "require": "./dist/src/in-app-agent/server/systemPrompt.js"}},"scripts": {@@ -112,7 +132,6 @@"dependencies": {"@ag-ui/client": "^0.0.52","@ag-ui/core": "^0.0.52",- "@ag-ui/mastra": "1.1.1","@ai-sdk/amazon-bedrock": "^5.0.25","@ai-sdk/anthropic": "^4.0.5","@ai-sdk/azure": "^4.0.5",@@ -122,7 +141,6 @@"@ai-sdk/openai-compatible": "^3.0.3","@aws-sdk/client-cloudwatch": "catalog:","@aws-sdk/client-lambda": "catalog:",- "@aws-sdk/client-lambda-microvms": "catalog:","@aws-sdk/client-s3": "catalog:","@aws-sdk/client-sesv2": "catalog:","@aws-sdk/credential-providers": "catalog:",@@ -131,13 +149,10 @@"@azure/storage-blob": "^12.26.0","@clickhouse/client": "1.23.1","@google-cloud/storage": "^7.19.0",- "@mastra/core": "1.46.0",- "@mastra/mcp": "1.8.1","@opentelemetry/api": ">=1.0.0 <1.10.0","@opentelemetry/otlp-transformer": "^0.220.0","@opentelemetry/resources": "^2.9.0","@opentelemetry/sdk-trace-base": "^2.9.0",- "@paralleldrive/cuid2": "^2.2.2","@prisma/client": "^6.19.3","@react-email/components": "^0.5.1","@react-email/render": "^1.2.1",@@ -146,7 +161,6 @@"@smithy/node-http-handler": "4.5.1","@types/bcryptjs": "^2.4.6","ai": "^7.0.0",- "ai-sdk-amazon-bedrock-v4": "npm:@ai-sdk/[email protected]","ajv": "^8.18.0","ajv-formats": "^3.0.1","bcryptjs": "^2.4.3",@@ -159,7 +173,6 @@"ioredis": "^5.10.1","ipaddr.js": "^2.2.0","jsonpath-plus": "10.3.0",- "langfuse": "3.38.4","langfuse-langchain": "3.38.20","lodash": "^4.18.1","lossless-json": "^4.1.1",@@ -173,19 +186,16 @@"undici": "^7.29.0","uuid": "^14.0.0","winston": "^3.15.0",- "yaml": "^2.9.0","zod": "^4.3.6"},"devDependencies": {"@opentelemetry/context-async-hooks": "^2.9.0","@repo/eslint-config": "workspace:*","@repo/typescript-config": "workspace:*",- "@types/dockerode": "^4.0.1","@types/lodash": "^4.17.24","@types/node": "^24.3.0","@types/nodemailer": "^8.0.1","@types/react": "19.2.14",- "dockerode": "^4.0.9","dotenv-cli": "^7.4.4","eslint": "catalog:","prisma": "^6.19.3",diff --git a/packages/shared/scripts/seeder/seed-postgres.ts b/packages/shared/scripts/seeder/seed-postgres.tsindex e064c70267..dd8088c51a 100644--- a/packages/shared/scripts/seeder/seed-postgres.ts+++ b/packages/shared/scripts/seeder/seed-postgres.ts@@ -3,7 +3,7 @@ import { parseArgs } from "node:util";import { hash } from "bcryptjs";import { v4 } from "uuid";import { encrypt } from "../../src/encryption";-import { IN_APP_AGENT_SYSTEM_PROMPT_TEMPLATE } from "../../src/in-app-agent/server/prompts/in-app-agent-system-prompt";+import { IN_APP_AGENT_SYSTEM_PROMPT_TEMPLATE } from "../../src/in-app-agent/server/systemPrompt";import {EvalTemplateSourceCodeLanguage,EvalTemplateType,diff --git a/packages/shared/scripts/seeder/utils/in-app-agent-seed.ts b/packages/shared/scripts/seeder/utils/in-app-agent-seed.tsindex c408c8b0df..cfa8c0ad05 100644--- a/packages/shared/scripts/seeder/utils/in-app-agent-seed.ts+++ b/packages/shared/scripts/seeder/utils/in-app-agent-seed.ts@@ -1,9 +1,9 @@import {- InAppAgentRunStatus,type Prisma,type PrismaClient,type Prompt,} from "../../../src/index";+import { InAppAgentRunStatus } from "../../../src/features/inAppAgent/types";type SummaryPrompt = Pick<Prompt,diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.tsindex 7d9461aff3..8fd573c109 100644--- a/packages/shared/src/env.ts+++ b/packages/shared/src/env.ts@@ -522,76 +522,6 @@ const EnvSchema = z.object({LANGFUSE_AWS_BEDROCK_REGION: z.string().optional(),LANGFUSE_AWS_BEDROCK_MODEL: z.string().optional(),LANGFUSE_AWS_BEDROCK_SMALL_MODEL: z.string().optional(),- LANGFUSE_IN_APP_AGENT_AWS_PROFILE: z.string().optional(),- // Ambient AWS profile of the host process; the in-app agent prefers it over- // the configured Bedrock profile so local dev credentials win.- AWS_PROFILE: z.string().optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER: z- .enum(["dangerous-docker", "lambda-microvm"])- .optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER: z- .string()- .optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN: z- .string()- .optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN:- z.string().optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION: z- .string()- .optional(),- LANGFUSE_IN_APP_AGENT_HEARTBEAT_INTERVAL_MS: z.coerce- .number()- .int()- .positive()- .default(5_000),- LANGFUSE_IN_APP_AGENT_HEARTBEAT_STALE_MS: z.coerce- .number()- .int()- .positive()- .default(60_000),- LANGFUSE_IN_APP_AGENT_QUEUE_TIMEOUT_MS: z.coerce- .number()- .int()- .positive()- .default(5 * 60_000),- LANGFUSE_IN_APP_AGENT_RUN_MAX_DURATION_MS: z.coerce- .number()- .int()- .positive()- .default(15 * 60_000),- LANGFUSE_IN_APP_AGENT_APPROVAL_TTL_MS: z.coerce- .number()- .int()- .positive()- .default(24 * 60 * 60_000),- // Flat safety ceilings on concurrent non-terminal runs. Per region, so a- // small region (JP, staging) can be tightened below its execution capacity.- LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER: z.coerce- .number()- .int()- .positive()- .default(5),- LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG: z.coerce- .number()- .int()- .positive()- .default(20),- LANGFUSE_IN_APP_AGENT_WATCH_TAIL_POLL_MS: z.coerce- .number()- .int()- .positive()- .default(1_000),- LANGFUSE_IN_APP_AGENT_WATCH_KEEPALIVE_MS: z.coerce- .number()- .int()- .positive()- .default(15_000),- LANGFUSE_IN_APP_AGENT_WATCH_MAX_CONNECTION_MS: z.coerce- .number()- .int()- .positive()- .default(90_000),// API Performance Flags// Whether to add a `FINAL` modifier to the observations CTE in GET /api/public/traces.diff --git a/packages/shared/src/in-app-agent/approvalEvents.ts b/packages/shared/src/in-app-agent/approvalEvents.tsnew file mode 100644index 0000000000..e2a1736dc7--- /dev/null+++ b/packages/shared/src/in-app-agent/approvalEvents.ts@@ -0,0 +1,42 @@+import { EventType } from "@ag-ui/core";+import { z } from "zod";++import type { AgUiCustomEvent, AgUiEvent } from "./schema";++/** Render-only approval history stored in the append-only event stream. */+export const IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME =+ "langfuse_approval_decision";++export const InAppAgentApprovalDecisionSchema = z.object({+ toolCallId: z.string().min(1),+ approved: z.boolean(),+ decidedByUserId: z.string().min(1),+});++export type InAppAgentApprovalDecision = z.infer<+ typeof InAppAgentApprovalDecisionSchema+>;++export function buildInAppAgentApprovalDecisionEvent(+ decision: InAppAgentApprovalDecision,+): AgUiCustomEvent {+ return {+ type: EventType.CUSTOM,+ name: IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,+ value: decision,+ };+}++export function parseInAppAgentApprovalDecisionEvent(+ event: AgUiEvent,+): InAppAgentApprovalDecision | undefined {+ if (+ event.type !== EventType.CUSTOM ||+ event.name !== IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME+ ) {+ return undefined;+ }++ const parsed = InAppAgentApprovalDecisionSchema.safeParse(event.value);+ return parsed.success ? parsed.data : undefined;+}diff --git a/packages/shared/src/in-app-agent/backgroundWatch.ts b/packages/shared/src/in-app-agent/backgroundWatch.tsdeleted file mode 100644index 2878726658..0000000000--- a/packages/shared/src/in-app-agent/backgroundWatch.ts+++ /dev/null@@ -1,117 +0,0 @@-// Browser-safe approval and watch contracts shared by web and worker code.--import { EventType } from "@ag-ui/core";-import { z } from "zod";--import {- InAppAgentRunStatus,- InAppAgentRunStatusSchema,-} from "../features/inAppAgent/types";-import type { AgUiCustomEvent, AgUiEvent } from "./schema";--/** Render-only approval history stored in the append-only event stream. */-export const IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME =- "langfuse_approval_decision";--export const InAppAgentApprovalDecisionSchema = z.object({- toolCallId: z.string().min(1),- approved: z.boolean(),- decidedByUserId: z.string().min(1),- /** Optional render-only scope; durable policy comes from conversation grants. */- scope: z.enum(["once", "conversation"]).optional(),-});--export type InAppAgentApprovalDecision = z.infer<- typeof InAppAgentApprovalDecisionSchema->;--export function buildInAppAgentApprovalDecisionEvent(- decision: InAppAgentApprovalDecision,-): AgUiCustomEvent {- return {- type: EventType.CUSTOM,- name: IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,- value: decision,- };-}--export function parseInAppAgentApprovalDecisionEvent(- event: AgUiEvent,-): InAppAgentApprovalDecision | undefined {- if (- event.type !== EventType.CUSTOM ||- event.name !== IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME- ) {- return undefined;- }-- const parsed = InAppAgentApprovalDecisionSchema.safeParse(event.value);-- return parsed.success ? parsed.data : undefined;-}--/** Conversation-scoped watch frames keyed by persisted sequence number. */-export const InAppAgentWatchStatusFrameSchema = z.object({- type: z.literal("status"),- runId: z.string(),- status: InAppAgentRunStatusSchema,- errorCode: z.string().nullable().optional(),- /** Cancellation is cooperative, so this may be true while status is RUNNING. */- cancelRequested: z.boolean().optional(),-});--export const InAppAgentWatchEventFrameSchema = z.object({- type: z.literal("event"),- sequenceNumber: z.number().int(),- event: z.record(z.string(), z.unknown()),-});--export const InAppAgentWatchErrorFrameSchema = z.object({- type: z.literal("error"),- code: z.string(),- message: z.string(),-});--/** Only this frame tells clients to stop reconnecting. */-export const InAppAgentWatchDoneFrameSchema = z.object({- type: z.literal("done"),-});--export const InAppAgentWatchFrameSchema = z.discriminatedUnion("type", [- InAppAgentWatchStatusFrameSchema,- InAppAgentWatchEventFrameSchema,- InAppAgentWatchErrorFrameSchema,- InAppAgentWatchDoneFrameSchema,-]);--export type InAppAgentWatchFrame = z.infer<typeof InAppAgentWatchFrameSchema>;--/** A parked approval occupies neither a worker nor the conversation slot. */-export const IN_APP_AGENT_ACTIVE_RUN_STATUSES: readonly InAppAgentRunStatus[] =- [InAppAgentRunStatus.QUEUED, InAppAgentRunStatus.RUNNING];--export function isActiveInAppAgentRunStatus(- status: InAppAgentRunStatus,-): boolean {- return IN_APP_AGENT_ACTIVE_RUN_STATUSES.includes(status);-}--/**- * Runs the user still has to deal with: executing, or parked on their decision.- *- * Wider than {@link IN_APP_AGENT_ACTIVE_RUN_STATUSES} on purpose. A parked- * approval sets `finishedAt`, so `finishedAt: null` finds executing runs but- * silently misses the one state that is literally waiting for the user.- */-export const IN_APP_AGENT_UNSETTLED_RUN_STATUSES: readonly InAppAgentRunStatus[] =- [- InAppAgentRunStatus.QUEUED,- InAppAgentRunStatus.RUNNING,- InAppAgentRunStatus.AWAITING_APPROVAL,- ];--export function isUnsettledInAppAgentRunStatus(- status: InAppAgentRunStatus,-): boolean {- return IN_APP_AGENT_UNSETTLED_RUN_STATUSES.includes(status);-}diff --git a/packages/shared/src/in-app-agent/constants.ts b/packages/shared/src/in-app-agent/constants.tsindex 3f738b0262..b15291b1b8 100644--- a/packages/shared/src/in-app-agent/constants.ts+++ b/packages/shared/src/in-app-agent/constants.ts@@ -1,25 +1,36 @@+import { InAppAgentRunStatus } from "../features/inAppAgent/types";+// Avoid renaming this as the FE is aware of this when rendering, renaming it would cause history issuesexport const IN_APP_AGENT_REDIRECT_TOOL_NAME = "langfuse_proposeRedirect";export const IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE = "tool_call_rejected";+export const IN_APP_AGENT_GENERIC_ERROR_MESSAGE =+ "An error occurred. Please try again or start a new conversation.";++/** Runs that are not yet in a terminal state, including parked approvals. */+export const IN_APP_AGENT_UNSETTLED_RUN_STATUSES: readonly InAppAgentRunStatus[] =+ [+ InAppAgentRunStatus.QUEUED,+ InAppAgentRunStatus.RUNNING,+ InAppAgentRunStatus.AWAITING_APPROVAL,+ ];++export function isUnsettledInAppAgentRunStatus(+ status: InAppAgentRunStatus,+): boolean {+ return IN_APP_AGENT_UNSETTLED_RUN_STATUSES.includes(status);+}+export const IN_APP_AGENT_SILENT_MCP_OUTPUT_TYPE = "silent-mcp-output";export const IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE ="Output saved to /workspace/tool_calls";-export const IN_APP_AGENT_MCP_USER_AGENT = "langfuse-in-app-agent";-// Header used only by Langfuse's server-side in-app agent when it calls the// Langfuse MCP endpoint with a temporary in-app-agent API key and run override.export const IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER ="x-langfuse-in-app-agent-tool-override";-export const IN_APP_AGENT_LOCAL_SANDBOX_IMAGE =- "langfuse-in-app-agent-sandbox:latest";--export const IN_APP_AGENT_GENERIC_ERROR_MESSAGE =- "An error occurred. Please try again or start a new conversation.";-// Observation ids stay equal to the per-turn run id so persisted messages,// feedback, and traced generations all point at the same Langfuse observation.export const getInAppAgentInstrumentationObservationId = (runId: string) =>diff --git a/packages/shared/src/in-app-agent/index.ts b/packages/shared/src/in-app-agent/index.tsindex 7231aa70f8..b558fa3d5e 100644--- a/packages/shared/src/in-app-agent/index.ts+++ b/packages/shared/src/in-app-agent/index.ts@@ -2,8 +2,8 @@// re-exported here — this barrel is imported by web client components and is// covered by the client-bundle scan.export * from "./schema";-export * from "./backgroundWatch";+export * from "./approvalEvents";export * from "./constants";-export * from "./ids";export * from "./interrupts";export * from "./messages";+export * from "../features/inAppAgent/types";diff --git a/packages/shared/src/in-app-agent/schema.ts b/packages/shared/src/in-app-agent/schema.tsindex b277458789..6205159be6 100644--- a/packages/shared/src/in-app-agent/schema.ts+++ b/packages/shared/src/in-app-agent/schema.ts@@ -29,24 +29,6 @@ const AgUiToolCallSchema = z.object({encryptedValue: z.string().optional(),});-export const InAppAgentMessageFeedbackValueSchema = z.enum([- "thumbs_up",- "thumbs_down",-]);--export type InAppAgentMessageFeedbackValue = z.infer<- typeof InAppAgentMessageFeedbackValueSchema->;--export const InAppAgentMessageFeedbackSchema = z.object({- value: InAppAgentMessageFeedbackValueSchema,- comment: z.string().nullable(),-});--export type InAppAgentMessageFeedback = z.infer<- typeof InAppAgentMessageFeedbackSchema->;-export const InAppAgentRateLimitErrorResponseSchema = z.object({code: z.literal("rate_limited"),details: z.object({@@ -122,7 +104,6 @@ export const AgUiMessageSchema = z.discriminatedUnion("role", [role: z.literal("assistant"),content: z.string().optional(),toolCalls: z.array(AgUiToolCallSchema).optional(),- feedback: InAppAgentMessageFeedbackSchema.optional(),runId: z.string().optional(),}),AgUiBaseMessageSchema.extend({@@ -153,62 +134,12 @@ export const AgUiMessageSchema = z.discriminatedUnion("role", [export type AgUiMessage = z.infer<typeof AgUiMessageSchema>;-const AbsoluteHttpUrlSchema = z.string().transform((value, ctx) => {- let parsedUrl: URL;-- try {- parsedUrl = new URL(value);- } catch {- ctx.addIssue({- code: "custom",- message: "URL must be absolute",- });- return z.NEVER;- }-- if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {- ctx.addIssue({- code: "custom",- message: "URL protocol must be http or https",- });- return z.NEVER;- }-- return parsedUrl.href;-});--export const InAppAgentMessageSourceSchema = z.object({- title: z.string(),- url: AbsoluteHttpUrlSchema,- faviconUrl: AbsoluteHttpUrlSchema,-});--export type InAppAgentMessageSource = z.infer<- typeof InAppAgentMessageSourceSchema->;--type AgUiTool = {- name: string;- description: string;- parameters?: unknown;- metadata?: Record<string, unknown>;-};-export const AgUiContextSchema = z.object({description: z.string(),value: z.string(),});-export type AgUiRunAgentInput = {- threadId: string;- runId: string;- parentRunId?: string;- state?: unknown;- messages: AgUiMessage[];- tools: AgUiTool[];- context: Array<z.infer<typeof AgUiContextSchema>>;- forwardedProps?: unknown;-};+export type AgUiContext = Array<z.infer<typeof AgUiContextSchema>>;export type AgUiEvent = {type: EventType;@@ -234,19 +165,3 @@ export const InAppAgentToolApprovalRequestSchema = z.object({export type InAppAgentToolApprovalRequest = z.infer<typeof InAppAgentToolApprovalRequestSchema>;--export const ResumeForwardedPropsSchema = z.object({- command: z.object({- resume: z.object({- approved: z.boolean(),- continuationNumber: z.number().int().positive().optional(),- rootRunId: z.string().min(1).optional(),- traceStartedAt: z.iso.datetime({ offset: true }).optional(),- approvalRequestedAt: z.iso.datetime({ offset: true }).optional(),- approvalDecidedAt: z.iso.datetime({ offset: true }).optional(),- approvalRequest: InAppAgentToolApprovalRequestSchema,- }),- }),-});--export type ResumeForwardedProps = z.infer<typeof ResumeForwardedPropsSchema>;diff --git a/packages/shared/src/in-app-agent/server/access.ts b/packages/shared/src/in-app-agent/server/access.tsdeleted file mode 100644index 113cb42237..0000000000--- a/packages/shared/src/in-app-agent/server/access.ts+++ /dev/null@@ -1,17 +0,0 @@-import { LangfuseNotFoundError } from "../../index";-import type { InAppAgentConversation } from "../../db";--/** Owner-only authorization with a non-enumerating failure. */-export function assertConversationAccess(params: {- conversation: Pick<InAppAgentConversation, "createdByUserId" | "deletedAt">;- userId: string;-}): void {- const { conversation } = params;-- if (- conversation.deletedAt ||- conversation.createdByUserId !== params.userId- ) {- throw new LangfuseNotFoundError("Agent conversation not found");- }-}diff --git a/packages/shared/src/in-app-agent/server/index.ts b/packages/shared/src/in-app-agent/server/index.tsdeleted file mode 100644index 755abe5ee8..0000000000--- a/packages/shared/src/in-app-agent/server/index.ts+++ /dev/null@@ -1,18 +0,0 @@-// Server entry of the in-app-agent runtime, consumed by web's router/watch-// adapters and the worker queue processor.-export * from "./access";-export * from "./agent";-export * from "./tools";-export * from "./mcpPolicy";-export * from "./toolResults";-export * from "./human-in-the-loop";-export * from "./instrumentation";-export * from "./eventCompaction";-export * from "./persistence";-export * from "./runLifecycle";-export * from "./tunables";-export * from "./watch";-export * from "./promptClient";-export * from "./skills";-export * from "./sandbox";-export * from "./prompts/in-app-agent-system-prompt";diff --git a/packages/shared/src/in-app-agent/server/mcpPolicy.ts b/packages/shared/src/in-app-agent/server/mcpPolicy.tsindex 23402e96d7..777eaad9a1 100644--- a/packages/shared/src/in-app-agent/server/mcpPolicy.ts+++ b/packages/shared/src/in-app-agent/server/mcpPolicy.ts@@ -2,6 +2,7 @@ import type { ProjectScope } from "../../features/rbac/projectAccessRights";import { hasProjectAccessByRole } from "../../features/rbac/projectAccessRights";import { Role } from "../../db";import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "../constants";+import { z } from "zod";type InAppAgentMcpToolApproval = "auto" | "approval";@@ -356,6 +357,36 @@ export const IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES =) as InAppAgentLangfuseMcpToolName[],);+const InAppAgentLangfuseMcpToolNameSchema =+ z.custom<InAppAgentLangfuseMcpToolName>(+ (value) =>+ typeof value === "string" &&+ IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES.has(+ value as InAppAgentLangfuseMcpToolName,+ ),+ { message: "Invalid MCP tool name" },+ );++export const InAppAgentMcpRunOverrideSchema = z+ .union([+ z.object({ toolNames: z.array(InAppAgentLangfuseMcpToolNameSchema) }),+ z.object({ toolName: InAppAgentLangfuseMcpToolNameSchema }),+ ])+ .transform((override) => ({+ toolNames:+ "toolNames" in override ? override.toolNames : [override.toolName],+ }));++export async function createInAppAgentMcpRunOverride(params: {+ toolNames: InAppAgentLangfuseMcpToolName[];+}) {+ return JSON.stringify({+ // Older web pods read the singular field during rolling deploys.+ toolName: params.toolNames[0],+ toolNames: params.toolNames,+ });+}+export const IN_APP_AGENT_AUTO_APPROVED_EXTERNAL_TOOL_NAMES = new Set([IN_APP_AGENT_REDIRECT_TOOL_NAME,]);diff --git a/packages/shared/src/in-app-agent/server/persistence.ts b/packages/shared/src/in-app-agent/server/persistence.tsindex 9192abab4c..b6ee67cf6a 100644--- a/packages/shared/src/in-app-agent/server/persistence.ts+++ b/packages/shared/src/in-app-agent/server/persistence.ts@@ -1,11 +1,11 @@import { compactEvents } from "@ag-ui/client";import { EventType } from "@ag-ui/core";+import { LangfuseNotFoundError } from "../../index";import {InAppAgentRunErrorCode,InAppAgentRunStatus,- LangfuseNotFoundError,-} from "../../index";+} from "../../features/inAppAgent/types";import {ChatMessageRole,ChatMessageType,@@ -33,7 +33,6 @@ import {dropEmptyAssistantMessages,dropUnpairedAssistantToolCalls,} from "../messages";-import { assertConversationAccess } from "./access";import { compactPersistedEventDeltas } from "./eventCompaction";import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "../constants";import { safeJsonParse } from "../../utils/json";@@ -48,6 +47,19 @@ import { getToolFailureMessage } from "./toolErrors";export const ACTIVE_RUN_CONFLICT_MESSAGE ="Assistant is already responding in this conversation";+/** Owner-only authorization with a non-enumerating failure. */+export function assertOwnedConversation(params: {+ conversation: Pick<InAppAgentConversation, "createdByUserId" | "deletedAt">;+ userId: string;+}): void {+ if (+ params.conversation.deletedAt ||+ params.conversation.createdByUserId !== params.userId+ ) {+ throw new LangfuseNotFoundError("Agent conversation not found");+ }+}+export type SerializedInAppAgentConversation = {id: string;title: string | null;@@ -99,7 +111,7 @@ export async function getOwnedConversationOrThrow(params: {throw new LangfuseNotFoundError("Agent conversation not found");}- assertConversationAccess({+ assertOwnedConversation({conversation,userId: params.userId,});@@ -123,7 +135,7 @@ export async function ensureOwnedConversation(params: {});if (existing) {- assertConversationAccess({+ assertOwnedConversation({conversation: existing,userId: params.userId,});diff --git a/packages/shared/src/in-app-agent/server/runLifecycle.test.ts b/packages/shared/src/in-app-agent/server/runLifecycle.test.tsindex 7e2266a42a..26200ad5ba 100644--- a/packages/shared/src/in-app-agent/server/runLifecycle.test.ts+++ b/packages/shared/src/in-app-agent/server/runLifecycle.test.ts@@ -1,7 +1,7 @@import { EventType } from "@ag-ui/core";import { describe, expect, it, vi } from "vitest";-import { InAppAgentRunStatus } from "../../index";+import { InAppAgentRunStatus } from "../../features/inAppAgent/types";import type { PrismaClient } from "../../db";import {createQueuedRun,diff --git a/packages/shared/src/in-app-agent/server/runLifecycle.ts b/packages/shared/src/in-app-agent/server/runLifecycle.tsindex 85dc58afaa..d9604b70c1 100644--- a/packages/shared/src/in-app-agent/server/runLifecycle.ts+++ b/packages/shared/src/in-app-agent/server/runLifecycle.ts@@ -1,16 +1,13 @@+import { LangfuseConflictError } from "../../index";import {InAppAgentRunErrorCode,InAppAgentRunStatus,InAppAgentRunStatusSchema,- LangfuseConflictError,-} from "../../index";+} from "../../features/inAppAgent/types";import { Prisma } from "../../db";import type { InAppAgentRun, PrismaClient } from "../../db";import { logger } from "../../server";-import {- buildInAppAgentApprovalDecisionEvent,- IN_APP_AGENT_UNSETTLED_RUN_STATUSES,-} from "../backgroundWatch";+import { buildInAppAgentApprovalDecisionEvent } from "../approvalEvents";import type { AgUiEvent } from "../schema";import type { InAppAgentPrefixedLangfuseMcpToolName } from "./mcpPolicy";import {@@ -18,6 +15,7 @@ import {resolveInAppAgentRootRunId,type InAppAgentRunRequest,} from "../../features/inAppAgent/types";+import { IN_APP_AGENT_UNSETTLED_RUN_STATUSES } from "../constants";import {ACTIVE_RUN_CONFLICT_MESSAGE,lockConversation,@@ -330,9 +328,6 @@ export async function decideToolApproval(params: {toolCallId: params.toolCallId,approved: params.approved,decidedByUserId: params.decidedByUserId,- ...(params.alwaysAllowToolName- ? { scope: "conversation" as const }- : {}),}),});diff --git a/packages/shared/src/in-app-agent/server/prompts/in-app-agent-system-prompt.ts b/packages/shared/src/in-app-agent/server/systemPrompt.tssimilarity index 100%rename from packages/shared/src/in-app-agent/server/prompts/in-app-agent-system-prompt.tsrename to packages/shared/src/in-app-agent/server/systemPrompt.tsdiff --git a/packages/shared/src/in-app-agent/server/toolResults.ts b/packages/shared/src/in-app-agent/server/toolResults.tsindex a919efbd88..916dd0ba5b 100644--- a/packages/shared/src/in-app-agent/server/toolResults.ts+++ b/packages/shared/src/in-app-agent/server/toolResults.ts@@ -1,7 +1,10 @@+import { EventType } from "@ag-ui/core";+import {IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE,IN_APP_AGENT_SILENT_MCP_OUTPUT_TYPE,} from "../constants";+import type { AgUiEvent } from "../schema";export type SilentInAppAgentMcpToolOutput = {type: typeof IN_APP_AGENT_SILENT_MCP_OUTPUT_TYPE;@@ -44,3 +47,24 @@ export function isSilentInAppAgentMcpToolOutput("output" in value);}++/** Withhold private persisted event payloads from browser-facing streams. */+export function toPublicInAppAgentEvent(event: AgUiEvent): AgUiEvent {+ if (event.type === EventType.RUN_STARTED && event.input !== undefined) {+ const publicEvent = { ...event };+ delete publicEvent.input;+ return publicEvent;+ }++ if (+ event.type === EventType.TOOL_CALL_RESULT &&+ typeof event.content === "string"+ ) {+ return {+ ...event,+ content: getPublicInAppAgentMcpToolResultContent(event.content),+ };+ }++ return event;+}diff --git a/packages/shared/src/in-app-agent/server/tunables.ts b/packages/shared/src/in-app-agent/server/tunables.tsindex a1e24d463b..15115e792f 100644--- a/packages/shared/src/in-app-agent/server/tunables.ts+++ b/packages/shared/src/in-app-agent/server/tunables.ts@@ -1,40 +1,17 @@-import { env } from "../../env";-/** Worker lease renewal + cancel-signal pickup interval. */-export const IN_APP_AGENT_HEARTBEAT_INTERVAL_MS =- env.LANGFUSE_IN_APP_AGENT_HEARTBEAT_INTERVAL_MS;+export const IN_APP_AGENT_HEARTBEAT_INTERVAL_MS = 5_000;/** RUNNING with a heartbeat older than this is failed (worker_lost) on read. */-export const IN_APP_AGENT_HEARTBEAT_STALE_MS =- env.LANGFUSE_IN_APP_AGENT_HEARTBEAT_STALE_MS;+export const IN_APP_AGENT_HEARTBEAT_STALE_MS = 60_000;/** QUEUED older than this is failed (queue_timeout) on read. */-export const IN_APP_AGENT_QUEUE_TIMEOUT_MS =- env.LANGFUSE_IN_APP_AGENT_QUEUE_TIMEOUT_MS;+export const IN_APP_AGENT_QUEUE_TIMEOUT_MS = 5 * 60_000;/*** RUNNING for longer than this since claim is failed (run_timeout) on read —* the backstop against a hung tool renewing a healthy heartbeat forever.*/-export const IN_APP_AGENT_RUN_MAX_DURATION_MS =- env.LANGFUSE_IN_APP_AGENT_RUN_MAX_DURATION_MS;+export const IN_APP_AGENT_RUN_MAX_DURATION_MS = 15 * 60_000;/** AWAITING_APPROVAL parked longer than this expires (approval_expired) on read. */-export const IN_APP_AGENT_APPROVAL_TTL_MS =- env.LANGFUSE_IN_APP_AGENT_APPROVAL_TTL_MS;--/** Interval at which the watch stream re-reads run status + new events. */-export const IN_APP_AGENT_WATCH_TAIL_POLL_MS =- env.LANGFUSE_IN_APP_AGENT_WATCH_TAIL_POLL_MS;--/** SSE comment interval, so load-balancer idle timeouts never fire. */-export const IN_APP_AGENT_WATCH_KEEPALIVE_MS =- env.LANGFUSE_IN_APP_AGENT_WATCH_KEEPALIVE_MS;--/**- * Deliberate stream end; the client reconnects with its cursor through the- * same path as a fresh page load, so route/LB duration limits are never hit- * unpredictably. Kept well inside the watch route's 120s `maxDuration`.- */-export const IN_APP_AGENT_WATCH_MAX_CONNECTION_MS =- env.LANGFUSE_IN_APP_AGENT_WATCH_MAX_CONNECTION_MS;+export const IN_APP_AGENT_APPROVAL_TTL_MS = 24 * 60 * 60_000;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 02da8c2c93..ed11f0d3e5 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -239,9 +239,6 @@ importers:'@ag-ui/core':specifier: ^0.0.52version: 0.0.52- '@ag-ui/mastra':- specifier: 1.1.1- version: 1.1.1(@ag-ui/[email protected])(@ag-ui/[email protected])(@copilotkit/[email protected](1060c54502e6f347b0aa0d1cbe91322c))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected]))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))'@ai-sdk/amazon-bedrock':specifier: ^5.0.25version: 5.0.25([email protected])@@ -269,9 +266,6 @@ importers:'@aws-sdk/client-lambda':specifier: 'catalog:'version: 3.1074.0- '@aws-sdk/client-lambda-microvms':- specifier: 'catalog:'- version: 3.1074.0'@aws-sdk/client-s3':specifier: 'catalog:'version: 3.1074.0@@ -296,12 +290,6 @@ importers:'@google-cloud/storage':specifier: ^7.19.0version: 7.19.0- '@mastra/core':- specifier: 1.46.0- version: 1.46.0(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])- '@mastra/mcp':- specifier: 1.8.1- version: 1.8.1(@cfworker/[email protected])(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])'@opentelemetry/api':specifier: '>=1.0.0 <1.10.0'version: 1.9.1@@ -314,9 +302,6 @@ importers:'@opentelemetry/sdk-trace-base':specifier: ^2.9.0version: 2.9.0(@opentelemetry/[email protected])- '@paralleldrive/cuid2':- specifier: ^2.2.2- version: 2.2.2'@prisma/client':specifier: ^6.19.3version: 6.19.3(@typescript/[email protected])([email protected](@typescript/[email protected])([email protected]))@@ -341,9 +326,6 @@ importers:ai:specifier: ^7.0.0version: 7.0.8([email protected])- ai-sdk-amazon-bedrock-v4:- specifier: npm:@ai-sdk/[email protected]- version: '@ai-sdk/[email protected]([email protected])'ajv:specifier: ^8.18.0version: 8.20.0@@ -380,9 +362,6 @@ importers:jsonpath-plus:specifier: 10.3.0version: 10.3.0- langfuse:- specifier: 3.38.4- version: 3.38.4langfuse-langchain:specifier: 3.38.20version: 3.38.20([email protected](@langchain/[email protected](@opentelemetry/[email protected])(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected]([email protected])([email protected]))([email protected]))(@opentelemetry/[email protected])(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected]([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])([email protected]([email protected])))@@ -425,9 +404,6 @@ importers:winston:specifier: ^3.15.0version: 3.15.0- yaml:- specifier: ^2.9.0- version: 2.9.0zod:specifier: 4.3.6version: 4.3.6@@ -441,9 +417,6 @@ importers:'@repo/typescript-config':specifier: workspace:*version: link:../config-typescript- '@types/dockerode':- specifier: ^4.0.1- version: 4.0.1'@types/lodash':specifier: ^4.17.24version: 4.17.24@@ -456,9 +429,6 @@ importers:'@types/react':specifier: 19.2.14version: 19.2.14- dockerode:- specifier: ^4.0.9- version: 4.0.12dotenv-cli:specifier: ^7.4.4version: 7.4.4@@ -486,9 +456,6 @@ importers:'@ag-ui/core':specifier: ^0.0.52version: 0.0.52- '@ag-ui/mastra':- specifier: 1.1.1- version: 1.1.1(@ag-ui/[email protected])(@ag-ui/[email protected])(@copilotkit/[email protected](1060c54502e6f347b0aa0d1cbe91322c))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected]))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))'@appsignal/opentelemetry-instrumentation-bullmq':specifier: ^0.8.0version: 0.8.0([email protected])@@ -498,12 +465,6 @@ importers:'@aws-crypto/sha256-browser':specifier: ^5.2.0version: 5.2.0- '@aws-sdk/client-lambda-microvms':- specifier: 'catalog:'- version: 3.1074.0- '@aws-sdk/credential-providers':- specifier: 'catalog:'- version: 3.1074.0'@baselime/trpc-opentelemetry-middleware':specifier: ^0.1.2@@ -555,15 +516,6 @@ importers:'@lezer/highlight':specifier: ^1.2.3version: 1.2.3- '@mastra/client-js':- specifier: 1.21.1- version: 1.21.1(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected])- '@mastra/core':- specifier: 1.46.0- version: 1.46.0(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])- '@mastra/mcp':- specifier: 1.8.1- version: 1.8.1(@cfworker/[email protected])(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])'@modelcontextprotocol/sdk':specifier: 1.29.0version: 1.29.0(@cfworker/[email protected])([email protected])@@ -603,6 +555,9 @@ importers:'@opentelemetry/sdk-trace-base':specifier: ^2.9.0version: 2.9.0(@opentelemetry/[email protected])+ '@paralleldrive/cuid2':+ specifier: 2.2.2+ version: 2.2.2'@prisma/instrumentation':specifier: ^6.19.3version: 6.19.3(@opentelemetry/[email protected])@@ -708,9 +663,6 @@ importers:'@uiw/react-codemirror':specifier: ^4.25.8version: 4.25.8(@babel/[email protected])(@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected]))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected](@lezer/[email protected]))([email protected]([email protected]))([email protected])- ai-sdk-amazon-bedrock-v4:- specifier: npm:@ai-sdk/[email protected]- version: '@ai-sdk/[email protected]([email protected])'bcryptjs:specifier: ^2.4.3version: 2.4.3@@ -955,9 +907,6 @@ importers:'@types/d3-zoom':specifier: ^3.0.8version: 3.0.8- '@types/dockerode':- specifier: ^4.0.1- version: 4.0.1'@types/lodash':specifier: ^4.17.24version: 4.17.24@@ -982,9 +931,6 @@ importers:dependency-cruiser:specifier: ^18.1.0version: 18.1.0- dockerode:- specifier: ^4.0.9- version: 4.0.12dotenv:specifier: ^16.6.1version: 16.6.1@@ -1051,15 +997,33 @@ importers:worker:dependencies:+ '@ag-ui/core':+ specifier: ^0.0.52+ version: 0.0.52+ '@ag-ui/mastra':+ specifier: 1.1.1+ version: 1.1.1(@ag-ui/[email protected])(@ag-ui/[email protected])(@copilotkit/[email protected](1060c54502e6f347b0aa0d1cbe91322c))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected]))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))'@anthropic-ai/tokenizer':specifier: ^0.0.4version: 0.0.4'@appsignal/opentelemetry-instrumentation-bullmq':specifier: ^0.8.0version: 0.8.0([email protected])+ '@aws-sdk/client-lambda-microvms':+ specifier: 'catalog:'+ version: 3.1074.0+ '@aws-sdk/credential-providers':+ specifier: 'catalog:'+ version: 3.1074.0'@langfuse/shared':specifier: workspace:*version: link:../packages/shared+ '@mastra/core':+ specifier: 1.46.0+ version: 1.46.0(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])+ '@mastra/mcp':+ specifier: 1.8.1+ version: 1.8.1(@cfworker/[email protected])(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])'@opentelemetry/api':specifier: ^1.9.1version: 1.9.1@@ -1102,6 +1066,9 @@ importers:'@prisma/instrumentation':specifier: ^6.19.3version: 6.19.3(@opentelemetry/[email protected])+ ai-sdk-amazon-bedrock-v4:+ specifier: npm:@ai-sdk/[email protected]+ version: '@ai-sdk/[email protected]([email protected])'bullmq:specifier: ^5.76.3version: 5.76.3@@ -1117,6 +1084,9 @@ importers:decimal.js:specifier: ^10.4.3version: 10.6.0+ dockerode:+ specifier: ^4.0.9+ version: 4.0.12dotenv:specifier: ^16.4.5version: 16.6.1@@ -1132,6 +1102,9 @@ importers:ioredis:specifier: ^5.10.1version: 5.10.1+ langfuse:+ specifier: 3.38.4+ version: 3.38.4lodash:specifier: 4.18.1version: 4.18.1@@ -1150,6 +1123,9 @@ importers:uuid:specifier: ^14.0.0version: 14.0.0+ yaml:+ specifier: ^2.9.0+ version: 2.9.0zod:specifier: 4.3.6version: 4.3.6@@ -1163,6 +1139,9 @@ importers:'@types/cors':specifier: ^2.8.17version: 2.8.19+ '@types/dockerode':+ specifier: ^4.0.1+ version: 4.0.1'@types/express':specifier: ^5.0.6version: 5.0.6@@ -12020,10 +11999,10 @@ snapshots:- ws- zod-to-json-schema- '@ag-ui/[email protected](@ag-ui/[email protected])(@ag-ui/[email protected])(@copilotkit/[email protected](1060c54502e6f347b0aa0d1cbe91322c))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected]))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))':+ '@ag-ui/[email protected](@ag-ui/[email protected])(@ag-ui/[email protected])(@copilotkit/[email protected](1060c54502e6f347b0aa0d1cbe91322c))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected]))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))':dependencies:'@ag-ui/a2ui-toolkit': 0.0.4- '@ag-ui/client': 0.0.52+ '@ag-ui/client': 0.0.57'@ag-ui/core': 0.0.52'@ai-sdk/ui-utils': 1.2.11([email protected])'@copilotkit/runtime': 1.63.1(1060c54502e6f347b0aa0d1cbe91322c)@@ -12033,19 +12012,6 @@ snapshots:rxjs: 7.8.1zod: 4.3.6- '@ag-ui/[email protected](@ag-ui/[email protected])(@ag-ui/[email protected])(@copilotkit/[email protected](1060c54502e6f347b0aa0d1cbe91322c))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected]))(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))':- dependencies:- '@ag-ui/a2ui-toolkit': 0.0.4- '@ag-ui/client': 0.0.52- '@ag-ui/core': 0.0.52- '@ai-sdk/ui-utils': 1.2.11([email protected])- '@copilotkit/runtime': 1.63.1(1060c54502e6f347b0aa0d1cbe91322c)- '@mastra/client-js': 1.21.1(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected])- '@mastra/core': 1.46.0(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])- fast-json-patch: 3.1.1- rxjs: 7.8.1- zod: 4.3.6-'@ag-ui/[email protected](@ag-ui/[email protected])(@cfworker/[email protected])([email protected])':dependencies:'@ag-ui/client': 0.0.57@@ -14347,32 +14313,6 @@ snapshots:- supports-color- utf-8-validate- '@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected])':- dependencies:- '@ai-sdk/ui-utils': 1.2.11([email protected])- '@lukeed/uuid': 2.0.1- '@mastra/core': 1.37.1(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected])- '@mastra/schema-compat': 1.2.10([email protected])- canonicalize: 1.0.8- jose: 6.2.3- json-schema: 0.4.0- zod: 4.3.6- transitivePeerDependencies:- - '@bufbuild/protobuf'- - '@cfworker/json-schema'- - '@grpc/grpc-js'- - '@hono/standard-validator'- - '@standard-community/standard-json'- - '@standard-community/standard-openapi'- - '@types/json-schema'- - ai- - bufferutil- - express- - openapi-types- - rxjs- - supports-color- - utf-8-validate-'@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected])':dependencies:@@ -14423,56 +14363,6 @@ snapshots:- supports-color- utf-8-validate- '@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])([email protected])':- dependencies:- '@ai-sdk/provider-utils-v5': '@ai-sdk/[email protected]([email protected])'- '@ai-sdk/provider-utils-v6': '@ai-sdk/[email protected]([email protected])'- '@ai-sdk/provider-v5': '@ai-sdk/[email protected]'- '@ai-sdk/provider-v6': '@ai-sdk/[email protected]'- '@ai-sdk/ui-utils-v5': '@ai-sdk/[email protected]([email protected])'- '@isaacs/ttlcache': 2.1.5- '@lukeed/uuid': 2.0.1- '@mastra/schema-compat': 1.2.10([email protected])- '@modelcontextprotocol/sdk': 1.29.0(@cfworker/[email protected])([email protected])- '@sindresorhus/slugify': 2.2.1- '@standard-schema/spec': 1.1.0- ajv: 8.20.0- croner: 10.0.1- dotenv: 17.4.2- execa: 9.6.1- fastq: 1.20.1- gray-matter: 4.0.3- hono: 4.12.27- hono-openapi: 1.3.0(@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-community/[email protected](@standard-community/[email protected](@standard-schema/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]([email protected]))([email protected]))(@standard-schema/[email protected])([email protected])([email protected])([email protected]))(@types/[email protected])([email protected])([email protected])- ignore: 7.0.6- json-schema: 0.4.0- lru-cache: 11.2.7- p-map: 7.0.4- p-retry: 7.1.1- picomatch: 4.0.5- posthog-node: 5.48.1([email protected])- tokenx: 1.3.0- ws: 8.21.1- xxhash-wasm: 1.1.0- zod: 4.3.6- transitivePeerDependencies:- - '@bufbuild/protobuf'- - '@cfworker/json-schema'- - '@grpc/grpc-js'- - '@hono/standard-validator'- - '@standard-community/standard-json'- - '@standard-community/standard-openapi'- - '@types/json-schema'- - ai- - bufferutil- - express- - openapi-types- - rxjs- - supports-color- - utf-8-validate-'@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])':dependencies:@@ -14516,49 +14406,6 @@ snapshots:- supports-color- utf-8-validate- '@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])':- dependencies:- '@ai-sdk/provider-utils-v5': '@ai-sdk/[email protected]([email protected])'- '@ai-sdk/provider-utils-v6': '@ai-sdk/[email protected]([email protected])'- '@ai-sdk/provider-v5': '@ai-sdk/[email protected]'- '@ai-sdk/provider-v6': '@ai-sdk/[email protected]'- '@isaacs/ttlcache': 2.1.5- '@lukeed/uuid': 2.0.1- '@mastra/schema-compat': 1.3.0([email protected])- '@modelcontextprotocol/sdk': 1.29.0(@cfworker/[email protected])([email protected])- '@sindresorhus/slugify': 2.2.1- '@standard-schema/spec': 1.1.0- ajv: 8.20.0- croner: 10.0.1- dotenv: 17.4.2- execa: 9.6.1- fastq: 1.20.1- gray-matter: 4.0.3- ignore: 7.0.6- jpeg-js: 0.4.4- json-schema: 0.4.0- lru-cache: 11.2.7- p-map: 7.0.4- p-retry: 7.1.1- picomatch: 4.0.5- posthog-node: 5.48.1([email protected])- tokenx: 1.3.0- ws: 8.21.1- xxhash-wasm: 1.1.0- zod: 4.3.6- transitivePeerDependencies:- - '@bufbuild/protobuf'- - '@cfworker/json-schema'- - '@grpc/grpc-js'- - ai- - bufferutil- - express- - rxjs- - supports-color- - utf-8-validate-'@mastra/[email protected](@cfworker/[email protected])(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])':dependencies:'@mastra/core': 1.46.0(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])@@ -14573,20 +14420,6 @@ snapshots:- supports-color- zod- '@mastra/[email protected](@cfworker/[email protected])(@mastra/[email protected](@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])':- dependencies:- '@mastra/core': 1.46.0(@bufbuild/[email protected])(@cfworker/[email protected])(@grpc/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])- '@modelcontextprotocol/ext-apps': 1.7.2(@modelcontextprotocol/[email protected](@cfworker/[email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])- '@modelcontextprotocol/sdk': 1.29.0(@cfworker/[email protected])([email protected])- exit-hook: 5.1.0- fast-deep-equal: 3.1.3- transitivePeerDependencies:- - '@cfworker/json-schema'- - react- - react-dom- - supports-color- - zod-'@mastra/[email protected]([email protected])':dependencies:json-schema-to-zod: 2.8.1@@ -18578,21 +18411,6 @@ snapshots:transitivePeerDependencies:- supports-color- dependencies:- '@workflow/serde': 4.1.0-beta.2- mdast-util-to-string: 4.0.0- remark-gfm: 4.0.1- remark-parse: 11.0.0- remark-stringify: 11.0.0- remend: 1.3.0- unified: 11.0.5- optionalDependencies:- ai: 7.0.8([email protected])- zod: 4.3.6- transitivePeerDependencies:- - supports-color-diff --git a/scripts/in-app-agent/README.md b/scripts/in-app-agent/README.mdindex e568178328..05cba033f7 100644--- a/scripts/in-app-agent/README.md+++ b/scripts/in-app-agent/README.md@@ -4,14 +4,14 @@The generated in-app agent skills live at:-`packages/shared/src/in-app-agent/server/skills/generated/raw`+`worker/src/features/in-app-agent/runtime/skills/generated/raw`The generated TypeScript index lives at:-`packages/shared/src/in-app-agent/server/skills/generated/skill-markdown.ts`+`worker/src/features/in-app-agent/runtime/skills/generated/skill-markdown.ts`The generated module inlines each markdown file as a string literal so it-compiles under plain `tsc` in `@langfuse/shared`; the `raw/*.md` copies exist+compiles under plain `tsc` in `worker`; the `raw/*.md` copies existfor reviewable diffs only.Use `sync-raw-skills.mjs` to download all markdown files from@@ -33,7 +33,7 @@ node scripts/in-app-agent/sync-raw-skills.mjs --checkThe canonical system prompt for the in-app agent lives at:-`packages/shared/src/in-app-agent/server/prompts/in-app-agent-system-prompt.ts`+`packages/shared/src/in-app-agent/server/systemPrompt.ts`The local Postgres seeder imports this module and creates the text prompt named`in-app-agent-system-prompt` in the seed projectdiff --git a/scripts/in-app-agent/sync-prompt.sh b/scripts/in-app-agent/sync-prompt.shindex ce983b6fce..30cce4e798 100755--- a/scripts/in-app-agent/sync-prompt.sh+++ b/scripts/in-app-agent/sync-prompt.sh@@ -3,7 +3,7 @@ set -euo pipefailSCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"-PROMPT_FILE="${REPO_ROOT}/packages/shared/src/in-app-agent/server/prompts/in-app-agent-system-prompt.ts"+PROMPT_FILE="${REPO_ROOT}/packages/shared/src/in-app-agent/server/systemPrompt.ts"PROMPT_NAME="in-app-agent-system-prompt"REGIONS=(STAGING EU US JP HIPAA)BASE_URLS=(diff --git a/scripts/in-app-agent/sync-raw-skills.mjs b/scripts/in-app-agent/sync-raw-skills.mjsindex 80e7cc3815..c0a791c888 100644--- a/scripts/in-app-agent/sync-raw-skills.mjs+++ b/scripts/in-app-agent/sync-raw-skills.mjs@@ -14,7 +14,7 @@ import { format as formatWithPrettier } from "prettier";const repoRoot = resolve(new URL("../..", import.meta.url).pathname);const generatedDir = resolve(repoRoot,- "packages/shared/src/in-app-agent/server/skills/generated",+ "worker/src/features/in-app-agent/runtime/skills/generated",);const rawTargetDir = resolve(generatedDir, "raw");const generatedModuleName = "skill-markdown.ts";@@ -156,7 +156,7 @@ const getCurrentManagedFileNames = () =>const renderGeneratedModule = async (files) => {// Markdown is inlined as string literals (instead of raw `.md` imports) so- // the module compiles under plain tsc in @langfuse/shared without bundler+ // the module compiles under plain tsc in worker without bundler// support. The raw/*.md files are still written for reviewable diffs.const entries = files.map(diff --git a/web/AGENTS.md b/web/AGENTS.mdindex 958279a014..7e914bbc19 100644--- a/web/AGENTS.md+++ b/web/AGENTS.md@@ -40,14 +40,12 @@- Use narrower subpaths such as `@langfuse/shared/src/env` or`@langfuse/shared/encryption` only when that focused surface is the clearestdependency.-- The in-app-agent runtime lives in shared:- `@langfuse/shared/in-app-agent` is the client-safe contracts entry;- its `AgUiRunAgentInput` is a compile-time-only execution contract;- `@langfuse/shared/in-app-agent` also owns the browser-safe durable interrupt- parser. `@langfuse/shared/in-app-agent/server` (and per-module subpaths) is- server-only. Web keeps only the thin adapters in- `src/features/in-app-agent/` (router and UI), plus the authenticated watch- route in `src/app/api/in-app-agent/watch/`.+- The in-app-agent execution runtime lives in the worker. Shared exposes its+ durable browser-safe contracts plus explicit server-only persistence,+ lifecycle, policy, tool-result, compaction, and prompt subpaths. Web owns the+ UI, IDs, feedback/source/rate-limit schemas, conversation access, tRPC run+ adapters, snapshot construction, watch framing/service, and the authenticated+ watch route in `src/app/api/in-app-agent/watch/`.- See `../packages/shared/AGENTS.md` for the full shared export map and whateach entrypoint contains.- For the higher-level platform topology across web, worker, Postgres,diff --git a/web/next.config.mjs b/web/next.config.mjsindex b89dd2aba5..929a2dce12 100644--- a/web/next.config.mjs+++ b/web/next.config.mjs@@ -91,10 +91,6 @@ const nextConfig = {"bullmq","@opentelemetry/sdk-node","@opentelemetry/instrumentation-winston",- // The local-only dangerous-docker sandbox provider depends on dockerode,- // which pulls ssh2 assets that Turbopack cannot place into ESM chunks.- // Keep it external to the server bundle and load it only at runtime.- "dockerode",],poweredByHeader: false,basePath: env.NEXT_PUBLIC_BASE_PATH,diff --git a/web/package.json b/web/package.jsonindex cb7b930788..9f8c477db4 100644--- a/web/package.json+++ b/web/package.json@@ -35,12 +35,9 @@"dependencies": {"@ag-ui/client": "^0.0.52","@ag-ui/core": "^0.0.52",- "@ag-ui/mastra": "1.1.1","@appsignal/opentelemetry-instrumentation-bullmq": "^0.8.0","@astral-sh/ruff-wasm-web": "0.15.13","@aws-crypto/sha256-browser": "^5.2.0",- "@aws-sdk/client-lambda-microvms": "catalog:",- "@aws-sdk/credential-providers": "catalog:","@baselime/trpc-opentelemetry-middleware": "^0.1.2","@codemirror/autocomplete": "^6.17.0","@codemirror/lang-javascript": "^6.2.5",@@ -58,9 +55,6 @@"@hookform/resolvers": "^5.2.2","@langfuse/shared": "workspace:*","@lezer/highlight": "^1.2.3",- "@mastra/client-js": "1.21.1",- "@mastra/core": "1.46.0",- "@mastra/mcp": "1.8.1","@modelcontextprotocol/sdk": "1.29.0","@next-auth/prisma-adapter": "^1.0.7","@opentelemetry/api": "^1.9.1",@@ -74,6 +68,7 @@"@opentelemetry/resources": "^2.9.0","@opentelemetry/sdk-node": "^0.220.0","@opentelemetry/sdk-trace-base": "^2.9.0",+ "@paralleldrive/cuid2": "2.2.2","@prisma/instrumentation": "^6.19.3","@radix-ui/react-accordion": "^1.2.12","@radix-ui/react-alert-dialog": "^1.1.15",@@ -109,7 +104,6 @@"@typescript/typescript6": "^6.0.2","@uiw/codemirror-themes": "^4.23.7","@uiw/react-codemirror": "^4.25.8",- "ai-sdk-amazon-bedrock-v4": "npm:@ai-sdk/[email protected]","bcryptjs": "^2.4.3","bullmq": "^5.76.3","chroma-js": "^3.1.2",@@ -193,7 +187,6 @@"@types/cors": "^2.8.19","@types/d3-selection": "^3.0.11","@types/d3-zoom": "^3.0.8",- "@types/dockerode": "^4.0.1","@types/lodash": "^4.17.24","@types/node": "24.3.0","@types/react": "19.2.14",@@ -202,7 +195,6 @@"@vitejs/plugin-react": "^4.7.0","@vitest/browser-playwright": "4.1.10","dependency-cruiser": "^18.1.0",- "dockerode": "^4.0.9","dotenv": "^16.6.1","dotenv-cli": "^7.4.2","dotenv-expand": "^10.0.0",diff --git a/web/src/__tests__/server/in-app-agent-background-run.servertest.ts b/web/src/__tests__/server/in-app-agent-background-run.servertest.tsindex cb0a13f128..d7cc088b89 100644--- a/web/src/__tests__/server/in-app-agent-background-run.servertest.ts+++ b/web/src/__tests__/server/in-app-agent-background-run.servertest.ts@@ -10,20 +10,24 @@ import { EventType } from "@ag-ui/core";import { randomUUID } from "crypto";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { type Plan } from "@langfuse/shared";+import { prisma } from "@langfuse/shared/src/db";+import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";import {+ IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,InAppAgentRunErrorCode,InAppAgentRunStatus,- type Plan,-} from "@langfuse/shared";-import { prisma } from "@langfuse/shared/src/db";-import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";+} from "@langfuse/shared/in-app-agent";import {createInAppAgentConversationId,createInAppAgentRunId,- IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,-} from "@langfuse/shared/in-app-agent";+} from "@/src/features/in-app-agent/ids";import { ensureOwnedConversation } from "@langfuse/shared/in-app-agent/server/persistence";-import { env as sharedEnv } from "@langfuse/shared/src/env";+import {+ IN_APP_AGENT_HEARTBEAT_STALE_MS,+ IN_APP_AGENT_QUEUE_TIMEOUT_MS,+ IN_APP_AGENT_RUN_MAX_DURATION_MS,+} from "@langfuse/shared/in-app-agent/server/tunables";import { env } from "@/src/env.mjs";import { inAppAgentRouter } from "@/src/features/in-app-agent/server/router";import { createInnerTRPCContext } from "@/src/server/api/trpc";@@ -93,9 +97,9 @@ describe("in-app agent background runs", () => {const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;const originalBedrockModel = env.LANGFUSE_AWS_BEDROCK_MODEL;const originalMaxActiveRunsPerUser =- sharedEnv.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER;+ env.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER;const originalMaxActiveRunsPerOrg =- sharedEnv.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG;+ env.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG;beforeEach(() => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "DEV";@@ -113,9 +117,9 @@ describe("in-app agent background runs", () => {vi.useRealTimers();(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;(env as any).LANGFUSE_AWS_BEDROCK_MODEL = originalBedrockModel;- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER =+ (env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER =originalMaxActiveRunsPerUser;- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG =+ (env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG =originalMaxActiveRunsPerOrg;});@@ -365,7 +369,7 @@ describe("in-app agent background runs", () => {userId,});- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG = 1;+ (env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG = 1;await expect(caller.startRun({@@ -399,13 +403,13 @@ describe("in-app agent background runs", () => {userId,createdAt: new Date(Date.now() -- sharedEnv.LANGFUSE_IN_APP_AGENT_QUEUE_TIMEOUT_MS -- sharedEnv.LANGFUSE_IN_APP_AGENT_RUN_MAX_DURATION_MS -+ IN_APP_AGENT_QUEUE_TIMEOUT_MS -+ IN_APP_AGENT_RUN_MAX_DURATION_MS -60_000,),});- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER = 1;+ (env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER = 1;const { runId } = await caller.startRun({projectId,@@ -430,8 +434,8 @@ describe("in-app agent background runs", () => {// its slot in the accounting, or the ceiling leaks while hung runs pile up.const overdue = new Date(Date.now() -- sharedEnv.LANGFUSE_IN_APP_AGENT_QUEUE_TIMEOUT_MS -- sharedEnv.LANGFUSE_IN_APP_AGENT_RUN_MAX_DURATION_MS -+ IN_APP_AGENT_QUEUE_TIMEOUT_MS -+ IN_APP_AGENT_RUN_MAX_DURATION_MS -60_000,);await prisma.inAppAgentRun.create({@@ -448,7 +452,7 @@ describe("in-app agent background runs", () => {},});- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER = 1;+ (env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER = 1;await expect(caller.startRun({@@ -477,13 +481,11 @@ describe("in-app agent background runs", () => {request: { kind: "userMessage", context: [] },createdAt: new Date(Date.now() - 5 * 60_000),claimedAt: new Date(Date.now() - 5 * 60_000),- heartbeatAt: new Date(- Date.now() - sharedEnv.LANGFUSE_IN_APP_AGENT_HEARTBEAT_STALE_MS * 3,- ),+ heartbeatAt: new Date(Date.now() - IN_APP_AGENT_HEARTBEAT_STALE_MS * 3),},});- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER = 1;+ (env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER = 1;const { runId } = await caller.startRun({projectId,@@ -593,7 +595,7 @@ describe("in-app agent background runs", () => {});expect(decisionEvent.event).toMatchObject({name: IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,- value: { toolCallId: "tool-call-grant", scope: "conversation" },+ value: { toolCallId: "tool-call-grant" },});});diff --git a/web/src/__tests__/server/in-app-agent-persistence.servertest.ts b/web/src/__tests__/server/in-app-agent-persistence.servertest.tsindex f561e6f26b..c74171bac6 100644--- a/web/src/__tests__/server/in-app-agent-persistence.servertest.ts+++ b/web/src/__tests__/server/in-app-agent-persistence.servertest.ts@@ -13,12 +13,7 @@ import { randomUUID } from "crypto";import { vi } from "vitest";import waitForExpect from "wait-for-expect";-import {- InAppAgentRunErrorCode,- InAppAgentRunStatus,- type InAppAgentRunRequest,- type Plan,-} from "@langfuse/shared";+import { type Plan } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";import {createOrgProjectAndApiKey,@@ -27,17 +22,22 @@ import {} from "@langfuse/shared/src/server";import { env } from "@/src/env.mjs";import {- createInAppAgentConversationId,- createInAppAgentRunId,+ InAppAgentRunErrorCode,+ InAppAgentRunStatus,getInAppAgentInstrumentationObservationId,getInAppAgentInstrumentationTraceId,} from "@langfuse/shared/in-app-agent";+import {+ createInAppAgentConversationId,+ createInAppAgentRunId,+} from "@/src/features/in-app-agent/ids";import {dropEmptyAssistantMessages,dropUnpairedAssistantToolCalls,type AgUiEvent,- type InAppAgentWatchFrame,} from "@langfuse/shared/in-app-agent";+import type { InAppAgentRunRequest } from "@langfuse/shared/in-app-agent";+import type { InAppAgentWatchFrame } from "@/src/features/in-app-agent/watchFrames";import {deserializeInAppAgentDisplayState,projectInAppAgentMessagesForDisplay,@@ -54,7 +54,7 @@ import {toPersistableAgentEvent,} from "@langfuse/shared/in-app-agent/server/persistence";import { finishClaimedRun } from "@langfuse/shared/in-app-agent/server/runLifecycle";-import { watchConversationFrames } from "@langfuse/shared/in-app-agent/server/watch";+import { watchConversationFrames } from "@/src/features/in-app-agent/server/watch";import { createInnerTRPCContext } from "@/src/server/api/trpc";import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@langfuse/shared/in-app-agent";diff --git a/web/src/__tests__/server/unit/in-app-agent-background-snapshot.servertest.ts b/web/src/__tests__/server/unit/in-app-agent-background-snapshot.servertest.tsindex b4f60e5cff..a67530c2de 100644--- a/web/src/__tests__/server/unit/in-app-agent-background-snapshot.servertest.ts+++ b/web/src/__tests__/server/unit/in-app-agent-background-snapshot.servertest.ts@@ -1,9 +1,11 @@import { EventType } from "@ag-ui/core";import { describe, expect, it, vi } from "vitest";-import { InAppAgentRunStatus } from "@langfuse/shared";import { Prisma, type PrismaClient } from "@langfuse/shared/src/db";-import { IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE } from "@langfuse/shared/in-app-agent";+import {+ IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE,+ InAppAgentRunStatus,+} from "@langfuse/shared/in-app-agent";vi.mock("@langfuse/shared/src/server", () => ({ClickHouseClientManager: {diff --git a/web/src/__tests__/server/unit/in-app-agent-mcp-policy.servertest.ts b/web/src/__tests__/server/unit/in-app-agent-mcp-policy.servertest.tsnew file mode 100644index 0000000000..8a42871c82--- /dev/null+++ b/web/src/__tests__/server/unit/in-app-agent-mcp-policy.servertest.ts@@ -0,0 +1,25 @@+import { describe, expect, expectTypeOf, it } from "vitest";++import {+ IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES,+ type InAppAgentLangfuseMcpToolName,+} from "@langfuse/shared/in-app-agent/server/mcpPolicy";+import "@/src/features/mcp/server/bootstrap";+import type { McpToolName } from "@/src/features/mcp/server/bootstrap";+import { toolRegistry } from "@/src/features/mcp/server/registry";++describe("IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES", () => {+ it("classifies every Langfuse MCP tool exactly once", () => {+ expectTypeOf<InAppAgentLangfuseMcpToolName>().toEqualTypeOf<McpToolName>();++ const registeredToolNames = toolRegistry+ .getFeatures()+ .flatMap((feature) => feature.tools.map((tool) => tool.definition.name))+ .sort();+ const classifiedToolNames = Object.keys(+ IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES,+ ).sort();++ expect(classifiedToolNames).toEqual(registeredToolNames);+ });+});diff --git a/web/src/__tests__/server/unit/in-app-agent-mcp-run-override.servertest.ts b/web/src/__tests__/server/unit/in-app-agent-mcp-run-override.servertest.tsnew file mode 100644index 0000000000..9ca822fd83--- /dev/null+++ b/web/src/__tests__/server/unit/in-app-agent-mcp-run-override.servertest.ts@@ -0,0 +1,50 @@+import {+ createInAppAgentMcpRunOverride,+ InAppAgentMcpRunOverrideSchema,+} from "@langfuse/shared/in-app-agent/server/mcpPolicy";++describe("in-app agent MCP run override", () => {+ it("serializes the override as plain JSON", async () => {+ const token = await createInAppAgentMcpRunOverride({+ toolNames: ["upsertDataset"],+ });++ expect(JSON.parse(token)).toEqual({+ toolName: "upsertDataset",+ toolNames: ["upsertDataset"],+ });+ });++ it("accepts a matching plain JSON override", async () => {+ const token = await createInAppAgentMcpRunOverride({+ toolNames: ["upsertDataset"],+ });++ expect(InAppAgentMcpRunOverrideSchema.safeParse(JSON.parse(token))).toEqual(+ {+ success: true,+ data: {+ toolNames: ["upsertDataset"],+ },+ },+ );+ });++ it("rejects malformed or mismatched overrides", () => {+ expect(InAppAgentMcpRunOverrideSchema.safeParse("not-json").success).toBe(+ false,+ );++ expect(+ InAppAgentMcpRunOverrideSchema.safeParse({+ toolName: "notAMcpTool",+ }).success,+ ).toBe(false);++ expect(+ InAppAgentMcpRunOverrideSchema.safeParse({+ other: "value",+ }).success,+ ).toBe(false);+ });+});diff --git a/packages/shared/src/in-app-agent/server/watch.test.ts b/web/src/__tests__/server/unit/in-app-agent-watch.servertest.tssimilarity index 97%rename from packages/shared/src/in-app-agent/server/watch.test.tsrename to web/src/__tests__/server/unit/in-app-agent-watch.servertest.tsindex 29763e4e10..6ad872cefd 100644--- a/packages/shared/src/in-app-agent/server/watch.test.ts+++ b/web/src/__tests__/server/unit/in-app-agent-watch.servertest.ts@@ -1,11 +1,13 @@import { EventType } from "@ag-ui/core";import { describe, expect, it, vi } from "vitest";-import { InAppAgentRunStatus } from "../../index";-import type { PrismaClient } from "../../db";-import { IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE } from "../constants";-import type { InAppAgentWatchFrame } from "../backgroundWatch";-import { watchConversationFrames } from "./watch";+import type { PrismaClient } from "@langfuse/shared/src/db";+import {+ IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE,+ InAppAgentRunStatus,+} from "@langfuse/shared/in-app-agent";+import type { InAppAgentWatchFrame } from "@/src/features/in-app-agent/watchFrames";+import { watchConversationFrames } from "@/src/features/in-app-agent/server/watch";/*** The framing rules are what these tests protect, so the data source is adiff --git a/web/src/__tests__/server/unit/mcp-route-in-app-agent-context.servertest.ts b/web/src/__tests__/server/unit/mcp-route-in-app-agent-context.servertest.tsindex 2a155a8bb3..904ee851d5 100644--- a/web/src/__tests__/server/unit/mcp-route-in-app-agent-context.servertest.ts+++ b/web/src/__tests__/server/unit/mcp-route-in-app-agent-context.servertest.ts@@ -1,5 +1,5 @@import { IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER } from "@langfuse/shared/in-app-agent";-import { createInAppAgentMcpRunOverride } from "@langfuse/shared/in-app-agent/server/human-in-the-loop";+import { createInAppAgentMcpRunOverride } from "@langfuse/shared/in-app-agent/server/mcpPolicy";import { getInAppAgentContext } from "@/src/pages/api/public/mcp";import type { NextApiRequest, NextApiResponse } from "next";import { createMocks } from "node-mocks-http";diff --git a/web/src/env.mjs b/web/src/env.mjsindex 1195231425..05d95b2243 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -542,21 +542,16 @@ export const env = createEnv({AWS_ACCESS_KEY_ID: z.string().optional(),AWS_SECRET_ACCESS_KEY: z.string().optional(),LANGFUSE_AWS_BEDROCK_REGION: z.string().optional(),- LANGFUSE_IN_APP_AGENT_AWS_PROFILE: z.string().optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER: z- .enum(["dangerous-docker", "lambda-microvm"])- .optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER: z- .string()- .optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN: z- .string()- .optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN:- z.string().optional(),- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION: z- .string()- .optional(),+ LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER: z.coerce+ .number()+ .int()+ .positive()+ .default(5),+ LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG: z.coerce+ .number()+ .int()+ .positive()+ .default(20),},/**@@ -645,21 +640,10 @@ export const env = createEnv({AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,LANGFUSE_AWS_BEDROCK_REGION: process.env.LANGFUSE_AWS_BEDROCK_REGION,- LANGFUSE_IN_APP_AGENT_AWS_PROFILE:- process.env.LANGFUSE_IN_APP_AGENT_AWS_PROFILE,- LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER:- process.env.LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER,- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER:- process.env- .LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER,- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN:- process.env- .LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN,- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN:- process.env- .LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN,- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION:- process.env.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION,+ LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER:+ process.env.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER,+ LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG:+ process.env.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG,LANGFUSE_TEAM_SLACK_WEBHOOK: process.env.LANGFUSE_TEAM_SLACK_WEBHOOK,LANGFUSE_FEEDBACK_INTAKE_SLACK_WEBHOOK:process.env.LANGFUSE_FEEDBACK_INTAKE_SLACK_WEBHOOK,@@ -1042,26 +1026,3 @@ export const env = createEnv({skipValidation: process.env.DOCKER_BUILD === "1",emptyStringAsUndefined: true, // https://env.t3.gg/docs/customization#treat-empty-strings-as-undefined});--/**- * @param {typeof env} parsed- */-const validateInAppAgentSandboxConfig = (parsed) => {- if (parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER !== "lambda-microvm") {- return;- }-- if (- !parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER ||- !parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN ||- !parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION- ) {- throw new Error(- "Invalid lambda-microvm sandbox config: image identifier, execution role ARN, and region are required.",- );- }-};--if (typeof window === "undefined") {- validateInAppAgentSandboxConfig(env);-}diff --git a/web/src/features/in-app-agent/ARCHITECTURE.md b/web/src/features/in-app-agent/ARCHITECTURE.mdindex e6a6a4b90d..2f11544be7 100644--- a/web/src/features/in-app-agent/ARCHITECTURE.md+++ b/web/src/features/in-app-agent/ARCHITECTURE.md@@ -58,11 +58,14 @@ Two consequences worth stating explicitly:`packages/shared` is for what web **and** worker both need. Web-only logic staysin web even when it executes on a server.-The worker runs agents; it never renders. So the event log, canonical-accumulation, replay, the run lifecycle and watch framing are shared, while-display recording and projection live in `web/src/features/in-app-agent/lib/`-and are imported by both the browser and the web server that builds snapshots.-Shared persistence knows nothing about rendering.+The worker runs agents; it never renders. Mastra adaptation, tools,+instrumentation, continuation handling, prompt loading, skills, and sandbox+providers therefore live in `worker/src/features/in-app-agent/runtime/`.+Shared owns only durable cross-process contracts and storage behavior: the+event log, canonical accumulation, replay, lifecycle, approval events, MCP+policy, tool-result redaction, and seeded prompt. Watch framing, display+recording, projection, IDs, feedback/source schemas, and conversation access+live in web. Shared persistence knows nothing about rendering.The two message-pruning helpers are the deliberate exception: they prune`AgUiMessage` shape rather than describe presentation, and replay needs them@@ -83,14 +86,18 @@ flowchart LRendsubgraph Shared["packages/shared"]L[("in_app_agent_events")]- A["agent runtime"]+ C["durable contracts + lifecycle"]+ end+ subgraph Worker["worker"]+ W["executeInAppAgentRun"]+ A["runtime/agent + tools + sandbox"]end- W["worker: executeInAppAgentRun"]S -->|"tRPC start + snapshot"| RTRT -->|"enqueue"| WW --> AW --> L+ W -.-> CS -->|"SSE tail above cursor"| WRRT --> LWR --> Ldiff --git a/web/src/features/in-app-agent/README.md b/web/src/features/in-app-agent/README.mdindex 8951221270..1793875715 100644--- a/web/src/features/in-app-agent/README.md+++ b/web/src/features/in-app-agent/README.md@@ -6,7 +6,7 @@ persisted event stream.`ARCHITECTURE.md` covers why the feature is shaped this way: the one-log /three-derivations contract, where code lives and why, and the boundaries between-browser, web server, shared runtime, and worker.+browser, web server, shared durable contracts, and worker runtime.Read it before changing how messages are represented or where logic lives.## Core Model@@ -15,7 +15,10 @@ AG-UI events are the durable transcript vocabulary. Langfuse-owned protocolscoordinate persistence, watching, run lifecycle, approvals, and displayprojection around those events.-The browser owns interaction state and submits intent. The server owns authorization, run/message IDs, request sanitization, MCP credentials, runtime configuration, tool access, persistence, and replay.+The browser owns interaction state and submits intent. Web owns authorization,+run/message IDs, request sanitization, admission, snapshots, and watching. The+worker owns runtime configuration, MCP credentials, tools, execution, and+continuations. Shared owns durable contracts, persistence, and lifecycle.A conversation can have one active run. The browser starts a durable run,hydrates one persisted transcript/cursor snapshot, and observes its tail.@@ -23,27 +26,24 @@ Closing the drawer detaches observation without cancelling the worker run.## Major Files-- `schema.ts`: runtime-neutral AG-UI schemas and types shared by browser, server, persistence, replay, and rendering, including Langfuse-owned human-in-the-loop wire contracts.-- `server/agent.ts`: Mastra/Bedrock/MCP runtime setup, custom tool wiring, human-in-the-loop approval gates, AG-UI event normalization, and cleanup.-- `interrupts.ts`: browser-safe parsing of the durable approval interrupt-- `server/human-in-the-loop.ts`: worker continuation handling- compatibility.-- `server/mcpPolicy.ts`: MCP names, authorization, and approval policy-- `server/toolResults.ts`: persisted MCP result redaction and sandbox-file contracts-- `server/tools.ts`: custom agent tools with strict schemas and scoped, user-visible behavior.-- `server/persistence.ts`: conversations, events, canonical accumulation, and replay. Knows nothing about rendering.-- `server/runLifecycle.ts`: durable run creation, claiming, cancellation, terminal transitions, active-run locking, and reconciliation.+- `packages/shared/src/in-app-agent/schema.ts`: runtime-neutral AG-UI and durable+ human-in-the-loop wire contracts.+- `packages/shared/src/in-app-agent/interrupts.ts`: browser-safe durable+ approval interrupt parsing used by browser, web, and worker.+- Explicit `packages/shared/src/in-app-agent/server/*` modules own persistence,+ lifecycle, MCP policy, persisted tool-result handling, compaction, tunables,+ and the seeded system prompt. There is no aggregate server barrel.+- `schema.ts`, `ids.ts`, and `watchFrames.ts`: web-owned feedback/source/rate+ schemas, browser/server IDs, and watch wire framing.- `lib/display.ts`: display-state recording, the render-time projection, and itswire serialization. Web-only; used by the browser and by the web server whenit builds a conversation snapshot.- `server/conversationSnapshot.ts`: rebuilds canonical messages and display statefrom one read of the persisted event log.- `server/router.ts`: tRPC routes for durable run start/cancel/approval, conversation snapshots and lists, and feedback.-- `server/instrumentation.ts`: optional Langfuse tracing for agent runs, prompts, events, and errors.-- `server/sandbox/config.ts`: sandbox provider selection and runtime configuration.-- `server/sandbox/service.ts`: conversation-scoped sandbox session reuse, readonly file sync, and turn-end session persistence.-- `server/sandbox/providers/*`: provider adapters for local Docker and Lambda MicroVM sandboxes.-- `server/sandbox/types.ts`: runtime-neutral sandbox interface used by tools/agent.+- `worker/src/features/in-app-agent/runtime/*`: Mastra/Bedrock/MCP execution,+ continuation handling, instrumentation, prompt loading, tools, skills, and+ sandbox providers.- `constants.ts`: stable names shared across prompts, tools, persistence, and rendering.- `components/InAppAiAgentProvider.tsx`: query integration and the React bridgeto the background session.@@ -80,23 +80,23 @@ flowchart TBBackgroundClient -->|SSE tail| Watch["app/api/in-app-agent/watch\nauthenticated watch route"]Provider -->|tRPC| Router["server/router.ts\ntRPC routes (non-streaming)"]- Schema["schema.ts\nshared AG-UI contract"] -.-> Provider- Schema -.-> HumanLoop["server/human-in-the-loop.ts\napproval state + validation"]+ Schema["packages/shared/.../schema.ts\ndurable AG-UI contract"] -.-> Provider+ Schema -.-> HumanLoop["worker runtime/human-in-the-loop.ts\ncontinuation compatibility"]Schema -.-> RouterSchema -.-> Persistence["server/persistence.ts"]Router -->|enqueue| Worker["worker executeInAppAgentRun\ndurable run driver"]Worker --> Persistence- Worker --> Sandbox["server/sandbox/service.ts\nsandbox lifecycle"]- Worker --> Agent["server/agent.ts\nagent runtime"]+ Worker --> Sandbox["worker runtime/sandbox\nsandbox lifecycle"]+ Worker --> Agent["worker runtime/agent.ts\nagent runtime"]Worker --> HumanLoopWatch --> PersistenceSandbox --> Persistence- Sandbox --> Providers["server/sandbox/providers/*\nDocker or Lambda MicroVM"]+ Sandbox --> Providers["worker runtime/sandbox/providers/*\nDocker or Lambda MicroVM"]Agent --> HumanLoop- Agent --> Tools["server/tools.ts\ncustom tools"]+ Agent --> Tools["worker runtime/tools.ts\ncustom tools"]Agent --> Tools- Agent --> Instrumentation["server/instrumentation.ts\nLangfuse telemetry"]+ Agent --> Instrumentation["worker runtime/instrumentation.ts\nLangfuse telemetry"]Router --> Persistence```@@ -145,9 +145,9 @@ Streaming publications and background session snapshots are high-frequency.Keep their subscription boundary narrow, derive status/notice values duringrender, and preserve stable message references between session publications.-Stop intentionally emits no new analytics event during the internal rollout:-the existing run lifecycle is sufficient to diagnose correctness, and there is-no product decision that a separate click event would answer yet.+Stop intentionally emits no separate analytics event: the run lifecycle is+sufficient to diagnose correctness, and there is no product decision that a+separate click event would answer.## Operations@@ -163,9 +163,21 @@ its default of 20 equals full US capacity and exceeds JP and staging.Conversation switching, detached invalidations, retry, and conversation-list runstatuses remain separate project concerns.+Environment ownership:++- Worker: queue enable/concurrency, sandbox provider and Lambda MicroVM values,+ and development-only `LANGFUSE_IN_APP_AGENT_AWS_PROFILE`.+- Fixed lifecycle policy: queue timeout (300000 ms), maximum run duration+ (900000 ms), and approval TTL (86400000 ms). These are shared constants, so+ web and worker cannot diverge.+- Web: per-user (5) and per-org (20) active-run ceilings.+- Fixed implementation timings: 5000 ms worker heartbeat, 60000 ms stale+ heartbeat, 1000 ms watch poll, 15000 ms keepalive, and 90000 ms watch+ connection. These are intentionally not environment variables.+## Sandbox Runtime-`server/sandbox/service.ts` gives the agent a conversation-scoped sandbox interface with `read`, `write`, `edit`, and `bash`. Sessions are created lazily on the first sandbox tool call. The service reuses a live or suspended provider session identified by `providerSessionId`; if that session is gone or terminal, it boots a fresh session and persists the replacement id.+The worker runtime sandbox service gives the agent a conversation-scoped sandbox interface with `read`, `write`, and `edit` plus a separate turn-end callback. It reuses an existing provider session when the stored provider/session/TTL still match, otherwise it boots a fresh session and persists the new state on the conversation.Both sandbox providers target the same runtime contract from `packages/in-app-agent-sandbox-runtime`.@@ -216,19 +228,16 @@ MCP registry behavior:- In-app-agent keys can call read-only tools directly when the tool has `readOnlyHint: true`.- In-app-agent keys need a valid tool override to call named non-read-only Langfuse MCP tools.-RBAC is the first gate for Langfuse MCP tools. Before a tool is exposed to the model, `server/mcpPolicy.ts` checks the signed-in user's `projectRole` and `isAdmin` against the tool's required `ProjectScope` with `hasProjectAccess()`. That means the assistant never sees tools the user could not use manually in the product UI or APIs. Human approval is a second gate on top of RBAC for tools classified as `"approval"`: approval can allow one execution of a tool the user already has access to, but it does not widen the user's project permissions.--Human approval is separate from the MCP tool override. Shared `server/mcpPolicy.ts` classifies every Langfuse MCP tool in `IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES`, using unprefixed MCP registry names and either `"auto"` or `"approval"`. The web in-app-agent server test imports the MCP registry's `McpToolName` contract and verifies both type equality and runtime registry equality, so adding a Langfuse MCP tool requires an explicit in-app agent approval classification without making MCP bootstrap depend on the in-app agent.+RBAC is the first gate for Langfuse MCP tools. Before a tool is exposed to the model, shared `mcpPolicy.ts` checks the signed-in user's `projectRole` and `isAdmin` against the tool's required `ProjectScope` with `hasProjectAccess()`. That means the assistant never sees tools the user could not use manually in the product UI or APIs. Human approval is a second gate on top of RBAC for tools classified as `"approval"`: approval can allow one execution of a tool the user already has access to, but it does not widen the user's project permissions.-`server/mcpPolicy.ts` turns that map into an `InAppAgentToolPolicy` with an `available` set for tools the model may see and an `autoApproved` set for tools that run without a prompt. `createInAppAgentToolPolicy()` intersects stored grants with current availability, so an unknown, deleted, reclassified, or now-out-of-role tool silently drops out. Local tools such as `IN_APP_AGENT_REDIRECT_TOOL_NAME` and the sandbox tools are always auto-approved; docs MCP tools are auto-approved by the `langfuseDocs_` prefix. `server/agent.ts` marks every other tool with Mastra `requireApproval: true`.+Human approval is separate from the MCP tool override. Shared `mcpPolicy.ts` classifies every Langfuse MCP tool in `IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES`, using unprefixed MCP registry names and either `"auto"` or `"approval"`. The web in-app-agent server test imports the MCP registry's `McpToolName` contract and verifies both type equality and runtime registry equality, so adding a Langfuse MCP tool requires an explicit in-app agent approval classification without making MCP bootstrap depend on the in-app agent.-Conversation-scoped grants live in `InAppAgentConversation.alwaysAllowedTools`, holding server-prefixed names such as `langfuse_createDashboardWidget`. The prefix is part of the identity, so a stored grant cannot be mistaken for a same-named tool on another MCP surface; unprefixed entries are rejected when the policy is rebuilt. Grants are written inside the same locked transaction as the approval decision in `server/runLifecycle.ts`. A one-off `Approve` writes nothing there; only `Always approve` does. The worker rebuilds the policy from the column on every run rather than trusting enqueue-time authorization. Mastra emits an interrupt, the browser asks the user, and the router records the decision for a durable worker continuation. `server/human-in-the-loop.ts` adapts Mastra's runtime interrupt payload into the Langfuse-owned `tool_approval_request` contract from `schema.ts`; the browser stores and forwards only that runtime-neutral shape.-The browser-safe `interrupts.ts` parser adapts Mastra's runtime payload into the Langfuse-owned `tool_approval_request` contract from `schema.ts`; browser, web server, and worker all consume that same parser.+The internal auto-approval set is derived from that map by prefixing Langfuse MCP tools with `langfuse_` and adding local tools such as `IN_APP_AGENT_REDIRECT_TOOL_NAME`; docs MCP tools are auto-approved by the `langfuseDocs_` prefix. The worker runtime agent marks every other tool with Mastra `requireApproval: true`. Mastra emits an interrupt, the browser asks the user, and the router records the decision for a durable worker continuation. The browser-safe `interrupts.ts` parser adapts Mastra's runtime payload into the Langfuse-owned `tool_approval_request` contract from `schema.ts`; browser, web server, and worker all consume that same parser.The `InAppAgentPendingToolApproval` table is not used by background execution.It remains temporarily so existing rows and Prisma relations stay valid.-Sandbox tools are separate from MCP authorization. When a sandbox provider is enabled, `server/tools.ts` adds local `read`, `write`, `edit`, and `bash` tools backed by the sandbox provider contract rather than the MCP registry.+Sandbox tools are separate from MCP authorization. When a sandbox provider is enabled, the worker runtime adds local `read`, `write`, `edit`, and `bash` tools backed by the sandbox provider contract rather than the MCP registry.## Change Rulesdiff --git a/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsx b/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsxindex 250e9f64e3..001f2e907b 100644--- a/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsx+++ b/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsx@@ -20,8 +20,10 @@ import {isCancellableBackgroundRun,type BackgroundExecutionRunView,} from "@/src/features/in-app-agent/lib/backgroundExecutionSession";-import { InAppAgentRunStatus } from "@langfuse/shared";-import { isUnsettledInAppAgentRunStatus } from "@langfuse/shared/in-app-agent";+import {+ InAppAgentRunStatus,+ isUnsettledInAppAgentRunStatus,+} from "@langfuse/shared/in-app-agent";function getBackgroundRunNotice(run: BackgroundExecutionRunView | null,diff --git a/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx b/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsxindex c1713a15e3..42d3f37f6a 100644--- a/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx@@ -6,8 +6,11 @@ import {waitFor,} from "@testing-library/react";import { EventType } from "@ag-ui/core";-import { InAppAgentRunErrorCode, InAppAgentRunStatus } from "@langfuse/shared";-import type { AgUiMessage } from "@langfuse/shared/in-app-agent";+import {+ InAppAgentRunErrorCode,+ InAppAgentRunStatus,+ type AgUiMessage,+} from "@langfuse/shared/in-app-agent";import { TooltipProvider } from "@/src/components/ui/tooltip";import { ControlledInAppAgentWindow } from "./ControlledInAppAgentWindow";diff --git a/web/src/features/in-app-agent/components/InAppAgentMessage.tsx b/web/src/features/in-app-agent/components/InAppAgentMessage.tsxindex cc8ef87c47..888c34686b 100644--- a/web/src/features/in-app-agent/components/InAppAgentMessage.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentMessage.tsx@@ -27,11 +27,11 @@ import {type ButtonHTMLAttributes,type ReactNode,} from "react";-import {- type InAppAgentMessageFeedback,- type InAppAgentMessageFeedbackValue,- type InAppAgentMessageSource,-} from "@langfuse/shared/in-app-agent";+import type {+ InAppAgentMessageFeedback,+ InAppAgentMessageFeedbackValue,+ InAppAgentMessageSource,+} from "../schema";import {Popover,PopoverAnchor,diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsxindex f062a4272a..98b8607840 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsx@@ -6,7 +6,7 @@ import {within,} from "@testing-library/react";import { ScanSearch } from "lucide-react";-import { InAppAgentRunStatus } from "@langfuse/shared";+import { InAppAgentRunStatus } from "@langfuse/shared/in-app-agent";import { TooltipProvider } from "@/src/components/ui/tooltip";import {InAppAgentWindow,diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.tsxindex 22592d6a9d..3d25736038 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.tsx@@ -47,12 +47,11 @@ import {type InAppAgentMessageContent,type InAppAgentMessageRole,} from "./InAppAgentMessage";-import {- IN_APP_AGENT_GENERIC_ERROR_MESSAGE,- type InAppAgentMessageFeedbackValue,- type InAppAgentMessageSource,-} from "@langfuse/shared/in-app-agent";-import { deduplicateBy } from "@/src/utils/arrays";+import type {+ InAppAgentMessageFeedbackValue,+ InAppAgentMessageSource,+} from "../schema";+import { IN_APP_AGENT_GENERIC_ERROR_MESSAGE } from "@langfuse/shared/in-app-agent";import type { InAppAgentScreenContextDescription } from "@/src/features/in-app-agent/context";import type { InAppAgentActivityByConversationId } from "@/src/features/in-app-agent/lib/inAppAgentActivity";import { ConversationActivityIndicator } from "@/src/features/in-app-agent/components/ConversationActivityIndicator";@@ -64,6 +63,7 @@ import {type InAppAgentError,isInAppAgentRateLimited,} from "@/src/features/in-app-agent/components/utils/utils";+import { deduplicateBy } from "@/src/utils/arrays";import messageStyles from "./InAppAgentMessage.module.css";import styles from "./InAppAgentWindow.module.css";import { assertUnreachable } from "@/src/utils/types";diff --git a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsxindex 8caa0f5dc1..9b5d96a962 100644--- a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx+++ b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx@@ -16,20 +16,21 @@ import { useSession } from "next-auth/react";import { useRouter } from "next/router";import useSessionStorage from "@/src/components/useSessionStorage";-import {- createInAppAgentConversationId,- IN_APP_AGENT_REDIRECT_TOOL_NAME,-} from "@langfuse/shared/in-app-agent";+import { createInAppAgentConversationId } from "../ids";+import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@langfuse/shared/in-app-agent";import {AgUiMessageSchema,dropEmptyAssistantMessages,dropUnpairedAssistantToolCalls,- isActiveInAppAgentRunStatus,type AgUiMessage,- type InAppAgentMessageFeedback,- type InAppAgentMessageFeedbackValue,type InAppAgentToolApprovalRequest,} from "@langfuse/shared/in-app-agent";+import { isActiveInAppAgentRunStatus } from "../watchFrames";+import type {+ InAppAgentMessageFeedback,+ InAppAgentMessageFeedbackValue,+ InAppAgentUiMessage,+} from "../schema";import {createInAppAgentDisplayState,deserializeInAppAgentDisplayState,@@ -1525,7 +1526,7 @@ function isAgentConversationMessage(message: unknown): message is AgUiMessage {function mergeMessagesWithFeedback(messages: readonly AgUiMessage[],feedbackByMessageId: Record<string, InAppAgentMessageFeedback> | undefined,-): readonly AgUiMessage[] {+): readonly InAppAgentUiMessage[] {if (!feedbackByMessageId || Object.keys(feedbackByMessageId).length === 0) {return messages;}diff --git a/web/src/features/in-app-agent/components/utils/utils.ts b/web/src/features/in-app-agent/components/utils/utils.tsindex 8ec181c9cd..e86e369f5d 100644--- a/web/src/features/in-app-agent/components/utils/utils.ts+++ b/web/src/features/in-app-agent/components/utils/utils.ts@@ -11,11 +11,14 @@ import {import {AgUiMessageSchema,type AgUiMessage,+ InAppAgentRedirectActionToolResultSchema,InAppAgentRateLimitErrorResponseSchema,+} from "@langfuse/shared/in-app-agent";+import {+ InAppAgentMessageFeedbackSchema,type InAppAgentMessageSource,- InAppAgentRedirectActionToolResultSchema,InAppAgentMessageSourceSchema,-} from "@langfuse/shared/in-app-agent";+} from "../../schema";export type InAppAgentError =| { type: "generic"; message: string }@@ -26,6 +29,7 @@ const InAppAiAgentMessageSchema = AgUiMessageSchema.and(isLoading: z.boolean().optional(),feedbackMessageId: z.string().optional(),timestamp: z.number().optional(),+ feedback: InAppAgentMessageFeedbackSchema.optional(),}),);diff --git a/web/src/features/in-app-agent/context.ts b/web/src/features/in-app-agent/context.tsindex a2b80023b6..0fa23a2c48 100644--- a/web/src/features/in-app-agent/context.ts+++ b/web/src/features/in-app-agent/context.ts@@ -1,8 +1,8 @@-import type { AgUiRunAgentInput } from "@langfuse/shared/in-app-agent";+import type { AgUiContext } from "@langfuse/shared/in-app-agent";import { getInAppAgentProjectRoute } from "@/src/features/in-app-agent/routeContext";import type { FilterState } from "@langfuse/shared";-type InAppAgentContext = AgUiRunAgentInput["context"];+type InAppAgentContext = AgUiContext;export type InAppAgentScreenContextDescription =| { type: "page" }diff --git a/packages/shared/src/in-app-agent/ids.ts b/web/src/features/in-app-agent/ids.tssimilarity index 100%rename from packages/shared/src/in-app-agent/ids.tsrename to web/src/features/in-app-agent/ids.tsdiff --git a/web/src/features/in-app-agent/lib/backgroundAgentClient.ts b/web/src/features/in-app-agent/lib/backgroundAgentClient.tsindex 002f349312..6b5e2195c4 100644--- a/web/src/features/in-app-agent/lib/backgroundAgentClient.ts+++ b/web/src/features/in-app-agent/lib/backgroundAgentClient.ts@@ -2,13 +2,15 @@ import { AbstractAgent, type RunAgentInput } from "@ag-ui/client";import { EventType, type BaseEvent } from "@ag-ui/core";import { Observable } from "rxjs";-import { InAppAgentRunStatus } from "@langfuse/shared";import {- InAppAgentWatchFrameSchema,+ InAppAgentRunStatus,+ type AgUiContext,type AgUiMessage,- type AgUiRunAgentInput,- type InAppAgentWatchFrame,} from "@langfuse/shared/in-app-agent";+import {+ InAppAgentWatchFrameSchema,+ type InAppAgentWatchFrame,+} from "../watchFrames";import { env } from "@/src/env.mjs";import { parseSSEBuffer } from "@/src/hooks/useSSEDashboardQuery";@@ -44,18 +46,13 @@ function sleep(ms: number, signal: AbortSignal): Promise<void> {type StartRunFn = (params: {message: string;- context: AgUiRunAgentInput["context"];+ context: AgUiContext;}) => Promise<{ runId: string }>;type RunFramingState = {openRunId: string | null;};-// AG-UI's Zod v3 declarations resolve as unknown against this repo's Zod v4.-function asAgUiRunAgentInput(input: RunAgentInput): AgUiRunAgentInput {- return input as unknown as AgUiRunAgentInput;-}-// AG-UI transport backed by a tRPC start mutation and persisted event tail.export class InAppAgentBackgroundClient extends AbstractAgent {private readonly projectId: string;@@ -92,15 +89,18 @@ export class InAppAgentBackgroundClient extends AbstractAgent {return new Observable<BaseEvent>((subscriber) => {const controller = this.resetAbortController();- const runInput = asAgUiRunAgentInput(input);- const message = getLastUserMessageContent(runInput.messages);+ const messages = input.messages as unknown as AgUiMessage[];+ const message = getLastUserMessageContent(messages);if (!message) {subscriber.error(new Error("A user message is required"));return;}- this.startRun({ message, context: runInput.context })+ this.startRun({+ message,+ context: input.context as unknown as AgUiContext,+ }).then(({ runId }) => {this.onStatus?.({type: "status",@@ -363,7 +363,7 @@ function getErrorMessage(error: unknown): string {}function getLastUserMessageContent(- messages: AgUiRunAgentInput["messages"],+ messages: readonly AgUiMessage[],): string | undefined {for (let index = messages.length - 1; index >= 0; index -= 1) {const message = messages[index];diff --git a/web/src/features/in-app-agent/lib/backgroundExecutionSession.clienttest.ts b/web/src/features/in-app-agent/lib/backgroundExecutionSession.clienttest.tsindex aa91ec3324..1cfeaa2419 100644--- a/web/src/features/in-app-agent/lib/backgroundExecutionSession.clienttest.ts+++ b/web/src/features/in-app-agent/lib/backgroundExecutionSession.clienttest.ts@@ -2,8 +2,11 @@ import { EventType } from "@ag-ui/core";import type { AgentSubscriber } from "@ag-ui/client";import { afterEach, describe, expect, it, vi } from "vitest";-import { InAppAgentRunErrorCode, InAppAgentRunStatus } from "@langfuse/shared";-import type { AgUiMessage } from "@langfuse/shared/in-app-agent";+import {+ InAppAgentRunErrorCode,+ InAppAgentRunStatus,+ type AgUiMessage,+} from "@langfuse/shared/in-app-agent";import { InAppAgentBackgroundClient } from "./backgroundAgentClient";import {diff --git a/web/src/features/in-app-agent/lib/backgroundExecutionSession.ts b/web/src/features/in-app-agent/lib/backgroundExecutionSession.tsindex 62d12d1b27..e1cf59e4df 100644--- a/web/src/features/in-app-agent/lib/backgroundExecutionSession.ts+++ b/web/src/features/in-app-agent/lib/backgroundExecutionSession.ts@@ -1,16 +1,17 @@import type { AgentSubscriber } from "@ag-ui/client";-import { InAppAgentRunErrorCode, InAppAgentRunStatus } from "@langfuse/shared";import type {- AgUiRunAgentInput,+ AgUiContext,AgUiMessage,InAppAgentToolApprovalRequest,} from "@langfuse/shared/in-app-agent";import {AgUiMessageSchema,- createInAppAgentMessageId,+ InAppAgentRunErrorCode,+ InAppAgentRunStatus,parseInAppAgentInterruptEvent,} from "@langfuse/shared/in-app-agent";+import { createInAppAgentMessageId } from "../ids";import { BackgroundExecutionConnectionError } from "./backgroundExecutionErrors";import {createInAppAgentDisplayState,@@ -21,7 +22,7 @@ import {export type BackgroundExecutionRunCommand = {message: string;- context: AgUiRunAgentInput["context"];+ context: AgUiContext;};export type ApprovalDecision = {@@ -84,7 +85,7 @@ type BackgroundExecutionAgent = {addMessage(message: AgUiMessage): void;setMessages(messages: AgUiMessage[]): void;subscribe(subscriber: AgentSubscriber): { unsubscribe(): void };- runAgent(input: { context: AgUiRunAgentInput["context"] }): Promise<unknown>;+ runAgent(input: { context: AgUiContext }): Promise<unknown>;connectAgent(): Promise<unknown>;abortRun(): void;setCursor(cursor: number): void;diff --git a/web/src/features/in-app-agent/lib/display.clienttest.ts b/web/src/features/in-app-agent/lib/display.clienttest.tsindex f729c40427..6fd7c84811 100644--- a/web/src/features/in-app-agent/lib/display.clienttest.ts+++ b/web/src/features/in-app-agent/lib/display.clienttest.ts@@ -1,4 +1,5 @@import type { AgUiMessage } from "@langfuse/shared/in-app-agent";+import type { InAppAgentUiMessage } from "../schema";import {createInAppAgentDisplayState,deserializeInAppAgentDisplayState,@@ -93,7 +94,7 @@ describe("in-app agent display projection", () => {content: "Compare both weeks",},assistantMessage,- ] satisfies AgUiMessage[];+ ] satisfies InAppAgentUiMessage[];const messagesWithBothTools = [initialMessages[0],{@@ -241,7 +242,7 @@ describe("in-app agent display projection", () => {runId: "run-1",feedback: { value: "thumbs_up", comment: null },},- ] satisfies AgUiMessage[];+ ] satisfies InAppAgentUiMessage[];const reasoningMessages = firstMessages.concat({id: "reasoning-2",role: "reasoning",diff --git a/web/src/features/in-app-agent/lib/display.ts b/web/src/features/in-app-agent/lib/display.tsindex 97992ec31c..5127f9ea61 100644--- a/web/src/features/in-app-agent/lib/display.ts+++ b/web/src/features/in-app-agent/lib/display.ts@@ -2,6 +2,7 @@ import { z } from "zod";import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@langfuse/shared/in-app-agent";import type { AgUiMessage } from "@langfuse/shared/in-app-agent";+import type { InAppAgentUiMessage } from "../schema";/*** Rendering-only derivation of the persisted event log. The canonical messages@@ -44,7 +45,7 @@ export type InAppAgentDisplayState = {toolCallPlacements: Record<string, InAppAgentDisplayPlacement | null>;};-type InAppAgentDisplayMessage = AgUiMessage & {+type InAppAgentDisplayMessage = InAppAgentUiMessage & {feedbackMessageId?: string;timestamp?: number;};@@ -280,7 +281,7 @@ export function recordInAppAgentToolCallForDisplay(}export function projectInAppAgentMessagesForDisplay(- messages: readonly AgUiMessage[],+ messages: readonly InAppAgentUiMessage[],state: InAppAgentDisplayState,): InAppAgentDisplayMessage[] {// Canonical messages stay untouched for persistence and subsequent runs.diff --git a/web/src/features/in-app-agent/schema.ts b/web/src/features/in-app-agent/schema.tsnew file mode 100644index 0000000000..86d2fc229b--- /dev/null+++ b/web/src/features/in-app-agent/schema.ts@@ -0,0 +1,56 @@+import { z } from "zod";++import type { AgUiMessage } from "@langfuse/shared/in-app-agent";++export const InAppAgentMessageFeedbackValueSchema = z.enum([+ "thumbs_up",+ "thumbs_down",+]);++export type InAppAgentMessageFeedbackValue = z.infer<+ typeof InAppAgentMessageFeedbackValueSchema+>;++export const InAppAgentMessageFeedbackSchema = z.object({+ value: InAppAgentMessageFeedbackValueSchema,+ comment: z.string().nullable(),+});++export type InAppAgentMessageFeedback = z.infer<+ typeof InAppAgentMessageFeedbackSchema+>;++export type InAppAgentUiMessage = AgUiMessage & {+ feedback?: InAppAgentMessageFeedback;+};++const AbsoluteHttpUrlSchema = z.string().transform((value, ctx) => {+ let parsedUrl: URL;++ try {+ parsedUrl = new URL(value);+ } catch {+ ctx.addIssue({ code: "custom", message: "URL must be absolute" });+ return z.NEVER;+ }++ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {+ ctx.addIssue({+ code: "custom",+ message: "URL protocol must be http or https",+ });+ return z.NEVER;+ }++ return parsedUrl.href;+});++export const InAppAgentMessageSourceSchema = z.object({+ title: z.string(),+ url: AbsoluteHttpUrlSchema,+ faviconUrl: AbsoluteHttpUrlSchema,+});++export type InAppAgentMessageSource = z.infer<+ typeof InAppAgentMessageSourceSchema+>;diff --git a/web/src/features/in-app-agent/server/backgroundRunService.ts b/web/src/features/in-app-agent/server/backgroundRunService.tsindex 687ab39200..63412b9cc8 100644--- a/web/src/features/in-app-agent/server/backgroundRunService.ts+++ b/web/src/features/in-app-agent/server/backgroundRunService.ts@@ -1,14 +1,7 @@import { EventType } from "@ag-ui/core";import { randomUUID } from "crypto";-import {- BaseError,- InAppAgentRunErrorCode,- InAppAgentRunStatus,- InAppAgentRunStatusSchema,- LangfuseNotFoundError,- type Plan,-} from "@langfuse/shared";+import { BaseError, LangfuseNotFoundError, type Plan } from "@langfuse/shared";import { Prisma, type PrismaClient } from "@langfuse/shared/src/db";import {InAppAgentRunQueue,@@ -18,13 +11,15 @@ import {} from "@langfuse/shared/src/server";import { deleteApiKeyFromDb } from "@langfuse/shared/src/server/auth/apiKeys";import {- createInAppAgentMessageId,- createInAppAgentRunId,+ InAppAgentRunErrorCode,+ InAppAgentRunStatus,+ InAppAgentRunStatusSchema,parseInAppAgentApprovalDecisionEvent,parseInAppAgentInterruptEvent,- type AgUiRunAgentInput,+ type AgUiContext,} from "@langfuse/shared/in-app-agent";import { getInAppAgentPrefixedToolName } from "@langfuse/shared/in-app-agent/server/mcpPolicy";+import { createInAppAgentMessageId, createInAppAgentRunId } from "../ids";import {ensureOwnedConversation,getConversationEvents,@@ -192,7 +187,7 @@ export async function startBackgroundRun(params: {conversationId: string;userId: string;message: string;- context: AgUiRunAgentInput["context"];+ context: AgUiContext;isV4Enabled: boolean;model: string | undefined;aiTelemetryEnabled: boolean;diff --git a/web/src/features/in-app-agent/server/router.ts b/web/src/features/in-app-agent/server/router.tsindex 6747e2419b..da0a695968 100644--- a/web/src/features/in-app-agent/server/router.ts+++ b/web/src/features/in-app-agent/server/router.ts@@ -17,7 +17,7 @@ import {getInAppAgentInstrumentationObservationId,getInAppAgentInstrumentationTraceId,} from "@langfuse/shared/in-app-agent";-import { InAppAgentMessageFeedbackValueSchema } from "@langfuse/shared/in-app-agent";+import { InAppAgentMessageFeedbackValueSchema } from "../schema";import { assertInAppAgentAvailable } from "@/src/features/in-app-agent/server/availability";import {createTRPCRouter,diff --git a/web/src/features/in-app-agent/server/runCapacity.ts b/web/src/features/in-app-agent/server/runCapacity.tsindex 8ab28d1fa6..a986fda261 100644--- a/web/src/features/in-app-agent/server/runCapacity.ts+++ b/web/src/features/in-app-agent/server/runCapacity.ts@@ -1,7 +1,12 @@import { BaseError, type Plan } from "@langfuse/shared";import type { PrismaClient } from "@langfuse/shared/src/db";-import { env } from "@langfuse/shared/src/env";+import {+ IN_APP_AGENT_HEARTBEAT_STALE_MS,+ IN_APP_AGENT_QUEUE_TIMEOUT_MS,+ IN_APP_AGENT_RUN_MAX_DURATION_MS,+} from "@langfuse/shared/in-app-agent/server/tunables";import { recordIncrement } from "@langfuse/shared/src/server";+import { env } from "@/src/env.mjs";/*** Flat safety ceiling on concurrent non-terminal runs, checked at admission.@@ -36,15 +41,15 @@ export async function assertInAppAgentRunCapacity(params: {// wins because a hung tool may keep renewing its heartbeat").const reconcilableBefore = new Date(Date.now() -- env.LANGFUSE_IN_APP_AGENT_QUEUE_TIMEOUT_MS -- env.LANGFUSE_IN_APP_AGENT_RUN_MAX_DURATION_MS,+ IN_APP_AGENT_QUEUE_TIMEOUT_MS -+ IN_APP_AGENT_RUN_MAX_DURATION_MS,);// Which is why a fresh heartbeat overrides that test. It is the one positive// liveness signal a row carries, and a run still holding a worker must keep// counting however old it is, or the ceiling leaks exactly when hung runs are// accumulating.const heartbeatAliveSince = new Date(- Date.now() - env.LANGFUSE_IN_APP_AGENT_HEARTBEAT_STALE_MS,+ Date.now() - IN_APP_AGENT_HEARTBEAT_STALE_MS,);// Grouped by user so one query answers both ceilings. Scoped through thediff --git a/web/src/features/in-app-agent/server/runContext.ts b/web/src/features/in-app-agent/server/runContext.tsindex e9d6c42244..2da8bea2d8 100644--- a/web/src/features/in-app-agent/server/runContext.ts+++ b/web/src/features/in-app-agent/server/runContext.ts@@ -3,9 +3,9 @@ import {LangfuseNotFoundError,TableViewPresetTableName,} from "@langfuse/shared";-import type { AgUiRunAgentInput } from "@langfuse/shared/in-app-agent";+import type { AgUiContext } from "@langfuse/shared/in-app-agent";-type InAppAgentContext = AgUiRunAgentInput["context"];+type InAppAgentContext = AgUiContext;import {logger,parseSavedViewFromURL,diff --git a/packages/shared/src/in-app-agent/server/watch.ts b/web/src/features/in-app-agent/server/watch.tssimilarity index 86%rename from packages/shared/src/in-app-agent/server/watch.tsrename to web/src/features/in-app-agent/server/watch.tsindex 6787c91b23..12c37adf43 100644--- a/packages/shared/src/in-app-agent/server/watch.ts+++ b/web/src/features/in-app-agent/server/watch.ts@@ -1,20 +1,22 @@import { EventType } from "@ag-ui/core";-import { InAppAgentRunStatus, InAppAgentRunStatusSchema } from "../../index";-import { type PrismaClient } from "../../db";+import {+ InAppAgentRunStatus,+ InAppAgentRunStatusSchema,+ type AgUiEvent,+} from "@langfuse/shared/in-app-agent";+import { type PrismaClient } from "@langfuse/shared/src/db";+import { reconcileConversationRuns } from "@langfuse/shared/in-app-agent/server/runLifecycle";+import { toPublicInAppAgentEvent } from "@langfuse/shared/in-app-agent/server/toolResults";+import { IN_APP_AGENT_HEARTBEAT_STALE_MS } from "@langfuse/shared/in-app-agent/server/tunables";import {isActiveInAppAgentRunStatus,type InAppAgentWatchFrame,-} from "../backgroundWatch";-import type { AgUiEvent } from "../schema";-import { reconcileConversationRuns } from "./runLifecycle";-import { getPublicInAppAgentMcpToolResultContent } from "./toolResults";-import {- IN_APP_AGENT_HEARTBEAT_STALE_MS,- IN_APP_AGENT_WATCH_KEEPALIVE_MS,- IN_APP_AGENT_WATCH_MAX_CONNECTION_MS,- IN_APP_AGENT_WATCH_TAIL_POLL_MS,-} from "./tunables";+} from "../watchFrames";++const IN_APP_AGENT_WATCH_TAIL_POLL_MS = 1_000;+const IN_APP_AGENT_WATCH_KEEPALIVE_MS = 15_000;+const IN_APP_AGENT_WATCH_MAX_CONNECTION_MS = 90_000;/*** Tail persisted events while preserving AG-UI run framing. Synthetic frames@@ -136,7 +138,7 @@ export async function* watchConversationFrames(params: {yield {type: "event",sequenceNumber: row.sequenceNumber,- event: toPublicEvent(event),+ event: toPublicInAppAgentEvent(event),};if (@@ -237,29 +239,6 @@ function isStaleClaimedRun(return now - lastSign.getTime() > IN_APP_AGENT_HEARTBEAT_STALE_MS;}-/** Withhold private persisted event payloads from the browser watch stream. */-export function toPublicEvent(event: AgUiEvent): AgUiEvent {- if (event.type === EventType.RUN_STARTED && event.input !== undefined) {- const publicEvent = { ...event };- delete publicEvent.input;-- return publicEvent;- }-- if (event.type === EventType.TOOL_CALL_RESULT) {- if (typeof event.content !== "string") {- return event;- }-- return {- ...event,- content: getPublicInAppAgentMcpToolResultContent(event.content),- };- }-- return event;-}-function syntheticFrame(cursor: number,event: AgUiEvent,diff --git a/web/src/features/in-app-agent/server/watchHandler.ts b/web/src/features/in-app-agent/server/watchHandler.tsindex 38ff0de5e6..50bb5c9b9c 100644--- a/web/src/features/in-app-agent/server/watchHandler.ts+++ b/web/src/features/in-app-agent/server/watchHandler.ts@@ -1,9 +1,9 @@import { BaseError, ForbiddenError, UnauthorizedError } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";import { addUserToSpan, logger } from "@langfuse/shared/src/server";-import type { InAppAgentWatchFrame } from "@langfuse/shared/in-app-agent";-import { assertConversationAccess } from "@langfuse/shared/in-app-agent/server/access";-import { watchConversationFrames } from "@langfuse/shared/in-app-agent/server/watch";+import { assertOwnedConversation } from "@langfuse/shared/in-app-agent/server/persistence";+import type { InAppAgentWatchFrame } from "../watchFrames";+import { watchConversationFrames } from "./watch";import { z } from "zod";import { assertInAppAgentAvailable } from "@/src/features/in-app-agent/server/availability";@@ -61,7 +61,7 @@ export default async function watchHandler(request: Request) {throw new BaseError("NotFoundError", 404, "Conversation not found", true);}- assertConversationAccess({+ assertOwnedConversation({conversation,userId: user.id,});diff --git a/web/src/features/in-app-agent/watchFrames.ts b/web/src/features/in-app-agent/watchFrames.tsnew file mode 100644index 0000000000..78ec93202d--- /dev/null+++ b/web/src/features/in-app-agent/watchFrames.ts@@ -0,0 +1,40 @@+import { z } from "zod";++import {+ InAppAgentRunStatus,+ InAppAgentRunStatusSchema,+} from "@langfuse/shared/in-app-agent";++export const InAppAgentWatchFrameSchema = z.discriminatedUnion("type", [+ z.object({+ type: z.literal("status"),+ runId: z.string(),+ status: InAppAgentRunStatusSchema,+ errorCode: z.string().nullable().optional(),+ /** Cancellation is cooperative, so this may be true while status is RUNNING. */+ cancelRequested: z.boolean().optional(),+ }),+ z.object({+ type: z.literal("event"),+ sequenceNumber: z.number().int(),+ event: z.record(z.string(), z.unknown()),+ }),+ z.object({+ type: z.literal("error"),+ code: z.string(),+ message: z.string(),+ }),+ z.object({ type: z.literal("done") }),+]);++export type InAppAgentWatchFrame = z.infer<typeof InAppAgentWatchFrameSchema>;++/** A parked approval occupies neither a worker nor the conversation slot. */+export const IN_APP_AGENT_ACTIVE_RUN_STATUSES: readonly InAppAgentRunStatus[] =+ [InAppAgentRunStatus.QUEUED, InAppAgentRunStatus.RUNNING];++export function isActiveInAppAgentRunStatus(+ status: InAppAgentRunStatus,+): boolean {+ return IN_APP_AGENT_ACTIVE_RUN_STATUSES.includes(status);+}diff --git a/web/src/pages/api/public/mcp/index.ts b/web/src/pages/api/public/mcp/index.tsindex 9252579fdf..241d5068a8 100644--- a/web/src/pages/api/public/mcp/index.ts+++ b/web/src/pages/api/public/mcp/index.ts@@ -46,7 +46,7 @@ import {import { ZodError } from "zod";import { isUserInputError } from "@/src/features/mcp/core/errors";import { IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER } from "@langfuse/shared/in-app-agent";-import { InAppAgentMcpRunOverrideSchema } from "@langfuse/shared/in-app-agent/server/human-in-the-loop";+import { InAppAgentMcpRunOverrideSchema } from "@langfuse/shared/in-app-agent/server/mcpPolicy";// Bootstrap MCP features - registers all tools at module load timeimport "@/src/features/mcp/server/bootstrap";diff --git a/web/vitest.config.mts b/web/vitest.config.mtsindex 77e5745fa5..cf4c678499 100644--- a/web/vitest.config.mts+++ b/web/vitest.config.mts@@ -81,7 +81,7 @@ const sharedSourcePath = (path: string) =>join(import.meta.dirname, "../packages/shared/src", path);// Shared's built dist is CJS, whose require() calls bypass Vitest's module-// graph. Tests that mock the in-app-agent runtime or mutate shared's env need+// graph. Tests that mock in-app-agent storage/lifecycle or mutate shared's env need// one source module identity; applying these aliases globally makes every// server test transform shared.const sharedSourceResolve = {@@ -90,10 +90,6 @@ const sharedSourceResolve = {find: /^@langfuse\/shared\/in-app-agent\/server\/(.+)$/,replacement: sharedSourcePath("in-app-agent/server/$1"),},- {- find: /^@langfuse\/shared\/in-app-agent\/server$/,- replacement: sharedSourcePath("in-app-agent/server/index.ts"),- },{find: /^@langfuse\/shared\/in-app-agent$/,replacement: sharedSourcePath("in-app-agent/index.ts"),@@ -135,12 +131,8 @@ const sharedSourceResolve = {// Runtime source resolves these through shared's node_modules symlinks.// Dedupe keeps one module identity so mocks registered from web intercept.dedupe: [- "@mastra/core",- "@mastra/mcp","@ag-ui/core","@ag-ui/client",- "@ag-ui/mastra",- "ai-sdk-amazon-bedrock-v4","langfuse",],};diff --git a/worker/AGENTS.md b/worker/AGENTS.mdindex d638e0a769..56eb428d94 100644--- a/worker/AGENTS.md+++ b/worker/AGENTS.md@@ -63,6 +63,17 @@- Prefer explicit env-flag gating in `src/app.ts` for new consumers.- Keep queue payload parsing/schema validation centralized in shared contracts.+## In-App Agent Runtime++- `src/features/in-app-agent/runtime/` owns Mastra adaptation, agent execution,+ instrumentation, prompt loading, continuation handling, tools, skills, and+ sandbox providers.+- Worker env owns queue consumer/concurrency, sandbox configuration, and the+ development-only in-app-agent AWS profile. Shared lifecycle policy values+ are fixed constants, so web and worker cannot diverge.+- Persisted/queued contracts, lifecycle, storage, MCP policy, tool-result+ handling, and the seeded system prompt remain explicit shared subpaths.+## Package-Specific Rules- Keep tests independent; no ordering assumptions.diff --git a/worker/package.json b/worker/package.jsonindex 978c0efe09..5502fe3c1b 100644--- a/worker/package.json+++ b/worker/package.json@@ -32,8 +32,14 @@"author": "[email protected]","dependencies": {"@anthropic-ai/tokenizer": "^0.0.4",+ "@ag-ui/core": "^0.0.52",+ "@ag-ui/mastra": "1.1.1","@appsignal/opentelemetry-instrumentation-bullmq": "^0.8.0","@langfuse/shared": "workspace:*",+ "@aws-sdk/client-lambda-microvms": "catalog:",+ "@aws-sdk/credential-providers": "catalog:",+ "@mastra/core": "1.46.0",+ "@mastra/mcp": "1.8.1","@opentelemetry/api": "^1.9.1","@opentelemetry/exporter-trace-otlp-proto": "^0.220.0","@opentelemetry/instrumentation-aws-sdk": "^0.75.0",@@ -48,28 +54,33 @@"@opentelemetry/sdk-node": "^0.220.0","@prisma/client": "^6.19.3","@prisma/instrumentation": "^6.19.3",+ "ai-sdk-amazon-bedrock-v4": "npm:@ai-sdk/[email protected]","bullmq": "^5.76.3","cors": "^2.8.5","csv-parse": "^5.6.0","dd-trace": "5.109.0","decimal.js": "^10.4.3",+ "dockerode": "^4.0.9","dotenv": "^16.4.5","exponential-backoff": "^3.1.2","express": "^5.2.1","helmet": "^7.1.0","ioredis": "^5.10.1","lodash": "4.18.1",+ "langfuse": "3.38.4","p-limit": "^7.3.0","posthog-node": "^5.48.1","stripe": "^17.4.0","tiktoken": "^1.0.20","uuid": "^14.0.0",+ "yaml": "^2.9.0","zod": "^4.3.6"},"devDependencies": {"@repo/eslint-config": "workspace:*","@repo/typescript-config": "workspace:*","@types/cors": "^2.8.17",+ "@types/dockerode": "^4.0.1","@types/express": "^5.0.6","@types/lodash": "^4.17.24","@types/node": "^24.3.0",diff --git a/worker/src/app.ts b/worker/src/app.tsindex 2573516437..6b0245653d 100644--- a/worker/src/app.ts+++ b/worker/src/app.ts@@ -48,7 +48,7 @@ import {CodeEvalExecutionQueue,} from "@langfuse/shared/src/server";import { monitorProcessorTtl } from "@langfuse/shared/monitors/server";-import { IN_APP_AGENT_RUN_MAX_DURATION_MS } from "@langfuse/shared/in-app-agent/server";+import { IN_APP_AGENT_RUN_MAX_DURATION_MS } from "@langfuse/shared/in-app-agent/server/tunables";import { env, v4WritesToEventsTable } from "./env";import { ingestionQueueProcessorBuilder } from "./queues/ingestionQueue";import { BackgroundMigrationManager } from "./backgroundMigrations/backgroundMigrationManager";diff --git a/worker/src/env.ts b/worker/src/env.tsindex 8770fa4f70..25dcc5be5c 100644--- a/worker/src/env.ts+++ b/worker/src/env.ts@@ -234,11 +234,29 @@ const EnvSchema = z.object({QUEUE_CONSUMER_MONITOR_QUEUE_IS_ENABLED: z.enum(["true", "false"]).default("true"),- // Off by default until the background-execution rollout: the consumer needs- // Bedrock/MCP/sandbox config the worker deployment may not carry yet.+ // Opt-in because only workers provisioned for agent execution should consume+ // durable runs; ingestion-only workers must leave this disabled.QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED: z.enum(["true", "false"]).default("false"),+ // The ambient host profile takes precedence over the agent-specific default+ // so local developer credentials win when both are configured.+ AWS_PROFILE: z.string().optional(),+ LANGFUSE_IN_APP_AGENT_AWS_PROFILE: z.string().optional(),+ LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER: z+ .enum(["dangerous-docker", "lambda-microvm"])+ .optional(),+ LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER: z+ .string()+ .optional(),+ LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN: z+ .string()+ .optional(),+ LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN:+ z.string().optional(),+ LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION: z+ .string()+ .optional(),QUEUE_CONSUMER_CLOUD_USAGE_METERING_QUEUE_IS_ENABLED: z.enum(["true", "false"]).default("true"),@@ -680,9 +698,26 @@ const validateV4Flags = (parsed: ParsedEnv): void => {}};+const validateInAppAgentSandboxConfig = (parsed: ParsedEnv): void => {+ if (parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER !== "lambda-microvm") {+ return;+ }++ if (+ !parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER ||+ !parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN ||+ !parsed.LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION+ ) {+ throw new Error(+ "Invalid lambda-microvm sandbox config: image identifier, execution role ARN, and region are required.",+ );+ }+};+const parseEnv = (): ParsedEnv => {const parsed = EnvSchema.parse(removeEmptyEnvVariables(process.env));validateV4Flags(parsed);+ validateInAppAgentSandboxConfig(parsed);return parsed;};diff --git a/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts b/worker/src/features/in-app-agent/executeInAppAgentRun.test.tsindex 70f4265527..8dd39e241f 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts@@ -3,11 +3,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";import { prisma } from "@langfuse/shared/src/db";-import {- createInAppAgentConversationId,- createInAppAgentRunId,- ResumeForwardedPropsSchema,-} from "@langfuse/shared/in-app-agent";+import { ResumeForwardedPropsSchema } from "./runtime/types";+import { env } from "../../env";++const createConversationId = () => `aconv_${randomUUID()}`;+const createRunId = () => `arun_${randomUUID()}`;vi.hoisted(() => {// This suite uses mocked agent execution and does not exercise a sandbox@@ -35,6 +35,9 @@ type AgentScenario = (ctx: {};signal: AbortSignal;options: {+ awsBedrock: {+ profile?: string;+ };langfuseMcp: {toolPolicy: {available: ReadonlySet<string>;@@ -58,18 +61,10 @@ const scenarioRef = vi.hoisted(() => ({titleInferenceCalls: 0,}));-vi.mock("@langfuse/shared/in-app-agent/server", async (importOriginal) => {- const actual =- await importOriginal<- typeof import("@langfuse/shared/in-app-agent/server")- >();-+vi.mock("./runtime/agent", async (importOriginal) => {+ const actual = await importOriginal<typeof import("./runtime/agent")>();return {...actual,- IN_APP_AGENT_HEARTBEAT_INTERVAL_MS: 50,- maybeInferAndPersistConversationTitle: async () => {- scenarioRef.titleInferenceCalls += 1;- },createAgUiStream: async (params: {input: never;signal: AbortSignal;@@ -98,6 +93,16 @@ vi.mock("@langfuse/shared/in-app-agent/server", async (importOriginal) => {};});+vi.mock(+ "@langfuse/shared/in-app-agent/server/tunables",+ async (importOriginal) => ({+ ...(await importOriginal<+ typeof import("@langfuse/shared/in-app-agent/server/tunables")+ >()),+ IN_APP_AGENT_HEARTBEAT_INTERVAL_MS: 50,+ }),+);+vi.mock("@langfuse/shared/src/server/auth/apiKeys", async (importOriginal) => {const actual =await importOriginal<@@ -174,7 +179,7 @@ async function seedBackgroundRun(opts?: {});const conversation = await prisma.inAppAgentConversation.create({data: {- id: createInAppAgentConversationId(),+ id: createConversationId(),projectId,createdByUserId: user.id,title: "background test",@@ -183,7 +188,7 @@ async function seedBackgroundRun(opts?: {});const run = await prisma.inAppAgentRun.create({data: {- id: createInAppAgentRunId(),+ id: createRunId(),projectId,conversationId: conversation.id,triggeredByUserId: user.id,@@ -219,7 +224,7 @@ async function seedApprovedContinuation(opts?: {const { projectId, conversation, run, user } = seeded;const parentRun = await prisma.inAppAgentRun.create({data: {- id: createInAppAgentRunId(),+ id: createRunId(),projectId,conversationId: conversation.id,triggeredByUserId: user.id,@@ -278,6 +283,32 @@ describe("executeInAppAgentRun", () => {expect(scenarioRef.titleInferenceCalls).toBe(0);});+ it("prefers the ambient AWS profile over the configured agent profile", async () => {+ const workerEnv = env as {+ AWS_PROFILE?: string;+ LANGFUSE_IN_APP_AGENT_AWS_PROFILE?: string;+ };+ const originalAwsProfile = workerEnv.AWS_PROFILE;+ const originalConfiguredProfile =+ workerEnv.LANGFUSE_IN_APP_AGENT_AWS_PROFILE;+ workerEnv.AWS_PROFILE = "developer-profile";+ workerEnv.LANGFUSE_IN_APP_AGENT_AWS_PROFILE = "playground";++ const { projectId, run } = await seedBackgroundRun();+ scenarioRef.current = async ({ options }) => {+ expect(options.awsBedrock.profile).toBe("developer-profile");+ await options.onComplete();+ await options.onFinish();+ };++ try {+ await executeInAppAgentRun({ projectId, runId: run.id });+ } finally {+ workerEnv.AWS_PROFILE = originalAwsProfile;+ workerEnv.LANGFUSE_IN_APP_AGENT_AWS_PROFILE = originalConfiguredProfile;+ }+ });+it("passes persisted continuation context to the agent input", async () => {const rootRunId = "root-run-1";const traceStartedAt = "2026-08-14T10:00:00.000Z";diff --git a/worker/src/features/in-app-agent/executeInAppAgentRun.ts b/worker/src/features/in-app-agent/executeInAppAgentRun.tsindex 39ef2976cf..a712285b11 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.ts@@ -1,10 +1,4 @@-import {- InAppAgentRunErrorCode,- InAppAgentRunRequestSchema,- InAppAgentRunStatus,- Role,- type InAppAgentRunRequest,-} from "@langfuse/shared";+import { Role } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";import { env as sharedEnv } from "@langfuse/shared/src/env";import {@@ -17,38 +11,46 @@ import {deleteApiKeyFromDb,} from "@langfuse/shared/src/server/auth/apiKeys";import {+ InAppAgentRunErrorCode,+ InAppAgentRunRequestSchema,+ InAppAgentRunStatus,getInAppAgentInstrumentationTraceId,parseInAppAgentInterruptEvent,type AgUiEvent,- type AgUiRunAgentInput,+ type InAppAgentRunRequest,type InAppAgentToolApprovalRequest,} from "@langfuse/shared/in-app-agent";import {- claimQueuedRun,- clearRunMcpApiKeyPointer,- createAgUiStream,- createInAppAgentMcpRunOverride,- createInAppAgentSandbox,createSandboxToolCallFileAccumulator,- finishClaimedRun,flushPendingRunEvents,getConversationEvents,getConversationMessagesForReplay,- getInAppAgentPromptClient,+ shouldFlushPersistedEvent,+ toPersistableAgentEvent,+ type PersistedConversationEvent,+} from "@langfuse/shared/in-app-agent/server/persistence";+import {+ claimQueuedRun,+ clearRunMcpApiKeyPointer,+ finishClaimedRun,heartbeatClaimedRun,- IN_APP_AGENT_HEARTBEAT_INTERVAL_MS,+} from "@langfuse/shared/in-app-agent/server/runLifecycle";+import {+ createInAppAgentMcpRunOverride,createInAppAgentToolPolicy,getInAppAgentMcpAllowedToolNames,getInAppAgentRegistryToolName,- shouldFlushPersistedEvent,- toPersistableAgentEvent,type InAppAgentUserAccess,- type PersistedConversationEvent,-} from "@langfuse/shared/in-app-agent/server";+} from "@langfuse/shared/in-app-agent/server/mcpPolicy";+import { IN_APP_AGENT_HEARTBEAT_INTERVAL_MS } from "@langfuse/shared/in-app-agent/server/tunables";import {createInAppAgentSandboxProvider,getDefaultInAppAgentSandboxProviderType,-} from "@langfuse/shared/in-app-agent/server/sandbox/config";+} from "./runtime/sandbox/config";+import { createInAppAgentSandbox } from "./runtime/sandbox";+import { createAgUiStream } from "./runtime/agent";+import { getInAppAgentPromptClient } from "./runtime/promptClient";+import type { AgUiRunAgentInput } from "./runtime/types";import { env } from "../../env";@@ -74,6 +76,7 @@ export async function executeInAppAgentRun(params: {runId: string;}): Promise<void> {const { projectId, runId } = params;+ const awsProfile = env.AWS_PROFILE ?? env.LANGFUSE_IN_APP_AGENT_AWS_PROFILE;// Claim CAS: zero rows means duplicate delivery or a run reconciled away// while queued — ack and exit, Postgres owns correctness.@@ -500,9 +503,7 @@ export async function executeInAppAgentRun(params: {awsBedrock: {region: sharedEnv.LANGFUSE_AWS_BEDROCK_REGION,modelId: bedrockModelId,- ...(sharedEnv.LANGFUSE_IN_APP_AGENT_AWS_PROFILE- ? { profile: sharedEnv.LANGFUSE_IN_APP_AGENT_AWS_PROFILE }- : {}),+ ...(awsProfile ? { profile: awsProfile } : {}),},langfuseMcp: {url: getLangfuseMcpUrl(),diff --git a/web/src/__tests__/server/in-app-agent-stream.servertest.ts b/worker/src/features/in-app-agent/runtime/agent.test.tssimilarity index 95%rename from web/src/__tests__/server/in-app-agent-stream.servertest.tsrename to worker/src/features/in-app-agent/runtime/agent.test.tsindex 6c138bd3df..3207df5ee8 100644--- a/web/src/__tests__/server/in-app-agent-stream.servertest.ts+++ b/worker/src/features/in-app-agent/runtime/agent.test.ts@@ -1,38 +1,29 @@import { EventType } from "@ag-ui/core";import { Agent } from "@mastra/core/agent";import { MCPClient } from "@mastra/mcp";-import { describe, expect, expectTypeOf, it, vi } from "vitest";+import { beforeEach, describe, expect, it, vi } from "vitest";import type { AgUiEvent } from "@langfuse/shared/in-app-agent";import {IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER,- IN_APP_AGENT_MCP_USER_AGENT,IN_APP_AGENT_REDIRECT_TOOL_NAME,IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE,} from "@langfuse/shared/in-app-agent";-import {- patchMastraApprovalChunks,- type createAgUiStream,-} from "@langfuse/shared/in-app-agent/server/agent";+import { createInAppAgentToolPolicy } from "@langfuse/shared/in-app-agent/server/mcpPolicy";+import { patchMastraApprovalChunks, type createAgUiStream } from "./agent";import {createInAppAgentSandbox,type SandboxProvider,type SandboxSession,-} from "@langfuse/shared/in-app-agent/server/sandbox";-import {- createInAppAgentToolPolicy,- IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES,- type InAppAgentLangfuseMcpToolName,-} from "@langfuse/shared/in-app-agent/server/mcpPolicy";+} from "./sandbox";import {DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS,decodeFiltersGeneric,} from "@langfuse/shared";-import "@/src/features/mcp/server/bootstrap";-import type { McpToolName } from "@/src/features/mcp/server/bootstrap";-import { toolRegistry } from "@/src/features/mcp/server/registry";import type { Langfuse } from "langfuse";-import type { InAppAgentTracingConfig } from "@langfuse/shared/in-app-agent/server/instrumentation";+import type { InAppAgentTracingConfig } from "./instrumentation";++const EXPECTED_MCP_USER_AGENT = "langfuse-in-app-agent";// Shape of the tool entries the mocked MCP client feeds into the Agent// constructor. `Agent`'s own `tools` type is a `DynamicArgument` union that@@ -315,7 +306,7 @@ vi.mock("@mastra/mcp", () => ({}),}));-vi.mock("@langfuse/shared/in-app-agent/server/instrumentation", () => ({+vi.mock("./instrumentation", () => ({createInAppAgentInstrumentation:instrumentationMocks.createInAppAgentInstrumentation,}));@@ -470,25 +461,6 @@ describe("patchMastraApprovalChunks", () => {});});-describe("IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES", () => {- const getRegisteredLangfuseMcpTools = () =>- toolRegistry- .getFeatures()- .flatMap((feature) => feature.tools.map((tool) => tool.definition));-- it("classifies every Langfuse MCP tool exactly once", () => {- expectTypeOf<InAppAgentLangfuseMcpToolName>().toEqualTypeOf<McpToolName>();-- const tools = getRegisteredLangfuseMcpTools();- const registeredToolNames = tools.map((tool) => tool.name).sort();- const classifiedToolNames = Object.keys(- IN_APP_AGENT_LANGFUSE_MCP_TOOL_POLICIES,- ).sort();-- expect(classifiedToolNames).toEqual(registeredToolNames);- });-});-describe("createAgUiStream", () => {beforeEach(() => {vi.clearAllMocks();@@ -501,8 +473,7 @@ describe("createAgUiStream", () => {});const initializeBasicTracedAgent = async (runId: string) => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId,@@ -597,8 +568,7 @@ describe("createAgUiStream", () => {});it("serializes valid events including adapter snapshots and reasoning messages", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -962,8 +932,7 @@ describe("createAgUiStream", () => {});it("does not enable Bedrock reasoning for non-Claude models", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -1034,8 +1003,7 @@ describe("createAgUiStream", () => {});it("adds a run instruction when the persisted workspace is gone", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -1108,8 +1076,7 @@ describe("createAgUiStream", () => {});it("stamps top-level error on TOOL_CALL_RESULT from structured failure payloads", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -1206,8 +1173,7 @@ describe("createAgUiStream", () => {});it("stops gating a tool the user approved for the conversation", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -1275,8 +1241,7 @@ describe("createAgUiStream", () => {});it("executes approved tools manually and continues with tool result history", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = createToolApprovalResumeInput(true);adapterEvents.inputs = [];adapterEvents.items = [@@ -1367,7 +1332,7 @@ describe("createAgUiStream", () => {requestInit: {headers: expect.objectContaining({Authorization: expect.stringContaining("Basic "),- "User-Agent": IN_APP_AGENT_MCP_USER_AGENT,+ "User-Agent": EXPECTED_MCP_USER_AGENT,[IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER]: "run-override",}),},@@ -1375,7 +1340,7 @@ describe("createAgUiStream", () => {langfuseDocs: {requestInit: {headers: expect.objectContaining({- "User-Agent": IN_APP_AGENT_MCP_USER_AGENT,+ "User-Agent": EXPECTED_MCP_USER_AGENT,}),},},@@ -1387,14 +1352,14 @@ describe("createAgUiStream", () => {langfuse: {requestInit: {headers: expect.objectContaining({- "User-Agent": IN_APP_AGENT_MCP_USER_AGENT,+ "User-Agent": EXPECTED_MCP_USER_AGENT,}),},},langfuseDocs: {requestInit: {headers: expect.objectContaining({- "User-Agent": IN_APP_AGENT_MCP_USER_AGENT,+ "User-Agent": EXPECTED_MCP_USER_AGENT,}),},},@@ -1552,8 +1517,7 @@ describe("createAgUiStream", () => {});it("persists raw silent output for approved tools while resuming with redacted content", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = createToolApprovalResumeInput(true, { silent: true });adapterEvents.createScoreConfigExecute.mockResolvedValueOnce({type: "silent-mcp-output",@@ -1634,8 +1598,7 @@ describe("createAgUiStream", () => {});it("continues approved tools with a tool error result when execution fails", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = createToolApprovalResumeInput(true);const validationErrorMessage ="MCP error -32602: Validation failed: categories: Category must be an array of objects with label value pairs, where labels and values are unique.";@@ -1788,8 +1751,7 @@ describe("createAgUiStream", () => {});it("escapes screen context delimiters before compiling prompt instructions", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -1862,8 +1824,7 @@ describe("createAgUiStream", () => {});it("continues after rejected tools and asks the user how to proceed", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = createToolApprovalResumeInput(false);const rejectionError = JSON.stringify({code: IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE,@@ -2035,8 +1996,7 @@ describe("createAgUiStream", () => {});it("uses V4-compatible filters for traces redirect actions", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",@@ -2115,8 +2075,7 @@ describe("createAgUiStream", () => {});it("does not expose sandbox tools when sandboxing is disabled", async () => {- const { createAgUiStream } =- await import("@langfuse/shared/in-app-agent/server/agent");+ const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",runId: "run-1",diff --git a/packages/shared/src/in-app-agent/server/agent.ts b/worker/src/features/in-app-agent/runtime/agent.tssimilarity index 97%rename from packages/shared/src/in-app-agent/server/agent.tsrename to worker/src/features/in-app-agent/runtime/agent.tsindex 9227e499a7..deb8cd5c80 100644--- a/packages/shared/src/in-app-agent/server/agent.ts+++ b/worker/src/features/in-app-agent/runtime/agent.ts@@ -1,6 +1,6 @@import { EventType } from "@ag-ui/core";import { MastraAgent } from "@ag-ui/mastra";-import { IN_APP_AGENT_SYSTEM_PROMPT_TEMPLATE } from "./prompts/in-app-agent-system-prompt";+import { IN_APP_AGENT_SYSTEM_PROMPT_TEMPLATE } from "@langfuse/shared/in-app-agent/server/systemPrompt";import { createAmazonBedrock } from "ai-sdk-amazon-bedrock-v4";import { fromNodeProviderChain } from "@aws-sdk/credential-providers";import { Agent } from "@mastra/core/agent";@@ -9,14 +9,11 @@ import type { Langfuse } from "langfuse";import {type AgUiEvent,- type AgUiRunAgentInput,type InAppAgentToolApprovalRequest,- type ResumeForwardedProps,-} from "../schema";-import {- createInAppAgentMcpRunOverride,- createManualToolApprovalRunInput,-} from "./human-in-the-loop";+} from "@langfuse/shared/in-app-agent";+import { getToolFailureMessage } from "@langfuse/shared/in-app-agent/server/toolErrors";+import type { AgUiRunAgentInput, ResumeForwardedProps } from "./types";+import { createManualToolApprovalRunInput } from "./human-in-the-loop";import type {InAppAgentPromptMetadata,InAppAgentTracingConfig,@@ -26,7 +23,6 @@ import {parseMcpRateLimitError,withMcpRateLimitWait,} from "./mcpRateLimitWait";-import { getToolFailureMessage } from "./toolErrors";import {createSandboxTools,createRedirectActionTool,@@ -34,31 +30,33 @@ import {hasCallableExecute,withOptionalSilentMcpOutput,} from "./tools";-import type { CompletedInAppAgentMcpToolCall } from "./toolResults";import {+ toPublicInAppAgentEvent,+ type CompletedInAppAgentMcpToolCall,+} from "@langfuse/shared/in-app-agent/server/toolResults";+import {+ createInAppAgentMcpRunOverride,filterInAppAgentAvailableLangfuseMcpTools,getInAppAgentMcpAllowedToolNames,getInAppAgentRegistryToolName,type InAppAgentToolPolicy,withInAppAgentToolApproval,-} from "./mcpPolicy";-import { toPublicEvent } from "./watch";+} from "@langfuse/shared/in-app-agent/server/mcpPolicy";import { LANGFUSE_IN_APP_AGENT_SKILLS } from "./skills";import type { InAppAgentSandbox } from "./sandbox";-import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "../../features/filters/internalEnvironments";-import { env } from "../../env";-import { logger } from "../../server";+import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@langfuse/shared";+import { logger } from "@langfuse/shared/src/server";import {IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER,- IN_APP_AGENT_MCP_USER_AGENT,IN_APP_AGENT_REDIRECT_TOOL_NAME,-} from "../constants";+} from "@langfuse/shared/in-app-agent";const ASSISTANT_TITLE = "Langfuse Assistant";const IN_APP_AGENT_SYSTEM_PROMPT_NAME = "in-app-agent-system-prompt";const MAX_AGENT_STEPS = 20;const BEDROCK_CLAUDE_MODEL_ID_PART = "anthropic.claude";const LANGFUSE_DOCS_MCP_URL = "https://langfuse.com/api/mcp";+const IN_APP_AGENT_MCP_USER_AGENT = "langfuse-in-app-agent";// Screen context is included as data only. Tool execution safety is enforced by// deterministic in-app tool approval below, not by model instructions.@@ -214,7 +212,7 @@ export async function createAgUiStream(params: {options: CreateAgUiStreamOptions;}) {const encoder = new TextEncoder();- const awsProfile = env.AWS_PROFILE ?? params.options.awsBedrock.profile;+ const awsProfile = params.options.awsBedrock.profile;const langfuseMcpAuthHeader = `Basic ${Buffer.from(`${params.options.langfuseMcp.publicKey}:${params.options.langfuseMcp.secretKey}`,@@ -427,7 +425,7 @@ export async function createAgUiStream(params: {controller.enqueue(encoder.encode(- `data: ${JSON.stringify(toPublicEvent(agUiEvent))}\n\n`,+ `data: ${JSON.stringify(toPublicInAppAgentEvent(agUiEvent))}\n\n`,),);})diff --git a/packages/shared/src/in-app-agent/server/human-in-the-loop.ts b/worker/src/features/in-app-agent/runtime/human-in-the-loop.tssimilarity index 87%rename from packages/shared/src/in-app-agent/server/human-in-the-loop.tsrename to worker/src/features/in-app-agent/runtime/human-in-the-loop.tsindex 9825e84fcd..f332a88f2f 100644--- a/packages/shared/src/in-app-agent/server/human-in-the-loop.ts+++ b/worker/src/features/in-app-agent/runtime/human-in-the-loop.ts@@ -1,18 +1,11 @@import { EventType } from "@ag-ui/core";-import { z } from "zod";--import { IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE } from "../constants";-import {- IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES,- type InAppAgentLangfuseMcpToolName,-} from "./mcpPolicy";+import { IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE } from "@langfuse/shared/in-app-agent";import {type AgUiEvent,type AgUiMessage,- type AgUiRunAgentInput,type InAppAgentToolApprovalRequest,- type ResumeForwardedProps,-} from "../schema";+} from "@langfuse/shared/in-app-agent";+import type { AgUiRunAgentInput, ResumeForwardedProps } from "./types";const MANUAL_TOOL_APPROVAL_REJECTION_MESSAGE ="Tool call was not approved by the user.";@@ -23,37 +16,6 @@ const MANUAL_TOOL_APPROVAL_REJECTION_ERROR = JSON.stringify({type DeveloperGuidanceMessage = Extract<AgUiMessage, { role: "developer" }>;-const InAppAgentLangfuseMcpToolNameSchema =- z.custom<InAppAgentLangfuseMcpToolName>(- (value) =>- typeof value === "string" &&- IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES.has(- value as InAppAgentLangfuseMcpToolName,- ),- { message: "Invalid MCP tool name" },- );--/** Accept the legacy single-tool shape while older continuations may still be queued. */-export const InAppAgentMcpRunOverrideSchema = z- .union([- z.object({ toolNames: z.array(InAppAgentLangfuseMcpToolNameSchema) }),- z.object({ toolName: InAppAgentLangfuseMcpToolNameSchema }),- ])- .transform((override) => ({- toolNames:- "toolNames" in override ? override.toolNames : [override.toolName],- }));--export async function createInAppAgentMcpRunOverride(params: {- toolNames: InAppAgentLangfuseMcpToolName[];-}) {- return JSON.stringify({- // Older web pods read the singular field during rolling deploys.- toolName: params.toolNames[0],- toolNames: params.toolNames,- });-}-export type ManualToolApprovalRunInput = {input: AgUiRunAgentInput;syntheticEvents: AgUiEvent[];diff --git a/web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.ts b/worker/src/features/in-app-agent/runtime/instrumentation.test.tssimilarity index 99%rename from web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.tsrename to worker/src/features/in-app-agent/runtime/instrumentation.test.tsindex 3774dd33ca..35c902e029 100644--- a/web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.ts+++ b/worker/src/features/in-app-agent/runtime/instrumentation.test.ts@@ -1,12 +1,13 @@import { EventType } from "@ag-ui/core";+import { beforeEach, describe, expect, it, vi } from "vitest";import {getInAppAgentInstrumentationObservationId,getInAppAgentInstrumentationTraceId,getInAppAgentLlmCallObservationId,} from "@langfuse/shared/in-app-agent";-import type { AgUiRunAgentInput } from "@langfuse/shared/in-app-agent";-import { InAppAgentInstrumentation } from "@langfuse/shared/in-app-agent/server/instrumentation";+import type { AgUiRunAgentInput } from "./types";+import { InAppAgentInstrumentation } from "./instrumentation";const runId = "run-1";const traceId = getInAppAgentInstrumentationTraceId(runId);diff --git a/packages/shared/src/in-app-agent/server/instrumentation.ts b/worker/src/features/in-app-agent/runtime/instrumentation.tssimilarity index 98%rename from packages/shared/src/in-app-agent/server/instrumentation.tsrename to worker/src/features/in-app-agent/runtime/instrumentation.tsindex b3914a9d01..114373d8e0 100644--- a/packages/shared/src/in-app-agent/server/instrumentation.ts+++ b/worker/src/features/in-app-agent/runtime/instrumentation.ts@@ -1,27 +1,23 @@import { EventType } from "@ag-ui/core";import { Buffer } from "node:buffer";-import { getInternalTracingHandler, logger } from "../../server";+import { getInternalTracingHandler, logger } from "@langfuse/shared/src/server";import {getInAppAgentInstrumentationObservationId,getInAppAgentInstrumentationTraceId,getInAppAgentLlmCallObservationId,-} from "../constants";-import {- ResumeForwardedPropsSchema,- type AgUiEvent,- type AgUiMessage,- type AgUiRunAgentInput,-} from "../schema";-import { compactTextMessageChunks } from "./eventCompaction";+} from "@langfuse/shared/in-app-agent";+import type { AgUiEvent, AgUiMessage } from "@langfuse/shared/in-app-agent";import {getToolFailureMessage,isRecord,normalizeToolOutput,parseJsonOrString,-} from "./toolErrors";-import type { InAppAgentUserAccess } from "./mcpPolicy";-import { assertUnreachable } from "../../utils/typeChecks";+} from "@langfuse/shared/in-app-agent/server/toolErrors";+import { ResumeForwardedPropsSchema, type AgUiRunAgentInput } from "./types";+import { compactTextMessageChunks } from "@langfuse/shared/in-app-agent/server/eventCompaction";+import type { InAppAgentUserAccess } from "@langfuse/shared/in-app-agent/server/mcpPolicy";+import { assertUnreachable } from "@langfuse/shared";export type InAppAgentTracingConfig = {environment: string;diff --git a/packages/shared/src/in-app-agent/server/mcpRateLimitWait.test.ts b/worker/src/features/in-app-agent/runtime/mcpRateLimitWait.test.tssimilarity index 100%rename from packages/shared/src/in-app-agent/server/mcpRateLimitWait.test.tsrename to worker/src/features/in-app-agent/runtime/mcpRateLimitWait.test.tsdiff --git a/packages/shared/src/in-app-agent/server/mcpRateLimitWait.ts b/worker/src/features/in-app-agent/runtime/mcpRateLimitWait.tssimilarity index 69%rename from packages/shared/src/in-app-agent/server/mcpRateLimitWait.tsrename to worker/src/features/in-app-agent/runtime/mcpRateLimitWait.tsindex 76fa78a2ff..ed7943968d 100644--- a/packages/shared/src/in-app-agent/server/mcpRateLimitWait.ts+++ b/worker/src/features/in-app-agent/runtime/mcpRateLimitWait.ts@@ -1,22 +1,13 @@-import { logger } from "../../server";-import { InAppAgentRateLimitErrorResponseSchema } from "../schema";--/**- * Total time a single MCP operation may spend waiting out `rate_limited`- * responses. Sized so a full Hobby `public-api` window (`retryAfterSeconds: 60`)- * can still be waited out within one operation.- */+import { InAppAgentRateLimitErrorResponseSchema } from "@langfuse/shared/in-app-agent";+import { logger } from "@langfuse/shared/src/server";++/** Total time a single MCP operation may spend waiting out rate limits. */export const IN_APP_AGENT_MCP_RATE_LIMIT_WAIT_BUDGET_MS = 60_000;type McpRateLimitError = {retryAfterSeconds: number;};-/**- * Recognizes the public API `rate_limited` payload wherever the MCP transport- * surfaces it: as a structured value, as a thrown `Error`, or embedded as JSON- * in an error string (`Failed to initialize Langfuse MCP: ...`).- */export function parseMcpRateLimitError(error: unknown,): McpRateLimitError | null {@@ -47,12 +38,10 @@ function parseEmbeddedRateLimitError(message: string) {);if (parsed.success) {- return {- retryAfterSeconds: parsed.data.details.retryAfterSeconds,- };+ return { retryAfterSeconds: parsed.data.details.retryAfterSeconds };}} catch {- // The transport prefixes JSON with error context, so try the next object.+ // The transport prefixes JSON with error context.}startIndex = message.indexOf("{", startIndex + 1);@@ -61,13 +50,6 @@ function parseEmbeddedRateLimitError(message: string) {return null;}-/**- * Retries a single MCP operation while the public API answers `rate_limited`,- * sleeping exactly as long as the response asks for. The server escalates- * `retryAfterSeconds` as its window empties, so there is no local backoff- * ladder. A wait longer than the remaining budget fails immediately instead of- * sleeping and hoping.- */export async function withMcpRateLimitWait<T>(params: {fn: () => Promise<T>;signal?: AbortSignal;diff --git a/packages/shared/src/in-app-agent/server/promptClient.ts b/worker/src/features/in-app-agent/runtime/promptClient.tssimilarity index 86%rename from packages/shared/src/in-app-agent/server/promptClient.tsrename to worker/src/features/in-app-agent/runtime/promptClient.tsindex b8b9a00aac..86f465a1ac 100644--- a/packages/shared/src/in-app-agent/server/promptClient.ts+++ b/worker/src/features/in-app-agent/runtime/promptClient.ts@@ -1,7 +1,7 @@import { Langfuse } from "langfuse";-import { env } from "../../env";-import { getProductBaseUrl } from "../../server/utils/baseUrl";+import { env } from "@langfuse/shared/src/env";+import { getProductBaseUrl } from "@langfuse/shared/src/server";let client: Langfuse | null = null;diff --git a/web/src/__tests__/server/unit/in-app-agent-reasoning.servertest.ts b/worker/src/features/in-app-agent/runtime/reasoning.test.tssimilarity index 91%rename from web/src/__tests__/server/unit/in-app-agent-reasoning.servertest.tsrename to worker/src/features/in-app-agent/runtime/reasoning.test.tsindex 1a20753db8..0983c4fb4d 100644--- a/web/src/__tests__/server/unit/in-app-agent-reasoning.servertest.ts+++ b/worker/src/features/in-app-agent/runtime/reasoning.test.ts@@ -1,4 +1,5 @@-import { getBedrockReasoningProviderOptions } from "@langfuse/shared/in-app-agent/server/agent";+import { getBedrockReasoningProviderOptions } from "./agent";+import { describe, expect, it } from "vitest";describe("getBedrockReasoningProviderOptions", () => {it("sends adaptive thinking with summarized display to Claude models by default", () => {diff --git a/packages/shared/src/in-app-agent/server/sandbox/config.ts b/worker/src/features/in-app-agent/runtime/sandbox/config.tssimilarity index 92%rename from packages/shared/src/in-app-agent/server/sandbox/config.tsrename to worker/src/features/in-app-agent/runtime/sandbox/config.tsindex bfc7eba47d..b777ec5ed9 100644--- a/packages/shared/src/in-app-agent/server/sandbox/config.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/config.ts@@ -1,8 +1,9 @@import { createLambdaMicrovmSandboxProvider } from "./providers/lambdaMicrovm";import type { InAppAgentSandboxProviderType, SandboxProvider } from "./types";-import { env } from "../../../env";-import { IN_APP_AGENT_LOCAL_SANDBOX_IMAGE } from "../../constants";-import { assertUnreachable } from "../../../utils/typeChecks";+import { env } from "../../../../env";+import { assertUnreachable } from "@langfuse/shared";++const IN_APP_AGENT_LOCAL_SANDBOX_IMAGE = "langfuse-in-app-agent-sandbox:latest";export function getDefaultInAppAgentSandboxProviderType(): InAppAgentSandboxProviderType | null {const providerType = env.LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER ?? null;diff --git a/packages/shared/src/in-app-agent/server/sandbox/index.ts b/worker/src/features/in-app-agent/runtime/sandbox/index.tssimilarity index 100%rename from packages/shared/src/in-app-agent/server/sandbox/index.tsrename to worker/src/features/in-app-agent/runtime/sandbox/index.tsdiff --git a/web/src/__tests__/server/unit/in-app-agent-docker-provider.servertest.ts b/worker/src/features/in-app-agent/runtime/sandbox/providers/docker.test.tssimilarity index 97%rename from web/src/__tests__/server/unit/in-app-agent-docker-provider.servertest.tsrename to worker/src/features/in-app-agent/runtime/sandbox/providers/docker.test.tsindex 114befcc9b..b74157ff39 100644--- a/web/src/__tests__/server/unit/in-app-agent-docker-provider.servertest.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/providers/docker.test.ts@@ -166,8 +166,7 @@ describe("in-app agent docker sandbox provider", () => {});it("recreates the named container when it was manually removed", async () => {- const { createDockerSandboxProvider } =- await import("@langfuse/shared/in-app-agent/server/sandbox/providers/docker");+ const { createDockerSandboxProvider } = await import("./docker");const provider = await createDockerSandboxProvider({image: "langfuse-in-app-agent-sandbox:latest",});diff --git a/packages/shared/src/in-app-agent/server/sandbox/providers/docker.ts b/worker/src/features/in-app-agent/runtime/sandbox/providers/docker.tssimilarity index 99%rename from packages/shared/src/in-app-agent/server/sandbox/providers/docker.tsrename to worker/src/features/in-app-agent/runtime/sandbox/providers/docker.tsindex 57709134df..0d7b6c0232 100644--- a/packages/shared/src/in-app-agent/server/sandbox/providers/docker.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/providers/docker.ts@@ -1,7 +1,7 @@import { PassThrough } from "node:stream";import type Docker from "dockerode";-import { logger } from "../../../../server";+import { logger } from "@langfuse/shared/src/server";import type { SandboxFile, SandboxProvider, SandboxSession } from "../types";diff --git a/web/src/__tests__/server/unit/in-app-agent-lambda-microvm-provider.servertest.ts b/worker/src/features/in-app-agent/runtime/sandbox/providers/lambdaMicrovm.test.tssimilarity index 96%rename from web/src/__tests__/server/unit/in-app-agent-lambda-microvm-provider.servertest.tsrename to worker/src/features/in-app-agent/runtime/sandbox/providers/lambdaMicrovm.test.tsindex 87f6d4a4c7..f018cf801b 100644--- a/web/src/__tests__/server/unit/in-app-agent-lambda-microvm-provider.servertest.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/providers/lambdaMicrovm.test.ts@@ -51,7 +51,7 @@ describe("in-app agent lambda microvm sandbox provider", () => {it("uses suspend for suspendSession and terminate for terminateSession", async () => {const { createLambdaMicrovmSandboxProvider } =- await import("@langfuse/shared/in-app-agent/server/sandbox/providers/lambdaMicrovm");+ await import("./lambdaMicrovm");const provider = createLambdaMicrovmSandboxProvider({imageIdentifier: "image-1",@@ -111,7 +111,7 @@ describe("in-app agent lambda microvm sandbox provider", () => {});const { createLambdaMicrovmSandboxProvider } =- await import("@langfuse/shared/in-app-agent/server/sandbox/providers/lambdaMicrovm");+ await import("./lambdaMicrovm");const provider = createLambdaMicrovmSandboxProvider({imageIdentifier: "image-1",executionRoleArn: "arn:aws:iam::123456789012:role/sandbox",@@ -170,7 +170,7 @@ describe("in-app agent lambda microvm sandbox provider", () => {});const { createLambdaMicrovmSandboxProvider } =- await import("@langfuse/shared/in-app-agent/server/sandbox/providers/lambdaMicrovm");+ await import("./lambdaMicrovm");const provider = createLambdaMicrovmSandboxProvider({imageIdentifier: "image-1",executionRoleArn: "arn:aws:iam::123456789012:role/sandbox",@@ -264,7 +264,7 @@ describe("in-app agent lambda microvm sandbox provider", () => {});const { createLambdaMicrovmSandboxProvider } =- await import("@langfuse/shared/in-app-agent/server/sandbox/providers/lambdaMicrovm");+ await import("./lambdaMicrovm");const provider = createLambdaMicrovmSandboxProvider({imageIdentifier: "image-1",executionRoleArn: "arn:aws:iam::123456789012:role/sandbox",diff --git a/packages/shared/src/in-app-agent/server/sandbox/providers/lambdaMicrovm.ts b/worker/src/features/in-app-agent/runtime/sandbox/providers/lambdaMicrovm.tssimilarity index 99%rename from packages/shared/src/in-app-agent/server/sandbox/providers/lambdaMicrovm.tsrename to worker/src/features/in-app-agent/runtime/sandbox/providers/lambdaMicrovm.tsindex 236f2d3cab..d9ae83505d 100644--- a/packages/shared/src/in-app-agent/server/sandbox/providers/lambdaMicrovm.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/providers/lambdaMicrovm.ts@@ -10,7 +10,7 @@ import {TerminateMicrovmCommand,type RunMicrovmCommandInput,} from "@aws-sdk/client-lambda-microvms";-import { logger } from "../../../../server";+import { logger } from "@langfuse/shared/src/server";import { z } from "zod";import type {diff --git a/web/src/__tests__/server/unit/in-app-agent-sandbox.servertest.ts b/worker/src/features/in-app-agent/runtime/sandbox/sandbox.test.tssimilarity index 96%rename from web/src/__tests__/server/unit/in-app-agent-sandbox.servertest.tsrename to worker/src/features/in-app-agent/runtime/sandbox/sandbox.test.tsindex c3dc967add..4304b56d23 100644--- a/web/src/__tests__/server/unit/in-app-agent-sandbox.servertest.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/sandbox.test.ts@@ -1,13 +1,15 @@import { EventType } from "@ag-ui/core";-import { standardSchemaToJSONSchema } from "@mastra/core/schema";+import {+ standardSchemaToJSONSchema,+ toStandardSchema,+} from "@mastra/core/schema";import { Tool } from "@mastra/core/tools";import { describe, expect, it } from "vitest";import { z } from "zod";import { createSandboxToolCallFileAccumulator } from "@langfuse/shared/in-app-agent/server/persistence";-import { createInAppAgentSandbox } from "@langfuse/shared/in-app-agent/server/sandbox";-import { withOptionalSilentMcpOutput } from "@langfuse/shared/in-app-agent/server/tools";-import { listObservationsTool } from "@/src/features/mcp/features/observations/tools/listObservations";+import { createInAppAgentSandbox } from ".";+import { withOptionalSilentMcpOutput } from "../tools";// Only presence matters for the tests below: it is what makes// withOptionalSilentMcpOutput advertise the `silent` parameter.@@ -191,8 +193,12 @@ describe("in-app agent sandbox", () => {listObservations: {...new Tool({id: "listObservations",- description: listObservationsTool.description,- inputSchema: listObservationsTool.inputSchema,+ description: "List observations",+ inputSchema: toStandardSchema({+ type: "object",+ additionalProperties: false,+ properties: { limit: { type: "number" } },+ }),execute: async (input) => {receivedInput = input;return { data: [] };diff --git a/packages/shared/src/in-app-agent/server/sandbox/service.ts b/worker/src/features/in-app-agent/runtime/sandbox/service.tssimilarity index 97%rename from packages/shared/src/in-app-agent/server/sandbox/service.tsrename to worker/src/features/in-app-agent/runtime/sandbox/service.tsindex 6c3e3f47ac..f0e4d4b87a 100644--- a/packages/shared/src/in-app-agent/server/sandbox/service.ts+++ b/worker/src/features/in-app-agent/runtime/sandbox/service.ts@@ -4,7 +4,7 @@ import type {SandboxFile,SandboxProvider,} from "./types";-import { logger, recordIncrement } from "../../../server";+import { logger, recordIncrement } from "@langfuse/shared/src/server";export async function createInAppAgentSandbox(params: {conversationId: string;diff --git a/packages/shared/src/in-app-agent/server/sandbox/types.ts b/worker/src/features/in-app-agent/runtime/sandbox/types.tssimilarity index 100%rename from packages/shared/src/in-app-agent/server/sandbox/types.tsrename to worker/src/features/in-app-agent/runtime/sandbox/types.tsdiff --git a/packages/shared/src/in-app-agent/server/skills.ts b/worker/src/features/in-app-agent/runtime/skills.tssimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills.tsrename to worker/src/features/in-app-agent/runtime/skills.tsdiff --git a/packages/shared/src/in-app-agent/server/skills/generated/raw/README.md b/worker/src/features/in-app-agent/runtime/skills/generated/raw/README.mdsimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills/generated/raw/README.mdrename to worker/src/features/in-app-agent/runtime/skills/generated/raw/README.mddiff --git a/packages/shared/src/in-app-agent/server/skills/generated/raw/cli.md b/worker/src/features/in-app-agent/runtime/skills/generated/raw/cli.mdsimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills/generated/raw/cli.mdrename to worker/src/features/in-app-agent/runtime/skills/generated/raw/cli.mddiff --git a/packages/shared/src/in-app-agent/server/skills/generated/raw/error-analysis.md b/worker/src/features/in-app-agent/runtime/skills/generated/raw/error-analysis.mdsimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills/generated/raw/error-analysis.mdrename to worker/src/features/in-app-agent/runtime/skills/generated/raw/error-analysis.mddiff --git a/packages/shared/src/in-app-agent/server/skills/generated/raw/prompt-engineering.md b/worker/src/features/in-app-agent/runtime/skills/generated/raw/prompt-engineering.mdsimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills/generated/raw/prompt-engineering.mdrename to worker/src/features/in-app-agent/runtime/skills/generated/raw/prompt-engineering.mddiff --git a/packages/shared/src/in-app-agent/server/skills/generated/raw/v4-project-migration.md b/worker/src/features/in-app-agent/runtime/skills/generated/raw/v4-project-migration.mdsimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills/generated/raw/v4-project-migration.mdrename to worker/src/features/in-app-agent/runtime/skills/generated/raw/v4-project-migration.mddiff --git a/packages/shared/src/in-app-agent/server/skills/generated/skill-markdown.ts b/worker/src/features/in-app-agent/runtime/skills/generated/skill-markdown.tssimilarity index 100%rename from packages/shared/src/in-app-agent/server/skills/generated/skill-markdown.tsrename to worker/src/features/in-app-agent/runtime/skills/generated/skill-markdown.tsdiff --git a/packages/shared/src/in-app-agent/server/tools.ts b/worker/src/features/in-app-agent/runtime/tools.tssimilarity index 97%rename from packages/shared/src/in-app-agent/server/tools.tsrename to worker/src/features/in-app-agent/runtime/tools.tsindex 70e02a24dd..f3be52efda 100644--- a/packages/shared/src/in-app-agent/server/tools.ts+++ b/worker/src/features/in-app-agent/runtime/tools.ts@@ -4,7 +4,8 @@ import {} from "@mastra/core/schema";import { createTool, Tool } from "@mastra/core/tools";import type { InAppAgentSandbox } from "./sandbox";-import { assertUnreachable } from "../../utils/typeChecks";+import { assertUnreachable } from "@langfuse/shared";+import { getToolFailureMessage } from "@langfuse/shared/in-app-agent/server/toolErrors";import {buildDashboardsPath,buildDashboardWidgetPath,@@ -22,21 +23,23 @@ import {buildSessionsPath,buildTracePath,buildTracesPath,-} from "../../server/utils/productUrl";+} from "@langfuse/shared/src/server";import z from "zod";-import { TABLE_AGGREGATION_OPTIONS } from "../../utils/dateRanges";-import { ObservationLevelDomain, TracingSearchType } from "../../index";+import {+ ObservationLevelDomain,+ TABLE_AGGREGATION_OPTIONS,+ TracingSearchType,+} from "@langfuse/shared";import {IN_APP_AGENT_REDIRECT_TOOL_NAME,IN_APP_AGENT_SILENT_MCP_OUTPUT_MESSAGE,IN_APP_AGENT_SILENT_MCP_OUTPUT_TYPE,-} from "../constants";-import { getToolFailureMessage } from "./toolErrors";+} from "@langfuse/shared/in-app-agent";import {isSilentInAppAgentMcpToolOutput,type CompletedInAppAgentMcpToolCall,type SilentInAppAgentMcpToolOutput,-} from "./toolResults";+} from "@langfuse/shared/in-app-agent/server/toolResults";export function createSandboxTools(sandbox: InAppAgentSandbox) {return {read: createTool({diff --git a/worker/src/features/in-app-agent/runtime/types.ts b/worker/src/features/in-app-agent/runtime/types.tsnew file mode 100644index 0000000000..a135a2d8c8--- /dev/null+++ b/worker/src/features/in-app-agent/runtime/types.ts@@ -0,0 +1,37 @@+import { z } from "zod";+import type { AgUiContext, AgUiMessage } from "@langfuse/shared/in-app-agent";+import { InAppAgentToolApprovalRequestSchema } from "@langfuse/shared/in-app-agent";++type AgUiTool = {+ name: string;+ description: string;+ parameters?: unknown;+ metadata?: Record<string, unknown>;+};++export const ResumeForwardedPropsSchema = z.object({+ command: z.object({+ resume: z.object({+ approved: z.boolean(),+ continuationNumber: z.number().int().positive().optional(),+ rootRunId: z.string().min(1).optional(),+ traceStartedAt: z.iso.datetime({ offset: true }).optional(),+ approvalRequestedAt: z.iso.datetime({ offset: true }).optional(),+ approvalDecidedAt: z.iso.datetime({ offset: true }).optional(),+ approvalRequest: InAppAgentToolApprovalRequestSchema,+ }),+ }),+});++export type ResumeForwardedProps = z.infer<typeof ResumeForwardedPropsSchema>;++export type AgUiRunAgentInput = {+ threadId: string;+ runId: string;+ parentRunId?: string;+ state?: unknown;+ messages: AgUiMessage[];+ tools: AgUiTool[];+ context: AgUiContext;+ forwardedProps?: unknown;+};