@crewai-ts/core 0.1.2 → 0.1.5

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.
Files changed (92) hide show
  1. package/dist/a2a.d.ts +1684 -0
  2. package/dist/a2ui-schemas.d.ts +3312 -0
  3. package/dist/a2ui.d.ts +379 -0
  4. package/dist/agent-adapters.d.ts +178 -0
  5. package/dist/agent-executors.d.ts +508 -0
  6. package/dist/agent-parser.d.ts +44 -0
  7. package/dist/agent-planning.d.ts +358 -0
  8. package/dist/agent-utils.d.ts +210 -0
  9. package/dist/agent.d.ts +444 -0
  10. package/dist/auth.d.ts +179 -0
  11. package/dist/config-utils.d.ts +5 -0
  12. package/dist/content-processor.d.ts +12 -0
  13. package/dist/context.d.ts +157 -0
  14. package/dist/converter.d.ts +97 -0
  15. package/dist/crew-chat.d.ts +97 -0
  16. package/dist/crew.d.ts +424 -0
  17. package/dist/decorators.d.ts +20 -0
  18. package/dist/env.d.ts +13 -0
  19. package/dist/errors.d.ts +27 -0
  20. package/dist/evaluators.d.ts +477 -0
  21. package/dist/events.d.ts +2657 -0
  22. package/dist/execution-utils.d.ts +85 -0
  23. package/dist/experimental-conversational.d.ts +181 -0
  24. package/dist/file-handler.d.ts +36 -0
  25. package/dist/file-store.d.ts +37 -0
  26. package/dist/files.d.ts +554 -0
  27. package/dist/flow-conversation.d.ts +90 -0
  28. package/dist/flow-definition.d.ts +195 -0
  29. package/dist/flow-persistence.d.ts +107 -0
  30. package/dist/flow-visualization.d.ts +77 -0
  31. package/dist/flow.d.ts +927 -0
  32. package/dist/formatter.d.ts +7 -0
  33. package/dist/guardrail.d.ts +95 -0
  34. package/dist/hooks.d.ts +241 -0
  35. package/dist/human-input.d.ts +74 -0
  36. package/dist/i18n.d.ts +26 -0
  37. package/dist/index.cjs +83 -36
  38. package/dist/index.d.ts +99 -13004
  39. package/dist/index.js +82 -36
  40. package/dist/input-files.d.ts +24 -0
  41. package/dist/input-provider.d.ts +22 -0
  42. package/dist/knowledge.d.ts +353 -0
  43. package/dist/lite-agent-output.d.ts +69 -0
  44. package/dist/lite-agent.d.ts +154 -0
  45. package/dist/llm.d.ts +630 -0
  46. package/dist/llms-hooks-transport.d.ts +1 -2
  47. package/dist/lock-store.d.ts +14 -0
  48. package/dist/logger.d.ts +55 -0
  49. package/dist/mcp.d.ts +315 -0
  50. package/dist/memory.d.ts +915 -0
  51. package/dist/metadata.d.ts +9 -0
  52. package/dist/misc-compat.d.ts +125 -0
  53. package/dist/openai-completion.d.ts +324 -0
  54. package/dist/outputs.d.ts +69 -0
  55. package/dist/planning.d.ts +60 -0
  56. package/dist/plus-api.d.ts +194 -0
  57. package/dist/project-compat.d.ts +133 -0
  58. package/dist/project.d.ts +221 -0
  59. package/dist/prompts.d.ts +66 -0
  60. package/dist/provider-completions.d.ts +593 -0
  61. package/dist/rag.d.ts +1074 -0
  62. package/dist/rpm.d.ts +27 -0
  63. package/dist/rw-lock.d.ts +21 -0
  64. package/dist/schema-utils.d.ts +121 -0
  65. package/dist/security.d.ts +66 -0
  66. package/dist/settings.d.ts +103 -0
  67. package/dist/skills.d.ts +145 -0
  68. package/dist/state-provider-core.d.ts +1 -1
  69. package/dist/state.d.ts +204 -0
  70. package/dist/step-execution-context.d.ts +36 -0
  71. package/dist/streaming.d.ts +153 -0
  72. package/dist/string-utils.d.ts +12 -0
  73. package/dist/task-output-storage.d.ts +62 -0
  74. package/dist/task.d.ts +305 -0
  75. package/dist/telemetry.d.ts +91 -0
  76. package/dist/token-counter-callback.d.ts +36 -0
  77. package/dist/tools.d.ts +563 -0
  78. package/dist/tracing-utils.d.ts +56 -0
  79. package/dist/training-converter.d.ts +36 -0
  80. package/dist/training-handler.d.ts +10 -0
  81. package/dist/types.d.ts +72 -0
  82. package/dist/utilities.d.ts +130 -0
  83. package/dist/utility-types.d.ts +10 -0
  84. package/dist/version.d.ts +12 -0
  85. package/package.json +326 -4904
  86. package/dist/index.d.cts +0 -13068
  87. package/dist/llms-hooks-transport-ChGiFBiU.d.ts +0 -233
  88. package/dist/llms-hooks-transport-DZlurMUQ.d.cts +0 -233
  89. package/dist/llms-hooks-transport.d.cts +0 -2
  90. package/dist/state-provider-core-Be9RKRAm.d.cts +0 -4876
  91. package/dist/state-provider-core-Be9RKRAm.d.ts +0 -4876
  92. package/dist/state-provider-core.d.cts +0 -1
