@artinet/sdk 0.6.0-preview.1 → 0.6.0-preview.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -17
- package/dist/browser/client/a2a-client.js +4 -4
- package/dist/browser/config/index.d.ts +1 -1
- package/dist/browser/config/index.js +1 -1
- package/dist/browser/create/agentcard-builder.d.ts +47 -0
- package/dist/browser/create/agentcard-builder.js +65 -0
- package/dist/browser/create/base.d.ts +4 -0
- package/dist/browser/create/base.js +1 -0
- package/dist/browser/create/describe.d.ts +8 -0
- package/dist/browser/create/describe.js +8 -0
- package/dist/browser/create/message-builder.d.ts +78 -0
- package/dist/browser/create/message-builder.js +108 -0
- package/dist/browser/create/part-builder.d.ts +60 -0
- package/dist/browser/create/part-builder.js +81 -0
- package/dist/browser/create/task-builder.d.ts +251 -0
- package/dist/browser/create/task-builder.js +379 -0
- package/dist/browser/transport/rpc/parser.d.ts +1 -1
- package/dist/browser/transport/rpc/parser.js +2 -1
- package/dist/browser/types/a2a/a2a.d.ts +7 -3
- package/dist/browser/types/a2a/index.d.ts +3 -1
- package/dist/browser/types/a2a/index.js +0 -1
- package/dist/browser/utils/common/constants.d.ts +0 -5
- package/dist/browser/utils/common/constants.js +0 -27
- package/dist/browser/utils/common/errors.d.ts +57 -1
- package/dist/browser/utils/common/errors.js +68 -15
- package/dist/client/a2a-client.js +4 -4
- package/dist/config/default.d.ts +1 -1
- package/dist/config/default.js +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/create/agent-builder.d.ts +77 -0
- package/dist/create/agent-builder.js +20 -0
- package/dist/create/agentcard-builder.d.ts +47 -0
- package/dist/create/agentcard-builder.js +66 -0
- package/dist/create/base.d.ts +4 -0
- package/dist/create/base.js +1 -0
- package/dist/create/create.d.ts +762 -0
- package/dist/create/create.js +556 -0
- package/dist/create/describe.d.ts +8 -0
- package/dist/create/describe.js +8 -0
- package/dist/create/index.d.ts +4 -0
- package/dist/create/index.js +4 -0
- package/dist/create/message-builder.d.ts +78 -0
- package/dist/create/message-builder.js +110 -0
- package/dist/create/part-builder.d.ts +60 -0
- package/dist/create/part-builder.js +84 -0
- package/dist/create/status-builder.d.ts +30 -0
- package/dist/create/status-builder.js +46 -0
- package/dist/create/task-builder.d.ts +251 -0
- package/dist/create/task-builder.js +384 -0
- package/dist/create/transform.d.ts +16 -0
- package/dist/create/transform.js +106 -0
- package/dist/extensions/otel.d.ts +3 -0
- package/dist/extensions/otel.js +3 -0
- package/dist/extensions/pino.d.ts +3 -0
- package/dist/extensions/pino.js +3 -0
- package/dist/extensions/winston.d.ts +3 -0
- package/dist/extensions/winston.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/server/express/errors.js +4 -8
- package/dist/server/express/middeware.js +17 -38
- package/dist/server/express/server.d.ts +20 -1
- package/dist/server/express/server.js +44 -12
- package/dist/services/a2a/execute.d.ts +5 -0
- package/dist/services/a2a/execute.js +7 -0
- package/dist/services/a2a/factory/context.d.ts +1 -1
- package/dist/services/a2a/factory/context.js +2 -3
- package/dist/services/a2a/factory/handler.js +3 -3
- package/dist/services/a2a/factory/index.d.ts +0 -1
- package/dist/services/a2a/factory/index.js +0 -1
- package/dist/services/a2a/factory/service.d.ts +2 -2
- package/dist/services/a2a/factory/service.js +2 -2
- package/dist/services/a2a/factory/state-machine.d.ts +1 -1
- package/dist/services/a2a/factory/state-machine.js +30 -8
- package/dist/services/a2a/handlers/artifact.d.ts +2 -5
- package/dist/services/a2a/handlers/artifact.js +21 -32
- package/dist/services/a2a/handlers/cancel-task.js +7 -5
- package/dist/services/a2a/handlers/resubscribe-task.d.ts +10 -2
- package/dist/services/a2a/handlers/resubscribe-task.js +21 -18
- package/dist/services/a2a/handlers/send-message.js +6 -10
- package/dist/services/a2a/handlers/stream-message.d.ts +10 -2
- package/dist/services/a2a/handlers/stream-message.js +5 -1
- package/dist/services/a2a/handlers/update.js +15 -12
- package/dist/services/a2a/helpers/content.d.ts +5 -1
- package/dist/services/a2a/helpers/content.js +5 -1
- package/dist/services/a2a/helpers/index.d.ts +2 -2
- package/dist/services/a2a/helpers/index.js +2 -2
- package/dist/services/a2a/index.d.ts +1 -1
- package/dist/services/a2a/index.js +1 -1
- package/dist/services/a2a/managers.js +7 -1
- package/dist/services/a2a/service.d.ts +6 -2
- package/dist/services/a2a/service.js +54 -61
- package/dist/services/a2a/state-machine.d.ts +3 -3
- package/dist/services/a2a/state-machine.js +2 -0
- package/dist/transport/rpc/parser.d.ts +1 -1
- package/dist/transport/rpc/parser.js +2 -1
- package/dist/transport/trpc/a2a/routes/message/route.js +2 -1
- package/dist/transport/trpc/a2a/routes/tasks/route.js +2 -1
- package/dist/types/a2a/a2a.d.ts +7 -3
- package/dist/types/a2a/index.d.ts +3 -1
- package/dist/types/a2a/index.js +0 -1
- package/dist/utils/common/constants.d.ts +0 -5
- package/dist/utils/common/constants.js +0 -27
- package/dist/utils/common/errors.d.ts +57 -1
- package/dist/utils/common/errors.js +68 -15
- package/dist/utils/common/parse.d.ts +1 -1
- package/dist/utils/common/schema-validation.d.ts +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/package.json +8 -5
- package/dist/browser/services/a2a/helpers/message-builder.d.ts +0 -17
- package/dist/browser/services/a2a/helpers/message-builder.js +0 -66
- package/dist/browser/types/a2a/builder.d.ts +0 -43
- package/dist/browser/types/a2a/builder.js +0 -5
- package/dist/services/a2a/factory/builder.d.ts +0 -292
- package/dist/services/a2a/factory/builder.js +0 -370
- package/dist/services/a2a/helpers/agentcard-builder.d.ts +0 -11
- package/dist/services/a2a/helpers/agentcard-builder.js +0 -27
- package/dist/services/a2a/helpers/message-builder.d.ts +0 -17
- package/dist/services/a2a/helpers/message-builder.js +0 -66
- package/dist/types/a2a/builder.d.ts +0 -43
- package/dist/types/a2a/builder.js +0 -5
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ npm install @artinet/sdk
|
|
|
55
55
|
**Peer dependencies (required):**
|
|
56
56
|
|
|
57
57
|
```bash
|
|
58
|
-
npm install @a2a-js/sdk @modelcontextprotocol/sdk
|
|
58
|
+
npm install @a2a-js/sdk @modelcontextprotocol/sdk @trpc/server
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
## Requirements
|
|
@@ -67,22 +67,13 @@ npm install @a2a-js/sdk @modelcontextprotocol/sdk
|
|
|
67
67
|
**Server:**
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
|
-
import {
|
|
71
|
-
|
|
72
|
-
const { app } =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
.createAgent({
|
|
78
|
-
agentCard: "QuickStart Agent",
|
|
79
|
-
}),
|
|
80
|
-
basePath: "/a2a",
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
app.listen(3000, () => {
|
|
84
|
-
console.log("A2A Server running at http://localhost:3000/a2a");
|
|
85
|
-
});
|
|
70
|
+
import { cr8 } from "@artinet/sdk";
|
|
71
|
+
|
|
72
|
+
const { app } = cr8("QuickStart Agent")
|
|
73
|
+
.text(async ({ content }) => {
|
|
74
|
+
return `You said: ${content}`;
|
|
75
|
+
}) //start an a2a server on port 3000
|
|
76
|
+
.server.start(3000);
|
|
86
77
|
```
|
|
87
78
|
|
|
88
79
|
**Client:**
|
|
@@ -6,7 +6,7 @@ import { executeJsonRpcRequest, executeGetRequest, } from "../transport/rpc/rpc-
|
|
|
6
6
|
import { executeStreamEvents } from "../transport/streaming/event-stream.js";
|
|
7
7
|
import { INTERNAL_ERROR } from "../utils/common/errors.js";
|
|
8
8
|
import { logger } from "../config/index.js";
|
|
9
|
-
import
|
|
9
|
+
import * as describe from "../create/describe.js";
|
|
10
10
|
/**
|
|
11
11
|
* A2AClient is the main client class for interacting with Agent2Agent (A2A) protocol-compliant services.
|
|
12
12
|
* It provides methods for sending tasks, retrieving statuses, canceling operations, and handling streaming responses.
|
|
@@ -104,10 +104,10 @@ export class A2AClient {
|
|
|
104
104
|
*/
|
|
105
105
|
async sendMessage(params) {
|
|
106
106
|
return await executeJsonRpcRequest(this.agentUrl, "message/send", typeof params === "string"
|
|
107
|
-
?
|
|
107
|
+
? describe.messageSendParams(params)
|
|
108
108
|
: typeof params === "object" && "message" in params
|
|
109
109
|
? params
|
|
110
|
-
:
|
|
110
|
+
: describe.messageSendParams({ message: params }), this.customHeaders);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* @deprecated Use sendMessage instead.
|
|
@@ -124,7 +124,7 @@ export class A2AClient {
|
|
|
124
124
|
* @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
|
|
125
125
|
*/
|
|
126
126
|
sendStreamingMessage(params) {
|
|
127
|
-
return executeStreamEvents(this.agentUrl, "message/stream",
|
|
127
|
+
return executeStreamEvents(this.agentUrl, "message/stream", describe.messageSendParams(params), this.customHeaders);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* @deprecated Use sendStreamingMessage instead.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
export type AgentCardParams = (Partial<A2A.AgentCard> & Required<Pick<A2A.AgentCard, "name">>) | string;
|
|
7
|
+
export declare const isAgentCardParams: (params: any) => params is AgentCardParams;
|
|
8
|
+
export declare class AgentCard {
|
|
9
|
+
private readonly _agentCard;
|
|
10
|
+
constructor(params: Partial<A2A.AgentCard> & Required<Pick<A2A.AgentCard, "name">>);
|
|
11
|
+
get agentCard(): A2A.AgentCard;
|
|
12
|
+
static create(params: AgentCardParams): A2A.AgentCard;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use {@link card} instead
|
|
16
|
+
* @since 0.6.0
|
|
17
|
+
*/
|
|
18
|
+
export declare const AgentCardBuilder: typeof AgentCard;
|
|
19
|
+
/**
|
|
20
|
+
* Convenience factory function for creating an {@link A2A.AgentCard} with default parameters.
|
|
21
|
+
*
|
|
22
|
+
* @returns New {@link A2A.AgentCard} with default parameters
|
|
23
|
+
* @defaults {
|
|
24
|
+
* description: "An agent that can use the A2A protocol.",
|
|
25
|
+
* url: "https://localhost:3000/a2a",
|
|
26
|
+
* version: "0.0.0",
|
|
27
|
+
* capabilities: {},
|
|
28
|
+
* defaultInputModes: [],
|
|
29
|
+
* defaultOutputModes: [],
|
|
30
|
+
* skills: [],
|
|
31
|
+
* preferredTransport: "JSONRPC",
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const agentCard = card("My Agent");
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
* @since 0.6.0
|
|
41
|
+
*/
|
|
42
|
+
export declare const card: typeof AgentCard.create;
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use {@link card} instead
|
|
45
|
+
* @since 0.6.0
|
|
46
|
+
*/
|
|
47
|
+
export declare const createAgentCard: typeof AgentCard.create;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
export const isAgentCardParams = (params) => {
|
|
6
|
+
return (typeof params === "string" ||
|
|
7
|
+
(typeof params === "object" && params !== null && "name" in params));
|
|
8
|
+
};
|
|
9
|
+
export class AgentCard {
|
|
10
|
+
constructor(params) {
|
|
11
|
+
this._agentCard = {
|
|
12
|
+
protocolVersion: "0.3.0",
|
|
13
|
+
description: "An agent that can use the A2A protocol.",
|
|
14
|
+
url: "https://localhost:3000/a2a",
|
|
15
|
+
version: "0.0.0",
|
|
16
|
+
capabilities: {},
|
|
17
|
+
defaultInputModes: [],
|
|
18
|
+
defaultOutputModes: [],
|
|
19
|
+
skills: [],
|
|
20
|
+
preferredTransport: "JSONRPC",
|
|
21
|
+
...params,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
get agentCard() {
|
|
25
|
+
return this._agentCard;
|
|
26
|
+
}
|
|
27
|
+
static create(params) {
|
|
28
|
+
return new AgentCard(typeof params === "string" ? { name: params } : params)
|
|
29
|
+
.agentCard;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use {@link card} instead
|
|
34
|
+
* @since 0.6.0
|
|
35
|
+
*/
|
|
36
|
+
export const AgentCardBuilder = AgentCard;
|
|
37
|
+
/**
|
|
38
|
+
* Convenience factory function for creating an {@link A2A.AgentCard} with default parameters.
|
|
39
|
+
*
|
|
40
|
+
* @returns New {@link A2A.AgentCard} with default parameters
|
|
41
|
+
* @defaults {
|
|
42
|
+
* description: "An agent that can use the A2A protocol.",
|
|
43
|
+
* url: "https://localhost:3000/a2a",
|
|
44
|
+
* version: "0.0.0",
|
|
45
|
+
* capabilities: {},
|
|
46
|
+
* defaultInputModes: [],
|
|
47
|
+
* defaultOutputModes: [],
|
|
48
|
+
* skills: [],
|
|
49
|
+
* preferredTransport: "JSONRPC",
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const agentCard = card("My Agent");
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
* @since 0.6.0
|
|
59
|
+
*/
|
|
60
|
+
export const card = AgentCard.create;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use {@link card} instead
|
|
63
|
+
* @since 0.6.0
|
|
64
|
+
*/
|
|
65
|
+
export const createAgentCard = AgentCard.create;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { card, type AgentCardParams, isAgentCardParams, } from "./agentcard-builder.js";
|
|
2
|
+
export { message, type MessageParams, isMessageParams, messageSendParams, type MessageSendParamsParams, } from "./message-builder.js";
|
|
3
|
+
export { part } from "./part-builder.js";
|
|
4
|
+
export { artifact, type ArtifactParams, isArtifactParams, type StatusParams, isStatusParams, status, type TaskParams, task, type StatusUpdateParams, type ArtifactUpdateParams, update, } from "./task-builder.js";
|
|
5
|
+
/**
|
|
6
|
+
* Exports from describe are meant to be portable between different modules.
|
|
7
|
+
* As such, they should only be dependant on `./types` or other Factory files that are also portable.
|
|
8
|
+
*/
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { card, isAgentCardParams, } from "./agentcard-builder.js";
|
|
2
|
+
export { message, isMessageParams, messageSendParams, } from "./message-builder.js";
|
|
3
|
+
export { part } from "./part-builder.js";
|
|
4
|
+
export { artifact, isArtifactParams, isStatusParams, status, task, update, } from "./task-builder.js";
|
|
5
|
+
/**
|
|
6
|
+
* Exports from describe are meant to be portable between different modules.
|
|
7
|
+
* As such, they should only be dependant on `./types` or other Factory files that are also portable.
|
|
8
|
+
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
import { Kindless } from "./base.js";
|
|
7
|
+
export declare class Message {
|
|
8
|
+
private readonly _message;
|
|
9
|
+
constructor(params?: Partial<Kindless<A2A.Message>>);
|
|
10
|
+
get message(): A2A.Message;
|
|
11
|
+
static create(params?: MessageParams): A2A.Message;
|
|
12
|
+
}
|
|
13
|
+
export type BaseMessageParams = Partial<Kindless<A2A.Message>>;
|
|
14
|
+
export type MessageParams = BaseMessageParams | string;
|
|
15
|
+
export declare const isMessageParams: (params: any) => params is MessageParams;
|
|
16
|
+
/**
|
|
17
|
+
* Convenience factory function for creating a message builder with default parameters.
|
|
18
|
+
*
|
|
19
|
+
* @returns New {@link A2A.Message} with default parameters
|
|
20
|
+
* @defaults {
|
|
21
|
+
* role: "agent",
|
|
22
|
+
* parts: [],
|
|
23
|
+
* messageId: uuidv4(),
|
|
24
|
+
* kind: "message",
|
|
25
|
+
* }
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const message = message();
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
* @since 0.6.0
|
|
33
|
+
*/
|
|
34
|
+
export declare const message: typeof Message.create;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use {@link message} instead.
|
|
37
|
+
* @since 0.6.0
|
|
38
|
+
*/
|
|
39
|
+
export declare const MessageBuilder: typeof Message;
|
|
40
|
+
export declare class MessageSendConfiguration {
|
|
41
|
+
private readonly _configuration;
|
|
42
|
+
constructor(params?: Partial<A2A.MessageSendConfiguration> | null | undefined);
|
|
43
|
+
get configuration(): A2A.MessageSendConfiguration;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use {@link messageSendParams} instead.
|
|
47
|
+
* @since 0.6.0
|
|
48
|
+
*/
|
|
49
|
+
export declare const MessageSendConfigurationBuilder: typeof MessageSendConfiguration;
|
|
50
|
+
export type MessageSendParamsParams = Partial<Kindless<A2A.MessageSendParams>> | MessageParams;
|
|
51
|
+
/**
|
|
52
|
+
* Convenience factory function for creating a message send params with default parameters.
|
|
53
|
+
*
|
|
54
|
+
* @returns New {@link A2A.MessageSendParams} with default parameters
|
|
55
|
+
* @defaults {
|
|
56
|
+
* message: {
|
|
57
|
+
* role: "agent",
|
|
58
|
+
* parts: [],
|
|
59
|
+
* messageId: uuidv4(),
|
|
60
|
+
* kind: "message",
|
|
61
|
+
* },
|
|
62
|
+
* configuration: undefined,
|
|
63
|
+
* metadata: undefined,
|
|
64
|
+
* }
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const params = messageSendParams("hello there");
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
* @since 0.6.0
|
|
72
|
+
*/
|
|
73
|
+
export declare function messageSendParams(params: MessageSendParamsParams): A2A.MessageSendParams;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use {@link messageSendParams} instead.
|
|
76
|
+
* @since 0.6.0
|
|
77
|
+
*/
|
|
78
|
+
export declare const createMessageSendParams: typeof messageSendParams;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
import { v4 as uuidv4 } from "uuid";
|
|
7
|
+
export class Message {
|
|
8
|
+
constructor(params = {}) {
|
|
9
|
+
const messageId = params.messageId ?? uuidv4();
|
|
10
|
+
// TODO: Consider whether default role should be "user" when used in messageSendParams context.
|
|
11
|
+
// Currently defaults to "agent" which may be incorrect for MessageSendParams.
|
|
12
|
+
this._message = {
|
|
13
|
+
...params,
|
|
14
|
+
role: params.role ?? "agent",
|
|
15
|
+
parts: params.parts ?? [],
|
|
16
|
+
messageId,
|
|
17
|
+
kind: A2A.Kind.message,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
get message() {
|
|
21
|
+
return this._message;
|
|
22
|
+
}
|
|
23
|
+
static create(params = {}) {
|
|
24
|
+
return new Message(typeof params === "string"
|
|
25
|
+
? { parts: [{ text: params, kind: "text" }] }
|
|
26
|
+
: params).message;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const isMessageParams = (params) => {
|
|
30
|
+
return (typeof params === "string" ||
|
|
31
|
+
(typeof params === "object" && params !== null && "parts" in params));
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Convenience factory function for creating a message builder with default parameters.
|
|
35
|
+
*
|
|
36
|
+
* @returns New {@link A2A.Message} with default parameters
|
|
37
|
+
* @defaults {
|
|
38
|
+
* role: "agent",
|
|
39
|
+
* parts: [],
|
|
40
|
+
* messageId: uuidv4(),
|
|
41
|
+
* kind: "message",
|
|
42
|
+
* }
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const message = message();
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
* @since 0.6.0
|
|
50
|
+
*/
|
|
51
|
+
export const message = Message.create;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use {@link message} instead.
|
|
54
|
+
* @since 0.6.0
|
|
55
|
+
*/
|
|
56
|
+
export const MessageBuilder = Message;
|
|
57
|
+
export class MessageSendConfiguration {
|
|
58
|
+
constructor(params = {}) {
|
|
59
|
+
this._configuration = !params
|
|
60
|
+
? {}
|
|
61
|
+
: {
|
|
62
|
+
...params,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
get configuration() {
|
|
66
|
+
return this._configuration;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use {@link messageSendParams} instead.
|
|
71
|
+
* @since 0.6.0
|
|
72
|
+
*/
|
|
73
|
+
export const MessageSendConfigurationBuilder = MessageSendConfiguration;
|
|
74
|
+
/**
|
|
75
|
+
* Convenience factory function for creating a message send params with default parameters.
|
|
76
|
+
*
|
|
77
|
+
* @returns New {@link A2A.MessageSendParams} with default parameters
|
|
78
|
+
* @defaults {
|
|
79
|
+
* message: {
|
|
80
|
+
* role: "agent",
|
|
81
|
+
* parts: [],
|
|
82
|
+
* messageId: uuidv4(),
|
|
83
|
+
* kind: "message",
|
|
84
|
+
* },
|
|
85
|
+
* configuration: undefined,
|
|
86
|
+
* metadata: undefined,
|
|
87
|
+
* }
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const params = messageSendParams("hello there");
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
* @since 0.6.0
|
|
95
|
+
*/
|
|
96
|
+
export function messageSendParams(params) {
|
|
97
|
+
const _isMessageParams = isMessageParams(params);
|
|
98
|
+
return {
|
|
99
|
+
message: message(_isMessageParams ? params : params.message),
|
|
100
|
+
configuration: new MessageSendConfiguration(_isMessageParams ? undefined : params.configuration).configuration,
|
|
101
|
+
metadata: _isMessageParams ? undefined : params.metadata,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Use {@link messageSendParams} instead.
|
|
106
|
+
* @since 0.6.0
|
|
107
|
+
*/
|
|
108
|
+
export const createMessageSendParams = messageSendParams;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
export declare class TextPart {
|
|
7
|
+
private readonly _part;
|
|
8
|
+
constructor(params: string);
|
|
9
|
+
get part(): A2A.TextPart;
|
|
10
|
+
static create(params: string): A2A.TextPart;
|
|
11
|
+
}
|
|
12
|
+
export type FileParams = (Partial<A2A.File> & {
|
|
13
|
+
bytes: string;
|
|
14
|
+
}) | (Partial<A2A.File> & {
|
|
15
|
+
uri: string;
|
|
16
|
+
});
|
|
17
|
+
export type FilePartParams = string | FileParams;
|
|
18
|
+
export declare class FilePart {
|
|
19
|
+
private readonly _part;
|
|
20
|
+
constructor(params: FileParams);
|
|
21
|
+
get part(): A2A.FilePart;
|
|
22
|
+
static create(params: FilePartParams): A2A.FilePart;
|
|
23
|
+
}
|
|
24
|
+
export declare const filePart: typeof FilePart.create;
|
|
25
|
+
export declare class DataPart {
|
|
26
|
+
private readonly _part;
|
|
27
|
+
constructor(params: Record<string, unknown>);
|
|
28
|
+
get part(): A2A.DataPart;
|
|
29
|
+
static create(params: Record<string, unknown>): A2A.DataPart;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Namespace for {@link A2A.Part} creation utilities.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const t = part.text("Hello");
|
|
37
|
+
* const f = part.file("https://example.com/file.pdf");
|
|
38
|
+
* const d = part.data({ key: "value" });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
* @since 0.6.0
|
|
43
|
+
*/
|
|
44
|
+
export declare const part: {
|
|
45
|
+
/**
|
|
46
|
+
* Create a text part.
|
|
47
|
+
* @see {@link A2A.TextPart}
|
|
48
|
+
*/
|
|
49
|
+
text: typeof TextPart.create;
|
|
50
|
+
/**
|
|
51
|
+
* Create a file part.
|
|
52
|
+
* @see {@link A2A.FilePart}
|
|
53
|
+
*/
|
|
54
|
+
file: typeof FilePart.create;
|
|
55
|
+
/**
|
|
56
|
+
* Create a data part.
|
|
57
|
+
* @see {@link A2A.DataPart}
|
|
58
|
+
*/
|
|
59
|
+
data: typeof DataPart.create;
|
|
60
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
export class TextPart {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
this._part = {
|
|
9
|
+
text: params,
|
|
10
|
+
kind: A2A.Kind.text,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
get part() {
|
|
14
|
+
return this._part;
|
|
15
|
+
}
|
|
16
|
+
static create(params) {
|
|
17
|
+
return new TextPart(params).part;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class FilePart {
|
|
21
|
+
constructor(params) {
|
|
22
|
+
this._part = {
|
|
23
|
+
kind: A2A.Kind.file,
|
|
24
|
+
file: params,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
get part() {
|
|
28
|
+
return this._part;
|
|
29
|
+
}
|
|
30
|
+
static create(params) {
|
|
31
|
+
if (typeof params === "string") {
|
|
32
|
+
return new FilePart({ uri: params }).part;
|
|
33
|
+
}
|
|
34
|
+
return new FilePart(params).part;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export const filePart = FilePart.create;
|
|
38
|
+
export class DataPart {
|
|
39
|
+
constructor(params) {
|
|
40
|
+
this._part = {
|
|
41
|
+
data: params,
|
|
42
|
+
kind: A2A.Kind.data,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
get part() {
|
|
46
|
+
return this._part;
|
|
47
|
+
}
|
|
48
|
+
static create(params) {
|
|
49
|
+
return new DataPart(params).part;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Namespace for {@link A2A.Part} creation utilities.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const t = part.text("Hello");
|
|
58
|
+
* const f = part.file("https://example.com/file.pdf");
|
|
59
|
+
* const d = part.data({ key: "value" });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
* @since 0.6.0
|
|
64
|
+
*/
|
|
65
|
+
export const part = {
|
|
66
|
+
/**
|
|
67
|
+
* Create a text part.
|
|
68
|
+
* @see {@link A2A.TextPart}
|
|
69
|
+
*/
|
|
70
|
+
text: TextPart.create,
|
|
71
|
+
/**
|
|
72
|
+
* Create a file part.
|
|
73
|
+
* @see {@link A2A.FilePart}
|
|
74
|
+
*/
|
|
75
|
+
file: FilePart.create,
|
|
76
|
+
/**
|
|
77
|
+
* Create a data part.
|
|
78
|
+
* @see {@link A2A.DataPart}
|
|
79
|
+
*/
|
|
80
|
+
data: DataPart.create,
|
|
81
|
+
};
|