@hilbras/sdk 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapters/cohere.d.ts +2 -0
- package/dist/adapters/cohere.d.ts.map +1 -1
- package/dist/adapters/cohere.js +36 -0
- package/dist/adapters/cohere.js.map +1 -1
- package/dist/adapters/openai-compatible.d.ts +2 -0
- package/dist/adapters/openai-compatible.d.ts.map +1 -1
- package/dist/adapters/openai-compatible.js +30 -0
- package/dist/adapters/openai-compatible.js.map +1 -1
- package/dist/adapters/openai.d.ts +5 -0
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openai.js +149 -0
- package/dist/adapters/openai.js.map +1 -1
- package/dist/catalog/models.d.ts.map +1 -1
- package/dist/catalog/models.js +24 -0
- package/dist/catalog/models.js.map +1 -1
- package/dist/client/client.d.ts +46 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +75 -0
- package/dist/client/client.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/output/schema-helpers.d.ts +67 -0
- package/dist/output/schema-helpers.d.ts.map +1 -0
- package/dist/output/schema-helpers.js +155 -0
- package/dist/output/schema-helpers.js.map +1 -0
- package/dist/transport/fetch.d.ts.map +1 -1
- package/dist/transport/fetch.js +4 -1
- package/dist/transport/fetch.js.map +1 -1
- package/dist/transport/transport.d.ts +2 -2
- package/dist/transport/transport.d.ts.map +1 -1
- package/dist/types/adapter.d.ts +14 -0
- package/dist/types/adapter.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/models.d.ts +10 -0
- package/dist/types/models.d.ts.map +1 -1
- package/dist/types/models.js +5 -0
- package/dist/types/models.js.map +1 -1
- package/dist/types/multi-modal.d.ts +98 -0
- package/dist/types/multi-modal.d.ts.map +1 -0
- package/dist/types/multi-modal.js +8 -0
- package/dist/types/multi-modal.js.map +1 -0
- package/dist/types/tool-builder.d.ts +120 -0
- package/dist/types/tool-builder.d.ts.map +1 -0
- package/dist/types/tool-builder.js +142 -0
- package/dist/types/tool-builder.js.map +1 -0
- package/dist/utils/id.d.ts +43 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +76 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/sse.d.ts +81 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +150 -0
- package/dist/utils/sse.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,uDAAuD;IACvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpE,0EAA0E;IAC1E,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IAErF,mCAAmC;IACnC,KAAK,IAAI,IAAI,CAAC;CACf"}
|
package/dist/types/adapter.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { Message } from "./messages.js";
|
|
|
14
14
|
import type { Tool } from "./tools.js";
|
|
15
15
|
import type { StreamChunk } from "./streams.js";
|
|
16
16
|
import type { Transport } from "../transport/transport.js";
|
|
17
|
+
import type { EmbeddingParams, EmbeddingResult, ImageParams, ImageResult, SpeechParams, SpeechResult, TranscriptionParams, TranscriptionResult, RerankParams, RerankResult } from "./multi-modal.js";
|
|
17
18
|
/** Shared config passed to all adapter constructors */
|
|
18
19
|
export interface AdapterConfig {
|
|
19
20
|
provider: ProviderConfig;
|
|
@@ -34,6 +35,9 @@ export interface GenerateParams {
|
|
|
34
35
|
*
|
|
35
36
|
* Any class with this shape can be registered via AdapterRegistry
|
|
36
37
|
* and used with HilbrasClient — no SDK modification required.
|
|
38
|
+
*
|
|
39
|
+
* Multi-modal methods are optional — adapters declare support by
|
|
40
|
+
* implementing the relevant method.
|
|
37
41
|
*/
|
|
38
42
|
export interface AIProvider {
|
|
39
43
|
/** Unique identifier for this provider type (e.g. "openai", "anthropic") */
|
|
@@ -42,5 +46,15 @@ export interface AIProvider {
|
|
|
42
46
|
stream(params: GenerateParams): AsyncGenerator<StreamChunk>;
|
|
43
47
|
/** Non-streaming chat completion */
|
|
44
48
|
complete(params: GenerateParams): Promise<string>;
|
|
49
|
+
/** Generate embeddings for text input */
|
|
50
|
+
embed?(params: EmbeddingParams): Promise<EmbeddingResult>;
|
|
51
|
+
/** Generate images from text prompt */
|
|
52
|
+
generateImage?(params: ImageParams): Promise<ImageResult>;
|
|
53
|
+
/** Synthesize speech from text */
|
|
54
|
+
generateSpeech?(params: SpeechParams): Promise<SpeechResult>;
|
|
55
|
+
/** Transcribe audio to text */
|
|
56
|
+
transcribe?(params: TranscriptionParams): Promise<TranscriptionResult>;
|
|
57
|
+
/** Rerank documents by relevance to a query */
|
|
58
|
+
rerank?(params: RerankParams): Promise<RerankResult>;
|
|
45
59
|
}
|
|
46
60
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/types/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/types/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,2CAA2C;AAC3C,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CA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c,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
package/dist/types/index.js
CHANGED
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
package/dist/types/models.d.ts
CHANGED
|
@@ -12,6 +12,16 @@ export interface ModelCapabilities {
|
|
|
12
12
|
structuredOutput: boolean;
|
|
13
13
|
parallelTools: boolean;
|
|
14
14
|
systemPrompts: boolean;
|
|
15
|
+
/** Model supports text embeddings (e.g. text-embedding-3-small) */
|
|
16
|
+
embeddings: boolean;
|
|
17
|
+
/** Model supports image generation (e.g. dall-e-3) */
|
|
18
|
+
imageGeneration: boolean;
|
|
19
|
+
/** Model supports speech synthesis (e.g. tts-1) */
|
|
20
|
+
speech: boolean;
|
|
21
|
+
/** Model supports audio transcription (e.g. whisper-1) */
|
|
22
|
+
transcription: boolean;
|
|
23
|
+
/** Model supports document reranking (e.g. cohere rerank) */
|
|
24
|
+
reranking: boolean;
|
|
15
25
|
}
|
|
16
26
|
export declare const DEFAULT_CAPABILITIES: ModelCapabilities;
|
|
17
27
|
export interface Model {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/types/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/types/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,eAAe,EAAE,OAAO,CAAC;IACzB,mDAAmD;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,0DAA0D;IAC1D,aAAa,EAAE,OAAO,CAAC;IACvB,6DAA6D;IAC7D,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,oBAAoB,EAAE,iBAalC,CAAC;AAEF,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,iBAAiB,CAAC;CACjC"}
|
package/dist/types/models.js
CHANGED
|
@@ -12,5 +12,10 @@ export const DEFAULT_CAPABILITIES = {
|
|
|
12
12
|
structuredOutput: false,
|
|
13
13
|
parallelTools: false,
|
|
14
14
|
systemPrompts: true,
|
|
15
|
+
embeddings: false,
|
|
16
|
+
imageGeneration: false,
|
|
17
|
+
speech: false,
|
|
18
|
+
transcription: false,
|
|
19
|
+
reranking: false,
|
|
15
20
|
};
|
|
16
21
|
//# sourceMappingURL=models.js.map
|
package/dist/types/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/types/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/types/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,MAAM,CAAC,MAAM,oBAAoB,GAAsB;IACrD,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,gBAAgB,EAAE,KAAK;IACvB,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,KAAK;IACjB,eAAe,EAAE,KAAK;IACtB,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,KAAK;IACpB,SAAS,EAAE,KAAK;CACjB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Multi-Modal Types
|
|
3
|
+
*
|
|
4
|
+
* Types for embedding, image generation, speech synthesis,
|
|
5
|
+
* transcription, and reranking — the five non-chat model capabilities.
|
|
6
|
+
*/
|
|
7
|
+
export interface EmbeddingParams {
|
|
8
|
+
model: string;
|
|
9
|
+
input: string | string[];
|
|
10
|
+
dimensions?: number;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export interface EmbeddingResult {
|
|
14
|
+
embeddings: number[][];
|
|
15
|
+
usage: {
|
|
16
|
+
inputTokens: number;
|
|
17
|
+
totalTokens: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export type ImageSize = "256x256" | "512x512" | "1024x1024" | "1792x1024" | "1024x1792";
|
|
21
|
+
export type ImageQuality = "standard" | "hd";
|
|
22
|
+
export type ImageStyle = "vivid" | "natural";
|
|
23
|
+
export interface ImageParams {
|
|
24
|
+
model: string;
|
|
25
|
+
prompt: string;
|
|
26
|
+
n?: number;
|
|
27
|
+
size?: ImageSize;
|
|
28
|
+
quality?: ImageQuality;
|
|
29
|
+
style?: ImageStyle;
|
|
30
|
+
responseFormat?: "url" | "b64_json";
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
export interface ImageResult {
|
|
34
|
+
images: Array<{
|
|
35
|
+
url?: string;
|
|
36
|
+
b64Json?: string;
|
|
37
|
+
revisedPrompt?: string;
|
|
38
|
+
}>;
|
|
39
|
+
usage?: {
|
|
40
|
+
inputTokens: number;
|
|
41
|
+
outputTokens: number;
|
|
42
|
+
totalTokens: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export type SpeechVoice = "alloy" | "ash" | "ballad" | "coral" | "echo" | "fable" | "nova" | "onyx" | "sage" | "shimmer";
|
|
46
|
+
export type SpeechFormat = "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
|
|
47
|
+
export interface SpeechParams {
|
|
48
|
+
model: string;
|
|
49
|
+
input: string;
|
|
50
|
+
voice: SpeechVoice;
|
|
51
|
+
responseFormat?: SpeechFormat;
|
|
52
|
+
speed?: number;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}
|
|
55
|
+
export interface SpeechResult {
|
|
56
|
+
audio: Uint8Array;
|
|
57
|
+
format: SpeechFormat;
|
|
58
|
+
}
|
|
59
|
+
export type TranscriptLanguage = "en" | "es" | "fr" | "de" | "it" | "pt" | "ru" | "ja" | "ko" | "zh";
|
|
60
|
+
export type TranscriptFormat = "json" | "text" | "srt" | "verbose_json";
|
|
61
|
+
export interface TranscriptionParams {
|
|
62
|
+
model: string;
|
|
63
|
+
file: File | Blob | Uint8Array;
|
|
64
|
+
language?: TranscriptLanguage;
|
|
65
|
+
prompt?: string;
|
|
66
|
+
responseFormat?: TranscriptFormat;
|
|
67
|
+
temperature?: number;
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}
|
|
70
|
+
export interface TranscriptionResult {
|
|
71
|
+
text: string;
|
|
72
|
+
language?: string;
|
|
73
|
+
duration?: number;
|
|
74
|
+
segments?: Array<{
|
|
75
|
+
start: number;
|
|
76
|
+
end: number;
|
|
77
|
+
text: string;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
80
|
+
export interface RerankParams {
|
|
81
|
+
model: string;
|
|
82
|
+
query: string;
|
|
83
|
+
documents: string[];
|
|
84
|
+
topN?: number;
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
export interface RerankResult {
|
|
88
|
+
results: Array<{
|
|
89
|
+
index: number;
|
|
90
|
+
relevanceScore: number;
|
|
91
|
+
document?: string;
|
|
92
|
+
}>;
|
|
93
|
+
usage?: {
|
|
94
|
+
inputTokens: number;
|
|
95
|
+
totalTokens: number;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=multi-modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-modal.d.ts","sourceRoot":"","sources":["../../src/types/multi-modal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACvB,KAAK,EAAE;QAAE,WAAW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WAAW,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7E,KAAK,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CACtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-modal.js","sourceRoot":"","sources":["../../src/types/multi-modal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Tool Builder
|
|
3
|
+
*
|
|
4
|
+
* Type-safe helpers for defining tools with schemas.
|
|
5
|
+
* Supports both static and runtime-defined tools.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { tool } from "@hilbras/sdk";
|
|
9
|
+
*
|
|
10
|
+
* const weatherTool = tool({
|
|
11
|
+
* name: "get_weather",
|
|
12
|
+
* description: "Get the weather for a location",
|
|
13
|
+
* parameters: {
|
|
14
|
+
* location: { type: "string", description: "City name" },
|
|
15
|
+
* unit: { type: "string", enum: ["celsius", "fahrenheit"] },
|
|
16
|
+
* },
|
|
17
|
+
* required: ["location"],
|
|
18
|
+
* execute: async (input) => {
|
|
19
|
+
* return { temp: 22, condition: "sunny" };
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Use with client
|
|
24
|
+
* const result = await client.complete({
|
|
25
|
+
* messages: [...],
|
|
26
|
+
* tools: [weatherTool.definition],
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Or execute directly
|
|
30
|
+
* const weather = await weatherTool.execute({ location: "London" });
|
|
31
|
+
*/
|
|
32
|
+
import type { Tool, ToolParameters } from "../types/tools.js";
|
|
33
|
+
/** Schema definition for tool parameters (simplified, user-friendly format) */
|
|
34
|
+
export type ParameterSchema = Record<string, {
|
|
35
|
+
type: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
enum?: string[];
|
|
38
|
+
properties?: Record<string, ParameterSchema[string]>;
|
|
39
|
+
required?: string[];
|
|
40
|
+
}>;
|
|
41
|
+
/** A tool with both definition and execution function */
|
|
42
|
+
export interface DefinedTool<TInput = Record<string, unknown>, TOutput = unknown> {
|
|
43
|
+
/** The tool definition for passing to the LLM */
|
|
44
|
+
definition: Tool;
|
|
45
|
+
/** Execute the tool with validated input */
|
|
46
|
+
inputSchema: ParameterSchema;
|
|
47
|
+
required: string[];
|
|
48
|
+
execute: (input: TInput) => Promise<TOutput>;
|
|
49
|
+
}
|
|
50
|
+
/** A tool definition without an execute function (for LLM-only use) */
|
|
51
|
+
export type ToolDefinition = Tool;
|
|
52
|
+
/**
|
|
53
|
+
* Define a type-safe tool with schema and execution function.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const calculator = tool({
|
|
57
|
+
* name: "calculate",
|
|
58
|
+
* description: "Perform a math calculation",
|
|
59
|
+
* parameters: {
|
|
60
|
+
* expression: { type: "string", description: "Math expression" },
|
|
61
|
+
* },
|
|
62
|
+
* required: ["expression"],
|
|
63
|
+
* execute: async (input) => {
|
|
64
|
+
* return { result: eval(input.expression) };
|
|
65
|
+
* },
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // Access the definition for LLM
|
|
69
|
+
* console.log(calculator.definition);
|
|
70
|
+
*
|
|
71
|
+
* // Execute directly
|
|
72
|
+
* const result = await calculator.execute({ expression: "2 + 2" });
|
|
73
|
+
*/
|
|
74
|
+
export declare function tool<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown>(config: {
|
|
75
|
+
name: string;
|
|
76
|
+
description: string;
|
|
77
|
+
parameters: ParameterSchema;
|
|
78
|
+
required: (keyof TInput & string)[];
|
|
79
|
+
execute: (input: TInput) => Promise<TOutput>;
|
|
80
|
+
}): DefinedTool<TInput, TOutput>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a tool definition without an execute function.
|
|
83
|
+
* Useful when you only need the schema for the LLM,
|
|
84
|
+
* or when execution is handled elsewhere.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const def = toolDef({
|
|
88
|
+
* name: "search",
|
|
89
|
+
* description: "Search the web",
|
|
90
|
+
* parameters: {
|
|
91
|
+
* query: { type: "string", description: "Search query" },
|
|
92
|
+
* },
|
|
93
|
+
* required: ["query"],
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Pass to LLM
|
|
97
|
+
* await client.complete({ messages, tools: [def] });
|
|
98
|
+
*/
|
|
99
|
+
export declare function toolDef(config: {
|
|
100
|
+
name: string;
|
|
101
|
+
description: string;
|
|
102
|
+
parameters: ParameterSchema;
|
|
103
|
+
required?: string[];
|
|
104
|
+
}): Tool;
|
|
105
|
+
/**
|
|
106
|
+
* Create a tool from a runtime-defined schema.
|
|
107
|
+
* Useful when tool definitions come from an API or database.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const tools = await fetchToolDefinitionsFromAPI();
|
|
111
|
+
* const dynamicTools = tools.map(dynamicTool);
|
|
112
|
+
* await client.complete({ messages, tools: dynamicTools });
|
|
113
|
+
*/
|
|
114
|
+
export declare function dynamicTool(config: {
|
|
115
|
+
name: string;
|
|
116
|
+
description: string;
|
|
117
|
+
parameters: ToolParameters;
|
|
118
|
+
execute?: (input: Record<string, unknown>) => Promise<unknown>;
|
|
119
|
+
}): Tool | DefinedTool;
|
|
120
|
+
//# sourceMappingURL=tool-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-builder.d.ts","sourceRoot":"","sources":["../../src/types/tool-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EA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AO,CAAC,CA0B/B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,eAAe,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG,IAAI,CAmBP;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE,GAAG,IAAI,GAAG,WAAW,CAoBrB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Tool Builder
|
|
3
|
+
*
|
|
4
|
+
* Type-safe helpers for defining tools with schemas.
|
|
5
|
+
* Supports both static and runtime-defined tools.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { tool } from "@hilbras/sdk";
|
|
9
|
+
*
|
|
10
|
+
* const weatherTool = tool({
|
|
11
|
+
* name: "get_weather",
|
|
12
|
+
* description: "Get the weather for a location",
|
|
13
|
+
* parameters: {
|
|
14
|
+
* location: { type: "string", description: "City name" },
|
|
15
|
+
* unit: { type: "string", enum: ["celsius", "fahrenheit"] },
|
|
16
|
+
* },
|
|
17
|
+
* required: ["location"],
|
|
18
|
+
* execute: async (input) => {
|
|
19
|
+
* return { temp: 22, condition: "sunny" };
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Use with client
|
|
24
|
+
* const result = await client.complete({
|
|
25
|
+
* messages: [...],
|
|
26
|
+
* tools: [weatherTool.definition],
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Or execute directly
|
|
30
|
+
* const weather = await weatherTool.execute({ location: "London" });
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Define a type-safe tool with schema and execution function.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const calculator = tool({
|
|
37
|
+
* name: "calculate",
|
|
38
|
+
* description: "Perform a math calculation",
|
|
39
|
+
* parameters: {
|
|
40
|
+
* expression: { type: "string", description: "Math expression" },
|
|
41
|
+
* },
|
|
42
|
+
* required: ["expression"],
|
|
43
|
+
* execute: async (input) => {
|
|
44
|
+
* return { result: eval(input.expression) };
|
|
45
|
+
* },
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Access the definition for LLM
|
|
49
|
+
* console.log(calculator.definition);
|
|
50
|
+
*
|
|
51
|
+
* // Execute directly
|
|
52
|
+
* const result = await calculator.execute({ expression: "2 + 2" });
|
|
53
|
+
*/
|
|
54
|
+
export function tool(config) {
|
|
55
|
+
const toolParameters = {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {},
|
|
58
|
+
required: config.required,
|
|
59
|
+
};
|
|
60
|
+
for (const [key, def] of Object.entries(config.parameters)) {
|
|
61
|
+
toolParameters.properties[key] = def;
|
|
62
|
+
}
|
|
63
|
+
const definition = {
|
|
64
|
+
type: "function",
|
|
65
|
+
function: {
|
|
66
|
+
name: config.name,
|
|
67
|
+
description: config.description,
|
|
68
|
+
parameters: toolParameters,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
definition,
|
|
73
|
+
inputSchema: config.parameters,
|
|
74
|
+
required: config.required,
|
|
75
|
+
execute: config.execute,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a tool definition without an execute function.
|
|
80
|
+
* Useful when you only need the schema for the LLM,
|
|
81
|
+
* or when execution is handled elsewhere.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const def = toolDef({
|
|
85
|
+
* name: "search",
|
|
86
|
+
* description: "Search the web",
|
|
87
|
+
* parameters: {
|
|
88
|
+
* query: { type: "string", description: "Search query" },
|
|
89
|
+
* },
|
|
90
|
+
* required: ["query"],
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // Pass to LLM
|
|
94
|
+
* await client.complete({ messages, tools: [def] });
|
|
95
|
+
*/
|
|
96
|
+
export function toolDef(config) {
|
|
97
|
+
const toolParameters = {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {},
|
|
100
|
+
required: config.required ?? [],
|
|
101
|
+
};
|
|
102
|
+
for (const [key, def] of Object.entries(config.parameters)) {
|
|
103
|
+
toolParameters.properties[key] = def;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
type: "function",
|
|
107
|
+
function: {
|
|
108
|
+
name: config.name,
|
|
109
|
+
description: config.description,
|
|
110
|
+
parameters: toolParameters,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a tool from a runtime-defined schema.
|
|
116
|
+
* Useful when tool definitions come from an API or database.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* const tools = await fetchToolDefinitionsFromAPI();
|
|
120
|
+
* const dynamicTools = tools.map(dynamicTool);
|
|
121
|
+
* await client.complete({ messages, tools: dynamicTools });
|
|
122
|
+
*/
|
|
123
|
+
export function dynamicTool(config) {
|
|
124
|
+
const definition = {
|
|
125
|
+
type: "function",
|
|
126
|
+
function: {
|
|
127
|
+
name: config.name,
|
|
128
|
+
description: config.description,
|
|
129
|
+
parameters: config.parameters,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
if (config.execute) {
|
|
133
|
+
return {
|
|
134
|
+
definition,
|
|
135
|
+
inputSchema: config.parameters.properties,
|
|
136
|
+
required: config.parameters.required,
|
|
137
|
+
execute: config.execute,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return definition;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=tool-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-builder.js","sourceRoot":"","sources":["../../src/types/tool-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AA0BH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,IAAI,CAAsF,MAMzG;IACC,MAAM,cAAc,GAAmB;QACrC,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,MAAM,CAAC,QAAoB;KACtC,CAAC;IAEF,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,GAAoB,CAAC;IACxD,CAAC;IAED,MAAM,UAAU,GAAS;QACvB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU,EAAE,cAAc;SAC3B;KACF,CAAC;IAEF,OAAO;QACL,UAAU;QACV,WAAW,EAAE,MAAM,CAAC,UAAU;QAC9B,QAAQ,EAAE,MAAM,CAAC,QAAoB;QACrC,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO,CAAC,MAKvB;IACC,MAAM,cAAc,GAAmB;QACrC,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE;KAChC,CAAC;IAEF,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,GAAoB,CAAC;IACxD,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU,EAAE,cAAc;SAC3B;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,MAK3B;IACC,MAAM,UAAU,GAAS;QACvB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO;YACL,UAAU;YACV,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,UAA6B;YAC5D,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC,QAAQ;YACpC,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — ID Generation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Generate unique IDs for requests, tool calls, and other entities.
|
|
5
|
+
* Uses crypto.randomUUID() when available, falls back to a simple counter.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { generateId, createIdGenerator } from "@hilbras/sdk";
|
|
9
|
+
*
|
|
10
|
+
* const id = generateId(); // "a1b2c3d4-e5f6-..."
|
|
11
|
+
* const gen = createIdGenerator("req");
|
|
12
|
+
* const id1 = gen(); // "req_001"
|
|
13
|
+
* const id2 = gen(); // "req_002"
|
|
14
|
+
*/
|
|
15
|
+
/** Generate a unique ID (UUID v4 when available, fallback to random hex) */
|
|
16
|
+
export declare function generateId(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Create a sequential ID generator with a prefix.
|
|
19
|
+
*
|
|
20
|
+
* @param prefix - Optional prefix for generated IDs
|
|
21
|
+
* @param start - Starting number (default: 1)
|
|
22
|
+
* @returns A function that returns incrementing IDs
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const gen = createIdGenerator("req");
|
|
26
|
+
* gen(); // "req_001"
|
|
27
|
+
* gen(); // "req_002"
|
|
28
|
+
* gen(); // "req_003"
|
|
29
|
+
*
|
|
30
|
+
* const gen2 = createIdGenerator("call", 100);
|
|
31
|
+
* gen2(); // "call_100"
|
|
32
|
+
* gen2(); // "call_101"
|
|
33
|
+
*/
|
|
34
|
+
export declare function createIdGenerator(prefix?: string, start?: number): () => string;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a short random ID (8 characters).
|
|
37
|
+
* Useful for correlation IDs, request tags, etc.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const tag = shortId(); // "a1b2c3d4"
|
|
41
|
+
*/
|
|
42
|
+
export declare function shortId(): string;
|
|
43
|
+
//# sourceMappingURL=id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,4EAA4E;AAC5E,wBAAgB,UAAU,IAAI,MAAM,CAkBnC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAO,EAAE,KAAK,SAAI,GAAG,MAAM,MAAM,CAGxE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,IAAI,MAAM,CAUhC"}
|
package/dist/utils/id.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — ID Generation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Generate unique IDs for requests, tool calls, and other entities.
|
|
5
|
+
* Uses crypto.randomUUID() when available, falls back to a simple counter.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { generateId, createIdGenerator } from "@hilbras/sdk";
|
|
9
|
+
*
|
|
10
|
+
* const id = generateId(); // "a1b2c3d4-e5f6-..."
|
|
11
|
+
* const gen = createIdGenerator("req");
|
|
12
|
+
* const id1 = gen(); // "req_001"
|
|
13
|
+
* const id2 = gen(); // "req_002"
|
|
14
|
+
*/
|
|
15
|
+
/** Generate a unique ID (UUID v4 when available, fallback to random hex) */
|
|
16
|
+
export function generateId() {
|
|
17
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
18
|
+
return crypto.randomUUID();
|
|
19
|
+
}
|
|
20
|
+
// Fallback: generate a random hex string
|
|
21
|
+
const arr = new Uint8Array(16);
|
|
22
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
23
|
+
crypto.getRandomValues(arr);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
for (let i = 0; i < 16; i++) {
|
|
27
|
+
arr[i] = Math.floor(Math.random() * 256);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Set version 4 and variant bits
|
|
31
|
+
arr[6] = (arr[6] & 0x0f) | 0x40;
|
|
32
|
+
arr[8] = (arr[8] & 0x3f) | 0x80;
|
|
33
|
+
const hex = Array.from(arr, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
34
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a sequential ID generator with a prefix.
|
|
38
|
+
*
|
|
39
|
+
* @param prefix - Optional prefix for generated IDs
|
|
40
|
+
* @param start - Starting number (default: 1)
|
|
41
|
+
* @returns A function that returns incrementing IDs
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const gen = createIdGenerator("req");
|
|
45
|
+
* gen(); // "req_001"
|
|
46
|
+
* gen(); // "req_002"
|
|
47
|
+
* gen(); // "req_003"
|
|
48
|
+
*
|
|
49
|
+
* const gen2 = createIdGenerator("call", 100);
|
|
50
|
+
* gen2(); // "call_100"
|
|
51
|
+
* gen2(); // "call_101"
|
|
52
|
+
*/
|
|
53
|
+
export function createIdGenerator(prefix = "id", start = 1) {
|
|
54
|
+
let counter = start;
|
|
55
|
+
return () => `${prefix}_${String(counter++).padStart(6, "0")}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate a short random ID (8 characters).
|
|
59
|
+
* Useful for correlation IDs, request tags, etc.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const tag = shortId(); // "a1b2c3d4"
|
|
63
|
+
*/
|
|
64
|
+
export function shortId() {
|
|
65
|
+
const arr = new Uint8Array(4);
|
|
66
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
67
|
+
crypto.getRandomValues(arr);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
for (let i = 0; i < 4; i++) {
|
|
71
|
+
arr[i] = Math.floor(Math.random() * 256);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return Array.from(arr, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,4EAA4E;AAC5E,MAAM,UAAU,UAAU;IACxB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC7E,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;IACD,yCAA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