@@ -2,8 +2,11 @@ import * as asana from "asana";
22
33import {
44 type ActivityLink ,
5+ ActivityLinkType ,
56 ActivityType ,
67 type NewActivityWithNotes ,
8+ type NewNote ,
9+ Uuid ,
710} from "@plotday/twister" ;
811import type {
912 Project ,
@@ -269,8 +272,8 @@ export class Asana extends Tool<Asana> implements ProjectTool {
269272 for ( const task of tasksResult . data ) {
270273 // Optionally filter by time
271274 if ( options ?. timeMin ) {
272- const createdAt = new Date ( task . created_at ) ;
273- if ( createdAt < options . timeMin ) {
275+ const created = new Date ( task . created_at ) ;
276+ if ( created < options . timeMin ) {
274277 continue ;
275278 }
276279 }
@@ -339,28 +342,46 @@ export class Asana extends Tool<Asana> implements ProjectTool {
339342 } ;
340343 }
341344
342- // Build notes array: description
343- const notes : Array < { content : string } > = [ ] ;
345+ // Build notes array: always create initial note with description and link
346+ const notes : NewNote [ ] = [ ] ;
344347
348+ // Extract description (if any)
349+ let description : string | null = null ;
345350 if ( task . notes ) {
346- notes . push ( { content : task . notes } ) ;
351+ description = task . notes ;
347352 }
348353
349- // Ensure at least one note exists
350- if ( notes . length === 0 ) {
351- notes . push ( { content : "" } ) ;
352- }
354+ // Construct Asana task URL
355+ const taskUrl = `https://app.asana.com/0/${ projectId } /${ task . gid } ` ;
356+
357+ // Create initial note with description and link to Asana task
358+ const links : ActivityLink [ ] = [ ] ;
359+ links . push ( {
360+ type : ActivityLinkType . external ,
361+ title : `Open in Asana` ,
362+ url : taskUrl ,
363+ } ) ;
364+
365+ notes . push ( {
366+ activity : { source : taskUrl } ,
367+ key : "description" ,
368+ content : description ,
369+ created : task . created_at ? new Date ( task . created_at ) : undefined ,
370+ links : links . length > 0 ? links : null ,
371+ } ) ;
353372
354373 return {
374+ source : taskUrl ,
355375 type : ActivityType . Action ,
356376 title : task . name ,
377+ created : task . created_at ? new Date ( task . created_at ) : undefined ,
357378 meta : {
358- source : `asana:task:${ projectId } :${ task . gid } ` ,
359379 taskGid : task . gid ,
380+ projectId,
360381 } ,
361382 author : authorContact ,
362- assignee : assigneeContact ,
363- doneAt : task . completed ? new Date ( task . completed_at || Date . now ( ) ) : null ,
383+ assignee : assigneeContact ?? null , // Explicitly set to null for unassigned tasks
384+ done : task . completed && task . completed_at ? new Date ( task . completed_at ) : null ,
364385 notes,
365386 } ;
366387 }
@@ -395,10 +416,10 @@ export class Asana extends Tool<Asana> implements ProjectTool {
395416 updateFields . assignee = update . assignee ?. id || null ;
396417 }
397418
398- // Handle completion status based on doneAt
419+ // Handle completion status based on done
399420 // Asana only has completed boolean (no In Progress state)
400- if ( update . doneAt !== undefined ) {
401- updateFields . completed = update . doneAt !== null ;
421+ if ( update . done !== undefined ) {
422+ updateFields . completed = update . done !== null ;
402423 }
403424
404425 // Apply updates if any fields changed
0 commit comments