json-object-editor 0.10.642 → 0.10.650

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/js/joe-ai.js CHANGED
@@ -1675,6 +1675,59 @@
1675
1675
  }
1676
1676
  };
1677
1677
 
1678
+ /**
1679
+ * Run the Thought agent for the current schema object.
1680
+ * Used by the core `proposeThought` field.
1681
+ */
1682
+ Ai.runProposeThought = function(scopeId, textareaId){
1683
+ try{
1684
+ if (!scopeId) {
1685
+ alert('Save the item before proposing thoughts.');
1686
+ return;
1687
+ }
1688
+ var ta = document.getElementById(textareaId);
1689
+ if (!ta) {
1690
+ alert('Prompt field not found.');
1691
+ return;
1692
+ }
1693
+ var prompt = (ta.value || '').trim();
1694
+ if (!prompt) {
1695
+ alert('Please enter a prompt for the Thought run.');
1696
+ return;
1697
+ }
1698
+ var body = {
1699
+ jsonrpc: '2.0',
1700
+ id: String(Date.now()),
1701
+ method: 'runThoughtAgent',
1702
+ params: {
1703
+ agent_id: 'thought_agent_default',
1704
+ scope_id: scopeId,
1705
+ user_input: prompt
1706
+ }
1707
+ };
1708
+ fetch('/mcp', {
1709
+ method: 'POST',
1710
+ headers: { 'Content-Type': 'application/json' },
1711
+ body: JSON.stringify(body)
1712
+ }).then(function(res){
1713
+ return res.json();
1714
+ }).then(function(payload){
1715
+ var result = (payload && (payload.result || payload)) || {};
1716
+ var count = result.proposed_thoughts_count || 0;
1717
+ if (window._joe && _joe.toast) {
1718
+ _joe.toast('Thought agent run complete. Proposed ' + count + ' thoughts.');
1719
+ } else {
1720
+ alert('Thought agent run complete. Proposed ' + count + ' thoughts.');
1721
+ }
1722
+ }).catch(function(err){
1723
+ console.error('Ai.runProposeThought error', err);
1724
+ alert('Failed to run Thought agent: ' + (err && err.message || err));
1725
+ });
1726
+ }catch(e){
1727
+ console.error('Ai.runProposeThought error', e);
1728
+ }
1729
+ };
1730
+
1678
1731
  Ai.applyAutofillPatch = function(patch = {}){
1679
1732
  Object.keys(patch).forEach(function(fname){
1680
1733
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-object-editor",
3
- "version": "0.10.642",
3
+ "version": "0.10.650",
4
4
  "description": "JOE the Json Object Editor | Platform Edition",
5
5
  "main": "app.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -159,6 +159,13 @@ JOE is software that allows you to manage data models via JSON objects. There ar
159
159
  - If you see a payload like `{ originalURL: "/...", site: "no site found" }`, the request hit the Sites catch-all. Ensure MCP routes are initialized before Sites (handled by default in `server/init.js` via `MCP.init()`), and use the correct URL: `/.well-known/mcp/manifest.json` or `/mcp`.
160
160
  - To update contact email on /privacy and /terms, set Setting `PRIVACY_CONTACT`.
161
161
 
162
+ ## Thoughts & Thought Pipeline
163
+
164
+ - `thought` schema stores AI/human hypotheses, syntheses, and link-thoughts with `about[]` (what it concerns), `because[]` (receipts), `status`, and AI lineage fields like `source_ai_response` / `created_by`.
165
+ - `ThoughtPipeline` module compiles a deterministic context from a `scope_object` (the item you’re thinking about), schema summaries, and accepted Thoughts, and the `runThoughtAgent` MCP tool runs an OpenAI Responses call to propose new Thoughts.
166
+ - Each Thought run persists an `ai_response` with `response_type:'thought_generation'`, `referenced_objects:[scope_id]`, and `generated_thoughts[]` containing the ids of created Thought records.
167
+ - In any schema UI you can include core fields `proposeThought` and `ai_responses` to (a) trigger a Thought run for the current object and (b) list all related `ai_response` records for audit and reuse.
168
+
162
169
  ## File uploads (S3)
163
170
  - Uploader field options:
164
171
  - `allowmultiple: true|false` — allow selecting multiple files.
@@ -5,6 +5,7 @@ var App = function () {
5
5
 
6
6
  // Core AI-related schemas in JOE
7
7
  this.collections = [
8
+ 'thought',
8
9
  'ai_assistant',
9
10
  'ai_prompt',
10
11
  'ai_tool',
@@ -550,6 +550,46 @@ var fields = {
550
550
  listConversations:{display:'Ai Conversations', type:"content",reloadable:true,run:function(obj){
551
551
  return _joe.schemas.ai_conversation.methods.listConversations(obj,true);
552
552
  }},
553
+ ai_responses:{
554
+ display:'AI Responses',
555
+ type:'content',
556
+ reloadable:true,
557
+ run:function(obj){
558
+ return _joe.schemas.ai_response.methods.listResponses(obj);
559
+ }
560
+ },
561
+ proposeThought:{
562
+ display:'Propose Thought',
563
+ type:'content',
564
+ reloadable:true,
565
+ run:function(obj){
566
+ if (!obj || !obj._id) {
567
+ return '<joe-text>Save this item before proposing Thoughts.</joe-text>';
568
+ }
569
+ var schema = _joe.current && _joe.current.schema || null;
570
+ var itemtype = (obj && obj.itemtype) || (schema && schema.name) || 'item';
571
+ // Allow schemas to override the default prompt via extend:'proposeThought',specs:{prompt:'...'}
572
+ var fieldDef = null;
573
+ if (_joe && typeof _joe.getField === 'function') {
574
+ try { fieldDef = _joe.getField('proposeThought'); } catch(_e) {}
575
+ }
576
+ var overridePrompt = fieldDef && fieldDef.prompt;
577
+ var defaultPrompt = overridePrompt || (
578
+ 'Propose 1–2 concise hypotheses or links about this ' + itemtype +
579
+ ' and its related objects (risks, dependencies, or next steps). ' +
580
+ 'Base them only on the object fields and related records. ' +
581
+ 'Avoid meta-thoughts about prompts or schemas.'
582
+ );
583
+ var taId = 'propose_thought_prompt_' + obj._id;
584
+ var html = '';
585
+ html += '<joe-text>Thought prompt</joe-text>';
586
+ html += '<textarea id="'+taId+'" style="width:100%;min-height:80px;">'+defaultPrompt+'</textarea>';
587
+ // For now, use the generic Thought agent; scope_id is the current object id.
588
+ html += "<joe-button class=\"joe-button joe-blue-button\" ";
589
+ html += "onclick=\"_joe.Ai.runProposeThought('"+obj._id+"','"+taId+"')\">Run Thought Agent</joe-button>";
590
+ return html;
591
+ }
592
+ },
553
593
 
554
594
  };
555
595
 
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  const MCP = {};
10
+ const ThoughtPipeline = require('./ThoughtPipeline');
10
11
 
11
12
  // Internal helpers
12
13
  function getStorage() {
@@ -588,6 +589,18 @@ MCP.tools = {
588
589
  }
589
590
  });
590
591
  return { names, apps: summarized };
592
+ },
593
+
594
+ // Compile a named pipeline into a deterministic prompt payload.
595
+ compilePipeline: async ({ pipeline_id, scope_id, user_input } = {}, _ctx) => {
596
+ const compiled = await ThoughtPipeline.compile(pipeline_id, scope_id, { user_input });
597
+ return compiled;
598
+ },
599
+
600
+ // Run a thought agent (pipeline + Responses API) and materialize proposed Thoughts.
601
+ runThoughtAgent: async ({ agent_id, user_input, scope_id } = {}, ctx = {}) => {
602
+ const result = await ThoughtPipeline.runAgent(agent_id, user_input, scope_id, ctx);
603
+ return result;
591
604
  }
592
605
 
593
606
  // 🔧 Add more tools here as needed
@@ -611,7 +624,9 @@ MCP.descriptions = {
611
624
  saveObjects: "Batch save objects with bounded concurrency; per-item history/events preserved.",
612
625
  hydrate: "Loads and merges the full JOE context, including core and organization-specific schemas, relationships, universal fields (tags and statuses), and datasets. Returns a single unified object describing the active environment for use by agents, UIs, and plugins.",
613
626
  listApps: "List app definitions (title, description, collections, plugins).",
614
- understandObject: "High-level helper: given an _id (and optional itemtype), returns { object, flattened, schemas, related[] } combining the main object, its schema summary, and referenced objects plus their schemas. Prefer this when you need to understand or reason about an object by id instead of issuing many separate getObject/getSchema calls."
627
+ understandObject: "High-level helper: given an _id (and optional itemtype), returns { object, flattened, schemas, related[] } combining the main object, its schema summary, and referenced objects plus their schemas. Prefer this when you need to understand or reason about an object by id instead of issuing many separate getObject/getSchema calls.",
628
+ compilePipeline: "Compile a named pipeline (e.g., the default Thought pipeline) into a deterministic prompt payload with system_context, user_context, and attachments.steps.",
629
+ runThoughtAgent: "Run a Thought agent: compile its pipeline, call the OpenAI Responses API, store an ai_response, and materialize any proposed thought objects for later review."
615
630
  };
616
631
 
617
632
  MCP.params = {
@@ -716,7 +731,25 @@ MCP.params = {
716
731
  },
717
732
  hydrate: { type: "object", properties: {} }
718
733
  ,
719
- listApps: { type: "object", properties: {} }
734
+ listApps: { type: "object", properties: {} },
735
+ compilePipeline: {
736
+ type: "object",
737
+ properties: {
738
+ pipeline_id: { type: "string" },
739
+ scope_id: { type: "string" },
740
+ user_input: { type: "string" }
741
+ },
742
+ required: []
743
+ },
744
+ runThoughtAgent: {
745
+ type: "object",
746
+ properties: {
747
+ agent_id: { type: "string" },
748
+ user_input: { type: "string" },
749
+ scope_id: { type: "string" }
750
+ },
751
+ required: ["user_input"]
752
+ }
720
753
  };
721
754
 
722
755
  MCP.returns = {
@@ -761,6 +794,40 @@ MCP.returns = {
761
794
  names: { type: "array", items: { type: "string" } },
762
795
  apps: { type: "object" }
763
796
  }
797
+ },
798
+ compilePipeline: {
799
+ type: "object",
800
+ properties: {
801
+ pipeline_id: { type: "string" },
802
+ scope_id: { type: "string" },
803
+ system_context: { type: "string" },
804
+ developer_context: { type: "string" },
805
+ user_context: { type: "string" },
806
+ attachments: { type: "object" }
807
+ }
808
+ },
809
+ runThoughtAgent: {
810
+ type: "object",
811
+ properties: {
812
+ agent_id: { type: "string" },
813
+ pipeline_id: { type: "string" },
814
+ scope_id: { type: "string" },
815
+ ai_response_id: { type: "string" },
816
+ proposed_thoughts_count: { type: "integer" },
817
+ saved_thought_ids: {
818
+ type: "array",
819
+ items: { type: "string" }
820
+ },
821
+ questions: {
822
+ type: "array",
823
+ items: { type: "string" }
824
+ },
825
+ missing_info: {
826
+ type: "array",
827
+ items: { type: "string" }
828
+ },
829
+ raw_response: { type: "string" }
830
+ }
764
831
  }
765
832
  };
766
833