@artinet/fleet 0.1.1 → 0.1.7

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 (38) hide show
  1. package/README.md +109 -230
  2. package/dist/default.d.ts +1 -0
  3. package/dist/default.js +1 -0
  4. package/dist/routes/create/index.d.ts +51 -50
  5. package/dist/routes/create/index.js +1 -1
  6. package/dist/routes/request/implementation/load.d.ts +1 -1
  7. package/dist/routes/request/implementation/load.js +17 -20
  8. package/dist/routes/request/types/definitions.d.ts +59 -57
  9. package/dist/routes/request/types/definitions.js +5 -7
  10. package/dist/server/express/agent-request.d.ts +6 -15
  11. package/dist/server/express/agent-request.js +33 -27
  12. package/dist/server/express/deploy-request.d.ts +6 -14
  13. package/dist/server/express/deploy-request.js +18 -18
  14. package/dist/server/express/server.d.ts +73 -13
  15. package/dist/server/express/server.js +57 -49
  16. package/dist/server/express/test-request.d.ts +16 -14
  17. package/dist/server/express/test-request.js +25 -25
  18. package/dist/server/express/types.d.ts +10 -0
  19. package/dist/server/express/types.js +5 -0
  20. package/dist/server/hono/agent-request.d.ts +6 -14
  21. package/dist/server/hono/agent-request.js +25 -21
  22. package/dist/server/hono/deploy-request.d.ts +6 -13
  23. package/dist/server/hono/deploy-request.js +14 -13
  24. package/dist/server/hono/rpc.d.ts +9 -11
  25. package/dist/server/hono/rpc.js +19 -20
  26. package/dist/server/hono/server.d.ts +82 -13
  27. package/dist/server/hono/server.js +63 -44
  28. package/dist/server/hono/test-request.d.ts +6 -13
  29. package/dist/server/hono/test-request.js +26 -26
  30. package/dist/server/hono/types.d.ts +9 -0
  31. package/dist/server/hono/types.js +5 -0
  32. package/dist/settings.d.ts +22 -1
  33. package/dist/ship.d.ts +45 -1
  34. package/dist/ship.js +46 -1
  35. package/dist/types.d.ts +37 -0
  36. package/dist/utils.d.ts +11 -0
  37. package/dist/utils.js +13 -0
  38. package/package.json +108 -108
