@illalabs/sdk 0.0.0-dev-1-9cae6c3-20251024211627

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 (202) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/asyncToolChecker/AsyncToolChecker.d.ts +39 -0
  3. package/dist/src/asyncToolChecker/AsyncToolChecker.d.ts.map +1 -0
  4. package/dist/src/asyncToolChecker/AsyncToolChecker.js +209 -0
  5. package/dist/src/asyncToolChecker/AsyncToolChecker.js.map +1 -0
  6. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMaxRetriesExceeded.d.ts +23 -0
  7. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMaxRetriesExceeded.d.ts.map +1 -0
  8. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMaxRetriesExceeded.js +30 -0
  9. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMaxRetriesExceeded.js.map +1 -0
  10. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMethodNotImplemented.d.ts +17 -0
  11. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMethodNotImplemented.d.ts.map +1 -0
  12. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMethodNotImplemented.js +26 -0
  13. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerMethodNotImplemented.js.map +1 -0
  14. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerTimeout.d.ts +17 -0
  15. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerTimeout.d.ts.map +1 -0
  16. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerTimeout.js +21 -0
  17. package/dist/src/asyncToolChecker/errors/AsyncToolCheckerTimeout.js.map +1 -0
  18. package/dist/src/asyncToolChecker/errors/index.d.ts +4 -0
  19. package/dist/src/asyncToolChecker/errors/index.d.ts.map +1 -0
  20. package/dist/src/asyncToolChecker/errors/index.js +4 -0
  21. package/dist/src/asyncToolChecker/errors/index.js.map +1 -0
  22. package/dist/src/asyncToolChecker/index.d.ts +6 -0
  23. package/dist/src/asyncToolChecker/index.d.ts.map +1 -0
  24. package/dist/src/asyncToolChecker/index.js +5 -0
  25. package/dist/src/asyncToolChecker/index.js.map +1 -0
  26. package/dist/src/asyncToolChecker/types.d.ts +24 -0
  27. package/dist/src/asyncToolChecker/types.d.ts.map +1 -0
  28. package/dist/src/asyncToolChecker/types.js +2 -0
  29. package/dist/src/asyncToolChecker/types.js.map +1 -0
  30. package/dist/src/asyncToolChecker/utils/index.d.ts +3 -0
  31. package/dist/src/asyncToolChecker/utils/index.d.ts.map +1 -0
  32. package/dist/src/asyncToolChecker/utils/index.js +3 -0
  33. package/dist/src/asyncToolChecker/utils/index.js.map +1 -0
  34. package/dist/src/asyncToolChecker/utils/isErrorResponse.d.ts +11 -0
  35. package/dist/src/asyncToolChecker/utils/isErrorResponse.d.ts.map +1 -0
  36. package/dist/src/asyncToolChecker/utils/isErrorResponse.js +12 -0
  37. package/dist/src/asyncToolChecker/utils/isErrorResponse.js.map +1 -0
  38. package/dist/src/asyncToolChecker/utils/normalizeTimeout.d.ts +9 -0
  39. package/dist/src/asyncToolChecker/utils/normalizeTimeout.d.ts.map +1 -0
  40. package/dist/src/asyncToolChecker/utils/normalizeTimeout.js +14 -0
  41. package/dist/src/asyncToolChecker/utils/normalizeTimeout.js.map +1 -0
  42. package/dist/src/caching/InMemoryCache.d.ts +14 -0
  43. package/dist/src/caching/InMemoryCache.d.ts.map +1 -0
  44. package/dist/src/caching/InMemoryCache.js +31 -0
  45. package/dist/src/caching/InMemoryCache.js.map +1 -0
  46. package/dist/src/caching/index.d.ts +3 -0
  47. package/dist/src/caching/index.d.ts.map +1 -0
  48. package/dist/src/caching/index.js +2 -0
  49. package/dist/src/caching/index.js.map +1 -0
  50. package/dist/src/chat/Chat.d.ts +62 -0
  51. package/dist/src/chat/Chat.d.ts.map +1 -0
  52. package/dist/src/chat/Chat.js +126 -0
  53. package/dist/src/chat/Chat.js.map +1 -0
  54. package/dist/src/chat/errors/ChatAsyncToolCheckerUnavailable.d.ts +19 -0
  55. package/dist/src/chat/errors/ChatAsyncToolCheckerUnavailable.d.ts.map +1 -0
  56. package/dist/src/chat/errors/ChatAsyncToolCheckerUnavailable.js +28 -0
  57. package/dist/src/chat/errors/ChatAsyncToolCheckerUnavailable.js.map +1 -0
  58. package/dist/src/chat/errors/index.d.ts +2 -0
  59. package/dist/src/chat/errors/index.d.ts.map +1 -0
  60. package/dist/src/chat/errors/index.js +2 -0
  61. package/dist/src/chat/errors/index.js.map +1 -0
  62. package/dist/src/chat/index.d.ts +5 -0
  63. package/dist/src/chat/index.d.ts.map +1 -0
  64. package/dist/src/chat/index.js +3 -0
  65. package/dist/src/chat/index.js.map +1 -0
  66. package/dist/src/chat/types.d.ts +9 -0
  67. package/dist/src/chat/types.d.ts.map +1 -0
  68. package/dist/src/chat/types.js +2 -0
  69. package/dist/src/chat/types.js.map +1 -0
  70. package/dist/src/chat/utils/index.d.ts +2 -0
  71. package/dist/src/chat/utils/index.d.ts.map +1 -0
  72. package/dist/src/chat/utils/index.js +2 -0
  73. package/dist/src/chat/utils/index.js.map +1 -0
  74. package/dist/src/chat/utils/uuid.d.ts +12 -0
  75. package/dist/src/chat/utils/uuid.d.ts.map +1 -0
  76. package/dist/src/chat/utils/uuid.js +19 -0
  77. package/dist/src/chat/utils/uuid.js.map +1 -0
  78. package/dist/src/context/ContextManager.d.ts +26 -0
  79. package/dist/src/context/ContextManager.d.ts.map +1 -0
  80. package/dist/src/context/ContextManager.js +93 -0
  81. package/dist/src/context/ContextManager.js.map +1 -0
  82. package/dist/src/context/index.d.ts +2 -0
  83. package/dist/src/context/index.d.ts.map +1 -0
  84. package/dist/src/context/index.js +2 -0
  85. package/dist/src/context/index.js.map +1 -0
  86. package/dist/src/context/types.d.ts +17 -0
  87. package/dist/src/context/types.d.ts.map +1 -0
  88. package/dist/src/context/types.js +2 -0
  89. package/dist/src/context/types.js.map +1 -0
  90. package/dist/src/external.d.ts +14 -0
  91. package/dist/src/external.d.ts.map +1 -0
  92. package/dist/src/external.js +13 -0
  93. package/dist/src/external.js.map +1 -0
  94. package/dist/src/index.d.ts +8 -0
  95. package/dist/src/index.d.ts.map +1 -0
  96. package/dist/src/index.js +8 -0
  97. package/dist/src/index.js.map +1 -0
  98. package/dist/src/interfaces/asyncToolChecker.interface.d.ts +85 -0
  99. package/dist/src/interfaces/asyncToolChecker.interface.d.ts.map +1 -0
  100. package/dist/src/interfaces/asyncToolChecker.interface.js +2 -0
  101. package/dist/src/interfaces/asyncToolChecker.interface.js.map +1 -0
  102. package/dist/src/interfaces/cache.interface.d.ts +35 -0
  103. package/dist/src/interfaces/cache.interface.d.ts.map +1 -0
  104. package/dist/src/interfaces/cache.interface.js +2 -0
  105. package/dist/src/interfaces/cache.interface.js.map +1 -0
  106. package/dist/src/interfaces/chat.interface.d.ts +84 -0
  107. package/dist/src/interfaces/chat.interface.d.ts.map +1 -0
  108. package/dist/src/interfaces/chat.interface.js +2 -0
  109. package/dist/src/interfaces/chat.interface.js.map +1 -0
  110. package/dist/src/interfaces/contextManager.interface.d.ts +86 -0
  111. package/dist/src/interfaces/contextManager.interface.d.ts.map +1 -0
  112. package/dist/src/interfaces/contextManager.interface.js +2 -0
  113. package/dist/src/interfaces/contextManager.interface.js.map +1 -0
  114. package/dist/src/interfaces/coreApiProvider.interface.d.ts +26 -0
  115. package/dist/src/interfaces/coreApiProvider.interface.d.ts.map +1 -0
  116. package/dist/src/interfaces/coreApiProvider.interface.js +2 -0
  117. package/dist/src/interfaces/coreApiProvider.interface.js.map +1 -0
  118. package/dist/src/interfaces/index.d.ts +7 -0
  119. package/dist/src/interfaces/index.d.ts.map +1 -0
  120. package/dist/src/interfaces/index.js +2 -0
  121. package/dist/src/interfaces/index.js.map +1 -0
  122. package/dist/src/internal.d.ts +14 -0
  123. package/dist/src/internal.d.ts.map +1 -0
  124. package/dist/src/internal.js +14 -0
  125. package/dist/src/internal.js.map +1 -0
  126. package/dist/src/prompt/Prompt.d.ts +61 -0
  127. package/dist/src/prompt/Prompt.d.ts.map +1 -0
  128. package/dist/src/prompt/Prompt.js +118 -0
  129. package/dist/src/prompt/Prompt.js.map +1 -0
  130. package/dist/src/prompt/errors/PromptConfigurationConflict.d.ts +10 -0
  131. package/dist/src/prompt/errors/PromptConfigurationConflict.d.ts.map +1 -0
  132. package/dist/src/prompt/errors/PromptConfigurationConflict.js +13 -0
  133. package/dist/src/prompt/errors/PromptConfigurationConflict.js.map +1 -0
  134. package/dist/src/prompt/errors/index.d.ts +2 -0
  135. package/dist/src/prompt/errors/index.d.ts.map +1 -0
  136. package/dist/src/prompt/errors/index.js +2 -0
  137. package/dist/src/prompt/errors/index.js.map +1 -0
  138. package/dist/src/prompt/index.d.ts +4 -0
  139. package/dist/src/prompt/index.d.ts.map +1 -0
  140. package/dist/src/prompt/index.js +3 -0
  141. package/dist/src/prompt/index.js.map +1 -0
  142. package/dist/src/prompt/types.d.ts +57 -0
  143. package/dist/src/prompt/types.d.ts.map +1 -0
  144. package/dist/src/prompt/types.js +2 -0
  145. package/dist/src/prompt/types.js.map +1 -0
  146. package/dist/src/prompt/utils/cloneToolResult.d.ts +12 -0
  147. package/dist/src/prompt/utils/cloneToolResult.d.ts.map +1 -0
  148. package/dist/src/prompt/utils/cloneToolResult.js +28 -0
  149. package/dist/src/prompt/utils/cloneToolResult.js.map +1 -0
  150. package/dist/src/prompt/utils/deepClone.d.ts +9 -0
  151. package/dist/src/prompt/utils/deepClone.d.ts.map +1 -0
  152. package/dist/src/prompt/utils/deepClone.js +15 -0
  153. package/dist/src/prompt/utils/deepClone.js.map +1 -0
  154. package/dist/src/prompt/utils/index.d.ts +5 -0
  155. package/dist/src/prompt/utils/index.d.ts.map +1 -0
  156. package/dist/src/prompt/utils/index.js +5 -0
  157. package/dist/src/prompt/utils/index.js.map +1 -0
  158. package/dist/src/prompt/utils/normalizeTextPrompt.d.ts +14 -0
  159. package/dist/src/prompt/utils/normalizeTextPrompt.d.ts.map +1 -0
  160. package/dist/src/prompt/utils/normalizeTextPrompt.js +22 -0
  161. package/dist/src/prompt/utils/normalizeTextPrompt.js.map +1 -0
  162. package/dist/src/prompt/utils/normalizeToolResult.d.ts +14 -0
  163. package/dist/src/prompt/utils/normalizeToolResult.d.ts.map +1 -0
  164. package/dist/src/prompt/utils/normalizeToolResult.js +27 -0
  165. package/dist/src/prompt/utils/normalizeToolResult.js.map +1 -0
  166. package/dist/src/providers/coreApiProvider/CoreApiProvider.d.ts +35 -0
  167. package/dist/src/providers/coreApiProvider/CoreApiProvider.d.ts.map +1 -0
  168. package/dist/src/providers/coreApiProvider/CoreApiProvider.js +93 -0
  169. package/dist/src/providers/coreApiProvider/CoreApiProvider.js.map +1 -0
  170. package/dist/src/providers/coreApiProvider/CoreApiProviderConfig.d.ts +24 -0
  171. package/dist/src/providers/coreApiProvider/CoreApiProviderConfig.d.ts.map +1 -0
  172. package/dist/src/providers/coreApiProvider/CoreApiProviderConfig.js +2 -0
  173. package/dist/src/providers/coreApiProvider/CoreApiProviderConfig.js.map +1 -0
  174. package/dist/src/providers/coreApiProvider/RequestOptions.d.ts +10 -0
  175. package/dist/src/providers/coreApiProvider/RequestOptions.d.ts.map +1 -0
  176. package/dist/src/providers/coreApiProvider/RequestOptions.js +2 -0
  177. package/dist/src/providers/coreApiProvider/RequestOptions.js.map +1 -0
  178. package/dist/src/providers/coreApiProvider/errors/CoreApiAuthenticationMissing.d.ts +10 -0
  179. package/dist/src/providers/coreApiProvider/errors/CoreApiAuthenticationMissing.d.ts.map +1 -0
  180. package/dist/src/providers/coreApiProvider/errors/CoreApiAuthenticationMissing.js +14 -0
  181. package/dist/src/providers/coreApiProvider/errors/CoreApiAuthenticationMissing.js.map +1 -0
  182. package/dist/src/providers/coreApiProvider/errors/CoreApiMethodNotImplemented.d.ts +9 -0
  183. package/dist/src/providers/coreApiProvider/errors/CoreApiMethodNotImplemented.d.ts.map +1 -0
  184. package/dist/src/providers/coreApiProvider/errors/CoreApiMethodNotImplemented.js +19 -0
  185. package/dist/src/providers/coreApiProvider/errors/CoreApiMethodNotImplemented.js.map +1 -0
  186. package/dist/src/providers/coreApiProvider/errors/index.d.ts +3 -0
  187. package/dist/src/providers/coreApiProvider/errors/index.d.ts.map +1 -0
  188. package/dist/src/providers/coreApiProvider/errors/index.js +3 -0
  189. package/dist/src/providers/coreApiProvider/errors/index.js.map +1 -0
  190. package/dist/src/providers/coreApiProvider/index.d.ts +7 -0
  191. package/dist/src/providers/coreApiProvider/index.d.ts.map +1 -0
  192. package/dist/src/providers/coreApiProvider/index.js +3 -0
  193. package/dist/src/providers/coreApiProvider/index.js.map +1 -0
  194. package/dist/src/providers/coreApiProvider/types.d.ts +7 -0
  195. package/dist/src/providers/coreApiProvider/types.d.ts.map +1 -0
  196. package/dist/src/providers/coreApiProvider/types.js +2 -0
  197. package/dist/src/providers/coreApiProvider/types.js.map +1 -0
  198. package/dist/src/providers/index.d.ts +2 -0
  199. package/dist/src/providers/index.d.ts.map +1 -0
  200. package/dist/src/providers/index.js +2 -0
  201. package/dist/src/providers/index.js.map +1 -0
  202. package/package.json +43 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Default cache implementation that keeps values in memory.
