@aigne/core 0.4.211-beta.2 → 1.0.0
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/lib/cjs/agent.js +18 -11
- package/lib/cjs/constants.js +5 -5
- package/lib/cjs/definitions/data-type-schema.js +12 -11
- package/lib/cjs/definitions/memory.js +3 -1
- package/lib/cjs/function-agent.js +5 -6
- package/lib/cjs/function-runner.js +13 -13
- package/lib/cjs/llm-agent.js +16 -15
- package/lib/cjs/llm-decision-agent.js +15 -13
- package/lib/cjs/llm-model.js +11 -11
- package/lib/cjs/local-function-agent.js +3 -3
- package/lib/cjs/memorable.js +3 -3
- package/lib/cjs/open-api-agent.js +4 -4
- package/lib/cjs/pipeline-agent.js +26 -17
- package/lib/cjs/runnable.js +2 -2
- package/lib/cjs/utils/fetch-open-api.js +9 -8
- package/lib/cjs/utils/fetch.js +3 -2
- package/lib/cjs/utils/is-non-nullable.js +1 -4
- package/lib/cjs/utils/message-utils.js +23 -16
- package/lib/cjs/utils/mustache-utils.js +2 -5
- package/lib/cjs/utils/open-api-parameter.js +19 -22
- package/lib/cjs/utils/stream-utils.js +6 -5
- package/lib/cjs/utils/structured-output-schema.js +10 -9
- package/lib/esm/agent.js +20 -10
- package/lib/esm/constants.js +5 -5
- package/lib/esm/definitions/data-type-schema.js +14 -13
- package/lib/esm/definitions/memory.js +5 -3
- package/lib/esm/function-agent.js +11 -12
- package/lib/esm/function-runner.js +15 -15
- package/lib/esm/index.js +18 -18
- package/lib/esm/llm-agent.js +26 -25
- package/lib/esm/llm-decision-agent.js +22 -20
- package/lib/esm/llm-model.js +13 -13
- package/lib/esm/local-function-agent.js +9 -9
- package/lib/esm/memorable.js +6 -6
- package/lib/esm/open-api-agent.js +11 -11
- package/lib/esm/pipeline-agent.js +35 -23
- package/lib/esm/runnable.js +3 -3
- package/lib/esm/utils/fetch-open-api.js +11 -9
- package/lib/esm/utils/fetch.js +3 -2
- package/lib/esm/utils/index.js +10 -10
- package/lib/esm/utils/is-non-nullable.js +1 -1
- package/lib/esm/utils/message-utils.js +26 -16
- package/lib/esm/utils/mustache-utils.js +2 -2
- package/lib/esm/utils/open-api-parameter.js +21 -21
- package/lib/esm/utils/stream-utils.js +7 -6
- package/lib/esm/utils/structured-output-schema.js +12 -8
- package/lib/types/agent.d.ts +3 -3
- package/lib/types/context.d.ts +2 -2
- package/lib/types/definitions/data-type-schema.d.ts +14 -14
- package/lib/types/definitions/data-type.d.ts +8 -8
- package/lib/types/definitions/memory.d.ts +5 -5
- package/lib/types/definitions/open-api.d.ts +9 -9
- package/lib/types/function-agent.d.ts +9 -9
- package/lib/types/function-runner.d.ts +4 -4
- package/lib/types/index.d.ts +18 -18
- package/lib/types/llm-agent.d.ts +12 -12
- package/lib/types/llm-decision-agent.d.ts +20 -20
- package/lib/types/llm-model.d.ts +12 -12
- package/lib/types/local-function-agent.d.ts +14 -16
- package/lib/types/memorable.d.ts +51 -51
- package/lib/types/open-api-agent.d.ts +12 -12
- package/lib/types/pipeline-agent.d.ts +14 -14
- package/lib/types/runnable.d.ts +5 -5
- package/lib/types/utils/fetch-open-api.d.ts +2 -2
- package/lib/types/utils/index.d.ts +10 -10
- package/lib/types/utils/message-utils.d.ts +4 -4
- package/lib/types/utils/open-api-parameter.d.ts +3 -3
- package/lib/types/utils/runnable-type.d.ts +1 -1
- package/lib/types/utils/stream-utils.d.ts +1 -1
- package/lib/types/utils/structured-output-schema.d.ts +2 -2
- package/package.json +11 -10
- package/tsconfig.json +3 -1
- package/lib/cjs/api-agent.js +0 -70
- package/lib/cjs/data-type-schema.js +0 -46
- package/lib/cjs/data-type.js +0 -2
- package/lib/cjs/definitions/api-parameter.js +0 -10
- package/lib/cjs/memory.js +0 -32
- package/lib/cjs/tsconfig.tsbuildinfo +0 -1
- package/lib/cjs/utils/fetch-api.js +0 -35
- package/lib/cjs/utils/flatten-openapi.js +0 -14
- package/lib/cjs/utils/format-parameter.js +0 -126
- package/lib/esm/api-agent.js +0 -67
- package/lib/esm/data-type-schema.js +0 -43
- package/lib/esm/data-type.js +0 -1
- package/lib/esm/definitions/api-parameter.js +0 -7
- package/lib/esm/memory.js +0 -27
- package/lib/esm/tsconfig.tsbuildinfo +0 -1
- package/lib/esm/utils/fetch-api.js +0 -31
- package/lib/esm/utils/flatten-openapi.js +0 -11
- package/lib/esm/utils/format-parameter.js +0 -116
- package/lib/types/api-agent.d.ts +0 -53
- package/lib/types/data-type-schema.d.ts +0 -46
- package/lib/types/data-type.d.ts +0 -32
- package/lib/types/definitions/api-parameter.d.ts +0 -55
- package/lib/types/memory.d.ts +0 -184
- package/lib/types/tsconfig.tsbuildinfo +0 -1
- package/lib/types/utils/fetch-api.d.ts +0 -3
- package/lib/types/utils/flatten-openapi.d.ts +0 -25
- package/lib/types/utils/format-parameter.d.ts +0 -6
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { withQuery } from 'ufo';
|
|
2
|
-
import { TIMEOUT } from './constants';
|
|
3
|
-
export const fetchApi = async (request) => {
|
|
4
|
-
let cookieString = '';
|
|
5
|
-
if (request.cookies) {
|
|
6
|
-
cookieString = Object.entries(request.cookies)
|
|
7
|
-
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
8
|
-
.join('; ');
|
|
9
|
-
}
|
|
10
|
-
const controller = new AbortController();
|
|
11
|
-
const timeoutId = setTimeout(() => controller.abort(), Number(TIMEOUT));
|
|
12
|
-
const response = await fetch(withQuery(request.url, request.query || {}), {
|
|
13
|
-
method: request.method,
|
|
14
|
-
headers: {
|
|
15
|
-
'Content-Type': 'application/json',
|
|
16
|
-
...(cookieString && { Cookie: cookieString.trim() }),
|
|
17
|
-
...request.headers,
|
|
18
|
-
},
|
|
19
|
-
body: request.method !== 'GET' ? JSON.stringify(request.body) : undefined,
|
|
20
|
-
credentials: request.cookies ? 'include' : 'same-origin',
|
|
21
|
-
signal: controller.signal,
|
|
22
|
-
}).finally(() => clearTimeout(timeoutId));
|
|
23
|
-
if (!response.ok) {
|
|
24
|
-
const errorBody = await response.text();
|
|
25
|
-
throw new Error(`API request failed for ${request.url}\n` +
|
|
26
|
-
`Status: ${response.status} ${response.statusText}\n` +
|
|
27
|
-
`Response: ${errorBody.slice(0, 200)}`);
|
|
28
|
-
}
|
|
29
|
-
return response.json();
|
|
30
|
-
};
|
|
31
|
-
export default fetchApi;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function flattenApiStructure(apiStructure) {
|
|
2
|
-
const paths = apiStructure?.paths || {};
|
|
3
|
-
return Object.entries(paths).flatMap(([, methods]) => Object.entries(methods).map(([, endpoint]) => ({
|
|
4
|
-
id: endpoint['x-id'],
|
|
5
|
-
name: endpoint['x-did'],
|
|
6
|
-
path: endpoint['x-path'],
|
|
7
|
-
method: endpoint['x-method'],
|
|
8
|
-
did: endpoint['x-did'],
|
|
9
|
-
...endpoint,
|
|
10
|
-
})));
|
|
11
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import logger from '../logger';
|
|
2
|
-
export function getAuthParams(auth) {
|
|
3
|
-
if (!auth)
|
|
4
|
-
return {};
|
|
5
|
-
if (auth.type === 'custom') {
|
|
6
|
-
return { headers: auth.getValue() };
|
|
7
|
-
}
|
|
8
|
-
const paramKey = auth.key || 'Authorization';
|
|
9
|
-
const paramValue = (() => {
|
|
10
|
-
let paramValue = auth.token;
|
|
11
|
-
switch (auth.type) {
|
|
12
|
-
case 'basic':
|
|
13
|
-
paramValue = `Basic ${auth.token}`;
|
|
14
|
-
break;
|
|
15
|
-
case 'bearer':
|
|
16
|
-
paramValue = `Bearer ${auth.token}`;
|
|
17
|
-
break;
|
|
18
|
-
default:
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
return paramValue;
|
|
22
|
-
})();
|
|
23
|
-
switch (auth.in) {
|
|
24
|
-
case 'header':
|
|
25
|
-
return { headers: { [paramKey]: paramValue } };
|
|
26
|
-
case 'query':
|
|
27
|
-
return { query: { [paramKey]: paramValue } };
|
|
28
|
-
case 'cookie':
|
|
29
|
-
return { cookies: { [paramKey]: paramValue } };
|
|
30
|
-
default:
|
|
31
|
-
// 默认放在 header 中
|
|
32
|
-
return { headers: { [paramKey]: paramValue } };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export function processParameters(api, inputs, input) {
|
|
36
|
-
const method = (api.method || 'GET').toUpperCase();
|
|
37
|
-
const result = {
|
|
38
|
-
url: api.url,
|
|
39
|
-
method,
|
|
40
|
-
headers: {},
|
|
41
|
-
query: {},
|
|
42
|
-
cookies: {},
|
|
43
|
-
body: {},
|
|
44
|
-
};
|
|
45
|
-
const filterInputs = Object.values(inputs).filter((i) => !Array.isArray(i));
|
|
46
|
-
// 处理路径参数
|
|
47
|
-
let processedUrl = api.url;
|
|
48
|
-
const pathParams = filterInputs.filter((x) => x.in === 'path');
|
|
49
|
-
pathParams.forEach(({ name }) => {
|
|
50
|
-
if (name && input[name] !== undefined) {
|
|
51
|
-
const placeholder = `{${name}}`;
|
|
52
|
-
processedUrl = processedUrl.replace(placeholder, String(input[name]));
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
result.url = processedUrl;
|
|
56
|
-
// 处理其他参数
|
|
57
|
-
Object.entries(input).forEach(([key, value]) => {
|
|
58
|
-
const schema = filterInputs.find((i) => i.name === key);
|
|
59
|
-
const paramIn = schema?.in;
|
|
60
|
-
switch (paramIn) {
|
|
61
|
-
case 'query':
|
|
62
|
-
result.query[key] = value;
|
|
63
|
-
break;
|
|
64
|
-
case 'header':
|
|
65
|
-
result.headers[key] = value;
|
|
66
|
-
break;
|
|
67
|
-
case 'cookie':
|
|
68
|
-
result.cookies[key] = value;
|
|
69
|
-
break;
|
|
70
|
-
case 'body':
|
|
71
|
-
result.body[key] = value;
|
|
72
|
-
break;
|
|
73
|
-
case 'path':
|
|
74
|
-
break;
|
|
75
|
-
default:
|
|
76
|
-
// 没有指定 in 的情况
|
|
77
|
-
if (method === 'GET') {
|
|
78
|
-
result.query[key] = value;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
result.body[key] = value;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
export function mergeParameters(parameters, authParams) {
|
|
88
|
-
const result = {};
|
|
89
|
-
if (parameters.query || authParams.query) {
|
|
90
|
-
result.query = { ...(parameters.query || {}), ...(authParams.query || {}) };
|
|
91
|
-
}
|
|
92
|
-
if (parameters.cookies || authParams.cookies) {
|
|
93
|
-
result.cookies = { ...(parameters.cookies || {}), ...(authParams.cookies || {}) };
|
|
94
|
-
}
|
|
95
|
-
if (parameters.headers || authParams.headers) {
|
|
96
|
-
result.headers = { ...(parameters.headers || {}), ...(authParams.headers || {}) };
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
export const formatRequest = (api, inputs, input) => {
|
|
101
|
-
const inputParams = processParameters(api, inputs, input);
|
|
102
|
-
logger.debug('inputParams', inputParams);
|
|
103
|
-
const authParams = getAuthParams(api.auth);
|
|
104
|
-
logger.debug('authParams', authParams);
|
|
105
|
-
const mergedParams = mergeParameters(inputParams, authParams);
|
|
106
|
-
logger.debug('mergedParams', mergedParams);
|
|
107
|
-
const params = { ...inputParams, ...mergedParams };
|
|
108
|
-
return {
|
|
109
|
-
url: params.url,
|
|
110
|
-
method: params.method,
|
|
111
|
-
...(params.headers && Object.keys(params.headers).length > 0 && { headers: params.headers }),
|
|
112
|
-
...(params.query && Object.keys(params.query).length > 0 && { query: params.query }),
|
|
113
|
-
...(params.cookies && Object.keys(params.cookies).length > 0 && { cookies: params.cookies }),
|
|
114
|
-
...(params.body && Object.keys(params.body).length > 0 && { body: params.body }),
|
|
115
|
-
};
|
|
116
|
-
};
|
package/lib/types/api-agent.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Agent } from './agent';
|
|
2
|
-
import type { Context, ContextState } from './context';
|
|
3
|
-
import { AuthConfig, FetchRequest, FormatMethod } from './definitions/api-parameter';
|
|
4
|
-
import { DataTypeSchema, InputDataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
|
|
5
|
-
import { CreateRunnableMemory } from './definitions/memory';
|
|
6
|
-
import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
|
|
7
|
-
import { RunnableDefinition } from './runnable';
|
|
8
|
-
export declare class OpenAPIAgent<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: OpenAPIAgentDefinition;
|
|
16
|
-
static create: typeof create;
|
|
17
|
-
constructor(definition: OpenAPIAgentDefinition, context?: Context<State>);
|
|
18
|
-
process(input: I): Promise<any>;
|
|
19
|
-
fetch(request: FetchRequest): Promise<any>;
|
|
20
|
-
}
|
|
21
|
-
export interface OpenAPIAgentDefinition extends RunnableDefinition {
|
|
22
|
-
type: 'api_agent';
|
|
23
|
-
url: string;
|
|
24
|
-
method?: FormatMethod;
|
|
25
|
-
auth?: AuthConfig;
|
|
26
|
-
}
|
|
27
|
-
export interface CreateOpenAPIAgentOptions<I extends {
|
|
28
|
-
[name: string]: DataTypeSchema;
|
|
29
|
-
}, O extends {
|
|
30
|
-
[name: string]: DataTypeSchema;
|
|
31
|
-
}, Memories extends {
|
|
32
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
33
|
-
}, State extends ContextState> {
|
|
34
|
-
context?: Context<State>;
|
|
35
|
-
id?: string;
|
|
36
|
-
name?: string;
|
|
37
|
-
inputs: I;
|
|
38
|
-
outputs: O;
|
|
39
|
-
memories?: Memories;
|
|
40
|
-
url: string;
|
|
41
|
-
method?: FormatMethod;
|
|
42
|
-
auth?: AuthConfig;
|
|
43
|
-
}
|
|
44
|
-
declare function create<I extends {
|
|
45
|
-
[name: string]: InputDataTypeSchema;
|
|
46
|
-
}, O extends {
|
|
47
|
-
[name: string]: DataTypeSchema;
|
|
48
|
-
}, Memories extends {
|
|
49
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
50
|
-
}, State extends ContextState>({ context, ...options }: CreateOpenAPIAgentOptions<I, O, Memories, State>): OpenAPIAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
51
|
-
[name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
|
|
52
|
-
}, State>;
|
|
53
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { DataType } from './data-type';
|
|
2
|
-
import { OrderedRecord } from './utils';
|
|
3
|
-
export declare function schemaToDataType(dataType: {
|
|
4
|
-
[name: string]: DataTypeSchema;
|
|
5
|
-
}): OrderedRecord<DataType>;
|
|
6
|
-
export type DataTypeSchema = DataTypeSchemaString | DataTypeSchemaNumber | DataTypeSchemaBoolean | DataTypeSchemaObject | DataTypeSchemaArray;
|
|
7
|
-
export interface DataTypeSchemaBase {
|
|
8
|
-
description?: string;
|
|
9
|
-
required?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface DataTypeSchemaString extends DataTypeSchemaBase {
|
|
12
|
-
type: 'string';
|
|
13
|
-
}
|
|
14
|
-
export interface DataTypeSchemaNumber extends DataTypeSchemaBase {
|
|
15
|
-
type: 'number';
|
|
16
|
-
}
|
|
17
|
-
export interface DataTypeSchemaBoolean extends DataTypeSchemaBase {
|
|
18
|
-
type: 'boolean';
|
|
19
|
-
}
|
|
20
|
-
export interface DataTypeSchemaObject extends DataTypeSchemaBase {
|
|
21
|
-
type: 'object';
|
|
22
|
-
properties: {
|
|
23
|
-
[key: string]: DataTypeSchema;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export interface DataTypeSchemaArray extends DataTypeSchemaBase {
|
|
27
|
-
type: 'array';
|
|
28
|
-
items: DataTypeSchema;
|
|
29
|
-
}
|
|
30
|
-
type SchemaTypeInner<T extends DataTypeSchema> = T extends DataTypeSchemaString ? string : T extends DataTypeSchemaNumber ? number : T extends DataTypeSchemaBoolean ? boolean : T extends DataTypeSchemaObject ? MakeNullablePropertyOptional<{
|
|
31
|
-
[K in keyof T['properties']]: SchemaType<T['properties'][K]>;
|
|
32
|
-
}> : T extends DataTypeSchemaArray ? SchemaType<T['items']>[] : never;
|
|
33
|
-
export type SchemaType<T extends DataTypeSchema> = T['required'] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
|
|
34
|
-
export type SchemaMapType<T extends Record<string, DataTypeSchema>> = SchemaType<{
|
|
35
|
-
type: 'object';
|
|
36
|
-
required: true;
|
|
37
|
-
properties: T;
|
|
38
|
-
}>;
|
|
39
|
-
type MakeNullablePropertyOptional<T extends {
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
}> = {
|
|
42
|
-
[K in keyof T as Extract<T[K], null | undefined> extends never ? K : never]: T[K];
|
|
43
|
-
} & {
|
|
44
|
-
[K in keyof T as Extract<T[K], null | undefined> extends never ? never : K]?: T[K];
|
|
45
|
-
};
|
|
46
|
-
export {};
|
package/lib/types/data-type.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { OmitPropsFromUnion } from './utils/omit';
|
|
2
|
-
import { 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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export type AuthType = 'apiKey' | 'basic' | 'bearer' | 'custom';
|
|
2
|
-
export interface BaseAuthConfig {
|
|
3
|
-
type: AuthType;
|
|
4
|
-
token: string;
|
|
5
|
-
in?: 'header' | 'query' | 'cookie';
|
|
6
|
-
key?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface ApiKeyAuthConfig extends BaseAuthConfig {
|
|
9
|
-
type: 'apiKey';
|
|
10
|
-
}
|
|
11
|
-
export interface BasicAuthConfig extends BaseAuthConfig {
|
|
12
|
-
type: 'basic';
|
|
13
|
-
}
|
|
14
|
-
export interface BearerAuthConfig extends BaseAuthConfig {
|
|
15
|
-
type: 'bearer';
|
|
16
|
-
}
|
|
17
|
-
export interface CustomAuthConfig extends Omit<BaseAuthConfig, 'in' | 'key' | 'token'> {
|
|
18
|
-
type: 'custom';
|
|
19
|
-
getValue: () => Record<string, string>;
|
|
20
|
-
}
|
|
21
|
-
export type AuthConfig = ApiKeyAuthConfig | BasicAuthConfig | BearerAuthConfig | CustomAuthConfig;
|
|
22
|
-
export interface AuthResult {
|
|
23
|
-
headers?: Record<string, string>;
|
|
24
|
-
query?: Record<string, string>;
|
|
25
|
-
cookies?: Record<string, string>;
|
|
26
|
-
}
|
|
27
|
-
export declare const enum HTTPMethod {
|
|
28
|
-
GET = "GET",
|
|
29
|
-
POST = "POST",
|
|
30
|
-
PUT = "PUT",
|
|
31
|
-
DELETE = "DELETE"
|
|
32
|
-
}
|
|
33
|
-
export type FormatMethod = Uppercase<HTTPMethod> | Lowercase<HTTPMethod>;
|
|
34
|
-
export type API = {
|
|
35
|
-
url: string;
|
|
36
|
-
method?: FormatMethod;
|
|
37
|
-
auth?: AuthConfig;
|
|
38
|
-
};
|
|
39
|
-
export type ParameterLocation = 'path' | 'query' | 'body' | 'header' | 'cookie';
|
|
40
|
-
export type OpenAPIParameter = {
|
|
41
|
-
in?: ParameterLocation;
|
|
42
|
-
};
|
|
43
|
-
export type FetchRequest = {
|
|
44
|
-
url: string;
|
|
45
|
-
method: string;
|
|
46
|
-
headers?: Record<string, string>;
|
|
47
|
-
query?: Record<string, string>;
|
|
48
|
-
cookies?: Record<string, string>;
|
|
49
|
-
body?: Record<string, any>;
|
|
50
|
-
};
|
|
51
|
-
export interface ParametersResult extends AuthResult {
|
|
52
|
-
url: string;
|
|
53
|
-
method: string;
|
|
54
|
-
body?: Record<string, any>;
|
|
55
|
-
}
|
package/lib/types/memory.d.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Runnable } from './runnable';
|
|
2
|
-
export interface MemoryMetadata {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}
|
|
5
|
-
export type MemoryActionItem<T> = {
|
|
6
|
-
event: 'add';
|
|
7
|
-
id: string;
|
|
8
|
-
memory: T;
|
|
9
|
-
metadata?: MemoryMetadata;
|
|
10
|
-
} | {
|
|
11
|
-
event: 'update';
|
|
12
|
-
id: string;
|
|
13
|
-
memory: T;
|
|
14
|
-
oldMemory: T;
|
|
15
|
-
metadata?: MemoryMetadata;
|
|
16
|
-
} | {
|
|
17
|
-
event: 'delete';
|
|
18
|
-
id: string;
|
|
19
|
-
memory: T;
|
|
20
|
-
} | {
|
|
21
|
-
event: 'none';
|
|
22
|
-
memory: T;
|
|
23
|
-
};
|
|
24
|
-
export interface MemoryItem<T> {
|
|
25
|
-
id: string;
|
|
26
|
-
userId?: string;
|
|
27
|
-
sessionId?: string;
|
|
28
|
-
createdAt: string;
|
|
29
|
-
updatedAt: string;
|
|
30
|
-
memory: T;
|
|
31
|
-
metadata: MemoryMetadata;
|
|
32
|
-
}
|
|
33
|
-
export interface MemoryItemWithScore<T> extends MemoryItem<T> {
|
|
34
|
-
score: number;
|
|
35
|
-
}
|
|
36
|
-
export interface MemoryMessage {
|
|
37
|
-
role: string;
|
|
38
|
-
content: string;
|
|
39
|
-
}
|
|
40
|
-
export type MemoryActions<T> = {
|
|
41
|
-
action: 'add';
|
|
42
|
-
inputs: {
|
|
43
|
-
messages: MemoryMessage[];
|
|
44
|
-
options?: {
|
|
45
|
-
userId?: string;
|
|
46
|
-
sessionId?: string;
|
|
47
|
-
metadata?: MemoryMetadata;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
outputs: {
|
|
51
|
-
results: MemoryActionItem<T>[];
|
|
52
|
-
};
|
|
53
|
-
} | {
|
|
54
|
-
action: 'search';
|
|
55
|
-
inputs: {
|
|
56
|
-
query: string;
|
|
57
|
-
options?: {
|
|
58
|
-
k?: number;
|
|
59
|
-
userId?: string;
|
|
60
|
-
sessionId?: string;
|
|
61
|
-
filter?: MemoryMetadata;
|
|
62
|
-
sort?: MemorySortOptions;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
outputs: {
|
|
66
|
-
results: MemoryItemWithScore<T>[];
|
|
67
|
-
};
|
|
68
|
-
} | {
|
|
69
|
-
action: 'filter';
|
|
70
|
-
inputs: {
|
|
71
|
-
options?: {
|
|
72
|
-
k?: number;
|
|
73
|
-
userId?: string;
|
|
74
|
-
sessionId?: string;
|
|
75
|
-
filter?: MemoryMetadata;
|
|
76
|
-
sort?: MemorySortOptions;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
outputs: {
|
|
80
|
-
results: MemoryItem<T>[];
|
|
81
|
-
};
|
|
82
|
-
} | {
|
|
83
|
-
action: 'get';
|
|
84
|
-
inputs: {
|
|
85
|
-
memoryId: string;
|
|
86
|
-
};
|
|
87
|
-
outputs: {
|
|
88
|
-
result: MemoryItem<T> | null;
|
|
89
|
-
};
|
|
90
|
-
} | {
|
|
91
|
-
action: 'create';
|
|
92
|
-
inputs: {
|
|
93
|
-
memory: T;
|
|
94
|
-
options?: {
|
|
95
|
-
userId?: string;
|
|
96
|
-
sessionId?: string;
|
|
97
|
-
metadata?: MemoryMetadata;
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
outputs: {
|
|
101
|
-
result: MemoryItem<T>;
|
|
102
|
-
};
|
|
103
|
-
} | {
|
|
104
|
-
action: 'update';
|
|
105
|
-
inputs: {
|
|
106
|
-
memoryId: string;
|
|
107
|
-
memory: T;
|
|
108
|
-
};
|
|
109
|
-
outputs: {
|
|
110
|
-
result: MemoryItem<T> | null;
|
|
111
|
-
};
|
|
112
|
-
} | {
|
|
113
|
-
action: 'delete';
|
|
114
|
-
inputs: {
|
|
115
|
-
filter: string | string[] | Record<string, any>;
|
|
116
|
-
};
|
|
117
|
-
outputs: {};
|
|
118
|
-
} | {
|
|
119
|
-
action: 'reset';
|
|
120
|
-
inputs: {};
|
|
121
|
-
outputs: {};
|
|
122
|
-
};
|
|
123
|
-
export interface SortItem {
|
|
124
|
-
field: string;
|
|
125
|
-
direction: 'asc' | 'desc';
|
|
126
|
-
}
|
|
127
|
-
export type MemorySortOptions = SortItem | SortItem[];
|
|
128
|
-
export declare abstract class Memory<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>['outputs']> {
|
|
129
|
-
constructor();
|
|
130
|
-
abstract runner?: MemoryRunner<T, C>;
|
|
131
|
-
abstract add(messages: Extract<MemoryActions<T>, {
|
|
132
|
-
action: 'add';
|
|
133
|
-
}>['inputs']['messages'], options?: Extract<MemoryActions<T>, {
|
|
134
|
-
action: 'add';
|
|
135
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
136
|
-
action: 'add';
|
|
137
|
-
}>['outputs']>;
|
|
138
|
-
abstract search(query: Extract<MemoryActions<T>, {
|
|
139
|
-
action: 'search';
|
|
140
|
-
}>['inputs']['query'], options?: Extract<MemoryActions<T>, {
|
|
141
|
-
action: 'search';
|
|
142
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
143
|
-
action: 'search';
|
|
144
|
-
}>['outputs']>;
|
|
145
|
-
abstract filter(options: Extract<MemoryActions<T>, {
|
|
146
|
-
action: 'filter';
|
|
147
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
148
|
-
action: 'filter';
|
|
149
|
-
}>['outputs']>;
|
|
150
|
-
abstract get(memoryId: Extract<MemoryActions<T>, {
|
|
151
|
-
action: 'get';
|
|
152
|
-
}>['inputs']['memoryId']): Promise<Extract<MemoryActions<T>, {
|
|
153
|
-
action: 'get';
|
|
154
|
-
}>['outputs']>;
|
|
155
|
-
abstract create(memory: Extract<MemoryActions<T>, {
|
|
156
|
-
action: 'create';
|
|
157
|
-
}>['inputs']['memory'], options?: Extract<MemoryActions<T>, {
|
|
158
|
-
action: 'create';
|
|
159
|
-
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
160
|
-
action: 'create';
|
|
161
|
-
}>['outputs']>;
|
|
162
|
-
abstract update(memoryId: Extract<MemoryActions<T>, {
|
|
163
|
-
action: 'update';
|
|
164
|
-
}>['inputs']['memoryId'], memory: T): Promise<Extract<MemoryActions<T>, {
|
|
165
|
-
action: 'update';
|
|
166
|
-
}>['outputs']>;
|
|
167
|
-
abstract delete(memoryId: Extract<MemoryActions<T>, {
|
|
168
|
-
action: 'delete';
|
|
169
|
-
}>['inputs']['filter']): Promise<Extract<MemoryActions<T>, {
|
|
170
|
-
action: 'delete';
|
|
171
|
-
}>['outputs']>;
|
|
172
|
-
abstract reset(): Promise<void>;
|
|
173
|
-
}
|
|
174
|
-
export interface MemoryRunnerInput<C = undefined> {
|
|
175
|
-
messages: MemoryMessage[];
|
|
176
|
-
userId?: string;
|
|
177
|
-
sessionId?: string;
|
|
178
|
-
metadata?: MemoryMetadata;
|
|
179
|
-
filter?: MemoryMetadata;
|
|
180
|
-
customData: C;
|
|
181
|
-
}
|
|
182
|
-
export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
|
|
183
|
-
constructor(name: string);
|
|
184
|
-
}
|