@struktur/sdk 2.1.2 → 2.3.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 (200) hide show
  1. package/dist/artifacts/fileToArtifact.d.ts +8 -0
  2. package/dist/artifacts/fileToArtifact.d.ts.map +1 -0
  3. package/dist/artifacts/input.d.ts +60 -0
  4. package/dist/artifacts/input.d.ts.map +1 -0
  5. package/{src/artifacts/providers.ts → dist/artifacts/providers.d.ts} +2 -4
  6. package/dist/artifacts/providers.d.ts.map +1 -0
  7. package/dist/artifacts/urlToArtifact.d.ts +3 -0
  8. package/dist/artifacts/urlToArtifact.d.ts.map +1 -0
  9. package/dist/auth/config.d.ts +34 -0
  10. package/dist/auth/config.d.ts.map +1 -0
  11. package/dist/auth/tokens.d.ts +18 -0
  12. package/dist/auth/tokens.d.ts.map +1 -0
  13. package/dist/chunking/ArtifactBatcher.d.ts +11 -0
  14. package/dist/chunking/ArtifactBatcher.d.ts.map +1 -0
  15. package/dist/chunking/ArtifactSplitter.d.ts +10 -0
  16. package/dist/chunking/ArtifactSplitter.d.ts.map +1 -0
  17. package/dist/debug/logger.d.ts +169 -0
  18. package/dist/debug/logger.d.ts.map +1 -0
  19. package/dist/extract.d.ts +3 -0
  20. package/dist/extract.d.ts.map +1 -0
  21. package/dist/fields.d.ts +75 -0
  22. package/dist/fields.d.ts.map +1 -0
  23. package/dist/index.d.ts +24 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +5603 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/llm/LLMClient.d.ts +40 -0
  28. package/dist/llm/LLMClient.d.ts.map +1 -0
  29. package/dist/llm/RetryingRunner.d.ts +37 -0
  30. package/dist/llm/RetryingRunner.d.ts.map +1 -0
  31. package/dist/llm/message.d.ts +12 -0
  32. package/dist/llm/message.d.ts.map +1 -0
  33. package/dist/llm/models.d.ts +13 -0
  34. package/dist/llm/models.d.ts.map +1 -0
  35. package/dist/llm/resolveModel.d.ts +3 -0
  36. package/dist/llm/resolveModel.d.ts.map +1 -0
  37. package/dist/merge/Deduplicator.d.ts +4 -0
  38. package/dist/merge/Deduplicator.d.ts.map +1 -0
  39. package/dist/merge/SmartDataMerger.d.ts +7 -0
  40. package/dist/merge/SmartDataMerger.d.ts.map +1 -0
  41. package/dist/parsers/collect.d.ts +7 -0
  42. package/dist/parsers/collect.d.ts.map +1 -0
  43. package/{src/parsers/index.ts → dist/parsers/index.d.ts} +1 -0
  44. package/dist/parsers/index.d.ts.map +1 -0
  45. package/dist/parsers/mime.d.ts +12 -0
  46. package/dist/parsers/mime.d.ts.map +1 -0
  47. package/dist/parsers/npm.d.ts +16 -0
  48. package/dist/parsers/npm.d.ts.map +1 -0
  49. package/dist/parsers/pdf.d.ts +36 -0
  50. package/dist/parsers/pdf.d.ts.map +1 -0
  51. package/dist/parsers/runner.d.ts +4 -0
  52. package/dist/parsers/runner.d.ts.map +1 -0
  53. package/dist/parsers/types.d.ts +27 -0
  54. package/dist/parsers/types.d.ts.map +1 -0
  55. package/dist/parsers.d.ts +1 -0
  56. package/dist/parsers.js +492 -0
  57. package/dist/parsers.js.map +1 -0
  58. package/dist/prompts/DeduplicationPrompt.d.ts +5 -0
  59. package/dist/prompts/DeduplicationPrompt.d.ts.map +1 -0
  60. package/dist/prompts/ExtractorPrompt.d.ts +6 -0
  61. package/dist/prompts/ExtractorPrompt.d.ts.map +1 -0
  62. package/dist/prompts/ParallelMergerPrompt.d.ts +5 -0
  63. package/dist/prompts/ParallelMergerPrompt.d.ts.map +1 -0
  64. package/dist/prompts/SequentialExtractorPrompt.d.ts +6 -0
  65. package/dist/prompts/SequentialExtractorPrompt.d.ts.map +1 -0
  66. package/dist/prompts/formatArtifacts.d.ts +3 -0
  67. package/dist/prompts/formatArtifacts.d.ts.map +1 -0
  68. package/dist/strategies/DoublePassAutoMergeStrategy.d.ts +23 -0
  69. package/dist/strategies/DoublePassAutoMergeStrategy.d.ts.map +1 -0
  70. package/dist/strategies/DoublePassStrategy.d.ts +22 -0
  71. package/dist/strategies/DoublePassStrategy.d.ts.map +1 -0
  72. package/dist/strategies/ParallelAutoMergeStrategy.d.ts +27 -0
  73. package/dist/strategies/ParallelAutoMergeStrategy.d.ts.map +1 -0
  74. package/dist/strategies/ParallelStrategy.d.ts +22 -0
  75. package/dist/strategies/ParallelStrategy.d.ts.map +1 -0
  76. package/dist/strategies/SequentialAutoMergeStrategy.d.ts +22 -0
  77. package/dist/strategies/SequentialAutoMergeStrategy.d.ts.map +1 -0
  78. package/dist/strategies/SequentialStrategy.d.ts +20 -0
  79. package/dist/strategies/SequentialStrategy.d.ts.map +1 -0
  80. package/dist/strategies/SimpleStrategy.d.ts +18 -0
  81. package/dist/strategies/SimpleStrategy.d.ts.map +1 -0
  82. package/dist/strategies/agent/AgentStrategy.d.ts +44 -0
  83. package/dist/strategies/agent/AgentStrategy.d.ts.map +1 -0
  84. package/dist/strategies/agent/AgentTools.d.ts +55 -0
  85. package/dist/strategies/agent/AgentTools.d.ts.map +1 -0
  86. package/dist/strategies/agent/ArtifactFilesystem.d.ts +51 -0
  87. package/dist/strategies/agent/ArtifactFilesystem.d.ts.map +1 -0
  88. package/dist/strategies/agent/index.d.ts +4 -0
  89. package/dist/strategies/agent/index.d.ts.map +1 -0
  90. package/dist/strategies/concurrency.d.ts +2 -0
  91. package/dist/strategies/concurrency.d.ts.map +1 -0
  92. package/{src/strategies/index.ts → dist/strategies/index.d.ts} +2 -0
  93. package/dist/strategies/index.d.ts.map +1 -0
  94. package/dist/strategies/utils.d.ts +39 -0
  95. package/dist/strategies/utils.d.ts.map +1 -0
  96. package/dist/strategies.d.ts +1 -0
  97. package/dist/strategies.js +3930 -0
  98. package/dist/strategies.js.map +1 -0
  99. package/dist/tokenization.d.ts +11 -0
  100. package/dist/tokenization.d.ts.map +1 -0
  101. package/dist/types.d.ts +178 -0
  102. package/dist/types.d.ts.map +1 -0
  103. package/dist/validation/validator.d.ts +20 -0
  104. package/dist/validation/validator.d.ts.map +1 -0
  105. package/package.json +30 -14
  106. package/src/agent-cli-integration.test.ts +0 -47
  107. package/src/agent-export.test.ts +0 -17
  108. package/src/agent-tool-labels.test.ts +0 -50
  109. package/src/artifacts/AGENTS.md +0 -16
  110. package/src/artifacts/fileToArtifact.test.ts +0 -37
  111. package/src/artifacts/fileToArtifact.ts +0 -44
  112. package/src/artifacts/input.test.ts +0 -243
  113. package/src/artifacts/input.ts +0 -360
  114. package/src/artifacts/providers.test.ts +0 -19
  115. package/src/artifacts/urlToArtifact.test.ts +0 -23
  116. package/src/artifacts/urlToArtifact.ts +0 -19
  117. package/src/auth/AGENTS.md +0 -11
  118. package/src/auth/config.test.ts +0 -132
  119. package/src/auth/config.ts +0 -186
  120. package/src/auth/tokens.test.ts +0 -58
  121. package/src/auth/tokens.ts +0 -229
  122. package/src/chunking/AGENTS.md +0 -11
  123. package/src/chunking/ArtifactBatcher.test.ts +0 -22
  124. package/src/chunking/ArtifactBatcher.ts +0 -110
  125. package/src/chunking/ArtifactSplitter.test.ts +0 -38
  126. package/src/chunking/ArtifactSplitter.ts +0 -151
  127. package/src/debug/AGENTS.md +0 -79
  128. package/src/debug/logger.test.ts +0 -244
  129. package/src/debug/logger.ts +0 -211
  130. package/src/extract.test.ts +0 -22
  131. package/src/extract.ts +0 -150
  132. package/src/fields.test.ts +0 -681
  133. package/src/fields.ts +0 -246
  134. package/src/index.test.ts +0 -20
  135. package/src/index.ts +0 -110
  136. package/src/llm/AGENTS.md +0 -9
  137. package/src/llm/LLMClient.test.ts +0 -394
  138. package/src/llm/LLMClient.ts +0 -264
  139. package/src/llm/RetryingRunner.test.ts +0 -174
  140. package/src/llm/RetryingRunner.ts +0 -270
  141. package/src/llm/message.test.ts +0 -42
  142. package/src/llm/message.ts +0 -47
  143. package/src/llm/models.test.ts +0 -82
  144. package/src/llm/models.ts +0 -190
  145. package/src/llm/resolveModel.ts +0 -86
  146. package/src/merge/AGENTS.md +0 -6
  147. package/src/merge/Deduplicator.test.ts +0 -108
  148. package/src/merge/Deduplicator.ts +0 -45
  149. package/src/merge/SmartDataMerger.test.ts +0 -177
  150. package/src/merge/SmartDataMerger.ts +0 -56
  151. package/src/parsers/AGENTS.md +0 -58
  152. package/src/parsers/collect.test.ts +0 -56
  153. package/src/parsers/collect.ts +0 -31
  154. package/src/parsers/mime.test.ts +0 -91
  155. package/src/parsers/mime.ts +0 -137
  156. package/src/parsers/npm.ts +0 -26
  157. package/src/parsers/pdf.test.ts +0 -394
  158. package/src/parsers/pdf.ts +0 -194
  159. package/src/parsers/runner.test.ts +0 -95
  160. package/src/parsers/runner.ts +0 -177
  161. package/src/parsers/types.ts +0 -29
  162. package/src/prompts/AGENTS.md +0 -8
  163. package/src/prompts/DeduplicationPrompt.test.ts +0 -41
  164. package/src/prompts/DeduplicationPrompt.ts +0 -37
  165. package/src/prompts/ExtractorPrompt.test.ts +0 -21
  166. package/src/prompts/ExtractorPrompt.ts +0 -72
  167. package/src/prompts/ParallelMergerPrompt.test.ts +0 -8
  168. package/src/prompts/ParallelMergerPrompt.ts +0 -37
  169. package/src/prompts/SequentialExtractorPrompt.test.ts +0 -24
  170. package/src/prompts/SequentialExtractorPrompt.ts +0 -82
  171. package/src/prompts/formatArtifacts.test.ts +0 -39
  172. package/src/prompts/formatArtifacts.ts +0 -46
  173. package/src/strategies/AGENTS.md +0 -6
  174. package/src/strategies/DoublePassAutoMergeStrategy.test.ts +0 -53
  175. package/src/strategies/DoublePassAutoMergeStrategy.ts +0 -410
  176. package/src/strategies/DoublePassStrategy.test.ts +0 -48
  177. package/src/strategies/DoublePassStrategy.ts +0 -266
  178. package/src/strategies/ParallelAutoMergeStrategy.test.ts +0 -152
  179. package/src/strategies/ParallelAutoMergeStrategy.ts +0 -345
  180. package/src/strategies/ParallelStrategy.test.ts +0 -61
  181. package/src/strategies/ParallelStrategy.ts +0 -208
  182. package/src/strategies/SequentialAutoMergeStrategy.test.ts +0 -66
  183. package/src/strategies/SequentialAutoMergeStrategy.ts +0 -325
  184. package/src/strategies/SequentialStrategy.test.ts +0 -53
  185. package/src/strategies/SequentialStrategy.ts +0 -142
  186. package/src/strategies/SimpleStrategy.test.ts +0 -46
  187. package/src/strategies/SimpleStrategy.ts +0 -94
  188. package/src/strategies/concurrency.test.ts +0 -16
  189. package/src/strategies/concurrency.ts +0 -14
  190. package/src/strategies/index.test.ts +0 -20
  191. package/src/strategies/utils.test.ts +0 -76
  192. package/src/strategies/utils.ts +0 -95
  193. package/src/tokenization.test.ts +0 -119
  194. package/src/tokenization.ts +0 -71
  195. package/src/types.test.ts +0 -25
  196. package/src/types.ts +0 -174
  197. package/src/validation/AGENTS.md +0 -7
  198. package/src/validation/validator.test.ts +0 -204
  199. package/src/validation/validator.ts +0 -90
  200. package/tsconfig.json +0 -22
