@trikhub/manifest 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/LICENSE +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +388 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validator.d.ts +37 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +187 -0
- package/dist/validator.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Muffles
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { JSONSchema, TrikManifest, TrikCapabilities, TrikLimits, TrikEntry, ExecuteRequest, ExecuteResponse, SuccessResponse, ClarificationResponse, ErrorResponse, ClarifyRequest, ClarificationQuestion, ClarificationAnswer, GatewayResult, GatewaySuccess, GatewaySuccessTemplate, GatewaySuccessPassthrough, GatewayError, GatewayClarification, GatewayErrorCode, AllowedAgentStringFormat, ResponseMode, ResponseTemplate, ActionDefinition, SessionCapabilities, SessionHistoryEntry, TrikSession, SessionContext, GraphInput, GraphResult, PassthroughContent, PassthroughDeliveryReceipt, UserContentReference, } from './types.js';
|
|
2
|
+
export { validateManifest, validateData, createValidator, SchemaValidator, type ValidationResult, } from './validator.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,yBAAyB,EACzB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAEhB,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAEhB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,UAAU,EACV,WAAW,EAEX,kBAAkB,EAClB,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwCA,aAAa;AACb,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,GAEhB,MAAM,gBAAgB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema type (subset for our needs)
|
|
3
|
+
*/
|
|
4
|
+
export interface JSONSchema {
|
|
5
|
+
type?: string | string[];
|
|
6
|
+
properties?: Record<string, JSONSchema>;
|
|
7
|
+
items?: JSONSchema;
|
|
8
|
+
required?: string[];
|
|
9
|
+
enum?: unknown[];
|
|
10
|
+
const?: unknown;
|
|
11
|
+
$ref?: string;
|
|
12
|
+
$defs?: Record<string, JSONSchema>;
|
|
13
|
+
additionalProperties?: boolean | JSONSchema;
|
|
14
|
+
minLength?: number;
|
|
15
|
+
maxLength?: number;
|
|
16
|
+
minimum?: number;
|
|
17
|
+
maximum?: number;
|
|
18
|
+
pattern?: string;
|
|
19
|
+
format?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
default?: unknown;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Session capabilities for multi-turn conversations
|
|
26
|
+
*/
|
|
27
|
+
export interface SessionCapabilities {
|
|
28
|
+
/** Whether session state is enabled for this trik */
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
/** Maximum session duration in milliseconds (default: 30 minutes) */
|
|
31
|
+
maxDurationMs?: number;
|
|
32
|
+
/** Maximum number of history entries to keep (default: 20) */
|
|
33
|
+
maxHistoryEntries?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Trik capabilities declared in manifest
|
|
37
|
+
*/
|
|
38
|
+
export interface TrikCapabilities {
|
|
39
|
+
/** List of tool names this trik uses */
|
|
40
|
+
tools: string[];
|
|
41
|
+
/** Whether trik can request clarification from user */
|
|
42
|
+
canRequestClarification: boolean;
|
|
43
|
+
/** Session capabilities for multi-turn conversations */
|
|
44
|
+
session?: SessionCapabilities;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resource limits for trik execution
|
|
48
|
+
*/
|
|
49
|
+
export interface TrikLimits {
|
|
50
|
+
/** Maximum execution time in milliseconds */
|
|
51
|
+
maxExecutionTimeMs: number;
|
|
52
|
+
/** Maximum number of LLM calls allowed */
|
|
53
|
+
maxLlmCalls: number;
|
|
54
|
+
/** Maximum number of tool calls allowed */
|
|
55
|
+
maxToolCalls: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Entry point configuration
|
|
59
|
+
*/
|
|
60
|
+
export interface TrikEntry {
|
|
61
|
+
/** Path to the compiled module (relative to trik directory) */
|
|
62
|
+
module: string;
|
|
63
|
+
/** Export name to use (usually "default") */
|
|
64
|
+
export: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Request to execute a trik
|
|
68
|
+
*/
|
|
69
|
+
export interface ExecuteRequest {
|
|
70
|
+
requestId: string;
|
|
71
|
+
input: unknown;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Clarification question from a trik
|
|
75
|
+
*/
|
|
76
|
+
export interface ClarificationQuestion {
|
|
77
|
+
questionId: string;
|
|
78
|
+
questionText: string;
|
|
79
|
+
questionType: 'text' | 'multiple_choice' | 'boolean';
|
|
80
|
+
options?: string[];
|
|
81
|
+
required?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Answer to a clarification question
|
|
85
|
+
*/
|
|
86
|
+
export interface ClarificationAnswer {
|
|
87
|
+
questionId: string;
|
|
88
|
+
answer: string | boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Request to provide clarification answers
|
|
92
|
+
*/
|
|
93
|
+
export interface ClarifyRequest {
|
|
94
|
+
sessionId: string;
|
|
95
|
+
answers: ClarificationAnswer[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Successful execution response
|
|
99
|
+
*/
|
|
100
|
+
export interface SuccessResponse {
|
|
101
|
+
requestId: string;
|
|
102
|
+
type: 'result';
|
|
103
|
+
agentData: unknown;
|
|
104
|
+
userContent?: unknown;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Clarification needed response
|
|
108
|
+
*/
|
|
109
|
+
export interface ClarificationResponse {
|
|
110
|
+
requestId: string;
|
|
111
|
+
type: 'clarification_needed';
|
|
112
|
+
sessionId: string;
|
|
113
|
+
questions: ClarificationQuestion[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Error response
|
|
117
|
+
*/
|
|
118
|
+
export interface ErrorResponse {
|
|
119
|
+
requestId: string;
|
|
120
|
+
type: 'error';
|
|
121
|
+
code: string;
|
|
122
|
+
message: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Union of all possible execution responses
|
|
126
|
+
*/
|
|
127
|
+
export type ExecuteResponse = SuccessResponse | ClarificationResponse | ErrorResponse;
|
|
128
|
+
export type GatewayErrorCode = 'TRIK_NOT_FOUND' | 'INVALID_INPUT' | 'INVALID_OUTPUT' | 'TIMEOUT' | 'EXECUTION_ERROR' | 'NOT_ALLOWED' | 'NETWORK_ERROR';
|
|
129
|
+
export interface GatewayError {
|
|
130
|
+
success: false;
|
|
131
|
+
code: GatewayErrorCode;
|
|
132
|
+
error: string;
|
|
133
|
+
details?: unknown;
|
|
134
|
+
}
|
|
135
|
+
export interface GatewayClarification {
|
|
136
|
+
success: false;
|
|
137
|
+
code: 'CLARIFICATION_NEEDED';
|
|
138
|
+
sessionId: string;
|
|
139
|
+
questions: ClarificationQuestion[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Allowed string formats in agentDataSchema.
|
|
143
|
+
* These are safe because they have constrained, predictable values.
|
|
144
|
+
*/
|
|
145
|
+
export type AllowedAgentStringFormat = 'id' | 'date' | 'date-time' | 'uuid' | 'email' | 'url';
|
|
146
|
+
/**
|
|
147
|
+
* Response template for agent responses.
|
|
148
|
+
* Templates are filled with values from agentData only.
|
|
149
|
+
*/
|
|
150
|
+
export interface ResponseTemplate {
|
|
151
|
+
/** The template text with {{placeholder}} syntax */
|
|
152
|
+
text: string;
|
|
153
|
+
/** Optional condition for when to use this template */
|
|
154
|
+
condition?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Response mode for an action.
|
|
158
|
+
* - template: Agent sees agentData + template, fills and outputs directly
|
|
159
|
+
* - passthrough: Agent gets receipt only, content flows through passthrough renderer
|
|
160
|
+
*/
|
|
161
|
+
export type ResponseMode = 'template' | 'passthrough';
|
|
162
|
+
/**
|
|
163
|
+
* Action definition for triks.
|
|
164
|
+
* Each action declares ONE response mode: template OR passthrough.
|
|
165
|
+
*/
|
|
166
|
+
export interface ActionDefinition {
|
|
167
|
+
/** Description of what this action does */
|
|
168
|
+
description?: string;
|
|
169
|
+
/** JSON Schema for action input */
|
|
170
|
+
inputSchema: JSONSchema;
|
|
171
|
+
/**
|
|
172
|
+
* Response mode for this action.
|
|
173
|
+
* - "template": Agent sees agentData + template text, fills it, outputs directly
|
|
174
|
+
* - "passthrough": Agent gets receipt only, content delivered via passthrough renderer
|
|
175
|
+
*/
|
|
176
|
+
responseMode: ResponseMode;
|
|
177
|
+
/**
|
|
178
|
+
* Schema for data the agent can reason over (template mode).
|
|
179
|
+
* MUST NOT contain free-form strings - only:
|
|
180
|
+
* - integers, numbers, booleans
|
|
181
|
+
* - strings with enum constraint
|
|
182
|
+
* - strings with format constraint (id, date, date-time, uuid, email, url)
|
|
183
|
+
* - strings with pattern constraint
|
|
184
|
+
* - arrays/objects containing only the above
|
|
185
|
+
*
|
|
186
|
+
* Required for template mode.
|
|
187
|
+
*/
|
|
188
|
+
agentDataSchema?: JSONSchema;
|
|
189
|
+
/**
|
|
190
|
+
* Response templates keyed by template ID (template mode).
|
|
191
|
+
* Agent selects which template to use via agentData.template field.
|
|
192
|
+
* Templates can only reference fields from agentDataSchema.
|
|
193
|
+
*
|
|
194
|
+
* Required for template mode.
|
|
195
|
+
*/
|
|
196
|
+
responseTemplates?: Record<string, ResponseTemplate>;
|
|
197
|
+
/**
|
|
198
|
+
* Schema for content shown to the user (passthrough mode).
|
|
199
|
+
* Free-form strings allowed here.
|
|
200
|
+
* This content is delivered via passthrough renderer - agent never sees it.
|
|
201
|
+
*
|
|
202
|
+
* Required for passthrough mode.
|
|
203
|
+
*/
|
|
204
|
+
userContentSchema?: JSONSchema;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The trik manifest - the single source of truth for the trik contract.
|
|
208
|
+
* Triks define actions with type-directed privilege separation.
|
|
209
|
+
*/
|
|
210
|
+
export interface TrikManifest {
|
|
211
|
+
/** Unique identifier for the trik */
|
|
212
|
+
id: string;
|
|
213
|
+
/** Human-readable name */
|
|
214
|
+
name: string;
|
|
215
|
+
/** Description of what the trik does */
|
|
216
|
+
description: string;
|
|
217
|
+
/** Semantic version */
|
|
218
|
+
version: string;
|
|
219
|
+
/** Map of action names to their definitions */
|
|
220
|
+
actions: Record<string, ActionDefinition>;
|
|
221
|
+
/** Declared capabilities */
|
|
222
|
+
capabilities: TrikCapabilities;
|
|
223
|
+
/** Resource limits */
|
|
224
|
+
limits: TrikLimits;
|
|
225
|
+
/** Entry point */
|
|
226
|
+
entry: TrikEntry;
|
|
227
|
+
/** Optional: author name */
|
|
228
|
+
author?: string;
|
|
229
|
+
/** Optional: repository URL */
|
|
230
|
+
repository?: string;
|
|
231
|
+
/** Optional: license identifier */
|
|
232
|
+
license?: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Gateway success for template mode
|
|
236
|
+
*/
|
|
237
|
+
export interface GatewaySuccessTemplate<TAgent> {
|
|
238
|
+
success: true;
|
|
239
|
+
/** Response mode */
|
|
240
|
+
responseMode: 'template';
|
|
241
|
+
/** Data for agent reasoning - structured, no free text */
|
|
242
|
+
agentData: TAgent;
|
|
243
|
+
/** Template text for agent to fill with agentData values */
|
|
244
|
+
templateText?: string;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Gateway success for passthrough mode
|
|
248
|
+
*/
|
|
249
|
+
export interface GatewaySuccessPassthrough {
|
|
250
|
+
success: true;
|
|
251
|
+
/** Response mode */
|
|
252
|
+
responseMode: 'passthrough';
|
|
253
|
+
/** Reference to content that will be delivered via passthrough */
|
|
254
|
+
userContentRef: string;
|
|
255
|
+
/** Content type for the receipt */
|
|
256
|
+
contentType: string;
|
|
257
|
+
/** Optional metadata the agent can see */
|
|
258
|
+
metadata?: Record<string, unknown>;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Gateway success - either template or passthrough mode
|
|
262
|
+
*/
|
|
263
|
+
export type GatewaySuccess<TAgent = unknown> = GatewaySuccessTemplate<TAgent> | GatewaySuccessPassthrough;
|
|
264
|
+
/**
|
|
265
|
+
* Gateway result type
|
|
266
|
+
*/
|
|
267
|
+
export type GatewayResult<TAgent = unknown> = GatewaySuccess<TAgent> | GatewayError | GatewayClarification;
|
|
268
|
+
/**
|
|
269
|
+
* User content with content type for passthrough mode.
|
|
270
|
+
* When userContent has this structure and contentType matches
|
|
271
|
+
* passthroughContentTypes, it can be delivered via passthrough.
|
|
272
|
+
*/
|
|
273
|
+
export interface PassthroughContent {
|
|
274
|
+
/** Type of content being delivered (e.g., "recipe", "article") */
|
|
275
|
+
contentType: string;
|
|
276
|
+
/** The actual free-text content */
|
|
277
|
+
content: string;
|
|
278
|
+
/** Optional metadata that the agent CAN see */
|
|
279
|
+
metadata?: Record<string, unknown>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Receipt returned to agent after passthrough delivery.
|
|
283
|
+
* The agent sees this instead of the actual content.
|
|
284
|
+
*/
|
|
285
|
+
export interface PassthroughDeliveryReceipt {
|
|
286
|
+
/** Indicates content was delivered */
|
|
287
|
+
delivered: true;
|
|
288
|
+
/** What type of content was delivered */
|
|
289
|
+
contentType: string;
|
|
290
|
+
/** Optional metadata from the content (safe data only) */
|
|
291
|
+
metadata?: Record<string, unknown>;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Content reference stored by gateway for later delivery.
|
|
295
|
+
*/
|
|
296
|
+
export interface UserContentReference {
|
|
297
|
+
/** Unique reference ID */
|
|
298
|
+
ref: string;
|
|
299
|
+
/** The trik and action that produced this content */
|
|
300
|
+
trikId: string;
|
|
301
|
+
actionName: string;
|
|
302
|
+
/** The actual content (stored, not returned to agent) */
|
|
303
|
+
content: PassthroughContent;
|
|
304
|
+
/** When this reference was created */
|
|
305
|
+
createdAt: number;
|
|
306
|
+
/** When this reference expires */
|
|
307
|
+
expiresAt: number;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Entry in the session history.
|
|
311
|
+
* Triks receive the full history to resolve references like "the healthcare article".
|
|
312
|
+
*/
|
|
313
|
+
export interface SessionHistoryEntry {
|
|
314
|
+
/** When this entry was created */
|
|
315
|
+
timestamp: number;
|
|
316
|
+
/** Which action was called */
|
|
317
|
+
action: string;
|
|
318
|
+
/** The input that was passed to the action */
|
|
319
|
+
input: unknown;
|
|
320
|
+
/** The agentData returned by the action */
|
|
321
|
+
agentData: unknown;
|
|
322
|
+
/** The userContent returned by the action (trik can use for reference resolution) */
|
|
323
|
+
userContent?: unknown;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Session state maintained by the gateway.
|
|
327
|
+
* Passed to triks so they can resolve references and maintain context.
|
|
328
|
+
*/
|
|
329
|
+
export interface TrikSession {
|
|
330
|
+
/** Unique session identifier */
|
|
331
|
+
sessionId: string;
|
|
332
|
+
/** Trik this session belongs to */
|
|
333
|
+
trikId: string;
|
|
334
|
+
/** When the session was created */
|
|
335
|
+
createdAt: number;
|
|
336
|
+
/** When the session was last accessed */
|
|
337
|
+
lastActivityAt: number;
|
|
338
|
+
/** When the session expires */
|
|
339
|
+
expiresAt: number;
|
|
340
|
+
/** History of previous interactions */
|
|
341
|
+
history: SessionHistoryEntry[];
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Session context passed to triks in graph input
|
|
345
|
+
*/
|
|
346
|
+
export interface SessionContext {
|
|
347
|
+
/** Session identifier */
|
|
348
|
+
sessionId: string;
|
|
349
|
+
/** Full history for reference resolution */
|
|
350
|
+
history: SessionHistoryEntry[];
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Input passed to a trik graph
|
|
354
|
+
*/
|
|
355
|
+
export interface GraphInput {
|
|
356
|
+
/** The action input */
|
|
357
|
+
input: unknown;
|
|
358
|
+
/** Which action to execute */
|
|
359
|
+
action: string;
|
|
360
|
+
/** Clarification answers if resuming from clarification */
|
|
361
|
+
clarificationAnswers?: Record<string, string | boolean>;
|
|
362
|
+
/** Session context for multi-turn conversations */
|
|
363
|
+
session?: SessionContext;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Result returned from a trik graph
|
|
367
|
+
*/
|
|
368
|
+
export interface GraphResult {
|
|
369
|
+
/**
|
|
370
|
+
* Response mode for this result.
|
|
371
|
+
* Can override the manifest's default responseMode for this action.
|
|
372
|
+
* Useful when no template fits and trik wants to return free-form content.
|
|
373
|
+
*/
|
|
374
|
+
responseMode?: ResponseMode;
|
|
375
|
+
/** Data for agent reasoning - structured, no free text (template mode) */
|
|
376
|
+
agentData?: unknown;
|
|
377
|
+
/** Content for user display - free text (passthrough mode) */
|
|
378
|
+
userContent?: unknown;
|
|
379
|
+
/** Whether clarification is needed */
|
|
380
|
+
needsClarification?: boolean;
|
|
381
|
+
/** Single clarification question */
|
|
382
|
+
clarificationQuestion?: ClarificationQuestion;
|
|
383
|
+
/** Multiple clarification questions */
|
|
384
|
+
clarificationQuestions?: ClarificationQuestion[];
|
|
385
|
+
/** If true, end the session after this response */
|
|
386
|
+
endSession?: boolean;
|
|
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C,sBAAsB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACjD,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ValidateFunction } from 'ajv';
|
|
2
|
+
import type { JSONSchema } from './types.js';
|
|
3
|
+
export interface ValidationResult {
|
|
4
|
+
valid: boolean;
|
|
5
|
+
errors?: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Validate a trik manifest
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateManifest(manifest: unknown): ValidationResult;
|
|
11
|
+
/**
|
|
12
|
+
* Create a validator function for a given JSON Schema
|
|
13
|
+
*/
|
|
14
|
+
export declare function createValidator(schema: JSONSchema): ValidateFunction;
|
|
15
|
+
/**
|
|
16
|
+
* Validate data against a JSON Schema
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateData(schema: JSONSchema, data: unknown): ValidationResult;
|
|
19
|
+
/**
|
|
20
|
+
* Validator class that caches compiled schemas
|
|
21
|
+
*/
|
|
22
|
+
export declare class SchemaValidator {
|
|
23
|
+
private cache;
|
|
24
|
+
/**
|
|
25
|
+
* Get or create a validator for the given schema
|
|
26
|
+
*/
|
|
27
|
+
getValidator(schemaId: string, schema: JSONSchema): ValidateFunction;
|
|
28
|
+
/**
|
|
29
|
+
* Validate data against a cached schema
|
|
30
|
+
*/
|
|
31
|
+
validate(schemaId: string, schema: JSONSchema, data: unknown): ValidationResult;
|
|
32
|
+
/**
|
|
33
|
+
* Clear the schema cache
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,KAAK,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA+G7C,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAaD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,OAAO,GAAG,gBAAgB,CASpE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,gBAAgB,CAEpE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAUhF;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAuC;IAEpD;;OAEG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,gBAAgB;IAUpE;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB;IAY/E;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
// Create Ajv instance
|
|
3
|
+
const ajv = new Ajv.default({ allErrors: true, strict: false });
|
|
4
|
+
/**
|
|
5
|
+
* Common manifest properties
|
|
6
|
+
*/
|
|
7
|
+
const commonManifestProperties = {
|
|
8
|
+
id: { type: 'string', minLength: 1 },
|
|
9
|
+
name: { type: 'string', minLength: 1 },
|
|
10
|
+
description: { type: 'string' },
|
|
11
|
+
version: { type: 'string', pattern: '^\\d+\\.\\d+\\.\\d+' },
|
|
12
|
+
capabilities: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
tools: { type: 'array', items: { type: 'string' } },
|
|
16
|
+
canRequestClarification: { type: 'boolean' },
|
|
17
|
+
},
|
|
18
|
+
required: ['tools', 'canRequestClarification'],
|
|
19
|
+
},
|
|
20
|
+
limits: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
maxExecutionTimeMs: { type: 'number', minimum: 0 },
|
|
24
|
+
maxLlmCalls: { type: 'number', minimum: 0 },
|
|
25
|
+
maxToolCalls: { type: 'number', minimum: 0 },
|
|
26
|
+
},
|
|
27
|
+
required: ['maxExecutionTimeMs', 'maxLlmCalls', 'maxToolCalls'],
|
|
28
|
+
},
|
|
29
|
+
entry: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
module: { type: 'string', minLength: 1 },
|
|
33
|
+
export: { type: 'string', minLength: 1 },
|
|
34
|
+
},
|
|
35
|
+
required: ['module', 'export'],
|
|
36
|
+
},
|
|
37
|
+
author: { type: 'string' },
|
|
38
|
+
repository: { type: 'string' },
|
|
39
|
+
license: { type: 'string' },
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Action definition for template mode (requires agentDataSchema + responseTemplates)
|
|
43
|
+
*/
|
|
44
|
+
const actionSchemaTemplate = {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: {
|
|
47
|
+
responseMode: { type: 'string', const: 'template' },
|
|
48
|
+
inputSchema: { type: 'object' },
|
|
49
|
+
agentDataSchema: { type: 'object' },
|
|
50
|
+
userContentSchema: { type: 'object' },
|
|
51
|
+
responseTemplates: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
additionalProperties: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
text: { type: 'string' },
|
|
57
|
+
},
|
|
58
|
+
required: ['text'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
description: { type: 'string' },
|
|
62
|
+
},
|
|
63
|
+
required: ['responseMode', 'inputSchema', 'agentDataSchema', 'responseTemplates'],
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Action definition for passthrough mode (requires userContentSchema)
|
|
67
|
+
*/
|
|
68
|
+
const actionSchemaPassthrough = {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
responseMode: { type: 'string', const: 'passthrough' },
|
|
72
|
+
inputSchema: { type: 'object' },
|
|
73
|
+
userContentSchema: { type: 'object' },
|
|
74
|
+
description: { type: 'string' },
|
|
75
|
+
},
|
|
76
|
+
required: ['responseMode', 'inputSchema', 'userContentSchema'],
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* JSON Schema for validating TrikManifest
|
|
80
|
+
*/
|
|
81
|
+
const manifestSchema = {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
...commonManifestProperties,
|
|
85
|
+
actions: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
additionalProperties: {
|
|
88
|
+
anyOf: [actionSchemaTemplate, actionSchemaPassthrough],
|
|
89
|
+
},
|
|
90
|
+
minProperties: 1,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
required: [
|
|
94
|
+
'id',
|
|
95
|
+
'name',
|
|
96
|
+
'description',
|
|
97
|
+
'version',
|
|
98
|
+
'actions',
|
|
99
|
+
'capabilities',
|
|
100
|
+
'limits',
|
|
101
|
+
'entry',
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
const validateManifestSchema = ajv.compile(manifestSchema);
|
|
105
|
+
/**
|
|
106
|
+
* Format ajv errors into readable strings
|
|
107
|
+
*/
|
|
108
|
+
function formatErrors(errors) {
|
|
109
|
+
if (!errors)
|
|
110
|
+
return [];
|
|
111
|
+
return errors.map((e) => {
|
|
112
|
+
const path = e.instancePath || 'root';
|
|
113
|
+
return `${path}: ${e.message}`;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Validate a trik manifest
|
|
118
|
+
*/
|
|
119
|
+
export function validateManifest(manifest) {
|
|
120
|
+
const valid = validateManifestSchema(manifest);
|
|
121
|
+
if (valid) {
|
|
122
|
+
return { valid: true };
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
valid: false,
|
|
126
|
+
errors: formatErrors(validateManifestSchema.errors),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a validator function for a given JSON Schema
|
|
131
|
+
*/
|
|
132
|
+
export function createValidator(schema) {
|
|
133
|
+
return ajv.compile(schema);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Validate data against a JSON Schema
|
|
137
|
+
*/
|
|
138
|
+
export function validateData(schema, data) {
|
|
139
|
+
const validate = ajv.compile(schema);
|
|
140
|
+
const valid = validate(data);
|
|
141
|
+
if (valid) {
|
|
142
|
+
return { valid: true };
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
valid: false,
|
|
146
|
+
errors: formatErrors(validate.errors),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validator class that caches compiled schemas
|
|
151
|
+
*/
|
|
152
|
+
export class SchemaValidator {
|
|
153
|
+
cache = new Map();
|
|
154
|
+
/**
|
|
155
|
+
* Get or create a validator for the given schema
|
|
156
|
+
*/
|
|
157
|
+
getValidator(schemaId, schema) {
|
|
158
|
+
const cached = this.cache.get(schemaId);
|
|
159
|
+
if (cached) {
|
|
160
|
+
return cached;
|
|
161
|
+
}
|
|
162
|
+
const validator = ajv.compile(schema);
|
|
163
|
+
this.cache.set(schemaId, validator);
|
|
164
|
+
return validator;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validate data against a cached schema
|
|
168
|
+
*/
|
|
169
|
+
validate(schemaId, schema, data) {
|
|
170
|
+
const validator = this.getValidator(schemaId, schema);
|
|
171
|
+
const valid = validator(data);
|
|
172
|
+
if (valid) {
|
|
173
|
+
return { valid: true };
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
valid: false,
|
|
177
|
+
errors: formatErrors(validator.errors),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Clear the schema cache
|
|
182
|
+
*/
|
|
183
|
+
clear() {
|
|
184
|
+
this.cache.clear();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAItB,sBAAsB;AACtB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,wBAAwB,GAAG;IAC/B,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;IACpC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;IACtC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC/B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,EAAE;IAC3D,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YACnD,uBAAuB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;SAC7C;QACD,QAAQ,EAAE,CAAC,OAAO,EAAE,yBAAyB,CAAC;KAC/C;IACD,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,kBAAkB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;YAClD,WA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CAAC;IACnB,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,QAAgB,EAAE,MAAkB,EAAE,IAAa;QAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QACD,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC;SACvC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trikhub/manifest",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type definitions and validation for trik manifests",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ai",
|
|
21
|
+
"agent",
|
|
22
|
+
"trik",
|
|
23
|
+
"manifest",
|
|
24
|
+
"validation",
|
|
25
|
+
"schema",
|
|
26
|
+
"typescript",
|
|
27
|
+
"trikhub"
|
|
28
|
+
],
|
|
29
|
+
"author": "Muffles",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/Muffles/trikhub.git",
|
|
34
|
+
"directory": "packages/trik-manifest"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/Muffles/trikhub/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/Muffles/trikhub/tree/main/packages/trik-manifest#readme",
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"ajv": "^8.17.1"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc",
|
|
51
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
52
|
+
}
|
|
53
|
+
}
|