Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@cloudflare/sandbox": "0.12.3",
"@larksuiteoapi/node-sdk": "^1.66.0",
"@mosoo/ag-ui-session": "workspace:*",
"@mosoo/agent-driver": "workspace:*",
"@mosoo/agent-package": "workspace:*",
"@mosoo/contracts": "workspace:*",
"@mosoo/db": "workspace:*",
Expand All @@ -28,7 +29,6 @@
"@mosoo/session-policy": "workspace:*",
"@mosoo/skill-package": "workspace:*",
"@orpc/server": "^1.14.3",
"agent-driver": "workspace:*",
"arktype": "^2.2.0",
"better-auth": "1.6.23",
"cloudflare": "7.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isSupportedDriverRuntime } from "@mosoo/agent-driver/runtime";
import type { DriverRuntime } from "@mosoo/agent-driver/runtime";
import type { JsonObject } from "@mosoo/contracts";
import type { AgentBuiltInToolConfig, AgentEnvironmentConfig } from "@mosoo/contracts/agent";
import { classifyAgentConfigChanges } from "@mosoo/contracts/agent-config-change-plan";
Expand All @@ -7,8 +9,6 @@ import type {
} from "@mosoo/contracts/agent-config-change-plan";
import type { AgentId, McpServerId, SkillId } from "@mosoo/id";
import { getRuntimeCatalogEntry } from "@mosoo/runtime-catalog";
import { isSupportedDriverRuntime } from "agent-driver/runtime";
import type { DriverRuntime } from "agent-driver/runtime";

import { listEditableAgentSkillReferences } from "./agent-deployment-version.service";
import type { AgentRow } from "./agent-types";
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/public-api/public-thread-events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OpenAiPrivateCitationStreamFilter } from "@mosoo/agent-driver/provider-output";
import type {
PublicThreadApiListThreadEventsResponse,
PublicThreadEventLogEntry,
Expand All @@ -12,7 +13,6 @@ import type { SessionProcessEvent } from "@mosoo/contracts/session";
import { sessionEventsTable, sessionMessagesTable } from "@mosoo/db";
import { parsePlatformId } from "@mosoo/id";
import type { RuntimeEventId, SessionId, SessionRunId } from "@mosoo/id";
import { OpenAiPrivateCitationStreamFilter } from "agent-driver/provider-output";
import { and, asc, desc, eq, gt, lt } from "drizzle-orm";
import type { SQL } from "drizzle-orm";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getSessionOrganizationPath, getSessionRuntimeStatePath } from "@mosoo/agent-driver/paths";
import type { JsonObject } from "@mosoo/contracts";
import type { AgentKind, AgentReadiness } from "@mosoo/contracts/agent";
import type { AccountId, AgentId, SandboxId, SandboxSessionId, SessionId } from "@mosoo/id";
import { getSessionOrganizationPath, getSessionRuntimeStatePath } from "agent-driver/paths";

import type {
DriverConfigRevision,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DriverBootPayload } from "agent-driver/boot";
import type { DriverBootPayload } from "@mosoo/agent-driver/boot";

export interface DriverBootPayloadPreparedInput {
readonly bootPayload: DriverBootPayload;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getSessionOrganizationPath } from "@mosoo/agent-driver/paths";
import type { SessionSummary } from "@mosoo/contracts/session";
import type { UserWarning } from "@mosoo/contracts/session-run";
import type { ResolvedRunSkill } from "@mosoo/contracts/skill";
Expand All @@ -6,7 +7,6 @@ import type { AgentId, PlatformId, AppId, SandboxId, SandboxSessionId, SessionId
import { getRuntimeCatalogEntry, getRuntimeCatalogVendorForProvider } from "@mosoo/runtime-catalog";
import type { RuntimeCatalogVendor } from "@mosoo/runtime-catalog";
import { RUNTIME_DIAGNOSTIC_EVENT } from "@mosoo/runtime-events";
import { getSessionOrganizationPath } from "agent-driver/paths";

import type { ApiBindings } from "../../../../platform/cloudflare/worker-types";
import { validationError } from "../../../../platform/errors";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
MosooSessionConfigTraceMcpServer,
MosooSessionConfigTraceValue,
} from "@mosoo/ag-ui-session";
import type { DriverBootMcpServer, DriverBootPayload } from "agent-driver/boot";
import type { DriverBootMcpServer, DriverBootPayload } from "@mosoo/agent-driver/boot";

function summarizeMcpServer(server: DriverBootMcpServer): MosooSessionConfigTraceMcpServer {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DriverBootPayload, DriverRuntime } from "@mosoo/agent-driver/boot";
import { parsePlatformId } from "@mosoo/id";
import type { AgentId, DriverInstanceId, FileId, SessionId, SessionRunId } from "@mosoo/id";
import { RUNTIME_DIAGNOSTIC_EVENT } from "@mosoo/runtime-events";
import type { DriverBootPayload, DriverRuntime } from "agent-driver/boot";

