@webiny/api-core 6.4.12-beta.5 → 6.5.0-beta.1
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.js +0 -2
- package/ApiCoreFeature.js.map +1 -1
- package/createApiCore.d.ts +1 -1
- package/createApiCore.js +9 -7
- package/createApiCore.js.map +1 -1
- package/exports/api/security/api-key.d.ts +1 -0
- package/exports/api/security/api-key.js +1 -0
- package/exports/api.d.ts +2 -1
- package/exports/api.js +1 -1
- package/features/ai/Ai.d.ts +3 -1
- package/features/ai/Ai.js +38 -3
- package/features/ai/Ai.js.map +1 -1
- package/features/ai/AiModelRegistry.js +3 -1
- package/features/ai/AiModelRegistry.js.map +1 -1
- package/features/ai/AnthropicSdkFactory.js +24 -4
- package/features/ai/AnthropicSdkFactory.js.map +1 -1
- package/features/ai/DEVELOPERS.md +126 -0
- package/features/ai/GoogleSdkFactory.d.ts +10 -0
- package/features/ai/GoogleSdkFactory.js +65 -0
- package/features/ai/GoogleSdkFactory.js.map +1 -0
- package/features/ai/OpenAiSdkFactory.js +67 -11
- package/features/ai/OpenAiSdkFactory.js.map +1 -1
- package/features/ai/TextExtractor/DefaultTextExtractor.d.ts +9 -0
- package/features/ai/TextExtractor/DefaultTextExtractor.js +28 -0
- package/features/ai/TextExtractor/DefaultTextExtractor.js.map +1 -0
- package/features/ai/TextExtractor/abstractions.d.ts +12 -0
- package/features/ai/TextExtractor/abstractions.js +5 -0
- package/features/ai/TextExtractor/abstractions.js.map +1 -0
- package/features/ai/TextExtractor/index.d.ts +3 -0
- package/features/ai/TextExtractor/index.js +2 -0
- package/features/ai/TextExtractor/parsers/docxParser.d.ts +1 -0
- package/features/ai/TextExtractor/parsers/docxParser.js +111 -0
- package/features/ai/TextExtractor/parsers/docxParser.js.map +1 -0
- package/features/ai/abstractions.d.ts +4 -0
- package/features/ai/abstractions.js.map +1 -1
- package/features/ai/events.d.ts +59 -0
- package/features/ai/events.js +41 -0
- package/features/ai/events.js.map +1 -0
- package/features/ai/feature.js +9 -1
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +7 -1
- package/features/ai/index.js +3 -0
- package/features/ai/toolPipeline/AiOutputToolRegistry.d.ts +11 -0
- package/features/ai/toolPipeline/AiOutputToolRegistry.js +31 -0
- package/features/ai/toolPipeline/AiOutputToolRegistry.js.map +1 -0
- package/features/ai/toolPipeline/AiToolPipelineRunner.d.ts +10 -0
- package/features/ai/toolPipeline/AiToolPipelineRunner.js +36 -0
- package/features/ai/toolPipeline/AiToolPipelineRunner.js.map +1 -0
- package/features/ai/toolPipeline/abstractions.d.ts +23 -0
- package/features/ai/toolPipeline/abstractions.js +7 -0
- package/features/ai/toolPipeline/abstractions.js.map +1 -0
- package/features/ai/toolPipeline/index.d.ts +2 -0
- package/features/ai/toolPipeline/index.js +1 -0
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +1 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.d.ts +1 -3
- package/features/security/apiKeys/GetApiKeyBySlug/GetApiKeyBySlugUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.d.ts +1 -1
- package/features/security/apiKeys/GetApiKeyBySlug/abstractions.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.d.ts +1 -3
- package/features/security/apiKeys/GetApiKeyByToken/GetApiKeyByTokenUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.d.ts +1 -1
- package/features/security/apiKeys/GetApiKeyByToken/abstractions.js.map +1 -1
- package/features/security/apiKeys/feature.js +7 -2
- package/features/security/apiKeys/feature.js.map +1 -1
- package/features/security/apiKeys/shared/ApiKeyProvider.d.ts +3 -5
- package/features/security/apiKeys/shared/ApiKeyProvider.js +6 -21
- package/features/security/apiKeys/shared/ApiKeyProvider.js.map +1 -1
- package/features/security/apiKeys/shared/ApiKeysRepository.d.ts +1 -0
- package/features/security/apiKeys/shared/ApiKeysRepository.js +19 -4
- package/features/security/apiKeys/shared/ApiKeysRepository.js.map +1 -1
- package/features/security/apiKeys/shared/generateToken.d.ts +1 -1
- package/features/security/apiKeys/shared/generateToken.js.map +1 -1
- package/features/security/apiKeys/shared/types.d.ts +1 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +1 -1
- package/features/security/utils/getPermissionsFromRoles.d.ts +1 -1
- package/features/serviceDiscovery/ServiceDiscovery.d.ts +17 -0
- package/features/serviceDiscovery/ServiceDiscovery.js +22 -0
- package/features/serviceDiscovery/ServiceDiscovery.js.map +1 -0
- package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js +111 -0
- package/features/serviceDiscovery/__tests__/ServiceDiscovery.test.js.map +1 -0
- package/features/serviceDiscovery/index.d.ts +3 -0
- package/features/serviceDiscovery/index.js +1 -0
- package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +1 -1
- package/features/tenancy/InstallTenant/InstallTenantUseCase.d.ts +1 -1
- package/features/tenancy/UpdateTenant/UpdateTenantUseCase.d.ts +2 -2
- package/features/users/CreateUser/decorators/CreateUserWithWcpIncrement.d.ts +1 -1
- package/features/users/shared/loaders.js.map +1 -1
- package/features/wcp/WcpContext/WcpContext.d.ts +9 -0
- package/features/wcp/WcpContext/WcpContext.js +27 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +31 -5
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +48 -2
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/legacy/security/plugins/apiKeyAuthentication.d.ts +1 -1
- package/legacy/security/plugins/apiKeyAuthorization.d.ts +1 -1
- package/legacy/security/plugins/authenticateUsingCookie.d.ts +1 -1
- package/legacy/security/plugins/authenticateUsingHttpHeader.d.ts +1 -1
- package/legacy/security/plugins/secureHeaders.js +0 -1
- package/legacy/security/plugins/secureHeaders.js.map +1 -1
- package/legacy/wcp/LegacyWcpContext.d.ts +9 -0
- package/legacy/wcp/LegacyWcpContext.js +27 -0
- package/legacy/wcp/LegacyWcpContext.js.map +1 -1
- package/package.json +24 -25
- package/types/security.d.ts +1 -1
- package/features/debugger/Debugger.d.ts +0 -23
- package/features/debugger/Debugger.js +0 -134
- package/features/debugger/Debugger.js.map +0 -1
- package/features/debugger/GraphQLDebuggerTransport.d.ts +0 -26
- package/features/debugger/GraphQLDebuggerTransport.js +0 -45
- package/features/debugger/GraphQLDebuggerTransport.js.map +0 -1
- package/features/debugger/__tests__/matchNamespace.test.js +0 -67
- package/features/debugger/__tests__/matchNamespace.test.js.map +0 -1
- package/features/debugger/__tests__/serialize.test.d.ts +0 -1
- package/features/debugger/__tests__/serialize.test.js +0 -220
- package/features/debugger/__tests__/serialize.test.js.map +0 -1
- package/features/debugger/abstractions.d.ts +0 -100
- package/features/debugger/abstractions.js +0 -6
- package/features/debugger/abstractions.js.map +0 -1
- package/features/debugger/feature.d.ts +0 -5
- package/features/debugger/feature.js +0 -15
- package/features/debugger/feature.js.map +0 -1
- package/features/debugger/index.d.ts +0 -7
- package/features/debugger/index.js +0 -7
- package/features/debugger/limits.d.ts +0 -18
- package/features/debugger/limits.js +0 -11
- package/features/debugger/limits.js.map +0 -1
- package/features/debugger/matchNamespace.d.ts +0 -21
- package/features/debugger/matchNamespace.js +0 -48
- package/features/debugger/matchNamespace.js.map +0 -1
- package/features/debugger/permissions.d.ts +0 -33
- package/features/debugger/permissions.js +0 -12
- package/features/debugger/permissions.js.map +0 -1
- package/features/debugger/permissionsSchema.d.ts +0 -17
- package/features/debugger/permissionsSchema.js +0 -18
- package/features/debugger/permissionsSchema.js.map +0 -1
- package/features/debugger/plugins.d.ts +0 -4
- package/features/debugger/plugins.js +0 -82
- package/features/debugger/plugins.js.map +0 -1
- package/features/debugger/serialize.d.ts +0 -11
- package/features/debugger/serialize.js +0 -121
- package/features/debugger/serialize.js.map +0 -1
- /package/features/{debugger/__tests__/matchNamespace.test.d.ts → serviceDiscovery/__tests__/ServiceDiscovery.test.d.ts} +0 -0
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
import { createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { AiSdkFactory } from "./abstractions.js";
|
|
3
3
|
const OPENAI_MODELS = [
|
|
4
|
+
{
|
|
5
|
+
id: "gpt-6-astra",
|
|
6
|
+
name: "GPT-6 Astra"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
id: "gpt-5.6-sol",
|
|
10
|
+
name: "GPT-5.6 Sol"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "gpt-5.6-terra",
|
|
14
|
+
name: "GPT-5.6 Terra"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "gpt-5.6-luna",
|
|
18
|
+
name: "GPT-5.6 Luna"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "gpt-5.5",
|
|
22
|
+
name: "GPT-5.5"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "gpt-5.5-pro",
|
|
26
|
+
name: "GPT-5.5 Pro"
|
|
27
|
+
},
|
|
4
28
|
{
|
|
5
29
|
id: "gpt-5.4",
|
|
6
30
|
name: "GPT-5.4"
|
|
7
31
|
},
|
|
32
|
+
{
|
|
33
|
+
id: "gpt-5.4-pro",
|
|
34
|
+
name: "GPT-5.4 Pro"
|
|
35
|
+
},
|
|
8
36
|
{
|
|
9
37
|
id: "gpt-5.4-mini",
|
|
10
38
|
name: "GPT-5.4 Mini"
|
|
@@ -14,12 +42,28 @@ const OPENAI_MODELS = [
|
|
|
14
42
|
name: "GPT-5.4 Nano"
|
|
15
43
|
},
|
|
16
44
|
{
|
|
17
|
-
id: "gpt-5.
|
|
18
|
-
name: "GPT-5.
|
|
45
|
+
id: "gpt-5.2",
|
|
46
|
+
name: "GPT-5.2"
|
|
19
47
|
},
|
|
20
48
|
{
|
|
21
|
-
id: "gpt-5.
|
|
22
|
-
name: "GPT-5.
|
|
49
|
+
id: "gpt-5.2-pro",
|
|
50
|
+
name: "GPT-5.2 Pro"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "gpt-5",
|
|
54
|
+
name: "GPT-5"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "gpt-5-pro",
|
|
58
|
+
name: "GPT-5 Pro"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "gpt-5-mini",
|
|
62
|
+
name: "GPT-5 Mini"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "gpt-5-nano",
|
|
66
|
+
name: "GPT-5 Nano"
|
|
23
67
|
},
|
|
24
68
|
{
|
|
25
69
|
id: "gpt-4.1",
|
|
@@ -29,10 +73,6 @@ const OPENAI_MODELS = [
|
|
|
29
73
|
id: "gpt-4.1-mini",
|
|
30
74
|
name: "GPT-4.1 Mini"
|
|
31
75
|
},
|
|
32
|
-
{
|
|
33
|
-
id: "gpt-4.1-nano",
|
|
34
|
-
name: "GPT-4.1 Nano"
|
|
35
|
-
},
|
|
36
76
|
{
|
|
37
77
|
id: "gpt-4o",
|
|
38
78
|
name: "GPT-4o"
|
|
@@ -42,12 +82,28 @@ const OPENAI_MODELS = [
|
|
|
42
82
|
name: "GPT-4o Mini"
|
|
43
83
|
},
|
|
44
84
|
{
|
|
45
|
-
id: "
|
|
46
|
-
name: "
|
|
85
|
+
id: "o3-pro",
|
|
86
|
+
name: "o3 Pro",
|
|
87
|
+
deprecated: new Date("2026-06-11"),
|
|
88
|
+
endOfLife: new Date("2026-12-11")
|
|
47
89
|
},
|
|
48
90
|
{
|
|
49
91
|
id: "o3",
|
|
50
|
-
name: "o3"
|
|
92
|
+
name: "o3",
|
|
93
|
+
deprecated: new Date("2026-06-11"),
|
|
94
|
+
endOfLife: new Date("2026-12-11")
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "gpt-4.1-nano",
|
|
98
|
+
name: "GPT-4.1 Nano",
|
|
99
|
+
deprecated: new Date("2026-04-22"),
|
|
100
|
+
endOfLife: new Date("2026-10-23")
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "o4-mini",
|
|
104
|
+
name: "o4 Mini",
|
|
105
|
+
deprecated: new Date("2026-04-22"),
|
|
106
|
+
endOfLife: new Date("2026-10-23")
|
|
51
107
|
}
|
|
52
108
|
];
|
|
53
109
|
class OpenAiSdkFactoryImpl {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/OpenAiSdkFactory.js","sources":["../../../src/features/ai/OpenAiSdkFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { AiSdkFactory as AiSdkFactoryAbstraction } from \"./abstractions.js\";\nimport type { IAiSdk, IAiSdkModel } from \"./abstractions.js\";\n\nconst OPENAI_MODELS: IAiSdkModel[] = [\n { id: \"gpt-5.4\", name: \"GPT-5.4\" },\n { id: \"gpt-5.4-mini\", name: \"GPT-5.4 Mini\" },\n { id: \"gpt-5.4-nano\", name: \"GPT-5.4 Nano\" },\n { id: \"gpt-5.
|
|
1
|
+
{"version":3,"file":"features/ai/OpenAiSdkFactory.js","sources":["../../../src/features/ai/OpenAiSdkFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { AiSdkFactory as AiSdkFactoryAbstraction } from \"./abstractions.js\";\nimport type { IAiSdk, IAiSdkModel } from \"./abstractions.js\";\n\nconst OPENAI_MODELS: IAiSdkModel[] = [\n { id: \"gpt-6-astra\", name: \"GPT-6 Astra\" },\n { id: \"gpt-5.6-sol\", name: \"GPT-5.6 Sol\" },\n { id: \"gpt-5.6-terra\", name: \"GPT-5.6 Terra\" },\n { id: \"gpt-5.6-luna\", name: \"GPT-5.6 Luna\" },\n { id: \"gpt-5.5\", name: \"GPT-5.5\" },\n { id: \"gpt-5.5-pro\", name: \"GPT-5.5 Pro\" },\n { id: \"gpt-5.4\", name: \"GPT-5.4\" },\n { id: \"gpt-5.4-pro\", name: \"GPT-5.4 Pro\" },\n { id: \"gpt-5.4-mini\", name: \"GPT-5.4 Mini\" },\n { id: \"gpt-5.4-nano\", name: \"GPT-5.4 Nano\" },\n { id: \"gpt-5.2\", name: \"GPT-5.2\" },\n { id: \"gpt-5.2-pro\", name: \"GPT-5.2 Pro\" },\n { id: \"gpt-5\", name: \"GPT-5\" },\n { id: \"gpt-5-pro\", name: \"GPT-5 Pro\" },\n { id: \"gpt-5-mini\", name: \"GPT-5 Mini\" },\n { id: \"gpt-5-nano\", name: \"GPT-5 Nano\" },\n { id: \"gpt-4.1\", name: \"GPT-4.1\" },\n { id: \"gpt-4.1-mini\", name: \"GPT-4.1 Mini\" },\n { id: \"gpt-4o\", name: \"GPT-4o\" },\n { id: \"gpt-4o-mini\", name: \"GPT-4o Mini\" },\n {\n id: \"o3-pro\",\n name: \"o3 Pro\",\n deprecated: new Date(\"2026-06-11\"),\n endOfLife: new Date(\"2026-12-11\")\n },\n {\n id: \"o3\",\n name: \"o3\",\n deprecated: new Date(\"2026-06-11\"),\n endOfLife: new Date(\"2026-12-11\")\n },\n {\n id: \"gpt-4.1-nano\",\n name: \"GPT-4.1 Nano\",\n deprecated: new Date(\"2026-04-22\"),\n endOfLife: new Date(\"2026-10-23\")\n },\n {\n id: \"o4-mini\",\n name: \"o4 Mini\",\n deprecated: new Date(\"2026-04-22\"),\n endOfLife: new Date(\"2026-10-23\")\n }\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"],"names":["OPENAI_MODELS","Date","OpenAiSdkFactoryImpl","apiKey","createOpenAI","provider","process","modelId","OpenAiSdkFactory","createImplementation","AiSdkFactoryAbstraction"],"mappings":";;AAIA,MAAMA,gBAA+B;IACjC;QAAE,IAAI;QAAe,MAAM;IAAc;IACzC;QAAE,IAAI;QAAe,MAAM;IAAc;IACzC;QAAE,IAAI;QAAiB,MAAM;IAAgB;IAC7C;QAAE,IAAI;QAAgB,MAAM;IAAe;IAC3C;QAAE,IAAI;QAAW,MAAM;IAAU;IACjC;QAAE,IAAI;QAAe,MAAM;IAAc;IACzC;QAAE,IAAI;QAAW,MAAM;IAAU;IACjC;QAAE,IAAI;QAAe,MAAM;IAAc;IACzC;QAAE,IAAI;QAAgB,MAAM;IAAe;IAC3C;QAAE,IAAI;QAAgB,MAAM;IAAe;IAC3C;QAAE,IAAI;QAAW,MAAM;IAAU;IACjC;QAAE,IAAI;QAAe,MAAM;IAAc;IACzC;QAAE,IAAI;QAAS,MAAM;IAAQ;IAC7B;QAAE,IAAI;QAAa,MAAM;IAAY;IACrC;QAAE,IAAI;QAAc,MAAM;IAAa;IACvC;QAAE,IAAI;QAAc,MAAM;IAAa;IACvC;QAAE,IAAI;QAAW,MAAM;IAAU;IACjC;QAAE,IAAI;QAAgB,MAAM;IAAe;IAC3C;QAAE,IAAI;QAAU,MAAM;IAAS;IAC/B;QAAE,IAAI;QAAe,MAAM;IAAc;IACzC;QACI,IAAI;QACJ,MAAM;QACN,YAAY,IAAIC,KAAK;QACrB,WAAW,IAAIA,KAAK;IACxB;IACA;QACI,IAAI;QACJ,MAAM;QACN,YAAY,IAAIA,KAAK;QACrB,WAAW,IAAIA,KAAK;IACxB;IACA;QACI,IAAI;QACJ,MAAM;QACN,YAAY,IAAIA,KAAK;QACrB,WAAW,IAAIA,KAAK;IACxB;IACA;QACI,IAAI;QACJ,MAAM;QACN,YAAY,IAAIA,KAAK;QACrB,WAAW,IAAIA,KAAK;IACxB;CACH;AAED,MAAMC;IAKF,MAAM,QAAQC,MAAe,EAAmB;QAC5C,MAAM,EAAEC,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC;QACtC,MAAMC,WAAWD,aAAa;YAC1B,QAAQD,UAAUG,QAAQ,GAAG,CAAC,yBAAyB;QAC3D;QACA,OAAO;YACH,eAAeC,CAAAA,UAAWF,SAAS,IAAI,CAACE;QAC5C;IACJ;;aAZS,EAAE,GAAG;aACL,IAAI,GAAG;aACP,MAAM,GAAGP;;AAWtB;AAEO,MAAMQ,mBAAmBC,qBAAqB;IACjD,aAAaC;IACb,gBAAgBR;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TextExtractor, type TextExtractorResult } from "./abstractions.js";
|
|
2
|
+
declare class TextExtractorImpl implements TextExtractor.Interface {
|
|
3
|
+
canExtract(mimeType: string): boolean;
|
|
4
|
+
extract(buffer: Buffer, mimeType: string): Promise<TextExtractorResult>;
|
|
5
|
+
}
|
|
6
|
+
export declare const DefaultTextExtractor: typeof TextExtractorImpl & {
|
|
7
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ITextExtractor>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TextExtractor } from "./abstractions.js";
|
|
2
|
+
import { extractDocxText } from "./parsers/docxParser.js";
|
|
3
|
+
const TEXT_MIME_PREFIX = "text/";
|
|
4
|
+
const SUPPORTED_MIME_TYPES = new Set([
|
|
5
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
6
|
+
"application/json"
|
|
7
|
+
]);
|
|
8
|
+
class TextExtractorImpl {
|
|
9
|
+
canExtract(mimeType) {
|
|
10
|
+
return mimeType.startsWith(TEXT_MIME_PREFIX) || SUPPORTED_MIME_TYPES.has(mimeType);
|
|
11
|
+
}
|
|
12
|
+
async extract(buffer, mimeType) {
|
|
13
|
+
if (mimeType.startsWith(TEXT_MIME_PREFIX) || "application/json" === mimeType) return {
|
|
14
|
+
text: buffer.toString("utf-8")
|
|
15
|
+
};
|
|
16
|
+
if ("application/vnd.openxmlformats-officedocument.wordprocessingml.document" === mimeType) return {
|
|
17
|
+
text: await extractDocxText(buffer)
|
|
18
|
+
};
|
|
19
|
+
throw new Error(`Unsupported MIME type: ${mimeType}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const DefaultTextExtractor = TextExtractor.createImplementation({
|
|
23
|
+
implementation: TextExtractorImpl,
|
|
24
|
+
dependencies: []
|
|
25
|
+
});
|
|
26
|
+
export { DefaultTextExtractor };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=DefaultTextExtractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/TextExtractor/DefaultTextExtractor.js","sources":["../../../../src/features/ai/TextExtractor/DefaultTextExtractor.ts"],"sourcesContent":["import { TextExtractor, type TextExtractorResult } from \"./abstractions.js\";\nimport { extractDocxText } from \"./parsers/docxParser.js\";\n\nconst TEXT_MIME_PREFIX = \"text/\";\n\nconst SUPPORTED_MIME_TYPES = new Set([\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/json\"\n]);\n\nclass TextExtractorImpl implements TextExtractor.Interface {\n canExtract(mimeType: string): boolean {\n return mimeType.startsWith(TEXT_MIME_PREFIX) || SUPPORTED_MIME_TYPES.has(mimeType);\n }\n\n async extract(buffer: Buffer, mimeType: string): Promise<TextExtractorResult> {\n if (mimeType.startsWith(TEXT_MIME_PREFIX) || mimeType === \"application/json\") {\n return { text: buffer.toString(\"utf-8\") };\n }\n\n if (\n mimeType === \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\"\n ) {\n return { text: await extractDocxText(buffer) };\n }\n\n throw new Error(`Unsupported MIME type: ${mimeType}`);\n }\n}\n\nexport const DefaultTextExtractor = TextExtractor.createImplementation({\n implementation: TextExtractorImpl,\n dependencies: []\n});\n"],"names":["TEXT_MIME_PREFIX","SUPPORTED_MIME_TYPES","Set","TextExtractorImpl","mimeType","buffer","extractDocxText","Error","DefaultTextExtractor","TextExtractor"],"mappings":";;AAGA,MAAMA,mBAAmB;AAEzB,MAAMC,uBAAuB,IAAIC,IAAI;IACjC;IACA;CACH;AAED,MAAMC;IACF,WAAWC,QAAgB,EAAW;QAClC,OAAOA,SAAS,UAAU,CAACJ,qBAAqBC,qBAAqB,GAAG,CAACG;IAC7E;IAEA,MAAM,QAAQC,MAAc,EAAED,QAAgB,EAAgC;QAC1E,IAAIA,SAAS,UAAU,CAACJ,qBAAqBI,AAAa,uBAAbA,UACzC,OAAO;YAAE,MAAMC,OAAO,QAAQ,CAAC;QAAS;QAG5C,IACID,AAAa,8EAAbA,UAEA,OAAO;YAAE,MAAM,MAAME,gBAAgBD;QAAQ;QAGjD,MAAM,IAAIE,MAAM,CAAC,uBAAuB,EAAEH,UAAU;IACxD;AACJ;AAEO,MAAMI,uBAAuBC,cAAc,oBAAoB,CAAC;IACnE,gBAAgBN;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface TextExtractorResult {
|
|
2
|
+
text: string;
|
|
3
|
+
}
|
|
4
|
+
export interface ITextExtractor {
|
|
5
|
+
canExtract(mimeType: string): boolean;
|
|
6
|
+
extract(buffer: Buffer, mimeType: string): Promise<TextExtractorResult>;
|
|
7
|
+
}
|
|
8
|
+
export declare const TextExtractor: import("@webiny/di").Abstraction<ITextExtractor>;
|
|
9
|
+
export declare namespace TextExtractor {
|
|
10
|
+
type Interface = ITextExtractor;
|
|
11
|
+
type Result = TextExtractorResult;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/TextExtractor/abstractions.js","sources":["../../../../src/features/ai/TextExtractor/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface TextExtractorResult {\n text: string;\n}\n\nexport interface ITextExtractor {\n canExtract(mimeType: string): boolean;\n extract(buffer: Buffer, mimeType: string): Promise<TextExtractorResult>;\n}\n\nexport const TextExtractor = createAbstraction<ITextExtractor>(\"TextExtractor\");\n\nexport namespace TextExtractor {\n export type Interface = ITextExtractor;\n export type Result = TextExtractorResult;\n}\n"],"names":["TextExtractor","createAbstraction"],"mappings":";AAWO,MAAMA,gBAAgBC,kBAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractDocxText(buffer: Buffer): Promise<string>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { inflateRawSync } from "node:zlib";
|
|
2
|
+
async function extractDocxText(buffer) {
|
|
3
|
+
const xml = extractFileFromZip(buffer, "word/document.xml");
|
|
4
|
+
if (!xml) throw new Error("Invalid DOCX: word/document.xml not found.");
|
|
5
|
+
const stylesXml = extractFileFromZip(buffer, "word/styles.xml");
|
|
6
|
+
const styleMap = stylesXml ? buildStyleMap(stylesXml) : new Map();
|
|
7
|
+
return convertToMarkdown(xml, styleMap);
|
|
8
|
+
}
|
|
9
|
+
function buildStyleMap(stylesXml) {
|
|
10
|
+
const map = new Map();
|
|
11
|
+
const styleRegex = /<w:style\s[^>]*w:styleId="([^"]*)"[^>]*>[\s\S]*?<\/w:style>/g;
|
|
12
|
+
let match;
|
|
13
|
+
while(null !== (match = styleRegex.exec(stylesXml))){
|
|
14
|
+
const styleId = match[1];
|
|
15
|
+
const block = match[0];
|
|
16
|
+
const nameMatch = block.match(/<w:name\s+w:val="([^"]*)"/);
|
|
17
|
+
if (nameMatch) map.set(styleId, nameMatch[1]);
|
|
18
|
+
}
|
|
19
|
+
return map;
|
|
20
|
+
}
|
|
21
|
+
function getHeadingLevel(paragraphXml, styleMap) {
|
|
22
|
+
const styleMatch = paragraphXml.match(/<w:pStyle\s+w:val="([^"]*)"/);
|
|
23
|
+
if (!styleMatch) return 0;
|
|
24
|
+
const styleId = styleMatch[1];
|
|
25
|
+
const directMatch = styleId.match(/^[Hh]eading(\d)$/);
|
|
26
|
+
if (directMatch) return parseInt(directMatch[1], 10);
|
|
27
|
+
const styleName = styleMap.get(styleId) ?? "";
|
|
28
|
+
const nameMatch = styleName.match(/^[Hh]eading\s*(\d)$/);
|
|
29
|
+
if (nameMatch) return parseInt(nameMatch[1], 10);
|
|
30
|
+
if (/title/i.test(styleName) || /title/i.test(styleId)) return 1;
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
function isListItem(paragraphXml) {
|
|
34
|
+
return /<w:numId\s/.test(paragraphXml);
|
|
35
|
+
}
|
|
36
|
+
function extractRunMarkdown(runXml) {
|
|
37
|
+
const textRegex = /<w:t(?:\s[^>]*)?>([^<]*)<\/w:t>/g;
|
|
38
|
+
const texts = [];
|
|
39
|
+
let match;
|
|
40
|
+
while(null !== (match = textRegex.exec(runXml)))texts.push(match[1]);
|
|
41
|
+
if (0 === texts.length) return "";
|
|
42
|
+
const text = texts.join("");
|
|
43
|
+
const isBold = /<w:b[\s/>]/.test(runXml) && !/<w:b\s+w:val="(false|0)"/.test(runXml);
|
|
44
|
+
const isItalic = /<w:i[\s/>]/.test(runXml) && !/<w:i\s+w:val="(false|0)"/.test(runXml);
|
|
45
|
+
if (isBold && isItalic) return `***${text}***`;
|
|
46
|
+
if (isBold) return `**${text}**`;
|
|
47
|
+
if (isItalic) return `*${text}*`;
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
function convertToMarkdown(xml, styleMap) {
|
|
51
|
+
const paragraphs = [];
|
|
52
|
+
const paragraphRegex = /<w:p[\s>][\s\S]*?<\/w:p>/g;
|
|
53
|
+
let paragraphMatch;
|
|
54
|
+
while(null !== (paragraphMatch = paragraphRegex.exec(xml))){
|
|
55
|
+
const paragraphXml = paragraphMatch[0];
|
|
56
|
+
const runRegex = /<w:r[\s>][\s\S]*?<\/w:r>/g;
|
|
57
|
+
const runs = [];
|
|
58
|
+
let runMatch;
|
|
59
|
+
while(null !== (runMatch = runRegex.exec(paragraphXml))){
|
|
60
|
+
const md = extractRunMarkdown(runMatch[0]);
|
|
61
|
+
if (md) runs.push(md);
|
|
62
|
+
}
|
|
63
|
+
if (0 === runs.length) continue;
|
|
64
|
+
let line = runs.join("");
|
|
65
|
+
const headingLevel = getHeadingLevel(paragraphXml, styleMap);
|
|
66
|
+
if (headingLevel > 0 && headingLevel <= 6) line = `${"#".repeat(headingLevel)} ${line}`;
|
|
67
|
+
else if (isListItem(paragraphXml)) line = `- ${line}`;
|
|
68
|
+
paragraphs.push(line);
|
|
69
|
+
}
|
|
70
|
+
return paragraphs.join("\n\n");
|
|
71
|
+
}
|
|
72
|
+
function extractFileFromZip(buffer, targetPath) {
|
|
73
|
+
const eocdOffset = findEocd(buffer);
|
|
74
|
+
if (-1 === eocdOffset) throw new Error("Invalid ZIP: End of Central Directory not found.");
|
|
75
|
+
const cdOffset = buffer.readUInt32LE(eocdOffset + 16);
|
|
76
|
+
const cdSize = buffer.readUInt32LE(eocdOffset + 12);
|
|
77
|
+
const cdEnd = cdOffset + cdSize;
|
|
78
|
+
let offset = cdOffset;
|
|
79
|
+
while(offset < cdEnd){
|
|
80
|
+
const sig = buffer.readUInt32LE(offset);
|
|
81
|
+
if (0x02014b50 !== sig) break;
|
|
82
|
+
const compressionMethod = buffer.readUInt16LE(offset + 10);
|
|
83
|
+
const compressedSize = buffer.readUInt32LE(offset + 20);
|
|
84
|
+
const fileNameLen = buffer.readUInt16LE(offset + 28);
|
|
85
|
+
const extraLen = buffer.readUInt16LE(offset + 30);
|
|
86
|
+
const commentLen = buffer.readUInt16LE(offset + 32);
|
|
87
|
+
const localHeaderOffset = buffer.readUInt32LE(offset + 42);
|
|
88
|
+
const fileName = buffer.toString("utf-8", offset + 46, offset + 46 + fileNameLen);
|
|
89
|
+
if (fileName === targetPath) return readLocalFile(buffer, localHeaderOffset, compressionMethod, compressedSize);
|
|
90
|
+
offset += 46 + fileNameLen + extraLen + commentLen;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
function readLocalFile(buffer, offset, compressionMethod, compressedSize) {
|
|
95
|
+
const sig = buffer.readUInt32LE(offset);
|
|
96
|
+
if (0x04034b50 !== sig) throw new Error("Invalid ZIP: bad local file header.");
|
|
97
|
+
const localFileNameLen = buffer.readUInt16LE(offset + 26);
|
|
98
|
+
const localExtraLen = buffer.readUInt16LE(offset + 28);
|
|
99
|
+
const dataOffset = offset + 30 + localFileNameLen + localExtraLen;
|
|
100
|
+
const raw = buffer.subarray(dataOffset, dataOffset + compressedSize);
|
|
101
|
+
if (0 === compressionMethod) return raw.toString("utf-8");
|
|
102
|
+
if (8 === compressionMethod) return inflateRawSync(raw).toString("utf-8");
|
|
103
|
+
throw new Error(`Unsupported ZIP compression method: ${compressionMethod}`);
|
|
104
|
+
}
|
|
105
|
+
function findEocd(buffer) {
|
|
106
|
+
for(let i = buffer.length - 22; i >= Math.max(0, buffer.length - 65557); i--)if (0x06054b50 === buffer.readUInt32LE(i)) return i;
|
|
107
|
+
return -1;
|
|
108
|
+
}
|
|
109
|
+
export { extractDocxText };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=docxParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/TextExtractor/parsers/docxParser.js","sources":["../../../../../src/features/ai/TextExtractor/parsers/docxParser.ts"],"sourcesContent":["import { inflateRawSync } from \"node:zlib\";\n\nexport async function extractDocxText(buffer: Buffer): Promise<string> {\n const xml = extractFileFromZip(buffer, \"word/document.xml\");\n if (!xml) {\n throw new Error(\"Invalid DOCX: word/document.xml not found.\");\n }\n\n const stylesXml = extractFileFromZip(buffer, \"word/styles.xml\");\n const styleMap = stylesXml ? buildStyleMap(stylesXml) : new Map<string, string>();\n\n return convertToMarkdown(xml, styleMap);\n}\n\nfunction buildStyleMap(stylesXml: string): Map<string, string> {\n const map = new Map<string, string>();\n const styleRegex = /<w:style\\s[^>]*w:styleId=\"([^\"]*)\"[^>]*>[\\s\\S]*?<\\/w:style>/g;\n let match: RegExpExecArray | null;\n\n while ((match = styleRegex.exec(stylesXml)) !== null) {\n const styleId = match[1];\n const block = match[0];\n const nameMatch = block.match(/<w:name\\s+w:val=\"([^\"]*)\"/);\n if (nameMatch) {\n map.set(styleId, nameMatch[1]);\n }\n }\n\n return map;\n}\n\nfunction getHeadingLevel(paragraphXml: string, styleMap: Map<string, string>): number {\n const styleMatch = paragraphXml.match(/<w:pStyle\\s+w:val=\"([^\"]*)\"/);\n if (!styleMatch) {\n return 0;\n }\n\n const styleId = styleMatch[1];\n\n const directMatch = styleId.match(/^[Hh]eading(\\d)$/);\n if (directMatch) {\n return parseInt(directMatch[1], 10);\n }\n\n const styleName = styleMap.get(styleId) ?? \"\";\n const nameMatch = styleName.match(/^[Hh]eading\\s*(\\d)$/);\n if (nameMatch) {\n return parseInt(nameMatch[1], 10);\n }\n\n if (/title/i.test(styleName) || /title/i.test(styleId)) {\n return 1;\n }\n\n return 0;\n}\n\nfunction isListItem(paragraphXml: string): boolean {\n return /<w:numId\\s/.test(paragraphXml);\n}\n\nfunction extractRunMarkdown(runXml: string): string {\n const textRegex = /<w:t(?:\\s[^>]*)?>([^<]*)<\\/w:t>/g;\n const texts: string[] = [];\n let match: RegExpExecArray | null;\n while ((match = textRegex.exec(runXml)) !== null) {\n texts.push(match[1]);\n }\n if (texts.length === 0) {\n return \"\";\n }\n\n const text = texts.join(\"\");\n const isBold = /<w:b[\\s/>]/.test(runXml) && !/<w:b\\s+w:val=\"(false|0)\"/.test(runXml);\n const isItalic = /<w:i[\\s/>]/.test(runXml) && !/<w:i\\s+w:val=\"(false|0)\"/.test(runXml);\n\n if (isBold && isItalic) {\n return `***${text}***`;\n }\n if (isBold) {\n return `**${text}**`;\n }\n if (isItalic) {\n return `*${text}*`;\n }\n return text;\n}\n\nfunction convertToMarkdown(xml: string, styleMap: Map<string, string>): string {\n const paragraphs: string[] = [];\n const paragraphRegex = /<w:p[\\s>][\\s\\S]*?<\\/w:p>/g;\n let paragraphMatch: RegExpExecArray | null;\n\n while ((paragraphMatch = paragraphRegex.exec(xml)) !== null) {\n const paragraphXml = paragraphMatch[0];\n\n const runRegex = /<w:r[\\s>][\\s\\S]*?<\\/w:r>/g;\n const runs: string[] = [];\n let runMatch: RegExpExecArray | null;\n while ((runMatch = runRegex.exec(paragraphXml)) !== null) {\n const md = extractRunMarkdown(runMatch[0]);\n if (md) {\n runs.push(md);\n }\n }\n\n if (runs.length === 0) {\n continue;\n }\n\n let line = runs.join(\"\");\n const headingLevel = getHeadingLevel(paragraphXml, styleMap);\n\n if (headingLevel > 0 && headingLevel <= 6) {\n line = `${\"#\".repeat(headingLevel)} ${line}`;\n } else if (isListItem(paragraphXml)) {\n line = `- ${line}`;\n }\n\n paragraphs.push(line);\n }\n\n return paragraphs.join(\"\\n\\n\");\n}\n\n// --- ZIP utilities (unchanged) ---\n\nfunction extractFileFromZip(buffer: Buffer, targetPath: string): string | null {\n const eocdOffset = findEocd(buffer);\n if (eocdOffset === -1) {\n throw new Error(\"Invalid ZIP: End of Central Directory not found.\");\n }\n\n const cdOffset = buffer.readUInt32LE(eocdOffset + 16);\n const cdSize = buffer.readUInt32LE(eocdOffset + 12);\n const cdEnd = cdOffset + cdSize;\n let offset = cdOffset;\n\n while (offset < cdEnd) {\n const sig = buffer.readUInt32LE(offset);\n if (sig !== 0x02014b50) {\n break;\n }\n\n const compressionMethod = buffer.readUInt16LE(offset + 10);\n const compressedSize = buffer.readUInt32LE(offset + 20);\n const fileNameLen = buffer.readUInt16LE(offset + 28);\n const extraLen = buffer.readUInt16LE(offset + 30);\n const commentLen = buffer.readUInt16LE(offset + 32);\n const localHeaderOffset = buffer.readUInt32LE(offset + 42);\n const fileName = buffer.toString(\"utf-8\", offset + 46, offset + 46 + fileNameLen);\n\n if (fileName === targetPath) {\n return readLocalFile(buffer, localHeaderOffset, compressionMethod, compressedSize);\n }\n\n offset += 46 + fileNameLen + extraLen + commentLen;\n }\n\n return null;\n}\n\nfunction readLocalFile(\n buffer: Buffer,\n offset: number,\n compressionMethod: number,\n compressedSize: number\n): string {\n const sig = buffer.readUInt32LE(offset);\n if (sig !== 0x04034b50) {\n throw new Error(\"Invalid ZIP: bad local file header.\");\n }\n\n const localFileNameLen = buffer.readUInt16LE(offset + 26);\n const localExtraLen = buffer.readUInt16LE(offset + 28);\n const dataOffset = offset + 30 + localFileNameLen + localExtraLen;\n\n const raw = buffer.subarray(dataOffset, dataOffset + compressedSize);\n\n if (compressionMethod === 0) {\n return raw.toString(\"utf-8\");\n }\n\n if (compressionMethod === 8) {\n return inflateRawSync(raw).toString(\"utf-8\");\n }\n\n throw new Error(`Unsupported ZIP compression method: ${compressionMethod}`);\n}\n\nfunction findEocd(buffer: Buffer): number {\n for (let i = buffer.length - 22; i >= Math.max(0, buffer.length - 65557); i--) {\n if (buffer.readUInt32LE(i) === 0x06054b50) {\n return i;\n }\n }\n return -1;\n}\n"],"names":["extractDocxText","buffer","xml","extractFileFromZip","Error","stylesXml","styleMap","buildStyleMap","Map","convertToMarkdown","map","styleRegex","match","styleId","block","nameMatch","getHeadingLevel","paragraphXml","styleMatch","directMatch","parseInt","styleName","isListItem","extractRunMarkdown","runXml","textRegex","texts","text","isBold","isItalic","paragraphs","paragraphRegex","paragraphMatch","runRegex","runs","runMatch","md","line","headingLevel","targetPath","eocdOffset","findEocd","cdOffset","cdSize","cdEnd","offset","sig","compressionMethod","compressedSize","fileNameLen","extraLen","commentLen","localHeaderOffset","fileName","readLocalFile","localFileNameLen","localExtraLen","dataOffset","raw","inflateRawSync","i","Math"],"mappings":"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"}
|
|
@@ -5,6 +5,8 @@ import type { FlexibleSchema, ToolSet } from "ai";
|
|
|
5
5
|
export interface IAiSdkModel {
|
|
6
6
|
id: string;
|
|
7
7
|
name: string;
|
|
8
|
+
deprecated?: Date;
|
|
9
|
+
endOfLife?: Date;
|
|
8
10
|
}
|
|
9
11
|
export interface IAiSdk {
|
|
10
12
|
languageModel(modelId: string): LanguageModel;
|
|
@@ -55,6 +57,8 @@ export interface AiModel {
|
|
|
55
57
|
providerName: string;
|
|
56
58
|
modelId: string;
|
|
57
59
|
modelName: string;
|
|
60
|
+
deprecated: Date | undefined;
|
|
61
|
+
endOfLife: Date | undefined;
|
|
58
62
|
}
|
|
59
63
|
export interface IAi {
|
|
60
64
|
generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/abstractions.js","sources":["../../../src/features/ai/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { generateText } from \"ai\";\nimport type { streamText } from \"ai\";\nimport type { LanguageModel } from \"ai\";\nimport type { FlexibleSchema, ToolSet } from \"ai\";\n\n// AiSdk\n\nexport interface IAiSdkModel {\n id: string; // raw model id, e.g. \"claude-sonnet-4-5\"\n name: string; // human-friendly name, e.g. \"Claude Sonnet 4.5\"\n}\n\nexport interface IAiSdk {\n languageModel(modelId: string): LanguageModel;\n}\n\n/** A single AI SDK instance (e.g. OpenAI, Anthropic) that resolves model instances. */\nexport const AiSdk = createAbstraction<IAiSdk>(\"AiSdk\");\n\nexport namespace AiSdk {\n export type Interface = IAiSdk;\n}\n\n// AiSdkFactory\n\nexport interface IAiSdkFactory {\n readonly id: string; // machine id, e.g. \"anthropic\"\n readonly name: string; // human-friendly name, e.g. \"Anthropic\"\n readonly models: readonly IAiSdkModel[]; // static model list, no API call needed\n execute(apiKey?: string): Promise<IAiSdk>;\n}\n\n/** Factory that asynchronously initialises an AI SDK. Register one per provider namespace. */\nexport const AiSdkFactory = createAbstraction<IAiSdkFactory>(\"AiSdkFactory\");\n\nexport namespace AiSdkFactory {\n export type Interface = IAiSdkFactory;\n}\n\n// AiConnection\n\nexport interface IAiConnectionInline {\n readonly sdkName: string;\n readonly apiKey?: string;\n}\n\nexport interface IAiConnection extends IAiConnectionInline {\n readonly id: string;\n}\n\n// AiConnectionFactory\n\nexport interface IAiConnectionFactory {\n execute(): Promise<IAiConnection>;\n}\n\n/** Factory that asynchronously produces an AiConnection. */\nexport const AiConnectionFactory = createAbstraction<IAiConnectionFactory>(\"AiConnectionFactory\");\n\nexport namespace AiConnectionFactory {\n export type Interface = IAiConnectionFactory;\n}\n\n// Ai\n\ntype SDKGenerateTextParams = Parameters<typeof generateText>[0];\ntype SDKStreamTextParams = Parameters<typeof streamText>[0];\n\nexport type AiGenerateTextParams = Omit<SDKGenerateTextParams, \"model\"> & {\n model: string;\n connection?: string | IAiConnectionInline;\n};\nexport type AiStreamTextParams = Omit<SDKStreamTextParams, \"model\"> & {\n model: string;\n connection?: string | IAiConnectionInline;\n};\n\nexport interface AiModel {\n providerId: string; // e.g. \"anthropic\"\n providerName: string; // e.g. \"Anthropic\"\n modelId: string; // e.g. \"claude-sonnet-4-5\"\n modelName: string; // e.g. \"Claude Sonnet 4.5\"\n}\n\nexport interface IAi {\n generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;\n streamText(params: AiStreamTextParams): Promise<ReturnType<typeof streamText>>;\n listModels(): Promise<AiModel[]>;\n listModelsByConnections(): Promise<AiModel[]>;\n listModelsByConnection(connection: string | IAiConnectionInline): Promise<AiModel[]>;\n}\n\n/** Interact with AI language models using registered providers. */\nexport const Ai = createAbstraction<IAi>(\"Ai\");\n\nexport namespace Ai {\n export type Interface = IAi;\n export type GenerateTextParams = AiGenerateTextParams;\n export type StreamTextParams = AiStreamTextParams;\n}\n\n// AiModelRegistry\n\nexport interface IAiModelRegistry {\n listModels(): Promise<AiModel[]>;\n}\n\n/** Single source of truth for available AI models. Decoratable to restrict the model list. */\nexport const AiModelRegistry = createAbstraction<IAiModelRegistry>(\"AiModelRegistry\");\n\nexport namespace AiModelRegistry {\n export type Interface = IAiModelRegistry;\n}\n\n// AiSdkTool\n\nexport interface IAiSdkTool<TInput = any> {\n readonly name: string;\n readonly description: string;\n readonly inputSchema: FlexibleSchema<TInput>;\n execute(input: TInput): Promise<unknown>;\n}\n\n/** A single tool that can be provided to AI generateText/streamText calls. */\nexport const AiSdkTool = createAbstraction<IAiSdkTool>(\"AiSdkTool\");\n\nexport namespace AiSdkTool {\n export type Interface = IAiSdkTool;\n}\n\n// AiSdkTools\n\nexport interface IAiSdkTools {\n getToolSet(): ToolSet;\n}\n\n/** Collection of AI SDK tools. Returns a ready-to-use ToolSet for generateText/streamText. */\nexport const AiSdkTools = createAbstraction<IAiSdkTools>(\"AiSdkTools\");\n\nexport namespace AiSdkTools {\n export type Interface = IAiSdkTools;\n}\n"],"names":["AiSdk","createAbstraction","AiSdkFactory","AiConnectionFactory","Ai","AiModelRegistry","AiSdkTool","AiSdkTools"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/ai/abstractions.js","sources":["../../../src/features/ai/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { generateText } from \"ai\";\nimport type { streamText } from \"ai\";\nimport type { LanguageModel } from \"ai\";\nimport type { FlexibleSchema, ToolSet } from \"ai\";\n\n// AiSdk\n\nexport interface IAiSdkModel {\n id: string; // raw model id, e.g. \"claude-sonnet-4-5\"\n name: string; // human-friendly name, e.g. \"Claude Sonnet 4.5\"\n deprecated?: Date;\n endOfLife?: Date;\n}\n\nexport interface IAiSdk {\n languageModel(modelId: string): LanguageModel;\n}\n\n/** A single AI SDK instance (e.g. OpenAI, Anthropic) that resolves model instances. */\nexport const AiSdk = createAbstraction<IAiSdk>(\"AiSdk\");\n\nexport namespace AiSdk {\n export type Interface = IAiSdk;\n}\n\n// AiSdkFactory\n\nexport interface IAiSdkFactory {\n readonly id: string; // machine id, e.g. \"anthropic\"\n readonly name: string; // human-friendly name, e.g. \"Anthropic\"\n readonly models: readonly IAiSdkModel[]; // static model list, no API call needed\n execute(apiKey?: string): Promise<IAiSdk>;\n}\n\n/** Factory that asynchronously initialises an AI SDK. Register one per provider namespace. */\nexport const AiSdkFactory = createAbstraction<IAiSdkFactory>(\"AiSdkFactory\");\n\nexport namespace AiSdkFactory {\n export type Interface = IAiSdkFactory;\n}\n\n// AiConnection\n\nexport interface IAiConnectionInline {\n readonly sdkName: string;\n readonly apiKey?: string;\n}\n\nexport interface IAiConnection extends IAiConnectionInline {\n readonly id: string;\n}\n\n// AiConnectionFactory\n\nexport interface IAiConnectionFactory {\n execute(): Promise<IAiConnection>;\n}\n\n/** Factory that asynchronously produces an AiConnection. */\nexport const AiConnectionFactory = createAbstraction<IAiConnectionFactory>(\"AiConnectionFactory\");\n\nexport namespace AiConnectionFactory {\n export type Interface = IAiConnectionFactory;\n}\n\n// Ai\n\ntype SDKGenerateTextParams = Parameters<typeof generateText>[0];\ntype SDKStreamTextParams = Parameters<typeof streamText>[0];\n\nexport type AiGenerateTextParams = Omit<SDKGenerateTextParams, \"model\"> & {\n model: string;\n connection?: string | IAiConnectionInline;\n};\nexport type AiStreamTextParams = Omit<SDKStreamTextParams, \"model\"> & {\n model: string;\n connection?: string | IAiConnectionInline;\n};\n\nexport interface AiModel {\n providerId: string; // e.g. \"anthropic\"\n providerName: string; // e.g. \"Anthropic\"\n modelId: string; // e.g. \"claude-sonnet-4-5\"\n modelName: string; // e.g. \"Claude Sonnet 4.5\"\n deprecated: Date | undefined;\n endOfLife: Date | undefined;\n}\n\nexport interface IAi {\n generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;\n streamText(params: AiStreamTextParams): Promise<ReturnType<typeof streamText>>;\n listModels(): Promise<AiModel[]>;\n listModelsByConnections(): Promise<AiModel[]>;\n listModelsByConnection(connection: string | IAiConnectionInline): Promise<AiModel[]>;\n}\n\n/** Interact with AI language models using registered providers. */\nexport const Ai = createAbstraction<IAi>(\"Ai\");\n\nexport namespace Ai {\n export type Interface = IAi;\n export type GenerateTextParams = AiGenerateTextParams;\n export type StreamTextParams = AiStreamTextParams;\n}\n\n// AiModelRegistry\n\nexport interface IAiModelRegistry {\n listModels(): Promise<AiModel[]>;\n}\n\n/** Single source of truth for available AI models. Decoratable to restrict the model list. */\nexport const AiModelRegistry = createAbstraction<IAiModelRegistry>(\"AiModelRegistry\");\n\nexport namespace AiModelRegistry {\n export type Interface = IAiModelRegistry;\n}\n\n// AiSdkTool\n\nexport interface IAiSdkTool<TInput = any> {\n readonly name: string;\n readonly description: string;\n readonly inputSchema: FlexibleSchema<TInput>;\n execute(input: TInput): Promise<unknown>;\n}\n\n/** A single tool that can be provided to AI generateText/streamText calls. */\nexport const AiSdkTool = createAbstraction<IAiSdkTool>(\"AiSdkTool\");\n\nexport namespace AiSdkTool {\n export type Interface = IAiSdkTool;\n}\n\n// AiSdkTools\n\nexport interface IAiSdkTools {\n getToolSet(): ToolSet;\n}\n\n/** Collection of AI SDK tools. Returns a ready-to-use ToolSet for generateText/streamText. */\nexport const AiSdkTools = createAbstraction<IAiSdkTools>(\"AiSdkTools\");\n\nexport namespace AiSdkTools {\n export type Interface = IAiSdkTools;\n}\n"],"names":["AiSdk","createAbstraction","AiSdkFactory","AiConnectionFactory","Ai","AiModelRegistry","AiSdkTool","AiSdkTools"],"mappings":";AAoBO,MAAMA,QAAQC,kBAA0B;AAgBxC,MAAMC,eAAeD,kBAAiC;AAwBtD,MAAME,sBAAsBF,kBAAwC;AAsCpE,MAAMG,KAAKH,kBAAuB;AAelC,MAAMI,kBAAkBJ,kBAAoC;AAgB5D,MAAMK,YAAYL,kBAA8B;AAahD,MAAMM,aAAaN,kBAA+B"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DomainEvent } from "../../features/eventPublisher/index.js";
|
|
2
|
+
import type { IEventHandler } from "../../features/eventPublisher/index.js";
|
|
3
|
+
import type { AiGenerateTextParams, AiStreamTextParams } from "./abstractions.js";
|
|
4
|
+
import type { generateText } from "ai";
|
|
5
|
+
export interface AiBeforeGenerateTextPayload {
|
|
6
|
+
requestId: string;
|
|
7
|
+
params: AiGenerateTextParams;
|
|
8
|
+
}
|
|
9
|
+
export declare class AiBeforeGenerateTextEvent extends DomainEvent<AiBeforeGenerateTextPayload> {
|
|
10
|
+
eventType: "ai.beforeGenerateText";
|
|
11
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<AiBeforeGenerateTextEvent>>;
|
|
12
|
+
}
|
|
13
|
+
export declare const AiBeforeGenerateTextEventHandler: import("@webiny/di").Abstraction<IEventHandler<AiBeforeGenerateTextEvent>>;
|
|
14
|
+
export declare namespace AiBeforeGenerateTextEventHandler {
|
|
15
|
+
type Interface = IEventHandler<AiBeforeGenerateTextEvent>;
|
|
16
|
+
type Event = AiBeforeGenerateTextEvent;
|
|
17
|
+
}
|
|
18
|
+
export interface AiAfterGenerateTextPayload {
|
|
19
|
+
requestId: string;
|
|
20
|
+
params: AiGenerateTextParams;
|
|
21
|
+
result: Awaited<ReturnType<typeof generateText>>;
|
|
22
|
+
duration: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class AiAfterGenerateTextEvent extends DomainEvent<AiAfterGenerateTextPayload> {
|
|
25
|
+
eventType: "ai.afterGenerateText";
|
|
26
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<AiAfterGenerateTextEvent>>;
|
|
27
|
+
}
|
|
28
|
+
export declare const AiAfterGenerateTextEventHandler: import("@webiny/di").Abstraction<IEventHandler<AiAfterGenerateTextEvent>>;
|
|
29
|
+
export declare namespace AiAfterGenerateTextEventHandler {
|
|
30
|
+
type Interface = IEventHandler<AiAfterGenerateTextEvent>;
|
|
31
|
+
type Event = AiAfterGenerateTextEvent;
|
|
32
|
+
}
|
|
33
|
+
export interface AiGenerateTextErrorPayload {
|
|
34
|
+
requestId: string;
|
|
35
|
+
params: AiGenerateTextParams;
|
|
36
|
+
error: Error;
|
|
37
|
+
duration: number;
|
|
38
|
+
}
|
|
39
|
+
export declare class AiGenerateTextErrorEvent extends DomainEvent<AiGenerateTextErrorPayload> {
|
|
40
|
+
eventType: "ai.generateTextError";
|
|
41
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<AiGenerateTextErrorEvent>>;
|
|
42
|
+
}
|
|
43
|
+
export declare const AiGenerateTextErrorEventHandler: import("@webiny/di").Abstraction<IEventHandler<AiGenerateTextErrorEvent>>;
|
|
44
|
+
export declare namespace AiGenerateTextErrorEventHandler {
|
|
45
|
+
type Interface = IEventHandler<AiGenerateTextErrorEvent>;
|
|
46
|
+
type Event = AiGenerateTextErrorEvent;
|
|
47
|
+
}
|
|
48
|
+
export interface AiBeforeStreamTextPayload {
|
|
49
|
+
params: AiStreamTextParams;
|
|
50
|
+
}
|
|
51
|
+
export declare class AiBeforeStreamTextEvent extends DomainEvent<AiBeforeStreamTextPayload> {
|
|
52
|
+
eventType: "ai.beforeStreamText";
|
|
53
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<IEventHandler<AiBeforeStreamTextEvent>>;
|
|
54
|
+
}
|
|
55
|
+
export declare const AiBeforeStreamTextEventHandler: import("@webiny/di").Abstraction<IEventHandler<AiBeforeStreamTextEvent>>;
|
|
56
|
+
export declare namespace AiBeforeStreamTextEventHandler {
|
|
57
|
+
type Interface = IEventHandler<AiBeforeStreamTextEvent>;
|
|
58
|
+
type Event = AiBeforeStreamTextEvent;
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
import { DomainEvent } from "../eventPublisher/index.js";
|
|
3
|
+
class AiBeforeGenerateTextEvent extends DomainEvent {
|
|
4
|
+
getHandlerAbstraction() {
|
|
5
|
+
return AiBeforeGenerateTextEventHandler;
|
|
6
|
+
}
|
|
7
|
+
constructor(...args){
|
|
8
|
+
super(...args), this.eventType = "ai.beforeGenerateText";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const AiBeforeGenerateTextEventHandler = createAbstraction("AiBeforeGenerateTextEventHandler");
|
|
12
|
+
class AiAfterGenerateTextEvent extends DomainEvent {
|
|
13
|
+
getHandlerAbstraction() {
|
|
14
|
+
return AiAfterGenerateTextEventHandler;
|
|
15
|
+
}
|
|
16
|
+
constructor(...args){
|
|
17
|
+
super(...args), this.eventType = "ai.afterGenerateText";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const AiAfterGenerateTextEventHandler = createAbstraction("AiAfterGenerateTextEventHandler");
|
|
21
|
+
class AiGenerateTextErrorEvent extends DomainEvent {
|
|
22
|
+
getHandlerAbstraction() {
|
|
23
|
+
return AiGenerateTextErrorEventHandler;
|
|
24
|
+
}
|
|
25
|
+
constructor(...args){
|
|
26
|
+
super(...args), this.eventType = "ai.generateTextError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const AiGenerateTextErrorEventHandler = createAbstraction("AiGenerateTextErrorEventHandler");
|
|
30
|
+
class AiBeforeStreamTextEvent extends DomainEvent {
|
|
31
|
+
getHandlerAbstraction() {
|
|
32
|
+
return AiBeforeStreamTextEventHandler;
|
|
33
|
+
}
|
|
34
|
+
constructor(...args){
|
|
35
|
+
super(...args), this.eventType = "ai.beforeStreamText";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const AiBeforeStreamTextEventHandler = createAbstraction("AiBeforeStreamTextEventHandler");
|
|
39
|
+
export { AiAfterGenerateTextEvent, AiAfterGenerateTextEventHandler, AiBeforeGenerateTextEvent, AiBeforeGenerateTextEventHandler, AiBeforeStreamTextEvent, AiBeforeStreamTextEventHandler, AiGenerateTextErrorEvent, AiGenerateTextErrorEventHandler };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/events.js","sources":["../../../src/features/ai/events.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { DomainEvent } from \"~/features/eventPublisher/index.js\";\nimport type { IEventHandler } from \"~/features/eventPublisher/index.js\";\nimport type { AiGenerateTextParams, AiStreamTextParams } from \"./abstractions.js\";\nimport type { generateText } from \"ai\";\n\n// ============================================================================\n// BeforeGenerateText\n// ============================================================================\n\nexport interface AiBeforeGenerateTextPayload {\n requestId: string;\n params: AiGenerateTextParams;\n}\n\nexport class AiBeforeGenerateTextEvent extends DomainEvent<AiBeforeGenerateTextPayload> {\n eventType = \"ai.beforeGenerateText\" as const;\n\n getHandlerAbstraction() {\n return AiBeforeGenerateTextEventHandler;\n }\n}\n\nexport const AiBeforeGenerateTextEventHandler = createAbstraction<\n IEventHandler<AiBeforeGenerateTextEvent>\n>(\"AiBeforeGenerateTextEventHandler\");\n\nexport namespace AiBeforeGenerateTextEventHandler {\n export type Interface = IEventHandler<AiBeforeGenerateTextEvent>;\n export type Event = AiBeforeGenerateTextEvent;\n}\n\n// ============================================================================\n// AfterGenerateText\n// ============================================================================\n\nexport interface AiAfterGenerateTextPayload {\n requestId: string;\n params: AiGenerateTextParams;\n result: Awaited<ReturnType<typeof generateText>>;\n duration: number;\n}\n\nexport class AiAfterGenerateTextEvent extends DomainEvent<AiAfterGenerateTextPayload> {\n eventType = \"ai.afterGenerateText\" as const;\n\n getHandlerAbstraction() {\n return AiAfterGenerateTextEventHandler;\n }\n}\n\nexport const AiAfterGenerateTextEventHandler = createAbstraction<\n IEventHandler<AiAfterGenerateTextEvent>\n>(\"AiAfterGenerateTextEventHandler\");\n\nexport namespace AiAfterGenerateTextEventHandler {\n export type Interface = IEventHandler<AiAfterGenerateTextEvent>;\n export type Event = AiAfterGenerateTextEvent;\n}\n\n// ============================================================================\n// GenerateTextError\n// ============================================================================\n\nexport interface AiGenerateTextErrorPayload {\n requestId: string;\n params: AiGenerateTextParams;\n error: Error;\n duration: number;\n}\n\nexport class AiGenerateTextErrorEvent extends DomainEvent<AiGenerateTextErrorPayload> {\n eventType = \"ai.generateTextError\" as const;\n\n getHandlerAbstraction() {\n return AiGenerateTextErrorEventHandler;\n }\n}\n\nexport const AiGenerateTextErrorEventHandler = createAbstraction<\n IEventHandler<AiGenerateTextErrorEvent>\n>(\"AiGenerateTextErrorEventHandler\");\n\nexport namespace AiGenerateTextErrorEventHandler {\n export type Interface = IEventHandler<AiGenerateTextErrorEvent>;\n export type Event = AiGenerateTextErrorEvent;\n}\n\n// ============================================================================\n// BeforeStreamText\n// ============================================================================\n\nexport interface AiBeforeStreamTextPayload {\n params: AiStreamTextParams;\n}\n\nexport class AiBeforeStreamTextEvent extends DomainEvent<AiBeforeStreamTextPayload> {\n eventType = \"ai.beforeStreamText\" as const;\n\n getHandlerAbstraction() {\n return AiBeforeStreamTextEventHandler;\n }\n}\n\nexport const AiBeforeStreamTextEventHandler = createAbstraction<\n IEventHandler<AiBeforeStreamTextEvent>\n>(\"AiBeforeStreamTextEventHandler\");\n\nexport namespace AiBeforeStreamTextEventHandler {\n export type Interface = IEventHandler<AiBeforeStreamTextEvent>;\n export type Event = AiBeforeStreamTextEvent;\n}\n"],"names":["AiBeforeGenerateTextEvent","DomainEvent","AiBeforeGenerateTextEventHandler","createAbstraction","AiAfterGenerateTextEvent","AiAfterGenerateTextEventHandler","AiGenerateTextErrorEvent","AiGenerateTextErrorEventHandler","AiBeforeStreamTextEvent","AiBeforeStreamTextEventHandler"],"mappings":";;AAeO,MAAMA,kCAAkCC;IAG3C,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,mCAAmCC,kBAE9C;AAkBK,MAAMC,iCAAiCH;IAG1C,wBAAwB;QACpB,OAAOI;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,kCAAkCF,kBAE7C;AAkBK,MAAMG,iCAAiCL;IAG1C,wBAAwB;QACpB,OAAOM;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,kCAAkCJ,kBAE7C;AAeK,MAAMK,gCAAgCP;IAGzC,wBAAwB;QACpB,OAAOQ;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,iCAAiCN,kBAE5C"}
|
package/features/ai/feature.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { OpenAiSdkFactory } from "./OpenAiSdkFactory.js";
|
|
3
3
|
import { AnthropicSdkFactory } from "./AnthropicSdkFactory.js";
|
|
4
|
+
import { GoogleSdkFactory } from "./GoogleSdkFactory.js";
|
|
4
5
|
import { Ai } from "./Ai.js";
|
|
5
6
|
import { AiModelRegistry } from "./AiModelRegistry.js";
|
|
6
7
|
import { AiSdkTools } from "./AiSdkTools.js";
|
|
8
|
+
import { AiOutputToolRegistry } from "./toolPipeline/AiOutputToolRegistry.js";
|
|
9
|
+
import { AiToolPipelineRunner } from "./toolPipeline/AiToolPipelineRunner.js";
|
|
10
|
+
import { DefaultTextExtractor } from "./TextExtractor/DefaultTextExtractor.js";
|
|
7
11
|
const AiFeature = createFeature({
|
|
8
12
|
name: "AiFeature",
|
|
9
13
|
register (container) {
|
|
10
14
|
container.register(OpenAiSdkFactory);
|
|
11
15
|
container.register(AnthropicSdkFactory);
|
|
12
|
-
container.register(
|
|
16
|
+
container.register(GoogleSdkFactory);
|
|
13
17
|
container.register(Ai);
|
|
18
|
+
container.register(AiModelRegistry);
|
|
14
19
|
container.register(AiSdkTools);
|
|
20
|
+
container.register(AiOutputToolRegistry);
|
|
21
|
+
container.register(AiToolPipelineRunner);
|
|
22
|
+
container.register(DefaultTextExtractor);
|
|
15
23
|
}
|
|
16
24
|
});
|
|
17
25
|
export { AiFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { OpenAiSdkFactory } from \"./OpenAiSdkFactory.js\";\nimport { AnthropicSdkFactory } from \"./AnthropicSdkFactory.js\";\nimport { Ai } from \"./Ai.js\";\nimport { AiModelRegistry } from \"./AiModelRegistry.js\";\nimport { AiSdkTools } from \"./AiSdkTools.js\";\n\nexport const AiFeature = createFeature({\n name: \"AiFeature\",\n register(container) {\n container.register(OpenAiSdkFactory);\n container.register(AnthropicSdkFactory);\n container.register(
|
|
1
|
+
{"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { OpenAiSdkFactory } from \"./OpenAiSdkFactory.js\";\nimport { AnthropicSdkFactory } from \"./AnthropicSdkFactory.js\";\nimport { GoogleSdkFactory } from \"./GoogleSdkFactory.js\";\nimport { Ai } from \"./Ai.js\";\nimport { AiModelRegistry } from \"./AiModelRegistry.js\";\nimport { AiSdkTools } from \"./AiSdkTools.js\";\nimport { AiOutputToolRegistry } from \"./toolPipeline/AiOutputToolRegistry.js\";\nimport { AiToolPipelineRunner } from \"./toolPipeline/AiToolPipelineRunner.js\";\nimport { DefaultTextExtractor } from \"./TextExtractor/DefaultTextExtractor.js\";\n\nexport const AiFeature = createFeature({\n name: \"AiFeature\",\n register(container) {\n container.register(OpenAiSdkFactory);\n container.register(AnthropicSdkFactory);\n container.register(GoogleSdkFactory);\n container.register(Ai);\n container.register(AiModelRegistry);\n container.register(AiSdkTools);\n container.register(AiOutputToolRegistry);\n container.register(AiToolPipelineRunner);\n container.register(DefaultTextExtractor);\n }\n});\n"],"names":["AiFeature","createFeature","container","OpenAiSdkFactory","AnthropicSdkFactory","GoogleSdkFactory","Ai","AiModelRegistry","AiSdkTools","AiOutputToolRegistry","AiToolPipelineRunner","DefaultTextExtractor"],"mappings":";;;;;;;;;;AAWO,MAAMA,YAAYC,cAAc;IACnC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;IACvB;AACJ"}
|
package/features/ai/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export { AiSdk, AiSdkFactory, AiConnectionFactory, Ai, AiModelRegistry, AiSdkTool, AiSdkTools } from "./abstractions.js";
|
|
2
|
-
export type { IAiConnection, IAiConnectionInline, AiModel,
|
|
2
|
+
export type { IAiConnection, IAiConnectionInline, AiModel, IAiSdkModel, IAiModelRegistry, IAiSdkTool, IAiSdkTools } from "./abstractions.js";
|
|
3
|
+
export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner } from "./toolPipeline/index.js";
|
|
4
|
+
export type { IAiOutputTool, IAiOutputToolRegistry, IAiToolPipelineRunner } from "./toolPipeline/index.js";
|
|
5
|
+
export { TextExtractor, DefaultTextExtractor } from "./TextExtractor/index.js";
|
|
6
|
+
export type { ITextExtractor, TextExtractorResult } from "./TextExtractor/index.js";
|
|
7
|
+
export { AiBeforeGenerateTextEvent, AiBeforeGenerateTextEventHandler, AiAfterGenerateTextEvent, AiAfterGenerateTextEventHandler, AiGenerateTextErrorEvent, AiGenerateTextErrorEventHandler, AiBeforeStreamTextEvent, AiBeforeStreamTextEventHandler } from "./events.js";
|
|
8
|
+
export type { AiBeforeGenerateTextPayload, AiAfterGenerateTextPayload, AiGenerateTextErrorPayload, AiBeforeStreamTextPayload } from "./events.js";
|
|
3
9
|
export { AiFeature } from "./feature.js";
|
package/features/ai/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { Ai, AiConnectionFactory, AiModelRegistry, AiSdk, AiSdkFactory, AiSdkTool, AiSdkTools } from "./abstractions.js";
|
|
2
|
+
export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner } from "./toolPipeline/index.js";
|
|
3
|
+
export { DefaultTextExtractor, TextExtractor } from "./TextExtractor/index.js";
|
|
4
|
+
export { AiAfterGenerateTextEvent, AiAfterGenerateTextEventHandler, AiBeforeGenerateTextEvent, AiBeforeGenerateTextEventHandler, AiBeforeStreamTextEvent, AiBeforeStreamTextEventHandler, AiGenerateTextErrorEvent, AiGenerateTextErrorEventHandler } from "./events.js";
|
|
2
5
|
export { AiFeature } from "./feature.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IAiOutputTool, type IAiOutputToolRegistry } from "./abstractions.js";
|
|
2
|
+
declare class AiOutputToolRegistryImpl implements IAiOutputToolRegistry {
|
|
3
|
+
private toolMap;
|
|
4
|
+
constructor(tools: IAiOutputTool[]);
|
|
5
|
+
has(name: string): boolean;
|
|
6
|
+
invoke(name: string, params: Record<string, unknown>): Promise<unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare const AiOutputToolRegistry: typeof AiOutputToolRegistryImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<IAiOutputToolRegistry>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AiOutputTool, AiOutputToolRegistry } from "./abstractions.js";
|
|
2
|
+
class AiOutputToolRegistryImpl {
|
|
3
|
+
constructor(tools){
|
|
4
|
+
this.toolMap = new Map(tools.map((t)=>[
|
|
5
|
+
t.name,
|
|
6
|
+
t
|
|
7
|
+
]));
|
|
8
|
+
}
|
|
9
|
+
has(name) {
|
|
10
|
+
return this.toolMap.has(name);
|
|
11
|
+
}
|
|
12
|
+
async invoke(name, params) {
|
|
13
|
+
const tool = this.toolMap.get(name);
|
|
14
|
+
if (!tool) return;
|
|
15
|
+
return tool.execute(params);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const AiOutputToolRegistry_AiOutputToolRegistry = AiOutputToolRegistry.createImplementation({
|
|
19
|
+
implementation: AiOutputToolRegistryImpl,
|
|
20
|
+
dependencies: [
|
|
21
|
+
[
|
|
22
|
+
AiOutputTool,
|
|
23
|
+
{
|
|
24
|
+
multiple: true
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
export { AiOutputToolRegistry_AiOutputToolRegistry as AiOutputToolRegistry };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=AiOutputToolRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/ai/toolPipeline/AiOutputToolRegistry.js","sources":["../../../../src/features/ai/toolPipeline/AiOutputToolRegistry.ts"],"sourcesContent":["import {\n AiOutputTool,\n AiOutputToolRegistry as Abstraction,\n type IAiOutputTool,\n type IAiOutputToolRegistry\n} from \"./abstractions.js\";\n\nclass AiOutputToolRegistryImpl implements IAiOutputToolRegistry {\n private toolMap: Map<string, IAiOutputTool>;\n\n constructor(tools: IAiOutputTool[]) {\n this.toolMap = new Map(tools.map(t => [t.name, t]));\n }\n\n has(name: string): boolean {\n return this.toolMap.has(name);\n }\n\n async invoke(name: string, params: Record<string, unknown>): Promise<unknown> {\n const tool = this.toolMap.get(name);\n if (!tool) {\n return undefined;\n }\n return tool.execute(params);\n }\n}\n\nexport const AiOutputToolRegistry = Abstraction.createImplementation({\n implementation: AiOutputToolRegistryImpl,\n dependencies: [[AiOutputTool, { multiple: true }]]\n});\n"],"names":["AiOutputToolRegistryImpl","tools","Map","t","name","params","tool","AiOutputToolRegistry","Abstraction","AiOutputTool"],"mappings":";AAOA,MAAMA;IAGF,YAAYC,KAAsB,CAAE;QAChC,IAAI,CAAC,OAAO,GAAG,IAAIC,IAAID,MAAM,GAAG,CAACE,CAAAA,IAAK;gBAACA,EAAE,IAAI;gBAAEA;aAAE;IACrD;IAEA,IAAIC,IAAY,EAAW;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA;IAC5B;IAEA,MAAM,OAAOA,IAAY,EAAEC,MAA+B,EAAoB;QAC1E,MAAMC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAACF;QAC9B,IAAI,CAACE,MACD;QAEJ,OAAOA,KAAK,OAAO,CAACD;IACxB;AACJ;AAEO,MAAME,4CAAuBC,qBAAAA,oBAAgC,CAAC;IACjE,gBAAgBR;IAChB,cAAc;QAAC;YAACS;YAAc;gBAAE,UAAU;YAAK;SAAE;KAAC;AACtD"}
|