@struktur/sdk 2.1.2 → 2.2.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.
Files changed (105) hide show
  1. package/dist/index.js +4111 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/parsers.js +492 -0
  4. package/dist/parsers.js.map +1 -0
  5. package/dist/strategies.js +2435 -0
  6. package/dist/strategies.js.map +1 -0
  7. package/package.json +24 -12
  8. package/src/agent-cli-integration.test.ts +0 -47
  9. package/src/agent-export.test.ts +0 -17
  10. package/src/agent-tool-labels.test.ts +0 -50
  11. package/src/artifacts/AGENTS.md +0 -16
  12. package/src/artifacts/fileToArtifact.test.ts +0 -37
  13. package/src/artifacts/fileToArtifact.ts +0 -44
  14. package/src/artifacts/input.test.ts +0 -243
  15. package/src/artifacts/input.ts +0 -360
  16. package/src/artifacts/providers.test.ts +0 -19
  17. package/src/artifacts/providers.ts +0 -7
  18. package/src/artifacts/urlToArtifact.test.ts +0 -23
  19. package/src/artifacts/urlToArtifact.ts +0 -19
  20. package/src/auth/AGENTS.md +0 -11
  21. package/src/auth/config.test.ts +0 -132
  22. package/src/auth/config.ts +0 -186
  23. package/src/auth/tokens.test.ts +0 -58
  24. package/src/auth/tokens.ts +0 -229
  25. package/src/chunking/AGENTS.md +0 -11
  26. package/src/chunking/ArtifactBatcher.test.ts +0 -22
  27. package/src/chunking/ArtifactBatcher.ts +0 -110
  28. package/src/chunking/ArtifactSplitter.test.ts +0 -38
  29. package/src/chunking/ArtifactSplitter.ts +0 -151
  30. package/src/debug/AGENTS.md +0 -79
  31. package/src/debug/logger.test.ts +0 -244
  32. package/src/debug/logger.ts +0 -211
  33. package/src/extract.test.ts +0 -22
  34. package/src/extract.ts +0 -150
  35. package/src/fields.test.ts +0 -681
  36. package/src/fields.ts +0 -246
  37. package/src/index.test.ts +0 -20
  38. package/src/index.ts +0 -110
  39. package/src/llm/AGENTS.md +0 -9
  40. package/src/llm/LLMClient.test.ts +0 -394
  41. package/src/llm/LLMClient.ts +0 -264
  42. package/src/llm/RetryingRunner.test.ts +0 -174
  43. package/src/llm/RetryingRunner.ts +0 -270
  44. package/src/llm/message.test.ts +0 -42
  45. package/src/llm/message.ts +0 -47
  46. package/src/llm/models.test.ts +0 -82
  47. package/src/llm/models.ts +0 -190
  48. package/src/llm/resolveModel.ts +0 -86
  49. package/src/merge/AGENTS.md +0 -6
  50. package/src/merge/Deduplicator.test.ts +0 -108
  51. package/src/merge/Deduplicator.ts +0 -45
  52. package/src/merge/SmartDataMerger.test.ts +0 -177
  53. package/src/merge/SmartDataMerger.ts +0 -56
  54. package/src/parsers/AGENTS.md +0 -58
  55. package/src/parsers/collect.test.ts +0 -56
  56. package/src/parsers/collect.ts +0 -31
  57. package/src/parsers/index.ts +0 -6
  58. package/src/parsers/mime.test.ts +0 -91
  59. package/src/parsers/mime.ts +0 -137
  60. package/src/parsers/npm.ts +0 -26
  61. package/src/parsers/pdf.test.ts +0 -394
  62. package/src/parsers/pdf.ts +0 -194
  63. package/src/parsers/runner.test.ts +0 -95
  64. package/src/parsers/runner.ts +0 -177
  65. package/src/parsers/types.ts +0 -29
  66. package/src/prompts/AGENTS.md +0 -8
  67. package/src/prompts/DeduplicationPrompt.test.ts +0 -41
  68. package/src/prompts/DeduplicationPrompt.ts +0 -37
  69. package/src/prompts/ExtractorPrompt.test.ts +0 -21
  70. package/src/prompts/ExtractorPrompt.ts +0 -72
  71. package/src/prompts/ParallelMergerPrompt.test.ts +0 -8
  72. package/src/prompts/ParallelMergerPrompt.ts +0 -37
  73. package/src/prompts/SequentialExtractorPrompt.test.ts +0 -24
  74. package/src/prompts/SequentialExtractorPrompt.ts +0 -82
  75. package/src/prompts/formatArtifacts.test.ts +0 -39
  76. package/src/prompts/formatArtifacts.ts +0 -46
  77. package/src/strategies/AGENTS.md +0 -6
  78. package/src/strategies/DoublePassAutoMergeStrategy.test.ts +0 -53
  79. package/src/strategies/DoublePassAutoMergeStrategy.ts +0 -410
  80. package/src/strategies/DoublePassStrategy.test.ts +0 -48
  81. package/src/strategies/DoublePassStrategy.ts +0 -266
  82. package/src/strategies/ParallelAutoMergeStrategy.test.ts +0 -152
  83. package/src/strategies/ParallelAutoMergeStrategy.ts +0 -345
  84. package/src/strategies/ParallelStrategy.test.ts +0 -61
  85. package/src/strategies/ParallelStrategy.ts +0 -208
  86. package/src/strategies/SequentialAutoMergeStrategy.test.ts +0 -66
  87. package/src/strategies/SequentialAutoMergeStrategy.ts +0 -325
  88. package/src/strategies/SequentialStrategy.test.ts +0 -53
  89. package/src/strategies/SequentialStrategy.ts +0 -142
  90. package/src/strategies/SimpleStrategy.test.ts +0 -46
  91. package/src/strategies/SimpleStrategy.ts +0 -94
  92. package/src/strategies/concurrency.test.ts +0 -16
  93. package/src/strategies/concurrency.ts +0 -14
  94. package/src/strategies/index.test.ts +0 -20
  95. package/src/strategies/index.ts +0 -7
  96. package/src/strategies/utils.test.ts +0 -76
  97. package/src/strategies/utils.ts +0 -95
  98. package/src/tokenization.test.ts +0 -119
  99. package/src/tokenization.ts +0 -71
  100. package/src/types.test.ts +0 -25
  101. package/src/types.ts +0 -174
  102. package/src/validation/AGENTS.md +0 -7
  103. package/src/validation/validator.test.ts +0 -204
  104. package/src/validation/validator.ts +0 -90
  105. package/tsconfig.json +0 -22
