@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55

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 (190) hide show
  1. package/CHANGELOG.md +110 -2
  2. package/README.md +266 -88
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/api-only.d.ts +16 -4
  9. package/dist/api-only.js +21 -7
  10. package/dist/cli.js +5 -3
  11. package/dist/composio-made.d.ts +26 -1
  12. package/dist/composio-made.js +39 -2
  13. package/dist/composio-preset.d.ts +3 -2
  14. package/dist/composio-preset.js +46 -14
  15. package/dist/computer-held-routes.js +2 -3
  16. package/dist/computer-setting.d.ts +4 -2
  17. package/dist/computer-setting.js +0 -2
  18. package/dist/computers-running.d.ts +8 -0
  19. package/dist/computers-running.js +27 -0
  20. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  21. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  22. package/dist/console/assets/index-DYhU4adm.css +1 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/docker-host-addresses.d.ts +23 -3
  25. package/dist/docker-host-addresses.js +90 -18
  26. package/dist/exa-keyless.d.ts +2 -3
  27. package/dist/exa-keyless.js +43 -127
  28. package/dist/firecrawl-keyless.d.ts +41 -0
  29. package/dist/firecrawl-keyless.js +152 -0
  30. package/dist/handed-secret.d.ts +3 -1
  31. package/dist/handed-secret.js +4 -2
  32. package/dist/harness-keys.d.ts +98 -0
  33. package/dist/harness-keys.js +247 -0
  34. package/dist/harness-recipe-entry.d.ts +14 -9
  35. package/dist/harness-recipe-entry.js +25 -14
  36. package/dist/harness-table.d.ts +16 -1
  37. package/dist/harness-table.js +19 -7
  38. package/dist/harness.d.ts +4 -0
  39. package/dist/harness.js +12 -1
  40. package/dist/host-check.d.ts +2 -0
  41. package/dist/host-check.js +6 -0
  42. package/dist/import-summary.d.ts +1 -1
  43. package/dist/import-summary.js +1 -1
  44. package/dist/import.d.ts +5 -5
  45. package/dist/import.js +54 -67
  46. package/dist/keyless-mcp.d.ts +36 -0
  47. package/dist/keyless-mcp.js +127 -0
  48. package/dist/learn/audit.d.ts +3 -3
  49. package/dist/learn/audit.js +3 -3
  50. package/dist/learn/commit.d.ts +8 -7
  51. package/dist/learn/commit.js +60 -20
  52. package/dist/learn/compile.d.ts +4 -3
  53. package/dist/learn/compile.js +7 -5
  54. package/dist/learn/folder.d.ts +16 -3
  55. package/dist/learn/folder.js +46 -13
  56. package/dist/learn/promote.d.ts +37 -13
  57. package/dist/learn/promote.js +112 -40
  58. package/dist/learn/secrets.js +10 -2
  59. package/dist/learning-routes.d.ts +22 -17
  60. package/dist/learning-routes.js +40 -39
  61. package/dist/learning.js +2 -2
  62. package/dist/manifest.d.ts +10 -0
  63. package/dist/manifest.js +30 -0
  64. package/dist/mcp-pin-first.d.ts +4 -2
  65. package/dist/mcp-pin-first.js +5 -2
  66. package/dist/mcp-secret-writes.d.ts +16 -7
  67. package/dist/mcp-secret-writes.js +35 -27
  68. package/dist/mcp-servers-store.d.ts +30 -6
  69. package/dist/mcp-servers-store.js +112 -28
  70. package/dist/mcp-sources.d.ts +10 -2
  71. package/dist/mcp-sources.js +9 -2
  72. package/dist/mcp-store.d.ts +13 -7
  73. package/dist/mcp-store.js +12 -9
  74. package/dist/model-form.d.ts +3 -2
  75. package/dist/model-form.js +11 -7
  76. package/dist/model.d.ts +20 -4
  77. package/dist/model.js +68 -9
  78. package/dist/native/history.d.ts +1 -1
  79. package/dist/native/history.js +2 -2
  80. package/dist/ollama-provider.d.ts +92 -0
  81. package/dist/ollama-provider.js +495 -0
  82. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  83. package/dist/openapi.js +127 -37
  84. package/dist/page.d.ts +11 -3
  85. package/dist/page.js +22 -7
  86. package/dist/place-offers.d.ts +17 -1
  87. package/dist/place-offers.js +46 -5
  88. package/dist/print.js +1 -1
  89. package/dist/purged-workflow.d.ts +35 -7
  90. package/dist/purged-workflow.js +73 -26
  91. package/dist/run-computer.d.ts +2 -0
  92. package/dist/run-computer.js +2 -0
  93. package/dist/run-files.d.ts +4 -0
  94. package/dist/run-files.js +4 -0
  95. package/dist/run-keys.d.ts +2 -4
  96. package/dist/run-keys.js +6 -7
  97. package/dist/run-launch.d.ts +4 -0
  98. package/dist/run-launch.js +4 -0
  99. package/dist/run-reads-over-store.d.ts +3 -2
  100. package/dist/run-reads-over-store.js +66 -2
  101. package/dist/run-secrets.js +5 -2
  102. package/dist/runner/adapter-loop.d.ts +6 -3
  103. package/dist/runner/adapter-loop.js +34 -15
  104. package/dist/runner/adapter-run-spec.d.ts +3 -0
  105. package/dist/runner/adapter-run-spec.js +5 -3
  106. package/dist/runner/audit.js +8 -4
  107. package/dist/runner/beside.d.ts +2 -1
  108. package/dist/runner/beside.js +6 -2
  109. package/dist/runner/claim-secrets.d.ts +5 -8
  110. package/dist/runner/claim-secrets.js +6 -0
  111. package/dist/runner/cli-run-spec.d.ts +1 -1
  112. package/dist/runner/cli-run-spec.js +38 -6
  113. package/dist/runner/harness-loops.d.ts +22 -9
  114. package/dist/runner/harness-loops.js +21 -11
  115. package/dist/runner/held.d.ts +3 -0
  116. package/dist/runner/learning-end.d.ts +1 -1
  117. package/dist/runner/learning-end.js +8 -3
  118. package/dist/runner/loop-contract.d.ts +5 -4
  119. package/dist/runner/main.js +4 -2
  120. package/dist/runner/mcp-claim.d.ts +3 -0
  121. package/dist/runner/mcp-claim.js +26 -2
  122. package/dist/runner/mcp-run.d.ts +3 -0
  123. package/dist/runner/mcp-run.js +2 -1
  124. package/dist/runner/metrics.d.ts +10 -10
  125. package/dist/runner/metrics.js +19 -38
  126. package/dist/runner/model-route.d.ts +3 -0
  127. package/dist/runner/model-route.js +6 -2
  128. package/dist/runner/promotion.d.ts +15 -9
  129. package/dist/runner/promotion.js +25 -15
  130. package/dist/runner/run-child-host.js +17 -7
  131. package/dist/runner/run-child.js +3 -1
  132. package/dist/runner/sdk-loop.js +2 -0
  133. package/dist/runner/workflow-loop.d.ts +2 -2
  134. package/dist/runner/workflow-loop.js +1 -2
  135. package/dist/runner/workflow-spec.d.ts +1 -1
  136. package/dist/runner/workflow-spec.js +6 -6
  137. package/dist/sdk/check.d.ts +4 -1
  138. package/dist/sdk/check.js +2 -1
  139. package/dist/sdk/runs.d.ts +2 -2
  140. package/dist/sdk/runs.js +8 -6
  141. package/dist/secret-cut.js +2 -1
  142. package/dist/secret-writes.d.ts +3 -2
  143. package/dist/secret-writes.js +1 -1
  144. package/dist/server.d.ts +44 -8
  145. package/dist/server.js +283 -108
  146. package/dist/standard-webhooks.d.ts +11 -0
  147. package/dist/standard-webhooks.js +20 -2
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/schema.js +5 -2
  150. package/dist/store/sqlite/store.js +90 -34
  151. package/dist/store/store.d.ts +54 -14
  152. package/dist/store-reads/journal.d.ts +7 -2
  153. package/dist/store-reads/journal.js +9 -6
  154. package/dist/store-reads/learning.d.ts +12 -9
  155. package/dist/store-reads/learning.js +18 -24
  156. package/dist/store-view.d.ts +0 -5
  157. package/dist/store-view.js +9 -8
  158. package/dist/template-eval.d.ts +49 -4
  159. package/dist/template-eval.js +168 -45
  160. package/dist/template-import.js +4 -2
  161. package/dist/templates.d.ts +5 -3
  162. package/dist/templates.js +19 -40
  163. package/dist/timeline/labels.d.ts +2 -2
  164. package/dist/timeline/labels.js +2 -2
  165. package/dist/timeline/timeline.d.ts +2 -2
  166. package/dist/timeline/timeline.js +1 -1
  167. package/dist/tool-plane.d.ts +17 -9
  168. package/dist/tool-plane.js +38 -17
  169. package/dist/tools.js +2 -2
  170. package/dist/trigger-launch-hook.d.ts +16 -8
  171. package/dist/trigger-launch-hook.js +32 -23
  172. package/dist/trigger-targets.d.ts +18 -8
  173. package/dist/trigger-targets.js +42 -19
  174. package/dist/triggers.d.ts +85 -23
  175. package/dist/triggers.js +303 -96
  176. package/dist/web-fake.js +3 -3
  177. package/dist/web-fetch-direct.d.ts +4 -0
  178. package/dist/web-fetch-direct.js +8 -1
  179. package/dist/web-fetch.d.ts +12 -3
  180. package/dist/web-fetch.js +47 -14
  181. package/dist/web-search.d.ts +33 -4
  182. package/dist/web-search.js +100 -41
  183. package/dist/webhooks.js +4 -5
  184. package/launcher/agentrun-serve +5 -1
  185. package/package.json +17 -13
  186. package/templates/README.md +2 -2
  187. package/dist/console/assets/index-B_85An2t.js +0 -745
  188. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  189. package/dist/import-sources.d.ts +0 -116
  190. package/dist/import-sources.js +0 -693
