cognitive-modules-cli 2.2.1 → 2.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +12 -65
- package/dist/commands/index.d.ts +0 -1
- package/dist/commands/index.js +0 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -5
- package/dist/modules/index.d.ts +0 -2
- package/dist/modules/index.js +0 -2
- package/dist/modules/loader.d.ts +2 -22
- package/dist/modules/loader.js +4 -167
- package/dist/modules/runner.d.ts +34 -348
- package/dist/modules/runner.js +708 -1263
- package/dist/modules/subagent.js +0 -2
- package/dist/providers/base.d.ts +45 -1
- package/dist/providers/base.js +67 -0
- package/dist/providers/openai.d.ts +27 -3
- package/dist/providers/openai.js +175 -3
- package/dist/types.d.ts +316 -93
- package/dist/types.js +120 -1
- package/package.json +1 -2
- package/src/cli.ts +12 -73
- package/src/commands/index.ts +0 -1
- package/src/index.ts +0 -35
- package/src/modules/index.ts +0 -2
- package/src/modules/loader.ts +6 -196
- package/src/modules/runner.ts +996 -1690
- package/src/modules/subagent.ts +0 -2
- package/src/providers/base.ts +86 -1
- package/src/providers/openai.ts +226 -4
- package/src/types.ts +462 -113
- package/tsconfig.json +1 -1
- package/dist/commands/compose.d.ts +0 -31
- package/dist/commands/compose.js +0 -148
- package/dist/modules/composition.d.ts +0 -251
- package/dist/modules/composition.js +0 -1265
- package/dist/modules/composition.test.d.ts +0 -11
- package/dist/modules/composition.test.js +0 -450
- package/dist/modules/policy.test.d.ts +0 -10
- package/dist/modules/policy.test.js +0 -369
- package/dist/modules/validator.d.ts +0 -28
- package/dist/modules/validator.js +0 -629
- package/src/commands/compose.ts +0 -185
- package/src/modules/composition.test.ts +0 -558
- package/src/modules/composition.ts +0 -1674
- package/src/modules/policy.test.ts +0 -455
- package/src/modules/validator.ts +0 -700
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cognitive Runtime - Core Types
|
|
3
|
-
* Version 2.
|
|
3
|
+
* Version 2.5 - With streaming response and multimodal support
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// =============================================================================
|
|
@@ -53,90 +53,6 @@ export type EnumStrategy = 'strict' | 'extensible';
|
|
|
53
53
|
/** Risk aggregation rule */
|
|
54
54
|
export type RiskRule = 'max_changes_risk' | 'max_issues_risk' | 'explicit';
|
|
55
55
|
|
|
56
|
-
// =============================================================================
|
|
57
|
-
// Composition Types (v2.2)
|
|
58
|
-
// =============================================================================
|
|
59
|
-
|
|
60
|
-
/** Composition pattern types */
|
|
61
|
-
export type CompositionPattern = 'sequential' | 'parallel' | 'conditional' | 'iterative';
|
|
62
|
-
|
|
63
|
-
/** Aggregation strategy for combining multiple outputs */
|
|
64
|
-
export type AggregationStrategy = 'merge' | 'array' | 'first' | 'custom';
|
|
65
|
-
|
|
66
|
-
/** Semver-like version matching pattern */
|
|
67
|
-
export type VersionPattern = string; // e.g., ">=1.0.0", "^1.0.0", "~1.0.0", "*"
|
|
68
|
-
|
|
69
|
-
/** Dependency declaration for composition.requires */
|
|
70
|
-
export interface DependencyDeclaration {
|
|
71
|
-
/** Module name */
|
|
72
|
-
name: string;
|
|
73
|
-
/** Semver version pattern */
|
|
74
|
-
version?: VersionPattern;
|
|
75
|
-
/** Whether dependency is optional */
|
|
76
|
-
optional?: boolean;
|
|
77
|
-
/** Fallback module if unavailable */
|
|
78
|
-
fallback?: string | null;
|
|
79
|
-
/** Per-module timeout (ms) */
|
|
80
|
-
timeout_ms?: number;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Dataflow mapping expression */
|
|
84
|
-
export interface DataflowMapping {
|
|
85
|
-
[key: string]: string; // target_field: "$.source.path"
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Dataflow step configuration */
|
|
89
|
-
export interface DataflowStep {
|
|
90
|
-
/** Source of data: 'input' or 'module-name.output' */
|
|
91
|
-
from: string | string[];
|
|
92
|
-
/** Destination: module name or 'output' */
|
|
93
|
-
to: string | string[];
|
|
94
|
-
/** Field mapping expressions */
|
|
95
|
-
mapping?: DataflowMapping;
|
|
96
|
-
/** Condition for execution */
|
|
97
|
-
condition?: string;
|
|
98
|
-
/** Aggregation strategy when from is an array */
|
|
99
|
-
aggregate?: AggregationStrategy;
|
|
100
|
-
/** Custom aggregation function name */
|
|
101
|
-
aggregator?: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Conditional routing rule */
|
|
105
|
-
export interface RoutingRule {
|
|
106
|
-
/** Condition expression */
|
|
107
|
-
condition: string;
|
|
108
|
-
/** Next module to execute (null means use current result) */
|
|
109
|
-
next: string | null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Iteration configuration */
|
|
113
|
-
export interface IterationConfig {
|
|
114
|
-
/** Maximum iterations */
|
|
115
|
-
max_iterations?: number;
|
|
116
|
-
/** Condition to continue iterating */
|
|
117
|
-
continue_condition?: string;
|
|
118
|
-
/** Condition to stop iterating */
|
|
119
|
-
stop_condition?: string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** Full composition configuration (from module.yaml) */
|
|
123
|
-
export interface CompositionConfig {
|
|
124
|
-
/** Composition pattern */
|
|
125
|
-
pattern: CompositionPattern;
|
|
126
|
-
/** Required dependencies */
|
|
127
|
-
requires?: DependencyDeclaration[];
|
|
128
|
-
/** Dataflow configuration */
|
|
129
|
-
dataflow?: DataflowStep[];
|
|
130
|
-
/** Conditional routing rules */
|
|
131
|
-
routing?: RoutingRule[];
|
|
132
|
-
/** Maximum composition depth */
|
|
133
|
-
max_depth?: number;
|
|
134
|
-
/** Total timeout for composition (ms) */
|
|
135
|
-
timeout_ms?: number;
|
|
136
|
-
/** Iteration configuration */
|
|
137
|
-
iteration?: IterationConfig;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
56
|
// =============================================================================
|
|
141
57
|
// Module Configuration (v2.2)
|
|
142
58
|
// =============================================================================
|
|
@@ -184,9 +100,6 @@ export interface CognitiveModule {
|
|
|
184
100
|
// v2.2: Meta configuration (including risk_rule)
|
|
185
101
|
metaConfig?: MetaConfig;
|
|
186
102
|
|
|
187
|
-
// v2.2: Composition configuration
|
|
188
|
-
composition?: CompositionConfig;
|
|
189
|
-
|
|
190
103
|
// Execution context
|
|
191
104
|
context?: 'fork' | 'main';
|
|
192
105
|
|
|
@@ -310,30 +223,9 @@ export interface EnvelopeMeta {
|
|
|
310
223
|
latency_ms?: number;
|
|
311
224
|
}
|
|
312
225
|
|
|
313
|
-
/**
|
|
314
|
-
* Enhanced error structure with retry and recovery info (v2.2.1).
|
|
315
|
-
*/
|
|
316
|
-
export interface EnvelopeError {
|
|
317
|
-
/** Error code (e.g., "INVALID_INPUT", "PARSE_ERROR") */
|
|
318
|
-
code: string;
|
|
319
|
-
|
|
320
|
-
/** Human-readable error message */
|
|
321
|
-
message: string;
|
|
322
|
-
|
|
323
|
-
/** Whether the error can be retried */
|
|
324
|
-
recoverable?: boolean;
|
|
325
|
-
|
|
326
|
-
/** Suggested wait time before retry (in milliseconds) */
|
|
327
|
-
retry_after_ms?: number;
|
|
328
|
-
|
|
329
|
-
/** Additional error context */
|
|
330
|
-
details?: Record<string, unknown>;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
226
|
/** Success response in v2.2 envelope format */
|
|
334
227
|
export interface EnvelopeSuccessV22<T = unknown> {
|
|
335
228
|
ok: true;
|
|
336
|
-
version?: string; // Envelope version (e.g., "2.2")
|
|
337
229
|
meta: EnvelopeMeta;
|
|
338
230
|
data: T;
|
|
339
231
|
}
|
|
@@ -341,9 +233,11 @@ export interface EnvelopeSuccessV22<T = unknown> {
|
|
|
341
233
|
/** Error response in v2.2 envelope format */
|
|
342
234
|
export interface EnvelopeErrorV22 {
|
|
343
235
|
ok: false;
|
|
344
|
-
version?: string; // Envelope version (e.g., "2.2")
|
|
345
236
|
meta: EnvelopeMeta;
|
|
346
|
-
error:
|
|
237
|
+
error: {
|
|
238
|
+
code: string;
|
|
239
|
+
message: string;
|
|
240
|
+
};
|
|
347
241
|
partial_data?: unknown;
|
|
348
242
|
}
|
|
349
243
|
|
|
@@ -424,10 +318,12 @@ export interface ModuleResultData {
|
|
|
424
318
|
/** v2.2 module result with meta and data separation */
|
|
425
319
|
export interface ModuleResultV22 {
|
|
426
320
|
ok: boolean;
|
|
427
|
-
version?: string; // Envelope version (e.g., "2.2")
|
|
428
321
|
meta: EnvelopeMeta;
|
|
429
322
|
data?: ModuleResultData;
|
|
430
|
-
error?:
|
|
323
|
+
error?: {
|
|
324
|
+
code: string;
|
|
325
|
+
message: string;
|
|
326
|
+
};
|
|
431
327
|
partial_data?: unknown;
|
|
432
328
|
raw?: string;
|
|
433
329
|
}
|
|
@@ -597,3 +493,456 @@ export function shouldEscalate<T>(
|
|
|
597
493
|
|
|
598
494
|
return false;
|
|
599
495
|
}
|
|
496
|
+
|
|
497
|
+
// =============================================================================
|
|
498
|
+
// v2.5 Streaming Types
|
|
499
|
+
// =============================================================================
|
|
500
|
+
|
|
501
|
+
/** Response mode configuration */
|
|
502
|
+
export type ResponseMode = 'sync' | 'streaming' | 'both';
|
|
503
|
+
|
|
504
|
+
/** Chunk type for streaming */
|
|
505
|
+
export type ChunkType = 'delta' | 'snapshot';
|
|
506
|
+
|
|
507
|
+
/** Response configuration in module.yaml */
|
|
508
|
+
export interface ResponseConfig {
|
|
509
|
+
mode: ResponseMode;
|
|
510
|
+
chunk_type?: ChunkType;
|
|
511
|
+
buffer_size?: number;
|
|
512
|
+
heartbeat_interval_ms?: number;
|
|
513
|
+
max_duration_ms?: number;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** Meta chunk - initial streaming response */
|
|
517
|
+
export interface MetaChunk {
|
|
518
|
+
ok: true;
|
|
519
|
+
streaming: true;
|
|
520
|
+
session_id: string;
|
|
521
|
+
resumed?: boolean;
|
|
522
|
+
resume_from_seq?: number;
|
|
523
|
+
meta: Partial<EnvelopeMeta>;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** Delta chunk - incremental content */
|
|
527
|
+
export interface DeltaChunk {
|
|
528
|
+
chunk: {
|
|
529
|
+
seq: number;
|
|
530
|
+
type: 'delta';
|
|
531
|
+
field?: string;
|
|
532
|
+
delta: string;
|
|
533
|
+
checkpoint?: Checkpoint;
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** Snapshot chunk - full state replacement */
|
|
538
|
+
export interface SnapshotChunk {
|
|
539
|
+
chunk: {
|
|
540
|
+
seq: number;
|
|
541
|
+
type: 'snapshot';
|
|
542
|
+
field?: string;
|
|
543
|
+
data: unknown;
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** Progress chunk - progress update */
|
|
548
|
+
export interface ProgressChunk {
|
|
549
|
+
progress: {
|
|
550
|
+
percent: number;
|
|
551
|
+
stage?: string;
|
|
552
|
+
message?: string;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** Final chunk - completion signal */
|
|
557
|
+
export interface FinalChunk {
|
|
558
|
+
final: true;
|
|
559
|
+
meta: EnvelopeMeta;
|
|
560
|
+
data: ModuleResultData;
|
|
561
|
+
usage?: {
|
|
562
|
+
input_tokens: number;
|
|
563
|
+
output_tokens: number;
|
|
564
|
+
total_tokens: number;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** Recovery checkpoint for stream resume */
|
|
569
|
+
export interface Checkpoint {
|
|
570
|
+
offset: number;
|
|
571
|
+
hash: string; // First 6 chars of SHA256
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** Recovery information in error */
|
|
575
|
+
export interface RecoveryInfo {
|
|
576
|
+
last_seq: number;
|
|
577
|
+
last_checkpoint?: Checkpoint;
|
|
578
|
+
retry_after_ms?: number;
|
|
579
|
+
max_retries?: number;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** Error with optional recovery information */
|
|
583
|
+
export interface ErrorWithRecovery {
|
|
584
|
+
code: string;
|
|
585
|
+
message: string;
|
|
586
|
+
recoverable?: boolean;
|
|
587
|
+
recovery?: RecoveryInfo;
|
|
588
|
+
details?: Record<string, unknown>;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** Error chunk during streaming */
|
|
592
|
+
export interface ErrorChunk {
|
|
593
|
+
ok: false;
|
|
594
|
+
streaming: true;
|
|
595
|
+
session_id?: string;
|
|
596
|
+
error: ErrorWithRecovery;
|
|
597
|
+
partial_data?: unknown;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** Union of all streaming chunk types */
|
|
601
|
+
export type StreamingChunk =
|
|
602
|
+
| MetaChunk
|
|
603
|
+
| DeltaChunk
|
|
604
|
+
| SnapshotChunk
|
|
605
|
+
| ProgressChunk
|
|
606
|
+
| FinalChunk
|
|
607
|
+
| ErrorChunk;
|
|
608
|
+
|
|
609
|
+
/** Streaming session state */
|
|
610
|
+
export interface StreamingSession {
|
|
611
|
+
session_id: string;
|
|
612
|
+
module_name: string;
|
|
613
|
+
started_at: number;
|
|
614
|
+
chunks_sent: number;
|
|
615
|
+
accumulated_data: Record<string, unknown>;
|
|
616
|
+
accumulated_text: Record<string, string>;
|
|
617
|
+
last_checkpoint?: Checkpoint;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// =============================================================================
|
|
621
|
+
// v2.5 Response Mode Negotiation
|
|
622
|
+
// =============================================================================
|
|
623
|
+
|
|
624
|
+
/** Request options for response mode negotiation */
|
|
625
|
+
export interface RequestOptions {
|
|
626
|
+
response_mode?: ResponseMode;
|
|
627
|
+
chunk_type?: ChunkType;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** Recovery context for stream retry */
|
|
631
|
+
export interface RecoveryContext {
|
|
632
|
+
session_id: string;
|
|
633
|
+
last_seq: number;
|
|
634
|
+
last_checkpoint?: Checkpoint;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** Warning in response (for fallback scenarios) */
|
|
638
|
+
export interface ResponseWarning {
|
|
639
|
+
code: string;
|
|
640
|
+
message: string;
|
|
641
|
+
fallback_used?: string;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** Execute options with negotiation support */
|
|
645
|
+
export interface ExecuteOptionsV25 {
|
|
646
|
+
input: Record<string, unknown>;
|
|
647
|
+
_options?: RequestOptions;
|
|
648
|
+
_recovery?: RecoveryContext;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** Negotiation result */
|
|
652
|
+
export interface NegotiationResult {
|
|
653
|
+
mode: ResponseMode;
|
|
654
|
+
reason: 'header' | 'body_option' | 'query_param' | 'accept_header' | 'module_default';
|
|
655
|
+
warnings?: ResponseWarning[];
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// =============================================================================
|
|
659
|
+
// v2.5 Multimodal Types
|
|
660
|
+
// =============================================================================
|
|
661
|
+
|
|
662
|
+
/** Supported modality types */
|
|
663
|
+
export type ModalityType = 'text' | 'image' | 'audio' | 'video' | 'document';
|
|
664
|
+
|
|
665
|
+
/** Modalities configuration in module.yaml */
|
|
666
|
+
export interface ModalitiesConfig {
|
|
667
|
+
input: ModalityType[];
|
|
668
|
+
output: ModalityType[];
|
|
669
|
+
constraints?: MediaConstraints;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/** Media size/duration constraints */
|
|
673
|
+
export interface MediaConstraints {
|
|
674
|
+
max_image_size_mb?: number;
|
|
675
|
+
max_audio_size_mb?: number;
|
|
676
|
+
max_video_size_mb?: number;
|
|
677
|
+
max_audio_duration_s?: number;
|
|
678
|
+
max_video_duration_s?: number;
|
|
679
|
+
allowed_image_types?: string[];
|
|
680
|
+
allowed_audio_types?: string[];
|
|
681
|
+
allowed_video_types?: string[];
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** Media input - URL reference */
|
|
685
|
+
export interface UrlMediaInput {
|
|
686
|
+
type: 'url';
|
|
687
|
+
url: string;
|
|
688
|
+
media_type?: string;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** Media input - Base64 inline */
|
|
692
|
+
export interface Base64MediaInput {
|
|
693
|
+
type: 'base64';
|
|
694
|
+
media_type: string;
|
|
695
|
+
data: string;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/** Media input - File path */
|
|
699
|
+
export interface FileMediaInput {
|
|
700
|
+
type: 'file';
|
|
701
|
+
path: string;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/** Media input - Upload reference (for pre-uploaded files) */
|
|
705
|
+
export interface UploadRefMediaInput {
|
|
706
|
+
type: 'upload_ref';
|
|
707
|
+
upload_id: string;
|
|
708
|
+
media_type?: string;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** Union of media input types */
|
|
712
|
+
export type MediaInput = UrlMediaInput | Base64MediaInput | FileMediaInput | UploadRefMediaInput;
|
|
713
|
+
|
|
714
|
+
/** Checksum for media integrity */
|
|
715
|
+
export interface MediaChecksum {
|
|
716
|
+
algorithm: 'sha256' | 'md5' | 'crc32';
|
|
717
|
+
value: string;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/** Media validation result */
|
|
721
|
+
export interface MediaValidationResult {
|
|
722
|
+
index: number;
|
|
723
|
+
media_type: string;
|
|
724
|
+
size_bytes: number;
|
|
725
|
+
dimensions?: {
|
|
726
|
+
width: number;
|
|
727
|
+
height: number;
|
|
728
|
+
};
|
|
729
|
+
duration_ms?: number;
|
|
730
|
+
valid: boolean;
|
|
731
|
+
errors?: string[];
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/** Media validation summary in meta */
|
|
735
|
+
export interface MediaValidationSummary {
|
|
736
|
+
input_count: number;
|
|
737
|
+
validated: MediaValidationResult[];
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/** Magic bytes for media type detection */
|
|
741
|
+
export const MEDIA_MAGIC_BYTES: Record<string, string[]> = {
|
|
742
|
+
'image/jpeg': ['ffd8ff'],
|
|
743
|
+
'image/png': ['89504e470d0a1a0a'],
|
|
744
|
+
'image/gif': ['47494638'],
|
|
745
|
+
'image/webp': ['52494646'],
|
|
746
|
+
'audio/mpeg': ['fffb', 'fffa', '494433'],
|
|
747
|
+
'audio/wav': ['52494646'],
|
|
748
|
+
'audio/ogg': ['4f676753'],
|
|
749
|
+
'video/mp4': ['0000001866747970', '0000002066747970'],
|
|
750
|
+
'video/webm': ['1a45dfa3'],
|
|
751
|
+
'application/pdf': ['25504446'],
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
/** Media size limits in bytes */
|
|
755
|
+
export const MEDIA_SIZE_LIMITS: Record<string, number> = {
|
|
756
|
+
'image': 20 * 1024 * 1024, // 20MB
|
|
757
|
+
'audio': 25 * 1024 * 1024, // 25MB
|
|
758
|
+
'video': 100 * 1024 * 1024, // 100MB
|
|
759
|
+
'document': 50 * 1024 * 1024, // 50MB
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
/** Media dimension limits */
|
|
763
|
+
export const MEDIA_DIMENSION_LIMITS = {
|
|
764
|
+
max_width: 8192,
|
|
765
|
+
max_height: 8192,
|
|
766
|
+
min_width: 10,
|
|
767
|
+
min_height: 10,
|
|
768
|
+
max_pixels: 67108864, // 8192 x 8192
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
/** Media output with metadata */
|
|
772
|
+
export interface MediaOutput {
|
|
773
|
+
type: 'url' | 'base64' | 'file';
|
|
774
|
+
media_type: string;
|
|
775
|
+
url?: string;
|
|
776
|
+
data?: string;
|
|
777
|
+
path?: string;
|
|
778
|
+
width?: number;
|
|
779
|
+
height?: number;
|
|
780
|
+
duration_ms?: number;
|
|
781
|
+
expires_at?: string;
|
|
782
|
+
generation_params?: Record<string, unknown>;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/** Supported image MIME types */
|
|
786
|
+
export const SUPPORTED_IMAGE_TYPES = [
|
|
787
|
+
'image/jpeg',
|
|
788
|
+
'image/png',
|
|
789
|
+
'image/webp',
|
|
790
|
+
'image/gif'
|
|
791
|
+
] as const;
|
|
792
|
+
|
|
793
|
+
/** Supported audio MIME types */
|
|
794
|
+
export const SUPPORTED_AUDIO_TYPES = [
|
|
795
|
+
'audio/mpeg',
|
|
796
|
+
'audio/wav',
|
|
797
|
+
'audio/ogg',
|
|
798
|
+
'audio/webm'
|
|
799
|
+
] as const;
|
|
800
|
+
|
|
801
|
+
/** Supported video MIME types */
|
|
802
|
+
export const SUPPORTED_VIDEO_TYPES = [
|
|
803
|
+
'video/mp4',
|
|
804
|
+
'video/webm',
|
|
805
|
+
'video/quicktime'
|
|
806
|
+
] as const;
|
|
807
|
+
|
|
808
|
+
// =============================================================================
|
|
809
|
+
// v2.5 Error Codes
|
|
810
|
+
// =============================================================================
|
|
811
|
+
|
|
812
|
+
/** v2.5 Error codes for streaming and multimodal */
|
|
813
|
+
export const ErrorCodesV25 = {
|
|
814
|
+
// Media errors (E1xxx)
|
|
815
|
+
UNSUPPORTED_MEDIA_TYPE: 'E1010',
|
|
816
|
+
MEDIA_TOO_LARGE: 'E1011',
|
|
817
|
+
MEDIA_FETCH_FAILED: 'E1012',
|
|
818
|
+
MEDIA_DECODE_FAILED: 'E1013',
|
|
819
|
+
MEDIA_TYPE_MISMATCH: 'E1014',
|
|
820
|
+
MEDIA_DIMENSION_EXCEEDED: 'E1015',
|
|
821
|
+
MEDIA_DIMENSION_TOO_SMALL: 'E1016',
|
|
822
|
+
MEDIA_PIXEL_LIMIT: 'E1017',
|
|
823
|
+
UPLOAD_EXPIRED: 'E1018',
|
|
824
|
+
UPLOAD_NOT_FOUND: 'E1019',
|
|
825
|
+
CHECKSUM_MISMATCH: 'E1020',
|
|
826
|
+
|
|
827
|
+
// Streaming errors (E2xxx)
|
|
828
|
+
STREAM_INTERRUPTED: 'E2010',
|
|
829
|
+
STREAM_TIMEOUT: 'E2011',
|
|
830
|
+
|
|
831
|
+
// Capability errors (E4xxx)
|
|
832
|
+
STREAMING_NOT_SUPPORTED: 'E4010',
|
|
833
|
+
MULTIMODAL_NOT_SUPPORTED: 'E4011',
|
|
834
|
+
RECOVERY_NOT_SUPPORTED: 'E4012',
|
|
835
|
+
SESSION_EXPIRED: 'E4013',
|
|
836
|
+
CHECKPOINT_INVALID: 'E4014',
|
|
837
|
+
} as const;
|
|
838
|
+
|
|
839
|
+
export type ErrorCodeV25 = typeof ErrorCodesV25[keyof typeof ErrorCodesV25];
|
|
840
|
+
|
|
841
|
+
// =============================================================================
|
|
842
|
+
// v2.5 Runtime Capabilities
|
|
843
|
+
// =============================================================================
|
|
844
|
+
|
|
845
|
+
/** Runtime capability declaration */
|
|
846
|
+
export interface RuntimeCapabilities {
|
|
847
|
+
streaming: boolean;
|
|
848
|
+
multimodal: {
|
|
849
|
+
input: ModalityType[];
|
|
850
|
+
output: ModalityType[];
|
|
851
|
+
};
|
|
852
|
+
max_media_size_mb: number;
|
|
853
|
+
supported_transports: ('sse' | 'websocket' | 'ndjson')[];
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/** Default runtime capabilities */
|
|
857
|
+
export const DEFAULT_RUNTIME_CAPABILITIES: RuntimeCapabilities = {
|
|
858
|
+
streaming: true,
|
|
859
|
+
multimodal: {
|
|
860
|
+
input: ['text', 'image'],
|
|
861
|
+
output: ['text']
|
|
862
|
+
},
|
|
863
|
+
max_media_size_mb: 20,
|
|
864
|
+
supported_transports: ['sse', 'ndjson']
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// =============================================================================
|
|
868
|
+
// v2.5 Extended Provider Interface
|
|
869
|
+
// =============================================================================
|
|
870
|
+
|
|
871
|
+
/** Extended invoke params with streaming support */
|
|
872
|
+
export interface InvokeParamsV25 extends InvokeParams {
|
|
873
|
+
stream?: boolean;
|
|
874
|
+
images?: MediaInput[];
|
|
875
|
+
audio?: MediaInput[];
|
|
876
|
+
video?: MediaInput[];
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** Streaming invoke result */
|
|
880
|
+
export interface StreamingInvokeResult {
|
|
881
|
+
stream: AsyncIterable<string>;
|
|
882
|
+
usage?: {
|
|
883
|
+
promptTokens: number;
|
|
884
|
+
completionTokens: number;
|
|
885
|
+
totalTokens: number;
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/** Extended provider interface for v2.5 */
|
|
890
|
+
export interface ProviderV25 extends Provider {
|
|
891
|
+
/** Check if provider supports streaming */
|
|
892
|
+
supportsStreaming?(): boolean;
|
|
893
|
+
|
|
894
|
+
/** Check if provider supports multimodal input */
|
|
895
|
+
supportsMultimodal?(): { input: ModalityType[]; output: ModalityType[] };
|
|
896
|
+
|
|
897
|
+
/** Invoke with streaming */
|
|
898
|
+
invokeStream?(params: InvokeParamsV25): Promise<StreamingInvokeResult>;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/** Type guard for v2.5 provider */
|
|
902
|
+
export function isProviderV25(provider: Provider): provider is ProviderV25 {
|
|
903
|
+
return 'invokeStream' in provider || 'supportsStreaming' in provider;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// =============================================================================
|
|
907
|
+
// v2.5 Module Configuration Extensions
|
|
908
|
+
// =============================================================================
|
|
909
|
+
|
|
910
|
+
/** Extended module interface for v2.5 */
|
|
911
|
+
export interface CognitiveModuleV25 extends CognitiveModule {
|
|
912
|
+
/** v2.5: Response configuration */
|
|
913
|
+
response?: ResponseConfig;
|
|
914
|
+
|
|
915
|
+
/** v2.5: Modalities configuration */
|
|
916
|
+
modalities?: ModalitiesConfig;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/** Type guard for v2.5 module */
|
|
920
|
+
export function isModuleV25(module: CognitiveModule): module is CognitiveModuleV25 {
|
|
921
|
+
return 'response' in module || 'modalities' in module;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/** Check if module supports streaming */
|
|
925
|
+
export function moduleSupportsStreaming(module: CognitiveModule): boolean {
|
|
926
|
+
if (!isModuleV25(module)) return false;
|
|
927
|
+
const mode = module.response?.mode;
|
|
928
|
+
return mode === 'streaming' || mode === 'both';
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/** Check if module supports multimodal input */
|
|
932
|
+
export function moduleSupportsMultimodal(module: CognitiveModule): boolean {
|
|
933
|
+
if (!isModuleV25(module)) return false;
|
|
934
|
+
const modalities = module.modalities?.input ?? ['text'];
|
|
935
|
+
return modalities.some(m => m !== 'text');
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/** Get supported input modalities for module */
|
|
939
|
+
export function getModuleInputModalities(module: CognitiveModule): ModalityType[] {
|
|
940
|
+
if (!isModuleV25(module)) return ['text'];
|
|
941
|
+
return module.modalities?.input ?? ['text'];
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** Get supported output modalities for module */
|
|
945
|
+
export function getModuleOutputModalities(module: CognitiveModule): ModalityType[] {
|
|
946
|
+
if (!isModuleV25(module)) return ['text'];
|
|
947
|
+
return module.modalities?.output ?? ['text'];
|
|
948
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cog compose - Execute a Composed Cognitive Module Workflow
|
|
3
|
-
*
|
|
4
|
-
* Supports all composition patterns:
|
|
5
|
-
* - Sequential: A → B → C
|
|
6
|
-
* - Parallel: A → [B, C, D] → Aggregate
|
|
7
|
-
* - Conditional: A → (condition) → B or C
|
|
8
|
-
* - Iterative: A → (check) → A → ... → Done
|
|
9
|
-
*/
|
|
10
|
-
import type { CommandContext, CommandResult } from '../types.js';
|
|
11
|
-
export interface ComposeOptions {
|
|
12
|
-
/** Direct text input */
|
|
13
|
-
args?: string;
|
|
14
|
-
/** JSON input data */
|
|
15
|
-
input?: string;
|
|
16
|
-
/** Maximum composition depth */
|
|
17
|
-
maxDepth?: number;
|
|
18
|
-
/** Timeout in milliseconds */
|
|
19
|
-
timeout?: number;
|
|
20
|
-
/** Include execution trace */
|
|
21
|
-
trace?: boolean;
|
|
22
|
-
/** Pretty print output */
|
|
23
|
-
pretty?: boolean;
|
|
24
|
-
/** Verbose mode */
|
|
25
|
-
verbose?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare function compose(moduleName: string, ctx: CommandContext, options?: ComposeOptions): Promise<CommandResult>;
|
|
28
|
-
/**
|
|
29
|
-
* Show composition info for a module
|
|
30
|
-
*/
|
|
31
|
-
export declare function composeInfo(moduleName: string, ctx: CommandContext): Promise<CommandResult>;
|