@@ -1,204 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import type { JSONSchemaType, ErrorObject } from "ajv";
3
- import { createAjv, validateOrThrow, SchemaValidationError, isRequiredError, validateAllowingMissingRequired } from "./validator";
4
-
5
- type Person = {
6
- name: string;
7
- age: number;
8
- };
9
-
10
- const personSchema: JSONSchemaType<Person> = {
11
- type: "object",
12
- properties: {
13
- name: { type: "string" },
14
- age: { type: "number" },
15
- },
16
- required: ["name", "age"],
17
- additionalProperties: false,
18
- };
19
-
20
- type NestedSchema = {
21
- user: {
22
- name: string;
23
- email: string;
24
- };
25
- items: string[];
26
- };
27
-
28
- const nestedSchema: JSONSchemaType<NestedSchema> = {
29
- type: "object",
30
- properties: {
31
- user: {
32
- type: "object",
33
- properties: {
34
- name: { type: "string" },
35
- email: { type: "string", format: "email" },
36
- },
37
- required: ["name", "email"],
38
- },
39
- items: {
40
- type: "array",
41
- items: { type: "string" },
42
- },
43
- },
44
- required: ["user", "items"],
45
- };
46
-
47
- test("validateOrThrow returns typed data for valid input", () => {
48
- const ajv = createAjv();
49
- const data = validateOrThrow<Person>(ajv, personSchema, {
50
- name: "Ada",
51
- age: 33,
52
- });
53
-
54
- expect(data.name).toBe("Ada");
55
- expect(data.age).toBe(33);
56
- });
57
-
58
- test("validateOrThrow throws SchemaValidationError for invalid input", () => {
59
- const ajv = createAjv();
60
- try {
61
- validateOrThrow<Person>(ajv, personSchema, { name: "Ada" });
62
- throw new Error("Expected validation error");
63
- } catch (error) {
64
- expect(error).toBeInstanceOf(SchemaValidationError);
65
- const validationError = error as SchemaValidationError;
66
- expect(validationError.errors.length).toBeGreaterThan(0);
67
- }
68
- });
69
-
70
- test("createAjv supports common formats", () => {
71
- const ajv = createAjv();
72
- const schema: JSONSchemaType<string> = { type: "string", format: "email" };
73
-
74
- const data = validateOrThrow<string>(ajv, schema, "test@example.com");
75
- expect(data).toBe("test@example.com");
76
-
77
- try {
78
- validateOrThrow<string>(ajv, schema, "not-an-email");
79
- throw new Error("Expected validation error");
80
- } catch (error) {
81
- expect(error).toBeInstanceOf(SchemaValidationError);
82
- }
83
- });
84
-
85
- test("createAjv supports artifact-id format", () => {
86
- const ajv = createAjv();
87
- const schema: JSONSchemaType<string> = { type: "string", format: "artifact-id" };
88
-
89
- const validData = validateOrThrow<string>(ajv, schema, "artifact:123456/images/image1.jpg");
90
- expect(validData).toBe("artifact:123456/images/image1.jpg");
91
-
92
- const validData2 = validateOrThrow<string>(ajv, schema, "artifact:abc-xyz/images/image10.png");
93
- expect(validData2).toBe("artifact:abc-xyz/images/image10.png");
94
-
95
- try {
96
- validateOrThrow<string>(ajv, schema, "not-an-artifact-id");
97
- throw new Error("Expected validation error");
98
- } catch (error) {
99
- expect(error).toBeInstanceOf(SchemaValidationError);
100
- }
101
-
102
- try {
103
- validateOrThrow<string>(ajv, schema, "artifact:123/images/image");
104
- throw new Error("Expected validation error");
105
- } catch (error) {
106
- expect(error).toBeInstanceOf(SchemaValidationError);
107
- }
108
-
109
- try {
110
- validateOrThrow<string>(ajv, schema, "https://example.com/image.jpg");
111
- throw new Error("Expected validation error");
112
- } catch (error) {
113
- expect(error).toBeInstanceOf(SchemaValidationError);
114
- }
115
- });
116
-
117
- test("isRequiredError identifies required constraint violations", () => {
118
- const requiredError = {
119
- keyword: "required",
120
- params: { missingProperty: "name" },
121
- instancePath: "",
122
- schemaPath: "#/required"
123
- } as unknown as ErrorObject;
124
- const typeError = {
125
- keyword: "type",
126
- params: { type: "string" },
127
- instancePath: "/age",
128
- schemaPath: "#/properties/age/type"
129
- } as unknown as ErrorObject;
130
-
131
- expect(isRequiredError(requiredError)).toBe(true);
132
- expect(isRequiredError(typeError)).toBe(false);
133
- });
134
-
135
- test("validateAllowingMissingRequired ignores required errors but catches type errors", () => {
136
- const ajv = createAjv();
137
-
138
- const resultMissingRequired = validateAllowingMissingRequired<Person>(
139
- ajv,
140
- personSchema,
141
- { name: "Ada" }
142
- );
143
- expect(resultMissingRequired.valid).toBe(true);
144
- if (resultMissingRequired.valid) {
145
- expect(resultMissingRequired.data.name).toBe("Ada");
146
- }
147
-
148
- const resultTypeError = validateAllowingMissingRequired<Person>(
149
- ajv,
150
- personSchema,
151
- { name: "Ada", age: "thirty-three" }
152
- );
153
- expect(resultTypeError.valid).toBe(false);
154
- if (!resultTypeError.valid) {
155
- expect(resultTypeError.errors.some(e => e.keyword === "type")).toBe(true);
156
- }
157
-
158
- const resultValid = validateAllowingMissingRequired<Person>(
159
- ajv,
160
- personSchema,
161
- { name: "Ada", age: 33 }
162
- );
163
- expect(resultValid.valid).toBe(true);
164
- if (resultValid.valid) {
165
- expect(resultValid.data.name).toBe("Ada");
166
- expect(resultValid.data.age).toBe(33);
167
- }
168
- });
169
-
170
- test("validateAllowingMissingRequired handles format errors", () => {
171
- const ajv = createAjv();
172
-
173
- const result = validateAllowingMissingRequired<NestedSchema>(
174
- ajv,
175
- nestedSchema,
176
- {
177
- user: { name: "Ada", email: "not-an-email" },
178
- items: ["a", "b"]
179
- }
180
- );
181
-
182
- expect(result.valid).toBe(false);
183
- if (!result.valid) {
184
- expect(result.errors.some(e => e.keyword === "format")).toBe(true);
185
- }
186
- });
187
-
188
- test("validateAllowingMissingRequired handles nested required field errors", () => {
189
- const ajv = createAjv();
190
-
191
- const result = validateAllowingMissingRequired<NestedSchema>(
192
- ajv,
193
- nestedSchema,
194
- {
195
- user: { name: "Ada" },
196
- items: ["a"]
197
- }
198
- );
199
-
200
- expect(result.valid).toBe(true);
201
- if (result.valid) {
202
- expect(result.data.user.name).toBe("Ada");
203
- }
204
- });
@@ -1,90 +0,0 @@
1
- import Ajv, { type AnySchema, type ErrorObject, type JSONSchemaType } from "ajv";
2
- import addFormats from "ajv-formats";
3
-
4
- export type ValidationErrors = ErrorObject[];
5
-
6
- export type ValidationMode = 'strict' | 'lenient';
7
-
8
- export type ValidationResult<T> =
9
- | { valid: true; data: T }
10
- | { valid: false; errors: ErrorObject[] };
11
-
12
- export class SchemaValidationError extends Error {
13
- public readonly errors: ValidationErrors;
14
-
15
- constructor(message: string, errors: ValidationErrors) {
16
- super(message);
17
- this.name = "SchemaValidationError";
18
- this.errors = errors;
19
- }
20
- }
21
-
22
- const ARTIFACT_ID_PATTERN = /^artifact:[^/]+\/images\/image\d+\.\w+$/;
23
-
24
- export const createAjv = () => {
25
- const ajv = new Ajv({
26
- allErrors: true,
27
- strict: false,
28
- allowUnionTypes: true,
29
- });
30
- addFormats(ajv);
31
-
32
- ajv.addFormat("artifact-id", {
33
- type: "string",
34
- validate: (data: string) => ARTIFACT_ID_PATTERN.test(data),
35
- });
36
-
37
- return ajv;
38
- };
39
-
40
- export type SchemaInput<T> = JSONSchemaType<T> | AnySchema;
41
-
42
- export const validateOrThrow = <T>(
43
- ajv: Ajv,
44
- schema: SchemaInput<T>,
45
- data: unknown
46
- ): T => {
47
- const validate = ajv.compile<T>(schema);
48
- const valid = validate(data);
49
-
50
- if (!valid) {
51
- const errors = validate.errors ?? [];
52
- const message = "Schema validation failed";
53
- throw new SchemaValidationError(message, errors);
54
- }
55
-
56
- return data as T;
57
- };
58
-
59
- export const isRequiredError = (error: ErrorObject): boolean => {
60
- return error.keyword === "required";
61
- };
62
-
63
- export const validateAllowingMissingRequired = <T>(
64
- ajv: Ajv,
65
- schema: SchemaInput<T>,
66
- data: unknown,
67
- isFinalAttempt: boolean = true
68
- ): ValidationResult<T> => {
69
- const validate = ajv.compile<T>(schema);
70
- const valid = validate(data);
71
-
72
- if (valid) {
73
- return { valid: true, data: data as T };
74
- }
75
-
76
- const errors = validate.errors ?? [];
77
- const nonRequiredErrors = errors.filter((error) => !isRequiredError(error));
78
-
79
- if (nonRequiredErrors.length === 0) {
80
- // Only required field errors
81
- // On final attempt, accept partial data
82
- // On non-final attempts, return invalid to trigger retry
83
- if (isFinalAttempt) {
84
- return { valid: true, data: data as T };
85
- }
86
- return { valid: false, errors };
87
- }
88
-
89
- return { valid: false, errors: nonRequiredErrors };
90
- };
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["ESNext"],
4
- "target": "ESNext",
5
- "module": "Preserve",
6
- "moduleDetection": "force",
7
- "jsx": "react-jsx",
8
- "allowJs": true,
9
- "moduleResolution": "bundler",
10
- "allowImportingTsExtensions": true,
11
- "verbatimModuleSyntax": true,
12
- "noEmit": true,
13
- "strict": true,
14
- "skipLibCheck": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "noUncheckedIndexedAccess": true,
17
- "noImplicitOverride": true,
18
- "noUnusedLocals": false,
19
- "noUnusedParameters": false,
20
- "noPropertyAccessFromIndexSignature": false
21
- }
22
- }