taias 0.9.2 → 0.9.3

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/dist/index.d.cts DELETED
@@ -1,399 +0,0 @@
1
- /**
2
- * Default slots for backwards compatibility.
3
- * Users can define custom slots by passing a type parameter.
4
- */
5
- type DefaultSlots = "primaryCta" | "secondaryCta" | "widgetVariant";
6
- /**
7
- * Alias for backwards compatibility in exports.
8
- * @deprecated Use DefaultSlots or define your own slot type
9
- */
10
- type CanonicalSlot = DefaultSlots;
11
- type Binding = {
12
- key: string;
13
- value: string;
14
- };
15
- /**
16
- * Input format for registering affordance bindings.
17
- * - { toolName } is shorthand for { key: "nextTool", value: toolName }
18
- * - { key, value } is the generalized form for custom bindings
19
- */
20
- type BindingInput = {
21
- toolName: string;
22
- } | {
23
- key: string;
24
- value: string;
25
- };
26
- /**
27
- * A registered UI affordance handle.
28
- * Generic over slot type S for custom slot support.
29
- */
30
- type HandleRegistration<S extends string = DefaultSlots> = {
31
- slot: S;
32
- handleId: string;
33
- bindsTo: Binding;
34
- };
35
- type Selection = {
36
- handleId: string;
37
- bindsTo: Binding;
38
- };
39
- /**
40
- * UI selections keyed by slot name.
41
- * Generic over slot type S for custom slot support.
42
- */
43
- type UiSelections<S extends string = DefaultSlots> = Partial<Record<S, Selection>>;
44
- /**
45
- * Collection of registered handles.
46
- * Generic over slot type S for custom slot support.
47
- */
48
- type AffordanceRegistry<S extends string = DefaultSlots> = {
49
- handles: HandleRegistration<S>[];
50
- };
51
-
52
- /**
53
- * Generalized decision object.
54
- * Contains nextTool plus any custom fields returned by step handlers.
55
- */
56
- type Decision = Record<string, string | undefined>;
57
- /**
58
- * Context passed to a step handler.
59
- *
60
- * - toolName: the name of the tool being executed
61
- * - params: the input parameters of the tool call (optional)
62
- * - result: the output of the tool's execution (optional)
63
- */
64
- type TaiasContext = {
65
- toolName: string;
66
- params?: Record<string, unknown>;
67
- result?: Record<string, unknown>;
68
- };
69
- /**
70
- * Decision returned by a step handler specifying the next tool.
71
- * Additional custom fields can be included for multi-dimensional UI control.
72
- */
73
- type StepDecision = {
74
- nextTool: string;
75
- [key: string]: string;
76
- };
77
- /**
78
- * Affordances returned by resolve():
79
- * - advice: LLM guidance text
80
- * - decision: generalized decision object (contains nextTool + custom fields)
81
- * - selections: UI affordance selections (may be empty)
82
- *
83
- * Generic over slot type S for custom slot support.
84
- */
85
- type Affordances<S extends string = DefaultSlots> = {
86
- advice: string;
87
- decision: Decision;
88
- selections: UiSelections<S>;
89
- };
90
- /**
91
- * Handler function for a flow step.
92
- * Can return synchronously or asynchronously.
93
- */
94
- type StepHandler = (ctx: TaiasContext) => StepDecision | null | Promise<StepDecision | null>;
95
- /**
96
- * A condition operator applied to a single field value.
97
- *
98
- * - { is: value } -- exact equality (field === value)
99
- * - { isNot: value } -- not equal (field !== value)
100
- *
101
- * Condition accepts unknown values, enabling matching on strings, numbers,
102
- * booleans, and any other value type. Comparison uses strict equality (===).
103
- *
104
- * The operator system is pure data (not wrapper functions), aligning with
105
- * the logic-as-data philosophy. New operators (oneOf, contains, etc.) can
106
- * be added as union members without changing the evaluation architecture.
107
- */
108
- type Condition = {
109
- is: unknown;
110
- } | {
111
- isNot: unknown;
112
- };
113
- /**
114
- * Match condition for a logic statement.
115
- *
116
- * All fields are optional -- steps can match on any combination of
117
- * toolName, params, and result. Each field uses explicit Condition
118
- * operators ({ is: ... } or { isNot: ... }).
119
- *
120
- * For params and result, conditions are specified per-key. Only the
121
- * specified keys are checked (subset matching); unspecified keys are
122
- * ignored. If a step specifies a params/result condition but the
123
- * context doesn't include params/result, the step does not match.
124
- */
125
- type MatchCondition = {
126
- toolName?: Condition;
127
- params?: Record<string, Condition>;
128
- result?: Record<string, Condition>;
129
- };
130
- /**
131
- * A declarative logic statement -- the core primitive of the decision engine.
132
- *
133
- * Formalizes the implicit "Given X, then Y" logic into structured data
134
- * that Taias can understand, validate, and optimize.
135
- *
136
- * - match: the conditions under which this statement applies
137
- * - decision: the decision to produce when matched
138
- */
139
- type LogicStatement = {
140
- match: MatchCondition;
141
- decision: StepDecision;
142
- };
143
- /**
144
- * A step within a flow. Discriminated union:
145
- *
146
- * - "logic": A declarative logic statement. The statement is the sole source
147
- * of truth for its match conditions and decision.
148
- * - "handler": A handler function (backwards-compatible escape hatch).
149
- * The match condition is stored alongside the handler since the function
150
- * itself has no formal match conditions.
151
- */
152
- type FlowStep = {
153
- kind: "logic";
154
- statement: LogicStatement;
155
- } | {
156
- kind: "handler";
157
- match: MatchCondition;
158
- handler: StepHandler;
159
- };
160
- /**
161
- * A complete flow definition with an id and its steps.
162
- */
163
- type FlowDefinition = {
164
- id: string;
165
- steps: Array<FlowStep>;
166
- };
167
- /**
168
- * The input accepted by flow.step() -- either a handler function
169
- * or a static StepDecision object.
170
- */
171
- type StepInput = StepHandler | StepDecision;
172
- /**
173
- * Builder interface for defining flow steps.
174
- *
175
- * step() takes two arguments:
176
- * - match: a MatchCondition object describing the conditions under which
177
- * this step applies. All fields use explicit operator objects.
178
- * - input: a StepDecision object (creates a logic statement).
179
- * A StepHandler function is also accepted for backwards compatibility.
180
- */
181
- interface FlowBuilder {
182
- step(match: MatchCondition, input: StepInput): void;
183
- }
184
- /**
185
- * Evaluation record for a single step during resolve().
186
- * Present when tracing: "detailed" is enabled.
187
- */
188
- type StepEvaluation = {
189
- stepIndex: number;
190
- match: MatchCondition;
191
- result: "matched" | "no-match";
192
- fieldResults?: Record<string, {
193
- condition: Condition;
194
- actual: unknown;
195
- passed: boolean;
196
- }>;
197
- };
198
- /**
199
- * Trace of how resolve() reached its decision.
200
- *
201
- * Always includes summary information (which step matched, how it was found).
202
- * When tracing: "detailed", also includes per-step evaluation breakdowns.
203
- */
204
- type ResolveTrace = {
205
- matched: boolean;
206
- matchedStepIndex: number | null;
207
- matchedStepKind: "logic" | "handler" | null;
208
- matchedStepMatch: MatchCondition | null;
209
- phase: "indexed" | "broad" | null;
210
- resolutionPath: string[];
211
- candidatesEvaluated: number;
212
- evaluations?: StepEvaluation[];
213
- };
214
- /**
215
- * Structured event emitted on every resolve() call.
216
- *
217
- * Four-part structure:
218
- * 1. context -- what was passed to resolve()
219
- * 2. trace -- how the decision was reached
220
- * 3. decision -- what was decided
221
- * 4. affordances -- how the decision was manifested (advice + selections)
222
- */
223
- type ResolveEvent<S extends string = DefaultSlots> = {
224
- flowId: string;
225
- timestamp: number;
226
- durationMs: number;
227
- context: TaiasContext;
228
- trace: ResolveTrace;
229
- decision: Decision | null;
230
- affordances: {
231
- advice: string;
232
- selections: UiSelections<S>;
233
- } | null;
234
- };
235
- /**
236
- * Map of event names to their event types.
237
- * Extensible to future event types (e.g., "init", "error").
238
- */
239
- type TaiasEventMap<S extends string = DefaultSlots> = {
240
- resolve: ResolveEvent<S>;
241
- };
242
- /**
243
- * Options for the built-in debug subscriber.
244
- *
245
- * - format: "default" (multi-line breakdown) or "compact" (single line).
246
- * - logger: Custom log function (defaults to console.log).
247
- */
248
- type DebugOptions = {
249
- format?: "default" | "compact";
250
- logger?: (...args: unknown[]) => void;
251
- };
252
- /**
253
- * Options for creating a Taias instance.
254
- * Generic over slot type S for custom slot support.
255
- */
256
- type TaiasOptions<S extends string = DefaultSlots> = {
257
- flow: FlowDefinition;
258
- affordances?: AffordanceRegistry<S>;
259
- devMode?: boolean;
260
- debug?: boolean | DebugOptions;
261
- tracing?: "summary" | "detailed";
262
- onMissingStep?: (ctx: TaiasContext) => void;
263
- onWarn?: (msg: string) => void;
264
- };
265
- /**
266
- * The Taias instance interface.
267
- * Generic over slot type S for custom slot support.
268
- */
269
- interface Taias<S extends string = DefaultSlots> {
270
- resolve(ctx: TaiasContext): Affordances<S> | null | Promise<Affordances<S> | null>;
271
- on<E extends keyof TaiasEventMap<S>>(event: E, handler: (data: TaiasEventMap<S>[E]) => void): void;
272
- off<E extends keyof TaiasEventMap<S>>(event: E, handler: (data: TaiasEventMap<S>[E]) => void): void;
273
- }
274
-
275
- /**
276
- * Define a flow with its steps.
277
- *
278
- * @param flowId - Unique identifier for the flow
279
- * @param builder - Callback that receives a FlowBuilder to define steps
280
- * @returns A FlowDefinition object
281
- *
282
- * @example Logic statement matching on toolName
283
- * ```ts
284
- * const onboardRepoFlow = defineFlow("onboard_repo", (flow) => {
285
- * flow.step({ toolName: { is: "scan_repo" } }, { nextTool: "configure_app" });
286
- * });
287
- * ```
288
- *
289
- * @example Matching on params and result
290
- * ```ts
291
- * flow.step(
292
- * { toolName: { is: "scan_repo" }, params: { language: { is: "python" } } },
293
- * { nextTool: "configure_python" },
294
- * );
295
- * flow.step(
296
- * { result: { hasConfig: { is: true } } },
297
- * { nextTool: "review_config" },
298
- * );
299
- * ```
300
- *
301
- * @example isNot operator
302
- * ```ts
303
- * flow.step({ toolName: { isNot: "abort_session" } }, { nextTool: "continue_flow" });
304
- * ```
305
- */
306
- declare function defineFlow(flowId: string, builder: (flow: FlowBuilder) => void): FlowDefinition;
307
-
308
- /**
309
- * createTaias constructs a decision engine.
310
- *
311
- * Taias resolves context into a generalized Decision object,
312
- * and then manifests that decision into concrete affordances:
313
- *
314
- * - LLM guidance (advice)
315
- * - UI affordance selections
316
- *
317
- * Flow logic is expressed as logic statements -- structured data that
318
- * Taias understands. (Handler functions remain as a backwards-compatible
319
- * escape hatch.)
320
- *
321
- * Flow logic determines *what should happen next*.
322
- * UI affordances determine *how that decision appears in the interface*.
323
- *
324
- * This file is the boundary where:
325
- *
326
- * Inputs -> Decision -> Manifestations
327
- *
328
- * are unified into a single resolve() call.
329
- *
330
- * @example
331
- * ```ts
332
- * const taias = createTaias({ flow, affordances });
333
- * ```
334
- */
335
- declare function createTaias<S extends string = DefaultSlots>(options: TaiasOptions<S>): Taias<S>;
336
-
337
- type DebugSubscriberOptions = DebugOptions;
338
- /**
339
- * Create a debug subscriber for Taias resolve events.
340
- *
341
- * Returns a handler function suitable for `taias.on("resolve", handler)`.
342
- *
343
- * - "default" format: multi-line breakdown of context, trace, decision, and affordances.
344
- * - "compact" format: single line per resolve call.
345
- */
346
- declare function createDebugSubscriber(options?: DebugSubscriberOptions): (event: ResolveEvent) => void;
347
-
348
- /**
349
- * Mapped type that creates a registration method for each slot in S.
350
- * This enables fully typed custom slots via generics.
351
- */
352
- type AffordanceRegistrar<S extends string = DefaultSlots> = {
353
- [K in S]: (handleId: string, bindsTo: BindingInput) => void;
354
- };
355
- /**
356
- * Define UI affordances for a widget using a builder pattern.
357
- *
358
- * @example Default slots (backwards compatible)
359
- * ```ts
360
- * const affordances = defineAffordances((r) => {
361
- * r.primaryCta("cta.recommend", { toolName: "get_recommendations" });
362
- * r.widgetVariant("variant.discovery", { toolName: "get_recommendations" });
363
- * });
364
- * ```
365
- *
366
- * @example Custom slots (fully type-safe)
367
- * ```ts
368
- * type MySlots = "primaryCta" | "contentArea" | "headerStyle";
369
- * const affordances = defineAffordances<MySlots>((r) => {
370
- * r.primaryCta("cta.create", { toolName: "createUser" });
371
- * r.contentArea("content.form", { key: "contentArea", value: "email-form" });
372
- * r.headerStyle("header.progress", { key: "headerStyle", value: "step-1" });
373
- * });
374
- * ```
375
- */
376
- declare function defineAffordances<S extends string = DefaultSlots>(builder: (r: AffordanceRegistrar<S>) => void): AffordanceRegistry<S>;
377
-
378
- type MergeAffordancesOptions = {
379
- devMode?: boolean;
380
- onWarn?: (msg: string) => void;
381
- };
382
- /**
383
- * Merge multiple affordance registries into one.
384
- * Generic over slot type S for custom slot support.
385
- *
386
- * @example Default slots
387
- * ```ts
388
- * const merged = mergeAffordances([widgetA, widgetB]);
389
- * ```
390
- *
391
- * @example Custom slots
392
- * ```ts
393
- * type MySlots = "primaryCta" | "contentArea";
394
- * const merged = mergeAffordances<MySlots>([widgetA, widgetB]);
395
- * ```
396
- */
397
- declare function mergeAffordances<S extends string = DefaultSlots>(registries: AffordanceRegistry<S>[], opts?: MergeAffordancesOptions): AffordanceRegistry<S>;
398
-
399
- export { type AffordanceRegistrar, type AffordanceRegistry, type Affordances, type Binding, type BindingInput, type CanonicalSlot, type Condition, type DebugOptions, type Decision, type DefaultSlots, type FlowBuilder, type FlowDefinition, type FlowStep, type HandleRegistration, type LogicStatement, type MatchCondition, type ResolveEvent, type ResolveTrace, type Selection, type StepDecision, type StepEvaluation, type StepHandler, type StepInput, type Taias, type TaiasContext, type TaiasEventMap, type TaiasOptions, type UiSelections, createDebugSubscriber, createTaias, defineAffordances, defineFlow, mergeAffordances };