@graphext/cuery 0.4.0 → 0.5.2
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/esm/browser.d.ts +1 -1
- package/esm/browser.d.ts.map +1 -1
- package/esm/browser.js +1 -1
- package/esm/mod.d.ts +5 -2
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -2
- package/esm/src/api.d.ts +36 -5
- package/esm/src/api.d.ts.map +1 -1
- package/esm/src/api.js +84 -37
- package/esm/src/apis/chatgptScraper/brightdata.js +1 -1
- package/esm/src/apis/chatgptScraper/oxy.js +1 -1
- package/esm/src/apis/chatgptScraper/scraper.js +2 -2
- package/esm/src/apis/hasdata/aim.js +1 -1
- package/esm/src/apis/hasdata/aio.js +1 -1
- package/esm/src/apis/hasdata/helpers.d.ts +1 -1
- package/esm/src/apis/hasdata/helpers.d.ts.map +1 -1
- package/esm/src/apis/hasdata/helpers.js +2 -2
- package/esm/src/assets/models.d.ts +60725 -0
- package/esm/src/assets/models.d.ts.map +1 -0
- package/esm/src/assets/models.js +71915 -0
- package/esm/src/helpers/async.d.ts.map +1 -0
- package/esm/src/{async.js → helpers/async.js} +1 -1
- package/esm/src/helpers/seedKeywords.d.ts.map +1 -0
- package/esm/src/helpers/urls.d.ts.map +1 -0
- package/esm/src/helpers/utils.d.ts.map +1 -0
- package/esm/src/llm.d.ts +35 -0
- package/esm/src/llm.d.ts.map +1 -0
- package/esm/src/llm.js +59 -0
- package/esm/src/providers/google.d.ts +12 -0
- package/esm/src/providers/google.d.ts.map +1 -0
- package/esm/src/providers/google.js +111 -0
- package/esm/src/providers/index.d.ts +13 -0
- package/esm/src/providers/index.d.ts.map +1 -0
- package/esm/src/providers/index.js +14 -0
- package/esm/src/providers/openai.d.ts +12 -0
- package/esm/src/providers/openai.d.ts.map +1 -0
- package/esm/src/providers/openai.js +141 -0
- package/esm/src/providers/pricing.d.ts +72 -0
- package/esm/src/providers/pricing.d.ts.map +1 -0
- package/esm/src/providers/pricing.js +88 -0
- package/esm/src/providers/registry.d.ts +20 -0
- package/esm/src/providers/registry.d.ts.map +1 -0
- package/esm/src/providers/registry.js +35 -0
- package/esm/src/providers/types.d.ts +49 -0
- package/esm/src/providers/types.d.ts.map +1 -0
- package/esm/src/providers/types.js +7 -0
- package/esm/src/response.d.ts +74 -0
- package/esm/src/response.d.ts.map +1 -0
- package/esm/src/response.js +110 -0
- package/esm/src/tool.d.ts +58 -0
- package/esm/src/tool.d.ts.map +1 -0
- package/esm/src/tool.js +91 -0
- package/esm/src/tools/brands.js +6 -6
- package/esm/src/tools/classifier.d.ts +80 -17
- package/esm/src/tools/classifier.d.ts.map +1 -1
- package/esm/src/tools/classifier.js +68 -80
- package/esm/src/tools/entities.d.ts +23 -12
- package/esm/src/tools/entities.d.ts.map +1 -1
- package/esm/src/tools/entities.js +27 -47
- package/esm/src/tools/funnel.js +7 -7
- package/esm/src/tools/generic.d.ts +17 -4
- package/esm/src/tools/generic.d.ts.map +1 -1
- package/esm/src/tools/generic.js +39 -14
- package/esm/src/tools/keywords.js +5 -5
- package/esm/src/tools/personas.d.ts +49 -2
- package/esm/src/tools/personas.d.ts.map +1 -1
- package/esm/src/tools/personas.js +59 -35
- package/esm/src/tools/scorer.d.ts +24 -6
- package/esm/src/tools/scorer.d.ts.map +1 -1
- package/esm/src/tools/scorer.js +27 -22
- package/esm/src/tools/search.d.ts.map +1 -1
- package/esm/src/tools/search.js +33 -9
- package/esm/src/tools/sentiment.d.ts +30 -8
- package/esm/src/tools/sentiment.d.ts.map +1 -1
- package/esm/src/tools/sentiment.js +33 -28
- package/esm/src/tools/sources.d.ts +5 -5
- package/esm/src/tools/sources.d.ts.map +1 -1
- package/esm/src/tools/sources.js +5 -6
- package/esm/src/tools/topics.d.ts +44 -16
- package/esm/src/tools/topics.d.ts.map +1 -1
- package/esm/src/tools/topics.js +77 -68
- package/esm/src/tools/translate.d.ts +22 -31
- package/esm/src/tools/translate.d.ts.map +1 -1
- package/esm/src/tools/translate.js +40 -36
- package/package.json +2 -1
- package/script/browser.d.ts +1 -1
- package/script/browser.d.ts.map +1 -1
- package/script/browser.js +1 -1
- package/script/mod.d.ts +5 -2
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -2
- package/script/src/api.d.ts +36 -5
- package/script/src/api.d.ts.map +1 -1
- package/script/src/api.js +84 -35
- package/script/src/apis/chatgptScraper/brightdata.js +1 -1
- package/script/src/apis/chatgptScraper/oxy.js +1 -1
- package/script/src/apis/chatgptScraper/scraper.js +2 -2
- package/script/src/apis/hasdata/aim.js +1 -1
- package/script/src/apis/hasdata/aio.js +1 -1
- package/script/src/apis/hasdata/helpers.d.ts +1 -1
- package/script/src/apis/hasdata/helpers.d.ts.map +1 -1
- package/script/src/apis/hasdata/helpers.js +2 -2
- package/script/src/assets/models.d.ts +60725 -0
- package/script/src/assets/models.d.ts.map +1 -0
- package/script/src/assets/models.js +71917 -0
- package/script/src/helpers/async.d.ts.map +1 -0
- package/script/src/{async.js → helpers/async.js} +1 -1
- package/script/src/helpers/seedKeywords.d.ts.map +1 -0
- package/script/src/helpers/urls.d.ts.map +1 -0
- package/script/src/helpers/utils.d.ts.map +1 -0
- package/script/src/llm.d.ts +35 -0
- package/script/src/llm.d.ts.map +1 -0
- package/script/src/llm.js +65 -0
- package/script/src/providers/google.d.ts +12 -0
- package/script/src/providers/google.d.ts.map +1 -0
- package/script/src/providers/google.js +148 -0
- package/script/src/providers/index.d.ts +13 -0
- package/script/src/providers/index.d.ts.map +1 -0
- package/script/src/providers/index.js +24 -0
- package/script/src/providers/openai.d.ts +12 -0
- package/script/src/providers/openai.d.ts.map +1 -0
- package/script/src/providers/openai.js +181 -0
- package/script/src/providers/pricing.d.ts +72 -0
- package/script/src/providers/pricing.d.ts.map +1 -0
- package/script/src/providers/pricing.js +97 -0
- package/script/src/providers/registry.d.ts +20 -0
- package/script/src/providers/registry.d.ts.map +1 -0
- package/script/src/providers/registry.js +39 -0
- package/script/src/providers/types.d.ts +49 -0
- package/script/src/providers/types.d.ts.map +1 -0
- package/script/src/providers/types.js +8 -0
- package/script/src/response.d.ts +74 -0
- package/script/src/response.d.ts.map +1 -0
- package/script/src/response.js +114 -0
- package/script/src/tool.d.ts +58 -0
- package/script/src/tool.d.ts.map +1 -0
- package/script/src/tool.js +95 -0
- package/script/src/tools/brands.js +6 -6
- package/script/src/tools/classifier.d.ts +80 -17
- package/script/src/tools/classifier.d.ts.map +1 -1
- package/script/src/tools/classifier.js +72 -85
- package/script/src/tools/entities.d.ts +23 -12
- package/script/src/tools/entities.d.ts.map +1 -1
- package/script/src/tools/entities.js +29 -51
- package/script/src/tools/funnel.js +7 -7
- package/script/src/tools/generic.d.ts +17 -4
- package/script/src/tools/generic.d.ts.map +1 -1
- package/script/src/tools/generic.js +39 -14
- package/script/src/tools/keywords.js +5 -5
- package/script/src/tools/personas.d.ts +49 -2
- package/script/src/tools/personas.d.ts.map +1 -1
- package/script/src/tools/personas.js +63 -36
- package/script/src/tools/scorer.d.ts +24 -6
- package/script/src/tools/scorer.d.ts.map +1 -1
- package/script/src/tools/scorer.js +28 -24
- package/script/src/tools/search.d.ts.map +1 -1
- package/script/src/tools/search.js +69 -9
- package/script/src/tools/sentiment.d.ts +30 -8
- package/script/src/tools/sentiment.d.ts.map +1 -1
- package/script/src/tools/sentiment.js +37 -30
- package/script/src/tools/sources.d.ts +5 -5
- package/script/src/tools/sources.d.ts.map +1 -1
- package/script/src/tools/sources.js +4 -5
- package/script/src/tools/topics.d.ts +44 -16
- package/script/src/tools/topics.d.ts.map +1 -1
- package/script/src/tools/topics.js +80 -72
- package/script/src/tools/translate.d.ts +22 -31
- package/script/src/tools/translate.d.ts.map +1 -1
- package/script/src/tools/translate.js +43 -40
- package/esm/src/async.d.ts.map +0 -1
- package/esm/src/models.d.ts +0 -18
- package/esm/src/models.d.ts.map +0 -1
- package/esm/src/models.js +0 -48
- package/esm/src/openai.d.ts +0 -17
- package/esm/src/openai.d.ts.map +0 -1
- package/esm/src/openai.js +0 -136
- package/esm/src/tools/seedKeywords.d.ts.map +0 -1
- package/esm/src/urls.d.ts.map +0 -1
- package/esm/src/utils.d.ts.map +0 -1
- package/script/src/async.d.ts.map +0 -1
- package/script/src/models.d.ts +0 -18
- package/script/src/models.d.ts.map +0 -1
- package/script/src/models.js +0 -52
- package/script/src/openai.d.ts +0 -17
- package/script/src/openai.d.ts.map +0 -1
- package/script/src/openai.js +0 -175
- package/script/src/tools/seedKeywords.d.ts.map +0 -1
- package/script/src/urls.d.ts.map +0 -1
- package/script/src/utils.d.ts.map +0 -1
- /package/esm/src/{async.d.ts → helpers/async.d.ts} +0 -0
- /package/esm/src/{tools → helpers}/seedKeywords.d.ts +0 -0
- /package/esm/src/{tools → helpers}/seedKeywords.js +0 -0
- /package/esm/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
- /package/esm/src/{urls.js → helpers/urls.js} +0 -0
- /package/esm/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
- /package/esm/src/{utils.js → helpers/utils.js} +0 -0
- /package/script/src/{async.d.ts → helpers/async.d.ts} +0 -0
- /package/script/src/{tools → helpers}/seedKeywords.d.ts +0 -0
- /package/script/src/{tools → helpers}/seedKeywords.js +0 -0
- /package/script/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
- /package/script/src/{urls.js → helpers/urls.js} +0 -0
- /package/script/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
- /package/script/src/{utils.js → helpers/utils.js} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider registry - instantiates LLM providers by name or model ID.
|
|
3
|
+
*/
|
|
4
|
+
import { OpenAIProvider } from './openai.js';
|
|
5
|
+
import { GoogleProvider } from './google.js';
|
|
6
|
+
/**
|
|
7
|
+
* Get a provider by name.
|
|
8
|
+
* Creates a fresh provider instance each time to support different API keys.
|
|
9
|
+
* @param name - Provider name ('openai', 'google')
|
|
10
|
+
* @param apiKey - Optional API key. If not provided, uses environment variable.
|
|
11
|
+
*/
|
|
12
|
+
export function getProvider(name, apiKey) {
|
|
13
|
+
switch (name) {
|
|
14
|
+
case 'google':
|
|
15
|
+
return new GoogleProvider(apiKey);
|
|
16
|
+
case 'openai':
|
|
17
|
+
default:
|
|
18
|
+
return new OpenAIProvider(apiKey);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the appropriate provider for a model ID.
|
|
23
|
+
* Infers provider from model name prefix.
|
|
24
|
+
* Creates a fresh provider instance each time to support different API keys.
|
|
25
|
+
* @param modelId - Model identifier (e.g., 'gpt-4.1', 'gemini-2.0-flash')
|
|
26
|
+
* @param apiKey - Optional API key. If not provided, uses environment variable.
|
|
27
|
+
*/
|
|
28
|
+
export function getProviderForModel(modelId, apiKey) {
|
|
29
|
+
const modelLower = modelId.toLowerCase();
|
|
30
|
+
if (modelLower.startsWith('gemini')) {
|
|
31
|
+
return new GoogleProvider(apiKey);
|
|
32
|
+
}
|
|
33
|
+
// Default to OpenAI for gpt-*, o1-*, o3-*, and unknown models
|
|
34
|
+
return new OpenAIProvider(apiKey);
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core LLM types - provider-agnostic interfaces.
|
|
3
|
+
*
|
|
4
|
+
* This module is the foundation of the provider system.
|
|
5
|
+
* It has no dependencies on other modules to avoid circular imports.
|
|
6
|
+
*/
|
|
7
|
+
import type { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
8
|
+
import type { TokenUsage } from '../response.js';
|
|
9
|
+
/**
|
|
10
|
+
* A message in an LLM conversation.
|
|
11
|
+
*/
|
|
12
|
+
export interface Message {
|
|
13
|
+
role: 'system' | 'user' | 'assistant';
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Response from an LLM provider.
|
|
18
|
+
*/
|
|
19
|
+
export interface LLMResponse<T> {
|
|
20
|
+
parsed: T | null;
|
|
21
|
+
text: string | null;
|
|
22
|
+
usage: TokenUsage | null;
|
|
23
|
+
error: Error | null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Provider-specific parameters passed through to the underlying API.
|
|
27
|
+
*/
|
|
28
|
+
export type ProviderParams = Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Interface for LLM providers.
|
|
31
|
+
*/
|
|
32
|
+
export interface LLMProvider {
|
|
33
|
+
/** Provider name (e.g., 'openai', 'gemini') */
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/**
|
|
36
|
+
* Make a completion request to the LLM.
|
|
37
|
+
*
|
|
38
|
+
* @param messages - The conversation messages
|
|
39
|
+
* @param model - The model identifier
|
|
40
|
+
* @param schema - Optional Zod schema for structured output
|
|
41
|
+
* @param params - Provider-specific parameters
|
|
42
|
+
*/
|
|
43
|
+
complete<T>(messages: Message[], model: string, schema: z.ZodType<T> | null, params?: ProviderParams): Promise<LLMResponse<T>>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Conversation type (array of messages).
|
|
47
|
+
*/
|
|
48
|
+
export type LLMConversation = Message[];
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;;;OAOG;IACH,QAAQ,CAAC,CAAC,EACT,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BatchResponse - A wrapper for batch LLM results with usage tracking.
|
|
3
|
+
*
|
|
4
|
+
* Provides an array-like interface for backwards compatibility while
|
|
5
|
+
* adding usage aggregation capabilities.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Token usage from a single LLM call.
|
|
9
|
+
*/
|
|
10
|
+
export interface TokenUsage {
|
|
11
|
+
inputTokens: number;
|
|
12
|
+
outputTokens: number;
|
|
13
|
+
totalTokens: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cost calculation result in USD.
|
|
17
|
+
*/
|
|
18
|
+
export interface UsageCost {
|
|
19
|
+
inputCost: number;
|
|
20
|
+
outputCost: number;
|
|
21
|
+
totalCost: number;
|
|
22
|
+
currency: 'USD';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Aggregated usage across multiple LLM calls.
|
|
26
|
+
*/
|
|
27
|
+
export interface AggregatedUsage {
|
|
28
|
+
tokens: TokenUsage;
|
|
29
|
+
cost: UsageCost | null;
|
|
30
|
+
callCount: number;
|
|
31
|
+
model: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A batch of LLM results with usage tracking.
|
|
35
|
+
*
|
|
36
|
+
* Implements Iterable<T> and provides array-like methods for backwards
|
|
37
|
+
* compatibility with code expecting Array<T>.
|
|
38
|
+
*/
|
|
39
|
+
export declare class BatchResponse<T> implements Iterable<T> {
|
|
40
|
+
readonly results: ReadonlyArray<T>;
|
|
41
|
+
private readonly _tokenUsages;
|
|
42
|
+
private readonly _model;
|
|
43
|
+
constructor(results: T[], tokenUsages?: Array<TokenUsage | null | undefined>, model?: string);
|
|
44
|
+
get length(): number;
|
|
45
|
+
[Symbol.iterator](): Iterator<T>;
|
|
46
|
+
at(index: number): T | undefined;
|
|
47
|
+
map<U>(fn: (value: T, index: number) => U): BatchResponse<U>;
|
|
48
|
+
filter(fn: (value: T, index: number) => boolean): BatchResponse<T>;
|
|
49
|
+
forEach(fn: (value: T, index: number) => void): void;
|
|
50
|
+
find(fn: (value: T, index: number) => boolean): T | undefined;
|
|
51
|
+
findIndex(fn: (value: T, index: number) => boolean): number;
|
|
52
|
+
some(fn: (value: T, index: number) => boolean): boolean;
|
|
53
|
+
every(fn: (value: T, index: number) => boolean): boolean;
|
|
54
|
+
reduce<U>(fn: (acc: U, value: T, index: number) => U, initial: U): U;
|
|
55
|
+
/**
|
|
56
|
+
* Convert to a plain array.
|
|
57
|
+
*/
|
|
58
|
+
toArray(): T[];
|
|
59
|
+
/**
|
|
60
|
+
* Get aggregated usage across all calls in this batch.
|
|
61
|
+
* Cost is calculated lazily only if model and costCalculator were provided.
|
|
62
|
+
* Returns null if usage tracking was not enabled.
|
|
63
|
+
*/
|
|
64
|
+
usage(): AggregatedUsage | null;
|
|
65
|
+
/**
|
|
66
|
+
* Get token usage for a specific index.
|
|
67
|
+
*/
|
|
68
|
+
usageAt(index: number): TokenUsage | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Check if any usage info is available.
|
|
71
|
+
*/
|
|
72
|
+
hasUsage(): boolean;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/src/response.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuC;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAGtC,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC,EAClD,KAAK,CAAC,EAAE,MAAM;IAUf,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;IAIhC,EAAE,CAAC,KAAK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1
|
+
/**
|
|
2
|
+
* BatchResponse - A wrapper for batch LLM results with usage tracking.
|
|
3
|
+
*
|
|
4
|
+
* Provides an array-like interface for backwards compatibility while
|
|
5
|
+
* adding usage aggregation capabilities.
|
|
6
|
+
*/
|
|
7
|
+
import { calculateCost } from './providers/pricing.js';
|
|
8
|
+
/**
|
|
9
|
+
* A batch of LLM results with usage tracking.
|
|
10
|
+
*
|
|
11
|
+
* Implements Iterable<T> and provides array-like methods for backwards
|
|
12
|
+
* compatibility with code expecting Array<T>.
|
|
13
|
+
*/
|
|
14
|
+
export class BatchResponse {
|
|
15
|
+
results;
|
|
16
|
+
_tokenUsages;
|
|
17
|
+
_model;
|
|
18
|
+
constructor(results, tokenUsages, model) {
|
|
19
|
+
this.results = results;
|
|
20
|
+
// Normalize null to undefined for internal storage, or null if not provided
|
|
21
|
+
this._tokenUsages = tokenUsages ? tokenUsages.map(u => u ?? undefined) : null;
|
|
22
|
+
this._model = model ?? null;
|
|
23
|
+
}
|
|
24
|
+
// Array-like interface
|
|
25
|
+
get length() {
|
|
26
|
+
return this.results.length;
|
|
27
|
+
}
|
|
28
|
+
[Symbol.iterator]() {
|
|
29
|
+
return this.results[Symbol.iterator]();
|
|
30
|
+
}
|
|
31
|
+
at(index) {
|
|
32
|
+
return this.results.at(index);
|
|
33
|
+
}
|
|
34
|
+
map(fn) {
|
|
35
|
+
const mapped = this.results.map((item, i) => fn(item, i));
|
|
36
|
+
return new BatchResponse(mapped, this._tokenUsages ?? undefined, this._model ?? undefined);
|
|
37
|
+
}
|
|
38
|
+
filter(fn) {
|
|
39
|
+
const filtered = [];
|
|
40
|
+
const usages = this._tokenUsages ? [] : undefined;
|
|
41
|
+
this.results.forEach((item, i) => {
|
|
42
|
+
if (fn(item, i)) {
|
|
43
|
+
filtered.push(item);
|
|
44
|
+
usages?.push(this._tokenUsages[i]);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return new BatchResponse(filtered, usages, this._model ?? undefined);
|
|
48
|
+
}
|
|
49
|
+
forEach(fn) {
|
|
50
|
+
this.results.forEach(fn);
|
|
51
|
+
}
|
|
52
|
+
find(fn) {
|
|
53
|
+
return this.results.find(fn);
|
|
54
|
+
}
|
|
55
|
+
findIndex(fn) {
|
|
56
|
+
return this.results.findIndex(fn);
|
|
57
|
+
}
|
|
58
|
+
some(fn) {
|
|
59
|
+
return this.results.some(fn);
|
|
60
|
+
}
|
|
61
|
+
every(fn) {
|
|
62
|
+
return this.results.every(fn);
|
|
63
|
+
}
|
|
64
|
+
reduce(fn, initial) {
|
|
65
|
+
return this.results.reduce(fn, initial);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convert to a plain array.
|
|
69
|
+
*/
|
|
70
|
+
toArray() {
|
|
71
|
+
return [...this.results];
|
|
72
|
+
}
|
|
73
|
+
// Usage tracking
|
|
74
|
+
/**
|
|
75
|
+
* Get aggregated usage across all calls in this batch.
|
|
76
|
+
* Cost is calculated lazily only if model and costCalculator were provided.
|
|
77
|
+
* Returns null if usage tracking was not enabled.
|
|
78
|
+
*/
|
|
79
|
+
usage() {
|
|
80
|
+
if (!this._tokenUsages) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const valid = this._tokenUsages.filter((u) => u !== undefined);
|
|
84
|
+
const aggregatedTokens = {
|
|
85
|
+
inputTokens: valid.reduce((sum, u) => sum + u.inputTokens, 0),
|
|
86
|
+
outputTokens: valid.reduce((sum, u) => sum + u.outputTokens, 0),
|
|
87
|
+
totalTokens: valid.reduce((sum, u) => sum + u.totalTokens, 0),
|
|
88
|
+
};
|
|
89
|
+
// Calculate cost if we have a model
|
|
90
|
+
const cost = this._model ? calculateCost(this._model, aggregatedTokens) : null;
|
|
91
|
+
return {
|
|
92
|
+
tokens: aggregatedTokens,
|
|
93
|
+
cost,
|
|
94
|
+
callCount: valid.length,
|
|
95
|
+
model: this._model,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get token usage for a specific index.
|
|
100
|
+
*/
|
|
101
|
+
usageAt(index) {
|
|
102
|
+
return this._tokenUsages?.[index];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if any usage info is available.
|
|
106
|
+
*/
|
|
107
|
+
hasUsage() {
|
|
108
|
+
return this._tokenUsages?.some((u) => u !== undefined) ?? false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool abstraction for LLM-powered operations.
|
|
3
|
+
*
|
|
4
|
+
* Provides a base class for building tools with consistent
|
|
5
|
+
* single-item and batch processing, usage tracking, and error handling.
|
|
6
|
+
*/
|
|
7
|
+
import type { z } from '../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
8
|
+
import { type LLMResponse, type Message, type ProviderParams } from './llm.js';
|
|
9
|
+
import { BatchResponse } from './response.js';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for LLM calls. Can be overridden per-invocation.
|
|
12
|
+
*/
|
|
13
|
+
export interface ModelConfig {
|
|
14
|
+
/** The model to use */
|
|
15
|
+
model: string;
|
|
16
|
+
/** Provider-specific parameters */
|
|
17
|
+
modelParams?: ProviderParams;
|
|
18
|
+
/** Maximum retry attempts (default: 3) */
|
|
19
|
+
maxRetries?: number;
|
|
20
|
+
/** Max concurrent requests for batch (default: 100) */
|
|
21
|
+
maxConcurrency?: number;
|
|
22
|
+
/** Enable cost tracking for batch (default: false) */
|
|
23
|
+
trackCost?: boolean;
|
|
24
|
+
/** Throw an error instead of returning null on failure (default: false) */
|
|
25
|
+
throwOnFailure?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Abstract base class for LLM-powered tools.
|
|
29
|
+
*/
|
|
30
|
+
export declare abstract class Tool<TInput, TOutput, TResult = TOutput> {
|
|
31
|
+
protected readonly modelConfig: ModelConfig;
|
|
32
|
+
constructor(modelConfig: ModelConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Define the Zod schema for LLM response validation.
|
|
35
|
+
* Override this to provide structured output validation.
|
|
36
|
+
*
|
|
37
|
+
* Returns null by default for raw text mode.
|
|
38
|
+
* When returning null, TOutput must be `string`.
|
|
39
|
+
*
|
|
40
|
+
* Make this as cheap as possible, as it's called on every invocation (row).
|
|
41
|
+
* E.g. by preparing it in the constructor if it doesn't depend on input.
|
|
42
|
+
*/
|
|
43
|
+
protected schema(): z.ZodType<TOutput> | null;
|
|
44
|
+
/** Build the prompt from a single input
|
|
45
|
+
* Make this as cheap as possible, as it's called on every invocation (row).
|
|
46
|
+
* E.g. by preparing it in the constructor if it doesn't depend on input.
|
|
47
|
+
*/
|
|
48
|
+
protected abstract prompt(input: TInput): string | Message[];
|
|
49
|
+
/** Extract final result from parsed output. Override to transform. */
|
|
50
|
+
protected extractResult(parsed: TOutput): TResult;
|
|
51
|
+
/** Check if input should be skipped (returns null without LLM call) */
|
|
52
|
+
protected isEmpty(input: TInput): boolean;
|
|
53
|
+
/** Process a single input */
|
|
54
|
+
invoke(input: TInput, options?: Partial<ModelConfig>): Promise<LLMResponse<TResult | null>>;
|
|
55
|
+
/** Process multiple inputs with usage tracking */
|
|
56
|
+
batch(inputs: TInput[], options?: Partial<ModelConfig>): Promise<BatchResponse<TResult | null>>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/src/tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,4CAA4C,CAAC;AACpE,OAAO,EAAc,KAAK,WAAW,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAE3F,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,uBAAuB;IACvB,KAAK,EAAE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|
|
4
|
+
* Provides a base class for building tools with consistent
|
|
5
|
+
* single-item and batch processing, usage tracking, and error handling.
|
|
6
|
+
*/
|
|
7
|
+
import { askLLMSafe } from './llm.js';
|
|
8
|
+
import { mapParallel } from './helpers/async.js';
|
|
9
|
+
import { BatchResponse } from './response.js';
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
maxRetries: 3,
|
|
12
|
+
maxConcurrency: 100,
|
|
13
|
+
trackCost: false,
|
|
14
|
+
throwOnFailure: false,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Abstract base class for LLM-powered tools.
|
|
18
|
+
*/
|
|
19
|
+
export class Tool {
|
|
20
|
+
modelConfig;
|
|
21
|
+
constructor(modelConfig) {
|
|
22
|
+
this.modelConfig = modelConfig;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Define the Zod schema for LLM response validation.
|
|
26
|
+
* Override this to provide structured output validation.
|
|
27
|
+
*
|
|
28
|
+
* Returns null by default for raw text mode.
|
|
29
|
+
* When returning null, TOutput must be `string`.
|
|
30
|
+
*
|
|
31
|
+
* Make this as cheap as possible, as it's called on every invocation (row).
|
|
32
|
+
* E.g. by preparing it in the constructor if it doesn't depend on input.
|
|
33
|
+
*/
|
|
34
|
+
schema() {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
/** Extract final result from parsed output. Override to transform. */
|
|
38
|
+
extractResult(parsed) {
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
/** Check if input should be skipped (returns null without LLM call) */
|
|
42
|
+
isEmpty(input) {
|
|
43
|
+
if (input == null)
|
|
44
|
+
return true;
|
|
45
|
+
if (typeof input === 'string' && input.trim() === '')
|
|
46
|
+
return true;
|
|
47
|
+
if (typeof input === 'object' && Object.keys(input).length === 0)
|
|
48
|
+
return true;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/** Process a single input */
|
|
52
|
+
async invoke(input, options = {}) {
|
|
53
|
+
if (this.isEmpty(input)) {
|
|
54
|
+
return { parsed: null, text: null, usage: null, error: null };
|
|
55
|
+
}
|
|
56
|
+
const { model, modelParams, maxRetries, throwOnFailure } = { ...DEFAULTS, ...this.modelConfig, ...options };
|
|
57
|
+
const response = await askLLMSafe({
|
|
58
|
+
prompt: this.prompt(input),
|
|
59
|
+
model,
|
|
60
|
+
schema: this.schema(),
|
|
61
|
+
params: modelParams,
|
|
62
|
+
maxRetries,
|
|
63
|
+
onError: 'return',
|
|
64
|
+
});
|
|
65
|
+
if (response.error != null || response.parsed == null) {
|
|
66
|
+
if (throwOnFailure) {
|
|
67
|
+
throw response.error ?? new Error('LLM call failed to produce a result');
|
|
68
|
+
}
|
|
69
|
+
return { parsed: null, text: response.text, usage: response.usage, error: response.error };
|
|
70
|
+
}
|
|
71
|
+
// Type assertion: when schema() returns null, askLLMSafe returns string,
|
|
72
|
+
// which should match TOutput (caller's responsibility to set TOutput = string)
|
|
73
|
+
const parsed = response.parsed;
|
|
74
|
+
return {
|
|
75
|
+
parsed: this.extractResult(parsed),
|
|
76
|
+
text: response.text,
|
|
77
|
+
usage: response.usage,
|
|
78
|
+
error: null,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Process multiple inputs with usage tracking */
|
|
82
|
+
async batch(inputs, options = {}) {
|
|
83
|
+
const { model, modelParams, maxRetries, maxConcurrency, trackCost } = {
|
|
84
|
+
...DEFAULTS,
|
|
85
|
+
...this.modelConfig,
|
|
86
|
+
...options,
|
|
87
|
+
};
|
|
88
|
+
const responses = await mapParallel(inputs, maxConcurrency, (input) => this.invoke(input, { model, modelParams, maxRetries }));
|
|
89
|
+
return new BatchResponse(responses.map((r) => r.parsed), trackCost ? responses.map((r) => r.usage) : undefined, trackCost ? model : undefined);
|
|
90
|
+
}
|
|
91
|
+
}
|
package/esm/src/tools/brands.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
-
import { mapParallel } from '../async.js';
|
|
3
|
-
import {
|
|
2
|
+
import { mapParallel } from '../helpers/async.js';
|
|
3
|
+
import { askLLMSafe } from '../llm.js';
|
|
4
4
|
import { BrandSchema, BrandListSchema } from '../schemas/brand.schema.js';
|
|
5
5
|
import { searchWithFormat } from './search.js';
|
|
6
|
-
import { dedent } from '../utils.js';
|
|
7
|
-
import { extractDomain } from '../urls.js';
|
|
6
|
+
import { dedent } from '../helpers/utils.js';
|
|
7
|
+
import { extractDomain } from '../helpers/urls.js';
|
|
8
8
|
export function buildBrandContext({ brand, brandDomain, sector, market, briefing }) {
|
|
9
9
|
let brandContext;
|
|
10
10
|
if (brandDomain) {
|
|
@@ -148,9 +148,9 @@ export async function generatePortfolioKeywords(product, sector, market, languag
|
|
|
148
148
|
.replaceAll('{sector}', sector)
|
|
149
149
|
.replaceAll('{market}', market)
|
|
150
150
|
.replaceAll('{language}', language);
|
|
151
|
-
const { parsed } = await
|
|
151
|
+
const { parsed } = await askLLMSafe({ prompt, model, schema: PortfolioKeywordsSchema });
|
|
152
152
|
if (!parsed) {
|
|
153
|
-
throw new Error('Failed to parse portfolio keywords from
|
|
153
|
+
throw new Error('Failed to parse portfolio keywords from LLM response');
|
|
154
154
|
}
|
|
155
155
|
return parsed.keywords;
|
|
156
156
|
}
|
|
@@ -1,34 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
3
|
+
interface ClassifierConfig {
|
|
4
|
+
/** Map of label names to descriptions */
|
|
5
|
+
labels: Record<string, string>;
|
|
6
|
+
/** Additional instructions for the classifier */
|
|
7
|
+
instructions?: string;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
|
-
*
|
|
10
|
+
* A tool that classifies records into one of the provided categories.
|
|
4
11
|
*/
|
|
5
|
-
export declare
|
|
12
|
+
export declare class Classifier extends Tool<Record<string, unknown> | null, {
|
|
13
|
+
label: string;
|
|
14
|
+
}, string> {
|
|
15
|
+
private readonly labelSchema;
|
|
16
|
+
private readonly promptTemplate;
|
|
17
|
+
constructor(config: ClassifierConfig, modelConfig: ModelConfig);
|
|
18
|
+
protected schema(): z.ZodObject<{
|
|
19
|
+
label: z.ZodLiteral<string>;
|
|
20
|
+
}, z.core.$strip> | z.ZodObject<{
|
|
21
|
+
label: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
protected prompt(record: Record<string, unknown> | null): string;
|
|
24
|
+
protected extractResult(parsed: {
|
|
25
|
+
label: string;
|
|
26
|
+
}): string;
|
|
27
|
+
}
|
|
6
28
|
/**
|
|
7
|
-
*
|
|
29
|
+
* Configuration for the Labeler tool.
|
|
8
30
|
*/
|
|
9
|
-
export
|
|
31
|
+
export interface LabelerConfig {
|
|
32
|
+
/** Map of label names to descriptions */
|
|
33
|
+
labels: Record<string, string>;
|
|
34
|
+
/** Additional instructions for the labeler */
|
|
35
|
+
instructions?: string;
|
|
36
|
+
}
|
|
10
37
|
/**
|
|
11
|
-
*
|
|
38
|
+
* A tool that assigns one or more labels to records from provided options.
|
|
12
39
|
*/
|
|
13
|
-
export declare
|
|
40
|
+
export declare class Labeler extends Tool<Record<string, unknown> | null, {
|
|
41
|
+
labels: Array<string>;
|
|
42
|
+
}, Array<string>> {
|
|
43
|
+
private readonly multiLabelSchema;
|
|
44
|
+
private readonly promptTemplate;
|
|
45
|
+
constructor(config: LabelerConfig, modelConfig: ModelConfig);
|
|
46
|
+
protected schema(): z.ZodObject<{
|
|
47
|
+
labels: z.ZodArray<z.ZodLiteral<string> | z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
protected prompt(record: Record<string, unknown> | null): string;
|
|
50
|
+
protected extractResult(parsed: {
|
|
51
|
+
labels: Array<string>;
|
|
52
|
+
}): string[];
|
|
53
|
+
}
|
|
14
54
|
/**
|
|
15
|
-
*
|
|
55
|
+
* Configuration for the LabelExtractor tool.
|
|
16
56
|
*/
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
records: Array<Record<string, unknown>>;
|
|
57
|
+
export interface LabelExtractorConfig {
|
|
58
|
+
/** Maximum number of labels to extract (default: 10) */
|
|
20
59
|
nLabels?: number;
|
|
60
|
+
/** Additional instructions for label extraction */
|
|
21
61
|
instructions?: string;
|
|
62
|
+
/** Maximum number of records to sample (default: 500) */
|
|
22
63
|
maxSamples?: number;
|
|
23
|
-
|
|
24
|
-
modelParams?: AIParams;
|
|
25
|
-
maxRetries?: number;
|
|
64
|
+
/** Language for labels and descriptions (default: same as records) */
|
|
26
65
|
language?: string;
|
|
27
66
|
}
|
|
28
67
|
/**
|
|
29
|
-
*
|
|
68
|
+
* A tool that extracts classification labels from a set of records.
|
|
30
69
|
* Returns a Record<string, string> mapping label names to descriptions,
|
|
31
|
-
* which can be used directly with
|
|
70
|
+
* which can be used directly with Classifier and Labeler.
|
|
32
71
|
*/
|
|
33
|
-
export declare
|
|
72
|
+
export declare class LabelExtractor extends Tool<Array<Record<string, unknown>>, {
|
|
73
|
+
labels: Array<{
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
}>;
|
|
77
|
+
}, Record<string, string>> {
|
|
78
|
+
private readonly maxSamples;
|
|
79
|
+
private readonly promptTemplate;
|
|
80
|
+
constructor(config: LabelExtractorConfig | undefined, modelConfig: ModelConfig);
|
|
81
|
+
protected schema(): z.ZodObject<{
|
|
82
|
+
labels: z.ZodArray<z.ZodObject<{
|
|
83
|
+
name: z.ZodString;
|
|
84
|
+
description: z.ZodString;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
protected prompt(records: Array<Record<string, unknown>>): string;
|
|
88
|
+
protected isEmpty(records: Array<Record<string, unknown>>): boolean;
|
|
89
|
+
protected extractResult(parsed: {
|
|
90
|
+
labels: Array<{
|
|
91
|
+
name: string;
|
|
92
|
+
description: string;
|
|
93
|
+
}>;
|
|
94
|
+
}): Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
34
97
|
//# sourceMappingURL=classifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../../src/src/tools/classifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../../src/src/tools/classifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAmGpD,UAAU,gBAAgB;IACzB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,CAAC;IAC9F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;IACnE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW;cAS3C,MAAM;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;cAIpC,aAAa,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;CAG1D;AAMD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,yCAAyC;IACzC,MAA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