@granular-software/sdk 0.4.25 → 0.4.27
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/dist/agent-evals.d.mts +1 -1
- package/dist/agent-evals.d.ts +1 -1
- package/dist/agent-evals.js +226 -20
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +226 -20
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/cli/index.js +240 -20
- package/dist/{client-BeKRGMoT.d.mts → client-CigjaeO8.d.mts} +70 -29
- package/dist/{client-BeKRGMoT.d.ts → client-CigjaeO8.d.ts} +70 -29
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +527 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +527 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4588,6 +4588,22 @@ var Session = class {
|
|
|
4588
4588
|
}
|
|
4589
4589
|
};
|
|
4590
4590
|
}
|
|
4591
|
+
stringifyConversationValue(value) {
|
|
4592
|
+
if (typeof value === "string") {
|
|
4593
|
+
return value;
|
|
4594
|
+
}
|
|
4595
|
+
if (typeof value === "boolean") {
|
|
4596
|
+
return value ? "Confirmed" : "Canceled";
|
|
4597
|
+
}
|
|
4598
|
+
if (value === void 0) {
|
|
4599
|
+
return "";
|
|
4600
|
+
}
|
|
4601
|
+
try {
|
|
4602
|
+
return JSON.stringify(value, null, 2);
|
|
4603
|
+
} catch {
|
|
4604
|
+
return String(value);
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4591
4607
|
// --- Public API ---
|
|
4592
4608
|
get document() {
|
|
4593
4609
|
return this.client.doc;
|
|
@@ -4738,6 +4754,20 @@ var Session = class {
|
|
|
4738
4754
|
answer: resolvedAnswer,
|
|
4739
4755
|
value: resolvedAnswer
|
|
4740
4756
|
});
|
|
4757
|
+
try {
|
|
4758
|
+
const content = this.stringifyConversationValue(resolvedAnswer);
|
|
4759
|
+
if (content.trim()) {
|
|
4760
|
+
await this.appendConversationMessage({
|
|
4761
|
+
role: "user",
|
|
4762
|
+
content,
|
|
4763
|
+
promptId
|
|
4764
|
+
});
|
|
4765
|
+
}
|
|
4766
|
+
} catch {
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
async appendConversationMessage(input) {
|
|
4770
|
+
return this.client.call("conversation.append", input);
|
|
4741
4771
|
}
|
|
4742
4772
|
/**
|
|
4743
4773
|
* Get the current list of available effects.
|
|
@@ -4877,9 +4907,24 @@ var Session = class {
|
|
|
4877
4907
|
* Get domain documentation for LLMs. Returns types (preferred) or fallback.
|
|
4878
4908
|
*/
|
|
4879
4909
|
async getDomainDocumentation() {
|
|
4880
|
-
const types = await
|
|
4881
|
-
|
|
4882
|
-
|
|
4910
|
+
const [types, docs] = await Promise.all([
|
|
4911
|
+
this.getDomainTypes(),
|
|
4912
|
+
this.getDomainDocs()
|
|
4913
|
+
]);
|
|
4914
|
+
const normalizedTypes = types.trim();
|
|
4915
|
+
const normalizedDocs = docs.trim();
|
|
4916
|
+
if (normalizedTypes && (normalizedTypes.includes("export declare class") || normalizedTypes.includes("export async function"))) {
|
|
4917
|
+
if (!normalizedDocs) {
|
|
4918
|
+
return normalizedTypes;
|
|
4919
|
+
}
|
|
4920
|
+
return [
|
|
4921
|
+
normalizedTypes,
|
|
4922
|
+
"Generated usage notes from ./sandbox-tools docs:",
|
|
4923
|
+
normalizedDocs
|
|
4924
|
+
].join("\n\n");
|
|
4925
|
+
}
|
|
4926
|
+
if (normalizedDocs) {
|
|
4927
|
+
return normalizedDocs;
|
|
4883
4928
|
}
|
|
4884
4929
|
const summary = await this.getDomain();
|
|
4885
4930
|
return this.generateFallbackDocs(summary);
|
|
@@ -9689,10 +9734,15 @@ external_exports.union([
|
|
|
9689
9734
|
scalarType: external_exports.string().optional()
|
|
9690
9735
|
}).strict()
|
|
9691
9736
|
]);
|
|
9737
|
+
external_exports.union([
|
|
9738
|
+
external_exports.boolean(),
|
|
9739
|
+
external_exports.object({
|
|
9740
|
+
enabled: external_exports.boolean().optional(),
|
|
9741
|
+
phonetic: external_exports.boolean().optional()
|
|
9742
|
+
}).strict()
|
|
9743
|
+
]);
|
|
9692
9744
|
external_exports.object({
|
|
9693
|
-
operator: external_exports.enum(
|
|
9694
|
-
[...VALIDATION_RULE_OPERATORS]
|
|
9695
|
-
),
|
|
9745
|
+
operator: external_exports.enum([...VALIDATION_RULE_OPERATORS]),
|
|
9696
9746
|
stringValue: external_exports.string().optional(),
|
|
9697
9747
|
numberValue: external_exports.number().optional(),
|
|
9698
9748
|
booleanValue: external_exports.boolean().optional(),
|
|
@@ -9785,12 +9835,18 @@ function collectMetamodelSummarySelections(packages) {
|
|
|
9785
9835
|
const propertyFields = [];
|
|
9786
9836
|
const methodFields = [];
|
|
9787
9837
|
for (const metamodelPackage of packages) {
|
|
9788
|
-
pushUnique(
|
|
9838
|
+
pushUnique(
|
|
9839
|
+
classFields,
|
|
9840
|
+
metamodelPackage.summary.selections?.classFields || []
|
|
9841
|
+
);
|
|
9789
9842
|
pushUnique(
|
|
9790
9843
|
propertyFields,
|
|
9791
9844
|
metamodelPackage.summary.selections?.propertyFields || []
|
|
9792
9845
|
);
|
|
9793
|
-
pushUnique(
|
|
9846
|
+
pushUnique(
|
|
9847
|
+
methodFields,
|
|
9848
|
+
metamodelPackage.summary.selections?.methodFields || []
|
|
9849
|
+
);
|
|
9794
9850
|
}
|
|
9795
9851
|
return {
|
|
9796
9852
|
classFields: unique(classFields),
|
|
@@ -9878,7 +9934,11 @@ function createMetamodelRegistry(metamodelPackages) {
|
|
|
9878
9934
|
return collectMetamodelSummarySelections(packages);
|
|
9879
9935
|
},
|
|
9880
9936
|
applyClassSummaryReaders(rawClass, classSummary) {
|
|
9881
|
-
return applyMetamodelSummaryReadersToClass(
|
|
9937
|
+
return applyMetamodelSummaryReadersToClass(
|
|
9938
|
+
packages,
|
|
9939
|
+
rawClass,
|
|
9940
|
+
classSummary
|
|
9941
|
+
);
|
|
9882
9942
|
},
|
|
9883
9943
|
applyPropertySummaryReaders(rawProperty, propertySummary) {
|
|
9884
9944
|
return applyMetamodelSummaryReadersToProperty(
|
|
@@ -9888,7 +9948,11 @@ function createMetamodelRegistry(metamodelPackages) {
|
|
|
9888
9948
|
);
|
|
9889
9949
|
},
|
|
9890
9950
|
applyMethodSummaryReaders(rawMethod, methodSummary) {
|
|
9891
|
-
return applyMetamodelSummaryReadersToMethod(
|
|
9951
|
+
return applyMetamodelSummaryReadersToMethod(
|
|
9952
|
+
packages,
|
|
9953
|
+
rawMethod,
|
|
9954
|
+
methodSummary
|
|
9955
|
+
);
|
|
9892
9956
|
},
|
|
9893
9957
|
applyClassIR(classIR, classSummary) {
|
|
9894
9958
|
return applyMetamodelClassIR(packages, classIR, classSummary);
|
|
@@ -9936,6 +10000,10 @@ function mergeClassSummaryPatch(target, patch) {
|
|
|
9936
10000
|
}
|
|
9937
10001
|
function mergePropertySummaryPatch(target, patch) {
|
|
9938
10002
|
pushUnique(target.notes, patch.notes || []);
|
|
10003
|
+
if (patch.searchable !== void 0) target.searchable = patch.searchable;
|
|
10004
|
+
if (patch.searchablePhonetic !== void 0) {
|
|
10005
|
+
target.searchablePhonetic = patch.searchablePhonetic;
|
|
10006
|
+
}
|
|
9939
10007
|
if (patch.required !== void 0) target.required = patch.required;
|
|
9940
10008
|
if (patch.enumRule !== void 0) target.enumRule = patch.enumRule;
|
|
9941
10009
|
if (patch.filterBy !== void 0) target.filterBy = patch.filterBy;
|
|
@@ -9947,9 +10015,11 @@ function mergeMethodSummaryPatch(target, patch) {
|
|
|
9947
10015
|
if (patch.effectKey !== void 0) target.effectKey = patch.effectKey;
|
|
9948
10016
|
if (patch.description !== void 0) target.description = patch.description;
|
|
9949
10017
|
if (patch.inputSchema !== void 0) target.inputSchema = patch.inputSchema;
|
|
9950
|
-
if (patch.outputSchema !== void 0)
|
|
10018
|
+
if (patch.outputSchema !== void 0)
|
|
10019
|
+
target.outputSchema = patch.outputSchema;
|
|
9951
10020
|
if (patch.metamodels !== void 0) target.metamodels = patch.metamodels;
|
|
9952
|
-
if (patch.effectBehaviors !== void 0)
|
|
10021
|
+
if (patch.effectBehaviors !== void 0)
|
|
10022
|
+
target.effectBehaviors = patch.effectBehaviors;
|
|
9953
10023
|
if (patch.static !== void 0) target.static = patch.static;
|
|
9954
10024
|
}
|
|
9955
10025
|
function toPascalCase(value) {
|
|
@@ -10455,12 +10525,20 @@ function defaultFilterOperators(scalarType) {
|
|
|
10455
10525
|
switch ((scalarType || "").toLowerCase()) {
|
|
10456
10526
|
case "number":
|
|
10457
10527
|
case "date":
|
|
10458
|
-
return [
|
|
10528
|
+
return [
|
|
10529
|
+
"equal_to",
|
|
10530
|
+
"greater_than",
|
|
10531
|
+
"greater_than_or_equal_to",
|
|
10532
|
+
"less_than",
|
|
10533
|
+
"less_than_or_equal_to",
|
|
10534
|
+
"not_null"
|
|
10535
|
+
];
|
|
10459
10536
|
case "boolean":
|
|
10460
|
-
return ["equal_to", "not_null"];
|
|
10537
|
+
return ["equal_to", "true", "false", "not_null"];
|
|
10461
10538
|
default:
|
|
10462
10539
|
return [
|
|
10463
10540
|
"equal_to",
|
|
10541
|
+
"in",
|
|
10464
10542
|
"contains",
|
|
10465
10543
|
"not_contains",
|
|
10466
10544
|
"starts_with",
|
|
@@ -10469,16 +10547,26 @@ function defaultFilterOperators(scalarType) {
|
|
|
10469
10547
|
];
|
|
10470
10548
|
}
|
|
10471
10549
|
}
|
|
10550
|
+
function supportsDefaultFilterBy(scalarType) {
|
|
10551
|
+
return ["string", "number", "boolean", "date"].includes(
|
|
10552
|
+
String(scalarType || "").toLowerCase()
|
|
10553
|
+
);
|
|
10554
|
+
}
|
|
10472
10555
|
function normalizeFilterByInput(filterBy, scalarType) {
|
|
10473
|
-
if (
|
|
10556
|
+
if (filterBy === false) return null;
|
|
10557
|
+
if (filterBy === void 0) {
|
|
10558
|
+
if (!supportsDefaultFilterBy(scalarType)) return null;
|
|
10559
|
+
return { operators: defaultFilterOperators(scalarType), scalarType };
|
|
10560
|
+
}
|
|
10474
10561
|
if (filterBy === true) {
|
|
10475
|
-
return { operators: defaultFilterOperators(scalarType) };
|
|
10562
|
+
return { operators: defaultFilterOperators(scalarType), scalarType };
|
|
10476
10563
|
}
|
|
10477
10564
|
if (Array.isArray(filterBy)) {
|
|
10478
|
-
return { operators: filterBy };
|
|
10565
|
+
return { operators: filterBy, scalarType };
|
|
10479
10566
|
}
|
|
10480
10567
|
return {
|
|
10481
|
-
operators: filterBy.operators
|
|
10568
|
+
operators: filterBy.operators,
|
|
10569
|
+
scalarType: filterBy.scalarType || scalarType
|
|
10482
10570
|
};
|
|
10483
10571
|
}
|
|
10484
10572
|
function buildFilterByFieldMutations(fieldPath, filterBy, scalarType) {
|
|
@@ -10489,7 +10577,7 @@ function buildFilterByFieldMutations(fieldPath, filterBy, scalarType) {
|
|
|
10489
10577
|
label: `set filterBy on ${fieldPath}`,
|
|
10490
10578
|
query: `mutation { at(path: ${JSON.stringify(fieldPath)}) { set_filter_by(operators: ${JSON.stringify(
|
|
10491
10579
|
normalized.operators
|
|
10492
|
-
)}) { operators } } }`
|
|
10580
|
+
)}${normalized.scalarType ? `, scalar_type: ${JSON.stringify(normalized.scalarType)}` : ""}) { operators } } }`
|
|
10493
10581
|
}
|
|
10494
10582
|
];
|
|
10495
10583
|
}
|
|
@@ -10499,7 +10587,7 @@ var filterByMetamodelPackage = defineMetamodelPackage({
|
|
|
10499
10587
|
fieldRows: [
|
|
10500
10588
|
{
|
|
10501
10589
|
key: "filterBy",
|
|
10502
|
-
description: "Exposes filter operators for generated query surfaces.
|
|
10590
|
+
description: "Exposes filter operators for generated query surfaces. Scalar fields are filterable by default; set `filterBy: false` to opt out, or override with `true`, an operator array, or `{ operators, scalarType }`."
|
|
10503
10591
|
}
|
|
10504
10592
|
]
|
|
10505
10593
|
},
|
|
@@ -10763,6 +10851,123 @@ var requiredMetamodelPackage = defineMetamodelPackage({
|
|
|
10763
10851
|
}
|
|
10764
10852
|
});
|
|
10765
10853
|
|
|
10854
|
+
// ../metamodel-searchable/src/index.ts
|
|
10855
|
+
function supportsDefaultSearchable(scalarType) {
|
|
10856
|
+
return String(scalarType || "").toLowerCase() === "string";
|
|
10857
|
+
}
|
|
10858
|
+
function normalizeSearchableInput(searchable, scalarType) {
|
|
10859
|
+
if (!supportsDefaultSearchable(scalarType)) return null;
|
|
10860
|
+
if (typeof searchable === "boolean" || searchable === void 0) {
|
|
10861
|
+
return {
|
|
10862
|
+
enabled: searchable !== false,
|
|
10863
|
+
phonetic: false
|
|
10864
|
+
};
|
|
10865
|
+
}
|
|
10866
|
+
const enabled = searchable.enabled !== false;
|
|
10867
|
+
return {
|
|
10868
|
+
enabled,
|
|
10869
|
+
phonetic: enabled && searchable.phonetic === true
|
|
10870
|
+
};
|
|
10871
|
+
}
|
|
10872
|
+
function buildSearchableFieldMutations(fieldPath, searchable, scalarType) {
|
|
10873
|
+
const normalized = normalizeSearchableInput(searchable, scalarType);
|
|
10874
|
+
if (normalized === null) return [];
|
|
10875
|
+
return [
|
|
10876
|
+
{
|
|
10877
|
+
label: `set searchable on ${fieldPath}`,
|
|
10878
|
+
query: `mutation { at(path: ${JSON.stringify(fieldPath)}) { set_searchable(enabled: ${normalized.enabled}, phonetic: ${normalized.phonetic}) { enabled phonetic } } }`
|
|
10879
|
+
}
|
|
10880
|
+
];
|
|
10881
|
+
}
|
|
10882
|
+
var searchableMetamodelPackage = defineMetamodelPackage({
|
|
10883
|
+
id: "searchable",
|
|
10884
|
+
docs: {
|
|
10885
|
+
fieldRows: [
|
|
10886
|
+
{
|
|
10887
|
+
key: "searchable",
|
|
10888
|
+
description: "Controls full-text search exposure for string fields. String fields are searchable by default; set `searchable: false` to opt out, or use `searchable: { phonetic: true }` to keep the field searchable while enabling FalkorDB phonetic matching for class-wide search."
|
|
10889
|
+
}
|
|
10890
|
+
]
|
|
10891
|
+
},
|
|
10892
|
+
graphql: {
|
|
10893
|
+
typeDefs: [
|
|
10894
|
+
`
|
|
10895
|
+
type SearchableMetamodel {
|
|
10896
|
+
model: Model!
|
|
10897
|
+
enabled: Boolean!
|
|
10898
|
+
phonetic: Boolean!
|
|
10899
|
+
}
|
|
10900
|
+
|
|
10901
|
+
extend type Model {
|
|
10902
|
+
searchable: SearchableMetamodel
|
|
10903
|
+
}
|
|
10904
|
+
|
|
10905
|
+
extend type ModelMutation {
|
|
10906
|
+
set_searchable(enabled: Boolean!, phonetic: Boolean): SearchableMetamodel
|
|
10907
|
+
}
|
|
10908
|
+
`
|
|
10909
|
+
],
|
|
10910
|
+
createResolvers({ run }) {
|
|
10911
|
+
return {
|
|
10912
|
+
SearchableMetamodel: {
|
|
10913
|
+
model: (value) => value.model,
|
|
10914
|
+
enabled: (value) => value.enabled !== false,
|
|
10915
|
+
phonetic: (value) => value.phonetic === true
|
|
10916
|
+
},
|
|
10917
|
+
Model: {
|
|
10918
|
+
searchable: async (ant) => await run(ant.searchable())
|
|
10919
|
+
},
|
|
10920
|
+
ModelMutation: {
|
|
10921
|
+
set_searchable: async (ant, { enabled, phonetic }) => {
|
|
10922
|
+
return {
|
|
10923
|
+
model: await run(ant.set_searchable(enabled, phonetic === true)),
|
|
10924
|
+
enabled,
|
|
10925
|
+
phonetic: phonetic === true
|
|
10926
|
+
};
|
|
10927
|
+
}
|
|
10928
|
+
}
|
|
10929
|
+
};
|
|
10930
|
+
}
|
|
10931
|
+
},
|
|
10932
|
+
manifest: {
|
|
10933
|
+
buildFieldMutations(fieldPath, spec) {
|
|
10934
|
+
return buildSearchableFieldMutations(
|
|
10935
|
+
fieldPath,
|
|
10936
|
+
spec.searchable,
|
|
10937
|
+
spec.type
|
|
10938
|
+
);
|
|
10939
|
+
}
|
|
10940
|
+
},
|
|
10941
|
+
summary: {
|
|
10942
|
+
selections: {
|
|
10943
|
+
propertyFields: [`searchable { enabled phonetic }`]
|
|
10944
|
+
},
|
|
10945
|
+
readPropertySummary(rawProperty) {
|
|
10946
|
+
if (typeof rawProperty.searchable?.enabled !== "boolean") {
|
|
10947
|
+
return {};
|
|
10948
|
+
}
|
|
10949
|
+
return {
|
|
10950
|
+
searchable: rawProperty.searchable.enabled,
|
|
10951
|
+
searchablePhonetic: rawProperty.searchable.phonetic === true
|
|
10952
|
+
};
|
|
10953
|
+
}
|
|
10954
|
+
},
|
|
10955
|
+
domain: {
|
|
10956
|
+
applyToPropertyIR(propertyIR, propertySummary) {
|
|
10957
|
+
if (String(propertySummary.type || "").toLowerCase() !== "string" || propertySummary.searchable === false) {
|
|
10958
|
+
return propertyIR;
|
|
10959
|
+
}
|
|
10960
|
+
return {
|
|
10961
|
+
...propertyIR,
|
|
10962
|
+
docs: [
|
|
10963
|
+
...propertyIR.docs,
|
|
10964
|
+
propertySummary.searchablePhonetic ? "Searchable via `search` using FalkorDB full-text query syntax with phonetic matching enabled." : "Searchable via `search` using FalkorDB full-text query syntax."
|
|
10965
|
+
]
|
|
10966
|
+
};
|
|
10967
|
+
}
|
|
10968
|
+
}
|
|
10969
|
+
});
|
|
10970
|
+
|
|
10766
10971
|
// ../metamodel-state-machine/src/index.ts
|
|
10767
10972
|
function normalizeStateMachines(values) {
|
|
10768
10973
|
return (values || []).map((machine) => {
|
|
@@ -11343,6 +11548,7 @@ var DEFAULT_METAMODEL_PACKAGES = [
|
|
|
11343
11548
|
requiredMetamodelPackage,
|
|
11344
11549
|
enumMetamodelPackage,
|
|
11345
11550
|
filterByMetamodelPackage,
|
|
11551
|
+
searchableMetamodelPackage,
|
|
11346
11552
|
validationRuleMetamodelPackage,
|
|
11347
11553
|
stateMachineMetamodelPackage,
|
|
11348
11554
|
effectBehaviorsMetamodelPackage
|
|
@@ -14762,6 +14968,306 @@ function resolveJobPresentation({
|
|
|
14762
14968
|
};
|
|
14763
14969
|
}
|
|
14764
14970
|
|
|
14765
|
-
|
|
14971
|
+
// src/session-transcript.ts
|
|
14972
|
+
var EMPTY_HEAP = {
|
|
14973
|
+
entriesByPath: {},
|
|
14974
|
+
listsByName: {},
|
|
14975
|
+
variablesByName: {}};
|
|
14976
|
+
function asRecord4(value) {
|
|
14977
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
14978
|
+
return value;
|
|
14979
|
+
}
|
|
14980
|
+
function asArray2(value) {
|
|
14981
|
+
return Array.isArray(value) ? value : [];
|
|
14982
|
+
}
|
|
14983
|
+
function asNumber(value) {
|
|
14984
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
14985
|
+
}
|
|
14986
|
+
function asString(value) {
|
|
14987
|
+
return typeof value === "string" ? value : void 0;
|
|
14988
|
+
}
|
|
14989
|
+
function trimString(value) {
|
|
14990
|
+
return typeof value === "string" ? value.trim() : "";
|
|
14991
|
+
}
|
|
14992
|
+
function normalizeShowRefs(value) {
|
|
14993
|
+
const record = asRecord4(value);
|
|
14994
|
+
if (!record) return void 0;
|
|
14995
|
+
const normalizeRefs = (input) => {
|
|
14996
|
+
if (!Array.isArray(input)) return void 0;
|
|
14997
|
+
const refs = Array.from(
|
|
14998
|
+
new Set(
|
|
14999
|
+
input.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean)
|
|
15000
|
+
)
|
|
15001
|
+
);
|
|
15002
|
+
return refs.length > 0 ? refs : void 0;
|
|
15003
|
+
};
|
|
15004
|
+
const show = {
|
|
15005
|
+
entryPaths: normalizeRefs(record.entryPaths),
|
|
15006
|
+
listNames: normalizeRefs(record.listNames),
|
|
15007
|
+
variableNames: normalizeRefs(record.variableNames)
|
|
15008
|
+
};
|
|
15009
|
+
return show.entryPaths || show.listNames || show.variableNames ? show : void 0;
|
|
15010
|
+
}
|
|
15011
|
+
function stringifyTranscriptValue(value, fallback = "") {
|
|
15012
|
+
if (typeof value === "string") {
|
|
15013
|
+
return value.trim() || fallback;
|
|
15014
|
+
}
|
|
15015
|
+
if (typeof value === "boolean") {
|
|
15016
|
+
return value ? "Confirmed" : "Canceled";
|
|
15017
|
+
}
|
|
15018
|
+
if (value === void 0) {
|
|
15019
|
+
return fallback;
|
|
15020
|
+
}
|
|
15021
|
+
try {
|
|
15022
|
+
const json = JSON.stringify(value, null, 2);
|
|
15023
|
+
if (!json || json === "undefined") return fallback;
|
|
15024
|
+
return json.length > 2e3 ? `${json.slice(0, 2e3)}...` : json;
|
|
15025
|
+
} catch {
|
|
15026
|
+
return String(value);
|
|
15027
|
+
}
|
|
15028
|
+
}
|
|
15029
|
+
function buildArtifactHistory(show) {
|
|
15030
|
+
if (!show) return void 0;
|
|
15031
|
+
return `[Agent message]
|
|
15032
|
+
${stringifyTranscriptValue({ show }, "")}`;
|
|
15033
|
+
}
|
|
15034
|
+
function normalizeConversationMessage(raw) {
|
|
15035
|
+
const record = asRecord4(raw);
|
|
15036
|
+
if (!record) return null;
|
|
15037
|
+
const role = record.role === "user" ? "user" : record.role === "assistant" ? "assistant" : null;
|
|
15038
|
+
if (!role) return null;
|
|
15039
|
+
const content = trimString(
|
|
15040
|
+
record.content ?? record.reply ?? record.message ?? record.text
|
|
15041
|
+
);
|
|
15042
|
+
const show = normalizeShowRefs(record.show);
|
|
15043
|
+
const id = asString(record.id) || crypto.randomUUID();
|
|
15044
|
+
const timestamp = asNumber(record.timestamp) || asNumber(record.ts) || 0;
|
|
15045
|
+
if (!content && !show) return null;
|
|
15046
|
+
return {
|
|
15047
|
+
id,
|
|
15048
|
+
role,
|
|
15049
|
+
content,
|
|
15050
|
+
timestamp,
|
|
15051
|
+
jobId: asString(record.jobId),
|
|
15052
|
+
promptId: asString(record.promptId),
|
|
15053
|
+
show,
|
|
15054
|
+
historyContent: role === "assistant" ? content ? `[Assistant reply]
|
|
15055
|
+
${content}` : buildArtifactHistory(show) : void 0,
|
|
15056
|
+
source: "conversation"
|
|
15057
|
+
};
|
|
15058
|
+
}
|
|
15059
|
+
function normalizePromptEntries(jobId, rawPrompts, conversationPromptIds) {
|
|
15060
|
+
const promptsById = asRecord4(rawPrompts) || {};
|
|
15061
|
+
return Object.values(promptsById).map((value) => asRecord4(value)).filter((value) => Boolean(value)).sort(
|
|
15062
|
+
(left, right) => (asNumber(left.openedAt) || asNumber(left.answeredAt) || 0) - (asNumber(right.openedAt) || asNumber(right.answeredAt) || 0)
|
|
15063
|
+
).flatMap((prompt) => {
|
|
15064
|
+
const promptId = asString(prompt.promptId);
|
|
15065
|
+
if (!promptId || conversationPromptIds.has(promptId)) return [];
|
|
15066
|
+
const title = trimString(prompt.title);
|
|
15067
|
+
const message = trimString(prompt.message);
|
|
15068
|
+
const assistantContent = message || title || "Input required";
|
|
15069
|
+
const openedAt = asNumber(prompt.openedAt) || 0;
|
|
15070
|
+
const answeredAt = asNumber(prompt.answeredAt) || openedAt;
|
|
15071
|
+
const entries = [
|
|
15072
|
+
{
|
|
15073
|
+
id: `prompt:${promptId}:assistant`,
|
|
15074
|
+
role: "assistant",
|
|
15075
|
+
content: assistantContent,
|
|
15076
|
+
timestamp: openedAt,
|
|
15077
|
+
jobId,
|
|
15078
|
+
promptId,
|
|
15079
|
+
historyContent: `[Assistant reply]
|
|
15080
|
+
${assistantContent}`,
|
|
15081
|
+
source: "job_prompt"
|
|
15082
|
+
}
|
|
15083
|
+
];
|
|
15084
|
+
if (Object.prototype.hasOwnProperty.call(prompt, "answer")) {
|
|
15085
|
+
entries.push({
|
|
15086
|
+
id: `prompt:${promptId}:user`,
|
|
15087
|
+
role: "user",
|
|
15088
|
+
content: stringifyTranscriptValue(prompt.answer, ""),
|
|
15089
|
+
timestamp: answeredAt,
|
|
15090
|
+
jobId,
|
|
15091
|
+
promptId,
|
|
15092
|
+
source: "job_prompt"
|
|
15093
|
+
});
|
|
15094
|
+
}
|
|
15095
|
+
return entries;
|
|
15096
|
+
});
|
|
15097
|
+
}
|
|
15098
|
+
function normalizeAgentMessageEntries(jobId, rawMessages) {
|
|
15099
|
+
return asArray2(rawMessages).map((value) => asRecord4(value)).filter((value) => Boolean(value)).sort(
|
|
15100
|
+
(left, right) => (asNumber(left.timestamp) || asNumber(left.ts) || 0) - (asNumber(right.timestamp) || asNumber(right.ts) || 0)
|
|
15101
|
+
).flatMap((message) => {
|
|
15102
|
+
const messageId = asString(message.messageId) || asString(message.id) || crypto.randomUUID();
|
|
15103
|
+
const timestamp = asNumber(message.timestamp) || asNumber(message.ts) || 0;
|
|
15104
|
+
const reply = trimString(
|
|
15105
|
+
message.reply ?? message.message ?? message.text ?? message.content
|
|
15106
|
+
);
|
|
15107
|
+
const show = normalizeShowRefs(message.show);
|
|
15108
|
+
const entries = [];
|
|
15109
|
+
if (reply) {
|
|
15110
|
+
entries.push({
|
|
15111
|
+
id: `agent:${messageId}:text`,
|
|
15112
|
+
role: "assistant",
|
|
15113
|
+
content: reply,
|
|
15114
|
+
timestamp,
|
|
15115
|
+
jobId,
|
|
15116
|
+
historyContent: `[Assistant reply]
|
|
15117
|
+
${reply}`,
|
|
15118
|
+
source: "job_agent_message"
|
|
15119
|
+
});
|
|
15120
|
+
}
|
|
15121
|
+
if (show) {
|
|
15122
|
+
entries.push({
|
|
15123
|
+
id: `agent:${messageId}:artifacts`,
|
|
15124
|
+
role: "assistant",
|
|
15125
|
+
content: "",
|
|
15126
|
+
timestamp,
|
|
15127
|
+
jobId,
|
|
15128
|
+
show,
|
|
15129
|
+
historyContent: buildArtifactHistory(show),
|
|
15130
|
+
source: "job_agent_message"
|
|
15131
|
+
});
|
|
15132
|
+
}
|
|
15133
|
+
return entries;
|
|
15134
|
+
});
|
|
15135
|
+
}
|
|
15136
|
+
function buildJobFallbackEntries(jobId, job, sessionHeap) {
|
|
15137
|
+
const timestamp = asNumber(job.finishedAt) || asNumber(job.startedAt) || asNumber(job.submittedAt) || 0;
|
|
15138
|
+
const resultPreview = stringifyTranscriptValue(
|
|
15139
|
+
job.result,
|
|
15140
|
+
"No job result recorded."
|
|
15141
|
+
);
|
|
15142
|
+
const presentation = resolveJobPresentation({
|
|
15143
|
+
jobId,
|
|
15144
|
+
result: job.result,
|
|
15145
|
+
stdout: [],
|
|
15146
|
+
sessionHeap
|
|
15147
|
+
});
|
|
15148
|
+
const entries = [];
|
|
15149
|
+
const responseText = presentation.responseText || "";
|
|
15150
|
+
if (responseText) {
|
|
15151
|
+
entries.push({
|
|
15152
|
+
id: `job:${jobId}:result-text`,
|
|
15153
|
+
role: "assistant",
|
|
15154
|
+
content: responseText,
|
|
15155
|
+
timestamp,
|
|
15156
|
+
jobId,
|
|
15157
|
+
historyContent: `[Assistant reply]
|
|
15158
|
+
${responseText}`,
|
|
15159
|
+
source: "job_result"
|
|
15160
|
+
});
|
|
15161
|
+
}
|
|
15162
|
+
const show = {
|
|
15163
|
+
entryPaths: presentation.entries.map((entry) => entry.path),
|
|
15164
|
+
listNames: presentation.lists.map((list) => list.name)
|
|
15165
|
+
};
|
|
15166
|
+
if (show.entryPaths && show.entryPaths.length > 0 || show.listNames && show.listNames.length > 0) {
|
|
15167
|
+
entries.push({
|
|
15168
|
+
id: `job:${jobId}:result-artifacts`,
|
|
15169
|
+
role: "assistant",
|
|
15170
|
+
content: "",
|
|
15171
|
+
timestamp,
|
|
15172
|
+
jobId,
|
|
15173
|
+
show,
|
|
15174
|
+
historyContent: buildArtifactHistory(show),
|
|
15175
|
+
source: "job_result"
|
|
15176
|
+
});
|
|
15177
|
+
}
|
|
15178
|
+
if (entries.length === 0 && trimString(job.error)) {
|
|
15179
|
+
entries.push({
|
|
15180
|
+
id: `job:${jobId}:result-error`,
|
|
15181
|
+
role: "assistant",
|
|
15182
|
+
content: trimString(job.error),
|
|
15183
|
+
timestamp,
|
|
15184
|
+
jobId,
|
|
15185
|
+
historyContent: `[Assistant reply]
|
|
15186
|
+
${trimString(job.error)}`,
|
|
15187
|
+
source: "job_result"
|
|
15188
|
+
});
|
|
15189
|
+
}
|
|
15190
|
+
if (entries.length === 0 && resultPreview && resultPreview !== "No job result recorded.") {
|
|
15191
|
+
entries.push({
|
|
15192
|
+
id: `job:${jobId}:result-preview`,
|
|
15193
|
+
role: "assistant",
|
|
15194
|
+
content: resultPreview,
|
|
15195
|
+
timestamp,
|
|
15196
|
+
jobId,
|
|
15197
|
+
historyContent: `[Assistant reply]
|
|
15198
|
+
${resultPreview}`,
|
|
15199
|
+
source: "job_result"
|
|
15200
|
+
});
|
|
15201
|
+
}
|
|
15202
|
+
return entries;
|
|
15203
|
+
}
|
|
15204
|
+
function buildJobCodeEntry(jobId, job) {
|
|
15205
|
+
const code = trimString(job.source);
|
|
15206
|
+
if (!code) return null;
|
|
15207
|
+
const jobStatus = asString(job.status);
|
|
15208
|
+
const error = jobStatus === "failed" || jobStatus === "canceled" || jobStatus === "timeout" ? trimString(job.error) || `Job ${jobStatus}` : void 0;
|
|
15209
|
+
return {
|
|
15210
|
+
id: `job:${jobId}:code`,
|
|
15211
|
+
role: "assistant",
|
|
15212
|
+
content: "",
|
|
15213
|
+
timestamp: asNumber(job.submittedAt) || asNumber(job.startedAt) || asNumber(job.finishedAt) || 0,
|
|
15214
|
+
jobId,
|
|
15215
|
+
code,
|
|
15216
|
+
jobStatus,
|
|
15217
|
+
jobResultPreview: stringifyTranscriptValue(job.result, "No job result recorded."),
|
|
15218
|
+
error,
|
|
15219
|
+
source: "job_code"
|
|
15220
|
+
};
|
|
15221
|
+
}
|
|
15222
|
+
function buildSessionTranscript(input) {
|
|
15223
|
+
const liveDoc = input.liveDoc || null;
|
|
15224
|
+
const sessionHeap = input.sessionHeap || EMPTY_HEAP;
|
|
15225
|
+
const transcript = [];
|
|
15226
|
+
const conversationMessages = asArray2(asRecord4(liveDoc?.conversation)?.messages).map((message) => normalizeConversationMessage(message)).filter((message) => Boolean(message));
|
|
15227
|
+
const conversationPromptIds = new Set(
|
|
15228
|
+
conversationMessages.map((message) => message.promptId).filter((promptId) => Boolean(promptId))
|
|
15229
|
+
);
|
|
15230
|
+
const assistantConversationJobIds = new Set(
|
|
15231
|
+
conversationMessages.filter((message) => message.role === "assistant" && Boolean(message.jobId)).map((message) => message.jobId)
|
|
15232
|
+
);
|
|
15233
|
+
transcript.push(...conversationMessages);
|
|
15234
|
+
const jobsById = asRecord4(asRecord4(liveDoc?.jobs)?.byId) || {};
|
|
15235
|
+
const jobs = Object.values(jobsById).map((value) => asRecord4(value)).filter((value) => Boolean(value)).sort(
|
|
15236
|
+
(left, right) => (asNumber(left.submittedAt) || asNumber(left.startedAt) || asNumber(left.finishedAt) || 0) - (asNumber(right.submittedAt) || asNumber(right.startedAt) || asNumber(right.finishedAt) || 0)
|
|
15237
|
+
);
|
|
15238
|
+
for (const job of jobs) {
|
|
15239
|
+
const jobId = asString(job.jobId);
|
|
15240
|
+
if (!jobId) continue;
|
|
15241
|
+
const codeEntry = buildJobCodeEntry(jobId, job);
|
|
15242
|
+
if (codeEntry) {
|
|
15243
|
+
transcript.push(codeEntry);
|
|
15244
|
+
}
|
|
15245
|
+
transcript.push(
|
|
15246
|
+
...normalizePromptEntries(jobId, job.prompts, conversationPromptIds)
|
|
15247
|
+
);
|
|
15248
|
+
if (!assistantConversationJobIds.has(jobId)) {
|
|
15249
|
+
const agentEntries = normalizeAgentMessageEntries(jobId, job.agentMessages);
|
|
15250
|
+
if (agentEntries.length > 0) {
|
|
15251
|
+
transcript.push(...agentEntries);
|
|
15252
|
+
} else {
|
|
15253
|
+
transcript.push(
|
|
15254
|
+
...buildJobFallbackEntries(
|
|
15255
|
+
jobId,
|
|
15256
|
+
job,
|
|
15257
|
+
sessionHeap
|
|
15258
|
+
)
|
|
15259
|
+
);
|
|
15260
|
+
}
|
|
15261
|
+
}
|
|
15262
|
+
}
|
|
15263
|
+
return transcript.sort((left, right) => {
|
|
15264
|
+
if (left.timestamp !== right.timestamp) {
|
|
15265
|
+
return left.timestamp - right.timestamp;
|
|
15266
|
+
}
|
|
15267
|
+
return left.id.localeCompare(right.id);
|
|
15268
|
+
});
|
|
15269
|
+
}
|
|
15270
|
+
|
|
15271
|
+
export { Environment, Granular, Session, WSClient, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, buildSessionTranscript, createHarnessVerifierSnapshot, evaluateContinuation, extractPromptTokens, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, invokeRegisteredEffect, isLocalApiUrl, normalizeEffectBehaviors, normalizePrompt, normalizePromptText, normalizePromptType, projectHeapSummary, projectLoopSummary, projectWorkflowFocus, projectWorkflowSummary, resolveApiUrl, resolveAuthTokenForApiUrl, resolveJobPresentation, resolvePromptAnswer, reviewGeneratedJobCode, scorePromptChoiceMatch };
|
|
14766
15272
|
//# sourceMappingURL=index.mjs.map
|
|
14767
15273
|
//# sourceMappingURL=index.mjs.map
|