indusagi 0.12.11 → 0.12.12

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.
package/README.md CHANGED
@@ -11,6 +11,8 @@ All-in-one package that bundles:
11
11
 
12
12
  Use this package if you want a single dependency for the core Indusagi SDK stack.
13
13
 
14
+ Docs: https://www.indusagi.com
15
+
14
16
  For the CLI, install `indusagi-coding-agent` globally:
15
17
 
16
18
  ```bash
@@ -3,4 +3,6 @@ export * from "./agent-loop.js";
3
3
  export * from "./proxy.js";
4
4
  export * from "./types.js";
5
5
  export * from "./tools/index.js";
6
+ export * from "./messages.js";
7
+ export * from "./session-manager.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAEhC,cAAc,YAAY,CAAC;AAE3B,cAAc,YAAY,CAAC;AAE3B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAEhC,cAAc,YAAY,CAAC;AAE3B,cAAc,YAAY,CAAC;AAE3B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
@@ -8,4 +8,7 @@ export * from "./proxy.js";
8
8
  export * from "./types.js";
9
9
  // Tools
10
10
  export * from "./tools/index.js";
11
+ // Session management and messages
12
+ export * from "./messages.js";
13
+ export * from "./session-manager.js";
11
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAC3B,iBAAiB;AACjB,cAAc,iBAAiB,CAAC;AAChC,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAC3B,QAAQ;AACR,cAAc,YAAY,CAAC;AAC3B,QAAQ;AACR,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAC3B,iBAAiB;AACjB,cAAc,iBAAiB,CAAC;AAChC,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAC3B,QAAQ;AACR,cAAc,YAAY,CAAC;AAC3B,QAAQ;AACR,cAAc,kBAAkB,CAAC;AACjC,kCAAkC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Custom message types and transformers for agent sessions.
3
+ *
4
+ * Extends the base AgentMessage type with session-related message types,
5
+ * and provides a transformer to convert them to LLM-compatible messages.
6
+ */
7
+ import type { AgentMessage } from "./types.js";
8
+ import type { ImageContent, Message, TextContent } from "../ai/index.js";
9
+ export declare const COMPACTION_SUMMARY_PREFIX = "The conversation history before this point was compacted into the following summary:\n\n<summary>\n";
10
+ export declare const COMPACTION_SUMMARY_SUFFIX = "\n</summary>";
11
+ export declare const BRANCH_SUMMARY_PREFIX = "The following is a summary of a branch that this conversation came back from:\n\n<summary>\n";
12
+ export declare const BRANCH_SUMMARY_SUFFIX = "</summary>";
13
+ /**
14
+ * Message type for bash executions via the ! command.
15
+ */
16
+ export interface BashExecutionMessage {
17
+ role: "bashExecution";
18
+ command: string;
19
+ output: string;
20
+ exitCode: number | undefined;
21
+ cancelled: boolean;
22
+ truncated: boolean;
23
+ fullOutputPath?: string;
24
+ timestamp: number;
25
+ /** If true, this message is excluded from LLM context (!! prefix) */
26
+ excludeFromContext?: boolean;
27
+ }
28
+ /**
29
+ * Message type for extension-injected messages via sendMessage().
30
+ * These are custom messages that extensions can inject into the conversation.
31
+ */
32
+ export interface CustomMessage<T = unknown> {
33
+ role: "custom";
34
+ customType: string;
35
+ content: string | (TextContent | ImageContent)[];
36
+ display: boolean;
37
+ details?: T;
38
+ timestamp: number;
39
+ }
40
+ export interface BranchSummaryMessage {
41
+ role: "branchSummary";
42
+ summary: string;
43
+ fromId: string;
44
+ timestamp: number;
45
+ }
46
+ export interface CompactionSummaryMessage {
47
+ role: "compactionSummary";
48
+ summary: string;
49
+ tokensBefore: number;
50
+ timestamp: number;
51
+ }
52
+ declare module "indusagi/agent" {
53
+ interface CustomAgentMessages {
54
+ bashExecution: BashExecutionMessage;
55
+ custom: CustomMessage;
56
+ branchSummary: BranchSummaryMessage;
57
+ compactionSummary: CompactionSummaryMessage;
58
+ }
59
+ }
60
+ /**
61
+ * Convert a BashExecutionMessage to user message text for LLM context.
62
+ */
63
+ export declare function bashExecutionToText(msg: BashExecutionMessage): string;
64
+ export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage;
65
+ export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string): CompactionSummaryMessage;
66
+ /** Convert CustomMessageEntry to AgentMessage format */
67
+ export declare function createCustomMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown | undefined, timestamp: string): CustomMessage;
68
+ /**
69
+ * Transform AgentMessages (including custom types) to LLM-compatible Messages.
70
+ *
71
+ * This is used by:
72
+ * - Agent's transformToLlm option (for prompt calls and queued messages)
73
+ * - Compaction's generateSummary (for summarization)
74
+ * - Custom extensions and tools
75
+ */
76
+ export declare function convertToLlm(messages: AgentMessage[]): Message[];
77
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/agent/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,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AAE,aAAa,CAAC;QACtB,aAAa,EAAE,oBAAoB,CAAC;QACpC,iBAAiB,EAAE,wBAAwB,CAAC;KAC5C;CACD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,MAAM,CAgBrE;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,oBAAoB,CAOnH;AAED,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GACf,wBAAwB,CAO1B;AAED,wDAAwD;AACxD,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,EAChD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GACf,aAAa,CASf;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CA+ChE"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Custom message types and transformers for agent sessions.
3
+ *
4
+ * Extends the base AgentMessage type with session-related message types,
5
+ * and provides a transformer to convert them to LLM-compatible messages.
6
+ */
7
+ export const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;
8
+ export const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;
9
+ export const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;
10
+ export const BRANCH_SUMMARY_SUFFIX = `</summary>`;
11
+ /**
12
+ * Convert a BashExecutionMessage to user message text for LLM context.
13
+ */
14
+ export function bashExecutionToText(msg) {
15
+ let text = `Ran \`${msg.command}\`\n`;
16
+ if (msg.output) {
17
+ text += `\`\`\`\n${msg.output}\n\`\`\``;
18
+ }
19
+ else {
20
+ text += "(no output)";
21
+ }
22
+ if (msg.cancelled) {
23
+ text += "\n\n(command cancelled)";
24
+ }
25
+ else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {
26
+ text += `\n\nCommand exited with code ${msg.exitCode}`;
27
+ }
28
+ if (msg.truncated && msg.fullOutputPath) {
29
+ text += `\n\n[Output truncated. Full output: ${msg.fullOutputPath}]`;
30
+ }
31
+ return text;
32
+ }
33
+ export function createBranchSummaryMessage(summary, fromId, timestamp) {
34
+ return {
35
+ role: "branchSummary",
36
+ summary,
37
+ fromId,
38
+ timestamp: new Date(timestamp).getTime(),
39
+ };
40
+ }
41
+ export function createCompactionSummaryMessage(summary, tokensBefore, timestamp) {
42
+ return {
43
+ role: "compactionSummary",
44
+ summary: summary,
45
+ tokensBefore,
46
+ timestamp: new Date(timestamp).getTime(),
47
+ };
48
+ }
49
+ /** Convert CustomMessageEntry to AgentMessage format */
50
+ export function createCustomMessage(customType, content, display, details, timestamp) {
51
+ return {
52
+ role: "custom",
53
+ customType,
54
+ content,
55
+ display,
56
+ details,
57
+ timestamp: new Date(timestamp).getTime(),
58
+ };
59
+ }
60
+ /**
61
+ * Transform AgentMessages (including custom types) to LLM-compatible Messages.
62
+ *
63
+ * This is used by:
64
+ * - Agent's transformToLlm option (for prompt calls and queued messages)
65
+ * - Compaction's generateSummary (for summarization)
66
+ * - Custom extensions and tools
67
+ */
68
+ export function convertToLlm(messages) {
69
+ return messages
70
+ .map((m) => {
71
+ switch (m.role) {
72
+ case "bashExecution":
73
+ // Skip messages excluded from context (!! prefix)
74
+ if (m.excludeFromContext) {
75
+ return undefined;
76
+ }
77
+ return {
78
+ role: "user",
79
+ content: [{ type: "text", text: bashExecutionToText(m) }],
80
+ timestamp: m.timestamp,
81
+ };
82
+ case "custom": {
83
+ const content = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content;
84
+ return {
85
+ role: "user",
86
+ content,
87
+ timestamp: m.timestamp,
88
+ };
89
+ }
90
+ case "branchSummary":
91
+ return {
92
+ role: "user",
93
+ content: [{ type: "text", text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],
94
+ timestamp: m.timestamp,
95
+ };
96
+ case "compactionSummary":
97
+ return {
98
+ role: "user",
99
+ content: [
100
+ { type: "text", text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },
101
+ ],
102
+ timestamp: m.timestamp,
103
+ };
104
+ case "user":
105
+ case "assistant":
106
+ case "toolResult":
107
+ return m;
108
+ default:
109
+ // biome-ignore lint/correctness/noSwitchDeclarations: intentional exhaustiveness
110
+ const _exhaustiveCheck = m;
111
+ return undefined;
112
+ }
113
+ })
114
+ .filter((m) => m !== undefined);
115
+ }
116
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/agent/messages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,CAAC,MAAM,yBAAyB,GAAG,qGAAqG,CAAC;AAE/I,MAAM,CAAC,MAAM,yBAAyB,GAAG,cAAc,CAAC;AAExD,MAAM,CAAC,MAAM,qBAAqB,GAAG,8FAA8F,CAAC;AAEpI,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAuDlD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAyB;IAC5D,IAAI,IAAI,GAAG,SAAS,GAAG,CAAC,OAAO,MAAM,CAAC;IACtC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAChB,IAAI,IAAI,WAAW,GAAG,CAAC,MAAM,UAAU,CAAC;IACzC,CAAC;SAAM,CAAC;QACP,IAAI,IAAI,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;QACnB,IAAI,IAAI,yBAAyB,CAAC;IACnC,CAAC;SAAM,IAAI,GAAG,CAAC,QAAQ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