@xpert-ai/plugin-sdk 3.18.7 → 3.20.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/MIDDLEWARE_APPS.md +71 -0
  3. package/README.md +57 -0
  4. package/RESOURCE-CARDS-VALIDATION.md +51 -0
  5. package/RESOURCE-CARDS.md +361 -0
  6. package/TOOL-IMAGES.md +85 -0
  7. package/agent-results.cjs.default.js +1 -0
  8. package/agent-results.cjs.js +20 -0
  9. package/agent-results.cjs.mjs +2 -0
  10. package/agent-results.d.ts +1 -0
  11. package/agent-results.esm.js +4 -0
  12. package/index.cjs.js +586 -162
  13. package/index.esm.js +530 -167
  14. package/model-provider.cjs.js +5 -0
  15. package/model-provider.esm.js +5 -1
  16. package/package.json +8 -2
  17. package/results.cjs.js +50 -0
  18. package/results.esm.js +46 -0
  19. package/runtime-capabilities.md +35 -0
  20. package/src/agent-results.d.ts +2 -0
  21. package/src/index.d.ts +5 -0
  22. package/src/lib/agent/handoff/agent-chat.contract.d.ts +6 -1
  23. package/src/lib/agent/handoff/agent-runtime-message.contract.d.ts +319 -0
  24. package/src/lib/agent/handoff/index.d.ts +1 -0
  25. package/src/lib/agent/index.d.ts +2 -0
  26. package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +55 -20
  27. package/src/lib/agent/middleware/index.d.ts +1 -0
  28. package/src/lib/agent/middleware/model-requirements.d.ts +9 -0
  29. package/src/lib/agent/middleware/strategy.interface.d.ts +4 -0
  30. package/src/lib/agent/middleware/types.d.ts +20 -3
  31. package/src/lib/agent/resource-card.d.ts +3 -0
  32. package/src/lib/agent/runtime/activity.d.ts +6 -0
  33. package/src/lib/agent/runtime/capability.d.ts +37 -0
  34. package/src/lib/agent/runtime/cli-model-profile.d.ts +62 -0
  35. package/src/lib/agent/runtime/dispatch.d.ts +517 -0
  36. package/src/lib/agent/runtime/execution-runner.d.ts +66 -0
  37. package/src/lib/agent/runtime/index.d.ts +10 -0
  38. package/src/lib/agent/runtime/model-execution.d.ts +15 -0
  39. package/src/lib/agent/runtime/results.d.ts +335 -0
  40. package/src/lib/agent/runtime/strategy.d.ts +53 -0
  41. package/src/lib/agent/runtime/task-wait.d.ts +35 -0
  42. package/src/lib/agent/runtime/types.d.ts +156 -0
  43. package/src/lib/ai-model/ai-model-provider.interface.d.ts +2 -0
  44. package/src/lib/ai-model/ai-model.d.ts +2 -0
  45. package/src/lib/ai-model/index.d.ts +3 -0
  46. package/src/lib/ai-model/llm.d.ts +4 -2
  47. package/src/lib/ai-model/native-model.d.ts +22 -0
  48. package/src/lib/ai-model/realtime.d.ts +36 -0
  49. package/src/lib/ai-model/token-usage.d.ts +13 -0
  50. package/src/lib/assistant-capability/index.d.ts +42 -0
  51. package/src/lib/connector/runtime-capability.d.ts +2 -0
  52. package/src/lib/connector/strategy.interface.d.ts +8 -0
  53. package/src/lib/core/context/request-context.d.ts +6 -0
  54. package/src/lib/core/strategy-bus.d.ts +0 -3
  55. package/src/lib/evolution/runtime-capability.d.ts +2 -1
  56. package/src/lib/integration/strategy.interface.d.ts +22 -0
  57. package/src/lib/mcp/app.d.ts +14 -1
  58. package/src/lib/project-task/index.d.ts +66 -0
  59. package/src/lib/project-type/index.d.ts +71 -0
  60. package/src/lib/resource-card-provider/index.d.ts +3 -0
  61. package/src/lib/resource-card-provider/provider.decorator.d.ts +4 -0
  62. package/src/lib/resource-card-provider/provider.registry.d.ts +14 -0
  63. package/src/lib/resource-card-provider/types.d.ts +36 -0
  64. package/src/lib/resource-card.d.ts +6 -0
  65. package/src/lib/runtime/capabilities/index.d.ts +1 -0
  66. package/src/lib/runtime/capabilities/knowledge-graph.d.ts +59 -0
  67. package/src/lib/runtime/capabilities/knowledgebase-documents.d.ts +21 -0
  68. package/src/lib/runtime/capabilities/knowledgebase.d.ts +8 -3
  69. package/src/lib/runtime/capabilities/project-access.d.ts +2 -1
  70. package/src/lib/runtime/capabilities/project-provisioning.d.ts +13 -0
  71. package/src/lib/runtime/capabilities/tool-images.d.ts +24 -0
  72. package/src/lib/runtime/runtime-scope.d.ts +7 -1
  73. package/src/lib/sandbox/execution-environment.d.ts +12 -0
  74. package/src/lib/sandbox/execution.d.ts +13 -0
  75. package/src/lib/sandbox/index.d.ts +1 -0
  76. package/src/lib/sandbox/managed-service.d.ts +1 -0
  77. package/src/lib/sandbox/protocol.d.ts +2 -0
  78. package/src/lib/tool-provider/types.d.ts +6 -0
  79. package/src/lib/types.d.ts +2 -1
  80. package/src/lib/workflow/trigger/strategy.interface.d.ts +2 -1
