Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
00fe460
feat: add ApiClient for documents and links APIs with SSE support
janole Aug 23, 2025
5dc6d76
refactor: move chat-server-storage.ts to chat-server subdirectory to …
janole Aug 23, 2025
98d5de6
refactor: rename chat-server-storage.ts to api-client.ts for clarity
janole Aug 23, 2025
f85d037
refactor: remove unnecessary eslint disable comment for dynamic impor…
janole Aug 23, 2025
ef70e8c
feat: sync session data to chat server on save
janole Aug 23, 2025
83a2d37
feat: add chat server client for API communication with environment v…
janole Aug 23, 2025
e0ca89d
fix: update environment variables and enable subscription logging in …
janole Aug 26, 2025
4b4040b
feat: add methods to list documents linking to a target and to list c…
janole Aug 26, 2025
5f3f8ec
feat: add command listener management to chat server client for handl…
janole Aug 26, 2025
3e8f6a3
feat: add command listener to process external chat commands and send…
janole Aug 26, 2025
000a95f
feat: add Supabase realtime client with presence and document insert …
janole Aug 27, 2025
0e1bbd4
refactor: add ClientStatus interface and update setStatus method; rem…
janole Aug 27, 2025
8781764
refactor: remove unused command listener logic and simplify chat serv…
janole Aug 27, 2025
d7c919a
refactor: replace addCommandListener with chatServerClient methods an…
janole Aug 27, 2025
0f5e58d
fix: fix authData usage and update setStatus method parameters and pa…
janole Aug 27, 2025
e25fc42
chore: add @supabase/supabase-js dependency at version 2.56.0 in pack…
janole Aug 27, 2025
181cf97
style: add trailing comma to export list
janole Aug 27, 2025
ab48d7b
fix: update chat server client status based on working state
janole Aug 30, 2025
befde84
fix: remove debug console log from api-client.ts
janole Sep 3, 2025
1e67a8e
fix: handle broadcast command events by pushing commands with args
janole Sep 3, 2025
f5ede6e
chore: add async-mutex dependency to package.json and package-lock.json
janole Sep 3, 2025
61bd301
fix: remove debug log from chat controller command listener
janole Sep 3, 2025
413838d
chore: add commented-out Mutex class for potential future use in api-…
janole Sep 3, 2025
249f792
chore: remove commented-out Mutex class from api-client.ts
janole Sep 3, 2025
f6a3bf4
refactor: add mutex to ensureSupabaseClient for safe initialization a…
janole Sep 3, 2025
5a257e0
fix: update pushCommand to handle command event payload structure and…
janole Sep 3, 2025
08865ff
refactor: prefix interface names with 'I' in api-client.ts and update…
janole Sep 3, 2025
7aeab3c
fix: update API client methods to use IDocument interface instead of …
janole Sep 4, 2025
bd85528
fix: prevent redundant status updates by tracking status with ref in …
janole Sep 4, 2025
733716d
fix: include handleSendHistory in dependencies array of useChatContro…
janole Sep 4, 2025
6453bcb
chore: remove eventsource dependency and its types from package files
janole Sep 4, 2025
a5ae7da
fix: queue async message updates in chat controller to avoid concurre…
janole Sep 5, 2025
4ea773d
fix: update effect dependency from session to session.id to avoid unn…
janole Sep 5, 2025
b21c956
refactor: change session messages handling to inline update in useCha…
janole Sep 5, 2025
26cc8ee
refactor: remove redundant session.setMessages call in chat controlle…
janole Sep 5, 2025
907bcf4
feat: add chat server type definitions for models, messages, and chat…
janole Sep 6, 2025
2d5abca
feat: add types for managing chat models and accounts including add/r…
janole Sep 6, 2025
abbbfa5
refactor: define TConfirmState using a constant array for better type…
janole Sep 6, 2025
812771a
feat: add functions to map messages and chat sessions for chat-server…
janole Sep 7, 2025
d982f7e
fix: serialize session.setMessages calls to avoid race conditions and…
janole Sep 7, 2025
0601391
fix: update session data mapping when syncing with chat server client…
janole Sep 7, 2025
51d9348
fix: save session before rendering chat app to ensure state persistence
janole Sep 7, 2025
172f411
feat: add streaming messages upload to chat server and update send to…
janole Sep 7, 2025
bf5ff3c
chore: reset to pre-branch state
janole Sep 7, 2025
663cd02
chore: reset to pre-branch state
janole Sep 7, 2025
1bc84b9
feat: add broadcast and document management methods to ApiClient incl…
janole Sep 7, 2025
4fd0fa1
chore: add console log for upsert operation in file session storage
janole Sep 7, 2025
4026a28
chore: reset to pre-branch state
janole Sep 7, 2025
78815bd
chore: reset to pre-branch state
janole Sep 7, 2025
a2114f7
chore: reset to pre-branch state
janole Sep 7, 2025
1611f65
chore: revert to main
janole Sep 7, 2025
a9e898e
refactor: replace send callback with session.setMessages to manage me…
janole Sep 8, 2025
a6cb90b
refactor: make CustomMessage abstract and add isMessageFinished metho…
janole Sep 8, 2025
c0c1a2c
refactor: clean up chat-controller by removing unnecessary params, si…
janole Sep 8, 2025
9be21fb
refactor: dynamically determine finished messages in chat display ren…
janole Sep 8, 2025
3b5ff79
refactor: remove finished property from session and update save logic…
janole Sep 8, 2025
bd4a643
refactor: convert setMessages method to arrow function for consistent…
janole Sep 8, 2025
f4638c9
refactor: convert setStorage method to an arrow function in ChatSessi…
janole Sep 8, 2025
a94fe82
refactor: change notifyListeners method to public arrow function to p…
janole Sep 8, 2025
5882de8
refactor: convert onUpdate method to arrow function and update syntax…
janole Sep 8, 2025
575e60b
fix: add missing semicolon to method definition in session.ts
janole Sep 8, 2025
441c758
refactor: convert toggleConfirmState method to arrow function to pres…
janole Sep 8, 2025
4909657
refactor: change save method to an arrow function and update promise …
janole Sep 8, 2025
5b8f320
refactor: update _saveOnlineQueue type and convert _saveOnline to arr…
janole Sep 8, 2025
51b637c
fix: await asynchronous setMessages call to ensure proper message upd…
janole Sep 8, 2025
85a0009
feat: add no-invalid-this rule to eslint configuration for TypeScript
janole Sep 8, 2025
a2a59ce
feat: add flush method to await save queues for online and storage op…
janole Sep 8, 2025
d6cda33
refactor: simplify flush method by removing conditional options and a…
janole Sep 8, 2025
9482fa4
fix: return a new array copy of messages when toolProgressMessages is…
janole Sep 8, 2025
dee71e3
refactor: streamline session message handling and tool mode checks in…
janole Sep 8, 2025
6711de4
feat: add streaming state handling to chat session and improve save l…
janole Sep 8, 2025
70e1c68
fix: replace session.save() with session.flush() to correctly persist…
janole Sep 8, 2025
47d6562
fix: remove unnecessary saveOnline call and redundant console logs in…
janole Sep 8, 2025
c1c861a
refactor: simplify session save logic and use syncSession for online …
janole Sep 9, 2025
9c1ea70
refactor: remove addDoc method and rename upsertDocument2 to directUp…
janole Sep 9, 2025
2255935
feat: add online syncing for chat sessions with support for streaming…
janole Sep 9, 2025
9825b6d
chore: remove trailing newline at end of chat-server-client.ts file
janole Sep 9, 2025
5b20137
feat: add streaming support and async generateResponse method to Chat…
janole Sep 9, 2025
c913509
refactor: remove streaming prop and use session.streaming instead in …
janole Sep 9, 2025
9abe68f
refactor: remove ChatService and work usage; delegate response genera…
janole Sep 9, 2025
924c9fb
refactor: replace chatHistory with messages state in ChatApp componen…
janole Sep 9, 2025
57ea11b
fix: add streaming option support and set chat service on session ini…
janole Sep 9, 2025
63eb78a
refactor: update type imports and set chat state dynamically based on…
janole Sep 9, 2025
3389148
refactor: change isWorking property to have private setter and public…
janole Sep 9, 2025
5c4fdf0
feat: implement IApiClientCommandListener in ChatSession to handle in…
janole Sep 9, 2025
8ca1b0f
refactor: replace command listener function with interface for better…
janole Sep 9, 2025
59a6d87
fix: throttle syncSession calls to limit pushStreamingMessageOnline f…
janole Sep 9, 2025
d981406
refactor: simplify supabase client initialization and remove async-mu…
janole Sep 9, 2025
cd53f76
fix: add comment to clarify supabase client initialization then block
janole Sep 9, 2025
0a9258a
chore: add @supabase/supabase-js as an optional dependency in package…
janole Sep 9, 2025
8a8a13a
refactor: use dynamic import for createClient from supabase-js to opt…
janole Sep 9, 2025
43e15c8
chore: remove commented out getMessageState and setMessageState funct…
janole Sep 9, 2025
0951c51
fix: pass toolProgressMessage in metadata when invoking selected tool…
janole Sep 9, 2025
204022b
refactor: replace handleSendHistory with session.generateResponse in …
janole Sep 9, 2025
3ebbfcc
chore: add newline at end of package.json file
janole Sep 9, 2025
2998559
feat: add info property to ToolProgressMessage to include additional …
janole Sep 9, 2025
6c14eb4
feat: add setToolMode method to update tool mode and notify listeners…
janole Sep 9, 2025
6c0d2af
feat: add confirmToolUse method to handle tool usage confirmation and…
janole Sep 9, 2025
e86f391
feat: add abortController to ChatSession for aborting generateRespons…
janole Sep 9, 2025
49606e5
feat: add toolMode to update listener and handle confirm tool use eve…
janole Sep 9, 2025
2ac7647
refactor: simplify chat controller by removing abort controller state…
janole Sep 9, 2025
8110bc9
fix: add description and fileName to toolCall mapping in chat-server-…
janole Sep 9, 2025
6675e45
feat: add progress message updates to file system tools operations
janole Sep 9, 2025
e1e279a
feat: add setToolProgressMessageInfo to update progress message details
janole Sep 9, 2025
c35c97c
chore: add TODO comment to relocate handleCommand method from session
janole Sep 9, 2025
97a2e4e
fix: update abort method to check if already aborted before aborting …
janole Sep 9, 2025
3446c6e
feat: add abort handling to cancel ongoing chat session on external a…
janole Sep 9, 2025
c239450
fix: return the modified message object in setMessageIsStreaming func…
janole Sep 9, 2025
3bff06c
feat: add resetIsStreamingFlag function to reset streaming flag on me…
janole Sep 9, 2025
59ea973
fix: reset streaming flag on messages when handling work error in cha…
janole Sep 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default [
format: ["camelCase", "PascalCase"],
}],

