@itphx/synth-shared 0.8.8 → 0.10.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.
- package/LICENSE +1 -1
- package/LICENSE.ru.md +31 -0
- package/dist/config/defaults.js +51 -1
- package/dist/config/env-overrides.d.ts +68 -0
- package/dist/config/env-overrides.js +165 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/config/loader.d.ts +2 -0
- package/dist/config/loader.js +10 -2
- package/dist/config/resolve.d.ts +17 -0
- package/dist/config/resolve.js +21 -0
- package/dist/config/types.d.ts +589 -36
- package/dist/config/types.js +169 -2
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +36 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -2
- package/dist/interfaces/index.d.ts +8 -1
- package/dist/schemas/index.d.ts +1695 -17
- package/dist/schemas/index.js +380 -29
- package/dist/types/decision.d.ts +502 -0
- package/dist/types/decision.js +98 -0
- package/dist/types/events.d.ts +219 -0
- package/dist/types/events.js +1 -0
- package/dist/types/hooks.d.ts +96 -0
- package/dist/types/hooks.js +1 -0
- package/dist/types/index.d.ts +81 -4
- package/dist/types/index.js +43 -9
- package/dist/types/schedules.d.ts +109 -0
- package/dist/types/schedules.js +9 -0
- package/dist/types/service-keys.d.ts +106 -0
- package/dist/types/service-keys.js +72 -0
- package/dist/types/tools.d.ts +1 -0
- package/dist/types/tools.js +2 -0
- package/dist/types/webhooks.d.ts +97 -0
- package/dist/types/webhooks.js +53 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AD-084: decision-модели (System One: Clef/Jev/Decision-1/…) как единый
|
|
3
|
+
* примитив — `state` (текст/JSON) + типизированные вопросы → вероятности за
|
|
4
|
+
* один forward-pass. Здесь только контракты без бизнес-логики: сами адаптеры и
|
|
5
|
+
* вызовы живут в core (`providers/decision.ts`, `GatewayProvider.decide`).
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/**
|
|
9
|
+
* Тип вопроса:
|
|
10
|
+
* - `noul` — бинарный вопрос (да/нет → вероятность);
|
|
11
|
+
* - `choice` — выбор одного из вариантов (`probabilities` + `confidence`);
|
|
12
|
+
* - `score` — позиция на шкале (`probabilities` + `confidence` + `legend`).
|
|
13
|
+
*/
|
|
14
|
+
export type DecisionQuestionType = 'noul' | 'choice' | 'score';
|
|
15
|
+
/** Границы числа вариантов для `choice`/`score` (System One-контракт). */
|
|
16
|
+
export declare const DECISION_CRITERIA_MIN = 2;
|
|
17
|
+
export declare const DECISION_CRITERIA_MAX = 26;
|
|
18
|
+
/**
|
|
19
|
+
* AD-084: бинарный вопрос. `criteria` — подписи веток `true`/`false` (опц.),
|
|
20
|
+
* `instructions` — пояснение для модели (опц.).
|
|
21
|
+
*/
|
|
22
|
+
export interface DecisionNoulQuestion {
|
|
23
|
+
type: 'noul';
|
|
24
|
+
instructions?: string;
|
|
25
|
+
criteria?: {
|
|
26
|
+
true?: string;
|
|
27
|
+
false?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** AD-084: вопрос-выбор. `criteria` — карта «вариант → пояснение|null» (2..26). */
|
|
31
|
+
export interface DecisionChoiceQuestion {
|
|
32
|
+
type: 'choice';
|
|
33
|
+
instructions: string;
|
|
34
|
+
criteria: Record<string, string | null>;
|
|
35
|
+
}
|
|
36
|
+
/** AD-084: вопрос-шкала. `criteria` — упорядоченный список позиций (2..26). */
|
|
37
|
+
export interface DecisionScoreQuestion {
|
|
38
|
+
type: 'score';
|
|
39
|
+
instructions: string;
|
|
40
|
+
criteria: string[];
|
|
41
|
+
}
|
|
42
|
+
/** AD-084: типизированный вопрос decision-модели. */
|
|
43
|
+
export type DecisionQuestion = DecisionNoulQuestion | DecisionChoiceQuestion | DecisionScoreQuestion;
|
|
44
|
+
/** AD-084: ответ на `noul` — вероятность «да» (`0..1`). */
|
|
45
|
+
export interface DecisionNoulAnswer {
|
|
46
|
+
type: 'noul';
|
|
47
|
+
noul: number;
|
|
48
|
+
}
|
|
49
|
+
/** AD-084: ответ на `choice` — выбранный вариант + вероятности по всем. */
|
|
50
|
+
export interface DecisionChoiceAnswer {
|
|
51
|
+
type: 'choice';
|
|
52
|
+
choice: string;
|
|
53
|
+
confidence: number;
|
|
54
|
+
probabilities: Record<string, number>;
|
|
55
|
+
}
|
|
56
|
+
/** AD-084: ответ на `score` — позиция на шкале + вероятности по всем. */
|
|
57
|
+
export interface DecisionScoreAnswer {
|
|
58
|
+
type: 'score';
|
|
59
|
+
score: number;
|
|
60
|
+
confidence: number;
|
|
61
|
+
probabilities: Record<string, number>;
|
|
62
|
+
/** Подписи позиций шкалы (если модель/провайдер их отдаёт). */
|
|
63
|
+
legend?: Record<string, string>;
|
|
64
|
+
}
|
|
65
|
+
/** AD-084: типизированный ответ decision-модели. */
|
|
66
|
+
export type DecisionAnswer = DecisionNoulAnswer | DecisionChoiceAnswer | DecisionScoreAnswer;
|
|
67
|
+
/**
|
|
68
|
+
* AD-084: медиа-вложения decision-запроса (AD-085 задел). Источник изображений/
|
|
69
|
+
* видео — мультимодальный ввод (пока не реализован), здесь только контракт-
|
|
70
|
+
* plumbing: значения прокидываются в тело decision-запроса, если непусты.
|
|
71
|
+
*/
|
|
72
|
+
export interface DecisionMediaInput {
|
|
73
|
+
images?: string[];
|
|
74
|
+
videos?: string[];
|
|
75
|
+
}
|
|
76
|
+
/** AD-084: запрос `state + questions → answers`. */
|
|
77
|
+
export interface DecisionRequest extends DecisionMediaInput {
|
|
78
|
+
model: string;
|
|
79
|
+
/** Текст или JSON-совместимая структура (System One понимает оба). */
|
|
80
|
+
state: unknown;
|
|
81
|
+
questions: Record<string, DecisionQuestion>;
|
|
82
|
+
}
|
|
83
|
+
/** AD-084: расход токенов decision-запроса (snake_case — как у провайдеров). */
|
|
84
|
+
export interface DecisionUsage {
|
|
85
|
+
input_tokens: number;
|
|
86
|
+
output_tokens: number;
|
|
87
|
+
}
|
|
88
|
+
/** AD-084: ответ decision-модели. */
|
|
89
|
+
export interface DecisionResponse {
|
|
90
|
+
id?: string;
|
|
91
|
+
model?: string;
|
|
92
|
+
answers: Record<string, DecisionAnswer>;
|
|
93
|
+
usage?: DecisionUsage;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* AD-084: универсальная схема вопроса. Границы `choice`/`score` (2..26)
|
|
97
|
+
* проверяются отдельно — иначе `discriminatedUnion` не принимает
|
|
98
|
+
* `ZodEffects`-обёртки внутри вариантов.
|
|
99
|
+
*/
|
|
100
|
+
export declare const decisionQuestionSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
101
|
+
type: z.ZodLiteral<"noul">;
|
|
102
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
103
|
+
criteria: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
true: z.ZodOptional<z.ZodString>;
|
|
105
|
+
false: z.ZodOptional<z.ZodString>;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
true?: string | undefined;
|
|
108
|
+
false?: string | undefined;
|
|
109
|
+
}, {
|
|
110
|
+
true?: string | undefined;
|
|
111
|
+
false?: string | undefined;
|
|
112
|
+
}>>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
type: "noul";
|
|
115
|
+
instructions?: string | undefined;
|
|
116
|
+
criteria?: {
|
|
117
|
+
true?: string | undefined;
|
|
118
|
+
false?: string | undefined;
|
|
119
|
+
} | undefined;
|
|
120
|
+
}, {
|
|
121
|
+
type: "noul";
|
|
122
|
+
instructions?: string | undefined;
|
|
123
|
+
criteria?: {
|
|
124
|
+
true?: string | undefined;
|
|
125
|
+
false?: string | undefined;
|
|
126
|
+
} | undefined;
|
|
127
|
+
}>, z.ZodObject<{
|
|
128
|
+
type: z.ZodLiteral<"choice">;
|
|
129
|
+
instructions: z.ZodString;
|
|
130
|
+
criteria: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
|
|
131
|
+
}, "strip", z.ZodTypeAny, {
|
|
132
|
+
type: "choice";
|
|
133
|
+
instructions: string;
|
|
134
|
+
criteria: Record<string, string | null>;
|
|
135
|
+
}, {
|
|
136
|
+
type: "choice";
|
|
137
|
+
instructions: string;
|
|
138
|
+
criteria: Record<string, string | null>;
|
|
139
|
+
}>, z.ZodObject<{
|
|
140
|
+
type: z.ZodLiteral<"score">;
|
|
141
|
+
instructions: z.ZodString;
|
|
142
|
+
criteria: z.ZodArray<z.ZodString, "many">;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
type: "score";
|
|
145
|
+
instructions: string;
|
|
146
|
+
criteria: string[];
|
|
147
|
+
}, {
|
|
148
|
+
type: "score";
|
|
149
|
+
instructions: string;
|
|
150
|
+
criteria: string[];
|
|
151
|
+
}>]>, {
|
|
152
|
+
type: "noul";
|
|
153
|
+
instructions?: string | undefined;
|
|
154
|
+
criteria?: {
|
|
155
|
+
true?: string | undefined;
|
|
156
|
+
false?: string | undefined;
|
|
157
|
+
} | undefined;
|
|
158
|
+
} | {
|
|
159
|
+
type: "choice";
|
|
160
|
+
instructions: string;
|
|
161
|
+
criteria: Record<string, string | null>;
|
|
162
|
+
} | {
|
|
163
|
+
type: "score";
|
|
164
|
+
instructions: string;
|
|
165
|
+
criteria: string[];
|
|
166
|
+
}, {
|
|
167
|
+
type: "noul";
|
|
168
|
+
instructions?: string | undefined;
|
|
169
|
+
criteria?: {
|
|
170
|
+
true?: string | undefined;
|
|
171
|
+
false?: string | undefined;
|
|
172
|
+
} | undefined;
|
|
173
|
+
} | {
|
|
174
|
+
type: "choice";
|
|
175
|
+
instructions: string;
|
|
176
|
+
criteria: Record<string, string | null>;
|
|
177
|
+
} | {
|
|
178
|
+
type: "score";
|
|
179
|
+
instructions: string;
|
|
180
|
+
criteria: string[];
|
|
181
|
+
}>;
|
|
182
|
+
export declare const decisionNoulAnswerSchema: z.ZodObject<{
|
|
183
|
+
type: z.ZodLiteral<"noul">;
|
|
184
|
+
noul: z.ZodNumber;
|
|
185
|
+
}, "strip", z.ZodTypeAny, {
|
|
186
|
+
type: "noul";
|
|
187
|
+
noul: number;
|
|
188
|
+
}, {
|
|
189
|
+
type: "noul";
|
|
190
|
+
noul: number;
|
|
191
|
+
}>;
|
|
192
|
+
export declare const decisionChoiceAnswerSchema: z.ZodObject<{
|
|
193
|
+
type: z.ZodLiteral<"choice">;
|
|
194
|
+
choice: z.ZodString;
|
|
195
|
+
confidence: z.ZodNumber;
|
|
196
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
197
|
+
}, "strip", z.ZodTypeAny, {
|
|
198
|
+
type: "choice";
|
|
199
|
+
choice: string;
|
|
200
|
+
confidence: number;
|
|
201
|
+
probabilities: Record<string, number>;
|
|
202
|
+
}, {
|
|
203
|
+
type: "choice";
|
|
204
|
+
choice: string;
|
|
205
|
+
confidence: number;
|
|
206
|
+
probabilities: Record<string, number>;
|
|
207
|
+
}>;
|
|
208
|
+
export declare const decisionScoreAnswerSchema: z.ZodObject<{
|
|
209
|
+
type: z.ZodLiteral<"score">;
|
|
210
|
+
score: z.ZodNumber;
|
|
211
|
+
confidence: z.ZodNumber;
|
|
212
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
213
|
+
legend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
214
|
+
}, "strip", z.ZodTypeAny, {
|
|
215
|
+
type: "score";
|
|
216
|
+
score: number;
|
|
217
|
+
confidence: number;
|
|
218
|
+
probabilities: Record<string, number>;
|
|
219
|
+
legend?: Record<string, string> | undefined;
|
|
220
|
+
}, {
|
|
221
|
+
type: "score";
|
|
222
|
+
score: number;
|
|
223
|
+
confidence: number;
|
|
224
|
+
probabilities: Record<string, number>;
|
|
225
|
+
legend?: Record<string, string> | undefined;
|
|
226
|
+
}>;
|
|
227
|
+
/** AD-084: схема ответа decision-модели. */
|
|
228
|
+
export declare const decisionAnswerSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
229
|
+
type: z.ZodLiteral<"noul">;
|
|
230
|
+
noul: z.ZodNumber;
|
|
231
|
+
}, "strip", z.ZodTypeAny, {
|
|
232
|
+
type: "noul";
|
|
233
|
+
noul: number;
|
|
234
|
+
}, {
|
|
235
|
+
type: "noul";
|
|
236
|
+
noul: number;
|
|
237
|
+
}>, z.ZodObject<{
|
|
238
|
+
type: z.ZodLiteral<"choice">;
|
|
239
|
+
choice: z.ZodString;
|
|
240
|
+
confidence: z.ZodNumber;
|
|
241
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
242
|
+
}, "strip", z.ZodTypeAny, {
|
|
243
|
+
type: "choice";
|
|
244
|
+
choice: string;
|
|
245
|
+
confidence: number;
|
|
246
|
+
probabilities: Record<string, number>;
|
|
247
|
+
}, {
|
|
248
|
+
type: "choice";
|
|
249
|
+
choice: string;
|
|
250
|
+
confidence: number;
|
|
251
|
+
probabilities: Record<string, number>;
|
|
252
|
+
}>, z.ZodObject<{
|
|
253
|
+
type: z.ZodLiteral<"score">;
|
|
254
|
+
score: z.ZodNumber;
|
|
255
|
+
confidence: z.ZodNumber;
|
|
256
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
257
|
+
legend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
258
|
+
}, "strip", z.ZodTypeAny, {
|
|
259
|
+
type: "score";
|
|
260
|
+
score: number;
|
|
261
|
+
confidence: number;
|
|
262
|
+
probabilities: Record<string, number>;
|
|
263
|
+
legend?: Record<string, string> | undefined;
|
|
264
|
+
}, {
|
|
265
|
+
type: "score";
|
|
266
|
+
score: number;
|
|
267
|
+
confidence: number;
|
|
268
|
+
probabilities: Record<string, number>;
|
|
269
|
+
legend?: Record<string, string> | undefined;
|
|
270
|
+
}>]>;
|
|
271
|
+
export declare const decisionRequestSchema: z.ZodObject<{
|
|
272
|
+
model: z.ZodString;
|
|
273
|
+
state: z.ZodUnknown;
|
|
274
|
+
questions: z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
275
|
+
type: z.ZodLiteral<"noul">;
|
|
276
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
277
|
+
criteria: z.ZodOptional<z.ZodObject<{
|
|
278
|
+
true: z.ZodOptional<z.ZodString>;
|
|
279
|
+
false: z.ZodOptional<z.ZodString>;
|
|
280
|
+
}, "strip", z.ZodTypeAny, {
|
|
281
|
+
true?: string | undefined;
|
|
282
|
+
false?: string | undefined;
|
|
283
|
+
}, {
|
|
284
|
+
true?: string | undefined;
|
|
285
|
+
false?: string | undefined;
|
|
286
|
+
}>>;
|
|
287
|
+
}, "strip", z.ZodTypeAny, {
|
|
288
|
+
type: "noul";
|
|
289
|
+
instructions?: string | undefined;
|
|
290
|
+
criteria?: {
|
|
291
|
+
true?: string | undefined;
|
|
292
|
+
false?: string | undefined;
|
|
293
|
+
} | undefined;
|
|
294
|
+
}, {
|
|
295
|
+
type: "noul";
|
|
296
|
+
instructions?: string | undefined;
|
|
297
|
+
criteria?: {
|
|
298
|
+
true?: string | undefined;
|
|
299
|
+
false?: string | undefined;
|
|
300
|
+
} | undefined;
|
|
301
|
+
}>, z.ZodObject<{
|
|
302
|
+
type: z.ZodLiteral<"choice">;
|
|
303
|
+
instructions: z.ZodString;
|
|
304
|
+
criteria: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
|
|
305
|
+
}, "strip", z.ZodTypeAny, {
|
|
306
|
+
type: "choice";
|
|
307
|
+
instructions: string;
|
|
308
|
+
criteria: Record<string, string | null>;
|
|
309
|
+
}, {
|
|
310
|
+
type: "choice";
|
|
311
|
+
instructions: string;
|
|
312
|
+
criteria: Record<string, string | null>;
|
|
313
|
+
}>, z.ZodObject<{
|
|
314
|
+
type: z.ZodLiteral<"score">;
|
|
315
|
+
instructions: z.ZodString;
|
|
316
|
+
criteria: z.ZodArray<z.ZodString, "many">;
|
|
317
|
+
}, "strip", z.ZodTypeAny, {
|
|
318
|
+
type: "score";
|
|
319
|
+
instructions: string;
|
|
320
|
+
criteria: string[];
|
|
321
|
+
}, {
|
|
322
|
+
type: "score";
|
|
323
|
+
instructions: string;
|
|
324
|
+
criteria: string[];
|
|
325
|
+
}>]>, {
|
|
326
|
+
type: "noul";
|
|
327
|
+
instructions?: string | undefined;
|
|
328
|
+
criteria?: {
|
|
329
|
+
true?: string | undefined;
|
|
330
|
+
false?: string | undefined;
|
|
331
|
+
} | undefined;
|
|
332
|
+
} | {
|
|
333
|
+
type: "choice";
|
|
334
|
+
instructions: string;
|
|
335
|
+
criteria: Record<string, string | null>;
|
|
336
|
+
} | {
|
|
337
|
+
type: "score";
|
|
338
|
+
instructions: string;
|
|
339
|
+
criteria: string[];
|
|
340
|
+
}, {
|
|
341
|
+
type: "noul";
|
|
342
|
+
instructions?: string | undefined;
|
|
343
|
+
criteria?: {
|
|
344
|
+
true?: string | undefined;
|
|
345
|
+
false?: string | undefined;
|
|
346
|
+
} | undefined;
|
|
347
|
+
} | {
|
|
348
|
+
type: "choice";
|
|
349
|
+
instructions: string;
|
|
350
|
+
criteria: Record<string, string | null>;
|
|
351
|
+
} | {
|
|
352
|
+
type: "score";
|
|
353
|
+
instructions: string;
|
|
354
|
+
criteria: string[];
|
|
355
|
+
}>>;
|
|
356
|
+
/** AD-084/AD-085: медиа-вложения (изображения/видео) — опциональны. */
|
|
357
|
+
images: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
358
|
+
videos: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
359
|
+
}, "strip", z.ZodTypeAny, {
|
|
360
|
+
model: string;
|
|
361
|
+
questions: Record<string, {
|
|
362
|
+
type: "noul";
|
|
363
|
+
instructions?: string | undefined;
|
|
364
|
+
criteria?: {
|
|
365
|
+
true?: string | undefined;
|
|
366
|
+
false?: string | undefined;
|
|
367
|
+
} | undefined;
|
|
368
|
+
} | {
|
|
369
|
+
type: "choice";
|
|
370
|
+
instructions: string;
|
|
371
|
+
criteria: Record<string, string | null>;
|
|
372
|
+
} | {
|
|
373
|
+
type: "score";
|
|
374
|
+
instructions: string;
|
|
375
|
+
criteria: string[];
|
|
376
|
+
}>;
|
|
377
|
+
state?: unknown;
|
|
378
|
+
images?: string[] | undefined;
|
|
379
|
+
videos?: string[] | undefined;
|
|
380
|
+
}, {
|
|
381
|
+
model: string;
|
|
382
|
+
questions: Record<string, {
|
|
383
|
+
type: "noul";
|
|
384
|
+
instructions?: string | undefined;
|
|
385
|
+
criteria?: {
|
|
386
|
+
true?: string | undefined;
|
|
387
|
+
false?: string | undefined;
|
|
388
|
+
} | undefined;
|
|
389
|
+
} | {
|
|
390
|
+
type: "choice";
|
|
391
|
+
instructions: string;
|
|
392
|
+
criteria: Record<string, string | null>;
|
|
393
|
+
} | {
|
|
394
|
+
type: "score";
|
|
395
|
+
instructions: string;
|
|
396
|
+
criteria: string[];
|
|
397
|
+
}>;
|
|
398
|
+
state?: unknown;
|
|
399
|
+
images?: string[] | undefined;
|
|
400
|
+
videos?: string[] | undefined;
|
|
401
|
+
}>;
|
|
402
|
+
export declare const decisionResponseSchema: z.ZodObject<{
|
|
403
|
+
id: z.ZodOptional<z.ZodString>;
|
|
404
|
+
model: z.ZodOptional<z.ZodString>;
|
|
405
|
+
answers: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
406
|
+
type: z.ZodLiteral<"noul">;
|
|
407
|
+
noul: z.ZodNumber;
|
|
408
|
+
}, "strip", z.ZodTypeAny, {
|
|
409
|
+
type: "noul";
|
|
410
|
+
noul: number;
|
|
411
|
+
}, {
|
|
412
|
+
type: "noul";
|
|
413
|
+
noul: number;
|
|
414
|
+
}>, z.ZodObject<{
|
|
415
|
+
type: z.ZodLiteral<"choice">;
|
|
416
|
+
choice: z.ZodString;
|
|
417
|
+
confidence: z.ZodNumber;
|
|
418
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
419
|
+
}, "strip", z.ZodTypeAny, {
|
|
420
|
+
type: "choice";
|
|
421
|
+
choice: string;
|
|
422
|
+
confidence: number;
|
|
423
|
+
probabilities: Record<string, number>;
|
|
424
|
+
}, {
|
|
425
|
+
type: "choice";
|
|
426
|
+
choice: string;
|
|
427
|
+
confidence: number;
|
|
428
|
+
probabilities: Record<string, number>;
|
|
429
|
+
}>, z.ZodObject<{
|
|
430
|
+
type: z.ZodLiteral<"score">;
|
|
431
|
+
score: z.ZodNumber;
|
|
432
|
+
confidence: z.ZodNumber;
|
|
433
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
434
|
+
legend: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
435
|
+
}, "strip", z.ZodTypeAny, {
|
|
436
|
+
type: "score";
|
|
437
|
+
score: number;
|
|
438
|
+
confidence: number;
|
|
439
|
+
probabilities: Record<string, number>;
|
|
440
|
+
legend?: Record<string, string> | undefined;
|
|
441
|
+
}, {
|
|
442
|
+
type: "score";
|
|
443
|
+
score: number;
|
|
444
|
+
confidence: number;
|
|
445
|
+
probabilities: Record<string, number>;
|
|
446
|
+
legend?: Record<string, string> | undefined;
|
|
447
|
+
}>]>>;
|
|
448
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
449
|
+
input_tokens: z.ZodNumber;
|
|
450
|
+
output_tokens: z.ZodNumber;
|
|
451
|
+
}, "strip", z.ZodTypeAny, {
|
|
452
|
+
input_tokens: number;
|
|
453
|
+
output_tokens: number;
|
|
454
|
+
}, {
|
|
455
|
+
input_tokens: number;
|
|
456
|
+
output_tokens: number;
|
|
457
|
+
}>>;
|
|
458
|
+
}, "strip", z.ZodTypeAny, {
|
|
459
|
+
answers: Record<string, {
|
|
460
|
+
type: "noul";
|
|
461
|
+
noul: number;
|
|
462
|
+
} | {
|
|
463
|
+
type: "choice";
|
|
464
|
+
choice: string;
|
|
465
|
+
confidence: number;
|
|
466
|
+
probabilities: Record<string, number>;
|
|
467
|
+
} | {
|
|
468
|
+
type: "score";
|
|
469
|
+
score: number;
|
|
470
|
+
confidence: number;
|
|
471
|
+
probabilities: Record<string, number>;
|
|
472
|
+
legend?: Record<string, string> | undefined;
|
|
473
|
+
}>;
|
|
474
|
+
model?: string | undefined;
|
|
475
|
+
id?: string | undefined;
|
|
476
|
+
usage?: {
|
|
477
|
+
input_tokens: number;
|
|
478
|
+
output_tokens: number;
|
|
479
|
+
} | undefined;
|
|
480
|
+
}, {
|
|
481
|
+
answers: Record<string, {
|
|
482
|
+
type: "noul";
|
|
483
|
+
noul: number;
|
|
484
|
+
} | {
|
|
485
|
+
type: "choice";
|
|
486
|
+
choice: string;
|
|
487
|
+
confidence: number;
|
|
488
|
+
probabilities: Record<string, number>;
|
|
489
|
+
} | {
|
|
490
|
+
type: "score";
|
|
491
|
+
score: number;
|
|
492
|
+
confidence: number;
|
|
493
|
+
probabilities: Record<string, number>;
|
|
494
|
+
legend?: Record<string, string> | undefined;
|
|
495
|
+
}>;
|
|
496
|
+
model?: string | undefined;
|
|
497
|
+
id?: string | undefined;
|
|
498
|
+
usage?: {
|
|
499
|
+
input_tokens: number;
|
|
500
|
+
output_tokens: number;
|
|
501
|
+
} | undefined;
|
|
502
|
+
}>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AD-084: decision-модели (System One: Clef/Jev/Decision-1/…) как единый
|
|
3
|
+
* примитив — `state` (текст/JSON) + типизированные вопросы → вероятности за
|
|
4
|
+
* один forward-pass. Здесь только контракты без бизнес-логики: сами адаптеры и
|
|
5
|
+
* вызовы живут в core (`providers/decision.ts`, `GatewayProvider.decide`).
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/** Границы числа вариантов для `choice`/`score` (System One-контракт). */
|
|
9
|
+
export const DECISION_CRITERIA_MIN = 2;
|
|
10
|
+
export const DECISION_CRITERIA_MAX = 26;
|
|
11
|
+
// --- Zod-схемы (валидация запроса/ответа) ---
|
|
12
|
+
const decisionNoulQuestionSchema = z.object({
|
|
13
|
+
type: z.literal('noul'),
|
|
14
|
+
instructions: z.string().optional(),
|
|
15
|
+
criteria: z
|
|
16
|
+
.object({ true: z.string().optional(), false: z.string().optional() })
|
|
17
|
+
.optional(),
|
|
18
|
+
});
|
|
19
|
+
const decisionChoiceQuestionSchema = z.object({
|
|
20
|
+
type: z.literal('choice'),
|
|
21
|
+
instructions: z.string(),
|
|
22
|
+
criteria: z.record(z.string(), z.string().nullable()),
|
|
23
|
+
});
|
|
24
|
+
const decisionScoreQuestionSchema = z.object({
|
|
25
|
+
type: z.literal('score'),
|
|
26
|
+
instructions: z.string(),
|
|
27
|
+
criteria: z.array(z.string()),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* AD-084: универсальная схема вопроса. Границы `choice`/`score` (2..26)
|
|
31
|
+
* проверяются отдельно — иначе `discriminatedUnion` не принимает
|
|
32
|
+
* `ZodEffects`-обёртки внутри вариантов.
|
|
33
|
+
*/
|
|
34
|
+
export const decisionQuestionSchema = z
|
|
35
|
+
.discriminatedUnion('type', [
|
|
36
|
+
decisionNoulQuestionSchema,
|
|
37
|
+
decisionChoiceQuestionSchema,
|
|
38
|
+
decisionScoreQuestionSchema,
|
|
39
|
+
])
|
|
40
|
+
.superRefine((question, ctx) => {
|
|
41
|
+
if (question.type === 'choice') {
|
|
42
|
+
const count = Object.keys(question.criteria).length;
|
|
43
|
+
if (count < DECISION_CRITERIA_MIN || count > DECISION_CRITERIA_MAX) {
|
|
44
|
+
ctx.addIssue({
|
|
45
|
+
code: z.ZodIssueCode.custom,
|
|
46
|
+
message: `choice.criteria: от ${DECISION_CRITERIA_MIN} до ${DECISION_CRITERIA_MAX} вариантов`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (question.type === 'score') {
|
|
51
|
+
const count = question.criteria.length;
|
|
52
|
+
if (count < DECISION_CRITERIA_MIN || count > DECISION_CRITERIA_MAX) {
|
|
53
|
+
ctx.addIssue({
|
|
54
|
+
code: z.ZodIssueCode.custom,
|
|
55
|
+
message: `score.criteria: от ${DECISION_CRITERIA_MIN} до ${DECISION_CRITERIA_MAX} позиций`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
export const decisionNoulAnswerSchema = z.object({
|
|
61
|
+
type: z.literal('noul'),
|
|
62
|
+
noul: z.number(),
|
|
63
|
+
});
|
|
64
|
+
export const decisionChoiceAnswerSchema = z.object({
|
|
65
|
+
type: z.literal('choice'),
|
|
66
|
+
choice: z.string(),
|
|
67
|
+
confidence: z.number(),
|
|
68
|
+
probabilities: z.record(z.string(), z.number()),
|
|
69
|
+
});
|
|
70
|
+
export const decisionScoreAnswerSchema = z.object({
|
|
71
|
+
type: z.literal('score'),
|
|
72
|
+
score: z.number(),
|
|
73
|
+
confidence: z.number(),
|
|
74
|
+
probabilities: z.record(z.string(), z.number()),
|
|
75
|
+
legend: z.record(z.string(), z.string()).optional(),
|
|
76
|
+
});
|
|
77
|
+
/** AD-084: схема ответа decision-модели. */
|
|
78
|
+
export const decisionAnswerSchema = z.discriminatedUnion('type', [
|
|
79
|
+
decisionNoulAnswerSchema,
|
|
80
|
+
decisionChoiceAnswerSchema,
|
|
81
|
+
decisionScoreAnswerSchema,
|
|
82
|
+
]);
|
|
83
|
+
export const decisionRequestSchema = z.object({
|
|
84
|
+
model: z.string(),
|
|
85
|
+
state: z.unknown(),
|
|
86
|
+
questions: z.record(z.string(), decisionQuestionSchema),
|
|
87
|
+
/** AD-084/AD-085: медиа-вложения (изображения/видео) — опциональны. */
|
|
88
|
+
images: z.array(z.string()).optional(),
|
|
89
|
+
videos: z.array(z.string()).optional(),
|
|
90
|
+
});
|
|
91
|
+
export const decisionResponseSchema = z.object({
|
|
92
|
+
id: z.string().optional(),
|
|
93
|
+
model: z.string().optional(),
|
|
94
|
+
answers: z.record(z.string(), decisionAnswerSchema),
|
|
95
|
+
usage: z
|
|
96
|
+
.object({ input_tokens: z.number(), output_tokens: z.number() })
|
|
97
|
+
.optional(),
|
|
98
|
+
});
|