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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions bun.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"private": true,
"dependencies": {
"@activepieces/import-fresh-webpack": "3.3.0",
"@ai-sdk/anthropic": "2.0.3",
"@ai-sdk/azure": "2.0.12",
"@ai-sdk/google": "2.0.6",
"@ai-sdk/mcp": "1.0.1 ",
"@ai-sdk/openai": "2.0.12",
"@ai-sdk/openai-compatible": "1.0.29",
"@ai-sdk/provider": "2.0.0",
"@ai-sdk/replicate": "1.0.3",
"@ai-sdk/anthropic": "^3.0.0",
"@ai-sdk/azure": "^3.0.0",
"@ai-sdk/google": "^3.0.0",
"@ai-sdk/mcp": "1.0.11",
"@ai-sdk/openai": "^3.0.0",
"@ai-sdk/openai-compatible": "2.0.16",
"@ai-sdk/provider": "^3.0.0",
"@ai-sdk/replicate": "2.0.8 ",
"@authenio/samlify-node-xmllint": "2.0.0",
"@aws-sdk/client-s3": "3.637.0",
"@aws-sdk/s3-request-presigner": "3.658.1",
Expand Down Expand Up @@ -142,7 +142,7 @@
"@uiw/codemirror-theme-github": "4.23.0",
"@uiw/react-codemirror": "4.23.0",
"@xyflow/react": "12.3.5",
"ai": "5.0.104",
"ai": "^6.0.0",
"async-mutex": "0.4.0",
"axios": "1.13.1",
"axios-retry": "4.4.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/engine/src/lib/handler/piece-executor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { URL } from 'url'
import { ActionContext, backwardCompatabilityContextUtils, ConstructToolParams, InputPropertyMap, PauseHook, PauseHookParams, PieceAuthProperty, PiecePropertyMap, RespondHook, RespondHookParams, StaticPropsValue, StopHook, StopHookParams, TagsManager } from '@activepieces/pieces-framework'
import { AUTHENTICATION_PROPERTY_NAME, EngineGenericError, EngineSocketEvent, ExecutionType, FlowActionType, FlowRunStatus, GenericStepOutput, isNil, PausedFlowTimeoutError, PauseType, PieceAction, RespondResponse, StepOutputStatus } from '@activepieces/shared'
import { LanguageModelV2 } from '@ai-sdk/provider'
import { ToolSet } from 'ai'
import dayjs from 'dayjs'
import { continueIfFailureHandler, runWithExponentialBackoff } from '../helper/error-handling'
Expand Down Expand Up @@ -122,7 +121,7 @@ const executeAction: ActionHandler<PieceAction> = async ({ action, executionStat
tools: async (params: ConstructToolParams): Promise<ToolSet> => agentTools.tools({
engineConstants: constants,
tools: params.tools,
model: params.model as LanguageModelV2,
model: params.model,
}),
},
propsValue: processedInput,
Expand Down
25 changes: 13 additions & 12 deletions packages/engine/src/lib/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Action, DropdownOption, ExecutePropsResult, PieceProperty, PropertyType } from '@activepieces/pieces-framework'
import { AgentPieceTool, ExecuteToolOperation, ExecuteToolResponse, ExecutionToolStatus, FieldControlMode, FlowActionType, isNil, PieceAction, PropertyExecutionType, StepOutputStatus } from '@activepieces/shared'
import { generateObject, LanguageModel, Tool } from 'ai'
import { z } from 'zod/v4'
import { generateText, LanguageModel, Output, Tool } from 'ai'
import { z } from 'zod/v3'
import { EngineConstants } from '../handler/context/engine-constants'
import { FlowExecutorContext } from '../handler/context/flow-execution-context'
import { flowExecutor } from '../handler/flow-executor'
Expand Down Expand Up @@ -92,9 +92,7 @@ async function resolveProperties(
operation,
result,
)
propertyToFill[property] = propertyFromAction.required
? propertySchema
: propertySchema.nullish()
propertyToFill[property] = propertySchema

const propertyDetail = await buildPropertyDetail(
property,
Expand All @@ -117,17 +115,19 @@ async function resolveProperties(
result,
)

const { object } = await generateObject({
const { output } = await generateText({
model,
schema: schemaObject,
prompt: extractionPrompt,
mode: 'json',
output: 'object',
output: Output.object({
schema: schemaObject,
}),
})

result = {
...result,
...(object as Record<string, unknown>),
...(output as Record<string, unknown>),
}

}
return result
}
Expand Down Expand Up @@ -226,6 +226,7 @@ type ExecuteToolOperationWithModel = ExecuteToolOperation & {

async function propertyToSchema(propertyName: string, property: PieceProperty, operation: ExecuteToolOperation, resolvedInput: Record<string, unknown>): Promise<z.ZodTypeAny> {
let schema: z.ZodTypeAny

switch (property.type) {
case PropertyType.SHORT_TEXT:
case PropertyType.LONG_TEXT:
Expand All @@ -249,7 +250,7 @@ async function propertyToSchema(propertyName: string, property: PieceProperty, o
schema = z.number()
break
case PropertyType.ARRAY:
return z.array(z.unknown())
return z.array(z.string())
case PropertyType.OBJECT:
schema = z.record(z.string(), z.unknown())
break
Expand Down Expand Up @@ -278,7 +279,7 @@ async function propertyToSchema(propertyName: string, property: PieceProperty, o
if (property.description) {
schema = schema.describe(property.description)
}
return property.required ? schema : schema.nullish()
return property.required ? schema : schema.nullable()
}

async function buildDynamicSchema(propertyName: string, operation: ExecuteToolOperation, resolvedInput: Record<string, unknown>): Promise<z.ZodTypeAny> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
generateText,
GenerateTextResult,
ImagePart,
LanguageModel,
ToolSet,
} from 'ai';
import { experimental_generateImage as generateImage } from 'ai';
import { LanguageModelV2 } from '@ai-sdk/provider';
import mime from 'mime-types';
import { isNil } from '@activepieces/shared';
import { createAIModel } from '../../common/ai-sdk';
Expand Down Expand Up @@ -203,7 +203,7 @@ const getGeneratedImage = async ({
case AIProviderName.OPENROUTER:
case AIProviderName.CLOUDFLARE_GATEWAY:
return generateImageUsingGenerateText({
model: model as unknown as LanguageModelV2,
model: model as unknown as LanguageModel,
prompt,
advancedOptions,
});
Expand All @@ -225,7 +225,7 @@ const generateImageUsingGenerateText = async ({
prompt,
advancedOptions,
}: {
model: LanguageModelV2;
model: LanguageModel;
prompt: string;
advancedOptions?: DynamicPropsValue;
}): Promise<GeneratedFile> => {
Expand Down
9 changes: 4 additions & 5 deletions packages/pieces/community/ai/src/lib/common/ai-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { anthropic, createAnthropic } from '@ai-sdk/anthropic'
import { createGoogleGenerativeAI, google } from '@ai-sdk/google'
import { createOpenAI, openai } from '@ai-sdk/openai'
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { LanguageModelV2 } from '@ai-sdk/provider'
import { createAzure } from '@ai-sdk/azure'
import { createOpenRouter } from '@openrouter/ai-sdk-provider'
import { ImageModel } from 'ai'
import { ImageModel, LanguageModel } from 'ai'
import { httpClient, HttpMethod } from '@activepieces/pieces-common'
import { AIProviderName, AzureProviderConfig, CloudflareGatewayProviderConfig, GetProviderConfigResponse, OpenAICompatibleProviderConfig } from '@activepieces/shared'

Expand All @@ -21,7 +20,7 @@ type CreateAIModelParams<IsImage extends boolean = false> = {
isImage?: IsImage;
}

export function createAIModel(params: CreateAIModelParams<false>): Promise<LanguageModelV2>;
export function createAIModel(params: CreateAIModelParams<false>): Promise<LanguageModel>;
export function createAIModel(params: CreateAIModelParams<true>): Promise<ImageModel>;
export async function createAIModel({
provider,
Expand All @@ -33,7 +32,7 @@ export async function createAIModel({
apiUrl,
openaiResponsesModel = false,
isImage,
}: CreateAIModelParams<boolean>): Promise<ImageModel | LanguageModelV2> {
}: CreateAIModelParams<boolean>): Promise<ImageModel | LanguageModel> {
const { body: {
config,
auth,
Expand Down Expand Up @@ -108,7 +107,7 @@ export async function createAIModel({
case AIProviderName.ACTIVEPIECES:
case AIProviderName.OPENROUTER: {
const provider = createOpenRouter({ apiKey: auth.apiKey })
return provider.chat(modelId)
return provider.chat(modelId) as LanguageModel
}
default:
throw new Error(`Provider ${provider} is not supported`)
Expand Down
4 changes: 2 additions & 2 deletions packages/pieces/community/framework/src/lib/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TriggerPayload,
TriggerStrategy,
} from '@activepieces/shared';
import { Tool } from 'ai'
import { LanguageModel, Tool } from 'ai'

import {
BasicAuthProperty,
Expand Down Expand Up @@ -234,7 +234,7 @@ export type ActionContext<

export type ConstructToolParams = {
tools: AgentPieceTool[]
model: unknown,
model: LanguageModel,
}

export interface AgentContext {
Expand Down
Loading