@ljoukov/llm 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,8 @@ Unified TypeScript wrapper over:
9
9
 
10
10
  - **OpenAI Responses API** (`openai`)
11
11
  - **Google Gemini via Vertex AI** (`@google/genai`)
12
- - **ChatGPT subscription models** via `chatgpt-*` model ids (requires `CHATGPT_AUTH_JSON_B64`)
12
+ - **Fireworks chat-completions models** (`kimi-k2.5`, `glm-5`, `minimax-m2.1`)
13
+ - **ChatGPT subscription models** via `chatgpt-*` model ids (reuses Codex auth store, or a token provider)
13
14
 
14
15
  Designed around a single streaming API that yields:
15
16
 
@@ -69,12 +70,27 @@ If deploying to Cloudflare Workers/Pages:
69
70
  jq -c . < path/to/service-account.json | wrangler secret put GOOGLE_SERVICE_ACCOUNT_JSON
70
71
  ```
71
72
 
73
+ ### Fireworks
74
+
75
+ - `FIREWORKS_TOKEN` (or `FIREWORKS_API_KEY`)
76
+
72
77
  ### ChatGPT subscription models
73
78
 
74
- - `CHATGPT_AUTH_JSON_B64`
79
+ By default, `chatgpt-*` models reuse the ChatGPT OAuth tokens stored by the Codex CLI:
80
+
81
+ - `${CODEX_HOME:-~/.codex}/auth.json`
82
+
83
+ If you deploy to multiple environments (Vercel, GCP, local dev, etc.), use a centralized HTTPS token provider that owns
84
+ refresh-token rotation and serves short-lived access tokens.
75
85
 
76
- This is a base64url-encoded JSON blob containing the ChatGPT OAuth tokens + account id (RFC 4648):
77
- https://www.rfc-editor.org/rfc/rfc4648
86
+ - `CHATGPT_AUTH_TOKEN_PROVIDER_URL` (example: `https://chatgpt-auth.<your-domain>`)
87
+ - `CHATGPT_AUTH_API_KEY` (shared secret; sent as `Authorization: Bearer ...` and `x-chatgpt-auth: ...`)
88
+ - `CHATGPT_AUTH_TOKEN_PROVIDER_STORE` (`kv` or `d1`, defaults to `kv`)
89
+
90
+ This repo includes a Cloudflare Workers token provider implementation in `workers/chatgpt-auth/`.
91
+
92
+ If `CHATGPT_AUTH_TOKEN_PROVIDER_URL` + `CHATGPT_AUTH_API_KEY` are set, `chatgpt-*` models will fetch tokens from the
93
+ token provider and will not read the local Codex auth store.
78
94
 
79
95
  ## Usage
80
96
 