3
+ */
4
+ export class InMemoryCache {
5
+ store = new Map();
6
+ /** @inheritdoc */
7
+ async get(key) {
8
+ const entry = this.store.get(key);
9
+ if (entry === undefined) {
10
+ return undefined;
11
+ }
12
+ if (entry.expiresAt !== undefined && entry.expiresAt <= Date.now()) {
13
+ this.store.delete(key);
14
+ return undefined;
15
+ }
16
+ return entry.value;
17
+ }
18
+ /** @inheritdoc */
19
+ async set(key, value, options = {}) {
20
+ const expiresAt = options.ttl !== undefined ? Date.now() + options.ttl : undefined;
21
+ this.store.set(key, {
22
+ value,
23
+ expiresAt,
24
+ });
25
+ }
26
+ /** @inheritdoc */
27
+ async del(key) {
28
+ this.store.delete(key);
29
+ }
30
+ }
31
+ //# sourceMappingURL=InMemoryCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryCache.js","sourceRoot":"","sources":["../../../src/caching/InMemoryCache.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAO,aAAa;IACL,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEjE,kBAAkB;IACX,KAAK,CAAC,GAAG,CAAS,GAAW;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,SAAS,CAAC;QACrB,CAAC;QAED,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YACjE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,SAAS,CAAC;QACrB,CAAC;QAED,OAAO,KAAK,CAAC,KAAe,CAAC;IACjC,CAAC;IAED,kBAAkB;IACX,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAc,EAAE,UAA6B,EAAE;QACzE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;QAEnF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,KAAK;YACL,SAAS;SACZ,CAAC,CAAC;IACP,CAAC;IAED,kBAAkB;IACX,KAAK,CAAC,GAAG,CAAC,GAAW;QACxB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export type { CacheEntryOptions, ICache } from "../interfaces/cache.interface.js";
2
+ export { InMemoryCache } from "./InMemoryCache.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/caching/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { InMemoryCache } from "./InMemoryCache.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/caching/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,62 @@
1
+ import type { AwaitableActionDescriptor, AwaitActionResult } from "../asyncToolChecker/index.js";
2
+ import type { ChatContextSnapshot, ChatOptions, SendMessageResult } from "../interfaces/index.js";
3
+ import type { Prompt } from "../prompt/index.js";
4
+ /**
5
+ * Represents a conversational session with the Illa Core API.
6
+ */
7
+ export declare class Chat {
8
+ private readonly id;
9
+ private readonly coreApiProvider;
10
+ private readonly contextManager;
11
+ private readonly asyncToolChecker?;
12
+ private readonly defaultRole;
13
+ private readonly userContext;
14
+ /**
15
+ * Creates a new {@link Chat} instance.
16
+ *
17
+ * @param options Chat construction options including dependencies.
18
+ */
19
+ constructor(options: ChatOptions);
20
+ /**
21
+ * Retrieves the identifier associated with this chat instance.
22
+ *
23
+ * @returns Chat identifier.
24
+ */
25
+ getId(): string;
26
+ /**
27
+ * Sends a prompt to the Core API and returns the processed result.
28
+ *
29
+ * @param prompt Prompt instance representing the message to be processed.
30
+ *
31
+ * @returns Structured chat result containing the processed response.
32
+ */
33
+ sendMessage(prompt: Prompt): Promise<SendMessageResult>;
34
+ private buildRequest;
35
+ private static isSuccessResponse;
36
+ /**
37
+ * Awaits the completion of a long running action triggered by the conversation.
38
+ *
39
+ * When the chat has no async tool checker configured, the method throws a
40
+ * {@link ChatAsyncToolCheckerUnavailable} error; otherwise it delegates the
41
+ * request to the checker and returns its result.
42
+ *
43
+ * @param descriptor Descriptor identifying the action to track.
44
+ *
45
+ * @throws {ChatAsyncToolCheckerUnavailable} When no async tool checker is configured.
46
+ *
47
+ * @returns Action status result emitted by the async tool checker.
48
+ */
49
+ awaitAction(descriptor: AwaitableActionDescriptor): Promise<AwaitActionResult>;
50
+ /**
51
+ * Retrieves the current chat context including messages and tool configuration. *
52
+ * @returns Snapshot of the chat context.
53
+ */
54
+ getContext(): Promise<ChatContextSnapshot>;
55
+ /**
56
+ * Replaces the persisted chat context with the provided snapshot.
57
+ *
58
+ * @param snapshot Context snapshot to store.
59
+ */
60
+ setContext(snapshot: ChatContextSnapshot): Promise<void>;
61
+ }
62
+ //# sourceMappingURL=Chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/chat/Chat.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAER,yBAAyB,EACzB,iBAAiB,EACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACR,mBAAmB,EACnB,WAAW,EAGX,iBAAiB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAA4B,MAAM,EAAc,MAAM,oBAAoB,CAAC;AAIvF;;GAEG;AACH,qBAAa,IAAI;IACb,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAE5B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;IAEnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkB;IAEjD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAmB;IAErD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IAEzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAE1C;;;;OAIG;gBACgB,OAAO,EAAE,WAAW;IASvC;;;;OAIG;IACI,KAAK,IAAI,MAAM;IAItB;;;;;;OAMG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkCpE,OAAO,CAAC,YAAY;IAoBpB,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAMhC;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,UAAU,EAAE,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAe3F;;;OAGG;IACU,UAAU,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIvD;;;;OAIG;IACU,UAAU,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CAIxE"}
@@ -0,0 +1,126 @@
1
+ import { ChatAsyncToolCheckerUnavailable } from "./errors/index.js";
2
+ import { generateUUID } from "./utils/index.js";
3
+ /**
4
+ * Represents a conversational session with the Illa Core API.
5
+ */
6
+ export class Chat {
7
+ id;
8
+ coreApiProvider;
9
+ contextManager;
10
+ asyncToolChecker;
11
+ defaultRole;
12
+ userContext;
13
+ /**
14
+ * Creates a new {@link Chat} instance.
15
+ *
16
+ * @param options Chat construction options including dependencies.
17
+ */
18
+ constructor(options) {
19
+ this.id = options.id ?? generateUUID();
20
+ this.coreApiProvider = options.coreApiProvider;
21
+ this.contextManager = options.contextManager;
22
+ this.asyncToolChecker = options.asyncToolChecker;
23
+ this.defaultRole = options.defaultRole ?? "user";
24
+ this.userContext = options.userContext;
25
+ }
26
+ /**
27
+ * Retrieves the identifier associated with this chat instance.
28
+ *
29
+ * @returns Chat identifier.
30
+ */
31
+ getId() {
32
+ return this.id;
33
+ }
34
+ /**
35
+ * Sends a prompt to the Core API and returns the processed result.
36
+ *
37
+ * @param prompt Prompt instance representing the message to be processed.
38
+ *
39
+ * @returns Structured chat result containing the processed response.
40
+ */
41
+ async sendMessage(prompt) {
42
+ const promptSnapshot = prompt.getSnapshot();
43
+ const normalizedPrompt = prompt.getNormalizedSnapshot(this.defaultRole);
44
+ const originalContext = await this.contextManager.getContext(this.id);
45
+ const { body, messages: stagedMessages } = this.buildRequest(originalContext, normalizedPrompt);
46
+ const response = await this.coreApiProvider.sendMessage(body);
47
+ if (!Chat.isSuccessResponse(response)) {
48
+ return {
49
+ chatId: this.id,
50
+ prompt: body.prompt,
51
+ promptSnapshot,
52
+ messages: stagedMessages,
53
+ toolsConfig: originalContext.toolsConfig,
54
+ response,
55
+ };
56
+ }
57
+ await this.contextManager.setMessages(this.id, response.messages);
58
+ await this.contextManager.setToolsConfig(this.id, originalContext.toolsConfig);
59
+ return {
60
+ chatId: this.id,
61
+ prompt: body.prompt,
62
+ promptSnapshot,
63
+ messages: response.messages,
64
+ toolsConfig: originalContext.toolsConfig,
65
+ response,
66
+ };
67
+ }
68
+ buildRequest(context, normalizedPrompt) {
69
+ return {
70
+ body: {
71
+ toolsConfig: context.toolsConfig,
72
+ messages: context.messages,
73
+ userContext: this.userContext,
74
+ prompt: normalizedPrompt.message,
75
+ },
76
+ messages: context.messages,
77
+ toolsConfig: context.toolsConfig,
78
+ };
79
+ }
80
+ static isSuccessResponse(response) {
81
+ return "status" in response && response.status === 200;
82
+ }
83
+ /**
84
+ * Awaits the completion of a long running action triggered by the conversation.
85
+ *
86
+ * When the chat has no async tool checker configured, the method throws a
87
+ * {@link ChatAsyncToolCheckerUnavailable} error; otherwise it delegates the
88
+ * request to the checker and returns its result.
89
+ *
90
+ * @param descriptor Descriptor identifying the action to track.
91
+ *
92
+ * @throws {ChatAsyncToolCheckerUnavailable} When no async tool checker is configured.
93
+ *
94
+ * @returns Action status result emitted by the async tool checker.
95
+ */
96
+ async awaitAction(descriptor) {
97
+ if (this.asyncToolChecker === undefined) {
98
+ throw new ChatAsyncToolCheckerUnavailable({
99
+ chatId: this.getId(),
100
+ descriptor,
101
+ });
102
+ }
103
+ return this.asyncToolChecker.check({
104
+ toolName: descriptor.toolName,
105
+ protocol: descriptor.protocol,
106
+ descriptor: descriptor.args,
107
+ });
108
+ }
109
+ /**
110
+ * Retrieves the current chat context including messages and tool configuration. *
111
+ * @returns Snapshot of the chat context.
112
+ */
113
+ async getContext() {
114
+ return this.contextManager.getContext(this.id);
115
+ }
116
+ /**
117
+ * Replaces the persisted chat context with the provided snapshot.
118
+ *
119
+ * @param snapshot Context snapshot to store.
120
+ */
121
+ async setContext(snapshot) {
122
+ await this.contextManager.setMessages(this.id, snapshot.messages);
123
+ await this.contextManager.setToolsConfig(this.id, snapshot.toolsConfig);
124
+ }
125
+ }
126
+ //# sourceMappingURL=Chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chat.js","sourceRoot":"","sources":["../../../src/chat/Chat.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,IAAI;IACI,EAAE,CAAS;IAEX,eAAe,CAAmB;IAElC,cAAc,CAAkB;IAEhC,gBAAgB,CAAoB;IAEpC,WAAW,CAAa;IAExB,WAAW,CAAc;IAE1C;;;;OAIG;IACH,YAAmB,OAAoB;QACnC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,YAAY,EAAE,CAAC;QACvC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,MAAM,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACI,KAAK;QACR,OAAO,IAAI,CAAC,EAAE,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,MAAc;QACnC,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,gBAAgB,GAAG,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAA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,EAAE,OAAO,CAAC,QAAQ;YAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;SACnC,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,iBAAiB,CAC5B,QAA6B;QAE7B,OAAO,QAAQ,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC;IAC3D,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,WAAW,CAAC,UAAqC;QAC1D,IAAI,IAAI,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,+BAA+B,CAAC;gBACtC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE;gBACpB,UAAU;aACb,CAAC,CAAC;QACP,CAAC;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,UAAU,EAAE,UAAU,CAAC,IAAI;SAC9B,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,UAAU;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,UAAU,CAAC,QAA6B;QACjD,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC5E,CAAC;CACJ"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Error emitted when attempting to await an action without configuring an async tool checker.
3
+ *
4
+ * The error may include a `context` property with additional debugging information
5
+ * such as the `chatId` and the original `descriptor` of the awaited action.
6
+ */
7
+ export declare class ChatAsyncToolCheckerUnavailable extends Error {
8
+ /**
9
+ * Optional context describing the awaited action and chat details.
10
+ */
11
+ readonly context?: unknown;
12
+ /**
13
+ * Creates a new {@link ChatAsyncToolCheckerUnavailable} instance.
14
+ *
15
+ * @param context Additional context useful for debugging, e.g. `{ chatId: string, descriptor: unknown }`.
16
+ */
17
+ constructor(context?: unknown);
18
+ }
19
+ //# sourceMappingURL=ChatAsyncToolCheckerUnavailable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatAsyncToolCheckerUnavailable.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/ChatAsyncToolCheckerUnavailable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;IACtD;;OAEG;IACH,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,OAAO;CAUvC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Error emitted when attempting to await an action without configuring an async tool checker.
3
+ *
4
+ * The error may include a `context` property with additional debugging information
5
+ * such as the `chatId` and the original `descriptor` of the awaited action.
6
+ */
7
+ export class ChatAsyncToolCheckerUnavailable extends Error {
8
+ /**
9
+ * Optional context describing the awaited action and chat details.
10
+ */
11
+ context;
12
+ /**
13
+ * Creates a new {@link ChatAsyncToolCheckerUnavailable} instance.
14
+ *
15
+ * @param context Additional context useful for debugging, e.g. `{ chatId: string, descriptor: unknown }`.
16
+ */
17
+ constructor(context) {
18
+ super("Chat awaitAction requires an async tool checker to be configured.");
19
+ this.name = "ChatAsyncToolCheckerUnavailable";
20
+ if (context !== undefined) {
21
+ Object.defineProperty(this, "context", {
22
+ value: context,
23
+ enumerable: true,
24
+ });
25
+ }
26
+ }
27
+ }
28
+ //# sourceMappingURL=ChatAsyncToolCheckerUnavailable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatAsyncToolCheckerUnavailable.js","sourceRoot":"","sources":["../../../../src/chat/errors/ChatAsyncToolCheckerUnavailable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IACtD;;OAEG;IACa,OAAO,CAAW;IAElC;;;;OAIG;IACH,YAAmB,OAAiB;QAChC,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAC;QAC9C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;gBACnC,KAAK,EAAE,OAAO;gBACd,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export { ChatAsyncToolCheckerUnavailable } from "./ChatAsyncToolCheckerUnavailable.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ChatAsyncToolCheckerUnavailable } from "./ChatAsyncToolCheckerUnavailable.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/chat/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { Chat } from "./Chat.js";
2
+ export type { ChatOptions } from "../interfaces/index.js";
3
+ export * from "./errors/index.js";
4
+ export type { ChatContextInput } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,cAAc,mBAAmB,CAAC;AAClC,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Chat } from "./Chat.js";
2
+ export * from "./errors/index.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ChatContextSnapshot } from "../interfaces/index.js";
2
+ /**
3
+ * Context replacement payload accepted by the chat facade.
4
+ *
5
+ * This type re-exports the existing {@link ChatContextSnapshot} for improved discoverability
6
+ * when working within the chat module.
7
+ */
8
+ export type ChatContextInput = ChatContextSnapshot;
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/chat/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/chat/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { generateUUID } from "./uuid.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/chat/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { generateUUID } from "./uuid.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/chat/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generates a random UUID (v4) compatible with both browser and Node.js environments.
3
+ *
4
+ * This helper uses the Web Crypto API's `crypto.randomUUID()` when available
5
+ * (modern browsers and Node.js 19+) and falls back to the `uuid` library for
6
+ * compatibility with older environments.
7
+ *
8
+ * @returns A randomly generated UUID string in the format
9
+ * `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
10
+ */
11
+ export declare function generateUUID(): string;
12
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../../../src/chat/utils/uuid.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAOrC"}
@@ -0,0 +1,19 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ /**
3
+ * Generates a random UUID (v4) compatible with both browser and Node.js environments.
4
+ *
5
+ * This helper uses the Web Crypto API's `crypto.randomUUID()` when available
6
+ * (modern browsers and Node.js 19+) and falls back to the `uuid` library for
7
+ * compatibility with older environments.
8
+ *
9
+ * @returns A randomly generated UUID string in the format
10
+ * `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
11
+ */
12
+ export function generateUUID() {
13
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
14
+ return crypto.randomUUID();
15
+ }
16
+ // Fallback to uuid library for older environments
17
+ return uuidv4();
18
+ }
19
+ //# sourceMappingURL=uuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../../src/chat/utils/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY;IACxB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC3E,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC/B,CAAC;IAED,kDAAkD;IAClD,OAAO,MAAM,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { MessageHistoryType, ToolAutorouterRequest } from "@illalabs/interfaces";
2
+ import type { ChatContextSnapshot, ContextManagerOptions, ICache, IContextManager } from "../interfaces/index.js";
3
+ /**
4
+ * Manages chat context using an injected cache implementation.
5
+ */
6
+ export declare class ContextManager implements IContextManager {
7
+ private readonly cache;
8
+ private readonly cacheEntryOptions?;
9
+ private readonly defaultSnapshot;
10
+ private readonly prefix;
11
+ constructor(cache: ICache, options?: ContextManagerOptions);
12
+ /** @inheritdoc */
13
+ getContext(chatId: string): Promise<ChatContextSnapshot>;
14
+ /** @inheritdoc */
15
+ setMessages(chatId: string, messages: MessageHistoryType): Promise<void>;
16
+ /** @inheritdoc */
17
+ appendMessages(chatId: string, messages: MessageHistoryType): Promise<void>;
18
+ /** @inheritdoc */
19
+ setToolsConfig(chatId: string, toolsConfig: ToolAutorouterRequest): Promise<void>;
20
+ /** @inheritdoc */
21
+ deleteContext(chatId: string): Promise<void>;
22
+ private readRecord;
23
+ private writeRecord;
24
+ private buildCacheKey;
25
+ }
26
+ //# sourceMappingURL=ContextManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextManager.d.ts","sourceRoot":"","sources":["../../../src/context/ContextManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,KAAK,EAER,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,EACN,eAAe,EAClB,MAAM,wBAAwB,CAAC;AAuBhC;;GAEG;AACH,qBAAa,cAAe,YAAW,eAAe;IAQ9C,OAAO,CAAC,QAAQ,CAAC,KAAK;IAP1B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAoB;IAEvD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgB;IAEhD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAGX,KAAK,EAAE,MAAM,EAC9B,OAAO,GAAE,qBAA0B;IAUvC,kBAAkB;IACL,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IASrE,kBAAkB;IACL,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrF,kBAAkB;IACL,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxF,kBAAkB;IACL,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAU9F,kBAAkB;IACL,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAI3C,UAAU;YAgBV,WAAW;IAIzB,OAAO,CAAC,aAAa;CAGxB"}
@@ -0,0 +1,93 @@
1
+ const DEFAULT_PREFIX = "illa:sdk:ctx";
2
+ const DEFAULT_TOOLS_CONFIG = {};
3
+ const cloneMessageContent = (content) => {
4
+ if (typeof content === "string") {
5
+ return content;
6
+ }
7
+ return content.map((part) => ({ ...part }));
8
+ };
9
+ const cloneMessages = (messages) => messages.map((message) => ({
10
+ ...message,
11
+ content: cloneMessageContent(message.content),
12
+ }));
13
+ const cloneToolsConfig = (config) => structuredClone(config);
14
+ /**
15
+ * Manages chat context using an injected cache implementation.
16
+ */
17
+ export class ContextManager {
18
+ cache;
19
+ cacheEntryOptions;
20
+ defaultSnapshot;
21
+ prefix;
22
+ constructor(cache, options = {}) {
23
+ this.cache = cache;
24
+ this.prefix = options.cacheKeyPrefix ?? DEFAULT_PREFIX;
25
+ this.cacheEntryOptions = options.cacheEntryOptions;
26
+ this.defaultSnapshot = {
27
+ messages: [],
28
+ toolsConfig: cloneToolsConfig(options.defaultToolsConfig ?? DEFAULT_TOOLS_CONFIG),
29
+ };
30
+ }
31
+ /** @inheritdoc */
32
+ async getContext(chatId) {
33
+ const record = await this.readRecord(chatId);
34
+ return {
35
+ messages: cloneMessages(record.messages),
36
+ toolsConfig: cloneToolsConfig(record.toolsConfig),
37
+ };
38
+ }
39
+ /** @inheritdoc */
40
+ async setMessages(chatId, messages) {
41
+ const record = await this.readRecord(chatId);
42
+ const updated = {
43
+ messages: cloneMessages(messages),
44
+ toolsConfig: record.toolsConfig,
45
+ };
46
+ await this.writeRecord(chatId, updated);
47
+ }
48
+ /** @inheritdoc */
49
+ async appendMessages(chatId, messages) {
50
+ if (messages.length === 0) {
51
+ return;
52
+ }
53
+ const record = await this.readRecord(chatId);
54
+ const appended = cloneMessages(record.messages).concat(cloneMessages(messages));
55
+ await this.writeRecord(chatId, {
56
+ messages: appended,
57
+ toolsConfig: record.toolsConfig,
58
+ });
59
+ }
60
+ /** @inheritdoc */
61
+ async setToolsConfig(chatId, toolsConfig) {
62
+ const record = await this.readRecord(chatId);
63
+ const updated = {
64
+ messages: record.messages,
65
+ toolsConfig: cloneToolsConfig(toolsConfig),
66
+ };
67
+ await this.writeRecord(chatId, updated);
68
+ }
69
+ /** @inheritdoc */
70
+ async deleteContext(chatId) {
71
+ await this.cache.del(this.buildCacheKey(chatId));
72
+ }
73
+ async readRecord(chatId) {
74
+ const stored = await this.cache.get(this.buildCacheKey(chatId));
75
+ if (stored === undefined) {
76
+ return {
77
+ messages: cloneMessages(this.defaultSnapshot.messages),
78
+ toolsConfig: cloneToolsConfig(this.defaultSnapshot.toolsConfig),
79
+ };
80
+ }
81
+ return {
82
+ messages: cloneMessages(stored.messages),
83
+ toolsConfig: cloneToolsConfig(stored.toolsConfig),
84
+ };
85
+ }
86
+ async writeRecord(chatId, record) {
87
+ await this.cache.set(this.buildCacheKey(chatId), record, this.cacheEntryOptions);
88
+ }
89
+ buildCacheKey(chatId) {
90
+ return `${this.prefix}:${chatId}`;
91
+ }
92
+ }
93
+ //# sourceMappingURL=ContextManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextManager.js","sourceRoot":"","sources":["../../../src/context/ContextManager.ts"],"names":[],"mappings":"AAWA,MAAM,cAAc,GAAG,cAAuB,CAAC;AAC/C,MAAM,oBAAoB,GAA0B,EAAE,CAAC;AAEvD,MAAM,mBAAmB,GAAG,CAAC,OAAuB,EAAkB,EAAE;IACpE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAmB,CAAC;AAClE,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,QAA4B,EAAsB,EAAE,CACvE,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,OAAO;IACV,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;CAChD,CAAC,CAAuB,CAAC;AAE9B,MAAM,gBAAgB,GAAG,CAAC,MAA6B,EAAyB,EAAE,CAC9E,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,OAAO,cAAc;IAQF;IAPJ,iBAAiB,CAAqB;IAEtC,eAAe,CAAgB;IAE/B,MAAM,CAAS;IAEhC,YACqB,KAAa,EAC9B,UAAiC,EAAE;QADlB,UAAK,GAAL,KAAK,CAAQ;QAG9B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,IAAI,cAAc,CAAC;QACvD,IAAI,CAAC,iBAAiB,GA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O,aAAa,CAAC,MAAc;QAChC,OAAO,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;IACtC,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export { ContextManager } from "./ContextManager.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ContextManager } from "./ContextManager.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { MessageHistoryType, ToolAutorouterRequest } from "@illalabs/interfaces";
2
+ /**
3
+ * Internal record structure stored in cache.
4
+ */
5
+ export type ContextRecord = {
6
+ readonly messages: MessageHistoryType;
7
+ readonly toolsConfig: ToolAutorouterRequest;
8
+ };
9
+ /**
10
+ * Single message entry from the message history.
11
+ */
12
+ export type MessageEntry = MessageHistoryType[number];
13
+ /**
14
+ * Content of a message, which can be a string or an array of content parts.
15
+ */
16
+ export type MessageContent = MessageEntry["content"];
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/context/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEtF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/context/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Public API exports for the Illa SDK package
3
+ *
4
+ * This file explicitly defines the public interface of the SDK.
5
+ * Only exports listed here are considered part of the public API.
6
+ */
7
+ export { InMemoryCache } from "./caching/index.js";
8
+ export { Chat } from "./chat/index.js";
9
+ export { ContextManager } from "./context/index.js";
10
+ export { AsyncToolChecker } from "./asyncToolChecker/index.js";
11
+ export type { CacheEntryOptions, ChatContextSnapshot, ContextManagerOptions, ICache, IContextManager, } from "./interfaces/index.js";
12
+ export * from "./prompt/index.js";
13
+ export * from "./providers/index.js";
14
+ //# sourceMappingURL=external.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/external.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EACR,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,EACN,eAAe,GAClB,MAAM,uBAAuB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}