@code-yeongyu/senpi-ai 2026.10.25-4 → 2026.10.26-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.
Files changed (45) hide show
  1. package/dist/api/anthropic-messages.js +19 -2
  2. package/dist/api/azure-openai-responses.js +1 -1
  3. package/dist/api/bedrock-converse-stream.js +13 -1
  4. package/dist/api/cursor-agent.js +2 -2
  5. package/dist/api/devin-agent/stream-state.js +8 -0
  6. package/dist/api/devin-agent.js +1 -1
  7. package/dist/api/google-generative-ai.js +22 -10
  8. package/dist/api/google-vertex.js +22 -10
  9. package/dist/api/lazy.js +8 -2
  10. package/dist/api/mistral-conversations.js +1 -1
  11. package/dist/api/openai-codex-responses.js +1 -1
  12. package/dist/api/openai-completions.js +9 -4
  13. package/dist/api/openai-responses-shared.js +37 -3
  14. package/dist/api/openai-responses.js +1 -1
  15. package/dist/api/pi-messages.js +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/providers/data/.manifest.json +1 -1
  19. package/dist/providers/data/amazon-bedrock.json +1 -1
  20. package/dist/providers/data/opengateway.json +1 -1
  21. package/dist/providers/data/openrouter.json +1 -1
  22. package/dist/providers/faux.js +5 -1
  23. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.js +37 -2
  24. package/dist/tool-call-middleware/recovery-event-stream.d.ts +12 -1
  25. package/dist/tool-call-middleware/recovery-event-stream.js +30 -4
  26. package/dist/tool-call-middleware/recovery-native-projection.d.ts +10 -0
  27. package/dist/tool-call-middleware/recovery-native-projection.js +36 -7
  28. package/dist/tool-call-middleware/recovery-stream-failure.js +3 -2
  29. package/dist/tool-call-middleware/recovery-stream-terminal.d.ts +6 -0
  30. package/dist/tool-call-middleware/recovery-stream-terminal.js +35 -17
  31. package/dist/tool-call-middleware/recovery-stream-wrapper.js +26 -12
  32. package/dist/tool-call-middleware/stream-wrapper.js +3 -1
  33. package/dist/utils/assistant-capture.d.ts +101 -0
  34. package/dist/utils/assistant-capture.js +327 -0
  35. package/dist/utils/event-stream.d.ts +15 -2
  36. package/dist/utils/event-stream.js +57 -8
  37. package/dist/utils/tool-argument-coercion.d.ts +2 -0
  38. package/dist/utils/tool-argument-coercion.js +74 -0
  39. package/dist/utils/tool-argument-validator.d.ts +20 -0
  40. package/dist/utils/tool-argument-validator.js +9 -0
  41. package/dist/utils/tool-schema-compat.d.ts +5 -0
  42. package/dist/utils/tool-schema-compat.js +5 -0
  43. package/dist/utils/validation.d.ts +1 -0
  44. package/dist/utils/validation.js +14 -75
  45. package/package.json +2 -2
@@ -1,5 +1,8 @@
1
1
  import { Compile } from "typebox/compile";
2
2
  import { Value } from "typebox/value";
3
+ import { getToolArgumentValidator } from "./tool-argument-validator.js";
4
+ import { coercePrimitiveByType } from "./tool-argument-coercion.js";
5
+ export { registerToolArgumentValidator } from "./tool-argument-validator.js";
3
6
  const validatorCache = new WeakMap();
4
7
  const TYPEBOX_KIND = Symbol.for("TypeBox.Kind");
5
8
  function getSchemaTypes(schema) {
@@ -39,79 +42,6 @@ function getSubSchemaValidator(schema) {
39
42
  return undefined;
40
43
  }
41
44
  }
