@cognipeer/agent-sdk 0.1.1 → 0.1.2

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { ToolInterface as ToolInterface$1 } from '@langchain/core/tools';
2
- import { ZodSchema } from 'zod';
1
+ import { ZodSchema, z } from 'zod';
2
+ import { JSONSchema7 } from 'json-schema';
3
3
 
4
4
  interface BaseChatMessagePart {
5
5
  type?: string;
@@ -35,22 +35,6 @@ declare function isSmartModel(m: any): m is SmartModel;
35
35
  declare function withTools(model: SmartModel, tools: any[]): BaseChatModel;
36
36
  declare function fromLangchainModel(lcModel: any): BaseChatModel;
37
37
 
38
- type SmartToolFn = (args: any) => Promise<any> | any;
39
- declare function createSmartTool({ name, description, schema, func, }: {
40
- name: string;
41
- description?: string;
42
- schema: ZodSchema;
43
- func: SmartToolFn;
44
- }): ToolInterface$1;
45
- declare function createTool({ name, description, schema, func, }: {
46
- name: string;
47
- description?: string;
48
- schema: ZodSchema;
49
- func: SmartToolFn;
50
- }): ToolInterface$1;
51
-
52
- declare function buildSystemPrompt(extra?: string, planning?: boolean, name?: string): string;
53
-
54
38
  type ImageURL = {
55
39
  url: string;
56
40
  detail?: 'auto' | 'low' | 'high';
@@ -75,6 +59,9 @@ interface ToolInterface<TInput = any, TOutput = any, TCallOptions = any> {
75
59
  invoke?: (input: TInput, config?: TCallOptions) => Promise<TOutput> | TOutput;
76
60
  call?: (input: TInput, config?: TCallOptions) => Promise<TOutput> | TOutput;
77
61
  schema?: any;
62
+ needsApproval?: boolean;
63
+ approvalPrompt?: string;
64
+ approvalDefaults?: any;
78
65
  [key: string]: any;
79
66
  }
80
67
  type RunnableConfig = {
@@ -92,47 +79,289 @@ type AIMessage = BaseMessage & {
92
79
  role: 'assistant';
93
80
  };
94
81
  type Message = BaseMessage;
95
- type SmartAgentLimits = {
82
+ declare enum GuardrailPhase {
83
+ Request = "request",
84
+ Response = "response"
85
+ }
86
+ type GuardrailDisposition = "block" | "warn" | "allow";
87
+ type GuardrailContext = {
88
+ phase: GuardrailPhase;
89
+ messages: Message[];
90
+ latestMessage?: Message;
91
+ state: SmartState;
92
+ runtime?: AgentRuntimeConfig;
93
+ options: SmartAgentOptions;
94
+ };
95
+ type GuardrailRuleResult = {
96
+ passed: boolean;
97
+ reason?: string;
98
+ details?: Record<string, any>;
99
+ disposition?: GuardrailDisposition;
100
+ };
101
+ type GuardrailRule = {
102
+ id?: string;
103
+ title?: string;
104
+ description?: string;
105
+ evaluate: (context: GuardrailContext) => Promise<GuardrailRuleResult> | GuardrailRuleResult;
106
+ metadata?: Record<string, any>;
107
+ };
108
+ type GuardrailIncident = {
109
+ guardrailId?: string;
110
+ guardrailTitle?: string;
111
+ ruleId?: string;
112
+ ruleTitle?: string;
113
+ phase: GuardrailPhase;
114
+ reason?: string;
115
+ details?: Record<string, any>;
116
+ disposition: GuardrailDisposition;
117
+ };
118
+ type ConversationGuardrail = {
119
+ id?: string;
120
+ title?: string;
121
+ description?: string;
122
+ appliesTo: GuardrailPhase[];
123
+ rules: GuardrailRule[];
124
+ haltOnViolation?: boolean;
125
+ onViolation?: (incident: GuardrailIncident, context: GuardrailContext) => Promise<GuardrailDisposition | void> | GuardrailDisposition | void;
126
+ metadata?: Record<string, any>;
127
+ };
128
+ type GuardrailOutcome = {
129
+ ok: boolean;
130
+ incidents: GuardrailIncident[];
131
+ };
132
+ type AgentLimits = {
96
133
  maxToolCalls?: number;
97
- toolOutputTokenLimit?: number;
98
134
  contextTokenLimit?: number;
99
135
  summaryTokenLimit?: number;
100
- summary_token_limit?: number;
101
136
  maxToken?: number;
102
137
  maxParallelTools?: number;
103
138
  };
139
+ type SmartAgentLimits = AgentLimits;
140
+ type TraceSinkFileConfig = {
141
+ type: "file";
142
+ path?: string;
143
+ };
144
+ type TraceSinkCustomConfig = {
145
+ type: "custom";
146
+ onEvent?: (event: TraceEventRecord) => void | Promise<void>;
147
+ onSession?: (session: TraceSessionFile) => void | Promise<void>;
148
+ };
149
+ type TraceSinkCognipeerConfig = {
150
+ type: "cognipeer";
151
+ apiKey: string;
152
+ url?: string;
153
+ };
154
+ type TraceSinkHttpConfig = {
155
+ type: "http";
156
+ url: string;
157
+ headers?: Record<string, string>;
158
+ };
159
+ type TraceSinkConfig = TraceSinkFileConfig | TraceSinkCustomConfig | TraceSinkCognipeerConfig | TraceSinkHttpConfig;
160
+ type TracingConfig = {
161
+ enabled: boolean;
162
+ logData?: boolean;
163
+ sink?: TraceSinkConfig;
164
+ };
165
+ type SmartAgentTracingConfig = TracingConfig;
166
+ type AgentOptions = {
167
+ name?: string;
168
+ version?: string;
169
+ model: any;
170
+ tools?: Array<ToolInterface<any, any, any>>;
171
+ guardrails?: ConversationGuardrail[];
172
+ handoffs?: HandoffDescriptor[];
173
+ limits?: AgentLimits;
174
+ usageConverter?: (finalMessage: AIMessage, fullState: SmartState, model: any) => any;
175
+ outputSchema?: ZodSchema<any>;
176
+ tracing?: TracingConfig;
177
+ };
104
178
  type SmartAgentOptions = {
105
179
  name?: string;
180
+ version?: string;
106
181
  model: any;
107
182
  tools?: Array<ToolInterface<any, any, any>>;
108
- handoffs?: HandoffDescriptor<any, any, any>[];
109
- limits?: SmartAgentLimits;
183
+ guardrails?: ConversationGuardrail[];
184
+ handoffs?: HandoffDescriptor[];
185
+ limits?: AgentLimits;
110
186
  summarization?: boolean;
111
187
  systemPrompt?: string;
112
188
  useTodoList?: boolean;
113
189
  usageConverter?: (finalMessage: AIMessage, fullState: SmartState, model: any) => any;
114
- debug?: {
115
- enabled: boolean;
116
- path?: string;
117
- callback?: (entry: {
118
- sessionId: string;
119
- stepIndex: number;
120
- fileName: string;
121
- markdown: string;
122
- }) => void;
123
- };
124
190
  outputSchema?: ZodSchema<any>;
191
+ tracing?: TracingConfig;
125
192
  };
126
193
  type AgentRuntimeConfig = {
127
194
  name?: string;
195
+ version?: string;
128
196
  model: any;
129
197
  tools: Array<ToolInterface<any, any, any>>;
198
+ guardrails?: ConversationGuardrail[];
130
199
  systemPrompt?: string;
131
- limits?: SmartAgentLimits;
200
+ limits?: AgentLimits;
132
201
  useTodoList?: boolean;
133
202
  outputSchema?: ZodSchema<any>;
203
+ tracing?: TracingConfig;
204
+ };
205
+ type TraceMessageSection = {
206
+ id?: string;
207
+ kind: "message";
208
+ label: string;
209
+ role: string;
210
+ content: string;
211
+ metadata?: Record<string, any>;
212
+ };
213
+ type TraceToolCallSection = {
214
+ id?: string;
215
+ kind: "tool_call";
216
+ label: string;
217
+ tool: string;
218
+ arguments?: any;
219
+ };
220
+ type TraceToolResultItem = {
221
+ title?: string;
222
+ url?: string;
223
+ snippet?: string;
224
+ [key: string]: any;
225
+ };
226
+ type TraceToolResultSection = {
227
+ id?: string;
228
+ kind: "tool_result";
229
+ label: string;
230
+ tool: string;
231
+ summary?: string;
232
+ items?: TraceToolResultItem[];
233
+ output?: any;
134
234
  };
135
- type HandoffDescriptor<TIn = any, TOut = any, TParsed = any> = {
235
+ type TraceToolResponseSection = {
236
+ id?: string;
237
+ kind: "tool_response";
238
+ label: string;
239
+ tool: string;
240
+ summary?: string;
241
+ items?: TraceToolResultItem[];
242
+ output?: any;
243
+ };
244
+ type TraceSummarySection = {
245
+ id?: string;
246
+ kind: "summary";
247
+ label: string;
248
+ content: string;
249
+ };
250
+ type TraceMetadataSection = {
251
+ id?: string;
252
+ kind: "metadata";
253
+ label: string;
254
+ data: Record<string, any>;
255
+ };
256
+ type TraceDataSection = TraceMessageSection | TraceToolCallSection | TraceToolResultSection | TraceToolResponseSection | TraceSummarySection | TraceMetadataSection;
257
+ type TraceEventRecord = {
258
+ sessionId: string;
259
+ id: string;
260
+ type: string;
261
+ label: string;
262
+ sequence: number;
263
+ timestamp: string;
264
+ actor?: {
265
+ scope?: string;
266
+ name?: string;
267
+ role?: string;
268
+ version?: string;
269
+ };
270
+ status: "success" | "error" | "skipped" | "retry";
271
+ durationMs?: number;
272
+ inputTokens?: number;
273
+ outputTokens?: number;
274
+ totalTokens?: number;
275
+ cachedInputTokens?: number;
276
+ requestBytes?: number;
277
+ responseBytes?: number;
278
+ model?: string;
279
+ provider?: string;
280
+ toolExecutionId?: string;
281
+ retryOf?: string;
282
+ error?: {
283
+ message: string;
284
+ stack?: string;
285
+ } | null;
286
+ data?: {
287
+ sections: TraceDataSection[];
288
+ };
289
+ debug?: Record<string, any>;
290
+ };
291
+ type TraceErrorRecord = {
292
+ eventId: string;
293
+ message: string;
294
+ stack?: string;
295
+ type?: string;
296
+ timestamp?: string;
297
+ };
298
+ type TraceSessionSummary = {
299
+ totalDurationMs: number;
300
+ totalInputTokens: number;
301
+ totalOutputTokens: number;
302
+ totalCachedInputTokens: number;
303
+ totalBytesIn: number;
304
+ totalBytesOut: number;
305
+ eventCounts: Record<string, number>;
306
+ };
307
+ type TraceSessionStatus = "in_progress" | "success" | "error" | "partial";
308
+ type TraceSinkSnapshot = {
309
+ type: "file";
310
+ path: string;
311
+ } | {
312
+ type: "custom";
313
+ } | {
314
+ type: "cognipeer";
315
+ url: string;
316
+ } | {
317
+ type: "http";
318
+ url: string;
319
+ };
320
+ type TraceSessionConfigSnapshot = {
321
+ enabled: boolean;
322
+ logData: boolean;
323
+ sink: TraceSinkSnapshot;
324
+ };
325
+ type TraceSessionFile = {
326
+ sessionId: string;
327
+ startedAt: string;
328
+ endedAt?: string;
329
+ durationMs?: number;
330
+ agent?: {
331
+ name?: string;
332
+ version?: string;
333
+ model?: string;
334
+ provider?: string;
335
+ };
336
+ config: TraceSessionConfigSnapshot;
337
+ summary: TraceSessionSummary;
338
+ events: TraceEventRecord[];
339
+ status: TraceSessionStatus;
340
+ errors: TraceErrorRecord[];
341
+ };
342
+ type ResolvedTraceSink = {
343
+ type: "file";
344
+ baseDir: string;
345
+ } | {
346
+ type: "custom";
347
+ onEvent?: (event: TraceEventRecord) => void | Promise<void>;
348
+ onSession?: (session: TraceSessionFile) => void | Promise<void>;
349
+ } | {
350
+ type: "cognipeer";
351
+ url: string;
352
+ apiKey: string;
353
+ } | {
354
+ type: "http";
355
+ url: string;
356
+ headers?: Record<string, string>;
357
+ };
358
+ type ResolvedTraceConfig = {
359
+ enabled: boolean;
360
+ mode: "batched";
361
+ logData: boolean;
362
+ sink: ResolvedTraceSink;
363
+ };
364
+ type HandoffDescriptor<TParsed = any> = {
136
365
  type: "handoff";
137
366
  toolName: string;
138
367
  description: string;
@@ -141,10 +370,9 @@ type HandoffDescriptor<TIn = any, TOut = any, TParsed = any> = {
141
370
  __runtime: AgentRuntimeConfig;
142
371
  };
143
372
  };
144
- type SmartState = {
373
+ type AgentState = {
145
374
  messages: Message[];
146
375
  agent?: AgentRuntimeConfig;
147
- summaries?: string[];
148
376
  toolHistory?: Array<{
149
377
  executionId: string;
150
378
  toolName: string;
@@ -158,6 +386,31 @@ type SmartState = {
158
386
  tool_call_id?: string;
159
387
  fromCache?: boolean;
160
388
  }>;
389
+ toolCache?: Record<string, any>;
390
+ toolCallCount?: number;
391
+ metadata?: Record<string, any>;
392
+ ctx?: Record<string, any>;
393
+ pendingApprovals?: PendingToolApproval[];
394
+ usage?: {
395
+ perRequest: Array<{
396
+ id: string;
397
+ modelName: string;
398
+ usage: any;
399
+ timestamp: string;
400
+ turn: number;
401
+ cachedInput?: number;
402
+ }>;
403
+ totals: Record<string, {
404
+ input: number;
405
+ output: number;
406
+ total: number;
407
+ cachedInput: number;
408
+ }>;
409
+ };
410
+ guardrailResult?: GuardrailOutcome;
411
+ };
412
+ type SmartState = AgentState & {
413
+ summaries?: string[];
161
414
  toolHistoryArchived?: Array<{
162
415
  executionId: string;
163
416
  toolName: string;
@@ -171,8 +424,6 @@ type SmartState = {
171
424
  tool_call_id?: string;
172
425
  fromCache?: boolean;
173
426
  }>;
174
- toolCache?: Record<string, any>;
175
- toolCallCount?: number;
176
427
  plan?: {
177
428
  version: number;
178
429
  steps: Array<{
@@ -183,24 +434,6 @@ type SmartState = {
183
434
  lastUpdated?: string;
184
435
  } | null;
185
436
  planVersion?: number;
186
- metadata?: Record<string, any>;
187
- ctx?: Record<string, any>;
188
- usage?: {
189
- perRequest: Array<{
190
- id: string;
191
- modelName: string;
192
- usage: any;
193
- timestamp: string;
194
- turn: number;
195
- cachedInput?: number;
196
- }>;
197
- totals: Record<string, {
198
- input: number;
199
- output: number;
200
- total: number;
201
- cachedInput: number;
202
- }>;
203
- };
204
437
  };
205
438
  type ToolCallEvent = {
206
439
  type: "tool_call";
@@ -249,9 +482,86 @@ type HandoffEvent = {
249
482
  to?: string;
250
483
  toolName: string;
251
484
  };
252
- type SmartAgentEvent = ToolCallEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent;
485
+ type ToolApprovalStatus = "pending" | "approved" | "rejected" | "executed";
486
+ type PendingToolApproval = {
487
+ id: string;
488
+ toolCallId: string;
489
+ toolName: string;
490
+ args: any;
491
+ status: ToolApprovalStatus;
492
+ requestedAt: string;
493
+ decidedAt?: string;
494
+ decidedBy?: string;
495
+ comment?: string;
496
+ approvedArgs?: any;
497
+ resolvedAt?: string;
498
+ executionId?: string;
499
+ metadata?: Record<string, any>;
500
+ };
501
+ type ToolApprovalResolution = {
502
+ id: string;
503
+ approved: boolean;
504
+ approvedArgs?: any;
505
+ decidedBy?: string;
506
+ comment?: string;
507
+ };
508
+ type ToolApprovalEvent = {
509
+ type: "tool_approval";
510
+ status: "pending" | "approved" | "rejected";
511
+ id: string;
512
+ toolName: string;
513
+ toolCallId?: string;
514
+ args?: any;
515
+ decidedBy?: string;
516
+ comment?: string;
517
+ };
518
+ type GuardrailEvent = {
519
+ type: "guardrail";
520
+ phase: GuardrailPhase;
521
+ guardrailId?: string;
522
+ guardrailTitle?: string;
523
+ ruleId?: string;
524
+ ruleTitle?: string;
525
+ disposition: GuardrailDisposition;
526
+ reason?: string;
527
+ details?: Record<string, any>;
528
+ };
529
+ type SmartAgentEvent = ToolCallEvent | ToolApprovalEvent | PlanEvent | SummarizationEvent | FinalAnswerEvent | MetadataEvent | HandoffEvent | GuardrailEvent;
253
530
  type InvokeConfig = RunnableConfig & {
254
531
  onEvent?: (event: SmartAgentEvent) => void;
532
+ onStateChange?: (state: SmartState) => boolean;
533
+ checkpointReason?: string;
534
+ };
535
+ type SnapshotRuntimeHint = {
536
+ name?: string;
537
+ version?: string;
538
+ tools?: string[];
539
+ };
540
+ type SerializableSmartState = Omit<SmartState, "agent"> & {
541
+ agent?: undefined;
542
+ };
543
+ type AgentSnapshotMetadata = {
544
+ createdAt: string;
545
+ tag?: string;
546
+ paused?: {
547
+ stage?: string;
548
+ iteration?: number;
549
+ reason?: string;
550
+ } | null;
551
+ };
552
+ type AgentSnapshot = {
553
+ state: SerializableSmartState;
554
+ runtimeHint?: SnapshotRuntimeHint;
555
+ metadata: AgentSnapshotMetadata;
556
+ };
557
+ type SnapshotOptions = {
558
+ tag?: string;
559
+ includeRuntimeHint?: boolean;
560
+ };
561
+ type RestoreSnapshotOptions = {
562
+ agent?: AgentRuntimeConfig;
563
+ ctx?: Record<string, any>;
564
+ mergeCtx?: boolean;
255
565
  };
256
566
  type AgentInvokeResult<TOutput = unknown> = {
257
567
  content: string;
@@ -262,8 +572,11 @@ type AgentInvokeResult<TOutput = unknown> = {
262
572
  messages: Message[];
263
573
  state?: SmartState;
264
574
  };
265
- type SmartAgentInstance<TOutput = unknown> = {
575
+ type AgentInstance<TOutput = unknown> = {
266
576
  invoke: (input: SmartState, config?: InvokeConfig) => Promise<AgentInvokeResult<TOutput>>;
577
+ snapshot: (state: SmartState, options?: SnapshotOptions) => AgentSnapshot;
578
+ resume: (snapshot: AgentSnapshot, config?: InvokeConfig, restoreOptions?: RestoreSnapshotOptions) => Promise<AgentInvokeResult<TOutput>>;
579
+ resolveToolApproval: (state: SmartState, resolution: ToolApprovalResolution) => SmartState;
267
580
  asTool: (opts: {
268
581
  toolName: string;
269
582
  description?: string;
@@ -273,15 +586,23 @@ type SmartAgentInstance<TOutput = unknown> = {
273
586
  toolName?: string;
274
587
  description?: string;
275
588
  schema?: ZodSchema<any>;
276
- }) => HandoffDescriptor<any, any, TOutput>;
589
+ }) => HandoffDescriptor<TOutput>;
277
590
  __runtime: AgentRuntimeConfig;
278
591
  };
279
- type AgentLimits = SmartAgentLimits;
280
- type AgentOptions = SmartAgentOptions;
281
- type AgentState = SmartState;
282
- type AgentEvent = SmartAgentEvent;
283
- type AgentResult<T = unknown> = AgentInvokeResult<T>;
284
- type AgentInstance<T = unknown> = SmartAgentInstance<T>;
592
+ type SmartAgentInstance<TOutput = unknown> = AgentInstance<TOutput>;
593
+
594
+ type SmartToolFn = (args: any) => Promise<any> | any;
595
+ declare function createTool({ name, description, schema, func, needsApproval, approvalPrompt, approvalDefaults, }: {
596
+ name: string;
597
+ description?: string;
598
+ schema: ZodSchema;
599
+ func: SmartToolFn;
600
+ needsApproval?: boolean;
601
+ approvalPrompt?: string;
602
+ approvalDefaults?: any;
603
+ }): ToolInterface;
604
+
605
+ declare function buildSystemPrompt(extra?: string, planning?: boolean, name?: string): string;
285
606
 
286
607
  declare function createAgent<TOutput = unknown>(opts: AgentOptions & {
287
608
  outputSchema?: ZodSchema<TOutput>;
@@ -289,7 +610,7 @@ declare function createAgent<TOutput = unknown>(opts: AgentOptions & {
289
610
 
290
611
  declare function createAgentNode(opts: SmartAgentOptions): (state: SmartState) => Promise<Partial<SmartState>>;
291
612
 
292
- declare function createToolsNode(initialTools: Array<ToolInterface$1<any, any, any>>, opts?: SmartAgentOptions): (state: SmartState) => Promise<any>;
613
+ declare function createToolsNode(initialTools: Array<ToolInterface<any, any, any>>, opts?: SmartAgentOptions): (state: SmartState) => Promise<any>;
293
614
 
294
615
  declare function createResolverNode(): (state: SmartState) => Promise<SmartState>;
295
616
 
@@ -301,12 +622,11 @@ type TokenLimits = {
301
622
  contextTokenLimit: number;
302
623
  summaryTokenLimit: number;
303
624
  };
304
- declare function applyTokenLimits({ state, model, limits, }: {
625
+ declare function applyTokenLimits({ state, limits, }: {
305
626
  state: {
306
627
  messages: Message[];
307
628
  summaries?: string[];
308
629
  };
309
- model: any;
310
630
  limits: {
311
631
  contextTokenLimit: number;
312
632
  summaryTokenLimit: number;
@@ -327,47 +647,145 @@ declare function createContextTools(stateRef: {
327
647
  outputSchema?: any;
328
648
  }): any[];
329
649
 
330
- type DebugSession = {
331
- sessionId: string;
332
- baseDir: string;
333
- sessionDir: string;
334
- stepIndex: number;
335
- callback?: (entry: {
336
- sessionId: string;
337
- stepIndex: number;
338
- fileName: string;
339
- markdown: string;
340
- messages: Message[];
341
- usage?: any;
342
- modelName?: string;
343
- limits?: any;
344
- tools?: any[];
345
- }) => void;
346
- };
347
- declare function resolveLogsBaseDir(customPath?: string): string;
348
- declare function createDebugSession(opts: SmartAgentOptions): DebugSession | undefined;
349
- declare function bumpStep(session: DebugSession): number;
350
- type UsageLike = any;
351
- declare function getModelName(model: any): string | undefined;
352
- declare function serializeAgentTools(tools: any[]): any[];
353
- declare function formatMarkdown(params: {
354
- modelName: string | undefined;
355
- date: string;
356
- limits?: any;
357
- usage?: UsageLike;
358
- tools?: any[];
359
- messages: Message[];
360
- }): string;
361
- declare function writeStepMarkdown(session: DebugSession, fileName: string, markdown: string, payload?: {
362
- messages: Message[];
363
- usage?: any;
364
- modelName?: string;
365
- limits?: any;
366
- tools?: any[];
367
- }): Promise<void>;
368
-
369
- declare function createSmartAgent<TOutput = unknown>(opts: AgentOptions & {
650
+ declare function createSmartAgent<TOutput = unknown>(opts: SmartAgentOptions & {
370
651
  outputSchema?: ZodSchema<TOutput>;
371
- }): AgentInstance<TOutput>;
652
+ }): SmartAgentInstance<TOutput>;
653
+
654
+ type GuardrailEvaluationParams = {
655
+ guardrails?: ConversationGuardrail[];
656
+ phase: GuardrailPhase;
657
+ state: SmartState;
658
+ runtime: AgentRuntimeConfig;
659
+ options: SmartAgentOptions;
660
+ emit?: (event: SmartAgentEvent) => void;
661
+ };
662
+ declare function evaluateGuardrails(params: GuardrailEvaluationParams): Promise<GuardrailOutcome>;
663
+ type CreateGuardrailOptions = {
664
+ id?: string;
665
+ title?: string;
666
+ description?: string;
667
+ appliesTo?: GuardrailPhase[];
668
+ checks: GuardrailRule[];
669
+ haltOnViolation?: boolean;
670
+ onViolation?: ConversationGuardrail["onViolation"];
671
+ metadata?: Record<string, any>;
672
+ };
673
+ declare function createGuardrail(options: CreateGuardrailOptions): ConversationGuardrail;
674
+
675
+ type RegexRuleOptions = {
676
+ id?: string;
677
+ title?: string;
678
+ description?: string;
679
+ pattern: RegExp | string;
680
+ flags?: string;
681
+ matchDisposition?: GuardrailDisposition;
682
+ selector?: (context: GuardrailContext) => string;
683
+ allowIfMatch?: boolean;
684
+ failureMessage?: string;
685
+ };
686
+ declare function regexRule(options: RegexRuleOptions): GuardrailRule;
687
+ type JsonSchemaRuleOptions = {
688
+ id?: string;
689
+ title?: string;
690
+ description?: string;
691
+ schema: JSONSchema7 | z.ZodTypeAny;
692
+ selector?: (context: GuardrailContext) => string;
693
+ disposition?: GuardrailDisposition;
694
+ allowOnParseError?: boolean;
695
+ };
696
+ declare function jsonSchemaRule(options: JsonSchemaRuleOptions): GuardrailRule;
697
+ type CodeDetectionRuleOptions = {
698
+ id?: string;
699
+ title?: string;
700
+ description?: string;
701
+ selector?: (context: GuardrailContext) => string;
702
+ disposition?: GuardrailDisposition;
703
+ allowList?: Array<RegExp | string>;
704
+ };
705
+ declare function codePresenceRule(options?: CodeDetectionRuleOptions): GuardrailRule;
706
+ declare const guardianSchema: z.ZodObject<{
707
+ allow: z.ZodBoolean;
708
+ disposition: z.ZodOptional<z.ZodEnum<["allow", "warn", "block"]>>;
709
+ reason: z.ZodOptional<z.ZodString>;
710
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
711
+ }, "strip", z.ZodTypeAny, {
712
+ allow: boolean;
713
+ disposition?: "block" | "warn" | "allow" | undefined;
714
+ reason?: string | undefined;
715
+ details?: Record<string, any> | undefined;
716
+ }, {
717
+ allow: boolean;
718
+ disposition?: "block" | "warn" | "allow" | undefined;
719
+ reason?: string | undefined;
720
+ details?: Record<string, any> | undefined;
721
+ }>;
722
+ type AgentRuleOptions = {
723
+ id?: string;
724
+ title?: string;
725
+ description?: string;
726
+ agent: SmartAgentInstance<z.infer<typeof guardianSchema>>;
727
+ systemPrompt?: string;
728
+ payloadBuilder?: (context: GuardrailContext) => string;
729
+ dispositionFallback?: GuardrailDisposition;
730
+ };
731
+ declare function agentVerdictRule(options: AgentRuleOptions): GuardrailRule;
732
+ type CustomRuleCallback = (context: GuardrailContext) => boolean | {
733
+ allow: boolean;
734
+ reason?: string;
735
+ disposition?: GuardrailDisposition;
736
+ details?: Record<string, any>;
737
+ } | Promise<boolean | {
738
+ allow: boolean;
739
+ reason?: string;
740
+ disposition?: GuardrailDisposition;
741
+ details?: Record<string, any>;
742
+ }>;
743
+ type CustomRuleOptions = {
744
+ id?: string;
745
+ title?: string;
746
+ description?: string;
747
+ callback: CustomRuleCallback;
748
+ defaultDisposition?: GuardrailDisposition;
749
+ };
750
+ declare function customCallbackRule(options: CustomRuleOptions): GuardrailRule;
751
+
752
+ type GuardrailPresetBase = {
753
+ guardrailId?: string;
754
+ guardrailTitle?: string;
755
+ guardrailDescription?: string;
756
+ phases?: GuardrailPhase[];
757
+ haltOnViolation?: boolean;
758
+ onViolation?: ConversationGuardrail["onViolation"];
759
+ metadata?: Record<string, any>;
760
+ };
761
+ type RegexGuardrailOptions = GuardrailPresetBase & {
762
+ rule?: Omit<RegexRuleOptions, "pattern">;
763
+ };
764
+ declare function createRegexGuardrail(pattern: RegExp | string, options?: RegexGuardrailOptions): ConversationGuardrail;
765
+ type JsonGuardrailOptions = GuardrailPresetBase & {
766
+ rule?: Omit<JsonSchemaRuleOptions, "schema">;
767
+ };
768
+ declare function createJsonGuardrail(schema: JsonSchemaRuleOptions["schema"], options?: JsonGuardrailOptions): ConversationGuardrail;
769
+ type CodeGuardrailOptions = GuardrailPresetBase & {
770
+ rule?: CodeDetectionRuleOptions;
771
+ };
772
+ declare function createCodeGuardrail(options?: CodeGuardrailOptions): ConversationGuardrail;
773
+
774
+ declare function captureSnapshot(state: SmartState, options?: SnapshotOptions): AgentSnapshot;
775
+ declare function restoreSnapshot(snapshot: AgentSnapshot, restoreOptions?: RestoreSnapshotOptions): SmartState;
776
+
777
+ declare function resolveToolApprovalState(state: SmartState, resolution: ToolApprovalResolution): SmartState;
778
+
779
+ declare function fromLangchainTools<T extends ToolInterface = ToolInterface>(tools: any[]): T[];
780
+
781
+ declare function fileSink(path?: string): TraceSinkConfig;
782
+ type CustomSinkArg = ((event: TraceEventRecord) => void | Promise<void>) | {
783
+ onEvent?: (event: TraceEventRecord) => void | Promise<void>;
784
+ onSession?: (session: TraceSessionFile) => void | Promise<void>;
785
+ };
786
+ declare function customSink(handler: CustomSinkArg): TraceSinkConfig;
787
+ declare function cognipeerSink(apiKey: string): TraceSinkConfig;
788
+ declare function cognipeerSink(url: string | undefined, apiKey: string): TraceSinkConfig;
789
+ declare function httpSink(url: string, headers?: Record<string, string>): TraceSinkConfig;
372
790
 
373
- export { type AgentEvent, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentResult, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type DebugSession, type InvokeConfig, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentOptions, type SmartModel, type SmartState, type SmartToolFn, type TokenLimits, applyTokenLimits, buildSystemPrompt, bumpStep, countApproxTokens, createAgent, createAgentNode, createContextSummarizeNode, createContextTools, createDebugSession, createResolverNode, createSmartAgent, createSmartTool, createTool, createToolLimitFinalizeNode, createToolsNode, formatMarkdown, fromLangchainModel, getModelName, isSmartModel, resolveLogsBaseDir, serializeAgentTools, withTools, writeStepMarkdown };
791
+ export { type AIMessage, type AgentInstance, type AgentInvokeResult, type AgentLimits, type AgentOptions, type AgentRuleOptions, type AgentRuntimeConfig, type AgentSnapshot, type AgentSnapshotMetadata, type AgentState, type BaseChatMessage, type BaseChatMessagePart, type BaseChatModel, type BaseMessage, type CodeDetectionRuleOptions, type CodeGuardrailOptions, type ConversationGuardrail, type CustomRuleCallback, type CustomRuleOptions, type GuardrailContext, type GuardrailDisposition, type GuardrailEvent, type GuardrailIncident, type GuardrailOutcome, GuardrailPhase, type GuardrailRule, type HandoffDescriptor, type InvokeConfig, type JsonGuardrailOptions, type JsonSchemaRuleOptions, type Message, type PendingToolApproval, type RegexGuardrailOptions, type RegexRuleOptions, type ResolvedTraceConfig, type ResolvedTraceSink, type RestoreSnapshotOptions, type SerializableSmartState, type SmartAgentEvent, type SmartAgentInstance, type SmartAgentLimits, type SmartAgentOptions, type SmartAgentTracingConfig, type SmartModel, type SmartState, type SmartToolFn, type SnapshotOptions, type SnapshotRuntimeHint, type TokenLimits, type ToolApprovalEvent, type ToolApprovalResolution, type ToolInterface, 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 TraceSinkSnapshot, type TraceSummarySection, type TraceToolCallSection, type TraceToolResultSection, type TracingConfig, agentVerdictRule, applyTokenLimits, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, createAgent, createAgentNode, createCodeGuardrail, createContextSummarizeNode, createContextTools, createGuardrail, createJsonGuardrail, createRegexGuardrail, createResolverNode, createSmartAgent, createTool, createToolLimitFinalizeNode, createToolsNode, customCallbackRule, customSink, evaluateGuardrails, fileSink, fromLangchainModel, fromLangchainTools, httpSink, isSmartModel, jsonSchemaRule, regexRule, resolveToolApprovalState, restoreSnapshot, withTools };