@framers/agentos 0.1.228 → 0.1.230

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.
Files changed (37) hide show
  1. package/README.md +1 -0
  2. package/dist/api/editImage.d.ts +21 -0
  3. package/dist/api/editImage.d.ts.map +1 -1
  4. package/dist/api/editImage.js +30 -2
  5. package/dist/api/editImage.js.map +1 -1
  6. package/dist/api/generateImage.d.ts +12 -1
  7. package/dist/api/generateImage.d.ts.map +1 -1
  8. package/dist/api/generateImage.js +7 -2
  9. package/dist/api/generateImage.js.map +1 -1
  10. package/dist/emergent/ForgeRejectionClassifier.d.ts +67 -0
  11. package/dist/emergent/ForgeRejectionClassifier.d.ts.map +1 -0
  12. package/dist/emergent/ForgeRejectionClassifier.js +126 -0
  13. package/dist/emergent/ForgeRejectionClassifier.js.map +1 -0
  14. package/dist/emergent/ForgeSchemaInference.d.ts +39 -0
  15. package/dist/emergent/ForgeSchemaInference.d.ts.map +1 -0
  16. package/dist/emergent/ForgeSchemaInference.js +92 -0
  17. package/dist/emergent/ForgeSchemaInference.js.map +1 -0
  18. package/dist/emergent/ForgeShapeValidator.d.ts +41 -0
  19. package/dist/emergent/ForgeShapeValidator.d.ts.map +1 -0
  20. package/dist/emergent/ForgeShapeValidator.js +57 -0
  21. package/dist/emergent/ForgeShapeValidator.js.map +1 -0
  22. package/dist/emergent/ForgeStatsAggregator.d.ts +94 -0
  23. package/dist/emergent/ForgeStatsAggregator.d.ts.map +1 -0
  24. package/dist/emergent/ForgeStatsAggregator.js +123 -0
  25. package/dist/emergent/ForgeStatsAggregator.js.map +1 -0
  26. package/dist/emergent/index.d.ts +5 -0
  27. package/dist/emergent/index.d.ts.map +1 -1
  28. package/dist/emergent/index.js +9 -0
  29. package/dist/emergent/index.js.map +1 -1
  30. package/dist/emergent/wrapForgeTool.d.ts +114 -0
  31. package/dist/emergent/wrapForgeTool.d.ts.map +1 -0
  32. package/dist/emergent/wrapForgeTool.js +219 -0
  33. package/dist/emergent/wrapForgeTool.js.map +1 -0
  34. package/dist/media/images/providers/ReplicateImageProvider.d.ts.map +1 -1
  35. package/dist/media/images/providers/ReplicateImageProvider.js +7 -0
  36. package/dist/media/images/providers/ReplicateImageProvider.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @fileoverview Pre-judge shape validator for forge requests.
