@agimon-ai/po-approval 0.0.0-alpha.43

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/LICENSE ADDED
@@ -0,0 +1,149 @@
1
+ License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
2
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
3
+
4
+ Parameters
5
+
6
+ Licensor: Agimon Pty Ltd
7
+ Licensed Work: Po, the software in the Po source repository and the
8
+ packages released from it, in each version released by
9
+ the Licensor.
10
+ The Licensed Work is (c) 2026 Agimon Pty Ltd.
11
+ Material identified as third-party in the "Third-party
12
+ components" section at the end of this file or in a
13
+ NOTICE file, and any package or directory whose own
14
+ license file grants a different license, is not part of
15
+ the Licensed Work and remains under its own license.
16
+ Additional Use Grant: You may make production use of the Licensed Work if
17
+ your use is Eligible Use. "Eligible Use" is production use that falls
18
+ within at least one of the following:
19
+
20
+ (a) Personal Use. Use by an individual for their own personal purposes,
21
+ and not on behalf of, or for the benefit of, an employer, client, or
22
+ other Organization. Use by an individual in the course of employment
23
+ or engagement by an Organization is use by that Organization.
24
+
25
+ (b) Small Organization Use. Use by or on behalf of an Organization whose
26
+ Annual Revenue is less than USD 1,000,000.
27
+
28
+ (c) Non-profit, Education and Research Use. Use, regardless of Annual
29
+ Revenue, by (i) an Organization registered or recognized as a
30
+ non-profit or charitable organization under the laws of its
31
+ jurisdiction, for its non-profit purposes; (ii) an accredited school,
32
+ college, or university, for teaching, learning, or academic research;
33
+ or (iii) a publicly funded research institution, for its research.
34
+
35
+ (d) Service Provider Use. Use by a consultant, contractor, agency, or other
36
+ service provider, regardless of its own Annual Revenue, solely to
37
+ build, deploy, host, operate, or support the Licensed Work for a client
38
+ whose own use would be Eligible Use under (a), (b), or (c). A service
39
+ provider's use for its own purposes is Eligible Use only if the service
40
+ provider itself qualifies under (b) or (c).
41
+
42
+
43
+ Hosted services. Offering the Licensed Work to third parties as a hosted
44
+ or managed service whose primary value is the Licensed Work is Eligible
45
+ Use only if each such third party's own use would be Eligible Use.
46
+
47
+ Definitions. "Organization" means any company, partnership, sole
48
+ proprietorship, trust, association, government body, or other entity, and
49
+ includes an individual acting in a business or professional capacity.
50
+ "Affiliate" means any entity that directly or indirectly controls, is
51
+ controlled by, or is under common control with an Organization, where
52
+ "control" means ownership of more than 50% of the voting interests of an
53
+ entity or the power to direct its management and policies by contract or
54
+ otherwise. "Annual Revenue" means the total gross revenue of an
55
+ Organization and all of its Affiliates combined, from all sources and
56
+ whether or not related to the Licensed Work, for its most recently
57
+ completed fiscal year, or, if it has not completed a fiscal year, for the
58
+ twelve months before the use (or since its formation, if shorter),
59
+ converted into US dollars at the average exchange rate for that period.
60
+ Proceeds of equity or debt financing are not revenue.
61
+
62
+ Threshold. If an Organization stops qualifying under (b), its existing
63
+ production use remains Eligible Use for 90 days after it stops
64
+ qualifying, after which it must obtain a commercial license or stop
65
+ production use. Use that was Eligible Use when it occurred never requires
66
+ a commercial license after the fact.
67
+ Change Date: Four years from the date a version of the Licensed Work
68
+ is first publicly released by the Licensor.
69
+ Change License: Apache License, Version 2.0
70
+
71
+ For information about alternative licensing arrangements for the Licensed
72
+ Work, please visit: https://agimon.ai/licensing
73
+
74
+ Notice
75
+
76
+ The Business Source License (this document, or the "License") is not an Open
77
+ Source license. However, the Licensed Work will eventually be made available
78
+ under an Open Source License, as stated in this License.
79
+
80
+ -----------------------------------------------------------------------------
81
+
82
+ Business Source License 1.1
83
+
84
+ Terms
85
+
86
+ The Licensor hereby grants you the right to copy, modify, create derivative
87
+ works, redistribute, and make non-production use of the Licensed Work. The
88
+ Licensor may make an Additional Use Grant, above, permitting limited
89
+ production use.
90
+
91
+ Effective on the Change Date, or the fourth anniversary of the first publicly
92
+ available distribution of a specific version of the Licensed Work under this
93
+ License, whichever comes first, the Licensor hereby grants you rights under
94
+ the terms of the Change License, and the rights granted in the paragraph
95
+ above terminate.
96
+
97
+ If your use of the Licensed Work does not comply with the requirements
98
+ currently in effect as described in this License, you must purchase a
99
+ commercial license from the Licensor, its affiliated entities, or authorized
100
+ resellers, or you must refrain from using the Licensed Work.
101
+
102
+ All copies of the original and modified Licensed Work, and derivative works
103
+ of the Licensed Work, are subject to this License. This License applies
104
+ separately for each version of the Licensed Work and the Change Date may vary
105
+ for each version of the Licensed Work released by Licensor.
106
+
107
+ You must conspicuously display this License on each original or modified copy
108
+ of the Licensed Work. If you receive the Licensed Work in original or
109
+ modified form from a third party, the terms and conditions set forth in this
110
+ License apply to your use of that work.
111
+
112
+ Any use of the Licensed Work in violation of this License will automatically
113
+ terminate your rights under this License for the current and all other
114
+ versions of the Licensed Work.
115
+
116
+ This License does not grant you any right in any trademark or logo of
117
+ Licensor or its affiliates (provided that you may use a trademark or logo of
118
+ Licensor as expressly required by this License).
119
+
120
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
121
+ AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
122
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
123
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
124
+ TITLE.
125
+
126
+ MariaDB hereby grants you permission to use this License’s text to license
127
+ your works, and to refer to it using the trademark “Business Source License”,
128
+ as long as you comply with the Covenants of Licensor below.
129
+
130
+ Covenants of Licensor
131
+
132
+ In consideration of the right to use this License’s text and the “Business
133
+ Source License” name and trademark, Licensor covenants to MariaDB, and to all
134
+ other recipients of the licensed work to be provided by Licensor:
135
+
136
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
137
+ or a license that is compatible with GPL Version 2.0 or a later version,
138
+ where “compatible” means that software provided under the Change License can
139
+ be included in a program with software provided under GPL Version 2.0 or a
140
+ later version. Licensor may specify additional Change Licenses without
141
+ limitation.
142
+
143
+ 2. To either: (a) specify an additional grant of rights to use that does not
144
+ impose any additional restriction on the right granted in this License, as
145
+ the Additional Use Grant; or (b) insert the text “None”.
146
+
147
+ 3. To specify a Change Date.
148
+
149
+ 4. Not to modify this License in any other way.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Po Approval
2
+
3
+ Asks the person before a tool or code-mode method that declares approval runs in a Po session.
4
+
5
+ ## What it binds
6
+
7
+ The session service `po/approval` (`PO_APPROVAL_CONTRACT` from `@agimon-ai/po-core/approval`). Po core's gate calls it for any
8
+ direct tool or code-mode namespace member that declares `approval: { requirement, describe }`. Without this package
9
+ bound, `ask` calls run without asking and `human` calls are refused.
10
+
11
+ ## How a call is asked
12
+
13
+ Each gated call opens one Approve/Deny dialog on the session's client. The dialog carries the bounded text the package's
14
+ `describe` returned (title, summary, up to 12 details), never the call's arguments. The decision is:
15
+
16
+ - `approved`: only from an explicit Approve that arrives before the call is aborted or its deadline passes.
17
+ - `denied`: the person chose Deny. The agent is told not to retry unless asked.
18
+ - `cancelled`: dismissed, aborted, expired, or the session or server closed while waiting.
19
+
20
+ Only `approved` runs the call, once. A restart cancels every pending approval; nothing is replayed.
21
+
22
+ ## Where nobody can answer
23
+
24
+ The host sets `interaction: 'unattended'` for workflow and new calendar-created sessions. Subagents and background `exec`
25
+ scripts are always unattended, even if their session is interactive. `ask` calls run there without asking; `human` calls
26
+ are hidden or refused before this service is reached. The field survives restart and host/container handoff.
27
+
28
+ Absent `interaction` means interactive. Provenance labels stay opaque, and tool arguments cannot change presence.
29
+
30
+ ## Limits
31
+
32
+ `ask` is a courtesy, not a security boundary: it is skipped where nobody can answer. Pi tools, Bash and raw code are not
33
+ gated.
@@ -0,0 +1,53 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ let _agimon_ai_po_core_apiContracts = require("@agimon-ai/po-core/apiContracts");
6
+ let _agimon_ai_po_core_approval = require("@agimon-ai/po-core/approval");
7
+ let typebox = require("typebox");
8
+ //#region src/schemas/apiContracts.ts
9
+ const VoiceApprovalAnswerSchema = typebox.Type.Object({
10
+ approvalId: typebox.Type.String({
11
+ minLength: 1,
12
+ maxLength: 200
13
+ }),
14
+ decision: typebox.Type.Union([typebox.Type.Literal("approved"), typebox.Type.Literal("denied")]),
15
+ channel: typebox.Type.Literal("voice")
16
+ });
17
+ const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
18
+ version: 1,
19
+ http: [{
20
+ id: "approval.current",
21
+ scope: "session",
22
+ basePath: "approval",
23
+ path: "/current",
24
+ method: "GET",
25
+ authentication: "owner",
26
+ description: "Read the visible head approval, or null when another dialog is at the head.",
27
+ responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(typebox.Type.Union([_agimon_ai_po_core_approval.PoApprovalPromptSchema, typebox.Type.Null()]))
28
+ }, {
29
+ id: "approval.answer",
30
+ scope: "session",
31
+ basePath: "approval",
32
+ path: "/current",
33
+ method: "POST",
34
+ authentication: "owner",
35
+ description: "Answer the current ask approval through Voice. Human approvals are app-only.",
36
+ body: {
37
+ required: true,
38
+ contentType: "application/json",
39
+ schema: VoiceApprovalAnswerSchema
40
+ },
41
+ responses: {
42
+ ...(0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(typebox.Type.Object({ answered: typebox.Type.Boolean() })),
43
+ "400": { description: "Invalid approval answer." }
44
+ }
45
+ }],
46
+ sockets: [],
47
+ dynamic: []
48
+ });
49
+ //#endregion
50
+ exports.apiContracts = apiContracts;
51
+ exports.default = apiContracts;
52
+
53
+ //# sourceMappingURL=apiContracts.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiContracts.cjs","names":["Type","defineApiContract","jsonApiResponses","PoApprovalPromptSchema"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { PoApprovalPromptSchema } from '@agimon-ai/po-core/approval';\nimport { Type } from 'typebox';\n\nexport const VoiceApprovalAnswerSchema = Type.Object({\n approvalId: Type.String({ minLength: 1, maxLength: 200 }),\n decision: Type.Union([Type.Literal('approved'), Type.Literal('denied')]),\n channel: Type.Literal('voice'),\n});\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http: [\n {\n id: 'approval.current',\n scope: 'session',\n basePath: 'approval',\n path: '/current',\n method: 'GET',\n authentication: 'owner',\n description: 'Read the visible head approval, or null when another dialog is at the head.',\n responses: jsonApiResponses(Type.Union([PoApprovalPromptSchema, Type.Null()])),\n },\n {\n id: 'approval.answer',\n scope: 'session',\n basePath: 'approval',\n path: '/current',\n method: 'POST',\n authentication: 'owner',\n description: 'Answer the current ask approval through Voice. Human approvals are app-only.',\n body: { required: true, contentType: 'application/json', schema: VoiceApprovalAnswerSchema },\n responses: {\n ...jsonApiResponses(Type.Object({ answered: Type.Boolean() })),\n '400': { description: 'Invalid approval answer.' },\n },\n },\n ],\n sockets: [],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;;AAIA,MAAa,4BAA4BA,QAAAA,KAAK,OAAO;CACnD,YAAYA,QAAAA,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC;CACxD,UAAUA,QAAAA,KAAK,MAAM,CAACA,QAAAA,KAAK,QAAQ,UAAU,GAAGA,QAAAA,KAAK,QAAQ,QAAQ,CAAC,CAAC;CACvE,SAASA,QAAAA,KAAK,QAAQ,OAAO;AAC/B,CAAC;AAED,MAAa,gBAAA,GAAeC,gCAAAA,kBAAAA,CAAkB;CAC5C,SAAS;CACT,MAAM,CACJ;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiBF,QAAAA,KAAK,MAAM,CAACG,4BAAAA,wBAAwBH,QAAAA,KAAK,KAAK,CAAC,CAAC,CAAC;CAC/E,GACA;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,MAAM;GAAE,UAAU;GAAM,aAAa;GAAoB,QAAQ;EAA0B;EAC3F,WAAW;GACT,IAAA,GAAGE,gCAAAA,iBAAAA,CAAiBF,QAAAA,KAAK,OAAO,EAAE,UAAUA,QAAAA,KAAK,QAAQ,EAAE,CAAC,CAAC;GAC7D,OAAO,EAAE,aAAa,2BAA2B;EACnD;CACF,CACF;CACA,SAAS,CAAC;CACV,SAAS,CAAC;AACZ,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { Type } from "typebox";
2
+ //#region src/schemas/apiContracts.d.ts
3
+ export declare const apiContracts: {
4
+ version: 1;
5
+ protocols?: Record<string, string> | undefined;
6
+ schemas?: Record<string, boolean | object> | undefined;
7
+ http: {
8
+ id: string;
9
+ scope: "global" | "session" | "workspace";
10
+ basePath?: string | undefined;
11
+ path: string;
12
+ method: "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT";
13
+ description: string;
14
+ availability?: string | undefined;
15
+ authentication: "device" | "none" | "owner";
16
+ parameters?: {
17
+ name: string;
18
+ in: "header" | "path" | "query";
19
+ required: boolean;
20
+ schema: boolean | object;
21
+ }[] | undefined;
22
+ body?: {
23
+ contentType: string;
24
+ contentTypes?: string[] | undefined;
25
+ required: boolean;
26
+ schema: boolean | object;
27
+ } | undefined;
28
+ responses: Record<string, {
29
+ description: string;
30
+ contentType?: string | undefined;
31
+ schema?: boolean | object | undefined;
32
+ events?: Record<string, boolean | object> | undefined;
33
+ }>;
34
+ }[];
35
+ sockets: {
36
+ id: string;
37
+ scope: "global" | "session" | "workspace";
38
+ description: string;
39
+ availability?: string | undefined;
40
+ service: string;
41
+ member: string;
42
+ direction: "client-to-server" | "server-to-client";
43
+ kind: "channel" | "method" | "state";
44
+ input: boolean | object;
45
+ output?: boolean | object | undefined;
46
+ errors?: boolean | object | undefined;
47
+ }[];
48
+ dynamic: string[];
49
+ gaps?: string[] | undefined;
50
+ };
51
+ //#endregion
52
+ export { apiContracts as default };
53
+ //# sourceMappingURL=apiContracts.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiContracts.d.mts","names":[],"sources":["../src/schemas/apiContracts.ts"],"mappings":";;qBAUa"}
@@ -0,0 +1,48 @@
1
+ import { defineApiContract, jsonApiResponses } from "@agimon-ai/po-core/apiContracts";
2
+ import { PoApprovalPromptSchema } from "@agimon-ai/po-core/approval";
3
+ import { Type } from "typebox";
4
+ //#region src/schemas/apiContracts.ts
5
+ const VoiceApprovalAnswerSchema = Type.Object({
6
+ approvalId: Type.String({
7
+ minLength: 1,
8
+ maxLength: 200
9
+ }),
10
+ decision: Type.Union([Type.Literal("approved"), Type.Literal("denied")]),
11
+ channel: Type.Literal("voice")
12
+ });
13
+ const apiContracts = defineApiContract({
14
+ version: 1,
15
+ http: [{
16
+ id: "approval.current",
17
+ scope: "session",
18
+ basePath: "approval",
19
+ path: "/current",
20
+ method: "GET",
21
+ authentication: "owner",
22
+ description: "Read the visible head approval, or null when another dialog is at the head.",
23
+ responses: jsonApiResponses(Type.Union([PoApprovalPromptSchema, Type.Null()]))
24
+ }, {
25
+ id: "approval.answer",
26
+ scope: "session",
27
+ basePath: "approval",
28
+ path: "/current",
29
+ method: "POST",
30
+ authentication: "owner",
31
+ description: "Answer the current ask approval through Voice. Human approvals are app-only.",
32
+ body: {
33
+ required: true,
34
+ contentType: "application/json",
35
+ schema: VoiceApprovalAnswerSchema
36
+ },
37
+ responses: {
38
+ ...jsonApiResponses(Type.Object({ answered: Type.Boolean() })),
39
+ "400": { description: "Invalid approval answer." }
40
+ }
41
+ }],
42
+ sockets: [],
43
+ dynamic: []
44
+ });
45
+ //#endregion
46
+ export { apiContracts, apiContracts as default };
47
+
48
+ //# sourceMappingURL=apiContracts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { PoApprovalPromptSchema } from '@agimon-ai/po-core/approval';\nimport { Type } from 'typebox';\n\nexport const VoiceApprovalAnswerSchema = Type.Object({\n approvalId: Type.String({ minLength: 1, maxLength: 200 }),\n decision: Type.Union([Type.Literal('approved'), Type.Literal('denied')]),\n channel: Type.Literal('voice'),\n});\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http: [\n {\n id: 'approval.current',\n scope: 'session',\n basePath: 'approval',\n path: '/current',\n method: 'GET',\n authentication: 'owner',\n description: 'Read the visible head approval, or null when another dialog is at the head.',\n responses: jsonApiResponses(Type.Union([PoApprovalPromptSchema, Type.Null()])),\n },\n {\n id: 'approval.answer',\n scope: 'session',\n basePath: 'approval',\n path: '/current',\n method: 'POST',\n authentication: 'owner',\n description: 'Answer the current ask approval through Voice. Human approvals are app-only.',\n body: { required: true, contentType: 'application/json', schema: VoiceApprovalAnswerSchema },\n responses: {\n ...jsonApiResponses(Type.Object({ answered: Type.Boolean() })),\n '400': { description: 'Invalid approval answer.' },\n },\n },\n ],\n sockets: [],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;;AAIA,MAAa,4BAA4B,KAAK,OAAO;CACnD,YAAY,KAAK,OAAO;EAAE,WAAW;EAAG,WAAW;CAAI,CAAC;CACxD,UAAU,KAAK,MAAM,CAAC,KAAK,QAAQ,UAAU,GAAG,KAAK,QAAQ,QAAQ,CAAC,CAAC;CACvE,SAAS,KAAK,QAAQ,OAAO;AAC/B,CAAC;AAED,MAAa,eAAe,kBAAkB;CAC5C,SAAS;CACT,MAAM,CACJ;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,WAAW,iBAAiB,KAAK,MAAM,CAAC,wBAAwB,KAAK,KAAK,CAAC,CAAC,CAAC;CAC/E,GACA;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,MAAM;GAAE,UAAU;GAAM,aAAa;GAAoB,QAAQ;EAA0B;EAC3F,WAAW;GACT,GAAG,iBAAiB,KAAK,OAAO,EAAE,UAAU,KAAK,QAAQ,EAAE,CAAC,CAAC;GAC7D,OAAO,EAAE,aAAa,2BAA2B;EACnD;CACF,CACF;CACA,SAAS,CAAC;CACV,SAAS,CAAC;AACZ,CAAC"}
@@ -0,0 +1,73 @@
1
+ //#region src/services/approvalCoordinator/index.ts
2
+ /** setTimeout fires at once past this many milliseconds, so a far expiry waits in steps no longer than it. */
3
+ const MAX_TIMER_MS = 2147483647;
4
+ /** The options of every approval dialog. Clients match the labels; the values come back as the decision. */
5
+ const APPROVAL_OPTIONS = Object.freeze([Object.freeze({
6
+ label: "Approve",
7
+ value: "approved"
8
+ }), Object.freeze({
9
+ label: "Deny",
10
+ value: "denied"
11
+ })]);
12
+ /**
13
+ * Asks the person through the session's dialog channel: one Approve/Deny `select` per call, carrying the bounded
14
+ * approval card and never the call's arguments. Resolves `approved` only from an explicit Approve that arrived before
15
+ * abort or expiry; everything else, including a closed client, is `cancelled` or `denied`, so nothing runs.
16
+ */
17
+ function createApprovalCoordinator(client) {
18
+ return { async request(request) {
19
+ const target = client();
20
+ const remaining = request.expiresAt === void 0 ? void 0 : request.expiresAt - Date.now();
21
+ if (target === void 0 || request.signal?.aborted === true || remaining !== void 0 && remaining <= 0) return "cancelled";
22
+ const expiry = new AbortController();
23
+ let timer;
24
+ const wait = () => {
25
+ const left = (request.expiresAt ?? 0) - Date.now();
26
+ timer = left <= 0 ? void 0 : setTimeout(wait, Math.min(left, MAX_TIMER_MS));
27
+ if (left <= 0) expiry.abort();
28
+ };
29
+ if (remaining !== void 0) wait();
30
+ const signal = request.signal === void 0 ? expiry.signal : AbortSignal.any([request.signal, expiry.signal]);
31
+ const { title, summary, details } = request.description;
32
+ const approval = {
33
+ id: crypto.randomUUID(),
34
+ toolCallId: request.toolCallId,
35
+ operation: request.operation,
36
+ requirement: request.requirement,
37
+ title,
38
+ summary,
39
+ ...details === void 0 ? {} : { details },
40
+ ...request.expiresAt === void 0 ? {} : { expiresAt: request.expiresAt }
41
+ };
42
+ try {
43
+ const answer = await target.request({
44
+ kind: "select",
45
+ title,
46
+ message: summary,
47
+ options: APPROVAL_OPTIONS,
48
+ approval
49
+ }, signal);
50
+ if (signal.aborted) return "cancelled";
51
+ return answer === "approved" || answer === "denied" ? answer : "cancelled";
52
+ } catch {
53
+ return "cancelled";
54
+ } finally {
55
+ clearTimeout(timer);
56
+ }
57
+ } };
58
+ }
59
+ //#endregion
60
+ Object.defineProperty(exports, "APPROVAL_OPTIONS", {
61
+ enumerable: true,
62
+ get: function() {
63
+ return APPROVAL_OPTIONS;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "createApprovalCoordinator", {
67
+ enumerable: true,
68
+ get: function() {
69
+ return createApprovalCoordinator;
70
+ }
71
+ });
72
+
73
+ //# sourceMappingURL=approvalCoordinator-Be6utzFg.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approvalCoordinator-Be6utzFg.cjs","names":[],"sources":["../src/services/approvalCoordinator/index.ts"],"sourcesContent":["import type {\n PoApprovalDecision,\n PoApprovalPrompt,\n PoApprovalRequest,\n PoApprovalService,\n} from '@agimon-ai/po-core/approval';\nimport type { PoHeadlessClient } from '@agimon-ai/po-core/headless';\n\n/** setTimeout fires at once past this many milliseconds, so a far expiry waits in steps no longer than it. */\nconst MAX_TIMER_MS = 2_147_483_647;\n\n/** The options of every approval dialog. Clients match the labels; the values come back as the decision. */\nexport const APPROVAL_OPTIONS = Object.freeze([\n Object.freeze({ label: 'Approve', value: 'approved' }),\n Object.freeze({ label: 'Deny', value: 'denied' }),\n]);\n\n/**\n * Asks the person through the session's dialog channel: one Approve/Deny `select` per call, carrying the bounded\n * approval card and never the call's arguments. Resolves `approved` only from an explicit Approve that arrived before\n * abort or expiry; everything else, including a closed client, is `cancelled` or `denied`, so nothing runs.\n */\nexport function createApprovalCoordinator(client: () => PoHeadlessClient | undefined): PoApprovalService {\n return {\n async request(request: PoApprovalRequest): Promise<PoApprovalDecision> {\n const target = client();\n const remaining = request.expiresAt === undefined ? undefined : request.expiresAt - Date.now();\n if (target === undefined || request.signal?.aborted === true || (remaining !== undefined && remaining <= 0))\n return 'cancelled';\n const expiry = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const wait = (): void => {\n const left = (request.expiresAt ?? 0) - Date.now();\n timer = left <= 0 ? undefined : setTimeout(wait, Math.min(left, MAX_TIMER_MS));\n if (left <= 0) expiry.abort();\n };\n if (remaining !== undefined) wait();\n const signal = request.signal === undefined ? expiry.signal : AbortSignal.any([request.signal, expiry.signal]);\n const { title, summary, details } = request.description;\n const approval: PoApprovalPrompt = {\n id: crypto.randomUUID(),\n toolCallId: request.toolCallId,\n operation: request.operation,\n requirement: request.requirement,\n title,\n summary,\n ...(details === undefined ? {} : { details }),\n ...(request.expiresAt === undefined ? {} : { expiresAt: request.expiresAt }),\n };\n try {\n const answer = await target.request(\n { kind: 'select', title, message: summary, options: APPROVAL_OPTIONS, approval },\n signal,\n );\n if (signal.aborted) return 'cancelled';\n return answer === 'approved' || answer === 'denied' ? answer : 'cancelled';\n } catch {\n // A closed client (the session or server ended) or a refused envelope: nobody approved, so nothing runs.\n return 'cancelled';\n } finally {\n clearTimeout(timer);\n }\n },\n };\n}\n"],"mappings":";;AASA,MAAM,eAAe;;AAGrB,MAAa,mBAAmB,OAAO,OAAO,CAC5C,OAAO,OAAO;CAAE,OAAO;CAAW,OAAO;AAAW,CAAC,GACrD,OAAO,OAAO;CAAE,OAAO;CAAQ,OAAO;AAAS,CAAC,CAClD,CAAC;;;;;;AAOD,SAAgB,0BAA0B,QAA+D;CACvG,OAAO,EACL,MAAM,QAAQ,SAAyD;EACrE,MAAM,SAAS,OAAO;EACtB,MAAM,YAAY,QAAQ,cAAc,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,KAAK,IAAI;EAC7F,IAAI,WAAW,KAAA,KAAa,QAAQ,QAAQ,YAAY,QAAS,cAAc,KAAA,KAAa,aAAa,GACvG,OAAO;EACT,MAAM,SAAS,IAAI,gBAAgB;EACnC,IAAI;EACJ,MAAM,aAAmB;GACvB,MAAM,QAAQ,QAAQ,aAAa,KAAK,KAAK,IAAI;GACjD,QAAQ,QAAQ,IAAI,KAAA,IAAY,WAAW,MAAM,KAAK,IAAI,MAAM,YAAY,CAAC;GAC7E,IAAI,QAAQ,GAAG,OAAO,MAAM;EAC9B;EACA,IAAI,cAAc,KAAA,GAAW,KAAK;EAClC,MAAM,SAAS,QAAQ,WAAW,KAAA,IAAY,OAAO,SAAS,YAAY,IAAI,CAAC,QAAQ,QAAQ,OAAO,MAAM,CAAC;EAC7G,MAAM,EAAE,OAAO,SAAS,YAAY,QAAQ;EAC5C,MAAM,WAA6B;GACjC,IAAI,OAAO,WAAW;GACtB,YAAY,QAAQ;GACpB,WAAW,QAAQ;GACnB,aAAa,QAAQ;GACrB;GACA;GACA,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;GAC3C,GAAI,QAAQ,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW,QAAQ,UAAU;EAC5E;EACA,IAAI;GACF,MAAM,SAAS,MAAM,OAAO,QAC1B;IAAE,MAAM;IAAU;IAAO,SAAS;IAAS,SAAS;IAAkB;GAAS,GAC/E,MACF;GACA,IAAI,OAAO,SAAS,OAAO;GAC3B,OAAO,WAAW,cAAc,WAAW,WAAW,SAAS;EACjE,QAAQ;GAEN,OAAO;EACT,UAAU;GACR,aAAa,KAAK;EACpB;CACF,EACF;AACF"}
@@ -0,0 +1,62 @@
1
+ //#region src/services/approvalCoordinator/index.ts
2
+ /** setTimeout fires at once past this many milliseconds, so a far expiry waits in steps no longer than it. */
3
+ const MAX_TIMER_MS = 2147483647;
4
+ /** The options of every approval dialog. Clients match the labels; the values come back as the decision. */
5
+ const APPROVAL_OPTIONS = Object.freeze([Object.freeze({
6
+ label: "Approve",
7
+ value: "approved"
8
+ }), Object.freeze({
9
+ label: "Deny",
10
+ value: "denied"
11
+ })]);
12
+ /**
13
+ * Asks the person through the session's dialog channel: one Approve/Deny `select` per call, carrying the bounded
14
+ * approval card and never the call's arguments. Resolves `approved` only from an explicit Approve that arrived before
15
+ * abort or expiry; everything else, including a closed client, is `cancelled` or `denied`, so nothing runs.
16
+ */
17
+ function createApprovalCoordinator(client) {
18
+ return { async request(request) {
19
+ const target = client();
20
+ const remaining = request.expiresAt === void 0 ? void 0 : request.expiresAt - Date.now();
21
+ if (target === void 0 || request.signal?.aborted === true || remaining !== void 0 && remaining <= 0) return "cancelled";
22
+ const expiry = new AbortController();
23
+ let timer;
24
+ const wait = () => {
25
+ const left = (request.expiresAt ?? 0) - Date.now();
26
+ timer = left <= 0 ? void 0 : setTimeout(wait, Math.min(left, MAX_TIMER_MS));
27
+ if (left <= 0) expiry.abort();
28
+ };
29
+ if (remaining !== void 0) wait();
30
+ const signal = request.signal === void 0 ? expiry.signal : AbortSignal.any([request.signal, expiry.signal]);
31
+ const { title, summary, details } = request.description;
32
+ const approval = {
33
+ id: crypto.randomUUID(),
34
+ toolCallId: request.toolCallId,
35
+ operation: request.operation,
36
+ requirement: request.requirement,
37
+ title,
38
+ summary,
39
+ ...details === void 0 ? {} : { details },
40
+ ...request.expiresAt === void 0 ? {} : { expiresAt: request.expiresAt }
41
+ };
42
+ try {
43
+ const answer = await target.request({
44
+ kind: "select",
45
+ title,
46
+ message: summary,
47
+ options: APPROVAL_OPTIONS,
48
+ approval
49
+ }, signal);
50
+ if (signal.aborted) return "cancelled";
51
+ return answer === "approved" || answer === "denied" ? answer : "cancelled";
52
+ } catch {
53
+ return "cancelled";
54
+ } finally {
55
+ clearTimeout(timer);
56
+ }
57
+ } };
58
+ }
59
+ //#endregion
60
+ export { createApprovalCoordinator as n, APPROVAL_OPTIONS as t };
61
+
62
+ //# sourceMappingURL=approvalCoordinator-CRbOm-PY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approvalCoordinator-CRbOm-PY.mjs","names":[],"sources":["../src/services/approvalCoordinator/index.ts"],"sourcesContent":["import type {\n PoApprovalDecision,\n PoApprovalPrompt,\n PoApprovalRequest,\n PoApprovalService,\n} from '@agimon-ai/po-core/approval';\nimport type { PoHeadlessClient } from '@agimon-ai/po-core/headless';\n\n/** setTimeout fires at once past this many milliseconds, so a far expiry waits in steps no longer than it. */\nconst MAX_TIMER_MS = 2_147_483_647;\n\n/** The options of every approval dialog. Clients match the labels; the values come back as the decision. */\nexport const APPROVAL_OPTIONS = Object.freeze([\n Object.freeze({ label: 'Approve', value: 'approved' }),\n Object.freeze({ label: 'Deny', value: 'denied' }),\n]);\n\n/**\n * Asks the person through the session's dialog channel: one Approve/Deny `select` per call, carrying the bounded\n * approval card and never the call's arguments. Resolves `approved` only from an explicit Approve that arrived before\n * abort or expiry; everything else, including a closed client, is `cancelled` or `denied`, so nothing runs.\n */\nexport function createApprovalCoordinator(client: () => PoHeadlessClient | undefined): PoApprovalService {\n return {\n async request(request: PoApprovalRequest): Promise<PoApprovalDecision> {\n const target = client();\n const remaining = request.expiresAt === undefined ? undefined : request.expiresAt - Date.now();\n if (target === undefined || request.signal?.aborted === true || (remaining !== undefined && remaining <= 0))\n return 'cancelled';\n const expiry = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const wait = (): void => {\n const left = (request.expiresAt ?? 0) - Date.now();\n timer = left <= 0 ? undefined : setTimeout(wait, Math.min(left, MAX_TIMER_MS));\n if (left <= 0) expiry.abort();\n };\n if (remaining !== undefined) wait();\n const signal = request.signal === undefined ? expiry.signal : AbortSignal.any([request.signal, expiry.signal]);\n const { title, summary, details } = request.description;\n const approval: PoApprovalPrompt = {\n id: crypto.randomUUID(),\n toolCallId: request.toolCallId,\n operation: request.operation,\n requirement: request.requirement,\n title,\n summary,\n ...(details === undefined ? {} : { details }),\n ...(request.expiresAt === undefined ? {} : { expiresAt: request.expiresAt }),\n };\n try {\n const answer = await target.request(\n { kind: 'select', title, message: summary, options: APPROVAL_OPTIONS, approval },\n signal,\n );\n if (signal.aborted) return 'cancelled';\n return answer === 'approved' || answer === 'denied' ? answer : 'cancelled';\n } catch {\n // A closed client (the session or server ended) or a refused envelope: nobody approved, so nothing runs.\n return 'cancelled';\n } finally {\n clearTimeout(timer);\n }\n },\n };\n}\n"],"mappings":";;AASA,MAAM,eAAe;;AAGrB,MAAa,mBAAmB,OAAO,OAAO,CAC5C,OAAO,OAAO;CAAE,OAAO;CAAW,OAAO;AAAW,CAAC,GACrD,OAAO,OAAO;CAAE,OAAO;CAAQ,OAAO;AAAS,CAAC,CAClD,CAAC;;;;;;AAOD,SAAgB,0BAA0B,QAA+D;CACvG,OAAO,EACL,MAAM,QAAQ,SAAyD;EACrE,MAAM,SAAS,OAAO;EACtB,MAAM,YAAY,QAAQ,cAAc,KAAA,IAAY,KAAA,IAAY,QAAQ,YAAY,KAAK,IAAI;EAC7F,IAAI,WAAW,KAAA,KAAa,QAAQ,QAAQ,YAAY,QAAS,cAAc,KAAA,KAAa,aAAa,GACvG,OAAO;EACT,MAAM,SAAS,IAAI,gBAAgB;EACnC,IAAI;EACJ,MAAM,aAAmB;GACvB,MAAM,QAAQ,QAAQ,aAAa,KAAK,KAAK,IAAI;GACjD,QAAQ,QAAQ,IAAI,KAAA,IAAY,WAAW,MAAM,KAAK,IAAI,MAAM,YAAY,CAAC;GAC7E,IAAI,QAAQ,GAAG,OAAO,MAAM;EAC9B;EACA,IAAI,cAAc,KAAA,GAAW,KAAK;EAClC,MAAM,SAAS,QAAQ,WAAW,KAAA,IAAY,OAAO,SAAS,YAAY,IAAI,CAAC,QAAQ,QAAQ,OAAO,MAAM,CAAC;EAC7G,MAAM,EAAE,OAAO,SAAS,YAAY,QAAQ;EAC5C,MAAM,WAA6B;GACjC,IAAI,OAAO,WAAW;GACtB,YAAY,QAAQ;GACpB,WAAW,QAAQ;GACnB,aAAa,QAAQ;GACrB;GACA;GACA,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;GAC3C,GAAI,QAAQ,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW,QAAQ,UAAU;EAC5E;EACA,IAAI;GACF,MAAM,SAAS,MAAM,OAAO,QAC1B;IAAE,MAAM;IAAU;IAAO,SAAS;IAAS,SAAS;IAAkB;GAAS,GAC/E,MACF;GACA,IAAI,OAAO,SAAS,OAAO;GAC3B,OAAO,WAAW,cAAc,WAAW,WAAW,SAAS;EACjE,QAAQ;GAEN,OAAO;EACT,UAAU;GACR,aAAa,KAAK;EACpB;CACF,EACF;AACF"}