capman 0.5.5 → 0.6.1

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/bin/lib/cmd-generate.js +156 -12
  3. package/bin/lib/cmd-help.js +3 -0
  4. package/dist/cjs/cache.d.ts +9 -0
  5. package/dist/cjs/cache.d.ts.map +1 -1
  6. package/dist/cjs/cache.js +37 -7
  7. package/dist/cjs/cache.js.map +1 -1
  8. package/dist/cjs/engine.d.ts +68 -1
  9. package/dist/cjs/engine.d.ts.map +1 -1
  10. package/dist/cjs/engine.js +313 -13
  11. package/dist/cjs/engine.js.map +1 -1
  12. package/dist/cjs/generator.d.ts.map +1 -1
  13. package/dist/cjs/generator.js +28 -6
  14. package/dist/cjs/generator.js.map +1 -1
  15. package/dist/cjs/index.d.ts +3 -1
  16. package/dist/cjs/index.d.ts.map +1 -1
  17. package/dist/cjs/index.js +5 -1
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/learning.d.ts +7 -0
  20. package/dist/cjs/learning.d.ts.map +1 -1
  21. package/dist/cjs/learning.js +44 -23
  22. package/dist/cjs/learning.js.map +1 -1
  23. package/dist/cjs/matcher.d.ts +92 -0
  24. package/dist/cjs/matcher.d.ts.map +1 -1
  25. package/dist/cjs/matcher.js +354 -35
  26. package/dist/cjs/matcher.js.map +1 -1
  27. package/dist/cjs/parser.js +27 -9
  28. package/dist/cjs/parser.js.map +1 -1
  29. package/dist/cjs/resolver.d.ts +2 -2
  30. package/dist/cjs/resolver.d.ts.map +1 -1
  31. package/dist/cjs/resolver.js +66 -26
  32. package/dist/cjs/resolver.js.map +1 -1
  33. package/dist/cjs/schema.d.ts +865 -94
  34. package/dist/cjs/schema.d.ts.map +1 -1
  35. package/dist/cjs/schema.js +62 -12
  36. package/dist/cjs/schema.js.map +1 -1
  37. package/dist/cjs/types.d.ts +153 -9
  38. package/dist/cjs/types.d.ts.map +1 -1
  39. package/dist/cjs/version.d.ts +1 -1
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/esm/cache.d.ts +9 -0
  42. package/dist/esm/cache.js +37 -7
  43. package/dist/esm/engine.d.ts +68 -1
  44. package/dist/esm/engine.js +314 -14
  45. package/dist/esm/generator.js +28 -6
  46. package/dist/esm/index.d.ts +3 -1
  47. package/dist/esm/index.js +2 -0
  48. package/dist/esm/learning.d.ts +7 -0
  49. package/dist/esm/learning.js +45 -24
  50. package/dist/esm/matcher.d.ts +92 -0
  51. package/dist/esm/matcher.js +346 -35
  52. package/dist/esm/parser.js +27 -9
  53. package/dist/esm/resolver.d.ts +2 -2
  54. package/dist/esm/resolver.js +66 -26
  55. package/dist/esm/schema.d.ts +865 -94
  56. package/dist/esm/schema.js +62 -12
  57. package/dist/esm/types.d.ts +153 -9
  58. package/dist/esm/version.d.ts +1 -1
  59. package/dist/esm/version.js +1 -1
  60. package/package.json +1 -1
@@ -5,16 +5,22 @@ const CapabilityParamSchema = z.object({
5
5
  description: z.string().min(1, 'param description is required'),
6
6
  required: z.boolean(),
7
7
  source: z.enum(['user_query', 'session']),
8
- default: z.union([z.string(), z.number(), z.boolean()]).optional(),
9
- });
8
+ pattern: z.string().optional(),
9
+ type: z.enum(['string', 'number', 'boolean', 'date', 'email', 'url', 'enum', 'object']).optional(),
10
+ enum: z.array(z.string()).optional(),
11
+ example: z.string().optional(),
12
+ }).refine(p => !(p.type === 'enum' && (!p.enum || p.enum.length === 0)), { message: 'enum values required when type is "enum"' });
10
13
  // ─── Resolver Schemas ─────────────────────────────────────────────────────────
14
+ const EndpointSchema = z.object({
15
+ method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']),
16
+ path: z.string().min(1, 'endpoint path is required'),
17
+ params: z.array(z.string()).optional(),
18
+ idempotent: z.boolean().optional(),
19
+ idempotencyKey: z.string().optional(),
20
+ });
11
21
  const ApiResolverSchema = z.object({
12
22
  type: z.literal('api'),
13
- endpoints: z.array(z.object({
14
- method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),
15
- path: z.string().min(1, 'endpoint path is required'),
16
- params: z.array(z.string()).optional(),
17
- })).min(1, 'at least one endpoint is required'),
23
+ endpoints: z.array(EndpointSchema).min(1, 'at least one endpoint is required'),
18
24
  });
