@axintai/compiler 0.2.1 → 0.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.
@@ -1,3 +1,5 @@
1
+ export { EntityDefinition, EntityDisplay, IntentDefinition, ParamConfig, defineEntity, defineIntent, param } from '../sdk/index.js';
2
+
1
3
  /**
2
4
  * Axint Core Types
3
5
  *
@@ -20,6 +22,14 @@ type IRType = {
20
22
  kind: "entity";
21
23
  entityName: string;
22
24
  properties: IRParameter[];
25
+ } | {
26
+ kind: "entityQuery";
27
+ entityName: string;
28
+ queryType: "all" | "id" | "string" | "property";
29
+ } | {
30
+ kind: "dynamicOptions";
31
+ valueType: IRType;
32
+ providerName: string;
23
33
  } | {
24
34
  kind: "enum";
25
35
  name: string;
@@ -34,6 +44,25 @@ interface IRParameter {
34
44
  isOptional: boolean;
35
45
  defaultValue?: unknown;
36
46
  }
47
+ /**
48
+ * Display representation configuration for an entity.
49
+ * Maps which properties to show in Siri and Shortcuts UI.
50
+ */
51
+ interface DisplayRepresentation {
52
+ title: string;
53
+ subtitle?: string;
54
+ image?: string;
55
+ }
56
+ /**
57
+ * An App Entity definition for complex, domain-specific data types.
58
+ * Entities can be queried and used as parameter types in intents.
59
+ */
60
+ interface IREntity {
61
+ name: string;
62
+ displayRepresentation: DisplayRepresentation;
63
+ properties: IRParameter[];
64
+ queryType: "all" | "id" | "string" | "property";
65
+ }
37
66
  /** The main IR node representing a compiled intent */
