@breadstone/archipel-mcp 0.0.52 → 0.0.54

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.
Files changed (59) hide show
  1. package/data/guides/ai-realtime-voice.md +506 -0
  2. package/data/guides/ai-text-generation.md +9 -0
  3. package/data/guides/health-indicators.md +12 -3
  4. package/data/guides/index.md +6 -4
  5. package/data/guides/intelligence-prompts-warm-up.md +358 -0
  6. package/data/packages/platform-health/index.md +1 -1
  7. package/data/packages/platform-intelligence/api/Class.DefaultIntelligencePromptPolicyAdapter.md +54 -0
  8. package/data/packages/platform-intelligence/api/Class.IntelligenceHealthIndicator.md +6 -5
  9. package/data/packages/platform-intelligence/api/Class.IntelligenceModule.md +2 -2
  10. package/data/packages/platform-intelligence/api/Class.IntelligencePromptExecutor.md +88 -0
  11. package/data/packages/platform-intelligence/api/Class.IntelligencePromptPolicyPort.md +48 -0
  12. package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeError.md +110 -0
  13. package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeMeteringPort.md +47 -0
  14. package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionFactory.md +129 -0
  15. package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionPort.md +308 -0
  16. package/data/packages/platform-intelligence/api/Class.IntelligenceTextGenerator.md +6 -6
  17. package/data/packages/platform-intelligence/api/Function.intelligencePrompt.md +31 -0
  18. package/data/packages/platform-intelligence/api/Function.loadGoogleRealtimeModel.md +25 -0
  19. package/data/packages/platform-intelligence/api/Function.loadGrokRealtimeModel.md +25 -0
  20. package/data/packages/platform-intelligence/api/Function.loadOpenAIRealtimeModel.md +25 -0
  21. package/data/packages/platform-intelligence/api/Interface.IIntelligenceModuleOptions.md +30 -6
  22. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptDefinition.md +145 -0
  23. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptEffectivePolicy.md +30 -0
  24. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionContext.md +20 -0
  25. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionPolicy.md +70 -0
  26. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionResult.md +139 -0
  27. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptInvocation.md +49 -0
  28. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptPolicyRequest.md +60 -0
  29. package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptRenderContext.md +26 -0
  30. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeAudioFormat.md +34 -0
  31. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeCloseEvent.md +40 -0
  32. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeModuleOptions.md +120 -0
  33. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeSessionConfiguration.md +135 -0
  34. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeSessionOptions.md +148 -0
  35. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeToolDefinition.md +58 -0
  36. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeTranscriptionConfiguration.md +46 -0
  37. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeTurnDetectionConfiguration.md +58 -0
  38. package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeUsage.md +103 -0
  39. package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextCompletion.md +24 -12
  40. package/data/packages/platform-intelligence/api/TypeAlias.IIntelligencePromptModelRequirement.md +25 -0
  41. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptCapability.md +20 -0
  42. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptDefinitionConfiguration.md +29 -0
  43. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptGenerationOptions.md +16 -0
  44. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptLatency.md +14 -0
  45. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptMode.md +14 -0
  46. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptQuality.md +14 -0
  47. package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptReasoning.md +14 -0
  48. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeClientEvent.md +64 -0
  49. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeMetadataValue.md +14 -0
  50. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeMeteringEvent.md +44 -0
  51. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoader.md +25 -0
  52. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoaders.md +14 -0
  53. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeServerEvent.md +159 -0
  54. package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeStatus.md +14 -0
  55. package/data/packages/platform-intelligence/api/index.md +43 -0
  56. package/data/packages/platform-intelligence/index.md +211 -7
  57. package/data/patterns/index.md +1 -0
  58. package/data/patterns/realtime-session-pattern.md +309 -0
  59. package/package.json +1 -1
