@pliuz/sdk 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/CHANGELOG.md +46 -0
- package/LICENSE +201 -0
- package/README.md +332 -0
- package/dist/adapters/ai.cjs +578 -0
- package/dist/adapters/ai.cjs.map +1 -0
- package/dist/adapters/ai.d.cts +74 -0
- package/dist/adapters/ai.d.ts +74 -0
- package/dist/adapters/ai.js +575 -0
- package/dist/adapters/ai.js.map +1 -0
- package/dist/client-BABvN_88.d.cts +153 -0
- package/dist/client-BABvN_88.d.ts +153 -0
- package/dist/index.cjs +561 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +179 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +532 -0
- package/dist/index.js.map +1 -0
- package/examples/basic.ts +70 -0
- package/examples/gated-basic.ts +62 -0
- package/examples/vercel-ai-agent.ts +65 -0
- package/package.json +91 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@pliuz/sdk` (TypeScript SDK) are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] — 2026-05-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`gated(options, fn)`** — the headline wrapper. Pauses any function for
|
|
13
|
+
human approval via Pliuz before executing. Always returns
|
|
14
|
+
`Promise<TResult>`. Auto-generates deterministic idempotency keys.
|
|
15
|
+
- **`PliuzClient`** — low-level client for the 3 SDK-facing endpoints
|
|
16
|
+
(`POST /approvals`, `GET /:id`, `POST /:id/execution`). Uses native
|
|
17
|
+
`fetch` + `AbortController`. Configurable retries, timeouts, custom
|
|
18
|
+
fetch injection for testing.
|
|
19
|
+
- **`applyRedaction(payload, paths)`** — client-side field redaction with
|
|
20
|
+
dotted-path + `[*]` array-wildcard syntax. Sensitive fields never
|
|
21
|
+
leave the caller's process plaintext.
|
|
22
|
+
- **Typed error hierarchy** — `PliuzError` base + 12 specific subclasses
|
|
23
|
+
(`PliuzAuthError`, `PliuzPolicyError`, `PliuzRejectedError`,
|
|
24
|
+
`PliuzApprovalExpiredError`, `PliuzApprovalTimeoutError`, etc.).
|
|
25
|
+
Each preserves `instanceof` correctness across ESM and CJS targets.
|
|
26
|
+
- **`gatedTool()`** (Vercel AI SDK adapter, optional) — wraps `tool({...})`
|
|
27
|
+
from `ai` so any Vercel AI agent can gate execution. Surfaces input
|
|
28
|
+
dict directly as Pliuz `tool_args` for clean audit logs.
|
|
29
|
+
- **Dual ESM/CJS output** via tsup, with `.d.ts` + `.d.cts` for both.
|
|
30
|
+
- **Cross-language idempotency** — same algorithm as the Python SDK,
|
|
31
|
+
so a call from Python and TS with same args produces the same key.
|
|
32
|
+
- **49 unit/contract/retry tests + 3 integration tests**.
|
|
33
|
+
|
|
34
|
+
### Requirements
|
|
35
|
+
|
|
36
|
+
- Node ≥ 18.17 (uses native `fetch` + `AbortController`)
|
|
37
|
+
- Optional peer: `ai >= 4.0` for the Vercel AI SDK adapter
|
|
38
|
+
|
|
39
|
+
### Stability
|
|
40
|
+
|
|
41
|
+
- `gated`, `PliuzClient`, `errors.*` — stable across 0.x patches
|
|
42
|
+
- `adapters/*` — experimental, may shift before 1.0
|
|
43
|
+
|
|
44
|
+
## [0.0.1] — 2026-05-21
|
|
45
|
+
|
|
46
|
+
Placeholder release — reserved the `@pliuz/sdk` name on npm. Not functional.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed" page as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Pliuz
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# @pliuz/sdk — TypeScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@pliuz/sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/@pliuz/sdk)
|
|
5
|
+
[](https://github.com/mwhitex/pliuz/blob/main/sdk-typescript/LICENSE)
|
|
6
|
+
|
|
7
|
+
> **Human-in-the-loop approval gates for AI agents.** Wrap any function in `gated()` to pause execution, route the call to a human approver via Pliuz, then resume — or abort — based on the decision. Every call is audited.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { gated } from '@pliuz/sdk'
|
|
11
|
+
|
|
12
|
+
const issueRefund = gated(
|
|
13
|
+
{
|
|
14
|
+
policy: 'refund',
|
|
15
|
+
redact: ['customer.ssn'],
|
|
16
|
+
toolArgs: (customerId: string, amountCents: number) => ({
|
|
17
|
+
customer_id: customerId,
|
|
18
|
+
amount_cents: amountCents,
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
async (customerId: string, amountCents: number) => {
|
|
22
|
+
return stripe.refunds.create({ customer: customerId, amount: amountCents })
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// Pauses. A human gets a Slack card. They click approve.
|
|
27
|
+
// Then your code runs — and Pliuz records the outcome.
|
|
28
|
+
const result = await issueRefund('cus_123', 5000)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @pliuz/sdk
|
|
37
|
+
# or, with the Vercel AI SDK adapter
|
|
38
|
+
npm install @pliuz/sdk ai
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Requires Node ≥ 18.17 (uses native `fetch` + `AbortController`).
|
|
42
|
+
|
|
43
|
+
## Quickstart
|
|
44
|
+
|
|
45
|
+
### 1. Get an API key
|
|
46
|
+
|
|
47
|
+
Sign up at [pliuz.dev](https://pliuz.dev), create an agent in the dashboard, copy the key.
|
|
48
|
+
|
|
49
|
+
### 2. Set the env var
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
export PLIUZ_API_KEY=pli_live_...
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 3. Gate a function
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { gated } from '@pliuz/sdk'
|
|
59
|
+
|
|
60
|
+
const runSql = gated(
|
|
61
|
+
{ policy: 'risky_query' },
|
|
62
|
+
async (query: string) => db.execute(query),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
// Blocks until a human approves (or rejects, or it expires).
|
|
66
|
+
const rows = await runSql("DELETE FROM users WHERE created_at < '2024-01-01'")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
That's it. Pliuz handles the rest: idempotency, retries, audit logging, hash-chained event log.
|
|
70
|
+
|
|
71
|
+
## What `gated()` does
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
yourFn(...args) yourFn(...args)
|
|
75
|
+
│ │
|
|
76
|
+
▼ ▼
|
|
77
|
+
┌──────────┐ POST /approvals ┌──────────┐
|
|
78
|
+
│ gated │ ───────────────► ┌─────────────┐ │ gated │
|
|
79
|
+
│ wrapper │ │ Pliuz API │ │ wrapper │
|
|
80
|
+
│ │ ◄─────────────── └─────────────┘ │ │
|
|
81
|
+
└──────────┘ status=pending ▲ └──────────┘
|
|
82
|
+
│ │ │
|
|
83
|
+
│ poll every 2s │ ▼
|
|
84
|
+
│ ────────────────────────────────► humans ┌──────────┐
|
|
85
|
+
▼ │ │ original │
|
|
86
|
+
┌──────────┐ status=approved │ │ fn() │
|
|
87
|
+
│ execute │ ◄──────────────────────────┘ └──────────┘
|
|
88
|
+
│ original │ │
|
|
89
|
+
│ fn() │ POST /:id/execution ▼
|
|
90
|
+
└──────────┘ ─────────────────────────► audit log
|
|
91
|
+
│
|
|
92
|
+
▼
|
|
93
|
+
result
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Features
|
|
97
|
+
|
|
98
|
+
- **Zero dependencies** — uses native `fetch` + `AbortController`
|
|
99
|
+
- **Dual ESM/CJS** — works in any modern Node project
|
|
100
|
+
- **First-class TypeScript** — fully typed, including narrow error subclasses
|
|
101
|
+
- **Idempotency** via deterministic key hashing — safe to retry from anywhere
|
|
102
|
+
- **Client-side redaction** — sensitive fields never leave your process plaintext
|
|
103
|
+
- **Cancellable** via `AbortSignal` (pass `timeoutMs`)
|
|
104
|
+
- **Single-shot execution reporting** — closes the audit loop automatically
|
|
105
|
+
- **Typed errors** — `PliuzRejectedError`, `PliuzApprovalExpiredError`, `PliuzPolicyError`, etc.
|
|
106
|
+
- **Vercel AI SDK adapter** — `gatedTool()` wraps `tool({...})` from `ai` so existing AI SDK agents gate transparently
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## API
|
|
111
|
+
|
|
112
|
+
### `gated()` — the headline
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { gated } from '@pliuz/sdk'
|
|
116
|
+
|
|
117
|
+
const wrapped = gated(
|
|
118
|
+
{
|
|
119
|
+
policy: 'refund', // Pliuz policy slug (optional)
|
|
120
|
+
redact: ['customer.ssn'], // Dotted paths to strip BEFORE sending
|
|
121
|
+
timeoutMs: 300_000, // Max polling duration (5 min default)
|
|
122
|
+
pollIntervalMs: 2000, // Time between status checks
|
|
123
|
+
toolName: 'custom_name', // Override fn.name
|
|
124
|
+
toolArgs: (...args) => ({ ... }), // Map positional args → tool_args object
|
|
125
|
+
client: pliuz, // Reuse a client (default: lazy from env)
|
|
126
|
+
contextMessages: ['extra info for the human'],
|
|
127
|
+
sessionId: 'trace-abc',
|
|
128
|
+
originator: { type: 'user', id: 'user-42' },
|
|
129
|
+
},
|
|
130
|
+
async (...args) => { ... },
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Why `toolArgs`**: JS lacks named-parameter introspection. By default, all positional args go to `{ args: [...] }`. Provide a `toolArgs` mapper to get cleaner audit logs.
|
|
135
|
+
|
|
136
|
+
### Errors
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import {
|
|
140
|
+
PliuzError, // base
|
|
141
|
+
PliuzApiError, // any 4xx/5xx from Pliuz API
|
|
142
|
+
PliuzAuthError, // 401 — bad/missing key
|
|
143
|
+
PliuzForbiddenError, // 403 — agent mismatch
|
|
144
|
+
PliuzNotFoundError, // 404
|
|
145
|
+
PliuzConflictError, // 409 — duplicate execution report
|
|
146
|
+
PliuzValidationError, // 400 — invalid body
|
|
147
|
+
PliuzPolicyError, // 422 — no policy matched
|
|
148
|
+
PliuzRateLimitError, // 429
|
|
149
|
+
PliuzServerError, // 5xx
|
|
150
|
+
PliuzNetworkError, // connection failed
|
|
151
|
+
PliuzTimeoutError, // request timed out
|
|
152
|
+
PliuzRejectedError, // human said no
|
|
153
|
+
PliuzApprovalExpiredError, // SLA expired before human decided
|
|
154
|
+
PliuzApprovalTimeoutError, // SDK polling gave up
|
|
155
|
+
} from '@pliuz/sdk'
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
await issueRefund(...)
|
|
159
|
+
} catch (e) {
|
|
160
|
+
if (e instanceof PliuzRejectedError) {
|
|
161
|
+
console.log('Human rejected:', e.reason)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
if (e instanceof PliuzApprovalTimeoutError) {
|
|
165
|
+
// Poll later via client.getApproval(e.approvalId)
|
|
166
|
+
}
|
|
167
|
+
throw e
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Low-level client
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { PliuzClient } from '@pliuz/sdk'
|
|
175
|
+
|
|
176
|
+
const pliuz = new PliuzClient() // reads PLIUZ_API_KEY
|
|
177
|
+
|
|
178
|
+
const created = await pliuz.createApproval({
|
|
179
|
+
tool_name: 'refund',
|
|
180
|
+
tool_args: { amount: 100 },
|
|
181
|
+
idempotency_key: 'abc-123',
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
const fetched = await pliuz.getApproval(created.id)
|
|
185
|
+
|
|
186
|
+
await pliuz.reportExecution(created.id, {
|
|
187
|
+
status: 'success',
|
|
188
|
+
latency_ms: 42,
|
|
189
|
+
})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Redaction
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { applyRedaction } from '@pliuz/sdk'
|
|
196
|
+
|
|
197
|
+
const clean = applyRedaction(
|
|
198
|
+
{ customer: { ssn: '123-45-6789', id: 'cus_x' } },
|
|
199
|
+
['customer.ssn'],
|
|
200
|
+
)
|
|
201
|
+
// { customer: { ssn: '<redacted>', id: 'cus_x' } }
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Supports dotted paths and `[*]` for array wildcards:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
applyRedaction({ items: [{ card: '...' }] }, ['items[*].card'])
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Input is never mutated — returns a deep clone.
|
|
211
|
+
|
|
212
|
+
### Vercel AI SDK integration (optional)
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npm install ai
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { tool, generateText } from 'ai'
|
|
220
|
+
import { z } from 'zod'
|
|
221
|
+
import { gatedTool } from '@pliuz/sdk/adapters/ai'
|
|
222
|
+
|
|
223
|
+
const issueRefund = gatedTool(
|
|
224
|
+
{ policy: 'refund', redact: ['customer.ssn'] },
|
|
225
|
+
tool({
|
|
226
|
+
description: 'Issue a refund to a customer',
|
|
227
|
+
parameters: z.object({
|
|
228
|
+
customer_id: z.string(),
|
|
229
|
+
amount_cents: z.number().int().positive(),
|
|
230
|
+
}),
|
|
231
|
+
execute: async ({ customer_id, amount_cents }) =>
|
|
232
|
+
stripe.refunds.create({ customer: customer_id, amount: amount_cents }),
|
|
233
|
+
}),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
const { text } = await generateText({
|
|
237
|
+
model: openai('gpt-4o'),
|
|
238
|
+
tools: { issueRefund },
|
|
239
|
+
prompt: 'Refund cus_123 for $50',
|
|
240
|
+
})
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The wrapped tool preserves `description` and `parameters` — the LLM sees it identically. Only the execution path is gated.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Configuration
|
|
248
|
+
|
|
249
|
+
| Env var | Default | Purpose |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `PLIUZ_API_KEY` | _(required)_ | Per-agent API key. `pli_live_...` format. |
|
|
252
|
+
| `PLIUZ_BASE_URL` | `https://pliuz-dev.vercel.app` | Override for self-hosted or staging. |
|
|
253
|
+
|
|
254
|
+
All env vars can be passed as `PliuzClient` constructor options:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
new PliuzClient({ apiKey: 'pli_live_...', baseUrl: 'https://pliuz.mycompany.com' })
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Production tips
|
|
263
|
+
|
|
264
|
+
### Idempotency
|
|
265
|
+
|
|
266
|
+
`gated()` automatically generates a deterministic `idempotency_key` per call — same args → same key. The backend dedupes within 24 h, so safe to retry from anywhere (queues, retry loops, agent restarts).
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const refund = gated({ policy: 'refund' }, async (id: string, cents: number) => {
|
|
270
|
+
// ...
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
// Calling twice in a 24h window → only 1 approval request created.
|
|
274
|
+
// Same human decision applies to both. No duplicate refunds.
|
|
275
|
+
await refund('cus_123', 5000)
|
|
276
|
+
await refund('cus_123', 5000)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Cross-language idempotency
|
|
280
|
+
|
|
281
|
+
The idempotency hash algorithm is identical to the [Python SDK](https://pypi.org/project/pliuz/). A call from Python + a call from TypeScript with the same `tool_name`, `tool_args`, and `sessionId` produces the same key.
|
|
282
|
+
|
|
283
|
+
### Custom timeouts per call
|
|
284
|
+
|
|
285
|
+
- **Live user-facing**: `timeoutMs: 30_000`
|
|
286
|
+
- **Background jobs**: `timeoutMs: 86_400_000` (24 h)
|
|
287
|
+
- **Critical security gates**: don't use `gated()` — use a synchronous Pliuz dashboard flow
|
|
288
|
+
|
|
289
|
+
### When `gated()` rejects mid-execution
|
|
290
|
+
|
|
291
|
+
If polling exceeds `timeoutMs`, you get `PliuzApprovalTimeoutError`. **Your wrapped function never runs.** The approval may still resolve later server-side — handle the retry with `pliuz.getApproval(e.approvalId)`.
|
|
292
|
+
|
|
293
|
+
### Edge / Bun / Deno
|
|
294
|
+
|
|
295
|
+
The SDK uses only `fetch` + `AbortController` + `crypto.createHash`. Should work in any modern runtime that exposes these (Bun, Deno via `npm:` specifier, Vercel Edge, Cloudflare Workers). Not tested in CI — file an issue if you hit anything.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## Versioning
|
|
300
|
+
|
|
301
|
+
This SDK follows [SemVer](https://semver.org). The current line is `0.x.y` — minor versions may include breaking changes until `1.0.0`.
|
|
302
|
+
|
|
303
|
+
| Surface | Stability |
|
|
304
|
+
|---|---|
|
|
305
|
+
| `gated`, `PliuzClient` | Stable across 0.x patches |
|
|
306
|
+
| `errors.*` | Stable across 0.x patches |
|
|
307
|
+
| `adapters/*` | Experimental — may shift before 1.0 |
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Examples
|
|
312
|
+
|
|
313
|
+
See [`examples/`](./examples) for runnable scripts:
|
|
314
|
+
|
|
315
|
+
- [`basic.ts`](./examples/basic.ts) — bare `PliuzClient` (no wrapper)
|
|
316
|
+
- [`gated-basic.ts`](./examples/gated-basic.ts) — `gated()` happy path
|
|
317
|
+
- [`vercel-ai-agent.ts`](./examples/vercel-ai-agent.ts) — Vercel AI SDK agent with gated tools
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Links
|
|
322
|
+
|
|
323
|
+
- **Docs**: https://pliuz.dev/docs
|
|
324
|
+
- **GitHub**: https://github.com/mwhitex/pliuz
|
|
325
|
+
- **Issues**: https://github.com/mwhitex/pliuz/issues
|
|
326
|
+
- **Python SDK**: [`pliuz`](https://pypi.org/project/pliuz/)
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## License
|
|
331
|
+
|
|
332
|
+
[Apache 2.0](./LICENSE). The Pliuz platform itself is proprietary — this SDK is the public client only.
|