@breadstone/archipel-mcp 0.0.54 → 0.0.56
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/data/guides/ai-image-generation.md +101 -0
- package/data/guides/ai-realtime-voice.md +85 -473
- package/data/guides/ai-text-generation.md +98 -635
- package/data/guides/health-indicators.md +67 -66
- package/data/guides/index.md +2 -1
- package/data/guides/intelligence-prompts-warm-up.md +81 -312
- package/data/packages/platform-intelligence/api/Class.AnthropicIntelligenceProviderAdapter.md +122 -0
- package/data/packages/platform-intelligence/api/Class.GatewayIntelligenceProviderAdapter.md +122 -0
- package/data/packages/platform-intelligence/api/Class.GoogleIntelligenceProviderAdapter.md +122 -0
- package/data/packages/platform-intelligence/api/Class.GrokIntelligenceProviderAdapter.md +122 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceAgent.md +95 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceAgentFactory.md +11 -23
- package/data/packages/platform-intelligence/api/Class.IntelligenceEmbeddingGenerator.md +25 -21
- package/data/packages/platform-intelligence/api/Class.IntelligenceHealthIndicator.md +15 -10
- package/data/packages/platform-intelligence/api/Class.IntelligenceImageGenerator.md +117 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceLanguageGenerator.md +159 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceModule.md +2 -2
- package/data/packages/platform-intelligence/api/Class.IntelligencePromptExecutor.md +6 -6
- package/data/packages/platform-intelligence/api/Class.IntelligencePromptPolicyPort.md +1 -1
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderAdapterPort.md +104 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderAssetUploader.md +21 -15
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderDiagnostics.md +55 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderError.md +14 -4
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderRegistry.md +68 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeError.md +9 -9
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeMeteringPort.md +1 -1
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionFactory.md +8 -8
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionPort.md +18 -18
- package/data/packages/platform-intelligence/api/Class.IntelligenceReranker.md +58 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceSpeechGenerator.md +117 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolBase.md +14 -16
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolRegistry.md +14 -18
- package/data/packages/platform-intelligence/api/Class.IntelligenceTranscriptionGenerator.md +139 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceVideoGenerator.md +117 -0
- package/data/packages/platform-intelligence/api/Class.MiMoIntelligenceProviderAdapter.md +122 -0
- package/data/packages/platform-intelligence/api/Class.OpenAIIntelligenceProviderAdapter.md +122 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicAdvisor20260301Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250522Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250825Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20260120Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20251124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicMemory20250818Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250429Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250728Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchBM2520251119Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchRegex20251119Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20250910Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20260209Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20250305Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20260209Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleCodeExecutionTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleEnterpriseWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleMapsTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleUrlContextTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleVertexRagStoreTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokCodeExecutionTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokMcpServerTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokViewImageTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokViewXVideoTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokXSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createIntelligenceJsonSchema.md +31 -0
- package/data/packages/platform-intelligence/api/Function.createIntelligenceTool.md +2 -2
- package/data/packages/platform-intelligence/api/Function.createMimoCustomTool.md +5 -5
- package/data/packages/platform-intelligence/api/Function.createOpenAIApplyPatchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAICodeInterpreterTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAICustomTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIImageGenerationTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAILocalShellTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIMcpTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIShellTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIToolSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchPreviewTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.defineIntelligenceTool.md +31 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceAgentConfiguration.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingBatchOptions.md +140 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingBatchResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingOptions.md +130 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFileUploadOptions.md +118 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFileUploadResult.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceGeneratedFile.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceGenerationStepStartEvent.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceImageGenerationOptions.md +186 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceImageGenerationResult.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageCompletion.md +141 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageGenerationOptions.md +250 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageStream.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelReference.md +34 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelRequestOptions.md +72 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelStatus.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModuleOptions.md +54 -26
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceObjectStream.md +56 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePrompt.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptDefinition.md +14 -14
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptEffectivePolicy.md +1 -1
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionPolicy.md +1 -1
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionResult.md +15 -27
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderConfiguration.md +10 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderLoadRequest.md +54 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderProbeResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeModuleOptions.md +9 -21
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeSessionOptions.md +23 -11
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeUsage.md +174 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRequestOptions.md +114 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRerankingOptions.md +156 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRerankingResult.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSkillUploadOptions.md +110 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSkillUploadResult.md +80 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSpeechGenerationOptions.md +180 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSpeechGenerationResult.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceStreamingTranscriptionOptions.md +155 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTool.md +7 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolCall.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolDefinition.md +91 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolExecutionEndEvent.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolExecutionStartEvent.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolRegistry.md +4 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionOptions.md +130 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionResult.md +84 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionStream.md +97 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceUsage.md +197 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceVideoGenerationOptions.md +245 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceVideoGenerationResult.md +50 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligenceModelMessage.md +43 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligencePromptModelRequirement.md +2 -2
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligenceSchema.md +70 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceCapability.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceDefaultModels.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceJsonValue.md +22 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptDefinitionConfiguration.md +2 -2
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptGenerationOptions.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderName.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderOptions.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderProbeStatus.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderToolOptions.md +17 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeMeteringEvent.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRequestTimeouts.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolChoice.md +21 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolOutput.md +22 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolSet.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTranscriptionStreamPart.md +46 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_API_KEY.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_BASE_URL.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MAX_OUTPUT_TOKENS.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MODEL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_PROVIDER.md +2 -2
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TEMPERATURE.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TOP_P.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.IntelligenceCapabilityNames.md +40 -0
- package/data/packages/platform-intelligence/api/Variable.IntelligenceProviderNames.md +2 -0
- package/data/packages/platform-intelligence/api/Variable.PLATFORM_INTELLIGENCE_CONFIG_ENTRIES.md +2 -2
- package/data/packages/platform-intelligence/api/index.md +83 -32
- package/data/packages/platform-intelligence/index.md +81 -622
- package/package.json +1 -1
- package/data/packages/index.md +0 -8
- package/data/packages/platform-analytics/index.md +0 -209
- package/data/packages/platform-authentication/index.md +0 -725
- package/data/packages/platform-blob-storage/index.md +0 -416
- package/data/packages/platform-bootstrap/index.md +0 -162
- package/data/packages/platform-caching/index.md +0 -167
- package/data/packages/platform-configuration/index.md +0 -226
- package/data/packages/platform-core/index.md +0 -504
- package/data/packages/platform-cryptography/index.md +0 -142
- package/data/packages/platform-database/index.md +0 -337
- package/data/packages/platform-documents/index.md +0 -255
- package/data/packages/platform-esigning/index.md +0 -710
- package/data/packages/platform-feature-flags/index.md +0 -103
- package/data/packages/platform-health/index.md +0 -141
- package/data/packages/platform-intelligence/api/Class.IntelligenceMediaGenerator.md +0 -118
- package/data/packages/platform-intelligence/api/Class.IntelligenceStructuredGenerator.md +0 -70
- package/data/packages/platform-intelligence/api/Class.IntelligenceTelemetryRegistry.md +0 -44
- package/data/packages/platform-intelligence/api/Class.IntelligenceTextGenerator.md +0 -138
- package/data/packages/platform-intelligence/api/Function.createProviderOptions.md +0 -39
- package/data/packages/platform-intelligence/api/Function.loadAnthropicLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGoogleLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGoogleRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Function.loadGrokLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGrokRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Function.loadMimoLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadOpenAILanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadOpenAIRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCompletionUsage.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextCompletion.md +0 -180
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerationOptions.md +0 -144
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerator.md +0 -78
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextStreamingOptions.md +0 -170
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoader.md +0 -24
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoaders.md +0 -14
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoader.md +0 -25
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoaders.md +0 -14
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTextStream.md +0 -14
- package/data/packages/platform-logging/index.md +0 -150
- package/data/packages/platform-mailing/index.md +0 -470
- package/data/packages/platform-mapping/index.md +0 -123
- package/data/packages/platform-mcp/index.md +0 -335
- package/data/packages/platform-openapi/index.md +0 -207
- package/data/packages/platform-payments/index.md +0 -610
- package/data/packages/platform-queue/index.md +0 -192
- package/data/packages/platform-reporting/index.md +0 -233
- package/data/packages/platform-resources/index.md +0 -137
- package/data/packages/platform-telemetry/index.md +0 -262
|
@@ -1,687 +1,150 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: AI
|
|
3
|
-
description: Generate text
|
|
2
|
+
title: AI Language Generation
|
|
3
|
+
description: Generate text and structured output, stream results, use tools, and create agents without leaking provider SDKs.
|
|
4
4
|
order: 15
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
# AI
|
|
7
|
+
# AI Language Generation
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
`IntelligenceLanguageGenerator` is the provider-neutral language facade. It
|
|
10
|
+
owns plain text, schema-constrained objects, streaming, tool execution, result
|
|
11
|
+
normalization, retries, cancellation, and timeouts.
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
execution policy, and a NestJS executor, start with
|
|
13
|
-
[Intelligence Prompts Warm-up](./intelligence-prompts-warm-up).
|
|
14
|
-
|
|
15
|
-
For server-owned, bidirectional audio and text connections, use the separate
|
|
16
|
-
[AI Realtime Voice](./ai-realtime-voice) guide. Realtime sessions have a
|
|
17
|
-
different transport, lifecycle, persistence, and metering model from request-
|
|
18
|
-
or response-scoped text generation.
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
13
|
+
Consumer applications depend only on Archipel:
|
|
23
14
|
|
|
24
15
|
```bash
|
|
25
16
|
yarn add @breadstone/archipel-platform-intelligence
|
|
26
17
|
```
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
| Provider | Package |
|
|
31
|
-
| -------------- | ------------------- |
|
|
32
|
-
| **OpenAI** | `@ai-sdk/openai` |
|
|
33
|
-
| **Anthropic** | `@ai-sdk/anthropic` |
|
|
34
|
-
| **Google** | `@ai-sdk/google` |
|
|
35
|
-
| **Grok (xAI)** | `@ai-sdk/xai` |
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# Example: OpenAI
|
|
39
|
-
yarn add @ai-sdk/openai
|
|
40
|
-
|
|
41
|
-
# Example: Grok / xAI
|
|
42
|
-
yarn add @ai-sdk/xai
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Module Registration
|
|
48
|
-
|
|
49
|
-
Import `IntelligenceModule` into your application module. It exposes `IntelligenceTextGenerator` and `IntelligenceToolRegistry` as shared providers.
|
|
19
|
+
## Registration
|
|
50
20
|
|
|
51
21
|
```typescript
|
|
52
22
|
import { Module } from '@nestjs/common';
|
|
53
|
-
import { IntelligenceModule, IntelligenceProviderNames } from '@breadstone/archipel-platform-intelligence';
|
|
54
|
-
import {
|
|
23
|
+
import { IntelligenceCapabilityNames, IntelligenceModule, IntelligenceProviderNames } from '@breadstone/archipel-platform-intelligence';
|
|
24
|
+
import { ANTHROPIC_CONFIG_ENTRIES, AnthropicIntelligenceProviderAdapter } from '@breadstone/archipel-platform-intelligence/provider/anthropic';
|
|
25
|
+
import { OPENAI_CONFIG_ENTRIES, OpenAIIntelligenceProviderAdapter } from '@breadstone/archipel-platform-intelligence/provider/openai';
|
|
55
26
|
|
|
56
27
|
@Module({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Configuration
|
|
73
|
-
|
|
74
|
-
All intelligence settings are read from environment variables via `ConfigService`. No direct `process.env` access is needed.
|
|
75
|
-
|
|
76
|
-
```dotenv
|
|
77
|
-
INTELLIGENCE_PROVIDER=openai
|
|
78
|
-
INTELLIGENCE_MODEL=gpt-4o-mini
|
|
79
|
-
INTELLIGENCE_API_KEY=sk-...
|
|
80
|
-
INTELLIGENCE_TEMPERATURE=0.7
|
|
81
|
-
INTELLIGENCE_TOP_P=1
|
|
82
|
-
INTELLIGENCE_MAX_OUTPUT_TOKENS=1024
|
|
83
|
-
INTELLIGENCE_BASE_URL= # optional — override for custom endpoints
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Supported Providers
|
|
87
|
-
|
|
88
|
-
| `INTELLIGENCE_PROVIDER` | Default model | Notes |
|
|
89
|
-
| ----------------------- | -------------------------- | ---------------------------------- |
|
|
90
|
-
| `openai` | `gpt-4o-mini` | OpenAI API |
|
|
91
|
-
| `anthropic` | `claude-sonnet-4-20250514` | Anthropic API |
|
|
92
|
-
| `google` | `gemini-2.0-flash` | Google Gemini API |
|
|
93
|
-
| `grok` | `grok-3-mini` | xAI Grok API |
|
|
94
|
-
|
|
95
|
-
Each provider resolves its API key and base URL from dedicated environment variables when the generic `INTELLIGENCE_API_KEY` is not set:
|
|
96
|
-
|
|
97
|
-
```dotenv
|
|
98
|
-
# Provider-specific keys (optional — fallback from INTELLIGENCE_API_KEY)
|
|
99
|
-
OPENAI_API_KEY=sk-...
|
|
100
|
-
ANTHROPIC_API_KEY=sk-ant-...
|
|
101
|
-
GOOGLE_API_KEY=AI...
|
|
102
|
-
GROK_API_KEY=xai-...
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## Generating Text
|
|
108
|
-
|
|
109
|
-
Inject `IntelligenceTextGenerator` to generate completions:
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
import { Injectable } from '@nestjs/common';
|
|
113
|
-
import type { Prompt } from 'ai';
|
|
114
|
-
import { IntelligenceTextGenerator, type IIntelligenceTextCompletion } from '@breadstone/archipel-platform-intelligence';
|
|
115
|
-
|
|
116
|
-
@Injectable()
|
|
117
|
-
export class SummaryService {
|
|
118
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
119
|
-
|
|
120
|
-
constructor(textGenerator: IntelligenceTextGenerator) {
|
|
121
|
-
this._textGenerator = textGenerator;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public async summarize(content: string): Promise<string> {
|
|
125
|
-
const prompt: Prompt = {
|
|
126
|
-
system: 'You are a concise summarizer. Respond with a short summary.',
|
|
127
|
-
messages: [{ role: 'user', content: content }],
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const completion = await this._textGenerator.generateText(prompt);
|
|
131
|
-
|
|
132
|
-
return completion.text;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Prompt Structure
|
|
138
|
-
|
|
139
|
-
A prompt uses the native AI SDK `Prompt` type. Use either a string prompt or a full message array:
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
type Prompt =
|
|
143
|
-
| { readonly system?: string; readonly prompt: string }
|
|
144
|
-
| { readonly system?: string; readonly messages: Array<ModelMessage> };
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Per-Request Overrides
|
|
148
|
-
|
|
149
|
-
Override generation parameters for individual requests without changing the global configuration:
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
const completion = await this._textGenerator.generateText(prompt, {
|
|
153
|
-
temperature: 0.2, // more deterministic
|
|
154
|
-
maxOutputTokens: 256, // shorter responses
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### Completion Response
|
|
159
|
-
|
|
160
|
-
The response includes the generated text, the provider/model used, provider-native sources, generated files, and optional token usage telemetry:
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
interface IIntelligenceTextCompletion {
|
|
164
|
-
readonly text: string;
|
|
165
|
-
readonly provider: string;
|
|
166
|
-
readonly model: string;
|
|
167
|
-
readonly sources: ReadonlyArray<LanguageModelV3Source>;
|
|
168
|
-
readonly files: ReadonlyArray<GeneratedFile>;
|
|
169
|
-
readonly usage: IIntelligenceCompletionUsage | null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
interface IIntelligenceCompletionUsage {
|
|
173
|
-
readonly promptTokens: number | null;
|
|
174
|
-
readonly completionTokens: number | null;
|
|
175
|
-
readonly totalTokens: number | null;
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## Multi-Turn Conversations
|
|
182
|
-
|
|
183
|
-
Build multi-turn conversations by passing the full message history:
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
const prompt: Prompt = {
|
|
187
|
-
system: 'You are a helpful fitness coach.',
|
|
188
|
-
messages: [
|
|
189
|
-
{ role: 'user', content: 'What should I eat before a workout?' },
|
|
190
|
-
{ role: 'assistant', content: 'A balanced meal with carbs and protein about 2 hours before.' },
|
|
191
|
-
{ role: 'user', content: 'Can you give me a specific example?' },
|
|
192
|
-
],
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const completion = await this._textGenerator.generateText(prompt);
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
|
-
## Tool Registration
|
|
201
|
-
|
|
202
|
-
The intelligence module uses native AI SDK tools. Define a class that exposes a `name` and a native `Tool`, or register provider-native tool wrappers from provider subpaths.
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
import { Injectable, Module } from '@nestjs/common';
|
|
206
|
-
import { tool, type Tool } from 'ai';
|
|
207
|
-
import { z } from 'zod';
|
|
208
|
-
import { IntelligenceModule, IntelligenceProviderNames, IntelligenceToolBase } from '@breadstone/archipel-platform-intelligence';
|
|
209
|
-
import { loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
210
|
-
|
|
211
|
-
interface IWorkoutInput {
|
|
212
|
-
readonly goal: string;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
interface IWorkoutOutput {
|
|
216
|
-
readonly recommendation: string;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
@Injectable()
|
|
220
|
-
export class WorkoutRecommendationTool extends IntelligenceToolBase<IWorkoutInput, IWorkoutOutput> {
|
|
221
|
-
public override get name(): string {
|
|
222
|
-
return 'recommendWorkout';
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public override get tool(): Tool<IWorkoutInput, IWorkoutOutput> {
|
|
226
|
-
return tool({
|
|
227
|
-
description: 'Recommends a workout plan for a user goal.',
|
|
228
|
-
inputSchema: z.object({
|
|
229
|
-
goal: z.string().describe('The user fitness goal'),
|
|
230
|
-
}),
|
|
231
|
-
execute: async (input) => ({
|
|
232
|
-
recommendation: `Workout plan for ${input.goal}`,
|
|
233
|
-
}),
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
@Module({
|
|
239
|
-
imports: [
|
|
240
|
-
IntelligenceModule.register({
|
|
241
|
-
providerLoaders: {
|
|
242
|
-
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
243
|
-
},
|
|
244
|
-
tools: [WorkoutRecommendationTool],
|
|
245
|
-
}),
|
|
246
|
-
],
|
|
28
|
+
imports: [
|
|
29
|
+
IntelligenceModule.register({
|
|
30
|
+
configEntries: [...OPENAI_CONFIG_ENTRIES, ...ANTHROPIC_CONFIG_ENTRIES],
|
|
31
|
+
providerAdapters: [OpenAIIntelligenceProviderAdapter, AnthropicIntelligenceProviderAdapter],
|
|
32
|
+
defaultModels: {
|
|
33
|
+
[IntelligenceCapabilityNames.Language]: {
|
|
34
|
+
provider: IntelligenceProviderNames.OpenAI,
|
|
35
|
+
model: 'gpt-5.4-mini',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
247
40
|
})
|
|
248
|
-
export class
|
|
41
|
+
export class ApplicationModule {}
|
|
249
42
|
```
|
|
250
43
|
|
|
251
|
-
|
|
44
|
+
## Text and Objects
|
|
252
45
|
|
|
253
46
|
```typescript
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
47
|
+
const completion = await language.generateText(
|
|
48
|
+
{
|
|
49
|
+
system: 'Answer using the supplied application context only.',
|
|
50
|
+
prompt: 'Summarize the open tasks.',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
maxOutputTokens: 800,
|
|
54
|
+
maxRetries: 2,
|
|
55
|
+
},
|
|
56
|
+
);
|
|
258
57
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
},
|
|
265
|
-
tools: [createOpenAIWebSearchTool({ searchContextSize: 'medium' })],
|
|
58
|
+
const structured = await language.generateObject(
|
|
59
|
+
{ prompt: 'Classify the customer request.' },
|
|
60
|
+
z.object({
|
|
61
|
+
category: z.enum(['billing', 'technical', 'other']),
|
|
62
|
+
urgency: z.enum(['low', 'normal', 'high']),
|
|
266
63
|
}),
|
|
267
|
-
|
|
268
|
-
})
|
|
269
|
-
export class SearchModule {}
|
|
64
|
+
);
|
|
270
65
|
```
|
|
271
66
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
Archipel is not intended to be a closed subset of the AI SDK. `IntelligenceTextGenerator.generateText()` and `streamText()` accept native AI SDK `Prompt` objects directly. Their options extend the native AI SDK call options, while Archipel still contributes provider configuration, registered tool merging, timeout defaults, logging, and normalized completion metadata.
|
|
67
|
+
Applications can provide a model override as
|
|
68
|
+
`{ provider: string, model: string }`. They never construct a provider-native
|
|
69
|
+
model.
|
|
277
70
|
|
|
278
|
-
|
|
71
|
+
## Streaming
|
|
279
72
|
|
|
280
73
|
```typescript
|
|
281
|
-
|
|
282
|
-
import { Injectable, Module } from '@nestjs/common';
|
|
283
|
-
import { IntelligenceModule, IntelligenceTextGenerator, type IIntelligenceTextCompletion } from '@breadstone/archipel-platform-intelligence';
|
|
284
|
-
|
|
285
|
-
@Module({
|
|
286
|
-
imports: [
|
|
287
|
-
IntelligenceModule.register({
|
|
288
|
-
validateOnModuleInit: false,
|
|
289
|
-
}),
|
|
290
|
-
],
|
|
291
|
-
})
|
|
292
|
-
export class RawAiSdkModule {}
|
|
293
|
-
|
|
294
|
-
@Injectable()
|
|
295
|
-
export class RawAiSdkRecipeService {
|
|
296
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
74
|
+
const stream = await language.streamText({ prompt: 'Explain the result.' });
|
|
297
75
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
public async generateWithNativeAiSdkOptions(): Promise<IIntelligenceTextCompletion> {
|
|
303
|
-
return this._textGenerator.generateText(
|
|
304
|
-
{
|
|
305
|
-
system: 'Answer concisely and include assumptions.',
|
|
306
|
-
prompt: 'Compare the operational risks of outdoor work tomorrow.',
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
model: openai.responses('gpt-5'),
|
|
310
|
-
headers: { 'x-use-case': 'outdoor-risk' },
|
|
311
|
-
providerOptions: {
|
|
312
|
-
openai: {
|
|
313
|
-
reasoningEffort: 'medium',
|
|
314
|
-
},
|
|
315
|
-
},
|
|
316
|
-
seed: 42,
|
|
317
|
-
},
|
|
318
|
-
);
|
|
319
|
-
}
|
|
76
|
+
for await (const delta of stream.textStream) {
|
|
77
|
+
sendToAuthenticatedClient(delta);
|
|
320
78
|
}
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
If every request passes a native AI SDK model, `validateOnModuleInit: false` avoids requiring platform provider configuration at startup. If no `model` option is supplied, the configured provider loader and `INTELLIGENCE_PROVIDER` / `INTELLIGENCE_MODEL` values still define the model.
|
|
324
|
-
|
|
325
|
-
### Additional OpenAI Tool Recipes
|
|
326
|
-
|
|
327
|
-
The same pattern works for other provider-defined OpenAI tools. Register the provider tool wrapper on the module when it is available to the whole use case, or pass request-specific tools through `generateText()` when the tool needs request data such as a `fileId`.
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
import { Injectable } from '@nestjs/common';
|
|
331
|
-
import { stepCountIs, tool } from 'ai';
|
|
332
|
-
import { z } from 'zod';
|
|
333
|
-
import { IntelligenceTextGenerator } from '@breadstone/archipel-platform-intelligence';
|
|
334
|
-
import { OpenAIIntelligenceToolNames } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
335
|
-
import {
|
|
336
|
-
createOpenAICodeInterpreterTool,
|
|
337
|
-
createOpenAICustomTool,
|
|
338
|
-
createOpenAIImageGenerationTool,
|
|
339
|
-
createOpenAIToolSearchTool,
|
|
340
|
-
} from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
341
|
-
|
|
342
|
-
@Injectable()
|
|
343
|
-
export class OpenAIToolRecipeService {
|
|
344
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
345
|
-
|
|
346
|
-
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
347
|
-
this._textGenerator = textGenerator;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
public async analyseSpreadsheet(fileId: string): Promise<IIntelligenceTextCompletion> {
|
|
351
|
-
return this._textGenerator.generateText(
|
|
352
|
-
{
|
|
353
|
-
system: 'You analyze uploaded spreadsheets and explain unusual values clearly.',
|
|
354
|
-
messages: [
|
|
355
|
-
{
|
|
356
|
-
role: 'user',
|
|
357
|
-
content: 'Analyze the file, detect unusual values, and summarize the most important findings as a table.',
|
|
358
|
-
},
|
|
359
|
-
],
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
activeTools: [OpenAIIntelligenceToolNames.CodeInterpreter],
|
|
363
|
-
tools: {
|
|
364
|
-
[OpenAIIntelligenceToolNames.CodeInterpreter]: createOpenAICodeInterpreterTool({
|
|
365
|
-
container: { fileIds: [fileId] },
|
|
366
|
-
}).tool,
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
public async generateIllustration(description: string): Promise<IIntelligenceTextCompletion> {
|
|
373
|
-
return this._textGenerator.generateText(
|
|
374
|
-
{
|
|
375
|
-
prompt: description,
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
activeTools: [OpenAIIntelligenceToolNames.ImageGeneration],
|
|
379
|
-
tools: {
|
|
380
|
-
[OpenAIIntelligenceToolNames.ImageGeneration]: createOpenAIImageGenerationTool({
|
|
381
|
-
quality: 'medium',
|
|
382
|
-
size: '1024x1024',
|
|
383
|
-
}).tool,
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
79
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
{
|
|
392
|
-
prompt: prompt,
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
stopWhen: stepCountIs(10),
|
|
396
|
-
tools: {
|
|
397
|
-
[OpenAIIntelligenceToolNames.ToolSearch]: createOpenAIToolSearchTool().tool,
|
|
398
|
-
get_birthdays: tool({
|
|
399
|
-
description: 'Returns employee birthdays in a date range.',
|
|
400
|
-
inputSchema: z.object({
|
|
401
|
-
from: z.string(),
|
|
402
|
-
to: z.string(),
|
|
403
|
-
}),
|
|
404
|
-
execute: async (input) => ({ from: input.from, to: input.to, employees: [] }),
|
|
405
|
-
providerOptions: {
|
|
406
|
-
openai: { deferLoading: true },
|
|
407
|
-
},
|
|
408
|
-
}),
|
|
409
|
-
search_orders: tool({
|
|
410
|
-
description: 'Searches orders using domain-specific filters.',
|
|
411
|
-
inputSchema: z.object({
|
|
412
|
-
query: z.string(),
|
|
413
|
-
}),
|
|
414
|
-
execute: async (input) => ({ query: input.query, orders: [] }),
|
|
415
|
-
providerOptions: {
|
|
416
|
-
openai: { deferLoading: true },
|
|
417
|
-
},
|
|
418
|
-
}),
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
public async createReadOnlyReportQuery(prompt: string): Promise<IIntelligenceTextCompletion> {
|
|
425
|
-
return this._textGenerator.generateText(
|
|
426
|
-
{
|
|
427
|
-
system: 'Create only read-only reporting queries. The query must start with SELECT.',
|
|
428
|
-
messages: [{ role: 'user', content: prompt }],
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
toolChoice: 'required',
|
|
432
|
-
stopWhen: stepCountIs(3),
|
|
433
|
-
activeTools: ['report_query'],
|
|
434
|
-
tools: {
|
|
435
|
-
report_query: createOpenAICustomTool({
|
|
436
|
-
name: 'report_query',
|
|
437
|
-
description: 'Create a strictly read-only reporting query.',
|
|
438
|
-
format: {
|
|
439
|
-
type: 'grammar',
|
|
440
|
-
syntax: 'regex',
|
|
441
|
-
definition: 'SELECT .+',
|
|
442
|
-
},
|
|
443
|
-
}).tool,
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
80
|
+
const finalText = await stream.text;
|
|
81
|
+
const usage = await stream.usage;
|
|
449
82
|
```
|
|
450
83
|
|
|
451
|
-
`
|
|
452
|
-
|
|
453
|
-
|
|
84
|
+
`streamObject()` exposes partial structured output and a validated final object.
|
|
85
|
+
All stream iterables and result promises normalize provider failures as
|
|
86
|
+
`IntelligenceProviderError`.
|
|
454
87
|
|
|
455
|
-
|
|
88
|
+
## Application Tools
|
|
456
89
|
|
|
457
90
|
```typescript
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
IntelligenceModule,
|
|
463
|
-
IntelligenceProviderNames,
|
|
464
|
-
IntelligenceTextGenerator,
|
|
465
|
-
IntelligenceToolBase,
|
|
466
|
-
type IIntelligenceTextCompletion,
|
|
467
|
-
} from '@breadstone/archipel-platform-intelligence';
|
|
468
|
-
import { OpenAIIntelligenceToolNames, loadOpenAILanguageModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
|
|
469
|
-
import { createOpenAIWebSearchTool } from '@breadstone/archipel-platform-intelligence/providers/openai/tools';
|
|
470
|
-
|
|
471
|
-
interface IOutdoorOrderLookupInput {
|
|
472
|
-
readonly date: string;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
interface IOutdoorOrder {
|
|
476
|
-
readonly id: string;
|
|
477
|
-
readonly location: string;
|
|
478
|
-
readonly scheduledAt: string;
|
|
479
|
-
readonly outdoorWork: boolean;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
interface IOutdoorOrderLookupOutput {
|
|
483
|
-
readonly date: string;
|
|
484
|
-
readonly orders: ReadonlyArray<IOutdoorOrder>;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
@Injectable()
|
|
488
|
-
export class OutdoorOrdersTool extends IntelligenceToolBase<IOutdoorOrderLookupInput, IOutdoorOrderLookupOutput> {
|
|
489
|
-
public override get name(): string {
|
|
490
|
-
return 'get_outdoor_orders';
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
public override get tool(): Tool<IOutdoorOrderLookupInput, IOutdoorOrderLookupOutput> {
|
|
494
|
-
return tool({
|
|
495
|
-
description: 'Returns outdoor field orders for the current tenant and date.',
|
|
496
|
-
inputSchema: z.object({
|
|
497
|
-
date: z.string().describe('Date in YYYY-MM-DD format'),
|
|
498
|
-
}),
|
|
499
|
-
execute: async (input: IOutdoorOrderLookupInput) => this.loadOutdoorOrders(input.date),
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
private async loadOutdoorOrders(date: string): Promise<IOutdoorOrderLookupOutput> {
|
|
504
|
-
return {
|
|
505
|
-
date: date,
|
|
506
|
-
orders: [
|
|
507
|
-
{
|
|
508
|
-
id: 'ord_4711',
|
|
509
|
-
location: 'Berlin',
|
|
510
|
-
scheduledAt: `${date}T08:00:00+02:00`,
|
|
511
|
-
outdoorWork: true,
|
|
512
|
-
},
|
|
513
|
-
],
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
@Injectable()
|
|
519
|
-
export class OutdoorOrderRiskAnalysisService {
|
|
520
|
-
private readonly _textGenerator: IntelligenceTextGenerator;
|
|
521
|
-
|
|
522
|
-
public constructor(textGenerator: IntelligenceTextGenerator) {
|
|
523
|
-
this._textGenerator = textGenerator;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
public async analyseOutdoorOrders(date: string): Promise<{ readonly text: string; readonly sources: IIntelligenceTextCompletion['sources'] }> {
|
|
527
|
-
const result = await this._textGenerator.generateText(
|
|
528
|
-
{
|
|
529
|
-
system: 'You assess weather-related risks for tenant outdoor field orders.',
|
|
530
|
-
messages: [
|
|
531
|
-
{
|
|
532
|
-
role: 'user',
|
|
533
|
-
content: `Review outdoor field orders for ${date} and flag weather-related risks.`,
|
|
534
|
-
},
|
|
535
|
-
],
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
toolChoice: 'auto',
|
|
539
|
-
activeTools: ['get_outdoor_orders', OpenAIIntelligenceToolNames.WebSearch],
|
|
540
|
-
stopWhen: stepCountIs(3),
|
|
541
|
-
},
|
|
542
|
-
);
|
|
91
|
+
export class CustomerSearchTool extends IntelligenceToolBase<ICustomerSearchInput, ReadonlyArray<ICustomerSummary>> {
|
|
92
|
+
public override get name(): string {
|
|
93
|
+
return 'customer_search';
|
|
94
|
+
}
|
|
543
95
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
96
|
+
public override get tool() {
|
|
97
|
+
return defineIntelligenceTool({
|
|
98
|
+
description: 'Searches customers visible to the authenticated tenant.',
|
|
99
|
+
inputSchema: createIntelligenceJsonSchema<ICustomerSearchInput>({
|
|
100
|
+
type: 'object',
|
|
101
|
+
properties: { query: { type: 'string' } },
|
|
102
|
+
required: ['query'],
|
|
103
|
+
additionalProperties: false,
|
|
104
|
+
}),
|
|
105
|
+
execute: async ({ query }) => this._customers.search(query),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
549
108
|
}
|
|
550
|
-
|
|
551
|
-
@Module({
|
|
552
|
-
imports: [
|
|
553
|
-
IntelligenceModule.register({
|
|
554
|
-
providerLoaders: {
|
|
555
|
-
[IntelligenceProviderNames.OpenAI]: loadOpenAILanguageModel,
|
|
556
|
-
},
|
|
557
|
-
tools: [
|
|
558
|
-
OutdoorOrdersTool,
|
|
559
|
-
createOpenAIWebSearchTool({
|
|
560
|
-
externalWebAccess: true,
|
|
561
|
-
searchContextSize: 'medium',
|
|
562
|
-
filters: {
|
|
563
|
-
allowedDomains: ['dwd.de'],
|
|
564
|
-
},
|
|
565
|
-
}),
|
|
566
|
-
],
|
|
567
|
-
}),
|
|
568
|
-
],
|
|
569
|
-
providers: [OutdoorOrderRiskAnalysisService],
|
|
570
|
-
})
|
|
571
|
-
export class OutdoorOrderRiskAnalysisModule {}
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
Use AI SDK request options to constrain tool use per call:
|
|
575
|
-
|
|
576
|
-
```typescript
|
|
577
|
-
const completion = await this._textGenerator.generateText(prompt, {
|
|
578
|
-
toolChoice: 'auto',
|
|
579
|
-
activeTools: ['recommendWorkout'],
|
|
580
|
-
});
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
> **Capacity limit:** The registry enforces a maximum of **128** registered tools.
|
|
584
|
-
|
|
585
|
-
---
|
|
586
|
-
|
|
587
|
-
## Streaming Text
|
|
588
|
-
|
|
589
|
-
`streamText()` uses the same provider configuration and registered tools as `generateText()` and returns the native AI SDK stream result.
|
|
590
|
-
|
|
591
|
-
```typescript
|
|
592
|
-
const stream = await this._textGenerator.streamText(prompt, {
|
|
593
|
-
activeTools: ['recommendWorkout'],
|
|
594
|
-
stopWhen: stepCountIs(3),
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
return stream.toUIMessageStreamResponse();
|
|
598
109
|
```
|
|
599
110
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
Retrieve the resolved provider configuration at runtime:
|
|
605
|
-
|
|
606
|
-
```typescript
|
|
607
|
-
const config = this._textGenerator.getConfiguration();
|
|
608
|
-
console.log(config.provider); // 'openai'
|
|
609
|
-
console.log(config.model); // 'gpt-4o-mini'
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
---
|
|
613
|
-
|
|
614
|
-
## Error Handling
|
|
615
|
-
|
|
616
|
-
`IntelligenceTextGenerator` wraps all provider errors in `IntelligenceProviderError`, which includes `provider`, `model`, and `retryable` metadata. The generator automatically retries retryable failures (e.g. transient network errors) with exponential backoff before giving up.
|
|
617
|
-
|
|
618
|
-
Two additional error classes handle configuration and validation failures:
|
|
111
|
+
Register tools through `IntelligenceModule.register({ tools: [...] })`. Use
|
|
112
|
+
`activeToolNames` to constrain a call and `maxSteps` to bound the tool loop.
|
|
113
|
+
Tool authorization remains application-owned and must fail closed before data
|
|
114
|
+
or side effects are exposed.
|
|
619
115
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
| `IntelligenceValidationError` | `INTELLIGENCE_VALIDATION` | Invalid generation parameters (temperature, topP, maxOutputTokens) |
|
|
624
|
-
| `IntelligenceConfigurationError` | `INTELLIGENCE_CONFIGURATION` | Unsupported provider, missing API key, or missing provider loader |
|
|
116
|
+
Provider-owned tools are imported from Archipel provider `/tools` subpaths.
|
|
117
|
+
They are represented by opaque Archipel definitions; their native SDK types do
|
|
118
|
+
not cross into the application.
|
|
625
119
|
|
|
626
|
-
|
|
120
|
+
## Agents
|
|
627
121
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
| `timeoutMs` | `30000` | Abort the provider request after this many milliseconds |
|
|
631
|
-
| Max retries | `2` | Retryable errors are retried up to 2 times |
|
|
632
|
-
| Backoff | 1s → 4s | Exponential backoff with a 4-second cap between retries |
|
|
633
|
-
|
|
634
|
-
Override the timeout per call:
|
|
122
|
+
`IntelligenceAgentFactory.create()` builds a reusable bounded agent on the same
|
|
123
|
+
language facade:
|
|
635
124
|
|
|
636
125
|
```typescript
|
|
637
|
-
const
|
|
638
|
-
|
|
126
|
+
const agent = agents.create({
|
|
127
|
+
name: 'researcher',
|
|
128
|
+
instructions: 'Use approved sources and report uncertainty.',
|
|
129
|
+
activeToolNames: ['web_search', 'document_search'],
|
|
130
|
+
maxSteps: 6,
|
|
639
131
|
});
|
|
640
|
-
```
|
|
641
|
-
|
|
642
|
-
### Catching Errors
|
|
643
|
-
|
|
644
|
-
```typescript
|
|
645
|
-
import { IntelligenceProviderError } from '@breadstone/archipel-platform-intelligence';
|
|
646
132
|
|
|
647
|
-
|
|
648
|
-
const result = await this._textGenerator.generateText(prompt);
|
|
649
|
-
return result.text;
|
|
650
|
-
} catch (error) {
|
|
651
|
-
if (error instanceof IntelligenceProviderError) {
|
|
652
|
-
this._logger.error(`Provider ${error.provider}/${error.model} failed`, {
|
|
653
|
-
retryable: error.retryable,
|
|
654
|
-
message: error.message,
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
return 'Sorry, I could not generate a response right now.';
|
|
658
|
-
}
|
|
133
|
+
const answer = await agent.generate({ prompt: question });
|
|
659
134
|
```
|
|
660
135
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
---
|
|
136
|
+
Agents do not create a second provider abstraction. They compose language,
|
|
137
|
+
tools, model policy, and step limits already owned by Archipel.
|
|
664
138
|
|
|
665
|
-
##
|
|
139
|
+
## Results and Failures
|
|
666
140
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
141
|
+
Language completions expose provider, model, text, typed output, finish reason,
|
|
142
|
+
reasoning text, normalized sources and files, tool calls/results, warnings, and
|
|
143
|
+
usage. Usage contains provider-neutral input, output, total, cache-read,
|
|
144
|
+
cache-write, reasoning, and available modality counters. A `null` counter means
|
|
145
|
+
the provider did not report it and must not be interpreted as measured zero.
|
|
146
|
+
The default total-operation timeout is 30 seconds.
|
|
673
147
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
ProviderLoaders[Registered Provider Loaders\nproviders/openai, providers/anthropic, providers/google, providers/grok]
|
|
678
|
-
FeatureTools[Feature Tools\nnative AI SDK tools]
|
|
679
|
-
|
|
680
|
-
TextGenerator --> GenerateText
|
|
681
|
-
TextGenerator --> StreamText
|
|
682
|
-
ToolRegistry --> ResolveTools
|
|
683
|
-
TextGenerator --> ProviderLoaders
|
|
684
|
-
ToolRegistry --> FeatureTools
|
|
685
|
-
GenerateText --> ToolRegistry
|
|
686
|
-
StreamText --> ToolRegistry
|
|
687
|
-
```
|
|
148
|
+
Provider failures use `IntelligenceProviderError`; invalid prompts and options
|
|
149
|
+
use `IntelligenceValidationError`; missing adapters or capability defaults use
|
|
150
|
+
`IntelligenceConfigurationError`.
|