@agentica/core 0.25.0 → 0.26.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.
Files changed (46) hide show
  1. package/README.md +56 -17
  2. package/lib/context/internal/AgenticaOperationComposer.spec.js +13 -5
  3. package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
  4. package/lib/events/AgenticaEvent.type.js +8 -0
  5. package/lib/events/AgenticaEvent.type.js.map +1 -0
  6. package/lib/factory/histories.js +38 -10
  7. package/lib/factory/histories.js.map +1 -1
  8. package/lib/histories/AgenticaHistory.d.ts +5 -3
  9. package/lib/histories/AgenticaSystemMessageHistory.d.ts +5 -0
  10. package/lib/histories/AgenticaSystemMessageHistory.js +3 -0
  11. package/lib/histories/AgenticaSystemMessageHistory.js.map +1 -0
  12. package/lib/histories/index.d.ts +1 -0
  13. package/lib/histories/index.js +1 -0
  14. package/lib/histories/index.js.map +1 -1
  15. package/lib/index.mjs +44 -8
  16. package/lib/index.mjs.map +1 -1
  17. package/lib/json/IAgenticaEventJson.d.ts +20 -1
  18. package/lib/json/IAgenticaEventJson.type.d.ts +1 -0
  19. package/lib/json/IAgenticaEventJson.type.js +8 -0
  20. package/lib/json/IAgenticaEventJson.type.js.map +1 -0
  21. package/lib/json/IAgenticaHistoryJson.d.ts +16 -6
  22. package/lib/json/IAgenticaHistoryJson.type.d.ts +1 -0
  23. package/lib/json/IAgenticaHistoryJson.type.js +8 -0
  24. package/lib/json/IAgenticaHistoryJson.type.js.map +1 -0
  25. package/lib/transformers/transformHistory.js +9 -0
  26. package/lib/transformers/transformHistory.js.map +1 -1
  27. package/lib/utils/types.d.ts +33 -0
  28. package/lib/utils/types.js +29 -0
  29. package/lib/utils/types.js.map +1 -0
  30. package/package.json +3 -2
  31. package/src/context/internal/AgenticaOperationComposer.spec.ts +15 -5
  32. package/src/events/AgenticaEvent.type.ts +19 -0
  33. package/src/factory/histories.ts +52 -10
  34. package/src/histories/AgenticaHistory.ts +6 -3
  35. package/src/histories/AgenticaSystemMessageHistory.ts +10 -0
  36. package/src/histories/index.ts +1 -0
  37. package/src/json/IAgenticaEventJson.ts +24 -0
  38. package/src/json/IAgenticaEventJson.type.ts +19 -0
  39. package/src/json/IAgenticaHistoryJson.ts +20 -8
  40. package/src/json/IAgenticaHistoryJson.type.ts +19 -0
  41. package/src/transformers/transformHistory.ts +14 -1
  42. package/src/utils/types.ts +50 -0
  43. package/lib/transformers/transformEvent.js +0 -198
  44. package/lib/transformers/transformEvent.js.map +0 -1
  45. package/src/transformers/transformEvent.ts +0 -248
  46. /package/lib/{transformers/transformEvent.d.ts → events/AgenticaEvent.type.d.ts} +0 -0
@@ -17,21 +17,22 @@ import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelect
17
17
  *
18
18
  * @author Samchon
19
19
  */
