@thanh01.pmt/curriculum-kit 1.4.31 → 1.4.32

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.
@@ -1,3 +1,44 @@
1
+ /** Định nghĩa tool (OpenAI-compatible function schema) cho LLM tool-calling */
2
+ interface ToolDefinition {
3
+ type: 'function';
4
+ function: {
5
+ name: string;
6
+ description: string;
7
+ /** JSON Schema cho tham số */
8
+ parameters: Record<string, unknown>;
9
+ };
10
+ }
11
+ /** Tool call hoàn chỉnh sau khi aggregate các delta */
12
+ interface AggregatedToolCall {
13
+ id: string;
14
+ name: string;
15
+ /** JSON string arguments từ model */
16
+ arguments: string;
17
+ }
18
+ /** Kết quả thực thi tool do caller cung cấp */
19
+ interface ToolExecutionResult {
20
+ toolCallId: string;
21
+ name: string;
22
+ /** Kết quả serialize thành JSON string khi gửi lại model */
23
+ result: unknown;
24
+ isError?: boolean;
25
+ }
26
+ /** Executor: nhận (name, parsedArgs) → kết quả. Throw = lỗi tool (báo lại model) */
27
+ type ToolExecutor = (name: string, args: Record<string, unknown>) => Promise<unknown>;
28
+ /** Cấu hình vòng lặp tool-calling */
29
+ interface ToolLoopConfig {
30
+ tools: ToolDefinition[];
31
+ executor: ToolExecutor;
32
+ /** Số vòng tool-call tối đa (chống vòng lặp vô hạn). Mặc định 4 */
33
+ maxRounds?: number;
34
+ /** Báo mỗi lần bắt đầu thực thi tool (để UI hiển thị) */
35
+ onToolStart?: (name: string, args: Record<string, unknown>) => void;
36
+ /** Báo kết quả tool */
37
+ onToolResult?: (result: ToolExecutionResult) => void;
38
+ /** Báo lỗi tool (không dừng workflow — tool error được đưa lại cho model tự xử lý) */
39
+ onToolError?: (name: string, error: string) => void;
40
+ }
41
+
1
42
  interface ChatMessage {
2
43
  role: 'user' | 'assistant' | 'system' | 'model';
3
44
  content: string;
@@ -38,6 +79,40 @@ interface StreamRunnerOptions {
38
79
  maxTokens: number;
39
80
  onChunk: (token: string, type: ChunkType) => void;
40
81
  }) => Promise<string>;
82
+ /**
83
+ * Host-provided TOOL-CALLING inference override (unified-tracing mandate,
84
+ * gap #8 audit 2026-09-14). When present, `streamCurriculumAIInferenceWithTools`
85
+ * routes every turn through this gateway instead of its built-in raw-fetch
86
+ * provider routes, so tool-loop calls emit the host's OpenTelemetry spans
87
+ * (unified Langfuse trace). The request carries the FULL conversation
88
+ * (including prior assistant tool_calls and tool results) and the OpenAI-
89
+ * compatible tool definitions; the implementation returns the turn result.
90
+ * Stream text deltas via ('content'|'thought') chunks and report token spend
91
+ * via onChunk(JSON.stringify({ promptTokens, completionTokens, totalTokens,
92
+ * reasoningTokens }), 'usage') — same contract as customInference.
93
+ */
94
+ customToolInference?: (request: {
95
+ messages: Array<{
96
+ role: string;
97
+ content: string | null;
98
+ tool_calls?: Array<{
99
+ id: string;
100
+ type: 'function';
101
+ function: {
102
+ name: string;
103
+ arguments: string;
104
+ };
105
+ }>;
106
+ tool_call_id?: string;
107
+ }>;
108
+ tools: ToolDefinition[];
109
+ temperature: number;
110
+ maxTokens: number;
111
+ onChunk: (token: string, type: ChunkType) => void;
112
+ }) => Promise<{
113
+ content: string;
114
+ toolCalls: AggregatedToolCall[];
115
+ }>;
41
116
  }
42
117
  declare function resolveApiKey(keyName: string, explicitKey?: string): string;
43
118
  /**
@@ -106,4 +181,4 @@ declare function streamCurriculumAIInference(messages: ChatMessage[], projectCon
106
181
  */
107
182
  declare function runCurriculumAIInference(messages: ChatMessage[], projectContext: string, options?: StreamRunnerOptions, onChunk?: (token: string, type: ChunkType) => void): Promise<string>;
108
183
 
