@crewx/sdk 0.9.0-rc.74 → 0.9.0-rc.76

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.
@@ -0,0 +1,53 @@
1
+ import type { ConversationHighlight, SemanticContinuityContext, TemplateMessage } from '../conversation/types.js';
2
+ export declare const DEFAULT_PROTECTED_TURN_COUNT = 5;
3
+ export declare const DEFAULT_HIGHLIGHT_BUDGET_PERCENT = 5;
4
+ export interface ConversationTurn {
5
+ taskId?: string;
6
+ messages: TemplateMessage[];
7
+ ordinal: number;
8
+ }
9
+ export interface GroupedConversationTurns {
10
+ turns: ConversationTurn[];
11
+ unpairedMessages: TemplateMessage[];
12
+ }
13
+ export interface ConversationTurnSelection {
14
+ includedTurns: ConversationTurn[];
15
+ omittedTurns: ConversationTurn[];
16
+ protectedTurns: ConversationTurn[];
17
+ tokenCount: number;
18
+ protectedTokenCount: number;
19
+ overBudget: boolean;
20
+ }
21
+ export interface SelectConversationTurnsOptions {
22
+ turns: readonly ConversationTurn[];
23
+ maxTokenCount: number;
24
+ countTokens: (text: string) => number;
25
+ protectedTurnCount?: number;
26
+ materializeTurn?: (turn: ConversationTurn) => string;
27
+ }
28
+ export interface ConversationHighlightSelection {
29
+ includedHighlights: ConversationHighlight[];
30
+ omittedHighlights: ConversationHighlight[];
31
+ representedTaskIds: string[];
32
+ unrepresentedTaskIds: string[];
33
+ tokenCount: number;
34
+ budgetTokens: number;
35
+ }
36
+ export interface SelectConversationHighlightsOptions {
37
+ highlights: readonly ConversationHighlight[];
38
+ omittedTaskIds: readonly string[];
39
+ taskOrder: readonly string[];
40
+ maxTokenCount: number;
41
+ countTokens: (text: string) => number;
42
+ }
43
+ export declare function getConversationMessageTaskId(message: TemplateMessage): string | undefined;
44
+ export declare function groupConversationTurns(messages: readonly TemplateMessage[]): GroupedConversationTurns;
45
+ export declare function materializeConversationTurn(turn: ConversationTurn, includeActivityLog?: boolean): string;
46
+ export declare function selectConversationTurns(options: SelectConversationTurnsOptions): ConversationTurnSelection;
47
+ export declare function selectConversationHighlights(options: SelectConversationHighlightsOptions): ConversationHighlightSelection;
48
+ export interface BuildSemanticContinuityContextOptions {
49
+ highlights: readonly ConversationHighlight[];
50
+ omittedTaskIds: readonly string[];
51
+ representedTaskIds: readonly string[];
52
+ }
53
+ export declare function buildSemanticContinuityContext(options: BuildSemanticContinuityContextOptions): SemanticContinuityContext;
@@ -45,6 +45,25 @@ export interface UnresolvedInputBudget {
45
45
  export type ResolveInputBudgetResult = ResolvedInputBudget | UnresolvedInputBudget;
46
46
  export type ContextBudgetPhase = 'fresh' | 'resume';
47
47
  export type ProviderInitialInputFraming = typeof FRESH_PROVIDER_INITIAL_INPUT_FRAMING | typeof RESUME_PROVIDER_INITIAL_INPUT_FRAMING;
48
+ export interface ContextBudgetLayoutCapability {
49
+ layoutId: string;
50
+ supportsSemanticContinuity: boolean;
51
+ slot: string | null;
52
+ requiredForOmittedTurns: boolean;
53
+ warning?: string;
54
+ }
55
+ export interface ContextBudgetActivityDegradation {
56
+ taskId: string;
57
+ taskDistance: number;
58
+ action: 'reduced' | 'omitted';
59
+ }
60
+ export type ContextBudgetAssemblyErrorCode = 'INPUT_BUDGET_EXCEEDED' | 'CONTINUITY_SLOT_REQUIRED';
61
+ export declare class ContextBudgetLayoutError extends Error {
62
+ readonly layoutId: string;
63
+ readonly omittedTurnCount: number;
64
+ readonly code: "CONTINUITY_SLOT_REQUIRED";
65
+ constructor(message: string, layoutId: string, omittedTurnCount: number);
66
+ }
48
67
  export interface ContextBudgetManifest {
49
68
  phase: ContextBudgetPhase;
50
69
  initialInputFraming: ProviderInitialInputFraming;
@@ -68,6 +87,20 @@ export interface ContextBudgetManifest {
68
87
  historyOriginalMessages: number;
69
88
  historyIncludedMessages: number;
70
89
  historyOmittedMessages: number;
90
+ turnOriginal: number;
91
+ turnIncluded: number;
92
+ turnOmitted: number;
93
+ highlightOriginal: number;
94
+ highlightIncluded: number;
95
+ highlightOmitted: number;
96
+ representedOmittedTurns: number;
97
+ unrepresentedOmittedTurns: number;
98
+ activityDegraded: boolean;
99
+ activityIncludedTasks: number;
100
+ activityOmittedTasks: number;
101
+ activityDegradation: ContextBudgetActivityDegradation[];
102
+ highlightLookupFailed: boolean;
103
+ layoutCapability: ContextBudgetLayoutCapability;
71
104
  overBudget: boolean;
72
105
  }
73
106
  export interface TokenCountResult {
@@ -102,4 +135,5 @@ export declare function countFreshProviderInitialInput(input: FreshProviderIniti
102
135
  export declare function createTokenCounter(options?: TokenizerOptions): TokenCounter;
103
136
  export declare function __createTokenCounterForTest(options?: TokenizerOptions, internalOptions?: TokenCounterInternalOptions): TokenCounter;
104
137
  export declare function resolveInputBudget(options: ResolveInputBudgetOptions): ResolveInputBudgetResult;
105
- export {};
138
+ export { DEFAULT_HIGHLIGHT_BUDGET_PERCENT, DEFAULT_PROTECTED_TURN_COUNT, buildSemanticContinuityContext, getConversationMessageTaskId, groupConversationTurns, materializeConversationTurn, selectConversationHighlights, selectConversationTurns, } from './continuity.js';
139
+ export type { BuildSemanticContinuityContextOptions, ConversationHighlightSelection, ConversationTurn, ConversationTurnSelection, GroupedConversationTurns, SelectConversationHighlightsOptions, SelectConversationTurnsOptions, } from './continuity.js';
@@ -1,8 +1,9 @@
1
- import type { ConversationThread, FetchHistoryOptions, IConversationHistoryProvider, Platform } from './types';
1
+ import type { ConversationHighlight, ConversationThread, FetchHistoryOptions, IConversationHistoryProvider, Platform } from './types';
2
2
  export declare class SqliteConversationProvider implements IConversationHistoryProvider {
3
3
  private readonly dbPath;
4
4
  constructor(dbPath?: string);
5
5
  private getThreadRepo;
6
+ private getThreadHistoryRepo;
6
7
  updateThread(id: string, patch: {
7
8
  title?: string;
8
9
  }): void;
@@ -10,6 +11,7 @@ export declare class SqliteConversationProvider implements IConversationHistoryP
10
11
  created: boolean;
11
12
  }>;
12
13
  fetchHistory(threadId: string, options?: FetchHistoryOptions): Promise<ConversationThread>;
14
+ fetchHighlights(threadId: string): Promise<ConversationHighlight[] | undefined>;
13
15
  saveUserMessage(threadId: string, text: string, _userId?: string, _metadata?: Record<string, unknown>): Promise<{
14
16
  id: string;
15
17
  firstMessage: boolean;
@@ -19,5 +21,6 @@ export declare class SqliteConversationProvider implements IConversationHistoryP
19
21
  }>;
20
22
  close(): void;
21
23
  private normalizeStatus;
24
+ private readActiveHighlights;
22
25
  private rowsToMessages;
23
26
  }
@@ -4,13 +4,38 @@ export interface ConversationMessage {
4
4
  text: string;
5
5
  isAssistant: boolean;
6
6
  timestamp: number;
7
+ taskId?: string;
7
8
  metadata?: Record<string, unknown>;
8
9
  }
9
10
  export type Platform = 'cli' | 'web' | 'api' | 'mcp' | `channel/${string}`;
11
+ export interface ConversationHighlight {
12
+ id: string;
13
+ text: string;
14
+ kind?: string;
15
+ source?: string;
16
+ coversFromTaskId?: string;
17
+ coversToTaskId?: string;
18
+ covers_from_task_id?: string;
19
+ covers_to_task_id?: string;
20
+ createdAt?: number | string;
21
+ created_at?: number | string;
22
+ }
23
+ export interface SemanticContinuityContext {
24
+ highlights: ConversationHighlight[];
25
+ omittedTurns: {
26
+ count: number;
27
+ represented: number;
28
+ unrepresented: number;
29
+ taskIds: string[];
30
+ };
31
+ rendered?: string;
32
+ }
33
+ export type ConversationSemanticContinuityContext = SemanticContinuityContext;
10
34
  export interface ConversationThread {
11
35
  threadId: string;
12
36
  platform: Platform;
13
37
  messages: ConversationMessage[];
38
+ highlights?: ConversationHighlight[];
14
39
  metadata?: {
15
40
  title?: string;
16
41
  firstMessage?: string;
@@ -20,8 +45,10 @@ export interface ConversationThread {
20
45
  };
21
46
  }
22
47
  export interface TemplateMessage {
48
+ id?: string;
23
49
  text: string;
24
50
  isAssistant: boolean;
51
+ taskId?: string;
25
52
  timestamp?: number;
26
53
  metadata?: Record<string, unknown>;
27
54
  activity_log?: string;
@@ -41,6 +68,7 @@ export interface IConversationHistoryProvider {
41
68
  created: boolean;
42
69
  }>;
43
70
  fetchHistory(threadId: string, options?: FetchHistoryOptions): Promise<ConversationThread>;
71
+ fetchHighlights?(threadId: string): Promise<ConversationHighlight[] | undefined>;
44
72
  saveUserMessage(threadId: string, text: string, userId?: string, metadata?: Record<string, unknown>): Promise<{
45
73
  id: string;
46
74
  firstMessage: boolean;