@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.
- package/README.md +109 -230
- package/dist/default.d.ts +1 -0
- package/dist/default.js +1 -0
- package/dist/routes/create/index.d.ts +51 -50
- package/dist/routes/create/index.js +1 -1
- package/dist/routes/request/implementation/load.d.ts +1 -1
- package/dist/routes/request/implementation/load.js +17 -20
- package/dist/routes/request/types/definitions.d.ts +59 -57
- package/dist/routes/request/types/definitions.js +5 -7
- package/dist/server/express/agent-request.d.ts +6 -15
- package/dist/server/express/agent-request.js +33 -27
- package/dist/server/express/deploy-request.d.ts +6 -14
- package/dist/server/express/deploy-request.js +18 -18
- package/dist/server/express/server.d.ts +73 -13
- package/dist/server/express/server.js +57 -49
- package/dist/server/express/test-request.d.ts +16 -14
- package/dist/server/express/test-request.js +25 -25
- package/dist/server/express/types.d.ts +10 -0
- package/dist/server/express/types.js +5 -0
- package/dist/server/hono/agent-request.d.ts +6 -14
- package/dist/server/hono/agent-request.js +25 -21
- package/dist/server/hono/deploy-request.d.ts +6 -13
- package/dist/server/hono/deploy-request.js +14 -13
- package/dist/server/hono/rpc.d.ts +9 -11
- package/dist/server/hono/rpc.js +19 -20
- package/dist/server/hono/server.d.ts +82 -13
- package/dist/server/hono/server.js +63 -44
- package/dist/server/hono/test-request.d.ts +6 -13
- package/dist/server/hono/test-request.js +26 -26
- package/dist/server/hono/types.d.ts +9 -0
- package/dist/server/hono/types.js +5 -0
- package/dist/settings.d.ts +22 -1
- package/dist/ship.d.ts +45 -1
- package/dist/ship.js +46 -1
- package/dist/types.d.ts +37 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +13 -0
- package/package.json +108 -108
|
@@ -2,29 +2,98 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import * as hono from
|
|
6
|
-
import { type ServerType } from
|
|
7
|
-
import { CreateAgentRoute } from
|
|
8
|
-
import { Settings as FleetSettings } from
|
|
9
|
-
import * as agent from
|
|
10
|
-
import * as testing from
|
|
11
|
-
import * as deployment from
|
|
5
|
+
import * as hono from 'hono';
|
|
6
|
+
import { type ServerType } from '@hono/node-server';
|
|
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 Hono Fleet server.
|
|
15
|
+
*
|
|
16
|
+
* Combines base {@link FleetSettings} with Hono-specific handlers for
|
|
17
|
+
* authentication, user resolution, and request processing.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://hono.dev/docs/guides/middleware Hono Middleware Guide}
|
|
20
|
+
*/
|
|
12
21
|
export type Settings = FleetSettings & {
|
|
13
|
-
user
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
/** Extracts the user ID from the session. 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://hono.dev/docs/guides/middleware#middleware-argument Middleware Guide}
|
|
33
|
+
*/
|
|
17
34
|
auth?: (ctx: hono.Context, next: hono.Next) => Promise<void>;
|
|
18
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Options for configuring the Fleet server instance.
|
|
38
|
+
*
|
|
39
|
+
* Allows injection of a pre-configured Hono app for integration with
|
|
40
|
+
* existing servers or edge runtime deployments.
|
|
41
|
+
*/
|
|
19
42
|
export interface Options {
|
|
43
|
+
/** Pre-configured Hono application. Defaults to a new `Hono()` instance. */
|
|
20
44
|
app?: hono.Hono;
|
|
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
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Creates and configures a Fleet server instance using Hono.
|
|
52
|
+
*
|
|
53
|
+
* This function implements the **Factory Pattern** combined with **Dependency Injection**
|
|
54
|
+
* to provide a flexible, testable, and configurable server setup. Hono is chosen for its
|
|
55
|
+
* ultrafast performance, edge-runtime compatibility, and minimal footprint.
|
|
56
|
+
*
|
|
57
|
+
* @see {@link https://hono.dev/docs/ Hono Documentation}
|
|
58
|
+
* @see {@link https://hono.dev/docs/concepts/routers Hono Routers}
|
|
59
|
+
* @see {@link https://hono.dev/docs/guides/middleware Hono Middleware Guide}
|
|
60
|
+
*
|
|
61
|
+
* ## Security Considerations
|
|
62
|
+
*
|
|
63
|
+
* - Authentication middleware is applied conditionally via `auth` setting
|
|
64
|
+
* - `authOnRetrieve` flag controls whether agent retrieval requires authentication
|
|
65
|
+
* - Consider enabling `authOnRetrieve` in production environments
|
|
66
|
+
*
|
|
67
|
+
* @param settings - Partial configuration merged with defaults. Supports custom
|
|
68
|
+
* handlers for `get`, `set`, `test`, and middleware composition.
|
|
69
|
+
* @param options - Server instantiation options
|
|
70
|
+
* @param options.app - Pre-configured Hono application instance. Useful for
|
|
71
|
+
* adding custom middleware or integrating with existing servers.
|
|
72
|
+
* @param options.authOnRetrieve - When `true`, applies auth middleware to agent
|
|
73
|
+
* retrieval routes. Defaults to `false` for development convenience.
|
|
74
|
+
* @param options.enableTesting - When `true`, exposes the test endpoint for
|
|
75
|
+
* agent evaluation. Disable in production if not needed.
|
|
76
|
+
*
|
|
77
|
+
* @returns Object containing:
|
|
78
|
+
* - `app`: The configured Hono application
|
|
79
|
+
* - `launch`: Function to start the HTTP server on a specified port
|
|
80
|
+
* - `ship`: Async function to deploy agents and return a launchable server
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Basic usage with defaults
|
|
85
|
+
* const { app, launch } = fleet();
|
|
86
|
+
* launch(3000);
|
|
87
|
+
*
|
|
88
|
+
* // With custom configuration and edge deployment
|
|
89
|
+
* const { app } = fleet({ userId: 'admin' }, { authOnRetrieve: true });
|
|
90
|
+
* export default app; // For Cloudflare Workers
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function fleet(settings?: Partial<Settings>, { app, authOnRetrieve, enableTesting }?: Options): {
|
|
25
94
|
app: hono.Hono;
|
|
26
95
|
launch: (port: number) => ServerType;
|
|
27
|
-
ship: (agents: CreateAgentRoute[
|
|
96
|
+
ship: (agents: CreateAgentRoute['request'][], userId?: string) => Promise<{
|
|
28
97
|
launch: (port?: number) => ServerType;
|
|
29
98
|
}>;
|
|
30
99
|
};
|
|
@@ -2,27 +2,22 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import * as hono from
|
|
6
|
-
import { serve } from
|
|
7
|
-
import * as sdk from
|
|
8
|
-
import { DEFAULTS } from
|
|
9
|
-
import * as agent from
|
|
10
|
-
import * as testing from
|
|
11
|
-
import * as deployment from
|
|
12
|
-
import {
|
|
13
|
-
import { errorHandler } from "./error-handler.js";
|
|
5
|
+
import * as hono from 'hono';
|
|
6
|
+
import { serve } from '@hono/node-server';
|
|
7
|
+
import * as sdk from '@artinet/sdk';
|
|
8
|
+
import { DEFAULTS, AGENT_FIELD_NAME } from '../../default.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 { errorHandler } from './error-handler.js';
|
|
14
13
|
const createContext = (settings) => {
|
|
15
14
|
const _settings = {
|
|
16
15
|
...DEFAULTS,
|
|
17
16
|
...settings,
|
|
18
|
-
retrieve: agent.factory(settings.get ?? DEFAULTS.get,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
evaluate: testing.factory(settings.test ?? DEFAULTS.test),
|
|
23
|
-
user: settings.user
|
|
24
|
-
? settings.user
|
|
25
|
-
: (_ctx) => Promise.resolve(settings.userId ?? "default"),
|
|
17
|
+
retrieve: agent.factory({ implementation: settings.get ?? DEFAULTS.get }),
|
|
18
|
+
deploy: deployment.factory({ implementation: settings.set ?? DEFAULTS.set }),
|
|
19
|
+
evaluate: testing.factory({ implementation: settings.test ?? DEFAULTS.test }),
|
|
20
|
+
user: settings.user ? settings.user : (_session) => Promise.resolve(settings.userId ?? 'default'),
|
|
26
21
|
};
|
|
27
22
|
return _settings;
|
|
28
23
|
};
|
|
@@ -42,11 +37,53 @@ const createRequestContext = (context) => {
|
|
|
42
37
|
timestamp: undefined,
|
|
43
38
|
};
|
|
44
39
|
};
|
|
45
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Creates and configures a Fleet server instance using Hono.
|
|
42
|
+
*
|
|
43
|
+
* This function implements the **Factory Pattern** combined with **Dependency Injection**
|
|
44
|
+
* to provide a flexible, testable, and configurable server setup. Hono is chosen for its
|
|
45
|
+
* ultrafast performance, edge-runtime compatibility, and minimal footprint.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://hono.dev/docs/ Hono Documentation}
|
|
48
|
+
* @see {@link https://hono.dev/docs/concepts/routers Hono Routers}
|
|
49
|
+
* @see {@link https://hono.dev/docs/guides/middleware Hono Middleware Guide}
|
|
50
|
+
*
|
|
51
|
+
* ## Security Considerations
|
|
52
|
+
*
|
|
53
|
+
* - Authentication middleware is applied conditionally via `auth` setting
|
|
54
|
+
* - `authOnRetrieve` flag controls whether agent retrieval requires authentication
|
|
55
|
+
* - Consider enabling `authOnRetrieve` in production environments
|
|
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 Hono 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 Hono 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 and edge deployment
|
|
79
|
+
* const { app } = fleet({ userId: 'admin' }, { authOnRetrieve: true });
|
|
80
|
+
* export default app; // For Cloudflare Workers
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function fleet(settings = DEFAULTS, { app = new hono.Hono(), authOnRetrieve = false, enableTesting = true } = {}) {
|
|
46
84
|
const context = createContext(settings);
|
|
47
|
-
const { basePath, agentPath, fallbackPath, deploymentPath, testPath, auth, user, evaluate, deploy, retrieve, set
|
|
85
|
+
const { basePath, agentPath, fallbackPath, deploymentPath, testPath, auth, user, evaluate, deploy, retrieve, set } = context;
|
|
48
86
|
const router = new hono.Hono();
|
|
49
|
-
// router.use(hono.json());
|
|
50
87
|
router.onError(errorHandler);
|
|
51
88
|
if (auth) {
|
|
52
89
|
router.use(testPath, auth);
|
|
@@ -58,33 +95,31 @@ export function fleet(settings = DEFAULTS, { app = new hono.Hono(), authOnRetrie
|
|
|
58
95
|
}
|
|
59
96
|
if (enableTesting === true && evaluate !== undefined) {
|
|
60
97
|
router.post(testPath, async (ctx, next) => await testing.request({
|
|
61
|
-
ctx,
|
|
62
|
-
next,
|
|
98
|
+
session: { ctx, next },
|
|
63
99
|
context: createRequestContext(context),
|
|
64
100
|
handler: evaluate,
|
|
65
101
|
user,
|
|
66
102
|
}));
|
|
67
103
|
}
|
|
68
104
|
router.post(deploymentPath, async (ctx, next) => await deployment.request({
|
|
69
|
-
ctx,
|
|
70
|
-
next,
|
|
105
|
+
session: { ctx, next },
|
|
71
106
|
context: createRequestContext(context),
|
|
72
107
|
handler: deploy,
|
|
73
108
|
user,
|
|
74
109
|
}));
|
|
75
110
|
router.use(`${agentPath}/:${AGENT_FIELD_NAME}/*`, async (ctx, next) => await agent.request({
|
|
76
|
-
ctx,
|
|
77
|
-
next,
|
|
111
|
+
session: { ctx, next },
|
|
78
112
|
context: createRequestContext(context),
|
|
79
113
|
handler: retrieve,
|
|
80
114
|
user,
|
|
115
|
+
intercepts: settings.middleware?.build() ?? [],
|
|
81
116
|
}));
|
|
82
117
|
router.use(`${fallbackPath}/:${AGENT_FIELD_NAME}/*`, async (ctx, next) => await agent.request({
|
|
83
|
-
ctx,
|
|
84
|
-
next,
|
|
118
|
+
session: { ctx, next },
|
|
85
119
|
context: createRequestContext(context),
|
|
86
120
|
handler: retrieve,
|
|
87
121
|
user,
|
|
122
|
+
intercepts: settings.middleware?.build() ?? [],
|
|
88
123
|
}));
|
|
89
124
|
app.route(basePath, router);
|
|
90
125
|
const launch = (port = 3000) => {
|
|
@@ -104,19 +139,3 @@ export function fleet(settings = DEFAULTS, { app = new hono.Hono(), authOnRetrie
|
|
|
104
139
|
};
|
|
105
140
|
return { app, launch, ship };
|
|
106
141
|
}
|
|
107
|
-
// const swarm = await fleet().ship([
|
|
108
|
-
// {
|
|
109
|
-
// config: {
|
|
110
|
-
// uri: "my-agent",
|
|
111
|
-
// name: "my-agent",
|
|
112
|
-
// description: "A helpful assistant",
|
|
113
|
-
// modelId: "gpt-4",
|
|
114
|
-
// instructions: "You are a helpful assistant.",
|
|
115
|
-
// version: "1.0.0",
|
|
116
|
-
// skills: [],
|
|
117
|
-
// capabilities: {},
|
|
118
|
-
// services: [],
|
|
119
|
-
// },
|
|
120
|
-
// },
|
|
121
|
-
// ]);
|
|
122
|
-
// swarm.launch(3000);
|
|
@@ -2,16 +2,9 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
export type
|
|
8
|
-
export declare
|
|
9
|
-
export declare const
|
|
10
|
-
export
|
|
11
|
-
ctx: hono.Context;
|
|
12
|
-
next: hono.Next;
|
|
13
|
-
context: Omit<TestAgentRoute["context"], "agentId">;
|
|
14
|
-
handler: handler;
|
|
15
|
-
user: (ctx: hono.Context) => Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
export declare function request({ ctx, next, context, handler, user, }: Params): Promise<hono.Context["res"]>;
|
|
5
|
+
import { TestAgentMount } from '../../routes/request/index.js';
|
|
6
|
+
import { Session } from './types.js';
|
|
7
|
+
export type Mount = TestAgentMount<Session>;
|
|
8
|
+
export declare const factory: Mount['factory'];
|
|
9
|
+
export declare const handle: Mount['handler'];
|
|
10
|
+
export declare const request: Mount['request'];
|
|
@@ -2,25 +2,11 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import * as sdk from
|
|
6
|
-
import { TestAgent, TestRequestSchema, } from
|
|
7
|
-
import { v4 as uuidv4 } from
|
|
8
|
-
import { handleJSONRPCResponse } from
|
|
9
|
-
import { generateRequestId } from
|
|
10
|
-
export async function handle(ctx, _next, context, test = TestAgent) {
|
|
11
|
-
/* hono.Context.req uses a raw JSON.parse() so we prefer to use the text() and our own safeParse() */
|
|
12
|
-
const req = sdk.safeParse(await ctx.req.text());
|
|
13
|
-
let parsed = await sdk.validateSchema(TestRequestSchema, req);
|
|
14
|
-
let id = parsed.id ?? uuidv4();
|
|
15
|
-
parsed.id = id;
|
|
16
|
-
let request = parsed;
|
|
17
|
-
context.target = parsed.config;
|
|
18
|
-
request.method = "test/invoke";
|
|
19
|
-
request.params = null;
|
|
20
|
-
const response = await test(request, context);
|
|
21
|
-
await handleJSONRPCResponse(ctx, String(id), request.method, response);
|
|
22
|
-
}
|
|
23
|
-
export const factory = (test = TestAgent) => async (ctx, next, context) => await handle(ctx, next, context, test);
|
|
5
|
+
import * as sdk from '@artinet/sdk';
|
|
6
|
+
import { TestAgent, TestRequestSchema, } from '../../routes/request/index.js';
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
import { handleJSONRPCResponse } from './rpc.js';
|
|
9
|
+
import { generateRequestId } from './utils.js';
|
|
24
10
|
const MAX_TEST_ID_ATTEMPTS = 10;
|
|
25
11
|
const getTestId = async (context) => {
|
|
26
12
|
let testId = uuidv4();
|
|
@@ -42,15 +28,29 @@ const getTestId = async (context) => {
|
|
|
42
28
|
}
|
|
43
29
|
return testId;
|
|
44
30
|
};
|
|
45
|
-
export
|
|
31
|
+
export const factory = ({ implementation = TestAgent }) => async (params) => await handle(params, implementation);
|
|
32
|
+
export const handle = async ({ session: { ctx }, context, intercepts }, implementation = TestAgent) => {
|
|
33
|
+
/* hono.Context.req uses a raw JSON.parse() so we prefer to use the text() and our own safeParse() */
|
|
34
|
+
const req = sdk.safeParse(await ctx.req.text());
|
|
35
|
+
let parsed = await sdk.validateSchema(TestRequestSchema, req);
|
|
36
|
+
let id = parsed.id ?? uuidv4();
|
|
37
|
+
parsed.id = id;
|
|
38
|
+
let request = parsed;
|
|
39
|
+
context.target = parsed.config;
|
|
40
|
+
request.method = 'test/invoke';
|
|
41
|
+
request.params = null;
|
|
42
|
+
const response = await implementation(request, context, intercepts);
|
|
43
|
+
return await handleJSONRPCResponse(ctx, String(id), request.method, response);
|
|
44
|
+
};
|
|
45
|
+
export const request = async ({ session, context, handler = handle, user, intercepts }, implementation = TestAgent) => {
|
|
46
|
+
const { ctx } = session;
|
|
46
47
|
/* hono.Context.req uses a raw JSON.parse() so we prefer to use the text() and our own safeParse() */
|
|
47
|
-
const reqId = ctx.req.header(
|
|
48
|
-
const
|
|
48
|
+
const reqId = ctx.req.header('x-request-id') ?? sdk.safeParse(await ctx.req.text())?.id;
|
|
49
|
+
const _context = {
|
|
49
50
|
...context,
|
|
50
51
|
agentId: await getTestId(context),
|
|
51
52
|
requestId: generateRequestId(context, reqId),
|
|
52
|
-
userId: await user?.(
|
|
53
|
+
userId: await user?.(session),
|
|
53
54
|
};
|
|
54
|
-
await handler(
|
|
55
|
-
|
|
56
|
-
}
|
|
55
|
+
return await handler({ session, context: _context, intercepts }, implementation);
|
|
56
|
+
};
|
package/dist/settings.d.ts
CHANGED
|
@@ -6,16 +6,37 @@ import { RequestAgentRoute, TestAgentRoute } from "./routes/index.js";
|
|
|
6
6
|
import { CreateAgentRoute } from "./routes/create/index.js";
|
|
7
7
|
import { Configuration } from "./types.js";
|
|
8
8
|
import { Middleware } from "./routes/intercept.js";
|
|
9
|
+
/**
|
|
10
|
+
* Route path configuration parameters for the Fleet server.
|
|
11
|
+
*
|
|
12
|
+
* Extends {@link Configuration} with customizable URL paths for each endpoint,
|
|
13
|
+
* allowing flexible integration with existing API structures.
|
|
14
|
+
*/
|
|
9
15
|
export interface Params extends Configuration {
|
|
16
|
+
/** Base path prefix for all Fleet routes. Defaults to `/`. */
|
|
10
17
|
basePath?: string;
|
|
18
|
+
/** Fallback path for agent requests. Defaults to `/.well-known/agent`. */
|
|
11
19
|
fallbackPath?: string;
|
|
20
|
+
/** Path for agent deployment requests. Defaults to `/deploy`. */
|
|
12
21
|
deploymentPath?: string;
|
|
22
|
+
/** Path for agent test/evaluation requests. Defaults to `/test`. */
|
|
13
23
|
testPath?: string;
|
|
14
|
-
/**Middleware addons are currently only supported on the Request Agent route */
|
|
24
|
+
/** Middleware addons are currently only supported on the Request Agent route. */
|
|
15
25
|
middleware?: Middleware;
|
|
16
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Complete settings combining route paths with handler implementations.
|
|
29
|
+
*
|
|
30
|
+
* Defines the core operations for agent management:
|
|
31
|
+
* - `get`: Retrieve and execute agent requests
|
|
32
|
+
* - `set`: Deploy new agents or update existing ones
|
|
33
|
+
* - `test`: Evaluate agent behavior (optional)
|
|
34
|
+
*/
|
|
17
35
|
export interface Settings extends Params {
|
|
36
|
+
/** Implementation for retrieving and processing agent requests. */
|
|
18
37
|
get: RequestAgentRoute["implementation"];
|
|
38
|
+
/** Implementation for deploying or updating agents. */
|
|
19
39
|
set: CreateAgentRoute["implementation"];
|
|
40
|
+
/** Implementation for testing/evaluating agents. Optional. */
|
|
20
41
|
test?: TestAgentRoute["implementation"];
|
|
21
42
|
}
|
package/dist/ship.d.ts
CHANGED
|
@@ -3,4 +3,48 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { CreateAgentRoute } from "./routes/create/index.js";
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Deploys an agent configuration to a remote Fleet server.
|
|
8
|
+
*
|
|
9
|
+
* This function serves as a client for agent deployment,
|
|
10
|
+
* implementing schema validation on both request and response to ensure type safety
|
|
11
|
+
* and data integrity across network boundaries.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://zod.dev/ Zod Schema Validation}
|
|
14
|
+
*
|
|
15
|
+
* Schema validation will throw if the request or response doesn't match the expected
|
|
16
|
+
* structure. Network errors from `fetch` will propagate as-is.
|
|
17
|
+
*
|
|
18
|
+
* @template T - The agent request type, constrained to `CreateAgentRoute["request"]`
|
|
19
|
+
*
|
|
20
|
+
* @param fleetUrl - Base URL of the Fleet server. Defaults to `http://localhost:3000`
|
|
21
|
+
* for local development. In production, use environment variables.
|
|
22
|
+
* @param request - Agent configuration to deploy. Must conform to {@link armada.CreateAgentRequestSchema}.
|
|
23
|
+
* @param headers - Optional custom HTTP headers to include with the request. Useful for authentication tokens, correlation IDs, or distributed tracing headers.
|
|
24
|
+
*
|
|
25
|
+
* @returns Promise resolving to the deployment response, validated against {@link API.CreateAgentResponseSchema}.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Deploy to local development server
|
|
30
|
+
* const result = await ship("http://localhost:3000", {
|
|
31
|
+
* config: {
|
|
32
|
+
* schemaVersion: "0.1.0",
|
|
33
|
+
* uri: "my-agent",
|
|
34
|
+
* name: "My Agent",
|
|
35
|
+
* description: "A helpful assistant",
|
|
36
|
+
* modelId: "gpt-4",
|
|
37
|
+
* instructions: "You are a helpful assistant.",
|
|
38
|
+
* version: "1.0.0",
|
|
39
|
+
* },
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Deploy with authentication header
|
|
43
|
+
* const authResult = await ship(
|
|
44
|
+
* process.env.FLEET_URL!,
|
|
45
|
+
* agentConfig,
|
|
46
|
+
* { Authorization: `Bearer ${token}` }
|
|
47
|
+
* );
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function ship<T extends CreateAgentRoute["request"]>(fleetUrl: string | undefined, request: T, headers?: Record<string, string>): Promise<CreateAgentRoute["response"]>;
|
package/dist/ship.js
CHANGED
|
@@ -5,13 +5,58 @@
|
|
|
5
5
|
import * as sdk from "@artinet/sdk";
|
|
6
6
|
import * as armada from "@artinet/armada";
|
|
7
7
|
import { API } from "@artinet/types";
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Deploys an agent configuration to a remote Fleet server.
|
|
10
|
+
*
|
|
11
|
+
* This function serves as a client for agent deployment,
|
|
12
|
+
* implementing schema validation on both request and response to ensure type safety
|
|
13
|
+
* and data integrity across network boundaries.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://zod.dev/ Zod Schema Validation}
|
|
16
|
+
*
|
|
17
|
+
* Schema validation will throw if the request or response doesn't match the expected
|
|
18
|
+
* structure. Network errors from `fetch` will propagate as-is.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The agent request type, constrained to `CreateAgentRoute["request"]`
|
|
21
|
+
*
|
|
22
|
+
* @param fleetUrl - Base URL of the Fleet server. Defaults to `http://localhost:3000`
|
|
23
|
+
* for local development. In production, use environment variables.
|
|
24
|
+
* @param request - Agent configuration to deploy. Must conform to {@link armada.CreateAgentRequestSchema}.
|
|
25
|
+
* @param headers - Optional custom HTTP headers to include with the request. Useful for authentication tokens, correlation IDs, or distributed tracing headers.
|
|
26
|
+
*
|
|
27
|
+
* @returns Promise resolving to the deployment response, validated against {@link API.CreateAgentResponseSchema}.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Deploy to local development server
|
|
32
|
+
* const result = await ship("http://localhost:3000", {
|
|
33
|
+
* config: {
|
|
34
|
+
* schemaVersion: "0.1.0",
|
|
35
|
+
* uri: "my-agent",
|
|
36
|
+
* name: "My Agent",
|
|
37
|
+
* description: "A helpful assistant",
|
|
38
|
+
* modelId: "gpt-4",
|
|
39
|
+
* instructions: "You are a helpful assistant.",
|
|
40
|
+
* version: "1.0.0",
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Deploy with authentication header
|
|
45
|
+
* const authResult = await ship(
|
|
46
|
+
* process.env.FLEET_URL!,
|
|
47
|
+
* agentConfig,
|
|
48
|
+
* { Authorization: `Bearer ${token}` }
|
|
49
|
+
* );
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export async function ship(fleetUrl = "http://localhost:3000", request, headers = {}) {
|
|
9
53
|
const requestBody = await sdk.validateSchema(armada.CreateAgentRequestSchema, request);
|
|
10
54
|
sdk.logger.debug(`deployAgent request:`, { requestBody });
|
|
11
55
|
const response = await fetch(`${fleetUrl}/deploy`, {
|
|
12
56
|
method: "POST",
|
|
13
57
|
headers: {
|
|
14
58
|
"Content-Type": "application/json",
|
|
59
|
+
...headers,
|
|
15
60
|
},
|
|
16
61
|
body: JSON.stringify(requestBody),
|
|
17
62
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -4,8 +4,45 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { RequestAgentRoute, TestAgentRoute } from "./routes/index.js";
|
|
6
6
|
import { CreateAgentRoute } from "./routes/create/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Combined context type for all route handlers.
|
|
9
|
+
*
|
|
10
|
+
* Represents the intersection of context requirements across agent request,
|
|
11
|
+
* creation, and testing routes. Used internally for handler type safety.
|
|
12
|
+
*/
|
|
7
13
|
export type Config = RequestAgentRoute["context"] & CreateAgentRoute["context"] & TestAgentRoute["context"];
|
|
14
|
+
/**
|
|
15
|
+
* Configuration type without agent-specific identifiers.
|
|
16
|
+
*
|
|
17
|
+
* Omits `agentId` from {@link Config} for use in settings and initialization
|
|
18
|
+
* where the agent ID is not yet known.
|
|
19
|
+
*/
|
|
8
20
|
export type Configuration = Omit<Config, "agentId">;
|
|
21
|
+
/**
|
|
22
|
+
* Discriminated union for operation results.
|
|
23
|
+
*
|
|
24
|
+
* Provides a type-safe way to represent three possible outcomes:
|
|
25
|
+
* - `success`: Operation completed with a result
|
|
26
|
+
* - `error`: Operation failed with an error
|
|
27
|
+
* - `stream`: Operation returns an async iterable stream
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions Discriminated Unions}
|
|
30
|
+
*
|
|
31
|
+
* @template Result - Type of successful result. Defaults to `unknown`.
|
|
32
|
+
* @template Error - Type of error payload. Defaults to `unknown`.
|
|
33
|
+
* @template Stream - Type of streamed items. Defaults to `unknown`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* function handle(result: ResultOrError<User, ApiError, Chunk>) {
|
|
38
|
+
* switch (result.type) {
|
|
39
|
+
* case "success": return result.result; // User
|
|
40
|
+
* case "error": throw result.error; // ApiError
|
|
41
|
+
* case "stream": return result.stream; // AsyncIterable<Chunk>
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
9
46
|
export type ResultOrError<Result = unknown, Error = unknown, Stream = unknown> = {
|
|
10
47
|
type: "success";
|
|
11
48
|
result: Result;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResultOrError } from './types.js';
|
|
2
|
+
export declare function sanitizeString(str: string): string;
|
|
3
|
+
export declare function toJSONRPCResponse(id: string, result_or_error: ResultOrError): {
|
|
4
|
+
jsonrpc: '2.0';
|
|
5
|
+
id: string;
|
|
6
|
+
result: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
jsonrpc: '2.0';
|
|
9
|
+
id: string;
|
|
10
|
+
error: unknown;
|
|
11
|
+
};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import escapeHtml from 'escape-html';
|
|
2
|
+
export function sanitizeString(str) {
|
|
3
|
+
return escapeHtml(str).trim();
|
|
4
|
+
}
|
|
5
|
+
export function toJSONRPCResponse(id, result_or_error) {
|
|
6
|
+
if (result_or_error.type === 'success') {
|
|
7
|
+
return { jsonrpc: '2.0', id: sanitizeString(id), result: result_or_error.result };
|
|
8
|
+
}
|
|
9
|
+
if (result_or_error.type === 'error') {
|
|
10
|
+
return { jsonrpc: '2.0', id: sanitizeString(id), error: result_or_error.error };
|
|
11
|
+
}
|
|
12
|
+
throw new Error('Invalid response type');
|
|
13
|
+
}
|