@x-code-cli/core 0.1.3 → 0.1.4
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/dist/agent/api-errors.d.ts +11 -0
- package/dist/agent/api-errors.d.ts.map +1 -0
- package/dist/agent/api-errors.js +134 -0
- package/dist/agent/api-errors.js.map +1 -0
- package/dist/agent/context-window.d.ts +26 -0
- package/dist/agent/context-window.d.ts.map +1 -0
- package/dist/agent/context-window.js +126 -0
- package/dist/agent/context-window.js.map +1 -0
- package/dist/agent/loop-state.d.ts +14 -0
- package/dist/agent/loop-state.d.ts.map +1 -0
- package/dist/agent/loop-state.js +12 -0
- package/dist/agent/loop-state.js.map +1 -0
- package/dist/agent/loop.d.ts +11 -15
- package/dist/agent/loop.d.ts.map +1 -1
- package/dist/agent/loop.js +213 -381
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/messages.d.ts +0 -2
- package/dist/agent/messages.d.ts.map +1 -1
- package/dist/agent/messages.js +0 -32
- package/dist/agent/messages.js.map +1 -1
- package/dist/agent/provider-compat.d.ts +17 -0
- package/dist/agent/provider-compat.d.ts.map +1 -0
- package/dist/agent/provider-compat.js +31 -0
- package/dist/agent/provider-compat.js.map +1 -0
- package/dist/agent/stream-utils.d.ts +33 -0
- package/dist/agent/stream-utils.d.ts.map +1 -0
- package/dist/agent/stream-utils.js +14 -0
- package/dist/agent/stream-utils.js.map +1 -0
- package/dist/agent/system-prompt.d.ts +1 -3
- package/dist/agent/system-prompt.d.ts.map +1 -1
- package/dist/agent/system-prompt.js +34 -23
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/agent/tool-execution.d.ts +11 -0
- package/dist/agent/tool-execution.d.ts.map +1 -0
- package/dist/agent/tool-execution.js +171 -0
- package/dist/agent/tool-execution.js.map +1 -0
- package/dist/config/index.d.ts +19 -8
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +66 -32
- package/dist/config/index.js.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/knowledge/auto-memory.d.ts +1 -1
- package/dist/knowledge/auto-memory.d.ts.map +1 -1
- package/dist/knowledge/auto-memory.js +55 -16
- package/dist/knowledge/auto-memory.js.map +1 -1
- package/dist/knowledge/init.d.ts +1 -2
- package/dist/knowledge/init.d.ts.map +1 -1
- package/dist/knowledge/init.js +83 -69
- package/dist/knowledge/init.js.map +1 -1
- package/dist/knowledge/loader.d.ts +0 -9
- package/dist/knowledge/loader.d.ts.map +1 -1
- package/dist/knowledge/loader.js +54 -99
- package/dist/knowledge/loader.js.map +1 -1
- package/dist/knowledge/session.d.ts +1 -1
- package/dist/knowledge/session.d.ts.map +1 -1
- package/dist/knowledge/session.js +2 -1
- package/dist/knowledge/session.js.map +1 -1
- package/dist/permissions/index.d.ts +2 -0
- package/dist/permissions/index.d.ts.map +1 -1
- package/dist/permissions/index.js +35 -14
- package/dist/permissions/index.js.map +1 -1
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +3 -1
- package/dist/tools/glob.js.map +1 -1
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +7 -2
- package/dist/tools/grep.js.map +1 -1
- package/dist/tools/index.d.ts +3 -7
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -5
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/list-dir.d.ts.map +1 -1
- package/dist/tools/list-dir.js +3 -1
- package/dist/tools/list-dir.js.map +1 -1
- package/dist/tools/progress.d.ts +6 -0
- package/dist/tools/progress.d.ts.map +1 -0
- package/dist/tools/progress.js +14 -0
- package/dist/tools/progress.js.map +1 -0
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +3 -1
- package/dist/tools/read-file.js.map +1 -1
- package/dist/tools/save-knowledge.d.ts +2 -2
- package/dist/tools/save-knowledge.d.ts.map +1 -1
- package/dist/tools/save-knowledge.js +31 -6
- package/dist/tools/save-knowledge.js.map +1 -1
- package/dist/tools/shell-utils.d.ts.map +1 -1
- package/dist/tools/shell-utils.js +7 -0
- package/dist/tools/shell-utils.js.map +1 -1
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +88 -19
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +85 -12
- package/dist/tools/web-search.js.map +1 -1
- package/dist/types/index.d.ts +60 -21
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +64 -6
- package/dist/types/index.js.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +32 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/dist/agent/plan-mode.d.ts +0 -11
- package/dist/agent/plan-mode.d.ts.map +0 -1
- package/dist/agent/plan-mode.js +0 -37
- package/dist/agent/plan-mode.js.map +0 -1
- package/dist/agent/pricing.d.ts +0 -9
- package/dist/agent/pricing.d.ts.map +0 -1
- package/dist/agent/pricing.js +0 -47
- package/dist/agent/pricing.js.map +0 -1
- package/dist/knowledge/hooks.d.ts +0 -3
- package/dist/knowledge/hooks.d.ts.map +0 -1
- package/dist/knowledge/hooks.js +0 -59
- package/dist/knowledge/hooks.js.map +0 -1
- package/dist/tools/enter-plan-mode.d.ts +0 -2
- package/dist/tools/enter-plan-mode.d.ts.map +0 -1
- package/dist/tools/enter-plan-mode.js +0 -11
- package/dist/tools/enter-plan-mode.js.map +0 -1
- package/dist/tools/exit-plan-mode.d.ts +0 -2
- package/dist/tools/exit-plan-mode.d.ts.map +0 -1
- package/dist/tools/exit-plan-mode.js +0 -9
- package/dist/tools/exit-plan-mode.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const saveKnowledge: import("ai").Tool<{
|
|
2
|
-
category: "
|
|
3
|
-
key: string;
|
|
2
|
+
category: "user" | "feedback" | "project" | "reference";
|
|
4
3
|
action: "add" | "delete";
|
|
4
|
+
key: string;
|
|
5
5
|
fact: string;
|
|
6
6
|
scope: "project" | "global";
|
|
7
7
|
}, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-knowledge.d.ts","sourceRoot":"","sources":["../../src/tools/save-knowledge.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa;;;;;;
|
|
1
|
+
{"version":3,"file":"save-knowledge.d.ts","sourceRoot":"","sources":["../../src/tools/save-knowledge.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa;;;;;;UAyDxB,CAAA"}
|
|
@@ -1,19 +1,44 @@
|
|
|
1
|
-
// @x-code-cli/core — saveKnowledge tool (
|
|
1
|
+
// @x-code-cli/core — saveKnowledge tool (AI-written persistent memory)
|
|
2
2
|
import { tool } from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { getAutoMemory } from '../knowledge/auto-memory.js';
|
|
5
5
|
export const saveKnowledge = tool({
|
|
6
|
-
description:
|
|
6
|
+
description: `Save or delete a persistent memory that should survive across sessions.
|
|
7
|
+
|
|
8
|
+
Before calling this tool, ask yourself: **"Will a future session plausibly act better because I save this?"** If not — do NOT call the tool. No-op is the default; saving is the exception. This tool is strictly for durable, cross-session knowledge.
|
|
9
|
+
|
|
10
|
+
Every memory MUST be filed under one of four categories — pick the one that describes the TYPE of knowledge, not the topic:
|
|
11
|
+
|
|
12
|
+
user — Facts about the human user: their role, expertise, goals, long-term constraints. Example: "user is a senior Go engineer new to this frontend".
|
|
13
|
+
feedback — Corrections or validated approaches the user has given. Save both when the user corrects you AND when they confirm a non-obvious choice worked. Include WHY so edge cases are judgeable. Example: "integration tests must hit real DB, not mocks — prior incident where mocks masked broken migration".
|
|
14
|
+
project — Ongoing work, initiatives, deadlines, non-obvious project state that would NOT be derivable from reading code or git log. Example: "merge freeze begins 2026-03-05 for mobile release cut".
|
|
15
|
+
reference — Pointers to external systems. Example: "pipeline bugs tracked in Linear project INGEST".
|
|
16
|
+
|
|
17
|
+
Do NOT save any of these (these are the common failure modes):
|
|
18
|
+
- The user's current task or request ("user asked me to build a snake game") — this is transient, not durable
|
|
19
|
+
- Summaries of code you just wrote, bugs you just fixed, or findings from the current turn
|
|
20
|
+
- Anything derivable from the code or git log (tech stack, package.json scripts, dependencies, directory layout) — future sessions can read the code
|
|
21
|
+
- Content already in AGENTS.md / CLAUDE.md
|
|
22
|
+
- Debugging solutions (the fix is in the code; the commit has the context)
|
|
23
|
+
- Duplicates or near-duplicates of an existing memory — update the existing one instead
|
|
24
|
+
|
|
25
|
+
Even if the user says "remember X" — if X is one-off task context (a specific request, a game they wanted), still decline. Ask yourself what is *surprising* or *durable* about it; if nothing, no-op.
|
|
26
|
+
|
|
27
|
+
Scope: project = this repo only; global = applies across all repos.`,
|
|
7
28
|
inputSchema: z.object({
|
|
8
29
|
action: z
|
|
9
30
|
.enum(['add', 'delete'])
|
|
10
31
|
.describe('add = create or update (auto-replaces conflicting old fact), delete = remove outdated fact'),
|
|
11
32
|
key: z
|
|
12
33
|
.string()
|
|
13
|
-
.describe('
|
|
14
|
-
fact: z
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
.describe('Short unique slug identifying this fact. Same key under same category auto-replaces. Example: "testing-db-policy", "user-role".'),
|
|
35
|
+
fact: z
|
|
36
|
+
.string()
|
|
37
|
+
.describe('The fact itself. For feedback, lead with the rule and include a one-line reason so future edge cases are judgeable.'),
|
|
38
|
+
scope: z.enum(['project', 'global']).describe('project = this repo (.x-code/), global = all repos (~/.x-code/)'),
|
|
39
|
+
category: z
|
|
40
|
+
.enum(['user', 'feedback', 'project', 'reference'])
|
|
41
|
+
.describe('user | feedback | project | reference — see tool description for when to pick each'),
|
|
17
42
|
}),
|
|
18
43
|
execute: ({ action, key, fact, scope, category }) => {
|
|
19
44
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-knowledge.js","sourceRoot":"","sources":["../../src/tools/save-knowledge.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"save-knowledge.js","sourceRoot":"","sources":["../../src/tools/save-knowledge.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;oEAqBqD;IAClE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,CAAC;aACN,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;aACvB,QAAQ,CAAC,4FAA4F,CAAC;QACzG,GAAG,EAAE,CAAC;aACH,MAAM,EAAE;aACR,QAAQ,CACP,iIAAiI,CAClI;QACH,IAAI,EAAE,CAAC;aACJ,MAAM,EAAE;aACR,QAAQ,CACP,qHAAqH,CACtH;QACH,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,iEAAiE,CAAC;QAChH,QAAQ,EAAE,CAAC;aACR,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;aAClD,QAAQ,CAAC,oFAAoF,CAAC;KAClG,CAAC;IACF,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;QAClD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;YACnC,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;gBACrB,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;gBAChF,OAAO,qBAAqB,QAAQ,KAAK,GAAG,KAAK,IAAI,EAAE,CAAA;YACzD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;gBAC5B,OAAO,uBAAuB,QAAQ,KAAK,GAAG,EAAE,CAAA;YAClD,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC5D,OAAO,2BAA2B,GAAG,EAAE,CAAA;QACzC,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-utils.d.ts","sourceRoot":"","sources":["../../src/tools/shell-utils.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,KAAK,CAAA;AAErD,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,IAAI,EAAE,SAAS,CAAA;CAChB;AAED,wBAAgB,cAAc,IAAI,WAAW,
|
|
1
|
+
{"version":3,"file":"shell-utils.d.ts","sourceRoot":"","sources":["../../src/tools/shell-utils.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,KAAK,CAAA;AAErD,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,IAAI,EAAE,SAAS,CAAA;CAChB;AAED,wBAAgB,cAAc,IAAI,WAAW,CAc5C;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CA0CxD;AAkDD,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGlD"}
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
export function getShellConfig() {
|
|
4
4
|
if (os.platform() === 'win32') {
|
|
5
|
+
// Git Bash / MSYS2 / Cygwin set SHELL to a Unix-style path (e.g. /usr/bin/bash).
|
|
6
|
+
// Prefer that shell when available so the Unix tool ecosystem works as expected.
|
|
7
|
+
const shell = process.env.SHELL;
|
|
8
|
+
if (shell && /\b(bash|zsh)$/i.test(shell)) {
|
|
9
|
+
const type = shell.endsWith('zsh') ? 'zsh' : 'bash';
|
|
10
|
+
return { executable: shell, args: ['-c'], type };
|
|
11
|
+
}
|
|
5
12
|
return { executable: 'powershell.exe', args: ['-NoProfile', '-Command'], type: 'powershell' };
|
|
6
13
|
}
|
|
7
14
|
const userShell = process.env.SHELL ?? '/bin/bash';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-utils.js","sourceRoot":"","sources":["../../src/tools/shell-utils.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,MAAM,SAAS,CAAA;AAUxB,MAAM,UAAU,cAAc;IAC5B,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,EAAE,CAAC;QAC9B,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAA;IAC/F,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,WAAW,CAAA;IAClD,MAAM,IAAI,GAAc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N,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,UAAU;IACV,MAAM;IACN,MAAM;IACN,aAAa;IACb,eAAe;IACf,cAAc;IACd,aAAa;IACb,eAAe;IACf,WAAW;CACZ,CAAA;AAED,0CAA0C;AAC1C,MAAM,yBAAyB,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AAE9F,uCAAuC;AACvC,MAAM,eAAe,GAAG,IAAI,MAAM,CAChC,SAAS,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAC5F,CAAA;AAED,MAAM,oBAAoB,GAAa;IACrC,gDAAgD;IAChD,UAAU;IACV,UAAU;IACV,YAAY;IACZ,wBAAwB;IACxB,eAAe;IACf,YAAY;IACZ,4BAA4B;CAC7B,CAAA;AAED,+DAA+D;AAC/D,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;AACzC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IACpB,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAmFA,eAAO,MAAM,QAAQ;;;UAsEnB,CAAA"}
|
package/dist/tools/web-fetch.js
CHANGED
|
@@ -1,40 +1,111 @@
|
|
|
1
|
-
// @x-code-cli/core — webFetch tool (HTTP fetch + HTML→Markdown)
|
|
1
|
+
// @x-code-cli/core — webFetch tool (HTTP fetch + HTML→Markdown, with LRU cache + CF fallback)
|
|
2
2
|
import * as cheerio from 'cheerio';
|
|
3
3
|
// @ts-expect-error turndown has no types
|
|
4
4
|
import TurndownService from 'turndown';
|
|
5
5
|
import { tool } from 'ai';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
//
|
|
7
|
+
import { reportProgress } from './progress.js';
|
|
8
|
+
const FETCH_TIMEOUT_MS = 15_000;
|
|
9
|
+
// Markdown returned to the model. Bumped from 30 KB (which cut docs pages in half)
|
|
10
|
+
// but kept well under the model's context budget: ~100 KB ≈ ~25 K tokens, roughly
|
|
11
|
+
// 12% of a Sonnet 200 K window, so a single fetch can't blow context.
|
|
12
|
+
// This is a per-call cap; the model can always fetch again with a narrower prompt.
|
|
13
|
+
const MAX_CONTENT_CHARS = 100_000;
|
|
14
|
+
// Raw HTML ceiling before turndown. 10 MB is comfortable for any real doc page;
|
|
15
|
+
// enforced via content-length header (best-effort — chunked responses skip this,
|
|
16
|
+
// in which case the 15 s fetch timeout bounds the download).
|
|
17
|
+
const MAX_HTTP_BYTES = 10 * 1024 * 1024;
|
|
18
|
+
const CACHE_TTL_MS = 15 * 60 * 1000;
|
|
19
|
+
const CACHE_MAX_ENTRIES = 50;
|
|
20
|
+
const BROWSER_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36';
|
|
21
|
+
// Used as Cloudflare fallback: aggressive bot rules often let honest CLI UAs through
|
|
22
|
+
// while blocking browser impersonators that fail TLS-fingerprint checks.
|
|
23
|
+
const FALLBACK_UA = 'x-code-cli/0.1 (+https://github.com/woai3c/x-code-cli)';
|
|
24
|
+
const YEAR = new Date().getFullYear();
|
|
25
|
+
const fetchCache = new Map();
|
|
26
|
+
function cacheGet(url) {
|
|
27
|
+
const entry = fetchCache.get(url);
|
|
28
|
+
if (!entry)
|
|
29
|
+
return null;
|
|
30
|
+
if (Date.now() - entry.at > CACHE_TTL_MS) {
|
|
31
|
+
fetchCache.delete(url);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
// LRU: re-insert to move this entry to the tail (most-recently-used)
|
|
35
|
+
fetchCache.delete(url);
|
|
36
|
+
fetchCache.set(url, entry);
|
|
37
|
+
return entry.markdown;
|
|
38
|
+
}
|
|
39
|
+
function cacheSet(url, markdown) {
|
|
40
|
+
if (fetchCache.size >= CACHE_MAX_ENTRIES) {
|
|
41
|
+
const oldest = fetchCache.keys().next().value;
|
|
42
|
+
if (oldest !== undefined)
|
|
43
|
+
fetchCache.delete(oldest);
|
|
44
|
+
}
|
|
45
|
+
fetchCache.set(url, { markdown, at: Date.now() });
|
|
46
|
+
}
|
|
10
47
|
const turndown = new TurndownService({
|
|
11
48
|
headingStyle: 'atx',
|
|
12
49
|
codeBlockStyle: 'fenced',
|
|
13
50
|
});
|
|
51
|
+
async function doFetch(url, userAgent) {
|
|
52
|
+
return fetch(url, {
|
|
53
|
+
headers: {
|
|
54
|
+
'User-Agent': userAgent,
|
|
55
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,text/plain;q=0.8,*/*;q=0.5',
|
|
56
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
57
|
+
},
|
|
58
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function formatOutput(url, markdown, prompt) {
|
|
62
|
+
if (prompt) {
|
|
63
|
+
return `# Content from ${url}\n\n${markdown}\n\n---\nExtract instruction: ${prompt}`;
|
|
64
|
+
}
|
|
65
|
+
return markdown;
|
|
66
|
+
}
|
|
14
67
|
export const webFetch = tool({
|
|
15
|
-
description:
|
|
68
|
+
description: `Fetch a web page and extract its content as markdown. No API key needed. ` +
|
|
69
|
+
`When summarizing the returned content for the user, preserve key details, concrete examples, ` +
|
|
70
|
+
`section structure, and numbers — don't over-compress. ` +
|
|
71
|
+
`Results are cached for 15 minutes per URL, so repeated reads of the same page are free. ` +
|
|
72
|
+
`The current year is ${YEAR} — use it whenever the user asks for recent/latest/current information.`,
|
|
16
73
|
inputSchema: z.object({
|
|
17
74
|
url: z.string().url().describe('The URL to fetch'),
|
|
18
75
|
prompt: z.string().optional().describe('What information to extract from the page'),
|
|
19
76
|
}),
|
|
20
|
-
execute: async ({ url, prompt }) => {
|
|
77
|
+
execute: async ({ url, prompt }, { toolCallId }) => {
|
|
21
78
|
try {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
79
|
+
const cached = cacheGet(url);
|
|
80
|
+
if (cached) {
|
|
81
|
+
reportProgress(toolCallId, 'Using cached copy');
|
|
82
|
+
return formatOutput(url, cached, prompt);
|
|
83
|
+
}
|
|
84
|
+
reportProgress(toolCallId, `Fetching ${url}`);
|
|
85
|
+
let response = await doFetch(url, BROWSER_UA);
|
|
86
|
+
// Cloudflare bot-challenge fallback: on 403 + cf-mitigated header, retry with
|
|
87
|
+
// an honest CLI UA. Many CF rules whitelist identified crawlers while blocking
|
|
88
|
+
// anything that fails the browser TLS fingerprint check.
|
|
89
|
+
if (response.status === 403 && response.headers.get('cf-mitigated') !== null) {
|
|
90
|
+
response = await doFetch(url, FALLBACK_UA);
|
|
91
|
+
}
|
|
29
92
|
if (!response.ok) {
|
|
30
93
|
return `Error: HTTP ${response.status} ${response.statusText}`;
|
|
31
94
|
}
|
|
95
|
+
// Best-effort size guard: content-length is optional under chunked encoding,
|
|
96
|
+
// so we also rely on fetch's 15s timeout to bound pathological pages.
|
|
97
|
+
const contentLength = Number(response.headers.get('content-length') ?? '0');
|
|
98
|
+
if (contentLength > MAX_HTTP_BYTES) {
|
|
99
|
+
const mb = Math.round(contentLength / 1024 / 1024);
|
|
100
|
+
return `Error: Content too large (${mb} MB, limit ${MAX_HTTP_BYTES / 1024 / 1024} MB)`;
|
|
101
|
+
}
|
|
32
102
|
const contentType = response.headers.get('content-type') ?? '';
|
|
33
103
|
const body = await response.text();
|
|
34
104
|
if (contentType.includes('application/json')) {
|
|
35
|
-
|
|
105
|
+
const json = body.slice(0, MAX_CONTENT_CHARS);
|
|
106
|
+
cacheSet(url, json);
|
|
107
|
+
return formatOutput(url, json, prompt);
|
|
36
108
|
}
|
|
37
|
-
// HTML → Markdown
|
|
38
109
|
const $ = cheerio.load(body);
|
|
39
110
|
$('script, style, nav, footer, header, aside, .sidebar, .nav, .menu, .ads, .advertisement').remove();
|
|
40
111
|
const mainContent = $('main, article, .content, .post, #content').first();
|
|
@@ -45,10 +116,8 @@ export const webFetch = tool({
|
|
|
45
116
|
if (markdown.length > MAX_CONTENT_CHARS) {
|
|
46
117
|
markdown = markdown.slice(0, MAX_CONTENT_CHARS) + '\n\n... [content truncated]';
|
|
47
118
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
return markdown;
|
|
119
|
+
cacheSet(url, markdown);
|
|
120
|
+
return formatOutput(url, markdown, prompt);
|
|
52
121
|
}
|
|
53
122
|
catch (err) {
|
|
54
123
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-fetch.js","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"web-fetch.js","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,yCAAyC;AACzC,OAAO,eAAe,MAAM,UAAU,CAAA;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAA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YACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC5D,OAAO,uBAAuB,GAAG,EAAE,CAAA;QACrC,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AA6FA,eAAO,MAAM,SAAS;;;UAyBpB,CAAA"}
|
package/dist/tools/web-search.js
CHANGED
|
@@ -1,26 +1,99 @@
|
|
|
1
|
-
// @x-code-cli/core — webSearch tool (Tavily
|
|
1
|
+
// @x-code-cli/core — webSearch tool (Tavily primary, Brave fallback)
|
|
2
2
|
import { tool } from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { reportProgress } from './progress.js';
|
|
5
|
+
import { getShellConfig } from './shell-utils.js';
|
|
6
|
+
const YEAR = new Date().getFullYear();
|
|
7
|
+
const BRAVE_TIMEOUT_MS = 15_000;
|
|
8
|
+
async function searchWithTavily(query, maxResults) {
|
|
9
|
+
const { tavily } = await import('@tavily/core');
|
|
10
|
+
const client = tavily({ apiKey: process.env.TAVILY_API_KEY });
|
|
11
|
+
const response = await client.search(query, { maxResults });
|
|
12
|
+
return response.results.map((r) => ({ title: r.title, url: r.url, content: r.content }));
|
|
13
|
+
}
|
|
14
|
+
async function searchWithBrave(query, maxResults) {
|
|
15
|
+
const url = new URL('https://api.search.brave.com/res/v1/web/search');
|
|
16
|
+
url.searchParams.set('q', query);
|
|
17
|
+
url.searchParams.set('count', String(Math.min(maxResults, 20)));
|
|
18
|
+
const res = await fetch(url, {
|
|
19
|
+
headers: {
|
|
20
|
+
'X-Subscription-Token': process.env.BRAVE_API_KEY,
|
|
21
|
+
Accept: 'application/json',
|
|
22
|
+
},
|
|
23
|
+
signal: AbortSignal.timeout(BRAVE_TIMEOUT_MS),
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
throw new Error(`Brave API returned HTTP ${res.status} ${res.statusText}`);
|
|
27
|
+
}
|
|
28
|
+
const data = (await res.json());
|
|
29
|
+
return (data.web?.results ?? []).map((r) => ({ title: r.title, url: r.url, content: r.description }));
|
|
30
|
+
}
|
|
31
|
+
function buildMissingKeyError() {
|
|
32
|
+
const { type } = getShellConfig();
|
|
33
|
+
let setupBlock;
|
|
34
|
+
if (type === 'powershell') {
|
|
35
|
+
setupBlock = [
|
|
36
|
+
' # current session:',
|
|
37
|
+
' $env:TAVILY_API_KEY = "tvly-xxx"',
|
|
38
|
+
' $env:BRAVE_API_KEY = "BSA-xxx"',
|
|
39
|
+
' # persistent (new shells):',
|
|
40
|
+
' [Environment]::SetEnvironmentVariable("TAVILY_API_KEY","tvly-xxx","User")',
|
|
41
|
+
' [Environment]::SetEnvironmentVariable("BRAVE_API_KEY", "BSA-xxx", "User")',
|
|
42
|
+
].join('\n');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const rc = type === 'zsh' ? '~/.zshrc' : '~/.bashrc';
|
|
46
|
+
setupBlock = [
|
|
47
|
+
' # current session:',
|
|
48
|
+
' export TAVILY_API_KEY="tvly-xxx"',
|
|
49
|
+
' export BRAVE_API_KEY="BSA-xxx"',
|
|
50
|
+
' # persistent (new shells):',
|
|
51
|
+
` echo 'export TAVILY_API_KEY="tvly-xxx"' >> ${rc}`,
|
|
52
|
+
` echo 'export BRAVE_API_KEY="BSA-xxx"' >> ${rc}`,
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
55
|
+
return [
|
|
56
|
+
'Error: WebSearch requires an API key. Two free options (set either one):',
|
|
57
|
+
'',
|
|
58
|
+
' 1. Tavily — 1000 searches/month, recommended',
|
|
59
|
+
' Sign up: https://tavily.com → copy API key from dashboard',
|
|
60
|
+
'',
|
|
61
|
+
' 2. Brave — 2000 searches/month (requires credit card, no charge)',
|
|
62
|
+
' Sign up: https://api.search.brave.com → create API key',
|
|
63
|
+
'',
|
|
64
|
+
`Setup (${type}):`,
|
|
65
|
+
setupBlock,
|
|
66
|
+
'',
|
|
67
|
+
'After setting, restart this shell for the variable to take effect.',
|
|
68
|
+
].join('\n');
|
|
69
|
+
}
|
|
70
|
+
function formatResults(results) {
|
|
71
|
+
if (results.length === 0)
|
|
72
|
+
return 'No results found.';
|
|
73
|
+
return results.map((r) => `### ${r.title}\n${r.url}\n${r.content}`).join('\n\n');
|
|
74
|
+
}
|
|
4
75
|
export const webSearch = tool({
|
|
5
|
-
description:
|
|
76
|
+
description: `Search the web for information. Useful for looking up documentation, error messages, or current information. ` +
|
|
77
|
+
`The current year is ${YEAR} — use it whenever the user asks for recent/latest/current information ` +
|
|
78
|
+
`(e.g. prefer "React 19 release notes ${YEAR}" over "React latest release notes").`,
|
|
6
79
|
inputSchema: z.object({
|
|
7
80
|
query: z.string().describe('The search query'),
|
|
8
81
|
maxResults: z.number().optional().describe('Max results (default: 5)'),
|
|
9
82
|
}),
|
|
10
|
-
execute: async ({ query, maxResults }) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
83
|
+
execute: async ({ query, maxResults }, { toolCallId }) => {
|
|
84
|
+
const n = maxResults ?? 5;
|
|
85
|
+
const hasTavily = !!process.env.TAVILY_API_KEY;
|
|
86
|
+
const hasBrave = !!process.env.BRAVE_API_KEY;
|
|
87
|
+
if (!hasTavily && !hasBrave)
|
|
88
|
+
return buildMissingKeyError();
|
|
89
|
+
reportProgress(toolCallId, `Searching: ${query}`);
|
|
14
90
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const response = await client.search(query, { maxResults: maxResults ?? 5 });
|
|
18
|
-
const results = response.results.map((r) => `### ${r.title}\n${r.url}\n${r.content}`);
|
|
19
|
-
return results.join('\n\n') || 'No results found.';
|
|
91
|
+
const results = hasTavily ? await searchWithTavily(query, n) : await searchWithBrave(query, n);
|
|
92
|
+
return formatResults(results);
|
|
20
93
|
}
|
|
21
94
|
catch (err) {
|
|
22
95
|
const msg = err instanceof Error ? err.message : String(err);
|
|
23
|
-
return `Error searching: ${msg}`;
|
|
96
|
+
return `Error searching (${hasTavily ? 'Tavily' : 'Brave'}): ${msg}`;
|
|
24
97
|
}
|
|
25
98
|
},
|
|
26
99
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;AACrC,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAQ/B,KAAK,UAAU,gBAAgB,CAAC,KAAa,EAAE,UAAkB;IAC/D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAe,EAAE,CAAC,CAAA;IAC9D,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IAC3D,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,C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
|
5
5
|
outputTokens: number;
|
|
6
6
|
totalTokens: number;
|
|
7
|
-
estimatedCost: number;
|
|
8
|
-
costCurrency: 'USD' | 'CNY';
|
|
9
7
|
}
|
|
10
8
|
export interface DisplayMessage {
|
|
11
9
|
id: string;
|
|
@@ -13,19 +11,45 @@ export interface DisplayMessage {
|
|
|
13
11
|
content: string;
|
|
14
12
|
toolCalls?: DisplayToolCall[];
|
|
15
13
|
timestamp: number;
|
|
14
|
+
/** True for assistant text chunks emitted mid-stream (one per newline).
|
|
15
|
+
* Rendered WITHOUT the trailing blank line that regular messages append,
|
|
16
|
+
* so consecutive chunks join into a single paragraph visually. Keeps
|
|
17
|
+
* streaming text out of the bottom cell buffer (avoids row-shift jitter)
|
|
18
|
+
* by sending each complete line directly to scrollback. */
|
|
19
|
+
streamingChunk?: boolean;
|
|
20
|
+
/** Compact slash-command rendering, matching Claude Code's 2-line block:
|
|
21
|
+
* > /model
|
|
22
|
+
* ⎿ Set model to Sonnet 4.6
|
|
23
|
+
* 'command-echo' (user role) drops the trailing blank that regular user
|
|
24
|
+
* messages append; 'command-result' (assistant role) renders with the
|
|
25
|
+
* ⎿ prefix and a single trailing newline instead of markdown + \n\n.
|
|
26
|
+
* Used only for short, single-line command responses. Long multi-line
|
|
27
|
+
* output (/help, /usage) keeps the regular assistant-message path. */
|
|
28
|
+
kind?: 'command-echo' | 'command-result';
|
|
16
29
|
}
|
|
17
30
|
export interface DisplayToolCall {
|
|
18
31
|
id: string;
|
|
19
32
|
toolName: string;
|
|
20
33
|
input: Record<string, unknown>;
|
|
21
34
|
output?: string;
|
|
22
|
-
|
|
35
|
+
/** `error` marks a tool that finished but with a non-zero exit / thrown
|
|
36
|
+
* exception — the stdout-writer renders its result body in red so
|
|
37
|
+
* failures stand out in scrollback. `denied` is reserved for the
|
|
38
|
+
* permission-denial path. */
|
|
39
|
+
status: 'pending' | 'running' | 'completed' | 'denied' | 'error';
|
|
40
|
+
/** How long the tool call took to execute (milliseconds) */
|
|
41
|
+
durationMs?: number;
|
|
23
42
|
}
|
|
24
43
|
export interface AgentCallbacks {
|
|
25
44
|
onTextDelta: (text: string) => void;
|
|
26
|
-
onToolCall: (toolName: string, input: Record<string, unknown>) => void;
|
|
27
|
-
|
|
45
|
+
onToolCall: (toolCallId: string, toolName: string, input: Record<string, unknown>) => void;
|
|
46
|
+
/** Streamed progress messages emitted by a tool while it runs (e.g.
|
|
47
|
+
* "Searching: query" → "Found 5 results"). Only the LATEST message is
|
|
48
|
+
* shown in the live UI; the final summary comes through onToolResult. */
|
|
49
|
+
onToolProgress: (toolCallId: string, message: string) => void;
|
|
50
|
+
onToolResult: (toolCallId: string, result: string, isError?: boolean) => void;
|
|
28
51
|
onAskPermission: (toolCall: {
|
|
52
|
+
toolCallId: string;
|
|
29
53
|
toolName: string;
|
|
30
54
|
input: Record<string, unknown>;
|
|
31
55
|
}) => Promise<boolean>;
|
|
@@ -46,13 +70,22 @@ export interface AgentOptions {
|
|
|
46
70
|
systemPromptExtra?: string;
|
|
47
71
|
abortSignal?: AbortSignal;
|
|
48
72
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Category taxonomy for auto memory entries. Categories describe the TYPE of
|
|
75
|
+
* knowledge (who it's about, how it was learned) rather than the topic —
|
|
76
|
+
* this mirrors the taxonomy Claude Code uses and produces sharper memories
|
|
77
|
+
* because each category has distinct trigger conditions for the agent.
|
|
78
|
+
*
|
|
79
|
+
* - user: Facts about the human user — role, expertise, goals, constraints
|
|
80
|
+
* - feedback: Corrections or validated approaches ("don't mock the db", "yes, that was right")
|
|
81
|
+
* - project: Ongoing work, initiatives, decisions, non-obvious project state
|
|
82
|
+
* - reference: Pointers to external systems (Linear project, Grafana dashboard, etc.)
|
|
83
|
+
*/
|
|
84
|
+
export type KnowledgeCategory = 'user' | 'feedback' | 'project' | 'reference';
|
|
52
85
|
export interface KnowledgeFact {
|
|
53
86
|
key: string;
|
|
54
87
|
fact: string;
|
|
55
|
-
category:
|
|
88
|
+
category: KnowledgeCategory;
|
|
56
89
|
date: string;
|
|
57
90
|
}
|
|
58
91
|
export interface SessionSummary {
|
|
@@ -67,26 +100,16 @@ export interface SessionSummary {
|
|
|
67
100
|
filesModified: string[];
|
|
68
101
|
decisions: string[];
|
|
69
102
|
}
|
|
70
|
-
export interface RuleFrontmatter {
|
|
71
|
-
alwaysApply?: boolean;
|
|
72
|
-
paths?: string[];
|
|
73
|
-
description?: string;
|
|
74
|
-
}
|
|
75
|
-
export interface RuleFile {
|
|
76
|
-
filename: string;
|
|
77
|
-
frontmatter: RuleFrontmatter;
|
|
78
|
-
content: string;
|
|
79
|
-
}
|
|
80
103
|
export declare const MODEL_ALIASES: Record<string, string>;
|
|
81
104
|
export declare const PROVIDER_DETECTION_ORDER: readonly [{
|
|
82
105
|
readonly envKey: "ANTHROPIC_API_KEY";
|
|
83
|
-
readonly defaultModel: "anthropic:claude-sonnet-4-
|
|
106
|
+
readonly defaultModel: "anthropic:claude-sonnet-4-6";
|
|
84
107
|
}, {
|
|
85
108
|
readonly envKey: "OPENAI_API_KEY";
|
|
86
109
|
readonly defaultModel: "openai:gpt-4.1";
|
|
87
110
|
}, {
|
|
88
111
|
readonly envKey: "DEEPSEEK_API_KEY";
|
|
89
|
-
readonly defaultModel: "deepseek:deepseek-
|
|
112
|
+
readonly defaultModel: "deepseek:deepseek-v4-flash";
|
|
90
113
|
}, {
|
|
91
114
|
readonly envKey: "ALIBABA_API_KEY";
|
|
92
115
|
readonly defaultModel: "alibaba:qwen-max";
|
|
@@ -103,6 +126,22 @@ export declare const PROVIDER_DETECTION_ORDER: readonly [{
|
|
|
103
126
|
readonly envKey: "MOONSHOT_API_KEY";
|
|
104
127
|
readonly defaultModel: "moonshotai:kimi-k2.5";
|
|
105
128
|
}];
|
|
129
|
+
export interface ProviderModel {
|
|
130
|
+
/** Full `<provider>:<model>` id passed to AI SDK */
|
|
131
|
+
id: string;
|
|
132
|
+
/** Short display label shown in the picker */
|
|
133
|
+
label: string;
|
|
134
|
+
/** One-line description shown under the label */
|
|
135
|
+
description: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Hand-curated models per provider. Only models we've tested or that are
|
|
139
|
+
* advertised as production-stable make the list — agents tend to pick
|
|
140
|
+
* whatever is visible, so we don't dump every experimental variant here.
|
|
141
|
+
* Users who need something exotic can still type the full id into
|
|
142
|
+
* `/model <provider>:<model>` or pass it via `--model`.
|
|
143
|
+
*/
|
|
144
|
+
export declare const PROVIDER_MODELS: Record<string, readonly ProviderModel[]>;
|
|
106
145
|
export declare const PROVIDER_KEY_URLS: Record<string, string>;
|
|
107
146
|
export type { ModelMessage, LanguageModel };
|
|
108
147
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAIrD,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,KAAK,GAAG,MAAM,CAAA;AAI7D,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAIrD,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,KAAK,GAAG,MAAM,CAAA;AAI7D,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;CACpB;AAID,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,GAAG,W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