@mercuryo-ai/magicpay-cli 0.1.0
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/README.md +56 -0
- package/dist/agentbrowse-assistive.d.ts +2 -0
- package/dist/agentbrowse-assistive.d.ts.map +1 -0
- package/dist/agentbrowse-assistive.js +66 -0
- package/dist/assistive-llm-client.d.ts +13 -0
- package/dist/assistive-llm-client.d.ts.map +1 -0
- package/dist/assistive-llm-client.js +152 -0
- package/dist/browser-bridge/act.d.ts +5 -0
- package/dist/browser-bridge/act.d.ts.map +1 -0
- package/dist/browser-bridge/act.js +8 -0
- package/dist/browser-bridge/observe.d.ts +5 -0
- package/dist/browser-bridge/observe.d.ts.map +1 -0
- package/dist/browser-bridge/observe.js +53 -0
- package/dist/browser-home.d.ts +7 -0
- package/dist/browser-home.d.ts.map +1 -0
- package/dist/browser-home.js +34 -0
- package/dist/commands/act.d.ts +5 -0
- package/dist/commands/act.d.ts.map +1 -0
- package/dist/commands/act.js +8 -0
- package/dist/commands/attach.d.ts +4 -0
- package/dist/commands/attach.d.ts.map +1 -0
- package/dist/commands/attach.js +10 -0
- package/dist/commands/browser-status.d.ts +5 -0
- package/dist/commands/browser-status.d.ts.map +1 -0
- package/dist/commands/browser-status.js +5 -0
- package/dist/commands/close.d.ts +4 -0
- package/dist/commands/close.d.ts.map +1 -0
- package/dist/commands/close.js +11 -0
- package/dist/commands/end-session.d.ts +22 -0
- package/dist/commands/end-session.d.ts.map +1 -0
- package/dist/commands/end-session.js +104 -0
- package/dist/commands/extract.d.ts +4 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +14 -0
- package/dist/commands/fill-secret.d.ts +10 -0
- package/dist/commands/fill-secret.d.ts.map +1 -0
- package/dist/commands/fill-secret.js +483 -0
- package/dist/commands/find-form.d.ts +57 -0
- package/dist/commands/find-form.d.ts.map +1 -0
- package/dist/commands/find-form.js +138 -0
- package/dist/commands/get-secrets-catalog.d.ts +13 -0
- package/dist/commands/get-secrets-catalog.d.ts.map +1 -0
- package/dist/commands/get-secrets-catalog.js +103 -0
- package/dist/commands/init.d.ts +10 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +28 -0
- package/dist/commands/launch.d.ts +4 -0
- package/dist/commands/launch.d.ts.map +1 -0
- package/dist/commands/launch.js +10 -0
- package/dist/commands/mock-approve-secret.d.ts +21 -0
- package/dist/commands/mock-approve-secret.d.ts.map +1 -0
- package/dist/commands/mock-approve-secret.js +69 -0
- package/dist/commands/mock-deny-secret.d.ts +21 -0
- package/dist/commands/mock-deny-secret.d.ts.map +1 -0
- package/dist/commands/mock-deny-secret.js +69 -0
- package/dist/commands/navigate.d.ts +4 -0
- package/dist/commands/navigate.d.ts.map +1 -0
- package/dist/commands/navigate.js +9 -0
- package/dist/commands/observe.d.ts +5 -0
- package/dist/commands/observe.d.ts.map +1 -0
- package/dist/commands/observe.js +53 -0
- package/dist/commands/poll-secret.d.ts +13 -0
- package/dist/commands/poll-secret.d.ts.map +1 -0
- package/dist/commands/poll-secret.js +87 -0
- package/dist/commands/request-secret.d.ts +15 -0
- package/dist/commands/request-secret.d.ts.map +1 -0
- package/dist/commands/request-secret.js +235 -0
- package/dist/commands/screenshot.d.ts +4 -0
- package/dist/commands/screenshot.d.ts.map +1 -0
- package/dist/commands/screenshot.js +11 -0
- package/dist/commands/solve-captcha.d.ts +19 -0
- package/dist/commands/solve-captcha.d.ts.map +1 -0
- package/dist/commands/solve-captcha.js +63 -0
- package/dist/commands/start-session.d.ts +28 -0
- package/dist/commands/start-session.d.ts.map +1 -0
- package/dist/commands/start-session.js +298 -0
- package/dist/commands/status.d.ts +27 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +51 -0
- package/dist/commands/submit-form.d.ts +36 -0
- package/dist/commands/submit-form.d.ts.map +1 -0
- package/dist/commands/submit-form.js +242 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +1 -0
- package/dist/fillable-form-state.d.ts +5 -0
- package/dist/fillable-form-state.d.ts.map +1 -0
- package/dist/fillable-form-state.js +22 -0
- package/dist/gateway.d.ts +10 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +49 -0
- package/dist/generated/build-config.d.ts +2 -0
- package/dist/generated/build-config.d.ts.map +1 -0
- package/dist/generated/build-config.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +398 -0
- package/dist/mock-secret-cabinet.d.ts +37 -0
- package/dist/mock-secret-cabinet.d.ts.map +1 -0
- package/dist/mock-secret-cabinet.js +321 -0
- package/dist/mock-secret-store.d.ts +12 -0
- package/dist/mock-secret-store.d.ts.map +1 -0
- package/dist/mock-secret-store.js +108 -0
- package/dist/mock-stored-secrets.json +180 -0
- package/dist/otel-exporter.d.ts +58 -0
- package/dist/otel-exporter.d.ts.map +1 -0
- package/dist/otel-exporter.js +241 -0
- package/dist/otel-projector.d.ts +59 -0
- package/dist/otel-projector.d.ts.map +1 -0
- package/dist/otel-projector.js +325 -0
- package/dist/output.d.ts +10 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +29 -0
- package/dist/package-version.d.ts +2 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +14 -0
- package/dist/protected-exposure.d.ts +4 -0
- package/dist/protected-exposure.d.ts.map +1 -0
- package/dist/protected-exposure.js +17 -0
- package/dist/request-output.d.ts +4 -0
- package/dist/request-output.d.ts.map +1 -0
- package/dist/request-output.js +27 -0
- package/dist/run-store.d.ts +130 -0
- package/dist/run-store.d.ts.map +1 -0
- package/dist/run-store.js +245 -0
- package/dist/secret-backend.d.ts +28 -0
- package/dist/secret-backend.d.ts.map +1 -0
- package/dist/secret-backend.js +335 -0
- package/dist/secret-state.d.ts +7 -0
- package/dist/secret-state.d.ts.map +1 -0
- package/dist/secret-state.js +26 -0
- package/dist/session-backend.d.ts +34 -0
- package/dist/session-backend.d.ts.map +1 -0
- package/dist/session-backend.js +36 -0
- package/dist/update-check.d.ts +13 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +175 -0
- package/dist/workflow-session-completion.d.ts +32 -0
- package/dist/workflow-session-completion.d.ts.map +1 -0
- package/dist/workflow-session-completion.js +149 -0
- package/dist/workflow-state.d.ts +2 -0
- package/dist/workflow-state.d.ts.map +1 -0
- package/dist/workflow-state.js +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProtectedExposureArtifacts, ProtectedFillForm } from "@mercuryo-ai/agentbrowse/protected-fill";
|
|
2
|
+
import type { MagicPaySession } from "./workflow-state.js";
|
|
3
|
+
export declare function activateProtectedExposure(session: MagicPaySession, fillableForm: ProtectedFillForm, requestId: string, reason: "protected_fill_success" | "protected_fill_binding_stale" | "protected_fill_validation_failed" | "protected_fill_unexpected_error", artifacts?: ProtectedExposureArtifacts): void;
|
|
4
|
+
//# sourceMappingURL=protected-exposure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-exposure.d.ts","sourceRoot":"","sources":["../src/protected-exposure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,eAAe,EACxB,YAAY,EAAE,iBAAiB,EAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,EACF,wBAAwB,GACxB,8BAA8B,GAC9B,kCAAkC,GAClC,iCAAiC,EACrC,SAAS,CAAC,EAAE,0BAA0B,GACrC,IAAI,CAgBN"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function activateProtectedExposure(session, fillableForm, requestId, reason, artifacts) {
|
|
2
|
+
if (!session.runtime) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
session.runtime.protectedExposureByPage ??= {};
|
|
6
|
+
session.runtime.protectedExposureByPage[fillableForm.pageRef] = {
|
|
7
|
+
pageRef: fillableForm.pageRef,
|
|
8
|
+
scopeRef: fillableForm.scopeRef,
|
|
9
|
+
fillRef: fillableForm.fillRef,
|
|
10
|
+
requestId,
|
|
11
|
+
activatedAt: new Date().toISOString(),
|
|
12
|
+
...(artifacts?.exactValueProfile
|
|
13
|
+
? { exactValueProfile: artifacts.exactValueProfile }
|
|
14
|
+
: {}),
|
|
15
|
+
reason,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SecretRequestSnapshot } from '@mercuryo-ai/magicpay-sdk';
|
|
2
|
+
export declare function serializeSecretRequest(snapshot: SecretRequestSnapshot): Record<string, unknown>;
|
|
3
|
+
export declare function serializeSecretRequestContext(snapshot: SecretRequestSnapshot): Record<string, unknown>;
|
|
4
|
+
//# sourceMappingURL=request-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-output.d.ts","sourceRoot":"","sources":["../src/request-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAc/F;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,qBAAqB,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function serializeSecretRequest(snapshot) {
|
|
2
|
+
return {
|
|
3
|
+
requestId: snapshot.requestId,
|
|
4
|
+
fillRef: snapshot.fillRef,
|
|
5
|
+
requestType: snapshot.requestType,
|
|
6
|
+
status: snapshot.status,
|
|
7
|
+
...(snapshot.storedSecretRef ? { storedSecretRef: snapshot.storedSecretRef } : {}),
|
|
8
|
+
...(snapshot.kind ? { kind: snapshot.kind } : {}),
|
|
9
|
+
createdAt: snapshot.createdAt,
|
|
10
|
+
updatedAt: snapshot.updatedAt,
|
|
11
|
+
...(snapshot.expiresAt ? { expiresAt: snapshot.expiresAt } : {}),
|
|
12
|
+
...(snapshot.resolvedAt ? { resolvedAt: snapshot.resolvedAt } : {}),
|
|
13
|
+
...(snapshot.claimedAt ? { claimedAt: snapshot.claimedAt } : {}),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function serializeSecretRequestContext(snapshot) {
|
|
17
|
+
return {
|
|
18
|
+
requestType: snapshot.requestType,
|
|
19
|
+
...(snapshot.storedSecretRef ? { storedSecretRef: snapshot.storedSecretRef } : {}),
|
|
20
|
+
...(snapshot.kind ? { kind: snapshot.kind } : {}),
|
|
21
|
+
createdAt: snapshot.createdAt,
|
|
22
|
+
updatedAt: snapshot.updatedAt,
|
|
23
|
+
...(snapshot.expiresAt ? { expiresAt: snapshot.expiresAt } : {}),
|
|
24
|
+
...(snapshot.resolvedAt ? { resolvedAt: snapshot.resolvedAt } : {}),
|
|
25
|
+
...(snapshot.claimedAt ? { claimedAt: snapshot.claimedAt } : {}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export type RunStatus = 'running' | 'completed' | 'failed' | 'aborted';
|
|
2
|
+
export type RunTerminalStatus = Extract<RunStatus, 'completed' | 'failed' | 'aborted'>;
|
|
3
|
+
export type StepCommand = 'launch' | 'start-session' | 'end-session' | 'navigate' | 'observe' | 'act' | 'extract' | 'screenshot' | 'get-secrets-catalog' | 'request-secret' | 'poll-secret' | 'fill-secret' | 'browser-status' | 'status' | 'close';
|
|
4
|
+
export type RunRecord = {
|
|
5
|
+
runId: string;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
startedAt: string;
|
|
8
|
+
endedAt?: string;
|
|
9
|
+
status: RunStatus;
|
|
10
|
+
source: 'cli' | 'test' | 'replay';
|
|
11
|
+
entryCommand?: string;
|
|
12
|
+
displayName?: string;
|
|
13
|
+
profile?: string;
|
|
14
|
+
runtimeVersion: string;
|
|
15
|
+
cliVersion: string;
|
|
16
|
+
cwd?: string;
|
|
17
|
+
hostHints?: string[];
|
|
18
|
+
traceContext: {
|
|
19
|
+
traceId: string;
|
|
20
|
+
rootSpanId: string;
|
|
21
|
+
propagationMode: 'single-trace-across-cli-steps';
|
|
22
|
+
};
|
|
23
|
+
resource: {
|
|
24
|
+
serviceName: string;
|
|
25
|
+
serviceVersion: string;
|
|
26
|
+
serviceInstanceId?: string;
|
|
27
|
+
telemetrySdkLanguage?: string;
|
|
28
|
+
};
|
|
29
|
+
stepIds: string[];
|
|
30
|
+
finalOutcome?: {
|
|
31
|
+
success: boolean;
|
|
32
|
+
outcomeType?: string;
|
|
33
|
+
message?: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
};
|
|
36
|
+
protectedRun: boolean;
|
|
37
|
+
ingestState: 'local_only' | 'queued' | 'exported' | 'export_failed';
|
|
38
|
+
};
|
|
39
|
+
export type StepChildSpanRecord = {
|
|
40
|
+
spanId: string;
|
|
41
|
+
parentSpanId: string;
|
|
42
|
+
name: string;
|
|
43
|
+
kind: 'client';
|
|
44
|
+
startedAt: string;
|
|
45
|
+
endedAt: string;
|
|
46
|
+
statusCode: 'unset' | 'ok' | 'error';
|
|
47
|
+
statusMessage?: string;
|
|
48
|
+
attributes: Record<string, unknown>;
|
|
49
|
+
};
|
|
50
|
+
export type StepRecord = {
|
|
51
|
+
stepId: string;
|
|
52
|
+
runId: string;
|
|
53
|
+
ordinal: number;
|
|
54
|
+
command: StepCommand;
|
|
55
|
+
startedAt: string;
|
|
56
|
+
endedAt?: string;
|
|
57
|
+
otel: {
|
|
58
|
+
traceId: string;
|
|
59
|
+
spanId: string;
|
|
60
|
+
parentSpanId?: string;
|
|
61
|
+
spanName: string;
|
|
62
|
+
spanKind: 'internal';
|
|
63
|
+
statusCode: 'unset' | 'ok' | 'error';
|
|
64
|
+
statusMessage?: string;
|
|
65
|
+
instrumentationScope: string;
|
|
66
|
+
};
|
|
67
|
+
input: Record<string, unknown>;
|
|
68
|
+
outputSummary?: {
|
|
69
|
+
success: boolean;
|
|
70
|
+
outcomeType?: string;
|
|
71
|
+
message?: string;
|
|
72
|
+
reason?: string;
|
|
73
|
+
};
|
|
74
|
+
refs?: {
|
|
75
|
+
pageRef?: string;
|
|
76
|
+
targetRef?: string;
|
|
77
|
+
surfaceRef?: string;
|
|
78
|
+
fillRef?: string;
|
|
79
|
+
requestId?: string;
|
|
80
|
+
};
|
|
81
|
+
eventIds: string[];
|
|
82
|
+
childSpanIds: string[];
|
|
83
|
+
childSpans: StepChildSpanRecord[];
|
|
84
|
+
protectedStep: boolean;
|
|
85
|
+
};
|
|
86
|
+
export declare function loadRunRecord(runId: string): RunRecord | null;
|
|
87
|
+
export declare function loadStepRecord(runId: string, stepId: string): StepRecord | null;
|
|
88
|
+
export declare function startCliRun(options: {
|
|
89
|
+
sessionId: string;
|
|
90
|
+
entryCommand: string;
|
|
91
|
+
displayName?: string;
|
|
92
|
+
profile?: string;
|
|
93
|
+
url?: string;
|
|
94
|
+
now?: Date;
|
|
95
|
+
}): RunRecord;
|
|
96
|
+
export declare function startRunStep(options: {
|
|
97
|
+
runId: string;
|
|
98
|
+
command: StepCommand;
|
|
99
|
+
input?: Record<string, unknown>;
|
|
100
|
+
refs?: StepRecord['refs'];
|
|
101
|
+
protectedStep?: boolean;
|
|
102
|
+
now?: Date;
|
|
103
|
+
}): StepRecord | null;
|
|
104
|
+
export declare function finishRunStep(options: {
|
|
105
|
+
runId: string;
|
|
106
|
+
stepId: string;
|
|
107
|
+
success: boolean;
|
|
108
|
+
outcomeType?: string;
|
|
109
|
+
message?: string;
|
|
110
|
+
reason?: string;
|
|
111
|
+
now?: Date;
|
|
112
|
+
}): StepRecord | null;
|
|
113
|
+
export declare function finishRunRecord(runId: string, options: {
|
|
114
|
+
status: RunTerminalStatus;
|
|
115
|
+
now?: Date;
|
|
116
|
+
finalOutcome?: RunRecord['finalOutcome'];
|
|
117
|
+
}): RunRecord | null;
|
|
118
|
+
export declare function appendStepChildSpan(options: {
|
|
119
|
+
runId: string;
|
|
120
|
+
stepId: string;
|
|
121
|
+
name: string;
|
|
122
|
+
kind?: StepChildSpanRecord['kind'];
|
|
123
|
+
startedAt: string;
|
|
124
|
+
endedAt: string;
|
|
125
|
+
statusCode: StepChildSpanRecord['statusCode'];
|
|
126
|
+
statusMessage?: string;
|
|
127
|
+
attributes?: Record<string, unknown>;
|
|
128
|
+
}): StepChildSpanRecord | null;
|
|
129
|
+
export declare function setRunIngestState(runId: string, ingestState: RunRecord['ingestState']): RunRecord | null;
|
|
130
|
+
//# sourceMappingURL=run-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-store.d.ts","sourceRoot":"","sources":["../src/run-store.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AACvE,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,SAAS,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC;AACvF,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,eAAe,GACf,aAAa,GACb,UAAU,GACV,SAAS,GACT,KAAK,GACL,SAAS,GACT,YAAY,GACZ,qBAAqB,GACrB,gBAAgB,GAChB,aAAa,GACb,aAAa,GACb,gBAAgB,GAChB,QAAQ,GACR,OAAO,CAAC;AAEZ,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,Y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K,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,GAAG,mBAAmB,GAAG,IAAI,CAyB7B;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,SAAS,CAAC,aAAa,CAAC,GACpC,SAAS,GAAG,IAAI,CAiBlB"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { getMagicPayRunsDir } from '@mercuryo-ai/magicpay-home';
|
|
5
|
+
import { readCurrentPackageVersion } from './package-version.js';
|
|
6
|
+
const SERVICE_NAME = '@mercuryo-ai/magicpay-cli';
|
|
7
|
+
function getRunsDir() {
|
|
8
|
+
return getMagicPayRunsDir();
|
|
9
|
+
}
|
|
10
|
+
function getRunDir(runId) {
|
|
11
|
+
return join(getRunsDir(), runId);
|
|
12
|
+
}
|
|
13
|
+
function getRunRecordPath(runId) {
|
|
14
|
+
return join(getRunDir(runId), 'run.json');
|
|
15
|
+
}
|
|
16
|
+
function getRunStepsDir(runId) {
|
|
17
|
+
return join(getRunDir(runId), 'steps');
|
|
18
|
+
}
|
|
19
|
+
function getStepRecordPath(runId, stepId) {
|
|
20
|
+
return join(getRunStepsDir(runId), `${stepId}.json`);
|
|
21
|
+
}
|
|
22
|
+
function ensureRunDir(runId) {
|
|
23
|
+
mkdirSync(getRunStepsDir(runId), { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
function randomHex(bytes) {
|
|
26
|
+
return randomBytes(bytes).toString('hex');
|
|
27
|
+
}
|
|
28
|
+
function atomicWriteUtf8(filePath, contents) {
|
|
29
|
+
const tempPath = `${filePath}.${process.pid}.${randomHex(4)}.tmp`;
|
|
30
|
+
try {
|
|
31
|
+
writeFileSync(tempPath, contents, 'utf-8');
|
|
32
|
+
renameSync(tempPath, filePath);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
rmSync(tempPath, { force: true });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function parseHostHints(url) {
|
|
40
|
+
if (!url) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return [new URL(url).host];
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function saveRunRecord(record) {
|
|
51
|
+
ensureRunDir(record.runId);
|
|
52
|
+
atomicWriteUtf8(getRunRecordPath(record.runId), `${JSON.stringify(record, null, 2)}\n`);
|
|
53
|
+
}
|
|
54
|
+
function saveStepRecord(record) {
|
|
55
|
+
ensureRunDir(record.runId);
|
|
56
|
+
atomicWriteUtf8(getStepRecordPath(record.runId, record.stepId), `${JSON.stringify(record, null, 2)}\n`);
|
|
57
|
+
}
|
|
58
|
+
export function loadRunRecord(runId) {
|
|
59
|
+
const recordPath = getRunRecordPath(runId);
|
|
60
|
+
if (!existsSync(recordPath)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(readFileSync(recordPath, 'utf-8'));
|
|
65
|
+
if (!parsed.runId || !parsed.sessionId || !parsed.startedAt || !parsed.status) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...parsed,
|
|
70
|
+
stepIds: Array.isArray(parsed.stepIds) ? parsed.stepIds : [],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function loadStepRecord(runId, stepId) {
|
|
78
|
+
const recordPath = getStepRecordPath(runId, stepId);
|
|
79
|
+
if (!existsSync(recordPath)) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(readFileSync(recordPath, 'utf-8'));
|
|
84
|
+
if (!parsed.stepId || !parsed.runId || !parsed.command || !parsed.startedAt) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
...parsed,
|
|
89
|
+
eventIds: Array.isArray(parsed.eventIds) ? parsed.eventIds : [],
|
|
90
|
+
childSpanIds: Array.isArray(parsed.childSpanIds) ? parsed.childSpanIds : [],
|
|
91
|
+
childSpans: Array.isArray(parsed.childSpans) ? parsed.childSpans : [],
|
|
92
|
+
protectedStep: parsed.protectedStep === true,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function startCliRun(options) {
|
|
100
|
+
const version = readCurrentPackageVersion();
|
|
101
|
+
const startedAt = (options.now ?? new Date()).toISOString();
|
|
102
|
+
const run = {
|
|
103
|
+
runId: randomUUID(),
|
|
104
|
+
sessionId: options.sessionId,
|
|
105
|
+
startedAt,
|
|
106
|
+
status: 'running',
|
|
107
|
+
source: 'cli',
|
|
108
|
+
entryCommand: options.entryCommand,
|
|
109
|
+
...(options.displayName ? { displayName: options.displayName } : {}),
|
|
110
|
+
...(options.profile ? { profile: options.profile } : {}),
|
|
111
|
+
runtimeVersion: process.version,
|
|
112
|
+
cliVersion: version,
|
|
113
|
+
cwd: process.cwd(),
|
|
114
|
+
...(parseHostHints(options.url) ? { hostHints: parseHostHints(options.url) } : {}),
|
|
115
|
+
traceContext: {
|
|
116
|
+
traceId: randomHex(16),
|
|
117
|
+
rootSpanId: randomHex(8),
|
|
118
|
+
propagationMode: 'single-trace-across-cli-steps',
|
|
119
|
+
},
|
|
120
|
+
resource: {
|
|
121
|
+
serviceName: SERVICE_NAME,
|
|
122
|
+
serviceVersion: version,
|
|
123
|
+
serviceInstanceId: randomHex(6),
|
|
124
|
+
telemetrySdkLanguage: 'nodejs',
|
|
125
|
+
},
|
|
126
|
+
stepIds: [],
|
|
127
|
+
protectedRun: false,
|
|
128
|
+
ingestState: 'local_only',
|
|
129
|
+
};
|
|
130
|
+
saveRunRecord(run);
|
|
131
|
+
return run;
|
|
132
|
+
}
|
|
133
|
+
export function startRunStep(options) {
|
|
134
|
+
const run = loadRunRecord(options.runId);
|
|
135
|
+
if (!run) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const step = {
|
|
139
|
+
stepId: randomUUID(),
|
|
140
|
+
runId: run.runId,
|
|
141
|
+
ordinal: run.stepIds.length + 1,
|
|
142
|
+
command: options.command,
|
|
143
|
+
startedAt: (options.now ?? new Date()).toISOString(),
|
|
144
|
+
otel: {
|
|
145
|
+
traceId: run.traceContext.traceId,
|
|
146
|
+
spanId: randomHex(8),
|
|
147
|
+
parentSpanId: run.traceContext.rootSpanId,
|
|
148
|
+
spanName: `magicpay.${options.command}`,
|
|
149
|
+
spanKind: 'internal',
|
|
150
|
+
statusCode: 'unset',
|
|
151
|
+
instrumentationScope: 'magicpay.local-run-store',
|
|
152
|
+
},
|
|
153
|
+
input: { ...(options.input ?? {}) },
|
|
154
|
+
...(options.refs ? { refs: options.refs } : {}),
|
|
155
|
+
eventIds: [],
|
|
156
|
+
childSpanIds: [],
|
|
157
|
+
childSpans: [],
|
|
158
|
+
protectedStep: options.protectedStep === true,
|
|
159
|
+
};
|
|
160
|
+
saveStepRecord(step);
|
|
161
|
+
saveRunRecord({
|
|
162
|
+
...run,
|
|
163
|
+
stepIds: [...run.stepIds, step.stepId],
|
|
164
|
+
});
|
|
165
|
+
return step;
|
|
166
|
+
}
|
|
167
|
+
export function finishRunStep(options) {
|
|
168
|
+
const step = loadStepRecord(options.runId, options.stepId);
|
|
169
|
+
if (!step) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const nextStep = {
|
|
173
|
+
...step,
|
|
174
|
+
endedAt: step.endedAt ?? (options.now ?? new Date()).toISOString(),
|
|
175
|
+
otel: {
|
|
176
|
+
...step.otel,
|
|
177
|
+
statusCode: step.otel.statusCode === 'unset' ? (options.success ? 'ok' : 'error') : step.otel.statusCode,
|
|
178
|
+
...(step.otel.statusMessage
|
|
179
|
+
? { statusMessage: step.otel.statusMessage }
|
|
180
|
+
: options.reason
|
|
181
|
+
? { statusMessage: options.reason }
|
|
182
|
+
: {}),
|
|
183
|
+
},
|
|
184
|
+
outputSummary: step.outputSummary ?? {
|
|
185
|
+
success: options.success,
|
|
186
|
+
...(options.outcomeType ? { outcomeType: options.outcomeType } : {}),
|
|
187
|
+
...(options.message ? { message: options.message } : {}),
|
|
188
|
+
...(options.reason ? { reason: options.reason } : {}),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
saveStepRecord(nextStep);
|
|
192
|
+
return nextStep;
|
|
193
|
+
}
|
|
194
|
+
export function finishRunRecord(runId, options) {
|
|
195
|
+
const run = loadRunRecord(runId);
|
|
196
|
+
if (!run) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
const nextRun = {
|
|
200
|
+
...run,
|
|
201
|
+
status: run.endedAt ? run.status : options.status,
|
|
202
|
+
endedAt: run.endedAt ?? (options.now ?? new Date()).toISOString(),
|
|
203
|
+
finalOutcome: run.finalOutcome ?? options.finalOutcome,
|
|
204
|
+
};
|
|
205
|
+
saveRunRecord(nextRun);
|
|
206
|
+
return nextRun;
|
|
207
|
+
}
|
|
208
|
+
export function appendStepChildSpan(options) {
|
|
209
|
+
const step = loadStepRecord(options.runId, options.stepId);
|
|
210
|
+
if (!step) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const childSpan = {
|
|
214
|
+
spanId: randomHex(8),
|
|
215
|
+
parentSpanId: step.otel.spanId,
|
|
216
|
+
name: options.name,
|
|
217
|
+
kind: options.kind ?? 'client',
|
|
218
|
+
startedAt: options.startedAt,
|
|
219
|
+
endedAt: options.endedAt,
|
|
220
|
+
statusCode: options.statusCode,
|
|
221
|
+
...(options.statusMessage ? { statusMessage: options.statusMessage } : {}),
|
|
222
|
+
attributes: { ...(options.attributes ?? {}) },
|
|
223
|
+
};
|
|
224
|
+
saveStepRecord({
|
|
225
|
+
...step,
|
|
226
|
+
childSpanIds: [...step.childSpanIds, childSpan.spanId],
|
|
227
|
+
childSpans: [...step.childSpans, childSpan],
|
|
228
|
+
});
|
|
229
|
+
return childSpan;
|
|
230
|
+
}
|
|
231
|
+
export function setRunIngestState(runId, ingestState) {
|
|
232
|
+
const run = loadRunRecord(runId);
|
|
233
|
+
if (!run) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
if (run.ingestState === ingestState) {
|
|
237
|
+
return run;
|
|
238
|
+
}
|
|
239
|
+
const nextRun = {
|
|
240
|
+
...run,
|
|
241
|
+
ingestState,
|
|
242
|
+
};
|
|
243
|
+
saveRunRecord(nextRun);
|
|
244
|
+
return nextRun;
|
|
245
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type MagicPayClient, type MagicPayClientRequestOptions, type SecretCatalog } from '@mercuryo-ai/magicpay-sdk';
|
|
2
|
+
export declare class SecretBackendDisabledError extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
export interface SecretBackend {
|
|
6
|
+
kind: 'mock' | 'magicpay_api';
|
|
7
|
+
fetchSecretCatalog(sessionId: string, urlOrHost: string, options?: MagicPayClientRequestOptions): Promise<SecretCatalog>;
|
|
8
|
+
}
|
|
9
|
+
export interface MockSecretDecisionResult {
|
|
10
|
+
requestId: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
status: 'fulfilled' | 'denied';
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
resolvedAt?: string;
|
|
15
|
+
expiresAt?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function isMockSecretBackendEnabled(): boolean;
|
|
18
|
+
export declare function getMagicPayClient(options?: {
|
|
19
|
+
fetchImpl?: typeof fetch;
|
|
20
|
+
}): MagicPayClient;
|
|
21
|
+
export declare function getSecretBackend(): SecretBackend;
|
|
22
|
+
export declare function approveMockSecretRequest(requestId: string): MockSecretDecisionResult;
|
|
23
|
+
export declare function denyMockSecretRequest(requestId: string): MockSecretDecisionResult;
|
|
24
|
+
export declare const __testSecretBackend: {
|
|
25
|
+
approveMockSecretRequest: typeof approveMockSecretRequest;
|
|
26
|
+
denyMockSecretRequest: typeof denyMockSecretRequest;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=secret-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-backend.d.ts","sourceRoot":"","sources":["../src/secret-backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,4BAA4B,EAGjC,KAAK,aAAa,EAMnB,MAAM,2BAA2B,CAAC;AA8UnC,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,SAAsC;CAI1D;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;IAC9B,kBAAkB,CAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,4BAA4B,GACrC,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqCD,wBAAgB,0BAA0B,IAAI,OAAO,CAEpD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GAAG,cAAc,CAM5F;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAchD;AAUD,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,wBAAwB,CAGpF;AAED,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,wBAAwB,CAGjF;AAED,eAAO,MAAM,mBAAmB;;;CAG/B,CAAC"}
|