@rcrsr/rill-agent-foundry 0.18.4 → 0.18.6
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 +1 -1
- package/dist/index.d.ts +398 -17
- package/dist/index.js +969 -22
- package/package.json +15 -13
- package/dist/conversations.d.ts +0 -23
- package/dist/conversations.d.ts.map +0 -1
- package/dist/conversations.js +0 -91
- package/dist/conversations.js.map +0 -1
- package/dist/errors.d.ts +0 -26
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -40
- package/dist/errors.js.map +0 -1
- package/dist/extract.d.ts +0 -19
- package/dist/extract.d.ts.map +0 -1
- package/dist/extract.js +0 -109
- package/dist/extract.js.map +0 -1
- package/dist/harness.d.ts +0 -21
- package/dist/harness.d.ts.map +0 -1
- package/dist/harness.js +0 -481
- package/dist/harness.js.map +0 -1
- package/dist/id.d.ts +0 -26
- package/dist/id.d.ts.map +0 -1
- package/dist/id.js +0 -83
- package/dist/id.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/response.d.ts +0 -25
- package/dist/response.d.ts.map +0 -1
- package/dist/response.js +0 -154
- package/dist/response.js.map +0 -1
- package/dist/session.d.ts +0 -24
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -34
- package/dist/session.js.map +0 -1
- package/dist/stream.d.ts +0 -47
- package/dist/stream.d.ts.map +0 -1
- package/dist/stream.js +0 -189
- package/dist/stream.js.map +0 -1
- package/dist/telemetry.d.ts +0 -21
- package/dist/telemetry.d.ts.map +0 -1
- package/dist/telemetry.js +0 -53
- package/dist/telemetry.js.map +0 -1
- package/dist/types.d.ts +0 -161
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Azure-hosted harness factory for the [rill](https://github.com/rcrsr/rill) agent
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @rcrsr/rill-agent-foundry @
|
|
8
|
+
npm install @rcrsr/rill-agent-foundry @opentelemetry/api
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
`@opentelemetry/api` is a required peer dependency.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,398 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { TokenCredential } from '@azure/identity';
|
|
4
|
+
import { Tracer } from '@opentelemetry/api';
|
|
5
|
+
import { Hono } from 'hono';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A single text part within a user message content array.
|
|
9
|
+
*/
|
|
10
|
+
export interface ContentPart {
|
|
11
|
+
readonly type: "input_text";
|
|
12
|
+
readonly text: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A user message input item.
|
|
16
|
+
*/
|
|
17
|
+
export interface UserMessageItem {
|
|
18
|
+
readonly type: "message";
|
|
19
|
+
readonly role: "user";
|
|
20
|
+
readonly content: string | ContentPart[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A function call output input item (tool result).
|
|
24
|
+
*/
|
|
25
|
+
export interface FunctionCallOutputItem {
|
|
26
|
+
readonly type: "function_call_output";
|
|
27
|
+
readonly call_id: string;
|
|
28
|
+
readonly output: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A function call item (paired with function_call_output).
|
|
32
|
+
*/
|
|
33
|
+
export interface FunctionCallItem {
|
|
34
|
+
readonly type: "function_call";
|
|
35
|
+
readonly call_id: string;
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly arguments: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Discriminated union of all input item variants.
|
|
41
|
+
*/
|
|
42
|
+
export type InputItem = UserMessageItem | FunctionCallOutputItem | FunctionCallItem;
|
|
43
|
+
/**
|
|
44
|
+
* Tool definition included in a CreateResponse request.
|
|
45
|
+
*/
|
|
46
|
+
export interface ToolDefinition {
|
|
47
|
+
readonly type: "function";
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly description?: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Inbound request body for the Foundry Responses endpoint.
|
|
53
|
+
* Maps to the Azure AI Foundry CreateResponse API.
|
|
54
|
+
*/
|
|
55
|
+
export interface CreateResponse {
|
|
56
|
+
readonly input: string | InputItem[];
|
|
57
|
+
readonly stream?: boolean | undefined;
|
|
58
|
+
readonly conversation?: string | {
|
|
59
|
+
id: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
readonly store?: boolean | undefined;
|
|
62
|
+
readonly model?: string | undefined;
|
|
63
|
+
readonly instructions?: string | undefined;
|
|
64
|
+
readonly temperature?: number | undefined;
|
|
65
|
+
readonly user?: string | undefined;
|
|
66
|
+
readonly metadata?: Record<string, string> | undefined;
|
|
67
|
+
readonly tools?: ToolDefinition[] | undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A single text part in an output message content array.
|
|
71
|
+
*/
|
|
72
|
+
export interface OutputContentPart {
|
|
73
|
+
readonly type: "text";
|
|
74
|
+
readonly text: string;
|
|
75
|
+
readonly annotations: [
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A single output message item in a FoundryResponse.
|
|
80
|
+
*/
|
|
81
|
+
export interface OutputItem {
|
|
82
|
+
readonly id: string;
|
|
83
|
+
readonly type: "message";
|
|
84
|
+
readonly role: "assistant";
|
|
85
|
+
readonly status: "completed";
|
|
86
|
+
readonly content: OutputContentPart[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Synchronous response body returned by the Foundry Responses endpoint.
|
|
90
|
+
*/
|
|
91
|
+
export interface FoundryResponse {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly object: "response";
|
|
94
|
+
readonly created_at: number;
|
|
95
|
+
readonly status: "completed" | "failed";
|
|
96
|
+
readonly output: OutputItem[];
|
|
97
|
+
readonly error: {
|
|
98
|
+
readonly code: string;
|
|
99
|
+
readonly message: string;
|
|
100
|
+
} | null;
|
|
101
|
+
readonly metadata: Record<string, string>;
|
|
102
|
+
readonly temperature: number;
|
|
103
|
+
readonly top_p: number;
|
|
104
|
+
readonly user: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Non-streaming error response body.
|
|
108
|
+
*/
|
|
109
|
+
export interface ErrorResponse {
|
|
110
|
+
readonly error: {
|
|
111
|
+
readonly code: string;
|
|
112
|
+
readonly message: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Streaming error event payload.
|
|
117
|
+
*/
|
|
118
|
+
export interface StreamErrorEvent {
|
|
119
|
+
readonly type: "error";
|
|
120
|
+
readonly message: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* JSON Schema object used in tool parameter definitions.
|
|
124
|
+
*/
|
|
125
|
+
export interface JSONSchemaObject {
|
|
126
|
+
readonly type: "object";
|
|
127
|
+
readonly properties: Record<string, JSONSchemaProperty>;
|
|
128
|
+
readonly required?: string[] | undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A single property in a JSON Schema object.
|
|
132
|
+
*/
|
|
133
|
+
export interface JSONSchemaProperty {
|
|
134
|
+
readonly type: string;
|
|
135
|
+
readonly description?: string | undefined;
|
|
136
|
+
readonly default?: unknown;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A tool definition generated from an agent handler for the Foundry API.
|
|
140
|
+
*/
|
|
141
|
+
export interface FoundryToolDefinition {
|
|
142
|
+
readonly type: "function";
|
|
143
|
+
readonly name: string;
|
|
144
|
+
readonly description: string;
|
|
145
|
+
readonly parameters: JSONSchemaObject;
|
|
146
|
+
readonly strict: boolean;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Runtime metrics for the Foundry harness.
|
|
150
|
+
*/
|
|
151
|
+
export interface FoundryMetrics {
|
|
152
|
+
readonly activeSessions: number;
|
|
153
|
+
readonly totalRequests: number;
|
|
154
|
+
readonly errorCount: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Options accepted by createFoundryHarness.
|
|
158
|
+
* All values default from environment variables.
|
|
159
|
+
*/
|
|
160
|
+
export interface FoundryHarnessOptions {
|
|
161
|
+
readonly port?: number | undefined;
|
|
162
|
+
readonly maxConcurrentSessions?: number | undefined;
|
|
163
|
+
readonly agentName?: string | undefined;
|
|
164
|
+
readonly agentVersion?: string | undefined;
|
|
165
|
+
readonly debugErrors?: boolean | undefined;
|
|
166
|
+
readonly forceSync?: boolean | undefined;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Error thrown when the request input is missing, empty, or unparseable.
|
|
170
|
+
* Maps to HTTP 400. Error code: INVALID_REQUEST.
|
|
171
|
+
*/
|
|
172
|
+
export declare class InputError extends Error {
|
|
173
|
+
/** HTTP status code for this error. */
|
|
174
|
+
readonly statusCode: 400;
|
|
175
|
+
constructor(message: string);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Error thrown when managed identity credential acquisition fails at startup.
|
|
179
|
+
* Triggers a non-zero process exit.
|
|
180
|
+
*/
|
|
181
|
+
export declare class CredentialError extends Error {
|
|
182
|
+
constructor(message: string);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Error thrown when the session pool is at maximum capacity.
|
|
186
|
+
* Maps to HTTP 429. Error code: RATE_LIMITED.
|
|
187
|
+
*/
|
|
188
|
+
export declare class CapacityError extends Error {
|
|
189
|
+
/** HTTP status code for this error. */
|
|
190
|
+
readonly statusCode: 429;
|
|
191
|
+
constructor(max: number);
|
|
192
|
+
}
|
|
193
|
+
export interface IdGenerator {
|
|
194
|
+
readonly responseId: string;
|
|
195
|
+
generateMessageId(): string;
|
|
196
|
+
generateFunctionCallId(): string;
|
|
197
|
+
generateFunctionOutputId(): string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create an IdGenerator scoped to a single request.
|
|
201
|
+
*
|
|
202
|
+
* Partition key extraction priority:
|
|
203
|
+
* 1. conversationId (preferred for conversation-scoped routing)
|
|
204
|
+
* 2. responseId (fallback for response-scoped routing)
|
|
205
|
+
* 3. random 18-char key when neither has a valid format
|
|
206
|
+
*
|
|
207
|
+
* If responseId is not provided, one is generated with prefix `resp`.
|
|
208
|
+
*/
|
|
209
|
+
export declare function createIdGenerator(responseId?: string | undefined, conversationId?: string | undefined): IdGenerator;
|
|
210
|
+
/**
|
|
211
|
+
* Generate a prefixed random ID using crypto-secure entropy.
|
|
212
|
+
* Format: {prefix}{32 alphanumeric chars}
|
|
213
|
+
*
|
|
214
|
+
* Kept for backward compatibility with callers that do not need
|
|
215
|
+
* partition-key correlation.
|
|
216
|
+
*/
|
|
217
|
+
export declare function generateId(prefix: string): string;
|
|
218
|
+
/**
|
|
219
|
+
* Result of extractInput: the extracted params and an optional target agent.
|
|
220
|
+
*/
|
|
221
|
+
export interface ExtractedInput {
|
|
222
|
+
readonly params: Record<string, unknown>;
|
|
223
|
+
readonly targetAgent?: string | undefined;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Extract normalized params and optional target agent from a polymorphic input.
|
|
227
|
+
*
|
|
228
|
+
* Variants:
|
|
229
|
+
* - string → { params: { input: string } }
|
|
230
|
+
* - array with user message → { params: { input: lastUserText } }
|
|
231
|
+
* - array with function_call_output → { params: { tool_results: [...] }, targetAgent }
|
|
232
|
+
*
|
|
233
|
+
* Throws InputError for missing, empty, or unactionable input.
|
|
234
|
+
*/
|
|
235
|
+
export declare function extractInput(input: unknown): ExtractedInput;
|
|
236
|
+
export interface SessionManager {
|
|
237
|
+
/**
|
|
238
|
+
* Acquire a session for the given conversation ID.
|
|
239
|
+
* When conversationId is provided, it is used directly as the session ID.
|
|
240
|
+
* When absent, a new random session ID is generated.
|
|
241
|
+
* Throws CapacityError when the pool is at maximum capacity.
|
|
242
|
+
*/
|
|
243
|
+
acquire(conversationId: string | undefined): string;
|
|
244
|
+
/**
|
|
245
|
+
* Release a session by ID. No-op if the session ID is not tracked.
|
|
246
|
+
*/
|
|
247
|
+
release(sessionId: string): void;
|
|
248
|
+
/**
|
|
249
|
+
* Return the number of currently open sessions.
|
|
250
|
+
*/
|
|
251
|
+
activeCount(): number;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Create a bounded pool manager for concurrent rill sessions.
|
|
255
|
+
*
|
|
256
|
+
* Max capacity reads from MAX_CONCURRENT_SESSIONS env var, default 10.
|
|
257
|
+
*/
|
|
258
|
+
export declare function createSessionManager(): SessionManager;
|
|
259
|
+
export interface HandlerDescription {
|
|
260
|
+
readonly name: string;
|
|
261
|
+
readonly description?: string | undefined;
|
|
262
|
+
readonly params: ReadonlyArray<{
|
|
263
|
+
readonly name: string;
|
|
264
|
+
readonly type: string;
|
|
265
|
+
readonly required: boolean;
|
|
266
|
+
readonly description?: string | undefined;
|
|
267
|
+
readonly defaultValue?: unknown;
|
|
268
|
+
}>;
|
|
269
|
+
}
|
|
270
|
+
export interface RunRequest {
|
|
271
|
+
readonly params?: Record<string, unknown> | undefined;
|
|
272
|
+
readonly timeout?: number | undefined;
|
|
273
|
+
}
|
|
274
|
+
export interface RunContext {
|
|
275
|
+
readonly sessionVars?: Record<string, string> | undefined;
|
|
276
|
+
readonly onLog?: ((message: string) => void) | undefined;
|
|
277
|
+
readonly onChunk?: ((chunk: unknown) => Promise<void>) | undefined;
|
|
278
|
+
}
|
|
279
|
+
export interface RunResponse {
|
|
280
|
+
readonly state: "completed" | "error";
|
|
281
|
+
readonly result: unknown;
|
|
282
|
+
readonly streamed?: boolean | undefined;
|
|
283
|
+
}
|
|
284
|
+
export interface AgentRouter {
|
|
285
|
+
run(agentName: string, request: RunRequest, context?: RunContext): Promise<RunResponse>;
|
|
286
|
+
describe(agentName: string): HandlerDescription | null;
|
|
287
|
+
agents(): string[];
|
|
288
|
+
defaultAgent(): string;
|
|
289
|
+
dispose(): Promise<void>;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Build a synchronous FoundryResponse from a RunResponse.
|
|
293
|
+
*
|
|
294
|
+
* State mapping: 'completed' → 'completed', 'error' → 'failed'.
|
|
295
|
+
* Result is coerced to string; errors are encoded in the response body.
|
|
296
|
+
*/
|
|
297
|
+
export declare function buildSyncResponse(result: RunResponse, responseId: string): FoundryResponse;
|
|
298
|
+
/**
|
|
299
|
+
* Build a non-streaming JSON error response body.
|
|
300
|
+
*
|
|
301
|
+
* When debug is true, the original message is passed through verbatim.
|
|
302
|
+
* When debug is false or absent, a generic message is returned based on
|
|
303
|
+
* the error code per IR-10 (FOUNDRY_AGENT_DEBUG_ERRORS=false behavior).
|
|
304
|
+
*/
|
|
305
|
+
export declare function buildErrorResponse(code: string, message: string, debug?: boolean): ErrorResponse;
|
|
306
|
+
/**
|
|
307
|
+
* Generate Foundry tool definitions from the default agent's handler descriptions.
|
|
308
|
+
*
|
|
309
|
+
* Only the default agent's handlers are exposed (AC-21).
|
|
310
|
+
* Returns an empty array when describe() returns null.
|
|
311
|
+
*/
|
|
312
|
+
export declare function generateToolDefinitions(router: AgentRouter): FoundryToolDefinition[];
|
|
313
|
+
export interface StreamOptions {
|
|
314
|
+
readonly onError?: ((err: unknown) => void) | undefined;
|
|
315
|
+
/** IdGenerator scoped to the request for correlated message IDs. */
|
|
316
|
+
readonly idGenerator?: IdGenerator | undefined;
|
|
317
|
+
/** Session ID echoed back in x-agent-session-id response header. */
|
|
318
|
+
readonly sessionId?: string | undefined;
|
|
319
|
+
/** Invocation ID echoed back in x-agent-invocation-id response header. */
|
|
320
|
+
readonly invocationId?: string | undefined;
|
|
321
|
+
/** Pre-built x-aml-foundry-agents-metadata JSON string. */
|
|
322
|
+
readonly metadataHeader?: string | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* When true, raw error messages are forwarded to clients. When false
|
|
325
|
+
* (default), error events emit a generic message to avoid leaking
|
|
326
|
+
* internal details. Mirrors the harness `debugErrors` option used by
|
|
327
|
+
* `buildErrorResponse`.
|
|
328
|
+
*/
|
|
329
|
+
readonly debugErrors?: boolean | undefined;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Stream a Foundry Responses lifecycle via SSE.
|
|
333
|
+
* Delegates to createFoundryStreamResponse for all paths.
|
|
334
|
+
*/
|
|
335
|
+
export declare function streamFoundryResponse(_c: unknown, responseId: string, resultStream: AsyncIterable<{
|
|
336
|
+
value?: unknown;
|
|
337
|
+
}>, options: StreamOptions & {
|
|
338
|
+
resultPromise?: Promise<string>;
|
|
339
|
+
}): Response;
|
|
340
|
+
export interface ConversationsClient {
|
|
341
|
+
saveItems(conversationId: string, items: ReadonlyArray<unknown>): Promise<void>;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Error thrown when the Conversations API returns a non-success status
|
|
345
|
+
* or when a network timeout occurs.
|
|
346
|
+
* Maps to HTTP 502. Error code: SERVER_ERROR.
|
|
347
|
+
*/
|
|
348
|
+
export declare class PersistenceError extends Error {
|
|
349
|
+
readonly statusCode: 502;
|
|
350
|
+
constructor(message: string);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Create a client for the Azure AI Foundry Conversations API.
|
|
354
|
+
*
|
|
355
|
+
* Auth: DefaultAzureCredential with scope https://ai.azure.com/.default
|
|
356
|
+
* API version: 2025-11-15-preview
|
|
357
|
+
*
|
|
358
|
+
* saveItems() throws PersistenceError on 4xx/5xx or network timeout.
|
|
359
|
+
*/
|
|
360
|
+
export declare function createConversationsClient(projectEndpoint: string, credential: TokenCredential): ConversationsClient;
|
|
361
|
+
export interface TelemetryOptions {
|
|
362
|
+
agentName?: string | undefined;
|
|
363
|
+
agentVersion?: string | undefined;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Initialize the OpenTelemetry SDK when OTEL_EXPORTER_OTLP_ENDPOINT is set.
|
|
367
|
+
* No-op when the env var is absent. Safe to call multiple times.
|
|
368
|
+
*/
|
|
369
|
+
export declare function initTelemetry(options?: TelemetryOptions): void;
|
|
370
|
+
/**
|
|
371
|
+
* Return a tracer for the foundry harness instrumentation scope.
|
|
372
|
+
* Returns a no-op tracer when the SDK is not initialized.
|
|
373
|
+
*/
|
|
374
|
+
export declare function getTracer(): Tracer;
|
|
375
|
+
/**
|
|
376
|
+
* Gracefully shut down the OpenTelemetry SDK and flush pending spans.
|
|
377
|
+
* No-op when the SDK was never initialized.
|
|
378
|
+
*/
|
|
379
|
+
export declare function shutdownTelemetry(): Promise<void>;
|
|
380
|
+
export interface FoundryHarness {
|
|
381
|
+
listen(): Promise<void>;
|
|
382
|
+
close(): Promise<void>;
|
|
383
|
+
readonly app: Hono;
|
|
384
|
+
metrics(): FoundryMetrics;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Create a Foundry harness wrapping an AgentRouter.
|
|
388
|
+
*
|
|
389
|
+
* Routes:
|
|
390
|
+
* POST /responses — main Foundry Responses endpoint
|
|
391
|
+
* POST /runs — alias for /responses
|
|
392
|
+
* GET /readiness — 503 before init, 200 after
|
|
393
|
+
* GET /liveness — always 200
|
|
394
|
+
* GET /metrics — FoundryMetrics JSON
|
|
395
|
+
*/
|
|
396
|
+
export declare function createFoundryHarness(router: AgentRouter, options?: FoundryHarnessOptions): FoundryHarness;
|
|
397
|
+
|
|
398
|
+
export {};
|