@duct-sdk/sdk 0.6.0 → 0.7.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 +405 -385
- package/README.md +1 -1
- package/TOKEN_SPEC.md +2 -2
- package/dist/cli/action-confusion-format.d.ts +17 -0
- package/dist/cli/action-confusion-format.js +24 -0
- package/dist/cli/cloud.d.ts +30 -1
- package/dist/cli/cloud.js +8 -0
- package/dist/cli/generators/wiring-snippets.d.ts +0 -14
- package/dist/cli/generators/wiring-snippets.js +188 -305
- package/dist/cli/mcp-setup.js +1 -9
- package/dist/cli/policy-replay-format.d.ts +9 -0
- package/dist/cli/policy-replay-format.js +46 -0
- package/dist/cli/push.js +33 -1
- package/dist/core/compile.js +2 -0
- package/dist/core/config.d.ts +74 -18
- package/dist/core/config.js +8 -0
- package/dist/core/project.d.ts +66 -0
- package/dist/core/project.js +13 -0
- package/dist/core/types.d.ts +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -374,7 +374,7 @@ Webhooks are optional; chat and actions work without them.
|
|
|
374
374
|
|
|
375
375
|
## Receipts and audit evidence
|
|
376
376
|
|
|
377
|
-
Every action Duct runs gets a signed outcome receipt
|
|
377
|
+
Every action Duct runs gets a signed outcome receipt that you or a partner can check independently. Its `receipt_id` is 32 hex characters, a hash of the receipt body, so the same id appears in your audit log:
|
|
378
378
|
|
|
379
379
|
```ts
|
|
380
380
|
import { verifyReceipt } from '@duct-sdk/sdk/server';
|
package/TOKEN_SPEC.md
CHANGED
|
@@ -19,7 +19,7 @@ Language-agnostic contract for verifying Duct tokens in any backend. This docume
|
|
|
19
19
|
| `at_` | `Authorization: Bearer at_…` | Agent access token — identifies a registered third-party agent shell |
|
|
20
20
|
| `uct_` | `X-Duct-User-Consent: uct_…` | User consent token — scoped human approval for agent side-effects |
|
|
21
21
|
| `dt_` | `Authorization: Bearer dt_…` | Delegation token — short-lived cross-shell delegated identity (single-use `jti`) |
|
|
22
|
-
| `
|
|
22
|
+
| *(32 hex)* | `receipt_id` in the API body and audit log | Outcome receipt ID — first 32 hex characters of the SHA-256 of the signed gateway receipt's body (not a JWT, no prefix) |
|
|
23
23
|
| *(none)* | Query `?token=` or `Bearer` | Deeplink JWT — handoff from shell to your receiver |
|
|
24
24
|
|
|
25
25
|
Plain delegated user tokens (`duct_delegated` JWT type) have **no prefix** — they are standard HS256 JWTs minted by your app's token route.
|
|
@@ -96,7 +96,7 @@ Short-lived cross-shell JWT. **Default TTL: 60s.** Single-use per `jti`. Verify
|
|
|
96
96
|
|
|
97
97
|
---
|
|
98
98
|
|
|
99
|
-
## Outcome receipts (
|
|
99
|
+
## Outcome receipts (signed body)
|
|
100
100
|
|
|
101
101
|
Receipts are **not JWTs**. Structure:
|
|
102
102
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ActionConfusionPair {
|
|
2
|
+
action: string;
|
|
3
|
+
confused_with: string;
|
|
4
|
+
description_similarity: number;
|
|
5
|
+
misranked?: number;
|
|
6
|
+
examples?: number;
|
|
7
|
+
rate?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ActionConfusionResult {
|
|
10
|
+
mode: "examples" | "descriptions" | "none" | "unavailable";
|
|
11
|
+
actions?: number;
|
|
12
|
+
examples_examined?: number;
|
|
13
|
+
own_action_first?: number | null;
|
|
14
|
+
pairs: ActionConfusionPair[];
|
|
15
|
+
}
|
|
16
|
+
/** Lines for the push output; empty when there is nothing worth saying. */
|
|
17
|
+
export declare function formatActionConfusion(r: ActionConfusionResult, maxRows?: number): string[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Lines for the push output; empty when there is nothing worth saying. */
|
|
2
|
+
export function formatActionConfusion(r, maxRows = 6) {
|
|
3
|
+
if (r.mode === "none" || r.mode === "unavailable" || r.pairs.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const lines = [];
|
|
6
|
+
if (r.mode === "examples") {
|
|
7
|
+
const pct = r.own_action_first != null
|
|
8
|
+
? ` (${Math.round(r.own_action_first * 100)}% of ${r.examples_examined} example requests found their own action first; the routing model then picks among the top matches)`
|
|
9
|
+
: "";
|
|
10
|
+
lines.push(`Search mixes these actions up${pct}:`);
|
|
11
|
+
for (const p of r.pairs.slice(0, maxRows)) {
|
|
12
|
+
lines.push(` ${p.action} → ${p.confused_with}: ${p.misranked} of ${p.examples} example requests for ${p.action} matched ${p.confused_with}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
lines.push("These actions read unusually alike for this shell, so requests may be routed to the wrong one:");
|
|
17
|
+
for (const p of r.pairs.slice(0, maxRows))
|
|
18
|
+
lines.push(` ${p.action} and ${p.confused_with}`);
|
|
19
|
+
}
|
|
20
|
+
if (r.pairs.length > maxRows)
|
|
21
|
+
lines.push(` …and ${r.pairs.length - maxRows} more`);
|
|
22
|
+
lines.push("Make their descriptions say how they differ (what each returns, when to use which).");
|
|
23
|
+
return lines;
|
|
24
|
+
}
|
package/dist/cli/cloud.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ActionConfusionResult } from "./action-confusion-format.js";
|
|
1
2
|
export declare const DUCT_AUTH_FILE: string;
|
|
2
3
|
export interface DuctAuth {
|
|
3
4
|
token: string;
|
|
@@ -79,6 +80,34 @@ export interface PolicyCheckResult {
|
|
|
79
80
|
source?: string;
|
|
80
81
|
}
|
|
81
82
|
export declare function checkPolicy(auth: DuctAuth | null, apiKey: string, shellId: string, config: Record<string, unknown> | undefined, cases: PolicyCheckCase[]): Promise<PolicyCheckResult[]>;
|
|
83
|
+
export interface PolicyReplayChange {
|
|
84
|
+
action: string;
|
|
85
|
+
caller: string;
|
|
86
|
+
agent: string | null;
|
|
87
|
+
with_consent: boolean;
|
|
88
|
+
calls: number;
|
|
89
|
+
before: "allow" | "approval" | "deny" | "unknown_action";
|
|
90
|
+
after: "allow" | "approval" | "deny" | "unknown_action";
|
|
91
|
+
before_reason: string;
|
|
92
|
+
after_reason: string;
|
|
93
|
+
}
|
|
94
|
+
export interface PolicyReplayResult {
|
|
95
|
+
window_days: number;
|
|
96
|
+
calls_examined: number;
|
|
97
|
+
kinds_examined: number;
|
|
98
|
+
changes: PolicyReplayChange[];
|
|
99
|
+
summary: {
|
|
100
|
+
newly_denied_calls: number;
|
|
101
|
+
newly_need_approval_calls: number;
|
|
102
|
+
newly_allowed_calls: number;
|
|
103
|
+
unchanged_calls: number;
|
|
104
|
+
};
|
|
105
|
+
parameter_rules_not_replayed: string[];
|
|
106
|
+
}
|
|
107
|
+
/** What the config about to be pushed would have done to the shell's recent real calls. */
|
|
108
|
+
export declare function checkPolicyReplay(auth: DuctAuth | null, apiKey: string, shellId: string, config: Record<string, unknown>, days?: number): Promise<PolicyReplayResult>;
|
|
109
|
+
/** Which actions read alike enough to be routed to each other (router embeddings, no model calls). */
|
|
110
|
+
export declare function checkActionConfusion(auth: DuctAuth | null, apiKey: string, shellId: string, config: Record<string, unknown>): Promise<ActionConfusionResult>;
|
|
82
111
|
export interface UpstreamCheckResult {
|
|
83
112
|
ok: boolean;
|
|
84
113
|
code: string;
|
|
@@ -100,7 +129,7 @@ export declare function getShellWebhooks(auth: DuctAuth | null, apiKey: string,
|
|
|
100
129
|
export type WebhookPatch = Partial<Record<"deeplinkCallback" | "eventStream" | "consentCallback" | "identityUrl" | "secret", string>>;
|
|
101
130
|
export declare function patchShellWebhooks(auth: DuctAuth | null, apiKey: string, shellId: string, patch: WebhookPatch): Promise<ShellWebhooks>;
|
|
102
131
|
export interface ConnectionCheck {
|
|
103
|
-
target: "api" | "events" | "deeplinks" | "identity"
|
|
132
|
+
target: "api" | "events" | "deeplinks" | "identity";
|
|
104
133
|
label: string;
|
|
105
134
|
configured: boolean;
|
|
106
135
|
ok: boolean;
|
package/dist/cli/cloud.js
CHANGED
|
@@ -261,6 +261,14 @@ export async function checkPolicy(auth, apiKey, shellId, config, cases) {
|
|
|
261
261
|
const data = await callManifestApi(auth, apiKey, `/v1/shells/${encodeURIComponent(shellId)}/checks/policy`, { method: "POST", body: { ...(config ? { config: configForCases(config, cases) } : {}), cases } });
|
|
262
262
|
return data.results ?? [];
|
|
263
263
|
}
|
|
264
|
+
/** What the config about to be pushed would have done to the shell's recent real calls. */
|
|
265
|
+
export async function checkPolicyReplay(auth, apiKey, shellId, config, days) {
|
|
266
|
+
return callManifestApi(auth, apiKey, `/v1/shells/${encodeURIComponent(shellId)}/checks/policy-replay`, { method: "POST", body: { config, ...(days ? { days } : {}) } });
|
|
267
|
+
}
|
|
268
|
+
/** Which actions read alike enough to be routed to each other (router embeddings, no model calls). */
|
|
269
|
+
export async function checkActionConfusion(auth, apiKey, shellId, config) {
|
|
270
|
+
return callManifestApi(auth, apiKey, `/v1/shells/${encodeURIComponent(shellId)}/checks/action-confusion`, { method: "POST", body: { config: { shellId, actions: config.actions ?? [] } } });
|
|
271
|
+
}
|
|
264
272
|
export async function checkUpstream(auth, apiKey, shellId, config) {
|
|
265
273
|
return callManifestApi(auth, apiKey, `/v1/shells/${encodeURIComponent(shellId)}/checks/upstream`, { method: "POST", body: config ? { config: upstreamSlice(config) } : {} });
|
|
266
274
|
}
|
|
@@ -15,23 +15,9 @@ export interface WiringPlan {
|
|
|
15
15
|
middlewareSnippet: string;
|
|
16
16
|
uctSnippetPath?: string;
|
|
17
17
|
uctSnippet?: string;
|
|
18
|
-
/** Scaffold for the consent callback route (only when duct-consent mode). */
|
|
19
|
-
consentCallbackSnippetPath?: string;
|
|
20
|
-
consentCallbackSnippet?: string;
|
|
21
18
|
}
|
|
22
19
|
export declare function projectUsesVerifyDuctToken(sandboxFs: SandboxFS): Promise<boolean>;
|
|
23
20
|
export declare function generateVerifyDuctTokenMiddlewareSnippet(framework: FrameworkInfo, middlewarePath?: string): string;
|
|
24
21
|
export declare function generateUctVerificationSnippet(framework: FrameworkInfo): string;
|
|
25
22
|
export declare function buildWiringPlan(outputPaths: GeneratedOutputPaths, framework: FrameworkInfo, authDetection: AuthDetectionResult, thirdPartyAgentMode: ThirdPartyAgentMode): WiringPlan;
|
|
26
|
-
/**
|
|
27
|
-
* Scaffold for the consent callback route your app must expose when using
|
|
28
|
-
* the duct-consent third-party agent mode.
|
|
29
|
-
*
|
|
30
|
-
* This route receives the redirect from Duct after a user approves an agent
|
|
31
|
-
* consent request. It stores the uct_ token and user_ref so the agent can
|
|
32
|
-
* retrieve them for subsequent calls.
|
|
33
|
-
*
|
|
34
|
-
* Replace the TODO sections with your own DB / queue / webhook logic.
|
|
35
|
-
*/
|
|
36
|
-
export declare function generateConsentCallbackSnippet(framework: FrameworkInfo): string;
|
|
37
23
|
export declare function sideEffectActionsApproved(config: DuctConfig): boolean;
|