@a5c-ai/babysitter-sdk 0.0.187-staging.cbd8dccc → 0.0.187-staging.cfbb3a2e
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/api/breakpoints.d.ts +94 -0
- package/dist/api/breakpoints.d.ts.map +1 -0
- package/dist/api/breakpoints.js +318 -0
- package/dist/api/effects.d.ts.map +1 -1
- package/dist/api/effects.js +83 -103
- package/dist/api/eventStream.d.ts +34 -0
- package/dist/api/eventStream.d.ts.map +1 -0
- package/dist/api/eventStream.js +126 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +14 -1
- package/dist/api/utils.d.ts +28 -0
- package/dist/api/utils.d.ts.map +1 -0
- package/dist/api/utils.js +74 -0
- package/dist/cli/commands/daemon.d.ts +31 -0
- package/dist/cli/commands/daemon.d.ts.map +1 -0
- package/dist/cli/commands/daemon.js +148 -0
- package/dist/cli/commands/jsonlInteractive.d.ts +35 -0
- package/dist/cli/commands/jsonlInteractive.d.ts.map +1 -0
- package/dist/cli/commands/jsonlInteractive.js +302 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +54 -0
- package/dist/daemon/config.d.ts +8 -0
- package/dist/daemon/config.d.ts.map +1 -0
- package/dist/daemon/config.js +122 -0
- package/dist/daemon/daemonLog.d.ts +13 -0
- package/dist/daemon/daemonLog.d.ts.map +1 -0
- package/dist/daemon/daemonLog.js +64 -0
- package/dist/daemon/fileWatcher.d.ts +9 -0
- package/dist/daemon/fileWatcher.d.ts.map +1 -0
- package/dist/daemon/fileWatcher.js +140 -0
- package/dist/daemon/index.d.ts +12 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +22 -0
- package/dist/daemon/lifecycle.d.ts +12 -0
- package/dist/daemon/lifecycle.d.ts.map +1 -0
- package/dist/daemon/lifecycle.js +257 -0
- package/dist/daemon/loop.d.ts +21 -0
- package/dist/daemon/loop.d.ts.map +1 -0
- package/dist/daemon/loop.js +181 -0
- package/dist/daemon/timerScheduler.d.ts +17 -0
- package/dist/daemon/timerScheduler.d.ts.map +1 -0
- package/dist/daemon/timerScheduler.js +122 -0
- package/dist/daemon/types.d.ts +78 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/daemon/types.js +5 -0
- package/dist/daemon/webhookListener.d.ts +6 -0
- package/dist/daemon/webhookListener.d.ts.map +1 -0
- package/dist/daemon/webhookListener.js +108 -0
- package/dist/dashboard/ink/contexts/ChatContext.d.ts +26 -7
- package/dist/dashboard/ink/contexts/ChatContext.d.ts.map +1 -1
- package/dist/dashboard/ink/contexts/ChatContext.js +58 -17
- package/dist/dashboard/ink/helpers.d.ts +105 -1
- package/dist/dashboard/ink/helpers.d.ts.map +1 -1
- package/dist/dashboard/ink/helpers.js +246 -0
- package/dist/dashboard/ink/hooks/useChat.d.ts +1 -1
- package/dist/dashboard/ink/hooks/useChat.d.ts.map +1 -1
- package/dist/dashboard/ink/index.d.ts +13 -1
- package/dist/dashboard/ink/index.d.ts.map +1 -1
- package/dist/dashboard/ink/index.js +35 -1
- package/dist/dashboard/ink/views/SessionView.d.ts.map +1 -1
- package/dist/dashboard/ink/views/SessionView.js +64 -20
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +3 -1
- package/dist/storage/journalWatcher.d.ts +24 -0
- package/dist/storage/journalWatcher.d.ts.map +1 -0
- package/dist/storage/journalWatcher.js +183 -0
- package/package.json +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GAP-JSON-003: JSON Breakpoint Interaction API.
|
|
3
|
+
*
|
|
4
|
+
* Typed API wrappers for listing, showing, and responding to breakpoint effects,
|
|
5
|
+
* plus auto-approval rule management. All functions return ApiResult envelopes
|
|
6
|
+
* and never throw.
|
|
7
|
+
*/
|
|
8
|
+
import type { ApiResult } from "./runs";
|
|
9
|
+
import type { BreakpointRule, AutoApprovalResult } from "../breakpoints/types";
|
|
10
|
+
import type { BreakpointConfig } from "../profiles/types";
|
|
11
|
+
export interface ListBreakpointsOutput {
|
|
12
|
+
breakpoints: BreakpointSummary[];
|
|
13
|
+
}
|
|
14
|
+
export interface BreakpointSummary {
|
|
15
|
+
effectId: string;
|
|
16
|
+
breakpointId?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
expert?: string | string[];
|
|
20
|
+
strategy?: string;
|
|
21
|
+
autoApproval?: unknown;
|
|
22
|
+
requestedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ShowBreakpointOutput {
|
|
25
|
+
effectId: string;
|
|
26
|
+
status: string;
|
|
27
|
+
breakpointId?: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
expert?: string | string[];
|
|
32
|
+
strategy?: string;
|
|
33
|
+
previousFeedback?: string;
|
|
34
|
+
attempt?: number;
|
|
35
|
+
options?: unknown;
|
|
36
|
+
autoApproval?: unknown;
|
|
37
|
+
result?: unknown;
|
|
38
|
+
requestedAt?: string;
|
|
39
|
+
resolvedAt?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface RespondToBreakpointInput {
|
|
42
|
+
runDir: string;
|
|
43
|
+
effectId: string;
|
|
44
|
+
approved: boolean;
|
|
45
|
+
response?: string;
|
|
46
|
+
feedback?: string;
|
|
47
|
+
option?: string;
|
|
48
|
+
respondedBy?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface AddAutoApprovalRuleInput {
|
|
51
|
+
pattern: string;
|
|
52
|
+
action: "auto-approve" | "never-auto-approve";
|
|
53
|
+
createdBy: string;
|
|
54
|
+
id?: string;
|
|
55
|
+
source?: string;
|
|
56
|
+
note?: string;
|
|
57
|
+
rulesPath?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface EvaluateAutoApprovalInput {
|
|
60
|
+
breakpointId: string;
|
|
61
|
+
tags?: string[];
|
|
62
|
+
expert?: string;
|
|
63
|
+
rulesPath?: string;
|
|
64
|
+
autoApproveAfterN?: number;
|
|
65
|
+
consecutiveApprovals?: number;
|
|
66
|
+
profileConfig?: BreakpointConfig;
|
|
67
|
+
}
|
|
68
|
+
export declare function apiListBreakpoints(input: {
|
|
69
|
+
runDir: string;
|
|
70
|
+
}): Promise<ApiResult<ListBreakpointsOutput>>;
|
|
71
|
+
export declare function apiShowBreakpoint(input: {
|
|
72
|
+
runDir: string;
|
|
73
|
+
effectId: string;
|
|
74
|
+
}): Promise<ApiResult<ShowBreakpointOutput>>;
|
|
75
|
+
export declare function apiRespondToBreakpoint(input: RespondToBreakpointInput): Promise<ApiResult<{
|
|
76
|
+
resultRef: string;
|
|
77
|
+
}>>;
|
|
78
|
+
export declare function apiListAutoApprovalRules(input?: {
|
|
79
|
+
rulesPath?: string;
|
|
80
|
+
}): Promise<ApiResult<{
|
|
81
|
+
rules: BreakpointRule[];
|
|
82
|
+
}>>;
|
|
83
|
+
export declare function apiAddAutoApprovalRule(input: AddAutoApprovalRuleInput): Promise<ApiResult<{
|
|
84
|
+
rule: BreakpointRule;
|
|
85
|
+
rules: BreakpointRule[];
|
|
86
|
+
}>>;
|
|
87
|
+
export declare function apiRemoveAutoApprovalRule(input: {
|
|
88
|
+
ruleId: string;
|
|
89
|
+
rulesPath?: string;
|
|
90
|
+
}): Promise<ApiResult<{
|
|
91
|
+
rules: BreakpointRule[];
|
|
92
|
+
}>>;
|
|
93
|
+
export declare function apiEvaluateAutoApproval(input: EvaluateAutoApprovalInput): Promise<ApiResult<AutoApprovalResult>>;
|
|
94
|
+
//# sourceMappingURL=breakpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../src/api/breakpoints.ts"],"names":[],"mappings":"AAAA;;;;;;GA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AC,CAyE3C;AAED,wBAAsB,wBAAwB,CAC5C,KAAK,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7B,OAAO,CAAC,SAAS,CAAC;IAAE,KAAK,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC,CAAC,CAQjD;AAED,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,SAAS,CAAC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC,CAAC,CA6BvE;AAED,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,SAAS,CAAC;IAAE,KAAK,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC,CAAC,CAmBjD;AAED,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAuBxC"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GAP-JSON-003: JSON Breakpoint Interaction API.
|
|
4
|
+
*
|
|
5
|
+
* Typed API wrappers for listing, showing, and responding to breakpoint effects,
|
|
6
|
+
* plus auto-approval rule management. All functions return ApiResult envelopes
|
|
7
|
+
* and never throw.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.apiListBreakpoints = apiListBreakpoints;
|
|
44
|
+
exports.apiShowBreakpoint = apiShowBreakpoint;
|
|
45
|
+
exports.apiRespondToBreakpoint = apiRespondToBreakpoint;
|
|
46
|
+
exports.apiListAutoApprovalRules = apiListAutoApprovalRules;
|
|
47
|
+
exports.apiAddAutoApprovalRule = apiAddAutoApprovalRule;
|
|
48
|
+
exports.apiRemoveAutoApprovalRule = apiRemoveAutoApprovalRule;
|
|
49
|
+
exports.apiEvaluateAutoApproval = apiEvaluateAutoApproval;
|
|
50
|
+
const crypto = __importStar(require("node:crypto"));
|
|
51
|
+
const journal_1 = require("../storage/journal");
|
|
52
|
+
const tasks_1 = require("../storage/tasks");
|
|
53
|
+
const lock_1 = require("../storage/lock");
|
|
54
|
+
const serializer_1 = require("../tasks/serializer");
|
|
55
|
+
const rules_1 = require("../breakpoints/rules");
|
|
56
|
+
const evaluator_1 = require("../breakpoints/evaluator");
|
|
57
|
+
const utils_1 = require("./utils");
|
|
58
|
+
// ── Internal helpers ───────────────────────────────────────────────────────
|
|
59
|
+
function isBreakpointEffect(info) {
|
|
60
|
+
return info.kind === "breakpoint" || info.taskId === "__sdk.breakpoint";
|
|
61
|
+
}
|
|
62
|
+
// ── API functions ──────────────────────────────────────────────────────────
|
|
63
|
+
async function apiListBreakpoints(input) {
|
|
64
|
+
try {
|
|
65
|
+
if (!input.runDir) {
|
|
66
|
+
return (0, utils_1.fail)("INVALID_INPUT", "runDir must be a non-empty string");
|
|
67
|
+
}
|
|
68
|
+
if (!(await (0, utils_1.pathExists)(input.runDir))) {
|
|
69
|
+
return (0, utils_1.fail)("RUN_NOT_FOUND", `Run directory not found: ${input.runDir}`);
|
|
70
|
+
}
|
|
71
|
+
const events = await (0, journal_1.loadJournal)(input.runDir);
|
|
72
|
+
const effectMap = (0, utils_1.buildBaseEffectMap)(events);
|
|
73
|
+
const breakpoints = [];
|
|
74
|
+
for (const info of effectMap.values()) {
|
|
75
|
+
if (!isBreakpointEffect(info))
|
|
76
|
+
continue;
|
|
77
|
+
if (info.lifecycle !== "requested")
|
|
78
|
+
continue;
|
|
79
|
+
// Read task definition to extract breakpoint-specific fields
|
|
80
|
+
let taskDef;
|
|
81
|
+
try {
|
|
82
|
+
taskDef = await (0, tasks_1.readTaskDefinition)(input.runDir, info.effectId);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// task.json may not exist
|
|
86
|
+
}
|
|
87
|
+
const td = taskDef;
|
|
88
|
+
breakpoints.push({
|
|
89
|
+
effectId: info.effectId,
|
|
90
|
+
breakpointId: td?.breakpointId,
|
|
91
|
+
title: td?.title,
|
|
92
|
+
tags: Array.isArray(td?.tags) ? td.tags : undefined,
|
|
93
|
+
expert: td?.expert,
|
|
94
|
+
strategy: td?.strategy,
|
|
95
|
+
autoApproval: td?.autoApproval,
|
|
96
|
+
requestedAt: info.requestedAt,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return (0, utils_1.ok)({ breakpoints });
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
103
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function apiShowBreakpoint(input) {
|
|
107
|
+
try {
|
|
108
|
+
if (!input.runDir) {
|
|
109
|
+
return (0, utils_1.fail)("INVALID_INPUT", "runDir must be a non-empty string");
|
|
110
|
+
}
|
|
111
|
+
if (!input.effectId) {
|
|
112
|
+
return (0, utils_1.fail)("INVALID_INPUT", "effectId must be a non-empty string");
|
|
113
|
+
}
|
|
114
|
+
if (!(await (0, utils_1.pathExists)(input.runDir))) {
|
|
115
|
+
return (0, utils_1.fail)("RUN_NOT_FOUND", `Run directory not found: ${input.runDir}`);
|
|
116
|
+
}
|
|
117
|
+
const events = await (0, journal_1.loadJournal)(input.runDir);
|
|
118
|
+
const effectMap = (0, utils_1.buildBaseEffectMap)(events);
|
|
119
|
+
const info = effectMap.get(input.effectId);
|
|
120
|
+
if (!info) {
|
|
121
|
+
return (0, utils_1.fail)("EFFECT_NOT_FOUND", `Effect not found: ${input.effectId}`);
|
|
122
|
+
}
|
|
123
|
+
if (!isBreakpointEffect(info)) {
|
|
124
|
+
return (0, utils_1.fail)("EFFECT_NOT_BREAKPOINT", `Effect ${input.effectId} is not a breakpoint (kind=${info.kind})`);
|
|
125
|
+
}
|
|
126
|
+
// Read task definition
|
|
127
|
+
let taskDef;
|
|
128
|
+
try {
|
|
129
|
+
taskDef = await (0, tasks_1.readTaskDefinition)(input.runDir, input.effectId);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// task.json may not exist
|
|
133
|
+
}
|
|
134
|
+
// Read result if resolved
|
|
135
|
+
let resultData = undefined;
|
|
136
|
+
if (info.lifecycle === "resolved") {
|
|
137
|
+
try {
|
|
138
|
+
const storedResult = await (0, tasks_1.readTaskResult)(input.runDir, input.effectId);
|
|
139
|
+
resultData = storedResult ?? undefined;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// result.json may be missing/corrupt
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const td = taskDef;
|
|
146
|
+
const output = {
|
|
147
|
+
effectId: info.effectId,
|
|
148
|
+
status: info.lifecycle,
|
|
149
|
+
breakpointId: td?.breakpointId,
|
|
150
|
+
title: td?.title,
|
|
151
|
+
description: td?.description,
|
|
152
|
+
tags: Array.isArray(td?.tags) ? td.tags : undefined,
|
|
153
|
+
expert: td?.expert,
|
|
154
|
+
strategy: td?.strategy,
|
|
155
|
+
previousFeedback: td?.previousFeedback,
|
|
156
|
+
attempt: typeof td?.attempt === "number" ? td.attempt : undefined,
|
|
157
|
+
options: td?.options,
|
|
158
|
+
autoApproval: td?.autoApproval,
|
|
159
|
+
result: resultData,
|
|
160
|
+
requestedAt: info.requestedAt,
|
|
161
|
+
resolvedAt: info.resolvedAt,
|
|
162
|
+
};
|
|
163
|
+
return (0, utils_1.ok)(output);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
167
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function apiRespondToBreakpoint(input) {
|
|
171
|
+
try {
|
|
172
|
+
// Validate input
|
|
173
|
+
if (!input.runDir) {
|
|
174
|
+
return (0, utils_1.fail)("INVALID_INPUT", "runDir must be a non-empty string");
|
|
175
|
+
}
|
|
176
|
+
if (!input.effectId) {
|
|
177
|
+
return (0, utils_1.fail)("INVALID_INPUT", "effectId must be a non-empty string");
|
|
178
|
+
}
|
|
179
|
+
if (input.approved === false && (!input.feedback || input.feedback.trim() === "")) {
|
|
180
|
+
return (0, utils_1.fail)("INVALID_INPUT", "feedback is required when rejecting a breakpoint (approved=false)");
|
|
181
|
+
}
|
|
182
|
+
if (!(await (0, utils_1.pathExists)(input.runDir))) {
|
|
183
|
+
return (0, utils_1.fail)("RUN_NOT_FOUND", `Run directory not found: ${input.runDir}`);
|
|
184
|
+
}
|
|
185
|
+
return await (0, lock_1.withRunLock)(input.runDir, "api:respondToBreakpoint", async () => {
|
|
186
|
+
const events = await (0, journal_1.loadJournal)(input.runDir);
|
|
187
|
+
const effectMap = (0, utils_1.buildBaseEffectMap)(events);
|
|
188
|
+
const info = effectMap.get(input.effectId);
|
|
189
|
+
if (!info) {
|
|
190
|
+
return (0, utils_1.fail)("EFFECT_NOT_FOUND", `Effect not found: ${input.effectId}`);
|
|
191
|
+
}
|
|
192
|
+
if (!isBreakpointEffect(info)) {
|
|
193
|
+
return (0, utils_1.fail)("EFFECT_NOT_BREAKPOINT", `Effect ${input.effectId} is not a breakpoint (kind=${info.kind})`);
|
|
194
|
+
}
|
|
195
|
+
if (info.lifecycle !== "requested") {
|
|
196
|
+
return (0, utils_1.fail)("EFFECT_NOT_PENDING", `Breakpoint ${input.effectId} is not pending (status=${info.lifecycle})`);
|
|
197
|
+
}
|
|
198
|
+
const taskId = info.taskId ?? `task-${input.effectId}`;
|
|
199
|
+
const invocationKey = info.invocationKey ?? `key-${input.effectId}`;
|
|
200
|
+
// Build breakpoint result value
|
|
201
|
+
const breakpointResult = {
|
|
202
|
+
approved: input.approved,
|
|
203
|
+
};
|
|
204
|
+
if (input.response !== undefined)
|
|
205
|
+
breakpointResult.response = input.response;
|
|
206
|
+
if (input.feedback !== undefined)
|
|
207
|
+
breakpointResult.feedback = input.feedback;
|
|
208
|
+
if (input.option !== undefined)
|
|
209
|
+
breakpointResult.option = input.option;
|
|
210
|
+
if (input.respondedBy !== undefined)
|
|
211
|
+
breakpointResult.respondedBy = input.respondedBy;
|
|
212
|
+
const { resultRef } = await (0, serializer_1.serializeAndWriteTaskResult)({
|
|
213
|
+
runDir: input.runDir,
|
|
214
|
+
effectId: input.effectId,
|
|
215
|
+
taskId,
|
|
216
|
+
invocationKey,
|
|
217
|
+
payload: {
|
|
218
|
+
status: "ok",
|
|
219
|
+
result: breakpointResult,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
await (0, journal_1.appendEvent)({
|
|
223
|
+
runDir: input.runDir,
|
|
224
|
+
eventType: "EFFECT_RESOLVED",
|
|
225
|
+
event: {
|
|
226
|
+
effectId: input.effectId,
|
|
227
|
+
status: "ok",
|
|
228
|
+
resultRef,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
return (0, utils_1.ok)({ resultRef });
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
236
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function apiListAutoApprovalRules(input) {
|
|
240
|
+
try {
|
|
241
|
+
const rules = await (0, rules_1.readRules)(input?.rulesPath);
|
|
242
|
+
return (0, utils_1.ok)({ rules });
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
246
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async function apiAddAutoApprovalRule(input) {
|
|
250
|
+
try {
|
|
251
|
+
if (!input.pattern) {
|
|
252
|
+
return (0, utils_1.fail)("INVALID_INPUT", "pattern must be a non-empty string");
|
|
253
|
+
}
|
|
254
|
+
const validActions = ["auto-approve", "never-auto-approve"];
|
|
255
|
+
if (!validActions.includes(input.action)) {
|
|
256
|
+
return (0, utils_1.fail)("INVALID_INPUT", `action must be one of: ${validActions.join(", ")}`);
|
|
257
|
+
}
|
|
258
|
+
if (!input.createdBy) {
|
|
259
|
+
return (0, utils_1.fail)("INVALID_INPUT", "createdBy must be a non-empty string");
|
|
260
|
+
}
|
|
261
|
+
const rule = {
|
|
262
|
+
id: input.id ?? crypto.randomUUID(),
|
|
263
|
+
pattern: input.pattern,
|
|
264
|
+
action: input.action,
|
|
265
|
+
createdAt: new Date().toISOString(),
|
|
266
|
+
createdBy: input.createdBy,
|
|
267
|
+
source: input.source,
|
|
268
|
+
note: input.note,
|
|
269
|
+
};
|
|
270
|
+
const rules = await (0, rules_1.addRule)(rule, input.rulesPath);
|
|
271
|
+
return (0, utils_1.ok)({ rule, rules });
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
275
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function apiRemoveAutoApprovalRule(input) {
|
|
279
|
+
try {
|
|
280
|
+
if (!input.ruleId) {
|
|
281
|
+
return (0, utils_1.fail)("INVALID_INPUT", "ruleId must be a non-empty string");
|
|
282
|
+
}
|
|
283
|
+
// Check if rule exists before removing
|
|
284
|
+
const existingRules = await (0, rules_1.readRules)(input.rulesPath);
|
|
285
|
+
const ruleExists = existingRules.some((r) => r.id === input.ruleId);
|
|
286
|
+
if (!ruleExists) {
|
|
287
|
+
return (0, utils_1.fail)("RULE_NOT_FOUND", `Rule not found: ${input.ruleId}`);
|
|
288
|
+
}
|
|
289
|
+
const rules = await (0, rules_1.removeRule)(input.ruleId, input.rulesPath);
|
|
290
|
+
return (0, utils_1.ok)({ rules });
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
294
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async function apiEvaluateAutoApproval(input) {
|
|
298
|
+
try {
|
|
299
|
+
if (!input.breakpointId) {
|
|
300
|
+
return (0, utils_1.fail)("INVALID_INPUT", "breakpointId must be a non-empty string");
|
|
301
|
+
}
|
|
302
|
+
const rules = await (0, rules_1.readRules)(input.rulesPath);
|
|
303
|
+
const result = (0, evaluator_1.evaluateAutoApproval)({
|
|
304
|
+
breakpointId: input.breakpointId,
|
|
305
|
+
tags: input.tags,
|
|
306
|
+
expert: input.expert,
|
|
307
|
+
rules,
|
|
308
|
+
profileConfig: input.profileConfig,
|
|
309
|
+
consecutiveApprovals: input.consecutiveApprovals,
|
|
310
|
+
autoApproveAfterN: input.autoApproveAfterN,
|
|
311
|
+
});
|
|
312
|
+
return (0, utils_1.ok)(result);
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
316
|
+
return (0, utils_1.fail)("INTERNAL_ERROR", msg);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/api/effects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/api/effects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKjE,KAAK,kBAAkB,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AACjE,KAAK,kBAAkB,GAAG,WAAW,GAAG,aAAa,GAAG,gBAAgB,GAAG,WAAW,CAAC;AAEvF,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QACP,IA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