"@typescript-eslint/no-invalid-this": ["error"],

"@stylistic/brace-style": ["error", "allman", { allowSingleLine: true }],
"@stylistic/quotes": ["error", "double"],
"@stylistic/comma-dangle": ["error", "always-multiline"],
Expand Down
101 changes: 101 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"ulid": "^3.0.1",
"write-file-atomic": "^6.0.0"
},
"optionalDependencies": {
"@supabase/supabase-js": "^2.57.2"
},
"devDependencies": {
"@sindresorhus/tsconfig": "^7.0.0",
"@stylistic/eslint-plugin": "^5.1.0",
Expand Down
56 changes: 51 additions & 5 deletions src/ai/custom-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type TCustomMessageType = "error" | "tool-progress";

export type TMessageType = ReturnType<BaseMessage["getType"]> | TCustomMessageType;

export class CustomMessage
export abstract class CustomMessage
{
_type: TCustomMessageType;

Expand All @@ -21,6 +21,8 @@ export class CustomMessage
return this._type;
}

abstract isMessageFinished(): boolean;

static fromObject(obj: any): CustomMessage
{
if (obj._type === "error")
Expand All @@ -29,7 +31,7 @@ export class CustomMessage
}
else if (obj._type === "tool-progress")
{
return new ToolProgressMessage(obj.toolCall, obj.status, obj.content, obj.confirmState);
return new ToolProgressMessage(obj.toolCall, obj.status, obj.content, obj.confirmState, obj.info);
}

throw new Error(`Unknown custom message type: ${obj._type}`);
Expand Down Expand Up @@ -61,6 +63,11 @@ class ErrorMessage extends CustomMessage
};
}
}

