@agent-native/core 0.90.3 → 0.90.5
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/bin/agent-native.js +25 -3
- package/corpus/README.md +1 -1
- package/corpus/core/CHANGELOG.md +17 -0
- package/corpus/core/bin/agent-native.js +25 -3
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/agent/durable-background.ts +18 -18
- package/corpus/core/src/agent/engine/ai-sdk-engine.ts +8 -2
- package/corpus/core/src/agent/engine/anthropic-engine.ts +11 -1
- package/corpus/core/src/agent/engine/index.ts +1 -0
- package/corpus/core/src/agent/engine/registry.ts +63 -2
- package/corpus/core/src/agent/production-agent.ts +22 -11
- package/corpus/core/src/agent/run-manager.ts +17 -6
- package/corpus/core/src/agent/run-store.ts +16 -11
- package/corpus/core/src/cli/create.ts +35 -0
- package/corpus/core/src/cli/design-connect.ts +263 -1
- package/corpus/core/src/cli/index.ts +84 -7
- package/corpus/core/src/cli/workspacify.ts +34 -0
- package/corpus/core/src/client/KeepTabOpenNotice.tsx +20 -15
- package/corpus/core/src/client/RunStuckBanner.tsx +14 -13
- package/corpus/core/src/client/agent-chat-adapter.ts +28 -17
- package/corpus/core/src/client/history/VersionHistoryPanel.tsx +77 -47
- package/corpus/core/src/client/history/index.ts +3 -0
- package/corpus/core/src/client/history/use-history.ts +28 -0
- package/corpus/core/src/client/index.ts +8 -0
- package/corpus/core/src/client/review/index.ts +5 -0
- package/corpus/core/src/client/review/use-review.ts +40 -2
- package/corpus/core/src/client/use-run-stuck-detection.ts +8 -5
- package/corpus/core/src/history/actions/create-resource-version.ts +11 -8
- package/corpus/core/src/history/index.ts +0 -1
- package/corpus/core/src/history/registry.ts +24 -12
- package/corpus/core/src/history/store.ts +84 -53
- package/corpus/core/src/review/actions/consume-review-feedback.ts +15 -5
- package/corpus/core/src/review/actions/delete-review-comment.ts +15 -3
- package/corpus/core/src/review/actions/resolve-review-thread.ts +12 -5
- package/corpus/core/src/review/index.ts +0 -5
- package/corpus/core/src/review/registry.ts +24 -12
- package/corpus/core/src/review/store.ts +10 -7
- package/corpus/core/src/server/agent-chat-plugin.ts +6 -0
- package/corpus/core/src/server/credential-provider.ts +13 -3
- package/corpus/templates/assets/actions/_preset-skeleton-validation.ts +11 -11
- package/corpus/templates/assets/actions/generate-image.ts +64 -28
- package/corpus/templates/assets/app/components/generation/GenerationResults.tsx +1 -1
- package/corpus/templates/assets/app/routes/brand-kits.$id_.presets.$presetId.tsx +91 -74
- package/corpus/templates/assets/server/lib/generation.ts +29 -4
- package/corpus/templates/assets/server/lib/image-processing.ts +131 -0
- package/corpus/templates/calendar/.agents/skills/event-management/SKILL.md +24 -2
- package/corpus/templates/calendar/AGENTS.md +3 -0
- package/corpus/templates/calendar/actions/create-event.ts +8 -34
- package/corpus/templates/calendar/actions/event-action-helpers.ts +52 -0
- package/corpus/templates/calendar/actions/manage-event-draft.ts +7 -34
- package/corpus/templates/calendar/actions/update-event.ts +10 -23
- package/corpus/templates/calendar/app/components/calendar/AttendeeAutocomplete.tsx +47 -0
- package/corpus/templates/calendar/app/components/calendar/CreateEventDialog.tsx +23 -0
- package/corpus/templates/calendar/app/components/calendar/EventAttendeesSection.tsx +59 -2
- package/corpus/templates/calendar/app/components/calendar/EventDetailPanel.tsx +40 -1
- package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +34 -1
- package/corpus/templates/calendar/app/hooks/use-events.ts +6 -0
- package/corpus/templates/calendar/app/i18n/zh-TW.ts +4 -0
- package/corpus/templates/calendar/app/i18n-data.ts +40 -0
- package/corpus/templates/calendar/changelog/2026-07-07-you-can-mark-event-guests-as-optional-while-inviting-them-or.md +6 -0
- package/corpus/templates/calendar/server/handlers/events.ts +1 -0
- package/corpus/templates/calendar/server/lib/google-calendar.ts +4 -0
- package/corpus/templates/calendar/server/plugins/agent-chat.ts +1 -1
- package/corpus/templates/calendar/shared/api.ts +2 -0
- package/corpus/templates/clips/.agents/skills/ai-video-tools/SKILL.md +29 -3
- package/corpus/templates/clips/actions/generate-workflow.ts +19 -8
- package/corpus/templates/clips/actions/get-clips-ai-prefs.ts +36 -0
- package/corpus/templates/clips/actions/lib/clips-ai-prefs.ts +28 -0
- package/corpus/templates/clips/actions/regenerate-chapters.ts +21 -7
- package/corpus/templates/clips/actions/regenerate-summary.ts +26 -8
- package/corpus/templates/clips/actions/regenerate-title.ts +44 -7
- package/corpus/templates/clips/actions/update-clips-ai-prefs.ts +50 -0
- package/corpus/templates/clips/app/components/meetings/meeting-card.tsx +7 -2
- package/corpus/templates/clips/app/hooks/use-auto-title.ts +25 -10
- package/corpus/templates/clips/app/i18n/ar-SA.ts +28 -6
- package/corpus/templates/clips/app/i18n/de-DE.ts +28 -6
- package/corpus/templates/clips/app/i18n/en-US.ts +29 -6
- package/corpus/templates/clips/app/i18n/es-ES.ts +29 -6
- package/corpus/templates/clips/app/i18n/fr-FR.ts +30 -6
- package/corpus/templates/clips/app/i18n/hi-IN.ts +26 -6
- package/corpus/templates/clips/app/i18n/ja-JP.ts +27 -6
- package/corpus/templates/clips/app/i18n/ko-KR.ts +28 -6
- package/corpus/templates/clips/app/i18n/pt-BR.ts +28 -6
- package/corpus/templates/clips/app/i18n/zh-CN.ts +26 -6
- package/corpus/templates/clips/app/i18n/zh-TW.ts +25 -6
- package/corpus/templates/clips/app/routes/_app.meetings._index.tsx +73 -0
- package/corpus/templates/clips/app/routes/_app.settings._index.tsx +1 -0
- package/corpus/templates/clips/app/routes/r.$recordingId.tsx +70 -2
- package/corpus/templates/clips/changelog/2026-07-07-ai-tools-can-include-the-full-video-not-just-the-transcript-.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-07-clips-desktop-now-surfaces-meetings-and-dictate-directly-in-.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-07-meeting-notes-now-explain-exactly-how-to-start-granola-style.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-07-meeting-start-alerts-now-include-separate-start-notes-and-jo.md +6 -0
- package/corpus/templates/clips/changelog/2026-07-07-recordings-start-more-predictably-and-newly-saved-clips-refr.md +6 -0
- package/corpus/templates/clips/chrome-extension/public/manifest.json +1 -1
- package/corpus/templates/clips/desktop/src/app.tsx +435 -105
- package/corpus/templates/clips/desktop/src/lib/recorder.ts +27 -21
- package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +23 -22
- package/corpus/templates/clips/desktop/src/styles.css +167 -2
- package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +1 -1
- package/corpus/templates/clips/desktop/src-tauri/src/notifications.rs +3 -7
- package/corpus/templates/clips/desktop/src-tauri/src/tray_meetings.rs +5 -4
- package/corpus/templates/clips/server/routes/_agent-native/clips/user-prefs.put.ts +16 -8
- package/corpus/templates/clips/shared/clips-ai-prefs.ts +81 -0
- package/corpus/templates/content/AGENTS.md +1 -0
- package/corpus/templates/content/actions/_database-source-utils.ts +73 -8
- package/corpus/templates/content/actions/_database-utils.ts +2 -1
- package/corpus/templates/content/actions/prepare-builder-source-review.ts +20 -1
- package/corpus/templates/content/actions/stage-builder-source-bulk-update.ts +663 -0
- package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +33 -7
- package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +53 -4
- package/corpus/templates/content/app/components/editor/database/settings.tsx +24 -0
- package/corpus/templates/content/app/hooks/use-content-database.ts +70 -1
- package/corpus/templates/content/app/hooks/use-document-properties.ts +63 -5
- package/corpus/templates/content/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/content/app/i18n-data.ts +31 -0
- package/corpus/templates/content/changelog/2026-07-01-builder-source-rows-can-be-staged-in-bulk-with-a-reviewable.md +6 -0
- package/corpus/templates/content/changelog/2026-07-07-builder-backed-database-fields-now-edit-like-normal-content-fields.md +6 -0
- package/corpus/templates/content/parity/matrix.md +24 -24
- package/corpus/templates/content/parity/matrix.ts +2 -0
- package/corpus/templates/content/shared/api.ts +59 -4
- package/corpus/templates/design/.agents/skills/visual-edit/SKILL.md +16 -1
- package/corpus/templates/design/actions/add-localhost-screens.ts +1 -0
- package/corpus/templates/design/actions/connect-localhost.ts +26 -3
- package/corpus/templates/design/actions/open-visual-edit.ts +4 -37
- package/corpus/templates/design/app/components/design/DesignCanvas.tsx +362 -12
- package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +89 -14
- package/corpus/templates/design/app/components/design/bridge-security.ts +7 -1
- package/corpus/templates/design/app/components/design/multi-screen/types.ts +1 -1
- package/corpus/templates/design/app/i18n/zh-TW.ts +3 -0
- package/corpus/templates/design/app/i18n-data.ts +41 -0
- package/corpus/templates/design/changelog/2026-07-07-local-visual-edit-keeps-bridge-access-when-opening-previousl.md +6 -0
- package/corpus/templates/design/changelog/2026-07-07-local-visual-edit-now-keeps-the-live-app-connection-authenti.md +6 -0
- package/corpus/templates/design/changelog/2026-07-07-local-visual-edit-uses-live-app-iframes-for-click-to-edit-pr.md +6 -0
- package/dist/agent/durable-background.d.ts +12 -12
- package/dist/agent/durable-background.js +18 -18
- package/dist/agent/durable-background.js.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.js +8 -2
- package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
- package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
- package/dist/agent/engine/anthropic-engine.js +11 -1
- package/dist/agent/engine/anthropic-engine.js.map +1 -1
- package/dist/agent/engine/index.d.ts +1 -1
- package/dist/agent/engine/index.d.ts.map +1 -1
- package/dist/agent/engine/index.js +1 -1
- package/dist/agent/engine/index.js.map +1 -1
- package/dist/agent/engine/registry.d.ts +14 -0
- package/dist/agent/engine/registry.d.ts.map +1 -1
- package/dist/agent/engine/registry.js +56 -2
- package/dist/agent/engine/registry.js.map +1 -1
- package/dist/agent/production-agent.d.ts +2 -2
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +18 -11
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts +7 -1
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +6 -1
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts +1 -1
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +15 -10
- package/dist/agent/run-store.js.map +1 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +31 -0
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/design-connect.d.ts.map +1 -1
- package/dist/cli/design-connect.js +197 -1
- package/dist/cli/design-connect.js.map +1 -1
- package/dist/cli/index.js +76 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/workspacify.d.ts.map +1 -1
- package/dist/cli/workspacify.js +30 -0
- package/dist/cli/workspacify.js.map +1 -1
- package/dist/client/KeepTabOpenNotice.d.ts +9 -10
- package/dist/client/KeepTabOpenNotice.d.ts.map +1 -1
- package/dist/client/KeepTabOpenNotice.js +8 -4
- package/dist/client/KeepTabOpenNotice.js.map +1 -1
- package/dist/client/RunStuckBanner.d.ts.map +1 -1
- package/dist/client/RunStuckBanner.js +14 -13
- package/dist/client/RunStuckBanner.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +25 -17
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/history/VersionHistoryPanel.d.ts +1 -1
- package/dist/client/history/VersionHistoryPanel.d.ts.map +1 -1
- package/dist/client/history/VersionHistoryPanel.js +12 -5
- package/dist/client/history/VersionHistoryPanel.js.map +1 -1
- package/dist/client/history/index.d.ts +1 -1
- package/dist/client/history/index.d.ts.map +1 -1
- package/dist/client/history/index.js +1 -1
- package/dist/client/history/index.js.map +1 -1
- package/dist/client/history/use-history.d.ts +12 -0
- package/dist/client/history/use-history.d.ts.map +1 -1
- package/dist/client/history/use-history.js +6 -0
- package/dist/client/history/use-history.js.map +1 -1
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/review/index.d.ts +1 -1
- package/dist/client/review/index.d.ts.map +1 -1
- package/dist/client/review/index.js +1 -1
- package/dist/client/review/index.js.map +1 -1
- package/dist/client/review/use-review.d.ts +23 -0
- package/dist/client/review/use-review.d.ts.map +1 -1
- package/dist/client/review/use-review.js +8 -0
- package/dist/client/review/use-review.js.map +1 -1
- package/dist/client/use-run-stuck-detection.d.ts +1 -1
- package/dist/client/use-run-stuck-detection.d.ts.map +1 -1
- package/dist/client/use-run-stuck-detection.js +6 -4
- package/dist/client/use-run-stuck-detection.js.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/history/actions/create-resource-version.js +7 -4
- package/dist/history/actions/create-resource-version.js.map +1 -1
- package/dist/history/index.d.ts +1 -1
- package/dist/history/index.d.ts.map +1 -1
- package/dist/history/index.js +1 -1
- package/dist/history/index.js.map +1 -1
- package/dist/history/registry.d.ts.map +1 -1
- package/dist/history/registry.js +14 -12
- package/dist/history/registry.js.map +1 -1
- package/dist/history/store.d.ts.map +1 -1
- package/dist/history/store.js +74 -49
- package/dist/history/store.js.map +1 -1
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/resources/handlers.d.ts +3 -3
- package/dist/review/actions/consume-review-feedback.d.ts +1 -0
- package/dist/review/actions/consume-review-feedback.js +8 -2
- package/dist/review/actions/consume-review-feedback.js.map +1 -1
- package/dist/review/actions/delete-review-comment.d.ts +2 -1
- package/dist/review/actions/delete-review-comment.js +11 -3
- package/dist/review/actions/delete-review-comment.js.map +1 -1
- package/dist/review/actions/resolve-review-thread.d.ts +2 -1
- package/dist/review/actions/resolve-review-thread.js +5 -2
- package/dist/review/actions/resolve-review-thread.js.map +1 -1
- package/dist/review/index.d.ts +1 -1
- package/dist/review/index.d.ts.map +1 -1
- package/dist/review/index.js +1 -1
- package/dist/review/index.js.map +1 -1
- package/dist/review/registry.d.ts.map +1 -1
- package/dist/review/registry.js +14 -12
- package/dist/review/registry.js.map +1 -1
- package/dist/review/store.d.ts +3 -3
- package/dist/review/store.d.ts.map +1 -1
- package/dist/review/store.js +7 -4
- package/dist/review/store.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +5 -0
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/credential-provider.d.ts +2 -0
- package/dist/server/credential-provider.d.ts.map +1 -1
- package/dist/server/credential-provider.js +13 -3
- package/dist/server/credential-provider.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,6 +11,15 @@ export interface ListReviewCommentsResult {
|
|
|
11
11
|
comments: ReviewComment[];
|
|
12
12
|
reviewStatus: ReviewStatusEntry | null;
|
|
13
13
|
}
|
|
14
|
+
export interface GetReviewFeedbackParams {
|
|
15
|
+
resourceType: string;
|
|
16
|
+
resourceId: string;
|
|
17
|
+
includeHumanTargeted?: boolean;
|
|
18
|
+
limit?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface GetReviewFeedbackResult {
|
|
21
|
+
comments: ReviewComment[];
|
|
22
|
+
}
|
|
14
23
|
export interface CreateReviewCommentInput {
|
|
15
24
|
resourceType: string;
|
|
16
25
|
resourceId: string;
|
|
@@ -44,6 +53,11 @@ export interface DeleteReviewCommentInput {
|
|
|
44
53
|
resourceId: string;
|
|
45
54
|
commentId: string;
|
|
46
55
|
}
|
|
56
|
+
export interface ConsumeReviewFeedbackInput {
|
|
57
|
+
resourceType: string;
|
|
58
|
+
resourceId: string;
|
|
59
|
+
commentIds: string[];
|
|
60
|
+
}
|
|
47
61
|
export interface SetReviewStatusInput {
|
|
48
62
|
resourceType: string;
|
|
49
63
|
resourceId: string;
|
|
@@ -54,15 +68,24 @@ export interface SetReviewStatusInput {
|
|
|
54
68
|
export declare function useReviewComments(params: ListReviewCommentsParams, options?: {
|
|
55
69
|
enabled?: boolean;
|
|
56
70
|
}): import("@tanstack/react-query").UseQueryResult<NoInfer<ListReviewCommentsResult>, Error>;
|
|
71
|
+
export declare function useReviewFeedback(params: GetReviewFeedbackParams, options?: {
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
}): import("@tanstack/react-query").UseQueryResult<NoInfer<GetReviewFeedbackResult>, Error>;
|
|
57
74
|
export declare function useCreateReviewComment(): import("@tanstack/react-query").UseMutationResult<ReviewComment, Error, CreateReviewCommentInput, unknown>;
|
|
58
75
|
export declare function useReplyReviewComment(): import("@tanstack/react-query").UseMutationResult<ReviewComment, Error, ReplyReviewCommentInput, unknown>;
|
|
59
76
|
export declare function useResolveReviewThread(): import("@tanstack/react-query").UseMutationResult<{
|
|
60
77
|
threadId: string;
|
|
61
78
|
resolved: true;
|
|
79
|
+
updatedCount: number;
|
|
62
80
|
}, Error, ResolveReviewThreadInput, unknown>;
|
|
63
81
|
export declare function useDeleteReviewComment(): import("@tanstack/react-query").UseMutationResult<{
|
|
64
82
|
commentId: string;
|
|
65
83
|
deleted: true;
|
|
84
|
+
updatedCount: number;
|
|
66
85
|
}, Error, DeleteReviewCommentInput, unknown>;
|
|
86
|
+
export declare function useConsumeReviewFeedback(): import("@tanstack/react-query").UseMutationResult<{
|
|
87
|
+
consumedCommentIds: string[];
|
|
88
|
+
updatedCount: number;
|
|
89
|
+
}, Error, ConsumeReviewFeedbackInput, unknown>;
|
|
67
90
|
export declare function useSetReviewStatus(): import("@tanstack/react-query").UseMutationResult<ReviewStatusEntry, Error, SetReviewStatusInput, unknown>;
|
|
68
91
|
//# sourceMappingURL=use-review.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-review.d.ts","sourceRoot":"","sources":["../../../src/client/review/use-review.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;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,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,4FAUhC;AAED,wBAAgB,sBAAsB,+GAIrC;AAED,wBAAgB,qBAAqB,8GAIpC;AAED,wBAAgB,sBAAsB;cAEtB,MAAM;cAAY,IAAI;
|
|
1
|
+
{"version":3,"file":"use-review.d.ts","sourceRoot":"","sources":["../../../src/client/review/use-review.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAG/B,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,aAAa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Q,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,4FAUhC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,uBAAuB,EAC/B,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,2FAUhC;AAED,wBAAgB,sBAAsB,+GAIrC;AAED,wBAAgB,qBAAqB,8GAIpC;AAED,wBAAgB,sBAAsB;cAEtB,MAAM;cAAY,IAAI;kBAAgB,MAAM;6CAG3D;AAED,wBAAgB,sBAAsB;eAErB,MAAM;aAAW,IAAI;kBAAgB,MAAM;6CAG3D;AAED,wBAAgB,wBAAwB;wBAEd,MAAM,EAAE;kBAAgB,MAAM;+CAGvD;AAED,wBAAgB,kBAAkB,+GAIjC"}
|
|
@@ -4,6 +4,11 @@ export function useReviewComments(params, options) {
|
|
|
4
4
|
enabled: options?.enabled ?? Boolean(params.resourceType && params.resourceId),
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
|
+
export function useReviewFeedback(params, options) {
|
|
8
|
+
return useActionQuery("get-review-feedback", params, {
|
|
9
|
+
enabled: options?.enabled ?? Boolean(params.resourceType && params.resourceId),
|
|
10
|
+
});
|
|
11
|
+
}
|
|
7
12
|
export function useCreateReviewComment() {
|
|
8
13
|
return useActionMutation("create-review-comment");
|
|
9
14
|
}
|
|
@@ -16,6 +21,9 @@ export function useResolveReviewThread() {
|
|
|
16
21
|
export function useDeleteReviewComment() {
|
|
17
22
|
return useActionMutation("delete-review-comment");
|
|
18
23
|
}
|
|
24
|
+
export function useConsumeReviewFeedback() {
|
|
25
|
+
return useActionMutation("consume-review-feedback");
|
|
26
|
+
}
|
|
19
27
|
export function useSetReviewStatus() {
|
|
20
28
|
return useActionMutation("set-review-status");
|
|
21
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-review.js","sourceRoot":"","sources":["../../../src/client/review/use-review.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-review.js","sourceRoot":"","sources":["../../../src/client/review/use-review.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA8ErE,MAAM,UAAU,iBAAiB,CAC/B,MAAgC,EAChC,OAA+B;IAE/B,OAAO,cAAc,CACnB,sBAAsB,EACtB,MAAM,EACN;QACE,OAAO,EACL,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,UAAU,CAAC;KACxE,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAA+B,EAC/B,OAA+B;IAE/B,OAAO,cAAc,CACnB,qBAAqB,EACrB,MAAM,EACN;QACE,OAAO,EACL,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,UAAU,CAAC;KACxE,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,iBAAiB,CACtB,uBAAuB,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO,iBAAiB,CACtB,sBAAsB,CACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,iBAAiB,CAGtB,uBAAuB,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,iBAAiB,CAGtB,uBAAuB,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,iBAAiB,CAGtB,yBAAyB,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,iBAAiB,CACtB,mBAAmB,CACpB,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ReviewComment,\n ReviewCommentKind,\n ReviewMention,\n ReviewResolutionTarget,\n ReviewStatus,\n ReviewStatusEntry,\n} from \"../../review/types.js\";\nimport { useActionMutation, useActionQuery } from \"../use-action.js\";\n\nexport interface ListReviewCommentsParams {\n resourceType: string;\n resourceId: string;\n includeResolved?: boolean;\n includeDeleted?: boolean;\n targetId?: string | null;\n limit?: number;\n}\n\nexport interface ListReviewCommentsResult {\n comments: ReviewComment[];\n reviewStatus: ReviewStatusEntry | null;\n}\n\nexport interface GetReviewFeedbackParams {\n resourceType: string;\n resourceId: string;\n includeHumanTargeted?: boolean;\n limit?: number;\n}\n\nexport interface GetReviewFeedbackResult {\n comments: ReviewComment[];\n}\n\nexport interface CreateReviewCommentInput {\n resourceType: string;\n resourceId: string;\n targetId?: string | null;\n kind?: ReviewCommentKind;\n anchor?: unknown | null;\n body: string;\n authorName?: string | null;\n resolutionTarget?: ReviewResolutionTarget | null;\n mentions?: ReviewMention[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface ReplyReviewCommentInput {\n resourceType: string;\n resourceId: string;\n commentId: string;\n body: string;\n authorName?: string | null;\n resolutionTarget?: ReviewResolutionTarget | null;\n mentions?: ReviewMention[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface ResolveReviewThreadInput {\n resourceType: string;\n resourceId: string;\n threadId?: string;\n commentId?: string;\n}\n\nexport interface DeleteReviewCommentInput {\n resourceType: string;\n resourceId: string;\n commentId: string;\n}\n\nexport interface ConsumeReviewFeedbackInput {\n resourceType: string;\n resourceId: string;\n commentIds: string[];\n}\n\nexport interface SetReviewStatusInput {\n resourceType: string;\n resourceId: string;\n status: ReviewStatus;\n note?: string | null;\n metadata?: Record<string, unknown>;\n}\n\nexport function useReviewComments(\n params: ListReviewCommentsParams,\n options?: { enabled?: boolean },\n) {\n return useActionQuery<ListReviewCommentsResult>(\n \"list-review-comments\",\n params,\n {\n enabled:\n options?.enabled ?? Boolean(params.resourceType && params.resourceId),\n },\n );\n}\n\nexport function useReviewFeedback(\n params: GetReviewFeedbackParams,\n options?: { enabled?: boolean },\n) {\n return useActionQuery<GetReviewFeedbackResult>(\n \"get-review-feedback\",\n params,\n {\n enabled:\n options?.enabled ?? Boolean(params.resourceType && params.resourceId),\n },\n );\n}\n\nexport function useCreateReviewComment() {\n return useActionMutation<ReviewComment, CreateReviewCommentInput>(\n \"create-review-comment\",\n );\n}\n\nexport function useReplyReviewComment() {\n return useActionMutation<ReviewComment, ReplyReviewCommentInput>(\n \"reply-review-comment\",\n );\n}\n\nexport function useResolveReviewThread() {\n return useActionMutation<\n { threadId: string; resolved: true; updatedCount: number },\n ResolveReviewThreadInput\n >(\"resolve-review-thread\");\n}\n\nexport function useDeleteReviewComment() {\n return useActionMutation<\n { commentId: string; deleted: true; updatedCount: number },\n DeleteReviewCommentInput\n >(\"delete-review-comment\");\n}\n\nexport function useConsumeReviewFeedback() {\n return useActionMutation<\n { consumedCommentIds: string[]; updatedCount: number },\n ConsumeReviewFeedbackInput\n >(\"consume-review-feedback\");\n}\n\nexport function useSetReviewStatus() {\n return useActionMutation<ReviewStatusEntry, SetReviewStatusInput>(\n \"set-review-status\",\n );\n}\n"]}
|
|
@@ -22,7 +22,7 @@ export interface RunStuckState {
|
|
|
22
22
|
heartbeatAt: number | null;
|
|
23
23
|
/** Milliseconds since `heartbeatAt`, computed against the server clock. */
|
|
24
24
|
heartbeatSinceMs: number | null;
|
|
25
|
-
/** How the run was dispatched, e.g. foreground or background-processing. */
|
|
25
|
+
/** How the run was dispatched/continued, e.g. foreground-self-chain or background-processing. */
|
|
26
26
|
dispatchMode: string | null;
|
|
27
27
|
}
|
|
28
28
|
export interface UseRunStuckDetectionOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-run-stuck-detection.d.ts","sourceRoot":"","sources":["../../src/client/use-run-stuck-detection.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,4EAA4E;IAC5E,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,oDAAoD;IACpD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iEAAiE;IACjE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,2EAA2E;IAC3E,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,
|
|
1
|
+
{"version":3,"file":"use-run-stuck-detection.d.ts","sourceRoot":"","sources":["../../src/client/use-run-stuck-detection.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,4EAA4E;IAC5E,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,oDAAoD;IACpD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,iEAAiE;IACjE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,2EAA2E;IAC3E,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iGAAiG;IACjG,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,qEAAqE;IACrE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;;;OAOG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,sCAAsC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,eAAO,MAAM,qCAAqC,SAAU,CAAC;AA0B7D,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,OAAc,EACd,gBAA6C,EAC7C,0BAAkE,EAClE,cAAyC,EACzC,MAAM,GACP,EAAE,2BAA2B,GAAG,aAAa,CAiG7C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,WAEzB,MAAM,WAAU,MAAM,KAAY,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBzE"}
|
|
@@ -46,10 +46,12 @@ export function useRunStuckDetection({ threadId, enabled = true, stuckThresholdM
|
|
|
46
46
|
const heartbeatAt = data.heartbeatAt ?? null;
|
|
47
47
|
const heartbeatSinceMs = heartbeatAt != null ? nowMs - heartbeatAt : null;
|
|
48
48
|
const dispatchMode = typeof data.dispatchMode === "string" ? data.dispatchMode : null;
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
const
|
|
49
|
+
// Server-continued runs get the wider threshold: the server's own
|
|
50
|
+
// recovery (150s no-progress backstop + chained continuations) must
|
|
51
|
+
// get its chance before the user sees a "stuck" affordance.
|
|
52
|
+
const serverContinued = dispatchMode === "foreground-self-chain" ||
|
|
53
|
+
dispatchMode?.startsWith("background") === true;
|
|
54
|
+
const effectiveThresholdMs = serverContinued
|
|
53
55
|
? backgroundStuckThresholdMs
|
|
54
56
|
: stuckThresholdMs;
|
|
55
57
|
const isStuck = Boolean(data.active &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-run-stuck-detection.js","sourceRoot":"","sources":["../../src/client/use-run-stuck-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA6DhD,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,CAAC,MAAM,qCAAqC,GAAG,OAAO,CAAC;AAC7D,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAaxC,MAAM,WAAW,GAAkB;IACjC,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,EACnC,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,gBAAgB,GAAG,0BAA0B,EAC7C,0BAA0B,GAAG,qCAAqC,EAClE,cAAc,GAAG,wBAAwB,EACzC,MAAM,GACsB;IAC5B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC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;YACjB,IAAI,KAAK;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC;IACJ,CAAC,EAAE;QACD,QAAQ;QACR,OAAO;QACP,gBAAgB;QAChB,0BAA0B;QAC1B,cAAc;QACd,MAAM;KACP,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,OAAO,WAAW,CAChB,KAAK,EAAE,KAAa,EAAE,MAAM,GAAW,MAAM,EAA0B,EAAE;QACvE,MAAM,IAAI,GAAG,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAC;QACpE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,GAAG,IAAI,SAAS,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EACjD;gBACE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,WAAW,EAAE,aAAa;gBAC1B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;aACjC,CACF,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useState, useCallback } from \"react\";\n\nimport { agentNativePath } from \"./api-path.js\";\n\n/**\n * Per-thread chat run health, derived from the durable `last_progress_at`\n * timestamp on the server. Drives the user-visible \"this chat looks stuck\"\n * affordance — distinct from the silent reconnect logic in\n * `agent-chat-adapter.ts`, which keeps trying in the background. When\n * automatic recovery isn't making progress (for whatever reason), this\n * hook surfaces a Retry / Cancel button to the user instead of leaving\n * them staring at a frozen spinner.\n */\nexport interface RunStuckState {\n /** True when an active run hasn't emitted an event for `stuckThresholdMs`. */\n isStuck: boolean;\n /** ID of the active run, or null when nothing is in flight. */\n runId: string | null;\n /** Server-side run status (\"running\" / \"completed\" / \"errored\" / etc.). */\n status: string | null;\n /** Server timestamp (ms) of the last emitted event, or null if none yet. */\n lastProgressAt: number | null;\n /** Milliseconds since `lastProgressAt`, or null. */\n stuckSinceMs: number | null;\n /** Server timestamp (ms) of the last process-alive heartbeat. */\n heartbeatAt: number | null;\n /** Milliseconds since `heartbeatAt`, computed against the server clock. */\n heartbeatSinceMs: number | null;\n /** How the run was dispatched, e.g. foreground or background-processing. */\n dispatchMode: string | null;\n}\n\nexport interface UseRunStuckDetectionOptions {\n /** The thread to monitor. Pass null/undefined to disable polling. */\n threadId: string | null | undefined;\n /**\n * Set false to skip scheduling the poll loop entirely — used to gate\n * polling to only the active chat tab when multiple tabs are mounted\n * (inactive tabs are kept alive via display:none, not unmounted).\n * Defaults to true.\n */\n enabled?: boolean;\n /**\n * Threshold above which an in-flight FOREGROUND run is considered stuck.\n * The default sits comfortably above the adapter's 75s no-progress\n * reconnect — by then automatic recovery has already had its chance.\n */\n stuckThresholdMs?: number;\n /**\n * Threshold for BACKGROUND-dispatched runs (dispatchMode starts with\n * \"background\"). The server owns recovery for these — its run-manager\n * no-progress backstop (150s) and unclaimed-run sweep act first — so the\n * user-facing \"stuck\" affordance is a late fallback, not a race against\n * them. Selected inside the hook because the dispatch mode is only known\n * from the same poll response that computes the elapsed time.\n */\n backgroundStuckThresholdMs?: number;\n /** Poll interval. Default 5_000ms. */\n pollIntervalMs?: number;\n /** API base path. Default `/_agent-native/agent-chat`. */\n apiUrl?: string;\n}\n\nconst DEFAULT_STUCK_THRESHOLD_MS = 90_000;\nexport const DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS = 180_000;\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\nconst IDLE_BACKOFF_INTERVAL_MS = 15_000;\n\ninterface ActiveRunResponse {\n active: boolean;\n runId?: string;\n status?: string;\n heartbeatAt: number | null;\n lastProgressAt?: number | null;\n dispatchMode?: string | null;\n /** Server clock at response time, used to compute elapsed server-relative. */\n serverNow?: number;\n}\n\nconst EMPTY_STATE: RunStuckState = {\n isStuck: false,\n runId: null,\n status: null,\n lastProgressAt: null,\n stuckSinceMs: null,\n heartbeatAt: null,\n heartbeatSinceMs: null,\n dispatchMode: null,\n};\n\nexport function useRunStuckDetection({\n threadId,\n enabled = true,\n stuckThresholdMs = DEFAULT_STUCK_THRESHOLD_MS,\n backgroundStuckThresholdMs = DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS,\n pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,\n apiUrl,\n}: UseRunStuckDetectionOptions): RunStuckState {\n const [state, setState] = useState<RunStuckState>(EMPTY_STATE);\n\n useEffect(() => {\n // Reset on every thread change so the previous thread's stuck banner\n // doesn't bleed onto the new one before the first poll completes.\n setState(EMPTY_STATE);\n if (!threadId || !enabled) return;\n\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n let cancelled = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const poll = async () => {\n if (cancelled) return;\n let nextDelay = pollIntervalMs;\n try {\n const res = await fetch(\n `${base}/runs/active?threadId=${encodeURIComponent(threadId)}`,\n { credentials: \"same-origin\" },\n );\n if (cancelled) return;\n if (res.ok) {\n const data = (await res.json()) as ActiveRunResponse;\n const lastProgressAt = data.lastProgressAt ?? null;\n // Measure elapsed against the SERVER clock (serverNow) rather than the\n // client's Date.now(). lastProgressAt is a server timestamp, so client\n // clock skew of more than stuckThresholdMs would otherwise mark every\n // run stuck (clock ahead) or never stuck (clock behind). Fall back to\n // the client clock for older bundles that don't send serverNow.\n const nowMs = data.serverNow ?? Date.now();\n const stuckSinceMs =\n lastProgressAt != null ? nowMs - lastProgressAt : null;\n const heartbeatAt = data.heartbeatAt ?? null;\n const heartbeatSinceMs =\n heartbeatAt != null ? nowMs - heartbeatAt : null;\n const dispatchMode =\n typeof data.dispatchMode === \"string\" ? data.dispatchMode : null;\n // Background-dispatched runs get the wider threshold: the server's\n // own recovery (150s no-progress backstop + chained continuations)\n // must get its chance before the user sees a \"stuck\" affordance.\n const effectiveThresholdMs = dispatchMode?.startsWith(\"background\")\n ? backgroundStuckThresholdMs\n : stuckThresholdMs;\n const isStuck = Boolean(\n data.active &&\n data.status === \"running\" &&\n stuckSinceMs != null &&\n stuckSinceMs > effectiveThresholdMs,\n );\n setState({\n isStuck,\n runId: data.runId ?? null,\n status: data.status ?? null,\n lastProgressAt,\n stuckSinceMs,\n heartbeatAt,\n heartbeatSinceMs,\n dispatchMode,\n });\n // Back off polling when nothing is in flight — there's no point\n // hammering the endpoint while the chat is idle. We still poll\n // occasionally so a fresh run started in another tab is picked up.\n if (!data.active || data.status !== \"running\") {\n nextDelay = IDLE_BACKOFF_INTERVAL_MS;\n }\n }\n } catch {\n // Network blip — leave previous state. Next tick will retry.\n }\n if (!cancelled) {\n timer = setTimeout(poll, nextDelay);\n }\n };\n\n // Stagger the first poll so a freshly-started run isn't immediately\n // classified as stuck before the server has had a chance to record\n // any progress events.\n timer = setTimeout(poll, 2_000);\n\n return () => {\n cancelled = true;\n if (timer) clearTimeout(timer);\n };\n }, [\n threadId,\n enabled,\n stuckThresholdMs,\n backgroundStuckThresholdMs,\n pollIntervalMs,\n apiUrl,\n ]);\n\n return state;\n}\n\n/**\n * POST `/runs/:id/abort` so the server flips the run to \"aborted\" and the\n * adapter's reconnect loop exits cleanly. Returns the run id that was\n * aborted (or null on failure) so callers can correlate observability\n * events. Best-effort — failures are swallowed, since the user's intent\n * is already captured locally.\n */\nexport function useAbortRun(apiUrl?: string) {\n return useCallback(\n async (runId: string, reason: string = \"user\"): Promise<string | null> => {\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n try {\n const res = await fetch(\n `${base}/runs/${encodeURIComponent(runId)}/abort`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n credentials: \"same-origin\",\n body: JSON.stringify({ reason }),\n },\n );\n if (!res.ok) return null;\n return runId;\n } catch {\n return null;\n }\n },\n [apiUrl],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-run-stuck-detection.js","sourceRoot":"","sources":["../../src/client/use-run-stuck-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AA6DhD,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,CAAC,MAAM,qCAAqC,GAAG,OAAO,CAAC;AAC7D,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAaxC,MAAM,WAAW,GAAkB;IACjC,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,EACnC,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,gBAAgB,GAAG,0BAA0B,EAC7C,0BAA0B,GAAG,qCAAqC,EAClE,cAAc,GAAG,wBAAwB,EACzC,MAAM,GACsB;IAC5B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,WAAW,CAAC,CAAC;IAE/D,SAAS,CAAC,GAAG,EAAE;QACb,qEAAqE;QACrE,kEAAkE;QAClE,QAAQ,CAAC,WAAW,CAAC,CAAC;QACtB,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO;YAAE,OAAO;QAElC,MAAM,IAAI,GAAG,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAC;QACpE,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB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ED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAe;IACzC,OAAO,WAAW,CAChB,KAAK,EAAE,KAAa,EAAE,MAAM,GAAW,MAAM,EAA0B,EAAE;QACvE,MAAM,IAAI,GAAG,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAC;QACpE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,GAAG,IAAI,SAAS,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EACjD;gBACE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,WAAW,EAAE,aAAa;gBAC1B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;aACjC,CACF,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useState, useCallback } from \"react\";\n\nimport { agentNativePath } from \"./api-path.js\";\n\n/**\n * Per-thread chat run health, derived from the durable `last_progress_at`\n * timestamp on the server. Drives the user-visible \"this chat looks stuck\"\n * affordance — distinct from the silent reconnect logic in\n * `agent-chat-adapter.ts`, which keeps trying in the background. When\n * automatic recovery isn't making progress (for whatever reason), this\n * hook surfaces a Retry / Cancel button to the user instead of leaving\n * them staring at a frozen spinner.\n */\nexport interface RunStuckState {\n /** True when an active run hasn't emitted an event for `stuckThresholdMs`. */\n isStuck: boolean;\n /** ID of the active run, or null when nothing is in flight. */\n runId: string | null;\n /** Server-side run status (\"running\" / \"completed\" / \"errored\" / etc.). */\n status: string | null;\n /** Server timestamp (ms) of the last emitted event, or null if none yet. */\n lastProgressAt: number | null;\n /** Milliseconds since `lastProgressAt`, or null. */\n stuckSinceMs: number | null;\n /** Server timestamp (ms) of the last process-alive heartbeat. */\n heartbeatAt: number | null;\n /** Milliseconds since `heartbeatAt`, computed against the server clock. */\n heartbeatSinceMs: number | null;\n /** How the run was dispatched/continued, e.g. foreground-self-chain or background-processing. */\n dispatchMode: string | null;\n}\n\nexport interface UseRunStuckDetectionOptions {\n /** The thread to monitor. Pass null/undefined to disable polling. */\n threadId: string | null | undefined;\n /**\n * Set false to skip scheduling the poll loop entirely — used to gate\n * polling to only the active chat tab when multiple tabs are mounted\n * (inactive tabs are kept alive via display:none, not unmounted).\n * Defaults to true.\n */\n enabled?: boolean;\n /**\n * Threshold above which an in-flight FOREGROUND run is considered stuck.\n * The default sits comfortably above the adapter's 75s no-progress\n * reconnect — by then automatic recovery has already had its chance.\n */\n stuckThresholdMs?: number;\n /**\n * Threshold for BACKGROUND-dispatched runs (dispatchMode starts with\n * \"background\"). The server owns recovery for these — its run-manager\n * no-progress backstop (150s) and unclaimed-run sweep act first — so the\n * user-facing \"stuck\" affordance is a late fallback, not a race against\n * them. Selected inside the hook because the dispatch mode is only known\n * from the same poll response that computes the elapsed time.\n */\n backgroundStuckThresholdMs?: number;\n /** Poll interval. Default 5_000ms. */\n pollIntervalMs?: number;\n /** API base path. Default `/_agent-native/agent-chat`. */\n apiUrl?: string;\n}\n\nconst DEFAULT_STUCK_THRESHOLD_MS = 90_000;\nexport const DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS = 180_000;\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\nconst IDLE_BACKOFF_INTERVAL_MS = 15_000;\n\ninterface ActiveRunResponse {\n active: boolean;\n runId?: string;\n status?: string;\n heartbeatAt: number | null;\n lastProgressAt?: number | null;\n dispatchMode?: string | null;\n /** Server clock at response time, used to compute elapsed server-relative. */\n serverNow?: number;\n}\n\nconst EMPTY_STATE: RunStuckState = {\n isStuck: false,\n runId: null,\n status: null,\n lastProgressAt: null,\n stuckSinceMs: null,\n heartbeatAt: null,\n heartbeatSinceMs: null,\n dispatchMode: null,\n};\n\nexport function useRunStuckDetection({\n threadId,\n enabled = true,\n stuckThresholdMs = DEFAULT_STUCK_THRESHOLD_MS,\n backgroundStuckThresholdMs = DEFAULT_BACKGROUND_STUCK_THRESHOLD_MS,\n pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,\n apiUrl,\n}: UseRunStuckDetectionOptions): RunStuckState {\n const [state, setState] = useState<RunStuckState>(EMPTY_STATE);\n\n useEffect(() => {\n // Reset on every thread change so the previous thread's stuck banner\n // doesn't bleed onto the new one before the first poll completes.\n setState(EMPTY_STATE);\n if (!threadId || !enabled) return;\n\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n let cancelled = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n const poll = async () => {\n if (cancelled) return;\n let nextDelay = pollIntervalMs;\n try {\n const res = await fetch(\n `${base}/runs/active?threadId=${encodeURIComponent(threadId)}`,\n { credentials: \"same-origin\" },\n );\n if (cancelled) return;\n if (res.ok) {\n const data = (await res.json()) as ActiveRunResponse;\n const lastProgressAt = data.lastProgressAt ?? null;\n // Measure elapsed against the SERVER clock (serverNow) rather than the\n // client's Date.now(). lastProgressAt is a server timestamp, so client\n // clock skew of more than stuckThresholdMs would otherwise mark every\n // run stuck (clock ahead) or never stuck (clock behind). Fall back to\n // the client clock for older bundles that don't send serverNow.\n const nowMs = data.serverNow ?? Date.now();\n const stuckSinceMs =\n lastProgressAt != null ? nowMs - lastProgressAt : null;\n const heartbeatAt = data.heartbeatAt ?? null;\n const heartbeatSinceMs =\n heartbeatAt != null ? nowMs - heartbeatAt : null;\n const dispatchMode =\n typeof data.dispatchMode === \"string\" ? data.dispatchMode : null;\n // Server-continued runs get the wider threshold: the server's own\n // recovery (150s no-progress backstop + chained continuations) must\n // get its chance before the user sees a \"stuck\" affordance.\n const serverContinued =\n dispatchMode === \"foreground-self-chain\" ||\n dispatchMode?.startsWith(\"background\") === true;\n const effectiveThresholdMs = serverContinued\n ? backgroundStuckThresholdMs\n : stuckThresholdMs;\n const isStuck = Boolean(\n data.active &&\n data.status === \"running\" &&\n stuckSinceMs != null &&\n stuckSinceMs > effectiveThresholdMs,\n );\n setState({\n isStuck,\n runId: data.runId ?? null,\n status: data.status ?? null,\n lastProgressAt,\n stuckSinceMs,\n heartbeatAt,\n heartbeatSinceMs,\n dispatchMode,\n });\n // Back off polling when nothing is in flight — there's no point\n // hammering the endpoint while the chat is idle. We still poll\n // occasionally so a fresh run started in another tab is picked up.\n if (!data.active || data.status !== \"running\") {\n nextDelay = IDLE_BACKOFF_INTERVAL_MS;\n }\n }\n } catch {\n // Network blip — leave previous state. Next tick will retry.\n }\n if (!cancelled) {\n timer = setTimeout(poll, nextDelay);\n }\n };\n\n // Stagger the first poll so a freshly-started run isn't immediately\n // classified as stuck before the server has had a chance to record\n // any progress events.\n timer = setTimeout(poll, 2_000);\n\n return () => {\n cancelled = true;\n if (timer) clearTimeout(timer);\n };\n }, [\n threadId,\n enabled,\n stuckThresholdMs,\n backgroundStuckThresholdMs,\n pollIntervalMs,\n apiUrl,\n ]);\n\n return state;\n}\n\n/**\n * POST `/runs/:id/abort` so the server flips the run to \"aborted\" and the\n * adapter's reconnect loop exits cleanly. Returns the run id that was\n * aborted (or null on failure) so callers can correlate observability\n * events. Best-effort — failures are swallowed, since the user's intent\n * is already captured locally.\n */\nexport function useAbortRun(apiUrl?: string) {\n return useCallback(\n async (runId: string, reason: string = \"user\"): Promise<string | null> => {\n const base = apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n try {\n const res = await fetch(\n `${base}/runs/${encodeURIComponent(runId)}/abort`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n credentials: \"same-origin\",\n body: JSON.stringify({ reason }),\n },\n );\n if (!res.ok) return null;\n return runId;\n } catch {\n return null;\n }\n },\n [apiUrl],\n );\n}\n"]}
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* Body: { json: any, fieldName?: string, type?: "map"|"array", requestSource?: string }
|
|
14
14
|
*/
|
|
15
15
|
export declare const postCollabJson: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
16
|
-
error: string;
|
|
17
16
|
ok?: undefined;
|
|
17
|
+
error: string;
|
|
18
18
|
} | {
|
|
19
19
|
error?: undefined;
|
|
20
20
|
ok: boolean;
|
|
@@ -17,12 +17,12 @@ declare const _default: import("../../action.js").ActionDefinition<{
|
|
|
17
17
|
id?: undefined;
|
|
18
18
|
provider?: undefined;
|
|
19
19
|
} | {
|
|
20
|
-
error?: undefined;
|
|
21
20
|
configured?: undefined;
|
|
22
21
|
connectPath?: undefined;
|
|
23
22
|
url: string;
|
|
24
23
|
id: string;
|
|
25
24
|
provider: string;
|
|
25
|
+
error?: undefined;
|
|
26
26
|
}>;
|
|
27
27
|
export default _default;
|
|
28
28
|
//# sourceMappingURL=upload-image.d.ts.map
|
|
@@ -17,14 +17,17 @@ export default defineAction({
|
|
|
17
17
|
const actionCtx = ctx;
|
|
18
18
|
const access = await assertVersionedResourceAccess(args.resourceType, args.resourceId, actionCtx, "editor");
|
|
19
19
|
const registration = getVersionedResource(args.resourceType);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// Prefer the registered server snapshot when available so editors/agents
|
|
21
|
+
// cannot plant arbitrary restore payloads for managed resource types.
|
|
22
|
+
const serverSnapshot = registration?.getSnapshot
|
|
23
|
+
? await registration.getSnapshot({
|
|
23
24
|
resourceType: args.resourceType,
|
|
24
25
|
resourceId: args.resourceId,
|
|
25
26
|
ctx: actionCtx,
|
|
26
27
|
access,
|
|
27
|
-
})
|
|
28
|
+
})
|
|
29
|
+
: undefined;
|
|
30
|
+
const snapshot = serverSnapshot !== undefined ? serverSnapshot : args.snapshot;
|
|
28
31
|
if (snapshot === undefined) {
|
|
29
32
|
throw new Error(`No snapshot was provided and ${args.resourceType} has no getSnapshot history handler`);
|
|
30
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-resource-version.js","sourceRoot":"","sources":["../../../src/history/actions/create-resource-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAChC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACvD,CAAC,CAAC;AAEH,eAAe,YAAY,CAAC;IAC1B,WAAW,EAAE,4DAA4D;IACzE,MAAM;IACN,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QACvB,MAAM,SAAS,GAAG,GAA2C,CAAC;QAC9D,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAChD,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,UAAU,EACf,SAAS,EACT,QAAQ,CACT,CAAC;QACF,MAAM,YAAY,GAAG,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC7D,
|
|
1
|
+
{"version":3,"file":"create-resource-version.js","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9B,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;aAC/B,CAAC;QACJ,CAAC;KACF;CACF,CAAC,CAAC;AAEH,SAAS,oBAAoB,CAC3B,GAAyC;IAEzC,MAAM,MAAM,GAAG,OAAO,GAAG,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7C,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport { defineAction } from \"../../action.js\";\nimport {\n assertVersionedResourceAccess,\n getVersionedResource,\n normalizeHistoryVisibility,\n} from \"../registry.js\";\nimport { insertResourceVersion } from \"../store.js\";\nimport type { HistoryActorKind, VersionedResourceContext } from \"../types.js\";\n\nconst schema = z.object({\n resourceType: z.string().min(1),\n resourceId: z.string().min(1),\n title: z.string().optional(),\n summary: z.string().optional(),\n snapshot: z.unknown().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport default defineAction({\n description: \"Create a reusable version-history snapshot for a resource.\",\n schema,\n run: async (args, ctx) => {\n const actionCtx = ctx as VersionedResourceContext | undefined;\n const access = await assertVersionedResourceAccess(\n args.resourceType,\n args.resourceId,\n actionCtx,\n \"editor\",\n );\n const registration = getVersionedResource(args.resourceType);\n // Prefer the registered server snapshot when available so editors/agents\n // cannot plant arbitrary restore payloads for managed resource types.\n const serverSnapshot = registration?.getSnapshot\n ? await registration.getSnapshot({\n resourceType: args.resourceType,\n resourceId: args.resourceId,\n ctx: actionCtx,\n access,\n })\n : undefined;\n const snapshot =\n serverSnapshot !== undefined ? serverSnapshot : args.snapshot;\n\n if (snapshot === undefined) {\n throw new Error(\n `No snapshot was provided and ${args.resourceType} has no getSnapshot history handler`,\n );\n }\n\n return insertResourceVersion({\n resourceType: args.resourceType,\n resourceId: args.resourceId,\n createdBy: actionCtx?.userEmail ?? null,\n actorKind: actorKindFromContext(actionCtx),\n ownerEmail: access.ownerEmail ?? actionCtx?.userEmail ?? null,\n orgId: access.orgId ?? actionCtx?.orgId ?? null,\n visibility: normalizeHistoryVisibility(access.visibility),\n title: args.title,\n summary: args.summary,\n snapshot,\n metadata: args.metadata,\n });\n },\n audit: {\n target: (args, result) => {\n const version = result as {\n ownerEmail?: string | null;\n orgId?: string | null;\n visibility?: \"private\" | \"org\" | \"public\";\n };\n return {\n type: args.resourceType,\n id: args.resourceId,\n ownerEmail: version.ownerEmail,\n orgId: version.orgId,\n visibility: version.visibility,\n };\n },\n },\n});\n\nfunction actorKindFromContext(\n ctx: VersionedResourceContext | undefined,\n): HistoryActorKind {\n const caller = typeof ctx?.caller === \"string\" ? ctx.caller : \"\";\n if (caller === \"agent\" || caller === \"tool\") {\n return \"agent\";\n }\n return ctx?.userEmail ? \"human\" : \"system\";\n}\n"]}
|
package/dist/history/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { HistoryActorKind, HistoryResourceRole, ResourceHistoryScope, ResourceVersion, VersionedResourceAccess, VersionedResourceContext, VersionedResourceRegistration, VersionedResourceRestoreContext, VersionedResourceSnapshotContext, } from "./types.js";
|
|
2
2
|
export { __resetVersionedResourcesForTests, assertVersionedResourceAccess, getVersionedResource, listVersionedResources, registerVersionedResource, resolveVersionedResourceAccess, } from "./registry.js";
|
|
3
|
-
export { __resetHistoryInitForTests, ensureResourceVersionsTable, getResourceVersionById, getResourceVersionByNumber,
|
|
3
|
+
export { __resetHistoryInitForTests, ensureResourceVersionsTable, getResourceVersionById, getResourceVersionByNumber, queryResourceVersions, } from "./store.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,EAC7B,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,EAC7B,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,YAAY,CAAC"}
|
package/dist/history/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { __resetVersionedResourcesForTests, assertVersionedResourceAccess, getVersionedResource, listVersionedResources, registerVersionedResource, resolveVersionedResourceAccess, } from "./registry.js";
|
|
2
|
-
export { __resetHistoryInitForTests, ensureResourceVersionsTable, getResourceVersionById, getResourceVersionByNumber,
|
|
2
|
+
export { __resetHistoryInitForTests, ensureResourceVersionsTable, getResourceVersionById, getResourceVersionByNumber, queryResourceVersions, } from "./store.js";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,iCAAiC,EACjC,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,YAAY,CAAC","sourcesContent":["export type {\n HistoryActorKind,\n HistoryResourceRole,\n ResourceHistoryScope,\n ResourceVersion,\n VersionedResourceAccess,\n VersionedResourceContext,\n VersionedResourceRegistration,\n VersionedResourceRestoreContext,\n VersionedResourceSnapshotContext,\n} from \"./types.js\";\nexport {\n __resetVersionedResourcesForTests,\n assertVersionedResourceAccess,\n getVersionedResource,\n listVersionedResources,\n registerVersionedResource,\n resolveVersionedResourceAccess,\n} from \"./registry.js\";\nexport {\n __resetHistoryInitForTests,\n ensureResourceVersionsTable,\n getResourceVersionById,\n getResourceVersionByNumber,\n queryResourceVersions,\n} from \"./store.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/history/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/history/registry.ts"],"names":[],"mappings":"AAMA,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,YAAY,CAAC;AAIpB,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,6BAA6B,GAC1C,IAAI,CAON;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GACX,6BAA6B,GAAG,SAAS,CAE3C;AAED,wBAAgB,sBAAsB,IAAI,6BAA6B,EAAE,CAExE;AAYD,wBAAsB,8BAA8B,CAClD,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,GAAG,CAAC,EAAE,wBAAwB,GAC7B,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CA4BzC;AAED,wBAAsB,6BAA6B,CACjD,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,wBAAwB,GAAG,SAAS,EACzC,WAAW,EAAE,mBAAmB,GAC/B,OAAO,CAAC,uBAAuB,CAAC,CAYlC;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACxC,UAAU,CAIZ;AAED,wBAAgB,iCAAiC,IAAI,IAAI,CAExD"}
|
package/dist/history/registry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ForbiddenError, resolveAccess } from "../sharing/access.js";
|
|
1
|
+
import { ForbiddenError, resolveAccess, } from "../sharing/access.js";
|
|
2
2
|
import { getShareableResource } from "../sharing/registry.js";
|
|
3
3
|
import { roleSatisfies } from "../sharing/schema.js";
|
|
4
4
|
const registrations = new Map();
|
|
@@ -14,13 +14,21 @@ export function getVersionedResource(type) {
|
|
|
14
14
|
export function listVersionedResources() {
|
|
15
15
|
return Array.from(registrations.values());
|
|
16
16
|
}
|
|
17
|
+
function accessContextFrom(ctx) {
|
|
18
|
+
if (!ctx)
|
|
19
|
+
return undefined;
|
|
20
|
+
return {
|
|
21
|
+
userEmail: ctx.userEmail ?? undefined,
|
|
22
|
+
orgId: ctx.orgId ?? undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
17
25
|
export async function resolveVersionedResourceAccess(resourceType, resourceId, ctx) {
|
|
18
26
|
const registration = getVersionedResource(resourceType);
|
|
19
27
|
if (registration?.resolveAccess) {
|
|
20
28
|
return registration.resolveAccess(resourceId, ctx);
|
|
21
29
|
}
|
|
22
30
|
if (getShareableResource(resourceType)) {
|
|
23
|
-
const access = await resolveAccess(resourceType, resourceId);
|
|
31
|
+
const access = await resolveAccess(resourceType, resourceId, accessContextFrom(ctx));
|
|
24
32
|
if (!access) {
|
|
25
33
|
return null;
|
|
26
34
|
}
|
|
@@ -32,16 +40,10 @@ export async function resolveVersionedResourceAccess(resourceType, resourceId, c
|
|
|
32
40
|
resource: access.resource,
|
|
33
41
|
};
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
role: "owner",
|
|
41
|
-
ownerEmail: userEmail,
|
|
42
|
-
orgId: ctx?.orgId ?? null,
|
|
43
|
-
visibility: "private",
|
|
44
|
-
};
|
|
43
|
+
// Fail closed: unregistered types, and registered types without an access
|
|
44
|
+
// resolver that aren't shareable, never invent ownership. bypassScope on
|
|
45
|
+
// history queries is only safe after a real resource ACL.
|
|
46
|
+
return null;
|
|
45
47
|
}
|
|
46
48
|
export async function assertVersionedResourceAccess(resourceType, resourceId, ctx, minimumRole) {
|
|
47
49
|
const access = await resolveVersionedResourceAccess(resourceType, resourceId, ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/history/registry.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/history/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,aAAa,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U,EACV,iBAAiB,CAAC,GAAG,CAAC,CACvB,CAAC;QACF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAA2B;YACxC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU,IAAI,IAAI;YAC9C,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI;YACpC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU;YACtC,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC;IACJ,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,0DAA0D;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,YAAoB,EACpB,UAAkB,EAClB,GAAyC,EACzC,WAAgC;IAEhC,MAAM,MAAM,GAAG,MAAM,8BAA8B,CACjD,YAAY,EACZ,UAAU,EACV,GAAG,CACJ,CAAC;IACF,IAAI,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,cAAc,CACtB,yBAAyB,YAAY,IAAI,UAAU,EAAE,CACtD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,UAAyC;IAEzC,OAAO,UAAU,KAAK,KAAK,IAAI,UAAU,KAAK,QAAQ;QACpD,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iCAAiC;IAC/C,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import {\n ForbiddenError,\n resolveAccess,\n type AccessContext,\n} from \"../sharing/access.js\";\nimport { getShareableResource } from \"../sharing/registry.js\";\nimport { roleSatisfies, type Visibility } from \"../sharing/schema.js\";\nimport type {\n HistoryResourceRole,\n VersionedResourceAccess,\n VersionedResourceContext,\n VersionedResourceRegistration,\n} from \"./types.js\";\n\nconst registrations = new Map<string, VersionedResourceRegistration>();\n\nexport function registerVersionedResource(\n registration: VersionedResourceRegistration,\n): void {\n if (!registration.type.trim()) {\n throw new Error(\n \"registerVersionedResource requires a non-empty resource type\",\n );\n }\n registrations.set(registration.type, registration);\n}\n\nexport function getVersionedResource(\n type: string,\n): VersionedResourceRegistration | undefined {\n return registrations.get(type);\n}\n\nexport function listVersionedResources(): VersionedResourceRegistration[] {\n return Array.from(registrations.values());\n}\n\nfunction accessContextFrom(\n ctx?: VersionedResourceContext,\n): AccessContext | undefined {\n if (!ctx) return undefined;\n return {\n userEmail: ctx.userEmail ?? undefined,\n orgId: ctx.orgId ?? undefined,\n };\n}\n\nexport async function resolveVersionedResourceAccess(\n resourceType: string,\n resourceId: string,\n ctx?: VersionedResourceContext,\n): Promise<VersionedResourceAccess | null> {\n const registration = getVersionedResource(resourceType);\n if (registration?.resolveAccess) {\n return registration.resolveAccess(resourceId, ctx);\n }\n\n if (getShareableResource(resourceType)) {\n const access = await resolveAccess(\n resourceType,\n resourceId,\n accessContextFrom(ctx),\n );\n if (!access) {\n return null;\n }\n return {\n role: access.role as HistoryResourceRole,\n ownerEmail: access.resource.ownerEmail ?? null,\n orgId: access.resource.orgId ?? null,\n visibility: access.resource.visibility,\n resource: access.resource,\n };\n }\n\n // Fail closed: unregistered types, and registered types without an access\n // resolver that aren't shareable, never invent ownership. bypassScope on\n // history queries is only safe after a real resource ACL.\n return null;\n}\n\nexport async function assertVersionedResourceAccess(\n resourceType: string,\n resourceId: string,\n ctx: VersionedResourceContext | undefined,\n minimumRole: HistoryResourceRole,\n): Promise<VersionedResourceAccess> {\n const access = await resolveVersionedResourceAccess(\n resourceType,\n resourceId,\n ctx,\n );\n if (!access || !roleSatisfies(access.role, minimumRole)) {\n throw new ForbiddenError(\n `Not allowed to access ${resourceType}:${resourceId}`,\n );\n }\n return access;\n}\n\nexport function normalizeHistoryVisibility(\n visibility: Visibility | null | undefined,\n): Visibility {\n return visibility === \"org\" || visibility === \"public\"\n ? visibility\n : \"private\";\n}\n\nexport function __resetVersionedResourcesForTests(): void {\n registrations.clear();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/history/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/history/store.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EAChB,MAAM,YAAY,CAAC;AAMpB,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,oBAAoB,CAAC;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC,CAkDjE;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,CAAC,CAgG1B;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,eAAe,EAAE,CAAC,CAiB5B;AAED,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,oBAAoB,EAC3B,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACtC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAejC;AAED,wBAAsB,0BAA0B,CAC9C,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,oBAAoB,EAC3B,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACtC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAkBjC;AAED,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD"}
|
package/dist/history/store.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getDbExec, intType, isPostgres } from "../db/client.js";
|
|
1
|
+
import { getDbExec, intType, isPostgres, isUniqueViolation, } from "../db/client.js";
|
|
2
2
|
import { ensureIndexExists, ensureTableExists } from "../db/ddl-guard.js";
|
|
3
3
|
let historyTableInitPromise;
|
|
4
|
+
const VERSION_INSERT_MAX_ATTEMPTS = 8;
|
|
4
5
|
export async function ensureResourceVersionsTable() {
|
|
5
6
|
if (!historyTableInitPromise) {
|
|
6
7
|
historyTableInitPromise = (async () => {
|
|
@@ -22,7 +23,7 @@ export async function ensureResourceVersionsTable() {
|
|
|
22
23
|
metadata_json TEXT
|
|
23
24
|
)`;
|
|
24
25
|
const indexes = [
|
|
25
|
-
`CREATE INDEX IF NOT EXISTS
|
|
26
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS idx_agent_resource_versions_resource_number
|
|
26
27
|
ON agent_resource_versions (resource_type, resource_id, version_number)`,
|
|
27
28
|
`CREATE INDEX IF NOT EXISTS idx_agent_resource_versions_owner
|
|
28
29
|
ON agent_resource_versions (owner_email, created_at)`,
|
|
@@ -31,7 +32,7 @@ export async function ensureResourceVersionsTable() {
|
|
|
31
32
|
];
|
|
32
33
|
if (isPostgres()) {
|
|
33
34
|
await ensureTableExists("agent_resource_versions", createSql);
|
|
34
|
-
await ensureIndexExists("
|
|
35
|
+
await ensureIndexExists("idx_agent_resource_versions_resource_number", indexes[0]);
|
|
35
36
|
await ensureIndexExists("idx_agent_resource_versions_owner", indexes[1]);
|
|
36
37
|
await ensureIndexExists("idx_agent_resource_versions_org", indexes[2]);
|
|
37
38
|
}
|
|
@@ -48,36 +49,49 @@ export async function ensureResourceVersionsTable() {
|
|
|
48
49
|
export async function insertResourceVersion(input) {
|
|
49
50
|
await ensureResourceVersionsTable();
|
|
50
51
|
const client = getDbExec();
|
|
51
|
-
const
|
|
52
|
-
|
|
52
|
+
const visibility = input.visibility === "org" || input.visibility === "public"
|
|
53
|
+
? input.visibility
|
|
54
|
+
: "private";
|
|
55
|
+
const actorKind = input.actorKind ?? "human";
|
|
56
|
+
const createdBy = input.createdBy ?? null;
|
|
57
|
+
const ownerEmail = input.ownerEmail ?? input.createdBy ?? null;
|
|
58
|
+
const orgId = input.orgId ?? null;
|
|
59
|
+
const title = input.title ?? null;
|
|
60
|
+
const summary = input.summary ?? null;
|
|
61
|
+
const metadata = input.metadata ?? null;
|
|
62
|
+
const snapshotJson = JSON.stringify(input.snapshot);
|
|
63
|
+
const metadataJson = stringifyOptionalJson(metadata);
|
|
64
|
+
let lastError;
|
|
65
|
+
for (let attempt = 0; attempt < VERSION_INSERT_MAX_ATTEMPTS; attempt++) {
|
|
66
|
+
const maxRows = await client.execute({
|
|
67
|
+
sql: `SELECT MAX(version_number) as max_version
|
|
53
68
|
FROM agent_resource_versions
|
|
54
69
|
WHERE resource_type = ? AND resource_id = ?`,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
sql: `INSERT INTO agent_resource_versions (
|
|
70
|
+
args: [input.resourceType, input.resourceId],
|
|
71
|
+
});
|
|
72
|
+
const versionNumber = Number(maxRows.rows?.[0]
|
|
73
|
+
?.max_version ?? 0) + 1;
|
|
74
|
+
const id = createVersionId();
|
|
75
|
+
const createdAt = new Date().toISOString();
|
|
76
|
+
const version = {
|
|
77
|
+
id,
|
|
78
|
+
resourceType: input.resourceType,
|
|
79
|
+
resourceId: input.resourceId,
|
|
80
|
+
versionNumber,
|
|
81
|
+
createdAt,
|
|
82
|
+
createdBy,
|
|
83
|
+
actorKind,
|
|
84
|
+
ownerEmail,
|
|
85
|
+
orgId,
|
|
86
|
+
visibility,
|
|
87
|
+
title,
|
|
88
|
+
summary,
|
|
89
|
+
snapshot: input.snapshot,
|
|
90
|
+
metadata,
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
await client.execute({
|
|
94
|
+
sql: `INSERT INTO agent_resource_versions (
|
|
81
95
|
id,
|
|
82
96
|
resource_type,
|
|
83
97
|
resource_id,
|
|
@@ -93,24 +107,35 @@ export async function insertResourceVersion(input) {
|
|
|
93
107
|
snapshot_json,
|
|
94
108
|
metadata_json
|
|
95
109
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
args: [
|
|
111
|
+
version.id,
|
|
112
|
+
version.resourceType,
|
|
113
|
+
version.resourceId,
|
|
114
|
+
version.versionNumber,
|
|
115
|
+
version.createdAt,
|
|
116
|
+
version.createdBy,
|
|
117
|
+
version.actorKind,
|
|
118
|
+
version.ownerEmail,
|
|
119
|
+
version.orgId,
|
|
120
|
+
version.visibility,
|
|
121
|
+
version.title,
|
|
122
|
+
version.summary,
|
|
123
|
+
snapshotJson,
|
|
124
|
+
metadataJson,
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
return version;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
lastError = error;
|
|
131
|
+
if (!isUniqueViolation(error)) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
throw lastError instanceof Error
|
|
137
|
+
? lastError
|
|
138
|
+
: new Error("Failed to allocate a unique resource version number");
|
|
114
139
|
}
|
|
115
140
|
export async function queryResourceVersions(input) {
|
|
116
141
|
await ensureResourceVersionsTable();
|