@niscorp/signal 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.
- package/DESIGN.md +139 -0
- package/DOCS.md +502 -0
- package/LICENSE +202 -0
- package/README.md +117 -0
- package/dist/index.cjs +1847 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +591 -0
- package/dist/index.d.ts +591 -0
- package/dist/index.js +1825 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import { z, ZodType } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ImageSource = {
|
|
4
|
+
type: 'url';
|
|
5
|
+
url: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: 'base64';
|
|
8
|
+
mediaType: string;
|
|
9
|
+
data: string;
|
|
10
|
+
};
|
|
11
|
+
type ContentPart = {
|
|
12
|
+
type: 'text';
|
|
13
|
+
text: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'image';
|
|
16
|
+
source: ImageSource;
|
|
17
|
+
};
|
|
18
|
+
type AssistantToolCall = {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
args: string;
|
|
22
|
+
};
|
|
23
|
+
type Message = {
|
|
24
|
+
role: 'system';
|
|
25
|
+
content: string;
|
|
26
|
+
} | {
|
|
27
|
+
role: 'user';
|
|
28
|
+
content: string | ContentPart[];
|
|
29
|
+
} | {
|
|
30
|
+
role: 'assistant';
|
|
31
|
+
content: string;
|
|
32
|
+
toolCalls?: AssistantToolCall[];
|
|
33
|
+
} | {
|
|
34
|
+
role: 'tool';
|
|
35
|
+
toolCallId: string;
|
|
36
|
+
name: string;
|
|
37
|
+
content: string;
|
|
38
|
+
};
|
|
39
|
+
type ToolConfig<TInput = unknown> = {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
input: z.ZodType<TInput>;
|
|
43
|
+
execute: (input: TInput) => Promise<unknown> | unknown;
|
|
44
|
+
};
|
|
45
|
+
type Tool = {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
inputSchema: z.ZodType;
|
|
49
|
+
execute: (input: unknown) => Promise<unknown> | unknown;
|
|
50
|
+
};
|
|
51
|
+
type ToolCallRecord = {
|
|
52
|
+
name: string;
|
|
53
|
+
args: unknown;
|
|
54
|
+
result: unknown;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
};
|
|
57
|
+
type EndpointCapabilities = {
|
|
58
|
+
nativeTools: boolean;
|
|
59
|
+
nativeJsonMode: boolean;
|
|
60
|
+
validatesToolArgs: boolean;
|
|
61
|
+
supportsEmbedding: boolean;
|
|
62
|
+
};
|
|
63
|
+
type ModelCapabilities = {
|
|
64
|
+
nativeJsonSchema: boolean;
|
|
65
|
+
toolsWithStructuredOutput: boolean;
|
|
66
|
+
manglesNestedToolArgs: boolean;
|
|
67
|
+
multimodal: boolean;
|
|
68
|
+
};
|
|
69
|
+
type Capabilities = EndpointCapabilities & ModelCapabilities;
|
|
70
|
+
declare const REASONING_EFFORTS: readonly ["none", "default", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
71
|
+
type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
|
|
72
|
+
type SignalOptions = {
|
|
73
|
+
temperature?: number;
|
|
74
|
+
maxTokens?: number;
|
|
75
|
+
topP?: number;
|
|
76
|
+
stopSequences?: string[];
|
|
77
|
+
seed?: number;
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
reasoningEffort?: ReasoningEffort;
|
|
80
|
+
};
|
|
81
|
+
type ProviderError = {
|
|
82
|
+
code: string;
|
|
83
|
+
message: string;
|
|
84
|
+
recovered: boolean;
|
|
85
|
+
raw?: unknown;
|
|
86
|
+
};
|
|
87
|
+
type SignalMeta = {
|
|
88
|
+
model: string;
|
|
89
|
+
usage: {
|
|
90
|
+
inputTokens: number;
|
|
91
|
+
outputTokens: number;
|
|
92
|
+
totalTokens: number;
|
|
93
|
+
};
|
|
94
|
+
durationMs: number;
|
|
95
|
+
retries: number;
|
|
96
|
+
toolCalls: ToolCallRecord[];
|
|
97
|
+
provider: {
|
|
98
|
+
raw: unknown;
|
|
99
|
+
errors: ProviderError[];
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
type SignalResult<T> = {
|
|
103
|
+
response: T;
|
|
104
|
+
history: Message[];
|
|
105
|
+
meta: SignalMeta;
|
|
106
|
+
};
|
|
107
|
+
type StepToolCall = {
|
|
108
|
+
id: string;
|
|
109
|
+
name: string;
|
|
110
|
+
args: unknown;
|
|
111
|
+
};
|
|
112
|
+
type StepInputMessage = Message | {
|
|
113
|
+
role: 'tool';
|
|
114
|
+
toolCallId: string;
|
|
115
|
+
name: string;
|
|
116
|
+
content: string;
|
|
117
|
+
};
|
|
118
|
+
type Rejection = {
|
|
119
|
+
name?: string;
|
|
120
|
+
args?: unknown;
|
|
121
|
+
argsText: string;
|
|
122
|
+
truncated: boolean;
|
|
123
|
+
};
|
|
124
|
+
type StepOutcome = {
|
|
125
|
+
kind: 'tool_calls';
|
|
126
|
+
calls: StepToolCall[];
|
|
127
|
+
} | {
|
|
128
|
+
kind: 'output';
|
|
129
|
+
value: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
kind: 'failed';
|
|
132
|
+
evidence: string;
|
|
133
|
+
truncated?: boolean;
|
|
134
|
+
};
|
|
135
|
+
type WireReport = {
|
|
136
|
+
rung?: string;
|
|
137
|
+
recovered?: {
|
|
138
|
+
strategy: string;
|
|
139
|
+
name?: string;
|
|
140
|
+
truncated: boolean;
|
|
141
|
+
};
|
|
142
|
+
notes?: string[];
|
|
143
|
+
};
|
|
144
|
+
type StepToolDescriptor = {
|
|
145
|
+
name: string;
|
|
146
|
+
description: string;
|
|
147
|
+
parameters: Record<string, unknown>;
|
|
148
|
+
};
|
|
149
|
+
type ResponseFormat = {
|
|
150
|
+
type: 'json_schema';
|
|
151
|
+
jsonSchema: {
|
|
152
|
+
name: string;
|
|
153
|
+
strict: boolean;
|
|
154
|
+
schema: Record<string, unknown>;
|
|
155
|
+
};
|
|
156
|
+
} | {
|
|
157
|
+
type: 'json_object';
|
|
158
|
+
};
|
|
159
|
+
type StepRequest = {
|
|
160
|
+
messages: ReadonlyArray<StepInputMessage>;
|
|
161
|
+
tools?: ReadonlyArray<StepToolDescriptor>;
|
|
162
|
+
toolChoice?: 'auto' | 'none' | 'required' | {
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
165
|
+
output?: {
|
|
166
|
+
accept: z.ZodType;
|
|
167
|
+
outputTool?: string;
|
|
168
|
+
};
|
|
169
|
+
responseFormat?: ResponseFormat;
|
|
170
|
+
options?: SignalOptions;
|
|
171
|
+
};
|
|
172
|
+
type StepResult = {
|
|
173
|
+
content: string;
|
|
174
|
+
toolCalls: StepToolCall[];
|
|
175
|
+
usage: {
|
|
176
|
+
inputTokens: number;
|
|
177
|
+
outputTokens: number;
|
|
178
|
+
totalTokens: number;
|
|
179
|
+
reported: boolean;
|
|
180
|
+
};
|
|
181
|
+
finishReason: string;
|
|
182
|
+
raw: unknown;
|
|
183
|
+
outcome?: StepOutcome;
|
|
184
|
+
wire?: WireReport;
|
|
185
|
+
};
|
|
186
|
+
type CountInput = string | ReadonlyArray<StepInputMessage>;
|
|
187
|
+
type EmbedOptions = {
|
|
188
|
+
dimensions?: number;
|
|
189
|
+
onUsage?: (usage: {
|
|
190
|
+
inputTokens: number;
|
|
191
|
+
totalTokens: number;
|
|
192
|
+
}, model: string) => void;
|
|
193
|
+
};
|
|
194
|
+
type EmbedRequest = {
|
|
195
|
+
model: string;
|
|
196
|
+
input: string | string[];
|
|
197
|
+
dimensions?: number;
|
|
198
|
+
};
|
|
199
|
+
type EmbedResponse = {
|
|
200
|
+
embeddings: number[][];
|
|
201
|
+
usage: {
|
|
202
|
+
inputTokens: number;
|
|
203
|
+
totalTokens: number;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
type ChoiceQuestion<K extends string = string> = {
|
|
207
|
+
type: 'choice';
|
|
208
|
+
instructions: string;
|
|
209
|
+
criteria: Record<K, string>;
|
|
210
|
+
};
|
|
211
|
+
type ScoreQuestion = {
|
|
212
|
+
type: 'score';
|
|
213
|
+
instructions: string;
|
|
214
|
+
criteria: readonly string[];
|
|
215
|
+
};
|
|
216
|
+
type NoulQuestion = {
|
|
217
|
+
type: 'noul';
|
|
218
|
+
instructions: string;
|
|
219
|
+
criteria?: {
|
|
220
|
+
true: string;
|
|
221
|
+
false: string;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
type Question = ChoiceQuestion | ScoreQuestion | NoulQuestion;
|
|
225
|
+
type Questions = Record<string, Question>;
|
|
226
|
+
type DecideState = string | Record<string, unknown> | readonly unknown[];
|
|
227
|
+
type UncalibratedDecision<Q extends Question> = Q extends ChoiceQuestion<infer K> ? {
|
|
228
|
+
choice: K;
|
|
229
|
+
} : Q extends ScoreQuestion ? {
|
|
230
|
+
level: number;
|
|
231
|
+
} : {
|
|
232
|
+
answer: boolean;
|
|
233
|
+
};
|
|
234
|
+
type CalibratedDecision<Q extends Question> = Q extends ChoiceQuestion<infer K> ? {
|
|
235
|
+
choice: K;
|
|
236
|
+
probabilities: Record<K, number>;
|
|
237
|
+
confidence: number;
|
|
238
|
+
} : Q extends ScoreQuestion ? {
|
|
239
|
+
level: number;
|
|
240
|
+
score: number;
|
|
241
|
+
probabilities: number[];
|
|
242
|
+
confidence: number;
|
|
243
|
+
} : {
|
|
244
|
+
answer: boolean;
|
|
245
|
+
noul: number;
|
|
246
|
+
};
|
|
247
|
+
type DecideRequest<Qs extends Questions> = {
|
|
248
|
+
state: DecideState;
|
|
249
|
+
questions: Qs;
|
|
250
|
+
options?: {
|
|
251
|
+
signal?: AbortSignal;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
type DecideMeta = {
|
|
255
|
+
model: string;
|
|
256
|
+
usage: {
|
|
257
|
+
inputTokens: number;
|
|
258
|
+
outputTokens: number;
|
|
259
|
+
totalTokens: number;
|
|
260
|
+
reported: boolean;
|
|
261
|
+
};
|
|
262
|
+
durationMs: number;
|
|
263
|
+
provider: {
|
|
264
|
+
raw: unknown;
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
type DecideResult<Qs extends Questions> = {
|
|
268
|
+
calibrated: true;
|
|
269
|
+
decisions: {
|
|
270
|
+
[N in keyof Qs]: CalibratedDecision<Qs[N]>;
|
|
271
|
+
};
|
|
272
|
+
meta: DecideMeta;
|
|
273
|
+
} | {
|
|
274
|
+
calibrated: false;
|
|
275
|
+
decisions: {
|
|
276
|
+
[N in keyof Qs]: UncalibratedDecision<Qs[N]>;
|
|
277
|
+
};
|
|
278
|
+
meta: DecideMeta;
|
|
279
|
+
};
|
|
280
|
+
type StreamEvent<T> = {
|
|
281
|
+
type: 'text';
|
|
282
|
+
text: string;
|
|
283
|
+
} | {
|
|
284
|
+
type: 'tool_start';
|
|
285
|
+
name: string;
|
|
286
|
+
args: unknown;
|
|
287
|
+
} | {
|
|
288
|
+
type: 'tool_end';
|
|
289
|
+
name: string;
|
|
290
|
+
result: unknown;
|
|
291
|
+
} | {
|
|
292
|
+
type: 'retry';
|
|
293
|
+
reason: string;
|
|
294
|
+
attempt: number;
|
|
295
|
+
} | {
|
|
296
|
+
type: 'error';
|
|
297
|
+
error: Error;
|
|
298
|
+
recovered: boolean;
|
|
299
|
+
} | {
|
|
300
|
+
type: 'done';
|
|
301
|
+
response: T;
|
|
302
|
+
history: Message[];
|
|
303
|
+
meta: SignalMeta;
|
|
304
|
+
};
|
|
305
|
+
type StepStreamEvent = {
|
|
306
|
+
type: 'text';
|
|
307
|
+
text: string;
|
|
308
|
+
} | {
|
|
309
|
+
type: 'reasoning';
|
|
310
|
+
text: string;
|
|
311
|
+
} | {
|
|
312
|
+
type: 'tool_call_delta';
|
|
313
|
+
index: number;
|
|
314
|
+
id?: string;
|
|
315
|
+
name?: string;
|
|
316
|
+
argsText: string;
|
|
317
|
+
} | {
|
|
318
|
+
type: 'done';
|
|
319
|
+
result: StepResult;
|
|
320
|
+
};
|
|
321
|
+
type StreamOptions = {
|
|
322
|
+
signal?: AbortSignal;
|
|
323
|
+
};
|
|
324
|
+
type ProviderStreamDelta = {
|
|
325
|
+
type: 'text';
|
|
326
|
+
text: string;
|
|
327
|
+
} | {
|
|
328
|
+
type: 'reasoning';
|
|
329
|
+
text: string;
|
|
330
|
+
} | {
|
|
331
|
+
type: 'tool_call';
|
|
332
|
+
index: number;
|
|
333
|
+
id?: string;
|
|
334
|
+
name?: string;
|
|
335
|
+
argsFragment?: string;
|
|
336
|
+
} | {
|
|
337
|
+
type: 'usage';
|
|
338
|
+
inputTokens: number;
|
|
339
|
+
outputTokens: number;
|
|
340
|
+
totalTokens: number;
|
|
341
|
+
} | {
|
|
342
|
+
type: 'finish';
|
|
343
|
+
finishReason: string;
|
|
344
|
+
};
|
|
345
|
+
type ProviderRequest = {
|
|
346
|
+
model: string;
|
|
347
|
+
messages: Message[];
|
|
348
|
+
responseFormat?: ResponseFormat;
|
|
349
|
+
tools?: Array<{
|
|
350
|
+
type: 'function';
|
|
351
|
+
function: {
|
|
352
|
+
name: string;
|
|
353
|
+
description: string;
|
|
354
|
+
parameters: Record<string, unknown>;
|
|
355
|
+
};
|
|
356
|
+
}>;
|
|
357
|
+
toolChoice?: 'auto' | 'none' | 'required' | {
|
|
358
|
+
name: string;
|
|
359
|
+
};
|
|
360
|
+
options?: SignalOptions;
|
|
361
|
+
};
|
|
362
|
+
type ProviderResponse = {
|
|
363
|
+
content: string;
|
|
364
|
+
toolCalls?: Array<{
|
|
365
|
+
id: string;
|
|
366
|
+
name: string;
|
|
367
|
+
args: string;
|
|
368
|
+
}>;
|
|
369
|
+
usage: {
|
|
370
|
+
inputTokens: number;
|
|
371
|
+
outputTokens: number;
|
|
372
|
+
totalTokens: number;
|
|
373
|
+
};
|
|
374
|
+
finishReason: string;
|
|
375
|
+
raw: unknown;
|
|
376
|
+
};
|
|
377
|
+
type ChatAdapter = {
|
|
378
|
+
kind: 'chat';
|
|
379
|
+
id: string;
|
|
380
|
+
chat: (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
381
|
+
chatStream: (request: ProviderRequest, options?: {
|
|
382
|
+
signal?: AbortSignal;
|
|
383
|
+
}) => AsyncIterable<ProviderStreamDelta>;
|
|
384
|
+
embed?: (request: EmbedRequest) => Promise<EmbedResponse>;
|
|
385
|
+
};
|
|
386
|
+
type DecisionAdapter = {
|
|
387
|
+
kind: 'decisions';
|
|
388
|
+
id: string;
|
|
389
|
+
decide: (request: DecisionRequest, options?: {
|
|
390
|
+
signal?: AbortSignal;
|
|
391
|
+
}) => Promise<DecisionResponse>;
|
|
392
|
+
};
|
|
393
|
+
type ProviderAdapter = ChatAdapter | DecisionAdapter;
|
|
394
|
+
type DecisionRequest = {
|
|
395
|
+
model: string;
|
|
396
|
+
state: DecideState;
|
|
397
|
+
questions: Questions;
|
|
398
|
+
};
|
|
399
|
+
type DecisionResponse = {
|
|
400
|
+
model?: string;
|
|
401
|
+
answers: unknown;
|
|
402
|
+
usage?: {
|
|
403
|
+
inputTokens: number;
|
|
404
|
+
outputTokens: number;
|
|
405
|
+
};
|
|
406
|
+
raw: unknown;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
type SignalConfig = {
|
|
410
|
+
readonly provider: string | CustomProviderConfig;
|
|
411
|
+
readonly apiKey?: string;
|
|
412
|
+
readonly model?: string;
|
|
413
|
+
readonly client?: unknown;
|
|
414
|
+
readonly systemPrompt?: string;
|
|
415
|
+
readonly history?: Message[];
|
|
416
|
+
readonly schema?: ZodType;
|
|
417
|
+
readonly tools?: Tool[];
|
|
418
|
+
readonly retries?: number;
|
|
419
|
+
readonly options?: SignalOptions;
|
|
420
|
+
readonly onRetry?: (error: Error, attempt: number) => void;
|
|
421
|
+
readonly onToolCall?: (name: string, args: unknown) => void;
|
|
422
|
+
};
|
|
423
|
+
type CustomProviderBase = {
|
|
424
|
+
baseUrl: string;
|
|
425
|
+
apiKey?: string;
|
|
426
|
+
model?: string;
|
|
427
|
+
};
|
|
428
|
+
type CustomChatProviderConfig = CustomProviderBase & {
|
|
429
|
+
adapter?: 'openai-compatible' | 'anthropic' | 'google';
|
|
430
|
+
capabilities?: Partial<Capabilities>;
|
|
431
|
+
wire?: string[];
|
|
432
|
+
};
|
|
433
|
+
type CustomDecisionProviderConfig = CustomProviderBase & {
|
|
434
|
+
adapter: 'systemone';
|
|
435
|
+
};
|
|
436
|
+
type CustomProviderConfig = CustomChatProviderConfig | CustomDecisionProviderConfig;
|
|
437
|
+
|
|
438
|
+
type Signal<T = string> = {
|
|
439
|
+
apiKey: (key: string) => Signal<T>;
|
|
440
|
+
model: (model: string) => Signal<T>;
|
|
441
|
+
systemPrompt: (prompt: string) => Signal<T>;
|
|
442
|
+
history: (messages: Message[]) => Signal<T>;
|
|
443
|
+
schema: <U>(schema: ZodType<U>) => Signal<U>;
|
|
444
|
+
tools: (tools: Tool[]) => Signal<T>;
|
|
445
|
+
retries: (count: number) => Signal<T>;
|
|
446
|
+
options: (opts: SignalOptions) => Signal<T>;
|
|
447
|
+
onRetry: (handler: (error: Error, attempt: number) => void) => Signal<T>;
|
|
448
|
+
onToolCall: (handler: (name: string, args: unknown) => void) => Signal<T>;
|
|
449
|
+
complete: (input: string | ContentPart[]) => Promise<SignalResult<T>>;
|
|
450
|
+
stream: (input: string | ContentPart[], options?: StreamOptions) => AsyncIterable<StreamEvent<T>>;
|
|
451
|
+
describe: () => SignalDescription;
|
|
452
|
+
step: (request: StepRequest) => Promise<StepResult>;
|
|
453
|
+
stepStream: (request: StepRequest, options?: StreamOptions) => AsyncIterable<StepStreamEvent>;
|
|
454
|
+
count: (input: CountInput) => Promise<number>;
|
|
455
|
+
embed: {
|
|
456
|
+
(input: string, options?: EmbedOptions): Promise<number[]>;
|
|
457
|
+
(input: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
458
|
+
};
|
|
459
|
+
decide: <const Qs extends Questions>(request: DecideRequest<Qs>) => Promise<DecideResult<Qs>>;
|
|
460
|
+
};
|
|
461
|
+
type SignalDescription = {
|
|
462
|
+
provider: string;
|
|
463
|
+
model: string | undefined;
|
|
464
|
+
kind: ProviderAdapter['kind'];
|
|
465
|
+
capabilities: Capabilities;
|
|
466
|
+
modelKnown: boolean;
|
|
467
|
+
};
|
|
468
|
+
declare const createSignal: (provider: string | CustomProviderConfig, options?: Partial<Omit<SignalConfig, "provider">>) => Signal<string>;
|
|
469
|
+
|
|
470
|
+
declare const defineTool: <TInput>(config: ToolConfig<TInput>) => Tool;
|
|
471
|
+
|
|
472
|
+
declare const ErrorCode: {
|
|
473
|
+
readonly PROVIDER_NOT_FOUND: "E_PROVIDER_NOT_FOUND";
|
|
474
|
+
readonly MISSING_API_KEY: "E_MISSING_API_KEY";
|
|
475
|
+
readonly MISSING_MODEL: "E_MISSING_MODEL";
|
|
476
|
+
readonly MISSING_SDK: "E_MISSING_SDK";
|
|
477
|
+
readonly VALIDATION_FAILED: "E_VALIDATION_FAILED";
|
|
478
|
+
readonly MAX_RETRIES: "E_MAX_RETRIES";
|
|
479
|
+
readonly MAX_ITERATIONS: "E_MAX_ITERATIONS";
|
|
480
|
+
readonly PROVIDER_ERROR: "E_PROVIDER_ERROR";
|
|
481
|
+
readonly TOOL_NOT_FOUND: "E_TOOL_NOT_FOUND";
|
|
482
|
+
readonly TOOL_EXECUTION: "E_TOOL_EXECUTION";
|
|
483
|
+
readonly TOOL_VALIDATION: "E_TOOL_VALIDATION";
|
|
484
|
+
readonly VERB_NOT_SUPPORTED: "E_VERB_NOT_SUPPORTED";
|
|
485
|
+
};
|
|
486
|
+
type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
487
|
+
declare class SignalError extends Error {
|
|
488
|
+
readonly code: ErrorCode;
|
|
489
|
+
readonly context?: Record<string, unknown>;
|
|
490
|
+
constructor(message: string, code: ErrorCode, context?: Record<string, unknown>);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
type ProviderEntryBase = {
|
|
494
|
+
id: string;
|
|
495
|
+
baseUrl: string;
|
|
496
|
+
envKey: string;
|
|
497
|
+
defaultModel: string;
|
|
498
|
+
};
|
|
499
|
+
type ChatProviderEntry = ProviderEntryBase & {
|
|
500
|
+
adapter: 'openai-compatible' | 'anthropic' | 'google';
|
|
501
|
+
endpoint: EndpointCapabilities;
|
|
502
|
+
wire?: string[];
|
|
503
|
+
reasoningRequest?: Record<string, unknown>;
|
|
504
|
+
};
|
|
505
|
+
type DecisionProviderEntry = ProviderEntryBase & {
|
|
506
|
+
adapter: 'systemone';
|
|
507
|
+
};
|
|
508
|
+
type ProviderEntry = ChatProviderEntry | DecisionProviderEntry;
|
|
509
|
+
type ModelEntry = {
|
|
510
|
+
capabilities: ModelCapabilities;
|
|
511
|
+
reasoningEfforts: readonly ReasoningEffort[];
|
|
512
|
+
verified: string;
|
|
513
|
+
};
|
|
514
|
+
declare const providerRegistry: Record<string, ProviderEntry>;
|
|
515
|
+
declare const modelRegistry: Record<string, ModelEntry>;
|
|
516
|
+
declare const UNMEASURED_MODEL: ModelCapabilities;
|
|
517
|
+
declare const modelKey: (provider: string, model: string) => string;
|
|
518
|
+
declare const modelEntry: (provider: string, model: string) => ModelEntry | undefined;
|
|
519
|
+
declare const chatProviderEntry: (id: string) => ChatProviderEntry | undefined;
|
|
520
|
+
|
|
521
|
+
type ErrorWireStrategy = {
|
|
522
|
+
id: string;
|
|
523
|
+
hook: 'error';
|
|
524
|
+
matches: (error: unknown) => boolean;
|
|
525
|
+
recover: (error: unknown) => Rejection | undefined;
|
|
526
|
+
};
|
|
527
|
+
type ResponseWireStrategy = {
|
|
528
|
+
id: string;
|
|
529
|
+
hook: 'response';
|
|
530
|
+
candidates: (content: string) => string[];
|
|
531
|
+
};
|
|
532
|
+
type WireStrategy = ErrorWireStrategy | ResponseWireStrategy;
|
|
533
|
+
|
|
534
|
+
type RouteRequest = {
|
|
535
|
+
content: string;
|
|
536
|
+
toolCalls: ReadonlyArray<StepToolCall>;
|
|
537
|
+
declared: ReadonlySet<string>;
|
|
538
|
+
outputTool?: string | undefined;
|
|
539
|
+
accept?: ZodType | undefined;
|
|
540
|
+
responseStrategies: ReadonlyArray<ResponseWireStrategy>;
|
|
541
|
+
};
|
|
542
|
+
type Routed = {
|
|
543
|
+
outcome: StepOutcome;
|
|
544
|
+
wire: WireReport;
|
|
545
|
+
};
|
|
546
|
+
declare const routeResponse: (request: RouteRequest) => Routed;
|
|
547
|
+
declare const routeRejection: (rejection: Rejection, request: Omit<RouteRequest, "content" | "toolCalls">) => Routed;
|
|
548
|
+
|
|
549
|
+
type ExtractResult = {
|
|
550
|
+
ok: true;
|
|
551
|
+
value: unknown;
|
|
552
|
+
} | {
|
|
553
|
+
ok: false;
|
|
554
|
+
};
|
|
555
|
+
declare const extractJson: (content: string) => ExtractResult;
|
|
556
|
+
declare const repairEscapeDamage: (text: string) => string[];
|
|
557
|
+
declare const decodeJsonish: (value: unknown) => unknown;
|
|
558
|
+
declare const deepDecodeJsonish: (value: unknown) => unknown;
|
|
559
|
+
declare const closeTruncated: (content: string) => string | undefined;
|
|
560
|
+
declare const isTruncatedJson: (content: string) => boolean;
|
|
561
|
+
|
|
562
|
+
type OutputTransport = 'respond' | 'native' | 'emit';
|
|
563
|
+
type ResponseMode = 'required' | 'optional';
|
|
564
|
+
type TransportSpec = {
|
|
565
|
+
wire: ZodType;
|
|
566
|
+
looseWire: ZodType;
|
|
567
|
+
responseMode: ResponseMode;
|
|
568
|
+
hasData: boolean;
|
|
569
|
+
hasTools: boolean;
|
|
570
|
+
choice?: 'auto' | OutputTransport;
|
|
571
|
+
forceTool?: boolean;
|
|
572
|
+
};
|
|
573
|
+
type ResolvedTransport = {
|
|
574
|
+
transport: OutputTransport;
|
|
575
|
+
responseMode: ResponseMode;
|
|
576
|
+
respondDetail?: 'full' | 'loose' | 'permissive';
|
|
577
|
+
respondDescriptor?: StepToolDescriptor;
|
|
578
|
+
outputToolName?: string;
|
|
579
|
+
responseFormat?: ResponseFormat;
|
|
580
|
+
toolChoice?: 'required';
|
|
581
|
+
injectSchemaDoc: boolean;
|
|
582
|
+
finishProtocol: string;
|
|
583
|
+
corrections: {
|
|
584
|
+
termination: string;
|
|
585
|
+
invalidOutput: string;
|
|
586
|
+
};
|
|
587
|
+
};
|
|
588
|
+
declare const RESPOND_TOOL_NAME = "respond";
|
|
589
|
+
declare const resolveTransport: (spec: TransportSpec, caps: Capabilities) => ResolvedTransport;
|
|
590
|
+
|
|
591
|
+
export { type AssistantToolCall, type CalibratedDecision, type Capabilities, type ChatProviderEntry, type ChoiceQuestion, type ContentPart, type CountInput, type CustomChatProviderConfig, type CustomDecisionProviderConfig, type CustomProviderConfig, type DecideMeta, type DecideRequest, type DecideResult, type DecideState, type DecisionProviderEntry, type EmbedOptions, type EmbedRequest, type EmbedResponse, type EndpointCapabilities, ErrorCode, type ErrorWireStrategy, type ExtractResult, type ImageSource, type Message, type ModelCapabilities, type ModelEntry, type NoulQuestion, type OutputTransport, type ProviderEntry, type ProviderError, type Question, type Questions, REASONING_EFFORTS, RESPOND_TOOL_NAME, type ReasoningEffort, type Rejection, type ResolvedTransport, type ResponseFormat, type ResponseWireStrategy, type ScoreQuestion, type Signal, type SignalConfig, type SignalDescription, SignalError, type SignalMeta, type SignalOptions, type SignalResult, type StepInputMessage, type StepOutcome, type StepRequest, type StepResult, type StepStreamEvent, type StepToolCall, type StepToolDescriptor, type StreamEvent, type StreamOptions, type Tool, type ToolCallRecord, type ToolConfig, type TransportSpec, UNMEASURED_MODEL, type UncalibratedDecision, type WireReport, type WireStrategy, chatProviderEntry, closeTruncated, createSignal, decodeJsonish, deepDecodeJsonish, defineTool, extractJson, isTruncatedJson, modelEntry, modelKey, modelRegistry, providerRegistry, repairEscapeDamage, resolveTransport, routeRejection, routeResponse };
|