@axlsdk/axl 0.13.0 → 0.13.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
@@ -940,6 +940,12 @@ declare class MemoryManager {
940
940
  * Wraps Zod v4's built-in `z.toJSONSchema()`, stripping the `$schema` key
941
941
  * since tool parameter schemas are embedded objects, not standalone documents. */
942
942
  declare function zodToJsonSchema(schema: z.ZodType): Record<string, unknown>;
943
+ /**
944
+ * Extract JSON from LLM response content.
945
+ * Handles: raw JSON, markdown fenced blocks (```json ... ```),
946
+ * and content with leading/trailing text around a JSON object/array.
947
+ */
948
+ declare function extractJson(content: string): string;
943
949
  type WorkflowContextInit = {
944
950
  input: unknown;
945
951
  executionId: string;
@@ -1938,4 +1944,4 @@ declare class NoopSpanManager implements SpanManager {
1938
1944
  */
1939
1945
  declare function createSpanManager(config?: TelemetryConfig): Promise<SpanManager>;
1940
1946
 
1941
- export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type CreateContextOptions, type DelegateOptions, type Effort, type Embedder, type EvalHistoryEntry, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type OutputValidator, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type ValidateResult, ValidationError, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VerifyRetry, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
1947
+ export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type CreateContextOptions, type DelegateOptions, type Effort, type Embedder, type EvalHistoryEntry, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type OutputValidator, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type ValidateResult, ValidationError, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VerifyRetry, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, extractJson, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -940,6 +940,12 @@ declare class MemoryManager {
940
940
  * Wraps Zod v4's built-in `z.toJSONSchema()`, stripping the `$schema` key
941
941
  * since tool parameter schemas are embedded objects, not standalone documents. */
942
942
  declare function zodToJsonSchema(schema: z.ZodType): Record<string, unknown>;
943
+ /**
944
+ * Extract JSON from LLM response content.
945
+ * Handles: raw JSON, markdown fenced blocks (```json ... ```),
946
+ * and content with leading/trailing text around a JSON object/array.
947
+ */
948
+ declare function extractJson(content: string): string;
943
949
  type WorkflowContextInit = {
944
950
  input: unknown;
945
951
  executionId: string;
@@ -1938,4 +1944,4 @@ declare class NoopSpanManager implements SpanManager {
1938
1944
  */
1939
1945
  declare function createSpanManager(config?: TelemetryConfig): Promise<SpanManager>;
1940
1946
 
1941
- export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type CreateContextOptions, type DelegateOptions, type Effort, type Embedder, type EvalHistoryEntry, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type OutputValidator, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type ValidateResult, ValidationError, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VerifyRetry, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
1947
+ export { type Agent, type AgentCallInfo, type AgentConfig, AnthropicProvider, type AskOptions, type AwaitHumanOptions, type AxlConfig, AxlError, AxlRuntime, AxlStream, BudgetExceededError, type BudgetOptions, type BudgetResult, type ChatMessage, type ChatOptions, type CreateContextOptions, type DelegateOptions, type Effort, type Embedder, type EvalHistoryEntry, type ExecutionInfo, type ExecutionState, GeminiProvider, type GuardrailBlockHandler, GuardrailError, type GuardrailResult, type GuardrailsConfig, type HandoffDescriptor, type HandoffRecord, type HumanDecision, InMemoryVectorStore, type InputGuardrail, type MapOptions, MaxTurnsError, McpManager, type McpServer, type McpServerConfig, type McpToolDefinition, type McpToolResult, type MemoryConfig, MemoryManager, MemoryStore, NoConsensus, NoopSpanManager, OpenAIEmbedder, OpenAIProvider, OpenAIResponsesProvider, type OutputGuardrail, type OutputValidator, type PendingDecision, type Provider, type ProviderAdapter, ProviderRegistry, type ProviderResponse, QuorumNotMet, type RaceOptions, type RecallOptions, RedisStore, type RememberOptions, type ResolvedThinkingOptions, type Result, type RetryPolicy, SQLiteStore, Session, type SessionOptions, type SpanHandle, type SpanManager, type SpawnOptions, SqliteVectorStore, type StateStore, type StreamChunk, type StreamEvent, type TelemetryConfig, TimeoutError, type Tool, type ToolCallMessage, type ToolChoice, type ToolConfig, ToolDenied, type ToolHooks, type TraceEvent, type ValidateResult, ValidationError, type VectorEntry, type VectorResult, type VectorStore, VerifyError, type VerifyOptions, type VerifyRetry, type VoteOptions, type Workflow, type WorkflowConfig, WorkflowContext, type WorkflowContextInit, agent, createSpanManager, defineConfig, extractJson, resolveThinkingOptions, tool, workflow, zodToJsonSchema };
package/dist/index.js CHANGED
@@ -2109,15 +2109,54 @@ function zodToJsonSchema(schema) {
2109
2109
  function estimateTokens(text) {
2110
2110
  return Math.ceil(text.length / 4);
2111
2111
  }
2112
- function stripMarkdownFences(text) {
2113
- const trimmed = text.trim();
2114
- if (trimmed.startsWith("```")) {
2115
- const withoutOpening = trimmed.replace(/^```\w*\s*\n?/, "");
2116
- const withoutClosing = withoutOpening.replace(/\n?```\s*$/, "");
2117
- return withoutClosing.trim();
2112
+ function extractJson(content) {
2113
+ const trimmed = content.trim();
2114
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
2115
+ return trimmed;
2116
+ }
2117
+ const fenceMatch = trimmed.match(/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/);
2118
+ if (fenceMatch) {
2119
+ return fenceMatch[1].trim();
2120
+ }
2121
+ const open = trimmed.indexOf("{");
2122
+ if (open >= 0) {
2123
+ const extracted = extractBalanced(trimmed, open, "{", "}");
2124
+ if (extracted) return extracted;
2125
+ }
2126
+ const openBracket = trimmed.indexOf("[");
2127
+ if (openBracket >= 0) {
2128
+ const extracted = extractBalanced(trimmed, openBracket, "[", "]");
2129
+ if (extracted) return extracted;
2118
2130
  }
2119
2131
  return trimmed;
2120
2132
  }
2133
+ function extractBalanced(str, start, openChar, closeChar) {
2134
+ let depth = 0;
2135
+ let inString = false;
2136
+ let escape = false;
2137
+ for (let i = start; i < str.length; i++) {
2138
+ const ch = str[i];
2139
+ if (escape) {
2140
+ escape = false;
2141
+ continue;
2142
+ }
2143
+ if (ch === "\\" && inString) {
2144
+ escape = true;
2145
+ continue;
2146
+ }
2147
+ if (ch === '"') {
2148
+ inString = !inString;
2149
+ continue;
2150
+ }
2151
+ if (inString) continue;
2152
+ if (ch === openChar) depth++;
2153
+ else if (ch === closeChar) {
2154
+ depth--;
2155
+ if (depth === 0) return str.slice(start, i + 1);
2156
+ }
2157
+ }
2158
+ return null;
2159
+ }
2121
2160
  function estimateMessagesTokens(messages) {
2122
2161
  let total = 0;
2123
2162
  for (const msg of messages) {
@@ -2898,7 +2937,7 @@ ${JSON.stringify(jsonSchema, null, 2)}`;
2898
2937
  let validated = void 0;
2899
2938
  if (options?.schema) {
2900
2939
  try {
2901
- const parsed = JSON.parse(stripMarkdownFences(content));
2940
+ const parsed = JSON.parse(extractJson(content));
2902
2941
  validated = options.schema.parse(parsed);
2903
2942
  } catch (err) {
2904
2943
  const maxSchemaRetries = options.retries ?? 3;
@@ -6447,6 +6486,7 @@ export {
6447
6486
  agent,
6448
6487
  createSpanManager,
6449
6488
  defineConfig,
6489
+ extractJson,
6450
6490
  resolveThinkingOptions,
6451
6491
  tool,
6452
6492
  workflow,