@api-client/core 0.19.3 → 0.19.4
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/build/src/models/AiSession.d.ts +13 -0
- package/build/src/models/AiSession.d.ts.map +1 -1
- package/build/src/models/AiSession.js +8 -0
- package/build/src/models/AiSession.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/models/AiSession.ts +20 -0
- package/tests/unit/models/AiSession.spec.ts +5 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { IDeletion } from './store/Deletion.js';
|
|
2
2
|
import { AiSessionKind } from './kinds.js';
|
|
3
3
|
import type { AiModelMessage } from './AiMessage.js';
|
|
4
|
+
/**
|
|
5
|
+
* The application the session is for.
|
|
6
|
+
*
|
|
7
|
+
* - `domain` - The session is for data domain modeling.
|
|
8
|
+
* - `api` - The session is for API modeling.
|
|
9
|
+
* - `general` - The session is for general AI chat.
|
|
10
|
+
*/
|
|
4
11
|
export type AiSessionApp = 'domain' | 'api' | 'general';
|
|
5
12
|
export interface AiSessionSchema {
|
|
6
13
|
/**
|
|
@@ -48,6 +55,11 @@ export interface AiSessionSchema {
|
|
|
48
55
|
* Always set when the `delete` is true.
|
|
49
56
|
*/
|
|
50
57
|
deletedInfo?: IDeletion;
|
|
58
|
+
/**
|
|
59
|
+
* If the session is related to a file (data domain, API model, etc.), this is the key of the file.
|
|
60
|
+
* It is useful to filter session by specific object.
|
|
61
|
+
*/
|
|
62
|
+
fileKey?: string;
|
|
51
63
|
}
|
|
52
64
|
export declare class AiSession implements AiSessionSchema {
|
|
53
65
|
static get Kind(): typeof AiSessionKind;
|
|
@@ -61,6 +73,7 @@ export declare class AiSession implements AiSessionSchema {
|
|
|
61
73
|
updatedAt: number;
|
|
62
74
|
deleted: boolean;
|
|
63
75
|
deletedInfo?: IDeletion;
|
|
76
|
+
fileKey?: string;
|
|
64
77
|
/**
|
|
65
78
|
* Checks if the given value is a valid AiSessionApp.
|
|
66
79
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiSession.d.ts","sourceRoot":"","sources":["../../../src/models/AiSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAA;AAEvD,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,aAAa,CAAA;IACnC;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,GAAG,EAAE,YAAY,CAAA;IACjB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,MAAM,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;IACpB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"AiSession.d.ts","sourceRoot":"","sources":["../../../src/models/AiSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAA;AAEvD,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QA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,GAAG,IAAI;CAenE"}
|
|
@@ -16,6 +16,7 @@ export class AiSession {
|
|
|
16
16
|
updatedAt;
|
|
17
17
|
deleted;
|
|
18
18
|
deletedInfo;
|
|
19
|
+
fileKey;
|
|
19
20
|
/**
|
|
20
21
|
* Checks if the given value is a valid AiSessionApp.
|
|
21
22
|
*/
|
|
@@ -44,6 +45,9 @@ export class AiSession {
|
|
|
44
45
|
result.deleted = input.deleted;
|
|
45
46
|
result.deletedInfo = input.deletedInfo;
|
|
46
47
|
}
|
|
48
|
+
if (input.fileKey) {
|
|
49
|
+
result.fileKey = input.fileKey;
|
|
50
|
+
}
|
|
47
51
|
return result;
|
|
48
52
|
}
|
|
49
53
|
constructor(input = {}) {
|
|
@@ -57,6 +61,7 @@ export class AiSession {
|
|
|
57
61
|
this.updatedAt = init.updatedAt;
|
|
58
62
|
this.deleted = init.deleted || false;
|
|
59
63
|
this.deletedInfo = init.deletedInfo;
|
|
64
|
+
this.fileKey = init.fileKey;
|
|
60
65
|
}
|
|
61
66
|
toJSON() {
|
|
62
67
|
const result = {
|
|
@@ -73,6 +78,9 @@ export class AiSession {
|
|
|
73
78
|
result.deleted = this.deleted;
|
|
74
79
|
result.deletedInfo = { ...this.deletedInfo };
|
|
75
80
|
}
|
|
81
|
+
if (this.fileKey) {
|
|
82
|
+
result.fileKey = this.fileKey;
|
|
83
|
+
}
|
|
76
84
|
return result;
|
|
77
85
|
}
|
|
78
86
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiSession.js","sourceRoot":"","sources":["../../../src/models/AiSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"AiSession.js","sourceRoot":"","sources":["../../../src/models/AiSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OA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CAAC,WAAW,EAAE,CAAC;YACrC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;YAC7B,MAAM,CAAC,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;QAC9C,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC/B,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAuB;QAChD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,IAAI,CAAA;QACb,CAAC;QACD,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC5B,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACtB,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAClC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import type { IDeletion } from './store/Deletion.js'\nimport { AiSessionKind } from './kinds.js'\nimport { nanoid } from '../nanoid.js'\nimport type { AiModelMessage } from './AiMessage.js'\n\n/**\n * The application the session is for.\n *\n * - `domain` - The session is for data domain modeling.\n * - `api` - The session is for API modeling.\n * - `general` - The session is for general AI chat.\n */\nexport type AiSessionApp = 'domain' | 'api' | 'general'\n\nexport interface AiSessionSchema {\n /**\n * The kind of the schema\n * This is set by the API and is used to identify the schema.\n * @readonly\n */\n readonly kind: typeof AiSessionKind\n /**\n * The key of the session\n * This is set by the API and is used to identify the session.\n */\n key: string\n /**\n * The application the session is for.\n * Each app must query for its own sessions.\n */\n app: AiSessionApp\n /**\n * The title of the session.\n */\n title: string\n /**\n * Whether the session is pinned.\n */\n pinned: boolean\n /**\n * Whether the user has renamed the session.\n */\n userRenamed: boolean\n /**\n * The creation timestamp of the session.\n */\n createdAt: number\n /**\n * The update timestamp of the session.\n */\n updatedAt: number\n /**\n * Whether the file object is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `delete` is true.\n */\n deletedInfo?: IDeletion\n /**\n * If the session is related to a file (data domain, API model, etc.), this is the key of the file.\n * It is useful to filter session by specific object.\n */\n fileKey?: string\n}\n\nexport class AiSession implements AiSessionSchema {\n static get Kind(): typeof AiSessionKind {\n return AiSessionKind\n }\n\n get kind(): typeof AiSessionKind {\n return AiSessionKind\n }\n\n key: string\n app: AiSessionApp\n title: string\n pinned: boolean\n userRenamed: boolean\n createdAt: number\n updatedAt: number\n deleted: boolean\n deletedInfo?: IDeletion\n fileKey?: string\n\n /**\n * Checks if the given value is a valid AiSessionApp.\n */\n static isSessionApp(app: unknown): app is AiSessionApp {\n return ['domain', 'api', 'general'].includes(app as string)\n }\n\n static createSchema(input: Partial<AiSessionSchema>): AiSessionSchema {\n const { key = nanoid(), app, title = '', createdAt = 0, updatedAt = 0, pinned = false, userRenamed = false } = input\n if (!app) {\n throw new Error('App is required to create an AiSession schema.')\n }\n if (!AiSession.isSessionApp(app)) {\n throw new Error(`Invalid app: ${app}`)\n }\n const result: AiSessionSchema = {\n key,\n kind: AiSessionKind,\n app,\n title,\n pinned,\n userRenamed,\n createdAt,\n updatedAt,\n }\n if (input.deleted) {\n result.deleted = input.deleted\n result.deletedInfo = input.deletedInfo\n }\n if (input.fileKey) {\n result.fileKey = input.fileKey\n }\n return result\n }\n\n constructor(input: Partial<AiSessionSchema> = {}) {\n const init = AiSession.createSchema(input)\n this.key = init.key\n this.app = init.app\n this.title = init.title\n this.pinned = init.pinned\n this.userRenamed = init.userRenamed\n this.createdAt = init.createdAt\n this.updatedAt = init.updatedAt\n this.deleted = init.deleted || false\n this.deletedInfo = init.deletedInfo\n this.fileKey = init.fileKey\n }\n\n toJSON(): AiSessionSchema {\n const result: AiSessionSchema = {\n kind: this.kind,\n key: this.key,\n app: this.app,\n title: this.title,\n pinned: this.pinned,\n userRenamed: this.userRenamed,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n }\n if (this.deleted && this.deletedInfo) {\n result.deleted = this.deleted\n result.deletedInfo = { ...this.deletedInfo }\n }\n if (this.fileKey) {\n result.fileKey = this.fileKey\n }\n return result\n }\n\n /**\n * Processes the agent response and extracts the session title if available.\n * It looks for a JSON object in the response text and extracts the `sessionTitle`.\n *\n * @param message The agent response.\n * @returns {string | null} The session title if found, otherwise null.\n */\n static extractSessionTitle(message: AiModelMessage): string | null {\n const txt = message.text\n if (!txt) {\n return null\n }\n try {\n const json = JSON.parse(txt)\n if (json.sessionTitle) {\n return String(json.sessionTitle)\n }\n } catch {\n // ignore\n }\n return null\n }\n}\n"]}
|