19
25
  const NavResolverSchema = z.object({
20
26
  type: z.literal('nav'),
@@ -24,11 +30,7 @@ const NavResolverSchema = z.object({
24
30
  const HybridResolverSchema = z.object({
25
31
  type: z.literal('hybrid'),
26
32
  api: z.object({
27
- endpoints: z.array(z.object({
28
- method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),
29
- path: z.string().min(1),
30
- params: z.array(z.string()).optional(),
31
- })).min(1),
33
+ endpoints: z.array(EndpointSchema).min(1),
32
34
  }),
33
35
  nav: z.object({
34
36
  destination: z.string().min(1),
@@ -45,6 +47,22 @@ const PrivacyScopeSchema = z.object({
45
47
  level: z.enum(['public', 'user_owned', 'admin']),
46
48
  note: z.string().optional(),
47
49
  });
50
+ const LifecycleInfoSchema = z.object({
51
+ status: z.enum(['stable', 'beta', 'experimental', 'deprecated']),
52
+ deprecatedAt: z.string().datetime().optional(),
53
+ sunsetAt: z.string().datetime().optional(),
54
+ successor: z.string().optional(),
55
+ note: z.string().optional(),
56
+ });
57
+ const MatchHintSchema = z.object({
58
+ preferredMode: z.enum(['cheap', 'balanced', 'accurate']).optional(),
59
+ });
60
+ const CapabilityErrorSchema = z.object({
61
+ code: z.string().min(1, 'error code is required'),
62
+ description: z.string().min(1, 'error description is required'),
63
+ httpStatus: z.number().int().min(400).max(599).optional(),
64
+ retryable: z.boolean().optional(),
65
+ });
48
66
  // ─── Capability Schema ────────────────────────────────────────────────────────
49
67
  const CapabilitySchema = z.object({
50
68
  id: z.string().min(1, 'capability id is required')
@@ -58,11 +76,39 @@ const CapabilitySchema = z.object({
58
76
  returns: z.array(z.string()),
59
77
  resolver: ResolverSchema,
60
78
  privacy: PrivacyScopeSchema,
79
+ lifecycle: LifecycleInfoSchema.optional(),
80
+ tags: z.array(z.string().min(1)).optional(),
81
+ errors: z.array(CapabilityErrorSchema).optional(),
82
+ matchHint: MatchHintSchema.optional(),
83
+ });
84
+ const ServerSchema = z.object({
85
+ url: z.string().url('server url must be a valid URL'),
86
+ description: z.string().optional(),
87
+ environment: z.string().optional(),
88
+ });
89
+ // ─── ManifestInfo Schema ──────────────────────────────────────────────────────
90
+ const ManifestInfoSchema = z.object({
91
+ title: z.string().optional(),
92
+ description: z.string().optional(),
93
+ version: z.string().optional(),
94
+ homepage: z.string().url().optional(),
95
+ contact: z.object({
96
+ name: z.string().optional(),
97
+ email: z.string().email().optional(),
98
+ url: z.string().url().optional(),
99
+ }).optional(),
100
+ license: z.object({
101
+ name: z.string().min(1, 'license name is required'),
102
+ url: z.string().url().optional(),
103
+ }).optional(),
61
104
  });
62
105
  // ─── Config Schema ────────────────────────────────────────────────────────────
63
106
  export const CapmanConfigSchema = z.object({
64
107
  app: z.string().min(1, 'app name is required'),
65
108
  baseUrl: z.string().url().optional(),
109
+ info: ManifestInfoSchema.optional(),
110
+ servers: z.array(ServerSchema).optional(),
111
+ tagRegistry: z.record(z.object({ description: z.string() })).optional(),
66
112
  capabilities: z.array(CapabilitySchema)
67
113
  .min(1, 'at least one capability is required')
68
114
  .refine(caps => new Set(caps.map(c => c.id)).size === caps.length, 'capability ids must be unique'),
@@ -72,10 +118,14 @@ export const CapmanConfigSchema = z.object({
72
118
  }, { message: 'baseUrl is required when any capability uses an api or hybrid resolver' });
73
119
  // ─── Manifest Schema ──────────────────────────────────────────────────────────
74
120
  export const ManifestSchema = z.object({
121
+ schemaVersion: z.string().min(1, 'schemaVersion is required'),
75
122
  version: z.string(),
76
123
  app: z.string().min(1),
77
124
  generatedAt: z.string().datetime(),
78
125
  capabilities: z.array(CapabilitySchema).min(1),
126
+ tagRegistry: z.record(z.object({ description: z.string() })).optional(),
127
+ servers: z.array(ServerSchema).optional(),
128
+ info: ManifestInfoSchema.optional(),
79
129
  });
80
130
  export function validateConfig(config) {
81
131
  const result = CapmanConfigSchema.safeParse(config);
@@ -1,19 +1,58 @@
1
1
  export type ResolverType = 'api' | 'nav' | 'hybrid';
2
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
2
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
3
+ export type ParamType = 'string' | 'number' | 'boolean' | 'date' | 'email' | 'url' | 'enum' | 'object';
3
4
  export interface CapabilityParam {
4
5
  name: string;
5
6
  description: string;
6
7
  required: boolean;
7
8
  source: 'user_query' | 'session';
8
- default?: string | number | boolean;
9
+ /**
10
+ * Optional extraction hint. Either a named type or an example template.
11
+ * Named types: 'email' | 'date' | 'orderId' | 'url'
12
+ * Example template: "order {paramName}" — extracts token after "order"
13
+ */
14
+ pattern?: string;
15
+ /**
16
+ * Semantic type of the parameter value.
17
+ * When set, implies a TYPE_PATTERNS match without requiring pattern to be set.
18
+ * 'email', 'date', 'url' map directly to TYPE_PATTERNS regex.
19
+ * 'enum' requires the enum field to be set with allowed values.
20
+ * 'number', 'boolean', 'object' affect coercion in LLM extraction.
21
+ */
22
+ type?: ParamType;
23
+ /**
24
+ * Allowed values when type === 'enum'.
25
+ * Extracted values not in this list are rejected and added to missingParams.
26
+ */
27
+ enum?: string[];
28
+ /**
29
+ * Single concrete example for LLM param prompting.
30
+ * Helps the LLM understand what a valid value looks like.
31
+ * e.g. example: "ORD-12345"
32
+ */
33
+ example?: string;
34
+ }
35
+ export interface Endpoint {
36
+ method: HttpMethod;
37
+ path: string;
38
+ params?: string[];
39
+ /**
40
+ * Whether this endpoint is idempotent — safe to retry on failure.
41
+ * Defaults: true for GET/HEAD/OPTIONS, false for POST/PUT/PATCH/DELETE.
42
+ * Set explicitly to override — e.g. `idempotent: true` on a POST
43
+ * with an idempotency key allows retries without `retryAllMethods: true`.
44
+ */
45
+ idempotent?: boolean;
46
+ /**
47
+ * Name of the param whose value is sent as the `Idempotency-Key` header.
48
+ * When set and the param is available, the header is injected automatically.
49
+ * e.g. idempotencyKey: 'order_id' → `Idempotency-Key: ORD-12345`
50
+ */
51
+ idempotencyKey?: string;
9
52
  }
10
53
  export interface ApiResolver {
11
54
  type: 'api';
12
- endpoints: Array<{
13
- method: HttpMethod;
14
- path: string;
15
- params?: string[];
16
- }>;
55
+ endpoints: Endpoint[];
17
56
  }
18
57
  export interface NavResolver {
19
58
  type: 'nav';
@@ -30,6 +69,41 @@ export interface PrivacyScope {
30
69
  level: 'public' | 'user_owned' | 'admin';
31
70
  note?: string;
32
71
  }
72
+ export type LifecycleStatus = 'stable' | 'beta' | 'experimental' | 'deprecated';
73
+ export interface LifecycleInfo {
74
+ status: LifecycleStatus;
75
+ /** ISO 8601 — when the capability was deprecated */
76
+ deprecatedAt?: string;
77
+ /** ISO 8601 — when the capability will stop working */
78
+ sunsetAt?: string;
79
+ /** Capability id to use instead of this one */
80
+ successor?: string;
81
+ /** Human-readable note for consumers */
82
+ note?: string;
83
+ }
84
+ export interface MatchHint {
85
+ /**
86
+ * Advisory preferred matching mode for this capability.
87
+ * The engine logs when it ignores the hint (e.g. engine is in cheap mode
88
+ * but capability prefers accurate). Never enforced — library must not
89
+ * restrict what consumers can do.
90
+ */
91
+ preferredMode?: MatchMode;
92
+ }
93
+ export interface CapabilityError {
94
+ /** Machine-readable error code e.g. "ORDER_NOT_FOUND", "INSUFFICIENT_FUNDS" */
95
+ code: string;
96
+ /** Human-readable description for developers */
97
+ description: string;
98
+ /** HTTP status code this error maps to */
99
+ httpStatus?: number;
100
+ /**
101
+ * Whether the agent should retry after this error.
102
+ * true — transient (503, timeout) — retry is safe
103
+ * false — permanent (422, 404) — retrying won't help, ask user
104
+ */
105
+ retryable?: boolean;
106
+ }
33
107
  export interface Capability {
34
108
  id: string;
35
109
  name: string;
@@ -39,17 +113,82 @@ export interface Capability {
39
113
  returns: string[];
40
114
  resolver: Resolver;
41
115
  privacy: PrivacyScope;
116
+ /** Lifecycle status — defaults to 'stable' when absent */
117
+ lifecycle?: LifecycleInfo;
118
+ /** Tags for grouping and filtering capabilities */
119
+ tags?: string[];
120
+ errors?: CapabilityError[];
121
+ matchHint?: MatchHint;
122
+ }
123
+ export interface ManifestInfo {
124
+ /** Human-readable title for the app */
125
+ title?: string;
126
+ /** Brief description of what the app does */
127
+ description?: string;
128
+ /** App's own version — distinct from capman package version */
129
+ version?: string;
130
+ /** URL to the app's homepage or documentation */
131
+ homepage?: string;
132
+ contact?: {
133
+ name?: string;
134
+ email?: string;
135
+ url?: string;
136
+ };
137
+ license?: {
138
+ /** SPDX license identifier e.g. "MIT", "Apache-2.0" */
139
+ name: string;
140
+ url?: string;
141
+ };
142
+ }
143
+ export interface Server {
144
+ url: string;
145
+ description?: string;
146
+ /**
147
+ * Environment this server belongs to.
148
+ * Engine selects server by matching EngineOptions.environment.
149
+ * Fallback: first server in array when no environment matches.
150
+ */
151
+ environment?: 'production' | 'staging' | 'development' | string;
42
152
  }
43
153
  export interface Manifest {
154
+ /**
155
+ * Manifest format version — independent of the capman package version.
156
+ * Consumers use this to determine which parser/validator to apply.
157
+ * "1" = v0.6+ schema (tags, lifecycle, typed params, servers, etc.)
158
+ */
159
+ schemaVersion: string;
160
+ /** capman package version that generated this manifest */
44
161
  version: string;
45
162
  app: string;
46
163
  generatedAt: string;
47
164
  capabilities: Capability[];
165
+ /**
166
+ * Optional registry of known tags with descriptions.
167
+ * Used for documentation and validation — not required for tags to work.
168
+ */
169
+ tagRegistry?: Record<string, {
170
+ description: string;
171
+ }>;
172
+ /** Optional metadata block for documentation and provenance */
173
+ info?: ManifestInfo;
174
+ /**
175
+ * Server definitions. When present, engine selects baseUrl from this list.
176
+ * Falls back to EngineOptions.baseUrl if servers is absent or no match found.
177
+ */
178
+ servers?: Server[];
48
179
  }
49
180
  export interface CapmanConfig {
50
181
  app: string;
51
182
  baseUrl?: string;
52
183
  capabilities: Capability[];
184
+ /** Optional metadata — written to manifest.info */
185
+ info?: ManifestInfo;
186
+ /** Optional tag registry — written to manifest.tagRegistry */
187
+ tagRegistry?: Record<string, {
188
+ description: string;
189
+ }>;
190
+ /** Server definitions — written to manifest.servers */
191
+ servers?: Server[];
53
192
  }
54
193
  export interface MatchResult {
55
194
  capability: Capability | null;
@@ -68,15 +207,20 @@ export interface ApiCallResult {
68
207
  status?: number;
69
208
  /** Parsed JSON response body — only present when actually executed */
70
209
  data?: unknown;
210
+ /** Error message — only present on network-level failure (status 0) */
211
+ error?: string;
71
212
  }
72
213
  export interface ResolveResult {
73
214
  success: boolean;
74
215
  resolverType: ResolverType | null;
216
+ error?: string;
217
+ /** Structured error from capability.errors[] when httpStatus matches */
218
+ matchedError?: CapabilityError;
75
219
  apiCalls?: ApiCallResult[];
76
220
  navTarget?: string;
77
- /** Execution time in milliseconds */
221
+ status?: number;
222
+ data?: unknown;
78
223
  durationMs?: number;
79
- error?: string;
80
224
  }
81
225
  export interface ValidationResult {
82
226
  valid: boolean;
@@ -1 +1 @@
1
- export declare const VERSION = "0.5.5";
1
+ export declare const VERSION = "0.6.0";
@@ -1,2 +1,2 @@
1
1
  // Auto-generated by scripts/version.js — do not edit manually
2
- export const VERSION = '0.5.5';
2
+ export const VERSION = '0.6.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capman",
3
- "version": "0.5.5",
3
+ "version": "0.6.1",
4
4
  "description": "Capability Manifest Engine — let AI agents interact with your app without navigating the UI",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",