rystem.playframework.client 0.1.1 → 0.1.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandResult.d.ts","sourceRoot":"","sources":["../../src/models/CommandResult.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;IACtB;;;OAGG;mBACY,MAAM,KAAG,aAAa;IAErC;;;OAGG;oBACa,MAAM,KAAG,aAAa;CACzC,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandResult = void 0;
4
+ /**
5
+ * Helper methods for creating CommandResult instances.
6
+ */
7
+ exports.CommandResult = {
8
+ /**
9
+ * Creates a successful result.
10
+ * @param message - Optional success message
11
+ */
12
+ ok: (message) => ({ success: true, message }),
13
+ /**
14
+ * Creates a failed result.
15
+ * @param message - Error message describing what went wrong
16
+ */
17
+ fail: (message) => ({ success: false, message }),
18
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Execution phase enum (matches C# ExecutionPhase).
3
+ * Serialized as camelCase from JsonStringEnumConverter.
4
+ */
5
+ export type ExecutionPhase = "notStarted" | "initialized" | "sceneSelected" | "executingScene" | "awaitingClient" | "sceneCompleted" | "chaining" | "generatingFinalResponse" | "completed" | "completedNoResponse" | "budgetExceeded" | "sceneNotFound" | "tooManyToolRequests" | "break" | "unauthorized";
6
+ /**
7
+ * Execution state for resuming conversations.
8
+ */
9
+ export interface ExecutionState {
10
+ /**
11
+ * Current execution phase.
12
+ */
13
+ phase: ExecutionPhase;
14
+ /**
15
+ * Executed scenes in order.
16
+ */
17
+ executedSceneOrder: string[];
18
+ /**
19
+ * Tools executed per scene.
20
+ */
21
+ executedScenes: Record<string, any[]>;
22
+ /**
23
+ * Executed tools.
24
+ */
25
+ executedTools: string[];
26
+ /**
27
+ * Accumulated cost.
28
+ */
29
+ accumulatedCost: number;
30
+ /**
31
+ * Current scene name (if resuming mid-execution).
32
+ */
33
+ currentSceneName?: string | null;
34
+ }
35
+ //# sourceMappingURL=ExecutionState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionState.d.ts","sourceRoot":"","sources":["../../src/models/ExecutionState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,cAAc,GACpB,YAAY,GACZ,aAAa,GACb,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,GAChB,UAAU,GACV,yBAAyB,GACzB,WAAW,GACX,qBAAqB,GACrB,gBAAgB,GAChB,eAAe,GACf,qBAAqB,GACrB,OAAO,GACP,cAAc,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;IAEtB;;OAEG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAE7B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAEtC;;OAEG;IACH,aAAa,EAAE,MAAM,EAAE,CAAC;IAExB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,88 @@
1
+ import type { StoredMessage } from './StoredMessage';
2
+ import type { ExecutionState } from './ExecutionState';
3
+ /**
4
+ * Stored conversation with messages and metadata.
5
+ */
6
+ export interface StoredConversation {
7
+ /**
8
+ * Unique conversation identifier.
9
+ */
10
+ conversationKey: string;
11
+ /**
12
+ * User who owns this conversation (null = public).
13
+ */
14
+ userId?: string | null;
15
+ /**
16
+ * Whether this conversation is public (accessible to everyone).
17
+ */
18
+ isPublic: boolean;
19
+ /**
20
+ * Last update timestamp.
21
+ */
22
+ timestamp: string;
23
+ /**
24
+ * Serializable messages.
25
+ */
26
+ messages: StoredMessage[];
27
+ /**
28
+ * Execution state (scenes executed, tools used, etc.).
29
+ */
30
+ executionState?: ExecutionState | null;
31
+ }
32
+ /**
33
+ * Query parameters for listing conversations.
34
+ */
35
+ export interface ConversationQueryParameters {
36
+ /**
37
+ * Search text in conversation messages (optional).
38
+ */
39
+ searchText?: string;
40
+ /**
41
+ * Sort order by timestamp.
42
+ */
43
+ orderBy?: ConversationSortOrder;
44
+ /**
45
+ * Include public conversations (default: true).
46
+ */
47
+ includePublic?: boolean;
48
+ /**
49
+ * Include private conversations owned by current user (default: true).
50
+ */
51
+ includePrivate?: boolean;
52
+ /**
53
+ * Number of items to skip for pagination (default: 0).
54
+ */
55
+ skip?: number;
56
+ /**
57
+ * Number of items to take for pagination (default: 50).
58
+ */
59
+ take?: number;
60
+ /**
61
+ * Include message contents (images, audio, PDFs, etc.) in responses (default: false).
62
+ * When false, contents are excluded to reduce payload size in list operations.
63
+ */
64
+ includeContents?: boolean;
65
+ }
66
+ /**
67
+ * Sort order for conversation list.
68
+ */
69
+ export declare enum ConversationSortOrder {
70
+ /**
71
+ * Newest first (default).
72
+ */
73
+ TimestampDescending = 0,
74
+ /**
75
+ * Oldest first.
76
+ */
77
+ TimestampAscending = 1
78
+ }
79
+ /**
80
+ * Request body for updating conversation visibility.
81
+ */
82
+ export interface UpdateConversationVisibilityRequest {
83
+ /**
84
+ * Whether the conversation should be public.
85
+ */
86
+ isPublic: boolean;
87
+ }
88
+ //# sourceMappingURL=StoredConversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoredConversation.d.ts","sourceRoot":"","sources":["../../src/models/StoredConversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,aAAa,EAAE,CAAC;IAE1B;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IACxC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAEhC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,oBAAY,qBAAqB;IAC7B;;OAEG;IACH,mBAAmB,IAAI;IAEvB;;OAEG;IACH,kBAAkB,IAAI;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mCAAmC;IAChD;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationSortOrder = void 0;
4
+ /**
5
+ * Sort order for conversation list.
6
+ */
7
+ var ConversationSortOrder;
8
+ (function (ConversationSortOrder) {
9
+ /**
10
+ * Newest first (default).
11
+ */
12
+ ConversationSortOrder[ConversationSortOrder["TimestampDescending"] = 0] = "TimestampDescending";
13
+ /**
14
+ * Oldest first.
15
+ */
16
+ ConversationSortOrder[ConversationSortOrder["TimestampAscending"] = 1] = "TimestampAscending";
17
+ })(ConversationSortOrder || (exports.ConversationSortOrder = ConversationSortOrder = {}));
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Serializable representation of a message.
3
+ */
4
+ export interface StoredMessage {
5
+ /**
6
+ * Business type flags.
7
+ */
8
+ businessType: number;
9
+ /**
10
+ * Label for debugging.
11
+ */
12
+ label?: string | null;
13
+ /**
14
+ * The role of the message (User, Assistant, System, Tool).
15
+ */
16
+ role: string;
17
+ /**
18
+ * Text content of the message (if any).
19
+ */
20
+ text?: string | null;
21
+ /**
22
+ * Serialized contents for complex messages.
23
+ */
24
+ contents?: any[] | null;
25
+ /**
26
+ * Additional properties from the original message.
27
+ */
28
+ additionalProperties?: Record<string, any> | null;
29
+ }
30
+ //# sourceMappingURL=StoredMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoredMessage.d.ts","sourceRoot":"","sources":["../../src/models/StoredMessage.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;CACrD"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,62 @@
1
+ import type { AIContent } from '../models/ClientInteractionResult';
2
+ /**
3
+ * Utility class for converting AIContent (base64 data) to Blob URLs for browser display.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const content: AIContent = { type: "data", data: "...", mediaType: "image/jpeg" };
8
+ *
9
+ * // Convert to Blob URL
10
+ * const url = ContentUrlConverter.toBlobUrl(content);
11
+ *
12
+ * // Use in <img> tag
13
+ * <img src={url} alt="Image" />
14
+ *
15
+ * // Cleanup when done
16
+ * ContentUrlConverter.revokeUrl(url);
17
+ * ```
18
+ */
19
+ export declare class ContentUrlConverter {
20
+ private static urlCache;
21
+ /**
22
+ * Converts AIContent with data (Base64) to a Blob object.
23
+ *
24
+ * @param content - AIContent with data field
25
+ * @returns Blob or null if no data present
26
+ */
27
+ static toBlob(content: AIContent): Blob | null;
28
+ /**
29
+ * Converts AIContent to a blob: URL that can be used in <img>, <audio>, <video>, etc.
30
+ *
31
+ * @param content - AIContent with data field
32
+ * @param cacheKey - Optional cache key for reusing URLs
33
+ * @returns Blob URL string or null if conversion fails
34
+ */
35
+ static toBlobUrl(content: AIContent, cacheKey?: string): string | null;
36
+ /**
37
+ * Revokes a blob URL to free memory. Always call this when done using the URL.
38
+ *
39
+ * @param url - Blob URL to revoke
40
+ * @param cacheKey - Optional cache key to remove from cache
41
+ */
42
+ static revokeUrl(url: string, cacheKey?: string): void;
43
+ /**
44
+ * Clears all cached blob URLs and revokes them.
45
+ */
46
+ static clearCache(): void;
47
+ /**
48
+ * Downloads AIContent as a file.
49
+ *
50
+ * @param content - AIContent to download
51
+ * @param filename - Filename to use (defaults to "download" + extension)
52
+ */
53
+ static downloadAsFile(content: AIContent, filename?: string): void;
54
+ /**
55
+ * Gets the file extension from mediaType.
56
+ *
57
+ * @param mediaType - MIME type (e.g., "image/jpeg")
58
+ * @returns File extension (e.g., ".jpg") or empty string
59
+ */
60
+ static getFileExtension(mediaType?: string): string;
61
+ }
62
+ //# sourceMappingURL=ContentUrlConverter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentUrlConverter.d.ts","sourceRoot":"","sources":["../../src/utils/ContentUrlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAEpD;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI;IAmB9C;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAwBtE;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAUtD;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IASzB;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAqBlE;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;CAyBtD"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentUrlConverter = void 0;
4
+ /**
5
+ * Utility class for converting AIContent (base64 data) to Blob URLs for browser display.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const content: AIContent = { type: "data", data: "...", mediaType: "image/jpeg" };
10
+ *
11
+ * // Convert to Blob URL
12
+ * const url = ContentUrlConverter.toBlobUrl(content);
13
+ *
14
+ * // Use in <img> tag
15
+ * <img src={url} alt="Image" />
16
+ *
17
+ * // Cleanup when done
18
+ * ContentUrlConverter.revokeUrl(url);
19
+ * ```
20
+ */
21
+ class ContentUrlConverter {
22
+ static urlCache = new Map();
23
+ /**
24
+ * Converts AIContent with data (Base64) to a Blob object.
25
+ *
26
+ * @param content - AIContent with data field
27
+ * @returns Blob or null if no data present
28
+ */
29
+ static toBlob(content) {
30
+ if (!content.data)
31
+ return null;
32
+ try {
33
+ // Decode base64 to binary string
34
+ const byteString = atob(content.data);
35
+ const bytes = new Uint8Array(byteString.length);
36
+ for (let i = 0; i < byteString.length; i++) {
37
+ bytes[i] = byteString.charCodeAt(i);
38
+ }
39
+ return new Blob([bytes], { type: content.mediaType || 'application/octet-stream' });
40
+ }
41
+ catch (error) {
42
+ console.error('Failed to decode base64 data:', error);
43
+ return null;
44
+ }
45
+ }
46
+ /**
47
+ * Converts AIContent to a blob: URL that can be used in <img>, <audio>, <video>, etc.
48
+ *
49
+ * @param content - AIContent with data field
50
+ * @param cacheKey - Optional cache key for reusing URLs
51
+ * @returns Blob URL string or null if conversion fails
52
+ */
53
+ static toBlobUrl(content, cacheKey) {
54
+ // For text content, return null (not displayable as media)
55
+ if (content.type === 'text') {
56
+ return null;
57
+ }
58
+ // Check cache first
59
+ if (cacheKey && this.urlCache.has(cacheKey)) {
60
+ return this.urlCache.get(cacheKey);
61
+ }
62
+ const blob = this.toBlob(content);
63
+ if (!blob)
64
+ return null;
65
+ const url = URL.createObjectURL(blob);
66
+ // Store in cache if key provided
67
+ if (cacheKey) {
68
+ this.urlCache.set(cacheKey, url);
69
+ }
70
+ return url;
71
+ }
72
+ /**
73
+ * Revokes a blob URL to free memory. Always call this when done using the URL.
74
+ *
75
+ * @param url - Blob URL to revoke
76
+ * @param cacheKey - Optional cache key to remove from cache
77
+ */
78
+ static revokeUrl(url, cacheKey) {
79
+ if (url.startsWith('blob:')) {
80
+ URL.revokeObjectURL(url);
81
+ }
82
+ if (cacheKey) {
83
+ this.urlCache.delete(cacheKey);
84
+ }
85
+ }
86
+ /**
87
+ * Clears all cached blob URLs and revokes them.
88
+ */
89
+ static clearCache() {
90
+ this.urlCache.forEach(url => {
91
+ if (url.startsWith('blob:')) {
92
+ URL.revokeObjectURL(url);
93
+ }
94
+ });
95
+ this.urlCache.clear();
96
+ }
97
+ /**
98
+ * Downloads AIContent as a file.
99
+ *
100
+ * @param content - AIContent to download
101
+ * @param filename - Filename to use (defaults to "download" + extension)
102
+ */
103
+ static downloadAsFile(content, filename) {
104
+ const blob = this.toBlob(content);
105
+ if (!blob) {
106
+ console.error('Cannot download: no blob data');
107
+ return;
108
+ }
109
+ const url = URL.createObjectURL(blob);
110
+ const a = document.createElement('a');
111
+ a.href = url;
112
+ // Generate filename with proper extension
113
+ const extension = this.getFileExtension(content.mediaType);
114
+ a.download = filename || `download${extension}`;
115
+ document.body.appendChild(a);
116
+ a.click();
117
+ document.body.removeChild(a);
118
+ URL.revokeObjectURL(url);
119
+ }
120
+ /**
121
+ * Gets the file extension from mediaType.
122
+ *
123
+ * @param mediaType - MIME type (e.g., "image/jpeg")
124
+ * @returns File extension (e.g., ".jpg") or empty string
125
+ */
126
+ static getFileExtension(mediaType) {
127
+ if (!mediaType)
128
+ return '';
129
+ const extensionMap = {
130
+ 'image/jpeg': '.jpg',
131
+ 'image/png': '.png',
132
+ 'image/gif': '.gif',
133
+ 'image/webp': '.webp',
134
+ 'image/svg+xml': '.svg',
135
+ 'audio/mpeg': '.mp3',
136
+ 'audio/wav': '.wav',
137
+ 'audio/ogg': '.ogg',
138
+ 'video/mp4': '.mp4',
139
+ 'video/webm': '.webm',
140
+ 'video/ogg': '.ogv',
141
+ 'application/pdf': '.pdf',
142
+ 'application/json': '.json',
143
+ 'text/plain': '.txt',
144
+ 'text/html': '.html',
145
+ 'text/css': '.css',
146
+ 'application/javascript': '.js',
147
+ };
148
+ return extensionMap[mediaType] || '';
149
+ }
150
+ }
151
+ exports.ContentUrlConverter = ContentUrlConverter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rystem.playframework.client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "author": "Alessandro Rapiti <alessandro.rapiti44@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "TypeScript client for Rystem PlayFramework HTTP API with step-by-step and token-level streaming support.",