Skip to content

Commit 3da17c3

Browse files
committed
wip
1 parent e00a121 commit 3da17c3

File tree

2 files changed

+34
-23
lines changed
  • typescript-sdk
    • apps/dojo/src/app/[integrationId]/feature/agentic_chat
    • integrations/mastra/src

2 files changed

+34
-23
lines changed

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/agentic_chat/page.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ const Chat = () => {
3131

3232
const { state: agentState, setState: setAgentState } = useCoAgent({
3333
name: "agentic_chat",
34-
initialState: {
35-
firstName: "Markus",
36-
},
34+
// initialState: {
35+
// firstName: "Markus",
36+
// },
3737
});
3838

39-
delete (agentState as any).messages;
40-
4139
console.log(agentState);
4240

4341
useCopilotAction({

typescript-sdk/integrations/mastra/src/index.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ export class MastraAgent extends AbstractAgent {
175175
}
176176

177177
protected run(input: RunAgentInput): Observable<BaseEvent> {
178+
console.log("STATE INPUT", input.state);
179+
178180
const finalMessages: Message[] = [...input.messages];
179181
let messageId = randomUUID();
180182
let assistantMessage: AssistantMessage = {
@@ -194,32 +196,34 @@ export class MastraAgent extends AbstractAgent {
194196
} as RunStartedEvent);
195197

196198
// Handle local agent memory management (from Mastra implementation)
197-
if ('metrics' in this.agent) {
199+
if ("metrics" in this.agent) {
198200
const memory = this.agent.getMemory();
199201

200202
if (memory && input.state && Object.keys(input.state || {}).length > 0) {
201-
let thread: StorageThreadType | null = await memory.getThreadById({ threadId: input.threadId });
203+
let thread: StorageThreadType | null = await memory.getThreadById({
204+
threadId: input.threadId,
205+
});
202206

203207
if (!thread) {
204208
thread = {
205209
id: input.threadId,
206-
title: '',
210+
title: "",
207211
metadata: {},
208-
resourceId: this.resourceId as string,
212+
resourceId: this.resourceId ?? input.threadId,
209213
createdAt: new Date(),
210214
updatedAt: new Date(),
211215
};
212216
}
213217

214-
if (thread.resourceId && thread.resourceId !== this.resourceId) {
215-
throw new Error(
216-
`Thread with id ${input.threadId} resourceId does not match the current resourceId ${this.resourceId}`,
217-
);
218-
}
218+
// if (thread.resourceId && thread.resourceId !== this.resourceId) {
219+
// throw new Error(
220+
// `Thread with id ${input.threadId} resourceId does not match the current resourceId ${this.resourceId}`,
221+
// );
222+
// }
219223

220224
const { messages, ...rest } = input.state;
221225
const workingMemory = JSON.stringify(rest);
222-
226+
223227
// Update thread metadata with new working memory
224228
await memory.saveThread({
225229
thread: {
@@ -294,10 +298,16 @@ export class MastraAgent extends AbstractAgent {
294298
};
295299
subscriber.next(event);
296300

297-
if ('metrics' in this.agent){
301+
if ("metrics" in this.agent) {
298302
const memory = this.agent.getMemory();
299303
if (memory) {
300-
const workingMemory = await memory.getWorkingMemory({ threadId: input.threadId, format: 'json' });
304+
const workingMemory = await memory.getWorkingMemory({
305+
threadId: input.threadId,
306+
format: "json",
307+
});
308+
309+
console.log(">>> workingMemory", workingMemory);
310+
301311
subscriber.next({
302312
type: EventType.STATE_SNAPSHOT,
303313
snapshot: workingMemory,
@@ -383,9 +393,12 @@ export class MastraAgent extends AbstractAgent {
383393

384394
// For local agents, the response should already be a stream
385395
// Process it using the agent's built-in streaming mechanism
386-
if (response && typeof response === 'object') {
396+
if (response && typeof response === "object") {
387397
// If the response has a toDataStreamResponse method, use it
388-
if ('toDataStreamResponse' in response && typeof response.toDataStreamResponse === 'function') {
398+
if (
399+
"toDataStreamResponse" in response &&
400+
typeof response.toDataStreamResponse === "function"
401+
) {
389402
const dataStreamResponse = response.toDataStreamResponse();
390403
if (dataStreamResponse && dataStreamResponse.body) {
391404
await processDataStream({
@@ -396,7 +409,7 @@ export class MastraAgent extends AbstractAgent {
396409
onFinishMessagePart,
397410
});
398411
} else {
399-
throw new Error('Invalid data stream response from local agent');
412+
throw new Error("Invalid data stream response from local agent");
400413
}
401414
} else {
402415
// If it's already a readable stream, process it directly
@@ -409,7 +422,7 @@ export class MastraAgent extends AbstractAgent {
409422
});
410423
}
411424
} else {
412-
throw new Error('Invalid response from local agent');
425+
throw new Error("Invalid response from local agent");
413426
}
414427
} catch (error) {
415428
onError?.(error as Error);
@@ -426,15 +439,15 @@ export class MastraAgent extends AbstractAgent {
426439
});
427440

428441
// Remote agents should have a processDataStream method
429-
if (response && typeof response.processDataStream === 'function') {
442+
if (response && typeof response.processDataStream === "function") {
430443
await response.processDataStream({
431444
onTextPart,
432445
onToolCallPart,
433446
onToolResultPart,
434447
onFinishMessagePart,
435448
});
436449
} else {
437-
throw new Error('Invalid response from remote agent');
450+
throw new Error("Invalid response from remote agent");
438451
}
439452
} catch (error) {
440453
onError?.(error as Error);

0 commit comments

Comments
 (0)