@webiny/api-core 6.2.0-beta.0 → 6.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ApiCoreFeature.d.ts +5 -1
- package/ApiCoreFeature.js +4 -0
- package/ApiCoreFeature.js.map +1 -1
- package/createApiCore.d.ts +1 -1
- package/exports/api.d.ts +3 -0
- package/exports/api.js +2 -0
- package/exports/api.js.map +1 -1
- package/features/ai/Ai.d.ts +26 -0
- package/features/ai/Ai.js +133 -0
- package/features/ai/Ai.js.map +1 -0
- package/features/ai/AiSdkTools.d.ts +11 -0
- package/features/ai/AiSdkTools.js +25 -0
- package/features/ai/AiSdkTools.js.map +1 -0
- package/features/ai/AnthropicSdkFactory.d.ts +10 -0
- package/features/ai/AnthropicSdkFactory.js +71 -0
- package/features/ai/AnthropicSdkFactory.js.map +1 -0
- package/features/ai/OpenAiSdkFactory.d.ts +10 -0
- package/features/ai/OpenAiSdkFactory.js +187 -0
- package/features/ai/OpenAiSdkFactory.js.map +1 -0
- package/features/ai/abstractions.d.ts +92 -0
- package/features/ai/abstractions.js +35 -0
- package/features/ai/abstractions.js.map +1 -0
- package/features/ai/feature.d.ts +4 -0
- package/features/ai/feature.js +16 -0
- package/features/ai/feature.js.map +1 -0
- package/features/ai/index.d.ts +3 -0
- package/features/ai/index.js +4 -0
- package/features/ai/index.js.map +1 -0
- package/features/buildParams/feature.d.ts +5 -1
- package/features/encryption/EncryptionService.d.ts +10 -0
- package/features/encryption/EncryptionService.js +58 -0
- package/features/encryption/EncryptionService.js.map +1 -0
- package/features/encryption/abstractions.d.ts +9 -0
- package/features/encryption/abstractions.js +5 -0
- package/features/encryption/abstractions.js.map +1 -0
- package/features/encryption/feature.d.ts +4 -0
- package/features/encryption/feature.js +10 -0
- package/features/encryption/feature.js.map +1 -0
- package/features/encryption/index.d.ts +1 -0
- package/features/encryption/index.js +3 -0
- package/features/encryption/index.js.map +1 -0
- package/features/eventPublisher/feature.d.ts +5 -1
- package/features/featureFlags/feature.d.ts +5 -1
- package/features/keyValueStore/feature.d.ts +4 -1
- package/features/keyValueStore/feature.js.map +1 -1
- package/features/logger/feature.d.ts +4 -1
- package/features/security/IdentityContext/feature.d.ts +4 -1
- package/features/security/SecurityFeature.d.ts +5 -1
- package/features/security/apiKeys/CreateApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/DeleteApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/GetApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/GetApiKeyBySlug/feature.d.ts +4 -1
- package/features/security/apiKeys/GetApiKeyByToken/feature.d.ts +4 -1
- package/features/security/apiKeys/ListApiKeys/feature.d.ts +4 -1
- package/features/security/apiKeys/UpdateApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/feature.d.ts +4 -1
- package/features/security/authentication/AuthenticationContext/feature.d.ts +4 -1
- package/features/security/authorization/AuthorizationContext/feature.d.ts +4 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.d.ts +4 -1
- package/features/security/permissions/createPermissions.d.ts +4 -1
- package/features/security/roles/CreateRole/feature.d.ts +4 -1
- package/features/security/roles/DeleteRole/feature.d.ts +4 -1
- package/features/security/roles/GetRole/feature.d.ts +4 -1
- package/features/security/roles/ListRoles/feature.d.ts +4 -1
- package/features/security/roles/UpdateRole/feature.d.ts +4 -1
- package/features/security/roles/feature.d.ts +4 -1
- package/features/security/teams/CreateTeam/feature.d.ts +4 -1
- package/features/security/teams/DeleteTeam/feature.d.ts +4 -1
- package/features/security/teams/GetTeam/feature.d.ts +4 -1
- package/features/security/teams/ListTeams/feature.d.ts +4 -1
- package/features/security/teams/UpdateTeam/feature.d.ts +4 -1
- package/features/security/teams/feature.d.ts +4 -1
- package/features/system/InstallSystem/feature.d.ts +5 -1
- package/features/system/SystemFeature.d.ts +4 -1
- package/features/task/TaskService/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/feature.d.ts +5 -1
- package/features/tenancy/DeleteTenant/feature.d.ts +5 -1
- package/features/tenancy/GetRootTenant/feature.d.ts +5 -1
- package/features/tenancy/GetTenantById/feature.d.ts +5 -1
- package/features/tenancy/InstallTenant/feature.d.ts +5 -1
- package/features/tenancy/ListTenants/feature.d.ts +5 -1
- package/features/tenancy/TenancyFeature.d.ts +4 -1
- package/features/tenancy/TenancyFeature.js.map +1 -1
- package/features/tenancy/TenantContext/feature.d.ts +4 -1
- package/features/tenancy/UpdateTenant/feature.d.ts +5 -1
- package/features/users/AdminUsersFeature.d.ts +4 -1
- package/features/users/AdminUsersFeature.js.map +1 -1
- package/features/users/CreateUser/feature.d.ts +4 -1
- package/features/users/DeleteUser/feature.d.ts +4 -1
- package/features/users/ExternalIdpUserSync/feature.d.ts +4 -1
- package/features/users/GetIdentityProfile/feature.d.ts +4 -1
- package/features/users/GetUser/feature.d.ts +4 -1
- package/features/users/ListUserTeams/feature.d.ts +4 -1
- package/features/users/ListUsers/feature.d.ts +4 -1
- package/features/users/UpdateUser/feature.d.ts +4 -1
- package/features/wcp/WcpContext/WcpContext.d.ts +3 -0
- package/features/wcp/WcpContext/WcpContext.js +9 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +15 -0
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +22 -0
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/features/wcp/WcpContext/feature.d.ts +5 -1
- package/features/wcp/WcpFeature.d.ts +4 -1
- package/features/wcp/WcpFeature.js.map +1 -1
- package/graphql/wcp/graphql.js +1 -0
- package/graphql/wcp/graphql.js.map +1 -1
- package/idp/feature.d.ts +4 -1
- package/legacy/wcp/LegacyWcpContext.d.ts +3 -0
- package/legacy/wcp/LegacyWcpContext.js +9 -0
- package/legacy/wcp/LegacyWcpContext.js.map +1 -1
- package/models/cms/PrivateCmsModelBuilder.js.map +1 -1
- package/models/cms/fieldsBuilder.md +4 -2
- package/package.json +20 -17
package/ApiCoreFeature.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import { Container } from "@webiny/di";
|
|
1
2
|
import type { ApiCoreStorageOperations } from "./types/core.js";
|
|
2
|
-
export declare const ApiCoreFeature:
|
|
3
|
+
export declare const ApiCoreFeature: {
|
|
4
|
+
name: string;
|
|
5
|
+
register(container: Container, context: ApiCoreStorageOperations): void;
|
|
6
|
+
};
|
package/ApiCoreFeature.js
CHANGED
|
@@ -8,14 +8,18 @@ import { AdminUsersFeature } from "./features/users/AdminUsersFeature.js";
|
|
|
8
8
|
import { IdpAuthenticatorFeature } from "./idp/feature.js";
|
|
9
9
|
import { KeyValueStoreFeature } from "./features/keyValueStore/feature.js";
|
|
10
10
|
import { BuildParamsFeature } from "./features/buildParams/feature.js";
|
|
11
|
+
import { EncryptionFeature } from "./features/encryption/feature.js";
|
|
11
12
|
import { FeatureFlagsFeature } from "./features/featureFlags/feature.js";
|
|
13
|
+
import { AiFeature } from "./features/ai/feature.js";
|
|
12
14
|
export const ApiCoreFeature = createFeature({
|
|
13
15
|
name: "ApiCore",
|
|
14
16
|
register(container, config) {
|
|
15
17
|
// Register features
|
|
18
|
+
AiFeature.register(container);
|
|
16
19
|
LoggerFeature.register(container);
|
|
17
20
|
EventPublisherFeature.register(container);
|
|
18
21
|
BuildParamsFeature.register(container);
|
|
22
|
+
EncryptionFeature.register(container);
|
|
19
23
|
FeatureFlagsFeature.register(container);
|
|
20
24
|
TenancyFeature.register(container, config.tenancyStorageOperations);
|
|
21
25
|
SecurityFeature.register(container, config.securityStorageOperations);
|
package/ApiCoreFeature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","EventPublisherFeature","LoggerFeature","SecurityFeature","SystemFeature","TenancyFeature","AdminUsersFeature","IdpAuthenticatorFeature","KeyValueStoreFeature","BuildParamsFeature","FeatureFlagsFeature","ApiCoreFeature","name","register","container","config","tenancyStorageOperations","securityStorageOperations","usersStorageOperations","keyValueStorageOperations"],"sources":["ApiCoreFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Container } from \"@webiny/di\";\nimport { EventPublisherFeature } from \"~/features/eventPublisher/feature.js\";\nimport { LoggerFeature } from \"~/features/logger/feature.js\";\nimport { SecurityFeature } from \"~/features/security/SecurityFeature.js\";\nimport { SystemFeature } from \"~/features/system/SystemFeature.js\";\nimport { TenancyFeature } from \"./features/tenancy/TenancyFeature.js\";\nimport { AdminUsersFeature } from \"~/features/users/AdminUsersFeature.js\";\nimport type { ApiCoreStorageOperations } from \"~/types/core.js\";\nimport { IdpAuthenticatorFeature } from \"~/idp/feature.js\";\nimport { KeyValueStoreFeature } from \"~/features/keyValueStore/feature.js\";\nimport { BuildParamsFeature } from \"~/features/buildParams/feature.js\";\nimport { FeatureFlagsFeature } from \"~/features/featureFlags/feature.js\";\n\nexport const ApiCoreFeature = createFeature({\n name: \"ApiCore\",\n register(container: Container, config: ApiCoreStorageOperations) {\n // Register features\n LoggerFeature.register(container);\n EventPublisherFeature.register(container);\n BuildParamsFeature.register(container);\n FeatureFlagsFeature.register(container);\n TenancyFeature.register(container, config.tenancyStorageOperations);\n SecurityFeature.register(container, config.securityStorageOperations);\n AdminUsersFeature.register(container, config.usersStorageOperations);\n KeyValueStoreFeature.register(container, config.keyValueStorageOperations);\n SystemFeature.register(container);\n IdpAuthenticatorFeature.register(container);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AAEnD,SAASC,qBAAqB;AAC9B,SAASC,aAAa;AACtB,SAASC,eAAe;AACxB,SAASC,aAAa;AACtB,SAASC,cAAc;AACvB,SAASC,iBAAiB;AAE1B,SAASC,uBAAuB;AAChC,SAASC,oBAAoB;AAC7B,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;
|
|
1
|
+
{"version":3,"names":["createFeature","EventPublisherFeature","LoggerFeature","SecurityFeature","SystemFeature","TenancyFeature","AdminUsersFeature","IdpAuthenticatorFeature","KeyValueStoreFeature","BuildParamsFeature","EncryptionFeature","FeatureFlagsFeature","AiFeature","ApiCoreFeature","name","register","container","config","tenancyStorageOperations","securityStorageOperations","usersStorageOperations","keyValueStorageOperations"],"sources":["ApiCoreFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Container } from \"@webiny/di\";\nimport { EventPublisherFeature } from \"~/features/eventPublisher/feature.js\";\nimport { LoggerFeature } from \"~/features/logger/feature.js\";\nimport { SecurityFeature } from \"~/features/security/SecurityFeature.js\";\nimport { SystemFeature } from \"~/features/system/SystemFeature.js\";\nimport { TenancyFeature } from \"./features/tenancy/TenancyFeature.js\";\nimport { AdminUsersFeature } from \"~/features/users/AdminUsersFeature.js\";\nimport type { ApiCoreStorageOperations } from \"~/types/core.js\";\nimport { IdpAuthenticatorFeature } from \"~/idp/feature.js\";\nimport { KeyValueStoreFeature } from \"~/features/keyValueStore/feature.js\";\nimport { BuildParamsFeature } from \"~/features/buildParams/feature.js\";\nimport { EncryptionFeature } from \"~/features/encryption/feature.js\";\nimport { FeatureFlagsFeature } from \"~/features/featureFlags/feature.js\";\nimport { AiFeature } from \"~/features/ai/feature.js\";\n\nexport const ApiCoreFeature = createFeature({\n name: \"ApiCore\",\n register(container: Container, config: ApiCoreStorageOperations) {\n // Register features\n AiFeature.register(container);\n LoggerFeature.register(container);\n EventPublisherFeature.register(container);\n BuildParamsFeature.register(container);\n EncryptionFeature.register(container);\n FeatureFlagsFeature.register(container);\n TenancyFeature.register(container, config.tenancyStorageOperations);\n SecurityFeature.register(container, config.securityStorageOperations);\n AdminUsersFeature.register(container, config.usersStorageOperations);\n KeyValueStoreFeature.register(container, config.keyValueStorageOperations);\n SystemFeature.register(container);\n IdpAuthenticatorFeature.register(container);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AAEnD,SAASC,qBAAqB;AAC9B,SAASC,aAAa;AACtB,SAASC,eAAe;AACxB,SAASC,aAAa;AACtB,SAASC,cAAc;AACvB,SAASC,iBAAiB;AAE1B,SAASC,uBAAuB;AAChC,SAASC,oBAAoB;AAC7B,SAASC,kBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;AAC5B,SAASC,SAAS;AAElB,OAAO,MAAMC,cAAc,GAAGb,aAAa,CAAC;EACxCc,IAAI,EAAE,SAAS;EACfC,QAAQA,CAACC,SAAoB,EAAEC,MAAgC,EAAE;IAC7D;IACAL,SAAS,CAACG,QAAQ,CAACC,SAAS,CAAC;IAC7Bd,aAAa,CAACa,QAAQ,CAACC,SAAS,CAAC;IACjCf,qBAAqB,CAACc,QAAQ,CAACC,SAAS,CAAC;IACzCP,kBAAkB,CAACM,QAAQ,CAACC,SAAS,CAAC;IACtCN,iBAAiB,CAACK,QAAQ,CAACC,SAAS,CAAC;IACrCL,mBAAmB,CAACI,QAAQ,CAACC,SAAS,CAAC;IACvCX,cAAc,CAACU,QAAQ,CAACC,SAAS,EAAEC,MAAM,CAACC,wBAAwB,CAAC;IACnEf,eAAe,CAACY,QAAQ,CAACC,SAAS,EAAEC,MAAM,CAACE,yBAAyB,CAAC;IACrEb,iBAAiB,CAACS,QAAQ,CAACC,SAAS,EAAEC,MAAM,CAACG,sBAAsB,CAAC;IACpEZ,oBAAoB,CAACO,QAAQ,CAACC,SAAS,EAAEC,MAAM,CAACI,yBAAyB,CAAC;IAC1EjB,aAAa,CAACW,QAAQ,CAACC,SAAS,CAAC;IACjCT,uBAAuB,CAACQ,QAAQ,CAACC,SAAS,CAAC;EAC/C;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/createApiCore.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export interface ApiCoreConfig {
|
|
|
4
4
|
storageOperations: ApiCoreStorageOperations;
|
|
5
5
|
testProjectLicense?: DecryptedWcpProjectLicense;
|
|
6
6
|
}
|
|
7
|
-
export declare const createApiCore: (config: ApiCoreConfig) => (import("@webiny/handler-graphql/index.js").GraphQLSchemaPlugin<import("@webiny/api/types.js").Context> | import("@webiny/api/index.js").ContextPlugin<import("./features/wcp/WcpContext/types.js").WcpContext> | import("@webiny/api/index.js").ContextPlugin<import("~/types/core.js").ApiCoreContext>[] | import("@webiny/handler/
|
|
7
|
+
export declare const createApiCore: (config: ApiCoreConfig) => (import("@webiny/handler-graphql/index.js").GraphQLSchemaPlugin<import("@webiny/api/types.js").Context> | import("@webiny/api/index.js").ContextPlugin<import("./features/wcp/WcpContext/types.js").WcpContext> | import("@webiny/api/index.js").ContextPlugin<import("~/types/core.js").ApiCoreContext>[] | import("@webiny/handler/index.js").HandlerOnRequestPlugin<import("@webiny/handler/types.js").Context>)[];
|
package/exports/api.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export { AiSdk, AiSdkFactory, AiConnectionFactory, Ai } from "../features/ai/index.js";
|
|
2
|
+
export type { IAiConnection, IAiConnectionInline } from "../features/ai/index.js";
|
|
1
3
|
export { Logger } from "../features/logger/index.js";
|
|
4
|
+
export { Encryption } from "../features/encryption/index.js";
|
|
2
5
|
export { BuildParam, BuildParams } from "../features/buildParams/index.js";
|
|
3
6
|
export { DomainEvent, EventPublisher } from "../features/eventPublisher/index.js";
|
|
4
7
|
export { GlobalKeyValueStore, KeyValueStore } from "../features/keyValueStore/index.js";
|
package/exports/api.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { AiSdk, AiSdkFactory, AiConnectionFactory, Ai } from "../features/ai/index.js";
|
|
1
2
|
export { Logger } from "../features/logger/index.js";
|
|
3
|
+
export { Encryption } from "../features/encryption/index.js";
|
|
2
4
|
export { BuildParam, BuildParams } from "../features/buildParams/index.js";
|
|
3
5
|
export { DomainEvent, EventPublisher } from "../features/eventPublisher/index.js";
|
|
4
6
|
export { GlobalKeyValueStore, KeyValueStore } from "../features/keyValueStore/index.js";
|
package/exports/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logger","BuildParam","BuildParams","DomainEvent","EventPublisher","GlobalKeyValueStore","KeyValueStore"],"sources":["api.ts"],"sourcesContent":["export { Logger } from \"~/features/logger/index.js\";\nexport { BuildParam, BuildParams } from \"~/features/buildParams/index.js\";\nexport { DomainEvent, EventPublisher } from \"~/features/eventPublisher/index.js\";\nexport { GlobalKeyValueStore, KeyValueStore } from \"~/features/keyValueStore/index.js\";\n"],"mappings":"AAAA,SAASA,MAAM;AACf,SAASC,UAAU,EAAEC,WAAW;AAChC,SAASC,WAAW,EAAEC,cAAc;AACpC,SAASC,mBAAmB,EAAEC,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["AiSdk","AiSdkFactory","AiConnectionFactory","Ai","Logger","Encryption","BuildParam","BuildParams","DomainEvent","EventPublisher","GlobalKeyValueStore","KeyValueStore"],"sources":["api.ts"],"sourcesContent":["export { AiSdk, AiSdkFactory, AiConnectionFactory, Ai } from \"~/features/ai/index.js\";\nexport type { IAiConnection, IAiConnectionInline } from \"~/features/ai/index.js\";\nexport { Logger } from \"~/features/logger/index.js\";\nexport { Encryption } from \"~/features/encryption/index.js\";\nexport { BuildParam, BuildParams } from \"~/features/buildParams/index.js\";\nexport { DomainEvent, EventPublisher } from \"~/features/eventPublisher/index.js\";\nexport { GlobalKeyValueStore, KeyValueStore } from \"~/features/keyValueStore/index.js\";\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,EAAE;AAErD,SAASC,MAAM;AACf,SAASC,UAAU;AACnB,SAASC,UAAU,EAAEC,WAAW;AAChC,SAASC,WAAW,EAAEC,cAAc;AACpC,SAASC,mBAAmB,EAAEC,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { generateText } from "ai";
|
|
2
|
+
import { streamText } from "ai";
|
|
3
|
+
import { Ai as AiAbstraction } from "./abstractions.js";
|
|
4
|
+
import { AiSdkFactory } from "./abstractions.js";
|
|
5
|
+
import { AiConnectionFactory } from "./abstractions.js";
|
|
6
|
+
import type { AiGenerateTextParams, AiModel } from "./abstractions.js";
|
|
7
|
+
import type { AiStreamTextParams } from "./abstractions.js";
|
|
8
|
+
import type { IAiConnectionInline } from "./abstractions.js";
|
|
9
|
+
declare class AiImpl implements AiAbstraction.Interface {
|
|
10
|
+
private readonly sdkFactories;
|
|
11
|
+
private readonly connectionFactories;
|
|
12
|
+
private sdkCache;
|
|
13
|
+
private resolvedConnections;
|
|
14
|
+
constructor(sdkFactories: AiSdkFactory.Interface[], connectionFactories: AiConnectionFactory.Interface[]);
|
|
15
|
+
generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;
|
|
16
|
+
streamText(params: AiStreamTextParams): Promise<ReturnType<typeof streamText>>;
|
|
17
|
+
listModels(): Promise<AiModel[]>;
|
|
18
|
+
listModelsByConnections(): Promise<AiModel[]>;
|
|
19
|
+
listModelsByConnection(connection: string | IAiConnectionInline): Promise<AiModel[]>;
|
|
20
|
+
private resolveLanguageModel;
|
|
21
|
+
private getConnections;
|
|
22
|
+
private resolveConnection;
|
|
23
|
+
private getSdk;
|
|
24
|
+
}
|
|
25
|
+
export declare const Ai: import("@webiny/di").Implementation<typeof AiImpl>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { generateText } from "ai";
|
|
3
|
+
import { streamText } from "ai";
|
|
4
|
+
import { Ai as AiAbstraction } from "./abstractions.js";
|
|
5
|
+
import { AiSdkFactory } from "./abstractions.js";
|
|
6
|
+
import { AiConnectionFactory } from "./abstractions.js";
|
|
7
|
+
function toAiModel(factory, modelId, modelName) {
|
|
8
|
+
return {
|
|
9
|
+
providerId: factory.id,
|
|
10
|
+
providerName: factory.name,
|
|
11
|
+
modelId,
|
|
12
|
+
modelName
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
class AiImpl {
|
|
16
|
+
sdkCache = new Map();
|
|
17
|
+
resolvedConnections = null;
|
|
18
|
+
constructor(sdkFactories, connectionFactories) {
|
|
19
|
+
this.sdkFactories = sdkFactories;
|
|
20
|
+
this.connectionFactories = connectionFactories;
|
|
21
|
+
}
|
|
22
|
+
generateText(params) {
|
|
23
|
+
const {
|
|
24
|
+
model,
|
|
25
|
+
connection,
|
|
26
|
+
...rest
|
|
27
|
+
} = params;
|
|
28
|
+
return this.resolveLanguageModel(model, connection).then(resolvedModel => {
|
|
29
|
+
// Cast required: spreading the discriminated Prompt union loses its narrowing.
|
|
30
|
+
return generateText({
|
|
31
|
+
model: resolvedModel,
|
|
32
|
+
...rest
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async streamText(params) {
|
|
37
|
+
const {
|
|
38
|
+
model,
|
|
39
|
+
connection,
|
|
40
|
+
...rest
|
|
41
|
+
} = params;
|
|
42
|
+
const resolvedModel = await this.resolveLanguageModel(model, connection);
|
|
43
|
+
// Cast required: spreading the discriminated Prompt union loses its narrowing.
|
|
44
|
+
return streamText({
|
|
45
|
+
model: resolvedModel,
|
|
46
|
+
...rest
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
listModels() {
|
|
50
|
+
return Promise.resolve(this.sdkFactories.flatMap(factory => factory.models.map(m => toAiModel(factory, m.id, m.name))));
|
|
51
|
+
}
|
|
52
|
+
async listModelsByConnections() {
|
|
53
|
+
const connections = await this.getConnections();
|
|
54
|
+
return connections.flatMap(conn => {
|
|
55
|
+
const factory = this.sdkFactories.find(f => f.id === conn.sdkName);
|
|
56
|
+
if (!factory) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return factory.models.map(m => toAiModel(factory, m.id, m.name));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async listModelsByConnection(connection) {
|
|
63
|
+
const conn = await this.resolveConnection(undefined, connection);
|
|
64
|
+
const factory = this.sdkFactories.find(f => f.id === conn.sdkName);
|
|
65
|
+
if (!factory) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
return factory.models.map(m => toAiModel(factory, m.id, m.name));
|
|
69
|
+
}
|
|
70
|
+
async resolveLanguageModel(modelId, connection) {
|
|
71
|
+
const slashIndex = modelId.indexOf("/");
|
|
72
|
+
if (slashIndex === -1) {
|
|
73
|
+
throw new Error(`Invalid model ID "${modelId}". Expected format: "<providerId>/<modelId>" (e.g. "openai/gpt-4o").`);
|
|
74
|
+
}
|
|
75
|
+
const providerId = modelId.slice(0, slashIndex);
|
|
76
|
+
const modelName = modelId.slice(slashIndex + 1);
|
|
77
|
+
const conn = await this.resolveConnection(providerId, connection);
|
|
78
|
+
const sdk = await this.getSdk(conn);
|
|
79
|
+
return sdk.languageModel(modelName);
|
|
80
|
+
}
|
|
81
|
+
async getConnections() {
|
|
82
|
+
if (!this.resolvedConnections) {
|
|
83
|
+
this.resolvedConnections = await Promise.all(this.connectionFactories.map(f => f.execute()));
|
|
84
|
+
}
|
|
85
|
+
return this.resolvedConnections;
|
|
86
|
+
}
|
|
87
|
+
async resolveConnection(providerId, connection) {
|
|
88
|
+
if (typeof connection === "object") {
|
|
89
|
+
return connection;
|
|
90
|
+
}
|
|
91
|
+
const connections = await this.getConnections();
|
|
92
|
+
if (typeof connection === "string") {
|
|
93
|
+
const found = connections.find(c => c.id === connection);
|
|
94
|
+
if (!found) {
|
|
95
|
+
const known = connections.map(c => `"${c.id}"`).join(", ");
|
|
96
|
+
throw new Error(`Unknown AI connection "${connection}". Registered connections: ${known}.`);
|
|
97
|
+
}
|
|
98
|
+
return found;
|
|
99
|
+
}
|
|
100
|
+
const found = connections.find(c => c.sdkName === providerId);
|
|
101
|
+
if (!found) {
|
|
102
|
+
const known = connections.map(c => `"${c.id}" (${c.sdkName})`).join(", ");
|
|
103
|
+
throw new Error(`No AI connection found for provider "${providerId}". Registered connections: ${known}.`);
|
|
104
|
+
}
|
|
105
|
+
return found;
|
|
106
|
+
}
|
|
107
|
+
async getSdk(connection) {
|
|
108
|
+
const cacheKey = "id" in connection ? connection.id : `${connection.sdkName}:${connection.apiKey ?? "__env__"}`;
|
|
109
|
+
const cached = this.sdkCache.get(cacheKey);
|
|
110
|
+
if (cached) {
|
|
111
|
+
return cached;
|
|
112
|
+
}
|
|
113
|
+
const factory = this.sdkFactories.find(f => f.id === connection.sdkName);
|
|
114
|
+
if (!factory) {
|
|
115
|
+
const known = this.sdkFactories.map(f => `"${f.id}"`).join(", ");
|
|
116
|
+
throw new Error(`No AI SDK factory found for "${connection.sdkName}". Registered factories: ${known}.`);
|
|
117
|
+
}
|
|
118
|
+
const sdk = await factory.execute(connection.apiKey);
|
|
119
|
+
this.sdkCache.set(cacheKey, sdk);
|
|
120
|
+
return sdk;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export const Ai = createImplementation({
|
|
124
|
+
abstraction: AiAbstraction,
|
|
125
|
+
implementation: AiImpl,
|
|
126
|
+
dependencies: [[AiSdkFactory, {
|
|
127
|
+
multiple: true
|
|
128
|
+
}], [AiConnectionFactory, {
|
|
129
|
+
multiple: true
|
|
130
|
+
}]]
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=Ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createImplementation","generateText","streamText","Ai","AiAbstraction","AiSdkFactory","AiConnectionFactory","toAiModel","factory","modelId","modelName","providerId","id","providerName","name","AiImpl","sdkCache","Map","resolvedConnections","constructor","sdkFactories","connectionFactories","params","model","connection","rest","resolveLanguageModel","then","resolvedModel","listModels","Promise","resolve","flatMap","models","map","m","listModelsByConnections","connections","getConnections","conn","find","f","sdkName","listModelsByConnection","resolveConnection","undefined","slashIndex","indexOf","Error","slice","sdk","getSdk","languageModel","all","execute","found","c","known","join","cacheKey","apiKey","cached","get","set","abstraction","implementation","dependencies","multiple"],"sources":["Ai.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { generateText } from \"ai\";\nimport { streamText } from \"ai\";\nimport { Ai as AiAbstraction } from \"./abstractions.js\";\nimport { AiSdkFactory } from \"./abstractions.js\";\nimport { AiConnectionFactory } from \"./abstractions.js\";\nimport type { AiGenerateTextParams, AiModel, IAiSdkFactory } from \"./abstractions.js\";\nimport type { AiStreamTextParams } from \"./abstractions.js\";\nimport type { IAiSdk } from \"./abstractions.js\";\nimport type { IAiConnection } from \"./abstractions.js\";\nimport type { IAiConnectionInline } from \"./abstractions.js\";\nimport type { LanguageModel } from \"ai\";\n\nfunction toAiModel(factory: IAiSdkFactory, modelId: string, modelName: string): AiModel {\n return {\n providerId: factory.id,\n providerName: factory.name,\n modelId,\n modelName\n };\n}\n\nclass AiImpl implements AiAbstraction.Interface {\n private sdkCache = new Map<string, IAiSdk>();\n private resolvedConnections: IAiConnection[] | null = null;\n\n constructor(\n private readonly sdkFactories: AiSdkFactory.Interface[],\n private readonly connectionFactories: AiConnectionFactory.Interface[]\n ) {}\n\n generateText(params: AiGenerateTextParams): ReturnType<typeof generateText> {\n const { model, connection, ...rest } = params;\n return this.resolveLanguageModel(model, connection).then(resolvedModel => {\n // Cast required: spreading the discriminated Prompt union loses its narrowing.\n return generateText({ model: resolvedModel, ...rest } as Parameters<\n typeof generateText\n >[0]);\n });\n }\n\n async streamText(params: AiStreamTextParams): Promise<ReturnType<typeof streamText>> {\n const { model, connection, ...rest } = params;\n const resolvedModel = await this.resolveLanguageModel(model, connection);\n // Cast required: spreading the discriminated Prompt union loses its narrowing.\n return streamText({ model: resolvedModel, ...rest } as Parameters<typeof streamText>[0]);\n }\n\n listModels(): Promise<AiModel[]> {\n return Promise.resolve(\n this.sdkFactories.flatMap(factory =>\n factory.models.map(m => toAiModel(factory, m.id, m.name))\n )\n );\n }\n\n async listModelsByConnections(): Promise<AiModel[]> {\n const connections = await this.getConnections();\n return connections.flatMap(conn => {\n const factory = this.sdkFactories.find(f => f.id === conn.sdkName);\n if (!factory) {\n return [];\n }\n return factory.models.map(m => toAiModel(factory, m.id, m.name));\n });\n }\n\n async listModelsByConnection(connection: string | IAiConnectionInline): Promise<AiModel[]> {\n const conn = await this.resolveConnection(undefined, connection);\n const factory = this.sdkFactories.find(f => f.id === conn.sdkName);\n if (!factory) {\n return [];\n }\n return factory.models.map(m => toAiModel(factory, m.id, m.name));\n }\n\n private async resolveLanguageModel(\n modelId: string,\n connection?: string | IAiConnectionInline\n ): Promise<LanguageModel> {\n const slashIndex = modelId.indexOf(\"/\");\n if (slashIndex === -1) {\n throw new Error(\n `Invalid model ID \"${modelId}\". Expected format: \"<providerId>/<modelId>\" (e.g. \"openai/gpt-4o\").`\n );\n }\n\n const providerId = modelId.slice(0, slashIndex);\n const modelName = modelId.slice(slashIndex + 1);\n\n const conn = await this.resolveConnection(providerId, connection);\n const sdk = await this.getSdk(conn);\n return sdk.languageModel(modelName);\n }\n\n private async getConnections(): Promise<IAiConnection[]> {\n if (!this.resolvedConnections) {\n this.resolvedConnections = await Promise.all(\n this.connectionFactories.map(f => f.execute())\n );\n }\n return this.resolvedConnections;\n }\n\n private async resolveConnection(\n providerId: string | undefined,\n connection?: string | IAiConnectionInline\n ): Promise<IAiConnectionInline> {\n if (typeof connection === \"object\") {\n return connection;\n }\n\n const connections = await this.getConnections();\n\n if (typeof connection === \"string\") {\n const found = connections.find(c => c.id === connection);\n if (!found) {\n const known = connections.map(c => `\"${c.id}\"`).join(\", \");\n throw new Error(\n `Unknown AI connection \"${connection}\". Registered connections: ${known}.`\n );\n }\n return found;\n }\n\n const found = connections.find(c => c.sdkName === providerId);\n if (!found) {\n const known = connections.map(c => `\"${c.id}\" (${c.sdkName})`).join(\", \");\n throw new Error(\n `No AI connection found for provider \"${providerId}\". Registered connections: ${known}.`\n );\n }\n return found;\n }\n\n private async getSdk(connection: IAiConnectionInline): Promise<IAiSdk> {\n const cacheKey =\n \"id\" in connection\n ? (connection as IAiConnection).id\n : `${connection.sdkName}:${connection.apiKey ?? \"__env__\"}`;\n\n const cached = this.sdkCache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const factory = this.sdkFactories.find(f => f.id === connection.sdkName);\n if (!factory) {\n const known = this.sdkFactories.map(f => `\"${f.id}\"`).join(\", \");\n throw new Error(\n `No AI SDK factory found for \"${connection.sdkName}\". Registered factories: ${known}.`\n );\n }\n\n const sdk = await factory.execute(connection.apiKey);\n this.sdkCache.set(cacheKey, sdk);\n return sdk;\n }\n}\n\nexport const Ai = createImplementation({\n abstraction: AiAbstraction,\n implementation: AiImpl,\n dependencies: [\n [AiSdkFactory, { multiple: true }],\n [AiConnectionFactory, { multiple: true }]\n ]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,YAAY,QAAQ,IAAI;AACjC,SAASC,UAAU,QAAQ,IAAI;AAC/B,SAASC,EAAE,IAAIC,aAAa;AAC5B,SAASC,YAAY;AACrB,SAASC,mBAAmB;AAQ5B,SAASC,SAASA,CAACC,OAAsB,EAAEC,OAAe,EAAEC,SAAiB,EAAW;EACpF,OAAO;IACHC,UAAU,EAAEH,OAAO,CAACI,EAAE;IACtBC,YAAY,EAAEL,OAAO,CAACM,IAAI;IAC1BL,OAAO;IACPC;EACJ,CAAC;AACL;AAEA,MAAMK,MAAM,CAAoC;EACpCC,QAAQ,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACpCC,mBAAmB,GAA2B,IAAI;EAE1DC,WAAWA,CACUC,YAAsC,EACtCC,mBAAoD,EACvE;IAAA,KAFmBD,YAAsC,GAAtCA,YAAsC;IAAA,KACtCC,mBAAoD,GAApDA,mBAAoD;EACtE;EAEHpB,YAAYA,CAACqB,MAA4B,EAAmC;IACxE,MAAM;MAAEC,KAAK;MAAEC,UAAU;MAAE,GAAGC;IAAK,CAAC,GAAGH,MAAM;IAC7C,OAAO,IAAI,CAACI,oBAAoB,CAACH,KAAK,EAAEC,UAAU,CAAC,CAACG,IAAI,CAACC,aAAa,IAAI;MACtE;MACA,OAAO3B,YAAY,CAAC;QAAEsB,KAAK,EAAEK,aAAa;QA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S,EAAE;IAEnE,MAAMC,MAAM,GAAG,IAAI,CAAC7C,QAAQ,CAAC8C,GAAG,CAACH,QAAQ,CAAC;IAC1C,IAAIE,MAAM,EAAE;MACR,OAAOA,MAAM;IACjB;IAEA,MAAMrD,OAAO,GAAG,IAAI,CAACY,YAAY,CAACoB,IAAI,CAACC,CAAC,IAAIA,CAAC,CAAC7B,EAAE,KAAKY,UAAU,CAACkB,OAAO,CAAC;IACxE,IAAI,CAAClC,OAAO,EAAE;MACV,MAAMiD,KAAK,GAAG,IAAI,CAACrC,YAAY,CAACc,GAAG,CAACO,CAAC,IAAI,IAAIA,CAAC,CAAC7B,EAAE,GAAG,CAAC,CAAC8C,IAAI,CAAC,IAAI,CAAC;MAChE,MAAM,IAAIV,KAAK,CACX,gCAAgCxB,UAAU,CAACkB,OAAO,4BAA4Be,KAAK,GACvF,CAAC;IACL;IAEA,MAAMP,GAAG,GAAG,MAAM1C,OAAO,CAAC8C,OAAO,CAAC9B,UAAU,CAACoC,MAAM,CAAC;IACpD,IAAI,CAAC5C,QAAQ,CAAC+C,GAAG,CAACJ,QAAQ,EAAET,GAAG,CAAC;IAChC,OAAOA,GAAG;EACd;AACJ;AAEA,OAAO,MAAM/C,EAAE,GAAGH,oBAAoB,CAAC;EACnCgE,WAAW,EAAE5D,aAAa;EAC1B6D,cAAc,EAAElD,MAAM;EACtBmD,YAAY,EAAE,CACV,CAAC7D,YAAY,EAAE;IAAE8D,QAAQ,EAAE;EAAK,CAAC,CAAC,EAClC,CAAC7D,mBAAmB,EAAE;IAAE6D,QAAQ,EAAE;EAAK,CAAC,CAAC;AAEjD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AiSdkTool, AiSdkTools as AiSdkToolsAbstraction } from "./abstractions.js";
|
|
2
|
+
import type { ToolSet } from "ai";
|
|
3
|
+
declare class AiSdkToolsImpl implements AiSdkToolsAbstraction.Interface {
|
|
4
|
+
private tools;
|
|
5
|
+
constructor(tools: AiSdkTool.Interface[]);
|
|
6
|
+
getToolSet(): ToolSet;
|
|
7
|
+
}
|
|
8
|
+
export declare const AiSdkTools: typeof AiSdkToolsImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IAiSdkTools>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AiSdkTool, AiSdkTools as AiSdkToolsAbstraction } from "./abstractions.js";
|
|
2
|
+
class AiSdkToolsImpl {
|
|
3
|
+
constructor(tools) {
|
|
4
|
+
this.tools = tools;
|
|
5
|
+
}
|
|
6
|
+
getToolSet() {
|
|
7
|
+
const map = {};
|
|
8
|
+
for (const t of this.tools) {
|
|
9
|
+
map[t.name] = {
|
|
10
|
+
description: t.description,
|
|
11
|
+
inputSchema: t.inputSchema,
|
|
12
|
+
execute: input => t.execute(input)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return map;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const AiSdkTools = AiSdkToolsAbstraction.createImplementation({
|
|
19
|
+
implementation: AiSdkToolsImpl,
|
|
20
|
+
dependencies: [[AiSdkTool, {
|
|
21
|
+
multiple: true
|
|
22
|
+
}]]
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=AiSdkTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["AiSdkTool","AiSdkTools","AiSdkToolsAbstraction","AiSdkToolsImpl","constructor","tools","getToolSet","map","t","name","description","inputSchema","execute","input","createImplementation","implementation","dependencies","multiple"],"sources":["AiSdkTools.ts"],"sourcesContent":["import { AiSdkTool, AiSdkTools as AiSdkToolsAbstraction } from \"./abstractions.js\";\nimport type { ToolSet } from \"ai\";\n\nclass AiSdkToolsImpl implements AiSdkToolsAbstraction.Interface {\n constructor(private tools: AiSdkTool.Interface[]) {}\n\n getToolSet(): ToolSet {\n const map: ToolSet = {};\n for (const t of this.tools) {\n map[t.name] = {\n description: t.description,\n inputSchema: t.inputSchema,\n execute: (input: unknown) => t.execute(input)\n };\n }\n return map;\n }\n}\n\nexport const AiSdkTools = AiSdkToolsAbstraction.createImplementation({\n implementation: AiSdkToolsImpl,\n dependencies: [[AiSdkTool, { multiple: true }]]\n});\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,UAAU,IAAIC,qBAAqB;AAGvD,MAAMC,cAAc,CAA4C;EAC5DC,WAAWA,CAASC,KAA4B,EAAE;IAAA,KAA9BA,KAA4B,GAA5BA,KAA4B;EAAG;EAEnDC,UAAUA,CAAA,EAAY;IAClB,MAAMC,GAAY,GAAG,CAAC,CAAC;IACvB,KAAK,MAAMC,CAAC,IAAI,IAAI,CAACH,KAAK,EAAE;MACxBE,GAAG,CAACC,CAAC,CAACC,IAAI,CAAC,GAAG;QACVC,WAAW,EAAEF,CAAC,CAACE,WAAW;QAC1BC,WAAW,EAAEH,CAAC,CAACG,WAAW;QAC1BC,OAAO,EAAGC,KAAc,IAAKL,CAAC,CAACI,OAAO,CAACC,KAAK;MAChD,CAAC;IACL;IACA,OAAON,GAAG;EACd;AACJ;AAEA,OAAO,MAAMN,UAAU,GAAGC,qBAAqB,CAACY,oBAAoB,CAAC;EACjEC,cAAc,EAAEZ,cAAc;EAC9Ba,YAAY,EAAE,CAAC,CAAChB,SAAS,EAAE;IAAEiB,QAAQ,EAAE;EAAK,CAAC,CAAC;AAClD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AiSdkFactory as AiSdkFactoryAbstraction } from "./abstractions.js";
|
|
2
|
+
import type { IAiSdk, IAiSdkModel } from "./abstractions.js";
|
|
3
|
+
declare class AnthropicSdkFactoryImpl implements AiSdkFactoryAbstraction.Interface {
|
|
4
|
+
readonly id = "anthropic";
|
|
5
|
+
readonly name = "Anthropic";
|
|
6
|
+
readonly models: IAiSdkModel[];
|
|
7
|
+
execute(apiKey?: string): Promise<IAiSdk>;
|
|
8
|
+
}
|
|
9
|
+
export declare const AnthropicSdkFactory: import("@webiny/di").Implementation<typeof AnthropicSdkFactoryImpl>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { AiSdkFactory as AiSdkFactoryAbstraction } from "./abstractions.js";
|
|
3
|
+
const ANTHROPIC_MODELS = [{
|
|
4
|
+
id: "claude-3-haiku-20240307",
|
|
5
|
+
name: "Claude 3 Haiku"
|
|
6
|
+
}, {
|
|
7
|
+
id: "claude-haiku-4-5-20251001",
|
|
8
|
+
name: "Claude Haiku 4.5"
|
|
9
|
+
}, {
|
|
10
|
+
id: "claude-haiku-4-5",
|
|
11
|
+
name: "Claude Haiku 4.5"
|
|
12
|
+
}, {
|
|
13
|
+
id: "claude-opus-4-0",
|
|
14
|
+
name: "Claude Opus 4"
|
|
15
|
+
}, {
|
|
16
|
+
id: "claude-opus-4-20250514",
|
|
17
|
+
name: "Claude Opus 4"
|
|
18
|
+
}, {
|
|
19
|
+
id: "claude-opus-4-1-20250805",
|
|
20
|
+
name: "Claude Opus 4.1"
|
|
21
|
+
}, {
|
|
22
|
+
id: "claude-opus-4-1",
|
|
23
|
+
name: "Claude Opus 4.1"
|
|
24
|
+
}, {
|
|
25
|
+
id: "claude-opus-4-5",
|
|
26
|
+
name: "Claude Opus 4.5"
|
|
27
|
+
}, {
|
|
28
|
+
id: "claude-opus-4-5-20251101",
|
|
29
|
+
name: "Claude Opus 4.5"
|
|
30
|
+
}, {
|
|
31
|
+
id: "claude-sonnet-4-0",
|
|
32
|
+
name: "Claude Sonnet 4"
|
|
33
|
+
}, {
|
|
34
|
+
id: "claude-sonnet-4-20250514",
|
|
35
|
+
name: "Claude Sonnet 4"
|
|
36
|
+
}, {
|
|
37
|
+
id: "claude-sonnet-4-5-20250929",
|
|
38
|
+
name: "Claude Sonnet 4.5"
|
|
39
|
+
}, {
|
|
40
|
+
id: "claude-sonnet-4-5",
|
|
41
|
+
name: "Claude Sonnet 4.5"
|
|
42
|
+
}, {
|
|
43
|
+
id: "claude-sonnet-4-6",
|
|
44
|
+
name: "Claude Sonnet 4.6"
|
|
45
|
+
}, {
|
|
46
|
+
id: "claude-opus-4-6",
|
|
47
|
+
name: "Claude Opus 4.6"
|
|
48
|
+
}];
|
|
49
|
+
class AnthropicSdkFactoryImpl {
|
|
50
|
+
id = "anthropic";
|
|
51
|
+
name = "Anthropic";
|
|
52
|
+
models = ANTHROPIC_MODELS;
|
|
53
|
+
async execute(apiKey) {
|
|
54
|
+
const {
|
|
55
|
+
createAnthropic
|
|
56
|
+
} = await import("@ai-sdk/anthropic");
|
|
57
|
+
const provider = createAnthropic({
|
|
58
|
+
apiKey: apiKey ?? process.env.WEBINY_API_ANTHROPIC_API_KEY
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
languageModel: modelId => provider.chat(modelId)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export const AnthropicSdkFactory = createImplementation({
|
|
66
|
+
abstraction: AiSdkFactoryAbstraction,
|
|
67
|
+
implementation: AnthropicSdkFactoryImpl,
|
|
68
|
+
dependencies: []
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=AnthropicSdkFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createImplementation","AiSdkFactory","AiSdkFactoryAbstraction","ANTHROPIC_MODELS","id","name","AnthropicSdkFactoryImpl","models","execute","apiKey","createAnthropic","provider","process","env","WEBINY_API_ANTHROPIC_API_KEY","languageModel","modelId","chat","AnthropicSdkFactory","abstraction","implementation","dependencies"],"sources":["AnthropicSdkFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { AiSdkFactory as AiSdkFactoryAbstraction } from \"./abstractions.js\";\nimport type { IAiSdk, IAiSdkModel } from \"./abstractions.js\";\n\nconst ANTHROPIC_MODELS: IAiSdkModel[] = [\n { id: \"claude-3-haiku-20240307\", name: \"Claude 3 Haiku\" },\n { id: \"claude-haiku-4-5-20251001\", name: \"Claude Haiku 4.5\" },\n { id: \"claude-haiku-4-5\", name: \"Claude Haiku 4.5\" },\n { id: \"claude-opus-4-0\", name: \"Claude Opus 4\" },\n { id: \"claude-opus-4-20250514\", name: \"Claude Opus 4\" },\n { id: \"claude-opus-4-1-20250805\", name: \"Claude Opus 4.1\" },\n { id: \"claude-opus-4-1\", name: \"Claude Opus 4.1\" },\n { id: \"claude-opus-4-5\", name: \"Claude Opus 4.5\" },\n { id: \"claude-opus-4-5-20251101\", name: \"Claude Opus 4.5\" },\n { id: \"claude-sonnet-4-0\", name: \"Claude Sonnet 4\" },\n { id: \"claude-sonnet-4-20250514\", name: \"Claude Sonnet 4\" },\n { id: \"claude-sonnet-4-5-20250929\", name: \"Claude Sonnet 4.5\" },\n { id: \"claude-sonnet-4-5\", name: \"Claude Sonnet 4.5\" },\n { id: \"claude-sonnet-4-6\", name: \"Claude Sonnet 4.6\" },\n { id: \"claude-opus-4-6\", name: \"Claude Opus 4.6\" }\n];\n\nclass AnthropicSdkFactoryImpl implements AiSdkFactoryAbstraction.Interface {\n readonly id = \"anthropic\";\n readonly name = \"Anthropic\";\n readonly models = ANTHROPIC_MODELS;\n\n async execute(apiKey?: string): Promise<IAiSdk> {\n const { createAnthropic } = await import(\"@ai-sdk/anthropic\");\n const provider = createAnthropic({\n apiKey: apiKey ?? process.env.WEBINY_API_ANTHROPIC_API_KEY\n });\n return {\n languageModel: modelId => provider.chat(modelId)\n };\n }\n}\n\nexport const AnthropicSdkFactory = createImplementation({\n abstraction: AiSdkFactoryAbstraction,\n implementation: AnthropicSdkFactoryImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,YAAY,IAAIC,uBAAuB;AAGhD,MAAMC,gBAA+B,GAAG,CACpC;EAAEC,EAAE,EAAE,yBAAyB;EAA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A,MAAM,IAAIG,OAAO,CAACC,GAAG,CAACC;IAClC,CAAC,CAAC;IACF,OAAO;MACHC,aAAa,EAAEC,OAAO,IAAIL,QAAQ,CAACM,IAAI,CAACD,OAAO;IACnD,CAAC;EACL;AACJ;AAEA,OAAO,MAAME,mBAAmB,GAAGlB,oBAAoB,CAAC;EACpDmB,WAAW,EAAEjB,uBAAuB;EACpCkB,cAAc,EAAEd,uBAAuB;EACvCe,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AiSdkFactory as AiSdkFactoryAbstraction } from "./abstractions.js";
|
|
2
|
+
import type { IAiSdk, IAiSdkModel } from "./abstractions.js";
|
|
3
|
+
declare class OpenAiSdkFactoryImpl implements AiSdkFactoryAbstraction.Interface {
|
|
4
|
+
readonly id = "openai";
|
|
5
|
+
readonly name = "OpenAI";
|
|
6
|
+
readonly models: IAiSdkModel[];
|
|
7
|
+
execute(apiKey?: string): Promise<IAiSdk>;
|
|
8
|
+
}
|
|
9
|
+
export declare const OpenAiSdkFactory: import("@webiny/di").Implementation<typeof OpenAiSdkFactoryImpl>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { AiSdkFactory as AiSdkFactoryAbstraction } from "./abstractions.js";
|
|
3
|
+
// 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05'
|
|
4
|
+
|
|
5
|
+
const OPENAI_MODELS = [{
|
|
6
|
+
id: "gpt-5",
|
|
7
|
+
name: "GPT-5"
|
|
8
|
+
}, {
|
|
9
|
+
id: "gpt-5-2025-08-07",
|
|
10
|
+
name: "GPT-5"
|
|
11
|
+
}, {
|
|
12
|
+
id: "gpt-5-chat-latest",
|
|
13
|
+
name: "GPT-5"
|
|
14
|
+
}, {
|
|
15
|
+
id: "gpt-5-mini",
|
|
16
|
+
name: "GPT-5 Mini"
|
|
17
|
+
}, {
|
|
18
|
+
id: "gpt-5-mini-2025-08-07",
|
|
19
|
+
name: "GPT-5 Mini"
|
|
20
|
+
}, {
|
|
21
|
+
id: "gpt-5-nano",
|
|
22
|
+
name: "GPT-5 Nano"
|
|
23
|
+
}, {
|
|
24
|
+
id: "gpt-5-nano-2025-08-07",
|
|
25
|
+
name: "GPT-5 Nano"
|
|
26
|
+
}, {
|
|
27
|
+
id: "gpt-5.1",
|
|
28
|
+
name: "GPT-5.1"
|
|
29
|
+
}, {
|
|
30
|
+
id: "gpt-5.1-2025-11-13",
|
|
31
|
+
name: "GPT-5.1"
|
|
32
|
+
}, {
|
|
33
|
+
id: "gpt-5.1-chat-latest",
|
|
34
|
+
name: "GPT-5.1"
|
|
35
|
+
}, {
|
|
36
|
+
id: "gpt-5.2",
|
|
37
|
+
name: "GPT-5.2"
|
|
38
|
+
}, {
|
|
39
|
+
id: "gpt-5.2-2025-12-11",
|
|
40
|
+
name: "GPT-5.2"
|
|
41
|
+
}, {
|
|
42
|
+
id: "gpt-5.2-chat-latest",
|
|
43
|
+
name: "GPT-5.2"
|
|
44
|
+
}, {
|
|
45
|
+
id: "gpt-5.2-pro",
|
|
46
|
+
name: "GPT-5.2 Pro"
|
|
47
|
+
}, {
|
|
48
|
+
id: "gpt-5.2-pro-2025-12-11",
|
|
49
|
+
name: "GPT-5.2 Pro"
|
|
50
|
+
}, {
|
|
51
|
+
id: "gpt-5.3-chat-latest",
|
|
52
|
+
name: "GPT-5.3"
|
|
53
|
+
}, {
|
|
54
|
+
id: "gpt-5.4",
|
|
55
|
+
name: "GPT-5.4"
|
|
56
|
+
}, {
|
|
57
|
+
id: "gpt-5.4-2026-03-05",
|
|
58
|
+
name: "GPT-5.4"
|
|
59
|
+
}, {
|
|
60
|
+
id: "gpt-5.4-mini",
|
|
61
|
+
name: "GPT-5.4 Mini"
|
|
62
|
+
}, {
|
|
63
|
+
id: "gpt-5.4-mini-2026-03-17",
|
|
64
|
+
name: "GPT-5.4 Mini"
|
|
65
|
+
}, {
|
|
66
|
+
id: "gpt-5.4-nano",
|
|
67
|
+
name: "GPT-5.4 Nano"
|
|
68
|
+
}, {
|
|
69
|
+
id: "gpt-5.4-nano-2026-03-17",
|
|
70
|
+
name: "GPT-5.4 Nano"
|
|
71
|
+
}, {
|
|
72
|
+
id: "gpt-5.4-pro",
|
|
73
|
+
name: "GPT-5.4 Pro"
|
|
74
|
+
}, {
|
|
75
|
+
id: "gpt-5.4-pro-2026-03-05",
|
|
76
|
+
name: "GPT-5.4 Pro"
|
|
77
|
+
}, {
|
|
78
|
+
id: "gpt-4.1",
|
|
79
|
+
name: "GPT-4.1"
|
|
80
|
+
}, {
|
|
81
|
+
id: "gpt-4.1-2025-04-14",
|
|
82
|
+
name: "GPT-4.1"
|
|
83
|
+
}, {
|
|
84
|
+
id: "gpt-4.1-mini",
|
|
85
|
+
name: "GPT-4.1 Mini"
|
|
86
|
+
}, {
|
|
87
|
+
id: "gpt-4.1-mini-2025-04-14",
|
|
88
|
+
name: "GPT-4.1 Mini"
|
|
89
|
+
}, {
|
|
90
|
+
id: "gpt-4.1-nano",
|
|
91
|
+
name: "GPT-4.1 Nano"
|
|
92
|
+
}, {
|
|
93
|
+
id: "gpt-4.1-nano-2025-04-14",
|
|
94
|
+
name: "GPT-4.1 Nano"
|
|
95
|
+
}, {
|
|
96
|
+
id: "gpt-4o",
|
|
97
|
+
name: "GPT-4o"
|
|
98
|
+
}, {
|
|
99
|
+
id: "gpt-4o-2024-05-13",
|
|
100
|
+
name: "GPT-4o"
|
|
101
|
+
}, {
|
|
102
|
+
id: "gpt-4o-2024-08-06",
|
|
103
|
+
name: "GPT-4o"
|
|
104
|
+
}, {
|
|
105
|
+
id: "gpt-4o-2024-11-20",
|
|
106
|
+
name: "GPT-4o"
|
|
107
|
+
}, {
|
|
108
|
+
id: "gpt-4o-audio-preview",
|
|
109
|
+
name: "GPT-4o Audio Preview"
|
|
110
|
+
}, {
|
|
111
|
+
id: "gpt-4o-audio-preview-2024-12-17",
|
|
112
|
+
name: "GPT-4o Audio Preview"
|
|
113
|
+
}, {
|
|
114
|
+
id: "gpt-4o-search-preview",
|
|
115
|
+
name: "GPT-4o Search Preview"
|
|
116
|
+
}, {
|
|
117
|
+
id: "gpt-4o-search-preview-2025-03-11",
|
|
118
|
+
name: "GPT-4o Search Preview"
|
|
119
|
+
}, {
|
|
120
|
+
id: "gpt-4o-mini-search-preview",
|
|
121
|
+
name: "GPT-4o Mini Search Preview"
|
|
122
|
+
}, {
|
|
123
|
+
id: "gpt-4o-mini-search-preview-2025-03-11",
|
|
124
|
+
name: "GPT-4o Mini Search Preview"
|
|
125
|
+
}, {
|
|
126
|
+
id: "gpt-4o-mini",
|
|
127
|
+
name: "GPT-4o Mini"
|
|
128
|
+
}, {
|
|
129
|
+
id: "gpt-4o-mini-2024-07-18",
|
|
130
|
+
name: "GPT-4o Mini"
|
|
131
|
+
}, {
|
|
132
|
+
id: "gpt-3.5-turbo-0125",
|
|
133
|
+
name: "GPT-3.5 Turbo"
|
|
134
|
+
}, {
|
|
135
|
+
id: "gpt-3.5-turbo",
|
|
136
|
+
name: "GPT-3.5 Turbo"
|
|
137
|
+
}, {
|
|
138
|
+
id: "gpt-3.5-turbo-1106",
|
|
139
|
+
name: "GPT-3.5 Turbo"
|
|
140
|
+
}, {
|
|
141
|
+
id: "o1",
|
|
142
|
+
name: "o1"
|
|
143
|
+
}, {
|
|
144
|
+
id: "o1-2024-12-17",
|
|
145
|
+
name: "o1"
|
|
146
|
+
}, {
|
|
147
|
+
id: "o3",
|
|
148
|
+
name: "o3"
|
|
149
|
+
}, {
|
|
150
|
+
id: "o3-2025-04-16",
|
|
151
|
+
name: "o3"
|
|
152
|
+
}, {
|
|
153
|
+
id: "o3-mini",
|
|
154
|
+
name: "o3 Mini"
|
|
155
|
+
}, {
|
|
156
|
+
id: "o3-mini-2025-01-31",
|
|
157
|
+
name: "o3 Mini"
|
|
158
|
+
}, {
|
|
159
|
+
id: "o4-mini",
|
|
160
|
+
name: "o4 Mini"
|
|
161
|
+
}, {
|
|
162
|
+
id: "o4-mini-2025-04-16",
|
|
163
|
+
name: "o4 Mini"
|
|
164
|
+
}];
|
|
165
|
+
class OpenAiSdkFactoryImpl {
|
|
166
|
+
id = "openai";
|
|
167
|
+
name = "OpenAI";
|
|
168
|
+
models = OPENAI_MODELS;
|
|
169
|
+
async execute(apiKey) {
|
|
170
|
+
const {
|
|
171
|
+
createOpenAI
|
|
172
|
+
} = await import("@ai-sdk/openai");
|
|
173
|
+
const provider = createOpenAI({
|
|
174
|
+
apiKey: apiKey ?? process.env.WEBINY_API_OPENAI_API_KEY
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
languageModel: modelId => provider.chat(modelId)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export const OpenAiSdkFactory = createImplementation({
|
|
182
|
+
abstraction: AiSdkFactoryAbstraction,
|
|
183
|
+
implementation: OpenAiSdkFactoryImpl,
|
|
184
|
+
dependencies: []
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=OpenAiSdkFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createImplementation","AiSdkFactory","AiSdkFactoryAbstraction","OPENAI_MODELS","id","name","OpenAiSdkFactoryImpl","models","execute","apiKey","createOpenAI","provider","process","env","WEBINY_API_OPENAI_API_KEY","languageModel","modelId","chat","OpenAiSdkFactory","abstraction","implementation","dependencies"],"sources":["OpenAiSdkFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { AiSdkFactory as AiSdkFactoryAbstraction } from \"./abstractions.js\";\nimport type { IAiSdk, IAiSdkModel } from \"./abstractions.js\";\n\n// 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05'\n\nconst OPENAI_MODELS: IAiSdkModel[] = [\n { id: \"gpt-5\", name: \"GPT-5\" },\n { id: \"gpt-5-2025-08-07\", name: \"GPT-5\" },\n { id: \"gpt-5-chat-latest\", name: \"GPT-5\" },\n { id: \"gpt-5-mini\", name: \"GPT-5 Mini\" },\n { id: \"gpt-5-mini-2025-08-07\", name: \"GPT-5 Mini\" },\n { id: \"gpt-5-nano\", name: \"GPT-5 Nano\" },\n { id: \"gpt-5-nano-2025-08-07\", name: \"GPT-5 Nano\" },\n { id: \"gpt-5.1\", name: \"GPT-5.1\" },\n { id: \"gpt-5.1-2025-11-13\", name: \"GPT-5.1\" },\n { id: \"gpt-5.1-chat-latest\", name: \"GPT-5.1\" },\n { id: \"gpt-5.2\", name: \"GPT-5.2\" },\n { id: \"gpt-5.2-2025-12-11\", name: \"GPT-5.2\" },\n { id: \"gpt-5.2-chat-latest\", name: \"GPT-5.2\" },\n { id: \"gpt-5.2-pro\", name: \"GPT-5.2 Pro\" },\n { id: \"gpt-5.2-pro-2025-12-11\", name: \"GPT-5.2 Pro\" },\n { id: \"gpt-5.3-chat-latest\", name: \"GPT-5.3\" },\n { id: \"gpt-5.4\", name: \"GPT-5.4\" },\n { id: \"gpt-5.4-2026-03-05\", name: \"GPT-5.4\" },\n { id: \"gpt-5.4-mini\", name: \"GPT-5.4 Mini\" },\n { id: \"gpt-5.4-mini-2026-03-17\", name: \"GPT-5.4 Mini\" },\n { id: \"gpt-5.4-nano\", name: \"GPT-5.4 Nano\" },\n { id: \"gpt-5.4-nano-2026-03-17\", name: \"GPT-5.4 Nano\" },\n { id: \"gpt-5.4-pro\", name: \"GPT-5.4 Pro\" },\n { id: \"gpt-5.4-pro-2026-03-05\", name: \"GPT-5.4 Pro\" },\n { id: \"gpt-4.1\", name: \"GPT-4.1\" },\n { id: \"gpt-4.1-2025-04-14\", name: \"GPT-4.1\" },\n { id: \"gpt-4.1-mini\", name: \"GPT-4.1 Mini\" },\n { id: \"gpt-4.1-mini-2025-04-14\", name: \"GPT-4.1 Mini\" },\n { id: \"gpt-4.1-nano\", name: \"GPT-4.1 Nano\" },\n { id: \"gpt-4.1-nano-2025-04-14\", name: \"GPT-4.1 Nano\" },\n { id: \"gpt-4o\", name: \"GPT-4o\" },\n { id: \"gpt-4o-2024-05-13\", name: \"GPT-4o\" },\n { id: \"gpt-4o-2024-08-06\", name: \"GPT-4o\" },\n { id: \"gpt-4o-2024-11-20\", name: \"GPT-4o\" },\n { id: \"gpt-4o-audio-preview\", name: \"GPT-4o Audio Preview\" },\n { id: \"gpt-4o-audio-preview-2024-12-17\", name: \"GPT-4o Audio Preview\" },\n { id: \"gpt-4o-search-preview\", name: \"GPT-4o Search Preview\" },\n { id: \"gpt-4o-search-preview-2025-03-11\", name: \"GPT-4o Search Preview\" },\n { id: \"gpt-4o-mini-search-preview\", name: \"GPT-4o Mini Search Preview\" },\n { id: \"gpt-4o-mini-search-preview-2025-03-11\", name: \"GPT-4o Mini Search Preview\" },\n { id: \"gpt-4o-mini\", name: \"GPT-4o Mini\" },\n { id: \"gpt-4o-mini-2024-07-18\", name: \"GPT-4o Mini\" },\n { id: \"gpt-3.5-turbo-0125\", name: \"GPT-3.5 Turbo\" },\n { id: \"gpt-3.5-turbo\", name: \"GPT-3.5 Turbo\" },\n { id: \"gpt-3.5-turbo-1106\", name: \"GPT-3.5 Turbo\" },\n { id: \"o1\", name: \"o1\" },\n { id: \"o1-2024-12-17\", name: \"o1\" },\n { id: \"o3\", name: \"o3\" },\n { id: \"o3-2025-04-16\", name: \"o3\" },\n { id: \"o3-mini\", name: \"o3 Mini\" },\n { id: \"o3-mini-2025-01-31\", name: \"o3 Mini\" },\n { id: \"o4-mini\", name: \"o4 Mini\" },\n { id: \"o4-mini-2025-04-16\", name: \"o4 Mini\" }\n];\n\nclass OpenAiSdkFactoryImpl implements AiSdkFactoryAbstraction.Interface {\n readonly id = \"openai\";\n readonly name = \"OpenAI\";\n readonly models = OPENAI_MODELS;\n\n async execute(apiKey?: string): Promise<IAiSdk> {\n const { createOpenAI } = await import(\"@ai-sdk/openai\");\n const provider = createOpenAI({\n apiKey: apiKey ?? process.env.WEBINY_API_OPENAI_API_KEY\n });\n return {\n languageModel: modelId => provider.chat(modelId)\n };\n }\n}\n\nexport const OpenAiSdkFactory = createImplementation({\n abstraction: AiSdkFactoryAbstraction,\n implementation: OpenAiSdkFactoryImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,YAAY,IAAIC,uBAAuB;AAGhD;;AAEA,MAAMC,aAA4B,GAAG,CACjC;EAAEC,EAAE,EAAE,OAAO;EAAEC,IAAI,EAAE;AAAQ,CAAC,EAC9B;EAAED,EAAE,EAAE,kBAAkB;EAAEC,IAAI,EAAE;AAAQ,CAAC,EACzC;EAAED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