scoutline 0.1.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/LICENSE +21 -0
- package/README.md +146 -0
- package/bin/scoutline.js +17 -0
- package/dist/commands/code.d.ts +13 -0
- package/dist/commands/code.d.ts.map +1 -0
- package/dist/commands/code.js +94 -0
- package/dist/commands/code.js.map +1 -0
- package/dist/commands/doctor.d.ts +10 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +70 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/quota.d.ts +9 -0
- package/dist/commands/quota.d.ts.map +1 -0
- package/dist/commands/quota.js +77 -0
- package/dist/commands/quota.js.map +1 -0
- package/dist/commands/read.d.ts +20 -0
- package/dist/commands/read.d.ts.map +1 -0
- package/dist/commands/read.js +166 -0
- package/dist/commands/read.js.map +1 -0
- package/dist/commands/repo.d.ts +22 -0
- package/dist/commands/repo.d.ts.map +1 -0
- package/dist/commands/repo.js +219 -0
- package/dist/commands/repo.js.map +1 -0
- package/dist/commands/search.d.ts +19 -0
- package/dist/commands/search.d.ts.map +1 -0
- package/dist/commands/search.js +235 -0
- package/dist/commands/search.js.map +1 -0
- package/dist/commands/tools.d.ts +22 -0
- package/dist/commands/tools.d.ts.map +1 -0
- package/dist/commands/tools.js +173 -0
- package/dist/commands/tools.js.map +1 -0
- package/dist/commands/vision.d.ts +15 -0
- package/dist/commands/vision.d.ts.map +1 -0
- package/dist/commands/vision.js +168 -0
- package/dist/commands/vision.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +443 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-client.d.ts +133 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +150 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/cache.d.ts +34 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.js +168 -0
- package/dist/lib/cache.js.map +1 -0
- package/dist/lib/code-mode.d.ts +19 -0
- package/dist/lib/code-mode.d.ts.map +1 -0
- package/dist/lib/code-mode.js +83 -0
- package/dist/lib/code-mode.js.map +1 -0
- package/dist/lib/config.d.ts +21 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +59 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +29 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +69 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/extract.d.ts +37 -0
- package/dist/lib/extract.d.ts.map +1 -0
- package/dist/lib/extract.js +106 -0
- package/dist/lib/extract.js.map +1 -0
- package/dist/lib/image.d.ts +13 -0
- package/dist/lib/image.d.ts.map +1 -0
- package/dist/lib/image.js +102 -0
- package/dist/lib/image.js.map +1 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +10 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/mcp-client.d.ts +161 -0
- package/dist/lib/mcp-client.d.ts.map +1 -0
- package/dist/lib/mcp-client.js +494 -0
- package/dist/lib/mcp-client.js.map +1 -0
- package/dist/lib/mcp-config.d.ts +24 -0
- package/dist/lib/mcp-config.d.ts.map +1 -0
- package/dist/lib/mcp-config.js +129 -0
- package/dist/lib/mcp-config.js.map +1 -0
- package/dist/lib/monitor-client.d.ts +51 -0
- package/dist/lib/monitor-client.d.ts.map +1 -0
- package/dist/lib/monitor-client.js +115 -0
- package/dist/lib/monitor-client.js.map +1 -0
- package/dist/lib/output.d.ts +24 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +59 -0
- package/dist/lib/output.js.map +1 -0
- package/dist/lib/redact.d.ts +7 -0
- package/dist/lib/redact.d.ts.map +1 -0
- package/dist/lib/redact.js +50 -0
- package/dist/lib/redact.js.map +1 -0
- package/dist/lib/silence.d.ts +16 -0
- package/dist/lib/silence.d.ts.map +1 -0
- package/dist/lib/silence.js +56 -0
- package/dist/lib/silence.js.map +1 -0
- package/dist/lib/tty.d.ts +60 -0
- package/dist/lib/tty.d.ts.map +1 -0
- package/dist/lib/tty.js +103 -0
- package/dist/lib/tty.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z.AI API client for vision, search, and reader
|
|
3
|
+
*/
|
|
4
|
+
import { loadConfig } from "./config.js";
|
|
5
|
+
import { ApiError, AuthError, NetworkError, TimeoutError } from "./errors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Retry wrapper with exponential backoff
|
|
8
|
+
*/
|
|
9
|
+
async function withRetry(fn, maxRetries = 2, baseDelay = 1000) {
|
|
10
|
+
let lastError;
|
|
11
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
12
|
+
try {
|
|
13
|
+
return await fn();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
lastError = error;
|
|
17
|
+
// Don't retry auth errors or validation errors
|
|
18
|
+
if (error instanceof AuthError) {
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
// Don't retry on last attempt
|
|
22
|
+
if (attempt === maxRetries) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
// Exponential backoff
|
|
26
|
+
const delay = baseDelay * Math.pow(2, attempt);
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw lastError;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Z.AI API client
|
|
34
|
+
*/
|
|
35
|
+
export class ZaiApiClient {
|
|
36
|
+
config;
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.config = config || loadConfig();
|
|
39
|
+
}
|
|
40
|
+
async request(endpoint, body) {
|
|
41
|
+
const url = `${this.config.baseUrl}${endpoint}`;
|
|
42
|
+
const controller = new AbortController();
|
|
43
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetch(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
"Accept-Language": "en-US,en",
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
signal: controller.signal,
|
|
54
|
+
});
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const text = await response.text();
|
|
58
|
+
let errorMessage = `HTTP ${response.status}: ${text}`;
|
|
59
|
+
try {
|
|
60
|
+
const errorJson = JSON.parse(text);
|
|
61
|
+
// Handle nested error objects
|
|
62
|
+
const msg = errorJson.message || errorJson.error?.message || errorJson.error;
|
|
63
|
+
if (typeof msg === "string") {
|
|
64
|
+
errorMessage = msg;
|
|
65
|
+
}
|
|
66
|
+
else if (typeof msg === "object") {
|
|
67
|
+
errorMessage = JSON.stringify(msg);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Use text as-is
|
|
72
|
+
}
|
|
73
|
+
if (response.status === 401 || response.status === 403) {
|
|
74
|
+
throw new AuthError(errorMessage);
|
|
75
|
+
}
|
|
76
|
+
throw new ApiError(errorMessage, response.status);
|
|
77
|
+
}
|
|
78
|
+
return (await response.json());
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
clearTimeout(timeoutId);
|
|
82
|
+
if (error instanceof AuthError || error instanceof ApiError) {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
if (error.name === "AbortError") {
|
|
87
|
+
throw new TimeoutError(this.config.timeout);
|
|
88
|
+
}
|
|
89
|
+
if (error.message.includes("fetch")) {
|
|
90
|
+
throw new NetworkError(error.message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Vision completions API for image/video analysis
|
|
98
|
+
*/
|
|
99
|
+
async visionComplete(messages) {
|
|
100
|
+
return withRetry(() => this.request("/chat/completions", {
|
|
101
|
+
model: this.config.visionModel,
|
|
102
|
+
messages,
|
|
103
|
+
thinking: { type: "enabled" },
|
|
104
|
+
stream: false,
|
|
105
|
+
temperature: this.config.temperature,
|
|
106
|
+
top_p: this.config.topP,
|
|
107
|
+
max_tokens: this.config.maxTokens,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Web search API
|
|
112
|
+
*/
|
|
113
|
+
async webSearch(params) {
|
|
114
|
+
const body = {
|
|
115
|
+
search_engine: "search-prime",
|
|
116
|
+
search_query: params.query,
|
|
117
|
+
...(params.count && { count: params.count }),
|
|
118
|
+
...(params.domainFilter && { search_domain_filter: params.domainFilter }),
|
|
119
|
+
...(params.recencyFilter && { search_recency_filter: params.recencyFilter }),
|
|
120
|
+
};
|
|
121
|
+
return withRetry(() => this.request("/web_search", body));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Web reader API
|
|
125
|
+
*/
|
|
126
|
+
async webRead(params) {
|
|
127
|
+
const body = {
|
|
128
|
+
url: params.url,
|
|
129
|
+
return_format: params.format || "markdown",
|
|
130
|
+
retain_images: params.retainImages ?? true,
|
|
131
|
+
with_links_summary: params.withLinksSummary ?? false,
|
|
132
|
+
...(params.timeout && { timeout: params.timeout }),
|
|
133
|
+
};
|
|
134
|
+
return withRetry(() => this.request("/reader", body));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Helper functions for building multimodal messages
|
|
138
|
+
export function createImageContent(url) {
|
|
139
|
+
return { type: "image_url", image_url: { url } };
|
|
140
|
+
}
|
|
141
|
+
export function createVideoContent(url) {
|
|
142
|
+
return { type: "video_url", video_url: { url } };
|
|
143
|
+
}
|
|
144
|
+
export function createTextContent(text) {
|
|
145
|
+
return { type: "text", text };
|
|
146
|
+
}
|
|
147
|
+
export function createMultimodalMessage(contents, role = "user") {
|
|
148
|
+
return { role, content: contents };
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAyG9E;;GAEG;AACH,KAAK,UAAU,SAAS,CACtB,EAAoB,EACpB,UAAU,GAAW,CAAC,EACtB,SAAS,GAAW,IAAI;IAExB,IAAI,SAA4B,CAAC;IAEjC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAc,CAAC;YAE3B,+CAA+C;YAC/C,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;gBAC/B,MAAM,KAAK,CAAC;YACd,CAAC;YAED,8BAA8B;YAC9B,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;gBAC3B,MAAM;YACR,CAAC;YAED,sBAAsB;YACtB,MAAM,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC/C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,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C,OAAO,EAAE,CAAC;SACnD,CAAC;QAEF,OAAO,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAiB,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAED,oDAAoD;AACpD,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,QAA0B,EAC1B,IAAI,GAAsB,MAAM;IAEhC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local response cache for Z.AI API responses.
|
|
3
|
+
*
|
|
4
|
+
* Stores the RAW response from Z.AI (before any post-processing like
|
|
5
|
+
* truncation, format conversion, or extraction) keyed by a hash of the
|
|
6
|
+
* command + request-affecting arguments. Post-processing flags like
|
|
7
|
+
* --max-chars, --output-format, --extract are NOT part of the cache key,
|
|
8
|
+
* so the same cached response can serve multiple presentation variants.
|
|
9
|
+
*
|
|
10
|
+
* Default TTL: 24h. Default size cap: 100MB. LRU eviction when full.
|
|
11
|
+
* Disable per-call with --no-cache.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Build a stable cache key from command + request-affecting args.
|
|
15
|
+
* Post-processing flags (maxChars, outputFormat, extract, fullEnvelope)
|
|
16
|
+
* are intentionally excluded so one cached fetch serves many presentations.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildCacheKey(command: string, requestArgs: Record<string, unknown>): string;
|
|
19
|
+
export declare function isCacheEnabled(): boolean;
|
|
20
|
+
export declare function readCache<T>(key: string, ttlMs?: number): Promise<T | null>;
|
|
21
|
+
export declare function writeCache<T>(key: string, data: T): Promise<void>;
|
|
22
|
+
export declare function clearCache(): Promise<{
|
|
23
|
+
cleared: number;
|
|
24
|
+
bytesFreed: number;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function cacheStats(): Promise<{
|
|
27
|
+
entries: number;
|
|
28
|
+
totalBytes: number;
|
|
29
|
+
dir: string;
|
|
30
|
+
ttlMs: number;
|
|
31
|
+
sizeCapBytes: number;
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/lib/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA8BH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAO3F;AAED,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,SAAiB,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAczF;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAYvE;AAgCD,wBAAsB,UAAU,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAqBnF;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC,CA0BD"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local response cache for Z.AI API responses.
|
|
3
|
+
*
|
|
4
|
+
* Stores the RAW response from Z.AI (before any post-processing like
|
|
5
|
+
* truncation, format conversion, or extraction) keyed by a hash of the
|
|
6
|
+
* command + request-affecting arguments. Post-processing flags like
|
|
7
|
+
* --max-chars, --output-format, --extract are NOT part of the cache key,
|
|
8
|
+
* so the same cached response can serve multiple presentation variants.
|
|
9
|
+
*
|
|
10
|
+
* Default TTL: 24h. Default size cap: 100MB. LRU eviction when full.
|
|
11
|
+
* Disable per-call with --no-cache.
|
|
12
|
+
*/
|
|
13
|
+
import crypto from "node:crypto";
|
|
14
|
+
import * as fs from "node:fs/promises";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { getApiKey } from "./config.js";
|
|
18
|
+
const DEFAULT_TTL_MS = parseInt(process.env.ZAI_CACHE_TTL_MS || "", 10) || 24 * 60 * 60 * 1000;
|
|
19
|
+
const DEFAULT_SIZE_CAP_BYTES = parseInt(process.env.ZAI_CACHE_SIZE_MB || "", 10) * 1024 * 1024 || 100 * 1024 * 1024;
|
|
20
|
+
const CACHE_ENABLED = !["0", "false"].includes((process.env.ZAI_CACHE || "1").toLowerCase());
|
|
21
|
+
function resolveCacheDir() {
|
|
22
|
+
const explicit = process.env.ZAI_CACHE_DIR;
|
|
23
|
+
if (explicit)
|
|
24
|
+
return explicit;
|
|
25
|
+
const xdg = process.env.XDG_CACHE_HOME;
|
|
26
|
+
// Retain the adapter cache location until provider configuration is generalized.
|
|
27
|
+
if (xdg)
|
|
28
|
+
return path.join(xdg, "zai-cli", "responses");
|
|
29
|
+
if (process.platform === "darwin") {
|
|
30
|
+
return path.join(os.homedir(), "Library", "Caches", "zai-cli", "responses");
|
|
31
|
+
}
|
|
32
|
+
return path.join(os.homedir(), ".cache", "zai-cli", "responses");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build a stable cache key from command + request-affecting args.
|
|
36
|
+
* Post-processing flags (maxChars, outputFormat, extract, fullEnvelope)
|
|
37
|
+
* are intentionally excluded so one cached fetch serves many presentations.
|
|
38
|
+
*/
|
|
39
|
+
export function buildCacheKey(command, requestArgs) {
|
|
40
|
+
const apiKey = getApiKey();
|
|
41
|
+
// Namespace by api key hash so different keys never collide
|
|
42
|
+
const keyHash = crypto.createHash("sha256").update(apiKey).digest("hex").slice(0, 12);
|
|
43
|
+
const payload = JSON.stringify({ command, args: requestArgs });
|
|
44
|
+
const argsHash = crypto.createHash("sha256").update(payload).digest("hex").slice(0, 24);
|
|
45
|
+
return `${command}.${keyHash}.${argsHash}.json`;
|
|
46
|
+
}
|
|
47
|
+
export function isCacheEnabled() {
|
|
48
|
+
return CACHE_ENABLED;
|
|
49
|
+
}
|
|
50
|
+
export async function readCache(key, ttlMs = DEFAULT_TTL_MS) {
|
|
51
|
+
if (!CACHE_ENABLED || ttlMs <= 0)
|
|
52
|
+
return null;
|
|
53
|
+
const file = path.join(resolveCacheDir(), key);
|
|
54
|
+
try {
|
|
55
|
+
const raw = await fs.readFile(file, "utf8");
|
|
56
|
+
const entry = JSON.parse(raw);
|
|
57
|
+
if (!entry || typeof entry.ts !== "number")
|
|
58
|
+
return null;
|
|
59
|
+
if (Date.now() - entry.ts > ttlMs)
|
|
60
|
+
return null;
|
|
61
|
+
// Touch the file for LRU freshness (best-effort)
|
|
62
|
+
await fs.utimes(file, new Date(), new Date()).catch(() => { });
|
|
63
|
+
return entry.data;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export async function writeCache(key, data) {
|
|
70
|
+
if (!CACHE_ENABLED)
|
|
71
|
+
return;
|
|
72
|
+
const dir = resolveCacheDir();
|
|
73
|
+
const file = path.join(dir, key);
|
|
74
|
+
try {
|
|
75
|
+
await fs.mkdir(dir, { recursive: true });
|
|
76
|
+
const entry = { ts: Date.now(), data };
|
|
77
|
+
await fs.writeFile(file, JSON.stringify(entry));
|
|
78
|
+
await evictIfNeeded(dir);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Best-effort cache only
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function evictIfNeeded(dir) {
|
|
85
|
+
try {
|
|
86
|
+
const entries = await fs.readdir(dir);
|
|
87
|
+
const stats = await Promise.all(entries.map(async (name) => {
|
|
88
|
+
try {
|
|
89
|
+
const p = path.join(dir, name);
|
|
90
|
+
const s = await fs.stat(p);
|
|
91
|
+
return { name, size: s.size, mtimeMs: s.mtimeMs };
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
const valid = stats.filter((s) => s !== null);
|
|
98
|
+
const totalBytes = valid.reduce((sum, e) => sum + e.size, 0);
|
|
99
|
+
if (totalBytes <= DEFAULT_SIZE_CAP_BYTES)
|
|
100
|
+
return;
|
|
101
|
+
// Evict oldest until under cap
|
|
102
|
+
const sorted = valid.sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
103
|
+
let bytes = totalBytes;
|
|
104
|
+
for (const entry of sorted) {
|
|
105
|
+
if (bytes <= DEFAULT_SIZE_CAP_BYTES * 0.8)
|
|
106
|
+
break;
|
|
107
|
+
await fs.unlink(path.join(dir, entry.name)).catch(() => { });
|
|
108
|
+
bytes -= entry.size;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Best-effort
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export async function clearCache() {
|
|
116
|
+
const dir = resolveCacheDir();
|
|
117
|
+
let cleared = 0;
|
|
118
|
+
let bytesFreed = 0;
|
|
119
|
+
try {
|
|
120
|
+
const entries = await fs.readdir(dir);
|
|
121
|
+
for (const name of entries) {
|
|
122
|
+
const p = path.join(dir, name);
|
|
123
|
+
try {
|
|
124
|
+
const s = await fs.stat(p);
|
|
125
|
+
await fs.unlink(p);
|
|
126
|
+
cleared += 1;
|
|
127
|
+
bytesFreed += s.size;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// skip
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// dir doesn't exist
|
|
136
|
+
}
|
|
137
|
+
return { cleared, bytesFreed };
|
|
138
|
+
}
|
|
139
|
+
export async function cacheStats() {
|
|
140
|
+
const dir = resolveCacheDir();
|
|
141
|
+
let entries = 0;
|
|
142
|
+
let totalBytes = 0;
|
|
143
|
+
try {
|
|
144
|
+
const names = await fs.readdir(dir);
|
|
145
|
+
for (const name of names) {
|
|
146
|
+
try {
|
|
147
|
+
const s = await fs.stat(path.join(dir, name));
|
|
148
|
+
entries += 1;
|
|
149
|
+
totalBytes += s.size;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// skip
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// dir doesn't exist yet
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
entries,
|
|
161
|
+
totalBytes,
|
|
162
|
+
dir,
|
|
163
|
+
ttlMs: DEFAULT_TTL_MS,
|
|
164
|
+
sizeCapBytes: DEFAULT_SIZE_CAP_BYTES,
|
|
165
|
+
enabled: CACHE_ENABLED,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/lib/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;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CAAC,CAAC;gBAC9C,OAAO,IAAI,CAAC,CAAC;gBACb,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,wBAAwB;IAC1B,CAAC;IACD,OAAO;QACL,OAAO;QACP,UAAU;QACV,GAAG;QACH,KAAK,EAAE,cAAc;QACrB,YAAY,EAAE,sBAAsB;QACpC,OAAO,EAAE,aAAa;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Mode client for tool chaining with UTCP
|
|
3
|
+
*/
|
|
4
|
+
import "@utcp/mcp";
|
|
5
|
+
export declare class ZaiCodeModeClient {
|
|
6
|
+
private client;
|
|
7
|
+
private initPromise;
|
|
8
|
+
private isInitialized;
|
|
9
|
+
static getPromptTemplate(): string;
|
|
10
|
+
private init;
|
|
11
|
+
private _doInit;
|
|
12
|
+
callToolChain(code: string, timeoutMs?: number): Promise<{
|
|
13
|
+
result: unknown;
|
|
14
|
+
logs: string[];
|
|
15
|
+
}>;
|
|
16
|
+
getAllInterfaces(): Promise<string>;
|
|
17
|
+
close(timeoutMs?: number): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=code-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-mode.d.ts","sourceRoot":"","sources":["../../src/lib/code-mode.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,WAAW,CAAC;AAMnB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,aAAa,CAAS;IAE9B,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAEjC;YAEa,IAAI;YAOJ,OAAO;IA0Cf,aAAa,CACjB,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAO9C;IAEK,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,CAMxC;IAEK,KAAK,CAAC,SAAS,GAAE,MAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnD;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Mode client for tool chaining with UTCP
|
|
3
|
+
*/
|
|
4
|
+
import { CodeModeUtcpClient } from "@utcp/code-mode";
|
|
5
|
+
import "@utcp/mcp";
|
|
6
|
+
import { buildMcpCallTemplate } from "./mcp-config.js";
|
|
7
|
+
import { ApiError, AuthError, NetworkError, TimeoutError } from "./errors.js";
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = parseInt(process.env.Z_AI_TIMEOUT || "30000", 10);
|
|
9
|
+
export class ZaiCodeModeClient {
|
|
10
|
+
client = null;
|
|
11
|
+
initPromise = null;
|
|
12
|
+
isInitialized = false;
|
|
13
|
+
static getPromptTemplate() {
|
|
14
|
+
return CodeModeUtcpClient.AGENT_PROMPT_TEMPLATE;
|
|
15
|
+
}
|
|
16
|
+
async init() {
|
|
17
|
+
if (this.isInitialized)
|
|
18
|
+
return;
|
|
19
|
+
if (this.initPromise)
|
|
20
|
+
return this.initPromise;
|
|
21
|
+
this.initPromise = this._doInit();
|
|
22
|
+
return this.initPromise;
|
|
23
|
+
}
|
|
24
|
+
async _doInit() {
|
|
25
|
+
try {
|
|
26
|
+
this.client = await CodeModeUtcpClient.create();
|
|
27
|
+
const result = await this.client.registerManual(buildMcpCallTemplate());
|
|
28
|
+
if (!result.success) {
|
|
29
|
+
throw new ApiError(`Failed to register MCP servers: ${result.errors.join(", ")}`, 500);
|
|
30
|
+
}
|
|
31
|
+
this.isInitialized = true;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.initPromise = null;
|
|
35
|
+
if (error instanceof ApiError) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
if (error instanceof Error) {
|
|
39
|
+
if (error.message.includes("401") ||
|
|
40
|
+
error.message.includes("403") ||
|
|
41
|
+
error.message.includes("auth")) {
|
|
42
|
+
throw new AuthError(`Authentication failed: ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
if (error.message.includes("timeout") || error.message.includes("ETIMEDOUT")) {
|
|
45
|
+
throw new TimeoutError(DEFAULT_TIMEOUT_MS);
|
|
46
|
+
}
|
|
47
|
+
if (error.message.includes("ECONNREFUSED") ||
|
|
48
|
+
error.message.includes("network") ||
|
|
49
|
+
error.message.includes("fetch")) {
|
|
50
|
+
throw new NetworkError(error.message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new ApiError(`Code Mode initialization failed: ${error instanceof Error ? error.message : String(error)}`, 500);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async callToolChain(code, timeoutMs) {
|
|
57
|
+
await this.init();
|
|
58
|
+
if (!this.client) {
|
|
59
|
+
throw new ApiError("Code Mode client not initialized", 500);
|
|
60
|
+
}
|
|
61
|
+
const timeout = timeoutMs ?? 30000;
|
|
62
|
+
return this.client.callToolChain(code, timeout);
|
|
63
|
+
}
|
|
64
|
+
async getAllInterfaces() {
|
|
65
|
+
await this.init();
|
|
66
|
+
if (!this.client) {
|
|
67
|
+
throw new ApiError("Code Mode client not initialized", 500);
|
|
68
|
+
}
|
|
69
|
+
return this.client.getAllToolsTypeScriptInterfaces();
|
|
70
|
+
}
|
|
71
|
+
async close(timeoutMs = 2000) {
|
|
72
|
+
if (this.client) {
|
|
73
|
+
await Promise.race([
|
|
74
|
+
this.client.close(),
|
|
75
|
+
new Promise((resolve) => setTimeout(resolve, timeoutMs)),
|
|
76
|
+
]);
|
|
77
|
+
this.client = null;
|
|
78
|
+
this.isInitialized = false;
|
|
79
|
+
this.initPromise = null;
|
|
80
|
+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|
+
apiKey: string;
|
|
6
|
+
mode: "ZAI" | "ZHIPU";
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
timeout: number;
|
|
9
|
+
visionModel: string;
|
|
10
|
+
temperature: number;
|
|
11
|
+
topP: number;
|
|
12
|
+
maxTokens: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function loadConfig(): ZaiConfig;
|
|
15
|
+
export declare function getMcpEndpoints(): {
|
|
16
|
+
readonly ZREAD: "https://api.z.ai/api/mcp/zread/mcp";
|
|
17
|
+
readonly WEB_SEARCH: "https://api.z.ai/api/mcp/web_search_prime/mcp";
|
|
18
|
+
readonly WEB_READER: "https://api.z.ai/api/mcp/web_reader/mcp";
|
|
19
|
+
};
|
|
20
|
+
export declare function getApiKey(): string;
|
|
21
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAeD,wBAAgB,UAAU,IAAI,SAAS,CAuCtC;AAED,wBAAgB,eAAe;oBA9CtB,oCAAoC;yBAC/B,+CAA+C;yBAC/C,yCAAyC;EA8CtD;AAED,wBAAgB,SAAS,IAAI,MAAM,CAiBlC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration and environment loading for Scoutline
|
|
3
|
+
*/
|
|
4
|
+
const BASE_URLS = {
|
|
5
|
+
// Z.AI Coding Plan requires the /coding/ endpoint
|
|
6
|
+
ZAI: "https://api.z.ai/api/coding/paas/v4",
|
|
7
|
+
ZHIPU: "https://open.bigmodel.cn/api/paas/v4",
|
|
8
|
+
};
|
|
9
|
+
// MCP server endpoints
|
|
10
|
+
const MCP_ENDPOINTS = {
|
|
11
|
+
ZREAD: "https://api.z.ai/api/mcp/zread/mcp",
|
|
12
|
+
WEB_SEARCH: "https://api.z.ai/api/mcp/web_search_prime/mcp",
|
|
13
|
+
WEB_READER: "https://api.z.ai/api/mcp/web_reader/mcp",
|
|
14
|
+
};
|
|
15
|
+
export function loadConfig() {
|
|
16
|
+
const apiKey = process.env.Z_AI_API_KEY || process.env.ZAI_API_KEY;
|
|
17
|
+
if (!apiKey) {
|
|
18
|
+
console.error(JSON.stringify({
|
|
19
|
+
success: false,
|
|
20
|
+
error: "Z_AI_API_KEY environment variable is required",
|
|
21
|
+
help: [
|
|
22
|
+
"To set it:",
|
|
23
|
+
' export Z_AI_API_KEY="your-api-key"',
|
|
24
|
+
"",
|
|
25
|
+
"Get your API key at:",
|
|
26
|
+
" https://z.ai/manage-apikey/apikey-list",
|
|
27
|
+
].join("\n"),
|
|
28
|
+
}, null, 2));
|
|
29
|
+
process.exit(3);
|
|
30
|
+
}
|
|
31
|
+
const mode = (process.env.Z_AI_MODE || process.env.PLATFORM_MODE || "ZAI").toUpperCase();
|
|
32
|
+
const baseUrl = process.env.Z_AI_BASE_URL || BASE_URLS[mode] || BASE_URLS.ZAI;
|
|
33
|
+
return {
|
|
34
|
+
apiKey,
|
|
35
|
+
mode,
|
|
36
|
+
baseUrl,
|
|
37
|
+
timeout: parseInt(process.env.Z_AI_TIMEOUT || "30000", 10),
|
|
38
|
+
visionModel: process.env.Z_AI_VISION_MODEL || "glm-4.6v",
|
|
39
|
+
temperature: parseFloat(process.env.Z_AI_TEMPERATURE || "0.8"),
|
|
40
|
+
topP: parseFloat(process.env.Z_AI_TOP_P || "0.6"),
|
|
41
|
+
maxTokens: parseInt(process.env.Z_AI_MAX_TOKENS || "32768", 10),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function getMcpEndpoints() {
|
|
45
|
+
return MCP_ENDPOINTS;
|
|
46
|
+
}
|
|
47
|
+
export function getApiKey() {
|
|
48
|
+
const apiKey = process.env.Z_AI_API_KEY || process.env.ZAI_API_KEY;
|
|
49
|
+
if (!apiKey) {
|
|
50
|
+
console.error(JSON.stringify({
|
|
51
|
+
success: false,
|
|
52
|
+
error: "Z_AI_API_KEY environment variable is required",
|
|
53
|
+
help: 'export Z_AI_API_KEY="your-api-key"',
|
|
54
|
+
}, null, 2));
|
|
55
|
+
process.exit(3);
|
|
56
|
+
}
|
|
57
|
+
return apiKey;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH,MAAM,SAAS,GAAG;IAChB,kDAAkD;IAClD,GAAG,EAAE,qCAAqC;IAC1C,KAAK,EAAE,sCAAsC;CACrC,CAAC;AAEX,uBAAuB;AACvB,MAAM,aAAa,GAAG;IACpB,KAAK,EAAE,oCAAoC;IAC3C,UAAU,EAAE,+CAA+C;IAC3D,UAAU,EAAE,yCAAyC;CAC7C,CAAC;AAEX,MAAM,UAAU,UAAU;IACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAEnE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CACX,IAAI,CAAC,SAAS,CACZ;YACE,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,+CAA+C;YACtD,IAAI,EAAE;gBACJ,YAAY;gBACZ,sCAAsC;gBACtC,EAAE;gBACF,sBAAsB;gBACtB,0CAA0C;aAC3C,CAAC,IAAI,CAAC,IAAI,CAAC;SACb,EACD,IAAI,EACJ,CAAC,CACF,CAC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IAClB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types and handling for Scoutline
|
|
3
|
+
*/
|
|
4
|
+
export declare class ZaiError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
statusCode?: number | undefined;
|
|
7
|
+
help?: string | undefined;
|
|
8
|
+
constructor(message: string, code: string, statusCode?: number | undefined, help?: string | undefined);
|
|
9
|
+
}
|
|
10
|
+
export declare class AuthError extends ZaiError {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ValidationError extends ZaiError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class ApiError extends ZaiError {
|
|
17
|
+
constructor(message: string, statusCode: number);
|
|
18
|
+
}
|
|
19
|
+
export declare class NetworkError extends ZaiError {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class TimeoutError extends ZaiError {
|
|
23
|
+
constructor(timeoutMs: number);
|
|
24
|
+
}
|
|
25
|
+
export declare class FileError extends ZaiError {
|
|
26
|
+
constructor(message: string, help?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare function formatErrorOutput(error: unknown): string;
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,QAAS,SAAQ,KAAK;IAGxB,IAAI,EAAE,MAAM;IACZ,UAAU,CAAC,EAAE,MAAM;IACnB,IAAI,CAAC,EAAE,MAAM;IAJtB,YACE,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,IAAI,CAAC,EAAE,MAAM,YAAA,EAIrB;CACF;AAED,qBAAa,SAAU,SAAQ,QAAQ;IACrC,YAAY,OAAO,EAAE,MAAM,EAE1B;CACF;AAED,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,YAAY,OAAO,EAAE,MAAM,EAE1B;CACF;AAED,qBAAa,QAAS,SAAQ,QAAQ;IACpC,YAAY,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAE9C;CACF;AAED,qBAAa,YAAa,SAAQ,QAAQ;IACxC,YAAY,OAAO,EAAE,MAAM,EAE1B;CACF;AAED,qBAAa,YAAa,SAAQ,QAAQ;IACxC,YAAY,SAAS,EAAE,MAAM,EAO5B;CACF;AAED,qBAAa,SAAU,SAAQ,QAAQ;IACrC,YAAY,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAEzC;CACF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAoCxD"}
|