@hahnfeld/teams-adapter 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,20 @@
1
1
  /**
2
- * Message composer — manages a single "main message" per session in Teams.
2
+ * Message composer — manages a single Adaptive Card per session in Teams.
3
3
  *
4
- * Emulates Claude Code's terminal UX using Adaptive Cards:
5
- * - Title: bold, persistent — session name
6
- * - Thinking blocks: italic, 💭 prefix, ALWAYS append (never replaced)
7
- * - Tool progress: 🔄 Running... with elapsed time, persistent as historical record
8
- * - Tool result: 📄 Result... appears AFTER progress (both coexist)
9
- * - Streaming text: root-level, appended
10
- * - Usage: italic footer, persistent
4
+ * Every message type renders into the same card, updated in-place via REST PUT.
11
5
  *
12
- * Tool output during execution is indented as children under the tool block.
13
- * When a tool completes, a NEW tool-result entry is appended — the progress
14
- * entry stays as a historical record (matching Claude Code's behavior).
6
+ * Entry types:
7
+ * - title: Bold session name, always first
8
+ * - timed: Two-level Container with live timer (tool, thinking)
9
+ * - info: Two-level Container, no timer (error, system, mode, config, model)
10
+ * - text: Root-level streamed text, always at bottom
11
+ * - plan: Formatted plan list, updated in place
12
+ * - resource: Inline 📎 line (attachments, resources, resource links)
13
+ * - usage: Italic footer, singleton
14
+ * - divider: Horizontal rule
15
+ *
16
+ * Level 2 lines use a 3-column ColumnSet for true indentation:
17
+ * Column 1: spacer (20px) | Column 2: ⎿ (auto) | Column 3: content (stretch, wrap)
15
18
  */
16
19
  import type { TurnContext } from "@microsoft/agents-hosting";
17
20
  import type { ConversationRateLimiter } from "./rate-limiter.js";
@@ -21,6 +24,18 @@ export interface MessageRef {
21
24
  serviceUrl: string;
22
25
  }
23
26
  export type AcquireBotToken = () => Promise<string | null>;
