dsh-select-quote 0.3.13 → 0.3.15
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 +6 -3
- package/lib/client.js +15801 -301
- package/lib/index.js +132 -2
- package/lib/typert.js +13823 -0
- package/package.json +11 -3
package/lib/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import "zod";
|
|
1
4
|
//#region node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.6/node_modules/@deepseek-ai/cosmokit/lib/index.js
|
|
2
5
|
/** Return true when a value is `null` or `undefined`. */
|
|
3
6
|
function isNullable(value) {
|
|
@@ -896,6 +899,128 @@ defineMethod("transform", [
|
|
|
896
899
|
*/
|
|
897
900
|
const PACKAGE_NAME = "dsh-select-quote";
|
|
898
901
|
//#endregion
|
|
902
|
+
//#region src/shared/side-task-remote.ts
|
|
903
|
+
/**
|
|
904
|
+
* Wire contract shared by the two halves.
|
|
905
|
+
*
|
|
906
|
+
* The Host owns the implementation (`ctx.selectQuoteSideTask`); the browser
|
|
907
|
+
* mounts the same descriptor group through `ctx.remote.$mount(...)`. Both
|
|
908
|
+
* schemas are written here so the argument shapes cannot drift apart.
|
|
909
|
+
*/
|
|
910
|
+
const SIDE_TASK_SERVICE = "selectQuoteSideTask";
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region src/shared/side-task-reuse.ts
|
|
913
|
+
/**
|
|
914
|
+
* Reuse bookkeeping for the "one side child per main session" mode.
|
|
915
|
+
*
|
|
916
|
+
* The identity is derived, never remembered: a Host restart or a new browser
|
|
917
|
+
* tab resolves the same child again. The shape is UUID-like so the value is
|
|
918
|
+
* indistinguishable from an ordinary session id in logs and the catalog.
|
|
919
|
+
*/
|
|
920
|
+
function reusableChildId(parentSessionId) {
|
|
921
|
+
const hex = createHash("sha256").update(`dsh-select-quote:side-task:${parentSessionId}`).digest("hex").slice(0, 32);
|
|
922
|
+
return [
|
|
923
|
+
hex.slice(0, 8),
|
|
924
|
+
hex.slice(8, 12),
|
|
925
|
+
hex.slice(12, 16),
|
|
926
|
+
hex.slice(16, 20),
|
|
927
|
+
hex.slice(20)
|
|
928
|
+
].join("-");
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Whether a failed continuation means "no such child" rather than a refusal.
|
|
932
|
+
* The gateway wraps refusals in `RemoteError` and keeps the original
|
|
933
|
+
* `SubagentError` as `cause`, so the code can sit on either level.
|
|
934
|
+
*/
|
|
935
|
+
function isNotResumable(error) {
|
|
936
|
+
if (typeof error !== "object" || error === null) return false;
|
|
937
|
+
const code = error.code;
|
|
938
|
+
if (code === "subagent/not-resumable" || code === "NOT_RESUMABLE") return true;
|
|
939
|
+
return isNotResumable(error.cause);
|
|
940
|
+
}
|
|
941
|
+
//#endregion
|
|
942
|
+
//#region src/side-task-service.ts
|
|
943
|
+
/**
|
|
944
|
+
* Class-prototype key the Typert Gateway reads its Remote method markers from.
|
|
945
|
+
* It is a plain string (not a Symbol), so a third-party package can publish the
|
|
946
|
+
* same marker without importing the protocol package at runtime.
|
|
947
|
+
*/
|
|
948
|
+
const REMOTE_METHOD_DESCRIPTOR = "@deepseek-ai/dsh-typert-protocol/remote-methods";
|
|
949
|
+
const REMOTE_METHODS = Object.freeze({
|
|
950
|
+
version: 1,
|
|
951
|
+
methods: Object.freeze([Object.freeze({
|
|
952
|
+
method: "create",
|
|
953
|
+
invocation: Object.freeze({ kind: "direct" })
|
|
954
|
+
})])
|
|
955
|
+
});
|
|
956
|
+
/**
|
|
957
|
+
* Host face of the side-task entry point.
|
|
958
|
+
*
|
|
959
|
+
* The browser cannot create a subagent: only the Host half owns
|
|
960
|
+
* `ctx.subagents`, and only a subagent session carries `origin: "subagent"`
|
|
961
|
+
* (which is what keeps it out of the session list). `delivery: "caller"`
|
|
962
|
+
* suppresses the settlement notice the parent would otherwise receive.
|
|
963
|
+
*/
|
|
964
|
+
var SelectQuoteSideTask = class extends Service {
|
|
965
|
+
/** Visible binding the Gateway's source-mode discovery requires. */
|
|
966
|
+
typertRemote;
|
|
967
|
+
constructor(ctx) {
|
|
968
|
+
super(ctx, SIDE_TASK_SERVICE);
|
|
969
|
+
this.typertRemote = Object.freeze({
|
|
970
|
+
service: this,
|
|
971
|
+
serviceKey: SIDE_TASK_SERVICE,
|
|
972
|
+
namespace: SIDE_TASK_SERVICE
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
async create(agent, request) {
|
|
976
|
+
const prompt = request.prompt.trim();
|
|
977
|
+
if (!prompt) throw new Error("side task prompt must not be empty");
|
|
978
|
+
const subagents = this.ctx.subagents;
|
|
979
|
+
if (subagents === void 0) throw new Error("the subagent service is unavailable");
|
|
980
|
+
const agentOptions = request.model === void 0 ? void 0 : {
|
|
981
|
+
provider: request.model.provider,
|
|
982
|
+
model: request.model.model,
|
|
983
|
+
...request.model.reasoningEffort === void 0 ? {} : { reasoningEffort: request.model.reasoningEffort }
|
|
984
|
+
};
|
|
985
|
+
const childId = request.reuse === true ? reusableChildId(agent.id) : void 0;
|
|
986
|
+
if (childId !== void 0) try {
|
|
987
|
+
await subagents.prompt({
|
|
988
|
+
requestId: randomUUID(),
|
|
989
|
+
parentSessionId: agent.id,
|
|
990
|
+
childSessionId: childId,
|
|
991
|
+
mode: "continuable",
|
|
992
|
+
delivery: "queue",
|
|
993
|
+
content: [{
|
|
994
|
+
type: "text",
|
|
995
|
+
text: prompt
|
|
996
|
+
}]
|
|
997
|
+
}, new AbortController().signal);
|
|
998
|
+
return { childId };
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
if (!isNotResumable(error)) throw error;
|
|
1001
|
+
}
|
|
1002
|
+
return { childId: (await subagents.startActivation({
|
|
1003
|
+
provider: "fork",
|
|
1004
|
+
...request.label === void 0 ? {} : { label: request.label },
|
|
1005
|
+
...childId === void 0 ? {} : { childId },
|
|
1006
|
+
delivery: "caller",
|
|
1007
|
+
request: {
|
|
1008
|
+
parent: agent,
|
|
1009
|
+
prompt: [{
|
|
1010
|
+
type: "text",
|
|
1011
|
+
text: prompt
|
|
1012
|
+
}],
|
|
1013
|
+
...agentOptions === void 0 ? {} : { agentOptions }
|
|
1014
|
+
},
|
|
1015
|
+
signal: new AbortController().signal
|
|
1016
|
+
})).childId };
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
Object.defineProperty(SelectQuoteSideTask.prototype, REMOTE_METHOD_DESCRIPTOR, {
|
|
1020
|
+
configurable: true,
|
|
1021
|
+
value: REMOTE_METHODS
|
|
1022
|
+
});
|
|
1023
|
+
//#endregion
|
|
899
1024
|
//#region src/index.ts
|
|
900
1025
|
const Config = Schema.object({
|
|
901
1026
|
triggerMode: Schema.union([
|
|
@@ -903,9 +1028,14 @@ const Config = Schema.object({
|
|
|
903
1028
|
"contextmenu",
|
|
904
1029
|
"both"
|
|
905
1030
|
]).default("auto").volatile(),
|
|
906
|
-
shortcut: Schema.boolean().default(false).volatile()
|
|
1031
|
+
shortcut: Schema.boolean().default(false).volatile(),
|
|
1032
|
+
sideTaskMode: Schema.union(["separate", "reuse"]).default("separate").volatile()
|
|
907
1033
|
});
|
|
908
1034
|
const name = PACKAGE_NAME;
|
|
909
|
-
function apply(
|
|
1035
|
+
function apply(ctx, _config) {
|
|
1036
|
+
ctx.inject(["subagents"], (scope) => {
|
|
1037
|
+
new SelectQuoteSideTask(scope);
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
910
1040
|
//#endregion
|
|
911
1041
|
export { Config, apply, name };
|