@@ -0,0 +1,335 @@
1
+ import { z } from 'zod/v3';
2
+ import { type AgentOutputDelivery } from '@xpert-ai/contracts';
3
+ /** Opt in to the host's authorized, on-demand result View from middleware metadata. */
4
+ export declare const AGENT_TASK_RESULTS_FEATURE = "agent_task_results";
5
+ export { agentResultPathSchema, agentOutputDeliverySchema, type AgentOutputDelivery } from '@xpert-ai/contracts';
6
+ /** Machine-readable result kind; file declarations are not committed artifacts or download grants. */
7
+ export declare const agentResultItemSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
8
+ type: z.ZodLiteral<"analysis">;
9
+ id: z.ZodString;
10
+ title: z.ZodString;
11
+ summary: z.ZodString;
12
+ }, "strict", z.ZodTypeAny, {
13
+ type?: "analysis";
14
+ id?: string;
15
+ title?: string;
16
+ summary?: string;
17
+ }, {
18
+ type?: "analysis";
19
+ id?: string;
20
+ title?: string;
21
+ summary?: string;
22
+ }>, z.ZodObject<{
23
+ type: z.ZodLiteral<"changes">;
24
+ files: z.ZodArray<z.ZodObject<{
25
+ path: z.ZodEffects<z.ZodString, string, string>;
26
+ change: z.ZodEnum<["created", "modified", "deleted"]>;
27
+ }, "strict", z.ZodTypeAny, {
28
+ path?: string;
29
+ change?: "created" | "modified" | "deleted";
30
+ }, {
31
+ path?: string;
32
+ change?: "created" | "modified" | "deleted";
33
+ }>, "many">;
34
+ id: z.ZodString;
35
+ title: z.ZodString;
36
+ summary: z.ZodString;
37
+ }, "strict", z.ZodTypeAny, {
38
+ type?: "changes";
39
+ id?: string;
40
+ title?: string;
41
+ summary?: string;
42
+ files?: {
43
+ path?: string;
44
+ change?: "created" | "modified" | "deleted";
45
+ }[];
46
+ }, {
47
+ type?: "changes";
48
+ id?: string;
49
+ title?: string;
50
+ summary?: string;
51
+ files?: {
52
+ path?: string;
53
+ change?: "created" | "modified" | "deleted";
54
+ }[];
55
+ }>, z.ZodObject<{
56
+ type: z.ZodLiteral<"tests">;
57
+ status: z.ZodEnum<["passed", "failed", "skipped"]>;
58
+ command: z.ZodOptional<z.ZodString>;
59
+ id: z.ZodString;
60
+ title: z.ZodString;
61
+ summary: z.ZodString;
62
+ }, "strict", z.ZodTypeAny, {
63
+ type?: "tests";
64
+ status?: "passed" | "failed" | "skipped";
65
+ id?: string;
66
+ title?: string;
67
+ summary?: string;
68
+ command?: string;
69
+ }, {
70
+ type?: "tests";
71
+ status?: "passed" | "failed" | "skipped";
72
+ id?: string;
73
+ title?: string;
74
+ summary?: string;
75
+ command?: string;
76
+ }>, z.ZodObject<{
77
+ type: z.ZodLiteral<"file">;
78
+ path: z.ZodEffects<z.ZodString, string, string>;
79
+ id: z.ZodString;
80
+ title: z.ZodString;
81
+ summary: z.ZodString;
82
+ }, "strict", z.ZodTypeAny, {
83
+ type?: "file";
84
+ path?: string;
85
+ id?: string;
86
+ title?: string;
87
+ summary?: string;
88
+ }, {
89
+ type?: "file";
90
+ path?: string;
91
+ id?: string;
92
+ title?: string;
93
+ summary?: string;
94
+ }>]>;
95
+ export type AgentResultItem = z.output<typeof agentResultItemSchema>;
96
+ /** Explicit final response envelope shared by adapters; ordinary prose is never classified heuristically. */
97
+ export declare const agentTaskResultSchema: z.ZodEffects<z.ZodObject<{
98
+ version: z.ZodLiteral<1>;
99
+ summary: z.ZodString;
100
+ items: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
101
+ type: z.ZodLiteral<"analysis">;
102
+ id: z.ZodString;
103
+ title: z.ZodString;
104
+ summary: z.ZodString;
105
+ }, "strict", z.ZodTypeAny, {
106
+ type?: "analysis";
107
+ id?: string;
108
+ title?: string;
109
+ summary?: string;
110
+ }, {
111
+ type?: "analysis";
112
+ id?: string;
113
+ title?: string;
114
+ summary?: string;
115
+ }>, z.ZodObject<{
116
+ type: z.ZodLiteral<"changes">;
117
+ files: z.ZodArray<z.ZodObject<{
118
+ path: z.ZodEffects<z.ZodString, string, string>;
119
+ change: z.ZodEnum<["created", "modified", "deleted"]>;
120
+ }, "strict", z.ZodTypeAny, {
121
+ path?: string;
122
+ change?: "created" | "modified" | "deleted";
123
+ }, {
124
+ path?: string;
125
+ change?: "created" | "modified" | "deleted";
126
+ }>, "many">;
127
+ id: z.ZodString;
128
+ title: z.ZodString;
129
+ summary: z.ZodString;
130
+ }, "strict", z.ZodTypeAny, {
131
+ type?: "changes";
132
+ id?: string;
133
+ title?: string;
134
+ summary?: string;
135
+ files?: {
136
+ path?: string;
137
+ change?: "created" | "modified" | "deleted";
138
+ }[];
139
+ }, {
140
+ type?: "changes";
141
+ id?: string;
142
+ title?: string;
143
+ summary?: string;
144
+ files?: {
145
+ path?: string;
146
+ change?: "created" | "modified" | "deleted";
147
+ }[];
148
+ }>, z.ZodObject<{
149
+ type: z.ZodLiteral<"tests">;
150
+ status: z.ZodEnum<["passed", "failed", "skipped"]>;
151
+ command: z.ZodOptional<z.ZodString>;
152
+ id: z.ZodString;
153
+ title: z.ZodString;
154
+ summary: z.ZodString;
155
+ }, "strict", z.ZodTypeAny, {
156
+ type?: "tests";
157
+ status?: "passed" | "failed" | "skipped";
158
+ id?: string;
159
+ title?: string;
160
+ summary?: string;
161
+ command?: string;
162
+ }, {
163
+ type?: "tests";
164
+ status?: "passed" | "failed" | "skipped";
165
+ id?: string;
166
+ title?: string;
167
+ summary?: string;
168
+ command?: string;
169
+ }>, z.ZodObject<{
170
+ type: z.ZodLiteral<"file">;
171
+ path: z.ZodEffects<z.ZodString, string, string>;
172
+ id: z.ZodString;
173
+ title: z.ZodString;
174
+ summary: z.ZodString;
175
+ }, "strict", z.ZodTypeAny, {
176
+ type?: "file";
177
+ path?: string;
178
+ id?: string;
179
+ title?: string;
180
+ summary?: string;
181
+ }, {
182
+ type?: "file";
183
+ path?: string;
184
+ id?: string;
185
+ title?: string;
186
+ summary?: string;
187
+ }>]>, "many">;
188
+ }, "strict", z.ZodTypeAny, {
189
+ summary?: string;
190
+ version?: 1;
191
+ items?: ({
192
+ type?: "analysis";
193
+ id?: string;
194
+ title?: string;
195
+ summary?: string;
196
+ } | {
197
+ type?: "changes";
198
+ id?: string;
199
+ title?: string;
200
+ summary?: string;
201
+ files?: {
202
+ path?: string;
203
+ change?: "created" | "modified" | "deleted";
204
+ }[];
205
+ } | {
206
+ type?: "tests";
207
+ status?: "passed" | "failed" | "skipped";
208
+ id?: string;
209
+ title?: string;
210
+ summary?: string;
211
+ command?: string;
212
+ } | {
213
+ type?: "file";
214
+ path?: string;
215
+ id?: string;
216
+ title?: string;
217
+ summary?: string;
218
+ })[];
219
+ }, {
220
+ summary?: string;
221
+ version?: 1;
222
+ items?: ({
223
+ type?: "analysis";
224
+ id?: string;
225
+ title?: string;
226
+ summary?: string;
227
+ } | {
228
+ type?: "changes";
229
+ id?: string;
230
+ title?: string;
231
+ summary?: string;
232
+ files?: {
233
+ path?: string;
234
+ change?: "created" | "modified" | "deleted";
235
+ }[];
236
+ } | {
237
+ type?: "tests";
238
+ status?: "passed" | "failed" | "skipped";
239
+ id?: string;
240
+ title?: string;
241
+ summary?: string;
242
+ command?: string;
243
+ } | {
244
+ type?: "file";
245
+ path?: string;
246
+ id?: string;
247
+ title?: string;
248
+ summary?: string;
249
+ })[];
250
+ }>, {
251
+ summary?: string;
252
+ version?: 1;
253
+ items?: ({
254
+ type?: "analysis";
255
+ id?: string;
256
+ title?: string;
257
+ summary?: string;
258
+ } | {
259
+ type?: "changes";
260
+ id?: string;
261
+ title?: string;
262
+ summary?: string;
263
+ files?: {
264
+ path?: string;
265
+ change?: "created" | "modified" | "deleted";
266
+ }[];
267
+ } | {
268
+ type?: "tests";
269
+ status?: "passed" | "failed" | "skipped";
270
+ id?: string;
271
+ title?: string;
272
+ summary?: string;
273
+ command?: string;
274
+ } | {
275
+ type?: "file";
276
+ path?: string;
277
+ id?: string;
278
+ title?: string;
279
+ summary?: string;
280
+ })[];
281
+ }, {
282
+ summary?: string;
283
+ version?: 1;
284
+ items?: ({
285
+ type?: "analysis";
286
+ id?: string;
287
+ title?: string;
288
+ summary?: string;
289
+ } | {
290
+ type?: "changes";
291
+ id?: string;
292
+ title?: string;
293
+ summary?: string;
294
+ files?: {
295
+ path?: string;
296
+ change?: "created" | "modified" | "deleted";
297
+ }[];
298
+ } | {
299
+ type?: "tests";
300
+ status?: "passed" | "failed" | "skipped";
301
+ id?: string;
302
+ title?: string;
303
+ summary?: string;
304
+ command?: string;
305
+ } | {
306
+ type?: "file";
307
+ path?: string;
308
+ id?: string;
309
+ title?: string;
310
+ summary?: string;
311
+ })[];
312
+ }>;
313
+ export type AgentTaskResult = z.output<typeof agentTaskResultSchema>;
314
+ /** Persist only after the platform has committed the artifact; never accept an ID invented by a model. */
315
+ export interface AgentResultArtifact {
316
+ id: string;
317
+ name?: string;
318
+ mimeType?: string;
319
+ /** Required for downloads; optional only to read older task records without changing their meaning. */
320
+ versionId?: string;
321
+ /** Item paths included in this immutable artifact. */
322
+ paths?: string[];
323
+ }
324
+ export interface AgentArtifactSelection {
325
+ mode: 'files' | 'archive';
326
+ /** Exact relative files; the runner still enforces filesystem and delivery authorization. */
327
+ paths: string[];
328
+ }
329
+ /** Export outcome is independent of task success, so an export error cannot hide completed work. */
330
+ export interface AgentOutputExport {
331
+ mode: AgentOutputDelivery['mode'];
332
+ status: 'not_requested' | 'completed' | 'failed' | 'unavailable';
333
+ /** Safe diagnostic only; execution status is independent of export status. */
334
+ error?: string;
335
+ }
@@ -0,0 +1,53 @@
1
+ import { DiscoveryService, Reflector } from '@nestjs/core';
2
+ import type { RuntimeCapabilityRegistry } from '../../core/runtime-capability';
3
+ import { BaseStrategyRegistry, type StrategySource } from '../../strategy';
4
+ import type { AgentActivityRecorder } from './activity';
5
+ import type { AgentInvocationInput, AgentInvocationScope, AgentJson, AgentRuntimeCapabilities, AgentRuntimeHandle, AgentRuntimeObservation, AgentTarget } from './types';
6
+ /** Trusted per-operation host context, independent of graph and provider transport details. */
7
+ export interface AgentRuntimeContext {
8
+ /** Durable host invocation ID used to correlate provider receipts. */
9
+ invocationId: string;
10
+ scope: Readonly<AgentInvocationScope>;
11
+ /** Cooperative cancellation; abort alone does not confirm remote termination. */
12
+ signal?: AbortSignal;
13
+ capabilities: RuntimeCapabilityRegistry;
14
+ /** Available only for declared public activity; scoped by the host to this invocation. */
15
+ activity?: AgentActivityRecorder;
16
+ /** Persist a receipt before waiting on long-running work. Await persistence and propagate failures. */
17
+ checkpoint(observation: AgentRuntimeObservation): Promise<void>;
18
+ }
19
+ /** Pinned launch/recovery input supplied after the host reserves the invocation. */
20
+ export interface AgentRuntimeStart {
21
+ target: Readonly<AgentTarget>;
22
+ input: Readonly<AgentInvocationInput>;
23
+ /** Host invocation ID for provider idempotency; distinct from the caller callId. */
24
+ operationId: string;
25
+ /** Existing receipt for recovery. Reattach instead of resending the initial task. */
26
+ previous?: AgentRuntimeHandle;
27
+ }
28
+ /**
29
+ * Extension point for native and third-party runtimes. Strategies may serve concurrent calls;
30
+ * keep per-invocation state isolated. The host owns authorization and persistence.
31
+ */
32
+ export interface IAgentRuntimeStrategy {
33
+ /** Support flags must agree with the optional methods implemented below. */
34
+ readonly capabilities: AgentRuntimeCapabilities;
35
+ /** Launch or recover approved work; checkpoint the handle as soon as it is known. */
36
+ start(request: AgentRuntimeStart, context: AgentRuntimeContext): Promise<AgentRuntimeObservation>;
37
+ /** Reconcile existing work without relaunching it. Return unknown if its outcome cannot be established. */
38
+ inspect(handle: AgentRuntimeHandle, context: AgentRuntimeContext): Promise<AgentRuntimeObservation>;
39
+ /** Required when cancellation is supported. Return cancelled only after termination is confirmed. */
40
+ cancel?(handle: AgentRuntimeHandle, context: AgentRuntimeContext): Promise<AgentRuntimeObservation>;
41
+ /** Required when interactions are supported. Validate the response against the pending interaction. */
42
+ respond?(handle: AgentRuntimeHandle, interactionId: string, response: AgentJson, context: AgentRuntimeContext): Promise<AgentRuntimeObservation>;
43
+ }
44
+ /** Nest discovery metadata key for runtime strategies. */
45
+ export declare const AGENT_RUNTIME_STRATEGY = "AGENT_RUNTIME_STRATEGY";
46
+ /** Associate a stable provider key with an adapter. Also declare @Injectable() and register the provider. */
47
+ export declare const AgentRuntimeStrategy: (provider: string) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
48
+ /** Scoped strategy registry with pinned provider/version lookup for continuation. */
49
+ export declare class AgentRuntimeRegistry extends BaseStrategyRegistry<IAgentRuntimeStrategy> {
50
+ constructor(discoveryService: DiscoveryService, reflector: Reflector);
51
+ /** Find the exact original scope/plugin/version, without fallback. Returns undefined if unavailable. */
52
+ getPinned(provider: string, source: StrategySource): IAgentRuntimeStrategy | undefined;
53
+ }
@@ -0,0 +1,35 @@
1
+ /** Provider-neutral dependency waiting. A wait ending does not terminate its tasks. */
2
+ export type TaskWaitMode = 'any' | 'all';
3
+ /** `completed` means terminal, not necessarily successful. `timeout` is a historical durable-wait deadline. */
4
+ export type TaskWaitReason = 'completed' | 'pending' | 'attention' | 'timeout' | 'unavailable';
5
+ export interface TaskWaitRequest {
6
+ /** Stable tool-call identity, assigned by the host rather than the model. */
7
+ callId: string;
8
+ /** Distinct handles owned by the caller; the invocation adapter accepts at most 32. */
9
+ taskIds: string[];
10
+ /** Whether one terminal task or all terminal tasks satisfy this wait. */
11
+ mode: TaskWaitMode;
12
+ /** Requested observation window, bounded by host policy; expiry returns pending, not an interrupt. */
13
+ timeoutMs?: number;
14
+ }
15
+ export interface TaskWaitResult<T> {
16
+ reason: TaskWaitReason;
17
+ /** Latest observed states, including unfinished tasks when mode is `any`. */
18
+ tasks: T[];
19
+ }
20
+ /** Host policy caps the requested observation window. */
21
+ export interface TaskWaitPolicy {
22
+ /** Default initial observation window, in milliseconds. */
23
+ inlineWaitMs: number;
24
+ /** Maximum duration of a single observation call, in milliseconds. */
25
+ maxInlineWaitMs: number;
26
+ /** Interval between backend reads; each read must bound its own I/O. */
27
+ pollIntervalMs: number;
28
+ /** Historical persisted wait deadline, independent of a new status-call duration. */
29
+ maxWaitMs: number;
30
+ /** Historical grace period before an ambiguous outcome is reported unavailable. */
31
+ unknownGraceMs: number;
32
+ }
33
+ /** Domain adapters map their explicit states into these dependency states. */
34
+ export type TaskDependencyState = 'pending' | 'completed' | 'attention' | 'unknown';
35
+ export declare function taskWaitReason(states: readonly TaskDependencyState[], mode: TaskWaitMode): TaskWaitReason | undefined;
@@ -0,0 +1,156 @@
1
+ import type { AgentInvocationStatus, AgentRuntimeProgress, ModelExecutionEnvironment, ExecutionActivityCapabilities } from '@xpert-ai/contracts';
2
+ export type { AgentInvocationStatus, AgentRuntimeProgress } from '@xpert-ai/contracts';
3
+ import type { AgentInvocationDispatchContext } from './dispatch';
4
+ import type { AgentRunnerReceipt } from './execution-runner';
5
+ import type { AgentOutputDelivery, AgentOutputExport, AgentResultArtifact, AgentResultItem } from './results';
6
+ /** Serializable invocation data. Use finite numbers and plain objects; exclude credentials. */
7
+ export type AgentJson = null | boolean | number | string | AgentJson[] | {
8
+ [key: string]: AgentJson;
9
+ };
10
+ /** Host-authorized ownership and execution scope; never accept identities from model input. */
11
+ export interface AgentInvocationScope {
12
+ tenantId: string;
13
+ organizationId: string;
14
+ userId: string;
15
+ workspaceId?: string;
16
+ projectId?: string;
17
+ /** Platform conversation ID, distinct from a provider session ID. */
18
+ conversationId?: string;
19
+ /** Opaque parent execution identity; host Task adapters may use logical IDs. */
20
+ parentExecutionId: string;
21
+ /** Calling Agent key or host-assigned background-task entry. */
22
+ callerAgentKey: string;
23
+ /** Omitted preserves existing Assistant callers. Project general agents have no fabricated Assistant ID. */
24
+ callerType?: 'xpert' | 'project_agent';
25
+ callerXpertId?: string;
26
+ }
27
+ /** Authorized, version-pinned target. Pass the resolved snapshot unchanged. */
28
+ export interface AgentTarget {
29
+ /** Opaque host binding ID; do not assume UUID format or derive the provider from it. */
30
+ bindingId: string;
31
+ /** Registered AgentRuntimeStrategy key. */
32
+ provider: string;
33
+ /** Opaque configuration version, distinct from the invocation revision. */
34
+ revision: string;
35
+ /** Provider-specific target/profile reference. */
36
+ reference: string;
37
+ /** Validated configuration; use managed secret references instead of credentials. */
38
+ configuration: {
39
+ [key: string]: AgentJson;
40
+ };
41
+ }
42
+ /** Provider support flags; they do not grant caller permissions. */
43
+ export interface AgentRuntimeCapabilities {
44
+ activity?: ExecutionActivityCapabilities;
45
+ /** Explicit adapter compatibility; does not install tools or grant model/environment access. */
46
+ executionTools?: Array<{
47
+ id: string;
48
+ versions: string[];
49
+ environments: ModelExecutionEnvironment['type'][];
50
+ }>;
51
+ /**
52
+ * Recovery by host checkpoint, existing provider session, or none.
53
+ * Session recovery does not guarantee survival of a worker crash.
54
+ */
55
+ recovery: 'checkpoint' | 'session' | 'none';
56
+ interactions: boolean;
57
+ /** Supports cancel requests; termination still requires provider confirmation. */
58
+ cancellation: boolean;
59
+ /** Work can continue after start() returns. */
60
+ background: boolean;
61
+ /** Omitted means unsupported. This declaration alone does not enable a host message API. */
62
+ runningMessages?: boolean;
63
+ /** A new invocation may reuse a prior session only through an explicitly supported adapter path. */
64
+ sessionContinuation?: boolean;
65
+ }
66
+ /** Provider-neutral task payload; supported structured fields depend on the adapter. */
67
+ export interface AgentInvocationInput {
68
+ prompt: string;
69
+ /** No export by default; files/archive require an explicit delivery request. */
70
+ delivery?: AgentOutputDelivery;
71
+ parameters?: {
72
+ [key: string]: AgentJson;
73
+ };
74
+ context?: {
75
+ [key: string]: AgentJson;
76
+ };
77
+ /** Host-managed file references, authorized and materialized by the adapter. */
78
+ files?: Array<{
79
+ id: string;
80
+ name?: string;
81
+ }>;
82
+ }
83
+ /** Output or in-progress receipt. Check invocation status before treating it as final. */
84
+ export interface AgentInvocationResult {
85
+ text: string;
86
+ /** Explicit adapter-normalized findings; display kind is never inferred from prose or titles. */
87
+ items?: AgentResultItem[];
88
+ /** Separate delivery outcome; task success does not imply that files were exported. */
89
+ export?: AgentOutputExport;
90
+ /** Adapter-defined structured output. */
91
+ data?: AgentJson;
92
+ /** Host-managed output references; normal artifact authorization applies. */
93
+ artifacts?: AgentResultArtifact[];
94
+ }
95
+ /** Persisted provider receipt. Session/run IDs are distinct from the host invocation ID. */
96
+ export interface AgentRuntimeHandle {
97
+ /** Optional host-managed process receipt; direct remote runtimes need only their session/run IDs. */
98
+ runner?: AgentRunnerReceipt;
99
+ sessionId: string;
100
+ runId: string;
101
+ metadata?: {
102
+ [key: string]: AgentJson;
103
+ };
104
+ }
105
+ /** Pending question or approval. Respond using its exact ID and provider-defined data schema. */
106
+ export interface AgentInteraction {
107
+ id: string;
108
+ kind: 'approval' | 'input';
109
+ prompt: string;
110
+ data?: AgentJson;
111
+ }
112
+ /**
113
+ * Partial provider observation; omitted fields may retain previously stored values.
114
+ * The host manages identity, revisions and persistence.
115
+ */
116
+ export interface AgentRuntimeObservation {
117
+ /** succeeded requires a result, even for structured-only output. */
118
+ status: AgentInvocationStatus;
119
+ handle?: AgentRuntimeHandle;
120
+ result?: AgentInvocationResult;
121
+ interaction?: AgentInteraction;
122
+ /** Reported work/activity only; it never confirms business acceptance. */
123
+ progress?: AgentRuntimeProgress;
124
+ /** Safe diagnostic message without credentials or raw provider payloads. */
125
+ error?: string;
126
+ }
127
+ /** Request pinned by the host before dispatch. */
128
+ export interface AgentInvocationRequest {
129
+ target: AgentTarget;
130
+ /**
131
+ * Idempotency key within the captured scope (max 1024 characters).
132
+ * Reuse for the same request; changed input or target is a conflict.
133
+ */
134
+ callId: string;
135
+ input: AgentInvocationInput;
136
+ /** Optional host-owned asynchronous reply and project association; not supplied by the execution Agent. */
137
+ dispatch?: AgentInvocationDispatchContext;
138
+ }
139
+ /** Host-owned invocation snapshot; not an update DTO. */
140
+ export interface AgentInvocation extends AgentRuntimeObservation {
141
+ /** Pinned presentation contract remains readable after the runtime plugin is removed. */
142
+ activity?: ExecutionActivityCapabilities;
143
+ /** Host startup fence; intermediate receipts are not inspected until start returns or this deadline expires. */
144
+ startPendingUntil?: string;
145
+ /** Host invocation ID used by inspect, cancel and respond. */
146
+ id: string;
147
+ /** Host-managed concurrency revision, distinct from the target version. */
148
+ revision: number;
149
+ scope: AgentInvocationScope;
150
+ request: AgentInvocationRequest;
151
+ /** Host timestamps in ISO 8601 format. */
152
+ createdAt: string;
153
+ updatedAt: string;
154
+ }
155
+ /** Checks confirmed completion; unknown remains non-terminal. */
156
+ export declare function isAgentInvocationTerminal(status: AgentInvocationStatus): boolean;
@@ -4,7 +4,9 @@ import { Embeddings } from '@langchain/core/embeddings';
4
4
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
5
5
  import { AIGCModelClient, AsyncAIGCModelClient, IRerank } from './types';
