@artinet/sdk 0.2.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.
- package/CHANGELOG.md +45 -0
- package/LICENSE +21 -0
- package/README.md +618 -0
- package/dist/client/a2a-client.d.ts +99 -0
- package/dist/client/a2a-client.d.ts.map +1 -0
- package/dist/client/a2a-client.js +171 -0
- package/dist/client/a2a-client.js.map +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/interfaces/client.d.ts +19 -0
- package/dist/client/interfaces/client.d.ts.map +1 -0
- package/dist/client/interfaces/client.js +2 -0
- package/dist/client/interfaces/client.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a-server.d.ts +144 -0
- package/dist/server/a2a-server.d.ts.map +1 -0
- package/dist/server/a2a-server.js +384 -0
- package/dist/server/a2a-server.js.map +1 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +9 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/interfaces/context.d.ts +41 -0
- package/dist/server/interfaces/context.d.ts.map +1 -0
- package/dist/server/interfaces/context.js +2 -0
- package/dist/server/interfaces/context.js.map +1 -0
- package/dist/server/interfaces/params.d.ts +72 -0
- package/dist/server/interfaces/params.d.ts.map +1 -0
- package/dist/server/interfaces/params.js +3 -0
- package/dist/server/interfaces/params.js.map +1 -0
- package/dist/server/interfaces/server.d.ts +34 -0
- package/dist/server/interfaces/server.d.ts.map +1 -0
- package/dist/server/interfaces/server.js +2 -0
- package/dist/server/interfaces/server.js.map +1 -0
- package/dist/server/interfaces/store.d.ts +30 -0
- package/dist/server/interfaces/store.d.ts.map +1 -0
- package/dist/server/interfaces/store.js +2 -0
- package/dist/server/interfaces/store.js.map +1 -0
- package/dist/server/lib/express-server.d.ts +13 -0
- package/dist/server/lib/express-server.d.ts.map +1 -0
- package/dist/server/lib/express-server.js +51 -0
- package/dist/server/lib/express-server.js.map +1 -0
- package/dist/server/lib/json-middleware.d.ts +19 -0
- package/dist/server/lib/json-middleware.d.ts.map +1 -0
- package/dist/server/lib/json-middleware.js +180 -0
- package/dist/server/lib/json-middleware.js.map +1 -0
- package/dist/server/lib/state.d.ts +28 -0
- package/dist/server/lib/state.d.ts.map +1 -0
- package/dist/server/lib/state.js +108 -0
- package/dist/server/lib/state.js.map +1 -0
- package/dist/server/lib/storage/file.d.ts +62 -0
- package/dist/server/lib/storage/file.d.ts.map +1 -0
- package/dist/server/lib/storage/file.js +148 -0
- package/dist/server/lib/storage/file.js.map +1 -0
- package/dist/server/lib/storage/memory.d.ts +21 -0
- package/dist/server/lib/storage/memory.d.ts.map +1 -0
- package/dist/server/lib/storage/memory.js +40 -0
- package/dist/server/lib/storage/memory.js.map +1 -0
- package/dist/transport/index.d.ts +5 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/rpc/parser.d.ts +12 -0
- package/dist/transport/rpc/parser.d.ts.map +1 -0
- package/dist/transport/rpc/parser.js +37 -0
- package/dist/transport/rpc/parser.js.map +1 -0
- package/dist/transport/rpc/rpc-client.d.ts +77 -0
- package/dist/transport/rpc/rpc-client.d.ts.map +1 -0
- package/dist/transport/rpc/rpc-client.js +182 -0
- package/dist/transport/rpc/rpc-client.js.map +1 -0
- package/dist/transport/streaming/event-stream.d.ts +22 -0
- package/dist/transport/streaming/event-stream.d.ts.map +1 -0
- package/dist/transport/streaming/event-stream.js +79 -0
- package/dist/transport/streaming/event-stream.js.map +1 -0
- package/dist/transport/streaming/stream.d.ts +42 -0
- package/dist/transport/streaming/stream.d.ts.map +1 -0
- package/dist/transport/streaming/stream.js +128 -0
- package/dist/transport/streaming/stream.js.map +1 -0
- package/dist/types/extended-schema.d.ts +52 -0
- package/dist/types/extended-schema.d.ts.map +1 -0
- package/dist/types/extended-schema.js +7 -0
- package/dist/types/extended-schema.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/schema.d.ts +729 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +23 -0
- package/dist/types/schema.js.map +1 -0
- package/dist/utils/common/constants.d.ts +6 -0
- package/dist/utils/common/constants.d.ts.map +1 -0
- package/dist/utils/common/constants.js +28 -0
- package/dist/utils/common/constants.js.map +1 -0
- package/dist/utils/common/errors.d.ts +26 -0
- package/dist/utils/common/errors.d.ts.map +1 -0
- package/dist/utils/common/errors.js +59 -0
- package/dist/utils/common/errors.js.map +1 -0
- package/dist/utils/common/utils.d.ts +30 -0
- package/dist/utils/common/utils.d.ts.map +1 -0
- package/dist/utils/common/utils.js +67 -0
- package/dist/utils/common/utils.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logging/log.d.ts +30 -0
- package/dist/utils/logging/log.d.ts.map +1 -0
- package/dist/utils/logging/log.js +58 -0
- package/dist/utils/logging/log.js.map +1 -0
- package/dist/utils/logging/logger.d.ts +16 -0
- package/dist/utils/logging/logger.d.ts.map +1 -0
- package/dist/utils/logging/logger.js +38 -0
- package/dist/utils/logging/logger.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../../src/server/lib/storage/file.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;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|
|
|
1
|
+
import { TaskAndHistory, TaskStore } from "../../interfaces/store.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory implementation of the TaskStore interface.
|
|
4
|
+
* Stores tasks and their history in memory. Not persisted between server restarts.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InMemoryTaskStore implements TaskStore {
|
|
7
|
+
private store;
|
|
8
|
+
/**
|
|
9
|
+
* Loads a task and its history by task ID.
|
|
10
|
+
* @param taskId The ID of the task to load.
|
|
11
|
+
* @returns A promise resolving to the task and history, or null if not found.
|
|
12
|
+
*/
|
|
13
|
+
load(taskId: string): Promise<TaskAndHistory | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Saves a task and its history.
|
|
16
|
+
* @param data The task and history to save.
|
|
17
|
+
* @returns A promise that resolves when the save is complete.
|
|
18
|
+
*/
|
|
19
|
+
save(data: TaskAndHistory): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/server/lib/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtE;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IACjD,OAAO,CAAC,KAAK,CAA0C;IAEvD;;;;OAIG;IACG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAa1D;;;;OAIG;IACG,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAShD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { logDebug } from "../../../utils/logging/log.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory implementation of the TaskStore interface.
|
|
4
|
+
* Stores tasks and their history in memory. Not persisted between server restarts.
|
|
5
|
+
*/
|
|
6
|
+
export class InMemoryTaskStore {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.store = new Map();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Loads a task and its history by task ID.
|
|
12
|
+
* @param taskId The ID of the task to load.
|
|
13
|
+
* @returns A promise resolving to the task and history, or null if not found.
|
|
14
|
+
*/
|
|
15
|
+
async load(taskId) {
|
|
16
|
+
logDebug("InMemoryTaskStore", `Loading task: ${taskId}`);
|
|
17
|
+
const entry = this.store.get(taskId);
|
|
18
|
+
// Return copies to prevent external mutation
|
|
19
|
+
return entry
|
|
20
|
+
? {
|
|
21
|
+
task: { ...entry.task },
|
|
22
|
+
history: [...entry.history],
|
|
23
|
+
}
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Saves a task and its history.
|
|
28
|
+
* @param data The task and history to save.
|
|
29
|
+
* @returns A promise that resolves when the save is complete.
|
|
30
|
+
*/
|
|
31
|
+
async save(data) {
|
|
32
|
+
logDebug("InMemoryTaskStore", `Saving task: ${data.task.id}`);
|
|
33
|
+
// Store copies to prevent internal mutation if caller reuses objects
|
|
34
|
+
this.store.set(data.task.id, {
|
|
35
|
+
task: { ...data.task },
|
|
36
|
+
history: [...data.history],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../../src/server/lib/storage/memory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACU,UAAK,GAAgC,IAAI,GAAG,EAAE,CAAC;IAkCzD,CAAC;IAhCC;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,MAAc;QACvB,QAAQ,CAAC,mBAAmB,EAAE,iBAAiB,MAAM,EAAE,CAAC,CAAC;QACzD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAErC,6CAA6C;QAC7C,OAAO,KAAK;YACV,CAAC,CAAC;gBACE,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE;gBACvB,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;aAC5B;YACH,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,IAAoB;QAC7B,QAAQ,CAAC,mBAAmB,EAAE,gBAAgB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QAE9D,qEAAqE;QACrE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;YAC3B,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE;YACtB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JSONRPCResponse } from "../../types/extended-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses a JSON-RPC response string and validates its structure.
|
|
4
|
+
* If the response contains an error, it is thrown as an A2AError.
|
|
5
|
+
* If the response contains neither a result nor an error, a validation error is thrown.
|
|
6
|
+
*
|
|
7
|
+
* @param data Response data as string
|
|
8
|
+
* @returns The parsed and validated response object
|
|
9
|
+
* @throws A2AError if the response contains an error or is invalid
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseResponse<Res extends JSONRPCResponse>(data: string): Res;
|
|
12
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/transport/rpc/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGjE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,GAAG,SAAS,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAkC5E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SystemError, PARSE_ERROR } from "../../utils/common/errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses a JSON-RPC response string and validates its structure.
|
|
4
|
+
* If the response contains an error, it is thrown as an A2AError.
|
|
5
|
+
* If the response contains neither a result nor an error, a validation error is thrown.
|
|
6
|
+
*
|
|
7
|
+
* @param data Response data as string
|
|
8
|
+
* @returns The parsed and validated response object
|
|
9
|
+
* @throws A2AError if the response contains an error or is invalid
|
|
10
|
+
*/
|
|
11
|
+
export function parseResponse(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
throw PARSE_ERROR();
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(data);
|
|
17
|
+
if (parsed.error) {
|
|
18
|
+
throw new SystemError(parsed.error.message, parsed.error.code, parsed.error.data);
|
|
19
|
+
}
|
|
20
|
+
if (typeof parsed !== "object" ||
|
|
21
|
+
parsed === null ||
|
|
22
|
+
parsed.jsonrpc !== "2.0") {
|
|
23
|
+
throw PARSE_ERROR();
|
|
24
|
+
}
|
|
25
|
+
if (parsed.result === undefined) {
|
|
26
|
+
throw PARSE_ERROR();
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof SystemError) {
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
throw PARSE_ERROR(error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/transport/rpc/parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAA8B,IAAY;IACrE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,WAAW,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAQ,CAAC;QACvC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,IAAI,WAAW,CACnB,MAAM,CAAC,KAAK,CAAC,OAAO,EACpB,MAAM,CAAC,KAAK,CAAC,IAAI,EACjB,MAAM,CAAC,KAAK,CAAC,IAAI,CAClB,CAAC;QACJ,CAAC;QAED,IACE,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,KAAK,IAAI;YACf,MAAM,CAAC,OAAO,KAAK,KAAK,EACxB,CAAC;YACD,MAAM,WAAW,EAAE,CAAC;QACtB,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,WAAW,EAAE,CAAC;QACtB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { JSONRPCRequest, JSONRPCResponse, A2ARequest } from "../../types/extended-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a JSON-RPC request body with the specified method and parameters.
|
|
4
|
+
*, ErrorCodeParseError
|
|
5
|
+
* @param method The JSON-RPC method name
|
|
6
|
+
* @param params The parameters for the method
|
|
7
|
+
* @param requestId Optional request ID (generates a UUID v4 if not provided)
|
|
8
|
+
* @returns A properly formatted JSON-RPC request object
|
|
9
|
+
*/
|
|
10
|
+
export declare function createJsonRpcRequest<Req extends A2ARequest>(method: Req["method"], params: Req["params"], requestId?: string | number): JSONRPCRequest;
|
|
11
|
+
/**
|
|
12
|
+
* Sends a JSON-RPC request to the specified endpoint.
|
|
13
|
+
*
|
|
14
|
+
* @param baseUrl The API endpoint URL
|
|
15
|
+
* @param method The JSON-RPC method name
|
|
16
|
+
* @param params The parameters for the method
|
|
17
|
+
* @param headers Custom headers to include in the request
|
|
18
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
19
|
+
* @returns A Promise resolving to the fetch Response object
|
|
20
|
+
* @throws RpcError if there's a network error
|
|
21
|
+
*/
|
|
22
|
+
export declare function sendJsonRpcRequest<Req extends A2ARequest>(baseUrl: URL, method: Req["method"], params: Req["params"], headers?: Record<string, string>, acceptHeader?: "application/json" | "text/event-stream"): Promise<Response>;
|
|
23
|
+
/**
|
|
24
|
+
* Sends a GET request to the specified endpoint.
|
|
25
|
+
* This is used for non-JSON-RPC calls like agent card retrieval.
|
|
26
|
+
*
|
|
27
|
+
* @param url The endpoint URL
|
|
28
|
+
* @param headers Custom headers to include in the request
|
|
29
|
+
* @returns A Promise resolving to the fetch Response object
|
|
30
|
+
* @throws RpcError if there's a network error
|
|
31
|
+
*/
|
|
32
|
+
export declare function sendGetRequest(url: URL, headers?: Record<string, string>): Promise<Response>;
|
|
33
|
+
/**
|
|
34
|
+
* Processes a standard JSON-RPC response (non-streaming).
|
|
35
|
+
* Parses the response, validates it, and returns the result payload.
|
|
36
|
+
*
|
|
37
|
+
* @param response The fetch Response object
|
|
38
|
+
* @param expectedMethod Optional method name for logging purposes
|
|
39
|
+
* @returns A promise resolving to the result payload
|
|
40
|
+
* @throws RpcError if there's an error in the response
|
|
41
|
+
*/
|
|
42
|
+
export declare function handleJsonRpcResponse<Res extends JSONRPCResponse>(response: Response, expectedMethod?: string): Promise<NonNullable<Res["result"]>>;
|
|
43
|
+
/**
|
|
44
|
+
* Processes a JSON response from a regular GET request.
|
|
45
|
+
* Handles error checking and returns the parsed JSON.
|
|
46
|
+
*
|
|
47
|
+
* @param response The fetch Response object
|
|
48
|
+
* @param endpoint Optional endpoint description for logging purposes
|
|
49
|
+
* @returns A promise resolving to the parsed JSON
|
|
50
|
+
* @throws RpcError if there's a response error
|
|
51
|
+
*/
|
|
52
|
+
export declare function handleJsonResponse<T>(response: Response, endpoint?: string): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Sends a JSON-RPC request and processes the response in a single operation.
|
|
55
|
+
* This combines sendJsonRpcRequest and handleJsonRpcResponse into one call.
|
|
56
|
+
*
|
|
57
|
+
* @param baseUrl The API endpoint URL
|
|
58
|
+
* @param method The JSON-RPC method name
|
|
59
|
+
* @param params The parameters for the method
|
|
60
|
+
* @param headers Custom headers to include in the request
|
|
61
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
62
|
+
* @returns A Promise resolving to the result payload
|
|
63
|
+
* @throws RpcError if there's a network error or error in the response
|
|
64
|
+
*/
|
|
65
|
+
export declare function executeJsonRpcRequest<Req extends A2ARequest, Res extends JSONRPCResponse>(baseUrl: URL, method: Req["method"], params: Req["params"], headers?: Record<string, string>, acceptHeader?: "application/json" | "text/event-stream"): Promise<NonNullable<Res["result"]>>;
|
|
66
|
+
/**
|
|
67
|
+
* Sends a GET request and processes the JSON response.
|
|
68
|
+
* Helper for non-RPC REST endpoints.
|
|
69
|
+
*
|
|
70
|
+
* @param url The endpoint URL
|
|
71
|
+
* @param headers Custom headers to include in the request
|
|
72
|
+
* @param endpoint Optional endpoint description for logging
|
|
73
|
+
* @returns A Promise resolving to the parsed JSON
|
|
74
|
+
* @throws RpcError if there's a network error or error in the response
|
|
75
|
+
*/
|
|
76
|
+
export declare function executeGetRequest<T>(url: URL, headers?: Record<string, string>, endpoint?: string): Promise<T>;
|
|
77
|
+
//# sourceMappingURL=rpc-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/transport/rpc/rpc-client.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,UAAU,EACX,MAAM,gCAAgC,CAAC;AAIxC;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,UAAU,EACzD,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,SAAS,GAAE,MAAM,GAAG,MAAiB,GACpC,cAAc,CAOhB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,SAAS,UAAU,EAC7D,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,YAAY,GAAE,kBAAkB,GAAG,mBAAwC,GAC1E,OAAO,CAAC,QAAQ,CAAC,CAsBnB;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,OAAO,CAAC,QAAQ,CAAC,CAiBnB;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,SAAS,eAAe,EACrE,QAAQ,EAAE,QAAQ,EAClB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CA+CrC;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CA2BZ;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,SAAS,UAAU,EACtB,GAAG,SAAS,eAAe,EAE3B,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,YAAY,GAAE,kBAAkB,GAAG,mBAAwC,GAC1E,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAUrC;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAGZ"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP JSON-RPC client utilities.
|
|
3
|
+
* Handles the common pattern of sending JSON-RPC requests and processing responses.
|
|
4
|
+
*/
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
import { SystemError, INTERNAL_ERROR, PARSE_ERROR, } from "../../utils/common/errors.js";
|
|
7
|
+
import { parseResponse } from "./parser.js";
|
|
8
|
+
import { logError, logWarn } from "../../utils/logging/log.js";
|
|
9
|
+
/**
|
|
10
|
+
* Creates a JSON-RPC request body with the specified method and parameters.
|
|
11
|
+
*, ErrorCodeParseError
|
|
12
|
+
* @param method The JSON-RPC method name
|
|
13
|
+
* @param params The parameters for the method
|
|
14
|
+
* @param requestId Optional request ID (generates a UUID v4 if not provided)
|
|
15
|
+
* @returns A properly formatted JSON-RPC request object
|
|
16
|
+
*/
|
|
17
|
+
export function createJsonRpcRequest(method, params, requestId = uuidv4()) {
|
|
18
|
+
return {
|
|
19
|
+
jsonrpc: "2.0",
|
|
20
|
+
id: requestId,
|
|
21
|
+
method,
|
|
22
|
+
params,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sends a JSON-RPC request to the specified endpoint.
|
|
27
|
+
*
|
|
28
|
+
* @param baseUrl The API endpoint URL
|
|
29
|
+
* @param method The JSON-RPC method name
|
|
30
|
+
* @param params The parameters for the method
|
|
31
|
+
* @param headers Custom headers to include in the request
|
|
32
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
33
|
+
* @returns A Promise resolving to the fetch Response object
|
|
34
|
+
* @throws RpcError if there's a network error
|
|
35
|
+
*/
|
|
36
|
+
export async function sendJsonRpcRequest(baseUrl, method, params, headers = {}, acceptHeader = "application/json") {
|
|
37
|
+
const requestBody = createJsonRpcRequest(method, params);
|
|
38
|
+
try {
|
|
39
|
+
return await fetch(baseUrl, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
Accept: acceptHeader,
|
|
44
|
+
...headers,
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify(requestBody),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (networkError) {
|
|
50
|
+
logError("SendJsonRpcRequest", "Network error during RPC call:", networkError);
|
|
51
|
+
// Wrap network errors into a standard error format
|
|
52
|
+
throw INTERNAL_ERROR(networkError);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sends a GET request to the specified endpoint.
|
|
57
|
+
* This is used for non-JSON-RPC calls like agent card retrieval.
|
|
58
|
+
*
|
|
59
|
+
* @param url The endpoint URL
|
|
60
|
+
* @param headers Custom headers to include in the request
|
|
61
|
+
* @returns A Promise resolving to the fetch Response object
|
|
62
|
+
* @throws RpcError if there's a network error
|
|
63
|
+
*/
|
|
64
|
+
export async function sendGetRequest(url, headers = {}) {
|
|
65
|
+
try {
|
|
66
|
+
return await fetch(url, {
|
|
67
|
+
method: "GET",
|
|
68
|
+
headers: {
|
|
69
|
+
Accept: "application/json",
|
|
70
|
+
...headers,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (networkError) {
|
|
75
|
+
logError("SendGetRequest", "Network error during GET request:", networkError);
|
|
76
|
+
throw INTERNAL_ERROR(networkError);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Processes a standard JSON-RPC response (non-streaming).
|
|
81
|
+
* Parses the response, validates it, and returns the result payload.
|
|
82
|
+
*
|
|
83
|
+
* @param response The fetch Response object
|
|
84
|
+
* @param expectedMethod Optional method name for logging purposes
|
|
85
|
+
* @returns A promise resolving to the result payload
|
|
86
|
+
* @throws RpcError if there's an error in the response
|
|
87
|
+
*/
|
|
88
|
+
export async function handleJsonRpcResponse(response, expectedMethod) {
|
|
89
|
+
let responseBody = null;
|
|
90
|
+
try {
|
|
91
|
+
responseBody = await response.text();
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
try {
|
|
94
|
+
// Try to parse error as JSON-RPC
|
|
95
|
+
parseResponse(responseBody);
|
|
96
|
+
// If we get here, it means there was no error in the response
|
|
97
|
+
// But the HTTP status was not OK, so we throw a generic error
|
|
98
|
+
}
|
|
99
|
+
catch (parseError) {
|
|
100
|
+
logWarn("handleJsonRpcResponse", "Error parsing JSON-RPC response:", parseError);
|
|
101
|
+
}
|
|
102
|
+
// Throw a generic HTTP error if we couldn't extract an RPC error
|
|
103
|
+
throw new Error(`HTTP error ${response.status}: ${response.statusText}${responseBody ? ` - ${responseBody}` : ""}`);
|
|
104
|
+
}
|
|
105
|
+
// Parse and validate the response
|
|
106
|
+
// If it has an error, parseResponse will throw
|
|
107
|
+
// If it doesn't have a result, parseResponse will also throw
|
|
108
|
+
const jsonResponse = parseResponse(responseBody);
|
|
109
|
+
// At this point, we know we have a valid result
|
|
110
|
+
// NonNullable is used in the return type to ensure TypeScript knows this
|
|
111
|
+
return jsonResponse.result;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
logError("handleJsonRpcResponse", `Error processing response [${expectedMethod}]:`, error);
|
|
115
|
+
// Re-throw RpcError instances directly, wrap others
|
|
116
|
+
if (error instanceof SystemError) {
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw INTERNAL_ERROR(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Processes a JSON response from a regular GET request.
|
|
126
|
+
* Handles error checking and returns the parsed JSON.
|
|
127
|
+
*
|
|
128
|
+
* @param response The fetch Response object
|
|
129
|
+
* @param endpoint Optional endpoint description for logging purposes
|
|
130
|
+
* @returns A promise resolving to the parsed JSON
|
|
131
|
+
* @throws RpcError if there's a response error
|
|
132
|
+
*/
|
|
133
|
+
export async function handleJsonResponse(response, endpoint) {
|
|
134
|
+
let responseBody = null;
|
|
135
|
+
try {
|
|
136
|
+
responseBody = await response.text();
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
throw new Error(`HTTP error ${response.status}: ${response.statusText}${responseBody ? ` - ${responseBody}` : ""}`);
|
|
139
|
+
}
|
|
140
|
+
return JSON.parse(responseBody);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
logError("handleJsonResponse", `Error processing response for ${endpoint || "unknown endpoint"}:`, error);
|
|
144
|
+
if (error instanceof SystemError) {
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw PARSE_ERROR(error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Sends a JSON-RPC request and processes the response in a single operation.
|
|
154
|
+
* This combines sendJsonRpcRequest and handleJsonRpcResponse into one call.
|
|
155
|
+
*
|
|
156
|
+
* @param baseUrl The API endpoint URL
|
|
157
|
+
* @param method The JSON-RPC method name
|
|
158
|
+
* @param params The parameters for the method
|
|
159
|
+
* @param headers Custom headers to include in the request
|
|
160
|
+
* @param acceptHeader The desired Accept header ('application/json' or 'text/event-stream')
|
|
161
|
+
* @returns A Promise resolving to the result payload
|
|
162
|
+
* @throws RpcError if there's a network error or error in the response
|
|
163
|
+
*/
|
|
164
|
+
export async function executeJsonRpcRequest(baseUrl, method, params, headers = {}, acceptHeader = "application/json") {
|
|
165
|
+
const response = await sendJsonRpcRequest(baseUrl, method, params, headers, acceptHeader);
|
|
166
|
+
return handleJsonRpcResponse(response, method);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Sends a GET request and processes the JSON response.
|
|
170
|
+
* Helper for non-RPC REST endpoints.
|
|
171
|
+
*
|
|
172
|
+
* @param url The endpoint URL
|
|
173
|
+
* @param headers Custom headers to include in the request
|
|
174
|
+
* @param endpoint Optional endpoint description for logging
|
|
175
|
+
* @returns A Promise resolving to the parsed JSON
|
|
176
|
+
* @throws RpcError if there's a network error or error in the response
|
|
177
|
+
*/
|
|
178
|
+
export async function executeGetRequest(url, headers = {}, endpoint) {
|
|
179
|
+
const response = await sendGetRequest(url, headers);
|
|
180
|
+
return handleJsonResponse(response, endpoint);
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=rpc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/transport/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;A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AAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAQ,EACR,UAAkC,EAAE,EACpC,QAAiB;IAEjB,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACpD,OAAO,kBAAkB,CAAI,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { JSONRPCResponse, A2ARequest } from "../../types/extended-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an async generator for processing task events from an SSE stream
|
|
4
|
+
*
|
|
5
|
+
* @template T The type of task event to process (TaskStatusUpdateEvent or TaskArtifactUpdateEvent)
|
|
6
|
+
* @param response The fetch Response object containing the event stream
|
|
7
|
+
* @returns An async generator yielding the specified type of task events from StreamingResponse
|
|
8
|
+
*/
|
|
9
|
+
export declare function handleEventStream<StreamRes extends JSONRPCResponse>(response: Response): AsyncGenerator<NonNullable<StreamRes["result"]>>;
|
|
10
|
+
/**
|
|
11
|
+
* Executes a streaming JSON-RPC request and yields events as they arrive
|
|
12
|
+
*
|
|
13
|
+
* @template Req The type of request being made
|
|
14
|
+
* @template StreamRes The type of streaming response expected
|
|
15
|
+
* @param baseUrl The base URL for the API
|
|
16
|
+
* @param method The JSON-RPC method to call
|
|
17
|
+
* @param params The parameters for the method
|
|
18
|
+
* @param customHeaders Any custom headers to include in the request
|
|
19
|
+
* @returns An AsyncIterable yielding events from the stream
|
|
20
|
+
*/
|
|
21
|
+
export declare function executeStreamEvents<Req extends A2ARequest, StreamRes extends JSONRPCResponse>(baseUrl: URL, method: Req["method"], params: Req["params"], customHeaders: Record<string, string>): AsyncIterable<NonNullable<StreamRes["result"]>>;
|
|
22
|
+
//# sourceMappingURL=event-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.d.ts","sourceRoot":"","sources":["../../../src/transport/streaming/event-stream.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACX,MAAM,gCAAgC,CAAC;AAIxC;;;;;;GAMG;AACH,wBAAuB,iBAAiB,CAAC,SAAS,SAAS,eAAe,EACxE,QAAQ,EAAE,QAAQ,GACjB,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAqDlD;AAED;;;;;;;;;;GAUG;AACH,wBAAuB,mBAAmB,CACxC,GAAG,SAAS,UAAU,EACtB,SAAS,SAAS,eAAe,EAEjC,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,EACrB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAejD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event stream utilities for handling Server-Sent Events (SSE).
|
|
3
|
+
*/
|
|
4
|
+
import { parseResponse } from "../rpc/parser.js";
|
|
5
|
+
import { createParser } from "eventsource-parser";
|
|
6
|
+
import { sendJsonRpcRequest } from "../rpc/rpc-client.js";
|
|
7
|
+
import { logError, logWarn, logDebug } from "../../utils/logging/log.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates an async generator for processing task events from an SSE stream
|
|
10
|
+
*
|
|
11
|
+
* @template T The type of task event to process (TaskStatusUpdateEvent or TaskArtifactUpdateEvent)
|
|
12
|
+
* @param response The fetch Response object containing the event stream
|
|
13
|
+
* @returns An async generator yielding the specified type of task events from StreamingResponse
|
|
14
|
+
*/
|
|
15
|
+
export async function* handleEventStream(response) {
|
|
16
|
+
if (!response.ok || !response.body) {
|
|
17
|
+
let errorText = null;
|
|
18
|
+
try {
|
|
19
|
+
errorText = await response.text();
|
|
20
|
+
}
|
|
21
|
+
catch (_) { }
|
|
22
|
+
logError("handleEventStream", `HTTP error [${response.status}:${response.statusText}] - ${errorText}`, new Error(`HTTP error [${response.status}:${response.statusText}] - ${errorText}`));
|
|
23
|
+
throw new Error(`HTTP error [${response.status}:${response.statusText}] - ${errorText}`);
|
|
24
|
+
}
|
|
25
|
+
// Use eventsource-parser to process the SSE stream
|
|
26
|
+
const reader = response.body.getReader();
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
const events = [];
|
|
29
|
+
const parser = createParser((event) => {
|
|
30
|
+
if (event.type === "event" && event.data) {
|
|
31
|
+
try {
|
|
32
|
+
const parsedData = parseResponse(event.data);
|
|
33
|
+
const eventResult = parsedData.result;
|
|
34
|
+
if (eventResult) {
|
|
35
|
+
events.push(eventResult);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
logWarn("handleEventStream", "Failed to parse SSE data", parsedData);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
logWarn("handleEventStream", "Failed to parse SSE data", e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
while (true) {
|
|
48
|
+
const { done, value } = await reader.read();
|
|
49
|
+
if (done)
|
|
50
|
+
break;
|
|
51
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
52
|
+
parser.feed(chunk);
|
|
53
|
+
while (events.length > 0) {
|
|
54
|
+
yield events.shift();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
reader.releaseLock();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Executes a streaming JSON-RPC request and yields events as they arrive
|
|
64
|
+
*
|
|
65
|
+
* @template Req The type of request being made
|
|
66
|
+
* @template StreamRes The type of streaming response expected
|
|
67
|
+
* @param baseUrl The base URL for the API
|
|
68
|
+
* @param method The JSON-RPC method to call
|
|
69
|
+
* @param params The parameters for the method
|
|
70
|
+
* @param customHeaders Any custom headers to include in the request
|
|
71
|
+
* @returns An AsyncIterable yielding events from the stream
|
|
72
|
+
*/
|
|
73
|
+
export async function* executeStreamEvents(baseUrl, method, params, customHeaders) {
|
|
74
|
+
logDebug("executeStreamEvents", `Sending streaming request to: ${baseUrl.toString()}, method: ${method}`);
|
|
75
|
+
const responsePromise = sendJsonRpcRequest(baseUrl, method, params, customHeaders, "text/event-stream");
|
|
76
|
+
const response = await responsePromise;
|
|
77
|
+
yield* handleEventStream(response);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=event-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.js","sourceRoot":"","sources":["../../../src/transport/streaming/event-stream.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,iBAAiB,CACtC,QAAkB;IAElB,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,SAAS,GAAkB,IAAI,CAAC;QACpC,IAAI,CAAC;YACH,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;QACd,QAAQ,CACN,mBAAmB,EACnB,eAAe,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,OAAO,SAAS,EAAE,EACvE,IAAI,KAAK,CACP,eAAe,QAAQ,CAAC,MAAM,IAAI,QAAQ,CA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I,CAAC,KAAK,CAAC,CAAC;YAEnB,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACzB,MAAM,MAAM,CAAC,KAAK,EAAG,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CAIxC,OAAY,EACZ,MAAqB,EACrB,MAAqB,EACrB,aAAqC;IAErC,QAAQ,CACN,qBAAqB,EACrB,iCAAiC,OAAO,CAAC,QAAQ,EAAE,aAAa,MAAM,EAAE,CACzE,CAAC;IAEF,MAAM,eAAe,GAAG,kBAAkB,CACxC,OAAO,EACP,MAAM,EACN,MAAM,EACN,aAAa,EACb,mBAAmB,CACpB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC;IACvC,KAAK,CAAC,CAAC,iBAAiB,CAAY,QAAQ,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Response } from "express";
|
|
2
|
+
import { JSONRPCError } from "../../types/schema.js";
|
|
3
|
+
import { TaskEvent } from "../../types/extended-schema.js";
|
|
4
|
+
import { TaskStore, TaskAndHistory } from "../../server/interfaces/store.js";
|
|
5
|
+
import { TaskContext } from "../../server/interfaces/context.js";
|
|
6
|
+
import { TaskHandler } from "../../server/interfaces/context.js";
|
|
7
|
+
/**
|
|
8
|
+
* Sets up a Server-Sent Events stream with appropriate headers
|
|
9
|
+
* and initializes tracking for the stream.
|
|
10
|
+
*
|
|
11
|
+
* @param res The Express Response object
|
|
12
|
+
* @param taskId The task ID to associate with this stream
|
|
13
|
+
* @param reqId The request ID for acknowledgment
|
|
14
|
+
* @param initialStatus Optional initial status to send
|
|
15
|
+
* @param addStreamMethod Function to add stream to tracking
|
|
16
|
+
* @param sendSseMethod Function to send SSE events
|
|
17
|
+
*/
|
|
18
|
+
export declare function setupSseStream(res: Response, taskId: string, initialStatus: TaskEvent, addStreamMethod?: (taskId: string, res: Response) => void): void;
|
|
19
|
+
/**
|
|
20
|
+
* Sends a Server-Sent Event with task data.
|
|
21
|
+
* @param res The Express Response object
|
|
22
|
+
* @param reqId The request ID
|
|
23
|
+
* @param eventData The event data to send
|
|
24
|
+
*/
|
|
25
|
+
export declare function sendSSEEvent(res: Response, update: TaskEvent): void;
|
|
26
|
+
/**
|
|
27
|
+
* Sends a Server-Sent Event with error data.
|
|
28
|
+
* @param res The Express Response object
|
|
29
|
+
* @param reqId The request ID
|
|
30
|
+
* @param error The error to send
|
|
31
|
+
*/
|
|
32
|
+
export declare function sendSSEError(res: Response, error: JSONRPCError<any, any>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Processes a task stream, handling generator yields and sending SSE events.
|
|
35
|
+
* @param req The request object
|
|
36
|
+
* @param res The response object
|
|
37
|
+
* @param taskId The task ID
|
|
38
|
+
* @param context The task context
|
|
39
|
+
* @param initialData The initial task data
|
|
40
|
+
*/
|
|
41
|
+
export declare function processTaskStream(taskStore: TaskStore, taskHandler: TaskHandler, res: Response, taskId: string, context: TaskContext, initialData: TaskAndHistory, onCancel: (data: TaskAndHistory, res: Response) => Promise<void>, onEnd: (taskId: string, res: Response) => Promise<void>): Promise<void>;
|
|
42
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/transport/streaming/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAY,YAAY,EAAmB,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MA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