@cognipeer/agent-sdk 0.10.5 → 0.12.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/README.md +28 -3
- package/dist/index.cjs +1785 -501
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1073 -661
- package/dist/index.d.ts +1073 -661
- package/dist/index.mjs +1778 -501
- package/dist/index.mjs.map +1 -1
- package/package.json +39 -1
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ interface BaseChatMessage {
|
|
|
72
72
|
name: string;
|
|
73
73
|
arguments: string;
|
|
74
74
|
};
|
|
75
|
+
thoughtSignature?: string;
|
|
75
76
|
}>;
|
|
76
77
|
tool_call_id?: string;
|
|
77
78
|
usage?: any;
|
|
@@ -210,6 +211,37 @@ type MediaAttachment = {
|
|
|
210
211
|
approxBytes?: number;
|
|
211
212
|
fileName?: string;
|
|
212
213
|
};
|
|
214
|
+
type MediaKind$1 = "image" | "audio" | "video" | "file";
|
|
215
|
+
/**
|
|
216
|
+
* What kind of attachment a content part is, or undefined for text and for
|
|
217
|
+
* anything that is not a media part.
|
|
218
|
+
*
|
|
219
|
+
* Covers the unified shape (`image`/`audio`/`file` with a `source`), the
|
|
220
|
+
* OpenAI shapes (`image_url`, `input_audio`, `file`, `input_image`, `input_file`)
|
|
221
|
+
* and Gemini's untyped `inlineData` / `fileData`.
|
|
222
|
+
*/
|
|
223
|
+
declare function mediaKindOf(part: unknown): MediaKind$1 | undefined;
|
|
224
|
+
/** True when the content is an array holding at least one media part. */
|
|
225
|
+
declare function hasMediaPart(content: unknown): boolean;
|
|
226
|
+
/**
|
|
227
|
+
* A short, human-readable stand-in for a media part: `[image: photo.png]`,
|
|
228
|
+
* `[image: image/png]`, `[audio]`. Undefined for text and non-media parts.
|
|
229
|
+
*
|
|
230
|
+
* This is what anything that flattens content to TEXT must use for an
|
|
231
|
+
* attachment — token estimation, the summarizer's input, trace display. The
|
|
232
|
+
* alternative, `JSON.stringify(part)`, writes the whole base64 payload into the
|
|
233
|
+
* text: an image of ~400 tokens counts as 18,000 and a summarizer reads (and is
|
|
234
|
+
* truncated into) a wall of base64 instead of knowing a picture was there.
|
|
235
|
+
*
|
|
236
|
+
* The label is the part's own `name`, else its file id, else its media type.
|
|
237
|
+
*/
|
|
238
|
+
declare function describeContentPart(part: unknown): string | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* One content part as plain text: strings and text parts as they are, media as
|
|
241
|
+
* its placeholder, anything else through `fallback` (default: its own `text` /
|
|
242
|
+
* `content`, else its JSON).
|
|
243
|
+
*/
|
|
244
|
+
declare function contentPartToText(part: unknown, fallback?: (part: unknown) => string): string;
|
|
213
245
|
declare function contentToString(content: string | ContentPart$1[] | any): string;
|
|
214
246
|
declare function extractMessageText(message: any): string;
|
|
215
247
|
/**
|
|
@@ -1801,12 +1833,28 @@ type AgentRuntimeConfig = {
|
|
|
1801
1833
|
smart?: ResolvedSmartAgentConfig;
|
|
1802
1834
|
humanInTheLoop?: HumanInTheLoopRuntimeConfig;
|
|
1803
1835
|
};
|
|
1836
|
+
/** One part of a message as it was sent: text, or an attachment (image, audio, file …). */
|
|
1837
|
+
type TraceMessagePart = {
|
|
1838
|
+
type?: string;
|
|
1839
|
+
text?: string;
|
|
1840
|
+
[key: string]: any;
|
|
1841
|
+
};
|
|
1804
1842
|
type TraceMessageSection = {
|
|
1805
1843
|
id?: string;
|
|
1806
1844
|
kind: "message";
|
|
1807
1845
|
label: string;
|
|
1808
1846
|
role: string;
|
|
1847
|
+
/**
|
|
1848
|
+
* The message as text. An attachment appears in it as a short placeholder
|
|
1849
|
+
* (`[image: photo.png]`), never as its encoded payload.
|
|
1850
|
+
*/
|
|
1809
1851
|
content: string;
|
|
1852
|
+
/**
|
|
1853
|
+
* The message's structured parts, present only when it carries a non-text part
|
|
1854
|
+
* (an image, audio, a file). Lets a host render the attachment — a thumbnail —
|
|
1855
|
+
* where `content` can only name it. Text parts are included, in order.
|
|
1856
|
+
*/
|
|
1857
|
+
parts?: TraceMessagePart[];
|
|
1810
1858
|
metadata?: Record<string, any>;
|
|
1811
1859
|
};
|
|
1812
1860
|
type TraceToolCallSection = {
|
|
@@ -2355,6 +2403,11 @@ type StreamEvent = {
|
|
|
2355
2403
|
text: string;
|
|
2356
2404
|
isFinal?: boolean;
|
|
2357
2405
|
};
|
|
2406
|
+
/** Incremental model reasoning text (providers that expose it while streaming). */
|
|
2407
|
+
type ReasoningEvent = {
|
|
2408
|
+
type: "reasoning";
|
|
2409
|
+
text: string;
|
|
2410
|
+
};
|
|
2358
2411
|
type CancelledEvent = {
|
|
2359
2412
|
type: "cancelled";
|
|
2360
2413
|
stage?: string;
|
|
@@ -2533,7 +2586,7 @@ type DelegationEventStamp = {
|
|
|
2533
2586
|
/** Name of the `asTool` child agent this forwarded event came from. */
|
|
2534
2587
|
delegatedTo?: string;
|
|
2535
2588
|
};
|
|
2536
|
-
type SmartAgentEvent = (ToolCallEvent | ToolApprovalEvent | UserQuestionEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | CancelledEvent | SubagentEvent | ReflectionEvent | PluginEvent) & DelegationEventStamp;
|
|
2589
|
+
type SmartAgentEvent = (ToolCallEvent | ToolApprovalEvent | UserQuestionEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent | ProgressEvent | StreamEvent | ReasoningEvent | CancelledEvent | SubagentEvent | ReflectionEvent | PluginEvent) & DelegationEventStamp;
|
|
2537
2590
|
type ReflectionEvent = {
|
|
2538
2591
|
type: "reflection";
|
|
2539
2592
|
id: string;
|
|
@@ -3255,596 +3308,305 @@ type CreateGuardrailOptions = {
|
|
|
3255
3308
|
};
|
|
3256
3309
|
declare function createGuardrail(options: CreateGuardrailOptions): ConversationGuardrail;
|
|
3257
3310
|
|
|
3258
|
-
type
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
pattern: RegExp | string;
|
|
3263
|
-
flags?: string;
|
|
3264
|
-
matchDisposition?: GuardrailDisposition;
|
|
3265
|
-
selector?: (context: GuardrailContext) => string;
|
|
3266
|
-
allowIfMatch?: boolean;
|
|
3267
|
-
failureMessage?: string;
|
|
3311
|
+
type MessageRole = "system" | "user" | "assistant" | "tool";
|
|
3312
|
+
type TextContent = {
|
|
3313
|
+
type: "text";
|
|
3314
|
+
text: string;
|
|
3268
3315
|
};
|
|
3269
|
-
|
|
3270
|
-
type
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3316
|
+
type ImageContent = {
|
|
3317
|
+
type: "image";
|
|
3318
|
+
source: {
|
|
3319
|
+
type: "base64";
|
|
3320
|
+
mediaType: string;
|
|
3321
|
+
data: string;
|
|
3322
|
+
} | {
|
|
3323
|
+
type: "url";
|
|
3324
|
+
url: string;
|
|
3325
|
+
mediaType?: string;
|
|
3326
|
+
};
|
|
3278
3327
|
};
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3328
|
+
/**
|
|
3329
|
+
* A document attachment (PDF, DOCX, CSV, …). Providers map this to their
|
|
3330
|
+
* native document blocks: Gemini `inlineData`/`fileData`, Anthropic
|
|
3331
|
+
* `document`, OpenAI Chat Completions `file` / Responses `input_file`,
|
|
3332
|
+
* Bedrock Converse `document`. Providers without document support degrade
|
|
3333
|
+
* to a text placeholder referencing the file name/URL.
|
|
3334
|
+
*/
|
|
3335
|
+
type FileContent = {
|
|
3336
|
+
type: "file";
|
|
3337
|
+
source: {
|
|
3338
|
+
type: "base64";
|
|
3339
|
+
mediaType: string;
|
|
3340
|
+
data: string;
|
|
3341
|
+
} | {
|
|
3342
|
+
type: "url";
|
|
3343
|
+
url: string;
|
|
3344
|
+
mediaType?: string;
|
|
3345
|
+
};
|
|
3346
|
+
/** Original file name, when known (required by some providers, e.g. Bedrock). */
|
|
3347
|
+
fileName?: string;
|
|
3287
3348
|
};
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
}
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
}>;
|
|
3305
|
-
type AgentRuleOptions = {
|
|
3306
|
-
id?: string;
|
|
3307
|
-
title?: string;
|
|
3308
|
-
description?: string;
|
|
3309
|
-
agent: SmartAgentInstance<z.infer<typeof guardianSchema>>;
|
|
3310
|
-
systemPrompt?: string;
|
|
3311
|
-
payloadBuilder?: (context: GuardrailContext) => string;
|
|
3312
|
-
dispositionFallback?: GuardrailDisposition;
|
|
3349
|
+
/**
|
|
3350
|
+
* An audio attachment. Gemini accepts it as `inlineData`/`fileData`; OpenAI
|
|
3351
|
+
* audio-capable models as `input_audio`. Providers without audio support
|
|
3352
|
+
* degrade to a text placeholder.
|
|
3353
|
+
*/
|
|
3354
|
+
type AudioContent = {
|
|
3355
|
+
type: "audio";
|
|
3356
|
+
source: {
|
|
3357
|
+
type: "base64";
|
|
3358
|
+
mediaType: string;
|
|
3359
|
+
data: string;
|
|
3360
|
+
} | {
|
|
3361
|
+
type: "url";
|
|
3362
|
+
url: string;
|
|
3363
|
+
mediaType?: string;
|
|
3364
|
+
};
|
|
3313
3365
|
};
|
|
3314
|
-
|
|
3315
|
-
type
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
disposition?: GuardrailDisposition;
|
|
3324
|
-
details?: Record<string, any>;
|
|
3325
|
-
}>;
|
|
3326
|
-
type CustomRuleOptions = {
|
|
3327
|
-
id?: string;
|
|
3328
|
-
title?: string;
|
|
3329
|
-
description?: string;
|
|
3330
|
-
callback: CustomRuleCallback;
|
|
3331
|
-
defaultDisposition?: GuardrailDisposition;
|
|
3366
|
+
type ContentPart = TextContent | ImageContent | FileContent | AudioContent;
|
|
3367
|
+
type ToolCall = {
|
|
3368
|
+
id: string;
|
|
3369
|
+
name: string;
|
|
3370
|
+
arguments: string;
|
|
3371
|
+
/** Gemini `thoughtSignature` attached to a functionCall part; must be echoed back on the next turn. */
|
|
3372
|
+
thoughtSignature?: string;
|
|
3373
|
+
/** Position of the call within the assistant turn. Set on streamed deltas so a consumer can frame them (OpenAI `tool_calls[].index`). */
|
|
3374
|
+
index?: number;
|
|
3332
3375
|
};
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3376
|
+
/**
|
|
3377
|
+
* A provider-native reasoning/thinking block. Captured from the model response
|
|
3378
|
+
* and replayed verbatim on subsequent turns (required by Anthropic extended
|
|
3379
|
+
* thinking when tools are involved — the `signature` must round-trip intact).
|
|
3380
|
+
*/
|
|
3381
|
+
type ReasoningBlock = {
|
|
3382
|
+
type: "thinking" | "redacted_thinking";
|
|
3383
|
+
/** Plain-text thinking content (absent for redacted blocks). */
|
|
3384
|
+
text?: string;
|
|
3385
|
+
/** Cryptographic signature Anthropic requires to be echoed back verbatim. */
|
|
3386
|
+
signature?: string;
|
|
3387
|
+
/** Opaque payload for redacted_thinking blocks. */
|
|
3388
|
+
data?: string;
|
|
3343
3389
|
};
|
|
3344
|
-
|
|
3345
|
-
|
|
3390
|
+
/** Captured reasoning payload attached to assistant turns / responses. */
|
|
3391
|
+
type ReasoningPayload = {
|
|
3392
|
+
/** Verbatim provider blocks to replay on the next turn. */
|
|
3393
|
+
blocks?: ReasoningBlock[];
|
|
3394
|
+
/** Human-readable reasoning summary, when the provider exposes one. */
|
|
3395
|
+
summary?: string;
|
|
3346
3396
|
};
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3397
|
+
type UnifiedMessage = {
|
|
3398
|
+
role: MessageRole;
|
|
3399
|
+
content: string | ContentPart[];
|
|
3400
|
+
name?: string;
|
|
3401
|
+
toolCalls?: ToolCall[];
|
|
3402
|
+
toolCallId?: string;
|
|
3403
|
+
/** Native reasoning blocks to replay verbatim (Anthropic/Bedrock thinking). */
|
|
3404
|
+
reasoning?: ReasoningPayload;
|
|
3350
3405
|
};
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3406
|
+
type ToolDefinition = {
|
|
3407
|
+
name: string;
|
|
3408
|
+
description: string;
|
|
3409
|
+
parameters: Record<string, any>;
|
|
3410
|
+
strict?: boolean;
|
|
3411
|
+
};
|
|
3412
|
+
type ChatCompletionRequest = {
|
|
3413
|
+
model: string;
|
|
3414
|
+
messages: UnifiedMessage[];
|
|
3415
|
+
temperature?: number;
|
|
3416
|
+
maxTokens?: number;
|
|
3417
|
+
topP?: number;
|
|
3418
|
+
stop?: string[];
|
|
3419
|
+
/** OpenAI-family only; other providers ignore it. */
|
|
3420
|
+
presencePenalty?: number;
|
|
3421
|
+
/** OpenAI-family only; other providers ignore it. */
|
|
3422
|
+
frequencyPenalty?: number;
|
|
3423
|
+
tools?: ToolDefinition[];
|
|
3424
|
+
toolChoice?: "auto" | "required" | "none" | {
|
|
3425
|
+
name: string;
|
|
3426
|
+
};
|
|
3427
|
+
responseFormat?: {
|
|
3428
|
+
type: "json_schema" | "json_object" | "text";
|
|
3429
|
+
schema?: Record<string, any>;
|
|
3430
|
+
name?: string;
|
|
3431
|
+
};
|
|
3432
|
+
stream?: boolean;
|
|
3433
|
+
/**
|
|
3434
|
+
* Streaming only. `false` opts out of `stream_options.include_usage` on
|
|
3435
|
+
* OpenAI-shaped endpoints (some servers reject the option). Default true.
|
|
3436
|
+
*/
|
|
3437
|
+
streamUsage?: boolean;
|
|
3438
|
+
/** OpenAI-family: deterministic sampling seed. Passed through. */
|
|
3439
|
+
seed?: number;
|
|
3440
|
+
/** OpenAI-family: number of choices. Pass-through only; only choice 0 is parsed. */
|
|
3441
|
+
n?: number;
|
|
3442
|
+
/** OpenAI-family: allow/forbid parallel tool calls. Passed through when set. */
|
|
3443
|
+
parallelToolCalls?: boolean;
|
|
3444
|
+
/** OpenAI-family: return token log probabilities. Passed through. */
|
|
3445
|
+
logprobs?: boolean;
|
|
3446
|
+
/** OpenAI-family: how many top log probabilities per token. Passed through. */
|
|
3447
|
+
topLogprobs?: number;
|
|
3448
|
+
extra?: Record<string, any>;
|
|
3449
|
+
/**
|
|
3450
|
+
* Unified native-reasoning request config. Each provider maps this to its
|
|
3451
|
+
* own shape:
|
|
3452
|
+
* - OpenAI o-series: body.reasoning_effort = effort
|
|
3453
|
+
* - OpenAI Responses: body.reasoning = { effort }
|
|
3454
|
+
* - Anthropic: body.thinking = { type: "enabled", budget_tokens }
|
|
3455
|
+
* - Google / Vertex: body.generationConfig.thinkingConfig = { thinkingBudget, includeThoughts }
|
|
3456
|
+
*
|
|
3457
|
+
* Providers silently ignore unsupported fields.
|
|
3458
|
+
*/
|
|
3459
|
+
reasoning?: ReasoningRequestConfig;
|
|
3460
|
+
/**
|
|
3461
|
+
* Cancels the HTTP request (and an in-flight stream) when it aborts. The agent
|
|
3462
|
+
* loop sets it from the run's cancellation token / abort signal; a caller using
|
|
3463
|
+
* a provider directly can pass its own. It is never serialised into the body.
|
|
3464
|
+
*/
|
|
3465
|
+
signal?: AbortSignal;
|
|
3354
3466
|
};
|
|
3355
|
-
declare function createCodeGuardrail(options?: CodeGuardrailOptions): ConversationGuardrail;
|
|
3356
|
-
|
|
3357
|
-
/**
|
|
3358
|
-
* Wrap a plugin factory so config flows through with full inference:
|
|
3359
|
-
*
|
|
3360
|
-
* const myGuard = definePlugin<{ level: number }>((cfg) => ({ name: "my-guard", ... }));
|
|
3361
|
-
* myGuard({ level: 2 })
|
|
3362
|
-
*
|
|
3363
|
-
* The indirection buys nothing at runtime — it exists so the config type is
|
|
3364
|
-
* inferred at the call site and the returned object is checked against
|
|
3365
|
-
* `AgentPlugin` at the definition site, where the error message is useful.
|
|
3366
|
-
*/
|
|
3367
|
-
declare function definePlugin<TConfig = void>(factory: (config: TConfig) => AgentPlugin): (config: TConfig) => AgentPlugin;
|
|
3368
3467
|
/**
|
|
3369
|
-
*
|
|
3370
|
-
* lifecycle would be ceremony:
|
|
3468
|
+
* `none` is OFF, and it is a value rather than the absence of one.
|
|
3371
3469
|
*
|
|
3372
|
-
*
|
|
3470
|
+
* On a thinking-by-default model — every Qwen3 under vLLM, gpt-5.1 and newer on
|
|
3471
|
+
* OpenAI — sending no reasoning field leaves the model thinking. So "do not
|
|
3472
|
+
* think" is an instruction that has to travel: `reasoning_effort:"none"` on
|
|
3473
|
+
* OpenAI, `thinkingBudget:0` on Gemini, and no thinking block at all on
|
|
3474
|
+
* Anthropic (where thinking is opt-in and the absence IS off). Omitting
|
|
3475
|
+
* `effort` still means "say nothing about reasoning", which is the different
|
|
3476
|
+
* and equally necessary state.
|
|
3373
3477
|
*/
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3478
|
+
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high";
|
|
3479
|
+
type ReasoningRequestConfig = {
|
|
3480
|
+
/** Qualitative effort hint (mapped per-provider). */
|
|
3481
|
+
effort?: ReasoningEffort;
|
|
3482
|
+
/** Explicit per-call token budget for reasoning/thinking. */
|
|
3483
|
+
budgetTokens?: number;
|
|
3380
3484
|
/**
|
|
3381
|
-
*
|
|
3382
|
-
* `
|
|
3383
|
-
*
|
|
3384
|
-
* tool execution.
|
|
3485
|
+
* Gemini 3 style discrete thinking level (e.g. "low" | "high"). Sent as
|
|
3486
|
+
* `thinkingConfig.thinkingLevel` and replaces the derived `thinkingBudget`
|
|
3487
|
+
* (the API rejects both together). Ignored by other providers.
|
|
3385
3488
|
*/
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
/**
|
|
3390
|
-
|
|
3391
|
-
*
|
|
3392
|
-
* A policy configured as `mode: "enforce"` whose hook is never called is worse
|
|
3393
|
-
* than no policy: the console shows a control that does not exist. A host
|
|
3394
|
-
* cannot infer that from the type surface, because a declared hook and a wired
|
|
3395
|
-
* one look identical to TypeScript — so the runtime states it.
|
|
3396
|
-
*
|
|
3397
|
-
* This table is maintained BY HAND alongside the wiring. That is deliberate:
|
|
3398
|
-
* deriving it from the registry would only prove that a handler was registered,
|
|
3399
|
-
* not that any call site raises it, which is precisely the failure it exists to
|
|
3400
|
-
* make visible.
|
|
3401
|
-
*/
|
|
3402
|
-
|
|
3403
|
-
/**
|
|
3404
|
-
* Bumped when the hook contract changes shape in a way a host must notice —
|
|
3405
|
-
* a hook gains or loses a call site, a payload field changes meaning, a slot
|
|
3406
|
-
* starts or stops being consumed. Independent of the package version.
|
|
3407
|
-
*/
|
|
3408
|
-
declare const HOOK_CONTRACT_VERSION = 1;
|
|
3409
|
-
type CapabilityStatus = {
|
|
3410
|
-
/** True when a call site in the runtime actually raises this. */
|
|
3411
|
-
implemented: boolean;
|
|
3412
|
-
/** Why not, or what the caveat is. */
|
|
3413
|
-
notes?: string;
|
|
3489
|
+
thinkingLevel?: string;
|
|
3490
|
+
/** Whether the provider should expose its reasoning/thought summary to the caller. Gemini: default false. Claude adaptive thinking (5.x): default summarized (`thinking.display = "summarized"`) unless this is `false`; never added when the caller passes an explicit `extra.thinking`. */
|
|
3491
|
+
includeThoughts?: boolean;
|
|
3492
|
+
/** Provider-specific passthrough merged on top of the mapped shape. */
|
|
3493
|
+
providerExtras?: Record<string, any>;
|
|
3414
3494
|
};
|
|
3415
|
-
type
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3495
|
+
type TokenUsage = {
|
|
3496
|
+
inputTokens: number;
|
|
3497
|
+
outputTokens: number;
|
|
3498
|
+
totalTokens: number;
|
|
3499
|
+
cachedInputTokens: number;
|
|
3500
|
+
cachedWriteTokens: number;
|
|
3501
|
+
cachedOutputTokens: number;
|
|
3502
|
+
reasoningTokens: number;
|
|
3420
3503
|
};
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
declare function pluginCapabilities(): SdkCapabilities;
|
|
3441
|
-
/** Convenience for a host that only wants to know whether it can enforce. */
|
|
3442
|
-
declare function isHookImplemented(hook: HookName): boolean;
|
|
3443
|
-
|
|
3444
|
-
/**
|
|
3445
|
-
* Guardrail transport + the plugin that drives it.
|
|
3446
|
-
*
|
|
3447
|
-
* Layered the way tracing sinks are layered — a transport seam, a generic HTTP
|
|
3448
|
-
* implementation, an in-process escape hatch, and thin first-party presets on
|
|
3449
|
-
* top (see `cognipeerGuardrail`, `portkeyGuardrail`). What is deliberately NOT
|
|
3450
|
-
* copied from tracing is its retry policy: a trace post can afford four
|
|
3451
|
-
* attempts at an 8s timeout because nothing waits on it, while a guardrail sits
|
|
3452
|
-
* on the critical path of every turn and the same policy would stall an agent
|
|
3453
|
-
* for half a minute.
|
|
3454
|
-
*/
|
|
3455
|
-
|
|
3456
|
-
/**
|
|
3457
|
-
* `tool` is the ARGUMENTS a model wants to run; `tool_result` is what came
|
|
3458
|
-
* back. They are different surfaces with different risks — one is an action
|
|
3459
|
-
* about to happen, the other is untrusted content entering the context — and a
|
|
3460
|
-
* policy usually wants different rules for each.
|
|
3461
|
-
*/
|
|
3462
|
-
type GuardrailPhaseName = "input" | "output" | "tool" | "tool_result";
|
|
3463
|
-
type GuardrailRequest = {
|
|
3464
|
-
phase: GuardrailPhaseName;
|
|
3465
|
-
content: string;
|
|
3466
|
-
/** Tool name for `tool` / `tool_result`, otherwise unset. */
|
|
3467
|
-
subject?: string;
|
|
3468
|
-
/** The SDK hook this check was raised from, so a preset can map it exactly. */
|
|
3469
|
-
hook?: string;
|
|
3470
|
-
/** Structured tool arguments, for a service that wants them un-stringified. */
|
|
3471
|
-
toolArgs?: unknown;
|
|
3472
|
-
/** The tool's return value, for `tool_result`. */
|
|
3473
|
-
toolResult?: unknown;
|
|
3504
|
+
declare function emptyUsage(): TokenUsage;
|
|
3505
|
+
type FinishReason = "stop" | "tool_calls" | "length" | "content_filter" | "error";
|
|
3506
|
+
type ProviderResponseFields = {
|
|
3507
|
+
system_fingerprint?: string;
|
|
3508
|
+
service_tier?: string;
|
|
3509
|
+
annotations?: any[];
|
|
3510
|
+
refusal?: string | null;
|
|
3511
|
+
logprobs?: any;
|
|
3512
|
+
[key: string]: any;
|
|
3513
|
+
};
|
|
3514
|
+
type ChatCompletionResponse = {
|
|
3515
|
+
id: string;
|
|
3516
|
+
model: string;
|
|
3517
|
+
content: string | null;
|
|
3518
|
+
toolCalls: ToolCall[];
|
|
3519
|
+
usage: TokenUsage;
|
|
3520
|
+
finishReason: FinishReason;
|
|
3521
|
+
/** The provider's own finish/stop reason string, unnormalised (e.g. "end_turn", "function_call"). */
|
|
3522
|
+
rawFinishReason?: string;
|
|
3474
3523
|
/**
|
|
3475
|
-
*
|
|
3476
|
-
*
|
|
3477
|
-
* media needs these; one that does not simply ignores the field.
|
|
3478
|
-
*
|
|
3479
|
-
* Inline payloads are DESCRIBED (kind, media type, size) rather than
|
|
3480
|
-
* inlined: shipping a base64 image on every check would multiply the cost of
|
|
3481
|
-
* the guardrail by the size of the upload. A service that needs the bytes
|
|
3482
|
-
* should take a URL, or the caller should override `buildRequest`.
|
|
3524
|
+
* Provider response fields the unified shape has no slot for, kept when present:
|
|
3525
|
+
* `system_fingerprint`, `service_tier`, `annotations`, `refusal`, `logprobs`.
|
|
3483
3526
|
*/
|
|
3484
|
-
|
|
3485
|
-
|
|
3527
|
+
providerFields?: ProviderResponseFields;
|
|
3528
|
+
/** Native reasoning blocks + summary captured from the response, if any. */
|
|
3529
|
+
reasoning?: ReasoningPayload;
|
|
3530
|
+
raw: any;
|
|
3486
3531
|
};
|
|
3487
|
-
type
|
|
3488
|
-
id
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3532
|
+
type ChatCompletionChunk = {
|
|
3533
|
+
id: string;
|
|
3534
|
+
model: string;
|
|
3535
|
+
delta: {
|
|
3536
|
+
content?: string;
|
|
3537
|
+
toolCalls?: Partial<ToolCall>[];
|
|
3538
|
+
/** Incremental reasoning text / signature deltas (Anthropic thinking). */
|
|
3539
|
+
reasoning?: ReasoningPayload;
|
|
3540
|
+
};
|
|
3541
|
+
usage?: TokenUsage;
|
|
3542
|
+
finishReason?: FinishReason;
|
|
3543
|
+
/** The provider's own finish reason string, unnormalised. Present on the chunk that carries it. */
|
|
3544
|
+
rawFinishReason?: string;
|
|
3545
|
+
/** See ChatCompletionResponse.providerFields; per-chunk (fingerprint, tier, delta refusal/annotations, logprobs). */
|
|
3546
|
+
providerFields?: ProviderResponseFields;
|
|
3547
|
+
};
|
|
3548
|
+
/** Why the text is being embedded; mapped to each provider's own task/input type. */
|
|
3549
|
+
type EmbeddingInputType = "search_document" | "search_query" | "classification" | "clustering" | "semantic_similarity" | "question_answering" | "fact_verification" | "code_retrieval_query" | (string & {});
|
|
3550
|
+
type EmbeddingRequest = {
|
|
3551
|
+
/** Model id (OpenAI/compatible), deployment name (Azure), model id (Bedrock), model name (Vertex). */
|
|
3552
|
+
model: string;
|
|
3553
|
+
/** Texts to embed. One vector per entry, in the same order. */
|
|
3554
|
+
input: string[];
|
|
3555
|
+
/** Requested output dimensions, for models that support shortening (OpenAI v3, Titan v2, Cohere v4, Gemini). */
|
|
3556
|
+
dimensions?: number;
|
|
3557
|
+
/** OpenAI-shaped endpoints: wire encoding. Vectors are always returned as number[] either way. */
|
|
3558
|
+
encodingFormat?: "float" | "base64";
|
|
3559
|
+
/** Task hint (Cohere on Bedrock, Gemini on Vertex). Ignored by providers without one. */
|
|
3560
|
+
inputType?: EmbeddingInputType;
|
|
3561
|
+
/** Max texts per HTTP request. Defaults per provider (OpenAI 2048, Vertex 100, Gemini-embedding 1, Titan 1). */
|
|
3562
|
+
batchSize?: number;
|
|
3563
|
+
/** Provider-specific fields merged into each request body (escape hatch). */
|
|
3564
|
+
extra?: Record<string, any>;
|
|
3565
|
+
signal?: AbortSignal;
|
|
3492
3566
|
};
|
|
3493
|
-
type
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
/** Required when `action === "mask"`. */
|
|
3497
|
-
maskedContent?: string;
|
|
3498
|
-
violations?: GuardrailViolation[];
|
|
3499
|
-
/** The untouched service response, for tracing and debugging. */
|
|
3500
|
-
raw?: unknown;
|
|
3567
|
+
type EmbeddingUsage = {
|
|
3568
|
+
inputTokens: number;
|
|
3569
|
+
totalTokens: number;
|
|
3501
3570
|
};
|
|
3502
|
-
type
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3571
|
+
type EmbeddingResponse = {
|
|
3572
|
+
model: string;
|
|
3573
|
+
/** One vector per input, in input order. */
|
|
3574
|
+
vectors: number[][];
|
|
3575
|
+
usage: EmbeddingUsage;
|
|
3576
|
+
/** Raw provider responses, one per HTTP request made. */
|
|
3577
|
+
raw: any[];
|
|
3508
3578
|
};
|
|
3509
|
-
type
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
describe?: () => MaybePromise<{
|
|
3519
|
-
activePhases?: GuardrailPhaseName[];
|
|
3520
|
-
} | null | undefined>;
|
|
3521
|
-
close?: () => MaybePromise<void>;
|
|
3579
|
+
type ProviderRetryConfig = {
|
|
3580
|
+
/** Maximum retries on 429/5xx (default 3). */
|
|
3581
|
+
maxRetries?: number;
|
|
3582
|
+
/** Initial delay between retries in ms (default 500, doubled each attempt). */
|
|
3583
|
+
baseDelayMs?: number;
|
|
3584
|
+
/** Hard cap on a single retry delay in ms (default 8000). */
|
|
3585
|
+
maxDelayMs?: number;
|
|
3586
|
+
/** Custom predicate to opt in/out of a specific retry. */
|
|
3587
|
+
shouldRetry?: (error: any, attempt: number) => boolean;
|
|
3522
3588
|
};
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
/** Static headers, or a thunk so a rotating token is read per call. */
|
|
3526
|
-
headers?: Record<string, string> | (() => Record<string, string>);
|
|
3527
|
-
/** Hard ceiling per attempt. Default 3000ms — this is on the critical path. */
|
|
3528
|
-
timeoutMs?: number;
|
|
3529
|
-
/** Retries after the first attempt. Default 1. */
|
|
3530
|
-
retries?: number;
|
|
3531
|
-
/** Send all pending checks in one request. Default true. */
|
|
3532
|
-
batch?: boolean;
|
|
3533
|
-
/** Override the wire request. Default: `{ items, runId, traceId }`. */
|
|
3534
|
-
buildRequest?: (requests: GuardrailRequest[], ctx: GuardrailCallContext) => unknown;
|
|
3535
|
-
/** Override response mapping. Default: `normalizeVerdicts`, which is forgiving. */
|
|
3536
|
-
mapVerdict?: (response: unknown, requests: GuardrailRequest[]) => GuardrailVerdict[];
|
|
3589
|
+
/** Transport options shared by every provider config. */
|
|
3590
|
+
type ProviderTransportConfig = {
|
|
3537
3591
|
/**
|
|
3538
|
-
*
|
|
3539
|
-
*
|
|
3540
|
-
*
|
|
3541
|
-
* failureMode path with the wrong reason attached.
|
|
3592
|
+
* Custom `fetch` used at EVERY HTTP call site of the provider (chat, stream,
|
|
3593
|
+
* Responses, token exchange). Lets a host inject an SSRF-safe or proxied
|
|
3594
|
+
* fetch. Defaults to the global `fetch`.
|
|
3542
3595
|
*/
|
|
3543
|
-
|
|
3544
|
-
/** Optional GET endpoint for the setup-time handshake. */
|
|
3545
|
-
describeUrl?: string;
|
|
3546
|
-
name?: string;
|
|
3547
|
-
};
|
|
3548
|
-
/**
|
|
3549
|
-
* Accepts the shapes a guardrail service is likely to return and normalizes
|
|
3550
|
-
* them. Being forgiving here is the point: the exact contract can change on the
|
|
3551
|
-
* service side without a client release, and a stricter parser would turn a
|
|
3552
|
-
* cosmetic field rename into an outage.
|
|
3553
|
-
*/
|
|
3554
|
-
declare function normalizeVerdicts(response: unknown, requests: GuardrailRequest[]): GuardrailVerdict[];
|
|
3555
|
-
declare function httpGuardrail(options: HttpGuardrailOptions): GuardrailTransport;
|
|
3556
|
-
/** In-process evaluation — regex policies, a local model, Presidio, tests. */
|
|
3557
|
-
declare function customGuardrail(evaluate: (request: GuardrailRequest, ctx: GuardrailCallContext) => MaybePromise<GuardrailVerdict | void>, name?: string): GuardrailTransport;
|
|
3558
|
-
type GuardrailPluginOptions = {
|
|
3559
|
-
name: string;
|
|
3560
|
-
transport: GuardrailTransport;
|
|
3561
|
-
/** Which surfaces to check. Default: input + output. */
|
|
3562
|
-
apply?: GuardrailPhaseName[];
|
|
3596
|
+
fetch?: typeof fetch;
|
|
3563
3597
|
/**
|
|
3564
|
-
*
|
|
3565
|
-
*
|
|
3598
|
+
* Per-request timeout in ms, measured until the response headers arrive
|
|
3599
|
+
* (an established stream is not cut by it). Default: none.
|
|
3566
3600
|
*/
|
|
3567
|
-
mode?: "enforce" | "shadow";
|
|
3568
|
-
/** Block when the service is unreachable. Default true. */
|
|
3569
|
-
failClosed?: boolean;
|
|
3570
3601
|
timeoutMs?: number;
|
|
3571
|
-
priority?: number;
|
|
3572
|
-
inheritToSubagents?: boolean;
|
|
3573
|
-
/** Memoize verdicts per run. Default true. */
|
|
3574
|
-
cache?: boolean | {
|
|
3575
|
-
maxEntries?: number;
|
|
3576
|
-
};
|
|
3577
|
-
/** Extra metadata attached to every request. */
|
|
3578
|
-
metadata?: Record<string, unknown>;
|
|
3579
3602
|
};
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
/**
|
|
3583
|
-
* Cognipeer Console guardrail — the first-party preset.
|
|
3584
|
-
*
|
|
3585
|
-
* Talks to the Console's HOOK plane, not its single-shot evaluator:
|
|
3586
|
-
*
|
|
3587
|
-
* POST {baseUrl}/api/client/v1/guardrails/hooks/evaluate
|
|
3588
|
-
* Authorization: Bearer <api key>
|
|
3589
|
-
* { hook, guardrail_keys, text?, tool_name?, tool_args?, tool_result?, … }
|
|
3590
|
-
*
|
|
3591
|
-
* Three properties of that contract shape everything below, and getting any of
|
|
3592
|
-
* them wrong turns a working policy into a silent one:
|
|
3593
|
-
*
|
|
3594
|
-
* `decision` is the EFFECTIVE verdict, already neutralised in monitor mode.
|
|
3595
|
-
* Priority runs block > redact > warn > flag > allow.
|
|
3596
|
-
* `enforced` false means the decision was NOT applied — a dry run. Blocking
|
|
3597
|
-
* on `decision === "block"` without checking this turns every
|
|
3598
|
-
* monitoring policy into an enforcing one on the day it is
|
|
3599
|
-
* switched on for observation.
|
|
3600
|
-
* `passed` means "no blocking finding", NOT "the request was allowed".
|
|
3601
|
-
* The two diverge in monitor mode, which is exactly when someone
|
|
3602
|
-
* reads the wrong one.
|
|
3603
|
-
*
|
|
3604
|
-
* `subject` (or `redacted_text` for the text case) is filled only when the
|
|
3605
|
-
* service actually rewrote something; when it is present it REPLACES what was
|
|
3606
|
-
* sent rather than being merged with it.
|
|
3607
|
-
*
|
|
3608
|
-
* The endpoint answers 200 for a finding as readily as for a clean check, and
|
|
3609
|
-
* only emits 246/446 when a guardrail opts into verdict status codes — so both
|
|
3610
|
-
* are declared as verdict-carrying rather than treated as transport failures.
|
|
3611
|
-
* An unknown key answers 404 ON PURPOSE: a vacuous allow read as "content is
|
|
3612
|
-
* safe" is the failure the whole plane exists to avoid.
|
|
3613
|
-
*/
|
|
3614
|
-
|
|
3615
|
-
type CognipeerGuardrailConfig = {
|
|
3616
|
-
/** Guardrail keys from the Console. Defaults to `COGNIPEER_GUARDRAIL_KEYS` (comma-separated). */
|
|
3617
|
-
guardrailKeys?: string[];
|
|
3618
|
-
/** Convenience for the single-key case. */
|
|
3619
|
-
guardrailKey?: string;
|
|
3620
|
-
/** Defaults to `COGNIPEER_API_KEY`. */
|
|
3621
|
-
apiKey?: string;
|
|
3622
|
-
/** Defaults to `COGNIPEER_BASE_URL`, then the production console. Point at localhost for local runs. */
|
|
3623
|
-
baseUrl?: string;
|
|
3624
|
-
/** Override the hook-evaluate path. */
|
|
3625
|
-
path?: string;
|
|
3626
|
-
/** Surfaces to guard. Default: input + output. Add `"tool"` / `"tool_result"` for the tool surface. */
|
|
3627
|
-
apply?: GuardrailPhaseName[];
|
|
3628
|
-
/** Restrict to specific check families, e.g. `["pii"]`. */
|
|
3629
|
-
only?: string[];
|
|
3630
|
-
/** Override the SDK-hook → Console-hook-id mapping, merged over the default. */
|
|
3631
|
-
hookIds?: Record<string, string>;
|
|
3632
|
-
/** Ask the service to evaluate without enforcing. Independent of `mode`. */
|
|
3633
|
-
shadow?: boolean;
|
|
3634
|
-
/** `shadow` here reports locally without acting, whatever the service says. */
|
|
3635
|
-
mode?: "enforce" | "shadow";
|
|
3636
|
-
/** Default true — an unreachable or misconfigured policy blocks rather than silently stops guarding. */
|
|
3637
|
-
failClosed?: boolean;
|
|
3638
|
-
/** Per-check ceiling. Default 3000ms; also sent as `budget_ms`. */
|
|
3639
|
-
timeoutMs?: number;
|
|
3640
|
-
retries?: number;
|
|
3641
|
-
priority?: number;
|
|
3642
|
-
cache?: boolean | {
|
|
3643
|
-
maxEntries?: number;
|
|
3644
|
-
};
|
|
3645
|
-
metadata?: Record<string, unknown>;
|
|
3646
|
-
buildRequest?: (requests: GuardrailRequest[], ctx: GuardrailCallContext) => unknown;
|
|
3647
|
-
mapVerdict?: (response: unknown, requests: GuardrailRequest[]) => GuardrailVerdict[];
|
|
3648
|
-
name?: string;
|
|
3649
|
-
};
|
|
3650
|
-
/** The Console's hook response, mapped onto the transport's three-valued verdict. */
|
|
3651
|
-
declare function mapConsoleHookVerdict(response: unknown, requests: GuardrailRequest[]): GuardrailVerdict[];
|
|
3652
|
-
declare function cognipeerGuardrail(config?: CognipeerGuardrailConfig): AgentPlugin;
|
|
3653
|
-
|
|
3654
|
-
type MessageRole = "system" | "user" | "assistant" | "tool";
|
|
3655
|
-
type TextContent = {
|
|
3656
|
-
type: "text";
|
|
3657
|
-
text: string;
|
|
3658
|
-
};
|
|
3659
|
-
type ImageContent = {
|
|
3660
|
-
type: "image";
|
|
3661
|
-
source: {
|
|
3662
|
-
type: "base64";
|
|
3663
|
-
mediaType: string;
|
|
3664
|
-
data: string;
|
|
3665
|
-
} | {
|
|
3666
|
-
type: "url";
|
|
3667
|
-
url: string;
|
|
3668
|
-
mediaType?: string;
|
|
3669
|
-
};
|
|
3670
|
-
};
|
|
3671
|
-
/**
|
|
3672
|
-
* A document attachment (PDF, DOCX, CSV, …). Providers map this to their
|
|
3673
|
-
* native document blocks: Gemini `inlineData`/`fileData`, Anthropic
|
|
3674
|
-
* `document`, OpenAI Chat Completions `file` / Responses `input_file`,
|
|
3675
|
-
* Bedrock Converse `document`. Providers without document support degrade
|
|
3676
|
-
* to a text placeholder referencing the file name/URL.
|
|
3677
|
-
*/
|
|
3678
|
-
type FileContent = {
|
|
3679
|
-
type: "file";
|
|
3680
|
-
source: {
|
|
3681
|
-
type: "base64";
|
|
3682
|
-
mediaType: string;
|
|
3683
|
-
data: string;
|
|
3684
|
-
} | {
|
|
3685
|
-
type: "url";
|
|
3686
|
-
url: string;
|
|
3687
|
-
mediaType?: string;
|
|
3688
|
-
};
|
|
3689
|
-
/** Original file name, when known (required by some providers, e.g. Bedrock). */
|
|
3690
|
-
fileName?: string;
|
|
3691
|
-
};
|
|
3692
|
-
/**
|
|
3693
|
-
* An audio attachment. Gemini accepts it as `inlineData`/`fileData`; OpenAI
|
|
3694
|
-
* audio-capable models as `input_audio`. Providers without audio support
|
|
3695
|
-
* degrade to a text placeholder.
|
|
3696
|
-
*/
|
|
3697
|
-
type AudioContent = {
|
|
3698
|
-
type: "audio";
|
|
3699
|
-
source: {
|
|
3700
|
-
type: "base64";
|
|
3701
|
-
mediaType: string;
|
|
3702
|
-
data: string;
|
|
3703
|
-
} | {
|
|
3704
|
-
type: "url";
|
|
3705
|
-
url: string;
|
|
3706
|
-
mediaType?: string;
|
|
3707
|
-
};
|
|
3708
|
-
};
|
|
3709
|
-
type ContentPart = TextContent | ImageContent | FileContent | AudioContent;
|
|
3710
|
-
type ToolCall = {
|
|
3711
|
-
id: string;
|
|
3712
|
-
name: string;
|
|
3713
|
-
arguments: string;
|
|
3714
|
-
};
|
|
3715
|
-
/**
|
|
3716
|
-
* A provider-native reasoning/thinking block. Captured from the model response
|
|
3717
|
-
* and replayed verbatim on subsequent turns (required by Anthropic extended
|
|
3718
|
-
* thinking when tools are involved — the `signature` must round-trip intact).
|
|
3719
|
-
*/
|
|
3720
|
-
type ReasoningBlock = {
|
|
3721
|
-
type: "thinking" | "redacted_thinking";
|
|
3722
|
-
/** Plain-text thinking content (absent for redacted blocks). */
|
|
3723
|
-
text?: string;
|
|
3724
|
-
/** Cryptographic signature Anthropic requires to be echoed back verbatim. */
|
|
3725
|
-
signature?: string;
|
|
3726
|
-
/** Opaque payload for redacted_thinking blocks. */
|
|
3727
|
-
data?: string;
|
|
3728
|
-
};
|
|
3729
|
-
/** Captured reasoning payload attached to assistant turns / responses. */
|
|
3730
|
-
type ReasoningPayload = {
|
|
3731
|
-
/** Verbatim provider blocks to replay on the next turn. */
|
|
3732
|
-
blocks?: ReasoningBlock[];
|
|
3733
|
-
/** Human-readable reasoning summary, when the provider exposes one. */
|
|
3734
|
-
summary?: string;
|
|
3735
|
-
};
|
|
3736
|
-
type UnifiedMessage = {
|
|
3737
|
-
role: MessageRole;
|
|
3738
|
-
content: string | ContentPart[];
|
|
3739
|
-
name?: string;
|
|
3740
|
-
toolCalls?: ToolCall[];
|
|
3741
|
-
toolCallId?: string;
|
|
3742
|
-
/** Native reasoning blocks to replay verbatim (Anthropic/Bedrock thinking). */
|
|
3743
|
-
reasoning?: ReasoningPayload;
|
|
3744
|
-
};
|
|
3745
|
-
type ToolDefinition = {
|
|
3746
|
-
name: string;
|
|
3747
|
-
description: string;
|
|
3748
|
-
parameters: Record<string, any>;
|
|
3749
|
-
strict?: boolean;
|
|
3750
|
-
};
|
|
3751
|
-
type ChatCompletionRequest = {
|
|
3752
|
-
model: string;
|
|
3753
|
-
messages: UnifiedMessage[];
|
|
3754
|
-
temperature?: number;
|
|
3755
|
-
maxTokens?: number;
|
|
3756
|
-
topP?: number;
|
|
3757
|
-
stop?: string[];
|
|
3758
|
-
tools?: ToolDefinition[];
|
|
3759
|
-
toolChoice?: "auto" | "required" | "none" | {
|
|
3760
|
-
name: string;
|
|
3761
|
-
};
|
|
3762
|
-
responseFormat?: {
|
|
3763
|
-
type: "json_schema" | "json_object" | "text";
|
|
3764
|
-
schema?: Record<string, any>;
|
|
3765
|
-
name?: string;
|
|
3766
|
-
};
|
|
3767
|
-
stream?: boolean;
|
|
3768
|
-
extra?: Record<string, any>;
|
|
3603
|
+
type OpenAIProviderConfig = ProviderTransportConfig & {
|
|
3769
3604
|
/**
|
|
3770
|
-
*
|
|
3771
|
-
*
|
|
3772
|
-
*
|
|
3773
|
-
* - OpenAI Responses: body.reasoning = { effort }
|
|
3774
|
-
* - Anthropic: body.thinking = { type: "enabled", budget_tokens }
|
|
3775
|
-
* - Google / Vertex: body.generationConfig.thinkingConfig = { thinkingBudget, includeThoughts }
|
|
3776
|
-
*
|
|
3777
|
-
* Providers silently ignore unsupported fields.
|
|
3605
|
+
* Which token-limit field to send: `max_tokens` or `max_completion_tokens`.
|
|
3606
|
+
* `auto` (default) uses `max_completion_tokens` for o-series / gpt-5 models
|
|
3607
|
+
* and `max_tokens` otherwise.
|
|
3778
3608
|
*/
|
|
3779
|
-
|
|
3780
|
-
};
|
|
3781
|
-
/**
|
|
3782
|
-
* `none` is OFF, and it is a value rather than the absence of one.
|
|
3783
|
-
*
|
|
3784
|
-
* On a thinking-by-default model — every Qwen3 under vLLM, gpt-5.1 and newer on
|
|
3785
|
-
* OpenAI — sending no reasoning field leaves the model thinking. So "do not
|
|
3786
|
-
* think" is an instruction that has to travel: `reasoning_effort:"none"` on
|
|
3787
|
-
* OpenAI, `thinkingBudget:0` on Gemini, and no thinking block at all on
|
|
3788
|
-
* Anthropic (where thinking is opt-in and the absence IS off). Omitting
|
|
3789
|
-
* `effort` still means "say nothing about reasoning", which is the different
|
|
3790
|
-
* and equally necessary state.
|
|
3791
|
-
*/
|
|
3792
|
-
type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high";
|
|
3793
|
-
type ReasoningRequestConfig = {
|
|
3794
|
-
/** Qualitative effort hint (mapped per-provider). */
|
|
3795
|
-
effort?: ReasoningEffort;
|
|
3796
|
-
/** Explicit per-call token budget for reasoning/thinking. */
|
|
3797
|
-
budgetTokens?: number;
|
|
3798
|
-
/** Whether the provider should expose its reasoning/thought summary to the caller. Default false. */
|
|
3799
|
-
includeThoughts?: boolean;
|
|
3800
|
-
/** Provider-specific passthrough merged on top of the mapped shape. */
|
|
3801
|
-
providerExtras?: Record<string, any>;
|
|
3802
|
-
};
|
|
3803
|
-
type TokenUsage = {
|
|
3804
|
-
inputTokens: number;
|
|
3805
|
-
outputTokens: number;
|
|
3806
|
-
totalTokens: number;
|
|
3807
|
-
cachedInputTokens: number;
|
|
3808
|
-
cachedWriteTokens: number;
|
|
3809
|
-
cachedOutputTokens: number;
|
|
3810
|
-
reasoningTokens: number;
|
|
3811
|
-
};
|
|
3812
|
-
declare function emptyUsage(): TokenUsage;
|
|
3813
|
-
type FinishReason = "stop" | "tool_calls" | "length" | "content_filter" | "error";
|
|
3814
|
-
type ChatCompletionResponse = {
|
|
3815
|
-
id: string;
|
|
3816
|
-
model: string;
|
|
3817
|
-
content: string | null;
|
|
3818
|
-
toolCalls: ToolCall[];
|
|
3819
|
-
usage: TokenUsage;
|
|
3820
|
-
finishReason: FinishReason;
|
|
3821
|
-
/** Native reasoning blocks + summary captured from the response, if any. */
|
|
3822
|
-
reasoning?: ReasoningPayload;
|
|
3823
|
-
raw: any;
|
|
3824
|
-
};
|
|
3825
|
-
type ChatCompletionChunk = {
|
|
3826
|
-
id: string;
|
|
3827
|
-
model: string;
|
|
3828
|
-
delta: {
|
|
3829
|
-
content?: string;
|
|
3830
|
-
toolCalls?: Partial<ToolCall>[];
|
|
3831
|
-
/** Incremental reasoning text / signature deltas (Anthropic thinking). */
|
|
3832
|
-
reasoning?: ReasoningPayload;
|
|
3833
|
-
};
|
|
3834
|
-
usage?: TokenUsage;
|
|
3835
|
-
finishReason?: FinishReason;
|
|
3836
|
-
};
|
|
3837
|
-
type ProviderRetryConfig = {
|
|
3838
|
-
/** Maximum retries on 429/5xx (default 3). */
|
|
3839
|
-
maxRetries?: number;
|
|
3840
|
-
/** Initial delay between retries in ms (default 500, doubled each attempt). */
|
|
3841
|
-
baseDelayMs?: number;
|
|
3842
|
-
/** Hard cap on a single retry delay in ms (default 8000). */
|
|
3843
|
-
maxDelayMs?: number;
|
|
3844
|
-
/** Custom predicate to opt in/out of a specific retry. */
|
|
3845
|
-
shouldRetry?: (error: any, attempt: number) => boolean;
|
|
3846
|
-
};
|
|
3847
|
-
type OpenAIProviderConfig = {
|
|
3609
|
+
maxTokensParam?: "auto" | "max_tokens" | "max_completion_tokens";
|
|
3848
3610
|
provider: "openai";
|
|
3849
3611
|
apiKey: string;
|
|
3850
3612
|
baseURL?: string;
|
|
@@ -3853,9 +3615,13 @@ type OpenAIProviderConfig = {
|
|
|
3853
3615
|
defaultHeaders?: Record<string, string>;
|
|
3854
3616
|
retry?: ProviderRetryConfig;
|
|
3855
3617
|
/**
|
|
3618
|
+
* @deprecated Use `api: "chat" | "responses" | "auto"`. Kept as an alias:
|
|
3619
|
+
* `never` = chat, `always` = responses, `auto` = the name-based heuristic.
|
|
3620
|
+
* When `api` is also set, `api` wins.
|
|
3621
|
+
*
|
|
3856
3622
|
* WHICH API a reasoning-carrying request is addressed to.
|
|
3857
3623
|
*
|
|
3858
|
-
* auto (default
|
|
3624
|
+
* auto (the default for OpenAI and Azure) route to the Responses API when
|
|
3859
3625
|
* the request carries `reasoning` AND the model name looks like an
|
|
3860
3626
|
* o-series/gpt-5 reasoning model.
|
|
3861
3627
|
* never always Chat Completions. `reasoning` is still mapped, as
|
|
@@ -3874,9 +3640,25 @@ type OpenAIProviderConfig = {
|
|
|
3874
3640
|
* where it matters most: a self-hosted model is named by whoever served it.
|
|
3875
3641
|
*/
|
|
3876
3642
|
responsesApi?: "auto" | "never" | "always";
|
|
3643
|
+
/** @internal Set by OpenAICompatibleProvider: `auto` then means Chat Completions. */
|
|
3644
|
+
_autoMeansChat?: boolean;
|
|
3645
|
+
/**
|
|
3646
|
+
* Which upstream API requests are sent to. `"auto"` (default) keeps the
|
|
3647
|
+
* 0.11 behaviour of each class: OpenAI and Azure use Responses when the
|
|
3648
|
+
* request carries `reasoning` and the model name looks like an o-series /
|
|
3649
|
+
* gpt-5 model, otherwise Chat Completions; OpenAI-compatible always uses
|
|
3650
|
+
* Chat Completions (the model name is the server operator's). `"chat"` always
|
|
3651
|
+
* sends Chat Completions. `"responses"`
|
|
3652
|
+
* sends every request to the Responses API (`POST /responses`) and streams it
|
|
3653
|
+
* over real SSE (text, tool-call arguments and reasoning-summary deltas;
|
|
3654
|
+
* set `responsesStreaming: false` to get one non-streaming call instead).
|
|
3655
|
+
* Works on `OpenAIProvider`, `AzureProvider` and `OpenAICompatibleProvider`.
|
|
3656
|
+
* When set, it wins over the deprecated `responsesApi`.
|
|
3657
|
+
*/
|
|
3658
|
+
api?: "chat" | "responses" | "auto";
|
|
3877
3659
|
/**
|
|
3878
3660
|
* Models that go to the Responses API, named explicitly. Opt-in; unset by
|
|
3879
|
-
* default
|
|
3661
|
+
* default.
|
|
3880
3662
|
*
|
|
3881
3663
|
* A string matches the request's model (or `defaultModel`) exactly; a RegExp
|
|
3882
3664
|
* is tested against it. A match routes the request to Responses whether or
|
|
@@ -3894,86 +3676,654 @@ type OpenAIProviderConfig = {
|
|
|
3894
3676
|
* `stream_options.include_usage` dropped.
|
|
3895
3677
|
* - real SSE streaming, when `responsesStreaming` is also true.
|
|
3896
3678
|
*
|
|
3897
|
-
* Honoured by `OpenAIProvider
|
|
3898
|
-
* `OpenAICompatibleProvider`
|
|
3679
|
+
* Honoured by `OpenAIProvider`, `AzureProvider` and
|
|
3680
|
+
* `OpenAICompatibleProvider` alike.
|
|
3899
3681
|
*/
|
|
3900
3682
|
responsesApiModels?: Array<string | RegExp>;
|
|
3901
3683
|
/**
|
|
3902
|
-
* Stream Responses API output as it arrives (text
|
|
3903
|
-
* deltas) for
|
|
3904
|
-
*
|
|
3905
|
-
*
|
|
3684
|
+
* Stream Responses API output as it arrives (text, tool-call argument and
|
|
3685
|
+
* reasoning-summary deltas) for `api: "responses"` and for models in
|
|
3686
|
+
* `responsesApiModels`. Default true with `api: "responses"`, false
|
|
3687
|
+
* otherwise (one non-streaming Responses call emitted as a single chunk).
|
|
3688
|
+
* Has no effect on Chat Completions requests.
|
|
3689
|
+
*/
|
|
3690
|
+
responsesStreaming?: boolean;
|
|
3691
|
+
};
|
|
3692
|
+
type AnthropicProviderConfig = ProviderTransportConfig & {
|
|
3693
|
+
provider: "anthropic";
|
|
3694
|
+
apiKey: string;
|
|
3695
|
+
baseURL?: string;
|
|
3696
|
+
defaultModel?: string;
|
|
3697
|
+
defaultHeaders?: Record<string, string>;
|
|
3698
|
+
anthropicVersion?: string;
|
|
3699
|
+
retry?: ProviderRetryConfig;
|
|
3700
|
+
/**
|
|
3701
|
+
* Prompt caching configuration. When enabled, places cache_control:
|
|
3702
|
+
* ephemeral breakpoints on the system prompt and the final tool definition,
|
|
3703
|
+
* which is the recommended Anthropic recipe for static system + tools.
|
|
3704
|
+
*/
|
|
3705
|
+
prompt_caching?: {
|
|
3706
|
+
enabled: boolean;
|
|
3707
|
+
};
|
|
3708
|
+
/**
|
|
3709
|
+
* Thinking request shape. `auto` (default) picks per model id: Claude 5.x
|
|
3710
|
+
* and newer use `thinking:{type:"adaptive"}` + `output_config.effort`, older
|
|
3711
|
+
* models use `thinking:{type:"enabled", budget_tokens}`. Force one with
|
|
3712
|
+
* `adaptive` / `budget`. On the specific 400 for the wrong shape the
|
|
3713
|
+
* provider retries once with the other form.
|
|
3714
|
+
*/
|
|
3715
|
+
thinkingMode?: "auto" | "adaptive" | "budget";
|
|
3716
|
+
};
|
|
3717
|
+
type AzureProviderConfig = ProviderTransportConfig & {
|
|
3718
|
+
provider: "azure";
|
|
3719
|
+
retry?: ProviderRetryConfig;
|
|
3720
|
+
/** See OpenAIProviderConfig.maxTokensParam. */
|
|
3721
|
+
maxTokensParam?: "auto" | "max_tokens" | "max_completion_tokens";
|
|
3722
|
+
apiKey: string;
|
|
3723
|
+
endpoint: string;
|
|
3724
|
+
apiVersion?: string;
|
|
3725
|
+
deploymentName?: string;
|
|
3726
|
+
defaultModel?: string;
|
|
3727
|
+
defaultHeaders?: Record<string, string>;
|
|
3728
|
+
/** See OpenAIProviderConfig.api. Default "auto". */
|
|
3729
|
+
api?: "chat" | "responses" | "auto";
|
|
3730
|
+
/** @deprecated Use `api`. */
|
|
3731
|
+
responsesApi?: "auto" | "never" | "always";
|
|
3732
|
+
responsesApiModels?: Array<string | RegExp>;
|
|
3733
|
+
responsesStreaming?: boolean;
|
|
3734
|
+
};
|
|
3735
|
+
type OpenAICompatibleProviderConfig = ProviderTransportConfig & {
|
|
3736
|
+
provider: "openai-compatible";
|
|
3737
|
+
organization?: string;
|
|
3738
|
+
retry?: ProviderRetryConfig;
|
|
3739
|
+
/** @deprecated Use `api`. Default: see `api`. */
|
|
3740
|
+
responsesApi?: "auto" | "never" | "always";
|
|
3741
|
+
/** See OpenAIProviderConfig.api. Default "auto". */
|
|
3742
|
+
api?: "chat" | "responses" | "auto";
|
|
3743
|
+
responsesApiModels?: Array<string | RegExp>;
|
|
3744
|
+
responsesStreaming?: boolean;
|
|
3745
|
+
/** See OpenAIProviderConfig.maxTokensParam. Compatible servers default to `auto`. */
|
|
3746
|
+
maxTokensParam?: "auto" | "max_tokens" | "max_completion_tokens";
|
|
3747
|
+
apiKey: string;
|
|
3748
|
+
baseURL: string;
|
|
3749
|
+
defaultModel?: string;
|
|
3750
|
+
defaultHeaders?: Record<string, string>;
|
|
3751
|
+
};
|
|
3752
|
+
type BedrockProviderConfig = ProviderTransportConfig & {
|
|
3753
|
+
provider: "bedrock";
|
|
3754
|
+
region: string;
|
|
3755
|
+
/** Thinking request shape for Claude models: `auto` (by model id), `adaptive` or `budget`. */
|
|
3756
|
+
thinkingMode?: "auto" | "adaptive" | "budget";
|
|
3757
|
+
accessKeyId?: string;
|
|
3758
|
+
secretAccessKey?: string;
|
|
3759
|
+
sessionToken?: string;
|
|
3760
|
+
defaultModel?: string;
|
|
3761
|
+
defaultHeaders?: Record<string, string>;
|
|
3762
|
+
retry?: ProviderRetryConfig;
|
|
3763
|
+
/**
|
|
3764
|
+
* Insert Bedrock Converse `cachePoint` blocks at the end of the system
|
|
3765
|
+
* prompt and tools list. Only supported by models that implement Converse
|
|
3766
|
+
* prompt caching (most Anthropic Claude variants on Bedrock).
|
|
3767
|
+
*/
|
|
3768
|
+
prompt_caching?: {
|
|
3769
|
+
enabled: boolean;
|
|
3770
|
+
};
|
|
3771
|
+
};
|
|
3772
|
+
type VertexProviderConfig = ProviderTransportConfig & {
|
|
3773
|
+
provider: "vertex";
|
|
3774
|
+
projectId: string;
|
|
3775
|
+
location?: string;
|
|
3776
|
+
accessToken?: string;
|
|
3777
|
+
serviceAccountJson?: string | Record<string, any>;
|
|
3778
|
+
defaultModel?: string;
|
|
3779
|
+
defaultHeaders?: Record<string, string>;
|
|
3780
|
+
/** Retry policy for 429/5xx (default 3 retries, exponential backoff). */
|
|
3781
|
+
retry?: ProviderRetryConfig;
|
|
3782
|
+
};
|
|
3783
|
+
type JevProviderConfig = ProviderTransportConfig & {
|
|
3784
|
+
provider: "jev";
|
|
3785
|
+
apiKey: string;
|
|
3786
|
+
/** Defaults to https://api.typesafe.ai. */
|
|
3787
|
+
baseURL?: string;
|
|
3788
|
+
defaultModel?: string;
|
|
3789
|
+
defaultHeaders?: Record<string, string>;
|
|
3790
|
+
retry?: ProviderRetryConfig;
|
|
3791
|
+
};
|
|
3792
|
+
type ProviderConfig = OpenAIProviderConfig | AnthropicProviderConfig | AzureProviderConfig | OpenAICompatibleProviderConfig | BedrockProviderConfig | VertexProviderConfig | JevProviderConfig;
|
|
3793
|
+
type ProviderType = ProviderConfig["provider"];
|
|
3794
|
+
declare class ProviderError extends Error {
|
|
3795
|
+
readonly provider: string;
|
|
3796
|
+
readonly statusCode?: number | undefined;
|
|
3797
|
+
readonly responseBody?: any | undefined;
|
|
3798
|
+
constructor(message: string, provider: string, statusCode?: number | undefined, responseBody?: any | undefined);
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3801
|
+
type ProviderRetryPolicy = {
|
|
3802
|
+
/** Maximum number of retries on 429/5xx responses. Default: 3. */
|
|
3803
|
+
maxRetries?: number;
|
|
3804
|
+
/** Initial backoff in ms (doubled on each retry). Default: 500. */
|
|
3805
|
+
baseDelayMs?: number;
|
|
3806
|
+
/** Hard cap on individual delay between retries. Default: 8000. */
|
|
3807
|
+
maxDelayMs?: number;
|
|
3808
|
+
/**
|
|
3809
|
+
* Custom predicate to decide whether to retry. By default we retry 429
|
|
3810
|
+
* and 5xx responses; pass a function to broaden/narrow that set.
|
|
3811
|
+
*/
|
|
3812
|
+
shouldRetry?: (error: any, attempt: number) => boolean;
|
|
3813
|
+
};
|
|
3814
|
+
declare abstract class BaseProvider {
|
|
3815
|
+
abstract readonly providerName: ProviderType;
|
|
3816
|
+
protected retryPolicy: ProviderRetryPolicy;
|
|
3817
|
+
/** Injected `fetch` (config.fetch); falls back to the global one at call time. */
|
|
3818
|
+
protected fetchImpl?: typeof fetch;
|
|
3819
|
+
/** Per-request timeout in ms (config.timeoutMs). Undefined = no timeout. */
|
|
3820
|
+
protected timeoutMs?: number;
|
|
3821
|
+
/** Applies the transport options shared by every provider config. */
|
|
3822
|
+
protected configureTransport(config: {
|
|
3823
|
+
fetch?: typeof fetch;
|
|
3824
|
+
timeoutMs?: number;
|
|
3825
|
+
}): void;
|
|
3826
|
+
/**
|
|
3827
|
+
* The single HTTP entry point for every provider call site. Uses the
|
|
3828
|
+
* configured `fetch` and applies `timeoutMs`: the timer covers the time until
|
|
3829
|
+
* the response HEADERS arrive and is cleared after that, so a long-running
|
|
3830
|
+
* stream is never cut by it (use the request `signal` to cancel a stream).
|
|
3831
|
+
* A timeout surfaces as a `ProviderError` with status 408. The caller's
|
|
3832
|
+
* `signal` still aborts the request as before.
|
|
3833
|
+
*/
|
|
3834
|
+
protected httpFetch(url: string, init?: RequestInit): Promise<Response>;
|
|
3835
|
+
/**
|
|
3836
|
+
* Embeds `request.input`. Implemented by the providers that have an
|
|
3837
|
+
* embeddings endpoint (OpenAI, Azure, openai-compatible, Bedrock, Vertex);
|
|
3838
|
+
* the others reject with a 400 ProviderError.
|
|
3839
|
+
*/
|
|
3840
|
+
embed(_request: EmbeddingRequest): Promise<EmbeddingResponse>;
|
|
3841
|
+
/** Non-streaming completion */
|
|
3842
|
+
abstract complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
3843
|
+
/** Streaming completion – yields incremental chunks */
|
|
3844
|
+
abstract completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
3845
|
+
/**
|
|
3846
|
+
* Helper concrete providers can wrap their fetch with. Retries 429/5xx
|
|
3847
|
+
* with exponential backoff and respects Retry-After if the response
|
|
3848
|
+
* carries one.
|
|
3849
|
+
*
|
|
3850
|
+
* `signal` is the call's cancellation: a run that is cancelled while the
|
|
3851
|
+
* provider is backing off must not sit out the delay, nor start another attempt.
|
|
3852
|
+
*/
|
|
3853
|
+
protected doFetchWithRetry(execute: () => Promise<Response>, signal?: AbortSignal): Promise<Response>;
|
|
3854
|
+
}
|
|
3855
|
+
|
|
3856
|
+
/** A System One question. `noul` asks for the probability of a "yes". */
|
|
3857
|
+
type JevQuestion = {
|
|
3858
|
+
type: "noul" | "choice" | "score";
|
|
3859
|
+
instructions?: string;
|
|
3860
|
+
criteria?: unknown;
|
|
3861
|
+
};
|
|
3862
|
+
type JevSystemOneRequest = {
|
|
3863
|
+
/** The text the questions are asked about. */
|
|
3864
|
+
state: string;
|
|
3865
|
+
questions: Record<string, JevQuestion>;
|
|
3866
|
+
/** Overrides the provider's `defaultModel` for this call. */
|
|
3867
|
+
model?: string;
|
|
3868
|
+
};
|
|
3869
|
+
type JevSystemOneResult = {
|
|
3870
|
+
readonly model?: string;
|
|
3871
|
+
readonly answers?: Record<string, {
|
|
3872
|
+
readonly type: string;
|
|
3873
|
+
readonly noul?: number;
|
|
3874
|
+
readonly [k: string]: unknown;
|
|
3875
|
+
} | undefined>;
|
|
3876
|
+
readonly usage?: {
|
|
3877
|
+
readonly input_tokens: number;
|
|
3878
|
+
readonly output_tokens: number;
|
|
3879
|
+
};
|
|
3880
|
+
};
|
|
3881
|
+
declare class JevProvider extends BaseProvider {
|
|
3882
|
+
readonly providerName: ProviderType;
|
|
3883
|
+
private readonly apiKey;
|
|
3884
|
+
private readonly baseURL;
|
|
3885
|
+
private readonly defaultModel?;
|
|
3886
|
+
private readonly defaultHeaders;
|
|
3887
|
+
constructor(config: JevProviderConfig);
|
|
3888
|
+
/** Ask System One questions about `state`. */
|
|
3889
|
+
systemOne(request: JevSystemOneRequest, options?: {
|
|
3890
|
+
signal?: AbortSignal;
|
|
3891
|
+
}): Promise<JevSystemOneResult>;
|
|
3892
|
+
complete(_request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
3893
|
+
completeStream(_request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
3894
|
+
}
|
|
3895
|
+
|
|
3896
|
+
type RegexRuleOptions = {
|
|
3897
|
+
id?: string;
|
|
3898
|
+
title?: string;
|
|
3899
|
+
description?: string;
|
|
3900
|
+
pattern: RegExp | string;
|
|
3901
|
+
flags?: string;
|
|
3902
|
+
matchDisposition?: GuardrailDisposition;
|
|
3903
|
+
selector?: (context: GuardrailContext) => string;
|
|
3904
|
+
allowIfMatch?: boolean;
|
|
3905
|
+
failureMessage?: string;
|
|
3906
|
+
};
|
|
3907
|
+
declare function regexRule(options: RegexRuleOptions): GuardrailRule;
|
|
3908
|
+
type JsonSchemaRuleOptions = {
|
|
3909
|
+
id?: string;
|
|
3910
|
+
title?: string;
|
|
3911
|
+
description?: string;
|
|
3912
|
+
schema: JSONSchema7 | z.ZodTypeAny;
|
|
3913
|
+
selector?: (context: GuardrailContext) => string;
|
|
3914
|
+
disposition?: GuardrailDisposition;
|
|
3915
|
+
allowOnParseError?: boolean;
|
|
3916
|
+
};
|
|
3917
|
+
declare function jsonSchemaRule(options: JsonSchemaRuleOptions): GuardrailRule;
|
|
3918
|
+
type CodeDetectionRuleOptions = {
|
|
3919
|
+
id?: string;
|
|
3920
|
+
title?: string;
|
|
3921
|
+
description?: string;
|
|
3922
|
+
selector?: (context: GuardrailContext) => string;
|
|
3923
|
+
disposition?: GuardrailDisposition;
|
|
3924
|
+
allowList?: Array<RegExp | string>;
|
|
3925
|
+
};
|
|
3926
|
+
declare function codePresenceRule(options?: CodeDetectionRuleOptions): GuardrailRule;
|
|
3927
|
+
declare const guardianSchema: z.ZodObject<{
|
|
3928
|
+
allow: z.ZodBoolean;
|
|
3929
|
+
disposition: z.ZodOptional<z.ZodEnum<["allow", "warn", "block"]>>;
|
|
3930
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
3931
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
3932
|
+
}, "strip", z.ZodTypeAny, {
|
|
3933
|
+
allow: boolean;
|
|
3934
|
+
reason?: string | undefined;
|
|
3935
|
+
disposition?: "allow" | "block" | "warn" | undefined;
|
|
3936
|
+
details?: Record<string, any> | undefined;
|
|
3937
|
+
}, {
|
|
3938
|
+
allow: boolean;
|
|
3939
|
+
reason?: string | undefined;
|
|
3940
|
+
disposition?: "allow" | "block" | "warn" | undefined;
|
|
3941
|
+
details?: Record<string, any> | undefined;
|
|
3942
|
+
}>;
|
|
3943
|
+
/** Which judge backend `agentVerdictRule` uses to produce its verdict. */
|
|
3944
|
+
type GuardrailJudgeEngine = "llm" | "jev";
|
|
3945
|
+
/** Jev answer for a `noul` (yes/no probability) question. */
|
|
3946
|
+
type JevNoulAnswer = {
|
|
3947
|
+
readonly type: "noul";
|
|
3948
|
+
/** Probability of a "yes", from zero to one. */
|
|
3949
|
+
readonly noul: number;
|
|
3950
|
+
};
|
|
3951
|
+
/**
|
|
3952
|
+
* Anything with the provider's `systemOne` method: a `JevProvider`, or a stub in tests.
|
|
3953
|
+
*/
|
|
3954
|
+
type JevClientLike = Pick<JevProvider, "systemOne">;
|
|
3955
|
+
type JevEngineOptions = {
|
|
3956
|
+
/** Pre-built `JevProvider` (or compatible stub). When set, `apiKey`/`baseURL`/`model` are ignored. */
|
|
3957
|
+
client?: JevClientLike;
|
|
3958
|
+
/** API key for the `JevProvider` built on first use; falls back to `TYPESAFE_API_KEY`. */
|
|
3959
|
+
apiKey?: string;
|
|
3960
|
+
/** API root; falls back to `TYPESAFE_BASE_URL`, then the provider default. */
|
|
3961
|
+
baseURL?: string;
|
|
3962
|
+
/** Model override, per call. */
|
|
3963
|
+
model?: string;
|
|
3964
|
+
/** Risk probability at or above which the message fails the rule. Defaults to 0.5. */
|
|
3965
|
+
threshold?: number;
|
|
3966
|
+
/** Customizes the `noul` question instructions, mirroring `payloadBuilder`. */
|
|
3967
|
+
question?: (context: GuardrailContext) => string;
|
|
3968
|
+
/** Optional descriptions of the yes/no outcomes passed to the `noul` question. */
|
|
3969
|
+
criteria?: {
|
|
3970
|
+
true?: string;
|
|
3971
|
+
false?: string;
|
|
3972
|
+
};
|
|
3973
|
+
};
|
|
3974
|
+
type AgentRuleOptions = {
|
|
3975
|
+
id?: string;
|
|
3976
|
+
title?: string;
|
|
3977
|
+
description?: string;
|
|
3978
|
+
/** Guardian agent. Required for the default `"llm"` engine; unused by `"jev"`. */
|
|
3979
|
+
agent?: SmartAgentInstance<z.infer<typeof guardianSchema>>;
|
|
3980
|
+
systemPrompt?: string;
|
|
3981
|
+
payloadBuilder?: (context: GuardrailContext) => string;
|
|
3982
|
+
dispositionFallback?: GuardrailDisposition;
|
|
3983
|
+
/** Judge backend. Defaults to `"llm"` for full backward compatibility. */
|
|
3984
|
+
engine?: GuardrailJudgeEngine;
|
|
3985
|
+
/** Configuration for the `"jev"` engine. Ignored by the `"llm"` engine. */
|
|
3986
|
+
jev?: JevEngineOptions;
|
|
3987
|
+
};
|
|
3988
|
+
declare function agentVerdictRule(options: AgentRuleOptions): GuardrailRule;
|
|
3989
|
+
type CustomRuleCallback = (context: GuardrailContext) => boolean | {
|
|
3990
|
+
allow: boolean;
|
|
3991
|
+
reason?: string;
|
|
3992
|
+
disposition?: GuardrailDisposition;
|
|
3993
|
+
details?: Record<string, any>;
|
|
3994
|
+
} | Promise<boolean | {
|
|
3995
|
+
allow: boolean;
|
|
3996
|
+
reason?: string;
|
|
3997
|
+
disposition?: GuardrailDisposition;
|
|
3998
|
+
details?: Record<string, any>;
|
|
3999
|
+
}>;
|
|
4000
|
+
type CustomRuleOptions = {
|
|
4001
|
+
id?: string;
|
|
4002
|
+
title?: string;
|
|
4003
|
+
description?: string;
|
|
4004
|
+
callback: CustomRuleCallback;
|
|
4005
|
+
defaultDisposition?: GuardrailDisposition;
|
|
4006
|
+
};
|
|
4007
|
+
declare function customCallbackRule(options: CustomRuleOptions): GuardrailRule;
|
|
4008
|
+
|
|
4009
|
+
type GuardrailPresetBase = {
|
|
4010
|
+
guardrailId?: string;
|
|
4011
|
+
guardrailTitle?: string;
|
|
4012
|
+
guardrailDescription?: string;
|
|
4013
|
+
phases?: GuardrailPhase[];
|
|
4014
|
+
haltOnViolation?: boolean;
|
|
4015
|
+
onViolation?: ConversationGuardrail["onViolation"];
|
|
4016
|
+
metadata?: Record<string, any>;
|
|
4017
|
+
};
|
|
4018
|
+
type RegexGuardrailOptions = GuardrailPresetBase & {
|
|
4019
|
+
rule?: Omit<RegexRuleOptions, "pattern">;
|
|
4020
|
+
};
|
|
4021
|
+
declare function createRegexGuardrail(pattern: RegExp | string, options?: RegexGuardrailOptions): ConversationGuardrail;
|
|
4022
|
+
type JsonGuardrailOptions = GuardrailPresetBase & {
|
|
4023
|
+
rule?: Omit<JsonSchemaRuleOptions, "schema">;
|
|
4024
|
+
};
|
|
4025
|
+
declare function createJsonGuardrail(schema: JsonSchemaRuleOptions["schema"], options?: JsonGuardrailOptions): ConversationGuardrail;
|
|
4026
|
+
type CodeGuardrailOptions = GuardrailPresetBase & {
|
|
4027
|
+
rule?: CodeDetectionRuleOptions;
|
|
4028
|
+
};
|
|
4029
|
+
declare function createCodeGuardrail(options?: CodeGuardrailOptions): ConversationGuardrail;
|
|
4030
|
+
|
|
4031
|
+
/**
|
|
4032
|
+
* Wrap a plugin factory so config flows through with full inference:
|
|
4033
|
+
*
|
|
4034
|
+
* const myGuard = definePlugin<{ level: number }>((cfg) => ({ name: "my-guard", ... }));
|
|
4035
|
+
* myGuard({ level: 2 })
|
|
4036
|
+
*
|
|
4037
|
+
* The indirection buys nothing at runtime — it exists so the config type is
|
|
4038
|
+
* inferred at the call site and the returned object is checked against
|
|
4039
|
+
* `AgentPlugin` at the definition site, where the error message is useful.
|
|
4040
|
+
*/
|
|
4041
|
+
declare function definePlugin<TConfig = void>(factory: (config: TConfig) => AgentPlugin): (config: TConfig) => AgentPlugin;
|
|
4042
|
+
/**
|
|
4043
|
+
* A single hook, packaged as a plugin. For the common case where naming and a
|
|
4044
|
+
* lifecycle would be ceremony:
|
|
4045
|
+
*
|
|
4046
|
+
* defineHook("preToolUse", ({ toolName }) => toolName === "shell" ? { decision: "ask" } : undefined)
|
|
4047
|
+
*/
|
|
4048
|
+
declare function defineHook<K extends HookName>(hook: K, handler: HookHandler<K>, opts?: {
|
|
4049
|
+
name?: string;
|
|
4050
|
+
priority?: number;
|
|
4051
|
+
failureMode?: PluginFailureMode;
|
|
4052
|
+
timeoutMs?: number;
|
|
4053
|
+
inheritToSubagents?: boolean;
|
|
4054
|
+
/**
|
|
4055
|
+
* Declare that this hook never returns `decision: "ask"`. Without it a
|
|
4056
|
+
* `preToolUse` hook is assumed to be able to pause, and the whole tool
|
|
4057
|
+
* batch is scheduled serially — silently costing an agent its parallel
|
|
4058
|
+
* tool execution.
|
|
4059
|
+
*/
|
|
4060
|
+
mayRequireApproval?: boolean;
|
|
4061
|
+
}): AgentPlugin;
|
|
4062
|
+
|
|
4063
|
+
/**
|
|
4064
|
+
* What this build actually implements.
|
|
4065
|
+
*
|
|
4066
|
+
* A policy configured as `mode: "enforce"` whose hook is never called is worse
|
|
4067
|
+
* than no policy: the console shows a control that does not exist. A host
|
|
4068
|
+
* cannot infer that from the type surface, because a declared hook and a wired
|
|
4069
|
+
* one look identical to TypeScript — so the runtime states it.
|
|
4070
|
+
*
|
|
4071
|
+
* This table is maintained BY HAND alongside the wiring. That is deliberate:
|
|
4072
|
+
* deriving it from the registry would only prove that a handler was registered,
|
|
4073
|
+
* not that any call site raises it, which is precisely the failure it exists to
|
|
4074
|
+
* make visible.
|
|
4075
|
+
*/
|
|
4076
|
+
|
|
4077
|
+
/**
|
|
4078
|
+
* Bumped when the hook contract changes shape in a way a host must notice —
|
|
4079
|
+
* a hook gains or loses a call site, a payload field changes meaning, a slot
|
|
4080
|
+
* starts or stops being consumed. Independent of the package version.
|
|
4081
|
+
*/
|
|
4082
|
+
declare const HOOK_CONTRACT_VERSION = 1;
|
|
4083
|
+
type CapabilityStatus = {
|
|
4084
|
+
/** True when a call site in the runtime actually raises this. */
|
|
4085
|
+
implemented: boolean;
|
|
4086
|
+
/** Why not, or what the caveat is. */
|
|
4087
|
+
notes?: string;
|
|
4088
|
+
};
|
|
4089
|
+
type SdkCapabilities = {
|
|
4090
|
+
hookContractVersion: number;
|
|
4091
|
+
hooks: Record<HookName, CapabilityStatus>;
|
|
4092
|
+
slots: Record<SlotName, CapabilityStatus>;
|
|
4093
|
+
features: Record<string, CapabilityStatus>;
|
|
4094
|
+
};
|
|
4095
|
+
/**
|
|
4096
|
+
* Hook ids used by the Cognipeer Console's guardrail plane, mapped onto this
|
|
4097
|
+
* SDK's hooks.
|
|
4098
|
+
*
|
|
4099
|
+
* The Console plane originally had one input stage, which collapsed two
|
|
4100
|
+
* moments that behave differently: `userPromptSubmit` fires ONCE for a new
|
|
4101
|
+
* user turn and can see attachments, while `preModelCall` fires before EVERY
|
|
4102
|
+
* provider call — which is where the legacy `GuardrailPhase.Request` actually
|
|
4103
|
+
* ran. A policy meant to vet what a person typed wants the first; one meant to
|
|
4104
|
+
* vet every prompt reaching the model, including turns built from tool output,
|
|
4105
|
+
* wants the second. Mapping both to one id silently changes how often the
|
|
4106
|
+
* policy runs, and on a moderation-model guardrail that is a cost as well as a
|
|
4107
|
+
* semantics bug.
|
|
4108
|
+
*
|
|
4109
|
+
* The Console added `prompt.pre` for the first and kept `input.pre` meaning
|
|
4110
|
+
* the second, so every id below is single-valued.
|
|
4111
|
+
*/
|
|
4112
|
+
declare const CONSOLE_HOOK_MAP: Readonly<Record<string, HookName | null>>;
|
|
4113
|
+
/** What this build implements. Safe to call at any time; allocates a fresh copy. */
|
|
4114
|
+
declare function pluginCapabilities(): SdkCapabilities;
|
|
4115
|
+
/** Convenience for a host that only wants to know whether it can enforce. */
|
|
4116
|
+
declare function isHookImplemented(hook: HookName): boolean;
|
|
4117
|
+
|
|
4118
|
+
/**
|
|
4119
|
+
* Guardrail transport + the plugin that drives it.
|
|
4120
|
+
*
|
|
4121
|
+
* Layered the way tracing sinks are layered — a transport seam, a generic HTTP
|
|
4122
|
+
* implementation, an in-process escape hatch, and thin first-party presets on
|
|
4123
|
+
* top (see `cognipeerGuardrail`, `portkeyGuardrail`). What is deliberately NOT
|
|
4124
|
+
* copied from tracing is its retry policy: a trace post can afford four
|
|
4125
|
+
* attempts at an 8s timeout because nothing waits on it, while a guardrail sits
|
|
4126
|
+
* on the critical path of every turn and the same policy would stall an agent
|
|
4127
|
+
* for half a minute.
|
|
4128
|
+
*/
|
|
4129
|
+
|
|
4130
|
+
/**
|
|
4131
|
+
* `tool` is the ARGUMENTS a model wants to run; `tool_result` is what came
|
|
4132
|
+
* back. They are different surfaces with different risks — one is an action
|
|
4133
|
+
* about to happen, the other is untrusted content entering the context — and a
|
|
4134
|
+
* policy usually wants different rules for each.
|
|
4135
|
+
*/
|
|
4136
|
+
type GuardrailPhaseName = "input" | "output" | "tool" | "tool_result";
|
|
4137
|
+
type GuardrailRequest = {
|
|
4138
|
+
phase: GuardrailPhaseName;
|
|
4139
|
+
content: string;
|
|
4140
|
+
/** Tool name for `tool` / `tool_result`, otherwise unset. */
|
|
4141
|
+
subject?: string;
|
|
4142
|
+
/** The SDK hook this check was raised from, so a preset can map it exactly. */
|
|
4143
|
+
hook?: string;
|
|
4144
|
+
/** Structured tool arguments, for a service that wants them un-stringified. */
|
|
4145
|
+
toolArgs?: unknown;
|
|
4146
|
+
/** The tool's return value, for `tool_result`. */
|
|
4147
|
+
toolResult?: unknown;
|
|
4148
|
+
/**
|
|
4149
|
+
* Non-text parts of the turn — images, audio, video, files. A text-only
|
|
4150
|
+
* policy sees the caption and nothing else, so a service that moderates
|
|
4151
|
+
* media needs these; one that does not simply ignores the field.
|
|
4152
|
+
*
|
|
4153
|
+
* Inline payloads are DESCRIBED (kind, media type, size) rather than
|
|
4154
|
+
* inlined: shipping a base64 image on every check would multiply the cost of
|
|
4155
|
+
* the guardrail by the size of the upload. A service that needs the bytes
|
|
4156
|
+
* should take a URL, or the caller should override `buildRequest`.
|
|
4157
|
+
*/
|
|
4158
|
+
attachments?: MediaAttachment[];
|
|
4159
|
+
metadata?: Record<string, unknown>;
|
|
4160
|
+
};
|
|
4161
|
+
type GuardrailViolation = {
|
|
4162
|
+
id?: string;
|
|
4163
|
+
type?: string;
|
|
4164
|
+
severity?: string;
|
|
4165
|
+
detail?: string;
|
|
4166
|
+
};
|
|
4167
|
+
type GuardrailVerdict = {
|
|
4168
|
+
action: "allow" | "block" | "mask";
|
|
4169
|
+
message?: string;
|
|
4170
|
+
/** Required when `action === "mask"`. */
|
|
4171
|
+
maskedContent?: string;
|
|
4172
|
+
violations?: GuardrailViolation[];
|
|
4173
|
+
/** The untouched service response, for tracing and debugging. */
|
|
4174
|
+
raw?: unknown;
|
|
4175
|
+
};
|
|
4176
|
+
type GuardrailCallContext = {
|
|
4177
|
+
runId: string;
|
|
4178
|
+
agentName?: string;
|
|
4179
|
+
/** Correlates a guardrail decision with the trace session in the console UI. */
|
|
4180
|
+
traceId?: string;
|
|
4181
|
+
signal?: AbortSignal;
|
|
4182
|
+
};
|
|
4183
|
+
type GuardrailTransport = {
|
|
4184
|
+
name: string;
|
|
4185
|
+
/** Verdicts must come back in the same order as `requests`. */
|
|
4186
|
+
evaluate(requests: GuardrailRequest[], ctx: GuardrailCallContext): MaybePromise<GuardrailVerdict[]>;
|
|
4187
|
+
/**
|
|
4188
|
+
* Optional setup-time handshake. When a service can say which phases carry
|
|
4189
|
+
* active rules, every other phase skips the network entirely — usually the
|
|
4190
|
+
* single biggest latency win available here.
|
|
3906
4191
|
*/
|
|
3907
|
-
|
|
4192
|
+
describe?: () => MaybePromise<{
|
|
4193
|
+
activePhases?: GuardrailPhaseName[];
|
|
4194
|
+
} | null | undefined>;
|
|
4195
|
+
close?: () => MaybePromise<void>;
|
|
3908
4196
|
};
|
|
3909
|
-
type
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
4197
|
+
type HttpGuardrailOptions = {
|
|
4198
|
+
url: string;
|
|
4199
|
+
/** Static headers, or a thunk so a rotating token is read per call. */
|
|
4200
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
4201
|
+
/** Hard ceiling per attempt. Default 3000ms — this is on the critical path. */
|
|
4202
|
+
timeoutMs?: number;
|
|
4203
|
+
/** Retries after the first attempt. Default 1. */
|
|
4204
|
+
retries?: number;
|
|
4205
|
+
/** Send all pending checks in one request. Default true. */
|
|
4206
|
+
batch?: boolean;
|
|
4207
|
+
/** Override the wire request. Default: `{ items, runId, traceId }`. */
|
|
4208
|
+
buildRequest?: (requests: GuardrailRequest[], ctx: GuardrailCallContext) => unknown;
|
|
4209
|
+
/** Override response mapping. Default: `normalizeVerdicts`, which is forgiving. */
|
|
4210
|
+
mapVerdict?: (response: unknown, requests: GuardrailRequest[]) => GuardrailVerdict[];
|
|
3917
4211
|
/**
|
|
3918
|
-
*
|
|
3919
|
-
*
|
|
3920
|
-
*
|
|
4212
|
+
* Status codes that carry a VERDICT rather than an error. Some services
|
|
4213
|
+
* signal the outcome in the status line (e.g. 446 for a block); treating
|
|
4214
|
+
* those as transport failures would route a real decision through the
|
|
4215
|
+
* failureMode path with the wrong reason attached.
|
|
3921
4216
|
*/
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
type AzureProviderConfig = {
|
|
3927
|
-
provider: "azure";
|
|
3928
|
-
apiKey: string;
|
|
3929
|
-
endpoint: string;
|
|
3930
|
-
apiVersion?: string;
|
|
3931
|
-
deploymentName?: string;
|
|
3932
|
-
defaultModel?: string;
|
|
3933
|
-
defaultHeaders?: Record<string, string>;
|
|
3934
|
-
};
|
|
3935
|
-
type OpenAICompatibleProviderConfig = {
|
|
3936
|
-
provider: "openai-compatible";
|
|
3937
|
-
apiKey: string;
|
|
3938
|
-
baseURL: string;
|
|
3939
|
-
defaultModel?: string;
|
|
3940
|
-
defaultHeaders?: Record<string, string>;
|
|
4217
|
+
verdictStatuses?: number[];
|
|
4218
|
+
/** Optional GET endpoint for the setup-time handshake. */
|
|
4219
|
+
describeUrl?: string;
|
|
4220
|
+
name?: string;
|
|
3941
4221
|
};
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
4222
|
+
/**
|
|
4223
|
+
* Accepts the shapes a guardrail service is likely to return and normalizes
|
|
4224
|
+
* them. Being forgiving here is the point: the exact contract can change on the
|
|
4225
|
+
* service side without a client release, and a stricter parser would turn a
|
|
4226
|
+
* cosmetic field rename into an outage.
|
|
4227
|
+
*/
|
|
4228
|
+
declare function normalizeVerdicts(response: unknown, requests: GuardrailRequest[]): GuardrailVerdict[];
|
|
4229
|
+
declare function httpGuardrail(options: HttpGuardrailOptions): GuardrailTransport;
|
|
4230
|
+
/** In-process evaluation — regex policies, a local model, Presidio, tests. */
|
|
4231
|
+
declare function customGuardrail(evaluate: (request: GuardrailRequest, ctx: GuardrailCallContext) => MaybePromise<GuardrailVerdict | void>, name?: string): GuardrailTransport;
|
|
4232
|
+
type GuardrailPluginOptions = {
|
|
4233
|
+
name: string;
|
|
4234
|
+
transport: GuardrailTransport;
|
|
4235
|
+
/** Which surfaces to check. Default: input + output. */
|
|
4236
|
+
apply?: GuardrailPhaseName[];
|
|
3951
4237
|
/**
|
|
3952
|
-
*
|
|
3953
|
-
*
|
|
3954
|
-
* prompt caching (most Anthropic Claude variants on Bedrock).
|
|
4238
|
+
* `shadow` evaluates and reports but never blocks or masks. This is how a
|
|
4239
|
+
* policy gets rolled out safely: measure what it would have caught first.
|
|
3955
4240
|
*/
|
|
3956
|
-
|
|
3957
|
-
|
|
4241
|
+
mode?: "enforce" | "shadow";
|
|
4242
|
+
/** Block when the service is unreachable. Default true. */
|
|
4243
|
+
failClosed?: boolean;
|
|
4244
|
+
timeoutMs?: number;
|
|
4245
|
+
priority?: number;
|
|
4246
|
+
inheritToSubagents?: boolean;
|
|
4247
|
+
/** Memoize verdicts per run. Default true. */
|
|
4248
|
+
cache?: boolean | {
|
|
4249
|
+
maxEntries?: number;
|
|
3958
4250
|
};
|
|
4251
|
+
/** Extra metadata attached to every request. */
|
|
4252
|
+
metadata?: Record<string, unknown>;
|
|
3959
4253
|
};
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
4254
|
+
declare function createGuardrailPlugin(options: GuardrailPluginOptions): AgentPlugin;
|
|
4255
|
+
|
|
4256
|
+
/**
|
|
4257
|
+
* Cognipeer Console guardrail — the first-party preset.
|
|
4258
|
+
*
|
|
4259
|
+
* Talks to the Console's HOOK plane, not its single-shot evaluator:
|
|
4260
|
+
*
|
|
4261
|
+
* POST {baseUrl}/api/client/v1/guardrails/hooks/evaluate
|
|
4262
|
+
* Authorization: Bearer <api key>
|
|
4263
|
+
* { hook, guardrail_keys, text?, tool_name?, tool_args?, tool_result?, … }
|
|
4264
|
+
*
|
|
4265
|
+
* Three properties of that contract shape everything below, and getting any of
|
|
4266
|
+
* them wrong turns a working policy into a silent one:
|
|
4267
|
+
*
|
|
4268
|
+
* `decision` is the EFFECTIVE verdict, already neutralised in monitor mode.
|
|
4269
|
+
* Priority runs block > redact > warn > flag > allow.
|
|
4270
|
+
* `enforced` false means the decision was NOT applied — a dry run. Blocking
|
|
4271
|
+
* on `decision === "block"` without checking this turns every
|
|
4272
|
+
* monitoring policy into an enforcing one on the day it is
|
|
4273
|
+
* switched on for observation.
|
|
4274
|
+
* `passed` means "no blocking finding", NOT "the request was allowed".
|
|
4275
|
+
* The two diverge in monitor mode, which is exactly when someone
|
|
4276
|
+
* reads the wrong one.
|
|
4277
|
+
*
|
|
4278
|
+
* `subject` (or `redacted_text` for the text case) is filled only when the
|
|
4279
|
+
* service actually rewrote something; when it is present it REPLACES what was
|
|
4280
|
+
* sent rather than being merged with it.
|
|
4281
|
+
*
|
|
4282
|
+
* The endpoint answers 200 for a finding as readily as for a clean check, and
|
|
4283
|
+
* only emits 246/446 when a guardrail opts into verdict status codes — so both
|
|
4284
|
+
* are declared as verdict-carrying rather than treated as transport failures.
|
|
4285
|
+
* An unknown key answers 404 ON PURPOSE: a vacuous allow read as "content is
|
|
4286
|
+
* safe" is the failure the whole plane exists to avoid.
|
|
4287
|
+
*/
|
|
4288
|
+
|
|
4289
|
+
type CognipeerGuardrailConfig = {
|
|
4290
|
+
/** Guardrail keys from the Console. Defaults to `COGNIPEER_GUARDRAIL_KEYS` (comma-separated). */
|
|
4291
|
+
guardrailKeys?: string[];
|
|
4292
|
+
/** Convenience for the single-key case. */
|
|
4293
|
+
guardrailKey?: string;
|
|
4294
|
+
/** Defaults to `COGNIPEER_API_KEY`. */
|
|
4295
|
+
apiKey?: string;
|
|
4296
|
+
/** Defaults to `COGNIPEER_BASE_URL`, then the production console. Point at localhost for local runs. */
|
|
4297
|
+
baseUrl?: string;
|
|
4298
|
+
/** Override the hook-evaluate path. */
|
|
4299
|
+
path?: string;
|
|
4300
|
+
/** Surfaces to guard. Default: input + output. Add `"tool"` / `"tool_result"` for the tool surface. */
|
|
4301
|
+
apply?: GuardrailPhaseName[];
|
|
4302
|
+
/** Restrict to specific check families, e.g. `["pii"]`. */
|
|
4303
|
+
only?: string[];
|
|
4304
|
+
/** Override the SDK-hook → Console-hook-id mapping, merged over the default. */
|
|
4305
|
+
hookIds?: Record<string, string>;
|
|
4306
|
+
/** Ask the service to evaluate without enforcing. Independent of `mode`. */
|
|
4307
|
+
shadow?: boolean;
|
|
4308
|
+
/** `shadow` here reports locally without acting, whatever the service says. */
|
|
4309
|
+
mode?: "enforce" | "shadow";
|
|
4310
|
+
/** Default true — an unreachable or misconfigured policy blocks rather than silently stops guarding. */
|
|
4311
|
+
failClosed?: boolean;
|
|
4312
|
+
/** Per-check ceiling. Default 3000ms; also sent as `budget_ms`. */
|
|
4313
|
+
timeoutMs?: number;
|
|
4314
|
+
retries?: number;
|
|
4315
|
+
priority?: number;
|
|
4316
|
+
cache?: boolean | {
|
|
4317
|
+
maxEntries?: number;
|
|
4318
|
+
};
|
|
4319
|
+
metadata?: Record<string, unknown>;
|
|
4320
|
+
buildRequest?: (requests: GuardrailRequest[], ctx: GuardrailCallContext) => unknown;
|
|
4321
|
+
mapVerdict?: (response: unknown, requests: GuardrailRequest[]) => GuardrailVerdict[];
|
|
4322
|
+
name?: string;
|
|
3968
4323
|
};
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
declare
|
|
3972
|
-
readonly provider: string;
|
|
3973
|
-
readonly statusCode?: number | undefined;
|
|
3974
|
-
readonly responseBody?: any | undefined;
|
|
3975
|
-
constructor(message: string, provider: string, statusCode?: number | undefined, responseBody?: any | undefined);
|
|
3976
|
-
}
|
|
4324
|
+
/** The Console's hook response, mapped onto the transport's three-valued verdict. */
|
|
4325
|
+
declare function mapConsoleHookVerdict(response: unknown, requests: GuardrailRequest[]): GuardrailVerdict[];
|
|
4326
|
+
declare function cognipeerGuardrail(config?: CognipeerGuardrailConfig): AgentPlugin;
|
|
3977
4327
|
|
|
3978
4328
|
/**
|
|
3979
4329
|
* Portkey — two integration shapes, because Portkey supports two.
|
|
@@ -5505,33 +5855,8 @@ declare function buildResponseFormatSection(responseFormat: Record<string, any>
|
|
|
5505
5855
|
*/
|
|
5506
5856
|
declare function startStreamingSession(session: TraceSessionRuntime | undefined, agentRuntime?: AgentRuntimeConfig): Promise<void>;
|
|
5507
5857
|
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
maxRetries?: number;
|
|
5511
|
-
/** Initial backoff in ms (doubled on each retry). Default: 500. */
|
|
5512
|
-
baseDelayMs?: number;
|
|
5513
|
-
/** Hard cap on individual delay between retries. Default: 8000. */
|
|
5514
|
-
maxDelayMs?: number;
|
|
5515
|
-
/**
|
|
5516
|
-
* Custom predicate to decide whether to retry. By default we retry 429
|
|
5517
|
-
* and 5xx responses; pass a function to broaden/narrow that set.
|
|
5518
|
-
*/
|
|
5519
|
-
shouldRetry?: (error: any, attempt: number) => boolean;
|
|
5520
|
-
};
|
|
5521
|
-
declare abstract class BaseProvider {
|
|
5522
|
-
abstract readonly providerName: ProviderType;
|
|
5523
|
-
protected retryPolicy: ProviderRetryPolicy;
|
|
5524
|
-
/** Non-streaming completion */
|
|
5525
|
-
abstract complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
5526
|
-
/** Streaming completion – yields incremental chunks */
|
|
5527
|
-
abstract completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
5528
|
-
/**
|
|
5529
|
-
* Helper concrete providers can wrap their fetch with. Retries 429/5xx
|
|
5530
|
-
* with exponential backoff and respects Retry-After if the response
|
|
5531
|
-
* carries one.
|
|
5532
|
-
*/
|
|
5533
|
-
protected doFetchWithRetry(execute: () => Promise<Response>): Promise<Response>;
|
|
5534
|
-
}
|
|
5858
|
+
/** True for Claude model ids of major version 5+ (or the `fable` line). */
|
|
5859
|
+
declare function supportsAdaptiveThinking(model: unknown): boolean;
|
|
5535
5860
|
|
|
5536
5861
|
declare class OpenAIProvider extends BaseProvider {
|
|
5537
5862
|
readonly providerName: ProviderType;
|
|
@@ -5542,6 +5867,11 @@ declare class OpenAIProvider extends BaseProvider {
|
|
|
5542
5867
|
protected readonly responsesApi: "auto" | "never" | "always";
|
|
5543
5868
|
private readonly responsesApiModels;
|
|
5544
5869
|
private readonly responsesStreaming;
|
|
5870
|
+
private readonly apiExplicitChat;
|
|
5871
|
+
private readonly apiExplicitResponses;
|
|
5872
|
+
/** `api: "responses"` was passed (the legacy `responsesApi: "always"` keeps its old single-call behaviour). */
|
|
5873
|
+
private readonly apiResponsesNative;
|
|
5874
|
+
protected readonly maxTokensParam: "auto" | "max_tokens" | "max_completion_tokens";
|
|
5545
5875
|
constructor(config: OpenAIProviderConfig);
|
|
5546
5876
|
/** True when the caller listed this request's model in `responsesApiModels`. */
|
|
5547
5877
|
private isResponsesApiModel;
|
|
@@ -5560,6 +5890,9 @@ declare class OpenAIProvider extends BaseProvider {
|
|
|
5560
5890
|
protected useResponsesApi(request: ChatCompletionRequest): boolean;
|
|
5561
5891
|
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
5562
5892
|
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
5893
|
+
/** POST /embeddings, batched (default 2048 inputs per request, the OpenAI cap). */
|
|
5894
|
+
embed(request: EmbeddingRequest): Promise<EmbeddingResponse>;
|
|
5895
|
+
protected embeddingsFetch(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
|
|
5563
5896
|
protected buildRequestBody(request: ChatCompletionRequest, stream: boolean): Record<string, any>;
|
|
5564
5897
|
protected completeResponses(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
5565
5898
|
/** Real Responses SSE streaming, for models opted in through
|
|
@@ -5573,11 +5906,11 @@ declare class OpenAIProvider extends BaseProvider {
|
|
|
5573
5906
|
protected buildResponsesBody(request: ChatCompletionRequest): Record<string, any>;
|
|
5574
5907
|
/** Maps a unified message to a Responses API `input` item. */
|
|
5575
5908
|
protected toResponsesInput(m: UnifiedMessage): Record<string, any>;
|
|
5576
|
-
protected responsesFetch(body: Record<string, any
|
|
5909
|
+
protected responsesFetch(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
|
|
5577
5910
|
protected parseResponsesResponse(json: any, modelId: string): ChatCompletionResponse;
|
|
5578
5911
|
protected toOpenAIMessage(m: UnifiedMessage): Record<string, any>;
|
|
5579
5912
|
protected toOpenAITool(t: ToolDefinition): Record<string, any>;
|
|
5580
|
-
protected doFetch(body: Record<string, any
|
|
5913
|
+
protected doFetch(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
|
|
5581
5914
|
protected parseResponse(json: any): ChatCompletionResponse;
|
|
5582
5915
|
protected extractUsage(usage: any): TokenUsage;
|
|
5583
5916
|
}
|
|
@@ -5590,6 +5923,7 @@ declare class AnthropicProvider extends BaseProvider {
|
|
|
5590
5923
|
private readonly defaultHeaders;
|
|
5591
5924
|
private readonly anthropicVersion;
|
|
5592
5925
|
private readonly promptCachingEnabled;
|
|
5926
|
+
private readonly thinkingMode;
|
|
5593
5927
|
constructor(config: AnthropicProviderConfig);
|
|
5594
5928
|
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
5595
5929
|
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
@@ -5609,6 +5943,9 @@ declare class AnthropicProvider extends BaseProvider {
|
|
|
5609
5943
|
private toAnthropicToolResult;
|
|
5610
5944
|
private toAnthropicMessage;
|
|
5611
5945
|
private toAnthropicTool;
|
|
5946
|
+
/** Builds and sends the request; retries once with the other thinking form
|
|
5947
|
+
* when the upstream rejects the one we picked. */
|
|
5948
|
+
private send;
|
|
5612
5949
|
private doFetch;
|
|
5613
5950
|
private parseResponse;
|
|
5614
5951
|
}
|
|
@@ -5620,11 +5957,14 @@ declare class AzureProvider extends OpenAIProvider {
|
|
|
5620
5957
|
private readonly deploymentName?;
|
|
5621
5958
|
private readonly azureApiKey;
|
|
5622
5959
|
constructor(config: AzureProviderConfig);
|
|
5623
|
-
protected doFetch(body: Record<string, any
|
|
5960
|
+
protected doFetch(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
|
|
5961
|
+
/** Azure embeddings: the deployment named by the request's model (falling back
|
|
5962
|
+
* to the configured deployment) in the path, api-key auth. */
|
|
5963
|
+
protected embeddingsFetch(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
|
|
5624
5964
|
/** Azure exposes the Responses API at /openai/responses with api-key auth.
|
|
5625
5965
|
* Reasoning summaries require a preview api-version; callers can override via
|
|
5626
5966
|
* the `apiVersion` config. */
|
|
5627
|
-
protected responsesFetch(body: Record<string, any
|
|
5967
|
+
protected responsesFetch(body: Record<string, any>, signal?: AbortSignal): Promise<Response>;
|
|
5628
5968
|
}
|
|
5629
5969
|
|
|
5630
5970
|
declare class OpenAICompatibleProvider extends OpenAIProvider {
|
|
@@ -5639,9 +5979,28 @@ declare class BedrockProvider extends BaseProvider {
|
|
|
5639
5979
|
private readonly defaultModel;
|
|
5640
5980
|
private readonly defaultHeaders;
|
|
5641
5981
|
private readonly promptCachingEnabled;
|
|
5982
|
+
private readonly thinkingMode;
|
|
5642
5983
|
constructor(config: BedrockProviderConfig);
|
|
5643
5984
|
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
5985
|
+
/**
|
|
5986
|
+
* Real streaming over ConverseStream. The response is an AWS event-stream
|
|
5987
|
+
* (binary frames); each frame carries one JSON event: messageStart,
|
|
5988
|
+
* contentBlockStart/Delta/Stop (text, toolUse, reasoningContent),
|
|
5989
|
+
* messageStop and, last, metadata (usage). Text, tool-call argument and
|
|
5990
|
+
* reasoning deltas are yielded as they arrive; one closing chunk carries the
|
|
5991
|
+
* finish reason, usage and the signed reasoning blocks.
|
|
5992
|
+
*/
|
|
5644
5993
|
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
5994
|
+
/**
|
|
5995
|
+
* InvokeModel embeddings. Supported families (by model id, inference-profile
|
|
5996
|
+
* prefixes such as `us.` allowed):
|
|
5997
|
+
* - Amazon Titan Text Embeddings (v1, v2): one text per call, `dimensions`
|
|
5998
|
+
* (v2: 256/512/1024) and `normalize` via `extra`.
|
|
5999
|
+
* - Cohere Embed (v3, v4): a batch of texts per call (default 96), `inputType`
|
|
6000
|
+
* maps to `input_type`, `dimensions` to `output_dimension` (v4).
|
|
6001
|
+
*/
|
|
6002
|
+
embed(request: EmbeddingRequest): Promise<EmbeddingResponse>;
|
|
6003
|
+
private invokeModel;
|
|
5645
6004
|
private buildConverseBody;
|
|
5646
6005
|
private splitSystemMessages;
|
|
5647
6006
|
/**
|
|
@@ -5659,6 +6018,9 @@ declare class BedrockProvider extends BaseProvider {
|
|
|
5659
6018
|
private toBedrockToolResult;
|
|
5660
6019
|
private toBedrockMessage;
|
|
5661
6020
|
private toBedrockTool;
|
|
6021
|
+
/** Sends the Converse call; retries once with toolChoice auto when the
|
|
6022
|
+
* model rejects forced tool use. */
|
|
6023
|
+
private converseFetch;
|
|
5662
6024
|
private doFetch;
|
|
5663
6025
|
private parseResponse;
|
|
5664
6026
|
}
|
|
@@ -5675,6 +6037,13 @@ declare class VertexProvider extends BaseProvider {
|
|
|
5675
6037
|
constructor(config: VertexProviderConfig);
|
|
5676
6038
|
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
5677
6039
|
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
6040
|
+
/**
|
|
6041
|
+
* Vertex `:predict` embeddings (text-embedding-00x, text-multilingual-embedding,
|
|
6042
|
+
* gemini-embedding-001). `inputType` maps to the task type; `dimensions` to
|
|
6043
|
+
* `outputDimensionality`. gemini-embedding takes one instance per request, the
|
|
6044
|
+
* text-embedding models up to `batchSize` (default 100).
|
|
6045
|
+
*/
|
|
6046
|
+
embed(request: EmbeddingRequest): Promise<EmbeddingResponse>;
|
|
5678
6047
|
private buildUrl;
|
|
5679
6048
|
private buildGeminiBody;
|
|
5680
6049
|
private buildContents;
|
|
@@ -5699,7 +6068,50 @@ type NativeModelOptions = {
|
|
|
5699
6068
|
extra?: Record<string, any>;
|
|
5700
6069
|
/** Unified native reasoning config applied by default (per-call overrides supported). */
|
|
5701
6070
|
reasoning?: ReasoningRequestConfig;
|
|
6071
|
+
/** Default nucleus sampling. */
|
|
6072
|
+
topP?: number;
|
|
6073
|
+
/** Default stop sequences. */
|
|
6074
|
+
stop?: string[];
|
|
6075
|
+
/** Default presence penalty (OpenAI-family only). */
|
|
6076
|
+
presencePenalty?: number;
|
|
6077
|
+
/** Default frequency penalty (OpenAI-family only). */
|
|
6078
|
+
frequencyPenalty?: number;
|
|
6079
|
+
/**
|
|
6080
|
+
* Last-mile hook: receives the fully built request (tools, response format,
|
|
6081
|
+
* reasoning already applied) right before it goes to the provider. Mutate it
|
|
6082
|
+
* in place or return a replacement. Use it for model-specific rules the
|
|
6083
|
+
* unified request cannot express (e.g. force `reasoning` off when tools are bound).
|
|
6084
|
+
*/
|
|
6085
|
+
transformRequest?: (request: ChatCompletionRequest) => ChatCompletionRequest | void | Promise<ChatCompletionRequest | void>;
|
|
6086
|
+
};
|
|
6087
|
+
/**
|
|
6088
|
+
* The ONE usage shape carried on every assistant message produced by a native
|
|
6089
|
+
* provider (`message.usage`, and mirrored on `response_metadata.token_usage`):
|
|
6090
|
+
*
|
|
6091
|
+
* ```
|
|
6092
|
+
* {
|
|
6093
|
+
* prompt_tokens, completion_tokens, total_tokens,
|
|
6094
|
+
* prompt_tokens_details: { cached_tokens, cache_write_tokens },
|
|
6095
|
+
* completion_tokens_details: { reasoning_tokens },
|
|
6096
|
+
* }
|
|
6097
|
+
* ```
|
|
6098
|
+
* `completion_tokens` INCLUDES `reasoning_tokens`; `prompt_tokens` INCLUDES
|
|
6099
|
+
* `cached_tokens`. `response_metadata.token_usage` additionally keeps the flat
|
|
6100
|
+
* legacy `cached_tokens` / `cache_write_tokens` keys.
|
|
6101
|
+
*/
|
|
6102
|
+
type MessageUsage = {
|
|
6103
|
+
prompt_tokens: number;
|
|
6104
|
+
completion_tokens: number;
|
|
6105
|
+
total_tokens: number;
|
|
6106
|
+
prompt_tokens_details: {
|
|
6107
|
+
cached_tokens: number;
|
|
6108
|
+
cache_write_tokens: number;
|
|
6109
|
+
};
|
|
6110
|
+
completion_tokens_details: {
|
|
6111
|
+
reasoning_tokens: number;
|
|
6112
|
+
};
|
|
5702
6113
|
};
|
|
6114
|
+
declare function toMessageUsage(u: TokenUsage): MessageUsage;
|
|
5703
6115
|
/**
|
|
5704
6116
|
* Creates a BaseChatModel from a native provider.
|
|
5705
6117
|
*
|
|
@@ -5736,4 +6148,4 @@ declare function fromNativeProvider(provider: BaseProvider, options?: NativeMode
|
|
|
5736
6148
|
*/
|
|
5737
6149
|
declare function createProvider(config: ProviderConfig): BaseProvider;
|
|
5738
6150
|
|
|
5739
|
-
export { type AIMessage, ASK_USER_TOOL_NAME, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentPlugin, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, type ApprovalTransport, type AudioContent, type AuditEntry, type AuditLogConfig, type AzureContentSafetyConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, type BedrockGuardrailConfig, BedrockProvider, type BedrockProviderConfig, type BudgetGuardConfig, type BuildChildConfig, type BuiltInRuntimeProfile, CCRStore, CONSOLE_HOOK_MAP, CONTEXT_PILOT_JSON_MARKER_KEY, CONTROL_PLANE_TOOL_NAMES, type CancellationTokenLike, type CancelledEvent, type CapabilityStatus, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type CheckpointPluginConfig, type CheckpointStore, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type CognipeerGuardrailConfig, type CompressToolOutputParams, type ContextBuilder, type ContextPilotCCRConfig, type ContextPilotCacheAlignmentConfig, type ContextPilotCompressionConfig, type ContextPilotCompressionStats, type ContextPilotCompressorKind, type ContextPilotConfig, type ContextPilotDedupConfig, type ContextPilotDiffCompressionConfig, type ContextPilotJsonCompressionConfig, type ContextPilotLogCompressionConfig, type ContextPilotResult, type ContextPilotRuntime, type ContextPilotSearchCompressionConfig, type ContextPilotTextCompressionConfig, type ContextPolicy, type ContextToolsStateRef, type ConversationGuardrail, type ConversationPluginConfig, type ConversationStore, type CostEstimator, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_MAX_TOOL_INPUT_FIELD_CHARS, DEFAULT_PROFILE_CONFIGS, DEFAULT_SKILL_POLICY, DEFAULT_SUBAGENT_POLICY, DEFAULT_SUBAGENT_TOOL_NAMES, DEFAULT_TOOL_INPUT_DIGEST_HEAD_CHARS, DELEGATION_TOOL_NAMES, DedupTracker, type DelegationEventStamp, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FileContent, type FinalAnswerEvent, type FinishReason, type GateResult, type GuardrailCallContext, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailPhaseName, type GuardrailPluginOptions, type GuardrailRequest, type GuardrailRule, type GuardrailRuleResult, type GuardrailTransport, type GuardrailVerdict, type GuardrailViolation, HOOK_CONTRACT_VERSION, HOOK_NAMES, type HandoffDescriptor, type HandoffEvent, type HookContext, type HookDecision, type HookHandler, type HookMap, type HookName, type HookRegistrations, HookTimeoutError, type HttpGuardrailOptions, type HumanInTheLoopAskUserConfig, type HumanInTheLoopOptions, type HumanInTheLoopRuntimeConfig, type ImageContent, InMemoryMemoryStore, type InjectionScan, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type LangfuseBuildContext, type LangfuseEvent, type LangfuseEventKind, type LangfuseTracingConfig, type LanguageGuardConfig, type LoadSkillsOptions, type MaybePromise, type McpConfig, type McpConnection, type MediaAttachment, type MediaKind, type MediaPolicyConfig, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, type OpenAIModerationConfig, OpenAIProvider, type OpenAIProviderConfig, type OtelTracingConfig, type OutputGuardConfig, PREOPEN_TOOL_CALL_PREFIX, type PendingToolApproval, type PendingUserQuestion, type PiiDetector, type PiiEntity, type PiiRedactionConfig, type PlanEvent, type PlanStepRecord, type PlanningMode, type PluginContributions, type PluginEvent, type PluginFailureMode, type PluginHost, type PluginHostOptions, type PluginLogger, type PluginProvides, type PluginRunHost, type PluginSetupContext, type PortkeyGatewayConfig, type PortkeyGuardrailConfig, type PreopenSkillsResult, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type PromptHooks, type PromptInjectionFamily, type PromptInjectionGuardConfig, type PromptSource, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type RateLimitConfig, type ReasoningConfig, type ReasoningLevel, type RedactionResult, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionHookContext, type ReflectionRecord, type RegexGuardrailConfig, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedContextPilotConfig, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type ResponseCacheConfig, type RestoreSnapshotOptions, type RuntimeProfile, SMALL_TIER_SKILL_POLICY, type SdkCapabilities, type SerializableSmartState, type SessionMetrics, type SessionMetricsConfig, type Skill, type SkillDisclosure, type SkillExecutionContext, type SkillFrontmatter, type SkillFs, type SkillModelTier, type SkillPolicy, type SkillRegistryRef, type SkillSource, type SkillToolDeps, type SkillToolHeader, type SlotName, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type StreamChunk, type StreamEvent, type StrictRestorers, type StrictTransform, type StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SubagentDef, type SubagentEvent, type SubagentMode, type SubagentPendingRecord, type SubagentPolicy, type SubagentRegistryRef, type SubagentResult, type SubagentToolDeps, type SubagentToolNames, type SummarizationEvent, type SummarizationMode, type SummarizerInput, type SummarizerResult, type SummarizerStrategy, type SummaryFactItem, type SummaryIntegrityCheck, TOOL_INPUT_DIGEST_KEY, type TextContent, type TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInputDigestOptions, type ToolInputDigestResult, type ToolInputRetentionPolicy, type ToolInterface, type ToolPolicyConfig, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetentionDeclarations, type ToolRetentionSpec, type ToolRetryPolicy, type ToolRule, type TraceDataSection, type TraceErrorRecord, type TraceEventRecord, type TraceMessageSection, type TraceMetadataSection, type TraceSessionConfigSnapshot, type TraceSessionFile, type TraceSessionStatus, type TraceSessionSummary, type TraceSinkCognipeerConfig, type TraceSinkConfig, type TraceSinkCustomConfig, type TraceSinkFileConfig, type TraceSinkHttpConfig, type TraceSinkOtlpConfig, type TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolDefinition, type TraceToolDefinitionsSection, type TraceToolDetails, type TraceToolResponseSection, type TraceToolResultSection, type TracingConfig, type TracingMode, type UnifiedMessage, type UserQuestionAnswer, type UserQuestionAnswerSet, type UserQuestionEvent, type UserQuestionItem, type UserQuestionOption, type UserQuestionResolution, type UserQuestionStatus, VertexProvider, type VertexProviderConfig, type VolatileContentFinding, type VolatileContentPattern, type WebhookApprovalConfig, agentVerdictRule, appendBoundTools, auditLog, azureContentSafety, bedrockGuardrail, budgetGuard, buildHandoffTools, buildResponseFormatSection, buildSkillHeaderBlock, buildSubagentCatalogBlock, buildSystemPrompt, buildToolDefinitionsSection, canOpenSkill, canSpawn, captureSnapshot, checkpointing, codePresenceRule, coerceToolArgs, cognipeerGuardrail, cognipeerSink, collectAttachments, collectToolRetentionDeclarations, composeToolSets, compressDiffOutput, compressJsonOutput, compressLogOutput, compressSearchOutput, compressTextOutput, compressToolOutput, contentToString, conversationHistory, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createBindSkillToolsTool, createCodeGuardrail, createContextPilotRuntime, createContextSummarizeNode, createContextTools, createDelegateTool, createGetToolResponseTool, createGuardrail, createGuardrailPlugin, createJsonGuardrail, createManageTodoListAliasTool, createManageTodoTool, createOpenSkillTool, createParallelTool, createPluginHost, createProvider, createRegexGuardrail, createResolverNode, createSearchSkillsTool, createSkillRegistryRef, createSkillTools, createSmartAgent, createSpawnTool, createSubagentRegistryRef, createSubagentTools, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customGuardrail, customSink, dedupeToolsByName, defaultTokenCounter, defineHook, definePlugin, detectLanguage, detectTextFormat, detectVolatileContent, digestToolInputArguments, digestToolInputValue, emptyUsage, evaluateGuardrails, extractLatestUserQuery, extractMessageText, fileCheckpointStore, fileSink, findSubagent, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasToolResponseRecoveryReference, httpGuardrail, httpSink, inMemoryCheckpointStore, inMemoryConversationStore, isHookImplemented, isOpenAIHostedEndpoint, isSmartModel, isValidIban, isValidLuhn, isValidTckn, jsonSchemaRule, defaultBuildPayload as langfuseDefaultPayload, langfuseTracing, languageGuard, loadSkillsFromDisk, mapConsoleHookVerdict, mapTextParts, mcp, mediaPolicy, normalizeSmartAgentOptions, normalizeVerdicts, openAIModeration, otelTracing, otlpSink, outputGuard, parseApprovalDecision, parseSkillFrontmatter, pathSandbox, piiRedaction, pluginCapabilities, portkeyGateway, portkeyGuardrail, preopenSkills, preopenToolCallId, prepareStrictToolMenu, promptInjectionGuard, rateLimit, readMemoryFacts, redactText, regexGuardrail, regexRule, replaceTextContent, resolveAvailableSkills, resolveAvailableSubagents, resolveInputRetention, resolveMemoryStore, resolveReasoning, resolveStrategy, resolveSubagentTools, resolveSummarizationRetention, resolveToolApprovalState, resolveUserQuestionState, responseCache, restoreSnapshot, restoreToolCalls, runSmartAgentEvalHarness, scoreItemsByRelevance, searchSkills, seedChildMessages, selectTopIndicesInOrder, sessionMetrics, setTokenCounter, startStreamingSession, summarizeObject, textFromContent, toStrictCompatible, toStrictToolSchema, tokenize, toolPolicy, traceSessionToOtlp, validateReasoningConfig, validateToolArgs, webhookApproval, withTools, withinDepth, writeSummaryFactsToMemory };
|
|
6151
|
+
export { type AIMessage, ASK_USER_TOOL_NAME, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentPlugin, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, type ApprovalTransport, type AudioContent, type AuditEntry, type AuditLogConfig, type AzureContentSafetyConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, type BedrockGuardrailConfig, BedrockProvider, type BedrockProviderConfig, type BudgetGuardConfig, type BuildChildConfig, type BuiltInRuntimeProfile, CCRStore, CONSOLE_HOOK_MAP, CONTEXT_PILOT_JSON_MARKER_KEY, CONTROL_PLANE_TOOL_NAMES, type CancellationTokenLike, type CancelledEvent, type CapabilityStatus, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type CheckpointPluginConfig, type CheckpointStore, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type CognipeerGuardrailConfig, type CompressToolOutputParams, type ContextBuilder, type ContextPilotCCRConfig, type ContextPilotCacheAlignmentConfig, type ContextPilotCompressionConfig, type ContextPilotCompressionStats, type ContextPilotCompressorKind, type ContextPilotConfig, type ContextPilotDedupConfig, type ContextPilotDiffCompressionConfig, type ContextPilotJsonCompressionConfig, type ContextPilotLogCompressionConfig, type ContextPilotResult, type ContextPilotRuntime, type ContextPilotSearchCompressionConfig, type ContextPilotTextCompressionConfig, type ContextPolicy, type ContextToolsStateRef, type ConversationGuardrail, type ConversationPluginConfig, type ConversationStore, type CostEstimator, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_MAX_TOOL_INPUT_FIELD_CHARS, DEFAULT_PROFILE_CONFIGS, DEFAULT_SKILL_POLICY, DEFAULT_SUBAGENT_POLICY, DEFAULT_SUBAGENT_TOOL_NAMES, DEFAULT_TOOL_INPUT_DIGEST_HEAD_CHARS, DELEGATION_TOOL_NAMES, DedupTracker, type DelegationEventStamp, type DelegationMode, type EmbeddingInputType, type EmbeddingRequest, type EmbeddingResponse, type EmbeddingUsage, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FileContent, type FinalAnswerEvent, type FinishReason, type GateResult, type GuardrailCallContext, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailJudgeEngine, type GuardrailOutcome, GuardrailPhase, type GuardrailPhaseName, type GuardrailPluginOptions, type GuardrailRequest, type GuardrailRule, type GuardrailRuleResult, type GuardrailTransport, type GuardrailVerdict, type GuardrailViolation, HOOK_CONTRACT_VERSION, HOOK_NAMES, type HandoffDescriptor, type HandoffEvent, type HookContext, type HookDecision, type HookHandler, type HookMap, type HookName, type HookRegistrations, HookTimeoutError, type HttpGuardrailOptions, type HumanInTheLoopAskUserConfig, type HumanInTheLoopOptions, type HumanInTheLoopRuntimeConfig, type ImageContent, InMemoryMemoryStore, type InjectionScan, type InvokeConfig, type JevClientLike, type JevEngineOptions, type JevNoulAnswer, JevProvider, type JevProviderConfig, type JevQuestion, type JevSystemOneRequest, type JevSystemOneResult, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type LangfuseBuildContext, type LangfuseEvent, type LangfuseEventKind, type LangfuseTracingConfig, type LanguageGuardConfig, type LoadSkillsOptions, type MaybePromise, type McpConfig, type McpConnection, type MediaAttachment, type MediaKind$1 as MediaKind, type MediaPolicyConfig, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MessageUsage, type MetadataEvent, type ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, type NativeReasoningConfig, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, type OpenAIModerationConfig, OpenAIProvider, type OpenAIProviderConfig, type OtelTracingConfig, type OutputGuardConfig, PREOPEN_TOOL_CALL_PREFIX, type PendingToolApproval, type PendingUserQuestion, type PiiDetector, type PiiEntity, type PiiRedactionConfig, type PlanEvent, type PlanStepRecord, type PlanningMode, type PluginContributions, type PluginEvent, type PluginFailureMode, type PluginHost, type PluginHostOptions, type PluginLogger, type PluginProvides, type PluginRunHost, type PluginSetupContext, type PortkeyGatewayConfig, type PortkeyGuardrailConfig, type PreopenSkillsResult, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type PromptHooks, type PromptInjectionFamily, type PromptInjectionGuardConfig, type PromptSource, type ProviderConfig, ProviderError, type ProviderResponseFields, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderTransportConfig, type ProviderType, type RateLimitConfig, type ReasoningConfig, type ReasoningLevel, type RedactionResult, type ReflectionCadence, type ReflectionConfig, type ReflectionEvent, type ReflectionHookContext, type ReflectionRecord, type RegexGuardrailConfig, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedContextPilotConfig, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type ResponseCacheConfig, type RestoreSnapshotOptions, type RuntimeProfile, SMALL_TIER_SKILL_POLICY, type SdkCapabilities, type SerializableSmartState, type SessionMetrics, type SessionMetricsConfig, type Skill, type SkillDisclosure, type SkillExecutionContext, type SkillFrontmatter, type SkillFs, type SkillModelTier, type SkillPolicy, type SkillRegistryRef, type SkillSource, type SkillToolDeps, type SkillToolHeader, type SlotName, type SmartAgentBudgetConfig, type SmartAgentContextConfig, type SmartAgentCustomProfileConfig, type SmartAgentDelegationConfig, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentMemoryConfig, type SmartAgentOptions, type SmartAgentPlanningConfig, type SmartAgentSummarizationConfig, type SmartAgentToolResponseConfig, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type StreamChunk, type StreamEvent, type StrictRestorers, type StrictTransform, type StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SubagentDef, type SubagentEvent, type SubagentMode, type SubagentPendingRecord, type SubagentPolicy, type SubagentRegistryRef, type SubagentResult, type SubagentToolDeps, type SubagentToolNames, type SummarizationEvent, type SummarizationMode, type SummarizerInput, type SummarizerResult, type SummarizerStrategy, type SummaryFactItem, type SummaryIntegrityCheck, TOOL_INPUT_DIGEST_KEY, type TextContent, type TokenCounter, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCachePolicy, type ToolCallEvent, type ToolInputDigestOptions, type ToolInputDigestResult, type ToolInputRetentionPolicy, type ToolInterface, type ToolPolicyConfig, type ToolResponseClassification, type ToolResponseRetentionPolicy, type ToolRetentionDeclarations, type ToolRetentionSpec, type ToolRetryPolicy, type ToolRule, type TraceDataSection, type TraceErrorRecord, type TraceEventRecord, type TraceMessagePart, type TraceMessageSection, type TraceMetadataSection, type TraceSessionConfigSnapshot, type TraceSessionFile, type TraceSessionStatus, type TraceSessionSummary, type TraceSinkCognipeerConfig, type TraceSinkConfig, type TraceSinkCustomConfig, type TraceSinkFileConfig, type TraceSinkHttpConfig, type TraceSinkOtlpConfig, type TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolDefinition, type TraceToolDefinitionsSection, type TraceToolDetails, type TraceToolResponseSection, type TraceToolResultSection, type TracingConfig, type TracingMode, type UnifiedMessage, type UserQuestionAnswer, type UserQuestionAnswerSet, type UserQuestionEvent, type UserQuestionItem, type UserQuestionOption, type UserQuestionResolution, type UserQuestionStatus, VertexProvider, type VertexProviderConfig, type VolatileContentFinding, type VolatileContentPattern, type WebhookApprovalConfig, agentVerdictRule, appendBoundTools, auditLog, azureContentSafety, bedrockGuardrail, budgetGuard, buildHandoffTools, buildResponseFormatSection, buildSkillHeaderBlock, buildSubagentCatalogBlock, buildSystemPrompt, buildToolDefinitionsSection, canOpenSkill, canSpawn, captureSnapshot, checkpointing, codePresenceRule, coerceToolArgs, cognipeerGuardrail, cognipeerSink, collectAttachments, collectToolRetentionDeclarations, composeToolSets, compressDiffOutput, compressJsonOutput, compressLogOutput, compressSearchOutput, compressTextOutput, compressToolOutput, contentPartToText, contentToString, conversationHistory, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createAskUserQuestionTool, createBindSkillToolsTool, createCodeGuardrail, createContextPilotRuntime, createContextSummarizeNode, createContextTools, createDelegateTool, createGetToolResponseTool, createGuardrail, createGuardrailPlugin, createJsonGuardrail, createManageTodoListAliasTool, createManageTodoTool, createOpenSkillTool, createParallelTool, createPluginHost, createProvider, createRegexGuardrail, createResolverNode, createSearchSkillsTool, createSkillRegistryRef, createSkillTools, createSmartAgent, createSpawnTool, createSubagentRegistryRef, createSubagentTools, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customGuardrail, customSink, dedupeToolsByName, defaultTokenCounter, defineHook, definePlugin, describeContentPart, detectLanguage, detectTextFormat, detectVolatileContent, digestToolInputArguments, digestToolInputValue, emptyUsage, evaluateGuardrails, extractLatestUserQuery, extractMessageText, fileCheckpointStore, fileSink, findSubagent, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, getTokenCounter, hasMediaPart, hasToolResponseRecoveryReference, httpGuardrail, httpSink, inMemoryCheckpointStore, inMemoryConversationStore, isHookImplemented, isOpenAIHostedEndpoint, isSmartModel, isValidIban, isValidLuhn, isValidTckn, jsonSchemaRule, defaultBuildPayload as langfuseDefaultPayload, langfuseTracing, languageGuard, loadSkillsFromDisk, mapConsoleHookVerdict, mapTextParts, mcp, mediaKindOf, mediaPolicy, normalizeSmartAgentOptions, normalizeVerdicts, openAIModeration, otelTracing, otlpSink, outputGuard, parseApprovalDecision, parseSkillFrontmatter, pathSandbox, piiRedaction, pluginCapabilities, portkeyGateway, portkeyGuardrail, preopenSkills, preopenToolCallId, prepareStrictToolMenu, promptInjectionGuard, rateLimit, readMemoryFacts, redactText, regexGuardrail, regexRule, replaceTextContent, resolveAvailableSkills, resolveAvailableSubagents, resolveInputRetention, resolveMemoryStore, resolveReasoning, resolveStrategy, resolveSubagentTools, resolveSummarizationRetention, resolveToolApprovalState, resolveUserQuestionState, responseCache, restoreSnapshot, restoreToolCalls, runSmartAgentEvalHarness, scoreItemsByRelevance, searchSkills, seedChildMessages, selectTopIndicesInOrder, sessionMetrics, setTokenCounter, startStreamingSession, summarizeObject, supportsAdaptiveThinking, textFromContent, toMessageUsage, toStrictCompatible, toStrictToolSchema, tokenize, toolPolicy, traceSessionToOtlp, validateReasoningConfig, validateToolArgs, webhookApproval, withTools, withinDepth, writeSummaryFactsToMemory };
|