@ideascol/agents-generator-sdk 0.7.4 → 0.8.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.
@@ -1,21 +1,47 @@
1
- import { ApiError, CancelablePromise, CancelError, ConversationsService, MessageCreate, OpenAPI, AgentService, McpServersService, RootService, FileLibraryService, CredentialsService, AdminAgentsService, PublicAgentsService, PublicConversationsService, AdminConversationsService, AdminCredentialsService, AdminFileLibraryService, AdminMcpServersService, AdminWorkspacesService, WorkspaceCollaboratorsService, AdminApiKeysService, PresenceService, ModelsService, SchemaGeneratorService, TokenUsageService, AuthService } from "./clients/agents-generator";
1
+ import { ApiError, CancelablePromise, CancelError, ConversationsService, MessageCreate, OpenAPI, AgentService, McpServersService, RootService, FileLibraryService, CredentialsService, AdminAgentsService, PublicAgentsService, PublicConversationsService, AdminConversationsService, AdminCredentialsService, AdminFileLibraryService, AdminMcpServersService, AdminWorkspacesService, WorkspaceCollaboratorsService, AdminApiKeysService, PresenceService, ModelsService, SchemaGeneratorService, TokenUsageService, AuthService, type AgentRequest, type CreateAgentResponse, type Handoff, type MCPServerReference } from "./clients/agents-generator";
2
2
  export * from "./clients/agents-generator";
3
- export interface StreamEvent {
4
- type: string;
5
- content?: string;
6
- message_id?: string;
7
- transfer?: TransferEvent;
8
- }
3
+ export { type ModelProvider, type ModelName, type ModelInfo, MODEL_PROVIDERS, MODEL_NAMES, MODELS_BY_PROVIDER, MODEL_INFO, } from "./generated/models";
4
+ import type { ModelName, ModelProvider } from "./generated/models";
9
5
  export interface TransferEvent {
10
6
  from_agent?: string;
11
7
  to_agent?: string;
12
8
  reason?: string;
13
9
  }
10
+ export interface MessageStreamEvent {
11
+ type: "message";
12
+ content?: string;
13
+ }
14
+ export interface DoneStreamEvent {
15
+ type: "done";
16
+ message_id?: string;
17
+ }
18
+ export interface TransferStreamEvent {
19
+ type: "transfer";
20
+ transfer?: TransferEvent;
21
+ }
22
+ export interface ToolCallEvent {
23
+ type: "tool_call";
24
+ call_id: string;
25
+ name: string;
26
+ arguments?: unknown;
27
+ raw_arguments?: string;
28
+ }
29
+ export interface ToolResultAckEvent {
30
+ type: "tool_result_ack";
31
+ ack?: Record<string, any>;
32
+ }
33
+ export interface UnknownStreamEvent {
34
+ type: string;
35
+ [key: string]: any;
36
+ }
37
+ export type StreamEvent = MessageStreamEvent | DoneStreamEvent | TransferStreamEvent | ToolCallEvent | ToolResultAckEvent | UnknownStreamEvent;
14
38
  export interface StreamCallbacks {
15
39
  onMessage?: (content: string) => void;
16
40
  onDone?: (messageId: string) => void;
17
41
  onError?: (error: Error) => void;
18
42
  onTransfer?: (transfer: TransferEvent) => void;
43
+ onToolCall?: (toolCall: ToolCallEvent) => void;
44
+ onToolResultAck?: (ack: Record<string, any>) => void;
19
45
  }
