@codeworksh/aikit 0.3.1 → 0.4.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 +73 -81
- package/{agent → dist/pack/agent}/codemode/drivers/drivers.d.mts +1 -1
- package/dist/pack/codemode-BEDXG7WN.d.mts +8736 -0
- package/{index.d.mts → dist/pack/index.d.mts} +1 -1
- package/dist/pack/index.mjs +8226 -0
- package/dist/pack/index.mjs.map +1 -0
- package/package.json +31 -24
- package/src/agent/agent.ts +790 -0
- package/src/agent/codemode/codemode.ts +561 -0
- package/src/agent/codemode/drivers/drivers.ts +1 -0
- package/src/agent/codemode/drivers/quickjs-wasi-driver.ts +149 -0
- package/src/agent/codemode/index.ts +1 -0
- package/src/agent/loop.ts +903 -0
- package/src/agent.ts +11 -0
- package/src/event/event.ts +277 -0
- package/src/index.ts +6 -0
- package/src/llm.ts +31 -0
- package/src/message/message.ts +311 -0
- package/src/model/catalog.ts +94 -0
- package/src/model/model.ts +250 -0
- package/src/model/transform.ts +59 -0
- package/src/provider/provider.ts +60 -0
- package/src/provider/providers/anthropic/index.ts +792 -0
- package/src/provider/providers/github/github.ts +34 -0
- package/src/provider/providers/openai/completions.ts +953 -0
- package/src/provider/providers/utils.ts +7 -0
- package/src/provider/register.ts +6 -0
- package/src/provider/stream.ts +278 -0
- package/src/stream.ts +72 -0
- package/src/utils/eventstream.ts +95 -0
- package/src/utils/helpers.ts +24 -0
- package/src/utils/jsonparse.ts +32 -0
- package/src/utils/overflow.ts +121 -0
- package/src/utils/sanitize.ts +25 -0
- package/src/utils/validation.ts +87 -0
- package/LICENSE +0 -21
- package/codemode-SiETGR3z.d.mts +0 -8410
- package/index.mjs +0 -3381
- package/index.mjs.map +0 -1
- /package/{agent → dist/pack/agent}/codemode/drivers/drivers.mjs +0 -0
- /package/{agent → dist/pack/agent}/codemode/drivers/drivers.mjs.map +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Validation powered by TypeBox's built-in schema compiler.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Static, TSchema } from "typebox";
|
|
6
|
+
import Schema from "typebox/schema";
|
|
7
|
+
import Value from "typebox/value";
|
|
8
|
+
|
|
9
|
+
import type { Agent } from "../agent/agent";
|
|
10
|
+
import type { Message } from "../message/message";
|
|
11
|
+
|
|
12
|
+
const validators = new WeakMap<TSchema, ReturnType<typeof Schema.Compile>>();
|
|
13
|
+
|
|
14
|
+
function getValidator<T extends TSchema>(schema: T): ReturnType<typeof Schema.Compile<T>> {
|
|
15
|
+
const existing = validators.get(schema) as ReturnType<typeof Schema.Compile<T>> | undefined;
|
|
16
|
+
if (existing) return existing;
|
|
17
|
+
|
|
18
|
+
const validator = Schema.Compile(schema);
|
|
19
|
+
validators.set(schema, validator);
|
|
20
|
+
return validator;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function errorPath(error: { instancePath?: string; params?: Record<string, unknown> }): string {
|
|
24
|
+
if (error.instancePath) return error.instancePath.substring(1);
|
|
25
|
+
|
|
26
|
+
const requiredProperties = error.params?.requiredProperties;
|
|
27
|
+
if (Array.isArray(requiredProperties)) return requiredProperties.join(", ");
|
|
28
|
+
|
|
29
|
+
return "root";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Validates an arbitrary value against a TypeBox schema and returns the coerced value.
|
|
34
|
+
*/
|
|
35
|
+
export function validateSchema<T extends TSchema>(schema: T, value: unknown, label: string): Static<T> {
|
|
36
|
+
const validator = getValidator(schema);
|
|
37
|
+
const input = Value.Convert(schema, structuredClone(value));
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
return validator.Parse(input);
|
|
41
|
+
} catch {
|
|
42
|
+
const [_result, validationErrors] = validator.Errors(input);
|
|
43
|
+
const errors =
|
|
44
|
+
validationErrors
|
|
45
|
+
.map((err) => {
|
|
46
|
+
return ` - ${errorPath(err)}: ${err.message}`;
|
|
47
|
+
})
|
|
48
|
+
.join("\n") || "Unknown Validation Error";
|
|
49
|
+
|
|
50
|
+
throw new Error(
|
|
51
|
+
[
|
|
52
|
+
`Validation Failed For ${label}`,
|
|
53
|
+
`${errors}\n`,
|
|
54
|
+
"Received Value:",
|
|
55
|
+
`${JSON.stringify(value, null, 2)}\n`,
|
|
56
|
+
].join("\n"),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Finds a tool by name and validates the tool call arguments against its TypeBox schema
|
|
63
|
+
*/
|
|
64
|
+
export function validateToolCall<T extends Message.Tool>(
|
|
65
|
+
tools: T[],
|
|
66
|
+
toolExecution: Agent.ToolCallInFlight,
|
|
67
|
+
): Message.ToolArguments<T> {
|
|
68
|
+
const tool = tools.find((t) => t.name === toolExecution.name);
|
|
69
|
+
if (!tool) {
|
|
70
|
+
throw new Error(`Tool "${toolExecution.name}" not found`);
|
|
71
|
+
}
|
|
72
|
+
return validateToolArguments(tool, toolExecution);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validates tool call arguments against the tool's TypeBox schema
|
|
77
|
+
*/
|
|
78
|
+
export function validateToolArguments<T extends Message.Tool>(
|
|
79
|
+
tool: T,
|
|
80
|
+
toolExecution: Agent.ToolCallInFlight,
|
|
81
|
+
): Message.ToolArguments<T> {
|
|
82
|
+
return validateSchema(
|
|
83
|
+
tool.parameters,
|
|
84
|
+
toolExecution.rawArgs,
|
|
85
|
+
`Tool "${toolExecution.name}"`,
|
|
86
|
+
) as Message.ToolArguments<T>;
|
|
87
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Sanchit Kudari
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|