@ultimat3/ai 31.46.0 → 31.47.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.
package/README.md CHANGED
@@ -18,7 +18,16 @@ import {
18
18
  providerGateway,
19
19
  openAiProvider,
20
20
  registerModel,
21
+ type GatewayCache,
21
22
  } from '@ultimat3/ai';
23
+ import { type Actor } from '@ultimat3/core';
24
+
25
+ declare const memoCache: GatewayCache;
26
+
27
+ declare const ticket: { readonly body: string };
28
+ declare const env: { readonly LLM_TOKEN: string; readonly LLM_URL: string };
29
+
30
+ declare const actor: Actor;
22
31
 
23
32
  // 1. Your models: your ids, your contract's prices (integer minor units), the source you read them from.
24
33
  registerModel({
@@ -171,6 +180,15 @@ transport by itself above the ceiling and returns the assembled result — the l
171
180
  the transport, so it is not one the caller has to change API for.
172
181
 
173
182
  ```ts
183
+ import { type Gateway, type ProjectableAction, runLlmToolCall } from '@ultimat3/ai';
184
+ import { type Actor } from '@ultimat3/core';
185
+
186
+ declare const ai: Gateway;
187
+ declare const messages: Parameters<Gateway['stream']>[0]['messages'];
188
+ declare const tools: readonly ProjectableAction[];
189
+ declare const actor: Actor;
190
+ declare function debit(cost: unknown): void;
191
+
174
192
  for await (const chunk of ai.stream({ messages, maxTokens: 64_000 })) {
175
193
  if (chunk.type === 'text') process.stdout.write(chunk.text);
176
194
  if (chunk.type === 'tool-call') await runLlmToolCall(tools, chunk.call, actor);
@@ -194,6 +212,8 @@ uses; `baseUrl` selects the provider. `hashEmbedder()` is the deterministic offl
194
212
  and the test suite run on.
195
213
 
196
214
  ```ts
215
+ import { remoteEmbedder } from '@ultimat3/ai';
216
+
197
217
  const embedder = remoteEmbedder({ name: 'voyage-3', dimension: 1_024 }); // EMBEDDINGS_API_KEY
198
218
  ```
199
219
 
@@ -209,6 +229,10 @@ half-written at the wrong width has no error to report, only worse answers.
209
229
  Vertex, a fine-tune, a negotiated rate — all expressible, none needing a fork.
210
230
 
211
231
  ```ts
232
+ import { type Provider, providerGateway, registerModel } from '@ultimat3/ai';
233
+
234
+ declare const InternalGatewayProvider: new () => Provider;
235
+
212
236
  registerModel({
213
237
  id: 'llama-internal-70b',
214
238
  contextWindow: 128_000,
@@ -360,8 +384,22 @@ Not a ninth primitive. A model call has an input schema, an output schema and a
360
384
  is an `action` — so `llm()` returns one, and everything an action projects, it projects.
361
385
 
362
386
  ```ts
363
- import { llm, t } from '@ultimat3/ai';
387
+ import { llm, type Prompt, t } from '@ultimat3/ai';
364
388
  import { can } from '@ultimat3/policy';
389
+ import { toolFrom } from '@ultimat3/mcp';
390
+
391
+ declare module '@ultimat3/core' {
392
+ interface CtxServices {
393
+ readonly posts: {
394
+ publish(id: string, tx?: unknown): Promise<{ id: string; orgId: string; title: string }>;
395
+ like(id: string): Promise<{ likeCount: number; likedByMe: boolean }>;
396
+ body(id: string): Promise<string>;
397
+ };
398
+ }
399
+ }
400
+
401
+ declare const summarizePrompt: Prompt<{ body: string }>;
402
+ const HOUSE_LARGE = 'house-large';
365
403
 
366
404
  export const summarize = llm({
367
405
  model: HOUSE_LARGE, // imported from your models.ts
@@ -392,6 +430,17 @@ summarize.contract(); // the contract tests
392
430
  ### Streaming is the same action
393
431
 
394
432
  ```ts
433
+ import { type LlmAction, t } from '@ultimat3/ai';
434
+ import { type Ctx } from '@ultimat3/core';
435
+
436
+ const SummarizeInput = t.object({ postId: t.uuid });
437
+ const Summary = t.object({ summary: t.string, tags: t.array(t.string) });
438
+ declare const summarize: LlmAction<typeof SummarizeInput, typeof Summary>;
439
+ declare const ctx: Ctx;
440
+ declare const postId: string;
441
+ declare function write(text: string): void;
442
+ declare function save(value: { summary: string; tags: string[] }): void;
443
+
395
444
  for await (const chunk of summarize.stream({ postId }, { ctx })) {
396
445
  if (chunk.type === 'text') write(chunk.text);
397
446
  if (chunk.type === 'done') save(chunk.value); // validated against `output`
@@ -425,6 +474,15 @@ The second half of "no ninth primitive": a tool-using run is still one server-au
425
474
  operation with an input schema, an output schema and a policy.
426
475
 
427
476
  ```ts
477
+ import { type Action } from '@ultimat3/action';
478
+ import { agent, type Prompt, t } from '@ultimat3/ai';
479
+ import { can } from '@ultimat3/policy';
480
+
481
+ declare const supportPrompt: Prompt<{ orderId: string }>;
482
+ declare const lookupOrder: Action;
483
+ declare const issueRefund: Action;
484
+ declare const progress: unknown[];
485
+
428
486
  export const support = agent({
429
487
  input: t.object({ orderId: t.string }),
430
488
  output: t.object({ answer: t.string }),
@@ -435,7 +493,7 @@ export const support = agent({
435
493
  maxToolResultChars: 4_000,
436
494
  budget: { tokensPerRun: 200_000, costPerCall: { minor: 50, currency: 'USD' } },
437
495
  policy: can('order:support'),
438
- onTurn: ({ turn, toolCalls, cost }) => progress.push({ turn, toolCalls, cost }),
496
+ onTurn: ({ turn, toolCalls, cost }) => { progress.push({ turn, toolCalls, cost }); },
439
497
  });
440
498
  ```
441
499
 
@@ -845,6 +903,10 @@ runs — and the redactor sits on both, between the row and a third-party endpoi
845
903
  `vars()` alone until 2026-09-23, so an agent's tool results left the process unredacted.
846
904
 
847
905
  ```ts
906
+ import { configureAi } from '@ultimat3/ai';
907
+
908
+ declare function scrubPatientIdentifiers(text: string): string;
909
+
848
910
  configureAi({ redact: (text) => scrubPatientIdentifiers(text) });
849
911
  ```
850
912
 
@@ -864,6 +926,10 @@ long before a provider exists. One way in (31.0.0): `aiGateway` in `apps/<app>/r
864
926
 
865
927
  ```ts
866
928
  // apps/web/runtime.ts
929
+ import { type Provider, providerGateway } from '@ultimat3/ai';
930
+
931
+ declare const yourProvider: Provider;
932
+
867
933
  export const runtime = {
868
934
  aiGateway: providerGateway({ providers: [yourProvider], defaultModel: 'house-large' }),
869
935
  };
@@ -929,6 +995,13 @@ export const summarizeEval = defineEval({
929
995
 
930
996
  ```ts
931
997
  // app/support/summarize.eval.test.ts — the suite `x verify` runs
998
+ import { test } from 'bun:test';
999
+ import { type Gateway } from '@ultimat3/ai';
1000
+
1001
+ declare const summarizeEval: { assert(gateway: Gateway): Promise<void> };
1002
+
1003
+ declare const ai: Gateway;
1004
+
932
1005
  test('summarize holds its recorded scores', async () => {
933
1006
  await summarizeEval.assert(ai); // throws X_EVAL_THRESHOLD on a drop past 0.05
934
1007
  });
@@ -1000,6 +1073,8 @@ baseline is the same file, keyed by the agent's prompt hash. Exported types: `Ag
1000
1073
  ## Prompts are versioned artifacts
1001
1074
 
1002
1075
  ```ts
1076
+ import { definePrompt } from '@ultimat3/ai';
1077
+
1003
1078
  export const summarize = definePrompt<{ ticket: string }>({
1004
1079
  id: 'summarize',
1005
1080
  version: '1.0.0',
@@ -1061,6 +1136,18 @@ is still `ctx.actor` and tools are still matched against the declaration.
1061
1136
  ## Retrieval
1062
1137
 
1063
1138
  ```ts
1139
+ import {
1140
+ assembleContext,
1141
+ type Embedder,
1142
+ indexDocument,
1143
+ postgresVectorStore,
1144
+ retrieve,
1145
+ } from '@ultimat3/ai';
1146
+
1147
+ declare const embedder: Embedder;
1148
+ declare const text: string;
1149
+ declare const query: string;
1150
+
1064
1151
  const store = postgresVectorStore({ name: 'doc_chunks', dimension: 256 }); // memoryVectorStore() in dev
1065
1152
  await indexDocument({ store, embedder, document: { id: 'faq', text } });
1066
1153
 
@@ -1090,6 +1177,12 @@ then `x db migrate`.
1090
1177
  ### The scope is the leak-proofing
1091
1178
 
1092
1179
  ```ts
1180
+ import { type VectorStore } from '@ultimat3/ai';
1181
+
1182
+ declare const store: VectorStore;
1183
+
1184
+ declare const orgId: string;
1185
+
1093
1186
  const tenantStore = store.scoped({ tenant: orgId, allow: { visibility: ['public', 'internal'] } });
1094
1187
  ```
1095
1188
 
@@ -1125,6 +1218,15 @@ any `source` the caller passed, because `indexDocument` prunes a re-index by it.
1125
1218
 
1126
1219
  ```ts
1127
1220
  // `ProjectableAction` — `{ name, mcp?, inputJsonSchema?, run }`, the projection SEAM.
1221
+ import { type LlmToolCall, runLlmToolCall, toLlmTools, type ProjectableAction } from '@ultimat3/ai';
1222
+ import { type Actor } from '@ultimat3/core';
1223
+
1224
+ declare const publishPost: ProjectableAction;
1225
+ declare const suspendUser: ProjectableAction;
1226
+ declare const actions: readonly ProjectableAction[];
1227
+ declare const call: LlmToolCall;
1228
+ declare const actor: Actor;
1229
+
1128
1230
  const tools = toLlmTools([publishPost, suspendUser]); // only those with mcp.expose
1129
1231
  const result = await runLlmToolCall(actions, call, actor);
1130
1232
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/ai",
3
- "version": "31.46.0",
3
+ "version": "31.47.1",
4
4
  "description": "LLM gateway, versioned prompts, evals as tests, embeddings, hybrid vector search, RAG",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -45,17 +45,17 @@
45
45
  "test": "bun test"
46
46
  },
47
47
  "dependencies": {
48
- "@ultimat3/action": "31.46.0",
49
- "@ultimat3/cache": "31.46.0",
50
- "@ultimat3/core": "31.46.0",
51
- "@ultimat3/db": "31.46.0",
52
- "@ultimat3/http": "31.46.0",
53
- "@ultimat3/jobs": "31.46.0",
54
- "@ultimat3/money": "31.46.0",
55
- "@ultimat3/schema": "31.46.0",
56
- "@ultimat3/time": "31.46.0"
48
+ "@ultimat3/action": "31.47.1",
49
+ "@ultimat3/cache": "31.47.1",
50
+ "@ultimat3/core": "31.47.1",
51
+ "@ultimat3/db": "31.47.1",
52
+ "@ultimat3/http": "31.47.1",
53
+ "@ultimat3/jobs": "31.47.1",
54
+ "@ultimat3/money": "31.47.1",
55
+ "@ultimat3/schema": "31.47.1",
56
+ "@ultimat3/time": "31.47.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@ultimat3/policy": "31.46.0"
59
+ "@ultimat3/policy": "31.47.1"
60
60
  }
61
61
  }
package/src/llm-cache.ts CHANGED
@@ -52,8 +52,8 @@ export interface LlmSemanticCache<TParsed> {
52
52
 
53
53
  export interface LlmCache<TParsed> {
54
54
  readonly semantic: LlmSemanticCache<TParsed>;
55
- // `05-caching.md` also declares `invalidates: [tag.post]` here. It is deliberately absent
56
- // until `@ultimat3/cache`'s fan-out can reach something that is not a `CacheTier`: storing
55
+ // No `invalidates: [tag.post]` here. It is deliberately absent until
56
+ // `@ultimat3/cache`'s fan-out can reach something that is not a `CacheTier`: storing
57
57
  // tags that the ONE invalidation path never visits would read as wired and silently not be.
58
58
  // Today the invalidation story is the prompt version (a bump reaches a different store) and
59
59
  // `ttl`.
@@ -4,7 +4,7 @@
4
4
  // The keys are the WIRE's own names (`top_p`, `service_tier`), never a translated set: a body builder
5
5
  // spreads a screened bag as it stands, the way it passes a content block through.
6
6
 
7
- import { renderCauseValue } from '@ultimat3/core';
7
+ import { isJsonObject, renderCauseValue } from '@ultimat3/core';
8
8
  import { AiRequestInvalidError } from './errors';
9
9
  import type { SamplingWire } from './sampling';
10
10
 
@@ -70,9 +70,6 @@ export const PROVIDER_OPTION_KEYS: { readonly [W in SamplingWire]: readonly stri
70
70
  openai: Object.keys(RULES.openai).sort(),
71
71
  };
72
72
 
73
- const isRecord = (value: unknown): value is Record<string, unknown> =>
74
- typeof value === 'object' && value !== null && !Array.isArray(value);
75
-
76
73
  const refuse = (detail: string, fix: string): never => {
77
74
  throw new AiRequestInvalidError({ detail, fix });
78
75
  };
@@ -117,7 +114,7 @@ function screenFields(
117
114
  fields: Readonly<Record<string, Rule>>,
118
115
  bag: unknown,
119
116
  ): void {
120
- if (!isRecord(bag)) {
117
+ if (!isJsonObject(bag)) {
121
118
  refuse(
122
119
  `providerOptions.${path} is ${renderCauseValue(bag)}; it must be an object`,
123
120
  FIX(wire, key),
@@ -147,7 +144,7 @@ function screenFields(
147
144
  */
148
145
  export function screenProviderOptions(options: unknown): void {
149
146
  if (options === undefined) return;
150
- if (!isRecord(options)) {
147
+ if (!isJsonObject(options)) {
151
148
  refuse(
152
149
  `providerOptions is ${renderCauseValue(options)}; it must be an object keyed by wire format`,
153
150
  `providerOptions: { openai: { top_p: 0.9 } } # keyed by ${WIRES.join(', ')}`,