@orthacms/copilot-server 0.0.0-reserve.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.
Files changed (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/index.d.ts +24 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +48 -0
  6. package/dist/lib/chat/application/appliers-registrar.d.ts +16 -0
  7. package/dist/lib/chat/application/appliers-registrar.d.ts.map +1 -0
  8. package/dist/lib/chat/application/appliers-registrar.js +50 -0
  9. package/dist/lib/chat/application/capability-profile.service.d.ts +43 -0
  10. package/dist/lib/chat/application/capability-profile.service.d.ts.map +1 -0
  11. package/dist/lib/chat/application/capability-profile.service.js +75 -0
  12. package/dist/lib/chat/application/content-type-summary.service.d.ts +32 -0
  13. package/dist/lib/chat/application/content-type-summary.service.d.ts.map +1 -0
  14. package/dist/lib/chat/application/content-type-summary.service.js +64 -0
  15. package/dist/lib/chat/application/decide-proposal.service.d.ts +80 -0
  16. package/dist/lib/chat/application/decide-proposal.service.d.ts.map +1 -0
  17. package/dist/lib/chat/application/decide-proposal.service.js +112 -0
  18. package/dist/lib/chat/application/dto/create-run.dto.d.ts +138 -0
  19. package/dist/lib/chat/application/dto/create-run.dto.d.ts.map +1 -0
  20. package/dist/lib/chat/application/dto/create-run.dto.js +253 -0
  21. package/dist/lib/chat/application/dto/decide-tool-permission.dto.d.ts +20 -0
  22. package/dist/lib/chat/application/dto/decide-tool-permission.dto.d.ts.map +1 -0
  23. package/dist/lib/chat/application/dto/decide-tool-permission.dto.js +44 -0
  24. package/dist/lib/chat/application/dto/extend-tool-permission.dto.d.ts +18 -0
  25. package/dist/lib/chat/application/dto/extend-tool-permission.dto.d.ts.map +1 -0
  26. package/dist/lib/chat/application/dto/extend-tool-permission.dto.js +33 -0
  27. package/dist/lib/chat/application/dto/list-conversations-query.dto.d.ts +18 -0
  28. package/dist/lib/chat/application/dto/list-conversations-query.dto.d.ts.map +1 -0
  29. package/dist/lib/chat/application/dto/list-conversations-query.dto.js +39 -0
  30. package/dist/lib/chat/application/dto/list-proposals-query.dto.d.ts +15 -0
  31. package/dist/lib/chat/application/dto/list-proposals-query.dto.d.ts.map +1 -0
  32. package/dist/lib/chat/application/dto/list-proposals-query.dto.js +41 -0
  33. package/dist/lib/chat/application/dto/update-conversation.dto.d.ts +68 -0
  34. package/dist/lib/chat/application/dto/update-conversation.dto.d.ts.map +1 -0
  35. package/dist/lib/chat/application/dto/update-conversation.dto.js +115 -0
  36. package/dist/lib/chat/application/proposal-applier.registry.d.ts +27 -0
  37. package/dist/lib/chat/application/proposal-applier.registry.d.ts.map +1 -0
  38. package/dist/lib/chat/application/proposal-applier.registry.js +62 -0
  39. package/dist/lib/chat/application/run-engine.service.d.ts +243 -0
  40. package/dist/lib/chat/application/run-engine.service.d.ts.map +1 -0
  41. package/dist/lib/chat/application/run-engine.service.js +1058 -0
  42. package/dist/lib/chat/application/summarize-tool-output.d.ts +15 -0
  43. package/dist/lib/chat/application/summarize-tool-output.d.ts.map +1 -0
  44. package/dist/lib/chat/application/summarize-tool-output.js +61 -0
  45. package/dist/lib/chat/application/system-prompt.d.ts +81 -0
  46. package/dist/lib/chat/application/system-prompt.d.ts.map +1 -0
  47. package/dist/lib/chat/application/system-prompt.js +477 -0
  48. package/dist/lib/chat/application/tool-permission.broker.d.ts +118 -0
  49. package/dist/lib/chat/application/tool-permission.broker.d.ts.map +1 -0
  50. package/dist/lib/chat/application/tool-permission.broker.js +221 -0
  51. package/dist/lib/chat/http/controllers/create-run.controller.d.ts +30 -0
  52. package/dist/lib/chat/http/controllers/create-run.controller.d.ts.map +1 -0
  53. package/dist/lib/chat/http/controllers/create-run.controller.js +159 -0
  54. package/dist/lib/chat/http/controllers/get-conversation.controller.d.ts +22 -0
  55. package/dist/lib/chat/http/controllers/get-conversation.controller.d.ts.map +1 -0
  56. package/dist/lib/chat/http/controllers/get-conversation.controller.js +50 -0
  57. package/dist/lib/chat/http/controllers/list-conversations.controller.d.ts +20 -0
  58. package/dist/lib/chat/http/controllers/list-conversations.controller.d.ts.map +1 -0
  59. package/dist/lib/chat/http/controllers/list-conversations.controller.js +47 -0
  60. package/dist/lib/chat/http/controllers/list-models.controller.d.ts +35 -0
  61. package/dist/lib/chat/http/controllers/list-models.controller.d.ts.map +1 -0
  62. package/dist/lib/chat/http/controllers/list-models.controller.js +48 -0
  63. package/dist/lib/chat/http/controllers/proposals.controller.d.ts +43 -0
  64. package/dist/lib/chat/http/controllers/proposals.controller.d.ts.map +1 -0
  65. package/dist/lib/chat/http/controllers/proposals.controller.js +98 -0
  66. package/dist/lib/chat/http/controllers/tool-permission.controller.d.ts +57 -0
  67. package/dist/lib/chat/http/controllers/tool-permission.controller.d.ts.map +1 -0
  68. package/dist/lib/chat/http/controllers/tool-permission.controller.js +116 -0
  69. package/dist/lib/chat/http/controllers/update-conversation.controller.d.ts +37 -0
  70. package/dist/lib/chat/http/controllers/update-conversation.controller.d.ts.map +1 -0
  71. package/dist/lib/chat/http/controllers/update-conversation.controller.js +108 -0
  72. package/dist/lib/chat/http/sse-stream.d.ts +41 -0
  73. package/dist/lib/chat/http/sse-stream.d.ts.map +1 -0
  74. package/dist/lib/chat/http/sse-stream.js +95 -0
  75. package/dist/lib/chat/infrastructure/persistence/conversation.repository.d.ts +159 -0
  76. package/dist/lib/chat/infrastructure/persistence/conversation.repository.d.ts.map +1 -0
  77. package/dist/lib/chat/infrastructure/persistence/conversation.repository.js +249 -0
  78. package/dist/lib/chat/infrastructure/persistence/derive-title.d.ts +13 -0
  79. package/dist/lib/chat/infrastructure/persistence/derive-title.d.ts.map +1 -0
  80. package/dist/lib/chat/infrastructure/persistence/derive-title.js +35 -0
  81. package/dist/lib/chat/infrastructure/persistence/proposal.repository.d.ts +86 -0
  82. package/dist/lib/chat/infrastructure/persistence/proposal.repository.d.ts.map +1 -0
  83. package/dist/lib/chat/infrastructure/persistence/proposal.repository.js +152 -0
  84. package/dist/lib/chat/infrastructure/schema/conversations.d.ts +189 -0
  85. package/dist/lib/chat/infrastructure/schema/conversations.d.ts.map +1 -0
  86. package/dist/lib/chat/infrastructure/schema/conversations.js +100 -0
  87. package/dist/lib/chat/infrastructure/schema/external-refs.d.ts +67 -0
  88. package/dist/lib/chat/infrastructure/schema/external-refs.d.ts.map +1 -0
  89. package/dist/lib/chat/infrastructure/schema/external-refs.js +28 -0
  90. package/dist/lib/chat/infrastructure/schema/index.d.ts +5 -0
  91. package/dist/lib/chat/infrastructure/schema/index.d.ts.map +1 -0
  92. package/dist/lib/chat/infrastructure/schema/index.js +12 -0
  93. package/dist/lib/chat/infrastructure/schema/messages.d.ts +264 -0
  94. package/dist/lib/chat/infrastructure/schema/messages.d.ts.map +1 -0
  95. package/dist/lib/chat/infrastructure/schema/messages.js +96 -0
  96. package/dist/lib/chat/infrastructure/schema/proposals.d.ts +328 -0
  97. package/dist/lib/chat/infrastructure/schema/proposals.d.ts.map +1 -0
  98. package/dist/lib/chat/infrastructure/schema/proposals.js +87 -0
  99. package/dist/lib/chat/infrastructure/schema/tool-calls.d.ts +203 -0
  100. package/dist/lib/chat/infrastructure/schema/tool-calls.d.ts.map +1 -0
  101. package/dist/lib/chat/infrastructure/schema/tool-calls.js +50 -0
  102. package/dist/lib/copilot.module.d.ts +30 -0
  103. package/dist/lib/copilot.module.d.ts.map +1 -0
  104. package/dist/lib/copilot.module.js +146 -0
  105. package/dist/lib/copilot.tokens.d.ts +34 -0
  106. package/dist/lib/copilot.tokens.d.ts.map +1 -0
  107. package/dist/lib/copilot.tokens.js +38 -0
  108. package/dist/lib/infrastructure/model-registry.d.ts +22 -0
  109. package/dist/lib/infrastructure/model-registry.d.ts.map +1 -0
  110. package/dist/lib/infrastructure/model-registry.js +54 -0
  111. package/dist/lib/skills/application/dto/create-skill.dto.d.ts +36 -0
  112. package/dist/lib/skills/application/dto/create-skill.dto.d.ts.map +1 -0
  113. package/dist/lib/skills/application/dto/create-skill.dto.js +106 -0
  114. package/dist/lib/skills/application/dto/update-skill.dto.d.ts +28 -0
  115. package/dist/lib/skills/application/dto/update-skill.dto.d.ts.map +1 -0
  116. package/dist/lib/skills/application/dto/update-skill.dto.js +96 -0
  117. package/dist/lib/skills/application/skill-catalog.service.d.ts +97 -0
  118. package/dist/lib/skills/application/skill-catalog.service.d.ts.map +1 -0
  119. package/dist/lib/skills/application/skill-catalog.service.js +157 -0
  120. package/dist/lib/skills/http/controllers/list-skills.controller.d.ts +19 -0
  121. package/dist/lib/skills/http/controllers/list-skills.controller.d.ts.map +1 -0
  122. package/dist/lib/skills/http/controllers/list-skills.controller.js +50 -0
  123. package/dist/lib/skills/http/controllers/manage-skills.controller.d.ts +64 -0
  124. package/dist/lib/skills/http/controllers/manage-skills.controller.d.ts.map +1 -0
  125. package/dist/lib/skills/http/controllers/manage-skills.controller.js +182 -0
  126. package/dist/lib/skills/infrastructure/persistence/skill.repository.d.ts +78 -0
  127. package/dist/lib/skills/infrastructure/persistence/skill.repository.d.ts.map +1 -0
  128. package/dist/lib/skills/infrastructure/persistence/skill.repository.js +116 -0
  129. package/dist/lib/skills/infrastructure/schema/index.d.ts +2 -0
  130. package/dist/lib/skills/infrastructure/schema/index.d.ts.map +1 -0
  131. package/dist/lib/skills/infrastructure/schema/index.js +6 -0
  132. package/dist/lib/skills/infrastructure/schema/skills.d.ts +212 -0
  133. package/dist/lib/skills/infrastructure/schema/skills.d.ts.map +1 -0
  134. package/dist/lib/skills/infrastructure/schema/skills.js +78 -0
  135. package/dist/lib/types/copilot-config.d.ts +55 -0
  136. package/dist/lib/types/copilot-config.d.ts.map +1 -0
  137. package/dist/lib/types/copilot-config.js +2 -0
  138. package/dist/lib/utils/copilot-plugin.d.ts +66 -0
  139. package/dist/lib/utils/copilot-plugin.d.ts.map +1 -0
  140. package/dist/lib/utils/copilot-plugin.js +87 -0
  141. package/migrations/0000_copilot_chat.sql +48 -0
  142. package/migrations/0001_proposals.sql +34 -0
  143. package/migrations/0002_drop_workspace_policies.sql +1 -0
  144. package/migrations/0003_conversation_allowed_tools.sql +1 -0
  145. package/migrations/0004_message_attachments.sql +1 -0
  146. package/migrations/0005_skills.sql +19 -0
  147. package/migrations/0006_conversation_model_choice.sql +1 -0
  148. package/migrations/meta/0000_snapshot.json +390 -0
  149. package/migrations/meta/0001_snapshot.json +657 -0
  150. package/migrations/meta/0002_snapshot.json +610 -0
  151. package/migrations/meta/0003_snapshot.json +617 -0
  152. package/migrations/meta/0004_snapshot.json +623 -0
  153. package/migrations/meta/0005_snapshot.json +771 -0
  154. package/migrations/meta/0006_snapshot.json +777 -0
  155. package/migrations/meta/_journal.json +55 -0
  156. package/package.json +46 -0
@@ -0,0 +1,264 @@
1
+ import type { AttachmentRef, ModelContentBlock, SkillRef } from '@orthacms/copilot-domain';
2
+ /** Who produced a turn. Mirrors the port's `ModelMessage['role']`. */
3
+ export declare const copilotMessageRole: import("drizzle-orm/pg-core").PgEnum<["user", "assistant"]>;
4
+ /**
5
+ * One turn of a conversation — **append-only**. This is the transcript used for
6
+ * replay and audit, so a row is never edited after it is written: a turn that
7
+ * failed keeps its `stopReason`, and a turn that was cancelled keeps whatever
8
+ * text had streamed. Rewriting history here would defeat the point of having it.
9
+ *
10
+ * The user's message is written **before** the model is called (design §5, step
11
+ * 3), so a dropped connection never loses what someone typed.
12
+ */
13
+ export declare const copilotMessages: import("drizzle-orm/pg-core").PgTableWithColumns<{
14
+ name: "copilot_messages";
15
+ schema: undefined;
16
+ columns: {
17
+ id: import("drizzle-orm/pg-core").PgColumn<{
18
+ name: "id";
19
+ tableName: "copilot_messages";
20
+ dataType: "string";
21
+ columnType: "PgUUID";
22
+ data: string;
23
+ driverParam: string;
24
+ notNull: true;
25
+ hasDefault: true;
26
+ isPrimaryKey: true;
27
+ isAutoincrement: false;
28
+ hasRuntimeDefault: false;
29
+ enumValues: undefined;
30
+ baseColumn: never;
31
+ identity: undefined;
32
+ generated: undefined;
33
+ }, {}, {}>;
34
+ conversationId: import("drizzle-orm/pg-core").PgColumn<{
35
+ name: "conversation_id";
36
+ tableName: "copilot_messages";
37
+ dataType: "string";
38
+ columnType: "PgUUID";
39
+ data: string;
40
+ driverParam: string;
41
+ notNull: true;
42
+ hasDefault: false;
43
+ isPrimaryKey: false;
44
+ isAutoincrement: false;
45
+ hasRuntimeDefault: false;
46
+ enumValues: undefined;
47
+ baseColumn: never;
48
+ identity: undefined;
49
+ generated: undefined;
50
+ }, {}, {}>;
51
+ runId: import("drizzle-orm/pg-core").PgColumn<{
52
+ name: "run_id";
53
+ tableName: "copilot_messages";
54
+ dataType: "string";
55
+ columnType: "PgUUID";
56
+ data: string;
57
+ driverParam: string;
58
+ notNull: true;
59
+ hasDefault: false;
60
+ isPrimaryKey: false;
61
+ isAutoincrement: false;
62
+ hasRuntimeDefault: false;
63
+ enumValues: undefined;
64
+ baseColumn: never;
65
+ identity: undefined;
66
+ generated: undefined;
67
+ }, {}, {}>;
68
+ role: import("drizzle-orm/pg-core").PgColumn<{
69
+ name: "role";
70
+ tableName: "copilot_messages";
71
+ dataType: "string";
72
+ columnType: "PgEnumColumn";
73
+ data: "user" | "assistant";
74
+ driverParam: string;
75
+ notNull: true;
76
+ hasDefault: false;
77
+ isPrimaryKey: false;
78
+ isAutoincrement: false;
79
+ hasRuntimeDefault: false;
80
+ enumValues: ["user", "assistant"];
81
+ baseColumn: never;
82
+ identity: undefined;
83
+ generated: undefined;
84
+ }, {}, {}>;
85
+ content: import("drizzle-orm/pg-core").PgColumn<{
86
+ name: "content";
87
+ tableName: "copilot_messages";
88
+ dataType: "json";
89
+ columnType: "PgJsonb";
90
+ data: ModelContentBlock[];
91
+ driverParam: unknown;
92
+ notNull: true;
93
+ hasDefault: false;
94
+ isPrimaryKey: false;
95
+ isAutoincrement: false;
96
+ hasRuntimeDefault: false;
97
+ enumValues: undefined;
98
+ baseColumn: never;
99
+ identity: undefined;
100
+ generated: undefined;
101
+ }, {}, {
102
+ $type: ModelContentBlock[];
103
+ }>;
104
+ attachments: import("drizzle-orm/pg-core").PgColumn<{
105
+ name: "attachments";
106
+ tableName: "copilot_messages";
107
+ dataType: "json";
108
+ columnType: "PgJsonb";
109
+ data: AttachmentRef[];
110
+ driverParam: unknown;
111
+ notNull: false;
112
+ hasDefault: false;
113
+ isPrimaryKey: false;
114
+ isAutoincrement: false;
115
+ hasRuntimeDefault: false;
116
+ enumValues: undefined;
117
+ baseColumn: never;
118
+ identity: undefined;
119
+ generated: undefined;
120
+ }, {}, {
121
+ $type: AttachmentRef[];
122
+ }>;
123
+ skills: import("drizzle-orm/pg-core").PgColumn<{
124
+ name: "skills";
125
+ tableName: "copilot_messages";
126
+ dataType: "json";
127
+ columnType: "PgJsonb";
128
+ data: SkillRef[];
129
+ driverParam: unknown;
130
+ notNull: false;
131
+ hasDefault: false;
132
+ isPrimaryKey: false;
133
+ isAutoincrement: false;
134
+ hasRuntimeDefault: false;
135
+ enumValues: undefined;
136
+ baseColumn: never;
137
+ identity: undefined;
138
+ generated: undefined;
139
+ }, {}, {
140
+ $type: SkillRef[];
141
+ }>;
142
+ model: import("drizzle-orm/pg-core").PgColumn<{
143
+ name: "model";
144
+ tableName: "copilot_messages";
145
+ dataType: "string";
146
+ columnType: "PgText";
147
+ data: string;
148
+ driverParam: string;
149
+ notNull: false;
150
+ hasDefault: false;
151
+ isPrimaryKey: false;
152
+ isAutoincrement: false;
153
+ hasRuntimeDefault: false;
154
+ enumValues: [string, ...string[]];
155
+ baseColumn: never;
156
+ identity: undefined;
157
+ generated: undefined;
158
+ }, {}, {}>;
159
+ provider: import("drizzle-orm/pg-core").PgColumn<{
160
+ name: "provider";
161
+ tableName: "copilot_messages";
162
+ dataType: "string";
163
+ columnType: "PgText";
164
+ data: string;
165
+ driverParam: string;
166
+ notNull: false;
167
+ hasDefault: false;
168
+ isPrimaryKey: false;
169
+ isAutoincrement: false;
170
+ hasRuntimeDefault: false;
171
+ enumValues: [string, ...string[]];
172
+ baseColumn: never;
173
+ identity: undefined;
174
+ generated: undefined;
175
+ }, {}, {}>;
176
+ stopReason: import("drizzle-orm/pg-core").PgColumn<{
177
+ name: "stop_reason";
178
+ tableName: "copilot_messages";
179
+ dataType: "string";
180
+ columnType: "PgText";
181
+ data: string;
182
+ driverParam: string;
183
+ notNull: false;
184
+ hasDefault: false;
185
+ isPrimaryKey: false;
186
+ isAutoincrement: false;
187
+ hasRuntimeDefault: false;
188
+ enumValues: [string, ...string[]];
189
+ baseColumn: never;
190
+ identity: undefined;
191
+ generated: undefined;
192
+ }, {}, {}>;
193
+ inputTokens: import("drizzle-orm/pg-core").PgColumn<{
194
+ name: "input_tokens";
195
+ tableName: "copilot_messages";
196
+ dataType: "number";
197
+ columnType: "PgInteger";
198
+ data: number;
199
+ driverParam: string | number;
200
+ notNull: false;
201
+ hasDefault: false;
202
+ isPrimaryKey: false;
203
+ isAutoincrement: false;
204
+ hasRuntimeDefault: false;
205
+ enumValues: undefined;
206
+ baseColumn: never;
207
+ identity: undefined;
208
+ generated: undefined;
209
+ }, {}, {}>;
210
+ outputTokens: import("drizzle-orm/pg-core").PgColumn<{
211
+ name: "output_tokens";
212
+ tableName: "copilot_messages";
213
+ dataType: "number";
214
+ columnType: "PgInteger";
215
+ data: number;
216
+ driverParam: string | number;
217
+ notNull: false;
218
+ hasDefault: false;
219
+ isPrimaryKey: false;
220
+ isAutoincrement: false;
221
+ hasRuntimeDefault: false;
222
+ enumValues: undefined;
223
+ baseColumn: never;
224
+ identity: undefined;
225
+ generated: undefined;
226
+ }, {}, {}>;
227
+ position: import("drizzle-orm/pg-core").PgColumn<{
228
+ name: "position";
229
+ tableName: "copilot_messages";
230
+ dataType: "number";
231
+ columnType: "PgInteger";
232
+ data: number;
233
+ driverParam: string | number;
234
+ notNull: true;
235
+ hasDefault: false;
236
+ isPrimaryKey: false;
237
+ isAutoincrement: false;
238
+ hasRuntimeDefault: false;
239
+ enumValues: undefined;
240
+ baseColumn: never;
241
+ identity: undefined;
242
+ generated: undefined;
243
+ }, {}, {}>;
244
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
245
+ name: "created_at";
246
+ tableName: "copilot_messages";
247
+ dataType: "date";
248
+ columnType: "PgTimestamp";
249
+ data: Date;
250
+ driverParam: string;
251
+ notNull: true;
252
+ hasDefault: true;
253
+ isPrimaryKey: false;
254
+ isAutoincrement: false;
255
+ hasRuntimeDefault: false;
256
+ enumValues: undefined;
257
+ baseColumn: never;
258
+ identity: undefined;
259
+ generated: undefined;
260
+ }, {}, {}>;
261
+ };
262
+ dialect: "pg";
263
+ }>;
264
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../../src/lib/chat/infrastructure/schema/messages.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACR,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACX,MAAM,0BAA0B,CAAC;AAGlC,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,6DAG7B,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmF3B,CAAC"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copilotMessages = exports.copilotMessageRole = void 0;
4
+ const pg_core_1 = require("drizzle-orm/pg-core");
5
+ const conversations_1 = require("./conversations");
6
+ /** Who produced a turn. Mirrors the port's `ModelMessage['role']`. */
7
+ exports.copilotMessageRole = (0, pg_core_1.pgEnum)('copilot_message_role', [
8
+ 'user',
9
+ 'assistant'
10
+ ]);
11
+ /**
12
+ * One turn of a conversation — **append-only**. This is the transcript used for
13
+ * replay and audit, so a row is never edited after it is written: a turn that
14
+ * failed keeps its `stopReason`, and a turn that was cancelled keeps whatever
15
+ * text had streamed. Rewriting history here would defeat the point of having it.
16
+ *
17
+ * The user's message is written **before** the model is called (design §5, step
18
+ * 3), so a dropped connection never loses what someone typed.
19
+ */
20
+ exports.copilotMessages = (0, pg_core_1.pgTable)('copilot_messages', {
21
+ /** Primary key. */
22
+ id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
23
+ /** The thread this turn belongs to. */
24
+ conversationId: (0, pg_core_1.uuid)('conversation_id')
25
+ .notNull()
26
+ .references(() => conversations_1.copilotConversations.id, { onDelete: 'cascade' }),
27
+ /**
28
+ * The run that produced this turn. The user message that opened the
29
+ * run carries the same id, so one run's turns select together.
30
+ */
31
+ runId: (0, pg_core_1.uuid)('run_id').notNull(),
32
+ /** Who produced the turn. */
33
+ role: (0, exports.copilotMessageRole)('role').notNull(),
34
+ /**
35
+ * The turn's content blocks, exactly as the port models them — text,
36
+ * tool_use and tool_result. Stored as the port's shape rather than a
37
+ * provider's, so a transcript survives switching provider.
38
+ */
39
+ content: (0, pg_core_1.jsonb)('content').$type().notNull(),
40
+ /**
41
+ * Files the user attached to this turn, resolved at send time. Null on
42
+ * an assistant turn and on a user turn with none.
43
+ *
44
+ * Its own column rather than another `content` block, for two reasons.
45
+ * The port's `ModelContentBlock` union is what every adapter switches
46
+ * on, so a sixth member would be a change to three adapters for
47
+ * something no provider needs to see; and the transcript read wants
48
+ * this **structured** — the panel renders attachments as chips, and
49
+ * recovering them by sniffing a text block's prefix is the kind of
50
+ * parsing that works until someone types the prefix.
51
+ *
52
+ * The engine folds them back into a fenced text block when it builds
53
+ * model messages, so a follow-up turn still knows what was attached.
54
+ */
55
+ attachments: (0, pg_core_1.jsonb)('attachments').$type(),
56
+ /**
57
+ * The skills that were in force for this turn — attached by the person
58
+ * *and* the workspace's always-on ones. Null on an assistant turn and
59
+ * on a user turn that ran with none.
60
+ *
61
+ * A **snapshot** (name, title, source), not ids: a skill can be renamed
62
+ * or deleted, and a thread read months later still has to be able to
63
+ * say what shaped the answer. It is also what the transcript renders as
64
+ * chips, which is the only way a person ever learns, after the fact,
65
+ * that an answer was written under instructions they did not see.
66
+ *
67
+ * Its own column rather than a content block, for the same two reasons
68
+ * `attachments` is: no adapter needs to switch on it, and recovering it
69
+ * by parsing a text block works until someone types the prefix.
70
+ */
71
+ skills: (0, pg_core_1.jsonb)('skills').$type(),
72
+ /** Which model produced an assistant turn; null on a user turn. */
73
+ model: (0, pg_core_1.text)('model'),
74
+ /** Which registered provider served it; null on a user turn. */
75
+ provider: (0, pg_core_1.text)('provider'),
76
+ /** Why the run ended, on the final assistant turn. */
77
+ stopReason: (0, pg_core_1.text)('stop_reason'),
78
+ /** Tokens billed as input across the run. */
79
+ inputTokens: (0, pg_core_1.integer)('input_tokens'),
80
+ /** Tokens the model generated across the run. */
81
+ outputTokens: (0, pg_core_1.integer)('output_tokens'),
82
+ /**
83
+ * Monotonic position within the thread. Explicit rather than inferred
84
+ * from `createdAt`: two turns of one run can land inside the same
85
+ * millisecond, and a transcript that renders out of order is worse
86
+ * than one that renders slowly.
87
+ */
88
+ position: (0, pg_core_1.integer)('position').notNull(),
89
+ /** Row creation timestamp. */
90
+ createdAt: (0, pg_core_1.timestamp)('created_at', { withTimezone: true })
91
+ .notNull()
92
+ .defaultNow()
93
+ }, (table) => [
94
+ // The transcript read: one thread's turns, in order.
95
+ (0, pg_core_1.index)('copilot_messages_thread_idx').on(table.conversationId, table.position)
96
+ ]);
@@ -0,0 +1,328 @@
1
+ /**
2
+ * **The accept boundary** — one row per change the copilot proposed
3
+ * ([ADR-0005](../../../../../../docs/adr/0005-copilot-authority-model.md) §5).
4
+ *
5
+ * Every mutating tool writes here first and a human decides; a workspace that
6
+ * opted a tool into auto-apply still gets the row, accepted in the same breath.
7
+ * That is what makes a direct apply "undoable, never invisible" rather than a
8
+ * write with no paper trail — the row records what was proposed, by which run,
9
+ * on whose behalf, and who decided.
10
+ *
11
+ * `target` and `patch` are opaque jsonb on purpose: their shape belongs to the
12
+ * applier that declared the `kind`, and teaching this table about content
13
+ * entries would make the copilot the thing that changes when content does.
14
+ */
15
+ export declare const copilotProposals: import("drizzle-orm/pg-core").PgTableWithColumns<{
16
+ name: "copilot_proposals";
17
+ schema: undefined;
18
+ columns: {
19
+ id: import("drizzle-orm/pg-core").PgColumn<{
20
+ name: "id";
21
+ tableName: "copilot_proposals";
22
+ dataType: "string";
23
+ columnType: "PgUUID";
24
+ data: string;
25
+ driverParam: string;
26
+ notNull: true;
27
+ hasDefault: true;
28
+ isPrimaryKey: true;
29
+ isAutoincrement: false;
30
+ hasRuntimeDefault: false;
31
+ enumValues: undefined;
32
+ baseColumn: never;
33
+ identity: undefined;
34
+ generated: undefined;
35
+ }, {}, {}>;
36
+ conversationId: import("drizzle-orm/pg-core").PgColumn<{
37
+ name: "conversation_id";
38
+ tableName: "copilot_proposals";
39
+ dataType: "string";
40
+ columnType: "PgUUID";
41
+ data: string;
42
+ driverParam: string;
43
+ notNull: true;
44
+ hasDefault: false;
45
+ isPrimaryKey: false;
46
+ isAutoincrement: false;
47
+ hasRuntimeDefault: false;
48
+ enumValues: undefined;
49
+ baseColumn: never;
50
+ identity: undefined;
51
+ generated: undefined;
52
+ }, {}, {}>;
53
+ runId: import("drizzle-orm/pg-core").PgColumn<{
54
+ name: "run_id";
55
+ tableName: "copilot_proposals";
56
+ dataType: "string";
57
+ columnType: "PgUUID";
58
+ data: string;
59
+ driverParam: string;
60
+ notNull: true;
61
+ hasDefault: false;
62
+ isPrimaryKey: false;
63
+ isAutoincrement: false;
64
+ hasRuntimeDefault: false;
65
+ enumValues: undefined;
66
+ baseColumn: never;
67
+ identity: undefined;
68
+ generated: undefined;
69
+ }, {}, {}>;
70
+ toolCallId: import("drizzle-orm/pg-core").PgColumn<{
71
+ name: "tool_call_id";
72
+ tableName: "copilot_proposals";
73
+ dataType: "string";
74
+ columnType: "PgText";
75
+ data: string;
76
+ driverParam: string;
77
+ notNull: true;
78
+ hasDefault: false;
79
+ isPrimaryKey: false;
80
+ isAutoincrement: false;
81
+ hasRuntimeDefault: false;
82
+ enumValues: [string, ...string[]];
83
+ baseColumn: never;
84
+ identity: undefined;
85
+ generated: undefined;
86
+ }, {}, {}>;
87
+ toolName: import("drizzle-orm/pg-core").PgColumn<{
88
+ name: "tool_name";
89
+ tableName: "copilot_proposals";
90
+ dataType: "string";
91
+ columnType: "PgText";
92
+ data: string;
93
+ driverParam: string;
94
+ notNull: true;
95
+ hasDefault: false;
96
+ isPrimaryKey: false;
97
+ isAutoincrement: false;
98
+ hasRuntimeDefault: false;
99
+ enumValues: [string, ...string[]];
100
+ baseColumn: never;
101
+ identity: undefined;
102
+ generated: undefined;
103
+ }, {}, {}>;
104
+ kind: import("drizzle-orm/pg-core").PgColumn<{
105
+ name: "kind";
106
+ tableName: "copilot_proposals";
107
+ dataType: "string";
108
+ columnType: "PgText";
109
+ data: string;
110
+ driverParam: string;
111
+ notNull: true;
112
+ hasDefault: false;
113
+ isPrimaryKey: false;
114
+ isAutoincrement: false;
115
+ hasRuntimeDefault: false;
116
+ enumValues: [string, ...string[]];
117
+ baseColumn: never;
118
+ identity: undefined;
119
+ generated: undefined;
120
+ }, {}, {}>;
121
+ workspaceId: import("drizzle-orm/pg-core").PgColumn<{
122
+ name: "workspace_id";
123
+ tableName: "copilot_proposals";
124
+ dataType: "string";
125
+ columnType: "PgUUID";
126
+ data: string;
127
+ driverParam: string;
128
+ notNull: true;
129
+ hasDefault: false;
130
+ isPrimaryKey: false;
131
+ isAutoincrement: false;
132
+ hasRuntimeDefault: false;
133
+ enumValues: undefined;
134
+ baseColumn: never;
135
+ identity: undefined;
136
+ generated: undefined;
137
+ }, {}, {}>;
138
+ createdBy: import("drizzle-orm/pg-core").PgColumn<{
139
+ name: "created_by";
140
+ tableName: "copilot_proposals";
141
+ dataType: "string";
142
+ columnType: "PgUUID";
143
+ data: string;
144
+ driverParam: string;
145
+ notNull: true;
146
+ hasDefault: false;
147
+ isPrimaryKey: false;
148
+ isAutoincrement: false;
149
+ hasRuntimeDefault: false;
150
+ enumValues: undefined;
151
+ baseColumn: never;
152
+ identity: undefined;
153
+ generated: undefined;
154
+ }, {}, {}>;
155
+ target: import("drizzle-orm/pg-core").PgColumn<{
156
+ name: "target";
157
+ tableName: "copilot_proposals";
158
+ dataType: "json";
159
+ columnType: "PgJsonb";
160
+ data: unknown;
161
+ driverParam: unknown;
162
+ notNull: true;
163
+ hasDefault: false;
164
+ isPrimaryKey: false;
165
+ isAutoincrement: false;
166
+ hasRuntimeDefault: false;
167
+ enumValues: undefined;
168
+ baseColumn: never;
169
+ identity: undefined;
170
+ generated: undefined;
171
+ }, {}, {}>;
172
+ patch: import("drizzle-orm/pg-core").PgColumn<{
173
+ name: "patch";
174
+ tableName: "copilot_proposals";
175
+ dataType: "json";
176
+ columnType: "PgJsonb";
177
+ data: unknown;
178
+ driverParam: unknown;
179
+ notNull: true;
180
+ hasDefault: false;
181
+ isPrimaryKey: false;
182
+ isAutoincrement: false;
183
+ hasRuntimeDefault: false;
184
+ enumValues: undefined;
185
+ baseColumn: never;
186
+ identity: undefined;
187
+ generated: undefined;
188
+ }, {}, {}>;
189
+ summary: import("drizzle-orm/pg-core").PgColumn<{
190
+ name: "summary";
191
+ tableName: "copilot_proposals";
192
+ dataType: "string";
193
+ columnType: "PgText";
194
+ data: string;
195
+ driverParam: string;
196
+ notNull: true;
197
+ hasDefault: false;
198
+ isPrimaryKey: false;
199
+ isAutoincrement: false;
200
+ hasRuntimeDefault: false;
201
+ enumValues: [string, ...string[]];
202
+ baseColumn: never;
203
+ identity: undefined;
204
+ generated: undefined;
205
+ }, {}, {}>;
206
+ changes: import("drizzle-orm/pg-core").PgColumn<{
207
+ name: "changes";
208
+ tableName: "copilot_proposals";
209
+ dataType: "json";
210
+ columnType: "PgJsonb";
211
+ data: unknown;
212
+ driverParam: unknown;
213
+ notNull: false;
214
+ hasDefault: false;
215
+ isPrimaryKey: false;
216
+ isAutoincrement: false;
217
+ hasRuntimeDefault: false;
218
+ enumValues: undefined;
219
+ baseColumn: never;
220
+ identity: undefined;
221
+ generated: undefined;
222
+ }, {}, {}>;
223
+ status: import("drizzle-orm/pg-core").PgColumn<{
224
+ name: "status";
225
+ tableName: "copilot_proposals";
226
+ dataType: "string";
227
+ columnType: "PgText";
228
+ data: string;
229
+ driverParam: string;
230
+ notNull: true;
231
+ hasDefault: true;
232
+ isPrimaryKey: false;
233
+ isAutoincrement: false;
234
+ hasRuntimeDefault: false;
235
+ enumValues: [string, ...string[]];
236
+ baseColumn: never;
237
+ identity: undefined;
238
+ generated: undefined;
239
+ }, {}, {}>;
240
+ decidedBy: import("drizzle-orm/pg-core").PgColumn<{
241
+ name: "decided_by";
242
+ tableName: "copilot_proposals";
243
+ dataType: "string";
244
+ columnType: "PgUUID";
245
+ data: string;
246
+ driverParam: string;
247
+ notNull: false;
248
+ hasDefault: false;
249
+ isPrimaryKey: false;
250
+ isAutoincrement: false;
251
+ hasRuntimeDefault: false;
252
+ enumValues: undefined;
253
+ baseColumn: never;
254
+ identity: undefined;
255
+ generated: undefined;
256
+ }, {}, {}>;
257
+ decidedAt: import("drizzle-orm/pg-core").PgColumn<{
258
+ name: "decided_at";
259
+ tableName: "copilot_proposals";
260
+ dataType: "date";
261
+ columnType: "PgTimestamp";
262
+ data: Date;
263
+ driverParam: string;
264
+ notNull: false;
265
+ hasDefault: false;
266
+ isPrimaryKey: false;
267
+ isAutoincrement: false;
268
+ hasRuntimeDefault: false;
269
+ enumValues: undefined;
270
+ baseColumn: never;
271
+ identity: undefined;
272
+ generated: undefined;
273
+ }, {}, {}>;
274
+ result: import("drizzle-orm/pg-core").PgColumn<{
275
+ name: "result";
276
+ tableName: "copilot_proposals";
277
+ dataType: "json";
278
+ columnType: "PgJsonb";
279
+ data: unknown;
280
+ driverParam: unknown;
281
+ notNull: false;
282
+ hasDefault: false;
283
+ isPrimaryKey: false;
284
+ isAutoincrement: false;
285
+ hasRuntimeDefault: false;
286
+ enumValues: undefined;
287
+ baseColumn: never;
288
+ identity: undefined;
289
+ generated: undefined;
290
+ }, {}, {}>;
291
+ error: import("drizzle-orm/pg-core").PgColumn<{
292
+ name: "error";
293
+ tableName: "copilot_proposals";
294
+ dataType: "string";
295
+ columnType: "PgText";
296
+ data: string;
297
+ driverParam: string;
298
+ notNull: false;
299
+ hasDefault: false;
300
+ isPrimaryKey: false;
301
+ isAutoincrement: false;
302
+ hasRuntimeDefault: false;
303
+ enumValues: [string, ...string[]];
304
+ baseColumn: never;
305
+ identity: undefined;
306
+ generated: undefined;
307
+ }, {}, {}>;
308
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
309
+ name: "created_at";
310
+ tableName: "copilot_proposals";
311
+ dataType: "date";
312
+ columnType: "PgTimestamp";
313
+ data: Date;
314
+ driverParam: string;
315
+ notNull: true;
316
+ hasDefault: true;
317
+ isPrimaryKey: false;
318
+ isAutoincrement: false;
319
+ hasRuntimeDefault: false;
320
+ enumValues: undefined;
321
+ baseColumn: never;
322
+ identity: undefined;
323
+ generated: undefined;
324
+ }, {}, {}>;
325
+ };
326
+ dialect: "pg";
327
+ }>;
328
+ //# sourceMappingURL=proposals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proposals.d.ts","sourceRoot":"","sources":["../../../../../src/lib/chat/infrastructure/schema/proposals.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0E5B,CAAC"}