@@ -0,0 +1,11 @@
1
+ import type { Artifact, ArtifactContent, ArtifactImage } from "./types";
2
+ export type TokenCountOptions = {
3
+ textTokenRatio?: number;
4
+ defaultImageTokens?: number;
5
+ };
6
+ export declare const estimateTextTokens: (text: string, options?: TokenCountOptions) => number;
7
+ export declare const estimateImageTokens: (_image: ArtifactImage, options?: TokenCountOptions) => number;
8
+ export declare const countContentTokens: (content: ArtifactContent, options?: TokenCountOptions) => number;
9
+ export declare const countArtifactTokens: (artifact: Artifact, options?: TokenCountOptions) => number;
10
+ export declare const countArtifactImages: (artifact: Artifact) => number;
11
+ //# sourceMappingURL=tokenization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenization.d.ts","sourceRoot":"","sources":["../src/tokenization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAYF,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,UAAU,iBAAiB,WAG3E,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,aAAa,EACrB,UAAU,iBAAiB,WAI5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,SAAS,eAAe,EACxB,UAAU,iBAAiB,WAkB5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,QAAQ,EAClB,UAAU,iBAAiB,WAU5B,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,UAAU,QAAQ,WAIrD,CAAC"}
@@ -0,0 +1,178 @@
1
+ import type { JSONSchemaType } from "ajv";
2
+ import type { DebugLogger } from "./debug/logger";
3
+ export type ArtifactType = "text" | "image" | "pdf" | "file";
4
+ export type ImageType = "embedded" | "screenshot";
5
+ export type ArtifactImage = {
6
+ type: "image";
7
+ url?: string;
8
+ base64?: string;
9
+ contents?: Buffer;
10
+ text?: string;
11
+ x?: number;
12
+ y?: number;
13
+ width?: number;
14
+ height?: number;
15
+ imageType?: ImageType;
16
+ };
17
+ export type ArtifactContent = {
18
+ page?: number;
19
+ text?: string;
20
+ media?: ArtifactImage[];
21
+ };
22
+ export interface Artifact {
23
+ id: string;
24
+ type: ArtifactType;
25
+ raw: () => Promise<Buffer>;
26
+ contents: ArtifactContent[];
27
+ metadata?: Record<string, unknown>;
28
+ tokens?: number;
29
+ }
30
+ export type Usage = {
31
+ inputTokens: number;
32
+ outputTokens: number;
33
+ totalTokens: number;
34
+ };
35
+ export type ExtractionResult<T> = {
36
+ data: T;
37
+ usage: Usage;
38
+ error?: Error;
39
+ };
40
+ /**
41
+ * Telemetry adapter interface for tracing extraction operations.
42
+ * This is a minimal interface that matches the full TelemetryAdapter from @struktur/telemetry.
43
+ * SDK users should import adapters from @struktur/telemetry package.
44
+ */
45
+ export interface TelemetryAdapter {
46
+ readonly name: string;
47
+ readonly version: string;
48
+ initialize(): Promise<void>;
49
+ shutdown(): Promise<void>;
50
+ startSpan(context: {
51
+ name: string;
52
+ kind: "CHAIN" | "LLM" | "TOOL" | "AGENT" | "RETRIEVER" | "EMBEDDING" | "RERANKER";
53
+ parentSpan?: {
54
+ id: string;
55
+ traceId: string;
56
+ };
57
+ attributes?: Record<string, unknown>;
58
+ startTime?: number;
59
+ }): {
60
+ id: string;
61
+ traceId: string;
62
+ name: string;
63
+ kind: string;
64
+ startTime: number;
65
+ parentId?: string;
66
+ };
67
+ endSpan(span: {
68
+ id: string;
69
+ }, result?: {
70
+ status: "ok" | "error";
71
+ error?: Error;
72
+ output?: unknown;
73
+ latencyMs?: number;
74
+ }): void;
75
+ recordEvent(span: {
76
+ id: string;
77
+ }, event: unknown): void;
78
+ setAttributes(span: {
79
+ id: string;
80
+ }, attributes: Record<string, unknown>): void;
81
+ setContext(context: {
82
+ sessionId?: string;
83
+ userId?: string;
84
+ metadata?: Record<string, unknown>;
85
+ tags?: string[];
86
+ }): void;
87
+ }
88
+ export type StepInfo = {
89
+ step: number;
90
+ total?: number;
91
+ label?: string;
92
+ detail?: string;
93
+ };
94
+ export type ProgressInfo = {
95
+ current: number;
96
+ total: number;
97
+ percent?: number;
98
+ };
99
+ export type MessageInfo = {
100
+ role: "system" | "user" | "assistant" | "tool";
101
+ content: unknown;
102
+ };
103
+ export type TokenUsageInfo = Usage & {
104
+ model?: string;
105
+ };
106
+ export type RetryInfo = {
107
+ attempt: number;
108
+ maxAttempts: number;
109
+ reason?: string;
110
+ };
111
+ export type AgentToolStartInfo = {
112
+ toolName: string;
113
+ toolCallId: string;
114
+ args: Record<string, unknown>;
115
+ };
116
+ export type AgentToolEndInfo = {
117
+ toolCallId: string;
118
+ result?: Record<string, unknown>;
119
+ error?: string;
120
+ };
121
+ export type AgentMessageInfo = {
122
+ content: string;
123
+ role?: "assistant" | "user";
124
+ };
125
+ export type AgentReasoningInfo = {
126
+ thought: string;
127
+ };
128
+ export type AgentEvents = {
129
+ onAgentToolStart?: (info: AgentToolStartInfo) => void | Promise<void>;
130
+ onAgentToolEnd?: (info: AgentToolEndInfo) => void | Promise<void>;
131
+ onAgentMessage?: (info: AgentMessageInfo) => void | Promise<void>;
132
+ onAgentReasoning?: (info: AgentReasoningInfo) => void | Promise<void>;
133
+ };
134
+ export type ExtractionEvents = {
135
+ onStep?: (info: StepInfo) => void | Promise<void>;
136
+ onMessage?: (info: MessageInfo) => void | Promise<void>;
137
+ onProgress?: (info: ProgressInfo) => void | Promise<void>;
138
+ onTokenUsage?: (info: TokenUsageInfo) => void | Promise<void>;
139
+ onRetry?: (info: RetryInfo) => void | Promise<void>;
140
+ } & AgentEvents;
141
+ export type AnyJSONSchema = Record<string, unknown>;
142
+ export type TypedJSONSchema<T> = JSONSchemaType<T>;
143
+ export type ProviderModelsResult = {
144
+ provider: string;
145
+ ok: boolean;
146
+ models?: string[];
147
+ error?: string;
148
+ };
149
+ export type ExtractionOptions<T> = {
150
+ artifacts: Artifact[];
151
+ /**
152
+ * JSON Schema for the extracted output.
153
+ * Exactly one of `schema`, `fields`, or an inline schema via the CLI must be provided.
154
+ */
155
+ schema?: TypedJSONSchema<T> | AnyJSONSchema;
156
+ /**
157
+ * Shorthand schema definition as a comma-separated string of `name` or `name:type` tokens.
158
+ * E.g. `"title, price:number"`. Defaults to `string` when no type is specified.
159
+ * Mutually exclusive with `schema`.
160
+ */
161
+ fields?: string;
162
+ strategy: ExtractionStrategy<T>;
163
+ events?: ExtractionEvents;
164
+ debug?: DebugLogger;
165
+ strict?: boolean;
166
+ /**
167
+ * Telemetry adapter for tracing extraction operations.
168
+ * Supports Phoenix (Arize), Langfuse, and other OpenTelemetry-compatible providers.
169
+ * Import from `@struktur/telemetry` package and pass the adapter here.
170
+ */
171
+ telemetry?: TelemetryAdapter | null;
172
+ };
173
+ export interface ExtractionStrategy<T> {
174
+ name: string;
175
+ run(options: ExtractionOptions<T>): Promise<ExtractionResult<T>>;
176
+ getEstimatedSteps?: (artifacts: Artifact[]) => number;
177
+ }
178
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d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AE,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,MAAM,CAAC;CACvD"}
@@ -0,0 +1,20 @@
1
+ import Ajv, { type AnySchema, type ErrorObject, type JSONSchemaType } from "ajv";
2
+ export type ValidationErrors = ErrorObject[];
3
+ export type ValidationMode = 'strict' | 'lenient';
4
+ export type ValidationResult<T> = {
5
+ valid: true;
6
+ data: T;
7
+ } | {
8
+ valid: false;
9
+ errors: ErrorObject[];
10
+ };
11
+ export declare class SchemaValidationError extends Error {
12
+ readonly errors: ValidationErrors;
13
+ constructor(message: string, errors: ValidationErrors);
14
+ }
15
+ export declare const createAjv: () => Ajv;
16
+ export type SchemaInput<T> = JSONSchemaType<T> | AnySchema;
17
+ export declare const validateOrThrow: <T>(ajv: Ajv, schema: SchemaInput<T>, data: unknown) => T;
18
+ export declare const isRequiredError: (error: ErrorObject) => boolean;
19
+ export declare const validateAllowingMissingRequired: <T>(ajv: Ajv, schema: SchemaInput<T>, data: unknown, isFinalAttempt?: boolean) => ValidationResult<T>;
20
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validation/validator.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAGjF,MAAM,MAAM,gBAAgB,GAAG,WAAW,EAAE,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,SAAS,CAAC;AAElD,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACxB;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC;AAE5C,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,SAAgB,MAAM,EAAE,gBAAgB,CAAC;gBAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB;CAKtD;AAID,eAAO,MAAM,SAAS,WAcrB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAE3D,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,KAAK,GAAG,EACR,QAAQ,WAAW,CAAC,CAAC,CAAC,EACtB,MAAM,OAAO,KACZ,CAWF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,WAAW,KAAG,OAEpD,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAAI,CAAC,EAC/C,KAAK,GAAG,EACR,QAAQ,WAAW,CAAC,CAAC,CAAC,EACtB,MAAM,OAAO,EACb,iBAAgB,OAAc,KAC7B,gBAAgB,CAAC,CAAC,CAsBpB,CAAC"}
package/package.json CHANGED
@@ -1,35 +1,51 @@
1
1
  {
2
2
  "name": "@struktur/sdk",
3
- "version": "2.1.2",
3
+ "version": "2.3.0",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "type": "module",
6
- "main": "src/index.ts",
7
- "types": "src/index.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "exports": {
9
- ".": "./src/index.ts",
10
- "./strategies": "./src/strategies/index.ts",
11
- "./artifacts": "./src/artifacts/index.ts",
12
- "./parsers": "./src/parsers/index.ts",
13
- "./auth": "./src/auth/index.ts",
14
- "./llm": "./src/llm/index.ts",
15
- "./validation": "./src/validation/index.ts",
16
- "./debug": "./src/debug/index.ts"
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./strategies": {
14
+ "types": "./dist/strategies.d.ts",
15
+ "import": "./dist/strategies.js"
16
+ },
17
+ "./parsers": {
18
+ "types": "./dist/parsers.d.ts",
19
+ "import": "./dist/parsers.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup && tsc --project tsconfig.build.json && node scripts/postbuild.mjs",
27
+ "prepublishOnly": "bun run build"
17
28
  },
