u
This commit is contained in:
@@ -15,9 +15,10 @@ export default function create(provider) {
|
||||
* @param {object} input - Conversation input.
|
||||
* @param {string} input.provider - LLM provider name.
|
||||
* @param {string} input.model - Model identifier.
|
||||
* @param {number|null} [input.started_by] - Id of the conversation that starts this one as a subagent (unenforced reference; omit/null for a top-level conversation).
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string}>}
|
||||
* @throws {Error} 'Provider required' or 'Model required'.
|
||||
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string, started_by: number|null}>}
|
||||
* @throws {Error} 'Provider required', 'Model required' or 'Invalid started_by'.
|
||||
*
|
||||
* @example
|
||||
* const c = await store.modelconversation.create(42, { provider: 'openrouter', model: 'openai/gpt-5' });
|
||||
@@ -28,6 +29,10 @@ export default function create(provider) {
|
||||
if (!providerName) throw new Error('Provider required');
|
||||
const model = typeof input.model === 'string' ? input.model.trim() : '';
|
||||
if (!model) throw new Error('Model required');
|
||||
const startedBy = input.started_by ?? null;
|
||||
if (startedBy !== null && (!Number.isInteger(startedBy) || startedBy <= 0)) {
|
||||
throw new Error('Invalid started_by');
|
||||
}
|
||||
|
||||
const runner = makeRunner(provider, tx);
|
||||
const { companyuserId } = await access(googleAuthId, runner);
|
||||
@@ -36,6 +41,7 @@ export default function create(provider) {
|
||||
companyuserId,
|
||||
provider: providerName,
|
||||
model,
|
||||
startedBy,
|
||||
});
|
||||
return shape(result.rows[0]);
|
||||
};
|
||||
|
||||
@@ -9,7 +9,8 @@ export default function del(provider) {
|
||||
provider?.dialect === 'sqlite3' ? SQLITE_DELETE : MSSQL_DELETE;
|
||||
|
||||
/**
|
||||
* Deletes a model conversation by ID for the user in the selected company.
|
||||
* Deletes a model conversation by ID for the user in the selected company, together with
|
||||
* every subagent conversation below it (`started_by` chain, recursively) and their messages.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} conversationId - The conversation id.
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function get(provider) {
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} conversationId - The conversation id.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string}>}
|
||||
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string, started_by: number|null}>}
|
||||
* @throws {Error} 'Conversation not found'.
|
||||
*/
|
||||
return async (googleAuthId, conversationId, tx) => {
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function list(provider) {
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<Array<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string}>>}
|
||||
* @returns {Promise<Array<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string, started_by: number|null, first_user_message: string|null}>>} `started_by` is the originating conversation id for subagent conversations (null otherwise), so clients can build a tree. `first_user_message` is the stored `message` payload of the conversation's first `user` message (null if none yet).
|
||||
*
|
||||
* @example
|
||||
* const conversations = await store.modelconversation.list(42);
|
||||
@@ -22,6 +22,9 @@ export default function list(provider) {
|
||||
const runner = makeRunner(provider, tx);
|
||||
const { companyuserId } = await access(googleAuthId, runner);
|
||||
const result = await runner.query(sql, { companyuserId });
|
||||
return result.rows.map(shape);
|
||||
return result.rows.map((row) => ({
|
||||
...shape(row),
|
||||
first_user_message: row.first_user_message ?? null,
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function setState(provider) {
|
||||
* @param {number} conversationId - The conversation id.
|
||||
* @param {string} state - The new state ('idle' | 'busy').
|
||||
* @param {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string}>}
|
||||
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string, started_by: number|null}>}
|
||||
* @throws {Error} 'Invalid state' or 'Conversation not found'.
|
||||
*/
|
||||
return async (googleAuthId, conversationId, state, tx) => {
|
||||
|
||||
@@ -7,5 +7,6 @@ export default function shape(row) {
|
||||
created_at: row.created_at ?? row.createdAt,
|
||||
updated_at: row.updated_at ?? row.updatedAt,
|
||||
state: row.state,
|
||||
started_by: row.started_by ?? row.startedBy ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user