3
+ * @module @framers/agentos/emergent/ForgeShapeValidator
4
+ *
5
+ * Catches the failure modes that dominate cheap-tier forge rejections
6
+ * (empty schema properties, too-few testCases, empty-input testCases)
7
+ * BEFORE the judge LLM sees the request. Every shape-check rejection
8
+ * saves one judge invocation plus the sandbox round-trip that would
9
+ * have followed it.
10
+ *
11
+ * Pure function, no dependencies.
12
+ */
13
+ /**
14
+ * Validate a forge request's shape against the rules that dominate
15
+ * cheap-tier failures. Every violation is reported at once (no
16
+ * short-circuit) so the caller can build one comprehensive error
17
+ * message to show the LLM.
18
+ *
19
+ * Rules enforced:
20
+ * - `inputSchema.properties` must declare at least one field.
21
+ * - `outputSchema.properties` must declare at least one field.
22
+ * - `testCases` must have at least 2 entries.
23
+ * - Every testCase must have a non-empty `input` object.
24
+ *
25
+ * @param req Request fragment. Only the three fields are inspected;
26
+ * other fields on the forge request are ignored.
27
+ * @returns Array of human-readable error strings. Empty means the
28
+ * request's shape is well-formed enough to forward to the judge.
29
+ */
30
+ export function validateForgeShape(req) {
31
+ const errors = [];
32
+ const inputSchema = req.inputSchema;
33
+ const outputSchema = req.outputSchema;
34
+ const inputProps = inputSchema && typeof inputSchema.properties === 'object' ? inputSchema.properties : null;
35
+ const outputProps = outputSchema && typeof outputSchema.properties === 'object' ? outputSchema.properties : null;
36
+ if (!inputProps || Object.keys(inputProps).length === 0) {
37
+ errors.push('inputSchema has no declared properties; add at least two typed fields');
38
+ }
39
+ if (!outputProps || Object.keys(outputProps).length === 0) {
40
+ errors.push('outputSchema has no declared properties; add at least one typed output field');
41
+ }
42
+ const tcArr = Array.isArray(req.testCases)
43
+ ? req.testCases
44
+ : [];
45
+ if (tcArr.length < 2) {
46
+ errors.push(`need at least 2 testCases, got ${tcArr.length}`);
47
+ }
48
+ const emptyInputs = tcArr.filter(tc => {
49
+ const inp = tc?.input;
50
+ return !inp || typeof inp !== 'object' || Object.keys(inp).length === 0;
51
+ }).length;
52
+ if (emptyInputs > 0) {
53
+ errors.push(`${emptyInputs} testCase${emptyInputs === 1 ? '' : 's'} use empty input; every test needs real field values`);
54
+ }
55
+ return errors;
56
+ }
57
+ //# sourceMappingURL=ForgeShapeValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForgeShapeValidator.js","sourceRoot":"","sources":["../../src/emergent/ForgeShapeValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAaH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAsB;IACvD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,WAAW,GAAG,GAAG,CAAC,WAA8D,CAAC;IACvF,MAAM,YAAY,GAAG,GAAG,CAAC,YAA+D,CAAC;IACzF,MAAM,UAAU,GACd,WAAW,IAAI,OAAO,WAAW,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5F,MAAM,WAAW,GACf,YAAY,IAAI,OAAO,YAAY,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/F,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,uEAAuE,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,CAAC,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1D,MAAM,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;IAC9F,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;QACxC,CAAC,CAAE,GAAG,CAAC,SAAkE;QACzE,CAAC,CAAC,EAAE,CAAC;IACP,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC,kCAAkC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QACpC,MAAM,GAAG,GAAG,EAAE,EAAE,KAAK,CAAC;QACtB,OAAO,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,GAA8B,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACrG,CAAC,CAAC,CAAC,MAAM,CAAC;IACV,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CACT,GAAG,WAAW,YAAY,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,sDAAsD,CAC7G,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @fileoverview Standalone per-run aggregator for forge reliability
3
+ * telemetry. Composes with any cost/usage tracker the consumer already
4
+ * has.
5
+ * @module @framers/agentos/emergent/ForgeStatsAggregator
6
+ *
7
+ * Pinned shape: the {@link ForgeStats} snapshot must stay stable. It
8
+ * ships through consumer telemetry endpoints that downstream dashboards
9
+ * parse; renaming fields is a breaking change. Fold in new dimensions
10
+ * by adding fields, not renaming existing ones.
11
+ */
12
+ import { type ForgeRejectionCategory } from './ForgeRejectionClassifier.js';
13
+ /** Per-run forge reliability rollup snapshot. */
14
+ export interface ForgeStats {
15
+ /** Total forge attempts (approved + rejected combined). */
16
+ attempts: number;
17
+ /** Attempts the judge approved. */
18
+ approved: number;
19
+ /** Attempts the judge or shape validator rejected. */
20
+ rejected: number;
21
+ /** Sum of confidence across approved attempts. Divide by `approved` for avg. */
22
+ approvedConfidenceSum: number;
23
+ /**
24
+ * Count of unique tool names seen this run (union of approved + rejected).
25
+ * A tool rejected then re-forged under the same name counts once.
26
+ */
27
+ uniqueNames: number;
28
+ /** Count of unique tool names that landed approved at least once this run. */
29
+ uniqueApproved: number;
30
+ /**
31
+ * Count of unique tool names that were ONLY rejected (never approved)
32
+ * this run. The retry loop did not recover these. Actionable signal
33
+ * for "real quality failures" vs retry churn.
34
+ */
35
+ uniqueTerminalRejections: number;
36
+ /**
37
+ * Histogram of rejection reasons, classified via
38
+ * {@link classifyForgeRejection}. Keys match {@link ForgeRejectionCategory}.
39
+ */
40
+ rejectionReasons: Record<ForgeRejectionCategory, number>;
41
+ }
42
+ /**
43
+ * Create a fresh, zeroed {@link ForgeStats} snapshot. Exposed for consumers
44
+ * that want to seed their own state or compare against a baseline.
45
+ */
46
+ export declare function emptyForgeStats(): ForgeStats;
47
+ /**
48
+ * Aggregator for forge outcomes across a single run. No dependency on
49
+ * the cost tracker or any consumer-specific types — consumers compose
50
+ * it into whatever telemetry layer they already have.
51
+ *
52
+ * Typical wiring: the consumer's forge capture callback calls
53
+ * {@link recordAttempt} with the outcome fields, then embeds
54
+ * {@link snapshot} under a `forgeStats` key in whatever payload the
55
+ * consumer ships to clients.
56
+ */
57
+ export declare class ForgeStatsAggregator {
58
+ private stats;
59
+ private readonly approvedNames;
60
+ private readonly rejectedNames;
61
+ /**
62
+ * Record one forge attempt's outcome.
63
+ *
64
+ * @param approved `true` when the judge approved; `false` for shape-check
65
+ * or judge rejections.
66
+ * @param confidence Judge's confidence score for approved tools. Summed
67
+ * into `approvedConfidenceSum` (skipped for rejections so rejection
68
+ * confidence does not dilute the average).
69
+ * @param toolName Optional tool name. When provided, tracks unique-tool
70
+ * metrics (eventually-approved vs terminally-rejected) rather than
71
+ * raw attempt counts.
72
+ * @param errorReason Optional rejection-reason string. On a rejected
73
+ * attempt, passed through {@link classifyForgeRejection} and binned
74
+ * into `rejectionReasons`.
75
+ */
76
+ recordAttempt(approved: boolean, confidence: number, toolName?: string, errorReason?: string): void;
77
+ /**
78
+ * Build a plain-object snapshot of current stats. Safe to JSON-serialize
79
+ * and ship to clients. Returns a shallow copy so callers can mutate
80
+ * without affecting the aggregator's internal state.
81
+ */
82
+ snapshot(): ForgeStats;
83
+ /**
84
+ * Clear all accumulated state. Useful when the aggregator is reused
85
+ * across multiple runs in one process.
86
+ */
87
+ reset(): void;
88
+ /**
89
+ * Recompute the three unique-tool counters from the name sets. Called
90
+ * after every attempt so `snapshot()` never has to do the math itself.
91
+ */
92
+ private refreshUniqueCounts;
93
+ }
94
+ //# sourceMappingURL=ForgeStatsAggregator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForgeStatsAggregator.d.ts","sourceRoot":"","sources":["../../src/emergent/ForgeStatsAggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,+BAA+B,CAAC;AAEvC,iDAAiD;AACjD,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,qBAAqB,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,cAAc,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,wBAAwB,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CAC1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,UAAU,CAiB5C;AAED;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IAEnD;;;;;;;;;;;;;;OAcG;IACH,aAAa,CACX,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI;IAeP;;;;OAIG;IACH,QAAQ,IAAI,UAAU;IAOtB;;;OAGG;IACH,KAAK,IAAI,IAAI;IAMb;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAY5B"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @fileoverview Standalone per-run aggregator for forge reliability
3
+ * telemetry. Composes with any cost/usage tracker the consumer already
4
+ * has.
5
+ * @module @framers/agentos/emergent/ForgeStatsAggregator
6
+ *
7
+ * Pinned shape: the {@link ForgeStats} snapshot must stay stable. It
8
+ * ships through consumer telemetry endpoints that downstream dashboards
9
+ * parse; renaming fields is a breaking change. Fold in new dimensions
10
+ * by adding fields, not renaming existing ones.
11
+ */
12
+ import { classifyForgeRejection, } from './ForgeRejectionClassifier.js';
13
+ /**
14
+ * Create a fresh, zeroed {@link ForgeStats} snapshot. Exposed for consumers
15
+ * that want to seed their own state or compare against a baseline.
16
+ */
17
+ export function emptyForgeStats() {
18
+ return {
19
+ attempts: 0,
20
+ approved: 0,
21
+ rejected: 0,
22
+ approvedConfidenceSum: 0,
23
+ uniqueNames: 0,
24
+ uniqueApproved: 0,
25
+ uniqueTerminalRejections: 0,
26
+ rejectionReasons: {
27
+ schema_extra_field: 0,
28
+ shape_check: 0,
29
+ parse_error: 0,
30
+ judge_correctness: 0,
31
+ other: 0,
32
+ },
33
+ };
34
+ }
35
+ /**
36
+ * Aggregator for forge outcomes across a single run. No dependency on
37
+ * the cost tracker or any consumer-specific types — consumers compose
38
+ * it into whatever telemetry layer they already have.
39
+ *
40
+ * Typical wiring: the consumer's forge capture callback calls
41
+ * {@link recordAttempt} with the outcome fields, then embeds
42
+ * {@link snapshot} under a `forgeStats` key in whatever payload the
43
+ * consumer ships to clients.
44
+ */
45
+ export class ForgeStatsAggregator {
46
+ constructor() {
47
+ this.stats = emptyForgeStats();
48
+ this.approvedNames = new Set();
49
+ this.rejectedNames = new Set();
50
+ }
51
+ /**
52
+ * Record one forge attempt's outcome.
53
+ *
54
+ * @param approved `true` when the judge approved; `false` for shape-check
55
+ * or judge rejections.
56
+ * @param confidence Judge's confidence score for approved tools. Summed
57
+ * into `approvedConfidenceSum` (skipped for rejections so rejection
58
+ * confidence does not dilute the average).
59
+ * @param toolName Optional tool name. When provided, tracks unique-tool
60
+ * metrics (eventually-approved vs terminally-rejected) rather than
61
+ * raw attempt counts.
62
+ * @param errorReason Optional rejection-reason string. On a rejected
63
+ * attempt, passed through {@link classifyForgeRejection} and binned
64
+ * into `rejectionReasons`.
65
+ */
66
+ recordAttempt(approved, confidence, toolName, errorReason) {
67
+ this.stats.attempts += 1;
68
+ if (approved) {
69
+ this.stats.approved += 1;
70
+ this.stats.approvedConfidenceSum += confidence;
71
+ if (toolName)
72
+ this.approvedNames.add(toolName);
73
+ }
74
+ else {
75
+ this.stats.rejected += 1;
76
+ if (toolName)
77
+ this.rejectedNames.add(toolName);
78
+ const category = classifyForgeRejection(errorReason);
79
+ this.stats.rejectionReasons[category] += 1;
80
+ }
81
+ this.refreshUniqueCounts();
82
+ }
83
+ /**
84
+ * Build a plain-object snapshot of current stats. Safe to JSON-serialize
85
+ * and ship to clients. Returns a shallow copy so callers can mutate
86
+ * without affecting the aggregator's internal state.
87
+ */
88
+ snapshot() {
89
+ return {
90
+ ...this.stats,
91
+ rejectionReasons: { ...this.stats.rejectionReasons },
92
+ };
93
+ }
94
+ /**
95
+ * Clear all accumulated state. Useful when the aggregator is reused
96
+ * across multiple runs in one process.
97
+ */
98
+ reset() {
99
+ this.stats = emptyForgeStats();
100
+ this.approvedNames.clear();
101
+ this.rejectedNames.clear();
102
+ }
103
+ /**
104
+ * Recompute the three unique-tool counters from the name sets. Called
105
+ * after every attempt so `snapshot()` never has to do the math itself.
106
+ */
107
+ refreshUniqueCounts() {
108
+ this.stats.uniqueApproved = this.approvedNames.size;
109
+ let terminal = 0;
110
+ for (const n of this.rejectedNames) {
111
+ if (!this.approvedNames.has(n))
112
+ terminal += 1;
113
+ }
114
+ this.stats.uniqueTerminalRejections = terminal;
115
+ const union = new Set();
116
+ for (const n of this.approvedNames)
117
+ union.add(n);
118
+ for (const n of this.rejectedNames)
119
+ union.add(n);
120
+ this.stats.uniqueNames = union.size;
121
+ }
122
+ }
123
+ //# sourceMappingURL=ForgeStatsAggregator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForgeStatsAggregator.js","sourceRoot":"","sources":["../../src/emergent/ForgeStatsAggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC;AAgCvC;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,qBAAqB,EAAE,CAAC;QACxB,WAAW,EAAE,CAAC;QACd,cAAc,EAAE,CAAC;QACjB,wBAAwB,EAAE,CAAC;QAC3B,gBAAgB,EAAE;YAChB,kBAAkB,EAAE,CAAC;YACrB,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,CAAC;YACd,iBAAiB,EAAE,CAAC;YACpB,KAAK,EAAE,CAAC;SACT;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,oBAAoB;IAAjC;QACU,UAAK,GAAe,eAAe,EAAE,CAAC;QAC7B,kBAAa,GAAG,IAAI,GAAG,EAAU,CAAC;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AAC;QACpD,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,QAAQ,IAAI,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,wBAAwB,GAAG,QAAQ,CAAC;QAC/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa;YAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACjD,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa;YAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC;IACtC,CAAC;CACF"}
@@ -33,4 +33,9 @@ export { SelfEvaluateTool } from './SelfEvaluateTool.js';
33
33
  export { PersonalityMutationStore } from './PersonalityMutationStore.js';
