@smarter.sh/api 0.0.0-stage → 1.0.2-alpha.1

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 (251) hide show
  1. package/LICENSE.txt +671 -0
  2. package/README.md +193 -2
  3. package/dist/client.d.ts +146 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +178 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/core/config.d.ts +148 -0
  8. package/dist/core/config.d.ts.map +1 -0
  9. package/dist/core/config.js +212 -0
  10. package/dist/core/config.js.map +1 -0
  11. package/dist/core/errors.d.ts +189 -0
  12. package/dist/core/errors.d.ts.map +1 -0
  13. package/dist/core/errors.js +187 -0
  14. package/dist/core/errors.js.map +1 -0
  15. package/dist/core/http.d.ts +207 -0
  16. package/dist/core/http.d.ts.map +1 -0
  17. package/dist/core/http.js +456 -0
  18. package/dist/core/http.js.map +1 -0
  19. package/dist/core/log.d.ts +62 -0
  20. package/dist/core/log.d.ts.map +1 -0
  21. package/dist/core/log.js +68 -0
  22. package/dist/core/log.js.map +1 -0
  23. package/dist/core/sse.d.ts +38 -0
  24. package/dist/core/sse.d.ts.map +1 -0
  25. package/dist/core/sse.js +79 -0
  26. package/dist/core/sse.js.map +1 -0
  27. package/dist/core/typing.d.ts +21 -0
  28. package/dist/core/typing.d.ts.map +1 -0
  29. package/dist/core/typing.js +13 -0
  30. package/dist/core/typing.js.map +1 -0
  31. package/dist/index.d.ts +51 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +51 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/models/account.d.ts +112 -0
  36. package/dist/models/account.d.ts.map +1 -0
  37. package/dist/models/account.js +55 -0
  38. package/dist/models/account.js.map +1 -0
  39. package/dist/models/base.d.ts +99 -0
  40. package/dist/models/base.d.ts.map +1 -0
  41. package/dist/models/base.js +111 -0
  42. package/dist/models/base.js.map +1 -0
  43. package/dist/models/chat.d.ts +2243 -0
  44. package/dist/models/chat.d.ts.map +1 -0
  45. package/dist/models/chat.js +451 -0
  46. package/dist/models/chat.js.map +1 -0
  47. package/dist/models/guardrail.d.ts +109 -0
  48. package/dist/models/guardrail.d.ts.map +1 -0
  49. package/dist/models/guardrail.js +68 -0
  50. package/dist/models/guardrail.js.map +1 -0
  51. package/dist/models/journal.d.ts +159 -0
  52. package/dist/models/journal.d.ts.map +1 -0
  53. package/dist/models/journal.js +115 -0
  54. package/dist/models/journal.js.map +1 -0
  55. package/dist/models/llmclient.d.ts +183 -0
  56. package/dist/models/llmclient.d.ts.map +1 -0
  57. package/dist/models/llmclient.js +105 -0
  58. package/dist/models/llmclient.js.map +1 -0
  59. package/dist/models/llmhost.d.ts +121 -0
  60. package/dist/models/llmhost.d.ts.map +1 -0
  61. package/dist/models/llmhost.js +79 -0
  62. package/dist/models/llmhost.js.map +1 -0
  63. package/dist/models/manifest.d.ts +211 -0
  64. package/dist/models/manifest.d.ts.map +1 -0
  65. package/dist/models/manifest.js +290 -0
  66. package/dist/models/manifest.js.map +1 -0
  67. package/dist/models/mcpclient.d.ts +99 -0
  68. package/dist/models/mcpclient.d.ts.map +1 -0
  69. package/dist/models/mcpclient.js +65 -0
  70. package/dist/models/mcpclient.js.map +1 -0
  71. package/dist/models/misc.d.ts +232 -0
  72. package/dist/models/misc.d.ts.map +1 -0
  73. package/dist/models/misc.js +110 -0
  74. package/dist/models/misc.js.map +1 -0
  75. package/dist/models/platform.d.ts +88 -0
  76. package/dist/models/platform.d.ts.map +1 -0
  77. package/dist/models/platform.js +35 -0
  78. package/dist/models/platform.js.map +1 -0
  79. package/dist/models/plugin.d.ts +36 -0
  80. package/dist/models/plugin.d.ts.map +1 -0
  81. package/dist/models/plugin.js +16 -0
  82. package/dist/models/plugin.js.map +1 -0
  83. package/dist/models/react.d.ts +104 -0
  84. package/dist/models/react.d.ts.map +1 -0
  85. package/dist/models/react.js +136 -0
  86. package/dist/models/react.js.map +1 -0
  87. package/dist/models/sam/account.d.ts +155 -0
  88. package/dist/models/sam/account.d.ts.map +1 -0
  89. package/dist/models/sam/account.js +7 -0
  90. package/dist/models/sam/account.js.map +1 -0
  91. package/dist/models/sam/apiconnection.d.ts +147 -0
  92. package/dist/models/sam/apiconnection.d.ts.map +1 -0
  93. package/dist/models/sam/apiconnection.js +7 -0
  94. package/dist/models/sam/apiconnection.js.map +1 -0
  95. package/dist/models/sam/apiplugin.d.ts +278 -0
  96. package/dist/models/sam/apiplugin.d.ts.map +1 -0
  97. package/dist/models/sam/apiplugin.js +7 -0
  98. package/dist/models/sam/apiplugin.js.map +1 -0
  99. package/dist/models/sam/budget.d.ts +219 -0
  100. package/dist/models/sam/budget.d.ts.map +1 -0
  101. package/dist/models/sam/budget.js +7 -0
  102. package/dist/models/sam/budget.js.map +1 -0
  103. package/dist/models/sam/customdomain.d.ts +139 -0
  104. package/dist/models/sam/customdomain.d.ts.map +1 -0
  105. package/dist/models/sam/customdomain.js +7 -0
  106. package/dist/models/sam/customdomain.js.map +1 -0
  107. package/dist/models/sam/guardrail.d.ts +222 -0
  108. package/dist/models/sam/guardrail.d.ts.map +1 -0
  109. package/dist/models/sam/guardrail.js +7 -0
  110. package/dist/models/sam/guardrail.js.map +1 -0
  111. package/dist/models/sam/imagesearchplugin.d.ts +235 -0
  112. package/dist/models/sam/imagesearchplugin.d.ts.map +1 -0
  113. package/dist/models/sam/imagesearchplugin.js +7 -0
  114. package/dist/models/sam/imagesearchplugin.js.map +1 -0
  115. package/dist/models/sam/index.d.ts +104 -0
  116. package/dist/models/sam/index.d.ts.map +1 -0
  117. package/dist/models/sam/index.js +50 -0
  118. package/dist/models/sam/index.js.map +1 -0
  119. package/dist/models/sam/llmclient.d.ts +490 -0
  120. package/dist/models/sam/llmclient.d.ts.map +1 -0
  121. package/dist/models/sam/llmclient.js +7 -0
  122. package/dist/models/sam/llmclient.js.map +1 -0
  123. package/dist/models/sam/llmhost.d.ts +429 -0
  124. package/dist/models/sam/llmhost.d.ts.map +1 -0
  125. package/dist/models/sam/llmhost.js +7 -0
  126. package/dist/models/sam/llmhost.js.map +1 -0
  127. package/dist/models/sam/llmhostcompute.d.ts +221 -0
  128. package/dist/models/sam/llmhostcompute.d.ts.map +1 -0
  129. package/dist/models/sam/llmhostcompute.js +7 -0
  130. package/dist/models/sam/llmhostcompute.js.map +1 -0
  131. package/dist/models/sam/mcpclient.d.ts +195 -0
  132. package/dist/models/sam/mcpclient.d.ts.map +1 -0
  133. package/dist/models/sam/mcpclient.js +7 -0
  134. package/dist/models/sam/mcpclient.js.map +1 -0
  135. package/dist/models/sam/orchestrator.d.ts +163 -0
  136. package/dist/models/sam/orchestrator.d.ts.map +1 -0
  137. package/dist/models/sam/orchestrator.js +7 -0
  138. package/dist/models/sam/orchestrator.js.map +1 -0
  139. package/dist/models/sam/plugin.d.ts +163 -0
  140. package/dist/models/sam/plugin.d.ts.map +1 -0
  141. package/dist/models/sam/plugin.js +7 -0
  142. package/dist/models/sam/plugin.js.map +1 -0
  143. package/dist/models/sam/prompt.d.ts +116 -0
  144. package/dist/models/sam/prompt.d.ts.map +1 -0
  145. package/dist/models/sam/prompt.js +7 -0
  146. package/dist/models/sam/prompt.js.map +1 -0
  147. package/dist/models/sam/provider.d.ts +195 -0
  148. package/dist/models/sam/provider.d.ts.map +1 -0
  149. package/dist/models/sam/provider.js +7 -0
  150. package/dist/models/sam/provider.js.map +1 -0
  151. package/dist/models/sam/proxy.d.ts +163 -0
  152. package/dist/models/sam/proxy.d.ts.map +1 -0
  153. package/dist/models/sam/proxy.js +7 -0
  154. package/dist/models/sam/proxy.js.map +1 -0
  155. package/dist/models/sam/schemas.d.ts +8 -0
  156. package/dist/models/sam/schemas.d.ts.map +1 -0
  157. package/dist/models/sam/schemas.js +6059 -0
  158. package/dist/models/sam/schemas.js.map +1 -0
  159. package/dist/models/sam/secret.d.ts +123 -0
  160. package/dist/models/sam/secret.d.ts.map +1 -0
  161. package/dist/models/sam/secret.js +7 -0
  162. package/dist/models/sam/secret.js.map +1 -0
  163. package/dist/models/sam/skillplugin.d.ts +181 -0
  164. package/dist/models/sam/skillplugin.d.ts.map +1 -0
  165. package/dist/models/sam/skillplugin.js +7 -0
  166. package/dist/models/sam/skillplugin.js.map +1 -0
  167. package/dist/models/sam/smarterauthtoken.d.ts +115 -0
  168. package/dist/models/sam/smarterauthtoken.d.ts.map +1 -0
  169. package/dist/models/sam/smarterauthtoken.js +7 -0
  170. package/dist/models/sam/smarterauthtoken.js.map +1 -0
  171. package/dist/models/sam/sqlconnection.d.ts +187 -0
  172. package/dist/models/sam/sqlconnection.d.ts.map +1 -0
  173. package/dist/models/sam/sqlconnection.js +7 -0
  174. package/dist/models/sam/sqlconnection.js.map +1 -0
  175. package/dist/models/sam/sqlplugin.d.ts +232 -0
  176. package/dist/models/sam/sqlplugin.d.ts.map +1 -0
  177. package/dist/models/sam/sqlplugin.js +7 -0
  178. package/dist/models/sam/sqlplugin.js.map +1 -0
  179. package/dist/models/sam/user.d.ts +135 -0
  180. package/dist/models/sam/user.d.ts.map +1 -0
  181. package/dist/models/sam/user.js +7 -0
  182. package/dist/models/sam/user.js.map +1 -0
  183. package/dist/models/sam/vectorsearch.d.ts +150 -0
  184. package/dist/models/sam/vectorsearch.d.ts.map +1 -0
  185. package/dist/models/sam/vectorsearch.js +7 -0
  186. package/dist/models/sam/vectorsearch.js.map +1 -0
  187. package/dist/models/sam/vectorstore.d.ts +291 -0
  188. package/dist/models/sam/vectorstore.d.ts.map +1 -0
  189. package/dist/models/sam/vectorstore.js +7 -0
  190. package/dist/models/sam/vectorstore.js.map +1 -0
  191. package/dist/models/sam/websearchplugin.d.ts +229 -0
  192. package/dist/models/sam/websearchplugin.d.ts.map +1 -0
  193. package/dist/models/sam/websearchplugin.js +7 -0
  194. package/dist/models/sam/websearchplugin.js.map +1 -0
  195. package/dist/models/vectorstore.d.ts +165 -0
  196. package/dist/models/vectorstore.d.ts.map +1 -0
  197. package/dist/models/vectorstore.js +90 -0
  198. package/dist/models/vectorstore.js.map +1 -0
  199. package/dist/resources/accounts.d.ts +107 -0
  200. package/dist/resources/accounts.d.ts.map +1 -0
  201. package/dist/resources/accounts.js +84 -0
  202. package/dist/resources/accounts.js.map +1 -0
  203. package/dist/resources/base.d.ts +127 -0
  204. package/dist/resources/base.d.ts.map +1 -0
  205. package/dist/resources/base.js +139 -0
  206. package/dist/resources/base.js.map +1 -0
  207. package/dist/resources/catalog.d.ts +209 -0
  208. package/dist/resources/catalog.d.ts.map +1 -0
  209. package/dist/resources/catalog.js +124 -0
  210. package/dist/resources/catalog.js.map +1 -0
  211. package/dist/resources/guardrails.d.ts +82 -0
  212. package/dist/resources/guardrails.d.ts.map +1 -0
  213. package/dist/resources/guardrails.js +46 -0
  214. package/dist/resources/guardrails.js.map +1 -0
  215. package/dist/resources/history.d.ts +97 -0
  216. package/dist/resources/history.d.ts.map +1 -0
  217. package/dist/resources/history.js +109 -0
  218. package/dist/resources/history.js.map +1 -0
  219. package/dist/resources/llmclients.d.ts +348 -0
  220. package/dist/resources/llmclients.d.ts.map +1 -0
  221. package/dist/resources/llmclients.js +367 -0
  222. package/dist/resources/llmclients.js.map +1 -0
  223. package/dist/resources/llmhosts.d.ts +146 -0
  224. package/dist/resources/llmhosts.d.ts.map +1 -0
  225. package/dist/resources/llmhosts.js +128 -0
  226. package/dist/resources/llmhosts.js.map +1 -0
  227. package/dist/resources/manifests.d.ts +153 -0
  228. package/dist/resources/manifests.d.ts.map +1 -0
  229. package/dist/resources/manifests.js +203 -0
  230. package/dist/resources/manifests.js.map +1 -0
  231. package/dist/resources/mcpclients.d.ts +90 -0
  232. package/dist/resources/mcpclients.d.ts.map +1 -0
  233. package/dist/resources/mcpclients.js +57 -0
  234. package/dist/resources/mcpclients.js.map +1 -0
  235. package/dist/resources/providers.d.ts +33 -0
  236. package/dist/resources/providers.d.ts.map +1 -0
  237. package/dist/resources/providers.js +39 -0
  238. package/dist/resources/providers.js.map +1 -0
  239. package/dist/resources/proxies.d.ts +61 -0
  240. package/dist/resources/proxies.d.ts.map +1 -0
  241. package/dist/resources/proxies.js +57 -0
  242. package/dist/resources/proxies.js.map +1 -0
  243. package/dist/resources/vectorstores.d.ts +194 -0
  244. package/dist/resources/vectorstores.d.ts.map +1 -0
  245. package/dist/resources/vectorstores.js +200 -0
  246. package/dist/resources/vectorstores.js.map +1 -0
  247. package/dist/version.d.ts +3 -0
  248. package/dist/version.d.ts.map +1 -0
  249. package/dist/version.js +5 -0
  250. package/dist/version.js.map +1 -0
  251. package/package.json +81 -4
