@aigne/core 1.0.2-beta.4 → 1.0.2-beta.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 (35) hide show
  1. package/lib/dts/agent.d.ts +41 -0
  2. package/lib/dts/constants.d.ts +7 -0
  3. package/lib/dts/context.d.ts +17 -0
  4. package/lib/dts/definitions/data-type-schema.d.ts +42 -0
  5. package/lib/dts/definitions/data-type.d.ts +32 -0
  6. package/lib/dts/definitions/memory.d.ts +40 -0
  7. package/lib/dts/definitions/open-api.d.ts +36 -0
  8. package/lib/dts/function-agent.d.ts +49 -0
  9. package/lib/dts/function-runner.d.ts +25 -0
  10. package/lib/dts/index.d.ts +18 -0
  11. package/lib/dts/llm-agent.d.ts +96 -0
  12. package/lib/dts/llm-decision-agent.d.ts +73 -0
  13. package/lib/dts/llm-model.d.ts +80 -0
  14. package/lib/dts/local-function-agent.d.ts +64 -0
  15. package/lib/dts/logger.d.ts +2 -0
  16. package/lib/dts/memorable.d.ts +183 -0
  17. package/lib/dts/open-api-agent.d.ts +55 -0
  18. package/lib/dts/pipeline-agent.d.ts +79 -0
  19. package/lib/dts/runnable.d.ts +70 -0
  20. package/lib/dts/utils/constants.d.ts +1 -0
  21. package/lib/dts/utils/fetch-open-api.d.ts +2 -0
  22. package/lib/dts/utils/fetch.d.ts +1 -0
  23. package/lib/dts/utils/index.d.ts +10 -0
  24. package/lib/dts/utils/is-non-nullable.d.ts +2 -0
  25. package/lib/dts/utils/message-utils.d.ts +20 -0
  26. package/lib/dts/utils/mustache-utils.d.ts +3 -0
  27. package/lib/dts/utils/nullable.d.ts +7 -0
  28. package/lib/dts/utils/omit.d.ts +1 -0
  29. package/lib/dts/utils/open-api-parameter.d.ts +7 -0
  30. package/lib/dts/utils/ordered-map.d.ts +37 -0
  31. package/lib/dts/utils/runnable-type.d.ts +3 -0
  32. package/lib/dts/utils/stream-utils.d.ts +20 -0
  33. package/lib/dts/utils/structured-output-schema.d.ts +3 -0
  34. package/lib/dts/utils/union.d.ts +1 -0
  35. package/package.json +2 -2