20
- export type IAgenticaHistoryJson = IAgenticaHistoryJson.IUserMessage | IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISelect | IAgenticaHistoryJson.ICancel | IAgenticaHistoryJson.IExecute | IAgenticaHistoryJson.IDescribe;
20
+ export type IAgenticaHistoryJson = IAgenticaHistoryJson.ISelect | IAgenticaHistoryJson.ICancel | IAgenticaHistoryJson.IExecute | IAgenticaHistoryJson.IDescribe | IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage | IAgenticaHistoryJson.IUserMessage;
21
21
  export declare namespace IAgenticaHistoryJson {
22
22
  export type Type = IAgenticaHistoryJson["type"];
23
23
  export interface Mapper {
24
- userMessage: IUserMessage;
25
- assistantMessage: IAssistantMessage;
26
24
  select: ISelect;
27
25
  cancel: ICancel;
28
26
  execute: IExecute;
29
27
  describe: IDescribe;
28
+ assistantMessage: IAssistantMessage;
29
+ systemMessage: ISystemMessage;
30
+ userMessage: IUserMessage;
30
31
  }
31
32
  /**
32
- * User prompt.
33
+ * User message.
33
34
  *
34
- * User prompt about the user's input.
35
+ * User message about the user's input.
35
36
  */
36
37
  export interface IUserMessage extends IBase<"userMessage"> {
37
38
  /**
@@ -40,7 +41,16 @@ export declare namespace IAgenticaHistoryJson {
40
41
  contents: Array<AgenticaUserMessageContent>;
41
42
  }
42
43
  /**
43
- * Assistant prompt.
44
+ * System message.
45
+ */
46
+ export interface ISystemMessage extends IBase<"systemMessage"> {
47
+ /**
48
+ * The text content.
49
+ */
50
+ text: string;
51
+ }
52
+ /**
53
+ * Assistant message.
44
54
  */
45
55
  export interface IAssistantMessage extends IBase<"assistantMessage"> {
46
56
  /**
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("../utils/types");
4
+ (0, types_1.checks)([
5
+ (0, types_1.check)(),
6
+ (0, types_1.check)(),
7
+ ]);
8
+ //# sourceMappingURL=IAgenticaHistoryJson.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAgenticaHistoryJson.type.js","sourceRoot":"","sources":["../../src/json/IAgenticaHistoryJson.type.ts"],"names":[],"mappings":";;AAGA,0CAA+C;AAI/C,IAAA,cAAM,EAAC;IACL,IAAA,aAAK,GAIF;IACH,IAAA,aAAK,GAIF;CACJ,CAAC,CAAC"}
@@ -19,6 +19,12 @@ function transformHistory(props) {
19
19
  history: props.history,
20
20
  });
21
21
  }
22
+ // SYSTEM
23
+ else if (props.history.type === "systemMessage") {
24
+ return transformSystemMessage({
25
+ history: props.history,
26
+ });
27
+ }
22
28
  // SELECT & CANCEL
23
29
  else if (props.history.type === "select") {
24
30
  return transformSelect({
@@ -47,6 +53,9 @@ function transformHistory(props) {
47
53
  function transformAssistantMessage(props) {
48
54
  return (0, histories_1.createAssistantMessageHistory)(props.history);
49
55
  }
56
+ function transformSystemMessage(props) {
57
+ return (0, histories_1.createSystemMessageHistory)(props.history);
58
+ }
50
59
  function transformUserMessage(props) {
51
60
  return (0, histories_1.createUserMessageHistory)(props.history);
52
61
  }
@@ -1 +1 @@
1
- {"version":3,"file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AAK,CAAC,OAAO,CAAC,SAAS;SAC/B,CAAC;QACF,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;QAClC;;;WAGG;QACH,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAgC;KACtD,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAiC,KAG1D;IACC,OAAO,IAAA,iCAAqB,EAAC;QAC3B,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI;QACxB,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAC1C,gBAAgB,CAAC;YACf,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,OAAO,EAAE,IAAI;SACd,CAAC,CACH;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAiC,KAMtD;;IACC,MAAM,KAAK,GAAyC,MAAA,KAAK,CAAC,UAAU;SACjE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,0CAC1B,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,oCAAoC,KAAK,CAAC,KAAK,CAAC,UAAU,eAAe,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,CACjG,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * from ts-toolbelt repository
3
+ * https://github.com/millsp/ts-toolbelt/blob/master/sources/Test.ts
4
+ */
5
+ type Equals<A1, A2> = (<A>() => A extends A2 ? 1 : 0) extends <A>() => A extends A1 ? 1 : 0 ? 1 : 0;
6
+ type Boolean = 0 | 1;
7
+ /**
8
+ * Test should pass
9
+ */
10
+ export type Pass = 1;
11
+ /**
12
+ * Test should fail
13
+ */
14
+ export type Fail = 0;
15
+ /**
16
+ * Check or test the validity of a type
17
+ * @param debug to debug with parameter hints (`ctrl+p`, `ctrl+shift+space`)
18
+ * @example
19
+ * ```ts
20
+ * // see in `tst` folder
21
+ * ```
22
+ */
23
+ export declare function check<Type, Expect, Outcome extends Boolean>(debug?: Type): Equals<Equals<Type, Expect>, Outcome>;
24
+ /**
25
+ * Validates a batch of [[check]]
26
+ * @param _checks a batch of [[check]]
27
+ * @example
28
+ * ```ts
29
+ * // see in `tst` folder
30
+ * ```
31
+ */
32
+ export declare function checks(_checks: 1[]): void;
33
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.check = check;
4
+ exports.checks = checks;
5
+ /**
6
+ * Check or test the validity of a type
7
+ * @param debug to debug with parameter hints (`ctrl+p`, `ctrl+shift+space`)
8
+ * @example
9
+ * ```ts
10
+ * // see in `tst` folder
11
+ * ```
12
+ */
13
+ function check(debug) {
14
+ if (debug !== undefined) {
15
+ // eslint-disable-next-line no-console
16
+ console.log(debug);
17
+ }
18
+ return 1;
19
+ }
20
+ /**
21
+ * Validates a batch of [[check]]
22
+ * @param _checks a batch of [[check]]
23
+ * @example
24
+ * ```ts
25
+ * // see in `tst` folder
26
+ * ```
27
+ */
28
+ function checks(_checks) { }
29
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;AA8BA,sBASC;AAUD,wBAA8C;AA3B9C;;;;;;;GAOG;AACH,SAAgB,KAAK,CACnB,KAAY;IAEZ,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,CAA0C,CAAC;AACpD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,MAAM,CAAC,OAAY,IAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentica/core",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Agentic AI Library specialized in LLM Function Calling",
5
5
  "author": "Wrtn Technologies",
6
6
  "license": "MIT",
@@ -50,9 +50,10 @@
50
50
  "@nestia/e2e": "^6.0.1",
51
51
  "@rollup/plugin-terser": "^0.4.4",
52
52
  "@rollup/plugin-typescript": "^12.1.2",
53
- "@ryoppippi/unplugin-typia": "^2.2.1",
53
+ "@ryoppippi/unplugin-typia": "^2.6.2",
54
54
  "@types/node": "^22.13.4",
55
55
  "@types/uuid": "^10.0.0",
56
+ "@wrtnlabs/calculator-mcp": "^0.2.1",
56
57
  "openai": "^4.80.0",
57
58
  "rimraf": "^6.0.1",
58
59
  "rollup": "^4.34.8",
@@ -1,7 +1,8 @@
1
1
  import type { IChatGptSchema, IHttpLlmFunction, ILlmFunction, IMcpLlmFunction, IValidation } from "@samchon/openapi";
2
2
 
3
3
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
4
+ import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory";
5
+ import { createServer } from "@wrtnlabs/calculator-mcp";
5
6
 
6
7
  import type { IAgenticaConfig } from "../../structures/IAgenticaConfig";
7
8
  import type { IAgenticaController } from "../../structures/IAgenticaController";
@@ -86,10 +87,19 @@ async function createMockMcpController(name: string, functions: IMcpLlmFunction<
86
87
 
87
88
  describe("a AgenticaOperationComposer", () => {
88
89
  beforeAll(async () => {
89
- await client.connect(new StdioClientTransport({
90
- command: "npx",
91
- args: ["-y", "@wrtnlabs/calculator-mcp"],
92
- }));
90
+ // eslint-disable-next-line ts/no-unsafe-call
91
+ const server = await createServer({
92
+ name: "calculator",
93
+ version: "1.0.0",
94
+ });
95
+
96
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
97
+
98
+ await Promise.all([
99
+ client.connect(clientTransport),
100
+ // eslint-disable-next-line ts/no-unsafe-call
101
+ server.connect(serverTransport),
102
+ ]);
93
103
  });
94
104
  describe("compose", () => {
95
105
  it("should compose operations from controllers", async () => {
@@ -0,0 +1,19 @@
1
+ import type { AgenticaHistory } from "../histories";
2
+ import type { Pass } from "../utils/types";
3
+
4
+ import { check, checks } from "../utils/types";
5
+
6
+ import type { AgenticaEvent } from "./AgenticaEvent";
7
+
8
+ checks([
9
+ check<
10
+ Exclude<AgenticaHistory.Type, "systemMessage"> extends AgenticaEvent.Type ? true : false,
11
+ true,
12
+ Pass
13
+ >(),
14
+ check<
15
+ Exclude<AgenticaHistory.Type, "systemMessage"> extends keyof AgenticaEvent.Mapper<any> ? true : false,
16
+ true,
17
+ Pass
18
+ >(),
19
+ ]);
@@ -10,6 +10,7 @@ import type { AgenticaDescribeHistory } from "../histories/AgenticaDescribeHisto
10
10
  import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
11
11
  import type { AgenticaHistory } from "../histories/AgenticaHistory";
12
12
  import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
13
+ import type { AgenticaSystemMessageHistory } from "../histories/AgenticaSystemMessageHistory";
13
14
  import type { AgenticaUserMessageHistory } from "../histories/AgenticaUserMessageHistory";
14
15
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
15
16
 
@@ -91,7 +92,8 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
91
92
  },
92
93
  ];
93
94
  }
94
- else if (history.type === "assistantMessage") {
95
+
96
+ if (history.type === "assistantMessage") {
95
97
  return [
96
98
  {
97
99
  role: "assistant",
@@ -99,18 +101,38 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
99
101
  },
100
102
  ];
101
103
  }
102
- return [
103
- {
104
- role: "user",
105
- content: history.contents.map(decodeUserMessageContent),
106
- },
107
- ];
104
+
105
+ if (history.type === "systemMessage") {
106
+ return [
107
+ {
108
+ role: "system",
109
+ content: history.text,
110
+ },
111
+ ];
112
+ }
113
+
114
+ if (history.type === "userMessage") {
115
+ const contents = history.contents;
116
+ return [
117
+ {
118
+ role: "user",
119
+ content: contents.map(decodeUserMessageContent),
120
+ },
121
+ ];
122
+ }
123
+
124
+ history satisfies never;
125
+ throw new Error(`Unsupported history type, value: ${JSON.stringify(history)}`);
108
126
  }
109
127
 
110
128
  /**
111
129
  * @internal
112
130
  */
113
131
  export function decodeUserMessageContent(content: AgenticaUserMessageContent): OpenAI.ChatCompletionContentPart {
132
+ if (content.type === "text") {
133
+ return content;
134
+ }
135
+
114
136
  if (content.type === "audio") {
115
137
  return {
116
138
  type: "input_audio",
@@ -120,7 +142,8 @@ export function decodeUserMessageContent(content: AgenticaUserMessageContent): O
120
142
  },
121
143
  };
122
144
  }
123
- else if (content.type === "file") {
145
+
146
+ if (content.type === "file") {
124
147
  return {
125
148
  type: "file",
126
149
  file: content.file.type === "data"
@@ -133,7 +156,8 @@ export function decodeUserMessageContent(content: AgenticaUserMessageContent): O
133
156
  },
134
157
  };
135
158
  }
136
- else if (content.type === "image") {
159
+
160
+ if (content.type === "image") {
137
161
  return {
138
162
  type: "image_url",
139
163
  image_url: {
@@ -142,7 +166,9 @@ export function decodeUserMessageContent(content: AgenticaUserMessageContent): O
142
166
  },
143
167
  };
144
168
  }
145
- return content;
169
+
170
+ content satisfies never;
171
+ throw new Error(`Unsupported user message content type, value: ${JSON.stringify(content)}`);
146
172
  }
147
173
 
148
174
  /* -----------------------------------------------------------
@@ -183,6 +209,22 @@ export function createAssistantMessageHistory(props: {
183
209
  };
184
210
  }
185
211
 
212
+ /**
213
+ * @internal
214
+ */
215
+ export function createSystemMessageHistory(props: {
216
+ text: string;
217
+ }): AgenticaSystemMessageHistory {
218
+ const prompt: IAgenticaHistoryJson.ISystemMessage = {
219
+ type: "systemMessage",
220
+ text: props.text,
221
+ };
222
+ return {
223
+ ...prompt,
224
+ toJSON: () => prompt,
225
+ };
226
+ }
227
+
186
228
  /**
187
229
  * @internal
188
230
  */
@@ -5,6 +5,7 @@ import type { AgenticaCancelHistory } from "./AgenticaCancelHistory";
5
5
  import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
6
6
  import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
7
7
  import type { AgenticaSelectHistory } from "./AgenticaSelectHistory";
8
+ import type { AgenticaSystemMessageHistory } from "./AgenticaSystemMessageHistory";
8
9
  import type { AgenticaUserMessageHistory } from "./AgenticaUserMessageHistory";
9
10
 
10
11
  export type AgenticaHistory<Model extends ILlmSchema.Model> =
@@ -13,15 +14,17 @@ export type AgenticaHistory<Model extends ILlmSchema.Model> =
13
14
  | AgenticaExecuteHistory<Model>
14
15
  | AgenticaSelectHistory<Model>
15
16
  | AgenticaAssistantMessageHistory
16
- | AgenticaUserMessageHistory;
17
+ | AgenticaUserMessageHistory
18
+ | AgenticaSystemMessageHistory;
17
19
  export namespace AgenticaHistory {
18
20
  export type Type = AgenticaHistory<any>["type"];
19
21
  export interface Mapper<Model extends ILlmSchema.Model> {
20
- assistantMessage: AgenticaAssistantMessageHistory;
21
- userMessage: AgenticaUserMessageHistory;
22
22
  select: AgenticaSelectHistory<Model>;
23
23
  cancel: AgenticaCancelHistory<Model>;
24
24
  execute: AgenticaExecuteHistory<Model>;
25
25
  describe: AgenticaDescribeHistory<Model>;
26
+ assistantMessage: AgenticaAssistantMessageHistory;
27
+ systemMessage: AgenticaSystemMessageHistory;
28
+ userMessage: AgenticaUserMessageHistory;
26
29
  }
27
30
  }
@@ -0,0 +1,10 @@
1
+ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
+
3
+ import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
4
+
5
+ export interface AgenticaSystemMessageHistory extends AgenticaHistoryBase<
6
+ "systemMessage",
7
+ IAgenticaHistoryJson.ISystemMessage
8
+ > {
9
+ text: string;
10
+ }
@@ -4,6 +4,7 @@ export * from "./AgenticaDescribeHistory";
4
4
  export * from "./AgenticaExecuteHistory";
5
5
  export * from "./AgenticaHistory";
6
6
  export * from "./AgenticaSelectHistory";
7
+ export * from "./AgenticaSystemMessageHistory";
7
8
  export * from "./AgenticaUserMessageHistory";
8
9
  export * from "./contents";
9
10
  export * from "./MicroAgenticaHistory";
@@ -25,10 +25,12 @@ export type IAgenticaEventJson =
25
25
  | IAgenticaEventJson.IExecute
26
26
  | IAgenticaEventJson.IInitialize
27
27
  | IAgenticaEventJson.IRequest
28
+ | IAgenticaEventJson.IResponse
28
29
  | IAgenticaEventJson.ISelect
29
30
  | IAgenticaEventJson.IValidate
30
31
  | IAgenticaEventJson.IAssistantMessage
31
32
  | IAgenticaEventJson.IUserMessage;
33
+
32
34
  export namespace IAgenticaEventJson {
33
35
  export type Type = IAgenticaEventJson["type"];
34
36
  export interface Mapper {
@@ -41,6 +43,8 @@ export namespace IAgenticaEventJson {
41
43
  execute: IExecute;
42
44
  describe: IDescribe;
43
45
  request: IRequest;
46
+ response: IResponse;
47
+ validate: IValidate;
44
48
  }
45
49
 
46
50
  /**
@@ -189,6 +193,26 @@ export namespace IAgenticaEventJson {
189
193
  options?: OpenAI.RequestOptions | undefined;
190
194
  }
191
195
 
196
+ /**
197
+ * Response event of LLM vendor API.
198
+ */
199
+ export interface IResponse extends IBase<"response"> {
200
+ /**
201
+ * The source agent of the response.
202
+ */
203
+ source: AgenticaEventSource;
204
+
205
+ /**
206
+ * Response body.
207
+ */
208
+ body: OpenAI.ChatCompletion;
209
+
210
+ /**
211
+ * Options for the request.
212
+ */
213
+ options?: OpenAI.RequestOptions | undefined;
214
+ }
215
+
192
216
  interface IBase<Type extends string> {
193
217
  /**
194
218
  * Discriminator type.
@@ -0,0 +1,19 @@
1
+ import type { AgenticaEvent } from "../events";
2
+ import type { Pass } from "../utils/types";
3
+
4
+ import { check, checks } from "../utils/types";
5
+
6
+ import type { IAgenticaEventJson } from "./IAgenticaEventJson";
7
+
8
+ checks([
9
+ check<
10
+ AgenticaEvent.Type,
11
+ IAgenticaEventJson.Type,
12
+ Pass
13
+ >(),
14
+ check<
15
+ AgenticaEvent.Type,
16
+ keyof IAgenticaEventJson.Mapper,
17
+ Pass
18
+ >(),
19
+ ]);
@@ -20,27 +20,29 @@ import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelect
20
20
  * @author Samchon
21
21
  */
22
22
  export type IAgenticaHistoryJson =
23
- | IAgenticaHistoryJson.IUserMessage
24
- | IAgenticaHistoryJson.IAssistantMessage
25
23
  | IAgenticaHistoryJson.ISelect
26
24
  | IAgenticaHistoryJson.ICancel
27
25
  | IAgenticaHistoryJson.IExecute
28
- | IAgenticaHistoryJson.IDescribe;
26
+ | IAgenticaHistoryJson.IDescribe
27
+ | IAgenticaHistoryJson.IAssistantMessage
28
+ | IAgenticaHistoryJson.ISystemMessage
29
+ | IAgenticaHistoryJson.IUserMessage;
29
30
  export namespace IAgenticaHistoryJson {
30
31
  export type Type = IAgenticaHistoryJson["type"];
31
32
  export interface Mapper {
32
- userMessage: IUserMessage;
33
- assistantMessage: IAssistantMessage;
34
33
  select: ISelect;
35
34
  cancel: ICancel;
36
35
  execute: IExecute;
37
36
  describe: IDescribe;
37
+ assistantMessage: IAssistantMessage;
38
+ systemMessage: ISystemMessage;
39
+ userMessage: IUserMessage;
38
40
  }
39
41
 
40
42
  /**
41
- * User prompt.
43
+ * User message.
42
44
  *
43
- * User prompt about the user's input.
45
+ * User message about the user's input.
44
46
  */
45
47
  export interface IUserMessage extends IBase<"userMessage"> {
46
48
  /**
@@ -50,7 +52,17 @@ export namespace IAgenticaHistoryJson {
50
52
  }
51
53
 
52
54
  /**
53
- * Assistant prompt.
55
+ * System message.
56
+ */
57
+ export interface ISystemMessage extends IBase<"systemMessage"> {
58
+ /**
59
+ * The text content.
60
+ */
61
+ text: string;
62
+ }
63
+
64
+ /**
65
+ * Assistant message.
54
66
  */
55
67
  export interface IAssistantMessage extends IBase<"assistantMessage"> {
56
68
  /**
@@ -0,0 +1,19 @@
1
+ import type { AgenticaHistory } from "../histories";
2
+ import type { Pass } from "../utils/types";
3
+
4
+ import { check, checks } from "../utils/types";
5
+
6
+ import type { IAgenticaHistoryJson } from "./IAgenticaHistoryJson";
7
+
8
+ checks([
9
+ check<
10
+ AgenticaHistory.Type,
11
+ IAgenticaHistoryJson.Type,
12
+ Pass
13
+ >(),
14
+ check<
15
+ AgenticaHistory.Type,
16
+ keyof IAgenticaHistoryJson.Mapper,
17
+ Pass
18
+ >(),
19
+ ]);
@@ -8,9 +8,10 @@ import type { AgenticaDescribeHistory } from "../histories/AgenticaDescribeHisto
8
8
  import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
9
9
  import type { AgenticaHistory } from "../histories/AgenticaHistory";
10
10
  import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
11
+ import type { AgenticaSystemMessageHistory } from "../histories/AgenticaSystemMessageHistory";
11
12
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
12
13
 
13
- import { createAssistantMessageHistory, createCancelHistory, createDescribeHistory, createExecuteHistory, createSelectHistory, createUserMessageHistory } from "../factory/histories";
14
+ import { createAssistantMessageHistory, createCancelHistory, createDescribeHistory, createExecuteHistory, createSelectHistory, createSystemMessageHistory, createUserMessageHistory } from "../factory/histories";
14
15
  import { createOperationSelection } from "../factory/operations";
15
16
 
16
17
  /**
@@ -32,6 +33,12 @@ export function transformHistory<Model extends ILlmSchema.Model>(props: {
32
33
  history: props.history,
33
34
  });
34
35
  }
36
+ // SYSTEM
37
+ else if (props.history.type === "systemMessage") {
38
+ return transformSystemMessage({
39
+ history: props.history,
40
+ });
41
+ }
35
42
  // SELECT & CANCEL
36
43
  else if (props.history.type === "select") {
37
44
  return transformSelect({
@@ -64,6 +71,12 @@ function transformAssistantMessage(props: {
64
71
  return createAssistantMessageHistory(props.history);
65
72
  }
66
73
 
74
+ function transformSystemMessage(props: {
75
+ history: IAgenticaHistoryJson.ISystemMessage;
76
+ }): AgenticaSystemMessageHistory {
77
+ return createSystemMessageHistory(props.history);
78
+ }
79
+
67
80
  function transformUserMessage(props: {
68
81
  history: IAgenticaHistoryJson.IUserMessage;
69
82
  }): AgenticaUserMessageHistory {
@@ -0,0 +1,50 @@
1
+ /**
2
+ * from ts-toolbelt repository
3
+ * https://github.com/millsp/ts-toolbelt/blob/master/sources/Test.ts
4
+ */
5
+
6
+ type Equals<A1, A2> = (<A>() => A extends A2 ? 1 : 0) extends <
7
+ A,
8
+ >() => A extends A1 ? 1 : 0
9
+ ? 1
10
+ : 0;
11
+
12
+ type Boolean = 0 | 1;
13
+ /**
14
+ * Test should pass
15
+ */
16
+ export type Pass = 1;
17
+
18
+ /**
19
+ * Test should fail
20
+ */
21
+ export type Fail = 0;
22
+
23
+ /**
24
+ * Check or test the validity of a type
25
+ * @param debug to debug with parameter hints (`ctrl+p`, `ctrl+shift+space`)
26
+ * @example
27
+ * ```ts
28
+ * // see in `tst` folder
29
+ * ```
30
+ */
31
+ export function check<Type, Expect, Outcome extends Boolean>(
32
+ debug?: Type,
33
+ ): Equals<Equals<Type, Expect>, Outcome> {
34
+ if (debug !== undefined) {
35
+ // eslint-disable-next-line no-console
36
+ console.log(debug);
37
+ }
38
+
39
+ return 1 as Equals<Equals<Type, Expect>, Outcome>;
40
+ }
41
+
42
+ /**
43
+ * Validates a batch of [[check]]
44
+ * @param _checks a batch of [[check]]
45
+ * @example
46
+ * ```ts
47
+ * // see in `tst` folder
48
+ * ```
49
+ */
50
+ export function checks(_checks: 1[]): void { }