@allternit/gizzi-code 1.0.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.
- package/WORKSPACE_INTEGRATION.md +290 -0
- package/chat-sessions/sessions-index.json +98 -0
- package/package.json +43 -0
- package/package.json.original +31 -0
- package/package.json.publish +47 -0
- package/src/bootstrap/state.d.ts +169 -0
- package/src/bootstrap/state.js +261 -0
- package/src/bootstrap/state.ts +371 -0
- package/src/context/pack-builder.d.ts +24 -0
- package/src/context/pack-builder.js +281 -0
- package/src/context/pack-builder.ts +334 -0
- package/src/hooks/useExitOnCtrlCD.d.ts +86 -0
- package/src/hooks/useExitOnCtrlCD.js +130 -0
- package/src/hooks/useExitOnCtrlCD.ts +202 -0
- package/src/hooks/useKeybinding.d.ts +89 -0
- package/src/hooks/useKeybinding.js +163 -0
- package/src/hooks/useKeybinding.ts +226 -0
- package/src/hooks/useTerminalSize.d.ts +41 -0
- package/src/hooks/useTerminalSize.js +90 -0
- package/src/hooks/useTerminalSize.ts +117 -0
- package/src/index.d.ts +23 -0
- package/src/index.js +24 -0
- package/src/index.ts +132 -0
- package/src/runtime/brand/brand.d.ts +488 -0
- package/src/runtime/brand/brand.js +464 -0
- package/src/runtime/brand/brand.ts +667 -0
- package/src/runtime/services/tokenEstimation.d.ts +187 -0
- package/src/runtime/services/tokenEstimation.js +423 -0
- package/src/runtime/services/tokenEstimation.ts +547 -0
- package/src/runtime/tools/Tool.d.ts +239 -0
- package/src/runtime/tools/Tool.js +285 -0
- package/src/runtime/tools/Tool.ts +524 -0
- package/src/scheduler/TaskScheduler.d.ts +98 -0
- package/src/scheduler/TaskScheduler.js +201 -0
- package/src/scheduler/TaskScheduler.ts +259 -0
- package/src/state/AppStateStore.d.ts +347 -0
- package/src/state/AppStateStore.js +439 -0
- package/src/state/AppStateStore.ts +658 -0
- package/src/state/WorkspaceStateStore.d.ts +43 -0
- package/src/state/WorkspaceStateStore.js +224 -0
- package/src/state/WorkspaceStateStore.ts +297 -0
- package/src/types/message.d.ts +190 -0
- package/src/types/message.js +77 -0
- package/src/types/message.ts +277 -0
- package/src/utils/format.d.ts +126 -0
- package/src/utils/format.js +230 -0
- package/src/utils/format.ts +336 -0
- package/src/utils/fullscreen.d.ts +161 -0
- package/src/utils/fullscreen.js +277 -0
- package/src/utils/fullscreen.ts +382 -0
- package/src/utils/sessionStorage.d.ts +210 -0
- package/src/utils/sessionStorage.js +435 -0
- package/src/utils/sessionStorage.ts +559 -0
- package/src/watcher/WorkspaceWatcher.d.ts +70 -0
- package/src/watcher/WorkspaceWatcher.js +191 -0
- package/src/watcher/WorkspaceWatcher.ts +251 -0
- package/src/workspace/loader.d.ts +30 -0
- package/src/workspace/loader.js +117 -0
- package/src/workspace/loader.ts +171 -0
- package/src/workspace/types.d.ts +91 -0
- package/src/workspace/types.js +7 -0
- package/src/workspace/types.ts +122 -0
- package/threads/thread_1775361175022.json +9 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gizzi Workspace State Store
|
|
3
|
+
*
|
|
4
|
+
* Enhanced state management with workspace/agent context integration
|
|
5
|
+
* Extends AppStateStore with agent workspace capabilities
|
|
6
|
+
*/
|
|
7
|
+
import { AppStateStore } from './AppStateStore';
|
|
8
|
+
import { loadWorkspace, executeStartupTasks, enhanceSessionWithWorkspace } from '../workspace/loader';
|
|
9
|
+
import { shouldRefreshContext } from '../context/pack-builder';
|
|
10
|
+
import { TaskScheduler } from '../scheduler/TaskScheduler';
|
|
11
|
+
import { getWorkspaceWatcher } from '../watcher/WorkspaceWatcher';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Workspace State Store
|
|
14
|
+
// ============================================================================
|
|
15
|
+
export class WorkspaceStateStore extends AppStateStore {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.workspaceState = {
|
|
19
|
+
session: null,
|
|
20
|
+
contextPack: null,
|
|
21
|
+
isAgentMode: false,
|
|
22
|
+
};
|
|
23
|
+
this.fs = null;
|
|
24
|
+
this.basePath = '';
|
|
25
|
+
this.workspaceWatcher = null;
|
|
26
|
+
this.taskScheduler = new TaskScheduler({
|
|
27
|
+
onTaskExecute: async (job) => {
|
|
28
|
+
console.log(`[WorkspaceStateStore] Executing scheduled task: ${job.taskId}`);
|
|
29
|
+
// Add system message for task execution
|
|
30
|
+
this.addMessage({
|
|
31
|
+
id: `scheduled-${Date.now()}`,
|
|
32
|
+
role: 'system',
|
|
33
|
+
content: `[Scheduled Task] Executing: ${job.taskId}`,
|
|
34
|
+
systemType: 'info',
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
setFileSystem(fs, basePath) {
|
|
40
|
+
this.fs = fs;
|
|
41
|
+
this.basePath = basePath;
|
|
42
|
+
}
|
|
43
|
+
// ========================================================================
|
|
44
|
+
// Agent Mode Activation
|
|
45
|
+
// ========================================================================
|
|
46
|
+
async activateAgentMode(agentId, agentName) {
|
|
47
|
+
if (!this.fs || !this.basePath) {
|
|
48
|
+
console.error('[WorkspaceStateStore] FileSystem not configured');
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
console.log(`[WorkspaceStateStore] Activating agent mode: ${agentName}`);
|
|
52
|
+
try {
|
|
53
|
+
// Load workspace
|
|
54
|
+
const workspace = await loadWorkspace({
|
|
55
|
+
agentId,
|
|
56
|
+
agentName,
|
|
57
|
+
sessionId: this.workspaceState.session?.id || `session-${Date.now()}`,
|
|
58
|
+
fs: this.fs,
|
|
59
|
+
basePath: this.basePath,
|
|
60
|
+
});
|
|
61
|
+
if (!workspace) {
|
|
62
|
+
console.log('[WorkspaceStateStore] No workspace found, using default agent settings');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// Execute startup tasks
|
|
66
|
+
await executeStartupTasks(workspace.startupTasks, (content) => {
|
|
67
|
+
// Send startup task message if needed
|
|
68
|
+
this.addMessage({
|
|
69
|
+
id: `system-${Date.now()}`,
|
|
70
|
+
role: 'system',
|
|
71
|
+
content,
|
|
72
|
+
systemType: 'info',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
// Register recurring tasks with scheduler
|
|
76
|
+
const recurringTasks = workspace.startupTasks
|
|
77
|
+
.filter(t => t.frequency !== 'startup')
|
|
78
|
+
.map(t => ({
|
|
79
|
+
id: t.id,
|
|
80
|
+
action: t.action,
|
|
81
|
+
frequency: t.frequency,
|
|
82
|
+
completed: false,
|
|
83
|
+
}));
|
|
84
|
+
if (recurringTasks.length > 0) {
|
|
85
|
+
this.taskScheduler.registerTasks(agentId, recurringTasks);
|
|
86
|
+
this.taskScheduler.start();
|
|
87
|
+
console.log(`[WorkspaceStateStore] Started task scheduler with ${recurringTasks.length} recurring tasks`);
|
|
88
|
+
}
|
|
89
|
+
// Setup file watcher for auto-refresh
|
|
90
|
+
if (this.fs && this.basePath) {
|
|
91
|
+
this.workspaceWatcher = getWorkspaceWatcher(agentId, this.basePath, this.fs, {
|
|
92
|
+
pollIntervalMs: 5000,
|
|
93
|
+
onChange: (changes) => {
|
|
94
|
+
console.log(`[WorkspaceStateStore] Workspace changed, refreshing context:`, changes.map(c => c.path).join(', '));
|
|
95
|
+
// Refresh context
|
|
96
|
+
this.refreshContext();
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
this.workspaceWatcher.start();
|
|
100
|
+
}
|
|
101
|
+
// Update state
|
|
102
|
+
this.workspaceState = {
|
|
103
|
+
session: enhanceSessionWithWorkspace({ id: `session-${Date.now()}`, name: agentName, mode: 'agent' }, workspace),
|
|
104
|
+
contextPack: workspace.contextPack,
|
|
105
|
+
isAgentMode: true,
|
|
106
|
+
};
|
|
107
|
+
// Add system message with agent context
|
|
108
|
+
this.addMessage({
|
|
109
|
+
id: `context-${Date.now()}`,
|
|
110
|
+
role: 'system',
|
|
111
|
+
content: `[Agent Context Loaded] ${agentName} is now active with full workspace context.`,
|
|
112
|
+
systemType: 'info',
|
|
113
|
+
});
|
|
114
|
+
console.log('[WorkspaceStateStore] Agent mode activated successfully');
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error('[WorkspaceStateStore] Failed to activate agent mode:', error);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// ========================================================================
|
|
123
|
+
// Message Sending with Context
|
|
124
|
+
// ========================================================================
|
|
125
|
+
async sendMessageWithContext(content, options = {}) {
|
|
126
|
+
// Add user message
|
|
127
|
+
const userMessage = {
|
|
128
|
+
id: `user-${Date.now()}`,
|
|
129
|
+
role: 'user',
|
|
130
|
+
content,
|
|
131
|
+
timestamp: new Date(),
|
|
132
|
+
};
|
|
133
|
+
this.addMessage(userMessage);
|
|
134
|
+
// Check if we should refresh context
|
|
135
|
+
if (this.workspaceState.contextPack && shouldRefreshContext(this.workspaceState.contextPack)) {
|
|
136
|
+
console.log('[WorkspaceStateStore] Context expired, refreshing...');
|
|
137
|
+
if (this.workspaceState.session?.agentId && this.workspaceState.session?.agentName) {
|
|
138
|
+
await this.activateAgentMode(this.workspaceState.session.agentId, this.workspaceState.session.agentName);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Build context for AI
|
|
142
|
+
const context = this.workspaceState.isAgentMode && !options.skipContext
|
|
143
|
+
? this.workspaceState.contextPack
|
|
144
|
+
: null;
|
|
145
|
+
// Here you would send to your AI backend with the context
|
|
146
|
+
// For now, we'll simulate the response structure
|
|
147
|
+
console.log('[WorkspaceStateStore] Sending message with context:', {
|
|
148
|
+
content: content.slice(0, 50) + '...',
|
|
149
|
+
hasContext: !!context,
|
|
150
|
+
trustTiers: context?.trustTiers ? 'included' : 'none',
|
|
151
|
+
});
|
|
152
|
+
// The actual AI integration would happen here:
|
|
153
|
+
// const response = await aiClient.complete({
|
|
154
|
+
// messages: [...this.getState().messages, userMessage],
|
|
155
|
+
// systemPrompt: context?.systemPrompt,
|
|
156
|
+
// trustTiers: context?.trustTiers,
|
|
157
|
+
// });
|
|
158
|
+
}
|
|
159
|
+
// ========================================================================
|
|
160
|
+
// Context Utilities
|
|
161
|
+
// ========================================================================
|
|
162
|
+
getContextPack() {
|
|
163
|
+
return this.workspaceState.contextPack;
|
|
164
|
+
}
|
|
165
|
+
getSystemPrompt() {
|
|
166
|
+
return this.workspaceState.contextPack?.systemPrompt ||
|
|
167
|
+
'You are Gizzi, a helpful AI assistant.';
|
|
168
|
+
}
|
|
169
|
+
isAgentMode() {
|
|
170
|
+
return this.workspaceState.isAgentMode;
|
|
171
|
+
}
|
|
172
|
+
requiresPermission(action) {
|
|
173
|
+
if (!this.workspaceState.contextPack)
|
|
174
|
+
return false;
|
|
175
|
+
// Check Tier 3 rules
|
|
176
|
+
const actionLower = action.toLowerCase();
|
|
177
|
+
return this.workspaceState.contextPack.trustTiers.tier3.rules.some(rule => actionLower.includes(rule.toLowerCase()));
|
|
178
|
+
}
|
|
179
|
+
getTrustTiers() {
|
|
180
|
+
return this.workspaceState.contextPack?.trustTiers || null;
|
|
181
|
+
}
|
|
182
|
+
// ========================================================================
|
|
183
|
+
// Context Refresh
|
|
184
|
+
// ========================================================================
|
|
185
|
+
async refreshContext() {
|
|
186
|
+
if (!this.workspaceState.session?.agentId || !this.workspaceState.session?.agentName) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
console.log('[WorkspaceStateStore] Refreshing context...');
|
|
190
|
+
await this.activateAgentMode(this.workspaceState.session.agentId, this.workspaceState.session.agentName);
|
|
191
|
+
}
|
|
192
|
+
// ========================================================================
|
|
193
|
+
// State Reset
|
|
194
|
+
// ========================================================================
|
|
195
|
+
resetAgentMode() {
|
|
196
|
+
// Stop scheduler
|
|
197
|
+
this.taskScheduler.stop();
|
|
198
|
+
this.taskScheduler.unregisterAgentTasks(this.workspaceState.session?.agentId || '');
|
|
199
|
+
// Stop watcher
|
|
200
|
+
if (this.workspaceWatcher) {
|
|
201
|
+
this.workspaceWatcher.stop();
|
|
202
|
+
this.workspaceWatcher = null;
|
|
203
|
+
}
|
|
204
|
+
this.workspaceState = {
|
|
205
|
+
session: null,
|
|
206
|
+
contextPack: null,
|
|
207
|
+
isAgentMode: false,
|
|
208
|
+
};
|
|
209
|
+
this.clearMessages();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// ============================================================================
|
|
213
|
+
// Global Instance
|
|
214
|
+
// ============================================================================
|
|
215
|
+
let workspaceStore = null;
|
|
216
|
+
export function getWorkspaceStore() {
|
|
217
|
+
if (!workspaceStore) {
|
|
218
|
+
workspaceStore = new WorkspaceStateStore();
|
|
219
|
+
}
|
|
220
|
+
return workspaceStore;
|
|
221
|
+
}
|
|
222
|
+
export function setWorkspaceStore(store) {
|
|
223
|
+
workspaceStore = store;
|
|
224
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gizzi Workspace State Store
|
|
3
|
+
*
|
|
4
|
+
* Enhanced state management with workspace/agent context integration
|
|
5
|
+
* Extends AppStateStore with agent workspace capabilities
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { AppStateStore, getGlobalStore } from './AppStateStore';
|
|
9
|
+
import type { TypedMessage, AssistantMessage } from '../types/message';
|
|
10
|
+
import type { ContextPack, WorkspaceSession } from '../workspace/types';
|
|
11
|
+
import { loadWorkspace, executeStartupTasks, enhanceSessionWithWorkspace } from '../workspace/loader';
|
|
12
|
+
import type { FileSystem } from '../workspace/loader';
|
|
13
|
+
import { buildSystemPrompt, shouldRefreshContext } from '../context/pack-builder';
|
|
14
|
+
import { TaskScheduler, taskScheduler, type ScheduledTask } from '../scheduler/TaskScheduler';
|
|
15
|
+
import { WorkspaceWatcher, getWorkspaceWatcher, type FileChange } from '../watcher/WorkspaceWatcher';
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Types
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
export interface WorkspaceEnhancedState {
|
|
22
|
+
session: WorkspaceSession | null;
|
|
23
|
+
contextPack: ContextPack | null;
|
|
24
|
+
isAgentMode: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Workspace State Store
|
|
29
|
+
// ============================================================================
|
|
30
|
+
|
|
31
|
+
export class WorkspaceStateStore extends AppStateStore {
|
|
32
|
+
private workspaceState: WorkspaceEnhancedState = {
|
|
33
|
+
session: null,
|
|
34
|
+
contextPack: null,
|
|
35
|
+
isAgentMode: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
private fs: FileSystem | null = null;
|
|
39
|
+
private basePath: string = '';
|
|
40
|
+
private taskScheduler: TaskScheduler;
|
|
41
|
+
private workspaceWatcher: WorkspaceWatcher | null = null;
|
|
42
|
+
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
this.taskScheduler = new TaskScheduler({
|
|
46
|
+
onTaskExecute: async (job) => {
|
|
47
|
+
console.log(`[WorkspaceStateStore] Executing scheduled task: ${job.taskId}`);
|
|
48
|
+
// Add system message for task execution
|
|
49
|
+
this.addMessage({
|
|
50
|
+
id: `scheduled-${Date.now()}`,
|
|
51
|
+
role: 'system',
|
|
52
|
+
content: `[Scheduled Task] Executing: ${job.taskId}`,
|
|
53
|
+
systemType: 'info',
|
|
54
|
+
} as TypedMessage);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setFileSystem(fs: FileSystem, basePath: string) {
|
|
60
|
+
this.fs = fs;
|
|
61
|
+
this.basePath = basePath;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ========================================================================
|
|
65
|
+
// Agent Mode Activation
|
|
66
|
+
// ========================================================================
|
|
67
|
+
|
|
68
|
+
async activateAgentMode(agentId: string, agentName: string): Promise<boolean> {
|
|
69
|
+
if (!this.fs || !this.basePath) {
|
|
70
|
+
console.error('[WorkspaceStateStore] FileSystem not configured');
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log(`[WorkspaceStateStore] Activating agent mode: ${agentName}`);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
// Load workspace
|
|
78
|
+
const workspace = await loadWorkspace({
|
|
79
|
+
agentId,
|
|
80
|
+
agentName,
|
|
81
|
+
sessionId: this.workspaceState.session?.id || `session-${Date.now()}`,
|
|
82
|
+
fs: this.fs,
|
|
83
|
+
basePath: this.basePath,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (!workspace) {
|
|
87
|
+
console.log('[WorkspaceStateStore] No workspace found, using default agent settings');
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Execute startup tasks
|
|
92
|
+
await executeStartupTasks(workspace.startupTasks, (content) => {
|
|
93
|
+
// Send startup task message if needed
|
|
94
|
+
this.addMessage({
|
|
95
|
+
id: `system-${Date.now()}`,
|
|
96
|
+
role: 'system',
|
|
97
|
+
content,
|
|
98
|
+
systemType: 'info',
|
|
99
|
+
} as TypedMessage);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Register recurring tasks with scheduler
|
|
103
|
+
const recurringTasks: ScheduledTask[] = workspace.startupTasks
|
|
104
|
+
.filter(t => t.frequency !== 'startup')
|
|
105
|
+
.map(t => ({
|
|
106
|
+
id: t.id,
|
|
107
|
+
action: t.action,
|
|
108
|
+
frequency: t.frequency as any,
|
|
109
|
+
completed: false,
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
if (recurringTasks.length > 0) {
|
|
113
|
+
this.taskScheduler.registerTasks(agentId, recurringTasks);
|
|
114
|
+
this.taskScheduler.start();
|
|
115
|
+
console.log(`[WorkspaceStateStore] Started task scheduler with ${recurringTasks.length} recurring tasks`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Setup file watcher for auto-refresh
|
|
119
|
+
if (this.fs && this.basePath) {
|
|
120
|
+
this.workspaceWatcher = getWorkspaceWatcher(agentId, this.basePath, this.fs, {
|
|
121
|
+
pollIntervalMs: 5000,
|
|
122
|
+
onChange: (changes) => {
|
|
123
|
+
console.log(`[WorkspaceStateStore] Workspace changed, refreshing context:`,
|
|
124
|
+
changes.map(c => c.path).join(', '));
|
|
125
|
+
// Refresh context
|
|
126
|
+
this.refreshContext();
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
this.workspaceWatcher.start();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Update state
|
|
133
|
+
this.workspaceState = {
|
|
134
|
+
session: enhanceSessionWithWorkspace(
|
|
135
|
+
{ id: `session-${Date.now()}`, name: agentName, mode: 'agent' },
|
|
136
|
+
workspace
|
|
137
|
+
),
|
|
138
|
+
contextPack: workspace.contextPack,
|
|
139
|
+
isAgentMode: true,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Add system message with agent context
|
|
143
|
+
this.addMessage({
|
|
144
|
+
id: `context-${Date.now()}`,
|
|
145
|
+
role: 'system',
|
|
146
|
+
content: `[Agent Context Loaded] ${agentName} is now active with full workspace context.`,
|
|
147
|
+
systemType: 'info',
|
|
148
|
+
} as TypedMessage);
|
|
149
|
+
|
|
150
|
+
console.log('[WorkspaceStateStore] Agent mode activated successfully');
|
|
151
|
+
return true;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error('[WorkspaceStateStore] Failed to activate agent mode:', error);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ========================================================================
|
|
159
|
+
// Message Sending with Context
|
|
160
|
+
// ========================================================================
|
|
161
|
+
|
|
162
|
+
async sendMessageWithContext(
|
|
163
|
+
content: string,
|
|
164
|
+
options: {
|
|
165
|
+
skipContext?: boolean;
|
|
166
|
+
onThinking?: (thinking: string) => void;
|
|
167
|
+
onResponse?: (response: AssistantMessage) => void;
|
|
168
|
+
} = {}
|
|
169
|
+
): Promise<void> {
|
|
170
|
+
// Add user message
|
|
171
|
+
const userMessage: TypedMessage = {
|
|
172
|
+
id: `user-${Date.now()}`,
|
|
173
|
+
role: 'user',
|
|
174
|
+
content,
|
|
175
|
+
timestamp: new Date(),
|
|
176
|
+
};
|
|
177
|
+
this.addMessage(userMessage);
|
|
178
|
+
|
|
179
|
+
// Check if we should refresh context
|
|
180
|
+
if (this.workspaceState.contextPack && shouldRefreshContext(this.workspaceState.contextPack)) {
|
|
181
|
+
console.log('[WorkspaceStateStore] Context expired, refreshing...');
|
|
182
|
+
if (this.workspaceState.session?.agentId && this.workspaceState.session?.agentName) {
|
|
183
|
+
await this.activateAgentMode(
|
|
184
|
+
this.workspaceState.session.agentId,
|
|
185
|
+
this.workspaceState.session.agentName
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Build context for AI
|
|
191
|
+
const context = this.workspaceState.isAgentMode && !options.skipContext
|
|
192
|
+
? this.workspaceState.contextPack
|
|
193
|
+
: null;
|
|
194
|
+
|
|
195
|
+
// Here you would send to your AI backend with the context
|
|
196
|
+
// For now, we'll simulate the response structure
|
|
197
|
+
console.log('[WorkspaceStateStore] Sending message with context:', {
|
|
198
|
+
content: content.slice(0, 50) + '...',
|
|
199
|
+
hasContext: !!context,
|
|
200
|
+
trustTiers: context?.trustTiers ? 'included' : 'none',
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// The actual AI integration would happen here:
|
|
204
|
+
// const response = await aiClient.complete({
|
|
205
|
+
// messages: [...this.getState().messages, userMessage],
|
|
206
|
+
// systemPrompt: context?.systemPrompt,
|
|
207
|
+
// trustTiers: context?.trustTiers,
|
|
208
|
+
// });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ========================================================================
|
|
212
|
+
// Context Utilities
|
|
213
|
+
// ========================================================================
|
|
214
|
+
|
|
215
|
+
getContextPack(): ContextPack | null {
|
|
216
|
+
return this.workspaceState.contextPack;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
getSystemPrompt(): string {
|
|
220
|
+
return this.workspaceState.contextPack?.systemPrompt ||
|
|
221
|
+
'You are Gizzi, a helpful AI assistant.';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
isAgentMode(): boolean {
|
|
225
|
+
return this.workspaceState.isAgentMode;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
requiresPermission(action: string): boolean {
|
|
229
|
+
if (!this.workspaceState.contextPack) return false;
|
|
230
|
+
|
|
231
|
+
// Check Tier 3 rules
|
|
232
|
+
const actionLower = action.toLowerCase();
|
|
233
|
+
return this.workspaceState.contextPack.trustTiers.tier3.rules.some(
|
|
234
|
+
rule => actionLower.includes(rule.toLowerCase())
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getTrustTiers() {
|
|
239
|
+
return this.workspaceState.contextPack?.trustTiers || null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ========================================================================
|
|
243
|
+
// Context Refresh
|
|
244
|
+
// ========================================================================
|
|
245
|
+
|
|
246
|
+
async refreshContext(): Promise<void> {
|
|
247
|
+
if (!this.workspaceState.session?.agentId || !this.workspaceState.session?.agentName) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
console.log('[WorkspaceStateStore] Refreshing context...');
|
|
252
|
+
await this.activateAgentMode(
|
|
253
|
+
this.workspaceState.session.agentId,
|
|
254
|
+
this.workspaceState.session.agentName
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ========================================================================
|
|
259
|
+
// State Reset
|
|
260
|
+
// ========================================================================
|
|
261
|
+
|
|
262
|
+
resetAgentMode(): void {
|
|
263
|
+
// Stop scheduler
|
|
264
|
+
this.taskScheduler.stop();
|
|
265
|
+
this.taskScheduler.unregisterAgentTasks(this.workspaceState.session?.agentId || '');
|
|
266
|
+
|
|
267
|
+
// Stop watcher
|
|
268
|
+
if (this.workspaceWatcher) {
|
|
269
|
+
this.workspaceWatcher.stop();
|
|
270
|
+
this.workspaceWatcher = null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
this.workspaceState = {
|
|
274
|
+
session: null,
|
|
275
|
+
contextPack: null,
|
|
276
|
+
isAgentMode: false,
|
|
277
|
+
};
|
|
278
|
+
this.clearMessages();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ============================================================================
|
|
283
|
+
// Global Instance
|
|
284
|
+
// ============================================================================
|
|
285
|
+
|
|
286
|
+
let workspaceStore: WorkspaceStateStore | null = null;
|
|
287
|
+
|
|
288
|
+
export function getWorkspaceStore(): WorkspaceStateStore {
|
|
289
|
+
if (!workspaceStore) {
|
|
290
|
+
workspaceStore = new WorkspaceStateStore();
|
|
291
|
+
}
|
|
292
|
+
return workspaceStore;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function setWorkspaceStore(store: WorkspaceStateStore | null): void {
|
|
296
|
+
workspaceStore = store;
|
|
297
|
+
}
|