@duct-sdk/sdk 0.3.11 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/config.d.ts +43 -0
- package/dist/core/config.js +7 -0
- package/dist/core/limits.d.ts +1 -1
- package/dist/core/limits.js +1 -1
- package/dist/core/page-resolve.d.ts +49 -0
- package/dist/core/page-resolve.js +87 -0
- package/dist/core/types.d.ts +16 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +2 -0
- package/package.json +1 -1
package/dist/core/config.d.ts
CHANGED
|
@@ -229,6 +229,21 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
229
229
|
expirySeconds: z.ZodDefault<z.ZodNumber>;
|
|
230
230
|
requiresAuth: z.ZodBoolean;
|
|
231
231
|
intent: z.ZodOptional<z.ZodString>;
|
|
232
|
+
pageResolver: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
233
|
+
actionId: z.ZodString;
|
|
234
|
+
}, "strip", z.ZodTypeAny, {
|
|
235
|
+
actionId: string;
|
|
236
|
+
}, {
|
|
237
|
+
actionId: string;
|
|
238
|
+
}>, z.ZodObject<{
|
|
239
|
+
endpoint: z.ZodString;
|
|
240
|
+
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
endpoint: string;
|
|
242
|
+
}, {
|
|
243
|
+
endpoint: string;
|
|
244
|
+
}>]>>;
|
|
245
|
+
allowFetch: z.ZodOptional<z.ZodBoolean>;
|
|
246
|
+
contentSelector: z.ZodOptional<z.ZodString>;
|
|
232
247
|
}, "strip", z.ZodTypeAny, {
|
|
233
248
|
id: string;
|
|
234
249
|
name: string;
|
|
@@ -244,6 +259,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
244
259
|
}[];
|
|
245
260
|
expirySeconds: number;
|
|
246
261
|
intent?: string | undefined;
|
|
262
|
+
pageResolver?: {
|
|
263
|
+
actionId: string;
|
|
264
|
+
} | {
|
|
265
|
+
endpoint: string;
|
|
266
|
+
} | undefined;
|
|
267
|
+
allowFetch?: boolean | undefined;
|
|
268
|
+
contentSelector?: string | undefined;
|
|
247
269
|
}, {
|
|
248
270
|
id: string;
|
|
249
271
|
name: string;
|
|
@@ -259,6 +281,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
259
281
|
}[] | undefined;
|
|
260
282
|
expirySeconds?: number | undefined;
|
|
261
283
|
intent?: string | undefined;
|
|
284
|
+
pageResolver?: {
|
|
285
|
+
actionId: string;
|
|
286
|
+
} | {
|
|
287
|
+
endpoint: string;
|
|
288
|
+
} | undefined;
|
|
289
|
+
allowFetch?: boolean | undefined;
|
|
290
|
+
contentSelector?: string | undefined;
|
|
262
291
|
}>, "many">>;
|
|
263
292
|
agentPermissions: z.ZodObject<{
|
|
264
293
|
defaultLevel: z.ZodEnum<["none", "read", "write", "admin"]>;
|
|
@@ -399,6 +428,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
399
428
|
}[];
|
|
400
429
|
expirySeconds: number;
|
|
401
430
|
intent?: string | undefined;
|
|
431
|
+
pageResolver?: {
|
|
432
|
+
actionId: string;
|
|
433
|
+
} | {
|
|
434
|
+
endpoint: string;
|
|
435
|
+
} | undefined;
|
|
436
|
+
allowFetch?: boolean | undefined;
|
|
437
|
+
contentSelector?: string | undefined;
|
|
402
438
|
}[];
|
|
403
439
|
agentPermissions: {
|
|
404
440
|
defaultLevel: "none" | "read" | "write" | "admin";
|
|
@@ -506,6 +542,13 @@ export declare const DuctConfigSchema: z.ZodObject<{
|
|
|
506
542
|
}[] | undefined;
|
|
507
543
|
expirySeconds?: number | undefined;
|
|
508
544
|
intent?: string | undefined;
|
|
545
|
+
pageResolver?: {
|
|
546
|
+
actionId: string;
|
|
547
|
+
} | {
|
|
548
|
+
endpoint: string;
|
|
549
|
+
} | undefined;
|
|
550
|
+
allowFetch?: boolean | undefined;
|
|
551
|
+
contentSelector?: string | undefined;
|
|
509
552
|
}[] | undefined;
|
|
510
553
|
widget?: {
|
|
511
554
|
primaryColor?: string | undefined;
|
package/dist/core/config.js
CHANGED
|
@@ -99,6 +99,10 @@ const StateFieldSchema = z.object({
|
|
|
99
99
|
description: z.string().optional(),
|
|
100
100
|
sessionSource: z.string().optional(),
|
|
101
101
|
});
|
|
102
|
+
const PageResolverSchema = z.union([
|
|
103
|
+
z.object({ actionId: z.string().min(1) }),
|
|
104
|
+
z.object({ endpoint: z.string().min(1).startsWith("/") }),
|
|
105
|
+
]);
|
|
102
106
|
const DeeplinkDefinitionSchema = z.object({
|
|
103
107
|
id: z
|
|
104
108
|
.string()
|
|
@@ -111,6 +115,9 @@ const DeeplinkDefinitionSchema = z.object({
|
|
|
111
115
|
expirySeconds: z.number().positive().default(300),
|
|
112
116
|
requiresAuth: z.boolean(),
|
|
113
117
|
intent: z.string().optional(),
|
|
118
|
+
pageResolver: PageResolverSchema.optional(),
|
|
119
|
+
allowFetch: z.boolean().optional(),
|
|
120
|
+
contentSelector: z.string().optional(),
|
|
114
121
|
});
|
|
115
122
|
const AgentPermissionLevelSchema = z.enum([
|
|
116
123
|
"none",
|
package/dist/core/limits.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Default agent loop ceilings used in widget manifest defaults. */
|
|
2
|
-
export declare const DEFAULT_MAX_TOOL_ITERATIONS =
|
|
2
|
+
export declare const DEFAULT_MAX_TOOL_ITERATIONS = 4;
|
|
3
3
|
export declare const DEFAULT_MAX_PLAN_STEPS = 8;
|
|
4
4
|
export declare const HARD_CEILING_TOOL_ITERATIONS = 25;
|
|
5
5
|
export declare const HARD_CEILING_PLAN_STEPS = 12;
|
package/dist/core/limits.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Default agent loop ceilings used in widget manifest defaults. */
|
|
2
|
-
export const DEFAULT_MAX_TOOL_ITERATIONS =
|
|
2
|
+
export const DEFAULT_MAX_TOOL_ITERATIONS = 4;
|
|
3
3
|
export const DEFAULT_MAX_PLAN_STEPS = 8;
|
|
4
4
|
export const HARD_CEILING_TOOL_ITERATIONS = 25;
|
|
5
5
|
export const HARD_CEILING_PLAN_STEPS = 12;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface DuctPageContext {
|
|
2
|
+
/** Human-readable page title */
|
|
3
|
+
title?: string;
|
|
4
|
+
/** Route or screen identifier in the host app */
|
|
5
|
+
route?: string;
|
|
6
|
+
/** Key fields visible on the page (entity snapshots, form values, etc.) */
|
|
7
|
+
fields?: Record<string, unknown>;
|
|
8
|
+
/** Optional structured sections (tables, lists) */
|
|
9
|
+
sections?: Array<{
|
|
10
|
+
id: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
items?: unknown[];
|
|
13
|
+
}>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface PageResolveResult {
|
|
17
|
+
page_context: DuctPageContext;
|
|
18
|
+
data?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface PageResolveContext {
|
|
21
|
+
deeplinkId: string;
|
|
22
|
+
state: Record<string, string>;
|
|
23
|
+
headers: Record<string, string | string[] | undefined>;
|
|
24
|
+
searchParams: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
export type PageResolveResolver = (ctx: PageResolveContext) => Promise<PageResolveResult>;
|
|
27
|
+
export interface PageResolveHandlerOptions {
|
|
28
|
+
cacheTtlSeconds?: number;
|
|
29
|
+
noCache?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function createPageResolveHandler(resolver: PageResolveResolver, options?: PageResolveHandlerOptions): (req: Request) => Promise<Response>;
|
|
32
|
+
export declare function createPageResolvePageHandler(resolver: PageResolveResolver, options?: PageResolveHandlerOptions): (req: {
|
|
33
|
+
headers: Record<string, string | string[]>;
|
|
34
|
+
query: Record<string, string | string[]>;
|
|
35
|
+
}, res: {
|
|
36
|
+
status: (code: number) => {
|
|
37
|
+
json: (body: unknown) => void;
|
|
38
|
+
};
|
|
39
|
+
setHeader: (name: string, value: string) => void;
|
|
40
|
+
}) => Promise<void>;
|
|
41
|
+
export declare function createPageResolveExpressHandler(resolver: PageResolveResolver, options?: PageResolveHandlerOptions): (req: {
|
|
42
|
+
headers: Record<string, string | string[] | undefined>;
|
|
43
|
+
query: Record<string, string | string[]>;
|
|
44
|
+
}, res: {
|
|
45
|
+
status: (code: number) => {
|
|
46
|
+
json: (body: unknown) => void;
|
|
47
|
+
};
|
|
48
|
+
setHeader: (name: string, value: string) => void;
|
|
49
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — /duct/page-resolve handler factory
|
|
3
|
+
// Companies implement structured page context for agent deeplink
|
|
4
|
+
// resolution (parallel to /duct/introspect).
|
|
5
|
+
//
|
|
6
|
+
// Contract:
|
|
7
|
+
// GET /duct/page-resolve?deeplink_id=...&<state fields>
|
|
8
|
+
// → { page_context: { ... }, data?: unknown }
|
|
9
|
+
// ============================================================
|
|
10
|
+
async function runPageResolveResolver(resolver, ctx, options) {
|
|
11
|
+
const ttl = options.cacheTtlSeconds ?? 60;
|
|
12
|
+
const cacheControl = options.noCache
|
|
13
|
+
? 'no-store'
|
|
14
|
+
: `private, max-age=${ttl}, stale-while-revalidate=30`;
|
|
15
|
+
try {
|
|
16
|
+
const result = await resolver(ctx);
|
|
17
|
+
return {
|
|
18
|
+
body: result,
|
|
19
|
+
headers: { 'Cache-Control': cacheControl, 'Content-Type': 'application/json' },
|
|
20
|
+
status: 200,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return {
|
|
25
|
+
body: { page_context: {} },
|
|
26
|
+
headers: { 'Cache-Control': 'no-store', 'Content-Type': 'application/json' },
|
|
27
|
+
status: 500,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function headersToRecord(headers) {
|
|
32
|
+
const out = {};
|
|
33
|
+
headers.forEach((value, key) => { out[key] = value; });
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function extractPageResolveContext(req, searchParamsFromUrl) {
|
|
37
|
+
const searchParams = {};
|
|
38
|
+
if (searchParamsFromUrl) {
|
|
39
|
+
searchParamsFromUrl.forEach((v, k) => { searchParams[k] = v; });
|
|
40
|
+
}
|
|
41
|
+
else if (req.query) {
|
|
42
|
+
for (const [k, v] of Object.entries(req.query)) {
|
|
43
|
+
searchParams[k] = Array.isArray(v) ? v[0] ?? '' : v;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const deeplinkId = searchParams.deeplink_id ?? searchParams.deeplinkId ?? '';
|
|
47
|
+
const state = {};
|
|
48
|
+
for (const [k, v] of Object.entries(searchParams)) {
|
|
49
|
+
if (k === 'deeplink_id' || k === 'deeplinkId')
|
|
50
|
+
continue;
|
|
51
|
+
state[k] = v;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
deeplinkId,
|
|
55
|
+
state,
|
|
56
|
+
headers: req.headers,
|
|
57
|
+
searchParams,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function createPageResolveHandler(resolver, options = {}) {
|
|
61
|
+
return async (req) => {
|
|
62
|
+
const url = new URL(req.url);
|
|
63
|
+
const ctx = extractPageResolveContext({ headers: headersToRecord(req.headers) }, url.searchParams);
|
|
64
|
+
const { body, headers, status } = await runPageResolveResolver(resolver, ctx, options);
|
|
65
|
+
return new Response(JSON.stringify(body), { status, headers });
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function createPageResolvePageHandler(resolver, options = {}) {
|
|
69
|
+
return async (req, res) => {
|
|
70
|
+
const ctx = extractPageResolveContext({ headers: req.headers, query: req.query });
|
|
71
|
+
const { body, headers, status } = await runPageResolveResolver(resolver, ctx, options);
|
|
72
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
73
|
+
res.setHeader(key, value);
|
|
74
|
+
}
|
|
75
|
+
res.status(status).json(body);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function createPageResolveExpressHandler(resolver, options = {}) {
|
|
79
|
+
return async (req, res) => {
|
|
80
|
+
const ctx = extractPageResolveContext({ headers: req.headers, query: req.query });
|
|
81
|
+
const { body, headers, status } = await runPageResolveResolver(resolver, ctx, options);
|
|
82
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
83
|
+
res.setHeader(key, value);
|
|
84
|
+
}
|
|
85
|
+
res.status(status).json(body);
|
|
86
|
+
};
|
|
87
|
+
}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -158,6 +158,22 @@ export interface DeeplinkDefinition {
|
|
|
158
158
|
openInNewTab?: boolean;
|
|
159
159
|
/** Human-readable intent description (for agent use) */
|
|
160
160
|
intent?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Agent page resolution — invoke an action or company endpoint to return
|
|
163
|
+
* structured page context instead of a bare handoff URL.
|
|
164
|
+
*/
|
|
165
|
+
pageResolver?: {
|
|
166
|
+
actionId: string;
|
|
167
|
+
} | {
|
|
168
|
+
endpoint: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* When true (and pageResolver absent or insufficient), platform may fetch
|
|
172
|
+
* rendered HTML from the deeplink URL. Off by default — explicit opt-in.
|
|
173
|
+
*/
|
|
174
|
+
allowFetch?: boolean;
|
|
175
|
+
/** CSS selector hints for generic HTML extraction when allowFetch is true */
|
|
176
|
+
contentSelector?: string;
|
|
161
177
|
/** ISO 8601 timestamp of last update (set by duct push) */
|
|
162
178
|
updatedAt?: string;
|
|
163
179
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeepli
|
|
|
4
4
|
export type { GenerateTokenOptions, GenerateTokenResult, VerifyTokenOptions, VerifyTokenResult, GenerateDeeplinkTokenOptions, GenerateDeeplinkTokenResult, VerifyDeeplinkTokenOptions, VerifyDeeplinkResult, } from "./core/token.js";
|
|
5
5
|
export { createIntrospectHandler, createIntrospectPageHandler, createIntrospectExpressHandler, } from "./core/introspect.js";
|
|
6
6
|
export type { IntrospectEntity, IntrospectResult, IntrospectContext, IntrospectResolver, IntrospectHandlerOptions, } from "./core/introspect.js";
|
|
7
|
+
export { createPageResolveHandler, createPageResolvePageHandler, createPageResolveExpressHandler, } from "./core/page-resolve.js";
|
|
8
|
+
export type { DuctPageContext, PageResolveResult, PageResolveContext, PageResolveResolver, PageResolveHandlerOptions, } from "./core/page-resolve.js";
|
|
7
9
|
export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
|
|
8
10
|
export type { ActionSearchEntry } from "./core/action.js";
|
|
9
11
|
export { sendIntershellAction, sendIntershellQuery } from "./core/intershell.js";
|
package/dist/server.js
CHANGED
|
@@ -15,6 +15,8 @@ export { defineDuctConfig, DuctConfigSchema } from "./core/config.js";
|
|
|
15
15
|
export { generateDuctToken, verifyDuctToken, generateDeeplinkToken, verifyDeeplinkToken, } from "./core/token.js";
|
|
16
16
|
// Introspect handler factories
|
|
17
17
|
export { createIntrospectHandler, createIntrospectPageHandler, createIntrospectExpressHandler, } from "./core/introspect.js";
|
|
18
|
+
// Page-resolve handler factories (agent deeplink resolution)
|
|
19
|
+
export { createPageResolveHandler, createPageResolvePageHandler, createPageResolveExpressHandler, } from "./core/page-resolve.js";
|
|
18
20
|
// Action utilities (permission checking, search index)
|
|
19
21
|
export { buildAction, checkActionPermission, buildActionSearchIndex, shouldDeferActions, } from "./core/action.js";
|
|
20
22
|
// Cross-shell client (IS-29)
|