@axiastudio/aioc 0.1.0-beta.6 → 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 +48 -12
- package/dist/agent.d.ts +0 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +0 -3
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +17 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/logger.d.ts +8 -2
- package/dist/logger.d.ts.map +1 -1
- package/dist/policy-outcomes.d.ts +26 -0
- package/dist/policy-outcomes.d.ts.map +1 -0
- package/dist/policy-outcomes.js +88 -0
- package/dist/policy.d.ts +11 -4
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +6 -1
- package/dist/proposal-hashing.d.ts +21 -0
- package/dist/proposal-hashing.d.ts.map +1 -0
- package/dist/proposal-hashing.js +31 -0
- package/dist/run-log-emitter.d.ts +2 -2
- package/dist/run-log-emitter.d.ts.map +1 -1
- package/dist/run-log-emitter.js +10 -4
- package/dist/run-record.d.ts +33 -1
- package/dist/run-record.d.ts.map +1 -1
- package/dist/run-recorder-runtime.d.ts +4 -1
- package/dist/run-recorder-runtime.d.ts.map +1 -1
- package/dist/run-recorder-runtime.js +10 -0
- package/dist/run.d.ts +1 -8
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +152 -79
- package/dist/suspended-proposals.d.ts +22 -0
- package/dist/suspended-proposals.d.ts.map +1 -0
- package/dist/suspended-proposals.js +55 -0
- package/dist/tool.d.ts +11 -2
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js +5 -1
- package/package.json +4 -1
package/dist/run-record.d.ts
CHANGED
|
@@ -10,10 +10,13 @@ export interface PolicyDecisionRecord {
|
|
|
10
10
|
timestamp: string;
|
|
11
11
|
turn: number;
|
|
12
12
|
callId: string;
|
|
13
|
-
decision: "allow" | "deny";
|
|
13
|
+
decision: "allow" | "deny" | "require_approval";
|
|
14
14
|
reason: string;
|
|
15
|
+
publicReason?: string;
|
|
16
|
+
resultMode?: "throw" | "tool_result";
|
|
15
17
|
policyVersion?: string;
|
|
16
18
|
resource: PolicyResourceSnapshot;
|
|
19
|
+
expiresAt?: string;
|
|
17
20
|
metadata?: Record<string, unknown>;
|
|
18
21
|
}
|
|
19
22
|
export interface GuardrailDecisionRecord {
|
|
@@ -49,6 +52,34 @@ export interface RequestFingerprintRecord {
|
|
|
49
52
|
messageCount: number;
|
|
50
53
|
toolCount: number;
|
|
51
54
|
}
|
|
55
|
+
export interface SuspendedProposalBase {
|
|
56
|
+
timestamp: string;
|
|
57
|
+
runId: string;
|
|
58
|
+
turn: number;
|
|
59
|
+
callId: string;
|
|
60
|
+
agentName: string;
|
|
61
|
+
proposalHash: string;
|
|
62
|
+
reason: string;
|
|
63
|
+
publicReason?: string;
|
|
64
|
+
policyVersion?: string;
|
|
65
|
+
expiresAt?: string;
|
|
66
|
+
metadata?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
export interface SuspendedToolProposal extends SuspendedProposalBase {
|
|
69
|
+
kind: "tool";
|
|
70
|
+
toolName: string;
|
|
71
|
+
rawArguments: string;
|
|
72
|
+
parsedArguments: unknown;
|
|
73
|
+
argsCanonicalJson: string;
|
|
74
|
+
}
|
|
75
|
+
export interface SuspendedHandoffProposal extends SuspendedProposalBase {
|
|
76
|
+
kind: "handoff";
|
|
77
|
+
fromAgentName: string;
|
|
78
|
+
toAgentName: string;
|
|
79
|
+
handoffPayload: unknown;
|
|
80
|
+
payloadCanonicalJson: string;
|
|
81
|
+
}
|
|
82
|
+
export type SuspendedProposal = SuspendedToolProposal | SuspendedHandoffProposal;
|
|
52
83
|
export interface RunRecord<TContext = unknown> {
|
|
53
84
|
runId: string;
|
|
54
85
|
startedAt: string;
|
|
@@ -65,6 +96,7 @@ export interface RunRecord<TContext = unknown> {
|
|
|
65
96
|
promptSnapshots: PromptSnapshotRecord[];
|
|
66
97
|
requestFingerprints: RequestFingerprintRecord[];
|
|
67
98
|
policyDecisions: PolicyDecisionRecord[];
|
|
99
|
+
suspendedProposals?: SuspendedProposal[];
|
|
68
100
|
guardrailDecisions?: GuardrailDecisionRecord[];
|
|
69
101
|
errorName?: string;
|
|
70
102
|
errorMessage?: string;
|
package/dist/run-record.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-record.d.ts","sourceRoot":"","sources":["../src/run-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"run-record.d.ts","sourceRoot":"","sources":["../src/run-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC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MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;CAC5D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GuardrailDecisionRecord, PolicyDecisionRecord, PromptSnapshotRecord, RequestFingerprintRecord, RunRecordOptions } from "./run-record";
|
|
1
|
+
import type { GuardrailDecisionRecord, PolicyDecisionRecord, PromptSnapshotRecord, RequestFingerprintRecord, RunRecordOptions, SuspendedProposal } from "./run-record";
|
|
2
2
|
import type { AgentInputItem } from "./types";
|
|
3
3
|
export type PendingPolicyDecisionRecord = Omit<PolicyDecisionRecord, "timestamp">;
|
|
4
4
|
export type PendingGuardrailDecisionRecord = Omit<GuardrailDecisionRecord, "timestamp">;
|
|
@@ -36,6 +36,7 @@ export declare class RunRecorder<TContext = unknown> {
|
|
|
36
36
|
private readonly contextSnapshot;
|
|
37
37
|
private readonly includePromptText;
|
|
38
38
|
private readonly policyDecisions;
|
|
39
|
+
private readonly suspendedProposals;
|
|
39
40
|
private readonly guardrailDecisions;
|
|
40
41
|
private readonly promptSnapshots;
|
|
41
42
|
private readonly requestFingerprints;
|
|
@@ -43,7 +44,9 @@ export declare class RunRecorder<TContext = unknown> {
|
|
|
43
44
|
private runRecordWritten;
|
|
44
45
|
private constructor();
|
|
45
46
|
static create<TContext = unknown>(options: RunRecorderCreateOptions<TContext>): Promise<RunRecorder<TContext>>;
|
|
47
|
+
get runId(): string;
|
|
46
48
|
onPolicyDecision: (decision: PendingPolicyDecisionRecord) => void;
|
|
49
|
+
onSuspendedProposal: (proposal: SuspendedProposal) => void;
|
|
47
50
|
onGuardrailDecision: (decision: PendingGuardrailDecisionRecord) => void;
|
|
48
51
|
onPromptSnapshot: (snapshot: PendingPromptSnapshotRecord) => void;
|
|
49
52
|
onRequestFingerprint: (fingerprint: PendingRequestFingerprintRecord) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-recorder-runtime.d.ts","sourceRoot":"","sources":["../src/run-recorder-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAGxB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"run-recorder-runtime.d.ts","sourceRoot":"","sources":["../src/run-recorder-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAGxB,gBAAgB,EAEhB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,oBAAoB,EACpB,WAAW,CACZ,CAAC;AACF,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAC/C,uBAAuB,EACvB,WAAW,CACZ,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,oBAAoB,EACpB,WAAW,GAAG,YAAY,GAAG,YAAY,CAC1C,GAAG;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAChD,wBAAwB,EACtB,WAAW,GACX,gBAAgB,GAChB,0BAA0B,GAC1B,aAAa,GACb,kBAAkB,GAClB,cAAc,GACd,WAAW,GACX,mBAAmB,GACnB,cAAc,GACd,WAAW,CACd,GAAG;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,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C,QAAQ,CAAC,GAC1C,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAsBjC,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,gBAAgB,GAAI,UAAU,2BAA2B,KAAG,IAAI,CAK9D;IAEF,mBAAmB,GAAI,UAAU,iBAAiB,KAAG,IAAI,CAEvD;IAEF,mBAAmB,GAAI,UAAU,8BAA8B,KAAG,IAAI,CAKpE;IAEF,gBAAgB,GAAI,UAAU,2BAA2B,KAAG,IAAI,CAW9D;IAEF,oBAAoB,GAClB,aAAa,+BAA+B,KAC3C,IAAI,CAgCL;IAEF,eAAe,GAAI,SAAS,MAAM,KAAG,IAAI,CAEvC;IAEI,aAAa,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CACd,OAAO,EAAE,0BAA0B,EACnC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC;YAIF,IAAI;CA8CnB"}
|
|
@@ -99,6 +99,7 @@ class RunRecorder {
|
|
|
99
99
|
contextSnapshot;
|
|
100
100
|
includePromptText;
|
|
101
101
|
policyDecisions = [];
|
|
102
|
+
suspendedProposals = [];
|
|
102
103
|
guardrailDecisions = [];
|
|
103
104
|
promptSnapshots = [];
|
|
104
105
|
requestFingerprints = [];
|
|
@@ -122,12 +123,18 @@ class RunRecorder {
|
|
|
122
123
|
const contextSnapshot = await resolveContextSnapshot(options.context, options.recordOptions);
|
|
123
124
|
return new RunRecorder(runRecordWriter, runRecordId, startedAt, question, options.providerName, options.recordOptions?.metadata, contextSnapshot, options.recordOptions?.includePromptText ?? false);
|
|
124
125
|
}
|
|
126
|
+
get runId() {
|
|
127
|
+
return this.runRecordId;
|
|
128
|
+
}
|
|
125
129
|
onPolicyDecision = (decision) => {
|
|
126
130
|
this.policyDecisions.push({
|
|
127
131
|
timestamp: new Date().toISOString(),
|
|
128
132
|
...decision,
|
|
129
133
|
});
|
|
130
134
|
};
|
|
135
|
+
onSuspendedProposal = (proposal) => {
|
|
136
|
+
this.suspendedProposals.push(proposal);
|
|
137
|
+
};
|
|
131
138
|
onGuardrailDecision = (decision) => {
|
|
132
139
|
this.guardrailDecisions.push({
|
|
133
140
|
timestamp: new Date().toISOString(),
|
|
@@ -209,6 +216,9 @@ class RunRecorder {
|
|
|
209
216
|
promptSnapshots: [...this.promptSnapshots],
|
|
210
217
|
requestFingerprints: [...this.requestFingerprints],
|
|
211
218
|
policyDecisions: [...this.policyDecisions],
|
|
219
|
+
suspendedProposals: this.suspendedProposals.length > 0
|
|
220
|
+
? [...this.suspendedProposals]
|
|
221
|
+
: undefined,
|
|
212
222
|
guardrailDecisions: this.guardrailDecisions.length > 0
|
|
213
223
|
? [...this.guardrailDecisions]
|
|
214
224
|
: undefined,
|
package/dist/run.d.ts
CHANGED
|
@@ -4,13 +4,7 @@ type MutableRunState<TContext> = {
|
|
|
4
4
|
history: AgentInputItem[];
|
|
5
5
|
lastAgent: Agent<TContext>;
|
|
6
6
|
};
|
|
7
|
-
export type ToolResultEnvelopeStatus
|
|
8
|
-
export interface ToolResultEnvelope {
|
|
9
|
-
status: ToolResultEnvelopeStatus;
|
|
10
|
-
code: string | null;
|
|
11
|
-
publicReason: string | null;
|
|
12
|
-
data: unknown | null;
|
|
13
|
-
}
|
|
7
|
+
export type { ToolResultEnvelope, ToolResultEnvelopeStatus, } from "./policy-outcomes";
|
|
14
8
|
export declare class StreamedRunResult<TContext = unknown> {
|
|
15
9
|
private consumed;
|
|
16
10
|
private stream;
|
|
@@ -22,5 +16,4 @@ export declare class StreamedRunResult<TContext = unknown> {
|
|
|
22
16
|
}
|
|
23
17
|
export declare function run<TContext = unknown>(startingAgent: Agent<TContext>, input: string | AgentInputItem[], options: StreamRunOptions<TContext>): Promise<StreamedRunResult<TContext>>;
|
|
24
18
|
export declare function run<TContext = unknown>(startingAgent: Agent<TContext>, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext>): Promise<RunResult<TContext>>;
|
|
25
|
-
export {};
|
|
26
19
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAsChC,OAAO,EACL,cAAc,EAEd,mBAAmB,EAGnB,SAAS,EACT,cAAc,EACd,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,KAAK,eAAe,CAAC,QAAQ,IAAI;IAC/B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC5B,CAAC;AAGF,YAAY,EACV,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAuwB3B,qBAAa,iBAAiB,CAAC,QAAQ,GAAG,OAAO;IAC/C,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,KAAK,CAA4B;gBAGvC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAC/C,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC;IAMlC,QAAQ,IAAI,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAQnD,IAAI,OAAO,IAAI,cAAc,EAAE,CAE9B;IAED,IAAI,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,CAE/B;CACF;AAED,wBAAsB,GAAG,CAAC,QAAQ,GAAG,OAAO,EAC1C,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,EAC9B,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,EAChC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAClC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAExC,wBAAsB,GAAG,CAAC,QAAQ,GAAG,OAAO,EAC1C,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,EAC9B,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,EAChC,OAAO,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,GACtC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
package/dist/run.js
CHANGED
|
@@ -5,9 +5,12 @@ exports.run = run;
|
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
const messages_1 = require("./messages");
|
|
8
|
+
const policy_outcomes_1 = require("./policy-outcomes");
|
|
9
|
+
const proposal_hashing_1 = require("./proposal-hashing");
|
|
8
10
|
const run_log_emitter_1 = require("./run-log-emitter");
|
|
9
11
|
const run_recorder_runtime_1 = require("./run-recorder-runtime");
|
|
10
12
|
const run_context_1 = require("./run-context");
|
|
13
|
+
const suspended_proposals_1 = require("./suspended-proposals");
|
|
11
14
|
const zod_1 = require("zod");
|
|
12
15
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
13
16
|
function toToolParameterSchema(schema) {
|
|
@@ -99,54 +102,89 @@ function toErrorMetadata(error) {
|
|
|
99
102
|
errorMessage: String(error),
|
|
100
103
|
};
|
|
101
104
|
}
|
|
102
|
-
function
|
|
103
|
-
return {
|
|
104
|
-
decision: "deny",
|
|
105
|
-
reason,
|
|
106
|
-
metadata,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
function shouldReturnDeniedAsToolResult(policyResult) {
|
|
110
|
-
return (policyResult.decision === "deny" && policyResult.denyMode === "tool_result");
|
|
111
|
-
}
|
|
112
|
-
function toAllowedToolResultEnvelope(data) {
|
|
113
|
-
return {
|
|
114
|
-
status: "ok",
|
|
115
|
-
code: null,
|
|
116
|
-
publicReason: null,
|
|
117
|
-
data,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function toDeniedToolResultEnvelope(policyResult) {
|
|
121
|
-
return {
|
|
122
|
-
status: "denied",
|
|
123
|
-
code: policyResult.reason,
|
|
124
|
-
publicReason: policyResult.publicReason?.trim() || "Action not allowed.",
|
|
125
|
-
data: null,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function isPolicyResult(value) {
|
|
105
|
+
function isPolicyResultShape(value) {
|
|
129
106
|
if (typeof value !== "object" || value === null) {
|
|
130
107
|
return false;
|
|
131
108
|
}
|
|
132
109
|
const candidate = value;
|
|
133
|
-
const validDecision = candidate.decision === "allow" ||
|
|
110
|
+
const validDecision = candidate.decision === "allow" ||
|
|
111
|
+
candidate.decision === "deny" ||
|
|
112
|
+
candidate.decision === "require_approval";
|
|
134
113
|
const validPublicReason = typeof candidate.publicReason === "undefined" ||
|
|
135
114
|
typeof candidate.publicReason === "string";
|
|
136
|
-
const
|
|
137
|
-
candidate.
|
|
138
|
-
candidate.
|
|
115
|
+
const validResultMode = typeof candidate.resultMode === "undefined" ||
|
|
116
|
+
candidate.resultMode === "throw" ||
|
|
117
|
+
candidate.resultMode === "tool_result";
|
|
118
|
+
const validExpiresAt = typeof candidate.expiresAt === "undefined" ||
|
|
119
|
+
typeof candidate.expiresAt === "string";
|
|
139
120
|
return (validDecision &&
|
|
140
121
|
typeof candidate.reason === "string" &&
|
|
141
122
|
candidate.reason.trim().length > 0 &&
|
|
142
123
|
validPublicReason &&
|
|
143
|
-
|
|
124
|
+
validResultMode &&
|
|
125
|
+
validExpiresAt);
|
|
126
|
+
}
|
|
127
|
+
function hasDeprecatedDenyMode(value) {
|
|
128
|
+
return typeof value === "object" && value !== null && "denyMode" in value;
|
|
129
|
+
}
|
|
130
|
+
function createDeprecatedDenyModeResult(receivedValue) {
|
|
131
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("deprecated_policy_field_denyMode", {
|
|
132
|
+
deprecatedField: "denyMode",
|
|
133
|
+
replacementField: "resultMode",
|
|
134
|
+
receivedValue,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async function emitPolicyDecision(params) {
|
|
138
|
+
const { agentName, turn, callId, policyResult, logEmitter, onPolicyDecision, } = params;
|
|
139
|
+
const resultMode = policyResult.decision === "allow"
|
|
140
|
+
? undefined
|
|
141
|
+
: (0, policy_outcomes_1.resolveResultMode)(policyResult);
|
|
142
|
+
if (params.kind === "tool") {
|
|
143
|
+
await logEmitter.toolPolicyEvaluated(agentName, turn, params.toolName, callId, policyResult.decision, policyResult.reason, policyResult.publicReason, resultMode, policyResult.policyVersion, policyResult.expiresAt, policyResult.metadata);
|
|
144
|
+
onPolicyDecision?.({
|
|
145
|
+
turn,
|
|
146
|
+
callId,
|
|
147
|
+
decision: policyResult.decision,
|
|
148
|
+
reason: policyResult.reason,
|
|
149
|
+
publicReason: policyResult.publicReason,
|
|
150
|
+
resultMode,
|
|
151
|
+
policyVersion: policyResult.policyVersion,
|
|
152
|
+
resource: {
|
|
153
|
+
kind: "tool",
|
|
154
|
+
name: params.toolName,
|
|
155
|
+
},
|
|
156
|
+
expiresAt: policyResult.expiresAt,
|
|
157
|
+
metadata: policyResult.metadata,
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
await logEmitter.handoffPolicyEvaluated(agentName, turn, params.handoffName, callId, params.toAgentName, policyResult.decision, policyResult.reason, policyResult.publicReason, resultMode, policyResult.policyVersion, policyResult.expiresAt, policyResult.metadata);
|
|
162
|
+
onPolicyDecision?.({
|
|
163
|
+
turn,
|
|
164
|
+
callId,
|
|
165
|
+
decision: policyResult.decision,
|
|
166
|
+
reason: policyResult.reason,
|
|
167
|
+
publicReason: policyResult.publicReason,
|
|
168
|
+
resultMode,
|
|
169
|
+
policyVersion: policyResult.policyVersion,
|
|
170
|
+
resource: {
|
|
171
|
+
kind: "handoff",
|
|
172
|
+
name: params.toAgentName,
|
|
173
|
+
},
|
|
174
|
+
expiresAt: policyResult.expiresAt,
|
|
175
|
+
metadata: policyResult.metadata,
|
|
176
|
+
});
|
|
144
177
|
}
|
|
145
178
|
async function evaluateToolPolicy(agent, call, parsedArguments, runContext, turn, policies) {
|
|
146
179
|
const policy = policies?.toolPolicy;
|
|
147
180
|
if (!policy) {
|
|
148
|
-
return createDeniedPolicyResult("policy_not_configured");
|
|
181
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("policy_not_configured");
|
|
149
182
|
}
|
|
183
|
+
const { proposalHash, argsCanonicalJson } = (0, proposal_hashing_1.createToolProposalFingerprint)({
|
|
184
|
+
agentName: agent.name,
|
|
185
|
+
toolName: call.name,
|
|
186
|
+
parsedArguments,
|
|
187
|
+
});
|
|
150
188
|
let rawResult;
|
|
151
189
|
try {
|
|
152
190
|
rawResult = await policy({
|
|
@@ -154,72 +192,98 @@ async function evaluateToolPolicy(agent, call, parsedArguments, runContext, turn
|
|
|
154
192
|
toolName: call.name,
|
|
155
193
|
rawArguments: call.arguments,
|
|
156
194
|
parsedArguments,
|
|
195
|
+
proposalHash,
|
|
196
|
+
argsCanonicalJson,
|
|
157
197
|
runContext,
|
|
158
198
|
turn,
|
|
159
199
|
});
|
|
160
200
|
}
|
|
161
201
|
catch (error) {
|
|
162
|
-
return createDeniedPolicyResult("policy_error", toErrorMetadata(error));
|
|
202
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("policy_error", toErrorMetadata(error));
|
|
203
|
+
}
|
|
204
|
+
if (hasDeprecatedDenyMode(rawResult)) {
|
|
205
|
+
return createDeprecatedDenyModeResult(rawResult.denyMode);
|
|
163
206
|
}
|
|
164
|
-
if (!
|
|
165
|
-
return createDeniedPolicyResult("invalid_policy_result");
|
|
207
|
+
if (!isPolicyResultShape(rawResult)) {
|
|
208
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("invalid_policy_result");
|
|
166
209
|
}
|
|
167
|
-
return rawResult;
|
|
210
|
+
return (0, policy_outcomes_1.materializePolicyResult)(rawResult);
|
|
168
211
|
}
|
|
169
212
|
async function evaluateHandoffPolicy(fromAgent, toAgent, call, handoffPayload, runContext, turn, policies) {
|
|
170
213
|
const policy = policies?.handoffPolicy;
|
|
171
214
|
if (!policy) {
|
|
172
|
-
return createDeniedPolicyResult("policy_not_configured");
|
|
215
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("policy_not_configured");
|
|
173
216
|
}
|
|
217
|
+
const { proposalHash, payloadCanonicalJson } = (0, proposal_hashing_1.createHandoffProposalFingerprint)({
|
|
218
|
+
fromAgentName: fromAgent.name,
|
|
219
|
+
toAgentName: toAgent.name,
|
|
220
|
+
handoffPayload,
|
|
221
|
+
});
|
|
174
222
|
let rawResult;
|
|
175
223
|
try {
|
|
176
224
|
rawResult = await policy({
|
|
177
225
|
fromAgentName: fromAgent.name,
|
|
178
226
|
toAgentName: toAgent.name,
|
|
179
227
|
handoffPayload,
|
|
228
|
+
proposalHash,
|
|
229
|
+
payloadCanonicalJson,
|
|
180
230
|
runContext,
|
|
181
231
|
turn,
|
|
182
232
|
});
|
|
183
233
|
}
|
|
184
234
|
catch (error) {
|
|
185
|
-
return createDeniedPolicyResult("policy_error", toErrorMetadata(error));
|
|
235
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("policy_error", toErrorMetadata(error));
|
|
236
|
+
}
|
|
237
|
+
if (hasDeprecatedDenyMode(rawResult)) {
|
|
238
|
+
return createDeprecatedDenyModeResult(rawResult.denyMode);
|
|
186
239
|
}
|
|
187
|
-
if (!
|
|
188
|
-
return createDeniedPolicyResult("invalid_policy_result");
|
|
240
|
+
if (!isPolicyResultShape(rawResult)) {
|
|
241
|
+
return (0, policy_outcomes_1.createDeniedPolicyResult)("invalid_policy_result");
|
|
189
242
|
}
|
|
190
|
-
return rawResult;
|
|
243
|
+
return (0, policy_outcomes_1.materializePolicyResult)(rawResult);
|
|
191
244
|
}
|
|
192
|
-
async function executeToolCall(agent, call, parsedArguments, runContext, turn, logEmitter, policies, onPolicyDecision) {
|
|
245
|
+
async function executeToolCall(agent, runId, call, parsedArguments, runContext, turn, logEmitter, policies, onPolicyDecision, onSuspendedProposal) {
|
|
193
246
|
const definition = agent.tools.find((tool) => tool.name === call.name);
|
|
194
247
|
if (!definition) {
|
|
195
248
|
throw new errors_1.ToolCallError(`Tool "${call.name}" is not registered.`);
|
|
196
249
|
}
|
|
197
250
|
const policyResult = await evaluateToolPolicy(agent, call, parsedArguments, runContext, turn, policies);
|
|
198
|
-
await
|
|
199
|
-
|
|
251
|
+
await emitPolicyDecision({
|
|
252
|
+
kind: "tool",
|
|
253
|
+
agentName: agent.name,
|
|
200
254
|
turn,
|
|
201
255
|
callId: call.callId,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
kind: "tool",
|
|
207
|
-
name: call.name,
|
|
208
|
-
},
|
|
209
|
-
metadata: policyResult.metadata,
|
|
256
|
+
toolName: call.name,
|
|
257
|
+
policyResult,
|
|
258
|
+
logEmitter,
|
|
259
|
+
onPolicyDecision,
|
|
210
260
|
});
|
|
211
261
|
if (policyResult.decision !== "allow") {
|
|
212
|
-
|
|
213
|
-
|
|
262
|
+
const suspendedProposal = policyResult.decision === "require_approval"
|
|
263
|
+
? (0, suspended_proposals_1.buildSuspendedToolProposal)({
|
|
264
|
+
runId,
|
|
265
|
+
agentName: agent.name,
|
|
266
|
+
turn,
|
|
267
|
+
callId: call.callId,
|
|
268
|
+
toolName: call.name,
|
|
269
|
+
rawArguments: call.arguments,
|
|
270
|
+
parsedArguments,
|
|
271
|
+
policyResult,
|
|
272
|
+
})
|
|
273
|
+
: undefined;
|
|
274
|
+
if (suspendedProposal) {
|
|
275
|
+
onSuspendedProposal?.(suspendedProposal);
|
|
214
276
|
}
|
|
215
|
-
|
|
277
|
+
return (0, policy_outcomes_1.handleBlockedPolicyResult)({
|
|
278
|
+
kind: "tool",
|
|
216
279
|
toolName: call.name,
|
|
217
280
|
policyResult,
|
|
281
|
+
suspendedProposal,
|
|
218
282
|
});
|
|
219
283
|
}
|
|
220
284
|
const validated = definition.parameters.parse(parsedArguments);
|
|
221
285
|
const toolOutput = await definition.execute(validated, runContext);
|
|
222
|
-
return toAllowedToolResultEnvelope(toolOutput);
|
|
286
|
+
return (0, policy_outcomes_1.toAllowedToolResultEnvelope)(toolOutput);
|
|
223
287
|
}
|
|
224
288
|
async function evaluateOutputGuardrails(agent, runContext, history, outputText, logEmitter, turn, onGuardrailDecision) {
|
|
225
289
|
for (const guardrail of agent.outputGuardrails) {
|
|
@@ -253,7 +317,7 @@ async function evaluateOutputGuardrails(agent, runContext, history, outputText,
|
|
|
253
317
|
await logEmitter.outputGuardrailPassed(agent.name, turn, guardrail.name);
|
|
254
318
|
}
|
|
255
319
|
}
|
|
256
|
-
async function* runLoop(state, provider, runContext, maxTurns, logger, policies, onPolicyDecision, onGuardrailDecision, onPromptSnapshot, onRequestFingerprint) {
|
|
320
|
+
async function* runLoop(state, runId, provider, runContext, maxTurns, logger, policies, onPolicyDecision, onSuspendedProposal, onGuardrailDecision, onPromptSnapshot, onRequestFingerprint) {
|
|
257
321
|
const logEmitter = new run_log_emitter_1.RunLogEmitter(logger);
|
|
258
322
|
await logEmitter.runStarted(state.lastAgent.name, maxTurns, state.history.length);
|
|
259
323
|
yield {
|
|
@@ -366,33 +430,42 @@ async function* runLoop(state, provider, runContext, maxTurns, logger, policies,
|
|
|
366
430
|
try {
|
|
367
431
|
if (handoffTarget) {
|
|
368
432
|
const handoffPolicyResult = await evaluateHandoffPolicy(currentAgent, handoffTarget, call, callItemArguments, runContext, activeTurn, policies);
|
|
369
|
-
await
|
|
370
|
-
|
|
433
|
+
await emitPolicyDecision({
|
|
434
|
+
kind: "handoff",
|
|
435
|
+
agentName: currentAgent.name,
|
|
371
436
|
turn: activeTurn,
|
|
372
437
|
callId: call.callId,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
name: handoffTarget.name,
|
|
379
|
-
},
|
|
380
|
-
metadata: handoffPolicyResult.metadata,
|
|
438
|
+
handoffName: call.name,
|
|
439
|
+
toAgentName: handoffTarget.name,
|
|
440
|
+
policyResult: handoffPolicyResult,
|
|
441
|
+
logEmitter,
|
|
442
|
+
onPolicyDecision,
|
|
381
443
|
});
|
|
382
444
|
if (handoffPolicyResult.decision !== "allow") {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
445
|
+
const suspendedProposal = handoffPolicyResult.decision === "require_approval"
|
|
446
|
+
? (0, suspended_proposals_1.buildSuspendedHandoffProposal)({
|
|
447
|
+
runId,
|
|
448
|
+
fromAgentName: currentAgent.name,
|
|
449
|
+
toAgentName: handoffTarget.name,
|
|
450
|
+
turn: activeTurn,
|
|
451
|
+
callId: call.callId,
|
|
452
|
+
handoffPayload: callItemArguments,
|
|
390
453
|
policyResult: handoffPolicyResult,
|
|
391
|
-
})
|
|
454
|
+
})
|
|
455
|
+
: undefined;
|
|
456
|
+
if (suspendedProposal) {
|
|
457
|
+
onSuspendedProposal?.(suspendedProposal);
|
|
392
458
|
}
|
|
459
|
+
toolOutput = (0, policy_outcomes_1.handleBlockedPolicyResult)({
|
|
460
|
+
kind: "handoff",
|
|
461
|
+
fromAgent: currentAgent.name,
|
|
462
|
+
toAgent: handoffTarget.name,
|
|
463
|
+
policyResult: handoffPolicyResult,
|
|
464
|
+
suspendedProposal,
|
|
465
|
+
});
|
|
393
466
|
}
|
|
394
467
|
else {
|
|
395
|
-
toolOutput = toAllowedToolResultEnvelope({
|
|
468
|
+
toolOutput = (0, policy_outcomes_1.toAllowedToolResultEnvelope)({
|
|
396
469
|
handoffTo: handoffTarget.name,
|
|
397
470
|
accepted: true,
|
|
398
471
|
payload: callItemArguments,
|
|
@@ -402,7 +475,7 @@ async function* runLoop(state, provider, runContext, maxTurns, logger, policies,
|
|
|
402
475
|
}
|
|
403
476
|
}
|
|
404
477
|
else {
|
|
405
|
-
toolOutput = await executeToolCall(currentAgent, call, callItemArguments, runContext, activeTurn, logEmitter, policies, onPolicyDecision);
|
|
478
|
+
toolOutput = await executeToolCall(currentAgent, runId, call, callItemArguments, runContext, activeTurn, logEmitter, policies, onPolicyDecision, onSuspendedProposal);
|
|
406
479
|
}
|
|
407
480
|
}
|
|
408
481
|
catch (error) {
|
|
@@ -495,7 +568,7 @@ async function run(startingAgent, input, options = {}) {
|
|
|
495
568
|
providerName: provider.constructor.name,
|
|
496
569
|
recordOptions: options.record,
|
|
497
570
|
});
|
|
498
|
-
const rawStream = runLoop(state, provider, runContext, maxTurns, options.logger, options.policies, runRecorder.onPolicyDecision, runRecorder.onGuardrailDecision, runRecorder.onPromptSnapshot, runRecorder.onRequestFingerprint);
|
|
571
|
+
const rawStream = runLoop(state, runRecorder.runId, provider, runContext, maxTurns, options.logger, options.policies, runRecorder.onPolicyDecision, runRecorder.onSuspendedProposal, runRecorder.onGuardrailDecision, runRecorder.onPromptSnapshot, runRecorder.onRequestFingerprint);
|
|
499
572
|
const runRecordSnapshot = () => ({
|
|
500
573
|
agentName: state.lastAgent.name,
|
|
501
574
|
model: state.lastAgent.model,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PolicyResult } from "./policy";
|
|
2
|
+
import type { SuspendedProposal } from "./run-record";
|
|
3
|
+
export declare function buildSuspendedToolProposal(params: {
|
|
4
|
+
runId: string;
|
|
5
|
+
agentName: string;
|
|
6
|
+
turn: number;
|
|
7
|
+
callId: string;
|
|
8
|
+
toolName: string;
|
|
9
|
+
rawArguments: string;
|
|
10
|
+
parsedArguments: unknown;
|
|
11
|
+
policyResult: PolicyResult;
|
|
12
|
+
}): SuspendedProposal;
|
|
13
|
+
export declare function buildSuspendedHandoffProposal(params: {
|
|
14
|
+
runId: string;
|
|
15
|
+
fromAgentName: string;
|
|
16
|
+
toAgentName: string;
|
|
17
|
+
turn: number;
|
|
18
|
+
callId: string;
|
|
19
|
+
handoffPayload: unknown;
|
|
20
|
+
policyResult: PolicyResult;
|
|
21
|
+
}): SuspendedProposal;
|
|
22
|
+
//# sourceMappingURL=suspended-proposals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspended-proposals.d.ts","sourceRoot":"","sources":["../src/suspended-proposals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAK7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,iBAAiB,CAyBpB;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,iBAAiB,CA0BpB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSuspendedToolProposal = buildSuspendedToolProposal;
|
|
4
|
+
exports.buildSuspendedHandoffProposal = buildSuspendedHandoffProposal;
|
|
5
|
+
const proposal_hashing_1 = require("./proposal-hashing");
|
|
6
|
+
function buildSuspendedToolProposal(params) {
|
|
7
|
+
const { argsCanonicalJson, proposalHash } = (0, proposal_hashing_1.createToolProposalFingerprint)({
|
|
8
|
+
agentName: params.agentName,
|
|
9
|
+
toolName: params.toolName,
|
|
10
|
+
parsedArguments: params.parsedArguments,
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
timestamp: new Date().toISOString(),
|
|
14
|
+
kind: "tool",
|
|
15
|
+
runId: params.runId,
|
|
16
|
+
turn: params.turn,
|
|
17
|
+
callId: params.callId,
|
|
18
|
+
agentName: params.agentName,
|
|
19
|
+
proposalHash,
|
|
20
|
+
reason: params.policyResult.reason,
|
|
21
|
+
publicReason: params.policyResult.publicReason,
|
|
22
|
+
policyVersion: params.policyResult.policyVersion,
|
|
23
|
+
expiresAt: params.policyResult.expiresAt,
|
|
24
|
+
metadata: params.policyResult.metadata,
|
|
25
|
+
toolName: params.toolName,
|
|
26
|
+
rawArguments: params.rawArguments,
|
|
27
|
+
parsedArguments: params.parsedArguments,
|
|
28
|
+
argsCanonicalJson,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function buildSuspendedHandoffProposal(params) {
|
|
32
|
+
const { payloadCanonicalJson, proposalHash } = (0, proposal_hashing_1.createHandoffProposalFingerprint)({
|
|
33
|
+
fromAgentName: params.fromAgentName,
|
|
34
|
+
toAgentName: params.toAgentName,
|
|
35
|
+
handoffPayload: params.handoffPayload,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
timestamp: new Date().toISOString(),
|
|
39
|
+
kind: "handoff",
|
|
40
|
+
runId: params.runId,
|
|
41
|
+
turn: params.turn,
|
|
42
|
+
callId: params.callId,
|
|
43
|
+
agentName: params.fromAgentName,
|
|
44
|
+
proposalHash,
|
|
45
|
+
reason: params.policyResult.reason,
|
|
46
|
+
publicReason: params.policyResult.publicReason,
|
|
47
|
+
policyVersion: params.policyResult.policyVersion,
|
|
48
|
+
expiresAt: params.policyResult.expiresAt,
|
|
49
|
+
metadata: params.policyResult.metadata,
|
|
50
|
+
fromAgentName: params.fromAgentName,
|
|
51
|
+
toAgentName: params.toAgentName,
|
|
52
|
+
handoffPayload: params.handoffPayload,
|
|
53
|
+
payloadCanonicalJson,
|
|
54
|
+
};
|
|
55
|
+
}
|
package/dist/tool.d.ts
CHANGED
|
@@ -6,11 +6,20 @@ export interface Tool<TContext = unknown, TOutput = unknown> {
|
|
|
6
6
|
parameters: z.ZodTypeAny;
|
|
7
7
|
execute: (input: unknown, runContext?: RunContext<TContext>) => Promise<TOutput> | TOutput;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
type ToolConfigWithParameters<TContext = unknown, TSchema extends z.ZodTypeAny = z.ZodTypeAny, TOutput = unknown> = {
|
|
10
10
|
name: string;
|
|
11
11
|
description: string;
|
|
12
12
|
parameters: TSchema;
|
|
13
13
|
execute: (input: z.infer<TSchema>, runContext?: RunContext<TContext>) => Promise<TOutput> | TOutput;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type ToolConfigWithoutParameters<TContext = unknown, TOutput = unknown> = {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
parameters?: undefined;
|
|
19
|
+
execute: (input: Record<string, never>, runContext?: RunContext<TContext>) => Promise<TOutput> | TOutput;
|
|
20
|
+
};
|
|
21
|
+
export type ToolConfig<TContext = unknown, TSchema extends z.ZodTypeAny = z.ZodTypeAny, TOutput = unknown> = ToolConfigWithParameters<TContext, TSchema, TOutput> | ToolConfigWithoutParameters<TContext, TOutput>;
|
|
22
|
+
export declare function tool<TContext = unknown, TOutput = unknown>(config: ToolConfigWithoutParameters<TContext, TOutput>): Tool<TContext, TOutput>;
|
|
23
|
+
export declare function tool<TContext = unknown, TSchema extends z.ZodTypeAny = z.ZodTypeAny, TOutput = unknown>(config: ToolConfigWithParameters<TContext, TSchema, TOutput>): Tool<TContext, TOutput>;
|
|
24
|
+
export {};
|
|
16
25
|
//# sourceMappingURL=tool.d.ts.map
|
package/dist/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../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