@alint-js/core 0.0.21 → 0.0.23

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.
@@ -1,4 +1,4 @@
1
- import { W as ResolvedModel, g as RuleContext } from "./types-DQfoxG8J.mjs";
1
+ import { $ as ResolvedModel, v as RuleContext } from "./types-CIqhJ96f.mjs";
2
2
  import { GenericSchema, InferOutput } from "valibot";
3
3
  import { JsonSchema } from "@valibot/to-json-schema";
4
4
  import { Message } from "@xsai/shared-chat";
@@ -57,8 +57,9 @@ async function generateStructured(options) {
57
57
  tools: [tool]
58
58
  });
59
59
  } catch (error) {
60
- previousError = `Tool call failed before validation: ${errorMessageFrom(error) ?? String(error)}`;
61
- options.logger?.debug(`${options.operation} attempt ${attempt} failed while calling the model: ${previousError}`);
60
+ const callError = `Tool call failed before validation: ${errorMessageFrom(error) ?? String(error)}`;
61
+ previousError = isRetriableHttpError(error) ? void 0 : callError;
62
+ options.logger?.debug(`${options.operation} attempt ${attempt} failed while calling the model: ${callError}`);
62
63
  if (!isRetriableCallError(error) || attempt === maxAttempts) throw error;
63
64
  await sleep(retryDelay(attempt));
64
65
  continue;
@@ -89,8 +90,14 @@ function exponentialRetryDelay(attempt) {
89
90
  }
90
91
  function isRetriableCallError(error) {
91
92
  if (!(error instanceof Error)) return true;
93
+ if (isRetriableHttpError(error)) return true;
92
94
  return error.name === "InvalidToolCallError" || error.name === "InvalidToolInputError" || error.name === "ToolExecutionError";
93
95
  }
96
+ function isRetriableHttpError(error) {
97
+ if (!(error instanceof Error)) return false;
98
+ const statusCode = "statusCode" in error && typeof error.statusCode === "number" ? error.statusCode : void 0;
99
+ return statusCode !== void 0 && (statusCode >= 500 || [408, 429].includes(statusCode));
100
+ }
94
101
  function normalizeJsonSchemaDefinition(schema) {
95
102
  if (typeof schema === "boolean") return schema;
96
103
  const normalized = { ...schema };
@@ -95,6 +95,9 @@ interface AgentUsage {
95
95
  }
96
96
  //#endregion
97
97
  //#region src/core/source/types.d.ts
98
+ type ClassTarget = SourceTargetOfKind<'class'>;
99
+ type FileTarget = SourceTargetOfKind<'file'>;
100
+ type FunctionTarget = SourceTargetOfKind<'function'>;
98
101
  interface LanguageContext {
99
102
  cwd: string;
100
103
  languageOptions: Record<string, unknown>;
@@ -162,6 +165,9 @@ interface SourceTarget {
162
165
  text: string;
163
166
  }
164
167
  type SourceTargetKind = 'class' | 'file' | 'fragment' | 'function' | 'symbol' | (string & {});
168
+ type SourceTargetOfKind<Kind extends SourceTargetKind> = Omit<SourceTarget, 'kind'> & {
169
+ kind: Kind;
170
+ };
165
171
  interface SourceTargetOrigin {
166
172
  physicalPath: string;
167
173
  range?: SourceRange;
@@ -180,6 +186,7 @@ type AlintConfigInput = AlintConfigItem | readonly AlintConfigInput[];
180
186
  interface AlintConfigItem {
181
187
  agent?: AgentAdapter;
182
188
  basePath?: string;
189
+ directories?: readonly (readonly string[] | string)[];
183
190
  extends?: readonly AlintConfigExtends[];
184
191
  files?: readonly (readonly string[] | string)[];
185
192
  ignore?: IgnoreConfig;
@@ -215,6 +222,10 @@ interface DiagnosticLocation {
215
222
  line: number;
216
223
  };
217
224
  }
225
+ interface DirectoryTarget {
226
+ kind: 'directory';
227
+ path: string;
228
+ }
218
229
  interface EnabledRule {
219
230
  id: string;
220
231
  localId: string;
@@ -239,6 +250,12 @@ interface ProcessorDefinition {
239
250
  postprocess?: (diagnostics: DiagnosticDescriptor[], context: ProcessorPostprocessContext) => Awaitable<DiagnosticDescriptor[]>;
240
251
  preprocess: (file: SourceFile, context: ProcessorContext) => Awaitable<ProcessedSource[]>;
241
252
  }
253
+ interface ProjectTarget {
254
+ files: SourceFile[];
255
+ kind: 'project';
256
+ root: string;
257
+ targets: SourceTarget[];
258
+ }
242
259
  type RuleCacheConfig = boolean | {
243
260
  level?: 'target';
244
261
  };
@@ -262,12 +279,12 @@ interface RuleContext {
262
279
  }
263
280
  interface RuleDefinition {
264
281
  cache?: RuleCacheConfig;
282
+ /** Additional stable rule inputs, such as imported prompts, that invalidate cached results when changed. */
283
+ cacheKey?: unknown;
265
284
  create: (context: RuleContext) => RuleHandlers;
266
285
  model?: ModelRequirement;
267
286
  }
268
- interface RuleHandlers {
269
- onTarget?: (target: SourceTarget) => Awaitable<void>;
270
- }
287
+ type RuleHandlers = RuleSpecializedHandlers | RuleWithHandler;
271
288
  interface RuleInferenceUsageRecord {
272
289
  filePath?: string;
273
290
  inputTokens?: number;
@@ -283,5 +300,22 @@ interface RuleRegistry {
283
300
  rules: Map<string, RuleDefinition>;
284
301
  }
285
302
  type RuleSeverity = 'error' | 'off' | 'warn';
303
+ interface RuleSpecializedHandlers {
304
+ onTargetClass?: (target: ClassTarget) => Awaitable<void>;
305
+ onTargetDirectory?: (target: DirectoryTarget) => Awaitable<void>;
306
+ onTargetFile?: (target: FileTarget) => Awaitable<void>;
307
+ onTargetFunction?: (target: FunctionTarget) => Awaitable<void>;
308
+ onTargetProject?: (target: ProjectTarget) => Awaitable<void>;
309
+ onTargetWith?: never;
310
+ }
311
+ interface RuleWithHandler {
312
+ onTargetClass?: never;
313
+ onTargetDirectory?: never;
314
+ onTargetFile?: never;
315
+ onTargetFunction?: never;
316
+ onTargetProject?: never;
317
+ onTargetWith: (target: Target) => Awaitable<void>;
318
+ }
319
+ type Target = DirectoryTarget | ProjectTarget | SourceTarget;
286
320
  //#endregion
287
- export { SourcePosition as A, AgentTool as B, LineRange as C, ProcessorPostprocessContext as D, ProcessorContext as E, SourceTargetOrigin as F, ResolvedProvider as G, ModelRequirement as H, SourceText as I, ProviderType as J, ModelSize as K, AgentAdapter as L, SourceRuntime as M, SourceTarget as N, SourceFile as O, SourceTargetKind as P, SetupModelDefinition as Q, AgentRequest as R, LanguageContext as S, ProcessedSourceOrigin as T, ResolveModelOptions as U, AgentUsage as V, ResolvedModel as W, RunnerStatsConfig as X, RunnerConfig as Y, SetupConfig as Z, RuleDefinition as _, AlintLinterOptions as a, RuleRegistry as b, DiagnosticLocation as c, LanguageDefinition as d, PluginDefinition as f, RuleContext as g, RuleConfigEntry as h, AlintConfigItem as i, SourceRange as j, SourceLocation as k, EnabledRule as l, RuleCacheConfig as m, AlintConfigExtends as n, Awaitable as o, ProcessorDefinition as p, ProviderDefinition as q, AlintConfigInput as r, DiagnosticDescriptor as s, AlintConfig as t, IgnoreConfig as u, RuleHandlers as v, ProcessedSource as w, RuleSeverity as x, RuleInferenceUsageRecord as y, AgentResult as z };
321
+ export { ResolvedModel as $, LanguageContext as A, SourceRuntime as B, RuleSeverity as C, ClassTarget as D, Target as E, ProcessorPostprocessContext as F, SourceText as G, SourceTargetKind as H, SourceFile as I, AgentResult as J, AgentAdapter as K, SourceLocation as L, ProcessedSource as M, ProcessedSourceOrigin as N, FileTarget as O, ProcessorContext as P, ResolveModelOptions as Q, SourcePosition as R, RuleRegistry as S, RuleWithHandler as T, SourceTargetOfKind as U, SourceTarget as V, SourceTargetOrigin as W, AgentUsage as X, AgentTool as Y, ModelRequirement as Z, RuleConfigEntry as _, AlintLinterOptions as a, RunnerStatsConfig as at, RuleHandlers as b, DiagnosticLocation as c, IgnoreConfig as d, ResolvedProvider as et, LanguageDefinition as f, RuleCacheConfig as g, ProjectTarget as h, AlintConfigItem as i, RunnerConfig as it, LineRange as j, FunctionTarget as k, DirectoryTarget as l, ProcessorDefinition as m, AlintConfigExtends as n, ProviderDefinition as nt, Awaitable as o, SetupConfig as ot, PluginDefinition as p, AgentRequest as q, AlintConfigInput as r, ProviderType as rt, DiagnosticDescriptor as s, SetupModelDefinition as st, AlintConfig as t, ModelSize as tt, EnabledRule as u, RuleContext as v, RuleSpecializedHandlers as w, RuleInferenceUsageRecord as x, RuleDefinition as y, SourceRange as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alint-js/core",
3
3
  "type": "module",
4
- "version": "0.0.21",
4
+ "version": "0.0.23",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.mts",
@@ -23,21 +23,15 @@
23
23
  "dependencies": {
24
24
  "@moeru/std": "^0.1.0-beta.18",
25
25
  "@valibot/to-json-schema": "^1.7.1",
26
- "@xsai/generate-text": "^0.5.0-beta.6",
27
- "@xsai/shared-chat": "^0.5.0-beta.6",
28
- "@xsai/tool": "^0.5.0-beta.6",
26
+ "@xsai/generate-text": "^0.5.0-beta.7",
27
+ "@xsai/shared-chat": "^0.5.0-beta.7",
28
+ "@xsai/tool": "^0.5.0-beta.7",
29
29
  "es-toolkit": "^1.49.0",
30
30
  "minimatch": "^10.2.5",
31
31
  "oxc-parser": "^0.137.0",
32
32
  "pathe": "^2.0.3",
33
33
  "valibot": "^1.4.1"
34
34
  },
35
- "devDependencies": {
36
- "@types/node": "^26.0.1",
37
- "tsdown": "^0.22.3",
38
- "typescript": "^6.0.3",
39
- "vitest": "^4.1.9"
40
- },
41
35
  "scripts": {
42
36
  "build": "tsdown",
43
37
  "typecheck": "tsc -p tsconfig.json --noEmit",