socialcalc-ai 1.0.2 → 1.0.4

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
@@ -24,6 +24,7 @@ Derived from Dan Bricklin's proven, industrial-strength **SocialCalc** engine, `
24
24
  - [RowActionPopover](#3-rowactionpopover)
25
25
  - [EditableCellsModal](#4-editablecellsmodal)
26
26
  - [DemoVideosModal](#5-demovideosmodal)
27
+ - [AgentModal](#6-agentmodal)
27
28
  - [Plugins & Modules API](#-plugins--modules-api)
28
29
  - [Row & Column Headers](#1-row--column-headers-modulesrow-col-headersjs)
29
30
  - [Grid Lines](#2-grid-lines-modulesgrid-linesjs)
@@ -34,6 +35,8 @@ Derived from Dan Bricklin's proven, industrial-strength **SocialCalc** engine, `
34
35
  - [History & Undo/Redo](#7-history-undo--redo-moduleshistoryjs)
35
36
  - [Exporters & Sheets](#8-exporters--sheets-modulesexportersjs-modulessheetsjs)
36
37
  - [Invoice Utilities](#9-invoice-utilities-modulesinvoicejs)
38
+ - [AI Agent Plugin (Text Editor Agent)](#10-ai-agent-plugin-text-editor-agent-modulesagentjs)
39
+ - [Cell Formatting & Display Suite](#11-cell-formatting--display-suite)
37
40
  - [Event-Driven Architecture](#-event-driven-architecture)
38
41
  - [AI & MultiSheet Calc (MSC) Integration](#-ai--multisheet-calc-msc-integration)
39
42
  - [TypeScript Support](#-typescript-support)
@@ -277,6 +280,16 @@ A modern, responsive bottom-sheet modal that replaces legacy browser `prompt()`
277
280
  - **Image Insertion**: Embed images into cells with automatic client-side compression via `imageCompressor.ts`.
278
281
  - **Fallback**: Automatically falls back to native inline input if modal mode is disabled.
279
282
 
283
+ <p align="center">
284
+ <img src="../public/screenshots/edit-cell-modal.png" alt="Cell Edit Modal Overview" width="48%" />
285
+ <img src="../public/screenshots/edit-cell-modal-features.png" alt="Cell Edit Modal Features" width="48%" />
286
+ </p>
287
+ <p align="center">
288
+ <img src="../public/screenshots/edit-cell-modal-text-color.png" alt="Font Color Palette" width="31%" />
289
+ <img src="../public/screenshots/edit-cell-modal-background-color.png" alt="Background Color Palette" width="31%" />
290
+ <img src="../public/screenshots/edit-cell-model-cell-borders.png" alt="Cell Borders Customizer" width="31%" />
291
+ </p>
292
+
280
293
  ```tsx
281
294
  <CellEditModal
282
295
  isOpen={isOpen}
@@ -301,6 +314,10 @@ A context popup that appears when clicking any row header index:
301
314
  - **Insert Row Below**: Inserts an empty row below the selected index.
302
315
  - **Delete Row**: Removes the selected row and cascades formula references.
303
316
 
317
+ <p align="center">
318
+ <img src="../public/screenshots/row-options.png" alt="Row Action Popover Menu" width="50%" />
319
+ </p>
320
+
304
321
  ```tsx
305
322
  <RowActionPopover
306
323
  isOpen={showPopover}
@@ -316,6 +333,10 @@ An administrative inspector for template creators:
316
333
  - Bind application field mappings (e.g., `vendor_name -> B4`) to spreadsheet coordinates.
317
334
  - Test template locking permissions.
318
335
 
336
+ <p align="center">
337
+ <img src="../public/screenshots/editable-cells-modal.png" alt="Editable Cells Modal" width="60%" />
338
+ </p>
339
+
319
340
  ```tsx
320
341
  <EditableCellsModal
321
342
  isOpen={showModal}
@@ -335,12 +356,152 @@ An interactive help and reference modal containing:
335
356
  />
336
357
  ```
337
358
 
359
+ ### 6. `AgentModal`
360
+ An interactive AI Agent Workbench and chat modal:
361
+ - Inspect active sheet context, dimensions, and detected `appMapping` fields.
362
+ - Test one-click quick actions (e.g. fill invoice header, populate table items, set formula).
363
+ - Execute custom JSON action arrays directly or copy LLM tool schemas (Gemini function declarations, OpenAI tools, and system prompts).
364
+ - View real-time action execution logs.
365
+
366
+ <p align="center">
367
+ <img src="../public/screenshots/agent-console.png" alt="SocialCalc AI Agent Workbench" width="65%" />
368
+ </p>
369
+
370
+ ```tsx
371
+ <AgentModal
372
+ isOpen={showAgentModal}
373
+ onClose={() => setShowAgentModal(false)}
374
+ appMapping={appMapping}
375
+ currentSheet="sheet1"
376
+ onExecute={(res) => console.log("Agent actions:", res)}
377
+ />
378
+ ```
379
+
380
+ #### Customizable Tab Combinations & Header Controls:
381
+ Developers can customize which tabs are visible, choose specific combinations, and optionally hide the tab headers bar:
382
+
383
+ ```tsx
384
+ // Example 1: Show only AI Copilot and Sheet Context
385
+ <AgentModal
386
+ isOpen={showAgentModal}
387
+ onClose={() => setShowAgentModal(false)}
388
+ enabledTabs={["actions", "context"]}
389
+ />
390
+
391
+ // Example 2: Minimalist AI Copilot with NO tab headers bar (pure chatbot view)
392
+ <AgentModal
393
+ isOpen={showAgentModal}
394
+ onClose={() => setShowAgentModal(false)}
395
+ enabledTabs={["actions"]}
396
+ hideTabHeaders={true}
397
+ />
398
+
399
+ // Example 4: Built-in Generic Spreadsheet Suggestions
400
+ <AgentModal
401
+ isOpen={showAgentModal}
402
+ onClose={() => setShowAgentModal(false)}
403
+ suggestions="generic"
404
+ suggestionsTitle="Helpful Prompts:"
405
+ />
406
+
407
+ // Example 5: Custom Developer Prompt Suggestions
408
+ <AgentModal
409
+ isOpen={showAgentModal}
410
+ onClose={() => setShowAgentModal(false)}
411
+ suggestionsTitle="Payroll Shortcuts:"
412
+ suggestions={[
413
+ { label: "Calculate Overtime", prompt: "Compute overtime pay at 1.5x for hours over 40." },
414
+ { label: "Format Currency", prompt: "Format all salary and total cells to USD currency." },
415
+ { label: "Summarize Depts", prompt: "Group departments and show total expenditure per department." },
416
+ ]}
417
+ promptPlaceholder="Ask AI to analyze payroll or edit cells..."
418
+ />
419
+
420
+ // Example 6: Custom Header Title, Icon, and Color/Gradient
421
+ <AgentModal
422
+ isOpen={showAgentModal}
423
+ onClose={() => setShowAgentModal(false)}
424
+ title="Financial Copilot"
425
+ headerIcon={calculatorOutline}
426
+ headerIconColor="#38bdf8"
427
+ headerColor="linear-gradient(135deg, #0284c7 0%, #0369a1 100%)"
428
+ headerTextColor="#ffffff"
429
+ versionTag="Finance v1.0"
430
+ // Example 7: Overall Modal Visual Themes
431
+ <AgentModal
432
+ isOpen={showAgentModal}
433
+ onClose={() => setShowAgentModal(false)}
434
+ theme="dark" // or "midnight" | "emerald" | "purple" | "slate" | "light" | "default"
435
+ />
436
+
437
+ // Example 8: Custom Theme Configuration Object
438
+ <AgentModal
439
+ isOpen={showAgentModal}
440
+ onClose={() => setShowAgentModal(false)}
441
+ theme={{
442
+ mode: "dark",
443
+ primaryColor: "#059669",
444
+ headerBackground: "linear-gradient(135deg, #064e3b, #047857)",
445
+ cardBackground: "#111827",
446
+ }}
447
+ />
448
+ ```
449
+
450
+ | Prop | Type | Default | Description |
451
+ |------|------|---------|-------------|
452
+ | `theme` | `"default" \| "dark" \| "midnight" \| "emerald" \| "purple" \| "slate" \| "light" \| AgentModalThemeConfig` | `"default"` | Controls the overall modal visual theme, supporting dark mode, emerald, purple, slate, or custom theme objects. |
453
+ | `title` / `headerTitle` | `string` | `"SocialCalc AI Agent Workbench"` | Custom title text for the modal window header. |
454
+ | `headerIcon` / `icon` | `any` | `sparklesOutline` | Custom Ionicon or React node for the modal header icon. Pass `false` or `null` to hide. |
455
+ | `headerIconColor` | `string` | `"#a855f7"` | Custom color for the modal header icon. |
456
+ | `headerColor` / `headerBackground` | `string` | Dark indigo gradient | Custom CSS background color or gradient for the modal toolbar (e.g. `"#0f172a"` or `linear-gradient(...)`). |
457
+ | `versionTag` / `headerSubtitle` | `string \| null \| false` | `undefined` (hidden) | Optional pill badge next to header title. Pass a string to display a custom tag. |
458
+ | `copilotTitle` | `string` | `"Agentic Text-Editor Copilot"` | Custom title displayed in the Copilot card header inside the Actions tab. |
459
+ | `copilotIcon` | `any` | `sparklesOutline` | Custom icon for the Copilot card header. Pass `false` or `null` to hide. |
460
+ | `enabledTabs` | `("actions" \| "context" \| "schemas" \| "console")[]` | `["actions", "context", "schemas", "console"]` | Specify the exact list and combination of tabs to display. |
461
+ | `showActionsTab` | `boolean` | `true` | Show or hide the AI Copilot & Actions tab. |
462
+ | `showContextTab` | `boolean` | `true` | Show or hide the Sheet Context tab. |
463
+ | `showSchemasTab` | `boolean` | `true` | Show or hide the LLM Schemas tab. |
464
+ | `showConsoleTab` | `boolean` | `true` | Show or hide the Live Agent Console tab. |
465
+ | `hideTabHeaders` | `boolean` | `false` | Completely hides the tab header bar (aliases: `hideHeaders`, `hideTabBar`). |
466
+ | `defaultTab` | `string` | First enabled tab | Sets the default active tab on opening. |
467
+ | `showPluginTest` | `boolean` | `true` | Show or remove the Direct Plugin Quick Actions & Custom JSON test component (`AgentPluginTest`). Set to `false` for a pure AI Copilot chat interface (aliases: `showQuickActions`, `hidePluginTest`). |
468
+ | `suggestions` | `AgentPromptSuggestion[] \| "generic" \| "invoice" \| boolean` | `undefined` | Configure prompt suggestions: pass `"generic"` for general spreadsheet suggestions, `"invoice"` for invoice actions, custom `[{ label, prompt }]` array, or leave unset/`false` for a clean interface without suggestion chips. |
469
+ | `suggestionsTitle` | `string` | `"Suggestions:"` | Title label displayed above the suggestion chips. |
470
+ | `showSuggestions` | `boolean` | `true` (when `suggestions` provided) | Explicitly show or hide the suggestion chips row. |
471
+ | `promptPlaceholder` | `string` | `"e.g. 'Fill cell C5 with Client Name...'"` | Custom placeholder text for the AI prompt textarea. |
472
+
473
+ ### 7. `AgentPluginTest` (`Agentplugintest`)
474
+ A standalone, removable component for testing direct spreadsheet plugin macros, mappings, and raw JSON actions:
475
+ - **Pre-configured Quick Actions**: Fill Acme invoice header, populate 3 line items, set `=SUM(...)` formula, or clear table.
476
+ - **Custom JSON Action Executor**: Test custom action arrays directly against the active spreadsheet.
477
+ - **Removable from `AgentModal`**: Can be removed from `AgentModal` via `showPluginTest={false}` or `hidePluginTest={true}`.
478
+ - **Usable Standalone**: Can be placed anywhere in your custom developer drawer, page, or modal.
479
+
480
+ ```tsx
481
+ import { AgentPluginTest, Agentplugintest } from "socialcalc";
482
+
483
+ // Use standalone anywhere in your app:
484
+ <AgentPluginTest
485
+ currentSheet="sheet1"
486
+ appMapping={appMapping}
487
+ onExecute={(res) => console.log("Actions applied:", res)}
488
+ onLog={(msg) => console.log("Log:", msg)}
489
+ showCustomJson={true}
490
+ />
491
+ ```
492
+
338
493
  ---
339
494
 
340
495
  ## 🔌 Plugins & Modules API
341
496
 
342
497
  ### 1. Row & Column Headers (`modules/row-col-headers.js`)
343
498
  Enables 123 row numbers and ABCD column headers with interactive column resizing:
499
+
500
+ <p align="center">
501
+ <img src="../public/screenshots/headers.png" alt="Row & Col Headers" width="48%" />
502
+ <img src="../public/screenshots/col-resize-picker.png" alt="Column Resize Handle" width="48%" />
503
+ </p>
504
+
344
505
  ```ts
345
506
  // Enable row/col headers
346
507
  AppGeneral.enableRowColHeaders();
@@ -454,6 +615,78 @@ const coords = getInvoiceCoordinates();
454
615
  // Returns standard coordinates for billTo, from, invoiceDetails, items, totals
455
616
  ```
456
617
 
618
+ ### 10. AI Agent Plugin (Text Editor Agent) (`modules/agent.js`)
619
+ Provides an extensible AI agent layer to connect LLMs (Gemini, OpenAI, Anthropic) or custom backends (Node.js, Python Tornado) with the spreadsheet engine.
620
+
621
+ #### Key Features:
622
+ - **Intelligent Context Extraction**: Reads current sheet, bounding range, non-empty cells, and automatically parses template `appMapping` fields (e.g. `BillTo.Name` -> `C5`, `Items` table rows 21–33) or falls back to free-form mode if mappings are empty.
623
+ - **LLM-Ready Tool Schemas & Prompts**: Generates Gemini `functionDeclarations`, OpenAI `tool_calls`, and optimized system prompts out of the box.
624
+ - **Atomic Text Editor Actions**: Executes `SET_CELL`, `SET_CELLS`, `CLEAR_CELL`, `SET_MAPPING_FIELD`, `APPLY_MAPPING_DATA`, and `RAW_COMMAND`.
625
+ - **Extensible Action Handler Registry**: Ready for future styling, merge/unmerge, and dimension agents (`registerAgentActionHandler`).
626
+ - **Universal Compatibility**: Zero React/Ionic dependencies in the core module; works in browser client calls as well as server runtimes.
627
+
628
+ <p align="center">
629
+ <img src="../public/screenshots/agent-console.png" alt="AI Agent Execution Console" width="70%" />
630
+ </p>
631
+
632
+ #### Client-side Gemini Integration Example:
633
+ ```ts
634
+ import {
635
+ getAgentContext,
636
+ getAgentToolDefinitions,
637
+ generateAgentSystemPrompt,
638
+ executeAgentResponse,
639
+ } from "socialcalc-ai";
640
+
641
+ // 1. Extract context & tool declarations
642
+ const context = getAgentContext();
643
+ const tools = getAgentToolDefinitions({ format: "gemini" });
644
+ const systemPrompt = generateAgentSystemPrompt();
645
+
646
+ // 2. Call Gemini API (SDK or direct fetch)
647
+ const geminiResponse = await callGemini({
648
+ systemInstruction: systemPrompt,
649
+ contents: [{ role: "user", parts: [{ text: "Fill invoice for Acme Corp with $500 consulting" }] }],
650
+ tools,
651
+ });
652
+
653
+ // 3. Apply actions to SocialCalc sheet
654
+ const result = executeAgentResponse(geminiResponse);
655
+ console.log(`Executed ${result.count} actions atomically!`);
656
+ ```
657
+
658
+ #### Backend Integration Example (Node.js Express or Python Tornado):
659
+ ```ts
660
+ // Client sends exportable context to backend
661
+ const payload = exportAgentContext();
662
+ const res = await fetch("/api/agent/chat", {
663
+ method: "POST",
664
+ headers: { "Content-Type": "application/json" },
665
+ body: JSON.stringify({ message: "Update invoice date to today", context: payload }),
666
+ });
667
+
668
+ const { actions } = await res.json();
669
+ executeAgentActions(actions);
670
+ ```
671
+
672
+ ### 11. Cell Formatting & Display Suite
673
+ SocialCalc provides built-in formatters for commercial, financial, and date/time data types:
674
+
675
+ <p align="center">
676
+ <img src="../public/screenshots/cell-format-numbers.png" alt="Numeric Formatting" width="31%" />
677
+ <img src="../public/screenshots/cell-format-currency.png" alt="Currency Formatting" width="31%" />
678
+ <img src="../public/screenshots/cell-format-percent.png" alt="Percentage Formatting" width="31%" />
679
+ </p>
680
+ <p align="center">
681
+ <img src="../public/screenshots/cell-format-date.png" alt="Date Formatting" width="48%" />
682
+ <img src="../public/screenshots/cell-format-time.png" alt="Time Formatting" width="48%" />
683
+ </p>
684
+
685
+ - **Numeric Formats**: Precision decimal control, integer display, comma thousand grouping (`#,##0.00`).
686
+ - **Currency Formats**: Localized currency symbols (`$`, `€`, `₹`), negative parentheses notation.
687
+ - **Percentage Formats**: Automatic conversion of decimals/fractions into clean percentage percentages (`15.00%`).
688
+ - **Date & Time Formats**: ISO timestamps, short date (`MM/DD/YYYY`), medium date (`DD-MMM-YYYY`), and 12/24-hour clocks.
689
+
457
690
  ---
458
691
 
459
692
  ## 📡 Event-Driven Architecture
@@ -467,6 +700,7 @@ const coords = getInvoiceCoordinates();
467
700
  | `socialcalc:cell-change` | `{ coord: string, value: string }` | Fired after a cell's value or formula is committed and recalculated. |
468
701
  | `socialcalc:horizontal-scroll`| `{ currentFirstCol: number, currentColName: string, totalCols: number }` | Fired whenever the horizontal viewport column changes. |
469
702
  | `socialcalc:plugin-change` | `{ pluginName: string, state: boolean, allStates: Record<string, boolean> }` | Fired whenever a plugin is registered, enabled, or disabled. |
703
+ | `socialcalc:agent-action` | `{ actions: Array, commands: string[], results: Array, timestamp: number }` | Fired whenever the AI Agent executes actions on the spreadsheet. |
470
704
 
471
705
  ### Event Listener Example:
472
706
 
@@ -532,6 +766,11 @@ import {
532
766
 
533
767
  ## 📦 Release Notes
534
768
 
769
+ ### v1.0.3
770
+ - **Node.js ESM & Runtime Compatibility**: Enhanced UMD root resolution across all core modules to support `globalThis`, eliminating undefined root errors in Node.js ES module loaders.
771
+ - **TypeScript Declarations**: Bundled official type declarations (`index.d.ts`) covering all core exports, plugin modules, and React/Ionic UI modal components.
772
+ - **Packaging Refinements**: Added `.npmignore` to exclude test files, scratch scripts, and developer metadata from distributed tarballs.
773
+
535
774
  ### v1.0.2
536
775
  - **Cell Edit Modal Fix**: Fixed cell click interceptor and mouse delegates so clicking any cell reliably triggers the `CellEditModal` bottom sheet.
537
776
  - **Scroll Distortion Fix**: Resolved table border collapse and column misalignment when scrolling past multi-row (`rowspan`) and multi-column (`colspan`) blocks.