Repository navigation
Add package services runtime #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
4b8c2a7
Add package services runtime
cursoragent 8147b28
Bind package services in preview and test
cursoragent 05e040d
Polish package services review feedback
cursoragent 28f7fb8
Fix oauth workers env for package services
cursoragent 8397a00
Tighten package services runtime parity
cursoragent f3d0d47
Schedule package service auto-start alarms
cursoragent 21a9553
Tighten package service capability inputs
cursoragent b2c5bb3
Make package services gateway-friendly
cursoragent 5c894ad
Add package service timeout controls
cursoragent 97404a3
Export service helper from kody runtime
cursoragent cf3b668
Add Discord gateway package guide
cursoragent 1bf4480
Keep service runtime helpers in module execution
cursoragent a3a31bd
Polish package service runtime flow
cursoragent 02503bc
Recover package services after DO restart
cursoragent 9f66ded
Preserve explicit package service stops
cursoragent 7c6611c
Harden package service alarm behavior
cursoragent f9c49d4
Polish package service RPC handling
cursoragent 54641bc
Generalize package service examples
cursoragent 4790002
Tighten package service helper semantics
cursoragent 5428196
Retry MCP test server port binding
cursoragent fdf5f67
Clear stale package service stop requests
cursoragent 55301df
Refine package service lifecycle edges
cursoragent e5ccfe3
Isolate package service auto-start failures
cursoragent aa62f27
Polish package service runtime lifecycle
cursoragent 2cf25f4
Preserve null service timeout status
cursoragent 7d0a93e
Reuse saved package in service listing
cursoragent e4e06f4
Drop unused package service auto-start helper
cursoragent 2489d44
Rearm auto-start services after unexpected exits
cursoragent 9217317
Share package service status normalization
cursoragent 17cf643
Treat service_start as restart intent
cursoragent 4678d67
Retry auto-start services after alarm load errors
cursoragent 93d5de5
Back off auto-start alarm retries
cursoragent cf53f5b
Keep service status validation in runtime
cursoragent ad49d08
Honor autoStart when alarm retries fire
cursoragent cfe34b4
Back off runtime auto-start restarts
cursoragent 31d3271
Polish package service review follow-ups
cursoragent 7b06950
Trim package service runtime surface
cursoragent 597effc
Harden package service registry calls
cursoragent 07aba12
Align package app service list shape
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { defineDomain } from '../define-domain.ts' | ||
| import { capabilityDomainNames } from '../domain-metadata.ts' | ||
| import { serviceGetCapability } from './service-get.ts' | ||
| import { serviceListCapability } from './service-list.ts' | ||
| import { serviceStartCapability } from './service-start.ts' | ||
| import { serviceStopCapability } from './service-stop.ts' | ||
|
|
||
| export const servicesDomain = defineDomain({ | ||
| name: capabilityDomainNames.services, | ||
| description: | ||
| 'Package service capabilities for inspecting and controlling long-lived package-owned runtimes.', | ||
| keywords: ['service', 'package service', 'runtime', 'background', 'gateway'], | ||
| capabilities: [ | ||
| serviceListCapability, | ||
| serviceGetCapability, | ||
| serviceStartCapability, | ||
| serviceStopCapability, | ||
| ], | ||
| }) |
42 changes: 42 additions & 0 deletions
42
packages/worker/src/mcp/capabilities/services/service-get.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { defineDomainCapability } from '#mcp/capabilities/define-domain-capability.ts' | ||
| import { capabilityDomainNames } from '#mcp/capabilities/domain-metadata.ts' | ||
| import { z } from 'zod' | ||
| import { | ||
| normalizePackageServiceStatus, | ||
| packageServiceStatusSchema, | ||
| requirePackageServiceContext, | ||
| } from './shared.ts' | ||
|
|
||
| export const serviceGetCapability = defineDomainCapability( | ||
| capabilityDomainNames.services, | ||
| { | ||
| name: 'service_get', | ||
| description: | ||
| 'Get status for one package service declared under package.json#kody.services.', | ||
| keywords: ['service', 'status', 'package', 'inspect'], | ||
| readOnly: true, | ||
| idempotent: true, | ||
| destructive: false, | ||
| inputSchema: z.object({ | ||
| service_name: z.string().trim().min(1), | ||
| package_id: z.string().min(1).optional(), | ||
| }), | ||
| outputSchema: packageServiceStatusSchema, | ||
| async handler(args, ctx) { | ||
| const serviceContext = await requirePackageServiceContext({ | ||
| env: ctx.env, | ||
| callerContext: ctx.callerContext, | ||
| serviceName: args.service_name, | ||
| explicitPackageId: args.package_id, | ||
| }) | ||
| if (!serviceContext.service) { | ||
| throw new Error( | ||
| `Package service "${args.service_name}" was not found.`, | ||
| ) | ||
| } | ||
| return normalizePackageServiceStatus( | ||
| await serviceContext.service.status(), | ||
| ) | ||
| }, | ||
| }, | ||
| ) |
63 changes: 63 additions & 0 deletions
63
packages/worker/src/mcp/capabilities/services/service-list.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { z } from 'zod' | ||
| import { defineDomainCapability } from '#mcp/capabilities/define-domain-capability.ts' | ||
| import { capabilityDomainNames } from '#mcp/capabilities/domain-metadata.ts' | ||
| import { | ||
| listPackageServicesForContext, | ||
| packageServiceSummarySchema, | ||
| normalizePackageServiceStatus, | ||
| } from './shared.ts' | ||
|
|
||
| const inputSchema = z.object({ | ||
| package_id: z.string().min(1).optional(), | ||
| }) | ||
|
|
||
| const outputSchema = z.object({ | ||
| package_id: z.string(), | ||
| kody_id: z.string(), | ||
| services: z.array(packageServiceSummarySchema), | ||
| }) | ||
|
|
||
| export const serviceListCapability = defineDomainCapability( | ||
| capabilityDomainNames.services, | ||
| { | ||
| name: 'service_list', | ||
| description: | ||
| 'List package services declared by a saved package, including their current runtime status.', | ||
| keywords: ['service', 'services', 'package', 'list', 'status'], | ||
| readOnly: true, | ||
| idempotent: true, | ||
| destructive: false, | ||
| inputSchema, | ||
| outputSchema, | ||
| async handler(args, ctx) { | ||
| const listed = await listPackageServicesForContext({ | ||
| env: ctx.env, | ||
| callerContext: ctx.callerContext, | ||
| explicitPackageId: args.package_id, | ||
| }) | ||
| const services = await Promise.all( | ||
| listed.services.map(async (service) => { | ||
| let status: z.infer<typeof packageServiceSummarySchema>['status'] = 'error' | ||
| try { | ||
| status = normalizePackageServiceStatus( | ||
| await listed.rpc(service.name).status(), | ||
| ).status | ||
| } catch { | ||
| // Keep the rest of the service list usable if one status lookup fails. | ||
| } | ||
| return { | ||
| name: service.name, | ||
| entry: service.entry, | ||
| auto_start: service.auto_start, | ||
| status, | ||
| } | ||
| }), | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| return { | ||
| package_id: listed.savedPackage.id, | ||
| kody_id: listed.savedPackage.kodyId, | ||
| services, | ||
| } | ||
| }, | ||
| }, | ||
| ) | ||
46 changes: 46 additions & 0 deletions
46
packages/worker/src/mcp/capabilities/services/service-start.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { z } from 'zod' | ||
| import { defineDomainCapability } from '#mcp/capabilities/define-domain-capability.ts' | ||
| import { capabilityDomainNames } from '#mcp/capabilities/domain-metadata.ts' | ||
| import { requirePackageServiceContext } from './shared.ts' | ||
|
|
||
| const inputSchema = z.object({ | ||
| service_name: z.string().min(1), | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| package_id: z.string().min(1).optional(), | ||
| }) | ||
|
|
||
| const outputSchema = z.object({ | ||
| ok: z.boolean(), | ||
| result: z.unknown().optional(), | ||
| error: z.string().optional(), | ||
| started_at: z.string().optional(), | ||
| finished_at: z.string().optional(), | ||
| }) | ||
|
|
||
| export const serviceStartCapability = defineDomainCapability( | ||
| capabilityDomainNames.services, | ||
| { | ||
| name: 'service_start', | ||
| description: | ||
| 'Start a package service instance and return the latest execution result.', | ||
| keywords: ['service', 'start', 'package service', 'runtime'], | ||
| readOnly: false, | ||
| idempotent: false, | ||
| destructive: false, | ||
| inputSchema, | ||
| outputSchema, | ||
| async handler(args, ctx) { | ||
| const serviceContext = await requirePackageServiceContext({ | ||
| env: ctx.env, | ||
| callerContext: ctx.callerContext, | ||
| serviceName: args.service_name, | ||
| explicitPackageId: args.package_id, | ||
| }) | ||
| if (!serviceContext.service) { | ||
| throw new Error( | ||
| `Package service "${args.service_name}" was not found for this package.`, | ||
| ) | ||
| } | ||
| return await serviceContext.service.start() | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }, | ||
| }, | ||
| ) | ||
44 changes: 44 additions & 0 deletions
44
packages/worker/src/mcp/capabilities/services/service-stop.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { z } from 'zod' | ||
| import { defineDomainCapability } from '#mcp/capabilities/define-domain-capability.ts' | ||
| import { capabilityDomainNames } from '#mcp/capabilities/domain-metadata.ts' | ||
| import { requirePackageServiceContext } from './shared.ts' | ||
|
|
||
| const inputSchema = z.object({ | ||
| service_name: z.string().trim().min(1), | ||
| package_id: z.string().min(1).optional(), | ||
| }) | ||
|
|
||
| const outputSchema = z.object({ | ||
| ok: z.boolean(), | ||
| }) | ||
|
|
||
| export const serviceStopCapability = defineDomainCapability( | ||
| capabilityDomainNames.services, | ||
| { | ||
| name: 'service_stop', | ||
| description: 'Stop one declared package service instance.', | ||
| keywords: ['service', 'stop', 'package'], | ||
| readOnly: false, | ||
| idempotent: false, | ||
| destructive: false, | ||
| inputSchema, | ||
| outputSchema, | ||
| async handler(args, ctx) { | ||
| const serviceContext = await requirePackageServiceContext({ | ||
| env: ctx.env, | ||
| callerContext: ctx.callerContext, | ||
| serviceName: args.service_name, | ||
| explicitPackageId: args.package_id, | ||
| }) | ||
| if (!serviceContext.service) { | ||
| throw new Error( | ||
| `Package service "${args.service_name}" was not found.`, | ||
| ) | ||
| } | ||
| const result = (await serviceContext.service.stop()) as { ok?: unknown } | ||
| return { | ||
| ok: result?.ok === true, | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| }, | ||
| }, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.