@@ -0,0 +1,367 @@
1
+ /**
2
+ * LLMClients: read them, prompt them, stream a prompt's progress, and hold a multi-turn chat.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { Smarter } from "@smarter.sh/api";
7
+ *
8
+ * const client = new Smarter();
9
+ * const llmclient = await client.llmClients.find("calculator");
10
+ *
11
+ * // one prompt
12
+ * const response = await client.llmClients.prompt(llmclient.id, "What is 17 times 23?");
13
+ * console.log(response.text);
14
+ *
15
+ * // a conversation, which keeps its session and thread
16
+ * const chat = await client.llmClients.chat(llmclient.id);
17
+ * console.log((await chat.send("What is 2 to the 10th power?")).text);
18
+ * console.log((await chat.send("And divided by 4?")).text);
19
+ *
20
+ * // the prompt's progress, e.g. its tool calls, while it runs
21
+ * const stream = client.llmClients.stream(llmclient.id, "What is sin(pi / 2)?");
22
+ * for await (const event of stream) console.log(event.message);
23
+ * console.log(stream.response.text);
24
+ * ```
25
+ */
26
+ import { z } from "zod";
27
+ import { SmarterError, SmarterPromptError } from "../core/errors.js";
28
+ import { LLM_MESSAGE_ROLES, PromptChatApiConfigResponse, PromptChatApiMessage, PromptChatApiProgressEvent, PromptChatApiProgressResult, PromptChatApiPromptResponse, withPromptText, } from "../models/chat.js";
29
+ import { LLMClient, LLMClientApiKey, LLMClientCustomDomain, LLMClientExtension, LLMClientPlugin, } from "../models/llmclient.js";
30
+ import { resourceId, SmarterKindResource } from "./base.js";
31
+ /**
32
+ * A prompt as a list of messages.
33
+ *
34
+ * @param prompt - A user message's text, or a list of messages.
35
+ * @returns The messages.
36
+ */
37
+ export function toMessages(prompt) {
38
+ if (typeof prompt === "string")
39
+ return [{ role: "user", content: prompt }];
40
+ return prompt.map((message) => PromptChatApiMessage.parse(message));
41
+ }
42
+ /**
43
+ * Messages as the prompt api's request sends them: only those that the LLM accepts.
44
+ *
45
+ * Smarter's own `smarter` and `smarter_error` messages are left out, as Smarter Chat leaves them out.
46
+ * Every message keeps its `content`, even when it is null, e.g. an assistant's tool calls: the
47
+ * platform requires the key.
48
+ *
49
+ * @param messages - A chat thread.
50
+ * @returns The messages, as JSON.
51
+ */
52
+ export function requestMessages(messages) {
53
+ const result = [];
54
+ for (const message of messages) {
55
+ if (!LLM_MESSAGE_ROLES.includes(message.role))
56
+ continue;
57
+ const data = {};
58
+ for (const [key, value] of Object.entries(message)) {
59
+ if (value !== null && value !== undefined)
60
+ data[key] = value;
61
+ }
62
+ data["content"] ??= null;
63
+ result.push(data);
64
+ }
65
+ return result;
66
+ }
67
+ /**
68
+ * A prompt whose progress is streamed as Server-Sent Events.
69
+ *
70
+ * Iterate it with `for await` for the {@link PromptChatApiProgressEvent} events, e.g. "Calling tool
71
+ * calculator". The request is sent when the iteration starts, and its connection is closed when the
72
+ * iteration ends, also when the loop exits early. When the stream has been read to its end,
73
+ * {@link PromptStream.response} is the prompt's response, exactly as a non-streaming prompt returns it.
74
+ */
75
+ export class PromptStream {
76
+ #events;
77
+ #onResult;
78
+ #result;
79
+ #started = false;
80
+ /**
81
+ * @param events - Starts the request, and iterates its Server-Sent Events.
82
+ * @param onResult - Called with the final `result` event, before the iteration ends.
83
+ */
84
+ constructor(events, onResult) {
85
+ this.#events = events;
86
+ this.#onResult = onResult;
87
+ }
88
+ async *[Symbol.asyncIterator]() {
89
+ if (this.#started)
90
+ throw new SmarterError("A prompt stream can be read only once.");
91
+ this.#started = true;
92
+ for await (const event of this.#events()) {
93
+ if (event.event === "progress") {
94
+ yield PromptChatApiProgressEvent.parse(JSON.parse(event.data));
95
+ }
96
+ else if (event.event === "result") {
97
+ this.#result = PromptChatApiProgressResult.parse(JSON.parse(event.data));
98
+ this.#onResult?.(this.#result);
99
+ }
100
+ }
101
+ }
102
+ /**
103
+ * Read the stream to its end, discarding the progress events.
104
+ *
105
+ * @returns The prompt's response.
106
+ */
107
+ async untilDone() {
108
+ const events = this[Symbol.asyncIterator]();
109
+ while (!(await events.next()).done) {
110
+ // the progress events are discarded.
111
+ }
112
+ return this.response;
113
+ }
114
+ /** The final `result` event, once the stream has been read: the prompt's status and response. */
115
+ get result() {
116
+ return this.#result;
117
+ }
118
+ /**
119
+ * The prompt's response, once the stream has been read.
120
+ *
121
+ * @throws {@link SmarterPromptError} If the prompt failed.
122
+ * @throws {@link SmarterError} If the stream has not been read, or ended without a result.
123
+ */
124
+ get response() {
125
+ if (this.#result === undefined) {
126
+ throw new SmarterError("The stream has not been read to its end, or it ended without a result event.");
127
+ }
128
+ const response = this.#result.response;
129
+ if (response.error)
130
+ throw new SmarterPromptError(response.error.description, response);
131
+ return withPromptText(response);
132
+ }
133
+ }
134
+ /**
135
+ * A multi-turn conversation with an LLMClient.
136
+ *
137
+ * It keeps the chat session's key, so that the platform keeps the session's history, and the
138
+ * thread, which it sends with each prompt as Smarter Chat does. Create one with {@link LLMClients.chat}.
139
+ */
140
+ export class ChatSession {
141
+ /** The LLMClient's id or hashed id. */
142
+ llmclientId;
143
+ /** The chat session's configuration. */
144
+ config;
145
+ /** The chat thread. */
146
+ messages;
147
+ #llmclients;
148
+ /**
149
+ * @param llmclients - The LLMClients resource.
150
+ * @param llmclientId - The LLMClient's id or hashed id.
151
+ * @param config - The chat session's configuration.
152
+ */
153
+ constructor(llmclients, llmclientId, config) {
154
+ this.#llmclients = llmclients;
155
+ this.llmclientId = llmclientId;
156
+ this.config = config;
157
+ this.messages =
158
+ config.history.chat_history.length > 0 ? [...config.history.chat_history] : ChatSession.#introduction(config);
159
+ }
160
+ /** A new thread: the LLMClient's system prompt and welcome message, as Smarter Chat starts one. */
161
+ static #introduction(config) {
162
+ const messages = [];
163
+ if (config.llmclient.default_system_role)
164
+ messages.push({ role: "system", content: config.llmclient.default_system_role });
165
+ if (config.llmclient.app_welcome_message)
166
+ messages.push({ role: "assistant", content: config.llmclient.app_welcome_message });
167
+ return messages;
168
+ }
169
+ /** The chat session's key, with which the session can be resumed: see {@link LLMClients.chat}. */
170
+ get sessionKey() {
171
+ return this.config.session_key;
172
+ }
173
+ /**
174
+ * Send a message, and add it and the prompt's messages to the thread.
175
+ *
176
+ * @param content - A user message's text, or a message.
177
+ * @param options - Per-request options.
178
+ * @returns The prompt's response. `text` is the LLM's reply.
179
+ */
180
+ async send(content, options) {
181
+ const thread = [...this.messages, ...toMessages(typeof content === "string" ? content : [content])];
182
+ const response = await this.#llmclients.prompt(this.llmclientId, thread, {
183
+ ...options,
184
+ sessionKey: this.sessionKey,
185
+ });
186
+ this.messages = [...thread, ...response.data.messages];
187
+ return response;
188
+ }
189
+ /**
190
+ * Send a message, and stream the prompt's progress. The thread is updated when the stream has been read to its end.
191
+ *
192
+ * @param content - A user message's text, or a message.
193
+ * @param options - Per-request options.
194
+ * @returns The stream.
195
+ */
196
+ stream(content, options) {
197
+ const thread = [...this.messages, ...toMessages(typeof content === "string" ? content : [content])];
198
+ const events = this.#llmclients.events(this.llmclientId, thread, { ...options, sessionKey: this.sessionKey });
199
+ return new ChatStream(events, (messages) => {
200
+ this.messages = [...thread, ...messages];
201
+ });
202
+ }
203
+ }
204
+ /** A {@link PromptStream} of a {@link ChatSession}, which adds the prompt's messages to the session's thread. */
205
+ export class ChatStream extends PromptStream {
206
+ /**
207
+ * @param events - Starts the request, and iterates its Server-Sent Events.
208
+ * @param onMessages - Called with a successful prompt's messages.
209
+ */
210
+ constructor(events, onMessages) {
211
+ super(events, (result) => {
212
+ const parsed = PromptChatApiPromptResponse.safeParse(result.response);
213
+ if (parsed.success && !parsed.data.error)
214
+ onMessages(parsed.data.data.messages);
215
+ });
216
+ }
217
+ }
218
+ /** LLMClients: `/api/v1/llm-clients/`, and the manifest api's `LLMClient` kind. */
219
+ export class LLMClients extends SmarterKindResource {
220
+ kind = "LLMClient";
221
+ path = "llm-clients/";
222
+ model = LLMClient;
223
+ /**
224
+ * An LLMClient's chat configuration, and a chat session.
225
+ *
226
+ * By default, the configuration has what a chat needs: the LLMClient, the session's key and chat
227
+ * history, a short `meta_data`, and the counts of the LLMClient's plugins and extensions. `verbose`
228
+ * adds the diagnostic parts: the lists of plugins and extensions, the session's tool calls and the
229
+ * complete `meta_data`.
230
+ *
231
+ * @param id - The LLMClient's id or hashed id.
232
+ * @param options - `sessionKey`: an existing session's key, to resume it with its history, or none for a new session. `verbose`: true to add the diagnostic parts (`?verbose=true`).
233
+ * @returns The configuration, whose `session_key` identifies the session.
234
+ * @example
235
+ * ```ts
236
+ * const config = await client.llmClients.config("calculator", { verbose: true });
237
+ * console.log(config.plugins.plugins.map((plugin) => plugin.plugin_meta.name));
238
+ * ```
239
+ */
240
+ async config(id, options) {
241
+ const response = await this.http.request("POST", `${this.path}${resourceId(id)}/config/`, PromptChatApiConfigResponse, {
242
+ ...options,
243
+ params: { verbose: options?.verbose ? true : undefined },
244
+ json: { session_key: options?.sessionKey ?? null },
245
+ });
246
+ return response.data;
247
+ }
248
+ /**
249
+ * Prompt an LLMClient.
250
+ *
251
+ * The platform runs the LLMClient's whole prompt: it selects plugins, calls the LLM, runs the tools
252
+ * that the LLM calls, and applies the Guardrails. Prompts are billed by the LLM provider.
253
+ *
254
+ * @param id - The LLMClient's id or hashed id.
255
+ * @param prompt - The text of one user message, or the chat thread as a list of messages.
256
+ * @param options - `sessionKey`, the chat session's key, and per-request options.
257
+ * @returns The response. `text` is the LLM's final reply, and `data.messages` every message that
258
+ * the prompt added, including Smarter's own.
259
+ * @throws {@link APIStatusError} If the prompt failed, e.g. the LLM provider returned an error. The
260
+ * error's `body` is the error response.
261
+ */
262
+ async prompt(id, prompt, options) {
263
+ const response = await this.http.request("POST", `${this.path}${resourceId(id)}/prompt/`, PromptChatApiPromptResponse, {
264
+ ...options,
265
+ json: { session_key: options?.sessionKey ?? null, messages: requestMessages(toMessages(prompt)) },
266
+ });
267
+ return withPromptText(response);
268
+ }
269
+ /**
270
+ * Prompt an LLMClient, and stream its progress: the LLM requests, tool calls and plugin calls.
271
+ *
272
+ * @param id - The LLMClient's id or hashed id.
273
+ * @param prompt - The text of one user message, or the chat thread as a list of messages.
274
+ * @param options - `sessionKey`, and per-request options. The timeout applies to each event.
275
+ * @returns The stream. Iterate it with `for await` for the progress events.
276
+ */
277
+ stream(id, prompt, options) {
278
+ return new PromptStream(this.events(id, prompt, options));
279
+ }
280
+ /**
281
+ * The Server-Sent Events of a prompt, which are requested when the iteration starts.
282
+ *
283
+ * @param id - The LLMClient's id or hashed id.
284
+ * @param prompt - The prompt.
285
+ * @param options - `sessionKey`, and per-request options.
286
+ * @returns A function that starts the request.
287
+ */
288
+ events(id, prompt, options) {
289
+ const path = `${this.path}${resourceId(id)}/prompt/`;
290
+ const json = { session_key: options?.sessionKey ?? null, messages: requestMessages(toMessages(prompt)) };
291
+ return () => this.http.events("POST", path, { ...options, json });
292
+ }
293
+ /**
294
+ * Start or resume a conversation with an LLMClient.
295
+ *
296
+ * @param id - The LLMClient's id or hashed id.
297
+ * @param options - `sessionKey`: an existing session's key, to resume it, or none for a new session.
298
+ * @returns The chat session.
299
+ */
300
+ async chat(id, options) {
301
+ return new ChatSession(this, id, await this.config(id, options));
302
+ }
303
+ /**
304
+ * An LLMClient's plugins.
305
+ *
306
+ * @param id - The LLMClient's integer id.
307
+ * @param options - Per-request options.
308
+ * @returns The plugins.
309
+ */
310
+ async plugins(id, options) {
311
+ return this.http.request("GET", `${this.path}${resourceId(id)}/plugins/`, z.array(LLMClientPlugin), options);
312
+ }
313
+ /**
314
+ * The extensions whose tools an LLMClient offers the LLM, e.g. `calculator`.
315
+ *
316
+ * @param id - The LLMClient's integer id.
317
+ * @param options - Per-request options.
318
+ * @returns The extensions.
319
+ */
320
+ async extensions(id, options) {
321
+ return this.http.request("GET", `${this.path}${resourceId(id)}/extensions`, z.array(LLMClientExtension), options);
322
+ }
323
+ /**
324
+ * The api keys that may call an LLMClient that requires authentication.
325
+ *
326
+ * @param id - The LLMClient's integer id.
327
+ * @param options - Per-request options.
328
+ * @returns The api keys.
329
+ */
330
+ async apiKeys(id, options) {
331
+ return this.http.request("GET", `${this.path}${resourceId(id)}/apikeys/`, z.array(LLMClientApiKey), options);
332
+ }
333
+ /**
334
+ * The custom domains of an LLMClient.
335
+ *
336
+ * @param id - The LLMClient's integer id.
337
+ * @param options - Per-request options.
338
+ * @returns The custom domains.
339
+ */
340
+ async customDomains(id, options) {
341
+ return this.http.request("GET", `${this.path}${resourceId(id)}/customdomains`, z.array(LLMClientCustomDomain), options);
342
+ }
343
+ /**
344
+ * Deploy an LLMClient on its own host name.
345
+ *
346
+ * This creates real, possibly billable infrastructure: DNS records, a TLS certificate and a
347
+ * Kubernetes ingress.
348
+ *
349
+ * @param name - The LLMClient's name.
350
+ * @param options - Per-request options.
351
+ * @returns The platform's response.
352
+ */
353
+ async deploy(name, options) {
354
+ return this.client.manifests.deploy(this.kind, name, options);
355
+ }
356
+ /**
357
+ * Undo an LLMClient's deployment.
358
+ *
359
+ * @param name - The LLMClient's name.
360
+ * @param options - Per-request options.
361
+ * @returns The platform's response.
362
+ */
363
+ async undeploy(name, options) {
364
+ return this.client.manifests.undeploy(this.kind, name, options);
365
+ }
366
+ }
367
+ //# sourceMappingURL=llmclients.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llmclients.js","sourceRoot":"","sources":["../../src/resources/llmclients.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIrE,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,oBA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CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,OAAwB;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,OAAwB;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;CACF"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * LLMHosts: open-weight models that the platform serves on its own Kubernetes cluster.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const models = await client.llmHosts.discover({ query: "qwen", task: "chat" });
7
+ * const plan = await client.llmHosts.plan(3); // what deploying would create, without creating it
8
+ * const status = await client.llmHosts.status(3);
9
+ * ```
10
+ */
11
+ import type { RequestOptions } from "../core/http.ts";
12
+ import type { SmarterId } from "../core/typing.ts";
13
+ import { LLMHost, LLMHostLogs, LLMHostPlan, LLMHostReport, LLMHostStatus, type DiscoveredModel } from "../models/llmhost.ts";
14
+ import { Manifest } from "../models/manifest.ts";
15
+ import { SmarterKindResource } from "./base.ts";
16
+ /** LLMHosts: `/api/v1/llmhosts/`, and the manifest api's `LLMHost` kind. */
17
+ export declare class LLMHosts extends SmarterKindResource<typeof LLMHost> {
18
+ readonly kind = "LLMHost";
19
+ readonly path = "llmhosts/";
20
+ readonly model: import("zod").ZodObject<{
21
+ id: import("zod").ZodNumber;
22
+ hashedId: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
23
+ name: import("zod").ZodString;
24
+ description: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
25
+ version: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
26
+ tags: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
27
+ annotations: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodPreprocess<import("zod").ZodNullable<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>, unknown>>>;
28
+ createdAt: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
29
+ updatedAt: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
30
+ userProfile: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodObject<{
31
+ user: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodObject<{
32
+ username: import("zod").ZodString;
33
+ email: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
34
+ }, import("zod/v4/core").$loose>>>;
35
+ account: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodObject<{
36
+ accountNumber: import("zod").ZodString;
37
+ }, import("zod/v4/core").$loose>>>;
38
+ }, import("zod/v4/core").$loose>>>;
39
+ canDelete: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodBoolean>>;
40
+ manifestUrl: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
41
+ detailUrl: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
42
+ ready: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodBoolean>>;
43
+ spec: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodType<import("../core/typing.ts").JsonObject, unknown, import("zod/v4/core").$ZodTypeInternals<import("../core/typing.ts").JsonObject, unknown>>>>;
44
+ modelSource: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
45
+ modelRepository: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
46
+ modelRevision: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
47
+ modelTask: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
48
+ inferenceEngine: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
49
+ apiFormat: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
50
+ compute: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
51
+ gpuCount: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
52
+ gpuType: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
53
+ replicas: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
54
+ readyReplicas: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodNumber>>;
55
+ status: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
56
+ statusMessage: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
57
+ endpointUrl: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
58
+ publicUrl: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
59
+ servedModelName: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
60
+ isActive: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodBoolean>>;
61
+ deployedAt: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
62
+ costPerHour: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
63
+ }, import("zod/v4/core").$loose>;
64
+ /**
65
+ * An LLMHost's state, read from Kubernetes now.
66
+ *
67
+ * @param id - The LLMHost's id or hashed id.
68
+ * @param options - Per-request options.
69
+ * @returns Its status, replicas and pods.
70
+ */
71
+ status(id: SmarterId, options?: RequestOptions): Promise<LLMHostStatus>;
72
+ /**
73
+ * The latest log lines of an LLMHost's pods.
74
+ *
75
+ * @param id - The LLMHost's id or hashed id.
76
+ * @param options - `tail`: how many lines, 200 by default.
77
+ * @returns The logs.
78
+ */
79
+ logs(id: SmarterId, options?: RequestOptions & {
80
+ tail?: number;
81
+ }): Promise<LLMHostLogs>;
82
+ /**
83
+ * The Kubernetes resources that deploying an LLMHost would create, without creating them.
84
+ *
85
+ * @param id - The LLMHost's id or hashed id.
86
+ * @param options - Per-request options.
87
+ * @returns The resources.
88
+ */
89
+ plan(id: SmarterId, options?: RequestOptions): Promise<LLMHostPlan>;
90
+ /**
91
+ * Deploy an LLMHost on the platform's cluster.
92
+ *
93
+ * This creates real, billable infrastructure, e.g. GPU nodes. Check {@link LLMHosts.plan} first.
94
+ *
95
+ * @param id - The LLMHost's id or hashed id.
96
+ * @param options - Per-request options.
97
+ * @returns Its state.
98
+ */
99
+ deploy(id: SmarterId, options?: RequestOptions): Promise<LLMHostStatus>;
100
+ /**
101
+ * Undeploy an LLMHost.
102
+ *
103
+ * @param id - The LLMHost's id or hashed id.
104
+ * @param options - `purge`: true to delete its model storage too.
105
+ * @returns Its state.
106
+ */
107
+ undeploy(id: SmarterId, options?: RequestOptions & {
108
+ purge?: boolean;
109
+ }): Promise<LLMHostStatus>;
110
+ /**
111
+ * A report of every LLMHost that the user may read: counts by status and engine, and estimated costs.
112
+ *
113
+ * @param options - Per-request options.
114
+ * @returns The report.
115
+ */
116
+ report(options?: RequestOptions): Promise<LLMHostReport>;
117
+ /**
118
+ * Search a public model catalog for models that an LLMHost can serve.
119
+ *
120
+ * @param options - `query`: the search text, e.g. `qwen`. `task`: only models of this task, e.g.
121
+ * `chat` or `embedding`. `catalog`: `huggingface` by default. `limit`: at most this many, 20 by default.
122
+ * @returns The models, each with the LLMHost manifest that would serve it.
123
+ */
124
+ discover(options?: RequestOptions & {
125
+ query?: string | null;
126
+ task?: string | null;
127
+ catalog?: string;
128
+ limit?: number;
129
+ }): Promise<DiscoveredModel[]>;
130
+ /**
131
+ * An LLMHost manifest for a model in a public catalog, ready to apply.
132
+ *
133
+ * @param repository - The model's repository, e.g. `Qwen/Qwen2.5-7B-Instruct`.
134
+ * @param options - `catalog`, `huggingface` by default. `engine`: the inference engine, or none for the
135
+ * platform's choice. `name`: the LLMHost's name, or none for one derived from the repository.
136
+ * `tokenSecret`: the name of a Secret that holds the catalog's access token, for gated models.
137
+ * @returns The manifest, which {@link LLMHosts.apply} accepts.
138
+ */
139
+ discoverManifest(repository: string, options?: RequestOptions & {
140
+ catalog?: string;
141
+ engine?: string | null;
142
+ name?: string | null;
143
+ tokenSecret?: string | null;
144
+ }): Promise<Manifest>;
145
+ }
146
+ //# sourceMappingURL=llmhosts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llmhosts.d.ts","sourceRoot":"","sources":["../../src/resources/llmhosts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAGL,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,EACb,aAAa,EACb,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAc,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAE5D,4EAA4E;AAC5E,qBAAa,QAAS,SAAQ,mBAAmB,CAAC,OAAO,OAAO,CAAC;IAC/D,QAAQ,CAAC,IAAI,aAAa;IAC1B,QAAQ,CAAC,IAAI,eAAe;IAC5B,QAAQ,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAAW;IAEzB;;;;;;OAMG;IACG,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAI7E;;;;;;OAMG;IACG,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAO7F;;;;;;OAMG;IACG,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzE;;;;;;;;OAQG;IACG,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAI7E;;;;;;OAMG;IACG,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAOrG;;;;;OAKG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAI9D;;;;;;OAMG;IACG,QAAQ,CACZ,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3G,OAAO,CAAC,eAAe,EAAE,CAAC;IAa7B;;;;;;;;OAQG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,cAAc,GAAG;QACzB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC7B,GACA,OAAO,CAAC,QAAQ,CAAC;CAarB"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * LLMHosts: open-weight models that the platform serves on its own Kubernetes cluster.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const models = await client.llmHosts.discover({ query: "qwen", task: "chat" });
7
+ * const plan = await client.llmHosts.plan(3); // what deploying would create, without creating it
8
+ * const status = await client.llmHosts.status(3);
9
+ * ```
10
+ */
11
+ import { DiscoveredManifest, DiscoveredModels, LLMHost, LLMHostLogs, LLMHostPlan, LLMHostReport, LLMHostStatus, } from "../models/llmhost.js";
12
+ import { Manifest } from "../models/manifest.js";
13
+ import { resourceId, SmarterKindResource } from "./base.js";
14
+ /** LLMHosts: `/api/v1/llmhosts/`, and the manifest api's `LLMHost` kind. */
15
+ export class LLMHosts extends SmarterKindResource {
16
+ kind = "LLMHost";
17
+ path = "llmhosts/";
18
+ model = LLMHost;
19
+ /**
20
+ * An LLMHost's state, read from Kubernetes now.
21
+ *
22
+ * @param id - The LLMHost's id or hashed id.
23
+ * @param options - Per-request options.
24
+ * @returns Its status, replicas and pods.
25
+ */
26
+ async status(id, options) {
27
+ return this.http.request("GET", `${this.path}${resourceId(id)}/status/`, LLMHostStatus, options);
28
+ }
29
+ /**
30
+ * The latest log lines of an LLMHost's pods.
31
+ *
32
+ * @param id - The LLMHost's id or hashed id.
33
+ * @param options - `tail`: how many lines, 200 by default.
34
+ * @returns The logs.
35
+ */
36
+ async logs(id, options) {
37
+ return this.http.request("GET", `${this.path}${resourceId(id)}/logs/`, LLMHostLogs, {
38
+ ...options,
39
+ params: { tail: options?.tail ?? 200 },
40
+ });
41
+ }
42
+ /**
43
+ * The Kubernetes resources that deploying an LLMHost would create, without creating them.
44
+ *
45
+ * @param id - The LLMHost's id or hashed id.
46
+ * @param options - Per-request options.
47
+ * @returns The resources.
48
+ */
49
+ async plan(id, options) {
50
+ return this.http.request("GET", `${this.path}${resourceId(id)}/plan/`, LLMHostPlan, options);
51
+ }
52
+ /**
53
+ * Deploy an LLMHost on the platform's cluster.
54
+ *
55
+ * This creates real, billable infrastructure, e.g. GPU nodes. Check {@link LLMHosts.plan} first.
56
+ *
57
+ * @param id - The LLMHost's id or hashed id.
58
+ * @param options - Per-request options.
59
+ * @returns Its state.
60
+ */
61
+ async deploy(id, options) {
62
+ return this.http.request("POST", `${this.path}${resourceId(id)}/deploy/`, LLMHostStatus, options);
63
+ }
64
+ /**
65
+ * Undeploy an LLMHost.
66
+ *
67
+ * @param id - The LLMHost's id or hashed id.
68
+ * @param options - `purge`: true to delete its model storage too.
69
+ * @returns Its state.
70
+ */
71
+ async undeploy(id, options) {
72
+ return this.http.request("POST", `${this.path}${resourceId(id)}/undeploy/`, LLMHostStatus, {
73
+ ...options,
74
+ params: { purge: options?.purge ? true : undefined },
75
+ });
76
+ }
77
+ /**
78
+ * A report of every LLMHost that the user may read: counts by status and engine, and estimated costs.
79
+ *
80
+ * @param options - Per-request options.
81
+ * @returns The report.
82
+ */
83
+ async report(options) {
84
+ return this.http.request("GET", `${this.path}report/`, LLMHostReport, options);
85
+ }
86
+ /**
87
+ * Search a public model catalog for models that an LLMHost can serve.
88
+ *
89
+ * @param options - `query`: the search text, e.g. `qwen`. `task`: only models of this task, e.g.
90
+ * `chat` or `embedding`. `catalog`: `huggingface` by default. `limit`: at most this many, 20 by default.
91
+ * @returns The models, each with the LLMHost manifest that would serve it.
92
+ */
93
+ async discover(options) {
94
+ const response = await this.http.request("GET", `${this.path}discover/`, DiscoveredModels, {
95
+ ...options,
96
+ params: {
97
+ q: options?.query,
98
+ task: options?.task,
99
+ catalog: options?.catalog ?? "huggingface",
100
+ limit: options?.limit ?? 20,
101
+ },
102
+ });
103
+ return response.models;
104
+ }
105
+ /**
106
+ * An LLMHost manifest for a model in a public catalog, ready to apply.
107
+ *
108
+ * @param repository - The model's repository, e.g. `Qwen/Qwen2.5-7B-Instruct`.
109
+ * @param options - `catalog`, `huggingface` by default. `engine`: the inference engine, or none for the
110
+ * platform's choice. `name`: the LLMHost's name, or none for one derived from the repository.
111
+ * `tokenSecret`: the name of a Secret that holds the catalog's access token, for gated models.
112
+ * @returns The manifest, which {@link LLMHosts.apply} accepts.
113
+ */
114
+ async discoverManifest(repository, options) {
115
+ const response = await this.http.request("GET", `${this.path}discover/manifest/`, DiscoveredManifest, {
116
+ ...options,
117
+ params: {
118
+ repository,
119
+ catalog: options?.catalog ?? "huggingface",
120
+ engine: options?.engine,
121
+ name: options?.name,
122
+ tokenSecret: options?.tokenSecret,
123
+ },
124
+ });
125
+ return Manifest.parse(response.manifest);
126
+ }
127
+ }
128
+ //# sourceMappingURL=llmhosts.js.map