@interopio/working-context 0.1.1-beta.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/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@interopio/working-context",
3
+ "version": "0.1.1-beta.0",
4
+ "type": "module",
5
+ "description": "io.Intelligence Working Context for LLMs",
6
+ "main": "./dist/working-context.umd.js",
7
+ "module": "./dist/working-context.es.js",
8
+ "types": "./working-context.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./working-context.d.ts",
12
+ "import": "./dist/working-context.es.js",
13
+ "require": "./dist/working-context.umd.js"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "rollup -c",
18
+ "build:docker": "rollup -c",
19
+ "test": "karma start karma.conf.cjs --single-run",
20
+ "version": "npm run build"
21
+ },
22
+ "dependencies": {
23
+ "@interopio/browser": "^4.0.0",
24
+ "@interopio/desktop": "^6.0.0"
25
+ },
26
+ "keywords": [
27
+ "ai",
28
+ "llm",
29
+ "agentic",
30
+ "copilot",
31
+ "assistant",
32
+ "io.Intelligence",
33
+ "io.connect",
34
+ "interop.io",
35
+ "io.connect browser",
36
+ "io.connect desktop",
37
+ "io.connect browser platform"
38
+ ],
39
+ "homepage": "https://interop.io/",
40
+ "author": {
41
+ "name": "Interop.IO",
42
+ "url": "https://interop.io/"
43
+ },
44
+ "publishConfig": {
45
+ "@interopio:registry": "https://registry.npmjs.org",
46
+ "access": "public"
47
+ },
48
+ "license": "MIT",
49
+ "gitHead": "6cbd953e1718cca987f11c0bc7edb75781f7ecb2"
50
+ }
package/readme.md ADDED
@@ -0,0 +1,530 @@
1
+ # io.Intelligence Working Context
2
+
3
+ ## Table of Contents
4
+
5
+ 1. [Introduction](#introduction)
6
+ 2. [Installation](#installation)
7
+ 3. [Core Concepts](#core-concepts)
8
+ 4. [API Reference](#api-reference)
9
+ 5. [Configuration](#configuration)
10
+ 6. [Integration Options](#integration-options)
11
+ 7. [Examples](#examples)
12
+
13
+ ---
14
+
15
+ ## Introduction
16
+
17
+ The **io.Intelligence Working Context** package (`@interopio/working-context`) is a TypeScript library that enables developers to build intelligent, context-aware applications by automatically harvesting and managing contextual information gathered from multiple data sources within io.Connect.
18
+
19
+ ### What is Working Context?
20
+
21
+ Working Context represents the current state and information relevant to a user's workflow. This package automatically tracks, updates, and exposes contextual data from various sources within your application, making it readily available for AI agents, LLMs, or application logic.
22
+
23
+ ### Key Features
24
+
25
+ - **Automatic Context Harvesting**: Define schemas describing your data sources, and the package handles the rest
26
+ - **Multiple Source Support**: Track data from global contexts, workspaces, channels, and application instances
27
+ - **Type-Safe**: Built with TypeScript for complete type safety and IntelliSense support
28
+ - **Reactive Updates**: Subscribe to context changes and respond to updates in real-time
29
+ - **Flexible Integration**: Works standalone or integrates with other io.Intelligence packages
30
+
31
+ ## Installation
32
+
33
+ The package is available via npm and can be installed using npm or yarn:
34
+
35
+ ```bash
36
+ npm install @interopio/working-context
37
+ ```
38
+
39
+ ## Core Concepts
40
+
41
+ ### Schema-Driven Configuration
42
+
43
+ The Working Context package operates on a schema-like configuration object that defines:
44
+
45
+ 1. **Properties to track**: Each property has a name and expected data type
46
+ 2. **Source locations**: Where to find the data (global context, workspace, channel, etc.)
47
+ 3. **Data paths**: The specific path within each source to extract values
48
+
49
+ ### Context Sources
50
+
51
+ The package supports four types of context sources:
52
+
53
+ #### 1. Global Context
54
+
55
+ Global io.Connect shared contexts accessible across the entire io.Connect environment.
56
+
57
+ ```typescript
58
+ global: {
59
+ names: string[] // Array of global context names to track
60
+ }
61
+ ```
62
+
63
+ #### 2. Workspace Context
64
+
65
+ Context specific to workspaces (user's workspace or focused workspace).
66
+
67
+ ```typescript
68
+ workspace: {
69
+ target: "my" | "focused" | "hybrid";
70
+ }
71
+ ```
72
+
73
+ > **Note**: "focused" and "hybrid" targets are currently supported only in io.Connect Desktop.
74
+
75
+ #### 3. Channel Context
76
+
77
+ Data from specific channels.
78
+
79
+ ```typescript
80
+ channel: {
81
+ target: "my" | string; // "my" for user's channel or specific channel name
82
+ }
83
+ ```
84
+
85
+ #### 4. Application Instance Context
86
+
87
+ Context from specific application instances.
88
+
89
+ ```typescript
90
+ appInstance: {
91
+ appNames: string[] // Array of application names to track
92
+ }
93
+ ```
94
+
95
+ ### Property Types
96
+
97
+ The package supports five data types for tracked properties:
98
+
99
+ - `string`: Text values
100
+ - `number`: Numeric values
101
+ - `boolean`: True/false values
102
+ - `object`: Complex objects (non-array)
103
+ - `array`: Array values
104
+
105
+ ---
106
+
107
+ ## API Reference
108
+
109
+ ### Factory Function
110
+
111
+ #### `IoIntelWorkingContextFactory`
112
+
113
+ The main entry point for creating a Working Context instance.
114
+
115
+ **Signature:**
116
+
117
+ ```typescript
118
+ IoIntelWorkingContextFactory(
119
+ io: IOConnectBrowser.API,
120
+ config: IoIntelWorkingContext.Config
121
+ ): Promise<IoIntelWorkingContext.API>
122
+ ```
123
+
124
+ **Parameters:**
125
+
126
+ - `io`: The io.Connect browser API instance. **Note:** Providing an io.Connect API with Workspaces API configured is required for all Workspaces tracking.
127
+ - `config`: Configuration object defining the schema and sources
128
+
129
+ **Returns:**
130
+
131
+ - A Promise that resolves to the Working Context API
132
+
133
+ **Example:**
134
+
135
+ ```typescript
136
+ import { IoIntelWorkingContextFactory } from "@interopio/working-context";
137
+
138
+ const workingContext = await IoIntelWorkingContextFactory(io, {
139
+ schema: {
140
+ userName: {
141
+ type: "string",
142
+ description: "Current user's full name",
143
+ source: {
144
+ context: {
145
+ location: {
146
+ global: { names: ["UserProfile"] },
147
+ },
148
+ path: "user.name",
149
+ },
150
+ },
151
+ },
152
+ },
153
+ });
154
+ ```
155
+
156
+ ### Working Context API
157
+
158
+ Once initialized, the Working Context API provides two main methods:
159
+
160
+ #### `get()`
161
+
162
+ Retrieves the current state of all tracked properties.
163
+
164
+ **Signature:**
165
+
166
+ ```typescript
167
+ get(): Record<string, Property>
168
+ ```
169
+
170
+ **Returns:**
171
+
172
+ - Object containing all tracked properties with their current values
173
+
174
+ **Property Structure:**
175
+
176
+ ```typescript
177
+ interface Property {
178
+ description?: string;
179
+ value: any;
180
+ }
181
+ ```
182
+
183
+ **Example:**
184
+
185
+ ```typescript
186
+ const currentContext = workingContext.get();
187
+ console.log(currentContext.userName.value); // "John Doe"
188
+ ```
189
+
190
+ #### `onChanged()`
191
+
192
+ Subscribes to context changes.
193
+
194
+ **Signature:**
195
+
196
+ ```typescript
197
+ onChanged(
198
+ callback: (data: Record<string, Property>) => void
199
+ ): UnsubscribeFunction
200
+ ```
201
+
202
+ **Parameters:**
203
+
204
+ - `callback`: Function called whenever context changes
205
+
206
+ **Returns:**
207
+
208
+ - Unsubscribe function to stop receiving updates
209
+
210
+ **Example:**
211
+
212
+ ```typescript
213
+ const unsubscribe = workingContext.onChanged((updatedContext) => {
214
+ console.log("Context updated:", updatedContext);
215
+ });
216
+
217
+ // Later, to stop listening:
218
+ unsubscribe();
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Configuration
224
+
225
+ ### Configuration Object Structure
226
+
227
+ ```typescript
228
+ interface Config {
229
+ schema: Schema;
230
+ }
231
+
232
+ interface Schema {
233
+ [key: string]: PropertySchema;
234
+ }
235
+
236
+ interface PropertySchema {
237
+ type: "string" | "number" | "boolean" | "object" | "array";
238
+ description?: string;
239
+ source: Source;
240
+ }
241
+
242
+ interface Source {
243
+ context: {
244
+ location: SourceLocation;
245
+ path: string; // Dot notation path
246
+ };
247
+ }
248
+
249
+ interface SourceLocation {
250
+ global?: { names: string[] };
251
+ workspace?: { target: "my" | "focused" | "hybrid" };
252
+ appInstance?: { appNames: string[] };
253
+ channel?: { target: "my" | string };
254
+ }
255
+ ```
256
+
257
+ ### Configuration Rules
258
+
259
+ 1. **Single Source Location**: Each property must define exactly one source location (global, workspace, appInstance, or channel)
260
+ 2. **Dot Notation Paths**: Use dot notation for nested paths (e.g., `"user.profile.email"`)
261
+ 3. **Type Validation**: Values are validated against declared types; mismatches are logged and ignored
262
+
263
+ ### Complete Configuration Example
264
+
265
+ ```typescript
266
+ const config = {
267
+ schema: {
268
+ // Track user name from global context
269
+ userName: {
270
+ type: "string",
271
+ description: "User's display name",
272
+ source: {
273
+ context: {
274
+ location: {
275
+ global: { names: ["UserSession", "UserProfile"] },
276
+ },
277
+ path: "name",
278
+ },
279
+ },
280
+ },
281
+
282
+ // Track active document from workspace
283
+ activeDocument: {
284
+ type: "object",
285
+ description: "Currently open document",
286
+ source: {
287
+ context: {
288
+ location: {
289
+ workspace: { target: "my" },
290
+ },
291
+ path: "document.current",
292
+ },
293
+ },
294
+ },
295
+
296
+ // Track notification settings from channel
297
+ notificationsEnabled: {
298
+ type: "boolean",
299
+ source: {
300
+ context: {
301
+ location: {
302
+ channel: { target: "my" },
303
+ },
304
+ path: "settings.notifications.enabled",
305
+ },
306
+ },
307
+ },
308
+
309
+ // Track portfolio data from specific app instance
310
+ portfolioData: {
311
+ type: "array",
312
+ description: "User's portfolio holdings",
313
+ source: {
314
+ context: {
315
+ location: {
316
+ appInstance: { appNames: ["PortfolioManager"] },
317
+ },
318
+ path: "portfolio.holdings",
319
+ },
320
+ },
321
+ },
322
+ },
323
+ };
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Integration Options
329
+
330
+ The Working Context package offers three integration approaches:
331
+
332
+ ### 1. Standalone Usage
333
+
334
+ Use the package directly via its API for custom implementations.
335
+
336
+ **Use Case**: Custom solutions requiring direct control over context management
337
+
338
+ **Example:**
339
+
340
+ ```typescript
341
+ import { IoIntelWorkingContextFactory } from "@interopio/working-context";
342
+ import IOConnectBrowser from "@interopio/browser";
343
+
344
+ async function initializeContext() {
345
+ const io = await IOConnectBrowser();
346
+
347
+ const workingContext = await IoIntelWorkingContextFactory(io, config);
348
+
349
+ // Get current context
350
+ const context = workingContext.get();
351
+
352
+ // Subscribe to changes
353
+ workingContext.onChanged((data) => {
354
+ // Handle context updates
355
+ processContextUpdate(data);
356
+ });
357
+ }
358
+ ```
359
+
360
+ ### 2. Integration with `@interopio/intel-web`
361
+
362
+ Provides the best end-user experience with automatic context exposure to LLMs.
363
+
364
+ **Use Case**: Full-featured context-aware AI applications
365
+
366
+ **Benefits:**
367
+
368
+ - Automatic context harvesting
369
+ - Fine-tuned prompts for LLM integration
370
+ - Seamless API access if no LLM is configured
371
+
372
+ ### 3. Integration with `@interopio/mcp-core`
373
+
374
+ Designed for solutions using only the io.Intelligence MCP (Model Context Protocol).
375
+
376
+ **Use Case**: MCP-only solutions without other io.Intelligence packages
377
+
378
+ **Implementation:**
379
+
380
+ - Context exposed via dedicated MCP tool
381
+ - Requires custom prompt engineering
382
+ - Developer manages LLM system prompts
383
+
384
+ ## Examples
385
+
386
+ ### Example 1: Tracking User Profile
387
+
388
+ ```typescript
389
+ import { IoIntelWorkingContextFactory } from "@interopio/working-context";
390
+
391
+ const config = {
392
+ schema: {
393
+ userId: {
394
+ type: "string",
395
+ description: "Unique user identifier",
396
+ source: {
397
+ context: {
398
+ location: { global: { names: ["UserSession"] } },
399
+ path: "user.id",
400
+ },
401
+ },
402
+ },
403
+ userName: {
404
+ type: "string",
405
+ description: "User's full name",
406
+ source: {
407
+ context: {
408
+ location: { global: { names: ["UserSession"] } },
409
+ path: "user.fullName",
410
+ },
411
+ },
412
+ },
413
+ userRole: {
414
+ type: "string",
415
+ description: "User's role in the organization",
416
+ source: {
417
+ context: {
418
+ location: { global: { names: ["UserSession"] } },
419
+ path: "user.role",
420
+ },
421
+ },
422
+ },
423
+ },
424
+ };
425
+
426
+ const workingContext = await IoIntelWorkingContextFactory(io, config);
427
+
428
+ // Access user information
429
+ const context = workingContext.get();
430
+ console.log(`Welcome, ${context.userName.value}!`);
431
+ console.log(`Role: ${context.userRole.value}`);
432
+ ```
433
+
434
+ ### Example 2: Multi-Source Trading Application
435
+
436
+ ```typescript
437
+ const tradingConfig = {
438
+ schema: {
439
+ // From global context
440
+ traderId: {
441
+ type: "string",
442
+ source: {
443
+ context: {
444
+ location: { global: { names: ["TraderProfile"] } },
445
+ path: "trader.id",
446
+ },
447
+ },
448
+ },
449
+
450
+ // From workspace
451
+ activeInstrument: {
452
+ type: "object",
453
+ description: "Currently selected trading instrument",
454
+ source: {
455
+ context: {
456
+ location: { workspace: { target: "my" } },
457
+ path: "instrument",
458
+ },
459
+ },
460
+ },
461
+
462
+ // From channel
463
+ marketData: {
464
+ type: "object",
465
+ description: "Real-time market data",
466
+ source: {
467
+ context: {
468
+ location: { channel: { target: "MarketData" } },
469
+ path: "data",
470
+ },
471
+ },
472
+ },
473
+
474
+ // From app instance
475
+ openOrders: {
476
+ type: "array",
477
+ description: "List of open orders",
478
+ source: {
479
+ context: {
480
+ location: { appInstance: { appNames: ["OrderManager"] } },
481
+ path: "orders.open",
482
+ },
483
+ },
484
+ },
485
+ },
486
+ };
487
+
488
+ const tradingContext = await IoIntelWorkingContextFactory(io, tradingConfig);
489
+
490
+ // Monitor trading context
491
+ tradingContext.onChanged((context) => {
492
+ if (context.activeInstrument.value) {
493
+ console.log(
494
+ `Instrument changed to: ${context.activeInstrument.value.symbol}`,
495
+ );
496
+ }
497
+
498
+ if (context.openOrders.value) {
499
+ console.log(`Open orders: ${context.openOrders.value.length}`);
500
+ }
501
+ });
502
+ ```
503
+
504
+ ### Example 3: Deeply Nested Data Paths
505
+
506
+ ```typescript
507
+ const nestedConfig = {
508
+ schema: {
509
+ departmentName: {
510
+ type: "string",
511
+ source: {
512
+ context: {
513
+ location: { global: { names: ["OrgStructure"] } },
514
+ path: "organization.division.department.name",
515
+ },
516
+ },
517
+ },
518
+
519
+ budgetRemaining: {
520
+ type: "number",
521
+ source: {
522
+ context: {
523
+ location: { global: { names: ["FinanceData"] } },
524
+ path: "department.finance.budget.fiscal2024.remaining",
525
+ },
526
+ },
527
+ },
528
+ },
529
+ };
530
+ ```