@dnotifier-realtime/dnotifier 1.1.23 → 1.1.26
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/LICENSE +9 -0
- package/README.md +138 -41
- package/dist/agent-runtime/backendClient.d.ts +48 -0
- package/dist/agent-runtime/backendClient.d.ts.map +1 -0
- package/dist/agent-runtime/backendClient.js +1 -0
- package/dist/agent-runtime/descriptors.d.ts +15 -0
- package/dist/agent-runtime/descriptors.d.ts.map +1 -0
- package/dist/agent-runtime/descriptors.js +1 -0
- package/dist/agent-runtime/errors.d.ts +43 -0
- package/dist/agent-runtime/errors.d.ts.map +1 -0
- package/dist/agent-runtime/errors.js +1 -0
- package/dist/agent-runtime/ids.d.ts +6 -0
- package/dist/agent-runtime/ids.d.ts.map +1 -0
- package/dist/agent-runtime/ids.js +1 -0
- package/dist/agent-runtime/index.d.ts +23 -0
- package/dist/agent-runtime/index.d.ts.map +1 -0
- package/dist/agent-runtime/index.js +1 -0
- package/dist/agent-runtime/localCompletions.d.ts +32 -0
- package/dist/agent-runtime/localCompletions.d.ts.map +1 -0
- package/dist/agent-runtime/localCompletions.js +1 -0
- package/dist/agent-runtime/mcp/client.d.ts +30 -0
- package/dist/agent-runtime/mcp/client.d.ts.map +1 -0
- package/dist/agent-runtime/mcp/client.js +1 -0
- package/dist/agent-runtime/mcp/registry.d.ts +47 -0
- package/dist/agent-runtime/mcp/registry.d.ts.map +1 -0
- package/dist/agent-runtime/mcp/registry.js +1 -0
- package/dist/agent-runtime/observability.d.ts +10 -0
- package/dist/agent-runtime/observability.d.ts.map +1 -0
- package/dist/agent-runtime/observability.js +1 -0
- package/dist/agent-runtime/permissions.d.ts +10 -0
- package/dist/agent-runtime/permissions.d.ts.map +1 -0
- package/dist/agent-runtime/permissions.js +1 -0
- package/dist/agent-runtime/runtime.d.ts +35 -0
- package/dist/agent-runtime/runtime.d.ts.map +1 -0
- package/dist/agent-runtime/runtime.js +1 -0
- package/dist/agent-runtime/schema.d.ts +7 -0
- package/dist/agent-runtime/schema.d.ts.map +1 -0
- package/dist/agent-runtime/schema.js +1 -0
- package/dist/agent-runtime/toolRegistry.d.ts +36 -0
- package/dist/agent-runtime/toolRegistry.d.ts.map +1 -0
- package/dist/agent-runtime/toolRegistry.js +1 -0
- package/dist/cjs/dnotifier.js +1 -1
- package/dist/cjs/providers/openai.js +1 -1
- package/dist/cjs/transport/httpTransport.js +1 -1
- package/dist/cjs/transport/websocketTransport.js +1 -1
- package/dist/cjs/utils/buffer.js +1 -1
- package/dist/cjs/utils/frame.js +1 -1
- package/dist/cjs/utils/id.js +1 -1
- package/dist/cjs/utils/payload.js +1 -1
- package/dist/config/endpoints.d.ts +8 -0
- package/dist/config/endpoints.d.ts.map +1 -1
- package/dist/config/endpoints.js +1 -1
- package/dist/dnotifier.cjs +9355 -926
- package/dist/dnotifier.d.ts +52 -2
- package/dist/dnotifier.d.ts.map +1 -1
- package/dist/dnotifier.js +1 -1
- package/dist/providers/openai.js +1 -1
- package/dist/transport/httpTransport.js +1 -1
- package/dist/transport/websocketTransport.js +1 -1
- package/dist/utils/buffer.js +1 -1
- package/dist/utils/frame.js +1 -1
- package/dist/utils/id.js +1 -1
- package/dist/utils/logs.js +1 -1
- package/dist/utils/payload.js +1 -1
- package/dist/workflow/agent.d.ts +15 -9
- package/dist/workflow/agent.d.ts.map +1 -1
- package/dist/workflow/agent.js +1 -1
- package/dist/workflow/context.d.ts +2 -0
- package/dist/workflow/context.d.ts.map +1 -1
- package/dist/workflow/context.js +1 -1
- package/dist/workflow/errors.js +1 -1
- package/dist/workflow/graphParents.js +1 -1
- package/dist/workflow/ids.js +1 -1
- package/dist/workflow/jsonPayload.js +1 -1
- package/dist/workflow/mockObservabilityClient.js +1 -1
- package/dist/workflow/observability.d.ts +2 -1
- package/dist/workflow/observability.d.ts.map +1 -1
- package/dist/workflow/observability.js +1 -1
- package/dist/workflow/remoteAgentClient.js +1 -1
- package/dist/workflow/remoteAgentProtocol.js +1 -1
- package/dist/workflow/runner.d.ts.map +1 -1
- package/dist/workflow/runner.js +1 -1
- package/dist/workflow/stepTypes.d.ts +2 -0
- package/dist/workflow/stepTypes.d.ts.map +1 -1
- package/dist/workflow/stepTypes.js +1 -1
- package/dist/workflow/workflow.js +1 -1
- package/dist/workflow/workflowObservabilityClient.js +1 -1
- package/package.json +15 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright (c) DNotifier. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the
|
|
4
|
+
property of DNotifier. Unauthorized copying, modification, distribution, or
|
|
5
|
+
use of the Software, in whole or in part, is strictly prohibited without
|
|
6
|
+
express written permission from DNotifier.
|
|
7
|
+
|
|
8
|
+
For licensing inquiries, contact DNotifier.
|
|
9
|
+
Website: https://dnotifier.com
|
package/README.md
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
# DNotifier JavaScript SDK
|
|
2
2
|
|
|
3
|
-
**DNotifier** is
|
|
3
|
+
**DNotifier** is the developer platform for **AI agents**, **multi-agent orchestration**, **AI workflows**, **observability**, and realtime communication. This package is the official JavaScript / TypeScript SDK for **Node.js** and **browsers**.
|
|
4
|
+
|
|
5
|
+
Use it to send prompts, run RAG over a knowledge base, define agents and workflows, and trace runs in the dashboard. AI, RAG, and workflow calls use **HTTP** and return from the method. Directed 1:1 messaging is available on the same client when you need it.
|
|
6
|
+
|
|
7
|
+
**Documentation:** [dnotifier.gitbook.io/product-docs](https://dnotifier.gitbook.io/product-docs)
|
|
8
|
+
|
|
9
|
+
| Guide | What it covers |
|
|
10
|
+
|-------|----------------|
|
|
11
|
+
| [AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview) | Prompts, providers, sessions, RAG, semantic search |
|
|
12
|
+
| [Workflows & agents](https://dnotifier.gitbook.io/product-docs/workflows/overview) | Multi-step pipelines, tools, and MCP |
|
|
13
|
+
| [Observability](https://dnotifier.gitbook.io/product-docs/observability) | `logs`, `saveHistory`, and workflow telemetry |
|
|
14
|
+
| [Install — JavaScript / TypeScript](https://dnotifier.gitbook.io/product-docs/getting-started/installation/javascript-typescript) | npm install, ESM, CommonJS, and Node WebSocket |
|
|
4
15
|
|
|
5
16
|
---
|
|
6
17
|
|
|
7
18
|
## Features
|
|
8
19
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- AI
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
- Workflows: named agents, sequential pipelines, dashboard observability
|
|
18
|
-
- Plan limits from auth (`getPlanLimits`)
|
|
20
|
+
- AI prompts and chat-style messages (`sendAI`), including provider and model selection
|
|
21
|
+
- Sessions, AI history, and dashboard session logging (`logs: true`)
|
|
22
|
+
- Knowledge base (RAG): add, update, get, list, delete, and semantic `search`
|
|
23
|
+
- Workflows: named agents, multi-step pipelines, local tools, and MCP
|
|
24
|
+
- Dashboard observability for AI sessions and workflow runs
|
|
25
|
+
- HTTP transport for AI, RAG, and workflows
|
|
26
|
+
- Plan limits from auth (`getPlanLimits`, `aiEnabled`)
|
|
27
|
+
- Directed 1:1 messaging over WebSocket when you need live delivery
|
|
19
28
|
|
|
20
29
|
---
|
|
21
30
|
|
|
@@ -29,47 +38,35 @@ npm install @dnotifier-realtime/dnotifier
|
|
|
29
38
|
|
|
30
39
|
## Quick start
|
|
31
40
|
|
|
41
|
+
AI calls use **`transport: "http"`**. The response comes back from `sendAI`. It does not arrive on `onMessage`.
|
|
42
|
+
|
|
32
43
|
```js
|
|
33
44
|
import { DNotifier } from "@dnotifier-realtime/dnotifier";
|
|
34
45
|
|
|
35
46
|
const notifier = new DNotifier({
|
|
36
47
|
appId: "your-app-id",
|
|
37
48
|
secret: "your-app-secret",
|
|
38
|
-
transport: "
|
|
49
|
+
transport: "http",
|
|
39
50
|
userId: "user-123",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
onDisconnected: () => console.log("Disconnected"),
|
|
51
|
+
logs: true,
|
|
52
|
+
onConnected: () => {},
|
|
53
|
+
onMessage: () => {},
|
|
54
|
+
onDisconnected: () => {},
|
|
46
55
|
});
|
|
47
56
|
|
|
48
57
|
await notifier.connect();
|
|
49
58
|
|
|
50
|
-
notifier.
|
|
59
|
+
if (!notifier.aiEnabled) {
|
|
60
|
+
throw new Error("AI is not enabled for this plan");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const response = await notifier.sendAI({
|
|
51
64
|
senderId: "user-123",
|
|
52
|
-
|
|
53
|
-
data: { type: "text", text: "Hello from DNotifier" },
|
|
65
|
+
message: { text: "Summarize our refund policy in two sentences." },
|
|
54
66
|
});
|
|
55
67
|
```
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
import WebSocket from "ws";
|
|
61
|
-
|
|
62
|
-
const notifier = new DNotifier({
|
|
63
|
-
appId: "your-app-id",
|
|
64
|
-
secret: "your-app-secret",
|
|
65
|
-
transport: "ws",
|
|
66
|
-
userId: "user-123",
|
|
67
|
-
WebSocketImpl: WebSocket,
|
|
68
|
-
onConnected: () => {},
|
|
69
|
-
onMessage: () => {},
|
|
70
|
-
onDisconnected: () => {},
|
|
71
|
-
});
|
|
72
|
-
```
|
|
69
|
+
Continue in the docs: [Send a prompt](https://dnotifier.gitbook.io/product-docs/ai/send-prompt) · [Build an AI assistant](https://dnotifier.gitbook.io/product-docs/ai/example-ai-assistant) · [RAG Q&A bot](https://dnotifier.gitbook.io/product-docs/ai/example-rag-bot)
|
|
73
70
|
|
|
74
71
|
---
|
|
75
72
|
|
|
@@ -79,7 +76,7 @@ const notifier = new DNotifier({
|
|
|
79
76
|
|--------|------|-------------|
|
|
80
77
|
| `appId` | `string` | Your DNotifier application id |
|
|
81
78
|
| `secret` | `string` | Application secret |
|
|
82
|
-
| `transport` | `"ws"` \| `"http"` | `"
|
|
79
|
+
| `transport` | `"ws"` \| `"http"` | `"http"` for AI, RAG, and workflows; `"ws"` for directed 1:1 messaging |
|
|
83
80
|
| `userId` | `string` | End-user or agent id for auth and routing |
|
|
84
81
|
| `logs` | `boolean` | When `true`, tracks AI sessions in the DNotifier logs dashboard |
|
|
85
82
|
| `url` | `string` | Optional custom WebSocket URL |
|
|
@@ -108,6 +105,27 @@ After `connect()`, these properties are available:
|
|
|
108
105
|
|
|
109
106
|
## Real-time messaging
|
|
110
107
|
|
|
108
|
+
Directed 1:1 delivery over WebSocket. Messages go from a `senderId` to a `receiverId` (or a list of `receiverIds`). There are no broadcast topics.
|
|
109
|
+
|
|
110
|
+
Full guide: [Realtime communication](https://dnotifier.gitbook.io/product-docs/realtime-communication/overview).
|
|
111
|
+
|
|
112
|
+
In **Node.js**, pass a `WebSocket` implementation when `transport` is `"ws"`:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import WebSocket from "ws";
|
|
116
|
+
|
|
117
|
+
const notifier = new DNotifier({
|
|
118
|
+
appId: "your-app-id",
|
|
119
|
+
secret: "your-app-secret",
|
|
120
|
+
transport: "ws",
|
|
121
|
+
userId: "user-123",
|
|
122
|
+
WebSocketImpl: WebSocket,
|
|
123
|
+
onConnected: () => {},
|
|
124
|
+
onMessage: () => {},
|
|
125
|
+
onDisconnected: () => {},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
111
129
|
### Text and structured messages
|
|
112
130
|
|
|
113
131
|
Use any `type` in `data` that fits your app (`text`, `image`, `audio`, `doc`, etc.):
|
|
@@ -181,7 +199,9 @@ notifier.sendBinary({
|
|
|
181
199
|
|
|
182
200
|
## AI
|
|
183
201
|
|
|
184
|
-
Requires `aiEnabled` on your plan. Use `transport: "http"`
|
|
202
|
+
Requires `aiEnabled` on your plan. Use `transport: "http"` so `sendAI` returns the response directly.
|
|
203
|
+
|
|
204
|
+
Full guide: [AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview).
|
|
185
205
|
|
|
186
206
|
### Simple prompt
|
|
187
207
|
|
|
@@ -240,6 +260,10 @@ await notifier.deleteAIHistoryMessage({
|
|
|
240
260
|
|
|
241
261
|
## Knowledge base (RAG)
|
|
242
262
|
|
|
263
|
+
Index content, then answer from it with `search` or `sendAI({ message: { useKnowledgeBase: true } })`.
|
|
264
|
+
|
|
265
|
+
Full guide: [Knowledge base (RAG)](https://dnotifier.gitbook.io/product-docs/ai/knowledge-base-overview).
|
|
266
|
+
|
|
243
267
|
```js
|
|
244
268
|
// Add
|
|
245
269
|
await notifier.addDocument({
|
|
@@ -332,6 +356,8 @@ When `logs: true`, `sendAI` reports session start, completion, and token usage t
|
|
|
332
356
|
|
|
333
357
|
Build deterministic, multi-step AI pipelines with **named agents**, shared **workflow state**, and optional **observability** (execution and step telemetry in the DNotifier workflow dashboard).
|
|
334
358
|
|
|
359
|
+
Full guide: [Workflows overview](https://dnotifier.gitbook.io/product-docs/workflows/overview) · [Tools & MCP](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/tools-and-mcp).
|
|
360
|
+
|
|
335
361
|
### 1. Define agents
|
|
336
362
|
|
|
337
363
|
```js
|
|
@@ -454,6 +480,64 @@ const workflow = new DNotifier.Workflow({
|
|
|
454
480
|
});
|
|
455
481
|
```
|
|
456
482
|
|
|
483
|
+
### Agent tools and MCP
|
|
484
|
+
|
|
485
|
+
Register local tools and MCP servers on the connected client. Attach them to `DNotifier.defineAgent` — there is no separate `agents.create`.
|
|
486
|
+
|
|
487
|
+
```js
|
|
488
|
+
const getOrderStatus = notifier.tools.register({
|
|
489
|
+
name: "get_order_status",
|
|
490
|
+
description: "Get the current status of an order",
|
|
491
|
+
inputSchema: {
|
|
492
|
+
type: "object",
|
|
493
|
+
properties: { orderId: { type: "string" } },
|
|
494
|
+
required: ["orderId"],
|
|
495
|
+
},
|
|
496
|
+
execute: async ({ orderId }, context) => {
|
|
497
|
+
return { status: "shipped", orderId };
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const github = await notifier.mcp.connect({
|
|
502
|
+
id: "github",
|
|
503
|
+
name: "GitHub",
|
|
504
|
+
transport: "http",
|
|
505
|
+
endpoint: process.env.GITHUB_MCP_URL,
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const supportAgent = DNotifier.defineAgent({
|
|
509
|
+
name: "customer-support",
|
|
510
|
+
description: "Handles customer support requests",
|
|
511
|
+
tools: [getOrderStatus, ...github.tools()],
|
|
512
|
+
permissions: {
|
|
513
|
+
get_order_status: ["execute"],
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
Use the same agent in a workflow or on its own. The SDK owns the tool-call loop.
|
|
519
|
+
|
|
520
|
+
```js
|
|
521
|
+
// Workflow
|
|
522
|
+
const workflow = new DNotifier.Workflow({
|
|
523
|
+
name: "support-pipeline",
|
|
524
|
+
entry: async (ctx) =>
|
|
525
|
+
ctx.runAgent("customer-support", {
|
|
526
|
+
input: "What is the status of order ORD-123?",
|
|
527
|
+
}),
|
|
528
|
+
}).registerAgents({ "customer-support": supportAgent });
|
|
529
|
+
|
|
530
|
+
await notifier.runWorkflow({ workflow, input: {} });
|
|
531
|
+
|
|
532
|
+
// Standalone
|
|
533
|
+
const { output, executionId } = await notifier.runAgent(supportAgent, {
|
|
534
|
+
input: "What is the status of order ORD-123?",
|
|
535
|
+
userId: "user_123",
|
|
536
|
+
});
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
Agents without `tools` keep today's one-shot `ctx.sendAI`. Agents with `tools` and a custom `run(ctx)` still use that function as the workflow body; each `ctx.sendAI` inside it runs the tool loop.
|
|
540
|
+
|
|
457
541
|
### `WorkflowContext` (inside `entry` and agent `run`)
|
|
458
542
|
|
|
459
543
|
| Member / method | Description |
|
|
@@ -499,13 +583,16 @@ When `observability: true` on the workflow, SDK calls and `recordStep` are sent
|
|
|
499
583
|
| `listDocuments({ senderId, limit?, offset?, type? })` | List documents |
|
|
500
584
|
| `deleteDocument({ senderId, recordId })` | Delete a document |
|
|
501
585
|
| `runWorkflow({ workflow, input, senderId? })` | Run a workflow after `connect()` |
|
|
586
|
+
| `runAgent(agent, { input?, userId?, sessionId? })` | Run a `defineAgent` result outside a workflow |
|
|
587
|
+
| `tools.register(...)` / `tools.get` / `tools.list` | Local tool registry |
|
|
588
|
+
| `mcp.connect(...)` / `mcp.get` / `mcp.list` | MCP HTTP connections and discovery |
|
|
502
589
|
| `sendWithOpenAI(...)` | **Deprecated** — use `sendAI` |
|
|
503
590
|
|
|
504
591
|
### Workflow exports
|
|
505
592
|
|
|
506
593
|
| Export | Description |
|
|
507
594
|
|--------|-------------|
|
|
508
|
-
| `DNotifier.defineAgent({ name, run })` | Create a named agent |
|
|
595
|
+
| `DNotifier.defineAgent({ name, run?, tools?, permissions? })` | Create a named agent (optional tools) |
|
|
509
596
|
| `DNotifier.Workflow` | Workflow definition class |
|
|
510
597
|
| `DNotifier.WorkflowContext` | Context type passed to `entry` and agent `run` |
|
|
511
598
|
| `DNotifier.WorkflowError` | Workflow validation and runtime errors |
|
|
@@ -540,7 +627,17 @@ When `observability: true` on the workflow, SDK calls and `recordStep` are sent
|
|
|
540
627
|
|
|
541
628
|
---
|
|
542
629
|
|
|
630
|
+
## License
|
|
631
|
+
|
|
632
|
+
Proprietary — see [LICENSE](LICENSE). This SDK is not open source.
|
|
633
|
+
|
|
634
|
+
---
|
|
635
|
+
|
|
543
636
|
## Links
|
|
544
637
|
|
|
638
|
+
- **Documentation (GitBook):** [dnotifier.gitbook.io/product-docs](https://dnotifier.gitbook.io/product-docs)
|
|
639
|
+
- **AI:** [AI overview](https://dnotifier.gitbook.io/product-docs/ai/overview)
|
|
640
|
+
- **Workflows:** [Workflows overview](https://dnotifier.gitbook.io/product-docs/workflows/overview)
|
|
641
|
+
- **JavaScript install:** [Install — JavaScript / TypeScript](https://dnotifier.gitbook.io/product-docs/getting-started/installation/javascript-typescript)
|
|
545
642
|
- **Product:** [dnotifier.com](https://www.dnotifier.com)
|
|
546
|
-
- **
|
|
643
|
+
- **Dashboard:** [app.dnotifier.com](https://app.dnotifier.com)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export class AgentBackendClient {
|
|
2
|
+
constructor({ token, requestTimeoutMs }?: {
|
|
3
|
+
token?: string | null;
|
|
4
|
+
requestTimeoutMs?: number;
|
|
5
|
+
});
|
|
6
|
+
token: string | null;
|
|
7
|
+
requestTimeoutMs: number;
|
|
8
|
+
configure({ token }?: {
|
|
9
|
+
token?: string | null;
|
|
10
|
+
}): void;
|
|
11
|
+
post(url: string, body: object): Promise<any>;
|
|
12
|
+
postQuiet(url: any, body: any): Promise<void>;
|
|
13
|
+
registerTool(tool: object): Promise<void>;
|
|
14
|
+
registerMcpServer(server: {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
transport: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
registerMcpServerTools(serverId: string, tools: object[]): Promise<void>;
|
|
20
|
+
registerAgent(agent: import("../workflow/agent.js").Agent): Promise<void>;
|
|
21
|
+
checkPermission(body: object): Promise<{
|
|
22
|
+
decision?: string;
|
|
23
|
+
reason?: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export class AgentSync {
|
|
27
|
+
constructor({ backend }: {
|
|
28
|
+
backend: AgentBackendClient;
|
|
29
|
+
});
|
|
30
|
+
backend: AgentBackendClient;
|
|
31
|
+
_tools: Map<string, object>;
|
|
32
|
+
_servers: Map<string, {
|
|
33
|
+
server: object;
|
|
34
|
+
tools: object[];
|
|
35
|
+
}>;
|
|
36
|
+
_agents: Map<string, import("../workflow/agent.js").Agent>;
|
|
37
|
+
_chain: Promise<void>;
|
|
38
|
+
enqueueTool(tool: object): void;
|
|
39
|
+
enqueueServer(server: {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
transport: string;
|
|
43
|
+
}, tools: object[]): void;
|
|
44
|
+
enqueueAgent(agent: import("../workflow/agent.js").Agent): void;
|
|
45
|
+
flush(): Promise<void>;
|
|
46
|
+
_flushOnce(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=backendClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backendClient.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/backendClient.js"],"names":[],"mappings":"AA2BA;IAIE,0CAFW;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE,EAK9D;IAFC,qBAAkB;IAClB,yBAAwC;IAI1C,sBADY;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,QAGpC;IAGD,UADY,MAAM,QAAc,MAAM,gBAkBrC;IAGD,8CAOC;IAGD,mBADY,MAAM,iBAMjB;IAGD,0BADY;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,iBAQ1D;IAMD,iCAHW,MAAM,SACN,MAAM,EAAE,iBAOlB;IAGD,qBADY,OAAO,sBAAsB,EAAE,KAAK,iBAsB/C;IAMD,sBAHW,MAAM,GACJ,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAI3D;CACF;AAOD;IAEE,yBADY;QAAE,OAAO,EAAE,kBAAkB,CAAA;KAAE,EAU1C;IARC,4BAAsB;IAEtB,QADW,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CACP;IAEvB,UADW,GAAG,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAClC;IAEzB,SADW,GAAG,CAAC,MAAM,EAAE,OAAO,sBAAsB,EAAE,KAAK,CAAC,CACpC;IACxB,sBAA+B;IAIjC,kBADY,MAAM,QAIjB;IAMD,sBAHW;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,SAC/C,MAAM,EAAE,QAKlB;IAGD,oBADY,OAAO,sBAAsB,EAAE,KAAK,QAG/C;IAED,uBAUC;IAED,4BAkCC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{HttpTransport}from'../transport/httpTransport.js';import{DNotifierEndpoints}from'../config/endpoints.js';import{toPublicTool}from'./descriptors.js';import{agentBackendId}from'./ids.js';import{BackendError}from'./errors.js';const SDK_VERSION='1.1.23';function unwrap(_0x39754f){var _0x223154,_0x17a75d;if(_0x39754f&&'object'==typeof _0x39754f&&null!=_0x39754f['_responseCode']){if(0xc8!==Number(_0x39754f['_responseCode'])){const _0x3db1f3='string'==typeof _0x39754f['_responseData']?_0x39754f['_responseData']:JSON['stringify'](null!==(_0x223154=_0x39754f['_responseData'])&&void 0x0!==_0x223154?_0x223154:'');throw new Error(_0x3db1f3||'Backend\x20response\x20'+_0x39754f['_responseCode']);}return null!==(_0x17a75d=_0x39754f['_responseData'])&&void 0x0!==_0x17a75d?_0x17a75d:_0x39754f;}return _0x39754f;}export class AgentBackendClient{constructor({token:_0x5e2eaf=null,requestTimeoutMs:_0x38487e=0x7530}={}){this['token']=_0x5e2eaf,this['requestTimeoutMs']=_0x38487e;}['configure']({token:_0x172cf2}={}){void 0x0!==_0x172cf2&&(this['token']=_0x172cf2);}async['post'](_0x177598,_0x2c5514){var _0x30e4e3;if(!this['token'])throw new BackendError('Agent\x20backend\x20call\x20requires\x20a\x20connected\x20client');const _0x5a8661=new HttpTransport({'url':_0x177598,'headers':{'authorization':''+this['token']},'timeoutMs':this['requestTimeoutMs']});try{return unwrap(await _0x5a8661['send'](_0x2c5514));}catch(_0x55b301){if(_0x55b301 instanceof BackendError)throw _0x55b301;throw new BackendError(null!==(_0x30e4e3=null==_0x55b301?void 0x0:_0x55b301['message'])&&void 0x0!==_0x30e4e3?_0x30e4e3:'Backend\x20request\x20failed',{'cause':_0x55b301 instanceof Error?_0x55b301:void 0x0});}}async['postQuiet'](_0xa6f76f,_0x916c2a){if(this['token'])try{await this['post'](_0xa6f76f,_0x916c2a);}catch{}}async['registerTool'](_0x3b3de5){await this['post'](DNotifierEndpoints['agentToolRegisterUrl'],{...toPublicTool(_0x3b3de5),'sdkVersion':'1.1.23'});}async['registerMcpServer'](_0x27a095){await this['post'](DNotifierEndpoints['agentMcpServerRegisterUrl'],{'id':_0x27a095['id'],'name':_0x27a095['name'],'transport':_0x27a095['transport'],'sdkVersion':'1.1.23'});}async['registerMcpServerTools'](_0x3a4672,_0x18483f){await this['post'](DNotifierEndpoints['agentMcpServerToolsUrl'](_0x3a4672),{'tools':_0x18483f['map'](toPublicTool),'sdkVersion':'1.1.23'});}async['registerAgent'](_0x4d974a){var _0x395946,_0x24ffc0,_0x2ae465,_0x50799a;const _0x5851d5=agentBackendId(_0x4d974a['name']),_0x23210c=null!==(_0x395946=_0x4d974a['tools'])&&void 0x0!==_0x395946?_0x395946:[],_0x5d1d03=[...new Set(_0x23210c['map'](_0x27e9fe=>_0x27e9fe['mcpServerId'])['filter'](Boolean))];await this['post'](DNotifierEndpoints['agentRegisterUrl'],{'id':_0x5851d5,'name':_0x4d974a['name'],'description':null!==(_0x24ffc0=_0x4d974a['description'])&&void 0x0!==_0x24ffc0?_0x24ffc0:'','toolIds':_0x23210c['map'](_0x58fdf2=>_0x58fdf2['id']),'mcpServerIds':_0x5d1d03,'permissions':null!==(_0x2ae465=_0x4d974a['permissions'])&&void 0x0!==_0x2ae465?_0x2ae465:{},'sdkVersion':'1.1.23'}),await this['post'](DNotifierEndpoints['agentToolsUrl'](_0x5851d5),{'toolIds':_0x23210c['map'](_0x33a7c6=>_0x33a7c6['id'])}),await this['post'](DNotifierEndpoints['agentPermissionsUrl'](_0x5851d5),{'permissions':null!==(_0x50799a=_0x4d974a['permissions'])&&void 0x0!==_0x50799a?_0x50799a:{}});}async['checkPermission'](_0x4279ca){return this['post'](DNotifierEndpoints['agentPermissionCheckUrl'],_0x4279ca);}}export class AgentSync{constructor({backend:_0x22c27d}){this['backend']=_0x22c27d,this['_tools']=new Map(),this['_servers']=new Map(),this['_agents']=new Map(),this['_chain']=Promise['resolve']();}['enqueueTool'](_0x3ae7ca){this['_tools']['set'](_0x3ae7ca['id'],_0x3ae7ca),this['backend']['token']&&this['flush']()['catch'](()=>{});}['enqueueServer'](_0x343b9b,_0x24f669){this['_servers']['set'](_0x343b9b['id'],{'server':_0x343b9b,'tools':_0x24f669}),this['backend']['token']&&this['flush']()['catch'](()=>{});}['enqueueAgent'](_0xd845be){this['_agents']['set'](agentBackendId(_0xd845be['name']),_0xd845be);}async['flush'](){const _0x2493eb=this['_chain']['then'](()=>this['_flushOnce'](),()=>this['_flushOnce']());return this['_chain']=_0x2493eb['then'](()=>{},()=>{}),_0x2493eb;}async['_flushOnce'](){if(!this['backend']['token'])return;let _0x4adc8b=0x0;for(const [_0x4b9c4e,_0x32aacf]of[...this['_tools']]){try{await this['backend']['registerTool'](_0x32aacf);}catch{_0x4adc8b+=0x1;}this['_tools']['delete'](_0x4b9c4e);}for(const [_0x523cce,_0x115c8b]of[...this['_servers']]){try{await this['backend']['registerMcpServer'](_0x115c8b['server']),await this['backend']['registerMcpServerTools'](_0x523cce,_0x115c8b['tools']);}catch{_0x4adc8b+=0x1;}this['_servers']['delete'](_0x523cce);}for(const [_0x37db7e,_0x3f40c7]of[...this['_agents']]){try{await this['backend']['registerAgent'](_0x3f40c7);}catch{_0x4adc8b+=0x1;}this['_agents']['delete'](_0x37db7e);}_0x4adc8b>0x0&&console['warn']('[dnotifier]\x20skipped\x20'+_0x4adc8b+'\x20agent-backend\x20register\x20call(s)\x20(routes\x20not\x20available\x20yet)');}}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function toPublicTool(tool: {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
inputSchema?: object;
|
|
6
|
+
provider: string;
|
|
7
|
+
mcpServerId?: string;
|
|
8
|
+
}): {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
inputSchema: object;
|
|
13
|
+
provider: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=descriptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptors.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/descriptors.js"],"names":[],"mappings":"AAWA,mCATW;IACN,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;;;;;;EAYH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function toPublicTool(_0x250038){var _0x2596c0,_0x508548;const _0x166806={'id':_0x250038['id'],'name':_0x250038['name'],'description':null!==(_0x2596c0=_0x250038['description'])&&void 0x0!==_0x2596c0?_0x2596c0:'','inputSchema':null!==(_0x508548=_0x250038['inputSchema'])&&void 0x0!==_0x508548?_0x508548:{'type':'object'},'provider':_0x250038['provider']};return _0x250038['mcpServerId']&&(_0x166806['mcpServerId']=_0x250038['mcpServerId']),_0x166806;}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class DNotifierAgentError extends Error {
|
|
2
|
+
constructor(message: string, fields?: {
|
|
3
|
+
executionId?: string | null;
|
|
4
|
+
agentId?: string | null;
|
|
5
|
+
toolId?: string | null;
|
|
6
|
+
provider?: string | null;
|
|
7
|
+
cause?: Error;
|
|
8
|
+
});
|
|
9
|
+
executionId: string | null;
|
|
10
|
+
agentId: string | null;
|
|
11
|
+
toolId: string | null;
|
|
12
|
+
provider: string | null;
|
|
13
|
+
cause: Error | undefined;
|
|
14
|
+
}
|
|
15
|
+
export class ToolNotFoundError extends DNotifierAgentError {
|
|
16
|
+
constructor(message: string, fields?: object);
|
|
17
|
+
}
|
|
18
|
+
export class ToolValidationError extends DNotifierAgentError {
|
|
19
|
+
constructor(message: string, fields?: object, issues?: string[]);
|
|
20
|
+
issues: string[];
|
|
21
|
+
}
|
|
22
|
+
export class ToolExecutionError extends DNotifierAgentError {
|
|
23
|
+
constructor(message: string, fields?: object);
|
|
24
|
+
}
|
|
25
|
+
export class PermissionDeniedError extends DNotifierAgentError {
|
|
26
|
+
constructor(message: string, fields?: object);
|
|
27
|
+
}
|
|
28
|
+
export class MCPConnectionError extends DNotifierAgentError {
|
|
29
|
+
constructor(message: string, fields?: object);
|
|
30
|
+
}
|
|
31
|
+
export class MCPToolError extends DNotifierAgentError {
|
|
32
|
+
constructor(message: string, fields?: object);
|
|
33
|
+
}
|
|
34
|
+
export class AgentExecutionError extends DNotifierAgentError {
|
|
35
|
+
constructor(message: string, fields?: object);
|
|
36
|
+
}
|
|
37
|
+
export class BackendError extends DNotifierAgentError {
|
|
38
|
+
constructor(message: string, fields?: object);
|
|
39
|
+
}
|
|
40
|
+
export class LLMError extends DNotifierAgentError {
|
|
41
|
+
constructor(message: string, fields?: object);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/errors.js"],"names":[],"mappings":"AAAA;IAWE,qBATW,MAAM,WACN;QACN,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,EAUH;IALC,2BAA6C;IAC7C,uBAAqC;IACrC,sBAAmC;IACnC,wBAAuC;IACrB,yBAAyB;CAE9C;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAME,qBAJW,MAAM,WACN,MAAM,WACN,MAAM,EAAE,EAMlB;IADC,iBAAoB;CAEvB;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF;AAED;IAEE,qBADY,MAAM,WAAkB,MAAM,EAIzC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class DNotifierAgentError extends Error{constructor(_0x2c1f3d,_0x5a3225={}){var _0x1b331c,_0x24e4ca,_0x14a7b6,_0x137480;super(_0x2c1f3d),this['name']='DNotifierAgentError',this['executionId']=null!==(_0x1b331c=_0x5a3225['executionId'])&&void 0x0!==_0x1b331c?_0x1b331c:null,this['agentId']=null!==(_0x24e4ca=_0x5a3225['agentId'])&&void 0x0!==_0x24e4ca?_0x24e4ca:null,this['toolId']=null!==(_0x14a7b6=_0x5a3225['toolId'])&&void 0x0!==_0x14a7b6?_0x14a7b6:null,this['provider']=null!==(_0x137480=_0x5a3225['provider'])&&void 0x0!==_0x137480?_0x137480:null,_0x5a3225['cause']&&(this['cause']=_0x5a3225['cause']);}}export class ToolNotFoundError extends DNotifierAgentError{constructor(_0x56013c,_0x300ef2){super(_0x56013c,_0x300ef2),this['name']='ToolNotFoundError';}}export class ToolValidationError extends DNotifierAgentError{constructor(_0x2e7cc3,_0x23adab,_0x526d40=[]){super(_0x2e7cc3,_0x23adab),this['name']='ToolValidationError',this['issues']=_0x526d40;}}export class ToolExecutionError extends DNotifierAgentError{constructor(_0x110759,_0xc141b7){super(_0x110759,_0xc141b7),this['name']='ToolExecutionError';}}export class PermissionDeniedError extends DNotifierAgentError{constructor(_0x1d1eee,_0xc0816b){super(_0x1d1eee,_0xc0816b),this['name']='PermissionDeniedError';}}export class MCPConnectionError extends DNotifierAgentError{constructor(_0x2547c4,_0x394b55){super(_0x2547c4,_0x394b55),this['name']='MCPConnectionError';}}export class MCPToolError extends DNotifierAgentError{constructor(_0x25990d,_0x3ffe66){super(_0x25990d,_0x3ffe66),this['name']='MCPToolError';}}export class AgentExecutionError extends DNotifierAgentError{constructor(_0x539d12,_0x3e9c5a){super(_0x539d12,_0x3e9c5a),this['name']='AgentExecutionError';}}export class BackendError extends DNotifierAgentError{constructor(_0x61e7b7,_0x4bce35){super(_0x61e7b7,_0x4bce35),this['name']='BackendError';}}export class LLMError extends DNotifierAgentError{constructor(_0x4d5486,_0xa8cc9){super(_0x4d5486,_0xa8cc9),this['name']='LLMError';}}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function sanitizeIdPart(value: string): string;
|
|
2
|
+
export function localToolId(name: string): string;
|
|
3
|
+
export function mcpToolId(serverId: string, toolName: string): string;
|
|
4
|
+
export function mcpToolName(serverId: any, toolName: any): string;
|
|
5
|
+
export function agentBackendId(name: string): string;
|
|
6
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/ids.js"],"names":[],"mappings":"AACA,sCADY,MAAM,UAOjB;AAGD,kCADY,MAAM,UAKjB;AAMD,oCAHW,MAAM,YACN,MAAM,UAIhB;AAGD,kEAEC;AAGD,qCADY,MAAM,UAKjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function sanitizeIdPart(_0x5325ff){return String(_0x5325ff)['trim']()['toLowerCase']()['replace'](/[^a-z0-9]+/g,'_')['replace'](/^_+|_+$/g,'');}export function localToolId(_0x46c756){const _0x1ef743=sanitizeIdPart(_0x46c756);if(!_0x1ef743)throw new Error('Tool\x20name\x20is\x20required');return'tool_'+_0x1ef743;}export function mcpToolId(_0x654929,_0x1fc7f9){return'mcp_'+sanitizeIdPart(_0x654929)+'_'+sanitizeIdPart(_0x1fc7f9);}export function mcpToolName(_0x2177cf,_0x265e10){return _0x2177cf+'.'+_0x265e10;}export function agentBackendId(_0x5cde34){const _0x2c436=sanitizeIdPart(_0x5cde34);if(!_0x2c436)throw new Error('Agent\x20name\x20is\x20required');return'agent_'+_0x2c436;}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function createAgentServices(options?: {
|
|
2
|
+
permissionEnforcement?: "backend" | "disabled";
|
|
3
|
+
onAgentEvent?: ((event: object) => void) | null;
|
|
4
|
+
}): {
|
|
5
|
+
backend: AgentBackendClient;
|
|
6
|
+
sync: AgentSync;
|
|
7
|
+
events: AgentObservability;
|
|
8
|
+
tools: ToolRegistry;
|
|
9
|
+
mcp: McpRegistry;
|
|
10
|
+
permissionEnforcement: string;
|
|
11
|
+
configure(config: {
|
|
12
|
+
token?: string | null;
|
|
13
|
+
onAgentEvent?: ((event: object) => void) | null;
|
|
14
|
+
}): void;
|
|
15
|
+
};
|
|
16
|
+
export * from "./errors.js";
|
|
17
|
+
import { AgentBackendClient } from "./backendClient.js";
|
|
18
|
+
import { AgentSync } from "./backendClient.js";
|
|
19
|
+
import { AgentObservability } from "./observability.js";
|
|
20
|
+
import { ToolRegistry } from "./toolRegistry.js";
|
|
21
|
+
import { McpRegistry } from "./mcp/registry.js";
|
|
22
|
+
export { runAgentLoop, runToolAgent, workflowTraceFromContext } from "./runtime.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/index.js"],"names":[],"mappings":"AAkBA,8CALW;IACN,qBAAqB,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC/C,YAAY,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CACjD;;;;;;;sBAqBW;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,YAAY,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,CAAA;KAAE;EASxF;;mCA9C6C,oBAAoB;0BAApB,oBAAoB;mCAC/B,oBAAoB;6BAC1B,mBAAmB;4BACpB,mBAAmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AgentBackendClient,AgentSync}from'./backendClient.js';import{AgentObservability}from'./observability.js';import{ToolRegistry}from'./toolRegistry.js';import{McpRegistry}from'./mcp/registry.js';export{runAgentLoop,runToolAgent,workflowTraceFromContext}from'./runtime.js';export*from'./errors.js';export function createAgentServices(_0x2db55b={}){var _0x4300fc;const _0x54ffd6=new AgentBackendClient(),_0x1cd16d=new AgentSync({'backend':_0x54ffd6}),_0x2079e0=new AgentObservability({'backend':_0x54ffd6,'onAgentEvent':null!==(_0x4300fc=_0x2db55b['onAgentEvent'])&&void 0x0!==_0x4300fc?_0x4300fc:null}),_0x34b146=new ToolRegistry({'sync':_0x1cd16d}),_0x2cda28=new McpRegistry({'tools':_0x34b146,'sync':_0x1cd16d,'events':_0x2079e0});return{'backend':_0x54ffd6,'sync':_0x1cd16d,'events':_0x2079e0,'tools':_0x34b146,'mcp':_0x2cda28,'permissionEnforcement':'disabled'===_0x2db55b['permissionEnforcement']?'disabled':'backend','configure'(_0x309e43){_0x54ffd6['configure']({'token':_0x309e43['token']}),void 0x0!==_0x309e43['onAgentEvent']&&(_0x2079e0['onAgentEvent']=_0x309e43['onAgentEvent']);}};}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function parseNativeTurn(response: any): {
|
|
2
|
+
type: "message";
|
|
3
|
+
content: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: "tool_calls";
|
|
6
|
+
calls: object[];
|
|
7
|
+
};
|
|
8
|
+
export function toOpenAiToolName(name: unknown): string;
|
|
9
|
+
export function buildOpenAiToolNameMap(tools?: object[]): {
|
|
10
|
+
toSanitized: Map<string, string>;
|
|
11
|
+
toOriginal: Map<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export function toOpenAiTools(tools?: object[], toSanitized?: Map<string, string>): {
|
|
14
|
+
type: string;
|
|
15
|
+
function: {
|
|
16
|
+
name: string;
|
|
17
|
+
description: any;
|
|
18
|
+
parameters: any;
|
|
19
|
+
};
|
|
20
|
+
}[];
|
|
21
|
+
export function buildAgentChatMessages(history: object[], toSanitized?: Map<string, string> | null): object[];
|
|
22
|
+
export function describeChatMessageRoles(messages: object[]): string;
|
|
23
|
+
export function completeViaSendAI(notifier: import("../dnotifier.js").DNotifier, body: object): Promise<{
|
|
24
|
+
type: "message" | "tool_calls";
|
|
25
|
+
content?: string;
|
|
26
|
+
calls?: object[];
|
|
27
|
+
model: string | null;
|
|
28
|
+
provider: string | null;
|
|
29
|
+
tokensIn: number;
|
|
30
|
+
tokensOut: number;
|
|
31
|
+
}>;
|
|
32
|
+
//# sourceMappingURL=localCompletions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localCompletions.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/localCompletions.js"],"names":[],"mappings":"AAkGA,0CAHW,GAAG,GACD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CA4B1F;AAuCD,uCAHW,OAAO,GACL,MAAM,CAKlB;AAUD,+CANW,MAAM,EAAE,GACN;IACR,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAoBH;AAOD,sCAHW,MAAM,EAAE,gBACR,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;;IAa7B;AASD,gDAJW,MAAM,EAAE,gBACR,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GACxB,MAAM,EAAE,CAuGpB;AAMD,mDAFW,MAAM,EAAE,UAelB;AAgBD,4CAZW,OAAO,iBAAiB,EAAE,SAAS,QACnC,MAAM,GACJ,OAAO,CAAC;IAChB,IAAI,EAAE,SAAS,GAAG,YAAY,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAiGJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LLMError}from'./errors.js';function extractDataPayload(_0x49c596){return _0x49c596&&'object'==typeof _0x49c596?_0x49c596['data']&&'object'==typeof _0x49c596['data']&&!Array['isArray'](_0x49c596['data'])?_0x49c596['data']:_0x49c596:null;}function extractContent(_0x39c1f3){var _0x32f349,_0x5d90d2,_0x381099,_0x2fed44,_0x3dee68;if(null==_0x39c1f3)return'';if('string'==typeof _0x39c1f3)return _0x39c1f3;const _0x4e6ef5=extractDataPayload(_0x39c1f3),_0x16c5f8=[null==_0x4e6ef5?void 0x0:_0x4e6ef5['content'],null===(_0x32f349=null==_0x4e6ef5?void 0x0:_0x4e6ef5['message'])||void 0x0===_0x32f349?void 0x0:_0x32f349['content'],null==_0x4e6ef5?void 0x0:_0x4e6ef5['text'],null===(_0x2fed44=null===(_0x381099=null===(_0x5d90d2=null==_0x4e6ef5?void 0x0:_0x4e6ef5['choices'])||void 0x0===_0x5d90d2?void 0x0:_0x5d90d2[0x0])||void 0x0===_0x381099?void 0x0:_0x381099['message'])||void 0x0===_0x2fed44?void 0x0:_0x2fed44['content'],null==_0x39c1f3?void 0x0:_0x39c1f3['content'],null===(_0x3dee68=null==_0x39c1f3?void 0x0:_0x39c1f3['message'])||void 0x0===_0x3dee68?void 0x0:_0x3dee68['content'],null==_0x39c1f3?void 0x0:_0x39c1f3['text']];for(const _0x545e17 of _0x16c5f8)if('string'==typeof _0x545e17)return _0x545e17;try{return JSON['stringify'](_0x39c1f3);}catch{return String(_0x39c1f3);}}function extractAssistantMessage(_0x23851e){var _0xfa5bd8,_0x1ce35e,_0x95f75c,_0x3f566b;if(!_0x23851e||'object'!=typeof _0x23851e)return null;const _0xecf287=extractDataPayload(_0x23851e),_0x35d548=[_0xecf287,null===(_0x1ce35e=null===(_0xfa5bd8=null==_0xecf287?void 0x0:_0xecf287['choices'])||void 0x0===_0xfa5bd8?void 0x0:_0xfa5bd8[0x0])||void 0x0===_0x1ce35e?void 0x0:_0x1ce35e['message'],null==_0xecf287?void 0x0:_0xecf287['message'],null===(_0x3f566b=null===(_0x95f75c=null==_0x23851e?void 0x0:_0x23851e['choices'])||void 0x0===_0x95f75c?void 0x0:_0x95f75c[0x0])||void 0x0===_0x3f566b?void 0x0:_0x3f566b['message'],null==_0x23851e?void 0x0:_0x23851e['message'],_0x23851e];for(const _0x974f0e of _0x35d548)if(_0x974f0e&&'object'==typeof _0x974f0e&&!Array['isArray'](_0x974f0e)&&(Array['isArray'](_0x974f0e['tool_calls'])||Array['isArray'](_0x974f0e['toolCalls'])||'string'==typeof _0x974f0e['content']||null===_0x974f0e['content']))return _0x974f0e;return null;}function parseToolArguments(_0x5c03e9){if(null==_0x5c03e9||''===_0x5c03e9)return{};if('object'==typeof _0x5c03e9&&!Array['isArray'](_0x5c03e9))return _0x5c03e9;if('string'==typeof _0x5c03e9)try{const _0x9495d6=JSON['parse'](_0x5c03e9);return _0x9495d6&&'object'==typeof _0x9495d6&&!Array['isArray'](_0x9495d6)?_0x9495d6:{};}catch{return{};}return{};}export function parseNativeTurn(_0x3b3f5e){var _0x3a0fa6,_0x13d596;const _0x465625=extractAssistantMessage(_0x3b3f5e),_0x2f8d24=null!==(_0x13d596=null!==(_0x3a0fa6=null==_0x465625?void 0x0:_0x465625['tool_calls'])&&void 0x0!==_0x3a0fa6?_0x3a0fa6:null==_0x465625?void 0x0:_0x465625['toolCalls'])&&void 0x0!==_0x13d596?_0x13d596:null;return Array['isArray'](_0x2f8d24)&&_0x2f8d24['length']>0x0?{'type':'tool_calls','calls':_0x2f8d24['map']((_0xf47405,_0x14574c)=>{var _0x2727f6,_0x59d9dd,_0x310131;const _0x52a688=(null==_0xf47405?void 0x0:_0xf47405['function'])&&'object'==typeof _0xf47405['function']?_0xf47405['function']:null;return{'id':null!==(_0x2727f6=null==_0xf47405?void 0x0:_0xf47405['id'])&&void 0x0!==_0x2727f6?_0x2727f6:'call_'+(_0x14574c+0x1),'name':null!==(_0x59d9dd=null==_0x52a688?void 0x0:_0x52a688['name'])&&void 0x0!==_0x59d9dd?_0x59d9dd:null==_0xf47405?void 0x0:_0xf47405['name'],'arguments':parseToolArguments(null!==(_0x310131=null==_0x52a688?void 0x0:_0x52a688['arguments'])&&void 0x0!==_0x310131?_0x310131:null==_0xf47405?void 0x0:_0xf47405['arguments'])};})}:{'type':'message','content':_0x465625&&'content'in _0x465625?null==_0x465625['content']?'':String(_0x465625['content']):extractContent(_0x3b3f5e)};}function usageFromResponse(_0x4e61fa){var _0x17179f,_0x4dfa73,_0x575727,_0x5cccbf,_0x22b442,_0x1aeab9,_0x351155,_0x242fbf,_0x20dce8;const _0x2dc00d=extractDataPayload(_0x4e61fa),_0x1ad704=null!==(_0x4dfa73=null!==(_0x17179f=null==_0x2dc00d?void 0x0:_0x2dc00d['usage'])&&void 0x0!==_0x17179f?_0x17179f:null==_0x4e61fa?void 0x0:_0x4e61fa['usage'])&&void 0x0!==_0x4dfa73?_0x4dfa73:null;return _0x1ad704&&'object'==typeof _0x1ad704?{'tokensIn':null!==(_0x22b442=null!==(_0x5cccbf=null!==(_0x575727=_0x1ad704['prompt_tokens'])&&void 0x0!==_0x575727?_0x575727:_0x1ad704['input_tokens'])&&void 0x0!==_0x5cccbf?_0x5cccbf:_0x1ad704['tokensIn'])&&void 0x0!==_0x22b442?_0x22b442:0x0,'tokensOut':null!==(_0x20dce8=null!==(_0x242fbf=null!==(_0x351155=null!==(_0x1aeab9=_0x1ad704['completion_tokens'])&&void 0x0!==_0x1aeab9?_0x1aeab9:_0x1ad704['output_tokens'])&&void 0x0!==_0x351155?_0x351155:_0x1ad704['total_tokens'])&&void 0x0!==_0x242fbf?_0x242fbf:_0x1ad704['tokensOut'])&&void 0x0!==_0x20dce8?_0x20dce8:0x0,'model':null!=(null==_0x2dc00d?void 0x0:_0x2dc00d['model'])?String(_0x2dc00d['model']):null!=_0x1ad704['model']?String(_0x1ad704['model']):null}:{'tokensIn':0x0,'tokensOut':0x0,'model':null!=(null==_0x2dc00d?void 0x0:_0x2dc00d['model'])?String(_0x2dc00d['model']):null};}export function toOpenAiToolName(_0x86f36f){return String(null!=_0x86f36f?_0x86f36f:'')['replace'](/[^a-zA-Z0-9_-]/g,'_')||'tool';}export function buildOpenAiToolNameMap(_0xb01ec8=[]){var _0x196561;const _0x41883a=new Map(),_0x437c6d=new Map();for(const _0x3511cc of Array['isArray'](_0xb01ec8)?_0xb01ec8:[]){const _0x3dadf4=String(null!==(_0x196561=null==_0x3511cc?void 0x0:_0x3511cc['name'])&&void 0x0!==_0x196561?_0x196561:'');if(!_0x3dadf4)continue;let _0x1b0ffd=toOpenAiToolName(_0x3dadf4),_0x39fcae=0x2;for(;_0x437c6d['has'](_0x1b0ffd)&&_0x437c6d['get'](_0x1b0ffd)!==_0x3dadf4;)_0x1b0ffd=toOpenAiToolName(_0x3dadf4)+'_'+_0x39fcae,_0x39fcae+=0x1;_0x41883a['set'](_0x3dadf4,_0x1b0ffd),_0x437c6d['set'](_0x1b0ffd,_0x3dadf4);}return{'toSanitized':_0x41883a,'toOriginal':_0x437c6d};}export function toOpenAiTools(_0x3929e6=[],_0xda6ca6=null){const _0x7af4d3=null!=_0xda6ca6?_0xda6ca6:buildOpenAiToolNameMap(_0x3929e6)['toSanitized'];return(Array['isArray'](_0x3929e6)?_0x3929e6:[])['map'](_0x46e649=>{var _0x44fe65,_0x2d02e4;return{'type':'function','function':{'name':null!==(_0x44fe65=_0x7af4d3['get'](_0x46e649['name']))&&void 0x0!==_0x44fe65?_0x44fe65:toOpenAiToolName(_0x46e649['name']),'description':_0x46e649['description']||'','parameters':null!==(_0x2d02e4=_0x46e649['inputSchema'])&&void 0x0!==_0x2d02e4?_0x2d02e4:{'type':'object','properties':{}}}};});}export function buildAgentChatMessages(_0x103ced,_0x269015=null){var _0x47bd0b,_0x380252,_0x448f67,_0x21e91f,_0x10b3c1,_0x19bbcd;const _0x567609=Array['isArray'](_0x103ced)?_0x103ced:[],_0x361e10=_0x567609['filter'](_0x112712=>{var _0x4ead8d;return _0x112712&&'object'==typeof _0x112712&&'system'===_0x112712['role']&&String(null!==(_0x4ead8d=_0x112712['content'])&&void 0x0!==_0x4ead8d?_0x4ead8d:'')['trim']();})['map'](_0x5b9ae2=>String(_0x5b9ae2['content'])['trim']())['join']('\x0a\x0a'),_0x4627ea=[];_0x361e10&&_0x4627ea['push']({'role':'system','content':_0x361e10});for(const _0x28a2c7 of _0x567609)if(_0x28a2c7&&'object'==typeof _0x28a2c7&&'system'!==_0x28a2c7['role']){if('user'!==_0x28a2c7['role']){if('assistant'===_0x28a2c7['role']){const _0x35d096=Array['isArray'](_0x28a2c7['toolCalls'])?_0x28a2c7['toolCalls']:Array['isArray'](_0x28a2c7['tool_calls'])?_0x28a2c7['tool_calls']:null;if(_0x35d096&&_0x35d096['length']>0x0){const _0x283110=null!=_0x28a2c7['content']&&''!==String(_0x28a2c7['content'])['trim']()?String(_0x28a2c7['content']):'';_0x4627ea['push']({'role':'assistant','content':_0x283110,'tool_calls':_0x35d096['map']((_0x37925f,_0x1d465b)=>{var _0x45dc2f,_0x37b220,_0xcc40b1,_0x4cba8b,_0x5dff50,_0x30f050,_0x40e71c;const _0x51531c=(null==_0x37925f?void 0x0:_0x37925f['function'])&&'object'==typeof _0x37925f['function']?_0x37925f['function']:null,_0x4da8b9=null!==(_0x45dc2f=null==_0x51531c?void 0x0:_0x51531c['name'])&&void 0x0!==_0x45dc2f?_0x45dc2f:null==_0x37925f?void 0x0:_0x37925f['name'];return{'id':String(null!==(_0x37b220=null==_0x37925f?void 0x0:_0x37925f['id'])&&void 0x0!==_0x37b220?_0x37b220:'call_'+(_0x1d465b+0x1)),'type':'function','function':{'name':null!==(_0xcc40b1=null==_0x269015?void 0x0:_0x269015['get'](_0x4da8b9))&&void 0x0!==_0xcc40b1?_0xcc40b1:toOpenAiToolName(_0x4da8b9),'arguments':'string'==typeof(null!==(_0x4cba8b=null==_0x51531c?void 0x0:_0x51531c['arguments'])&&void 0x0!==_0x4cba8b?_0x4cba8b:null==_0x37925f?void 0x0:_0x37925f['arguments'])?null!==(_0x5dff50=null==_0x51531c?void 0x0:_0x51531c['arguments'])&&void 0x0!==_0x5dff50?_0x5dff50:null==_0x37925f?void 0x0:_0x37925f['arguments']:JSON['stringify'](null!==(_0x40e71c=null!==(_0x30f050=null==_0x51531c?void 0x0:_0x51531c['arguments'])&&void 0x0!==_0x30f050?_0x30f050:null==_0x37925f?void 0x0:_0x37925f['arguments'])&&void 0x0!==_0x40e71c?_0x40e71c:{})}};})});continue;}_0x4627ea['push']({'role':'assistant','content':String(null!==(_0x380252=_0x28a2c7['content'])&&void 0x0!==_0x380252?_0x380252:'')});continue;}if('tool'===_0x28a2c7['role']){const _0x41a39f=null!==(_0x448f67=_0x28a2c7['toolCallId'])&&void 0x0!==_0x448f67?_0x448f67:_0x28a2c7['tool_call_id'];if(null==_0x41a39f||''===String(_0x41a39f)['trim']())continue;const _0x50e97d=null!==(_0x21e91f=_0x28a2c7['name'])&&void 0x0!==_0x21e91f?_0x21e91f:null,_0x48becf={'role':'tool','tool_call_id':String(_0x41a39f),'content':String(null!==(_0x10b3c1=_0x28a2c7['content'])&&void 0x0!==_0x10b3c1?_0x10b3c1:'')};_0x50e97d&&(_0x48becf['name']=null!==(_0x19bbcd=null==_0x269015?void 0x0:_0x269015['get'](_0x50e97d))&&void 0x0!==_0x19bbcd?_0x19bbcd:toOpenAiToolName(_0x50e97d)),_0x4627ea['push'](_0x48becf);}}else _0x4627ea['push']({'role':'user','content':String(null!==(_0x47bd0b=_0x28a2c7['content'])&&void 0x0!==_0x47bd0b?_0x47bd0b:'')});}return _0x4627ea;}export function describeChatMessageRoles(_0x546eb9){return(Array['isArray'](_0x546eb9)?_0x546eb9:[])['map']((_0xf18e6c,_0x4baa64)=>{var _0x1c0f0f,_0x383a3b;return _0xf18e6c&&'object'==typeof _0xf18e6c?'assistant'===_0xf18e6c['role']&&Array['isArray'](_0xf18e6c['tool_calls'])?_0x4baa64+':assistant(tool_calls='+_0xf18e6c['tool_calls']['length']+')':'tool'===_0xf18e6c['role']?_0x4baa64+':tool(tool_call_id='+(null!==(_0x1c0f0f=_0xf18e6c['tool_call_id'])&&void 0x0!==_0x1c0f0f?_0x1c0f0f:'?')+')':_0x4baa64+':'+(null!==(_0x383a3b=_0xf18e6c['role'])&&void 0x0!==_0x383a3b?_0x383a3b:'?'):_0x4baa64+':<?>';})['join']('\x20->\x20');}export async function completeViaSendAI(_0xea1e06,_0x1e20b3){var _0x5207fa,_0x403260,_0x27372a,_0x46f43a,_0x5f20ea,_0x57b71f,_0x3f1688;const _0x52be06=Array['isArray'](_0x1e20b3['tools'])?_0x1e20b3['tools']:[],{toSanitized:_0x3ddb6b,toOriginal:_0x207d1b}=buildOpenAiToolNameMap(_0x52be06),_0x5eb3ae=buildAgentChatMessages(_0x1e20b3['messages'],_0x3ddb6b),_0x166fb3=toOpenAiTools(_0x52be06,_0x3ddb6b),_0x951796=describeChatMessageRoles(_0x5eb3ae),_0x5496cb={'useKnowledgeBase':!0x1,'messages':_0x5eb3ae};let _0x1ed1ed;_0x166fb3['length']>0x0&&(_0x5496cb['tools']=_0x166fb3);try{_0x1ed1ed=await _0xea1e06['sendAI']({'senderId':null!==(_0x5207fa=_0x1e20b3['userId'])&&void 0x0!==_0x5207fa?_0x5207fa:_0xea1e06['userId'],'provider':null!==(_0x403260=_0x1e20b3['provider'])&&void 0x0!==_0x403260?_0x403260:void 0x0,'model':null!==(_0x27372a=_0x1e20b3['model'])&&void 0x0!==_0x27372a?_0x27372a:void 0x0,'sessionId':null!==(_0x46f43a=_0x1e20b3['sessionId'])&&void 0x0!==_0x46f43a?_0x46f43a:null,'saveHistory':!0x1,'message':_0x5496cb});}catch(_0x2c6028){throw new LLMError(null!==(_0x5f20ea=null==_0x2c6028?void 0x0:_0x2c6028['message'])&&void 0x0!==_0x5f20ea?_0x5f20ea:'Local\x20sendAI\x20completion\x20failed',{'executionId':_0x1e20b3['executionId'],'agentId':_0x1e20b3['agentId'],'cause':_0x2c6028 instanceof Error?_0x2c6028:void 0x0});}if(null==_0x1ed1ed)throw new LLMError('Local\x20sendAI\x20completion\x20returned\x20empty\x20response',{'executionId':_0x1e20b3['executionId'],'agentId':_0x1e20b3['agentId']});const _0x566c60=extractDataPayload(_0x1ed1ed);if('error'===(null==_0x566c60?void 0x0:_0x566c60['type'])){const _0x2bb0f5=null!==(_0x57b71f=_0x566c60['message'])&&void 0x0!==_0x57b71f?_0x57b71f:'sendAI\x20returned\x20an\x20error';if(/role ['"]tool['"].*tool_calls/i['test'](String(_0x2bb0f5)))throw console['warn']('[agent-runtime]\x20sendAI\x20rejected\x20tool\x20history.\x20SDK\x20messages:',_0x951796),console['warn']('[agent-runtime]\x20If\x20the\x20digest\x20shows\x20assistant(tool_calls=N)\x20immediately\x20before\x20tool(...),\x20the\x20server\x20is\x20likely\x20dropping\x20tool_calls\x20before\x20forwarding\x20to\x20the\x20model.'),new LLMError(_0x2bb0f5+'\x20(sdk\x20messages:\x20'+_0x951796+')',{'executionId':_0x1e20b3['executionId'],'agentId':_0x1e20b3['agentId']});throw new LLMError(_0x2bb0f5,{'executionId':_0x1e20b3['executionId'],'agentId':_0x1e20b3['agentId']});}const _0x24eda8=usageFromResponse(_0x1ed1ed),_0x312610=null!=_0x1e20b3['model']&&''!==String(_0x1e20b3['model'])['trim']()?String(_0x1e20b3['model']):null,_0x100536=null!=_0x1e20b3['provider']&&''!==String(_0x1e20b3['provider'])['trim']()?String(_0x1e20b3['provider']):null,_0x18d88e=parseNativeTurn(_0x1ed1ed);return'tool_calls'===_0x18d88e['type']&&(_0x18d88e['calls']=_0x18d88e['calls']['map'](_0x54df5d=>{var _0x3bdf69;return{..._0x54df5d,'name':null!==(_0x3bdf69=_0x207d1b['get'](_0x54df5d['name']))&&void 0x0!==_0x3bdf69?_0x3bdf69:_0x54df5d['name']};})),{..._0x18d88e,'model':null!==(_0x3f1688=_0x24eda8['model'])&&void 0x0!==_0x3f1688?_0x3f1688:_0x312610,'provider':_0x100536,'tokensIn':_0x24eda8['tokensIn'],'tokensOut':_0x24eda8['tokensOut']};}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function textFromContent(result: {
|
|
2
|
+
content?: {
|
|
3
|
+
type?: string;
|
|
4
|
+
text?: string;
|
|
5
|
+
}[];
|
|
6
|
+
}): string;
|
|
7
|
+
export class McpHttpClient {
|
|
8
|
+
constructor({ endpoint, headers, sdkVersion }: {
|
|
9
|
+
endpoint: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
sdkVersion?: string;
|
|
12
|
+
});
|
|
13
|
+
endpoint: string;
|
|
14
|
+
headers: {
|
|
15
|
+
[x: string]: string;
|
|
16
|
+
};
|
|
17
|
+
sdkVersion: string;
|
|
18
|
+
sessionId: string | null;
|
|
19
|
+
_nextId: number;
|
|
20
|
+
_initialized: boolean;
|
|
21
|
+
connect(): Promise<void>;
|
|
22
|
+
listTools(): Promise<object[]>;
|
|
23
|
+
callTool(name: string, args: unknown, context?: {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): Promise<any>;
|
|
26
|
+
_initialize(): Promise<void>;
|
|
27
|
+
_request(method: string, params: object, signal?: AbortSignal): Promise<any>;
|
|
28
|
+
_post(payload: object, signal: AbortSignal | null): Promise<any>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/agent-runtime/mcp/client.js"],"names":[],"mappings":"AA2CA,wCADY;IAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,UAQ3D;AAED;IAQE,+CANW;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,EASH;IANC,iBAAwB;IACxB;;MAA6B;IAC7B,mBAA4B;IAC5B,yBAAqB;IACrB,gBAAgB;IAChB,sBAAyB;IAG3B,yBAEC;IAKD,aAFa,OAAO,CAAC,MAAM,EAAE,CAAC,CAa7B;IAOD,eAJW,MAAM,QACN,OAAO,YACP;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,gBAelC;IAED,6BAyBC;IAOD,iBAJW,MAAM,UACN,MAAM,WACN,WAAW,gBA8BrB;IAOD,eAHW,MAAM,UACN,WAAW,GAAG,IAAI,gBAwD5B;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MCPConnectionError,MCPToolError}from'../errors.js';const PROTOCOL_VERSION='2025-03-26';async function readJson(_0x3c3dc7){const _0x4a7738=await _0x3c3dc7['text']();if(!_0x4a7738)return{};try{return JSON['parse'](_0x4a7738);}catch(_0x31ac92){throw new MCPConnectionError('MCP\x20response\x20was\x20not\x20JSON',{'cause':_0x31ac92 instanceof Error?_0x31ac92:void 0x0});}}async function readSseJson(_0x38d202){const _0x5b2f5d=(await _0x38d202['text']())['split']('\x0a')['filter'](_0x2da547=>_0x2da547['startsWith']('data:'))['map'](_0x31fc75=>_0x31fc75['slice'](0x5)['trim']())['filter'](Boolean),_0x894c11=_0x5b2f5d[_0x5b2f5d['length']-0x1];if(!_0x894c11)return{};try{return JSON['parse'](_0x894c11);}catch(_0x158134){throw new MCPConnectionError('MCP\x20event\x20stream\x20was\x20not\x20JSON',{'provider':'mcp','cause':_0x158134 instanceof Error?_0x158134:void 0x0});}}export function textFromContent(_0x30b75d){return(Array['isArray'](null==_0x30b75d?void 0x0:_0x30b75d['content'])?_0x30b75d['content']:[])['filter'](_0xa82ed9=>'text'===(null==_0xa82ed9?void 0x0:_0xa82ed9['type'])&&'string'==typeof _0xa82ed9['text'])['map'](_0x5cfcba=>_0x5cfcba['text'])['join']('\x0a')||JSON['stringify'](null!=_0x30b75d?_0x30b75d:null);}export class McpHttpClient{constructor({endpoint:_0x1599bb,headers:_0x11d86c={},sdkVersion:_0x3bfccf='1.1.23'}){this['endpoint']=_0x1599bb,this['headers']={..._0x11d86c},this['sdkVersion']=_0x3bfccf,this['sessionId']=null,this['_nextId']=0x1,this['_initialized']=!0x1;}async['connect'](){await this['_initialize']();}async['listTools'](){const _0xfe963a=[];let _0x5d081c;do{const _0x1990b0=await this['_request']('tools/list',_0x5d081c?{'cursor':_0x5d081c}:{}),_0x6b1e18=Array['isArray'](null==_0x1990b0?void 0x0:_0x1990b0['tools'])?_0x1990b0['tools']:[];_0xfe963a['push'](..._0x6b1e18),_0x5d081c=(null==_0x1990b0?void 0x0:_0x1990b0['nextCursor'])||void 0x0;}while(_0x5d081c);return _0xfe963a;}async['callTool'](_0xcbf68e,_0x2e843d,_0x2f4777={}){const _0x2848f1=await this['_request']('tools/call',{'name':_0xcbf68e,'arguments':null!=_0x2e843d?_0x2e843d:{}},_0x2f4777['signal']);if(null==_0x2848f1?void 0x0:_0x2848f1['isError'])throw new MCPToolError(textFromContent(_0x2848f1)||'MCP\x20tool\x20failed:\x20'+_0xcbf68e,{'provider':'mcp'});return _0x2848f1;}async['_initialize'](){const _0xdf416=await this['_post']({'jsonrpc':'2.0','id':this['_nextId']++,'method':'initialize','params':{'protocolVersion':'2025-03-26','capabilities':{},'clientInfo':{'name':'dnotifier-js-sdk','version':this['sdkVersion']}}},null);if(null==_0xdf416?void 0x0:_0xdf416['error'])throw new MCPConnectionError(_0xdf416['error']['message']||'MCP\x20initialize\x20failed',{'provider':'mcp'});this['_initialized']=!0x0,await this['_post']({'jsonrpc':'2.0','method':'notifications/initialized'},null);}async['_request'](_0x388d9,_0x3b8127,_0x2da2f7){const _0x415a35=async()=>{var _0x21c71a;const _0x509602=await this['_post']({'jsonrpc':'2.0','id':this['_nextId']++,'method':_0x388d9,'params':_0x3b8127},_0x2da2f7);if(null==_0x509602?void 0x0:_0x509602['error'])throw new MCPToolError(_0x509602['error']['message']||'MCP\x20'+_0x388d9+'\x20failed',{'provider':'mcp'});return null!==(_0x21c71a=null==_0x509602?void 0x0:_0x509602['result'])&&void 0x0!==_0x21c71a?_0x21c71a:{};};try{return await _0x415a35();}catch(_0xe0bd9b){if(!(null==_0xe0bd9b?void 0x0:_0xe0bd9b['retryable']))throw _0xe0bd9b;return this['_initialized']=!0x1,this['sessionId']=null,await this['_initialize'](),_0x415a35();}}async['_post'](_0x59a749,_0x5b235f){var _0x21a059,_0x5855a9;const _0x291937={'accept':'application/json,\x20text/event-stream','content-type':'application/json',...this['headers']};let _0x184145;this['sessionId']&&(_0x291937['mcp-session-id']=this['sessionId']);try{_0x184145=await fetch(this['endpoint'],{'method':'POST','headers':_0x291937,'body':JSON['stringify'](_0x59a749),'signal':null!=_0x5b235f?_0x5b235f:void 0x0});}catch(_0x98a199){if(_0x98a199 instanceof MCPConnectionError||_0x98a199 instanceof MCPToolError)throw _0x98a199;const _0x49ff6f=new MCPConnectionError(null!==(_0x21a059=null==_0x98a199?void 0x0:_0x98a199['message'])&&void 0x0!==_0x21a059?_0x21a059:'MCP\x20connection\x20failed',{'provider':'mcp','cause':_0x98a199 instanceof Error?_0x98a199:void 0x0});throw _0x49ff6f['retryable']=!0x0,_0x49ff6f;}const _0x2e3b41=_0x184145['headers']['get']('mcp-session-id');if(_0x2e3b41&&(this['sessionId']=_0x2e3b41),0x194===_0x184145['status']){const _0x1e2c06=new MCPConnectionError('MCP\x20session\x20expired',{'provider':'mcp'});throw _0x1e2c06['retryable']=!0x0,_0x1e2c06;}if(!_0x184145['ok']){const _0x19a29d=await _0x184145['text']();throw new MCPConnectionError(_0x19a29d||'MCP\x20HTTP\x20'+_0x184145['status'],{'provider':'mcp'});}return(null!==(_0x5855a9=_0x184145['headers']['get']('content-type'))&&void 0x0!==_0x5855a9?_0x5855a9:'')['includes']('text/event-stream')?readSseJson(_0x184145):readJson(_0x184145);}}
|