@hilbras/omninode 2.0.0-alpha.2 → 2.0.0-alpha.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 +2 -2
- package/dist/cli/index.js +395 -63
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +247 -44
- package/dist/index.js +427 -59
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -673,6 +673,344 @@ var ModelRegistry = class {
|
|
|
673
673
|
|
|
674
674
|
// src/agents/process/index.ts
|
|
675
675
|
import { spawn } from "child_process";
|
|
676
|
+
|
|
677
|
+
// src/agent-protocol/version.ts
|
|
678
|
+
var PROTOCOL_V2 = "omninode-agent-protocol/2";
|
|
679
|
+
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
680
|
+
"omninode-agent-protocol/1",
|
|
681
|
+
PROTOCOL_V2
|
|
682
|
+
];
|
|
683
|
+
var MAX_MESSAGE_BYTES = 1048576;
|
|
684
|
+
function isSupportedProtocol(protocol) {
|
|
685
|
+
return SUPPORTED_PROTOCOL_VERSIONS.includes(protocol);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// src/agent-protocol/types.ts
|
|
689
|
+
function newMessageId(prefix = "msg") {
|
|
690
|
+
const random = Math.random().toString(36).slice(2, 10);
|
|
691
|
+
return `${prefix}-${Date.now().toString(36)}-${random}`;
|
|
692
|
+
}
|
|
693
|
+
function envelope(type, payload, ids = {}) {
|
|
694
|
+
return {
|
|
695
|
+
protocol: PROTOCOL_V2,
|
|
696
|
+
messageId: newMessageId(),
|
|
697
|
+
...ids.requestId !== void 0 ? { requestId: ids.requestId } : {},
|
|
698
|
+
...ids.taskId !== void 0 ? { taskId: ids.taskId } : {},
|
|
699
|
+
...ids.agentId !== void 0 ? { agentId: ids.agentId } : {},
|
|
700
|
+
...ids.pipelineId !== void 0 ? { pipelineId: ids.pipelineId } : {},
|
|
701
|
+
...ids.executionId !== void 0 ? { executionId: ids.executionId } : {},
|
|
702
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
703
|
+
type,
|
|
704
|
+
payload,
|
|
705
|
+
...ids.metadata !== void 0 ? { metadata: ids.metadata } : {}
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/agent-protocol/codec.ts
|
|
710
|
+
var KNOWN_TYPES = /* @__PURE__ */ new Set([
|
|
711
|
+
// node → agent
|
|
712
|
+
"TASK",
|
|
713
|
+
"HELLO_ACK",
|
|
714
|
+
"CONTEXT",
|
|
715
|
+
"INSTRUCTION",
|
|
716
|
+
"RESPONSE",
|
|
717
|
+
"CANCEL",
|
|
718
|
+
// agent → node
|
|
719
|
+
"HELLO",
|
|
720
|
+
"TASK_REQUEST",
|
|
721
|
+
"TASK_ACCEPTED",
|
|
722
|
+
"TASK_STARTED",
|
|
723
|
+
"STATUS",
|
|
724
|
+
"QUESTION",
|
|
725
|
+
"REPORT",
|
|
726
|
+
"ARTIFACT",
|
|
727
|
+
"COMPLETION",
|
|
728
|
+
"ERROR",
|
|
729
|
+
"CANCELLED"
|
|
730
|
+
]);
|
|
731
|
+
var PAYLOAD_REQUIRED_TYPES = /* @__PURE__ */ new Set(["TASK", "REPORT", "COMPLETION", "ERROR", "QUESTION", "ARTIFACT", "HELLO"]);
|
|
732
|
+
function validateEnvelope(value, line) {
|
|
733
|
+
const sample = line?.slice(0, 200);
|
|
734
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
735
|
+
return { ok: false, error: { code: "NOT_AN_OBJECT", message: "message must be a JSON object", ...sample ? { sample } : {} } };
|
|
736
|
+
}
|
|
737
|
+
const raw = value;
|
|
738
|
+
const protocol = raw.protocol;
|
|
739
|
+
if (protocol === void 0) {
|
|
740
|
+
const type = raw.type;
|
|
741
|
+
if (typeof type !== "string" || !KNOWN_TYPES.has(type)) {
|
|
742
|
+
return { ok: false, error: { code: "UNKNOWN_TYPE", message: `unknown message type ${String(type)}`, ...sample ? { sample } : {} } };
|
|
743
|
+
}
|
|
744
|
+
return {
|
|
745
|
+
ok: true,
|
|
746
|
+
legacy: true,
|
|
747
|
+
envelope: {
|
|
748
|
+
protocol: "omninode-agent-protocol/1",
|
|
749
|
+
messageId: typeof raw.messageId === "string" ? raw.messageId : "legacy",
|
|
750
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
751
|
+
type,
|
|
752
|
+
payload: raw.payload
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
if (typeof protocol !== "string" || !isSupportedProtocol(protocol)) {
|
|
757
|
+
return {
|
|
758
|
+
ok: false,
|
|
759
|
+
error: { code: "UNSUPPORTED_VERSION", message: `unsupported protocol "${String(protocol)}"`, ...sample ? { sample } : {} }
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
if (raw.type === void 0) {
|
|
763
|
+
return { ok: false, error: { code: "MISSING_FIELD", message: "message is missing 'type'", ...sample ? { sample } : {} } };
|
|
764
|
+
}
|
|
765
|
+
if (typeof raw.type !== "string" || !KNOWN_TYPES.has(raw.type)) {
|
|
766
|
+
return { ok: false, error: { code: "UNKNOWN_TYPE", message: `unknown message type ${String(raw.type)}`, ...sample ? { sample } : {} } };
|
|
767
|
+
}
|
|
768
|
+
if (raw.timestamp !== void 0 && typeof raw.timestamp !== "string") {
|
|
769
|
+
return { ok: false, error: { code: "MISSING_FIELD", message: "'timestamp' must be a string", ...sample ? { sample } : {} } };
|
|
770
|
+
}
|
|
771
|
+
if (PAYLOAD_REQUIRED_TYPES.has(raw.type) && (raw.payload === void 0 || raw.payload === null)) {
|
|
772
|
+
return { ok: false, error: { code: "INVALID_PAYLOAD", message: `${raw.type} requires a payload`, ...sample ? { sample } : {} } };
|
|
773
|
+
}
|
|
774
|
+
return {
|
|
775
|
+
ok: true,
|
|
776
|
+
legacy: protocol !== PROTOCOL_V2,
|
|
777
|
+
envelope: {
|
|
778
|
+
protocol,
|
|
779
|
+
messageId: typeof raw.messageId === "string" ? raw.messageId : "unknown",
|
|
780
|
+
...typeof raw.requestId === "string" ? { requestId: raw.requestId } : {},
|
|
781
|
+
...typeof raw.taskId === "string" ? { taskId: raw.taskId } : {},
|
|
782
|
+
...typeof raw.agentId === "string" ? { agentId: raw.agentId } : {},
|
|
783
|
+
...typeof raw.pipelineId === "string" ? { pipelineId: raw.pipelineId } : {},
|
|
784
|
+
...typeof raw.executionId === "string" ? { executionId: raw.executionId } : {},
|
|
785
|
+
timestamp: typeof raw.timestamp === "string" ? raw.timestamp : (/* @__PURE__ */ new Date()).toISOString(),
|
|
786
|
+
type: raw.type,
|
|
787
|
+
payload: raw.payload,
|
|
788
|
+
...raw.metadata !== null && typeof raw.metadata === "object" ? { metadata: raw.metadata } : {}
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
function decodeMessage(line, maxBytes = MAX_MESSAGE_BYTES) {
|
|
793
|
+
const trimmed = line.trim();
|
|
794
|
+
if (trimmed.length === 0) {
|
|
795
|
+
return { ok: false, error: { code: "INVALID_JSON", message: "empty line" } };
|
|
796
|
+
}
|
|
797
|
+
if (trimmed.length > maxBytes) {
|
|
798
|
+
return {
|
|
799
|
+
ok: false,
|
|
800
|
+
error: { code: "OVERSIZED", message: `message of ${trimmed.length} bytes exceeds the ${maxBytes} byte limit`, sample: trimmed.slice(0, 200) }
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
let value;
|
|
804
|
+
try {
|
|
805
|
+
value = JSON.parse(trimmed);
|
|
806
|
+
} catch (error) {
|
|
807
|
+
return {
|
|
808
|
+
ok: false,
|
|
809
|
+
error: { code: "INVALID_JSON", message: error instanceof Error ? error.message : "invalid JSON", sample: trimmed.slice(0, 200) }
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
return validateEnvelope(value, trimmed);
|
|
813
|
+
}
|
|
814
|
+
function encodeMessage(envelope2, maxBytes = MAX_MESSAGE_BYTES) {
|
|
815
|
+
const line = JSON.stringify(envelope2);
|
|
816
|
+
if (line.length > maxBytes) {
|
|
817
|
+
throw new Error(`outbound protocol message of ${line.length} bytes exceeds the ${maxBytes} byte limit`);
|
|
818
|
+
}
|
|
819
|
+
return line;
|
|
820
|
+
}
|
|
821
|
+
var ProtocolDecoder = class {
|
|
822
|
+
buffer = "";
|
|
823
|
+
maxBytes;
|
|
824
|
+
constructor(maxBytes = MAX_MESSAGE_BYTES) {
|
|
825
|
+
this.maxBytes = maxBytes;
|
|
826
|
+
}
|
|
827
|
+
push(chunk) {
|
|
828
|
+
this.buffer += chunk;
|
|
829
|
+
const results = [];
|
|
830
|
+
let index = this.buffer.indexOf("\n");
|
|
831
|
+
while (index >= 0) {
|
|
832
|
+
const line = this.buffer.slice(0, index);
|
|
833
|
+
this.buffer = this.buffer.slice(index + 1);
|
|
834
|
+
if (line.trim().length > 0) results.push(decodeMessage(line, this.maxBytes));
|
|
835
|
+
index = this.buffer.indexOf("\n");
|
|
836
|
+
}
|
|
837
|
+
if (this.buffer.length > this.maxBytes) {
|
|
838
|
+
results.push({
|
|
839
|
+
ok: false,
|
|
840
|
+
error: { code: "OVERSIZED", message: `line exceeded ${this.maxBytes} bytes without a newline`, sample: this.buffer.slice(0, 200) }
|
|
841
|
+
});
|
|
842
|
+
this.buffer = "";
|
|
843
|
+
}
|
|
844
|
+
return results;
|
|
845
|
+
}
|
|
846
|
+
/** Flush any trailing line when the process exits. */
|
|
847
|
+
flush() {
|
|
848
|
+
if (this.buffer.trim().length === 0) {
|
|
849
|
+
this.buffer = "";
|
|
850
|
+
return [];
|
|
851
|
+
}
|
|
852
|
+
const result = decodeMessage(this.buffer, this.maxBytes);
|
|
853
|
+
this.buffer = "";
|
|
854
|
+
return [result];
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
// src/agent-protocol/handshake.ts
|
|
859
|
+
function parseHello(envelopeValue) {
|
|
860
|
+
if (envelopeValue.type !== "HELLO") {
|
|
861
|
+
return { ok: false, reason: `expected HELLO, received ${envelopeValue.type}` };
|
|
862
|
+
}
|
|
863
|
+
const payload = envelopeValue.payload;
|
|
864
|
+
if (payload === null || typeof payload !== "object") {
|
|
865
|
+
return { ok: false, reason: "HELLO payload must be an object" };
|
|
866
|
+
}
|
|
867
|
+
const p = payload;
|
|
868
|
+
if (typeof p.name !== "string" || p.name.length === 0) {
|
|
869
|
+
return { ok: false, reason: "HELLO payload is missing 'name'" };
|
|
870
|
+
}
|
|
871
|
+
return {
|
|
872
|
+
ok: true,
|
|
873
|
+
descriptor: {
|
|
874
|
+
protocol: envelopeValue.protocol,
|
|
875
|
+
name: p.name,
|
|
876
|
+
...typeof p.version === "string" ? { version: p.version } : {},
|
|
877
|
+
capabilities: Array.isArray(p.capabilities) ? p.capabilities.filter((c) => typeof c === "string") : [],
|
|
878
|
+
supports: Array.isArray(p.supports) ? p.supports.filter((s) => typeof s === "string") : []
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
function buildHello(descriptor) {
|
|
883
|
+
return envelope("HELLO", descriptor, { agentId: descriptor.name });
|
|
884
|
+
}
|
|
885
|
+
function buildHelloAck(descriptor) {
|
|
886
|
+
return envelope("HELLO_ACK", {
|
|
887
|
+
ok: true,
|
|
888
|
+
protocol: PROTOCOL_V2,
|
|
889
|
+
agent: descriptor.name,
|
|
890
|
+
...descriptor.version !== void 0 ? { agentVersion: descriptor.version } : {},
|
|
891
|
+
supportedProtocols: [PROTOCOL_V2]
|
|
892
|
+
}, { agentId: descriptor.name });
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// src/agent-protocol/session.ts
|
|
896
|
+
var ProtocolSession = class {
|
|
897
|
+
decoder;
|
|
898
|
+
ids;
|
|
899
|
+
responder;
|
|
900
|
+
violations = [];
|
|
901
|
+
questions = [];
|
|
902
|
+
artifacts = [];
|
|
903
|
+
reports = [];
|
|
904
|
+
descriptor;
|
|
905
|
+
completionSummary;
|
|
906
|
+
errorMessage;
|
|
907
|
+
constructor(ids, options = {}) {
|
|
908
|
+
this.ids = ids;
|
|
909
|
+
this.responder = options.responder;
|
|
910
|
+
this.decoder = new ProtocolDecoder(options.maxBytes);
|
|
911
|
+
}
|
|
912
|
+
/** The v2 messages OmniNode sends to open a task (written to the agent's stdin). */
|
|
913
|
+
taskMessages(objective, role, context, instruction) {
|
|
914
|
+
const ids = this.ids;
|
|
915
|
+
const messages = [envelope("TASK", { taskId: ids.taskId, objective }, ids)];
|
|
916
|
+
if (role !== void 0) messages.push(envelope("CONTEXT", { role }, ids));
|
|
917
|
+
if (context !== void 0 && context.length > 0) messages.push(envelope("CONTEXT", { body: context }, ids));
|
|
918
|
+
if (instruction !== void 0 && instruction.length > 0) messages.push(envelope("INSTRUCTION", { text: instruction }, ids));
|
|
919
|
+
return messages.map((m) => encodeMessage(m));
|
|
920
|
+
}
|
|
921
|
+
helloAck(descriptor) {
|
|
922
|
+
return encodeMessage(buildHelloAck(descriptor));
|
|
923
|
+
}
|
|
924
|
+
/** Consumes decoded stdout, answering questions as they arrive. */
|
|
925
|
+
async handle(decoded) {
|
|
926
|
+
if (!decoded.ok) {
|
|
927
|
+
this.violations.push(decoded.error);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const message = decoded.envelope;
|
|
931
|
+
if (message.protocol === PROTOCOL_V2) this.sawV2 = true;
|
|
932
|
+
if (message.type === "HELLO") {
|
|
933
|
+
const hello = parseHello(message);
|
|
934
|
+
if (hello.ok) this.descriptor = hello.descriptor;
|
|
935
|
+
else this.violations.push({ code: "INVALID_PAYLOAD", message: `bad HELLO: ${hello.reason}` });
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
if (message.type === "QUESTION") {
|
|
939
|
+
await this.answerQuestion(message);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (message.type === "REPORT") {
|
|
943
|
+
this.reports.push(message.payload);
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
if (message.type === "ARTIFACT") {
|
|
947
|
+
this.artifacts.push(message.payload);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (message.type === "COMPLETION") {
|
|
951
|
+
const payload = message.payload;
|
|
952
|
+
this.completionSummary = typeof payload?.summary === "string" ? payload.summary : "";
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
if (message.type === "ERROR") {
|
|
956
|
+
const payload = message.payload;
|
|
957
|
+
const detail = typeof payload?.message === "string" ? payload.message : "agent reported an error";
|
|
958
|
+
const code = typeof payload?.code === "string" ? ` [${payload.code}]` : "";
|
|
959
|
+
this.errorMessage = `Agent error${code}: ${detail}`;
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
if (message.type === "TASK_ACCEPTED" || message.type === "TASK_STARTED" || message.type === "STATUS") {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
this.violations.push({
|
|
966
|
+
code: "UNKNOWN_TYPE",
|
|
967
|
+
message: `unexpected message type ${message.type} from agent`
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
async answerQuestion(message) {
|
|
971
|
+
const payload = message.payload ?? {};
|
|
972
|
+
const questionId = typeof payload.questionId === "string" ? payload.questionId : message.messageId;
|
|
973
|
+
const question = typeof payload.question === "string" ? payload.question : "";
|
|
974
|
+
const expected = typeof payload.expected === "string" ? payload.expected : "text";
|
|
975
|
+
let answer;
|
|
976
|
+
if (this.responder) {
|
|
977
|
+
try {
|
|
978
|
+
answer = await this.responder({ questionId, question, expected });
|
|
979
|
+
} catch (error) {
|
|
980
|
+
this.violations.push({
|
|
981
|
+
code: "INVALID_PAYLOAD",
|
|
982
|
+
message: `question responder failed: ${error instanceof Error ? error.message : String(error)}`
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
this.questions.push({ questionId, question, ...answer !== void 0 ? { answer } : {} });
|
|
987
|
+
this.pendingAnswers.push(
|
|
988
|
+
encodeMessage(
|
|
989
|
+
envelope("RESPONSE", { questionId, ...answer !== void 0 ? { body: answer } : {} }, {
|
|
990
|
+
...this.ids,
|
|
991
|
+
requestId: message.requestId ?? this.ids.requestId
|
|
992
|
+
})
|
|
993
|
+
)
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
pendingAnswers = [];
|
|
997
|
+
/** True once any inbound message carried the v2 protocol field. */
|
|
998
|
+
sawV2 = false;
|
|
999
|
+
};
|
|
1000
|
+
async function decodeStream(session, chunk) {
|
|
1001
|
+
const decoded = session.decoder.push(chunk);
|
|
1002
|
+
for (const result of decoded) {
|
|
1003
|
+
await session.handle(result);
|
|
1004
|
+
}
|
|
1005
|
+
return session.pendingAnswers.splice(0);
|
|
1006
|
+
}
|
|
1007
|
+
function requireCompletion(session) {
|
|
1008
|
+
if (session.errorMessage !== void 0) {
|
|
1009
|
+
throw new ProtocolError(session.errorMessage);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// src/agents/process/index.ts
|
|
676
1014
|
var DEFAULT_TIMEOUT_MS2 = 6e5;
|
|
677
1015
|
var KILL_GRACE_MS = 5e3;
|
|
678
1016
|
function buildChildEnv(config) {
|
|
@@ -706,18 +1044,19 @@ ${input.instruction}`);
|
|
|
706
1044
|
return sections.join("\n\n");
|
|
707
1045
|
}
|
|
708
1046
|
function buildProtocolMessages(input, agentName) {
|
|
709
|
-
const
|
|
1047
|
+
const session = new ProtocolSession({
|
|
1048
|
+
requestId: `req-${input.taskId}`,
|
|
710
1049
|
taskId: input.taskId,
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1050
|
+
agentId: agentName,
|
|
1051
|
+
...input.pipelineId !== void 0 ? { pipelineId: input.pipelineId } : {},
|
|
1052
|
+
...input.executionId !== void 0 ? { executionId: input.executionId } : {}
|
|
1053
|
+
});
|
|
1054
|
+
return session.taskMessages(
|
|
1055
|
+
input.objective,
|
|
1056
|
+
input.role,
|
|
1057
|
+
input.context,
|
|
1058
|
+
input.instruction
|
|
1059
|
+
);
|
|
721
1060
|
}
|
|
722
1061
|
var ProcessAgent = class {
|
|
723
1062
|
config;
|
|
@@ -870,62 +1209,75 @@ var ProcessAgent = class {
|
|
|
870
1209
|
return [...this.running.keys()];
|
|
871
1210
|
}
|
|
872
1211
|
};
|
|
873
|
-
function interpretProtocolRun({
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
const code = typeof payload?.code === "string" ? ` [${payload.code}]` : "";
|
|
894
|
-
error = `Agent error${code}: ${detail}`;
|
|
895
|
-
}
|
|
1212
|
+
function interpretProtocolRun({
|
|
1213
|
+
input,
|
|
1214
|
+
agentName,
|
|
1215
|
+
stdout,
|
|
1216
|
+
exitCode,
|
|
1217
|
+
logs,
|
|
1218
|
+
responder
|
|
1219
|
+
}) {
|
|
1220
|
+
const session = new ProtocolSession(
|
|
1221
|
+
{
|
|
1222
|
+
requestId: `req-${input.taskId}`,
|
|
1223
|
+
taskId: input.taskId,
|
|
1224
|
+
agentId: agentName,
|
|
1225
|
+
...input.pipelineId !== void 0 ? { pipelineId: input.pipelineId } : {},
|
|
1226
|
+
...input.executionId !== void 0 ? { executionId: input.executionId } : {}
|
|
1227
|
+
},
|
|
1228
|
+
{ ...responder !== void 0 ? { responder } : {} }
|
|
1229
|
+
);
|
|
1230
|
+
for (const result of session.decoder.push(stdout)) {
|
|
1231
|
+
session.handle(result);
|
|
896
1232
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
`Agent "${agentName}" produced no protocol messages on stdout (input mode "protocol").`,
|
|
900
|
-
{ details: { taskId: input.taskId, stdout: stdout.slice(0, 2e3) } }
|
|
901
|
-
);
|
|
1233
|
+
for (const result of session.decoder.flush()) {
|
|
1234
|
+
session.handle(result);
|
|
902
1235
|
}
|
|
1236
|
+
const reports = session.reports.flatMap((payload) => Array.isArray(payload) ? payload : [payload]).map((payload, index) => normalizeReport(payload, input.taskId, agentName, index)).filter((report) => report !== void 0);
|
|
903
1237
|
const trimmed = stdout.trim();
|
|
1238
|
+
const protocolBlock = {
|
|
1239
|
+
protocol: session.descriptor?.protocol ?? PROTOCOL_V2,
|
|
1240
|
+
legacy: !session.sawV2 && session.descriptor === void 0,
|
|
1241
|
+
...session.descriptor !== void 0 ? { descriptor: session.descriptor } : {},
|
|
1242
|
+
questions: session.questions,
|
|
1243
|
+
violations: session.violations.map((v) => `${v.code}: ${v.message}`)
|
|
1244
|
+
};
|
|
1245
|
+
if (session.errorMessage !== void 0) {
|
|
1246
|
+
return {
|
|
1247
|
+
taskId: input.taskId,
|
|
1248
|
+
status: "failed",
|
|
1249
|
+
error: session.errorMessage,
|
|
1250
|
+
rawOutput: trimmed.length > 0 ? trimmed : void 0,
|
|
1251
|
+
exitCode: exitCode ?? void 0,
|
|
1252
|
+
logs,
|
|
1253
|
+
protocol: protocolBlock,
|
|
1254
|
+
...reports.length > 0 ? { reports } : {}
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
if (session.descriptor === void 0 && session.violations.length > 0 && session.reports.length === 0 && session.completionSummary === void 0) {
|
|
1258
|
+
return {
|
|
1259
|
+
taskId: input.taskId,
|
|
1260
|
+
status: "failed",
|
|
1261
|
+
error: `agent produced no valid protocol messages: ${protocolBlock.violations.join("; ")}`,
|
|
1262
|
+
rawOutput: trimmed.length > 0 ? trimmed : void 0,
|
|
1263
|
+
exitCode: exitCode ?? void 0,
|
|
1264
|
+
logs,
|
|
1265
|
+
protocol: protocolBlock
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
const completed = exitCode === 0 && session.completionSummary !== void 0;
|
|
904
1269
|
return {
|
|
905
1270
|
taskId: input.taskId,
|
|
906
|
-
status:
|
|
907
|
-
summary:
|
|
1271
|
+
status: completed || exitCode === 0 ? completed ? "completed" : "completed" : "failed",
|
|
1272
|
+
summary: session.completionSummary ?? reports[0]?.summary,
|
|
908
1273
|
rawOutput: trimmed.length > 0 ? trimmed : void 0,
|
|
909
1274
|
exitCode: exitCode ?? void 0,
|
|
910
1275
|
logs,
|
|
911
|
-
|
|
912
|
-
|
|
1276
|
+
protocol: protocolBlock,
|
|
1277
|
+
...reports.length > 0 ? { reports } : {},
|
|
1278
|
+
...exitCode !== 0 ? { error: `Process exited with code ${exitCode ?? "unknown"}` } : {}
|
|
913
1279
|
};
|
|
914
1280
|
}
|
|
915
|
-
function parseAgentMessage(line) {
|
|
916
|
-
try {
|
|
917
|
-
const parsed = JSON.parse(line);
|
|
918
|
-
if (typeof parsed.type === "string") {
|
|
919
|
-
return { type: parsed.type, payload: parsed.payload };
|
|
920
|
-
}
|
|
921
|
-
const inner = parsed.message;
|
|
922
|
-
if (inner && typeof inner.type === "string") {
|
|
923
|
-
return { type: inner.type, payload: inner.payload };
|
|
924
|
-
}
|
|
925
|
-
} catch {
|
|
926
|
-
}
|
|
927
|
-
return void 0;
|
|
928
|
-
}
|
|
929
1281
|
function normalizeReport(payload, taskId, agentName, index) {
|
|
930
1282
|
if (payload === null || typeof payload !== "object") return void 0;
|
|
931
1283
|
const raw = payload;
|
|
@@ -2685,7 +3037,7 @@ var ProjectStores = class {
|
|
|
2685
3037
|
};
|
|
2686
3038
|
|
|
2687
3039
|
// src/version.ts
|
|
2688
|
-
var OMNINODE_VERSION = "2.0.0-alpha.
|
|
3040
|
+
var OMNINODE_VERSION = "2.0.0-alpha.3";
|
|
2689
3041
|
export {
|
|
2690
3042
|
AgentError,
|
|
2691
3043
|
AgentRegistry,
|
|
@@ -2700,6 +3052,7 @@ export {
|
|
|
2700
3052
|
JsonFileStore,
|
|
2701
3053
|
LocalMemoryProvider,
|
|
2702
3054
|
Logger,
|
|
3055
|
+
MAX_MESSAGE_BYTES,
|
|
2703
3056
|
MemoryError,
|
|
2704
3057
|
MemoryService,
|
|
2705
3058
|
ModelPlanner,
|
|
@@ -2709,16 +3062,20 @@ export {
|
|
|
2709
3062
|
OmniHilbrasProvider,
|
|
2710
3063
|
OmniNodeError,
|
|
2711
3064
|
OpenAICompatibleProvider,
|
|
3065
|
+
PROTOCOL_V2,
|
|
2712
3066
|
PipelineEngine,
|
|
2713
3067
|
PipelineError,
|
|
2714
3068
|
PlannerError,
|
|
2715
3069
|
ProcessAgent,
|
|
2716
3070
|
ProjectStores,
|
|
3071
|
+
ProtocolDecoder,
|
|
2717
3072
|
ProtocolError,
|
|
3073
|
+
ProtocolSession,
|
|
2718
3074
|
ProviderError,
|
|
2719
3075
|
RememberaMemoryProvider,
|
|
2720
3076
|
ReportService,
|
|
2721
3077
|
RoleRegistry,
|
|
3078
|
+
SUPPORTED_PROTOCOL_VERSIONS,
|
|
2722
3079
|
TERMINAL_TASK_STATUSES,
|
|
2723
3080
|
TaskEngine,
|
|
2724
3081
|
TaskError,
|
|
@@ -2728,6 +3085,8 @@ export {
|
|
|
2728
3085
|
authHeaders,
|
|
2729
3086
|
buildAgentRegistry,
|
|
2730
3087
|
buildChildEnv,
|
|
3088
|
+
buildHello,
|
|
3089
|
+
buildHelloAck,
|
|
2731
3090
|
buildPipelineEngine,
|
|
2732
3091
|
buildPlanner,
|
|
2733
3092
|
buildPlannerContext,
|
|
@@ -2738,14 +3097,21 @@ export {
|
|
|
2738
3097
|
createMemoryProvider,
|
|
2739
3098
|
createProvider,
|
|
2740
3099
|
createTaskEngine,
|
|
3100
|
+
decodeMessage,
|
|
3101
|
+
decodeStream,
|
|
2741
3102
|
defaultProjectConfigYaml,
|
|
3103
|
+
encodeMessage,
|
|
3104
|
+
envelope,
|
|
2742
3105
|
expandEnvRefs,
|
|
2743
3106
|
extractReportFromText,
|
|
2744
3107
|
findConfigFile,
|
|
2745
3108
|
isOmniNodeError,
|
|
3109
|
+
isSupportedProtocol,
|
|
2746
3110
|
keywords,
|
|
2747
3111
|
loadConfig,
|
|
2748
3112
|
logger,
|
|
3113
|
+
newMessageId,
|
|
3114
|
+
parseHello,
|
|
2749
3115
|
parsePlanJson,
|
|
2750
3116
|
pipelineConfigSchema,
|
|
2751
3117
|
pipelineStepConfigSchema,
|
|
@@ -2754,8 +3120,10 @@ export {
|
|
|
2754
3120
|
providerConfigSchema,
|
|
2755
3121
|
registryKey,
|
|
2756
3122
|
requestJson,
|
|
3123
|
+
requireCompletion,
|
|
2757
3124
|
resolveApiKey,
|
|
2758
3125
|
roleConfigSchema,
|
|
2759
|
-
similar
|
|
3126
|
+
similar,
|
|
3127
|
+
validateEnvelope
|
|
2760
3128
|
};
|
|
2761
3129
|
//# sourceMappingURL=index.js.map
|