@@ -2,12 +2,12 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import * as armada from "@artinet/armada";
6
- import { AgentConfiguration } from "agent-def";
7
- import * as sdk from "@artinet/sdk";
8
- import { API } from "@artinet/types";
9
- import { z } from "zod/v4";
10
- import { ResultOrError } from "../../../types.js";
5
+ import * as armada from '@artinet/armada';
6
+ import { AgentConfiguration } from 'agent-def';
7
+ import * as sdk from '@artinet/sdk';
8
+ import { API } from '@artinet/types';
9
+ import { z } from 'zod/v4';
10
+ import { ResultOrError } from '../../../types.js';
11
11
  export type AgentRequest = API.APIRequest & {
12
12
  method: string;
13
13
  params: sdk.A2A.RequestParam;
@@ -23,7 +23,7 @@ export type loadFunction = (config: AgentConfiguration, context?: RequestContext
23
23
  export type invokeFunction = <Req extends AgentRequest = AgentRequest>(request: Req, agent: Agent, context?: RequestContext) => Promise<AgentResponse | null>;
24
24
  export interface RequestContext extends armada.StorageContext<typeof armada.StoredAgentSchema>, armada.FindContext<typeof armada.StoredAgentSchema>,
25
25
  /**If passing `contexts` to the `orc8` loader, be aware that it requires a Monitored Context Manager */
26
- Pick<sdk.CreateAgentParams, "contexts" | "tasks"> {
26
+ Pick<sdk.CreateAgentParams, 'contexts' | 'tasks'> {
27
27
  agentId: string;
28
28
  headers?: Record<string, string>;
29
29
  agents?: Record<string, Agent>;
@@ -48,6 +48,7 @@ Pick<sdk.CreateAgentParams, "contexts" | "tasks"> {
48
48
  }
49
49
  export interface RequestAgentRoute<Req extends AgentRequest = AgentRequest> extends armada.Storable<typeof armada.StoredAgentSchema, Req, AgentResponse, RequestContext> {
50
50
  }
51
+ export type RequestAgentMount<Session extends object> = armada.Mount<Session, RequestAgentRoute['request'], RequestAgentRoute['response'], RequestAgentRoute['context']>;
51
52
  export declare const TestRequestSchema: z.ZodObject<{
52
53
  id: z.ZodOptional<z.ZodOptional<z.ZodString>>;
53
54
  requestId: z.ZodOptional<z.ZodString>;
@@ -58,27 +59,27 @@ export declare const TestRequestSchema: z.ZodObject<{
58
59
  protocolVersion: z.ZodOptional<z.ZodDefault<z.ZodString>>;
59
60
  name: z.ZodString;
60
61
  description: z.ZodString;
61
- url: z.ZodOptional<z.ZodString>;
62
+ url: z.ZodOptional<z.ZodURL>;
62
63
  preferredTransport: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
63
64
  JSONRPC: "JSONRPC";
64
65
  GRPC: "GRPC";
65
66
  "HTTP+JSON": "HTTP+JSON";
66
67
  }>, z.ZodString]>>;
67
68
  additionalInterfaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
68
- url: z.ZodString;
69
+ url: z.ZodURL;
69
70
  transport: z.ZodUnion<readonly [z.ZodEnum<{
70
71
  JSONRPC: "JSONRPC";
71
72
  GRPC: "GRPC";
72
73
  "HTTP+JSON": "HTTP+JSON";
73
74
  }>, z.ZodString]>;
74
75
  }, z.core.$strip>>>;
75
- iconUrl: z.ZodOptional<z.ZodString>;
76
+ iconUrl: z.ZodOptional<z.ZodURL>;
76
77
  provider: z.ZodOptional<z.ZodObject<{
77
78
  organization: z.ZodString;
78
- url: z.ZodString;
79
+ url: z.ZodURL;
79
80
  }, z.core.$strip>>;
80
81
  version: z.ZodString;
81
- documentationUrl: z.ZodOptional<z.ZodString>;
82
+ documentationUrl: z.ZodOptional<z.ZodURL>;
82
83
  capabilities: z.ZodOptional<z.ZodObject<{
83
84
  streaming: z.ZodOptional<z.ZodBoolean>;
84
85
  pushNotifications: z.ZodOptional<z.ZodBoolean>;
@@ -110,31 +111,31 @@ export declare const TestRequestSchema: z.ZodObject<{
110
111
  flows: z.ZodObject<{
111
112
  authorizationCode: z.ZodOptional<z.ZodObject<{
112
113
  authorizationUrl: z.ZodString;
113
- tokenUrl: z.ZodString;
114
- refreshUrl: z.ZodOptional<z.ZodString>;
114
+ tokenUrl: z.ZodURL;
115
+ refreshUrl: z.ZodOptional<z.ZodURL>;
115
116
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
116
117
  }, z.core.$strip>>;
117
118
  clientCredentials: z.ZodOptional<z.ZodObject<{
118
- tokenUrl: z.ZodString;
119
- refreshUrl: z.ZodOptional<z.ZodString>;
119
+ tokenUrl: z.ZodURL;
120
+ refreshUrl: z.ZodOptional<z.ZodURL>;
120
121
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
121
122
  }, z.core.$strip>>;
122
123
  implicit: z.ZodOptional<z.ZodObject<{
123
- authorizationUrl: z.ZodString;
124
- refreshUrl: z.ZodOptional<z.ZodString>;
124
+ authorizationUrl: z.ZodURL;
125
+ refreshUrl: z.ZodOptional<z.ZodURL>;
125
126
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
126
127
  }, z.core.$strip>>;
127
128
  password: z.ZodOptional<z.ZodObject<{
128
- tokenUrl: z.ZodString;
129
- refreshUrl: z.ZodOptional<z.ZodString>;
129
+ tokenUrl: z.ZodURL;
130
+ refreshUrl: z.ZodOptional<z.ZodURL>;
130
131
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
131
132
  }, z.core.$strip>>;
132
133
  }, z.core.$strip>;
133
- oauth2MetadataUrl: z.ZodOptional<z.ZodString>;
134
+ oauth2MetadataUrl: z.ZodOptional<z.ZodURL>;
134
135
  }, z.core.$strip>, z.ZodObject<{
135
136
  description: z.ZodOptional<z.ZodString>;
136
137
  type: z.ZodLiteral<"openIdConnect">;
137
- openIdConnectUrl: z.ZodString;
138
+ openIdConnectUrl: z.ZodURL;
138
139
  }, z.core.$strip>, z.ZodObject<{
139
140
  description: z.ZodOptional<z.ZodString>;
140
141
  type: z.ZodLiteral<"mutualTLS">;
@@ -170,7 +171,7 @@ export declare const TestRequestSchema: z.ZodObject<{
170
171
  instructions: z.ZodString;
171
172
  services: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
172
173
  id: z.ZodOptional<z.ZodString>;
173
- url: z.ZodString;
174
+ url: z.ZodURL;
174
175
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
175
176
  authToken: z.ZodOptional<z.ZodString>;
176
177
  parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -182,27 +183,27 @@ export declare const TestRequestSchema: z.ZodObject<{
182
183
  protocolVersion: z.ZodDefault<z.ZodString>;
183
184
  name: z.ZodString;
184
185
  description: z.ZodString;
185
- url: z.ZodString;
186
+ url: z.ZodURL;
186
187
  preferredTransport: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
187
188
  JSONRPC: "JSONRPC";
188
189
  GRPC: "GRPC";
189
190
  "HTTP+JSON": "HTTP+JSON";
190
191
  }>, z.ZodString]>>;
191
192
  additionalInterfaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
192
- url: z.ZodString;
193
+ url: z.ZodURL;
193
194
  transport: z.ZodUnion<readonly [z.ZodEnum<{
194
195
  JSONRPC: "JSONRPC";
195
196
  GRPC: "GRPC";
196
197
  "HTTP+JSON": "HTTP+JSON";
197
198
  }>, z.ZodString]>;
198
199
  }, z.core.$strip>>>;
199
- iconUrl: z.ZodOptional<z.ZodString>;
200
+ iconUrl: z.ZodOptional<z.ZodURL>;
200
201
  provider: z.ZodOptional<z.ZodObject<{
201
202
  organization: z.ZodString;
202
- url: z.ZodString;
203
+ url: z.ZodURL;
203
204
  }, z.core.$strip>>;
204
205
  version: z.ZodString;
205
- documentationUrl: z.ZodOptional<z.ZodString>;
206
+ documentationUrl: z.ZodOptional<z.ZodURL>;
206
207
  capabilities: z.ZodObject<{
207
208
  streaming: z.ZodOptional<z.ZodBoolean>;
208
209
  pushNotifications: z.ZodOptional<z.ZodBoolean>;
@@ -234,31 +235,31 @@ export declare const TestRequestSchema: z.ZodObject<{
234
235
  flows: z.ZodObject<{
235
236
  authorizationCode: z.ZodOptional<z.ZodObject<{
236
237
  authorizationUrl: z.ZodString;
237
- tokenUrl: z.ZodString;
238
- refreshUrl: z.ZodOptional<z.ZodString>;
238
+ tokenUrl: z.ZodURL;
239
+ refreshUrl: z.ZodOptional<z.ZodURL>;
239
240
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
240
241
  }, z.core.$strip>>;
241
242
  clientCredentials: z.ZodOptional<z.ZodObject<{
242
- tokenUrl: z.ZodString;
243
- refreshUrl: z.ZodOptional<z.ZodString>;
243
+ tokenUrl: z.ZodURL;
244
+ refreshUrl: z.ZodOptional<z.ZodURL>;
244
245
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
245
246
  }, z.core.$strip>>;
246
247
  implicit: z.ZodOptional<z.ZodObject<{
247
- authorizationUrl: z.ZodString;
248
- refreshUrl: z.ZodOptional<z.ZodString>;
248
+ authorizationUrl: z.ZodURL;
249
+ refreshUrl: z.ZodOptional<z.ZodURL>;
249
250
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
250
251
  }, z.core.$strip>>;
251
252
  password: z.ZodOptional<z.ZodObject<{
252
- tokenUrl: z.ZodString;
253
- refreshUrl: z.ZodOptional<z.ZodString>;
253
+ tokenUrl: z.ZodURL;
254
+ refreshUrl: z.ZodOptional<z.ZodURL>;
254
255
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
255
256
  }, z.core.$strip>>;
256
257
  }, z.core.$strip>;
257
- oauth2MetadataUrl: z.ZodOptional<z.ZodString>;
258
+ oauth2MetadataUrl: z.ZodOptional<z.ZodURL>;
258
259
  }, z.core.$strip>, z.ZodObject<{
259
260
  description: z.ZodOptional<z.ZodString>;
260
261
  type: z.ZodLiteral<"openIdConnect">;
261
- openIdConnectUrl: z.ZodString;
262
+ openIdConnectUrl: z.ZodURL;
262
263
  }, z.core.$strip>, z.ZodObject<{
263
264
  description: z.ZodOptional<z.ZodString>;
264
265
  type: z.ZodLiteral<"mutualTLS">;
@@ -285,7 +286,7 @@ export declare const TestRequestSchema: z.ZodObject<{
285
286
  }, z.core.$strip>;
286
287
  }, z.core.$strip>, z.ZodObject<{
287
288
  id: z.ZodOptional<z.ZodString>;
288
- url: z.ZodOptional<z.ZodString>;
289
+ url: z.ZodOptional<z.ZodURL>;
289
290
  headers: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
290
291
  authToken: z.ZodOptional<z.ZodString>;
291
292
  parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -297,27 +298,27 @@ export declare const TestRequestSchema: z.ZodObject<{
297
298
  protocolVersion: z.ZodDefault<z.ZodString>;
298
299
  name: z.ZodString;
299
300
  description: z.ZodString;
300
- url: z.ZodString;
301
+ url: z.ZodURL;
301
302
  preferredTransport: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
302
303
  JSONRPC: "JSONRPC";
303
304
  GRPC: "GRPC";
304
305
  "HTTP+JSON": "HTTP+JSON";
305
306
  }>, z.ZodString]>>;
306
307
  additionalInterfaces: z.ZodOptional<z.ZodArray<z.ZodObject<{
307
- url: z.ZodString;
308
+ url: z.ZodURL;
308
309
  transport: z.ZodUnion<readonly [z.ZodEnum<{
309
310
  JSONRPC: "JSONRPC";
310
311
  GRPC: "GRPC";
311
312
  "HTTP+JSON": "HTTP+JSON";
312
313
  }>, z.ZodString]>;
313
314
  }, z.core.$strip>>>;
314
- iconUrl: z.ZodOptional<z.ZodString>;
315
+ iconUrl: z.ZodOptional<z.ZodURL>;
315
316
  provider: z.ZodOptional<z.ZodObject<{
316
317
  organization: z.ZodString;
317
- url: z.ZodString;
318
+ url: z.ZodURL;
318
319
  }, z.core.$strip>>;
319
320
  version: z.ZodString;
320
- documentationUrl: z.ZodOptional<z.ZodString>;
321
+ documentationUrl: z.ZodOptional<z.ZodURL>;
321
322
  capabilities: z.ZodObject<{
322
323
  streaming: z.ZodOptional<z.ZodBoolean>;
323
324
  pushNotifications: z.ZodOptional<z.ZodBoolean>;
@@ -349,31 +350,31 @@ export declare const TestRequestSchema: z.ZodObject<{
349
350
  flows: z.ZodObject<{
350
351
  authorizationCode: z.ZodOptional<z.ZodObject<{
351
352
  authorizationUrl: z.ZodString;
352
- tokenUrl: z.ZodString;
353
- refreshUrl: z.ZodOptional<z.ZodString>;
353
+ tokenUrl: z.ZodURL;
354
+ refreshUrl: z.ZodOptional<z.ZodURL>;
354
355
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
355
356
  }, z.core.$strip>>;
356
357
  clientCredentials: z.ZodOptional<z.ZodObject<{
357
- tokenUrl: z.ZodString;
358
- refreshUrl: z.ZodOptional<z.ZodString>;
358
+ tokenUrl: z.ZodURL;
359
+ refreshUrl: z.ZodOptional<z.ZodURL>;
359
360
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
360
361
  }, z.core.$strip>>;
361
362
  implicit: z.ZodOptional<z.ZodObject<{
362
- authorizationUrl: z.ZodString;
363
- refreshUrl: z.ZodOptional<z.ZodString>;
363
+ authorizationUrl: z.ZodURL;
364
+ refreshUrl: z.ZodOptional<z.ZodURL>;
364
365
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
365
366
  }, z.core.$strip>>;
366
367
  password: z.ZodOptional<z.ZodObject<{
367
- tokenUrl: z.ZodString;
368
- refreshUrl: z.ZodOptional<z.ZodString>;
368
+ tokenUrl: z.ZodURL;
369
+ refreshUrl: z.ZodOptional<z.ZodURL>;
369
370
  scopes: z.ZodRecord<z.ZodString, z.ZodString>;
370
371
  }, z.core.$strip>>;
371
372
  }, z.core.$strip>;
372
- oauth2MetadataUrl: z.ZodOptional<z.ZodString>;
373
+ oauth2MetadataUrl: z.ZodOptional<z.ZodURL>;
373
374
  }, z.core.$strip>, z.ZodObject<{
374
375
  description: z.ZodOptional<z.ZodString>;
375
376
  type: z.ZodLiteral<"openIdConnect">;
376
- openIdConnectUrl: z.ZodString;
377
+ openIdConnectUrl: z.ZodURL;
377
378
  }, z.core.$strip>, z.ZodObject<{
378
379
  description: z.ZodOptional<z.ZodString>;
379
380
  type: z.ZodLiteral<"mutualTLS">;
@@ -400,7 +401,7 @@ export declare const TestRequestSchema: z.ZodObject<{
400
401
  }, z.core.$strip>;
401
402
  }, z.core.$strip>]>, z.ZodUnion<readonly [z.ZodObject<{
402
403
  id: z.ZodOptional<z.ZodString>;
403
- url: z.ZodString;
404
+ url: z.ZodURL;
404
405
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
405
406
  authToken: z.ZodOptional<z.ZodString>;
406
407
  parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -537,7 +538,7 @@ export declare const TestRequestSchema: z.ZodObject<{
537
538
  }, z.core.$strip>;
538
539
  }, z.core.$strip>, z.ZodObject<{
539
540
  id: z.ZodOptional<z.ZodString>;
540
- url: z.ZodOptional<z.ZodString>;
541
+ url: z.ZodOptional<z.ZodURL>;
541
542
  headers: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
542
543
  authToken: z.ZodOptional<z.ZodString>;
543
544
  parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -721,7 +722,7 @@ export declare const TestRequestSchema: z.ZodObject<{
721
722
  historyLength: z.ZodOptional<z.ZodNumber>;
722
723
  pushNotificationConfig: z.ZodOptional<z.ZodObject<{
723
724
  id: z.ZodOptional<z.ZodString>;
724
- url: z.ZodString;
725
+ url: z.ZodURL;
725
726
  token: z.ZodOptional<z.ZodString>;
726
727
  authentication: z.ZodOptional<z.ZodObject<{
727
728
  schemes: z.ZodArray<z.ZodString>;
@@ -736,3 +737,4 @@ export declare const TestRequestSchema: z.ZodObject<{
736
737
  export type TestRequest = z.output<typeof TestRequestSchema> & AgentRequest;
737
738
  export interface TestAgentRoute extends RequestAgentRoute<TestRequest> {
738
739
  }
740
+ export type TestAgentMount<Session extends object> = armada.Mount<Session, TestAgentRoute['request'], TestAgentRoute['response'], TestAgentRoute['context']>;
@@ -2,14 +2,12 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import * as armada from "@artinet/armada";
6
- import * as sdk from "@artinet/sdk";
7
- import { z } from "zod/v4";
5
+ import * as armada from '@artinet/armada';
6
+ import * as sdk from '@artinet/sdk';
7
+ import { z } from 'zod/v4';
8
8
  export const TestRequestSchema = armada.CreateAgentRequestSchema.extend({
9
9
  /**
10
10
  * All the requested test tasks
11
11
  */
12
- tests: z
13
- .array(sdk.A2A.MessageSendParamsSchema)
14
- .describe("All the requested test tasks"),
15
- }).describe("The test deployment parameters");
12
+ tests: z.array(sdk.A2A.MessageSendParamsSchema).describe('All the requested test tasks'),
13
+ }).describe('The test deployment parameters');
@@ -2,12 +2,8 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import express from "express";
6
- import { RequestAgentRoute, RequestContext } from "../../routes/request/index.js";
7
- export declare const AGENT_FIELD_NAME = "agentId";
8
- export type handler = (req: express.Request, res: express.Response, next: express.NextFunction, context: RequestContext, request?: RequestAgentRoute["implementation"], intercepts?: RequestAgentRoute["intercept"][]) => Promise<void>;
9
- export declare function handle(req: express.Request, res: express.Response, _next: express.NextFunction, context: RequestContext, request?: RequestAgentRoute["implementation"], intercepts?: RequestAgentRoute["intercept"][]): Promise<void>;
10
- export declare const factory: (request?: RequestAgentRoute["implementation"], intercepts?: RequestAgentRoute["intercept"][]) => handler;
5
+ import { RequestAgentMount } from '../../routes/request/index.js';
6
+ import { Session } from './types.js';
11
7
  /**
12
8
  * Handler utilities for agent HTTP requests.
13
9
  *
@@ -19,12 +15,7 @@ export declare const factory: (request?: RequestAgentRoute["implementation"], in
19
15
  *
20
16
  * @module server/handlers/agent
21
17
  */
22
- export interface Params {
23
- request: express.Request;
24
- response: express.Response;
25
- next: express.NextFunction;
26
- context: Omit<RequestContext, "agentId">;
27
- handler: handler;
28
- user: (request: express.Request) => Promise<string>;
29
- }
30
- export declare function request({ request: req, response: res, next, context, handler, user, }: Params): Promise<void>;
18
+ export type Mount = RequestAgentMount<Session>;
19
+ export declare const factory: Mount['factory'];
20
+ export declare const handle: Mount['handler'];
21
+ export declare const request: Mount['request'];
@@ -2,48 +2,54 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { INVALID_REQUEST } from "@artinet/sdk";
6
- import { RequestAgent, } from "../../routes/request/index.js";
7
- import * as sdk from "@artinet/sdk";
8
- import { handleJSONRPCResponse } from "./rpc.js";
9
- import { generateRequestId } from "./utils.js";
10
- export const AGENT_FIELD_NAME = "agentId";
11
- export async function handle(req, res, _next, context, request = RequestAgent, intercepts) {
12
- const requestId = generateRequestId(context, req);
5
+ import { INVALID_REQUEST } from '@artinet/sdk';
6
+ import { RequestAgent } from '../../routes/request/index.js';
7
+ import * as sdk from '@artinet/sdk';
8
+ import { handleJSONRPCResponse } from './rpc.js';
9
+ import { generateRequestId } from './utils.js';
10
+ import { AGENT_FIELD_NAME } from '../../default.js';
11
+ export const factory = ({ implementation = RequestAgent, }) => {
12
+ return async (params) => {
13
+ return await handle(params, implementation);
14
+ };
15
+ };
16
+ export const handle = async ({ session: { request, response }, context, intercepts }, implementation = RequestAgent) => {
17
+ const requestId = generateRequestId(context, request);
13
18
  let parsed;
14
- if (req?.path?.endsWith("agent-card.json") ||
15
- req?.path?.endsWith("agent.json")) {
19
+ if (request?.path?.endsWith('agent-card.json') || request?.path?.endsWith('agent.json')) {
16
20
  parsed = {
17
- jsonrpc: "2.0",
21
+ jsonrpc: '2.0',
18
22
  id: requestId,
19
- method: "agentcard/get",
23
+ method: 'agentcard/get',
20
24
  params: null,
21
25
  };
22
26
  }
23
27
  else {
24
- parsed = await sdk.validateSchema(sdk.A2A.A2ARequestSchema, req?.body ?? {});
28
+ parsed = await sdk.validateSchema(sdk.A2A.A2ARequestSchema, request?.body ?? {});
25
29
  }
26
30
  const params = await sdk.validateSchema(sdk.A2A.RequestParamSchema, parsed.params);
27
- const agentRequest = {
31
+ const req = {
28
32
  method: parsed.method,
29
33
  params: params,
30
34
  };
31
- sdk.logger.info(`handle agent request received:${parsed.method}:params:${sdk.formatJson(agentRequest)}`);
32
- const response = await request(agentRequest, context, intercepts);
33
- sdk.logger.info(`handle agent request completed:${parsed.method}:response:${sdk.formatJson(response)}`);
34
- await handleJSONRPCResponse(res, requestId, parsed.method, response);
35
- }
36
- export const factory = (request = RequestAgent, intercepts) => async (req, res, next, context) => await handle(req, res, next, context, request, intercepts);
37
- export async function request({ request: req, response: res, next, context, handler = handle, user, }) {
38
- const agentId = req?.params?.[AGENT_FIELD_NAME];
35
+ sdk.logger.info(`handle agent request received:${parsed.method}:params:${sdk.formatJson(req)}`);
36
+ const res = await implementation(req, context, intercepts);
37
+ sdk.logger.info(`handle agent request completed:${parsed.method}:response:${sdk.formatJson(res)}`);
38
+ await handleJSONRPCResponse(response, requestId, parsed.method, res);
39
+ };
40
+ export const request = async ({ session, context, handler = handle, user, intercepts }, implementation = RequestAgent) => {
41
+ const { request, next } = session;
42
+ const agentId = Array.isArray(request?.params?.[AGENT_FIELD_NAME])
43
+ ? request?.params?.[AGENT_FIELD_NAME][0]
44
+ : request?.params?.[AGENT_FIELD_NAME];
39
45
  if (!agentId) {
40
46
  return next(INVALID_REQUEST({ message: `${AGENT_FIELD_NAME} is required` }));
41
47
  }
42
- const requestContext = {
48
+ const _context = {
43
49
  ...context,
44
50
  agentId,
45
- requestId: generateRequestId(context, req),
46
- userId: await user?.(req),
51
+ requestId: generateRequestId(context, request),
52
+ userId: await user?.(session),
47
53
  };
48
- await handler(req, res, next, requestContext);
49
- }
54
+ return await handler({ session, context: _context, intercepts }, implementation);
55
+ };
@@ -2,17 +2,9 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import express from "express";
6
- import { CreateAgentRoute } from "../../routes/create/index.js";
7
- export type handler = (req: express.Request, res: express.Response, next: express.NextFunction, context: CreateAgentRoute["context"], deploy?: CreateAgentRoute["implementation"]) => Promise<void>;
8
- export declare function handle(req: express.Request, res: express.Response, _next: express.NextFunction, context: CreateAgentRoute["context"], deploy?: CreateAgentRoute["implementation"]): Promise<void>;
9
- export declare const factory: (deploy?: CreateAgentRoute["implementation"]) => handler;
10
- export interface Params {
11
- request: express.Request;
12
- response: express.Response;
13
- next: express.NextFunction;
14
- context: CreateAgentRoute["context"];
15
- handler: handler;
16
- user: (req: express.Request) => Promise<string>;
17
- }
18
- export declare function request({ request: req, response: res, next, context, handler, user, }: Params): Promise<void>;
5
+ import { CreateAgentMount } from '../../routes/create/index.js';
6
+ import { Session } from './types.js';
7
+ export type Mount = CreateAgentMount<Session>;
8
+ export declare const handle: Mount['handler'];
9
+ export declare const factory: Mount['factory'];
10
+ export declare const request: Mount['request'];
@@ -2,23 +2,23 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { CreateAgent, CreateAgentRequestSchema, } from "../../routes/create/index.js";
6
- import { generateRequestId, generateRegistrationId } from "./utils.js";
7
- import { logger, validateSchema, formatJson } from "@artinet/sdk";
8
- export async function handle(req, res, _next, context, deploy = CreateAgent) {
9
- const request = await validateSchema(CreateAgentRequestSchema, req?.body ?? {});
10
- logger.info(`deploying agent: ${request.config.name}`);
11
- logger.debug(`deploying agent: ${formatJson(request)}`);
12
- context.registrationId = generateRegistrationId(request.config.uri);
13
- const result = await deploy(request, context);
14
- res.json(result);
15
- }
16
- export const factory = (deploy = CreateAgent) => async (req, res, next, context) => await handle(req, res, next, context, deploy);
17
- export async function request({ request: req, response: res, next, context, handler = handle, user, }) {
18
- const requestContext = {
5
+ import { CreateAgent, CreateAgentRequestSchema, } from '../../routes/create/index.js';
6
+ import { generateRequestId, generateRegistrationId } from './utils.js';
7
+ import { logger, validateSchema, formatJson } from '@artinet/sdk';
8
+ export const handle = async ({ session: { request, response }, context, intercepts }, implementation = CreateAgent) => {
9
+ const req = await validateSchema(CreateAgentRequestSchema, request?.body ?? {});
10
+ logger.info(`deploying agent: ${req.config.name}`);
11
+ logger.debug(`deploying agent: ${formatJson(req)}`);
12
+ context.registrationId = generateRegistrationId(req.config.uri);
13
+ const res = await implementation(req, context, intercepts);
14
+ response.json(res);
15
+ };
16
+ export const factory = ({ implementation = CreateAgent }) => async (params) => await handle(params, implementation);
17
+ export const request = async ({ session, context, handler = handle, user, intercepts }, implementation = CreateAgent) => {
18
+ const _context = {
19
19
  ...context,
20
- requestId: generateRequestId(context, req),
21
- userId: await user?.(req),
20
+ requestId: generateRequestId(context, session.request),
21
+ userId: await user?.(session),
22
22
  };
23
- return await handler(req, res, next, requestContext);
24
- }
23
+ return await handler({ session, context: _context, intercepts }, implementation);
24
+ };
@@ -2,29 +2,89 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { Server } from "http";
6
- import express from "express";
7
- import { CreateAgentRoute } from "../../routes/create/index.js";
8
- import { Settings as FleetSettings } from "../../settings.js";
9
- import * as agent from "./agent-request.js";
10
- import * as testing from "./test-request.js";
11
- import * as deployment from "./deploy-request.js";
5
+ import { Server } from 'http';
6
+ import express from 'express';
7
+ import { CreateAgentRoute } from '../../routes/create/index.js';
8
+ import { Settings as FleetSettings } from '../../settings.js';
9
+ import * as agent from './agent-request.js';
10
+ import * as testing from './test-request.js';
11
+ import * as deployment from './deploy-request.js';
12
+ import { Session } from './types.js';
13
+ /**
14
+ * Extended settings for the Express Fleet server.
15
+ *
16
+ * Combines base {@link FleetSettings} with Express-specific handlers for
17
+ * authentication, user resolution, and request processing.
18
+ *
19
+ * @see {@link https://expressjs.com/en/guide/using-middleware.html Express Middleware}
20
+ */
12
21
  export type Settings = FleetSettings & {
13
- user?: (req: express.Request) => Promise<string>;
14
- retrieve?: agent.handler;
15
- deploy?: deployment.handler;
16
- evaluate?: testing.handler;
22
+ /** Extracts the user ID from an incoming request. Used for multi-tenant agent isolation. */
23
+ user?: (session: Session) => Promise<string>;
24
+ /** Handler for agent retrieval requests. Generated via {@link agent.factory}. */
25
+ retrieve?: agent.Mount['handler'];
26
+ /** Handler for agent deployment requests. Generated via {@link deployment.factory}. */
27
+ deploy?: deployment.Mount['handler'];
28
+ /** Handler for agent test/evaluation requests. Generated via {@link testing.factory}. */
29
+ evaluate?: testing.Mount['handler'];
30
+ /**
31
+ * Authentication middleware applied to protected routes.
32
+ * @see {@link https://expressjs.com/en/guide/writing-middleware.html Writing Middleware}
33
+ */
17
34
  auth?: (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
18
35
  };
36
+ /**
37
+ * Options for configuring the Fleet server instance.
38
+ *
39
+ * Allows injection of a pre-configured Express app for integration with
40
+ * existing servers or custom middleware stacks.
41
+ */
19
42
  export interface Options {
43
+ /** Pre-configured Express application. Defaults to a new `express()` instance. */
20
44
  app?: express.Application;
45
+ /** Apply auth middleware to agent retrieval routes. Defaults to `false`. */
21
46
  authOnRetrieve?: boolean;
47
+ /** Expose the test endpoint for agent evaluation. Defaults to `true`. */
22
48
  enableTesting?: boolean;
23
49
  }
24
- export declare function fleet(settings?: Partial<Settings>, { app, authOnRetrieve, enableTesting, }?: Options): {
50
+ /**
51
+ * Creates and configures a Fleet server instance using Express.
52
+ *
53
+ * This function implements the **Factory Pattern** combined with **Dependency Injection**
54
+ * to provide a flexible, testable, and configurable server setup. The pattern allows
55
+ * consumers to override defaults while maintaining sensible out-of-the-box behavior.
56
+ *
57
+ * @param settings - Partial configuration merged with defaults. Supports custom
58
+ * handlers for `get`, `set`, `test`, and middleware composition.
59
+ * @param options - Server instantiation options
60
+ * @param options.app - Pre-configured Express application instance. Useful for
61
+ * adding custom middleware or integrating with existing servers.
62
+ * @param options.authOnRetrieve - When `true`, applies auth middleware to agent
63
+ * retrieval routes. Defaults to `false` for development convenience.
64
+ * @param options.enableTesting - When `true`, exposes the test endpoint for
65
+ * agent evaluation. Disable in production if not needed.
66
+ *
67
+ * @returns Object containing:
68
+ * - `app`: The configured Express application
69
+ * - `launch`: Function to start the HTTP server on a specified port
70
+ * - `ship`: Async function to deploy agents and return a launchable server
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * // Basic usage with defaults
75
+ * const { app, launch } = fleet();
76
+ * launch(3000);
77
+ *
78
+ * // With custom configuration
79
+ * const { ship } = fleet({ userId: 'admin' }, { authOnRetrieve: true });
80
+ * const server = await ship([agentConfig]);
81
+ * server.launch(8080);
82
+ * ```
83
+ */
84
+ export declare function fleet(settings?: Partial<Settings>, { app, authOnRetrieve, enableTesting }?: Options): {
25
85
  app: express.Application;
26
86
  launch: (port: number) => Server;
27
- ship: (agents: CreateAgentRoute["request"][], userId?: string) => Promise<{
87
+ ship: (agents: CreateAgentRoute['request'][], userId?: string) => Promise<{
28
88
  launch: (port?: number) => Server;
29
89
  }>;
30
90
  };