42
- function coercePrimitiveByType(value, type) {
43
- switch (type) {
44
- case "number": {
45
- if (value === null) {
46
- return 0;
47
- }
48
- if (typeof value === "string" && value.trim() !== "") {
49
- const parsed = Number(value);
50
- if (Number.isFinite(parsed)) {
51
- return parsed;
52
- }
53
- }
54
- if (typeof value === "boolean") {
55
- return value ? 1 : 0;
56
- }
57
- return value;
58
- }
59
- case "integer": {
60
- if (value === null) {
61
- return 0;
62
- }
63
- if (typeof value === "string" && value.trim() !== "") {
64
- const parsed = Number(value);
65
- if (Number.isInteger(parsed)) {
66
- return parsed;
67
- }
68
- }
69
- if (typeof value === "boolean") {
70
- return value ? 1 : 0;
71
- }
72
- return value;
73
- }
74
- case "boolean": {
75
- if (value === null) {
76
- return false;
77
- }
78
- if (typeof value === "string") {
79
- if (value === "true") {
80
- return true;
81
- }
82
- if (value === "false") {
83
- return false;
84
- }
85
- }
86
- if (typeof value === "number") {
87
- if (value === 1) {
88
- return true;
89
- }
90
- if (value === 0) {
91
- return false;
92
- }
93
- }
94
- return value;
95
- }
96
- case "string": {
97
- if (value === null) {
98
- return "";
99
- }
100
- if (typeof value === "number" || typeof value === "boolean") {
101
- return String(value);
102
- }
103
- return value;
104
- }
105
- case "null": {
106
- if (value === "" || value === 0 || value === false) {
107
- return null;
108
- }
109
- return value;
110
- }
111
- default:
112
- return value;
113
- }
114
- }
115
45
  function applySchemaObjectCoercion(value, schema) {
116
46
  const properties = schema.properties;
117
47
  const definedKeys = new Set(properties ? Object.keys(properties) : []);
@@ -246,8 +176,7 @@ function getValidator(schema) {
246
176
  }
247
177
  function formatValidationPath(error) {
248
178
  if (error.keyword === "required") {
249
- const requiredProperties = error.params.requiredProperties;
250
- const requiredProperty = requiredProperties?.[0];
179
+ const requiredProperty = error.params.requiredProperties?.[0] ?? error.params.missingProperty;
251
180
  if (requiredProperty) {
252
181
  const basePath = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
253
182
  return basePath ? `${basePath}.${requiredProperty}` : requiredProperty;
@@ -279,6 +208,16 @@ export function validateToolCall(tools, toolCall) {
279
208
  */
280
209
  export function validateToolArguments(tool, toolCall) {
281
210
  const args = structuredClone(toolCall.arguments);
211
+ const protocolValidator = getToolArgumentValidator(tool.parameters);
212
+ if (protocolValidator !== undefined) {
213
+ if (!protocolValidator(args)) {
214
+ const errors = protocolValidator.errors
215
+ ?.map((error) => ` - ${formatValidationPath(error)}: ${error.message ?? error.keyword} (${error.keyword})`)
216
+ .join("\n") || "Unknown validation error";
217
+ throw new Error(`Validation failed for tool "${toolCall.name}":\n${errors}`);
218
+ }
219
+ return args;
220
+ }
282
221
  normalizeOptionalNulls(args, tool.parameters);
283
222
  Value.Convert(tool.parameters, args);
284
223
  const validator = getValidator(tool.parameters);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-ai",
3
- "version": "2026.10.25-4",
3
+ "version": "2026.10.26-2",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -88,7 +88,7 @@
88
88
  "dependencies": {
89
89
  "@anthropic-ai/sdk": "0.127.0",
90
90
  "@aws-sdk/client-bedrock-runtime": "3.1136.0",
91
- "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.10.25-4",
91
+ "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.10.26-2",
92
92
  "@google/genai": "2.23.0",
93
93
  "@smithy/node-http-handler": "4.12.1",
94
94
  "google-auth-library": "10.6.2",