saico 2.2.2 → 2.2.3
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/context.js +32 -2
- package/itask.js +5 -1
- package/package.json +1 -1
package/context.js
CHANGED
|
@@ -72,6 +72,36 @@ class Context {
|
|
|
72
72
|
// Overridable: extending classes provide current state summary
|
|
73
73
|
getStateSummary() { return ''; }
|
|
74
74
|
|
|
75
|
+
// Recursively collect state summaries from child tasks that have no context
|
|
76
|
+
// (no msg Q), stopping at children that do have one.
|
|
77
|
+
_collectChildStateSummaries(task) {
|
|
78
|
+
if (!task.child || !task.child.size) return '';
|
|
79
|
+
const parts = [];
|
|
80
|
+
for (const child of task.child) {
|
|
81
|
+
if (child.context) continue; // has its own Q — boundary, stop here
|
|
82
|
+
if (typeof child.getStateSummary === 'function') {
|
|
83
|
+
const s = child.getStateSummary();
|
|
84
|
+
if (s) parts.push(s);
|
|
85
|
+
}
|
|
86
|
+
const nested = this._collectChildStateSummaries(child);
|
|
87
|
+
if (nested) parts.push(nested);
|
|
88
|
+
}
|
|
89
|
+
return parts.join('\n');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Internal (not overridable): own getStateSummary() + summaries from all
|
|
93
|
+
// contextless descendants, stopping at the first child that has its own Q.
|
|
94
|
+
_getStateSummary() {
|
|
95
|
+
const parts = [];
|
|
96
|
+
const own = this.getStateSummary();
|
|
97
|
+
if (own) parts.push(own);
|
|
98
|
+
if (this.task) {
|
|
99
|
+
const childSummaries = this._collectChildStateSummaries(this.task);
|
|
100
|
+
if (childSummaries) parts.push(childSummaries);
|
|
101
|
+
}
|
|
102
|
+
return parts.join('\n');
|
|
103
|
+
}
|
|
104
|
+
|
|
75
105
|
// Snapshot all public (non-underscore) task properties for dirty detection.
|
|
76
106
|
// Mirrors the observable proxy convention: _ prefix = internal, ignored.
|
|
77
107
|
// Does NOT call serialize() — that is for persistence, not dirty detection.
|
|
@@ -808,7 +838,7 @@ class Context {
|
|
|
808
838
|
if (add_tag) prompt.tag = ctx.tag;
|
|
809
839
|
fullQueue.push(prompt);
|
|
810
840
|
}
|
|
811
|
-
const ctxSummary = ctx.
|
|
841
|
+
const ctxSummary = ctx._getStateSummary();
|
|
812
842
|
if (ctxSummary)
|
|
813
843
|
fullQueue.push({role: 'system', content: '[State Summary]\n' + ctxSummary});
|
|
814
844
|
}
|
|
@@ -817,7 +847,7 @@ class Context {
|
|
|
817
847
|
if (add_tag) prompt.tag = this.tag;
|
|
818
848
|
fullQueue.push(prompt);
|
|
819
849
|
}
|
|
820
|
-
const stateSummary = this.
|
|
850
|
+
const stateSummary = this._getStateSummary();
|
|
821
851
|
if (stateSummary)
|
|
822
852
|
fullQueue.push({role: 'system', content: '[State Summary]\n' + stateSummary});
|
|
823
853
|
|
package/itask.js
CHANGED
|
@@ -78,7 +78,7 @@ function Itask(opt, states){
|
|
|
78
78
|
|
|
79
79
|
EventEmitter.call(this);
|
|
80
80
|
opt = opt || {};
|
|
81
|
-
this.id = makeId(10);
|
|
81
|
+
this.id = opt.id || makeId(10);
|
|
82
82
|
this.name = opt.name;
|
|
83
83
|
this.cancelable = !!opt.cancel;
|
|
84
84
|
this.info = opt.info || {};
|
|
@@ -746,6 +746,10 @@ Itask.prototype.closeContext = async function closeContext(){
|
|
|
746
746
|
await this.context.close();
|
|
747
747
|
};
|
|
748
748
|
|
|
749
|
+
// Overridable: contextless tasks can provide a state summary that bubbles up
|
|
750
|
+
// into the nearest ancestor context's _getStateSummary().
|
|
751
|
+
Itask.prototype.getStateSummary = function getStateSummary(){ return ''; };
|
|
752
|
+
|
|
749
753
|
// Reference to Context class (set by index.js to avoid circular dependency)
|
|
750
754
|
Itask.Context = null;
|
|
751
755
|
|