@chai-ui/core 0.13.0 → 0.14.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.
- package/README.md +14 -3
- package/dist/analytics-events.d.ts +121 -0
- package/dist/analytics-events.d.ts.map +1 -0
- package/dist/analytics-events.js +55 -0
- package/dist/analytics-events.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/analytics-events.ts +106 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ The headless core behind Chai UI's components: the data types, the
|
|
|
16
16
|
Request → Run → Result model a submitted prompt flows through, and the
|
|
17
17
|
pluggable generation engines that actually call models, and the components'
|
|
18
18
|
behavior as small framework-free stores. No framework, no rendering:
|
|
19
|
-
`@chai-ui/react` wraps the stores in hooks, and
|
|
19
|
+
`@chai-ui/react` wraps the stores in hooks, and `@chai-ui/vue` wraps the
|
|
20
20
|
same stores.
|
|
21
21
|
|
|
22
22
|
## Layout
|
|
@@ -26,14 +26,25 @@ same stores.
|
|
|
26
26
|
- `engine.ts` — the `GenerationEngine` interface every provider implements, `GenerationError`, and `mockEngine`/`createMockEngine` (placeholder output, no network call, no API key).
|
|
27
27
|
- `engines/fal.ts` — `createFalEngine`, media generation through Fal.ai (the default).
|
|
28
28
|
- `engines/openrouter.ts` — `createOpenRouterEngine`, text/reasoning through OpenRouter (prompt enhancement, media analysis).
|
|
29
|
+
- `engines/vercel.ts` — `createVercelEngine`, text and image models through Vercel AI Gateway.
|
|
29
30
|
- `media-analysis-prompts.ts` — the instruction text `MediaAnalyzer` sends, per media kind × prompt length.
|
|
30
31
|
- `suggested-models.ts` — the suggested model lists per use case (Fal for generation, OpenRouter for analysis), each model with its verified aspect ratios and Fal input format; `suggestedModels(useCase)`.
|
|
31
32
|
- `check-suggested-models.ts` — `checkSuggestedModels()`: checks those lists against Fal's and OpenRouter's catalogs as they are today. No key, no model run.
|
|
32
33
|
- `model-routing.ts` — auto-select: `buildModelRoutingPrompt`, `parseModelRoutingReply`, and `routeModel`, which falls back to the first listed model instead of throwing.
|
|
33
34
|
- `reasoning.ts` — the reasoning engine and models a `ChaiProvider` shares: `createReasoning`, `pickReasoning`, `reasoningModelFor` and the suggested defaults.
|
|
34
|
-
- `composer.ts` — `createComposerStore`, what `useComposer` wraps: submit payload → runs, auto-select routing, Enhance, cancel,
|
|
35
|
+
- `composer.ts` — `createComposerStore`, what `useComposer` wraps: submit payload → runs, auto-select routing, Enhance, cancel, image edit versions and the evaluation judge. Plus the Composer's shared types (`ComposerSubmitPayload`, `EditVersion`, …).
|
|
36
|
+
- `composer-view.ts` — what the `Composer` shows and submits, worked out from its props, for every binding: model menus, aspect ratios, use-case rules (`nextUseCases`).
|
|
37
|
+
- `analytics-events.ts` — front-end analytics: the `ChaiEvent` type and the `composerEvents` and `resultCardEvents` the components report through `onEvent`.
|
|
38
|
+
- `evaluation-judge.ts` — the opt-in judge: `EvaluationCheck`, `DEFAULT_EVALUATION_CHECKS`, `buildJudgePrompt`, `parseJudgeReply`.
|
|
39
|
+
- `image-fit.ts` — `fitImageToRatio`: crops or pads a video's start image to the picked ratio (`startImageFit`).
|
|
40
|
+
- `region-edit.ts` — region editing: the region shape, the models that read regions as boxes, and `buildRegionEditPrompt`.
|
|
41
|
+
- `edit-card.ts` — `EditCard`'s geometry: region boxes, zoom and pan, and where the instruction field goes.
|
|
42
|
+
- `voice-input.ts` — the Composer's voice input: record, send to a speech-to-text model, return the transcript.
|
|
43
|
+
- `result-format.ts` — how `ResultCard` shows a result's details.
|
|
44
|
+
- `media-actions.ts` — download and share for generated media.
|
|
45
|
+
- `menu-placement.ts` — which way a component's menus open from their trigger.
|
|
35
46
|
- `media-analyzer.ts` — `createMediaAnalyzerStore`, what `useMediaAnalyzer` wraps.
|
|
36
|
-
- `server/` — `createChaiHandler` and `toNodeHandler
|
|
47
|
+
- `server/` — `createChaiHandler` (`chai-handler.ts`) and `toNodeHandler` (`node.ts`), exported from `@chai-ui/core/server` (server-only).
|
|
37
48
|
|
|
38
49
|
## Suggested models, and checking them
|
|
39
50
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Front-end analytics: what the person did in Chai's components and what
|
|
3
|
+
* the components showed them, reported through each component's `onEvent`.
|
|
4
|
+
* Defined once here so every framework binding sends the same events.
|
|
5
|
+
*
|
|
6
|
+
* Front end only: model calls, latency, cost and storage belong to the
|
|
7
|
+
* builder's back end. No prompt text, file names, URLs or outputs are ever
|
|
8
|
+
* sent: only lengths, counts and Chai's own ids. Properties are flat, so any
|
|
9
|
+
* analytics tool takes them as they are: `onEvent={(e) => posthog.capture(e.name, e.properties)}`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ComposerAttachMenuAction, ComposerPromptField } from "./composer-view.js";
|
|
12
|
+
import type { ComposerSubmitPayload, ComposerUseCase } from "./composer.js";
|
|
13
|
+
import type { MediaKind } from "./types.js";
|
|
14
|
+
export type ChaiEvent = {
|
|
15
|
+
name: "chai_composer_submitted";
|
|
16
|
+
properties: {
|
|
17
|
+
use_cases: string;
|
|
18
|
+
model_count: number;
|
|
19
|
+
auto_select: boolean;
|
|
20
|
+
aspect_ratio?: string;
|
|
21
|
+
attachment_count: number;
|
|
22
|
+
prompt_length: number;
|
|
23
|
+
retry: boolean;
|
|
24
|
+
};
|
|
25
|
+
} | {
|
|
26
|
+
name: "chai_composer_stopped";
|
|
27
|
+
properties: Record<string, never>;
|
|
28
|
+
} | {
|
|
29
|
+
name: "chai_composer_use_case_picked";
|
|
30
|
+
properties: {
|
|
31
|
+
action: ComposerAttachMenuAction;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
name: "chai_composer_use_case_removed";
|
|
35
|
+
properties: {
|
|
36
|
+
use_case: string;
|
|
37
|
+
};
|
|
38
|
+
} | {
|
|
39
|
+
name: "chai_composer_media_attached";
|
|
40
|
+
properties: {
|
|
41
|
+
count: number;
|
|
42
|
+
unsupported_count: number;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
name: "chai_composer_model_picked";
|
|
46
|
+
properties: {
|
|
47
|
+
use_case: string;
|
|
48
|
+
model_id: string;
|
|
49
|
+
};
|
|
50
|
+
} | {
|
|
51
|
+
name: "chai_composer_auto_select_toggled";
|
|
52
|
+
properties: {
|
|
53
|
+
on: boolean;
|
|
54
|
+
};
|
|
55
|
+
} | {
|
|
56
|
+
name: "chai_composer_option_picked";
|
|
57
|
+
properties: {
|
|
58
|
+
option: "aspect_ratio" | "voice" | "genre" | "frame_rate";
|
|
59
|
+
value: string;
|
|
60
|
+
};
|
|
61
|
+
} | {
|
|
62
|
+
name: "chai_composer_enhance_clicked";
|
|
63
|
+
properties: {
|
|
64
|
+
field: ComposerPromptField;
|
|
65
|
+
prompt_length: number;
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
name: "chai_composer_enhance_reverted";
|
|
69
|
+
properties: {
|
|
70
|
+
field: ComposerPromptField;
|
|
71
|
+
};
|
|
72
|
+
} | {
|
|
73
|
+
name: "chai_composer_voice_started";
|
|
74
|
+
properties: Record<string, never>;
|
|
75
|
+
} | {
|
|
76
|
+
name: "chai_result_shown";
|
|
77
|
+
properties: {
|
|
78
|
+
status: "done" | "error";
|
|
79
|
+
output_kind?: MediaKind;
|
|
80
|
+
result_count: number;
|
|
81
|
+
};
|
|
82
|
+
} | {
|
|
83
|
+
name: "chai_result_action";
|
|
84
|
+
properties: {
|
|
85
|
+
action: string;
|
|
86
|
+
};
|
|
87
|
+
} | {
|
|
88
|
+
name: "chai_result_paged";
|
|
89
|
+
properties: {
|
|
90
|
+
index: number;
|
|
91
|
+
count: number;
|
|
92
|
+
};
|
|
93
|
+
} | {
|
|
94
|
+
name: "chai_result_info_opened";
|
|
95
|
+
properties: Record<string, never>;
|
|
96
|
+
};
|
|
97
|
+
export type ChaiEventName = ChaiEvent["name"];
|
|
98
|
+
/** A use case as one short id, e.g. `"image"`, `"image:edit"` or `"audio:music"`. */
|
|
99
|
+
export declare function useCaseId(useCase: ComposerUseCase): string;
|
|
100
|
+
/** The events `Composer` reports. */
|
|
101
|
+
export declare const composerEvents: {
|
|
102
|
+
submitted: (payload: ComposerSubmitPayload, retry: boolean) => ChaiEvent;
|
|
103
|
+
stopped: () => ChaiEvent;
|
|
104
|
+
useCasePicked: (action: ComposerAttachMenuAction) => ChaiEvent;
|
|
105
|
+
useCaseRemoved: (useCase: ComposerUseCase) => ChaiEvent;
|
|
106
|
+
mediaAttached: (count: number, unsupportedCount: number) => ChaiEvent;
|
|
107
|
+
modelPicked: (useCase: string, modelId: string) => ChaiEvent;
|
|
108
|
+
autoSelectToggled: (on: boolean) => ChaiEvent;
|
|
109
|
+
optionPicked: (option: "aspect_ratio" | "voice" | "genre" | "frame_rate", value: string | number) => ChaiEvent;
|
|
110
|
+
enhanceClicked: (field: ComposerPromptField, promptLength: number) => ChaiEvent;
|
|
111
|
+
enhanceReverted: (field: ComposerPromptField) => ChaiEvent;
|
|
112
|
+
voiceStarted: () => ChaiEvent;
|
|
113
|
+
};
|
|
114
|
+
/** The events `ResultCard` reports. */
|
|
115
|
+
export declare const resultCardEvents: {
|
|
116
|
+
shown: (status: "done" | "error", outputKind: MediaKind | undefined, resultCount: number) => ChaiEvent;
|
|
117
|
+
action: (action: string) => ChaiEvent;
|
|
118
|
+
paged: (index: number, count: number) => ChaiEvent;
|
|
119
|
+
infoOpened: () => ChaiEvent;
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=analytics-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-events.d.ts","sourceRoot":"","sources":["../src/analytics-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,q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AM,oBAAoB,MAAM,KAAG,SAAS;2BAI5C,MAAM,WAAW,MAAM,KAAG,SAAS;4BAIlC,OAAO,KAAG,SAAS;2BACpB,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,YAAY,SAAS,MAAM,GAAG,MAAM,KAAG,SAAS;4BAIpF,mBAAmB,gBAAgB,MAAM,KAAG,SAAS;6BAIpD,mBAAmB,KAAG,SAAS;wBACtC,SAAS;CAC5B,CAAC;AAEF,uCAAuC;AACvC,eAAO,MAAM,gBAAgB;oBACX,MAAM,GAAG,OAAO,cAAc,SAAS,GAAG,SAAS,eAAe,MAAM,KAAG,SAAS;qBAInF,MAAM,KAAG,SAAS;mBACpB,MAAM,SAAS,MAAM,KAAG,SAAS;sBAChC,SAAS;CAC1B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** A use case as one short id, e.g. `"image"`, `"image:edit"` or `"audio:music"`. */
|
|
2
|
+
export function useCaseId(useCase) {
|
|
3
|
+
return `${useCase.kind}${useCase.edit ? ":edit" : ""}${useCase.audio ? `:${useCase.audio}` : ""}`;
|
|
4
|
+
}
|
|
5
|
+
/** The events `Composer` reports. */
|
|
6
|
+
export const composerEvents = {
|
|
7
|
+
submitted: (payload, retry) => ({
|
|
8
|
+
name: "chai_composer_submitted",
|
|
9
|
+
properties: {
|
|
10
|
+
use_cases: payload.selections.map((s) => useCaseId(s.useCase)).join(","),
|
|
11
|
+
model_count: payload.selections.reduce((n, s) => n + s.modelIds.length, 0),
|
|
12
|
+
auto_select: payload.autoSelectModel,
|
|
13
|
+
...(payload.aspectRatio && { aspect_ratio: payload.aspectRatio }),
|
|
14
|
+
attachment_count: payload.attachments.length,
|
|
15
|
+
prompt_length: payload.value.length,
|
|
16
|
+
retry,
|
|
17
|
+
},
|
|
18
|
+
}),
|
|
19
|
+
stopped: () => ({ name: "chai_composer_stopped", properties: {} }),
|
|
20
|
+
useCasePicked: (action) => ({ name: "chai_composer_use_case_picked", properties: { action } }),
|
|
21
|
+
useCaseRemoved: (useCase) => ({
|
|
22
|
+
name: "chai_composer_use_case_removed",
|
|
23
|
+
properties: { use_case: useCaseId(useCase) },
|
|
24
|
+
}),
|
|
25
|
+
mediaAttached: (count, unsupportedCount) => ({
|
|
26
|
+
name: "chai_composer_media_attached",
|
|
27
|
+
properties: { count, unsupported_count: unsupportedCount },
|
|
28
|
+
}),
|
|
29
|
+
modelPicked: (useCase, modelId) => ({
|
|
30
|
+
name: "chai_composer_model_picked",
|
|
31
|
+
properties: { use_case: useCase, model_id: modelId },
|
|
32
|
+
}),
|
|
33
|
+
autoSelectToggled: (on) => ({ name: "chai_composer_auto_select_toggled", properties: { on } }),
|
|
34
|
+
optionPicked: (option, value) => ({
|
|
35
|
+
name: "chai_composer_option_picked",
|
|
36
|
+
properties: { option, value: String(value) },
|
|
37
|
+
}),
|
|
38
|
+
enhanceClicked: (field, promptLength) => ({
|
|
39
|
+
name: "chai_composer_enhance_clicked",
|
|
40
|
+
properties: { field, prompt_length: promptLength },
|
|
41
|
+
}),
|
|
42
|
+
enhanceReverted: (field) => ({ name: "chai_composer_enhance_reverted", properties: { field } }),
|
|
43
|
+
voiceStarted: () => ({ name: "chai_composer_voice_started", properties: {} }),
|
|
44
|
+
};
|
|
45
|
+
/** The events `ResultCard` reports. */
|
|
46
|
+
export const resultCardEvents = {
|
|
47
|
+
shown: (status, outputKind, resultCount) => ({
|
|
48
|
+
name: "chai_result_shown",
|
|
49
|
+
properties: { status, ...(outputKind && { output_kind: outputKind }), result_count: resultCount },
|
|
50
|
+
}),
|
|
51
|
+
action: (action) => ({ name: "chai_result_action", properties: { action } }),
|
|
52
|
+
paged: (index, count) => ({ name: "chai_result_paged", properties: { index, count } }),
|
|
53
|
+
infoOpened: () => ({ name: "chai_result_info_opened", properties: {} }),
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=analytics-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-events.js","sourceRoot":"","sources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e,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chai-ui/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Chai UI headless core — the Request/Run/Result data model and pluggable generation engines (Fal.ai, OpenRouter, Vercel AI Gateway, mock). No framework, no rendering.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "kazarazat",
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Front-end analytics: what the person did in Chai's components and what
|
|
3
|
+
* the components showed them, reported through each component's `onEvent`.
|
|
4
|
+
* Defined once here so every framework binding sends the same events.
|
|
5
|
+
*
|
|
6
|
+
* Front end only: model calls, latency, cost and storage belong to the
|
|
7
|
+
* builder's back end. No prompt text, file names, URLs or outputs are ever
|
|
8
|
+
* sent: only lengths, counts and Chai's own ids. Properties are flat, so any
|
|
9
|
+
* analytics tool takes them as they are: `onEvent={(e) => posthog.capture(e.name, e.properties)}`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ComposerAttachMenuAction, ComposerPromptField } from "./composer-view.js";
|
|
12
|
+
import type { ComposerSubmitPayload, ComposerUseCase } from "./composer.js";
|
|
13
|
+
import type { MediaKind } from "./types.js";
|
|
14
|
+
|
|
15
|
+
export type ChaiEvent =
|
|
16
|
+
| {
|
|
17
|
+
name: "chai_composer_submitted";
|
|
18
|
+
properties: {
|
|
19
|
+
use_cases: string;
|
|
20
|
+
model_count: number;
|
|
21
|
+
auto_select: boolean;
|
|
22
|
+
aspect_ratio?: string;
|
|
23
|
+
attachment_count: number;
|
|
24
|
+
prompt_length: number;
|
|
25
|
+
retry: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
| { name: "chai_composer_stopped"; properties: Record<string, never> }
|
|
29
|
+
| { name: "chai_composer_use_case_picked"; properties: { action: ComposerAttachMenuAction } }
|
|
30
|
+
| { name: "chai_composer_use_case_removed"; properties: { use_case: string } }
|
|
31
|
+
| { name: "chai_composer_media_attached"; properties: { count: number; unsupported_count: number } }
|
|
32
|
+
| { name: "chai_composer_model_picked"; properties: { use_case: string; model_id: string } }
|
|
33
|
+
| { name: "chai_composer_auto_select_toggled"; properties: { on: boolean } }
|
|
34
|
+
| {
|
|
35
|
+
name: "chai_composer_option_picked";
|
|
36
|
+
properties: { option: "aspect_ratio" | "voice" | "genre" | "frame_rate"; value: string };
|
|
37
|
+
}
|
|
38
|
+
| { name: "chai_composer_enhance_clicked"; properties: { field: ComposerPromptField; prompt_length: number } }
|
|
39
|
+
| { name: "chai_composer_enhance_reverted"; properties: { field: ComposerPromptField } }
|
|
40
|
+
| { name: "chai_composer_voice_started"; properties: Record<string, never> }
|
|
41
|
+
| {
|
|
42
|
+
name: "chai_result_shown";
|
|
43
|
+
properties: { status: "done" | "error"; output_kind?: MediaKind; result_count: number };
|
|
44
|
+
}
|
|
45
|
+
| { name: "chai_result_action"; properties: { action: string } }
|
|
46
|
+
| { name: "chai_result_paged"; properties: { index: number; count: number } }
|
|
47
|
+
| { name: "chai_result_info_opened"; properties: Record<string, never> };
|
|
48
|
+
|
|
49
|
+
export type ChaiEventName = ChaiEvent["name"];
|
|
50
|
+
|
|
51
|
+
/** A use case as one short id, e.g. `"image"`, `"image:edit"` or `"audio:music"`. */
|
|
52
|
+
export function useCaseId(useCase: ComposerUseCase): string {
|
|
53
|
+
return `${useCase.kind}${useCase.edit ? ":edit" : ""}${useCase.audio ? `:${useCase.audio}` : ""}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The events `Composer` reports. */
|
|
57
|
+
export const composerEvents = {
|
|
58
|
+
submitted: (payload: ComposerSubmitPayload, retry: boolean): ChaiEvent => ({
|
|
59
|
+
name: "chai_composer_submitted",
|
|
60
|
+
properties: {
|
|
61
|
+
use_cases: payload.selections.map((s) => useCaseId(s.useCase)).join(","),
|
|
62
|
+
model_count: payload.selections.reduce((n, s) => n + s.modelIds.length, 0),
|
|
63
|
+
auto_select: payload.autoSelectModel,
|
|
64
|
+
...(payload.aspectRatio && { aspect_ratio: payload.aspectRatio }),
|
|
65
|
+
attachment_count: payload.attachments.length,
|
|
66
|
+
prompt_length: payload.value.length,
|
|
67
|
+
retry,
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
stopped: (): ChaiEvent => ({ name: "chai_composer_stopped", properties: {} }),
|
|
71
|
+
useCasePicked: (action: ComposerAttachMenuAction): ChaiEvent => ({ name: "chai_composer_use_case_picked", properties: { action } }),
|
|
72
|
+
useCaseRemoved: (useCase: ComposerUseCase): ChaiEvent => ({
|
|
73
|
+
name: "chai_composer_use_case_removed",
|
|
74
|
+
properties: { use_case: useCaseId(useCase) },
|
|
75
|
+
}),
|
|
76
|
+
mediaAttached: (count: number, unsupportedCount: number): ChaiEvent => ({
|
|
77
|
+
name: "chai_composer_media_attached",
|
|
78
|
+
properties: { count, unsupported_count: unsupportedCount },
|
|
79
|
+
}),
|
|
80
|
+
modelPicked: (useCase: string, modelId: string): ChaiEvent => ({
|
|
81
|
+
name: "chai_composer_model_picked",
|
|
82
|
+
properties: { use_case: useCase, model_id: modelId },
|
|
83
|
+
}),
|
|
84
|
+
autoSelectToggled: (on: boolean): ChaiEvent => ({ name: "chai_composer_auto_select_toggled", properties: { on } }),
|
|
85
|
+
optionPicked: (option: "aspect_ratio" | "voice" | "genre" | "frame_rate", value: string | number): ChaiEvent => ({
|
|
86
|
+
name: "chai_composer_option_picked",
|
|
87
|
+
properties: { option, value: String(value) },
|
|
88
|
+
}),
|
|
89
|
+
enhanceClicked: (field: ComposerPromptField, promptLength: number): ChaiEvent => ({
|
|
90
|
+
name: "chai_composer_enhance_clicked",
|
|
91
|
+
properties: { field, prompt_length: promptLength },
|
|
92
|
+
}),
|
|
93
|
+
enhanceReverted: (field: ComposerPromptField): ChaiEvent => ({ name: "chai_composer_enhance_reverted", properties: { field } }),
|
|
94
|
+
voiceStarted: (): ChaiEvent => ({ name: "chai_composer_voice_started", properties: {} }),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** The events `ResultCard` reports. */
|
|
98
|
+
export const resultCardEvents = {
|
|
99
|
+
shown: (status: "done" | "error", outputKind: MediaKind | undefined, resultCount: number): ChaiEvent => ({
|
|
100
|
+
name: "chai_result_shown",
|
|
101
|
+
properties: { status, ...(outputKind && { output_kind: outputKind }), result_count: resultCount },
|
|
102
|
+
}),
|
|
103
|
+
action: (action: string): ChaiEvent => ({ name: "chai_result_action", properties: { action } }),
|
|
104
|
+
paged: (index: number, count: number): ChaiEvent => ({ name: "chai_result_paged", properties: { index, count } }),
|
|
105
|
+
infoOpened: (): ChaiEvent => ({ name: "chai_result_info_opened", properties: {} }),
|
|
106
|
+
};
|
package/src/index.ts
CHANGED