34
34
  export type { PersonalityMutation, RecordMutationInput, DecayResult } from './PersonalityMutationStore.js';
35
35
  export type { SelfImprovementToolDeps } from './EmergentCapabilityEngine.js';
36
+ export { classifyForgeRejection, type ForgeRejectionCategory, } from './ForgeRejectionClassifier.js';
37
+ export { validateForgeShape, type ForgeShapeRequest, } from './ForgeShapeValidator.js';
38
+ export { inferSchemaFromTestCases, type ForgeSchemaInferenceRequest, } from './ForgeSchemaInference.js';
39
+ export { wrapForgeTool, type CapturedForge, type ForgeLogEvent, type WrapForgeToolOptions, } from './wrapForgeTool.js';
40
+ export { ForgeStatsAggregator, emptyForgeStats, type ForgeStats, } from './ForgeStatsAggregator.js';
36
41
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/emergent/index.ts"],"names":[],"mappings":"AAAA;;;;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AAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC3G,YAAY,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAM7E,OAAO,EACL,sBAAsB,EACtB,KAAK,sBAAsB,GAC5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,kBAAkB,EAClB,KAAK,iBAAiB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,KAAK,2BAA2B,GACjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,KAAK,UAAU,GAChB,MAAM,2BAA2B,CAAC"}
@@ -25,4 +25,13 @@ export { ManageSkillsTool } from './ManageSkillsTool.js';
25
25
  export { CreateWorkflowTool } from './CreateWorkflowTool.js';