@@ -0,0 +1,159 @@
1
+ ---
2
+ title: 'Type Alias: IntelligenceRealtimeServerEvent'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Type Alias: IntelligenceRealtimeServerEvent
7
+
8
+ ```ts
9
+ type IntelligenceRealtimeServerEvent =
10
+ | {
11
+ raw: unknown;
12
+ sessionId?: string;
13
+ type: "session-created";
14
+ }
15
+ | {
16
+ raw: unknown;
17
+ type: "session-updated";
18
+ }
19
+ | {
20
+ itemId?: string;
21
+ raw: unknown;
22
+ type: "speech-started";
23
+ }
24
+ | {
25
+ itemId?: string;
26
+ raw: unknown;
27
+ type: "speech-stopped";
28
+ }
29
+ | {
30
+ itemId?: string;
31
+ previousItemId?: string;
32
+ raw: unknown;
33
+ type: "audio-committed";
34
+ }
35
+ | {
36
+ item: unknown;
37
+ itemId: string;
38
+ raw: unknown;
39
+ type: "conversation-item-added";
40
+ }
41
+ | {
42
+ itemId: string;
43
+ raw: unknown;
44
+ transcript: string;
45
+ type: "input-transcription-completed";
46
+ }
47
+ | {
48
+ raw: unknown;
49
+ responseId: string;
50
+ type: "response-created";
51
+ }
52
+ | {
53
+ raw: unknown;
54
+ responseId: string;
55
+ status: string;
56
+ type: "response-done";
57
+ }
58
+ | {
59
+ itemId: string;
60
+ raw: unknown;
61
+ responseId: string;
62
+ type: "output-item-added";
63
+ }
64
+ | {
65
+ itemId: string;
66
+ raw: unknown;
67
+ responseId: string;
68
+ type: "output-item-done";
69
+ }
70
+ | {
71
+ itemId: string;
72
+ raw: unknown;
73
+ responseId: string;
74
+ type: "content-part-added";
75
+ }
76
+ | {
77
+ itemId: string;
78
+ raw: unknown;
79
+ responseId: string;
80
+ type: "content-part-done";
81
+ }
82
+ | {
83
+ delta: string;
84
+ itemId: string;
85
+ raw: unknown;
86
+ responseId: string;
87
+ type: "audio-delta";
88
+ }
89
+ | {
90
+ itemId: string;
91
+ raw: unknown;
92
+ responseId: string;
93
+ type: "audio-done";
94
+ }
95
+ | {
96
+ delta: string;
97
+ itemId: string;
98
+ raw: unknown;
99
+ responseId: string;
100
+ type: "audio-transcript-delta";
101
+ }
102
+ | {
103
+ itemId: string;
104
+ raw: unknown;
105
+ responseId: string;
106
+ transcript?: string;
107
+ type: "audio-transcript-done";
108
+ }
109
+ | {
110
+ delta: string;
111
+ itemId: string;
112
+ raw: unknown;
113
+ responseId: string;
114
+ type: "text-delta";
115
+ }
116
+ | {
117
+ itemId: string;
118
+ raw: unknown;
119
+ responseId: string;
120
+ text?: string;
121
+ type: "text-done";
122
+ }
123
+ | {
124
+ callId: string;
125
+ delta: string;
126
+ itemId: string;
127
+ raw: unknown;
128
+ responseId: string;
129
+ type: "function-call-arguments-delta";
130
+ }
131
+ | {
132
+ arguments: string;
133
+ callId: string;
134
+ itemId: string;
135
+ name: string;
136
+ raw: unknown;
137
+ responseId: string;
138
+ type: "function-call-arguments-done";
139
+ }
140
+ | {
141
+ code?: string;
142
+ message: string;
143
+ raw: unknown;
144
+ type: "error";
145
+ }
146
+ | {
147
+ raw: unknown;
148
+ rawType: string;
149
+ type: "custom";
150
+ };
151
+ ```
152
+
153
+ Defined in: [realtime/contracts/IntelligenceRealtimeServerEvent.ts:10](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-intelligence/src/realtime/contracts/IntelligenceRealtimeServerEvent.ts#L10)
154
+
155
+ Provider-neutral event emitted by a realtime model.
156
+
157
+ The original provider event remains available through `raw` for audited
158
+ provider-specific diagnostics without leaking provider contracts into the
159
+ normal application flow.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Type Alias: IntelligenceRealtimeStatus'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Type Alias: IntelligenceRealtimeStatus
7
+
8
+ ```ts
9
+ type IntelligenceRealtimeStatus = "idle" | "connecting" | "connected" | "closing" | "closed" | "error";
10
+ ```
11
+
12
+ Defined in: [realtime/contracts/IntelligenceRealtimeStatus.ts:6](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-intelligence/src/realtime/contracts/IntelligenceRealtimeStatus.ts#L6)
13
+
14
+ Describes the lifecycle state of an upstream realtime model connection.
@@ -9,14 +9,21 @@ editUrl: false
9
9
 
10
10
  | Class | Description |
11
11
  | ------ | ------ |
12
+ | [DefaultIntelligencePromptPolicyAdapter](Class.DefaultIntelligencePromptPolicyAdapter) | Default prompt policy that supports native settings and automatic model selection. |
12
13
  | [IntelligenceAgentFactory](Class.IntelligenceAgentFactory) | Creates AI SDK 7 tool-loop agents with platform-registered tools merged in. |
13
14
  | [IntelligenceConfigurationError](Class.IntelligenceConfigurationError) | Error thrown when an intelligence provider configuration is invalid or missing. |
14
15
  | [IntelligenceEmbeddingGenerator](Class.IntelligenceEmbeddingGenerator) | Executes AI SDK embedding operations. |
15
16
  | [IntelligenceHealthIndicator](Class.IntelligenceHealthIndicator) | Health indicator for the intelligence infrastructure. Verifies that the intelligence provider configuration can be resolved. |
16
17
  | [IntelligenceMediaGenerator](Class.IntelligenceMediaGenerator) | Executes AI SDK media generation and understanding operations. |
17
18
  | [IntelligenceModule](Class.IntelligenceModule) | Core module exposing the shared intelligence infrastructure. |
19
+ | [IntelligencePromptExecutor](Class.IntelligencePromptExecutor) | Validates and executes reusable intelligence prompt invocations. |
20
+ | [IntelligencePromptPolicyPort](Class.IntelligencePromptPolicyPort) | Resolves provider-neutral prompt requirements into effective generation settings. |
18
21
  | [IntelligenceProviderAssetUploader](Class.IntelligenceProviderAssetUploader) | Uploads provider-managed files and skills for reuse in AI SDK calls. |
19
22
  | [IntelligenceProviderError](Class.IntelligenceProviderError) | Error thrown when an intelligence provider call fails. |
23
+ | [IntelligenceRealtimeError](Class.IntelligenceRealtimeError) | Error raised by a realtime session, transport, or metering adapter. |
24
+ | [IntelligenceRealtimeMeteringPort](Class.IntelligenceRealtimeMeteringPort) | Application port for idempotently persisting realtime billing and audit events. |
25
+ | [IntelligenceRealtimeSessionFactory](Class.IntelligenceRealtimeSessionFactory) | Creates and owns server-side, provider-neutral realtime AI sessions. |
26
+ | [IntelligenceRealtimeSessionPort](Class.IntelligenceRealtimeSessionPort) | Provider-neutral control surface for one realtime model connection. |
20
27
  | [IntelligenceStructuredGenerator](Class.IntelligenceStructuredGenerator) | Executes AI SDK structured-output generation. |
21
28
  | [IntelligenceTelemetryRegistry](Class.IntelligenceTelemetryRegistry) | Registers AI SDK telemetry integrations for the current process. |
22
29
  | [IntelligenceTextGenerator](Class.IntelligenceTextGenerator) | Executes text completions using the configured intelligence provider. |
@@ -30,7 +37,24 @@ editUrl: false
30
37
  | ------ | ------ |
31
38
  | [IIntelligenceCompletionUsage](Interface.IIntelligenceCompletionUsage) | Captures usage telemetry returned by the intelligence provider. |
32
39
  | [IIntelligenceModuleOptions](Interface.IIntelligenceModuleOptions) | Options for configuring the intelligence module. |
40
+ | [IIntelligencePromptDefinition](Interface.IIntelligencePromptDefinition) | Reusable, immutable definition of an intelligence prompt. |
41
+ | [IIntelligencePromptEffectivePolicy](Interface.IIntelligencePromptEffectivePolicy) | Effective settings resolved for one prompt execution. |
42
+ | [IIntelligencePromptExecutionContext](Interface.IIntelligencePromptExecutionContext) | Application context made available to prompt policy adapters. |
43
+ | [IIntelligencePromptExecutionPolicy](Interface.IIntelligencePromptExecutionPolicy) | Native settings and provider-neutral requirements declared by an intelligence prompt. |
44
+ | [IIntelligencePromptExecutionResult](Interface.IIntelligencePromptExecutionResult) | Normalized result of an intelligence prompt execution. |
45
+ | [IIntelligencePromptInvocation](Interface.IIntelligencePromptInvocation) | Bound prompt definition ready for execution. |
46
+ | [IIntelligencePromptPolicyRequest](Interface.IIntelligencePromptPolicyRequest) | Policy resolution request for one prompt invocation. |
47
+ | [IIntelligencePromptRenderContext](Interface.IIntelligencePromptRenderContext) | Input exposed to pure prompt rendering functions. |
33
48
  | [IIntelligenceProviderConfiguration](Interface.IIntelligenceProviderConfiguration) | Describes the resolved configuration for the intelligence provider. |
49
+ | [IIntelligenceRealtimeAudioFormat](Interface.IIntelligenceRealtimeAudioFormat) | Provider-neutral audio format configuration. |
50
+ | [IIntelligenceRealtimeCloseEvent](Interface.IIntelligenceRealtimeCloseEvent) | Describes why an upstream realtime connection closed. |
51
+ | [IIntelligenceRealtimeModuleOptions](Interface.IIntelligenceRealtimeModuleOptions) | Module-level resilience and resource limits for realtime intelligence. |
52
+ | [IIntelligenceRealtimeSessionConfiguration](Interface.IIntelligenceRealtimeSessionConfiguration) | Provider-neutral configuration for a realtime AI session. |
53
+ | [IIntelligenceRealtimeSessionOptions](Interface.IIntelligenceRealtimeSessionOptions) | Options used to create one server-owned realtime model connection. |
54
+ | [IIntelligenceRealtimeToolDefinition](Interface.IIntelligenceRealtimeToolDefinition) | Provider-neutral function definition exposed to a realtime model. |
55
+ | [IIntelligenceRealtimeTranscriptionConfiguration](Interface.IIntelligenceRealtimeTranscriptionConfiguration) | Provider-neutral transcription configuration. |
56
+ | [IIntelligenceRealtimeTurnDetectionConfiguration](Interface.IIntelligenceRealtimeTurnDetectionConfiguration) | Provider-neutral voice activity detection configuration. |
57
+ | [IIntelligenceRealtimeUsage](Interface.IIntelligenceRealtimeUsage) | Normalized token usage reported by a realtime provider. |
34
58
  | [IIntelligenceTextCompletion](Interface.IIntelligenceTextCompletion) | Represents the normalized completion result produced by the intelligence provider. |
35
59
  | [IIntelligenceTextGenerationOptions](Interface.IIntelligenceTextGenerationOptions) | Options that can be supplied when generating text with the intelligence provider. |
36
60
  | [IIntelligenceTextGenerator](Interface.IIntelligenceTextGenerator) | Abstraction responsible for executing text completions using the configured provider. |
@@ -42,9 +66,24 @@ editUrl: false
42
66
 
43
67
  | Type Alias | Description |
44
68
  | ------ | ------ |
69
+ | [IIntelligencePromptModelRequirement](TypeAlias.IIntelligencePromptModelRequirement) | Model selection requested by a reusable intelligence prompt. |
45
70
  | [IntelligenceLanguageModelLoader](TypeAlias.IntelligenceLanguageModelLoader) | Represents a factory responsible for creating a configured language model instance. |
46
71
  | [IntelligenceLanguageModelLoaders](TypeAlias.IntelligenceLanguageModelLoaders) | Maps configured intelligence providers to their tree-shakable model loader. |
72
+ | [IntelligencePromptCapability](TypeAlias.IntelligencePromptCapability) | Provider-neutral capability required by an intelligence prompt. |
73
+ | [IntelligencePromptDefinitionConfiguration](TypeAlias.IntelligencePromptDefinitionConfiguration) | Configuration accepted by [intelligencePrompt](Function.intelligencePrompt). |
74
+ | [IntelligencePromptGenerationOptions](TypeAlias.IntelligencePromptGenerationOptions) | Native generation settings that can be stored on a prompt definition. |
75
+ | [IntelligencePromptLatency](TypeAlias.IntelligencePromptLatency) | Latency profile requested by an intelligence prompt. |
76
+ | [IntelligencePromptMode](TypeAlias.IntelligencePromptMode) | Supported execution modes for reusable intelligence prompts. |
77
+ | [IntelligencePromptQuality](TypeAlias.IntelligencePromptQuality) | Provider-neutral model quality requested by an intelligence prompt. |
78
+ | [IntelligencePromptReasoning](TypeAlias.IntelligencePromptReasoning) | Provider-neutral reasoning effort requested by an intelligence prompt. |
47
79
  | [IntelligenceProviderName](TypeAlias.IntelligenceProviderName) | Represents the union of supported intelligence provider identifiers. |
80
+ | [IntelligenceRealtimeClientEvent](TypeAlias.IntelligenceRealtimeClientEvent) | Provider-neutral event sent from an application to a realtime model. |
81
+ | [IntelligenceRealtimeMetadataValue](TypeAlias.IntelligenceRealtimeMetadataValue) | Serializable metadata copied into realtime metering events. |
82
+ | [IntelligenceRealtimeMeteringEvent](TypeAlias.IntelligenceRealtimeMeteringEvent) | Durable metering event emitted by an Archipel realtime session. |
83
+ | [IntelligenceRealtimeModelLoader](TypeAlias.IntelligenceRealtimeModelLoader) | Creates a configured Vercel AI SDK realtime model behind the Archipel facade. |
84
+ | [IntelligenceRealtimeModelLoaders](TypeAlias.IntelligenceRealtimeModelLoaders) | Maps configured intelligence providers to tree-shakable realtime model loaders. |
85
+ | [IntelligenceRealtimeServerEvent](TypeAlias.IntelligenceRealtimeServerEvent) | Provider-neutral event emitted by a realtime model. |
86
+ | [IntelligenceRealtimeStatus](TypeAlias.IntelligenceRealtimeStatus) | Describes the lifecycle state of an upstream realtime model connection. |
48
87
  | [IntelligenceTextStream](TypeAlias.IntelligenceTextStream) | Native AI SDK streaming result returned by the intelligence text generator. |
49
88
 
50
89
  ## Variables
@@ -135,8 +174,12 @@ editUrl: false
135
174
  | [createOpenAIWebSearchPreviewTool](Function.createOpenAIWebSearchPreviewTool) | Creates an OpenAI web-search-preview tool registration. |
136
175
  | [createOpenAIWebSearchTool](Function.createOpenAIWebSearchTool) | Creates an OpenAI web-search tool registration. |
137
176
  | [createProviderOptions](Function.createProviderOptions) | Creates the provider options object consumed by the AI SDK model factories. |
177
+ | [intelligencePrompt](Function.intelligencePrompt) | Creates a reusable intelligence prompt definition. |
138
178
  | [loadAnthropicLanguageModel](Function.loadAnthropicLanguageModel) | Creates the Anthropic language model from the resolved provider configuration. |
139
179
  | [loadGoogleLanguageModel](Function.loadGoogleLanguageModel) | Creates the Google Gemini language model from the resolved provider configuration. |
180
+ | [loadGoogleRealtimeModel](Function.loadGoogleRealtimeModel) | Creates a Google Gemini Live model exclusively through the Vercel AI SDK provider. |
140
181
  | [loadGrokLanguageModel](Function.loadGrokLanguageModel) | Creates the Grok language model through the native xAI provider. |
182
+ | [loadGrokRealtimeModel](Function.loadGrokRealtimeModel) | Creates an xAI Grok voice model exclusively through the Vercel AI SDK provider. |
141
183
  | [loadMimoLanguageModel](Function.loadMimoLanguageModel) | Creates the Xiaomi MiMo language model from the resolved provider configuration. |
142
184
  | [loadOpenAILanguageModel](Function.loadOpenAILanguageModel) | Creates the OpenAI language model from the resolved provider configuration. |
185
+ | [loadOpenAIRealtimeModel](Function.loadOpenAIRealtimeModel) | Creates an OpenAI realtime model exclusively through the Vercel AI SDK provider. |
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  title: platform-intelligence
3
- description: Multi-provider AI text generation, streaming, and tool calling.
3
+ description: Multi-provider AI text generation, streaming, realtime voice, metering, and tool calling.
4
4
  order: 16
5
- tags: [intelligence, ai, openai, anthropic, google, grok, text-generation, streaming, tool-calling, health]
5
+ tags: [intelligence, ai, openai, anthropic, google, grok, text-generation, streaming, realtime, voice, metering, tool-calling, health]
6
6
  package: '@breadstone/archipel-platform-intelligence'
7
7
  ---
8
8
 
9
9
  # platform-intelligence
10
10
 
11
- Multi-provider AI text generation library supporting OpenAI, Anthropic, Google Generative AI, and Grok. Tool orchestration is delegated to the AI SDK through native and provider-defined tool definitions, `toolChoice`, `activeTools`, and `stopWhen`. Advanced use cases can pass native AI SDK prompts, request-level models, provider options, headers, telemetry, output settings, and step hooks through the platform generator.
11
+ Multi-provider AI library supporting text generation and server-owned realtime voice sessions through OpenAI, Anthropic, Google Generative AI, and Grok. Tool orchestration is delegated to the AI SDK through native and provider-defined tool definitions, `toolChoice`, `activeTools`, and `stopWhen`. Advanced use cases can pass native AI SDK prompts, request-level models, provider options, headers, telemetry, output settings, and step hooks through the platform generator.
12
12
 
13
13
  **Package:** `@breadstone/archipel-platform-intelligence`
14
14
 
@@ -35,6 +35,204 @@ export class AppModule {}
35
35
 
36
36
  ---
37
37
 
38
+ ## Reusable Prompts
39
+
40
+ Use `intelligencePrompt()` to keep a prompt's identity, version, schemas,
41
+ instructions, messages, and execution requirements in one pure definition.
42
+ Bind already prepared feature data with `.with(...)` and execute the resulting
43
+ invocation through the NestJS `IntelligencePromptExecutor`.
44
+
45
+ For a guided first implementation, see
46
+ [Intelligence Prompts Warm-up](/guides/intelligence-prompts-warm-up).
47
+
48
+ ```typescript
49
+ import { Injectable } from '@nestjs/common';
50
+ import { z } from 'zod';
51
+ import {
52
+ intelligencePrompt,
53
+ IntelligencePromptExecutor,
54
+ } from '@breadstone/archipel-platform-intelligence';
55
+
56
+ const DuplicateDetectionPrompt = intelligencePrompt({
57
+ name: 'crm.duplicate-detection',
58
+ version: 1,
59
+ mode: 'object',
60
+ inputSchema: z.object({
61
+ sourceId: z.number().int(),
62
+ candidateIds: z.array(z.number().int()),
63
+ }),
64
+ outputSchema: z.object({
65
+ scores: z.array(z.object({
66
+ id: z.number().int(),
67
+ score: z.number().min(0).max(100),
68
+ })),
69
+ }),
70
+ system: () => [
71
+ 'Score duplicate candidates using only the supplied fields.',
72
+ 'Do not infer facts from missing data.',
73
+ ],
74
+ messages: ({ input }) => [
75
+ { role: 'user', content: JSON.stringify(input) },
76
+ ],
77
+ execution: {
78
+ options: { temperature: 0, maxOutputTokens: 800 },
79
+ model: { strategy: 'automatic' },
80
+ requiredCapabilities: ['structuredOutput'],
81
+ },
82
+ });
83
+
84
+ export function duplicateDetectionPrompt(sourceId: number, candidateIds: ReadonlyArray<number>) {
85
+ return DuplicateDetectionPrompt.with({ sourceId, candidateIds });
86
+ }
87
+
88
+ @Injectable()
89
+ export class DuplicateDetectionService {
90
+ public constructor(private readonly prompts: IntelligencePromptExecutor) {}
91
+
92
+ public async score(sourceId: number, candidateIds: ReadonlyArray<number>) {
93
+ const execution = await this.prompts.execute(
94
+ duplicateDetectionPrompt(sourceId, candidateIds),
95
+ );
96
+
97
+ return execution.output.scores;
98
+ }
99
+ }
100
+ ```
101
+
102
+ The schemas use the AI SDK `FlexibleSchema` contract. Object mode requires an
103
+ output schema and uses AI SDK 7 `Output.object()`; text mode has no output
104
+ schema and returns a string. Input and completed object output are validated at
105
+ runtime.
106
+
107
+ Native AI SDK settings work with the default policy. Applications that declare
108
+ provider-neutral quality, reasoning, latency, preferred models, or fixed model
109
+ identifiers register an `IntelligencePromptPolicyPort` adapter through
110
+ `IntelligenceModule.register({ promptPolicyAdapter })`. Execution results
111
+ contain requested and effective policy, provider, model, usage, reasoning, and
112
+ invocation metadata for application-owned billing and auditing.
113
+
114
+ ---
115
+
116
+ ## Realtime Voice
117
+
118
+ Archipel owns the upstream provider WebSocket and exposes normalized audio,
119
+ text, transcription, response, and tool events through
120
+ `IntelligenceRealtimeSessionPort`. The consuming backend can place its normal
121
+ authentication, authorization, tenant isolation, persistence, and client
122
+ WebSocket in front of this port. Provider credentials and short-lived tokens
123
+ never need to reach the browser.
124
+
125
+ The complete application integration is documented in
126
+ [AI Realtime Voice](/guides/ai-realtime-voice); the reusable ownership,
127
+ durability, and recovery rules are documented in the
128
+ [Realtime Session Pattern](/patterns/realtime-session-pattern).
129
+
130
+ The implementation uses the experimental realtime model contract in Vercel AI
131
+ SDK 7. OpenAI, Google, and xAI are loaded through Archipel provider subpaths;
132
+ consuming applications do not import the official OpenAI SDK or make direct
133
+ provider calls.
134
+
135
+ ```typescript
136
+ import { Injectable, Module } from '@nestjs/common';
137
+ import {
138
+ IntelligenceModule,
139
+ IntelligenceProviderNames,
140
+ } from '@breadstone/archipel-platform-intelligence';
141
+ import {
142
+ IntelligenceRealtimeMeteringPort,
143
+ IntelligenceRealtimeSessionFactory,
144
+ type IntelligenceRealtimeMeteringEvent,
145
+ } from '@breadstone/archipel-platform-intelligence/realtime';
146
+ import { loadOpenAIRealtimeModel } from '@breadstone/archipel-platform-intelligence/providers/openai';
147
+ import { loadGoogleRealtimeModel } from '@breadstone/archipel-platform-intelligence/providers/google';
148
+ import { loadGrokRealtimeModel } from '@breadstone/archipel-platform-intelligence/providers/grok';
149
+
150
+ @Injectable()
151
+ export class RealtimeMeteringAdapter extends IntelligenceRealtimeMeteringPort {
152
+ public async report(event: IntelligenceRealtimeMeteringEvent): Promise<void> {
153
+ await persistIdempotently(event.eventId, event);
154
+ }
155
+ }
156
+
157
+ @Module({
158
+ imports: [
159
+ IntelligenceModule.register({
160
+ validateOnModuleInit: false,
161
+ realtime: {
162
+ providerLoaders: {
163
+ [IntelligenceProviderNames.OpenAI]: loadOpenAIRealtimeModel,
164
+ [IntelligenceProviderNames.Google]: loadGoogleRealtimeModel,
165
+ [IntelligenceProviderNames.Grok]: loadGrokRealtimeModel,
166
+ },
167
+ meteringAdapter: RealtimeMeteringAdapter,
168
+ meteringIntervalMs: 30_000,
169
+ },
170
+ }),
171
+ ],
172
+ })
173
+ export class RealtimeModule {}
174
+
175
+ @Injectable()
176
+ export class RealtimeConsultationService {
177
+ public constructor(private readonly sessions: IntelligenceRealtimeSessionFactory) {}
178
+
179
+ public async open(consultationId: string): Promise<void> {
180
+ const session = await this.sessions.createSession({
181
+ sessionId: consultationId,
182
+ model: 'gpt-realtime',
183
+ sessionConfiguration: {
184
+ instructions: 'Transcribe the consultation and answer concisely.',
185
+ inputAudioFormat: { type: 'audio/pcm', rate: 24_000 },
186
+ inputAudioTranscription: {},
187
+ outputModalities: ['text', 'audio'],
188
+ turnDetection: { type: 'server-vad' },
189
+ },
190
+ onEvent: forwardToAuthenticatedClient,
191
+ });
192
+
193
+ await session.connect();
194
+ }
195
+ }
196
+ ```
197
+
198
+ | Provider | Archipel loader | Example model |
199
+ | --- | --- | --- |
200
+ | OpenAI | `loadOpenAIRealtimeModel` | `gpt-realtime` |
201
+ | Google | `loadGoogleRealtimeModel` | `gemini-3.1-flash-live-preview` |
202
+ | xAI / Grok | `loadGrokRealtimeModel` | `grok-voice-latest` |
203
+
204
+ ### Metering and audit
205
+
206
+ The application-supplied `IntelligenceRealtimeMeteringPort` receives four
207
+ idempotently identifiable event types:
208
+
209
+ | Event | Meaning |
210
+ | --- | --- |
211
+ | `session-started` | One upstream provider connection opened |
212
+ | `billing-interval` | Elapsed provider-independent usage, every 30 seconds by default and once more for the final partial interval |
213
+ | `provider-usage` | Exact token and modality counts when present in the raw provider event |
214
+ | `session-ended` | Connection duration and close reason |
215
+
216
+ An application can debit its own token ledger and append its AI audit log in
217
+ the same transaction keyed by `eventId`. Time-based charging remains available
218
+ when a provider omits exact usage; exact token usage remains available for cost
219
+ reconciliation when reported.
220
+
221
+ ### Failure and persistence rules
222
+
223
+ - Provider token requests and WebSocket setup are capped at five seconds and
224
+ transient token creation is retried at most twice.
225
+ - Inbound, outbound, metering, and WebSocket buffers are bounded.
226
+ - Normalized events preserve provider wire order.
227
+ - Nest shutdown closes all owned sessions and flushes metering.
228
+ - Archipel does not silently reconnect a lost provider conversation because a
229
+ new connection has different conversational state.
230
+ - The consuming application must persist audio chunks and transcript progress
231
+ durably before acknowledging them, then reconstruct context when it opens a
232
+ replacement provider session.
233
+
234
+ ---
235
+
38
236
  ## Provider Subpaths
39
237
 
40
238
  Import only the providers you need:
@@ -359,11 +557,12 @@ All errors are wrapped in `IntelligenceProviderError` with `provider`, `model`,
359
557
 
360
558
  ## Error Handling
361
559
 
362
- The library provides three domain error classes for different failure scenarios:
560
+ The library provides domain error classes for different failure scenarios:
363
561
 
364
562
  | Error class | Code | When thrown |
365
563
  | ---------------------------------- | ----------------------------- | --------------------------------------------------------------------- |
366
564
  | `IntelligenceProviderError` | `INTELLIGENCE_PROVIDER` | Provider SDK failures during text generation |
565
+ | `IntelligenceRealtimeError` | Realtime phase metadata | Configuration, token, connect, send, receive, metering, or close failures |
367
566
  | `IntelligenceValidationError` | `INTELLIGENCE_VALIDATION` | Invalid generation parameters (temperature, topP, maxOutputTokens) |
368
567
  | `IntelligenceConfigurationError` | `INTELLIGENCE_CONFIGURATION` | Unsupported provider, missing API key, or missing provider loader |
369
568
 
@@ -379,7 +578,12 @@ import {
379
578
 
380
579
  ## Lifecycle
381
580
 
382
- `IntelligenceTextGenerator` implements `OnModuleInit` and validates the provider configuration plus registered provider loader eagerly at startup. Missing API keys, unsupported providers, or missing loaders throw `IntelligenceConfigurationError` before the first request is processed.
581
+ `IntelligenceTextGenerator` implements `OnModuleInit` and validates the provider configuration plus registered provider loader eagerly at startup. Missing API keys, unsupported providers, or missing loaders throw `IntelligenceConfigurationError` before the first request is processed. `IntelligenceRealtimeSessionFactory` implements `OnModuleDestroy`, closes all owned provider WebSockets, and flushes queued metering on shutdown.
582
+
583
+ Set `validateOnModuleInit: false` for a realtime-only module because that option
584
+ controls eager text-model initialization. When text and realtime are both
585
+ used, register the language-model loaders and keep the default eager
586
+ validation.
383
587
 
384
588
  ---
385
589
 
@@ -391,7 +595,7 @@ import {
391
595
 
392
596
  ## Health Check
393
597
 
394
- The `IntelligenceHealthIndicator` verifies that provider configuration can be resolved. If no text generator is available, it reports `disabled: true`. Import it from the `/health` subpath:
598
+ The `IntelligenceHealthIndicator` verifies that provider configuration can be resolved and reports registered realtime providers plus active session count. If neither text nor realtime infrastructure is available, it reports `disabled: true`. Import it from the `/health` subpath:
395
599
 
396
600
  ```typescript
397
601
  import { IntelligenceModule, IntelligenceProviderNames } from '@breadstone/archipel-platform-intelligence';
@@ -414,7 +618,7 @@ export class AppModule {}
414
618
 
415
619
  | Key | Check | Dependencies |
416
620
  | --- | ----- | ------------ |
417
- | `intelligence` | `up` when provider configuration resolves, else `down` | `@Optional() IntelligenceTextGenerator` |
621
+ | `intelligence` | `up` when provider configuration resolves, else `down`; includes realtime readiness when registered | `@Optional() IntelligenceTextGenerator`, `@Optional() IntelligenceRealtimeSessionFactory` |
418
622
 
419
623
  ---
420
624
 
@@ -19,3 +19,4 @@ These patterns document repeatable implementation shapes used across Archipel. U
19
19
  | [Repository Pattern](./repository-pattern) | `RepositoryBase` subclasses and Prisma delegate isolation. |
20
20
  | [Testing Pattern](./testing-pattern) | Vitest structure, mocks, and integration test conventions. |
21
21
  | [Bootstrap Pattern](./bootstrap-pattern) | Composable NestJS startup with `PlatformApplication` and `PlatformBootstrapStep`. |
22
+ | [Realtime Session Pattern](./realtime-session-pattern) | Long-lived connection ownership, per-fragment durability, metering, backpressure, and recovery. |