@@ -245,6 +261,21 @@ const result = await generateText({
245
261
  console.log(result.text);
246
262
  ```
247
263
 
264
+ ### Fireworks
265
+
266
+ Use Fireworks model ids directly (for example `kimi-k2.5`, `glm-5`, `minimax-m2.1`):
267
+
268
+ ```ts
269
+ import { generateText } from "@ljoukov/llm";
270
+
271
+ const result = await generateText({
272
+ model: "kimi-k2.5",
273
+ input: "Return exactly: OK",
274
+ });
275
+
276
+ console.log(result.text);
277
+ ```
278
+
248
279
  ### ChatGPT subscription models
249
280
 
250
281
  Use a `chatgpt-` prefix:
@@ -348,14 +379,21 @@ const { value } = await generateJson({
348
379
 
349
380
  ## Tools
350
381
 
351
- This library supports two kinds of tools:
382
+ There are three tool-enabled call patterns:
383
+
384
+ 1. `generateText()` for provider-native/server-side tools (for example web search).
385
+ 2. `runToolLoop()` for your runtime JS/TS tools (function tools executed in your process).
386
+ 3. `runAgentLoop()` for filesystem tasks (a convenience wrapper around `runToolLoop()`).
352
387
 
353
- - Model tools (server-side): `web-search` and `code-execution`
354
- - Your tools (JS/TS code): use `runToolLoop()` and `tool()`
388
+ Architecture note:
355
389
 
356
- ### Model tools (web search / code execution)
390
+ - Filesystem tools are not a separate execution system.
391
+ - `runAgentLoop()` constructs a filesystem toolset, merges your optional custom tools, then calls the same `runToolLoop()` engine.
392
+ - This behavior is model-agnostic at API level; profile selection only adapts tool shape for model compatibility.
357
393
 
358
- These tools run on the provider side.
394
+ ### Provider-Native Tools (`generateText()`)
395
+
396
+ Use this when the model provider executes the tool remotely (for example search/code-exec style tools).
359
397
 
360
398
  ```ts
361
399
  import { generateText } from "@ljoukov/llm";
@@ -369,9 +407,9 @@ const result = await generateText({
369
407
  console.log(result.text);
370
408
  ```
371
409
 
372
- ### Your tools (function calling)
410
+ ### Runtime Tools (`runToolLoop()`)
373
411
 
374
- `runToolLoop()` runs a simple function-calling loop until the model returns a final answer or the step limit is hit.
412
+ Use this when the model should call your local runtime functions.
375
413
 
376
414
  ```ts
377
415
  import { runToolLoop, tool } from "@ljoukov/llm";
@@ -392,6 +430,91 @@ const result = await runToolLoop({
392
430
  console.log(result.text);
393
431
  ```
394
432
 
433
+ Use `customTool()` only when you need freeform/non-JSON tool input grammar.
434
+
435
+ ### Filesystem Tasks (`runAgentLoop()`)
436
+
437
+ Use this for read/search/write tasks in a workspace. The library auto-selects filesystem tool profile by model when `profile: "auto"`:
438
+
439
+ - Codex-like models: Codex-compatible filesystem tool shape.
440
+ - Gemini models: Gemini-compatible filesystem tool shape.
441
+ - Other models: model-agnostic profile (currently Gemini-style).
442
+
443
+ Confinement/policy is set through `filesystemTool.options`:
444
+
445
+ - `cwd`: workspace root for path resolution.
446
+ - `fs`: backend (`createNodeAgentFilesystem()` or `createInMemoryAgentFilesystem()`).
447
+ - `checkAccess`: hook for allow/deny policy + audit.
448
+ - `allowOutsideCwd`: opt-out confinement (default is false).
449
+
450
+ Detailed reference: `docs/agent-filesystem-tools.md`.
451
+
452
+ ```ts
453
+ import { createInMemoryAgentFilesystem, runAgentLoop } from "@ljoukov/llm";
454
+
455
+ const fs = createInMemoryAgentFilesystem({
456
+ "/repo/src/a.ts": "export const value = 1;\n",
457
+ });
458
+
459
+ const result = await runAgentLoop({
460
+ model: "chatgpt-gpt-5.3-codex-spark",
461
+ input: "Change value from 1 to 2 using filesystem tools.",
462
+ filesystemTool: {
463
+ profile: "auto",
464
+ options: {
465
+ cwd: "/repo",
466
+ fs,
467
+ },
468
+ },
469
+ });
470
+
471
+ console.log(result.text);
472
+ ```
473
+
474
+ If you need exact control over tool definitions, build the filesystem toolset yourself and call `runToolLoop()` directly.
475
+
476
+ ```ts
477
+ import {
478
+ createFilesystemToolSetForModel,
479
+ createInMemoryAgentFilesystem,
480
+ runToolLoop,
481
+ } from "@ljoukov/llm";
482
+
483
+ const fs = createInMemoryAgentFilesystem({ "/repo/a.ts": "export const n = 1;\n" });
484
+ const tools = createFilesystemToolSetForModel("chatgpt-gpt-5.3-codex-spark", {
485
+ cwd: "/repo",
486
+ fs,
487
+ });
488
+
489
+ const result = await runToolLoop({
490
+ model: "chatgpt-gpt-5.3-codex-spark",
491
+ input: "Update n to 2.",
492
+ tools,
493
+ });
494
+ ```
495
+
496
+ ## Agent benchmark (filesystem extraction)
497
+
498
+ For filesystem extraction/summarization evaluation across Codex, Fireworks, and Gemini models:
499
+
500
+ ```bash
501
+ npm run bench:agent
502
+ ```
503
+
504
+ Standard full refresh (all tasks, auto-write `LATEST_RESULTS.md`, refresh `traces/latest`, prune old traces):
505
+
506
+ ```bash
507
+ npm run bench:agent:latest
508
+ ```
509
+
510
+ Estimate-only:
511
+
512
+ ```bash
513
+ npm run bench:agent:estimate
514
+ ```
515
+
516
+ See `benchmarks/agent/README.md` for options and output format.
517
+
395
518
  ## License
396
519
 
397
520
  MIT