18
29
  "dependencies": {
19
30
  "@ai-sdk/anthropic": "^3.0.0",
20
31
  "@ai-sdk/google": "^3.0.0",
21
32
  "@ai-sdk/openai": "^3.0.0",
33
+ "@ai-sdk/provider": "^3.0.8",
34
+ "@mariozechner/pi-coding-agent": "^0.57.1",
22
35
  "@openrouter/ai-sdk-provider": "^2.0.0",
23
- "@struktur/agent-strategy": "2.1.2",
36
+ "@sinclair/typebox": "^0.34.48",
24
37
  "ai": "^6.0.97",
25
38
  "ajv": "^8.17.1",
26
39
  "ajv-formats": "^3.0.1",
27
- "pdf-parse": "^2.4.5"
40
+ "just-bash": "^2.11.15",
41
+ "pdf-parse": "^2.4.5",
42
+ "zod": "^3.25.76"
28
43
  },
29
44
  "peerDependencies": {
30
45
  "typescript": "^5"
31
46
  },
32
47
  "devDependencies": {
33
- "@types/bun": "latest"
48
+ "@types/bun": "latest",
49
+ "tsup": "^8.0.0"
34
50
  }
35
51
  }
@@ -1,47 +0,0 @@
1
- import { test, expect, describe } from "bun:test";
2
- import { agent, AgentStrategy } from "@struktur/sdk";
3
-
4
- describe("Agent Strategy CLI Integration", () => {
5
- test("agent strategy accepts provider and modelId", () => {
6
- const strategy = agent<{ name: string }>({
7
- provider: "anthropic",
8
- modelId: "claude-sonnet-4",
9
- maxSteps: 30,
10
- });
11
-
12
- expect(strategy).toBeInstanceOf(AgentStrategy);
13
- expect(strategy.name).toBe("agent");
14
- expect(strategy.getEstimatedSteps()).toBe(30);
15
- });
16
-
17
- test("agent strategy works with openai", () => {
18
- const strategy = agent<{ name: string }>({
19
- provider: "openai",
20
- modelId: "gpt-4o",
21
- maxSteps: 50,
22
- });
23
-
24
- expect(strategy).toBeInstanceOf(AgentStrategy);
25
- expect(strategy.name).toBe("agent");
26
- });
27
-
28
- test("agent strategy works with openrouter nested paths", () => {
29
- const strategy = agent<{ name: string }>({
30
- provider: "openrouter",
31
- modelId: "anthropic/claude-sonnet-4",
32
- maxSteps: 50,
33
- });
34
-
35
- expect(strategy).toBeInstanceOf(AgentStrategy);
36
- expect(strategy.name).toBe("agent");
37
- });
38
-
39
- test("agent strategy uses default maxSteps", () => {
40
- const strategy = agent<{ name: string }>({
41
- provider: "anthropic",
42
- modelId: "claude-sonnet-4",
43
- });
44
-
45
- expect(strategy.getEstimatedSteps()).toBe(50);
46
- });
47
- });
@@ -1,17 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import { agent, AgentStrategy } from "@struktur/sdk";
3
-
4
- test("agent strategy is exported from @struktur/sdk", () => {
5
- expect(agent).toBeDefined();
6
- expect(typeof agent).toBe("function");
7
- });
8
-
9
- test("AgentStrategy class is exported from @struktur/sdk", () => {
10
- const strategy = agent({
11
- provider: "anthropic",
12
- modelId: "claude-sonnet-4",
13
- maxSteps: 10,
14
- });
15
- expect(strategy).toBeInstanceOf(AgentStrategy);
16
- expect(strategy.name).toBe("agent");
17
- });
@@ -1,50 +0,0 @@
1
- import { test, expect, describe } from "bun:test";
2
- import { agent, AgentStrategy } from "@struktur/sdk";
3
-
4
- describe("Agent Strategy Tool Labels", () => {
5
- test("strategy creates properly configured agent", () => {
6
- const strategy = agent<{ title: string }>({
7
- provider: "anthropic",
8
- modelId: "claude-sonnet-4",
9
- maxSteps: 25,
10
- });
11
-
12
- expect(strategy).toBeDefined();
13
- expect(strategy.name).toBe("agent");
14
- });
15
-
16
- test("label format for read tool with file path only", () => {
17
- const label = "Read artifact.json";
18
- expect(label).toBe("Read artifact.json");
19
- });
20
-
21
- test("label format for read tool with limit", () => {
22
- const label = "Read artifact.json (limit 100)";
23
- expect(label).toBe("Read artifact.json (limit 100)");
24
- });
25
-
26
- test("label format for read tool with offset and limit", () => {
27
- const label = "Read artifact.json (offset 101, limit 100)";
28
- expect(label).toBe("Read artifact.json (offset 101, limit 100)");
29
- });
30
-
31
- test("label format for bash command", () => {
32
- const label = "Bash: cat /artifacts/artifact.json";
33
- expect(label).toBe("Bash: cat /artifacts/artifact.json");
34
- });
35
-
36
- test("label format for grep", () => {
37
- const label = 'Grep "pattern" in artifact.json';
38
- expect(label).toBe('Grep "pattern" in artifact.json');
39
- });
40
-
41
- test("label format for find", () => {
42
- const label = 'Find "*.json" in /artifacts';
43
- expect(label).toBe('Find "*.json" in /artifacts');
44
- });
45
-
46
- test("label format for ls", () => {
47
- const label = "List /artifacts (recursive)";
48
- expect(label).toBe("List /artifacts (recursive)");
49
- });
50
- });
@@ -1,16 +0,0 @@
1
- Artifacts module
2
-
3
- - Purpose: convert external inputs into Artifacts and manage parser configuration.
4
- - Key files: `fileToArtifact.ts`, `urlToArtifact.ts`, `providers.ts`, `input.ts`.
5
- - Design: `ParsersConfig` is the unified configuration system for all parsers (npm packages, CLI commands, and inline handlers). The `providers` registry is deprecated — use inline parsers in `ParsersConfig` instead.
6
- - `parse` accepts an optional `parserConfig: ParsersConfig` (from `src/parsers/types`) that takes priority over the deprecated providers registry. Custom parsers are resolved by MIME type.
7
- - `ParsersConfig` supports four parser types:
8
- - `NpmParserDef` — npm package with `parseFile` or `parseStream` exports
9
- - `CommandFileDef` — CLI command with `FILE_PATH` placeholder
10
- - `CommandStdinDef` — CLI command that reads from stdin
11
- - `InlineParserDef` — inline `(buffer: Buffer) => Promise<Artifact>` function (replaces the old providers registry)
12
- - JSON auto-detection: when MIME type is `application/json`, `fileParser` first attempts to validate the file as `SerializedArtifact[]`. If valid, it hydrates and returns them directly. If not valid, it checks `parsers` config for a custom parser; if none, throws a clear error.
13
- - `parseBufferInput` resolution order: (1) parsers config, (2) providers registry (deprecated), (3) JSON auto-detection, (4) built-in `application/pdf` (via `parsePdf`), (5) built-in text/*, (6) built-in image/*, (7) error.
14
- - `parse` accepts `includeImages?: boolean` which is forwarded to `parsePdf` for PDF inputs. Set to `false` to suppress image extraction (used by `--no-images` CLI flag).
15
- - `SerializedArtifactImage` schema validation accepts an optional `imageType` field with values `"embedded"` or `"screenshot"` to differentiate between embedded images extracted from PDFs and page screenshots.
16
- - Tests: `fileToArtifact.test.ts`, `urlToArtifact.test.ts`, `input.test.ts`, `providers.test.ts`.
@@ -1,37 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import { fileToArtifact } from "./fileToArtifact";
3
- import type { ArtifactType } from "../types";
4
-
5
- test("fileToArtifact uses custom providers", async () => {
6
- const providers = {
7
- "text/plain": async (buffer: Buffer): Promise<{ id: string; type: ArtifactType; raw: () => Promise<Buffer>; contents: { text: string }[] }> => ({
8
- id: "a1",
9
- type: "text",
10
- raw: async () => buffer,
11
- contents: [{ text: buffer.toString() }],
12
- }),
13
- };
14
-
15
- const artifact = await fileToArtifact(Buffer.from("hello"), {
16
- mimeType: "text/plain",
17
- providers,
18
- });
19
-
20
- expect(artifact.id).toBe("a1");
21
- expect(artifact.contents[0]?.text).toBe("hello");
22
- });
23
-
24
- test("fileToArtifact falls back to text for text/* mime types", async () => {
25
- const artifact = await fileToArtifact(Buffer.from("hello world"), {
26
- mimeType: "text/plain",
27
- });
28
-
29
- expect(artifact.type).toBe("text");
30
- expect(artifact.contents[0]?.text).toBe("hello world");
31
- });
32
-
33
- test("fileToArtifact throws for unknown mime types", async () => {
34
- await expect(
35
- fileToArtifact(Buffer.from("test"), { mimeType: "application/unknown" })
36
- ).rejects.toThrow("No artifact provider registered");
37
- });
@@ -1,44 +0,0 @@
1
- import type { Artifact } from "../types";
2
- import { defaultArtifactProviders, type ArtifactProviders } from "./providers";
3
-
4
- export type FileToArtifactOptions = {
5
- mimeType: string;
6
- providers?: ArtifactProviders;
7
- };
8
-
9
- const bufferToTextArtifact = (buffer: Buffer): Artifact => ({
10
- id: `artifact-${crypto.randomUUID()}`,
11
- type: "text",
12
- raw: async () => buffer,
13
- contents: [{ text: buffer.toString() }],
14
- });
15
-
16
- const bufferToImageArtifact = (buffer: Buffer): Artifact => ({
17
- id: `artifact-${crypto.randomUUID()}`,
18
- type: "image",
19
- raw: async () => buffer,
20
- contents: [{ media: [{ type: "image", contents: buffer }] }],
21
- });
22
-
23
- export const fileToArtifact = async (
24
- buffer: Buffer,
25
- options: FileToArtifactOptions
26
- ): Promise<Artifact> => {
27
- const providers = options.providers ?? defaultArtifactProviders;
28
- const provider = providers[options.mimeType];
29
- if (provider) {
30
- return provider(buffer);
31
- }
32
-
33
- if (options.mimeType.startsWith("text/")) {
34
- return bufferToTextArtifact(buffer);
35
- }
36
-
37
- if (options.mimeType.startsWith("image/")) {
38
- return bufferToImageArtifact(buffer);
39
- }
40
-
41
- throw new Error(
42
- `No artifact provider registered for ${options.mimeType}`
43
- );
44
- };