6
6
  import { AIModel } from './ai-model';
7
+ import type { NativeModelClientFactory } from './native-model';
7
8
  export interface IAIModelProviderStrategy {
9
+ getNativeModelClient?: NativeModelClientFactory;
8
10
  /**
9
11
  * Provider metadata
10
12
  */
@@ -1,4 +1,5 @@
1
1
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
+ import type { RealtimeModelConnection } from './realtime';
2
3
  import { AIModelEntity, AiModelTypeEnum, ICopilotModel, ModelUsagePricingContext, ModelUsagePricingSnapshot, ParameterRule, PriceInfo, PriceType } from '@xpert-ai/contracts';
3
4
  import { Logger } from '@nestjs/common';
4
5
  import { ModelProvider } from './abstract-provider';
@@ -13,6 +14,7 @@ export declare abstract class AIModel implements IAIModel {
13
14
  private positions;
14
15
  constructor(modelProvider: ModelProvider, modelType: AiModelTypeEnum);
15
16
  abstract validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
17
+ getRealtimeModel(_copilotModel: ICopilotModel): RealtimeModelConnection;
16
18
  getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
17
19
  getAIGCModel(copilotModel: ICopilotModel, options?: TChatModelOptions): AIGCModelClient | AsyncAIGCModelClient;
18
20
  getPrice(model: string, credentials: Record<string, any>, priceType: PriceType, tokens: number, inputTokens?: number): PriceInfo;
@@ -12,3 +12,6 @@ export * from './openai-compatible';
12
12
  export * from './model-provider-http-client';
13
13
  export * from './utils/index';
14
14
  export * from './commands/index';
15
+ export * from './token-usage';
16
+ export * from './native-model';
17
+ export * from './realtime';
@@ -40,6 +40,8 @@ export declare abstract class LargeLanguageModel extends AIModel {
40
40
  #private;
41
41
  protected startedAt: DOMHighResTimeStamp;
42
42
  protected _commonParameterRules(model: string): ParameterRule[];
43
+ /** Price already normalized provider facts without starting another inference or writing a ledger. */
44
+ priceActualTokenUsage(model: string, tokenUsage: TTokenUsage, context?: LLMPriceContext): ILLMUsage;
43
45
  protected calcResponseUsage(model: string, credentials: Record<string, any>, promptTokens: number, completionTokens: number, startedAt?: number, tokenUsage?: TTokenUsage, pricingContext?: LLMPriceContext): ILLMUsage;
44
46
  createHandleUsageCallbacks(copilot: ICopilot, model: string, credentials: any, handleLLMTokens: TChatModelOptions['handleLLMTokens'], pricingConfiguration?: LLMUsagePricingConfiguration): {
45
47
  name: string;
@@ -90,8 +92,8 @@ export declare abstract class LargeLanguageModel extends AIModel {
90
92
  handleRetrieverError?(err: any, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;
91
93
  handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): Promise<any> | any;
92
94
  }[];
93
- createHandleLLMErrorCallbacks(fields: any, logger?: Logger): {
94
- handleLLMError: (err: any) => void;
95
+ createHandleLLMErrorCallbacks(_fields: unknown, logger?: Logger): {
96
+ handleLLMError: (error: unknown) => void;
95
97
  };
96
98
  protected getCustomizableModelSchemaFromCredentials(model: string, credentials: Record<string, any>): AIModelEntity | null;
97
99
  protected createHandleVerboseCallbacks(enabled?: boolean, logger?: Logger): {
@@ -0,0 +1,22 @@
1
+ import type { ICopilotModel, ILLMUsage, LLMPriceContext, ModelExecutionProtocol, TTokenUsage } from '@xpert-ai/contracts';
2
+ export type NativeModelProtocol = Extract<ModelExecutionProtocol, 'openai_responses' | 'anthropic_messages'>;
3
+ export type NativeModelJson = null | boolean | number | string | NativeModelJson[] | {
4
+ [key: string]: NativeModelJson;
5
+ };
6
+ export type NativeModelBody = {
7
+ [key: string]: NativeModelJson;
8
+ };
9
+ /** Server-only capability. Provider credentials and configured upstream URLs never leave this closure. */
10
+ export interface NativeModelClient {
11
+ readonly protocol: NativeModelProtocol;
12
+ generate(body: NativeModelBody, headers: Readonly<Record<string, string>>, signal: AbortSignal): Promise<Response>;
13
+ priceUsage(usage: TTokenUsage, context?: LLMPriceContext): ILLMUsage;
14
+ }
15
+ export type NativeModelClientFactory = (protocol: NativeModelProtocol, model: ICopilotModel) => Promise<NativeModelClient>;
16
+ /** A single fetch is one billable attempt. No SDK retries or redirects to another credential origin. */
17
+ export declare function nativeModelTransport(input: {
18
+ protocol: NativeModelProtocol;
19
+ baseUrl: string;
20
+ authorization: string;
21
+ fetch?: typeof fetch;
22
+ }): NativeModelClient['generate'];