npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@arke-institute/agent-core

v1.0.0

Published

Shared infrastructure for Arke agents - Durable Objects, routing, logging, and utilities

Downloads

48

Readme

@arke-institute/agent-core

Shared infrastructure for Arke agents - Durable Objects, routing, logging, and utilities.

Installation

npm install @arke-institute/agent-core

Overview

This package provides the foundation for building Arke agents that can handle long-running jobs using Cloudflare Durable Objects:

  • BaseAgentDO: Abstract Durable Object class with alarm-based processing
  • createAgentRouter: Factory for creating Hono routers with standard endpoints
  • Signature verification: Ed25519 signature verification for Arke requests
  • Logging: Structured job logging with persistence to Arke
  • Dispatcher: Utilities for invoking agents and polling their status

Usage

1. Create your Durable Object

Extend BaseAgentDO and implement the required methods:

import {
  BaseAgentDO,
  BaseJobState,
  AlarmState,
  StartRequest,
  JobResponse,
  BaseStatusResponse,
} from '@arke-institute/agent-core';

interface MyJobState extends BaseJobState {
  // Add your custom state fields
  customField: string;
}

interface MyEnv extends BaseAgentEnv {
  MY_AGENT_JOBS: DurableObjectNamespace;
}

export class MyAgentJob extends BaseAgentDO<MyJobState, MyEnv> {
  protected async handleStart(request: StartRequest): Promise<JobResponse> {
    // Initialize job state
    const state: MyJobState = {
      job_id: request.job_id,
      status: 'pending',
      // ... other fields
    };
    await this.saveState(state);
    await this.scheduleImmediateAlarm();
    return { accepted: true, job_id: request.job_id };
  }

  protected async processAlarm(state: MyJobState, alarmState: AlarmState): Promise<boolean> {
    // Process one unit of work
    // Return true to continue, false when done
    return false;
  }

  protected getStatusResponse(state: MyJobState): BaseStatusResponse {
    return {
      job_id: state.job_id,
      status: state.status,
      // ... other fields
    };
  }
}

2. Create your router

Use createAgentRouter to create a Hono router with standard endpoints:

import { createAgentRouter } from '@arke-institute/agent-core';

const app = createAgentRouter<MyEnv>({
  doBindingName: 'MY_AGENT_JOBS',
  healthData: (env) => ({
    custom: 'data',
  }),
});

export default app;
export { MyAgentJob };

3. Configure wrangler.jsonc

{
  "name": "my-agent",
  "main": "src/index.ts",
  "compatibility_date": "2024-12-01",
  "compatibility_flags": ["nodejs_compat"],

  "durable_objects": {
    "bindings": [
      {
        "name": "MY_AGENT_JOBS",
        "class_name": "MyAgentJob"
      }
    ]
  },

  "migrations": [
    {
      "tag": "v1",
      "new_classes": ["MyAgentJob"]
    }
  ]
}

API Reference

BaseAgentDO

Abstract class for Durable Object-based agents.

Protected Methods to Implement:

  • handleStart(request): Initialize job state on new request
  • processAlarm(state, alarmState): Process one unit of work
  • getStatusResponse(state): Format status for client

Protected Helpers:

  • getState() / saveState(state): Manage job state
  • getAlarmState() / saveAlarmState(state): Manage alarm state
  • scheduleAlarm(delayMs) / scheduleImmediateAlarm(): Schedule alarms
  • failJob(state, code, message) / completeJob(state, result): Finalize jobs
  • getLogger(): Get JobLogger instance

createAgentRouter

Factory for creating Hono routers with standard endpoints:

  • GET /health: Health check
  • POST /process: Accept new jobs (with signature verification)
  • GET /status/:job_id: Query job status

dispatchToAgent

Invoke another agent via the Arke API:

const result = await dispatchToAgent(client, agentId, {
  target: 'collection_id',
  jobCollection: 'job_collection_id',
  input: { /* agent-specific input */ },
});

pollAgentStatus

Poll an agent's status endpoint:

const result = await pollAgentStatus(endpoint, jobId);
if (result.done) {
  console.log(result.status, result.result);
}

JobLogger

Structured logging during job execution:

const logger = new JobLogger('my-agent');
logger.info('Processing started', { count: 10 });
logger.success('Entity completed', { entityId: '...' });
logger.error('Failed', { error: '...' });

writeJobLog

Write job log to Arke job collection:

await writeJobLog(client, jobCollectionId, {
  job_id: '...',
  agent_id: '...',
  status: 'done',
  entries: logger.getEntries(),
});

License

MIT