@cognipeer/agent-sdk 0.2.5 → 0.2.7
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.cjs +311 -175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -8
- package/dist/index.d.ts +29 -8
- package/dist/index.mjs +311 -176
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -75,16 +75,15 @@ interface ToolInterface<TInput = any, TOutput = any, TCallOptions = any> {
|
|
|
75
75
|
approvalDefaults?: any;
|
|
76
76
|
[key: string]: any;
|
|
77
77
|
}
|
|
78
|
-
type RunnableConfig =
|
|
79
|
-
[key: string]: any;
|
|
80
|
-
};
|
|
78
|
+
type RunnableConfig = Record<string, unknown>;
|
|
81
79
|
type BaseMessage = {
|
|
82
80
|
role: string;
|
|
83
81
|
name?: string;
|
|
84
82
|
content: string | ContentPart[];
|
|
85
83
|
tool_calls?: any;
|
|
86
84
|
tool_call_id?: string;
|
|
87
|
-
|
|
85
|
+
metadata?: Record<string, any>;
|
|
86
|
+
additional_kwargs?: Record<string, any>;
|
|
88
87
|
};
|
|
89
88
|
type AIMessage = BaseMessage & {
|
|
90
89
|
role: 'assistant';
|
|
@@ -144,6 +143,7 @@ type AgentLimits = {
|
|
|
144
143
|
maxToolCalls?: number;
|
|
145
144
|
maxParallelTools?: number;
|
|
146
145
|
};
|
|
146
|
+
/** @deprecated Use AgentLimits instead */
|
|
147
147
|
type SmartAgentLimits = AgentLimits;
|
|
148
148
|
type TraceSinkFileConfig = {
|
|
149
149
|
type: "file";
|
|
@@ -176,11 +176,12 @@ type TracingConfig = {
|
|
|
176
176
|
mode?: TracingMode;
|
|
177
177
|
sink?: TraceSinkConfig;
|
|
178
178
|
};
|
|
179
|
+
/** @deprecated Use TracingConfig instead */
|
|
179
180
|
type SmartAgentTracingConfig = TracingConfig;
|
|
180
181
|
type AgentOptions = {
|
|
181
182
|
name?: string;
|
|
182
183
|
version?: string;
|
|
183
|
-
model:
|
|
184
|
+
model: BaseChatModel;
|
|
184
185
|
tools?: Array<ToolInterface<any, any, any>>;
|
|
185
186
|
guardrails?: ConversationGuardrail[];
|
|
186
187
|
handoffs?: HandoffDescriptor[];
|
|
@@ -192,7 +193,7 @@ type AgentOptions = {
|
|
|
192
193
|
type SmartAgentOptions = {
|
|
193
194
|
name?: string;
|
|
194
195
|
version?: string;
|
|
195
|
-
model:
|
|
196
|
+
model: BaseChatModel;
|
|
196
197
|
tools?: Array<ToolInterface<any, any, any>>;
|
|
197
198
|
guardrails?: ConversationGuardrail[];
|
|
198
199
|
handoffs?: HandoffDescriptor[];
|
|
@@ -214,7 +215,7 @@ type SmartAgentOptions = {
|
|
|
214
215
|
type AgentRuntimeConfig = {
|
|
215
216
|
name?: string;
|
|
216
217
|
version?: string;
|
|
217
|
-
model:
|
|
218
|
+
model: BaseChatModel;
|
|
218
219
|
tools: Array<ToolInterface<any, any, any>>;
|
|
219
220
|
guardrails?: ConversationGuardrail[];
|
|
220
221
|
systemPrompt?: string;
|
|
@@ -747,7 +748,27 @@ declare function applyTokenLimits({ state, limits, }: {
|
|
|
747
748
|
summaries?: string[];
|
|
748
749
|
}>;
|
|
749
750
|
|
|
751
|
+
/**
|
|
752
|
+
* Estimates token count from text using a character-based heuristic.
|
|
753
|
+
*
|
|
754
|
+
* This is a rough approximation:
|
|
755
|
+
* - For Latin/ASCII text: ~4 characters per token (GPT-family models)
|
|
756
|
+
* - For CJK/Unicode text: ~1.5 characters per token
|
|
757
|
+
*
|
|
758
|
+
* For production accuracy, consider using a proper tokenizer like tiktoken.
|
|
759
|
+
*/
|
|
750
760
|
declare function countApproxTokens(text: string): number;
|
|
761
|
+
/**
|
|
762
|
+
* Estimates the total token count for an array of messages.
|
|
763
|
+
*
|
|
764
|
+
* Unlike counting only `.content`, this includes:
|
|
765
|
+
* - `tool_calls[].function.arguments` (can be massive JSON)
|
|
766
|
+
* - `tool_calls[].function.name`
|
|
767
|
+
* - `additional_kwargs.tool_calls` (LangChain/Bedrock)
|
|
768
|
+
* - Per-message overhead (role, name, formatting)
|
|
769
|
+
* - Anthropic tool_use content blocks
|
|
770
|
+
*/
|
|
771
|
+
declare function countMessagesTokens(messages: any[]): number;
|
|
751
772
|
|
|
752
773
|
declare function createContextTools(stateRef: {
|
|
753
774
|
toolHistory?: any[];
|
|
@@ -904,4 +925,4 @@ declare function httpSink(url: string, headers?: Record<string, string>): TraceS
|
|
|
904
925
|
*/
|
|
905
926
|
declare function startStreamingSession(session: TraceSessionRuntime | undefined, agentRuntime?: AgentRuntimeConfig): Promise<void>;
|
|
906
927
|
|
|
907
|
-
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, type TracingMode, 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, startStreamingSession, withTools };
|
|
928
|
+
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, type TracingMode, agentVerdictRule, applyTokenLimits, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, 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, startStreamingSession, withTools };
|
package/dist/index.d.ts
CHANGED
|
@@ -75,16 +75,15 @@ interface ToolInterface<TInput = any, TOutput = any, TCallOptions = any> {
|
|
|
75
75
|
approvalDefaults?: any;
|
|
76
76
|
[key: string]: any;
|
|
77
77
|
}
|
|
78
|
-
type RunnableConfig =
|
|
79
|
-
[key: string]: any;
|
|
80
|
-
};
|
|
78
|
+
type RunnableConfig = Record<string, unknown>;
|
|
81
79
|
type BaseMessage = {
|
|
82
80
|
role: string;
|
|
83
81
|
name?: string;
|
|
84
82
|
content: string | ContentPart[];
|
|
85
83
|
tool_calls?: any;
|
|
86
84
|
tool_call_id?: string;
|
|
87
|
-
|
|
85
|
+
metadata?: Record<string, any>;
|
|
86
|
+
additional_kwargs?: Record<string, any>;
|
|
88
87
|
};
|
|
89
88
|
type AIMessage = BaseMessage & {
|
|
90
89
|
role: 'assistant';
|
|
@@ -144,6 +143,7 @@ type AgentLimits = {
|
|
|
144
143
|
maxToolCalls?: number;
|
|
145
144
|
maxParallelTools?: number;
|
|
146
145
|
};
|
|
146
|
+
/** @deprecated Use AgentLimits instead */
|
|
147
147
|
type SmartAgentLimits = AgentLimits;
|
|
148
148
|
type TraceSinkFileConfig = {
|
|
149
149
|
type: "file";
|
|
@@ -176,11 +176,12 @@ type TracingConfig = {
|
|
|
176
176
|
mode?: TracingMode;
|
|
177
177
|
sink?: TraceSinkConfig;
|
|
178
178
|
};
|
|
179
|
+
/** @deprecated Use TracingConfig instead */
|
|
179
180
|
type SmartAgentTracingConfig = TracingConfig;
|
|
180
181
|
type AgentOptions = {
|
|
181
182
|
name?: string;
|
|
182
183
|
version?: string;
|
|
183
|
-
model:
|
|
184
|
+
model: BaseChatModel;
|
|
184
185
|
tools?: Array<ToolInterface<any, any, any>>;
|
|
185
186
|
guardrails?: ConversationGuardrail[];
|
|
186
187
|
handoffs?: HandoffDescriptor[];
|
|
@@ -192,7 +193,7 @@ type AgentOptions = {
|
|
|
192
193
|
type SmartAgentOptions = {
|
|
193
194
|
name?: string;
|
|
194
195
|
version?: string;
|
|
195
|
-
model:
|
|
196
|
+
model: BaseChatModel;
|
|
196
197
|
tools?: Array<ToolInterface<any, any, any>>;
|
|
197
198
|
guardrails?: ConversationGuardrail[];
|
|
198
199
|
handoffs?: HandoffDescriptor[];
|
|
@@ -214,7 +215,7 @@ type SmartAgentOptions = {
|
|
|
214
215
|
type AgentRuntimeConfig = {
|
|
215
216
|
name?: string;
|
|
216
217
|
version?: string;
|
|
217
|
-
model:
|
|
218
|
+
model: BaseChatModel;
|
|
218
219
|
tools: Array<ToolInterface<any, any, any>>;
|
|
219
220
|
guardrails?: ConversationGuardrail[];
|
|
220
221
|
systemPrompt?: string;
|
|
@@ -747,7 +748,27 @@ declare function applyTokenLimits({ state, limits, }: {
|
|
|
747
748
|
summaries?: string[];
|
|
748
749
|
}>;
|
|
749
750
|
|
|
751
|
+
/**
|
|
752
|
+
* Estimates token count from text using a character-based heuristic.
|
|
753
|
+
*
|
|
754
|
+
* This is a rough approximation:
|
|
755
|
+
* - For Latin/ASCII text: ~4 characters per token (GPT-family models)
|
|
756
|
+
* - For CJK/Unicode text: ~1.5 characters per token
|
|
757
|
+
*
|
|
758
|
+
* For production accuracy, consider using a proper tokenizer like tiktoken.
|
|
759
|
+
*/
|
|
750
760
|
declare function countApproxTokens(text: string): number;
|
|
761
|
+
/**
|
|
762
|
+
* Estimates the total token count for an array of messages.
|
|
763
|
+
*
|
|
764
|
+
* Unlike counting only `.content`, this includes:
|
|
765
|
+
* - `tool_calls[].function.arguments` (can be massive JSON)
|
|
766
|
+
* - `tool_calls[].function.name`
|
|
767
|
+
* - `additional_kwargs.tool_calls` (LangChain/Bedrock)
|
|
768
|
+
* - Per-message overhead (role, name, formatting)
|
|
769
|
+
* - Anthropic tool_use content blocks
|
|
770
|
+
*/
|
|
771
|
+
declare function countMessagesTokens(messages: any[]): number;
|
|
751
772
|
|
|
752
773
|
declare function createContextTools(stateRef: {
|
|
753
774
|
toolHistory?: any[];
|
|
@@ -904,4 +925,4 @@ declare function httpSink(url: string, headers?: Record<string, string>): TraceS
|
|
|
904
925
|
*/
|
|
905
926
|
declare function startStreamingSession(session: TraceSessionRuntime | undefined, agentRuntime?: AgentRuntimeConfig): Promise<void>;
|
|
906
927
|
|
|
907
|
-
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, type TracingMode, 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, startStreamingSession, withTools };
|
|
928
|
+
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, type TracingMode, agentVerdictRule, applyTokenLimits, buildSystemPrompt, captureSnapshot, codePresenceRule, cognipeerSink, countApproxTokens, countMessagesTokens, 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, startStreamingSession, withTools };
|