import { logError, logInfo, logWarn } from "../../../../platform/cloudflare/logger";
import type { ApiBindings } from "../../../../platform/cloudflare/worker-types";
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/runtime/domain/driver-snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DriverRecoveryMessage } from "@mosoo/agent-driver/boot";
import type { DriverNativeRuntimeRef, DriverRuntime } from "@mosoo/agent-driver/runtime";
import type { JsonObject } from "@mosoo/contracts";
import type { AgentBuiltInToolConfig, AgentKind, AgentReadiness } from "@mosoo/contracts/agent";
import type {
Expand Down Expand Up @@ -27,8 +29,6 @@ import type {
SkillId,
SkillSnapshotId,
} from "@mosoo/id";
import type { DriverRecoveryMessage } from "agent-driver/boot";
import type { DriverNativeRuntimeRef, DriverRuntime } from "agent-driver/runtime";

export type { DriverRuntime };

Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/runtime/domain/runtime-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isSupportedDriverRuntime } from "@mosoo/agent-driver/runtime";
import type { DriverRuntime } from "@mosoo/agent-driver/runtime";
import { getRuntimeCatalogEntry } from "@mosoo/runtime-catalog";
import { isSupportedDriverRuntime } from "agent-driver/runtime";
import type { DriverRuntime } from "agent-driver/runtime";

export const DRIVER_BOOT_TOKEN_TTL_MS = 60_000;
export const RUNTIME_ACTION_TOKEN_TTL_MS = 10 * 60_000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SANDBOX_MEMORY_PATH } from "@mosoo/agent-driver/paths";
import { AGENT_KIND_RUNTIME_POLICIES } from "@mosoo/contracts/agent";
import type {
AgentKind,
Expand All @@ -6,7 +7,6 @@ import type {
AgentRuntimeTerminalTarget,
} from "@mosoo/contracts/agent";
import type { SandboxSubjectKind } from "@mosoo/contracts/sandbox";
import { SANDBOX_MEMORY_PATH } from "agent-driver/paths";

export type RuntimeSubjectScope = AgentRuntimeSubjectScope;
export type RuntimeCheckpointRule =
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/modules/runtime/domain/sandbox-layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DRIVER_CONTROL_PORT_MAX, DRIVER_CONTROL_PORT_MIN } from "@mosoo/agent-driver/boot";

const DRIVER_CONTROL_PORT_COUNT = DRIVER_CONTROL_PORT_MAX - DRIVER_CONTROL_PORT_MIN + 1;
import type { DriverInstanceId } from "@mosoo/id";
import { DRIVER_CONTROL_PORT_COUNT, DRIVER_CONTROL_PORT_MIN } from "agent-driver/boot";

function xorUint32(left: number, right: number): number {
let result = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DriverEventEnvelope } from "agent-driver/events";
import type { DriverEventReceipt } from "agent-driver/orpc";
import type { DriverEventEnvelope } from "@mosoo/agent-driver/events";
import type { DriverEventReceipt } from "@mosoo/agent-driver/orpc";

const MAX_PROCESSED_DRIVER_EVENT_RECEIPTS = 8192;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DRIVER_PROTOCOL_VERSION } from "@mosoo/agent-driver/boot";
import type { DriverRuntime } from "@mosoo/agent-driver/runtime";
import { driverCommandsTable, driverInstanceMcpGrantsTable, driverInstancesTable } from "@mosoo/db";
import type { DriverInstanceId, SandboxId, SessionId } from "@mosoo/id";
import { DRIVER_PROTOCOL_VERSION } from "agent-driver/boot";
import type { DriverRuntime } from "agent-driver/runtime";
import { and, desc, eq, inArray, notInArray, sql } from "drizzle-orm";
import type { SQL } from "drizzle-orm";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DriverLogBatchInput } from "agent-driver/orpc";
import type { DriverLogBatchInput } from "@mosoo/agent-driver/orpc";

import { createApiChildLogger, runWithApiLogContext } from "../../../../platform/cloudflare/logger";
import type { ApiBindings } from "../../../../platform/cloudflare/worker-types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createServerCustomEvent,
parseNullableSessionUsageSummary,
} from "@mosoo/ag-ui-session";
import type { DriverEventEnvelope } from "@mosoo/agent-driver/events";
import { parsePlatformId } from "@mosoo/id";
import type { DriverInstanceId } from "@mosoo/id";
import type { AccountId, SessionId } from "@mosoo/id";
Expand All @@ -16,7 +17,6 @@ import {
readRuntimeRunPayload,
} from "@mosoo/runtime-events";
import type { RuntimeEventEnvelope } from "@mosoo/runtime-events";
import type { DriverEventEnvelope } from "agent-driver/events";

