Skip to content

Commit 699c453

Browse files
committed
WIP move tool calling to boxel message events and add support for multiple tool calls/commands
1 parent 67af826 commit 699c453

File tree

5 files changed

+16
-56
lines changed

5 files changed

+16
-56
lines changed

packages/ai-bot/tests/responding-test.ts

+9-34
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ class FakeMatrixClient implements MatrixClient {
5858
this.sentEvents = [];
5959
this.eventId = 0;
6060
}
61-
sendStateEvent(
62-
_roomId: string,
63-
_eventType: string,
64-
_content: IContent,
65-
_stateKey: string,
66-
): Promise<{ event_id: string }> {
67-
throw new Error('Method not implemented.');
68-
}
6961
}
7062

7163
function snapshotWithContent(content: string): ChatCompletionSnapshot {
@@ -568,30 +560,13 @@ module('Responding', (hooks) => {
568560

569561
test('Updates message type to command when tool call is in progress', async () => {
570562
await responder.initialize();
571-
await responder.onChunk({
572-
id: '0',
573-
created: 0,
574-
model: 'gpt-3.5-turbo',
575-
object: 'chat.completion.chunk',
576-
choices: [
577-
{
578-
delta: {
579-
tool_calls: [
580-
{
581-
index: 0,
582-
type: 'function',
583-
function: {
584-
name: 'patchCard',
585-
arguments: '',
586-
},
587-
},
588-
],
589-
},
590-
index: 0,
591-
finish_reason: 'stop',
592-
},
593-
],
594-
});
563+
await responder.onChunk(
564+
{} as any,
565+
snapshotWithToolCall({
566+
name: 'patchCard',
567+
arguments: {},
568+
}),
569+
);
595570

596571
let sentEvents = fakeMatrixClient.getSentEvents();
597572
assert.equal(
@@ -605,8 +580,8 @@ module('Responding', (hooks) => {
605580
'Thinking message should be sent first',
606581
);
607582
assert.deepEqual(
608-
sentEvents[1].content['msgtype'],
609-
APP_BOXEL_COMMAND_MSGTYPE,
583+
sentEvents[1].content[APP_BOXEL_COMMAND_REQUESTS_KEY].length,
584+
1,
610585
'The message type should reflect that the model is preparing a tool call',
611586
);
612587
assert.deepEqual(

packages/host/app/components/ai-assistant/message/index.gts

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ interface Signature {
7878
}) => void;
7979
errorMessage?: string;
8080
isPending?: boolean;
81-
isCommandMessage?: boolean;
8281
retryAction?: () => void;
8382
};
8483
Blocks: { default: [] };

packages/host/app/components/ai-assistant/message/usage.gts

-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export default class AiAssistantMessageUsage extends Component {
6868
@errorMessage={{this.errorMessage}}
6969
@retryAction={{this.retryAction}}
7070
@isStreaming={{this.isStreaming}}
71-
@isCommandMessage={{this.isCommandMessage}}
7271
>
7372
<em>Optional embedded content</em>
7473
</AiAssistantMessage>
@@ -143,7 +142,6 @@ export default class AiAssistantMessageUsage extends Component {
143142
isReady=true
144143
}}
145144
@isStreaming={{false}}
146-
@isCommandMessage={{false}}
147145
/>
148146
<AiAssistantMessage
149147
@formattedMessage={{htmlSafe
@@ -155,7 +153,6 @@ export default class AiAssistantMessageUsage extends Component {
155153
@datetime={{this.oneMinutesAgo}}
156154
@isFromAssistant={{true}}
157155
@isStreaming={{false}}
158-
@isCommandMessage={{false}}
159156
/>
160157
</AiAssistantConversation>
161158
</div>

packages/host/app/components/matrix/room-message.gts

+1-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { trackedFunction } from 'ember-resources/util/function';
1111

1212
import { Avatar } from '@cardstack/boxel-ui/components';
1313

14-
import { bool, or } from '@cardstack/boxel-ui/helpers';
14+
import { bool } from '@cardstack/boxel-ui/helpers';
1515

1616
import { markdownToHtml } from '@cardstack/runtime-common';
1717

@@ -27,7 +27,6 @@ import { type CardDef } from 'https://cardstack.com/base/card-api';
2727
import AiAssistantMessage from '../ai-assistant/message';
2828
import { aiBotUserId } from '../ai-assistant/panel';
2929

30-
import PreparingRoomMessageCommand from './preparing-room-message-command';
3130
import RoomMessageCommand from './room-message-command';
3231

3332
interface Signature {
@@ -122,17 +121,8 @@ export default class RoomMessage extends Component<Signature> {
122121
@isStreaming={{@isStreaming}}
123122
@retryAction={{@retryAction}}
124123
@isPending={{@isPending}}
125-
<<<<<<< HEAD
126124
data-test-boxel-message-from={{this.message.author.name}}
127125
data-test-boxel-message-instance-id={{this.message.instanceId}}
128-
=======
129-
@isCommandMessage={{or
130-
(bool @message.command)
131-
@message.isPreparingCommand
132-
}}
133-
data-test-boxel-message-from={{@message.author.name}}
134-
data-test-boxel-message-instance-id={{@message.instanceId}}
135-
>>>>>>> dd3d939b8 (Show ApplyButton's preparing state when a command is being prepared)
136126
...attributes
137127
>
138128
{{#each this.message.commands as |command|}}
@@ -145,13 +135,7 @@ export default class RoomMessage extends Component<Signature> {
145135
@monacoSDK={{@monacoSDK}}
146136
@isError={{bool this.errorMessage}}
147137
/>
148-
<<<<<<< HEAD
149138
{{/each}}
150-
=======
151-
{{else if @message.isPreparingCommand}}
152-
<PreparingRoomMessageCommand />
153-
{{/if}}
154-
>>>>>>> dd3d939b8 (Show ApplyButton's preparing state when a command is being prepared)
155139
</AiAssistantMessage>
156140
{{/if}}
157141

packages/host/tests/integration/components/ai-assistant-panel-test.gts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2240,10 +2240,15 @@ module('Integration | ai-assistant-panel', function (hooks) {
22402240
isStreamingFinished: false,
22412241
});
22422242
simulateRemoteMessage(roomId, '@aibot:localhost', {
2243-
msgtype: APP_BOXEL_COMMAND_MSGTYPE,
2243+
msgtype: APP_BOXEL_MESSAGE_MSGTYPE,
22442244
body: 'Changing first name to Evie',
22452245
formatted_body: 'Changing first name to Evie',
22462246
format: 'org.matrix.custom.html',
2247+
[APP_BOXEL_COMMAND_REQUESTS_KEY]: [
2248+
{
2249+
name: 'patchCard',
2250+
},
2251+
],
22472252
isStreamingFinished: false,
22482253
'm.relates_to': {
22492254
rel_type: 'm.replace',

0 commit comments

Comments
 (0)