@@ -0,0 +1,7 @@
1
+ import type { Task } from "./task.js";
2
+ import type { TaskOutput } from "./outputs.js";
3
+ export declare const DIVIDERS = "\n\n----------\n\n";
4
+ export declare function aggregateRawOutputsFromTaskOutputs(taskOutputs: readonly TaskOutput[]): string;
5
+ export declare const aggregate_raw_outputs_from_task_outputs: typeof aggregateRawOutputsFromTaskOutputs;
6
+ export declare function aggregateRawOutputsFromTasks(tasks: readonly Task[] | null | undefined): string;
7
+ export declare const aggregate_raw_outputs_from_tasks: typeof aggregateRawOutputsFromTasks;
@@ -0,0 +1,95 @@
1
+ import type { LiteAgentOutput } from "./lite-agent-output.js";
2
+ import type { TaskOutput } from "./outputs.js";
3
+ import { type LLM } from "./llm.js";
4
+ export type GuardrailCallable = (output: TaskOutput | LiteAgentOutput) => readonly [boolean, unknown];
5
+ export declare const GuardrailCallable: FunctionConstructor;
6
+ export type GuardrailType = GuardrailCallable | string;
7
+ export declare const GuardrailType: Readonly<{
8
+ kind: "GuardrailType";
9
+ }>;
10
+ export type GuardrailsType = readonly GuardrailType[] | GuardrailType;
11
+ export declare const GuardrailsType: Readonly<{
12
+ kind: "GuardrailsType";
13
+ }>;
14
+ export type AsyncGuardrailCallable = (output: TaskOutput | LiteAgentOutput) => Promise<readonly [boolean, unknown]>;
15
+ export declare function _is_coroutine<T>(obj: T | PromiseLike<T>): obj is PromiseLike<T>;
16
+ export declare function _run_coroutine_sync<T>(coro: PromiseLike<T>): Promise<T>;
17
+ export declare class GuardrailResult {
18
+ readonly success: boolean;
19
+ readonly result: unknown;
20
+ readonly error: unknown;
21
+ constructor(options: {
22
+ success: boolean;
23
+ result?: unknown;
24
+ error?: unknown;
25
+ });
26
+ static fromTuple(result: readonly [boolean, unknown]): GuardrailResult;
27
+ static from_tuple(result: readonly [boolean, unknown]): GuardrailResult;
28
+ static validateResultErrorExclusivity(value: unknown, info?: {
29
+ data?: Record<string, unknown>;
30
+ }): unknown;
31
+ static validate_result_error_exclusivity(value: unknown, info?: {
32
+ data?: Record<string, unknown>;
33
+ }): unknown;
34
+ }
35
+ export declare function serializeGuardrailForJson(value: unknown, fieldName?: string): string | null;
36
+ export declare const serialize_guardrail_for_json: typeof serializeGuardrailForJson;
37
+ export declare function serializeGuardrailsForJson(value: unknown, fieldName?: string): readonly string[] | string | null;
38
+ export declare const serialize_guardrails_for_json: typeof serializeGuardrailsForJson;
39
+ export declare function processGuardrail(output: TaskOutput | LiteAgentOutput, guardrail: GuardrailCallable | null | undefined, options?: {
40
+ retryCount?: number;
41
+ retry_count?: number;
42
+ fromAgent?: unknown;
43
+ from_agent?: unknown;
44
+ fromTask?: unknown;
45
+ from_task?: unknown;
46
+ eventSource?: unknown;
47
+ event_source?: unknown;
48
+ }): GuardrailResult;
49
+ export declare const process_guardrail: typeof processGuardrail;
50
+ export type LLMGuardrailOptions = {
51
+ description: string;
52
+ llm: LLM;
53
+ };
54
+ export declare class LLMGuardrailResult {
55
+ readonly valid: boolean;
56
+ readonly feedback: string | null;
57
+ constructor(options: {
58
+ valid: boolean;
59
+ feedback?: string | null;
60
+ });
61
+ }
62
+ export declare class LLMGuardrail {
63
+ readonly description: string;
64
+ readonly llm: LLM;
65
+ constructor(options: LLMGuardrailOptions);
66
+ constructor(description: string, llm: LLM);
67
+ validateOutput(taskOutput: TaskOutput | LiteAgentOutput): Promise<LLMGuardrailResult>;
68
+ _validate_output(taskOutput: TaskOutput | LiteAgentOutput): Promise<LLMGuardrailResult>;
69
+ call(taskOutput: TaskOutput | LiteAgentOutput): Promise<readonly [boolean, unknown]>;
70
+ __call__(taskOutput: TaskOutput | LiteAgentOutput): Promise<readonly [boolean, unknown]>;
71
+ asGuardrail(): AsyncGuardrailCallable;
72
+ }
73
+ export type HallucinationGuardrailOptions = {
74
+ llm: LLM;
75
+ context?: string | null;
76
+ threshold?: number | null;
77
+ toolResponse?: string;
78
+ tool_response?: string;
79
+ };
80
+ export type HallucinationGuardrailHook = (guardrail: HallucinationGuardrail, taskOutput: TaskOutput | LiteAgentOutput) => readonly [boolean, unknown];
81
+ export declare function setHallucinationGuardrailHook(hook: HallucinationGuardrailHook | null): void;
82
+ export declare const set_hallucination_guardrail_hook: typeof setHallucinationGuardrailHook;
83
+ export declare class HallucinationGuardrail {
84
+ readonly context: string | null;
85
+ readonly llm: LLM;
86
+ readonly threshold: number | null;
87
+ readonly toolResponse: string;
88
+ readonly tool_response: string;
89
+ constructor(options: HallucinationGuardrailOptions);
90
+ constructor(llm: LLM, context?: string | null, threshold?: number | null, toolResponse?: string);
91
+ get description(): string;
92
+ call(taskOutput: TaskOutput | LiteAgentOutput): readonly [boolean, unknown];
93
+ __call__(taskOutput: TaskOutput | LiteAgentOutput): readonly [boolean, unknown];
94
+ asGuardrail(): GuardrailCallable;
95
+ }
@@ -0,0 +1,241 @@
1
+ import type { LLMResponse } from "./llm.js";
2
+ import type { LLM, LLMMessage, MaybePromise, Tool } from "./types.js";
3
+ export declare class LLMCallHookContext {
4
+ readonly executor: unknown;
5
+ readonly agent: unknown;
6
+ readonly task: unknown;
7
+ readonly crew: unknown;
8
+ readonly llm: LLM | string | null | undefined;
9
+ readonly iterations: number;
10
+ readonly messages: LLMMessage[];
11
+ response: LLMResponse | null;
12
+ constructor(options?: {
13
+ executor?: unknown;
14
+ messages?: LLMMessage[];
15
+ llm?: LLM | string | null;
16
+ agent?: unknown;
17
+ task?: unknown;
18
+ crew?: unknown;
19
+ iterations?: number;
20
+ response?: LLMResponse | null;
21
+ });
22
+ requestHumanInput(prompt: string, defaultMessage?: string): string;
23
+ request_human_input(prompt: string, defaultMessage?: string): string;
24
+ }
25
+ export declare class ToolCallHookContext {
26
+ readonly toolName: string;
27
+ readonly tool_name: string;
28
+ readonly tool: Tool;
29
+ readonly agent: unknown;
30
+ readonly task: unknown;
31
+ readonly crew: unknown;
32
+ readonly toolInput: Record<string, unknown>;
33
+ readonly tool_input: Record<string, unknown>;
34
+ toolResult: unknown;
35
+ tool_result: unknown;
36
+ constructor(options: {
37
+ toolName?: string;
38
+ tool_name?: string;
39
+ toolInput?: Record<string, unknown>;
40
+ tool_input?: Record<string, unknown>;
41
+ tool: Tool;
42
+ agent?: unknown;
43
+ task?: unknown;
44
+ crew?: unknown;
45
+ toolResult?: unknown;
46
+ tool_result?: unknown;
47
+ });
48
+ requestHumanInput(prompt: string, defaultMessage?: string): string;
49
+ request_human_input(prompt: string, defaultMessage?: string): string;
50
+ }
51
+ export type BeforeLLMCallHook = (context: LLMCallHookContext) => MaybePromise<boolean | null | undefined>;
52
+ export type AfterLLMCallHook = (context: LLMCallHookContext) => MaybePromise<string | null | undefined>;
53
+ export type BeforeToolCallHook = (context: ToolCallHookContext) => MaybePromise<boolean | null | undefined>;
54
+ export type AfterToolCallHook = (context: ToolCallHookContext) => MaybePromise<string | null | undefined>;
55
+ export declare const ContextT: Readonly<{
56
+ kind: "TypeVar";
57
+ }>;
58
+ export declare const ReturnT: Readonly<{
59
+ kind: "TypeVar";
60
+ }>;
61
+ export declare const P: Readonly<{
62
+ kind: "TypeVar";
63
+ }>;
64
+ export declare const R: Readonly<{
65
+ kind: "TypeVar";
66
+ }>;
67
+ export declare const U: Readonly<{
68
+ kind: "TypeVar";
69
+ }>;
70
+ export declare const Hook: Readonly<{
71
+ kind: "Hook";
72
+ }>;
73
+ export declare const HTTPTransportKwargs: Readonly<{
74
+ kind: "HTTPTransportKwargs";
75
+ }>;
76
+ export type HTTPTransportKwargs = Record<string, unknown>;
77
+ export declare abstract class BaseInterceptor<TOutbound = unknown, TInbound = unknown> {
78
+ abstract on_outbound(message: TOutbound): TOutbound;
79
+ abstract on_inbound(message: TInbound): TInbound;
80
+ static __get_pydantic_core_schema__(): {
81
+ type: "plain-validator";
82
+ validator: (value: unknown) => BaseInterceptor;
83
+ serialization: {
84
+ type: "identity";
85
+ };
86
+ };
87
+ static validateInterceptor(value: unknown): BaseInterceptor;
88
+ static validate_interceptor(value: unknown): BaseInterceptor;
89
+ aon_outbound(message: TOutbound): Promise<TOutbound>;
90
+ aon_inbound(message: TInbound): Promise<TInbound>;
91
+ }
92
+ export declare function _validate_interceptor(value: unknown): BaseInterceptor;
93
+ export declare class AsyncHTTPTransport {
94
+ readonly interceptor: BaseInterceptor;
95
+ readonly kwargs: HTTPTransportKwargs;
96
+ constructor(interceptor: BaseInterceptor, kwargs?: HTTPTransportKwargs);
97
+ handle_async_request(request: unknown): Promise<unknown>;
98
+ }
99
+ export declare class HTTPTransport {
100
+ readonly interceptor: BaseInterceptor;
101
+ readonly kwargs: HTTPTransportKwargs;
102
+ constructor(interceptor: BaseInterceptor, kwargs?: HTTPTransportKwargs);
103
+ handle_request(request: unknown): unknown;
104
+ }
105
+ export declare const BeforeLLMCallHook: Readonly<{
106
+ kind: "BeforeLLMCallHook";
107
+ }>;
108
+ export declare const AfterLLMCallHook: Readonly<{
109
+ kind: "AfterLLMCallHook";
110
+ }>;
111
+ export declare const BeforeToolCallHook: Readonly<{
112
+ kind: "BeforeToolCallHook";
113
+ }>;
114
+ export declare const AfterToolCallHook: Readonly<{
115
+ kind: "AfterToolCallHook";
116
+ }>;
117
+ export declare const BeforeLLMCallHookType: Readonly<{
118
+ kind: "BeforeLLMCallHook";
119
+ }>;
120
+ export declare const AfterLLMCallHookType: Readonly<{
121
+ kind: "AfterLLMCallHook";
122
+ }>;
123
+ export declare const BeforeToolCallHookType: Readonly<{
124
+ kind: "BeforeToolCallHook";
125
+ }>;
126
+ export declare const AfterToolCallHookType: Readonly<{
127
+ kind: "AfterToolCallHook";
128
+ }>;
129
+ export declare const BeforeLLMCallHookCallable: Readonly<{
130
+ kind: "BeforeLLMCallHook";
131
+ }>;
132
+ export declare const AfterLLMCallHookCallable: Readonly<{
133
+ kind: "AfterLLMCallHook";
134
+ }>;
135
+ export declare const BeforeToolCallHookCallable: Readonly<{
136
+ kind: "BeforeToolCallHook";
137
+ }>;
138
+ export declare const AfterToolCallHookCallable: Readonly<{
139
+ kind: "AfterToolCallHook";
140
+ }>;
141
+ declare class HookMethod {
142
+ readonly _meth: (...args: unknown[]) => unknown;
143
+ readonly agents: readonly string[] | null;
144
+ readonly tools: readonly string[] | null;
145
+ constructor(method: (...args: unknown[]) => unknown, options?: {
146
+ agents?: readonly string[] | null;
147
+ tools?: readonly string[] | null;
148
+ });
149
+ call(...args: unknown[]): unknown;
150
+ __call__(...args: unknown[]): unknown;
151
+ }
152
+ export declare class BeforeLLMCallHookMethod extends HookMethod {
153
+ readonly is_before_llm_call_hook = true;
154
+ constructor(method: (...args: unknown[]) => unknown, agents?: readonly string[] | null);
155
+ }
156
+ export declare class AfterLLMCallHookMethod extends HookMethod {
157
+ readonly is_after_llm_call_hook = true;
158
+ constructor(method: (...args: unknown[]) => unknown, agents?: readonly string[] | null);
159
+ }
160
+ export declare class BeforeToolCallHookMethod extends HookMethod {
161
+ readonly is_before_tool_call_hook = true;
162
+ constructor(method: (...args: unknown[]) => unknown, tools?: readonly string[] | null, agents?: readonly string[] | null);
163
+ }
164
+ export declare class AfterToolCallHookMethod extends HookMethod {
165
+ readonly is_after_tool_call_hook = true;
166
+ constructor(method: (...args: unknown[]) => unknown, tools?: readonly string[] | null, agents?: readonly string[] | null);
167
+ }
168
+ export declare function registerBeforeLlmCallHook(hook: BeforeLLMCallHook): void;
169
+ export declare const register_before_llm_call_hook: typeof registerBeforeLlmCallHook;
170
+ export declare function registerAfterLlmCallHook(hook: AfterLLMCallHook): void;
171
+ export declare const register_after_llm_call_hook: typeof registerAfterLlmCallHook;
172
+ export declare function getBeforeLlmCallHooks(): BeforeLLMCallHook[];
173
+ export declare const get_before_llm_call_hooks: typeof getBeforeLlmCallHooks;
174
+ export declare function getAfterLlmCallHooks(): AfterLLMCallHook[];
175
+ export declare const get_after_llm_call_hooks: typeof getAfterLlmCallHooks;
176
+ export declare function unregisterBeforeLlmCallHook(hook: BeforeLLMCallHook): boolean;
177
+ export declare const unregister_before_llm_call_hook: typeof unregisterBeforeLlmCallHook;
178
+ export declare function unregisterAfterLlmCallHook(hook: AfterLLMCallHook): boolean;
179
+ export declare const unregister_after_llm_call_hook: typeof unregisterAfterLlmCallHook;
180
+ export declare function clearBeforeLlmCallHooks(): number;
181
+ export declare const clear_before_llm_call_hooks: typeof clearBeforeLlmCallHooks;
182
+ export declare function clearAfterLlmCallHooks(): number;
183
+ export declare const clear_after_llm_call_hooks: typeof clearAfterLlmCallHooks;
184
+ export declare function clearAllLlmCallHooks(): [number, number];
185
+ export declare const clear_all_llm_call_hooks: typeof clearAllLlmCallHooks;
186
+ export declare function registerBeforeToolCallHook(hook: BeforeToolCallHook): void;
187
+ export declare const register_before_tool_call_hook: typeof registerBeforeToolCallHook;
188
+ export declare function registerAfterToolCallHook(hook: AfterToolCallHook): void;
189
+ export declare const register_after_tool_call_hook: typeof registerAfterToolCallHook;
190
+ export declare function getBeforeToolCallHooks(): BeforeToolCallHook[];
191
+ export declare const get_before_tool_call_hooks: typeof getBeforeToolCallHooks;
192
+ export declare function getAfterToolCallHooks(): AfterToolCallHook[];
193
+ export declare const get_after_tool_call_hooks: typeof getAfterToolCallHooks;
194
+ export declare function unregisterBeforeToolCallHook(hook: BeforeToolCallHook): boolean;
195
+ export declare const unregister_before_tool_call_hook: typeof unregisterBeforeToolCallHook;
196
+ export declare function unregisterAfterToolCallHook(hook: AfterToolCallHook): boolean;
197
+ export declare const unregister_after_tool_call_hook: typeof unregisterAfterToolCallHook;
198
+ export declare function clearBeforeToolCallHooks(): number;
199
+ export declare const clear_before_tool_call_hooks: typeof clearBeforeToolCallHooks;
200
+ export declare function clearAfterToolCallHooks(): number;
201
+ export declare const clear_after_tool_call_hooks: typeof clearAfterToolCallHooks;
202
+ export declare function clearAllToolCallHooks(): [number, number];
203
+ export declare const clear_all_tool_call_hooks: typeof clearAllToolCallHooks;
204
+ export declare function clearAllGlobalHooks(): {
205
+ llm_hooks: [number, number];
206
+ tool_hooks: [number, number];
207
+ total: [number, number];
208
+ };
209
+ export declare const clear_all_global_hooks: typeof clearAllGlobalHooks;
210
+ export type RegisteredCrewScopedHook = [
211
+ "before_llm_call" | "after_llm_call" | "before_tool_call" | "after_tool_call",
212
+ BeforeLLMCallHook | AfterLLMCallHook | BeforeToolCallHook | AfterToolCallHook
213
+ ];
214
+ export declare function registerCrewScopedHooks(instance: object): RegisteredCrewScopedHook[];
215
+ export declare function beforeLlmCall(hook: BeforeLLMCallHook, context?: ClassMethodDecoratorContext): BeforeLLMCallHook;
216
+ export declare function beforeLlmCall(options: {
217
+ agents?: readonly string[];
218
+ }): MethodDecorator;
219
+ export declare const before_llm_call: typeof beforeLlmCall;
220
+ export declare function afterLlmCall(hook: AfterLLMCallHook, context?: ClassMethodDecoratorContext): AfterLLMCallHook;
221
+ export declare function afterLlmCall(options: {
222
+ agents?: readonly string[];
223
+ }): MethodDecorator;
224
+ export declare const after_llm_call: typeof afterLlmCall;
225
+ export declare function beforeToolCall(hook: BeforeToolCallHook, context?: ClassMethodDecoratorContext): BeforeToolCallHook;
226
+ export declare function beforeToolCall(options: {
227
+ tools?: readonly string[];
228
+ agents?: readonly string[];
229
+ }): MethodDecorator;
230
+ export declare const before_tool_call: typeof beforeToolCall;
231
+ export declare function afterToolCall(hook: AfterToolCallHook, context?: ClassMethodDecoratorContext): AfterToolCallHook;
232
+ export declare function afterToolCall(options: {
233
+ tools?: readonly string[];
234
+ agents?: readonly string[];
235
+ }): MethodDecorator;
236
+ export declare const after_tool_call: typeof afterToolCall;
237
+ export declare function runBeforeLlmCallHooks(context: LLMCallHookContext): Promise<void>;
238
+ export declare function runAfterLlmCallHooks(context: LLMCallHookContext): Promise<LLMResponse>;
239
+ export declare function runBeforeToolCallHooks(context: ToolCallHookContext): Promise<void>;
240
+ export declare function runAfterToolCallHooks(context: ToolCallHookContext): Promise<unknown>;
241
+ export {};
@@ -0,0 +1,74 @@
1
+ import type { TaskOutput } from "./outputs.js";
2
+ export type HumanInputRequest = {
3
+ taskName: string | null;
4
+ taskDescription: string;
5
+ expectedOutput: string;
6
+ output: TaskOutput;
7
+ };
8
+ export type HumanInputProvider = {
9
+ requestFeedback: (request: HumanInputRequest) => string | Promise<string>;
10
+ setupMessages?: (context: ExecutorContext) => boolean;
11
+ setup_messages?: (context: ExecutorContext) => boolean;
12
+ postSetupMessages?: (context: ExecutorContext) => void;
13
+ post_setup_messages?: (context: ExecutorContext) => void;
14
+ handleFeedback?: (formattedAnswer: unknown, context: ExecutorContext) => unknown;
15
+ handle_feedback?: (formatted_answer: unknown, context: ExecutorContext) => unknown;
16
+ handleFeedbackAsync?: (formattedAnswer: unknown, context: AsyncExecutorContext) => Promise<unknown>;
17
+ handle_feedback_async?: (formatted_answer: unknown, context: AsyncExecutorContext) => Promise<unknown>;
18
+ };
19
+ export type ExecutorContext = {
20
+ task?: unknown;
21
+ crew?: unknown;
22
+ messages: unknown[];
23
+ askForHumanInput?: boolean;
24
+ ask_for_human_input?: boolean;
25
+ llm?: unknown;
26
+ agent?: unknown;
27
+ _invokeLoop?: () => unknown;
28
+ _invoke_loop?: () => unknown;
29
+ _isTrainingMode?: () => boolean;
30
+ _is_training_mode?: () => boolean;
31
+ _handleCrewTrainingOutput?: (result: unknown, humanFeedback?: string | null) => void;
32
+ _handle_crew_training_output?: (result: unknown, human_feedback?: string | null) => void;
33
+ _formatFeedbackMessage?: (feedback: string) => unknown;
34
+ _format_feedback_message?: (feedback: string) => unknown;
35
+ };
36
+ export type AsyncExecutorContext = ExecutorContext & {
37
+ _ainvokeLoop?: () => Promise<unknown>;
38
+ _ainvoke_loop?: () => Promise<unknown>;
39
+ };
40
+ export declare const HumanInputProvider: Readonly<{
41
+ kind: "HumanInputProvider";
42
+ }>;
43
+ export declare const ExecutorContext: Readonly<{
44
+ kind: "ExecutorContext";
45
+ }>;
46
+ export declare const AsyncExecutorContext: Readonly<{
47
+ kind: "AsyncExecutorContext";
48
+ }>;
49
+ export declare class SyncHumanInputProvider implements HumanInputProvider {
50
+ requestFeedback(request: HumanInputRequest): string | Promise<string>;
51
+ setupMessages(_context: ExecutorContext): boolean;
52
+ setup_messages(context: ExecutorContext): boolean;
53
+ postSetupMessages(_context: ExecutorContext): void;
54
+ post_setup_messages(context: ExecutorContext): void;
55
+ handleFeedback(formattedAnswer: unknown, context: ExecutorContext): unknown;
56
+ handle_feedback(formatted_answer: unknown, context: ExecutorContext): unknown;
57
+ handleFeedbackAsync(formattedAnswer: unknown, context: AsyncExecutorContext): Promise<unknown>;
58
+ handle_feedback_async(formatted_answer: unknown, context: AsyncExecutorContext): Promise<unknown>;
59
+ static _get_output_string(answer: unknown): string;
60
+ static _handle_training_feedback(initialAnswer: unknown, feedback: string, context: ExecutorContext): unknown;
61
+ _handle_training_feedback(initialAnswer: unknown, feedback: string, context: ExecutorContext): unknown;
62
+ _handle_regular_feedback(currentAnswer: unknown, initialFeedback: string, context: ExecutorContext): unknown;
63
+ static _handle_training_feedback_async(initialAnswer: unknown, feedback: string, context: AsyncExecutorContext): Promise<unknown>;
64
+ _handle_training_feedback_async(initialAnswer: unknown, feedback: string, context: AsyncExecutorContext): Promise<unknown>;
65
+ _handle_regular_feedback_async(currentAnswer: unknown, initialFeedback: string, context: AsyncExecutorContext): Promise<unknown>;
66
+ _prompt_input(crew?: unknown): string;
67
+ _prompt_input_async(crew?: unknown): Promise<string>;
68
+ }
69
+ export declare function _async_readline(): Promise<string>;
70
+ export declare function getHumanInputProvider(): HumanInputProvider;
71
+ export declare function setHumanInputProvider(provider: HumanInputProvider | null): HumanInputProvider | null;
72
+ export declare function get_provider(): HumanInputProvider;
73
+ export declare function set_provider(provider: HumanInputProvider): HumanInputProvider | null;
74
+ export declare function reset_provider(token: HumanInputProvider | null): void;
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export type PromptKind = "slices" | "errors" | "tools" | "reasoning" | "planning" | "hierarchical_manager_agent" | "memory";
2
+ export type PromptLeaf = string | Record<string, string>;
3
+ export type PromptCatalog = Record<string, Record<string, PromptLeaf>>;
4
+ export declare class I18N {
5
+ readonly promptFile: string | null;
6
+ readonly prompt_file: string | null;
7
+ private prompts;
8
+ constructor(options?: {
9
+ promptFile?: string | null;
10
+ prompt_file?: string | null;
11
+ prompts?: PromptCatalog;
12
+ });
13
+ loadPrompts(): this;
14
+ load_prompts(): this;
15
+ slice(slice: string): string;
16
+ errors(error: string): string;
17
+ tools(tool: string): PromptLeaf;
18
+ memory(key: string): string;
19
+ retrieve(kind: PromptKind, key: string): PromptLeaf;
20
+ private retrieveString;
21
+ }
22
+ export declare function getI18N(promptFile?: string | null): I18N;
23
+ export declare function clearI18NCache(): void;
24
+ export declare const I18N_DEFAULT: I18N;
25
+ export declare const get_i18n: typeof getI18N;
26
+ export declare const clear_i18n_cache: typeof clearI18NCache;
package/dist/index.cjs CHANGED
@@ -46193,6 +46193,7 @@ function readStringNumberBooleanRecord(value) {
46193
46193
 
46194
46194
  // src/provider-completions.ts
46195
46195
  init_cjs_shims();
46196
+ init_string_utils();
46196
46197
  var TOOL_SEARCH_TOOL_TYPES = Object.freeze([
46197
46198
  "tool_search_tool_regex_20251119",
46198
46199
  "tool_search_tool_bm25_20251119"
@@ -47347,33 +47348,37 @@ var GeminiCompletion = class _GeminiCompletion extends ConfiguredLLM {
47347
47348
  delete generationConfigBody.safety_settings;
47348
47349
  const model = this.model.replace(/^(?:gemini|google)\//, "");
47349
47350
  const baseUrl = this.baseUrl ?? "https://generativelanguage.googleapis.com/v1beta";
47350
- const requestInit = {
47351
+ const buildRequestInit = (currentContents) => ({
47351
47352
  method: "POST",
47352
47353
  headers: { "Content-Type": "application/json" },
47353
47354
  body: JSON.stringify({
47354
- contents,
47355
+ contents: currentContents,
47355
47356
  ...Object.keys(generationConfigBody).length > 0 ? { generationConfig: generationConfigBody } : {},
47356
47357
  ..."system_instruction" in requestBody ? { system_instruction: requestBody.system_instruction } : {},
47357
47358
  ..."tools" in requestBody ? { tools: requestBody.tools } : {},
47358
47359
  ..."safety_settings" in requestBody ? { safety_settings: requestBody.safety_settings } : {}
47359
- })
47360
- };
47361
- if (options?.signal) {
47362
- requestInit.signal = options.signal;
47363
- }
47364
- return fetch(
47365
- `${baseUrl.replace(/\/$/, "")}/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}`,
47366
- requestInit
47367
- ).then(async (response) => {
47360
+ }),
47361
+ ...options?.signal ? { signal: options.signal } : {}
47362
+ });
47363
+ const generateContent = async (currentContents) => {
47364
+ const response = await fetch(
47365
+ `${baseUrl.replace(/\/$/, "")}/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}`,
47366
+ buildRequestInit(currentContents)
47367
+ );
47368
47368
  const body = await response.json();
47369
47369
  if (!response.ok) {
47370
47370
  const error = readObject2(readObject2(body).error);
47371
47371
  throw new Error(scalarToString(error.message) ?? `Gemini request failed with HTTP ${response.status.toString()}.`);
47372
47372
  }
47373
+ return body;
47374
+ };
47375
+ return generateContent(contents).then(async (body) => {
47373
47376
  return await this.processResponseWithTools(
47374
47377
  body,
47375
47378
  contents,
47376
- options?.availableFunctions ?? options?.available_functions ?? null
47379
+ options?.availableFunctions ?? options?.available_functions ?? null,
47380
+ generateContent,
47381
+ geminiMaxToolRounds(options)
47377
47382
  );
47378
47383
  });
47379
47384
  }
@@ -47673,42 +47678,69 @@ ${textContent}` : textContent;
47673
47678
  static extract_structured_output_from_response(response) {
47674
47679
  return _GeminiCompletion.extractStructuredOutputFromResponse(response);
47675
47680
  }
47676
- async processResponseWithTools(response, contents = [], availableFunctions = null) {
47677
- void contents;
47678
- const candidates = readObject2(response).candidates;
47679
- if (!Array.isArray(candidates)) {
47680
- return _GeminiCompletion.extractTextFromResponse(response);
47681
- }
47682
- const first = readObject2(candidates[0]);
47683
- const rawParts = Array.isArray(readObject2(first.content).parts) ? readObject2(first.content).parts : [];
47684
- const functionCallParts = rawParts.filter((part) => Object.keys(readObject2(readObject2(part).functionCall ?? readObject2(part).function_call)).length > 0);
47685
- const nonStructuredParts = functionCallParts.filter((part) => {
47686
- const partRecord = readObject2(part);
47687
- const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
47688
- return (scalarToString(functionCall.name) ?? "") !== STRUCTURED_OUTPUT_TOOL_NAME;
47689
- });
47690
- if (nonStructuredParts.length > 0 && !availableFunctions) {
47691
- return nonStructuredParts;
47692
- }
47693
- if (nonStructuredParts.length > 0 && availableFunctions) {
47681
+ async processResponseWithTools(response, contents = [], availableFunctions = null, generateContent = null, maxToolRounds = DEFAULT_GEMINI_MAX_TOOL_ROUNDS) {
47682
+ let currentResponse = response;
47683
+ let currentContents = [...contents];
47684
+ for (let round = 0; round <= maxToolRounds; round += 1) {
47685
+ const candidates = readObject2(currentResponse).candidates;
47686
+ if (!Array.isArray(candidates)) {
47687
+ return _GeminiCompletion.extractTextFromResponse(currentResponse);
47688
+ }
47689
+ const first = readObject2(candidates[0]);
47690
+ const rawParts = Array.isArray(readObject2(first.content).parts) ? readObject2(first.content).parts : [];
47691
+ const functionCallParts = rawParts.filter((part) => Object.keys(readObject2(readObject2(part).functionCall ?? readObject2(part).function_call)).length > 0);
47692
+ const structuredOutput = _GeminiCompletion.extractStructuredOutputFromResponse(currentResponse);
47693
+ const nonStructuredParts = functionCallParts.filter((part) => {
47694
+ const partRecord = readObject2(part);
47695
+ const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
47696
+ return (scalarToString(functionCall.name) ?? "") !== STRUCTURED_OUTPUT_TOOL_NAME;
47697
+ });
47698
+ if (nonStructuredParts.length === 0) {
47699
+ return structuredOutput ?? _GeminiCompletion.extractTextFromResponse(currentResponse);
47700
+ }
47701
+ if (!availableFunctions) {
47702
+ return nonStructuredParts;
47703
+ }
47704
+ if (round >= maxToolRounds) {
47705
+ throw new Error(`Gemini tool loop exceeded max tool rounds (${String(maxToolRounds)}).`);
47706
+ }
47707
+ const functionResponseParts = [];
47708
+ let firstToolResult = null;
47694
47709
  for (const part of nonStructuredParts) {
47695
47710
  const partRecord = readObject2(part);
47696
47711
  const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
47697
- const functionName = scalarToString(functionCall.name);
47712
+ const rawFunctionName = scalarToString(functionCall.name) ?? "";
47713
+ const functionName = resolveGeminiFunctionName(rawFunctionName, availableFunctions);
47698
47714
  if (!functionName) {
47699
- continue;
47715
+ throw new Error(`Gemini requested unknown function '${rawFunctionName}'.`);
47700
47716
  }
47701
47717
  const result = await this.handleToolExecution({
47702
47718
  functionName,
47703
47719
  functionArgs: readObject2(functionCall.args),
47704
47720
  availableFunctions
47705
47721
  });
47706
- if (result !== null) {
47707
- return result;
47722
+ if (result === null) {
47723
+ throw new Error(`Gemini failed to execute function '${rawFunctionName}'.`);
47708
47724
  }
47725
+ firstToolResult ??= result;
47726
+ functionResponseParts.push({
47727
+ functionResponse: {
47728
+ name: rawFunctionName,
47729
+ response: { result }
47730
+ }
47731
+ });
47709
47732
  }
47733
+ if (!generateContent) {
47734
+ return firstToolResult;
47735
+ }
47736
+ currentContents = [
47737
+ ...currentContents,
47738
+ { role: "model", parts: rawParts },
47739
+ { role: "user", parts: functionResponseParts }
47740
+ ];
47741
+ currentResponse = await generateContent(currentContents);
47710
47742
  }
47711
- return _GeminiCompletion.extractTextFromResponse(response);
47743
+ throw new Error(`Gemini tool loop exceeded max tool rounds (${String(maxToolRounds)}).`);
47712
47744
  }
47713
47745
  async _process_response_with_tools(response, contents = [], availableFunctions = null) {
47714
47746
  return await this.processResponseWithTools(response, contents, availableFunctions);
@@ -48797,6 +48829,19 @@ function geminiVersion(model) {
48797
48829
  const match = /gemini-(\d+(?:\.\d+)?)/iu.exec(model.toLowerCase());
48798
48830
  return match ? Number.parseFloat(match[1] ?? "0") : 0;
48799
48831
  }
48832
+ var DEFAULT_GEMINI_MAX_TOOL_ROUNDS = 8;
48833
+ function geminiMaxToolRounds(options) {
48834
+ const record = readObject2(options);
48835
+ const configured = record.maxToolRounds ?? record.max_tool_rounds;
48836
+ return typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_GEMINI_MAX_TOOL_ROUNDS;
48837
+ }
48838
+ function resolveGeminiFunctionName(functionName, availableFunctions) {
48839
+ if (functionName in availableFunctions) {
48840
+ return functionName;
48841
+ }
48842
+ const sanitizedName = sanitizeToolName(functionName);
48843
+ return sanitizedName in availableFunctions ? sanitizedName : null;
48844
+ }
48800
48845
  function geminiTextParts(content) {
48801
48846
  if (Array.isArray(content)) {
48802
48847
  return content.map((item) => {
@@ -52088,9 +52133,11 @@ ${todo.description}`);
52088
52133
  if (this.tools.length === 0) {
52089
52134
  return Object.keys(options).length > 0 ? options : void 0;
52090
52135
  }
52091
- const [tools] = setupNativeTools(this.tools);
52136
+ const [tools, availableFunctions] = setupNativeTools(this.tools);
52092
52137
  if (tools.length > 0) {
52093
52138
  options.tools = tools;
52139
+ options.availableFunctions = availableFunctions;
52140
+ options.available_functions = availableFunctions;
52094
52141
  }
52095
52142
  return Object.keys(options).length > 0 ? options : void 0;
52096
52143
  }