@@ -1,4 +1,4 @@
1
- import { type Mcp, type McpCredential, type McpCredentialMark, type McpOauth, type McpServerRow, type OpenedMcpCredential } from "./store/index.js";
1
+ import { type Mcp, type McpCredential, type McpCredentialMark, type McpOauth, type McpOwnersMark, type McpServerRow, type McpTokensMark, type OpenedMcpCredential } from "./store/index.js";
2
2
  /** The most server-supplied text (server_info JSON, instructions) a row holds: both come from the remote server
3
3
  * (untrusted), so they are bounded at save, never stored unbounded. */
4
4
  export declare const MCP_META_MAX_BYTES: number;
@@ -29,15 +29,19 @@ export declare function saveMcpServer(store: {
29
29
  }): Promise<McpServerRow>;
30
30
  /** saveMcpServer, only while the server's credential is still `expected` (its mark as the writer read it: null, no
31
31
  * server by that name), compared and written in one statement (Mcp.putIfCredential). Undefined, writing nothing, when
32
- * another save, a sign-in or a removal changed it since. */
32
+ * another save, a sign-in or a removal changed it since. `tokens`: the API token's save, which writes over a saved row
33
+ * only while that row still carries the token's mark, compared in the same statement. `owns`: the owner's save, which
34
+ * drops the token's mark in the transaction that writes the row, once it is written (McpOwnersMark). */
33
35
  export declare function saveMcpServerIfCredential(store: {
34
36
  mcp: Pick<Mcp, "putIfCredential">;
35
- }, sealKey: Buffer, server: McpServerSave, expected: McpCredentialMark, { githubMcpOrigin }?: {
37
+ }, sealKey: Buffer, server: McpServerSave, expected: McpCredentialMark, { githubMcpOrigin, tokens, owns }?: {
36
38
  githubMcpOrigin?: string;
39
+ tokens?: McpTokensMark;
40
+ owns?: McpOwnersMark;
37
41
  }): Promise<McpServerRow | undefined>;
38
42
  /** Rewrites a server's row the owner read, its sealed credential kept as it is (store.mcp.rewrite): written iff the
39
43
  * credential is still `seen`; undefined, writing nothing, when it changed meanwhile or the row went. Bounded and
40
- * github_app-guarded as saveMcpServer. */
44
+ * github_app-guarded as saveMcpServer. `owns`: as saveMcpServerIfCredential's. */
41
45
  export declare function rewriteMcpServer(store: {
42
46
  mcp: Pick<Mcp, "rewrite">;
43
47
  }, server: {
@@ -51,18 +55,20 @@ export declare function rewriteMcpServer(store: {
51
55
  instructions?: string | null;
52
56
  listedAt?: number;
53
57
  updatedAt?: number;
54
- }, seen: Uint8Array | null, { githubMcpOrigin }?: {
58
+ }, seen: Uint8Array | null, { githubMcpOrigin, owns }?: {
55
59
  githubMcpOrigin?: string;
60
+ owns?: McpOwnersMark;
56
61
  }): Promise<McpServerRow | undefined>;
57
62
  /** The server's row goes; what it held as it went (its address, its credential opened, as openServerCredential does), or
58
63
  * undefined when there was no row. */
59
64
  export declare function removeMcpServer(store: {
60
65
  mcp: Pick<Mcp, "remove">;
61
66
  }, sealKey: Buffer, name: string): Promise<RemovedMcpServer | undefined>;
62
- /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential). Undefined when it is not. */
67
+ /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential), and with `tokens` (the
68
+ * API token's delete) only while it still carries the token's mark, both in the deleting statement. Undefined when not. */
63
69
  export declare function removeMcpServerIfCredential(store: {
64
70
  mcp: Pick<Mcp, "removeIfCredential">;
65
- }, sealKey: Buffer, name: string, expected: NonNullable<McpCredentialMark>): Promise<RemovedMcpServer | undefined>;
71
+ }, sealKey: Buffer, name: string, expected: NonNullable<McpCredentialMark>, tokens?: McpTokensMark): Promise<RemovedMcpServer | undefined>;
66
72
  /** A removed row: its address and its credential opened (§7), the credential the one the deleting statement saw. */