override isMessageFinished(): boolean
{
return true;
}
}

class ToolProgressMessage extends CustomMessage
Expand All @@ -71,12 +78,16 @@ class ToolProgressMessage extends CustomMessage
status: "pending" | "pending-confirmation" | "confirmed" | "declined" | "success" | "error";
content?: string;
confirmState: typeof ToolProgressMessage.CONFIRM_STATES[number];
info: {
description?: string;
fileName?: string;
};

static isTypeOf = (m: any) => m instanceof ToolProgressMessage;

clone({ status, confirmState }: Pick<ToolProgressMessage, "status" | "confirmState">)
{
return new ToolProgressMessage(this.toolCall, status, this.content, confirmState);
return new ToolProgressMessage(this.toolCall, status, this.content, confirmState, this.info);
}

toggleConfirmState({ direction }: { direction: -1 | 1 })
Expand Down Expand Up @@ -124,14 +135,20 @@ class ToolProgressMessage extends CustomMessage
return toolCallChunks?.map(i => ToolProgressMessage.createFromChunk(i)).filter(i => !!i) || [];
}

constructor(toolCall: ToolCall, status?: ToolProgressMessage["status"], content?: string, confirmState?: ToolProgressMessage["confirmState"])
constructor(toolCall: ToolCall, status?: ToolProgressMessage["status"], content?: string, confirmState?: ToolProgressMessage["confirmState"], info?: ToolProgressMessage["info"])
{
super("tool-progress");

this.toolCall = toolCall;
this.status = status || "pending";
this.content = content;
this.confirmState = confirmState || "no";
this.info = info || {};
}

override isMessageFinished(): boolean
{
return this.status !== "pending" && this.status !== "pending-confirmation";
}
}

Expand All @@ -149,9 +166,38 @@ export const isCustomMessage = (message: any): message is CustomMessage =>
);
};

const setMessageIsStreaming = (msg: BaseMessage, isStreaming: boolean) =>
{
msg.additional_kwargs["_coba_message_is_streaming"] = isStreaming;
return msg;
};

const isMessageStreaming = (msg: TMessage): boolean =>
{
return (msg instanceof BaseMessage) && (msg as BaseMessage).additional_kwargs["_coba_message_is_streaming"] === true;
};

const isMessageFinished = (msg: TMessage): boolean =>
{
if (msg instanceof BaseMessage)
{
return !isMessageStreaming(msg);
}

return msg.isMessageFinished();
};

const resetIsStreamingFlag = (msg: TMessage[]): TMessage[] =>
{
return msg.map(m => (m instanceof BaseMessage) ? setMessageIsStreaming(m, false) : m);
};

export
{
ErrorMessage,
isMessageFinished,
isMessageStreaming,
resetIsStreamingFlag,
setMessageIsStreaming,
ToolProgressMessage,
};

Loading