@@ -0,0 +1,41 @@
1
+ import type { Context, ContextState } from "./context";
2
+ import type { MemoryItemWithScore, MemoryMessage } from "./memorable";
3
+ import { type RunOptions, Runnable, type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "./runnable";
4
+ export interface AgentProcessOptions<Memories extends {
5
+ [name: string]: MemoryItemWithScore[];
6
+ }> {
7
+ memories: Memories;
8
+ }
9
+ export declare abstract class Agent<I extends {
10
+ [key: string]: any;
11
+ } = {}, O extends {
12
+ [key: string]: any;
13
+ } = {}, Memories extends {
14
+ [name: string]: MemoryItemWithScore[];
15
+ } = {}, State extends ContextState = ContextState> extends Runnable<I, O, State> {
16
+ private getMemoryQuery;
17
+ /**
18
+ * Load memories that are defined in the agent definition.
19
+ * @param input The agent input.
20
+ * @param context The AIGNE context.
21
+ * @returns A dictionary of memories, where the key is the memory id or name and the value is an array of memory items.
22
+ */
23
+ protected loadMemories(input: I, context?: Context): Promise<Memories>;
24
+ /**
25
+ * Update memories by user messages and assistant responses.
26
+ * @param messages Messages to be added to memories.
27
+ */
28
+ protected updateMemories(messages: MemoryMessage[]): Promise<void>;
29
+ run(input: I, options: RunOptions & {
30
+ stream: true;
31
+ }): Promise<RunnableResponseStream<O>>;
32
+ run(input: I, options?: RunOptions & {
33
+ stream?: false;
34
+ }): Promise<O>;
35
+ /**
36
+ * Hook that is called before the agent result is returned.
37
+ * @param _result The agent result.
38
+ */
39
+ protected onResult(_result: O): Promise<void>;
40
+ abstract process(input: I, options: AgentProcessOptions<Memories>): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
41
+ }
@@ -0,0 +1,7 @@
1
+ export declare const TYPES: {
2
+ context: symbol;
3
+ definition: symbol;
4
+ llmModel: symbol;
5
+ functionRunner: symbol;
6
+ };
7
+ export declare const StreamTextOutputName = "$text";
@@ -0,0 +1,17 @@
1
+ import type { LLMModelConfiguration } from "./llm-model";
2
+ import type { Runnable, RunnableDefinition } from "./runnable";
3
+ export interface ContextState {
4
+ userId?: string;
5
+ sessionId?: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface ContextConfig {
9
+ llmModel?: LLMModelConfiguration;
10
+ }
11
+ export interface Context<State extends ContextState = ContextState, Config extends ContextConfig = ContextConfig> {
12
+ state: State;
13
+ config: Config;
14
+ resolve<T extends Runnable>(id: string | RunnableDefinition | T): Promise<T>;
15
+ register<R extends Array<RunnableDefinition | Runnable> = []>(...definition: R): void;
16
+ resolveDependency<T>(token: string | symbol): T;
17
+ }
@@ -0,0 +1,42 @@
1
+ import type { MakeNullablePropertyOptional } from "../utils/nullable";
2
+ import { OrderedRecord } from "../utils/ordered-map";
3
+ import type { DataType } from "./data-type";
4
+ export declare function schemaToDataType(dataType: {
5
+ [name: string]: DataTypeSchema;
6
+ }): OrderedRecord<DataType>;
7
+ export type DataTypeSchema = DataTypeSchemaString | DataTypeSchemaNumber | DataTypeSchemaBoolean | DataTypeSchemaObject | DataTypeSchemaArray;
8
+ export interface DataTypeSchemaBase {
9
+ description?: string;
10
+ required?: boolean;
11
+ }
12
+ export interface DataTypeSchemaString extends DataTypeSchemaBase {
13
+ type: "string";
14
+ }
15
+ export interface DataTypeSchemaNumber extends DataTypeSchemaBase {
16
+ type: "number";
17
+ }
18
+ export interface DataTypeSchemaBoolean extends DataTypeSchemaBase {
19
+ type: "boolean";
20
+ }
21
+ export interface DataTypeSchemaObject extends DataTypeSchemaBase {
22
+ type: "object";
23
+ properties?: {
24
+ [key: string]: DataTypeSchema;
25
+ };
26
+ }
27
+ export interface DataTypeSchemaArray extends DataTypeSchemaBase {
28
+ type: "array";
29
+ items?: DataTypeSchema;
30
+ }
31
+ type SchemaTypeInner<T extends DataTypeSchema> = T extends DataTypeSchemaString ? string : T extends DataTypeSchemaNumber ? number : T extends DataTypeSchemaBoolean ? boolean : T extends DataTypeSchemaObject ? MakeNullablePropertyOptional<{
32
+ [K in keyof T["properties"]]: SchemaType<NonNullable<T["properties"]>[K]>;
33
+ }> : T extends DataTypeSchemaArray ? T["items"] extends null | undefined ? SchemaType<{
34
+ type: "object";
35
+ }>[] : SchemaType<NonNullable<T["items"]>>[] : never;
36
+ export type SchemaType<T extends DataTypeSchema> = T["required"] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
37
+ export type SchemaMapType<T extends Record<string, DataTypeSchema>> = SchemaType<{
38
+ type: "object";
39
+ required: true;
40
+ properties: T;
41
+ }>;
42
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { OmitPropsFromUnion } from "../utils/omit";
2
+ import type { OrderedRecord } from "../utils/ordered-map";
3
+ export type DataType = DataTypeString | DataTypeNumber | DataTypeBoolean | DataTypeObject | DataTypeArray;
4
+ export interface DataTypeBase {
5
+ id: string;
6
+ name?: string;
7
+ description?: string;
8
+ required?: boolean;
9
+ }
10
+ export interface DataTypeString extends DataTypeBase {
11
+ type: "string";
12
+ defaultValue?: string;
13
+ multiline?: boolean;
14
+ }
15
+ export interface DataTypeNumber extends DataTypeBase {
16
+ type: "number";
17
+ defaultValue?: number;
18
+ }
19
+ export interface DataTypeBoolean extends DataTypeBase {
20
+ type: "boolean";
21
+ defaultValue?: boolean;
22
+ }
23
+ export interface DataTypeObject extends DataTypeBase {
24
+ type: "object";
25
+ defaultValue?: object;
26
+ properties?: OrderedRecord<DataType>;
27
+ }
28
+ export interface DataTypeArray extends DataTypeBase {
29
+ type: "array";
30
+ defaultValue?: object[];
31
+ items?: OmitPropsFromUnion<DataType, "id">;
32
+ }
@@ -0,0 +1,40 @@
1
+ import type { Memorable } from "../memorable";
2
+ import type { RunnableInput, RunnableMemory } from "../runnable";
3
+ import { OrderedRecord } from "../utils";
4
+ import type { DataTypeSchema } from "./data-type-schema";
5
+ export interface CreateRunnableMemory<I extends {
6
+ [key: string]: DataTypeSchema;
7
+ } = {}> {
8
+ /**
9
+ * Memory instance to query/store memory.
10
+ */
11
+ memory: Memorable<any>;
12
+ /**
13
+ * Custom query to retrieve memory, if not provided, all input variables will be used.
14
+ *
15
+ * @example
16
+ * {
17
+ * fromVariable: 'question' // question is a string input variable
18
+ * }
19
+ */
20
+ query?: {
21
+ /**
22
+ * Variable name from input used to query memory.
23
+ */
24
+ fromVariable?: keyof {
25
+ [key in keyof I as I[key]["type"] extends "string" ? key : never]: any;
26
+ };
27
+ };
28
+ /**
29
+ * Custom options for memory query.
30
+ */
31
+ options?: {
32
+ /**
33
+ * Number of memories to retrieve.
34
+ */
35
+ k?: number;
36
+ };
37
+ }
38
+ export declare function toRunnableMemories<I extends {}>(agentName: string, inputs: OrderedRecord<RunnableInput>, memories: {
39
+ [name: string]: CreateRunnableMemory<I>;
40
+ }): OrderedRecord<RunnableMemory>;
@@ -0,0 +1,36 @@
1
+ import type { DataType } from "./data-type";
2
+ import type { DataTypeSchema } from "./data-type-schema";
3
+ export interface BaseAuthConfig {
4
+ type: "bearer" | "basic";
5
+ token: string;
6
+ in?: "header" | "query" | "cookie";
7
+ /**
8
+ * The key to use for the token. Default `Authorization` in header and `token` in query and cookie.
9
+ */
10
+ key?: string;
11
+ }
12
+ export interface CustomAuthConfig {
13
+ type: "custom";
14
+ getValue: () => Promise<AuthResult> | AuthResult;
15
+ }
16
+ export type AuthConfig = BaseAuthConfig | CustomAuthConfig;
17
+ export type AuthType = AuthConfig["type"];
18
+ export type AuthResult = Pick<FetchRequest, "headers" | "query" | "cookies">;
19
+ type HTTPMethodLowercase = "get" | "post" | "put" | "delete" | "patch" | "head" | "options";
20
+ export type HTTPMethod = Uppercase<HTTPMethodLowercase> | Lowercase<HTTPMethodLowercase>;
21
+ export type ParameterLocation = "path" | "query" | "body" | "header" | "cookie";
22
+ export type OpenAPIDataType = DataType & {
23
+ in?: ParameterLocation;
24
+ };
25
+ export type OpenAPIDataTypeSchema = DataTypeSchema & {
26
+ in?: ParameterLocation;
27
+ };
28
+ export type FetchRequest = {
29
+ url: string;
30
+ method: HTTPMethod;
31
+ query?: Record<string, string | number | boolean>;
32
+ headers?: Record<string, string>;
33
+ cookies?: Record<string, string>;
34
+ body?: Record<string, any>;
35
+ };
36
+ export {};
@@ -0,0 +1,49 @@
1
+ import { Agent, type AgentProcessOptions } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
4
+ import { type CreateRunnableMemory } from "./definitions/memory";
5
+ import type { FunctionRunner } from "./function-runner";
6
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
7
+ import type { RunnableDefinition } from "./runnable";
8
+ export declare class FunctionAgent<I extends {
9
+ [name: string]: any;
10
+ } = {}, O extends {
11
+ [name: string]: any;
12
+ } = {}, Memories extends {
13
+ [name: string]: MemoryItemWithScore[];
14
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
15
+ definition: FunctionAgentDefinition;
16
+ runner?: FunctionRunner<I, O, Memories, State> | undefined;
17
+ static create: typeof create;
18
+ constructor(definition: FunctionAgentDefinition, context?: Context<State>, runner?: FunctionRunner<I, O, Memories, State> | undefined);
19
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
20
+ }
21
+ export interface CreateFunctionAgentOptions<I extends {
22
+ [name: string]: DataTypeSchema;
23
+ }, O extends {
24
+ [name: string]: DataTypeSchema;
25
+ }, Memories extends {
26
+ [name: string]: CreateRunnableMemory<I>;
27
+ }, State extends ContextState> {
28
+ context?: Context<State>;
29
+ name?: string;
30
+ inputs: I;
31
+ outputs: O;
32
+ memories?: Memories;
33
+ language?: string;
34
+ code: string;
35
+ }
36
+ export declare function create<I extends {
37
+ [name: string]: DataTypeSchema;
38
+ }, O extends {
39
+ [name: string]: DataTypeSchema;
40
+ }, Memories extends {
41
+ [name: string]: CreateRunnableMemory<I>;
42
+ }, State extends ContextState>({ context, ...options }: CreateFunctionAgentOptions<I, O, Memories, State>): FunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
43
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
44
+ }, State>;
45
+ export interface FunctionAgentDefinition extends RunnableDefinition {
46
+ type: "function_agent";
47
+ language?: string;
48
+ code?: string;
49
+ }
@@ -0,0 +1,25 @@
1
+ import { Agent } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import type { MemoryItemWithScore } from "./memorable";
4
+ export interface FunctionRunnerInput<I extends {
5
+ [name: string]: any;
6
+ } = {}, Memories extends {
7
+ [name: string]: MemoryItemWithScore[];
8
+ } = {}, State extends ContextState = ContextState> {
9
+ name: string;
10
+ language?: string;
11
+ code: string;
12
+ input: I;
13
+ memories: Memories;
14
+ context: Pick<Context<State>, "state">;
15
+ }
16
+ export type FunctionRunnerOutput<O> = O;
17
+ export declare abstract class FunctionRunner<I extends {
18
+ [name: string]: any;
19
+ } = {}, O extends {
20
+ [name: string]: any;
21
+ } = {}, Memories extends {
22
+ [name: string]: MemoryItemWithScore[];
23
+ } = {}, State extends ContextState = ContextState> extends Agent<FunctionRunnerInput<I, Memories, State>, FunctionRunnerOutput<O>> {
24
+ constructor(context?: Context);
25
+ }
@@ -0,0 +1,18 @@
1
+ export * from "./utils";
2
+ export * from "./constants";
3
+ export * from "./definitions/data-type";
4
+ export * from "./definitions/data-type-schema";
5
+ export * from "./definitions/open-api";
6
+ export * from "./definitions/memory";
7
+ export * from "./context";
8
+ export * from "./runnable";
9
+ export * from "./agent";
10
+ export * from "./pipeline-agent";
11
+ export * from "./llm-agent";
12
+ export * from "./llm-model";
13
+ export * from "./function-agent";
14
+ export * from "./function-runner";
15
+ export * from "./llm-decision-agent";
16
+ export * from "./local-function-agent";
17
+ export * from "./open-api-agent";
18
+ export * from "./memorable";
@@ -0,0 +1,96 @@
1
+ import { Agent, type AgentProcessOptions } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
4
+ import { type CreateRunnableMemory } from "./definitions/memory";
5
+ import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
6
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
7
+ import type { RunnableDefinition } from "./runnable";
8
+ import { OrderedRecord } from "./utils/ordered-map";
9
+ export declare class LLMAgent<I extends {
10
+ [name: string]: any;
11
+ } = {}, O extends {
12
+ [name: string]: any;
13
+ } = {}, Memories extends {
14
+ [name: string]: MemoryItemWithScore[];
15
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
16
+ definition: LLMAgentDefinition;
17
+ model?: LLMModel | undefined;
18
+ static create: typeof create;
19
+ constructor(definition: LLMAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
20
+ process(input: I, options: AgentProcessOptions<Memories>): AsyncGenerator<{
21
+ $text: string | undefined;
22
+ delta?: undefined;
23
+ } | {
24
+ delta: any;
25
+ $text?: undefined;
26
+ }, void, unknown>;
27
+ private runWithStructuredOutput;
28
+ private runWithTextOutput;
29
+ }
30
+ export interface LLMAgentDefinition extends RunnableDefinition {
31
+ type: "llm_agent";
32
+ primaryMemoryId?: string;
33
+ messages?: OrderedRecord<LLMModelInputMessage & {
34
+ id: string;
35
+ }>;
36
+ modelOptions?: LLMModelInputs["modelOptions"];
37
+ }
38
+ /**
39
+ * Options to create LLMAgent.
40
+ */
41
+ export interface CreateLLMAgentOptions<I extends {
42
+ [name: string]: DataTypeSchema;
43
+ }, O extends {
44
+ [name: string]: DataTypeSchema;
45
+ }, Memories extends {
46
+ [name: string]: CreateRunnableMemory<I>;
47
+ }, State extends ContextState> {
48
+ context?: Context<State>;
49
+ /**
50
+ * Agent name, used to identify the agent.
51
+ */
52
+ name?: string;
53
+ /**
54
+ * Input variables for this agent.
55
+ */
56
+ inputs: I;
57
+ /**
58
+ * Output variables for this agent.
59
+ */
60
+ outputs: O;
61
+ /**
62
+ * Memories to be used in this agent.
63
+ */
64
+ memories?: Memories;
65
+ /**
66
+ * Options for LLM chat model.
67
+ */
68
+ modelOptions?: LLMModelInputs["modelOptions"];
69
+ /**
70
+ * Messages to be passed to LLM chat model.
71
+ */
72
+ messages?: LLMModelInputMessage[];
73
+ }
74
+ /**
75
+ * Create LLMAgent definition.
76
+ * @param options Options to create LLMAgent.
77
+ * @returns LLMAgent definition.
78
+ */
79
+ declare function create<I extends {
80
+ [name: string]: DataTypeSchema;
81
+ }, O extends {
82
+ [name: string]: DataTypeSchema;
83
+ }, Memories extends {
84
+ [name: string]: CreateRunnableMemory<I> & {
85
+ /**
86
+ * Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
87
+ * otherwise, it will be placed in a system message.
88
+ *
89
+ * Only one primary memory is allowed.
90
+ */
91
+ primary?: boolean;
92
+ };
93
+ }, State extends ContextState>({ context, ...options }: CreateLLMAgentOptions<I, O, Memories, State>): LLMAgent<SchemaMapType<I>, SchemaMapType<O>, {
94
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
95
+ }, State>;
96
+ export {};
@@ -0,0 +1,73 @@
1
+ import { Agent, type AgentProcessOptions } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import type { DataTypeSchema } from "./definitions/data-type-schema";
4
+ import { type CreateRunnableMemory } from "./definitions/memory";
5
+ import type { CreateLLMAgentOptions, LLMAgentDefinition } from "./llm-agent";
6
+ import type { LLMModel } from "./llm-model";
7
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
8
+ import type { Runnable, RunnableDefinition } from "./runnable";
9
+ import { OrderedRecord } from "./utils";
10
+ import type { ExtractRunnableInputType, ExtractRunnableOutputType } from "./utils/runnable-type";
11
+ import type { UnionToIntersection } from "./utils/union";
12
+ export declare class LLMDecisionAgent<I extends {
13
+ [name: string]: any;
14
+ } = {}, O extends {
15
+ [name: string]: any;
16
+ } = {}, Memories extends {
17
+ [name: string]: MemoryItemWithScore[];
18
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
19
+ definition: LLMDecisionAgentDefinition;
20
+ model?: LLMModel | undefined;
21
+ static create: typeof create;
22
+ constructor(definition: LLMDecisionAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
23
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponse<O>>;
24
+ }
25
+ export interface DecisionAgentCaseParameter<R extends Runnable = Runnable> {
26
+ description?: string;
27
+ runnable: R;
28
+ }
29
+ /**
30
+ * Options to create LLMDecisionAgent.
31
+ */
32
+ export interface CreateLLMDecisionAgentOptions<Case extends DecisionAgentCaseParameter, I extends UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, {
33
+ [name: string]: DataTypeSchema;
34
+ }>, O extends UnionToIntersection<ExtractRunnableOutputType<Case["runnable"]>, {
35
+ [name: string]: DataTypeSchema;
36
+ }>, Memories extends {
37
+ [name: string]: CreateRunnableMemory<I>;
38
+ }, State extends ContextState> extends Pick<CreateLLMAgentOptions<I, O, Memories, State>, "name" | "memories" | "messages" | "modelOptions"> {
39
+ context: Context<State>;
40
+ cases: {
41
+ [name: string]: Case;
42
+ };
43
+ }
44
+ declare function create<Case extends DecisionAgentCaseParameter, I extends UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, {
45
+ [name: string]: DataTypeSchema;
46
+ }>, O extends UnionToIntersection<ExtractRunnableOutputType<Case["runnable"]>, {
47
+ [name: string]: DataTypeSchema;
48
+ }>, Memories extends {
49
+ [name: string]: CreateRunnableMemory<I> & {
50
+ /**
51
+ * Whether this memory is primary? Primary memory will be passed as messages to LLM chat model,
52
+ * otherwise, it will be placed in a system message.
53
+ *
54
+ * Only one primary memory is allowed.
55
+ */
56
+ primary?: boolean;
57
+ };
58
+ }, State extends ContextState>({ context, ...options }: CreateLLMDecisionAgentOptions<Case, I, O, Memories, State>): LLMDecisionAgent<UnionToIntersection<ExtractRunnableInputType<Case["runnable"]>, {}>, ExtractRunnableOutputType<Case["runnable"]>, {
59
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
60
+ }, State>;
61
+ export interface LLMDecisionAgentDefinition extends RunnableDefinition, Pick<LLMAgentDefinition, "modelOptions" | "messages" | "primaryMemoryId"> {
62
+ type: "llm_decision_agent";
63
+ cases?: OrderedRecord<LLMDecisionCase>;
64
+ }
65
+ export interface LLMDecisionCase {
66
+ id: string;
67
+ name?: string;
68
+ description?: string;
69
+ runnable?: {
70
+ id?: string;
71
+ };
72
+ }
73
+ export {};
@@ -0,0 +1,80 @@
1
+ import { Agent } from "./agent";
2
+ import type { Context } from "./context";
3
+ export type Role = "system" | "user" | "assistant" | "tool";
4
+ export interface LLMModelInputs {
5
+ messages: LLMModelInputMessage[];
6
+ responseFormat?: {
7
+ type: "text";
8
+ } | {
9
+ type: "json_schema";
10
+ jsonSchema: {
11
+ name: string;
12
+ description?: string;
13
+ schema: object;
14
+ strict?: boolean;
15
+ };
16
+ };
17
+ tools?: LLMModelInputTool[];
18
+ toolChoice?: "auto" | "none" | "required" | {
19
+ type: "function";
20
+ function: {
21
+ name: string;
22
+ description?: string;
23
+ };
24
+ };
25
+ modelOptions?: LLMModelOptions;
26
+ }
27
+ export interface LLMModelInputMessage {
28
+ role: Role;
29
+ content: string | ({
30
+ type: "text";
31
+ text: string;
32
+ } | {
33
+ type: "image_url";
34
+ imageUrl: {
35
+ url: string;
36
+ };
37
+ })[];
38
+ toolCalls?: {
39
+ id: string;
40
+ type: "function";
41
+ function: {
42
+ name: string;
43
+ arguments: string;
44
+ };
45
+ }[];
46
+ toolCallId?: string;
47
+ }
48
+ export interface LLMModelInputTool {
49
+ type: "function";
50
+ function: {
51
+ name: string;
52
+ description?: string;
53
+ parameters: object;
54
+ };
55
+ }
56
+ export interface LLMModelOptions {
57
+ model?: string;
58
+ temperature?: number;
59
+ topP?: number;
60
+ frequencyPenalty?: number;
61
+ presencePenalty?: number;
62
+ }
63
+ export interface LLMModelOutputs {
64
+ $text?: string | null;
65
+ toolCalls?: {
66
+ id?: string;
67
+ type?: "function";
68
+ function?: {
69
+ name?: string;
70
+ arguments?: string;
71
+ };
72
+ }[];
73
+ }
74
+ export declare abstract class LLMModel extends Agent<LLMModelInputs, LLMModelOutputs> {
75
+ constructor(context?: Context);
76
+ }
77
+ export interface LLMModelConfiguration {
78
+ default?: Partial<LLMModelOptions>;
79
+ override?: Partial<LLMModelOptions>;
80
+ }
@@ -0,0 +1,64 @@
1
+ import { Agent, type AgentProcessOptions } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
4
+ import { type CreateRunnableMemory } from "./definitions/memory";
5
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
6
+ import type { RunnableDefinition, RunnableResponse, RunnableResponseChunk } from "./runnable";
7
+ export declare class LocalFunctionAgent<I extends {
8
+ [name: string]: any;
9
+ } = {}, O extends {
10
+ [name: string]: any;
11
+ } = {}, Memories extends {
12
+ [name: string]: MemoryItemWithScore[];
13
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
14
+ definition: LocalFunctionAgentDefinition<I, O, Memories, State>;
15
+ static create: typeof create;
16
+ constructor(definition: LocalFunctionAgentDefinition<I, O, Memories, State>, context?: Context<State>);
17
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
18
+ }
19
+ export interface LocalFunctionAgentDefinition<I extends {
20
+ [name: string]: any;
21
+ }, O extends {
22
+ [name: string]: any;
23
+ }, Memories extends {
24
+ [name: string]: MemoryItemWithScore[];
25
+ }, State extends ContextState> extends RunnableDefinition {
26
+ type: "local_function_agent";
27
+ function?: LocalFunctionFuncType<I, O, Memories, State>;
28
+ }
29
+ export type LocalFunctionFuncType<I extends {
30
+ [name: string]: any;
31
+ }, O extends {
32
+ [name: string]: any;
33
+ }, Memories extends {
34
+ [name: string]: MemoryItemWithScore[];
35
+ }, State extends ContextState> = (input: I, options: {
36
+ memories: Memories;
37
+ context: Context<State>;
38
+ }) => Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
39
+ export interface CreateLocalFunctionAgentOptions<I extends {
40
+ [name: string]: DataTypeSchema;
41
+ }, O extends {
42
+ [name: string]: DataTypeSchema;
43
+ }, Memories extends {
44
+ [name: string]: CreateRunnableMemory<I>;
45
+ }, State extends ContextState> {
46
+ context?: Context<State>;
47
+ name?: string;
48
+ inputs: I;
49
+ outputs: O;
50
+ memories?: Memories;
51
+ function?: LocalFunctionFuncType<SchemaMapType<I>, SchemaMapType<O>, {
52
+ [key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
53
+ }, State>;
54
+ }
55
+ declare function create<I extends {
56
+ [name: string]: DataTypeSchema;
57
+ }, O extends {
58
+ [name: string]: DataTypeSchema;
59
+ }, Memories extends {
60
+ [name: string]: CreateRunnableMemory<I>;
61
+ }, State extends ContextState>({ context, ...options }: CreateLocalFunctionAgentOptions<I, O, Memories, State>): LocalFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
62
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
63
+ }, State>;
64
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const logger: Console;
2
+ export default logger;
@@ -0,0 +1,183 @@
1
+ import type { LLMModelInputMessage } from "./llm-model";
2
+ import { Runnable } from "./runnable";
3
+ export interface MemoryMetadata {
4
+ [key: string]: any;
5
+ }
6
+ export type MemoryActionItem<T> = {
7
+ event: "add";
8
+ id: string;
9
+ memory: T;
10
+ metadata?: MemoryMetadata;
11
+ } | {
12
+ event: "update";
13
+ id: string;
14
+ memory: T;
15
+ oldMemory: T;
16
+ metadata?: MemoryMetadata;
17
+ } | {
18
+ event: "delete";
19
+ id: string;
20
+ memory: T;
21
+ } | {
22
+ event: "none";
23
+ memory: T;
24
+ };
25
+ export interface MemoryItem<T> {
26
+ id: string;
27
+ userId?: string;
28
+ sessionId?: string;
29
+ createdAt: string;
30
+ updatedAt: string;
31
+ memory: T;
32
+ metadata: MemoryMetadata;
33
+ }
34
+ export interface MemoryItemWithScore<T = any> extends MemoryItem<T> {
35
+ score: number;
36
+ }
37
+ export type MemoryMessage = LLMModelInputMessage;
38
+ export type MemoryActions<T> = {
39
+ action: "add";
40
+ inputs: {
41
+ messages: MemoryMessage[];
42
+ options?: {
43
+ userId?: string;
44
+ sessionId?: string;
45
+ metadata?: MemoryMetadata;
46
+ };
47
+ };
48
+ outputs: {
49
+ results: MemoryActionItem<T>[];
50
+ };
51
+ } | {
52
+ action: "search";
53
+ inputs: {
54
+ query: string;
55
+ options?: {
56
+ k?: number;
57
+ userId?: string;
58
+ sessionId?: string;
59
+ filter?: MemoryMetadata;
60
+ sort?: MemorySortOptions;
61
+ };
62
+ };
63
+ outputs: {
64
+ results: MemoryItemWithScore<T>[];
65
+ };
66
+ } | {
67
+ action: "filter";
68
+ inputs: {
69
+ options?: {
70
+ k?: number;
71
+ userId?: string;
72
+ sessionId?: string;
73
+ filter?: MemoryMetadata;
74
+ sort?: MemorySortOptions;
75
+ };
76
+ };
77
+ outputs: {
78
+ results: MemoryItem<T>[];
79
+ };
80
+ } | {
81
+ action: "get";
82
+ inputs: {
83
+ memoryId: string;
84
+ };
85
+ outputs: {
86
+ result: MemoryItem<T> | null;
87
+ };
88
+ } | {
89
+ action: "create";
90
+ inputs: {
91
+ memory: T;
92
+ options?: {
93
+ userId?: string;
94
+ sessionId?: string;
95
+ metadata?: MemoryMetadata;
96
+ };
97
+ };
98
+ outputs: {
99
+ result: MemoryItem<T>;
100
+ };
101
+ } | {
102
+ action: "update";
103
+ inputs: {
104
+ memoryId: string;
105
+ memory: T;
106
+ };
107
+ outputs: {
108
+ result: MemoryItem<T> | null;
109
+ };
110
+ } | {
111
+ action: "delete";
112
+ inputs: {
113
+ filter: string | string[] | Record<string, any>;
114
+ };
115
+ outputs: {};
116
+ } | {
117
+ action: "reset";
118
+ inputs: {};
119
+ outputs: {};
120
+ };
121
+ export interface SortItem {
122
+ field: string;
123
+ direction: "asc" | "desc";
124
+ }
125
+ export type MemorySortOptions = SortItem | SortItem[];
126
+ export declare abstract class Memorable<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>["outputs"]> {
127
+ constructor();
128
+ abstract runner?: MemoryRunner<T, C>;
129
+ abstract add(messages: Extract<MemoryActions<T>, {
130
+ action: "add";
131
+ }>["inputs"]["messages"], options?: Extract<MemoryActions<T>, {
132
+ action: "add";
133
+ }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
134
+ action: "add";
135
+ }>["outputs"]>;
136
+ abstract search(query: Extract<MemoryActions<T>, {
137
+ action: "search";
138
+ }>["inputs"]["query"], options?: Extract<MemoryActions<T>, {
139
+ action: "search";
140
+ }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
141
+ action: "search";
142
+ }>["outputs"]>;
143
+ abstract filter(options: Extract<MemoryActions<T>, {
144
+ action: "filter";
145
+ }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
146
+ action: "filter";
147
+ }>["outputs"]>;
148
+ abstract get(memoryId: Extract<MemoryActions<T>, {
149
+ action: "get";
150
+ }>["inputs"]["memoryId"]): Promise<Extract<MemoryActions<T>, {
151
+ action: "get";
152
+ }>["outputs"]>;
153
+ abstract create(memory: Extract<MemoryActions<T>, {
154
+ action: "create";
155
+ }>["inputs"]["memory"], options?: Extract<MemoryActions<T>, {
156
+ action: "create";
157
+ }>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
158
+ action: "create";
159
+ }>["outputs"]>;
160
+ abstract update(memoryId: Extract<MemoryActions<T>, {
161
+ action: "update";
162
+ }>["inputs"]["memoryId"], memory: T): Promise<Extract<MemoryActions<T>, {
163
+ action: "update";
164
+ }>["outputs"]>;
165
+ abstract delete(memoryId: Extract<MemoryActions<T>, {
166
+ action: "delete";
167
+ }>["inputs"]["filter"]): Promise<Extract<MemoryActions<T>, {
168
+ action: "delete";
169
+ }>["outputs"]>;
170
+ abstract reset(): Promise<void>;
171
+ }
172
+ export interface MemoryRunnerInput<C = undefined> {
173
+ messages: MemoryMessage[];
174
+ userId?: string;
175
+ sessionId?: string;
176
+ metadata?: MemoryMetadata;
177
+ filter?: MemoryMetadata;
178
+ customData: C;
179
+ }
180
+ export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
181
+ constructor(name: string);
182
+ }
183
+ export type MemorableSearchOutput<T extends Memorable<any>> = Awaited<ReturnType<T["search"]>>["results"];
@@ -0,0 +1,55 @@
1
+ import { Agent } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
4
+ import type { CreateRunnableMemory } from "./definitions/memory";
5
+ import type { AuthConfig, FetchRequest, HTTPMethod, OpenAPIDataType, OpenAPIDataTypeSchema } from "./definitions/open-api";
6
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
7
+ import type { RunnableDefinition } from "./runnable";
8
+ import type { OrderedRecord } from "./utils";
9
+ export declare class OpenAPIAgent<I extends {
10
+ [name: string]: any;
11
+ } = {}, O extends {
12
+ [name: string]: any;
13
+ } = {}, Memories extends {
14
+ [name: string]: MemoryItemWithScore[];
15
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
16
+ definition: OpenAPIAgentDefinition;
17
+ static create: typeof create;
18
+ constructor(definition: OpenAPIAgentDefinition, context?: Context<State>);
19
+ process(input: I): Promise<O>;
20
+ fetch<T>(request: FetchRequest): Promise<T>;
21
+ }
22
+ export interface OpenAPIAgentDefinition extends RunnableDefinition {
23
+ type: "open_api_agent";
24
+ inputs: OrderedRecord<OpenAPIDataType>;
25
+ url: string;
26
+ method?: HTTPMethod;
27
+ auth?: AuthConfig;
28
+ }
29
+ export interface CreateOpenAPIAgentOptions<I extends {
30
+ [name: string]: OpenAPIDataTypeSchema;
31
+ }, O extends {
32
+ [name: string]: DataTypeSchema;
33
+ }, Memories extends {
34
+ [name: string]: CreateRunnableMemory<I>;
35
+ }, State extends ContextState> {
36
+ context?: Context<State>;
37
+ id?: string;
38
+ name?: string;
39
+ inputs: I;
40
+ outputs: O;
41
+ memories?: Memories;
42
+ url: string;
43
+ method?: HTTPMethod;
44
+ auth?: AuthConfig;
45
+ }
46
+ declare function create<I extends {
47
+ [name: string]: OpenAPIDataTypeSchema;
48
+ }, O extends {
49
+ [name: string]: DataTypeSchema;
50
+ }, Memories extends {
51
+ [name: string]: CreateRunnableMemory<I>;
52
+ }, State extends ContextState>({ context, ...options }: CreateOpenAPIAgentOptions<I, O, Memories, State>): OpenAPIAgent<SchemaMapType<I>, SchemaMapType<O>, {
53
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
54
+ }, State>;
55
+ export {};
@@ -0,0 +1,79 @@
1
+ import { Agent, type AgentProcessOptions } from "./agent";
2
+ import type { Context, ContextState } from "./context";
3
+ import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
4
+ import { type CreateRunnableMemory } from "./definitions/memory";
5
+ import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
6
+ import type { Runnable, RunnableDefinition, RunnableOutput, RunnableResponseDelta } from "./runnable";
7
+ import type { MakeNullablePropertyOptional } from "./utils/nullable";
8
+ import { OrderedRecord } from "./utils/ordered-map";
9
+ import type { ExtractRunnableInputType } from "./utils/runnable-type";
10
+ export declare class PipelineAgent<I extends {
11
+ [key: string]: any;
12
+ } = {}, O extends {
13
+ [name: string]: any;
14
+ } = {}, Memories extends {
15
+ [name: string]: MemoryItemWithScore[];
16
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
17
+ definition: PipelineAgentDefinition;
18
+ static create: typeof create;
19
+ constructor(definition: PipelineAgentDefinition, context?: Context<State>);
20
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
21
+ }
22
+ type VariableWithPropPath = {
23
+ fromVariable: string;
24
+ fromVariablePropPath?: (string | number)[];
25
+ };
26
+ export type PipelineAgentProcessParameter<R extends Runnable = any, RI extends {
27
+ [name: string]: DataTypeSchema;
28
+ } = ExtractRunnableInputType<R>> = {
29
+ runnable: R;
30
+ input: MakeNullablePropertyOptional<{
31
+ [key in keyof RI]: VariableWithPropPath;
32
+ }>;
33
+ };
34
+ declare function create<I extends {
35
+ [name: string]: DataTypeSchema;
36
+ }, O extends {
37
+ [name: string]: DataTypeSchema & {
38
+ fromVariable: string;
39
+ fromVariablePropPath?: string[];
40
+ };
41
+ }, Memories extends {
42
+ [name: string]: CreateRunnableMemory<I>;
43
+ }, State extends ContextState, Processes extends {
44
+ [name: string]: PipelineAgentProcessParameter;
45
+ }>({ context, ...options }: {
46
+ context: Context<State>;
47
+ name?: string;
48
+ inputs: I;
49
+ outputs: O;
50
+ memories?: Memories;
51
+ processes: Processes;
52
+ }): PipelineAgent<SchemaMapType<I>, SchemaMapType<O>, {
53
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
54
+ }, State>;
55
+ export interface PipelineAgentDefinition extends RunnableDefinition {
56
+ type: "pipeline_agent";
57
+ processes?: OrderedRecord<PipelineAgentProcess>;
58
+ outputs: OrderedRecord<PipelineAgentOutput>;
59
+ }
60
+ export type PipelineAgentOutput = RunnableOutput & {
61
+ from: "variable";
62
+ fromVariableId?: string;
63
+ fromVariablePropPath?: (string | number)[];
64
+ };
65
+ export type PipelineAgentProcess = {
66
+ id: string;
67
+ name?: string;
68
+ runnable?: {
69
+ id?: string;
70
+ };
71
+ input?: {
72
+ [inputId: string]: {
73
+ from: "variable";
74
+ fromVariableId?: string;
75
+ fromVariablePropPath?: (string | number | symbol)[];
76
+ };
77
+ };
78
+ };
79
+ export {};
@@ -0,0 +1,70 @@
1
+ import type { Context, ContextState } from "./context";
2
+ import type { DataType } from "./definitions/data-type";
3
+ import type { Memorable } from "./memorable";
4
+ import { OrderedRecord } from "./utils/ordered-map";
5
+ export interface RunOptions {
6
+ stream?: boolean;
7
+ }
8
+ export type RunnableResponse<T> = T | RunnableResponseStream<T>;
9
+ export declare abstract class Runnable<I extends {
10
+ [name: string]: any;
11
+ } = {}, O extends {
12
+ [name: string]: any;
13
+ } = {}, State extends ContextState = ContextState> {
14
+ definition: RunnableDefinition;
15
+ context?: Context<State> | undefined;
16
+ constructor(definition: RunnableDefinition, context?: Context<State> | undefined);
17
+ get id(): string;
18
+ get name(): string | undefined;
19
+ inputs: {
20
+ [key in keyof I]: DataType;
21
+ };
22
+ outputs: {
23
+ [key in keyof O]: DataType;
24
+ };
25
+ abstract run(input: I, options: RunOptions & {
26
+ stream: true;
27
+ }): Promise<RunnableResponseStream<O>>;
28
+ abstract run(input: I, options?: RunOptions & {
29
+ stream?: false;
30
+ }): Promise<O>;
31
+ abstract run(input: I, options?: RunOptions): Promise<RunnableResponse<O>>;
32
+ }
33
+ export interface RunnableDefinition {
34
+ id: string;
35
+ type: string;
36
+ name?: string;
37
+ description?: string;
38
+ memories?: OrderedRecord<RunnableMemory>;
39
+ inputs: OrderedRecord<RunnableInput>;
40
+ outputs: OrderedRecord<RunnableOutput>;
41
+ }
42
+ export interface RunnableMemory {
43
+ id: string;
44
+ name?: string;
45
+ memory?: Memorable<any>;
46
+ query?: {
47
+ from: "variable";
48
+ fromVariableId?: string;
49
+ fromVariablePropPath?: string[];
50
+ };
51
+ options?: {
52
+ k?: number;
53
+ };
54
+ }
55
+ export type RunnableInput = DataType;
56
+ export type RunnableOutput = DataType;
57
+ export interface RunnableResponseDelta<T> {
58
+ $text?: string;
59
+ delta?: Partial<T>;
60
+ }
61
+ export interface RunnableResponseError {
62
+ error: {
63
+ message: string;
64
+ };
65
+ }
66
+ export type RunnableResponseChunk<T> = RunnableResponseDelta<T>;
67
+ export type RunnableResponseChunkWithError<T> = RunnableResponseChunk<T> | RunnableResponseError;
68
+ export declare function isRunnableResponseDelta<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseDelta<T>;
69
+ export declare function isRunnableResponseError<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseError;
70
+ export type RunnableResponseStream<T> = ReadableStream<RunnableResponseChunk<T>>;
@@ -0,0 +1 @@
1
+ export declare const FETCH_TIMEOUT: number;
@@ -0,0 +1,2 @@
1
+ import type { FetchRequest } from "../definitions/open-api";
2
+ export declare function fetchOpenApi<T>(request: FetchRequest): Promise<T>;
@@ -0,0 +1 @@
1
+ export declare function checkFetchResponse(result: Response): Promise<Response>;
@@ -0,0 +1,10 @@
1
+ export * from "./fetch";
2
+ export * from "./fetch-open-api";
3
+ export * from "./is-non-nullable";
4
+ export * from "./mustache-utils";
5
+ export * from "./nullable";
6
+ export * from "./omit";
7
+ export * from "./open-api-parameter";
8
+ export * from "./ordered-map";
9
+ export * from "./stream-utils";
10
+ export * from "./union";
@@ -0,0 +1,2 @@
1
+ export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
2
+ export declare function isPropsNonNullable<T, K extends keyof T>(...props: (K | K[])[]): (value: T) => value is T & Required<Pick<T, K>>;
@@ -0,0 +1,20 @@
1
+ import type { LLMAgentDefinition } from "../llm-agent";
2
+ import type { LLMModelInputMessage } from "../llm-model";
3
+ import type { MemoryItemWithScore } from "../memorable";
4
+ export declare function mergeHistoryMessages(messages: LLMModelInputMessage[], history: LLMModelInputMessage[]): LLMModelInputMessage[];
5
+ export declare function memoriesToMessages(memories: {
6
+ [name: string]: MemoryItemWithScore[];
7
+ }, { primaryMemoryName }?: {
8
+ primaryMemoryName?: string;
9
+ }): {
10
+ primaryMemory: LLMModelInputMessage[];
11
+ memory: string;
12
+ };
13
+ export declare function prepareMessages(definition: Pick<LLMAgentDefinition, "messages" | "memories" | "primaryMemoryId">, input: {
14
+ [name: string]: any;
15
+ }, memories: {
16
+ [name: string]: MemoryItemWithScore[];
17
+ }): {
18
+ originalMessages: LLMModelInputMessage[];
19
+ messagesWithMemory: LLMModelInputMessage[];
20
+ };
@@ -0,0 +1,3 @@
1
+ export declare function renderMessage(template: string, variables?: {
2
+ [key: string]: any;
3
+ }): string;
@@ -0,0 +1,7 @@
1
+ export type MakeNullablePropertyOptional<T extends {
2
+ [key: string]: any;
3
+ }> = {
4
+ [K in keyof T as Extract<T[K], null | undefined> extends never ? K : never]: T[K];
5
+ } & {
6
+ [K in keyof T as Extract<T[K], null | undefined> extends never ? never : K]?: T[K];
7
+ };
@@ -0,0 +1 @@
1
+ export type OmitPropsFromUnion<T, K extends string | number | symbol> = T extends any ? Omit<T, K> : never;
@@ -0,0 +1,7 @@
1
+ import type { AuthConfig, FetchRequest, HTTPMethod } from "../definitions/open-api";
2
+ import type { OpenAPIAgentDefinition } from "../open-api-agent";
3
+ export declare function formatOpenAPIRequest(api: {
4
+ url: string;
5
+ method: HTTPMethod;
6
+ auth?: AuthConfig;
7
+ }, inputs: OpenAPIAgentDefinition["inputs"], input: Record<string, any>): Promise<FetchRequest>;
@@ -0,0 +1,37 @@
1
+ export type OrderedRecord<T extends {
2
+ id: string;
3
+ }> = Record<string, T> & {
4
+ $indexes: string[];
5
+ };
6
+ export declare namespace OrderedRecord {
7
+ function iterator<T extends {
8
+ id: string;
9
+ }>(record?: OrderedRecord<T>): IterableIterator<T>;
10
+ function map<O, T extends {
11
+ id: string;
12
+ }>(record: OrderedRecord<T> | undefined, fn: (value: T, index: number) => O): O[];
13
+ function toArray<T extends {
14
+ id: string;
15
+ }>(record: OrderedRecord<T> | undefined): T[];
16
+ function fromArray<T extends {
17
+ id: string;
18
+ }>(array?: T[]): OrderedRecord<T>;
19
+ function find<T extends {
20
+ id: string;
21
+ }>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T | undefined;
22
+ function filter<T extends {
23
+ id: string;
24
+ }>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T[];
25
+ function at<T extends {
26
+ id: string;
27
+ }>(record: OrderedRecord<T> | undefined, index: number): T | undefined;
28
+ function push<T extends {
29
+ id: string;
30
+ }>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
31
+ function merge<T extends {
32
+ id: string;
33
+ }>(...records: OrderedRecord<T>[]): OrderedRecord<T>;
34
+ function pushOrUpdate<T extends {
35
+ id: string;
36
+ }>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
37
+ }
@@ -0,0 +1,3 @@
1
+ import type { Runnable, RunnableResponseStream } from "../runnable";
2
+ export type ExtractRunnableInputType<T> = T extends Runnable<infer I, any> ? I : never;
3
+ export type ExtractRunnableOutputType<T> = T extends Runnable<any, infer O> ? Exclude<O, RunnableResponseStream<any>> : never;
@@ -0,0 +1,20 @@
1
+ import { type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "../runnable";
2
+ export declare function objectToRunnableResponseStream<T extends {
3
+ [key: string]: any;
4
+ }>(obj: T): RunnableResponseStream<T>;
5
+ export declare function runnableResponseStreamToObject<T extends {
6
+ [key: string]: any;
7
+ }>(stream: RunnableResponseStream<T> | AsyncGenerator<RunnableResponseChunk<T>>): Promise<T>;
8
+ /**
9
+ * Extracts the outputs from a runnable output stream and run the
10
+ * resolve function on the result before the stream closes. It can be
11
+ * used to update the memories of an agent.
12
+ * @param output The runnable output stream or object
13
+ * @param resolve The function to run on the result
14
+ * @returns The runnable output stream or object
15
+ */
16
+ export declare function extractOutputsFromRunnableOutput<T extends {
17
+ [key: string]: any;
18
+ }>(output: RunnableResponse<T> | AsyncGenerator<RunnableResponseChunk<T>>, resolve: (result: T) => Promise<void> | void): Promise<RunnableResponse<T>>;
19
+ export declare function asyncGeneratorToReadableStream<T>(generator: AsyncGenerator<T>): ReadableStream<T>;
20
+ export declare function isAsyncGenerator<T extends AsyncGenerator>(value: any): value is T;
@@ -0,0 +1,3 @@
1
+ import type { RunnableOutput } from "../runnable";
2
+ import { OrderedRecord } from "./ordered-map";
3
+ export declare function outputsToJsonSchema(outputs: OrderedRecord<RunnableOutput>): object;
@@ -0,0 +1 @@
1
+ export type UnionToIntersection<U, O = any> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I extends O ? I : never : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.0.2-beta.4",
3
+ "version": "1.0.2-beta.5",
4
4
  "description": "AIGNE core library",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,7 +13,7 @@
13
13
  "types": "./lib/dts/index.d.ts",
14
14
  "files": [
15
15
  "lib/cjs",
16
- "lib/dst",
16
+ "lib/dts",
17
17
  "lib/esm",
18
18
  "LICENSE",
19
19
  "package.json",