@talex-touch/utils 1.0.39 → 1.0.42

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.
@@ -1,4 +1,7 @@
1
- export enum AiProviderType {
1
+ /**
2
+ * Supported intelligence provider types.
3
+ */
4
+ export enum IntelligenceProviderType {
2
5
  OPENAI = 'openai',
3
6
  ANTHROPIC = 'anthropic',
4
7
  DEEPSEEK = 'deepseek',
@@ -7,295 +10,1710 @@ export enum AiProviderType {
7
10
  CUSTOM = 'custom',
8
11
  }
9
12
 
10
- export enum AiCapabilityType {
13
+ /**
14
+ * Intelligence capability types for various AI operations.
15
+ */
16
+ export enum IntelligenceCapabilityType {
17
+ // Text capabilities
11
18
  CHAT = 'chat',
12
19
  COMPLETION = 'completion',
13
20
  EMBEDDING = 'embedding',
14
21
  SUMMARIZE = 'summarize',
15
22
  TRANSLATE = 'translate',
23
+ REWRITE = 'rewrite',
24
+ GRAMMAR_CHECK = 'grammar-check',
25
+ // Code capabilities
26
+ CODE_GENERATE = 'code-generate',
27
+ CODE_EXPLAIN = 'code-explain',
28
+ CODE_REVIEW = 'code-review',
29
+ CODE_REFACTOR = 'code-refactor',
30
+ CODE_DEBUG = 'code-debug',
31
+ // Analysis capabilities
32
+ INTENT_DETECT = 'intent-detect',
33
+ SENTIMENT_ANALYZE = 'sentiment-analyze',
34
+ CONTENT_EXTRACT = 'content-extract',
35
+ KEYWORDS_EXTRACT = 'keywords-extract',
36
+ CLASSIFICATION = 'classification',
37
+ // Audio capabilities
16
38
  TTS = 'tts',
17
39
  STT = 'stt',
40
+ AUDIO_TRANSCRIBE = 'audio-transcribe',
41
+ // Vision capabilities
18
42
  VISION = 'vision',
43
+ VISION_OCR = 'vision-ocr',
44
+ IMAGE_CAPTION = 'image-caption',
45
+ IMAGE_ANALYZE = 'image-analyze',
46
+ IMAGE_GENERATE = 'image-generate',
47
+ IMAGE_EDIT = 'image-edit',
48
+ // RAG & Search capabilities
49
+ RAG_QUERY = 'rag-query',
50
+ SEMANTIC_SEARCH = 'semantic-search',
51
+ RERANK = 'rerank',
52
+ // Workflow capabilities
53
+ WORKFLOW = 'workflow',
54
+ AGENT = 'agent',
19
55
  }
20
56
 
21
- export interface AiProviderRateLimit {
57
+ /**
58
+ * Rate limit configuration for an intelligence provider.
59
+ */
60
+ export interface IntelligenceProviderRateLimit {
61
+ /** Maximum requests allowed per minute. */
22
62
  requestsPerMinute?: number
63
+ /** Maximum requests allowed per day. */
23
64
  requestsPerDay?: number
65
+ /** Maximum tokens allowed per minute. */
24
66
  tokensPerMinute?: number
67
+ /** Maximum tokens allowed per day. */
25
68
  tokensPerDay?: number
26
69
  }
27
70
 
28
- export interface AiVisionImageSource {
71
+ /**
72
+ * Image source configuration for vision capabilities.
73
+ */
74
+ export interface IntelligenceVisionImageSource {
75
+ /** Source type: data URL, file path, or base64 encoded. */
29
76
  type: 'data-url' | 'file' | 'base64'
77
+ /** Data URL of the image. */
30
78
  dataUrl?: string
79
+ /** File path to the image. */
31
80
  filePath?: string
81
+ /** Base64 encoded image data. */
32
82
  base64?: string
33
83
  }
34
84
 
35
- export interface AiVisionOcrBlock {
85
+ /**
86
+ * OCR text block detected in an image.
87
+ */
88
+ export interface IntelligenceVisionOcrBlock {
89
+ /** Unique identifier for the block. */
36
90
  id?: string
91
+ /** Detected text content. */
37
92
  text: string
93
+ /** Detected language of the text. */
38
94
  language?: string
95
+ /** Confidence score (0-1). */
39
96
  confidence?: number
97
+ /** Bounding box coordinates [x, y, width, height]. */
40
98
  boundingBox?: [number, number, number, number]
99
+ /** Polygon points for non-rectangular regions. */
41
100
  polygon?: Array<[number, number]>
101
+ /** Block type classification. */
42
102
  type?: 'word' | 'line' | 'paragraph' | 'region'
43
- children?: AiVisionOcrBlock[]
103
+ /** Nested child blocks. */
104
+ children?: IntelligenceVisionOcrBlock[]
44
105
  }
45
106
 
46
- export interface AiVisionOcrResult {
107
+ /**
108
+ * Result from OCR vision capability.
109
+ */
110
+ export interface IntelligenceVisionOcrResult {
111
+ /** Full extracted text. */
47
112
  text: string
113
+ /** Overall confidence score. */
48
114
  confidence?: number
115
+ /** Detected primary language. */
49
116
  language?: string
117
+ /** Extracted keywords for search. */
50
118
  keywords?: string[]
119
+ /** Suggested search terms. */
51
120
  suggestions?: string[]
52
- blocks?: AiVisionOcrBlock[]
121
+ /** Structured text blocks. */
122
+ blocks?: IntelligenceVisionOcrBlock[]
123
+ /** Raw provider response. */
53
124
  raw?: any
54
125
  }
55
126
 
56
- export interface AiVisionOcrPayload {
57
- source: AiVisionImageSource
127
+ /**
128
+ * Payload for OCR vision capability.
129
+ */
130
+ export interface IntelligenceVisionOcrPayload {
131
+ /** Image source configuration. */
132
+ source: IntelligenceVisionImageSource
133
+ /** Expected language hint. */
58
134
  language?: string
135
+ /** Custom prompt for OCR. */
59
136
  prompt?: string
137
+ /** Additional metadata. */
60
138
  metadata?: Record<string, any>
139
+ /** Include layout information. */
61
140
  includeLayout?: boolean
141
+ /** Extract keywords from text. */
62
142
  includeKeywords?: boolean
63
143
  }
64
144
 
65
- export interface AiProviderConfig {
145
+ /**
146
+ * Configuration for an intelligence provider.
147
+ */
148
+ export interface IntelligenceProviderConfig {
149
+ /** Unique provider identifier. */
66
150
  id: string
67
- type: AiProviderType
151
+ /** Provider type. */
152
+ type: IntelligenceProviderType
153
+ /** Display name. */
68
154
  name: string
155
+ /** Whether the provider is enabled. */
69
156
  enabled: boolean
157
+ /** API key for authentication. */
70
158
  apiKey?: string
159
+ /** Base URL for API requests. */
71
160
  baseUrl?: string
72
- rateLimit?: AiProviderRateLimit
161
+ /** Rate limit configuration. */
162
+ rateLimit?: IntelligenceProviderRateLimit
163
+ /** Available models. */
73
164
  models?: string[]
165
+ /** Default model to use. */
74
166
  defaultModel?: string
167
+ /** System instructions. */
75
168
  instructions?: string
169
+ /** Request timeout in milliseconds. */
76
170
  timeout?: number
171
+ /** Provider priority for selection. */
77
172
  priority?: number
173
+ /** Supported capability IDs. */
78
174
  capabilities?: string[]
175
+ /** Additional metadata. */
79
176
  metadata?: Record<string, any>
80
177
  }
81
178
 
82
- export interface AiMessage {
179
+ /**
180
+ * Chat message structure.
181
+ */
182
+ export interface IntelligenceMessage {
183
+ /** Message role. */
83
184
  role: 'system' | 'user' | 'assistant'
185
+ /** Message content. */
84
186
  content: string
187
+ /** Optional sender name. */
85
188
  name?: string
86
189
  }
87
190
 
88
- export interface AiInvokeOptions {
191
+ /**
192
+ * Options for invoking an intelligence capability.
193
+ */
194
+ export interface IntelligenceInvokeOptions {
195
+ /** Strategy ID for provider selection. */
89
196
  strategy?: string
197
+ /** Preferred models in order. */
90
198
  modelPreference?: string[]
199
+ /** Maximum cost ceiling. */
91
200
  costCeiling?: number
201
+ /** Target latency in milliseconds. */
92
202
  latencyTarget?: number
203
+ /** Request timeout in milliseconds. */
93
204
  timeout?: number
205
+ /** Enable streaming response. */
94
206
  stream?: boolean
207
+ /** Preferred provider ID. */
95
208
  preferredProviderId?: string
209
+ /** Allowed provider IDs. */
96
210
  allowedProviderIds?: string[]
211
+ /** Additional metadata. */
97
212
  metadata?: Record<string, any>
213
+ /** Mark as test run. */
98
214
  testRun?: boolean
99
215
  }
100
216
 
101
- export interface AiInvokeContext {
217
+ /**
218
+ * Context information for an invocation.
219
+ */
220
+ export interface IntelligenceInvokeContext {
221
+ /** Request source identifier. */
102
222
  source?: string
223
+ /** User locale. */
103
224
  locale?: string
225
+ /** User identifier. */
104
226
  userId?: string
227
+ /** Session identifier. */
105
228
  sessionId?: string
106
229
  }
107
230
 
108
- export interface AiUsageInfo {
231
+ /**
232
+ * Token usage information.
233
+ */
234
+ export interface IntelligenceUsageInfo {
235
+ /** Tokens used in prompt. */
109
236
  promptTokens: number
237
+ /** Tokens used in completion. */
110
238
  completionTokens: number
239
+ /** Total tokens used. */
111
240
  totalTokens: number
241
+ /** Estimated cost. */
112
242
  cost?: number
113
243
  }
114
244
 
115
- export interface AiInvokeResult<T = any> {
245
+ /**
246
+ * Result from an intelligence invocation.
247
+ * @template T - Result data type.
248
+ */
249
+ export interface IntelligenceInvokeResult<T = any> {
250
+ /** The result data. */
116
251
  result: T
117
- usage: AiUsageInfo
252
+ /** Token usage information. */
253
+ usage: IntelligenceUsageInfo
254
+ /** Model used for the request. */
118
255
  model: string
256
+ /** Request latency in milliseconds. */
119
257
  latency: number
258
+ /** Unique trace identifier. */
120
259
  traceId: string
260
+ /** Provider that handled the request. */
121
261
  provider: string
122
262
  }
123
263
 
124
- export interface AiStreamChunk {
264
+ /**
265
+ * Streaming response chunk.
266
+ */
267
+ export interface IntelligenceStreamChunk {
268
+ /** Content delta. */
125
269
  delta: string
270
+ /** Whether streaming is complete. */
126
271
  done: boolean
127
- usage?: AiUsageInfo
272
+ /** Final usage info (when done). */
273
+ usage?: IntelligenceUsageInfo
128
274
  }
129
275
 
130
- export interface AiCapabilityDescriptor {
276
+ /**
277
+ * Descriptor for a registered capability.
278
+ */
279
+ export interface IntelligenceCapabilityDescriptor {
280
+ /** Unique capability identifier. */
131
281
  id: string
132
- type: AiCapabilityType
282
+ /** Capability type. */
283
+ type: IntelligenceCapabilityType
284
+ /** Display name. */
133
285
  name: string
286
+ /** Description of the capability. */
134
287
  description: string
288
+ /** JSON schema for input validation. */
135
289
  inputSchema?: any
290
+ /** JSON schema for output validation. */
136
291
  outputSchema?: any
292
+ /** Default strategy for provider selection. */
137
293
  defaultStrategy?: string
138
- supportedProviders: AiProviderType[]
294
+ /** Providers that support this capability. */
295
+ supportedProviders: IntelligenceProviderType[]
296
+ /** Additional metadata. */
139
297
  metadata?: Record<string, any>
140
298
  }
141
299
 
142
- export interface AiChatPayload {
143
- messages: AiMessage[]
144
- context?: AiInvokeContext
300
+ /**
301
+ * Payload for chat capability.
302
+ */
303
+ export interface IntelligenceChatPayload {
304
+ /** Conversation messages. */
305
+ messages: IntelligenceMessage[]
306
+ /** Invocation context. */
307
+ context?: IntelligenceInvokeContext
308
+ /** Sampling temperature (0-2). */
145
309
  temperature?: number
310
+ /** Maximum tokens to generate. */
146
311
  maxTokens?: number
312
+ /** Top-p sampling parameter. */
147
313
  topP?: number
314
+ /** Frequency penalty (-2 to 2). */
148
315
  frequencyPenalty?: number
316
+ /** Presence penalty (-2 to 2). */
149
317
  presencePenalty?: number
318
+ /** Stop sequences. */
150
319
  stop?: string[]
151
320
  }
152
321
 
153
- export interface AiEmbeddingPayload {
322
+ /**
323
+ * Payload for embedding generation.
324
+ */
325
+ export interface IntelligenceEmbeddingPayload {
326
+ /** Text to embed (single or batch). */
154
327
  text: string | string[]
328
+ /** Specific model to use. */
155
329
  model?: string
156
330
  }
157
331
 
158
- export interface AiTranslatePayload {
332
+ /**
333
+ * Payload for translation capability.
334
+ */
335
+ export interface IntelligenceTranslatePayload {
336
+ /** Text to translate. */
159
337
  text: string
338
+ /** Source language (auto-detect if omitted). */
160
339
  sourceLang?: string
340
+ /** Target language. */
161
341
  targetLang: string
162
342
  }
163
343
 
164
- export interface AiSummarizePayload {
344
+ /**
345
+ * Payload for summarization capability.
346
+ */
347
+ export interface IntelligenceSummarizePayload {
348
+ /** Text to summarize. */
165
349
  text: string
350
+ /** Maximum summary length. */
166
351
  maxLength?: number
352
+ /** Summary style. */
167
353
  style?: 'concise' | 'detailed' | 'bullet-points'
168
354
  }
169
355
 
170
- export interface AiSDKConfig {
171
- providers: AiProviderConfig[]
356
+ // Legacy aliases for backward compatibility
357
+ /** @deprecated Use IntelligenceProviderType instead. */
358
+ export type AiProviderType = IntelligenceProviderType
359
+ /** @deprecated Use IntelligenceCapabilityType instead. */
360
+ export type AiCapabilityType = IntelligenceCapabilityType
361
+ /** @deprecated Use IntelligenceProviderRateLimit instead. */
362
+ export type AiProviderRateLimit = IntelligenceProviderRateLimit
363
+ /** @deprecated Use IntelligenceVisionImageSource instead. */
364
+ export type AiVisionImageSource = IntelligenceVisionImageSource
365
+ /** @deprecated Use IntelligenceVisionOcrBlock instead. */
366
+ export type AiVisionOcrBlock = IntelligenceVisionOcrBlock
367
+ /** @deprecated Use IntelligenceVisionOcrResult instead. */
368
+ export type AiVisionOcrResult = IntelligenceVisionOcrResult
369
+ /** @deprecated Use IntelligenceVisionOcrPayload instead. */
370
+ export type AiVisionOcrPayload = IntelligenceVisionOcrPayload
371
+ /** @deprecated Use IntelligenceProviderConfig instead. */
372
+ export type AiProviderConfig = IntelligenceProviderConfig
373
+ /** @deprecated Use IntelligenceMessage instead. */
374
+ export type AiMessage = IntelligenceMessage
375
+ /** @deprecated Use IntelligenceInvokeOptions instead. */
376
+ export type AiInvokeOptions = IntelligenceInvokeOptions
377
+ /** @deprecated Use IntelligenceInvokeContext instead. */
378
+ export type AiInvokeContext = IntelligenceInvokeContext
379
+ /** @deprecated Use IntelligenceUsageInfo instead. */
380
+ export type AiUsageInfo = IntelligenceUsageInfo
381
+ /** @deprecated Use IntelligenceInvokeResult instead. */
382
+ export type AiInvokeResult<T = any> = IntelligenceInvokeResult<T>
383
+ /** @deprecated Use IntelligenceStreamChunk instead. */
384
+ export type AiStreamChunk = IntelligenceStreamChunk
385
+ /** @deprecated Use IntelligenceCapabilityDescriptor instead. */
386
+ export type AiCapabilityDescriptor = IntelligenceCapabilityDescriptor
387
+ /** @deprecated Use IntelligenceChatPayload instead. */
388
+ export type AiChatPayload = IntelligenceChatPayload
389
+ /** @deprecated Use IntelligenceEmbeddingPayload instead. */
390
+ export type AiEmbeddingPayload = IntelligenceEmbeddingPayload
391
+ /** @deprecated Use IntelligenceTranslatePayload instead. */
392
+ export type AiTranslatePayload = IntelligenceTranslatePayload
393
+ /** @deprecated Use IntelligenceSummarizePayload instead. */
394
+ export type AiSummarizePayload = IntelligenceSummarizePayload
395
+
396
+ // ============================================================================
397
+ // Extended Payload Types
398
+ // ============================================================================
399
+
400
+ /**
401
+ * Payload for text rewriting capability.
402
+ */
403
+ export interface IntelligenceRewritePayload {
404
+ /** Text to rewrite. */
405
+ text: string
406
+ /** Writing style. */
407
+ style?: 'formal' | 'casual' | 'professional' | 'creative' | 'simplified'
408
+ /** Tone of voice. */
409
+ tone?: 'neutral' | 'friendly' | 'authoritative' | 'humorous'
410
+ /** Target audience description. */
411
+ targetAudience?: string
412
+ /** Keywords to preserve. */
413
+ preserveKeywords?: string[]
414
+ }
415
+
416
+ /**
417
+ * Payload for grammar checking capability.
418
+ */
419
+ export interface IntelligenceGrammarCheckPayload {
420
+ /** Text to check. */
421
+ text: string
422
+ /** Language of the text. */
423
+ language?: string
424
+ /** Types of issues to check. */
425
+ checkTypes?: ('spelling' | 'grammar' | 'punctuation' | 'style')[]
426
+ /** Strictness level. */
427
+ strictness?: 'lenient' | 'standard' | 'strict'
428
+ }
429
+
430
+ /**
431
+ * Result from grammar checking capability.
432
+ */
433
+ export interface IntelligenceGrammarCheckResult {
434
+ /** Corrected text. */
435
+ correctedText: string
436
+ /** List of issues found. */
437
+ issues: Array<{
438
+ type: 'spelling' | 'grammar' | 'punctuation' | 'style'
439
+ original: string
440
+ suggestion: string
441
+ position: { start: number, end: number }
442
+ explanation?: string
443
+ }>
444
+ /** Overall score (0-100). */
445
+ score: number
446
+ }
447
+
448
+ /**
449
+ * Payload for code generation capability.
450
+ */
451
+ export interface IntelligenceCodeGeneratePayload {
452
+ /** Description of code to generate. */
453
+ description: string
454
+ /** Target programming language. */
455
+ language: string
456
+ /** Framework to use. */
457
+ framework?: string
458
+ /** Additional context. */
459
+ context?: string
460
+ /** Include unit tests. */
461
+ includeTests?: boolean
462
+ /** Include code comments. */
463
+ includeComments?: boolean
464
+ /** Code style preference. */
465
+ style?: 'minimal' | 'verbose' | 'production'
466
+ }
467
+
468
+ /**
469
+ * Result from code generation capability.
470
+ */
471
+ export interface IntelligenceCodeGenerateResult {
472
+ /** Generated code. */
473
+ code: string
474
+ /** Programming language. */
475
+ language: string
476
+ /** Explanation of the code. */
477
+ explanation?: string
478
+ /** Required dependencies. */
479
+ dependencies?: string[]
480
+ /** Generated tests. */
481
+ tests?: string
482
+ }
483
+
484
+ /**
485
+ * Payload for code explanation capability.
486
+ */
487
+ export interface IntelligenceCodeExplainPayload {
488
+ /** Code to explain. */
489
+ code: string
490
+ /** Programming language. */
491
+ language?: string
492
+ /** Explanation depth. */
493
+ depth?: 'brief' | 'detailed' | 'comprehensive'
494
+ /** Target audience level. */
495
+ targetAudience?: 'beginner' | 'intermediate' | 'expert'
496
+ }
497
+
498
+ /**
499
+ * Result from code explanation capability.
500
+ */
501
+ export interface IntelligenceCodeExplainResult {
502
+ /** Detailed explanation. */
503
+ explanation: string
504
+ /** Brief summary. */
505
+ summary: string
506
+ /** Key points. */
507
+ keyPoints: string[]
508
+ /** Complexity assessment. */
509
+ complexity?: 'simple' | 'moderate' | 'complex'
510
+ /** Programming concepts used. */
511
+ concepts?: string[]
512
+ }
513
+
514
+ /**
515
+ * Payload for code review capability.
516
+ */
517
+ export interface IntelligenceCodeReviewPayload {
518
+ /** Code to review. */
519
+ code: string
520
+ /** Programming language. */
521
+ language?: string
522
+ /** Additional context. */
523
+ context?: string
524
+ /** Areas to focus on. */
525
+ focusAreas?: ('security' | 'performance' | 'style' | 'bugs' | 'best-practices')[]
526
+ }
527
+
528
+ /**
529
+ * Result from code review capability.
530
+ */
531
+ export interface IntelligenceCodeReviewResult {
532
+ /** Review summary. */
533
+ summary: string
534
+ /** Overall score (0-100). */
535
+ score: number
536
+ /** Issues found. */
537
+ issues: Array<{
538
+ severity: 'critical' | 'warning' | 'info' | 'suggestion'
539
+ type: string
540
+ line?: number
541
+ message: string
542
+ suggestion?: string
543
+ }>
544
+ /** Suggested improvements. */
545
+ improvements: string[]
546
+ }
547
+
548
+ /**
549
+ * Payload for code refactoring capability.
550
+ */
551
+ export interface IntelligenceCodeRefactorPayload {
552
+ /** Code to refactor. */
553
+ code: string
554
+ /** Programming language. */
555
+ language?: string
556
+ /** Refactoring goals. */
557
+ goals?: ('readability' | 'performance' | 'maintainability' | 'modularity')[]
558
+ /** Preserve public interface. */
559
+ preserveInterface?: boolean
560
+ }
561
+
562
+ /**
563
+ * Result from code refactoring capability.
564
+ */
565
+ export interface IntelligenceCodeRefactorResult {
566
+ /** Refactored code. */
567
+ refactoredCode: string
568
+ /** List of changes made. */
569
+ changes: Array<{
570
+ type: string
571
+ description: string
572
+ before?: string
573
+ after?: string
574
+ }>
575
+ /** Explanation of changes. */
576
+ explanation: string
577
+ }
578
+
579
+ /**
580
+ * Payload for code debugging capability.
581
+ */
582
+ export interface IntelligenceCodeDebugPayload {
583
+ /** Code with bug. */
584
+ code: string
585
+ /** Error message. */
586
+ error?: string
587
+ /** Programming language. */
588
+ language?: string
589
+ /** Additional context. */
590
+ context?: string
591
+ /** Stack trace. */
592
+ stackTrace?: string
593
+ }
594
+
595
+ /**
596
+ * Result from code debugging capability.
597
+ */
598
+ export interface IntelligenceCodeDebugResult {
599
+ /** Bug diagnosis. */
600
+ diagnosis: string
601
+ /** Root cause analysis. */
602
+ rootCause: string
603
+ /** Fixed code. */
604
+ fixedCode: string
605
+ /** Explanation of the fix. */
606
+ explanation: string
607
+ /** Tips to prevent similar bugs. */
608
+ preventionTips?: string[]
609
+ }
610
+
611
+ /**
612
+ * Payload for intent detection capability.
613
+ */
614
+ export interface IntelligenceIntentDetectPayload {
615
+ /** Text to analyze. */
616
+ text: string
617
+ /** Additional context. */
618
+ context?: string
619
+ /** Possible intents to consider. */
620
+ possibleIntents?: string[]
621
+ /** Language of the text. */
622
+ language?: string
623
+ }
624
+
625
+ /**
626
+ * Result from intent detection capability.
627
+ */
628
+ export interface IntelligenceIntentDetectResult {
629
+ /** Detected intent. */
630
+ intent: string
631
+ /** Confidence score (0-1). */
632
+ confidence: number
633
+ /** Extracted entities. */
634
+ entities: Array<{
635
+ type: string
636
+ value: string
637
+ position?: { start: number, end: number }
638
+ }>
639
+ /** Secondary intents. */
640
+ subIntents?: Array<{ intent: string, confidence: number }>
641
+ }
642
+
643
+ /**
644
+ * Payload for sentiment analysis capability.
645
+ */
646
+ export interface IntelligenceSentimentAnalyzePayload {
647
+ /** Text to analyze. */
648
+ text: string
649
+ /** Language of the text. */
650
+ language?: string
651
+ /** Analysis granularity. */
652
+ granularity?: 'document' | 'sentence' | 'aspect'
653
+ /** Aspects to analyze. */
654
+ aspects?: string[]
655
+ }
656
+
657
+ /**
658
+ * Result from sentiment analysis capability.
659
+ */
660
+ export interface IntelligenceSentimentAnalyzeResult {
661
+ /** Overall sentiment. */
662
+ sentiment: 'positive' | 'negative' | 'neutral' | 'mixed'
663
+ /** Sentiment score (-1 to 1). */
664
+ score: number
665
+ /** Confidence score (0-1). */
666
+ confidence: number
667
+ /** Detected emotions. */
668
+ emotions?: Array<{ emotion: string, score: number }>
669
+ /** Aspect-based sentiments. */
670
+ aspects?: Array<{ aspect: string, sentiment: string, score: number }>
671
+ /** Sentiment keywords. */
672
+ keywords?: string[]
673
+ }
674
+
675
+ /**
676
+ * Payload for content extraction capability.
677
+ */
678
+ export interface IntelligenceContentExtractPayload {
679
+ /** Text to extract from. */
680
+ text: string
681
+ /** Types of entities to extract. */
682
+ extractTypes?: ('dates' | 'people' | 'locations' | 'organizations' | 'events' | 'products' | 'urls' | 'emails' | 'phones')[]
683
+ /** Language of the text. */
684
+ language?: string
685
+ /** Include surrounding context. */
686
+ includeContext?: boolean
687
+ }
688
+
689
+ /**
690
+ * Result from content extraction capability.
691
+ */
692
+ export interface IntelligenceContentExtractResult {
693
+ /** Extracted entities by type. */
694
+ entities: Record<string, Array<{
695
+ value: string
696
+ confidence: number
697
+ context?: string
698
+ position?: { start: number, end: number }
699
+ }>>
700
+ /** Content summary. */
701
+ summary?: string
702
+ }
703
+
704
+ /**
705
+ * Payload for keyword extraction capability.
706
+ */
707
+ export interface IntelligenceKeywordsExtractPayload {
708
+ /** Text to extract keywords from. */
709
+ text: string
710
+ /** Maximum keywords to return. */
711
+ maxKeywords?: number
712
+ /** Language of the text. */
713
+ language?: string
714
+ /** Include relevance scores. */
715
+ includeScores?: boolean
716
+ /** Types of keywords to extract. */
717
+ keywordTypes?: ('noun' | 'verb' | 'phrase' | 'entity')[]
718
+ }
719
+
720
+ /**
721
+ * Result from keyword extraction capability.
722
+ */
723
+ export interface IntelligenceKeywordsExtractResult {
724
+ /** Extracted keywords. */
725
+ keywords: Array<{
726
+ term: string
727
+ relevance: number
728
+ frequency?: number
729
+ type?: string
730
+ }>
731
+ }
732
+
733
+ /**
734
+ * Payload for text classification capability.
735
+ */
736
+ export interface IntelligenceClassificationPayload {
737
+ /** Text to classify. */
738
+ text: string
739
+ /** Available categories. */
740
+ categories: string[]
741
+ /** Allow multiple labels. */
742
+ multiLabel?: boolean
743
+ /** Confidence threshold. */
744
+ threshold?: number
745
+ }
746
+
747
+ /**
748
+ * Result from text classification capability.
749
+ */
750
+ export interface IntelligenceClassificationResult {
751
+ /** Classification predictions. */
752
+ predictions: Array<{
753
+ category: string
754
+ confidence: number
755
+ }>
756
+ /** Classification explanation. */
757
+ explanation?: string
758
+ }
759
+
760
+ // Legacy aliases for extended payload types
761
+ /** @deprecated Use IntelligenceRewritePayload instead. */
762
+ export type AiRewritePayload = IntelligenceRewritePayload
763
+ /** @deprecated Use IntelligenceGrammarCheckPayload instead. */
764
+ export type AiGrammarCheckPayload = IntelligenceGrammarCheckPayload
765
+ /** @deprecated Use IntelligenceGrammarCheckResult instead. */
766
+ export type AiGrammarCheckResult = IntelligenceGrammarCheckResult
767
+ /** @deprecated Use IntelligenceCodeGeneratePayload instead. */
768
+ export type AiCodeGeneratePayload = IntelligenceCodeGeneratePayload
769
+ /** @deprecated Use IntelligenceCodeGenerateResult instead. */
770
+ export type AiCodeGenerateResult = IntelligenceCodeGenerateResult
771
+ /** @deprecated Use IntelligenceCodeExplainPayload instead. */
772
+ export type AiCodeExplainPayload = IntelligenceCodeExplainPayload
773
+ /** @deprecated Use IntelligenceCodeExplainResult instead. */
774
+ export type AiCodeExplainResult = IntelligenceCodeExplainResult
775
+ /** @deprecated Use IntelligenceCodeReviewPayload instead. */
776
+ export type AiCodeReviewPayload = IntelligenceCodeReviewPayload
777
+ /** @deprecated Use IntelligenceCodeReviewResult instead. */
778
+ export type AiCodeReviewResult = IntelligenceCodeReviewResult
779
+ /** @deprecated Use IntelligenceCodeRefactorPayload instead. */
780
+ export type AiCodeRefactorPayload = IntelligenceCodeRefactorPayload
781
+ /** @deprecated Use IntelligenceCodeRefactorResult instead. */
782
+ export type AiCodeRefactorResult = IntelligenceCodeRefactorResult
783
+ /** @deprecated Use IntelligenceCodeDebugPayload instead. */
784
+ export type AiCodeDebugPayload = IntelligenceCodeDebugPayload
785
+ /** @deprecated Use IntelligenceCodeDebugResult instead. */
786
+ export type AiCodeDebugResult = IntelligenceCodeDebugResult
787
+ /** @deprecated Use IntelligenceIntentDetectPayload instead. */
788
+ export type AiIntentDetectPayload = IntelligenceIntentDetectPayload
789
+ /** @deprecated Use IntelligenceIntentDetectResult instead. */
790
+ export type AiIntentDetectResult = IntelligenceIntentDetectResult
791
+ /** @deprecated Use IntelligenceSentimentAnalyzePayload instead. */
792
+ export type AiSentimentAnalyzePayload = IntelligenceSentimentAnalyzePayload
793
+ /** @deprecated Use IntelligenceSentimentAnalyzeResult instead. */
794
+ export type AiSentimentAnalyzeResult = IntelligenceSentimentAnalyzeResult
795
+ /** @deprecated Use IntelligenceContentExtractPayload instead. */
796
+ export type AiContentExtractPayload = IntelligenceContentExtractPayload
797
+ /** @deprecated Use IntelligenceContentExtractResult instead. */
798
+ export type AiContentExtractResult = IntelligenceContentExtractResult
799
+ /** @deprecated Use IntelligenceKeywordsExtractPayload instead. */
800
+ export type AiKeywordsExtractPayload = IntelligenceKeywordsExtractPayload
801
+ /** @deprecated Use IntelligenceKeywordsExtractResult instead. */
802
+ export type AiKeywordsExtractResult = IntelligenceKeywordsExtractResult
803
+ /** @deprecated Use IntelligenceClassificationPayload instead. */
804
+ export type AiClassificationPayload = IntelligenceClassificationPayload
805
+ /** @deprecated Use IntelligenceClassificationResult instead. */
806
+ export type AiClassificationResult = IntelligenceClassificationResult
807
+
808
+ // ============================================================================
809
+ // Audio Payload Types
810
+ // ============================================================================
811
+
812
+ /**
813
+ * Payload for text-to-speech capability.
814
+ */
815
+ export interface IntelligenceTTSPayload {
816
+ /** Text to convert to speech. */
817
+ text: string
818
+ /** Voice identifier. */
819
+ voice?: string
820
+ /** Language code. */
821
+ language?: string
822
+ /** Speech speed multiplier. */
823
+ speed?: number
824
+ /** Voice pitch adjustment. */
825
+ pitch?: number
826
+ /** Output audio format. */
827
+ format?: 'mp3' | 'wav' | 'ogg' | 'flac'
828
+ /** Audio quality. */
829
+ quality?: 'standard' | 'hd'
830
+ }
831
+
832
+ /**
833
+ * Result from text-to-speech capability.
834
+ */
835
+ export interface IntelligenceTTSResult {
836
+ /** Audio data. */
837
+ audio: ArrayBuffer | string
838
+ /** Audio format. */
839
+ format: string
840
+ /** Duration in seconds. */
841
+ duration?: number
842
+ /** Sample rate in Hz. */
843
+ sampleRate?: number
844
+ }
845
+
846
+ /**
847
+ * Payload for speech-to-text capability.
848
+ */
849
+ export interface IntelligenceSTTPayload {
850
+ /** Audio data. */
851
+ audio: ArrayBuffer | string
852
+ /** Expected language. */
853
+ language?: string
854
+ /** Audio format. */
855
+ format?: string
856
+ /** Include word timestamps. */
857
+ enableTimestamps?: boolean
858
+ /** Enable speaker diarization. */
859
+ enableSpeakerDiarization?: boolean
860
+ }
861
+
862
+ /**
863
+ * Result from speech-to-text capability.
864
+ */
865
+ export interface IntelligenceSTTResult {
866
+ /** Transcribed text. */
867
+ text: string
868
+ /** Confidence score (0-1). */
869
+ confidence: number
870
+ /** Detected language. */
871
+ language?: string
872
+ /** Transcription segments. */
873
+ segments?: Array<{
874
+ text: string
875
+ start: number
876
+ end: number
877
+ speaker?: string
878
+ confidence?: number
879
+ }>
880
+ }
881
+
882
+ /**
883
+ * Payload for audio transcription capability.
884
+ */
885
+ export interface IntelligenceAudioTranscribePayload {
886
+ /** Audio data. */
887
+ audio: ArrayBuffer | string
888
+ /** Expected language. */
889
+ language?: string
890
+ /** Audio format. */
891
+ format?: string
892
+ /** Task type. */
893
+ task?: 'transcribe' | 'translate'
894
+ /** Include timestamps. */
895
+ enableTimestamps?: boolean
896
+ /** Context prompt. */
897
+ prompt?: string
898
+ }
899
+
900
+ /**
901
+ * Result from audio transcription capability.
902
+ */
903
+ export interface IntelligenceAudioTranscribeResult {
904
+ /** Transcribed text. */
905
+ text: string
906
+ /** Detected language. */
907
+ language: string
908
+ /** Audio duration in seconds. */
909
+ duration: number
910
+ /** Transcription segments. */
911
+ segments?: Array<{
912
+ id: number
913
+ text: string
914
+ start: number
915
+ end: number
916
+ confidence?: number
917
+ }>
918
+ }
919
+
920
+ // Legacy aliases for audio types
921
+ /** @deprecated Use IntelligenceTTSPayload instead. */
922
+ export type AiTTSPayload = IntelligenceTTSPayload
923
+ /** @deprecated Use IntelligenceTTSResult instead. */
924
+ export type AiTTSResult = IntelligenceTTSResult
925
+ /** @deprecated Use IntelligenceSTTPayload instead. */
926
+ export type AiSTTPayload = IntelligenceSTTPayload
927
+ /** @deprecated Use IntelligenceSTTResult instead. */
928
+ export type AiSTTResult = IntelligenceSTTResult
929
+ /** @deprecated Use IntelligenceAudioTranscribePayload instead. */
930
+ export type AiAudioTranscribePayload = IntelligenceAudioTranscribePayload
931
+ /** @deprecated Use IntelligenceAudioTranscribeResult instead. */
932
+ export type AiAudioTranscribeResult = IntelligenceAudioTranscribeResult
933
+
934
+ // ============================================================================
935
+ // Vision Extended Payload Types
936
+ // ============================================================================
937
+
938
+ /**
939
+ * Payload for image captioning capability.
940
+ */
941
+ export interface IntelligenceImageCaptionPayload {
942
+ /** Image source. */
943
+ source: IntelligenceVisionImageSource
944
+ /** Caption style. */
945
+ style?: 'brief' | 'detailed' | 'creative'
946
+ /** Output language. */
947
+ language?: string
948
+ /** Maximum caption length. */
949
+ maxLength?: number
950
+ }
951
+
952
+ /**
953
+ * Result from image captioning capability.
954
+ */
955
+ export interface IntelligenceImageCaptionResult {
956
+ /** Generated caption. */
957
+ caption: string
958
+ /** Alternative captions. */
959
+ alternativeCaptions?: string[]
960
+ /** Image tags. */
961
+ tags?: string[]
962
+ /** Confidence score (0-1). */
963
+ confidence?: number
964
+ }
965
+
966
+ /**
967
+ * Payload for image analysis capability.
968
+ */
969
+ export interface IntelligenceImageAnalyzePayload {
970
+ /** Image source. */
971
+ source: IntelligenceVisionImageSource
972
+ /** Types of analysis to perform. */
973
+ analysisTypes?: ('objects' | 'faces' | 'text' | 'colors' | 'composition' | 'scene' | 'emotions')[]
974
+ /** Output language. */
975
+ language?: string
976
+ /** Include detailed analysis. */
977
+ detailed?: boolean
978
+ }
979
+
980
+ /**
981
+ * Result from image analysis capability.
982
+ */
983
+ export interface IntelligenceImageAnalyzeResult {
984
+ /** Overall description. */
985
+ description: string
986
+ /** Detected objects. */
987
+ objects?: Array<{
988
+ name: string
989
+ confidence: number
990
+ boundingBox?: [number, number, number, number]
991
+ }>
992
+ /** Detected faces. */
993
+ faces?: Array<{
994
+ age?: number
995
+ gender?: string
996
+ emotion?: string
997
+ boundingBox?: [number, number, number, number]
998
+ }>
999
+ /** Dominant colors. */
1000
+ colors?: Array<{
1001
+ color: string
1002
+ percentage: number
1003
+ hex?: string
1004
+ }>
1005
+ /** Scene classification. */
1006
+ scene?: {
1007
+ type: string
1008
+ confidence: number
1009
+ attributes?: Record<string, any>
1010
+ }
1011
+ /** Detected text. */
1012
+ text?: string[]
1013
+ /** Image tags. */
1014
+ tags?: string[]
1015
+ }
1016
+
1017
+ /**
1018
+ * Payload for image generation capability.
1019
+ */
1020
+ export interface IntelligenceImageGeneratePayload {
1021
+ /** Generation prompt. */
1022
+ prompt: string
1023
+ /** Negative prompt. */
1024
+ negativePrompt?: string
1025
+ /** Image width in pixels. */
1026
+ width?: number
1027
+ /** Image height in pixels. */
1028
+ height?: number
1029
+ /** Style preset. */
1030
+ style?: string
1031
+ /** Image quality. */
1032
+ quality?: 'standard' | 'hd'
1033
+ /** Number of images to generate. */
1034
+ count?: number
1035
+ /** Random seed for reproducibility. */
1036
+ seed?: number
1037
+ }
1038
+
1039
+ /**
1040
+ * Result from image generation capability.
1041
+ */
1042
+ export interface IntelligenceImageGenerateResult {
1043
+ /** Generated images. */
1044
+ images: Array<{
1045
+ url?: string
1046
+ base64?: string
1047
+ revisedPrompt?: string
1048
+ }>
1049
+ /** Seed used for generation. */
1050
+ seed?: number
1051
+ }
1052
+
1053
+ /**
1054
+ * Payload for image editing capability.
1055
+ */
1056
+ export interface IntelligenceImageEditPayload {
1057
+ /** Source image. */
1058
+ source: IntelligenceVisionImageSource
1059
+ /** Mask for inpainting. */
1060
+ mask?: IntelligenceVisionImageSource
1061
+ /** Edit prompt. */
1062
+ prompt: string
1063
+ /** Type of edit. */
1064
+ editType?: 'inpaint' | 'outpaint' | 'variation' | 'upscale'
1065
+ }
1066
+
1067
+ /**
1068
+ * Result from image editing capability.
1069
+ */
1070
+ export interface IntelligenceImageEditResult {
1071
+ /** Edited image. */
1072
+ image: {
1073
+ url?: string
1074
+ base64?: string
1075
+ }
1076
+ /** Revised prompt. */
1077
+ revisedPrompt?: string
1078
+ }
1079
+
1080
+ // Legacy aliases for vision types
1081
+ /** @deprecated Use IntelligenceImageCaptionPayload instead. */
1082
+ export type AiImageCaptionPayload = IntelligenceImageCaptionPayload
1083
+ /** @deprecated Use IntelligenceImageCaptionResult instead. */
1084
+ export type AiImageCaptionResult = IntelligenceImageCaptionResult
1085
+ /** @deprecated Use IntelligenceImageAnalyzePayload instead. */
1086
+ export type AiImageAnalyzePayload = IntelligenceImageAnalyzePayload
1087
+ /** @deprecated Use IntelligenceImageAnalyzeResult instead. */
1088
+ export type AiImageAnalyzeResult = IntelligenceImageAnalyzeResult
1089
+ /** @deprecated Use IntelligenceImageGeneratePayload instead. */
1090
+ export type AiImageGeneratePayload = IntelligenceImageGeneratePayload
1091
+ /** @deprecated Use IntelligenceImageGenerateResult instead. */
1092
+ export type AiImageGenerateResult = IntelligenceImageGenerateResult
1093
+ /** @deprecated Use IntelligenceImageEditPayload instead. */
1094
+ export type AiImageEditPayload = IntelligenceImageEditPayload
1095
+ /** @deprecated Use IntelligenceImageEditResult instead. */
1096
+ export type AiImageEditResult = IntelligenceImageEditResult
1097
+
1098
+ // ============================================================================
1099
+ // RAG & Search Payload Types
1100
+ // ============================================================================
1101
+
1102
+ /**
1103
+ * Payload for RAG query capability.
1104
+ */
1105
+ export interface IntelligenceRAGQueryPayload {
1106
+ /** Query text. */
1107
+ query: string
1108
+ /** Documents to search. */
1109
+ documents?: Array<{
1110
+ id: string
1111
+ content: string
1112
+ metadata?: Record<string, any>
1113
+ }>
1114
+ /** Number of top results. */
1115
+ topK?: number
1116
+ /** Relevance threshold. */
1117
+ threshold?: number
1118
+ /** Enable reranking. */
1119
+ rerank?: boolean
1120
+ /** Include context in response. */
1121
+ includeContext?: boolean
1122
+ }
1123
+
1124
+ /**
1125
+ * Result from RAG query capability.
1126
+ */
1127
+ export interface IntelligenceRAGQueryResult {
1128
+ /** Generated answer. */
1129
+ answer: string
1130
+ /** Source documents. */
1131
+ sources: Array<{
1132
+ id: string
1133
+ content: string
1134
+ relevance: number
1135
+ metadata?: Record<string, any>
1136
+ }>
1137
+ /** Confidence score (0-1). */
1138
+ confidence: number
1139
+ }
1140
+
1141
+ /**
1142
+ * Payload for semantic search capability.
1143
+ */
1144
+ export interface IntelligenceSemanticSearchPayload {
1145
+ /** Search query. */
1146
+ query: string
1147
+ /** Documents to search. */
1148
+ documents: Array<{
1149
+ id: string
1150
+ content: string
1151
+ embedding?: number[]
1152
+ metadata?: Record<string, any>
1153
+ }>
1154
+ /** Number of top results. */
1155
+ topK?: number
1156
+ /** Similarity threshold. */
1157
+ threshold?: number
1158
+ }
1159
+
1160
+ /**
1161
+ * Result from semantic search capability.
1162
+ */
1163
+ export interface IntelligenceSemanticSearchResult {
1164
+ /** Search results. */
1165
+ results: Array<{
1166
+ id: string
1167
+ content: string
1168
+ score: number
1169
+ metadata?: Record<string, any>
1170
+ }>
1171
+ }
1172
+
1173
+ /**
1174
+ * Payload for document reranking capability.
1175
+ */
1176
+ export interface IntelligenceRerankPayload {
1177
+ /** Query for relevance scoring. */
1178
+ query: string
1179
+ /** Documents to rerank. */
1180
+ documents: Array<{
1181
+ id: string
1182
+ content: string
1183
+ metadata?: Record<string, any>
1184
+ }>
1185
+ /** Number of top results. */
1186
+ topK?: number
1187
+ }
1188
+
1189
+ /**
1190
+ * Result from document reranking capability.
1191
+ */
1192
+ export interface IntelligenceRerankResult {
1193
+ /** Reranked results. */
1194
+ results: Array<{
1195
+ id: string
1196
+ content: string
1197
+ score: number
1198
+ originalRank: number
1199
+ metadata?: Record<string, any>
1200
+ }>
1201
+ }
1202
+
1203
+ // Legacy aliases for RAG types
1204
+ /** @deprecated Use IntelligenceRAGQueryPayload instead. */
1205
+ export type AiRAGQueryPayload = IntelligenceRAGQueryPayload
1206
+ /** @deprecated Use IntelligenceRAGQueryResult instead. */
1207
+ export type AiRAGQueryResult = IntelligenceRAGQueryResult
1208
+ /** @deprecated Use IntelligenceSemanticSearchPayload instead. */
1209
+ export type AiSemanticSearchPayload = IntelligenceSemanticSearchPayload
1210
+ /** @deprecated Use IntelligenceSemanticSearchResult instead. */
1211
+ export type AiSemanticSearchResult = IntelligenceSemanticSearchResult
1212
+ /** @deprecated Use IntelligenceRerankPayload instead. */
1213
+ export type AiRerankPayload = IntelligenceRerankPayload
1214
+ /** @deprecated Use IntelligenceRerankResult instead. */
1215
+ export type AiRerankResult = IntelligenceRerankResult
1216
+
1217
+ // ============================================================================
1218
+ // Prompt Workflow System
1219
+ // ============================================================================
1220
+
1221
+ export type PromptVariableType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'file' | 'image'
1222
+
1223
+ export interface PromptVariable {
1224
+ name: string
1225
+ type: PromptVariableType
1226
+ description?: string
1227
+ required?: boolean
1228
+ default?: any
1229
+ validation?: {
1230
+ minLength?: number
1231
+ maxLength?: number
1232
+ pattern?: string
1233
+ enum?: any[]
1234
+ min?: number
1235
+ max?: number
1236
+ }
1237
+ }
1238
+
1239
+ export interface PromptTemplate {
1240
+ id: string
1241
+ name: string
1242
+ description?: string
1243
+ template: string
1244
+ variables: PromptVariable[]
1245
+ category?: string
1246
+ tags?: string[]
1247
+ version?: string
1248
+ author?: string
1249
+ createdAt?: number
1250
+ updatedAt?: number
1251
+ }
1252
+
1253
+ export interface PromptStep {
1254
+ id: string
1255
+ name: string
1256
+ type: 'prompt' | 'condition' | 'loop' | 'parallel' | 'transform' | 'api-call'
1257
+ config: PromptStepConfig
1258
+ next?: string | PromptStepCondition[]
1259
+ onError?: 'fail' | 'skip' | 'retry' | string
1260
+ retryConfig?: {
1261
+ maxRetries: number
1262
+ delay: number
1263
+ backoff?: 'linear' | 'exponential'
1264
+ }
1265
+ }
1266
+
1267
+ export interface PromptStepConfig {
1268
+ // For prompt type
1269
+ templateId?: string
1270
+ template?: string
1271
+ variables?: Record<string, any>
1272
+ capabilityId?: string
1273
+ modelPreference?: string[]
1274
+ // For condition type
1275
+ condition?: string
1276
+ // For loop type
1277
+ items?: string
1278
+ maxIterations?: number
1279
+ // For parallel type
1280
+ branches?: string[]
1281
+ // For transform type
1282
+ transform?: string
1283
+ // For api-call type
1284
+ url?: string
1285
+ method?: string
1286
+ headers?: Record<string, string>
1287
+ body?: any
1288
+ }
1289
+
1290
+ export interface PromptStepCondition {
1291
+ condition: string
1292
+ next: string
1293
+ }
1294
+
1295
+ export interface PromptWorkflow {
1296
+ id: string
1297
+ name: string
1298
+ description?: string
1299
+ version?: string
1300
+ steps: PromptStep[]
1301
+ entryPoint: string
1302
+ variables: PromptVariable[]
1303
+ outputs?: string[]
1304
+ metadata?: Record<string, any>
1305
+ createdAt?: number
1306
+ updatedAt?: number
1307
+ }
1308
+
1309
+ export interface PromptWorkflowExecution {
1310
+ id: string
1311
+ workflowId: string
1312
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled'
1313
+ startedAt: number
1314
+ completedAt?: number
1315
+ inputs: Record<string, any>
1316
+ outputs?: Record<string, any>
1317
+ steps: Array<{
1318
+ stepId: string
1319
+ status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped'
1320
+ startedAt?: number
1321
+ completedAt?: number
1322
+ input?: any
1323
+ output?: any
1324
+ error?: string
1325
+ }>
1326
+ error?: string
1327
+ }
1328
+
1329
+ export interface PromptWorkflowContext {
1330
+ execution: PromptWorkflowExecution
1331
+ variables: Record<string, any>
1332
+ stepResults: Record<string, any>
1333
+ currentStep?: string
1334
+ }
1335
+
1336
+ // ============================================================================
1337
+ // Agent System
1338
+ // ============================================================================
1339
+
1340
+ /**
1341
+ * Tool definition for an AI agent.
1342
+ */
1343
+ export interface IntelligenceAgentTool {
1344
+ /** Tool name. */
1345
+ name: string
1346
+ /** Tool description. */
1347
+ description: string
1348
+ /** Parameter schema. */
1349
+ parameters: {
1350
+ type: 'object'
1351
+ properties: Record<string, {
1352
+ type: string
1353
+ description?: string
1354
+ enum?: any[]
1355
+ required?: boolean
1356
+ }>
1357
+ required?: string[]
1358
+ }
1359
+ /** Handler function name. */
1360
+ handler?: string
1361
+ }
1362
+
1363
+ /**
1364
+ * Payload for agent capability.
1365
+ */
1366
+ export interface IntelligenceAgentPayload {
1367
+ /** Task description. */
1368
+ task: string
1369
+ /** Available tools. */
1370
+ tools?: IntelligenceAgentTool[]
1371
+ /** Additional context. */
1372
+ context?: string
1373
+ /** Maximum iterations. */
1374
+ maxIterations?: number
1375
+ /** Conversation memory. */
1376
+ memory?: Array<{ role: string, content: string }>
1377
+ /** Constraints for the agent. */
1378
+ constraints?: string[]
1379
+ }
1380
+
1381
+ /**
1382
+ * Result from agent capability.
1383
+ */
1384
+ export interface IntelligenceAgentResult {
1385
+ /** Final result. */
1386
+ result: string
1387
+ /** Reasoning steps. */
1388
+ steps: Array<{
1389
+ thought: string
1390
+ action?: string
1391
+ actionInput?: any
1392
+ observation?: string
1393
+ }>
1394
+ /** Tool call history. */
1395
+ toolCalls: Array<{
1396
+ tool: string
1397
+ input: any
1398
+ output: any
1399
+ }>
1400
+ /** Number of iterations. */
1401
+ iterations: number
1402
+ }
1403
+
1404
+ // Legacy aliases for agent types
1405
+ /** @deprecated Use IntelligenceAgentTool instead. */
1406
+ export type AiAgentTool = IntelligenceAgentTool
1407
+ /** @deprecated Use IntelligenceAgentPayload instead. */
1408
+ export type AiAgentPayload = IntelligenceAgentPayload
1409
+ /** @deprecated Use IntelligenceAgentResult instead. */
1410
+ export type AiAgentResult = IntelligenceAgentResult
1411
+
1412
+ /**
1413
+ * SDK configuration.
1414
+ */
1415
+ export interface IntelligenceSDKConfig {
1416
+ /** Provider configurations. */
1417
+ providers: IntelligenceProviderConfig[]
1418
+ /** Default strategy ID. */
172
1419
  defaultStrategy: string
1420
+ /** Enable audit logging. */
173
1421
  enableAudit: boolean
1422
+ /** Enable result caching. */
174
1423
  enableCache: boolean
1424
+ /** Cache expiration in seconds. */
175
1425
  cacheExpiration?: number
176
- capabilities?: Record<string, AiCapabilityRoutingConfig>
1426
+ /** Capability routing configurations. */
1427
+ capabilities?: Record<string, IntelligenceCapabilityRoutingConfig>
177
1428
  }
178
1429
 
179
- export interface AiStrategyConfig {
1430
+ /**
1431
+ * Strategy configuration.
1432
+ */
1433
+ export interface IntelligenceStrategyConfig {
1434
+ /** Strategy ID. */
180
1435
  id: string
1436
+ /** Strategy name. */
181
1437
  name: string
1438
+ /** Strategy type. */
182
1439
  type: 'rule-based' | 'adaptive' | 'custom'
1440
+ /** Strategy rules. */
183
1441
  rules?: any
1442
+ /** Strategy priority. */
184
1443
  priority?: number
185
1444
  }
186
1445
 
187
- export interface AiAuditLog {
1446
+ /**
1447
+ * Audit log entry.
1448
+ */
1449
+ export interface IntelligenceAuditLog {
1450
+ /** Trace ID. */
188
1451
  traceId: string
1452
+ /** Timestamp. */
189
1453
  timestamp: number
1454
+ /** Capability ID. */
190
1455
  capabilityId: string
1456
+ /** Provider ID. */
191
1457
  provider: string
1458
+ /** Model used. */
192
1459
  model: string
1460
+ /** Prompt hash. */
193
1461
  promptHash?: string
1462
+ /** Caller identifier. */
194
1463
  caller?: string
195
- usage: AiUsageInfo
1464
+ /** Usage information. */
1465
+ usage: IntelligenceUsageInfo
1466
+ /** Latency in milliseconds. */
196
1467
  latency: number
1468
+ /** Success status. */
197
1469
  success: boolean
1470
+ /** Error message. */
198
1471
  error?: string
199
1472
  }
200
1473
 
201
- export interface AiCapabilityProviderBinding {
1474
+ /**
1475
+ * Provider binding for a capability.
1476
+ */
1477
+ export interface IntelligenceCapabilityProviderBinding {
1478
+ /** Provider ID. */
202
1479
  providerId: string
1480
+ /** Specific models to use. */
203
1481
  models?: string[]
1482
+ /** Priority for selection. */
204
1483
  priority?: number
1484
+ /** Whether binding is enabled. */
205
1485
  enabled?: boolean
1486
+ /** Additional metadata. */
206
1487
  metadata?: Record<string, any>
207
1488
  }
208
1489
 
209
- export interface AiCapabilityRoutingConfig {
1490
+ /**
1491
+ * Routing configuration for a capability.
1492
+ */
1493
+ export interface IntelligenceCapabilityRoutingConfig {
1494
+ /** Display label. */
210
1495
  label?: string
1496
+ /** Description. */
211
1497
  description?: string
212
- providers: AiCapabilityProviderBinding[]
1498
+ /** Provider bindings. */
1499
+ providers: IntelligenceCapabilityProviderBinding[]
1500
+ /** Prompt template. */
213
1501
  promptTemplate?: string
1502
+ /** Test resource directory. */
214
1503
  testResourceDir?: string
1504
+ /** Additional metadata. */
215
1505
  metadata?: Record<string, any>
216
1506
  }
217
1507
 
218
- export interface AiSDKPersistedConfig {
219
- providers: AiProviderConfig[]
1508
+ /**
1509
+ * Persisted SDK configuration.
1510
+ */
1511
+ export interface IntelligenceSDKPersistedConfig {
1512
+ /** Provider configurations. */
1513
+ providers: IntelligenceProviderConfig[]
1514
+ /** Global configuration. */
220
1515
  globalConfig: {
221
1516
  defaultStrategy: string
222
1517
  enableAudit: boolean
223
1518
  enableCache: boolean
224
1519
  cacheExpiration?: number
225
1520
  }
226
- capabilities?: Record<string, AiCapabilityRoutingConfig>
1521
+ /** Capability configurations. */
1522
+ capabilities?: Record<string, IntelligenceCapabilityRoutingConfig>
1523
+ /** Configuration version. */
227
1524
  version: number
228
1525
  }
229
1526
 
230
- export interface AiProviderAdapter {
231
- readonly type: AiProviderType
232
- getConfig: () => AiProviderConfig
233
- updateConfig: (config: Partial<AiProviderConfig>) => void
1527
+ // Legacy aliases for SDK types
1528
+ /** @deprecated Use IntelligenceSDKConfig instead. */
1529
+ export type AiSDKConfig = IntelligenceSDKConfig
1530
+ /** @deprecated Use IntelligenceStrategyConfig instead. */
1531
+ export type AiStrategyConfig = IntelligenceStrategyConfig
1532
+ /** @deprecated Use IntelligenceAuditLog instead. */
1533
+ export type AiAuditLog = IntelligenceAuditLog
1534
+ /** @deprecated Use IntelligenceCapabilityProviderBinding instead. */
1535
+ export type AiCapabilityProviderBinding = IntelligenceCapabilityProviderBinding
1536
+ /** @deprecated Use IntelligenceCapabilityRoutingConfig instead. */
1537
+ export type AiCapabilityRoutingConfig = IntelligenceCapabilityRoutingConfig
1538
+ /** @deprecated Use IntelligenceSDKPersistedConfig instead. */
1539
+ export type AiSDKPersistedConfig = IntelligenceSDKPersistedConfig
1540
+
1541
+ /**
1542
+ * Provider adapter interface.
1543
+ */
1544
+ export interface IntelligenceProviderAdapter {
1545
+ /** Provider type. */
1546
+ readonly type: IntelligenceProviderType
1547
+ /** Get provider configuration. */
1548
+ getConfig: () => IntelligenceProviderConfig
1549
+ /** Update provider configuration. */
1550
+ updateConfig: (config: Partial<IntelligenceProviderConfig>) => void
1551
+ /** Check if provider is enabled. */
234
1552
  isEnabled: () => boolean
235
- chat: (payload: AiChatPayload, options: AiInvokeOptions) => Promise<AiInvokeResult<string>>
236
- chatStream: (
237
- payload: AiChatPayload,
238
- options: AiInvokeOptions,
239
- ) => AsyncGenerator<AiStreamChunk>
240
- embedding: (payload: AiEmbeddingPayload, options: AiInvokeOptions) => Promise<AiInvokeResult<number[]>>
241
- translate: (payload: AiTranslatePayload, options: AiInvokeOptions) => Promise<AiInvokeResult<string>>
242
- visionOcr: (
243
- payload: AiVisionOcrPayload,
244
- options: AiInvokeOptions,
245
- ) => Promise<AiInvokeResult<AiVisionOcrResult>>
246
- }
247
-
248
- export interface ProviderManagerAdapter {
1553
+
1554
+ // Core text capabilities
1555
+ chat: (payload: IntelligenceChatPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<string>>
1556
+ chatStream: (payload: IntelligenceChatPayload, options: IntelligenceInvokeOptions) => AsyncGenerator<IntelligenceStreamChunk>
1557
+ embedding: (payload: IntelligenceEmbeddingPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<number[]>>
1558
+ translate: (payload: IntelligenceTranslatePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<string>>
1559
+ summarize?: (payload: IntelligenceSummarizePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<string>>
1560
+ rewrite?: (payload: IntelligenceRewritePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<string>>
1561
+ grammarCheck?: (payload: IntelligenceGrammarCheckPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceGrammarCheckResult>>
1562
+
1563
+ // Code capabilities
1564
+ codeGenerate?: (payload: IntelligenceCodeGeneratePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceCodeGenerateResult>>
1565
+ codeExplain?: (payload: IntelligenceCodeExplainPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceCodeExplainResult>>
1566
+ codeReview?: (payload: IntelligenceCodeReviewPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceCodeReviewResult>>
1567
+ codeRefactor?: (payload: IntelligenceCodeRefactorPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceCodeRefactorResult>>
1568
+ codeDebug?: (payload: IntelligenceCodeDebugPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceCodeDebugResult>>
1569
+
1570
+ // Analysis capabilities
1571
+ intentDetect?: (payload: IntelligenceIntentDetectPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceIntentDetectResult>>
1572
+ sentimentAnalyze?: (payload: IntelligenceSentimentAnalyzePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceSentimentAnalyzeResult>>
1573
+ contentExtract?: (payload: IntelligenceContentExtractPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceContentExtractResult>>
1574
+ keywordsExtract?: (payload: IntelligenceKeywordsExtractPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceKeywordsExtractResult>>
1575
+ classification?: (payload: IntelligenceClassificationPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceClassificationResult>>
1576
+
1577
+ // Vision capabilities
1578
+ visionOcr: (payload: IntelligenceVisionOcrPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceVisionOcrResult>>
1579
+ imageCaption?: (payload: IntelligenceImageCaptionPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceImageCaptionResult>>
1580
+ imageAnalyze?: (payload: IntelligenceImageAnalyzePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceImageAnalyzeResult>>
1581
+ imageGenerate?: (payload: IntelligenceImageGeneratePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceImageGenerateResult>>
1582
+ imageEdit?: (payload: IntelligenceImageEditPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceImageEditResult>>
1583
+
1584
+ // Audio capabilities
1585
+ tts?: (payload: IntelligenceTTSPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceTTSResult>>
1586
+ stt?: (payload: IntelligenceSTTPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceSTTResult>>
1587
+ audioTranscribe?: (payload: IntelligenceAudioTranscribePayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceAudioTranscribeResult>>
1588
+
1589
+ // RAG & Search capabilities
1590
+ ragQuery?: (payload: IntelligenceRAGQueryPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceRAGQueryResult>>
1591
+ semanticSearch?: (payload: IntelligenceSemanticSearchPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceSemanticSearchResult>>
1592
+ rerank?: (payload: IntelligenceRerankPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceRerankResult>>
1593
+
1594
+ // Agent capabilities
1595
+ agent?: (payload: IntelligenceAgentPayload, options: IntelligenceInvokeOptions) => Promise<IntelligenceInvokeResult<IntelligenceAgentResult>>
1596
+ }
1597
+
1598
+ /** @deprecated Use IntelligenceProviderAdapter instead. */
1599
+ export type AiProviderAdapter = IntelligenceProviderAdapter
1600
+
1601
+ /**
1602
+ * Provider manager adapter interface.
1603
+ */
1604
+ export interface IntelligenceProviderManagerAdapter {
1605
+ /** Clear all providers. */
249
1606
  clear: () => void
250
- registerFromConfig: (config: AiProviderConfig) => AiProviderAdapter
251
- getEnabled: () => AiProviderAdapter[]
252
- get: (providerId: string) => AiProviderAdapter | undefined
253
- createProviderInstance: (config: AiProviderConfig) => AiProviderAdapter
1607
+ /** Register provider from configuration. */
1608
+ registerFromConfig: (config: IntelligenceProviderConfig) => IntelligenceProviderAdapter
1609
+ /** Get all enabled providers. */
1610
+ getEnabled: () => IntelligenceProviderAdapter[]
1611
+ /** Get provider by ID. */
1612
+ get: (providerId: string) => IntelligenceProviderAdapter | undefined
1613
+ /** Create provider instance. */
1614
+ createProviderInstance: (config: IntelligenceProviderConfig) => IntelligenceProviderAdapter
254
1615
  }
255
1616
 
256
- export interface AISDKGlobalConfig {
1617
+ /** @deprecated Use IntelligenceProviderManagerAdapter instead. */
1618
+ export type ProviderManagerAdapter = IntelligenceProviderManagerAdapter
1619
+
1620
+ /**
1621
+ * Global SDK configuration.
1622
+ */
1623
+ export interface IntelligenceGlobalConfig {
1624
+ /** Default strategy ID. */
257
1625
  defaultStrategy: string
1626
+ /** Enable audit logging. */
258
1627
  enableAudit: boolean
1628
+ /** Enable result caching. */
259
1629
  enableCache: boolean
1630
+ /** Cache expiration in seconds. */
260
1631
  cacheExpiration?: number
1632
+ /** Maximum retry attempts. */
261
1633
  maxRetries?: number
1634
+ /** Default timeout in milliseconds. */
262
1635
  defaultTimeout?: number
1636
+ /** Enable logging. */
263
1637
  enableLogging?: boolean
1638
+ /** Log level. */
264
1639
  logLevel?: 'debug' | 'info' | 'warn' | 'error'
1640
+ /** Enable caching. */
265
1641
  enableCaching?: boolean
1642
+ /** Cache size limit. */
266
1643
  cacheSize?: number
1644
+ /** Fallback strategy. */
267
1645
  fallbackStrategy?: 'next-available' | 'fail-fast' | 'round-robin'
1646
+ /** Allow parallel requests. */
268
1647
  parallelRequests?: boolean
269
1648
  }
270
1649
 
271
- export interface TestResult {
1650
+ /** @deprecated Use IntelligenceGlobalConfig instead. */
1651
+ export type AISDKGlobalConfig = IntelligenceGlobalConfig
1652
+
1653
+ /**
1654
+ * Test result structure.
1655
+ */
1656
+ export interface IntelligenceTestResult {
1657
+ /** Whether test succeeded. */
272
1658
  success: boolean
1659
+ /** Result message. */
273
1660
  message?: string
1661
+ /** Latency in milliseconds. */
274
1662
  latency?: number
1663
+ /** Test timestamp. */
275
1664
  timestamp: number
276
1665
  }
277
1666
 
278
- export interface AISDKCapabilityConfig {
1667
+ /** @deprecated Use IntelligenceTestResult instead. */
1668
+ export type TestResult = IntelligenceTestResult
1669
+
1670
+ /**
1671
+ * Capability configuration for SDK.
1672
+ */
1673
+ export interface IntelligenceCapabilityConfig {
1674
+ /** Capability ID. */
279
1675
  id: string
1676
+ /** Display label. */
280
1677
  label: string
1678
+ /** Description. */
281
1679
  description?: string
282
- providers: AiCapabilityProviderBinding[]
1680
+ /** Provider bindings. */
1681
+ providers: IntelligenceCapabilityProviderBinding[]
1682
+ /** Prompt template. */
283
1683
  promptTemplate?: string
1684
+ /** Test resource directory. */
284
1685
  testResourceDir?: string
1686
+ /** Additional metadata. */
285
1687
  metadata?: Record<string, any>
286
1688
  }
287
1689
 
288
- export interface AISDKStorageData {
289
- providers: AiProviderConfig[]
290
- globalConfig: AISDKGlobalConfig
291
- capabilities: Record<string, AISDKCapabilityConfig>
1690
+ /** @deprecated Use IntelligenceCapabilityConfig instead. */
1691
+ export type AISDKCapabilityConfig = IntelligenceCapabilityConfig
1692
+
1693
+ /**
1694
+ * Storage data structure for SDK.
1695
+ */
1696
+ export interface IntelligenceStorageData {
1697
+ /** Provider configurations. */
1698
+ providers: IntelligenceProviderConfig[]
1699
+ /** Global configuration. */
1700
+ globalConfig: IntelligenceGlobalConfig
1701
+ /** Capability configurations. */
1702
+ capabilities: Record<string, IntelligenceCapabilityConfig>
1703
+ /** Data version. */
292
1704
  version: number
293
1705
  }
294
1706
 
295
- export const DEFAULT_PROVIDERS: AiProviderConfig[] = [
1707
+ /** @deprecated Use IntelligenceStorageData instead. */
1708
+ export type AISDKStorageData = IntelligenceStorageData
1709
+
1710
+ /**
1711
+ * Default provider configurations.
1712
+ */
1713
+ export const DEFAULT_PROVIDERS: IntelligenceProviderConfig[] = [
296
1714
  {
297
1715
  id: 'openai-default',
298
- type: AiProviderType.OPENAI,
1716
+ type: IntelligenceProviderType.OPENAI,
299
1717
  name: 'OpenAI',
300
1718
  enabled: false,
301
1719
  priority: 1,
@@ -306,7 +1724,7 @@ export const DEFAULT_PROVIDERS: AiProviderConfig[] = [
306
1724
  },
307
1725
  {
308
1726
  id: 'anthropic-default',
309
- type: AiProviderType.ANTHROPIC,
1727
+ type: IntelligenceProviderType.ANTHROPIC,
310
1728
  name: 'Anthropic',
311
1729
  enabled: false,
312
1730
  priority: 2,
@@ -317,7 +1735,7 @@ export const DEFAULT_PROVIDERS: AiProviderConfig[] = [
317
1735
  },
318
1736
  {
319
1737
  id: 'deepseek-default',
320
- type: AiProviderType.DEEPSEEK,
1738
+ type: IntelligenceProviderType.DEEPSEEK,
321
1739
  name: 'DeepSeek',
322
1740
  enabled: false,
323
1741
  priority: 2,
@@ -328,7 +1746,7 @@ export const DEFAULT_PROVIDERS: AiProviderConfig[] = [
328
1746
  },
329
1747
  {
330
1748
  id: 'siliconflow-default',
331
- type: AiProviderType.SILICONFLOW,
1749
+ type: IntelligenceProviderType.SILICONFLOW,
332
1750
  name: 'SiliconFlow',
333
1751
  enabled: false,
334
1752
  priority: 2,
@@ -350,7 +1768,7 @@ export const DEFAULT_PROVIDERS: AiProviderConfig[] = [
350
1768
  },
351
1769
  {
352
1770
  id: 'local-default',
353
- type: AiProviderType.LOCAL,
1771
+ type: IntelligenceProviderType.LOCAL,
354
1772
  name: 'Local Model',
355
1773
  enabled: false,
356
1774
  priority: 3,