@cognipeer/agent-sdk 0.4.9 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -5
- package/dist/index.cjs +2682 -528
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +503 -25
- package/dist/index.d.ts +503 -25
- package/dist/index.mjs +2669 -531
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
|
-
import { ZodSchema, z } from 'zod';
|
|
1
|
+
import { ZodError, ZodSchema, z } from 'zod';
|
|
2
2
|
import { JSONSchema7 } from 'json-schema';
|
|
3
3
|
|
|
4
|
+
/** Describes what a model/provider natively supports. */
|
|
5
|
+
type ModelCapabilities = {
|
|
6
|
+
/** How the model supports structured output:
|
|
7
|
+
* - "native": model accepts response_format with json_schema (OpenAI, Gemini, etc.)
|
|
8
|
+
* - "tool_based": structured output must be emulated via a response tool
|
|
9
|
+
*/
|
|
10
|
+
structuredOutput?: "native" | "tool_based";
|
|
11
|
+
/** Whether tools must be bound with strict=true for native structured output auto-parsing. */
|
|
12
|
+
strictToolCalling?: boolean;
|
|
13
|
+
/** Whether the model supports streaming */
|
|
14
|
+
streaming?: boolean;
|
|
15
|
+
/** Provider identifier (e.g. "openai", "anthropic", "bedrock", "google") */
|
|
16
|
+
provider?: string;
|
|
17
|
+
};
|
|
18
|
+
type StructuredOutputFieldError = {
|
|
19
|
+
path: string;
|
|
20
|
+
expected: string;
|
|
21
|
+
received: string;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
type StructuredOutputError = {
|
|
25
|
+
type: "parse_error" | "validation_error" | "no_output" | "max_retries";
|
|
26
|
+
message: string;
|
|
27
|
+
fieldErrors?: StructuredOutputFieldError[];
|
|
28
|
+
rawContent?: string;
|
|
29
|
+
};
|
|
30
|
+
type StructuredOutputResult<T> = {
|
|
31
|
+
success: true;
|
|
32
|
+
data: T;
|
|
33
|
+
attempts: number;
|
|
34
|
+
} | {
|
|
35
|
+
success: false;
|
|
36
|
+
error: StructuredOutputError;
|
|
37
|
+
attempts: number;
|
|
38
|
+
rawContent?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Encapsulates how structured output is achieved for a given model/provider.
|
|
42
|
+
* NativeJsonSchemaStrategy uses response_format; ToolBasedStrategy uses a response tool.
|
|
43
|
+
*/
|
|
44
|
+
interface StructuredOutputStrategy {
|
|
45
|
+
readonly kind: "native" | "tool_based";
|
|
46
|
+
/**
|
|
47
|
+
* Build a correction prompt when validation fails.
|
|
48
|
+
* The prompt tells the model exactly which fields were wrong.
|
|
49
|
+
*/
|
|
50
|
+
buildCorrectionPrompt(error: ZodError<any>, previousAttempt: unknown): string;
|
|
51
|
+
}
|
|
52
|
+
type StructuredOutputManagerConfig = {
|
|
53
|
+
maxRetries?: number;
|
|
54
|
+
};
|
|
55
|
+
declare function getNestedValue(obj: unknown, path: (string | number)[]): unknown;
|
|
56
|
+
declare function formatZodError(error: ZodError<any>, rawContent?: string): StructuredOutputError;
|
|
57
|
+
|
|
4
58
|
interface BaseChatMessagePart {
|
|
5
59
|
type?: string;
|
|
6
60
|
text?: string;
|
|
@@ -37,13 +91,20 @@ interface BaseChatModel {
|
|
|
37
91
|
isCancellationRequested: boolean;
|
|
38
92
|
};
|
|
39
93
|
}): AsyncIterable<BaseChatMessage | BaseChatMessagePart | string>;
|
|
40
|
-
bindTools?(tools: any[]
|
|
94
|
+
bindTools?(tools: any[], options?: {
|
|
95
|
+
strict?: boolean;
|
|
96
|
+
[key: string]: any;
|
|
97
|
+
}): BaseChatModel;
|
|
41
98
|
modelName?: string;
|
|
99
|
+
capabilities?: ModelCapabilities;
|
|
42
100
|
[key: string]: any;
|
|
43
101
|
}
|
|
44
102
|
type SmartModel = BaseChatModel;
|
|
45
103
|
declare function isSmartModel(m: any): m is SmartModel;
|
|
46
|
-
declare function withTools(model: SmartModel, tools: any[]
|
|
104
|
+
declare function withTools(model: SmartModel, tools: any[], options?: {
|
|
105
|
+
strict?: boolean;
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
}): BaseChatModel;
|
|
47
108
|
declare function fromLangchainModel(lcModel: any): BaseChatModel;
|
|
48
109
|
|
|
49
110
|
type ImageURL = {
|
|
@@ -54,7 +115,7 @@ type ImageURL = {
|
|
|
54
115
|
media_type?: string;
|
|
55
116
|
detail?: 'auto' | 'low' | 'high';
|
|
56
117
|
} | string;
|
|
57
|
-
type ContentPart = {
|
|
118
|
+
type ContentPart$1 = {
|
|
58
119
|
type: 'text';
|
|
59
120
|
text: string;
|
|
60
121
|
} | {
|
|
@@ -82,7 +143,7 @@ type RunnableConfig = {
|
|
|
82
143
|
type BaseMessage = {
|
|
83
144
|
role: string;
|
|
84
145
|
name?: string;
|
|
85
|
-
content: string | ContentPart[];
|
|
146
|
+
content: string | ContentPart$1[];
|
|
86
147
|
tool_calls?: any;
|
|
87
148
|
tool_call_id?: string;
|
|
88
149
|
[key: string]: any;
|
|
@@ -377,6 +438,7 @@ type AgentRuntimeConfig = {
|
|
|
377
438
|
limits?: AgentLimits;
|
|
378
439
|
useTodoList?: boolean;
|
|
379
440
|
outputSchema?: ZodSchema<any>;
|
|
441
|
+
responseFormat?: Record<string, any>;
|
|
380
442
|
tracing?: TracingConfig;
|
|
381
443
|
runtimeProfile?: RuntimeProfile;
|
|
382
444
|
smart?: ResolvedSmartAgentConfig;
|
|
@@ -906,6 +968,7 @@ type RestoreSnapshotOptions = {
|
|
|
906
968
|
type AgentInvokeResult<TOutput = unknown> = {
|
|
907
969
|
content: string;
|
|
908
970
|
output?: TOutput;
|
|
971
|
+
outputError?: StructuredOutputError;
|
|
909
972
|
metadata: {
|
|
910
973
|
usage?: any;
|
|
911
974
|
};
|
|
@@ -971,24 +1034,6 @@ declare function createToolLimitFinalizeNode(_opts: SmartAgentOptions): (state:
|
|
|
971
1034
|
*/
|
|
972
1035
|
declare function createContextSummarizeNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
|
|
973
1036
|
|
|
974
|
-
type TokenLimits = {
|
|
975
|
-
contextTokenLimit: number;
|
|
976
|
-
summaryTokenLimit: number;
|
|
977
|
-
};
|
|
978
|
-
declare function applyTokenLimits({ state, limits, }: {
|
|
979
|
-
state: {
|
|
980
|
-
messages: Message[];
|
|
981
|
-
summaries?: string[];
|
|
982
|
-
};
|
|
983
|
-
limits: {
|
|
984
|
-
contextTokenLimit: number;
|
|
985
|
-
summaryTokenLimit: number;
|
|
986
|
-
};
|
|
987
|
-
}): Promise<{
|
|
988
|
-
messages: Message[];
|
|
989
|
-
summaries?: string[];
|
|
990
|
-
}>;
|
|
991
|
-
|
|
992
1037
|
/**
|
|
993
1038
|
* Estimates token count from text using a character-based heuristic.
|
|
994
1039
|
*
|
|
@@ -1048,7 +1093,6 @@ declare class InMemoryMemoryStore implements MemoryStore {
|
|
|
1048
1093
|
declare function resolveMemoryStore(config: ResolvedSmartAgentConfig): MemoryStore | undefined;
|
|
1049
1094
|
declare function readMemoryFacts(store: MemoryStore | undefined, config: ResolvedSmartAgentConfig, query: string): Promise<MemoryFact[]>;
|
|
1050
1095
|
declare function writeSummaryFactsToMemory(store: MemoryStore | undefined, config: ResolvedSmartAgentConfig, summary: StructuredSummary | undefined, sourceTurn: number): Promise<MemoryFact[]>;
|
|
1051
|
-
declare function renderMemoryFacts(facts: MemoryFact[]): string;
|
|
1052
1096
|
|
|
1053
1097
|
declare const DEFAULT_PROFILE_CONFIGS: Record<BuiltInRuntimeProfile, ProfileConfig>;
|
|
1054
1098
|
declare function normalizeSmartAgentOptions(opts: SmartAgentOptions): ResolvedSmartAgentConfig;
|
|
@@ -1176,6 +1220,152 @@ type CodeGuardrailOptions = GuardrailPresetBase & {
|
|
|
1176
1220
|
};
|
|
1177
1221
|
declare function createCodeGuardrail(options?: CodeGuardrailOptions): ConversationGuardrail;
|
|
1178
1222
|
|
|
1223
|
+
/**
|
|
1224
|
+
* Centralized manager for structured output across both base Agent and SmartAgent.
|
|
1225
|
+
*
|
|
1226
|
+
* Responsibilities:
|
|
1227
|
+
* - Prepare tools or response_format depending on the resolved strategy
|
|
1228
|
+
* - Build system prompt hints tailored to the strategy
|
|
1229
|
+
* - Build nudge/correction prompts for retries
|
|
1230
|
+
* - Parse final output from tool result or assistant content
|
|
1231
|
+
* - Report structured errors (never silently swallow)
|
|
1232
|
+
*/
|
|
1233
|
+
declare class StructuredOutputManager<T> {
|
|
1234
|
+
readonly strategy: StructuredOutputStrategy;
|
|
1235
|
+
readonly schema: ZodSchema<T>;
|
|
1236
|
+
readonly maxRetries: number;
|
|
1237
|
+
constructor(schema: ZodSchema<T>, strategy: StructuredOutputStrategy, config?: StructuredOutputManagerConfig);
|
|
1238
|
+
/**
|
|
1239
|
+
* Get the `response` tool for tool-based strategy.
|
|
1240
|
+
* Returns undefined for native strategy (no tool needed).
|
|
1241
|
+
*/
|
|
1242
|
+
getResponseTool(): ToolInterface | undefined;
|
|
1243
|
+
/**
|
|
1244
|
+
* Get response_format config for native strategy.
|
|
1245
|
+
* Returns undefined for tool-based strategy.
|
|
1246
|
+
*/
|
|
1247
|
+
getResponseFormat(): Record<string, any> | undefined;
|
|
1248
|
+
/**
|
|
1249
|
+
* Build the system prompt hint that tells the model how to produce structured output.
|
|
1250
|
+
*/
|
|
1251
|
+
buildSystemPromptHint(): string;
|
|
1252
|
+
/**
|
|
1253
|
+
* Build a nudge message for when the model didn't produce structured output.
|
|
1254
|
+
* Used by the agent loop when it needs to retry.
|
|
1255
|
+
*/
|
|
1256
|
+
buildNudgeMessage(isLastAttempt: boolean): {
|
|
1257
|
+
role: string;
|
|
1258
|
+
content: string;
|
|
1259
|
+
};
|
|
1260
|
+
/**
|
|
1261
|
+
* Build a correction message when schema validation failed.
|
|
1262
|
+
*/
|
|
1263
|
+
buildCorrectionMessage(error: StructuredOutputError, _previousAttempt?: unknown): {
|
|
1264
|
+
role: string;
|
|
1265
|
+
content: string;
|
|
1266
|
+
};
|
|
1267
|
+
/**
|
|
1268
|
+
* Try to parse structured output from the tool-based finalization result.
|
|
1269
|
+
* Called when __structuredOutputParsed is available in ctx.
|
|
1270
|
+
*/
|
|
1271
|
+
parseFromToolResult(data: unknown): StructuredOutputResult<T>;
|
|
1272
|
+
/**
|
|
1273
|
+
* Try to parse structured output from assistant message content.
|
|
1274
|
+
* For native strategy: content should be valid JSON.
|
|
1275
|
+
* For tool-based strategy: last-resort fallback extraction from text.
|
|
1276
|
+
*/
|
|
1277
|
+
parseFromContent(content: string): StructuredOutputResult<T>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Create a "no output" error result.
|
|
1280
|
+
*/
|
|
1281
|
+
noOutputResult(attempts: number, rawContent?: string): StructuredOutputResult<T>;
|
|
1282
|
+
/**
|
|
1283
|
+
* Create a "max retries" error result.
|
|
1284
|
+
*/
|
|
1285
|
+
maxRetriesResult(lastError: StructuredOutputError, attempts: number, rawContent?: string): StructuredOutputResult<T>;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Tool-based structured output strategy.
|
|
1290
|
+
*
|
|
1291
|
+
* Injects a hidden `response` tool that the model must call with the final JSON.
|
|
1292
|
+
* This is the universal fallback that works with all providers.
|
|
1293
|
+
*/
|
|
1294
|
+
declare class ToolBasedStrategy implements StructuredOutputStrategy {
|
|
1295
|
+
readonly kind: "tool_based";
|
|
1296
|
+
/**
|
|
1297
|
+
* Create the `response` tool for a given Zod schema.
|
|
1298
|
+
* The tool validates input against the schema and returns a sentinel object
|
|
1299
|
+
* that the tools node picks up to finalize the structured output.
|
|
1300
|
+
*/
|
|
1301
|
+
createResponseTool<T>(schema: ZodSchema<T>): ToolInterface;
|
|
1302
|
+
/**
|
|
1303
|
+
* Try to extract structured output from raw assistant text content.
|
|
1304
|
+
* Used as a last resort when the model writes JSON directly instead of calling the tool.
|
|
1305
|
+
*/
|
|
1306
|
+
extractFromText<T>(content: string, schema: ZodSchema<T>): {
|
|
1307
|
+
data: T;
|
|
1308
|
+
} | {
|
|
1309
|
+
error: StructuredOutputError;
|
|
1310
|
+
};
|
|
1311
|
+
buildCorrectionPrompt(error: ZodError<any>, previousAttempt: unknown): string;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Native JSON Schema strategy for providers that support `response_format`.
|
|
1316
|
+
*
|
|
1317
|
+
* Works with OpenAI (gpt-4o+), Google Gemini, and similar providers
|
|
1318
|
+
* that accept `response_format: { type: "json_schema", json_schema: {...} }`.
|
|
1319
|
+
*
|
|
1320
|
+
* The model guarantees valid JSON output matching the schema — no tool needed.
|
|
1321
|
+
*/
|
|
1322
|
+
declare class NativeJsonSchemaStrategy implements StructuredOutputStrategy {
|
|
1323
|
+
readonly kind: "native";
|
|
1324
|
+
private resolveJsonPointer;
|
|
1325
|
+
private unwrapRootObjectSchema;
|
|
1326
|
+
private normalizeOpenAIStrictSchema;
|
|
1327
|
+
/**
|
|
1328
|
+
* Convert a Zod schema to the JSON Schema object used in response_format.
|
|
1329
|
+
*/
|
|
1330
|
+
toJsonSchema(schema: ZodSchema<any>, name?: string): Record<string, any>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Build response_format configuration for the model call.
|
|
1333
|
+
* Returns the object that should be spread into model invocation options.
|
|
1334
|
+
*/
|
|
1335
|
+
buildResponseFormat(schema: ZodSchema<any>, name?: string): Record<string, any>;
|
|
1336
|
+
/**
|
|
1337
|
+
* Parse and validate model response content.
|
|
1338
|
+
* With native support, content is guaranteed JSON — but we still validate with Zod
|
|
1339
|
+
* for type safety and field-level error reporting.
|
|
1340
|
+
*/
|
|
1341
|
+
extractOutput<T>(content: string, schema: ZodSchema<T>): {
|
|
1342
|
+
data: T;
|
|
1343
|
+
} | {
|
|
1344
|
+
error: StructuredOutputError;
|
|
1345
|
+
};
|
|
1346
|
+
buildCorrectionPrompt(error: ZodError<any>, previousAttempt: unknown): string;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Resolve the most appropriate structured output strategy for a given model.
|
|
1351
|
+
*
|
|
1352
|
+
* If the model exposes capabilities (via adapter or direct provider),
|
|
1353
|
+
* we use native JSON Schema support when available. Otherwise we fall back
|
|
1354
|
+
* to the universal tool-based approach.
|
|
1355
|
+
*
|
|
1356
|
+
* When direct providers are added to the SDK, they should set
|
|
1357
|
+
* `model.capabilities.structuredOutput = "native"` for providers that support
|
|
1358
|
+
* response_format (OpenAI, Gemini, etc.).
|
|
1359
|
+
*/
|
|
1360
|
+
declare function resolveStrategy(model: any): StructuredOutputStrategy;
|
|
1361
|
+
/**
|
|
1362
|
+
* Extract capabilities from a model object.
|
|
1363
|
+
* Supports:
|
|
1364
|
+
* - model.capabilities (set by adapters or direct providers)
|
|
1365
|
+
* - Auto-detection from model class name / metadata
|
|
1366
|
+
*/
|
|
1367
|
+
declare function getModelCapabilities(model: any): ModelCapabilities;
|
|
1368
|
+
|
|
1179
1369
|
declare function captureSnapshot(state: SmartState, options?: SnapshotOptions): AgentSnapshot;
|
|
1180
1370
|
declare function restoreSnapshot(snapshot: AgentSnapshot, restoreOptions?: RestoreSnapshotOptions): SmartState;
|
|
1181
1371
|
|
|
@@ -1213,4 +1403,292 @@ declare function generateSpanId(): string;
|
|
|
1213
1403
|
*/
|
|
1214
1404
|
declare function startStreamingSession(session: TraceSessionRuntime | undefined, agentRuntime?: AgentRuntimeConfig): Promise<void>;
|
|
1215
1405
|
|
|
1216
|
-
|
|
1406
|
+
type MessageRole = "system" | "user" | "assistant" | "tool";
|
|
1407
|
+
type TextContent = {
|
|
1408
|
+
type: "text";
|
|
1409
|
+
text: string;
|
|
1410
|
+
};
|
|
1411
|
+
type ImageContent = {
|
|
1412
|
+
type: "image";
|
|
1413
|
+
source: {
|
|
1414
|
+
type: "base64";
|
|
1415
|
+
mediaType: string;
|
|
1416
|
+
data: string;
|
|
1417
|
+
} | {
|
|
1418
|
+
type: "url";
|
|
1419
|
+
url: string;
|
|
1420
|
+
};
|
|
1421
|
+
};
|
|
1422
|
+
type ContentPart = TextContent | ImageContent;
|
|
1423
|
+
type ToolCall = {
|
|
1424
|
+
id: string;
|
|
1425
|
+
name: string;
|
|
1426
|
+
arguments: string;
|
|
1427
|
+
};
|
|
1428
|
+
type UnifiedMessage = {
|
|
1429
|
+
role: MessageRole;
|
|
1430
|
+
content: string | ContentPart[];
|
|
1431
|
+
name?: string;
|
|
1432
|
+
toolCalls?: ToolCall[];
|
|
1433
|
+
toolCallId?: string;
|
|
1434
|
+
};
|
|
1435
|
+
type ToolDefinition = {
|
|
1436
|
+
name: string;
|
|
1437
|
+
description: string;
|
|
1438
|
+
parameters: Record<string, any>;
|
|
1439
|
+
strict?: boolean;
|
|
1440
|
+
};
|
|
1441
|
+
type ChatCompletionRequest = {
|
|
1442
|
+
model: string;
|
|
1443
|
+
messages: UnifiedMessage[];
|
|
1444
|
+
temperature?: number;
|
|
1445
|
+
maxTokens?: number;
|
|
1446
|
+
topP?: number;
|
|
1447
|
+
stop?: string[];
|
|
1448
|
+
tools?: ToolDefinition[];
|
|
1449
|
+
toolChoice?: "auto" | "required" | "none" | {
|
|
1450
|
+
name: string;
|
|
1451
|
+
};
|
|
1452
|
+
responseFormat?: {
|
|
1453
|
+
type: "json_schema" | "json_object" | "text";
|
|
1454
|
+
schema?: Record<string, any>;
|
|
1455
|
+
name?: string;
|
|
1456
|
+
};
|
|
1457
|
+
stream?: boolean;
|
|
1458
|
+
extra?: Record<string, any>;
|
|
1459
|
+
};
|
|
1460
|
+
type TokenUsage = {
|
|
1461
|
+
inputTokens: number;
|
|
1462
|
+
outputTokens: number;
|
|
1463
|
+
totalTokens: number;
|
|
1464
|
+
cachedInputTokens: number;
|
|
1465
|
+
cachedWriteTokens: number;
|
|
1466
|
+
cachedOutputTokens: number;
|
|
1467
|
+
reasoningTokens: number;
|
|
1468
|
+
};
|
|
1469
|
+
declare function emptyUsage(): TokenUsage;
|
|
1470
|
+
type FinishReason = "stop" | "tool_calls" | "length" | "content_filter" | "error";
|
|
1471
|
+
type ChatCompletionResponse = {
|
|
1472
|
+
id: string;
|
|
1473
|
+
model: string;
|
|
1474
|
+
content: string | null;
|
|
1475
|
+
toolCalls: ToolCall[];
|
|
1476
|
+
usage: TokenUsage;
|
|
1477
|
+
finishReason: FinishReason;
|
|
1478
|
+
raw: any;
|
|
1479
|
+
};
|
|
1480
|
+
type ChatCompletionChunk = {
|
|
1481
|
+
id: string;
|
|
1482
|
+
model: string;
|
|
1483
|
+
delta: {
|
|
1484
|
+
content?: string;
|
|
1485
|
+
toolCalls?: Partial<ToolCall>[];
|
|
1486
|
+
};
|
|
1487
|
+
usage?: TokenUsage;
|
|
1488
|
+
finishReason?: FinishReason;
|
|
1489
|
+
};
|
|
1490
|
+
type OpenAIProviderConfig = {
|
|
1491
|
+
provider: "openai";
|
|
1492
|
+
apiKey: string;
|
|
1493
|
+
baseURL?: string;
|
|
1494
|
+
organization?: string;
|
|
1495
|
+
defaultModel?: string;
|
|
1496
|
+
defaultHeaders?: Record<string, string>;
|
|
1497
|
+
};
|
|
1498
|
+
type AnthropicProviderConfig = {
|
|
1499
|
+
provider: "anthropic";
|
|
1500
|
+
apiKey: string;
|
|
1501
|
+
baseURL?: string;
|
|
1502
|
+
defaultModel?: string;
|
|
1503
|
+
defaultHeaders?: Record<string, string>;
|
|
1504
|
+
anthropicVersion?: string;
|
|
1505
|
+
};
|
|
1506
|
+
type AzureProviderConfig = {
|
|
1507
|
+
provider: "azure";
|
|
1508
|
+
apiKey: string;
|
|
1509
|
+
endpoint: string;
|
|
1510
|
+
apiVersion?: string;
|
|
1511
|
+
deploymentName?: string;
|
|
1512
|
+
defaultModel?: string;
|
|
1513
|
+
defaultHeaders?: Record<string, string>;
|
|
1514
|
+
};
|
|
1515
|
+
type OpenAICompatibleProviderConfig = {
|
|
1516
|
+
provider: "openai-compatible";
|
|
1517
|
+
apiKey: string;
|
|
1518
|
+
baseURL: string;
|
|
1519
|
+
defaultModel?: string;
|
|
1520
|
+
defaultHeaders?: Record<string, string>;
|
|
1521
|
+
};
|
|
1522
|
+
type BedrockProviderConfig = {
|
|
1523
|
+
provider: "bedrock";
|
|
1524
|
+
region: string;
|
|
1525
|
+
accessKeyId?: string;
|
|
1526
|
+
secretAccessKey?: string;
|
|
1527
|
+
sessionToken?: string;
|
|
1528
|
+
defaultModel?: string;
|
|
1529
|
+
defaultHeaders?: Record<string, string>;
|
|
1530
|
+
};
|
|
1531
|
+
type VertexProviderConfig = {
|
|
1532
|
+
provider: "vertex";
|
|
1533
|
+
projectId: string;
|
|
1534
|
+
location?: string;
|
|
1535
|
+
accessToken?: string;
|
|
1536
|
+
serviceAccountJson?: string | Record<string, any>;
|
|
1537
|
+
defaultModel?: string;
|
|
1538
|
+
defaultHeaders?: Record<string, string>;
|
|
1539
|
+
};
|
|
1540
|
+
type ProviderConfig = OpenAIProviderConfig | AnthropicProviderConfig | AzureProviderConfig | OpenAICompatibleProviderConfig | BedrockProviderConfig | VertexProviderConfig;
|
|
1541
|
+
type ProviderType = ProviderConfig["provider"];
|
|
1542
|
+
declare class ProviderError extends Error {
|
|
1543
|
+
readonly provider: string;
|
|
1544
|
+
readonly statusCode?: number | undefined;
|
|
1545
|
+
readonly responseBody?: any | undefined;
|
|
1546
|
+
constructor(message: string, provider: string, statusCode?: number | undefined, responseBody?: any | undefined);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
declare abstract class BaseProvider {
|
|
1550
|
+
abstract readonly providerName: ProviderType;
|
|
1551
|
+
/** Non-streaming completion */
|
|
1552
|
+
abstract complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1553
|
+
/** Streaming completion – yields incremental chunks */
|
|
1554
|
+
abstract completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
declare class OpenAIProvider extends BaseProvider {
|
|
1558
|
+
readonly providerName: ProviderType;
|
|
1559
|
+
protected readonly apiKey: string;
|
|
1560
|
+
protected readonly baseURL: string;
|
|
1561
|
+
protected readonly defaultModel: string;
|
|
1562
|
+
protected readonly defaultHeaders: Record<string, string>;
|
|
1563
|
+
constructor(config: OpenAIProviderConfig);
|
|
1564
|
+
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1565
|
+
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
1566
|
+
protected buildRequestBody(request: ChatCompletionRequest, stream: boolean): Record<string, any>;
|
|
1567
|
+
protected toOpenAIMessage(m: UnifiedMessage): Record<string, any>;
|
|
1568
|
+
protected toOpenAITool(t: ToolDefinition): Record<string, any>;
|
|
1569
|
+
protected doFetch(body: Record<string, any>): Promise<Response>;
|
|
1570
|
+
protected parseResponse(json: any): ChatCompletionResponse;
|
|
1571
|
+
protected extractUsage(usage: any): TokenUsage;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
declare class AnthropicProvider extends BaseProvider {
|
|
1575
|
+
readonly providerName: ProviderType;
|
|
1576
|
+
private readonly apiKey;
|
|
1577
|
+
private readonly baseURL;
|
|
1578
|
+
private readonly defaultModel;
|
|
1579
|
+
private readonly defaultHeaders;
|
|
1580
|
+
private readonly anthropicVersion;
|
|
1581
|
+
constructor(config: AnthropicProviderConfig);
|
|
1582
|
+
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1583
|
+
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
1584
|
+
private buildRequestBody;
|
|
1585
|
+
private splitSystemMessages;
|
|
1586
|
+
private toAnthropicMessage;
|
|
1587
|
+
private toAnthropicTool;
|
|
1588
|
+
private doFetch;
|
|
1589
|
+
private parseResponse;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
declare class AzureProvider extends OpenAIProvider {
|
|
1593
|
+
readonly providerName: ProviderType;
|
|
1594
|
+
private readonly endpoint;
|
|
1595
|
+
private readonly apiVersion;
|
|
1596
|
+
private readonly deploymentName?;
|
|
1597
|
+
private readonly azureApiKey;
|
|
1598
|
+
constructor(config: AzureProviderConfig);
|
|
1599
|
+
protected doFetch(body: Record<string, any>): Promise<Response>;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
declare class OpenAICompatibleProvider extends OpenAIProvider {
|
|
1603
|
+
readonly providerName: ProviderType;
|
|
1604
|
+
constructor(config: OpenAICompatibleProviderConfig);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
declare class BedrockProvider extends BaseProvider {
|
|
1608
|
+
readonly providerName: ProviderType;
|
|
1609
|
+
private readonly region;
|
|
1610
|
+
private readonly credentials;
|
|
1611
|
+
private readonly defaultModel;
|
|
1612
|
+
private readonly defaultHeaders;
|
|
1613
|
+
constructor(config: BedrockProviderConfig);
|
|
1614
|
+
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1615
|
+
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
1616
|
+
private buildConverseBody;
|
|
1617
|
+
private splitSystemMessages;
|
|
1618
|
+
private toBedrockMessage;
|
|
1619
|
+
private toBedrockTool;
|
|
1620
|
+
private doFetch;
|
|
1621
|
+
private parseResponse;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
declare class VertexProvider extends BaseProvider {
|
|
1625
|
+
readonly providerName: ProviderType;
|
|
1626
|
+
private readonly projectId;
|
|
1627
|
+
private readonly location;
|
|
1628
|
+
private readonly defaultModel;
|
|
1629
|
+
private readonly defaultHeaders;
|
|
1630
|
+
private accessToken?;
|
|
1631
|
+
private serviceAccountJson?;
|
|
1632
|
+
private tokenExpiry;
|
|
1633
|
+
constructor(config: VertexProviderConfig);
|
|
1634
|
+
complete(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
1635
|
+
completeStream(request: ChatCompletionRequest): AsyncGenerator<ChatCompletionChunk, void, unknown>;
|
|
1636
|
+
private buildUrl;
|
|
1637
|
+
private buildGeminiBody;
|
|
1638
|
+
private buildContents;
|
|
1639
|
+
private toGeminiContent;
|
|
1640
|
+
private toGeminiTool;
|
|
1641
|
+
private getAccessToken;
|
|
1642
|
+
private getTokenFromServiceAccount;
|
|
1643
|
+
private doFetch;
|
|
1644
|
+
private parseResponse;
|
|
1645
|
+
private parseStreamChunk;
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
type NativeModelOptions = {
|
|
1649
|
+
/** Override the model ID per adapter instance */
|
|
1650
|
+
model?: string;
|
|
1651
|
+
/** Default temperature */
|
|
1652
|
+
temperature?: number;
|
|
1653
|
+
/** Default max tokens */
|
|
1654
|
+
maxTokens?: number;
|
|
1655
|
+
/** Provider-specific extras passed on every request */
|
|
1656
|
+
extra?: Record<string, any>;
|
|
1657
|
+
};
|
|
1658
|
+
/**
|
|
1659
|
+
* Creates a BaseChatModel from a native provider.
|
|
1660
|
+
*
|
|
1661
|
+
* Usage:
|
|
1662
|
+
* ```ts
|
|
1663
|
+
* const provider = createProvider({ provider: "openai", apiKey: "..." });
|
|
1664
|
+
* const model = fromNativeProvider(provider, { model: "gpt-4o" });
|
|
1665
|
+
* const agent = createSmartAgent({ model, tools: [...] });
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
declare function fromNativeProvider(provider: BaseProvider, options?: NativeModelOptions): BaseChatModel;
|
|
1669
|
+
|
|
1670
|
+
/**
|
|
1671
|
+
* Factory function to create a provider from a config object.
|
|
1672
|
+
*
|
|
1673
|
+
* @example
|
|
1674
|
+
* ```ts
|
|
1675
|
+
* const provider = createProvider({
|
|
1676
|
+
* provider: "openai",
|
|
1677
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
1678
|
+
* });
|
|
1679
|
+
*
|
|
1680
|
+
* // Direct usage
|
|
1681
|
+
* const response = await provider.complete({
|
|
1682
|
+
* model: "gpt-4o",
|
|
1683
|
+
* messages: [{ role: "user", content: "Hello!" }],
|
|
1684
|
+
* });
|
|
1685
|
+
*
|
|
1686
|
+
* // Or wrap as BaseChatModel for agent-sdk
|
|
1687
|
+
* import { fromNativeProvider } from "./adapter";
|
|
1688
|
+
* const model = fromNativeProvider(provider, { model: "gpt-4o" });
|
|
1689
|
+
* const agent = createSmartAgent({ model, tools: [...] });
|
|
1690
|
+
* ```
|
|
1691
|
+
*/
|
|
1692
|
+
declare function createProvider(config: ProviderConfig): BaseProvider;
|
|
1693
|
+
|
|
1694
|
+
export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, AnthropicProvider, type AnthropicProviderConfig, AzureProvider, type AzureProviderConfig, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, BaseProvider, BedrockProvider, type BedrockProviderConfig, type BuiltInRuntimeProfile, type CancellationTokenLike, type CancelledEvent, type ChatCompletionChunk, type ChatCompletionRequest, type ChatCompletionResponse, type ChildContextPolicy, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ContextPolicy, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, DEFAULT_PROFILE_CONFIGS, type DelegationMode, type EvalCase, type EvalCaseResult, type EvalFamily, type EvalHarnessMetrics, type EvalHarnessParams, type EvalHarnessResult, type EvalProfileDescriptor, type EvalProfileTarget, type FinalAnswerEvent, type FinishReason, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type HandoffEvent, InMemoryMemoryStore, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type MemoryFact, type MemoryProviderKind, type MemoryReadPolicy, type MemoryScope, type MemoryStore, type MemoryWritePolicy, type Message, type MetadataEvent, type ModelCapabilities, NativeJsonSchemaStrategy, type NativeModelOptions, OpenAICompatibleProvider, type OpenAICompatibleProviderConfig, OpenAIProvider, type OpenAIProviderConfig, type PendingToolApproval, type PlanEvent, type PlanStepRecord, type PlanningMode, type ProfileConfig, type ProgressEvent, type ProgressUpdate, type ProviderConfig, ProviderError, type ToolCall as ProviderToolCall, type ToolDefinition as ProviderToolDefinition, type ProviderType, type RegexGuardrailOptions, type RegexRuleOptions, type ReplanPolicy, type ResolvedSmartAgentConfig, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type RuntimeProfile, type SerializableSmartState, 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 StructuredOutputError, type StructuredOutputFieldError, StructuredOutputManager, type StructuredOutputManagerConfig, type StructuredOutputResult, type StructuredOutputStrategy, type StructuredSummary, type SummarizationEvent, type SummarizationMode, type SummaryFactItem, type SummaryIntegrityCheck, type TokenUsage, type ToolApprovalEvent, type ToolApprovalResolution, type ToolApprovalStatus, ToolBasedStrategy, type ToolCallEvent, type ToolInterface, type ToolResponseClassification, type ToolResponseRetentionPolicy, 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 TraceToolResultSection, type TracingConfig, type TracingMode, type UnifiedMessage, VertexProvider, type VertexProviderConfig, agentVerdictRule, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createProvider, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, emptyUsage, evaluateGuardrails, fileSink, formatZodError, fromLangchainModel, fromLangchainTools, fromNativeProvider, generateSpanId, generateTraceId, getModelCapabilities, getNestedValue, getResolvedSmartConfig, httpSink, isSmartModel, jsonSchemaRule, normalizeSmartAgentOptions, otlpSink, readMemoryFacts, regexRule, resolveMemoryStore, resolveStrategy, resolveToolApprovalState, restoreSnapshot, runSmartAgentEvalHarness, startStreamingSession, traceSessionToOtlp, withTools, writeSummaryFactsToMemory };
|