20
46
  export interface SendMessageResponse {
21
47
  status: string;
@@ -23,8 +49,121 @@ export interface SendMessageResponse {
23
49
  message_id?: string;
24
50
  transfers?: TransferEvent[];
25
51
  }
52
+ export type LocalFunctionSchema = Record<string, any>;
53
+ export interface LocalFunctionContext {
54
+ agentId?: string;
55
+ conversationId: string;
56
+ callId: string;
57
+ client: AgentClient;
58
+ }
59
+ export interface LocalFunctionDefinition {
60
+ name: string;
61
+ description: string;
62
+ parameters?: LocalFunctionSchema;
63
+ headers?: Record<string, string> | null;
64
+ execute: (args: unknown, context: LocalFunctionContext) => unknown | Promise<unknown>;
65
+ }
66
+ export interface AgentFacadeOptions {
67
+ name: string;
68
+ description?: string | null;
69
+ instructions?: string | null;
70
+ functions?: Array<LocalFunctionDefinition>;
71
+ workspaceId?: string | null;
72
+ credentialId?: string | null;
73
+ folderId?: string | null;
74
+ handoffs?: Array<Handoff>;
75
+ mcpServers?: Array<MCPServerReference>;
76
+ outputSchema?: Record<string, any> | null;
77
+ modelProvider?: ModelProvider | (string & {}) | null;
78
+ modelName?: ModelName | (string & {}) | null;
79
+ baseUrl?: string | null;
80
+ nodeCredentialId?: string | null;
81
+ maxTokens?: number | null;
82
+ reasoningEffort?: string | null;
83
+ }
84
+ export interface InlineMessage {
85
+ role: "user" | "assistant" | "system" | "tool";
86
+ content: string;
87
+ name?: string;
88
+ tool_call_id?: string;
89
+ }
90
+ export interface InlineRunOptions {
91
+ history?: Array<InlineMessage>;
92
+ metadata?: Record<string, any> | null;
93
+ signal?: AbortSignal;
94
+ /**
95
+ * SSE streaming callbacks. Fire as the model emits content. The returned
96
+ * promise still resolves with the final `InlineRunResult` after the stream
97
+ * (and any callback-tool round-trips) complete.
98
+ */
99
+ callbacks?: SendWithToolsCallbacks;
100
+ }
101
+ export interface InlineRunResult {
102
+ message: string;
103
+ message_id?: string;
104
+ tool_results?: Array<ToolExecutionResult>;
105
+ transfers?: Array<TransferEvent>;
106
+ token_usage?: {
107
+ input_tokens?: number;
108
+ output_tokens?: number;
109
+ total_tokens?: number;
110
+ };
111
+ }
112
+ export interface InlineAgentDefinition extends AgentFacadeOptions {
113
+ /** Inline credential override; transient — never persisted server-side. */
114
+ apiKey?: string | null;
115
+ /** Cap on callback-tool round-trips per `run` call. Default: 10. */
116
+ maxToolIterations?: number;
117
+ }
118
+ export interface EphemeralConversationOptions {
119
+ title?: string | null;
120
+ ttlSeconds?: number;
121
+ }
122
+ export interface EphemeralConversationHandle {
123
+ conversation_id: string;
124
+ agent_id: string;
125
+ expires_at: string;
126
+ send(input: string, callbacks?: SendWithToolsCallbacks): Promise<SendWithToolsResponse>;
127
+ close(): Promise<void>;
128
+ }
129
+ export interface InlineAgentHandle {
130
+ /** Frozen wire payload — useful for debugging or audit. */
131
+ definition: AgentRequest;
132
+ run(input: string, opts?: InlineRunOptions): Promise<InlineRunResult>;
133
+ /**
134
+ * SSE streaming variant. Yields raw `StreamEvent`s as they arrive (one
135
+ * `message` event per accumulated delta, plus `tool_call`, `transfer`,
136
+ * `done`). Tool-callback round-trips are handled internally — the
137
+ * iterator continues across them transparently.
138
+ */
139
+ runStream(input: string, opts?: InlineRunOptions): AsyncIterable<StreamEvent>;
140
+ startConversation(opts?: EphemeralConversationOptions): Promise<EphemeralConversationHandle>;
141
+ }
142
+ export interface ToolExecutionResult {
143
+ call_id: string;
144
+ name: string;
145
+ result?: unknown;
146
+ error?: string;
147
+ is_error: boolean;
148
+ }
149
+ export interface SendWithToolsCallbacks extends StreamCallbacks {
150
+ onToolResult?: (result: ToolExecutionResult) => void;
151
+ }
152
+ export interface SendWithToolsOptions {
153
+ content: string;
154
+ agentId?: string;
155
+ conversationId?: string;
156
+ title?: string | null;
157
+ functions?: Array<LocalFunctionDefinition>;
158
+ useDraft?: boolean;
159
+ metadata?: Record<string, any> | null;
160
+ callbacks?: SendWithToolsCallbacks;
161
+ }
162
+ export interface SendWithToolsResponse extends SendMessageResponse {
163
+ conversation_id: string;
164
+ tool_results?: Array<ToolExecutionResult>;
165
+ }
26
166
  declare class ConversationsServiceStream extends ConversationsService {
27
- constructor();
28
167
  /**
29
168
  * Add Message with SSE streaming support
30
169
  * @param conversationId The ID of the conversation
@@ -91,13 +230,51 @@ export declare class AgentClient {
91
230
  OpenAPI: typeof OpenAPI;
92
231
  /**
93
232
  * Conversations stream service
94
- * @deprecated Use client.public.conversations.sendMessageWithStreaming instead
233
+ * @deprecated Use client.public.conversations.sendMessageWithStreaming instead
95
234
  */
96
235
  conversationsStream: typeof ConversationsServiceStream;
236
+ private localFunctionRegistry;
97
237
  constructor({ apiUrl, apiToken, }: {
98
238
  apiUrl: string;
99
- apiToken: string;
239
+ /**
240
+ * Platform auth token: a Keycloak JWT or a workspace API key (`ack_*`).
241
+ * Optional — omit it for anonymous inline-agent runs where you bring
242
+ * your own model-provider key via `defineAgent({ apiKey })`. Anonymous
243
+ * callers cannot use workspace-scoped features (credential refs, stored
244
+ * agents, workspace-agent tools).
245
+ */
246
+ apiToken?: string;
100
247
  });
248
+ defineFunction(definition: LocalFunctionDefinition): LocalFunctionDefinition;
249
+ createAgent(options: AgentFacadeOptions): Promise<CreateAgentResponse>;
250
+ updateAgent(agentId: string, options: AgentFacadeOptions): Promise<Record<string, any>>;
251
+ /**
252
+ * Define an agent in code and execute it without persisting the
253
+ * configuration server-side. Genkit-style usage:
254
+ *
255
+ * ```ts
256
+ * const agent = client.defineAgent({
257
+ * name: "weather",
258
+ * instructions: "...",
259
+ * modelProvider: "openai",
260
+ * modelName: "gpt-5-mini",
261
+ * apiKey: process.env.OPENAI_KEY,
262
+ * functions: [...],
263
+ * });
264
+ * const r = await agent.run("Weather in Bogota?");
265
+ * ```
266
+ *
267
+ * For multi-turn sessions where you don't want to replay history each
268
+ * call, use `agent.startConversation()`.
269
+ */
270
+ defineAgent(definition: InlineAgentDefinition): InlineAgentHandle;
271
+ /** Internal: register inline functions for an ephemeral agent id. */
272
+ private registerLocalFunctions;
273
+ /** Internal: drop inline functions when an ephemeral conversation closes. */
274
+ private unregisterLocalFunctions;
275
+ private streamConversationTurn;
276
+ private resolveConversationContext;
277
+ private executeToolCall;
101
278
  /**
102
279
  * sendMessageWithStreaming: Sent a message with streaming support to a conversation
103
280
  * Use client.public.conversations.sendMessageWithStreaming instead
@@ -110,5 +287,6 @@ export declare class AgentClient {
110
287
  * Use client.public.conversations.sendMessage instead
111
288
  */
112
289
  sendMessage(conversationId: string, requestBody: MessageCreate): Promise<SendMessageResponse>;
290
+ sendWithTools(options: SendWithToolsOptions): Promise<SendWithToolsResponse>;
113
291
  }
114
292
  export default AgentClient;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@ideascol/agents-generator-sdk",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "bun test",
7
7
  "build": "tsc --emitDeclarationOnly && bun build ./src/index.ts ./src/bin/cli.ts --target=node --outdir ./dist --format cjs",
8
8
  "build:test": "bun build ./src/tests/*.ts --target=node --outdir dist/tests --format cjs",
9
+ "generate:models": "bun run scripts/generate-models.ts",
9
10
  "prepublishOnly": "bun run build",
10
11
  "start": "bun run src/cli.ts"
11
12
  },