@things-factory/board-ai 10.0.0-beta.64
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/client/components/board-ai-chat.test.ts +120 -0
- package/client/components/board-ai-chat.ts +1502 -0
- package/client/components/chat-input-builder.ts +40 -0
- package/client/components/markdown.test.ts +220 -0
- package/client/components/markdown.ts +184 -0
- package/client/index.ts +11 -0
- package/client/tsconfig.json +13 -0
- package/client/utils/board-edit-patch.ts +200 -0
- package/config/config.development.js +43 -0
- package/config/config.production.js +15 -0
- package/dist-client/components/board-ai-chat.d.ts +127 -0
- package/dist-client/components/board-ai-chat.js +1455 -0
- package/dist-client/components/board-ai-chat.js.map +1 -0
- package/dist-client/components/board-ai-chat.test.d.ts +1 -0
- package/dist-client/components/board-ai-chat.test.js +112 -0
- package/dist-client/components/board-ai-chat.test.js.map +1 -0
- package/dist-client/components/chat-input-builder.d.ts +30 -0
- package/dist-client/components/chat-input-builder.js +25 -0
- package/dist-client/components/chat-input-builder.js.map +1 -0
- package/dist-client/components/markdown.d.ts +16 -0
- package/dist-client/components/markdown.js +167 -0
- package/dist-client/components/markdown.js.map +1 -0
- package/dist-client/components/markdown.test.d.ts +1 -0
- package/dist-client/components/markdown.test.js +187 -0
- package/dist-client/components/markdown.test.js.map +1 -0
- package/dist-client/index.d.ts +11 -0
- package/dist-client/index.js +12 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-client/utils/board-edit-patch.d.ts +73 -0
- package/dist-client/utils/board-edit-patch.js +159 -0
- package/dist-client/utils/board-edit-patch.js.map +1 -0
- package/dist-server/index.d.ts +21 -0
- package/dist-server/index.js +25 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/service/apply-patch.d.ts +46 -0
- package/dist-server/service/apply-patch.js +211 -0
- package/dist-server/service/apply-patch.js.map +1 -0
- package/dist-server/service/assistant.d.ts +75 -0
- package/dist-server/service/assistant.js +1298 -0
- package/dist-server/service/assistant.js.map +1 -0
- package/dist-server/service/board-ai-resolver.d.ts +40 -0
- package/dist-server/service/board-ai-resolver.js +260 -0
- package/dist-server/service/board-ai-resolver.js.map +1 -0
- package/dist-server/service/chat-message/chat-message.d.ts +24 -0
- package/dist-server/service/chat-message/chat-message.js +108 -0
- package/dist-server/service/chat-message/chat-message.js.map +1 -0
- package/dist-server/service/chat-message/index.d.ts +3 -0
- package/dist-server/service/chat-message/index.js +7 -0
- package/dist-server/service/chat-message/index.js.map +1 -0
- package/dist-server/service/chat-session/chat-session.d.ts +22 -0
- package/dist-server/service/chat-session/chat-session.js +109 -0
- package/dist-server/service/chat-session/chat-session.js.map +1 -0
- package/dist-server/service/chat-session/index.d.ts +3 -0
- package/dist-server/service/chat-session/index.js +7 -0
- package/dist-server/service/chat-session/index.js.map +1 -0
- package/dist-server/service/chat-session-resolver.d.ts +13 -0
- package/dist-server/service/chat-session-resolver.js +178 -0
- package/dist-server/service/chat-session-resolver.js.map +1 -0
- package/dist-server/service/index.d.ts +14 -0
- package/dist-server/service/index.js +26 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/patch-entry/index.d.ts +3 -0
- package/dist-server/service/patch-entry/index.js +7 -0
- package/dist-server/service/patch-entry/index.js.map +1 -0
- package/dist-server/service/patch-entry/patch-entry.d.ts +16 -0
- package/dist-server/service/patch-entry/patch-entry.js +96 -0
- package/dist-server/service/patch-entry/patch-entry.js.map +1 -0
- package/dist-server/service/types.d.ts +137 -0
- package/dist-server/service/types.js +3 -0
- package/dist-server/service/types.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +47 -0
- package/server/index.ts +21 -0
- package/server/service/apply-patch.test.ts +640 -0
- package/server/service/apply-patch.ts +250 -0
- package/server/service/assistant.test.ts +1317 -0
- package/server/service/assistant.ts +1431 -0
- package/server/service/board-ai-resolver.ts +239 -0
- package/server/service/chat-message/chat-message.ts +110 -0
- package/server/service/chat-message/index.ts +5 -0
- package/server/service/chat-session/chat-session.ts +103 -0
- package/server/service/chat-session/index.ts +5 -0
- package/server/service/chat-session-resolver.ts +154 -0
- package/server/service/index.ts +24 -0
- package/server/service/patch-entry/index.ts +5 -0
- package/server/service/patch-entry/patch-entry.ts +89 -0
- package/server/service/types.ts +138 -0
- package/things-factory.config.js +1 -0
- package/translations/en.json +39 -0
- package/translations/ja.json +39 -0
- package/translations/ko.json +40 -0
- package/translations/ms.json +39 -0
- package/translations/zh.json +39 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatMessage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* ChatMessage — ChatSession 의 한 메시지.
|
|
7
|
+
*
|
|
8
|
+
* role: 'user' | 'assistant' | 'system'
|
|
9
|
+
* 'system' 은 사용자 직접 편집/import 진행 등 시스템이 자동 생성하는 컨텍스트 메시지.
|
|
10
|
+
*
|
|
11
|
+
* relatedPatchId / relatedImportSessionId 로 메시지가 트리거한 패치·임포트와 연결.
|
|
12
|
+
*/
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const type_graphql_1 = require("type-graphql");
|
|
15
|
+
const graphql_scalars_1 = require("graphql-scalars");
|
|
16
|
+
const env_1 = require("@things-factory/env");
|
|
17
|
+
const chat_session_js_1 = require("../chat-session/chat-session.js");
|
|
18
|
+
const ORMCONFIG = env_1.config.get('ormconfig', {});
|
|
19
|
+
const DATABASE_TYPE = ORMCONFIG.type;
|
|
20
|
+
let ChatMessage = class ChatMessage {
|
|
21
|
+
/** GraphQL 노출용 — JSON 배열로 parse. */
|
|
22
|
+
get toolUsagesJson() {
|
|
23
|
+
if (!this.toolUsages)
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(this.toolUsages);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.ChatMessage = ChatMessage;
|
|
34
|
+
tslib_1.__decorate([
|
|
35
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
36
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true }),
|
|
37
|
+
tslib_1.__metadata("design:type", String)
|
|
38
|
+
], ChatMessage.prototype, "id", void 0);
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, typeorm_1.ManyToOne)(type => chat_session_js_1.ChatSession, session => session.messages, { onDelete: 'CASCADE' }),
|
|
41
|
+
tslib_1.__metadata("design:type", chat_session_js_1.ChatSession)
|
|
42
|
+
], ChatMessage.prototype, "session", void 0);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, typeorm_1.RelationId)((message) => message.session),
|
|
45
|
+
tslib_1.__metadata("design:type", String)
|
|
46
|
+
], ChatMessage.prototype, "sessionId", void 0);
|
|
47
|
+
tslib_1.__decorate([
|
|
48
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 16 }),
|
|
49
|
+
(0, type_graphql_1.Field)({ description: "'user' | 'assistant' | 'system'" }),
|
|
50
|
+
tslib_1.__metadata("design:type", String)
|
|
51
|
+
], ChatMessage.prototype, "role", void 0);
|
|
52
|
+
tslib_1.__decorate([
|
|
53
|
+
(0, typeorm_1.Column)({
|
|
54
|
+
type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
55
|
+
? 'longtext'
|
|
56
|
+
: DATABASE_TYPE == 'oracle'
|
|
57
|
+
? 'clob'
|
|
58
|
+
: DATABASE_TYPE == 'mssql'
|
|
59
|
+
? 'nvarchar'
|
|
60
|
+
: 'text',
|
|
61
|
+
length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined
|
|
62
|
+
}),
|
|
63
|
+
(0, type_graphql_1.Field)({ description: 'Message content' }),
|
|
64
|
+
tslib_1.__metadata("design:type", String)
|
|
65
|
+
], ChatMessage.prototype, "content", void 0);
|
|
66
|
+
tslib_1.__decorate([
|
|
67
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
68
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'PatchEntry.id this message triggered (if any).' }),
|
|
69
|
+
tslib_1.__metadata("design:type", String)
|
|
70
|
+
], ChatMessage.prototype, "relatedPatchId", void 0);
|
|
71
|
+
tslib_1.__decorate([
|
|
72
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
73
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'ImportSession.id this message triggered (if any).' }),
|
|
74
|
+
tslib_1.__metadata("design:type", String)
|
|
75
|
+
], ChatMessage.prototype, "relatedImportSessionId", void 0);
|
|
76
|
+
tslib_1.__decorate([
|
|
77
|
+
(0, typeorm_1.Column)({
|
|
78
|
+
type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
79
|
+
? 'longtext'
|
|
80
|
+
: DATABASE_TYPE == 'oracle'
|
|
81
|
+
? 'clob'
|
|
82
|
+
: DATABASE_TYPE == 'mssql'
|
|
83
|
+
? 'nvarchar'
|
|
84
|
+
: 'text',
|
|
85
|
+
length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined,
|
|
86
|
+
nullable: true
|
|
87
|
+
}),
|
|
88
|
+
tslib_1.__metadata("design:type", String)
|
|
89
|
+
], ChatMessage.prototype, "toolUsages", void 0);
|
|
90
|
+
tslib_1.__decorate([
|
|
91
|
+
(0, type_graphql_1.Field)(() => graphql_scalars_1.GraphQLJSON, {
|
|
92
|
+
nullable: true,
|
|
93
|
+
description: 'Tool usage trace — array of {name, arguments, result, kind}. Only on assistant messages.'
|
|
94
|
+
}),
|
|
95
|
+
tslib_1.__metadata("design:type", Object),
|
|
96
|
+
tslib_1.__metadata("design:paramtypes", [])
|
|
97
|
+
], ChatMessage.prototype, "toolUsagesJson", null);
|
|
98
|
+
tslib_1.__decorate([
|
|
99
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
100
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
101
|
+
tslib_1.__metadata("design:type", Date)
|
|
102
|
+
], ChatMessage.prototype, "createdAt", void 0);
|
|
103
|
+
exports.ChatMessage = ChatMessage = tslib_1.__decorate([
|
|
104
|
+
(0, typeorm_1.Entity)(),
|
|
105
|
+
(0, typeorm_1.Index)('ix_chat_message_1', (message) => [message.session, message.createdAt]),
|
|
106
|
+
(0, type_graphql_1.ObjectType)({ description: 'A single chat message in a ChatSession.' })
|
|
107
|
+
], ChatMessage);
|
|
108
|
+
//# sourceMappingURL=chat-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-message.js","sourceRoot":"","sources":["../../../server/service/chat-message/chat-message.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;GAOG;AACH,qCAQgB;AAChB,+CAAoD;AACpD,qDAA6C;AAE7C,6CAA4C;AAE5C,qEAA6D;AAE7D,MAAM,SAAS,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAA;AAK7B,IAAM,WAAW,GAAjB,MAAM,WAAW;IA6DtB,oCAAoC;IACpC,IAKI,cAAc;QAChB,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAA;QACjC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CAKF,CAAA;AA/EY,kCAAW;AAGb;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;uCAClB;AAGpB;IADC,I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,IAAI,EACF,aAAa,IAAI,OAAO,IAAI,aAAa,IAAI,SAAS;YACpD,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,aAAa,IAAI,QAAQ;gBACzB,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,aAAa,IAAI,OAAO;oBACxB,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,MAAM;QAChB,MAAM,EAAE,aAAa,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;QACpD,QAAQ,EAAE,IAAI;KACf,CAAC;;+CACiB;AAGnB;IAAC,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,6BAAW,EAAE;QACxB,QAAQ,EAAE,IAAI;QACd,WAAW,EACT,0FAA0F;KAC7F,CAAC;;;iDAQD;AAID;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACd,IAAI;8CAAA;sBA9EL,WAAW;IAHvB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,mBAAmB,EAAE,CAAC,OAAoB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1F,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAAC;GAC1D,WAAW,CA+EvB","sourcesContent":["/**\n * ChatMessage — ChatSession 의 한 메시지.\n *\n * role: 'user' | 'assistant' | 'system'\n * 'system' 은 사용자 직접 편집/import 진행 등 시스템이 자동 생성하는 컨텍스트 메시지.\n *\n * relatedPatchId / relatedImportSessionId 로 메시지가 트리거한 패치·임포트와 연결.\n */\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n PrimaryGeneratedColumn,\n RelationId\n} from 'typeorm'\nimport { Field, ID, ObjectType } from 'type-graphql'\nimport { GraphQLJSON } from 'graphql-scalars'\n\nimport { config } from '@things-factory/env'\n\nimport { ChatSession } from '../chat-session/chat-session.js'\n\nconst ORMCONFIG = config.get('ormconfig', {})\nconst DATABASE_TYPE = ORMCONFIG.type\n\n@Entity()\n@Index('ix_chat_message_1', (message: ChatMessage) => [message.session, message.createdAt])\n@ObjectType({ description: 'A single chat message in a ChatSession.' })\nexport class ChatMessage {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { nullable: true })\n readonly id?: string\n\n @ManyToOne(type => ChatSession, session => session.messages, { onDelete: 'CASCADE' })\n session?: ChatSession\n\n @RelationId((message: ChatMessage) => message.session)\n sessionId?: string\n\n @Column({ type: 'varchar', length: 16 })\n @Field({ description: \"'user' | 'assistant' | 'system'\" })\n role!: string\n\n @Column({\n type:\n DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'\n ? 'longtext'\n : DATABASE_TYPE == 'oracle'\n ? 'clob'\n : DATABASE_TYPE == 'mssql'\n ? 'nvarchar'\n : 'text',\n length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined\n })\n @Field({ description: 'Message content' })\n content!: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'PatchEntry.id this message triggered (if any).' })\n relatedPatchId?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'ImportSession.id this message triggered (if any).' })\n relatedImportSessionId?: string\n\n /**\n * AI 가 응답을 만드는 동안 호출한 도구 trace — JSON-stringified.\n *\n * 컬럼은 string (PatchEntry.ops 와 동일 패턴), GraphQL 노출은 toolUsagesJson getter\n * 로 parse 된 객체. UI 의 fold-able 박스 (\"AI 가 이런 도구를 사용했습니다\") 가\n * 페이지 reload / loadHistory 후에도 살아있도록 영속.\n *\n * 형태: ToolUsage[] (assistant.ts 의 시간순 trace, summarizeToolResult 로 압축).\n * null 이면 도구 호출 없었던 메시지 (text-only 응답).\n */\n @Column({\n type:\n DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'\n ? 'longtext'\n : DATABASE_TYPE == 'oracle'\n ? 'clob'\n : DATABASE_TYPE == 'mssql'\n ? 'nvarchar'\n : 'text',\n length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined,\n nullable: true\n })\n toolUsages?: string\n\n /** GraphQL 노출용 — JSON 배열로 parse. */\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'Tool usage trace — array of {name, arguments, result, kind}. Only on assistant messages.'\n })\n get toolUsagesJson(): any {\n if (!this.toolUsages) return null\n try {\n return JSON.parse(this.toolUsages)\n } catch {\n return null\n }\n }\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt?: Date\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entities = exports.ChatMessage = void 0;
|
|
4
|
+
const chat_message_js_1 = require("./chat-message.js");
|
|
5
|
+
Object.defineProperty(exports, "ChatMessage", { enumerable: true, get: function () { return chat_message_js_1.ChatMessage; } });
|
|
6
|
+
exports.entities = [chat_message_js_1.ChatMessage];
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/chat-message/index.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAEtC,4FAFA,6BAAW,OAEA;AAEP,QAAA,QAAQ,GAAG,CAAC,6BAAW,CAAC,CAAA","sourcesContent":["import { ChatMessage } from './chat-message.js'\n\nexport { ChatMessage }\n\nexport const entities = [ChatMessage]\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Domain } from '@things-factory/shell';
|
|
2
|
+
import { User } from '@things-factory/auth-base';
|
|
3
|
+
import { ChatMessage } from '../chat-message/chat-message.js';
|
|
4
|
+
import { PatchEntry } from '../patch-entry/patch-entry.js';
|
|
5
|
+
export declare class ChatSession {
|
|
6
|
+
readonly id?: string;
|
|
7
|
+
domain?: Domain;
|
|
8
|
+
domainId?: string;
|
|
9
|
+
/** Board.id 와 연결. Board 가 owning side 가 될 예정. unique 로 1:1 강제. */
|
|
10
|
+
boardId?: string;
|
|
11
|
+
creator?: User;
|
|
12
|
+
updater?: User;
|
|
13
|
+
/** 토큰 절감용 — 오래된 메시지를 LLM 으로 압축한 요약. Phase 2 에서 작성. */
|
|
14
|
+
lastSummary?: string;
|
|
15
|
+
/** 사용 모델 식별 — 'anthropic:claude-sonnet-4-6' 등 */
|
|
16
|
+
aiClientId?: string;
|
|
17
|
+
createdAt?: Date;
|
|
18
|
+
updatedAt?: Date;
|
|
19
|
+
deletedAt?: Date;
|
|
20
|
+
messages?: ChatMessage[];
|
|
21
|
+
patches?: PatchEntry[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatSession = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* ChatSession — Board 와 1:1 결합되는 AI 협력 세션.
|
|
7
|
+
*
|
|
8
|
+
* 보드 1개 = ChatSession 1개. 보드 수명 = 협력 수명. 보드 다시 열면 컨텍스트 복원.
|
|
9
|
+
* board-service 의 Board 가 owning side 가 될 예정 (ChatSession FK).
|
|
10
|
+
* 이번 단계에서는 ChatSession 이 boardId 만 unique 로 보유 (단계적 마이그레이션 위함).
|
|
11
|
+
*/
|
|
12
|
+
const typeorm_1 = require("typeorm");
|
|
13
|
+
const type_graphql_1 = require("type-graphql");
|
|
14
|
+
const shell_1 = require("@things-factory/shell");
|
|
15
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
16
|
+
const env_1 = require("@things-factory/env");
|
|
17
|
+
const chat_message_js_1 = require("../chat-message/chat-message.js");
|
|
18
|
+
const patch_entry_js_1 = require("../patch-entry/patch-entry.js");
|
|
19
|
+
const ORMCONFIG = env_1.config.get('ormconfig', {});
|
|
20
|
+
const DATABASE_TYPE = ORMCONFIG.type;
|
|
21
|
+
let ChatSession = class ChatSession {
|
|
22
|
+
};
|
|
23
|
+
exports.ChatSession = ChatSession;
|
|
24
|
+
tslib_1.__decorate([
|
|
25
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
26
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true }),
|
|
27
|
+
tslib_1.__metadata("design:type", String)
|
|
28
|
+
], ChatSession.prototype, "id", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, typeorm_1.ManyToOne)(type => shell_1.Domain),
|
|
31
|
+
(0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true }),
|
|
32
|
+
tslib_1.__metadata("design:type", shell_1.Domain)
|
|
33
|
+
], ChatSession.prototype, "domain", void 0);
|
|
34
|
+
tslib_1.__decorate([
|
|
35
|
+
(0, typeorm_1.RelationId)((session) => session.domain),
|
|
36
|
+
tslib_1.__metadata("design:type", String)
|
|
37
|
+
], ChatSession.prototype, "domainId", void 0);
|
|
38
|
+
tslib_1.__decorate([
|
|
39
|
+
(0, typeorm_1.Column)({ nullable: true, unique: true }),
|
|
40
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Connected Board id (1:1)' }),
|
|
41
|
+
tslib_1.__metadata("design:type", String)
|
|
42
|
+
], ChatSession.prototype, "boardId", void 0);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User),
|
|
45
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
|
|
46
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
47
|
+
], ChatSession.prototype, "creator", void 0);
|
|
48
|
+
tslib_1.__decorate([
|
|
49
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User),
|
|
50
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
|
|
51
|
+
tslib_1.__metadata("design:type", auth_base_1.User
|
|
52
|
+
/** 토큰 절감용 — 오래된 메시지를 LLM 으로 압축한 요약. Phase 2 에서 작성. */
|
|
53
|
+
)
|
|
54
|
+
], ChatSession.prototype, "updater", void 0);
|
|
55
|
+
tslib_1.__decorate([
|
|
56
|
+
(0, typeorm_1.Column)({
|
|
57
|
+
nullable: true,
|
|
58
|
+
type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
59
|
+
? 'longtext'
|
|
60
|
+
: DATABASE_TYPE == 'oracle'
|
|
61
|
+
? 'clob'
|
|
62
|
+
: DATABASE_TYPE == 'mssql'
|
|
63
|
+
? 'nvarchar'
|
|
64
|
+
: 'text',
|
|
65
|
+
length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined
|
|
66
|
+
}),
|
|
67
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Compressed summary of older messages (for token saving).' }),
|
|
68
|
+
tslib_1.__metadata("design:type", String)
|
|
69
|
+
], ChatSession.prototype, "lastSummary", void 0);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
72
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
73
|
+
tslib_1.__metadata("design:type", String)
|
|
74
|
+
], ChatSession.prototype, "aiClientId", void 0);
|
|
75
|
+
tslib_1.__decorate([
|
|
76
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
77
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
78
|
+
tslib_1.__metadata("design:type", Date)
|
|
79
|
+
], ChatSession.prototype, "createdAt", void 0);
|
|
80
|
+
tslib_1.__decorate([
|
|
81
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
82
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
83
|
+
tslib_1.__metadata("design:type", Date)
|
|
84
|
+
], ChatSession.prototype, "updatedAt", void 0);
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, typeorm_1.DeleteDateColumn)(),
|
|
87
|
+
tslib_1.__metadata("design:type", Date
|
|
88
|
+
// ── 관계 (TypeORM 만, GraphQL 노출은 별도 query 통해 페이징) ──
|
|
89
|
+
)
|
|
90
|
+
], ChatSession.prototype, "deletedAt", void 0);
|
|
91
|
+
tslib_1.__decorate([
|
|
92
|
+
(0, typeorm_1.OneToMany)(type => chat_message_js_1.ChatMessage, message => message.session),
|
|
93
|
+
tslib_1.__metadata("design:type", Array)
|
|
94
|
+
], ChatSession.prototype, "messages", void 0);
|
|
95
|
+
tslib_1.__decorate([
|
|
96
|
+
(0, typeorm_1.OneToMany)(type => patch_entry_js_1.PatchEntry, patch => patch.session),
|
|
97
|
+
tslib_1.__metadata("design:type", Array)
|
|
98
|
+
], ChatSession.prototype, "patches", void 0);
|
|
99
|
+
exports.ChatSession = ChatSession = tslib_1.__decorate([
|
|
100
|
+
(0, typeorm_1.Entity)(),
|
|
101
|
+
(0, typeorm_1.Index)('ix_chat_session_1', (session) => [session.domain, session.boardId], {
|
|
102
|
+
unique: true,
|
|
103
|
+
where: '"deleted_at" IS NULL'
|
|
104
|
+
}),
|
|
105
|
+
(0, type_graphql_1.ObjectType)({
|
|
106
|
+
description: 'AI 협력 세션 — Board 와 1:1 결합. 메시지/패치 이력을 영속하여 컨텍스트 복원.'
|
|
107
|
+
})
|
|
108
|
+
], ChatSession);
|
|
109
|
+
//# sourceMappingURL=chat-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-session.js","sourceRoot":"","sources":["../../../server/service/chat-session/chat-session.ts"],"names":[],"mappings":";;;;AAAA;;;;;;GAMG;AACH,qCAWgB;AAChB,+CAAoD;AAEpD,iDAA8C;AAC9C,yDAAgD;AAChD,6CAA4C;AAE5C,qEAA6D;AAC7D,kEAA0D;AAE1D,MAAM,SAAS,GAAG,YAAM,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAA;AAU7B,IAAM,WAAW,GAAjB,MAAM,WAAW;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IAAA,yBAAU,EAAC;QACV,WAAW,EAAE,qDAAqD;KACnE,CAAC;GACW,WAAW,CA+DvB","sourcesContent":["/**\n * ChatSession — Board 와 1:1 결합되는 AI 협력 세션.\n *\n * 보드 1개 = ChatSession 1개. 보드 수명 = 협력 수명. 보드 다시 열면 컨텍스트 복원.\n * board-service 의 Board 가 owning side 가 될 예정 (ChatSession FK).\n * 이번 단계에서는 ChatSession 이 boardId 만 unique 로 보유 (단계적 마이그레이션 위함).\n */\nimport {\n Column,\n CreateDateColumn,\n DeleteDateColumn,\n Entity,\n Index,\n ManyToOne,\n OneToMany,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\nimport { Field, ID, ObjectType } from 'type-graphql'\n\nimport { Domain } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { config } from '@things-factory/env'\n\nimport { ChatMessage } from '../chat-message/chat-message.js'\nimport { PatchEntry } from '../patch-entry/patch-entry.js'\n\nconst ORMCONFIG = config.get('ormconfig', {})\nconst DATABASE_TYPE = ORMCONFIG.type\n\n@Entity()\n@Index('ix_chat_session_1', (session: ChatSession) => [session.domain, session.boardId], {\n unique: true,\n where: '\"deleted_at\" IS NULL'\n})\n@ObjectType({\n description: 'AI 협력 세션 — Board 와 1:1 결합. 메시지/패치 이력을 영속하여 컨텍스트 복원.'\n})\nexport class ChatSession {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { nullable: true })\n readonly id?: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true })\n domain?: Domain\n\n @RelationId((session: ChatSession) => session.domain)\n domainId?: string\n\n /** Board.id 와 연결. Board 가 owning side 가 될 예정. unique 로 1:1 강제. */\n @Column({ nullable: true, unique: true })\n @Field({ nullable: true, description: 'Connected Board id (1:1)' })\n boardId?: string\n\n @ManyToOne(type => User)\n @Field(type => User, { nullable: true })\n creator?: User\n\n @ManyToOne(type => User)\n @Field(type => User, { nullable: true })\n updater?: User\n\n /** 토큰 절감용 — 오래된 메시지를 LLM 으로 압축한 요약. Phase 2 에서 작성. */\n @Column({\n nullable: true,\n type:\n DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'\n ? 'longtext'\n : DATABASE_TYPE == 'oracle'\n ? 'clob'\n : DATABASE_TYPE == 'mssql'\n ? 'nvarchar'\n : 'text',\n length: DATABASE_TYPE == 'mssql' ? 'MAX' : undefined\n })\n @Field({ nullable: true, description: 'Compressed summary of older messages (for token saving).' })\n lastSummary?: string\n\n /** 사용 모델 식별 — 'anthropic:claude-sonnet-4-6' 등 */\n @Column({ nullable: true })\n @Field({ nullable: true })\n aiClientId?: string\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt?: Date\n\n @DeleteDateColumn()\n deletedAt?: Date\n\n // ── 관계 (TypeORM 만, GraphQL 노출은 별도 query 통해 페이징) ──\n @OneToMany(type => ChatMessage, message => message.session)\n messages?: ChatMessage[]\n\n @OneToMany(type => PatchEntry, patch => patch.session)\n patches?: PatchEntry[]\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entities = exports.ChatSession = void 0;
|
|
4
|
+
const chat_session_js_1 = require("./chat-session.js");
|
|
5
|
+
Object.defineProperty(exports, "ChatSession", { enumerable: true, get: function () { return chat_session_js_1.ChatSession; } });
|
|
6
|
+
exports.entities = [chat_session_js_1.ChatSession];
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/chat-session/index.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAEtC,4FAFA,6BAAW,OAEA;AAEP,QAAA,QAAQ,GAAG,CAAC,6BAAW,CAAC,CAAA","sourcesContent":["import { ChatSession } from './chat-session.js'\n\nexport { ChatSession }\n\nexport const entities = [ChatSession]\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@things-factory/auth-base';
|
|
2
|
+
import { ChatSession } from './chat-session/chat-session.js';
|
|
3
|
+
import { ChatMessage } from './chat-message/chat-message.js';
|
|
4
|
+
import { PatchEntry } from './patch-entry/patch-entry.js';
|
|
5
|
+
export declare class ChatSessionResolver {
|
|
6
|
+
chatSession(id: string, context: ResolverContext): Promise<ChatSession | null>;
|
|
7
|
+
chatSessionByBoard(boardId: string, context: ResolverContext): Promise<ChatSession | null>;
|
|
8
|
+
chatMessages(sessionId: string, limit: number, offset: number, context: ResolverContext): Promise<ChatMessage[]>;
|
|
9
|
+
chatPatches(sessionId: string, limit: number, context: ResolverContext): Promise<PatchEntry[]>;
|
|
10
|
+
startBoardAISession(boardId: string, context: ResolverContext): Promise<ChatSession>;
|
|
11
|
+
recordDirectPatch(sessionId: string, ops: any[], summary: string | undefined, context: ResolverContext): Promise<PatchEntry>;
|
|
12
|
+
revertPatch(patchId: string, context: ResolverContext): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatSessionResolver = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* ChatSession lifecycle resolver — start/get/recordDirectPatch/revertPatch + 메시지·패치 페이징 query.
|
|
7
|
+
*
|
|
8
|
+
* 핵심: `recordDirectPatch` — 사용자가 모델러에서 직접 편집 시 클라이언트가 호출.
|
|
9
|
+
* 이게 PatchEntry(source:'user-direct') + system 메시지 자동 추가 → AI 가 모든 변경을 인지.
|
|
10
|
+
*/
|
|
11
|
+
const type_graphql_1 = require("type-graphql");
|
|
12
|
+
const graphql_scalars_1 = require("graphql-scalars");
|
|
13
|
+
require("@things-factory/auth-base");
|
|
14
|
+
const shell_1 = require("@things-factory/shell");
|
|
15
|
+
const chat_session_js_1 = require("./chat-session/chat-session.js");
|
|
16
|
+
const chat_message_js_1 = require("./chat-message/chat-message.js");
|
|
17
|
+
const patch_entry_js_1 = require("./patch-entry/patch-entry.js");
|
|
18
|
+
let ChatSessionResolver = class ChatSessionResolver {
|
|
19
|
+
async chatSession(id, context) {
|
|
20
|
+
const { domain } = context.state;
|
|
21
|
+
return (await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id, domain: { id: domain.id } })) ?? null;
|
|
22
|
+
}
|
|
23
|
+
async chatSessionByBoard(boardId, context) {
|
|
24
|
+
const { domain } = context.state;
|
|
25
|
+
return ((await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ boardId, domain: { id: domain.id } })) ?? null);
|
|
26
|
+
}
|
|
27
|
+
async chatMessages(sessionId, limit, offset, context) {
|
|
28
|
+
const { domain } = context.state;
|
|
29
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({
|
|
30
|
+
id: sessionId,
|
|
31
|
+
domain: { id: domain.id }
|
|
32
|
+
});
|
|
33
|
+
if (!session)
|
|
34
|
+
return [];
|
|
35
|
+
return await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage).find({
|
|
36
|
+
where: { session: { id: sessionId } },
|
|
37
|
+
order: { createdAt: 'ASC' },
|
|
38
|
+
take: limit,
|
|
39
|
+
skip: offset
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async chatPatches(sessionId, limit, context) {
|
|
43
|
+
const { domain } = context.state;
|
|
44
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({
|
|
45
|
+
id: sessionId,
|
|
46
|
+
domain: { id: domain.id }
|
|
47
|
+
});
|
|
48
|
+
if (!session)
|
|
49
|
+
return [];
|
|
50
|
+
return await (0, shell_1.getRepository)(patch_entry_js_1.PatchEntry).find({
|
|
51
|
+
where: { session: { id: sessionId } },
|
|
52
|
+
order: { createdAt: 'DESC' },
|
|
53
|
+
take: limit
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async startBoardAISession(boardId, context) {
|
|
57
|
+
const { domain, user, tx } = context.state;
|
|
58
|
+
const repo = (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx);
|
|
59
|
+
const existing = await repo.findOneBy({ boardId, domain: { id: domain.id } });
|
|
60
|
+
if (existing)
|
|
61
|
+
return existing;
|
|
62
|
+
return await repo.save({
|
|
63
|
+
domain,
|
|
64
|
+
boardId,
|
|
65
|
+
creator: user,
|
|
66
|
+
updater: user
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async recordDirectPatch(sessionId, ops, summary, context) {
|
|
70
|
+
const { domain, tx } = context.state;
|
|
71
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).findOneBy({
|
|
72
|
+
id: sessionId,
|
|
73
|
+
domain: { id: domain.id }
|
|
74
|
+
});
|
|
75
|
+
if (!session)
|
|
76
|
+
throw new Error(`ChatSession ${sessionId} not found`);
|
|
77
|
+
const entry = await (0, shell_1.getRepository)(patch_entry_js_1.PatchEntry, tx).save({
|
|
78
|
+
session: { id: session.id },
|
|
79
|
+
source: 'user-direct',
|
|
80
|
+
ops: JSON.stringify(ops || []),
|
|
81
|
+
summary,
|
|
82
|
+
reverted: false
|
|
83
|
+
});
|
|
84
|
+
// AI 컨텍스트 흐름 — system 메시지 자동 추가
|
|
85
|
+
await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).save({
|
|
86
|
+
session: { id: session.id },
|
|
87
|
+
role: 'system',
|
|
88
|
+
content: `User directly edited the board: ${summary ?? `${(ops || []).length} op(s)`}`,
|
|
89
|
+
relatedPatchId: entry.id
|
|
90
|
+
});
|
|
91
|
+
return entry;
|
|
92
|
+
}
|
|
93
|
+
async revertPatch(patchId, context) {
|
|
94
|
+
const { tx } = context.state;
|
|
95
|
+
await (0, shell_1.getRepository)(patch_entry_js_1.PatchEntry, tx).update(patchId, { reverted: true });
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.ChatSessionResolver = ChatSessionResolver;
|
|
100
|
+
tslib_1.__decorate([
|
|
101
|
+
(0, type_graphql_1.Query)(() => chat_session_js_1.ChatSession, { nullable: true, description: 'Get AI chat session by id.' }),
|
|
102
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "query")'),
|
|
103
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
104
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
105
|
+
tslib_1.__metadata("design:type", Function),
|
|
106
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
107
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
108
|
+
], ChatSessionResolver.prototype, "chatSession", null);
|
|
109
|
+
tslib_1.__decorate([
|
|
110
|
+
(0, type_graphql_1.Query)(() => chat_session_js_1.ChatSession, { nullable: true, description: 'Get AI chat session by board id.' }),
|
|
111
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "query")'),
|
|
112
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('boardId')),
|
|
113
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
114
|
+
tslib_1.__metadata("design:type", Function),
|
|
115
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
116
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
117
|
+
], ChatSessionResolver.prototype, "chatSessionByBoard", null);
|
|
118
|
+
tslib_1.__decorate([
|
|
119
|
+
(0, type_graphql_1.Query)(() => [chat_message_js_1.ChatMessage], { description: 'List chat messages of a session, oldest first.' }),
|
|
120
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "query")'),
|
|
121
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
122
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('limit', () => type_graphql_1.Int, { nullable: true, defaultValue: 100 })),
|
|
123
|
+
tslib_1.__param(2, (0, type_graphql_1.Arg)('offset', () => type_graphql_1.Int, { nullable: true, defaultValue: 0 })),
|
|
124
|
+
tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
|
|
125
|
+
tslib_1.__metadata("design:type", Function),
|
|
126
|
+
tslib_1.__metadata("design:paramtypes", [String, Number, Number, Object]),
|
|
127
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
128
|
+
], ChatSessionResolver.prototype, "chatMessages", null);
|
|
129
|
+
tslib_1.__decorate([
|
|
130
|
+
(0, type_graphql_1.Query)(() => [patch_entry_js_1.PatchEntry], { description: 'List patch entries of a session, newest first.' }),
|
|
131
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "query")'),
|
|
132
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
133
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('limit', () => type_graphql_1.Int, { nullable: true, defaultValue: 100 })),
|
|
134
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
135
|
+
tslib_1.__metadata("design:type", Function),
|
|
136
|
+
tslib_1.__metadata("design:paramtypes", [String, Number, Object]),
|
|
137
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
138
|
+
], ChatSessionResolver.prototype, "chatPatches", null);
|
|
139
|
+
tslib_1.__decorate([
|
|
140
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
141
|
+
(0, type_graphql_1.Mutation)(() => chat_session_js_1.ChatSession, {
|
|
142
|
+
description: 'Start (or get existing) AI chat session for a board. Idempotent.'
|
|
143
|
+
}),
|
|
144
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "mutation")'),
|
|
145
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('boardId')),
|
|
146
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
147
|
+
tslib_1.__metadata("design:type", Function),
|
|
148
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
149
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
150
|
+
], ChatSessionResolver.prototype, "startBoardAISession", null);
|
|
151
|
+
tslib_1.__decorate([
|
|
152
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
153
|
+
(0, type_graphql_1.Mutation)(() => patch_entry_js_1.PatchEntry, {
|
|
154
|
+
description: 'Record a patch from user direct edit. Adds a system message so AI sees the change next turn.'
|
|
155
|
+
}),
|
|
156
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "mutation")'),
|
|
157
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
158
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('ops', () => graphql_scalars_1.GraphQLJSON)),
|
|
159
|
+
tslib_1.__param(2, (0, type_graphql_1.Arg)('summary', { nullable: true })),
|
|
160
|
+
tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
|
|
161
|
+
tslib_1.__metadata("design:type", Function),
|
|
162
|
+
tslib_1.__metadata("design:paramtypes", [String, Array, String, Object]),
|
|
163
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
164
|
+
], ChatSessionResolver.prototype, "recordDirectPatch", null);
|
|
165
|
+
tslib_1.__decorate([
|
|
166
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
167
|
+
(0, type_graphql_1.Mutation)(() => Boolean, { description: 'Mark a patch as reverted (does not undo, only flags).' }),
|
|
168
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board-ai", privilege: "mutation")'),
|
|
169
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('patchId')),
|
|
170
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
171
|
+
tslib_1.__metadata("design:type", Function),
|
|
172
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
173
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
174
|
+
], ChatSessionResolver.prototype, "revertPatch", null);
|
|
175
|
+
exports.ChatSessionResolver = ChatSessionResolver = tslib_1.__decorate([
|
|
176
|
+
(0, type_graphql_1.Resolver)()
|
|
177
|
+
], ChatSessionResolver);
|
|
178
|
+
//# sourceMappingURL=chat-session-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-session-resolver.js","sourceRoot":"","sources":["../../server/service/chat-session-resolver.ts"],"names":[],"mappings":";;;;AAAA;;;;;GAKG;AACH,+CAAkF;AAClF,qDAA6C;AAC7C,qCAAkC;AAElC,iDAAqD;AAErD,oEAA4D;AAC5D,oEAA4D;AAC5D,iEAAyD;AAGlD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAGxB,AAAN,KAAK,CAAC,WAAW,CACJ,EAAU,EACd,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,OAAO,CAAC,MAAM,IAAA,qBAAa,EAAC,6BAAW,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAA;IAChG,CAAC;IAIK,AAAN,KAAK,CAAC,kBAAkB,CACN,OAAe,EACxB,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,OAAO,CACL,CAAC,MAAM,IAAA,qBAAa,EAAC,6BAAW,CAAC,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAC7F,CAAA;IACH,CAAC;IAIK,AAAN,KAAK,CAAC,YAAY,CACE,SAAiB,EAC6B,KAAa,EACd,MAAc,EACtE,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,MAAM,OAAO,GAAG,MAA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IAAA,wBAAS,EAAC,yDAAyD,CAAC;IAElE,mBAAA,IAAA,kBAAG,EAAC,WAAW,CAAC,CAAA;IAChB,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,GAAG,EAAE,CAAC,6BAAW,CAAC,CAAA;IAC7B,mBAAA,IAAA,kBAAG,EAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAClC,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;4DA0BP;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,uDAAuD,EAAE,CAAC;IACjG,IAAA,wBAAS,EAAC,yDAAyD,CAAC;IAElE,mBAAA,IAAA,kBAAG,EAAC,SAAS,CAAC,CAAA;IACd,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;sDAKP;8BAvIU,mBAAmB;IAD/B,IAAA,uBAAQ,GAAE;GACE,mBAAmB,CAwI/B","sourcesContent":["/**\n * ChatSession lifecycle resolver — start/get/recordDirectPatch/revertPatch + 메시지·패치 페이징 query.\n *\n * 핵심: `recordDirectPatch` — 사용자가 모델러에서 직접 편집 시 클라이언트가 호출.\n * 이게 PatchEntry(source:'user-direct') + system 메시지 자동 추가 → AI 가 모든 변경을 인지.\n */\nimport { Resolver, Query, Mutation, Arg, Ctx, Directive, Int } from 'type-graphql'\nimport { GraphQLJSON } from 'graphql-scalars'\nimport '@things-factory/auth-base'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { ChatSession } from './chat-session/chat-session.js'\nimport { ChatMessage } from './chat-message/chat-message.js'\nimport { PatchEntry } from './patch-entry/patch-entry.js'\n\n@Resolver()\nexport class ChatSessionResolver {\n @Query(() => ChatSession, { nullable: true, description: 'Get AI chat session by id.' })\n @Directive('@privilege(category: \"board-ai\", privilege: \"query\")')\n async chatSession(\n @Arg('id') id: string,\n @Ctx() context: ResolverContext\n ): Promise<ChatSession | null> {\n const { domain } = context.state\n return (await getRepository(ChatSession).findOneBy({ id, domain: { id: domain.id } })) ?? null\n }\n\n @Query(() => ChatSession, { nullable: true, description: 'Get AI chat session by board id.' })\n @Directive('@privilege(category: \"board-ai\", privilege: \"query\")')\n async chatSessionByBoard(\n @Arg('boardId') boardId: string,\n @Ctx() context: ResolverContext\n ): Promise<ChatSession | null> {\n const { domain } = context.state\n return (\n (await getRepository(ChatSession).findOneBy({ boardId, domain: { id: domain.id } })) ?? null\n )\n }\n\n @Query(() => [ChatMessage], { description: 'List chat messages of a session, oldest first.' })\n @Directive('@privilege(category: \"board-ai\", privilege: \"query\")')\n async chatMessages(\n @Arg('sessionId') sessionId: string,\n @Arg('limit', () => Int, { nullable: true, defaultValue: 100 }) limit: number,\n @Arg('offset', () => Int, { nullable: true, defaultValue: 0 }) offset: number,\n @Ctx() context: ResolverContext\n ): Promise<ChatMessage[]> {\n const { domain } = context.state\n const session = await getRepository(ChatSession).findOneBy({\n id: sessionId,\n domain: { id: domain.id }\n })\n if (!session) return []\n return await getRepository(ChatMessage).find({\n where: { session: { id: sessionId } as any },\n order: { createdAt: 'ASC' },\n take: limit,\n skip: offset\n })\n }\n\n @Query(() => [PatchEntry], { description: 'List patch entries of a session, newest first.' })\n @Directive('@privilege(category: \"board-ai\", privilege: \"query\")')\n async chatPatches(\n @Arg('sessionId') sessionId: string,\n @Arg('limit', () => Int, { nullable: true, defaultValue: 100 }) limit: number,\n @Ctx() context: ResolverContext\n ): Promise<PatchEntry[]> {\n const { domain } = context.state\n const session = await getRepository(ChatSession).findOneBy({\n id: sessionId,\n domain: { id: domain.id }\n })\n if (!session) return []\n return await getRepository(PatchEntry).find({\n where: { session: { id: sessionId } as any },\n order: { createdAt: 'DESC' },\n take: limit\n })\n }\n\n @Directive('@transaction')\n @Mutation(() => ChatSession, {\n description: 'Start (or get existing) AI chat session for a board. Idempotent.'\n })\n @Directive('@privilege(category: \"board-ai\", privilege: \"mutation\")')\n async startBoardAISession(\n @Arg('boardId') boardId: string,\n @Ctx() context: ResolverContext\n ): Promise<ChatSession> {\n const { domain, user, tx } = context.state\n const repo = getRepository(ChatSession, tx)\n\n const existing = await repo.findOneBy({ boardId, domain: { id: domain.id } })\n if (existing) return existing\n\n return await repo.save({\n domain,\n boardId,\n creator: user,\n updater: user\n } as any)\n }\n\n @Directive('@transaction')\n @Mutation(() => PatchEntry, {\n description: 'Record a patch from user direct edit. Adds a system message so AI sees the change next turn.'\n })\n @Directive('@privilege(category: \"board-ai\", privilege: \"mutation\")')\n async recordDirectPatch(\n @Arg('sessionId') sessionId: string,\n @Arg('ops', () => GraphQLJSON) ops: any[],\n @Arg('summary', { nullable: true }) summary: string | undefined,\n @Ctx() context: ResolverContext\n ): Promise<PatchEntry> {\n const { domain, tx } = context.state\n const session = await getRepository(ChatSession, tx).findOneBy({\n id: sessionId,\n domain: { id: domain.id }\n })\n if (!session) throw new Error(`ChatSession ${sessionId} not found`)\n\n const entry = await getRepository(PatchEntry, tx).save({\n session: { id: session.id } as any,\n source: 'user-direct',\n ops: JSON.stringify(ops || []),\n summary,\n reverted: false\n } as any)\n\n // AI 컨텍스트 흐름 — system 메시지 자동 추가\n await getRepository(ChatMessage, tx).save({\n session: { id: session.id } as any,\n role: 'system',\n content: `User directly edited the board: ${summary ?? `${(ops || []).length} op(s)`}`,\n relatedPatchId: entry.id\n } as any)\n\n return entry\n }\n\n @Directive('@transaction')\n @Mutation(() => Boolean, { description: 'Mark a patch as reverted (does not undo, only flags).' })\n @Directive('@privilege(category: \"board-ai\", privilege: \"mutation\")')\n async revertPatch(\n @Arg('patchId') patchId: string,\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { tx } = context.state\n await getRepository(PatchEntry, tx).update(patchId, { reverted: true })\n return true\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BoardAIChatResolver } from './board-ai-resolver.js';
|
|
2
|
+
import { ChatSessionResolver } from './chat-session-resolver.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './assistant.js';
|
|
5
|
+
export * from './apply-patch.js';
|
|
6
|
+
export * from './board-ai-resolver.js';
|
|
7
|
+
export * from './chat-session-resolver.js';
|
|
8
|
+
export * from './chat-session/index.js';
|
|
9
|
+
export * from './chat-message/index.js';
|
|
10
|
+
export * from './patch-entry/index.js';
|
|
11
|
+
export declare const entities: (typeof import("./chat-message/chat-message.js").ChatMessage | typeof import("./chat-session/chat-session.js").ChatSession | typeof import("./patch-entry/patch-entry.js").PatchEntry)[];
|
|
12
|
+
export declare const schema: {
|
|
13
|
+
resolverClasses: (typeof BoardAIChatResolver | typeof ChatSessionResolver)[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = exports.entities = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const board_ai_resolver_js_1 = require("./board-ai-resolver.js");
|
|
6
|
+
const chat_session_resolver_js_1 = require("./chat-session-resolver.js");
|
|
7
|
+
const index_js_1 = require("./chat-session/index.js");
|
|
8
|
+
const index_js_2 = require("./chat-message/index.js");
|
|
9
|
+
const index_js_3 = require("./patch-entry/index.js");
|
|
10
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./assistant.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./apply-patch.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./board-ai-resolver.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./chat-session-resolver.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./chat-session/index.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./chat-message/index.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./patch-entry/index.js"), exports);
|
|
18
|
+
exports.entities = [
|
|
19
|
+
...index_js_1.entities,
|
|
20
|
+
...index_js_2.entities,
|
|
21
|
+
...index_js_3.entities
|
|
22
|
+
];
|
|
23
|
+
exports.schema = {
|
|
24
|
+
resolverClasses: [board_ai_resolver_js_1.BoardAIChatResolver, chat_session_resolver_js_1.ChatSessionResolver]
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,iEAA4D;AAC5D,yEAAgE;AAChE,sDAAyE;AACzE,sDAAyE;AACzE,qDAAuE;AAEvE,qDAA0B;AAC1B,yDAA8B;AAC9B,2DAAgC;AAChC,iEAAsC;AACtC,qEAA0C;AAC1C,kEAAuC;AACvC,kEAAuC;AACvC,iEAAsC;AAEzB,QAAA,QAAQ,GAAG;IACtB,GAAG,mBAAmB;IACtB,GAAG,mBAAmB;IACtB,GAAG,mBAAkB;CACtB,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE,CAAC,0CAAmB,EAAE,8CAAmB,CAAC;CAC5D,CAAA","sourcesContent":["import { BoardAIChatResolver } from './board-ai-resolver.js'\nimport { ChatSessionResolver } from './chat-session-resolver.js'\nimport { entities as ChatSessionEntities } from './chat-session/index.js'\nimport { entities as ChatMessageEntities } from './chat-message/index.js'\nimport { entities as PatchEntryEntities } from './patch-entry/index.js'\n\nexport * from './types.js'\nexport * from './assistant.js'\nexport * from './apply-patch.js'\nexport * from './board-ai-resolver.js'\nexport * from './chat-session-resolver.js'\nexport * from './chat-session/index.js'\nexport * from './chat-message/index.js'\nexport * from './patch-entry/index.js'\n\nexport const entities = [\n ...ChatSessionEntities,\n ...ChatMessageEntities,\n ...PatchEntryEntities\n]\n\nexport const schema = {\n resolverClasses: [BoardAIChatResolver, ChatSessionResolver]\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entities = exports.PatchEntry = void 0;
|
|
4
|
+
const patch_entry_js_1 = require("./patch-entry.js");
|
|
5
|
+
Object.defineProperty(exports, "PatchEntry", { enumerable: true, get: function () { return patch_entry_js_1.PatchEntry; } });
|
|
6
|
+
exports.entities = [patch_entry_js_1.PatchEntry];
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/patch-entry/index.ts"],"names":[],"mappings":";;;AAAA,qDAA6C;AAEpC,2FAFA,2BAAU,OAEA;AAEN,QAAA,QAAQ,GAAG,CAAC,2BAAU,CAAC,CAAA","sourcesContent":["import { PatchEntry } from './patch-entry.js'\n\nexport { PatchEntry }\n\nexport const entities = [PatchEntry]\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChatSession } from '../chat-session/chat-session.js';
|
|
2
|
+
export declare class PatchEntry {
|
|
3
|
+
readonly id?: string;
|
|
4
|
+
session?: ChatSession;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
/** 'ai' | 'user-direct' | 'import' */
|
|
7
|
+
source: string;
|
|
8
|
+
/** BoardEditOp[] JSON-stringified — column 으로는 long text. */
|
|
9
|
+
ops: string;
|
|
10
|
+
/** GraphQL 노출용 — JSON 객체로 변환. */
|
|
11
|
+
get opsJson(): any;
|
|
12
|
+
summary?: string;
|
|
13
|
+
confidence?: number;
|
|
14
|
+
reverted: boolean;
|
|
15
|
+
createdAt?: Date;
|
|
16
|
+
}
|