67
73
  export type RemovedMcpServer = {
68
74
  url: string;
package/dist/mcp-store.js CHANGED
@@ -38,9 +38,11 @@ export async function saveMcpServer(store, sealKey, server,
38
38
  }
39
39
  /** saveMcpServer, only while the server's credential is still `expected` (its mark as the writer read it: null, no
40
40
  * server by that name), compared and written in one statement (Mcp.putIfCredential). Undefined, writing nothing, when
41
- * another save, a sign-in or a removal changed it since. */
42
- export async function saveMcpServerIfCredential(store, sealKey, server, expected, { githubMcpOrigin = GITHUB_MCP_ORIGIN } = {}) {
43
- return store.mcp.putIfCredential(serverWrite(sealKey, server, githubMcpOrigin), expected);
41
+ * another save, a sign-in or a removal changed it since. `tokens`: the API token's save, which writes over a saved row
42
+ * only while that row still carries the token's mark, compared in the same statement. `owns`: the owner's save, which
43
+ * drops the token's mark in the transaction that writes the row, once it is written (McpOwnersMark). */
44
+ export async function saveMcpServerIfCredential(store, sealKey, server, expected, { githubMcpOrigin = GITHUB_MCP_ORIGIN, tokens, owns } = {}) {
45
+ return store.mcp.putIfCredential(serverWrite(sealKey, server, githubMcpOrigin), expected, tokens, owns);
44
46
  }
45
47
  /** The store's write of `server`: its credential sealed, its info and instructions bounded. */
46
48
  function serverWrite(sealKey, server, githubMcpOrigin) {
@@ -60,24 +62,25 @@ function serverWrite(sealKey, server, githubMcpOrigin) {
60
62
  }
61
63
  /** Rewrites a server's row the owner read, its sealed credential kept as it is (store.mcp.rewrite): written iff the
62
64
  * credential is still `seen`; undefined, writing nothing, when it changed meanwhile or the row went. Bounded and
63
- * github_app-guarded as saveMcpServer. */
64
- export async function rewriteMcpServer(store, server, seen, { githubMcpOrigin = GITHUB_MCP_ORIGIN } = {}) {
65
+ * github_app-guarded as saveMcpServer. `owns`: as saveMcpServerIfCredential's. */
66
+ export async function rewriteMcpServer(store, server, seen, { githubMcpOrigin = GITHUB_MCP_ORIGIN, owns } = {}) {
65
67
  if (server.auth === "github_app" && !githubMcpUrl(server.url, githubMcpOrigin))
66
68
  throw new Error(`The MCP server ${server.name} is not kept: ${GITHUB_MCP_ONLY}.`);
67
69
  return store.mcp.rewrite({
68
70
  name: server.name, url: server.url, auth: server.auth, protocol: server.protocol ?? null, tools: server.tools, prices: server.prices ?? null,
69
71
  serverInfo: boundedServerInfo(server.serverInfo), instructions: boundedInstructions(server.instructions),
70
72
  ...(server.listedAt !== undefined ? { listedAt: server.listedAt } : {}), ...(server.updatedAt !== undefined ? { updatedAt: server.updatedAt } : {}),
71
- }, seen);
73
+ }, seen, owns);
72
74
  }
73
75
  /** The server's row goes; what it held as it went (its address, its credential opened, as openServerCredential does), or
74
76
  * undefined when there was no row. */
75
77
  export async function removeMcpServer(store, sealKey, name) {
76
78
  return removedServer(sealKey, name, await store.mcp.remove(name));
77
79
  }
78
- /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential). Undefined when it is not. */
79
- export async function removeMcpServerIfCredential(store, sealKey, name, expected) {
80
- return removedServer(sealKey, name, await store.mcp.removeIfCredential(name, expected));
80
+ /** The server's row goes, only while its credential is still `expected` (Mcp.removeIfCredential), and with `tokens` (the
81
+ * API token's delete) only while it still carries the token's mark, both in the deleting statement. Undefined when not. */
82
+ export async function removeMcpServerIfCredential(store, sealKey, name, expected, tokens) {
83
+ return removedServer(sealKey, name, await store.mcp.removeIfCredential(name, expected, tokens));
81
84
  }
82
85
  const removedServer = (sealKey, name, removed) => {
83
86
  if (!removed)
@@ -20,8 +20,9 @@ export type FreeModel = {
20
20
  context_window: number;
21
21
  };
22
22
  /** The free models offered for `harness` on this server, besides pickerCandidates' (harness.ts harnessOffers drops those
23
- * it does not run): OpenRouter's chat models whose catalog price is all zeros (pi-ai's own and serve's ADDED_MODELS), on
24
- * pi with OpenRouter's key, by id. None for an adapter harness (each runs its own wire's vendor), behind a gateway (its
23
+ * it does not run), on pi: the models of the Ollama here (ollama-provider.ts, `ollama/<tag>`, each at $0 on this machine,
24
+ * in Ollama's order), then, with OpenRouter's key, OpenRouter's chat models whose catalog price is all zeros (pi-ai's own
25
+ * and serve's ADDED_MODELS), by id. None for an adapter harness (each runs its own wire's vendor), behind a gateway (its
25
26
  * ids are its own) or with the faux model. */
26
27
  export declare function freeCandidates(env: NodeJS.ProcessEnv, harness: string): Promise<FreeModel[]>;
27
28
  /** The model `given` most likely means, in the form this harness takes, or undefined when none is obvious: the same id
@@ -56,16 +56,20 @@ export function pickerCandidates(env, harness) {
56
56
  return [...plan, ...PICKABLE.filter((p) => vendors.includes(p.vendor)).flatMap((p) => p.ids.map((id) => formOf(env, p.vendor, id)))];
57
57
  }
58
58
  /** The free models offered for `harness` on this server, besides pickerCandidates' (harness.ts harnessOffers drops those
59
- * it does not run): OpenRouter's chat models whose catalog price is all zeros (pi-ai's own and serve's ADDED_MODELS), on
60
- * pi with OpenRouter's key, by id. None for an adapter harness (each runs its own wire's vendor), behind a gateway (its
59
+ * it does not run), on pi: the models of the Ollama here (ollama-provider.ts, `ollama/<tag>`, each at $0 on this machine,
60
+ * in Ollama's order), then, with OpenRouter's key, OpenRouter's chat models whose catalog price is all zeros (pi-ai's own
61
+ * and serve's ADDED_MODELS), by id. None for an adapter harness (each runs its own wire's vendor), behind a gateway (its
61
62
  * ids are its own) or with the faux model. */
62
63
  export async function freeCandidates(env, harness) {
63
- if (env[FAUX_ENV] || env.AGENT_MODEL_BASE_URL || !env.OPENROUTER_API_KEY || factsOf(env, harness))
64
+ if (env[FAUX_ENV] || env.AGENT_MODEL_BASE_URL || factsOf(env, harness))
64
65
  return [];
65
- const [{ builtinModels }, { withLocalModels, isFree }] = await Promise.all([import("@earendil-works/pi-ai/providers/all"), import("./local-models.js")]);
66
- return withLocalModels(builtinModels()).getModels("openrouter").filter(isFree)
67
- .map((model) => ({ id: `openrouter/${model.id}`, context_window: model.contextWindow }))
68
- .sort((a, b) => a.id.localeCompare(b.id));
66
+ const [{ builtinModels }, { withLocalModels, isFree }, { contextOf, OLLAMA_PROVIDER, ollamaModels }] = await Promise.all([import("@earendil-works/pi-ai/providers/all"), import("./local-models.js"), import("./ollama-provider.js")]);
67
+ const local = (await ollamaModels(env)).filter((model) => model.capabilities.includes("completion")).map((model) => ({ id: `${OLLAMA_PROVIDER}/${model.name}`, context_window: contextOf(model, env) }));
68
+ if (!env.OPENROUTER_API_KEY)
69
+ return local;
70
+ return [...local, ...withLocalModels(builtinModels()).getModels("openrouter").filter(isFree)
71
+ .map((model) => ({ id: `openrouter/${model.id}`, context_window: model.contextWindow }))
72
+ .sort((a, b) => a.id.localeCompare(b.id))];
69
73
  }
70
74
  /** A model id with its spelling taken out (case, spaces, dots, dashes), and the provider's segments off. */
71
75
  const spelled = (given) => (given.split("/").pop() ?? "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
package/dist/model.d.ts CHANGED
@@ -5,6 +5,11 @@ import { type HarnessEntry } from "./harness-table.js";
5
5
  import type { Revision } from "./agent-rows.js";
6
6
  /** The child's environment names the faux module by absolute path. */
7
7
  export declare const FAUX_ENV = "AGENTRUN_SERVE_FAUX";
8
+ /** The Ollama tags among a run's models (`ollama/<tag>`): what providerModels resolves for it, one /api/show each. */
9
+ export declare const ollamaTagsOf: (refs: Iterable<ModelRef | undefined>) => string[];
10
+ /** Whether the Ollama here is asked for its models under `env`: not under the faux model or a model gateway, which take
11
+ * every model. The one rule for listing (withOllamaModels), the host default (localDefault) and the server's refresh. */
12
+ export declare const asksOllama: (env: NodeJS.ProcessEnv) => boolean;
8
13
  /** Every test hook's name starts so (AGENTRUN_SERVE_FAUX, AGENTRUN_SERVE_FAUX_WEB, ...), but the harness table's
9
14
  * (harness-table.ts HARNESS_TABLE_ENV), which withoutFaux drops by name, as it drops the resolved harness modules list
10
15
  * (HARNESS_MODULES_ENV) and recipes list (HARNESS_RECIPES_ENV). */
@@ -71,14 +76,21 @@ export declare function planWouldRun(env: NodeJS.ProcessEnv, harness: string): "
71
76
  /** `reason`, `harness`'s want of a key for its default model, with what a ChatGPT sign-in here would do about it
72
77
  * (planWouldRun), in words; as it was where the sign-in would not. */
73
78
  export declare function withPlanWords(env: NodeJS.ProcessEnv, harness: string, reason: string): string;
79
+ /** What a person does for a model on the Ollama here, ahead of ADD_A_KEY where one would run `harness` (ollamaWouldRun). */
80
+ export declare const START_OLLAMA = "start Ollama and pull a model with tools, or ";
81
+ /** Whether a model of the Ollama here would give `harness` its model: this server asks one (asksOllama, at an OLLAMA_HOST
82
+ * it takes: its operator's, or the default address server.ts hands its own env and its runner's on one owner's own machine
83
+ * alone, ollamaHostOf), and `harness` runs its models (pi; an adapter runs its wire's vendor's alone). A shared server with
84
+ * no OLLAMA_HOST never asks the default, so an Ollama started there gives no run: its words name a key alone. */
85
+ export declare const ollamaWouldRun: (env: NodeJS.ProcessEnv, harness: string) => boolean;
74
86
  /** Whether `harness` runs the model `id` (its entry in the harness table: harness-table.ts): pi any; one on an adapter, its
75
87
  * wire's vendor's model (or that vendor's on OpenRouter), or behind serve's gateway, on the wire it serves, any id. */
76
88
  export declare const harnessRuns: (env: NodeJS.ProcessEnv, id: string, harness: string) => boolean;
77
89
  /** The model a revision that names none runs on with `harness`, for `tier`: the tier's own variable, else AGENT_MODEL,
78
90
  * each only when `harness` runs it (harnessRuns; one it can't is skipped, never an error), else that of the first of
79
91
  * MODEL_KEYS whose key is here (a placeholder behind a base URL counts) and that `harness` runs on, else, in a run's
80
- * process that holds none of those keys, the one the server's keys gave it (DEFAULT_MODEL_ENV). Undefined when none is:
81
- * the harness has no default here. */
92
+ * process that holds none of those keys, the one the server's keys gave it (DEFAULT_MODEL_ENV), else, on pi, the first
93
+ * model of the Ollama here that calls tools (localDefault). Undefined when none is: the harness has no default here. */
82
94
  export declare function hostModel(env: NodeJS.ProcessEnv, tier?: Tier, harness?: string): string | undefined;
83
95
  /** `route_prefix`: the routing prefix this server puts before a gateway's model ids (MODEL_PROVIDER), which a reader takes off
84
96
  * to show the gateway's own id; null with any other source. */
@@ -223,8 +235,12 @@ export declare const anthropicRefusal: (models: {
223
235
  * requests (a hosted search, a learned node) and a grade, and the readiness chooseModel reports. A base gatewayBase
224
236
  * refuses (one a key may not go to) refuses Anthropic's route alone: its provider keeps its models, with no key, so
225
237
  * none of their requests is sent anywhere, and carries the refusal's words (anthropicRefusal), which chooseModel gives
226
- * for an Anthropic model; every other provider runs as it does without the setting. Never throws. */
227
- export declare function providerModels(env: NodeJS.ProcessEnv): Promise<import("@earendil-works/pi-ai").MutableModels>;
238
+ * for an Anthropic model; every other provider runs as it does without the setting. Never throws.
239
+ * `ollama`: the Ollama tags a run names (ollamaTagsOf), each resolved alone (withOllamaModels), for a run that never waits
240
+ * on a whole listing; without it, the Ollama here's whole listing (a picker's, capabilities'). */
241
+ export declare function providerModels(env: NodeJS.ProcessEnv, { ollama }?: {
242
+ ollama?: readonly string[];
243
+ }): Promise<import("@earendil-works/pi-ai").MutableModels>;
228
244
  export type Listed = {
229
245
  provider: string;
230
246
  cost: ModelCost;
package/dist/model.js CHANGED
@@ -17,8 +17,14 @@ import { modelWire, WIRES, wireOf } from "./wires.js";
17
17
  import { authContextOf } from "./secrets.js";
18
18
  import { EXPIRED, PLAN_DEFAULT_MODEL, PLAN_ORIGIN, PLAN_PROVIDER, planOf, signedIn, SIGNED_OUT } from "./chatgpt-plan.js";
19
19
  import { LOGIN_DEFAULT_MODEL, onClaudeLogin } from "./claude-login.js";
20
+ import { OLLAMA_PROVIDER, ollamaBase, ollamaHostRefused, ollamaModels, ollamaProvider, ollamaRelisted, ollamaShown, ollamaToolsModel } from "./ollama-provider.js";
20
21
  /** The child's environment names the faux module by absolute path. */
21
22
  export const FAUX_ENV = "AGENTRUN_SERVE_FAUX";
23
+ /** The Ollama tags among a run's models (`ollama/<tag>`): what providerModels resolves for it, one /api/show each. */
24
+ export const ollamaTagsOf = (refs) => [...new Set([...refs].flatMap((ref) => (ref?.provider === OLLAMA_PROVIDER ? [ref.modelId] : [])))];
25
+ /** Whether the Ollama here is asked for its models under `env`: not under the faux model or a model gateway, which take
26
+ * every model. The one rule for listing (withOllamaModels), the host default (localDefault) and the server's refresh. */
27
+ export const asksOllama = (env) => !env[FAUX_ENV] && !env.AGENT_MODEL_BASE_URL;
22
28
  /** Every test hook's name starts so (AGENTRUN_SERVE_FAUX, AGENTRUN_SERVE_FAUX_WEB, ...), but the harness table's
23
29
  * (harness-table.ts HARNESS_TABLE_ENV), which withoutFaux drops by name, as it drops the resolved harness modules list
24
30
  * (HARNESS_MODULES_ENV) and recipes list (HARNESS_RECIPES_ENV). */
@@ -118,15 +124,27 @@ export function withPlanWords(env, harness, reason) {
118
124
  const words = state === "expired" ? "your ChatGPT sign-in expired: sign in again (Settings → Model keys)" : "or sign in with ChatGPT (Settings → Model keys) to run it on your ChatGPT plan";
119
125
  return `${reason.replace(/\.$/, "")}; ${words}.`;
120
126
  }
127
+ /** What a person does for a model on the Ollama here, ahead of ADD_A_KEY where one would run `harness` (ollamaWouldRun). */
128
+ export const START_OLLAMA = "start Ollama and pull a model with tools, or ";
129
+ /** Whether a model of the Ollama here would give `harness` its model: this server asks one (asksOllama, at an OLLAMA_HOST
130
+ * it takes: its operator's, or the default address server.ts hands its own env and its runner's on one owner's own machine
131
+ * alone, ollamaHostOf), and `harness` runs its models (pi; an adapter runs its wire's vendor's alone). A shared server with
132
+ * no OLLAMA_HOST never asks the default, so an Ollama started there gives no run: its words name a key alone. */
133
+ export const ollamaWouldRun = (env, harness) => asksOllama(env) && Boolean(env.OLLAMA_HOST?.trim()) && !ollamaHostRefused(env) && harnessRuns(env, `${OLLAMA_PROVIDER}/any`, harness);
121
134
  /** Whether `harness` runs the model `id` (its entry in the harness table: harness-table.ts): pi any; one on an adapter, its
122
135
  * wire's vendor's model (or that vendor's on OpenRouter), or behind serve's gateway, on the wire it serves, any id. */
123
136
  export const harnessRuns = (env, id, harness) => harnessOf(env, harness)?.runs(env, id) ?? true;
124
137
  /** The model a revision that names none runs on with `harness`, for `tier`: the tier's own variable, else AGENT_MODEL,
125
138
  * each only when `harness` runs it (harnessRuns; one it can't is skipped, never an error), else that of the first of
126
139
  * MODEL_KEYS whose key is here (a placeholder behind a base URL counts) and that `harness` runs on, else, in a run's
127
- * process that holds none of those keys, the one the server's keys gave it (DEFAULT_MODEL_ENV). Undefined when none is:
128
- * the harness has no default here. */
140
+ * process that holds none of those keys, the one the server's keys gave it (DEFAULT_MODEL_ENV), else, on pi, the first
141
+ * model of the Ollama here that calls tools (localDefault). Undefined when none is: the harness has no default here. */
129
142
  export function hostModel(env, tier = "default", harness = DEFAULT_HARNESS) {
143
+ return settingsModel(env, tier, harness) ?? localDefault(env, harness);
144
+ }
145
+ /** hostModel's choice from this host's own settings (a tier variable, AGENT_MODEL, the plan, Claude Code's login, a key,
146
+ * the server's default): undefined where none names one, and only then is the Ollama here asked (localDefault). */
147
+ function settingsModel(env, tier, harness) {
130
148
  for (const id of [env[TIER_ENV[tier]], env.AGENT_MODEL])
131
149
  if (id && harnessRuns(env, id, harness))
132
150
  return id;
@@ -139,6 +157,16 @@ export function hostModel(env, tier = "default", harness = DEFAULT_HARNESS) {
139
157
  const row = MODEL_KEYS.find((row) => env[row.field] && (row.harnesses.includes(harness) || keyHarnesses(row, env).includes(harness)));
140
158
  return row ? rowModel(row, harness, env) : env[DEFAULT_MODEL_ENV] || undefined;
141
159
  }
160
+ /** The default with no key held: the first model of the Ollama here that calls tools (ollama-provider.ts
161
+ * ollamaToolsModel, from its last listing, which chooseModel asks for first), where `harness` runs it (harnessRuns, its
162
+ * entry's facts: pi any model, an adapter its wire's vendor's alone); none behind a gateway or under the faux model. A
163
+ * model that takes no tools is never a default: a run on it would have none. */
164
+ function localDefault(env, harness) {
165
+ if (!asksOllama(env))
166
+ return undefined;
167
+ const model = ollamaToolsModel(env);
168
+ return model && harnessRuns(env, model, harness) ? model : undefined;
169
+ }
142
170
  /** The plan's model a run that names none takes: GPT-6.1 Sol where the plan lists it, else the plan's first. */
143
171
  const planModel = (env) => {
144
172
  const models = planOf(env)?.models ?? [];
@@ -207,10 +235,20 @@ export function llmTiers(nodes, tiers) {
207
235
  * when `ref` is absent (hostModel). A PinnedModel is the pin itself, never chosen again (pinnedChoice).
208
236
  */
209
237
  export async function chooseModel(env, ref, tier = "default", harness = DEFAULT_HARNESS) {
238
+ return choose(env, ref, tier, harness, false);
239
+ }
240
+ /** chooseModel, `relisted` once the Ollama here was listed again for the host's default (below): never a second time. */
241
+ async function choose(env, ref, tier, harness, relisted) {
210
242
  if (typeof ref === "object")
211
243
  return pinnedChoice(env, ref, tier, harness);
212
244
  if (env[FAUX_ENV])
213
245
  return { model: { provider: "faux", modelId: fauxModel(env, tier) } };
246
+ // A host whose own settings name no model reads its default from the Ollama here (hostModel's localDefault): its
247
+ // listing first (ollamaModels: kept while fresh, asked now where none is, and a stale one asked again behind this
248
+ // choice), so a tag it took is never the last listing's for good. A ref, a key, a default or a plan never waits on it.
249
+ const local = ref === undefined && settingsModel(env, tier, harness) === undefined && asksOllama(env);
250
+ if (local && !relisted)
251
+ await ollamaModels(env);
214
252
  const named = ref ?? hostModel(env, tier, harness);
215
253
  // In a person's words (a first run from npx sees them): what to add and where. Operator detail is the README's.
216
254
  const none = tier === "default" ? "No model yet" : `No model yet for this workflow's ${tier} tier`;
@@ -238,13 +276,20 @@ export async function chooseModel(env, ref, tier = "default", harness = DEFAULT_
238
276
  return { model: { provider: MODEL_PROVIDER, modelId: sent }, ...(id && slash > 0 ? { namedProvider: id.slice(0, slash) } : {}) };
239
277
  }
240
278
  if (!named)
241
- return { why: withPlanWords(env, harness, `${none}: ${ADD_A_KEY}`), host: true, needs: "key" };
279
+ return { why: withPlanWords(env, harness, `${none}: ${ollamaWouldRun(env, harness) ? START_OLLAMA : ""}${ADD_A_KEY}`), host: true, needs: "key" };
242
280
  const slash = named.indexOf("/");
243
281
  if (slash < 1)
244
282
  return { why: modelFormWhy(env, harness, named, ref === undefined), host: ref === undefined, needs: "model" };
245
283
  const [provider, modelId] = [named.slice(0, slash), named.slice(slash + 1)];
246
- const models = await providerModels(env);
284
+ const models = await providerModels(env, { ollama: provider === OLLAMA_PROVIDER ? [modelId] : [] });
247
285
  const model = models.getModel(provider, modelId);
286
+ // The host's Ollama default no longer answers (removed, or that Ollama restarted without it) past its listing's TTL:
287
+ // that listing is dropped and asked again now, and the default chosen once more from it (the next model that calls
288
+ // tools, else the no-model words). Once: a tag the fresh listing still names and /api/show refuses is said as it is.
289
+ if (!model && local && !relisted) {
290
+ await ollamaRelisted(env);
291
+ return choose(env, ref, tier, harness, true);
292
+ }
248
293
  if (!model)
249
294
  return { why: modelFormWhy(env, harness, named, ref === undefined), host: ref === undefined, needs: "model" };
250
295
  // A gateway ANTHROPIC_BASE_URL names that a key may not go to (gatewayBase): no Anthropic model runs, by its words.
@@ -388,7 +433,7 @@ export async function runModels(env, ref, tiers = ["default"], harness = DEFAULT
388
433
  // Each provider's key from `env`, which holds this process's secrets, never from process.env (secrets.ts); Anthropic's
389
434
  // at ANTHROPIC_BASE_URL when set (providerModels). pi-ai's providers price their own models, but for OpenRouter's
390
435
  // routers, whose catalog zeros are no price (routersOf).
391
- return { models: withRequestKeys(await providerModels(env), env), model, byTier, unpriced: routersOf(byTier.values()) };
436
+ return { models: withRequestKeys(await providerModels(env, { ollama: ollamaTagsOf(byTier.values()) }), env), model, byTier, unpriced: routersOf(byTier.values()) };
392
437
  }
393
438
  const ids = [...new Set([...byTier.values()].map((m) => m.modelId))];
394
439
  const models = createModels({ authContext: authContextOf(env) });
@@ -556,7 +601,7 @@ export async function wireModels(entry, env, ref) {
556
601
  throw new Error(`${entry.id} does not run here.`);
557
602
  if ("why" in choice)
558
603
  throw new Error(choice.why);
559
- return { models: await providerModels(env), model: choice.model, byTier: new Map([["default", choice.model]]), unpriced: routersOf([choice.model]) };
604
+ return { models: await providerModels(env, { ollama: ollamaTagsOf([choice.model]) }), model: choice.model, byTier: new Map([["default", choice.model]]), unpriced: routersOf([choice.model]) };
560
605
  }
561
606
  /** The ids of `models` that are OpenRouter's routers (local-models.ts isRouter): pi-ai's catalog lists each at $0, the
562
607
  * price of no model, so serve has none for them. */
@@ -621,11 +666,13 @@ export const anthropicRefusal = (models) => models.getProvider("anthropic")?.[RE
621
666
  * requests (a hosted search, a learned node) and a grade, and the readiness chooseModel reports. A base gatewayBase
622
667
  * refuses (one a key may not go to) refuses Anthropic's route alone: its provider keeps its models, with no key, so
623
668
  * none of their requests is sent anywhere, and carries the refusal's words (anthropicRefusal), which chooseModel gives
624
- * for an Anthropic model; every other provider runs as it does without the setting. Never throws. */
625
- export async function providerModels(env) {
669
+ * for an Anthropic model; every other provider runs as it does without the setting. Never throws.
670
+ * `ollama`: the Ollama tags a run names (ollamaTagsOf), each resolved alone (withOllamaModels), for a run that never waits
671
+ * on a whole listing; without it, the Ollama here's whole listing (a picker's, capabilities'). */
672
+ export async function providerModels(env, { ollama } = {}) {
626
673
  const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
627
674
  // With the prices serve sets over pi-ai's catalog (local-models.ts): OpenRouter's particle-1 at its list price.
628
- const models = await withPlanModels(withLocalModels(builtinModels({ authContext: authContextOf(env) })), env);
675
+ const models = await withOllamaModels(await withPlanModels(withLocalModels(builtinModels({ authContext: authContextOf(env) })), env), env, ollama);
629
676
  if (!env.ANTHROPIC_BASE_URL)
630
677
  return models;
631
678
  const [{ createProvider }, { anthropicMessagesApi }] = await Promise.all([import("@earendil-works/pi-ai/models"), import("@earendil-works/pi-ai/api/anthropic-messages.lazy")]);
@@ -674,6 +721,18 @@ async function withPlanModels(models, env) {
674
721
  }));
675
722
  return models;
676
723
  }
724
+ /** `models` with the Ollama `env` names (OLLAMA_HOST, read from `env` itself, never through the auth context: it is no
725
+ * secret), its chat models listed live (ollama-provider.ts ollamaModels): provider `ollama`, keyless, at $0. None where
726
+ * it is down, hung or refused, and nothing thrown. None asked under the faux model or a gateway (asksOllama). `tags`:
727
+ * those models alone, each from the kept listing or its own /api/show (ollamaShown), never /api/tags; none, nothing asked. */
728
+ async function withOllamaModels(models, env, tags) {
729
+ if (!asksOllama(env))
730
+ return models;
731
+ const listed = tags === undefined ? await ollamaModels(env) : (await Promise.all(tags.map((tag) => ollamaShown(env, tag)))).filter((model) => model !== undefined);
732
+ if (listed.length)
733
+ models.setProvider(ollamaProvider(ollamaBase(env), listed, env));
734
+ return models;
735
+ }
677
736
  /** `models` with each request's `env` option carrying the REQUEST_KEYS that `env` holds (a run's process holds only
678
737
  * those of its model's provider), so Bedrock's request finds its AWS keys there: in no environment, which would hand
679
738
  * them to every program the run starts. A request's own `env` wins. With none held, `models` as it is. */
@@ -1,4 +1,4 @@
1
- import type { Session } from '../import-sources.js';
1
+ import type { Session } from '@parcha/agentrun-import';
2
2
  import type { Store, ImportRunInput } from '../store/store.js';
3
3
  import type { NativeRuntime } from './types.js';
4
4
  export type RemoteHistorySession = Pick<Session, 'source' | 'id' | 'startedAt' | 'endedAt' | 'state' | 'model' | 'costUsd' | 'firstPrompt' | 'activeMs' | 'turns'>;
@@ -70,8 +70,8 @@ function turnOf(value, now) {
70
70
  let usage;
71
71
  if (t.usage !== undefined) {
72
72
  const u = record(t.usage);
73
- keys(u, ['input', 'output', 'cacheRead', 'cacheWrite', 'cacheWrite1h']);
74
- usage = { input: count(u.input), output: count(u.output), cacheRead: count(u.cacheRead), cacheWrite: count(u.cacheWrite), ...(u.cacheWrite1h === undefined ? {} : { cacheWrite1h: count(u.cacheWrite1h) }) };
73
+ keys(u, ['input', 'output', 'cacheRead', 'cacheWrite', 'cacheWrite1h', 'reasoning']);
74
+ usage = { input: count(u.input), output: count(u.output), cacheRead: count(u.cacheRead), cacheWrite: count(u.cacheWrite), ...(u.cacheWrite1h === undefined ? {} : { cacheWrite1h: count(u.cacheWrite1h) }), ...(u.reasoning === undefined ? {} : { reasoning: count(u.reasoning) }) };
75
75
  }
76
76
  const rest = Object.fromEntries(['key', 'model', 'effort', 'error'].flatMap(key => t[key] === undefined ? [] : [[key, text(t[key], key === 'error' ? 4096 : 1024)]]));
77
77
  return { ...base, role, calls, ...rest, ...(usage ? { usage } : {}), ...(t.costUsd === undefined ? {} : { costUsd: number(t.costUsd, 1e9) }) };
@@ -0,0 +1,92 @@
1
+ import { type Model, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
2
+ /** The provider's id, the prefix of its models' refs (`ollama/<tag>`). */
3
+ export declare const OLLAMA_PROVIDER = "ollama";
4
+ /** The api its models name: Ollama's own chat API, neither Responses nor Messages, so the runner's route translates it. */
5
+ export declare const OLLAMA_API = "ollama-chat";
6
+ /** The most context a request asks Ollama for (options.num_ctx), and so the most window a model has here: 64k. */
7
+ export declare const OLLAMA_NUM_CTX = 65536;
8
+ /** How long a listing may take, all of it: a stuck Ollama costs a caller this once per OLLAMA_TTL_MS at most. */
9
+ export declare const OLLAMA_LIST_TIMEOUT_MS = 2000;
10
+ /** How long an address's listing is kept before it is asked again (behind the caller, which takes the kept one). */
11
+ export declare const OLLAMA_TTL_MS = 30000;
12
+ /** A model as Ollama lists it: its tag, its capabilities, and the context it was trained on (undefined: /api/show says none). */
13
+ export type OllamaListed = {
14
+ readonly name: string;
15
+ readonly capabilities: readonly string[];
16
+ readonly trained: number | undefined;
17
+ };
18
+ /**
19
+ * The base URL OLLAMA_HOST names, as the ollama CLI reads it (envconfig.Host): unset, this machine on 11434; with no
20
+ * scheme, http; with no port, 11434 with no scheme and the scheme's own with one (https: 443); a path kept. `0.0.0.0` and
21
+ * `::`, where `ollama serve` listens on every address, connect to this machine. Then the one base rule (provider.ts
22
+ * gatewayBase): plain http only to this machine, no user, query or fragment. Throws, naming OLLAMA_HOST, when refused.
23
+ */
24
+ export declare function ollamaBase(env: NodeJS.ProcessEnv): string;
25
+ /** A test's clock for the kept listings, so it ages them without waiting; with none, Date.now again. */
26
+ export declare function ollamaClock(clock?: () => number): void;
27
+ /** The listing under way for the Ollama `env` names (one a stale answer started behind its caller), or undefined: for a
28
+ * test to await what a refresh brings. */
29
+ export declare function ollamaAsking(env: NodeJS.ProcessEnv): Promise<readonly OllamaListed[]> | undefined;
30
+ /** A test process's switch, read from its own environment (process.env), never from the `env` a caller passes: set, no
31
+ * Ollama is asked, whatever address that `env` names or leaves to the default. A test hook's name (model.ts FAUX_PREFIX),
32
+ * so a server never hands it on to its runs. The test suites set it (test/support.mjs); a test of Ollama clears it. */
33
+ export declare const OLLAMA_OFF_ENV = "AGENTRUN_SERVE_FAUX_NO_OLLAMA";
34
+ /** Ollama's own default address (ollamaBase of an unset OLLAMA_HOST). */
35
+ export declare const OLLAMA_DEFAULT_HOST = "127.0.0.1:11434";
36
+ /**
37
+ * The OLLAMA_HOST a server asks, and hands the runner beside it: the one its environment sets, else Ollama's default
38
+ * address on one owner's own server on their own machine (`ownMachine`: server.ts whyNotOwnMachine, the rule
39
+ * --harness-sign-in starts under), else none. On a shared server, whatever answers on this machine's 11434 is no model of
40
+ * the people who start runs there, so it is asked only where its operator names it.
41
+ */
42
+ export declare function ollamaHostOf(env: NodeJS.ProcessEnv, ownMachine: boolean): string | undefined;
43
+ /** Why the OLLAMA_HOST `env` names is refused (ollamaBase's words, which never hold its value), or undefined. */
44
+ export declare function ollamaHostRefused(env: NodeJS.ProcessEnv): string | undefined;
45
+ /**
46
+ * The models the Ollama `env` names has, asked now: its tags (/api/tags), each one's capabilities and trained context
47
+ * (/api/show), in the order Ollama lists them. All of it within `timeoutMs`, with no redirect followed; a refused
48
+ * OLLAMA_HOST, a down or hung Ollama, or an answer of the wrong shape lists none, and nothing is thrown. A model /api/show
49
+ * does not answer for, before the deadline included, is left out and the others kept; so is a cloud model (remote_host or
50
+ * remote_model, in either answer). The answer is kept for its address (ollamaModels, ollamaKept). `fetch`: a test's.
51
+ */
52
+ export declare function listOllama(env: NodeJS.ProcessEnv, { fetch: send, timeoutMs }?: {
53
+ fetch?: typeof fetch;
54
+ timeoutMs?: number;
55
+ }): Promise<readonly OllamaListed[]>;
56
+ /** How long a run gives the /api/show of the one Ollama model it names (ollamaShown): longer than a listing's, since the
57
+ * run cannot start without it and Ollama may be loading another model. */
58
+ export declare const OLLAMA_SHOW_TIMEOUT_MS = 10000;
59
+ /** Model `tag` of the Ollama `env` names, for a run that names it (`ollama/<tag>`): from its address's kept listing while
60
+ * that is fresh (OLLAMA_TTL_MS), else its own /api/show within `timeoutMs`, never /api/tags, so a run never waits on a
61
+ * whole listing and never runs on a model's context from before it was pulled again. Undefined where it is not there,
62
+ * does not answer, is a cloud model or OLLAMA_HOST is refused. Nothing kept: the listing is the kept one. */
63
+ export declare function ollamaShown(env: NodeJS.ProcessEnv, tag: string, { fetch: send, timeoutMs }?: {
64
+ fetch?: typeof fetch;
65
+ timeoutMs?: number;
66
+ }): Promise<OllamaListed | undefined>;
67
+ /** The models the Ollama `env` names has: its address's kept listing while fresh; a stale one at once, asked again behind
68
+ * the caller; none kept, asked now (listOllama). One listing per address at a time. */
69
+ export declare function ollamaModels(env: NodeJS.ProcessEnv): Promise<readonly OllamaListed[]>;
70
+ /** The models the Ollama `env` names has, asked again now: its kept listing dropped first, so a tag removed since it was
71
+ * kept is gone from the answer (model.ts chooseModel, once the host's default no longer answers). A listing already
72
+ * under way for the address is awaited, never doubled. */
73
+ export declare function ollamaRelisted(env: NodeJS.ProcessEnv): Promise<readonly OllamaListed[]>;
74
+ /** The models the Ollama `env` names had when last asked (ollamaModels): none where it was never asked. Synchronous, for
75
+ * the host's default model (model.ts hostModel), which a listing primes before it is read. */
76
+ export declare function ollamaKept(env: NodeJS.ProcessEnv): readonly OllamaListed[];
77
+ /** `env`'s Ollama listing as last kept (ollamaKept), in one string: each model's tag, capabilities and trained context.
78
+ * A server compares it to see a model pulled, removed or an Ollama started since it made its offers (server.ts). */
79
+ export declare const ollamaListing: (env: NodeJS.ProcessEnv) => string;
80
+ /** The context a request on `model` asks for, and its window here: its trained context up to OLLAMA_NUM_CTX (which a model
81
+ * /api/show names none for gets), and never above the OLLAMA_CONTEXT_LENGTH `env` sets. */
82
+ export declare const contextOf: (model: Pick<OllamaListed, "trained">, env: NodeJS.ProcessEnv) => number;
83
+ /** The models of `env`'s Ollama that chat and call tools, as refs (`ollama/<tag>`), from its kept listing (ollamaKept),
84
+ * in its order: the ones a run of pi has tools on. */
85
+ export declare function ollamaToolsModels(env: NodeJS.ProcessEnv): string[];
86
+ /** The first of ollamaToolsModels; undefined where none calls tools. */
87
+ export declare const ollamaToolsModel: (env: NodeJS.ProcessEnv) => string | undefined;
88
+ /** The provider of `listed` (its chat models) at `base`: keyless, $0, each model's window its context (contextOf). */
89
+ export declare function ollamaProvider(base: string, listed: readonly OllamaListed[], env: NodeJS.ProcessEnv): import("@earendil-works/pi-ai").Provider<"ollama-chat">;
90
+ /** `context` as /api/chat's body for `model`: the current system prompt first, each message in Ollama's shape (a call's
91
+ * arguments an object, a result `tool` with the tool's name, images as base64), and the current tools in its `tools`. */
92
+ export declare function chatBody(model: Model<string>, context: TranscriptContext, options: SimpleStreamOptions | undefined): Record<string, unknown>;