@hilbras/sdk 0.11.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/index.d.ts +6 -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/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
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://img.shields.io/badge/version-0.
|
|
2
|
+
<img src="https://img.shields.io/badge/version-0.12.0-blue" alt="version">
|
|
3
3
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="license">
|
|
4
4
|
<img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen" alt="node">
|
|
5
5
|
<img src="https://img.shields.io/badge/types-strict-blueviolet" alt="types">
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ export { ModelRouter } from "./router/model-router.js";
|
|
|
25
25
|
export type { TaskRequirement, RoutingResult } from "./types/router.js";
|
|
26
26
|
export type { SchemaValidator, StructuredOutputConfig } from "./types/schema.js";
|
|
27
27
|
export { extractJson, buildJsonSystemInstruction, buildRepairPrompt, buildJsonModeParams } from "./output/structured.js";
|
|
28
|
+
export { zodSchema, jsonSchema } from "./output/schema-helpers.js";
|
|
29
|
+
export { tool, toolDef, dynamicTool } from "./types/tool-builder.js";
|
|
30
|
+
export type { DefinedTool, ToolDefinition, ParameterSchema } from "./types/tool-builder.js";
|
|
31
|
+
export { generateId, createIdGenerator, shortId } from "./utils/id.js";
|
|
32
|
+
export { parseSSEStream, parseJsonEventStream, collectSSEEvents, findSSEEvent } from "./utils/sse.js";
|
|
33
|
+
export type { SSEEvent } from "./utils/sse.js";
|
|
28
34
|
export { BudgetTracker } from "./cost/tracker.js";
|
|
29
35
|
export type { Reservation } from "./cost/tracker.js";
|
|
30
36
|
export type { CostEvent, CostReport, BudgetConfig } from "./cost/types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG9D,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEnE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE1F,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEnG,YAAY,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE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,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,YAAY,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,12 @@ export { AdapterRegistry, getDefaultAdapterRegistry } from "./providers/adapter-
|
|
|
17
17
|
// ─── Model Router ───────────────────────────────────────────────────────────
|
|
18
18
|
export { ModelRouter } from "./router/model-router.js";
|
|
19
19
|
export { extractJson, buildJsonSystemInstruction, buildRepairPrompt, buildJsonModeParams } from "./output/structured.js";
|
|
20
|
+
export { zodSchema, jsonSchema } from "./output/schema-helpers.js";
|
|
21
|
+
// ─── Tool Builder ───────────────────────────────────────────────────────────
|
|
22
|
+
export { tool, toolDef, dynamicTool } from "./types/tool-builder.js";
|
|
23
|
+
// ─── Utilities ──────────────────────────────────────────────────────────────
|
|
24
|
+
export { generateId, createIdGenerator, shortId } from "./utils/id.js";
|
|
25
|
+
export { parseSSEStream, parseJsonEventStream, collectSSEEvents, findSSEEvent } from "./utils/sse.js";
|
|
20
26
|
// ─── Cost Optimization ──────────────────────────────────────────────────────
|
|
21
27
|
export { BudgetTracker } from "./cost/tracker.js";
|
|
22
28
|
export { FetchTransport } from "./transport/fetch.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKnE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAK3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAsBzD,+EAA+E;AAC/E,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,+EAA+E;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAS7F,+EAA+E;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKnE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAK3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAsBzD,+EAA+E;AAC/E,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,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Schema Helpers
|
|
3
|
+
*
|
|
4
|
+
* Type-safe wrappers for Zod and JSON Schema validation.
|
|
5
|
+
* Works with any library that provides a `.safeParse()` method.
|
|
6
|
+
*
|
|
7
|
+
* Usage with Zod:
|
|
8
|
+
* import { z } from "zod";
|
|
9
|
+
* import { zodSchema } from "@hilbras/sdk";
|
|
10
|
+
*
|
|
11
|
+
* const schema = z.object({ name: z.string(), age: z.number() });
|
|
12
|
+
* const result = await client.complete({
|
|
13
|
+
* messages: [...],
|
|
14
|
+
* output: zodSchema(schema),
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* Usage with JSON Schema:
|
|
18
|
+
* import { jsonSchema } from "@hilbras/sdk";
|
|
19
|
+
*
|
|
20
|
+
* const result = await client.complete({
|
|
21
|
+
* messages: [...],
|
|
22
|
+
* output: jsonSchema({
|
|
23
|
+
* type: "object",
|
|
24
|
+
* properties: { name: { type: "string" }, age: { type: "number" } },
|
|
25
|
+
* required: ["name", "age"],
|
|
26
|
+
* }),
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
import type { SchemaValidator, StructuredOutputConfig } from "../types/schema.js";
|
|
30
|
+
/**
|
|
31
|
+
* Wrap a Zod schema for use with `complete()`.
|
|
32
|
+
*
|
|
33
|
+
* Accepts any object with a `.safeParse()` method (Zod, Valibot, etc.)
|
|
34
|
+
* and returns a `StructuredOutputConfig` ready for the client.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* import { z } from "zod";
|
|
38
|
+
* const config = zodSchema(z.object({ name: z.string() }));
|
|
39
|
+
* const result = await client.complete({ messages, output: config });
|
|
40
|
+
*/
|
|
41
|
+
export declare function zodSchema<T>(schema: SchemaValidator<T>, options?: {
|
|
42
|
+
maxRepairAttempts?: number;
|
|
43
|
+
repairInstructions?: string;
|
|
44
|
+
}): StructuredOutputConfig<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Create a structured output config from a raw JSON Schema object.
|
|
47
|
+
*
|
|
48
|
+
* Builds an inline `SchemaValidator` that validates against the provided
|
|
49
|
+
* JSON Schema using basic type checking. For full JSON Schema validation,
|
|
50
|
+
* use a dedicated library (ajv, yup) and pass it via `zodSchema()`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const config = jsonSchema({
|
|
54
|
+
* type: "object",
|
|
55
|
+
* properties: {
|
|
56
|
+
* name: { type: "string" },
|
|
57
|
+
* age: { type: "number" },
|
|
58
|
+
* },
|
|
59
|
+
* required: ["name", "age"],
|
|
60
|
+
* });
|
|
61
|
+
* const result = await client.complete({ messages, output: config });
|
|
62
|
+
*/
|
|
63
|
+
export declare function jsonSchema<T = unknown>(schema: Record<string, unknown>, options?: {
|
|
64
|
+
maxRepairAttempts?: number;
|
|
65
|
+
repairInstructions?: string;
|
|
66
|
+
}): StructuredOutputConfig<T>;
|
|
67
|
+
//# sourceMappingURL=schema-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-helpers.d.ts","sourceRoot":"","sources":["../../src/output/schema-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAElF;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,EAC1B,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE,sBAAsB,CAAC,CAAC,CAAC,CAM3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE;IAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE,sBAAsB,CAAC,CAAC,CAAC,CA2B3B"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — Schema Helpers
|
|
3
|
+
*
|
|
4
|
+
* Type-safe wrappers for Zod and JSON Schema validation.
|
|
5
|
+
* Works with any library that provides a `.safeParse()` method.
|
|
6
|
+
*
|
|
7
|
+
* Usage with Zod:
|
|
8
|
+
* import { z } from "zod";
|
|
9
|
+
* import { zodSchema } from "@hilbras/sdk";
|
|
10
|
+
*
|
|
11
|
+
* const schema = z.object({ name: z.string(), age: z.number() });
|
|
12
|
+
* const result = await client.complete({
|
|
13
|
+
* messages: [...],
|
|
14
|
+
* output: zodSchema(schema),
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* Usage with JSON Schema:
|
|
18
|
+
* import { jsonSchema } from "@hilbras/sdk";
|
|
19
|
+
*
|
|
20
|
+
* const result = await client.complete({
|
|
21
|
+
* messages: [...],
|
|
22
|
+
* output: jsonSchema({
|
|
23
|
+
* type: "object",
|
|
24
|
+
* properties: { name: { type: "string" }, age: { type: "number" } },
|
|
25
|
+
* required: ["name", "age"],
|
|
26
|
+
* }),
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Wrap a Zod schema for use with `complete()`.
|
|
31
|
+
*
|
|
32
|
+
* Accepts any object with a `.safeParse()` method (Zod, Valibot, etc.)
|
|
33
|
+
* and returns a `StructuredOutputConfig` ready for the client.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import { z } from "zod";
|
|
37
|
+
* const config = zodSchema(z.object({ name: z.string() }));
|
|
38
|
+
* const result = await client.complete({ messages, output: config });
|
|
39
|
+
*/
|
|
40
|
+
export function zodSchema(schema, options) {
|
|
41
|
+
return {
|
|
42
|
+
schema,
|
|
43
|
+
maxRepairAttempts: options?.maxRepairAttempts,
|
|
44
|
+
repairInstructions: options?.repairInstructions,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a structured output config from a raw JSON Schema object.
|
|
49
|
+
*
|
|
50
|
+
* Builds an inline `SchemaValidator` that validates against the provided
|
|
51
|
+
* JSON Schema using basic type checking. For full JSON Schema validation,
|
|
52
|
+
* use a dedicated library (ajv, yup) and pass it via `zodSchema()`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const config = jsonSchema({
|
|
56
|
+
* type: "object",
|
|
57
|
+
* properties: {
|
|
58
|
+
* name: { type: "string" },
|
|
59
|
+
* age: { type: "number" },
|
|
60
|
+
* },
|
|
61
|
+
* required: ["name", "age"],
|
|
62
|
+
* });
|
|
63
|
+
* const result = await client.complete({ messages, output: config });
|
|
64
|
+
*/
|
|
65
|
+
export function jsonSchema(schema, options) {
|
|
66
|
+
const validator = {
|
|
67
|
+
safeParse(data) {
|
|
68
|
+
try {
|
|
69
|
+
// Basic structural validation against JSON Schema
|
|
70
|
+
const errors = validateJsonSchema(data, schema);
|
|
71
|
+
if (errors.length > 0) {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
error: new Error(`JSON Schema validation failed: ${errors.join("; ")}`),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return { success: true, data: data };
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
schema: validator,
|
|
89
|
+
maxRepairAttempts: options?.maxRepairAttempts,
|
|
90
|
+
repairInstructions: options?.repairInstructions,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Basic JSON Schema validator — checks required fields and primitive types.
|
|
95
|
+
* Not a full implementation; for production use, integrate ajv or similar.
|
|
96
|
+
*/
|
|
97
|
+
function validateJsonSchema(data, schema) {
|
|
98
|
+
const errors = [];
|
|
99
|
+
const type = schema.type;
|
|
100
|
+
if (type === "array") {
|
|
101
|
+
if (!Array.isArray(data)) {
|
|
102
|
+
errors.push(`Expected type "array", got "${typeof data}"`);
|
|
103
|
+
}
|
|
104
|
+
return errors;
|
|
105
|
+
}
|
|
106
|
+
if (type === "object" && typeof data === "object" && data !== null && !Array.isArray(data)) {
|
|
107
|
+
const obj = data;
|
|
108
|
+
const required = schema.required;
|
|
109
|
+
if (required) {
|
|
110
|
+
for (const key of required) {
|
|
111
|
+
if (!(key in obj)) {
|
|
112
|
+
errors.push(`Missing required field: "${key}"`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const properties = schema.properties;
|
|
117
|
+
if (properties) {
|
|
118
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
119
|
+
if (key in obj) {
|
|
120
|
+
const propErrors = validateJsonSchemaField(obj[key], propSchema, key);
|
|
121
|
+
errors.push(...propErrors);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (type && type !== "array" && type !== "object" && type !== typeof data) {
|
|
127
|
+
errors.push(`Expected type "${schema.type}", got "${typeof data}"`);
|
|
128
|
+
}
|
|
129
|
+
return errors;
|
|
130
|
+
}
|
|
131
|
+
function validateJsonSchemaField(value, schema, path) {
|
|
132
|
+
const errors = [];
|
|
133
|
+
const type = schema.type;
|
|
134
|
+
if (type === "string" && typeof value !== "string") {
|
|
135
|
+
errors.push(`"${path}" should be a string`);
|
|
136
|
+
}
|
|
137
|
+
else if (type === "number" && typeof value !== "number") {
|
|
138
|
+
errors.push(`"${path}" should be a number`);
|
|
139
|
+
}
|
|
140
|
+
else if (type === "boolean" && typeof value !== "boolean") {
|
|
141
|
+
errors.push(`"${path}" should be a boolean`);
|
|
142
|
+
}
|
|
143
|
+
else if (type === "array" && !Array.isArray(value)) {
|
|
144
|
+
errors.push(`"${path}" should be an array`);
|
|
145
|
+
}
|
|
146
|
+
else if (type === "object" && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
147
|
+
errors.push(`"${path}" should be an object`);
|
|
148
|
+
}
|
|
149
|
+
else if (type === "object" && typeof value === "object" && value !== null && schema.properties) {
|
|
150
|
+
const nested = validateJsonSchema(value, schema);
|
|
151
|
+
errors.push(...nested.map((e) => `${path}.${e}`));
|
|
152
|
+
}
|
|
153
|
+
return errors;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=schema-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-helpers.js","sourceRoot":"","sources":["../../src/output/schema-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH;;;;;;;;;;GAUG;AACH,MAAM,UA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C,UAAU,EAAE,CAAC;QACjG,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACjD,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -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,EAAE,IAAI,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE7E,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE;IAC3C,IAAI,EAAE,MA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AAC;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.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;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,yCAAyC;IACzC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,UAAU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AAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AACjE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QAClF,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — SSE (Server-Sent Events) Parser
|
|
3
|
+
*
|
|
4
|
+
* Utilities for parsing SSE streams into structured events.
|
|
5
|
+
* Useful for consuming SSE endpoints directly or building custom adapters.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { parseJsonEventStream, parseSSEStream } from "@hilbras/sdk";
|
|
9
|
+
*
|
|
10
|
+
* // Parse a ReadableStream of SSE events
|
|
11
|
+
* for await (const event of parseSSEStream(response.body)) {
|
|
12
|
+
* console.log(event.event, event.data);
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* // Parse SSE and auto-parse JSON data
|
|
16
|
+
* for await (const data of parseJsonEventStream(response.body)) {
|
|
17
|
+
* console.log(data); // parsed JSON object
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
/** A parsed SSE event */
|
|
21
|
+
export interface SSEEvent {
|
|
22
|
+
/** Event type (from "event:" field, defaults to "message") */
|
|
23
|
+
event: string;
|
|
24
|
+
/** Raw data string */
|
|
25
|
+
data: string;
|
|
26
|
+
/** Event ID (from "id:" field, if present) */
|
|
27
|
+
id?: string;
|
|
28
|
+
/** Retry interval (from "retry:" field, if present) */
|
|
29
|
+
retry?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse a ReadableStream<Uint8Array> into SSE events.
|
|
33
|
+
* Handles multi-line data fields and optional fields.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const events = parseSSEStream(response.body);
|
|
37
|
+
* for await (const event of events) {
|
|
38
|
+
* if (event.event === "message") {
|
|
39
|
+
* const data = JSON.parse(event.data);
|
|
40
|
+
* processMessage(data);
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseSSEStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEEvent>;
|
|
45
|
+
/**
|
|
46
|
+
* Parse SSE stream and auto-parse JSON data.
|
|
47
|
+
* Yields parsed JSON objects for each event with JSON data.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const stream = parseJsonEventStream(response.body);
|
|
51
|
+
* for await (const data of stream) {
|
|
52
|
+
* if (data.type === "text") {
|
|
53
|
+
* processText(data.text);
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseJsonEventStream<T = unknown>(stream: ReadableStream<Uint8Array>): AsyncGenerator<{
|
|
58
|
+
event: string;
|
|
59
|
+
data: T;
|
|
60
|
+
id?: string;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Collect all events from an SSE stream into an array.
|
|
64
|
+
* Useful for testing or when you need all events at once.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const events = await collectSSEEvents(response.body);
|
|
68
|
+
* console.log(`Received ${events.length} events`);
|
|
69
|
+
*/
|
|
70
|
+
export declare function collectSSEEvents(stream: ReadableStream<Uint8Array>): Promise<SSEEvent[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Find the first event matching a given event type.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const message = await findSSEEvent(response.body, "message");
|
|
76
|
+
* if (message) {
|
|
77
|
+
* const data = JSON.parse(message.data);
|
|
78
|
+
* }
|
|
79
|
+
*/
|
|
80
|
+
export declare function findSSEEvent(stream: ReadableStream<Uint8Array>, eventType: string): Promise<SSEEvent | null>;
|
|
81
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/utils/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,yBAAyB;AACzB,MAAM,WAAW,QAAQ;IACvB,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAuB,cAAc,CACnC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC,QAAQ,CAAC,CA6B1B;AAgCD;;;;;;;;;;;GAWG;AACH,wBAAuB,oBAAoB,CAAC,CAAC,GAAG,OAAO,EACrD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAUzD;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAMrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAK1B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/sdk — SSE (Server-Sent Events) Parser
|
|
3
|
+
*
|
|
4
|
+
* Utilities for parsing SSE streams into structured events.
|
|
5
|
+
* Useful for consuming SSE endpoints directly or building custom adapters.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { parseJsonEventStream, parseSSEStream } from "@hilbras/sdk";
|
|
9
|
+
*
|
|
10
|
+
* // Parse a ReadableStream of SSE events
|
|
11
|
+
* for await (const event of parseSSEStream(response.body)) {
|
|
12
|
+
* console.log(event.event, event.data);
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* // Parse SSE and auto-parse JSON data
|
|
16
|
+
* for await (const data of parseJsonEventStream(response.body)) {
|
|
17
|
+
* console.log(data); // parsed JSON object
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Parse a ReadableStream<Uint8Array> into SSE events.
|
|
22
|
+
* Handles multi-line data fields and optional fields.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const events = parseSSEStream(response.body);
|
|
26
|
+
* for await (const event of events) {
|
|
27
|
+
* if (event.event === "message") {
|
|
28
|
+
* const data = JSON.parse(event.data);
|
|
29
|
+
* processMessage(data);
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
export async function* parseSSEStream(stream) {
|
|
34
|
+
const reader = stream.getReader();
|
|
35
|
+
const decoder = new TextDecoder();
|
|
36
|
+
let buffer = "";
|
|
37
|
+
try {
|
|
38
|
+
while (true) {
|
|
39
|
+
const { done, value } = await reader.read();
|
|
40
|
+
if (done)
|
|
41
|
+
break;
|
|
42
|
+
buffer += decoder.decode(value, { stream: true });
|
|
43
|
+
const parts = buffer.split("\n\n");
|
|
44
|
+
buffer = parts.pop() ?? "";
|
|
45
|
+
for (const part of parts) {
|
|
46
|
+
if (!part.trim())
|
|
47
|
+
continue;
|
|
48
|
+
const event = parseSSEBlock(part);
|
|
49
|
+
if (event)
|
|
50
|
+
yield event;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Process remaining buffer
|
|
54
|
+
if (buffer.trim()) {
|
|
55
|
+
const event = parseSSEBlock(buffer);
|
|
56
|
+
if (event)
|
|
57
|
+
yield event;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
reader.releaseLock();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Parse a single SSE block (between double newlines) into an event.
|
|
66
|
+
*/
|
|
67
|
+
function parseSSEBlock(block) {
|
|
68
|
+
const lines = block.split("\n");
|
|
69
|
+
let event = "message";
|
|
70
|
+
let data = "";
|
|
71
|
+
let id;
|
|
72
|
+
let retry;
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
if (line.startsWith("data: ")) {
|
|
75
|
+
const value = line.slice(6);
|
|
76
|
+
data += (data ? "\n" : "") + value;
|
|
77
|
+
}
|
|
78
|
+
else if (line.startsWith("event: ")) {
|
|
79
|
+
event = line.slice(7).trim();
|
|
80
|
+
}
|
|
81
|
+
else if (line.startsWith("id: ")) {
|
|
82
|
+
id = line.slice(4).trim();
|
|
83
|
+
}
|
|
84
|
+
else if (line.startsWith("retry: ")) {
|
|
85
|
+
const n = parseInt(line.slice(7).trim(), 10);
|
|
86
|
+
if (!isNaN(n))
|
|
87
|
+
retry = n;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Empty data means skip this event (except for comments)
|
|
91
|
+
if (!data && !id)
|
|
92
|
+
return null;
|
|
93
|
+
return { event, data, id, retry };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse SSE stream and auto-parse JSON data.
|
|
97
|
+
* Yields parsed JSON objects for each event with JSON data.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const stream = parseJsonEventStream(response.body);
|
|
101
|
+
* for await (const data of stream) {
|
|
102
|
+
* if (data.type === "text") {
|
|
103
|
+
* processText(data.text);
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
*/
|
|
107
|
+
export async function* parseJsonEventStream(stream) {
|
|
108
|
+
for await (const sseEvent of parseSSEStream(stream)) {
|
|
109
|
+
try {
|
|
110
|
+
const data = JSON.parse(sseEvent.data);
|
|
111
|
+
yield { event: sseEvent.event, data, id: sseEvent.id };
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Skip events with non-JSON data
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Collect all events from an SSE stream into an array.
|
|
121
|
+
* Useful for testing or when you need all events at once.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const events = await collectSSEEvents(response.body);
|
|
125
|
+
* console.log(`Received ${events.length} events`);
|
|
126
|
+
*/
|
|
127
|
+
export async function collectSSEEvents(stream) {
|
|
128
|
+
const events = [];
|
|
129
|
+
for await (const event of parseSSEStream(stream)) {
|
|
130
|
+
events.push(event);
|
|
131
|
+
}
|
|
132
|
+
return events;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Find the first event matching a given event type.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const message = await findSSEEvent(response.body, "message");
|
|
139
|
+
* if (message) {
|
|
140
|
+
* const data = JSON.parse(message.data);
|
|
141
|
+
* }
|
|
142
|
+
*/
|
|
143
|
+
export async function findSSEEvent(stream, eventType) {
|
|
144
|
+
for await (const event of parseSSEStream(stream)) {
|
|
145
|
+
if (event.event === eventType)
|
|
146
|
+
return event;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/utils/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAcH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,cAAc,CACnC,MAAkC;IAElC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,MAAM;YAEhB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACnC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;oBAAE,SAAS;gBAC3B,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;gBAClC,IAAI,KAAK;oBAAE,MAAM,KAAK,CAAC;YACzB,CAAC;QACH,CAAC;QAED,2BAA2B;QAC3B,IAAI,MAAM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C;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilbras/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Provider-agnostic LLM client SDK — streaming, tool calling, embeddings, image generation, speech synthesis, transcription, reranking, circuit breaker, retry, reasoning normalization, cost enforcement,
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "Provider-agnostic LLM client SDK — streaming, tool calling, embeddings, image generation, speech synthesis, transcription, reranking, circuit breaker, retry, reasoning normalization, cost enforcement, structured output with schema validation, type-safe tool builder, and SSRF-safe provider registration. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|