@mitralab.io/sdk-core 0.2.9-beta.0 → 0.2.9-beta.1
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 +12 -0
- package/README.md +15 -11
- package/contracts/README.md +4 -0
- package/contracts/manifest.json +6 -1
- package/contracts/v0.2.9-beta.1/sdk-parity.json +2902 -0
- package/dist/index.cjs +18 -9
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +18 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3332,7 +3332,13 @@ function errorCodeOf(body) {
|
|
|
3332
3332
|
return typeof code === "string" ? code : void 0;
|
|
3333
3333
|
}
|
|
3334
3334
|
function withBody(response, body) {
|
|
3335
|
-
return {
|
|
3335
|
+
return {
|
|
3336
|
+
ok: response.ok,
|
|
3337
|
+
status: response.status,
|
|
3338
|
+
headers: response.headers,
|
|
3339
|
+
body: response.body,
|
|
3340
|
+
json: async () => body
|
|
3341
|
+
};
|
|
3336
3342
|
}
|
|
3337
3343
|
var AgentDirectChannel = class {
|
|
3338
3344
|
constructor(tasks, fallback, options = {}) {
|
|
@@ -3697,17 +3703,14 @@ var AgentDirectChannel = class {
|
|
|
3697
3703
|
admission.settle(true);
|
|
3698
3704
|
return;
|
|
3699
3705
|
}
|
|
3700
|
-
if (response.status === 504) {
|
|
3701
|
-
admission.fail(new Error("The Agent box got no admission for the turn (504)."));
|
|
3702
|
-
return;
|
|
3703
|
-
}
|
|
3704
3706
|
const body = asObject(await response.json().catch(() => null));
|
|
3705
3707
|
const code = errorCodeOf(body);
|
|
3706
3708
|
if (isGrantRejection(response.status) && code === void 0) {
|
|
3707
3709
|
admission.fail(new GrantRejectedError(response.status));
|
|
3708
3710
|
return;
|
|
3709
3711
|
}
|
|
3710
|
-
const
|
|
3712
|
+
const fallback = response.status === 504 ? "The Agent box got no admission for the turn (504)." : `The Agent box refused the message (${response.status}).`;
|
|
3713
|
+
const message = typeof body?.message === "string" ? body.message : fallback;
|
|
3711
3714
|
admission.fail(new AgentTaskTurnError(message, code));
|
|
3712
3715
|
},
|
|
3713
3716
|
(error) => {
|
|
@@ -3753,6 +3756,11 @@ var AgentDirectChannel = class {
|
|
|
3753
3756
|
}
|
|
3754
3757
|
throw new Error(`Agent box event stream failed (${response.status}).`);
|
|
3755
3758
|
}
|
|
3759
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
3760
|
+
if (!/^text\/event-stream\b/i.test(contentType)) {
|
|
3761
|
+
close();
|
|
3762
|
+
throw new HttpUnsupportedError(contentType || "no content type");
|
|
3763
|
+
}
|
|
3756
3764
|
const lost = (error) => {
|
|
3757
3765
|
if (intentionalClose) return;
|
|
3758
3766
|
close();
|
|
@@ -3925,10 +3933,10 @@ function createAgentTaskSessionManager(options) {
|
|
|
3925
3933
|
const current = sessions.get(requested.taskId);
|
|
3926
3934
|
if (current && current.status !== "closed") return current;
|
|
3927
3935
|
}
|
|
3928
|
-
const sessionOptions = "create" in requested && !requested.runtime && channel.canDial(requested.transport) ? { ...requested, runtime: "T3" } : requested;
|
|
3936
|
+
const sessionOptions = "create" in requested && requested.agentId && !requested.runtime && channel.canDial(requested.transport) ? { ...requested, runtime: "T3" } : requested;
|
|
3929
3937
|
const session = new CoreAgentTaskSession(sessionOptions, {
|
|
3930
3938
|
tasks: options.tasks,
|
|
3931
|
-
eventSource:
|
|
3939
|
+
eventSource: options.eventSource,
|
|
3932
3940
|
channel,
|
|
3933
3941
|
onTaskId: (taskId, value) => sessions.set(taskId, value),
|
|
3934
3942
|
onClose: (taskId, value) => {
|
|
@@ -4209,7 +4217,8 @@ var CoreAgentTaskSession = class {
|
|
|
4209
4217
|
if (!this._taskId) return Promise.reject(new Error("Agent task has not been created."));
|
|
4210
4218
|
const abort = new AbortController();
|
|
4211
4219
|
this.connectionAbort = abort;
|
|
4212
|
-
this.
|
|
4220
|
+
const source = this._task?.agentId ? this.dependencies.channel : this.dependencies.eventSource;
|
|
4221
|
+
this.connectionPromise = source.open(
|
|
4213
4222
|
this._taskId,
|
|
4214
4223
|
{
|
|
4215
4224
|
onEvent: (event) => this.handleEvent(event),
|
package/dist/index.d.cts
CHANGED
|
@@ -1814,6 +1814,9 @@ interface AgentDirectChannelOptions {
|
|
|
1814
1814
|
interface AgentFetchResponse {
|
|
1815
1815
|
readonly ok: boolean;
|
|
1816
1816
|
readonly status: number;
|
|
1817
|
+
readonly headers: {
|
|
1818
|
+
get(name: string): string | null;
|
|
1819
|
+
};
|
|
1817
1820
|
json(): Promise<unknown>;
|
|
1818
1821
|
readonly body: {
|
|
1819
1822
|
getReader(): {
|
package/dist/index.d.ts
CHANGED
|
@@ -1814,6 +1814,9 @@ interface AgentDirectChannelOptions {
|
|
|
1814
1814
|
interface AgentFetchResponse {
|
|
1815
1815
|
readonly ok: boolean;
|
|
1816
1816
|
readonly status: number;
|
|
1817
|
+
readonly headers: {
|
|
1818
|
+
get(name: string): string | null;
|
|
1819
|
+
};
|
|
1817
1820
|
json(): Promise<unknown>;
|
|
1818
1821
|
readonly body: {
|
|
1819
1822
|
getReader(): {
|
package/dist/index.js
CHANGED
|
@@ -3260,7 +3260,13 @@ function errorCodeOf(body) {
|
|
|
3260
3260
|
return typeof code === "string" ? code : void 0;
|
|
3261
3261
|
}
|
|
3262
3262
|
function withBody(response, body) {
|
|
3263
|
-
return {
|
|
3263
|
+
return {
|
|
3264
|
+
ok: response.ok,
|
|
3265
|
+
status: response.status,
|
|
3266
|
+
headers: response.headers,
|
|
3267
|
+
body: response.body,
|
|
3268
|
+
json: async () => body
|
|
3269
|
+
};
|
|
3264
3270
|
}
|
|
3265
3271
|
var AgentDirectChannel = class {
|
|
3266
3272
|
constructor(tasks, fallback, options = {}) {
|
|
@@ -3625,17 +3631,14 @@ var AgentDirectChannel = class {
|
|
|
3625
3631
|
admission.settle(true);
|
|
3626
3632
|
return;
|
|
3627
3633
|
}
|
|
3628
|
-
if (response.status === 504) {
|
|
3629
|
-
admission.fail(new Error("The Agent box got no admission for the turn (504)."));
|
|
3630
|
-
return;
|
|
3631
|
-
}
|
|
3632
3634
|
const body = asObject(await response.json().catch(() => null));
|
|
3633
3635
|
const code = errorCodeOf(body);
|
|
3634
3636
|
if (isGrantRejection(response.status) && code === void 0) {
|
|
3635
3637
|
admission.fail(new GrantRejectedError(response.status));
|
|
3636
3638
|
return;
|
|
3637
3639
|
}
|
|
3638
|
-
const
|
|
3640
|
+
const fallback = response.status === 504 ? "The Agent box got no admission for the turn (504)." : `The Agent box refused the message (${response.status}).`;
|
|
3641
|
+
const message = typeof body?.message === "string" ? body.message : fallback;
|
|
3639
3642
|
admission.fail(new AgentTaskTurnError(message, code));
|
|
3640
3643
|
},
|
|
3641
3644
|
(error) => {
|
|
@@ -3681,6 +3684,11 @@ var AgentDirectChannel = class {
|
|
|
3681
3684
|
}
|
|
3682
3685
|
throw new Error(`Agent box event stream failed (${response.status}).`);
|
|
3683
3686
|
}
|
|
3687
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
3688
|
+
if (!/^text\/event-stream\b/i.test(contentType)) {
|
|
3689
|
+
close();
|
|
3690
|
+
throw new HttpUnsupportedError(contentType || "no content type");
|
|
3691
|
+
}
|
|
3684
3692
|
const lost = (error) => {
|
|
3685
3693
|
if (intentionalClose) return;
|
|
3686
3694
|
close();
|
|
@@ -3853,10 +3861,10 @@ function createAgentTaskSessionManager(options) {
|
|
|
3853
3861
|
const current = sessions.get(requested.taskId);
|
|
3854
3862
|
if (current && current.status !== "closed") return current;
|
|
3855
3863
|
}
|
|
3856
|
-
const sessionOptions = "create" in requested && !requested.runtime && channel.canDial(requested.transport) ? { ...requested, runtime: "T3" } : requested;
|
|
3864
|
+
const sessionOptions = "create" in requested && requested.agentId && !requested.runtime && channel.canDial(requested.transport) ? { ...requested, runtime: "T3" } : requested;
|
|
3857
3865
|
const session = new CoreAgentTaskSession(sessionOptions, {
|
|
3858
3866
|
tasks: options.tasks,
|
|
3859
|
-
eventSource:
|
|
3867
|
+
eventSource: options.eventSource,
|
|
3860
3868
|
channel,
|
|
3861
3869
|
onTaskId: (taskId, value) => sessions.set(taskId, value),
|
|
3862
3870
|
onClose: (taskId, value) => {
|
|
@@ -4137,7 +4145,8 @@ var CoreAgentTaskSession = class {
|
|
|
4137
4145
|
if (!this._taskId) return Promise.reject(new Error("Agent task has not been created."));
|
|
4138
4146
|
const abort = new AbortController();
|
|
4139
4147
|
this.connectionAbort = abort;
|
|
4140
|
-
this.
|
|
4148
|
+
const source = this._task?.agentId ? this.dependencies.channel : this.dependencies.eventSource;
|
|
4149
|
+
this.connectionPromise = source.open(
|
|
4141
4150
|
this._taskId,
|
|
4142
4151
|
{
|
|
4143
4152
|
onEvent: (event) => this.handleEvent(event),
|