import { createErrorLogContext, logInfo, logWarn } from "../../../../platform/cloudflare/logger";
import { withDisposedRpcResource } from "../../../../platform/cloudflare/rpc-disposal";
Expand Down Expand Up @@ -429,10 +429,7 @@ export async function appRuntimeDriverEvents(
function appendCanonicalEvent(source: DriverEventEnvelope, event: RuntimeEventEnvelope): void {
runtimeEvents.push({
event,
occurredAt:
typeof source.occurredAt === "number" && Number.isFinite(source.occurredAt)
? source.occurredAt
: null,
occurredAt: toDriverEventOccurredAtMs(source.occurredAt),
sourceEventId: resolveDriverEventPersistenceSourceId(source, event),
});
}
Expand All @@ -444,10 +441,7 @@ export async function appRuntimeDriverEvents(
): void {
sessionDeliveryEvents.push({
event: deliveryEvent,
occurredAt:
typeof source.occurredAt === "number" && Number.isFinite(source.occurredAt)
? source.occurredAt
: null,
occurredAt: toDriverEventOccurredAtMs(source.occurredAt),
sourceEventId: resolveDriverEventPersistenceSourceId(source, event),
});
}
Expand Down Expand Up @@ -619,6 +613,17 @@ export async function appRuntimeDriverEvents(
};
}

// Driver Contract v2 carries envelope occurredAt as an ISO 8601 string;
// persistence keeps epoch milliseconds. Unparsable or absent values stay null.
function toDriverEventOccurredAtMs(occurredAt: DriverEventEnvelope["occurredAt"]): number | null {
if (typeof occurredAt !== "string") {
return null;
}

const parsed = Date.parse(occurredAt);
return Number.isFinite(parsed) ? parsed : null;
}

function resolveDriverEventPersistenceSourceId(
source: DriverEventEnvelope,
event: RuntimeEventEnvelope,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type {
DriverHeartbeatInput,
DriverHelloInput,
DriverReadyInput,
} from "@mosoo/agent-driver/orpc";
import { driverInstancesTable } from "@mosoo/db";
import type { DriverInstanceId } from "@mosoo/id";
import type { DriverHeartbeatInput, DriverHelloInput, DriverReadyInput } from "agent-driver/orpc";
import { and, eq, inArray, sql } from "drizzle-orm";

import type { ApiBindings } from "../../../../platform/cloudflare/worker-types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DriverNativeRuntimeRef } from "@mosoo/agent-driver/runtime";
import { parseDriverNativeRuntimeRef } from "@mosoo/agent-driver/runtime";
import { readRuntimeEventPayload, readRuntimeEventString } from "@mosoo/runtime-events";
import type { RuntimeEventEnvelope } from "@mosoo/runtime-events";
import type { DriverNativeRuntimeRef } from "agent-driver/runtime";
import { parseDriverNativeRuntimeRef } from "agent-driver/runtime";

export function readNativeResumeRef(event: RuntimeEventEnvelope): DriverNativeRuntimeRef | null {
const payload = readRuntimeEventPayload(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {
DriverCommandUpdateInput,
DriverNextCommandInput,
DriverNextCommandOutput,
} from "@mosoo/agent-driver/orpc";
import { RuntimeCommandResult } from "@mosoo/contracts/runtime-command";
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";
import { parseSchemaValue } from "@mosoo/contracts/validation";
import { parsePlatformId } from "@mosoo/id";
import type { DriverCommandId } from "@mosoo/id";
import type {
DriverCommandUpdateInput,
DriverNextCommandInput,
DriverNextCommandOutput,
} from "agent-driver/orpc";

import {
claimNextQueuedRuntimeCommandRecord,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";
import type {
DriverCommandUpdateInput,
DriverCompletionInput,
Expand All @@ -13,7 +12,8 @@ import type {
DriverNextCommandInput,
DriverNextCommandOutput,
DriverReadyInput,
} from "agent-driver/orpc";
} from "@mosoo/agent-driver/orpc";
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";

import type { DriverInstanceRpcHandler, DriverInstanceRpcOperationContext } from "./rpc";
import { DriverInstanceRpcCommandController } from "./rpc-command-controller";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { parsePlatformId } from "@mosoo/id";
import type { SessionRunId } from "@mosoo/id";
import type { DriverEventEnvelope } from "agent-driver/events";
import type { DriverEventEnvelope } from "@mosoo/agent-driver/events";
import type {
DriverEventBatchInput,
DriverEventBatchOutput,
DriverEventReceipt,
DriverLogBatchInput,
DriverLogBatchOutput,
} from "agent-driver/orpc";
} from "@mosoo/agent-driver/orpc";
import { parsePlatformId } from "@mosoo/id";
import type { SessionRunId } from "@mosoo/id";

import { createErrorLogContext, logError } from "../../../../platform/cloudflare/logger";
import type { SessionDeliveryEvent } from "../../../sessions/application/session-live-state.service";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createPlatformId } from "@mosoo/id";
import type {
DriverHeartbeatInput,
DriverHelloInput,
DriverHelloOutput,
DriverReadyInput,
} from "agent-driver/orpc";
import { SANDBOX_ORGANIZATION_ROOT } from "agent-driver/paths";
} from "@mosoo/agent-driver/orpc";
import { SANDBOX_ORGANIZATION_ROOT } from "@mosoo/agent-driver/paths";
import { createPlatformId } from "@mosoo/id";

import { logInfo } from "../../../../platform/cloudflare/logger";
import { DRIVER_HEARTBEAT_INTERVAL_MS } from "../../domain/runtime-config";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DriverCompletionInput, DriverFailureInput } from "agent-driver/orpc";
import type { DriverCompletionInput, DriverFailureInput } from "@mosoo/agent-driver/orpc";

