@looopy-ai/core 2.1.20 → 2.1.21
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/core/iteration.d.ts +1 -1
- package/dist/core/iteration.js +3 -2
- package/dist/tools/agent-tool-provider.d.ts +2 -2
- package/dist/tools/local-tools.d.ts +2 -2
- package/dist/tools/mcp-tool-provider.d.ts +2 -2
- package/dist/types/core.d.ts +3 -3
- package/dist/utils/prompt.d.ts +1 -1
- package/dist/utils/prompt.js +2 -1
- package/package.json +1 -1
package/dist/core/iteration.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Observable } from 'rxjs';
|
|
2
|
-
import type
|
|
2
|
+
import { type IterationConfig, type IterationContext } from '../types/core';
|
|
3
3
|
import type { ContextAnyEvent } from '../types/event';
|
|
4
4
|
import type { LLMMessage } from '../types/message';
|
|
5
5
|
export declare const runIteration: <AuthContext>(context: IterationContext<AuthContext>, config: IterationConfig<AuthContext>, history: LLMMessage[]) => Observable<ContextAnyEvent>;
|
package/dist/core/iteration.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { concat, defer, filter, map, mergeMap, shareReplay } from 'rxjs';
|
|
2
2
|
import { startLLMCallSpan, startLoopIterationSpan } from '../observability/spans';
|
|
3
|
+
import { isToolPlugin, } from '../types/core';
|
|
3
4
|
import { getSystemPrompts } from '../utils/prompt';
|
|
4
5
|
import { runToolCall } from './tools';
|
|
5
6
|
export const runIteration = (context, config, history) => {
|
|
@@ -59,8 +60,8 @@ const prepareMessages = async (systemPrompts, history) => {
|
|
|
59
60
|
content: sp.content,
|
|
60
61
|
})));
|
|
61
62
|
};
|
|
62
|
-
const prepareTools = async (
|
|
63
|
-
const toolPromises =
|
|
63
|
+
const prepareTools = async (plugins) => {
|
|
64
|
+
const toolPromises = plugins.filter(isToolPlugin).map((p) => p.listTools());
|
|
64
65
|
const toolArrays = await Promise.all(toolPromises);
|
|
65
66
|
return toolArrays.filter(Boolean).flat();
|
|
66
67
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import z from 'zod';
|
|
3
|
-
import type { AnyEvent, ExecutionContext,
|
|
3
|
+
import type { AnyEvent, ExecutionContext, ToolPlugin } from '../types';
|
|
4
4
|
import type { ToolCall, ToolDefinition } from '../types/tools';
|
|
5
5
|
export type HeaderFactory<AuthContext> = (context: ExecutionContext<AuthContext>, card: AgentCard) => Promise<Record<string, string | undefined>>;
|
|
6
6
|
export declare const cardSchema: z.ZodObject<{
|
|
@@ -18,7 +18,7 @@ export declare const cardSchema: z.ZodObject<{
|
|
|
18
18
|
}, z.core.$loose>>;
|
|
19
19
|
}, z.core.$strip>;
|
|
20
20
|
export type AgentCard = z.infer<typeof cardSchema>;
|
|
21
|
-
export declare class AgentToolProvider<AuthContext> implements
|
|
21
|
+
export declare class AgentToolProvider<AuthContext> implements ToolPlugin<AuthContext> {
|
|
22
22
|
readonly card: AgentCard;
|
|
23
23
|
readonly getHeaders?: HeaderFactory<AuthContext> | undefined;
|
|
24
24
|
static fromUrl: <AuthContext_1>(cardUrl: string, getHeaders?: HeaderFactory<AuthContext_1>) => Promise<AgentToolProvider<AuthContext_1>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ExecutionContext } from '../types/context';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ToolPlugin } from '../types/core';
|
|
4
4
|
import type { ToolResult } from '../types/tools';
|
|
5
5
|
type InternalToolResult = Omit<ToolResult, 'toolCallId' | 'toolName'>;
|
|
6
6
|
export type ToolHandler<TParams, AuthContext> = (params: TParams, context: ExecutionContext<AuthContext>) => Promise<InternalToolResult> | InternalToolResult;
|
|
@@ -12,5 +12,5 @@ export interface LocalToolDefinition<TSchema extends z.ZodObject, AuthContext> {
|
|
|
12
12
|
handler: ToolHandler<z.infer<TSchema>, AuthContext>;
|
|
13
13
|
}
|
|
14
14
|
export declare function tool<TSchema extends z.ZodObject, AuthContext>(definition: LocalToolDefinition<TSchema, AuthContext>): LocalToolDefinition<TSchema, AuthContext>;
|
|
15
|
-
export declare function localTools<AuthContext>(tools: LocalToolDefinition<z.ZodObject, AuthContext>[]):
|
|
15
|
+
export declare function localTools<AuthContext>(tools: LocalToolDefinition<z.ZodObject, AuthContext>[]): ToolPlugin<AuthContext>;
|
|
16
16
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ToolPlugin } from '..';
|
|
2
2
|
import type { ExecutionContext } from '../types/context';
|
|
3
3
|
import type { ToolCall, ToolDefinition } from '../types/tools';
|
|
4
4
|
export interface MCPProviderConfig<AuthContext> {
|
|
@@ -8,7 +8,7 @@ export interface MCPProviderConfig<AuthContext> {
|
|
|
8
8
|
getHeaders: (authContext?: AuthContext) => Record<string, string>;
|
|
9
9
|
}
|
|
10
10
|
export declare const mcp: <AuthContext>(config: MCPProviderConfig<AuthContext>) => McpToolProvider<AuthContext>;
|
|
11
|
-
export declare class McpToolProvider<AuthContext> implements
|
|
11
|
+
export declare class McpToolProvider<AuthContext> implements ToolPlugin<AuthContext> {
|
|
12
12
|
name: string;
|
|
13
13
|
readonly id: string;
|
|
14
14
|
private readonly client;
|
package/dist/types/core.d.ts
CHANGED
|
@@ -27,16 +27,16 @@ export type IterationConfig<AuthContext> = {
|
|
|
27
27
|
llmProvider: LLMProvider | ((context: LoopContext<AuthContext>, systemPromptMetadata: Record<string, unknown> | undefined) => LLMProvider);
|
|
28
28
|
iterationNumber: number;
|
|
29
29
|
};
|
|
30
|
-
export type Plugin<AuthContext> =
|
|
30
|
+
export type Plugin<AuthContext> = SystemPromptPlugin<AuthContext> | ToolPlugin<AuthContext>;
|
|
31
31
|
type BasePlugin = {
|
|
32
32
|
readonly name: string;
|
|
33
33
|
readonly version?: string;
|
|
34
34
|
};
|
|
35
|
-
export type SystemPromptPlugin<AuthContext> = {
|
|
35
|
+
export type SystemPromptPlugin<AuthContext> = BasePlugin & {
|
|
36
36
|
generateSystemPrompts: (context: IterationContext<AuthContext>) => SystemPrompt[] | Promise<SystemPrompt[]>;
|
|
37
37
|
};
|
|
38
38
|
export declare const isSystemPromptPlugin: <AuthContext>(plugin: Plugin<AuthContext>) => plugin is BasePlugin & SystemPromptPlugin<AuthContext>;
|
|
39
|
-
export type ToolPlugin<AuthContext> = {
|
|
39
|
+
export type ToolPlugin<AuthContext> = BasePlugin & {
|
|
40
40
|
listTools: () => Promise<ToolDefinition[]>;
|
|
41
41
|
getTool: (toolId: string) => Promise<ToolDefinition | undefined>;
|
|
42
42
|
executeTool: (toolCall: ToolCall, context: IterationContext<AuthContext>) => Observable<ContextAnyEvent | AnyEvent>;
|
package/dist/utils/prompt.d.ts
CHANGED
package/dist/utils/prompt.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { isSystemPromptPlugin, } from '../types/core';
|
|
1
2
|
export const getSystemPrompts = async (plugins, loopContext) => {
|
|
2
3
|
if (!plugins?.length) {
|
|
3
4
|
return { before: [], after: [] };
|
|
4
5
|
}
|
|
5
|
-
const prompts = await Promise.all(plugins.map((p) => p.generateSystemPrompts?.(loopContext)));
|
|
6
|
+
const prompts = await Promise.all(plugins.filter(isSystemPromptPlugin).map((p) => p.generateSystemPrompts?.(loopContext)));
|
|
6
7
|
const flattened = prompts.flat().filter((p) => p !== undefined);
|
|
7
8
|
const before = Object.freeze(flattened
|
|
8
9
|
.filter((p) => p.position === 'before')
|