@runtypelabs/persona 3.16.0 → 3.18.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 +142 -0
- package/dist/animations/glyph-cycle.cjs +279 -0
- package/dist/animations/glyph-cycle.d.cts +5 -0
- package/dist/animations/glyph-cycle.d.ts +5 -0
- package/dist/animations/glyph-cycle.js +252 -0
- package/dist/animations/types-cwY5HaFD.d.cts +307 -0
- package/dist/animations/types-cwY5HaFD.d.ts +307 -0
- package/dist/animations/wipe.cjs +107 -0
- package/dist/animations/wipe.d.cts +5 -0
- package/dist/animations/wipe.d.ts +5 -0
- package/dist/animations/wipe.js +80 -0
- package/dist/index.cjs +49 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +504 -1
- package/dist/index.d.ts +504 -1
- package/dist/index.global.js +143 -88
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +49 -48
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +85 -0
- package/dist/testing.d.cts +39 -0
- package/dist/testing.d.ts +39 -0
- package/dist/testing.js +56 -0
- package/dist/theme-editor.cjs +2095 -207
- package/dist/theme-editor.d.cts +432 -2
- package/dist/theme-editor.d.ts +432 -2
- package/dist/theme-editor.js +2093 -207
- package/dist/theme-reference.cjs +1 -1
- package/dist/theme-reference.d.cts +14 -0
- package/dist/theme-reference.d.ts +14 -0
- package/dist/widget.css +565 -0
- package/package.json +20 -3
- package/src/animations/glyph-cycle.ts +332 -0
- package/src/animations/wipe.ts +66 -0
- package/src/client.test.ts +275 -0
- package/src/client.ts +99 -0
- package/src/components/ask-user-question-bubble.test.ts +583 -0
- package/src/components/ask-user-question-bubble.ts +924 -0
- package/src/components/composer-builder.ts +61 -10
- package/src/components/message-bubble.test.ts +181 -2
- package/src/components/message-bubble.ts +209 -14
- package/src/components/messages.ts +33 -1
- package/src/components/panel.ts +45 -5
- package/src/defaults.ts +37 -0
- package/src/index-global.ts +31 -0
- package/src/index.ts +34 -1
- package/src/plugins/types.ts +57 -0
- package/src/session.test.ts +276 -1
- package/src/session.ts +247 -3
- package/src/styles/widget.css +565 -0
- package/src/testing/index.ts +11 -0
- package/src/testing/mock-stream.test.ts +80 -0
- package/src/testing/mock-stream.ts +94 -0
- package/src/testing.ts +2 -0
- package/src/theme-editor/index.ts +4 -0
- package/src/theme-editor/preview-utils.test.ts +60 -0
- package/src/theme-editor/preview-utils.ts +129 -0
- package/src/theme-editor/sections.test.ts +19 -0
- package/src/theme-editor/sections.ts +84 -1
- package/src/types/theme.ts +15 -0
- package/src/types.ts +360 -0
- package/src/ui.ask-user-question-plugin.test.ts +649 -0
- package/src/ui.stop-button.test.ts +165 -0
- package/src/ui.ts +706 -11
- package/src/utils/message-fingerprint.ts +2 -0
- package/src/utils/morph.ts +7 -0
- package/src/utils/storage.ts +10 -2
- package/src/utils/stream-animation.test.ts +417 -0
- package/src/utils/stream-animation.ts +449 -0
- package/src/utils/theme.test.ts +36 -0
- package/src/utils/tokens.ts +23 -0
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/testing.ts
|
|
21
|
+
var testing_exports = {};
|
|
22
|
+
__export(testing_exports, {
|
|
23
|
+
buildAssistantTurnFrames: () => buildAssistantTurnFrames,
|
|
24
|
+
createMockSSEResponse: () => createMockSSEResponse,
|
|
25
|
+
createMockSSEStream: () => createMockSSEStream
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(testing_exports);
|
|
28
|
+
|
|
29
|
+
// src/testing/mock-stream.ts
|
|
30
|
+
var encoder = new TextEncoder();
|
|
31
|
+
function createMockSSEStream(frames, options) {
|
|
32
|
+
var _a;
|
|
33
|
+
const delayMs = (_a = options == null ? void 0 : options.delayMs) != null ? _a : 100;
|
|
34
|
+
const prefix = (options == null ? void 0 : options.eventName) ? `event: ${options.eventName}
|
|
35
|
+
` : "";
|
|
36
|
+
let index = 0;
|
|
37
|
+
return new ReadableStream({
|
|
38
|
+
async pull(controller) {
|
|
39
|
+
if (index >= frames.length) {
|
|
40
|
+
controller.close();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
44
|
+
const payload = JSON.stringify(frames[index]);
|
|
45
|
+
controller.enqueue(encoder.encode(`${prefix}data: ${payload}
|
|
46
|
+
|
|
47
|
+
`));
|
|
48
|
+
index += 1;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function buildAssistantTurnFrames(options) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const { executionId, text } = options;
|
|
55
|
+
const turnId = (_a = options.turnId) != null ? _a : "turn-1";
|
|
56
|
+
const chunkSize = Math.max(1, (_b = options.chunkSize) != null ? _b : 32);
|
|
57
|
+
const frames = [{ type: "agent_turn_start", executionId, turnId }];
|
|
58
|
+
for (let i = 0; i < text.length; i += chunkSize) {
|
|
59
|
+
frames.push({
|
|
60
|
+
type: "agent_turn_delta",
|
|
61
|
+
executionId,
|
|
62
|
+
turnId,
|
|
63
|
+
delta: text.slice(i, i + chunkSize)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
frames.push({ type: "agent_turn_complete", executionId, turnId });
|
|
67
|
+
return frames;
|
|
68
|
+
}
|
|
69
|
+
function createMockSSEResponse(frames, options) {
|
|
70
|
+
var _a;
|
|
71
|
+
const stream = createMockSSEStream(frames, options);
|
|
72
|
+
return new Response(stream, {
|
|
73
|
+
status: (_a = options == null ? void 0 : options.status) != null ? _a : 200,
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "text/event-stream",
|
|
76
|
+
...options == null ? void 0 : options.headers
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
buildAssistantTurnFrames,
|
|
83
|
+
createMockSSEResponse,
|
|
84
|
+
createMockSSEStream
|
|
85
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Shared helpers for mocking SSE streams in demos, previews, and tests. */
|
|
2
|
+
interface MockSSEFrame {
|
|
3
|
+
type: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
interface CreateMockSSEStreamOptions {
|
|
7
|
+
/** Delay in ms between emitted frames. Default: 100. */
|
|
8
|
+
delayMs?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Named event name. When set, each frame is emitted as `event: <name>\ndata: ...\n\n`.
|
|
11
|
+
* Omit for bare `data: ...\n\n` form (both are valid SSE and the widget parser accepts either).
|
|
12
|
+
*/
|
|
13
|
+
eventName?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function createMockSSEStream(frames: ReadonlyArray<MockSSEFrame>, options?: CreateMockSSEStreamOptions): ReadableStream<Uint8Array>;
|
|
16
|
+
interface AssistantTurnFramesOptions {
|
|
17
|
+
/** Execution id shared across the turn's frames. */
|
|
18
|
+
executionId: string;
|
|
19
|
+
/** Turn id. Default: `turn-1`. */
|
|
20
|
+
turnId?: string;
|
|
21
|
+
/** Assistant text content to stream. */
|
|
22
|
+
text: string;
|
|
23
|
+
/** Approximate characters per `agent_turn_delta` frame. Default: 32. */
|
|
24
|
+
chunkSize?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds the standard `agent_turn_start` → many `agent_turn_delta` → `agent_turn_complete`
|
|
28
|
+
* frame sequence for simulating a streaming assistant reply. The frames drive the same
|
|
29
|
+
* client pipeline as real SSE, so stream animations (typewriter, word-fade, etc.) engage.
|
|
30
|
+
*/
|
|
31
|
+
declare function buildAssistantTurnFrames(options: AssistantTurnFramesOptions): MockSSEFrame[];
|
|
32
|
+
interface MockSSEResponseOptions extends CreateMockSSEStreamOptions {
|
|
33
|
+
status?: number;
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/** Convenience wrapper: returns a `Response` ready to hand back from a `customFetch` implementation. */
|
|
37
|
+
declare function createMockSSEResponse(frames: ReadonlyArray<MockSSEFrame>, options?: MockSSEResponseOptions): Response;
|
|
38
|
+
|
|
39
|
+
export { type AssistantTurnFramesOptions, type CreateMockSSEStreamOptions, type MockSSEFrame, type MockSSEResponseOptions, buildAssistantTurnFrames, createMockSSEResponse, createMockSSEStream };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Shared helpers for mocking SSE streams in demos, previews, and tests. */
|
|
2
|
+
interface MockSSEFrame {
|
|
3
|
+
type: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
interface CreateMockSSEStreamOptions {
|
|
7
|
+
/** Delay in ms between emitted frames. Default: 100. */
|
|
8
|
+
delayMs?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Named event name. When set, each frame is emitted as `event: <name>\ndata: ...\n\n`.
|
|
11
|
+
* Omit for bare `data: ...\n\n` form (both are valid SSE and the widget parser accepts either).
|
|
12
|
+
*/
|
|
13
|
+
eventName?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function createMockSSEStream(frames: ReadonlyArray<MockSSEFrame>, options?: CreateMockSSEStreamOptions): ReadableStream<Uint8Array>;
|
|
16
|
+
interface AssistantTurnFramesOptions {
|
|
17
|
+
/** Execution id shared across the turn's frames. */
|
|
18
|
+
executionId: string;
|
|
19
|
+
/** Turn id. Default: `turn-1`. */
|
|
20
|
+
turnId?: string;
|
|
21
|
+
/** Assistant text content to stream. */
|
|
22
|
+
text: string;
|
|
23
|
+
/** Approximate characters per `agent_turn_delta` frame. Default: 32. */
|
|
24
|
+
chunkSize?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds the standard `agent_turn_start` → many `agent_turn_delta` → `agent_turn_complete`
|
|
28
|
+
* frame sequence for simulating a streaming assistant reply. The frames drive the same
|
|
29
|
+
* client pipeline as real SSE, so stream animations (typewriter, word-fade, etc.) engage.
|
|
30
|
+
*/
|
|
31
|
+
declare function buildAssistantTurnFrames(options: AssistantTurnFramesOptions): MockSSEFrame[];
|
|
32
|
+
interface MockSSEResponseOptions extends CreateMockSSEStreamOptions {
|
|
33
|
+
status?: number;
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/** Convenience wrapper: returns a `Response` ready to hand back from a `customFetch` implementation. */
|
|
37
|
+
declare function createMockSSEResponse(frames: ReadonlyArray<MockSSEFrame>, options?: MockSSEResponseOptions): Response;
|
|
38
|
+
|
|
39
|
+
export { type AssistantTurnFramesOptions, type CreateMockSSEStreamOptions, type MockSSEFrame, type MockSSEResponseOptions, buildAssistantTurnFrames, createMockSSEResponse, createMockSSEStream };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/testing/mock-stream.ts
|
|
2
|
+
var encoder = new TextEncoder();
|
|
3
|
+
function createMockSSEStream(frames, options) {
|
|
4
|
+
var _a;
|
|
5
|
+
const delayMs = (_a = options == null ? void 0 : options.delayMs) != null ? _a : 100;
|
|
6
|
+
const prefix = (options == null ? void 0 : options.eventName) ? `event: ${options.eventName}
|
|
7
|
+
` : "";
|
|
8
|
+
let index = 0;
|
|
9
|
+
return new ReadableStream({
|
|
10
|
+
async pull(controller) {
|
|
11
|
+
if (index >= frames.length) {
|
|
12
|
+
controller.close();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
16
|
+
const payload = JSON.stringify(frames[index]);
|
|
17
|
+
controller.enqueue(encoder.encode(`${prefix}data: ${payload}
|
|
18
|
+
|
|
19
|
+
`));
|
|
20
|
+
index += 1;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function buildAssistantTurnFrames(options) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const { executionId, text } = options;
|
|
27
|
+
const turnId = (_a = options.turnId) != null ? _a : "turn-1";
|
|
28
|
+
const chunkSize = Math.max(1, (_b = options.chunkSize) != null ? _b : 32);
|
|
29
|
+
const frames = [{ type: "agent_turn_start", executionId, turnId }];
|
|
30
|
+
for (let i = 0; i < text.length; i += chunkSize) {
|
|
31
|
+
frames.push({
|
|
32
|
+
type: "agent_turn_delta",
|
|
33
|
+
executionId,
|
|
34
|
+
turnId,
|
|
35
|
+
delta: text.slice(i, i + chunkSize)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
frames.push({ type: "agent_turn_complete", executionId, turnId });
|
|
39
|
+
return frames;
|
|
40
|
+
}
|
|
41
|
+
function createMockSSEResponse(frames, options) {
|
|
42
|
+
var _a;
|
|
43
|
+
const stream = createMockSSEStream(frames, options);
|
|
44
|
+
return new Response(stream, {
|
|
45
|
+
status: (_a = options == null ? void 0 : options.status) != null ? _a : 200,
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "text/event-stream",
|
|
48
|
+
...options == null ? void 0 : options.headers
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
buildAssistantTurnFrames,
|
|
54
|
+
createMockSSEResponse,
|
|
55
|
+
createMockSSEStream
|
|
56
|
+
};
|