38
67
  interface IRIntent {
39
68
  name: string;
@@ -50,6 +79,12 @@ interface IRIntent {
50
79
  infoPlistKeys?: Record<string, string>;
51
80
  /** Whether the intent should be exposed to Spotlight indexing */
52
81
  isDiscoverable?: boolean;
82
+ /** App Entities used by this intent */
83
+ entities?: IREntity[];
84
+ /** Whether to donate this intent to Spotlight/Siri when performed */
85
+ donateOnPerform?: boolean;
86
+ /** Custom result type (SwiftUI view or custom struct) to return */
87
+ customResultType?: string;
53
88
  }
54
89
  interface CompilerOptions {
55
90
  /** Output directory for generated Swift files */
@@ -133,6 +168,25 @@ declare function compileFile(filePath: string, options?: Partial<CompilerOptions
133
168
  * Useful for MCP server and testing.
134
169
  */
135
170
  declare function compileSource(source: string, fileName?: string, options?: Partial<CompilerOptions>): CompileResult;
171
+ /**
172
+ * Compile from a pre-built IR (skips parsing). This is the bridge
173
+ * that allows any frontend language (Python, Rust, Go) to emit an
174
+ * IRIntent JSON and feed it directly into the Swift generator.
175
+ *
176
+ * Used by:
177
+ * - `compileSource()` after its own parse step
178
+ * - `axint compile --from-ir <file.json>` for cross-language pipelines
179
+ * - The Python SDK's `axintai compile` command
180
+ */
181
+ declare function compileFromIR(ir: IRIntent, options?: Partial<CompilerOptions>): CompileResult;
182
+ /**
183
+ * Parse a raw JSON object into a typed IRIntent. Accepts the flat
184
+ * format that the Python SDK's `IntentIR.to_dict()` produces, where
185
+ * parameter types are plain strings rather than `{ kind, value }` objects.
186
+ *
187
+ * This is the key function that bridges the Python → TypeScript gap.
188
+ */
189
+ declare function irFromJSON(data: Record<string, unknown>): IRIntent;
136
190
 
137
191
  /**
138
192
  * Axint Parser
@@ -150,8 +204,8 @@ declare function compileSource(source: string, fileName?: string, options?: Part
150
204
  */
151
205
 
152
206
  /**
153
- * Parse a TypeScript source file containing a defineIntent() call
154
- * and return the IR representation.
207
+ * Parse a TypeScript source file containing defineIntent() and/or
208
+ * defineEntity() calls and return the IR representation.
155
209
  */
156
210
  declare function parseIntentSource(source: string, filePath?: string): IRIntent;
157
211
  declare class ParserError extends Error {
@@ -191,8 +245,17 @@ declare function escapeSwiftString(s: string): string;
191
245
  declare function escapeXml(s: string): string;
192
246
  /**
193
247
  * Generate a Swift App Intent source file from an IR intent.
248
+ * If entities are present, they are generated first, followed by the intent.
194
249
  */
195
250
  declare function generateSwift(intent: IRIntent): string;
251
+ /**
252
+ * Generate an AppEntity struct from an IREntity definition.
253
+ */
254
+ declare function generateEntity(entity: IREntity): string;
255
+ /**
256
+ * Generate an EntityQuery conformance struct based on the entity's query type.
257
+ */
258
+ declare function generateEntityQuery(entity: IREntity): string;
196
259
  /**
197
260
  * Generate an Info.plist XML fragment from the intent's declared keys.
198
261
  * Returns `undefined` if the intent declares no Info.plist keys.
@@ -225,9 +288,68 @@ declare function generateEntitlementsFragment(intent: IRIntent): string | undefi
225
288
  * Validate an IR intent for App Intents framework compliance.
226
289
  */
227
290
  declare function validateIntent(intent: IRIntent): Diagnostic[];
291
+ /**
292
+ * Validate an IREntity for App Intents framework compliance.
293
+ */
294
+ declare function validateEntity(entity: IREntity, sourceFile: string): Diagnostic[];
228
295
  /**
229
296
  * Validate generated Swift source code for basic correctness.
230
297
  */
231
298
  declare function validateSwiftSource(swift: string): Diagnostic[];
232
299
 
233
- export { type CompilerOptions, type CompilerOutput, type Diagnostic, type DiagnosticSeverity, type IRIntent, type IRParameter, type IRPrimitiveType, type IRType, LEGACY_PARAM_ALIASES, PARAM_TYPES, ParserError, SWIFT_TYPE_MAP, compileFile, compileSource, escapeSwiftString, escapeXml, generateEntitlementsFragment, generateInfoPlistFragment, generateSwift, irTypeToSwift, parseIntentSource, validateIntent, validateSwiftSource };
300
+ /**
301
+ * Axint Eject Module
302
+ *
303
+ * Generates standalone Swift code that has no dependency on Axint.
304
+ * This is useful for teams that want to verify there's no vendor lock-in
305
+ * or for distributing intents without the compilation layer.
306
+ *
307
+ * The eject process:
308
+ * 1. Compiles the TypeScript intent using the standard pipeline
309
+ * 2. Transforms the output to remove Axint markers
310
+ * 3. Optionally generates XCTest stubs
311
+ * 4. Emits all files (Swift, plist, entitlements, test)
312
+ */
313
+ interface EjectOptions {
314
+ /** Output directory for ejected files (defaults to ".") */
315
+ outDir?: string;
316
+ /** Generate a basic XCTest file for the intent */
317
+ includeTests?: boolean;
318
+ /** Format output with swift-format (requires swift-format on PATH) */
319
+ format?: boolean;
320
+ }
321
+ interface EjectResult {
322
+ /** The primary Swift file */
323
+ swiftFile: {
324
+ path: string;
325
+ content: string;
326
+ };
327
+ /** Optional Info.plist fragment */
328
+ infoPlist?: {
329
+ path: string;
330
+ content: string;
331
+ };
332
+ /** Optional entitlements fragment */
333
+ entitlements?: {
334
+ path: string;
335
+ content: string;
336
+ };
337
+ /** Optional XCTest file */
338
+ testFile?: {
339
+ path: string;
340
+ content: string;
341
+ };
342
+ }
343
+ /**
344
+ * Eject an intent from Axint, producing standalone Swift code with no
345
+ * vendor lock-in. The resulting Swift code is production-ready and can
346
+ * be committed directly to version control.
347
+ *
348
+ * @param source The TypeScript intent source
349
+ * @param fileName Display name for diagnostics (e.g., "intent.ts")
350
+ * @param options Eject options (outDir, includeTests, format)
351
+ * @returns Ejected files
352
+ */
353
+ declare function ejectIntent(source: string, fileName: string, options?: EjectOptions): EjectResult;
354
+
355
+ export { type CompilerOptions, type CompilerOutput, type Diagnostic, type DiagnosticSeverity, type DisplayRepresentation, type EjectOptions, type EjectResult, type IREntity, type IRIntent, type IRParameter, type IRPrimitiveType, type IRType, LEGACY_PARAM_ALIASES, PARAM_TYPES, ParserError, SWIFT_TYPE_MAP, compileFile, compileFromIR, compileSource, ejectIntent, escapeSwiftString, escapeXml, generateEntitlementsFragment, generateEntity, generateEntityQuery, generateInfoPlistFragment, generateSwift, irFromJSON, irTypeToSwift, parseIntentSource, validateEntity, validateIntent, validateSwiftSource };