@ixo/common 1.1.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/.eslintrc.js +9 -0
- package/.prettierignore +3 -0
- package/.prettierrc.cjs +4 -0
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +76 -0
- package/README.md +245 -0
- package/dist/ai/checkpointer/index.d.ts +2 -0
- package/dist/ai/checkpointer/index.d.ts.map +1 -0
- package/dist/ai/checkpointer/index.js +2 -0
- package/dist/ai/checkpointer/index.js.map +1 -0
- package/dist/ai/index.d.ts +9 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +9 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/models/index.d.ts +2 -0
- package/dist/ai/models/index.d.ts.map +1 -0
- package/dist/ai/models/index.js +2 -0
- package/dist/ai/models/index.js.map +1 -0
- package/dist/ai/models/openai.d.ts +10 -0
- package/dist/ai/models/openai.d.ts.map +1 -0
- package/dist/ai/models/openai.js +38 -0
- package/dist/ai/models/openai.js.map +1 -0
- package/dist/ai/models/openai.test.d.ts +2 -0
- package/dist/ai/models/openai.test.d.ts.map +1 -0
- package/dist/ai/models/openai.test.js +58 -0
- package/dist/ai/models/openai.test.js.map +1 -0
- package/dist/ai/nodes/create-fake-node.d.ts +2 -0
- package/dist/ai/nodes/create-fake-node.d.ts.map +1 -0
- package/dist/ai/nodes/create-fake-node.js +2 -0
- package/dist/ai/nodes/create-fake-node.js.map +1 -0
- package/dist/ai/nodes/find-docs/find-docs.prompt.d.ts +3 -0
- package/dist/ai/nodes/find-docs/find-docs.prompt.d.ts.map +1 -0
- package/dist/ai/nodes/find-docs/find-docs.prompt.js +61 -0
- package/dist/ai/nodes/find-docs/find-docs.prompt.js.map +1 -0
- package/dist/ai/nodes/find-docs/index.d.ts +3 -0
- package/dist/ai/nodes/find-docs/index.d.ts.map +1 -0
- package/dist/ai/nodes/find-docs/index.js +3 -0
- package/dist/ai/nodes/find-docs/index.js.map +1 -0
- package/dist/ai/nodes/find-docs/node.d.ts +17 -0
- package/dist/ai/nodes/find-docs/node.d.ts.map +1 -0
- package/dist/ai/nodes/find-docs/node.js +46 -0
- package/dist/ai/nodes/find-docs/node.js.map +1 -0
- package/dist/ai/nodes/generic-chat/generic-chat.node.d.ts +12 -0
- package/dist/ai/nodes/generic-chat/generic-chat.node.d.ts.map +1 -0
- package/dist/ai/nodes/generic-chat/generic-chat.node.js +34 -0
- package/dist/ai/nodes/generic-chat/generic-chat.node.js.map +1 -0
- package/dist/ai/nodes/generic-chat/generic-chat.prompt.d.ts +10 -0
- package/dist/ai/nodes/generic-chat/generic-chat.prompt.d.ts.map +1 -0
- package/dist/ai/nodes/generic-chat/generic-chat.prompt.js +58 -0
- package/dist/ai/nodes/generic-chat/generic-chat.prompt.js.map +1 -0
- package/dist/ai/nodes/generic-chat/index.d.ts +2 -0
- package/dist/ai/nodes/generic-chat/index.d.ts.map +1 -0
- package/dist/ai/nodes/generic-chat/index.js +2 -0
- package/dist/ai/nodes/generic-chat/index.js.map +1 -0
- package/dist/ai/nodes/index.d.ts +4 -0
- package/dist/ai/nodes/index.d.ts.map +1 -0
- package/dist/ai/nodes/index.js +4 -0
- package/dist/ai/nodes/index.js.map +1 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.d.ts +7 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.d.ts.map +1 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.js +71 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.js.map +1 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.test.d.ts +2 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.test.d.ts.map +1 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.test.js +68 -0
- package/dist/ai/semantic-router-factory/create-semantic-router.test.js.map +1 -0
- package/dist/ai/semantic-router-factory/index.d.ts +4 -0
- package/dist/ai/semantic-router-factory/index.d.ts.map +1 -0
- package/dist/ai/semantic-router-factory/index.js +4 -0
- package/dist/ai/semantic-router-factory/index.js.map +1 -0
- package/dist/ai/semantic-router-factory/semantic-router-prompt.d.ts +2 -0
- package/dist/ai/semantic-router-factory/semantic-router-prompt.d.ts.map +1 -0
- package/dist/ai/semantic-router-factory/semantic-router-prompt.js +169 -0
- package/dist/ai/semantic-router-factory/semantic-router-prompt.js.map +1 -0
- package/dist/ai/semantic-router-factory/validate-routes.d.ts +2 -0
- package/dist/ai/semantic-router-factory/validate-routes.d.ts.map +1 -0
- package/dist/ai/semantic-router-factory/validate-routes.js +16 -0
- package/dist/ai/semantic-router-factory/validate-routes.js.map +1 -0
- package/dist/ai/tools/action-caller.d.ts +14 -0
- package/dist/ai/tools/action-caller.d.ts.map +1 -0
- package/dist/ai/tools/action-caller.js +12 -0
- package/dist/ai/tools/action-caller.js.map +1 -0
- package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.d.ts +25 -0
- package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.d.ts.map +1 -0
- package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.js +46 -0
- package/dist/ai/tools/ask-ixo-guru/ask-ixo-guru.js.map +1 -0
- package/dist/ai/tools/ask-ixo-guru/index.d.ts +2 -0
- package/dist/ai/tools/ask-ixo-guru/index.d.ts.map +1 -0
- package/dist/ai/tools/ask-ixo-guru/index.js +2 -0
- package/dist/ai/tools/ask-ixo-guru/index.js.map +1 -0
- package/dist/ai/tools/browser-tool-caller.d.ts +14 -0
- package/dist/ai/tools/browser-tool-caller.d.ts.map +1 -0
- package/dist/ai/tools/browser-tool-caller.js +12 -0
- package/dist/ai/tools/browser-tool-caller.js.map +1 -0
- package/dist/ai/tools/frontend-tool-caller.d.ts +10 -0
- package/dist/ai/tools/frontend-tool-caller.d.ts.map +1 -0
- package/dist/ai/tools/frontend-tool-caller.js +50 -0
- package/dist/ai/tools/frontend-tool-caller.js.map +1 -0
- package/dist/ai/tools/index.d.ts +11 -0
- package/dist/ai/tools/index.d.ts.map +1 -0
- package/dist/ai/tools/index.js +11 -0
- package/dist/ai/tools/index.js.map +1 -0
- package/dist/ai/tools/log-action-to-matrix.d.ts +13 -0
- package/dist/ai/tools/log-action-to-matrix.d.ts.map +1 -0
- package/dist/ai/tools/log-action-to-matrix.js +14 -0
- package/dist/ai/tools/log-action-to-matrix.js.map +1 -0
- package/dist/ai/tools/parser-action-tool.d.ts +8 -0
- package/dist/ai/tools/parser-action-tool.d.ts.map +1 -0
- package/dist/ai/tools/parser-action-tool.js +40 -0
- package/dist/ai/tools/parser-action-tool.js.map +1 -0
- package/dist/ai/tools/parser-browser-tool.d.ts +8 -0
- package/dist/ai/tools/parser-browser-tool.d.ts.map +1 -0
- package/dist/ai/tools/parser-browser-tool.js +38 -0
- package/dist/ai/tools/parser-browser-tool.js.map +1 -0
- package/dist/ai/tools/retriever-tool/index.d.ts +2 -0
- package/dist/ai/tools/retriever-tool/index.d.ts.map +1 -0
- package/dist/ai/tools/retriever-tool/index.js +2 -0
- package/dist/ai/tools/retriever-tool/index.js.map +1 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.d.ts +18 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.d.ts.map +1 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.js +62 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.js.map +1 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.test.d.ts +2 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.test.d.ts.map +1 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.test.js +119 -0
- package/dist/ai/tools/retriever-tool/retriever-tool.test.js.map +1 -0
- package/dist/ai/tools/scrape-web-page.d.ts +7 -0
- package/dist/ai/tools/scrape-web-page.d.ts.map +1 -0
- package/dist/ai/tools/scrape-web-page.js +65 -0
- package/dist/ai/tools/scrape-web-page.js.map +1 -0
- package/dist/ai/tools/web-search-tool.d.ts +10 -0
- package/dist/ai/tools/web-search-tool.d.ts.map +1 -0
- package/dist/ai/tools/web-search-tool.js +30 -0
- package/dist/ai/tools/web-search-tool.js.map +1 -0
- package/dist/ai/types.d.ts +4 -0
- package/dist/ai/types.d.ts.map +1 -0
- package/dist/ai/types.js +2 -0
- package/dist/ai/types.js.map +1 -0
- package/dist/ai/utils/__tests__/chunk-arr.test.d.ts +2 -0
- package/dist/ai/utils/__tests__/chunk-arr.test.d.ts.map +1 -0
- package/dist/ai/utils/__tests__/chunk-arr.test.js +37 -0
- package/dist/ai/utils/__tests__/chunk-arr.test.js.map +1 -0
- package/dist/ai/utils/__tests__/doc-relevance-checker.test.d.ts +2 -0
- package/dist/ai/utils/__tests__/doc-relevance-checker.test.d.ts.map +1 -0
- package/dist/ai/utils/__tests__/doc-relevance-checker.test.js +80 -0
- package/dist/ai/utils/__tests__/doc-relevance-checker.test.js.map +1 -0
- package/dist/ai/utils/__tests__/doc-splitter.test.d.ts +2 -0
- package/dist/ai/utils/__tests__/doc-splitter.test.d.ts.map +1 -0
- package/dist/ai/utils/__tests__/doc-splitter.test.js +35 -0
- package/dist/ai/utils/__tests__/doc-splitter.test.js.map +1 -0
- package/dist/ai/utils/__tests__/filter-similarity-search-results.test.d.ts +2 -0
- package/dist/ai/utils/__tests__/filter-similarity-search-results.test.d.ts.map +1 -0
- package/dist/ai/utils/__tests__/filter-similarity-search-results.test.js +47 -0
- package/dist/ai/utils/__tests__/filter-similarity-search-results.test.js.map +1 -0
- package/dist/ai/utils/__tests__/json-to-yaml.test.d.ts +2 -0
- package/dist/ai/utils/__tests__/json-to-yaml.test.d.ts.map +1 -0
- package/dist/ai/utils/__tests__/json-to-yaml.test.js +63 -0
- package/dist/ai/utils/__tests__/json-to-yaml.test.js.map +1 -0
- package/dist/ai/utils/__tests__/stringify-docs.test.d.ts +2 -0
- package/dist/ai/utils/__tests__/stringify-docs.test.d.ts.map +1 -0
- package/dist/ai/utils/__tests__/stringify-docs.test.js +54 -0
- package/dist/ai/utils/__tests__/stringify-docs.test.js.map +1 -0
- package/dist/ai/utils/chunk-arr.d.ts +3 -0
- package/dist/ai/utils/chunk-arr.d.ts.map +1 -0
- package/dist/ai/utils/chunk-arr.js +13 -0
- package/dist/ai/utils/chunk-arr.js.map +1 -0
- package/dist/ai/utils/doc-relevance-checker.d.ts +10 -0
- package/dist/ai/utils/doc-relevance-checker.d.ts.map +1 -0
- package/dist/ai/utils/doc-relevance-checker.js +37 -0
- package/dist/ai/utils/doc-relevance-checker.js.map +1 -0
- package/dist/ai/utils/doc-splitter.d.ts +3 -0
- package/dist/ai/utils/doc-splitter.d.ts.map +1 -0
- package/dist/ai/utils/doc-splitter.js +20 -0
- package/dist/ai/utils/doc-splitter.js.map +1 -0
- package/dist/ai/utils/filter-similarity-search-results.d.ts +4 -0
- package/dist/ai/utils/filter-similarity-search-results.d.ts.map +1 -0
- package/dist/ai/utils/filter-similarity-search-results.js +11 -0
- package/dist/ai/utils/filter-similarity-search-results.js.map +1 -0
- package/dist/ai/utils/generate-questions-from-chunks.d.ts +15 -0
- package/dist/ai/utils/generate-questions-from-chunks.d.ts.map +1 -0
- package/dist/ai/utils/generate-questions-from-chunks.js +101 -0
- package/dist/ai/utils/generate-questions-from-chunks.js.map +1 -0
- package/dist/ai/utils/index.d.ts +11 -0
- package/dist/ai/utils/index.d.ts.map +1 -0
- package/dist/ai/utils/index.js +11 -0
- package/dist/ai/utils/index.js.map +1 -0
- package/dist/ai/utils/json-to-yaml.d.ts +2 -0
- package/dist/ai/utils/json-to-yaml.d.ts.map +1 -0
- package/dist/ai/utils/json-to-yaml.js +25 -0
- package/dist/ai/utils/json-to-yaml.js.map +1 -0
- package/dist/ai/utils/load-file.d.ts +3 -0
- package/dist/ai/utils/load-file.d.ts.map +1 -0
- package/dist/ai/utils/load-file.js +133 -0
- package/dist/ai/utils/load-file.js.map +1 -0
- package/dist/ai/utils/stringify-docs.d.ts +3 -0
- package/dist/ai/utils/stringify-docs.d.ts.map +1 -0
- package/dist/ai/utils/stringify-docs.js +6 -0
- package/dist/ai/utils/stringify-docs.js.map +1 -0
- package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.d.ts +35 -0
- package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.d.ts.map +1 -0
- package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.js +55 -0
- package/dist/ai/utils/transformGraphStateMessageToListMessageResponse.js.map +1 -0
- package/dist/ai/utils/verify-matrix-openId-token.d.ts +6 -0
- package/dist/ai/utils/verify-matrix-openId-token.d.ts.map +1 -0
- package/dist/ai/utils/verify-matrix-openId-token.js +36 -0
- package/dist/ai/utils/verify-matrix-openId-token.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/services/env/env-service.test.d.ts +2 -0
- package/dist/services/env/env-service.test.d.ts.map +1 -0
- package/dist/services/env/env-service.test.js +99 -0
- package/dist/services/env/env-service.test.js.map +1 -0
- package/dist/services/env/env.service.d.ts +11 -0
- package/dist/services/env/env.service.d.ts.map +1 -0
- package/dist/services/env/env.service.js +42 -0
- package/dist/services/env/env.service.js.map +1 -0
- package/dist/services/env/index.d.ts +2 -0
- package/dist/services/env/index.d.ts.map +1 -0
- package/dist/services/env/index.js +2 -0
- package/dist/services/env/index.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +5 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/memory-engine/memory-engine.service.d.ts +35 -0
- package/dist/services/memory-engine/memory-engine.service.d.ts.map +1 -0
- package/dist/services/memory-engine/memory-engine.service.js +295 -0
- package/dist/services/memory-engine/memory-engine.service.js.map +1 -0
- package/dist/services/memory-engine/types.d.ts +88 -0
- package/dist/services/memory-engine/types.d.ts.map +1 -0
- package/dist/services/memory-engine/types.js +2 -0
- package/dist/services/memory-engine/types.js.map +1 -0
- package/dist/services/session-manager/dto.d.ts +40 -0
- package/dist/services/session-manager/dto.d.ts.map +1 -0
- package/dist/services/session-manager/dto.js +170 -0
- package/dist/services/session-manager/dto.js.map +1 -0
- package/dist/services/session-manager/errors.d.ts +22 -0
- package/dist/services/session-manager/errors.d.ts.map +1 -0
- package/dist/services/session-manager/errors.js +41 -0
- package/dist/services/session-manager/errors.js.map +1 -0
- package/dist/services/session-manager/index.d.ts +4 -0
- package/dist/services/session-manager/index.d.ts.map +1 -0
- package/dist/services/session-manager/index.js +4 -0
- package/dist/services/session-manager/index.js.map +1 -0
- package/dist/services/session-manager/session-manager.service.d.ts +40 -0
- package/dist/services/session-manager/session-manager.service.d.ts.map +1 -0
- package/dist/services/session-manager/session-manager.service.js +251 -0
- package/dist/services/session-manager/session-manager.service.js.map +1 -0
- package/dist/utils/get-user-subscription.d.ts +21 -0
- package/dist/utils/get-user-subscription.d.ts.map +1 -0
- package/dist/utils/get-user-subscription.js +44 -0
- package/dist/utils/get-user-subscription.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/docs/ai-module.md +84 -0
- package/docs/services.md +168 -0
- package/docs/tools.md +325 -0
- package/jest.config.js +6 -0
- package/package.json +81 -0
- package/src/ai/checkpointer/index.ts +1 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/models/index.ts +1 -0
- package/src/ai/models/openai.test.ts +72 -0
- package/src/ai/models/openai.ts +54 -0
- package/src/ai/nodes/create-fake-node.ts +1 -0
- package/src/ai/nodes/find-docs/find-docs.prompt.ts +61 -0
- package/src/ai/nodes/find-docs/index.ts +2 -0
- package/src/ai/nodes/find-docs/node.ts +83 -0
- package/src/ai/nodes/generic-chat/generic-chat.node.ts +58 -0
- package/src/ai/nodes/generic-chat/generic-chat.prompt.ts +66 -0
- package/src/ai/nodes/generic-chat/index.ts +1 -0
- package/src/ai/nodes/index.ts +3 -0
- package/src/ai/semantic-router-factory/create-semantic-router.test.ts +98 -0
- package/src/ai/semantic-router-factory/create-semantic-router.ts +136 -0
- package/src/ai/semantic-router-factory/index.ts +3 -0
- package/src/ai/semantic-router-factory/semantic-router-prompt.ts +168 -0
- package/src/ai/semantic-router-factory/validate-routes.ts +26 -0
- package/src/ai/tools/action-caller.ts +37 -0
- package/src/ai/tools/ask-ixo-guru/ask-ixo-guru.ts +73 -0
- package/src/ai/tools/ask-ixo-guru/index.ts +1 -0
- package/src/ai/tools/browser-tool-caller.ts +37 -0
- package/src/ai/tools/frontend-tool-caller.ts +86 -0
- package/src/ai/tools/index.ts +10 -0
- package/src/ai/tools/log-action-to-matrix.ts +30 -0
- package/src/ai/tools/parser-action-tool.ts +61 -0
- package/src/ai/tools/parser-browser-tool.ts +55 -0
- package/src/ai/tools/retriever-tool/index.ts +1 -0
- package/src/ai/tools/retriever-tool/retriever-tool.test.ts +156 -0
- package/src/ai/tools/retriever-tool/retriever-tool.ts +107 -0
- package/src/ai/tools/scrape-web-page.ts +75 -0
- package/src/ai/tools/web-search-tool.ts +38 -0
- package/src/ai/types.ts +6 -0
- package/src/ai/utils/__tests__/chunk-arr.test.ts +46 -0
- package/src/ai/utils/__tests__/doc-relevance-checker.test.ts +90 -0
- package/src/ai/utils/__tests__/doc-splitter.test.ts +42 -0
- package/src/ai/utils/__tests__/filter-similarity-search-results.test.ts +57 -0
- package/src/ai/utils/__tests__/json-to-yaml.test.ts +70 -0
- package/src/ai/utils/__tests__/stringify-docs.test.ts +61 -0
- package/src/ai/utils/chunk-arr.ts +13 -0
- package/src/ai/utils/doc-relevance-checker.ts +58 -0
- package/src/ai/utils/doc-splitter.ts +28 -0
- package/src/ai/utils/filter-similarity-search-results.ts +15 -0
- package/src/ai/utils/generate-questions-from-chunks.ts +114 -0
- package/src/ai/utils/index.ts +10 -0
- package/src/ai/utils/json-to-yaml.ts +32 -0
- package/src/ai/utils/load-file.ts +170 -0
- package/src/ai/utils/stringify-docs.ts +14 -0
- package/src/ai/utils/transformGraphStateMessageToListMessageResponse.ts +108 -0
- package/src/ai/utils/verify-matrix-openId-token.ts +46 -0
- package/src/index.ts +3 -0
- package/src/services/env/env-service.test.ts +153 -0
- package/src/services/env/env.service.ts +65 -0
- package/src/services/env/index.ts +1 -0
- package/src/services/index.ts +4 -0
- package/src/services/memory-engine/memory-engine.service.ts +486 -0
- package/src/services/memory-engine/types.ts +208 -0
- package/src/services/session-manager/dto.ts +120 -0
- package/src/services/session-manager/errors.ts +56 -0
- package/src/services/session-manager/index.ts +3 -0
- package/src/services/session-manager/session-manager.service.ts +405 -0
- package/src/utils/get-user-subscription.ts +84 -0
- package/src/utils/index.ts +1 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
package/docs/services.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Services Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Services module in `@ixo/common` provides essential services for managing Matrix rooms and chat sessions. It integrates with the Matrix protocol through `@ixo/matrix` and provides type-safe operations for room and session management.
|
|
6
|
+
|
|
7
|
+
## Core Services
|
|
8
|
+
|
|
9
|
+
### Room Manager Service
|
|
10
|
+
|
|
11
|
+
A service for managing Matrix rooms with support for creation, retrieval, and access control.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { RoomManagerService } from '@ixo/common/services';
|
|
15
|
+
|
|
16
|
+
const roomManager = new RoomManagerService();
|
|
17
|
+
|
|
18
|
+
// Create or get existing room
|
|
19
|
+
const roomId = await roomManager.getOrCreateRoom({
|
|
20
|
+
did: 'user-did',
|
|
21
|
+
oracleName: 'oracle-name',
|
|
22
|
+
userAccessToken: 'matrix-access-token',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Get room by DID and oracle name
|
|
26
|
+
const room = await roomManager.getRoom({
|
|
27
|
+
did: 'user-did',
|
|
28
|
+
oracleName: 'oracle-name',
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Room Manager Capabilities
|
|
33
|
+
|
|
34
|
+
- Create new Matrix rooms
|
|
35
|
+
- Retrieve existing rooms by DID and oracle name
|
|
36
|
+
- Get or create rooms (idempotent operation)
|
|
37
|
+
|
|
38
|
+
#### Room Manager Types
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface CreateRoomDto {
|
|
42
|
+
did: string;
|
|
43
|
+
oracleName: string;
|
|
44
|
+
userAccessToken: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface GetRoomDto {
|
|
48
|
+
did: string;
|
|
49
|
+
oracleName: string;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Session Manager Service
|
|
54
|
+
|
|
55
|
+
A service for managing chat sessions with support for persistence in Matrix rooms.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { SessionManagerService } from '@ixo/common/services';
|
|
59
|
+
|
|
60
|
+
const sessionManager = new SessionManagerService();
|
|
61
|
+
|
|
62
|
+
// Create new chat session
|
|
63
|
+
const session = await sessionManager.createSession({
|
|
64
|
+
did: 'user-did',
|
|
65
|
+
oracleName: 'oracle-name',
|
|
66
|
+
matrixAccessToken: 'access-token',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// List user's sessions
|
|
70
|
+
const { sessions } = await sessionManager.listSessions({
|
|
71
|
+
did: 'user-did',
|
|
72
|
+
matrixAccessToken: 'access-token',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Delete a session
|
|
76
|
+
await sessionManager.deleteSession({
|
|
77
|
+
did: 'user-did',
|
|
78
|
+
sessionId: 'session-uuid',
|
|
79
|
+
matrixAccessToken: 'access-token',
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Session Manager Capabilities
|
|
84
|
+
|
|
85
|
+
- Create new chat sessions
|
|
86
|
+
- List existing sessions for a user
|
|
87
|
+
- Delete sessions
|
|
88
|
+
- Automatic session title generation using AI
|
|
89
|
+
- Session state persistence in Matrix rooms
|
|
90
|
+
- Type-safe operations with DTOs
|
|
91
|
+
|
|
92
|
+
#### Session Types
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
interface ChatSession {
|
|
96
|
+
sessionId: string;
|
|
97
|
+
oracleName: string;
|
|
98
|
+
title: string;
|
|
99
|
+
lastUpdatedAt: string;
|
|
100
|
+
createdAt: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface CreateChatSessionDto {
|
|
104
|
+
did: string;
|
|
105
|
+
oracleName: string;
|
|
106
|
+
matrixAccessToken: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface ListChatSessionsDto {
|
|
110
|
+
did: string;
|
|
111
|
+
matrixAccessToken: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface DeleteChatSessionDto {
|
|
115
|
+
did: string;
|
|
116
|
+
sessionId: string;
|
|
117
|
+
matrixAccessToken: string;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Error Handling
|
|
122
|
+
|
|
123
|
+
The services provide specific error types for common scenarios:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import {
|
|
127
|
+
NoUserRoomsFoundError,
|
|
128
|
+
RoomNotFoundError,
|
|
129
|
+
UserNotInRoomError,
|
|
130
|
+
} from '@ixo/common/services';
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
await operation();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof NoUserRoomsFoundError) {
|
|
136
|
+
// Handle case where user has no rooms
|
|
137
|
+
} else if (error instanceof RoomNotFoundError) {
|
|
138
|
+
// Handle case where specific room not found
|
|
139
|
+
} else if (error instanceof UserNotInRoomError) {
|
|
140
|
+
// Handle case where user doesn't have access
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Integration with Matrix
|
|
146
|
+
|
|
147
|
+
Both services integrate with the Matrix protocol through `@ixo/matrix`:
|
|
148
|
+
|
|
149
|
+
- Uses Matrix rooms for persistence
|
|
150
|
+
- Leverages Matrix state events for session storage
|
|
151
|
+
- Handles Matrix authentication and access control
|
|
152
|
+
- Provides type-safe Matrix operations
|
|
153
|
+
|
|
154
|
+
## Best Practices
|
|
155
|
+
|
|
156
|
+
### Room Management
|
|
157
|
+
|
|
158
|
+
- Store room IDs for frequent access
|
|
159
|
+
- Handle room creation idempotently
|
|
160
|
+
- Validate user access tokens
|
|
161
|
+
- Use appropriate error handling
|
|
162
|
+
|
|
163
|
+
### Session Management
|
|
164
|
+
|
|
165
|
+
- Use UUIDs for session IDs
|
|
166
|
+
- Handle session state updates atomically
|
|
167
|
+
- Implement proper cleanup for deleted sessions
|
|
168
|
+
- Validate session access before operations
|
package/docs/tools.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# Tools and Utilities Documentation
|
|
2
|
+
|
|
3
|
+
This document provides detailed information about the tools and utilities available in the `@ixo/common` package.
|
|
4
|
+
|
|
5
|
+
## Tools
|
|
6
|
+
|
|
7
|
+
### Ask IXO Guru Tool
|
|
8
|
+
|
|
9
|
+
A LangChain tool for interacting with the IXO Guru AI, which provides access to IXO's internal knowledge base.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { askIXOGuruTool } from '@ixo/common/ai/tools';
|
|
13
|
+
|
|
14
|
+
// Ask a question
|
|
15
|
+
const response = await askIXOGuruTool.invoke({
|
|
16
|
+
question: "What is IXO's approach to impact tokens?",
|
|
17
|
+
sessionId: 'uuid-v4-string', // To save the conversation to matrix
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
#### Configuration
|
|
22
|
+
|
|
23
|
+
Requires the following environment variables:
|
|
24
|
+
|
|
25
|
+
```env
|
|
26
|
+
IXO_GURU_QUERY_ENDPOINT=your_endpoint_url
|
|
27
|
+
GURU_ASSISTANCE_API_TOKEN=your_api_token
|
|
28
|
+
ORACLE_DID=your_oracle_did
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Response Format
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
answer: "The AI's response to your question"
|
|
35
|
+
sessionId: 'conversation-session-uuid'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Error Handling
|
|
39
|
+
|
|
40
|
+
The tool handles various error scenarios:
|
|
41
|
+
|
|
42
|
+
- Missing environment variables
|
|
43
|
+
- API connection issues
|
|
44
|
+
- Invalid session IDs
|
|
45
|
+
- Authentication failures
|
|
46
|
+
|
|
47
|
+
### Retriever Tool
|
|
48
|
+
|
|
49
|
+
A LangChain tool factory for creating document retrieval tools that can search and filter documents from a vector database with relevance checking.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { retrieverToolFactory } from '@ixo/common/ai/tools';
|
|
53
|
+
import { VectorDBDataStore } from '@ixo/data-store';
|
|
54
|
+
|
|
55
|
+
// Create a retriever tool
|
|
56
|
+
const retriever = retrieverToolFactory({
|
|
57
|
+
store: vectorStore, // Your VectorDBDataStore instance
|
|
58
|
+
similarThreshold: 0.3, // Optional similarity threshold
|
|
59
|
+
filters: { category: 'tech' }, // Optional filters
|
|
60
|
+
map: new Map(), // Optional map to store metadata
|
|
61
|
+
requestId: 'unique-id', // Optional request identifier
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Use the tool
|
|
65
|
+
const docs = await retriever.invoke({
|
|
66
|
+
query: "What's new in AI?",
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Features
|
|
71
|
+
|
|
72
|
+
- Integrates with vector databases via VectorDBDataStore
|
|
73
|
+
- Configurable similarity threshold for initial filtering
|
|
74
|
+
- Additional AI-powered relevance checking for better results
|
|
75
|
+
- Optional metadata mapping for tracking used documents
|
|
76
|
+
- Support for custom filters and OpenAI models
|
|
77
|
+
- Returns LangChain Document objects
|
|
78
|
+
|
|
79
|
+
#### Configuration Options
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
type RetrieverToolFactoryArgs = {
|
|
83
|
+
model?: BaseChatModel; // Optional OpenAI model
|
|
84
|
+
filters?: Record<string, unknown>; // Vector store filters
|
|
85
|
+
similarThreshold?: number; // Similarity cutoff (default: 0.3)
|
|
86
|
+
store: VectorDBDataStore; // Required vector store
|
|
87
|
+
map?: Map<string, unknown>; // Optional metadata map
|
|
88
|
+
requestId?: string; // Optional request tracking
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Behavior
|
|
93
|
+
|
|
94
|
+
- Queries vector store with similarity search
|
|
95
|
+
- For threshold ≥ 0.3, performs additional AI relevance check
|
|
96
|
+
- Stores document metadata in provided map if configured
|
|
97
|
+
- Returns undefined if no documents found
|
|
98
|
+
- Handles errors gracefully with logging
|
|
99
|
+
|
|
100
|
+
### Web Search Tool
|
|
101
|
+
|
|
102
|
+
A LangChain tool that provides web search capabilities using the Tavily API. This tool is optimized for comprehensive, accurate, and trusted search results.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { webSearchTool } from '@ixo/common/ai/tools';
|
|
106
|
+
|
|
107
|
+
// Use in LangChain
|
|
108
|
+
const result = await webSearchTool.invoke({
|
|
109
|
+
input: "What's new in AI technology?",
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Features and Behavior
|
|
114
|
+
|
|
115
|
+
- Uses Tavily's AI-powered search engine
|
|
116
|
+
- Returns structured search results including:
|
|
117
|
+
- Query summary
|
|
118
|
+
- Top 3 most relevant results
|
|
119
|
+
- Each result includes title, URL, content, and publish date
|
|
120
|
+
- Results are formatted in YAML for better readability for AI and ovid parsing errors
|
|
121
|
+
- Built-in input validation using Zod
|
|
122
|
+
|
|
123
|
+
#### Web Search Configuration
|
|
124
|
+
|
|
125
|
+
Requires the `TAVILY_API_KEY` environment variable to be set:
|
|
126
|
+
|
|
127
|
+
```env
|
|
128
|
+
TAVILY_API_KEY=your_api_key_here
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Web Search Response Format
|
|
132
|
+
|
|
133
|
+
```yaml
|
|
134
|
+
query: 'your search query'
|
|
135
|
+
summary: 'AI-generated summary of search results'
|
|
136
|
+
results:
|
|
137
|
+
- title: 'Result Title'
|
|
138
|
+
url: 'https://result.url'
|
|
139
|
+
content: 'Result content snippet'
|
|
140
|
+
publishedAt: '2024-01-28'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Utilities
|
|
144
|
+
|
|
145
|
+
### File Loading Utility
|
|
146
|
+
|
|
147
|
+
A versatile utility for loading and processing various types of files, supporting both local files and URLs. It automatically handles different file formats and returns processed LangChain Document objects.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { loadFile } from '@ixo/common/ai/utils';
|
|
151
|
+
|
|
152
|
+
// Load a local file
|
|
153
|
+
const pdfDocs = await loadFile('path/to/document.pdf');
|
|
154
|
+
|
|
155
|
+
// Load a file from URL with optional fetch options
|
|
156
|
+
const docsDocs = await loadFile('https://example.com/document.docx', {
|
|
157
|
+
headers: {
|
|
158
|
+
Authorization: 'Bearer token', // user OAuth token from Slack
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Supported File Types
|
|
164
|
+
|
|
165
|
+
- PDF (.pdf)
|
|
166
|
+
- Microsoft Word (.doc, .docx)
|
|
167
|
+
- Markdown (.md, .markdown)
|
|
168
|
+
- HTML (.html, .htm)
|
|
169
|
+
- Plain Text (.txt)
|
|
170
|
+
|
|
171
|
+
#### File Loading Features
|
|
172
|
+
|
|
173
|
+
- Automatic file type detection based on extension and MIME type
|
|
174
|
+
- Support for both local files and URLs
|
|
175
|
+
- Built-in error handling and logging
|
|
176
|
+
- Automatic text splitting using RecursiveCharacterTextSplitter
|
|
177
|
+
- HTML to text conversion for web content
|
|
178
|
+
- Returns LangChain Document objects ready for further processing
|
|
179
|
+
|
|
180
|
+
### Document Splitter
|
|
181
|
+
|
|
182
|
+
A utility for splitting text content into manageable chunks using LangChain's RecursiveCharacterTextSplitter.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { docSplitter } from '@ixo/common/ai/utils';
|
|
186
|
+
|
|
187
|
+
// Split a single string
|
|
188
|
+
const chunks = await docSplitter('Long text content...');
|
|
189
|
+
|
|
190
|
+
// Split multiple strings
|
|
191
|
+
const multiChunks = await docSplitter(['Text 1...', 'Text 2...']);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Document Splitter Features
|
|
195
|
+
|
|
196
|
+
- Input validation using Zod
|
|
197
|
+
- Supports both single string and string array inputs
|
|
198
|
+
- Returns array of LangChain Document objects
|
|
199
|
+
- Automatic error handling for empty or invalid inputs
|
|
200
|
+
|
|
201
|
+
### JSON to YAML Converter
|
|
202
|
+
|
|
203
|
+
A utility for converting JSON objects to YAML format, useful for creating human-readable configurations and outputs.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { jsonToYaml } from '@ixo/common/ai/utils';
|
|
207
|
+
|
|
208
|
+
const yaml = jsonToYaml({
|
|
209
|
+
name: 'example',
|
|
210
|
+
config: {
|
|
211
|
+
enabled: true,
|
|
212
|
+
values: [1, 2, 3],
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Document Stringifier
|
|
218
|
+
|
|
219
|
+
A utility for converting LangChain Document objects to string format.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { stringifyDocs } from '@ixo/common/ai/utils';
|
|
223
|
+
|
|
224
|
+
const stringified = stringifyDocs(documents);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Array Chunking
|
|
228
|
+
|
|
229
|
+
A utility for splitting arrays into smaller chunks of a specified size.
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { chunkArr } from '@ixo/common/ai/utils';
|
|
233
|
+
|
|
234
|
+
const chunks = chunkArr([1, 2, 3, 4, 5], 2);
|
|
235
|
+
// Result: [[1, 2], [3, 4], [5]]
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Document Relevance Checker
|
|
239
|
+
|
|
240
|
+
A utility that uses LLMs to determine if a document is relevant to a given query. It's particularly useful for filtering search results and ensuring content relevance.
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import checkDocRelevance from '@ixo/common/ai/utils';
|
|
244
|
+
|
|
245
|
+
// Check document relevance
|
|
246
|
+
const isRelevant = await checkDocRelevance({
|
|
247
|
+
doc: 'Document content or LangChain Document', // Can be string or Document
|
|
248
|
+
query: 'What technologies does IXO use?',
|
|
249
|
+
model: customModel, // Optional: defaults to OpenAI
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### Relevance Checker Capabilities
|
|
254
|
+
|
|
255
|
+
- Accepts both string content and LangChain Document objects
|
|
256
|
+
- Uses structured LLM output with Zod validation
|
|
257
|
+
- Customizable LLM model support
|
|
258
|
+
- Semantic relevance checking based on content meaning
|
|
259
|
+
- Built-in prompt template for consistent evaluation
|
|
260
|
+
|
|
261
|
+
#### Relevance Checker Behavior
|
|
262
|
+
|
|
263
|
+
The checker evaluates relevance based on three criteria:
|
|
264
|
+
|
|
265
|
+
1. Identifies documents completely unrelated to the query
|
|
266
|
+
2. Considers documents relevant if they contain related keywords or semantic meaning
|
|
267
|
+
3. Accepts partially relevant documents if they contain any related information
|
|
268
|
+
|
|
269
|
+
#### Usage Example with Custom Model
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { ChatOpenAI } from '@langchain/openai';
|
|
273
|
+
import checkDocRelevance from '@ixo/common/ai/utils';
|
|
274
|
+
|
|
275
|
+
const customModel = new ChatOpenAI({
|
|
276
|
+
modelName: 'gpt-4',
|
|
277
|
+
temperature: 0,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const isRelevant = await checkDocRelevance({
|
|
281
|
+
doc: new Document({ pageContent: 'content here' }),
|
|
282
|
+
query: 'your query',
|
|
283
|
+
model: customModel,
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Similarity Search Filter
|
|
288
|
+
|
|
289
|
+
A utility for filtering vector similarity search results based on a similarity threshold. This is useful for ensuring high-quality search results by removing low-similarity matches.
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import { filterSimilaritySearchResults } from '@ixo/common/ai/utils';
|
|
293
|
+
|
|
294
|
+
// Filter search results
|
|
295
|
+
const results: [Document, number][] = [
|
|
296
|
+
[doc1, 0.8],
|
|
297
|
+
[doc2, 0.4],
|
|
298
|
+
[doc3, 0.9],
|
|
299
|
+
];
|
|
300
|
+
|
|
301
|
+
const filteredDocs = filterSimilaritySearchResults(results, 0.7);
|
|
302
|
+
// Returns only docs with similarity >= 0.7
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### Filter Capabilities
|
|
306
|
+
|
|
307
|
+
- Type-safe implementation with generics
|
|
308
|
+
- Works with LangChain Document objects
|
|
309
|
+
- Filters based on configurable threshold
|
|
310
|
+
- Preserves document order
|
|
311
|
+
- Simple and efficient filtering
|
|
312
|
+
|
|
313
|
+
#### Usage with Vector Search
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { filterSimilaritySearchResults } from '@ixo/common/ai/utils';
|
|
317
|
+
import { type Document } from '@langchain/core/documents';
|
|
318
|
+
|
|
319
|
+
// Example with vector search results
|
|
320
|
+
type SearchResult = [Document, number];
|
|
321
|
+
const searchResults: SearchResult[] = await vectorStore.similaritySearch(query);
|
|
322
|
+
|
|
323
|
+
// Filter results with similarity >= 0.8
|
|
324
|
+
const highQualityResults = filterSimilaritySearchResults(searchResults, 0.8);
|
|
325
|
+
```
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ixo/common",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./ai": {
|
|
18
|
+
"types": "./dist/ai/index.d.ts",
|
|
19
|
+
"import": "./dist/ai/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./dist/*.d.ts",
|
|
23
|
+
"import": "./dist/*.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@jest/types": "^29.6.3",
|
|
28
|
+
"@langchain/langgraph-checkpoint-validation": "^1.0.0",
|
|
29
|
+
"@testcontainers/postgresql": "^10.16.0",
|
|
30
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
31
|
+
"@types/jest": "^29.5.14",
|
|
32
|
+
"@types/node": "^22.7.3",
|
|
33
|
+
"@types/store": "^2.0.5",
|
|
34
|
+
"better-sqlite3": "^12.4.6",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"testcontainers": "^10.16.0",
|
|
37
|
+
"ts-jest": "^29.2.5",
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"@ixo/eslint-config": "1.0.0",
|
|
40
|
+
"@ixo/data-store": "^1.0.1",
|
|
41
|
+
"@ixo/jest-config": "0.0.0",
|
|
42
|
+
"@ixo/typescript-config": "1.0.0",
|
|
43
|
+
"@ixo/oracles-events": "^1.0.1"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@cosmjs/proto-signing": "^0.33.0",
|
|
47
|
+
"@cosmjs/stargate": "^0.33.0",
|
|
48
|
+
"@ixo/impactxclient-sdk": "^2.3.1",
|
|
49
|
+
"@langchain/community": "^1.0.4",
|
|
50
|
+
"@langchain/core": "1.0.6",
|
|
51
|
+
"@langchain/langgraph": "1.0.2",
|
|
52
|
+
"@langchain/langgraph-checkpoint": "^1.0.0",
|
|
53
|
+
"@langchain/langgraph-checkpoint-sqlite": "^1.0.0",
|
|
54
|
+
"@langchain/openai": "^1.1.2",
|
|
55
|
+
"@langchain/textsplitters": "^1.0.0",
|
|
56
|
+
"@tavily/core": "0.0.2",
|
|
57
|
+
"axios": "^1.7.9",
|
|
58
|
+
"axios-retry": "^4.5.0",
|
|
59
|
+
"class-transformer": "^0.5.1",
|
|
60
|
+
"class-validator": "^0.14.1",
|
|
61
|
+
"dotenv": "^16.4.5",
|
|
62
|
+
"duck-duck-scrape": "^2.2.5",
|
|
63
|
+
"html-to-text": "9.0.5",
|
|
64
|
+
"langchain": "1.0.6",
|
|
65
|
+
"langfuse": "^3.38.5",
|
|
66
|
+
"langsmith": "^0.1.61",
|
|
67
|
+
"mammoth": "1.8.0",
|
|
68
|
+
"openai": "^6.9.1",
|
|
69
|
+
"pdf-parse": "^1.1.1",
|
|
70
|
+
"playwright": "^1.51.0",
|
|
71
|
+
"store": "^2.0.12",
|
|
72
|
+
"zod": "^4.1.12",
|
|
73
|
+
"@ixo/logger": "0.0.2",
|
|
74
|
+
"@ixo/matrix": "1.1.0",
|
|
75
|
+
"@ixo/oracles-chain-client": "1.2.0"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "tsc && tsc-alias",
|
|
79
|
+
"test": "jest"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@langchain/langgraph-checkpoint-sqlite';
|
package/src/ai/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './checkpointer/index.js';
|
|
2
|
+
export * from './models/index.js';
|
|
3
|
+
export * from './nodes/index.js';
|
|
4
|
+
export * from './semantic-router-factory/index.js';
|
|
5
|
+
export * from './tools/index.js';
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
export * from './utils/index.js';
|
|
8
|
+
export { zodResponseFormat } from 'openai/helpers/zod';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './openai.js';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
|
|
2
|
+
import { getChatOpenAiModel, getOpenAiEmbeddings } from './openai.js';
|
|
3
|
+
|
|
4
|
+
// Mock environment variables
|
|
5
|
+
const originalEnv = process.env;
|
|
6
|
+
|
|
7
|
+
describe('OpenAI Models', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
jest.resetModules();
|
|
10
|
+
process.env = { ...originalEnv };
|
|
11
|
+
process.env.OPENAI_API_KEY = 'test-api-key';
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
process.env = originalEnv;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('getChatOpenAiModel', () => {
|
|
19
|
+
it('should create a ChatOpenAI instance with default parameters', () => {
|
|
20
|
+
const model = getChatOpenAiModel();
|
|
21
|
+
|
|
22
|
+
expect(model).toBeInstanceOf(ChatOpenAI);
|
|
23
|
+
expect(model).toHaveProperty('temperature', 0.2);
|
|
24
|
+
expect(model).toHaveProperty('modelName', 'gpt-4o-mini');
|
|
25
|
+
expect(model).toHaveProperty('apiKey', 'test-api-key');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should override default parameters when provided', () => {
|
|
29
|
+
const customParams = {
|
|
30
|
+
temperature: 0.8,
|
|
31
|
+
model: 'gpt-4',
|
|
32
|
+
apiKey: 'custom-api-key',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const model = getChatOpenAiModel(customParams);
|
|
36
|
+
|
|
37
|
+
expect(model).toBeInstanceOf(ChatOpenAI);
|
|
38
|
+
expect(model).toHaveProperty('temperature', 0.8);
|
|
39
|
+
expect(model).toHaveProperty('modelName', 'gpt-4');
|
|
40
|
+
expect(model).toHaveProperty('apiKey', 'custom-api-key');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('getOpenAiEmbeddings', () => {
|
|
45
|
+
it('should create an OpenAIEmbeddings instance with default parameters', () => {
|
|
46
|
+
const embeddings = getOpenAiEmbeddings();
|
|
47
|
+
expect(embeddings).toBeInstanceOf(OpenAIEmbeddings);
|
|
48
|
+
expect(embeddings.model).toEqual('text-embedding-3-small');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should override default parameters when provided', () => {
|
|
52
|
+
const customParams = {
|
|
53
|
+
model: 'text-embedding-ada-002',
|
|
54
|
+
apiKey: 'custom-api-key',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const embeddings = getOpenAiEmbeddings(customParams);
|
|
58
|
+
|
|
59
|
+
expect(embeddings).toBeInstanceOf(OpenAIEmbeddings);
|
|
60
|
+
expect(embeddings.model).toEqual('text-embedding-ada-002');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('Error handling', () => {
|
|
65
|
+
it('should throw an error when OPENAI_API_KEY is not set', () => {
|
|
66
|
+
delete process.env.OPENAI_API_KEY;
|
|
67
|
+
|
|
68
|
+
expect(() => getChatOpenAiModel()).toThrow();
|
|
69
|
+
expect(() => getOpenAiEmbeddings()).toThrow();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|