27
+ export declare function escapeMd(text: string): string;
28
+ /**
29
+ * Build a 2-column ColumnSet for level-1 headings.
30
+ * Column 1: emoji (auto), Column 2: text (stretch, wrap).
31
+ * Ensures long text wraps without breaking back to the left margin.
32
+ */
33
+ export declare function buildLevel1(emoji: string, text: string): Record<string, unknown>;
34
+ /**
35
+ * Build a 3-column ColumnSet for indented level-2 content.
36
+ * Column 1: spacer (20px), Column 2: ⎿ (auto), Column 3: content (stretch, wrap).
37
+ */
38
+ export declare function buildLevel2(text: string, elapsed?: string, raw?: boolean): Record<string, unknown>;
24
39
  export declare class SessionMessage {
25
40
  private context;
26
41
  private conversationId;
@@ -30,94 +45,88 @@ export declare class SessionMessage {
30
45
  private entries;
31
46
  private titleId;
32
47
  private usageId;
33
- /** The active tool whose children accumulate streaming output */
34
- private toolActive;
48
+ private planId;
49
+ private thinkingActive;
50
+ private thinkingText;
51
+ private working;
52
+ private workingFrame;
53
+ private destroyed;
35
54
  private ref;
36
55
  private lastSent;
37
56
  private stallTimer?;
38
- /** Interval handle for periodic elapsed-time updates on running tools */
39
57
  private tickInterval?;
58
+ private emptyCardTimer?;
40
59
  constructor(context: TurnContext, conversationId: string, sessionId: string, rateLimiter: ConversationRateLimiter, acquireBotToken: AcquireBotToken);
41
60
  updateContext(context: TurnContext): void;
42
61
  getRef(): MessageRef | null;
43
62
  getBody(): string;
44
63
  getFooter(): string | null;
45
- /** Set the persistent session title (bold, survives finalize). */
64
+ /** Cancel the empty-card timer (called when real content arrives). */
65
+ private cancelEmptyCardTimer;
66
+ /** If no real content was added, delete the card activity and clean up. */
67
+ private deleteIfEmpty;
68
+ /** Set the persistent session title (bold, always first entry). */
46
69
  setTitle(text: string): void;
47
70
  /**
48
- * Add a tool-progress entry (🔄 Running...). Sets toolActive so subsequent
49
- * addText() calls route children here. Returns entry id for tracking.
71
+ * Start a timed entry (tool or thinking). Shows emoji + label with live elapsed timer.
72
+ * Returns the entry ID for pairing with addTimedResult().
50
73
  */
51
- addToolStart(toolName: string, _params?: string): string;
74
+ addTimedStart(emoji: string, label: string): string;
52
75
  /**
53
- * Add a tool-result entry (📄 Result...). Creates a NEW entry does NOT
54
- * replace the tool-progress entry. Both coexist as historical record.
55
- * Clears toolActive so subsequent addText() goes to root body.
76
+ * Close a timed entry by setting its result. Stops the tick interval if no
77
+ * other timed entries are still running.
56
78
  */
57
- addToolResult(id: string, result: string): void;
58
- /** Add text — goes to toolActive children if a tool is running, else root text entry. */
59
- addText(text: string): void;
79
+ addTimedResult(id: string, result: string): void;
60
80
  /**
61
- * Always append a new thought entry (thoughts persist, never replaced).
62
- * Multiple thinking blocks can coexist each is a historical record.
81
+ * Start or accumulate thinking text. The first call creates a timed entry;
82
+ * subsequent calls append to the pending result text. Call closeActiveThinking()
83
+ * to finalize.
63
84
  */
64
- addThought(text: string): void;
65
- /** Set or replace the usage entry (only one at a time). */
85
+ addThinking(text: string): void;
86
+ /**
87
+ * Close the active thinking entry (if any). Called by non-thought handlers
88
+ * so thinking ends when the next event type arrives.
89
+ */
90
+ closeActiveThinking(): void;
91
+ /** Add a one-shot info entry (error, system, mode, config, model). */
92
+ addInfo(emoji: string, label: string, detail: string): void;
93
+ /** Add or replace the plan entry. */
94
+ setPlan(entries: {
95
+ content: string;
96
+ status: string;
97
+ }[]): void;
98
+ /** Add text — always appended at root level. */
99
+ addText(text: string): void;
100
+ /** Add an inline resource line (📎 prefix). */
101
+ addResource(text: string): void;
102
+ /** Set or replace the usage footer. Stops the working animation. */
66
103
  setUsage(text: string): void;
67
104
  /** Add a divider entry. */
68
105
  appendDivider(): void;
69
106
  private findEntry;
70
- private removeEntry;
71
- /**
72
- * Start a 1-second interval that updates elapsed time on running tool-progress
73
- * entries. Called when a tool starts, stopped when tool completes or finalize.
74
- */
75
107
  private startTickInterval;
76
108
  private stopTickInterval;
77
109
  private buildCard;
110
+ private flushTimer?;
78
111
  private requestFlush;
79
112
  private flush;
80
113
  private updateCardViaRest;
81
114
  private resetStallTimer;
82
115
  finalize(): Promise<MessageRef | null>;
83
- /** Legacy compat — strip pattern from root text entries. */
116
+ /** Strip a pattern from root text entries. */
84
117
  stripPattern(pattern: RegExp): Promise<void>;
85
- /**
86
- * Check if root text exceeds limit and split into a new message.
87
- * Called from addText when a message is already sent (this.ref != null).
88
- */
89
118
  private checkSplit;
90
- /** For split: finalize current message at limit, start fresh. */
91
119
  private split;
92
- /** @deprecated — use addThought instead */
93
- setHeader(_text: string): void;
94
- /** @deprecated — use addToolResult instead */
95
- setHeaderResult(_text: string): void;
96
- /** @deprecated — use addText instead */
97
- appendBody(text: string): void;
98
- /** @deprecated — use setUsage instead */
99
- setFooter(text: string): void;
100
- /** @deprecated — use setUsage instead */
101
- appendFooter(text: string): void;
102
- /** @deprecated — header zone is gone */
103
- clearHeader(): void;
104
- /** @deprecated — thoughts persist, use addThought */
105
- removeThought(): void;
106
- /** @deprecated — use addToolStart + addToolResult */
107
- updateToolResult(_id: string, _result: string): void;
108
120
  }
109
121
  export declare class SessionMessageManager {
110
122
  private rateLimiter;
111
123
  private acquireBotToken;
112
124
  private messages;
113
- private planRefs;
114
125
  constructor(rateLimiter: ConversationRateLimiter, acquireBotToken: AcquireBotToken);
115
126
  getOrCreate(sessionId: string, context: TurnContext): SessionMessage;
116
127
  get(sessionId: string): SessionMessage | undefined;
117
128
  has(sessionId: string): boolean;
118
129
  finalize(sessionId: string): Promise<MessageRef | null>;
119
- getPlanRef(sessionId: string): MessageRef | undefined;
120
- setPlanRef(sessionId: string, ref: MessageRef): void;
121
130
  cleanup(sessionId: string): void;
122
131
  }
123
132
  //# sourceMappingURL=message-composer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message-composer.d.ts","sourceRoot":"","sources":["../src/message-composer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAIjE,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,eAA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