@kalada/provider-routing 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,171 @@
1
+ /** Experimental host composition v1; offsets are UTF-16, half-open, in the original text. */
2
+ declare const COMPOSITION_CONTRACT_VERSION = 1;
3
+ interface CompositionSnapshot {
4
+ readonly uri: string;
5
+ readonly text: string;
6
+ readonly version: number;
7
+ readonly environmentGeneration: string;
8
+ }
9
+ interface CompositionRange {
10
+ readonly start: number;
11
+ readonly end: number;
12
+ }
13
+ interface CompositionDiagnostic {
14
+ readonly owner: string;
15
+ readonly code: string;
16
+ readonly range: CompositionRange;
17
+ }
18
+ interface CompositionProfile {
19
+ readonly version: 1;
20
+ readonly hostLanguageId: string;
21
+ readonly position: string;
22
+ readonly allowedGuests: readonly string[];
23
+ readonly defaultGuest?: string;
24
+ /** Host grammar owns the opening and closing text; guest owns only the interior. */
25
+ readonly open: string;
26
+ readonly close: string;
27
+ }
28
+ interface CompositionSlot {
29
+ readonly position: string;
30
+ readonly start: number;
31
+ /** Optional independent host-known upper bound for guest stop, including early failures; not inferred by scanning guest text. */
32
+ readonly maxStop?: number;
33
+ readonly explicitGuest?: string;
34
+ /** Host-owned opaque facts; neither router nor guest may derive write authority from them. */
35
+ readonly context?: Readonly<{
36
+ expectedType?: unknown;
37
+ location?: unknown;
38
+ }>;
39
+ }
40
+ interface CompositionMeter {
41
+ /** Shared cumulative work: host charges its own text/markers; guest charges its interior and nested work. */
42
+ readonly exhausted: boolean;
43
+ readonly work: number;
44
+ readonly depth: number;
45
+ readonly diagnostics: number;
46
+ charge(units: number): boolean;
47
+ report(count: number): boolean;
48
+ enter(): boolean;
49
+ leave(): void;
50
+ }
51
+ interface CompositionGuest {
52
+ readonly languageId: string;
53
+ parse(input: Readonly<{
54
+ snapshot: CompositionSnapshot;
55
+ start: number;
56
+ close: string;
57
+ context?: CompositionSlot["context"];
58
+ meter: CompositionMeter;
59
+ }>): GuestCompositionResult;
60
+ }
61
+ interface GuestCompositionResult {
62
+ readonly owner: string;
63
+ readonly status: "valid" | "invalid" | "partial" | "unsupported";
64
+ readonly range: CompositionRange;
65
+ /** Valid: first applicable host close. Nonvalid: bounded failure stop (possibly start or EOF). Always equals range.end. */
66
+ readonly stop: number;
67
+ /** Success requires "host-close"; nonvalid results retain a nonempty guest reason without granting continuation. */
68
+ readonly reason: string;
69
+ readonly diagnostics: readonly CompositionDiagnostic[];
70
+ readonly subtree?: unknown;
71
+ }
72
+ interface CompositionNode {
73
+ readonly owner: string;
74
+ readonly range: CompositionRange;
75
+ readonly children: readonly CompositionNode[];
76
+ /** Opaque language-owned parsed subtree. Never interpreted by the host router. */
77
+ readonly subtree?: unknown;
78
+ }
79
+ /** Attempt metadata is diagnostic only; it never authenticates a failed subtree. */
80
+ interface CompositionAttempt {
81
+ readonly owner: string;
82
+ readonly range: CompositionRange;
83
+ readonly reason: string;
84
+ readonly status: GuestCompositionResult["status"];
85
+ readonly diagnostics: readonly CompositionDiagnostic[];
86
+ }
87
+ interface HostConnector {
88
+ readonly owner: string;
89
+ /** Host-owned original-source range from just after the safe close to the next opening. */
90
+ readonly range: CompositionRange;
91
+ }
92
+ interface HostContinuation {
93
+ validate(input: Readonly<{
94
+ snapshot: CompositionSnapshot;
95
+ close: CompositionRange;
96
+ nextSlot: Readonly<CompositionSlot>;
97
+ meter: CompositionMeter;
98
+ }>): HostConnector;
99
+ }
100
+ interface CompositionOutcome {
101
+ readonly status: "valid" | "invalid" | "partial" | "unsupported" | "stale" | "cancelled" | "budget";
102
+ readonly reason: string;
103
+ readonly snapshot: CompositionSnapshot;
104
+ readonly diagnostics: readonly CompositionDiagnostic[];
105
+ readonly tree?: CompositionNode;
106
+ /** Only on partial recovery; never equivalent to the authoritative tree. */
107
+ readonly attempts?: readonly CompositionAttempt[];
108
+ readonly candidates?: readonly CompositionNode[];
109
+ }
110
+ interface CompositionRequest {
111
+ readonly snapshot: CompositionSnapshot;
112
+ /** Must consult the caller's live identity, including environment, on both sides of callbacks. */
113
+ readonly isCurrent: (snapshot: CompositionSnapshot) => boolean;
114
+ readonly isCancelled?: () => boolean;
115
+ readonly hostLanguageId: string;
116
+ readonly slots: readonly CompositionSlot[];
117
+ readonly limits: Readonly<{
118
+ work: number;
119
+ depth: number;
120
+ diagnostics: number;
121
+ }>;
122
+ /** For a nested request, pass the parent's meter rather than allocating a fresh budget. */
123
+ readonly meter?: CompositionMeter;
124
+ /** Trusted host grammar, not a guest scanner; absent means no recovery continuation. */
125
+ readonly hostContinuation?: HostContinuation;
126
+ }
127
+
128
+ /** Registered callbacks are trusted/cooperative; this meter cannot preempt CPU or memory use. */
129
+ declare function createCompositionRouter(profiles: readonly CompositionProfile[], providers: readonly CompositionGuest[]): Readonly<{
130
+ compose(request: CompositionRequest): CompositionOutcome;
131
+ }>;
132
+
133
+ /** Experimental diagnostic contract v1; not a parser, checker, or runtime API. */
134
+
135
+ declare const DIAGNOSTIC_CONTRACT_VERSION = 1;
136
+ interface DocumentSnapshot {
137
+ readonly uri: string;
138
+ readonly text: string;
139
+ readonly version: number;
140
+ readonly environmentGeneration: string;
141
+ }
142
+ interface Diagnostic {
143
+ readonly code: string;
144
+ readonly range: Readonly<{
145
+ readonly start: number;
146
+ readonly end: number;
147
+ }>;
148
+ }
149
+ type ProviderOutcome = {
150
+ readonly status: "supported";
151
+ readonly diagnostics: readonly Diagnostic[];
152
+ } | {
153
+ readonly status: "invalid";
154
+ readonly diagnostics: readonly Diagnostic[];
155
+ } | {
156
+ readonly status: "unsupported";
157
+ readonly diagnostics?: never;
158
+ };
159
+ interface DiagnosticProvider {
160
+ readonly languageId: string;
161
+ diagnose(document: DocumentSnapshot): ProviderOutcome;
162
+ }
163
+ type RoutedOutcome = ProviderOutcome & {
164
+ readonly languageId: string;
165
+ readonly document: DocumentSnapshot;
166
+ };
167
+ declare function createDiagnosticRouter(providers: readonly DiagnosticProvider[]): Readonly<{
168
+ diagnose(languageId: string, input: DocumentSnapshot): RoutedOutcome;
169
+ }>;
170
+
171
+ export { COMPOSITION_CONTRACT_VERSION, type CompositionAttempt, type CompositionDiagnostic, type CompositionGuest, type CompositionMeter, type CompositionNode, type CompositionOutcome, type CompositionProfile, type CompositionRange, type CompositionRequest, type CompositionSlot, type CompositionSnapshot, DIAGNOSTIC_CONTRACT_VERSION, type Diagnostic, type DiagnosticProvider, type DocumentSnapshot, type GuestCompositionResult, type HostConnector, type HostContinuation, type ProviderOutcome, type RoutedOutcome, createCompositionRouter, createDiagnosticRouter };
@@ -0,0 +1,171 @@
1
+ /** Experimental host composition v1; offsets are UTF-16, half-open, in the original text. */
2
+ declare const COMPOSITION_CONTRACT_VERSION = 1;
3
+ interface CompositionSnapshot {
4
+ readonly uri: string;
5
+ readonly text: string;
6
+ readonly version: number;
7
+ readonly environmentGeneration: string;
8
+ }
9
+ interface CompositionRange {
10
+ readonly start: number;
11
+ readonly end: number;
12
+ }
13
+ interface CompositionDiagnostic {
14
+ readonly owner: string;
15
+ readonly code: string;
16
+ readonly range: CompositionRange;
17
+ }
18
+ interface CompositionProfile {
19
+ readonly version: 1;
20
+ readonly hostLanguageId: string;
21
+ readonly position: string;
22
+ readonly allowedGuests: readonly string[];
23
+ readonly defaultGuest?: string;
24
+ /** Host grammar owns the opening and closing text; guest owns only the interior. */
25
+ readonly open: string;
26
+ readonly close: string;
27
+ }
28
+ interface CompositionSlot {
29
+ readonly position: string;
30
+ readonly start: number;
31
+ /** Optional independent host-known upper bound for guest stop, including early failures; not inferred by scanning guest text. */
32
+ readonly maxStop?: number;
33
+ readonly explicitGuest?: string;
34
+ /** Host-owned opaque facts; neither router nor guest may derive write authority from them. */
35
+ readonly context?: Readonly<{
36
+ expectedType?: unknown;
37
+ location?: unknown;
38
+ }>;
39
+ }
40
+ interface CompositionMeter {
41
+ /** Shared cumulative work: host charges its own text/markers; guest charges its interior and nested work. */
42
+ readonly exhausted: boolean;
43
+ readonly work: number;
44
+ readonly depth: number;
45
+ readonly diagnostics: number;
46
+ charge(units: number): boolean;
47
+ report(count: number): boolean;
48
+ enter(): boolean;
49
+ leave(): void;
50
+ }
51
+ interface CompositionGuest {
52
+ readonly languageId: string;
53
+ parse(input: Readonly<{
54
+ snapshot: CompositionSnapshot;
55
+ start: number;
56
+ close: string;
57
+ context?: CompositionSlot["context"];
58
+ meter: CompositionMeter;
59
+ }>): GuestCompositionResult;
60
+ }
61
+ interface GuestCompositionResult {
62
+ readonly owner: string;
63
+ readonly status: "valid" | "invalid" | "partial" | "unsupported";
64
+ readonly range: CompositionRange;
65
+ /** Valid: first applicable host close. Nonvalid: bounded failure stop (possibly start or EOF). Always equals range.end. */
66
+ readonly stop: number;
67
+ /** Success requires "host-close"; nonvalid results retain a nonempty guest reason without granting continuation. */
68
+ readonly reason: string;
69
+ readonly diagnostics: readonly CompositionDiagnostic[];
70
+ readonly subtree?: unknown;
71
+ }
72
+ interface CompositionNode {
73
+ readonly owner: string;
74
+ readonly range: CompositionRange;
75
+ readonly children: readonly CompositionNode[];
76
+ /** Opaque language-owned parsed subtree. Never interpreted by the host router. */
77
+ readonly subtree?: unknown;
78
+ }
79
+ /** Attempt metadata is diagnostic only; it never authenticates a failed subtree. */
80
+ interface CompositionAttempt {
81
+ readonly owner: string;
82
+ readonly range: CompositionRange;
83
+ readonly reason: string;
84
+ readonly status: GuestCompositionResult["status"];
85
+ readonly diagnostics: readonly CompositionDiagnostic[];
86
+ }
87
+ interface HostConnector {
88
+ readonly owner: string;
89
+ /** Host-owned original-source range from just after the safe close to the next opening. */
90
+ readonly range: CompositionRange;
91
+ }
92
+ interface HostContinuation {
93
+ validate(input: Readonly<{
94
+ snapshot: CompositionSnapshot;
95
+ close: CompositionRange;
96
+ nextSlot: Readonly<CompositionSlot>;
97
+ meter: CompositionMeter;
98
+ }>): HostConnector;
99
+ }
100
+ interface CompositionOutcome {
101
+ readonly status: "valid" | "invalid" | "partial" | "unsupported" | "stale" | "cancelled" | "budget";
102
+ readonly reason: string;
103
+ readonly snapshot: CompositionSnapshot;
104
+ readonly diagnostics: readonly CompositionDiagnostic[];
105
+ readonly tree?: CompositionNode;
106
+ /** Only on partial recovery; never equivalent to the authoritative tree. */
107
+ readonly attempts?: readonly CompositionAttempt[];
108
+ readonly candidates?: readonly CompositionNode[];
109
+ }
110
+ interface CompositionRequest {
111
+ readonly snapshot: CompositionSnapshot;
112
+ /** Must consult the caller's live identity, including environment, on both sides of callbacks. */
113
+ readonly isCurrent: (snapshot: CompositionSnapshot) => boolean;
114
+ readonly isCancelled?: () => boolean;
115
+ readonly hostLanguageId: string;
116
+ readonly slots: readonly CompositionSlot[];
117
+ readonly limits: Readonly<{
118
+ work: number;
119
+ depth: number;
120
+ diagnostics: number;
121
+ }>;
122
+ /** For a nested request, pass the parent's meter rather than allocating a fresh budget. */
123
+ readonly meter?: CompositionMeter;
124
+ /** Trusted host grammar, not a guest scanner; absent means no recovery continuation. */
125
+ readonly hostContinuation?: HostContinuation;
126
+ }
127
+
128
+ /** Registered callbacks are trusted/cooperative; this meter cannot preempt CPU or memory use. */
129
+ declare function createCompositionRouter(profiles: readonly CompositionProfile[], providers: readonly CompositionGuest[]): Readonly<{
130
+ compose(request: CompositionRequest): CompositionOutcome;
131
+ }>;
132
+
133
+ /** Experimental diagnostic contract v1; not a parser, checker, or runtime API. */
134
+
135
+ declare const DIAGNOSTIC_CONTRACT_VERSION = 1;
136
+ interface DocumentSnapshot {
137
+ readonly uri: string;
138
+ readonly text: string;
139
+ readonly version: number;
140
+ readonly environmentGeneration: string;
141
+ }
142
+ interface Diagnostic {
143
+ readonly code: string;
144
+ readonly range: Readonly<{
145
+ readonly start: number;
146
+ readonly end: number;
147
+ }>;
148
+ }
149
+ type ProviderOutcome = {
150
+ readonly status: "supported";
151
+ readonly diagnostics: readonly Diagnostic[];
152
+ } | {
153
+ readonly status: "invalid";
154
+ readonly diagnostics: readonly Diagnostic[];
155
+ } | {
156
+ readonly status: "unsupported";
157
+ readonly diagnostics?: never;
158
+ };
159
+ interface DiagnosticProvider {
160
+ readonly languageId: string;
161
+ diagnose(document: DocumentSnapshot): ProviderOutcome;
162
+ }
163
+ type RoutedOutcome = ProviderOutcome & {
164
+ readonly languageId: string;
165
+ readonly document: DocumentSnapshot;
166
+ };
167
+ declare function createDiagnosticRouter(providers: readonly DiagnosticProvider[]): Readonly<{
168
+ diagnose(languageId: string, input: DocumentSnapshot): RoutedOutcome;
169
+ }>;
170
+
171
+ export { COMPOSITION_CONTRACT_VERSION, type CompositionAttempt, type CompositionDiagnostic, type CompositionGuest, type CompositionMeter, type CompositionNode, type CompositionOutcome, type CompositionProfile, type CompositionRange, type CompositionRequest, type CompositionSlot, type CompositionSnapshot, DIAGNOSTIC_CONTRACT_VERSION, type Diagnostic, type DiagnosticProvider, type DocumentSnapshot, type GuestCompositionResult, type HostConnector, type HostContinuation, type ProviderOutcome, type RoutedOutcome, createCompositionRouter, createDiagnosticRouter };