@duct-sdk/sdk 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/adapters/next/index.d.ts +4 -0
- package/dist/adapters/next/index.js +5 -0
- package/dist/adapters/next/receiver.d.ts +44 -0
- package/dist/adapters/next/receiver.js +162 -0
- package/dist/adapters/next/shell.d.ts +88 -0
- package/dist/adapters/next/shell.js +255 -0
- package/dist/adapters/react/index.d.ts +2 -0
- package/dist/adapters/react/index.js +4 -0
- package/dist/adapters/react/shell.d.ts +88 -0
- package/dist/adapters/react/shell.js +255 -0
- package/dist/adapters/remix/index.d.ts +2 -0
- package/dist/adapters/remix/index.js +4 -0
- package/dist/adapters/remix/receiver.d.ts +44 -0
- package/dist/adapters/remix/receiver.js +153 -0
- package/dist/adapters/sveltekit/index.d.ts +2 -0
- package/dist/adapters/sveltekit/index.js +4 -0
- package/dist/adapters/sveltekit/receiver.d.ts +56 -0
- package/dist/adapters/sveltekit/receiver.js +154 -0
- package/dist/adapters/vite/index.d.ts +2 -0
- package/dist/adapters/vite/index.js +4 -0
- package/dist/adapters/vite/receiver.d.ts +82 -0
- package/dist/adapters/vite/receiver.js +164 -0
- package/dist/assets/logo.d.ts +1 -0
- package/dist/assets/logo.js +1 -0
- package/dist/cli/agents/api-agent.d.ts +14 -0
- package/dist/cli/agents/api-agent.js +656 -0
- package/dist/cli/agents/auth-agent.d.ts +6 -0
- package/dist/cli/agents/auth-agent.js +198 -0
- package/dist/cli/agents/deeplink-agent.d.ts +6 -0
- package/dist/cli/agents/deeplink-agent.js +263 -0
- package/dist/cli/agents/llm.d.ts +33 -0
- package/dist/cli/agents/llm.js +276 -0
- package/dist/cli/agents/pipeline.d.ts +51 -0
- package/dist/cli/agents/pipeline.js +236 -0
- package/dist/cli/agents/reviewer-agent.d.ts +11 -0
- package/dist/cli/agents/reviewer-agent.js +442 -0
- package/dist/cli/agents/route-agent.d.ts +13 -0
- package/dist/cli/agents/route-agent.js +346 -0
- package/dist/cli/detectors/auth.d.ts +18 -0
- package/dist/cli/detectors/auth.js +273 -0
- package/dist/cli/detectors/framework.d.ts +22 -0
- package/dist/cli/detectors/framework.js +242 -0
- package/dist/cli/drift.d.ts +39 -0
- package/dist/cli/drift.js +247 -0
- package/dist/cli/fs/sandbox.d.ts +77 -0
- package/dist/cli/fs/sandbox.js +295 -0
- package/dist/cli/generators/config.d.ts +7 -0
- package/dist/cli/generators/config.js +255 -0
- package/dist/cli/generators/receiver.d.ts +12 -0
- package/dist/cli/generators/receiver.js +683 -0
- package/dist/cli/generators/shell.d.ts +18 -0
- package/dist/cli/generators/shell.js +672 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +603 -0
- package/dist/cli/init.d.ts +26 -0
- package/dist/cli/init.js +835 -0
- package/dist/core/action.d.ts +37 -0
- package/dist/core/action.js +140 -0
- package/dist/core/config.d.ts +514 -0
- package/dist/core/config.js +221 -0
- package/dist/core/endpoints.d.ts +17 -0
- package/dist/core/endpoints.js +128 -0
- package/dist/core/token.d.ts +70 -0
- package/dist/core/token.js +174 -0
- package/dist/core/types.d.ts +450 -0
- package/dist/core/types.js +11 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9 -0
- package/package.json +84 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
export type UIStateHint = "form" | "list" | "detail" | "dashboard" | "modal" | "wizard" | "empty" | "error" | "auth" | "checkout" | "profile" | "settings" | "search";
|
|
2
|
+
export interface RouteParam {
|
|
3
|
+
name: string;
|
|
4
|
+
type: "string" | "number" | "uuid" | "slug";
|
|
5
|
+
required: boolean;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface QueryParam {
|
|
9
|
+
name: string;
|
|
10
|
+
type: "string" | "number" | "boolean" | "string[]";
|
|
11
|
+
required: boolean;
|
|
12
|
+
description?: string;
|
|
13
|
+
defaultValue?: string | number | boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface RouteManifest {
|
|
16
|
+
/** e.g. "/dashboard", "/orders/[id]" */
|
|
17
|
+
path: string;
|
|
18
|
+
/** Human-readable name */
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
/** Dynamic path parameters */
|
|
22
|
+
params: RouteParam[];
|
|
23
|
+
/** URL query parameters */
|
|
24
|
+
queryParams: QueryParam[];
|
|
25
|
+
/** UI layout hints for generative UI */
|
|
26
|
+
uiStateHint: UIStateHint;
|
|
27
|
+
/** Whether authentication is required */
|
|
28
|
+
requiresAuth: boolean;
|
|
29
|
+
/** Whether this route is useful as a deeplink target */
|
|
30
|
+
deeplinkable: boolean;
|
|
31
|
+
/** HTTP methods that can be used to reach the route */
|
|
32
|
+
methods?: string[];
|
|
33
|
+
/** ISO 8601 timestamp of last update (set by duct push) */
|
|
34
|
+
updatedAt?: string;
|
|
35
|
+
}
|
|
36
|
+
export type SensitivityLevel = "none" | "low" | "medium" | "high" | "critical";
|
|
37
|
+
export interface ActionParam {
|
|
38
|
+
name: string;
|
|
39
|
+
type: "string" | "number" | "boolean" | "object" | "array";
|
|
40
|
+
required: boolean;
|
|
41
|
+
description?: string;
|
|
42
|
+
schema?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
export interface ActionManifest {
|
|
45
|
+
/** Unique ID for the action, e.g. "create_order" */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Human-readable name */
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
/** HTTP method */
|
|
51
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
52
|
+
/** API path, e.g. "/api/orders" */
|
|
53
|
+
path: string;
|
|
54
|
+
/** Whether AI agents can invoke this action */
|
|
55
|
+
agentAccessible: boolean;
|
|
56
|
+
/** Whether this action mutates state (POST/PUT/PATCH/DELETE) */
|
|
57
|
+
sideEffects: boolean;
|
|
58
|
+
/** Data sensitivity classification */
|
|
59
|
+
sensitivityLevel: SensitivityLevel;
|
|
60
|
+
/** Input parameters */
|
|
61
|
+
params: ActionParam[];
|
|
62
|
+
/** Response schema (JSON Schema) */
|
|
63
|
+
responseSchema?: Record<string, unknown>;
|
|
64
|
+
/** Input schema (JSON Schema) — used for validation */
|
|
65
|
+
inputSchema?: Record<string, unknown>;
|
|
66
|
+
/** Whether the action requires authentication */
|
|
67
|
+
requiresAuth: boolean;
|
|
68
|
+
/** Rate limit (requests per minute) */
|
|
69
|
+
rateLimit?: number;
|
|
70
|
+
/** Short hint for the action search index (shown in deferred mode) */
|
|
71
|
+
searchHint?: string;
|
|
72
|
+
/** Always include full schema even in large manifest deferred mode */
|
|
73
|
+
alwaysInclude?: boolean;
|
|
74
|
+
/** Interrupt behavior when a second message arrives mid-invocation */
|
|
75
|
+
interruptBehavior?: "cancel" | "block";
|
|
76
|
+
/** ISO 8601 timestamp of last update (set by duct push) */
|
|
77
|
+
updatedAt?: string;
|
|
78
|
+
}
|
|
79
|
+
export type AuthStrategy = "nextauth" | "clerk" | "auth0" | "custom-jwt" | "session-cookie" | "none" | "unknown";
|
|
80
|
+
export interface AuthSchema {
|
|
81
|
+
strategy: AuthStrategy;
|
|
82
|
+
/** Fields available in the session object */
|
|
83
|
+
sessionFields: string[];
|
|
84
|
+
/** Whether unauthenticated users can access the shell */
|
|
85
|
+
guestAllowed: boolean;
|
|
86
|
+
/** JWT expiry in seconds (for Duct delegated tokens) */
|
|
87
|
+
tokenExpirySeconds: number;
|
|
88
|
+
/** How Duct should request a token from the host app */
|
|
89
|
+
tokenEndpoint?: string;
|
|
90
|
+
/** Custom claims added to tokens */
|
|
91
|
+
customClaims?: Record<string, string>;
|
|
92
|
+
}
|
|
93
|
+
export interface StateField {
|
|
94
|
+
key: string;
|
|
95
|
+
type: "string" | "number" | "boolean" | "object";
|
|
96
|
+
required: boolean;
|
|
97
|
+
description?: string;
|
|
98
|
+
/** JSON path within session to source this value automatically */
|
|
99
|
+
sessionSource?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface DeeplinkDefinition {
|
|
102
|
+
/** Unique ID for this deeplink pattern */
|
|
103
|
+
id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
description: string;
|
|
106
|
+
/** Target route path pattern */
|
|
107
|
+
targetRoute: string;
|
|
108
|
+
/** State fields to encode in the deeplink JWT */
|
|
109
|
+
stateFields: StateField[];
|
|
110
|
+
/** Token expiry in seconds */
|
|
111
|
+
expirySeconds: number;
|
|
112
|
+
/** Whether this deeplink requires the user to be authenticated */
|
|
113
|
+
requiresAuth: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* When true, the shell runtime opens the deeplink URL in a new browser tab
|
|
116
|
+
* instead of posting DUCT_DEEPLINK_NAVIGATE to the parent frame.
|
|
117
|
+
* Useful for external URLs or flows that should not interrupt the current page.
|
|
118
|
+
*/
|
|
119
|
+
openInNewTab?: boolean;
|
|
120
|
+
/** Human-readable intent description (for agent use) */
|
|
121
|
+
intent?: string;
|
|
122
|
+
/** ISO 8601 timestamp of last update (set by duct push) */
|
|
123
|
+
updatedAt?: string;
|
|
124
|
+
}
|
|
125
|
+
export type ReviewIssueSeverity = "error" | "warning" | "info";
|
|
126
|
+
export interface ReviewIssue {
|
|
127
|
+
code: string;
|
|
128
|
+
severity: ReviewIssueSeverity;
|
|
129
|
+
message: string;
|
|
130
|
+
/** Which field/path in the config this refers to */
|
|
131
|
+
path?: string;
|
|
132
|
+
/** Suggested fix */
|
|
133
|
+
suggestion?: string;
|
|
134
|
+
}
|
|
135
|
+
export interface ReviewResult {
|
|
136
|
+
passed: boolean;
|
|
137
|
+
confidenceScore: number;
|
|
138
|
+
issues: ReviewIssue[];
|
|
139
|
+
suggestions: string[];
|
|
140
|
+
/** Summary of what was reviewed */
|
|
141
|
+
summary: string;
|
|
142
|
+
}
|
|
143
|
+
export type AgentPermissionLevel = "none" | "read" | "write" | "admin";
|
|
144
|
+
export interface AgentPermissions {
|
|
145
|
+
/** Default permission level for any agent */
|
|
146
|
+
defaultLevel: AgentPermissionLevel;
|
|
147
|
+
/** Per-action overrides */
|
|
148
|
+
actionOverrides?: Record<string, AgentPermissionLevel>;
|
|
149
|
+
/** List of allowed agent/shell IDs */
|
|
150
|
+
allowedAgents?: string[];
|
|
151
|
+
/** Whether to require explicit user consent for agent actions */
|
|
152
|
+
requireUserConsent: boolean;
|
|
153
|
+
/** Allowed actions (action IDs) */
|
|
154
|
+
allowedActions?: string[];
|
|
155
|
+
}
|
|
156
|
+
export interface WidgetConfig {
|
|
157
|
+
/** Primary brand color (hex) */
|
|
158
|
+
primaryColor?: string;
|
|
159
|
+
/** Position on the page */
|
|
160
|
+
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
161
|
+
/** Whether to show the widget by default */
|
|
162
|
+
defaultOpen?: boolean;
|
|
163
|
+
/** Custom launcher button text */
|
|
164
|
+
launcherText?: string;
|
|
165
|
+
/** Welcome message shown in empty state */
|
|
166
|
+
welcomeMessage?: string;
|
|
167
|
+
/** Input placeholder text */
|
|
168
|
+
placeholder?: string;
|
|
169
|
+
/** Whether to hide the launcher (for custom trigger) */
|
|
170
|
+
hideLauncher?: boolean;
|
|
171
|
+
/** Custom CSS injected into the shell iframe (scoped) */
|
|
172
|
+
customCSS?: string;
|
|
173
|
+
/** iframe width — default: 380 */
|
|
174
|
+
width?: number | string;
|
|
175
|
+
/** iframe height — default: 620 */
|
|
176
|
+
height?: number | string;
|
|
177
|
+
/** URL to your product logo (shown in empty state) */
|
|
178
|
+
logoUrl?: string;
|
|
179
|
+
}
|
|
180
|
+
export interface ProductConfig {
|
|
181
|
+
/** Company or product name */
|
|
182
|
+
name: string;
|
|
183
|
+
/** Brief description of the product */
|
|
184
|
+
description: string;
|
|
185
|
+
/** Base URL of the product */
|
|
186
|
+
baseUrl: string;
|
|
187
|
+
/** Primary language/locale */
|
|
188
|
+
locale?: string;
|
|
189
|
+
/** Industry/category for the product */
|
|
190
|
+
industry?: string;
|
|
191
|
+
}
|
|
192
|
+
export interface DuctConfig {
|
|
193
|
+
/** Shell ID assigned by Duct cloud */
|
|
194
|
+
shellId: string;
|
|
195
|
+
/** Product metadata */
|
|
196
|
+
product: ProductConfig;
|
|
197
|
+
/** Authentication configuration */
|
|
198
|
+
auth: AuthSchema;
|
|
199
|
+
/** All navigable routes */
|
|
200
|
+
routes: RouteManifest[];
|
|
201
|
+
/** All API actions */
|
|
202
|
+
actions: ActionManifest[];
|
|
203
|
+
/** Deeplink targets */
|
|
204
|
+
deeplinks: DeeplinkDefinition[];
|
|
205
|
+
/** Agent permission settings */
|
|
206
|
+
agentPermissions: AgentPermissions;
|
|
207
|
+
/** Shell widget display config */
|
|
208
|
+
widget?: WidgetConfig;
|
|
209
|
+
}
|
|
210
|
+
export interface ShellManifest {
|
|
211
|
+
shellId: string;
|
|
212
|
+
version: string;
|
|
213
|
+
createdAt: string;
|
|
214
|
+
updatedAt: string;
|
|
215
|
+
config: DuctConfig;
|
|
216
|
+
/** Checksum of the config for drift detection */
|
|
217
|
+
configChecksum: string;
|
|
218
|
+
/** Whether the shell is live */
|
|
219
|
+
active: boolean;
|
|
220
|
+
/** Duct cloud region */
|
|
221
|
+
region: string;
|
|
222
|
+
}
|
|
223
|
+
export type ModalityDecision = {
|
|
224
|
+
type: "text";
|
|
225
|
+
response: string;
|
|
226
|
+
} | {
|
|
227
|
+
type: "generative_ui";
|
|
228
|
+
componentHint: UIStateHint;
|
|
229
|
+
data: Record<string, unknown>;
|
|
230
|
+
} | {
|
|
231
|
+
type: "deeplink_handoff";
|
|
232
|
+
deeplinkId: string;
|
|
233
|
+
state: Record<string, unknown>;
|
|
234
|
+
message?: string;
|
|
235
|
+
} | {
|
|
236
|
+
type: "action";
|
|
237
|
+
actionId: string;
|
|
238
|
+
params: Record<string, unknown>;
|
|
239
|
+
} | {
|
|
240
|
+
type: "inter_shell";
|
|
241
|
+
targetShellId: string;
|
|
242
|
+
intent: string;
|
|
243
|
+
context: Record<string, unknown>;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Scored wrapper around a ModalityDecision.
|
|
247
|
+
* confidence < 0.6 → shell runtime must show clarification prompt before executing.
|
|
248
|
+
* fallback → what to do if the primary decision fails at execution time.
|
|
249
|
+
*/
|
|
250
|
+
export interface ScoredModalityDecision {
|
|
251
|
+
decision: ModalityDecision;
|
|
252
|
+
/** 0–1 confidence from the modality router LLM */
|
|
253
|
+
confidence: number;
|
|
254
|
+
/** Router's reasoning (for logging/debugging) */
|
|
255
|
+
reasoning: string;
|
|
256
|
+
/** Fallback decision if primary execution fails */
|
|
257
|
+
fallback: ModalityDecision | null;
|
|
258
|
+
}
|
|
259
|
+
export type ShellSessionPhase = "opening" | "exploring" | "transacting" | "closing";
|
|
260
|
+
/**
|
|
261
|
+
* Full typed state carried by a shell session between turns.
|
|
262
|
+
* Stored in Redis with 30-minute TTL, extended on each turn.
|
|
263
|
+
*/
|
|
264
|
+
export interface ShellSessionState {
|
|
265
|
+
sessionId: string;
|
|
266
|
+
shellId: string;
|
|
267
|
+
phase: ShellSessionPhase;
|
|
268
|
+
turnCount: number;
|
|
269
|
+
/** Filled after turn 8 via summarisation LLM call */
|
|
270
|
+
contextSummary: string | null;
|
|
271
|
+
/** deeplinkId → accumulated partial state from conversation entities */
|
|
272
|
+
accumulatedDeeplinkState: Record<string, Record<string, unknown>>;
|
|
273
|
+
/** Set when router confidence < 0.55 — pending clarification */
|
|
274
|
+
pendingConfirmation: {
|
|
275
|
+
/** Stored as plain JSON in Redis; use ScoredModalityDecision shape at call sites */
|
|
276
|
+
decision: Record<string, unknown>;
|
|
277
|
+
expiresAt: number;
|
|
278
|
+
} | null;
|
|
279
|
+
/** Set when ConfirmCard is shown for a side-effect action */
|
|
280
|
+
pendingExecution: {
|
|
281
|
+
actionId: string;
|
|
282
|
+
params: Record<string, unknown>;
|
|
283
|
+
executionToken: string;
|
|
284
|
+
expiresAt: number;
|
|
285
|
+
} | null;
|
|
286
|
+
lastDeeplinkFired: {
|
|
287
|
+
deeplinkId: string;
|
|
288
|
+
callbackId: string;
|
|
289
|
+
firedAt: number;
|
|
290
|
+
confirmed: boolean;
|
|
291
|
+
} | null;
|
|
292
|
+
callerType: "human" | "agent";
|
|
293
|
+
userId: string | null;
|
|
294
|
+
agentId: string | null;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Call chain passed as x-duct-call-chain header (JSON-encoded).
|
|
298
|
+
* depth >= 5 → MAX_CALL_DEPTH_EXCEEDED.
|
|
299
|
+
* path.includes(callerShellId) → CIRCULAR_SHELL_CALL.
|
|
300
|
+
*/
|
|
301
|
+
export interface ShellCallChain {
|
|
302
|
+
chainId: string;
|
|
303
|
+
depth: number;
|
|
304
|
+
path: string[];
|
|
305
|
+
}
|
|
306
|
+
/** Session type with single-character prefix used in typed session IDs. */
|
|
307
|
+
export type ShellSessionType = "human" | "agent" | "inter_shell" | "deeplink" | "background";
|
|
308
|
+
export declare const SESSION_TYPE_PREFIX: Record<ShellSessionType, string>;
|
|
309
|
+
export type PermissionRuleSource = "manifest" | "policy" | "session" | "default";
|
|
310
|
+
export type PermissionDecision = "allow" | "deny" | "ask";
|
|
311
|
+
export interface ActionPermissionContext {
|
|
312
|
+
actionId: string;
|
|
313
|
+
callerShellId: string;
|
|
314
|
+
isAgent: boolean;
|
|
315
|
+
hasUserConsentToken: boolean;
|
|
316
|
+
callChainDepth: number;
|
|
317
|
+
/** When true, the caller cannot show confirmation UI (background/agent context) */
|
|
318
|
+
avoidInteractivePrompts: boolean;
|
|
319
|
+
sessionPhase?: ShellSessionPhase;
|
|
320
|
+
}
|
|
321
|
+
export interface ActionPermissionResult {
|
|
322
|
+
decision: PermissionDecision;
|
|
323
|
+
reason: string;
|
|
324
|
+
source: PermissionRuleSource;
|
|
325
|
+
}
|
|
326
|
+
/** Structured validation result from validateInput on an ActionDef. */
|
|
327
|
+
export type ActionValidationResult = {
|
|
328
|
+
valid: true;
|
|
329
|
+
} | {
|
|
330
|
+
valid: false;
|
|
331
|
+
message: string;
|
|
332
|
+
/** 4001=missing required, 4002=type mismatch, 4003=out of range, 4004=schema failure */
|
|
333
|
+
code: 4001 | 4002 | 4003 | 4004;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Runtime-only fields added by buildAction().
|
|
337
|
+
* Not serialisable — kept in-memory only.
|
|
338
|
+
*/
|
|
339
|
+
export interface ActionRuntimeFields {
|
|
340
|
+
/** Short description used in deferred tool index (defaults to "METHOD PATH") */
|
|
341
|
+
searchHint?: string;
|
|
342
|
+
/** Always send full schema to router even in large manifests */
|
|
343
|
+
alwaysInclude?: boolean;
|
|
344
|
+
/** What to do when a second user message arrives while this action is in-flight */
|
|
345
|
+
interruptBehavior?: "cancel" | "block";
|
|
346
|
+
validateInput?: (params: Record<string, unknown>) => ActionValidationResult;
|
|
347
|
+
checkPermissions?: (params: Record<string, unknown>, ctx: ActionPermissionContext) => Promise<ActionPermissionResult>;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* ActionDef = manifest data + runtime callbacks.
|
|
351
|
+
* Produced by buildAction(). Used internally by the SDK and agent-proxy.
|
|
352
|
+
*
|
|
353
|
+
* Use BuiltActionDef when you know the value came from buildAction() and
|
|
354
|
+
* want the compiler to enforce that validateInput and checkPermissions are present.
|
|
355
|
+
*/
|
|
356
|
+
export type ActionDef = ActionManifest & ActionRuntimeFields;
|
|
357
|
+
/**
|
|
358
|
+
* Narrowed ActionDef where buildAction() always assigns the runtime callbacks.
|
|
359
|
+
* Eliminates the need for `!` assertions at call sites.
|
|
360
|
+
*/
|
|
361
|
+
export type BuiltActionDef = ActionManifest & Required<Pick<ActionRuntimeFields, 'validateInput' | 'checkPermissions'>> & Omit<ActionRuntimeFields, 'validateInput' | 'checkPermissions'>;
|
|
362
|
+
export interface Message {
|
|
363
|
+
id: string;
|
|
364
|
+
role: "user" | "assistant" | "system";
|
|
365
|
+
content: string;
|
|
366
|
+
timestamp: string;
|
|
367
|
+
metadata?: Record<string, unknown>;
|
|
368
|
+
}
|
|
369
|
+
export interface SessionContext {
|
|
370
|
+
sessionId: string;
|
|
371
|
+
shellId: string;
|
|
372
|
+
/** Authenticated user context (if any) */
|
|
373
|
+
user?: {
|
|
374
|
+
id: string;
|
|
375
|
+
email?: string;
|
|
376
|
+
name?: string;
|
|
377
|
+
[key: string]: unknown;
|
|
378
|
+
};
|
|
379
|
+
/** Whether this is an agent session (vs. human) */
|
|
380
|
+
isAgent: boolean;
|
|
381
|
+
/** Calling agent/shell ID if isAgent is true */
|
|
382
|
+
agentId?: string;
|
|
383
|
+
/** Conversation history */
|
|
384
|
+
messages: Message[];
|
|
385
|
+
/** Arbitrary metadata */
|
|
386
|
+
metadata?: Record<string, unknown>;
|
|
387
|
+
createdAt: string;
|
|
388
|
+
updatedAt: string;
|
|
389
|
+
}
|
|
390
|
+
export interface DuctAdapter {
|
|
391
|
+
/** Framework name */
|
|
392
|
+
name: string;
|
|
393
|
+
/**
|
|
394
|
+
* Create a receiver handler for the given config.
|
|
395
|
+
* Returns a framework-specific handler function.
|
|
396
|
+
*/
|
|
397
|
+
createReceiver(config: DuctConfig, options: ReceiverOptions): unknown;
|
|
398
|
+
/**
|
|
399
|
+
* Create the shell embed component/snippet.
|
|
400
|
+
*/
|
|
401
|
+
createShell(config: DuctConfig, options: ShellOptions): unknown;
|
|
402
|
+
}
|
|
403
|
+
export interface ReceiverOptions {
|
|
404
|
+
/** Secret key for JWT verification */
|
|
405
|
+
secretKey: string;
|
|
406
|
+
/** Called when a valid deeplink token is received */
|
|
407
|
+
onReceive: (deeplinkId: string, state: Record<string, unknown>, session: SessionContext) => Promise<void>;
|
|
408
|
+
/** Called when verification fails */
|
|
409
|
+
onError?: (error: Error) => void;
|
|
410
|
+
}
|
|
411
|
+
export interface ShellOptions {
|
|
412
|
+
/** User context to pass to the shell */
|
|
413
|
+
userContext?: Record<string, unknown>;
|
|
414
|
+
/** Function to generate a Duct token on demand */
|
|
415
|
+
onTokenRequest?: (shellId: string) => Promise<string>;
|
|
416
|
+
/** Custom CSS class */
|
|
417
|
+
className?: string;
|
|
418
|
+
/** Custom inline styles */
|
|
419
|
+
style?: Record<string, string>;
|
|
420
|
+
}
|
|
421
|
+
export interface DuctTokenPayload {
|
|
422
|
+
/** Token type — always "duct_delegated" */
|
|
423
|
+
type: "duct_delegated";
|
|
424
|
+
/** Subject — user ID */
|
|
425
|
+
sub: string;
|
|
426
|
+
/** Issuer — shell ID */
|
|
427
|
+
iss: string;
|
|
428
|
+
/** Issued at */
|
|
429
|
+
iat: number;
|
|
430
|
+
/** Expiration */
|
|
431
|
+
exp: number;
|
|
432
|
+
/** Allowed actions */
|
|
433
|
+
allowedActions?: string[];
|
|
434
|
+
/** User session fields (scalars only) */
|
|
435
|
+
session: Record<string, string | number | boolean | null>;
|
|
436
|
+
}
|
|
437
|
+
export interface DeeplinkTokenPayload {
|
|
438
|
+
/** Deeplink definition ID */
|
|
439
|
+
deeplink_id: string;
|
|
440
|
+
/** Subject — user ID */
|
|
441
|
+
sub: string;
|
|
442
|
+
/** Issuer — shell ID */
|
|
443
|
+
iss: string;
|
|
444
|
+
/** Issued at */
|
|
445
|
+
iat: number;
|
|
446
|
+
/** Expiration */
|
|
447
|
+
exp: number;
|
|
448
|
+
/** State fields */
|
|
449
|
+
state: Record<string, unknown>;
|
|
450
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — Core Types
|
|
3
|
+
// All shared TypeScript types for the Duct platform
|
|
4
|
+
// ============================================================
|
|
5
|
+
export const SESSION_TYPE_PREFIX = {
|
|
6
|
+
human: "h",
|
|
7
|
+
agent: "a",
|
|
8
|
+
inter_shell: "i",
|
|
9
|
+
deeplink: "d",
|
|
10
|
+
background: "b",
|
|
11
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { defineDuctConfig, DuctConfigSchema } from "./core/config.js";
|
|
2
|
+
export type { ValidatedDuctConfig } from "./core/config.js";
|
|
3
|
+
export { generateDuctToken, verifyDuctToken, verifyDeeplinkToken, } from "./core/token.js";
|
|
4
|
+
export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, } from "./core/token.js";
|
|
5
|
+
export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
|
|
6
|
+
export type { ActionSearchEntry } from "./core/action.js";
|
|
7
|
+
export type { RouteManifest, RouteParam, QueryParam, UIStateHint, ActionManifest, ActionParam, SensitivityLevel, ActionRuntimeFields, ActionDef, BuiltActionDef, ActionValidationResult, AuthSchema, AuthStrategy, DeeplinkDefinition, StateField, ReviewResult, ReviewIssue, ReviewIssueSeverity, DuctConfig, ProductConfig, AgentPermissions, AgentPermissionLevel, WidgetConfig, ShellManifest, ModalityDecision, ScoredModalityDecision, ShellSessionPhase, ShellSessionState, ShellSessionType, ShellCallChain, ActionPermissionContext, ActionPermissionResult, PermissionDecision, PermissionRuleSource, SessionContext, Message, DuctTokenPayload, DeeplinkTokenPayload, DuctAdapter, ReceiverOptions, ShellOptions, } from "./core/types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — Main Package Exports
|
|
3
|
+
// ============================================================
|
|
4
|
+
// Core config
|
|
5
|
+
export { defineDuctConfig, DuctConfigSchema } from "./core/config.js";
|
|
6
|
+
// Token utilities
|
|
7
|
+
export { generateDuctToken, verifyDuctToken, verifyDeeplinkToken, } from "./core/token.js";
|
|
8
|
+
// Action factory
|
|
9
|
+
export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@duct-sdk/sdk",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"duct": "dist/cli/index.js"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.js",
|
|
13
|
+
"./next": "./dist/adapters/next/index.js",
|
|
14
|
+
"./remix": "./dist/adapters/remix/index.js",
|
|
15
|
+
"./vite": "./dist/adapters/vite/index.js",
|
|
16
|
+
"./sveltekit": "./dist/adapters/sveltekit/index.js",
|
|
17
|
+
"./react": "./dist/adapters/react/index.js"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc --watch"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@anthropic-ai/sdk": "^0.24.0",
|
|
25
|
+
"jose": "^5.0.0",
|
|
26
|
+
"ignore": "^5.0.0",
|
|
27
|
+
"commander": "^12.0.0",
|
|
28
|
+
"chalk": "^5.0.0",
|
|
29
|
+
"ora": "^8.0.0",
|
|
30
|
+
"inquirer": "^9.0.0",
|
|
31
|
+
"zod": "^3.0.0",
|
|
32
|
+
"node-fetch": "^3.0.0",
|
|
33
|
+
"glob": "^10.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.0.0",
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"@types/inquirer": "^9.0.0",
|
|
39
|
+
"@types/react": "^18.0.0",
|
|
40
|
+
"next": "^14.0.0",
|
|
41
|
+
"react": "^18.0.0",
|
|
42
|
+
"react-dom": "^18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
46
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
47
|
+
"next": ">=14.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"react": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"react-dom": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"next": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"dist",
|
|
62
|
+
"README.md"
|
|
63
|
+
],
|
|
64
|
+
"keywords": [
|
|
65
|
+
"duct",
|
|
66
|
+
"ai",
|
|
67
|
+
"agent",
|
|
68
|
+
"shell",
|
|
69
|
+
"cli",
|
|
70
|
+
"llm",
|
|
71
|
+
"ai-agent",
|
|
72
|
+
"deeplink",
|
|
73
|
+
"next",
|
|
74
|
+
"nextjs",
|
|
75
|
+
"remix",
|
|
76
|
+
"vite",
|
|
77
|
+
"sveltekit",
|
|
78
|
+
"sdk"
|
|
79
|
+
],
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"registry": "https://registry.npmjs.org",
|
|
82
|
+
"access": "public"
|
|
83
|
+
}
|
|
84
|
+
}
|