import { logError, logInfo } from "../../../../platform/cloudflare/logger";
import { syncSessionViewerState } from "../../../sessions/application/session-viewer-events.service";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { DriverCapability } from "@mosoo/contracts/driver-instance";
import {
RuntimeCommand,
RuntimeCommandResult,
RuntimeCommandStatus,
} from "@mosoo/contracts/runtime-command";
import { RunError } from "@mosoo/contracts/session-run";
import { NonEmptyString, PrimitiveRecord, parseSchemaValue } from "@mosoo/contracts/validation";
import { eventIterator, os } from "@orpc/server";
import { parseDriverEventEnvelope } from "agent-driver/events";
import { parseDriverEventEnvelope } from "@mosoo/agent-driver/events";
import type {
DriverCommandUpdateInput,
DriverCompletionInput,
Expand All @@ -23,7 +14,16 @@ import type {
DriverNextCommandInput,
DriverNextCommandOutput,
DriverReadyInput,
} from "agent-driver/orpc";
} from "@mosoo/agent-driver/orpc";
import { DriverCapability } from "@mosoo/contracts/driver-instance";
import {
RuntimeCommand,
RuntimeCommandResult,
RuntimeCommandStatus,
} from "@mosoo/contracts/runtime-command";
import { RunError } from "@mosoo/contracts/session-run";
import { NonEmptyString, PrimitiveRecord, parseSchemaValue } from "@mosoo/contracts/validation";
import { eventIterator, os } from "@orpc/server";
import { type } from "arktype";

const DriverHelloInputWire = type({
Expand Down Expand Up @@ -69,7 +69,7 @@ const DriverReadyInputWire = type({
const DriverEventEnvelopeWire = type({
event: "unknown",
eventId: NonEmptyString,
"occurredAt?": "number | null | undefined",
"occurredAt?": "string | null | undefined",
});

const DriverEventReceiptWire = type({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";
import type {
DriverCommandUpdateInput,
DriverCompletionInput,
Expand All @@ -13,7 +12,8 @@ import type {
DriverNextCommandInput,
DriverNextCommandOutput,
DriverReadyInput,
} from "agent-driver/orpc";
} from "@mosoo/agent-driver/orpc";
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";

import type { RuntimeOrpcContext } from "./rpc-wire";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DriverEventEnvelope } from "agent-driver/events";
import type { DriverEventEnvelope } from "@mosoo/agent-driver/events";

type ReplayRuntimeEvent = DriverEventEnvelope["event"];
type ReplayRuntimeEventPayload = Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { parseRuntimeCommand } from "@mosoo/contracts/runtime-command";
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";
import { parsePlatformId } from "@mosoo/id";
import type { DriverInstanceId } from "@mosoo/id";
import {
parseDriverHeartbeatInput,
parseDriverHelloInput,
parseDriverReadyInput,
} from "agent-driver/orpc";
import type { DriverHeartbeatInput, DriverHelloInput, DriverReadyInput } from "agent-driver/orpc";
} from "@mosoo/agent-driver/orpc";
import type {
DriverHeartbeatInput,
DriverHelloInput,
DriverReadyInput,
} from "@mosoo/agent-driver/orpc";
import { parseRuntimeCommand } from "@mosoo/contracts/runtime-command";
import type { RuntimeCommand } from "@mosoo/contracts/runtime-command";
import { parsePlatformId } from "@mosoo/id";
import type { DriverInstanceId } from "@mosoo/id";

import type { DriverInstanceCloseSnapshot } from "./state";

Expand Down
Loading
Loading