109
- export { type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as k, resolveApiKey as r, streamCurriculumAIInference as s };
184
+ export { type AggregatedToolCall as A, type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, type ToolDefinition as T, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as k, type ToolExecutionResult as l, type ToolExecutor as m, type ToolLoopConfig as n, resolveApiKey as r, streamCurriculumAIInference as s };
@@ -1,3 +1,44 @@
1
+ /** Định nghĩa tool (OpenAI-compatible function schema) cho LLM tool-calling */
2
+ interface ToolDefinition {
3
+ type: 'function';
4
+ function: {
5
+ name: string;
6
+ description: string;
7
+ /** JSON Schema cho tham số */
8
+ parameters: Record<string, unknown>;
9
+ };
10
+ }
11
+ /** Tool call hoàn chỉnh sau khi aggregate các delta */
12
+ interface AggregatedToolCall {
13
+ id: string;
14
+ name: string;
15
+ /** JSON string arguments từ model */
16
+ arguments: string;
17
+ }
18
+ /** Kết quả thực thi tool do caller cung cấp */
19
+ interface ToolExecutionResult {
20
+ toolCallId: string;
21
+ name: string;
22
+ /** Kết quả serialize thành JSON string khi gửi lại model */
23
+ result: unknown;
24
+ isError?: boolean;
25
+ }
26
+ /** Executor: nhận (name, parsedArgs) → kết quả. Throw = lỗi tool (báo lại model) */
27
+ type ToolExecutor = (name: string, args: Record<string, unknown>) => Promise<unknown>;
28
+ /** Cấu hình vòng lặp tool-calling */
29
+ interface ToolLoopConfig {
30
+ tools: ToolDefinition[];
31
+ executor: ToolExecutor;
32
+ /** Số vòng tool-call tối đa (chống vòng lặp vô hạn). Mặc định 4 */
33
+ maxRounds?: number;
34
+ /** Báo mỗi lần bắt đầu thực thi tool (để UI hiển thị) */
35
+ onToolStart?: (name: string, args: Record<string, unknown>) => void;
36
+ /** Báo kết quả tool */
37
+ onToolResult?: (result: ToolExecutionResult) => void;
38
+ /** Báo lỗi tool (không dừng workflow — tool error được đưa lại cho model tự xử lý) */
39
+ onToolError?: (name: string, error: string) => void;
40
+ }
41
+
1
42
  interface ChatMessage {
2
43
  role: 'user' | 'assistant' | 'system' | 'model';
3
44
  content: string;
@@ -38,6 +79,40 @@ interface StreamRunnerOptions {
38
79
  maxTokens: number;
39
80
  onChunk: (token: string, type: ChunkType) => void;
40
81
  }) => Promise<string>;
82
+ /**
83
+ * Host-provided TOOL-CALLING inference override (unified-tracing mandate,
84
+ * gap #8 audit 2026-09-14). When present, `streamCurriculumAIInferenceWithTools`
85
+ * routes every turn through this gateway instead of its built-in raw-fetch
86
+ * provider routes, so tool-loop calls emit the host's OpenTelemetry spans
87
+ * (unified Langfuse trace). The request carries the FULL conversation
88
+ * (including prior assistant tool_calls and tool results) and the OpenAI-
89
+ * compatible tool definitions; the implementation returns the turn result.
90
+ * Stream text deltas via ('content'|'thought') chunks and report token spend
91
+ * via onChunk(JSON.stringify({ promptTokens, completionTokens, totalTokens,
92
+ * reasoningTokens }), 'usage') — same contract as customInference.
93
+ */
94
+ customToolInference?: (request: {
95
+ messages: Array<{
96
+ role: string;
97
+ content: string | null;
98
+ tool_calls?: Array<{
99
+ id: string;
100
+ type: 'function';
101
+ function: {
102
+ name: string;
103
+ arguments: string;
104
+ };
105
+ }>;
106
+ tool_call_id?: string;
107
+ }>;
108
+ tools: ToolDefinition[];
109
+ temperature: number;
110
+ maxTokens: number;
111
+ onChunk: (token: string, type: ChunkType) => void;
112
+ }) => Promise<{
113
+ content: string;
114
+ toolCalls: AggregatedToolCall[];
115
+ }>;
41
116
  }
42
117
  declare function resolveApiKey(keyName: string, explicitKey?: string): string;
43
118
  /**
@@ -106,4 +181,4 @@ declare function streamCurriculumAIInference(messages: ChatMessage[], projectCon
106
181
  */
107
182
  declare function runCurriculumAIInference(messages: ChatMessage[], projectContext: string, options?: StreamRunnerOptions, onChunk?: (token: string, type: ChunkType) => void): Promise<string>;
108
183
 
109
- export { type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as k, resolveApiKey as r, streamCurriculumAIInference as s };
184
+ export { type AggregatedToolCall as A, type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, type ToolDefinition as T, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as k, type ToolExecutionResult as l, type ToolExecutor as m, type ToolLoopConfig as n, resolveApiKey as r, streamCurriculumAIInference as s };