@agimon-ai/po-core 0.0.0-alpha.56 → 0.0.0-alpha.57
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/apiContracts.d.mts +3 -0
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/src/schemas/approval.cjs.map +1 -1
- package/dist/src/schemas/approval.d.mts +3 -0
- package/dist/src/schemas/approval.d.mts.map +1 -1
- package/dist/src/schemas/approval.mjs.map +1 -1
- package/dist/src/services/approvalGate/index.cjs +4 -2
- package/dist/src/services/approvalGate/index.cjs.map +1 -1
- package/dist/src/services/approvalGate/index.mjs +4 -2
- package/dist/src/services/approvalGate/index.mjs.map +1 -1
- package/dist/src/services/approvalGate/type.d.mts +1 -0
- package/dist/src/services/approvalGate/type.d.mts.map +1 -1
- package/package.json +4 -4
package/dist/apiContracts.d.mts
CHANGED
|
@@ -79,12 +79,15 @@ interface PoApprovalRequest {
|
|
|
79
79
|
readonly description: PoApprovalDescription;
|
|
80
80
|
/** The call's saved arguments, replayed by the operation kind's executor once approved. Never sent to clients. */
|
|
81
81
|
readonly input: unknown;
|
|
82
|
+
/** Code mode stores the full positional argument list; absent on legacy single-input receipts. */
|
|
83
|
+
readonly argumentFormat?: 'positional';
|
|
82
84
|
}
|
|
83
85
|
interface PoApprovedCall {
|
|
84
86
|
readonly approvalId: string;
|
|
85
87
|
readonly operation: PoApprovalOperation;
|
|
86
88
|
/** The saved `PoApprovalRequest.input`. */
|
|
87
89
|
readonly input: unknown;
|
|
90
|
+
readonly argumentFormat?: 'positional';
|
|
88
91
|
}
|
|
89
92
|
/** Runs an approved call; the resolved value or thrown error is reported to the agent. */
|
|
90
93
|
type PoApprovalExecutor = (call: PoApprovedCall, signal: AbortSignal) => Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiContracts.d.mts","names":["_0","_0","_0","IoContext","_0","_$__protocolContracts0.ChordMethods"],"sources":["../src/schemas/serverScope.ts","../src/schemas/approvalPrompt.ts","../src/schemas/approval.ts","../src/schemas/backgroundWork.ts","../src/schemas/platform.ts","../src/schemas/workflow.ts","../src/schemas/packageApi.ts","../src/schemas/serverBundle.ts","../src/schemas/apiContracts.ts","../src/services/apiContracts/index.ts","../src/schemas/builtinApiContracts.ts","../src/schemas/httpApiContracts.ts","../src/schemas/protocolContracts.ts","../src/schemas/sessionProtocol.ts","../src/schemas/sessionApiContracts.ts","../src/schemas/transportApiContracts.ts"],"mappings":";;;;;;;;;;UAiBiB,kBAAkB;WACxB;WACA,OAAO;;WAEP,QAAQ;;;KAQP;;UAoBK,sBAAsB;WAC5B,OAAO;EAChB,WAAW;;;UAII,oBAAoB;EACnC,QAAQ,GACN,KAAK,qBACL,cAAc,IAAI,QAAQ,IAC1B,WAAW,OAAO,aAAa,gBAC9B,QAAQ,sBAAsB;;EAEjC,IAAI,OAAO;;EAEX,MAAM,MAAM,sBAAsB;;;UAInB;WACN,OAAO;;;;;;EAMhB,QAAQ,GAAG,UAAU,kBAAkB,IAAI,OAAO,IAAI,cAAc;;EAEpE,QAAQ,GAAG,UAAU,kBAAkB,KAAK;;EAE5C,KAAK,gBAAgB,QAAQ,MAAM,MAAM,MAAM,WAAW,OAAO;;EAEjE,UAAU,gBAAgB,QAAQ,MAAM,MAAM,MAAM,WAAW,OAAO;;EAEtE,OAAO,QAAQ,gBAAgB,oBAAoB;;;YAIzC;IACR,mBAAmB;;;;;;UCxEN;WACN;WACA;WACA;aAA8B;aAAwB;;;UAGhD;WACN;;WAEA;;;;UCGM;WACN;;WAEA;WACA,WAAW;WACX;WACA,aAAa;;WAEb;;UAKM;WACN;WACA,WAAW;;WAEX;;;KAIC,sBAAsB,MAAM,gBAAgB,QAAQ,gBAAgB;;;;;UAM/D;EACf,OAAO,SAAS,oBAAoB;aAAmB;;EACvD,iBAAiB,MAAM,6BAA6B,KAAK;;;YAQ/C;IACR,eAAe;;;;;
|
|
1
|
+
{"version":3,"file":"apiContracts.d.mts","names":["_0","_0","_0","IoContext","_0","_$__protocolContracts0.ChordMethods"],"sources":["../src/schemas/serverScope.ts","../src/schemas/approvalPrompt.ts","../src/schemas/approval.ts","../src/schemas/backgroundWork.ts","../src/schemas/platform.ts","../src/schemas/workflow.ts","../src/schemas/packageApi.ts","../src/schemas/serverBundle.ts","../src/schemas/apiContracts.ts","../src/services/apiContracts/index.ts","../src/schemas/builtinApiContracts.ts","../src/schemas/httpApiContracts.ts","../src/schemas/protocolContracts.ts","../src/schemas/sessionProtocol.ts","../src/schemas/sessionApiContracts.ts","../src/schemas/transportApiContracts.ts"],"mappings":";;;;;;;;;;UAiBiB,kBAAkB;WACxB;WACA,OAAO;;WAEP,QAAQ;;;KAQP;;UAoBK,sBAAsB;WAC5B,OAAO;EAChB,WAAW;;;UAII,oBAAoB;EACnC,QAAQ,GACN,KAAK,qBACL,cAAc,IAAI,QAAQ,IAC1B,WAAW,OAAO,aAAa,gBAC9B,QAAQ,sBAAsB;;EAEjC,IAAI,OAAO;;EAEX,MAAM,MAAM,sBAAsB;;;UAInB;WACN,OAAO;;;;;;EAMhB,QAAQ,GAAG,UAAU,kBAAkB,IAAI,OAAO,IAAI,cAAc;;EAEpE,QAAQ,GAAG,UAAU,kBAAkB,KAAK;;EAE5C,KAAK,gBAAgB,QAAQ,MAAM,MAAM,MAAM,WAAW,OAAO;;EAEjE,UAAU,gBAAgB,QAAQ,MAAM,MAAM,MAAM,WAAW,OAAO;;EAEtE,OAAO,QAAQ,gBAAgB,oBAAoB;;;YAIzC;IACR,mBAAmB;;;;;;UCxEN;WACN;WACA;WACA;aAA8B;aAAwB;;;UAGhD;WACN;;WAEA;;;;UCGM;WACN;;WAEA;WACA,WAAW;WACX;WACA,aAAa;;WAEb;;WAEA;;UAKM;WACN;WACA,WAAW;;WAEX;WACA;;;KAIC,sBAAsB,MAAM,gBAAgB,QAAQ,gBAAgB;;;;;UAM/D;EACf,OAAO,SAAS,oBAAoB;aAAmB;;EACvD,iBAAiB,MAAM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KAAA,WAAA,KAAA,QAAA,KAAA,eAAA,KAAA,QAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA,aAAA,KAAA,YAAA,KAAA,YAAA,KAAA,QAAA,KAAA,eAAA,KAAA,YAAA,KAAA,QAAA,KAAA,eAAA,KAAA,QAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA,aAAA,KAAA,YAAA,KAAA,UAAA,KAAA,UAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,UAAA,KAAA,UAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,QAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA,aAAA,KAAA,YAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,OAAA,KAAA,aAAA,KAAA,QAAA,KAAA,eAAA,KAAA,UAAA,KAAA,OAAA,KAAA,QAAA,KAAA,SAAA,KAAA;;qBAqCjB,wBAAsB,KAAA,QAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAwBtB,wBAAsB,KAAA,QAAA,KAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.cjs","names":["defineServiceContract"],"sources":["../../../src/schemas/approval.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\n\nimport type { PoApprovalDescription, PoApprovalOperation } from './approvalPrompt';\nimport { defineServiceContract } from './serverScope';\n\nexport {\n PO_APPROVAL_TEXT_LIMITS,\n PO_APPROVAL_VOICE_EVENT,\n parsePoApprovalPrompt,\n PoApprovalPromptSchema,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPrompt,\n} from './approvalPrompt';\n\nexport const PO_APPROVAL_SERVICE = 'po/approval';\n\n/**\n * Declared on a direct tool, a portable tool, or a code-mode namespace member.\n * - `ask`: ask when a person can answer; run without asking for subagents, background scripts and scheduled runs.\n * - `human`: never run without a person's approval; refused where nobody can answer.\n */\nexport interface PoApprovalPolicy {\n readonly requirement: 'ask' | 'human';\n /** Receives the call's input (a tool's parameters, a namespace member's first argument). */\n describe(input: unknown): PoApprovalDescription | Promise<PoApprovalDescription>;\n}\n\nexport interface PoApprovalRequest {\n readonly sessionId: string;\n /** The direct tool call, or the `exec` call a namespace member runs inside. */\n readonly toolCallId: string;\n readonly operation: PoApprovalOperation;\n readonly requirement: 'ask' | 'human';\n readonly description: PoApprovalDescription;\n /** The call's saved arguments, replayed by the operation kind's executor once approved. Never sent to clients. */\n readonly input: unknown;\n}\n\nexport type PoApprovalDecision = 'approved' | 'denied' | 'cancelled';\n\nexport interface PoApprovedCall {\n readonly approvalId: string;\n readonly operation: PoApprovalOperation;\n /** The saved `PoApprovalRequest.input`. */\n readonly input: unknown;\n}\n\n/** Runs an approved call; the resolved value or thrown error is reported to the agent. */\nexport type PoApprovalExecutor = (call: PoApprovedCall, signal: AbortSignal) => Promise<unknown>;\n\n/**\n * Session-scoped. `submit` records a pending request durably and returns at once; the person decides later,\n * and an approved request runs through the executor registered for its operation kind.\n */\nexport interface PoApprovalService {\n submit(request: PoApprovalRequest): Promise<{ readonly id: string }>;\n registerExecutor(kind: PoApprovalOperation['kind'], run: PoApprovalExecutor): () => void;\n}\n\nexport const PO_APPROVAL_CONTRACT = defineServiceContract<PoApprovalService>(PO_APPROVAL_SERVICE, {\n scope: 'session',\n});\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/approval': PoApprovalService;\n }\n}\n\nexport function readPoApproval(context: Context): PoApprovalService | undefined {\n return context.get(PO_APPROVAL_SERVICE) as PoApprovalService | undefined;\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB;
|
|
1
|
+
{"version":3,"file":"approval.cjs","names":["defineServiceContract"],"sources":["../../../src/schemas/approval.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\n\nimport type { PoApprovalDescription, PoApprovalOperation } from './approvalPrompt';\nimport { defineServiceContract } from './serverScope';\n\nexport {\n PO_APPROVAL_TEXT_LIMITS,\n PO_APPROVAL_VOICE_EVENT,\n parsePoApprovalPrompt,\n PoApprovalPromptSchema,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPrompt,\n} from './approvalPrompt';\n\nexport const PO_APPROVAL_SERVICE = 'po/approval';\n\n/**\n * Declared on a direct tool, a portable tool, or a code-mode namespace member.\n * - `ask`: ask when a person can answer; run without asking for subagents, background scripts and scheduled runs.\n * - `human`: never run without a person's approval; refused where nobody can answer.\n */\nexport interface PoApprovalPolicy {\n readonly requirement: 'ask' | 'human';\n /** Receives the call's input (a tool's parameters, a namespace member's first argument). */\n describe(input: unknown): PoApprovalDescription | Promise<PoApprovalDescription>;\n}\n\nexport interface PoApprovalRequest {\n readonly sessionId: string;\n /** The direct tool call, or the `exec` call a namespace member runs inside. */\n readonly toolCallId: string;\n readonly operation: PoApprovalOperation;\n readonly requirement: 'ask' | 'human';\n readonly description: PoApprovalDescription;\n /** The call's saved arguments, replayed by the operation kind's executor once approved. Never sent to clients. */\n readonly input: unknown;\n /** Code mode stores the full positional argument list; absent on legacy single-input receipts. */\n readonly argumentFormat?: 'positional';\n}\n\nexport type PoApprovalDecision = 'approved' | 'denied' | 'cancelled';\n\nexport interface PoApprovedCall {\n readonly approvalId: string;\n readonly operation: PoApprovalOperation;\n /** The saved `PoApprovalRequest.input`. */\n readonly input: unknown;\n readonly argumentFormat?: 'positional';\n}\n\n/** Runs an approved call; the resolved value or thrown error is reported to the agent. */\nexport type PoApprovalExecutor = (call: PoApprovedCall, signal: AbortSignal) => Promise<unknown>;\n\n/**\n * Session-scoped. `submit` records a pending request durably and returns at once; the person decides later,\n * and an approved request runs through the executor registered for its operation kind.\n */\nexport interface PoApprovalService {\n submit(request: PoApprovalRequest): Promise<{ readonly id: string }>;\n registerExecutor(kind: PoApprovalOperation['kind'], run: PoApprovalExecutor): () => void;\n}\n\nexport const PO_APPROVAL_CONTRACT = defineServiceContract<PoApprovalService>(PO_APPROVAL_SERVICE, {\n scope: 'session',\n});\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/approval': PoApprovalService;\n }\n}\n\nexport function readPoApproval(context: Context): PoApprovalService | undefined {\n return context.get(PO_APPROVAL_SERVICE) as PoApprovalService | undefined;\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB;AAgDnC,MAAa,uBAAuBA,oBAAAA,sBAAyC,qBAAqB,EAChG,OAAO,UACT,CAAC;AAQD,SAAgB,eAAe,SAAiD;CAC9E,OAAO,QAAQ,IAAI,mBAAmB;AACxC"}
|
|
@@ -22,6 +22,8 @@ export interface PoApprovalRequest {
|
|
|
22
22
|
readonly description: PoApprovalDescription;
|
|
23
23
|
/** The call's saved arguments, replayed by the operation kind's executor once approved. Never sent to clients. */
|
|
24
24
|
readonly input: unknown;
|
|
25
|
+
/** Code mode stores the full positional argument list; absent on legacy single-input receipts. */
|
|
26
|
+
readonly argumentFormat?: 'positional';
|
|
25
27
|
}
|
|
26
28
|
export type PoApprovalDecision = 'approved' | 'denied' | 'cancelled';
|
|
27
29
|
export interface PoApprovedCall {
|
|
@@ -29,6 +31,7 @@ export interface PoApprovedCall {
|
|
|
29
31
|
readonly operation: PoApprovalOperation;
|
|
30
32
|
/** The saved `PoApprovalRequest.input`. */
|
|
31
33
|
readonly input: unknown;
|
|
34
|
+
readonly argumentFormat?: 'positional';
|
|
32
35
|
}
|
|
33
36
|
/** Runs an approved call; the resolved value or thrown error is reported to the agent. */
|
|
34
37
|
export type PoApprovalExecutor = (call: PoApprovedCall, signal: AbortSignal) => Promise<unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.d.mts","names":["_$__serverScope0.PoServiceContract"],"sources":["../../../src/schemas/approval.ts"],"mappings":";;;;qBAea;;;;;;iBAOI;WACN;;EAET,SAAS,iBAAiB,wBAAwB,QAAQ;;iBAG3C;WACN;;WAEA;WACA,WAAW;WACX;WACA,aAAa;;WAEb;;YAGC;iBAEK;WACN;WACA,WAAW;;WAEX;;;YAIC,sBAAsB,MAAM,gBAAgB,QAAQ,gBAAgB;;;;;iBAM/D;EACf,OAAO,SAAS,oBAAoB;aAAmB;;EACvD,iBAAiB,MAAM,6BAA6B,KAAK;;qBAG9C,sBAAoBA,kBAAA;;YAKrB;IACR,eAAe;;;wBAIH,eAAe,SAAS,UAAU"}
|
|
1
|
+
{"version":3,"file":"approval.d.mts","names":["_$__serverScope0.PoServiceContract"],"sources":["../../../src/schemas/approval.ts"],"mappings":";;;;qBAea;;;;;;iBAOI;WACN;;EAET,SAAS,iBAAiB,wBAAwB,QAAQ;;iBAG3C;WACN;;WAEA;WACA,WAAW;WACX;WACA,aAAa;;WAEb;;WAEA;;YAGC;iBAEK;WACN;WACA,WAAW;;WAEX;WACA;;;YAIC,sBAAsB,MAAM,gBAAgB,QAAQ,gBAAgB;;;;;iBAM/D;EACf,OAAO,SAAS,oBAAoB;aAAmB;;EACvD,iBAAiB,MAAM,6BAA6B,KAAK;;qBAG9C,sBAAoBA,kBAAA;;YAKrB;IACR,eAAe;;;wBAIH,eAAe,SAAS,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.mjs","names":[],"sources":["../../../src/schemas/approval.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\n\nimport type { PoApprovalDescription, PoApprovalOperation } from './approvalPrompt';\nimport { defineServiceContract } from './serverScope';\n\nexport {\n PO_APPROVAL_TEXT_LIMITS,\n PO_APPROVAL_VOICE_EVENT,\n parsePoApprovalPrompt,\n PoApprovalPromptSchema,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPrompt,\n} from './approvalPrompt';\n\nexport const PO_APPROVAL_SERVICE = 'po/approval';\n\n/**\n * Declared on a direct tool, a portable tool, or a code-mode namespace member.\n * - `ask`: ask when a person can answer; run without asking for subagents, background scripts and scheduled runs.\n * - `human`: never run without a person's approval; refused where nobody can answer.\n */\nexport interface PoApprovalPolicy {\n readonly requirement: 'ask' | 'human';\n /** Receives the call's input (a tool's parameters, a namespace member's first argument). */\n describe(input: unknown): PoApprovalDescription | Promise<PoApprovalDescription>;\n}\n\nexport interface PoApprovalRequest {\n readonly sessionId: string;\n /** The direct tool call, or the `exec` call a namespace member runs inside. */\n readonly toolCallId: string;\n readonly operation: PoApprovalOperation;\n readonly requirement: 'ask' | 'human';\n readonly description: PoApprovalDescription;\n /** The call's saved arguments, replayed by the operation kind's executor once approved. Never sent to clients. */\n readonly input: unknown;\n}\n\nexport type PoApprovalDecision = 'approved' | 'denied' | 'cancelled';\n\nexport interface PoApprovedCall {\n readonly approvalId: string;\n readonly operation: PoApprovalOperation;\n /** The saved `PoApprovalRequest.input`. */\n readonly input: unknown;\n}\n\n/** Runs an approved call; the resolved value or thrown error is reported to the agent. */\nexport type PoApprovalExecutor = (call: PoApprovedCall, signal: AbortSignal) => Promise<unknown>;\n\n/**\n * Session-scoped. `submit` records a pending request durably and returns at once; the person decides later,\n * and an approved request runs through the executor registered for its operation kind.\n */\nexport interface PoApprovalService {\n submit(request: PoApprovalRequest): Promise<{ readonly id: string }>;\n registerExecutor(kind: PoApprovalOperation['kind'], run: PoApprovalExecutor): () => void;\n}\n\nexport const PO_APPROVAL_CONTRACT = defineServiceContract<PoApprovalService>(PO_APPROVAL_SERVICE, {\n scope: 'session',\n});\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/approval': PoApprovalService;\n }\n}\n\nexport function readPoApproval(context: Context): PoApprovalService | undefined {\n return context.get(PO_APPROVAL_SERVICE) as PoApprovalService | undefined;\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB;
|
|
1
|
+
{"version":3,"file":"approval.mjs","names":[],"sources":["../../../src/schemas/approval.ts"],"sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\n\nimport type { PoApprovalDescription, PoApprovalOperation } from './approvalPrompt';\nimport { defineServiceContract } from './serverScope';\n\nexport {\n PO_APPROVAL_TEXT_LIMITS,\n PO_APPROVAL_VOICE_EVENT,\n parsePoApprovalPrompt,\n PoApprovalPromptSchema,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPrompt,\n} from './approvalPrompt';\n\nexport const PO_APPROVAL_SERVICE = 'po/approval';\n\n/**\n * Declared on a direct tool, a portable tool, or a code-mode namespace member.\n * - `ask`: ask when a person can answer; run without asking for subagents, background scripts and scheduled runs.\n * - `human`: never run without a person's approval; refused where nobody can answer.\n */\nexport interface PoApprovalPolicy {\n readonly requirement: 'ask' | 'human';\n /** Receives the call's input (a tool's parameters, a namespace member's first argument). */\n describe(input: unknown): PoApprovalDescription | Promise<PoApprovalDescription>;\n}\n\nexport interface PoApprovalRequest {\n readonly sessionId: string;\n /** The direct tool call, or the `exec` call a namespace member runs inside. */\n readonly toolCallId: string;\n readonly operation: PoApprovalOperation;\n readonly requirement: 'ask' | 'human';\n readonly description: PoApprovalDescription;\n /** The call's saved arguments, replayed by the operation kind's executor once approved. Never sent to clients. */\n readonly input: unknown;\n /** Code mode stores the full positional argument list; absent on legacy single-input receipts. */\n readonly argumentFormat?: 'positional';\n}\n\nexport type PoApprovalDecision = 'approved' | 'denied' | 'cancelled';\n\nexport interface PoApprovedCall {\n readonly approvalId: string;\n readonly operation: PoApprovalOperation;\n /** The saved `PoApprovalRequest.input`. */\n readonly input: unknown;\n readonly argumentFormat?: 'positional';\n}\n\n/** Runs an approved call; the resolved value or thrown error is reported to the agent. */\nexport type PoApprovalExecutor = (call: PoApprovedCall, signal: AbortSignal) => Promise<unknown>;\n\n/**\n * Session-scoped. `submit` records a pending request durably and returns at once; the person decides later,\n * and an approved request runs through the executor registered for its operation kind.\n */\nexport interface PoApprovalService {\n submit(request: PoApprovalRequest): Promise<{ readonly id: string }>;\n registerExecutor(kind: PoApprovalOperation['kind'], run: PoApprovalExecutor): () => void;\n}\n\nexport const PO_APPROVAL_CONTRACT = defineServiceContract<PoApprovalService>(PO_APPROVAL_SERVICE, {\n scope: 'session',\n});\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/approval': PoApprovalService;\n }\n}\n\nexport function readPoApproval(context: Context): PoApprovalService | undefined {\n return context.get(PO_APPROVAL_SERVICE) as PoApprovalService | undefined;\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB;AAgDnC,MAAa,uBAAuB,sBAAyC,qBAAqB,EAChG,OAAO,UACT,CAAC;AAQD,SAAgB,eAAe,SAAiD;CAC9E,OAAO,QAAQ,IAAI,mBAAmB;AACxC"}
|
|
@@ -66,8 +66,9 @@ async function gateApproval(input) {
|
|
|
66
66
|
let saved;
|
|
67
67
|
try {
|
|
68
68
|
const json = JSON.stringify(input.arguments ?? null);
|
|
69
|
-
if (json.
|
|
69
|
+
if (new TextEncoder().encode(json).byteLength > 262144) throw new Error(`its input is larger than ${APPROVAL_INPUT_LIMIT} bytes`);
|
|
70
70
|
saved = JSON.parse(json);
|
|
71
|
+
if (input.argumentFormat === "positional" && (operation.kind !== "codemode" || !Array.isArray(saved))) throw new Error("positional arguments must be a code-mode argument list");
|
|
71
72
|
} catch (error) {
|
|
72
73
|
return {
|
|
73
74
|
ok: false,
|
|
@@ -91,7 +92,8 @@ async function gateApproval(input) {
|
|
|
91
92
|
operation,
|
|
92
93
|
requirement: policy.requirement,
|
|
93
94
|
description,
|
|
94
|
-
input: saved
|
|
95
|
+
input: saved,
|
|
96
|
+
...input.argumentFormat === void 0 ? {} : { argumentFormat: input.argumentFormat }
|
|
95
97
|
});
|
|
96
98
|
return {
|
|
97
99
|
ok: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PO_APPROVAL_TEXT_LIMITS"],"sources":["../../../../src/services/approvalGate/index.ts"],"sourcesContent":["import {\n PO_APPROVAL_TEXT_LIMITS,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPolicy,\n type PoApprovalService,\n} from '../../schemas/approval';\nimport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\nexport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\n/** Saved input above this size is refused rather than stored. */\nexport const APPROVAL_INPUT_LIMIT = 256 * 1024;\n\n/** Thrown by a gated code-mode member while it waits for approval. Match on `name`: `instanceof` does not cross script sandboxes. */\nexport class ApprovalPendingError extends Error {\n override readonly name = 'ApprovalPendingError';\n constructor(\n readonly approvalId: string,\n message: string,\n ) {\n super(message);\n }\n}\n\nconst {\n title: TITLE_LIMIT,\n summary: SUMMARY_LIMIT,\n details: DETAIL_LIMIT,\n label: LABEL_LIMIT,\n value: VALUE_LIMIT,\n} = PO_APPROVAL_TEXT_LIMITS;\n\nfunction clip(value: unknown, limit: number): string {\n const text = typeof value === 'string' ? value.replace(/\\s+/gu, ' ').trim() : '';\n return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;\n}\n\n/** Bounded plain text, whatever the package's `describe` returned. */\nexport function boundApprovalDescription(description: PoApprovalDescription, fallback: string): PoApprovalDescription {\n const details = Array.isArray(description?.details)\n ? description.details\n .slice(0, DETAIL_LIMIT)\n .map((detail) => ({ label: clip(detail?.label, LABEL_LIMIT), value: clip(detail?.value, VALUE_LIMIT) }))\n .filter((detail) => detail.label !== '' && detail.value !== '')\n : [];\n return {\n title: clip(description?.title, TITLE_LIMIT) || clip(fallback, TITLE_LIMIT),\n summary: clip(description?.summary, SUMMARY_LIMIT),\n ...(details.length === 0 ? {} : { details }),\n };\n}\n\n/** A child or background run cannot elevate the session's host-set presence. */\nexport function isUnattended(input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>): boolean {\n return input.caller === 'child' || input.background === true || input.interaction === 'unattended';\n}\n\n/** True when an operation with this policy may not even be offered here. */\nexport function isApprovalUnavailable(\n policy: PoApprovalPolicy | undefined,\n input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>,\n): boolean {\n return policy?.requirement === 'human' && isUnattended(input);\n}\n\nfunction label(operation: PoApprovalOperation): string {\n return `'${operation.name}'`;\n}\n\n/**\n * The one admission rule for direct tools and code-mode members. Resolves `{ ok: true }` only when the operation\n * may run now. A person-gated call is recorded and resolves `pending` at once; it runs later, once approved.\n * A refusal carries the message the agent sees. Never throws for a refusal.\n */\nexport async function gateApproval(input: ApprovalGateInput): Promise<ApprovalGateResult> {\n const { policy, operation } = input;\n if (policy === undefined) return { ok: true };\n const cancelled: ApprovalGateResult = { ok: false, reason: `${label(operation)} was cancelled. Nothing ran.` };\n const stopped = (): boolean => input.signal?.aborted === true;\n if (stopped()) return cancelled;\n if (isUnattended(input)) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, and nobody can answer here (subagent, background script, workflow or scheduled run). Nothing ran. Ask the person to do it from their own session.`,\n };\n }\n const service: PoApprovalService | undefined = input.service;\n if (service === undefined) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, but approvals are not available in this session. Nothing ran.`,\n };\n }\n let saved: unknown;\n try {\n const json = JSON.stringify(input.arguments ?? null);\n if (json.
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PO_APPROVAL_TEXT_LIMITS"],"sources":["../../../../src/services/approvalGate/index.ts"],"sourcesContent":["import {\n PO_APPROVAL_TEXT_LIMITS,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPolicy,\n type PoApprovalService,\n} from '../../schemas/approval';\nimport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\nexport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\n/** Saved input above this size is refused rather than stored. */\nexport const APPROVAL_INPUT_LIMIT = 256 * 1024;\n\n/** Thrown by a gated code-mode member while it waits for approval. Match on `name`: `instanceof` does not cross script sandboxes. */\nexport class ApprovalPendingError extends Error {\n override readonly name = 'ApprovalPendingError';\n constructor(\n readonly approvalId: string,\n message: string,\n ) {\n super(message);\n }\n}\n\nconst {\n title: TITLE_LIMIT,\n summary: SUMMARY_LIMIT,\n details: DETAIL_LIMIT,\n label: LABEL_LIMIT,\n value: VALUE_LIMIT,\n} = PO_APPROVAL_TEXT_LIMITS;\n\nfunction clip(value: unknown, limit: number): string {\n const text = typeof value === 'string' ? value.replace(/\\s+/gu, ' ').trim() : '';\n return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;\n}\n\n/** Bounded plain text, whatever the package's `describe` returned. */\nexport function boundApprovalDescription(description: PoApprovalDescription, fallback: string): PoApprovalDescription {\n const details = Array.isArray(description?.details)\n ? description.details\n .slice(0, DETAIL_LIMIT)\n .map((detail) => ({ label: clip(detail?.label, LABEL_LIMIT), value: clip(detail?.value, VALUE_LIMIT) }))\n .filter((detail) => detail.label !== '' && detail.value !== '')\n : [];\n return {\n title: clip(description?.title, TITLE_LIMIT) || clip(fallback, TITLE_LIMIT),\n summary: clip(description?.summary, SUMMARY_LIMIT),\n ...(details.length === 0 ? {} : { details }),\n };\n}\n\n/** A child or background run cannot elevate the session's host-set presence. */\nexport function isUnattended(input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>): boolean {\n return input.caller === 'child' || input.background === true || input.interaction === 'unattended';\n}\n\n/** True when an operation with this policy may not even be offered here. */\nexport function isApprovalUnavailable(\n policy: PoApprovalPolicy | undefined,\n input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>,\n): boolean {\n return policy?.requirement === 'human' && isUnattended(input);\n}\n\nfunction label(operation: PoApprovalOperation): string {\n return `'${operation.name}'`;\n}\n\n/**\n * The one admission rule for direct tools and code-mode members. Resolves `{ ok: true }` only when the operation\n * may run now. A person-gated call is recorded and resolves `pending` at once; it runs later, once approved.\n * A refusal carries the message the agent sees. Never throws for a refusal.\n */\nexport async function gateApproval(input: ApprovalGateInput): Promise<ApprovalGateResult> {\n const { policy, operation } = input;\n if (policy === undefined) return { ok: true };\n const cancelled: ApprovalGateResult = { ok: false, reason: `${label(operation)} was cancelled. Nothing ran.` };\n const stopped = (): boolean => input.signal?.aborted === true;\n if (stopped()) return cancelled;\n if (isUnattended(input)) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, and nobody can answer here (subagent, background script, workflow or scheduled run). Nothing ran. Ask the person to do it from their own session.`,\n };\n }\n const service: PoApprovalService | undefined = input.service;\n if (service === undefined) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, but approvals are not available in this session. Nothing ran.`,\n };\n }\n let saved: unknown;\n try {\n const json = JSON.stringify(input.arguments ?? null);\n if (new TextEncoder().encode(json).byteLength > APPROVAL_INPUT_LIMIT)\n throw new Error(`its input is larger than ${APPROVAL_INPUT_LIMIT} bytes`);\n saved = JSON.parse(json);\n if (input.argumentFormat === 'positional' && (operation.kind !== 'codemode' || !Array.isArray(saved)))\n throw new Error('positional arguments must be a code-mode argument list');\n } catch (error) {\n return {\n ok: false,\n reason: `${label(operation)} cannot wait for approval: ${error instanceof Error ? error.message : String(error)}. Nothing ran.`,\n };\n }\n let description: PoApprovalDescription;\n try {\n description = boundApprovalDescription(await policy.describe(input.input), operation.name);\n } catch (error) {\n return {\n ok: false,\n reason: `${label(operation)} could not be described for approval: ${error instanceof Error ? error.message : String(error)}. Nothing ran.`,\n };\n }\n if (stopped()) return cancelled;\n try {\n const { id } = await service.submit({\n sessionId: input.sessionId,\n toolCallId: input.toolCallId,\n operation,\n requirement: policy.requirement,\n description,\n input: saved,\n ...(input.argumentFormat === undefined ? {} : { argumentFormat: input.argumentFormat }),\n });\n return {\n ok: false,\n pending: true,\n approvalId: id,\n reason: `${label(operation)} is waiting for the person's approval (id ${id}). Nothing ran yet. Keep working; the result arrives as a message once they decide. Do not call it again.`,\n };\n } catch (error) {\n return {\n ok: false,\n reason: `${label(operation)} could not request approval: ${error instanceof Error ? error.message : String(error)}. Nothing ran.`,\n };\n }\n}\n"],"mappings":";;;;AAYA,MAAa,uBAAuB;;AAGpC,IAAa,uBAAb,cAA0C,MAAM;CAGnC;CAFX,OAAyB;C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;GAClB;GACA,aAAa,OAAO;GACpB;GACA,OAAO;GACP,GAAI,MAAM,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,MAAM,eAAe;EACvF,CAAC;EACD,OAAO;GACL,IAAI;GACJ,SAAS;GACT,YAAY;GACZ,QAAQ,GAAG,MAAM,SAAS,EAAE,4CAA4C,GAAG;EAC7E;CACF,SAAS,OAAO;EACd,OAAO;GACL,IAAI;GACJ,QAAQ,GAAG,MAAM,SAAS,EAAE,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE;EACpH;CACF;AACF"}
|
|
@@ -66,8 +66,9 @@ async function gateApproval(input) {
|
|
|
66
66
|
let saved;
|
|
67
67
|
try {
|
|
68
68
|
const json = JSON.stringify(input.arguments ?? null);
|
|
69
|
-
if (json.
|
|
69
|
+
if (new TextEncoder().encode(json).byteLength > 262144) throw new Error(`its input is larger than ${APPROVAL_INPUT_LIMIT} bytes`);
|
|
70
70
|
saved = JSON.parse(json);
|
|
71
|
+
if (input.argumentFormat === "positional" && (operation.kind !== "codemode" || !Array.isArray(saved))) throw new Error("positional arguments must be a code-mode argument list");
|
|
71
72
|
} catch (error) {
|
|
72
73
|
return {
|
|
73
74
|
ok: false,
|
|
@@ -91,7 +92,8 @@ async function gateApproval(input) {
|
|
|
91
92
|
operation,
|
|
92
93
|
requirement: policy.requirement,
|
|
93
94
|
description,
|
|
94
|
-
input: saved
|
|
95
|
+
input: saved,
|
|
96
|
+
...input.argumentFormat === void 0 ? {} : { argumentFormat: input.argumentFormat }
|
|
95
97
|
});
|
|
96
98
|
return {
|
|
97
99
|
ok: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/services/approvalGate/index.ts"],"sourcesContent":["import {\n PO_APPROVAL_TEXT_LIMITS,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPolicy,\n type PoApprovalService,\n} from '../../schemas/approval';\nimport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\nexport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\n/** Saved input above this size is refused rather than stored. */\nexport const APPROVAL_INPUT_LIMIT = 256 * 1024;\n\n/** Thrown by a gated code-mode member while it waits for approval. Match on `name`: `instanceof` does not cross script sandboxes. */\nexport class ApprovalPendingError extends Error {\n override readonly name = 'ApprovalPendingError';\n constructor(\n readonly approvalId: string,\n message: string,\n ) {\n super(message);\n }\n}\n\nconst {\n title: TITLE_LIMIT,\n summary: SUMMARY_LIMIT,\n details: DETAIL_LIMIT,\n label: LABEL_LIMIT,\n value: VALUE_LIMIT,\n} = PO_APPROVAL_TEXT_LIMITS;\n\nfunction clip(value: unknown, limit: number): string {\n const text = typeof value === 'string' ? value.replace(/\\s+/gu, ' ').trim() : '';\n return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;\n}\n\n/** Bounded plain text, whatever the package's `describe` returned. */\nexport function boundApprovalDescription(description: PoApprovalDescription, fallback: string): PoApprovalDescription {\n const details = Array.isArray(description?.details)\n ? description.details\n .slice(0, DETAIL_LIMIT)\n .map((detail) => ({ label: clip(detail?.label, LABEL_LIMIT), value: clip(detail?.value, VALUE_LIMIT) }))\n .filter((detail) => detail.label !== '' && detail.value !== '')\n : [];\n return {\n title: clip(description?.title, TITLE_LIMIT) || clip(fallback, TITLE_LIMIT),\n summary: clip(description?.summary, SUMMARY_LIMIT),\n ...(details.length === 0 ? {} : { details }),\n };\n}\n\n/** A child or background run cannot elevate the session's host-set presence. */\nexport function isUnattended(input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>): boolean {\n return input.caller === 'child' || input.background === true || input.interaction === 'unattended';\n}\n\n/** True when an operation with this policy may not even be offered here. */\nexport function isApprovalUnavailable(\n policy: PoApprovalPolicy | undefined,\n input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>,\n): boolean {\n return policy?.requirement === 'human' && isUnattended(input);\n}\n\nfunction label(operation: PoApprovalOperation): string {\n return `'${operation.name}'`;\n}\n\n/**\n * The one admission rule for direct tools and code-mode members. Resolves `{ ok: true }` only when the operation\n * may run now. A person-gated call is recorded and resolves `pending` at once; it runs later, once approved.\n * A refusal carries the message the agent sees. Never throws for a refusal.\n */\nexport async function gateApproval(input: ApprovalGateInput): Promise<ApprovalGateResult> {\n const { policy, operation } = input;\n if (policy === undefined) return { ok: true };\n const cancelled: ApprovalGateResult = { ok: false, reason: `${label(operation)} was cancelled. Nothing ran.` };\n const stopped = (): boolean => input.signal?.aborted === true;\n if (stopped()) return cancelled;\n if (isUnattended(input)) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, and nobody can answer here (subagent, background script, workflow or scheduled run). Nothing ran. Ask the person to do it from their own session.`,\n };\n }\n const service: PoApprovalService | undefined = input.service;\n if (service === undefined) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, but approvals are not available in this session. Nothing ran.`,\n };\n }\n let saved: unknown;\n try {\n const json = JSON.stringify(input.arguments ?? null);\n if (json.
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/services/approvalGate/index.ts"],"sourcesContent":["import {\n PO_APPROVAL_TEXT_LIMITS,\n type PoApprovalDescription,\n type PoApprovalOperation,\n type PoApprovalPolicy,\n type PoApprovalService,\n} from '../../schemas/approval';\nimport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\nexport type { ApprovalGateInput, ApprovalGateResult } from './type';\n\n/** Saved input above this size is refused rather than stored. */\nexport const APPROVAL_INPUT_LIMIT = 256 * 1024;\n\n/** Thrown by a gated code-mode member while it waits for approval. Match on `name`: `instanceof` does not cross script sandboxes. */\nexport class ApprovalPendingError extends Error {\n override readonly name = 'ApprovalPendingError';\n constructor(\n readonly approvalId: string,\n message: string,\n ) {\n super(message);\n }\n}\n\nconst {\n title: TITLE_LIMIT,\n summary: SUMMARY_LIMIT,\n details: DETAIL_LIMIT,\n label: LABEL_LIMIT,\n value: VALUE_LIMIT,\n} = PO_APPROVAL_TEXT_LIMITS;\n\nfunction clip(value: unknown, limit: number): string {\n const text = typeof value === 'string' ? value.replace(/\\s+/gu, ' ').trim() : '';\n return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;\n}\n\n/** Bounded plain text, whatever the package's `describe` returned. */\nexport function boundApprovalDescription(description: PoApprovalDescription, fallback: string): PoApprovalDescription {\n const details = Array.isArray(description?.details)\n ? description.details\n .slice(0, DETAIL_LIMIT)\n .map((detail) => ({ label: clip(detail?.label, LABEL_LIMIT), value: clip(detail?.value, VALUE_LIMIT) }))\n .filter((detail) => detail.label !== '' && detail.value !== '')\n : [];\n return {\n title: clip(description?.title, TITLE_LIMIT) || clip(fallback, TITLE_LIMIT),\n summary: clip(description?.summary, SUMMARY_LIMIT),\n ...(details.length === 0 ? {} : { details }),\n };\n}\n\n/** A child or background run cannot elevate the session's host-set presence. */\nexport function isUnattended(input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>): boolean {\n return input.caller === 'child' || input.background === true || input.interaction === 'unattended';\n}\n\n/** True when an operation with this policy may not even be offered here. */\nexport function isApprovalUnavailable(\n policy: PoApprovalPolicy | undefined,\n input: Pick<ApprovalGateInput, 'caller' | 'background' | 'interaction'>,\n): boolean {\n return policy?.requirement === 'human' && isUnattended(input);\n}\n\nfunction label(operation: PoApprovalOperation): string {\n return `'${operation.name}'`;\n}\n\n/**\n * The one admission rule for direct tools and code-mode members. Resolves `{ ok: true }` only when the operation\n * may run now. A person-gated call is recorded and resolves `pending` at once; it runs later, once approved.\n * A refusal carries the message the agent sees. Never throws for a refusal.\n */\nexport async function gateApproval(input: ApprovalGateInput): Promise<ApprovalGateResult> {\n const { policy, operation } = input;\n if (policy === undefined) return { ok: true };\n const cancelled: ApprovalGateResult = { ok: false, reason: `${label(operation)} was cancelled. Nothing ran.` };\n const stopped = (): boolean => input.signal?.aborted === true;\n if (stopped()) return cancelled;\n if (isUnattended(input)) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, and nobody can answer here (subagent, background script, workflow or scheduled run). Nothing ran. Ask the person to do it from their own session.`,\n };\n }\n const service: PoApprovalService | undefined = input.service;\n if (service === undefined) {\n return policy.requirement === 'ask'\n ? { ok: true }\n : {\n ok: false,\n reason: `${label(operation)} needs a person's approval, but approvals are not available in this session. Nothing ran.`,\n };\n }\n let saved: unknown;\n try {\n const json = JSON.stringify(input.arguments ?? null);\n if (new TextEncoder().encode(json).byteLength > APPROVAL_INPUT_LIMIT)\n throw new Error(`its input is larger than ${APPROVAL_INPUT_LIMIT} bytes`);\n saved = JSON.parse(json);\n if (input.argumentFormat === 'positional' && (operation.kind !== 'codemode' || !Array.isArray(saved)))\n throw new Error('positional arguments must be a code-mode argument list');\n } catch (error) {\n return {\n ok: false,\n reason: `${label(operation)} cannot wait for approval: ${error instanceof Error ? error.message : String(error)}. Nothing ran.`,\n };\n }\n let description: PoApprovalDescription;\n try {\n description = boundApprovalDescription(await policy.describe(input.input), operation.name);\n } catch (error) {\n return {\n ok: false,\n reason: `${label(operation)} could not be described for approval: ${error instanceof Error ? error.message : String(error)}. Nothing ran.`,\n };\n }\n if (stopped()) return cancelled;\n try {\n const { id } = await service.submit({\n sessionId: input.sessionId,\n toolCallId: input.toolCallId,\n operation,\n requirement: policy.requirement,\n description,\n input: saved,\n ...(input.argumentFormat === undefined ? {} : { argumentFormat: input.argumentFormat }),\n });\n return {\n ok: false,\n pending: true,\n approvalId: id,\n reason: `${label(operation)} is waiting for the person's approval (id ${id}). Nothing ran yet. Keep working; the result arrives as a message once they decide. Do not call it again.`,\n };\n } catch (error) {\n return {\n ok: false,\n reason: `${label(operation)} could not request approval: ${error instanceof Error ? error.message : String(error)}. Nothing ran.`,\n };\n }\n}\n"],"mappings":";;;;AAYA,MAAa,uBAAuB;;AAGpC,IAAa,uBAAb,cAA0C,MAAM;CAGnC;CAFX,OAAyB;CAC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,aAAa,OAAO;GACpB;GACA,OAAO;GACP,GAAI,MAAM,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,MAAM,eAAe;EACvF,CAAC;EACD,OAAO;GACL,IAAI;GACJ,SAAS;GACT,YAAY;GACZ,QAAQ,GAAG,MAAM,SAAS,EAAE,4CAA4C,GAAG;EAC7E;CACF,SAAS,OAAO;EACd,OAAO;GACL,IAAI;GACJ,QAAQ,GAAG,MAAM,SAAS,EAAE,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE;EACpH;CACF;AACF"}
|
|
@@ -8,6 +8,7 @@ export interface ApprovalGateInput {
|
|
|
8
8
|
readonly input: unknown;
|
|
9
9
|
/** The full call arguments, saved as JSON and replayed once approved. */
|
|
10
10
|
readonly arguments: unknown;
|
|
11
|
+
readonly argumentFormat?: 'positional';
|
|
11
12
|
readonly sessionId: string;
|
|
12
13
|
readonly toolCallId: string;
|
|
13
14
|
readonly caller?: 'main' | 'child';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.mts","names":[],"sources":["../../../../src/services/approvalGate/type.ts"],"mappings":";;;iBAEiB;WACN,QAAQ;WACR,WAAW;;WAEX;;WAEA;WACA;WACA;WACA;;WAEA;;WAEA;;WAEA,SAAS;WACT,SAAS;;YAGR;WACG;;WACA;WAAoB;WAAyB;;WAC7C;WAAoB;WAAwB;WAA6B"}
|
|
1
|
+
{"version":3,"file":"type.d.mts","names":[],"sources":["../../../../src/services/approvalGate/type.ts"],"mappings":";;;iBAEiB;WACN,QAAQ;WACR,WAAW;;WAEX;;WAEA;WACA;WACA;WACA;WACA;;WAEA;;WAEA;;WAEA,SAAS;WACT,SAAS;;YAGR;WACG;;WACA;WAAoB;WAAyB;;WAC7C;WAAoB;WAAwB;WAA6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-core",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.57",
|
|
4
4
|
"description": "Po runtime systems and reusable core services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -559,8 +559,8 @@
|
|
|
559
559
|
"registry": "https://registry.npmjs.org/"
|
|
560
560
|
},
|
|
561
561
|
"dependencies": {
|
|
562
|
-
"@agimon-ai/po-logsink": "0.0.1-alpha.
|
|
563
|
-
"@agimon-ai/po-web-security": "0.0.0-alpha.
|
|
562
|
+
"@agimon-ai/po-logsink": "0.0.1-alpha.39",
|
|
563
|
+
"@agimon-ai/po-web-security": "0.0.0-alpha.57",
|
|
564
564
|
"@deepseek-ai/cordis": "4.0.5",
|
|
565
565
|
"@earendil-works/chord": "1.4.0",
|
|
566
566
|
"@earendil-works/pi-agent-core": "1.4.0",
|
|
@@ -584,7 +584,7 @@
|
|
|
584
584
|
"yaml": "2.9.1"
|
|
585
585
|
},
|
|
586
586
|
"devDependencies": {
|
|
587
|
-
"@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.
|
|
587
|
+
"@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.57",
|
|
588
588
|
"@apidevtools/swagger-parser": "^13.1.0",
|
|
589
589
|
"@asyncapi/parser": "^3.6.4",
|
|
590
590
|
"@earendil-works/pi-ai": "1.4.0",
|