26
26
  export { SelfEvaluateTool } from './SelfEvaluateTool.js';
27
27
  export { PersonalityMutationStore } from './PersonalityMutationStore.js';
28
+ // Forge observability — instrumentation for consumers that want live
29
+ // visibility into forge health (rejection-reason histogram, shape-check
30
+ // pre-validator, schema inference from testCases, capture wrapper,
31
+ // aggregator).
32
+ export { classifyForgeRejection, } from './ForgeRejectionClassifier.js';
33
+ export { validateForgeShape, } from './ForgeShapeValidator.js';
34
+ export { inferSchemaFromTestCases, } from './ForgeSchemaInference.js';
35
+ export { wrapForgeTool, } from './wrapForgeTool.js';
36
+ export { ForgeStatsAggregator, emptyForgeStats, } from './ForgeStatsAggregator.js';
28
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/emergent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAA8B,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAKjE,OAAO,EACL,oCAAoC,EACpC,wBAAwB,EACxB,4BAA4B,EAC5B,wBAAwB,EACxB,kCAAkC,GACnC,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","s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AEhB,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @fileoverview Wrapper around ForgeToolMetaTool that normalizes LLM
3
+ * output, runs a pre-judge shape check, captures every attempt, and
4
+ * surfaces outcomes as structured log events.
5
+ * @module @framers/agentos/emergent/wrapForgeTool
6
+ *
7
+ * LLMs emit wide variety in forge_tool args (stringified JSON, wrong
8
+ * mode spellings, missing allowlists, no code body). This wrapper fixes
9
+ * them up so the engine never crashes deep in sandbox validation, and
10
+ * every attempt gets recorded to the caller's capture sink regardless
11
+ * of outcome. That gives consumers an attempt-level ground truth that
12
+ * does not depend on the LLM self-reporting its forge calls.
13
+ *
14
+ * Pure wrapper over ForgeToolMetaTool + ForgeShapeValidator +
15
+ * ForgeSchemaInference. No stdout dependency — log events route
16
+ * through the optional `log` callback.
17
+ */
18
+ import type { ITool } from '../core/tools/ITool.js';
19
+ import { ForgeToolMetaTool } from './ForgeToolMetaTool.js';
20
+ /**
21
+ * Captured forge event — ground-truth record of an actual forge call,
22
+ * independent of whether the LLM self-reported it.
23
+ */
24
+ export interface CapturedForge {
25
+ /** Tool name (`fixed.name || 'unnamed'`). */
26
+ name: string;
27
+ /** Tool description (`fixed.description || name`). */
28
+ description: string;
29
+ /** `'sandbox'` or `'compose'` after normalization. */
30
+ mode: string;
31
+ /** Forge request's declared input schema post-normalization. */
32
+ inputSchema: unknown;
33
+ /** Forge request's declared output schema post-normalization. */
34
+ outputSchema: unknown;
35
+ /** Did the judge approve? */
36
+ approved: boolean;
37
+ /** Judge confidence for approved tools; 0 on rejection. */
38
+ confidence: number;
39
+ /** Judge verdict payload or shape-check context. */
40
+ output: unknown;
41
+ /** Populated on rejection or error. Truncated to 240 chars. */
42
+ errorReason?: string;
43
+ /**
44
+ * Optional free-form scope label (e.g. a department name, a chat
45
+ * agent id, or any grouping the caller wants propagated onto every
46
+ * capture record). Left undefined when the caller does not group.
47
+ */
48
+ scope?: string;
49
+ /** Wall-clock ms so captures can be attributed to surrounding events. */
50
+ timestamp: number;
51
+ }
52
+ /**
53
+ * Structured log event emitted at each forge lifecycle step. Consumers
54
+ * who care about stdout visibility can pass a `log` callback that
55
+ * renders this into console.log / pm2 / whatever. AgentOS emits
56
+ * nothing by default so the wrapper is safe to use in quiet contexts.
57
+ */
58
+ export type ForgeLogEvent = {
59
+ kind: 'start';
60
+ scope?: string;
61
+ toolName: string;
62
+ mode: string;
63
+ } | {
64
+ kind: 'approved';
65
+ scope?: string;
66
+ toolName: string;
67
+ confidence: number;
68
+ } | {
69
+ kind: 'rejected';
70
+ scope?: string;
71
+ toolName: string;
72
+ reason: string;
73
+ } | {
74
+ kind: 'error';
75
+ scope?: string;
76
+ toolName: string;
77
+ error: string;
78
+ };
79
+ /** Options for {@link wrapForgeTool}. */
80
+ export interface WrapForgeToolOptions {
81
+ /** The raw ForgeToolMetaTool instance from EmergentCapabilityEngine. */
82
+ raw: ForgeToolMetaTool;
83
+ /** GMI / agent id patched onto the tool execution context. */
84
+ agentId: string;
85
+ /** Session id patched onto the tool execution context under sessionData. */
86
+ sessionId: string;
87
+ /** Required capture sink. Every attempt (valid or not) is recorded. */
88
+ capture: (record: CapturedForge) => void;
89
+ /**
90
+ * Optional scope label propagated onto every CapturedForge. Use for
91
+ * semantic grouping when multiple callers share a wrapper (dept
92
+ * name, channel id, agent role, etc.).
93
+ */
94
+ scope?: string;
95
+ /**
96
+ * Optional log callback for lifecycle visibility. When undefined,
97
+ * no log events are emitted (quiet mode).
98
+ */
99
+ log?: (event: ForgeLogEvent) => void;
100
+ }
101
+ /**
102
+ * Wrap the raw ForgeToolMetaTool so each forge attempt gets normalized,
103
+ * pre-validated, captured, and logged.
104
+ *
105
+ * Normalization fixes: stringified-JSON fields, mode synonyms (`code`,
106
+ * `javascript`, `js` → `sandbox`; `composed`, `composition`, `chain`,
107
+ * `pipeline` → `compose`), missing allowlist / code body / steps /
108
+ * schemas / testCases. After normalization, the shape validator runs;
109
+ * on failure the judge is skipped and a rejection record is captured
110
+ * immediately. On success, the raw meta-tool executes and the result's
111
+ * verdict is folded into a capture record.
112
+ */
113
+ export declare function wrapForgeTool(options: WrapForgeToolOptions): ITool;
114
+ //# sourceMappingURL=wrapForgeTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapForgeTool.d.ts","sourceRoot":"","sources":["../../src/emergent/wrapForgeTool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAwB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAuB,MAAM,wBAAwB,CAAC;AAIhF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,WAAW,EAAE,OAAO,CAAC;IACrB,iEAAiE;IACjE,YAAY,EAAE,OAAO,CAAC;IACtB,6BAA6B;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,MAAM,EAAE,OAAO,CAAC;IAChB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,E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